aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/acpi/dispatcher/dsmethod.c12
-rw-r--r--drivers/acpi/dispatcher/dsopcode.c3
-rw-r--r--drivers/acpi/dispatcher/dsutils.c7
-rw-r--r--drivers/acpi/dispatcher/dswstate.c9
-rw-r--r--drivers/acpi/ec.c39
-rw-r--r--drivers/acpi/events/evgpe.c5
-rw-r--r--drivers/acpi/events/evgpeblk.c3
-rw-r--r--drivers/acpi/events/evmisc.c20
-rw-r--r--drivers/acpi/events/evregion.c15
-rw-r--r--drivers/acpi/events/evrgnini.c3
-rw-r--r--drivers/acpi/events/evxface.c7
-rw-r--r--drivers/acpi/events/evxfevnt.c2
-rw-r--r--drivers/acpi/executer/exconvrt.c5
-rw-r--r--drivers/acpi/executer/excreate.c6
-rw-r--r--drivers/acpi/executer/exdump.c17
-rw-r--r--drivers/acpi/executer/exmutex.c37
-rw-r--r--drivers/acpi/executer/exnames.c3
-rw-r--r--drivers/acpi/executer/exprep.c2
-rw-r--r--drivers/acpi/executer/exresop.c3
-rw-r--r--drivers/acpi/executer/exsystem.c30
-rw-r--r--drivers/acpi/executer/exutils.c104
-rw-r--r--drivers/acpi/glue.c46
-rw-r--r--drivers/acpi/hardware/hwsleep.c1
-rw-r--r--drivers/acpi/namespace/nseval.c13
-rw-r--r--drivers/acpi/namespace/nsinit.c7
-rw-r--r--drivers/acpi/namespace/nswalk.c6
-rw-r--r--drivers/acpi/namespace/nsxfeval.c17
-rw-r--r--drivers/acpi/numa.c8
-rw-r--r--drivers/acpi/osl.c46
-rw-r--r--drivers/acpi/parser/psopcode.c618
-rw-r--r--drivers/acpi/resources/rscalc.c3
-rw-r--r--drivers/acpi/resources/rscreate.c13
-rw-r--r--drivers/acpi/resources/rsdump.c8
-rw-r--r--drivers/acpi/resources/rsinfo.c2
-rw-r--r--drivers/acpi/resources/rslist.c7
-rw-r--r--drivers/acpi/resources/rsmisc.c4
-rw-r--r--drivers/acpi/resources/rsutils.c6
-rw-r--r--drivers/acpi/resources/rsxface.c3
-rw-r--r--drivers/acpi/scan.c2
-rw-r--r--drivers/acpi/sleep/main.c68
-rw-r--r--drivers/acpi/sleep/proc.c24
-rw-r--r--drivers/acpi/tables/tbfadt.c6
-rw-r--r--drivers/acpi/tables/tbxface.c16
-rw-r--r--drivers/acpi/thermal.c104
-rw-r--r--drivers/acpi/utilities/utalloc.c1
-rw-r--r--drivers/acpi/utilities/utcache.c3
-rw-r--r--drivers/acpi/utilities/utcopy.c4
-rw-r--r--drivers/acpi/utilities/utdebug.c4
-rw-r--r--drivers/acpi/utilities/utdelete.c1
-rw-r--r--drivers/acpi/utilities/utglobal.c6
-rw-r--r--drivers/acpi/utilities/utmisc.c6
-rw-r--r--drivers/acpi/utilities/utmutex.c8
-rw-r--r--drivers/acpi/utilities/utresrc.c1
-rw-r--r--drivers/acpi/utilities/utxface.c2
-rw-r--r--drivers/ata/Kconfig41
-rw-r--r--drivers/ata/Makefile2
-rw-r--r--drivers/ata/ahci.c49
-rw-r--r--drivers/ata/ata_generic.c14
-rw-r--r--drivers/ata/ata_piix.c23
-rw-r--r--drivers/ata/libata-acpi.c205
-rw-r--r--drivers/ata/libata-core.c395
-rw-r--r--drivers/ata/libata-eh.c310
-rw-r--r--drivers/ata/libata-scsi.c188
-rw-r--r--drivers/ata/libata-sff.c162
-rw-r--r--drivers/ata/libata.h9
-rw-r--r--drivers/ata/pata_ali.c36
-rw-r--r--drivers/ata/pata_amd.c24
-rw-r--r--drivers/ata/pata_artop.c40
-rw-r--r--drivers/ata/pata_atiixp.c14
-rw-r--r--drivers/ata/pata_cmd640.c15
-rw-r--r--drivers/ata/pata_cmd64x.c19
-rw-r--r--drivers/ata/pata_cs5520.c6
-rw-r--r--drivers/ata/pata_cs5530.c16
-rw-r--r--drivers/ata/pata_cs5535.c13
-rw-r--r--drivers/ata/pata_cypress.c12
-rw-r--r--drivers/ata/pata_efar.c15
-rw-r--r--drivers/ata/pata_hpt366.c45
-rw-r--r--drivers/ata/pata_hpt37x.c52
-rw-r--r--drivers/ata/pata_hpt3x2n.c18
-rw-r--r--drivers/ata/pata_hpt3x3.c12
-rw-r--r--drivers/ata/pata_icside.c184
-rw-r--r--drivers/ata/pata_isapnp.c2
-rw-r--r--drivers/ata/pata_it8213.c20
-rw-r--r--drivers/ata/pata_it821x.c16
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c4
-rw-r--r--drivers/ata/pata_jmicron.c19
-rw-r--r--drivers/ata/pata_legacy.c2
-rw-r--r--drivers/ata/pata_marvell.c22
-rw-r--r--drivers/ata/pata_mpc52xx.c4
-rw-r--r--drivers/ata/pata_mpiix.c9
-rw-r--r--drivers/ata/pata_netcell.c10
-rw-r--r--drivers/ata/pata_ns87410.c16
-rw-r--r--drivers/ata/pata_oldpiix.c16
-rw-r--r--drivers/ata/pata_opti.c16
-rw-r--r--drivers/ata/pata_optidma.c21
-rw-r--r--drivers/ata/pata_pcmcia.c2
-rw-r--r--drivers/ata/pata_pdc2027x.c5
-rw-r--r--drivers/ata/pata_pdc202xx_old.c12
-rw-r--r--drivers/ata/pata_platform.c6
-rw-r--r--drivers/ata/pata_qdi.c4
-rw-r--r--drivers/ata/pata_radisys.c10
-rw-r--r--drivers/ata/pata_rz1000.c20
-rw-r--r--drivers/ata/pata_sc1200.c14
-rw-r--r--drivers/ata/pata_scc.c14
-rw-r--r--drivers/ata/pata_serverworks.c25
-rw-r--r--drivers/ata/pata_sil680.c20
-rw-r--r--drivers/ata/pata_sis.c41
-rw-r--r--drivers/ata/pata_sl82c105.c24
-rw-r--r--drivers/ata/pata_triflex.c16
-rw-r--r--drivers/ata/pata_via.c41
-rw-r--r--drivers/ata/pata_winbond.c2
-rw-r--r--drivers/ata/pdc_adma.c2
-rw-r--r--drivers/ata/sata_inic162x.c21
-rw-r--r--drivers/ata/sata_mv.c2
-rw-r--r--drivers/ata/sata_nv.c131
-rw-r--r--drivers/ata/sata_promise.c24
-rw-r--r--drivers/ata/sata_qstor.c2
-rw-r--r--drivers/ata/sata_sil.c6
-rw-r--r--drivers/ata/sata_sil24.c19
-rw-r--r--drivers/ata/sata_sis.c8
-rw-r--r--drivers/ata/sata_svw.c4
-rw-r--r--drivers/ata/sata_sx4.c2
-rw-r--r--drivers/ata/sata_uli.c24
-rw-r--r--drivers/ata/sata_via.c15
-rw-r--r--drivers/ata/sata_vsc.c2
-rw-r--r--drivers/ata/sis.h2
-rw-r--r--drivers/atm/Kconfig32
-rw-r--r--drivers/auxdisplay/Kconfig1
-rw-r--r--drivers/base/devres.c32
-rw-r--r--drivers/base/dmapool.c1
-rw-r--r--drivers/base/platform.c20
-rw-r--r--drivers/base/topology.c3
-rw-r--r--drivers/block/Kconfig4
-rw-r--r--drivers/block/acsi_slm.c1
-rw-r--r--drivers/block/cciss.c333
-rw-r--r--drivers/block/cciss_scsi.c1
-rw-r--r--drivers/block/floppy.c7
-rw-r--r--drivers/block/loop.c171
-rw-r--r--drivers/block/nbd.c15
-rw-r--r--drivers/block/rd.c2
-rw-r--r--drivers/block/umem.c1
-rw-r--r--drivers/bluetooth/hci_ldisc.c10
-rw-r--r--drivers/bluetooth/hci_uart.h5
-rw-r--r--drivers/char/Kconfig22
-rw-r--r--drivers/char/agp/amd64-agp.c2
-rw-r--r--drivers/char/agp/frontend.c1
-rw-r--r--drivers/char/agp/generic.c1
-rw-r--r--drivers/char/agp/uninorth-agp.c2
-rw-r--r--drivers/char/agp/via-agp.c6
-rw-r--r--drivers/char/amiserial.c4
-rw-r--r--drivers/char/briq_panel.c2
-rw-r--r--drivers/char/consolemap.c6
-rw-r--r--drivers/char/cs5535_gpio.c1
-rw-r--r--drivers/char/cyclades.c2581
-rw-r--r--drivers/char/digi.h71
-rw-r--r--drivers/char/drm/ati_pcigart.c84
-rw-r--r--drivers/char/drm/drmP.h7
-rw-r--r--drivers/char/drm/drm_dma.c2
-rw-r--r--drivers/char/drm/drm_drv.c10
-rw-r--r--drivers/char/drm/drm_os_linux.h3
-rw-r--r--drivers/char/drm/drm_pciids.h1
-rw-r--r--drivers/char/drm/drm_vm.c2
-rw-r--r--drivers/char/drm/r128_cce.c3
-rw-r--r--drivers/char/drm/r128_drv.h2
-rw-r--r--drivers/char/drm/r300_reg.h2
-rw-r--r--drivers/char/drm/radeon_cp.c71
-rw-r--r--drivers/char/drm/radeon_drm.h1
-rw-r--r--drivers/char/drm/radeon_drv.h24
-rw-r--r--drivers/char/drm/radeon_state.c52
-rw-r--r--drivers/char/drm/via_dma.c111
-rw-r--r--drivers/char/drm/via_drv.h5
-rw-r--r--drivers/char/ds1620.c1
-rw-r--r--drivers/char/dsp56k.c1
-rw-r--r--drivers/char/dtlk.c15
-rw-r--r--drivers/char/ec3104_keyb.c1
-rw-r--r--drivers/char/epca.c2
-rw-r--r--drivers/char/genrtc.c6
-rw-r--r--drivers/char/hangcheck-timer.c3
-rw-r--r--drivers/char/hvc_console.c12
-rw-r--r--drivers/char/hvc_iseries.c2
-rw-r--r--drivers/char/hvc_vio.c2
-rw-r--r--drivers/char/hw_random/Kconfig14
-rw-r--r--drivers/char/hw_random/Makefile1
-rw-r--r--drivers/char/hw_random/intel-rng.c219
-rw-r--r--drivers/char/hw_random/pasemi-rng.c156
-rw-r--r--drivers/char/i8k.c1
-rw-r--r--drivers/char/ip27-rtc.c1
-rw-r--r--drivers/char/ipmi/Kconfig2
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c243
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c2
-rw-r--r--drivers/char/isicom.c3
-rw-r--r--drivers/char/keyboard.c2
-rw-r--r--drivers/char/lp.c8
-rw-r--r--drivers/char/mem.c9
-rw-r--r--drivers/char/misc.c27
-rw-r--r--drivers/char/mmtimer.c4
-rw-r--r--drivers/char/moxa.c8
-rw-r--r--drivers/char/mxser.c1
-rw-r--r--drivers/char/mxser_new.c1
-rw-r--r--drivers/char/n_r3964.c4
-rw-r--r--drivers/char/n_tty.c29
-rw-r--r--drivers/char/pcmcia/Kconfig1
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c46
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c7
-rw-r--r--drivers/char/ppdev.c3
-rw-r--r--drivers/char/rio/riocmd.c2
-rw-r--r--drivers/char/riscom8.c2
-rw-r--r--drivers/char/rocket.c36
-rw-r--r--drivers/char/rocket_int.h6
-rw-r--r--drivers/char/rtc.c2
-rw-r--r--drivers/char/selection.c2
-rw-r--r--drivers/char/serial167.c2
-rw-r--r--drivers/char/snsc_event.c2
-rw-r--r--drivers/char/synclink.c7
-rw-r--r--drivers/char/synclink_gt.c141
-rw-r--r--drivers/char/sysrq.c1
-rw-r--r--drivers/char/tipar.c2
-rw-r--r--drivers/char/tpm/Kconfig3
-rw-r--r--drivers/char/tpm/tpm.c36
-rw-r--r--drivers/char/tpm/tpm.h5
-rw-r--r--drivers/char/tpm/tpm_atmel.h7
-rw-r--r--drivers/char/tpm/tpm_infineon.c231
-rw-r--r--drivers/char/tty_io.c150
-rw-r--r--drivers/char/vc_screen.c19
-rw-r--r--drivers/char/vt.c304
-rw-r--r--drivers/char/vt_ioctl.c2
-rw-r--r--drivers/char/watchdog/Kconfig150
-rw-r--r--drivers/char/watchdog/Makefile2
-rw-r--r--drivers/char/watchdog/booke_wdt.c2
-rw-r--r--drivers/char/watchdog/cpu5wdt.c14
-rw-r--r--drivers/char/watchdog/eurotechwdt.c22
-rw-r--r--drivers/char/watchdog/i8xx_tco.c571
-rw-r--r--drivers/char/watchdog/i8xx_tco.h42
-rw-r--r--drivers/char/watchdog/iTCO_wdt.c2
-rw-r--r--drivers/char/watchdog/ibmasr.c11
-rw-r--r--drivers/char/watchdog/machzwd.c18
-rw-r--r--drivers/char/watchdog/mtx-1_wdt.c238
-rw-r--r--drivers/char/watchdog/omap_wdt.c1
-rw-r--r--drivers/char/watchdog/pcwd.c242
-rw-r--r--drivers/char/watchdog/pcwd_usb.c8
-rw-r--r--drivers/char/watchdog/s3c2410_wdt.c6
-rw-r--r--drivers/char/watchdog/sbc8360.c28
-rw-r--r--drivers/char/watchdog/w83627hf_wdt.c23
-rw-r--r--drivers/cpufreq/cpufreq.c3
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c2
-rw-r--r--drivers/cpufreq/cpufreq_stats.c2
-rw-r--r--drivers/crypto/Kconfig28
-rw-r--r--drivers/dma/Kconfig1
-rw-r--r--drivers/edac/Kconfig1
-rw-r--r--drivers/edac/i82875p_edac.c13
-rw-r--r--drivers/eisa/virtual_root.c2
-rw-r--r--drivers/firewire/Kconfig61
-rw-r--r--drivers/firewire/Makefile10
-rw-r--r--drivers/firewire/fw-card.c560
-rw-r--r--drivers/firewire/fw-cdev.c961
-rw-r--r--drivers/firewire/fw-device.c813
-rw-r--r--drivers/firewire/fw-device.h146
-rw-r--r--drivers/firewire/fw-iso.c163
-rw-r--r--drivers/firewire/fw-ohci.c1944
-rw-r--r--drivers/firewire/fw-ohci.h153
-rw-r--r--drivers/firewire/fw-sbp2.c1147
-rw-r--r--drivers/firewire/fw-topology.c537
-rw-r--r--drivers/firewire/fw-topology.h92
-rw-r--r--drivers/firewire/fw-transaction.c910
-rw-r--r--drivers/firewire/fw-transaction.h458
-rw-r--r--drivers/hid/hid-core.c1
-rw-r--r--drivers/hid/hid-input.c101
-rw-r--r--drivers/hid/usbhid/Kconfig4
-rw-r--r--drivers/hid/usbhid/hid-core.c41
-rw-r--r--drivers/hid/usbhid/hid-lgff.c2
-rw-r--r--drivers/hid/usbhid/hid-plff.c2
-rw-r--r--drivers/hid/usbhid/hid-quirks.c7
-rw-r--r--drivers/hid/usbhid/hid-tmff.c2
-rw-r--r--drivers/hid/usbhid/hid-zpff.c2
-rw-r--r--drivers/hid/usbhid/hiddev.c14
-rw-r--r--drivers/hid/usbhid/usbkbd.c21
-rw-r--r--drivers/hid/usbhid/usbmouse.c9
-rw-r--r--drivers/hwmon/Kconfig171
-rw-r--r--drivers/hwmon/Makefile4
-rw-r--r--drivers/hwmon/ad7418.c373
-rw-r--r--drivers/hwmon/ams/ams-core.c9
-rw-r--r--drivers/hwmon/ams/ams-i2c.c10
-rw-r--r--drivers/hwmon/ams/ams-input.c2
-rw-r--r--drivers/hwmon/ams/ams-pmu.c2
-rw-r--r--drivers/hwmon/applesmc.c1340
-rw-r--r--drivers/hwmon/coretemp.c408
-rw-r--r--drivers/hwmon/f71805f.c16
-rw-r--r--drivers/hwmon/hdaps.c40
-rw-r--r--drivers/hwmon/hwmon-vid.c6
-rw-r--r--drivers/hwmon/lm75.c82
-rw-r--r--drivers/hwmon/lm78.c662
-rw-r--r--drivers/hwmon/lm87.c2
-rw-r--r--drivers/hwmon/max6650.c693
-rw-r--r--drivers/hwmon/pc87427.c15
-rw-r--r--drivers/hwmon/smsc47b397.c228
-rw-r--r--drivers/hwmon/smsc47m1.c606
-rw-r--r--drivers/hwmon/smsc47m192.c4
-rw-r--r--drivers/hwmon/vt1211.c13
-rw-r--r--drivers/hwmon/w83627hf.c670
-rw-r--r--drivers/hwmon/w83781d.c1205
-rw-r--r--drivers/i2c/Kconfig1
-rw-r--r--drivers/i2c/busses/i2c-at91.c7
-rw-r--r--drivers/i2c/busses/i2c-parport.c1
-rw-r--r--drivers/i2c/busses/i2c-pxa.c2
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c3
-rw-r--r--drivers/i2c/busses/i2c-tiny-usb.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c1
-rw-r--r--drivers/i2c/chips/tps65010.c2
-rw-r--r--drivers/i2c/i2c-core.c5
-rw-r--r--drivers/i2c/i2c-dev.c1
-rw-r--r--drivers/ide/Kconfig28
-rw-r--r--drivers/ide/Makefile2
-rw-r--r--drivers/ide/arm/bast-ide.c2
-rw-r--r--drivers/ide/arm/icside.c50
-rw-r--r--drivers/ide/arm/ide_arm.c2
-rw-r--r--drivers/ide/arm/rapide.c7
-rw-r--r--drivers/ide/cris/ide-cris.c16
-rw-r--r--drivers/ide/h8300/ide-h8300.c2
-rw-r--r--drivers/ide/ide-cd.c20
-rw-r--r--drivers/ide/ide-disk.c101
-rw-r--r--drivers/ide/ide-dma.c103
-rw-r--r--drivers/ide/ide-floppy.c30
-rw-r--r--drivers/ide/ide-generic.c2
-rw-r--r--drivers/ide/ide-io.c18
-rw-r--r--drivers/ide/ide-iops.c55
-rw-r--r--drivers/ide/ide-lib.c144
-rw-r--r--drivers/ide/ide-pnp.c2
-rw-r--r--drivers/ide/ide-probe.c3
-rw-r--r--drivers/ide/ide-proc.c344
-rw-r--r--drivers/ide/ide-tape.c49
-rw-r--r--drivers/ide/ide.c471
-rw-r--r--drivers/ide/legacy/ali14xx.c3
-rw-r--r--drivers/ide/legacy/buddha.c2
-rw-r--r--drivers/ide/legacy/dtc2278.c3
-rw-r--r--drivers/ide/legacy/falconide.c2
-rw-r--r--drivers/ide/legacy/gayle.c2
-rw-r--r--drivers/ide/legacy/ht6560b.c3
-rw-r--r--drivers/ide/legacy/ide-cs.c2
-rw-r--r--drivers/ide/legacy/macide.c6
-rw-r--r--drivers/ide/legacy/q40ide.c2
-rw-r--r--drivers/ide/legacy/qd65xx.c7
-rw-r--r--drivers/ide/legacy/umc8672.c3
-rw-r--r--drivers/ide/mips/au1xxx-ide.c3
-rw-r--r--drivers/ide/mips/swarm.c3
-rw-r--r--drivers/ide/pci/aec62xx.c62
-rw-r--r--drivers/ide/pci/alim15x3.c164
-rw-r--r--drivers/ide/pci/amd74xx.c6
-rw-r--r--drivers/ide/pci/atiixp.c40
-rw-r--r--drivers/ide/pci/cmd64x.c103
-rw-r--r--drivers/ide/pci/cs5520.c20
-rw-r--r--drivers/ide/pci/cs5530.c160
-rw-r--r--drivers/ide/pci/cs5535.c33
-rw-r--r--drivers/ide/pci/delkin_cb.c2
-rw-r--r--drivers/ide/pci/hpt34x.c27
-rw-r--r--drivers/ide/pci/hpt366.c85
-rw-r--r--drivers/ide/pci/it8213.c39
-rw-r--r--drivers/ide/pci/it821x.c39
-rw-r--r--drivers/ide/pci/jmicron.c40
-rw-r--r--drivers/ide/pci/pdc202xx_new.c69
-rw-r--r--drivers/ide/pci/pdc202xx_old.c234
-rw-r--r--drivers/ide/pci/piix.c163
-rw-r--r--drivers/ide/pci/sc1200.c161
-rw-r--r--drivers/ide/pci/scc_pata.c41
-rw-r--r--drivers/ide/pci/serverworks.c104
-rw-r--r--drivers/ide/pci/sgiioc4.c2
-rw-r--r--drivers/ide/pci/siimage.c69
-rw-r--r--drivers/ide/pci/sis5513.c129
-rw-r--r--drivers/ide/pci/sl82c105.c76
-rw-r--r--drivers/ide/pci/slc90e66.c24
-rw-r--r--drivers/ide/pci/tc86c001.c20
-rw-r--r--drivers/ide/pci/triflex.c15
-rw-r--r--drivers/ide/ppc/pmac.c20
-rw-r--r--drivers/ide/setup-pci.c27
-rw-r--r--drivers/ieee1394/Kconfig3
-rw-r--r--drivers/ieee1394/dv1394.c1
-rw-r--r--drivers/ieee1394/nodemgr.c2
-rw-r--r--drivers/ieee1394/raw1394.c1
-rw-r--r--drivers/ieee1394/video1394.c1
-rw-r--r--drivers/infiniband/Kconfig8
-rw-r--r--drivers/infiniband/Makefile1
-rw-r--r--drivers/infiniband/core/Makefile4
-rw-r--r--drivers/infiniband/core/cache.c1
-rw-r--r--drivers/infiniband/core/cm.c4
-rw-r--r--drivers/infiniband/core/cma.c106
-rw-r--r--drivers/infiniband/core/device.c138
-rw-r--r--drivers/infiniband/core/umem.c (renamed from drivers/infiniband/core/uverbs_mem.c)158
-rw-r--r--drivers/infiniband/core/uverbs.h6
-rw-r--r--drivers/infiniband/core/uverbs_cmd.c60
-rw-r--r--drivers/infiniband/core/uverbs_main.c11
-rw-r--r--drivers/infiniband/hw/amso1100/c2_provider.c42
-rw-r--r--drivers/infiniband/hw/amso1100/c2_provider.h1
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_provider.c28
-rw-r--r--drivers/infiniband/hw/cxgb3/iwch_provider.h1
-rw-r--r--drivers/infiniband/hw/ehca/ehca_classes.h2
-rw-r--r--drivers/infiniband/hw/ehca/ehca_irq.c13
-rw-r--r--drivers/infiniband/hw/ehca/ehca_iverbs.h3
-rw-r--r--drivers/infiniband/hw/ehca/ehca_main.c96
-rw-r--r--drivers/infiniband/hw/ehca/ehca_mrmw.c76
-rw-r--r--drivers/infiniband/hw/ehca/ehca_qp.c17
-rw-r--r--drivers/infiniband/hw/ehca/hcp_if.c13
-rw-r--r--drivers/infiniband/hw/ipath/ipath_fs.c2
-rw-r--r--drivers/infiniband/hw/ipath/ipath_iba6120.c7
-rw-r--r--drivers/infiniband/hw/ipath/ipath_intr.c7
-rw-r--r--drivers/infiniband/hw/ipath/ipath_kernel.h2
-rw-r--r--drivers/infiniband/hw/ipath/ipath_mr.c38
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.c12
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs.h5
-rw-r--r--drivers/infiniband/hw/ipath/ipath_verbs_mcast.c16
-rw-r--r--drivers/infiniband/hw/mlx4/Kconfig9
-rw-r--r--drivers/infiniband/hw/mlx4/Makefile3
-rw-r--r--drivers/infiniband/hw/mlx4/ah.c100
-rw-r--r--drivers/infiniband/hw/mlx4/cq.c525
-rw-r--r--drivers/infiniband/hw/mlx4/doorbell.c216
-rw-r--r--drivers/infiniband/hw/mlx4/mad.c339
-rw-r--r--drivers/infiniband/hw/mlx4/main.c652
-rw-r--r--drivers/infiniband/hw/mlx4/mlx4_ib.h285
-rw-r--r--drivers/infiniband/hw/mlx4/mr.c184
-rw-r--r--drivers/infiniband/hw/mlx4/qp.c1371
-rw-r--r--drivers/infiniband/hw/mlx4/srq.c340
-rw-r--r--drivers/infiniband/hw/mlx4/user.h95
-rw-r--r--drivers/infiniband/hw/mthca/mthca_av.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cmd.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_cq.c5
-rw-r--r--drivers/infiniband/hw/mthca/mthca_main.c4
-rw-r--r--drivers/infiniband/hw/mthca/mthca_memfree.c1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.c38
-rw-r--r--drivers/infiniband/hw/mthca/mthca_provider.h1
-rw-r--r--drivers/infiniband/hw/mthca/mthca_qp.c160
-rw-r--r--drivers/infiniband/hw/mthca/mthca_srq.c1
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib.h49
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_cm.c214
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_ib.c87
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_main.c7
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_multicast.c2
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_verbs.c40
-rw-r--r--drivers/infiniband/ulp/iser/iser_verbs.c1
-rw-r--r--drivers/input/Kconfig1
-rw-r--r--drivers/input/evdev.c3
-rw-r--r--drivers/input/input.c1
-rw-r--r--drivers/input/joydev.c1
-rw-r--r--drivers/input/joystick/Kconfig1
-rw-r--r--drivers/input/joystick/xpad.c1
-rw-r--r--drivers/input/misc/Kconfig5
-rw-r--r--drivers/input/misc/ixp4xx-beeper.c2
-rw-r--r--drivers/input/mouse/Kconfig1
-rw-r--r--drivers/input/mousedev.c1
-rw-r--r--drivers/input/tablet/Kconfig4
-rw-r--r--drivers/input/touchscreen/Kconfig1
-rw-r--r--drivers/input/touchscreen/hp680_ts_input.c7
-rw-r--r--drivers/input/tsdev.c1
-rw-r--r--drivers/isdn/Kconfig1
-rw-r--r--drivers/isdn/capi/Kconfig2
-rw-r--r--drivers/isdn/capi/capi.c34
-rw-r--r--drivers/isdn/capi/capiutil.c8
-rw-r--r--drivers/isdn/divert/divert_procfs.c1
-rw-r--r--drivers/isdn/gigaset/usb-gigaset.c14
-rw-r--r--drivers/isdn/hardware/eicon/capimain.c1
-rw-r--r--drivers/isdn/hardware/eicon/dbgioctl.h198
-rw-r--r--drivers/isdn/hardware/eicon/divamnt.c1
-rw-r--r--drivers/isdn/hardware/eicon/divasi.c1
-rw-r--r--drivers/isdn/hardware/eicon/divasmain.c1
-rw-r--r--drivers/isdn/hardware/eicon/divasync.h2
-rw-r--r--drivers/isdn/hardware/eicon/main_if.h50
-rw-r--r--drivers/isdn/hardware/eicon/platform.h1
-rw-r--r--drivers/isdn/hisax/hfc_usb.c5
-rw-r--r--drivers/isdn/hysdn/boardergo.c2
-rw-r--r--drivers/isdn/hysdn/hysdn_proclog.c4
-rw-r--r--drivers/isdn/icn/icn.c1
-rw-r--r--drivers/isdn/isdnloop/isdnloop.c2
-rw-r--r--drivers/isdn/sc/message.c2
-rw-r--r--drivers/kvm/Kconfig1
-rw-r--r--drivers/kvm/kvm.h1
-rw-r--r--drivers/kvm/kvm_main.c4
-rw-r--r--drivers/kvm/svm.c1
-rw-r--r--drivers/kvm/vmx.c1
-rw-r--r--drivers/leds/Kconfig1
-rw-r--r--drivers/leds/leds-h1940.c2
-rw-r--r--drivers/macintosh/Kconfig14
-rw-r--r--drivers/macintosh/apm_emu.c521
-rw-r--r--drivers/macintosh/mac_hid.c8
-rw-r--r--drivers/macintosh/macio_sysfs.c27
-rw-r--r--drivers/macintosh/mediabay.c2
-rw-r--r--drivers/macintosh/smu.c2
-rw-r--r--drivers/macintosh/therm_adt746x.c5
-rw-r--r--drivers/macintosh/therm_pm72.c1
-rw-r--r--drivers/macintosh/via-pmu-led.c35
-rw-r--r--drivers/macintosh/via-pmu.c12
-rw-r--r--drivers/macintosh/windfarm_core.c11
-rw-r--r--drivers/macintosh/windfarm_lm75_sensor.c4
-rw-r--r--drivers/macintosh/windfarm_max6690_sensor.c2
-rw-r--r--drivers/macintosh/windfarm_smu_controls.c2
-rw-r--r--drivers/macintosh/windfarm_smu_sat.c2
-rw-r--r--drivers/mca/mca-bus.c28
-rw-r--r--drivers/mca/mca-driver.c13
-rw-r--r--drivers/md/Kconfig9
-rw-r--r--drivers/md/Makefile1
-rw-r--r--drivers/md/bitmap.c8
-rw-r--r--drivers/md/dm-bio-list.h26
-rw-r--r--drivers/md/dm-crypt.c91
-rw-r--r--drivers/md/dm-delay.c383
-rw-r--r--drivers/md/dm-exception-store.c54
-rw-r--r--drivers/md/dm-hw-handler.h1
-rw-r--r--drivers/md/dm-io.c232
-rw-r--r--drivers/md/dm-io.h83
-rw-r--r--drivers/md/dm-log.c77
-rw-r--r--drivers/md/dm-mpath.c3
-rw-r--r--drivers/md/dm-raid1.c187
-rw-r--r--drivers/md/dm-table.c10
-rw-r--r--drivers/md/dm.c1
-rw-r--r--drivers/md/kcopyd.c28
-rw-r--r--drivers/md/md.c162
-rw-r--r--drivers/md/raid1.c33
-rw-r--r--drivers/md/raid5.c4
-rw-r--r--drivers/media/Kconfig10
-rw-r--r--drivers/media/Makefile2
-rw-r--r--drivers/media/common/saa7146_core.c54
-rw-r--r--drivers/media/common/saa7146_fops.c1
-rw-r--r--drivers/media/dvb/Kconfig24
-rw-r--r--drivers/media/dvb/bt8xx/dst.c3
-rw-r--r--drivers/media/dvb/bt8xx/dst_common.h1
-rw-r--r--drivers/media/dvb/dvb-core/Kconfig14
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c15
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h5
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-remote.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h2
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.c565
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.h13
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x-fe.c14
-rw-r--r--drivers/media/dvb/frontends/dib7000m.c2
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c2
-rw-r--r--drivers/media/dvb/frontends/tda10021.c2
-rw-r--r--drivers/media/dvb/frontends/ves1x93.c2
-rw-r--r--drivers/media/dvb/pluto2/pluto2.c8
-rw-r--r--drivers/media/dvb/ttpci/av7110.c9
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c1
-rw-r--r--drivers/media/dvb/ttpci/av7110_ca.c1
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c1
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c1
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c2
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c37
-rw-r--r--drivers/media/radio/Kconfig11
-rw-r--r--drivers/media/radio/dsbr100.c346
-rw-r--r--drivers/media/radio/radio-cadet.c297
-rw-r--r--drivers/media/radio/radio-maestro.c3
-rw-r--r--drivers/media/radio/radio-zoltrix.c1
-rw-r--r--drivers/media/video/Kconfig45
-rw-r--r--drivers/media/video/cafe_ccic-regs.h6
-rw-r--r--drivers/media/video/cafe_ccic.c18
-rw-r--r--drivers/media/video/cpia.h1
-rw-r--r--drivers/media/video/cpia_pp.c1
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c4
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c5
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c1
-rw-r--r--drivers/media/video/cx88/cx88-video.c1
-rw-r--r--drivers/media/video/cx88/cx88-vp3054-i2c.c7
-rw-r--r--drivers/media/video/cx88/cx88-vp3054-i2c.h1
-rw-r--r--drivers/media/video/dabusb.c1
-rw-r--r--drivers/media/video/em28xx/Kconfig3
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c2
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c2
-rw-r--r--drivers/media/video/et61x251/Kconfig2
-rw-r--r--drivers/media/video/ivtv/Kconfig2
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h8
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c12
-rw-r--r--drivers/media/video/ov511.h1
-rw-r--r--drivers/media/video/ov7670.c21
-rw-r--r--drivers/media/video/pvrusb2/Kconfig2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-encoder.c13
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c10
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c23
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-main.c1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c14
-rw-r--r--drivers/media/video/pwc/Kconfig2
-rw-r--r--drivers/media/video/pwc/philips.txt6
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c123
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c17
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c1
-rw-r--r--drivers/media/video/saa7134/saa7134.h3
-rw-r--r--drivers/media/video/se401.h1
-rw-r--r--drivers/media/video/sn9c102/Kconfig2
-rw-r--r--drivers/media/video/sn9c102/sn9c102.h2
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c91
-rw-r--r--drivers/media/video/sn9c102/sn9c102_devtable.h4
-rw-r--r--drivers/media/video/sn9c102/sn9c102_hv7131d.c6
-rw-r--r--drivers/media/video/sn9c102/sn9c102_hv7131r.c8
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mi0343.c51
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mi0360.c220
-rw-r--r--drivers/media/video/sn9c102/sn9c102_ov7630.c25
-rw-r--r--drivers/media/video/sn9c102/sn9c102_ov7660.c63
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas106b.c14
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas202bcb.c48
-rw-r--r--drivers/media/video/sn9c102/sn9c102_sensor.h33
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5110c1b.c2
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5110d.c2
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5130d1b.c2
-rw-r--r--drivers/media/video/tuner-simple.c10
-rw-r--r--drivers/media/video/tvaudio.c1
-rw-r--r--drivers/media/video/usbvideo/Kconfig8
-rw-r--r--drivers/media/video/usbvideo/usbvideo.c1
-rw-r--r--drivers/media/video/usbvideo/vicam.c2
-rw-r--r--drivers/media/video/usbvision/Kconfig2
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c1
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c1
-rw-r--r--drivers/media/video/v4l1-compat.c63
-rw-r--r--drivers/media/video/v4l2-common.c1
-rw-r--r--drivers/media/video/video-buf.c4
-rw-r--r--drivers/media/video/videodev.c51
-rw-r--r--drivers/media/video/zc0301/Kconfig2
-rw-r--r--drivers/media/video/zoran_driver.c2
-rw-r--r--drivers/message/fusion/Kconfig1
-rw-r--r--drivers/message/fusion/lsi/mpi_history.txt2
-rw-r--r--drivers/message/fusion/mptbase.c2
-rw-r--r--drivers/message/i2o/Kconfig1
-rw-r--r--drivers/message/i2o/i2o_lan.h159
-rw-r--r--drivers/mfd/Kconfig1
-rw-r--r--drivers/mfd/ucb1x00-ts.c1
-rw-r--r--drivers/misc/Kconfig20
-rw-r--r--drivers/misc/Makefile2
-rw-r--r--drivers/misc/asus-laptop.c66
-rw-r--r--drivers/misc/blink.c27
-rw-r--r--drivers/misc/msi-laptop.c12
-rw-r--r--drivers/misc/phantom.c463
-rw-r--r--drivers/misc/sony-laptop.c8
-rw-r--r--drivers/misc/tifm_7xx1.c27
-rw-r--r--drivers/mmc/Kconfig11
-rw-r--r--drivers/mmc/card/Kconfig3
-rw-r--r--drivers/mmc/card/block.c17
-rw-r--r--drivers/mmc/core/Kconfig1
-rw-r--r--drivers/mmc/core/core.c10
-rw-r--r--drivers/mmc/host/Kconfig19
-rw-r--r--drivers/mmc/host/au1xmmc.c35
-rw-r--r--drivers/mmc/host/pxamci.c18
-rw-r--r--drivers/mmc/host/sdhci.c9
-rw-r--r--drivers/mmc/host/tifm_sd.c13
-rw-r--r--drivers/mtd/Kconfig1
-rw-r--r--drivers/mtd/chips/Kconfig40
-rw-r--r--drivers/mtd/chips/Makefile4
-rw-r--r--drivers/mtd/chips/amd_flash.c1396
-rw-r--r--drivers/mtd/chips/jedec.c935
-rw-r--r--drivers/mtd/chips/sharp.c601
-rw-r--r--drivers/mtd/devices/block2mtd.c2
-rw-r--r--drivers/mtd/maps/Kconfig18
-rw-r--r--drivers/mtd/maps/Makefile2
-rw-r--r--drivers/mtd/maps/arctic-mtd.c145
-rw-r--r--drivers/mtd/maps/beech-mtd.c122
-rw-r--r--drivers/mtd/maps/nettel.c2
-rw-r--r--drivers/mtd/maps/physmap_of.c10
-rw-r--r--drivers/mtd/mtd_blkdevs.c4
-rw-r--r--drivers/mtd/mtdpart.c1
-rw-r--r--drivers/mtd/nand/Kconfig21
-rw-r--r--drivers/mtd/nand/Makefile2
-rw-r--r--drivers/mtd/nand/at91_nand.c10
-rw-r--r--drivers/mtd/nand/cafe_ecc.c1381
-rw-r--r--drivers/mtd/nand/cafe_nand.c (renamed from drivers/mtd/nand/cafe.c)137
-rw-r--r--drivers/mtd/nand/nand_base.c11
-rw-r--r--drivers/mtd/nand/plat_nand.c150
-rw-r--r--drivers/mtd/onenand/onenand_base.c2
-rw-r--r--drivers/mtd/ubi/eba.c3
-rw-r--r--drivers/net/3c509.c5
-rw-r--r--drivers/net/3c59x.c2
-rw-r--r--drivers/net/Kconfig38
-rw-r--r--drivers/net/Makefile9
-rw-r--r--drivers/net/arm/at91_ether.c49
-rw-r--r--drivers/net/arm/at91_ether.h49
-rw-r--r--drivers/net/arm/ether1.c6
-rw-r--r--drivers/net/arm/ether3.c6
-rw-r--r--drivers/net/arm/etherh.c17
-rw-r--r--drivers/net/atl1/atl1_ethtool.c19
-rw-r--r--drivers/net/atl1/atl1_hw.c44
-rw-r--r--drivers/net/atl1/atl1_main.c95
-rw-r--r--drivers/net/atl1/atl1_param.c32
-rw-r--r--drivers/net/atp.c8
-rw-r--r--drivers/net/bmac.c5
-rw-r--r--drivers/net/bonding/bond_main.c2
-rw-r--r--drivers/net/declance.c2
-rw-r--r--drivers/net/dm9000.c15
-rw-r--r--drivers/net/e1000/e1000.h4
-rw-r--r--drivers/net/e1000/e1000_main.c45
-rw-r--r--drivers/net/eepro.c2
-rw-r--r--drivers/net/eepro100.c2
-rw-r--r--drivers/net/ehea/ehea_main.c19
-rw-r--r--drivers/net/epic100.c10
-rw-r--r--drivers/net/fs_enet/mac-scc.c2
-rw-r--r--drivers/net/gianfar.c11
-rw-r--r--drivers/net/hamradio/Kconfig2
-rw-r--r--drivers/net/ibm_emac/ibm_emac_core.c2
-rw-r--r--drivers/net/ibm_emac/ibm_emac_mal.c3
-rw-r--r--drivers/net/ibm_emac/ibm_emac_mal.h3
-rw-r--r--drivers/net/ibm_emac/ibm_emac_phy.c60
-rw-r--r--drivers/net/ibm_emac/ibm_emac_rgmii.c2
-rw-r--r--drivers/net/ibm_emac/ibm_emac_rgmii.h2
-rw-r--r--drivers/net/ibm_emac/ibm_emac_tah.c2
-rw-r--r--drivers/net/ibm_emac/ibm_emac_tah.h2
-rw-r--r--drivers/net/ibm_emac/ibm_emac_zmii.c2
-rw-r--r--drivers/net/ibm_emac/ibm_emac_zmii.h2
-rw-r--r--drivers/net/irda/Kconfig14
-rw-r--r--drivers/net/irda/Makefile1
-rw-r--r--drivers/net/irda/donauboe.h2
-rw-r--r--drivers/net/irda/kingsun-sir.c657
-rw-r--r--drivers/net/irda/sir_dev.c1
-rw-r--r--drivers/net/irda/sir_dongle.c1
-rw-r--r--drivers/net/irda/smsc-ircc2.c112
-rw-r--r--drivers/net/irda/vlsi_ir.c1
-rw-r--r--drivers/net/ixgb/ixgb.h2
-rw-r--r--drivers/net/ixgb/ixgb_ee.c2
-rw-r--r--drivers/net/ixgb/ixgb_main.c36
-rw-r--r--drivers/net/mace.c4
-rw-r--r--drivers/net/meth.h2
-rw-r--r--drivers/net/mlx4/Makefile4
-rw-r--r--drivers/net/mlx4/alloc.c180
-rw-r--r--drivers/net/mlx4/catas.c70
-rw-r--r--drivers/net/mlx4/cmd.c429
-rw-r--r--drivers/net/mlx4/cq.c254
-rw-r--r--drivers/net/mlx4/eq.c697
-rw-r--r--drivers/net/mlx4/fw.c775
-rw-r--r--drivers/net/mlx4/fw.h167
-rw-r--r--drivers/net/mlx4/icm.c380
-rw-r--r--drivers/net/mlx4/icm.h135
-rw-r--r--drivers/net/mlx4/intf.c165
-rw-r--r--drivers/net/mlx4/main.c934
-rw-r--r--drivers/net/mlx4/mcg.c380
-rw-r--r--drivers/net/mlx4/mlx4.h347
-rw-r--r--drivers/net/mlx4/mr.c479
-rw-r--r--drivers/net/mlx4/pd.c102
-rw-r--r--drivers/net/mlx4/profile.c238
-rw-r--r--drivers/net/mlx4/qp.c280
-rw-r--r--drivers/net/mlx4/reset.c182
-rw-r--r--drivers/net/mlx4/srq.c227
-rw-r--r--drivers/net/myri10ge/myri10ge.c261
-rw-r--r--drivers/net/myri10ge/myri10ge_mcp.h20
-rw-r--r--drivers/net/natsemi.c71
-rw-r--r--drivers/net/ne.c123
-rw-r--r--drivers/net/ne2k-pci.c3
-rw-r--r--drivers/net/netxen/netxen_nic_init.c2
-rw-r--r--drivers/net/netxen/netxen_nic_main.c2
-rw-r--r--drivers/net/ns83820.c1
-rw-r--r--drivers/net/pasemi_mac.c421
-rw-r--r--drivers/net/pasemi_mac.h27
-rw-r--r--drivers/net/pcmcia/Kconfig23
-rw-r--r--drivers/net/pcmcia/ibmtr_cs.c14
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c14
-rw-r--r--drivers/net/phy/Kconfig21
-rw-r--r--drivers/net/phy/davicom.c34
-rw-r--r--drivers/net/phy/phy.c6
-rw-r--r--drivers/net/ppp_generic.c1
-rw-r--r--drivers/net/s2io.c368
-rw-r--r--drivers/net/s2io.h32
-rw-r--r--drivers/net/sgiseeq.c83
-rw-r--r--drivers/net/skge.c22
-rw-r--r--drivers/net/sky2.c57
-rw-r--r--drivers/net/smc911x.c6
-rw-r--r--drivers/net/smc91x.h34
-rw-r--r--drivers/net/spider_net.c15
-rw-r--r--drivers/net/sundance.c3
-rw-r--r--drivers/net/sungem.c2
-rw-r--r--drivers/net/sungem_phy.c2
-rw-r--r--drivers/net/tc35815.c1
-rw-r--r--drivers/net/tg3.c11
-rw-r--r--drivers/net/tg3.h2
-rw-r--r--drivers/net/tsi108_eth.c12
-rw-r--r--drivers/net/tsi108_eth.h9
-rw-r--r--drivers/net/tulip/interrupt.c2
-rw-r--r--drivers/net/tulip/winbond-840.c2
-rw-r--r--drivers/net/tulip/xircom_cb.c2
-rw-r--r--drivers/net/typhoon.c2
-rw-r--r--drivers/net/ucc_geth.c82
-rw-r--r--drivers/net/ucc_geth_mii.c13
-rw-r--r--drivers/net/ucc_geth_mii.h10
-rw-r--r--drivers/net/usb/Kconfig (renamed from drivers/usb/net/Kconfig)0
-rw-r--r--drivers/net/usb/Makefile (renamed from drivers/usb/net/Makefile)0
-rw-r--r--drivers/net/usb/asix.c (renamed from drivers/usb/net/asix.c)0
-rw-r--r--drivers/net/usb/catc.c (renamed from drivers/usb/net/catc.c)0
-rw-r--r--drivers/net/usb/cdc_ether.c (renamed from drivers/usb/net/cdc_ether.c)0
-rw-r--r--drivers/net/usb/cdc_subset.c (renamed from drivers/usb/net/cdc_subset.c)0
-rw-r--r--drivers/net/usb/dm9601.c (renamed from drivers/usb/net/dm9601.c)0
-rw-r--r--drivers/net/usb/gl620a.c (renamed from drivers/usb/net/gl620a.c)0
-rw-r--r--drivers/net/usb/kaweth.c (renamed from drivers/usb/net/kaweth.c)0
-rw-r--r--drivers/net/usb/kawethfw.h (renamed from drivers/usb/net/kawethfw.h)0
-rw-r--r--drivers/net/usb/mcs7830.c (renamed from drivers/usb/net/mcs7830.c)0
-rw-r--r--drivers/net/usb/net1080.c (renamed from drivers/usb/net/net1080.c)0
-rw-r--r--drivers/net/usb/pegasus.c (renamed from drivers/usb/net/pegasus.c)0
-rw-r--r--drivers/net/usb/pegasus.h (renamed from drivers/usb/net/pegasus.h)0
-rw-r--r--drivers/net/usb/plusb.c (renamed from drivers/usb/net/plusb.c)0
-rw-r--r--drivers/net/usb/rndis_host.c (renamed from drivers/usb/net/rndis_host.c)0
-rw-r--r--drivers/net/usb/rtl8150.c (renamed from drivers/usb/net/rtl8150.c)0
-rw-r--r--drivers/net/usb/usbnet.c (renamed from drivers/usb/net/usbnet.c)0
-rw-r--r--drivers/net/usb/usbnet.h (renamed from drivers/usb/net/usbnet.h)2
-rw-r--r--drivers/net/usb/zaurus.c (renamed from drivers/usb/net/zaurus.c)0
-rw-r--r--drivers/net/wan/Kconfig34
-rw-r--r--drivers/net/wan/cosa.c1
-rw-r--r--drivers/net/wireless/Kconfig3
-rw-r--r--drivers/net/wireless/airo.c1
-rw-r--r--drivers/net/wireless/airport.c2
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx.h18
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_dma.c4
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.c81
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_main.h19
-rw-r--r--drivers/net/wireless/hostap/hostap_ioctl.c1
-rw-r--r--drivers/net/wireless/libertas/Makefile9
-rw-r--r--drivers/net/wireless/libertas/README516
-rw-r--r--drivers/net/wireless/libertas/assoc.c41
-rw-r--r--drivers/net/wireless/libertas/cmd.c23
-rw-r--r--drivers/net/wireless/libertas/cmdresp.c4
-rw-r--r--drivers/net/wireless/libertas/debugfs.c31
-rw-r--r--drivers/net/wireless/libertas/defs.h52
-rw-r--r--drivers/net/wireless/libertas/dev.h14
-rw-r--r--drivers/net/wireless/libertas/fw.c9
-rw-r--r--drivers/net/wireless/libertas/if_usb.c5
-rw-r--r--drivers/net/wireless/libertas/if_usb.h2
-rw-r--r--drivers/net/wireless/libertas/ioctl.c1529
-rw-r--r--drivers/net/wireless/libertas/join.c194
-rw-r--r--drivers/net/wireless/libertas/join.h7
-rw-r--r--drivers/net/wireless/libertas/main.c7
-rw-r--r--drivers/net/wireless/libertas/rx.c4
-rw-r--r--drivers/net/wireless/libertas/scan.c203
-rw-r--r--drivers/net/wireless/libertas/scan.h22
-rw-r--r--drivers/net/wireless/libertas/tx.c2
-rw-r--r--drivers/net/wireless/libertas/version.h7
-rw-r--r--drivers/net/wireless/libertas/wext.c448
-rw-r--r--drivers/net/wireless/libertas/wext.h85
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c2
-rw-r--r--drivers/net/wireless/prism54/islpci_dev.c2
-rw-r--r--drivers/net/wireless/wavelan_cs.c4
-rw-r--r--drivers/net/wireless/wavelan_cs.p.h2
-rw-r--r--drivers/net/wireless/zd1211rw/zd_usb.c4
-rw-r--r--drivers/net/yellowfin.c1
-rw-r--r--drivers/oprofile/buffer_sync.c1
-rw-r--r--drivers/parisc/lba_pci.c1
-rw-r--r--drivers/parport/Kconfig1
-rw-r--r--drivers/parport/parport_cs.c2
-rw-r--r--drivers/parport/parport_mfc3.c1
-rw-r--r--drivers/parport/parport_pc.c71
-rw-r--r--drivers/parport/parport_serial.c10
-rw-r--r--drivers/parport/parport_sunbpp.c1
-rw-r--r--drivers/parport/share.c5
-rw-r--r--drivers/pci/hotplug/acpiphp_core.c1
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c1
-rw-r--r--drivers/pci/hotplug/ibmphp_core.c1
-rw-r--r--drivers/pci/hotplug/ibmphp_hpc.c2
-rw-r--r--drivers/pci/hotplug/pci_hotplug_core.c1
-rw-r--r--drivers/pci/hotplug/rpadlpar_sysfs.c5
-rw-r--r--drivers/pci/hotplug/rpaphp_core.c11
-rw-r--r--drivers/pci/hotplug/sgi_hotplug.c36
-rw-r--r--drivers/pci/hotplug/shpchp_ctrl.c1
-rw-r--r--drivers/pci/msi.c7
-rw-r--r--drivers/pci/pci-driver.c2
-rw-r--r--drivers/pci/pcie/aer/aerdrv.h1
-rw-r--r--drivers/pci/proc.c1
-rw-r--r--drivers/pci/quirks.c1
-rw-r--r--drivers/pcmcia/pxa2xx_mainstone.c1
-rw-r--r--drivers/pcmcia/pxa2xx_sharpsl.c1
-rw-r--r--drivers/pnp/Kconfig1
-rw-r--r--drivers/pnp/core.c11
-rw-r--r--drivers/pnp/pnpacpi/core.c55
-rw-r--r--drivers/pnp/pnpbios/core.c17
-rw-r--r--drivers/pnp/quirks.c30
-rw-r--r--drivers/ps3/vuart.c8
-rw-r--r--drivers/rtc/Kconfig279
-rw-r--r--drivers/rtc/Makefile8
-rw-r--r--drivers/rtc/class.c118
-rw-r--r--drivers/rtc/hctosys.c14
-rw-r--r--drivers/rtc/interface.c86
-rw-r--r--drivers/rtc/rtc-at91rm9200.c32
-rw-r--r--drivers/rtc/rtc-cmos.c79
-rw-r--r--drivers/rtc/rtc-core.h70
-rw-r--r--drivers/rtc/rtc-dev.c184
-rw-r--r--drivers/rtc/rtc-ds1553.c2
-rw-r--r--drivers/rtc/rtc-lib.c81
-rw-r--r--drivers/rtc/rtc-max6900.c311
-rw-r--r--drivers/rtc/rtc-omap.c57
-rw-r--r--drivers/rtc/rtc-pl031.c2
-rw-r--r--drivers/rtc/rtc-proc.c68
-rw-r--r--drivers/rtc/rtc-rs5c313.c423
-rw-r--r--drivers/rtc/rtc-s3c.c26
-rw-r--r--drivers/rtc/rtc-sa1100.c4
-rw-r--r--drivers/rtc/rtc-sh.c8
-rw-r--r--drivers/rtc/rtc-sysfs.c129
-rw-r--r--drivers/rtc/rtc-test.c6
-rw-r--r--drivers/rtc/rtc-vr41xx.c32
-rw-r--r--drivers/s390/block/Kconfig11
-rw-r--r--drivers/s390/block/dasd.c8
-rw-r--r--drivers/s390/block/dasd_diag.c10
-rw-r--r--drivers/s390/block/dasd_eckd.c6
-rw-r--r--drivers/s390/block/dasd_ioctl.c4
-rw-r--r--drivers/s390/char/Kconfig (renamed from drivers/s390/Kconfig)111
-rw-r--r--drivers/s390/char/monreader.c14
-rw-r--r--drivers/s390/char/raw3270.c5
-rw-r--r--drivers/s390/char/sclp.h3
-rw-r--r--drivers/s390/char/sclp_rw.c2
-rw-r--r--drivers/s390/char/sclp_sdias.c8
-rw-r--r--drivers/s390/char/zcore.c9
-rw-r--r--drivers/s390/cio/css.c3
-rw-r--r--drivers/s390/cio/css.h2
-rw-r--r--drivers/s390/cio/device.c4
-rw-r--r--drivers/s390/cio/device_ops.c11
-rw-r--r--drivers/s390/cio/qdio.c38
-rw-r--r--drivers/s390/cio/qdio.h4
-rw-r--r--drivers/s390/net/Kconfig8
-rw-r--r--drivers/s390/net/netiucv.c5
-rw-r--r--drivers/s390/net/qeth_eddp.c4
-rw-r--r--drivers/s390/net/qeth_eddp.h3
-rw-r--r--drivers/s390/net/qeth_main.c47
-rw-r--r--drivers/s390/net/qeth_mpc.c101
-rw-r--r--drivers/s390/net/qeth_mpc.h219
-rw-r--r--drivers/s390/net/qeth_sys.c2
-rw-r--r--drivers/s390/scsi/zfcp_aux.c98
-rw-r--r--drivers/s390/scsi/zfcp_dbf.c2
-rw-r--r--drivers/s390/scsi/zfcp_def.h41
-rw-r--r--drivers/s390/scsi/zfcp_erp.c89
-rw-r--r--drivers/s390/scsi/zfcp_ext.h4
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c50
-rw-r--r--drivers/s390/scsi/zfcp_qdio.c51
-rw-r--r--drivers/s390/scsi/zfcp_scsi.c9
-rw-r--r--drivers/sbus/char/bbc_i2c.c1
-rw-r--r--drivers/sbus/char/bpp.c3
-rw-r--r--drivers/sbus/char/display7seg.c1
-rw-r--r--drivers/sbus/char/envctrl.c1
-rw-r--r--drivers/sbus/char/rtc.c1
-rw-r--r--drivers/sbus/char/vfc_dev.c1
-rw-r--r--drivers/scsi/Kconfig8
-rw-r--r--drivers/scsi/aacraid/comminit.c3
-rw-r--r--drivers/scsi/aacraid/commsup.c6
-rw-r--r--drivers/scsi/aacraid/dpcsup.c6
-rw-r--r--drivers/scsi/aacraid/rx.c4
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.h1
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_pci.c2
-rw-r--r--drivers/scsi/aic7xxx/aic7xxx_osm.h1
-rw-r--r--drivers/scsi/aic94xx/Makefile2
-rw-r--r--drivers/scsi/arm/arxescsi.c12
-rw-r--r--drivers/scsi/arm/cumana_2.c16
-rw-r--r--drivers/scsi/arm/eesox.c16
-rw-r--r--drivers/scsi/arm/powertec.c16
-rw-r--r--drivers/scsi/ch.c9
-rw-r--r--drivers/scsi/dc395x.c6
-rw-r--r--drivers/scsi/dpt_i2o.c18
-rw-r--r--drivers/scsi/ibmvscsi/ibmvstgt.c8
-rw-r--r--drivers/scsi/ibmvscsi/rpa_vscsi.c4
-rw-r--r--drivers/scsi/ide-scsi.c30
-rw-r--r--drivers/scsi/ipr.c349
-rw-r--r--drivers/scsi/ipr.h33
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c36
-rw-r--r--drivers/scsi/lpfc/lpfc.h33
-rw-r--r--drivers/scsi/lpfc/lpfc_attr.c212
-rw-r--r--drivers/scsi/lpfc/lpfc_crtn.h32
-rw-r--r--drivers/scsi/lpfc/lpfc_ct.c24
-rw-r--r--drivers/scsi/lpfc/lpfc_disc.h28
-rw-r--r--drivers/scsi/lpfc/lpfc_els.c552
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c884
-rw-r--r--drivers/scsi/lpfc/lpfc_hw.h11
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c516
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c3
-rw-r--r--drivers/scsi/lpfc/lpfc_nportdisc.c307
-rw-r--r--drivers/scsi/lpfc/lpfc_scsi.c109
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.c427
-rw-r--r--drivers/scsi/lpfc/lpfc_sli.h12
-rw-r--r--drivers/scsi/lpfc/lpfc_version.h6
-rw-r--r--drivers/scsi/mac53c94.c2
-rw-r--r--drivers/scsi/megaraid.c20
-rw-r--r--drivers/scsi/megaraid.h4
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.c4
-rw-r--r--drivers/scsi/mesh.c16
-rw-r--r--drivers/scsi/qla1280.c2
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c44
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c15
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c6
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h2
-rw-r--r--drivers/scsi/qla4xxx/ql4_dbg.c4
-rw-r--r--drivers/scsi/qla4xxx/ql4_glbl.h9
-rw-r--r--drivers/scsi/qla4xxx/ql4_init.c18
-rw-r--r--drivers/scsi/qla4xxx/ql4_iocb.c18
-rw-r--r--drivers/scsi/qla4xxx/ql4_mbx.c19
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c9
-rw-r--r--drivers/scsi/scsi_debug.c1
-rw-r--r--drivers/scsi/scsi_error.c3
-rw-r--r--drivers/scsi/scsi_lib.c2
-rw-r--r--drivers/scsi/scsi_transport_fc.c158
-rw-r--r--drivers/scsi/sg.c1
-rw-r--r--drivers/scsi/sgiwd93.c264
-rw-r--r--drivers/scsi/sni_53c710.c2
-rw-r--r--drivers/scsi/tmscsim.c225
-rw-r--r--drivers/scsi/tmscsim.h12
-rw-r--r--drivers/serial/8250.c23
-rw-r--r--drivers/serial/8250_acorn.c3
-rw-r--r--drivers/serial/Kconfig32
-rw-r--r--drivers/serial/Makefile1
-rw-r--r--drivers/serial/bfin_5xx.c125
-rw-r--r--drivers/serial/cpm_uart/cpm_uart.h2
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c15
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm1.c6
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm2.c6
-rw-r--r--drivers/serial/icom.c56
-rw-r--r--drivers/serial/jsm/jsm_neo.c7
-rw-r--r--drivers/serial/jsm/jsm_tty.c1
-rw-r--r--drivers/serial/mpc52xx_uart.c7
-rw-r--r--drivers/serial/of_serial.c4
-rw-r--r--drivers/serial/pmac_zilog.c8
-rw-r--r--drivers/serial/s3c2410.c6
-rw-r--r--drivers/serial/serial_ks8695.c657
-rw-r--r--drivers/serial/serial_txx9.c32
-rw-r--r--drivers/serial/sunhv.c280
-rw-r--r--drivers/serial/sunzilog.c138
-rw-r--r--drivers/serial/sunzilog.h19
-rw-r--r--drivers/spi/Kconfig28
-rw-r--r--drivers/spi/Makefile3
-rw-r--r--drivers/spi/atmel_spi.c5
-rw-r--r--drivers/spi/au1550_spi.c974
-rw-r--r--drivers/spi/mpc52xx_psc_spi.c654
-rw-r--r--drivers/spi/spi.c33
-rw-r--r--drivers/spi/spi_bfin5xx.c152
-rw-r--r--drivers/spi/spi_butterfly.c83
-rw-r--r--drivers/spi/spidev.c584
-rw-r--r--drivers/telephony/Kconfig1
-rw-r--r--drivers/telephony/ixj.c3
-rw-r--r--drivers/usb/Kconfig3
-rw-r--r--drivers/usb/Makefile7
-rw-r--r--drivers/usb/atm/usbatm.c3
-rw-r--r--drivers/usb/class/cdc-acm.c1
-rw-r--r--drivers/usb/class/usblp.c1
-rw-r--r--drivers/usb/core/hub.c1
-rw-r--r--drivers/usb/core/inode.c1
-rw-r--r--drivers/usb/core/usb.c1
-rw-r--r--drivers/usb/gadget/Kconfig2
-rw-r--r--drivers/usb/gadget/at91_udc.c1
-rw-r--r--drivers/usb/gadget/dummy_hcd.c1
-rw-r--r--drivers/usb/gadget/ether.c1
-rw-r--r--drivers/usb/gadget/goku_udc.c1
-rw-r--r--drivers/usb/gadget/net2280.c1
-rw-r--r--drivers/usb/gadget/serial.c1
-rw-r--r--drivers/usb/gadget/zero.c1
-rw-r--r--drivers/usb/host/ehci-hcd.c1
-rw-r--r--drivers/usb/host/ehci-ps3.c4
-rw-r--r--drivers/usb/host/ohci-hcd.c1
-rw-r--r--drivers/usb/host/ohci-ppc-of.c4
-rw-r--r--drivers/usb/host/ohci-ps3.c4
-rw-r--r--drivers/usb/host/sl811-hcd.c1
-rw-r--r--drivers/usb/host/u132-hcd.c1
-rw-r--r--drivers/usb/image/mdc800.c1
-rw-r--r--drivers/usb/image/microtek.c1
-rw-r--r--drivers/usb/misc/auerswald.c2
-rw-r--r--drivers/usb/misc/idmouse.c1
-rw-r--r--drivers/usb/misc/legousbtower.c1
-rw-r--r--drivers/usb/misc/rio500.c1
-rw-r--r--drivers/usb/misc/sisusbvga/sisusb_con.c3
-rw-r--r--drivers/usb/mon/mon_main.c1
-rw-r--r--drivers/usb/serial/Kconfig2
-rw-r--r--drivers/usb/serial/aircable.c4
-rw-r--r--drivers/usb/serial/io_edgeport.c4
-rw-r--r--drivers/usb/serial/usb-serial.c1
-rw-r--r--drivers/usb/storage/usb.h1
-rw-r--r--drivers/video/Kconfig194
-rw-r--r--drivers/video/Makefile23
-rw-r--r--drivers/video/arcfb.c28
-rw-r--r--drivers/video/arkfb.c1200
-rw-r--r--drivers/video/atmel_lcdfb.c752
-rw-r--r--drivers/video/aty/ati_ids.h2
-rw-r--r--drivers/video/aty/aty128fb.c29
-rw-r--r--drivers/video/aty/atyfb_base.c40
-rw-r--r--drivers/video/aty/mach64_ct.c8
-rw-r--r--drivers/video/aty/mach64_cursor.c1
-rw-r--r--drivers/video/aty/radeon_base.c11
-rw-r--r--drivers/video/aty/radeon_monitor.c11
-rw-r--r--drivers/video/aty/radeon_pm.c12
-rw-r--r--drivers/video/aty/radeonfb.h4
-rw-r--r--drivers/video/backlight/Kconfig8
-rw-r--r--drivers/video/backlight/Makefile1
-rw-r--r--drivers/video/backlight/cr_bllcd.c287
-rw-r--r--drivers/video/cfbcopyarea.c14
-rw-r--r--drivers/video/cfbfillrect.c68
-rw-r--r--drivers/video/cirrusfb.c69
-rw-r--r--drivers/video/console/Kconfig7
-rw-r--r--drivers/video/console/fbcon.c136
-rw-r--r--drivers/video/console/fonts.c10
-rw-r--r--drivers/video/console/mdacon.c3
-rw-r--r--drivers/video/console/promcon.c3
-rw-r--r--drivers/video/console/softcursor.c2
-rw-r--r--drivers/video/console/sticon.c2
-rw-r--r--drivers/video/console/sticore.c2
-rw-r--r--drivers/video/console/vgacon.c26
-rw-r--r--drivers/video/display/Kconfig24
-rw-r--r--drivers/video/display/Makefile6
-rw-r--r--drivers/video/display/display-sysfs.c217
-rw-r--r--drivers/video/epson1355fb.c21
-rw-r--r--drivers/video/fb_defio.c151
-rw-r--r--drivers/video/fb_draw.h72
-rw-r--r--drivers/video/fb_sys_fops.c104
-rw-r--r--drivers/video/fbmem.c131
-rw-r--r--drivers/video/fbmon.c169
-rw-r--r--drivers/video/fbsysfs.c2
-rw-r--r--drivers/video/hecubafb.c471
-rw-r--r--drivers/video/i810/i810.h2
-rw-r--r--drivers/video/i810/i810_main.c2
-rw-r--r--drivers/video/intelfb/intelfbhw.c34
-rw-r--r--drivers/video/logo/Kconfig30
-rw-r--r--drivers/video/matrox/matroxfb_Ti3026.c2
-rw-r--r--drivers/video/matrox/matroxfb_accel.c2
-rw-r--r--drivers/video/matrox/matroxfb_base.c2
-rw-r--r--drivers/video/matrox/matroxfb_misc.c2
-rw-r--r--drivers/video/modedb.c4
-rw-r--r--drivers/video/neofb.c1
-rw-r--r--drivers/video/nvidia/nv_accel.c76
-rw-r--r--drivers/video/nvidia/nv_hw.c22
-rw-r--r--drivers/video/nvidia/nv_i2c.c94
-rw-r--r--drivers/video/nvidia/nv_local.h4
-rw-r--r--drivers/video/nvidia/nv_of.c8
-rw-r--r--drivers/video/nvidia/nv_setup.c5
-rw-r--r--drivers/video/nvidia/nv_type.h8
-rw-r--r--drivers/video/nvidia/nvidia.c83
-rw-r--r--drivers/video/offb.c32
-rw-r--r--drivers/video/pm2fb.c250
-rw-r--r--drivers/video/pm3fb.c3983
-rw-r--r--drivers/video/ps3fb.c12
-rw-r--r--drivers/video/pvr2fb.c4
-rw-r--r--drivers/video/pxafb.c2
-rw-r--r--drivers/video/riva/fbdev.c22
-rw-r--r--drivers/video/riva/nv4ref.h2445
-rw-r--r--drivers/video/riva/nv_driver.c6
-rw-r--r--drivers/video/riva/riva_hw.c12
-rw-r--r--drivers/video/riva/rivafb-i2c.c43
-rw-r--r--drivers/video/riva/rivafb.h2
-rw-r--r--drivers/video/s3fb.c49
-rw-r--r--drivers/video/savage/savagefb-i2c.c22
-rw-r--r--drivers/video/savage/savagefb.h10
-rw-r--r--drivers/video/savage/savagefb_driver.c39
-rw-r--r--drivers/video/sis/osdef.h5
-rw-r--r--drivers/video/sis/sis.h51
-rw-r--r--drivers/video/sis/sis_main.c106
-rw-r--r--drivers/video/skeletonfb.c219
-rw-r--r--drivers/video/sm501fb.c2
-rw-r--r--drivers/video/svgalib.c55
-rw-r--r--drivers/video/syscopyarea.c378
-rw-r--r--drivers/video/sysfillrect.c334
-rw-r--r--drivers/video/sysimgblt.c291
-rw-r--r--drivers/video/tgafb.c425
-rw-r--r--drivers/video/vermilion/Makefile5
-rw-r--r--drivers/video/vermilion/cr_pll.c208
-rw-r--r--drivers/video/vermilion/vermilion.c1195
-rw-r--r--drivers/video/vermilion/vermilion.h260
-rw-r--r--drivers/video/vfb.c8
-rw-r--r--drivers/video/vga16fb.c2
-rw-r--r--drivers/video/vgastate.c26
-rw-r--r--drivers/video/vt8623fb.c927
-rw-r--r--drivers/video/xilinxfb.c381
-rw-r--r--drivers/w1/Kconfig1
-rw-r--r--drivers/w1/masters/Kconfig8
-rw-r--r--drivers/w1/masters/Makefile2
-rw-r--r--drivers/w1/masters/ds1wm.c468
-rw-r--r--drivers/w1/w1.c2
-rw-r--r--drivers/w1/w1_int.c3
1151 files changed, 56291 insertions, 31385 deletions
diff --git a/drivers/Makefile b/drivers/Makefile
index 26ca9031ea49..adad2f3d438a 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -36,6 +36,7 @@ obj-$(CONFIG_FC4) += fc4/
36obj-$(CONFIG_SCSI) += scsi/ 36obj-$(CONFIG_SCSI) += scsi/
37obj-$(CONFIG_ATA) += ata/ 37obj-$(CONFIG_ATA) += ata/
38obj-$(CONFIG_FUSION) += message/ 38obj-$(CONFIG_FUSION) += message/
39obj-$(CONFIG_FIREWIRE) += firewire/
39obj-$(CONFIG_IEEE1394) += ieee1394/ 40obj-$(CONFIG_IEEE1394) += ieee1394/
40obj-y += cdrom/ 41obj-y += cdrom/
41obj-y += auxdisplay/ 42obj-y += auxdisplay/
diff --git a/drivers/acpi/dispatcher/dsmethod.c b/drivers/acpi/dispatcher/dsmethod.c
index 1683e5c5b94c..1cbe61905824 100644
--- a/drivers/acpi/dispatcher/dsmethod.c
+++ b/drivers/acpi/dispatcher/dsmethod.c
@@ -231,8 +231,10 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
231 * Obtain the method mutex if necessary. Do not acquire mutex for a 231 * Obtain the method mutex if necessary. Do not acquire mutex for a
232 * recursive call. 232 * recursive call.
233 */ 233 */
234 if (acpi_os_get_thread_id() != 234 if (!walk_state ||
235 obj_desc->method.mutex->mutex.owner_thread_id) { 235 !obj_desc->method.mutex->mutex.owner_thread ||
236 (walk_state->thread !=
237 obj_desc->method.mutex->mutex.owner_thread)) {
236 /* 238 /*
237 * Acquire the method mutex. This releases the interpreter if we 239 * Acquire the method mutex. This releases the interpreter if we
238 * block (and reacquires it before it returns) 240 * block (and reacquires it before it returns)
@@ -246,14 +248,14 @@ acpi_ds_begin_method_execution(struct acpi_namespace_node *method_node,
246 } 248 }
247 249
248 /* Update the mutex and walk info and save the original sync_level */ 250 /* Update the mutex and walk info and save the original sync_level */
249 obj_desc->method.mutex->mutex.owner_thread_id =
250 acpi_os_get_thread_id();
251 251
252 if (walk_state) { 252 if (walk_state) {
253 obj_desc->method.mutex->mutex. 253 obj_desc->method.mutex->mutex.
254 original_sync_level = 254 original_sync_level =
255 walk_state->thread->current_sync_level; 255 walk_state->thread->current_sync_level;
256 256
257 obj_desc->method.mutex->mutex.owner_thread =
258 walk_state->thread;
257 walk_state->thread->current_sync_level = 259 walk_state->thread->current_sync_level =
258 obj_desc->method.sync_level; 260 obj_desc->method.sync_level;
259 } else { 261 } else {
@@ -567,7 +569,7 @@ acpi_ds_terminate_control_method(union acpi_operand_object *method_desc,
567 569
568 acpi_os_release_mutex(method_desc->method.mutex->mutex. 570 acpi_os_release_mutex(method_desc->method.mutex->mutex.
569 os_mutex); 571 os_mutex);
570 method_desc->method.mutex->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED; 572 method_desc->method.mutex->mutex.owner_thread = NULL;
571 } 573 }
572 } 574 }
573 575
diff --git a/drivers/acpi/dispatcher/dsopcode.c b/drivers/acpi/dispatcher/dsopcode.c
index 6c6104a7a247..fc9da4879cbf 100644
--- a/drivers/acpi/dispatcher/dsopcode.c
+++ b/drivers/acpi/dispatcher/dsopcode.c
@@ -866,8 +866,7 @@ acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
866 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) && 866 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
867 (op->common.parent->common.aml_opcode != 867 (op->common.parent->common.aml_opcode !=
868 AML_VAR_PACKAGE_OP) 868 AML_VAR_PACKAGE_OP)
869 && (op->common.parent->common.aml_opcode != 869 && (op->common.parent->common.aml_opcode != AML_NAME_OP))) {
870 AML_NAME_OP))) {
871 walk_state->result_obj = obj_desc; 870 walk_state->result_obj = obj_desc;
872 } 871 }
873 } 872 }
diff --git a/drivers/acpi/dispatcher/dsutils.c b/drivers/acpi/dispatcher/dsutils.c
index e4073e05a75c..71503c036f7c 100644
--- a/drivers/acpi/dispatcher/dsutils.c
+++ b/drivers/acpi/dispatcher/dsutils.c
@@ -556,10 +556,9 @@ acpi_ds_create_operand(struct acpi_walk_state *walk_state,
556 * indicate this to the interpreter, set the 556 * indicate this to the interpreter, set the
557 * object to the root 557 * object to the root
558 */ 558 */
559 obj_desc = 559 obj_desc = ACPI_CAST_PTR(union
560 ACPI_CAST_PTR(union 560 acpi_operand_object,
561 acpi_operand_object, 561 acpi_gbl_root_node);
562 acpi_gbl_root_node);
563 status = AE_OK; 562 status = AE_OK;
564 } else { 563 } else {
565 /* 564 /*
diff --git a/drivers/acpi/dispatcher/dswstate.c b/drivers/acpi/dispatcher/dswstate.c
index 16c8e38b51ef..5afcdd9c7449 100644
--- a/drivers/acpi/dispatcher/dswstate.c
+++ b/drivers/acpi/dispatcher/dswstate.c
@@ -630,12 +630,9 @@ struct acpi_walk_state *acpi_ds_pop_walk_state(struct acpi_thread_state *thread)
630 * 630 *
631 ******************************************************************************/ 631 ******************************************************************************/
632 632
633struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id, 633struct acpi_walk_state *acpi_ds_create_walk_state(acpi_owner_id owner_id, union acpi_parse_object
634 union acpi_parse_object 634 *origin, union acpi_operand_object
635 *origin, 635 *method_desc, struct acpi_thread_state
636 union acpi_operand_object
637 *method_desc,
638 struct acpi_thread_state
639 *thread) 636 *thread)
640{ 637{
641 struct acpi_walk_state *walk_state; 638 struct acpi_walk_state *walk_state;
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c
index e08cf98f504f..82f496c07675 100644
--- a/drivers/acpi/ec.c
+++ b/drivers/acpi/ec.c
@@ -147,9 +147,10 @@ static inline int acpi_ec_check_status(struct acpi_ec *ec, enum ec_event event,
147 return 0; 147 return 0;
148} 148}
149 149
150static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, unsigned count) 150static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event,
151 unsigned count, int force_poll)
151{ 152{
152 if (acpi_ec_mode == EC_POLL) { 153 if (unlikely(force_poll) || acpi_ec_mode == EC_POLL) {
153 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); 154 unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY);
154 while (time_before(jiffies, delay)) { 155 while (time_before(jiffies, delay)) {
155 if (acpi_ec_check_status(ec, event, 0)) 156 if (acpi_ec_check_status(ec, event, 0))
@@ -173,14 +174,15 @@ static int acpi_ec_wait(struct acpi_ec *ec, enum ec_event event, unsigned count)
173 174
174static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command, 175static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
175 const u8 * wdata, unsigned wdata_len, 176 const u8 * wdata, unsigned wdata_len,
176 u8 * rdata, unsigned rdata_len) 177 u8 * rdata, unsigned rdata_len,
178 int force_poll)
177{ 179{
178 int result = 0; 180 int result = 0;
179 unsigned count = atomic_read(&ec->event_count); 181 unsigned count = atomic_read(&ec->event_count);
180 acpi_ec_write_cmd(ec, command); 182 acpi_ec_write_cmd(ec, command);
181 183
182 for (; wdata_len > 0; --wdata_len) { 184 for (; wdata_len > 0; --wdata_len) {
183 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count); 185 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll);
184 if (result) { 186 if (result) {
185 printk(KERN_ERR PREFIX 187 printk(KERN_ERR PREFIX
186 "write_cmd timeout, command = %d\n", command); 188 "write_cmd timeout, command = %d\n", command);
@@ -191,7 +193,7 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
191 } 193 }
192 194
193 if (!rdata_len) { 195 if (!rdata_len) {
194 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count); 196 result = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, count, force_poll);
195 if (result) { 197 if (result) {
196 printk(KERN_ERR PREFIX 198 printk(KERN_ERR PREFIX
197 "finish-write timeout, command = %d\n", command); 199 "finish-write timeout, command = %d\n", command);
@@ -202,7 +204,7 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
202 } 204 }
203 205
204 for (; rdata_len > 0; --rdata_len) { 206 for (; rdata_len > 0; --rdata_len) {
205 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count); 207 result = acpi_ec_wait(ec, ACPI_EC_EVENT_OBF_1, count, force_poll);
206 if (result) { 208 if (result) {
207 printk(KERN_ERR PREFIX "read timeout, command = %d\n", 209 printk(KERN_ERR PREFIX "read timeout, command = %d\n",
208 command); 210 command);
@@ -217,7 +219,8 @@ static int acpi_ec_transaction_unlocked(struct acpi_ec *ec, u8 command,
217 219
218static int acpi_ec_transaction(struct acpi_ec *ec, u8 command, 220static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
219 const u8 * wdata, unsigned wdata_len, 221 const u8 * wdata, unsigned wdata_len,
220 u8 * rdata, unsigned rdata_len) 222 u8 * rdata, unsigned rdata_len,
223 int force_poll)
221{ 224{
222 int status; 225 int status;
223 u32 glk; 226 u32 glk;
@@ -240,7 +243,7 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
240 /* Make sure GPE is enabled before doing transaction */ 243 /* Make sure GPE is enabled before doing transaction */
241 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR); 244 acpi_enable_gpe(NULL, ec->gpe, ACPI_NOT_ISR);
242 245
243 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0); 246 status = acpi_ec_wait(ec, ACPI_EC_EVENT_IBF_0, 0, 0);
244 if (status) { 247 if (status) {
245 printk(KERN_DEBUG PREFIX 248 printk(KERN_DEBUG PREFIX
246 "input buffer is not empty, aborting transaction\n"); 249 "input buffer is not empty, aborting transaction\n");
@@ -249,7 +252,8 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
249 252
250 status = acpi_ec_transaction_unlocked(ec, command, 253 status = acpi_ec_transaction_unlocked(ec, command,
251 wdata, wdata_len, 254 wdata, wdata_len,
252 rdata, rdata_len); 255 rdata, rdata_len,
256 force_poll);
253 257
254 end: 258 end:
255 259
@@ -267,12 +271,12 @@ static int acpi_ec_transaction(struct acpi_ec *ec, u8 command,
267int acpi_ec_burst_enable(struct acpi_ec *ec) 271int acpi_ec_burst_enable(struct acpi_ec *ec)
268{ 272{
269 u8 d; 273 u8 d;
270 return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1); 274 return acpi_ec_transaction(ec, ACPI_EC_BURST_ENABLE, NULL, 0, &d, 1, 0);
271} 275}
272 276
273int acpi_ec_burst_disable(struct acpi_ec *ec) 277int acpi_ec_burst_disable(struct acpi_ec *ec)
274{ 278{
275 return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0); 279 return acpi_ec_transaction(ec, ACPI_EC_BURST_DISABLE, NULL, 0, NULL, 0, 0);
276} 280}
277 281
278static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data) 282static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
@@ -281,7 +285,7 @@ static int acpi_ec_read(struct acpi_ec *ec, u8 address, u8 * data)
281 u8 d; 285 u8 d;
282 286
283 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ, 287 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_READ,
284 &address, 1, &d, 1); 288 &address, 1, &d, 1, 0);
285 *data = d; 289 *data = d;
286 return result; 290 return result;
287} 291}
@@ -290,7 +294,7 @@ static int acpi_ec_write(struct acpi_ec *ec, u8 address, u8 data)
290{ 294{
291 u8 wdata[2] = { address, data }; 295 u8 wdata[2] = { address, data };
292 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE, 296 return acpi_ec_transaction(ec, ACPI_EC_COMMAND_WRITE,
293 wdata, 2, NULL, 0); 297 wdata, 2, NULL, 0, 0);
294} 298}
295 299
296/* 300/*
@@ -349,13 +353,15 @@ EXPORT_SYMBOL(ec_write);
349 353
350int ec_transaction(u8 command, 354int ec_transaction(u8 command,
351 const u8 * wdata, unsigned wdata_len, 355 const u8 * wdata, unsigned wdata_len,
352 u8 * rdata, unsigned rdata_len) 356 u8 * rdata, unsigned rdata_len,
357 int force_poll)
353{ 358{
354 if (!first_ec) 359 if (!first_ec)
355 return -ENODEV; 360 return -ENODEV;
356 361
357 return acpi_ec_transaction(first_ec, command, wdata, 362 return acpi_ec_transaction(first_ec, command, wdata,
358 wdata_len, rdata, rdata_len); 363 wdata_len, rdata, rdata_len,
364 force_poll);
359} 365}
360 366
361EXPORT_SYMBOL(ec_transaction); 367EXPORT_SYMBOL(ec_transaction);
@@ -374,7 +380,7 @@ static int acpi_ec_query(struct acpi_ec *ec, u8 * data)
374 * bit to be cleared (and thus clearing the interrupt source). 380 * bit to be cleared (and thus clearing the interrupt source).
375 */ 381 */
376 382
377 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1); 383 result = acpi_ec_transaction(ec, ACPI_EC_COMMAND_QUERY, NULL, 0, &d, 1, 0);
378 if (result) 384 if (result)
379 return result; 385 return result;
380 386
@@ -410,6 +416,7 @@ static u32 acpi_ec_gpe_handler(void *data)
410 acpi_status status = AE_OK; 416 acpi_status status = AE_OK;
411 u8 value; 417 u8 value;
412 struct acpi_ec *ec = data; 418 struct acpi_ec *ec = data;
419
413 atomic_inc(&ec->event_count); 420 atomic_inc(&ec->event_count);
414 421
415 if (acpi_ec_mode == EC_INTR) { 422 if (acpi_ec_mode == EC_INTR) {
diff --git a/drivers/acpi/events/evgpe.c b/drivers/acpi/events/evgpe.c
index 635ba449ebc2..e22f4a973c0f 100644
--- a/drivers/acpi/events/evgpe.c
+++ b/drivers/acpi/events/evgpe.c
@@ -341,9 +341,8 @@ struct acpi_gpe_event_info *acpi_ev_get_gpe_event_info(acpi_handle gpe_device,
341 341
342 /* A Non-NULL gpe_device means this is a GPE Block Device */ 342 /* A Non-NULL gpe_device means this is a GPE Block Device */
343 343
344 obj_desc = 344 obj_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *)
345 acpi_ns_get_attached_object((struct acpi_namespace_node *) 345 gpe_device);
346 gpe_device);
347 if (!obj_desc || !obj_desc->device.gpe_block) { 346 if (!obj_desc || !obj_desc->device.gpe_block) {
348 return (NULL); 347 return (NULL);
349 } 348 }
diff --git a/drivers/acpi/events/evgpeblk.c b/drivers/acpi/events/evgpeblk.c
index ad5bc76edf46..902c287b3a4f 100644
--- a/drivers/acpi/events/evgpeblk.c
+++ b/drivers/acpi/events/evgpeblk.c
@@ -1033,8 +1033,7 @@ acpi_ev_initialize_gpe_block(struct acpi_namespace_node *gpe_device,
1033 1033
1034 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) == 1034 if (((gpe_event_info->flags & ACPI_GPE_DISPATCH_MASK) ==
1035 ACPI_GPE_DISPATCH_METHOD) 1035 ACPI_GPE_DISPATCH_METHOD)
1036 && (gpe_event_info-> 1036 && (gpe_event_info->flags & ACPI_GPE_TYPE_RUNTIME)) {
1037 flags & ACPI_GPE_TYPE_RUNTIME)) {
1038 gpe_enabled_count++; 1037 gpe_enabled_count++;
1039 } 1038 }
1040 1039
diff --git a/drivers/acpi/events/evmisc.c b/drivers/acpi/events/evmisc.c
index cae786ca8600..21cb749d0c75 100644
--- a/drivers/acpi/events/evmisc.c
+++ b/drivers/acpi/events/evmisc.c
@@ -196,15 +196,12 @@ acpi_ev_queue_notify_request(struct acpi_namespace_node * node,
196 notify_info->notify.value = (u16) notify_value; 196 notify_info->notify.value = (u16) notify_value;
197 notify_info->notify.handler_obj = handler_obj; 197 notify_info->notify.handler_obj = handler_obj;
198 198
199 acpi_ex_exit_interpreter(); 199 status =
200 200 acpi_os_execute(OSL_NOTIFY_HANDLER, acpi_ev_notify_dispatch,
201 acpi_ev_notify_dispatch(notify_info); 201 notify_info);
202
203 status = acpi_ex_enter_interpreter();
204 if (ACPI_FAILURE(status)) { 202 if (ACPI_FAILURE(status)) {
205 return_ACPI_STATUS(status); 203 acpi_ut_delete_generic_state(notify_info);
206 } 204 }
207
208 } 205 }
209 206
210 if (!handler_obj) { 207 if (!handler_obj) {
@@ -323,8 +320,9 @@ static u32 acpi_ev_global_lock_handler(void *context)
323 acpi_gbl_global_lock_acquired = TRUE; 320 acpi_gbl_global_lock_acquired = TRUE;
324 /* Send a unit to the semaphore */ 321 /* Send a unit to the semaphore */
325 322
326 if (ACPI_FAILURE(acpi_os_signal_semaphore( 323 if (ACPI_FAILURE
327 acpi_gbl_global_lock_semaphore, 1))) { 324 (acpi_os_signal_semaphore
325 (acpi_gbl_global_lock_semaphore, 1))) {
328 ACPI_ERROR((AE_INFO, 326 ACPI_ERROR((AE_INFO,
329 "Could not signal Global Lock semaphore")); 327 "Could not signal Global Lock semaphore"));
330 } 328 }
@@ -450,7 +448,9 @@ acpi_status acpi_ev_acquire_global_lock(u16 timeout)
450 } 448 }
451 449
452 if (ACPI_FAILURE(status)) { 450 if (ACPI_FAILURE(status)) {
453 status = acpi_ex_system_wait_mutex(acpi_gbl_global_lock_mutex, timeout); 451 status =
452 acpi_ex_system_wait_mutex(acpi_gbl_global_lock_mutex,
453 timeout);
454 } 454 }
455 if (ACPI_FAILURE(status)) { 455 if (ACPI_FAILURE(status)) {
456 return_ACPI_STATUS(status); 456 return_ACPI_STATUS(status);
diff --git a/drivers/acpi/events/evregion.c b/drivers/acpi/events/evregion.c
index 96b0e8431748..e99f0c435a47 100644
--- a/drivers/acpi/events/evregion.c
+++ b/drivers/acpi/events/evregion.c
@@ -291,7 +291,6 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
291 u32 bit_width, acpi_integer * value) 291 u32 bit_width, acpi_integer * value)
292{ 292{
293 acpi_status status; 293 acpi_status status;
294 acpi_status status2;
295 acpi_adr_space_handler handler; 294 acpi_adr_space_handler handler;
296 acpi_adr_space_setup region_setup; 295 acpi_adr_space_setup region_setup;
297 union acpi_operand_object *handler_desc; 296 union acpi_operand_object *handler_desc;
@@ -345,7 +344,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
345 * setup will potentially execute control methods 344 * setup will potentially execute control methods
346 * (e.g., _REG method for this region) 345 * (e.g., _REG method for this region)
347 */ 346 */
348 acpi_ex_exit_interpreter(); 347 acpi_ex_relinquish_interpreter();
349 348
350 status = region_setup(region_obj, ACPI_REGION_ACTIVATE, 349 status = region_setup(region_obj, ACPI_REGION_ACTIVATE,
351 handler_desc->address_space.context, 350 handler_desc->address_space.context,
@@ -353,10 +352,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
353 352
354 /* Re-enter the interpreter */ 353 /* Re-enter the interpreter */
355 354
356 status2 = acpi_ex_enter_interpreter(); 355 acpi_ex_reacquire_interpreter();
357 if (ACPI_FAILURE(status2)) {
358 return_ACPI_STATUS(status2);
359 }
360 356
361 /* Check for failure of the Region Setup */ 357 /* Check for failure of the Region Setup */
362 358
@@ -409,7 +405,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
409 * exit the interpreter because the handler *might* block -- we don't 405 * exit the interpreter because the handler *might* block -- we don't
410 * know what it will do, so we can't hold the lock on the intepreter. 406 * know what it will do, so we can't hold the lock on the intepreter.
411 */ 407 */
412 acpi_ex_exit_interpreter(); 408 acpi_ex_relinquish_interpreter();
413 } 409 }
414 410
415 /* Call the handler */ 411 /* Call the handler */
@@ -430,10 +426,7 @@ acpi_ev_address_space_dispatch(union acpi_operand_object *region_obj,
430 * We just returned from a non-default handler, we must re-enter the 426 * We just returned from a non-default handler, we must re-enter the
431 * interpreter 427 * interpreter
432 */ 428 */
433 status2 = acpi_ex_enter_interpreter(); 429 acpi_ex_reacquire_interpreter();
434 if (ACPI_FAILURE(status2)) {
435 return_ACPI_STATUS(status2);
436 }
437 } 430 }
438 431
439 return_ACPI_STATUS(status); 432 return_ACPI_STATUS(status);
diff --git a/drivers/acpi/events/evrgnini.c b/drivers/acpi/events/evrgnini.c
index a4fa7e6822a3..400d90fca966 100644
--- a/drivers/acpi/events/evrgnini.c
+++ b/drivers/acpi/events/evrgnini.c
@@ -228,7 +228,8 @@ acpi_ev_pci_config_region_setup(acpi_handle handle,
228 228
229 /* Install a handler for this PCI root bridge */ 229 /* Install a handler for this PCI root bridge */
230 230
231 status = acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL); 231 status =
232 acpi_install_address_space_handler((acpi_handle) pci_root_node, ACPI_ADR_SPACE_PCI_CONFIG, ACPI_DEFAULT_HANDLER, NULL, NULL);
232 if (ACPI_FAILURE(status)) { 233 if (ACPI_FAILURE(status)) {
233 if (status == AE_SAME_HANDLER) { 234 if (status == AE_SAME_HANDLER) {
234 /* 235 /*
diff --git a/drivers/acpi/events/evxface.c b/drivers/acpi/events/evxface.c
index a3379bafa676..6d866a01f5f4 100644
--- a/drivers/acpi/events/evxface.c
+++ b/drivers/acpi/events/evxface.c
@@ -91,7 +91,6 @@ acpi_status acpi_install_exception_handler(acpi_exception_handler handler)
91 91
92ACPI_EXPORT_SYMBOL(acpi_install_exception_handler) 92ACPI_EXPORT_SYMBOL(acpi_install_exception_handler)
93#endif /* ACPI_FUTURE_USAGE */ 93#endif /* ACPI_FUTURE_USAGE */
94
95/******************************************************************************* 94/*******************************************************************************
96 * 95 *
97 * FUNCTION: acpi_install_fixed_event_handler 96 * FUNCTION: acpi_install_fixed_event_handler
@@ -768,11 +767,9 @@ acpi_status acpi_acquire_global_lock(u16 timeout, u32 * handle)
768 return (AE_BAD_PARAMETER); 767 return (AE_BAD_PARAMETER);
769 } 768 }
770 769
771 status = acpi_ex_enter_interpreter(); 770 /* Must lock interpreter to prevent race conditions */
772 if (ACPI_FAILURE(status)) {
773 return (status);
774 }
775 771
772 acpi_ex_enter_interpreter();
776 status = acpi_ev_acquire_global_lock(timeout); 773 status = acpi_ev_acquire_global_lock(timeout);
777 acpi_ex_exit_interpreter(); 774 acpi_ex_exit_interpreter();
778 775
diff --git a/drivers/acpi/events/evxfevnt.c b/drivers/acpi/events/evxfevnt.c
index 17065e98807c..9cbd3414a574 100644
--- a/drivers/acpi/events/evxfevnt.c
+++ b/drivers/acpi/events/evxfevnt.c
@@ -472,7 +472,6 @@ acpi_status acpi_clear_gpe(acpi_handle gpe_device, u32 gpe_number, u32 flags)
472} 472}
473 473
474ACPI_EXPORT_SYMBOL(acpi_clear_gpe) 474ACPI_EXPORT_SYMBOL(acpi_clear_gpe)
475
476#ifdef ACPI_FUTURE_USAGE 475#ifdef ACPI_FUTURE_USAGE
477/******************************************************************************* 476/*******************************************************************************
478 * 477 *
@@ -568,7 +567,6 @@ acpi_get_gpe_status(acpi_handle gpe_device,
568 567
569ACPI_EXPORT_SYMBOL(acpi_get_gpe_status) 568ACPI_EXPORT_SYMBOL(acpi_get_gpe_status)
570#endif /* ACPI_FUTURE_USAGE */ 569#endif /* ACPI_FUTURE_USAGE */
571
572/******************************************************************************* 570/*******************************************************************************
573 * 571 *
574 * FUNCTION: acpi_install_gpe_block 572 * FUNCTION: acpi_install_gpe_block
diff --git a/drivers/acpi/executer/exconvrt.c b/drivers/acpi/executer/exconvrt.c
index d470e8b1f4ea..79f2c0d42c06 100644
--- a/drivers/acpi/executer/exconvrt.c
+++ b/drivers/acpi/executer/exconvrt.c
@@ -512,9 +512,8 @@ acpi_ex_convert_to_string(union acpi_operand_object * obj_desc,
512 * Create a new string object and string buffer 512 * Create a new string object and string buffer
513 * (-1 because of extra separator included in string_length from above) 513 * (-1 because of extra separator included in string_length from above)
514 */ 514 */
515 return_desc = 515 return_desc = acpi_ut_create_string_object((acpi_size)
516 acpi_ut_create_string_object((acpi_size) 516 (string_length - 1));
517 (string_length - 1));
518 if (!return_desc) { 517 if (!return_desc) {
519 return_ACPI_STATUS(AE_NO_MEMORY); 518 return_ACPI_STATUS(AE_NO_MEMORY);
520 } 519 }
diff --git a/drivers/acpi/executer/excreate.c b/drivers/acpi/executer/excreate.c
index ae97812681a3..6e9a23e47fef 100644
--- a/drivers/acpi/executer/excreate.c
+++ b/drivers/acpi/executer/excreate.c
@@ -50,7 +50,6 @@
50 50
51#define _COMPONENT ACPI_EXECUTER 51#define _COMPONENT ACPI_EXECUTER
52ACPI_MODULE_NAME("excreate") 52ACPI_MODULE_NAME("excreate")
53
54#ifndef ACPI_NO_METHOD_EXECUTION 53#ifndef ACPI_NO_METHOD_EXECUTION
55/******************************************************************************* 54/*******************************************************************************
56 * 55 *
@@ -583,10 +582,7 @@ acpi_ex_create_method(u8 * aml_start,
583 * Get the sync_level. If method is serialized, a mutex will be 582 * Get the sync_level. If method is serialized, a mutex will be
584 * created for this method when it is parsed. 583 * created for this method when it is parsed.
585 */ 584 */
586 if (acpi_gbl_all_methods_serialized) { 585 if (method_flags & AML_METHOD_SERIALIZED) {
587 obj_desc->method.sync_level = 0;
588 obj_desc->method.method_flags |= AML_METHOD_SERIALIZED;
589 } else if (method_flags & AML_METHOD_SERIALIZED) {
590 /* 586 /*
591 * ACPI 1.0: sync_level = 0 587 * ACPI 1.0: sync_level = 0
592 * ACPI 2.0: sync_level = sync_level in method declaration 588 * ACPI 2.0: sync_level = sync_level in method declaration
diff --git a/drivers/acpi/executer/exdump.c b/drivers/acpi/executer/exdump.c
index 1a73c14df2c5..51c9c29987c3 100644
--- a/drivers/acpi/executer/exdump.c
+++ b/drivers/acpi/executer/exdump.c
@@ -134,7 +134,7 @@ static struct acpi_exdump_info acpi_ex_dump_method[8] = {
134static struct acpi_exdump_info acpi_ex_dump_mutex[5] = { 134static struct acpi_exdump_info acpi_ex_dump_mutex[5] = {
135 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_mutex), NULL}, 135 {ACPI_EXD_INIT, ACPI_EXD_TABLE_SIZE(acpi_ex_dump_mutex), NULL},
136 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(mutex.sync_level), "Sync Level"}, 136 {ACPI_EXD_UINT8, ACPI_EXD_OFFSET(mutex.sync_level), "Sync Level"},
137 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread_id), "Owner Thread"}, 137 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.owner_thread), "Owner Thread"},
138 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth), 138 {ACPI_EXD_UINT16, ACPI_EXD_OFFSET(mutex.acquisition_depth),
139 "Acquire Depth"}, 139 "Acquire Depth"},
140 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"} 140 {ACPI_EXD_POINTER, ACPI_EXD_OFFSET(mutex.os_mutex), "OsMutex"}
@@ -451,9 +451,8 @@ void acpi_ex_dump_operand(union acpi_operand_object *obj_desc, u32 depth)
451 451
452 ACPI_FUNCTION_NAME(ex_dump_operand) 452 ACPI_FUNCTION_NAME(ex_dump_operand)
453 453
454 if (! 454 if (!((ACPI_LV_EXEC & acpi_dbg_level)
455 ((ACPI_LV_EXEC & acpi_dbg_level) 455 && (_COMPONENT & acpi_dbg_layer))) {
456 && (_COMPONENT & acpi_dbg_layer))) {
457 return; 456 return;
458 } 457 }
459 458
@@ -844,9 +843,8 @@ void acpi_ex_dump_namespace_node(struct acpi_namespace_node *node, u32 flags)
844 ACPI_FUNCTION_ENTRY(); 843 ACPI_FUNCTION_ENTRY();
845 844
846 if (!flags) { 845 if (!flags) {
847 if (! 846 if (!((ACPI_LV_OBJECTS & acpi_dbg_level)
848 ((ACPI_LV_OBJECTS & acpi_dbg_level) 847 && (_COMPONENT & acpi_dbg_layer))) {
849 && (_COMPONENT & acpi_dbg_layer))) {
850 return; 848 return;
851 } 849 }
852 } 850 }
@@ -1011,9 +1009,8 @@ acpi_ex_dump_object_descriptor(union acpi_operand_object *obj_desc, u32 flags)
1011 } 1009 }
1012 1010
1013 if (!flags) { 1011 if (!flags) {
1014 if (! 1012 if (!((ACPI_LV_OBJECTS & acpi_dbg_level)
1015 ((ACPI_LV_OBJECTS & acpi_dbg_level) 1013 && (_COMPONENT & acpi_dbg_layer))) {
1016 && (_COMPONENT & acpi_dbg_layer))) {
1017 return_VOID; 1014 return_VOID;
1018 } 1015 }
1019 } 1016 }
diff --git a/drivers/acpi/executer/exmutex.c b/drivers/acpi/executer/exmutex.c
index 4eb883bda6ae..6748e3ef0997 100644
--- a/drivers/acpi/executer/exmutex.c
+++ b/drivers/acpi/executer/exmutex.c
@@ -66,9 +66,10 @@ acpi_ex_link_mutex(union acpi_operand_object *obj_desc,
66 * 66 *
67 ******************************************************************************/ 67 ******************************************************************************/
68 68
69void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc, 69void acpi_ex_unlink_mutex(union acpi_operand_object *obj_desc)
70 struct acpi_thread_state *thread)
71{ 70{
71 struct acpi_thread_state *thread = obj_desc->mutex.owner_thread;
72
72 if (!thread) { 73 if (!thread) {
73 return; 74 return;
74 } 75 }
@@ -173,13 +174,16 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
173 174
174 /* Support for multiple acquires by the owning thread */ 175 /* Support for multiple acquires by the owning thread */
175 176
176 if (obj_desc->mutex.owner_thread_id == acpi_os_get_thread_id()) { 177 if (obj_desc->mutex.owner_thread) {
177 /* 178 if (obj_desc->mutex.owner_thread->thread_id ==
178 * The mutex is already owned by this thread, just increment the 179 walk_state->thread->thread_id) {
179 * acquisition depth 180 /*
180 */ 181 * The mutex is already owned by this thread, just increment the
181 obj_desc->mutex.acquisition_depth++; 182 * acquisition depth
182 return_ACPI_STATUS(AE_OK); 183 */
184 obj_desc->mutex.acquisition_depth++;
185 return_ACPI_STATUS(AE_OK);
186 }
183 } 187 }
184 188
185 /* Acquire the mutex, wait if necessary. Special case for Global Lock */ 189 /* Acquire the mutex, wait if necessary. Special case for Global Lock */
@@ -202,7 +206,7 @@ acpi_ex_acquire_mutex(union acpi_operand_object *time_desc,
202 206
203 /* Have the mutex: update mutex and walk info and save the sync_level */ 207 /* Have the mutex: update mutex and walk info and save the sync_level */
204 208
205 obj_desc->mutex.owner_thread_id = acpi_os_get_thread_id(); 209 obj_desc->mutex.owner_thread = walk_state->thread;
206 obj_desc->mutex.acquisition_depth = 1; 210 obj_desc->mutex.acquisition_depth = 1;
207 obj_desc->mutex.original_sync_level = 211 obj_desc->mutex.original_sync_level =
208 walk_state->thread->current_sync_level; 212 walk_state->thread->current_sync_level;
@@ -242,7 +246,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
242 246
243 /* The mutex must have been previously acquired in order to release it */ 247 /* The mutex must have been previously acquired in order to release it */
244 248
245 if (!obj_desc->mutex.owner_thread_id) { 249 if (!obj_desc->mutex.owner_thread) {
246 ACPI_ERROR((AE_INFO, 250 ACPI_ERROR((AE_INFO,
247 "Cannot release Mutex [%4.4s], not acquired", 251 "Cannot release Mutex [%4.4s], not acquired",
248 acpi_ut_get_node_name(obj_desc->mutex.node))); 252 acpi_ut_get_node_name(obj_desc->mutex.node)));
@@ -262,14 +266,15 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
262 * The Mutex is owned, but this thread must be the owner. 266 * The Mutex is owned, but this thread must be the owner.
263 * Special case for Global Lock, any thread can release 267 * Special case for Global Lock, any thread can release
264 */ 268 */
265 if ((obj_desc->mutex.owner_thread_id != 269 if ((obj_desc->mutex.owner_thread->thread_id !=
266 walk_state->thread->thread_id) 270 walk_state->thread->thread_id)
267 && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) { 271 && (obj_desc->mutex.os_mutex != acpi_gbl_global_lock_mutex)) {
268 ACPI_ERROR((AE_INFO, 272 ACPI_ERROR((AE_INFO,
269 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX", 273 "Thread %lX cannot release Mutex [%4.4s] acquired by thread %lX",
270 (unsigned long)walk_state->thread->thread_id, 274 (unsigned long)walk_state->thread->thread_id,
271 acpi_ut_get_node_name(obj_desc->mutex.node), 275 acpi_ut_get_node_name(obj_desc->mutex.node),
272 (unsigned long)obj_desc->mutex.owner_thread_id)); 276 (unsigned long)obj_desc->mutex.owner_thread->
277 thread_id));
273 return_ACPI_STATUS(AE_AML_NOT_OWNER); 278 return_ACPI_STATUS(AE_AML_NOT_OWNER);
274 } 279 }
275 280
@@ -296,7 +301,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
296 301
297 /* Unlink the mutex from the owner's list */ 302 /* Unlink the mutex from the owner's list */
298 303
299 acpi_ex_unlink_mutex(obj_desc, walk_state->thread); 304 acpi_ex_unlink_mutex(obj_desc);
300 305
301 /* Release the mutex, special case for Global Lock */ 306 /* Release the mutex, special case for Global Lock */
302 307
@@ -308,7 +313,7 @@ acpi_ex_release_mutex(union acpi_operand_object *obj_desc,
308 313
309 /* Update the mutex and restore sync_level */ 314 /* Update the mutex and restore sync_level */
310 315
311 obj_desc->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED; 316 obj_desc->mutex.owner_thread = NULL;
312 walk_state->thread->current_sync_level = 317 walk_state->thread->current_sync_level =
313 obj_desc->mutex.original_sync_level; 318 obj_desc->mutex.original_sync_level;
314 319
@@ -363,7 +368,7 @@ void acpi_ex_release_all_mutexes(struct acpi_thread_state *thread)
363 368
364 /* Mark mutex unowned */ 369 /* Mark mutex unowned */
365 370
366 obj_desc->mutex.owner_thread_id = ACPI_MUTEX_NOT_ACQUIRED; 371 obj_desc->mutex.owner_thread = NULL;
367 372
368 /* Update Thread sync_level (Last mutex is the important one) */ 373 /* Update Thread sync_level (Last mutex is the important one) */
369 374
diff --git a/drivers/acpi/executer/exnames.c b/drivers/acpi/executer/exnames.c
index 1ee4fb1175c6..308eae52dc05 100644
--- a/drivers/acpi/executer/exnames.c
+++ b/drivers/acpi/executer/exnames.c
@@ -177,8 +177,7 @@ static acpi_status acpi_ex_name_segment(u8 ** in_aml_address, char *name_string)
177 177
178 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Bytes from stream:\n")); 178 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "Bytes from stream:\n"));
179 179
180 for (index = 0; 180 for (index = 0; (index < ACPI_NAME_SIZE)
181 (index < ACPI_NAME_SIZE)
182 && (acpi_ut_valid_acpi_char(*aml_address, 0)); index++) { 181 && (acpi_ut_valid_acpi_char(*aml_address, 0)); index++) {
183 char_buf[index] = *aml_address++; 182 char_buf[index] = *aml_address++;
184 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "%c\n", char_buf[index])); 183 ACPI_DEBUG_PRINT((ACPI_DB_LOAD, "%c\n", char_buf[index]));
diff --git a/drivers/acpi/executer/exprep.c b/drivers/acpi/executer/exprep.c
index a6696621ff1b..efe5d4b461a4 100644
--- a/drivers/acpi/executer/exprep.c
+++ b/drivers/acpi/executer/exprep.c
@@ -242,7 +242,7 @@ acpi_ex_decode_field_access(union acpi_operand_object *obj_desc,
242 obj_desc->common_field.bit_length, 242 obj_desc->common_field.bit_length,
243 0xFFFFFFFF 243 0xFFFFFFFF
244 /* Temp until we pass region_length as parameter */ 244 /* Temp until we pass region_length as parameter */
245 ); 245 );
246 bit_length = byte_alignment * 8; 246 bit_length = byte_alignment * 8;
247#endif 247#endif
248 248
diff --git a/drivers/acpi/executer/exresop.c b/drivers/acpi/executer/exresop.c
index ba761862a599..09d897b3f6d5 100644
--- a/drivers/acpi/executer/exresop.c
+++ b/drivers/acpi/executer/exresop.c
@@ -354,8 +354,7 @@ acpi_ex_resolve_operands(u16 opcode,
354 if ((opcode == AML_STORE_OP) && 354 if ((opcode == AML_STORE_OP) &&
355 (ACPI_GET_OBJECT_TYPE(*stack_ptr) == 355 (ACPI_GET_OBJECT_TYPE(*stack_ptr) ==
356 ACPI_TYPE_LOCAL_REFERENCE) 356 ACPI_TYPE_LOCAL_REFERENCE)
357 && ((*stack_ptr)->reference.opcode == 357 && ((*stack_ptr)->reference.opcode == AML_INDEX_OP)) {
358 AML_INDEX_OP)) {
359 goto next_operand; 358 goto next_operand;
360 } 359 }
361 break; 360 break;
diff --git a/drivers/acpi/executer/exsystem.c b/drivers/acpi/executer/exsystem.c
index b2edf620ba89..9460baff3032 100644
--- a/drivers/acpi/executer/exsystem.c
+++ b/drivers/acpi/executer/exsystem.c
@@ -66,7 +66,6 @@ ACPI_MODULE_NAME("exsystem")
66acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout) 66acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
67{ 67{
68 acpi_status status; 68 acpi_status status;
69 acpi_status status2;
70 69
71 ACPI_FUNCTION_TRACE(ex_system_wait_semaphore); 70 ACPI_FUNCTION_TRACE(ex_system_wait_semaphore);
72 71
@@ -79,7 +78,7 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
79 78
80 /* We must wait, so unlock the interpreter */ 79 /* We must wait, so unlock the interpreter */
81 80
82 acpi_ex_exit_interpreter(); 81 acpi_ex_relinquish_interpreter();
83 82
84 status = acpi_os_wait_semaphore(semaphore, 1, timeout); 83 status = acpi_os_wait_semaphore(semaphore, 1, timeout);
85 84
@@ -89,13 +88,7 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
89 88
90 /* Reacquire the interpreter */ 89 /* Reacquire the interpreter */
91 90
92 status2 = acpi_ex_enter_interpreter(); 91 acpi_ex_reacquire_interpreter();
93 if (ACPI_FAILURE(status2)) {
94
95 /* Report fatal error, could not acquire interpreter */
96
97 return_ACPI_STATUS(status2);
98 }
99 } 92 }
100 93
101 return_ACPI_STATUS(status); 94 return_ACPI_STATUS(status);
@@ -119,7 +112,6 @@ acpi_status acpi_ex_system_wait_semaphore(acpi_semaphore semaphore, u16 timeout)
119acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout) 112acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
120{ 113{
121 acpi_status status; 114 acpi_status status;
122 acpi_status status2;
123 115
124 ACPI_FUNCTION_TRACE(ex_system_wait_mutex); 116 ACPI_FUNCTION_TRACE(ex_system_wait_mutex);
125 117
@@ -132,7 +124,7 @@ acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
132 124
133 /* We must wait, so unlock the interpreter */ 125 /* We must wait, so unlock the interpreter */
134 126
135 acpi_ex_exit_interpreter(); 127 acpi_ex_relinquish_interpreter();
136 128
137 status = acpi_os_acquire_mutex(mutex, timeout); 129 status = acpi_os_acquire_mutex(mutex, timeout);
138 130
@@ -142,13 +134,7 @@ acpi_status acpi_ex_system_wait_mutex(acpi_mutex mutex, u16 timeout)
142 134
143 /* Reacquire the interpreter */ 135 /* Reacquire the interpreter */
144 136
145 status2 = acpi_ex_enter_interpreter(); 137 acpi_ex_reacquire_interpreter();
146 if (ACPI_FAILURE(status2)) {
147
148 /* Report fatal error, could not acquire interpreter */
149
150 return_ACPI_STATUS(status2);
151 }
152 } 138 }
153 139
154 return_ACPI_STATUS(status); 140 return_ACPI_STATUS(status);
@@ -209,20 +195,18 @@ acpi_status acpi_ex_system_do_stall(u32 how_long)
209 195
210acpi_status acpi_ex_system_do_suspend(acpi_integer how_long) 196acpi_status acpi_ex_system_do_suspend(acpi_integer how_long)
211{ 197{
212 acpi_status status;
213
214 ACPI_FUNCTION_ENTRY(); 198 ACPI_FUNCTION_ENTRY();
215 199
216 /* Since this thread will sleep, we must release the interpreter */ 200 /* Since this thread will sleep, we must release the interpreter */
217 201
218 acpi_ex_exit_interpreter(); 202 acpi_ex_relinquish_interpreter();
219 203
220 acpi_os_sleep(how_long); 204 acpi_os_sleep(how_long);
221 205
222 /* And now we must get the interpreter again */ 206 /* And now we must get the interpreter again */
223 207
224 status = acpi_ex_enter_interpreter(); 208 acpi_ex_reacquire_interpreter();
225 return (status); 209 return (AE_OK);
226} 210}
227 211
228/******************************************************************************* 212/*******************************************************************************
diff --git a/drivers/acpi/executer/exutils.c b/drivers/acpi/executer/exutils.c
index aea461f3a48c..6b0aeccbb69b 100644
--- a/drivers/acpi/executer/exutils.c
+++ b/drivers/acpi/executer/exutils.c
@@ -76,14 +76,15 @@ static u32 acpi_ex_digits_needed(acpi_integer value, u32 base);
76 * 76 *
77 * PARAMETERS: None 77 * PARAMETERS: None
78 * 78 *
79 * RETURN: Status 79 * RETURN: None
80 * 80 *
81 * DESCRIPTION: Enter the interpreter execution region. Failure to enter 81 * DESCRIPTION: Enter the interpreter execution region. Failure to enter
82 * the interpreter region is a fatal system error 82 * the interpreter region is a fatal system error. Used in
83 * conjunction with exit_interpreter.
83 * 84 *
84 ******************************************************************************/ 85 ******************************************************************************/
85 86
86acpi_status acpi_ex_enter_interpreter(void) 87void acpi_ex_enter_interpreter(void)
87{ 88{
88 acpi_status status; 89 acpi_status status;
89 90
@@ -91,31 +92,55 @@ acpi_status acpi_ex_enter_interpreter(void)
91 92
92 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER); 93 status = acpi_ut_acquire_mutex(ACPI_MTX_INTERPRETER);
93 if (ACPI_FAILURE(status)) { 94 if (ACPI_FAILURE(status)) {
94 ACPI_ERROR((AE_INFO, "Could not acquire interpreter mutex")); 95 ACPI_ERROR((AE_INFO,
96 "Could not acquire AML Interpreter mutex"));
95 } 97 }
96 98
97 return_ACPI_STATUS(status); 99 return_VOID;
98} 100}
99 101
100/******************************************************************************* 102/*******************************************************************************
101 * 103 *
102 * FUNCTION: acpi_ex_exit_interpreter 104 * FUNCTION: acpi_ex_reacquire_interpreter
103 * 105 *
104 * PARAMETERS: None 106 * PARAMETERS: None
105 * 107 *
106 * RETURN: None 108 * RETURN: None
107 * 109 *
108 * DESCRIPTION: Exit the interpreter execution region 110 * DESCRIPTION: Reacquire the interpreter execution region from within the
111 * interpreter code. Failure to enter the interpreter region is a
112 * fatal system error. Used in conjuction with
113 * relinquish_interpreter
114 *
115 ******************************************************************************/
116
117void acpi_ex_reacquire_interpreter(void)
118{
119 ACPI_FUNCTION_TRACE(ex_reacquire_interpreter);
120
121 /*
122 * If the global serialized flag is set, do not release the interpreter,
123 * since it was not actually released by acpi_ex_relinquish_interpreter.
124 * This forces the interpreter to be single threaded.
125 */
126 if (!acpi_gbl_all_methods_serialized) {
127 acpi_ex_enter_interpreter();
128 }
129
130 return_VOID;
131}
132
133/*******************************************************************************
134 *
135 * FUNCTION: acpi_ex_exit_interpreter
136 *
137 * PARAMETERS: None
138 *
139 * RETURN: None
109 * 140 *
110 * Cases where the interpreter is unlocked: 141 * DESCRIPTION: Exit the interpreter execution region. This is the top level
111 * 1) Completion of the execution of a control method 142 * routine used to exit the interpreter when all processing has
112 * 2) Method blocked on a Sleep() AML opcode 143 * been completed.
113 * 3) Method blocked on an Acquire() AML opcode
114 * 4) Method blocked on a Wait() AML opcode
115 * 5) Method blocked to acquire the global lock
116 * 6) Method blocked to execute a serialized control method that is
117 * already executing
118 * 7) About to invoke a user-installed opregion handler
119 * 144 *
120 ******************************************************************************/ 145 ******************************************************************************/
121 146
@@ -127,7 +152,46 @@ void acpi_ex_exit_interpreter(void)
127 152
128 status = acpi_ut_release_mutex(ACPI_MTX_INTERPRETER); 153 status = acpi_ut_release_mutex(ACPI_MTX_INTERPRETER);
129 if (ACPI_FAILURE(status)) { 154 if (ACPI_FAILURE(status)) {
130 ACPI_ERROR((AE_INFO, "Could not release interpreter mutex")); 155 ACPI_ERROR((AE_INFO,
156 "Could not release AML Interpreter mutex"));
157 }
158
159 return_VOID;
160}
161
162/*******************************************************************************
163 *
164 * FUNCTION: acpi_ex_relinquish_interpreter
165 *
166 * PARAMETERS: None
167 *
168 * RETURN: None
169 *
170 * DESCRIPTION: Exit the interpreter execution region, from within the
171 * interpreter - before attempting an operation that will possibly
172 * block the running thread.
173 *
174 * Cases where the interpreter is unlocked internally
175 * 1) Method to be blocked on a Sleep() AML opcode
176 * 2) Method to be blocked on an Acquire() AML opcode
177 * 3) Method to be blocked on a Wait() AML opcode
178 * 4) Method to be blocked to acquire the global lock
179 * 5) Method to be blocked waiting to execute a serialized control method
180 * that is currently executing
181 * 6) About to invoke a user-installed opregion handler
182 *
183 ******************************************************************************/
184
185void acpi_ex_relinquish_interpreter(void)
186{
187 ACPI_FUNCTION_TRACE(ex_relinquish_interpreter);
188
189 /*
190 * If the global serialized flag is set, do not release the interpreter.
191 * This forces the interpreter to be single threaded.
192 */
193 if (!acpi_gbl_all_methods_serialized) {
194 acpi_ex_exit_interpreter();
131 } 195 }
132 196
133 return_VOID; 197 return_VOID;
@@ -141,8 +205,8 @@ void acpi_ex_exit_interpreter(void)
141 * 205 *
142 * RETURN: none 206 * RETURN: none
143 * 207 *
144 * DESCRIPTION: Truncate a number to 32-bits if the currently executing method 208 * DESCRIPTION: Truncate an ACPI Integer to 32 bits if the execution mode is
145 * belongs to a 32-bit ACPI table. 209 * 32-bit, as determined by the revision of the DSDT.
146 * 210 *
147 ******************************************************************************/ 211 ******************************************************************************/
148 212
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 4334c208841a..41427a41f620 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -245,6 +245,35 @@ arch_initcall(init_acpi_device_notify);
245 245
246#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE) 246#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
247 247
248#ifdef CONFIG_PM
249static u32 rtc_handler(void *context)
250{
251 acpi_clear_event(ACPI_EVENT_RTC);
252 acpi_disable_event(ACPI_EVENT_RTC, 0);
253 return ACPI_INTERRUPT_HANDLED;
254}
255
256static inline void rtc_wake_setup(void)
257{
258 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
259}
260
261static void rtc_wake_on(struct device *dev)
262{
263 acpi_clear_event(ACPI_EVENT_RTC);
264 acpi_enable_event(ACPI_EVENT_RTC, 0);
265}
266
267static void rtc_wake_off(struct device *dev)
268{
269 acpi_disable_event(ACPI_EVENT_RTC, 0);
270}
271#else
272#define rtc_wake_setup() do{}while(0)
273#define rtc_wake_on NULL
274#define rtc_wake_off NULL
275#endif
276
248/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find 277/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
249 * its device node and pass extra config data. This helps its driver use 278 * its device node and pass extra config data. This helps its driver use
250 * capabilities that the now-obsolete mc146818 didn't have, and informs it 279 * capabilities that the now-obsolete mc146818 didn't have, and informs it
@@ -283,11 +312,24 @@ static int __init acpi_rtc_init(void)
283 struct device *dev = get_rtc_dev(); 312 struct device *dev = get_rtc_dev();
284 313
285 if (dev) { 314 if (dev) {
315 rtc_wake_setup();
316 rtc_info.wake_on = rtc_wake_on;
317 rtc_info.wake_off = rtc_wake_off;
318
319 /* workaround bug in some ACPI tables */
320 if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
321 DBG("bogus FADT month_alarm\n");
322 acpi_gbl_FADT.month_alarm = 0;
323 }
324
286 rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm; 325 rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
287 rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm; 326 rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
288 rtc_info.rtc_century = acpi_gbl_FADT.century; 327 rtc_info.rtc_century = acpi_gbl_FADT.century;
289 328
290 /* NOTE: acpi_gbl_FADT->rtcs4 is NOT currently useful */ 329 /* NOTE: S4_RTC_WAKE is NOT currently useful to Linux */
330 if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
331 printk(PREFIX "RTC can wake from S4\n");
332
291 333
292 dev->platform_data = &rtc_info; 334 dev->platform_data = &rtc_info;
293 335
@@ -296,7 +338,7 @@ static int __init acpi_rtc_init(void)
296 338
297 put_device(dev); 339 put_device(dev);
298 } else 340 } else
299 pr_debug("ACPI: RTC unavailable?\n"); 341 DBG("RTC unavailable?\n");
300 return 0; 342 return 0;
301} 343}
302/* do this between RTC subsys_initcall() and rtc_cmos driver_initcall() */ 344/* do this between RTC subsys_initcall() and rtc_cmos driver_initcall() */
diff --git a/drivers/acpi/hardware/hwsleep.c b/drivers/acpi/hardware/hwsleep.c
index c84b1faba28c..76c525dc590b 100644
--- a/drivers/acpi/hardware/hwsleep.c
+++ b/drivers/acpi/hardware/hwsleep.c
@@ -152,7 +152,6 @@ acpi_get_firmware_waking_vector(acpi_physical_address * physical_address)
152 152
153ACPI_EXPORT_SYMBOL(acpi_get_firmware_waking_vector) 153ACPI_EXPORT_SYMBOL(acpi_get_firmware_waking_vector)
154#endif 154#endif
155
156/******************************************************************************* 155/*******************************************************************************
157 * 156 *
158 * FUNCTION: acpi_enter_sleep_state_prep 157 * FUNCTION: acpi_enter_sleep_state_prep
diff --git a/drivers/acpi/namespace/nseval.c b/drivers/acpi/namespace/nseval.c
index 26fd0dd6953d..97b2ac57c16b 100644
--- a/drivers/acpi/namespace/nseval.c
+++ b/drivers/acpi/namespace/nseval.c
@@ -75,7 +75,7 @@ ACPI_MODULE_NAME("nseval")
75 * MUTEX: Locks interpreter 75 * MUTEX: Locks interpreter
76 * 76 *
77 ******************************************************************************/ 77 ******************************************************************************/
78acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info) 78acpi_status acpi_ns_evaluate(struct acpi_evaluate_info * info)
79{ 79{
80 acpi_status status; 80 acpi_status status;
81 81
@@ -154,11 +154,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
154 * Execute the method via the interpreter. The interpreter is locked 154 * Execute the method via the interpreter. The interpreter is locked
155 * here before calling into the AML parser 155 * here before calling into the AML parser
156 */ 156 */
157 status = acpi_ex_enter_interpreter(); 157 acpi_ex_enter_interpreter();
158 if (ACPI_FAILURE(status)) {
159 return_ACPI_STATUS(status);
160 }
161
162 status = acpi_ps_execute_method(info); 158 status = acpi_ps_execute_method(info);
163 acpi_ex_exit_interpreter(); 159 acpi_ex_exit_interpreter();
164 } else { 160 } else {
@@ -182,10 +178,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
182 * resolution, we must lock it because we could access an opregion. 178 * resolution, we must lock it because we could access an opregion.
183 * The opregion access code assumes that the interpreter is locked. 179 * The opregion access code assumes that the interpreter is locked.
184 */ 180 */
185 status = acpi_ex_enter_interpreter(); 181 acpi_ex_enter_interpreter();
186 if (ACPI_FAILURE(status)) {
187 return_ACPI_STATUS(status);
188 }
189 182
190 /* Function has a strange interface */ 183 /* Function has a strange interface */
191 184
diff --git a/drivers/acpi/namespace/nsinit.c b/drivers/acpi/namespace/nsinit.c
index c4ab615f77fe..33db2241044e 100644
--- a/drivers/acpi/namespace/nsinit.c
+++ b/drivers/acpi/namespace/nsinit.c
@@ -214,7 +214,7 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
214 u32 level, void *context, void **return_value) 214 u32 level, void *context, void **return_value)
215{ 215{
216 acpi_object_type type; 216 acpi_object_type type;
217 acpi_status status; 217 acpi_status status = AE_OK;
218 struct acpi_init_walk_info *info = 218 struct acpi_init_walk_info *info =
219 (struct acpi_init_walk_info *)context; 219 (struct acpi_init_walk_info *)context;
220 struct acpi_namespace_node *node = 220 struct acpi_namespace_node *node =
@@ -268,10 +268,7 @@ acpi_ns_init_one_object(acpi_handle obj_handle,
268 /* 268 /*
269 * Must lock the interpreter before executing AML code 269 * Must lock the interpreter before executing AML code
270 */ 270 */
271 status = acpi_ex_enter_interpreter(); 271 acpi_ex_enter_interpreter();
272 if (ACPI_FAILURE(status)) {
273 return (status);
274 }
275 272
276 /* 273 /*
277 * Each of these types can contain executable AML code within the 274 * Each of these types can contain executable AML code within the
diff --git a/drivers/acpi/namespace/nswalk.c b/drivers/acpi/namespace/nswalk.c
index 94eb8f332d94..280b8357c46c 100644
--- a/drivers/acpi/namespace/nswalk.c
+++ b/drivers/acpi/namespace/nswalk.c
@@ -65,10 +65,8 @@ ACPI_MODULE_NAME("nswalk")
65 * within Scope is returned. 65 * within Scope is returned.
66 * 66 *
67 ******************************************************************************/ 67 ******************************************************************************/
68struct acpi_namespace_node *acpi_ns_get_next_node(acpi_object_type type, 68struct acpi_namespace_node *acpi_ns_get_next_node(acpi_object_type type, struct acpi_namespace_node
69 struct acpi_namespace_node 69 *parent_node, struct acpi_namespace_node
70 *parent_node,
71 struct acpi_namespace_node
72 *child_node) 70 *child_node)
73{ 71{
74 struct acpi_namespace_node *next_node = NULL; 72 struct acpi_namespace_node *next_node = NULL;
diff --git a/drivers/acpi/namespace/nsxfeval.c b/drivers/acpi/namespace/nsxfeval.c
index 8904d0fae6a2..be4f2899de74 100644
--- a/drivers/acpi/namespace/nsxfeval.c
+++ b/drivers/acpi/namespace/nsxfeval.c
@@ -48,7 +48,6 @@
48 48
49#define _COMPONENT ACPI_NAMESPACE 49#define _COMPONENT ACPI_NAMESPACE
50ACPI_MODULE_NAME("nsxfeval") 50ACPI_MODULE_NAME("nsxfeval")
51
52#ifdef ACPI_FUTURE_USAGE 51#ifdef ACPI_FUTURE_USAGE
53/******************************************************************************* 52/*******************************************************************************
54 * 53 *
@@ -73,8 +72,8 @@ ACPI_MODULE_NAME("nsxfeval")
73acpi_status 72acpi_status
74acpi_evaluate_object_typed(acpi_handle handle, 73acpi_evaluate_object_typed(acpi_handle handle,
75 acpi_string pathname, 74 acpi_string pathname,
76 struct acpi_object_list * external_params, 75 struct acpi_object_list *external_params,
77 struct acpi_buffer * return_buffer, 76 struct acpi_buffer *return_buffer,
78 acpi_object_type return_type) 77 acpi_object_type return_type)
79{ 78{
80 acpi_status status; 79 acpi_status status;
@@ -143,7 +142,6 @@ acpi_evaluate_object_typed(acpi_handle handle,
143 142
144ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed) 143ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed)
145#endif /* ACPI_FUTURE_USAGE */ 144#endif /* ACPI_FUTURE_USAGE */
146
147/******************************************************************************* 145/*******************************************************************************
148 * 146 *
149 * FUNCTION: acpi_evaluate_object 147 * FUNCTION: acpi_evaluate_object
@@ -170,7 +168,6 @@ acpi_evaluate_object(acpi_handle handle,
170 struct acpi_buffer *return_buffer) 168 struct acpi_buffer *return_buffer)
171{ 169{
172 acpi_status status; 170 acpi_status status;
173 acpi_status status2;
174 struct acpi_evaluate_info *info; 171 struct acpi_evaluate_info *info;
175 acpi_size buffer_space_needed; 172 acpi_size buffer_space_needed;
176 u32 i; 173 u32 i;
@@ -329,14 +326,12 @@ acpi_evaluate_object(acpi_handle handle,
329 * Delete the internal return object. NOTE: Interpreter must be 326 * Delete the internal return object. NOTE: Interpreter must be
330 * locked to avoid race condition. 327 * locked to avoid race condition.
331 */ 328 */
332 status2 = acpi_ex_enter_interpreter(); 329 acpi_ex_enter_interpreter();
333 if (ACPI_SUCCESS(status2)) {
334 330
335 /* Remove one reference on the return object (should delete it) */ 331 /* Remove one reference on the return object (should delete it) */
336 332
337 acpi_ut_remove_reference(info->return_object); 333 acpi_ut_remove_reference(info->return_object);
338 acpi_ex_exit_interpreter(); 334 acpi_ex_exit_interpreter();
339 }
340 } 335 }
341 336
342 cleanup: 337 cleanup:
diff --git a/drivers/acpi/numa.c b/drivers/acpi/numa.c
index 8fcd6a15517f..a2efae8a4c4e 100644
--- a/drivers/acpi/numa.c
+++ b/drivers/acpi/numa.c
@@ -40,19 +40,19 @@ static nodemask_t nodes_found_map = NODE_MASK_NONE;
40#define NID_INVAL -1 40#define NID_INVAL -1
41 41
42/* maps to convert between proximity domain and logical node ID */ 42/* maps to convert between proximity domain and logical node ID */
43int __cpuinitdata pxm_to_node_map[MAX_PXM_DOMAINS] 43static int pxm_to_node_map[MAX_PXM_DOMAINS]
44 = { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL }; 44 = { [0 ... MAX_PXM_DOMAINS - 1] = NID_INVAL };
45int __cpuinitdata node_to_pxm_map[MAX_NUMNODES] 45static int node_to_pxm_map[MAX_NUMNODES]
46 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL }; 46 = { [0 ... MAX_NUMNODES - 1] = PXM_INVAL };
47 47
48int __cpuinit pxm_to_node(int pxm) 48int pxm_to_node(int pxm)
49{ 49{
50 if (pxm < 0) 50 if (pxm < 0)
51 return NID_INVAL; 51 return NID_INVAL;
52 return pxm_to_node_map[pxm]; 52 return pxm_to_node_map[pxm];
53} 53}
54 54
55int __cpuinit node_to_pxm(int node) 55int node_to_pxm(int node)
56{ 56{
57 if (node < 0) 57 if (node < 0)
58 return PXM_INVAL; 58 return PXM_INVAL;
diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index 971eca4864fa..b998340e23d4 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -30,7 +30,6 @@
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/mm.h> 31#include <linux/mm.h>
32#include <linux/pci.h> 32#include <linux/pci.h>
33#include <linux/smp_lock.h>
34#include <linux/interrupt.h> 33#include <linux/interrupt.h>
35#include <linux/kmod.h> 34#include <linux/kmod.h>
36#include <linux/delay.h> 35#include <linux/delay.h>
@@ -72,6 +71,7 @@ static unsigned int acpi_irq_irq;
72static acpi_osd_handler acpi_irq_handler; 71static acpi_osd_handler acpi_irq_handler;
73static void *acpi_irq_context; 72static void *acpi_irq_context;
74static struct workqueue_struct *kacpid_wq; 73static struct workqueue_struct *kacpid_wq;
74static struct workqueue_struct *kacpi_notify_wq;
75 75
76static void __init acpi_request_region (struct acpi_generic_address *addr, 76static void __init acpi_request_region (struct acpi_generic_address *addr,
77 unsigned int length, char *desc) 77 unsigned int length, char *desc)
@@ -138,8 +138,9 @@ acpi_status acpi_os_initialize1(void)
138 return AE_NULL_ENTRY; 138 return AE_NULL_ENTRY;
139 } 139 }
140 kacpid_wq = create_singlethread_workqueue("kacpid"); 140 kacpid_wq = create_singlethread_workqueue("kacpid");
141 kacpi_notify_wq = create_singlethread_workqueue("kacpi_notify");
141 BUG_ON(!kacpid_wq); 142 BUG_ON(!kacpid_wq);
142 143 BUG_ON(!kacpi_notify_wq);
143 return AE_OK; 144 return AE_OK;
144} 145}
145 146
@@ -151,6 +152,7 @@ acpi_status acpi_os_terminate(void)
151 } 152 }
152 153
153 destroy_workqueue(kacpid_wq); 154 destroy_workqueue(kacpid_wq);
155 destroy_workqueue(kacpi_notify_wq);
154 156
155 return AE_OK; 157 return AE_OK;
156} 158}
@@ -604,6 +606,23 @@ void acpi_os_derive_pci_id(acpi_handle rhandle, /* upper bound */
604static void acpi_os_execute_deferred(struct work_struct *work) 606static void acpi_os_execute_deferred(struct work_struct *work)
605{ 607{
606 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work); 608 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
609 if (!dpc) {
610 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
611 return;
612 }
613
614 dpc->function(dpc->context);
615 kfree(dpc);
616
617 /* Yield cpu to notify thread */
618 cond_resched();
619
620 return;
621}
622
623static void acpi_os_execute_notify(struct work_struct *work)
624{
625 struct acpi_os_dpc *dpc = container_of(work, struct acpi_os_dpc, work);
607 626
608 if (!dpc) { 627 if (!dpc) {
609 printk(KERN_ERR PREFIX "Invalid (NULL) context\n"); 628 printk(KERN_ERR PREFIX "Invalid (NULL) context\n");
@@ -638,14 +657,12 @@ acpi_status acpi_os_execute(acpi_execute_type type,
638 acpi_status status = AE_OK; 657 acpi_status status = AE_OK;
639 struct acpi_os_dpc *dpc; 658 struct acpi_os_dpc *dpc;
640 659
641 ACPI_FUNCTION_TRACE("os_queue_for_execution");
642
643 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, 660 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
644 "Scheduling function [%p(%p)] for deferred execution.\n", 661 "Scheduling function [%p(%p)] for deferred execution.\n",
645 function, context)); 662 function, context));
646 663
647 if (!function) 664 if (!function)
648 return_ACPI_STATUS(AE_BAD_PARAMETER); 665 return AE_BAD_PARAMETER;
649 666
650 /* 667 /*
651 * Allocate/initialize DPC structure. Note that this memory will be 668 * Allocate/initialize DPC structure. Note that this memory will be
@@ -663,14 +680,21 @@ acpi_status acpi_os_execute(acpi_execute_type type,
663 dpc->function = function; 680 dpc->function = function;
664 dpc->context = context; 681 dpc->context = context;
665 682
666 INIT_WORK(&dpc->work, acpi_os_execute_deferred); 683 if (type == OSL_NOTIFY_HANDLER) {
667 if (!queue_work(kacpid_wq, &dpc->work)) { 684 INIT_WORK(&dpc->work, acpi_os_execute_notify);
668 ACPI_DEBUG_PRINT((ACPI_DB_ERROR, 685 if (!queue_work(kacpi_notify_wq, &dpc->work)) {
686 status = AE_ERROR;
687 kfree(dpc);
688 }
689 } else {
690 INIT_WORK(&dpc->work, acpi_os_execute_deferred);
691 if (!queue_work(kacpid_wq, &dpc->work)) {
692 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
669 "Call to queue_work() failed.\n")); 693 "Call to queue_work() failed.\n"));
670 kfree(dpc); 694 status = AE_ERROR;
671 status = AE_ERROR; 695 kfree(dpc);
696 }
672 } 697 }
673
674 return_ACPI_STATUS(status); 698 return_ACPI_STATUS(status);
675} 699}
676 700
diff --git a/drivers/acpi/parser/psopcode.c b/drivers/acpi/parser/psopcode.c
index 16d8b6cc3c22..9296e86761d7 100644
--- a/drivers/acpi/parser/psopcode.c
+++ b/drivers/acpi/parser/psopcode.c
@@ -185,459 +185,453 @@ const struct acpi_opcode_info acpi_gbl_aml_op_info[AML_NUM_OPCODES] = {
185/* Index Name Parser Args Interpreter Args ObjectType Class Type Flags */ 185/* Index Name Parser Args Interpreter Args ObjectType Class Type Flags */
186 186
187/* 00 */ ACPI_OP("Zero", ARGP_ZERO_OP, ARGI_ZERO_OP, ACPI_TYPE_INTEGER, 187/* 00 */ ACPI_OP("Zero", ARGP_ZERO_OP, ARGI_ZERO_OP, ACPI_TYPE_INTEGER,
188 AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT), 188 AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT),
189/* 01 */ ACPI_OP("One", ARGP_ONE_OP, ARGI_ONE_OP, ACPI_TYPE_INTEGER, 189/* 01 */ ACPI_OP("One", ARGP_ONE_OP, ARGI_ONE_OP, ACPI_TYPE_INTEGER,
190 AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT), 190 AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT),
191/* 02 */ ACPI_OP("Alias", ARGP_ALIAS_OP, ARGI_ALIAS_OP, 191/* 02 */ ACPI_OP("Alias", ARGP_ALIAS_OP, ARGI_ALIAS_OP,
192 ACPI_TYPE_LOCAL_ALIAS, AML_CLASS_NAMED_OBJECT, 192 ACPI_TYPE_LOCAL_ALIAS, AML_CLASS_NAMED_OBJECT,
193 AML_TYPE_NAMED_SIMPLE, 193 AML_TYPE_NAMED_SIMPLE,
194 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 194 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
195 AML_NSNODE | AML_NAMED), 195 AML_NSNODE | AML_NAMED),
196/* 03 */ ACPI_OP("Name", ARGP_NAME_OP, ARGI_NAME_OP, ACPI_TYPE_ANY, 196/* 03 */ ACPI_OP("Name", ARGP_NAME_OP, ARGI_NAME_OP, ACPI_TYPE_ANY,
197 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_COMPLEX, 197 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_COMPLEX,
198 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 198 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
199 AML_NSNODE | AML_NAMED), 199 AML_NSNODE | AML_NAMED),
200/* 04 */ ACPI_OP("ByteConst", ARGP_BYTE_OP, ARGI_BYTE_OP, 200/* 04 */ ACPI_OP("ByteConst", ARGP_BYTE_OP, ARGI_BYTE_OP,
201 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, 201 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT,
202 AML_TYPE_LITERAL, AML_CONSTANT), 202 AML_TYPE_LITERAL, AML_CONSTANT),
203/* 05 */ ACPI_OP("WordConst", ARGP_WORD_OP, ARGI_WORD_OP, 203/* 05 */ ACPI_OP("WordConst", ARGP_WORD_OP, ARGI_WORD_OP,
204 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, 204 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT,
205 AML_TYPE_LITERAL, AML_CONSTANT), 205 AML_TYPE_LITERAL, AML_CONSTANT),
206/* 06 */ ACPI_OP("DwordConst", ARGP_DWORD_OP, ARGI_DWORD_OP, 206/* 06 */ ACPI_OP("DwordConst", ARGP_DWORD_OP, ARGI_DWORD_OP,
207 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, 207 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT,
208 AML_TYPE_LITERAL, AML_CONSTANT), 208 AML_TYPE_LITERAL, AML_CONSTANT),
209/* 07 */ ACPI_OP("String", ARGP_STRING_OP, ARGI_STRING_OP, 209/* 07 */ ACPI_OP("String", ARGP_STRING_OP, ARGI_STRING_OP,
210 ACPI_TYPE_STRING, AML_CLASS_ARGUMENT, 210 ACPI_TYPE_STRING, AML_CLASS_ARGUMENT,
211 AML_TYPE_LITERAL, AML_CONSTANT), 211 AML_TYPE_LITERAL, AML_CONSTANT),
212/* 08 */ ACPI_OP("Scope", ARGP_SCOPE_OP, ARGI_SCOPE_OP, 212/* 08 */ ACPI_OP("Scope", ARGP_SCOPE_OP, ARGI_SCOPE_OP,
213 ACPI_TYPE_LOCAL_SCOPE, AML_CLASS_NAMED_OBJECT, 213 ACPI_TYPE_LOCAL_SCOPE, AML_CLASS_NAMED_OBJECT,
214 AML_TYPE_NAMED_NO_OBJ, 214 AML_TYPE_NAMED_NO_OBJ,
215 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 215 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
216 AML_NSNODE | AML_NAMED), 216 AML_NSNODE | AML_NAMED),
217/* 09 */ ACPI_OP("Buffer", ARGP_BUFFER_OP, ARGI_BUFFER_OP, 217/* 09 */ ACPI_OP("Buffer", ARGP_BUFFER_OP, ARGI_BUFFER_OP,
218 ACPI_TYPE_BUFFER, AML_CLASS_CREATE, 218 ACPI_TYPE_BUFFER, AML_CLASS_CREATE,
219 AML_TYPE_CREATE_OBJECT, 219 AML_TYPE_CREATE_OBJECT,
220 AML_HAS_ARGS | AML_DEFER | AML_CONSTANT), 220 AML_HAS_ARGS | AML_DEFER | AML_CONSTANT),
221/* 0A */ ACPI_OP("Package", ARGP_PACKAGE_OP, ARGI_PACKAGE_OP, 221/* 0A */ ACPI_OP("Package", ARGP_PACKAGE_OP, ARGI_PACKAGE_OP,
222 ACPI_TYPE_PACKAGE, AML_CLASS_CREATE, 222 ACPI_TYPE_PACKAGE, AML_CLASS_CREATE,
223 AML_TYPE_CREATE_OBJECT, 223 AML_TYPE_CREATE_OBJECT,
224 AML_HAS_ARGS | AML_DEFER | AML_CONSTANT), 224 AML_HAS_ARGS | AML_DEFER | AML_CONSTANT),
225/* 0B */ ACPI_OP("Method", ARGP_METHOD_OP, ARGI_METHOD_OP, 225/* 0B */ ACPI_OP("Method", ARGP_METHOD_OP, ARGI_METHOD_OP,
226 ACPI_TYPE_METHOD, AML_CLASS_NAMED_OBJECT, 226 ACPI_TYPE_METHOD, AML_CLASS_NAMED_OBJECT,
227 AML_TYPE_NAMED_COMPLEX, 227 AML_TYPE_NAMED_COMPLEX,
228 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 228 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
229 AML_NSNODE | AML_NAMED | AML_DEFER), 229 AML_NSNODE | AML_NAMED | AML_DEFER),
230/* 0C */ ACPI_OP("Local0", ARGP_LOCAL0, ARGI_LOCAL0, 230/* 0C */ ACPI_OP("Local0", ARGP_LOCAL0, ARGI_LOCAL0,
231 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 231 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
232 AML_TYPE_LOCAL_VARIABLE, 0), 232 AML_TYPE_LOCAL_VARIABLE, 0),
233/* 0D */ ACPI_OP("Local1", ARGP_LOCAL1, ARGI_LOCAL1, 233/* 0D */ ACPI_OP("Local1", ARGP_LOCAL1, ARGI_LOCAL1,
234 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 234 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
235 AML_TYPE_LOCAL_VARIABLE, 0), 235 AML_TYPE_LOCAL_VARIABLE, 0),
236/* 0E */ ACPI_OP("Local2", ARGP_LOCAL2, ARGI_LOCAL2, 236/* 0E */ ACPI_OP("Local2", ARGP_LOCAL2, ARGI_LOCAL2,
237 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 237 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
238 AML_TYPE_LOCAL_VARIABLE, 0), 238 AML_TYPE_LOCAL_VARIABLE, 0),
239/* 0F */ ACPI_OP("Local3", ARGP_LOCAL3, ARGI_LOCAL3, 239/* 0F */ ACPI_OP("Local3", ARGP_LOCAL3, ARGI_LOCAL3,
240 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 240 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
241 AML_TYPE_LOCAL_VARIABLE, 0), 241 AML_TYPE_LOCAL_VARIABLE, 0),
242/* 10 */ ACPI_OP("Local4", ARGP_LOCAL4, ARGI_LOCAL4, 242/* 10 */ ACPI_OP("Local4", ARGP_LOCAL4, ARGI_LOCAL4,
243 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 243 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
244 AML_TYPE_LOCAL_VARIABLE, 0), 244 AML_TYPE_LOCAL_VARIABLE, 0),
245/* 11 */ ACPI_OP("Local5", ARGP_LOCAL5, ARGI_LOCAL5, 245/* 11 */ ACPI_OP("Local5", ARGP_LOCAL5, ARGI_LOCAL5,
246 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 246 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
247 AML_TYPE_LOCAL_VARIABLE, 0), 247 AML_TYPE_LOCAL_VARIABLE, 0),
248/* 12 */ ACPI_OP("Local6", ARGP_LOCAL6, ARGI_LOCAL6, 248/* 12 */ ACPI_OP("Local6", ARGP_LOCAL6, ARGI_LOCAL6,
249 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 249 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
250 AML_TYPE_LOCAL_VARIABLE, 0), 250 AML_TYPE_LOCAL_VARIABLE, 0),
251/* 13 */ ACPI_OP("Local7", ARGP_LOCAL7, ARGI_LOCAL7, 251/* 13 */ ACPI_OP("Local7", ARGP_LOCAL7, ARGI_LOCAL7,
252 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 252 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
253 AML_TYPE_LOCAL_VARIABLE, 0), 253 AML_TYPE_LOCAL_VARIABLE, 0),
254/* 14 */ ACPI_OP("Arg0", ARGP_ARG0, ARGI_ARG0, 254/* 14 */ ACPI_OP("Arg0", ARGP_ARG0, ARGI_ARG0,
255 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 255 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
256 AML_TYPE_METHOD_ARGUMENT, 0), 256 AML_TYPE_METHOD_ARGUMENT, 0),
257/* 15 */ ACPI_OP("Arg1", ARGP_ARG1, ARGI_ARG1, 257/* 15 */ ACPI_OP("Arg1", ARGP_ARG1, ARGI_ARG1,
258 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 258 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
259 AML_TYPE_METHOD_ARGUMENT, 0), 259 AML_TYPE_METHOD_ARGUMENT, 0),
260/* 16 */ ACPI_OP("Arg2", ARGP_ARG2, ARGI_ARG2, 260/* 16 */ ACPI_OP("Arg2", ARGP_ARG2, ARGI_ARG2,
261 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 261 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
262 AML_TYPE_METHOD_ARGUMENT, 0), 262 AML_TYPE_METHOD_ARGUMENT, 0),
263/* 17 */ ACPI_OP("Arg3", ARGP_ARG3, ARGI_ARG3, 263/* 17 */ ACPI_OP("Arg3", ARGP_ARG3, ARGI_ARG3,
264 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 264 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
265 AML_TYPE_METHOD_ARGUMENT, 0), 265 AML_TYPE_METHOD_ARGUMENT, 0),
266/* 18 */ ACPI_OP("Arg4", ARGP_ARG4, ARGI_ARG4, 266/* 18 */ ACPI_OP("Arg4", ARGP_ARG4, ARGI_ARG4,
267 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 267 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
268 AML_TYPE_METHOD_ARGUMENT, 0), 268 AML_TYPE_METHOD_ARGUMENT, 0),
269/* 19 */ ACPI_OP("Arg5", ARGP_ARG5, ARGI_ARG5, 269/* 19 */ ACPI_OP("Arg5", ARGP_ARG5, ARGI_ARG5,
270 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 270 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
271 AML_TYPE_METHOD_ARGUMENT, 0), 271 AML_TYPE_METHOD_ARGUMENT, 0),
272/* 1A */ ACPI_OP("Arg6", ARGP_ARG6, ARGI_ARG6, 272/* 1A */ ACPI_OP("Arg6", ARGP_ARG6, ARGI_ARG6,
273 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 273 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
274 AML_TYPE_METHOD_ARGUMENT, 0), 274 AML_TYPE_METHOD_ARGUMENT, 0),
275/* 1B */ ACPI_OP("Store", ARGP_STORE_OP, ARGI_STORE_OP, ACPI_TYPE_ANY, 275/* 1B */ ACPI_OP("Store", ARGP_STORE_OP, ARGI_STORE_OP, ACPI_TYPE_ANY,
276 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, 276 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R,
277 AML_FLAGS_EXEC_1A_1T_1R), 277 AML_FLAGS_EXEC_1A_1T_1R),
278/* 1C */ ACPI_OP("RefOf", ARGP_REF_OF_OP, ARGI_REF_OF_OP, ACPI_TYPE_ANY, 278/* 1C */ ACPI_OP("RefOf", ARGP_REF_OF_OP, ARGI_REF_OF_OP, ACPI_TYPE_ANY,
279 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R, 279 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R,
280 AML_FLAGS_EXEC_1A_0T_1R), 280 AML_FLAGS_EXEC_1A_0T_1R),
281/* 1D */ ACPI_OP("Add", ARGP_ADD_OP, ARGI_ADD_OP, ACPI_TYPE_ANY, 281/* 1D */ ACPI_OP("Add", ARGP_ADD_OP, ARGI_ADD_OP, ACPI_TYPE_ANY,
282 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, 282 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R,
283 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 283 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
284/* 1E */ ACPI_OP("Concatenate", ARGP_CONCAT_OP, ARGI_CONCAT_OP, 284/* 1E */ ACPI_OP("Concatenate", ARGP_CONCAT_OP, ARGI_CONCAT_OP,
285 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 285 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
286 AML_TYPE_EXEC_2A_1T_1R, 286 AML_TYPE_EXEC_2A_1T_1R,
287 AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT), 287 AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT),
288/* 1F */ ACPI_OP("Subtract", ARGP_SUBTRACT_OP, ARGI_SUBTRACT_OP, 288/* 1F */ ACPI_OP("Subtract", ARGP_SUBTRACT_OP, ARGI_SUBTRACT_OP,
289 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 289 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
290 AML_TYPE_EXEC_2A_1T_1R, 290 AML_TYPE_EXEC_2A_1T_1R,
291 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 291 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
292/* 20 */ ACPI_OP("Increment", ARGP_INCREMENT_OP, ARGI_INCREMENT_OP, 292/* 20 */ ACPI_OP("Increment", ARGP_INCREMENT_OP, ARGI_INCREMENT_OP,
293 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 293 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
294 AML_TYPE_EXEC_1A_0T_1R, 294 AML_TYPE_EXEC_1A_0T_1R,
295 AML_FLAGS_EXEC_1A_0T_1R | AML_CONSTANT), 295 AML_FLAGS_EXEC_1A_0T_1R | AML_CONSTANT),
296/* 21 */ ACPI_OP("Decrement", ARGP_DECREMENT_OP, ARGI_DECREMENT_OP, 296/* 21 */ ACPI_OP("Decrement", ARGP_DECREMENT_OP, ARGI_DECREMENT_OP,
297 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 297 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
298 AML_TYPE_EXEC_1A_0T_1R, 298 AML_TYPE_EXEC_1A_0T_1R,
299 AML_FLAGS_EXEC_1A_0T_1R | AML_CONSTANT), 299 AML_FLAGS_EXEC_1A_0T_1R | AML_CONSTANT),
300/* 22 */ ACPI_OP("Multiply", ARGP_MULTIPLY_OP, ARGI_MULTIPLY_OP, 300/* 22 */ ACPI_OP("Multiply", ARGP_MULTIPLY_OP, ARGI_MULTIPLY_OP,
301 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 301 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
302 AML_TYPE_EXEC_2A_1T_1R, 302 AML_TYPE_EXEC_2A_1T_1R,
303 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 303 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
304/* 23 */ ACPI_OP("Divide", ARGP_DIVIDE_OP, ARGI_DIVIDE_OP, 304/* 23 */ ACPI_OP("Divide", ARGP_DIVIDE_OP, ARGI_DIVIDE_OP,
305 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 305 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
306 AML_TYPE_EXEC_2A_2T_1R, 306 AML_TYPE_EXEC_2A_2T_1R,
307 AML_FLAGS_EXEC_2A_2T_1R | AML_CONSTANT), 307 AML_FLAGS_EXEC_2A_2T_1R | AML_CONSTANT),
308/* 24 */ ACPI_OP("ShiftLeft", ARGP_SHIFT_LEFT_OP, ARGI_SHIFT_LEFT_OP, 308/* 24 */ ACPI_OP("ShiftLeft", ARGP_SHIFT_LEFT_OP, ARGI_SHIFT_LEFT_OP,
309 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 309 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
310 AML_TYPE_EXEC_2A_1T_1R, 310 AML_TYPE_EXEC_2A_1T_1R,
311 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 311 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
312/* 25 */ ACPI_OP("ShiftRight", ARGP_SHIFT_RIGHT_OP, ARGI_SHIFT_RIGHT_OP, 312/* 25 */ ACPI_OP("ShiftRight", ARGP_SHIFT_RIGHT_OP, ARGI_SHIFT_RIGHT_OP,
313 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 313 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
314 AML_TYPE_EXEC_2A_1T_1R, 314 AML_TYPE_EXEC_2A_1T_1R,
315 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 315 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
316/* 26 */ ACPI_OP("And", ARGP_BIT_AND_OP, ARGI_BIT_AND_OP, ACPI_TYPE_ANY, 316/* 26 */ ACPI_OP("And", ARGP_BIT_AND_OP, ARGI_BIT_AND_OP, ACPI_TYPE_ANY,
317 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, 317 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R,
318 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 318 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
319/* 27 */ ACPI_OP("NAnd", ARGP_BIT_NAND_OP, ARGI_BIT_NAND_OP, 319/* 27 */ ACPI_OP("NAnd", ARGP_BIT_NAND_OP, ARGI_BIT_NAND_OP,
320 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 320 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
321 AML_TYPE_EXEC_2A_1T_1R, 321 AML_TYPE_EXEC_2A_1T_1R,
322 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 322 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
323/* 28 */ ACPI_OP("Or", ARGP_BIT_OR_OP, ARGI_BIT_OR_OP, ACPI_TYPE_ANY, 323/* 28 */ ACPI_OP("Or", ARGP_BIT_OR_OP, ARGI_BIT_OR_OP, ACPI_TYPE_ANY,
324 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, 324 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R,
325 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 325 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
326/* 29 */ ACPI_OP("NOr", ARGP_BIT_NOR_OP, ARGI_BIT_NOR_OP, ACPI_TYPE_ANY, 326/* 29 */ ACPI_OP("NOr", ARGP_BIT_NOR_OP, ARGI_BIT_NOR_OP, ACPI_TYPE_ANY,
327 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, 327 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R,
328 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 328 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
329/* 2A */ ACPI_OP("XOr", ARGP_BIT_XOR_OP, ARGI_BIT_XOR_OP, ACPI_TYPE_ANY, 329/* 2A */ ACPI_OP("XOr", ARGP_BIT_XOR_OP, ARGI_BIT_XOR_OP, ACPI_TYPE_ANY,
330 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, 330 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R,
331 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT), 331 AML_FLAGS_EXEC_2A_1T_1R | AML_MATH | AML_CONSTANT),
332/* 2B */ ACPI_OP("Not", ARGP_BIT_NOT_OP, ARGI_BIT_NOT_OP, ACPI_TYPE_ANY, 332/* 2B */ ACPI_OP("Not", ARGP_BIT_NOT_OP, ARGI_BIT_NOT_OP, ACPI_TYPE_ANY,
333 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, 333 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R,
334 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), 334 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT),
335/* 2C */ ACPI_OP("FindSetLeftBit", ARGP_FIND_SET_LEFT_BIT_OP, 335/* 2C */ ACPI_OP("FindSetLeftBit", ARGP_FIND_SET_LEFT_BIT_OP,
336 ARGI_FIND_SET_LEFT_BIT_OP, ACPI_TYPE_ANY, 336 ARGI_FIND_SET_LEFT_BIT_OP, ACPI_TYPE_ANY,
337 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, 337 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R,
338 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), 338 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT),
339/* 2D */ ACPI_OP("FindSetRightBit", ARGP_FIND_SET_RIGHT_BIT_OP, 339/* 2D */ ACPI_OP("FindSetRightBit", ARGP_FIND_SET_RIGHT_BIT_OP,
340 ARGI_FIND_SET_RIGHT_BIT_OP, ACPI_TYPE_ANY, 340 ARGI_FIND_SET_RIGHT_BIT_OP, ACPI_TYPE_ANY,
341 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, 341 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R,
342 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), 342 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT),
343/* 2E */ ACPI_OP("DerefOf", ARGP_DEREF_OF_OP, ARGI_DEREF_OF_OP, 343/* 2E */ ACPI_OP("DerefOf", ARGP_DEREF_OF_OP, ARGI_DEREF_OF_OP,
344 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 344 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
345 AML_TYPE_EXEC_1A_0T_1R, AML_FLAGS_EXEC_1A_0T_1R), 345 AML_TYPE_EXEC_1A_0T_1R, AML_FLAGS_EXEC_1A_0T_1R),
346/* 2F */ ACPI_OP("Notify", ARGP_NOTIFY_OP, ARGI_NOTIFY_OP, 346/* 2F */ ACPI_OP("Notify", ARGP_NOTIFY_OP, ARGI_NOTIFY_OP,
347 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 347 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
348 AML_TYPE_EXEC_2A_0T_0R, AML_FLAGS_EXEC_2A_0T_0R), 348 AML_TYPE_EXEC_2A_0T_0R, AML_FLAGS_EXEC_2A_0T_0R),
349/* 30 */ ACPI_OP("SizeOf", ARGP_SIZE_OF_OP, ARGI_SIZE_OF_OP, 349/* 30 */ ACPI_OP("SizeOf", ARGP_SIZE_OF_OP, ARGI_SIZE_OF_OP,
350 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 350 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
351 AML_TYPE_EXEC_1A_0T_1R, 351 AML_TYPE_EXEC_1A_0T_1R,
352 AML_FLAGS_EXEC_1A_0T_1R | AML_NO_OPERAND_RESOLVE), 352 AML_FLAGS_EXEC_1A_0T_1R | AML_NO_OPERAND_RESOLVE),
353/* 31 */ ACPI_OP("Index", ARGP_INDEX_OP, ARGI_INDEX_OP, ACPI_TYPE_ANY, 353/* 31 */ ACPI_OP("Index", ARGP_INDEX_OP, ARGI_INDEX_OP, ACPI_TYPE_ANY,
354 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, 354 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R,
355 AML_FLAGS_EXEC_2A_1T_1R), 355 AML_FLAGS_EXEC_2A_1T_1R),
356/* 32 */ ACPI_OP("Match", ARGP_MATCH_OP, ARGI_MATCH_OP, ACPI_TYPE_ANY, 356/* 32 */ ACPI_OP("Match", ARGP_MATCH_OP, ARGI_MATCH_OP, ACPI_TYPE_ANY,
357 AML_CLASS_EXECUTE, AML_TYPE_EXEC_6A_0T_1R, 357 AML_CLASS_EXECUTE, AML_TYPE_EXEC_6A_0T_1R,
358 AML_FLAGS_EXEC_6A_0T_1R | AML_CONSTANT), 358 AML_FLAGS_EXEC_6A_0T_1R | AML_CONSTANT),
359/* 33 */ ACPI_OP("CreateDWordField", ARGP_CREATE_DWORD_FIELD_OP, 359/* 33 */ ACPI_OP("CreateDWordField", ARGP_CREATE_DWORD_FIELD_OP,
360 ARGI_CREATE_DWORD_FIELD_OP, 360 ARGI_CREATE_DWORD_FIELD_OP,
361 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, 361 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE,
362 AML_TYPE_CREATE_FIELD, 362 AML_TYPE_CREATE_FIELD,
363 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | 363 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE |
364 AML_DEFER | AML_CREATE), 364 AML_DEFER | AML_CREATE),
365/* 34 */ ACPI_OP("CreateWordField", ARGP_CREATE_WORD_FIELD_OP, 365/* 34 */ ACPI_OP("CreateWordField", ARGP_CREATE_WORD_FIELD_OP,
366 ARGI_CREATE_WORD_FIELD_OP, 366 ARGI_CREATE_WORD_FIELD_OP,
367 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, 367 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE,
368 AML_TYPE_CREATE_FIELD, 368 AML_TYPE_CREATE_FIELD,
369 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | 369 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE |
370 AML_DEFER | AML_CREATE), 370 AML_DEFER | AML_CREATE),
371/* 35 */ ACPI_OP("CreateByteField", ARGP_CREATE_BYTE_FIELD_OP, 371/* 35 */ ACPI_OP("CreateByteField", ARGP_CREATE_BYTE_FIELD_OP,
372 ARGI_CREATE_BYTE_FIELD_OP, 372 ARGI_CREATE_BYTE_FIELD_OP,
373 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, 373 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE,
374 AML_TYPE_CREATE_FIELD, 374 AML_TYPE_CREATE_FIELD,
375 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | 375 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE |
376 AML_DEFER | AML_CREATE), 376 AML_DEFER | AML_CREATE),
377/* 36 */ ACPI_OP("CreateBitField", ARGP_CREATE_BIT_FIELD_OP, 377/* 36 */ ACPI_OP("CreateBitField", ARGP_CREATE_BIT_FIELD_OP,
378 ARGI_CREATE_BIT_FIELD_OP, 378 ARGI_CREATE_BIT_FIELD_OP,
379 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, 379 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE,
380 AML_TYPE_CREATE_FIELD, 380 AML_TYPE_CREATE_FIELD,
381 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | 381 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE |
382 AML_DEFER | AML_CREATE), 382 AML_DEFER | AML_CREATE),
383/* 37 */ ACPI_OP("ObjectType", ARGP_TYPE_OP, ARGI_TYPE_OP, 383/* 37 */ ACPI_OP("ObjectType", ARGP_TYPE_OP, ARGI_TYPE_OP,
384 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 384 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
385 AML_TYPE_EXEC_1A_0T_1R, 385 AML_TYPE_EXEC_1A_0T_1R,
386 AML_FLAGS_EXEC_1A_0T_1R | AML_NO_OPERAND_RESOLVE), 386 AML_FLAGS_EXEC_1A_0T_1R | AML_NO_OPERAND_RESOLVE),
387/* 38 */ ACPI_OP("LAnd", ARGP_LAND_OP, ARGI_LAND_OP, ACPI_TYPE_ANY, 387/* 38 */ ACPI_OP("LAnd", ARGP_LAND_OP, ARGI_LAND_OP, ACPI_TYPE_ANY,
388 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, 388 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R,
389 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL_NUMERIC | 389 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL_NUMERIC | AML_CONSTANT),
390 AML_CONSTANT),
391/* 39 */ ACPI_OP("LOr", ARGP_LOR_OP, ARGI_LOR_OP, ACPI_TYPE_ANY, 390/* 39 */ ACPI_OP("LOr", ARGP_LOR_OP, ARGI_LOR_OP, ACPI_TYPE_ANY,
392 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, 391 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R,
393 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL_NUMERIC | 392 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL_NUMERIC | AML_CONSTANT),
394 AML_CONSTANT),
395/* 3A */ ACPI_OP("LNot", ARGP_LNOT_OP, ARGI_LNOT_OP, ACPI_TYPE_ANY, 393/* 3A */ ACPI_OP("LNot", ARGP_LNOT_OP, ARGI_LNOT_OP, ACPI_TYPE_ANY,
396 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R, 394 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_1R,
397 AML_FLAGS_EXEC_1A_0T_1R | AML_CONSTANT), 395 AML_FLAGS_EXEC_1A_0T_1R | AML_CONSTANT),
398/* 3B */ ACPI_OP("LEqual", ARGP_LEQUAL_OP, ARGI_LEQUAL_OP, 396/* 3B */ ACPI_OP("LEqual", ARGP_LEQUAL_OP, ARGI_LEQUAL_OP,
399 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 397 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
400 AML_TYPE_EXEC_2A_0T_1R, 398 AML_TYPE_EXEC_2A_0T_1R,
401 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL | AML_CONSTANT), 399 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL | AML_CONSTANT),
402/* 3C */ ACPI_OP("LGreater", ARGP_LGREATER_OP, ARGI_LGREATER_OP, 400/* 3C */ ACPI_OP("LGreater", ARGP_LGREATER_OP, ARGI_LGREATER_OP,
403 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 401 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
404 AML_TYPE_EXEC_2A_0T_1R, 402 AML_TYPE_EXEC_2A_0T_1R,
405 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL | AML_CONSTANT), 403 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL | AML_CONSTANT),
406/* 3D */ ACPI_OP("LLess", ARGP_LLESS_OP, ARGI_LLESS_OP, ACPI_TYPE_ANY, 404/* 3D */ ACPI_OP("LLess", ARGP_LLESS_OP, ARGI_LLESS_OP, ACPI_TYPE_ANY,
407 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, 405 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R,
408 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL | AML_CONSTANT), 406 AML_FLAGS_EXEC_2A_0T_1R | AML_LOGICAL | AML_CONSTANT),
409/* 3E */ ACPI_OP("If", ARGP_IF_OP, ARGI_IF_OP, ACPI_TYPE_ANY, 407/* 3E */ ACPI_OP("If", ARGP_IF_OP, ARGI_IF_OP, ACPI_TYPE_ANY,
410 AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS), 408 AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS),
411/* 3F */ ACPI_OP("Else", ARGP_ELSE_OP, ARGI_ELSE_OP, ACPI_TYPE_ANY, 409/* 3F */ ACPI_OP("Else", ARGP_ELSE_OP, ARGI_ELSE_OP, ACPI_TYPE_ANY,
412 AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS), 410 AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS),
413/* 40 */ ACPI_OP("While", ARGP_WHILE_OP, ARGI_WHILE_OP, ACPI_TYPE_ANY, 411/* 40 */ ACPI_OP("While", ARGP_WHILE_OP, ARGI_WHILE_OP, ACPI_TYPE_ANY,
414 AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS), 412 AML_CLASS_CONTROL, AML_TYPE_CONTROL, AML_HAS_ARGS),
415/* 41 */ ACPI_OP("Noop", ARGP_NOOP_OP, ARGI_NOOP_OP, ACPI_TYPE_ANY, 413/* 41 */ ACPI_OP("Noop", ARGP_NOOP_OP, ARGI_NOOP_OP, ACPI_TYPE_ANY,
416 AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0), 414 AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0),
417/* 42 */ ACPI_OP("Return", ARGP_RETURN_OP, ARGI_RETURN_OP, 415/* 42 */ ACPI_OP("Return", ARGP_RETURN_OP, ARGI_RETURN_OP,
418 ACPI_TYPE_ANY, AML_CLASS_CONTROL, 416 ACPI_TYPE_ANY, AML_CLASS_CONTROL,
419 AML_TYPE_CONTROL, AML_HAS_ARGS), 417 AML_TYPE_CONTROL, AML_HAS_ARGS),
420/* 43 */ ACPI_OP("Break", ARGP_BREAK_OP, ARGI_BREAK_OP, ACPI_TYPE_ANY, 418/* 43 */ ACPI_OP("Break", ARGP_BREAK_OP, ARGI_BREAK_OP, ACPI_TYPE_ANY,
421 AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0), 419 AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0),
422/* 44 */ ACPI_OP("BreakPoint", ARGP_BREAK_POINT_OP, ARGI_BREAK_POINT_OP, 420/* 44 */ ACPI_OP("BreakPoint", ARGP_BREAK_POINT_OP, ARGI_BREAK_POINT_OP,
423 ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0), 421 ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0),
424/* 45 */ ACPI_OP("Ones", ARGP_ONES_OP, ARGI_ONES_OP, ACPI_TYPE_INTEGER, 422/* 45 */ ACPI_OP("Ones", ARGP_ONES_OP, ARGI_ONES_OP, ACPI_TYPE_INTEGER,
425 AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT), 423 AML_CLASS_ARGUMENT, AML_TYPE_CONSTANT, AML_CONSTANT),
426 424
427/* Prefixed opcodes (Two-byte opcodes with a prefix op) */ 425/* Prefixed opcodes (Two-byte opcodes with a prefix op) */
428 426
429/* 46 */ ACPI_OP("Mutex", ARGP_MUTEX_OP, ARGI_MUTEX_OP, ACPI_TYPE_MUTEX, 427/* 46 */ ACPI_OP("Mutex", ARGP_MUTEX_OP, ARGI_MUTEX_OP, ACPI_TYPE_MUTEX,
430 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, 428 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE,
431 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 429 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
432 AML_NSNODE | AML_NAMED), 430 AML_NSNODE | AML_NAMED),
433/* 47 */ ACPI_OP("Event", ARGP_EVENT_OP, ARGI_EVENT_OP, ACPI_TYPE_EVENT, 431/* 47 */ ACPI_OP("Event", ARGP_EVENT_OP, ARGI_EVENT_OP, ACPI_TYPE_EVENT,
434 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, 432 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE,
435 AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), 433 AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED),
436/* 48 */ ACPI_OP("CondRefOf", ARGP_COND_REF_OF_OP, ARGI_COND_REF_OF_OP, 434/* 48 */ ACPI_OP("CondRefOf", ARGP_COND_REF_OF_OP, ARGI_COND_REF_OF_OP,
437 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 435 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
438 AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R), 436 AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R),
439/* 49 */ ACPI_OP("CreateField", ARGP_CREATE_FIELD_OP, 437/* 49 */ ACPI_OP("CreateField", ARGP_CREATE_FIELD_OP,
440 ARGI_CREATE_FIELD_OP, ACPI_TYPE_BUFFER_FIELD, 438 ARGI_CREATE_FIELD_OP, ACPI_TYPE_BUFFER_FIELD,
441 AML_CLASS_CREATE, AML_TYPE_CREATE_FIELD, 439 AML_CLASS_CREATE, AML_TYPE_CREATE_FIELD,
442 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | 440 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE |
443 AML_DEFER | AML_FIELD | AML_CREATE), 441 AML_DEFER | AML_FIELD | AML_CREATE),
444/* 4A */ ACPI_OP("Load", ARGP_LOAD_OP, ARGI_LOAD_OP, ACPI_TYPE_ANY, 442/* 4A */ ACPI_OP("Load", ARGP_LOAD_OP, ARGI_LOAD_OP, ACPI_TYPE_ANY,
445 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_0R, 443 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_0R,
446 AML_FLAGS_EXEC_1A_1T_0R), 444 AML_FLAGS_EXEC_1A_1T_0R),
447/* 4B */ ACPI_OP("Stall", ARGP_STALL_OP, ARGI_STALL_OP, ACPI_TYPE_ANY, 445/* 4B */ ACPI_OP("Stall", ARGP_STALL_OP, ARGI_STALL_OP, ACPI_TYPE_ANY,
448 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R, 446 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R,
449 AML_FLAGS_EXEC_1A_0T_0R), 447 AML_FLAGS_EXEC_1A_0T_0R),
450/* 4C */ ACPI_OP("Sleep", ARGP_SLEEP_OP, ARGI_SLEEP_OP, ACPI_TYPE_ANY, 448/* 4C */ ACPI_OP("Sleep", ARGP_SLEEP_OP, ARGI_SLEEP_OP, ACPI_TYPE_ANY,
451 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R, 449 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R,
452 AML_FLAGS_EXEC_1A_0T_0R), 450 AML_FLAGS_EXEC_1A_0T_0R),
453/* 4D */ ACPI_OP("Acquire", ARGP_ACQUIRE_OP, ARGI_ACQUIRE_OP, 451/* 4D */ ACPI_OP("Acquire", ARGP_ACQUIRE_OP, ARGI_ACQUIRE_OP,
454 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 452 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
455 AML_TYPE_EXEC_2A_0T_1R, AML_FLAGS_EXEC_2A_0T_1R), 453 AML_TYPE_EXEC_2A_0T_1R, AML_FLAGS_EXEC_2A_0T_1R),
456/* 4E */ ACPI_OP("Signal", ARGP_SIGNAL_OP, ARGI_SIGNAL_OP, 454/* 4E */ ACPI_OP("Signal", ARGP_SIGNAL_OP, ARGI_SIGNAL_OP,
457 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 455 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
458 AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R), 456 AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R),
459/* 4F */ ACPI_OP("Wait", ARGP_WAIT_OP, ARGI_WAIT_OP, ACPI_TYPE_ANY, 457/* 4F */ ACPI_OP("Wait", ARGP_WAIT_OP, ARGI_WAIT_OP, ACPI_TYPE_ANY,
460 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R, 458 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_0T_1R,
461 AML_FLAGS_EXEC_2A_0T_1R), 459 AML_FLAGS_EXEC_2A_0T_1R),
462/* 50 */ ACPI_OP("Reset", ARGP_RESET_OP, ARGI_RESET_OP, ACPI_TYPE_ANY, 460/* 50 */ ACPI_OP("Reset", ARGP_RESET_OP, ARGI_RESET_OP, ACPI_TYPE_ANY,
463 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R, 461 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_0T_0R,
464 AML_FLAGS_EXEC_1A_0T_0R), 462 AML_FLAGS_EXEC_1A_0T_0R),
465/* 51 */ ACPI_OP("Release", ARGP_RELEASE_OP, ARGI_RELEASE_OP, 463/* 51 */ ACPI_OP("Release", ARGP_RELEASE_OP, ARGI_RELEASE_OP,
466 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 464 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
467 AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R), 465 AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R),
468/* 52 */ ACPI_OP("FromBCD", ARGP_FROM_BCD_OP, ARGI_FROM_BCD_OP, 466/* 52 */ ACPI_OP("FromBCD", ARGP_FROM_BCD_OP, ARGI_FROM_BCD_OP,
469 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 467 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
470 AML_TYPE_EXEC_1A_1T_1R, 468 AML_TYPE_EXEC_1A_1T_1R,
471 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), 469 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT),
472/* 53 */ ACPI_OP("ToBCD", ARGP_TO_BCD_OP, ARGI_TO_BCD_OP, ACPI_TYPE_ANY, 470/* 53 */ ACPI_OP("ToBCD", ARGP_TO_BCD_OP, ARGI_TO_BCD_OP, ACPI_TYPE_ANY,
473 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, 471 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R,
474 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), 472 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT),
475/* 54 */ ACPI_OP("Unload", ARGP_UNLOAD_OP, ARGI_UNLOAD_OP, 473/* 54 */ ACPI_OP("Unload", ARGP_UNLOAD_OP, ARGI_UNLOAD_OP,
476 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 474 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
477 AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R), 475 AML_TYPE_EXEC_1A_0T_0R, AML_FLAGS_EXEC_1A_0T_0R),
478/* 55 */ ACPI_OP("Revision", ARGP_REVISION_OP, ARGI_REVISION_OP, 476/* 55 */ ACPI_OP("Revision", ARGP_REVISION_OP, ARGI_REVISION_OP,
479 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, 477 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT,
480 AML_TYPE_CONSTANT, 0), 478 AML_TYPE_CONSTANT, 0),
481/* 56 */ ACPI_OP("Debug", ARGP_DEBUG_OP, ARGI_DEBUG_OP, 479/* 56 */ ACPI_OP("Debug", ARGP_DEBUG_OP, ARGI_DEBUG_OP,
482 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 480 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
483 AML_TYPE_CONSTANT, 0), 481 AML_TYPE_CONSTANT, 0),
484/* 57 */ ACPI_OP("Fatal", ARGP_FATAL_OP, ARGI_FATAL_OP, ACPI_TYPE_ANY, 482/* 57 */ ACPI_OP("Fatal", ARGP_FATAL_OP, ARGI_FATAL_OP, ACPI_TYPE_ANY,
485 AML_CLASS_EXECUTE, AML_TYPE_EXEC_3A_0T_0R, 483 AML_CLASS_EXECUTE, AML_TYPE_EXEC_3A_0T_0R,
486 AML_FLAGS_EXEC_3A_0T_0R), 484 AML_FLAGS_EXEC_3A_0T_0R),
487/* 58 */ ACPI_OP("OperationRegion", ARGP_REGION_OP, ARGI_REGION_OP, 485/* 58 */ ACPI_OP("OperationRegion", ARGP_REGION_OP, ARGI_REGION_OP,
488 ACPI_TYPE_REGION, AML_CLASS_NAMED_OBJECT, 486 ACPI_TYPE_REGION, AML_CLASS_NAMED_OBJECT,
489 AML_TYPE_NAMED_COMPLEX, 487 AML_TYPE_NAMED_COMPLEX,
490 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 488 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
491 AML_NSNODE | AML_NAMED | AML_DEFER), 489 AML_NSNODE | AML_NAMED | AML_DEFER),
492/* 59 */ ACPI_OP("Field", ARGP_FIELD_OP, ARGI_FIELD_OP, ACPI_TYPE_ANY, 490/* 59 */ ACPI_OP("Field", ARGP_FIELD_OP, ARGI_FIELD_OP, ACPI_TYPE_ANY,
493 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_FIELD, 491 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_FIELD,
494 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 492 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD),
495 AML_FIELD),
496/* 5A */ ACPI_OP("Device", ARGP_DEVICE_OP, ARGI_DEVICE_OP, 493/* 5A */ ACPI_OP("Device", ARGP_DEVICE_OP, ARGI_DEVICE_OP,
497 ACPI_TYPE_DEVICE, AML_CLASS_NAMED_OBJECT, 494 ACPI_TYPE_DEVICE, AML_CLASS_NAMED_OBJECT,
498 AML_TYPE_NAMED_NO_OBJ, 495 AML_TYPE_NAMED_NO_OBJ,
499 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 496 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
500 AML_NSNODE | AML_NAMED), 497 AML_NSNODE | AML_NAMED),
501/* 5B */ ACPI_OP("Processor", ARGP_PROCESSOR_OP, ARGI_PROCESSOR_OP, 498/* 5B */ ACPI_OP("Processor", ARGP_PROCESSOR_OP, ARGI_PROCESSOR_OP,
502 ACPI_TYPE_PROCESSOR, AML_CLASS_NAMED_OBJECT, 499 ACPI_TYPE_PROCESSOR, AML_CLASS_NAMED_OBJECT,
503 AML_TYPE_NAMED_SIMPLE, 500 AML_TYPE_NAMED_SIMPLE,
504 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 501 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
505 AML_NSNODE | AML_NAMED), 502 AML_NSNODE | AML_NAMED),
506/* 5C */ ACPI_OP("PowerResource", ARGP_POWER_RES_OP, ARGI_POWER_RES_OP, 503/* 5C */ ACPI_OP("PowerResource", ARGP_POWER_RES_OP, ARGI_POWER_RES_OP,
507 ACPI_TYPE_POWER, AML_CLASS_NAMED_OBJECT, 504 ACPI_TYPE_POWER, AML_CLASS_NAMED_OBJECT,
508 AML_TYPE_NAMED_SIMPLE, 505 AML_TYPE_NAMED_SIMPLE,
509 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 506 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
510 AML_NSNODE | AML_NAMED), 507 AML_NSNODE | AML_NAMED),
511/* 5D */ ACPI_OP("ThermalZone", ARGP_THERMAL_ZONE_OP, 508/* 5D */ ACPI_OP("ThermalZone", ARGP_THERMAL_ZONE_OP,
512 ARGI_THERMAL_ZONE_OP, ACPI_TYPE_THERMAL, 509 ARGI_THERMAL_ZONE_OP, ACPI_TYPE_THERMAL,
513 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_NO_OBJ, 510 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_NO_OBJ,
514 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 511 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
515 AML_NSNODE | AML_NAMED), 512 AML_NSNODE | AML_NAMED),
516/* 5E */ ACPI_OP("IndexField", ARGP_INDEX_FIELD_OP, ARGI_INDEX_FIELD_OP, 513/* 5E */ ACPI_OP("IndexField", ARGP_INDEX_FIELD_OP, ARGI_INDEX_FIELD_OP,
517 ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, 514 ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT,
518 AML_TYPE_NAMED_FIELD, 515 AML_TYPE_NAMED_FIELD,
519 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 516 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD),
520 AML_FIELD),
521/* 5F */ ACPI_OP("BankField", ARGP_BANK_FIELD_OP, ARGI_BANK_FIELD_OP, 517/* 5F */ ACPI_OP("BankField", ARGP_BANK_FIELD_OP, ARGI_BANK_FIELD_OP,
522 ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, 518 ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT,
523 AML_TYPE_NAMED_FIELD, 519 AML_TYPE_NAMED_FIELD,
524 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 520 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_FIELD),
525 AML_FIELD),
526 521
527/* Internal opcodes that map to invalid AML opcodes */ 522/* Internal opcodes that map to invalid AML opcodes */
528 523
529/* 60 */ ACPI_OP("LNotEqual", ARGP_LNOTEQUAL_OP, ARGI_LNOTEQUAL_OP, 524/* 60 */ ACPI_OP("LNotEqual", ARGP_LNOTEQUAL_OP, ARGI_LNOTEQUAL_OP,
530 ACPI_TYPE_ANY, AML_CLASS_INTERNAL, 525 ACPI_TYPE_ANY, AML_CLASS_INTERNAL,
531 AML_TYPE_BOGUS, AML_HAS_ARGS | AML_CONSTANT), 526 AML_TYPE_BOGUS, AML_HAS_ARGS | AML_CONSTANT),
532/* 61 */ ACPI_OP("LLessEqual", ARGP_LLESSEQUAL_OP, ARGI_LLESSEQUAL_OP, 527/* 61 */ ACPI_OP("LLessEqual", ARGP_LLESSEQUAL_OP, ARGI_LLESSEQUAL_OP,
533 ACPI_TYPE_ANY, AML_CLASS_INTERNAL, 528 ACPI_TYPE_ANY, AML_CLASS_INTERNAL,
534 AML_TYPE_BOGUS, AML_HAS_ARGS | AML_CONSTANT), 529 AML_TYPE_BOGUS, AML_HAS_ARGS | AML_CONSTANT),
535/* 62 */ ACPI_OP("LGreaterEqual", ARGP_LGREATEREQUAL_OP, 530/* 62 */ ACPI_OP("LGreaterEqual", ARGP_LGREATEREQUAL_OP,
536 ARGI_LGREATEREQUAL_OP, ACPI_TYPE_ANY, 531 ARGI_LGREATEREQUAL_OP, ACPI_TYPE_ANY,
537 AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 532 AML_CLASS_INTERNAL, AML_TYPE_BOGUS,
538 AML_HAS_ARGS | AML_CONSTANT), 533 AML_HAS_ARGS | AML_CONSTANT),
539/* 63 */ ACPI_OP("-NamePath-", ARGP_NAMEPATH_OP, ARGI_NAMEPATH_OP, 534/* 63 */ ACPI_OP("-NamePath-", ARGP_NAMEPATH_OP, ARGI_NAMEPATH_OP,
540 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT, 535 ACPI_TYPE_LOCAL_REFERENCE, AML_CLASS_ARGUMENT,
541 AML_TYPE_LITERAL, AML_NSOBJECT | AML_NSNODE), 536 AML_TYPE_LITERAL, AML_NSOBJECT | AML_NSNODE),
542/* 64 */ ACPI_OP("-MethodCall-", ARGP_METHODCALL_OP, ARGI_METHODCALL_OP, 537/* 64 */ ACPI_OP("-MethodCall-", ARGP_METHODCALL_OP, ARGI_METHODCALL_OP,
543 ACPI_TYPE_METHOD, AML_CLASS_METHOD_CALL, 538 ACPI_TYPE_METHOD, AML_CLASS_METHOD_CALL,
544 AML_TYPE_METHOD_CALL, 539 AML_TYPE_METHOD_CALL,
545 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE), 540 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE),
546/* 65 */ ACPI_OP("-ByteList-", ARGP_BYTELIST_OP, ARGI_BYTELIST_OP, 541/* 65 */ ACPI_OP("-ByteList-", ARGP_BYTELIST_OP, ARGI_BYTELIST_OP,
547 ACPI_TYPE_ANY, AML_CLASS_ARGUMENT, 542 ACPI_TYPE_ANY, AML_CLASS_ARGUMENT,
548 AML_TYPE_LITERAL, 0), 543 AML_TYPE_LITERAL, 0),
549/* 66 */ ACPI_OP("-ReservedField-", ARGP_RESERVEDFIELD_OP, 544/* 66 */ ACPI_OP("-ReservedField-", ARGP_RESERVEDFIELD_OP,
550 ARGI_RESERVEDFIELD_OP, ACPI_TYPE_ANY, 545 ARGI_RESERVEDFIELD_OP, ACPI_TYPE_ANY,
551 AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0), 546 AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0),
552/* 67 */ ACPI_OP("-NamedField-", ARGP_NAMEDFIELD_OP, ARGI_NAMEDFIELD_OP, 547/* 67 */ ACPI_OP("-NamedField-", ARGP_NAMEDFIELD_OP, ARGI_NAMEDFIELD_OP,
553 ACPI_TYPE_ANY, AML_CLASS_INTERNAL, 548 ACPI_TYPE_ANY, AML_CLASS_INTERNAL,
554 AML_TYPE_BOGUS, 549 AML_TYPE_BOGUS,
555 AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED), 550 AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE | AML_NAMED),
556/* 68 */ ACPI_OP("-AccessField-", ARGP_ACCESSFIELD_OP, 551/* 68 */ ACPI_OP("-AccessField-", ARGP_ACCESSFIELD_OP,
557 ARGI_ACCESSFIELD_OP, ACPI_TYPE_ANY, 552 ARGI_ACCESSFIELD_OP, ACPI_TYPE_ANY,
558 AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0), 553 AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0),
559/* 69 */ ACPI_OP("-StaticString", ARGP_STATICSTRING_OP, 554/* 69 */ ACPI_OP("-StaticString", ARGP_STATICSTRING_OP,
560 ARGI_STATICSTRING_OP, ACPI_TYPE_ANY, 555 ARGI_STATICSTRING_OP, ACPI_TYPE_ANY,
561 AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0), 556 AML_CLASS_INTERNAL, AML_TYPE_BOGUS, 0),
562/* 6A */ ACPI_OP("-Return Value-", ARG_NONE, ARG_NONE, ACPI_TYPE_ANY, 557/* 6A */ ACPI_OP("-Return Value-", ARG_NONE, ARG_NONE, ACPI_TYPE_ANY,
563 AML_CLASS_RETURN_VALUE, AML_TYPE_RETURN, 558 AML_CLASS_RETURN_VALUE, AML_TYPE_RETURN,
564 AML_HAS_ARGS | AML_HAS_RETVAL), 559 AML_HAS_ARGS | AML_HAS_RETVAL),
565/* 6B */ ACPI_OP("-UNKNOWN_OP-", ARG_NONE, ARG_NONE, ACPI_TYPE_INVALID, 560/* 6B */ ACPI_OP("-UNKNOWN_OP-", ARG_NONE, ARG_NONE, ACPI_TYPE_INVALID,
566 AML_CLASS_UNKNOWN, AML_TYPE_BOGUS, AML_HAS_ARGS), 561 AML_CLASS_UNKNOWN, AML_TYPE_BOGUS, AML_HAS_ARGS),
567/* 6C */ ACPI_OP("-ASCII_ONLY-", ARG_NONE, ARG_NONE, ACPI_TYPE_ANY, 562/* 6C */ ACPI_OP("-ASCII_ONLY-", ARG_NONE, ARG_NONE, ACPI_TYPE_ANY,
568 AML_CLASS_ASCII, AML_TYPE_BOGUS, AML_HAS_ARGS), 563 AML_CLASS_ASCII, AML_TYPE_BOGUS, AML_HAS_ARGS),
569/* 6D */ ACPI_OP("-PREFIX_ONLY-", ARG_NONE, ARG_NONE, ACPI_TYPE_ANY, 564/* 6D */ ACPI_OP("-PREFIX_ONLY-", ARG_NONE, ARG_NONE, ACPI_TYPE_ANY,
570 AML_CLASS_PREFIX, AML_TYPE_BOGUS, AML_HAS_ARGS), 565 AML_CLASS_PREFIX, AML_TYPE_BOGUS, AML_HAS_ARGS),
571 566
572/* ACPI 2.0 opcodes */ 567/* ACPI 2.0 opcodes */
573 568
574/* 6E */ ACPI_OP("QwordConst", ARGP_QWORD_OP, ARGI_QWORD_OP, 569/* 6E */ ACPI_OP("QwordConst", ARGP_QWORD_OP, ARGI_QWORD_OP,
575 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT, 570 ACPI_TYPE_INTEGER, AML_CLASS_ARGUMENT,
576 AML_TYPE_LITERAL, AML_CONSTANT), 571 AML_TYPE_LITERAL, AML_CONSTANT),
577 /* 6F */ ACPI_OP("Package", /* Var */ ARGP_VAR_PACKAGE_OP, 572 /* 6F */ ACPI_OP("Package", /* Var */ ARGP_VAR_PACKAGE_OP,
578 ARGI_VAR_PACKAGE_OP, ACPI_TYPE_PACKAGE, 573 ARGI_VAR_PACKAGE_OP, ACPI_TYPE_PACKAGE,
579 AML_CLASS_CREATE, AML_TYPE_CREATE_OBJECT, 574 AML_CLASS_CREATE, AML_TYPE_CREATE_OBJECT,
580 AML_HAS_ARGS | AML_DEFER), 575 AML_HAS_ARGS | AML_DEFER),
581/* 70 */ ACPI_OP("ConcatenateResTemplate", ARGP_CONCAT_RES_OP, 576/* 70 */ ACPI_OP("ConcatenateResTemplate", ARGP_CONCAT_RES_OP,
582 ARGI_CONCAT_RES_OP, ACPI_TYPE_ANY, 577 ARGI_CONCAT_RES_OP, ACPI_TYPE_ANY,
583 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, 578 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R,
584 AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT), 579 AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT),
585/* 71 */ ACPI_OP("Mod", ARGP_MOD_OP, ARGI_MOD_OP, ACPI_TYPE_ANY, 580/* 71 */ ACPI_OP("Mod", ARGP_MOD_OP, ARGI_MOD_OP, ACPI_TYPE_ANY,
586 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R, 581 AML_CLASS_EXECUTE, AML_TYPE_EXEC_2A_1T_1R,
587 AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT), 582 AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT),
588/* 72 */ ACPI_OP("CreateQWordField", ARGP_CREATE_QWORD_FIELD_OP, 583/* 72 */ ACPI_OP("CreateQWordField", ARGP_CREATE_QWORD_FIELD_OP,
589 ARGI_CREATE_QWORD_FIELD_OP, 584 ARGI_CREATE_QWORD_FIELD_OP,
590 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE, 585 ACPI_TYPE_BUFFER_FIELD, AML_CLASS_CREATE,
591 AML_TYPE_CREATE_FIELD, 586 AML_TYPE_CREATE_FIELD,
592 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE | 587 AML_HAS_ARGS | AML_NSOBJECT | AML_NSNODE |
593 AML_DEFER | AML_CREATE), 588 AML_DEFER | AML_CREATE),
594/* 73 */ ACPI_OP("ToBuffer", ARGP_TO_BUFFER_OP, ARGI_TO_BUFFER_OP, 589/* 73 */ ACPI_OP("ToBuffer", ARGP_TO_BUFFER_OP, ARGI_TO_BUFFER_OP,
595 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 590 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
596 AML_TYPE_EXEC_1A_1T_1R, 591 AML_TYPE_EXEC_1A_1T_1R,
597 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), 592 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT),
598/* 74 */ ACPI_OP("ToDecimalString", ARGP_TO_DEC_STR_OP, 593/* 74 */ ACPI_OP("ToDecimalString", ARGP_TO_DEC_STR_OP,
599 ARGI_TO_DEC_STR_OP, ACPI_TYPE_ANY, 594 ARGI_TO_DEC_STR_OP, ACPI_TYPE_ANY,
600 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R, 595 AML_CLASS_EXECUTE, AML_TYPE_EXEC_1A_1T_1R,
601 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), 596 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT),
602/* 75 */ ACPI_OP("ToHexString", ARGP_TO_HEX_STR_OP, ARGI_TO_HEX_STR_OP, 597/* 75 */ ACPI_OP("ToHexString", ARGP_TO_HEX_STR_OP, ARGI_TO_HEX_STR_OP,
603 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 598 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
604 AML_TYPE_EXEC_1A_1T_1R, 599 AML_TYPE_EXEC_1A_1T_1R,
605 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), 600 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT),
606/* 76 */ ACPI_OP("ToInteger", ARGP_TO_INTEGER_OP, ARGI_TO_INTEGER_OP, 601/* 76 */ ACPI_OP("ToInteger", ARGP_TO_INTEGER_OP, ARGI_TO_INTEGER_OP,
607 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 602 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
608 AML_TYPE_EXEC_1A_1T_1R, 603 AML_TYPE_EXEC_1A_1T_1R,
609 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT), 604 AML_FLAGS_EXEC_1A_1T_1R | AML_CONSTANT),
610/* 77 */ ACPI_OP("ToString", ARGP_TO_STRING_OP, ARGI_TO_STRING_OP, 605/* 77 */ ACPI_OP("ToString", ARGP_TO_STRING_OP, ARGI_TO_STRING_OP,
611 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 606 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
612 AML_TYPE_EXEC_2A_1T_1R, 607 AML_TYPE_EXEC_2A_1T_1R,
613 AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT), 608 AML_FLAGS_EXEC_2A_1T_1R | AML_CONSTANT),
614/* 78 */ ACPI_OP("CopyObject", ARGP_COPY_OP, ARGI_COPY_OP, 609/* 78 */ ACPI_OP("CopyObject", ARGP_COPY_OP, ARGI_COPY_OP,
615 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 610 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
616 AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R), 611 AML_TYPE_EXEC_1A_1T_1R, AML_FLAGS_EXEC_1A_1T_1R),
617/* 79 */ ACPI_OP("Mid", ARGP_MID_OP, ARGI_MID_OP, ACPI_TYPE_ANY, 612/* 79 */ ACPI_OP("Mid", ARGP_MID_OP, ARGI_MID_OP, ACPI_TYPE_ANY,
618 AML_CLASS_EXECUTE, AML_TYPE_EXEC_3A_1T_1R, 613 AML_CLASS_EXECUTE, AML_TYPE_EXEC_3A_1T_1R,
619 AML_FLAGS_EXEC_3A_1T_1R | AML_CONSTANT), 614 AML_FLAGS_EXEC_3A_1T_1R | AML_CONSTANT),
620/* 7A */ ACPI_OP("Continue", ARGP_CONTINUE_OP, ARGI_CONTINUE_OP, 615/* 7A */ ACPI_OP("Continue", ARGP_CONTINUE_OP, ARGI_CONTINUE_OP,
621 ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0), 616 ACPI_TYPE_ANY, AML_CLASS_CONTROL, AML_TYPE_CONTROL, 0),
622/* 7B */ ACPI_OP("LoadTable", ARGP_LOAD_TABLE_OP, ARGI_LOAD_TABLE_OP, 617/* 7B */ ACPI_OP("LoadTable", ARGP_LOAD_TABLE_OP, ARGI_LOAD_TABLE_OP,
623 ACPI_TYPE_ANY, AML_CLASS_EXECUTE, 618 ACPI_TYPE_ANY, AML_CLASS_EXECUTE,
624 AML_TYPE_EXEC_6A_0T_1R, AML_FLAGS_EXEC_6A_0T_1R), 619 AML_TYPE_EXEC_6A_0T_1R, AML_FLAGS_EXEC_6A_0T_1R),
625/* 7C */ ACPI_OP("DataTableRegion", ARGP_DATA_REGION_OP, 620/* 7C */ ACPI_OP("DataTableRegion", ARGP_DATA_REGION_OP,
626 ARGI_DATA_REGION_OP, ACPI_TYPE_REGION, 621 ARGI_DATA_REGION_OP, ACPI_TYPE_REGION,
627 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE, 622 AML_CLASS_NAMED_OBJECT, AML_TYPE_NAMED_SIMPLE,
628 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 623 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE |
629 AML_NSNODE | AML_NAMED), 624 AML_NSNODE | AML_NAMED),
630/* 7D */ ACPI_OP("[EvalSubTree]", ARGP_SCOPE_OP, ARGI_SCOPE_OP, 625/* 7D */ ACPI_OP("[EvalSubTree]", ARGP_SCOPE_OP, ARGI_SCOPE_OP,
631 ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT, 626 ACPI_TYPE_ANY, AML_CLASS_NAMED_OBJECT,
632 AML_TYPE_NAMED_NO_OBJ, 627 AML_TYPE_NAMED_NO_OBJ,
633 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | 628 AML_HAS_ARGS | AML_NSOBJECT | AML_NSOPCODE | AML_NSNODE),
634 AML_NSNODE),
635 629
636/* ACPI 3.0 opcodes */ 630/* ACPI 3.0 opcodes */
637 631
638/* 7E */ ACPI_OP("Timer", ARGP_TIMER_OP, ARGI_TIMER_OP, ACPI_TYPE_ANY, 632/* 7E */ ACPI_OP("Timer", ARGP_TIMER_OP, ARGI_TIMER_OP, ACPI_TYPE_ANY,
639 AML_CLASS_EXECUTE, AML_TYPE_EXEC_0A_0T_1R, 633 AML_CLASS_EXECUTE, AML_TYPE_EXEC_0A_0T_1R,
640 AML_FLAGS_EXEC_0A_0T_1R) 634 AML_FLAGS_EXEC_0A_0T_1R)
641 635
642/*! [End] no source code translation !*/ 636/*! [End] no source code translation !*/
643}; 637};
diff --git a/drivers/acpi/resources/rscalc.c b/drivers/acpi/resources/rscalc.c
index 8c6d3fdec38a..0dd2ce8a3475 100644
--- a/drivers/acpi/resources/rscalc.c
+++ b/drivers/acpi/resources/rscalc.c
@@ -567,7 +567,8 @@ acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
567 (*sub_object_list)->string. 567 (*sub_object_list)->string.
568 length + 1); 568 length + 1);
569 } else { 569 } else {
570 temp_size_needed += acpi_ns_get_pathname_length((*sub_object_list)->reference.node); 570 temp_size_needed +=
571 acpi_ns_get_pathname_length((*sub_object_list)->reference.node);
571 } 572 }
572 } else { 573 } else {
573 /* 574 /*
diff --git a/drivers/acpi/resources/rscreate.c b/drivers/acpi/resources/rscreate.c
index cc48ab05676c..50da494c3ee2 100644
--- a/drivers/acpi/resources/rscreate.c
+++ b/drivers/acpi/resources/rscreate.c
@@ -267,16 +267,19 @@ acpi_rs_create_pci_routing_table(union acpi_operand_object *package_object,
267 * If BIOS erroneously reversed the _PRT source_name and source_index, 267 * If BIOS erroneously reversed the _PRT source_name and source_index,
268 * then reverse them back. 268 * then reverse them back.
269 */ 269 */
270 if (ACPI_GET_OBJECT_TYPE (sub_object_list[3]) != ACPI_TYPE_INTEGER) { 270 if (ACPI_GET_OBJECT_TYPE(sub_object_list[3]) !=
271 ACPI_TYPE_INTEGER) {
271 if (acpi_gbl_enable_interpreter_slack) { 272 if (acpi_gbl_enable_interpreter_slack) {
272 source_name_index = 3; 273 source_name_index = 3;
273 source_index_index = 2; 274 source_index_index = 2;
274 printk(KERN_WARNING "ACPI: Handling Garbled _PRT entry\n"); 275 printk(KERN_WARNING
276 "ACPI: Handling Garbled _PRT entry\n");
275 } else { 277 } else {
276 ACPI_ERROR((AE_INFO, 278 ACPI_ERROR((AE_INFO,
277 "(PRT[%X].source_index) Need Integer, found %s", 279 "(PRT[%X].source_index) Need Integer, found %s",
278 index, 280 index,
279 acpi_ut_get_object_type_name(sub_object_list[3]))); 281 acpi_ut_get_object_type_name
282 (sub_object_list[3])));
280 return_ACPI_STATUS(AE_BAD_DATA); 283 return_ACPI_STATUS(AE_BAD_DATA);
281 } 284 }
282 } 285 }
diff --git a/drivers/acpi/resources/rsdump.c b/drivers/acpi/resources/rsdump.c
index de20a5d6decf..46da116a4030 100644
--- a/drivers/acpi/resources/rsdump.c
+++ b/drivers/acpi/resources/rsdump.c
@@ -46,7 +46,6 @@
46 46
47#define _COMPONENT ACPI_RESOURCES 47#define _COMPONENT ACPI_RESOURCES
48ACPI_MODULE_NAME("rsdump") 48ACPI_MODULE_NAME("rsdump")
49
50#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER) 49#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
51/* Local prototypes */ 50/* Local prototypes */
52static void acpi_rs_out_string(char *title, char *value); 51static void acpi_rs_out_string(char *title, char *value);
@@ -489,10 +488,9 @@ acpi_rs_dump_descriptor(void *resource, struct acpi_rsdump_info *table)
489 /* 488 /*
490 * Optional resource_source for Address resources 489 * Optional resource_source for Address resources
491 */ 490 */
492 acpi_rs_dump_resource_source(ACPI_CAST_PTR 491 acpi_rs_dump_resource_source(ACPI_CAST_PTR(struct
493 (struct 492 acpi_resource_source,
494 acpi_resource_source, 493 target));
495 target));
496 break; 494 break;
497 495
498 default: 496 default:
diff --git a/drivers/acpi/resources/rsinfo.c b/drivers/acpi/resources/rsinfo.c
index 7e3c335ab320..2c2adb6292c1 100644
--- a/drivers/acpi/resources/rsinfo.c
+++ b/drivers/acpi/resources/rsinfo.c
@@ -142,7 +142,7 @@ struct acpi_rsdump_info *acpi_gbl_dump_resource_dispatch[] = {
142}; 142};
143#endif 143#endif
144 144
145#endif /* ACPI_FUTURE_USAGE */ 145#endif /* ACPI_FUTURE_USAGE */
146/* 146/*
147 * Base sizes for external AML resource descriptors, indexed by internal type. 147 * Base sizes for external AML resource descriptors, indexed by internal type.
148 * Includes size of the descriptor header (1 byte for small descriptors, 148 * Includes size of the descriptor header (1 byte for small descriptors,
diff --git a/drivers/acpi/resources/rslist.c b/drivers/acpi/resources/rslist.c
index a92755c8877d..ca21e4660c79 100644
--- a/drivers/acpi/resources/rslist.c
+++ b/drivers/acpi/resources/rslist.c
@@ -153,10 +153,9 @@ acpi_rs_convert_resources_to_aml(struct acpi_resource *resource,
153 153
154 /* Perform the conversion */ 154 /* Perform the conversion */
155 155
156 status = acpi_rs_convert_resource_to_aml(resource, 156 status = acpi_rs_convert_resource_to_aml(resource, ACPI_CAST_PTR(union
157 ACPI_CAST_PTR(union 157 aml_resource,
158 aml_resource, 158 aml),
159 aml),
160 acpi_gbl_set_resource_dispatch 159 acpi_gbl_set_resource_dispatch
161 [resource->type]); 160 [resource->type]);
162 if (ACPI_FAILURE(status)) { 161 if (ACPI_FAILURE(status)) {
diff --git a/drivers/acpi/resources/rsmisc.c b/drivers/acpi/resources/rsmisc.c
index 3b63b561b94e..c7081afa893a 100644
--- a/drivers/acpi/resources/rsmisc.c
+++ b/drivers/acpi/resources/rsmisc.c
@@ -46,7 +46,6 @@
46 46
47#define _COMPONENT ACPI_RESOURCES 47#define _COMPONENT ACPI_RESOURCES
48ACPI_MODULE_NAME("rsmisc") 48ACPI_MODULE_NAME("rsmisc")
49
50#define INIT_RESOURCE_TYPE(i) i->resource_offset 49#define INIT_RESOURCE_TYPE(i) i->resource_offset
51#define INIT_RESOURCE_LENGTH(i) i->aml_offset 50#define INIT_RESOURCE_LENGTH(i) i->aml_offset
52#define INIT_TABLE_LENGTH(i) i->value 51#define INIT_TABLE_LENGTH(i) i->value
@@ -429,8 +428,7 @@ acpi_rs_convert_resource_to_aml(struct acpi_resource *resource,
429 * Optional resource_source (Index and String) 428 * Optional resource_source (Index and String)
430 */ 429 */
431 aml_length = 430 aml_length =
432 acpi_rs_set_resource_source(aml, 431 acpi_rs_set_resource_source(aml, (acpi_rs_length)
433 (acpi_rs_length)
434 aml_length, source); 432 aml_length, source);
435 acpi_rs_set_resource_length(aml_length, aml); 433 acpi_rs_set_resource_length(aml_length, aml);
436 break; 434 break;
diff --git a/drivers/acpi/resources/rsutils.c b/drivers/acpi/resources/rsutils.c
index 2442a8f8df57..11c0bd7b9cfd 100644
--- a/drivers/acpi/resources/rsutils.c
+++ b/drivers/acpi/resources/rsutils.c
@@ -353,10 +353,8 @@ acpi_rs_get_resource_source(acpi_rs_length resource_length,
353 * 353 *
354 * Zero the entire area of the buffer. 354 * Zero the entire area of the buffer.
355 */ 355 */
356 total_length = 356 total_length = (u32)
357 (u32) 357 ACPI_STRLEN(ACPI_CAST_PTR(char, &aml_resource_source[1])) + 1;
358 ACPI_STRLEN(ACPI_CAST_PTR(char, &aml_resource_source[1])) +
359 1;
360 total_length = (u32) ACPI_ROUND_UP_TO_NATIVE_WORD(total_length); 358 total_length = (u32) ACPI_ROUND_UP_TO_NATIVE_WORD(total_length);
361 359
362 ACPI_MEMSET(resource_source->string_ptr, 0, total_length); 360 ACPI_MEMSET(resource_source->string_ptr, 0, total_length);
diff --git a/drivers/acpi/resources/rsxface.c b/drivers/acpi/resources/rsxface.c
index 991f8901498c..f63813a358c5 100644
--- a/drivers/acpi/resources/rsxface.c
+++ b/drivers/acpi/resources/rsxface.c
@@ -217,7 +217,6 @@ acpi_get_current_resources(acpi_handle device_handle,
217} 217}
218 218
219ACPI_EXPORT_SYMBOL(acpi_get_current_resources) 219ACPI_EXPORT_SYMBOL(acpi_get_current_resources)
220
221#ifdef ACPI_FUTURE_USAGE 220#ifdef ACPI_FUTURE_USAGE
222/******************************************************************************* 221/*******************************************************************************
223 * 222 *
@@ -261,7 +260,6 @@ acpi_get_possible_resources(acpi_handle device_handle,
261 260
262ACPI_EXPORT_SYMBOL(acpi_get_possible_resources) 261ACPI_EXPORT_SYMBOL(acpi_get_possible_resources)
263#endif /* ACPI_FUTURE_USAGE */ 262#endif /* ACPI_FUTURE_USAGE */
264
265/******************************************************************************* 263/*******************************************************************************
266 * 264 *
267 * FUNCTION: acpi_set_current_resources 265 * FUNCTION: acpi_set_current_resources
@@ -496,7 +494,6 @@ ACPI_EXPORT_SYMBOL(acpi_rs_match_vendor_resource)
496 * each resource in the list. 494 * each resource in the list.
497 * 495 *
498 ******************************************************************************/ 496 ******************************************************************************/
499
500acpi_status 497acpi_status
501acpi_walk_resources(acpi_handle device_handle, 498acpi_walk_resources(acpi_handle device_handle,
502 char *name, 499 char *name,
diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
index d80dd84e5bfd..6b3b8a522476 100644
--- a/drivers/acpi/scan.c
+++ b/drivers/acpi/scan.c
@@ -302,7 +302,7 @@ static void acpi_device_shutdown(struct device *dev)
302 return ; 302 return ;
303} 303}
304 304
305static struct bus_type acpi_bus_type = { 305struct bus_type acpi_bus_type = {
306 .name = "acpi", 306 .name = "acpi",
307 .suspend = acpi_device_suspend, 307 .suspend = acpi_device_suspend,
308 .resume = acpi_device_resume, 308 .resume = acpi_device_resume,
diff --git a/drivers/acpi/sleep/main.c b/drivers/acpi/sleep/main.c
index f8c63410bcbf..bc7e16ec8393 100644
--- a/drivers/acpi/sleep/main.c
+++ b/drivers/acpi/sleep/main.c
@@ -29,7 +29,6 @@ static u32 acpi_suspend_states[] = {
29 [PM_SUSPEND_ON] = ACPI_STATE_S0, 29 [PM_SUSPEND_ON] = ACPI_STATE_S0,
30 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1, 30 [PM_SUSPEND_STANDBY] = ACPI_STATE_S1,
31 [PM_SUSPEND_MEM] = ACPI_STATE_S3, 31 [PM_SUSPEND_MEM] = ACPI_STATE_S3,
32 [PM_SUSPEND_DISK] = ACPI_STATE_S4,
33 [PM_SUSPEND_MAX] = ACPI_STATE_S5 32 [PM_SUSPEND_MAX] = ACPI_STATE_S5
34}; 33};
35 34
@@ -94,14 +93,6 @@ static int acpi_pm_enter(suspend_state_t pm_state)
94 do_suspend_lowlevel(); 93 do_suspend_lowlevel();
95 break; 94 break;
96 95
97 case PM_SUSPEND_DISK:
98 if (acpi_pm_ops.pm_disk_mode == PM_DISK_PLATFORM)
99 status = acpi_enter_sleep_state(acpi_state);
100 break;
101 case PM_SUSPEND_MAX:
102 acpi_power_off();
103 break;
104
105 default: 96 default:
106 return -EINVAL; 97 return -EINVAL;
107 } 98 }
@@ -157,12 +148,13 @@ int acpi_suspend(u32 acpi_state)
157 suspend_state_t states[] = { 148 suspend_state_t states[] = {
158 [1] = PM_SUSPEND_STANDBY, 149 [1] = PM_SUSPEND_STANDBY,
159 [3] = PM_SUSPEND_MEM, 150 [3] = PM_SUSPEND_MEM,
160 [4] = PM_SUSPEND_DISK,
161 [5] = PM_SUSPEND_MAX 151 [5] = PM_SUSPEND_MAX
162 }; 152 };
163 153
164 if (acpi_state < 6 && states[acpi_state]) 154 if (acpi_state < 6 && states[acpi_state])
165 return pm_suspend(states[acpi_state]); 155 return pm_suspend(states[acpi_state]);
156 if (acpi_state == 4)
157 return hibernate();
166 return -EINVAL; 158 return -EINVAL;
167} 159}
168 160
@@ -189,6 +181,49 @@ static struct pm_ops acpi_pm_ops = {
189 .finish = acpi_pm_finish, 181 .finish = acpi_pm_finish,
190}; 182};
191 183
184#ifdef CONFIG_SOFTWARE_SUSPEND
185static int acpi_hibernation_prepare(void)
186{
187 return acpi_sleep_prepare(ACPI_STATE_S4);
188}
189
190static int acpi_hibernation_enter(void)
191{
192 acpi_status status = AE_OK;
193 unsigned long flags = 0;
194
195 ACPI_FLUSH_CPU_CACHE();
196
197 local_irq_save(flags);
198 acpi_enable_wakeup_device(ACPI_STATE_S4);
199 /* This shouldn't return. If it returns, we have a problem */
200 status = acpi_enter_sleep_state(ACPI_STATE_S4);
201 local_irq_restore(flags);
202
203 return ACPI_SUCCESS(status) ? 0 : -EFAULT;
204}
205
206static void acpi_hibernation_finish(void)
207{
208 acpi_leave_sleep_state(ACPI_STATE_S4);
209 acpi_disable_wakeup_device(ACPI_STATE_S4);
210
211 /* reset firmware waking vector */
212 acpi_set_firmware_waking_vector((acpi_physical_address) 0);
213
214 if (init_8259A_after_S1) {
215 printk("Broken toshiba laptop -> kicking interrupts\n");
216 init_8259A(0);
217 }
218}
219
220static struct hibernation_ops acpi_hibernation_ops = {
221 .prepare = acpi_hibernation_prepare,
222 .enter = acpi_hibernation_enter,
223 .finish = acpi_hibernation_finish,
224};
225#endif /* CONFIG_SOFTWARE_SUSPEND */
226
192/* 227/*
193 * Toshiba fails to preserve interrupts over S1, reinitialization 228 * Toshiba fails to preserve interrupts over S1, reinitialization
194 * of 8259 is needed after S1 resume. 229 * of 8259 is needed after S1 resume.
@@ -227,14 +262,17 @@ int __init acpi_sleep_init(void)
227 sleep_states[i] = 1; 262 sleep_states[i] = 1;
228 printk(" S%d", i); 263 printk(" S%d", i);
229 } 264 }
230 if (i == ACPI_STATE_S4) {
231 if (sleep_states[i])
232 acpi_pm_ops.pm_disk_mode = PM_DISK_PLATFORM;
233 }
234 } 265 }
235 printk(")\n"); 266 printk(")\n");
236 267
237 pm_set_ops(&acpi_pm_ops); 268 pm_set_ops(&acpi_pm_ops);
269
270#ifdef CONFIG_SOFTWARE_SUSPEND
271 if (sleep_states[ACPI_STATE_S4])
272 hibernation_set_ops(&acpi_hibernation_ops);
273#else
274 sleep_states[ACPI_STATE_S4] = 0;
275#endif
276
238 return 0; 277 return 0;
239} 278}
240
diff --git a/drivers/acpi/sleep/proc.c b/drivers/acpi/sleep/proc.c
index dcde9ddd105a..61f1822cc350 100644
--- a/drivers/acpi/sleep/proc.c
+++ b/drivers/acpi/sleep/proc.c
@@ -60,7 +60,7 @@ acpi_system_write_sleep(struct file *file,
60 state = simple_strtoul(str, NULL, 0); 60 state = simple_strtoul(str, NULL, 0);
61#ifdef CONFIG_SOFTWARE_SUSPEND 61#ifdef CONFIG_SOFTWARE_SUSPEND
62 if (state == 4) { 62 if (state == 4) {
63 error = pm_suspend(PM_SUSPEND_DISK); 63 error = hibernate();
64 goto Done; 64 goto Done;
65 } 65 }
66#endif 66#endif
@@ -70,6 +70,14 @@ acpi_system_write_sleep(struct file *file,
70} 70}
71#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */ 71#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
72 72
73#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
74/* use /sys/class/rtc/rtcX/wakealarm instead; it's not ACPI-specific */
75#else
76#define HAVE_ACPI_LEGACY_ALARM
77#endif
78
79#ifdef HAVE_ACPI_LEGACY_ALARM
80
73static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset) 81static int acpi_system_alarm_seq_show(struct seq_file *seq, void *offset)
74{ 82{
75 u32 sec, min, hr; 83 u32 sec, min, hr;
@@ -341,6 +349,7 @@ acpi_system_write_alarm(struct file *file,
341 end: 349 end:
342 return_VALUE(result ? result : count); 350 return_VALUE(result ? result : count);
343} 351}
352#endif /* HAVE_ACPI_LEGACY_ALARM */
344 353
345extern struct list_head acpi_wakeup_device_list; 354extern struct list_head acpi_wakeup_device_list;
346extern spinlock_t acpi_device_lock; 355extern spinlock_t acpi_device_lock;
@@ -370,8 +379,8 @@ acpi_system_wakeup_device_seq_show(struct seq_file *seq, void *offset)
370 dev->wakeup.state.enabled ? "enabled" : "disabled"); 379 dev->wakeup.state.enabled ? "enabled" : "disabled");
371 if (ldev) 380 if (ldev)
372 seq_printf(seq, "%s:%s", 381 seq_printf(seq, "%s:%s",
373 ldev->bus ? ldev->bus->name : "no-bus", 382 ldev->bus ? ldev->bus->name : "no-bus",
374 ldev->bus_id); 383 ldev->bus_id);
375 seq_printf(seq, "\n"); 384 seq_printf(seq, "\n");
376 put_device(ldev); 385 put_device(ldev);
377 386
@@ -464,6 +473,7 @@ static const struct file_operations acpi_system_sleep_fops = {
464}; 473};
465#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */ 474#endif /* CONFIG_ACPI_SLEEP_PROC_SLEEP */
466 475
476#ifdef HAVE_ACPI_LEGACY_ALARM
467static const struct file_operations acpi_system_alarm_fops = { 477static const struct file_operations acpi_system_alarm_fops = {
468 .open = acpi_system_alarm_open_fs, 478 .open = acpi_system_alarm_open_fs,
469 .read = seq_read, 479 .read = seq_read,
@@ -479,8 +489,9 @@ static u32 rtc_handler(void *context)
479 489
480 return ACPI_INTERRUPT_HANDLED; 490 return ACPI_INTERRUPT_HANDLED;
481} 491}
492#endif /* HAVE_ACPI_LEGACY_ALARM */
482 493
483static int acpi_sleep_proc_init(void) 494static int __init acpi_sleep_proc_init(void)
484{ 495{
485 struct proc_dir_entry *entry = NULL; 496 struct proc_dir_entry *entry = NULL;
486 497
@@ -496,6 +507,7 @@ static int acpi_sleep_proc_init(void)
496 entry->proc_fops = &acpi_system_sleep_fops; 507 entry->proc_fops = &acpi_system_sleep_fops;
497#endif 508#endif
498 509
510#ifdef HAVE_ACPI_LEGACY_ALARM
499 /* 'alarm' [R/W] */ 511 /* 'alarm' [R/W] */
500 entry = 512 entry =
501 create_proc_entry("alarm", S_IFREG | S_IRUGO | S_IWUSR, 513 create_proc_entry("alarm", S_IFREG | S_IRUGO | S_IWUSR,
@@ -503,6 +515,9 @@ static int acpi_sleep_proc_init(void)
503 if (entry) 515 if (entry)
504 entry->proc_fops = &acpi_system_alarm_fops; 516 entry->proc_fops = &acpi_system_alarm_fops;
505 517
518 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
519#endif /* HAVE_ACPI_LEGACY_ALARM */
520
506 /* 'wakeup device' [R/W] */ 521 /* 'wakeup device' [R/W] */
507 entry = 522 entry =
508 create_proc_entry("wakeup", S_IFREG | S_IRUGO | S_IWUSR, 523 create_proc_entry("wakeup", S_IFREG | S_IRUGO | S_IWUSR,
@@ -510,7 +525,6 @@ static int acpi_sleep_proc_init(void)
510 if (entry) 525 if (entry)
511 entry->proc_fops = &acpi_system_wakeup_device_fops; 526 entry->proc_fops = &acpi_system_wakeup_device_fops;
512 527
513 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
514 return 0; 528 return 0;
515} 529}
516 530
diff --git a/drivers/acpi/tables/tbfadt.c b/drivers/acpi/tables/tbfadt.c
index 1db833eb2417..1285e91474fb 100644
--- a/drivers/acpi/tables/tbfadt.c
+++ b/drivers/acpi/tables/tbfadt.c
@@ -334,7 +334,8 @@ static void acpi_tb_convert_fadt(void)
334 (acpi_gbl_FADT.xpm1a_event_block.address + 334 (acpi_gbl_FADT.xpm1a_event_block.address +
335 pm1_register_length)); 335 pm1_register_length));
336 /* Don't forget to copy space_id of the GAS */ 336 /* Don't forget to copy space_id of the GAS */
337 acpi_gbl_xpm1a_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id; 337 acpi_gbl_xpm1a_enable.space_id =
338 acpi_gbl_FADT.xpm1a_event_block.space_id;
338 339
339 /* The PM1B register block is optional, ignore if not present */ 340 /* The PM1B register block is optional, ignore if not present */
340 341
@@ -344,7 +345,8 @@ static void acpi_tb_convert_fadt(void)
344 (acpi_gbl_FADT.xpm1b_event_block. 345 (acpi_gbl_FADT.xpm1b_event_block.
345 address + pm1_register_length)); 346 address + pm1_register_length));
346 /* Don't forget to copy space_id of the GAS */ 347 /* Don't forget to copy space_id of the GAS */
347 acpi_gbl_xpm1b_enable.space_id = acpi_gbl_FADT.xpm1a_event_block.space_id; 348 acpi_gbl_xpm1b_enable.space_id =
349 acpi_gbl_FADT.xpm1a_event_block.space_id;
348 350
349 } 351 }
350 352
diff --git a/drivers/acpi/tables/tbxface.c b/drivers/acpi/tables/tbxface.c
index 417ef5fa7666..5b302c4e293f 100644
--- a/drivers/acpi/tables/tbxface.c
+++ b/drivers/acpi/tables/tbxface.c
@@ -201,6 +201,7 @@ acpi_status acpi_reallocate_root_table(void)
201 201
202 return_ACPI_STATUS(AE_OK); 202 return_ACPI_STATUS(AE_OK);
203} 203}
204
204/******************************************************************************* 205/*******************************************************************************
205 * 206 *
206 * FUNCTION: acpi_load_table 207 * FUNCTION: acpi_load_table
@@ -262,7 +263,7 @@ ACPI_EXPORT_SYMBOL(acpi_load_table)
262acpi_status 263acpi_status
263acpi_get_table_header(char *signature, 264acpi_get_table_header(char *signature,
264 acpi_native_uint instance, 265 acpi_native_uint instance,
265 struct acpi_table_header *out_table_header) 266 struct acpi_table_header * out_table_header)
266{ 267{
267 acpi_native_uint i; 268 acpi_native_uint i;
268 acpi_native_uint j; 269 acpi_native_uint j;
@@ -321,7 +322,6 @@ acpi_get_table_header(char *signature,
321 322
322ACPI_EXPORT_SYMBOL(acpi_get_table_header) 323ACPI_EXPORT_SYMBOL(acpi_get_table_header)
323 324
324
325/****************************************************************************** 325/******************************************************************************
326 * 326 *
327 * FUNCTION: acpi_unload_table_id 327 * FUNCTION: acpi_unload_table_id
@@ -346,11 +346,11 @@ acpi_status acpi_unload_table_id(acpi_owner_id id)
346 continue; 346 continue;
347 } 347 }
348 /* 348 /*
349 * Delete all namespace objects owned by this table. Note that these 349 * Delete all namespace objects owned by this table. Note that these
350 * objects can appear anywhere in the namespace by virtue of the AML 350 * objects can appear anywhere in the namespace by virtue of the AML
351 * "Scope" operator. Thus, we need to track ownership by an ID, not 351 * "Scope" operator. Thus, we need to track ownership by an ID, not
352 * simply a position within the hierarchy 352 * simply a position within the hierarchy
353 */ 353 */
354 acpi_tb_delete_namespace_by_owner(i); 354 acpi_tb_delete_namespace_by_owner(i);
355 status = acpi_tb_release_owner_id(i); 355 status = acpi_tb_release_owner_id(i);
356 acpi_tb_set_table_loaded_flag(i, FALSE); 356 acpi_tb_set_table_loaded_flag(i, FALSE);
@@ -376,7 +376,7 @@ ACPI_EXPORT_SYMBOL(acpi_unload_table_id)
376 *****************************************************************************/ 376 *****************************************************************************/
377acpi_status 377acpi_status
378acpi_get_table(char *signature, 378acpi_get_table(char *signature,
379 acpi_native_uint instance, struct acpi_table_header ** out_table) 379 acpi_native_uint instance, struct acpi_table_header **out_table)
380{ 380{
381 acpi_native_uint i; 381 acpi_native_uint i;
382 acpi_native_uint j; 382 acpi_native_uint j;
diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c
index 589b98b7b216..1ada017d01ef 100644
--- a/drivers/acpi/thermal.c
+++ b/drivers/acpi/thermal.c
@@ -59,8 +59,6 @@
59#define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0 59#define ACPI_THERMAL_NOTIFY_CRITICAL 0xF0
60#define ACPI_THERMAL_NOTIFY_HOT 0xF1 60#define ACPI_THERMAL_NOTIFY_HOT 0xF1
61#define ACPI_THERMAL_MODE_ACTIVE 0x00 61#define ACPI_THERMAL_MODE_ACTIVE 0x00
62#define ACPI_THERMAL_MODE_PASSIVE 0x01
63#define ACPI_THERMAL_MODE_CRITICAL 0xff
64#define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff" 62#define ACPI_THERMAL_PATH_POWEROFF "/sbin/poweroff"
65 63
66#define ACPI_THERMAL_MAX_ACTIVE 10 64#define ACPI_THERMAL_MAX_ACTIVE 10
@@ -86,9 +84,6 @@ static int acpi_thermal_resume(struct acpi_device *device);
86static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file); 84static int acpi_thermal_state_open_fs(struct inode *inode, struct file *file);
87static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file); 85static int acpi_thermal_temp_open_fs(struct inode *inode, struct file *file);
88static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file); 86static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file);
89static ssize_t acpi_thermal_write_trip_points(struct file *,
90 const char __user *, size_t,
91 loff_t *);
92static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file); 87static int acpi_thermal_cooling_open_fs(struct inode *inode, struct file *file);
93static ssize_t acpi_thermal_write_cooling_mode(struct file *, 88static ssize_t acpi_thermal_write_cooling_mode(struct file *,
94 const char __user *, size_t, 89 const char __user *, size_t,
@@ -167,7 +162,6 @@ struct acpi_thermal {
167 unsigned long temperature; 162 unsigned long temperature;
168 unsigned long last_temperature; 163 unsigned long last_temperature;
169 unsigned long polling_frequency; 164 unsigned long polling_frequency;
170 u8 cooling_mode;
171 volatile u8 zombie; 165 volatile u8 zombie;
172 struct acpi_thermal_flags flags; 166 struct acpi_thermal_flags flags;
173 struct acpi_thermal_state state; 167 struct acpi_thermal_state state;
@@ -193,7 +187,6 @@ static const struct file_operations acpi_thermal_temp_fops = {
193static const struct file_operations acpi_thermal_trip_fops = { 187static const struct file_operations acpi_thermal_trip_fops = {
194 .open = acpi_thermal_trip_open_fs, 188 .open = acpi_thermal_trip_open_fs,
195 .read = seq_read, 189 .read = seq_read,
196 .write = acpi_thermal_write_trip_points,
197 .llseek = seq_lseek, 190 .llseek = seq_lseek,
198 .release = single_release, 191 .release = single_release,
199}; 192};
@@ -297,11 +290,6 @@ static int acpi_thermal_set_cooling_mode(struct acpi_thermal *tz, int mode)
297 if (ACPI_FAILURE(status)) 290 if (ACPI_FAILURE(status))
298 return -ENODEV; 291 return -ENODEV;
299 292
300 tz->cooling_mode = mode;
301
302 ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Cooling mode [%s]\n",
303 mode ? "passive" : "active"));
304
305 return 0; 293 return 0;
306} 294}
307 295
@@ -889,67 +877,6 @@ static int acpi_thermal_trip_open_fs(struct inode *inode, struct file *file)
889 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data); 877 return single_open(file, acpi_thermal_trip_seq_show, PDE(inode)->data);
890} 878}
891 879
892static ssize_t
893acpi_thermal_write_trip_points(struct file *file,
894 const char __user * buffer,
895 size_t count, loff_t * ppos)
896{
897 struct seq_file *m = file->private_data;
898 struct acpi_thermal *tz = m->private;
899
900 char *limit_string;
901 int num, critical, hot, passive;
902 int *active;
903 int i = 0;
904
905
906 limit_string = kzalloc(ACPI_THERMAL_MAX_LIMIT_STR_LEN, GFP_KERNEL);
907 if (!limit_string)
908 return -ENOMEM;
909
910 active = kmalloc(ACPI_THERMAL_MAX_ACTIVE * sizeof(int), GFP_KERNEL);
911 if (!active) {
912 kfree(limit_string);
913 return -ENOMEM;
914 }
915
916 if (!tz || (count > ACPI_THERMAL_MAX_LIMIT_STR_LEN - 1)) {
917 count = -EINVAL;
918 goto end;
919 }
920
921 if (copy_from_user(limit_string, buffer, count)) {
922 count = -EFAULT;
923 goto end;
924 }
925
926 limit_string[count] = '\0';
927
928 num = sscanf(limit_string, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d",
929 &critical, &hot, &passive,
930 &active[0], &active[1], &active[2], &active[3], &active[4],
931 &active[5], &active[6], &active[7], &active[8],
932 &active[9]);
933 if (!(num >= 5 && num < (ACPI_THERMAL_MAX_ACTIVE + 3))) {
934 count = -EINVAL;
935 goto end;
936 }
937
938 tz->trips.critical.temperature = CELSIUS_TO_KELVIN(critical);
939 tz->trips.hot.temperature = CELSIUS_TO_KELVIN(hot);
940 tz->trips.passive.temperature = CELSIUS_TO_KELVIN(passive);
941 for (i = 0; i < num - 3; i++) {
942 if (!(tz->trips.active[i].flags.valid))
943 break;
944 tz->trips.active[i].temperature = CELSIUS_TO_KELVIN(active[i]);
945 }
946
947 end:
948 kfree(active);
949 kfree(limit_string);
950 return count;
951}
952
953static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset) 880static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
954{ 881{
955 struct acpi_thermal *tz = seq->private; 882 struct acpi_thermal *tz = seq->private;
@@ -958,15 +885,10 @@ static int acpi_thermal_cooling_seq_show(struct seq_file *seq, void *offset)
958 if (!tz) 885 if (!tz)
959 goto end; 886 goto end;
960 887
961 if (!tz->flags.cooling_mode) { 888 if (!tz->flags.cooling_mode)
962 seq_puts(seq, "<setting not supported>\n"); 889 seq_puts(seq, "<setting not supported>\n");
963 }
964
965 if (tz->cooling_mode == ACPI_THERMAL_MODE_CRITICAL)
966 seq_printf(seq, "cooling mode: critical\n");
967 else 890 else
968 seq_printf(seq, "cooling mode: %s\n", 891 seq_puts(seq, "0 - Active; 1 - Passive\n");
969 tz->cooling_mode ? "passive" : "active");
970 892
971 end: 893 end:
972 return 0; 894 return 0;
@@ -1223,28 +1145,6 @@ static int acpi_thermal_get_info(struct acpi_thermal *tz)
1223 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE); 1145 result = acpi_thermal_set_cooling_mode(tz, ACPI_THERMAL_MODE_ACTIVE);
1224 if (!result) 1146 if (!result)
1225 tz->flags.cooling_mode = 1; 1147 tz->flags.cooling_mode = 1;
1226 else {
1227 /* Oh,we have not _SCP method.
1228 Generally show cooling_mode by _ACx, _PSV,spec 12.2 */
1229 tz->flags.cooling_mode = 0;
1230 if (tz->trips.active[0].flags.valid
1231 && tz->trips.passive.flags.valid) {
1232 if (tz->trips.passive.temperature >
1233 tz->trips.active[0].temperature)
1234 tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE;
1235 else
1236 tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE;
1237 } else if (!tz->trips.active[0].flags.valid
1238 && tz->trips.passive.flags.valid) {
1239 tz->cooling_mode = ACPI_THERMAL_MODE_PASSIVE;
1240 } else if (tz->trips.active[0].flags.valid
1241 && !tz->trips.passive.flags.valid) {
1242 tz->cooling_mode = ACPI_THERMAL_MODE_ACTIVE;
1243 } else {
1244 /* _ACx and _PSV are optional, but _CRT is required */
1245 tz->cooling_mode = ACPI_THERMAL_MODE_CRITICAL;
1246 }
1247 }
1248 1148
1249 /* Get default polling frequency [_TZP] (optional) */ 1149 /* Get default polling frequency [_TZP] (optional) */
1250 if (tzp) 1150 if (tzp)
diff --git a/drivers/acpi/utilities/utalloc.c b/drivers/acpi/utilities/utalloc.c
index 55a764807499..6e56d5f7c43a 100644
--- a/drivers/acpi/utilities/utalloc.c
+++ b/drivers/acpi/utilities/utalloc.c
@@ -107,7 +107,6 @@ acpi_status acpi_ut_create_caches(void)
107 if (ACPI_FAILURE(status)) { 107 if (ACPI_FAILURE(status)) {
108 return (status); 108 return (status);
109 } 109 }
110
111#ifdef ACPI_DBG_TRACK_ALLOCATIONS 110#ifdef ACPI_DBG_TRACK_ALLOCATIONS
112 111
113 /* Memory allocation lists */ 112 /* Memory allocation lists */
diff --git a/drivers/acpi/utilities/utcache.c b/drivers/acpi/utilities/utcache.c
index 870f6edeb5f2..285a0f531760 100644
--- a/drivers/acpi/utilities/utcache.c
+++ b/drivers/acpi/utilities/utcache.c
@@ -45,7 +45,6 @@
45 45
46#define _COMPONENT ACPI_UTILITIES 46#define _COMPONENT ACPI_UTILITIES
47ACPI_MODULE_NAME("utcache") 47ACPI_MODULE_NAME("utcache")
48
49#ifdef ACPI_USE_LOCAL_CACHE 48#ifdef ACPI_USE_LOCAL_CACHE
50/******************************************************************************* 49/*******************************************************************************
51 * 50 *
@@ -64,7 +63,7 @@ ACPI_MODULE_NAME("utcache")
64acpi_status 63acpi_status
65acpi_os_create_cache(char *cache_name, 64acpi_os_create_cache(char *cache_name,
66 u16 object_size, 65 u16 object_size,
67 u16 max_depth, struct acpi_memory_list **return_cache) 66 u16 max_depth, struct acpi_memory_list ** return_cache)
68{ 67{
69 struct acpi_memory_list *cache; 68 struct acpi_memory_list *cache;
70 69
diff --git a/drivers/acpi/utilities/utcopy.c b/drivers/acpi/utilities/utcopy.c
index 84d529db0a66..4c1e00874dff 100644
--- a/drivers/acpi/utilities/utcopy.c
+++ b/drivers/acpi/utilities/utcopy.c
@@ -814,7 +814,9 @@ acpi_ut_copy_ielement_to_ielement(u8 object_type,
814 /* 814 /*
815 * Create the object array 815 * Create the object array
816 */ 816 */
817 target_object->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size) source_object->package.count + 1) * sizeof(void *)); 817 target_object->package.elements =
818 ACPI_ALLOCATE_ZEROED(((acpi_size) source_object->package.
819 count + 1) * sizeof(void *));
818 if (!target_object->package.elements) { 820 if (!target_object->package.elements) {
819 status = AE_NO_MEMORY; 821 status = AE_NO_MEMORY;
820 goto error_exit; 822 goto error_exit;
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
index 61ad4f2daee2..c7e128e5369b 100644
--- a/drivers/acpi/utilities/utdebug.c
+++ b/drivers/acpi/utilities/utdebug.c
@@ -45,7 +45,6 @@
45 45
46#define _COMPONENT ACPI_UTILITIES 46#define _COMPONENT ACPI_UTILITIES
47ACPI_MODULE_NAME("utdebug") 47ACPI_MODULE_NAME("utdebug")
48
49#ifdef ACPI_DEBUG_OUTPUT 48#ifdef ACPI_DEBUG_OUTPUT
50static acpi_thread_id acpi_gbl_prev_thread_id; 49static acpi_thread_id acpi_gbl_prev_thread_id;
51static char *acpi_gbl_fn_entry_str = "----Entry"; 50static char *acpi_gbl_fn_entry_str = "----Entry";
@@ -181,7 +180,8 @@ acpi_ut_debug_print(u32 requested_debug_level,
181 if (ACPI_LV_THREADS & acpi_dbg_level) { 180 if (ACPI_LV_THREADS & acpi_dbg_level) {
182 acpi_os_printf 181 acpi_os_printf
183 ("\n**** Context Switch from TID %lX to TID %lX ****\n\n", 182 ("\n**** Context Switch from TID %lX to TID %lX ****\n\n",
184 (unsigned long)acpi_gbl_prev_thread_id, (unsigned long)thread_id); 183 (unsigned long)acpi_gbl_prev_thread_id,
184 (unsigned long)thread_id);
185 } 185 }
186 186
187 acpi_gbl_prev_thread_id = thread_id; 187 acpi_gbl_prev_thread_id = thread_id;
diff --git a/drivers/acpi/utilities/utdelete.c b/drivers/acpi/utilities/utdelete.c
index 673a0caa4073..f777cebdc46d 100644
--- a/drivers/acpi/utilities/utdelete.c
+++ b/drivers/acpi/utilities/utdelete.c
@@ -170,6 +170,7 @@ static void acpi_ut_delete_internal_obj(union acpi_operand_object *object)
170 acpi_os_delete_mutex(object->mutex.os_mutex); 170 acpi_os_delete_mutex(object->mutex.os_mutex);
171 acpi_gbl_global_lock_mutex = NULL; 171 acpi_gbl_global_lock_mutex = NULL;
172 } else { 172 } else {
173 acpi_ex_unlink_mutex(object);
173 acpi_os_delete_mutex(object->mutex.os_mutex); 174 acpi_os_delete_mutex(object->mutex.os_mutex);
174 } 175 }
175 break; 176 break;
diff --git a/drivers/acpi/utilities/utglobal.c b/drivers/acpi/utilities/utglobal.c
index af33358a964b..1621655d6e2b 100644
--- a/drivers/acpi/utilities/utglobal.c
+++ b/drivers/acpi/utilities/utglobal.c
@@ -55,12 +55,10 @@ ACPI_EXPORT_SYMBOL(acpi_gbl_FADT)
55 * Static global variable initialization. 55 * Static global variable initialization.
56 * 56 *
57 ******************************************************************************/ 57 ******************************************************************************/
58
59/* 58/*
60 * We want the debug switches statically initialized so they 59 * We want the debug switches statically initialized so they
61 * are already set when the debugger is entered. 60 * are already set when the debugger is entered.
62 */ 61 */
63
64/* Debug switch - level and trace mask */ 62/* Debug switch - level and trace mask */
65u32 acpi_dbg_level = ACPI_DEBUG_DEFAULT; 63u32 acpi_dbg_level = ACPI_DEBUG_DEFAULT;
66 64
@@ -735,5 +733,5 @@ void acpi_ut_init_globals(void)
735} 733}
736 734
737ACPI_EXPORT_SYMBOL(acpi_dbg_level) 735ACPI_EXPORT_SYMBOL(acpi_dbg_level)
738ACPI_EXPORT_SYMBOL(acpi_dbg_layer) 736 ACPI_EXPORT_SYMBOL(acpi_dbg_layer)
739ACPI_EXPORT_SYMBOL(acpi_gpe_count) 737 ACPI_EXPORT_SYMBOL(acpi_gpe_count)
diff --git a/drivers/acpi/utilities/utmisc.c b/drivers/acpi/utilities/utmisc.c
index 50133fffe420..2d19f71e9cfa 100644
--- a/drivers/acpi/utilities/utmisc.c
+++ b/drivers/acpi/utilities/utmisc.c
@@ -802,9 +802,8 @@ acpi_ut_strtoul64(char *string, u32 base, acpi_integer * ret_integer)
802 802
803 valid_digits++; 803 valid_digits++;
804 804
805 if (sign_of0x 805 if (sign_of0x && ((valid_digits > 16)
806 && ((valid_digits > 16) 806 || ((valid_digits > 8) && mode32))) {
807 || ((valid_digits > 8) && mode32))) {
808 /* 807 /*
809 * This is to_integer operation case. 808 * This is to_integer operation case.
810 * No any restrictions for string-to-integer conversion, 809 * No any restrictions for string-to-integer conversion,
@@ -1049,6 +1048,7 @@ acpi_ut_exception(char *module_name,
1049 acpi_os_vprintf(format, args); 1048 acpi_os_vprintf(format, args);
1050 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION); 1049 acpi_os_printf(" [%X]\n", ACPI_CA_VERSION);
1051} 1050}
1051
1052EXPORT_SYMBOL(acpi_ut_exception); 1052EXPORT_SYMBOL(acpi_ut_exception);
1053 1053
1054void ACPI_INTERNAL_VAR_XFACE 1054void ACPI_INTERNAL_VAR_XFACE
diff --git a/drivers/acpi/utilities/utmutex.c b/drivers/acpi/utilities/utmutex.c
index cbad2ef5987d..4820bc86d1f5 100644
--- a/drivers/acpi/utilities/utmutex.c
+++ b/drivers/acpi/utilities/utmutex.c
@@ -244,7 +244,7 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
244 244
245 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 245 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
246 "Thread %lX attempting to acquire Mutex [%s]\n", 246 "Thread %lX attempting to acquire Mutex [%s]\n",
247 (unsigned long) this_thread_id, 247 (unsigned long)this_thread_id,
248 acpi_ut_get_mutex_name(mutex_id))); 248 acpi_ut_get_mutex_name(mutex_id)));
249 249
250 status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex, 250 status = acpi_os_acquire_mutex(acpi_gbl_mutex_info[mutex_id].mutex,
@@ -252,7 +252,7 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
252 if (ACPI_SUCCESS(status)) { 252 if (ACPI_SUCCESS(status)) {
253 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 253 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
254 "Thread %lX acquired Mutex [%s]\n", 254 "Thread %lX acquired Mutex [%s]\n",
255 (unsigned long) this_thread_id, 255 (unsigned long)this_thread_id,
256 acpi_ut_get_mutex_name(mutex_id))); 256 acpi_ut_get_mutex_name(mutex_id)));
257 257
258 acpi_gbl_mutex_info[mutex_id].use_count++; 258 acpi_gbl_mutex_info[mutex_id].use_count++;
@@ -260,7 +260,7 @@ acpi_status acpi_ut_acquire_mutex(acpi_mutex_handle mutex_id)
260 } else { 260 } else {
261 ACPI_EXCEPTION((AE_INFO, status, 261 ACPI_EXCEPTION((AE_INFO, status,
262 "Thread %lX could not acquire Mutex [%X]", 262 "Thread %lX could not acquire Mutex [%X]",
263 (unsigned long) this_thread_id, mutex_id)); 263 (unsigned long)this_thread_id, mutex_id));
264 } 264 }
265 265
266 return (status); 266 return (status);
@@ -287,7 +287,7 @@ acpi_status acpi_ut_release_mutex(acpi_mutex_handle mutex_id)
287 this_thread_id = acpi_os_get_thread_id(); 287 this_thread_id = acpi_os_get_thread_id();
288 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX, 288 ACPI_DEBUG_PRINT((ACPI_DB_MUTEX,
289 "Thread %lX releasing Mutex [%s]\n", 289 "Thread %lX releasing Mutex [%s]\n",
290 (unsigned long) this_thread_id, 290 (unsigned long)this_thread_id,
291 acpi_ut_get_mutex_name(mutex_id))); 291 acpi_ut_get_mutex_name(mutex_id)));
292 292
293 if (mutex_id > ACPI_MAX_MUTEX) { 293 if (mutex_id > ACPI_MAX_MUTEX) {
diff --git a/drivers/acpi/utilities/utresrc.c b/drivers/acpi/utilities/utresrc.c
index e8fe1ba6cc24..cbbd3315a1e2 100644
--- a/drivers/acpi/utilities/utresrc.c
+++ b/drivers/acpi/utilities/utresrc.c
@@ -46,7 +46,6 @@
46 46
47#define _COMPONENT ACPI_UTILITIES 47#define _COMPONENT ACPI_UTILITIES
48ACPI_MODULE_NAME("utresrc") 48ACPI_MODULE_NAME("utresrc")
49
50#if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER) 49#if defined(ACPI_DISASSEMBLER) || defined (ACPI_DEBUGGER)
51/* 50/*
52 * Strings used to decode resource descriptors. 51 * Strings used to decode resource descriptors.
diff --git a/drivers/acpi/utilities/utxface.c b/drivers/acpi/utilities/utxface.c
index de3276f4f468..e9a57806cd34 100644
--- a/drivers/acpi/utilities/utxface.c
+++ b/drivers/acpi/utilities/utxface.c
@@ -337,7 +337,6 @@ acpi_status acpi_terminate(void)
337} 337}
338 338
339ACPI_EXPORT_SYMBOL(acpi_terminate) 339ACPI_EXPORT_SYMBOL(acpi_terminate)
340
341#ifdef ACPI_FUTURE_USAGE 340#ifdef ACPI_FUTURE_USAGE
342/******************************************************************************* 341/*******************************************************************************
343 * 342 *
@@ -470,7 +469,6 @@ acpi_install_initialization_handler(acpi_init_handler handler, u32 function)
470 469
471ACPI_EXPORT_SYMBOL(acpi_install_initialization_handler) 470ACPI_EXPORT_SYMBOL(acpi_install_initialization_handler)
472#endif /* ACPI_FUTURE_USAGE */ 471#endif /* ACPI_FUTURE_USAGE */
473
474/***************************************************************************** 472/*****************************************************************************
475 * 473 *
476 * FUNCTION: acpi_purge_cached_objects 474 * FUNCTION: acpi_purge_cached_objects
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 45dbdc14915f..b4a8d6030e48 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -2,10 +2,9 @@
2# SATA/PATA driver configuration 2# SATA/PATA driver configuration
3# 3#
4 4
5menu "Serial ATA (prod) and Parallel ATA (experimental) drivers" 5menuconfig ATA
6 6 tristate "Serial ATA (prod) and Parallel ATA (experimental) drivers"
7config ATA 7 depends on HAS_IOMEM
8 tristate "ATA device support"
9 depends on BLOCK 8 depends on BLOCK
10 depends on !(M32R || M68K) || BROKEN 9 depends on !(M32R || M68K) || BROKEN
11 depends on !SUN4 || BROKEN 10 depends on !SUN4 || BROKEN
@@ -23,6 +22,19 @@ config ATA_NONSTANDARD
23 bool 22 bool
24 default n 23 default n
25 24
25config ATA_ACPI
26 bool
27 depends on ACPI && PCI
28 default y
29 help
30 This option adds support for ATA-related ACPI objects.
31 These ACPI objects add the ability to retrieve taskfiles
32 from the ACPI BIOS and write them to the disk controller.
33 These objects may be related to performance, security,
34 power management, or other areas.
35 You can disable this at kernel boot time by using the
36 option libata.noacpi=1
37
26config SATA_AHCI 38config SATA_AHCI
27 tristate "AHCI SATA support" 39 tristate "AHCI SATA support"
28 depends on PCI 40 depends on PCI
@@ -120,7 +132,7 @@ config SATA_SIS
120 depends on PCI 132 depends on PCI
121 select PATA_SIS 133 select PATA_SIS
122 help 134 help
123 This option enables support for SiS Serial ATA on 135 This option enables support for SiS Serial ATA on
124 SiS 964/965/966/180 and Parallel ATA on SiS 180. 136 SiS 964/965/966/180 and Parallel ATA on SiS 180.
125 The PATA support for SiS 180 requires additionally to 137 The PATA support for SiS 180 requires additionally to
126 enable the PATA_SIS driver in the config. 138 enable the PATA_SIS driver in the config.
@@ -156,19 +168,6 @@ config SATA_INIC162X
156 help 168 help
157 This option enables support for Initio 162x Serial ATA. 169 This option enables support for Initio 162x Serial ATA.
158 170
159config SATA_ACPI
160 bool
161 depends on ACPI && PCI
162 default y
163 help
164 This option adds support for SATA-related ACPI objects.
165 These ACPI objects add the ability to retrieve taskfiles
166 from the ACPI BIOS and write them to the disk controller.
167 These objects may be related to performance, security,
168 power management, or other areas.
169 You can disable this at kernel boot time by using the
170 option libata.noacpi=1
171
172config PATA_ALI 171config PATA_ALI
173 tristate "ALi PATA support (Experimental)" 172 tristate "ALi PATA support (Experimental)"
174 depends on PCI && EXPERIMENTAL 173 depends on PCI && EXPERIMENTAL
@@ -435,7 +434,7 @@ config PATA_OPTIDMA
435 help 434 help
436 This option enables DMA/PIO support for the later OPTi 435 This option enables DMA/PIO support for the later OPTi
437 controllers found on some old motherboards and in some 436 controllers found on some old motherboards and in some
438 latops 437 laptops.
439 438
440 If unsure, say N. 439 If unsure, say N.
441 440
@@ -584,6 +583,4 @@ config PATA_SCC
584 583
585 If unsure, say N. 584 If unsure, say N.
586 585
587endif 586endif # ATA
588endmenu
589
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index 6f42a0e2812d..8149c68ac2c7 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -69,4 +69,4 @@ obj-$(CONFIG_ATA_GENERIC) += ata_generic.o
69obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o 69obj-$(CONFIG_PATA_LEGACY) += pata_legacy.o
70 70
71libata-objs := libata-core.o libata-scsi.o libata-sff.o libata-eh.o 71libata-objs := libata-core.o libata-scsi.o libata-sff.o libata-eh.o
72libata-$(CONFIG_SATA_ACPI) += libata-acpi.o 72libata-$(CONFIG_ATA_ACPI) += libata-acpi.o
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 34c5534ed64c..7baeaffefe7a 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "ahci" 48#define DRV_NAME "ahci"
49#define DRV_VERSION "2.1" 49#define DRV_VERSION "2.2"
50 50
51 51
52enum { 52enum {
@@ -170,10 +170,12 @@ enum {
170 AHCI_FLAG_IGN_IRQ_IF_ERR = (1 << 25), /* ignore IRQ_IF_ERR */ 170 AHCI_FLAG_IGN_IRQ_IF_ERR = (1 << 25), /* ignore IRQ_IF_ERR */
171 AHCI_FLAG_HONOR_PI = (1 << 26), /* honor PORTS_IMPL */ 171 AHCI_FLAG_HONOR_PI = (1 << 26), /* honor PORTS_IMPL */
172 AHCI_FLAG_IGN_SERR_INTERNAL = (1 << 27), /* ignore SERR_INTERNAL */ 172 AHCI_FLAG_IGN_SERR_INTERNAL = (1 << 27), /* ignore SERR_INTERNAL */
173 AHCI_FLAG_32BIT_ONLY = (1 << 28), /* force 32bit */
173 174
174 AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 175 AHCI_FLAG_COMMON = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
175 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | 176 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
176 ATA_FLAG_SKIP_D2H_BSY, 177 ATA_FLAG_SKIP_D2H_BSY |
178 ATA_FLAG_ACPI_SATA,
177}; 179};
178 180
179struct ahci_cmd_hdr { 181struct ahci_cmd_hdr {
@@ -250,10 +252,6 @@ static struct scsi_host_template ahci_sht = {
250 .slave_configure = ata_scsi_slave_config, 252 .slave_configure = ata_scsi_slave_config,
251 .slave_destroy = ata_scsi_slave_destroy, 253 .slave_destroy = ata_scsi_slave_destroy,
252 .bios_param = ata_std_bios_param, 254 .bios_param = ata_std_bios_param,
253#ifdef CONFIG_PM
254 .suspend = ata_scsi_device_suspend,
255 .resume = ata_scsi_device_resume,
256#endif
257}; 255};
258 256
259static const struct ata_port_operations ahci_ops = { 257static const struct ata_port_operations ahci_ops = {
@@ -357,7 +355,8 @@ static const struct ata_port_info ahci_port_info[] = {
357 /* board_ahci_sb600 */ 355 /* board_ahci_sb600 */
358 { 356 {
359 .flags = AHCI_FLAG_COMMON | 357 .flags = AHCI_FLAG_COMMON |
360 AHCI_FLAG_IGN_SERR_INTERNAL, 358 AHCI_FLAG_IGN_SERR_INTERNAL |
359 AHCI_FLAG_32BIT_ONLY,
361 .pio_mask = 0x1f, /* pio0-4 */ 360 .pio_mask = 0x1f, /* pio0-4 */
362 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 361 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
363 .port_ops = &ahci_ops, 362 .port_ops = &ahci_ops,
@@ -400,6 +399,7 @@ static const struct pci_device_id ahci_pci_tbl[] = {
400 399
401 /* ATI */ 400 /* ATI */
402 { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */ 401 { PCI_VDEVICE(ATI, 0x4380), board_ahci_sb600 }, /* ATI SB600 */
402 { PCI_VDEVICE(ATI, 0x4390), board_ahci_sb600 }, /* ATI SB700 */
403 403
404 /* VIA */ 404 /* VIA */
405 { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */ 405 { PCI_VDEVICE(VIA, 0x3349), board_ahci_vt8251 }, /* VIA VT8251 */
@@ -494,6 +494,13 @@ static void ahci_save_initial_config(struct pci_dev *pdev,
494 hpriv->saved_cap = cap = readl(mmio + HOST_CAP); 494 hpriv->saved_cap = cap = readl(mmio + HOST_CAP);
495 hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL); 495 hpriv->saved_port_map = port_map = readl(mmio + HOST_PORTS_IMPL);
496 496
497 /* some chips lie about 64bit support */
498 if ((cap & HOST_CAP_64) && (pi->flags & AHCI_FLAG_32BIT_ONLY)) {
499 dev_printk(KERN_INFO, &pdev->dev,
500 "controller can't do 64bit DMA, forcing 32bit\n");
501 cap &= ~HOST_CAP_64;
502 }
503
497 /* fixup zero port_map */ 504 /* fixup zero port_map */
498 if (!port_map) { 505 if (!port_map) {
499 port_map = (1 << ahci_nr_ports(hpriv->cap)) - 1; 506 port_map = (1 << ahci_nr_ports(hpriv->cap)) - 1;
@@ -874,7 +881,8 @@ static int ahci_clo(struct ata_port *ap)
874 return 0; 881 return 0;
875} 882}
876 883
877static int ahci_softreset(struct ata_port *ap, unsigned int *class) 884static int ahci_softreset(struct ata_port *ap, unsigned int *class,
885 unsigned long deadline)
878{ 886{
879 struct ahci_port_priv *pp = ap->private_data; 887 struct ahci_port_priv *pp = ap->private_data;
880 void __iomem *port_mmio = ahci_port_base(ap); 888 void __iomem *port_mmio = ahci_port_base(ap);
@@ -959,15 +967,13 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
959 */ 967 */
960 msleep(150); 968 msleep(150);
961 969
962 *class = ATA_DEV_NONE; 970 rc = ata_wait_ready(ap, deadline);
963 if (ata_port_online(ap)) { 971 /* link occupied, -ENODEV too is an error */
964 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 972 if (rc) {
965 rc = -EIO; 973 reason = "device not ready";
966 reason = "device not ready"; 974 goto fail;
967 goto fail;
968 }
969 *class = ahci_dev_classify(ap);
970 } 975 }
976 *class = ahci_dev_classify(ap);
971 977
972 DPRINTK("EXIT, class=%u\n", *class); 978 DPRINTK("EXIT, class=%u\n", *class);
973 return 0; 979 return 0;
@@ -979,7 +985,8 @@ static int ahci_softreset(struct ata_port *ap, unsigned int *class)
979 return rc; 985 return rc;
980} 986}
981 987
982static int ahci_hardreset(struct ata_port *ap, unsigned int *class) 988static int ahci_hardreset(struct ata_port *ap, unsigned int *class,
989 unsigned long deadline)
983{ 990{
984 struct ahci_port_priv *pp = ap->private_data; 991 struct ahci_port_priv *pp = ap->private_data;
985 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; 992 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
@@ -995,7 +1002,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
995 tf.command = 0x80; 1002 tf.command = 0x80;
996 ata_tf_to_fis(&tf, d2h_fis, 0); 1003 ata_tf_to_fis(&tf, d2h_fis, 0);
997 1004
998 rc = sata_std_hardreset(ap, class); 1005 rc = sata_std_hardreset(ap, class, deadline);
999 1006
1000 ahci_start_engine(ap); 1007 ahci_start_engine(ap);
1001 1008
@@ -1008,7 +1015,8 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
1008 return rc; 1015 return rc;
1009} 1016}
1010 1017
1011static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class) 1018static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class,
1019 unsigned long deadline)
1012{ 1020{
1013 int rc; 1021 int rc;
1014 1022
@@ -1016,7 +1024,8 @@ static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class)
1016 1024
1017 ahci_stop_engine(ap); 1025 ahci_stop_engine(ap);
1018 1026
1019 rc = sata_port_hardreset(ap, sata_ehc_deb_timing(&ap->eh_context)); 1027 rc = sata_port_hardreset(ap, sata_ehc_deb_timing(&ap->eh_context),
1028 deadline);
1020 1029
1021 /* vt8251 needs SError cleared for the port to operate */ 1030 /* vt8251 needs SError cleared for the port to operate */
1022 ahci_scr_write(ap, SCR_ERROR, ahci_scr_read(ap, SCR_ERROR)); 1031 ahci_scr_write(ap, SCR_ERROR, ahci_scr_read(ap, SCR_ERROR));
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index 92a491ddd030..7565f022bd69 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -26,7 +26,7 @@
26#include <linux/libata.h> 26#include <linux/libata.h>
27 27
28#define DRV_NAME "ata_generic" 28#define DRV_NAME "ata_generic"
29#define DRV_VERSION "0.2.11" 29#define DRV_VERSION "0.2.12"
30 30
31/* 31/*
32 * A generic parallel ATA driver using libata 32 * A generic parallel ATA driver using libata
@@ -54,7 +54,7 @@ static int generic_set_mode(struct ata_port *ap, struct ata_device **unused)
54 54
55 for (i = 0; i < ATA_MAX_DEVICES; i++) { 55 for (i = 0; i < ATA_MAX_DEVICES; i++) {
56 struct ata_device *dev = &ap->device[i]; 56 struct ata_device *dev = &ap->device[i];
57 if (ata_dev_ready(dev)) { 57 if (ata_dev_enabled(dev)) {
58 /* We don't really care */ 58 /* We don't really care */
59 dev->pio_mode = XFER_PIO_0; 59 dev->pio_mode = XFER_PIO_0;
60 dev->dma_mode = XFER_MW_DMA_0; 60 dev->dma_mode = XFER_MW_DMA_0;
@@ -90,10 +90,6 @@ static struct scsi_host_template generic_sht = {
90 .slave_configure = ata_scsi_slave_config, 90 .slave_configure = ata_scsi_slave_config,
91 .slave_destroy = ata_scsi_slave_destroy, 91 .slave_destroy = ata_scsi_slave_destroy,
92 .bios_param = ata_std_bios_param, 92 .bios_param = ata_std_bios_param,
93#ifdef CONFIG_PM
94 .resume = ata_scsi_device_resume,
95 .suspend = ata_scsi_device_suspend,
96#endif
97}; 93};
98 94
99static struct ata_port_operations generic_port_ops = { 95static struct ata_port_operations generic_port_ops = {
@@ -145,7 +141,7 @@ static int all_generic_ide; /* Set to claim all devices */
145static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id) 141static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id *id)
146{ 142{
147 u16 command; 143 u16 command;
148 static struct ata_port_info info = { 144 static const struct ata_port_info info = {
149 .sht = &generic_sht, 145 .sht = &generic_sht,
150 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 146 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
151 .pio_mask = 0x1f, 147 .pio_mask = 0x1f,
@@ -153,7 +149,7 @@ static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id
153 .udma_mask = 0x3f, 149 .udma_mask = 0x3f,
154 .port_ops = &generic_port_ops 150 .port_ops = &generic_port_ops
155 }; 151 };
156 static struct ata_port_info *port_info[2] = { &info, &info }; 152 const struct ata_port_info *ppi[] = { &info, NULL };
157 153
158 /* Don't use the generic entry unless instructed to do so */ 154 /* Don't use the generic entry unless instructed to do so */
159 if (id->driver_data == 1 && all_generic_ide == 0) 155 if (id->driver_data == 1 && all_generic_ide == 0)
@@ -179,7 +175,7 @@ static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id
179 if (dev->vendor == PCI_VENDOR_ID_AL) 175 if (dev->vendor == PCI_VENDOR_ID_AL)
180 ata_pci_clear_simplex(dev); 176 ata_pci_clear_simplex(dev);
181 177
182 return ata_pci_init_one(dev, port_info, 2); 178 return ata_pci_init_one(dev, ppi);
183} 179}
184 180
185static struct pci_device_id ata_generic[] = { 181static struct pci_device_id ata_generic[] = {
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 55d306a3e538..0458811010fd 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -155,7 +155,6 @@ struct piix_host_priv {
155static int piix_init_one (struct pci_dev *pdev, 155static int piix_init_one (struct pci_dev *pdev,
156 const struct pci_device_id *ent); 156 const struct pci_device_id *ent);
157static void piix_pata_error_handler(struct ata_port *ap); 157static void piix_pata_error_handler(struct ata_port *ap);
158static void piix_sata_error_handler(struct ata_port *ap);
159static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev); 158static void piix_set_piomode (struct ata_port *ap, struct ata_device *adev);
160static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev); 159static void piix_set_dmamode (struct ata_port *ap, struct ata_device *adev);
161static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev); 160static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev);
@@ -275,10 +274,6 @@ static struct scsi_host_template piix_sht = {
275 .slave_configure = ata_scsi_slave_config, 274 .slave_configure = ata_scsi_slave_config,
276 .slave_destroy = ata_scsi_slave_destroy, 275 .slave_destroy = ata_scsi_slave_destroy,
277 .bios_param = ata_std_bios_param, 276 .bios_param = ata_std_bios_param,
278#ifdef CONFIG_PM
279 .resume = ata_scsi_device_resume,
280 .suspend = ata_scsi_device_suspend,
281#endif
282}; 277};
283 278
284static const struct ata_port_operations piix_pata_ops = { 279static const struct ata_port_operations piix_pata_ops = {
@@ -368,7 +363,7 @@ static const struct ata_port_operations piix_sata_ops = {
368 363
369 .freeze = ata_bmdma_freeze, 364 .freeze = ata_bmdma_freeze,
370 .thaw = ata_bmdma_thaw, 365 .thaw = ata_bmdma_thaw,
371 .error_handler = piix_sata_error_handler, 366 .error_handler = ata_bmdma_error_handler,
372 .post_internal_cmd = ata_bmdma_post_internal_cmd, 367 .post_internal_cmd = ata_bmdma_post_internal_cmd,
373 368
374 .irq_handler = ata_interrupt, 369 .irq_handler = ata_interrupt,
@@ -625,17 +620,18 @@ static int ich_pata_cable_detect(struct ata_port *ap)
625/** 620/**
626 * piix_pata_prereset - prereset for PATA host controller 621 * piix_pata_prereset - prereset for PATA host controller
627 * @ap: Target port 622 * @ap: Target port
623 * @deadline: deadline jiffies for the operation
628 * 624 *
629 * LOCKING: 625 * LOCKING:
630 * None (inherited from caller). 626 * None (inherited from caller).
631 */ 627 */
632static int piix_pata_prereset(struct ata_port *ap) 628static int piix_pata_prereset(struct ata_port *ap, unsigned long deadline)
633{ 629{
634 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 630 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
635 631
636 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no])) 632 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
637 return -ENOENT; 633 return -ENOENT;
638 return ata_std_prereset(ap); 634 return ata_std_prereset(ap, deadline);
639} 635}
640 636
641static void piix_pata_error_handler(struct ata_port *ap) 637static void piix_pata_error_handler(struct ata_port *ap)
@@ -644,13 +640,6 @@ static void piix_pata_error_handler(struct ata_port *ap)
644 ata_std_postreset); 640 ata_std_postreset);
645} 641}
646 642
647
648static void piix_sata_error_handler(struct ata_port *ap)
649{
650 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, NULL,
651 ata_std_postreset);
652}
653
654/** 643/**
655 * piix_set_piomode - Initialize host controller PATA PIO timings 644 * piix_set_piomode - Initialize host controller PATA PIO timings
656 * @ap: Port whose timings we are configuring 645 * @ap: Port whose timings we are configuring
@@ -1034,7 +1023,7 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1034 static int printed_version; 1023 static int printed_version;
1035 struct device *dev = &pdev->dev; 1024 struct device *dev = &pdev->dev;
1036 struct ata_port_info port_info[2]; 1025 struct ata_port_info port_info[2];
1037 struct ata_port_info *ppinfo[2] = { &port_info[0], &port_info[1] }; 1026 const struct ata_port_info *ppi[] = { &port_info[0], &port_info[1] };
1038 struct piix_host_priv *hpriv; 1027 struct piix_host_priv *hpriv;
1039 unsigned long port_flags; 1028 unsigned long port_flags;
1040 1029
@@ -1093,7 +1082,7 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1093 port_info[1].mwdma_mask = 0; 1082 port_info[1].mwdma_mask = 0;
1094 port_info[1].udma_mask = 0; 1083 port_info[1].udma_mask = 0;
1095 } 1084 }
1096 return ata_pci_init_one(pdev, ppinfo, 2); 1085 return ata_pci_init_one(pdev, ppi);
1097} 1086}
1098 1087
1099static int __init piix_init(void) 1088static int __init piix_init(void)
diff --git a/drivers/ata/libata-acpi.c b/drivers/ata/libata-acpi.c
index 03a0acff6cfa..02236739b40f 100644
--- a/drivers/ata/libata-acpi.c
+++ b/drivers/ata/libata-acpi.c
@@ -270,8 +270,7 @@ out:
270 270
271/** 271/**
272 * do_drive_get_GTF - get the drive bootup default taskfile settings 272 * do_drive_get_GTF - get the drive bootup default taskfile settings
273 * @ap: the ata_port for the drive 273 * @dev: target ATA device
274 * @ix: target ata_device (drive) index
275 * @gtf_length: number of bytes of _GTF data returned at @gtf_address 274 * @gtf_length: number of bytes of _GTF data returned at @gtf_address
276 * @gtf_address: buffer containing _GTF taskfile arrays 275 * @gtf_address: buffer containing _GTF taskfile arrays
277 * 276 *
@@ -286,20 +285,19 @@ out:
286 * The returned @gtf_length and @gtf_address are only valid if the 285 * The returned @gtf_length and @gtf_address are only valid if the
287 * function return value is 0. 286 * function return value is 0.
288 */ 287 */
289static int do_drive_get_GTF(struct ata_port *ap, int ix, 288static int do_drive_get_GTF(struct ata_device *dev, unsigned int *gtf_length,
290 unsigned int *gtf_length, unsigned long *gtf_address, 289 unsigned long *gtf_address, unsigned long *obj_loc)
291 unsigned long *obj_loc)
292{ 290{
293 acpi_status status; 291 struct ata_port *ap = dev->ap;
294 acpi_handle dev_handle = NULL; 292 acpi_status status;
295 acpi_handle chan_handle, drive_handle; 293 acpi_handle dev_handle = NULL;
296 acpi_integer pcidevfn = 0; 294 acpi_handle chan_handle, drive_handle;
297 u32 dev_adr; 295 acpi_integer pcidevfn = 0;
298 struct acpi_buffer output; 296 u32 dev_adr;
299 union acpi_object *out_obj; 297 struct acpi_buffer output;
300 struct device *dev = ap->host->dev; 298 union acpi_object *out_obj;
301 struct ata_device *atadev = &ap->device[ix]; 299 struct device *gdev = ap->host->dev;
302 int err = -ENODEV; 300 int err = -ENODEV;
303 301
304 *gtf_length = 0; 302 *gtf_length = 0;
305 *gtf_address = 0UL; 303 *gtf_address = 0UL;
@@ -309,34 +307,34 @@ static int do_drive_get_GTF(struct ata_port *ap, int ix,
309 return 0; 307 return 0;
310 308
311 if (ata_msg_probe(ap)) 309 if (ata_msg_probe(ap))
312 ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n", 310 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
313 __FUNCTION__, ap->port_no); 311 __FUNCTION__, ap->port_no);
314 312
315 if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED)) { 313 if (!ata_dev_enabled(dev) || (ap->flags & ATA_FLAG_DISABLED)) {
316 if (ata_msg_probe(ap)) 314 if (ata_msg_probe(ap))
317 ata_dev_printk(atadev, KERN_DEBUG, "%s: ERR: " 315 ata_dev_printk(dev, KERN_DEBUG, "%s: ERR: "
318 "ata_dev_present: %d, PORT_DISABLED: %lu\n", 316 "ata_dev_present: %d, PORT_DISABLED: %lu\n",
319 __FUNCTION__, ata_dev_enabled(atadev), 317 __FUNCTION__, ata_dev_enabled(dev),
320 ap->flags & ATA_FLAG_DISABLED); 318 ap->flags & ATA_FLAG_DISABLED);
321 goto out; 319 goto out;
322 } 320 }
323 321
324 /* Don't continue if device has no _ADR method. 322 /* Don't continue if device has no _ADR method.
325 * _GTF is intended for known motherboard devices. */ 323 * _GTF is intended for known motherboard devices. */
326 if (!(ap->cbl == ATA_CBL_SATA)) { 324 if (!(ap->flags & ATA_FLAG_ACPI_SATA)) {
327 err = pata_get_dev_handle(dev, &dev_handle, &pcidevfn); 325 err = pata_get_dev_handle(gdev, &dev_handle, &pcidevfn);
328 if (err < 0) { 326 if (err < 0) {
329 if (ata_msg_probe(ap)) 327 if (ata_msg_probe(ap))
330 ata_dev_printk(atadev, KERN_DEBUG, 328 ata_dev_printk(dev, KERN_DEBUG,
331 "%s: pata_get_dev_handle failed (%d)\n", 329 "%s: pata_get_dev_handle failed (%d)\n",
332 __FUNCTION__, err); 330 __FUNCTION__, err);
333 goto out; 331 goto out;
334 } 332 }
335 } else { 333 } else {
336 err = sata_get_dev_handle(dev, &dev_handle, &pcidevfn); 334 err = sata_get_dev_handle(gdev, &dev_handle, &pcidevfn);
337 if (err < 0) { 335 if (err < 0) {
338 if (ata_msg_probe(ap)) 336 if (ata_msg_probe(ap))
339 ata_dev_printk(atadev, KERN_DEBUG, 337 ata_dev_printk(dev, KERN_DEBUG,
340 "%s: sata_get_dev_handle failed (%d\n", 338 "%s: sata_get_dev_handle failed (%d\n",
341 __FUNCTION__, err); 339 __FUNCTION__, err);
342 goto out; 340 goto out;
@@ -344,15 +342,15 @@ static int do_drive_get_GTF(struct ata_port *ap, int ix,
344 } 342 }
345 343
346 /* Get this drive's _ADR info. if not already known. */ 344 /* Get this drive's _ADR info. if not already known. */
347 if (!atadev->obj_handle) { 345 if (!dev->obj_handle) {
348 if (!(ap->cbl == ATA_CBL_SATA)) { 346 if (!(ap->flags & ATA_FLAG_ACPI_SATA)) {
349 /* get child objects of dev_handle == channel objects, 347 /* get child objects of dev_handle == channel objects,
350 * + _their_ children == drive objects */ 348 * + _their_ children == drive objects */
351 /* channel is ap->port_no */ 349 /* channel is ap->port_no */
352 chan_handle = acpi_get_child(dev_handle, 350 chan_handle = acpi_get_child(dev_handle,
353 ap->port_no); 351 ap->port_no);
354 if (ata_msg_probe(ap)) 352 if (ata_msg_probe(ap))
355 ata_dev_printk(atadev, KERN_DEBUG, 353 ata_dev_printk(dev, KERN_DEBUG,
356 "%s: chan adr=%d: chan_handle=0x%p\n", 354 "%s: chan adr=%d: chan_handle=0x%p\n",
357 __FUNCTION__, ap->port_no, 355 __FUNCTION__, ap->port_no,
358 chan_handle); 356 chan_handle);
@@ -361,26 +359,26 @@ static int do_drive_get_GTF(struct ata_port *ap, int ix,
361 goto out; 359 goto out;
362 } 360 }
363 /* TBD: could also check ACPI object VALID bits */ 361 /* TBD: could also check ACPI object VALID bits */
364 drive_handle = acpi_get_child(chan_handle, ix); 362 drive_handle = acpi_get_child(chan_handle, dev->devno);
365 if (!drive_handle) { 363 if (!drive_handle) {
366 err = -ENODEV; 364 err = -ENODEV;
367 goto out; 365 goto out;
368 } 366 }
369 dev_adr = ix; 367 dev_adr = dev->devno;
370 atadev->obj_handle = drive_handle; 368 dev->obj_handle = drive_handle;
371 } else { /* for SATA mode */ 369 } else { /* for SATA mode */
372 dev_adr = SATA_ADR_RSVD; 370 dev_adr = SATA_ADR_RSVD;
373 err = get_sata_adr(dev, dev_handle, pcidevfn, 0, 371 err = get_sata_adr(gdev, dev_handle, pcidevfn, 0,
374 ap, atadev, &dev_adr); 372 ap, dev, &dev_adr);
375 } 373 }
376 if (err < 0 || dev_adr == SATA_ADR_RSVD || 374 if (err < 0 || dev_adr == SATA_ADR_RSVD ||
377 !atadev->obj_handle) { 375 !dev->obj_handle) {
378 if (ata_msg_probe(ap)) 376 if (ata_msg_probe(ap))
379 ata_dev_printk(atadev, KERN_DEBUG, 377 ata_dev_printk(dev, KERN_DEBUG,
380 "%s: get_sata/pata_adr failed: " 378 "%s: get_sata/pata_adr failed: "
381 "err=%d, dev_adr=%u, obj_handle=0x%p\n", 379 "err=%d, dev_adr=%u, obj_handle=0x%p\n",
382 __FUNCTION__, err, dev_adr, 380 __FUNCTION__, err, dev_adr,
383 atadev->obj_handle); 381 dev->obj_handle);
384 goto out; 382 goto out;
385 } 383 }
386 } 384 }
@@ -391,11 +389,11 @@ static int do_drive_get_GTF(struct ata_port *ap, int ix,
391 389
392 /* _GTF has no input parameters */ 390 /* _GTF has no input parameters */
393 err = -EIO; 391 err = -EIO;
394 status = acpi_evaluate_object(atadev->obj_handle, "_GTF", 392 status = acpi_evaluate_object(dev->obj_handle, "_GTF",
395 NULL, &output); 393 NULL, &output);
396 if (ACPI_FAILURE(status)) { 394 if (ACPI_FAILURE(status)) {
397 if (ata_msg_probe(ap)) 395 if (ata_msg_probe(ap))
398 ata_dev_printk(atadev, KERN_DEBUG, 396 ata_dev_printk(dev, KERN_DEBUG,
399 "%s: Run _GTF error: status = 0x%x\n", 397 "%s: Run _GTF error: status = 0x%x\n",
400 __FUNCTION__, status); 398 __FUNCTION__, status);
401 goto out; 399 goto out;
@@ -403,7 +401,7 @@ static int do_drive_get_GTF(struct ata_port *ap, int ix,
403 401
404 if (!output.length || !output.pointer) { 402 if (!output.length || !output.pointer) {
405 if (ata_msg_probe(ap)) 403 if (ata_msg_probe(ap))
406 ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: " 404 ata_dev_printk(dev, KERN_DEBUG, "%s: Run _GTF: "
407 "length or ptr is NULL (0x%llx, 0x%p)\n", 405 "length or ptr is NULL (0x%llx, 0x%p)\n",
408 __FUNCTION__, 406 __FUNCTION__,
409 (unsigned long long)output.length, 407 (unsigned long long)output.length,
@@ -416,7 +414,7 @@ static int do_drive_get_GTF(struct ata_port *ap, int ix,
416 if (out_obj->type != ACPI_TYPE_BUFFER) { 414 if (out_obj->type != ACPI_TYPE_BUFFER) {
417 kfree(output.pointer); 415 kfree(output.pointer);
418 if (ata_msg_probe(ap)) 416 if (ata_msg_probe(ap))
419 ata_dev_printk(atadev, KERN_DEBUG, "%s: Run _GTF: " 417 ata_dev_printk(dev, KERN_DEBUG, "%s: Run _GTF: "
420 "error: expected object type of " 418 "error: expected object type of "
421 " ACPI_TYPE_BUFFER, got 0x%x\n", 419 " ACPI_TYPE_BUFFER, got 0x%x\n",
422 __FUNCTION__, out_obj->type); 420 __FUNCTION__, out_obj->type);
@@ -427,7 +425,7 @@ static int do_drive_get_GTF(struct ata_port *ap, int ix,
427 if (!out_obj->buffer.length || !out_obj->buffer.pointer || 425 if (!out_obj->buffer.length || !out_obj->buffer.pointer ||
428 out_obj->buffer.length % REGS_PER_GTF) { 426 out_obj->buffer.length % REGS_PER_GTF) {
429 if (ata_msg_drv(ap)) 427 if (ata_msg_drv(ap))
430 ata_dev_printk(atadev, KERN_ERR, 428 ata_dev_printk(dev, KERN_ERR,
431 "%s: unexpected GTF length (%d) or addr (0x%p)\n", 429 "%s: unexpected GTF length (%d) or addr (0x%p)\n",
432 __FUNCTION__, out_obj->buffer.length, 430 __FUNCTION__, out_obj->buffer.length,
433 out_obj->buffer.pointer); 431 out_obj->buffer.pointer);
@@ -439,7 +437,7 @@ static int do_drive_get_GTF(struct ata_port *ap, int ix,
439 *gtf_address = (unsigned long)out_obj->buffer.pointer; 437 *gtf_address = (unsigned long)out_obj->buffer.pointer;
440 *obj_loc = (unsigned long)out_obj; 438 *obj_loc = (unsigned long)out_obj;
441 if (ata_msg_probe(ap)) 439 if (ata_msg_probe(ap))
442 ata_dev_printk(atadev, KERN_DEBUG, "%s: returning " 440 ata_dev_printk(dev, KERN_DEBUG, "%s: returning "
443 "gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n", 441 "gtf_length=%d, gtf_address=0x%lx, obj_loc=0x%lx\n",
444 __FUNCTION__, *gtf_length, *gtf_address, *obj_loc); 442 __FUNCTION__, *gtf_length, *gtf_address, *obj_loc);
445 err = 0; 443 err = 0;
@@ -449,7 +447,7 @@ out:
449 447
450/** 448/**
451 * taskfile_load_raw - send taskfile registers to host controller 449 * taskfile_load_raw - send taskfile registers to host controller
452 * @ap: Port to which output is sent 450 * @dev: target ATA device
453 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7) 451 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
454 * 452 *
455 * Outputs ATA taskfile to standard ATA host controller using MMIO 453 * Outputs ATA taskfile to standard ATA host controller using MMIO
@@ -466,15 +464,15 @@ out:
466 * LOCKING: TBD: 464 * LOCKING: TBD:
467 * Inherited from caller. 465 * Inherited from caller.
468 */ 466 */
469static void taskfile_load_raw(struct ata_port *ap, 467static void taskfile_load_raw(struct ata_device *dev,
470 struct ata_device *atadev, 468 const struct taskfile_array *gtf)
471 const struct taskfile_array *gtf)
472{ 469{
470 struct ata_port *ap = dev->ap;
473 struct ata_taskfile tf; 471 struct ata_taskfile tf;
474 unsigned int err; 472 unsigned int err;
475 473
476 if (ata_msg_probe(ap)) 474 if (ata_msg_probe(ap))
477 ata_dev_printk(atadev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: " 475 ata_dev_printk(dev, KERN_DEBUG, "%s: (0x1f1-1f7): hex: "
478 "%02x %02x %02x %02x %02x %02x %02x\n", 476 "%02x %02x %02x %02x %02x %02x %02x\n",
479 __FUNCTION__, 477 __FUNCTION__,
480 gtf->tfa[0], gtf->tfa[1], gtf->tfa[2], 478 gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
@@ -485,12 +483,11 @@ static void taskfile_load_raw(struct ata_port *ap,
485 && (gtf->tfa[6] == 0)) 483 && (gtf->tfa[6] == 0))
486 return; 484 return;
487 485
488 ata_tf_init(atadev, &tf); 486 ata_tf_init(dev, &tf);
489 487
490 /* convert gtf to tf */ 488 /* convert gtf to tf */
491 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */ 489 tf.flags |= ATA_TFLAG_ISADDR | ATA_TFLAG_DEVICE; /* TBD */
492 tf.protocol = atadev->class == ATA_DEV_ATAPI ? 490 tf.protocol = ATA_PROT_NODATA;
493 ATA_PROT_ATAPI_NODATA : ATA_PROT_NODATA;
494 tf.feature = gtf->tfa[0]; /* 0x1f1 */ 491 tf.feature = gtf->tfa[0]; /* 0x1f1 */
495 tf.nsect = gtf->tfa[1]; /* 0x1f2 */ 492 tf.nsect = gtf->tfa[1]; /* 0x1f2 */
496 tf.lbal = gtf->tfa[2]; /* 0x1f3 */ 493 tf.lbal = gtf->tfa[2]; /* 0x1f3 */
@@ -499,17 +496,16 @@ static void taskfile_load_raw(struct ata_port *ap,
499 tf.device = gtf->tfa[5]; /* 0x1f6 */ 496 tf.device = gtf->tfa[5]; /* 0x1f6 */
500 tf.command = gtf->tfa[6]; /* 0x1f7 */ 497 tf.command = gtf->tfa[6]; /* 0x1f7 */
501 498
502 err = ata_exec_internal(atadev, &tf, NULL, DMA_NONE, NULL, 0); 499 err = ata_exec_internal(dev, &tf, NULL, DMA_NONE, NULL, 0);
503 if (err && ata_msg_probe(ap)) 500 if (err && ata_msg_probe(ap))
504 ata_dev_printk(atadev, KERN_ERR, 501 ata_dev_printk(dev, KERN_ERR,
505 "%s: ata_exec_internal failed: %u\n", 502 "%s: ata_exec_internal failed: %u\n",
506 __FUNCTION__, err); 503 __FUNCTION__, err);
507} 504}
508 505
509/** 506/**
510 * do_drive_set_taskfiles - write the drive taskfile settings from _GTF 507 * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
511 * @ap: the ata_port for the drive 508 * @dev: target ATA device
512 * @atadev: target ata_device
513 * @gtf_length: total number of bytes of _GTF taskfiles 509 * @gtf_length: total number of bytes of _GTF taskfiles
514 * @gtf_address: location of _GTF taskfile arrays 510 * @gtf_address: location of _GTF taskfile arrays
515 * 511 *
@@ -518,30 +514,31 @@ static void taskfile_load_raw(struct ata_port *ap,
518 * Write {gtf_address, length gtf_length} in groups of 514 * Write {gtf_address, length gtf_length} in groups of
519 * REGS_PER_GTF bytes. 515 * REGS_PER_GTF bytes.
520 */ 516 */
521static int do_drive_set_taskfiles(struct ata_port *ap, 517static int do_drive_set_taskfiles(struct ata_device *dev,
522 struct ata_device *atadev, unsigned int gtf_length, 518 unsigned int gtf_length,
523 unsigned long gtf_address) 519 unsigned long gtf_address)
524{ 520{
525 int err = -ENODEV; 521 struct ata_port *ap = dev->ap;
526 int gtf_count = gtf_length / REGS_PER_GTF; 522 int err = -ENODEV;
527 int ix; 523 int gtf_count = gtf_length / REGS_PER_GTF;
524 int ix;
528 struct taskfile_array *gtf; 525 struct taskfile_array *gtf;
529 526
530 if (ata_msg_probe(ap)) 527 if (ata_msg_probe(ap))
531 ata_dev_printk(atadev, KERN_DEBUG, "%s: ENTER: port#: %d\n", 528 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER: port#: %d\n",
532 __FUNCTION__, ap->port_no); 529 __FUNCTION__, ap->port_no);
533 530
534 if (libata_noacpi || !(ap->cbl == ATA_CBL_SATA)) 531 if (libata_noacpi || !(ap->flags & ATA_FLAG_ACPI_SATA))
535 return 0; 532 return 0;
536 533
537 if (!ata_dev_enabled(atadev) || (ap->flags & ATA_FLAG_DISABLED)) 534 if (!ata_dev_enabled(dev) || (ap->flags & ATA_FLAG_DISABLED))
538 goto out; 535 goto out;
539 if (!gtf_count) /* shouldn't be here */ 536 if (!gtf_count) /* shouldn't be here */
540 goto out; 537 goto out;
541 538
542 if (gtf_length % REGS_PER_GTF) { 539 if (gtf_length % REGS_PER_GTF) {
543 if (ata_msg_drv(ap)) 540 if (ata_msg_drv(ap))
544 ata_dev_printk(atadev, KERN_ERR, 541 ata_dev_printk(dev, KERN_ERR,
545 "%s: unexpected GTF length (%d)\n", 542 "%s: unexpected GTF length (%d)\n",
546 __FUNCTION__, gtf_length); 543 __FUNCTION__, gtf_length);
547 goto out; 544 goto out;
@@ -552,7 +549,7 @@ static int do_drive_set_taskfiles(struct ata_port *ap,
552 (gtf_address + ix * REGS_PER_GTF); 549 (gtf_address + ix * REGS_PER_GTF);
553 550
554 /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */ 551 /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */
555 taskfile_load_raw(ap, atadev, gtf); 552 taskfile_load_raw(dev, gtf);
556 } 553 }
557 554
558 err = 0; 555 err = 0;
@@ -568,11 +565,11 @@ out:
568 */ 565 */
569int ata_acpi_exec_tfs(struct ata_port *ap) 566int ata_acpi_exec_tfs(struct ata_port *ap)
570{ 567{
571 int ix; 568 int ix;
572 int ret =0; 569 int ret = 0;
573 unsigned int gtf_length; 570 unsigned int gtf_length;
574 unsigned long gtf_address; 571 unsigned long gtf_address;
575 unsigned long obj_loc; 572 unsigned long obj_loc;
576 573
577 if (libata_noacpi) 574 if (libata_noacpi)
578 return 0; 575 return 0;
@@ -581,15 +578,17 @@ int ata_acpi_exec_tfs(struct ata_port *ap)
581 * we should not run GTF on PATA devices since some 578 * we should not run GTF on PATA devices since some
582 * PATA require execution of GTM/STM before GTF. 579 * PATA require execution of GTM/STM before GTF.
583 */ 580 */
584 if (!(ap->cbl == ATA_CBL_SATA)) 581 if (!(ap->flags & ATA_FLAG_ACPI_SATA))
585 return 0; 582 return 0;
586 583
587 for (ix = 0; ix < ATA_MAX_DEVICES; ix++) { 584 for (ix = 0; ix < ATA_MAX_DEVICES; ix++) {
588 if (!ata_dev_enabled(&ap->device[ix])) 585 struct ata_device *dev = &ap->device[ix];
586
587 if (!ata_dev_enabled(dev))
589 continue; 588 continue;
590 589
591 ret = do_drive_get_GTF(ap, ix, 590 ret = do_drive_get_GTF(dev, &gtf_length, &gtf_address,
592 &gtf_length, &gtf_address, &obj_loc); 591 &obj_loc);
593 if (ret < 0) { 592 if (ret < 0) {
594 if (ata_msg_probe(ap)) 593 if (ata_msg_probe(ap))
595 ata_port_printk(ap, KERN_DEBUG, 594 ata_port_printk(ap, KERN_DEBUG,
@@ -598,8 +597,7 @@ int ata_acpi_exec_tfs(struct ata_port *ap)
598 break; 597 break;
599 } 598 }
600 599
601 ret = do_drive_set_taskfiles(ap, &ap->device[ix], 600 ret = do_drive_set_taskfiles(dev, gtf_length, gtf_address);
602 gtf_length, gtf_address);
603 kfree((void *)obj_loc); 601 kfree((void *)obj_loc);
604 if (ret < 0) { 602 if (ret < 0) {
605 if (ata_msg_probe(ap)) 603 if (ata_msg_probe(ap))
@@ -615,8 +613,7 @@ int ata_acpi_exec_tfs(struct ata_port *ap)
615 613
616/** 614/**
617 * ata_acpi_push_id - send Identify data to drive 615 * ata_acpi_push_id - send Identify data to drive
618 * @ap: the ata_port for the drive 616 * @dev: target ATA device
619 * @ix: drive index
620 * 617 *
621 * _SDD ACPI object: for SATA mode only 618 * _SDD ACPI object: for SATA mode only
622 * Must be after Identify (Packet) Device -- uses its data 619 * Must be after Identify (Packet) Device -- uses its data
@@ -624,57 +621,57 @@ int ata_acpi_exec_tfs(struct ata_port *ap)
624 * method and if it fails for whatever reason, we should still 621 * method and if it fails for whatever reason, we should still
625 * just keep going. 622 * just keep going.
626 */ 623 */
627int ata_acpi_push_id(struct ata_port *ap, unsigned int ix) 624int ata_acpi_push_id(struct ata_device *dev)
628{ 625{
629 acpi_handle handle; 626 struct ata_port *ap = dev->ap;
630 acpi_integer pcidevfn; 627 acpi_handle handle;
631 int err; 628 acpi_integer pcidevfn;
632 struct device *dev = ap->host->dev; 629 int err;
633 struct ata_device *atadev = &ap->device[ix]; 630 struct device *gdev = ap->host->dev;
634 u32 dev_adr; 631 u32 dev_adr;
635 acpi_status status; 632 acpi_status status;
636 struct acpi_object_list input; 633 struct acpi_object_list input;
637 union acpi_object in_params[1]; 634 union acpi_object in_params[1];
638 635
639 if (libata_noacpi) 636 if (libata_noacpi)
640 return 0; 637 return 0;
641 638
642 if (ata_msg_probe(ap)) 639 if (ata_msg_probe(ap))
643 ata_dev_printk(atadev, KERN_DEBUG, "%s: ix = %d, port#: %d\n", 640 ata_dev_printk(dev, KERN_DEBUG, "%s: ix = %d, port#: %d\n",
644 __FUNCTION__, ix, ap->port_no); 641 __FUNCTION__, dev->devno, ap->port_no);
645 642
646 /* Don't continue if not a SATA device. */ 643 /* Don't continue if not a SATA device. */
647 if (!(ap->cbl == ATA_CBL_SATA)) { 644 if (!(ap->flags & ATA_FLAG_ACPI_SATA)) {
648 if (ata_msg_probe(ap)) 645 if (ata_msg_probe(ap))
649 ata_dev_printk(atadev, KERN_DEBUG, 646 ata_dev_printk(dev, KERN_DEBUG,
650 "%s: Not a SATA device\n", __FUNCTION__); 647 "%s: Not a SATA device\n", __FUNCTION__);
651 goto out; 648 goto out;
652 } 649 }
653 650
654 /* Don't continue if device has no _ADR method. 651 /* Don't continue if device has no _ADR method.
655 * _SDD is intended for known motherboard devices. */ 652 * _SDD is intended for known motherboard devices. */
656 err = sata_get_dev_handle(dev, &handle, &pcidevfn); 653 err = sata_get_dev_handle(gdev, &handle, &pcidevfn);
657 if (err < 0) { 654 if (err < 0) {
658 if (ata_msg_probe(ap)) 655 if (ata_msg_probe(ap))
659 ata_dev_printk(atadev, KERN_DEBUG, 656 ata_dev_printk(dev, KERN_DEBUG,
660 "%s: sata_get_dev_handle failed (%d\n", 657 "%s: sata_get_dev_handle failed (%d\n",
661 __FUNCTION__, err); 658 __FUNCTION__, err);
662 goto out; 659 goto out;
663 } 660 }
664 661
665 /* Get this drive's _ADR info, if not already known */ 662 /* Get this drive's _ADR info, if not already known */
666 if (!atadev->obj_handle) { 663 if (!dev->obj_handle) {
667 dev_adr = SATA_ADR_RSVD; 664 dev_adr = SATA_ADR_RSVD;
668 err = get_sata_adr(dev, handle, pcidevfn, ix, ap, atadev, 665 err = get_sata_adr(gdev, handle, pcidevfn, dev->devno, ap, dev,
669 &dev_adr); 666 &dev_adr);
670 if (err < 0 || dev_adr == SATA_ADR_RSVD || 667 if (err < 0 || dev_adr == SATA_ADR_RSVD ||
671 !atadev->obj_handle) { 668 !dev->obj_handle) {
672 if (ata_msg_probe(ap)) 669 if (ata_msg_probe(ap))
673 ata_dev_printk(atadev, KERN_DEBUG, 670 ata_dev_printk(dev, KERN_DEBUG,
674 "%s: get_sata_adr failed: " 671 "%s: get_sata_adr failed: "
675 "err=%d, dev_adr=%u, obj_handle=0x%p\n", 672 "err=%d, dev_adr=%u, obj_handle=0x%p\n",
676 __FUNCTION__, err, dev_adr, 673 __FUNCTION__, err, dev_adr,
677 atadev->obj_handle); 674 dev->obj_handle);
678 goto out; 675 goto out;
679 } 676 }
680 } 677 }
@@ -684,19 +681,19 @@ int ata_acpi_push_id(struct ata_port *ap, unsigned int ix)
684 input.count = 1; 681 input.count = 1;
685 input.pointer = in_params; 682 input.pointer = in_params;
686 in_params[0].type = ACPI_TYPE_BUFFER; 683 in_params[0].type = ACPI_TYPE_BUFFER;
687 in_params[0].buffer.length = sizeof(atadev->id[0]) * ATA_ID_WORDS; 684 in_params[0].buffer.length = sizeof(dev->id[0]) * ATA_ID_WORDS;
688 in_params[0].buffer.pointer = (u8 *)atadev->id; 685 in_params[0].buffer.pointer = (u8 *)dev->id;
689 /* Output buffer: _SDD has no output */ 686 /* Output buffer: _SDD has no output */
690 687
691 /* It's OK for _SDD to be missing too. */ 688 /* It's OK for _SDD to be missing too. */
692 swap_buf_le16(atadev->id, ATA_ID_WORDS); 689 swap_buf_le16(dev->id, ATA_ID_WORDS);
693 status = acpi_evaluate_object(atadev->obj_handle, "_SDD", &input, NULL); 690 status = acpi_evaluate_object(dev->obj_handle, "_SDD", &input, NULL);
694 swap_buf_le16(atadev->id, ATA_ID_WORDS); 691 swap_buf_le16(dev->id, ATA_ID_WORDS);
695 692
696 err = ACPI_FAILURE(status) ? -EIO : 0; 693 err = ACPI_FAILURE(status) ? -EIO : 0;
697 if (err < 0) { 694 if (err < 0) {
698 if (ata_msg_probe(ap)) 695 if (ata_msg_probe(ap))
699 ata_dev_printk(atadev, KERN_DEBUG, 696 ata_dev_printk(dev, KERN_DEBUG,
700 "%s _SDD error: status = 0x%x\n", 697 "%s _SDD error: status = 0x%x\n",
701 __FUNCTION__, status); 698 __FUNCTION__, status);
702 } 699 }
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index ca67484af1eb..a6de57e02047 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -59,7 +59,7 @@
59 59
60#include "libata.h" 60#include "libata.h"
61 61
62#define DRV_VERSION "2.20" /* must be exactly four chars */ 62#define DRV_VERSION "2.21" /* must be exactly four chars */
63 63
64 64
65/* debounce timing parameters in msecs { interval, duration, timeout } */ 65/* debounce timing parameters in msecs { interval, duration, timeout } */
@@ -895,6 +895,7 @@ static u64 ata_read_native_max_address(struct ata_device *dev)
895/** 895/**
896 * ata_set_native_max_address_ext - LBA48 native max set 896 * ata_set_native_max_address_ext - LBA48 native max set
897 * @dev: Device to query 897 * @dev: Device to query
898 * @new_sectors: new max sectors value to set for the device
898 * 899 *
899 * Perform an LBA48 size set max upon the device in question. Return the 900 * Perform an LBA48 size set max upon the device in question. Return the
900 * actual LBA48 size or zero if the command fails. 901 * actual LBA48 size or zero if the command fails.
@@ -932,6 +933,7 @@ static u64 ata_set_native_max_address_ext(struct ata_device *dev, u64 new_sector
932/** 933/**
933 * ata_set_native_max_address - LBA28 native max set 934 * ata_set_native_max_address - LBA28 native max set
934 * @dev: Device to query 935 * @dev: Device to query
936 * @new_sectors: new max sectors value to set for the device
935 * 937 *
936 * Perform an LBA28 size set max upon the device in question. Return the 938 * Perform an LBA28 size set max upon the device in question. Return the
937 * actual LBA28 size or zero if the command fails. 939 * actual LBA28 size or zero if the command fails.
@@ -975,7 +977,7 @@ static u64 ata_hpa_resize(struct ata_device *dev)
975{ 977{
976 u64 sectors = dev->n_sectors; 978 u64 sectors = dev->n_sectors;
977 u64 hpa_sectors; 979 u64 hpa_sectors;
978 980
979 if (ata_id_has_lba48(dev->id)) 981 if (ata_id_has_lba48(dev->id))
980 hpa_sectors = ata_read_native_max_address_ext(dev); 982 hpa_sectors = ata_read_native_max_address_ext(dev);
981 else 983 else
@@ -1316,7 +1318,7 @@ void ata_port_flush_task(struct ata_port *ap)
1316 spin_unlock_irqrestore(ap->lock, flags); 1318 spin_unlock_irqrestore(ap->lock, flags);
1317 1319
1318 DPRINTK("flush #1\n"); 1320 DPRINTK("flush #1\n");
1319 flush_workqueue(ata_wq); 1321 cancel_work_sync(&ap->port_task.work); /* akpm: seems unneeded */
1320 1322
1321 /* 1323 /*
1322 * At this point, if a task is running, it's guaranteed to see 1324 * At this point, if a task is running, it's guaranteed to see
@@ -1327,7 +1329,7 @@ void ata_port_flush_task(struct ata_port *ap)
1327 if (ata_msg_ctl(ap)) 1329 if (ata_msg_ctl(ap))
1328 ata_port_printk(ap, KERN_DEBUG, "%s: flush #2\n", 1330 ata_port_printk(ap, KERN_DEBUG, "%s: flush #2\n",
1329 __FUNCTION__); 1331 __FUNCTION__);
1330 flush_workqueue(ata_wq); 1332 cancel_work_sync(&ap->port_task.work);
1331 } 1333 }
1332 1334
1333 spin_lock_irqsave(ap->lock, flags); 1335 spin_lock_irqsave(ap->lock, flags);
@@ -1586,7 +1588,7 @@ unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd)
1586 * Check if the current speed of the device requires IORDY. Used 1588 * Check if the current speed of the device requires IORDY. Used
1587 * by various controllers for chip configuration. 1589 * by various controllers for chip configuration.
1588 */ 1590 */
1589 1591
1590unsigned int ata_pio_need_iordy(const struct ata_device *adev) 1592unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1591{ 1593{
1592 /* Controller doesn't support IORDY. Probably a pointless check 1594 /* Controller doesn't support IORDY. Probably a pointless check
@@ -1609,7 +1611,7 @@ unsigned int ata_pio_need_iordy(const struct ata_device *adev)
1609 * Compute the highest mode possible if we are not using iordy. Return 1611 * Compute the highest mode possible if we are not using iordy. Return
1610 * -1 if no iordy mode is available. 1612 * -1 if no iordy mode is available.
1611 */ 1613 */
1612 1614
1613static u32 ata_pio_mask_no_iordy(const struct ata_device *adev) 1615static u32 ata_pio_mask_no_iordy(const struct ata_device *adev)
1614{ 1616{
1615 /* If we have no drive specific rule, then PIO 2 is non IORDY */ 1617 /* If we have no drive specific rule, then PIO 2 is non IORDY */
@@ -1652,7 +1654,7 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1652 struct ata_taskfile tf; 1654 struct ata_taskfile tf;
1653 unsigned int err_mask = 0; 1655 unsigned int err_mask = 0;
1654 const char *reason; 1656 const char *reason;
1655 int tried_spinup = 0; 1657 int may_fallback = 1, tried_spinup = 0;
1656 int rc; 1658 int rc;
1657 1659
1658 if (ata_msg_ctl(ap)) 1660 if (ata_msg_ctl(ap))
@@ -1696,11 +1698,31 @@ int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
1696 return -ENOENT; 1698 return -ENOENT;
1697 } 1699 }
1698 1700
1701 /* Device or controller might have reported the wrong
1702 * device class. Give a shot at the other IDENTIFY if
1703 * the current one is aborted by the device.
1704 */
1705 if (may_fallback &&
1706 (err_mask == AC_ERR_DEV) && (tf.feature & ATA_ABORTED)) {
1707 may_fallback = 0;
1708
1709 if (class == ATA_DEV_ATA)
1710 class = ATA_DEV_ATAPI;
1711 else
1712 class = ATA_DEV_ATA;
1713 goto retry;
1714 }
1715
1699 rc = -EIO; 1716 rc = -EIO;
1700 reason = "I/O error"; 1717 reason = "I/O error";
1701 goto err_out; 1718 goto err_out;
1702 } 1719 }
1703 1720
1721 /* Falling back doesn't make sense if ID data was read
1722 * successfully at least once.
1723 */
1724 may_fallback = 0;
1725
1704 swap_buf_le16(id, ATA_ID_WORDS); 1726 swap_buf_le16(id, ATA_ID_WORDS);
1705 1727
1706 /* sanity check */ 1728 /* sanity check */
@@ -1841,7 +1863,7 @@ int ata_dev_configure(struct ata_device *dev)
1841 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__); 1863 ata_dev_printk(dev, KERN_DEBUG, "%s: ENTER\n", __FUNCTION__);
1842 1864
1843 /* set _SDD */ 1865 /* set _SDD */
1844 rc = ata_acpi_push_id(ap, dev->devno); 1866 rc = ata_acpi_push_id(dev);
1845 if (rc) { 1867 if (rc) {
1846 ata_dev_printk(dev, KERN_WARNING, "failed to set _SDD(%d)\n", 1868 ata_dev_printk(dev, KERN_WARNING, "failed to set _SDD(%d)\n",
1847 rc); 1869 rc);
@@ -1891,7 +1913,6 @@ int ata_dev_configure(struct ata_device *dev)
1891 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id)); 1913 snprintf(revbuf, 7, "ATA-%d", ata_id_major_version(id));
1892 1914
1893 dev->n_sectors = ata_id_n_sectors(id); 1915 dev->n_sectors = ata_id_n_sectors(id);
1894 dev->n_sectors_boot = dev->n_sectors;
1895 1916
1896 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */ 1917 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */
1897 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV, 1918 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV,
@@ -2642,7 +2663,7 @@ int ata_timing_compute(struct ata_device *adev, unsigned short speed,
2642 t->active += (t->cycle - (t->active + t->recover)) / 2; 2663 t->active += (t->cycle - (t->active + t->recover)) / 2;
2643 t->recover = t->cycle - t->active; 2664 t->recover = t->cycle - t->active;
2644 } 2665 }
2645 2666
2646 /* In a few cases quantisation may produce enough errors to 2667 /* In a few cases quantisation may produce enough errors to
2647 leave t->cycle too low for the sum of active and recovery 2668 leave t->cycle too low for the sum of active and recovery
2648 if so we must correct this */ 2669 if so we must correct this */
@@ -2858,7 +2879,7 @@ int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2858 dev = &ap->device[i]; 2879 dev = &ap->device[i];
2859 2880
2860 /* don't update suspended devices' xfer mode */ 2881 /* don't update suspended devices' xfer mode */
2861 if (!ata_dev_ready(dev)) 2882 if (!ata_dev_enabled(dev))
2862 continue; 2883 continue;
2863 2884
2864 rc = ata_dev_set_mode(dev); 2885 rc = ata_dev_set_mode(dev);
@@ -2872,9 +2893,6 @@ int ata_do_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2872 if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX)) 2893 if (used_dma && (ap->host->flags & ATA_HOST_SIMPLEX))
2873 ap->host->simplex_claimed = ap; 2894 ap->host->simplex_claimed = ap;
2874 2895
2875 /* step5: chip specific finalisation */
2876 if (ap->ops->post_set_mode)
2877 ap->ops->post_set_mode(ap);
2878 out: 2896 out:
2879 if (rc) 2897 if (rc)
2880 *r_failed_dev = dev; 2898 *r_failed_dev = dev;
@@ -2979,23 +2997,71 @@ int ata_busy_sleep(struct ata_port *ap,
2979 return 0; 2997 return 0;
2980} 2998}
2981 2999
2982static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask) 3000/**
3001 * ata_wait_ready - sleep until BSY clears, or timeout
3002 * @ap: port containing status register to be polled
3003 * @deadline: deadline jiffies for the operation
3004 *
3005 * Sleep until ATA Status register bit BSY clears, or timeout
3006 * occurs.
3007 *
3008 * LOCKING:
3009 * Kernel thread context (may sleep).
3010 *
3011 * RETURNS:
3012 * 0 on success, -errno otherwise.
3013 */
3014int ata_wait_ready(struct ata_port *ap, unsigned long deadline)
3015{
3016 unsigned long start = jiffies;
3017 int warned = 0;
3018
3019 while (1) {
3020 u8 status = ata_chk_status(ap);
3021 unsigned long now = jiffies;
3022
3023 if (!(status & ATA_BUSY))
3024 return 0;
3025 if (status == 0xff)
3026 return -ENODEV;
3027 if (time_after(now, deadline))
3028 return -EBUSY;
3029
3030 if (!warned && time_after(now, start + 5 * HZ) &&
3031 (deadline - now > 3 * HZ)) {
3032 ata_port_printk(ap, KERN_WARNING,
3033 "port is slow to respond, please be patient "
3034 "(Status 0x%x)\n", status);
3035 warned = 1;
3036 }
3037
3038 msleep(50);
3039 }
3040}
3041
3042static int ata_bus_post_reset(struct ata_port *ap, unsigned int devmask,
3043 unsigned long deadline)
2983{ 3044{
2984 struct ata_ioports *ioaddr = &ap->ioaddr; 3045 struct ata_ioports *ioaddr = &ap->ioaddr;
2985 unsigned int dev0 = devmask & (1 << 0); 3046 unsigned int dev0 = devmask & (1 << 0);
2986 unsigned int dev1 = devmask & (1 << 1); 3047 unsigned int dev1 = devmask & (1 << 1);
2987 unsigned long timeout; 3048 int rc, ret = 0;
2988 3049
2989 /* if device 0 was found in ata_devchk, wait for its 3050 /* if device 0 was found in ata_devchk, wait for its
2990 * BSY bit to clear 3051 * BSY bit to clear
2991 */ 3052 */
2992 if (dev0) 3053 if (dev0) {
2993 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 3054 rc = ata_wait_ready(ap, deadline);
3055 if (rc) {
3056 if (rc != -ENODEV)
3057 return rc;
3058 ret = rc;
3059 }
3060 }
2994 3061
2995 /* if device 1 was found in ata_devchk, wait for 3062 /* if device 1 was found in ata_devchk, wait for
2996 * register access, then wait for BSY to clear 3063 * register access, then wait for BSY to clear
2997 */ 3064 */
2998 timeout = jiffies + ATA_TMOUT_BOOT;
2999 while (dev1) { 3065 while (dev1) {
3000 u8 nsect, lbal; 3066 u8 nsect, lbal;
3001 3067
@@ -3004,14 +3070,18 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
3004 lbal = ioread8(ioaddr->lbal_addr); 3070 lbal = ioread8(ioaddr->lbal_addr);
3005 if ((nsect == 1) && (lbal == 1)) 3071 if ((nsect == 1) && (lbal == 1))
3006 break; 3072 break;
3007 if (time_after(jiffies, timeout)) { 3073 if (time_after(jiffies, deadline))
3008 dev1 = 0; 3074 return -EBUSY;
3009 break;
3010 }
3011 msleep(50); /* give drive a breather */ 3075 msleep(50); /* give drive a breather */
3012 } 3076 }
3013 if (dev1) 3077 if (dev1) {
3014 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 3078 rc = ata_wait_ready(ap, deadline);
3079 if (rc) {
3080 if (rc != -ENODEV)
3081 return rc;
3082 ret = rc;
3083 }
3084 }
3015 3085
3016 /* is all this really necessary? */ 3086 /* is all this really necessary? */
3017 ap->ops->dev_select(ap, 0); 3087 ap->ops->dev_select(ap, 0);
@@ -3019,10 +3089,12 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
3019 ap->ops->dev_select(ap, 1); 3089 ap->ops->dev_select(ap, 1);
3020 if (dev0) 3090 if (dev0)
3021 ap->ops->dev_select(ap, 0); 3091 ap->ops->dev_select(ap, 0);
3092
3093 return ret;
3022} 3094}
3023 3095
3024static unsigned int ata_bus_softreset(struct ata_port *ap, 3096static int ata_bus_softreset(struct ata_port *ap, unsigned int devmask,
3025 unsigned int devmask) 3097 unsigned long deadline)
3026{ 3098{
3027 struct ata_ioports *ioaddr = &ap->ioaddr; 3099 struct ata_ioports *ioaddr = &ap->ioaddr;
3028 3100
@@ -3052,11 +3124,9 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
3052 * pulldown resistor. 3124 * pulldown resistor.
3053 */ 3125 */
3054 if (ata_check_status(ap) == 0xFF) 3126 if (ata_check_status(ap) == 0xFF)
3055 return 0; 3127 return -ENODEV;
3056
3057 ata_bus_post_reset(ap, devmask);
3058 3128
3059 return 0; 3129 return ata_bus_post_reset(ap, devmask, deadline);
3060} 3130}
3061 3131
3062/** 3132/**
@@ -3085,6 +3155,7 @@ void ata_bus_reset(struct ata_port *ap)
3085 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; 3155 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
3086 u8 err; 3156 u8 err;
3087 unsigned int dev0, dev1 = 0, devmask = 0; 3157 unsigned int dev0, dev1 = 0, devmask = 0;
3158 int rc;
3088 3159
3089 DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no); 3160 DPRINTK("ENTER, host %u, port %u\n", ap->print_id, ap->port_no);
3090 3161
@@ -3106,9 +3177,11 @@ void ata_bus_reset(struct ata_port *ap)
3106 ap->ops->dev_select(ap, 0); 3177 ap->ops->dev_select(ap, 0);
3107 3178
3108 /* issue bus reset */ 3179 /* issue bus reset */
3109 if (ap->flags & ATA_FLAG_SRST) 3180 if (ap->flags & ATA_FLAG_SRST) {
3110 if (ata_bus_softreset(ap, devmask)) 3181 rc = ata_bus_softreset(ap, devmask, jiffies + 40 * HZ);
3182 if (rc && rc != -ENODEV)
3111 goto err_out; 3183 goto err_out;
3184 }
3112 3185
3113 /* 3186 /*
3114 * determine by signature whether we have ATA or ATAPI devices 3187 * determine by signature whether we have ATA or ATAPI devices
@@ -3150,29 +3223,37 @@ err_out:
3150 * sata_phy_debounce - debounce SATA phy status 3223 * sata_phy_debounce - debounce SATA phy status
3151 * @ap: ATA port to debounce SATA phy status for 3224 * @ap: ATA port to debounce SATA phy status for
3152 * @params: timing parameters { interval, duratinon, timeout } in msec 3225 * @params: timing parameters { interval, duratinon, timeout } in msec
3226 * @deadline: deadline jiffies for the operation
3153 * 3227 *
3154 * Make sure SStatus of @ap reaches stable state, determined by 3228 * Make sure SStatus of @ap reaches stable state, determined by
3155 * holding the same value where DET is not 1 for @duration polled 3229 * holding the same value where DET is not 1 for @duration polled
3156 * every @interval, before @timeout. Timeout constraints the 3230 * every @interval, before @timeout. Timeout constraints the
3157 * beginning of the stable state. Because, after hot unplugging, 3231 * beginning of the stable state. Because DET gets stuck at 1 on
3158 * DET gets stuck at 1 on some controllers, this functions waits 3232 * some controllers after hot unplugging, this functions waits
3159 * until timeout then returns 0 if DET is stable at 1. 3233 * until timeout then returns 0 if DET is stable at 1.
3160 * 3234 *
3235 * @timeout is further limited by @deadline. The sooner of the
3236 * two is used.
3237 *
3161 * LOCKING: 3238 * LOCKING:
3162 * Kernel thread context (may sleep) 3239 * Kernel thread context (may sleep)
3163 * 3240 *
3164 * RETURNS: 3241 * RETURNS:
3165 * 0 on success, -errno on failure. 3242 * 0 on success, -errno on failure.
3166 */ 3243 */
3167int sata_phy_debounce(struct ata_port *ap, const unsigned long *params) 3244int sata_phy_debounce(struct ata_port *ap, const unsigned long *params,
3245 unsigned long deadline)
3168{ 3246{
3169 unsigned long interval_msec = params[0]; 3247 unsigned long interval_msec = params[0];
3170 unsigned long duration = params[1] * HZ / 1000; 3248 unsigned long duration = msecs_to_jiffies(params[1]);
3171 unsigned long timeout = jiffies + params[2] * HZ / 1000; 3249 unsigned long last_jiffies, t;
3172 unsigned long last_jiffies;
3173 u32 last, cur; 3250 u32 last, cur;
3174 int rc; 3251 int rc;
3175 3252
3253 t = jiffies + msecs_to_jiffies(params[2]);
3254 if (time_before(t, deadline))
3255 deadline = t;
3256
3176 if ((rc = sata_scr_read(ap, SCR_STATUS, &cur))) 3257 if ((rc = sata_scr_read(ap, SCR_STATUS, &cur)))
3177 return rc; 3258 return rc;
3178 cur &= 0xf; 3259 cur &= 0xf;
@@ -3188,7 +3269,7 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params)
3188 3269
3189 /* DET stable? */ 3270 /* DET stable? */
3190 if (cur == last) { 3271 if (cur == last) {
3191 if (cur == 1 && time_before(jiffies, timeout)) 3272 if (cur == 1 && time_before(jiffies, deadline))
3192 continue; 3273 continue;
3193 if (time_after(jiffies, last_jiffies + duration)) 3274 if (time_after(jiffies, last_jiffies + duration))
3194 return 0; 3275 return 0;
@@ -3199,8 +3280,8 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params)
3199 last = cur; 3280 last = cur;
3200 last_jiffies = jiffies; 3281 last_jiffies = jiffies;
3201 3282
3202 /* check timeout */ 3283 /* check deadline */
3203 if (time_after(jiffies, timeout)) 3284 if (time_after(jiffies, deadline))
3204 return -EBUSY; 3285 return -EBUSY;
3205 } 3286 }
3206} 3287}
@@ -3209,6 +3290,7 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params)
3209 * sata_phy_resume - resume SATA phy 3290 * sata_phy_resume - resume SATA phy
3210 * @ap: ATA port to resume SATA phy for 3291 * @ap: ATA port to resume SATA phy for
3211 * @params: timing parameters { interval, duratinon, timeout } in msec 3292 * @params: timing parameters { interval, duratinon, timeout } in msec
3293 * @deadline: deadline jiffies for the operation
3212 * 3294 *
3213 * Resume SATA phy of @ap and debounce it. 3295 * Resume SATA phy of @ap and debounce it.
3214 * 3296 *
@@ -3218,7 +3300,8 @@ int sata_phy_debounce(struct ata_port *ap, const unsigned long *params)
3218 * RETURNS: 3300 * RETURNS:
3219 * 0 on success, -errno on failure. 3301 * 0 on success, -errno on failure.
3220 */ 3302 */
3221int sata_phy_resume(struct ata_port *ap, const unsigned long *params) 3303int sata_phy_resume(struct ata_port *ap, const unsigned long *params,
3304 unsigned long deadline)
3222{ 3305{
3223 u32 scontrol; 3306 u32 scontrol;
3224 int rc; 3307 int rc;
@@ -3236,43 +3319,19 @@ int sata_phy_resume(struct ata_port *ap, const unsigned long *params)
3236 */ 3319 */
3237 msleep(200); 3320 msleep(200);
3238 3321
3239 return sata_phy_debounce(ap, params); 3322 return sata_phy_debounce(ap, params, deadline);
3240}
3241
3242static void ata_wait_spinup(struct ata_port *ap)
3243{
3244 struct ata_eh_context *ehc = &ap->eh_context;
3245 unsigned long end, secs;
3246 int rc;
3247
3248 /* first, debounce phy if SATA */
3249 if (ap->cbl == ATA_CBL_SATA) {
3250 rc = sata_phy_debounce(ap, sata_deb_timing_hotplug);
3251
3252 /* if debounced successfully and offline, no need to wait */
3253 if ((rc == 0 || rc == -EOPNOTSUPP) && ata_port_offline(ap))
3254 return;
3255 }
3256
3257 /* okay, let's give the drive time to spin up */
3258 end = ehc->i.hotplug_timestamp + ATA_SPINUP_WAIT * HZ / 1000;
3259 secs = ((end - jiffies) + HZ - 1) / HZ;
3260
3261 if (time_after(jiffies, end))
3262 return;
3263
3264 if (secs > 5)
3265 ata_port_printk(ap, KERN_INFO, "waiting for device to spin up "
3266 "(%lu secs)\n", secs);
3267
3268 schedule_timeout_uninterruptible(end - jiffies);
3269} 3323}
3270 3324
3271/** 3325/**
3272 * ata_std_prereset - prepare for reset 3326 * ata_std_prereset - prepare for reset
3273 * @ap: ATA port to be reset 3327 * @ap: ATA port to be reset
3328 * @deadline: deadline jiffies for the operation
3274 * 3329 *
3275 * @ap is about to be reset. Initialize it. 3330 * @ap is about to be reset. Initialize it. Failure from
3331 * prereset makes libata abort whole reset sequence and give up
3332 * that port, so prereset should be best-effort. It does its
3333 * best to prepare for reset sequence but if things go wrong, it
3334 * should just whine, not fail.
3276 * 3335 *
3277 * LOCKING: 3336 * LOCKING:
3278 * Kernel thread context (may sleep) 3337 * Kernel thread context (may sleep)
@@ -3280,41 +3339,41 @@ static void ata_wait_spinup(struct ata_port *ap)
3280 * RETURNS: 3339 * RETURNS:
3281 * 0 on success, -errno otherwise. 3340 * 0 on success, -errno otherwise.
3282 */ 3341 */
3283int ata_std_prereset(struct ata_port *ap) 3342int ata_std_prereset(struct ata_port *ap, unsigned long deadline)
3284{ 3343{
3285 struct ata_eh_context *ehc = &ap->eh_context; 3344 struct ata_eh_context *ehc = &ap->eh_context;
3286 const unsigned long *timing = sata_ehc_deb_timing(ehc); 3345 const unsigned long *timing = sata_ehc_deb_timing(ehc);
3287 int rc; 3346 int rc;
3288 3347
3289 /* handle link resume & hotplug spinup */ 3348 /* handle link resume */
3290 if ((ehc->i.flags & ATA_EHI_RESUME_LINK) && 3349 if ((ehc->i.flags & ATA_EHI_RESUME_LINK) &&
3291 (ap->flags & ATA_FLAG_HRST_TO_RESUME)) 3350 (ap->flags & ATA_FLAG_HRST_TO_RESUME))
3292 ehc->i.action |= ATA_EH_HARDRESET; 3351 ehc->i.action |= ATA_EH_HARDRESET;
3293 3352
3294 if ((ehc->i.flags & ATA_EHI_HOTPLUGGED) &&
3295 (ap->flags & ATA_FLAG_SKIP_D2H_BSY))
3296 ata_wait_spinup(ap);
3297
3298 /* if we're about to do hardreset, nothing more to do */ 3353 /* if we're about to do hardreset, nothing more to do */
3299 if (ehc->i.action & ATA_EH_HARDRESET) 3354 if (ehc->i.action & ATA_EH_HARDRESET)
3300 return 0; 3355 return 0;
3301 3356
3302 /* if SATA, resume phy */ 3357 /* if SATA, resume phy */
3303 if (ap->cbl == ATA_CBL_SATA) { 3358 if (ap->cbl == ATA_CBL_SATA) {
3304 rc = sata_phy_resume(ap, timing); 3359 rc = sata_phy_resume(ap, timing, deadline);
3305 if (rc && rc != -EOPNOTSUPP) { 3360 /* whine about phy resume failure but proceed */
3306 /* phy resume failed */ 3361 if (rc && rc != -EOPNOTSUPP)
3307 ata_port_printk(ap, KERN_WARNING, "failed to resume " 3362 ata_port_printk(ap, KERN_WARNING, "failed to resume "
3308 "link for reset (errno=%d)\n", rc); 3363 "link for reset (errno=%d)\n", rc);
3309 return rc;
3310 }
3311 } 3364 }
3312 3365
3313 /* Wait for !BSY if the controller can wait for the first D2H 3366 /* Wait for !BSY if the controller can wait for the first D2H
3314 * Reg FIS and we don't know that no device is attached. 3367 * Reg FIS and we don't know that no device is attached.
3315 */ 3368 */
3316 if (!(ap->flags & ATA_FLAG_SKIP_D2H_BSY) && !ata_port_offline(ap)) 3369 if (!(ap->flags & ATA_FLAG_SKIP_D2H_BSY) && !ata_port_offline(ap)) {
3317 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 3370 rc = ata_wait_ready(ap, deadline);
3371 if (rc) {
3372 ata_port_printk(ap, KERN_WARNING, "device not ready "
3373 "(errno=%d), forcing hardreset\n", rc);
3374 ehc->i.action |= ATA_EH_HARDRESET;
3375 }
3376 }
3318 3377
3319 return 0; 3378 return 0;
3320} 3379}
@@ -3323,6 +3382,7 @@ int ata_std_prereset(struct ata_port *ap)
3323 * ata_std_softreset - reset host port via ATA SRST 3382 * ata_std_softreset - reset host port via ATA SRST
3324 * @ap: port to reset 3383 * @ap: port to reset
3325 * @classes: resulting classes of attached devices 3384 * @classes: resulting classes of attached devices
3385 * @deadline: deadline jiffies for the operation
3326 * 3386 *
3327 * Reset host port using ATA SRST. 3387 * Reset host port using ATA SRST.
3328 * 3388 *
@@ -3332,10 +3392,12 @@ int ata_std_prereset(struct ata_port *ap)
3332 * RETURNS: 3392 * RETURNS:
3333 * 0 on success, -errno otherwise. 3393 * 0 on success, -errno otherwise.
3334 */ 3394 */
3335int ata_std_softreset(struct ata_port *ap, unsigned int *classes) 3395int ata_std_softreset(struct ata_port *ap, unsigned int *classes,
3396 unsigned long deadline)
3336{ 3397{
3337 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS; 3398 unsigned int slave_possible = ap->flags & ATA_FLAG_SLAVE_POSS;
3338 unsigned int devmask = 0, err_mask; 3399 unsigned int devmask = 0;
3400 int rc;
3339 u8 err; 3401 u8 err;
3340 3402
3341 DPRINTK("ENTER\n"); 3403 DPRINTK("ENTER\n");
@@ -3356,11 +3418,11 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
3356 3418
3357 /* issue bus reset */ 3419 /* issue bus reset */
3358 DPRINTK("about to softreset, devmask=%x\n", devmask); 3420 DPRINTK("about to softreset, devmask=%x\n", devmask);
3359 err_mask = ata_bus_softreset(ap, devmask); 3421 rc = ata_bus_softreset(ap, devmask, deadline);
3360 if (err_mask) { 3422 /* if link is occupied, -ENODEV too is an error */
3361 ata_port_printk(ap, KERN_ERR, "SRST failed (err_mask=0x%x)\n", 3423 if (rc && (rc != -ENODEV || sata_scr_valid(ap))) {
3362 err_mask); 3424 ata_port_printk(ap, KERN_ERR, "SRST failed (errno=%d)\n", rc);
3363 return -EIO; 3425 return rc;
3364 } 3426 }
3365 3427
3366 /* determine by signature whether we have ATA or ATAPI devices */ 3428 /* determine by signature whether we have ATA or ATAPI devices */
@@ -3377,6 +3439,7 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
3377 * sata_port_hardreset - reset port via SATA phy reset 3439 * sata_port_hardreset - reset port via SATA phy reset
3378 * @ap: port to reset 3440 * @ap: port to reset
3379 * @timing: timing parameters { interval, duratinon, timeout } in msec 3441 * @timing: timing parameters { interval, duratinon, timeout } in msec
3442 * @deadline: deadline jiffies for the operation
3380 * 3443 *
3381 * SATA phy-reset host port using DET bits of SControl register. 3444 * SATA phy-reset host port using DET bits of SControl register.
3382 * 3445 *
@@ -3386,7 +3449,8 @@ int ata_std_softreset(struct ata_port *ap, unsigned int *classes)
3386 * RETURNS: 3449 * RETURNS:
3387 * 0 on success, -errno otherwise. 3450 * 0 on success, -errno otherwise.
3388 */ 3451 */
3389int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing) 3452int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing,
3453 unsigned long deadline)
3390{ 3454{
3391 u32 scontrol; 3455 u32 scontrol;
3392 int rc; 3456 int rc;
@@ -3425,7 +3489,7 @@ int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing)
3425 msleep(1); 3489 msleep(1);
3426 3490
3427 /* bring phy back */ 3491 /* bring phy back */
3428 rc = sata_phy_resume(ap, timing); 3492 rc = sata_phy_resume(ap, timing, deadline);
3429 out: 3493 out:
3430 DPRINTK("EXIT, rc=%d\n", rc); 3494 DPRINTK("EXIT, rc=%d\n", rc);
3431 return rc; 3495 return rc;
@@ -3435,6 +3499,7 @@ int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing)
3435 * sata_std_hardreset - reset host port via SATA phy reset 3499 * sata_std_hardreset - reset host port via SATA phy reset
3436 * @ap: port to reset 3500 * @ap: port to reset
3437 * @class: resulting class of attached device 3501 * @class: resulting class of attached device
3502 * @deadline: deadline jiffies for the operation
3438 * 3503 *
3439 * SATA phy-reset host port using DET bits of SControl register, 3504 * SATA phy-reset host port using DET bits of SControl register,
3440 * wait for !BSY and classify the attached device. 3505 * wait for !BSY and classify the attached device.
@@ -3445,7 +3510,8 @@ int sata_port_hardreset(struct ata_port *ap, const unsigned long *timing)
3445 * RETURNS: 3510 * RETURNS:
3446 * 0 on success, -errno otherwise. 3511 * 0 on success, -errno otherwise.
3447 */ 3512 */
3448int sata_std_hardreset(struct ata_port *ap, unsigned int *class) 3513int sata_std_hardreset(struct ata_port *ap, unsigned int *class,
3514 unsigned long deadline)
3449{ 3515{
3450 const unsigned long *timing = sata_ehc_deb_timing(&ap->eh_context); 3516 const unsigned long *timing = sata_ehc_deb_timing(&ap->eh_context);
3451 int rc; 3517 int rc;
@@ -3453,7 +3519,7 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
3453 DPRINTK("ENTER\n"); 3519 DPRINTK("ENTER\n");
3454 3520
3455 /* do hardreset */ 3521 /* do hardreset */
3456 rc = sata_port_hardreset(ap, timing); 3522 rc = sata_port_hardreset(ap, timing, deadline);
3457 if (rc) { 3523 if (rc) {
3458 ata_port_printk(ap, KERN_ERR, 3524 ata_port_printk(ap, KERN_ERR,
3459 "COMRESET failed (errno=%d)\n", rc); 3525 "COMRESET failed (errno=%d)\n", rc);
@@ -3470,10 +3536,12 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
3470 /* wait a while before checking status, see SRST for more info */ 3536 /* wait a while before checking status, see SRST for more info */
3471 msleep(150); 3537 msleep(150);
3472 3538
3473 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 3539 rc = ata_wait_ready(ap, deadline);
3540 /* link occupied, -ENODEV too is an error */
3541 if (rc) {
3474 ata_port_printk(ap, KERN_ERR, 3542 ata_port_printk(ap, KERN_ERR,
3475 "COMRESET failed (device not ready)\n"); 3543 "COMRESET failed (errno=%d)\n", rc);
3476 return -EIO; 3544 return rc;
3477 } 3545 }
3478 3546
3479 ap->ops->dev_select(ap, 0); /* probably unnecessary */ 3547 ap->ops->dev_select(ap, 0); /* probably unnecessary */
@@ -3554,7 +3622,6 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
3554 const u16 *old_id = dev->id; 3622 const u16 *old_id = dev->id;
3555 unsigned char model[2][ATA_ID_PROD_LEN + 1]; 3623 unsigned char model[2][ATA_ID_PROD_LEN + 1];
3556 unsigned char serial[2][ATA_ID_SERNO_LEN + 1]; 3624 unsigned char serial[2][ATA_ID_SERNO_LEN + 1];
3557 u64 new_n_sectors;
3558 3625
3559 if (dev->class != new_class) { 3626 if (dev->class != new_class) {
3560 ata_dev_printk(dev, KERN_INFO, "class mismatch %d != %d\n", 3627 ata_dev_printk(dev, KERN_INFO, "class mismatch %d != %d\n",
@@ -3566,7 +3633,6 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
3566 ata_id_c_string(new_id, model[1], ATA_ID_PROD, sizeof(model[1])); 3633 ata_id_c_string(new_id, model[1], ATA_ID_PROD, sizeof(model[1]));
3567 ata_id_c_string(old_id, serial[0], ATA_ID_SERNO, sizeof(serial[0])); 3634 ata_id_c_string(old_id, serial[0], ATA_ID_SERNO, sizeof(serial[0]));
3568 ata_id_c_string(new_id, serial[1], ATA_ID_SERNO, sizeof(serial[1])); 3635 ata_id_c_string(new_id, serial[1], ATA_ID_SERNO, sizeof(serial[1]));
3569 new_n_sectors = ata_id_n_sectors(new_id);
3570 3636
3571 if (strcmp(model[0], model[1])) { 3637 if (strcmp(model[0], model[1])) {
3572 ata_dev_printk(dev, KERN_INFO, "model number mismatch " 3638 ata_dev_printk(dev, KERN_INFO, "model number mismatch "
@@ -3580,25 +3646,12 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
3580 return 0; 3646 return 0;
3581 } 3647 }
3582 3648
3583 if (dev->class == ATA_DEV_ATA && dev->n_sectors != new_n_sectors) {
3584 ata_dev_printk(dev, KERN_INFO, "n_sectors mismatch "
3585 "%llu != %llu\n",
3586 (unsigned long long)dev->n_sectors,
3587 (unsigned long long)new_n_sectors);
3588 /* Are we the boot time size - if so we appear to be the
3589 same disk at this point and our HPA got reapplied */
3590 if (ata_ignore_hpa && dev->n_sectors_boot == new_n_sectors
3591 && ata_id_hpa_enabled(new_id))
3592 return 1;
3593 return 0;
3594 }
3595
3596 return 1; 3649 return 1;
3597} 3650}
3598 3651
3599/** 3652/**
3600 * ata_dev_revalidate - Revalidate ATA device 3653 * ata_dev_reread_id - Re-read IDENTIFY data
3601 * @dev: device to revalidate 3654 * @adev: target ATA device
3602 * @readid_flags: read ID flags 3655 * @readid_flags: read ID flags
3603 * 3656 *
3604 * Re-read IDENTIFY page and make sure @dev is still attached to 3657 * Re-read IDENTIFY page and make sure @dev is still attached to
@@ -3610,34 +3663,68 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
3610 * RETURNS: 3663 * RETURNS:
3611 * 0 on success, negative errno otherwise 3664 * 0 on success, negative errno otherwise
3612 */ 3665 */
3613int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags) 3666int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags)
3614{ 3667{
3615 unsigned int class = dev->class; 3668 unsigned int class = dev->class;
3616 u16 *id = (void *)dev->ap->sector_buf; 3669 u16 *id = (void *)dev->ap->sector_buf;
3617 int rc; 3670 int rc;
3618 3671
3619 if (!ata_dev_enabled(dev)) {
3620 rc = -ENODEV;
3621 goto fail;
3622 }
3623
3624 /* read ID data */ 3672 /* read ID data */
3625 rc = ata_dev_read_id(dev, &class, readid_flags, id); 3673 rc = ata_dev_read_id(dev, &class, readid_flags, id);
3626 if (rc) 3674 if (rc)
3627 goto fail; 3675 return rc;
3628 3676
3629 /* is the device still there? */ 3677 /* is the device still there? */
3630 if (!ata_dev_same_device(dev, class, id)) { 3678 if (!ata_dev_same_device(dev, class, id))
3631 rc = -ENODEV; 3679 return -ENODEV;
3632 goto fail;
3633 }
3634 3680
3635 memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS); 3681 memcpy(dev->id, id, sizeof(id[0]) * ATA_ID_WORDS);
3682 return 0;
3683}
3684
3685/**
3686 * ata_dev_revalidate - Revalidate ATA device
3687 * @dev: device to revalidate
3688 * @readid_flags: read ID flags
3689 *
3690 * Re-read IDENTIFY page, make sure @dev is still attached to the
3691 * port and reconfigure it according to the new IDENTIFY page.
3692 *
3693 * LOCKING:
3694 * Kernel thread context (may sleep)
3695 *
3696 * RETURNS:
3697 * 0 on success, negative errno otherwise
3698 */
3699int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags)
3700{
3701 u64 n_sectors = dev->n_sectors;
3702 int rc;
3703
3704 if (!ata_dev_enabled(dev))
3705 return -ENODEV;
3706
3707 /* re-read ID */
3708 rc = ata_dev_reread_id(dev, readid_flags);
3709 if (rc)
3710 goto fail;
3636 3711
3637 /* configure device according to the new ID */ 3712 /* configure device according to the new ID */
3638 rc = ata_dev_configure(dev); 3713 rc = ata_dev_configure(dev);
3639 if (rc == 0) 3714 if (rc)
3640 return 0; 3715 goto fail;
3716
3717 /* verify n_sectors hasn't changed */
3718 if (dev->class == ATA_DEV_ATA && dev->n_sectors != n_sectors) {
3719 ata_dev_printk(dev, KERN_INFO, "n_sectors mismatch "
3720 "%llu != %llu\n",
3721 (unsigned long long)n_sectors,
3722 (unsigned long long)dev->n_sectors);
3723 rc = -ENODEV;
3724 goto fail;
3725 }
3726
3727 return 0;
3641 3728
3642 fail: 3729 fail:
3643 ata_dev_printk(dev, KERN_ERR, "revalidation failed (errno=%d)\n", rc); 3730 ata_dev_printk(dev, KERN_ERR, "revalidation failed (errno=%d)\n", rc);
@@ -3681,6 +3768,7 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3681 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA }, 3768 { "ATAPI CD-ROM DRIVE 40X MAXIMUM",NULL,ATA_HORKAGE_NODMA },
3682 { "_NEC DV5800A", NULL, ATA_HORKAGE_NODMA }, 3769 { "_NEC DV5800A", NULL, ATA_HORKAGE_NODMA },
3683 { "SAMSUNG CD-ROM SN-124","N001", ATA_HORKAGE_NODMA }, 3770 { "SAMSUNG CD-ROM SN-124","N001", ATA_HORKAGE_NODMA },
3771 { "Seagate STT20000A", NULL, ATA_HORKAGE_NODMA },
3684 3772
3685 /* Weird ATAPI devices */ 3773 /* Weird ATAPI devices */
3686 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 | 3774 { "TORiSAN DVD-ROM DRD-N216", NULL, ATA_HORKAGE_MAX_SEC_128 |
@@ -5793,37 +5881,11 @@ static int ata_host_request_pm(struct ata_host *host, pm_message_t mesg,
5793 */ 5881 */
5794int ata_host_suspend(struct ata_host *host, pm_message_t mesg) 5882int ata_host_suspend(struct ata_host *host, pm_message_t mesg)
5795{ 5883{
5796 int i, j, rc; 5884 int rc;
5797 5885
5798 rc = ata_host_request_pm(host, mesg, 0, ATA_EHI_QUIET, 1); 5886 rc = ata_host_request_pm(host, mesg, 0, ATA_EHI_QUIET, 1);
5799 if (rc) 5887 if (rc == 0)
5800 goto fail; 5888 host->dev->power.power_state = mesg;
5801
5802 /* EH is quiescent now. Fail if we have any ready device.
5803 * This happens if hotplug occurs between completion of device
5804 * suspension and here.
5805 */
5806 for (i = 0; i < host->n_ports; i++) {
5807 struct ata_port *ap = host->ports[i];
5808
5809 for (j = 0; j < ATA_MAX_DEVICES; j++) {
5810 struct ata_device *dev = &ap->device[j];
5811
5812 if (ata_dev_ready(dev)) {
5813 ata_port_printk(ap, KERN_WARNING,
5814 "suspend failed, device %d "
5815 "still active\n", dev->devno);
5816 rc = -EBUSY;
5817 goto fail;
5818 }
5819 }
5820 }
5821
5822 host->dev->power.power_state = mesg;
5823 return 0;
5824
5825 fail:
5826 ata_host_resume(host);
5827 return rc; 5889 return rc;
5828} 5890}
5829 5891
@@ -5932,6 +5994,7 @@ struct ata_port *ata_port_alloc(struct ata_host *host)
5932 if (!ap) 5994 if (!ap)
5933 return NULL; 5995 return NULL;
5934 5996
5997 ap->pflags |= ATA_PFLAG_INITIALIZING;
5935 ap->lock = &host->lock; 5998 ap->lock = &host->lock;
5936 ap->flags = ATA_FLAG_DISABLED; 5999 ap->flags = ATA_FLAG_DISABLED;
5937 ap->print_id = -1; 6000 ap->print_id = -1;
@@ -6300,6 +6363,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
6300 ehi->action |= ATA_EH_SOFTRESET; 6363 ehi->action |= ATA_EH_SOFTRESET;
6301 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET; 6364 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
6302 6365
6366 ap->pflags &= ~ATA_PFLAG_INITIALIZING;
6303 ap->pflags |= ATA_PFLAG_LOADING; 6367 ap->pflags |= ATA_PFLAG_LOADING;
6304 ata_port_schedule_eh(ap); 6368 ata_port_schedule_eh(ap);
6305 6369
@@ -6425,9 +6489,9 @@ void ata_port_detach(struct ata_port *ap)
6425 /* Flush hotplug task. The sequence is similar to 6489 /* Flush hotplug task. The sequence is similar to
6426 * ata_port_flush_task(). 6490 * ata_port_flush_task().
6427 */ 6491 */
6428 flush_workqueue(ata_aux_wq); 6492 cancel_work_sync(&ap->hotplug_task.work); /* akpm: why? */
6429 cancel_delayed_work(&ap->hotplug_task); 6493 cancel_delayed_work(&ap->hotplug_task);
6430 flush_workqueue(ata_aux_wq); 6494 cancel_work_sync(&ap->hotplug_task.work);
6431 6495
6432 skip_eh: 6496 skip_eh:
6433 /* remove the associated SCSI host */ 6497 /* remove the associated SCSI host */
@@ -6793,6 +6857,7 @@ EXPORT_SYMBOL_GPL(ata_port_disable);
6793EXPORT_SYMBOL_GPL(ata_ratelimit); 6857EXPORT_SYMBOL_GPL(ata_ratelimit);
6794EXPORT_SYMBOL_GPL(ata_wait_register); 6858EXPORT_SYMBOL_GPL(ata_wait_register);
6795EXPORT_SYMBOL_GPL(ata_busy_sleep); 6859EXPORT_SYMBOL_GPL(ata_busy_sleep);
6860EXPORT_SYMBOL_GPL(ata_wait_ready);
6796EXPORT_SYMBOL_GPL(ata_port_queue_task); 6861EXPORT_SYMBOL_GPL(ata_port_queue_task);
6797EXPORT_SYMBOL_GPL(ata_scsi_ioctl); 6862EXPORT_SYMBOL_GPL(ata_scsi_ioctl);
6798EXPORT_SYMBOL_GPL(ata_scsi_queuecmd); 6863EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
@@ -6823,6 +6888,7 @@ EXPORT_SYMBOL_GPL(ata_timing_merge);
6823#ifdef CONFIG_PCI 6888#ifdef CONFIG_PCI
6824EXPORT_SYMBOL_GPL(pci_test_config_bits); 6889EXPORT_SYMBOL_GPL(pci_test_config_bits);
6825EXPORT_SYMBOL_GPL(ata_pci_init_native_host); 6890EXPORT_SYMBOL_GPL(ata_pci_init_native_host);
6891EXPORT_SYMBOL_GPL(ata_pci_init_bmdma);
6826EXPORT_SYMBOL_GPL(ata_pci_prepare_native_host); 6892EXPORT_SYMBOL_GPL(ata_pci_prepare_native_host);
6827EXPORT_SYMBOL_GPL(ata_pci_init_one); 6893EXPORT_SYMBOL_GPL(ata_pci_init_one);
6828EXPORT_SYMBOL_GPL(ata_pci_remove_one); 6894EXPORT_SYMBOL_GPL(ata_pci_remove_one);
@@ -6836,11 +6902,6 @@ EXPORT_SYMBOL_GPL(ata_pci_default_filter);
6836EXPORT_SYMBOL_GPL(ata_pci_clear_simplex); 6902EXPORT_SYMBOL_GPL(ata_pci_clear_simplex);
6837#endif /* CONFIG_PCI */ 6903#endif /* CONFIG_PCI */
6838 6904
6839#ifdef CONFIG_PM
6840EXPORT_SYMBOL_GPL(ata_scsi_device_suspend);
6841EXPORT_SYMBOL_GPL(ata_scsi_device_resume);
6842#endif /* CONFIG_PM */
6843
6844EXPORT_SYMBOL_GPL(ata_eng_timeout); 6905EXPORT_SYMBOL_GPL(ata_eng_timeout);
6845EXPORT_SYMBOL_GPL(ata_port_schedule_eh); 6906EXPORT_SYMBOL_GPL(ata_port_schedule_eh);
6846EXPORT_SYMBOL_GPL(ata_port_abort); 6907EXPORT_SYMBOL_GPL(ata_port_abort);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 2bff9adcacf1..d8070989a39f 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -50,34 +50,39 @@ enum {
50 ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2), 50 ATA_EH_SPDN_FALLBACK_TO_PIO = (1 << 2),
51}; 51};
52 52
53/* Waiting in ->prereset can never be reliable. It's sometimes nice
54 * to wait there but it can't be depended upon; otherwise, we wouldn't
55 * be resetting. Just give it enough time for most drives to spin up.
56 */
57enum {
58 ATA_EH_PRERESET_TIMEOUT = 10 * HZ,
59};
60
61/* The following table determines how we sequence resets. Each entry
62 * represents timeout for that try. The first try can be soft or
63 * hardreset. All others are hardreset if available. In most cases
64 * the first reset w/ 10sec timeout should succeed. Following entries
65 * are mostly for error handling, hotplug and retarded devices.
66 */
67static const unsigned long ata_eh_reset_timeouts[] = {
68 10 * HZ, /* most drives spin up by 10sec */
69 10 * HZ, /* > 99% working drives spin up before 20sec */
70 35 * HZ, /* give > 30 secs of idleness for retarded devices */
71 5 * HZ, /* and sweet one last chance */
72 /* > 1 min has elapsed, give up */
73};
74
53static void __ata_port_freeze(struct ata_port *ap); 75static void __ata_port_freeze(struct ata_port *ap);
54static void ata_eh_finish(struct ata_port *ap); 76static void ata_eh_finish(struct ata_port *ap);
55#ifdef CONFIG_PM 77#ifdef CONFIG_PM
56static void ata_eh_handle_port_suspend(struct ata_port *ap); 78static void ata_eh_handle_port_suspend(struct ata_port *ap);
57static void ata_eh_handle_port_resume(struct ata_port *ap); 79static void ata_eh_handle_port_resume(struct ata_port *ap);
58static int ata_eh_suspend(struct ata_port *ap,
59 struct ata_device **r_failed_dev);
60static void ata_eh_prep_resume(struct ata_port *ap);
61static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev);
62#else /* CONFIG_PM */ 80#else /* CONFIG_PM */
63static void ata_eh_handle_port_suspend(struct ata_port *ap) 81static void ata_eh_handle_port_suspend(struct ata_port *ap)
64{ } 82{ }
65 83
66static void ata_eh_handle_port_resume(struct ata_port *ap) 84static void ata_eh_handle_port_resume(struct ata_port *ap)
67{ } 85{ }
68
69static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
70{
71 return 0;
72}
73
74static void ata_eh_prep_resume(struct ata_port *ap)
75{ }
76
77static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
78{
79 return 0;
80}
81#endif /* CONFIG_PM */ 86#endif /* CONFIG_PM */
82 87
83static void ata_ering_record(struct ata_ering *ering, int is_io, 88static void ata_ering_record(struct ata_ering *ering, int is_io,
@@ -546,6 +551,9 @@ void ata_port_schedule_eh(struct ata_port *ap)
546{ 551{
547 WARN_ON(!ap->ops->error_handler); 552 WARN_ON(!ap->ops->error_handler);
548 553
554 if (ap->pflags & ATA_PFLAG_INITIALIZING)
555 return;
556
549 ap->pflags |= ATA_PFLAG_EH_PENDING; 557 ap->pflags |= ATA_PFLAG_EH_PENDING;
550 scsi_schedule_eh(ap->scsi_host); 558 scsi_schedule_eh(ap->scsi_host);
551 559
@@ -1001,7 +1009,7 @@ static unsigned int atapi_eh_request_sense(struct ata_queued_cmd *qc)
1001 sense_buf[0] = 0x70; 1009 sense_buf[0] = 0x70;
1002 sense_buf[2] = qc->result_tf.feature >> 4; 1010 sense_buf[2] = qc->result_tf.feature >> 4;
1003 1011
1004 /* some devices time out if garbage left in tf */ 1012 /* some devices time out if garbage left in tf */
1005 ata_tf_init(dev, &tf); 1013 ata_tf_init(dev, &tf);
1006 1014
1007 memset(cdb, 0, ATAPI_CDB_LEN); 1015 memset(cdb, 0, ATAPI_CDB_LEN);
@@ -1558,14 +1566,14 @@ static void ata_eh_report(struct ata_port *ap)
1558} 1566}
1559 1567
1560static int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset, 1568static int ata_do_reset(struct ata_port *ap, ata_reset_fn_t reset,
1561 unsigned int *classes) 1569 unsigned int *classes, unsigned long deadline)
1562{ 1570{
1563 int i, rc; 1571 int i, rc;
1564 1572
1565 for (i = 0; i < ATA_MAX_DEVICES; i++) 1573 for (i = 0; i < ATA_MAX_DEVICES; i++)
1566 classes[i] = ATA_DEV_UNKNOWN; 1574 classes[i] = ATA_DEV_UNKNOWN;
1567 1575
1568 rc = reset(ap, classes); 1576 rc = reset(ap, classes, deadline);
1569 if (rc) 1577 if (rc)
1570 return rc; 1578 return rc;
1571 1579
@@ -1603,8 +1611,9 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1603{ 1611{
1604 struct ata_eh_context *ehc = &ap->eh_context; 1612 struct ata_eh_context *ehc = &ap->eh_context;
1605 unsigned int *classes = ehc->classes; 1613 unsigned int *classes = ehc->classes;
1606 int tries = ATA_EH_RESET_TRIES;
1607 int verbose = !(ehc->i.flags & ATA_EHI_QUIET); 1614 int verbose = !(ehc->i.flags & ATA_EHI_QUIET);
1615 int try = 0;
1616 unsigned long deadline;
1608 unsigned int action; 1617 unsigned int action;
1609 ata_reset_fn_t reset; 1618 ata_reset_fn_t reset;
1610 int i, did_followup_srst, rc; 1619 int i, did_followup_srst, rc;
@@ -1624,7 +1633,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1624 ehc->i.action |= ATA_EH_HARDRESET; 1633 ehc->i.action |= ATA_EH_HARDRESET;
1625 1634
1626 if (prereset) { 1635 if (prereset) {
1627 rc = prereset(ap); 1636 rc = prereset(ap, jiffies + ATA_EH_PRERESET_TIMEOUT);
1628 if (rc) { 1637 if (rc) {
1629 if (rc == -ENOENT) { 1638 if (rc == -ENOENT) {
1630 ata_port_printk(ap, KERN_DEBUG, 1639 ata_port_printk(ap, KERN_DEBUG,
@@ -1665,6 +1674,8 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1665 } 1674 }
1666 1675
1667 retry: 1676 retry:
1677 deadline = jiffies + ata_eh_reset_timeouts[try++];
1678
1668 /* shut up during boot probing */ 1679 /* shut up during boot probing */
1669 if (verbose) 1680 if (verbose)
1670 ata_port_printk(ap, KERN_INFO, "%s resetting port\n", 1681 ata_port_printk(ap, KERN_INFO, "%s resetting port\n",
@@ -1676,7 +1687,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1676 else 1687 else
1677 ehc->i.flags |= ATA_EHI_DID_SOFTRESET; 1688 ehc->i.flags |= ATA_EHI_DID_SOFTRESET;
1678 1689
1679 rc = ata_do_reset(ap, reset, classes); 1690 rc = ata_do_reset(ap, reset, classes, deadline);
1680 1691
1681 did_followup_srst = 0; 1692 did_followup_srst = 0;
1682 if (reset == hardreset && 1693 if (reset == hardreset &&
@@ -1693,7 +1704,7 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1693 } 1704 }
1694 1705
1695 ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK); 1706 ata_eh_about_to_do(ap, NULL, ATA_EH_RESET_MASK);
1696 rc = ata_do_reset(ap, reset, classes); 1707 rc = ata_do_reset(ap, reset, classes, deadline);
1697 1708
1698 if (rc == 0 && classify && 1709 if (rc == 0 && classify &&
1699 classes[0] == ATA_DEV_UNKNOWN) { 1710 classes[0] == ATA_DEV_UNKNOWN) {
@@ -1703,22 +1714,21 @@ static int ata_eh_reset(struct ata_port *ap, int classify,
1703 } 1714 }
1704 } 1715 }
1705 1716
1706 if (rc && --tries) { 1717 if (rc && try < ARRAY_SIZE(ata_eh_reset_timeouts)) {
1707 const char *type; 1718 unsigned long now = jiffies;
1708 1719
1709 if (reset == softreset) { 1720 if (time_before(now, deadline)) {
1710 if (did_followup_srst) 1721 unsigned long delta = deadline - jiffies;
1711 type = "follow-up soft";
1712 else
1713 type = "soft";
1714 } else
1715 type = "hard";
1716 1722
1717 ata_port_printk(ap, KERN_WARNING, 1723 ata_port_printk(ap, KERN_WARNING, "reset failed "
1718 "%sreset failed, retrying in 5 secs\n", type); 1724 "(errno=%d), retrying in %u secs\n",
1719 ssleep(5); 1725 rc, (jiffies_to_msecs(delta) + 999) / 1000);
1726
1727 schedule_timeout_uninterruptible(delta);
1728 }
1720 1729
1721 if (reset == hardreset) 1730 if (reset == hardreset &&
1731 try == ARRAY_SIZE(ata_eh_reset_timeouts) - 1)
1722 sata_down_spd_limit(ap); 1732 sata_down_spd_limit(ap);
1723 if (hardreset) 1733 if (hardreset)
1724 reset = hardreset; 1734 reset = hardreset;
@@ -1767,7 +1777,7 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1767 if (ehc->i.flags & ATA_EHI_DID_RESET) 1777 if (ehc->i.flags & ATA_EHI_DID_RESET)
1768 readid_flags |= ATA_READID_POSTRESET; 1778 readid_flags |= ATA_READID_POSTRESET;
1769 1779
1770 if (action & ATA_EH_REVALIDATE && ata_dev_ready(dev)) { 1780 if ((action & ATA_EH_REVALIDATE) && ata_dev_enabled(dev)) {
1771 if (ata_port_offline(ap)) { 1781 if (ata_port_offline(ap)) {
1772 rc = -EIO; 1782 rc = -EIO;
1773 goto err; 1783 goto err;
@@ -1848,166 +1858,6 @@ static int ata_eh_revalidate_and_attach(struct ata_port *ap,
1848 return rc; 1858 return rc;
1849} 1859}
1850 1860
1851#ifdef CONFIG_PM
1852/**
1853 * ata_eh_suspend - handle suspend EH action
1854 * @ap: target host port
1855 * @r_failed_dev: result parameter to indicate failing device
1856 *
1857 * Handle suspend EH action. Disk devices are spinned down and
1858 * other types of devices are just marked suspended. Once
1859 * suspended, no EH action to the device is allowed until it is
1860 * resumed.
1861 *
1862 * LOCKING:
1863 * Kernel thread context (may sleep).
1864 *
1865 * RETURNS:
1866 * 0 on success, -errno otherwise
1867 */
1868static int ata_eh_suspend(struct ata_port *ap, struct ata_device **r_failed_dev)
1869{
1870 struct ata_device *dev;
1871 int i, rc = 0;
1872
1873 DPRINTK("ENTER\n");
1874
1875 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1876 unsigned long flags;
1877 unsigned int action, err_mask;
1878
1879 dev = &ap->device[i];
1880 action = ata_eh_dev_action(dev);
1881
1882 if (!ata_dev_enabled(dev) || !(action & ATA_EH_SUSPEND))
1883 continue;
1884
1885 WARN_ON(dev->flags & ATA_DFLAG_SUSPENDED);
1886
1887 ata_eh_about_to_do(ap, dev, ATA_EH_SUSPEND);
1888
1889 if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1890 /* flush cache */
1891 rc = ata_flush_cache(dev);
1892 if (rc)
1893 break;
1894
1895 /* spin down */
1896 err_mask = ata_do_simple_cmd(dev, ATA_CMD_STANDBYNOW1);
1897 if (err_mask) {
1898 ata_dev_printk(dev, KERN_ERR, "failed to "
1899 "spin down (err_mask=0x%x)\n",
1900 err_mask);
1901 rc = -EIO;
1902 break;
1903 }
1904 }
1905
1906 spin_lock_irqsave(ap->lock, flags);
1907 dev->flags |= ATA_DFLAG_SUSPENDED;
1908 spin_unlock_irqrestore(ap->lock, flags);
1909
1910 ata_eh_done(ap, dev, ATA_EH_SUSPEND);
1911 }
1912
1913 if (rc)
1914 *r_failed_dev = dev;
1915
1916 DPRINTK("EXIT\n");
1917 return rc;
1918}
1919
1920/**
1921 * ata_eh_prep_resume - prep for resume EH action
1922 * @ap: target host port
1923 *
1924 * Clear SUSPENDED in preparation for scheduled resume actions.
1925 * This allows other parts of EH to access the devices being
1926 * resumed.
1927 *
1928 * LOCKING:
1929 * Kernel thread context (may sleep).
1930 */
1931static void ata_eh_prep_resume(struct ata_port *ap)
1932{
1933 struct ata_device *dev;
1934 unsigned long flags;
1935 int i;
1936
1937 DPRINTK("ENTER\n");
1938
1939 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1940 unsigned int action;
1941
1942 dev = &ap->device[i];
1943 action = ata_eh_dev_action(dev);
1944
1945 if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1946 continue;
1947
1948 spin_lock_irqsave(ap->lock, flags);
1949 dev->flags &= ~ATA_DFLAG_SUSPENDED;
1950 spin_unlock_irqrestore(ap->lock, flags);
1951 }
1952
1953 DPRINTK("EXIT\n");
1954}
1955
1956/**
1957 * ata_eh_resume - handle resume EH action
1958 * @ap: target host port
1959 * @r_failed_dev: result parameter to indicate failing device
1960 *
1961 * Handle resume EH action. Target devices are already reset and
1962 * revalidated. Spinning up is the only operation left.
1963 *
1964 * LOCKING:
1965 * Kernel thread context (may sleep).
1966 *
1967 * RETURNS:
1968 * 0 on success, -errno otherwise
1969 */
1970static int ata_eh_resume(struct ata_port *ap, struct ata_device **r_failed_dev)
1971{
1972 struct ata_device *dev;
1973 int i, rc = 0;
1974
1975 DPRINTK("ENTER\n");
1976
1977 for (i = 0; i < ATA_MAX_DEVICES; i++) {
1978 unsigned int action, err_mask;
1979
1980 dev = &ap->device[i];
1981 action = ata_eh_dev_action(dev);
1982
1983 if (!ata_dev_enabled(dev) || !(action & ATA_EH_RESUME))
1984 continue;
1985
1986 ata_eh_about_to_do(ap, dev, ATA_EH_RESUME);
1987
1988 if (dev->class == ATA_DEV_ATA && !(action & ATA_EH_PM_FREEZE)) {
1989 err_mask = ata_do_simple_cmd(dev,
1990 ATA_CMD_IDLEIMMEDIATE);
1991 if (err_mask) {
1992 ata_dev_printk(dev, KERN_ERR, "failed to "
1993 "spin up (err_mask=0x%x)\n",
1994 err_mask);
1995 rc = -EIO;
1996 break;
1997 }
1998 }
1999
2000 ata_eh_done(ap, dev, ATA_EH_RESUME);
2001 }
2002
2003 if (rc)
2004 *r_failed_dev = dev;
2005
2006 DPRINTK("EXIT\n");
2007 return 0;
2008}
2009#endif /* CONFIG_PM */
2010
2011static int ata_port_nr_enabled(struct ata_port *ap) 1861static int ata_port_nr_enabled(struct ata_port *ap)
2012{ 1862{
2013 int i, cnt = 0; 1863 int i, cnt = 0;
@@ -2033,17 +1883,6 @@ static int ata_eh_skip_recovery(struct ata_port *ap)
2033 struct ata_eh_context *ehc = &ap->eh_context; 1883 struct ata_eh_context *ehc = &ap->eh_context;
2034 int i; 1884 int i;
2035 1885
2036 /* skip if all possible devices are suspended */
2037 for (i = 0; i < ata_port_max_devices(ap); i++) {
2038 struct ata_device *dev = &ap->device[i];
2039
2040 if (!(dev->flags & ATA_DFLAG_SUSPENDED))
2041 break;
2042 }
2043
2044 if (i == ata_port_max_devices(ap))
2045 return 1;
2046
2047 /* thaw frozen port, resume link and recover failed devices */ 1886 /* thaw frozen port, resume link and recover failed devices */
2048 if ((ap->pflags & ATA_PFLAG_FROZEN) || 1887 if ((ap->pflags & ATA_PFLAG_FROZEN) ||
2049 (ehc->i.flags & ATA_EHI_RESUME_LINK) || ata_port_nr_enabled(ap)) 1888 (ehc->i.flags & ATA_EHI_RESUME_LINK) || ata_port_nr_enabled(ap))
@@ -2123,9 +1962,6 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2123 if (ap->pflags & ATA_PFLAG_UNLOADING) 1962 if (ap->pflags & ATA_PFLAG_UNLOADING)
2124 goto out; 1963 goto out;
2125 1964
2126 /* prep for resume */
2127 ata_eh_prep_resume(ap);
2128
2129 /* skip EH if possible. */ 1965 /* skip EH if possible. */
2130 if (ata_eh_skip_recovery(ap)) 1966 if (ata_eh_skip_recovery(ap))
2131 ehc->i.action = 0; 1967 ehc->i.action = 0;
@@ -2153,11 +1989,6 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2153 if (rc) 1989 if (rc)
2154 goto dev_fail; 1990 goto dev_fail;
2155 1991
2156 /* resume devices */
2157 rc = ata_eh_resume(ap, &dev);
2158 if (rc)
2159 goto dev_fail;
2160
2161 /* configure transfer mode if necessary */ 1992 /* configure transfer mode if necessary */
2162 if (ehc->i.flags & ATA_EHI_SETMODE) { 1993 if (ehc->i.flags & ATA_EHI_SETMODE) {
2163 rc = ata_set_mode(ap, &dev); 1994 rc = ata_set_mode(ap, &dev);
@@ -2166,25 +1997,16 @@ static int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
2166 ehc->i.flags &= ~ATA_EHI_SETMODE; 1997 ehc->i.flags &= ~ATA_EHI_SETMODE;
2167 } 1998 }
2168 1999
2169 /* suspend devices */
2170 rc = ata_eh_suspend(ap, &dev);
2171 if (rc)
2172 goto dev_fail;
2173
2174 goto out; 2000 goto out;
2175 2001
2176 dev_fail: 2002 dev_fail:
2177 ehc->tries[dev->devno]--; 2003 ehc->tries[dev->devno]--;
2178 2004
2179 switch (rc) { 2005 switch (rc) {
2180 case -EINVAL:
2181 /* eeek, something went very wrong, give up */
2182 ehc->tries[dev->devno] = 0;
2183 break;
2184
2185 case -ENODEV: 2006 case -ENODEV:
2186 /* device missing or wrong IDENTIFY data, schedule probing */ 2007 /* device missing or wrong IDENTIFY data, schedule probing */
2187 ehc->i.probe_mask |= (1 << dev->devno); 2008 ehc->i.probe_mask |= (1 << dev->devno);
2009 case -EINVAL:
2188 /* give it just one more chance */ 2010 /* give it just one more chance */
2189 ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1); 2011 ehc->tries[dev->devno] = min(ehc->tries[dev->devno], 1);
2190 case -EIO: 2012 case -EIO:
@@ -2366,22 +2188,13 @@ static void ata_eh_handle_port_suspend(struct ata_port *ap)
2366 * 2188 *
2367 * Resume @ap. 2189 * Resume @ap.
2368 * 2190 *
2369 * This function also waits upto one second until all devices
2370 * hanging off this port requests resume EH action. This is to
2371 * prevent invoking EH and thus reset multiple times on resume.
2372 *
2373 * On DPM resume, where some of devices might not be resumed
2374 * together, this may delay port resume upto one second, but such
2375 * DPM resumes are rare and 1 sec delay isn't too bad.
2376 *
2377 * LOCKING: 2191 * LOCKING:
2378 * Kernel thread context (may sleep). 2192 * Kernel thread context (may sleep).
2379 */ 2193 */
2380static void ata_eh_handle_port_resume(struct ata_port *ap) 2194static void ata_eh_handle_port_resume(struct ata_port *ap)
2381{ 2195{
2382 unsigned long timeout;
2383 unsigned long flags; 2196 unsigned long flags;
2384 int i, rc = 0; 2197 int rc = 0;
2385 2198
2386 /* are we resuming? */ 2199 /* are we resuming? */
2387 spin_lock_irqsave(ap->lock, flags); 2200 spin_lock_irqsave(ap->lock, flags);
@@ -2392,31 +2205,12 @@ static void ata_eh_handle_port_resume(struct ata_port *ap)
2392 } 2205 }
2393 spin_unlock_irqrestore(ap->lock, flags); 2206 spin_unlock_irqrestore(ap->lock, flags);
2394 2207
2395 /* spurious? */ 2208 WARN_ON(!(ap->pflags & ATA_PFLAG_SUSPENDED));
2396 if (!(ap->pflags & ATA_PFLAG_SUSPENDED))
2397 goto done;
2398 2209
2399 if (ap->ops->port_resume) 2210 if (ap->ops->port_resume)
2400 rc = ap->ops->port_resume(ap); 2211 rc = ap->ops->port_resume(ap);
2401 2212
2402 /* give devices time to request EH */ 2213 /* report result */
2403 timeout = jiffies + HZ; /* 1s max */
2404 while (1) {
2405 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2406 struct ata_device *dev = &ap->device[i];
2407 unsigned int action = ata_eh_dev_action(dev);
2408
2409 if ((dev->flags & ATA_DFLAG_SUSPENDED) &&
2410 !(action & ATA_EH_RESUME))
2411 break;
2412 }
2413
2414 if (i == ATA_MAX_DEVICES || time_after(jiffies, timeout))
2415 break;
2416 msleep(10);
2417 }
2418
2419 done:
2420 spin_lock_irqsave(ap->lock, flags); 2214 spin_lock_irqsave(ap->lock, flags);
2421 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED); 2215 ap->pflags &= ~(ATA_PFLAG_PM_PENDING | ATA_PFLAG_SUSPENDED);
2422 if (ap->pm_result) { 2216 if (ap->pm_result) {
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 9afba2ba489e..242c43eef807 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -510,133 +510,6 @@ static void ata_dump_status(unsigned id, struct ata_taskfile *tf)
510 } 510 }
511} 511}
512 512
513#ifdef CONFIG_PM
514/**
515 * ata_scsi_device_suspend - suspend ATA device associated with sdev
516 * @sdev: the SCSI device to suspend
517 * @mesg: target power management message
518 *
519 * Request suspend EH action on the ATA device associated with
520 * @sdev and wait for the operation to complete.
521 *
522 * LOCKING:
523 * Kernel thread context (may sleep).
524 *
525 * RETURNS:
526 * 0 on success, -errno otherwise.
527 */
528int ata_scsi_device_suspend(struct scsi_device *sdev, pm_message_t mesg)
529{
530 struct ata_port *ap = ata_shost_to_port(sdev->host);
531 struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
532 unsigned long flags;
533 unsigned int action;
534 int rc = 0;
535
536 if (!dev)
537 goto out;
538
539 spin_lock_irqsave(ap->lock, flags);
540
541 /* wait for the previous resume to complete */
542 while (dev->flags & ATA_DFLAG_SUSPENDED) {
543 spin_unlock_irqrestore(ap->lock, flags);
544 ata_port_wait_eh(ap);
545 spin_lock_irqsave(ap->lock, flags);
546 }
547
548 /* if @sdev is already detached, nothing to do */
549 if (sdev->sdev_state == SDEV_OFFLINE ||
550 sdev->sdev_state == SDEV_CANCEL || sdev->sdev_state == SDEV_DEL)
551 goto out_unlock;
552
553 /* request suspend */
554 action = ATA_EH_SUSPEND;
555 if (mesg.event != PM_EVENT_SUSPEND)
556 action |= ATA_EH_PM_FREEZE;
557 ap->eh_info.dev_action[dev->devno] |= action;
558 ap->eh_info.flags |= ATA_EHI_QUIET;
559 ata_port_schedule_eh(ap);
560
561 spin_unlock_irqrestore(ap->lock, flags);
562
563 /* wait for EH to do the job */
564 ata_port_wait_eh(ap);
565
566 spin_lock_irqsave(ap->lock, flags);
567
568 /* If @sdev is still attached but the associated ATA device
569 * isn't suspended, the operation failed.
570 */
571 if (sdev->sdev_state != SDEV_OFFLINE &&
572 sdev->sdev_state != SDEV_CANCEL && sdev->sdev_state != SDEV_DEL &&
573 !(dev->flags & ATA_DFLAG_SUSPENDED))
574 rc = -EIO;
575
576 out_unlock:
577 spin_unlock_irqrestore(ap->lock, flags);
578 out:
579 if (rc == 0)
580 sdev->sdev_gendev.power.power_state = mesg;
581 return rc;
582}
583
584/**
585 * ata_scsi_device_resume - resume ATA device associated with sdev
586 * @sdev: the SCSI device to resume
587 *
588 * Request resume EH action on the ATA device associated with
589 * @sdev and return immediately. This enables parallel
590 * wakeup/spinup of devices.
591 *
592 * LOCKING:
593 * Kernel thread context (may sleep).
594 *
595 * RETURNS:
596 * 0.
597 */
598int ata_scsi_device_resume(struct scsi_device *sdev)
599{
600 struct ata_port *ap = ata_shost_to_port(sdev->host);
601 struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
602 struct ata_eh_info *ehi = &ap->eh_info;
603 unsigned long flags;
604 unsigned int action;
605
606 if (!dev)
607 goto out;
608
609 spin_lock_irqsave(ap->lock, flags);
610
611 /* if @sdev is already detached, nothing to do */
612 if (sdev->sdev_state == SDEV_OFFLINE ||
613 sdev->sdev_state == SDEV_CANCEL || sdev->sdev_state == SDEV_DEL)
614 goto out_unlock;
615
616 /* request resume */
617 action = ATA_EH_RESUME;
618 if (sdev->sdev_gendev.power.power_state.event == PM_EVENT_SUSPEND)
619 __ata_ehi_hotplugged(ehi);
620 else
621 action |= ATA_EH_PM_FREEZE | ATA_EH_SOFTRESET;
622 ehi->dev_action[dev->devno] |= action;
623
624 /* We don't want autopsy and verbose EH messages. Disable
625 * those if we're the only device on this link.
626 */
627 if (ata_port_max_devices(ap) == 1)
628 ehi->flags |= ATA_EHI_NO_AUTOPSY | ATA_EHI_QUIET;
629
630 ata_port_schedule_eh(ap);
631
632 out_unlock:
633 spin_unlock_irqrestore(ap->lock, flags);
634 out:
635 sdev->sdev_gendev.power.power_state = PMSG_ON;
636 return 0;
637}
638#endif /* CONFIG_PM */
639
640/** 513/**
641 * ata_to_sense_error - convert ATA error to SCSI error 514 * ata_to_sense_error - convert ATA error to SCSI error
642 * @id: ATA device number 515 * @id: ATA device number
@@ -929,6 +802,8 @@ int ata_scsi_slave_config(struct scsi_device *sdev)
929 802
930 blk_queue_max_phys_segments(sdev->request_queue, LIBATA_MAX_PRD); 803 blk_queue_max_phys_segments(sdev->request_queue, LIBATA_MAX_PRD);
931 804
805 sdev->manage_start_stop = 1;
806
932 if (dev) 807 if (dev)
933 ata_scsi_dev_config(sdev, dev); 808 ata_scsi_dev_config(sdev, dev);
934 809
@@ -1018,6 +893,23 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
1018 return queue_depth; 893 return queue_depth;
1019} 894}
1020 895
896/* XXX: for spindown warning */
897static void ata_delayed_done_timerfn(unsigned long arg)
898{
899 struct scsi_cmnd *scmd = (void *)arg;
900
901 scmd->scsi_done(scmd);
902}
903
904/* XXX: for spindown warning */
905static void ata_delayed_done(struct scsi_cmnd *scmd)
906{
907 static struct timer_list timer;
908
909 setup_timer(&timer, ata_delayed_done_timerfn, (unsigned long)scmd);
910 mod_timer(&timer, jiffies + 5 * HZ);
911}
912
1021/** 913/**
1022 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command 914 * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command
1023 * @qc: Storage for translated ATA taskfile 915 * @qc: Storage for translated ATA taskfile
@@ -1069,9 +961,37 @@ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc)
1069 } 961 }
1070 962
1071 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */ 963 tf->command = ATA_CMD_VERIFY; /* READ VERIFY */
1072 } else 964 } else {
965 /* XXX: This is for backward compatibility, will be
966 * removed. Read Documentation/feature-removal-schedule.txt
967 * for more info.
968 */
969 if ((qc->dev->flags & ATA_DFLAG_SPUNDOWN) &&
970 (system_state == SYSTEM_HALT ||
971 system_state == SYSTEM_POWER_OFF)) {
972 static unsigned long warned = 0;
973
974 if (!test_and_set_bit(0, &warned)) {
975 ata_dev_printk(qc->dev, KERN_WARNING,
976 "DISK MIGHT NOT BE SPUN DOWN PROPERLY. "
977 "UPDATE SHUTDOWN UTILITY\n");
978 ata_dev_printk(qc->dev, KERN_WARNING,
979 "For more info, visit "
980 "http://linux-ata.org/shutdown.html\n");
981
982 /* ->scsi_done is not used, use it for
983 * delayed completion.
984 */
985 scmd->scsi_done = qc->scsidone;
986 qc->scsidone = ata_delayed_done;
987 }
988 scmd->result = SAM_STAT_GOOD;
989 return 1;
990 }
991
1073 /* Issue ATA STANDBY IMMEDIATE command */ 992 /* Issue ATA STANDBY IMMEDIATE command */
1074 tf->command = ATA_CMD_STANDBYNOW1; 993 tf->command = ATA_CMD_STANDBYNOW1;
994 }
1075 995
1076 /* 996 /*
1077 * Standby and Idle condition timers could be implemented but that 997 * Standby and Idle condition timers could be implemented but that
@@ -1474,6 +1394,14 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
1474 } 1394 }
1475 } 1395 }
1476 1396
1397 /* XXX: track spindown state for spindown skipping and warning */
1398 if (unlikely(qc->tf.command == ATA_CMD_STANDBY ||
1399 qc->tf.command == ATA_CMD_STANDBYNOW1))
1400 qc->dev->flags |= ATA_DFLAG_SPUNDOWN;
1401 else if (likely(system_state != SYSTEM_HALT &&
1402 system_state != SYSTEM_POWER_OFF))
1403 qc->dev->flags &= ~ATA_DFLAG_SPUNDOWN;
1404
1477 if (need_sense && !ap->ops->error_handler) 1405 if (need_sense && !ap->ops->error_handler)
1478 ata_dump_status(ap->print_id, &qc->result_tf); 1406 ata_dump_status(ap->print_id, &qc->result_tf);
1479 1407
@@ -1587,14 +1515,14 @@ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
1587 1515
1588early_finish: 1516early_finish:
1589 ata_qc_free(qc); 1517 ata_qc_free(qc);
1590 done(cmd); 1518 qc->scsidone(cmd);
1591 DPRINTK("EXIT - early finish (good or error)\n"); 1519 DPRINTK("EXIT - early finish (good or error)\n");
1592 return 0; 1520 return 0;
1593 1521
1594err_did: 1522err_did:
1595 ata_qc_free(qc); 1523 ata_qc_free(qc);
1596 cmd->result = (DID_ERROR << 16); 1524 cmd->result = (DID_ERROR << 16);
1597 done(cmd); 1525 qc->scsidone(cmd);
1598err_mem: 1526err_mem:
1599 DPRINTK("EXIT - internal\n"); 1527 DPRINTK("EXIT - internal\n");
1600 return 0; 1528 return 0;
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index d211db6b35a2..e35d13466c69 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -544,7 +544,7 @@ static int ata_resources_present(struct pci_dev *pdev, int port)
544 * RETURNS: 544 * RETURNS:
545 * 0 on success, -errno otherwise. 545 * 0 on success, -errno otherwise.
546 */ 546 */
547static int ata_pci_init_bmdma(struct ata_host *host) 547int ata_pci_init_bmdma(struct ata_host *host)
548{ 548{
549 struct device *gdev = host->dev; 549 struct device *gdev = host->dev;
550 struct pci_dev *pdev = to_pci_dev(gdev); 550 struct pci_dev *pdev = to_pci_dev(gdev);
@@ -566,7 +566,7 @@ static int ata_pci_init_bmdma(struct ata_host *host)
566 } 566 }
567 host->iomap = pcim_iomap_table(pdev); 567 host->iomap = pcim_iomap_table(pdev);
568 568
569 for (i = 0; i < host->n_ports; i++) { 569 for (i = 0; i < 2; i++) {
570 struct ata_port *ap = host->ports[i]; 570 struct ata_port *ap = host->ports[i];
571 void __iomem *bmdma = host->iomap[4] + 8 * i; 571 void __iomem *bmdma = host->iomap[4] + 8 * i;
572 572
@@ -585,54 +585,52 @@ static int ata_pci_init_bmdma(struct ata_host *host)
585/** 585/**
586 * ata_pci_init_native_host - acquire native ATA resources and init host 586 * ata_pci_init_native_host - acquire native ATA resources and init host
587 * @host: target ATA host 587 * @host: target ATA host
588 * @port_mask: ports to consider
589 * 588 *
590 * Acquire native PCI ATA resources for @host and initialize 589 * Acquire native PCI ATA resources for @host and initialize the
591 * @host accordoingly. 590 * first two ports of @host accordingly. Ports marked dummy are
591 * skipped and allocation failure makes the port dummy.
592 * 592 *
593 * LOCKING: 593 * LOCKING:
594 * Inherited from calling layer (may sleep). 594 * Inherited from calling layer (may sleep).
595 * 595 *
596 * RETURNS: 596 * RETURNS:
597 * 0 on success, -errno otherwise. 597 * 0 if at least one port is initialized, -ENODEV if no port is
598 * available.
598 */ 599 */
599int ata_pci_init_native_host(struct ata_host *host, unsigned int port_mask) 600int ata_pci_init_native_host(struct ata_host *host)
600{ 601{
601 struct device *gdev = host->dev; 602 struct device *gdev = host->dev;
602 struct pci_dev *pdev = to_pci_dev(gdev); 603 struct pci_dev *pdev = to_pci_dev(gdev);
604 unsigned int mask = 0;
603 int i, rc; 605 int i, rc;
604 606
605 /* Discard disabled ports. Some controllers show their unused
606 * channels this way. Disabled ports are made dummy.
607 */
608 for (i = 0; i < 2; i++) {
609 if ((port_mask & (1 << i)) && !ata_resources_present(pdev, i)) {
610 host->ports[i]->ops = &ata_dummy_port_ops;
611 port_mask &= ~(1 << i);
612 }
613 }
614
615 if (!port_mask) {
616 dev_printk(KERN_ERR, gdev, "no available port\n");
617 return -ENODEV;
618 }
619
620 /* request, iomap BARs and init port addresses accordingly */ 607 /* request, iomap BARs and init port addresses accordingly */
621 for (i = 0; i < 2; i++) { 608 for (i = 0; i < 2; i++) {
622 struct ata_port *ap = host->ports[i]; 609 struct ata_port *ap = host->ports[i];
623 int base = i * 2; 610 int base = i * 2;
624 void __iomem * const *iomap; 611 void __iomem * const *iomap;
625 612
626 if (!(port_mask & (1 << i))) 613 if (ata_port_is_dummy(ap))
614 continue;
615
616 /* Discard disabled ports. Some controllers show
617 * their unused channels this way. Disabled ports are
618 * made dummy.
619 */
620 if (!ata_resources_present(pdev, i)) {
621 ap->ops = &ata_dummy_port_ops;
627 continue; 622 continue;
623 }
628 624
629 rc = pcim_iomap_regions(pdev, 0x3 << base, DRV_NAME); 625 rc = pcim_iomap_regions(pdev, 0x3 << base, DRV_NAME);
630 if (rc) { 626 if (rc) {
631 dev_printk(KERN_ERR, gdev, "failed to request/iomap " 627 dev_printk(KERN_WARNING, gdev,
632 "BARs for port %d (errno=%d)\n", i, rc); 628 "failed to request/iomap BARs for port %d "
629 "(errno=%d)\n", i, rc);
633 if (rc == -EBUSY) 630 if (rc == -EBUSY)
634 pcim_pin_device(pdev); 631 pcim_pin_device(pdev);
635 return rc; 632 ap->ops = &ata_dummy_port_ops;
633 continue;
636 } 634 }
637 host->iomap = iomap = pcim_iomap_table(pdev); 635 host->iomap = iomap = pcim_iomap_table(pdev);
638 636
@@ -641,6 +639,13 @@ int ata_pci_init_native_host(struct ata_host *host, unsigned int port_mask)
641 ap->ioaddr.ctl_addr = (void __iomem *) 639 ap->ioaddr.ctl_addr = (void __iomem *)
642 ((unsigned long)iomap[base + 1] | ATA_PCI_CTL_OFS); 640 ((unsigned long)iomap[base + 1] | ATA_PCI_CTL_OFS);
643 ata_std_ports(&ap->ioaddr); 641 ata_std_ports(&ap->ioaddr);
642
643 mask |= 1 << i;
644 }
645
646 if (!mask) {
647 dev_printk(KERN_ERR, gdev, "no available native port\n");
648 return -ENODEV;
644 } 649 }
645 650
646 return 0; 651 return 0;
@@ -649,8 +654,7 @@ int ata_pci_init_native_host(struct ata_host *host, unsigned int port_mask)
649/** 654/**
650 * ata_pci_prepare_native_host - helper to prepare native PCI ATA host 655 * ata_pci_prepare_native_host - helper to prepare native PCI ATA host
651 * @pdev: target PCI device 656 * @pdev: target PCI device
652 * @ppi: array of port_info 657 * @ppi: array of port_info, must be enough for two ports
653 * @n_ports: number of ports to allocate
654 * @r_host: out argument for the initialized ATA host 658 * @r_host: out argument for the initialized ATA host
655 * 659 *
656 * Helper to allocate ATA host for @pdev, acquire all native PCI 660 * Helper to allocate ATA host for @pdev, acquire all native PCI
@@ -664,10 +668,9 @@ int ata_pci_init_native_host(struct ata_host *host, unsigned int port_mask)
664 */ 668 */
665int ata_pci_prepare_native_host(struct pci_dev *pdev, 669int ata_pci_prepare_native_host(struct pci_dev *pdev,
666 const struct ata_port_info * const * ppi, 670 const struct ata_port_info * const * ppi,
667 int n_ports, struct ata_host **r_host) 671 struct ata_host **r_host)
668{ 672{
669 struct ata_host *host; 673 struct ata_host *host;
670 unsigned int port_mask;
671 int rc; 674 int rc;
672 675
673 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) 676 if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL))
@@ -681,11 +684,7 @@ int ata_pci_prepare_native_host(struct pci_dev *pdev,
681 goto err_out; 684 goto err_out;
682 } 685 }
683 686
684 port_mask = ATA_PORT_PRIMARY; 687 rc = ata_pci_init_native_host(host);
685 if (n_ports > 1)
686 port_mask |= ATA_PORT_SECONDARY;
687
688 rc = ata_pci_init_native_host(host, port_mask);
689 if (rc) 688 if (rc)
690 goto err_out; 689 goto err_out;
691 690
@@ -777,8 +776,11 @@ static int ata_init_legacy_port(struct ata_port *ap,
777 /* iomap cmd and ctl ports */ 776 /* iomap cmd and ctl ports */
778 legacy_dr->cmd_addr[port_no] = ioport_map(cmd_port, 8); 777 legacy_dr->cmd_addr[port_no] = ioport_map(cmd_port, 8);
779 legacy_dr->ctl_addr[port_no] = ioport_map(ctl_port, 1); 778 legacy_dr->ctl_addr[port_no] = ioport_map(ctl_port, 1);
780 if (!legacy_dr->cmd_addr[port_no] || !legacy_dr->ctl_addr[port_no]) 779 if (!legacy_dr->cmd_addr[port_no] || !legacy_dr->ctl_addr[port_no]) {
780 dev_printk(KERN_WARNING, host->dev,
781 "failed to map cmd/ctl ports\n");
781 return -ENOMEM; 782 return -ENOMEM;
783 }
782 784
783 /* init IO addresses */ 785 /* init IO addresses */
784 ap->ioaddr.cmd_addr = legacy_dr->cmd_addr[port_no]; 786 ap->ioaddr.cmd_addr = legacy_dr->cmd_addr[port_no];
@@ -792,19 +794,20 @@ static int ata_init_legacy_port(struct ata_port *ap,
792/** 794/**
793 * ata_init_legacy_host - acquire legacy ATA resources and init ATA host 795 * ata_init_legacy_host - acquire legacy ATA resources and init ATA host
794 * @host: target ATA host 796 * @host: target ATA host
795 * @legacy_mask: out parameter, mask indicating ports is in legacy mode
796 * @was_busy: out parameter, indicates whether any port was busy 797 * @was_busy: out parameter, indicates whether any port was busy
797 * 798 *
798 * Acquire legacy ATA resources for ports. 799 * Acquire legacy ATA resources for the first two ports of @host
800 * and initialize it accordingly. Ports marked dummy are skipped
801 * and resource acquistion failure makes the port dummy.
799 * 802 *
800 * LOCKING: 803 * LOCKING:
801 * Inherited from calling layer (may sleep). 804 * Inherited from calling layer (may sleep).
802 * 805 *
803 * RETURNS: 806 * RETURNS:
804 * 0 on success, -errno otherwise. 807 * 0 if at least one port is initialized, -ENODEV if no port is
808 * available.
805 */ 809 */
806static int ata_init_legacy_host(struct ata_host *host, 810static int ata_init_legacy_host(struct ata_host *host, int *was_busy)
807 unsigned int *legacy_mask, int *was_busy)
808{ 811{
809 struct device *gdev = host->dev; 812 struct device *gdev = host->dev;
810 struct ata_legacy_devres *legacy_dr; 813 struct ata_legacy_devres *legacy_dr;
@@ -821,22 +824,23 @@ static int ata_init_legacy_host(struct ata_host *host,
821 devres_add(gdev, legacy_dr); 824 devres_add(gdev, legacy_dr);
822 825
823 for (i = 0; i < 2; i++) { 826 for (i = 0; i < 2; i++) {
824 *legacy_mask &= ~(1 << i); 827 if (ata_port_is_dummy(host->ports[i]))
828 continue;
829
825 rc = ata_init_legacy_port(host->ports[i], legacy_dr); 830 rc = ata_init_legacy_port(host->ports[i], legacy_dr);
826 if (rc == 0) 831 if (rc == 0)
827 legacy_dr->mask |= 1 << i; 832 legacy_dr->mask |= 1 << i;
828 else if (rc == -EBUSY) 833 else {
829 (*was_busy)++; 834 if (rc == -EBUSY)
830 } 835 (*was_busy)++;
831
832 if (!legacy_dr->mask)
833 return -EBUSY;
834
835 for (i = 0; i < 2; i++)
836 if (!(legacy_dr->mask & (1 << i)))
837 host->ports[i]->ops = &ata_dummy_port_ops; 836 host->ports[i]->ops = &ata_dummy_port_ops;
837 }
838 }
838 839
839 *legacy_mask |= legacy_dr->mask; 840 if (!legacy_dr->mask) {
841 dev_printk(KERN_ERR, gdev, "no available legacy port\n");
842 return -ENODEV;
843 }
840 844
841 devres_remove_group(gdev, NULL); 845 devres_remove_group(gdev, NULL);
842 return 0; 846 return 0;
@@ -875,7 +879,7 @@ static int ata_request_legacy_irqs(struct ata_host *host,
875 legacy_dr = devres_find(host->dev, ata_legacy_release, NULL, NULL); 879 legacy_dr = devres_find(host->dev, ata_legacy_release, NULL, NULL);
876 BUG_ON(!legacy_dr); 880 BUG_ON(!legacy_dr);
877 881
878 for (i = 0; i < host->n_ports; i++) { 882 for (i = 0; i < 2; i++) {
879 unsigned int irq; 883 unsigned int irq;
880 884
881 /* FIXME: ATA_*_IRQ() should take generic device not pci_dev */ 885 /* FIXME: ATA_*_IRQ() should take generic device not pci_dev */
@@ -923,8 +927,7 @@ static int ata_request_legacy_irqs(struct ata_host *host,
923/** 927/**
924 * ata_pci_init_one - Initialize/register PCI IDE host controller 928 * ata_pci_init_one - Initialize/register PCI IDE host controller
925 * @pdev: Controller to be initialized 929 * @pdev: Controller to be initialized
926 * @port_info: Information from low-level host driver 930 * @ppi: array of port_info, must be enough for two ports
927 * @n_ports: Number of ports attached to host controller
928 * 931 *
929 * This is a helper function which can be called from a driver's 932 * This is a helper function which can be called from a driver's
930 * xxx_init_one() probe function if the hardware uses traditional 933 * xxx_init_one() probe function if the hardware uses traditional
@@ -944,26 +947,34 @@ static int ata_request_legacy_irqs(struct ata_host *host,
944 * RETURNS: 947 * RETURNS:
945 * Zero on success, negative on errno-based value on error. 948 * Zero on success, negative on errno-based value on error.
946 */ 949 */
947 950int ata_pci_init_one(struct pci_dev *pdev,
948int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, 951 const struct ata_port_info * const * ppi)
949 unsigned int n_ports)
950{ 952{
951 struct device *dev = &pdev->dev; 953 struct device *dev = &pdev->dev;
954 const struct ata_port_info *pi = NULL;
952 struct ata_host *host = NULL; 955 struct ata_host *host = NULL;
953 const struct ata_port_info *port[2];
954 u8 mask; 956 u8 mask;
955 unsigned int legacy_mode = 0; 957 int legacy_mode = 0;
956 int rc; 958 int i, rc;
957 959
958 DPRINTK("ENTER\n"); 960 DPRINTK("ENTER\n");
959 961
960 if (!devres_open_group(dev, NULL, GFP_KERNEL)) 962 /* look up the first valid port_info */
961 return -ENOMEM; 963 for (i = 0; i < 2 && ppi[i]; i++) {
964 if (ppi[i]->port_ops != &ata_dummy_port_ops) {
965 pi = ppi[i];
966 break;
967 }
968 }
962 969
963 BUG_ON(n_ports < 1 || n_ports > 2); 970 if (!pi) {
971 dev_printk(KERN_ERR, &pdev->dev,
972 "no valid port_info specified\n");
973 return -EINVAL;
974 }
964 975
965 port[0] = port_info[0]; 976 if (!devres_open_group(dev, NULL, GFP_KERNEL))
966 port[1] = (n_ports > 1) ? port_info[1] : NULL; 977 return -ENOMEM;
967 978
968 /* FIXME: Really for ATA it isn't safe because the device may be 979 /* FIXME: Really for ATA it isn't safe because the device may be
969 multi-purpose and we want to leave it alone if it was already 980 multi-purpose and we want to leave it alone if it was already
@@ -984,7 +995,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
984 pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8); 995 pci_read_config_byte(pdev, PCI_CLASS_PROG, &tmp8);
985 mask = (1 << 2) | (1 << 0); 996 mask = (1 << 2) | (1 << 0);
986 if ((tmp8 & mask) != mask) 997 if ((tmp8 & mask) != mask)
987 legacy_mode = (1 << 3); 998 legacy_mode = 1;
988#if defined(CONFIG_NO_ATA_LEGACY) 999#if defined(CONFIG_NO_ATA_LEGACY)
989 /* Some platforms with PCI limits cannot address compat 1000 /* Some platforms with PCI limits cannot address compat
990 port space. In that case we punt if their firmware has 1001 port space. In that case we punt if their firmware has
@@ -998,7 +1009,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
998 } 1009 }
999 1010
1000 /* alloc and init host */ 1011 /* alloc and init host */
1001 host = ata_host_alloc_pinfo(dev, port, n_ports); 1012 host = ata_host_alloc_pinfo(dev, ppi, 2);
1002 if (!host) { 1013 if (!host) {
1003 dev_printk(KERN_ERR, &pdev->dev, 1014 dev_printk(KERN_ERR, &pdev->dev,
1004 "failed to allocate ATA host\n"); 1015 "failed to allocate ATA host\n");
@@ -1007,19 +1018,13 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1007 } 1018 }
1008 1019
1009 if (!legacy_mode) { 1020 if (!legacy_mode) {
1010 unsigned int port_mask; 1021 rc = ata_pci_init_native_host(host);
1011
1012 port_mask = ATA_PORT_PRIMARY;
1013 if (n_ports > 1)
1014 port_mask |= ATA_PORT_SECONDARY;
1015
1016 rc = ata_pci_init_native_host(host, port_mask);
1017 if (rc) 1022 if (rc)
1018 goto err_out; 1023 goto err_out;
1019 } else { 1024 } else {
1020 int was_busy = 0; 1025 int was_busy = 0;
1021 1026
1022 rc = ata_init_legacy_host(host, &legacy_mode, &was_busy); 1027 rc = ata_init_legacy_host(host, &was_busy);
1023 if (was_busy) 1028 if (was_busy)
1024 pcim_pin_device(pdev); 1029 pcim_pin_device(pdev);
1025 if (rc) 1030 if (rc)
@@ -1040,8 +1045,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1040 goto err_out; 1045 goto err_out;
1041 1046
1042 if (!legacy_mode) 1047 if (!legacy_mode)
1043 rc = devm_request_irq(dev, pdev->irq, 1048 rc = devm_request_irq(dev, pdev->irq, pi->port_ops->irq_handler,
1044 port_info[0]->port_ops->irq_handler,
1045 IRQF_SHARED, DRV_NAME, host); 1049 IRQF_SHARED, DRV_NAME, host);
1046 else { 1050 else {
1047 irq_handler_t handler[2] = { host->ops->irq_handler, 1051 irq_handler_t handler[2] = { host->ops->irq_handler,
@@ -1055,7 +1059,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1055 goto err_out; 1059 goto err_out;
1056 1060
1057 /* register */ 1061 /* register */
1058 rc = ata_host_register(host, port_info[0]->sht); 1062 rc = ata_host_register(host, pi->sht);
1059 if (rc) 1063 if (rc)
1060 goto err_out; 1064 goto err_out;
1061 1065
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 5f4d40cd3288..5e2466658420 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -75,7 +75,8 @@ extern unsigned ata_exec_internal_sg(struct ata_device *dev,
75extern unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd); 75extern unsigned int ata_do_simple_cmd(struct ata_device *dev, u8 cmd);
76extern int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class, 76extern int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
77 unsigned int flags, u16 *id); 77 unsigned int flags, u16 *id);
78extern int ata_dev_revalidate(struct ata_device *dev, unsigned int flags); 78extern int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags);
79extern int ata_dev_revalidate(struct ata_device *dev, unsigned int readid_flags);
79extern int ata_dev_configure(struct ata_device *dev); 80extern int ata_dev_configure(struct ata_device *dev);
80extern int sata_down_spd_limit(struct ata_port *ap); 81extern int sata_down_spd_limit(struct ata_port *ap);
81extern int sata_set_spd_needed(struct ata_port *ap); 82extern int sata_set_spd_needed(struct ata_port *ap);
@@ -96,15 +97,15 @@ extern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
96extern struct ata_port *ata_port_alloc(struct ata_host *host); 97extern struct ata_port *ata_port_alloc(struct ata_host *host);
97 98
98/* libata-acpi.c */ 99/* libata-acpi.c */
99#ifdef CONFIG_SATA_ACPI 100#ifdef CONFIG_ATA_ACPI
100extern int ata_acpi_exec_tfs(struct ata_port *ap); 101extern int ata_acpi_exec_tfs(struct ata_port *ap);
101extern int ata_acpi_push_id(struct ata_port *ap, unsigned int ix); 102extern int ata_acpi_push_id(struct ata_device *dev);
102#else 103#else
103static inline int ata_acpi_exec_tfs(struct ata_port *ap) 104static inline int ata_acpi_exec_tfs(struct ata_port *ap)
104{ 105{
105 return 0; 106 return 0;
106} 107}
107static inline int ata_acpi_push_id(struct ata_port *ap, unsigned int ix) 108static inline int ata_acpi_push_id(struct ata_device *dev)
108{ 109{
109 return 0; 110 return 0;
110} 111}
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index d40edebb510a..3c55a5ff74c7 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -291,10 +291,6 @@ static struct scsi_host_template ali_sht = {
291 .slave_configure = ata_scsi_slave_config, 291 .slave_configure = ata_scsi_slave_config,
292 .slave_destroy = ata_scsi_slave_destroy, 292 .slave_destroy = ata_scsi_slave_destroy,
293 .bios_param = ata_std_bios_param, 293 .bios_param = ata_std_bios_param,
294#ifdef CONFIG_PM
295 .resume = ata_scsi_device_resume,
296 .suspend = ata_scsi_device_suspend,
297#endif
298}; 294};
299 295
300/* 296/*
@@ -522,14 +518,14 @@ static void ali_init_chipset(struct pci_dev *pdev)
522 518
523static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 519static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
524{ 520{
525 static struct ata_port_info info_early = { 521 static const struct ata_port_info info_early = {
526 .sht = &ali_sht, 522 .sht = &ali_sht,
527 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 523 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
528 .pio_mask = 0x1f, 524 .pio_mask = 0x1f,
529 .port_ops = &ali_early_port_ops 525 .port_ops = &ali_early_port_ops
530 }; 526 };
531 /* Revision 0x20 added DMA */ 527 /* Revision 0x20 added DMA */
532 static struct ata_port_info info_20 = { 528 static const struct ata_port_info info_20 = {
533 .sht = &ali_sht, 529 .sht = &ali_sht,
534 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48, 530 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
535 .pio_mask = 0x1f, 531 .pio_mask = 0x1f,
@@ -537,7 +533,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
537 .port_ops = &ali_20_port_ops 533 .port_ops = &ali_20_port_ops
538 }; 534 };
539 /* Revision 0x20 with support logic added UDMA */ 535 /* Revision 0x20 with support logic added UDMA */
540 static struct ata_port_info info_20_udma = { 536 static const struct ata_port_info info_20_udma = {
541 .sht = &ali_sht, 537 .sht = &ali_sht,
542 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48, 538 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
543 .pio_mask = 0x1f, 539 .pio_mask = 0x1f,
@@ -546,7 +542,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
546 .port_ops = &ali_20_port_ops 542 .port_ops = &ali_20_port_ops
547 }; 543 };
548 /* Revision 0xC2 adds UDMA66 */ 544 /* Revision 0xC2 adds UDMA66 */
549 static struct ata_port_info info_c2 = { 545 static const struct ata_port_info info_c2 = {
550 .sht = &ali_sht, 546 .sht = &ali_sht,
551 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48, 547 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
552 .pio_mask = 0x1f, 548 .pio_mask = 0x1f,
@@ -555,7 +551,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
555 .port_ops = &ali_c2_port_ops 551 .port_ops = &ali_c2_port_ops
556 }; 552 };
557 /* Revision 0xC3 is UDMA100 */ 553 /* Revision 0xC3 is UDMA100 */
558 static struct ata_port_info info_c3 = { 554 static const struct ata_port_info info_c3 = {
559 .sht = &ali_sht, 555 .sht = &ali_sht,
560 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48, 556 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
561 .pio_mask = 0x1f, 557 .pio_mask = 0x1f,
@@ -564,7 +560,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
564 .port_ops = &ali_c2_port_ops 560 .port_ops = &ali_c2_port_ops
565 }; 561 };
566 /* Revision 0xC4 is UDMA133 */ 562 /* Revision 0xC4 is UDMA133 */
567 static struct ata_port_info info_c4 = { 563 static const struct ata_port_info info_c4 = {
568 .sht = &ali_sht, 564 .sht = &ali_sht,
569 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48, 565 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST | ATA_FLAG_PIO_LBA48,
570 .pio_mask = 0x1f, 566 .pio_mask = 0x1f,
@@ -573,7 +569,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
573 .port_ops = &ali_c2_port_ops 569 .port_ops = &ali_c2_port_ops
574 }; 570 };
575 /* Revision 0xC5 is UDMA133 with LBA48 DMA */ 571 /* Revision 0xC5 is UDMA133 with LBA48 DMA */
576 static struct ata_port_info info_c5 = { 572 static const struct ata_port_info info_c5 = {
577 .sht = &ali_sht, 573 .sht = &ali_sht,
578 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 574 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
579 .pio_mask = 0x1f, 575 .pio_mask = 0x1f,
@@ -582,7 +578,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
582 .port_ops = &ali_c5_port_ops 578 .port_ops = &ali_c5_port_ops
583 }; 579 };
584 580
585 static struct ata_port_info *port_info[2]; 581 const struct ata_port_info *ppi[] = { NULL, NULL };
586 u8 rev, tmp; 582 u8 rev, tmp;
587 struct pci_dev *isa_bridge; 583 struct pci_dev *isa_bridge;
588 584
@@ -594,17 +590,17 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
594 */ 590 */
595 591
596 if (rev < 0x20) { 592 if (rev < 0x20) {
597 port_info[0] = port_info[1] = &info_early; 593 ppi[0] = &info_early;
598 } else if (rev < 0xC2) { 594 } else if (rev < 0xC2) {
599 port_info[0] = port_info[1] = &info_20; 595 ppi[0] = &info_20;
600 } else if (rev == 0xC2) { 596 } else if (rev == 0xC2) {
601 port_info[0] = port_info[1] = &info_c2; 597 ppi[0] = &info_c2;
602 } else if (rev == 0xC3) { 598 } else if (rev == 0xC3) {
603 port_info[0] = port_info[1] = &info_c3; 599 ppi[0] = &info_c3;
604 } else if (rev == 0xC4) { 600 } else if (rev == 0xC4) {
605 port_info[0] = port_info[1] = &info_c4; 601 ppi[0] = &info_c4;
606 } else 602 } else
607 port_info[0] = port_info[1] = &info_c5; 603 ppi[0] = &info_c5;
608 604
609 ali_init_chipset(pdev); 605 ali_init_chipset(pdev);
610 606
@@ -613,10 +609,10 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
613 /* Are we paired with a UDMA capable chip */ 609 /* Are we paired with a UDMA capable chip */
614 pci_read_config_byte(isa_bridge, 0x5E, &tmp); 610 pci_read_config_byte(isa_bridge, 0x5E, &tmp);
615 if ((tmp & 0x1E) == 0x12) 611 if ((tmp & 0x1E) == 0x12)
616 port_info[0] = port_info[1] = &info_20_udma; 612 ppi[0] = &info_20_udma;
617 pci_dev_put(isa_bridge); 613 pci_dev_put(isa_bridge);
618 } 614 }
619 return ata_pci_init_one(pdev, port_info, 2); 615 return ata_pci_init_one(pdev, ppi);
620} 616}
621 617
622#ifdef CONFIG_PM 618#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index 536ee892ab72..b439351f1fd3 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -121,12 +121,13 @@ static void timing_setup(struct ata_port *ap, struct ata_device *adev, int offse
121/** 121/**
122 * amd_probe_init - perform reset handling 122 * amd_probe_init - perform reset handling
123 * @ap: ATA port 123 * @ap: ATA port
124 * @deadline: deadline jiffies for the operation
124 * 125 *
125 * Reset sequence checking enable bits to see which ports are 126 * Reset sequence checking enable bits to see which ports are
126 * active. 127 * active.
127 */ 128 */
128 129
129static int amd_pre_reset(struct ata_port *ap) 130static int amd_pre_reset(struct ata_port *ap, unsigned long deadline)
130{ 131{
131 static const struct pci_bits amd_enable_bits[] = { 132 static const struct pci_bits amd_enable_bits[] = {
132 { 0x40, 1, 0x02, 0x02 }, 133 { 0x40, 1, 0x02, 0x02 },
@@ -138,8 +139,7 @@ static int amd_pre_reset(struct ata_port *ap)
138 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no])) 139 if (!pci_test_config_bits(pdev, &amd_enable_bits[ap->port_no]))
139 return -ENOENT; 140 return -ENOENT;
140 141
141 return ata_std_prereset(ap); 142 return ata_std_prereset(ap, deadline);
142
143} 143}
144 144
145static void amd_error_handler(struct ata_port *ap) 145static void amd_error_handler(struct ata_port *ap)
@@ -227,7 +227,8 @@ static void amd133_set_dmamode(struct ata_port *ap, struct ata_device *adev)
227 * space for us. 227 * space for us.
228 */ 228 */
229 229
230static int nv_pre_reset(struct ata_port *ap) { 230static int nv_pre_reset(struct ata_port *ap, unsigned long deadline)
231{
231 static const struct pci_bits nv_enable_bits[] = { 232 static const struct pci_bits nv_enable_bits[] = {
232 { 0x50, 1, 0x02, 0x02 }, 233 { 0x50, 1, 0x02, 0x02 },
233 { 0x50, 1, 0x01, 0x01 } 234 { 0x50, 1, 0x01, 0x01 }
@@ -238,7 +239,7 @@ static int nv_pre_reset(struct ata_port *ap) {
238 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no])) 239 if (!pci_test_config_bits(pdev, &nv_enable_bits[ap->port_no]))
239 return -ENOENT; 240 return -ENOENT;
240 241
241 return ata_std_prereset(ap); 242 return ata_std_prereset(ap, deadline);
242} 243}
243 244
244static void nv_error_handler(struct ata_port *ap) 245static void nv_error_handler(struct ata_port *ap)
@@ -323,10 +324,6 @@ static struct scsi_host_template amd_sht = {
323 .slave_configure = ata_scsi_slave_config, 324 .slave_configure = ata_scsi_slave_config,
324 .slave_destroy = ata_scsi_slave_destroy, 325 .slave_destroy = ata_scsi_slave_destroy,
325 .bios_param = ata_std_bios_param, 326 .bios_param = ata_std_bios_param,
326#ifdef CONFIG_PM
327 .resume = ata_scsi_device_resume,
328 .suspend = ata_scsi_device_suspend,
329#endif
330}; 327};
331 328
332static struct ata_port_operations amd33_port_ops = { 329static struct ata_port_operations amd33_port_ops = {
@@ -541,7 +538,7 @@ static struct ata_port_operations nv133_port_ops = {
541 538
542static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 539static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
543{ 540{
544 static struct ata_port_info info[10] = { 541 static const struct ata_port_info info[10] = {
545 { /* 0: AMD 7401 */ 542 { /* 0: AMD 7401 */
546 .sht = &amd_sht, 543 .sht = &amd_sht,
547 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 544 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
@@ -623,7 +620,7 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
623 .port_ops = &amd100_port_ops 620 .port_ops = &amd100_port_ops
624 } 621 }
625 }; 622 };
626 static struct ata_port_info *port_info[2]; 623 const struct ata_port_info *ppi[] = { NULL, NULL };
627 static int printed_version; 624 static int printed_version;
628 int type = id->driver_data; 625 int type = id->driver_data;
629 u8 rev; 626 u8 rev;
@@ -655,9 +652,8 @@ static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
655 ata_pci_clear_simplex(pdev); 652 ata_pci_clear_simplex(pdev);
656 653
657 /* And fire it up */ 654 /* And fire it up */
658 655 ppi[0] = &info[type];
659 port_info[0] = port_info[1] = &info[type]; 656 return ata_pci_init_one(pdev, ppi);
660 return ata_pci_init_one(pdev, port_info, 2);
661} 657}
662 658
663#ifdef CONFIG_PM 659#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
index 00e9ec342db0..7b4810c171b7 100644
--- a/drivers/ata/pata_artop.c
+++ b/drivers/ata/pata_artop.c
@@ -28,7 +28,7 @@
28#include <linux/ata.h> 28#include <linux/ata.h>
29 29
30#define DRV_NAME "pata_artop" 30#define DRV_NAME "pata_artop"
31#define DRV_VERSION "0.4.2" 31#define DRV_VERSION "0.4.3"
32 32
33/* 33/*
34 * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we 34 * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we
@@ -39,7 +39,7 @@
39 39
40static int clock = 0; 40static int clock = 0;
41 41
42static int artop6210_pre_reset(struct ata_port *ap) 42static int artop6210_pre_reset(struct ata_port *ap, unsigned long deadline)
43{ 43{
44 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 44 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
45 const struct pci_bits artop_enable_bits[] = { 45 const struct pci_bits artop_enable_bits[] = {
@@ -49,7 +49,8 @@ static int artop6210_pre_reset(struct ata_port *ap)
49 49
50 if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) 50 if (!pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
51 return -ENOENT; 51 return -ENOENT;
52 return ata_std_prereset(ap); 52
53 return ata_std_prereset(ap, deadline);
53} 54}
54 55
55/** 56/**
@@ -70,12 +71,13 @@ static void artop6210_error_handler(struct ata_port *ap)
70/** 71/**
71 * artop6260_pre_reset - check for 40/80 pin 72 * artop6260_pre_reset - check for 40/80 pin
72 * @ap: Port 73 * @ap: Port
74 * @deadline: deadline jiffies for the operation
73 * 75 *
74 * The ARTOP hardware reports the cable detect bits in register 0x49. 76 * The ARTOP hardware reports the cable detect bits in register 0x49.
75 * Nothing complicated needed here. 77 * Nothing complicated needed here.
76 */ 78 */
77 79
78static int artop6260_pre_reset(struct ata_port *ap) 80static int artop6260_pre_reset(struct ata_port *ap, unsigned long deadline)
79{ 81{
80 static const struct pci_bits artop_enable_bits[] = { 82 static const struct pci_bits artop_enable_bits[] = {
81 { 0x4AU, 1U, 0x02UL, 0x02UL }, /* port 0 */ 83 { 0x4AU, 1U, 0x02UL, 0x02UL }, /* port 0 */
@@ -87,7 +89,8 @@ static int artop6260_pre_reset(struct ata_port *ap)
87 /* Odd numbered device ids are the units with enable bits (the -R cards) */ 89 /* Odd numbered device ids are the units with enable bits (the -R cards) */
88 if (pdev->device % 1 && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no])) 90 if (pdev->device % 1 && !pci_test_config_bits(pdev, &artop_enable_bits[ap->port_no]))
89 return -ENOENT; 91 return -ENOENT;
90 return ata_std_prereset(ap); 92
93 return ata_std_prereset(ap, deadline);
91} 94}
92 95
93/** 96/**
@@ -96,7 +99,7 @@ static int artop6260_pre_reset(struct ata_port *ap)
96 * 99 *
97 * Identify the cable type for the ARTOp interface in question 100 * Identify the cable type for the ARTOp interface in question
98 */ 101 */
99 102
100static int artop6260_cable_detect(struct ata_port *ap) 103static int artop6260_cable_detect(struct ata_port *ap)
101{ 104{
102 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 105 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
@@ -411,7 +414,7 @@ static const struct ata_port_operations artop6260_ops = {
411static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id) 414static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
412{ 415{
413 static int printed_version; 416 static int printed_version;
414 static struct ata_port_info info_6210 = { 417 static const struct ata_port_info info_6210 = {
415 .sht = &artop_sht, 418 .sht = &artop_sht,
416 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 419 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
417 .pio_mask = 0x1f, /* pio0-4 */ 420 .pio_mask = 0x1f, /* pio0-4 */
@@ -419,7 +422,7 @@ static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
419 .udma_mask = ATA_UDMA2, 422 .udma_mask = ATA_UDMA2,
420 .port_ops = &artop6210_ops, 423 .port_ops = &artop6210_ops,
421 }; 424 };
422 static struct ata_port_info info_626x = { 425 static const struct ata_port_info info_626x = {
423 .sht = &artop_sht, 426 .sht = &artop_sht,
424 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 427 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
425 .pio_mask = 0x1f, /* pio0-4 */ 428 .pio_mask = 0x1f, /* pio0-4 */
@@ -427,7 +430,7 @@ static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
427 .udma_mask = ATA_UDMA4, 430 .udma_mask = ATA_UDMA4,
428 .port_ops = &artop6260_ops, 431 .port_ops = &artop6260_ops,
429 }; 432 };
430 static struct ata_port_info info_626x_fast = { 433 static const struct ata_port_info info_626x_fast = {
431 .sht = &artop_sht, 434 .sht = &artop_sht,
432 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 435 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
433 .pio_mask = 0x1f, /* pio0-4 */ 436 .pio_mask = 0x1f, /* pio0-4 */
@@ -435,32 +438,30 @@ static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
435 .udma_mask = ATA_UDMA5, 438 .udma_mask = ATA_UDMA5,
436 .port_ops = &artop6260_ops, 439 .port_ops = &artop6260_ops,
437 }; 440 };
438 struct ata_port_info *port_info[2]; 441 const struct ata_port_info *ppi[] = { NULL, NULL };
439 struct ata_port_info *info = NULL;
440 int ports = 2;
441 442
442 if (!printed_version++) 443 if (!printed_version++)
443 dev_printk(KERN_DEBUG, &pdev->dev, 444 dev_printk(KERN_DEBUG, &pdev->dev,
444 "version " DRV_VERSION "\n"); 445 "version " DRV_VERSION "\n");
445 446
446 if (id->driver_data == 0) { /* 6210 variant */ 447 if (id->driver_data == 0) { /* 6210 variant */
447 info = &info_6210; 448 ppi[0] = &info_6210;
449 ppi[1] = &ata_dummy_port_info;
448 /* BIOS may have left us in UDMA, clear it before libata probe */ 450 /* BIOS may have left us in UDMA, clear it before libata probe */
449 pci_write_config_byte(pdev, 0x54, 0); 451 pci_write_config_byte(pdev, 0x54, 0);
450 /* For the moment (also lacks dsc) */ 452 /* For the moment (also lacks dsc) */
451 printk(KERN_WARNING "ARTOP 6210 requires serialize functionality not yet supported by libata.\n"); 453 printk(KERN_WARNING "ARTOP 6210 requires serialize functionality not yet supported by libata.\n");
452 printk(KERN_WARNING "Secondary ATA ports will not be activated.\n"); 454 printk(KERN_WARNING "Secondary ATA ports will not be activated.\n");
453 ports = 1;
454 } 455 }
455 else if (id->driver_data == 1) /* 6260 */ 456 else if (id->driver_data == 1) /* 6260 */
456 info = &info_626x; 457 ppi[0] = &info_626x;
457 else if (id->driver_data == 2) { /* 6260 or 6260 + fast */ 458 else if (id->driver_data == 2) { /* 6260 or 6260 + fast */
458 unsigned long io = pci_resource_start(pdev, 4); 459 unsigned long io = pci_resource_start(pdev, 4);
459 u8 reg; 460 u8 reg;
460 461
461 info = &info_626x; 462 ppi[0] = &info_626x;
462 if (inb(io) & 0x10) 463 if (inb(io) & 0x10)
463 info = &info_626x_fast; 464 ppi[0] = &info_626x_fast;
464 /* Mac systems come up with some registers not set as we 465 /* Mac systems come up with some registers not set as we
465 will need them */ 466 will need them */
466 467
@@ -481,10 +482,9 @@ static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
481 482
482 } 483 }
483 484
484 BUG_ON(info == NULL); 485 BUG_ON(ppi[0] == NULL);
485 486
486 port_info[0] = port_info[1] = info; 487 return ata_pci_init_one(pdev, ppi);
487 return ata_pci_init_one(pdev, port_info, ports);
488} 488}
489 489
490static const struct pci_device_id artop_pci_tbl[] = { 490static const struct pci_device_id artop_pci_tbl[] = {
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index 39c871a3ddac..844914681a2a 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -33,7 +33,7 @@ enum {
33 ATIIXP_IDE_UDMA_MODE = 0x56 33 ATIIXP_IDE_UDMA_MODE = 0x56
34}; 34};
35 35
36static int atiixp_pre_reset(struct ata_port *ap) 36static int atiixp_pre_reset(struct ata_port *ap, unsigned long deadline)
37{ 37{
38 static const struct pci_bits atiixp_enable_bits[] = { 38 static const struct pci_bits atiixp_enable_bits[] = {
39 { 0x48, 1, 0x01, 0x00 }, 39 { 0x48, 1, 0x01, 0x00 },
@@ -44,7 +44,7 @@ static int atiixp_pre_reset(struct ata_port *ap)
44 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no])) 44 if (!pci_test_config_bits(pdev, &atiixp_enable_bits[ap->port_no]))
45 return -ENOENT; 45 return -ENOENT;
46 46
47 return ata_std_prereset(ap); 47 return ata_std_prereset(ap, deadline);
48} 48}
49 49
50static void atiixp_error_handler(struct ata_port *ap) 50static void atiixp_error_handler(struct ata_port *ap)
@@ -229,10 +229,6 @@ static struct scsi_host_template atiixp_sht = {
229 .slave_configure = ata_scsi_slave_config, 229 .slave_configure = ata_scsi_slave_config,
230 .slave_destroy = ata_scsi_slave_destroy, 230 .slave_destroy = ata_scsi_slave_destroy,
231 .bios_param = ata_std_bios_param, 231 .bios_param = ata_std_bios_param,
232#ifdef CONFIG_PM
233 .resume = ata_scsi_device_resume,
234 .suspend = ata_scsi_device_suspend,
235#endif
236}; 232};
237 233
238static struct ata_port_operations atiixp_port_ops = { 234static struct ata_port_operations atiixp_port_ops = {
@@ -272,7 +268,7 @@ static struct ata_port_operations atiixp_port_ops = {
272 268
273static int atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id) 269static int atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id)
274{ 270{
275 static struct ata_port_info info = { 271 static const struct ata_port_info info = {
276 .sht = &atiixp_sht, 272 .sht = &atiixp_sht,
277 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 273 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
278 .pio_mask = 0x1f, 274 .pio_mask = 0x1f,
@@ -280,8 +276,8 @@ static int atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id)
280 .udma_mask = 0x3F, 276 .udma_mask = 0x3F,
281 .port_ops = &atiixp_port_ops 277 .port_ops = &atiixp_port_ops
282 }; 278 };
283 static struct ata_port_info *port_info[2] = { &info, &info }; 279 const struct ata_port_info *ppi[] = { &info, NULL };
284 return ata_pci_init_one(dev, port_info, 2); 280 return ata_pci_init_one(dev, ppi);
285} 281}
286 282
287static const struct pci_device_id atiixp[] = { 283static const struct pci_device_id atiixp[] = {
diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
index 2105985a8013..31cbf8daa299 100644
--- a/drivers/ata/pata_cmd640.c
+++ b/drivers/ata/pata_cmd640.c
@@ -107,7 +107,7 @@ static void cmd640_set_piomode(struct ata_port *ap, struct ata_device *adev)
107 pci_write_config_byte(pdev, arttim + 1, (t.active << 4) | t.recover); 107 pci_write_config_byte(pdev, arttim + 1, (t.active << 4) | t.recover);
108 } else { 108 } else {
109 /* Save the shared timings for channel, they will be loaded 109 /* Save the shared timings for channel, they will be loaded
110 by qc_issue_prot. Reloading the setup time is expensive 110 by qc_issue_prot. Reloading the setup time is expensive
111 so we keep a merged one loaded */ 111 so we keep a merged one loaded */
112 pci_read_config_byte(pdev, ARTIM23, &reg); 112 pci_read_config_byte(pdev, ARTIM23, &reg);
113 reg &= 0x3F; 113 reg &= 0x3F;
@@ -181,10 +181,6 @@ static struct scsi_host_template cmd640_sht = {
181 .slave_configure = ata_scsi_slave_config, 181 .slave_configure = ata_scsi_slave_config,
182 .slave_destroy = ata_scsi_slave_destroy, 182 .slave_destroy = ata_scsi_slave_destroy,
183 .bios_param = ata_std_bios_param, 183 .bios_param = ata_std_bios_param,
184#ifdef CONFIG_PM
185 .resume = ata_scsi_device_resume,
186 .suspend = ata_scsi_device_suspend,
187#endif
188}; 184};
189 185
190static struct ata_port_operations cmd640_port_ops = { 186static struct ata_port_operations cmd640_port_ops = {
@@ -235,7 +231,7 @@ static void cmd640_hardware_init(struct pci_dev *pdev)
235 pci_write_config_byte(pdev, CMDTIM, 0); 231 pci_write_config_byte(pdev, CMDTIM, 0);
236 /* 512 byte bursts (sector) */ 232 /* 512 byte bursts (sector) */
237 pci_write_config_byte(pdev, BRST, 0x40); 233 pci_write_config_byte(pdev, BRST, 0x40);
238 /* 234 /*
239 * A reporter a long time ago 235 * A reporter a long time ago
240 * Had problems with the data fifo 236 * Had problems with the data fifo
241 * So don't run the risk 237 * So don't run the risk
@@ -253,17 +249,16 @@ static void cmd640_hardware_init(struct pci_dev *pdev)
253 249
254static int cmd640_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 250static int cmd640_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
255{ 251{
256 static struct ata_port_info info = { 252 static const struct ata_port_info info = {
257 .sht = &cmd640_sht, 253 .sht = &cmd640_sht,
258 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 254 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
259 .pio_mask = 0x1f, 255 .pio_mask = 0x1f,
260 .port_ops = &cmd640_port_ops 256 .port_ops = &cmd640_port_ops
261 }; 257 };
262 258 const struct ata_port_info *ppi[] = { &info, NULL };
263 static struct ata_port_info *port_info[2] = { &info, &info };
264 259
265 cmd640_hardware_init(pdev); 260 cmd640_hardware_init(pdev);
266 return ata_pci_init_one(pdev, port_info, 2); 261 return ata_pci_init_one(pdev, ppi);
267} 262}
268 263
269static int cmd640_reinit_one(struct pci_dev *pdev) 264static int cmd640_reinit_one(struct pci_dev *pdev)
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index 3989cc577fcd..320a5b10aa98 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -31,7 +31,7 @@
31#include <linux/libata.h> 31#include <linux/libata.h>
32 32
33#define DRV_NAME "pata_cmd64x" 33#define DRV_NAME "pata_cmd64x"
34#define DRV_VERSION "0.2.2" 34#define DRV_VERSION "0.2.3"
35 35
36/* 36/*
37 * CMD64x specific registers definition. 37 * CMD64x specific registers definition.
@@ -266,10 +266,6 @@ static struct scsi_host_template cmd64x_sht = {
266 .slave_configure = ata_scsi_slave_config, 266 .slave_configure = ata_scsi_slave_config,
267 .slave_destroy = ata_scsi_slave_destroy, 267 .slave_destroy = ata_scsi_slave_destroy,
268 .bios_param = ata_std_bios_param, 268 .bios_param = ata_std_bios_param,
269#ifdef CONFIG_PM
270 .resume = ata_scsi_device_resume,
271 .suspend = ata_scsi_device_suspend,
272#endif
273}; 269};
274 270
275static struct ata_port_operations cmd64x_port_ops = { 271static struct ata_port_operations cmd64x_port_ops = {
@@ -381,7 +377,7 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
381{ 377{
382 u32 class_rev; 378 u32 class_rev;
383 379
384 static struct ata_port_info cmd_info[6] = { 380 static const struct ata_port_info cmd_info[6] = {
385 { /* CMD 643 - no UDMA */ 381 { /* CMD 643 - no UDMA */
386 .sht = &cmd64x_sht, 382 .sht = &cmd64x_sht,
387 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 383 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
@@ -428,11 +424,9 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
428 .port_ops = &cmd648_port_ops 424 .port_ops = &cmd648_port_ops
429 } 425 }
430 }; 426 };
431 static struct ata_port_info *port_info[2], *info; 427 const struct ata_port_info *ppi[] = { &cmd_info[id->driver_data], NULL };
432 u8 mrdmode; 428 u8 mrdmode;
433 429
434 info = &cmd_info[id->driver_data];
435
436 pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class_rev); 430 pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class_rev);
437 class_rev &= 0xFF; 431 class_rev &= 0xFF;
438 432
@@ -442,10 +436,10 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
442 if (pdev->device == PCI_DEVICE_ID_CMD_646) { 436 if (pdev->device == PCI_DEVICE_ID_CMD_646) {
443 /* Does UDMA work ? */ 437 /* Does UDMA work ? */
444 if (class_rev > 4) 438 if (class_rev > 4)
445 info = &cmd_info[2]; 439 ppi[0] = &cmd_info[2];
446 /* Early rev with other problems ? */ 440 /* Early rev with other problems ? */
447 else if (class_rev == 1) 441 else if (class_rev == 1)
448 info = &cmd_info[3]; 442 ppi[0] = &cmd_info[3];
449 } 443 }
450 444
451 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 64); 445 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 64);
@@ -461,8 +455,7 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
461 pci_write_config_byte(pdev, UDIDETCR0, 0xF0); 455 pci_write_config_byte(pdev, UDIDETCR0, 0xF0);
462#endif 456#endif
463 457
464 port_info[0] = port_info[1] = info; 458 return ata_pci_init_one(pdev, ppi);
465 return ata_pci_init_one(pdev, port_info, 2);
466} 459}
467 460
468#ifdef CONFIG_PM 461#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index 79bef0d1fad3..1aabe15ad9d3 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -41,7 +41,7 @@
41#include <linux/libata.h> 41#include <linux/libata.h>
42 42
43#define DRV_NAME "pata_cs5520" 43#define DRV_NAME "pata_cs5520"
44#define DRV_VERSION "0.6.4" 44#define DRV_VERSION "0.6.5"
45 45
46struct pio_clocks 46struct pio_clocks
47{ 47{
@@ -155,10 +155,6 @@ static struct scsi_host_template cs5520_sht = {
155 .slave_configure = ata_scsi_slave_config, 155 .slave_configure = ata_scsi_slave_config,
156 .slave_destroy = ata_scsi_slave_destroy, 156 .slave_destroy = ata_scsi_slave_destroy,
157 .bios_param = ata_std_bios_param, 157 .bios_param = ata_std_bios_param,
158#ifdef CONFIG_PM
159 .resume = ata_scsi_device_resume,
160 .suspend = ata_scsi_device_suspend,
161#endif
162}; 158};
163 159
164static struct ata_port_operations cs5520_port_ops = { 160static struct ata_port_operations cs5520_port_ops = {
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index 29642d5ee189..848f0309bf03 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -35,7 +35,7 @@
35#include <linux/dmi.h> 35#include <linux/dmi.h>
36 36
37#define DRV_NAME "pata_cs5530" 37#define DRV_NAME "pata_cs5530"
38#define DRV_VERSION "0.7.2" 38#define DRV_VERSION "0.7.3"
39 39
40static void __iomem *cs5530_port_base(struct ata_port *ap) 40static void __iomem *cs5530_port_base(struct ata_port *ap)
41{ 41{
@@ -176,10 +176,6 @@ static struct scsi_host_template cs5530_sht = {
176 .slave_configure = ata_scsi_slave_config, 176 .slave_configure = ata_scsi_slave_config,
177 .slave_destroy = ata_scsi_slave_destroy, 177 .slave_destroy = ata_scsi_slave_destroy,
178 .bios_param = ata_std_bios_param, 178 .bios_param = ata_std_bios_param,
179#ifdef CONFIG_PM
180 .resume = ata_scsi_device_resume,
181 .suspend = ata_scsi_device_suspend,
182#endif
183}; 179};
184 180
185static struct ata_port_operations cs5530_port_ops = { 181static struct ata_port_operations cs5530_port_ops = {
@@ -339,7 +335,7 @@ fail_put:
339 335
340static int cs5530_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 336static int cs5530_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
341{ 337{
342 static struct ata_port_info info = { 338 static const struct ata_port_info info = {
343 .sht = &cs5530_sht, 339 .sht = &cs5530_sht,
344 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 340 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
345 .pio_mask = 0x1f, 341 .pio_mask = 0x1f,
@@ -348,23 +344,23 @@ static int cs5530_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
348 .port_ops = &cs5530_port_ops 344 .port_ops = &cs5530_port_ops
349 }; 345 };
350 /* The docking connector doesn't do UDMA, and it seems not MWDMA */ 346 /* The docking connector doesn't do UDMA, and it seems not MWDMA */
351 static struct ata_port_info info_palmax_secondary = { 347 static const struct ata_port_info info_palmax_secondary = {
352 .sht = &cs5530_sht, 348 .sht = &cs5530_sht,
353 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 349 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
354 .pio_mask = 0x1f, 350 .pio_mask = 0x1f,
355 .port_ops = &cs5530_port_ops 351 .port_ops = &cs5530_port_ops
356 }; 352 };
357 static struct ata_port_info *port_info[2] = { &info, &info }; 353 const struct ata_port_info *ppi[] = { &info, NULL };
358 354
359 /* Chip initialisation */ 355 /* Chip initialisation */
360 if (cs5530_init_chip()) 356 if (cs5530_init_chip())
361 return -ENODEV; 357 return -ENODEV;
362 358
363 if (cs5530_is_palmax()) 359 if (cs5530_is_palmax())
364 port_info[1] = &info_palmax_secondary; 360 ppi[1] = &info_palmax_secondary;
365 361
366 /* Now kick off ATA set up */ 362 /* Now kick off ATA set up */
367 return ata_pci_init_one(pdev, port_info, 2); 363 return ata_pci_init_one(pdev, ppi);
368} 364}
369 365
370#ifdef CONFIG_PM 366#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
index 08cccc9c659b..aa3256fb9f7a 100644
--- a/drivers/ata/pata_cs5535.c
+++ b/drivers/ata/pata_cs5535.c
@@ -39,7 +39,7 @@
39#include <asm/msr.h> 39#include <asm/msr.h>
40 40
41#define DRV_NAME "cs5535" 41#define DRV_NAME "cs5535"
42#define DRV_VERSION "0.2.11" 42#define DRV_VERSION "0.2.12"
43 43
44/* 44/*
45 * The Geode (Aka Athlon GX now) uses an internal MSR based 45 * The Geode (Aka Athlon GX now) uses an internal MSR based
@@ -72,6 +72,7 @@
72/** 72/**
73 * cs5535_cable_detect - detect cable type 73 * cs5535_cable_detect - detect cable type
74 * @ap: Port to detect on 74 * @ap: Port to detect on
75 * @deadline: deadline jiffies for the operation
75 * 76 *
76 * Perform cable detection for ATA66 capable cable. Return a libata 77 * Perform cable detection for ATA66 capable cable. Return a libata
77 * cable type. 78 * cable type.
@@ -172,10 +173,6 @@ static struct scsi_host_template cs5535_sht = {
172 .slave_configure = ata_scsi_slave_config, 173 .slave_configure = ata_scsi_slave_config,
173 .slave_destroy = ata_scsi_slave_destroy, 174 .slave_destroy = ata_scsi_slave_destroy,
174 .bios_param = ata_std_bios_param, 175 .bios_param = ata_std_bios_param,
175#ifdef CONFIG_PM
176 .resume = ata_scsi_device_resume,
177 .suspend = ata_scsi_device_suspend,
178#endif
179}; 176};
180 177
181static struct ata_port_operations cs5535_port_ops = { 178static struct ata_port_operations cs5535_port_ops = {
@@ -226,7 +223,7 @@ static struct ata_port_operations cs5535_port_ops = {
226 223
227static int cs5535_init_one(struct pci_dev *dev, const struct pci_device_id *id) 224static int cs5535_init_one(struct pci_dev *dev, const struct pci_device_id *id)
228{ 225{
229 static struct ata_port_info info = { 226 static const struct ata_port_info info = {
230 .sht = &cs5535_sht, 227 .sht = &cs5535_sht,
231 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 228 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
232 .pio_mask = 0x1f, 229 .pio_mask = 0x1f,
@@ -234,7 +231,7 @@ static int cs5535_init_one(struct pci_dev *dev, const struct pci_device_id *id)
234 .udma_mask = 0x1f, 231 .udma_mask = 0x1f,
235 .port_ops = &cs5535_port_ops 232 .port_ops = &cs5535_port_ops
236 }; 233 };
237 struct ata_port_info *ports[1] = { &info }; 234 const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
238 235
239 u32 timings, dummy; 236 u32 timings, dummy;
240 237
@@ -246,7 +243,7 @@ static int cs5535_init_one(struct pci_dev *dev, const struct pci_device_id *id)
246 rdmsr(ATAC_CH0D1_PIO, timings, dummy); 243 rdmsr(ATAC_CH0D1_PIO, timings, dummy);
247 if (CS5535_BAD_PIO(timings)) 244 if (CS5535_BAD_PIO(timings))
248 wrmsr(ATAC_CH0D1_PIO, 0xF7F4F7F4UL, 0); 245 wrmsr(ATAC_CH0D1_PIO, 0xF7F4F7F4UL, 0);
249 return ata_pci_init_one(dev, ports, 1); 246 return ata_pci_init_one(dev, ppi);
250} 247}
251 248
252static const struct pci_device_id cs5535[] = { 249static const struct pci_device_id cs5535[] = {
diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
index 6ec049c3b1dc..d41a7691dd8e 100644
--- a/drivers/ata/pata_cypress.c
+++ b/drivers/ata/pata_cypress.c
@@ -18,7 +18,7 @@
18#include <linux/libata.h> 18#include <linux/libata.h>
19 19
20#define DRV_NAME "pata_cypress" 20#define DRV_NAME "pata_cypress"
21#define DRV_VERSION "0.1.4" 21#define DRV_VERSION "0.1.5"
22 22
23/* here are the offset definitions for the registers */ 23/* here are the offset definitions for the registers */
24 24
@@ -125,10 +125,6 @@ static struct scsi_host_template cy82c693_sht = {
125 .slave_configure = ata_scsi_slave_config, 125 .slave_configure = ata_scsi_slave_config,
126 .slave_destroy = ata_scsi_slave_destroy, 126 .slave_destroy = ata_scsi_slave_destroy,
127 .bios_param = ata_std_bios_param, 127 .bios_param = ata_std_bios_param,
128#ifdef CONFIG_PM
129 .resume = ata_scsi_device_resume,
130 .suspend = ata_scsi_device_suspend,
131#endif
132}; 128};
133 129
134static struct ata_port_operations cy82c693_port_ops = { 130static struct ata_port_operations cy82c693_port_ops = {
@@ -169,14 +165,14 @@ static struct ata_port_operations cy82c693_port_ops = {
169 165
170static int cy82c693_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 166static int cy82c693_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
171{ 167{
172 static struct ata_port_info info = { 168 static const struct ata_port_info info = {
173 .sht = &cy82c693_sht, 169 .sht = &cy82c693_sht,
174 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 170 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
175 .pio_mask = 0x1f, 171 .pio_mask = 0x1f,
176 .mwdma_mask = 0x07, 172 .mwdma_mask = 0x07,
177 .port_ops = &cy82c693_port_ops 173 .port_ops = &cy82c693_port_ops
178 }; 174 };
179 static struct ata_port_info *port_info[1] = { &info }; 175 const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
180 176
181 /* Devfn 1 is the ATA primary. The secondary is magic and on devfn2. 177 /* Devfn 1 is the ATA primary. The secondary is magic and on devfn2.
182 For the moment we don't handle the secondary. FIXME */ 178 For the moment we don't handle the secondary. FIXME */
@@ -184,7 +180,7 @@ static int cy82c693_init_one(struct pci_dev *pdev, const struct pci_device_id *i
184 if (PCI_FUNC(pdev->devfn) != 1) 180 if (PCI_FUNC(pdev->devfn) != 1)
185 return -ENODEV; 181 return -ENODEV;
186 182
187 return ata_pci_init_one(pdev, port_info, 1); 183 return ata_pci_init_one(pdev, ppi);
188} 184}
189 185
190static const struct pci_device_id cy82c693[] = { 186static const struct pci_device_id cy82c693[] = {
diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
index a3216850bba1..079248a9b460 100644
--- a/drivers/ata/pata_efar.c
+++ b/drivers/ata/pata_efar.c
@@ -27,12 +27,13 @@
27/** 27/**
28 * efar_pre_reset - Enable bits 28 * efar_pre_reset - Enable bits
29 * @ap: Port 29 * @ap: Port
30 * @deadline: deadline jiffies for the operation
30 * 31 *
31 * Perform cable detection for the EFAR ATA interface. This is 32 * Perform cable detection for the EFAR ATA interface. This is
32 * different to the PIIX arrangement 33 * different to the PIIX arrangement
33 */ 34 */
34 35
35static int efar_pre_reset(struct ata_port *ap) 36static int efar_pre_reset(struct ata_port *ap, unsigned long deadline)
36{ 37{
37 static const struct pci_bits efar_enable_bits[] = { 38 static const struct pci_bits efar_enable_bits[] = {
38 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */ 39 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
@@ -43,7 +44,7 @@ static int efar_pre_reset(struct ata_port *ap)
43 if (!pci_test_config_bits(pdev, &efar_enable_bits[ap->port_no])) 44 if (!pci_test_config_bits(pdev, &efar_enable_bits[ap->port_no]))
44 return -ENOENT; 45 return -ENOENT;
45 46
46 return ata_std_prereset(ap); 47 return ata_std_prereset(ap, deadline);
47} 48}
48 49
49/** 50/**
@@ -246,10 +247,6 @@ static struct scsi_host_template efar_sht = {
246 .slave_configure = ata_scsi_slave_config, 247 .slave_configure = ata_scsi_slave_config,
247 .slave_destroy = ata_scsi_slave_destroy, 248 .slave_destroy = ata_scsi_slave_destroy,
248 .bios_param = ata_std_bios_param, 249 .bios_param = ata_std_bios_param,
249#ifdef CONFIG_PM
250 .resume = ata_scsi_device_resume,
251 .suspend = ata_scsi_device_suspend,
252#endif
253}; 250};
254 251
255static const struct ata_port_operations efar_ops = { 252static const struct ata_port_operations efar_ops = {
@@ -304,7 +301,7 @@ static const struct ata_port_operations efar_ops = {
304static int efar_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 301static int efar_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
305{ 302{
306 static int printed_version; 303 static int printed_version;
307 static struct ata_port_info info = { 304 static const struct ata_port_info info = {
308 .sht = &efar_sht, 305 .sht = &efar_sht,
309 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 306 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
310 .pio_mask = 0x1f, /* pio0-4 */ 307 .pio_mask = 0x1f, /* pio0-4 */
@@ -312,13 +309,13 @@ static int efar_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
312 .udma_mask = 0x0f, /* UDMA 66 */ 309 .udma_mask = 0x0f, /* UDMA 66 */
313 .port_ops = &efar_ops, 310 .port_ops = &efar_ops,
314 }; 311 };
315 static struct ata_port_info *port_info[2] = { &info, &info }; 312 const struct ata_port_info *ppi[] = { &info, NULL };
316 313
317 if (!printed_version++) 314 if (!printed_version++)
318 dev_printk(KERN_DEBUG, &pdev->dev, 315 dev_printk(KERN_DEBUG, &pdev->dev,
319 "version " DRV_VERSION "\n"); 316 "version " DRV_VERSION "\n");
320 317
321 return ata_pci_init_one(pdev, port_info, 2); 318 return ata_pci_init_one(pdev, ppi);
322} 319}
323 320
324static const struct pci_device_id efar_pci_tbl[] = { 321static const struct pci_device_id efar_pci_tbl[] = {
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 93cfa6d300a5..0c9cb6090711 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -220,32 +220,6 @@ static int hpt36x_cable_detect(struct ata_port *ap)
220 return ATA_CBL_PATA80; 220 return ATA_CBL_PATA80;
221} 221}
222 222
223static int hpt36x_pre_reset(struct ata_port *ap)
224{
225 static const struct pci_bits hpt36x_enable_bits[] = {
226 { 0x50, 1, 0x04, 0x04 },
227 { 0x54, 1, 0x04, 0x04 }
228 };
229 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
230
231 if (!pci_test_config_bits(pdev, &hpt36x_enable_bits[ap->port_no]))
232 return -ENOENT;
233
234 return ata_std_prereset(ap);
235}
236
237/**
238 * hpt36x_error_handler - reset the hpt36x bus
239 * @ap: ATA port to reset
240 *
241 * Perform the reset handling for the 366/368
242 */
243
244static void hpt36x_error_handler(struct ata_port *ap)
245{
246 ata_bmdma_drive_eh(ap, hpt36x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
247}
248
249/** 223/**
250 * hpt366_set_piomode - PIO setup 224 * hpt366_set_piomode - PIO setup
251 * @ap: ATA interface 225 * @ap: ATA interface
@@ -331,10 +305,6 @@ static struct scsi_host_template hpt36x_sht = {
331 .slave_configure = ata_scsi_slave_config, 305 .slave_configure = ata_scsi_slave_config,
332 .slave_destroy = ata_scsi_slave_destroy, 306 .slave_destroy = ata_scsi_slave_destroy,
333 .bios_param = ata_std_bios_param, 307 .bios_param = ata_std_bios_param,
334#ifdef CONFIG_PM
335 .resume = ata_scsi_device_resume,
336 .suspend = ata_scsi_device_suspend,
337#endif
338}; 308};
339 309
340/* 310/*
@@ -355,7 +325,7 @@ static struct ata_port_operations hpt366_port_ops = {
355 325
356 .freeze = ata_bmdma_freeze, 326 .freeze = ata_bmdma_freeze,
357 .thaw = ata_bmdma_thaw, 327 .thaw = ata_bmdma_thaw,
358 .error_handler = hpt36x_error_handler, 328 .error_handler = ata_bmdma_error_handler,
359 .post_internal_cmd = ata_bmdma_post_internal_cmd, 329 .post_internal_cmd = ata_bmdma_post_internal_cmd,
360 .cable_detect = hpt36x_cable_detect, 330 .cable_detect = hpt36x_cable_detect,
361 331
@@ -421,7 +391,7 @@ static void hpt36x_init_chipset(struct pci_dev *dev)
421 391
422static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id) 392static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
423{ 393{
424 static struct ata_port_info info_hpt366 = { 394 static const struct ata_port_info info_hpt366 = {
425 .sht = &hpt36x_sht, 395 .sht = &hpt36x_sht,
426 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 396 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
427 .pio_mask = 0x1f, 397 .pio_mask = 0x1f,
@@ -429,7 +399,8 @@ static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
429 .udma_mask = 0x1f, 399 .udma_mask = 0x1f,
430 .port_ops = &hpt366_port_ops 400 .port_ops = &hpt366_port_ops
431 }; 401 };
432 struct ata_port_info *port_info[2] = {&info_hpt366, &info_hpt366}; 402 struct ata_port_info info = info_hpt366;
403 const struct ata_port_info *ppi[] = { &info, NULL };
433 404
434 u32 class_rev; 405 u32 class_rev;
435 u32 reg1; 406 u32 reg1;
@@ -450,17 +421,17 @@ static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
450 /* info_hpt366 is safe against re-entry so we can scribble on it */ 421 /* info_hpt366 is safe against re-entry so we can scribble on it */
451 switch((reg1 & 0x700) >> 8) { 422 switch((reg1 & 0x700) >> 8) {
452 case 5: 423 case 5:
453 info_hpt366.private_data = &hpt366_40; 424 info.private_data = &hpt366_40;
454 break; 425 break;
455 case 9: 426 case 9:
456 info_hpt366.private_data = &hpt366_25; 427 info.private_data = &hpt366_25;
457 break; 428 break;
458 default: 429 default:
459 info_hpt366.private_data = &hpt366_33; 430 info.private_data = &hpt366_33;
460 break; 431 break;
461 } 432 }
462 /* Now kick off ATA set up */ 433 /* Now kick off ATA set up */
463 return ata_pci_init_one(dev, port_info, 2); 434 return ata_pci_init_one(dev, ppi);
464} 435}
465 436
466#ifdef CONFIG_PM 437#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 41d831296347..a54c17433eef 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -307,11 +307,12 @@ static unsigned long hpt370a_filter(struct ata_device *adev, unsigned long mask)
307/** 307/**
308 * hpt37x_pre_reset - reset the hpt37x bus 308 * hpt37x_pre_reset - reset the hpt37x bus
309 * @ap: ATA port to reset 309 * @ap: ATA port to reset
310 * @deadline: deadline jiffies for the operation
310 * 311 *
311 * Perform the initial reset handling for the 370/372 and 374 func 0 312 * Perform the initial reset handling for the 370/372 and 374 func 0
312 */ 313 */
313 314
314static int hpt37x_pre_reset(struct ata_port *ap) 315static int hpt37x_pre_reset(struct ata_port *ap, unsigned long deadline)
315{ 316{
316 u8 scr2, ata66; 317 u8 scr2, ata66;
317 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 318 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
@@ -338,7 +339,7 @@ static int hpt37x_pre_reset(struct ata_port *ap)
338 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37); 339 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
339 udelay(100); 340 udelay(100);
340 341
341 return ata_std_prereset(ap); 342 return ata_std_prereset(ap, deadline);
342} 343}
343 344
344/** 345/**
@@ -353,7 +354,7 @@ static void hpt37x_error_handler(struct ata_port *ap)
353 ata_bmdma_drive_eh(ap, hpt37x_pre_reset, ata_std_softreset, NULL, ata_std_postreset); 354 ata_bmdma_drive_eh(ap, hpt37x_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
354} 355}
355 356
356static int hpt374_pre_reset(struct ata_port *ap) 357static int hpt374_pre_reset(struct ata_port *ap, unsigned long deadline)
357{ 358{
358 static const struct pci_bits hpt37x_enable_bits[] = { 359 static const struct pci_bits hpt37x_enable_bits[] = {
359 { 0x50, 1, 0x04, 0x04 }, 360 { 0x50, 1, 0x04, 0x04 },
@@ -388,7 +389,7 @@ static int hpt374_pre_reset(struct ata_port *ap)
388 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37); 389 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
389 udelay(100); 390 udelay(100);
390 391
391 return ata_std_prereset(ap); 392 return ata_std_prereset(ap, deadline);
392} 393}
393 394
394/** 395/**
@@ -886,7 +887,7 @@ static int hpt37x_calibrate_dpll(struct pci_dev *dev)
886static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id) 887static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
887{ 888{
888 /* HPT370 - UDMA100 */ 889 /* HPT370 - UDMA100 */
889 static struct ata_port_info info_hpt370 = { 890 static const struct ata_port_info info_hpt370 = {
890 .sht = &hpt37x_sht, 891 .sht = &hpt37x_sht,
891 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 892 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
892 .pio_mask = 0x1f, 893 .pio_mask = 0x1f,
@@ -895,7 +896,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
895 .port_ops = &hpt370_port_ops 896 .port_ops = &hpt370_port_ops
896 }; 897 };
897 /* HPT370A - UDMA100 */ 898 /* HPT370A - UDMA100 */
898 static struct ata_port_info info_hpt370a = { 899 static const struct ata_port_info info_hpt370a = {
899 .sht = &hpt37x_sht, 900 .sht = &hpt37x_sht,
900 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 901 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
901 .pio_mask = 0x1f, 902 .pio_mask = 0x1f,
@@ -904,7 +905,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
904 .port_ops = &hpt370a_port_ops 905 .port_ops = &hpt370a_port_ops
905 }; 906 };
906 /* HPT370 - UDMA100 */ 907 /* HPT370 - UDMA100 */
907 static struct ata_port_info info_hpt370_33 = { 908 static const struct ata_port_info info_hpt370_33 = {
908 .sht = &hpt37x_sht, 909 .sht = &hpt37x_sht,
909 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 910 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
910 .pio_mask = 0x1f, 911 .pio_mask = 0x1f,
@@ -913,7 +914,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
913 .port_ops = &hpt370_port_ops 914 .port_ops = &hpt370_port_ops
914 }; 915 };
915 /* HPT370A - UDMA100 */ 916 /* HPT370A - UDMA100 */
916 static struct ata_port_info info_hpt370a_33 = { 917 static const struct ata_port_info info_hpt370a_33 = {
917 .sht = &hpt37x_sht, 918 .sht = &hpt37x_sht,
918 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 919 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
919 .pio_mask = 0x1f, 920 .pio_mask = 0x1f,
@@ -922,7 +923,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
922 .port_ops = &hpt370a_port_ops 923 .port_ops = &hpt370a_port_ops
923 }; 924 };
924 /* HPT371, 372 and friends - UDMA133 */ 925 /* HPT371, 372 and friends - UDMA133 */
925 static struct ata_port_info info_hpt372 = { 926 static const struct ata_port_info info_hpt372 = {
926 .sht = &hpt37x_sht, 927 .sht = &hpt37x_sht,
927 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 928 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
928 .pio_mask = 0x1f, 929 .pio_mask = 0x1f,
@@ -931,7 +932,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
931 .port_ops = &hpt372_port_ops 932 .port_ops = &hpt372_port_ops
932 }; 933 };
933 /* HPT371, 372 and friends - UDMA100 at 50MHz clock */ 934 /* HPT371, 372 and friends - UDMA100 at 50MHz clock */
934 static struct ata_port_info info_hpt372_50 = { 935 static const struct ata_port_info info_hpt372_50 = {
935 .sht = &hpt37x_sht, 936 .sht = &hpt37x_sht,
936 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 937 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
937 .pio_mask = 0x1f, 938 .pio_mask = 0x1f,
@@ -940,7 +941,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
940 .port_ops = &hpt372_port_ops 941 .port_ops = &hpt372_port_ops
941 }; 942 };
942 /* HPT374 - UDMA133 */ 943 /* HPT374 - UDMA133 */
943 static struct ata_port_info info_hpt374 = { 944 static const struct ata_port_info info_hpt374 = {
944 .sht = &hpt37x_sht, 945 .sht = &hpt37x_sht,
945 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 946 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
946 .pio_mask = 0x1f, 947 .pio_mask = 0x1f,
@@ -950,16 +951,17 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
950 }; 951 };
951 952
952 static const int MHz[4] = { 33, 40, 50, 66 }; 953 static const int MHz[4] = { 33, 40, 50, 66 };
953 954 const struct ata_port_info *port;
954 struct ata_port_info *port_info[2]; 955 void *private_data = NULL;
955 struct ata_port_info *port; 956 struct ata_port_info port_info;
957 const struct ata_port_info *ppi[] = { &port_info, NULL };
956 958
957 u8 irqmask; 959 u8 irqmask;
958 u32 class_rev; 960 u32 class_rev;
959 u8 mcr1; 961 u8 mcr1;
960 u32 freq; 962 u32 freq;
961 int prefer_dpll = 1; 963 int prefer_dpll = 1;
962 964
963 unsigned long iobase = pci_resource_start(dev, 4); 965 unsigned long iobase = pci_resource_start(dev, 4);
964 966
965 const struct hpt_chip *chip_table; 967 const struct hpt_chip *chip_table;
@@ -1053,7 +1055,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1053 */ 1055 */
1054 1056
1055 pci_write_config_byte(dev, 0x5b, 0x23); 1057 pci_write_config_byte(dev, 0x5b, 0x23);
1056 1058
1057 /* 1059 /*
1058 * HighPoint does this for HPT372A. 1060 * HighPoint does this for HPT372A.
1059 * NOTE: This register is only writeable via I/O space. 1061 * NOTE: This register is only writeable via I/O space.
@@ -1086,7 +1088,7 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1086 * Turn the frequency check into a band and then find a timing 1088 * Turn the frequency check into a band and then find a timing
1087 * table to match it. 1089 * table to match it.
1088 */ 1090 */
1089 1091
1090 clock_slot = hpt37x_clock_slot(freq, chip_table->base); 1092 clock_slot = hpt37x_clock_slot(freq, chip_table->base);
1091 if (chip_table->clocks[clock_slot] == NULL || prefer_dpll) { 1093 if (chip_table->clocks[clock_slot] == NULL || prefer_dpll) {
1092 /* 1094 /*
@@ -1097,11 +1099,11 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1097 */ 1099 */
1098 unsigned int f_low, f_high; 1100 unsigned int f_low, f_high;
1099 int adjust; 1101 int adjust;
1100 1102
1101 clock_slot = 2; 1103 clock_slot = 2;
1102 if (port->udma_mask & 0xE0) 1104 if (port->udma_mask & 0xE0)
1103 clock_slot = 3; 1105 clock_slot = 3;
1104 1106
1105 f_low = (MHz[clock_slot] * chip_table->base) / 192; 1107 f_low = (MHz[clock_slot] * chip_table->base) / 192;
1106 f_high = f_low + 2; 1108 f_high = f_low + 2;
1107 1109
@@ -1123,13 +1125,13 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1123 return -ENODEV; 1125 return -ENODEV;
1124 } 1126 }
1125 if (clock_slot == 3) 1127 if (clock_slot == 3)
1126 port->private_data = (void *)hpt37x_timings_66; 1128 private_data = (void *)hpt37x_timings_66;
1127 else 1129 else
1128 port->private_data = (void *)hpt37x_timings_50; 1130 private_data = (void *)hpt37x_timings_50;
1129 1131
1130 printk(KERN_INFO "hpt37x: Bus clock %dMHz, using DPLL.\n", MHz[clock_slot]); 1132 printk(KERN_INFO "hpt37x: Bus clock %dMHz, using DPLL.\n", MHz[clock_slot]);
1131 } else { 1133 } else {
1132 port->private_data = (void *)chip_table->clocks[clock_slot]; 1134 private_data = (void *)chip_table->clocks[clock_slot];
1133 /* 1135 /*
1134 * Perform a final fixup. Note that we will have used the 1136 * Perform a final fixup. Note that we will have used the
1135 * DPLL on the HPT372 which means we don't have to worry 1137 * DPLL on the HPT372 which means we don't have to worry
@@ -1143,9 +1145,11 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1143 printk(KERN_INFO "hpt37x: %s: Bus clock %dMHz.\n", chip_table->name, MHz[clock_slot]); 1145 printk(KERN_INFO "hpt37x: %s: Bus clock %dMHz.\n", chip_table->name, MHz[clock_slot]);
1144 } 1146 }
1145 1147
1146 port_info[0] = port_info[1] = port;
1147 /* Now kick off ATA set up */ 1148 /* Now kick off ATA set up */
1148 return ata_pci_init_one(dev, port_info, 2); 1149 port_info = *port;
1150 port_info.private_data = private_data;
1151
1152 return ata_pci_init_one(dev, ppi);
1149} 1153}
1150 1154
1151static const struct pci_device_id hpt37x[] = { 1155static const struct pci_device_id hpt37x[] = {
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index 6a34521b9e01..f25154aed75d 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -148,13 +148,14 @@ static int hpt3x2n_cable_detect(struct ata_port *ap)
148 * Reset the hardware and state machine, 148 * Reset the hardware and state machine,
149 */ 149 */
150 150
151static int hpt3xn_pre_reset(struct ata_port *ap) 151static int hpt3xn_pre_reset(struct ata_port *ap, unsigned long deadline)
152{ 152{
153 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 153 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
154 /* Reset the state machine */ 154 /* Reset the state machine */
155 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37); 155 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
156 udelay(100); 156 udelay(100);
157 return ata_std_prereset(ap); 157
158 return ata_std_prereset(ap, deadline);
158} 159}
159 160
160/** 161/**
@@ -487,7 +488,7 @@ static int hpt3x2n_pci_clock(struct pci_dev *pdev)
487static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id) 488static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
488{ 489{
489 /* HPT372N and friends - UDMA133 */ 490 /* HPT372N and friends - UDMA133 */
490 static struct ata_port_info info = { 491 static const struct ata_port_info info = {
491 .sht = &hpt3x2n_sht, 492 .sht = &hpt3x2n_sht,
492 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 493 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
493 .pio_mask = 0x1f, 494 .pio_mask = 0x1f,
@@ -495,8 +496,8 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
495 .udma_mask = 0x7f, 496 .udma_mask = 0x7f,
496 .port_ops = &hpt3x2n_port_ops 497 .port_ops = &hpt3x2n_port_ops
497 }; 498 };
498 struct ata_port_info *port_info[2]; 499 struct ata_port_info port = info;
499 struct ata_port_info *port = &info; 500 const struct ata_port_info *ppi[] = { &port, NULL };
500 501
501 u8 irqmask; 502 u8 irqmask;
502 u32 class_rev; 503 u32 class_rev;
@@ -584,9 +585,9 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
584 585
585 /* Set our private data up. We only need a few flags so we use 586 /* Set our private data up. We only need a few flags so we use
586 it directly */ 587 it directly */
587 port->private_data = NULL; 588 port.private_data = NULL;
588 if (pci_mhz > 60) { 589 if (pci_mhz > 60) {
589 port->private_data = (void *)PCI66; 590 port.private_data = (void *)PCI66;
590 /* 591 /*
591 * On HPT371N, if ATA clock is 66 MHz we must set bit 2 in 592 * On HPT371N, if ATA clock is 66 MHz we must set bit 2 in
592 * the MISC. register to stretch the UltraDMA Tss timing. 593 * the MISC. register to stretch the UltraDMA Tss timing.
@@ -597,8 +598,7 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
597 } 598 }
598 599
599 /* Now kick off ATA set up */ 600 /* Now kick off ATA set up */
600 port_info[0] = port_info[1] = port; 601 return ata_pci_init_one(dev, ppi);
601 return ata_pci_init_one(dev, port_info, 2);
602} 602}
603 603
604static const struct pci_device_id hpt3x2n[] = { 604static const struct pci_device_id hpt3x2n[] = {
diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
index ac28ec8c50aa..8ce5e23a5f75 100644
--- a/drivers/ata/pata_hpt3x3.c
+++ b/drivers/ata/pata_hpt3x3.c
@@ -23,7 +23,7 @@
23#include <linux/libata.h> 23#include <linux/libata.h>
24 24
25#define DRV_NAME "pata_hpt3x3" 25#define DRV_NAME "pata_hpt3x3"
26#define DRV_VERSION "0.4.2" 26#define DRV_VERSION "0.4.3"
27 27
28/** 28/**
29 * hpt3x3_set_piomode - PIO setup 29 * hpt3x3_set_piomode - PIO setup
@@ -100,10 +100,6 @@ static struct scsi_host_template hpt3x3_sht = {
100 .slave_configure = ata_scsi_slave_config, 100 .slave_configure = ata_scsi_slave_config,
101 .slave_destroy = ata_scsi_slave_destroy, 101 .slave_destroy = ata_scsi_slave_destroy,
102 .bios_param = ata_std_bios_param, 102 .bios_param = ata_std_bios_param,
103#ifdef CONFIG_PM
104 .resume = ata_scsi_device_resume,
105 .suspend = ata_scsi_device_suspend,
106#endif
107}; 103};
108 104
109static struct ata_port_operations hpt3x3_port_ops = { 105static struct ata_port_operations hpt3x3_port_ops = {
@@ -175,7 +171,7 @@ static void hpt3x3_init_chipset(struct pci_dev *dev)
175 171
176static int hpt3x3_init_one(struct pci_dev *dev, const struct pci_device_id *id) 172static int hpt3x3_init_one(struct pci_dev *dev, const struct pci_device_id *id)
177{ 173{
178 static struct ata_port_info info = { 174 static const struct ata_port_info info = {
179 .sht = &hpt3x3_sht, 175 .sht = &hpt3x3_sht,
180 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 176 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
181 .pio_mask = 0x1f, 177 .pio_mask = 0x1f,
@@ -183,11 +179,11 @@ static int hpt3x3_init_one(struct pci_dev *dev, const struct pci_device_id *id)
183 .udma_mask = 0x07, 179 .udma_mask = 0x07,
184 .port_ops = &hpt3x3_port_ops 180 .port_ops = &hpt3x3_port_ops
185 }; 181 };
186 static struct ata_port_info *port_info[2] = { &info, &info }; 182 const struct ata_port_info *ppi[] = { &info, NULL };
187 183
188 hpt3x3_init_chipset(dev); 184 hpt3x3_init_chipset(dev);
189 /* Now kick off ATA set up */ 185 /* Now kick off ATA set up */
190 return ata_pci_init_one(dev, port_info, 2); 186 return ata_pci_init_one(dev, ppi);
191} 187}
192 188
193#ifdef CONFIG_PM 189#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c
index dbc8ee2adcf0..c791a46df461 100644
--- a/drivers/ata/pata_icside.c
+++ b/drivers/ata/pata_icside.c
@@ -60,6 +60,18 @@ struct pata_icside_state {
60 struct scatterlist sg[PATA_ICSIDE_MAX_SG]; 60 struct scatterlist sg[PATA_ICSIDE_MAX_SG];
61}; 61};
62 62
63struct pata_icside_info {
64 struct pata_icside_state *state;
65 struct expansion_card *ec;
66 void __iomem *base;
67 void __iomem *irqaddr;
68 unsigned int irqmask;
69 const expansioncard_ops_t *irqops;
70 unsigned int mwdma_mask;
71 unsigned int nr_ports;
72 const struct portinfo *port[2];
73};
74
63#define ICS_TYPE_A3IN 0 75#define ICS_TYPE_A3IN 0
64#define ICS_TYPE_A3USER 1 76#define ICS_TYPE_A3USER 1
65#define ICS_TYPE_V6 3 77#define ICS_TYPE_V6 3
@@ -269,9 +281,10 @@ static u8 pata_icside_bmdma_status(struct ata_port *ap)
269 return readb(irq_port) & 1 ? ATA_DMA_INTR : 0; 281 return readb(irq_port) & 1 ? ATA_DMA_INTR : 0;
270} 282}
271 283
272static int icside_dma_init(struct ata_probe_ent *ae, struct expansion_card *ec) 284static int icside_dma_init(struct pata_icside_info *info)
273{ 285{
274 struct pata_icside_state *state = ae->private_data; 286 struct pata_icside_state *state = info->state;
287 struct expansion_card *ec = info->ec;
275 int i; 288 int i;
276 289
277 for (i = 0; i < ATA_MAX_DEVICES; i++) { 290 for (i = 0; i < ATA_MAX_DEVICES; i++) {
@@ -281,7 +294,7 @@ static int icside_dma_init(struct ata_probe_ent *ae, struct expansion_card *ec)
281 294
282 if (ec->dma != NO_DMA && !request_dma(ec->dma, DRV_NAME)) { 295 if (ec->dma != NO_DMA && !request_dma(ec->dma, DRV_NAME)) {
283 state->dma = ec->dma; 296 state->dma = ec->dma;
284 ae->mwdma_mask = 0x07; /* MW0..2 */ 297 info->mwdma_mask = 0x07; /* MW0..2 */
285 } 298 }
286 299
287 return 0; 300 return 0;
@@ -371,6 +384,8 @@ static struct ata_port_operations pata_icside_port_ops = {
371 .check_status = ata_check_status, 384 .check_status = ata_check_status,
372 .dev_select = ata_std_dev_select, 385 .dev_select = ata_std_dev_select,
373 386
387 .cable_detect = ata_cable_40wire,
388
374 .bmdma_setup = pata_icside_bmdma_setup, 389 .bmdma_setup = pata_icside_bmdma_setup,
375 .bmdma_start = pata_icside_bmdma_start, 390 .bmdma_start = pata_icside_bmdma_start,
376 391
@@ -385,7 +400,6 @@ static struct ata_port_operations pata_icside_port_ops = {
385 .error_handler = ata_bmdma_error_handler, 400 .error_handler = ata_bmdma_error_handler,
386 .post_internal_cmd = pata_icside_bmdma_stop, 401 .post_internal_cmd = pata_icside_bmdma_stop,
387 402
388 .irq_handler = ata_interrupt,
389 .irq_clear = ata_dummy_noret, 403 .irq_clear = ata_dummy_noret,
390 .irq_on = ata_irq_on, 404 .irq_on = ata_irq_on,
391 .irq_ack = pata_icside_irq_ack, 405 .irq_ack = pata_icside_irq_ack,
@@ -396,11 +410,10 @@ static struct ata_port_operations pata_icside_port_ops = {
396 .bmdma_status = pata_icside_bmdma_status, 410 .bmdma_status = pata_icside_bmdma_status,
397}; 411};
398 412
399static void 413static void __devinit
400pata_icside_add_port(struct ata_probe_ent *ae, void __iomem *base, 414pata_icside_setup_ioaddr(struct ata_ioports *ioaddr, void __iomem *base,
401 const struct portinfo *info) 415 const struct portinfo *info)
402{ 416{
403 struct ata_ioports *ioaddr = &ae->port[ae->n_ports++];
404 void __iomem *cmd = base + info->dataoffset; 417 void __iomem *cmd = base + info->dataoffset;
405 418
406 ioaddr->cmd_addr = cmd; 419 ioaddr->cmd_addr = cmd;
@@ -419,58 +432,44 @@ pata_icside_add_port(struct ata_probe_ent *ae, void __iomem *base,
419 ioaddr->altstatus_addr = ioaddr->ctl_addr; 432 ioaddr->altstatus_addr = ioaddr->ctl_addr;
420} 433}
421 434
422static int __init 435static int __devinit pata_icside_register_v5(struct pata_icside_info *info)
423pata_icside_register_v5(struct ata_probe_ent *ae, struct expansion_card *ec)
424{ 436{
425 struct pata_icside_state *state = ae->private_data; 437 struct pata_icside_state *state = info->state;
426 void __iomem *base; 438 void __iomem *base;
427 439
428 base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), 440 base = ecardm_iomap(info->ec, ECARD_RES_MEMC, 0, 0);
429 ecard_resource_len(ec, ECARD_RES_MEMC));
430 if (!base) 441 if (!base)
431 return -ENOMEM; 442 return -ENOMEM;
432 443
433 state->irq_port = base; 444 state->irq_port = base;
434 445
435 ec->irqaddr = base + ICS_ARCIN_V5_INTRSTAT; 446 info->base = base;
436 ec->irqmask = 1; 447 info->irqaddr = base + ICS_ARCIN_V5_INTRSTAT;
437 ec->irq_data = state; 448 info->irqmask = 1;
438 ec->ops = &pata_icside_ops_arcin_v5; 449 info->irqops = &pata_icside_ops_arcin_v5;
439 450 info->nr_ports = 1;
440 /* 451 info->port[0] = &pata_icside_portinfo_v5;
441 * Be on the safe side - disable interrupts
442 */
443 ec->ops->irqdisable(ec, ec->irq);
444
445 pata_icside_add_port(ae, base, &pata_icside_portinfo_v5);
446 452
447 return 0; 453 return 0;
448} 454}
449 455
450static int __init 456static int __devinit pata_icside_register_v6(struct pata_icside_info *info)
451pata_icside_register_v6(struct ata_probe_ent *ae, struct expansion_card *ec)
452{ 457{
453 struct pata_icside_state *state = ae->private_data; 458 struct pata_icside_state *state = info->state;
459 struct expansion_card *ec = info->ec;
454 void __iomem *ioc_base, *easi_base; 460 void __iomem *ioc_base, *easi_base;
455 unsigned int sel = 0; 461 unsigned int sel = 0;
456 int ret;
457 462
458 ioc_base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 463 ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
459 ecard_resource_len(ec, ECARD_RES_IOCFAST)); 464 if (!ioc_base)
460 if (!ioc_base) { 465 return -ENOMEM;
461 ret = -ENOMEM;
462 goto out;
463 }
464 466
465 easi_base = ioc_base; 467 easi_base = ioc_base;
466 468
467 if (ecard_resource_flags(ec, ECARD_RES_EASI)) { 469 if (ecard_resource_flags(ec, ECARD_RES_EASI)) {
468 easi_base = ioremap(ecard_resource_start(ec, ECARD_RES_EASI), 470 easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0);
469 ecard_resource_len(ec, ECARD_RES_EASI)); 471 if (!easi_base)
470 if (!easi_base) { 472 return -ENOMEM;
471 ret = -ENOMEM;
472 goto unmap_slot;
473 }
474 473
475 /* 474 /*
476 * Enable access to the EASI region. 475 * Enable access to the EASI region.
@@ -480,45 +479,72 @@ pata_icside_register_v6(struct ata_probe_ent *ae, struct expansion_card *ec)
480 479
481 writeb(sel, ioc_base); 480 writeb(sel, ioc_base);
482 481
483 ec->irq_data = state;
484 ec->ops = &pata_icside_ops_arcin_v6;
485
486 state->irq_port = easi_base; 482 state->irq_port = easi_base;
487 state->ioc_base = ioc_base; 483 state->ioc_base = ioc_base;
488 state->port[0].port_sel = sel; 484 state->port[0].port_sel = sel;
489 state->port[1].port_sel = sel | 1; 485 state->port[1].port_sel = sel | 1;
490 486
491 /* 487 /*
492 * Be on the safe side - disable interrupts
493 */
494 ec->ops->irqdisable(ec, ec->irq);
495
496 /*
497 * Find and register the interfaces.
498 */
499 pata_icside_add_port(ae, easi_base, &pata_icside_portinfo_v6_1);
500 pata_icside_add_port(ae, easi_base, &pata_icside_portinfo_v6_2);
501
502 /*
503 * FIXME: work around libata's aversion to calling port_disable. 488 * FIXME: work around libata's aversion to calling port_disable.
504 * This permanently disables interrupts on port 0 - bad luck if 489 * This permanently disables interrupts on port 0 - bad luck if
505 * you have a drive on that port. 490 * you have a drive on that port.
506 */ 491 */
507 state->port[0].disabled = 1; 492 state->port[0].disabled = 1;
508 493
509 return icside_dma_init(ae, ec); 494 info->base = easi_base;
495 info->irqops = &pata_icside_ops_arcin_v6;
496 info->nr_ports = 2;
497 info->port[0] = &pata_icside_portinfo_v6_1;
498 info->port[1] = &pata_icside_portinfo_v6_2;
510 499
511 unmap_slot: 500 return icside_dma_init(info);
512 iounmap(ioc_base); 501}
513 out: 502
514 return ret; 503static int __devinit pata_icside_add_ports(struct pata_icside_info *info)
504{
505 struct expansion_card *ec = info->ec;
506 struct ata_host *host;
507 int i;
508
509 if (info->irqaddr) {
510 ec->irqaddr = info->irqaddr;
511 ec->irqmask = info->irqmask;
512 }
513 if (info->irqops)
514 ecard_setirq(ec, info->irqops, info->state);
515
516 /*
517 * Be on the safe side - disable interrupts
518 */
519 ec->ops->irqdisable(ec, ec->irq);
520
521 host = ata_host_alloc(&ec->dev, info->nr_ports);
522 if (!host)
523 return -ENOMEM;
524
525 host->private_data = info->state;
526 host->flags = ATA_HOST_SIMPLEX;
527
528 for (i = 0; i < info->nr_ports; i++) {
529 struct ata_port *ap = host->ports[i];
530
531 ap->pio_mask = 0x1f;
532 ap->mwdma_mask = info->mwdma_mask;
533 ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
534 ap->ops = &pata_icside_port_ops;
535
536 pata_icside_setup_ioaddr(&ap->ioaddr, info->base, info->port[i]);
537 }
538
539 return ata_host_activate(host, ec->irq, ata_interrupt, 0,
540 &pata_icside_sht);
515} 541}
516 542
517static int __devinit 543static int __devinit
518pata_icside_probe(struct expansion_card *ec, const struct ecard_id *id) 544pata_icside_probe(struct expansion_card *ec, const struct ecard_id *id)
519{ 545{
520 struct pata_icside_state *state; 546 struct pata_icside_state *state;
521 struct ata_probe_ent ae; 547 struct pata_icside_info info;
522 void __iomem *idmem; 548 void __iomem *idmem;
523 int ret; 549 int ret;
524 550
@@ -526,7 +552,7 @@ pata_icside_probe(struct expansion_card *ec, const struct ecard_id *id)
526 if (ret) 552 if (ret)
527 goto out; 553 goto out;
528 554
529 state = kzalloc(sizeof(struct pata_icside_state), GFP_KERNEL); 555 state = devm_kzalloc(&ec->dev, sizeof(*state), GFP_KERNEL);
530 if (!state) { 556 if (!state) {
531 ret = -ENOMEM; 557 ret = -ENOMEM;
532 goto release; 558 goto release;
@@ -535,8 +561,7 @@ pata_icside_probe(struct expansion_card *ec, const struct ecard_id *id)
535 state->type = ICS_TYPE_NOTYPE; 561 state->type = ICS_TYPE_NOTYPE;
536 state->dma = NO_DMA; 562 state->dma = NO_DMA;
537 563
538 idmem = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 564 idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
539 ecard_resource_len(ec, ECARD_RES_IOCFAST));
540 if (idmem) { 565 if (idmem) {
541 unsigned int type; 566 unsigned int type;
542 567
@@ -544,21 +569,14 @@ pata_icside_probe(struct expansion_card *ec, const struct ecard_id *id)
544 type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1; 569 type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1;
545 type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2; 570 type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2;
546 type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3; 571 type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3;
547 iounmap(idmem); 572 ecardm_iounmap(ec, idmem);
548 573
549 state->type = type; 574 state->type = type;
550 } 575 }
551 576
552 memset(&ae, 0, sizeof(ae)); 577 memset(&info, 0, sizeof(info));
553 INIT_LIST_HEAD(&ae.node); 578 info.state = state;
554 ae.dev = &ec->dev; 579 info.ec = ec;
555 ae.port_ops = &pata_icside_port_ops;
556 ae.sht = &pata_icside_sht;
557 ae.pio_mask = 0x1f;
558 ae.irq = ec->irq;
559 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
560 ae._host_flags = ATA_HOST_SIMPLEX;
561 ae.private_data = state;
562 580
563 switch (state->type) { 581 switch (state->type) {
564 case ICS_TYPE_A3IN: 582 case ICS_TYPE_A3IN:
@@ -572,11 +590,11 @@ pata_icside_probe(struct expansion_card *ec, const struct ecard_id *id)
572 break; 590 break;
573 591
574 case ICS_TYPE_V5: 592 case ICS_TYPE_V5:
575 ret = pata_icside_register_v5(&ae, ec); 593 ret = pata_icside_register_v5(&info);
576 break; 594 break;
577 595
578 case ICS_TYPE_V6: 596 case ICS_TYPE_V6:
579 ret = pata_icside_register_v6(&ae, ec); 597 ret = pata_icside_register_v6(&info);
580 break; 598 break;
581 599
582 default: 600 default:
@@ -586,12 +604,11 @@ pata_icside_probe(struct expansion_card *ec, const struct ecard_id *id)
586 } 604 }
587 605
588 if (ret == 0) 606 if (ret == 0)
589 ret = ata_device_add(&ae) == 0 ? -ENODEV : 0; 607 ret = pata_icside_add_ports(&info);
590 608
591 if (ret == 0) 609 if (ret == 0)
592 goto out; 610 goto out;
593 611
594 kfree(state);
595 release: 612 release:
596 ecard_release_resources(ec); 613 ecard_release_resources(ec);
597 out: 614 out:
@@ -609,8 +626,7 @@ static void pata_icside_shutdown(struct expansion_card *ec)
609 * this register via that region. 626 * this register via that region.
610 */ 627 */
611 local_irq_save(flags); 628 local_irq_save(flags);
612 if (ec->ops) 629 ec->ops->irqdisable(ec, ec->irq);
613 ec->ops->irqdisable(ec, ec->irq);
614 local_irq_restore(flags); 630 local_irq_restore(flags);
615 631
616 /* 632 /*
@@ -638,17 +654,9 @@ static void __devexit pata_icside_remove(struct expansion_card *ec)
638 * don't NULL out the drvdata - devres/libata wants it 654 * don't NULL out the drvdata - devres/libata wants it
639 * to free the ata_host structure. 655 * to free the ata_host structure.
640 */ 656 */
641 ec->ops = NULL;
642 ec->irq_data = NULL;
643
644 if (state->dma != NO_DMA) 657 if (state->dma != NO_DMA)
645 free_dma(state->dma); 658 free_dma(state->dma);
646 if (state->ioc_base)
647 iounmap(state->ioc_base);
648 if (state->ioc_base != state->irq_port)
649 iounmap(state->irq_port);
650 659
651 kfree(state);
652 ecard_release_resources(ec); 660 ecard_release_resources(ec);
653} 661}
654 662
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index d042efdfbac4..1f647b648204 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -17,7 +17,7 @@
17#include <linux/libata.h> 17#include <linux/libata.h>
18 18
19#define DRV_NAME "pata_isapnp" 19#define DRV_NAME "pata_isapnp"
20#define DRV_VERSION "0.2.0" 20#define DRV_VERSION "0.2.1"
21 21
22static struct scsi_host_template isapnp_sht = { 22static struct scsi_host_template isapnp_sht = {
23 .module = THIS_MODULE, 23 .module = THIS_MODULE,
diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
index 011306ef8334..95b0bb61788b 100644
--- a/drivers/ata/pata_it8213.c
+++ b/drivers/ata/pata_it8213.c
@@ -19,17 +19,18 @@
19#include <linux/ata.h> 19#include <linux/ata.h>
20 20
21#define DRV_NAME "pata_it8213" 21#define DRV_NAME "pata_it8213"
22#define DRV_VERSION "0.0.2" 22#define DRV_VERSION "0.0.3"
23 23
24/** 24/**
25 * it8213_pre_reset - check for 40/80 pin 25 * it8213_pre_reset - check for 40/80 pin
26 * @ap: Port 26 * @ap: Port
27 * @deadline: deadline jiffies for the operation
27 * 28 *
28 * Filter out ports by the enable bits before doing the normal reset 29 * Filter out ports by the enable bits before doing the normal reset
29 * and probe. 30 * and probe.
30 */ 31 */
31 32
32static int it8213_pre_reset(struct ata_port *ap) 33static int it8213_pre_reset(struct ata_port *ap, unsigned long deadline)
33{ 34{
34 static const struct pci_bits it8213_enable_bits[] = { 35 static const struct pci_bits it8213_enable_bits[] = {
35 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */ 36 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
@@ -37,7 +38,8 @@ static int it8213_pre_reset(struct ata_port *ap)
37 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 38 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
38 if (!pci_test_config_bits(pdev, &it8213_enable_bits[ap->port_no])) 39 if (!pci_test_config_bits(pdev, &it8213_enable_bits[ap->port_no]))
39 return -ENOENT; 40 return -ENOENT;
40 return ata_std_prereset(ap); 41
42 return ata_std_prereset(ap, deadline);
41} 43}
42 44
43/** 45/**
@@ -255,10 +257,6 @@ static struct scsi_host_template it8213_sht = {
255 .dma_boundary = ATA_DMA_BOUNDARY, 257 .dma_boundary = ATA_DMA_BOUNDARY,
256 .slave_configure = ata_scsi_slave_config, 258 .slave_configure = ata_scsi_slave_config,
257 .bios_param = ata_std_bios_param, 259 .bios_param = ata_std_bios_param,
258#ifdef CONFIG_PM
259 .resume = ata_scsi_device_resume,
260 .suspend = ata_scsi_device_suspend,
261#endif
262}; 260};
263 261
264static const struct ata_port_operations it8213_ops = { 262static const struct ata_port_operations it8213_ops = {
@@ -313,7 +311,7 @@ static const struct ata_port_operations it8213_ops = {
313static int it8213_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 311static int it8213_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
314{ 312{
315 static int printed_version; 313 static int printed_version;
316 static struct ata_port_info info = { 314 static const struct ata_port_info info = {
317 .sht = &it8213_sht, 315 .sht = &it8213_sht,
318 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 316 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
319 .pio_mask = 0x1f, /* pio0-4 */ 317 .pio_mask = 0x1f, /* pio0-4 */
@@ -321,14 +319,14 @@ static int it8213_init_one (struct pci_dev *pdev, const struct pci_device_id *en
321 .udma_mask = 0x1f, /* UDMA 100 */ 319 .udma_mask = 0x1f, /* UDMA 100 */
322 .port_ops = &it8213_ops, 320 .port_ops = &it8213_ops,
323 }; 321 };
324 static struct ata_port_info *port_info[2] = { &info, &info }; 322 /* Current IT8213 stuff is single port */
323 const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
325 324
326 if (!printed_version++) 325 if (!printed_version++)
327 dev_printk(KERN_DEBUG, &pdev->dev, 326 dev_printk(KERN_DEBUG, &pdev->dev,
328 "version " DRV_VERSION "\n"); 327 "version " DRV_VERSION "\n");
329 328
330 /* Current IT8213 stuff is single port */ 329 return ata_pci_init_one(pdev, ppi);
331 return ata_pci_init_one(pdev, port_info, 1);
332} 330}
333 331
334static const struct pci_device_id it8213_pci_tbl[] = { 332static const struct pci_device_id it8213_pci_tbl[] = {
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index f1f8cec8c224..ff9a6fd36657 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -620,10 +620,6 @@ static struct scsi_host_template it821x_sht = {
620 .slave_configure = ata_scsi_slave_config, 620 .slave_configure = ata_scsi_slave_config,
621 .slave_destroy = ata_scsi_slave_destroy, 621 .slave_destroy = ata_scsi_slave_destroy,
622 .bios_param = ata_std_bios_param, 622 .bios_param = ata_std_bios_param,
623#ifdef CONFIG_PM
624 .resume = ata_scsi_device_resume,
625 .suspend = ata_scsi_device_suspend,
626#endif
627}; 623};
628 624
629static struct ata_port_operations it821x_smart_port_ops = { 625static struct ata_port_operations it821x_smart_port_ops = {
@@ -722,14 +718,14 @@ static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
722{ 718{
723 u8 conf; 719 u8 conf;
724 720
725 static struct ata_port_info info_smart = { 721 static const struct ata_port_info info_smart = {
726 .sht = &it821x_sht, 722 .sht = &it821x_sht,
727 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 723 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
728 .pio_mask = 0x1f, 724 .pio_mask = 0x1f,
729 .mwdma_mask = 0x07, 725 .mwdma_mask = 0x07,
730 .port_ops = &it821x_smart_port_ops 726 .port_ops = &it821x_smart_port_ops
731 }; 727 };
732 static struct ata_port_info info_passthru = { 728 static const struct ata_port_info info_passthru = {
733 .sht = &it821x_sht, 729 .sht = &it821x_sht,
734 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 730 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
735 .pio_mask = 0x1f, 731 .pio_mask = 0x1f,
@@ -737,8 +733,8 @@ static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
737 .udma_mask = 0x7f, 733 .udma_mask = 0x7f,
738 .port_ops = &it821x_passthru_port_ops 734 .port_ops = &it821x_passthru_port_ops
739 }; 735 };
740 static struct ata_port_info *port_info[2];
741 736
737 const struct ata_port_info *ppi[] = { NULL, NULL };
742 static char *mode[2] = { "pass through", "smart" }; 738 static char *mode[2] = { "pass through", "smart" };
743 739
744 /* Force the card into bypass mode if so requested */ 740 /* Force the card into bypass mode if so requested */
@@ -751,11 +747,11 @@ static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
751 747
752 printk(KERN_INFO DRV_NAME ": controller in %s mode.\n", mode[conf]); 748 printk(KERN_INFO DRV_NAME ": controller in %s mode.\n", mode[conf]);
753 if (conf == 0) 749 if (conf == 0)
754 port_info[0] = port_info[1] = &info_passthru; 750 ppi[0] = &info_passthru;
755 else 751 else
756 port_info[0] = port_info[1] = &info_smart; 752 ppi[0] = &info_smart;
757 753
758 return ata_pci_init_one(pdev, port_info, 2); 754 return ata_pci_init_one(pdev, ppi);
759} 755}
760 756
761#ifdef CONFIG_PM 757#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index 420c343e5711..8d2bc1e9e871 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -23,7 +23,7 @@
23#include <scsi/scsi_host.h> 23#include <scsi/scsi_host.h>
24 24
25#define DRV_NAME "pata_ixp4xx_cf" 25#define DRV_NAME "pata_ixp4xx_cf"
26#define DRV_VERSION "0.1.2" 26#define DRV_VERSION "0.1.3"
27 27
28static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device **error) 28static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device **error)
29{ 29{
@@ -31,7 +31,7 @@ static int ixp4xx_set_mode(struct ata_port *ap, struct ata_device **error)
31 31
32 for (i = 0; i < ATA_MAX_DEVICES; i++) { 32 for (i = 0; i < ATA_MAX_DEVICES; i++) {
33 struct ata_device *dev = &ap->device[i]; 33 struct ata_device *dev = &ap->device[i];
34 if (ata_dev_ready(dev)) { 34 if (ata_dev_enabled(dev)) {
35 ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n"); 35 ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n");
36 dev->pio_mode = XFER_PIO_0; 36 dev->pio_mode = XFER_PIO_0;
37 dev->xfer_mode = XFER_PIO_0; 37 dev->xfer_mode = XFER_PIO_0;
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index 43763c99ea02..2af7ff8256ca 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -19,7 +19,7 @@
19#include <linux/ata.h> 19#include <linux/ata.h>
20 20
21#define DRV_NAME "pata_jmicron" 21#define DRV_NAME "pata_jmicron"
22#define DRV_VERSION "0.1.4" 22#define DRV_VERSION "0.1.5"
23 23
24typedef enum { 24typedef enum {
25 PORT_PATA0 = 0, 25 PORT_PATA0 = 0,
@@ -30,16 +30,17 @@ typedef enum {
30/** 30/**
31 * jmicron_pre_reset - check for 40/80 pin 31 * jmicron_pre_reset - check for 40/80 pin
32 * @ap: Port 32 * @ap: Port
33 * @deadline: deadline jiffies for the operation
33 * 34 *
34 * Perform the PATA port setup we need. 35 * Perform the PATA port setup we need.
35 36 *
36 * On the Jmicron 361/363 there is a single PATA port that can be mapped 37 * On the Jmicron 361/363 there is a single PATA port that can be mapped
37 * either as primary or secondary (or neither). We don't do any policy 38 * either as primary or secondary (or neither). We don't do any policy
38 * and setup here. We assume that has been done by init_one and the 39 * and setup here. We assume that has been done by init_one and the
39 * BIOS. 40 * BIOS.
40 */ 41 */
41 42
42static int jmicron_pre_reset(struct ata_port *ap) 43static int jmicron_pre_reset(struct ata_port *ap, unsigned long deadline)
43{ 44{
44 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 45 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
45 u32 control; 46 u32 control;
@@ -102,7 +103,7 @@ static int jmicron_pre_reset(struct ata_port *ap)
102 ap->cbl = ATA_CBL_SATA; 103 ap->cbl = ATA_CBL_SATA;
103 break; 104 break;
104 } 105 }
105 return ata_std_prereset(ap); 106 return ata_std_prereset(ap, deadline);
106} 107}
107 108
108/** 109/**
@@ -137,10 +138,6 @@ static struct scsi_host_template jmicron_sht = {
137 .slave_destroy = ata_scsi_slave_destroy, 138 .slave_destroy = ata_scsi_slave_destroy,
138 /* Use standard CHS mapping rules */ 139 /* Use standard CHS mapping rules */
139 .bios_param = ata_std_bios_param, 140 .bios_param = ata_std_bios_param,
140#ifdef CONFIG_PM
141 .suspend = ata_scsi_device_suspend,
142 .resume = ata_scsi_device_resume,
143#endif
144}; 141};
145 142
146static const struct ata_port_operations jmicron_ops = { 143static const struct ata_port_operations jmicron_ops = {
@@ -194,7 +191,7 @@ static const struct ata_port_operations jmicron_ops = {
194 191
195static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *id) 192static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
196{ 193{
197 static struct ata_port_info info = { 194 static const struct ata_port_info info = {
198 .sht = &jmicron_sht, 195 .sht = &jmicron_sht,
199 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 196 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
200 197
@@ -204,9 +201,9 @@ static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *i
204 201
205 .port_ops = &jmicron_ops, 202 .port_ops = &jmicron_ops,
206 }; 203 };
207 struct ata_port_info *port_info[2] = { &info, &info }; 204 const struct ata_port_info *ppi[] = { &info, NULL };
208 205
209 return ata_pci_init_one(pdev, port_info, 2); 206 return ata_pci_init_one(pdev, ppi);
210} 207}
211 208
212static const struct pci_device_id jmicron_pci_tbl[] = { 209static const struct pci_device_id jmicron_pci_tbl[] = {
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index 707099291e01..edffc25d2d3f 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -64,7 +64,7 @@
64#include <linux/platform_device.h> 64#include <linux/platform_device.h>
65 65
66#define DRV_NAME "pata_legacy" 66#define DRV_NAME "pata_legacy"
67#define DRV_VERSION "0.5.4" 67#define DRV_VERSION "0.5.5"
68 68
69#define NR_HOST 6 69#define NR_HOST 6
70 70
diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
index d9b94a1b6954..edbfe0dbbf78 100644
--- a/drivers/ata/pata_marvell.c
+++ b/drivers/ata/pata_marvell.c
@@ -25,11 +25,12 @@
25/** 25/**
26 * marvell_pre_reset - check for 40/80 pin 26 * marvell_pre_reset - check for 40/80 pin
27 * @ap: Port 27 * @ap: Port
28 * @deadline: deadline jiffies for the operation
28 * 29 *
29 * Perform the PATA port setup we need. 30 * Perform the PATA port setup we need.
30 */ 31 */
31 32
32static int marvell_pre_reset(struct ata_port *ap) 33static int marvell_pre_reset(struct ata_port *ap, unsigned long deadline)
33{ 34{
34 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 35 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
35 u32 devices; 36 u32 devices;
@@ -52,7 +53,8 @@ static int marvell_pre_reset(struct ata_port *ap)
52 if ((pdev->device == 0x6145) && (ap->port_no == 0) && 53 if ((pdev->device == 0x6145) && (ap->port_no == 0) &&
53 (!(devices & 0x10))) /* PATA enable ? */ 54 (!(devices & 0x10))) /* PATA enable ? */
54 return -ENOENT; 55 return -ENOENT;
55 return ata_std_prereset(ap); 56
57 return ata_std_prereset(ap, deadline);
56} 58}
57 59
58static int marvell_cable_detect(struct ata_port *ap) 60static int marvell_cable_detect(struct ata_port *ap)
@@ -67,6 +69,7 @@ static int marvell_cable_detect(struct ata_port *ap)
67 case 1: /* Legacy SATA port */ 69 case 1: /* Legacy SATA port */
68 return ATA_CBL_SATA; 70 return ATA_CBL_SATA;
69 } 71 }
72
70 BUG(); 73 BUG();
71 return 0; /* Our BUG macro needs the right markup */ 74 return 0; /* Our BUG macro needs the right markup */
72} 75}
@@ -104,10 +107,6 @@ static struct scsi_host_template marvell_sht = {
104 .slave_destroy = ata_scsi_slave_destroy, 107 .slave_destroy = ata_scsi_slave_destroy,
105 /* Use standard CHS mapping rules */ 108 /* Use standard CHS mapping rules */
106 .bios_param = ata_std_bios_param, 109 .bios_param = ata_std_bios_param,
107#ifdef CONFIG_PM
108 .resume = ata_scsi_device_resume,
109 .suspend = ata_scsi_device_suspend,
110#endif
111}; 110};
112 111
113static const struct ata_port_operations marvell_ops = { 112static const struct ata_port_operations marvell_ops = {
@@ -162,7 +161,7 @@ static const struct ata_port_operations marvell_ops = {
162 161
163static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id) 162static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
164{ 163{
165 static struct ata_port_info info = { 164 static const struct ata_port_info info = {
166 .sht = &marvell_sht, 165 .sht = &marvell_sht,
167 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 166 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
168 167
@@ -172,7 +171,7 @@ static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *i
172 171
173 .port_ops = &marvell_ops, 172 .port_ops = &marvell_ops,
174 }; 173 };
175 static struct ata_port_info info_sata = { 174 static const struct ata_port_info info_sata = {
176 .sht = &marvell_sht, 175 .sht = &marvell_sht,
177 /* Slave possible as its magically mapped not real */ 176 /* Slave possible as its magically mapped not real */
178 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 177 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
@@ -183,13 +182,12 @@ static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *i
183 182
184 .port_ops = &marvell_ops, 183 .port_ops = &marvell_ops,
185 }; 184 };
186 struct ata_port_info *port_info[2] = { &info, &info_sata }; 185 const struct ata_port_info *ppi[] = { &info, &info_sata };
187 int n_port = 2;
188 186
189 if (pdev->device == 0x6101) 187 if (pdev->device == 0x6101)
190 n_port = 1; 188 ppi[1] = &ata_dummy_port_info;
191 189
192 return ata_pci_init_one(pdev, port_info, n_port); 190 return ata_pci_init_one(pdev, ppi);
193} 191}
194 192
195static const struct pci_device_id marvell_pci_tbl[] = { 193static const struct pci_device_id marvell_pci_tbl[] = {
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index 9587a89f9683..368fac7d168b 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -280,10 +280,6 @@ static struct scsi_host_template mpc52xx_ata_sht = {
280 .dma_boundary = ATA_DMA_BOUNDARY, 280 .dma_boundary = ATA_DMA_BOUNDARY,
281 .slave_configure = ata_scsi_slave_config, 281 .slave_configure = ata_scsi_slave_config,
282 .bios_param = ata_std_bios_param, 282 .bios_param = ata_std_bios_param,
283#ifdef CONFIG_PM
284 .suspend = ata_scsi_device_suspend,
285 .resume = ata_scsi_device_resume,
286#endif
287}; 283};
288 284
289static struct ata_port_operations mpc52xx_ata_port_ops = { 285static struct ata_port_operations mpc52xx_ata_port_ops = {
diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
index 987c5fafab08..4ea42838297e 100644
--- a/drivers/ata/pata_mpiix.c
+++ b/drivers/ata/pata_mpiix.c
@@ -46,14 +46,15 @@ enum {
46 SECONDARY = (1 << 14) 46 SECONDARY = (1 << 14)
47}; 47};
48 48
49static int mpiix_pre_reset(struct ata_port *ap) 49static int mpiix_pre_reset(struct ata_port *ap, unsigned long deadline)
50{ 50{
51 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 51 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
52 static const struct pci_bits mpiix_enable_bits = { 0x6D, 1, 0x80, 0x80 }; 52 static const struct pci_bits mpiix_enable_bits = { 0x6D, 1, 0x80, 0x80 };
53 53
54 if (!pci_test_config_bits(pdev, &mpiix_enable_bits)) 54 if (!pci_test_config_bits(pdev, &mpiix_enable_bits))
55 return -ENOENT; 55 return -ENOENT;
56 return ata_std_prereset(ap); 56
57 return ata_std_prereset(ap, deadline);
57} 58}
58 59
59/** 60/**
@@ -164,10 +165,6 @@ static struct scsi_host_template mpiix_sht = {
164 .slave_configure = ata_scsi_slave_config, 165 .slave_configure = ata_scsi_slave_config,
165 .slave_destroy = ata_scsi_slave_destroy, 166 .slave_destroy = ata_scsi_slave_destroy,
166 .bios_param = ata_std_bios_param, 167 .bios_param = ata_std_bios_param,
167#ifdef CONFIG_PM
168 .resume = ata_scsi_device_resume,
169 .suspend = ata_scsi_device_suspend,
170#endif
171}; 168};
172 169
173static struct ata_port_operations mpiix_port_ops = { 170static struct ata_port_operations mpiix_port_ops = {
diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
index dbba5b77d79c..81f563458666 100644
--- a/drivers/ata/pata_netcell.c
+++ b/drivers/ata/pata_netcell.c
@@ -37,10 +37,6 @@ static struct scsi_host_template netcell_sht = {
37 .slave_destroy = ata_scsi_slave_destroy, 37 .slave_destroy = ata_scsi_slave_destroy,
38 /* Use standard CHS mapping rules */ 38 /* Use standard CHS mapping rules */
39 .bios_param = ata_std_bios_param, 39 .bios_param = ata_std_bios_param,
40#ifdef CONFIG_PM
41 .resume = ata_scsi_device_resume,
42 .suspend = ata_scsi_device_suspend,
43#endif
44}; 40};
45 41
46static const struct ata_port_operations netcell_ops = { 42static const struct ata_port_operations netcell_ops = {
@@ -96,7 +92,7 @@ static const struct ata_port_operations netcell_ops = {
96static int netcell_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 92static int netcell_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
97{ 93{
98 static int printed_version; 94 static int printed_version;
99 static struct ata_port_info info = { 95 static const struct ata_port_info info = {
100 .sht = &netcell_sht, 96 .sht = &netcell_sht,
101 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 97 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
102 /* Actually we don't really care about these as the 98 /* Actually we don't really care about these as the
@@ -106,7 +102,7 @@ static int netcell_init_one (struct pci_dev *pdev, const struct pci_device_id *e
106 .udma_mask = 0x3f, /* UDMA 133 */ 102 .udma_mask = 0x3f, /* UDMA 133 */
107 .port_ops = &netcell_ops, 103 .port_ops = &netcell_ops,
108 }; 104 };
109 static struct ata_port_info *port_info[2] = { &info, &info }; 105 const struct ata_port_info *port_info[] = { &info, NULL };
110 106
111 if (!printed_version++) 107 if (!printed_version++)
112 dev_printk(KERN_DEBUG, &pdev->dev, 108 dev_printk(KERN_DEBUG, &pdev->dev,
@@ -116,7 +112,7 @@ static int netcell_init_one (struct pci_dev *pdev, const struct pci_device_id *e
116 ata_pci_clear_simplex(pdev); 112 ata_pci_clear_simplex(pdev);
117 113
118 /* And let the library code do the work */ 114 /* And let the library code do the work */
119 return ata_pci_init_one(pdev, port_info, 2); 115 return ata_pci_init_one(pdev, port_info);
120} 116}
121 117
122static const struct pci_device_id netcell_pci_tbl[] = { 118static const struct pci_device_id netcell_pci_tbl[] = {
diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
index 078aeda9cf8d..ea70ec744879 100644
--- a/drivers/ata/pata_ns87410.c
+++ b/drivers/ata/pata_ns87410.c
@@ -33,11 +33,12 @@
33/** 33/**
34 * ns87410_pre_reset - probe begin 34 * ns87410_pre_reset - probe begin
35 * @ap: ATA port 35 * @ap: ATA port
36 * @deadline: deadline jiffies for the operation
36 * 37 *
37 * Check enabled ports 38 * Check enabled ports
38 */ 39 */
39 40
40static int ns87410_pre_reset(struct ata_port *ap) 41static int ns87410_pre_reset(struct ata_port *ap, unsigned long deadline)
41{ 42{
42 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 43 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
43 static const struct pci_bits ns87410_enable_bits[] = { 44 static const struct pci_bits ns87410_enable_bits[] = {
@@ -47,7 +48,8 @@ static int ns87410_pre_reset(struct ata_port *ap)
47 48
48 if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no])) 49 if (!pci_test_config_bits(pdev, &ns87410_enable_bits[ap->port_no]))
49 return -ENOENT; 50 return -ENOENT;
50 return ata_std_prereset(ap); 51
52 return ata_std_prereset(ap, deadline);
51} 53}
52 54
53/** 55/**
@@ -156,10 +158,6 @@ static struct scsi_host_template ns87410_sht = {
156 .slave_configure = ata_scsi_slave_config, 158 .slave_configure = ata_scsi_slave_config,
157 .slave_destroy = ata_scsi_slave_destroy, 159 .slave_destroy = ata_scsi_slave_destroy,
158 .bios_param = ata_std_bios_param, 160 .bios_param = ata_std_bios_param,
159#ifdef CONFIG_PM
160 .resume = ata_scsi_device_resume,
161 .suspend = ata_scsi_device_suspend,
162#endif
163}; 161};
164 162
165static struct ata_port_operations ns87410_port_ops = { 163static struct ata_port_operations ns87410_port_ops = {
@@ -193,14 +191,14 @@ static struct ata_port_operations ns87410_port_ops = {
193 191
194static int ns87410_init_one(struct pci_dev *dev, const struct pci_device_id *id) 192static int ns87410_init_one(struct pci_dev *dev, const struct pci_device_id *id)
195{ 193{
196 static struct ata_port_info info = { 194 static const struct ata_port_info info = {
197 .sht = &ns87410_sht, 195 .sht = &ns87410_sht,
198 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 196 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
199 .pio_mask = 0x0F, 197 .pio_mask = 0x0F,
200 .port_ops = &ns87410_port_ops 198 .port_ops = &ns87410_port_ops
201 }; 199 };
202 static struct ata_port_info *port_info[2] = {&info, &info}; 200 const struct ata_port_info *ppi[] = { &info, NULL };
203 return ata_pci_init_one(dev, port_info, 2); 201 return ata_pci_init_one(dev, ppi);
204} 202}
205 203
206static const struct pci_device_id ns87410[] = { 204static const struct pci_device_id ns87410[] = {
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index dea4690340d1..29c23ddd6550 100644
--- a/drivers/ata/pata_oldpiix.c
+++ b/drivers/ata/pata_oldpiix.c
@@ -30,11 +30,12 @@
30/** 30/**
31 * oldpiix_pre_reset - probe begin 31 * oldpiix_pre_reset - probe begin
32 * @ap: ATA port 32 * @ap: ATA port
33 * @deadline: deadline jiffies for the operation
33 * 34 *
34 * Set up cable type and use generic probe init 35 * Set up cable type and use generic probe init
35 */ 36 */
36 37
37static int oldpiix_pre_reset(struct ata_port *ap) 38static int oldpiix_pre_reset(struct ata_port *ap, unsigned long deadline)
38{ 39{
39 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 40 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
40 static const struct pci_bits oldpiix_enable_bits[] = { 41 static const struct pci_bits oldpiix_enable_bits[] = {
@@ -44,7 +45,8 @@ static int oldpiix_pre_reset(struct ata_port *ap)
44 45
45 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no])) 46 if (!pci_test_config_bits(pdev, &oldpiix_enable_bits[ap->port_no]))
46 return -ENOENT; 47 return -ENOENT;
47 return ata_std_prereset(ap); 48
49 return ata_std_prereset(ap, deadline);
48} 50}
49 51
50/** 52/**
@@ -232,10 +234,6 @@ static struct scsi_host_template oldpiix_sht = {
232 .slave_configure = ata_scsi_slave_config, 234 .slave_configure = ata_scsi_slave_config,
233 .slave_destroy = ata_scsi_slave_destroy, 235 .slave_destroy = ata_scsi_slave_destroy,
234 .bios_param = ata_std_bios_param, 236 .bios_param = ata_std_bios_param,
235#ifdef CONFIG_PM
236 .resume = ata_scsi_device_resume,
237 .suspend = ata_scsi_device_suspend,
238#endif
239}; 237};
240 238
241static const struct ata_port_operations oldpiix_pata_ops = { 239static const struct ata_port_operations oldpiix_pata_ops = {
@@ -291,20 +289,20 @@ static const struct ata_port_operations oldpiix_pata_ops = {
291static int oldpiix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 289static int oldpiix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
292{ 290{
293 static int printed_version; 291 static int printed_version;
294 static struct ata_port_info info = { 292 static const struct ata_port_info info = {
295 .sht = &oldpiix_sht, 293 .sht = &oldpiix_sht,
296 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 294 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
297 .pio_mask = 0x1f, /* pio0-4 */ 295 .pio_mask = 0x1f, /* pio0-4 */
298 .mwdma_mask = 0x07, /* mwdma1-2 */ 296 .mwdma_mask = 0x07, /* mwdma1-2 */
299 .port_ops = &oldpiix_pata_ops, 297 .port_ops = &oldpiix_pata_ops,
300 }; 298 };
301 static struct ata_port_info *port_info[2] = { &info, &info }; 299 const struct ata_port_info *ppi[] = { &info, NULL };
302 300
303 if (!printed_version++) 301 if (!printed_version++)
304 dev_printk(KERN_DEBUG, &pdev->dev, 302 dev_printk(KERN_DEBUG, &pdev->dev,
305 "version " DRV_VERSION "\n"); 303 "version " DRV_VERSION "\n");
306 304
307 return ata_pci_init_one(pdev, port_info, 2); 305 return ata_pci_init_one(pdev, ppi);
308} 306}
309 307
310static const struct pci_device_id oldpiix_pci_tbl[] = { 308static const struct pci_device_id oldpiix_pci_tbl[] = {
diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
index 13b63e21838d..1c44653e1e06 100644
--- a/drivers/ata/pata_opti.c
+++ b/drivers/ata/pata_opti.c
@@ -47,11 +47,12 @@ enum {
47/** 47/**
48 * opti_pre_reset - probe begin 48 * opti_pre_reset - probe begin
49 * @ap: ATA port 49 * @ap: ATA port
50 * @deadline: deadline jiffies for the operation
50 * 51 *
51 * Set up cable type and use generic probe init 52 * Set up cable type and use generic probe init
52 */ 53 */
53 54
54static int opti_pre_reset(struct ata_port *ap) 55static int opti_pre_reset(struct ata_port *ap, unsigned long deadline)
55{ 56{
56 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 57 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
57 static const struct pci_bits opti_enable_bits[] = { 58 static const struct pci_bits opti_enable_bits[] = {
@@ -61,7 +62,8 @@ static int opti_pre_reset(struct ata_port *ap)
61 62
62 if (!pci_test_config_bits(pdev, &opti_enable_bits[ap->port_no])) 63 if (!pci_test_config_bits(pdev, &opti_enable_bits[ap->port_no]))
63 return -ENOENT; 64 return -ENOENT;
64 return ata_std_prereset(ap); 65
66 return ata_std_prereset(ap, deadline);
65} 67}
66 68
67/** 69/**
@@ -177,10 +179,6 @@ static struct scsi_host_template opti_sht = {
177 .slave_configure = ata_scsi_slave_config, 179 .slave_configure = ata_scsi_slave_config,
178 .slave_destroy = ata_scsi_slave_destroy, 180 .slave_destroy = ata_scsi_slave_destroy,
179 .bios_param = ata_std_bios_param, 181 .bios_param = ata_std_bios_param,
180#ifdef CONFIG_PM
181 .resume = ata_scsi_device_resume,
182 .suspend = ata_scsi_device_suspend,
183#endif
184}; 182};
185 183
186static struct ata_port_operations opti_port_ops = { 184static struct ata_port_operations opti_port_ops = {
@@ -218,19 +216,19 @@ static struct ata_port_operations opti_port_ops = {
218 216
219static int opti_init_one(struct pci_dev *dev, const struct pci_device_id *id) 217static int opti_init_one(struct pci_dev *dev, const struct pci_device_id *id)
220{ 218{
221 static struct ata_port_info info = { 219 static const struct ata_port_info info = {
222 .sht = &opti_sht, 220 .sht = &opti_sht,
223 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 221 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
224 .pio_mask = 0x1f, 222 .pio_mask = 0x1f,
225 .port_ops = &opti_port_ops 223 .port_ops = &opti_port_ops
226 }; 224 };
227 static struct ata_port_info *port_info[2] = { &info, &info }; 225 const struct ata_port_info *ppi[] = { &info, NULL };
228 static int printed_version; 226 static int printed_version;
229 227
230 if (!printed_version++) 228 if (!printed_version++)
231 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n"); 229 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n");
232 230
233 return ata_pci_init_one(dev, port_info, 2); 231 return ata_pci_init_one(dev, ppi);
234} 232}
235 233
236static const struct pci_device_id opti[] = { 234static const struct pci_device_id opti[] = {
diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
index b70e04c144df..3093b02286ce 100644
--- a/drivers/ata/pata_optidma.c
+++ b/drivers/ata/pata_optidma.c
@@ -48,11 +48,12 @@ static int pci_clock; /* 0 = 33 1 = 25 */
48/** 48/**
49 * optidma_pre_reset - probe begin 49 * optidma_pre_reset - probe begin
50 * @ap: ATA port 50 * @ap: ATA port
51 * @deadline: deadline jiffies for the operation
51 * 52 *
52 * Set up cable type and use generic probe init 53 * Set up cable type and use generic probe init
53 */ 54 */
54 55
55static int optidma_pre_reset(struct ata_port *ap) 56static int optidma_pre_reset(struct ata_port *ap, unsigned long deadline)
56{ 57{
57 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 58 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
58 static const struct pci_bits optidma_enable_bits = { 59 static const struct pci_bits optidma_enable_bits = {
@@ -62,7 +63,7 @@ static int optidma_pre_reset(struct ata_port *ap)
62 if (ap->port_no && !pci_test_config_bits(pdev, &optidma_enable_bits)) 63 if (ap->port_no && !pci_test_config_bits(pdev, &optidma_enable_bits))
63 return -ENOENT; 64 return -ENOENT;
64 65
65 return ata_std_prereset(ap); 66 return ata_std_prereset(ap, deadline);
66} 67}
67 68
68/** 69/**
@@ -362,10 +363,6 @@ static struct scsi_host_template optidma_sht = {
362 .slave_configure = ata_scsi_slave_config, 363 .slave_configure = ata_scsi_slave_config,
363 .slave_destroy = ata_scsi_slave_destroy, 364 .slave_destroy = ata_scsi_slave_destroy,
364 .bios_param = ata_std_bios_param, 365 .bios_param = ata_std_bios_param,
365#ifdef CONFIG_PM
366 .resume = ata_scsi_device_resume,
367 .suspend = ata_scsi_device_suspend,
368#endif
369}; 366};
370 367
371static struct ata_port_operations optidma_port_ops = { 368static struct ata_port_operations optidma_port_ops = {
@@ -485,14 +482,14 @@ done_nomsg: /* Wrong chip revision */
485 482
486static int optidma_init_one(struct pci_dev *dev, const struct pci_device_id *id) 483static int optidma_init_one(struct pci_dev *dev, const struct pci_device_id *id)
487{ 484{
488 static struct ata_port_info info_82c700 = { 485 static const struct ata_port_info info_82c700 = {
489 .sht = &optidma_sht, 486 .sht = &optidma_sht,
490 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 487 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
491 .pio_mask = 0x1f, 488 .pio_mask = 0x1f,
492 .mwdma_mask = 0x07, 489 .mwdma_mask = 0x07,
493 .port_ops = &optidma_port_ops 490 .port_ops = &optidma_port_ops
494 }; 491 };
495 static struct ata_port_info info_82c700_udma = { 492 static const struct ata_port_info info_82c700_udma = {
496 .sht = &optidma_sht, 493 .sht = &optidma_sht,
497 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 494 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
498 .pio_mask = 0x1f, 495 .pio_mask = 0x1f,
@@ -500,8 +497,7 @@ static int optidma_init_one(struct pci_dev *dev, const struct pci_device_id *id)
500 .udma_mask = 0x07, 497 .udma_mask = 0x07,
501 .port_ops = &optiplus_port_ops 498 .port_ops = &optiplus_port_ops
502 }; 499 };
503 static struct ata_port_info *port_info[2]; 500 const struct ata_port_info *ppi[] = { &info_82c700, NULL };
504 struct ata_port_info *info = &info_82c700;
505 static int printed_version; 501 static int printed_version;
506 502
507 if (!printed_version++) 503 if (!printed_version++)
@@ -513,10 +509,9 @@ static int optidma_init_one(struct pci_dev *dev, const struct pci_device_id *id)
513 pci_clock = inb(0x1F5) & 1; /* 0 = 33Mhz, 1 = 25Mhz */ 509 pci_clock = inb(0x1F5) & 1; /* 0 = 33Mhz, 1 = 25Mhz */
514 510
515 if (optiplus_with_udma(dev)) 511 if (optiplus_with_udma(dev))
516 info = &info_82c700_udma; 512 ppi[0] = &info_82c700_udma;
517 513
518 port_info[0] = port_info[1] = info; 514 return ata_pci_init_one(dev, ppi);
519 return ata_pci_init_one(dev, port_info, 2);
520} 515}
521 516
522static const struct pci_device_id optidma[] = { 517static const struct pci_device_id optidma[] = {
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index 75dc84797ff3..4d44c7555db1 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -357,6 +357,7 @@ static struct pcmcia_device_id pcmcia_devices[] = {
357 PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */ 357 PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */
358 PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */ 358 PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */
359 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704), 359 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
360 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904),
360 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */ 361 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */
361 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */ 362 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */
362 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d), 363 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
@@ -396,6 +397,7 @@ static struct pcmcia_device_id pcmcia_devices[] = {
396 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003), 397 PCMCIA_DEVICE_PROD_ID12("TOSHIBA", "MK2001MPL", 0xb4585a1a, 0x3489e003),
397 PCMCIA_DEVICE_PROD_ID1("TRANSCEND 512M ", 0xd0909443), 398 PCMCIA_DEVICE_PROD_ID1("TRANSCEND 512M ", 0xd0909443),
398 PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS1GCF80", 0x709b1bf1, 0x2a54d4b1), 399 PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS1GCF80", 0x709b1bf1, 0x2a54d4b1),
400 PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS2GCF120", 0x709b1bf1, 0x969aa4f2),
399 PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS4GCF120", 0x709b1bf1, 0xf54a91c8), 401 PCMCIA_DEVICE_PROD_ID12("TRANSCEND", "TS4GCF120", 0x709b1bf1, 0xf54a91c8),
400 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852), 402 PCMCIA_DEVICE_PROD_ID12("WIT", "IDE16", 0x244e5994, 0x3e232852),
401 PCMCIA_DEVICE_PROD_ID12("WEIDA", "TWTTI", 0xcc7cf69c, 0x212bb918), 403 PCMCIA_DEVICE_PROD_ID12("WEIDA", "TWTTI", 0xcc7cf69c, 0x212bb918),
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index a61cbc110688..0d2cc49fde4b 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -301,6 +301,7 @@ static inline int pdc2027x_port_enabled(struct ata_port *ap)
301/** 301/**
302 * pdc2027x_prereset - prereset for PATA host controller 302 * pdc2027x_prereset - prereset for PATA host controller
303 * @ap: Target port 303 * @ap: Target port
304 * @deadline: deadline jiffies for the operation
304 * 305 *
305 * Probeinit including cable detection. 306 * Probeinit including cable detection.
306 * 307 *
@@ -308,12 +309,12 @@ static inline int pdc2027x_port_enabled(struct ata_port *ap)
308 * None (inherited from caller). 309 * None (inherited from caller).
309 */ 310 */
310 311
311static int pdc2027x_prereset(struct ata_port *ap) 312static int pdc2027x_prereset(struct ata_port *ap, unsigned long deadline)
312{ 313{
313 /* Check whether port enabled */ 314 /* Check whether port enabled */
314 if (!pdc2027x_port_enabled(ap)) 315 if (!pdc2027x_port_enabled(ap))
315 return -ENOENT; 316 return -ENOENT;
316 return ata_std_prereset(ap); 317 return ata_std_prereset(ap, deadline);
317} 318}
318 319
319/** 320/**
diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
index ee636beb05e1..edbaf9d653b8 100644
--- a/drivers/ata/pata_pdc202xx_old.c
+++ b/drivers/ata/pata_pdc202xx_old.c
@@ -244,10 +244,6 @@ static struct scsi_host_template pdc202xx_sht = {
244 .slave_configure = ata_scsi_slave_config, 244 .slave_configure = ata_scsi_slave_config,
245 .slave_destroy = ata_scsi_slave_destroy, 245 .slave_destroy = ata_scsi_slave_destroy,
246 .bios_param = ata_std_bios_param, 246 .bios_param = ata_std_bios_param,
247#ifdef CONFIG_PM
248 .resume = ata_scsi_device_resume,
249 .suspend = ata_scsi_device_suspend,
250#endif
251}; 247};
252 248
253static struct ata_port_operations pdc2024x_port_ops = { 249static struct ata_port_operations pdc2024x_port_ops = {
@@ -321,7 +317,7 @@ static struct ata_port_operations pdc2026x_port_ops = {
321 317
322static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id) 318static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
323{ 319{
324 static struct ata_port_info info[3] = { 320 static const struct ata_port_info info[3] = {
325 { 321 {
326 .sht = &pdc202xx_sht, 322 .sht = &pdc202xx_sht,
327 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 323 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
@@ -348,9 +344,7 @@ static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id
348 } 344 }
349 345
350 }; 346 };
351 static struct ata_port_info *port_info[2]; 347 const struct ata_port_info *ppi[] = { &info[id->driver_data], NULL };
352
353 port_info[0] = port_info[1] = &info[id->driver_data];
354 348
355 if (dev->device == PCI_DEVICE_ID_PROMISE_20265) { 349 if (dev->device == PCI_DEVICE_ID_PROMISE_20265) {
356 struct pci_dev *bridge = dev->bus->self; 350 struct pci_dev *bridge = dev->bus->self;
@@ -362,7 +356,7 @@ static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id
362 return -ENODEV; 356 return -ENODEV;
363 } 357 }
364 } 358 }
365 return ata_pci_init_one(dev, port_info, 2); 359 return ata_pci_init_one(dev, ppi);
366} 360}
367 361
368static const struct pci_device_id pdc202xx[] = { 362static const struct pci_device_id pdc202xx[] = {
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index a0a650c7f272..cbb7866940d6 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -22,7 +22,7 @@
22#include <linux/pata_platform.h> 22#include <linux/pata_platform.h>
23 23
24#define DRV_NAME "pata_platform" 24#define DRV_NAME "pata_platform"
25#define DRV_VERSION "0.1.2" 25#define DRV_VERSION "1.0"
26 26
27static int pio_mask = 1; 27static int pio_mask = 1;
28 28
@@ -48,6 +48,8 @@ static int pata_platform_set_mode(struct ata_port *ap, struct ata_device **unuse
48 return 0; 48 return 0;
49} 49}
50 50
51static int ata_dummy_ret0(struct ata_port *ap) { return 0; }
52
51static struct scsi_host_template pata_platform_sht = { 53static struct scsi_host_template pata_platform_sht = {
52 .module = THIS_MODULE, 54 .module = THIS_MODULE,
53 .name = DRV_NAME, 55 .name = DRV_NAME,
@@ -91,7 +93,7 @@ static struct ata_port_operations pata_platform_port_ops = {
91 .irq_on = ata_irq_on, 93 .irq_on = ata_irq_on,
92 .irq_ack = ata_irq_ack, 94 .irq_ack = ata_irq_ack,
93 95
94 .port_start = ata_port_start, 96 .port_start = ata_dummy_ret0,
95}; 97};
96 98
97static void pata_platform_setup_port(struct ata_ioports *ioaddr, 99static void pata_platform_setup_port(struct ata_ioports *ioaddr,
diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
index 27685ce63ceb..1998c19e8743 100644
--- a/drivers/ata/pata_qdi.c
+++ b/drivers/ata/pata_qdi.c
@@ -26,7 +26,7 @@
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27 27
28#define DRV_NAME "pata_qdi" 28#define DRV_NAME "pata_qdi"
29#define DRV_VERSION "0.3.0" 29#define DRV_VERSION "0.3.1"
30 30
31#define NR_HOST 4 /* Two 6580s */ 31#define NR_HOST 4 /* Two 6580s */
32 32
@@ -375,7 +375,7 @@ static __init int qdi_init(void)
375 res = inb(port + 3); 375 res = inb(port + 3);
376 if (res & 1) { 376 if (res & 1) {
377 /* Single channel mode */ 377 /* Single channel mode */
378 if (qdi_init_one(port, 6580, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04)) 378 if (qdi_init_one(port, 6580, ide_port[r & 0x01], ide_irq[r & 0x01], r & 0x04) == 0)
379 ct++; 379 ct++;
380 } else { 380 } else {
381 /* Dual channel mode */ 381 /* Dual channel mode */
diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
index 1c54673e008d..ba96b54f5b87 100644
--- a/drivers/ata/pata_radisys.c
+++ b/drivers/ata/pata_radisys.c
@@ -200,10 +200,6 @@ static struct scsi_host_template radisys_sht = {
200 .slave_configure = ata_scsi_slave_config, 200 .slave_configure = ata_scsi_slave_config,
201 .slave_destroy = ata_scsi_slave_destroy, 201 .slave_destroy = ata_scsi_slave_destroy,
202 .bios_param = ata_std_bios_param, 202 .bios_param = ata_std_bios_param,
203#ifdef CONFIG_PM
204 .resume = ata_scsi_device_resume,
205 .suspend = ata_scsi_device_suspend,
206#endif
207}; 203};
208 204
209static const struct ata_port_operations radisys_pata_ops = { 205static const struct ata_port_operations radisys_pata_ops = {
@@ -259,7 +255,7 @@ static const struct ata_port_operations radisys_pata_ops = {
259static int radisys_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 255static int radisys_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
260{ 256{
261 static int printed_version; 257 static int printed_version;
262 static struct ata_port_info info = { 258 static const struct ata_port_info info = {
263 .sht = &radisys_sht, 259 .sht = &radisys_sht,
264 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 260 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
265 .pio_mask = 0x1f, /* pio0-4 */ 261 .pio_mask = 0x1f, /* pio0-4 */
@@ -267,13 +263,13 @@ static int radisys_init_one (struct pci_dev *pdev, const struct pci_device_id *e
267 .udma_mask = 0x14, /* UDMA33/66 only */ 263 .udma_mask = 0x14, /* UDMA33/66 only */
268 .port_ops = &radisys_pata_ops, 264 .port_ops = &radisys_pata_ops,
269 }; 265 };
270 static struct ata_port_info *port_info[2] = { &info, &info }; 266 const struct ata_port_info *ppi[] = { &info, NULL };
271 267
272 if (!printed_version++) 268 if (!printed_version++)
273 dev_printk(KERN_DEBUG, &pdev->dev, 269 dev_printk(KERN_DEBUG, &pdev->dev,
274 "version " DRV_VERSION "\n"); 270 "version " DRV_VERSION "\n");
275 271
276 return ata_pci_init_one(pdev, port_info, 2); 272 return ata_pci_init_one(pdev, ppi);
277} 273}
278 274
279static const struct pci_device_id radisys_pci_tbl[] = { 275static const struct pci_device_id radisys_pci_tbl[] = {
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index 85c45290eeee..a3488b41ad26 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -21,7 +21,7 @@
21#include <linux/libata.h> 21#include <linux/libata.h>
22 22
23#define DRV_NAME "pata_rz1000" 23#define DRV_NAME "pata_rz1000"
24#define DRV_VERSION "0.2.3" 24#define DRV_VERSION "0.2.4"
25 25
26 26
27/** 27/**
@@ -40,7 +40,7 @@ static int rz1000_set_mode(struct ata_port *ap, struct ata_device **unused)
40 40
41 for (i = 0; i < ATA_MAX_DEVICES; i++) { 41 for (i = 0; i < ATA_MAX_DEVICES; i++) {
42 struct ata_device *dev = &ap->device[i]; 42 struct ata_device *dev = &ap->device[i];
43 if (ata_dev_ready(dev)) { 43 if (ata_dev_enabled(dev)) {
44 /* We don't really care */ 44 /* We don't really care */
45 dev->pio_mode = XFER_PIO_0; 45 dev->pio_mode = XFER_PIO_0;
46 dev->xfer_mode = XFER_PIO_0; 46 dev->xfer_mode = XFER_PIO_0;
@@ -69,10 +69,6 @@ static struct scsi_host_template rz1000_sht = {
69 .slave_configure = ata_scsi_slave_config, 69 .slave_configure = ata_scsi_slave_config,
70 .slave_destroy = ata_scsi_slave_destroy, 70 .slave_destroy = ata_scsi_slave_destroy,
71 .bios_param = ata_std_bios_param, 71 .bios_param = ata_std_bios_param,
72#ifdef CONFIG_PM
73 .resume = ata_scsi_device_resume,
74 .suspend = ata_scsi_device_suspend,
75#endif
76}; 72};
77 73
78static struct ata_port_operations rz1000_port_ops = { 74static struct ata_port_operations rz1000_port_ops = {
@@ -135,22 +131,20 @@ static int rz1000_fifo_disable(struct pci_dev *pdev)
135static int rz1000_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 131static int rz1000_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
136{ 132{
137 static int printed_version; 133 static int printed_version;
138 struct ata_port_info *port_info[2]; 134 static const struct ata_port_info info = {
139 static struct ata_port_info info = {
140 .sht = &rz1000_sht, 135 .sht = &rz1000_sht,
141 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 136 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
142 .pio_mask = 0x1f, 137 .pio_mask = 0x1f,
143 .port_ops = &rz1000_port_ops 138 .port_ops = &rz1000_port_ops
144 }; 139 };
140 const struct ata_port_info *ppi[] = { &info, NULL };
145 141
146 if (!printed_version++) 142 if (!printed_version++)
147 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n"); 143 printk(KERN_DEBUG DRV_NAME " version " DRV_VERSION "\n");
148 144
149 if (rz1000_fifo_disable(pdev) == 0) { 145 if (rz1000_fifo_disable(pdev) == 0)
150 port_info[0] = &info; 146 return ata_pci_init_one(pdev, ppi);
151 port_info[1] = &info; 147
152 return ata_pci_init_one(pdev, port_info, 2);
153 }
154 printk(KERN_ERR DRV_NAME ": failed to disable read-ahead on chipset..\n"); 148 printk(KERN_ERR DRV_NAME ": failed to disable read-ahead on chipset..\n");
155 /* Not safe to use so skip */ 149 /* Not safe to use so skip */
156 return -ENODEV; 150 return -ENODEV;
diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
index 66e8ff467c8d..1233063ab9a8 100644
--- a/drivers/ata/pata_sc1200.c
+++ b/drivers/ata/pata_sc1200.c
@@ -40,7 +40,7 @@
40#include <linux/libata.h> 40#include <linux/libata.h>
41 41
42#define DRV_NAME "sc1200" 42#define DRV_NAME "sc1200"
43#define DRV_VERSION "0.2.4" 43#define DRV_VERSION "0.2.5"
44 44
45#define SC1200_REV_A 0x00 45#define SC1200_REV_A 0x00
46#define SC1200_REV_B1 0x01 46#define SC1200_REV_B1 0x01
@@ -194,10 +194,6 @@ static struct scsi_host_template sc1200_sht = {
194 .slave_configure = ata_scsi_slave_config, 194 .slave_configure = ata_scsi_slave_config,
195 .slave_destroy = ata_scsi_slave_destroy, 195 .slave_destroy = ata_scsi_slave_destroy,
196 .bios_param = ata_std_bios_param, 196 .bios_param = ata_std_bios_param,
197#ifdef CONFIG_PM
198 .resume = ata_scsi_device_resume,
199 .suspend = ata_scsi_device_suspend,
200#endif
201}; 197};
202 198
203static struct ata_port_operations sc1200_port_ops = { 199static struct ata_port_operations sc1200_port_ops = {
@@ -247,7 +243,7 @@ static struct ata_port_operations sc1200_port_ops = {
247 243
248static int sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id) 244static int sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id)
249{ 245{
250 static struct ata_port_info info = { 246 static const struct ata_port_info info = {
251 .sht = &sc1200_sht, 247 .sht = &sc1200_sht,
252 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST, 248 .flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST,
253 .pio_mask = 0x1f, 249 .pio_mask = 0x1f,
@@ -255,10 +251,10 @@ static int sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id)
255 .udma_mask = 0x07, 251 .udma_mask = 0x07,
256 .port_ops = &sc1200_port_ops 252 .port_ops = &sc1200_port_ops
257 }; 253 };
258 static struct ata_port_info *port_info[2] = { &info, &info };
259
260 /* Can't enable port 2 yet, see top comments */ 254 /* Can't enable port 2 yet, see top comments */
261 return ata_pci_init_one(dev, port_info, 1); 255 const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
256
257 return ata_pci_init_one(dev, ppi);
262} 258}
263 259
264static const struct pci_device_id sc1200[] = { 260static const struct pci_device_id sc1200[] = {
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index 5df354d573e8..aa138d211b09 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -43,7 +43,7 @@
43#include <linux/libata.h> 43#include <linux/libata.h>
44 44
45#define DRV_NAME "pata_scc" 45#define DRV_NAME "pata_scc"
46#define DRV_VERSION "0.1" 46#define DRV_VERSION "0.2"
47 47
48#define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4 48#define PCI_DEVICE_ID_TOSHIBA_SCC_ATA 0x01b4
49 49
@@ -864,10 +864,10 @@ static void scc_bmdma_freeze (struct ata_port *ap)
864 * @ap: ATA port to be reset 864 * @ap: ATA port to be reset
865 */ 865 */
866 866
867static int scc_pata_prereset (struct ata_port *ap) 867static int scc_pata_prereset (struct ata_port *ap, unsigned long deadline)
868{ 868{
869 ap->cbl = ATA_CBL_PATA80; 869 ap->cbl = ATA_CBL_PATA80;
870 return ata_std_prereset(ap); 870 return ata_std_prereset(ap, deadline);
871} 871}
872 872
873/** 873/**
@@ -984,10 +984,6 @@ static struct scsi_host_template scc_sht = {
984 .slave_configure = ata_scsi_slave_config, 984 .slave_configure = ata_scsi_slave_config,
985 .slave_destroy = ata_scsi_slave_destroy, 985 .slave_destroy = ata_scsi_slave_destroy,
986 .bios_param = ata_std_bios_param, 986 .bios_param = ata_std_bios_param,
987#ifdef CONFIG_PM
988 .resume = ata_scsi_device_resume,
989 .suspend = ata_scsi_device_suspend,
990#endif
991}; 987};
992 988
993static const struct ata_port_operations scc_pata_ops = { 989static const struct ata_port_operations scc_pata_ops = {
@@ -1142,14 +1138,14 @@ static int scc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1142 static int printed_version; 1138 static int printed_version;
1143 unsigned int board_idx = (unsigned int) ent->driver_data; 1139 unsigned int board_idx = (unsigned int) ent->driver_data;
1144 const struct ata_port_info *ppi[] = { &scc_port_info[board_idx], NULL }; 1140 const struct ata_port_info *ppi[] = { &scc_port_info[board_idx], NULL };
1145 struct device *dev = &pdev->dev; 1141 struct ata_host *host;
1146 int rc; 1142 int rc;
1147 1143
1148 if (!printed_version++) 1144 if (!printed_version++)
1149 dev_printk(KERN_DEBUG, &pdev->dev, 1145 dev_printk(KERN_DEBUG, &pdev->dev,
1150 "version " DRV_VERSION "\n"); 1146 "version " DRV_VERSION "\n");
1151 1147
1152 host = ata_port_alloc_pinfo(&pdev->dev, ppi, 1); 1148 host = ata_host_alloc_pinfo(&pdev->dev, ppi, 1);
1153 if (!host) 1149 if (!host)
1154 return -ENOMEM; 1150 return -ENOMEM;
1155 1151
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index 3956ef26936d..1e8f421963c7 100644
--- a/drivers/ata/pata_serverworks.c
+++ b/drivers/ata/pata_serverworks.c
@@ -41,7 +41,7 @@
41#include <linux/libata.h> 41#include <linux/libata.h>
42 42
43#define DRV_NAME "pata_serverworks" 43#define DRV_NAME "pata_serverworks"
44#define DRV_VERSION "0.4.0" 44#define DRV_VERSION "0.4.1"
45 45
46#define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */ 46#define SVWKS_CSB5_REVISION_NEW 0x92 /* min PCI_REVISION_ID for UDMA5 (A2.0) */
47#define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */ 47#define SVWKS_CSB6_REVISION 0xa0 /* min PCI_REVISION_ID for UDMA4 (A1.0) */
@@ -139,12 +139,14 @@ static struct sv_cable_table cable_detect[] = {
139/** 139/**
140 * serverworks_cable_detect - cable detection 140 * serverworks_cable_detect - cable detection
141 * @ap: ATA port 141 * @ap: ATA port
142 * @deadline: deadline jiffies for the operation
142 * 143 *
143 * Perform cable detection according to the device and subvendor 144 * Perform cable detection according to the device and subvendor
144 * identifications 145 * identifications
145 */ 146 */
146 147
147static int serverworks_cable_detect(struct ata_port *ap) { 148static int serverworks_cable_detect(struct ata_port *ap)
149{
148 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 150 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
149 struct sv_cable_table *cb = cable_detect; 151 struct sv_cable_table *cb = cable_detect;
150 152
@@ -313,10 +315,6 @@ static struct scsi_host_template serverworks_sht = {
313 .slave_configure = ata_scsi_slave_config, 315 .slave_configure = ata_scsi_slave_config,
314 .slave_destroy = ata_scsi_slave_destroy, 316 .slave_destroy = ata_scsi_slave_destroy,
315 .bios_param = ata_std_bios_param, 317 .bios_param = ata_std_bios_param,
316#ifdef CONFIG_PM
317 .resume = ata_scsi_device_resume,
318 .suspend = ata_scsi_device_suspend,
319#endif
320}; 318};
321 319
322static struct ata_port_operations serverworks_osb4_port_ops = { 320static struct ata_port_operations serverworks_osb4_port_ops = {
@@ -477,8 +475,7 @@ static void serverworks_fixup_ht1000(struct pci_dev *pdev)
477 475
478static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 476static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
479{ 477{
480 int ports = 2; 478 static const struct ata_port_info info[4] = {
481 static struct ata_port_info info[4] = {
482 { /* OSB4 */ 479 { /* OSB4 */
483 .sht = &serverworks_sht, 480 .sht = &serverworks_sht,
484 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 481 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
@@ -509,8 +506,7 @@ static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id
509 .port_ops = &serverworks_csb_port_ops 506 .port_ops = &serverworks_csb_port_ops
510 } 507 }
511 }; 508 };
512 static struct ata_port_info *port_info[2]; 509 const struct ata_port_info *ppi[] = { &info[id->driver_data], NULL };
513 struct ata_port_info *devinfo = &info[id->driver_data];
514 510
515 /* Force master latency timer to 64 PCI clocks */ 511 /* Force master latency timer to 64 PCI clocks */
516 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40); 512 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40);
@@ -519,7 +515,7 @@ static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id
519 if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { 515 if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
520 /* Select non UDMA capable OSB4 if we can't do fixups */ 516 /* Select non UDMA capable OSB4 if we can't do fixups */
521 if ( serverworks_fixup_osb4(pdev) < 0) 517 if ( serverworks_fixup_osb4(pdev) < 0)
522 devinfo = &info[1]; 518 ppi[0] = &info[1];
523 } 519 }
524 /* setup CSB5/CSB6 : South Bridge and IDE option RAID */ 520 /* setup CSB5/CSB6 : South Bridge and IDE option RAID */
525 else if ((pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) || 521 else if ((pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) ||
@@ -529,11 +525,11 @@ static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id
529 /* If the returned btr is the newer revision then 525 /* If the returned btr is the newer revision then
530 select the right info block */ 526 select the right info block */
531 if (serverworks_fixup_csb(pdev) == 3) 527 if (serverworks_fixup_csb(pdev) == 3)
532 devinfo = &info[3]; 528 ppi[0] = &info[3];
533 529
534 /* Is this the 3rd channel CSB6 IDE ? */ 530 /* Is this the 3rd channel CSB6 IDE ? */
535 if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2) 531 if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)
536 ports = 1; 532 ppi[1] = &ata_dummy_port_info;
537 } 533 }
538 /* setup HT1000E */ 534 /* setup HT1000E */
539 else if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) 535 else if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE)
@@ -542,8 +538,7 @@ static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id
542 if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE) 538 if (pdev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5IDE)
543 ata_pci_clear_simplex(pdev); 539 ata_pci_clear_simplex(pdev);
544 540
545 port_info[0] = port_info[1] = devinfo; 541 return ata_pci_init_one(pdev, ppi);
546 return ata_pci_init_one(pdev, port_info, ports);
547} 542}
548 543
549#ifdef CONFIG_PM 544#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 6770820cfca9..440e2cb6ee75 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -94,11 +94,13 @@ static int sil680_cable_detect(struct ata_port *ap) {
94/** 94/**
95 * sil680_bus_reset - reset the SIL680 bus 95 * sil680_bus_reset - reset the SIL680 bus
96 * @ap: ATA port to reset 96 * @ap: ATA port to reset
97 * @deadline: deadline jiffies for the operation
97 * 98 *
98 * Perform the SIL680 housekeeping when doing an ATA bus reset 99 * Perform the SIL680 housekeeping when doing an ATA bus reset
99 */ 100 */
100 101
101static int sil680_bus_reset(struct ata_port *ap,unsigned int *classes) 102static int sil680_bus_reset(struct ata_port *ap,unsigned int *classes,
103 unsigned long deadline)
102{ 104{
103 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 105 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
104 unsigned long addr = sil680_selreg(ap, 0); 106 unsigned long addr = sil680_selreg(ap, 0);
@@ -108,7 +110,7 @@ static int sil680_bus_reset(struct ata_port *ap,unsigned int *classes)
108 pci_write_config_byte(pdev, addr, reset | 0x03); 110 pci_write_config_byte(pdev, addr, reset | 0x03);
109 udelay(25); 111 udelay(25);
110 pci_write_config_byte(pdev, addr, reset); 112 pci_write_config_byte(pdev, addr, reset);
111 return ata_std_softreset(ap, classes); 113 return ata_std_softreset(ap, classes, deadline);
112} 114}
113 115
114static void sil680_error_handler(struct ata_port *ap) 116static void sil680_error_handler(struct ata_port *ap)
@@ -230,10 +232,6 @@ static struct scsi_host_template sil680_sht = {
230 .slave_configure = ata_scsi_slave_config, 232 .slave_configure = ata_scsi_slave_config,
231 .slave_destroy = ata_scsi_slave_destroy, 233 .slave_destroy = ata_scsi_slave_destroy,
232 .bios_param = ata_std_bios_param, 234 .bios_param = ata_std_bios_param,
233#ifdef CONFIG_PM
234 .suspend = ata_scsi_device_suspend,
235 .resume = ata_scsi_device_resume,
236#endif
237}; 235};
238 236
239static struct ata_port_operations sil680_port_ops = { 237static struct ata_port_operations sil680_port_ops = {
@@ -343,7 +341,7 @@ static u8 sil680_init_chip(struct pci_dev *pdev)
343 341
344static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 342static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
345{ 343{
346 static struct ata_port_info info = { 344 static const struct ata_port_info info = {
347 .sht = &sil680_sht, 345 .sht = &sil680_sht,
348 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 346 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
349 .pio_mask = 0x1f, 347 .pio_mask = 0x1f,
@@ -351,7 +349,7 @@ static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
351 .udma_mask = 0x7f, 349 .udma_mask = 0x7f,
352 .port_ops = &sil680_port_ops 350 .port_ops = &sil680_port_ops
353 }; 351 };
354 static struct ata_port_info info_slow = { 352 static const struct ata_port_info info_slow = {
355 .sht = &sil680_sht, 353 .sht = &sil680_sht,
356 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 354 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
357 .pio_mask = 0x1f, 355 .pio_mask = 0x1f,
@@ -359,7 +357,7 @@ static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
359 .udma_mask = 0x3f, 357 .udma_mask = 0x3f,
360 .port_ops = &sil680_port_ops 358 .port_ops = &sil680_port_ops
361 }; 359 };
362 static struct ata_port_info *port_info[2] = {&info, &info}; 360 const struct ata_port_info *ppi[] = { &info, NULL };
363 static int printed_version; 361 static int printed_version;
364 362
365 if (!printed_version++) 363 if (!printed_version++)
@@ -368,12 +366,12 @@ static int sil680_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
368 switch(sil680_init_chip(pdev)) 366 switch(sil680_init_chip(pdev))
369 { 367 {
370 case 0: 368 case 0:
371 port_info[0] = port_info[1] = &info_slow; 369 ppi[0] = &info_slow;
372 break; 370 break;
373 case 0x30: 371 case 0x30:
374 return -ENODEV; 372 return -ENODEV;
375 } 373 }
376 return ata_pci_init_one(pdev, port_info, 2); 374 return ata_pci_init_one(pdev, ppi);
377} 375}
378 376
379#ifdef CONFIG_PM 377#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index a3fbcee6fb33..f2231267e011 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -38,8 +38,8 @@
38#define DRV_VERSION "0.5.1" 38#define DRV_VERSION "0.5.1"
39 39
40struct sis_chipset { 40struct sis_chipset {
41 u16 device; /* PCI host ID */ 41 u16 device; /* PCI host ID */
42 struct ata_port_info *info; /* Info block */ 42 const struct ata_port_info *info; /* Info block */
43 /* Probably add family, cable detect type etc here to clean 43 /* Probably add family, cable detect type etc here to clean
44 up code later */ 44 up code later */
45}; 45};
@@ -88,6 +88,7 @@ static int sis_port_base(struct ata_device *adev)
88/** 88/**
89 * sis_133_cable_detect - check for 40/80 pin 89 * sis_133_cable_detect - check for 40/80 pin
90 * @ap: Port 90 * @ap: Port
91 * @deadline: deadline jiffies for the operation
91 * 92 *
92 * Perform cable detection for the later UDMA133 capable 93 * Perform cable detection for the later UDMA133 capable
93 * SiS chipset. 94 * SiS chipset.
@@ -108,6 +109,7 @@ static int sis_133_cable_detect(struct ata_port *ap)
108/** 109/**
109 * sis_66_cable_detect - check for 40/80 pin 110 * sis_66_cable_detect - check for 40/80 pin
110 * @ap: Port 111 * @ap: Port
112 * @deadline: deadline jiffies for the operation
111 * 113 *
112 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133 114 * Perform cable detection on the UDMA66, UDMA100 and early UDMA133
113 * SiS IDE controllers. 115 * SiS IDE controllers.
@@ -130,11 +132,12 @@ static int sis_66_cable_detect(struct ata_port *ap)
130/** 132/**
131 * sis_pre_reset - probe begin 133 * sis_pre_reset - probe begin
132 * @ap: ATA port 134 * @ap: ATA port
135 * @deadline: deadline jiffies for the operation
133 * 136 *
134 * Set up cable type and use generic probe init 137 * Set up cable type and use generic probe init
135 */ 138 */
136 139
137static int sis_pre_reset(struct ata_port *ap) 140static int sis_pre_reset(struct ata_port *ap, unsigned long deadline)
138{ 141{
139 static const struct pci_bits sis_enable_bits[] = { 142 static const struct pci_bits sis_enable_bits[] = {
140 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */ 143 { 0x4aU, 1U, 0x02UL, 0x02UL }, /* port 0 */
@@ -145,7 +148,8 @@ static int sis_pre_reset(struct ata_port *ap)
145 148
146 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no])) 149 if (!pci_test_config_bits(pdev, &sis_enable_bits[ap->port_no]))
147 return -ENOENT; 150 return -ENOENT;
148 return ata_std_prereset(ap); 151
152 return ata_std_prereset(ap, deadline);
149} 153}
150 154
151 155
@@ -520,10 +524,6 @@ static struct scsi_host_template sis_sht = {
520 .slave_configure = ata_scsi_slave_config, 524 .slave_configure = ata_scsi_slave_config,
521 .slave_destroy = ata_scsi_slave_destroy, 525 .slave_destroy = ata_scsi_slave_destroy,
522 .bios_param = ata_std_bios_param, 526 .bios_param = ata_std_bios_param,
523#ifdef CONFIG_PM
524 .resume = ata_scsi_device_resume,
525 .suspend = ata_scsi_device_suspend,
526#endif
527}; 527};
528 528
529static const struct ata_port_operations sis_133_ops = { 529static const struct ata_port_operations sis_133_ops = {
@@ -696,7 +696,7 @@ static const struct ata_port_operations sis_old_ops = {
696 .port_start = ata_port_start, 696 .port_start = ata_port_start,
697}; 697};
698 698
699static struct ata_port_info sis_info = { 699static const struct ata_port_info sis_info = {
700 .sht = &sis_sht, 700 .sht = &sis_sht,
701 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 701 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
702 .pio_mask = 0x1f, /* pio0-4 */ 702 .pio_mask = 0x1f, /* pio0-4 */
@@ -704,7 +704,7 @@ static struct ata_port_info sis_info = {
704 .udma_mask = 0, 704 .udma_mask = 0,
705 .port_ops = &sis_old_ops, 705 .port_ops = &sis_old_ops,
706}; 706};
707static struct ata_port_info sis_info33 = { 707static const struct ata_port_info sis_info33 = {
708 .sht = &sis_sht, 708 .sht = &sis_sht,
709 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 709 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
710 .pio_mask = 0x1f, /* pio0-4 */ 710 .pio_mask = 0x1f, /* pio0-4 */
@@ -712,35 +712,35 @@ static struct ata_port_info sis_info33 = {
712 .udma_mask = ATA_UDMA2, /* UDMA 33 */ 712 .udma_mask = ATA_UDMA2, /* UDMA 33 */
713 .port_ops = &sis_old_ops, 713 .port_ops = &sis_old_ops,
714}; 714};
715static struct ata_port_info sis_info66 = { 715static const struct ata_port_info sis_info66 = {
716 .sht = &sis_sht, 716 .sht = &sis_sht,
717 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 717 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
718 .pio_mask = 0x1f, /* pio0-4 */ 718 .pio_mask = 0x1f, /* pio0-4 */
719 .udma_mask = ATA_UDMA4, /* UDMA 66 */ 719 .udma_mask = ATA_UDMA4, /* UDMA 66 */
720 .port_ops = &sis_66_ops, 720 .port_ops = &sis_66_ops,
721}; 721};
722static struct ata_port_info sis_info100 = { 722static const struct ata_port_info sis_info100 = {
723 .sht = &sis_sht, 723 .sht = &sis_sht,
724 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 724 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
725 .pio_mask = 0x1f, /* pio0-4 */ 725 .pio_mask = 0x1f, /* pio0-4 */
726 .udma_mask = ATA_UDMA5, 726 .udma_mask = ATA_UDMA5,
727 .port_ops = &sis_100_ops, 727 .port_ops = &sis_100_ops,
728}; 728};
729static struct ata_port_info sis_info100_early = { 729static const struct ata_port_info sis_info100_early = {
730 .sht = &sis_sht, 730 .sht = &sis_sht,
731 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 731 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
732 .udma_mask = ATA_UDMA5, 732 .udma_mask = ATA_UDMA5,
733 .pio_mask = 0x1f, /* pio0-4 */ 733 .pio_mask = 0x1f, /* pio0-4 */
734 .port_ops = &sis_66_ops, 734 .port_ops = &sis_66_ops,
735}; 735};
736struct ata_port_info sis_info133 = { 736const struct ata_port_info sis_info133 = {
737 .sht = &sis_sht, 737 .sht = &sis_sht,
738 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 738 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
739 .pio_mask = 0x1f, /* pio0-4 */ 739 .pio_mask = 0x1f, /* pio0-4 */
740 .udma_mask = ATA_UDMA6, 740 .udma_mask = ATA_UDMA6,
741 .port_ops = &sis_133_ops, 741 .port_ops = &sis_133_ops,
742}; 742};
743static struct ata_port_info sis_info133_early = { 743static const struct ata_port_info sis_info133_early = {
744 .sht = &sis_sht, 744 .sht = &sis_sht,
745 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 745 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
746 .pio_mask = 0x1f, /* pio0-4 */ 746 .pio_mask = 0x1f, /* pio0-4 */
@@ -823,8 +823,8 @@ static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
823static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 823static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
824{ 824{
825 static int printed_version; 825 static int printed_version;
826 static struct ata_port_info *port_info[2]; 826 struct ata_port_info port;
827 struct ata_port_info *port; 827 const struct ata_port_info *ppi[] = { &port, NULL };
828 struct pci_dev *host = NULL; 828 struct pci_dev *host = NULL;
829 struct sis_chipset *chipset = NULL; 829 struct sis_chipset *chipset = NULL;
830 struct sis_chipset *sets; 830 struct sis_chipset *sets;
@@ -964,13 +964,12 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
964 if (chipset == NULL) 964 if (chipset == NULL)
965 return -ENODEV; 965 return -ENODEV;
966 966
967 port = chipset->info; 967 port = *chipset->info;
968 port->private_data = chipset; 968 port.private_data = chipset;
969 969
970 sis_fixup(pdev, chipset); 970 sis_fixup(pdev, chipset);
971 971
972 port_info[0] = port_info[1] = port; 972 return ata_pci_init_one(pdev, ppi);
973 return ata_pci_init_one(pdev, port_info, 2);
974} 973}
975 974
976static const struct pci_device_id sis_pci_tbl[] = { 975static const struct pci_device_id sis_pci_tbl[] = {
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
index da9e22b25753..e5aaec43694d 100644
--- a/drivers/ata/pata_sl82c105.c
+++ b/drivers/ata/pata_sl82c105.c
@@ -26,7 +26,7 @@
26#include <linux/libata.h> 26#include <linux/libata.h>
27 27
28#define DRV_NAME "pata_sl82c105" 28#define DRV_NAME "pata_sl82c105"
29#define DRV_VERSION "0.3.0" 29#define DRV_VERSION "0.3.1"
30 30
31enum { 31enum {
32 /* 32 /*
@@ -44,11 +44,12 @@ enum {
44/** 44/**
45 * sl82c105_pre_reset - probe begin 45 * sl82c105_pre_reset - probe begin
46 * @ap: ATA port 46 * @ap: ATA port
47 * @deadline: deadline jiffies for the operation
47 * 48 *
48 * Set up cable type and use generic probe init 49 * Set up cable type and use generic probe init
49 */ 50 */
50 51
51static int sl82c105_pre_reset(struct ata_port *ap) 52static int sl82c105_pre_reset(struct ata_port *ap, unsigned long deadline)
52{ 53{
53 static const struct pci_bits sl82c105_enable_bits[] = { 54 static const struct pci_bits sl82c105_enable_bits[] = {
54 { 0x40, 1, 0x01, 0x01 }, 55 { 0x40, 1, 0x01, 0x01 },
@@ -58,7 +59,7 @@ static int sl82c105_pre_reset(struct ata_port *ap)
58 59
59 if (ap->port_no && !pci_test_config_bits(pdev, &sl82c105_enable_bits[ap->port_no])) 60 if (ap->port_no && !pci_test_config_bits(pdev, &sl82c105_enable_bits[ap->port_no]))
60 return -ENOENT; 61 return -ENOENT;
61 return ata_std_prereset(ap); 62 return ata_std_prereset(ap, deadline);
62} 63}
63 64
64 65
@@ -300,20 +301,22 @@ static int sl82c105_bridge_revision(struct pci_dev *pdev)
300 301
301static int sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id) 302static int sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id)
302{ 303{
303 static struct ata_port_info info_dma = { 304 static const struct ata_port_info info_dma = {
304 .sht = &sl82c105_sht, 305 .sht = &sl82c105_sht,
305 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 306 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
306 .pio_mask = 0x1f, 307 .pio_mask = 0x1f,
307 .mwdma_mask = 0x07, 308 .mwdma_mask = 0x07,
308 .port_ops = &sl82c105_port_ops 309 .port_ops = &sl82c105_port_ops
309 }; 310 };
310 static struct ata_port_info info_early = { 311 static const struct ata_port_info info_early = {
311 .sht = &sl82c105_sht, 312 .sht = &sl82c105_sht,
312 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 313 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
313 .pio_mask = 0x1f, 314 .pio_mask = 0x1f,
314 .port_ops = &sl82c105_port_ops 315 .port_ops = &sl82c105_port_ops
315 }; 316 };
316 static struct ata_port_info *port_info[2] = { &info_early, &info_early }; 317 /* for now use only the first port */
318 const struct ata_port_info *ppi[] = { &info_early,
319 &ata_dummy_port_info };
317 u32 val; 320 u32 val;
318 int rev; 321 int rev;
319 322
@@ -323,17 +326,14 @@ static int sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id
323 dev_printk(KERN_WARNING, &dev->dev, "pata_sl82c105: Unable to find bridge, disabling DMA.\n"); 326 dev_printk(KERN_WARNING, &dev->dev, "pata_sl82c105: Unable to find bridge, disabling DMA.\n");
324 else if (rev <= 5) 327 else if (rev <= 5)
325 dev_printk(KERN_WARNING, &dev->dev, "pata_sl82c105: Early bridge revision, no DMA available.\n"); 328 dev_printk(KERN_WARNING, &dev->dev, "pata_sl82c105: Early bridge revision, no DMA available.\n");
326 else { 329 else
327 port_info[0] = &info_dma; 330 ppi[0] = &info_dma;
328 port_info[1] = &info_dma;
329 }
330 331
331 pci_read_config_dword(dev, 0x40, &val); 332 pci_read_config_dword(dev, 0x40, &val);
332 val |= CTRL_P0EN | CTRL_P0F16 | CTRL_P1F16; 333 val |= CTRL_P0EN | CTRL_P0F16 | CTRL_P1F16;
333 pci_write_config_dword(dev, 0x40, val); 334 pci_write_config_dword(dev, 0x40, val);
334 335
335 336 return ata_pci_init_one(dev, ppi);
336 return ata_pci_init_one(dev, port_info, 1); /* For now */
337} 337}
338 338
339static const struct pci_device_id sl82c105[] = { 339static const struct pci_device_id sl82c105[] = {
diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
index e618ffd6e944..b1d3076dfe51 100644
--- a/drivers/ata/pata_triflex.c
+++ b/drivers/ata/pata_triflex.c
@@ -48,11 +48,12 @@
48/** 48/**
49 * triflex_prereset - probe begin 49 * triflex_prereset - probe begin
50 * @ap: ATA port 50 * @ap: ATA port
51 * @deadline: deadline jiffies for the operation
51 * 52 *
52 * Set up cable type and use generic probe init 53 * Set up cable type and use generic probe init
53 */ 54 */
54 55
55static int triflex_prereset(struct ata_port *ap) 56static int triflex_prereset(struct ata_port *ap, unsigned long deadline)
56{ 57{
57 static const struct pci_bits triflex_enable_bits[] = { 58 static const struct pci_bits triflex_enable_bits[] = {
58 { 0x80, 1, 0x01, 0x01 }, 59 { 0x80, 1, 0x01, 0x01 },
@@ -63,7 +64,8 @@ static int triflex_prereset(struct ata_port *ap)
63 64
64 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no])) 65 if (!pci_test_config_bits(pdev, &triflex_enable_bits[ap->port_no]))
65 return -ENOENT; 66 return -ENOENT;
66 return ata_std_prereset(ap); 67
68 return ata_std_prereset(ap, deadline);
67} 69}
68 70
69 71
@@ -192,10 +194,6 @@ static struct scsi_host_template triflex_sht = {
192 .slave_configure = ata_scsi_slave_config, 194 .slave_configure = ata_scsi_slave_config,
193 .slave_destroy = ata_scsi_slave_destroy, 195 .slave_destroy = ata_scsi_slave_destroy,
194 .bios_param = ata_std_bios_param, 196 .bios_param = ata_std_bios_param,
195#ifdef CONFIG_PM
196 .resume = ata_scsi_device_resume,
197 .suspend = ata_scsi_device_suspend,
198#endif
199}; 197};
200 198
201static struct ata_port_operations triflex_port_ops = { 199static struct ata_port_operations triflex_port_ops = {
@@ -235,20 +233,20 @@ static struct ata_port_operations triflex_port_ops = {
235 233
236static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id) 234static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
237{ 235{
238 static struct ata_port_info info = { 236 static const struct ata_port_info info = {
239 .sht = &triflex_sht, 237 .sht = &triflex_sht,
240 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 238 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
241 .pio_mask = 0x1f, 239 .pio_mask = 0x1f,
242 .mwdma_mask = 0x07, 240 .mwdma_mask = 0x07,
243 .port_ops = &triflex_port_ops 241 .port_ops = &triflex_port_ops
244 }; 242 };
245 static struct ata_port_info *port_info[2] = { &info, &info }; 243 const struct ata_port_info *ppi[] = { &info, NULL };
246 static int printed_version; 244 static int printed_version;
247 245
248 if (!printed_version++) 246 if (!printed_version++)
249 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n"); 247 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n");
250 248
251 return ata_pci_init_one(dev, port_info, 2); 249 return ata_pci_init_one(dev, ppi);
252} 250}
253 251
254static const struct pci_device_id triflex[] = { 252static const struct pci_device_id triflex[] = {
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index 96b71791d2f4..e4c71f76bd55 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -154,7 +154,7 @@ static int via_cable_detect(struct ata_port *ap) {
154 return ATA_CBL_PATA40; 154 return ATA_CBL_PATA40;
155} 155}
156 156
157static int via_pre_reset(struct ata_port *ap) 157static int via_pre_reset(struct ata_port *ap, unsigned long deadline)
158{ 158{
159 const struct via_isa_bridge *config = ap->host->private_data; 159 const struct via_isa_bridge *config = ap->host->private_data;
160 160
@@ -167,7 +167,8 @@ static int via_pre_reset(struct ata_port *ap)
167 if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no])) 167 if (!pci_test_config_bits(pdev, &via_enable_bits[ap->port_no]))
168 return -ENOENT; 168 return -ENOENT;
169 } 169 }
170 return ata_std_prereset(ap); 170
171 return ata_std_prereset(ap, deadline);
171} 172}
172 173
173 174
@@ -300,10 +301,6 @@ static struct scsi_host_template via_sht = {
300 .slave_configure = ata_scsi_slave_config, 301 .slave_configure = ata_scsi_slave_config,
301 .slave_destroy = ata_scsi_slave_destroy, 302 .slave_destroy = ata_scsi_slave_destroy,
302 .bios_param = ata_std_bios_param, 303 .bios_param = ata_std_bios_param,
303#ifdef CONFIG_PM
304 .resume = ata_scsi_device_resume,
305 .suspend = ata_scsi_device_suspend,
306#endif
307}; 304};
308 305
309static struct ata_port_operations via_port_ops = { 306static struct ata_port_operations via_port_ops = {
@@ -424,7 +421,7 @@ static void via_config_fifo(struct pci_dev *pdev, unsigned int flags)
424static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 421static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
425{ 422{
426 /* Early VIA without UDMA support */ 423 /* Early VIA without UDMA support */
427 static struct ata_port_info via_mwdma_info = { 424 static const struct ata_port_info via_mwdma_info = {
428 .sht = &via_sht, 425 .sht = &via_sht,
429 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING, 426 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
430 .pio_mask = 0x1f, 427 .pio_mask = 0x1f,
@@ -432,7 +429,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
432 .port_ops = &via_port_ops 429 .port_ops = &via_port_ops
433 }; 430 };
434 /* Ditto with IRQ masking required */ 431 /* Ditto with IRQ masking required */
435 static struct ata_port_info via_mwdma_info_borked = { 432 static const struct ata_port_info via_mwdma_info_borked = {
436 .sht = &via_sht, 433 .sht = &via_sht,
437 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING, 434 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
438 .pio_mask = 0x1f, 435 .pio_mask = 0x1f,
@@ -440,7 +437,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
440 .port_ops = &via_port_ops_noirq, 437 .port_ops = &via_port_ops_noirq,
441 }; 438 };
442 /* VIA UDMA 33 devices (and borked 66) */ 439 /* VIA UDMA 33 devices (and borked 66) */
443 static struct ata_port_info via_udma33_info = { 440 static const struct ata_port_info via_udma33_info = {
444 .sht = &via_sht, 441 .sht = &via_sht,
445 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING, 442 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
446 .pio_mask = 0x1f, 443 .pio_mask = 0x1f,
@@ -449,7 +446,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
449 .port_ops = &via_port_ops 446 .port_ops = &via_port_ops
450 }; 447 };
451 /* VIA UDMA 66 devices */ 448 /* VIA UDMA 66 devices */
452 static struct ata_port_info via_udma66_info = { 449 static const struct ata_port_info via_udma66_info = {
453 .sht = &via_sht, 450 .sht = &via_sht,
454 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING, 451 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
455 .pio_mask = 0x1f, 452 .pio_mask = 0x1f,
@@ -458,7 +455,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
458 .port_ops = &via_port_ops 455 .port_ops = &via_port_ops
459 }; 456 };
460 /* VIA UDMA 100 devices */ 457 /* VIA UDMA 100 devices */
461 static struct ata_port_info via_udma100_info = { 458 static const struct ata_port_info via_udma100_info = {
462 .sht = &via_sht, 459 .sht = &via_sht,
463 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING, 460 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
464 .pio_mask = 0x1f, 461 .pio_mask = 0x1f,
@@ -467,7 +464,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
467 .port_ops = &via_port_ops 464 .port_ops = &via_port_ops
468 }; 465 };
469 /* UDMA133 with bad AST (All current 133) */ 466 /* UDMA133 with bad AST (All current 133) */
470 static struct ata_port_info via_udma133_info = { 467 static const struct ata_port_info via_udma133_info = {
471 .sht = &via_sht, 468 .sht = &via_sht,
472 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING, 469 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SETXFER_POLLING,
473 .pio_mask = 0x1f, 470 .pio_mask = 0x1f,
@@ -475,7 +472,8 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
475 .udma_mask = 0x7f, /* FIXME: should check north bridge */ 472 .udma_mask = 0x7f, /* FIXME: should check north bridge */
476 .port_ops = &via_port_ops 473 .port_ops = &via_port_ops
477 }; 474 };
478 struct ata_port_info *port_info[2], *type; 475 struct ata_port_info type;
476 const struct ata_port_info *ppi[] = { &type, NULL };
479 struct pci_dev *isa = NULL; 477 struct pci_dev *isa = NULL;
480 const struct via_isa_bridge *config; 478 const struct via_isa_bridge *config;
481 static int printed_version; 479 static int printed_version;
@@ -520,25 +518,25 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
520 switch(config->flags & VIA_UDMA) { 518 switch(config->flags & VIA_UDMA) {
521 case VIA_UDMA_NONE: 519 case VIA_UDMA_NONE:
522 if (config->flags & VIA_NO_UNMASK) 520 if (config->flags & VIA_NO_UNMASK)
523 type = &via_mwdma_info_borked; 521 type = via_mwdma_info_borked;
524 else 522 else
525 type = &via_mwdma_info; 523 type = via_mwdma_info;
526 break; 524 break;
527 case VIA_UDMA_33: 525 case VIA_UDMA_33:
528 type = &via_udma33_info; 526 type = via_udma33_info;
529 break; 527 break;
530 case VIA_UDMA_66: 528 case VIA_UDMA_66:
531 type = &via_udma66_info; 529 type = via_udma66_info;
532 /* The 66 MHz devices require we enable the clock */ 530 /* The 66 MHz devices require we enable the clock */
533 pci_read_config_dword(pdev, 0x50, &timing); 531 pci_read_config_dword(pdev, 0x50, &timing);
534 timing |= 0x80008; 532 timing |= 0x80008;
535 pci_write_config_dword(pdev, 0x50, timing); 533 pci_write_config_dword(pdev, 0x50, timing);
536 break; 534 break;
537 case VIA_UDMA_100: 535 case VIA_UDMA_100:
538 type = &via_udma100_info; 536 type = via_udma100_info;
539 break; 537 break;
540 case VIA_UDMA_133: 538 case VIA_UDMA_133:
541 type = &via_udma133_info; 539 type = via_udma133_info;
542 break; 540 break;
543 default: 541 default:
544 WARN_ON(1); 542 WARN_ON(1);
@@ -553,10 +551,9 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
553 } 551 }
554 552
555 /* We have established the device type, now fire it up */ 553 /* We have established the device type, now fire it up */
556 type->private_data = (void *)config; 554 type.private_data = (void *)config;
557 555
558 port_info[0] = port_info[1] = type; 556 return ata_pci_init_one(pdev, ppi);
559 return ata_pci_init_one(pdev, port_info, 2);
560} 557}
561 558
562#ifdef CONFIG_PM 559#ifdef CONFIG_PM
diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
index cc4ad271afb5..83abfeca4057 100644
--- a/drivers/ata/pata_winbond.c
+++ b/drivers/ata/pata_winbond.c
@@ -16,7 +16,7 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17 17
18#define DRV_NAME "pata_winbond" 18#define DRV_NAME "pata_winbond"
19#define DRV_VERSION "0.0.2" 19#define DRV_VERSION "0.0.3"
20 20
21#define NR_HOST 4 /* Two winbond controllers, two channels each */ 21#define NR_HOST 4 /* Two winbond controllers, two channels each */
22 22
diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
index 52b69530ab29..f12c2b6ac08e 100644
--- a/drivers/ata/pdc_adma.c
+++ b/drivers/ata/pdc_adma.c
@@ -44,7 +44,7 @@
44#include <linux/libata.h> 44#include <linux/libata.h>
45 45
46#define DRV_NAME "pdc_adma" 46#define DRV_NAME "pdc_adma"
47#define DRV_VERSION "0.05" 47#define DRV_VERSION "0.06"
48 48
49/* macro to calculate base address for ATA regs */ 49/* macro to calculate base address for ATA regs */
50#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40)) 50#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40))
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
index f099a1d83a00..2d80c9d95e95 100644
--- a/drivers/ata/sata_inic162x.c
+++ b/drivers/ata/sata_inic162x.c
@@ -28,7 +28,7 @@
28#include <scsi/scsi_device.h> 28#include <scsi/scsi_device.h>
29 29
30#define DRV_NAME "sata_inic162x" 30#define DRV_NAME "sata_inic162x"
31#define DRV_VERSION "0.1" 31#define DRV_VERSION "0.2"
32 32
33enum { 33enum {
34 MMIO_BAR = 5, 34 MMIO_BAR = 5,
@@ -135,10 +135,6 @@ static struct scsi_host_template inic_sht = {
135 .slave_configure = inic_slave_config, 135 .slave_configure = inic_slave_config,
136 .slave_destroy = ata_scsi_slave_destroy, 136 .slave_destroy = ata_scsi_slave_destroy,
137 .bios_param = ata_std_bios_param, 137 .bios_param = ata_std_bios_param,
138#ifdef CONFIG_PM
139 .suspend = ata_scsi_device_suspend,
140 .resume = ata_scsi_device_resume,
141#endif
142}; 138};
143 139
144static const int scr_map[] = { 140static const int scr_map[] = {
@@ -420,7 +416,8 @@ static void inic_thaw(struct ata_port *ap)
420 * SRST and SControl hardreset don't give valid signature on this 416 * SRST and SControl hardreset don't give valid signature on this
421 * controller. Only controller specific hardreset mechanism works. 417 * controller. Only controller specific hardreset mechanism works.
422 */ 418 */
423static int inic_hardreset(struct ata_port *ap, unsigned int *class) 419static int inic_hardreset(struct ata_port *ap, unsigned int *class,
420 unsigned long deadline)
424{ 421{
425 void __iomem *port_base = inic_port_base(ap); 422 void __iomem *port_base = inic_port_base(ap);
426 void __iomem *idma_ctl = port_base + PORT_IDMA_CTL; 423 void __iomem *idma_ctl = port_base + PORT_IDMA_CTL;
@@ -437,7 +434,7 @@ static int inic_hardreset(struct ata_port *ap, unsigned int *class)
437 msleep(1); 434 msleep(1);
438 writew(val & ~IDMA_CTL_RST_ATA, idma_ctl); 435 writew(val & ~IDMA_CTL_RST_ATA, idma_ctl);
439 436
440 rc = sata_phy_resume(ap, timing); 437 rc = sata_phy_resume(ap, timing, deadline);
441 if (rc) { 438 if (rc) {
442 ata_port_printk(ap, KERN_WARNING, "failed to resume " 439 ata_port_printk(ap, KERN_WARNING, "failed to resume "
443 "link after reset (errno=%d)\n", rc); 440 "link after reset (errno=%d)\n", rc);
@@ -451,10 +448,12 @@ static int inic_hardreset(struct ata_port *ap, unsigned int *class)
451 /* wait a while before checking status */ 448 /* wait a while before checking status */
452 msleep(150); 449 msleep(150);
453 450
454 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 451 rc = ata_wait_ready(ap, deadline);
455 ata_port_printk(ap, KERN_WARNING, 452 /* link occupied, -ENODEV too is an error */
456 "device busy after hardreset\n"); 453 if (rc) {
457 return -EIO; 454 ata_port_printk(ap, KERN_WARNING, "device not ready "
455 "after hardreset (errno=%d)\n", rc);
456 return rc;
458 } 457 }
459 458
460 ata_tf_read(ap, &tf); 459 ata_tf_read(ap, &tf);
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index cb9b9ac12b4c..705a020e1597 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -35,7 +35,7 @@
35#include <linux/libata.h> 35#include <linux/libata.h>
36 36
37#define DRV_NAME "sata_mv" 37#define DRV_NAME "sata_mv"
38#define DRV_VERSION "0.8" 38#define DRV_VERSION "0.81"
39 39
40enum { 40enum {
41 /* BAR's are enumerated in terms of pci_resource_start() terms */ 41 /* BAR's are enumerated in terms of pci_resource_start() terms */
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index 02169740ed24..adfa693db53d 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -49,7 +49,7 @@
49#include <linux/libata.h> 49#include <linux/libata.h>
50 50
51#define DRV_NAME "sata_nv" 51#define DRV_NAME "sata_nv"
52#define DRV_VERSION "3.3" 52#define DRV_VERSION "3.4"
53 53
54#define NV_ADMA_DMA_BOUNDARY 0xffffffffUL 54#define NV_ADMA_DMA_BOUNDARY 0xffffffffUL
55 55
@@ -229,7 +229,6 @@ struct nv_host_priv {
229#define NV_ADMA_CHECK_INTR(GCTL, PORT) ((GCTL) & ( 1 << (19 + (12 * (PORT))))) 229#define NV_ADMA_CHECK_INTR(GCTL, PORT) ((GCTL) & ( 1 << (19 + (12 * (PORT)))))
230 230
231static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 231static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
232static void nv_remove_one (struct pci_dev *pdev);
233#ifdef CONFIG_PM 232#ifdef CONFIG_PM
234static int nv_pci_device_resume(struct pci_dev *pdev); 233static int nv_pci_device_resume(struct pci_dev *pdev);
235#endif 234#endif
@@ -257,6 +256,8 @@ static void nv_adma_port_stop(struct ata_port *ap);
257static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg); 256static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg);
258static int nv_adma_port_resume(struct ata_port *ap); 257static int nv_adma_port_resume(struct ata_port *ap);
259#endif 258#endif
259static void nv_adma_freeze(struct ata_port *ap);
260static void nv_adma_thaw(struct ata_port *ap);
260static void nv_adma_error_handler(struct ata_port *ap); 261static void nv_adma_error_handler(struct ata_port *ap);
261static void nv_adma_host_stop(struct ata_host *host); 262static void nv_adma_host_stop(struct ata_host *host);
262static void nv_adma_post_internal_cmd(struct ata_queued_cmd *qc); 263static void nv_adma_post_internal_cmd(struct ata_queued_cmd *qc);
@@ -286,12 +287,6 @@ static const struct pci_device_id nv_pci_tbl[] = {
286 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA), GENERIC }, 287 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA), GENERIC },
287 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2), GENERIC }, 288 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA2), GENERIC },
288 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3), GENERIC }, 289 { PCI_VDEVICE(NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SATA3), GENERIC },
289 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
290 PCI_ANY_ID, PCI_ANY_ID,
291 PCI_CLASS_STORAGE_IDE<<8, 0xffff00, GENERIC },
292 { PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
293 PCI_ANY_ID, PCI_ANY_ID,
294 PCI_CLASS_STORAGE_RAID<<8, 0xffff00, GENERIC },
295 290
296 { } /* terminate list */ 291 { } /* terminate list */
297}; 292};
@@ -304,7 +299,7 @@ static struct pci_driver nv_pci_driver = {
304 .suspend = ata_pci_device_suspend, 299 .suspend = ata_pci_device_suspend,
305 .resume = nv_pci_device_resume, 300 .resume = nv_pci_device_resume,
306#endif 301#endif
307 .remove = nv_remove_one, 302 .remove = ata_pci_remove_one,
308}; 303};
309 304
310static struct scsi_host_template nv_sht = { 305static struct scsi_host_template nv_sht = {
@@ -323,10 +318,6 @@ static struct scsi_host_template nv_sht = {
323 .slave_configure = ata_scsi_slave_config, 318 .slave_configure = ata_scsi_slave_config,
324 .slave_destroy = ata_scsi_slave_destroy, 319 .slave_destroy = ata_scsi_slave_destroy,
325 .bios_param = ata_std_bios_param, 320 .bios_param = ata_std_bios_param,
326#ifdef CONFIG_PM
327 .suspend = ata_scsi_device_suspend,
328 .resume = ata_scsi_device_resume,
329#endif
330}; 321};
331 322
332static struct scsi_host_template nv_adma_sht = { 323static struct scsi_host_template nv_adma_sht = {
@@ -345,10 +336,6 @@ static struct scsi_host_template nv_adma_sht = {
345 .slave_configure = nv_adma_slave_config, 336 .slave_configure = nv_adma_slave_config,
346 .slave_destroy = ata_scsi_slave_destroy, 337 .slave_destroy = ata_scsi_slave_destroy,
347 .bios_param = ata_std_bios_param, 338 .bios_param = ata_std_bios_param,
348#ifdef CONFIG_PM
349 .suspend = ata_scsi_device_suspend,
350 .resume = ata_scsi_device_resume,
351#endif
352}; 339};
353 340
354static const struct ata_port_operations nv_generic_ops = { 341static const struct ata_port_operations nv_generic_ops = {
@@ -444,8 +431,8 @@ static const struct ata_port_operations nv_adma_ops = {
444 .bmdma_status = ata_bmdma_status, 431 .bmdma_status = ata_bmdma_status,
445 .qc_prep = nv_adma_qc_prep, 432 .qc_prep = nv_adma_qc_prep,
446 .qc_issue = nv_adma_qc_issue, 433 .qc_issue = nv_adma_qc_issue,
447 .freeze = nv_ck804_freeze, 434 .freeze = nv_adma_freeze,
448 .thaw = nv_ck804_thaw, 435 .thaw = nv_adma_thaw,
449 .error_handler = nv_adma_error_handler, 436 .error_handler = nv_adma_error_handler,
450 .post_internal_cmd = nv_adma_post_internal_cmd, 437 .post_internal_cmd = nv_adma_post_internal_cmd,
451 .data_xfer = ata_data_xfer, 438 .data_xfer = ata_data_xfer,
@@ -463,7 +450,7 @@ static const struct ata_port_operations nv_adma_ops = {
463 .host_stop = nv_adma_host_stop, 450 .host_stop = nv_adma_host_stop,
464}; 451};
465 452
466static struct ata_port_info nv_port_info[] = { 453static const struct ata_port_info nv_port_info[] = {
467 /* generic */ 454 /* generic */
468 { 455 {
469 .sht = &nv_sht, 456 .sht = &nv_sht,
@@ -816,7 +803,15 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
816 u32 gen_ctl; 803 u32 gen_ctl;
817 u32 notifier, notifier_error; 804 u32 notifier, notifier_error;
818 805
819 /* if in ATA register mode, use standard ata interrupt handler */ 806 /* if ADMA is disabled, use standard ata interrupt handler */
807 if (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) {
808 u8 irq_stat = readb(host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804)
809 >> (NV_INT_PORT_SHIFT * i);
810 handled += nv_host_intr(ap, irq_stat);
811 continue;
812 }
813
814 /* if in ATA register mode, check for standard interrupts */
820 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) { 815 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) {
821 u8 irq_stat = readb(host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804) 816 u8 irq_stat = readb(host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804)
822 >> (NV_INT_PORT_SHIFT * i); 817 >> (NV_INT_PORT_SHIFT * i);
@@ -826,7 +821,6 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
826 command is active, to prevent losing interrupts. */ 821 command is active, to prevent losing interrupts. */
827 irq_stat |= NV_INT_DEV; 822 irq_stat |= NV_INT_DEV;
828 handled += nv_host_intr(ap, irq_stat); 823 handled += nv_host_intr(ap, irq_stat);
829 continue;
830 } 824 }
831 825
832 notifier = readl(mmio + NV_ADMA_NOTIFIER); 826 notifier = readl(mmio + NV_ADMA_NOTIFIER);
@@ -912,22 +906,77 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
912 return IRQ_RETVAL(handled); 906 return IRQ_RETVAL(handled);
913} 907}
914 908
909static void nv_adma_freeze(struct ata_port *ap)
910{
911 struct nv_adma_port_priv *pp = ap->private_data;
912 void __iomem *mmio = pp->ctl_block;
913 u16 tmp;
914
915 nv_ck804_freeze(ap);
916
917 if (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE)
918 return;
919
920 /* clear any outstanding CK804 notifications */
921 writeb( NV_INT_ALL << (ap->port_no * NV_INT_PORT_SHIFT),
922 ap->host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804);
923
924 /* Disable interrupt */
925 tmp = readw(mmio + NV_ADMA_CTL);
926 writew( tmp & ~(NV_ADMA_CTL_AIEN | NV_ADMA_CTL_HOTPLUG_IEN),
927 mmio + NV_ADMA_CTL);
928 readw( mmio + NV_ADMA_CTL ); /* flush posted write */
929}
930
931static void nv_adma_thaw(struct ata_port *ap)
932{
933 struct nv_adma_port_priv *pp = ap->private_data;
934 void __iomem *mmio = pp->ctl_block;
935 u16 tmp;
936
937 nv_ck804_thaw(ap);
938
939 if (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE)
940 return;
941
942 /* Enable interrupt */
943 tmp = readw(mmio + NV_ADMA_CTL);
944 writew( tmp | (NV_ADMA_CTL_AIEN | NV_ADMA_CTL_HOTPLUG_IEN),
945 mmio + NV_ADMA_CTL);
946 readw( mmio + NV_ADMA_CTL ); /* flush posted write */
947}
948
915static void nv_adma_irq_clear(struct ata_port *ap) 949static void nv_adma_irq_clear(struct ata_port *ap)
916{ 950{
917 struct nv_adma_port_priv *pp = ap->private_data; 951 struct nv_adma_port_priv *pp = ap->private_data;
918 void __iomem *mmio = pp->ctl_block; 952 void __iomem *mmio = pp->ctl_block;
919 u16 status = readw(mmio + NV_ADMA_STAT); 953 u32 notifier_clears[2];
920 u32 notifier = readl(mmio + NV_ADMA_NOTIFIER); 954
921 u32 notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR); 955 if (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) {
922 void __iomem *dma_stat_addr = ap->ioaddr.bmdma_addr + ATA_DMA_STATUS; 956 ata_bmdma_irq_clear(ap);
957 return;
958 }
959
960 /* clear any outstanding CK804 notifications */
961 writeb( NV_INT_ALL << (ap->port_no * NV_INT_PORT_SHIFT),
962 ap->host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804);
923 963
924 /* clear ADMA status */ 964 /* clear ADMA status */
925 writew(status, mmio + NV_ADMA_STAT); 965 writew(0xffff, mmio + NV_ADMA_STAT);
926 writel(notifier | notifier_error,
927 pp->notifier_clear_block);
928 966
929 /** clear legacy status */ 967 /* clear notifiers - note both ports need to be written with
930 iowrite8(ioread8(dma_stat_addr), dma_stat_addr); 968 something even though we are only clearing on one */
969 if (ap->port_no == 0) {
970 notifier_clears[0] = 0xFFFFFFFF;
971 notifier_clears[1] = 0;
972 } else {
973 notifier_clears[0] = 0;
974 notifier_clears[1] = 0xFFFFFFFF;
975 }
976 pp = ap->host->ports[0]->private_data;
977 writel(notifier_clears[0], pp->notifier_clear_block);
978 pp = ap->host->ports[1]->private_data;
979 writel(notifier_clears[1], pp->notifier_clear_block);
931} 980}
932 981
933static void nv_adma_post_internal_cmd(struct ata_queued_cmd *qc) 982static void nv_adma_post_internal_cmd(struct ata_queued_cmd *qc)
@@ -1405,7 +1454,8 @@ static void nv_ck804_thaw(struct ata_port *ap)
1405 writeb(mask, mmio_base + NV_INT_ENABLE_CK804); 1454 writeb(mask, mmio_base + NV_INT_ENABLE_CK804);
1406} 1455}
1407 1456
1408static int nv_hardreset(struct ata_port *ap, unsigned int *class) 1457static int nv_hardreset(struct ata_port *ap, unsigned int *class,
1458 unsigned long deadline)
1409{ 1459{
1410 unsigned int dummy; 1460 unsigned int dummy;
1411 1461
@@ -1413,7 +1463,7 @@ static int nv_hardreset(struct ata_port *ap, unsigned int *class)
1413 * some controllers. Don't classify on hardreset. For more 1463 * some controllers. Don't classify on hardreset. For more
1414 * info, see http://bugme.osdl.org/show_bug.cgi?id=3352 1464 * info, see http://bugme.osdl.org/show_bug.cgi?id=3352
1415 */ 1465 */
1416 return sata_std_hardreset(ap, &dummy); 1466 return sata_std_hardreset(ap, &dummy, deadline);
1417} 1467}
1418 1468
1419static void nv_error_handler(struct ata_port *ap) 1469static void nv_error_handler(struct ata_port *ap)
@@ -1480,7 +1530,7 @@ static void nv_adma_error_handler(struct ata_port *ap)
1480static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 1530static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1481{ 1531{
1482 static int printed_version = 0; 1532 static int printed_version = 0;
1483 const struct ata_port_info *ppi[2]; 1533 const struct ata_port_info *ppi[] = { NULL, NULL };
1484 struct ata_host *host; 1534 struct ata_host *host;
1485 struct nv_host_priv *hpriv; 1535 struct nv_host_priv *hpriv;
1486 int rc; 1536 int rc;
@@ -1508,8 +1558,8 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1508 type = ADMA; 1558 type = ADMA;
1509 } 1559 }
1510 1560
1511 ppi[0] = ppi[1] = &nv_port_info[type]; 1561 ppi[0] = &nv_port_info[type];
1512 rc = ata_pci_prepare_native_host(pdev, ppi, 2, &host); 1562 rc = ata_pci_prepare_native_host(pdev, ppi, &host);
1513 if (rc) 1563 if (rc)
1514 return rc; 1564 return rc;
1515 1565
@@ -1556,15 +1606,6 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1556 IRQF_SHARED, ppi[0]->sht); 1606 IRQF_SHARED, ppi[0]->sht);
1557} 1607}
1558 1608
1559static void nv_remove_one (struct pci_dev *pdev)
1560{
1561 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1562 struct nv_host_priv *hpriv = host->private_data;
1563
1564 ata_pci_remove_one(pdev);
1565 kfree(hpriv);
1566}
1567
1568#ifdef CONFIG_PM 1609#ifdef CONFIG_PM
1569static int nv_pci_device_resume(struct pci_dev *pdev) 1610static int nv_pci_device_resume(struct pci_dev *pdev)
1570{ 1611{
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index f56549b90aa6..3a7d9b5332af 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -45,7 +45,7 @@
45#include "sata_promise.h" 45#include "sata_promise.h"
46 46
47#define DRV_NAME "sata_promise" 47#define DRV_NAME "sata_promise"
48#define DRV_VERSION "2.05" 48#define DRV_VERSION "2.07"
49 49
50 50
51enum { 51enum {
@@ -653,6 +653,8 @@ static void pdc_error_intr(struct ata_port *ap, struct ata_queued_cmd *qc,
653 qc->err_mask |= ac_err_mask; 653 qc->err_mask |= ac_err_mask;
654 654
655 pdc_reset_port(ap); 655 pdc_reset_port(ap);
656
657 ata_port_abort(ap);
656} 658}
657 659
658static inline unsigned int pdc_host_intr( struct ata_port *ap, 660static inline unsigned int pdc_host_intr( struct ata_port *ap,
@@ -924,6 +926,7 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
924 struct ata_host *host; 926 struct ata_host *host;
925 void __iomem *base; 927 void __iomem *base;
926 int n_ports, i, rc; 928 int n_ports, i, rc;
929 int is_sataii_tx4;
927 930
928 if (!printed_version++) 931 if (!printed_version++)
929 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 932 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
@@ -962,10 +965,23 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
962 } 965 }
963 host->iomap = pcim_iomap_table(pdev); 966 host->iomap = pcim_iomap_table(pdev);
964 967
965 for (i = 0; i < host->n_ports; i++) 968 is_sataii_tx4 = 0;
969 if ((pi->flags & (PDC_FLAG_GEN_II|PDC_FLAG_4_PORTS)) == (PDC_FLAG_GEN_II|PDC_FLAG_4_PORTS)) {
970 is_sataii_tx4 = 1;
971 dev_printk(KERN_INFO, &pdev->dev, "applying SATAII TX4 port numbering workaround\n");
972 }
973 for (i = 0; i < host->n_ports; i++) {
974 static const unsigned char sataii_tx4_port_remap[4] = { 3, 1, 0, 2};
975 int ata_nr;
976
977 ata_nr = i;
978 if (is_sataii_tx4)
979 ata_nr = sataii_tx4_port_remap[i];
980
966 pdc_ata_setup_port(host->ports[i], 981 pdc_ata_setup_port(host->ports[i],
967 base + 0x200 + i * 0x80, 982 base + 0x200 + ata_nr * 0x80,
968 base + 0x400 + i * 0x100); 983 base + 0x400 + ata_nr * 0x100);
984 }
969 985
970 /* initialize adapter */ 986 /* initialize adapter */
971 pdc_host_init(host); 987 pdc_host_init(host);
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
index f5a05de0093d..6688ccb66320 100644
--- a/drivers/ata/sata_qstor.c
+++ b/drivers/ata/sata_qstor.c
@@ -39,7 +39,7 @@
39#include <linux/libata.h> 39#include <linux/libata.h>
40 40
41#define DRV_NAME "sata_qstor" 41#define DRV_NAME "sata_qstor"
42#define DRV_VERSION "0.07" 42#define DRV_VERSION "0.08"
43 43
44enum { 44enum {
45 QS_MMIO_BAR = 4, 45 QS_MMIO_BAR = 4,
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 0a1e417f309c..a3b339bcf3cf 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -182,10 +182,6 @@ static struct scsi_host_template sil_sht = {
182 .slave_configure = ata_scsi_slave_config, 182 .slave_configure = ata_scsi_slave_config,
183 .slave_destroy = ata_scsi_slave_destroy, 183 .slave_destroy = ata_scsi_slave_destroy,
184 .bios_param = ata_std_bios_param, 184 .bios_param = ata_std_bios_param,
185#ifdef CONFIG_PM
186 .suspend = ata_scsi_device_suspend,
187 .resume = ata_scsi_device_resume,
188#endif
189}; 185};
190 186
191static const struct ata_port_operations sil_ops = { 187static const struct ata_port_operations sil_ops = {
@@ -309,7 +305,7 @@ static int sil_set_mode (struct ata_port *ap, struct ata_device **r_failed)
309 u32 tmp, dev_mode[2]; 305 u32 tmp, dev_mode[2];
310 unsigned int i; 306 unsigned int i;
311 int rc; 307 int rc;
312 308
313 rc = ata_do_set_mode(ap, r_failed); 309 rc = ata_do_set_mode(ap, r_failed);
314 if (rc) 310 if (rc)
315 return rc; 311 return rc;
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index e6223ba667da..0ddfae9911cd 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -30,7 +30,7 @@
30#include <linux/libata.h> 30#include <linux/libata.h>
31 31
32#define DRV_NAME "sata_sil24" 32#define DRV_NAME "sata_sil24"
33#define DRV_VERSION "0.8" 33#define DRV_VERSION "0.9"
34 34
35/* 35/*
36 * Port request block (PRB) 32 bytes 36 * Port request block (PRB) 32 bytes
@@ -237,7 +237,8 @@ enum {
237 /* host flags */ 237 /* host flags */
238 SIL24_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 238 SIL24_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
239 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA | 239 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA |
240 ATA_FLAG_NCQ | ATA_FLAG_SKIP_D2H_BSY, 240 ATA_FLAG_NCQ | ATA_FLAG_SKIP_D2H_BSY |
241 ATA_FLAG_ACPI_SATA,
241 SIL24_FLAG_PCIX_IRQ_WOC = (1 << 24), /* IRQ loss errata on PCI-X */ 242 SIL24_FLAG_PCIX_IRQ_WOC = (1 << 24), /* IRQ loss errata on PCI-X */
242 243
243 IRQ_STAT_4PORTS = 0xf, 244 IRQ_STAT_4PORTS = 0xf,
@@ -380,10 +381,6 @@ static struct scsi_host_template sil24_sht = {
380 .slave_configure = ata_scsi_slave_config, 381 .slave_configure = ata_scsi_slave_config,
381 .slave_destroy = ata_scsi_slave_destroy, 382 .slave_destroy = ata_scsi_slave_destroy,
382 .bios_param = ata_std_bios_param, 383 .bios_param = ata_std_bios_param,
383#ifdef CONFIG_PM
384 .suspend = ata_scsi_device_suspend,
385 .resume = ata_scsi_device_resume,
386#endif
387}; 384};
388 385
389static const struct ata_port_operations sil24_ops = { 386static const struct ata_port_operations sil24_ops = {
@@ -534,7 +531,8 @@ static int sil24_init_port(struct ata_port *ap)
534 return 0; 531 return 0;
535} 532}
536 533
537static int sil24_softreset(struct ata_port *ap, unsigned int *class) 534static int sil24_softreset(struct ata_port *ap, unsigned int *class,
535 unsigned long deadline)
538{ 536{
539 void __iomem *port = ap->ioaddr.cmd_addr; 537 void __iomem *port = ap->ioaddr.cmd_addr;
540 struct sil24_port_priv *pp = ap->private_data; 538 struct sil24_port_priv *pp = ap->private_data;
@@ -566,7 +564,7 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class)
566 564
567 mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT; 565 mask = (PORT_IRQ_COMPLETE | PORT_IRQ_ERROR) << PORT_IRQ_RAW_SHIFT;
568 irq_stat = ata_wait_register(port + PORT_IRQ_STAT, mask, 0x0, 566 irq_stat = ata_wait_register(port + PORT_IRQ_STAT, mask, 0x0,
569 100, ATA_TMOUT_BOOT / HZ * 1000); 567 100, jiffies_to_msecs(deadline - jiffies));
570 568
571 writel(irq_stat, port + PORT_IRQ_STAT); /* clear IRQs */ 569 writel(irq_stat, port + PORT_IRQ_STAT); /* clear IRQs */
572 irq_stat >>= PORT_IRQ_RAW_SHIFT; 570 irq_stat >>= PORT_IRQ_RAW_SHIFT;
@@ -594,7 +592,8 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class)
594 return -EIO; 592 return -EIO;
595} 593}
596 594
597static int sil24_hardreset(struct ata_port *ap, unsigned int *class) 595static int sil24_hardreset(struct ata_port *ap, unsigned int *class,
596 unsigned long deadline)
598{ 597{
599 void __iomem *port = ap->ioaddr.cmd_addr; 598 void __iomem *port = ap->ioaddr.cmd_addr;
600 const char *reason; 599 const char *reason;
@@ -615,7 +614,7 @@ static int sil24_hardreset(struct ata_port *ap, unsigned int *class)
615 /* SStatus oscillates between zero and valid status after 614 /* SStatus oscillates between zero and valid status after
616 * DEV_RST, debounce it. 615 * DEV_RST, debounce it.
617 */ 616 */
618 rc = sata_phy_debounce(ap, sata_deb_timing_long); 617 rc = sata_phy_debounce(ap, sata_deb_timing_long, deadline);
619 if (rc) { 618 if (rc) {
620 reason = "PHY debouncing failed"; 619 reason = "PHY debouncing failed";
621 goto err; 620 goto err;
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index d8ee062e82fc..51d9251b0898 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -43,7 +43,7 @@
43#include "sis.h" 43#include "sis.h"
44 44
45#define DRV_NAME "sata_sis" 45#define DRV_NAME "sata_sis"
46#define DRV_VERSION "0.7" 46#define DRV_VERSION "0.8"
47 47
48enum { 48enum {
49 sis_180 = 0, 49 sis_180 = 0,
@@ -129,7 +129,7 @@ static const struct ata_port_operations sis_ops = {
129 .port_start = ata_port_start, 129 .port_start = ata_port_start,
130}; 130};
131 131
132static struct ata_port_info sis_port_info = { 132static const struct ata_port_info sis_port_info = {
133 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, 133 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
134 .pio_mask = 0x1f, 134 .pio_mask = 0x1f,
135 .mwdma_mask = 0x7, 135 .mwdma_mask = 0x7,
@@ -255,7 +255,7 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
255{ 255{
256 static int printed_version; 256 static int printed_version;
257 struct ata_port_info pi = sis_port_info; 257 struct ata_port_info pi = sis_port_info;
258 const struct ata_port_info *ppi[2] = { &pi, &pi }; 258 const struct ata_port_info *ppi[] = { &pi, NULL };
259 struct ata_host *host; 259 struct ata_host *host;
260 u32 genctl, val; 260 u32 genctl, val;
261 u8 pmr; 261 u8 pmr;
@@ -335,7 +335,7 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
335 break; 335 break;
336 } 336 }
337 337
338 rc = ata_pci_prepare_native_host(pdev, ppi, 2, &host); 338 rc = ata_pci_prepare_native_host(pdev, ppi, &host);
339 if (rc) 339 if (rc)
340 return rc; 340 return rc;
341 341
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index cc07aac10e8c..bcb2cd8b063d 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -53,7 +53,7 @@
53#endif /* CONFIG_PPC_OF */ 53#endif /* CONFIG_PPC_OF */
54 54
55#define DRV_NAME "sata_svw" 55#define DRV_NAME "sata_svw"
56#define DRV_VERSION "2.1" 56#define DRV_VERSION "2.2"
57 57
58enum { 58enum {
59 /* ap->flags bits */ 59 /* ap->flags bits */
@@ -288,7 +288,7 @@ static int k2_sata_proc_info(struct Scsi_Host *shost, char *page, char **start,
288 /* Match it to a port node */ 288 /* Match it to a port node */
289 index = (ap == ap->host->ports[0]) ? 0 : 1; 289 index = (ap == ap->host->ports[0]) ? 0 : 1;
290 for (np = np->child; np != NULL; np = np->sibling) { 290 for (np = np->child; np != NULL; np = np->sibling) {
291 const u32 *reg = get_property(np, "reg", NULL); 291 const u32 *reg = of_get_property(np, "reg", NULL);
292 if (!reg) 292 if (!reg)
293 continue; 293 continue;
294 if (index == *reg) 294 if (index == *reg)
diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
index 3a4f44559d0a..2d14f3d56d92 100644
--- a/drivers/ata/sata_sx4.c
+++ b/drivers/ata/sata_sx4.c
@@ -44,7 +44,7 @@
44#include "sata_promise.h" 44#include "sata_promise.h"
45 45
46#define DRV_NAME "sata_sx4" 46#define DRV_NAME "sata_sx4"
47#define DRV_VERSION "0.10" 47#define DRV_VERSION "0.11"
48 48
49 49
50enum { 50enum {
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index f74e383de083..6815de7cca79 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -36,7 +36,7 @@
36#include <linux/libata.h> 36#include <linux/libata.h>
37 37
38#define DRV_NAME "sata_uli" 38#define DRV_NAME "sata_uli"
39#define DRV_VERSION "1.1" 39#define DRV_VERSION "1.2"
40 40
41enum { 41enum {
42 uli_5289 = 0, 42 uli_5289 = 0,
@@ -125,7 +125,7 @@ static const struct ata_port_operations uli_ops = {
125 .port_start = ata_port_start, 125 .port_start = ata_port_start,
126}; 126};
127 127
128static struct ata_port_info uli_port_info = { 128static const struct ata_port_info uli_port_info = {
129 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 129 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
130 ATA_FLAG_IGN_SIMPLEX, 130 ATA_FLAG_IGN_SIMPLEX,
131 .pio_mask = 0x1f, /* pio0-4 */ 131 .pio_mask = 0x1f, /* pio0-4 */
@@ -201,19 +201,33 @@ static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
201 n_ports = 2; 201 n_ports = 2;
202 if (board_idx == uli_5287) 202 if (board_idx == uli_5287)
203 n_ports = 4; 203 n_ports = 4;
204 rc = ata_pci_prepare_native_host(pdev, ppi, n_ports, &host); 204
205 if (rc) 205 /* allocate the host */
206 return rc; 206 host = ata_host_alloc_pinfo(&pdev->dev, ppi, n_ports);
207 if (!host)
208 return -ENOMEM;
207 209
208 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL); 210 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
209 if (!hpriv) 211 if (!hpriv)
210 return -ENOMEM; 212 return -ENOMEM;
211 host->private_data = hpriv; 213 host->private_data = hpriv;
212 214
215 /* the first two ports are standard SFF */
216 rc = ata_pci_init_native_host(host);
217 if (rc)
218 return rc;
219
220 rc = ata_pci_init_bmdma(host);
221 if (rc)
222 return rc;
223
213 iomap = host->iomap; 224 iomap = host->iomap;
214 225
215 switch (board_idx) { 226 switch (board_idx) {
216 case uli_5287: 227 case uli_5287:
228 /* If there are four, the last two live right after
229 * the standard SFF ports.
230 */
217 hpriv->scr_cfg_addr[0] = ULI5287_BASE; 231 hpriv->scr_cfg_addr[0] = ULI5287_BASE;
218 hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS; 232 hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS;
219 233
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 1d855f55f5f7..01bba26d8d1a 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -46,7 +46,7 @@
46#include <linux/libata.h> 46#include <linux/libata.h>
47 47
48#define DRV_NAME "sata_via" 48#define DRV_NAME "sata_via"
49#define DRV_VERSION "2.1" 49#define DRV_VERSION "2.2"
50 50
51enum board_ids_enum { 51enum board_ids_enum {
52 vt6420, 52 vt6420,
@@ -93,6 +93,10 @@ static struct pci_driver svia_pci_driver = {
93 .name = DRV_NAME, 93 .name = DRV_NAME,
94 .id_table = svia_pci_tbl, 94 .id_table = svia_pci_tbl,
95 .probe = svia_init_one, 95 .probe = svia_init_one,
96#ifdef CONFIG_PM
97 .suspend = ata_pci_device_suspend,
98 .resume = ata_pci_device_resume,
99#endif
96 .remove = ata_pci_remove_one, 100 .remove = ata_pci_remove_one,
97}; 101};
98 102
@@ -268,6 +272,7 @@ static void svia_noop_freeze(struct ata_port *ap)
268/** 272/**
269 * vt6420_prereset - prereset for vt6420 273 * vt6420_prereset - prereset for vt6420
270 * @ap: target ATA port 274 * @ap: target ATA port
275 * @deadline: deadline jiffies for the operation
271 * 276 *
272 * SCR registers on vt6420 are pieces of shit and may hang the 277 * SCR registers on vt6420 are pieces of shit and may hang the
273 * whole machine completely if accessed with the wrong timing. 278 * whole machine completely if accessed with the wrong timing.
@@ -284,7 +289,7 @@ static void svia_noop_freeze(struct ata_port *ap)
284 * RETURNS: 289 * RETURNS:
285 * 0 on success, -errno otherwise. 290 * 0 on success, -errno otherwise.
286 */ 291 */
287static int vt6420_prereset(struct ata_port *ap) 292static int vt6420_prereset(struct ata_port *ap, unsigned long deadline)
288{ 293{
289 struct ata_eh_context *ehc = &ap->eh_context; 294 struct ata_eh_context *ehc = &ap->eh_context;
290 unsigned long timeout = jiffies + (HZ * 5); 295 unsigned long timeout = jiffies + (HZ * 5);
@@ -329,7 +334,7 @@ static int vt6420_prereset(struct ata_port *ap)
329 334
330 skip_scr: 335 skip_scr:
331 /* wait for !BSY */ 336 /* wait for !BSY */
332 ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT); 337 ata_wait_ready(ap, deadline);
333 338
334 return 0; 339 return 0;
335} 340}
@@ -406,7 +411,7 @@ static int vt6420_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
406 struct ata_host *host; 411 struct ata_host *host;
407 int rc; 412 int rc;
408 413
409 rc = ata_pci_prepare_native_host(pdev, ppi, 2, &host); 414 rc = ata_pci_prepare_native_host(pdev, ppi, &host);
410 if (rc) 415 if (rc)
411 return rc; 416 return rc;
412 *r_host = host; 417 *r_host = host;
@@ -436,7 +441,7 @@ static int vt6421_prepare_host(struct pci_dev *pdev, struct ata_host **r_host)
436 return -ENOMEM; 441 return -ENOMEM;
437 } 442 }
438 443
439 rc = pcim_iomap_regions(pdev, 0x1f, DRV_NAME); 444 rc = pcim_iomap_regions(pdev, 0x3f, DRV_NAME);
440 if (rc) { 445 if (rc) {
441 dev_printk(KERN_ERR, &pdev->dev, "failed to request/iomap " 446 dev_printk(KERN_ERR, &pdev->dev, "failed to request/iomap "
442 "PCI BARs (errno=%d)\n", rc); 447 "PCI BARs (errno=%d)\n", rc);
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index 80126f835d32..81330175fc89 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -47,7 +47,7 @@
47#include <linux/libata.h> 47#include <linux/libata.h>
48 48
49#define DRV_NAME "sata_vsc" 49#define DRV_NAME "sata_vsc"
50#define DRV_VERSION "2.1" 50#define DRV_VERSION "2.2"
51 51
52enum { 52enum {
53 VSC_MMIO_BAR = 0, 53 VSC_MMIO_BAR = 0,
diff --git a/drivers/ata/sis.h b/drivers/ata/sis.h
index 231da8fc2200..0f2208d8d5ef 100644
--- a/drivers/ata/sis.h
+++ b/drivers/ata/sis.h
@@ -2,4 +2,4 @@
2struct ata_port_info; 2struct ata_port_info;
3 3
4/* pata_sis.c */ 4/* pata_sis.c */
5extern struct ata_port_info sis_info133; 5extern const struct ata_port_info sis_info133;
diff --git a/drivers/atm/Kconfig b/drivers/atm/Kconfig
index 33687454eb32..f5a47a48c3b4 100644
--- a/drivers/atm/Kconfig
+++ b/drivers/atm/Kconfig
@@ -2,19 +2,22 @@
2# ATM device configuration 2# ATM device configuration
3# 3#
4 4
5menu "ATM drivers" 5menuconfig ATM_DRIVERS
6 bool "ATM drivers"
6 depends on NETDEVICES && ATM 7 depends on NETDEVICES && ATM
8 default y
9
10if ATM_DRIVERS
7 11
8config ATM_DUMMY 12config ATM_DUMMY
9 tristate "Dummy ATM driver" 13 tristate "Dummy ATM driver"
10 depends on ATM
11 help 14 help
12 Dummy ATM driver. Useful for proxy signalling, testing, 15 Dummy ATM driver. Useful for proxy signalling, testing,
13 and development. If unsure, say N. 16 and development. If unsure, say N.
14 17
15config ATM_TCP 18config ATM_TCP
16 tristate "ATM over TCP" 19 tristate "ATM over TCP"
17 depends on INET && ATM 20 depends on INET
18 help 21 help
19 ATM over TCP driver. Useful mainly for development and for 22 ATM over TCP driver. Useful mainly for development and for
20 experiments. If unsure, say N. 23 experiments. If unsure, say N.
@@ -30,7 +33,7 @@ config ATM_LANAI
30 33
31config ATM_ENI 34config ATM_ENI
32 tristate "Efficient Networks ENI155P" 35 tristate "Efficient Networks ENI155P"
33 depends on PCI && ATM 36 depends on PCI
34 ---help--- 37 ---help---
35 Driver for the Efficient Networks ENI155p series and SMC ATM 38 Driver for the Efficient Networks ENI155p series and SMC ATM
36 Power155 155 Mbps ATM adapters. Both, the versions with 512KB and 39 Power155 155 Mbps ATM adapters. Both, the versions with 512KB and
@@ -139,7 +142,7 @@ config ATM_ENI_BURST_RX_2W
139 142
140config ATM_FIRESTREAM 143config ATM_FIRESTREAM
141 tristate "Fujitsu FireStream (FS50/FS155) " 144 tristate "Fujitsu FireStream (FS50/FS155) "
142 depends on PCI && ATM 145 depends on PCI
143 help 146 help
144 Driver for the Fujitsu FireStream 155 (MB86697) and 147 Driver for the Fujitsu FireStream 155 (MB86697) and
145 FireStream 50 (MB86695) ATM PCI chips. 148 FireStream 50 (MB86695) ATM PCI chips.
@@ -149,7 +152,7 @@ config ATM_FIRESTREAM
149 152
150config ATM_ZATM 153config ATM_ZATM
151 tristate "ZeitNet ZN1221/ZN1225" 154 tristate "ZeitNet ZN1221/ZN1225"
152 depends on PCI && ATM 155 depends on PCI
153 help 156 help
154 Driver for the ZeitNet ZN1221 (MMF) and ZN1225 (UTP-5) 155 Mbps ATM 157 Driver for the ZeitNet ZN1221 (MMF) and ZN1225 (UTP-5) 155 Mbps ATM
155 adapters. 158 adapters.
@@ -169,7 +172,7 @@ config ATM_ZATM_DEBUG
169 172
170config ATM_NICSTAR 173config ATM_NICSTAR
171 tristate "IDT 77201 (NICStAR) (ForeRunnerLE)" 174 tristate "IDT 77201 (NICStAR) (ForeRunnerLE)"
172 depends on PCI && ATM && !64BIT 175 depends on PCI && !64BIT
173 help 176 help
174 The NICStAR chipset family is used in a large number of ATM NICs for 177 The NICStAR chipset family is used in a large number of ATM NICs for
175 25 and for 155 Mbps, including IDT cards and the Fore ForeRunnerLE 178 25 and for 155 Mbps, including IDT cards and the Fore ForeRunnerLE
@@ -202,7 +205,7 @@ config ATM_NICSTAR_USE_IDT77105
202 205
203config ATM_IDT77252 206config ATM_IDT77252
204 tristate "IDT 77252 (NICStAR II)" 207 tristate "IDT 77252 (NICStAR II)"
205 depends on PCI && ATM 208 depends on PCI
206 help 209 help
207 Driver for the IDT 77252 ATM PCI chips. 210 Driver for the IDT 77252 ATM PCI chips.
208 211
@@ -237,7 +240,7 @@ config ATM_IDT77252_USE_SUNI
237 240
238config ATM_AMBASSADOR 241config ATM_AMBASSADOR
239 tristate "Madge Ambassador (Collage PCI 155 Server)" 242 tristate "Madge Ambassador (Collage PCI 155 Server)"
240 depends on PCI && ATM 243 depends on PCI
241 select BITREVERSE 244 select BITREVERSE
242 help 245 help
243 This is a driver for ATMizer based ATM card produced by Madge 246 This is a driver for ATMizer based ATM card produced by Madge
@@ -262,7 +265,7 @@ config ATM_AMBASSADOR_DEBUG
262 265
263config ATM_HORIZON 266config ATM_HORIZON
264 tristate "Madge Horizon [Ultra] (Collage PCI 25 and Collage PCI 155 Client)" 267 tristate "Madge Horizon [Ultra] (Collage PCI 25 and Collage PCI 155 Client)"
265 depends on PCI && ATM 268 depends on PCI
266 help 269 help
267 This is a driver for the Horizon chipset ATM adapter cards once 270 This is a driver for the Horizon chipset ATM adapter cards once
268 produced by Madge Networks Ltd. Say Y (or M to compile as a module 271 produced by Madge Networks Ltd. Say Y (or M to compile as a module
@@ -286,7 +289,7 @@ config ATM_HORIZON_DEBUG
286 289
287config ATM_IA 290config ATM_IA
288 tristate "Interphase ATM PCI x575/x525/x531" 291 tristate "Interphase ATM PCI x575/x525/x531"
289 depends on PCI && ATM && !64BIT 292 depends on PCI && !64BIT
290 ---help--- 293 ---help---
291 This is a driver for the Interphase (i)ChipSAR adapter cards 294 This is a driver for the Interphase (i)ChipSAR adapter cards
292 which include a variety of variants in term of the size of the 295 which include a variety of variants in term of the size of the
@@ -319,7 +322,7 @@ config ATM_IA_DEBUG
319 322
320config ATM_FORE200E_MAYBE 323config ATM_FORE200E_MAYBE
321 tristate "FORE Systems 200E-series" 324 tristate "FORE Systems 200E-series"
322 depends on (PCI || SBUS) && ATM 325 depends on PCI || SBUS
323 ---help--- 326 ---help---
324 This is a driver for the FORE Systems 200E-series ATM adapter 327 This is a driver for the FORE Systems 200E-series ATM adapter
325 cards. It simultaneously supports PCA-200E and SBA-200E models 328 cards. It simultaneously supports PCA-200E and SBA-200E models
@@ -436,7 +439,7 @@ config ATM_FORE200E
436 439
437config ATM_HE 440config ATM_HE
438 tristate "ForeRunner HE Series" 441 tristate "ForeRunner HE Series"
439 depends on PCI && ATM 442 depends on PCI
440 help 443 help
441 This is a driver for the Marconi ForeRunner HE-series ATM adapter 444 This is a driver for the Marconi ForeRunner HE-series ATM adapter
442 cards. It simultaneously supports the 155 and 622 versions. 445 cards. It simultaneously supports the 155 and 622 versions.
@@ -448,5 +451,4 @@ config ATM_HE_USE_SUNI
448 Support for the S/UNI-Ultra and S/UNI-622 found in the ForeRunner 451 Support for the S/UNI-Ultra and S/UNI-622 found in the ForeRunner
449 HE cards. This driver provides carrier detection some statistics. 452 HE cards. This driver provides carrier detection some statistics.
450 453
451endmenu 454endif # ATM
452
diff --git a/drivers/auxdisplay/Kconfig b/drivers/auxdisplay/Kconfig
index 0300e7f54cc4..2e18a63ead36 100644
--- a/drivers/auxdisplay/Kconfig
+++ b/drivers/auxdisplay/Kconfig
@@ -6,6 +6,7 @@
6# 6#
7 7
8menu "Auxiliary Display support" 8menu "Auxiliary Display support"
9 depends on PARPORT
9 10
10config KS0108 11config KS0108
11 tristate "KS0108 LCD Controller" 12 tristate "KS0108 LCD Controller"
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
index e177c9533b6c..e1c0730a3b99 100644
--- a/drivers/base/devres.c
+++ b/drivers/base/devres.c
@@ -101,19 +101,6 @@ static void add_dr(struct device *dev, struct devres_node *node)
101 list_add_tail(&node->entry, &dev->devres_head); 101 list_add_tail(&node->entry, &dev->devres_head);
102} 102}
103 103
104/**
105 * devres_alloc - Allocate device resource data
106 * @release: Release function devres will be associated with
107 * @size: Allocation size
108 * @gfp: Allocation flags
109 *
110 * allocate devres of @size bytes. The allocated area is zeroed, then
111 * associated with @release. The returned pointer can be passed to
112 * other devres_*() functions.
113 *
114 * RETURNS:
115 * Pointer to allocated devres on success, NULL on failure.
116 */
117#ifdef CONFIG_DEBUG_DEVRES 104#ifdef CONFIG_DEBUG_DEVRES
118void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp, 105void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
119 const char *name) 106 const char *name)
@@ -128,6 +115,19 @@ void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
128} 115}
129EXPORT_SYMBOL_GPL(__devres_alloc); 116EXPORT_SYMBOL_GPL(__devres_alloc);
130#else 117#else
118/**
119 * devres_alloc - Allocate device resource data
120 * @release: Release function devres will be associated with
121 * @size: Allocation size
122 * @gfp: Allocation flags
123 *
124 * Allocate devres of @size bytes. The allocated area is zeroed, then
125 * associated with @release. The returned pointer can be passed to
126 * other devres_*() functions.
127 *
128 * RETURNS:
129 * Pointer to allocated devres on success, NULL on failure.
130 */
131void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp) 131void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
132{ 132{
133 struct devres *dr; 133 struct devres *dr;
@@ -416,7 +416,7 @@ static int release_nodes(struct device *dev, struct list_head *first,
416} 416}
417 417
418/** 418/**
419 * devres_release_all - Release all resources 419 * devres_release_all - Release all managed resources
420 * @dev: Device to release resources for 420 * @dev: Device to release resources for
421 * 421 *
422 * Release all resources associated with @dev. This function is 422 * Release all resources associated with @dev. This function is
@@ -600,7 +600,7 @@ static int devm_kzalloc_match(struct device *dev, void *res, void *data)
600} 600}
601 601
602/** 602/**
603 * devm_kzalloc - Managed kzalloc 603 * devm_kzalloc - Resource-managed kzalloc
604 * @dev: Device to allocate memory for 604 * @dev: Device to allocate memory for
605 * @size: Allocation size 605 * @size: Allocation size
606 * @gfp: Allocation gfp flags 606 * @gfp: Allocation gfp flags
@@ -628,7 +628,7 @@ void * devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
628EXPORT_SYMBOL_GPL(devm_kzalloc); 628EXPORT_SYMBOL_GPL(devm_kzalloc);
629 629
630/** 630/**
631 * devm_kfree - Managed kfree 631 * devm_kfree - Resource-managed kfree
632 * @dev: Device this memory belongs to 632 * @dev: Device this memory belongs to
633 * @p: Memory to free 633 * @p: Memory to free
634 * 634 *
diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c
index 9406259754ad..91970e9bb05e 100644
--- a/drivers/base/dmapool.c
+++ b/drivers/base/dmapool.c
@@ -8,6 +8,7 @@
8#include <linux/slab.h> 8#include <linux/slab.h>
9#include <linux/module.h> 9#include <linux/module.h>
10#include <linux/poison.h> 10#include <linux/poison.h>
11#include <linux/sched.h>
11 12
12/* 13/*
13 * Pool allocator ... wraps the dma_alloc_coherent page allocator, so 14 * Pool allocator ... wraps the dma_alloc_coherent page allocator, so
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 17b5ece8f82c..869ff8c00146 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -160,6 +160,11 @@ static void platform_device_release(struct device *dev)
160 * 160 *
161 * Create a platform device object which can have other objects attached 161 * Create a platform device object which can have other objects attached
162 * to it, and which will have attached objects freed when it is released. 162 * to it, and which will have attached objects freed when it is released.
163 *
164 * This device will be marked as not supporting hotpluggable drivers; no
165 * device add/remove uevents will be generated. In the unusual case that
166 * the device isn't being dynamically allocated as a legacy "probe the
167 * hardware" driver, infrastructure code should reverse this marking.
163 */ 168 */
164struct platform_device *platform_device_alloc(const char *name, unsigned int id) 169struct platform_device *platform_device_alloc(const char *name, unsigned int id)
165{ 170{
@@ -172,6 +177,12 @@ struct platform_device *platform_device_alloc(const char *name, unsigned int id)
172 pa->pdev.id = id; 177 pa->pdev.id = id;
173 device_initialize(&pa->pdev.dev); 178 device_initialize(&pa->pdev.dev);
174 pa->pdev.dev.release = platform_device_release; 179 pa->pdev.dev.release = platform_device_release;
180
181 /* prevent hotplug "modprobe $(MODALIAS)" from causing trouble in
182 * legacy probe-the-hardware drivers, which don't properly split
183 * out device enumeration logic from drivers.
184 */
185 pa->pdev.dev.uevent_suppress = 1;
175 } 186 }
176 187
177 return pa ? &pa->pdev : NULL; 188 return pa ? &pa->pdev : NULL;
@@ -349,8 +360,15 @@ EXPORT_SYMBOL_GPL(platform_device_unregister);
349 * This function creates a simple platform device that requires minimal 360 * This function creates a simple platform device that requires minimal
350 * resource and memory management. Canned release function freeing 361 * resource and memory management. Canned release function freeing
351 * memory allocated for the device allows drivers using such devices 362 * memory allocated for the device allows drivers using such devices
352 * to be unloaded iwithout waiting for the last reference to the device 363 * to be unloaded without waiting for the last reference to the device
353 * to be dropped. 364 * to be dropped.
365 *
366 * This interface is primarily intended for use with legacy drivers
367 * which probe hardware directly. Because such drivers create sysfs
368 * device nodes themselves, rather than letting system infrastructure
369 * handle such device enumeration tasks, they don't fully conform to
370 * the Linux driver model. In particular, when such drivers are built
371 * as modules, they can't be "hotplugged".
354 */ 372 */
355struct platform_device *platform_device_register_simple(char *name, unsigned int id, 373struct platform_device *platform_device_register_simple(char *name, unsigned int id,
356 struct resource *res, unsigned int num) 374 struct resource *res, unsigned int num)
diff --git a/drivers/base/topology.c b/drivers/base/topology.c
index 067a9e8bc377..8d8cdfec6529 100644
--- a/drivers/base/topology.c
+++ b/drivers/base/topology.c
@@ -126,10 +126,13 @@ static int __cpuinit topology_cpu_callback(struct notifier_block *nfb,
126 126
127 switch (action) { 127 switch (action) {
128 case CPU_UP_PREPARE: 128 case CPU_UP_PREPARE:
129 case CPU_UP_PREPARE_FROZEN:
129 rc = topology_add_dev(cpu); 130 rc = topology_add_dev(cpu);
130 break; 131 break;
131 case CPU_UP_CANCELED: 132 case CPU_UP_CANCELED:
133 case CPU_UP_CANCELED_FROZEN:
132 case CPU_DEAD: 134 case CPU_DEAD:
135 case CPU_DEAD_FROZEN:
133 topology_remove_dev(cpu); 136 topology_remove_dev(cpu);
134 break; 137 break;
135 } 138 }
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 17ee97f3a99b..b4c8319138b2 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -444,8 +444,6 @@ config CDROM_PKTCDVD_WCACHE
444 this option is dangerous unless the CD-RW media is known good, as we 444 this option is dangerous unless the CD-RW media is known good, as we
445 don't do deferred write error handling yet. 445 don't do deferred write error handling yet.
446 446
447source "drivers/s390/block/Kconfig"
448
449config ATA_OVER_ETH 447config ATA_OVER_ETH
450 tristate "ATA over Ethernet support" 448 tristate "ATA over Ethernet support"
451 depends on NET 449 depends on NET
@@ -453,6 +451,8 @@ config ATA_OVER_ETH
453 This driver provides Support for ATA over Ethernet block 451 This driver provides Support for ATA over Ethernet block
454 devices like the Coraid EtherDrive (R) Storage Blade. 452 devices like the Coraid EtherDrive (R) Storage Blade.
455 453
454source "drivers/s390/block/Kconfig"
455
456endmenu 456endmenu
457 457
458endif 458endif
diff --git a/drivers/block/acsi_slm.c b/drivers/block/acsi_slm.c
index e2e043290963..1d9d9b4f48cc 100644
--- a/drivers/block/acsi_slm.c
+++ b/drivers/block/acsi_slm.c
@@ -65,7 +65,6 @@ not be guaranteed. There are several ways to assure this:
65#include <linux/time.h> 65#include <linux/time.h>
66#include <linux/mm.h> 66#include <linux/mm.h>
67#include <linux/slab.h> 67#include <linux/slab.h>
68#include <linux/smp_lock.h>
69 68
70#include <asm/pgtable.h> 69#include <asm/pgtable.h>
71#include <asm/system.h> 70#include <asm/system.h>
diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
index 65a725cd3422..5acc6c44aead 100644
--- a/drivers/block/cciss.c
+++ b/drivers/block/cciss.c
@@ -45,6 +45,10 @@
45#include <linux/blkdev.h> 45#include <linux/blkdev.h>
46#include <linux/genhd.h> 46#include <linux/genhd.h>
47#include <linux/completion.h> 47#include <linux/completion.h>
48#include <scsi/scsi.h>
49#include <scsi/sg.h>
50#include <scsi/scsi_ioctl.h>
51#include <linux/cdrom.h>
48 52
49#define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin)) 53#define CCISS_DRIVER_VERSION(maj,min,submin) ((maj<<16)|(min<<8)|(submin))
50#define DRIVER_NAME "HP CISS Driver (v 3.6.14)" 54#define DRIVER_NAME "HP CISS Driver (v 3.6.14)"
@@ -1152,6 +1156,30 @@ static int cciss_ioctl(struct inode *inode, struct file *filep,
1152 kfree(ioc); 1156 kfree(ioc);
1153 return status; 1157 return status;
1154 } 1158 }
1159
1160 /* scsi_cmd_ioctl handles these, below, though some are not */
1161 /* very meaningful for cciss. SG_IO is the main one people want. */
1162
1163 case SG_GET_VERSION_NUM:
1164 case SG_SET_TIMEOUT:
1165 case SG_GET_TIMEOUT:
1166 case SG_GET_RESERVED_SIZE:
1167 case SG_SET_RESERVED_SIZE:
1168 case SG_EMULATED_HOST:
1169 case SG_IO:
1170 case SCSI_IOCTL_SEND_COMMAND:
1171 return scsi_cmd_ioctl(filep, disk, cmd, argp);
1172
1173 /* scsi_cmd_ioctl would normally handle these, below, but */
1174 /* they aren't a good fit for cciss, as CD-ROMs are */
1175 /* not supported, and we don't have any bus/target/lun */
1176 /* which we present to the kernel. */
1177
1178 case CDROM_SEND_PACKET:
1179 case CDROMCLOSETRAY:
1180 case CDROMEJECT:
1181 case SCSI_IOCTL_GET_IDLUN:
1182 case SCSI_IOCTL_GET_BUS_NUMBER:
1155 default: 1183 default:
1156 return -ENOTTY; 1184 return -ENOTTY;
1157 } 1185 }
@@ -1234,7 +1262,7 @@ static void cciss_softirq_done(struct request *rq)
1234 pci_unmap_page(h->pdev, temp64.val, cmd->SG[i].Len, ddir); 1262 pci_unmap_page(h->pdev, temp64.val, cmd->SG[i].Len, ddir);
1235 } 1263 }
1236 1264
1237 complete_buffers(rq->bio, rq->errors); 1265 complete_buffers(rq->bio, (rq->errors == 0));
1238 1266
1239 if (blk_fs_request(rq)) { 1267 if (blk_fs_request(rq)) {
1240 const int rw = rq_data_dir(rq); 1268 const int rw = rq_data_dir(rq);
@@ -1248,7 +1276,7 @@ static void cciss_softirq_done(struct request *rq)
1248 1276
1249 add_disk_randomness(rq->rq_disk); 1277 add_disk_randomness(rq->rq_disk);
1250 spin_lock_irqsave(&h->lock, flags); 1278 spin_lock_irqsave(&h->lock, flags);
1251 end_that_request_last(rq, rq->errors); 1279 end_that_request_last(rq, (rq->errors == 0));
1252 cmd_free(h, cmd, 1); 1280 cmd_free(h, cmd, 1);
1253 cciss_check_queues(h); 1281 cciss_check_queues(h);
1254 spin_unlock_irqrestore(&h->lock, flags); 1282 spin_unlock_irqrestore(&h->lock, flags);
@@ -2336,6 +2364,44 @@ static inline void resend_cciss_cmd(ctlr_info_t *h, CommandList_struct *c)
2336 start_io(h); 2364 start_io(h);
2337} 2365}
2338 2366
2367static inline int evaluate_target_status(CommandList_struct *cmd)
2368{
2369 unsigned char sense_key;
2370 int error_count = 1;
2371
2372 if (cmd->err_info->ScsiStatus != 0x02) { /* not check condition? */
2373 if (!blk_pc_request(cmd->rq))
2374 printk(KERN_WARNING "cciss: cmd %p "
2375 "has SCSI Status 0x%x\n",
2376 cmd, cmd->err_info->ScsiStatus);
2377 return error_count;
2378 }
2379
2380 /* check the sense key */
2381 sense_key = 0xf & cmd->err_info->SenseInfo[2];
2382 /* no status or recovered error */
2383 if ((sense_key == 0x0) || (sense_key == 0x1))
2384 error_count = 0;
2385
2386 if (!blk_pc_request(cmd->rq)) { /* Not SG_IO or similar? */
2387 if (error_count != 0)
2388 printk(KERN_WARNING "cciss: cmd %p has CHECK CONDITION"
2389 " sense key = 0x%x\n", cmd, sense_key);
2390 return error_count;
2391 }
2392
2393 /* SG_IO or similar, copy sense data back */
2394 if (cmd->rq->sense) {
2395 if (cmd->rq->sense_len > cmd->err_info->SenseLen)
2396 cmd->rq->sense_len = cmd->err_info->SenseLen;
2397 memcpy(cmd->rq->sense, cmd->err_info->SenseInfo,
2398 cmd->rq->sense_len);
2399 } else
2400 cmd->rq->sense_len = 0;
2401
2402 return error_count;
2403}
2404
2339/* checks the status of the job and calls complete buffers to mark all 2405/* checks the status of the job and calls complete buffers to mark all
2340 * buffers for the completed job. Note that this function does not need 2406 * buffers for the completed job. Note that this function does not need
2341 * to hold the hba/queue lock. 2407 * to hold the hba/queue lock.
@@ -2343,109 +2409,99 @@ static inline void resend_cciss_cmd(ctlr_info_t *h, CommandList_struct *c)
2343static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd, 2409static inline void complete_command(ctlr_info_t *h, CommandList_struct *cmd,
2344 int timeout) 2410 int timeout)
2345{ 2411{
2346 int status = 1;
2347 int retry_cmd = 0; 2412 int retry_cmd = 0;
2413 struct request *rq = cmd->rq;
2414
2415 rq->errors = 0;
2348 2416
2349 if (timeout) 2417 if (timeout)
2350 status = 0; 2418 rq->errors = 1;
2351 2419
2352 if (cmd->err_info->CommandStatus != 0) { /* an error has occurred */ 2420 if (cmd->err_info->CommandStatus == 0) /* no error has occurred */
2353 switch (cmd->err_info->CommandStatus) { 2421 goto after_error_processing;
2354 unsigned char sense_key;
2355 case CMD_TARGET_STATUS:
2356 status = 0;
2357 2422
2358 if (cmd->err_info->ScsiStatus == 0x02) { 2423 switch (cmd->err_info->CommandStatus) {
2359 printk(KERN_WARNING "cciss: cmd %p " 2424 case CMD_TARGET_STATUS:
2360 "has CHECK CONDITION " 2425 rq->errors = evaluate_target_status(cmd);
2361 " byte 2 = 0x%x\n", cmd, 2426 break;
2362 cmd->err_info->SenseInfo[2] 2427 case CMD_DATA_UNDERRUN:
2363 ); 2428 if (blk_fs_request(cmd->rq)) {
2364 /* check the sense key */
2365 sense_key = 0xf & cmd->err_info->SenseInfo[2];
2366 /* no status or recovered error */
2367 if ((sense_key == 0x0) || (sense_key == 0x1)) {
2368 status = 1;
2369 }
2370 } else {
2371 printk(KERN_WARNING "cciss: cmd %p "
2372 "has SCSI Status 0x%x\n",
2373 cmd, cmd->err_info->ScsiStatus);
2374 }
2375 break;
2376 case CMD_DATA_UNDERRUN:
2377 printk(KERN_WARNING "cciss: cmd %p has" 2429 printk(KERN_WARNING "cciss: cmd %p has"
2378 " completed with data underrun " 2430 " completed with data underrun "
2379 "reported\n", cmd); 2431 "reported\n", cmd);
2380 break; 2432 cmd->rq->data_len = cmd->err_info->ResidualCnt;
2381 case CMD_DATA_OVERRUN: 2433 }
2434 break;
2435 case CMD_DATA_OVERRUN:
2436 if (blk_fs_request(cmd->rq))
2382 printk(KERN_WARNING "cciss: cmd %p has" 2437 printk(KERN_WARNING "cciss: cmd %p has"
2383 " completed with data overrun " 2438 " completed with data overrun "
2384 "reported\n", cmd); 2439 "reported\n", cmd);
2385 break; 2440 break;
2386 case CMD_INVALID: 2441 case CMD_INVALID:
2387 printk(KERN_WARNING "cciss: cmd %p is " 2442 printk(KERN_WARNING "cciss: cmd %p is "
2388 "reported invalid\n", cmd); 2443 "reported invalid\n", cmd);
2389 status = 0; 2444 rq->errors = 1;
2390 break; 2445 break;
2391 case CMD_PROTOCOL_ERR: 2446 case CMD_PROTOCOL_ERR:
2392 printk(KERN_WARNING "cciss: cmd %p has " 2447 printk(KERN_WARNING "cciss: cmd %p has "
2393 "protocol error \n", cmd); 2448 "protocol error \n", cmd);
2394 status = 0; 2449 rq->errors = 1;
2395 break; 2450 break;
2396 case CMD_HARDWARE_ERR: 2451 case CMD_HARDWARE_ERR:
2397 printk(KERN_WARNING "cciss: cmd %p had " 2452 printk(KERN_WARNING "cciss: cmd %p had "
2398 " hardware error\n", cmd); 2453 " hardware error\n", cmd);
2399 status = 0; 2454 rq->errors = 1;
2400 break; 2455 break;
2401 case CMD_CONNECTION_LOST: 2456 case CMD_CONNECTION_LOST:
2402 printk(KERN_WARNING "cciss: cmd %p had " 2457 printk(KERN_WARNING "cciss: cmd %p had "
2403 "connection lost\n", cmd); 2458 "connection lost\n", cmd);
2404 status = 0; 2459 rq->errors = 1;
2405 break; 2460 break;
2406 case CMD_ABORTED: 2461 case CMD_ABORTED:
2407 printk(KERN_WARNING "cciss: cmd %p was " 2462 printk(KERN_WARNING "cciss: cmd %p was "
2408 "aborted\n", cmd); 2463 "aborted\n", cmd);
2409 status = 0; 2464 rq->errors = 1;
2410 break; 2465 break;
2411 case CMD_ABORT_FAILED: 2466 case CMD_ABORT_FAILED:
2412 printk(KERN_WARNING "cciss: cmd %p reports " 2467 printk(KERN_WARNING "cciss: cmd %p reports "
2413 "abort failed\n", cmd); 2468 "abort failed\n", cmd);
2414 status = 0; 2469 rq->errors = 1;
2415 break; 2470 break;
2416 case CMD_UNSOLICITED_ABORT: 2471 case CMD_UNSOLICITED_ABORT:
2417 printk(KERN_WARNING "cciss%d: unsolicited " 2472 printk(KERN_WARNING "cciss%d: unsolicited "
2418 "abort %p\n", h->ctlr, cmd); 2473 "abort %p\n", h->ctlr, cmd);
2419 if (cmd->retry_count < MAX_CMD_RETRIES) { 2474 if (cmd->retry_count < MAX_CMD_RETRIES) {
2420 retry_cmd = 1; 2475 retry_cmd = 1;
2421 printk(KERN_WARNING 2476 printk(KERN_WARNING
2422 "cciss%d: retrying %p\n", h->ctlr, cmd); 2477 "cciss%d: retrying %p\n", h->ctlr, cmd);
2423 cmd->retry_count++; 2478 cmd->retry_count++;
2424 } else 2479 } else
2425 printk(KERN_WARNING 2480 printk(KERN_WARNING
2426 "cciss%d: %p retried too " 2481 "cciss%d: %p retried too "
2427 "many times\n", h->ctlr, cmd); 2482 "many times\n", h->ctlr, cmd);
2428 status = 0; 2483 rq->errors = 1;
2429 break; 2484 break;
2430 case CMD_TIMEOUT: 2485 case CMD_TIMEOUT:
2431 printk(KERN_WARNING "cciss: cmd %p timedout\n", cmd); 2486 printk(KERN_WARNING "cciss: cmd %p timedout\n", cmd);
2432 status = 0; 2487 rq->errors = 1;
2433 break; 2488 break;
2434 default: 2489 default:
2435 printk(KERN_WARNING "cciss: cmd %p returned " 2490 printk(KERN_WARNING "cciss: cmd %p returned "
2436 "unknown status %x\n", cmd, 2491 "unknown status %x\n", cmd,
2437 cmd->err_info->CommandStatus); 2492 cmd->err_info->CommandStatus);
2438 status = 0; 2493 rq->errors = 1;
2439 }
2440 } 2494 }
2495
2496after_error_processing:
2497
2441 /* We need to return this command */ 2498 /* We need to return this command */
2442 if (retry_cmd) { 2499 if (retry_cmd) {
2443 resend_cciss_cmd(h, cmd); 2500 resend_cciss_cmd(h, cmd);
2444 return; 2501 return;
2445 } 2502 }
2446 2503 cmd->rq->data_len = 0;
2447 cmd->rq->completion_data = cmd; 2504 cmd->rq->completion_data = cmd;
2448 cmd->rq->errors = status;
2449 blk_add_trace_rq(cmd->rq->q, cmd->rq, BLK_TA_COMPLETE); 2505 blk_add_trace_rq(cmd->rq->q, cmd->rq, BLK_TA_COMPLETE);
2450 blk_complete_request(cmd->rq); 2506 blk_complete_request(cmd->rq);
2451} 2507}
@@ -2539,32 +2595,40 @@ static void do_cciss_request(request_queue_t *q)
2539#endif /* CCISS_DEBUG */ 2595#endif /* CCISS_DEBUG */
2540 2596
2541 c->Header.SGList = c->Header.SGTotal = seg; 2597 c->Header.SGList = c->Header.SGTotal = seg;
2542 if(h->cciss_read == CCISS_READ_10) { 2598 if (likely(blk_fs_request(creq))) {
2543 c->Request.CDB[1] = 0; 2599 if(h->cciss_read == CCISS_READ_10) {
2544 c->Request.CDB[2] = (start_blk >> 24) & 0xff; //MSB 2600 c->Request.CDB[1] = 0;
2545 c->Request.CDB[3] = (start_blk >> 16) & 0xff; 2601 c->Request.CDB[2] = (start_blk >> 24) & 0xff; //MSB
2546 c->Request.CDB[4] = (start_blk >> 8) & 0xff; 2602 c->Request.CDB[3] = (start_blk >> 16) & 0xff;
2547 c->Request.CDB[5] = start_blk & 0xff; 2603 c->Request.CDB[4] = (start_blk >> 8) & 0xff;
2548 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB 2604 c->Request.CDB[5] = start_blk & 0xff;
2549 c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff; 2605 c->Request.CDB[6] = 0; // (sect >> 24) & 0xff; MSB
2550 c->Request.CDB[8] = creq->nr_sectors & 0xff; 2606 c->Request.CDB[7] = (creq->nr_sectors >> 8) & 0xff;
2551 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0; 2607 c->Request.CDB[8] = creq->nr_sectors & 0xff;
2608 c->Request.CDB[9] = c->Request.CDB[11] = c->Request.CDB[12] = 0;
2609 } else {
2610 c->Request.CDBLen = 16;
2611 c->Request.CDB[1]= 0;
2612 c->Request.CDB[2]= (start_blk >> 56) & 0xff; //MSB
2613 c->Request.CDB[3]= (start_blk >> 48) & 0xff;
2614 c->Request.CDB[4]= (start_blk >> 40) & 0xff;
2615 c->Request.CDB[5]= (start_blk >> 32) & 0xff;
2616 c->Request.CDB[6]= (start_blk >> 24) & 0xff;
2617 c->Request.CDB[7]= (start_blk >> 16) & 0xff;
2618 c->Request.CDB[8]= (start_blk >> 8) & 0xff;
2619 c->Request.CDB[9]= start_blk & 0xff;
2620 c->Request.CDB[10]= (creq->nr_sectors >> 24) & 0xff;
2621 c->Request.CDB[11]= (creq->nr_sectors >> 16) & 0xff;
2622 c->Request.CDB[12]= (creq->nr_sectors >> 8) & 0xff;
2623 c->Request.CDB[13]= creq->nr_sectors & 0xff;
2624 c->Request.CDB[14] = c->Request.CDB[15] = 0;
2625 }
2626 } else if (blk_pc_request(creq)) {
2627 c->Request.CDBLen = creq->cmd_len;
2628 memcpy(c->Request.CDB, creq->cmd, BLK_MAX_CDB);
2552 } else { 2629 } else {
2553 c->Request.CDBLen = 16; 2630 printk(KERN_WARNING "cciss%d: bad request type %d\n", h->ctlr, creq->cmd_type);
2554 c->Request.CDB[1]= 0; 2631 BUG();
2555 c->Request.CDB[2]= (start_blk >> 56) & 0xff; //MSB
2556 c->Request.CDB[3]= (start_blk >> 48) & 0xff;
2557 c->Request.CDB[4]= (start_blk >> 40) & 0xff;
2558 c->Request.CDB[5]= (start_blk >> 32) & 0xff;
2559 c->Request.CDB[6]= (start_blk >> 24) & 0xff;
2560 c->Request.CDB[7]= (start_blk >> 16) & 0xff;
2561 c->Request.CDB[8]= (start_blk >> 8) & 0xff;
2562 c->Request.CDB[9]= start_blk & 0xff;
2563 c->Request.CDB[10]= (creq->nr_sectors >> 24) & 0xff;
2564 c->Request.CDB[11]= (creq->nr_sectors >> 16) & 0xff;
2565 c->Request.CDB[12]= (creq->nr_sectors >> 8) & 0xff;
2566 c->Request.CDB[13]= creq->nr_sectors & 0xff;
2567 c->Request.CDB[14] = c->Request.CDB[15] = 0;
2568 } 2632 }
2569 2633
2570 spin_lock_irq(q->queue_lock); 2634 spin_lock_irq(q->queue_lock);
@@ -3405,13 +3469,39 @@ static int __devinit cciss_init_one(struct pci_dev *pdev,
3405 return -1; 3469 return -1;
3406} 3470}
3407 3471
3408static void cciss_remove_one(struct pci_dev *pdev) 3472static void cciss_shutdown(struct pci_dev *pdev)
3409{ 3473{
3410 ctlr_info_t *tmp_ptr; 3474 ctlr_info_t *tmp_ptr;
3411 int i, j; 3475 int i;
3412 char flush_buf[4]; 3476 char flush_buf[4];
3413 int return_code; 3477 int return_code;
3414 3478
3479 tmp_ptr = pci_get_drvdata(pdev);
3480 if (tmp_ptr == NULL)
3481 return;
3482 i = tmp_ptr->ctlr;
3483 if (hba[i] == NULL)
3484 return;
3485
3486 /* Turn board interrupts off and send the flush cache command */
3487 /* sendcmd will turn off interrupt, and send the flush...
3488 * To write all data in the battery backed cache to disks */
3489 memset(flush_buf, 0, 4);
3490 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL,
3491 TYPE_CMD);
3492 if (return_code == IO_OK) {
3493 printk(KERN_INFO "Completed flushing cache on controller %d\n", i);
3494 } else {
3495 printk(KERN_WARNING "Error flushing cache on controller %d\n", i);
3496 }
3497 free_irq(hba[i]->intr[2], hba[i]);
3498}
3499
3500static void __devexit cciss_remove_one(struct pci_dev *pdev)
3501{
3502 ctlr_info_t *tmp_ptr;
3503 int i, j;
3504
3415 if (pci_get_drvdata(pdev) == NULL) { 3505 if (pci_get_drvdata(pdev) == NULL) {
3416 printk(KERN_ERR "cciss: Unable to remove device \n"); 3506 printk(KERN_ERR "cciss: Unable to remove device \n");
3417 return; 3507 return;
@@ -3442,18 +3532,7 @@ static void cciss_remove_one(struct pci_dev *pdev)
3442 3532
3443 cciss_unregister_scsi(i); /* unhook from SCSI subsystem */ 3533 cciss_unregister_scsi(i); /* unhook from SCSI subsystem */
3444 3534
3445 /* Turn board interrupts off and send the flush cache command */ 3535 cciss_shutdown(pdev);
3446 /* sendcmd will turn off interrupt, and send the flush...
3447 * To write all data in the battery backed cache to disks */
3448 memset(flush_buf, 0, 4);
3449 return_code = sendcmd(CCISS_CACHE_FLUSH, i, flush_buf, 4, 0, 0, 0, NULL,
3450 TYPE_CMD);
3451 if (return_code == IO_OK) {
3452 printk(KERN_INFO "Completed flushing cache on controller %d\n", i);
3453 } else {
3454 printk(KERN_WARNING "Error flushing cache on controller %d\n", i);
3455 }
3456 free_irq(hba[i]->intr[2], hba[i]);
3457 3536
3458#ifdef CONFIG_PCI_MSI 3537#ifdef CONFIG_PCI_MSI
3459 if (hba[i]->msix_vector) 3538 if (hba[i]->msix_vector)
@@ -3486,7 +3565,7 @@ static struct pci_driver cciss_pci_driver = {
3486 .probe = cciss_init_one, 3565 .probe = cciss_init_one,
3487 .remove = __devexit_p(cciss_remove_one), 3566 .remove = __devexit_p(cciss_remove_one),
3488 .id_table = cciss_pci_device_id, /* id_table */ 3567 .id_table = cciss_pci_device_id, /* id_table */
3489 .shutdown = cciss_remove_one, 3568 .shutdown = cciss_shutdown,
3490}; 3569};
3491 3570
3492/* 3571/*
diff --git a/drivers/block/cciss_scsi.c b/drivers/block/cciss_scsi.c
index bb15051ffbe0..90961a8ea895 100644
--- a/drivers/block/cciss_scsi.c
+++ b/drivers/block/cciss_scsi.c
@@ -35,7 +35,6 @@
35 35
36#include <asm/atomic.h> 36#include <asm/atomic.h>
37 37
38#include <scsi/scsi.h>
39#include <scsi/scsi_cmnd.h> 38#include <scsi/scsi_cmnd.h>
40#include <scsi/scsi_device.h> 39#include <scsi/scsi_device.h>
41#include <scsi/scsi_host.h> 40#include <scsi/scsi_host.h>
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 5231ed7e723f..3587cb434371 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4334,7 +4334,10 @@ static int __init floppy_init(void)
4334 if (err) 4334 if (err)
4335 goto out_flush_work; 4335 goto out_flush_work;
4336 4336
4337 device_create_file(&floppy_device[drive].dev,&dev_attr_cmos); 4337 err = device_create_file(&floppy_device[drive].dev,&dev_attr_cmos);
4338 if (err)
4339 goto out_unreg_platform_dev;
4340
4338 /* to be cleaned up... */ 4341 /* to be cleaned up... */
4339 disks[drive]->private_data = (void *)(long)drive; 4342 disks[drive]->private_data = (void *)(long)drive;
4340 disks[drive]->queue = floppy_queue; 4343 disks[drive]->queue = floppy_queue;
@@ -4345,6 +4348,8 @@ static int __init floppy_init(void)
4345 4348
4346 return 0; 4349 return 0;
4347 4350
4351out_unreg_platform_dev:
4352 platform_device_unregister(&floppy_device[drive]);
4348out_flush_work: 4353out_flush_work:
4349 flush_scheduled_work(); 4354 flush_scheduled_work();
4350 if (usage_count) 4355 if (usage_count)
diff --git a/drivers/block/loop.c b/drivers/block/loop.c
index 0d4ccd4a0957..5526eadb6592 100644
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
@@ -77,9 +77,8 @@
77 77
78#include <asm/uaccess.h> 78#include <asm/uaccess.h>
79 79
80static int max_loop = 8; 80static LIST_HEAD(loop_devices);
81static struct loop_device *loop_dev; 81static DEFINE_MUTEX(loop_devices_mutex);
82static struct gendisk **disks;
83 82
84/* 83/*
85 * Transfer functions 84 * Transfer functions
@@ -183,7 +182,7 @@ figure_loop_size(struct loop_device *lo)
183 if (unlikely((loff_t)x != size)) 182 if (unlikely((loff_t)x != size))
184 return -EFBIG; 183 return -EFBIG;
185 184
186 set_capacity(disks[lo->lo_number], x); 185 set_capacity(lo->lo_disk, x);
187 return 0; 186 return 0;
188} 187}
189 188
@@ -244,17 +243,13 @@ static int do_lo_send_aops(struct loop_device *lo, struct bio_vec *bvec,
244 transfer_result = lo_do_transfer(lo, WRITE, page, offset, 243 transfer_result = lo_do_transfer(lo, WRITE, page, offset,
245 bvec->bv_page, bv_offs, size, IV); 244 bvec->bv_page, bv_offs, size, IV);
246 if (unlikely(transfer_result)) { 245 if (unlikely(transfer_result)) {
247 char *kaddr;
248
249 /* 246 /*
250 * The transfer failed, but we still write the data to 247 * The transfer failed, but we still write the data to
251 * keep prepare/commit calls balanced. 248 * keep prepare/commit calls balanced.
252 */ 249 */
253 printk(KERN_ERR "loop: transfer error block %llu\n", 250 printk(KERN_ERR "loop: transfer error block %llu\n",
254 (unsigned long long)index); 251 (unsigned long long)index);
255 kaddr = kmap_atomic(page, KM_USER0); 252 zero_user_page(page, offset, size, KM_USER0);
256 memset(kaddr + offset, 0, size);
257 kunmap_atomic(kaddr, KM_USER0);
258 } 253 }
259 flush_dcache_page(page); 254 flush_dcache_page(page);
260 ret = aops->commit_write(file, page, offset, 255 ret = aops->commit_write(file, page, offset,
@@ -812,7 +807,7 @@ static int loop_set_fd(struct loop_device *lo, struct file *lo_file,
812 lo->lo_queue->queuedata = lo; 807 lo->lo_queue->queuedata = lo;
813 lo->lo_queue->unplug_fn = loop_unplug; 808 lo->lo_queue->unplug_fn = loop_unplug;
814 809
815 set_capacity(disks[lo->lo_number], size); 810 set_capacity(lo->lo_disk, size);
816 bd_set_size(bdev, size << 9); 811 bd_set_size(bdev, size << 9);
817 812
818 set_blocksize(bdev, lo_blocksize); 813 set_blocksize(bdev, lo_blocksize);
@@ -832,7 +827,7 @@ out_clr:
832 lo->lo_device = NULL; 827 lo->lo_device = NULL;
833 lo->lo_backing_file = NULL; 828 lo->lo_backing_file = NULL;
834 lo->lo_flags = 0; 829 lo->lo_flags = 0;
835 set_capacity(disks[lo->lo_number], 0); 830 set_capacity(lo->lo_disk, 0);
836 invalidate_bdev(bdev); 831 invalidate_bdev(bdev);
837 bd_set_size(bdev, 0); 832 bd_set_size(bdev, 0);
838 mapping_set_gfp_mask(mapping, lo->old_gfp_mask); 833 mapping_set_gfp_mask(mapping, lo->old_gfp_mask);
@@ -918,7 +913,7 @@ static int loop_clr_fd(struct loop_device *lo, struct block_device *bdev)
918 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE); 913 memset(lo->lo_crypt_name, 0, LO_NAME_SIZE);
919 memset(lo->lo_file_name, 0, LO_NAME_SIZE); 914 memset(lo->lo_file_name, 0, LO_NAME_SIZE);
920 invalidate_bdev(bdev); 915 invalidate_bdev(bdev);
921 set_capacity(disks[lo->lo_number], 0); 916 set_capacity(lo->lo_disk, 0);
922 bd_set_size(bdev, 0); 917 bd_set_size(bdev, 0);
923 mapping_set_gfp_mask(filp->f_mapping, gfp); 918 mapping_set_gfp_mask(filp->f_mapping, gfp);
924 lo->lo_state = Lo_unbound; 919 lo->lo_state = Lo_unbound;
@@ -1357,8 +1352,9 @@ static struct block_device_operations lo_fops = {
1357/* 1352/*
1358 * And now the modules code and kernel interface. 1353 * And now the modules code and kernel interface.
1359 */ 1354 */
1355static int max_loop;
1360module_param(max_loop, int, 0); 1356module_param(max_loop, int, 0);
1361MODULE_PARM_DESC(max_loop, "Maximum number of loop devices (1-256)"); 1357MODULE_PARM_DESC(max_loop, "obsolete, loop device is created on-demand");
1362MODULE_LICENSE("GPL"); 1358MODULE_LICENSE("GPL");
1363MODULE_ALIAS_BLOCKDEV_MAJOR(LOOP_MAJOR); 1359MODULE_ALIAS_BLOCKDEV_MAJOR(LOOP_MAJOR);
1364 1360
@@ -1383,7 +1379,7 @@ int loop_unregister_transfer(int number)
1383 1379
1384 xfer_funcs[n] = NULL; 1380 xfer_funcs[n] = NULL;
1385 1381
1386 for (lo = &loop_dev[0]; lo < &loop_dev[max_loop]; lo++) { 1382 list_for_each_entry(lo, &loop_devices, lo_list) {
1387 mutex_lock(&lo->lo_ctl_mutex); 1383 mutex_lock(&lo->lo_ctl_mutex);
1388 1384
1389 if (lo->lo_encryption == xfer) 1385 if (lo->lo_encryption == xfer)
@@ -1398,91 +1394,100 @@ int loop_unregister_transfer(int number)
1398EXPORT_SYMBOL(loop_register_transfer); 1394EXPORT_SYMBOL(loop_register_transfer);
1399EXPORT_SYMBOL(loop_unregister_transfer); 1395EXPORT_SYMBOL(loop_unregister_transfer);
1400 1396
1401static int __init loop_init(void) 1397static struct loop_device *loop_init_one(int i)
1402{ 1398{
1403 int i; 1399 struct loop_device *lo;
1400 struct gendisk *disk;
1404 1401
1405 if (max_loop < 1 || max_loop > 256) { 1402 list_for_each_entry(lo, &loop_devices, lo_list) {
1406 printk(KERN_WARNING "loop: invalid max_loop (must be between" 1403 if (lo->lo_number == i)
1407 " 1 and 256), using default (8)\n"); 1404 return lo;
1408 max_loop = 8;
1409 } 1405 }
1410 1406
1411 if (register_blkdev(LOOP_MAJOR, "loop")) 1407 lo = kzalloc(sizeof(*lo), GFP_KERNEL);
1412 return -EIO; 1408 if (!lo)
1413 1409 goto out;
1414 loop_dev = kmalloc(max_loop * sizeof(struct loop_device), GFP_KERNEL);
1415 if (!loop_dev)
1416 goto out_mem1;
1417 memset(loop_dev, 0, max_loop * sizeof(struct loop_device));
1418 1410
1419 disks = kmalloc(max_loop * sizeof(struct gendisk *), GFP_KERNEL); 1411 lo->lo_queue = blk_alloc_queue(GFP_KERNEL);
1420 if (!disks) 1412 if (!lo->lo_queue)
1421 goto out_mem2; 1413 goto out_free_dev;
1414
1415 disk = lo->lo_disk = alloc_disk(1);
1416 if (!disk)
1417 goto out_free_queue;
1418
1419 mutex_init(&lo->lo_ctl_mutex);
1420 lo->lo_number = i;
1421 lo->lo_thread = NULL;
1422 init_waitqueue_head(&lo->lo_event);
1423 spin_lock_init(&lo->lo_lock);
1424 disk->major = LOOP_MAJOR;
1425 disk->first_minor = i;
1426 disk->fops = &lo_fops;
1427 disk->private_data = lo;
1428 disk->queue = lo->lo_queue;
1429 sprintf(disk->disk_name, "loop%d", i);
1430 add_disk(disk);
1431 list_add_tail(&lo->lo_list, &loop_devices);
1432 return lo;
1433
1434out_free_queue:
1435 blk_cleanup_queue(lo->lo_queue);
1436out_free_dev:
1437 kfree(lo);
1438out:
1439 return NULL;
1440}
1422 1441
1423 for (i = 0; i < max_loop; i++) { 1442static void loop_del_one(struct loop_device *lo)
1424 disks[i] = alloc_disk(1); 1443{
1425 if (!disks[i]) 1444 del_gendisk(lo->lo_disk);
1426 goto out_mem3; 1445 blk_cleanup_queue(lo->lo_queue);
1427 } 1446 put_disk(lo->lo_disk);
1447 list_del(&lo->lo_list);
1448 kfree(lo);
1449}
1428 1450
1429 for (i = 0; i < max_loop; i++) { 1451static struct kobject *loop_probe(dev_t dev, int *part, void *data)
1430 struct loop_device *lo = &loop_dev[i]; 1452{
1431 struct gendisk *disk = disks[i]; 1453 struct loop_device *lo;
1432 1454 struct kobject *kobj;
1433 memset(lo, 0, sizeof(*lo));
1434 lo->lo_queue = blk_alloc_queue(GFP_KERNEL);
1435 if (!lo->lo_queue)
1436 goto out_mem4;
1437 mutex_init(&lo->lo_ctl_mutex);
1438 lo->lo_number = i;
1439 lo->lo_thread = NULL;
1440 init_waitqueue_head(&lo->lo_event);
1441 spin_lock_init(&lo->lo_lock);
1442 disk->major = LOOP_MAJOR;
1443 disk->first_minor = i;
1444 disk->fops = &lo_fops;
1445 sprintf(disk->disk_name, "loop%d", i);
1446 disk->private_data = lo;
1447 disk->queue = lo->lo_queue;
1448 }
1449 1455
1450 /* We cannot fail after we call this, so another loop!*/ 1456 mutex_lock(&loop_devices_mutex);
1451 for (i = 0; i < max_loop; i++) 1457 lo = loop_init_one(dev & MINORMASK);
1452 add_disk(disks[i]); 1458 kobj = lo ? get_disk(lo->lo_disk) : ERR_PTR(-ENOMEM);
1453 printk(KERN_INFO "loop: loaded (max %d devices)\n", max_loop); 1459 mutex_unlock(&loop_devices_mutex);
1454 return 0;
1455 1460
1456out_mem4: 1461 *part = 0;
1457 while (i--) 1462 return kobj;
1458 blk_cleanup_queue(loop_dev[i].lo_queue);
1459 i = max_loop;
1460out_mem3:
1461 while (i--)
1462 put_disk(disks[i]);
1463 kfree(disks);
1464out_mem2:
1465 kfree(loop_dev);
1466out_mem1:
1467 unregister_blkdev(LOOP_MAJOR, "loop");
1468 printk(KERN_ERR "loop: ran out of memory\n");
1469 return -ENOMEM;
1470} 1463}
1471 1464
1472static void loop_exit(void) 1465static int __init loop_init(void)
1473{ 1466{
1474 int i; 1467 if (register_blkdev(LOOP_MAJOR, "loop"))
1468 return -EIO;
1469 blk_register_region(MKDEV(LOOP_MAJOR, 0), 1UL << MINORBITS,
1470 THIS_MODULE, loop_probe, NULL, NULL);
1471
1472 if (max_loop) {
1473 printk(KERN_INFO "loop: the max_loop option is obsolete "
1474 "and will be removed in March 2008\n");
1475 1475
1476 for (i = 0; i < max_loop; i++) {
1477 del_gendisk(disks[i]);
1478 blk_cleanup_queue(loop_dev[i].lo_queue);
1479 put_disk(disks[i]);
1480 } 1476 }
1477 printk(KERN_INFO "loop: module loaded\n");
1478 return 0;
1479}
1480
1481static void __exit loop_exit(void)
1482{
1483 struct loop_device *lo, *next;
1484
1485 list_for_each_entry_safe(lo, next, &loop_devices, lo_list)
1486 loop_del_one(lo);
1487
1488 blk_unregister_region(MKDEV(LOOP_MAJOR, 0), 1UL << MINORBITS);
1481 if (unregister_blkdev(LOOP_MAJOR, "loop")) 1489 if (unregister_blkdev(LOOP_MAJOR, "loop"))
1482 printk(KERN_WARNING "loop: cannot unregister blkdev\n"); 1490 printk(KERN_WARNING "loop: cannot unregister blkdev\n");
1483
1484 kfree(disks);
1485 kfree(loop_dev);
1486} 1491}
1487 1492
1488module_init(loop_init); 1493module_init(loop_init);
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 090796bef78f..069ae39a9cd9 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -366,20 +366,25 @@ static struct disk_attribute pid_attr = {
366 .show = pid_show, 366 .show = pid_show,
367}; 367};
368 368
369static void nbd_do_it(struct nbd_device *lo) 369static int nbd_do_it(struct nbd_device *lo)
370{ 370{
371 struct request *req; 371 struct request *req;
372 int ret;
372 373
373 BUG_ON(lo->magic != LO_MAGIC); 374 BUG_ON(lo->magic != LO_MAGIC);
374 375
375 lo->pid = current->pid; 376 lo->pid = current->pid;
376 sysfs_create_file(&lo->disk->kobj, &pid_attr.attr); 377 ret = sysfs_create_file(&lo->disk->kobj, &pid_attr.attr);
378 if (ret) {
379 printk(KERN_ERR "nbd: sysfs_create_file failed!");
380 return ret;
381 }
377 382
378 while ((req = nbd_read_stat(lo)) != NULL) 383 while ((req = nbd_read_stat(lo)) != NULL)
379 nbd_end_request(req); 384 nbd_end_request(req);
380 385
381 sysfs_remove_file(&lo->disk->kobj, &pid_attr.attr); 386 sysfs_remove_file(&lo->disk->kobj, &pid_attr.attr);
382 return; 387 return 0;
383} 388}
384 389
385static void nbd_clear_que(struct nbd_device *lo) 390static void nbd_clear_que(struct nbd_device *lo)
@@ -569,7 +574,9 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
569 case NBD_DO_IT: 574 case NBD_DO_IT:
570 if (!lo->file) 575 if (!lo->file)
571 return -EINVAL; 576 return -EINVAL;
572 nbd_do_it(lo); 577 error = nbd_do_it(lo);
578 if (error)
579 return error;
573 /* on return tidy up in case we have a signal */ 580 /* on return tidy up in case we have a signal */
574 /* Forcibly shutdown the socket causing all listeners 581 /* Forcibly shutdown the socket causing all listeners
575 * to error 582 * to error
diff --git a/drivers/block/rd.c b/drivers/block/rd.c
index 43d4ebcb3b44..a1512da32410 100644
--- a/drivers/block/rd.c
+++ b/drivers/block/rd.c
@@ -151,7 +151,7 @@ static int ramdisk_commit_write(struct file *file, struct page *page,
151} 151}
152 152
153/* 153/*
154 * ->writepage to the the blockdev's mapping has to redirty the page so that the 154 * ->writepage to the blockdev's mapping has to redirty the page so that the
155 * VM doesn't go and steal it. We return AOP_WRITEPAGE_ACTIVATE so that the VM 155 * VM doesn't go and steal it. We return AOP_WRITEPAGE_ACTIVATE so that the VM
156 * won't try to (pointlessly) write the page again for a while. 156 * won't try to (pointlessly) write the page again for a while.
157 * 157 *
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 5872036e8ae6..6f5d6203d725 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -44,7 +44,6 @@
44#include <linux/module.h> 44#include <linux/module.h>
45#include <linux/init.h> 45#include <linux/init.h>
46#include <linux/interrupt.h> 46#include <linux/interrupt.h>
47#include <linux/smp_lock.h>
48#include <linux/timer.h> 47#include <linux/timer.h>
49#include <linux/pci.h> 48#include <linux/pci.h>
50#include <linux/slab.h> 49#include <linux/slab.h>
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 0f4203b499af..6055b9c0ac0f 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -307,7 +307,9 @@ static void hci_uart_tty_close(struct tty_struct *tty)
307 307
308 if (hu) { 308 if (hu) {
309 struct hci_dev *hdev = hu->hdev; 309 struct hci_dev *hdev = hu->hdev;
310 hci_uart_close(hdev); 310
311 if (hdev)
312 hci_uart_close(hdev);
311 313
312 if (test_and_clear_bit(HCI_UART_PROTO_SET, &hu->flags)) { 314 if (test_and_clear_bit(HCI_UART_PROTO_SET, &hu->flags)) {
313 hu->proto->close(hu); 315 hu->proto->close(hu);
@@ -473,12 +475,18 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
473 tty->low_latency = 1; 475 tty->low_latency = 1;
474 } else 476 } else
475 return -EBUSY; 477 return -EBUSY;
478 break;
476 479
477 case HCIUARTGETPROTO: 480 case HCIUARTGETPROTO:
478 if (test_bit(HCI_UART_PROTO_SET, &hu->flags)) 481 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
479 return hu->proto->id; 482 return hu->proto->id;
480 return -EUNATCH; 483 return -EUNATCH;
481 484
485 case HCIUARTGETDEVICE:
486 if (test_bit(HCI_UART_PROTO_SET, &hu->flags))
487 return hu->hdev->id;
488 return -EUNATCH;
489
482 default: 490 default:
483 err = n_tty_ioctl(tty, file, cmd, arg); 491 err = n_tty_ioctl(tty, file, cmd, arg);
484 break; 492 break;
diff --git a/drivers/bluetooth/hci_uart.h b/drivers/bluetooth/hci_uart.h
index b250e6789dee..1097ce72393f 100644
--- a/drivers/bluetooth/hci_uart.h
+++ b/drivers/bluetooth/hci_uart.h
@@ -28,8 +28,9 @@
28#endif 28#endif
29 29
30/* Ioctls */ 30/* Ioctls */
31#define HCIUARTSETPROTO _IOW('U', 200, int) 31#define HCIUARTSETPROTO _IOW('U', 200, int)
32#define HCIUARTGETPROTO _IOR('U', 201, int) 32#define HCIUARTGETPROTO _IOR('U', 201, int)
33#define HCIUARTGETDEVICE _IOR('U', 202, int)
33 34
34/* UART protocols */ 35/* UART protocols */
35#define HCI_UART_MAX_PROTO 4 36#define HCI_UART_MAX_PROTO 4
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index a26d91743b24..ef683ebd367c 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -6,6 +6,7 @@ menu "Character devices"
6 6
7config VT 7config VT
8 bool "Virtual terminal" if EMBEDDED 8 bool "Virtual terminal" if EMBEDDED
9 depends on !S390
9 select INPUT 10 select INPUT
10 default y if !VIOCONS 11 default y if !VIOCONS
11 ---help--- 12 ---help---
@@ -81,6 +82,7 @@ config VT_HW_CONSOLE_BINDING
81 82
82config SERIAL_NONSTANDARD 83config SERIAL_NONSTANDARD
83 bool "Non-standard serial port support" 84 bool "Non-standard serial port support"
85 depends on HAS_IOMEM
84 ---help--- 86 ---help---
85 Say Y here if you have any non-standard serial boards -- boards 87 Say Y here if you have any non-standard serial boards -- boards
86 which aren't supported using the standard "dumb" serial driver. 88 which aren't supported using the standard "dumb" serial driver.
@@ -127,7 +129,7 @@ config ROCKETPORT
127 129
128config CYCLADES 130config CYCLADES
129 tristate "Cyclades async mux support" 131 tristate "Cyclades async mux support"
130 depends on SERIAL_NONSTANDARD 132 depends on SERIAL_NONSTANDARD && (PCI || ISA)
131 ---help--- 133 ---help---
132 This driver supports Cyclades Z and Y multiserial boards. 134 This driver supports Cyclades Z and Y multiserial boards.
133 You would need something like this to connect more than two modems to 135 You would need something like this to connect more than two modems to
@@ -631,7 +633,8 @@ config HVC_CONSOLE
631 633
632config HVC_ISERIES 634config HVC_ISERIES
633 bool "iSeries Hypervisor Virtual Console support" 635 bool "iSeries Hypervisor Virtual Console support"
634 depends on PPC_ISERIES && !VIOCONS 636 depends on PPC_ISERIES
637 default y
635 select HVC_DRIVER 638 select HVC_DRIVER
636 help 639 help
637 iSeries machines support a hypervisor virtual console. 640 iSeries machines support a hypervisor virtual console.
@@ -764,7 +767,7 @@ config NVRAM
764 767
765config RTC 768config RTC
766 tristate "Enhanced Real Time Clock Support" 769 tristate "Enhanced Real Time Clock Support"
767 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV && !ARM && !SUPERH 770 depends on !PPC && !PARISC && !IA64 && !M68K && (!SPARC || PCI) && !FRV && !ARM && !SUPERH && !S390
768 ---help--- 771 ---help---
769 If you say Y here and create a character special file /dev/rtc with 772 If you say Y here and create a character special file /dev/rtc with
770 major number 10 and minor number 135 using mknod ("man mknod"), you 773 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -812,7 +815,7 @@ config SGI_IP27_RTC
812 815
813config GEN_RTC 816config GEN_RTC
814 tristate "Generic /dev/rtc emulation" 817 tristate "Generic /dev/rtc emulation"
815 depends on RTC!=y && !IA64 && !ARM && !M32R && !SPARC && !FRV 818 depends on RTC!=y && !IA64 && !ARM && !M32R && !SPARC && !FRV && !S390 && !SUPERH
816 ---help--- 819 ---help---
817 If you say Y here and create a character special file /dev/rtc with 820 If you say Y here and create a character special file /dev/rtc with
818 major number 10 and minor number 135 using mknod ("man mknod"), you 821 major number 10 and minor number 135 using mknod ("man mknod"), you
@@ -857,6 +860,7 @@ config COBALT_LCD
857 860
858config DTLK 861config DTLK
859 tristate "Double Talk PC internal speech card support" 862 tristate "Double Talk PC internal speech card support"
863 depends on ISA
860 help 864 help
861 This driver is for the DoubleTalk PC, a speech synthesizer 865 This driver is for the DoubleTalk PC, a speech synthesizer
862 manufactured by RC Systems (<http://www.rcsys.com/>). It is also 866 manufactured by RC Systems (<http://www.rcsys.com/>). It is also
@@ -1042,7 +1046,7 @@ config HPET_MMAP
1042 1046
1043config HANGCHECK_TIMER 1047config HANGCHECK_TIMER
1044 tristate "Hangcheck timer" 1048 tristate "Hangcheck timer"
1045 depends on X86 || IA64 || PPC64 1049 depends on X86 || IA64 || PPC64 || S390
1046 help 1050 help
1047 The hangcheck-timer module detects when the system has gone 1051 The hangcheck-timer module detects when the system has gone
1048 out to lunch past a certain margin. It can reboot the system 1052 out to lunch past a certain margin. It can reboot the system
@@ -1071,5 +1075,13 @@ config TELCLOCK
1071 /sys/devices/platform/telco_clock, with a number of files for 1075 /sys/devices/platform/telco_clock, with a number of files for
1072 controlling the behavior of this hardware. 1076 controlling the behavior of this hardware.
1073 1077
1078config DEVPORT
1079 bool
1080 depends on !M68K
1081 depends on ISA || PCI
1082 default y
1083
1084source "drivers/s390/char/Kconfig"
1085
1074endmenu 1086endmenu
1075 1087
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index c9f0f250d78f..801abdd29066 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -268,7 +268,7 @@ static int __devinit aperture_valid(u64 aper, u32 size)
268 printk(KERN_ERR PFX "Aperture too small (%d MB)\n", size>>20); 268 printk(KERN_ERR PFX "Aperture too small (%d MB)\n", size>>20);
269 return 0; 269 return 0;
270 } 270 }
271 if (aper + size > 0xffffffff) { 271 if ((u64)aper + size > 0x100000000ULL) {
272 printk(KERN_ERR PFX "Aperture out of bounds\n"); 272 printk(KERN_ERR PFX "Aperture out of bounds\n");
273 return 0; 273 return 0;
274 } 274 }
diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
index 679d7f972439..c7ed617aa7ff 100644
--- a/drivers/char/agp/frontend.c
+++ b/drivers/char/agp/frontend.c
@@ -37,6 +37,7 @@
37#include <linux/agpgart.h> 37#include <linux/agpgart.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/mm.h> 39#include <linux/mm.h>
40#include <linux/sched.h>
40#include <asm/uaccess.h> 41#include <asm/uaccess.h>
41#include <asm/pgtable.h> 42#include <asm/pgtable.h>
42#include "agp.h" 43#include "agp.h"
diff --git a/drivers/char/agp/generic.c b/drivers/char/agp/generic.c
index 45aeb917ec63..d535c406b319 100644
--- a/drivers/char/agp/generic.c
+++ b/drivers/char/agp/generic.c
@@ -37,6 +37,7 @@
37#include <linux/vmalloc.h> 37#include <linux/vmalloc.h>
38#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
39#include <linux/mm.h> 39#include <linux/mm.h>
40#include <linux/sched.h>
40#include <asm/io.h> 41#include <asm/io.h>
41#include <asm/cacheflush.h> 42#include <asm/cacheflush.h>
42#include <asm/pgtable.h> 43#include <asm/pgtable.h>
diff --git a/drivers/char/agp/uninorth-agp.c b/drivers/char/agp/uninorth-agp.c
index 91b062126a68..42c0a600b1ac 100644
--- a/drivers/char/agp/uninorth-agp.c
+++ b/drivers/char/agp/uninorth-agp.c
@@ -613,7 +613,7 @@ static int __devinit agp_uninorth_probe(struct pci_dev *pdev,
613 uninorth_node = of_find_node_by_name(NULL, "u3"); 613 uninorth_node = of_find_node_by_name(NULL, "u3");
614 } 614 }
615 if (uninorth_node) { 615 if (uninorth_node) {
616 const int *revprop = get_property(uninorth_node, 616 const int *revprop = of_get_property(uninorth_node,
617 "device-rev", NULL); 617 "device-rev", NULL);
618 if (revprop != NULL) 618 if (revprop != NULL)
619 uninorth_rev = *revprop & 0x3f; 619 uninorth_rev = *revprop & 0x3f;
diff --git a/drivers/char/agp/via-agp.c b/drivers/char/agp/via-agp.c
index a2bb4eccaab4..9aaf401a8975 100644
--- a/drivers/char/agp/via-agp.c
+++ b/drivers/char/agp/via-agp.c
@@ -384,9 +384,9 @@ static struct agp_device_ids via_agp_device_ids[] __devinitdata =
384 .device_id = PCI_DEVICE_ID_VIA_P4M800CE, 384 .device_id = PCI_DEVICE_ID_VIA_P4M800CE,
385 .chipset_name = "VT3314", 385 .chipset_name = "VT3314",
386 }, 386 },
387 /* CX700 */ 387 /* VT3324 / CX700 */
388 { 388 {
389 .device_id = PCI_DEVICE_ID_VIA_CX700, 389 .device_id = PCI_DEVICE_ID_VIA_VT3324,
390 .chipset_name = "CX700", 390 .chipset_name = "CX700",
391 }, 391 },
392 /* VT3336 */ 392 /* VT3336 */
@@ -540,7 +540,7 @@ static const struct pci_device_id agp_via_pci_table[] = {
540 ID(PCI_DEVICE_ID_VIA_83_87XX_1), 540 ID(PCI_DEVICE_ID_VIA_83_87XX_1),
541 ID(PCI_DEVICE_ID_VIA_3296_0), 541 ID(PCI_DEVICE_ID_VIA_3296_0),
542 ID(PCI_DEVICE_ID_VIA_P4M800CE), 542 ID(PCI_DEVICE_ID_VIA_P4M800CE),
543 ID(PCI_DEVICE_ID_VIA_CX700), 543 ID(PCI_DEVICE_ID_VIA_VT3324),
544 ID(PCI_DEVICE_ID_VIA_VT3336), 544 ID(PCI_DEVICE_ID_VIA_VT3336),
545 ID(PCI_DEVICE_ID_VIA_P4M890), 545 ID(PCI_DEVICE_ID_VIA_P4M890),
546 { } 546 { }
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 0e2b72f2b887..4eaceabd8cea 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -1574,7 +1574,7 @@ static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
1574 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 1574 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1575 break; 1575 break;
1576 } 1576 }
1577 current->state = TASK_RUNNING; 1577 __set_current_state(TASK_RUNNING);
1578#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT 1578#ifdef SERIAL_DEBUG_RS_WAIT_UNTIL_SENT
1579 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies); 1579 printk("lsr = %d (jiff=%lu)...done\n", lsr, jiffies);
1580#endif 1580#endif
@@ -1700,7 +1700,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
1700#endif 1700#endif
1701 schedule(); 1701 schedule();
1702 } 1702 }
1703 current->state = TASK_RUNNING; 1703 __set_current_state(TASK_RUNNING);
1704 remove_wait_queue(&info->open_wait, &wait); 1704 remove_wait_queue(&info->open_wait, &wait);
1705 if (extra_count) 1705 if (extra_count)
1706 state->count++; 1706 state->count++;
diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
index c70d52ace8b2..ed53f541d9e8 100644
--- a/drivers/char/briq_panel.c
+++ b/drivers/char/briq_panel.c
@@ -206,7 +206,7 @@ static int __init briq_panel_init(void)
206 const char *machine; 206 const char *machine;
207 int i; 207 int i;
208 208
209 machine = get_property(root, "model", NULL); 209 machine = of_get_property(root, "model", NULL);
210 if (!machine || strncmp(machine, "TotalImpact,BRIQ-1", 18) != 0) { 210 if (!machine || strncmp(machine, "TotalImpact,BRIQ-1", 18) != 0) {
211 of_node_put(root); 211 of_node_put(root);
212 return -ENODEV; 212 return -ENODEV;
diff --git a/drivers/char/consolemap.c b/drivers/char/consolemap.c
index b99b7561260d..fd40b959afdd 100644
--- a/drivers/char/consolemap.c
+++ b/drivers/char/consolemap.c
@@ -626,10 +626,10 @@ conv_uni_to_pc(struct vc_data *conp, long ucs)
626 626
627 /* Only 16-bit codes supported at this time */ 627 /* Only 16-bit codes supported at this time */
628 if (ucs > 0xffff) 628 if (ucs > 0xffff)
629 ucs = 0xfffd; /* U+FFFD: REPLACEMENT CHARACTER */ 629 return -4; /* Not found */
630 else if (ucs < 0x20 || ucs >= 0xfffe) 630 else if (ucs < 0x20)
631 return -1; /* Not a printable character */ 631 return -1; /* Not a printable character */
632 else if (ucs == 0xfeff || (ucs >= 0x200a && ucs <= 0x200f)) 632 else if (ucs == 0xfeff || (ucs >= 0x200b && ucs <= 0x200f))
633 return -2; /* Zero-width space */ 633 return -2; /* Zero-width space */
634 /* 634 /*
635 * UNI_DIRECT_BASE indicates the start of the region in the User Zone 635 * UNI_DIRECT_BASE indicates the start of the region in the User Zone
diff --git a/drivers/char/cs5535_gpio.c b/drivers/char/cs5535_gpio.c
index c02d9e99e050..fe6d2407baed 100644
--- a/drivers/char/cs5535_gpio.c
+++ b/drivers/char/cs5535_gpio.c
@@ -44,6 +44,7 @@ static struct pci_device_id divil_pci[] = {
44 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) }, 44 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
45 { } /* NULL entry */ 45 { } /* NULL entry */
46}; 46};
47MODULE_DEVICE_TABLE(pci, divil_pci);
47 48
48static struct cdev cs5535_gpio_cdev; 49static struct cdev cs5535_gpio_cdev;
49 50
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 16dc5d1d3cb4..c72ee97d3892 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -10,15 +10,14 @@
10 * 10 *
11 * Initially written by Randolph Bentson <bentson@grieg.seaslug.org>. 11 * Initially written by Randolph Bentson <bentson@grieg.seaslug.org>.
12 * Modified and maintained by Marcio Saito <marcio@cyclades.com>. 12 * Modified and maintained by Marcio Saito <marcio@cyclades.com>.
13 * Currently maintained by Cyclades team <async@cyclades.com>.
14 * 13 *
15 * For Technical support and installation problems, please send e-mail 14 * Copyright (C) 2007 Jiri Slaby <jirislaby@gmail.com>
16 * to support@cyclades.com.
17 * 15 *
18 * Much of the design and some of the code came from serial.c 16 * Much of the design and some of the code came from serial.c
19 * which was copyright (C) 1991, 1992 Linus Torvalds. It was 17 * which was copyright (C) 1991, 1992 Linus Torvalds. It was
20 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92, 18 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
21 * and then fixed as suggested by Michael K. Johnson 12/12/92. 19 * and then fixed as suggested by Michael K. Johnson 12/12/92.
20 * Converted to pci probing and cleaned up by Jiri Slaby.
22 * 21 *
23 * This version supports shared IRQ's (only for PCI boards). 22 * This version supports shared IRQ's (only for PCI boards).
24 * 23 *
@@ -591,7 +590,7 @@
591 * 590 *
592 */ 591 */
593 592
594#define CY_VERSION "2.4" 593#define CY_VERSION "2.5"
595 594
596/* If you need to install more boards than NR_CARDS, change the constant 595/* If you need to install more boards than NR_CARDS, change the constant
597 in the definition below. No other change is necessary to support up to 596 in the definition below. No other change is necessary to support up to
@@ -624,12 +623,6 @@
624#undef CY_ENABLE_MONITORING 623#undef CY_ENABLE_MONITORING
625#undef CY_PCI_DEBUG 624#undef CY_PCI_DEBUG
626 625
627#if 0
628#define PAUSE __asm__("nop")
629#else
630#define PAUSE do {} while (0)
631#endif
632
633/* 626/*
634 * Include section 627 * Include section
635 */ 628 */
@@ -659,17 +652,6 @@
659#include <asm/irq.h> 652#include <asm/irq.h>
660#include <asm/uaccess.h> 653#include <asm/uaccess.h>
661 654
662#define CY_LOCK(info,flags) \
663 do { \
664 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \
665 } while (0)
666
667#define CY_UNLOCK(info,flags) \
668 do { \
669 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \
670 } while (0)
671
672#include <linux/types.h>
673#include <linux/kernel.h> 655#include <linux/kernel.h>
674#include <linux/pci.h> 656#include <linux/pci.h>
675 657
@@ -682,13 +664,13 @@ static void cy_send_xchar(struct tty_struct *tty, char ch);
682#define IS_CYC_Z(card) ((card).num_chips == -1) 664#define IS_CYC_Z(card) ((card).num_chips == -1)
683 665
684#define Z_FPGA_CHECK(card) \ 666#define Z_FPGA_CHECK(card) \
685 ((cy_readl(&((struct RUNTIME_9060 __iomem *) \ 667 ((readl(&((struct RUNTIME_9060 __iomem *) \
686 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0) 668 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
687 669
688#define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \ 670#define ISZLOADED(card) (((ZO_V1==readl(&((struct RUNTIME_9060 __iomem *) \
689 ((card).ctl_addr))->mail_box_0)) || \ 671 ((card).ctl_addr))->mail_box_0)) || \
690 Z_FPGA_CHECK(card)) && \ 672 Z_FPGA_CHECK(card)) && \
691 (ZFIRM_ID==cy_readl(&((struct FIRM_ID __iomem *) \ 673 (ZFIRM_ID==readl(&((struct FIRM_ID __iomem *) \
692 ((card).base_addr+ID_ADDRESS))->signature))) 674 ((card).base_addr+ID_ADDRESS))->signature)))
693 675
694#ifndef SERIAL_XMIT_SIZE 676#ifndef SERIAL_XMIT_SIZE
@@ -725,8 +707,8 @@ static unsigned int cy_isa_addresses[] = {
725#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses) 707#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
726 708
727#ifdef MODULE 709#ifdef MODULE
728static long maddr[NR_CARDS] = { 0, }; 710static long maddr[NR_CARDS];
729static int irq[NR_CARDS] = { 0, }; 711static int irq[NR_CARDS];
730 712
731module_param_array(maddr, long, NULL, 0); 713module_param_array(maddr, long, NULL, 0);
732module_param_array(irq, int, NULL, 0); 714module_param_array(irq, int, NULL, 0);
@@ -739,11 +721,6 @@ module_param_array(irq, int, NULL, 0);
739*/ 721*/
740static struct cyclades_card cy_card[NR_CARDS]; 722static struct cyclades_card cy_card[NR_CARDS];
741 723
742/* This is the per-channel data structure containing pointers, flags
743 and variables for the port. This driver supports a maximum of NR_PORTS.
744*/
745static struct cyclades_port cy_port[NR_PORTS];
746
747static int cy_next_channel; /* next minor available */ 724static int cy_next_channel; /* next minor available */
748 725
749/* 726/*
@@ -825,9 +802,6 @@ static int cy_chip_offset[] = { 0x0000,
825 802
826/* PCI related definitions */ 803/* PCI related definitions */
827 804
828static unsigned short cy_pci_nboard;
829static unsigned short cy_isa_nboard;
830static unsigned short cy_nboard;
831#ifdef CONFIG_PCI 805#ifdef CONFIG_PCI
832static struct pci_device_id cy_pci_dev_id[] __devinitdata = { 806static struct pci_device_id cy_pci_dev_id[] __devinitdata = {
833 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Lo) }, /* PCI < 1Mb */ 807 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Lo) }, /* PCI < 1Mb */
@@ -845,7 +819,7 @@ MODULE_DEVICE_TABLE(pci, cy_pci_dev_id);
845 819
846static void cy_start(struct tty_struct *); 820static void cy_start(struct tty_struct *);
847static void set_line_char(struct cyclades_port *); 821static void set_line_char(struct cyclades_port *);
848static int cyz_issue_cmd(struct cyclades_card *, uclong, ucchar, uclong); 822static int cyz_issue_cmd(struct cyclades_card *, __u32, __u8, __u32);
849#ifdef CONFIG_ISA 823#ifdef CONFIG_ISA
850static unsigned detect_isa_irq(void __iomem *); 824static unsigned detect_isa_irq(void __iomem *);
851#endif /* CONFIG_ISA */ 825#endif /* CONFIG_ISA */
@@ -858,7 +832,6 @@ static void cyz_poll(unsigned long);
858/* The Cyclades-Z polling cycle is defined by this variable */ 832/* The Cyclades-Z polling cycle is defined by this variable */
859static long cyz_polling_cycle = CZ_DEF_POLL; 833static long cyz_polling_cycle = CZ_DEF_POLL;
860 834
861static int cyz_timeron = 0;
862static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0); 835static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0);
863 836
864#else /* CONFIG_CYZ_INTR */ 837#else /* CONFIG_CYZ_INTR */
@@ -871,21 +844,14 @@ static inline int serial_paranoia_check(struct cyclades_port *info,
871{ 844{
872#ifdef SERIAL_PARANOIA_CHECK 845#ifdef SERIAL_PARANOIA_CHECK
873 if (!info) { 846 if (!info) {
874 printk("cyc Warning: null cyclades_port for (%s) in %s\n", 847 printk(KERN_WARNING "cyc Warning: null cyclades_port for (%s) "
875 name, routine); 848 "in %s\n", name, routine);
876 return 1;
877 }
878
879 if ((long)info < (long)(&cy_port[0]) ||
880 (long)(&cy_port[NR_PORTS]) < (long)info) {
881 printk("cyc Warning: cyclades_port out of range for (%s) in "
882 "%s\n", name, routine);
883 return 1; 849 return 1;
884 } 850 }
885 851
886 if (info->magic != CYCLADES_MAGIC) { 852 if (info->magic != CYCLADES_MAGIC) {
887 printk("cyc Warning: bad magic number for serial struct (%s) " 853 printk(KERN_WARNING "cyc Warning: bad magic number for serial "
888 "in %s\n", name, routine); 854 "struct (%s) in %s\n", name, routine);
889 return 1; 855 return 1;
890 } 856 }
891#endif 857#endif
@@ -943,22 +909,16 @@ do_softint(struct work_struct *work)
943 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) 909 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event))
944 wake_up_interruptible(&info->open_wait); 910 wake_up_interruptible(&info->open_wait);
945#ifdef CONFIG_CYZ_INTR 911#ifdef CONFIG_CYZ_INTR
946 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event)) { 912 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event) &&
947 if (cyz_rx_full_timer[info->line].function == NULL) { 913 !timer_pending(&cyz_rx_full_timer[info->line]))
948 cyz_rx_full_timer[info->line].expires = jiffies + 1; 914 mod_timer(&cyz_rx_full_timer[info->line], jiffies + 1);
949 cyz_rx_full_timer[info->line].function = cyz_rx_restart;
950 cyz_rx_full_timer[info->line].data =
951 (unsigned long)info;
952 add_timer(&cyz_rx_full_timer[info->line]);
953 }
954 }
955#endif 915#endif
956 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event)) 916 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event))
957 wake_up_interruptible(&info->delta_msr_wait); 917 wake_up_interruptible(&info->delta_msr_wait);
958 tty_wakeup(tty); 918 tty_wakeup(tty);
959#ifdef Z_WAKE 919#ifdef Z_WAKE
960 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event)) 920 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event))
961 wake_up_interruptible(&info->shutdown_wait); 921 complete(&info->shutdown_wait);
962#endif 922#endif
963} /* do_softint */ 923} /* do_softint */
964 924
@@ -975,11 +935,11 @@ do_softint(struct work_struct *work)
975 */ 935 */
976static int cyy_issue_cmd(void __iomem * base_addr, u_char cmd, int index) 936static int cyy_issue_cmd(void __iomem * base_addr, u_char cmd, int index)
977{ 937{
978 volatile int i; 938 unsigned int i;
979 939
980 /* Check to see that the previous command has completed */ 940 /* Check to see that the previous command has completed */
981 for (i = 0; i < 100; i++) { 941 for (i = 0; i < 100; i++) {
982 if (cy_readb(base_addr + (CyCCR << index)) == 0) { 942 if (readb(base_addr + (CyCCR << index)) == 0) {
983 break; 943 break;
984 } 944 }
985 udelay(10L); 945 udelay(10L);
@@ -1022,7 +982,7 @@ static unsigned detect_isa_irq(void __iomem * address)
1022 982
1023 cy_writeb(address + (CyCAR << index), 0); 983 cy_writeb(address + (CyCAR << index), 0);
1024 cy_writeb(address + (CySRER << index), 984 cy_writeb(address + (CySRER << index),
1025 cy_readb(address + (CySRER << index)) | CyTxRdy); 985 readb(address + (CySRER << index)) | CyTxRdy);
1026 local_irq_restore(flags); 986 local_irq_restore(flags);
1027 987
1028 /* Wait ... */ 988 /* Wait ... */
@@ -1032,11 +992,11 @@ static unsigned detect_isa_irq(void __iomem * address)
1032 irq = probe_irq_off(irqs); 992 irq = probe_irq_off(irqs);
1033 993
1034 /* Clean up */ 994 /* Clean up */
1035 save_xir = (u_char) cy_readb(address + (CyTIR << index)); 995 save_xir = (u_char) readb(address + (CyTIR << index));
1036 save_car = cy_readb(address + (CyCAR << index)); 996 save_car = readb(address + (CyCAR << index));
1037 cy_writeb(address + (CyCAR << index), (save_xir & 0x3)); 997 cy_writeb(address + (CyCAR << index), (save_xir & 0x3));
1038 cy_writeb(address + (CySRER << index), 998 cy_writeb(address + (CySRER << index),
1039 cy_readb(address + (CySRER << index)) & ~CyTxRdy); 999 readb(address + (CySRER << index)) & ~CyTxRdy);
1040 cy_writeb(address + (CyTIR << index), (save_xir & 0x3f)); 1000 cy_writeb(address + (CyTIR << index), (save_xir & 0x3f));
1041 cy_writeb(address + (CyCAR << index), (save_car)); 1001 cy_writeb(address + (CyCAR << index), (save_car));
1042 cy_writeb(address + (Cy_ClrIntr << index), 0); 1002 cy_writeb(address + (Cy_ClrIntr << index), 0);
@@ -1051,45 +1011,43 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1051{ 1011{
1052 struct cyclades_port *info; 1012 struct cyclades_port *info;
1053 struct tty_struct *tty; 1013 struct tty_struct *tty;
1054 volatile int char_count; 1014 int char_count;
1055 int i, j, len, mdm_change, mdm_status, outch; 1015 int j, len, mdm_change, mdm_status, outch;
1056 int save_xir, channel, save_car; 1016 int save_xir, channel, save_car;
1057 char data; 1017 char data;
1058 1018
1059 if (status & CySRReceive) { /* reception interrupt */ 1019 if (status & CySRReceive) { /* reception interrupt */
1060#ifdef CY_DEBUG_INTERRUPTS 1020#ifdef CY_DEBUG_INTERRUPTS
1061 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip); 1021 printk(KERN_DEBUG "cyy_interrupt: rcvd intr, chip %d\n", chip);
1062#endif 1022#endif
1063 /* determine the channel & change to that context */ 1023 /* determine the channel & change to that context */
1064 spin_lock(&cinfo->card_lock); 1024 spin_lock(&cinfo->card_lock);
1065 save_xir = (u_char) cy_readb(base_addr + (CyRIR << index)); 1025 save_xir = (u_char) readb(base_addr + (CyRIR << index));
1066 channel = (u_short) (save_xir & CyIRChannel); 1026 channel = (u_short) (save_xir & CyIRChannel);
1067 i = channel + chip * 4 + cinfo->first_line; 1027 info = &cinfo->ports[channel + chip * 4];
1068 info = &cy_port[i]; 1028 save_car = readb(base_addr + (CyCAR << index));
1069 info->last_active = jiffies;
1070 save_car = cy_readb(base_addr + (CyCAR << index));
1071 cy_writeb(base_addr + (CyCAR << index), save_xir); 1029 cy_writeb(base_addr + (CyCAR << index), save_xir);
1072 1030
1073 /* if there is nowhere to put the data, discard it */ 1031 /* if there is nowhere to put the data, discard it */
1074 if (info->tty == 0) { 1032 if (info->tty == NULL) {
1075 j = (cy_readb(base_addr + (CyRIVR << index)) & 1033 j = (readb(base_addr + (CyRIVR << index)) &
1076 CyIVRMask); 1034 CyIVRMask);
1077 if (j == CyIVRRxEx) { /* exception */ 1035 if (j == CyIVRRxEx) { /* exception */
1078 data = cy_readb(base_addr + (CyRDSR << index)); 1036 data = readb(base_addr + (CyRDSR << index));
1079 } else { /* normal character reception */ 1037 } else { /* normal character reception */
1080 char_count = cy_readb(base_addr + 1038 char_count = readb(base_addr +
1081 (CyRDCR << index)); 1039 (CyRDCR << index));
1082 while (char_count--) { 1040 while (char_count--) {
1083 data = cy_readb(base_addr + 1041 data = readb(base_addr +
1084 (CyRDSR << index)); 1042 (CyRDSR << index));
1085 } 1043 }
1086 } 1044 }
1087 } else { /* there is an open port for this data */ 1045 } else { /* there is an open port for this data */
1088 tty = info->tty; 1046 tty = info->tty;
1089 j = (cy_readb(base_addr + (CyRIVR << index)) & 1047 j = (readb(base_addr + (CyRIVR << index)) &
1090 CyIVRMask); 1048 CyIVRMask);
1091 if (j == CyIVRRxEx) { /* exception */ 1049 if (j == CyIVRRxEx) { /* exception */
1092 data = cy_readb(base_addr + (CyRDSR << index)); 1050 data = readb(base_addr + (CyRDSR << index));
1093 1051
1094 /* For statistics only */ 1052 /* For statistics only */
1095 if (data & CyBREAK) 1053 if (data & CyBREAK)
@@ -1110,7 +1068,7 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1110 if (data & CyBREAK) { 1068 if (data & CyBREAK) {
1111 tty_insert_flip_char( 1069 tty_insert_flip_char(
1112 tty, 1070 tty,
1113 cy_readb( 1071 readb(
1114 base_addr + 1072 base_addr +
1115 (CyRDSR << 1073 (CyRDSR <<
1116 index)), 1074 index)),
@@ -1123,7 +1081,7 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1123 } else if (data & CyFRAME) { 1081 } else if (data & CyFRAME) {
1124 tty_insert_flip_char( 1082 tty_insert_flip_char(
1125 tty, 1083 tty,
1126 cy_readb( 1084 readb(
1127 base_addr + 1085 base_addr +
1128 (CyRDSR << 1086 (CyRDSR <<
1129 index)), 1087 index)),
@@ -1135,7 +1093,7 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1135 /* Pieces of seven... */ 1093 /* Pieces of seven... */
1136 tty_insert_flip_char( 1094 tty_insert_flip_char(
1137 tty, 1095 tty,
1138 cy_readb( 1096 readb(
1139 base_addr + 1097 base_addr +
1140 (CyRDSR << 1098 (CyRDSR <<
1141 index)), 1099 index)),
@@ -1154,7 +1112,7 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1154 */ 1112 */
1155 tty_insert_flip_char( 1113 tty_insert_flip_char(
1156 tty, 1114 tty,
1157 cy_readb( 1115 readb(
1158 base_addr + 1116 base_addr +
1159 (CyRDSR << 1117 (CyRDSR <<
1160 index)), 1118 index)),
@@ -1186,7 +1144,7 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1186 } 1144 }
1187 } else { /* normal character reception */ 1145 } else { /* normal character reception */
1188 /* load # chars available from the chip */ 1146 /* load # chars available from the chip */
1189 char_count = cy_readb(base_addr + 1147 char_count = readb(base_addr +
1190 (CyRDCR << index)); 1148 (CyRDCR << index));
1191 1149
1192#ifdef CY_ENABLE_MONITORING 1150#ifdef CY_ENABLE_MONITORING
@@ -1198,7 +1156,7 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1198#endif 1156#endif
1199 len = tty_buffer_request_room(tty, char_count); 1157 len = tty_buffer_request_room(tty, char_count);
1200 while (len--) { 1158 while (len--) {
1201 data = cy_readb(base_addr + 1159 data = readb(base_addr +
1202 (CyRDSR << index)); 1160 (CyRDSR << index));
1203 tty_insert_flip_char(tty, data, 1161 tty_insert_flip_char(tty, data,
1204 TTY_NORMAL); 1162 TTY_NORMAL);
@@ -1223,29 +1181,27 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1223 is empty, we know we can always stuff a dozen 1181 is empty, we know we can always stuff a dozen
1224 characters. */ 1182 characters. */
1225#ifdef CY_DEBUG_INTERRUPTS 1183#ifdef CY_DEBUG_INTERRUPTS
1226 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip); 1184 printk(KERN_DEBUG "cyy_interrupt: xmit intr, chip %d\n", chip);
1227#endif 1185#endif
1228 1186
1229 /* determine the channel & change to that context */ 1187 /* determine the channel & change to that context */
1230 spin_lock(&cinfo->card_lock); 1188 spin_lock(&cinfo->card_lock);
1231 save_xir = (u_char) cy_readb(base_addr + (CyTIR << index)); 1189 save_xir = (u_char) readb(base_addr + (CyTIR << index));
1232 channel = (u_short) (save_xir & CyIRChannel); 1190 channel = (u_short) (save_xir & CyIRChannel);
1233 i = channel + chip * 4 + cinfo->first_line; 1191 save_car = readb(base_addr + (CyCAR << index));
1234 save_car = cy_readb(base_addr + (CyCAR << index));
1235 cy_writeb(base_addr + (CyCAR << index), save_xir); 1192 cy_writeb(base_addr + (CyCAR << index), save_xir);
1236 1193
1237 /* validate the port# (as configured and open) */ 1194 /* validate the port# (as configured and open) */
1238 if ((i < 0) || (NR_PORTS <= i)) { 1195 if (channel + chip * 4 >= cinfo->nports) {
1239 cy_writeb(base_addr + (CySRER << index), 1196 cy_writeb(base_addr + (CySRER << index),
1240 cy_readb(base_addr + (CySRER << index)) & 1197 readb(base_addr + (CySRER << index)) &
1241 ~CyTxRdy); 1198 ~CyTxRdy);
1242 goto txend; 1199 goto txend;
1243 } 1200 }
1244 info = &cy_port[i]; 1201 info = &cinfo->ports[channel + chip * 4];
1245 info->last_active = jiffies; 1202 if (info->tty == NULL) {
1246 if (info->tty == 0) {
1247 cy_writeb(base_addr + (CySRER << index), 1203 cy_writeb(base_addr + (CySRER << index),
1248 cy_readb(base_addr + (CySRER << index)) & 1204 readb(base_addr + (CySRER << index)) &
1249 ~CyTxRdy); 1205 ~CyTxRdy);
1250 goto txdone; 1206 goto txdone;
1251 } 1207 }
@@ -1278,29 +1234,29 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1278 1234
1279 while (char_count-- > 0) { 1235 while (char_count-- > 0) {
1280 if (!info->xmit_cnt) { 1236 if (!info->xmit_cnt) {
1281 if (cy_readb(base_addr + (CySRER << index)) & 1237 if (readb(base_addr + (CySRER << index)) &
1282 CyTxMpty) { 1238 CyTxMpty) {
1283 cy_writeb(base_addr + (CySRER << index), 1239 cy_writeb(base_addr + (CySRER << index),
1284 cy_readb(base_addr + 1240 readb(base_addr +
1285 (CySRER << index)) & 1241 (CySRER << index)) &
1286 ~CyTxMpty); 1242 ~CyTxMpty);
1287 } else { 1243 } else {
1288 cy_writeb(base_addr + (CySRER << index), 1244 cy_writeb(base_addr + (CySRER << index),
1289 (cy_readb(base_addr + 1245 (readb(base_addr +
1290 (CySRER << index)) & 1246 (CySRER << index)) &
1291 ~CyTxRdy) | CyTxMpty); 1247 ~CyTxRdy) | CyTxMpty);
1292 } 1248 }
1293 goto txdone; 1249 goto txdone;
1294 } 1250 }
1295 if (info->xmit_buf == 0) { 1251 if (info->xmit_buf == NULL) {
1296 cy_writeb(base_addr + (CySRER << index), 1252 cy_writeb(base_addr + (CySRER << index),
1297 cy_readb(base_addr + (CySRER << index))& 1253 readb(base_addr + (CySRER << index)) &
1298 ~CyTxRdy); 1254 ~CyTxRdy);
1299 goto txdone; 1255 goto txdone;
1300 } 1256 }
1301 if (info->tty->stopped || info->tty->hw_stopped) { 1257 if (info->tty->stopped || info->tty->hw_stopped) {
1302 cy_writeb(base_addr + (CySRER << index), 1258 cy_writeb(base_addr + (CySRER << index),
1303 cy_readb(base_addr + (CySRER << index))& 1259 readb(base_addr + (CySRER << index)) &
1304 ~CyTxRdy); 1260 ~CyTxRdy);
1305 goto txdone; 1261 goto txdone;
1306 } 1262 }
@@ -1333,7 +1289,6 @@ static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1333 0); 1289 0);
1334 info->icount.tx++; 1290 info->icount.tx++;
1335 char_count--; 1291 char_count--;
1336 } else {
1337 } 1292 }
1338 } 1293 }
1339 } 1294 }
@@ -1353,19 +1308,16 @@ txend:
1353 1308
1354 /* determine the channel & change to that context */ 1309 /* determine the channel & change to that context */
1355 spin_lock(&cinfo->card_lock); 1310 spin_lock(&cinfo->card_lock);
1356 save_xir = (u_char) cy_readb(base_addr + (CyMIR << index)); 1311 save_xir = (u_char) readb(base_addr + (CyMIR << index));
1357 channel = (u_short) (save_xir & CyIRChannel); 1312 channel = (u_short) (save_xir & CyIRChannel);
1358 info = &cy_port[channel + chip * 4 + cinfo->first_line]; 1313 info = &cinfo->ports[channel + chip * 4];
1359 info->last_active = jiffies; 1314 save_car = readb(base_addr + (CyCAR << index));
1360 save_car = cy_readb(base_addr + (CyCAR << index));
1361 cy_writeb(base_addr + (CyCAR << index), save_xir); 1315 cy_writeb(base_addr + (CyCAR << index), save_xir);
1362 1316
1363 mdm_change = cy_readb(base_addr + (CyMISR << index)); 1317 mdm_change = readb(base_addr + (CyMISR << index));
1364 mdm_status = cy_readb(base_addr + (CyMSVR1 << index)); 1318 mdm_status = readb(base_addr + (CyMSVR1 << index));
1365 1319
1366 if (info->tty == 0) { /* no place for data, ignore it */ 1320 if (info->tty) {
1367 ;
1368 } else {
1369 if (mdm_change & CyANY_DELTA) { 1321 if (mdm_change & CyANY_DELTA) {
1370 /* For statistics only */ 1322 /* For statistics only */
1371 if (mdm_change & CyDCD) 1323 if (mdm_change & CyDCD)
@@ -1398,7 +1350,7 @@ txend:
1398 info->tty->hw_stopped = 0; 1350 info->tty->hw_stopped = 0;
1399 cy_writeb(base_addr + 1351 cy_writeb(base_addr +
1400 (CySRER << index), 1352 (CySRER << index),
1401 cy_readb(base_addr + 1353 readb(base_addr +
1402 (CySRER << 1354 (CySRER <<
1403 index))| 1355 index))|
1404 CyTxRdy); 1356 CyTxRdy);
@@ -1412,17 +1364,17 @@ txend:
1412 info->tty->hw_stopped = 1; 1364 info->tty->hw_stopped = 1;
1413 cy_writeb(base_addr + 1365 cy_writeb(base_addr +
1414 (CySRER << index), 1366 (CySRER << index),
1415 cy_readb(base_addr + 1367 readb(base_addr +
1416 (CySRER << 1368 (CySRER <<
1417 index)) & 1369 index)) &
1418 ~CyTxRdy); 1370 ~CyTxRdy);
1419 } 1371 }
1420 } 1372 }
1421 } 1373 }
1422 if (mdm_change & CyDSR) { 1374/* if (mdm_change & CyDSR) {
1423 } 1375 }
1424 if (mdm_change & CyRI) { 1376 if (mdm_change & CyRI) {
1425 } 1377 }*/
1426 } 1378 }
1427 /* end of service */ 1379 /* end of service */
1428 cy_writeb(base_addr + (CyMIR << index), (save_xir & 0x3f)); 1380 cy_writeb(base_addr + (CyMIR << index), (save_xir & 0x3f));
@@ -1438,16 +1390,16 @@ txend:
1438static irqreturn_t cyy_interrupt(int irq, void *dev_id) 1390static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1439{ 1391{
1440 int status; 1392 int status;
1441 struct cyclades_card *cinfo; 1393 struct cyclades_card *cinfo = dev_id;
1442 void __iomem *base_addr, *card_base_addr; 1394 void __iomem *base_addr, *card_base_addr;
1443 int chip; 1395 int chip;
1444 int index; 1396 int index;
1445 int too_many; 1397 int too_many;
1446 int had_work; 1398 int had_work;
1447 1399
1448 if ((cinfo = (struct cyclades_card *)dev_id) == 0) { 1400 if (unlikely(cinfo == NULL)) {
1449#ifdef CY_DEBUG_INTERRUPTS 1401#ifdef CY_DEBUG_INTERRUPTS
1450 printk("cyy_interrupt: spurious interrupt %d\n\r", irq); 1402 printk(KERN_DEBUG "cyy_interrupt: spurious interrupt %d\n",irq);
1451#endif 1403#endif
1452 return IRQ_NONE; /* spurious interrupt */ 1404 return IRQ_NONE; /* spurious interrupt */
1453 } 1405 }
@@ -1455,6 +1407,10 @@ static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1455 card_base_addr = cinfo->base_addr; 1407 card_base_addr = cinfo->base_addr;
1456 index = cinfo->bus_index; 1408 index = cinfo->bus_index;
1457 1409
1410 /* card was not initialized yet (e.g. DEBUG_SHIRQ) */
1411 if (unlikely(card_base_addr == NULL))
1412 return IRQ_HANDLED;
1413
1458 /* This loop checks all chips in the card. Make a note whenever 1414 /* This loop checks all chips in the card. Make a note whenever
1459 _any_ chip had some work to do, as this is considered an 1415 _any_ chip had some work to do, as this is considered an
1460 indication that there will be more to do. Only when no chip 1416 indication that there will be more to do. Only when no chip
@@ -1466,7 +1422,7 @@ static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1466 base_addr = cinfo->base_addr + 1422 base_addr = cinfo->base_addr +
1467 (cy_chip_offset[chip] << index); 1423 (cy_chip_offset[chip] << index);
1468 too_many = 0; 1424 too_many = 0;
1469 while ((status = cy_readb(base_addr + 1425 while ((status = readb(base_addr +
1470 (CySVRR << index))) != 0x00) { 1426 (CySVRR << index))) != 0x00) {
1471 had_work++; 1427 had_work++;
1472 /* The purpose of the following test is to ensure that 1428 /* The purpose of the following test is to ensure that
@@ -1498,7 +1454,7 @@ static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1498 1454
1499static int 1455static int
1500cyz_fetch_msg(struct cyclades_card *cinfo, 1456cyz_fetch_msg(struct cyclades_card *cinfo,
1501 uclong * channel, ucchar * cmd, uclong * param) 1457 __u32 * channel, __u8 * cmd, __u32 * param)
1502{ 1458{
1503 struct FIRM_ID __iomem *firm_id; 1459 struct FIRM_ID __iomem *firm_id;
1504 struct ZFW_CTRL __iomem *zfw_ctrl; 1460 struct ZFW_CTRL __iomem *zfw_ctrl;
@@ -1509,16 +1465,15 @@ cyz_fetch_msg(struct cyclades_card *cinfo,
1509 if (!ISZLOADED(*cinfo)) { 1465 if (!ISZLOADED(*cinfo)) {
1510 return -1; 1466 return -1;
1511 } 1467 }
1512 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 1468 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1513 0xfffff);
1514 board_ctrl = &zfw_ctrl->board_ctrl; 1469 board_ctrl = &zfw_ctrl->board_ctrl;
1515 1470
1516 loc_doorbell = cy_readl(&((struct RUNTIME_9060 __iomem *) 1471 loc_doorbell = readl(&((struct RUNTIME_9060 __iomem *)
1517 (cinfo->ctl_addr))->loc_doorbell); 1472 (cinfo->ctl_addr))->loc_doorbell);
1518 if (loc_doorbell) { 1473 if (loc_doorbell) {
1519 *cmd = (char)(0xff & loc_doorbell); 1474 *cmd = (char)(0xff & loc_doorbell);
1520 *channel = cy_readl(&board_ctrl->fwcmd_channel); 1475 *channel = readl(&board_ctrl->fwcmd_channel);
1521 *param = (uclong) cy_readl(&board_ctrl->fwcmd_param); 1476 *param = (__u32) readl(&board_ctrl->fwcmd_param);
1522 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))-> 1477 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1523 loc_doorbell, 0xffffffff); 1478 loc_doorbell, 0xffffffff);
1524 return 1; 1479 return 1;
@@ -1528,28 +1483,27 @@ cyz_fetch_msg(struct cyclades_card *cinfo,
1528 1483
1529static int 1484static int
1530cyz_issue_cmd(struct cyclades_card *cinfo, 1485cyz_issue_cmd(struct cyclades_card *cinfo,
1531 uclong channel, ucchar cmd, uclong param) 1486 __u32 channel, __u8 cmd, __u32 param)
1532{ 1487{
1533 struct FIRM_ID __iomem *firm_id; 1488 struct FIRM_ID __iomem *firm_id;
1534 struct ZFW_CTRL __iomem *zfw_ctrl; 1489 struct ZFW_CTRL __iomem *zfw_ctrl;
1535 struct BOARD_CTRL __iomem *board_ctrl; 1490 struct BOARD_CTRL __iomem *board_ctrl;
1536 unsigned long __iomem *pci_doorbell; 1491 __u32 __iomem *pci_doorbell;
1537 int index; 1492 int index;
1538 1493
1539 firm_id = cinfo->base_addr + ID_ADDRESS; 1494 firm_id = cinfo->base_addr + ID_ADDRESS;
1540 if (!ISZLOADED(*cinfo)) { 1495 if (!ISZLOADED(*cinfo)) {
1541 return -1; 1496 return -1;
1542 } 1497 }
1543 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 1498 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1544 0xfffff);
1545 board_ctrl = &zfw_ctrl->board_ctrl; 1499 board_ctrl = &zfw_ctrl->board_ctrl;
1546 1500
1547 index = 0; 1501 index = 0;
1548 pci_doorbell = 1502 pci_doorbell =
1549 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell; 1503 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell;
1550 while ((cy_readl(pci_doorbell) & 0xff) != 0) { 1504 while ((readl(pci_doorbell) & 0xff) != 0) {
1551 if (index++ == 1000) { 1505 if (index++ == 1000) {
1552 return (int)(cy_readl(pci_doorbell) & 0xff); 1506 return (int)(readl(pci_doorbell) & 0xff);
1553 } 1507 }
1554 udelay(50L); 1508 udelay(50L);
1555 } 1509 }
@@ -1561,34 +1515,30 @@ cyz_issue_cmd(struct cyclades_card *cinfo,
1561} /* cyz_issue_cmd */ 1515} /* cyz_issue_cmd */
1562 1516
1563static void 1517static void
1564cyz_handle_rx(struct cyclades_port *info, 1518cyz_handle_rx(struct cyclades_port *info, struct CH_CTRL __iomem *ch_ctrl,
1565 volatile struct CH_CTRL __iomem * ch_ctrl, 1519 struct BUF_CTRL __iomem *buf_ctrl)
1566 volatile struct BUF_CTRL __iomem * buf_ctrl)
1567{ 1520{
1568 struct cyclades_card *cinfo = &cy_card[info->card]; 1521 struct cyclades_card *cinfo = info->card;
1569 struct tty_struct *tty = info->tty; 1522 struct tty_struct *tty = info->tty;
1570 volatile int char_count; 1523 int char_count;
1571 int len; 1524 int len;
1572#ifdef BLOCKMOVE 1525#ifdef BLOCKMOVE
1573 int small_count; 1526 unsigned char *buf;
1574#else 1527#else
1575 char data; 1528 char data;
1576#endif 1529#endif
1577 volatile uclong rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr; 1530 __u32 rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr;
1578 1531
1579 rx_get = new_rx_get = cy_readl(&buf_ctrl->rx_get); 1532 rx_get = new_rx_get = readl(&buf_ctrl->rx_get);
1580 rx_put = cy_readl(&buf_ctrl->rx_put); 1533 rx_put = readl(&buf_ctrl->rx_put);
1581 rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize); 1534 rx_bufsize = readl(&buf_ctrl->rx_bufsize);
1582 rx_bufaddr = cy_readl(&buf_ctrl->rx_bufaddr); 1535 rx_bufaddr = readl(&buf_ctrl->rx_bufaddr);
1583 if (rx_put >= rx_get) 1536 if (rx_put >= rx_get)
1584 char_count = rx_put - rx_get; 1537 char_count = rx_put - rx_get;
1585 else 1538 else
1586 char_count = rx_put - rx_get + rx_bufsize; 1539 char_count = rx_put - rx_get + rx_bufsize;
1587 1540
1588 if (char_count) { 1541 if (char_count) {
1589 info->last_active = jiffies;
1590 info->jiffies[1] = jiffies;
1591
1592#ifdef CY_ENABLE_MONITORING 1542#ifdef CY_ENABLE_MONITORING
1593 info->mon.int_count++; 1543 info->mon.int_count++;
1594 info->mon.char_count += char_count; 1544 info->mon.char_count += char_count;
@@ -1596,7 +1546,7 @@ cyz_handle_rx(struct cyclades_port *info,
1596 info->mon.char_max = char_count; 1546 info->mon.char_max = char_count;
1597 info->mon.char_last = char_count; 1547 info->mon.char_last = char_count;
1598#endif 1548#endif
1599 if (tty == 0) { 1549 if (tty == NULL) {
1600 /* flush received characters */ 1550 /* flush received characters */
1601 new_rx_get = (new_rx_get + char_count) & 1551 new_rx_get = (new_rx_get + char_count) &
1602 (rx_bufsize - 1); 1552 (rx_bufsize - 1);
@@ -1606,30 +1556,28 @@ cyz_handle_rx(struct cyclades_port *info,
1606 /* we'd like to use memcpy(t, f, n) and memset(s, c, count) 1556 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1607 for performance, but because of buffer boundaries, there 1557 for performance, but because of buffer boundaries, there
1608 may be several steps to the operation */ 1558 may be several steps to the operation */
1609 while (0 < (small_count = min_t(unsigned int, 1559 while (1) {
1610 rx_bufsize - new_rx_get, 1560 len = tty_prepare_flip_string(tty, &buf,
1611 min_t(unsigned int, TTY_FLIPBUF_SIZE - 1561 char_count);
1612 tty->flip.count, char_count)))){ 1562 if (!len)
1613 memcpy_fromio(tty->flip.char_buf_ptr, 1563 break;
1614 (char *)(cinfo->base_addr + rx_bufaddr +
1615 new_rx_get),
1616 small_count);
1617 1564
1618 tty->flip.char_buf_ptr += small_count; 1565 len = min_t(unsigned int, min(len, char_count),
1619 memset(tty->flip.flag_buf_ptr, TTY_NORMAL, 1566 rx_bufsize - new_rx_get);
1620 small_count); 1567
1621 tty->flip.flag_buf_ptr += small_count; 1568 memcpy_fromio(buf, cinfo->base_addr +
1622 new_rx_get = (new_rx_get + small_count) & 1569 rx_bufaddr + new_rx_get, len);
1570
1571 new_rx_get = (new_rx_get + len) &
1623 (rx_bufsize - 1); 1572 (rx_bufsize - 1);
1624 char_count -= small_count; 1573 char_count -= len;
1625 info->icount.rx += small_count; 1574 info->icount.rx += len;
1626 info->idle_stats.recv_bytes += small_count; 1575 info->idle_stats.recv_bytes += len;
1627 tty->flip.count += small_count;
1628 } 1576 }
1629#else 1577#else
1630 len = tty_buffer_request_room(tty, char_count); 1578 len = tty_buffer_request_room(tty, char_count);
1631 while (len--) { 1579 while (len--) {
1632 data = cy_readb(cinfo->base_addr + rx_bufaddr + 1580 data = readb(cinfo->base_addr + rx_bufaddr +
1633 new_rx_get); 1581 new_rx_get);
1634 new_rx_get = (new_rx_get + 1)& (rx_bufsize - 1); 1582 new_rx_get = (new_rx_get + 1)& (rx_bufsize - 1);
1635 tty_insert_flip_char(tty, data, TTY_NORMAL); 1583 tty_insert_flip_char(tty, data, TTY_NORMAL);
@@ -1640,13 +1588,12 @@ cyz_handle_rx(struct cyclades_port *info,
1640#ifdef CONFIG_CYZ_INTR 1588#ifdef CONFIG_CYZ_INTR
1641 /* Recalculate the number of chars in the RX buffer and issue 1589 /* Recalculate the number of chars in the RX buffer and issue
1642 a cmd in case it's higher than the RX high water mark */ 1590 a cmd in case it's higher than the RX high water mark */
1643 rx_put = cy_readl(&buf_ctrl->rx_put); 1591 rx_put = readl(&buf_ctrl->rx_put);
1644 if (rx_put >= rx_get) 1592 if (rx_put >= rx_get)
1645 char_count = rx_put - rx_get; 1593 char_count = rx_put - rx_get;
1646 else 1594 else
1647 char_count = rx_put - rx_get + rx_bufsize; 1595 char_count = rx_put - rx_get + rx_bufsize;
1648 if (char_count >= (int)cy_readl(&buf_ctrl-> 1596 if (char_count >= (int)readl(&buf_ctrl->rx_threshold)) {
1649 rx_threshold)) {
1650 cy_sched_event(info, Cy_EVENT_Z_RX_FULL); 1597 cy_sched_event(info, Cy_EVENT_Z_RX_FULL);
1651 } 1598 }
1652#endif 1599#endif
@@ -1659,26 +1606,25 @@ cyz_handle_rx(struct cyclades_port *info,
1659} 1606}
1660 1607
1661static void 1608static void
1662cyz_handle_tx(struct cyclades_port *info, 1609cyz_handle_tx(struct cyclades_port *info, struct CH_CTRL __iomem *ch_ctrl,
1663 volatile struct CH_CTRL __iomem * ch_ctrl, 1610 struct BUF_CTRL __iomem *buf_ctrl)
1664 volatile struct BUF_CTRL __iomem * buf_ctrl)
1665{ 1611{
1666 struct cyclades_card *cinfo = &cy_card[info->card]; 1612 struct cyclades_card *cinfo = info->card;
1667 struct tty_struct *tty = info->tty; 1613 struct tty_struct *tty = info->tty;
1668 char data; 1614 char data;
1669 volatile int char_count; 1615 int char_count;
1670#ifdef BLOCKMOVE 1616#ifdef BLOCKMOVE
1671 int small_count; 1617 int small_count;
1672#endif 1618#endif
1673 volatile uclong tx_put, tx_get, tx_bufsize, tx_bufaddr; 1619 __u32 tx_put, tx_get, tx_bufsize, tx_bufaddr;
1674 1620
1675 if (info->xmit_cnt <= 0) /* Nothing to transmit */ 1621 if (info->xmit_cnt <= 0) /* Nothing to transmit */
1676 return; 1622 return;
1677 1623
1678 tx_get = cy_readl(&buf_ctrl->tx_get); 1624 tx_get = readl(&buf_ctrl->tx_get);
1679 tx_put = cy_readl(&buf_ctrl->tx_put); 1625 tx_put = readl(&buf_ctrl->tx_put);
1680 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize); 1626 tx_bufsize = readl(&buf_ctrl->tx_bufsize);
1681 tx_bufaddr = cy_readl(&buf_ctrl->tx_bufaddr); 1627 tx_bufaddr = readl(&buf_ctrl->tx_bufaddr);
1682 if (tx_put >= tx_get) 1628 if (tx_put >= tx_get)
1683 char_count = tx_get - tx_put - 1 + tx_bufsize; 1629 char_count = tx_get - tx_put - 1 + tx_bufsize;
1684 else 1630 else
@@ -1686,9 +1632,8 @@ cyz_handle_tx(struct cyclades_port *info,
1686 1632
1687 if (char_count) { 1633 if (char_count) {
1688 1634
1689 if (tty == 0) { 1635 if (tty == NULL)
1690 goto ztxdone; 1636 goto ztxdone;
1691 }
1692 1637
1693 if (info->x_char) { /* send special char */ 1638 if (info->x_char) { /* send special char */
1694 data = info->x_char; 1639 data = info->x_char;
@@ -1698,8 +1643,6 @@ cyz_handle_tx(struct cyclades_port *info,
1698 info->x_char = 0; 1643 info->x_char = 0;
1699 char_count--; 1644 char_count--;
1700 info->icount.tx++; 1645 info->icount.tx++;
1701 info->last_active = jiffies;
1702 info->jiffies[2] = jiffies;
1703 } 1646 }
1704#ifdef BLOCKMOVE 1647#ifdef BLOCKMOVE
1705 while (0 < (small_count = min_t(unsigned int, 1648 while (0 < (small_count = min_t(unsigned int,
@@ -1719,8 +1662,6 @@ cyz_handle_tx(struct cyclades_port *info,
1719 info->xmit_cnt -= small_count; 1662 info->xmit_cnt -= small_count;
1720 info->xmit_tail = (info->xmit_tail + small_count) & 1663 info->xmit_tail = (info->xmit_tail + small_count) &
1721 (SERIAL_XMIT_SIZE - 1); 1664 (SERIAL_XMIT_SIZE - 1);
1722 info->last_active = jiffies;
1723 info->jiffies[2] = jiffies;
1724 } 1665 }
1725#else 1666#else
1726 while (info->xmit_cnt && char_count) { 1667 while (info->xmit_cnt && char_count) {
@@ -1733,8 +1674,6 @@ cyz_handle_tx(struct cyclades_port *info,
1733 tx_put = (tx_put + 1) & (tx_bufsize - 1); 1674 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1734 char_count--; 1675 char_count--;
1735 info->icount.tx++; 1676 info->icount.tx++;
1736 info->last_active = jiffies;
1737 info->jiffies[2] = jiffies;
1738 } 1677 }
1739#endif 1678#endif
1740ztxdone: 1679ztxdone:
@@ -1750,33 +1689,32 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1750{ 1689{
1751 struct tty_struct *tty; 1690 struct tty_struct *tty;
1752 struct cyclades_port *info; 1691 struct cyclades_port *info;
1753 static volatile struct FIRM_ID __iomem *firm_id; 1692 static struct FIRM_ID __iomem *firm_id;
1754 static volatile struct ZFW_CTRL __iomem *zfw_ctrl; 1693 static struct ZFW_CTRL __iomem *zfw_ctrl;
1755 static volatile struct BOARD_CTRL __iomem *board_ctrl; 1694 static struct BOARD_CTRL __iomem *board_ctrl;
1756 static volatile struct CH_CTRL __iomem *ch_ctrl; 1695 static struct CH_CTRL __iomem *ch_ctrl;
1757 static volatile struct BUF_CTRL __iomem *buf_ctrl; 1696 static struct BUF_CTRL __iomem *buf_ctrl;
1758 uclong channel; 1697 __u32 channel;
1759 ucchar cmd; 1698 __u8 cmd;
1760 uclong param; 1699 __u32 param;
1761 uclong hw_ver, fw_ver; 1700 __u32 hw_ver, fw_ver;
1762 int special_count; 1701 int special_count;
1763 int delta_count; 1702 int delta_count;
1764 1703
1765 firm_id = cinfo->base_addr + ID_ADDRESS; 1704 firm_id = cinfo->base_addr + ID_ADDRESS;
1766 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 1705 zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1767 0xfffff);
1768 board_ctrl = &zfw_ctrl->board_ctrl; 1706 board_ctrl = &zfw_ctrl->board_ctrl;
1769 fw_ver = cy_readl(&board_ctrl->fw_version); 1707 fw_ver = readl(&board_ctrl->fw_version);
1770 hw_ver = cy_readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))-> 1708 hw_ver = readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1771 mail_box_0); 1709 mail_box_0);
1772 1710
1773 while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) { 1711 while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) {
1774 special_count = 0; 1712 special_count = 0;
1775 delta_count = 0; 1713 delta_count = 0;
1776 info = &cy_port[channel + cinfo->first_line]; 1714 info = &cinfo->ports[channel];
1777 if ((tty = info->tty) == 0) { 1715 if ((tty = info->tty) == NULL)
1778 continue; 1716 continue;
1779 } 1717
1780 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); 1718 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
1781 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]); 1719 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
1782 1720
@@ -1801,7 +1739,7 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1801 delta_count++; 1739 delta_count++;
1802 if (info->flags & ASYNC_CHECK_CD) { 1740 if (info->flags & ASYNC_CHECK_CD) {
1803 if ((fw_ver > 241 ? ((u_long) param) : 1741 if ((fw_ver > 241 ? ((u_long) param) :
1804 cy_readl(&ch_ctrl->rs_status)) & 1742 readl(&ch_ctrl->rs_status)) &
1805 C_RS_DCD) { 1743 C_RS_DCD) {
1806 cy_sched_event(info, 1744 cy_sched_event(info,
1807 Cy_EVENT_OPEN_WAKEUP); 1745 Cy_EVENT_OPEN_WAKEUP);
@@ -1833,8 +1771,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1833 case C_CM_INTBACK2: 1771 case C_CM_INTBACK2:
1834 /* Reception Interrupt */ 1772 /* Reception Interrupt */
1835#ifdef CY_DEBUG_INTERRUPTS 1773#ifdef CY_DEBUG_INTERRUPTS
1836 printk("cyz_interrupt: rcvd intr, card %d, " 1774 printk(KERN_DEBUG "cyz_interrupt: rcvd intr, card %d, "
1837 "port %ld\n\r", info->card, channel); 1775 "port %ld\n", info->card, channel);
1838#endif 1776#endif
1839 cyz_handle_rx(info, ch_ctrl, buf_ctrl); 1777 cyz_handle_rx(info, ch_ctrl, buf_ctrl);
1840 break; 1778 break;
@@ -1843,8 +1781,8 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1843 case C_CM_INTBACK: 1781 case C_CM_INTBACK:
1844 /* Transmission Interrupt */ 1782 /* Transmission Interrupt */
1845#ifdef CY_DEBUG_INTERRUPTS 1783#ifdef CY_DEBUG_INTERRUPTS
1846 printk("cyz_interrupt: xmit intr, card %d, " 1784 printk(KERN_DEBUG "cyz_interrupt: xmit intr, card %d, "
1847 "port %ld\n\r", info->card, channel); 1785 "port %ld\n", info->card, channel);
1848#endif 1786#endif
1849 cyz_handle_tx(info, ch_ctrl, buf_ctrl); 1787 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1850 break; 1788 break;
@@ -1865,18 +1803,19 @@ static void cyz_handle_cmd(struct cyclades_card *cinfo)
1865#ifdef CONFIG_CYZ_INTR 1803#ifdef CONFIG_CYZ_INTR
1866static irqreturn_t cyz_interrupt(int irq, void *dev_id) 1804static irqreturn_t cyz_interrupt(int irq, void *dev_id)
1867{ 1805{
1868 struct cyclades_card *cinfo; 1806 struct cyclades_card *cinfo = dev_id;
1869 1807
1870 if ((cinfo = (struct cyclades_card *)dev_id) == 0) { 1808 if (unlikely(cinfo == NULL)) {
1871#ifdef CY_DEBUG_INTERRUPTS 1809#ifdef CY_DEBUG_INTERRUPTS
1872 printk("cyz_interrupt: spurious interrupt %d\n\r", irq); 1810 printk(KERN_DEBUG "cyz_interrupt: spurious interrupt %d\n",irq);
1873#endif 1811#endif
1874 return IRQ_NONE; /* spurious interrupt */ 1812 return IRQ_NONE; /* spurious interrupt */
1875 } 1813 }
1876 1814
1877 if (!ISZLOADED(*cinfo)) { 1815 if (unlikely(!ISZLOADED(*cinfo))) {
1878#ifdef CY_DEBUG_INTERRUPTS 1816#ifdef CY_DEBUG_INTERRUPTS
1879 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq); 1817 printk(KERN_DEBUG "cyz_interrupt: board not yet loaded "
1818 "(IRQ%d).\n", irq);
1880#endif 1819#endif
1881 return IRQ_NONE; 1820 return IRQ_NONE;
1882 } 1821 }
@@ -1890,19 +1829,18 @@ static irqreturn_t cyz_interrupt(int irq, void *dev_id)
1890static void cyz_rx_restart(unsigned long arg) 1829static void cyz_rx_restart(unsigned long arg)
1891{ 1830{
1892 struct cyclades_port *info = (struct cyclades_port *)arg; 1831 struct cyclades_port *info = (struct cyclades_port *)arg;
1832 struct cyclades_card *card = info->card;
1893 int retval; 1833 int retval;
1894 int card = info->card; 1834 __u32 channel = info->line - card->first_line;
1895 uclong channel = (info->line) - (cy_card[card].first_line);
1896 unsigned long flags; 1835 unsigned long flags;
1897 1836
1898 CY_LOCK(info, flags); 1837 spin_lock_irqsave(&card->card_lock, flags);
1899 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK2, 0L); 1838 retval = cyz_issue_cmd(card, channel, C_CM_INTBACK2, 0L);
1900 if (retval != 0) { 1839 if (retval != 0) {
1901 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n", 1840 printk(KERN_ERR "cyc:cyz_rx_restart retval on ttyC%d was %x\n",
1902 info->line, retval); 1841 info->line, retval);
1903 } 1842 }
1904 cyz_rx_full_timer[info->line].function = NULL; 1843 spin_unlock_irqrestore(&card->card_lock, flags);
1905 CY_UNLOCK(info, flags);
1906} 1844}
1907 1845
1908#else /* CONFIG_CYZ_INTR */ 1846#else /* CONFIG_CYZ_INTR */
@@ -1912,14 +1850,14 @@ static void cyz_poll(unsigned long arg)
1912 struct cyclades_card *cinfo; 1850 struct cyclades_card *cinfo;
1913 struct cyclades_port *info; 1851 struct cyclades_port *info;
1914 struct tty_struct *tty; 1852 struct tty_struct *tty;
1915 static volatile struct FIRM_ID *firm_id; 1853 static struct FIRM_ID *firm_id;
1916 static volatile struct ZFW_CTRL *zfw_ctrl; 1854 static struct ZFW_CTRL *zfw_ctrl;
1917 static volatile struct BOARD_CTRL *board_ctrl; 1855 static struct BOARD_CTRL *board_ctrl;
1918 static volatile struct CH_CTRL *ch_ctrl; 1856 static struct CH_CTRL *ch_ctrl;
1919 static volatile struct BUF_CTRL *buf_ctrl; 1857 static struct BUF_CTRL *buf_ctrl;
1858 unsigned long expires = jiffies + HZ;
1920 int card, port; 1859 int card, port;
1921 1860
1922 cyz_timerlist.expires = jiffies + (HZ);
1923 for (card = 0; card < NR_CARDS; card++) { 1861 for (card = 0; card < NR_CARDS; card++) {
1924 cinfo = &cy_card[card]; 1862 cinfo = &cy_card[card];
1925 1863
@@ -1930,12 +1868,12 @@ static void cyz_poll(unsigned long arg)
1930 1868
1931 firm_id = cinfo->base_addr + ID_ADDRESS; 1869 firm_id = cinfo->base_addr + ID_ADDRESS;
1932 zfw_ctrl = cinfo->base_addr + 1870 zfw_ctrl = cinfo->base_addr +
1933 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1871 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
1934 board_ctrl = &(zfw_ctrl->board_ctrl); 1872 board_ctrl = &(zfw_ctrl->board_ctrl);
1935 1873
1936 /* Skip first polling cycle to avoid racing conditions with the FW */ 1874 /* Skip first polling cycle to avoid racing conditions with the FW */
1937 if (!cinfo->intr_enabled) { 1875 if (!cinfo->intr_enabled) {
1938 cinfo->nports = (int)cy_readl(&board_ctrl->n_channel); 1876 cinfo->nports = (int)readl(&board_ctrl->n_channel);
1939 cinfo->intr_enabled = 1; 1877 cinfo->intr_enabled = 1;
1940 continue; 1878 continue;
1941 } 1879 }
@@ -1943,7 +1881,7 @@ static void cyz_poll(unsigned long arg)
1943 cyz_handle_cmd(cinfo); 1881 cyz_handle_cmd(cinfo);
1944 1882
1945 for (port = 0; port < cinfo->nports; port++) { 1883 for (port = 0; port < cinfo->nports; port++) {
1946 info = &cy_port[port + cinfo->first_line]; 1884 info = &cinfo->ports[port];
1947 tty = info->tty; 1885 tty = info->tty;
1948 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]); 1886 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]);
1949 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]); 1887 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]);
@@ -1953,9 +1891,9 @@ static void cyz_poll(unsigned long arg)
1953 cyz_handle_tx(info, ch_ctrl, buf_ctrl); 1891 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1954 } 1892 }
1955 /* poll every 'cyz_polling_cycle' period */ 1893 /* poll every 'cyz_polling_cycle' period */
1956 cyz_timerlist.expires = jiffies + cyz_polling_cycle; 1894 expires = jiffies + cyz_polling_cycle;
1957 } 1895 }
1958 add_timer(&cyz_timerlist); 1896 mod_timer(&cyz_timerlist, expires);
1959} /* cyz_poll */ 1897} /* cyz_poll */
1960 1898
1961#endif /* CONFIG_CYZ_INTR */ 1899#endif /* CONFIG_CYZ_INTR */
@@ -1968,20 +1906,21 @@ static void cyz_poll(unsigned long arg)
1968 */ 1906 */
1969static int startup(struct cyclades_port *info) 1907static int startup(struct cyclades_port *info)
1970{ 1908{
1909 struct cyclades_card *card;
1971 unsigned long flags; 1910 unsigned long flags;
1972 int retval = 0; 1911 int retval = 0;
1973 void __iomem *base_addr; 1912 void __iomem *base_addr;
1974 int card, chip, channel, index; 1913 int chip, channel, index;
1975 unsigned long page; 1914 unsigned long page;
1976 1915
1977 card = info->card; 1916 card = info->card;
1978 channel = (info->line) - (cy_card[card].first_line); 1917 channel = info->line - card->first_line;
1979 1918
1980 page = get_zeroed_page(GFP_KERNEL); 1919 page = get_zeroed_page(GFP_KERNEL);
1981 if (!page) 1920 if (!page)
1982 return -ENOMEM; 1921 return -ENOMEM;
1983 1922
1984 CY_LOCK(info, flags); 1923 spin_lock_irqsave(&card->card_lock, flags);
1985 1924
1986 if (info->flags & ASYNC_INITIALIZED) { 1925 if (info->flags & ASYNC_INITIALIZED) {
1987 free_page(page); 1926 free_page(page);
@@ -2001,24 +1940,22 @@ static int startup(struct cyclades_port *info)
2001 else 1940 else
2002 info->xmit_buf = (unsigned char *)page; 1941 info->xmit_buf = (unsigned char *)page;
2003 1942
2004 CY_UNLOCK(info, flags); 1943 spin_unlock_irqrestore(&card->card_lock, flags);
2005 1944
2006 set_line_char(info); 1945 set_line_char(info);
2007 1946
2008 if (!IS_CYC_Z(cy_card[card])) { 1947 if (!IS_CYC_Z(*card)) {
2009 chip = channel >> 2; 1948 chip = channel >> 2;
2010 channel &= 0x03; 1949 channel &= 0x03;
2011 index = cy_card[card].bus_index; 1950 index = card->bus_index;
2012 base_addr = cy_card[card].base_addr + 1951 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
2013 (cy_chip_offset[chip] << index);
2014 1952
2015#ifdef CY_DEBUG_OPEN 1953#ifdef CY_DEBUG_OPEN
2016 printk("cyc startup card %d, chip %d, channel %d, " 1954 printk(KERN_DEBUG "cyc startup card %d, chip %d, channel %d, "
2017 "base_addr %lx\n", 1955 "base_addr %p\n",
2018 card, chip, channel, (long)base_addr); 1956 card, chip, channel, base_addr);
2019 /**/
2020#endif 1957#endif
2021 CY_LOCK(info, flags); 1958 spin_lock_irqsave(&card->card_lock, flags);
2022 1959
2023 cy_writeb(base_addr + (CyCAR << index), (u_char) channel); 1960 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2024 1961
@@ -2034,14 +1971,14 @@ static int startup(struct cyclades_port *info)
2034 cy_writeb(base_addr + (CyMSVR2 << index), CyDTR); 1971 cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
2035 1972
2036#ifdef CY_DEBUG_DTR 1973#ifdef CY_DEBUG_DTR
2037 printk("cyc:startup raising DTR\n"); 1974 printk(KERN_DEBUG "cyc:startup raising DTR\n");
2038 printk(" status: 0x%x, 0x%x\n", 1975 printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
2039 cy_readb(base_addr + (CyMSVR1 << index)), 1976 readb(base_addr + (CyMSVR1 << index)),
2040 cy_readb(base_addr + (CyMSVR2 << index))); 1977 readb(base_addr + (CyMSVR2 << index)));
2041#endif 1978#endif
2042 1979
2043 cy_writeb(base_addr + (CySRER << index), 1980 cy_writeb(base_addr + (CySRER << index),
2044 cy_readb(base_addr + (CySRER << index)) | CyRxData); 1981 readb(base_addr + (CySRER << index)) | CyRxData);
2045 info->flags |= ASYNC_INITIALIZED; 1982 info->flags |= ASYNC_INITIALIZED;
2046 1983
2047 if (info->tty) { 1984 if (info->tty) {
@@ -2054,7 +1991,7 @@ static int startup(struct cyclades_port *info)
2054 info->idle_stats.recv_idle = 1991 info->idle_stats.recv_idle =
2055 info->idle_stats.xmit_idle = jiffies; 1992 info->idle_stats.xmit_idle = jiffies;
2056 1993
2057 CY_UNLOCK(info, flags); 1994 spin_unlock_irqrestore(&card->card_lock, flags);
2058 1995
2059 } else { 1996 } else {
2060 struct FIRM_ID __iomem *firm_id; 1997 struct FIRM_ID __iomem *firm_id;
@@ -2063,24 +2000,23 @@ static int startup(struct cyclades_port *info)
2063 struct CH_CTRL __iomem *ch_ctrl; 2000 struct CH_CTRL __iomem *ch_ctrl;
2064 int retval; 2001 int retval;
2065 2002
2066 base_addr = cy_card[card].base_addr; 2003 base_addr = card->base_addr;
2067 2004
2068 firm_id = base_addr + ID_ADDRESS; 2005 firm_id = base_addr + ID_ADDRESS;
2069 if (!ISZLOADED(cy_card[card])) { 2006 if (!ISZLOADED(*card)) {
2070 return -ENODEV; 2007 return -ENODEV;
2071 } 2008 }
2072 2009
2073 zfw_ctrl = cy_card[card].base_addr + 2010 zfw_ctrl = card->base_addr +
2074 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2011 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
2075 board_ctrl = &zfw_ctrl->board_ctrl; 2012 board_ctrl = &zfw_ctrl->board_ctrl;
2076 ch_ctrl = zfw_ctrl->ch_ctrl; 2013 ch_ctrl = zfw_ctrl->ch_ctrl;
2077 2014
2078#ifdef CY_DEBUG_OPEN 2015#ifdef CY_DEBUG_OPEN
2079 printk("cyc startup Z card %d, channel %d, base_addr %lx\n", 2016 printk(KERN_DEBUG "cyc startup Z card %d, channel %d, "
2080 card, channel, (long)base_addr); 2017 "base_addr %p\n", card, channel, base_addr);
2081 /**/
2082#endif 2018#endif
2083 CY_LOCK(info, flags); 2019 spin_lock_irqsave(&card->card_lock, flags);
2084 2020
2085 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE); 2021 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
2086#ifdef Z_WAKE 2022#ifdef Z_WAKE
@@ -2102,33 +2038,31 @@ static int startup(struct cyclades_port *info)
2102#endif /* CONFIG_CYZ_INTR */ 2038#endif /* CONFIG_CYZ_INTR */
2103#endif /* Z_WAKE */ 2039#endif /* Z_WAKE */
2104 2040
2105 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L); 2041 retval = cyz_issue_cmd(card, channel, C_CM_IOCTL, 0L);
2106 if (retval != 0) { 2042 if (retval != 0) {
2107 printk("cyc:startup(1) retval on ttyC%d was %x\n", 2043 printk(KERN_ERR "cyc:startup(1) retval on ttyC%d was "
2108 info->line, retval); 2044 "%x\n", info->line, retval);
2109 } 2045 }
2110 2046
2111 /* Flush RX buffers before raising DTR and RTS */ 2047 /* Flush RX buffers before raising DTR and RTS */
2112 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_RX, 2048 retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_RX, 0L);
2113 0L);
2114 if (retval != 0) { 2049 if (retval != 0) {
2115 printk("cyc:startup(2) retval on ttyC%d was %x\n", 2050 printk(KERN_ERR "cyc:startup(2) retval on ttyC%d was "
2116 info->line, retval); 2051 "%x\n", info->line, retval);
2117 } 2052 }
2118 2053
2119 /* set timeout !!! */ 2054 /* set timeout !!! */
2120 /* set RTS and DTR !!! */ 2055 /* set RTS and DTR !!! */
2121 cy_writel(&ch_ctrl[channel].rs_control, 2056 cy_writel(&ch_ctrl[channel].rs_control,
2122 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS | 2057 readl(&ch_ctrl[channel].rs_control) | C_RS_RTS |
2123 C_RS_DTR); 2058 C_RS_DTR);
2124 retval = cyz_issue_cmd(&cy_card[info->card], channel, 2059 retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM, 0L);
2125 C_CM_IOCTLM, 0L);
2126 if (retval != 0) { 2060 if (retval != 0) {
2127 printk("cyc:startup(3) retval on ttyC%d was %x\n", 2061 printk(KERN_ERR "cyc:startup(3) retval on ttyC%d was "
2128 info->line, retval); 2062 "%x\n", info->line, retval);
2129 } 2063 }
2130#ifdef CY_DEBUG_DTR 2064#ifdef CY_DEBUG_DTR
2131 printk("cyc:startup raising Z DTR\n"); 2065 printk(KERN_DEBUG "cyc:startup raising Z DTR\n");
2132#endif 2066#endif
2133 2067
2134 /* enable send, recv, modem !!! */ 2068 /* enable send, recv, modem !!! */
@@ -2144,51 +2078,50 @@ static int startup(struct cyclades_port *info)
2144 info->idle_stats.recv_idle = 2078 info->idle_stats.recv_idle =
2145 info->idle_stats.xmit_idle = jiffies; 2079 info->idle_stats.xmit_idle = jiffies;
2146 2080
2147 CY_UNLOCK(info, flags); 2081 spin_unlock_irqrestore(&card->card_lock, flags);
2148 } 2082 }
2149 2083
2150#ifdef CY_DEBUG_OPEN 2084#ifdef CY_DEBUG_OPEN
2151 printk(" cyc startup done\n"); 2085 printk(KERN_DEBUG "cyc startup done\n");
2152#endif 2086#endif
2153 return 0; 2087 return 0;
2154 2088
2155errout: 2089errout:
2156 CY_UNLOCK(info, flags); 2090 spin_unlock_irqrestore(&card->card_lock, flags);
2157 return retval; 2091 return retval;
2158} /* startup */ 2092} /* startup */
2159 2093
2160static void start_xmit(struct cyclades_port *info) 2094static void start_xmit(struct cyclades_port *info)
2161{ 2095{
2096 struct cyclades_card *card;
2162 unsigned long flags; 2097 unsigned long flags;
2163 void __iomem *base_addr; 2098 void __iomem *base_addr;
2164 int card, chip, channel, index; 2099 int chip, channel, index;
2165 2100
2166 card = info->card; 2101 card = info->card;
2167 channel = (info->line) - (cy_card[card].first_line); 2102 channel = info->line - card->first_line;
2168 if (!IS_CYC_Z(cy_card[card])) { 2103 if (!IS_CYC_Z(*card)) {
2169 chip = channel >> 2; 2104 chip = channel >> 2;
2170 channel &= 0x03; 2105 channel &= 0x03;
2171 index = cy_card[card].bus_index; 2106 index = card->bus_index;
2172 base_addr = cy_card[card].base_addr + 2107 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
2173 (cy_chip_offset[chip] << index);
2174 2108
2175 CY_LOCK(info, flags); 2109 spin_lock_irqsave(&card->card_lock, flags);
2176 cy_writeb(base_addr + (CyCAR << index), channel); 2110 cy_writeb(base_addr + (CyCAR << index), channel);
2177 cy_writeb(base_addr + (CySRER << index), 2111 cy_writeb(base_addr + (CySRER << index),
2178 cy_readb(base_addr + (CySRER << index)) | CyTxRdy); 2112 readb(base_addr + (CySRER << index)) | CyTxRdy);
2179 CY_UNLOCK(info, flags); 2113 spin_unlock_irqrestore(&card->card_lock, flags);
2180 } else { 2114 } else {
2181#ifdef CONFIG_CYZ_INTR 2115#ifdef CONFIG_CYZ_INTR
2182 int retval; 2116 int retval;
2183 2117
2184 CY_LOCK(info, flags); 2118 spin_lock_irqsave(&card->card_lock, flags);
2185 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK, 2119 retval = cyz_issue_cmd(card, channel, C_CM_INTBACK, 0L);
2186 0L);
2187 if (retval != 0) { 2120 if (retval != 0) {
2188 printk("cyc:start_xmit retval on ttyC%d was %x\n", 2121 printk(KERN_ERR "cyc:start_xmit retval on ttyC%d was "
2189 info->line, retval); 2122 "%x\n", info->line, retval);
2190 } 2123 }
2191 CY_UNLOCK(info, flags); 2124 spin_unlock_irqrestore(&card->card_lock, flags);
2192#else /* CONFIG_CYZ_INTR */ 2125#else /* CONFIG_CYZ_INTR */
2193 /* Don't have to do anything at this time */ 2126 /* Don't have to do anything at this time */
2194#endif /* CONFIG_CYZ_INTR */ 2127#endif /* CONFIG_CYZ_INTR */
@@ -2201,30 +2134,30 @@ static void start_xmit(struct cyclades_port *info)
2201 */ 2134 */
2202static void shutdown(struct cyclades_port *info) 2135static void shutdown(struct cyclades_port *info)
2203{ 2136{
2137 struct cyclades_card *card;
2204 unsigned long flags; 2138 unsigned long flags;
2205 void __iomem *base_addr; 2139 void __iomem *base_addr;
2206 int card, chip, channel, index; 2140 int chip, channel, index;
2207 2141
2208 if (!(info->flags & ASYNC_INITIALIZED)) { 2142 if (!(info->flags & ASYNC_INITIALIZED)) {
2209 return; 2143 return;
2210 } 2144 }
2211 2145
2212 card = info->card; 2146 card = info->card;
2213 channel = info->line - cy_card[card].first_line; 2147 channel = info->line - card->first_line;
2214 if (!IS_CYC_Z(cy_card[card])) { 2148 if (!IS_CYC_Z(*card)) {
2215 chip = channel >> 2; 2149 chip = channel >> 2;
2216 channel &= 0x03; 2150 channel &= 0x03;
2217 index = cy_card[card].bus_index; 2151 index = card->bus_index;
2218 base_addr = cy_card[card].base_addr + 2152 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
2219 (cy_chip_offset[chip] << index);
2220 2153
2221#ifdef CY_DEBUG_OPEN 2154#ifdef CY_DEBUG_OPEN
2222 printk("cyc shutdown Y card %d, chip %d, channel %d, " 2155 printk(KERN_DEBUG "cyc shutdown Y card %d, chip %d, "
2223 "base_addr %lx\n", 2156 "channel %d, base_addr %p\n",
2224 card, chip, channel, (long)base_addr); 2157 card, chip, channel, base_addr);
2225#endif 2158#endif
2226 2159
2227 CY_LOCK(info, flags); 2160 spin_lock_irqsave(&card->card_lock, flags);
2228 2161
2229 /* Clear delta_msr_wait queue to avoid mem leaks. */ 2162 /* Clear delta_msr_wait queue to avoid mem leaks. */
2230 wake_up_interruptible(&info->delta_msr_wait); 2163 wake_up_interruptible(&info->delta_msr_wait);
@@ -2240,10 +2173,10 @@ static void shutdown(struct cyclades_port *info)
2240 cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS); 2173 cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
2241 cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR); 2174 cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
2242#ifdef CY_DEBUG_DTR 2175#ifdef CY_DEBUG_DTR
2243 printk("cyc shutdown dropping DTR\n"); 2176 printk(KERN_DEBUG "cyc shutdown dropping DTR\n");
2244 printk(" status: 0x%x, 0x%x\n", 2177 printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
2245 cy_readb(base_addr + (CyMSVR1 << index)), 2178 readb(base_addr + (CyMSVR1 << index)),
2246 cy_readb(base_addr + (CyMSVR2 << index))); 2179 readb(base_addr + (CyMSVR2 << index)));
2247#endif 2180#endif
2248 } 2181 }
2249 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyDIS_RCVR, index); 2182 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyDIS_RCVR, index);
@@ -2254,7 +2187,7 @@ static void shutdown(struct cyclades_port *info)
2254 set_bit(TTY_IO_ERROR, &info->tty->flags); 2187 set_bit(TTY_IO_ERROR, &info->tty->flags);
2255 } 2188 }
2256 info->flags &= ~ASYNC_INITIALIZED; 2189 info->flags &= ~ASYNC_INITIALIZED;
2257 CY_UNLOCK(info, flags); 2190 spin_unlock_irqrestore(&card->card_lock, flags);
2258 } else { 2191 } else {
2259 struct FIRM_ID __iomem *firm_id; 2192 struct FIRM_ID __iomem *firm_id;
2260 struct ZFW_CTRL __iomem *zfw_ctrl; 2193 struct ZFW_CTRL __iomem *zfw_ctrl;
@@ -2262,23 +2195,23 @@ static void shutdown(struct cyclades_port *info)
2262 struct CH_CTRL __iomem *ch_ctrl; 2195 struct CH_CTRL __iomem *ch_ctrl;
2263 int retval; 2196 int retval;
2264 2197
2265 base_addr = cy_card[card].base_addr; 2198 base_addr = card->base_addr;
2266#ifdef CY_DEBUG_OPEN 2199#ifdef CY_DEBUG_OPEN
2267 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n", 2200 printk(KERN_DEBUG "cyc shutdown Z card %d, channel %d, "
2268 card, channel, (long)base_addr); 2201 "base_addr %p\n", card, channel, base_addr);
2269#endif 2202#endif
2270 2203
2271 firm_id = base_addr + ID_ADDRESS; 2204 firm_id = base_addr + ID_ADDRESS;
2272 if (!ISZLOADED(cy_card[card])) { 2205 if (!ISZLOADED(*card)) {
2273 return; 2206 return;
2274 } 2207 }
2275 2208
2276 zfw_ctrl = cy_card[card].base_addr + 2209 zfw_ctrl = card->base_addr +
2277 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2210 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
2278 board_ctrl = &zfw_ctrl->board_ctrl; 2211 board_ctrl = &zfw_ctrl->board_ctrl;
2279 ch_ctrl = zfw_ctrl->ch_ctrl; 2212 ch_ctrl = zfw_ctrl->ch_ctrl;
2280 2213
2281 CY_LOCK(info, flags); 2214 spin_lock_irqsave(&card->card_lock, flags);
2282 2215
2283 if (info->xmit_buf) { 2216 if (info->xmit_buf) {
2284 unsigned char *temp; 2217 unsigned char *temp;
@@ -2289,16 +2222,16 @@ static void shutdown(struct cyclades_port *info)
2289 2222
2290 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { 2223 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2291 cy_writel(&ch_ctrl[channel].rs_control, 2224 cy_writel(&ch_ctrl[channel].rs_control,
2292 (uclong)(cy_readl(&ch_ctrl[channel].rs_control)& 2225 (__u32)(readl(&ch_ctrl[channel].rs_control) &
2293 ~(C_RS_RTS | C_RS_DTR))); 2226 ~(C_RS_RTS | C_RS_DTR)));
2294 retval = cyz_issue_cmd(&cy_card[info->card], channel, 2227 retval = cyz_issue_cmd(info->card, channel,
2295 C_CM_IOCTLM, 0L); 2228 C_CM_IOCTLM, 0L);
2296 if (retval != 0) { 2229 if (retval != 0) {
2297 printk("cyc:shutdown retval on ttyC%d was %x\n", 2230 printk(KERN_ERR"cyc:shutdown retval on ttyC%d "
2298 info->line, retval); 2231 "was %x\n", info->line, retval);
2299 } 2232 }
2300#ifdef CY_DEBUG_DTR 2233#ifdef CY_DEBUG_DTR
2301 printk("cyc:shutdown dropping Z DTR\n"); 2234 printk(KERN_DEBUG "cyc:shutdown dropping Z DTR\n");
2302#endif 2235#endif
2303 } 2236 }
2304 2237
@@ -2307,11 +2240,11 @@ static void shutdown(struct cyclades_port *info)
2307 } 2240 }
2308 info->flags &= ~ASYNC_INITIALIZED; 2241 info->flags &= ~ASYNC_INITIALIZED;
2309 2242
2310 CY_UNLOCK(info, flags); 2243 spin_unlock_irqrestore(&card->card_lock, flags);
2311 } 2244 }
2312 2245
2313#ifdef CY_DEBUG_OPEN 2246#ifdef CY_DEBUG_OPEN
2314 printk(" cyc shutdown done\n"); 2247 printk(KERN_DEBUG "cyc shutdown done\n");
2315#endif 2248#endif
2316} /* shutdown */ 2249} /* shutdown */
2317 2250
@@ -2332,7 +2265,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2332 int retval; 2265 int retval;
2333 void __iomem *base_addr; 2266 void __iomem *base_addr;
2334 2267
2335 cinfo = &cy_card[info->card]; 2268 cinfo = info->card;
2336 channel = info->line - cinfo->first_line; 2269 channel = info->line - cinfo->first_line;
2337 2270
2338 /* 2271 /*
@@ -2340,9 +2273,8 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2340 * until it's done, and then try again. 2273 * until it's done, and then try again.
2341 */ 2274 */
2342 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) { 2275 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2343 if (info->flags & ASYNC_CLOSING) { 2276 wait_event_interruptible(info->close_wait,
2344 interruptible_sleep_on(&info->close_wait); 2277 !(info->flags & ASYNC_CLOSING));
2345 }
2346 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; 2278 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
2347 } 2279 }
2348 2280
@@ -2365,17 +2297,16 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2365 retval = 0; 2297 retval = 0;
2366 add_wait_queue(&info->open_wait, &wait); 2298 add_wait_queue(&info->open_wait, &wait);
2367#ifdef CY_DEBUG_OPEN 2299#ifdef CY_DEBUG_OPEN
2368 printk("cyc block_til_ready before block: ttyC%d, count = %d\n", 2300 printk(KERN_DEBUG "cyc block_til_ready before block: ttyC%d, "
2369 info->line, info->count); 2301 "count = %d\n", info->line, info->count);
2370 /**/
2371#endif 2302#endif
2372 CY_LOCK(info, flags); 2303 spin_lock_irqsave(&cinfo->card_lock, flags);
2373 if (!tty_hung_up_p(filp)) 2304 if (!tty_hung_up_p(filp))
2374 info->count--; 2305 info->count--;
2375 CY_UNLOCK(info, flags); 2306 spin_unlock_irqrestore(&cinfo->card_lock, flags);
2376#ifdef CY_DEBUG_COUNT 2307#ifdef CY_DEBUG_COUNT
2377 printk("cyc block_til_ready: (%d): decrementing count to %d\n", 2308 printk(KERN_DEBUG "cyc block_til_ready: (%d): decrementing count to "
2378 current->pid, info->count); 2309 "%d\n", current->pid, info->count);
2379#endif 2310#endif
2380 info->blocked_open++; 2311 info->blocked_open++;
2381 2312
@@ -2386,7 +2317,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2386 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index); 2317 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
2387 2318
2388 while (1) { 2319 while (1) {
2389 CY_LOCK(info, flags); 2320 spin_lock_irqsave(&cinfo->card_lock, flags);
2390 if ((tty->termios->c_cflag & CBAUD)) { 2321 if ((tty->termios->c_cflag & CBAUD)) {
2391 cy_writeb(base_addr + (CyCAR << index), 2322 cy_writeb(base_addr + (CyCAR << index),
2392 (u_char) channel); 2323 (u_char) channel);
@@ -2395,15 +2326,14 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2395 cy_writeb(base_addr + (CyMSVR2 << index), 2326 cy_writeb(base_addr + (CyMSVR2 << index),
2396 CyDTR); 2327 CyDTR);
2397#ifdef CY_DEBUG_DTR 2328#ifdef CY_DEBUG_DTR
2398 printk("cyc:block_til_ready raising DTR\n"); 2329 printk(KERN_DEBUG "cyc:block_til_ready raising "
2399 printk(" status: 0x%x, 0x%x\n", 2330 "DTR\n");
2400 cy_readb(base_addr + 2331 printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
2401 (CyMSVR1 << index)), 2332 readb(base_addr + (CyMSVR1 << index)),
2402 cy_readb(base_addr + 2333 readb(base_addr + (CyMSVR2 << index)));
2403 (CyMSVR2 << index)));
2404#endif 2334#endif
2405 } 2335 }
2406 CY_UNLOCK(info, flags); 2336 spin_unlock_irqrestore(&cinfo->card_lock, flags);
2407 2337
2408 set_current_state(TASK_INTERRUPTIBLE); 2338 set_current_state(TASK_INTERRUPTIBLE);
2409 if (tty_hung_up_p(filp) || 2339 if (tty_hung_up_p(filp) ||
@@ -2413,26 +2343,25 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2413 break; 2343 break;
2414 } 2344 }
2415 2345
2416 CY_LOCK(info, flags); 2346 spin_lock_irqsave(&cinfo->card_lock, flags);
2417 cy_writeb(base_addr + (CyCAR << index), 2347 cy_writeb(base_addr + (CyCAR << index),
2418 (u_char) channel); 2348 (u_char) channel);
2419 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) || 2349 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2420 (cy_readb(base_addr + 2350 (readb(base_addr +
2421 (CyMSVR1 << index)) & CyDCD))) { 2351 (CyMSVR1 << index)) & CyDCD))) {
2422 CY_UNLOCK(info, flags); 2352 spin_unlock_irqrestore(&cinfo->card_lock, flags);
2423 break; 2353 break;
2424 } 2354 }
2425 CY_UNLOCK(info, flags); 2355 spin_unlock_irqrestore(&cinfo->card_lock, flags);
2426 2356
2427 if (signal_pending(current)) { 2357 if (signal_pending(current)) {
2428 retval = -ERESTARTSYS; 2358 retval = -ERESTARTSYS;
2429 break; 2359 break;
2430 } 2360 }
2431#ifdef CY_DEBUG_OPEN 2361#ifdef CY_DEBUG_OPEN
2432 printk("cyc block_til_ready blocking: ttyC%d, " 2362 printk(KERN_DEBUG "cyc block_til_ready blocking: "
2433 "count = %d\n", 2363 "ttyC%d, count = %d\n",
2434 info->line, info->count); 2364 info->line, info->count);
2435 /**/
2436#endif 2365#endif
2437 schedule(); 2366 schedule();
2438 } 2367 }
@@ -2446,31 +2375,30 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2446 base_addr = cinfo->base_addr; 2375 base_addr = cinfo->base_addr;
2447 firm_id = base_addr + ID_ADDRESS; 2376 firm_id = base_addr + ID_ADDRESS;
2448 if (!ISZLOADED(*cinfo)) { 2377 if (!ISZLOADED(*cinfo)) {
2449 current->state = TASK_RUNNING; 2378 __set_current_state(TASK_RUNNING);
2450 remove_wait_queue(&info->open_wait, &wait); 2379 remove_wait_queue(&info->open_wait, &wait);
2451 return -EINVAL; 2380 return -EINVAL;
2452 } 2381 }
2453 2382
2454 zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 2383 zfw_ctrl = base_addr + (readl(&firm_id->zfwctrl_addr)& 0xfffff);
2455 0xfffff);
2456 board_ctrl = &zfw_ctrl->board_ctrl; 2384 board_ctrl = &zfw_ctrl->board_ctrl;
2457 ch_ctrl = zfw_ctrl->ch_ctrl; 2385 ch_ctrl = zfw_ctrl->ch_ctrl;
2458 2386
2459 while (1) { 2387 while (1) {
2460 if ((tty->termios->c_cflag & CBAUD)) { 2388 if ((tty->termios->c_cflag & CBAUD)) {
2461 cy_writel(&ch_ctrl[channel].rs_control, 2389 cy_writel(&ch_ctrl[channel].rs_control,
2462 cy_readl(&ch_ctrl[channel]. 2390 readl(&ch_ctrl[channel].rs_control) |
2463 rs_control) | (C_RS_RTS | 2391 C_RS_RTS | C_RS_DTR);
2464 C_RS_DTR)); 2392 retval = cyz_issue_cmd(cinfo,
2465 retval = cyz_issue_cmd(&cy_card[info->card], 2393 channel, C_CM_IOCTLM, 0L);
2466 channel, C_CM_IOCTLM, 0L);
2467 if (retval != 0) { 2394 if (retval != 0) {
2468 printk("cyc:block_til_ready retval on " 2395 printk(KERN_ERR "cyc:block_til_ready "
2469 "ttyC%d was %x\n", 2396 "retval on ttyC%d was %x\n",
2470 info->line, retval); 2397 info->line, retval);
2471 } 2398 }
2472#ifdef CY_DEBUG_DTR 2399#ifdef CY_DEBUG_DTR
2473 printk("cyc:block_til_ready raising Z DTR\n"); 2400 printk(KERN_DEBUG "cyc:block_til_ready raising "
2401 "Z DTR\n");
2474#endif 2402#endif
2475 } 2403 }
2476 2404
@@ -2482,7 +2410,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2482 break; 2410 break;
2483 } 2411 }
2484 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) || 2412 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2485 (cy_readl(&ch_ctrl[channel].rs_status) & 2413 (readl(&ch_ctrl[channel].rs_status) &
2486 C_RS_DCD))) { 2414 C_RS_DCD))) {
2487 break; 2415 break;
2488 } 2416 }
@@ -2491,28 +2419,26 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2491 break; 2419 break;
2492 } 2420 }
2493#ifdef CY_DEBUG_OPEN 2421#ifdef CY_DEBUG_OPEN
2494 printk("cyc block_til_ready blocking: ttyC%d, " 2422 printk(KERN_DEBUG "cyc block_til_ready blocking: "
2495 "count = %d\n", 2423 "ttyC%d, count = %d\n",
2496 info->line, info->count); 2424 info->line, info->count);
2497 /**/
2498#endif 2425#endif
2499 schedule(); 2426 schedule();
2500 } 2427 }
2501 } 2428 }
2502 current->state = TASK_RUNNING; 2429 __set_current_state(TASK_RUNNING);
2503 remove_wait_queue(&info->open_wait, &wait); 2430 remove_wait_queue(&info->open_wait, &wait);
2504 if (!tty_hung_up_p(filp)) { 2431 if (!tty_hung_up_p(filp)) {
2505 info->count++; 2432 info->count++;
2506#ifdef CY_DEBUG_COUNT 2433#ifdef CY_DEBUG_COUNT
2507 printk("cyc:block_til_ready (%d): incrementing count to %d\n", 2434 printk(KERN_DEBUG "cyc:block_til_ready (%d): incrementing "
2508 current->pid, info->count); 2435 "count to %d\n", current->pid, info->count);
2509#endif 2436#endif
2510 } 2437 }
2511 info->blocked_open--; 2438 info->blocked_open--;
2512#ifdef CY_DEBUG_OPEN 2439#ifdef CY_DEBUG_OPEN
2513 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n", 2440 printk(KERN_DEBUG "cyc:block_til_ready after blocking: ttyC%d, "
2514 info->line, info->count); 2441 "count = %d\n", info->line, info->count);
2515 /**/
2516#endif 2442#endif
2517 if (retval) 2443 if (retval)
2518 return retval; 2444 return retval;
@@ -2527,13 +2453,20 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
2527static int cy_open(struct tty_struct *tty, struct file *filp) 2453static int cy_open(struct tty_struct *tty, struct file *filp)
2528{ 2454{
2529 struct cyclades_port *info; 2455 struct cyclades_port *info;
2456 unsigned int i;
2530 int retval, line; 2457 int retval, line;
2531 2458
2532 line = tty->index; 2459 line = tty->index;
2533 if ((line < 0) || (NR_PORTS <= line)) { 2460 if ((line < 0) || (NR_PORTS <= line)) {
2534 return -ENODEV; 2461 return -ENODEV;
2535 } 2462 }
2536 info = &cy_port[line]; 2463 for (i = 0; i < NR_CARDS; i++)
2464 if (line < cy_card[i].first_line + cy_card[i].nports &&
2465 line >= cy_card[i].first_line)
2466 break;
2467 if (i >= NR_CARDS)
2468 return -ENODEV;
2469 info = &cy_card[i].ports[line - cy_card[i].first_line];
2537 if (info->line < 0) { 2470 if (info->line < 0) {
2538 return -ENODEV; 2471 return -ENODEV;
2539 } 2472 }
@@ -2542,23 +2475,23 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2542 treat it as absent from the system. This 2475 treat it as absent from the system. This
2543 will make the user pay attention. 2476 will make the user pay attention.
2544 */ 2477 */
2545 if (IS_CYC_Z(cy_card[info->card])) { 2478 if (IS_CYC_Z(*info->card)) {
2546 struct cyclades_card *cinfo = &cy_card[info->card]; 2479 struct cyclades_card *cinfo = info->card;
2547 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS; 2480 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2548 2481
2549 if (!ISZLOADED(*cinfo)) { 2482 if (!ISZLOADED(*cinfo)) {
2550 if (((ZE_V1 == cy_readl( 2483 if (((ZE_V1 == readl(&((struct RUNTIME_9060 __iomem *)
2551 &((struct RUNTIME_9060 __iomem *)
2552 (cinfo->ctl_addr))->mail_box_0)) && 2484 (cinfo->ctl_addr))->mail_box_0)) &&
2553 Z_FPGA_CHECK(*cinfo)) && 2485 Z_FPGA_CHECK(*cinfo)) &&
2554 (ZFIRM_HLT == cy_readl( 2486 (ZFIRM_HLT == readl(
2555 &firm_id->signature))) { 2487 &firm_id->signature))) {
2556 printk("cyc:Cyclades-Z Error: you need an " 2488 printk(KERN_ERR "cyc:Cyclades-Z Error: you "
2557 "external power supply for this number " 2489 "need an external power supply for "
2558 "of ports.\n\rFirmware halted.\r\n"); 2490 "this number of ports.\nFirmware "
2491 "halted.\n");
2559 } else { 2492 } else {
2560 printk("cyc:Cyclades-Z firmware not yet " 2493 printk(KERN_ERR "cyc:Cyclades-Z firmware not "
2561 "loaded\n"); 2494 "yet loaded\n");
2562 } 2495 }
2563 return -ENODEV; 2496 return -ENODEV;
2564 } 2497 }
@@ -2572,24 +2505,23 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2572 struct BOARD_CTRL __iomem *board_ctrl; 2505 struct BOARD_CTRL __iomem *board_ctrl;
2573 2506
2574 zfw_ctrl = cinfo->base_addr + 2507 zfw_ctrl = cinfo->base_addr +
2575 (cy_readl(&firm_id->zfwctrl_addr) & 2508 (readl(&firm_id->zfwctrl_addr) &
2576 0xfffff); 2509 0xfffff);
2577 2510
2578 board_ctrl = &zfw_ctrl->board_ctrl; 2511 board_ctrl = &zfw_ctrl->board_ctrl;
2579 2512
2580 /* Enable interrupts on the PLX chip */ 2513 /* Enable interrupts on the PLX chip */
2581 cy_writew(cinfo->ctl_addr + 0x68, 2514 cy_writew(cinfo->ctl_addr + 0x68,
2582 cy_readw(cinfo->ctl_addr + 2515 readw(cinfo->ctl_addr + 0x68) | 0x0900);
2583 0x68) | 0x0900);
2584 /* Enable interrupts on the FW */ 2516 /* Enable interrupts on the FW */
2585 retval = cyz_issue_cmd(cinfo, 0, 2517 retval = cyz_issue_cmd(cinfo, 0,
2586 C_CM_IRQ_ENBL, 0L); 2518 C_CM_IRQ_ENBL, 0L);
2587 if (retval != 0) { 2519 if (retval != 0) {
2588 printk("cyc:IRQ enable retval was %x\n", 2520 printk(KERN_ERR "cyc:IRQ enable retval "
2589 retval); 2521 "was %x\n", retval);
2590 } 2522 }
2591 cinfo->nports = 2523 cinfo->nports =
2592 (int)cy_readl(&board_ctrl->n_channel); 2524 (int)readl(&board_ctrl->n_channel);
2593 cinfo->intr_enabled = 1; 2525 cinfo->intr_enabled = 1;
2594 } 2526 }
2595 } 2527 }
@@ -2599,7 +2531,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2599 return -ENODEV; 2531 return -ENODEV;
2600 } 2532 }
2601#ifdef CY_DEBUG_OTHER 2533#ifdef CY_DEBUG_OTHER
2602 printk("cyc:cy_open ttyC%d\n", info->line); /* */ 2534 printk(KERN_DEBUG "cyc:cy_open ttyC%d\n", info->line);
2603#endif 2535#endif
2604 tty->driver_data = info; 2536 tty->driver_data = info;
2605 info->tty = tty; 2537 info->tty = tty;
@@ -2607,12 +2539,12 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2607 return -ENODEV; 2539 return -ENODEV;
2608 } 2540 }
2609#ifdef CY_DEBUG_OPEN 2541#ifdef CY_DEBUG_OPEN
2610 printk("cyc:cy_open ttyC%d, count = %d\n", info->line, info->count); 2542 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
2611 /**/ 2543 info->count);
2612#endif 2544#endif
2613 info->count++; 2545 info->count++;
2614#ifdef CY_DEBUG_COUNT 2546#ifdef CY_DEBUG_COUNT
2615 printk("cyc:cy_open (%d): incrementing count to %d\n", 2547 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
2616 current->pid, info->count); 2548 current->pid, info->count);
2617#endif 2549#endif
2618 2550
@@ -2620,8 +2552,8 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2620 * If the port is the middle of closing, bail out now 2552 * If the port is the middle of closing, bail out now
2621 */ 2553 */
2622 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) { 2554 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2623 if (info->flags & ASYNC_CLOSING) 2555 wait_event_interruptible(info->close_wait,
2624 interruptible_sleep_on(&info->close_wait); 2556 !(info->flags & ASYNC_CLOSING));
2625 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS; 2557 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
2626 } 2558 }
2627 2559
@@ -2636,8 +2568,8 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2636 retval = block_til_ready(tty, filp, info); 2568 retval = block_til_ready(tty, filp, info);
2637 if (retval) { 2569 if (retval) {
2638#ifdef CY_DEBUG_OPEN 2570#ifdef CY_DEBUG_OPEN
2639 printk("cyc:cy_open returning after block_til_ready with %d\n", 2571 printk(KERN_DEBUG "cyc:cy_open returning after block_til_ready "
2640 retval); 2572 "with %d\n", retval);
2641#endif 2573#endif
2642 return retval; 2574 return retval;
2643 } 2575 }
@@ -2645,8 +2577,7 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2645 info->throttle = 0; 2577 info->throttle = 0;
2646 2578
2647#ifdef CY_DEBUG_OPEN 2579#ifdef CY_DEBUG_OPEN
2648 printk(" cyc:cy_open done\n"); 2580 printk(KERN_DEBUG "cyc:cy_open done\n");
2649 /**/
2650#endif 2581#endif
2651 return 0; 2582 return 0;
2652} /* cy_open */ 2583} /* cy_open */
@@ -2656,9 +2587,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
2656 */ 2587 */
2657static void cy_wait_until_sent(struct tty_struct *tty, int timeout) 2588static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2658{ 2589{
2659 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2590 struct cyclades_card *card;
2591 struct cyclades_port *info = tty->driver_data;
2660 void __iomem *base_addr; 2592 void __iomem *base_addr;
2661 int card, chip, channel, index; 2593 int chip, channel, index;
2662 unsigned long orig_jiffies; 2594 unsigned long orig_jiffies;
2663 int char_time; 2595 int char_time;
2664 2596
@@ -2697,20 +2629,19 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2697 if (!timeout || timeout > 2 * info->timeout) 2629 if (!timeout || timeout > 2 * info->timeout)
2698 timeout = 2 * info->timeout; 2630 timeout = 2 * info->timeout;
2699#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2631#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2700 printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time); 2632 printk(KERN_DEBUG "In cy_wait_until_sent(%d) check=%d, jiff=%lu...",
2701 printk("jiff=%lu...", jiffies); 2633 timeout, char_time, jiffies);
2702#endif 2634#endif
2703 card = info->card; 2635 card = info->card;
2704 channel = (info->line) - (cy_card[card].first_line); 2636 channel = (info->line) - (card->first_line);
2705 if (!IS_CYC_Z(cy_card[card])) { 2637 if (!IS_CYC_Z(*card)) {
2706 chip = channel >> 2; 2638 chip = channel >> 2;
2707 channel &= 0x03; 2639 channel &= 0x03;
2708 index = cy_card[card].bus_index; 2640 index = card->bus_index;
2709 base_addr = 2641 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
2710 cy_card[card].base_addr + (cy_chip_offset[chip] << index); 2642 while (readb(base_addr + (CySRER << index)) & CyTxRdy) {
2711 while (cy_readb(base_addr + (CySRER << index)) & CyTxRdy) {
2712#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2643#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2713 printk("Not clean (jiff=%lu)...", jiffies); 2644 printk(KERN_DEBUG "Not clean (jiff=%lu)...", jiffies);
2714#endif 2645#endif
2715 if (msleep_interruptible(jiffies_to_msecs(char_time))) 2646 if (msleep_interruptible(jiffies_to_msecs(char_time)))
2716 break; 2647 break;
@@ -2718,13 +2649,11 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2718 timeout)) 2649 timeout))
2719 break; 2650 break;
2720 } 2651 }
2721 } else {
2722 /* Nothing to do! */
2723 } 2652 }
2724 /* Run one more char cycle */ 2653 /* Run one more char cycle */
2725 msleep_interruptible(jiffies_to_msecs(char_time * 5)); 2654 msleep_interruptible(jiffies_to_msecs(char_time * 5));
2726#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2655#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2727 printk("Clean (jiff=%lu)...done\n", jiffies); 2656 printk(KERN_DEBUG "Clean (jiff=%lu)...done\n", jiffies);
2728#endif 2657#endif
2729} 2658}
2730 2659
@@ -2733,25 +2662,29 @@ static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2733 */ 2662 */
2734static void cy_close(struct tty_struct *tty, struct file *filp) 2663static void cy_close(struct tty_struct *tty, struct file *filp)
2735{ 2664{
2736 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2665 struct cyclades_port *info = tty->driver_data;
2666 struct cyclades_card *card;
2737 unsigned long flags; 2667 unsigned long flags;
2738 2668
2739#ifdef CY_DEBUG_OTHER 2669#ifdef CY_DEBUG_OTHER
2740 printk("cyc:cy_close ttyC%d\n", info->line); 2670 printk(KERN_DEBUG "cyc:cy_close ttyC%d\n", info->line);
2741#endif 2671#endif
2742 2672
2743 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) { 2673 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
2744 return; 2674 return;
2745 } 2675 }
2746 2676
2747 CY_LOCK(info, flags); 2677 card = info->card;
2678
2679 spin_lock_irqsave(&card->card_lock, flags);
2748 /* If the TTY is being hung up, nothing to do */ 2680 /* If the TTY is being hung up, nothing to do */
2749 if (tty_hung_up_p(filp)) { 2681 if (tty_hung_up_p(filp)) {
2750 CY_UNLOCK(info, flags); 2682 spin_unlock_irqrestore(&card->card_lock, flags);
2751 return; 2683 return;
2752 } 2684 }
2753#ifdef CY_DEBUG_OPEN 2685#ifdef CY_DEBUG_OPEN
2754 printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count); 2686 printk(KERN_DEBUG "cyc:cy_close ttyC%d, count = %d\n", info->line,
2687 info->count);
2755#endif 2688#endif
2756 if ((tty->count == 1) && (info->count != 1)) { 2689 if ((tty->count == 1) && (info->count != 1)) {
2757 /* 2690 /*
@@ -2761,22 +2694,22 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
2761 * one, we've got real problems, since it means the 2694 * one, we've got real problems, since it means the
2762 * serial port won't be shutdown. 2695 * serial port won't be shutdown.
2763 */ 2696 */
2764 printk("cyc:cy_close: bad serial port count; tty->count is 1, " 2697 printk(KERN_ERR "cyc:cy_close: bad serial port count; "
2765 "info->count is %d\n", info->count); 2698 "tty->count is 1, info->count is %d\n", info->count);
2766 info->count = 1; 2699 info->count = 1;
2767 } 2700 }
2768#ifdef CY_DEBUG_COUNT 2701#ifdef CY_DEBUG_COUNT
2769 printk("cyc:cy_close at (%d): decrementing count to %d\n", 2702 printk(KERN_DEBUG "cyc:cy_close at (%d): decrementing count to %d\n",
2770 current->pid, info->count - 1); 2703 current->pid, info->count - 1);
2771#endif 2704#endif
2772 if (--info->count < 0) { 2705 if (--info->count < 0) {
2773#ifdef CY_DEBUG_COUNT 2706#ifdef CY_DEBUG_COUNT
2774 printk("cyc:cyc_close setting count to 0\n"); 2707 printk(KERN_DEBUG "cyc:cyc_close setting count to 0\n");
2775#endif 2708#endif
2776 info->count = 0; 2709 info->count = 0;
2777 } 2710 }
2778 if (info->count) { 2711 if (info->count) {
2779 CY_UNLOCK(info, flags); 2712 spin_unlock_irqrestore(&card->card_lock, flags);
2780 return; 2713 return;
2781 } 2714 }
2782 info->flags |= ASYNC_CLOSING; 2715 info->flags |= ASYNC_CLOSING;
@@ -2786,81 +2719,80 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
2786 * the line discipline to only process XON/XOFF characters. 2719 * the line discipline to only process XON/XOFF characters.
2787 */ 2720 */
2788 tty->closing = 1; 2721 tty->closing = 1;
2789 CY_UNLOCK(info, flags); 2722 spin_unlock_irqrestore(&card->card_lock, flags);
2790 if (info->closing_wait != CY_CLOSING_WAIT_NONE) { 2723 if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
2791 tty_wait_until_sent(tty, info->closing_wait); 2724 tty_wait_until_sent(tty, info->closing_wait);
2792 } 2725 }
2793 CY_LOCK(info, flags); 2726 spin_lock_irqsave(&card->card_lock, flags);
2794 2727
2795 if (!IS_CYC_Z(cy_card[info->card])) { 2728 if (!IS_CYC_Z(*card)) {
2796 int channel = info->line - cy_card[info->card].first_line; 2729 int channel = info->line - card->first_line;
2797 int index = cy_card[info->card].bus_index; 2730 int index = card->bus_index;
2798 void __iomem *base_addr = cy_card[info->card].base_addr + 2731 void __iomem *base_addr = card->base_addr +
2799 (cy_chip_offset[channel >> 2] << index); 2732 (cy_chip_offset[channel >> 2] << index);
2800 /* Stop accepting input */ 2733 /* Stop accepting input */
2801 channel &= 0x03; 2734 channel &= 0x03;
2802 cy_writeb(base_addr + (CyCAR << index), (u_char) channel); 2735 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2803 cy_writeb(base_addr + (CySRER << index), 2736 cy_writeb(base_addr + (CySRER << index),
2804 cy_readb(base_addr + (CySRER << index)) & ~CyRxData); 2737 readb(base_addr + (CySRER << index)) & ~CyRxData);
2805 if (info->flags & ASYNC_INITIALIZED) { 2738 if (info->flags & ASYNC_INITIALIZED) {
2806 /* Waiting for on-board buffers to be empty before closing 2739 /* Waiting for on-board buffers to be empty before closing
2807 the port */ 2740 the port */
2808 CY_UNLOCK(info, flags); 2741 spin_unlock_irqrestore(&card->card_lock, flags);
2809 cy_wait_until_sent(tty, info->timeout); 2742 cy_wait_until_sent(tty, info->timeout);
2810 CY_LOCK(info, flags); 2743 spin_lock_irqsave(&card->card_lock, flags);
2811 } 2744 }
2812 } else { 2745 } else {
2813#ifdef Z_WAKE 2746#ifdef Z_WAKE
2814 /* Waiting for on-board buffers to be empty before closing the port */ 2747 /* Waiting for on-board buffers to be empty before closing the port */
2815 void __iomem *base_addr = cy_card[info->card].base_addr; 2748 void __iomem *base_addr = card->base_addr;
2816 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS; 2749 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS;
2817 struct ZFW_CTRL __iomem *zfw_ctrl = 2750 struct ZFW_CTRL __iomem *zfw_ctrl =
2818 base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2751 base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
2819 struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl; 2752 struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
2820 int channel = info->line - cy_card[info->card].first_line; 2753 int channel = info->line - card->first_line;
2821 int retval; 2754 int retval;
2822 2755
2823 if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) { 2756 if (readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) {
2824 retval = cyz_issue_cmd(&cy_card[info->card], channel, 2757 retval = cyz_issue_cmd(card, channel, C_CM_IOCTLW, 0L);
2825 C_CM_IOCTLW, 0L);
2826 if (retval != 0) { 2758 if (retval != 0) {
2827 printk("cyc:cy_close retval on ttyC%d was %x\n", 2759 printk(KERN_DEBUG "cyc:cy_close retval on "
2828 info->line, retval); 2760 "ttyC%d was %x\n", info->line, retval);
2829 } 2761 }
2830 CY_UNLOCK(info, flags); 2762 spin_unlock_irqrestore(&card->card_lock, flags);
2831 interruptible_sleep_on(&info->shutdown_wait); 2763 wait_for_completion_interruptible(&info->shutdown_wait);
2832 CY_LOCK(info, flags); 2764 spin_lock_irqsave(&card->card_lock, flags);
2833 } 2765 }
2834#endif 2766#endif
2835 } 2767 }
2836 2768
2837 CY_UNLOCK(info, flags); 2769 spin_unlock_irqrestore(&card->card_lock, flags);
2838 shutdown(info); 2770 shutdown(info);
2839 if (tty->driver->flush_buffer) 2771 if (tty->driver->flush_buffer)
2840 tty->driver->flush_buffer(tty); 2772 tty->driver->flush_buffer(tty);
2841 tty_ldisc_flush(tty); 2773 tty_ldisc_flush(tty);
2842 CY_LOCK(info, flags); 2774 spin_lock_irqsave(&card->card_lock, flags);
2843 2775
2844 tty->closing = 0; 2776 tty->closing = 0;
2845 info->event = 0; 2777 info->event = 0;
2846 info->tty = NULL; 2778 info->tty = NULL;
2847 if (info->blocked_open) { 2779 if (info->blocked_open) {
2848 CY_UNLOCK(info, flags); 2780 spin_unlock_irqrestore(&card->card_lock, flags);
2849 if (info->close_delay) { 2781 if (info->close_delay) {
2850 msleep_interruptible(jiffies_to_msecs 2782 msleep_interruptible(jiffies_to_msecs
2851 (info->close_delay)); 2783 (info->close_delay));
2852 } 2784 }
2853 wake_up_interruptible(&info->open_wait); 2785 wake_up_interruptible(&info->open_wait);
2854 CY_LOCK(info, flags); 2786 spin_lock_irqsave(&card->card_lock, flags);
2855 } 2787 }
2856 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); 2788 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
2857 wake_up_interruptible(&info->close_wait); 2789 wake_up_interruptible(&info->close_wait);
2858 2790
2859#ifdef CY_DEBUG_OTHER 2791#ifdef CY_DEBUG_OTHER
2860 printk(" cyc:cy_close done\n"); 2792 printk(KERN_DEBUG "cyc:cy_close done\n");
2861#endif 2793#endif
2862 2794
2863 CY_UNLOCK(info, flags); 2795 spin_unlock_irqrestore(&card->card_lock, flags);
2864} /* cy_close */ 2796} /* cy_close */
2865 2797
2866/* This routine gets called when tty_write has put something into 2798/* This routine gets called when tty_write has put something into
@@ -2878,12 +2810,12 @@ static void cy_close(struct tty_struct *tty, struct file *filp)
2878 */ 2810 */
2879static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count) 2811static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2880{ 2812{
2881 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2813 struct cyclades_port *info = tty->driver_data;
2882 unsigned long flags; 2814 unsigned long flags;
2883 int c, ret = 0; 2815 int c, ret = 0;
2884 2816
2885#ifdef CY_DEBUG_IO 2817#ifdef CY_DEBUG_IO
2886 printk("cyc:cy_write ttyC%d\n", info->line); /* */ 2818 printk(KERN_DEBUG "cyc:cy_write ttyC%d\n", info->line);
2887#endif 2819#endif
2888 2820
2889 if (serial_paranoia_check(info, tty->name, "cy_write")) { 2821 if (serial_paranoia_check(info, tty->name, "cy_write")) {
@@ -2893,7 +2825,7 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2893 if (!info->xmit_buf) 2825 if (!info->xmit_buf)
2894 return 0; 2826 return 0;
2895 2827
2896 CY_LOCK(info, flags); 2828 spin_lock_irqsave(&info->card->card_lock, flags);
2897 while (1) { 2829 while (1) {
2898 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1), 2830 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
2899 (int)(SERIAL_XMIT_SIZE - info->xmit_head))); 2831 (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
@@ -2909,7 +2841,7 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2909 count -= c; 2841 count -= c;
2910 ret += c; 2842 ret += c;
2911 } 2843 }
2912 CY_UNLOCK(info, flags); 2844 spin_unlock_irqrestore(&info->card->card_lock, flags);
2913 2845
2914 info->idle_stats.xmit_bytes += ret; 2846 info->idle_stats.xmit_bytes += ret;
2915 info->idle_stats.xmit_idle = jiffies; 2847 info->idle_stats.xmit_idle = jiffies;
@@ -2929,11 +2861,11 @@ static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2929 */ 2861 */
2930static void cy_put_char(struct tty_struct *tty, unsigned char ch) 2862static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2931{ 2863{
2932 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2864 struct cyclades_port *info = tty->driver_data;
2933 unsigned long flags; 2865 unsigned long flags;
2934 2866
2935#ifdef CY_DEBUG_IO 2867#ifdef CY_DEBUG_IO
2936 printk("cyc:cy_put_char ttyC%d\n", info->line); 2868 printk(KERN_DEBUG "cyc:cy_put_char ttyC%d\n", info->line);
2937#endif 2869#endif
2938 2870
2939 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 2871 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
@@ -2942,9 +2874,9 @@ static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2942 if (!info->xmit_buf) 2874 if (!info->xmit_buf)
2943 return; 2875 return;
2944 2876
2945 CY_LOCK(info, flags); 2877 spin_lock_irqsave(&info->card->card_lock, flags);
2946 if (info->xmit_cnt >= (int)(SERIAL_XMIT_SIZE - 1)) { 2878 if (info->xmit_cnt >= (int)(SERIAL_XMIT_SIZE - 1)) {
2947 CY_UNLOCK(info, flags); 2879 spin_unlock_irqrestore(&info->card->card_lock, flags);
2948 return; 2880 return;
2949 } 2881 }
2950 2882
@@ -2953,7 +2885,7 @@ static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2953 info->xmit_cnt++; 2885 info->xmit_cnt++;
2954 info->idle_stats.xmit_bytes++; 2886 info->idle_stats.xmit_bytes++;
2955 info->idle_stats.xmit_idle = jiffies; 2887 info->idle_stats.xmit_idle = jiffies;
2956 CY_UNLOCK(info, flags); 2888 spin_unlock_irqrestore(&info->card->card_lock, flags);
2957} /* cy_put_char */ 2889} /* cy_put_char */
2958 2890
2959/* 2891/*
@@ -2962,10 +2894,10 @@ static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2962 */ 2894 */
2963static void cy_flush_chars(struct tty_struct *tty) 2895static void cy_flush_chars(struct tty_struct *tty)
2964{ 2896{
2965 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2897 struct cyclades_port *info = tty->driver_data;
2966 2898
2967#ifdef CY_DEBUG_IO 2899#ifdef CY_DEBUG_IO
2968 printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */ 2900 printk(KERN_DEBUG "cyc:cy_flush_chars ttyC%d\n", info->line);
2969#endif 2901#endif
2970 2902
2971 if (serial_paranoia_check(info, tty->name, "cy_flush_chars")) 2903 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
@@ -2986,11 +2918,11 @@ static void cy_flush_chars(struct tty_struct *tty)
2986 */ 2918 */
2987static int cy_write_room(struct tty_struct *tty) 2919static int cy_write_room(struct tty_struct *tty)
2988{ 2920{
2989 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2921 struct cyclades_port *info = tty->driver_data;
2990 int ret; 2922 int ret;
2991 2923
2992#ifdef CY_DEBUG_IO 2924#ifdef CY_DEBUG_IO
2993 printk("cyc:cy_write_room ttyC%d\n", info->line); /* */ 2925 printk(KERN_DEBUG "cyc:cy_write_room ttyC%d\n", info->line);
2994#endif 2926#endif
2995 2927
2996 if (serial_paranoia_check(info, tty->name, "cy_write_room")) 2928 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
@@ -3003,46 +2935,49 @@ static int cy_write_room(struct tty_struct *tty)
3003 2935
3004static int cy_chars_in_buffer(struct tty_struct *tty) 2936static int cy_chars_in_buffer(struct tty_struct *tty)
3005{ 2937{
3006 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2938 struct cyclades_card *card;
3007 int card, channel; 2939 struct cyclades_port *info = tty->driver_data;
2940 int channel;
3008 2941
3009 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer")) 2942 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
3010 return 0; 2943 return 0;
3011 2944
3012 card = info->card; 2945 card = info->card;
3013 channel = (info->line) - (cy_card[card].first_line); 2946 channel = (info->line) - (card->first_line);
3014 2947
3015#ifdef Z_EXT_CHARS_IN_BUFFER 2948#ifdef Z_EXT_CHARS_IN_BUFFER
3016 if (!IS_CYC_Z(cy_card[card])) { 2949 if (!IS_CYC_Z(cy_card[card])) {
3017#endif /* Z_EXT_CHARS_IN_BUFFER */ 2950#endif /* Z_EXT_CHARS_IN_BUFFER */
3018#ifdef CY_DEBUG_IO 2951#ifdef CY_DEBUG_IO
3019 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt); /* */ 2952 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n",
2953 info->line, info->xmit_cnt);
3020#endif 2954#endif
3021 return info->xmit_cnt; 2955 return info->xmit_cnt;
3022#ifdef Z_EXT_CHARS_IN_BUFFER 2956#ifdef Z_EXT_CHARS_IN_BUFFER
3023 } else { 2957 } else {
3024 static volatile struct FIRM_ID *firm_id; 2958 static struct FIRM_ID *firm_id;
3025 static volatile struct ZFW_CTRL *zfw_ctrl; 2959 static struct ZFW_CTRL *zfw_ctrl;
3026 static volatile struct CH_CTRL *ch_ctrl; 2960 static struct CH_CTRL *ch_ctrl;
3027 static volatile struct BUF_CTRL *buf_ctrl; 2961 static struct BUF_CTRL *buf_ctrl;
3028 int char_count; 2962 int char_count;
3029 volatile uclong tx_put, tx_get, tx_bufsize; 2963 __u32 tx_put, tx_get, tx_bufsize;
3030 2964
3031 firm_id = cy_card[card].base_addr + ID_ADDRESS; 2965 firm_id = card->base_addr + ID_ADDRESS;
3032 zfw_ctrl = cy_card[card].base_addr + 2966 zfw_ctrl = card->base_addr +
3033 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2967 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3034 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); 2968 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3035 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]); 2969 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
3036 2970
3037 tx_get = cy_readl(&buf_ctrl->tx_get); 2971 tx_get = readl(&buf_ctrl->tx_get);
3038 tx_put = cy_readl(&buf_ctrl->tx_put); 2972 tx_put = readl(&buf_ctrl->tx_put);
3039 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize); 2973 tx_bufsize = readl(&buf_ctrl->tx_bufsize);
3040 if (tx_put >= tx_get) 2974 if (tx_put >= tx_get)
3041 char_count = tx_put - tx_get; 2975 char_count = tx_put - tx_get;
3042 else 2976 else
3043 char_count = tx_put - tx_get + tx_bufsize; 2977 char_count = tx_put - tx_get + tx_bufsize;
3044#ifdef CY_DEBUG_IO 2978#ifdef CY_DEBUG_IO
3045 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt + char_count); /* */ 2979 printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n",
2980 info->line, info->xmit_cnt + char_count);
3046#endif 2981#endif
3047 return info->xmit_cnt + char_count; 2982 return info->xmit_cnt + char_count;
3048 } 2983 }
@@ -3055,10 +2990,10 @@ static int cy_chars_in_buffer(struct tty_struct *tty)
3055 * ------------------------------------------------------------ 2990 * ------------------------------------------------------------
3056 */ 2991 */
3057 2992
3058static void cyy_baud_calc(struct cyclades_port *info, uclong baud) 2993static void cyy_baud_calc(struct cyclades_port *info, __u32 baud)
3059{ 2994{
3060 int co, co_val, bpr; 2995 int co, co_val, bpr;
3061 uclong cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 : 2996 __u32 cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 :
3062 25000000); 2997 25000000);
3063 2998
3064 if (baud == 0) { 2999 if (baud == 0) {
@@ -3086,9 +3021,10 @@ static void cyy_baud_calc(struct cyclades_port *info, uclong baud)
3086 */ 3021 */
3087static void set_line_char(struct cyclades_port *info) 3022static void set_line_char(struct cyclades_port *info)
3088{ 3023{
3024 struct cyclades_card *card;
3089 unsigned long flags; 3025 unsigned long flags;
3090 void __iomem *base_addr; 3026 void __iomem *base_addr;
3091 int card, chip, channel, index; 3027 int chip, channel, index;
3092 unsigned cflag, iflag; 3028 unsigned cflag, iflag;
3093 unsigned short chip_number; 3029 unsigned short chip_number;
3094 int baud, baud_rate = 0; 3030 int baud, baud_rate = 0;
@@ -3118,12 +3054,12 @@ static void set_line_char(struct cyclades_port *info)
3118 } 3054 }
3119 3055
3120 card = info->card; 3056 card = info->card;
3121 channel = (info->line) - (cy_card[card].first_line); 3057 channel = info->line - card->first_line;
3122 chip_number = channel / 4; 3058 chip_number = channel / 4;
3123 3059
3124 if (!IS_CYC_Z(cy_card[card])) { 3060 if (!IS_CYC_Z(*card)) {
3125 3061
3126 index = cy_card[card].bus_index; 3062 index = card->bus_index;
3127 3063
3128 /* baud rate */ 3064 /* baud rate */
3129 baud = tty_get_baud_rate(info->tty); 3065 baud = tty_get_baud_rate(info->tty);
@@ -3241,10 +3177,9 @@ static void set_line_char(struct cyclades_port *info)
3241 3177
3242 chip = channel >> 2; 3178 chip = channel >> 2;
3243 channel &= 0x03; 3179 channel &= 0x03;
3244 base_addr = cy_card[card].base_addr + 3180 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
3245 (cy_chip_offset[chip] << index);
3246 3181
3247 CY_LOCK(info, flags); 3182 spin_lock_irqsave(&card->card_lock, flags);
3248 cy_writeb(base_addr + (CyCAR << index), (u_char) channel); 3183 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3249 3184
3250 /* tx and rx baud rate */ 3185 /* tx and rx baud rate */
@@ -3276,8 +3211,7 @@ static void set_line_char(struct cyclades_port *info)
3276 if (C_CLOCAL(info->tty)) { 3211 if (C_CLOCAL(info->tty)) {
3277 /* without modem intr */ 3212 /* without modem intr */
3278 cy_writeb(base_addr + (CySRER << index), 3213 cy_writeb(base_addr + (CySRER << index),
3279 cy_readb(base_addr + 3214 readb(base_addr + (CySRER << index)) | CyMdmCh);
3280 (CySRER << index)) | CyMdmCh);
3281 /* act on 1->0 modem transitions */ 3215 /* act on 1->0 modem transitions */
3282 if ((cflag & CRTSCTS) && info->rflow) { 3216 if ((cflag & CRTSCTS) && info->rflow) {
3283 cy_writeb(base_addr + (CyMCOR1 << index), 3217 cy_writeb(base_addr + (CyMCOR1 << index),
@@ -3291,7 +3225,7 @@ static void set_line_char(struct cyclades_port *info)
3291 } else { 3225 } else {
3292 /* without modem intr */ 3226 /* without modem intr */
3293 cy_writeb(base_addr + (CySRER << index), 3227 cy_writeb(base_addr + (CySRER << index),
3294 cy_readb(base_addr + 3228 readb(base_addr +
3295 (CySRER << index)) | CyMdmCh); 3229 (CySRER << index)) | CyMdmCh);
3296 /* act on 1->0 modem transitions */ 3230 /* act on 1->0 modem transitions */
3297 if ((cflag & CRTSCTS) && info->rflow) { 3231 if ((cflag & CRTSCTS) && info->rflow) {
@@ -3316,10 +3250,10 @@ static void set_line_char(struct cyclades_port *info)
3316 ~CyDTR); 3250 ~CyDTR);
3317 } 3251 }
3318#ifdef CY_DEBUG_DTR 3252#ifdef CY_DEBUG_DTR
3319 printk("cyc:set_line_char dropping DTR\n"); 3253 printk(KERN_DEBUG "cyc:set_line_char dropping DTR\n");
3320 printk(" status: 0x%x, 0x%x\n", 3254 printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
3321 cy_readb(base_addr + (CyMSVR1 << index)), 3255 readb(base_addr + (CyMSVR1 << index)),
3322 cy_readb(base_addr + (CyMSVR2 << index))); 3256 readb(base_addr + (CyMSVR2 << index)));
3323#endif 3257#endif
3324 } else { 3258 } else {
3325 if (info->rtsdtr_inv) { 3259 if (info->rtsdtr_inv) {
@@ -3330,17 +3264,17 @@ static void set_line_char(struct cyclades_port *info)
3330 CyDTR); 3264 CyDTR);
3331 } 3265 }
3332#ifdef CY_DEBUG_DTR 3266#ifdef CY_DEBUG_DTR
3333 printk("cyc:set_line_char raising DTR\n"); 3267 printk(KERN_DEBUG "cyc:set_line_char raising DTR\n");
3334 printk(" status: 0x%x, 0x%x\n", 3268 printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
3335 cy_readb(base_addr + (CyMSVR1 << index)), 3269 readb(base_addr + (CyMSVR1 << index)),
3336 cy_readb(base_addr + (CyMSVR2 << index))); 3270 readb(base_addr + (CyMSVR2 << index)));
3337#endif 3271#endif
3338 } 3272 }
3339 3273
3340 if (info->tty) { 3274 if (info->tty) {
3341 clear_bit(TTY_IO_ERROR, &info->tty->flags); 3275 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3342 } 3276 }
3343 CY_UNLOCK(info, flags); 3277 spin_unlock_irqrestore(&card->card_lock, flags);
3344 3278
3345 } else { 3279 } else {
3346 struct FIRM_ID __iomem *firm_id; 3280 struct FIRM_ID __iomem *firm_id;
@@ -3348,16 +3282,16 @@ static void set_line_char(struct cyclades_port *info)
3348 struct BOARD_CTRL __iomem *board_ctrl; 3282 struct BOARD_CTRL __iomem *board_ctrl;
3349 struct CH_CTRL __iomem *ch_ctrl; 3283 struct CH_CTRL __iomem *ch_ctrl;
3350 struct BUF_CTRL __iomem *buf_ctrl; 3284 struct BUF_CTRL __iomem *buf_ctrl;
3351 uclong sw_flow; 3285 __u32 sw_flow;
3352 int retval; 3286 int retval;
3353 3287
3354 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3288 firm_id = card->base_addr + ID_ADDRESS;
3355 if (!ISZLOADED(cy_card[card])) { 3289 if (!ISZLOADED(*card)) {
3356 return; 3290 return;
3357 } 3291 }
3358 3292
3359 zfw_ctrl = cy_card[card].base_addr + 3293 zfw_ctrl = card->base_addr +
3360 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3294 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3361 board_ctrl = &zfw_ctrl->board_ctrl; 3295 board_ctrl = &zfw_ctrl->board_ctrl;
3362 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); 3296 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3363 buf_ctrl = &zfw_ctrl->buf_ctrl[channel]; 3297 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
@@ -3408,10 +3342,10 @@ static void set_line_char(struct cyclades_port *info)
3408 } 3342 }
3409 if (cflag & CSTOPB) { 3343 if (cflag & CSTOPB) {
3410 cy_writel(&ch_ctrl->comm_data_l, 3344 cy_writel(&ch_ctrl->comm_data_l,
3411 cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP); 3345 readl(&ch_ctrl->comm_data_l) | C_DL_2STOP);
3412 } else { 3346 } else {
3413 cy_writel(&ch_ctrl->comm_data_l, 3347 cy_writel(&ch_ctrl->comm_data_l,
3414 cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP); 3348 readl(&ch_ctrl->comm_data_l) | C_DL_1STOP);
3415 } 3349 }
3416 if (cflag & PARENB) { 3350 if (cflag & PARENB) {
3417 if (cflag & PARODD) { 3351 if (cflag & PARODD) {
@@ -3426,12 +3360,10 @@ static void set_line_char(struct cyclades_port *info)
3426 /* CTS flow control flag */ 3360 /* CTS flow control flag */
3427 if (cflag & CRTSCTS) { 3361 if (cflag & CRTSCTS) {
3428 cy_writel(&ch_ctrl->hw_flow, 3362 cy_writel(&ch_ctrl->hw_flow,
3429 cy_readl(&ch_ctrl-> 3363 readl(&ch_ctrl->hw_flow) | C_RS_CTS | C_RS_RTS);
3430 hw_flow) | C_RS_CTS | C_RS_RTS);
3431 } else { 3364 } else {
3432 cy_writel(&ch_ctrl->hw_flow, 3365 cy_writel(&ch_ctrl->hw_flow, readl(&ch_ctrl->hw_flow) &
3433 cy_readl(&ch_ctrl-> 3366 ~(C_RS_CTS | C_RS_RTS));
3434 hw_flow) & ~(C_RS_CTS | C_RS_RTS));
3435 } 3367 }
3436 /* As the HW flow control is done in firmware, the driver 3368 /* As the HW flow control is done in firmware, the driver
3437 doesn't need to care about it */ 3369 doesn't need to care about it */
@@ -3446,10 +3378,10 @@ static void set_line_char(struct cyclades_port *info)
3446 } 3378 }
3447 cy_writel(&ch_ctrl->sw_flow, sw_flow); 3379 cy_writel(&ch_ctrl->sw_flow, sw_flow);
3448 3380
3449 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L); 3381 retval = cyz_issue_cmd(card, channel, C_CM_IOCTL, 0L);
3450 if (retval != 0) { 3382 if (retval != 0) {
3451 printk("cyc:set_line_char retval on ttyC%d was %x\n", 3383 printk(KERN_ERR "cyc:set_line_char retval on ttyC%d "
3452 info->line, retval); 3384 "was %x\n", info->line, retval);
3453 } 3385 }
3454 3386
3455 /* CD sensitivity */ 3387 /* CD sensitivity */
@@ -3461,22 +3393,22 @@ static void set_line_char(struct cyclades_port *info)
3461 3393
3462 if (baud == 0) { /* baud rate is zero, turn off line */ 3394 if (baud == 0) { /* baud rate is zero, turn off line */
3463 cy_writel(&ch_ctrl->rs_control, 3395 cy_writel(&ch_ctrl->rs_control,
3464 cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR); 3396 readl(&ch_ctrl->rs_control) & ~C_RS_DTR);
3465#ifdef CY_DEBUG_DTR 3397#ifdef CY_DEBUG_DTR
3466 printk("cyc:set_line_char dropping Z DTR\n"); 3398 printk(KERN_DEBUG "cyc:set_line_char dropping Z DTR\n");
3467#endif 3399#endif
3468 } else { 3400 } else {
3469 cy_writel(&ch_ctrl->rs_control, 3401 cy_writel(&ch_ctrl->rs_control,
3470 cy_readl(&ch_ctrl->rs_control) | C_RS_DTR); 3402 readl(&ch_ctrl->rs_control) | C_RS_DTR);
3471#ifdef CY_DEBUG_DTR 3403#ifdef CY_DEBUG_DTR
3472 printk("cyc:set_line_char raising Z DTR\n"); 3404 printk(KERN_DEBUG "cyc:set_line_char raising Z DTR\n");
3473#endif 3405#endif
3474 } 3406 }
3475 3407
3476 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTLM,0L); 3408 retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM,0L);
3477 if (retval != 0) { 3409 if (retval != 0) {
3478 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n", 3410 printk(KERN_ERR "cyc:set_line_char(2) retval on ttyC%d "
3479 info->line, retval); 3411 "was %x\n", info->line, retval);
3480 } 3412 }
3481 3413
3482 if (info->tty) { 3414 if (info->tty) {
@@ -3490,14 +3422,15 @@ get_serial_info(struct cyclades_port *info,
3490 struct serial_struct __user * retinfo) 3422 struct serial_struct __user * retinfo)
3491{ 3423{
3492 struct serial_struct tmp; 3424 struct serial_struct tmp;
3493 struct cyclades_card *cinfo = &cy_card[info->card]; 3425 struct cyclades_card *cinfo = info->card;
3494 3426
3495 if (!retinfo) 3427 if (!retinfo)
3496 return -EFAULT; 3428 return -EFAULT;
3497 memset(&tmp, 0, sizeof(tmp)); 3429 memset(&tmp, 0, sizeof(tmp));
3498 tmp.type = info->type; 3430 tmp.type = info->type;
3499 tmp.line = info->line; 3431 tmp.line = info->line;
3500 tmp.port = info->card * 0x100 + info->line - cinfo->first_line; 3432 tmp.port = (info->card - cy_card) * 0x100 + info->line -
3433 cinfo->first_line;
3501 tmp.irq = cinfo->irq; 3434 tmp.irq = cinfo->irq;
3502 tmp.flags = info->flags; 3435 tmp.flags = info->flags;
3503 tmp.close_delay = info->close_delay; 3436 tmp.close_delay = info->close_delay;
@@ -3566,25 +3499,25 @@ check_and_exit:
3566 */ 3499 */
3567static int get_lsr_info(struct cyclades_port *info, unsigned int __user * value) 3500static int get_lsr_info(struct cyclades_port *info, unsigned int __user * value)
3568{ 3501{
3569 int card, chip, channel, index; 3502 struct cyclades_card *card;
3503 int chip, channel, index;
3570 unsigned char status; 3504 unsigned char status;
3571 unsigned int result; 3505 unsigned int result;
3572 unsigned long flags; 3506 unsigned long flags;
3573 void __iomem *base_addr; 3507 void __iomem *base_addr;
3574 3508
3575 card = info->card; 3509 card = info->card;
3576 channel = (info->line) - (cy_card[card].first_line); 3510 channel = (info->line) - (card->first_line);
3577 if (!IS_CYC_Z(cy_card[card])) { 3511 if (!IS_CYC_Z(*card)) {
3578 chip = channel >> 2; 3512 chip = channel >> 2;
3579 channel &= 0x03; 3513 channel &= 0x03;
3580 index = cy_card[card].bus_index; 3514 index = card->bus_index;
3581 base_addr = 3515 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
3582 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3583 3516
3584 CY_LOCK(info, flags); 3517 spin_lock_irqsave(&card->card_lock, flags);
3585 status = cy_readb(base_addr + (CySRER << index)) & 3518 status = readb(base_addr + (CySRER << index)) &
3586 (CyTxRdy | CyTxMpty); 3519 (CyTxRdy | CyTxMpty);
3587 CY_UNLOCK(info, flags); 3520 spin_unlock_irqrestore(&card->card_lock, flags);
3588 result = (status ? 0 : TIOCSER_TEMT); 3521 result = (status ? 0 : TIOCSER_TEMT);
3589 } else { 3522 } else {
3590 /* Not supported yet */ 3523 /* Not supported yet */
@@ -3595,8 +3528,9 @@ static int get_lsr_info(struct cyclades_port *info, unsigned int __user * value)
3595 3528
3596static int cy_tiocmget(struct tty_struct *tty, struct file *file) 3529static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3597{ 3530{
3598 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 3531 struct cyclades_port *info = tty->driver_data;
3599 int card, chip, channel, index; 3532 struct cyclades_card *card;
3533 int chip, channel, index;
3600 void __iomem *base_addr; 3534 void __iomem *base_addr;
3601 unsigned long flags; 3535 unsigned long flags;
3602 unsigned char status; 3536 unsigned char status;
@@ -3611,19 +3545,18 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3611 return -ENODEV; 3545 return -ENODEV;
3612 3546
3613 card = info->card; 3547 card = info->card;
3614 channel = (info->line) - (cy_card[card].first_line); 3548 channel = info->line - card->first_line;
3615 if (!IS_CYC_Z(cy_card[card])) { 3549 if (!IS_CYC_Z(*card)) {
3616 chip = channel >> 2; 3550 chip = channel >> 2;
3617 channel &= 0x03; 3551 channel &= 0x03;
3618 index = cy_card[card].bus_index; 3552 index = card->bus_index;
3619 base_addr = 3553 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
3620 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3621 3554
3622 CY_LOCK(info, flags); 3555 spin_lock_irqsave(&card->card_lock, flags);
3623 cy_writeb(base_addr + (CyCAR << index), (u_char) channel); 3556 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3624 status = cy_readb(base_addr + (CyMSVR1 << index)); 3557 status = readb(base_addr + (CyMSVR1 << index));
3625 status |= cy_readb(base_addr + (CyMSVR2 << index)); 3558 status |= readb(base_addr + (CyMSVR2 << index));
3626 CY_UNLOCK(info, flags); 3559 spin_unlock_irqrestore(&card->card_lock, flags);
3627 3560
3628 if (info->rtsdtr_inv) { 3561 if (info->rtsdtr_inv) {
3629 result = ((status & CyRTS) ? TIOCM_DTR : 0) | 3562 result = ((status & CyRTS) ? TIOCM_DTR : 0) |
@@ -3637,19 +3570,14 @@ static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3637 ((status & CyDSR) ? TIOCM_DSR : 0) | 3570 ((status & CyDSR) ? TIOCM_DSR : 0) |
3638 ((status & CyCTS) ? TIOCM_CTS : 0); 3571 ((status & CyCTS) ? TIOCM_CTS : 0);
3639 } else { 3572 } else {
3640 base_addr = cy_card[card].base_addr; 3573 base_addr = card->base_addr;
3641 3574 firm_id = card->base_addr + ID_ADDRESS;
3642 if (cy_card[card].num_chips != -1) { 3575 if (ISZLOADED(*card)) {
3643 return -EINVAL; 3576 zfw_ctrl = card->base_addr +
3644 } 3577 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3645
3646 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3647 if (ISZLOADED(cy_card[card])) {
3648 zfw_ctrl = cy_card[card].base_addr +
3649 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3650 board_ctrl = &zfw_ctrl->board_ctrl; 3578 board_ctrl = &zfw_ctrl->board_ctrl;
3651 ch_ctrl = zfw_ctrl->ch_ctrl; 3579 ch_ctrl = zfw_ctrl->ch_ctrl;
3652 lstatus = cy_readl(&ch_ctrl[channel].rs_status); 3580 lstatus = readl(&ch_ctrl[channel].rs_status);
3653 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0) | 3581 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0) |
3654 ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0) | 3582 ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0) |
3655 ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0) | 3583 ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0) |
@@ -3669,8 +3597,9 @@ static int
3669cy_tiocmset(struct tty_struct *tty, struct file *file, 3597cy_tiocmset(struct tty_struct *tty, struct file *file,
3670 unsigned int set, unsigned int clear) 3598 unsigned int set, unsigned int clear)
3671{ 3599{
3672 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 3600 struct cyclades_port *info = tty->driver_data;
3673 int card, chip, channel, index; 3601 struct cyclades_card *card;
3602 int chip, channel, index;
3674 void __iomem *base_addr; 3603 void __iomem *base_addr;
3675 unsigned long flags; 3604 unsigned long flags;
3676 struct FIRM_ID __iomem *firm_id; 3605 struct FIRM_ID __iomem *firm_id;
@@ -3683,16 +3612,15 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3683 return -ENODEV; 3612 return -ENODEV;
3684 3613
3685 card = info->card; 3614 card = info->card;
3686 channel = (info->line) - (cy_card[card].first_line); 3615 channel = (info->line) - (card->first_line);
3687 if (!IS_CYC_Z(cy_card[card])) { 3616 if (!IS_CYC_Z(*card)) {
3688 chip = channel >> 2; 3617 chip = channel >> 2;
3689 channel &= 0x03; 3618 channel &= 0x03;
3690 index = cy_card[card].bus_index; 3619 index = card->bus_index;
3691 base_addr = 3620 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
3692 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3693 3621
3694 if (set & TIOCM_RTS) { 3622 if (set & TIOCM_RTS) {
3695 CY_LOCK(info, flags); 3623 spin_lock_irqsave(&card->card_lock, flags);
3696 cy_writeb(base_addr + (CyCAR << index), 3624 cy_writeb(base_addr + (CyCAR << index),
3697 (u_char) channel); 3625 (u_char) channel);
3698 if (info->rtsdtr_inv) { 3626 if (info->rtsdtr_inv) {
@@ -3702,10 +3630,10 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3702 cy_writeb(base_addr + (CyMSVR1 << index), 3630 cy_writeb(base_addr + (CyMSVR1 << index),
3703 CyRTS); 3631 CyRTS);
3704 } 3632 }
3705 CY_UNLOCK(info, flags); 3633 spin_unlock_irqrestore(&card->card_lock, flags);
3706 } 3634 }
3707 if (clear & TIOCM_RTS) { 3635 if (clear & TIOCM_RTS) {
3708 CY_LOCK(info, flags); 3636 spin_lock_irqsave(&card->card_lock, flags);
3709 cy_writeb(base_addr + (CyCAR << index), 3637 cy_writeb(base_addr + (CyCAR << index),
3710 (u_char) channel); 3638 (u_char) channel);
3711 if (info->rtsdtr_inv) { 3639 if (info->rtsdtr_inv) {
@@ -3715,10 +3643,10 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3715 cy_writeb(base_addr + (CyMSVR1 << index), 3643 cy_writeb(base_addr + (CyMSVR1 << index),
3716 ~CyRTS); 3644 ~CyRTS);
3717 } 3645 }
3718 CY_UNLOCK(info, flags); 3646 spin_unlock_irqrestore(&card->card_lock, flags);
3719 } 3647 }
3720 if (set & TIOCM_DTR) { 3648 if (set & TIOCM_DTR) {
3721 CY_LOCK(info, flags); 3649 spin_lock_irqsave(&card->card_lock, flags);
3722 cy_writeb(base_addr + (CyCAR << index), 3650 cy_writeb(base_addr + (CyCAR << index),
3723 (u_char) channel); 3651 (u_char) channel);
3724 if (info->rtsdtr_inv) { 3652 if (info->rtsdtr_inv) {
@@ -3729,15 +3657,15 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3729 CyDTR); 3657 CyDTR);
3730 } 3658 }
3731#ifdef CY_DEBUG_DTR 3659#ifdef CY_DEBUG_DTR
3732 printk("cyc:set_modem_info raising DTR\n"); 3660 printk(KERN_DEBUG "cyc:set_modem_info raising DTR\n");
3733 printk(" status: 0x%x, 0x%x\n", 3661 printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
3734 cy_readb(base_addr + (CyMSVR1 << index)), 3662 readb(base_addr + (CyMSVR1 << index)),
3735 cy_readb(base_addr + (CyMSVR2 << index))); 3663 readb(base_addr + (CyMSVR2 << index)));
3736#endif 3664#endif
3737 CY_UNLOCK(info, flags); 3665 spin_unlock_irqrestore(&card->card_lock, flags);
3738 } 3666 }
3739 if (clear & TIOCM_DTR) { 3667 if (clear & TIOCM_DTR) {
3740 CY_LOCK(info, flags); 3668 spin_lock_irqsave(&card->card_lock, flags);
3741 cy_writeb(base_addr + (CyCAR << index), 3669 cy_writeb(base_addr + (CyCAR << index),
3742 (u_char) channel); 3670 (u_char) channel);
3743 if (info->rtsdtr_inv) { 3671 if (info->rtsdtr_inv) {
@@ -3749,68 +3677,69 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3749 } 3677 }
3750 3678
3751#ifdef CY_DEBUG_DTR 3679#ifdef CY_DEBUG_DTR
3752 printk("cyc:set_modem_info dropping DTR\n"); 3680 printk(KERN_DEBUG "cyc:set_modem_info dropping DTR\n");
3753 printk(" status: 0x%x, 0x%x\n", 3681 printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
3754 cy_readb(base_addr + (CyMSVR1 << index)), 3682 readb(base_addr + (CyMSVR1 << index)),
3755 cy_readb(base_addr + (CyMSVR2 << index))); 3683 readb(base_addr + (CyMSVR2 << index)));
3756#endif 3684#endif
3757 CY_UNLOCK(info, flags); 3685 spin_unlock_irqrestore(&card->card_lock, flags);
3758 } 3686 }
3759 } else { 3687 } else {
3760 base_addr = cy_card[card].base_addr; 3688 base_addr = card->base_addr;
3761 3689
3762 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3690 firm_id = card->base_addr + ID_ADDRESS;
3763 if (ISZLOADED(cy_card[card])) { 3691 if (ISZLOADED(*card)) {
3764 zfw_ctrl = cy_card[card].base_addr + 3692 zfw_ctrl = card->base_addr +
3765 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3693 (readl(&firm_id->zfwctrl_addr) & 0xfffff);
3766 board_ctrl = &zfw_ctrl->board_ctrl; 3694 board_ctrl = &zfw_ctrl->board_ctrl;
3767 ch_ctrl = zfw_ctrl->ch_ctrl; 3695 ch_ctrl = zfw_ctrl->ch_ctrl;
3768 3696
3769 if (set & TIOCM_RTS) { 3697 if (set & TIOCM_RTS) {
3770 CY_LOCK(info, flags); 3698 spin_lock_irqsave(&card->card_lock, flags);
3771 cy_writel(&ch_ctrl[channel].rs_control, 3699 cy_writel(&ch_ctrl[channel].rs_control,
3772 cy_readl(&ch_ctrl[channel]. 3700 readl(&ch_ctrl[channel].rs_control) |
3773 rs_control) | C_RS_RTS); 3701 C_RS_RTS);
3774 CY_UNLOCK(info, flags); 3702 spin_unlock_irqrestore(&card->card_lock, flags);
3775 } 3703 }
3776 if (clear & TIOCM_RTS) { 3704 if (clear & TIOCM_RTS) {
3777 CY_LOCK(info, flags); 3705 spin_lock_irqsave(&card->card_lock, flags);
3778 cy_writel(&ch_ctrl[channel].rs_control, 3706 cy_writel(&ch_ctrl[channel].rs_control,
3779 cy_readl(&ch_ctrl[channel]. 3707 readl(&ch_ctrl[channel].rs_control) &
3780 rs_control) & ~C_RS_RTS); 3708 ~C_RS_RTS);
3781 CY_UNLOCK(info, flags); 3709 spin_unlock_irqrestore(&card->card_lock, flags);
3782 } 3710 }
3783 if (set & TIOCM_DTR) { 3711 if (set & TIOCM_DTR) {
3784 CY_LOCK(info, flags); 3712 spin_lock_irqsave(&card->card_lock, flags);
3785 cy_writel(&ch_ctrl[channel].rs_control, 3713 cy_writel(&ch_ctrl[channel].rs_control,
3786 cy_readl(&ch_ctrl[channel]. 3714 readl(&ch_ctrl[channel].rs_control) |
3787 rs_control) | C_RS_DTR); 3715 C_RS_DTR);
3788#ifdef CY_DEBUG_DTR 3716#ifdef CY_DEBUG_DTR
3789 printk("cyc:set_modem_info raising Z DTR\n"); 3717 printk(KERN_DEBUG "cyc:set_modem_info raising "
3718 "Z DTR\n");
3790#endif 3719#endif
3791 CY_UNLOCK(info, flags); 3720 spin_unlock_irqrestore(&card->card_lock, flags);
3792 } 3721 }
3793 if (clear & TIOCM_DTR) { 3722 if (clear & TIOCM_DTR) {
3794 CY_LOCK(info, flags); 3723 spin_lock_irqsave(&card->card_lock, flags);
3795 cy_writel(&ch_ctrl[channel].rs_control, 3724 cy_writel(&ch_ctrl[channel].rs_control,
3796 cy_readl(&ch_ctrl[channel]. 3725 readl(&ch_ctrl[channel].rs_control) &
3797 rs_control) & ~C_RS_DTR); 3726 ~C_RS_DTR);
3798#ifdef CY_DEBUG_DTR 3727#ifdef CY_DEBUG_DTR
3799 printk("cyc:set_modem_info clearing Z DTR\n"); 3728 printk(KERN_DEBUG "cyc:set_modem_info clearing "
3729 "Z DTR\n");
3800#endif 3730#endif
3801 CY_UNLOCK(info, flags); 3731 spin_unlock_irqrestore(&card->card_lock, flags);
3802 } 3732 }
3803 } else { 3733 } else {
3804 return -ENODEV; 3734 return -ENODEV;
3805 } 3735 }
3806 CY_LOCK(info, flags); 3736 spin_lock_irqsave(&card->card_lock, flags);
3807 retval = cyz_issue_cmd(&cy_card[info->card], 3737 retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM, 0L);
3808 channel, C_CM_IOCTLM, 0L);
3809 if (retval != 0) { 3738 if (retval != 0) {
3810 printk("cyc:set_modem_info retval on ttyC%d was %x\n", 3739 printk(KERN_ERR "cyc:set_modem_info retval on ttyC%d "
3811 info->line, retval); 3740 "was %x\n", info->line, retval);
3812 } 3741 }
3813 CY_UNLOCK(info, flags); 3742 spin_unlock_irqrestore(&card->card_lock, flags);
3814 } 3743 }
3815 return 0; 3744 return 0;
3816} /* cy_tiocmset */ 3745} /* cy_tiocmset */
@@ -3820,14 +3749,17 @@ cy_tiocmset(struct tty_struct *tty, struct file *file,
3820 */ 3749 */
3821static void cy_break(struct tty_struct *tty, int break_state) 3750static void cy_break(struct tty_struct *tty, int break_state)
3822{ 3751{
3823 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 3752 struct cyclades_port *info = tty->driver_data;
3753 struct cyclades_card *card;
3824 unsigned long flags; 3754 unsigned long flags;
3825 3755
3826 if (serial_paranoia_check(info, tty->name, "cy_break")) 3756 if (serial_paranoia_check(info, tty->name, "cy_break"))
3827 return; 3757 return;
3828 3758
3829 CY_LOCK(info, flags); 3759 card = info->card;
3830 if (!IS_CYC_Z(cy_card[info->card])) { 3760
3761 spin_lock_irqsave(&card->card_lock, flags);
3762 if (!IS_CYC_Z(*card)) {
3831 /* Let the transmit ISR take care of this (since it 3763 /* Let the transmit ISR take care of this (since it
3832 requires stuffing characters into the output stream). 3764 requires stuffing characters into the output stream).
3833 */ 3765 */
@@ -3835,18 +3767,18 @@ static void cy_break(struct tty_struct *tty, int break_state)
3835 if (!info->breakon) { 3767 if (!info->breakon) {
3836 info->breakon = 1; 3768 info->breakon = 1;
3837 if (!info->xmit_cnt) { 3769 if (!info->xmit_cnt) {
3838 CY_UNLOCK(info, flags); 3770 spin_unlock_irqrestore(&card->card_lock, flags);
3839 start_xmit(info); 3771 start_xmit(info);
3840 CY_LOCK(info, flags); 3772 spin_lock_irqsave(&card->card_lock, flags);
3841 } 3773 }
3842 } 3774 }
3843 } else { 3775 } else {
3844 if (!info->breakoff) { 3776 if (!info->breakoff) {
3845 info->breakoff = 1; 3777 info->breakoff = 1;
3846 if (!info->xmit_cnt) { 3778 if (!info->xmit_cnt) {
3847 CY_UNLOCK(info, flags); 3779 spin_unlock_irqrestore(&card->card_lock, flags);
3848 start_xmit(info); 3780 start_xmit(info);
3849 CY_LOCK(info, flags); 3781 spin_lock_irqsave(&card->card_lock, flags);
3850 } 3782 }
3851 } 3783 }
3852 } 3784 }
@@ -3854,24 +3786,25 @@ static void cy_break(struct tty_struct *tty, int break_state)
3854 int retval; 3786 int retval;
3855 3787
3856 if (break_state == -1) { 3788 if (break_state == -1) {
3857 retval = cyz_issue_cmd(&cy_card[info->card], 3789 retval = cyz_issue_cmd(card,
3858 info->line - cy_card[info->card].first_line, 3790 info->line - card->first_line,
3859 C_CM_SET_BREAK, 0L); 3791 C_CM_SET_BREAK, 0L);
3860 if (retval != 0) { 3792 if (retval != 0) {
3861 printk("cyc:cy_break (set) retval on ttyC%d " 3793 printk(KERN_ERR "cyc:cy_break (set) retval on "
3862 "was %x\n", info->line, retval); 3794 "ttyC%d was %x\n", info->line, retval);
3863 } 3795 }
3864 } else { 3796 } else {
3865 retval = cyz_issue_cmd(&cy_card[info->card], 3797 retval = cyz_issue_cmd(card,
3866 info->line - cy_card[info->card].first_line, 3798 info->line - card->first_line,
3867 C_CM_CLR_BREAK, 0L); 3799 C_CM_CLR_BREAK, 0L);
3868 if (retval != 0) { 3800 if (retval != 0) {
3869 printk("cyc:cy_break (clr) retval on ttyC%d " 3801 printk(KERN_DEBUG "cyc:cy_break (clr) retval "
3870 "was %x\n", info->line, retval); 3802 "on ttyC%d was %x\n", info->line,
3803 retval);
3871 } 3804 }
3872 } 3805 }
3873 } 3806 }
3874 CY_UNLOCK(info, flags); 3807 spin_unlock_irqrestore(&card->card_lock, flags);
3875} /* cy_break */ 3808} /* cy_break */
3876 3809
3877static int 3810static int
@@ -3889,28 +3822,27 @@ get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
3889 3822
3890static int set_threshold(struct cyclades_port *info, unsigned long value) 3823static int set_threshold(struct cyclades_port *info, unsigned long value)
3891{ 3824{
3825 struct cyclades_card *card;
3892 void __iomem *base_addr; 3826 void __iomem *base_addr;
3893 int card, channel, chip, index; 3827 int channel, chip, index;
3894 unsigned long flags; 3828 unsigned long flags;
3895 3829
3896 card = info->card; 3830 card = info->card;
3897 channel = info->line - cy_card[card].first_line; 3831 channel = info->line - card->first_line;
3898 if (!IS_CYC_Z(cy_card[card])) { 3832 if (!IS_CYC_Z(*card)) {
3899 chip = channel >> 2; 3833 chip = channel >> 2;
3900 channel &= 0x03; 3834 channel &= 0x03;
3901 index = cy_card[card].bus_index; 3835 index = card->bus_index;
3902 base_addr = 3836 base_addr =
3903 cy_card[card].base_addr + (cy_chip_offset[chip] << index); 3837 card->base_addr + (cy_chip_offset[chip] << index);
3904 3838
3905 info->cor3 &= ~CyREC_FIFO; 3839 info->cor3 &= ~CyREC_FIFO;
3906 info->cor3 |= value & CyREC_FIFO; 3840 info->cor3 |= value & CyREC_FIFO;
3907 3841
3908 CY_LOCK(info, flags); 3842 spin_lock_irqsave(&card->card_lock, flags);
3909 cy_writeb(base_addr + (CyCOR3 << index), info->cor3); 3843 cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
3910 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR3ch, index); 3844 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR3ch, index);
3911 CY_UNLOCK(info, flags); 3845 spin_unlock_irqrestore(&card->card_lock, flags);
3912 } else {
3913 /* Nothing to do! */
3914 } 3846 }
3915 return 0; 3847 return 0;
3916} /* set_threshold */ 3848} /* set_threshold */
@@ -3918,25 +3850,23 @@ static int set_threshold(struct cyclades_port *info, unsigned long value)
3918static int 3850static int
3919get_threshold(struct cyclades_port *info, unsigned long __user * value) 3851get_threshold(struct cyclades_port *info, unsigned long __user * value)
3920{ 3852{
3853 struct cyclades_card *card;
3921 void __iomem *base_addr; 3854 void __iomem *base_addr;
3922 int card, channel, chip, index; 3855 int channel, chip, index;
3923 unsigned long tmp; 3856 unsigned long tmp;
3924 3857
3925 card = info->card; 3858 card = info->card;
3926 channel = info->line - cy_card[card].first_line; 3859 channel = info->line - card->first_line;
3927 if (!IS_CYC_Z(cy_card[card])) { 3860 if (!IS_CYC_Z(*card)) {
3928 chip = channel >> 2; 3861 chip = channel >> 2;
3929 channel &= 0x03; 3862 channel &= 0x03;
3930 index = cy_card[card].bus_index; 3863 index = card->bus_index;
3931 base_addr = 3864 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
3932 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3933 3865
3934 tmp = cy_readb(base_addr + (CyCOR3 << index)) & CyREC_FIFO; 3866 tmp = readb(base_addr + (CyCOR3 << index)) & CyREC_FIFO;
3935 return put_user(tmp, value); 3867 return put_user(tmp, value);
3936 } else {
3937 /* Nothing to do! */
3938 return 0;
3939 } 3868 }
3869 return 0;
3940} /* get_threshold */ 3870} /* get_threshold */
3941 3871
3942static int 3872static int
@@ -3954,49 +3884,45 @@ get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
3954 3884
3955static int set_timeout(struct cyclades_port *info, unsigned long value) 3885static int set_timeout(struct cyclades_port *info, unsigned long value)
3956{ 3886{
3887 struct cyclades_card *card;
3957 void __iomem *base_addr; 3888 void __iomem *base_addr;
3958 int card, channel, chip, index; 3889 int channel, chip, index;
3959 unsigned long flags; 3890 unsigned long flags;
3960 3891
3961 card = info->card; 3892 card = info->card;
3962 channel = info->line - cy_card[card].first_line; 3893 channel = info->line - card->first_line;
3963 if (!IS_CYC_Z(cy_card[card])) { 3894 if (!IS_CYC_Z(*card)) {
3964 chip = channel >> 2; 3895 chip = channel >> 2;
3965 channel &= 0x03; 3896 channel &= 0x03;
3966 index = cy_card[card].bus_index; 3897 index = card->bus_index;
3967 base_addr = 3898 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
3968 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3969 3899
3970 CY_LOCK(info, flags); 3900 spin_lock_irqsave(&card->card_lock, flags);
3971 cy_writeb(base_addr + (CyRTPR << index), value & 0xff); 3901 cy_writeb(base_addr + (CyRTPR << index), value & 0xff);
3972 CY_UNLOCK(info, flags); 3902 spin_unlock_irqrestore(&card->card_lock, flags);
3973 } else {
3974 /* Nothing to do! */
3975 } 3903 }
3976 return 0; 3904 return 0;
3977} /* set_timeout */ 3905} /* set_timeout */
3978 3906
3979static int get_timeout(struct cyclades_port *info, unsigned long __user * value) 3907static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
3980{ 3908{
3909 struct cyclades_card *card;
3981 void __iomem *base_addr; 3910 void __iomem *base_addr;
3982 int card, channel, chip, index; 3911 int channel, chip, index;
3983 unsigned long tmp; 3912 unsigned long tmp;
3984 3913
3985 card = info->card; 3914 card = info->card;
3986 channel = info->line - cy_card[card].first_line; 3915 channel = info->line - card->first_line;
3987 if (!IS_CYC_Z(cy_card[card])) { 3916 if (!IS_CYC_Z(*card)) {
3988 chip = channel >> 2; 3917 chip = channel >> 2;
3989 channel &= 0x03; 3918 channel &= 0x03;
3990 index = cy_card[card].bus_index; 3919 index = card->bus_index;
3991 base_addr = 3920 base_addr = card->base_addr + (cy_chip_offset[chip] << index);
3992 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3993 3921
3994 tmp = cy_readb(base_addr + (CyRTPR << index)); 3922 tmp = readb(base_addr + (CyRTPR << index));
3995 return put_user(tmp, value); 3923 return put_user(tmp, value);
3996 } else {
3997 /* Nothing to do! */
3998 return 0;
3999 } 3924 }
3925 return 0;
4000} /* get_timeout */ 3926} /* get_timeout */
4001 3927
4002static int set_default_timeout(struct cyclades_port *info, unsigned long value) 3928static int set_default_timeout(struct cyclades_port *info, unsigned long value)
@@ -4020,7 +3946,7 @@ static int
4020cy_ioctl(struct tty_struct *tty, struct file *file, 3946cy_ioctl(struct tty_struct *tty, struct file *file,
4021 unsigned int cmd, unsigned long arg) 3947 unsigned int cmd, unsigned long arg)
4022{ 3948{
4023 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 3949 struct cyclades_port *info = tty->driver_data;
4024 struct cyclades_icount cprev, cnow; /* kernel counter temps */ 3950 struct cyclades_icount cprev, cnow; /* kernel counter temps */
4025 struct serial_icounter_struct __user *p_cuser; /* user space */ 3951 struct serial_icounter_struct __user *p_cuser; /* user space */
4026 int ret_val = 0; 3952 int ret_val = 0;
@@ -4031,7 +3957,8 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
4031 return -ENODEV; 3957 return -ENODEV;
4032 3958
4033#ifdef CY_DEBUG_OTHER 3959#ifdef CY_DEBUG_OTHER
4034 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", info->line, cmd, arg); /* */ 3960 printk(KERN_DEBUG "cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
3961 info->line, cmd, arg);
4035#endif 3962#endif
4036 3963
4037 switch (cmd) { 3964 switch (cmd) {
@@ -4076,14 +4003,6 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
4076 case CYGETRTSDTR_INV: 4003 case CYGETRTSDTR_INV:
4077 ret_val = info->rtsdtr_inv; 4004 ret_val = info->rtsdtr_inv;
4078 break; 4005 break;
4079 case CYGETCARDINFO:
4080 if (copy_to_user(argp, &cy_card[info->card],
4081 sizeof(struct cyclades_card))) {
4082 ret_val = -EFAULT;
4083 break;
4084 }
4085 ret_val = 0;
4086 break;
4087 case CYGETCD1400VER: 4006 case CYGETCD1400VER:
4088 ret_val = info->chip_rev; 4007 ret_val = info->chip_rev;
4089 break; 4008 break;
@@ -4119,34 +4038,22 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
4119 * Caller should use TIOCGICOUNT to see which one it was 4038 * Caller should use TIOCGICOUNT to see which one it was
4120 */ 4039 */
4121 case TIOCMIWAIT: 4040 case TIOCMIWAIT:
4122 CY_LOCK(info, flags); 4041 spin_lock_irqsave(&info->card->card_lock, flags);
4123 /* note the counters on entry */ 4042 /* note the counters on entry */
4124 cprev = info->icount; 4043 cnow = info->icount;
4125 CY_UNLOCK(info, flags); 4044 spin_unlock_irqrestore(&info->card->card_lock, flags);
4126 while (1) { 4045 ret_val = wait_event_interruptible(info->delta_msr_wait, ({
4127 interruptible_sleep_on(&info->delta_msr_wait); 4046 cprev = cnow;
4128 /* see if a signal did it */ 4047 spin_lock_irqsave(&info->card->card_lock, flags);
4129 if (signal_pending(current)) {
4130 return -ERESTARTSYS;
4131 }
4132
4133 CY_LOCK(info, flags);
4134 cnow = info->icount; /* atomic copy */ 4048 cnow = info->icount; /* atomic copy */
4135 CY_UNLOCK(info, flags); 4049 spin_unlock_irqrestore(&info->card->card_lock, flags);
4136 4050
4137 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 4051 ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
4138 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) { 4052 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
4139 return -EIO; /* no change => error */ 4053 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
4140 } 4054 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts));
4141 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) || 4055 }));
4142 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) || 4056 break;
4143 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
4144 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
4145 return 0;
4146 }
4147 cprev = cnow;
4148 }
4149 /* NOTREACHED */
4150 4057
4151 /* 4058 /*
4152 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) 4059 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
@@ -4155,9 +4062,9 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
4155 * RI where only 0->1 is counted. 4062 * RI where only 0->1 is counted.
4156 */ 4063 */
4157 case TIOCGICOUNT: 4064 case TIOCGICOUNT:
4158 CY_LOCK(info, flags); 4065 spin_lock_irqsave(&info->card->card_lock, flags);
4159 cnow = info->icount; 4066 cnow = info->icount;
4160 CY_UNLOCK(info, flags); 4067 spin_unlock_irqrestore(&info->card->card_lock, flags);
4161 p_cuser = argp; 4068 p_cuser = argp;
4162 ret_val = put_user(cnow.cts, &p_cuser->cts); 4069 ret_val = put_user(cnow.cts, &p_cuser->cts);
4163 if (ret_val) 4070 if (ret_val)
@@ -4199,7 +4106,7 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
4199 } 4106 }
4200 4107
4201#ifdef CY_DEBUG_OTHER 4108#ifdef CY_DEBUG_OTHER
4202 printk(" cyc:cy_ioctl done\n"); 4109 printk(KERN_DEBUG "cyc:cy_ioctl done\n");
4203#endif 4110#endif
4204 4111
4205 return ret_val; 4112 return ret_val;
@@ -4213,10 +4120,10 @@ cy_ioctl(struct tty_struct *tty, struct file *file,
4213 */ 4120 */
4214static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 4121static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
4215{ 4122{
4216 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4123 struct cyclades_port *info = tty->driver_data;
4217 4124
4218#ifdef CY_DEBUG_OTHER 4125#ifdef CY_DEBUG_OTHER
4219 printk("cyc:cy_set_termios ttyC%d\n", info->line); 4126 printk(KERN_DEBUG "cyc:cy_set_termios ttyC%d\n", info->line);
4220#endif 4127#endif
4221 4128
4222 if (tty->termios->c_cflag == old_termios->c_cflag && 4129 if (tty->termios->c_cflag == old_termios->c_cflag &&
@@ -4248,8 +4155,9 @@ static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
4248*/ 4155*/
4249static void cy_send_xchar(struct tty_struct *tty, char ch) 4156static void cy_send_xchar(struct tty_struct *tty, char ch)
4250{ 4157{
4251 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4158 struct cyclades_port *info = tty->driver_data;
4252 int card, channel; 4159 struct cyclades_card *card;
4160 int channel;
4253 4161
4254 if (serial_paranoia_check(info, tty->name, "cy_send_xchar")) 4162 if (serial_paranoia_check(info, tty->name, "cy_send_xchar"))
4255 return; 4163 return;
@@ -4260,15 +4168,13 @@ static void cy_send_xchar(struct tty_struct *tty, char ch)
4260 cy_start(tty); 4168 cy_start(tty);
4261 4169
4262 card = info->card; 4170 card = info->card;
4263 channel = info->line - cy_card[card].first_line; 4171 channel = info->line - card->first_line;
4264 4172
4265 if (IS_CYC_Z(cy_card[card])) { 4173 if (IS_CYC_Z(*card)) {
4266 if (ch == STOP_CHAR(tty)) 4174 if (ch == STOP_CHAR(tty))
4267 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXOFF, 4175 cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L);
4268 0L);
4269 else if (ch == START_CHAR(tty)) 4176 else if (ch == START_CHAR(tty))
4270 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXON, 4177 cyz_issue_cmd(card, channel, C_CM_SENDXON, 0L);
4271 0L);
4272 } 4178 }
4273} 4179}
4274 4180
@@ -4278,15 +4184,16 @@ static void cy_send_xchar(struct tty_struct *tty, char ch)
4278 */ 4184 */
4279static void cy_throttle(struct tty_struct *tty) 4185static void cy_throttle(struct tty_struct *tty)
4280{ 4186{
4281 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4187 struct cyclades_port *info = tty->driver_data;
4188 struct cyclades_card *card;
4282 unsigned long flags; 4189 unsigned long flags;
4283 void __iomem *base_addr; 4190 void __iomem *base_addr;
4284 int card, chip, channel, index; 4191 int chip, channel, index;
4285 4192
4286#ifdef CY_DEBUG_THROTTLE 4193#ifdef CY_DEBUG_THROTTLE
4287 char buf[64]; 4194 char buf[64];
4288 4195
4289 printk("cyc:throttle %s: %d....ttyC%d\n", tty_name(tty, buf), 4196 printk(KERN_DEBUG "cyc:throttle %s: %ld...ttyC%d\n", tty_name(tty, buf),
4290 tty->ldisc.chars_in_buffer(tty), info->line); 4197 tty->ldisc.chars_in_buffer(tty), info->line);
4291#endif 4198#endif
4292 4199
@@ -4297,22 +4204,22 @@ static void cy_throttle(struct tty_struct *tty)
4297 card = info->card; 4204 card = info->card;
4298 4205
4299 if (I_IXOFF(tty)) { 4206 if (I_IXOFF(tty)) {
4300 if (!IS_CYC_Z(cy_card[card])) 4207 if (!IS_CYC_Z(*card))
4301 cy_send_xchar(tty, STOP_CHAR(tty)); 4208 cy_send_xchar(tty, STOP_CHAR(tty));
4302 else 4209 else
4303 info->throttle = 1; 4210 info->throttle = 1;
4304 } 4211 }
4305 4212
4306 if (tty->termios->c_cflag & CRTSCTS) { 4213 if (tty->termios->c_cflag & CRTSCTS) {
4307 channel = info->line - cy_card[card].first_line; 4214 channel = info->line - card->first_line;
4308 if (!IS_CYC_Z(cy_card[card])) { 4215 if (!IS_CYC_Z(*card)) {
4309 chip = channel >> 2; 4216 chip = channel >> 2;
4310 channel &= 0x03; 4217 channel &= 0x03;
4311 index = cy_card[card].bus_index; 4218 index = card->bus_index;
4312 base_addr = cy_card[card].base_addr + 4219 base_addr = card->base_addr +
4313 (cy_chip_offset[chip] << index); 4220 (cy_chip_offset[chip] << index);
4314 4221
4315 CY_LOCK(info, flags); 4222 spin_lock_irqsave(&card->card_lock, flags);
4316 cy_writeb(base_addr + (CyCAR << index), 4223 cy_writeb(base_addr + (CyCAR << index),
4317 (u_char) channel); 4224 (u_char) channel);
4318 if (info->rtsdtr_inv) { 4225 if (info->rtsdtr_inv) {
@@ -4322,7 +4229,7 @@ static void cy_throttle(struct tty_struct *tty)
4322 cy_writeb(base_addr + (CyMSVR1 << index), 4229 cy_writeb(base_addr + (CyMSVR1 << index),
4323 ~CyRTS); 4230 ~CyRTS);
4324 } 4231 }
4325 CY_UNLOCK(info, flags); 4232 spin_unlock_irqrestore(&card->card_lock, flags);
4326 } else { 4233 } else {
4327 info->throttle = 1; 4234 info->throttle = 1;
4328 } 4235 }
@@ -4336,16 +4243,17 @@ static void cy_throttle(struct tty_struct *tty)
4336 */ 4243 */
4337static void cy_unthrottle(struct tty_struct *tty) 4244static void cy_unthrottle(struct tty_struct *tty)
4338{ 4245{
4339 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4246 struct cyclades_port *info = tty->driver_data;
4247 struct cyclades_card *card;
4340 unsigned long flags; 4248 unsigned long flags;
4341 void __iomem *base_addr; 4249 void __iomem *base_addr;
4342 int card, chip, channel, index; 4250 int chip, channel, index;
4343 4251
4344#ifdef CY_DEBUG_THROTTLE 4252#ifdef CY_DEBUG_THROTTLE
4345 char buf[64]; 4253 char buf[64];
4346 4254
4347 printk("cyc:unthrottle %s: %d....ttyC%d\n", tty_name(tty, buf), 4255 printk(KERN_DEBUG "cyc:unthrottle %s: %ld...ttyC%d\n",
4348 tty->ldisc.chars_in_buffer(tty), info->line); 4256 tty_name(tty, buf), tty->ldisc.chars_in_buffer(tty),info->line);
4349#endif 4257#endif
4350 4258
4351 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")) { 4259 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")) {
@@ -4361,15 +4269,15 @@ static void cy_unthrottle(struct tty_struct *tty)
4361 4269
4362 if (tty->termios->c_cflag & CRTSCTS) { 4270 if (tty->termios->c_cflag & CRTSCTS) {
4363 card = info->card; 4271 card = info->card;
4364 channel = info->line - cy_card[card].first_line; 4272 channel = info->line - card->first_line;
4365 if (!IS_CYC_Z(cy_card[card])) { 4273 if (!IS_CYC_Z(*card)) {
4366 chip = channel >> 2; 4274 chip = channel >> 2;
4367 channel &= 0x03; 4275 channel &= 0x03;
4368 index = cy_card[card].bus_index; 4276 index = card->bus_index;
4369 base_addr = cy_card[card].base_addr + 4277 base_addr = card->base_addr +
4370 (cy_chip_offset[chip] << index); 4278 (cy_chip_offset[chip] << index);
4371 4279
4372 CY_LOCK(info, flags); 4280 spin_lock_irqsave(&card->card_lock, flags);
4373 cy_writeb(base_addr + (CyCAR << index), 4281 cy_writeb(base_addr + (CyCAR << index),
4374 (u_char) channel); 4282 (u_char) channel);
4375 if (info->rtsdtr_inv) { 4283 if (info->rtsdtr_inv) {
@@ -4379,7 +4287,7 @@ static void cy_unthrottle(struct tty_struct *tty)
4379 cy_writeb(base_addr + (CyMSVR1 << index), 4287 cy_writeb(base_addr + (CyMSVR1 << index),
4380 CyRTS); 4288 CyRTS);
4381 } 4289 }
4382 CY_UNLOCK(info, flags); 4290 spin_unlock_irqrestore(&card->card_lock, flags);
4383 } else { 4291 } else {
4384 info->throttle = 0; 4292 info->throttle = 0;
4385 } 4293 }
@@ -4392,102 +4300,96 @@ static void cy_unthrottle(struct tty_struct *tty)
4392static void cy_stop(struct tty_struct *tty) 4300static void cy_stop(struct tty_struct *tty)
4393{ 4301{
4394 struct cyclades_card *cinfo; 4302 struct cyclades_card *cinfo;
4395 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4303 struct cyclades_port *info = tty->driver_data;
4396 void __iomem *base_addr; 4304 void __iomem *base_addr;
4397 int chip, channel, index; 4305 int chip, channel, index;
4398 unsigned long flags; 4306 unsigned long flags;
4399 4307
4400#ifdef CY_DEBUG_OTHER 4308#ifdef CY_DEBUG_OTHER
4401 printk("cyc:cy_stop ttyC%d\n", info->line); /* */ 4309 printk(KERN_DEBUG "cyc:cy_stop ttyC%d\n", info->line);
4402#endif 4310#endif
4403 4311
4404 if (serial_paranoia_check(info, tty->name, "cy_stop")) 4312 if (serial_paranoia_check(info, tty->name, "cy_stop"))
4405 return; 4313 return;
4406 4314
4407 cinfo = &cy_card[info->card]; 4315 cinfo = info->card;
4408 channel = info->line - cinfo->first_line; 4316 channel = info->line - cinfo->first_line;
4409 if (!IS_CYC_Z(*cinfo)) { 4317 if (!IS_CYC_Z(*cinfo)) {
4410 index = cinfo->bus_index; 4318 index = cinfo->bus_index;
4411 chip = channel >> 2; 4319 chip = channel >> 2;
4412 channel &= 0x03; 4320 channel &= 0x03;
4413 base_addr = cy_card[info->card].base_addr + 4321 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
4414 (cy_chip_offset[chip] << index);
4415 4322
4416 CY_LOCK(info, flags); 4323 spin_lock_irqsave(&cinfo->card_lock, flags);
4417 cy_writeb(base_addr + (CyCAR << index), 4324 cy_writeb(base_addr + (CyCAR << index),
4418 (u_char)(channel & 0x0003)); /* index channel */ 4325 (u_char)(channel & 0x0003)); /* index channel */
4419 cy_writeb(base_addr + (CySRER << index), 4326 cy_writeb(base_addr + (CySRER << index),
4420 cy_readb(base_addr + (CySRER << index)) & ~CyTxRdy); 4327 readb(base_addr + (CySRER << index)) & ~CyTxRdy);
4421 CY_UNLOCK(info, flags); 4328 spin_unlock_irqrestore(&cinfo->card_lock, flags);
4422 } else {
4423 /* Nothing to do! */
4424 } 4329 }
4425} /* cy_stop */ 4330} /* cy_stop */
4426 4331
4427static void cy_start(struct tty_struct *tty) 4332static void cy_start(struct tty_struct *tty)
4428{ 4333{
4429 struct cyclades_card *cinfo; 4334 struct cyclades_card *cinfo;
4430 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4335 struct cyclades_port *info = tty->driver_data;
4431 void __iomem *base_addr; 4336 void __iomem *base_addr;
4432 int chip, channel, index; 4337 int chip, channel, index;
4433 unsigned long flags; 4338 unsigned long flags;
4434 4339
4435#ifdef CY_DEBUG_OTHER 4340#ifdef CY_DEBUG_OTHER
4436 printk("cyc:cy_start ttyC%d\n", info->line); /* */ 4341 printk(KERN_DEBUG "cyc:cy_start ttyC%d\n", info->line);
4437#endif 4342#endif
4438 4343
4439 if (serial_paranoia_check(info, tty->name, "cy_start")) 4344 if (serial_paranoia_check(info, tty->name, "cy_start"))
4440 return; 4345 return;
4441 4346
4442 cinfo = &cy_card[info->card]; 4347 cinfo = info->card;
4443 channel = info->line - cinfo->first_line; 4348 channel = info->line - cinfo->first_line;
4444 index = cinfo->bus_index; 4349 index = cinfo->bus_index;
4445 if (!IS_CYC_Z(*cinfo)) { 4350 if (!IS_CYC_Z(*cinfo)) {
4446 chip = channel >> 2; 4351 chip = channel >> 2;
4447 channel &= 0x03; 4352 channel &= 0x03;
4448 base_addr = cy_card[info->card].base_addr + 4353 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
4449 (cy_chip_offset[chip] << index);
4450 4354
4451 CY_LOCK(info, flags); 4355 spin_lock_irqsave(&cinfo->card_lock, flags);
4452 cy_writeb(base_addr + (CyCAR << index), (u_char) (channel & 0x0003)); /* index channel */ 4356 cy_writeb(base_addr + (CyCAR << index), (u_char) (channel & 0x0003)); /* index channel */
4453 cy_writeb(base_addr + (CySRER << index), 4357 cy_writeb(base_addr + (CySRER << index),
4454 cy_readb(base_addr + (CySRER << index)) | CyTxRdy); 4358 readb(base_addr + (CySRER << index)) | CyTxRdy);
4455 CY_UNLOCK(info, flags); 4359 spin_unlock_irqrestore(&cinfo->card_lock, flags);
4456 } else {
4457 /* Nothing to do! */
4458 } 4360 }
4459} /* cy_start */ 4361} /* cy_start */
4460 4362
4461static void cy_flush_buffer(struct tty_struct *tty) 4363static void cy_flush_buffer(struct tty_struct *tty)
4462{ 4364{
4463 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4365 struct cyclades_port *info = tty->driver_data;
4464 int card, channel, retval; 4366 struct cyclades_card *card;
4367 int channel, retval;
4465 unsigned long flags; 4368 unsigned long flags;
4466 4369
4467#ifdef CY_DEBUG_IO 4370#ifdef CY_DEBUG_IO
4468 printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */ 4371 printk(KERN_DEBUG "cyc:cy_flush_buffer ttyC%d\n", info->line);
4469#endif 4372#endif
4470 4373
4471 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer")) 4374 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
4472 return; 4375 return;
4473 4376
4474 card = info->card; 4377 card = info->card;
4475 channel = (info->line) - (cy_card[card].first_line); 4378 channel = info->line - card->first_line;
4476 4379
4477 CY_LOCK(info, flags); 4380 spin_lock_irqsave(&card->card_lock, flags);
4478 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 4381 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
4479 CY_UNLOCK(info, flags); 4382 spin_unlock_irqrestore(&card->card_lock, flags);
4480 4383
4481 if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board 4384 if (IS_CYC_Z(*card)) { /* If it is a Z card, flush the on-board
4482 buffers as well */ 4385 buffers as well */
4483 CY_LOCK(info, flags); 4386 spin_lock_irqsave(&card->card_lock, flags);
4484 retval = 4387 retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L);
4485 cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_TX, 0L);
4486 if (retval != 0) { 4388 if (retval != 0) {
4487 printk("cyc: flush_buffer retval on ttyC%d was %x\n", 4389 printk(KERN_ERR "cyc: flush_buffer retval on ttyC%d "
4488 info->line, retval); 4390 "was %x\n", info->line, retval);
4489 } 4391 }
4490 CY_UNLOCK(info, flags); 4392 spin_unlock_irqrestore(&card->card_lock, flags);
4491 } 4393 }
4492 tty_wakeup(tty); 4394 tty_wakeup(tty);
4493} /* cy_flush_buffer */ 4395} /* cy_flush_buffer */
@@ -4497,10 +4399,10 @@ static void cy_flush_buffer(struct tty_struct *tty)
4497 */ 4399 */
4498static void cy_hangup(struct tty_struct *tty) 4400static void cy_hangup(struct tty_struct *tty)
4499{ 4401{
4500 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4402 struct cyclades_port *info = tty->driver_data;
4501 4403
4502#ifdef CY_DEBUG_OTHER 4404#ifdef CY_DEBUG_OTHER
4503 printk("cyc:cy_hangup ttyC%d\n", info->line); /* */ 4405 printk(KERN_DEBUG "cyc:cy_hangup ttyC%d\n", info->line);
4504#endif 4406#endif
4505 4407
4506 if (serial_paranoia_check(info, tty->name, "cy_hangup")) 4408 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
@@ -4511,7 +4413,8 @@ static void cy_hangup(struct tty_struct *tty)
4511 info->event = 0; 4413 info->event = 0;
4512 info->count = 0; 4414 info->count = 0;
4513#ifdef CY_DEBUG_COUNT 4415#ifdef CY_DEBUG_COUNT
4514 printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid); 4416 printk(KERN_DEBUG "cyc:cy_hangup (%d): setting count to 0\n",
4417 current->pid);
4515#endif 4418#endif
4516 info->tty = NULL; 4419 info->tty = NULL;
4517 info->flags &= ~ASYNC_NORMAL_ACTIVE; 4420 info->flags &= ~ASYNC_NORMAL_ACTIVE;
@@ -4526,10 +4429,107 @@ static void cy_hangup(struct tty_struct *tty)
4526 * --------------------------------------------------------------------- 4429 * ---------------------------------------------------------------------
4527 */ 4430 */
4528 4431
4432static int __devinit cy_init_card(struct cyclades_card *cinfo)
4433{
4434 struct cyclades_port *info;
4435 u32 mailbox;
4436 unsigned int nports;
4437 unsigned short chip_number;
4438 int index, port;
4439
4440 spin_lock_init(&cinfo->card_lock);
4441
4442 if (IS_CYC_Z(*cinfo)) { /* Cyclades-Z */
4443 mailbox = readl(&((struct RUNTIME_9060 __iomem *)
4444 cinfo->ctl_addr)->mail_box_0);
4445 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
4446 cinfo->intr_enabled = 0;
4447 cinfo->nports = 0; /* Will be correctly set later, after
4448 Z FW is loaded */
4449 } else {
4450 index = cinfo->bus_index;
4451 nports = cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
4452 }
4453
4454 cinfo->ports = kzalloc(sizeof(*cinfo->ports) * nports, GFP_KERNEL);
4455 if (cinfo->ports == NULL) {
4456 printk(KERN_ERR "Cyclades: cannot allocate ports\n");
4457 cinfo->nports = 0;
4458 return -ENOMEM;
4459 }
4460
4461 for (port = cinfo->first_line; port < cinfo->first_line + nports;
4462 port++) {
4463 info = &cinfo->ports[port - cinfo->first_line];
4464 info->magic = CYCLADES_MAGIC;
4465 info->card = cinfo;
4466 info->line = port;
4467 info->flags = STD_COM_FLAGS;
4468 info->closing_wait = CLOSING_WAIT_DELAY;
4469 info->close_delay = 5 * HZ / 10;
4470
4471 INIT_WORK(&info->tqueue, do_softint);
4472 init_waitqueue_head(&info->open_wait);
4473 init_waitqueue_head(&info->close_wait);
4474 init_completion(&info->shutdown_wait);
4475 init_waitqueue_head(&info->delta_msr_wait);
4476
4477 if (IS_CYC_Z(*cinfo)) {
4478 info->type = PORT_STARTECH;
4479 if (mailbox == ZO_V1)
4480 info->xmit_fifo_size = CYZ_FIFO_SIZE;
4481 else
4482 info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE;
4483#ifdef CONFIG_CYZ_INTR
4484 setup_timer(&cyz_rx_full_timer[port],
4485 cyz_rx_restart, (unsigned long)info);
4486#endif
4487 } else {
4488 info->type = PORT_CIRRUS;
4489 info->xmit_fifo_size = CyMAX_CHAR_FIFO;
4490 info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS;
4491 info->cor2 = CyETC;
4492 info->cor3 = 0x08; /* _very_ small rcv threshold */
4493
4494 chip_number = (port - cinfo->first_line) / 4;
4495 if ((info->chip_rev = readb(cinfo->base_addr +
4496 (cy_chip_offset[chip_number] <<
4497 index) + (CyGFRCR << index))) >=
4498 CD1400_REV_J) {
4499 /* It is a CD1400 rev. J or later */
4500 info->tbpr = baud_bpr_60[13]; /* Tx BPR */
4501 info->tco = baud_co_60[13]; /* Tx CO */
4502 info->rbpr = baud_bpr_60[13]; /* Rx BPR */
4503 info->rco = baud_co_60[13]; /* Rx CO */
4504 info->rtsdtr_inv = 1;
4505 } else {
4506 info->tbpr = baud_bpr_25[13]; /* Tx BPR */
4507 info->tco = baud_co_25[13]; /* Tx CO */
4508 info->rbpr = baud_bpr_25[13]; /* Rx BPR */
4509 info->rco = baud_co_25[13]; /* Rx CO */
4510 info->rtsdtr_inv = 0;
4511 }
4512 info->read_status_mask = CyTIMEOUT | CySPECHAR |
4513 CyBREAK | CyPARITY | CyFRAME | CyOVERRUN;
4514 }
4515
4516 }
4517
4518#ifndef CONFIG_CYZ_INTR
4519 if (IS_CYC_Z(*cinfo) && !timer_pending(&cyz_timerlist)) {
4520 mod_timer(&cyz_timerlist, jiffies + 1);
4521#ifdef CY_PCI_DEBUG
4522 printk(KERN_DEBUG "Cyclades-Z polling initialized\n");
4523#endif
4524 }
4525#endif
4526 return 0;
4527}
4528
4529/* initialize chips on Cyclom-Y card -- return number of valid 4529/* initialize chips on Cyclom-Y card -- return number of valid
4530 chips (which is number of ports/4) */ 4530 chips (which is number of ports/4) */
4531static unsigned short __init 4531static unsigned short __devinit cyy_init_card(void __iomem *true_base_addr,
4532cyy_init_card(void __iomem * true_base_addr, int index) 4532 int index)
4533{ 4533{
4534 unsigned int chip_number; 4534 unsigned int chip_number;
4535 void __iomem *base_addr; 4535 void __iomem *base_addr;
@@ -4544,7 +4544,7 @@ cyy_init_card(void __iomem * true_base_addr, int index)
4544 base_addr = 4544 base_addr =
4545 true_base_addr + (cy_chip_offset[chip_number] << index); 4545 true_base_addr + (cy_chip_offset[chip_number] << index);
4546 mdelay(1); 4546 mdelay(1);
4547 if (cy_readb(base_addr + (CyCCR << index)) != 0x00) { 4547 if (readb(base_addr + (CyCCR << index)) != 0x00) {
4548 /************* 4548 /*************
4549 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n", 4549 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4550 chip_number, (unsigned long)base_addr); 4550 chip_number, (unsigned long)base_addr);
@@ -4561,7 +4561,7 @@ cyy_init_card(void __iomem * true_base_addr, int index)
4561 chip 4 GFRCR register appears at chip 0, there is no chip 4 4561 chip 4 GFRCR register appears at chip 0, there is no chip 4
4562 and this must be a Cyclom-16Y, not a Cyclom-32Ye. 4562 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4563 */ 4563 */
4564 if (chip_number == 4 && cy_readb(true_base_addr + 4564 if (chip_number == 4 && readb(true_base_addr +
4565 (cy_chip_offset[0] << index) + 4565 (cy_chip_offset[0] << index) +
4566 (CyGFRCR << index)) == 0) { 4566 (CyGFRCR << index)) == 0) {
4567 return chip_number; 4567 return chip_number;
@@ -4570,7 +4570,7 @@ cyy_init_card(void __iomem * true_base_addr, int index)
4570 cy_writeb(base_addr + (CyCCR << index), CyCHIP_RESET); 4570 cy_writeb(base_addr + (CyCCR << index), CyCHIP_RESET);
4571 mdelay(1); 4571 mdelay(1);
4572 4572
4573 if (cy_readb(base_addr + (CyGFRCR << index)) == 0x00) { 4573 if (readb(base_addr + (CyGFRCR << index)) == 0x00) {
4574 /* 4574 /*
4575 printk(" chip #%d at %#6lx is not responding ", 4575 printk(" chip #%d at %#6lx is not responding ",
4576 chip_number, (unsigned long)base_addr); 4576 chip_number, (unsigned long)base_addr);
@@ -4578,7 +4578,7 @@ cyy_init_card(void __iomem * true_base_addr, int index)
4578 */ 4578 */
4579 return chip_number; 4579 return chip_number;
4580 } 4580 }
4581 if ((0xf0 & (cy_readb(base_addr + (CyGFRCR << index)))) != 4581 if ((0xf0 & (readb(base_addr + (CyGFRCR << index)))) !=
4582 0x40) { 4582 0x40) {
4583 /* 4583 /*
4584 printk(" chip #%d at %#6lx is not valid (GFRCR == " 4584 printk(" chip #%d at %#6lx is not valid (GFRCR == "
@@ -4589,7 +4589,7 @@ cyy_init_card(void __iomem * true_base_addr, int index)
4589 return chip_number; 4589 return chip_number;
4590 } 4590 }
4591 cy_writeb(base_addr + (CyGCR << index), CyCH0_SERIAL); 4591 cy_writeb(base_addr + (CyGCR << index), CyCH0_SERIAL);
4592 if (cy_readb(base_addr + (CyGFRCR << index)) >= CD1400_REV_J) { 4592 if (readb(base_addr + (CyGFRCR << index)) >= CD1400_REV_J) {
4593 /* It is a CD1400 rev. J or later */ 4593 /* It is a CD1400 rev. J or later */
4594 /* Impossible to reach 5ms with this chip. 4594 /* Impossible to reach 5ms with this chip.
4595 Changed to 2ms instead (f = 500 Hz). */ 4595 Changed to 2ms instead (f = 500 Hz). */
@@ -4602,7 +4602,7 @@ cyy_init_card(void __iomem * true_base_addr, int index)
4602 /* 4602 /*
4603 printk(" chip #%d at %#6lx is rev 0x%2x\n", 4603 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4604 chip_number, (unsigned long)base_addr, 4604 chip_number, (unsigned long)base_addr,
4605 cy_readb(base_addr+(CyGFRCR<<index))); 4605 readb(base_addr+(CyGFRCR<<index)));
4606 */ 4606 */
4607 } 4607 }
4608 return chip_number; 4608 return chip_number;
@@ -4647,9 +4647,15 @@ static int __init cy_detect_isa(void)
4647 4647
4648 /* probe for CD1400... */ 4648 /* probe for CD1400... */
4649 cy_isa_address = ioremap(isa_address, CyISA_Ywin); 4649 cy_isa_address = ioremap(isa_address, CyISA_Ywin);
4650 if (cy_isa_address == NULL) {
4651 printk(KERN_ERR "Cyclom-Y/ISA: can't remap base "
4652 "address\n");
4653 continue;
4654 }
4650 cy_isa_nchan = CyPORTS_PER_CHIP * 4655 cy_isa_nchan = CyPORTS_PER_CHIP *
4651 cyy_init_card(cy_isa_address, 0); 4656 cyy_init_card(cy_isa_address, 0);
4652 if (cy_isa_nchan == 0) { 4657 if (cy_isa_nchan == 0) {
4658 iounmap(cy_isa_address);
4653 continue; 4659 continue;
4654 } 4660 }
4655#ifdef MODULE 4661#ifdef MODULE
@@ -4660,40 +4666,42 @@ static int __init cy_detect_isa(void)
4660 /* find out the board's irq by probing */ 4666 /* find out the board's irq by probing */
4661 cy_isa_irq = detect_isa_irq(cy_isa_address); 4667 cy_isa_irq = detect_isa_irq(cy_isa_address);
4662 if (cy_isa_irq == 0) { 4668 if (cy_isa_irq == 0) {
4663 printk("Cyclom-Y/ISA found at 0x%lx ", 4669 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but the "
4670 "IRQ could not be detected.\n",
4664 (unsigned long)cy_isa_address); 4671 (unsigned long)cy_isa_address);
4665 printk("but the IRQ could not be detected.\n"); 4672 iounmap(cy_isa_address);
4666 continue; 4673 continue;
4667 } 4674 }
4668 4675
4669 if ((cy_next_channel + cy_isa_nchan) > NR_PORTS) { 4676 if ((cy_next_channel + cy_isa_nchan) > NR_PORTS) {
4670 printk("Cyclom-Y/ISA found at 0x%lx ", 4677 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but no "
4678 "more channels are available. Change NR_PORTS "
4679 "in cyclades.c and recompile kernel.\n",
4671 (unsigned long)cy_isa_address); 4680 (unsigned long)cy_isa_address);
4672 printk("but no more channels are available.\n"); 4681 iounmap(cy_isa_address);
4673 printk("Change NR_PORTS in cyclades.c and recompile "
4674 "kernel.\n");
4675 return nboard; 4682 return nboard;
4676 } 4683 }
4677 /* fill the next cy_card structure available */ 4684 /* fill the next cy_card structure available */
4678 for (j = 0; j < NR_CARDS; j++) { 4685 for (j = 0; j < NR_CARDS; j++) {
4679 if (cy_card[j].base_addr == 0) 4686 if (cy_card[j].base_addr == NULL)
4680 break; 4687 break;
4681 } 4688 }
4682 if (j == NR_CARDS) { /* no more cy_cards available */ 4689 if (j == NR_CARDS) { /* no more cy_cards available */
4683 printk("Cyclom-Y/ISA found at 0x%lx ", 4690 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but no "
4691 "more cards can be used. Change NR_CARDS in "
4692 "cyclades.c and recompile kernel.\n",
4684 (unsigned long)cy_isa_address); 4693 (unsigned long)cy_isa_address);
4685 printk("but no more cards can be used .\n"); 4694 iounmap(cy_isa_address);
4686 printk("Change NR_CARDS in cyclades.c and recompile "
4687 "kernel.\n");
4688 return nboard; 4695 return nboard;
4689 } 4696 }
4690 4697
4691 /* allocate IRQ */ 4698 /* allocate IRQ */
4692 if (request_irq(cy_isa_irq, cyy_interrupt, 4699 if (request_irq(cy_isa_irq, cyy_interrupt,
4693 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) { 4700 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) {
4694 printk("Cyclom-Y/ISA found at 0x%lx ", 4701 printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but "
4695 (unsigned long)cy_isa_address); 4702 "could not allocate IRQ#%d.\n",
4696 printk("but could not allocate IRQ#%d.\n", cy_isa_irq); 4703 (unsigned long)cy_isa_address, cy_isa_irq);
4704 iounmap(cy_isa_address);
4697 return nboard; 4705 return nboard;
4698 } 4706 }
4699 4707
@@ -4704,15 +4712,23 @@ static int __init cy_detect_isa(void)
4704 cy_card[j].bus_index = 0; 4712 cy_card[j].bus_index = 0;
4705 cy_card[j].first_line = cy_next_channel; 4713 cy_card[j].first_line = cy_next_channel;
4706 cy_card[j].num_chips = cy_isa_nchan / 4; 4714 cy_card[j].num_chips = cy_isa_nchan / 4;
4715 if (cy_init_card(&cy_card[j])) {
4716 cy_card[j].base_addr = NULL;
4717 free_irq(cy_isa_irq, &cy_card[j]);
4718 iounmap(cy_isa_address);
4719 continue;
4720 }
4707 nboard++; 4721 nboard++;
4708 4722
4709 /* print message */ 4723 printk(KERN_INFO "Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d found: "
4710 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ", 4724 "%d channels starting from port %d\n",
4711 j + 1, (unsigned long)cy_isa_address, 4725 j + 1, (unsigned long)cy_isa_address,
4712 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)), 4726 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)),
4713 cy_isa_irq); 4727 cy_isa_irq, cy_isa_nchan, cy_next_channel);
4714 printk("%d channels starting from port %d.\n", 4728
4715 cy_isa_nchan, cy_next_channel); 4729 for (j = cy_next_channel;
4730 j < cy_next_channel + cy_isa_nchan; j++)
4731 tty_register_device(cy_serial_driver, j, NULL);
4716 cy_next_channel += cy_isa_nchan; 4732 cy_next_channel += cy_isa_nchan;
4717 } 4733 }
4718 return nboard; 4734 return nboard;
@@ -4721,510 +4737,310 @@ static int __init cy_detect_isa(void)
4721#endif /* CONFIG_ISA */ 4737#endif /* CONFIG_ISA */
4722} /* cy_detect_isa */ 4738} /* cy_detect_isa */
4723 4739
4724static void plx_init(void __iomem * addr, uclong initctl) 4740#ifdef CONFIG_PCI
4741static void __devinit plx_init(void __iomem * addr, __u32 initctl)
4725{ 4742{
4726 /* Reset PLX */ 4743 /* Reset PLX */
4727 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x40000000); 4744 cy_writel(addr + initctl, readl(addr + initctl) | 0x40000000);
4728 udelay(100L); 4745 udelay(100L);
4729 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x40000000); 4746 cy_writel(addr + initctl, readl(addr + initctl) & ~0x40000000);
4730 4747
4731 /* Reload Config. Registers from EEPROM */ 4748 /* Reload Config. Registers from EEPROM */
4732 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x20000000); 4749 cy_writel(addr + initctl, readl(addr + initctl) | 0x20000000);
4733 udelay(100L); 4750 udelay(100L);
4734 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x20000000); 4751 cy_writel(addr + initctl, readl(addr + initctl) & ~0x20000000);
4735} 4752}
4736 4753
4737/* 4754static int __devinit cy_pci_probe(struct pci_dev *pdev,
4738 * --------------------------------------------------------------------- 4755 const struct pci_device_id *ent)
4739 * cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
4740 * sets global variables and return the number of PCI boards found.
4741 * ---------------------------------------------------------------------
4742 */
4743static int __init cy_detect_pci(void)
4744{ 4756{
4745#ifdef CONFIG_PCI 4757 void __iomem *addr0 = NULL, *addr2 = NULL;
4746 4758 char *card_name = NULL;
4747 struct pci_dev *pdev = NULL; 4759 u32 mailbox;
4748 unsigned char cyy_rev_id; 4760 unsigned int device_id, nchan = 0, card_no, i;
4749 unsigned char cy_pci_irq = 0; 4761 unsigned char plx_ver;
4750 uclong cy_pci_phys0, cy_pci_phys2; 4762 int retval, irq;
4751 void __iomem *cy_pci_addr0, *cy_pci_addr2; 4763
4752 unsigned short i, j, cy_pci_nchan, plx_ver; 4764 retval = pci_enable_device(pdev);
4753 unsigned short device_id, dev_index = 0; 4765 if (retval) {
4754 uclong mailbox; 4766 dev_err(&pdev->dev, "cannot enable device\n");
4755 uclong ZeIndex = 0; 4767 goto err;
4756 void __iomem *Ze_addr0[NR_CARDS], *Ze_addr2[NR_CARDS]; 4768 }
4757 uclong Ze_phys0[NR_CARDS], Ze_phys2[NR_CARDS];
4758 unsigned char Ze_irq[NR_CARDS];
4759 struct pci_dev *Ze_pdev[NR_CARDS];
4760
4761 for (i = 0; i < NR_CARDS; i++) {
4762 /* look for a Cyclades card by vendor and device id */
4763 while ((device_id = cy_pci_dev_id[dev_index].device) != 0) {
4764 if ((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES,
4765 device_id, pdev)) == NULL) {
4766 dev_index++; /* try next device id */
4767 } else {
4768 break; /* found a board */
4769 }
4770 }
4771
4772 if (device_id == 0)
4773 break;
4774
4775 if (pci_enable_device(pdev))
4776 continue;
4777
4778 /* read PCI configuration area */
4779 cy_pci_irq = pdev->irq;
4780 cy_pci_phys0 = pci_resource_start(pdev, 0);
4781 cy_pci_phys2 = pci_resource_start(pdev, 2);
4782 pci_read_config_byte(pdev, PCI_REVISION_ID, &cyy_rev_id);
4783 4769
4784 device_id &= ~PCI_DEVICE_ID_MASK; 4770 /* read PCI configuration area */
4771 irq = pdev->irq;
4772 device_id = pdev->device & ~PCI_DEVICE_ID_MASK;
4785 4773
4786 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo || 4774#if defined(__alpha__)
4787 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) { 4775 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
4788#ifdef CY_PCI_DEBUG 4776 dev_err(&pdev->dev, "Cyclom-Y/PCI not supported for low "
4789 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ", 4777 "addresses on Alpha systems.\n");
4790 pdev->bus->number, pdev->devfn); 4778 retval = -EIO;
4791 printk("rev_id=%d) IRQ%d\n", 4779 goto err_dis;
4792 cyy_rev_id, (int)cy_pci_irq); 4780 }
4793 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4794 "ctladdr=0x%lx\n",
4795 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
4796#endif 4781#endif
4782 if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo) {
4783 dev_err(&pdev->dev, "Cyclades-Z/PCI not supported for low "
4784 "addresses\n");
4785 retval = -EIO;
4786 goto err_dis;
4787 }
4797 4788
4798 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) { 4789 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4799 printk(" Warning: PCI I/O bit incorrectly " 4790 dev_warn(&pdev->dev, "PCI I/O bit incorrectly set. Ignoring "
4800 "set. Ignoring it...\n"); 4791 "it...\n");
4801 pdev->resource[2].flags &= ~IORESOURCE_IO; 4792 pdev->resource[2].flags &= ~IORESOURCE_IO;
4802 } 4793 }
4803 4794
4804 /* Although we don't use this I/O region, we should 4795 retval = pci_request_regions(pdev, "cyclades");
4805 request it from the kernel anyway, to avoid problems 4796 if (retval) {
4806 with other drivers accessing it. */ 4797 dev_err(&pdev->dev, "failed to reserve resources\n");
4807 if (pci_request_regions(pdev, "Cyclom-Y") != 0) { 4798 goto err_dis;
4808 printk(KERN_ERR "cyclades: failed to reserve " 4799 }
4809 "PCI resources\n");
4810 continue;
4811 }
4812#if defined(__alpha__)
4813 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
4814 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4815 pdev->bus->number, pdev->devfn);
4816 printk("rev_id=%d) IRQ%d\n",
4817 cyy_rev_id, (int)cy_pci_irq);
4818 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4819 "ctladdr=0x%lx\n",
4820 (ulong)cy_pci_phys2,
4821 (ulong)cy_pci_phys0);
4822 printk("Cyclom-Y/PCI not supported for low "
4823 "addresses in Alpha systems.\n");
4824 i--;
4825 continue;
4826 }
4827#endif
4828 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Yctl);
4829 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ywin);
4830 4800
4831#ifdef CY_PCI_DEBUG 4801 retval = -EIO;
4832 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx " 4802 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
4833 "ctladdr=0x%lx\n", 4803 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
4834 (u_long)cy_pci_addr2, (u_long)cy_pci_addr0); 4804 card_name = "Cyclom-Y";
4835#endif
4836 cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP *
4837 cyy_init_card(cy_pci_addr2, 1));
4838 if (cy_pci_nchan == 0) {
4839 printk("Cyclom-Y PCI host card with ");
4840 printk("no Serial-Modules at 0x%lx.\n",
4841 (ulong) cy_pci_phys2);
4842 i--;
4843 continue;
4844 }
4845 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
4846 printk("Cyclom-Y/PCI found at 0x%lx ",
4847 (ulong) cy_pci_phys2);
4848 printk("but no channels are available.\n");
4849 printk("Change NR_PORTS in cyclades.c and "
4850 "recompile kernel.\n");
4851 return i;
4852 }
4853 /* fill the next cy_card structure available */
4854 for (j = 0; j < NR_CARDS; j++) {
4855 if (cy_card[j].base_addr == 0)
4856 break;
4857 }
4858 if (j == NR_CARDS) { /* no more cy_cards available */
4859 printk("Cyclom-Y/PCI found at 0x%lx ",
4860 (ulong) cy_pci_phys2);
4861 printk("but no more cards can be used.\n");
4862 printk("Change NR_CARDS in cyclades.c and "
4863 "recompile kernel.\n");
4864 return i;
4865 }
4866 4805
4867 /* allocate IRQ */ 4806 addr0 = pci_iomap(pdev, 0, CyPCI_Yctl);
4868 if (request_irq(cy_pci_irq, cyy_interrupt, 4807 if (addr0 == NULL) {
4869 IRQF_SHARED, "Cyclom-Y", &cy_card[j])) { 4808 dev_err(&pdev->dev, "can't remap ctl region\n");
4870 printk("Cyclom-Y/PCI found at 0x%lx ", 4809 goto err_reg;
4871 (ulong) cy_pci_phys2); 4810 }
4872 printk("but could not allocate IRQ%d.\n", 4811 addr2 = pci_iomap(pdev, 2, CyPCI_Ywin);
4873 cy_pci_irq); 4812 if (addr2 == NULL) {
4874 return i; 4813 dev_err(&pdev->dev, "can't remap base region\n");
4875 } 4814 goto err_unmap;
4815 }
4876 4816
4877 /* set cy_card */ 4817 nchan = CyPORTS_PER_CHIP * cyy_init_card(addr2, 1);
4878 cy_card[j].base_phys = (ulong) cy_pci_phys2; 4818 if (nchan == 0) {
4879 cy_card[j].ctl_phys = (ulong) cy_pci_phys0; 4819 dev_err(&pdev->dev, "Cyclom-Y PCI host card with no "
4880 cy_card[j].base_addr = cy_pci_addr2; 4820 "Serial-Modules\n");
4881 cy_card[j].ctl_addr = cy_pci_addr0; 4821 return -EIO;
4882 cy_card[j].irq = (int)cy_pci_irq; 4822 }
4883 cy_card[j].bus_index = 1; 4823 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
4884 cy_card[j].first_line = cy_next_channel; 4824 struct RUNTIME_9060 __iomem *ctl_addr;
4885 cy_card[j].num_chips = cy_pci_nchan / 4;
4886 cy_card[j].pdev = pdev;
4887
4888 /* enable interrupts in the PCI interface */
4889 plx_ver = cy_readb(cy_pci_addr2 + CyPLX_VER) & 0x0f;
4890 switch (plx_ver) {
4891 case PLX_9050:
4892
4893 cy_writeb(cy_pci_addr0 + 0x4c, 0x43);
4894 break;
4895 4825
4896 case PLX_9060: 4826 ctl_addr = addr0 = pci_iomap(pdev, 0, CyPCI_Zctl);
4897 case PLX_9080: 4827 if (addr0 == NULL) {
4898 default: /* Old boards, use PLX_9060 */ 4828 dev_err(&pdev->dev, "can't remap ctl region\n");
4899 4829 goto err_reg;
4900 plx_init(cy_pci_addr0, 0x6c); 4830 }
4901 /* For some yet unknown reason, once the PLX9060 reloads
4902 the EEPROM, the IRQ is lost and, thus, we have to
4903 re-write it to the PCI config. registers.
4904 This will remain here until we find a permanent
4905 fix. */
4906 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4907 cy_pci_irq);
4908
4909 cy_writew(cy_pci_addr0 + 0x68,
4910 cy_readw(cy_pci_addr0 +
4911 0x68) | 0x0900);
4912 break;
4913 }
4914 4831
4915 /* print message */ 4832 /* Disable interrupts on the PLX before resetting it */
4916 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 4833 cy_writew(addr0 + 0x68,
4917 j + 1, (ulong)cy_pci_phys2, 4834 readw(addr0 + 0x68) & ~0x0900);
4918 (ulong) (cy_pci_phys2 + CyPCI_Ywin - 1), 4835
4919 (int)cy_pci_irq); 4836 plx_init(addr0, 0x6c);
4920 printk("%d channels starting from port %d.\n", 4837 /* For some yet unknown reason, once the PLX9060 reloads
4921 cy_pci_nchan, cy_next_channel); 4838 the EEPROM, the IRQ is lost and, thus, we have to
4922 4839 re-write it to the PCI config. registers.
4923 cy_next_channel += cy_pci_nchan; 4840 This will remain here until we find a permanent
4924 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo) { 4841 fix. */
4925 /* print message */ 4842 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, irq);
4926 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ", 4843
4927 pdev->bus->number, pdev->devfn); 4844 mailbox = (u32)readl(&ctl_addr->mail_box_0);
4928 printk("rev_id=%d) IRQ%d\n", 4845
4929 cyy_rev_id, (int)cy_pci_irq); 4846 addr2 = pci_iomap(pdev, 2, mailbox == ZE_V1 ?
4930 printk("Cyclades-Z/PCI: found winaddr=0x%lx " 4847 CyPCI_Ze_win : CyPCI_Zwin);
4931 "ctladdr=0x%lx\n", 4848 if (addr2 == NULL) {
4932 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4849 dev_err(&pdev->dev, "can't remap base region\n");
4933 printk("Cyclades-Z/PCI not supported for low " 4850 goto err_unmap;
4934 "addresses\n"); 4851 }
4935 break;
4936 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
4937#ifdef CY_PCI_DEBUG
4938 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4939 pdev->bus->number, pdev->devfn);
4940 printk("rev_id=%d) IRQ%d\n",
4941 cyy_rev_id, (int)cy_pci_irq);
4942 printk("Cyclades-Z/PCI: found winaddr=0x%lx "
4943 "ctladdr=0x%lx\n",
4944 (ulong) cy_pci_phys2, (ulong) cy_pci_phys0);
4945#endif
4946 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Zctl);
4947
4948 /* Disable interrupts on the PLX before resetting it */
4949 cy_writew(cy_pci_addr0 + 0x68,
4950 cy_readw(cy_pci_addr0 + 0x68) & ~0x0900);
4951
4952 plx_init(cy_pci_addr0, 0x6c);
4953 /* For some yet unknown reason, once the PLX9060 reloads
4954 the EEPROM, the IRQ is lost and, thus, we have to
4955 re-write it to the PCI config. registers.
4956 This will remain here until we find a permanent
4957 fix. */
4958 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4959 cy_pci_irq);
4960
4961 mailbox =
4962 (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
4963 cy_pci_addr0)->mail_box_0);
4964
4965 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4966 printk(" Warning: PCI I/O bit incorrectly "
4967 "set. Ignoring it...\n");
4968 pdev->resource[2].flags &= ~IORESOURCE_IO;
4969 }
4970 4852
4971 /* Although we don't use this I/O region, we should 4853 if (mailbox == ZE_V1) {
4972 request it from the kernel anyway, to avoid problems 4854 card_name = "Cyclades-Ze";
4973 with other drivers accessing it. */
4974 if (pci_request_regions(pdev, "Cyclades-Z") != 0) {
4975 printk(KERN_ERR "cyclades: failed to reserve "
4976 "PCI resources\n");
4977 continue;
4978 }
4979 4855
4980 if (mailbox == ZE_V1) { 4856 readl(&ctl_addr->mail_box_0);
4981 cy_pci_addr2 = ioremap(cy_pci_phys2, 4857 nchan = ZE_V1_NPORTS;
4982 CyPCI_Ze_win); 4858 } else {
4983 if (ZeIndex == NR_CARDS) { 4859 card_name = "Cyclades-8Zo";
4984 printk("Cyclades-Ze/PCI found at "
4985 "0x%lx but no more cards can "
4986 "be used.\nChange NR_CARDS in "
4987 "cyclades.c and recompile "
4988 "kernel.\n",
4989 (ulong)cy_pci_phys2);
4990 } else {
4991 Ze_phys0[ZeIndex] = cy_pci_phys0;
4992 Ze_phys2[ZeIndex] = cy_pci_phys2;
4993 Ze_addr0[ZeIndex] = cy_pci_addr0;
4994 Ze_addr2[ZeIndex] = cy_pci_addr2;
4995 Ze_irq[ZeIndex] = cy_pci_irq;
4996 Ze_pdev[ZeIndex] = pdev;
4997 ZeIndex++;
4998 }
4999 i--;
5000 continue;
5001 } else {
5002 cy_pci_addr2 = ioremap(cy_pci_phys2,CyPCI_Zwin);
5003 }
5004 4860
5005#ifdef CY_PCI_DEBUG 4861#ifdef CY_PCI_DEBUG
5006 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx "
5007 "ctladdr=0x%lx\n",
5008 (ulong) cy_pci_addr2, (ulong) cy_pci_addr0);
5009 if (mailbox == ZO_V1) { 4862 if (mailbox == ZO_V1) {
5010 cy_writel(&((struct RUNTIME_9060 *) 4863 cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
5011 (cy_pci_addr0))->loc_addr_base, 4864 dev_info(&pdev->dev, "Cyclades-8Zo/PCI: FPGA "
5012 WIN_CREG); 4865 "id %lx, ver %lx\n", (ulong)(0xff &
5013 PAUSE; 4866 readl(&((struct CUSTOM_REG *)addr2)->
5014 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver " 4867 fpga_id)), (ulong)(0xff &
5015 "%lx\n", (ulong) (0xff & 4868 readl(&((struct CUSTOM_REG *)addr2)->
5016 cy_readl(&((struct CUSTOM_REG *) 4869 fpga_version)));
5017 (cy_pci_addr2))->fpga_id)), 4870 cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
5018 (ulong)(0xff &
5019 cy_readl(&((struct CUSTOM_REG *)
5020 (cy_pci_addr2))->
5021 fpga_version)));
5022 cy_writel(&((struct RUNTIME_9060 *)
5023 (cy_pci_addr0))->loc_addr_base,
5024 WIN_RAM);
5025 } else { 4871 } else {
5026 printk("Cyclades-Z/PCI: New Cyclades-Z board. " 4872 dev_info(&pdev->dev, "Cyclades-Z/PCI: New "
5027 "FPGA not loaded\n"); 4873 "Cyclades-Z board. FPGA not loaded\n");
5028 } 4874 }
5029#endif 4875#endif
5030 /* The following clears the firmware id word. This 4876 /* The following clears the firmware id word. This
5031 ensures that the driver will not attempt to talk to 4877 ensures that the driver will not attempt to talk to
5032 the board until it has been properly initialized. 4878 the board until it has been properly initialized.
5033 */ 4879 */
5034 PAUSE;
5035 if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) 4880 if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
5036 cy_writel(cy_pci_addr2 + ID_ADDRESS, 0L); 4881 cy_writel(addr2 + ID_ADDRESS, 0L);
5037 4882
5038 /* This must be a Cyclades-8Zo/PCI. The extendable 4883 /* This must be a Cyclades-8Zo/PCI. The extendable
5039 version will have a different device_id and will 4884 version will have a different device_id and will
5040 be allocated its maximum number of ports. */ 4885 be allocated its maximum number of ports. */
5041 cy_pci_nchan = 8; 4886 nchan = 8;
5042
5043 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
5044 printk("Cyclades-8Zo/PCI found at 0x%lx but"
5045 "no channels are available.\nChange "
5046 "NR_PORTS in cyclades.c and recompile "
5047 "kernel.\n", (ulong)cy_pci_phys2);
5048 return i;
5049 }
5050
5051 /* fill the next cy_card structure available */
5052 for (j = 0; j < NR_CARDS; j++) {
5053 if (cy_card[j].base_addr == 0)
5054 break;
5055 }
5056 if (j == NR_CARDS) { /* no more cy_cards available */
5057 printk("Cyclades-8Zo/PCI found at 0x%lx but"
5058 "no more cards can be used.\nChange "
5059 "NR_CARDS in cyclades.c and recompile "
5060 "kernel.\n", (ulong)cy_pci_phys2);
5061 return i;
5062 }
5063#ifdef CONFIG_CYZ_INTR
5064 /* allocate IRQ only if board has an IRQ */
5065 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
5066 if (request_irq(cy_pci_irq, cyz_interrupt,
5067 IRQF_SHARED, "Cyclades-Z",
5068 &cy_card[j])) {
5069 printk("Cyclom-8Zo/PCI found at 0x%lx "
5070 "but could not allocate "
5071 "IRQ%d.\n", (ulong)cy_pci_phys2,
5072 cy_pci_irq);
5073 return i;
5074 }
5075 }
5076#endif /* CONFIG_CYZ_INTR */
5077
5078 /* set cy_card */
5079 cy_card[j].base_phys = cy_pci_phys2;
5080 cy_card[j].ctl_phys = cy_pci_phys0;
5081 cy_card[j].base_addr = cy_pci_addr2;
5082 cy_card[j].ctl_addr = cy_pci_addr0;
5083 cy_card[j].irq = (int)cy_pci_irq;
5084 cy_card[j].bus_index = 1;
5085 cy_card[j].first_line = cy_next_channel;
5086 cy_card[j].num_chips = -1;
5087 cy_card[j].pdev = pdev;
5088
5089 /* print message */
5090#ifdef CONFIG_CYZ_INTR
5091 /* don't report IRQ if board is no IRQ */
5092 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
5093 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, "
5094 "IRQ%d, ", j + 1, (ulong)cy_pci_phys2,
5095 (ulong) (cy_pci_phys2 + CyPCI_Zwin - 1),
5096 (int)cy_pci_irq);
5097 else
5098#endif /* CONFIG_CYZ_INTR */
5099 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
5100 j + 1, (ulong)cy_pci_phys2,
5101 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1));
5102
5103 printk("%d channels starting from port %d.\n",
5104 cy_pci_nchan, cy_next_channel);
5105 cy_next_channel += cy_pci_nchan;
5106 } 4887 }
5107 } 4888 }
5108 4889
5109 for (; ZeIndex != 0 && i < NR_CARDS; i++) { 4890 if ((cy_next_channel + nchan) > NR_PORTS) {
5110 cy_pci_phys0 = Ze_phys0[0]; 4891 dev_err(&pdev->dev, "Cyclades-8Zo/PCI found, but no "
5111 cy_pci_phys2 = Ze_phys2[0]; 4892 "channels are available. Change NR_PORTS in "
5112 cy_pci_addr0 = Ze_addr0[0]; 4893 "cyclades.c and recompile kernel.\n");
5113 cy_pci_addr2 = Ze_addr2[0]; 4894 goto err_unmap;
5114 cy_pci_irq = Ze_irq[0]; 4895 }
5115 pdev = Ze_pdev[0]; 4896 /* fill the next cy_card structure available */
5116 for (j = 0; j < ZeIndex - 1; j++) { 4897 for (card_no = 0; card_no < NR_CARDS; card_no++) {
5117 Ze_phys0[j] = Ze_phys0[j + 1]; 4898 if (cy_card[card_no].base_addr == NULL)
5118 Ze_phys2[j] = Ze_phys2[j + 1]; 4899 break;
5119 Ze_addr0[j] = Ze_addr0[j + 1]; 4900 }
5120 Ze_addr2[j] = Ze_addr2[j + 1]; 4901 if (card_no == NR_CARDS) { /* no more cy_cards available */
5121 Ze_irq[j] = Ze_irq[j + 1]; 4902 dev_err(&pdev->dev, "Cyclades-8Zo/PCI found, but no "
5122 Ze_pdev[j] = Ze_pdev[j + 1]; 4903 "more cards can be used. Change NR_CARDS in "
5123 } 4904 "cyclades.c and recompile kernel.\n");
5124 ZeIndex--; 4905 goto err_unmap;
5125 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *) 4906 }
5126 cy_pci_addr0)->mail_box_0);
5127#ifdef CY_PCI_DEBUG
5128 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5129 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
5130 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not "
5131 "loaded\n");
5132#endif
5133 PAUSE;
5134 /* This must be the new Cyclades-Ze/PCI. */
5135 cy_pci_nchan = ZE_V1_NPORTS;
5136
5137 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
5138 printk("Cyclades-Ze/PCI found at 0x%lx but no channels "
5139 "are available.\nChange NR_PORTS in cyclades.c "
5140 "and recompile kernel.\n",
5141 (ulong) cy_pci_phys2);
5142 return i;
5143 }
5144 4907
5145 /* fill the next cy_card structure available */ 4908 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
5146 for (j = 0; j < NR_CARDS; j++) { 4909 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
5147 if (cy_card[j].base_addr == 0) 4910 /* allocate IRQ */
5148 break; 4911 retval = request_irq(irq, cyy_interrupt,
5149 } 4912 IRQF_SHARED, "Cyclom-Y", &cy_card[card_no]);
5150 if (j == NR_CARDS) { /* no more cy_cards available */ 4913 if (retval) {
5151 printk("Cyclades-Ze/PCI found at 0x%lx but no more " 4914 dev_err(&pdev->dev, "could not allocate IRQ\n");
5152 "cards can be used.\nChange NR_CARDS in " 4915 goto err_unmap;
5153 "cyclades.c and recompile kernel.\n",
5154 (ulong) cy_pci_phys2);
5155 return i;
5156 } 4916 }
4917 cy_card[card_no].num_chips = nchan / 4;
4918 } else {
5157#ifdef CONFIG_CYZ_INTR 4919#ifdef CONFIG_CYZ_INTR
5158 /* allocate IRQ only if board has an IRQ */ 4920 /* allocate IRQ only if board has an IRQ */
5159 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) { 4921 if (irq != 0 && irq != 255) {
5160 if (request_irq(cy_pci_irq, cyz_interrupt, 4922 retval = request_irq(irq, cyz_interrupt,
5161 IRQF_SHARED, "Cyclades-Z", 4923 IRQF_SHARED, "Cyclades-Z",
5162 &cy_card[j])) { 4924 &cy_card[card_no]);
5163 printk("Cyclom-Ze/PCI found at 0x%lx ", 4925 if (retval) {
5164 (ulong) cy_pci_phys2); 4926 dev_err(&pdev->dev, "could not allocate IRQ\n");
5165 printk("but could not allocate IRQ%d.\n", 4927 goto err_unmap;
5166 cy_pci_irq);
5167 return i;
5168 } 4928 }
5169 } 4929 }
5170#endif /* CONFIG_CYZ_INTR */ 4930#endif /* CONFIG_CYZ_INTR */
4931 cy_card[card_no].num_chips = -1;
4932 }
5171 4933
5172 /* set cy_card */ 4934 /* set cy_card */
5173 cy_card[j].base_phys = cy_pci_phys2; 4935 cy_card[card_no].base_addr = addr2;
5174 cy_card[j].ctl_phys = cy_pci_phys0; 4936 cy_card[card_no].ctl_addr = addr0;
5175 cy_card[j].base_addr = cy_pci_addr2; 4937 cy_card[card_no].irq = irq;
5176 cy_card[j].ctl_addr = cy_pci_addr0; 4938 cy_card[card_no].bus_index = 1;
5177 cy_card[j].irq = (int)cy_pci_irq; 4939 cy_card[card_no].first_line = cy_next_channel;
5178 cy_card[j].bus_index = 1; 4940 retval = cy_init_card(&cy_card[card_no]);
5179 cy_card[j].first_line = cy_next_channel; 4941 if (retval)
5180 cy_card[j].num_chips = -1; 4942 goto err_null;
5181 cy_card[j].pdev = pdev;
5182 4943
5183 /* print message */ 4944 pci_set_drvdata(pdev, &cy_card[card_no]);
5184#ifdef CONFIG_CYZ_INTR
5185 /* don't report IRQ if board is no IRQ */
5186 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
5187 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5188 j + 1, (ulong) cy_pci_phys2,
5189 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1),
5190 (int)cy_pci_irq);
5191 else
5192#endif /* CONFIG_CYZ_INTR */
5193 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5194 j + 1, (ulong) cy_pci_phys2,
5195 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1));
5196 4945
5197 printk("%d channels starting from port %d.\n", 4946 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
5198 cy_pci_nchan, cy_next_channel); 4947 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
5199 cy_next_channel += cy_pci_nchan; 4948 /* enable interrupts in the PCI interface */
5200 } 4949 plx_ver = readb(addr2 + CyPLX_VER) & 0x0f;
5201 if (ZeIndex != 0) { 4950 switch (plx_ver) {
5202 printk("Cyclades-Ze/PCI found at 0x%x but no more cards can be " 4951 case PLX_9050:
5203 "used.\nChange NR_CARDS in cyclades.c and recompile " 4952
5204 "kernel.\n", (unsigned int)Ze_phys2[0]); 4953 cy_writeb(addr0 + 0x4c, 0x43);
4954 break;
4955
4956 case PLX_9060:
4957 case PLX_9080:
4958 default: /* Old boards, use PLX_9060 */
4959
4960 plx_init(addr0, 0x6c);
4961 /* For some yet unknown reason, once the PLX9060 reloads
4962 the EEPROM, the IRQ is lost and, thus, we have to
4963 re-write it to the PCI config. registers.
4964 This will remain here until we find a permanent
4965 fix. */
4966 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, irq);
4967
4968 cy_writew(addr0 + 0x68, readw(addr0 + 0x68) | 0x0900);
4969 break;
4970 }
5205 } 4971 }
5206 return i; 4972
5207#else 4973 dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from "
4974 "port %d.\n", card_name, card_no + 1, nchan, cy_next_channel);
4975 for (i = cy_next_channel; i < cy_next_channel + nchan; i++)
4976 tty_register_device(cy_serial_driver, i, &pdev->dev);
4977 cy_next_channel += nchan;
4978
5208 return 0; 4979 return 0;
5209#endif /* ifdef CONFIG_PCI */ 4980err_null:
5210} /* cy_detect_pci */ 4981 cy_card[card_no].base_addr = NULL;
4982 free_irq(irq, &cy_card[card_no]);
4983err_unmap:
4984 pci_iounmap(pdev, addr0);
4985 if (addr2)
4986 pci_iounmap(pdev, addr2);
4987err_reg:
4988 pci_release_regions(pdev);
4989err_dis:
4990 pci_disable_device(pdev);
4991err:
4992 return retval;
4993}
5211 4994
5212/* 4995static void __devexit cy_pci_remove(struct pci_dev *pdev)
5213 * This routine prints out the appropriate serial driver version number
5214 * and identifies which options were configured into this driver.
5215 */
5216static inline void show_version(void)
5217{ 4996{
5218 printk("Cyclades driver " CY_VERSION "\n"); 4997 struct cyclades_card *cinfo = pci_get_drvdata(pdev);
5219 printk(" built %s %s\n", __DATE__, __TIME__); 4998 unsigned int i;
5220} /* show_version */ 4999
5000 /* non-Z with old PLX */
5001 if (!IS_CYC_Z(*cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) ==
5002 PLX_9050)
5003 cy_writeb(cinfo->ctl_addr + 0x4c, 0);
5004 else
5005#ifndef CONFIG_CYZ_INTR
5006 if (!IS_CYC_Z(*cinfo))
5007#endif
5008 cy_writew(cinfo->ctl_addr + 0x68,
5009 readw(cinfo->ctl_addr + 0x68) & ~0x0900);
5010
5011 pci_iounmap(pdev, cinfo->base_addr);
5012 if (cinfo->ctl_addr)
5013 pci_iounmap(pdev, cinfo->ctl_addr);
5014 if (cinfo->irq
5015#ifndef CONFIG_CYZ_INTR
5016 && !IS_CYC_Z(*cinfo)
5017#endif /* CONFIG_CYZ_INTR */
5018 )
5019 free_irq(cinfo->irq, cinfo);
5020 pci_release_regions(pdev);
5021
5022 cinfo->base_addr = NULL;
5023 for (i = cinfo->first_line; i < cinfo->first_line +
5024 cinfo->nports; i++)
5025 tty_unregister_device(cy_serial_driver, i);
5026 cinfo->nports = 0;
5027 kfree(cinfo->ports);
5028}
5029
5030static struct pci_driver cy_pci_driver = {
5031 .name = "cyclades",
5032 .id_table = cy_pci_dev_id,
5033 .probe = cy_pci_probe,
5034 .remove = __devexit_p(cy_pci_remove)
5035};
5036#endif
5221 5037
5222static int 5038static int
5223cyclades_get_proc_info(char *buf, char **start, off_t offset, int length, 5039cyclades_get_proc_info(char *buf, char **start, off_t offset, int length,
5224 int *eof, void *data) 5040 int *eof, void *data)
5225{ 5041{
5226 struct cyclades_port *info; 5042 struct cyclades_port *info;
5227 int i; 5043 unsigned int i, j;
5228 int len = 0; 5044 int len = 0;
5229 off_t begin = 0; 5045 off_t begin = 0;
5230 off_t pos = 0; 5046 off_t pos = 0;
@@ -5238,33 +5054,34 @@ cyclades_get_proc_info(char *buf, char **start, off_t offset, int length,
5238 len += size; 5054 len += size;
5239 5055
5240 /* Output one line for each known port */ 5056 /* Output one line for each known port */
5241 for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) { 5057 for (i = 0; i < NR_CARDS; i++)
5242 info = &cy_port[i]; 5058 for (j = 0; j < cy_card[i].nports; j++) {
5243 5059 info = &cy_card[i].ports[j];
5244 if (info->count) 5060
5245 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu " 5061 if (info->count)
5246 "%8lu %9lu %6ld\n", info->line, 5062 size = sprintf(buf + len, "%3d %8lu %10lu %8lu "
5247 (cur_jifs - info->idle_stats.in_use) / HZ, 5063 "%10lu %8lu %9lu %6ld\n", info->line,
5248 info->idle_stats.xmit_bytes, 5064 (cur_jifs - info->idle_stats.in_use) /
5249 (cur_jifs - info->idle_stats.xmit_idle) / HZ, 5065 HZ, info->idle_stats.xmit_bytes,
5250 info->idle_stats.recv_bytes, 5066 (cur_jifs - info->idle_stats.xmit_idle)/
5251 (cur_jifs - info->idle_stats.recv_idle) / HZ, 5067 HZ, info->idle_stats.recv_bytes,
5252 info->idle_stats.overruns, 5068 (cur_jifs - info->idle_stats.recv_idle)/
5253 (long)info->tty->ldisc.num); 5069 HZ, info->idle_stats.overruns,
5254 else 5070 (long)info->tty->ldisc.num);
5255 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu " 5071 else
5256 "%8lu %9lu %6ld\n", 5072 size = sprintf(buf + len, "%3d %8lu %10lu %8lu "
5257 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L); 5073 "%10lu %8lu %9lu %6ld\n",
5258 len += size; 5074 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5259 pos = begin + len; 5075 len += size;
5260 5076 pos = begin + len;
5261 if (pos < offset) { 5077
5262 len = 0; 5078 if (pos < offset) {
5263 begin = pos; 5079 len = 0;
5080 begin = pos;
5081 }
5082 if (pos > offset + length)
5083 goto done;
5264 } 5084 }
5265 if (pos > offset + length)
5266 goto done;
5267 }
5268 *eof = 1; 5085 *eof = 1;
5269done: 5086done:
5270 *start = buf + (offset - begin); /* Start of wanted data */ 5087 *start = buf + (offset - begin); /* Start of wanted data */
@@ -5319,18 +5136,15 @@ static const struct tty_operations cy_ops = {
5319 5136
5320static int __init cy_init(void) 5137static int __init cy_init(void)
5321{ 5138{
5322 struct cyclades_port *info; 5139 unsigned int nboards;
5323 struct cyclades_card *cinfo; 5140 int retval = -ENOMEM;
5324 int number_z_boards = 0;
5325 int board, port, i, index;
5326 unsigned long mailbox;
5327 unsigned short chip_number;
5328 int nports;
5329 5141
5330 cy_serial_driver = alloc_tty_driver(NR_PORTS); 5142 cy_serial_driver = alloc_tty_driver(NR_PORTS);
5331 if (!cy_serial_driver) 5143 if (!cy_serial_driver)
5332 return -ENOMEM; 5144 goto err;
5333 show_version(); 5145
5146 printk(KERN_INFO "Cyclades driver " CY_VERSION " (built %s %s)\n",
5147 __DATE__, __TIME__);
5334 5148
5335 /* Initialize the tty_driver structure */ 5149 /* Initialize the tty_driver structure */
5336 5150
@@ -5344,15 +5158,13 @@ static int __init cy_init(void)
5344 cy_serial_driver->init_termios = tty_std_termios; 5158 cy_serial_driver->init_termios = tty_std_termios;
5345 cy_serial_driver->init_termios.c_cflag = 5159 cy_serial_driver->init_termios.c_cflag =
5346 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 5160 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
5347 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW; 5161 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
5348 tty_set_operations(cy_serial_driver, &cy_ops); 5162 tty_set_operations(cy_serial_driver, &cy_ops);
5349 5163
5350 if (tty_register_driver(cy_serial_driver)) 5164 retval = tty_register_driver(cy_serial_driver);
5351 panic("Couldn't register Cyclades serial driver\n"); 5165 if (retval) {
5352 5166 printk(KERN_ERR "Couldn't register Cyclades serial driver\n");
5353 for (i = 0; i < NR_CARDS; i++) { 5167 goto err_frtty;
5354 /* base_addr=0 indicates board not found */
5355 cy_card[i].base_addr = NULL;
5356 } 5168 }
5357 5169
5358 /* the code below is responsible to find the boards. Each different 5170 /* the code below is responsible to find the boards. Each different
@@ -5363,223 +5175,68 @@ static int __init cy_init(void)
5363 the cy_next_channel. */ 5175 the cy_next_channel. */
5364 5176
5365 /* look for isa boards */ 5177 /* look for isa boards */
5366 cy_isa_nboard = cy_detect_isa(); 5178 nboards = cy_detect_isa();
5367 5179
5180#ifdef CONFIG_PCI
5368 /* look for pci boards */ 5181 /* look for pci boards */
5369 cy_pci_nboard = cy_detect_pci(); 5182 retval = pci_register_driver(&cy_pci_driver);
5370 5183 if (retval && !nboards)
5371 cy_nboard = cy_isa_nboard + cy_pci_nboard; 5184 goto err_unr;
5372
5373 /* invalidate remaining cy_card structures */
5374 for (i = 0; i < NR_CARDS; i++) {
5375 if (cy_card[i].base_addr == 0) {
5376 cy_card[i].first_line = -1;
5377 cy_card[i].ctl_addr = NULL;
5378 cy_card[i].irq = 0;
5379 cy_card[i].bus_index = 0;
5380 cy_card[i].first_line = 0;
5381 cy_card[i].num_chips = 0;
5382 }
5383 }
5384 /* invalidate remaining cy_port structures */
5385 for (i = cy_next_channel; i < NR_PORTS; i++) {
5386 cy_port[i].line = -1;
5387 cy_port[i].magic = -1;
5388 }
5389
5390 /* initialize per-port data structures for each valid board found */
5391 for (board = 0; board < cy_nboard; board++) {
5392 cinfo = &cy_card[board];
5393 if (cinfo->num_chips == -1) { /* Cyclades-Z */
5394 number_z_boards++;
5395 mailbox = cy_readl(&((struct RUNTIME_9060 __iomem *)
5396 cy_card[board].ctl_addr)->
5397 mail_box_0);
5398 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
5399 cinfo->intr_enabled = 0;
5400 cinfo->nports = 0; /* Will be correctly set later, after
5401 Z FW is loaded */
5402 spin_lock_init(&cinfo->card_lock);
5403 for (port = cinfo->first_line;
5404 port < cinfo->first_line + nports; port++) {
5405 info = &cy_port[port];
5406 info->magic = CYCLADES_MAGIC;
5407 info->type = PORT_STARTECH;
5408 info->card = board;
5409 info->line = port;
5410 info->chip_rev = 0;
5411 info->flags = STD_COM_FLAGS;
5412 info->tty = NULL;
5413 if (mailbox == ZO_V1)
5414 info->xmit_fifo_size = CYZ_FIFO_SIZE;
5415 else
5416 info->xmit_fifo_size =
5417 4 * CYZ_FIFO_SIZE;
5418 info->cor1 = 0;
5419 info->cor2 = 0;
5420 info->cor3 = 0;
5421 info->cor4 = 0;
5422 info->cor5 = 0;
5423 info->tbpr = 0;
5424 info->tco = 0;
5425 info->rbpr = 0;
5426 info->rco = 0;
5427 info->custom_divisor = 0;
5428 info->close_delay = 5 * HZ / 10;
5429 info->closing_wait = CLOSING_WAIT_DELAY;
5430 info->icount.cts = info->icount.dsr =
5431 info->icount.rng = info->icount.dcd = 0;
5432 info->icount.rx = info->icount.tx = 0;
5433 info->icount.frame = info->icount.parity = 0;
5434 info->icount.overrun = info->icount.brk = 0;
5435 info->x_char = 0;
5436 info->event = 0;
5437 info->count = 0;
5438 info->blocked_open = 0;
5439 info->default_threshold = 0;
5440 info->default_timeout = 0;
5441 INIT_WORK(&info->tqueue, do_softint);
5442 init_waitqueue_head(&info->open_wait);
5443 init_waitqueue_head(&info->close_wait);
5444 init_waitqueue_head(&info->shutdown_wait);
5445 init_waitqueue_head(&info->delta_msr_wait);
5446 /* info->session */
5447 /* info->pgrp */
5448 info->read_status_mask = 0;
5449 /* info->timeout */
5450 /* Bentson's vars */
5451 info->jiffies[0] = 0;
5452 info->jiffies[1] = 0;
5453 info->jiffies[2] = 0;
5454 info->rflush_count = 0;
5455#ifdef CONFIG_CYZ_INTR
5456 init_timer(&cyz_rx_full_timer[port]);
5457 cyz_rx_full_timer[port].function = NULL;
5458#endif 5185#endif
5459 }
5460 continue;
5461 } else { /* Cyclom-Y of some kind */
5462 index = cinfo->bus_index;
5463 spin_lock_init(&cinfo->card_lock);
5464 cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
5465 for (port = cinfo->first_line;
5466 port < cinfo->first_line + cinfo->nports; port++) {
5467 info = &cy_port[port];
5468 info->magic = CYCLADES_MAGIC;
5469 info->type = PORT_CIRRUS;
5470 info->card = board;
5471 info->line = port;
5472 info->flags = STD_COM_FLAGS;
5473 info->tty = NULL;
5474 info->xmit_fifo_size = CyMAX_CHAR_FIFO;
5475 info->cor1 =
5476 CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS;
5477 info->cor2 = CyETC;
5478 info->cor3 = 0x08; /* _very_ small rcv threshold */
5479 info->cor4 = 0;
5480 info->cor5 = 0;
5481 info->custom_divisor = 0;
5482 info->close_delay = 5 * HZ / 10;
5483 info->closing_wait = CLOSING_WAIT_DELAY;
5484 info->icount.cts = info->icount.dsr =
5485 info->icount.rng = info->icount.dcd = 0;
5486 info->icount.rx = info->icount.tx = 0;
5487 info->icount.frame = info->icount.parity = 0;
5488 info->icount.overrun = info->icount.brk = 0;
5489 chip_number = (port - cinfo->first_line) / 4;
5490 if ((info->chip_rev =
5491 cy_readb(cinfo->base_addr +
5492 (cy_chip_offset[chip_number] <<
5493 index) + (CyGFRCR << index))) >=
5494 CD1400_REV_J) {
5495 /* It is a CD1400 rev. J or later */
5496 info->tbpr = baud_bpr_60[13]; /* Tx BPR */
5497 info->tco = baud_co_60[13]; /* Tx CO */
5498 info->rbpr = baud_bpr_60[13]; /* Rx BPR */
5499 info->rco = baud_co_60[13]; /* Rx CO */
5500 info->rflow = 0;
5501 info->rtsdtr_inv = 1;
5502 } else {
5503 info->tbpr = baud_bpr_25[13]; /* Tx BPR */
5504 info->tco = baud_co_25[13]; /* Tx CO */
5505 info->rbpr = baud_bpr_25[13]; /* Rx BPR */
5506 info->rco = baud_co_25[13]; /* Rx CO */
5507 info->rflow = 0;
5508 info->rtsdtr_inv = 0;
5509 }
5510 info->x_char = 0;
5511 info->event = 0;
5512 info->count = 0;
5513 info->blocked_open = 0;
5514 info->default_threshold = 0;
5515 info->default_timeout = 0;
5516 INIT_WORK(&info->tqueue, do_softint);
5517 init_waitqueue_head(&info->open_wait);
5518 init_waitqueue_head(&info->close_wait);
5519 init_waitqueue_head(&info->shutdown_wait);
5520 init_waitqueue_head(&info->delta_msr_wait);
5521 /* info->session */
5522 /* info->pgrp */
5523 info->read_status_mask =
5524 CyTIMEOUT | CySPECHAR | CyBREAK
5525 | CyPARITY | CyFRAME | CyOVERRUN;
5526 /* info->timeout */
5527 }
5528 }
5529 }
5530
5531#ifndef CONFIG_CYZ_INTR
5532 if (number_z_boards && !cyz_timeron) {
5533 cyz_timeron++;
5534 cyz_timerlist.expires = jiffies + 1;
5535 add_timer(&cyz_timerlist);
5536#ifdef CY_PCI_DEBUG
5537 printk("Cyclades-Z polling initialized\n");
5538#endif
5539 }
5540#endif /* CONFIG_CYZ_INTR */
5541 5186
5542 return 0; 5187 return 0;
5543 5188err_unr:
5189 tty_unregister_driver(cy_serial_driver);
5190err_frtty:
5191 put_tty_driver(cy_serial_driver);
5192err:
5193 return retval;
5544} /* cy_init */ 5194} /* cy_init */
5545 5195
5546static void __exit cy_cleanup_module(void) 5196static void __exit cy_cleanup_module(void)
5547{ 5197{
5198 struct cyclades_card *card;
5548 int i, e1; 5199 int i, e1;
5549 5200
5550#ifndef CONFIG_CYZ_INTR 5201#ifndef CONFIG_CYZ_INTR
5551 if (cyz_timeron){ 5202 del_timer_sync(&cyz_timerlist);
5552 cyz_timeron = 0;
5553 del_timer(&cyz_timerlist);
5554 }
5555#endif /* CONFIG_CYZ_INTR */ 5203#endif /* CONFIG_CYZ_INTR */
5556 5204
5557 if ((e1 = tty_unregister_driver(cy_serial_driver))) 5205 if ((e1 = tty_unregister_driver(cy_serial_driver)))
5558 printk("cyc: failed to unregister Cyclades serial driver(%d)\n", 5206 printk(KERN_ERR "failed to unregister Cyclades serial "
5559 e1); 5207 "driver(%d)\n", e1);
5560 5208
5561 put_tty_driver(cy_serial_driver); 5209#ifdef CONFIG_PCI
5210 pci_unregister_driver(&cy_pci_driver);
5211#endif
5562 5212
5563 for (i = 0; i < NR_CARDS; i++) { 5213 for (i = 0; i < NR_CARDS; i++) {
5564 if (cy_card[i].base_addr) { 5214 card = &cy_card[i];
5565 iounmap(cy_card[i].base_addr); 5215 if (card->base_addr) {
5566 if (cy_card[i].ctl_addr) 5216 /* clear interrupt */
5567 iounmap(cy_card[i].ctl_addr); 5217 cy_writeb(card->base_addr + Cy_ClrIntr, 0);
5568 if (cy_card[i].irq 5218 iounmap(card->base_addr);
5219 if (card->ctl_addr)
5220 iounmap(card->ctl_addr);
5221 if (card->irq
5569#ifndef CONFIG_CYZ_INTR 5222#ifndef CONFIG_CYZ_INTR
5570 && cy_card[i].num_chips != -1 /* not a Z card */ 5223 && !IS_CYC_Z(*card)
5571#endif /* CONFIG_CYZ_INTR */ 5224#endif /* CONFIG_CYZ_INTR */
5572 ) 5225 )
5573 free_irq(cy_card[i].irq, &cy_card[i]); 5226 free_irq(card->irq, card);
5574#ifdef CONFIG_PCI 5227 for (e1 = card->first_line;
5575 if (cy_card[i].pdev) 5228 e1 < card->first_line +
5576 pci_release_regions(cy_card[i].pdev); 5229 card->nports; e1++)
5577#endif 5230 tty_unregister_device(cy_serial_driver, e1);
5231 kfree(card->ports);
5578 } 5232 }
5579 } 5233 }
5234
5235 put_tty_driver(cy_serial_driver);
5580} /* cy_cleanup_module */ 5236} /* cy_cleanup_module */
5581 5237
5582module_init(cy_init); 5238module_init(cy_init);
5583module_exit(cy_cleanup_module); 5239module_exit(cy_cleanup_module);
5584 5240
5585MODULE_LICENSE("GPL"); 5241MODULE_LICENSE("GPL");
5242MODULE_VERSION(CY_VERSION);
diff --git a/drivers/char/digi.h b/drivers/char/digi.h
deleted file mode 100644
index 19df0e879b1b..000000000000
--- a/drivers/char/digi.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/* Definitions for DigiBoard ditty(1) command. */
2
3#if !defined(TIOCMODG)
4#define TIOCMODG (('d'<<8) | 250) /* get modem ctrl state */
5#define TIOCMODS (('d'<<8) | 251) /* set modem ctrl state */
6#endif
7
8#if !defined(TIOCMSET)
9#define TIOCMSET (('d'<<8) | 252) /* set modem ctrl state */
10#define TIOCMGET (('d'<<8) | 253) /* set modem ctrl state */
11#endif
12
13#if !defined(TIOCMBIC)
14#define TIOCMBIC (('d'<<8) | 254) /* set modem ctrl state */
15#define TIOCMBIS (('d'<<8) | 255) /* set modem ctrl state */
16#endif
17
18#if !defined(TIOCSDTR)
19#define TIOCSDTR (('e'<<8) | 0) /* set DTR */
20#define TIOCCDTR (('e'<<8) | 1) /* clear DTR */
21#endif
22
23/************************************************************************
24 * Ioctl command arguments for DIGI parameters.
25 ************************************************************************/
26#define DIGI_GETA (('e'<<8) | 94) /* Read params */
27
28#define DIGI_SETA (('e'<<8) | 95) /* Set params */
29#define DIGI_SETAW (('e'<<8) | 96) /* Drain & set params */
30#define DIGI_SETAF (('e'<<8) | 97) /* Drain, flush & set params */
31
32#define DIGI_GETFLOW (('e'<<8) | 99) /* Get startc/stopc flow */
33 /* control characters */
34#define DIGI_SETFLOW (('e'<<8) | 100) /* Set startc/stopc flow */
35 /* control characters */
36#define DIGI_GETAFLOW (('e'<<8) | 101) /* Get Aux. startc/stopc */
37 /* flow control chars */
38#define DIGI_SETAFLOW (('e'<<8) | 102) /* Set Aux. startc/stopc */
39 /* flow control chars */
40
41struct digiflow_struct {
42 unsigned char startc; /* flow cntl start char */
43 unsigned char stopc; /* flow cntl stop char */
44};
45
46typedef struct digiflow_struct digiflow_t;
47
48
49/************************************************************************
50 * Values for digi_flags
51 ************************************************************************/
52#define DIGI_IXON 0x0001 /* Handle IXON in the FEP */
53#define DIGI_FAST 0x0002 /* Fast baud rates */
54#define RTSPACE 0x0004 /* RTS input flow control */
55#define CTSPACE 0x0008 /* CTS output flow control */
56#define DSRPACE 0x0010 /* DSR output flow control */
57#define DCDPACE 0x0020 /* DCD output flow control */
58#define DTRPACE 0x0040 /* DTR input flow control */
59#define DIGI_FORCEDCD 0x0100 /* Force carrier */
60#define DIGI_ALTPIN 0x0200 /* Alternate RJ-45 pin config */
61#define DIGI_AIXON 0x0400 /* Aux flow control in fep */
62
63
64/************************************************************************
65 * Structure used with ioctl commands for DIGI parameters.
66 ************************************************************************/
67struct digi_struct {
68 unsigned short digi_flags; /* Flags (see above) */
69};
70
71typedef struct digi_struct digi_t;
diff --git a/drivers/char/drm/ati_pcigart.c b/drivers/char/drm/ati_pcigart.c
index bd7be09ea53d..5b91bc04ea4e 100644
--- a/drivers/char/drm/ati_pcigart.c
+++ b/drivers/char/drm/ati_pcigart.c
@@ -33,59 +33,44 @@
33 33
34#include "drmP.h" 34#include "drmP.h"
35 35
36#if PAGE_SIZE == 65536
37# define ATI_PCIGART_TABLE_ORDER 0
38# define ATI_PCIGART_TABLE_PAGES (1 << 0)
39#elif PAGE_SIZE == 16384
40# define ATI_PCIGART_TABLE_ORDER 1
41# define ATI_PCIGART_TABLE_PAGES (1 << 1)
42#elif PAGE_SIZE == 8192
43# define ATI_PCIGART_TABLE_ORDER 2
44# define ATI_PCIGART_TABLE_PAGES (1 << 2)
45#elif PAGE_SIZE == 4096
46# define ATI_PCIGART_TABLE_ORDER 3
47# define ATI_PCIGART_TABLE_PAGES (1 << 3)
48#else
49# error - PAGE_SIZE not 64K, 16K, 8K or 4K
50#endif
51
52# define ATI_MAX_PCIGART_PAGES 8192 /**< 32 MB aperture, 4K pages */
53# define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */ 36# define ATI_PCIGART_PAGE_SIZE 4096 /**< PCI GART page size */
54 37
55static void *drm_ati_alloc_pcigart_table(void) 38static void *drm_ati_alloc_pcigart_table(int order)
56{ 39{
57 unsigned long address; 40 unsigned long address;
58 struct page *page; 41 struct page *page;
59 int i; 42 int i;
60 DRM_DEBUG("%s\n", __FUNCTION__); 43
44 DRM_DEBUG("%s: alloc %d order\n", __FUNCTION__, order);
61 45
62 address = __get_free_pages(GFP_KERNEL | __GFP_COMP, 46 address = __get_free_pages(GFP_KERNEL | __GFP_COMP,
63 ATI_PCIGART_TABLE_ORDER); 47 order);
64 if (address == 0UL) { 48 if (address == 0UL) {
65 return NULL; 49 return NULL;
66 } 50 }
67 51
68 page = virt_to_page(address); 52 page = virt_to_page(address);
69 53
70 for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) 54 for (i = 0; i < order; i++, page++)
71 SetPageReserved(page); 55 SetPageReserved(page);
72 56
73 DRM_DEBUG("%s: returning 0x%08lx\n", __FUNCTION__, address); 57 DRM_DEBUG("%s: returning 0x%08lx\n", __FUNCTION__, address);
74 return (void *)address; 58 return (void *)address;
75} 59}
76 60
77static void drm_ati_free_pcigart_table(void *address) 61static void drm_ati_free_pcigart_table(void *address, int order)
78{ 62{
79 struct page *page; 63 struct page *page;
80 int i; 64 int i;
65 int num_pages = 1 << order;
81 DRM_DEBUG("%s\n", __FUNCTION__); 66 DRM_DEBUG("%s\n", __FUNCTION__);
82 67
83 page = virt_to_page((unsigned long)address); 68 page = virt_to_page((unsigned long)address);
84 69
85 for (i = 0; i < ATI_PCIGART_TABLE_PAGES; i++, page++) 70 for (i = 0; i < num_pages; i++, page++)
86 ClearPageReserved(page); 71 ClearPageReserved(page);
87 72
88 free_pages((unsigned long)address, ATI_PCIGART_TABLE_ORDER); 73 free_pages((unsigned long)address, order);
89} 74}
90 75
91int drm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info) 76int drm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
@@ -93,6 +78,8 @@ int drm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
93 drm_sg_mem_t *entry = dev->sg; 78 drm_sg_mem_t *entry = dev->sg;
94 unsigned long pages; 79 unsigned long pages;
95 int i; 80 int i;
81 int order;
82 int num_pages, max_pages;
96 83
97 /* we need to support large memory configurations */ 84 /* we need to support large memory configurations */
98 if (!entry) { 85 if (!entry) {
@@ -100,15 +87,19 @@ int drm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
100 return 0; 87 return 0;
101 } 88 }
102 89
90 order = drm_order((gart_info->table_size + (PAGE_SIZE-1)) / PAGE_SIZE);
91 num_pages = 1 << order;
92
103 if (gart_info->bus_addr) { 93 if (gart_info->bus_addr) {
104 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) { 94 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
105 pci_unmap_single(dev->pdev, gart_info->bus_addr, 95 pci_unmap_single(dev->pdev, gart_info->bus_addr,
106 ATI_PCIGART_TABLE_PAGES * PAGE_SIZE, 96 num_pages * PAGE_SIZE,
107 PCI_DMA_TODEVICE); 97 PCI_DMA_TODEVICE);
108 } 98 }
109 99
110 pages = (entry->pages <= ATI_MAX_PCIGART_PAGES) 100 max_pages = (gart_info->table_size / sizeof(u32));
111 ? entry->pages : ATI_MAX_PCIGART_PAGES; 101 pages = (entry->pages <= max_pages)
102 ? entry->pages : max_pages;
112 103
113 for (i = 0; i < pages; i++) { 104 for (i = 0; i < pages; i++) {
114 if (!entry->busaddr[i]) 105 if (!entry->busaddr[i])
@@ -123,13 +114,12 @@ int drm_ati_pcigart_cleanup(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
123 114
124 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN 115 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN
125 && gart_info->addr) { 116 && gart_info->addr) {
126 drm_ati_free_pcigart_table(gart_info->addr); 117 drm_ati_free_pcigart_table(gart_info->addr, order);
127 gart_info->addr = NULL; 118 gart_info->addr = NULL;
128 } 119 }
129 120
130 return 1; 121 return 1;
131} 122}
132
133EXPORT_SYMBOL(drm_ati_pcigart_cleanup); 123EXPORT_SYMBOL(drm_ati_pcigart_cleanup);
134 124
135int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info) 125int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
@@ -139,6 +129,9 @@ int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
139 unsigned long pages; 129 unsigned long pages;
140 u32 *pci_gart, page_base, bus_address = 0; 130 u32 *pci_gart, page_base, bus_address = 0;
141 int i, j, ret = 0; 131 int i, j, ret = 0;
132 int order;
133 int max_pages;
134 int num_pages;
142 135
143 if (!entry) { 136 if (!entry) {
144 DRM_ERROR("no scatter/gather memory!\n"); 137 DRM_ERROR("no scatter/gather memory!\n");
@@ -148,7 +141,10 @@ int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
148 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) { 141 if (gart_info->gart_table_location == DRM_ATI_GART_MAIN) {
149 DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n"); 142 DRM_DEBUG("PCI: no table in VRAM: using normal RAM\n");
150 143
151 address = drm_ati_alloc_pcigart_table(); 144 order = drm_order((gart_info->table_size +
145 (PAGE_SIZE-1)) / PAGE_SIZE);
146 num_pages = 1 << order;
147 address = drm_ati_alloc_pcigart_table(order);
152 if (!address) { 148 if (!address) {
153 DRM_ERROR("cannot allocate PCI GART page!\n"); 149 DRM_ERROR("cannot allocate PCI GART page!\n");
154 goto done; 150 goto done;
@@ -160,11 +156,13 @@ int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
160 } 156 }
161 157
162 bus_address = pci_map_single(dev->pdev, address, 158 bus_address = pci_map_single(dev->pdev, address,
163 ATI_PCIGART_TABLE_PAGES * 159 num_pages * PAGE_SIZE,
164 PAGE_SIZE, PCI_DMA_TODEVICE); 160 PCI_DMA_TODEVICE);
165 if (bus_address == 0) { 161 if (bus_address == 0) {
166 DRM_ERROR("unable to map PCIGART pages!\n"); 162 DRM_ERROR("unable to map PCIGART pages!\n");
167 drm_ati_free_pcigart_table(address); 163 order = drm_order((gart_info->table_size +
164 (PAGE_SIZE-1)) / PAGE_SIZE);
165 drm_ati_free_pcigart_table(address, order);
168 address = NULL; 166 address = NULL;
169 goto done; 167 goto done;
170 } 168 }
@@ -177,10 +175,11 @@ int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
177 175
178 pci_gart = (u32 *) address; 176 pci_gart = (u32 *) address;
179 177
180 pages = (entry->pages <= ATI_MAX_PCIGART_PAGES) 178 max_pages = (gart_info->table_size / sizeof(u32));
181 ? entry->pages : ATI_MAX_PCIGART_PAGES; 179 pages = (entry->pages <= max_pages)
180 ? entry->pages : max_pages;
182 181
183 memset(pci_gart, 0, ATI_MAX_PCIGART_PAGES * sizeof(u32)); 182 memset(pci_gart, 0, max_pages * sizeof(u32));
184 183
185 for (i = 0; i < pages; i++) { 184 for (i = 0; i < pages; i++) {
186 /* we need to support large memory configurations */ 185 /* we need to support large memory configurations */
@@ -198,10 +197,18 @@ int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
198 page_base = (u32) entry->busaddr[i]; 197 page_base = (u32) entry->busaddr[i];
199 198
200 for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) { 199 for (j = 0; j < (PAGE_SIZE / ATI_PCIGART_PAGE_SIZE); j++) {
201 if (gart_info->is_pcie) 200 switch(gart_info->gart_reg_if) {
201 case DRM_ATI_GART_IGP:
202 *pci_gart = cpu_to_le32((page_base) | 0xc);
203 break;
204 case DRM_ATI_GART_PCIE:
202 *pci_gart = cpu_to_le32((page_base >> 8) | 0xc); 205 *pci_gart = cpu_to_le32((page_base >> 8) | 0xc);
203 else 206 break;
207 default:
208 case DRM_ATI_GART_PCI:
204 *pci_gart = cpu_to_le32(page_base); 209 *pci_gart = cpu_to_le32(page_base);
210 break;
211 }
205 pci_gart++; 212 pci_gart++;
206 page_base += ATI_PCIGART_PAGE_SIZE; 213 page_base += ATI_PCIGART_PAGE_SIZE;
207 } 214 }
@@ -220,5 +227,4 @@ int drm_ati_pcigart_init(drm_device_t *dev, drm_ati_pcigart_info *gart_info)
220 gart_info->bus_addr = bus_address; 227 gart_info->bus_addr = bus_address;
221 return ret; 228 return ret;
222} 229}
223
224EXPORT_SYMBOL(drm_ati_pcigart_init); 230EXPORT_SYMBOL(drm_ati_pcigart_init);
diff --git a/drivers/char/drm/drmP.h b/drivers/char/drm/drmP.h
index 80041d5b792d..d494315752a2 100644
--- a/drivers/char/drm/drmP.h
+++ b/drivers/char/drm/drmP.h
@@ -519,12 +519,17 @@ typedef struct drm_vbl_sig {
519#define DRM_ATI_GART_MAIN 1 519#define DRM_ATI_GART_MAIN 1
520#define DRM_ATI_GART_FB 2 520#define DRM_ATI_GART_FB 2
521 521
522#define DRM_ATI_GART_PCI 1
523#define DRM_ATI_GART_PCIE 2
524#define DRM_ATI_GART_IGP 3
525
522typedef struct ati_pcigart_info { 526typedef struct ati_pcigart_info {
523 int gart_table_location; 527 int gart_table_location;
524 int is_pcie; 528 int gart_reg_if;
525 void *addr; 529 void *addr;
526 dma_addr_t bus_addr; 530 dma_addr_t bus_addr;
527 drm_local_map_t mapping; 531 drm_local_map_t mapping;
532 int table_size;
528} drm_ati_pcigart_info; 533} drm_ati_pcigart_info;
529 534
530/* 535/*
diff --git a/drivers/char/drm/drm_dma.c b/drivers/char/drm/drm_dma.c
index 892db7096986..32ed19c9ec1c 100644
--- a/drivers/char/drm/drm_dma.c
+++ b/drivers/char/drm/drm_dma.c
@@ -65,7 +65,7 @@ int drm_dma_setup(drm_device_t * dev)
65 * \param dev DRM device. 65 * \param dev DRM device.
66 * 66 *
67 * Free all pages associated with DMA buffers, the buffers and pages lists, and 67 * Free all pages associated with DMA buffers, the buffers and pages lists, and
68 * finally the the drm_device::dma structure itself. 68 * finally the drm_device::dma structure itself.
69 */ 69 */
70void drm_dma_takedown(drm_device_t * dev) 70void drm_dma_takedown(drm_device_t * dev)
71{ 71{
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c
index 26bec30ee86e..8e77b7ed0f44 100644
--- a/drivers/char/drm/drm_drv.c
+++ b/drivers/char/drm/drm_drv.c
@@ -15,8 +15,6 @@
15 * #define DRIVER_DESC "Matrox G200/G400" 15 * #define DRIVER_DESC "Matrox G200/G400"
16 * #define DRIVER_DATE "20001127" 16 * #define DRIVER_DATE "20001127"
17 * 17 *
18 * #define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( mga_ioctls )
19 *
20 * #define drm_x mga_##x 18 * #define drm_x mga_##x
21 * \endcode 19 * \endcode
22 */ 20 */
@@ -120,7 +118,7 @@ static drm_ioctl_desc_t drm_ioctls[] = {
120 [DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW)] = {drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY}, 118 [DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW)] = {drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY},
121}; 119};
122 120
123#define DRIVER_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) 121#define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
124 122
125/** 123/**
126 * Take down the DRM device. 124 * Take down the DRM device.
@@ -496,11 +494,11 @@ int drm_ioctl(struct inode *inode, struct file *filp,
496 (long)old_encode_dev(priv->head->device), 494 (long)old_encode_dev(priv->head->device),
497 priv->authenticated); 495 priv->authenticated);
498 496
499 if ((nr >= DRIVER_IOCTL_COUNT) && 497 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
500 ((nr < DRM_COMMAND_BASE) || (nr >= DRM_COMMAND_END))) 498 ((nr < DRM_COMMAND_BASE) || (nr >= DRM_COMMAND_END)))
501 goto err_i1; 499 goto err_i1;
502 if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END) 500 if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END) &&
503 && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls)) 501 (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls))
504 ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE]; 502 ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE];
505 else if ((nr >= DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE)) 503 else if ((nr >= DRM_COMMAND_END) || (nr < DRM_COMMAND_BASE))
506 ioctl = &drm_ioctls[nr]; 504 ioctl = &drm_ioctls[nr];
diff --git a/drivers/char/drm/drm_os_linux.h b/drivers/char/drm/drm_os_linux.h
index 2908b72daa6e..0fe7b4497927 100644
--- a/drivers/char/drm/drm_os_linux.h
+++ b/drivers/char/drm/drm_os_linux.h
@@ -70,9 +70,6 @@ static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
70 70
71#endif 71#endif
72 72
73/** Task queue handler arguments */
74#define DRM_TASKQUEUE_ARGS void *arg
75
76/** For data going into the kernel through the ioctl argument */ 73/** For data going into the kernel through the ioctl argument */
77#define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \ 74#define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \
78 if ( copy_from_user(&arg1, arg2, arg3) ) \ 75 if ( copy_from_user(&arg1, arg2, arg3) ) \
diff --git a/drivers/char/drm/drm_pciids.h b/drivers/char/drm/drm_pciids.h
index 01cf482d2d00..31cdde83713b 100644
--- a/drivers/char/drm/drm_pciids.h
+++ b/drivers/char/drm/drm_pciids.h
@@ -102,6 +102,7 @@
102 {0x1002, 0x5653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ 102 {0x1002, 0x5653, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
103 {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP}, \ 103 {0x1002, 0x5834, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP}, \
104 {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \ 104 {0x1002, 0x5835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY}, \
105 {0x1002, 0x5955, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS400|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_IS_IGPGART}, \
105 {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 106 {0x1002, 0x5960, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
106 {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 107 {0x1002, 0x5961, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
107 {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \ 108 {0x1002, 0x5962, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV280}, \
diff --git a/drivers/char/drm/drm_vm.c b/drivers/char/drm/drm_vm.c
index 35540cfb43dd..b5c5b9fa84c3 100644
--- a/drivers/char/drm/drm_vm.c
+++ b/drivers/char/drm/drm_vm.c
@@ -157,7 +157,7 @@ static __inline__ struct page *drm_do_vm_nopage(struct vm_area_struct *vma,
157 * \param address access address. 157 * \param address access address.
158 * \return pointer to the page structure. 158 * \return pointer to the page structure.
159 * 159 *
160 * Get the the mapping, find the real physical page to map, get the page, and 160 * Get the mapping, find the real physical page to map, get the page, and
161 * return it. 161 * return it.
162 */ 162 */
163static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma, 163static __inline__ struct page *drm_do_vm_shm_nopage(struct vm_area_struct *vma,
diff --git a/drivers/char/drm/r128_cce.c b/drivers/char/drm/r128_cce.c
index db5a60450e68..1014602c43a7 100644
--- a/drivers/char/drm/r128_cce.c
+++ b/drivers/char/drm/r128_cce.c
@@ -560,9 +560,10 @@ static int r128_do_init_cce(drm_device_t * dev, drm_r128_init_t * init)
560 if (dev_priv->is_pci) { 560 if (dev_priv->is_pci) {
561#endif 561#endif
562 dev_priv->gart_info.gart_table_location = DRM_ATI_GART_MAIN; 562 dev_priv->gart_info.gart_table_location = DRM_ATI_GART_MAIN;
563 dev_priv->gart_info.table_size = R128_PCIGART_TABLE_SIZE;
563 dev_priv->gart_info.addr = NULL; 564 dev_priv->gart_info.addr = NULL;
564 dev_priv->gart_info.bus_addr = 0; 565 dev_priv->gart_info.bus_addr = 0;
565 dev_priv->gart_info.is_pcie = 0; 566 dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
566 if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) { 567 if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) {
567 DRM_ERROR("failed to init PCI GART!\n"); 568 DRM_ERROR("failed to init PCI GART!\n");
568 dev->dev_private = (void *)dev_priv; 569 dev->dev_private = (void *)dev_priv;
diff --git a/drivers/char/drm/r128_drv.h b/drivers/char/drm/r128_drv.h
index f1efb49de8df..9086835686dc 100644
--- a/drivers/char/drm/r128_drv.h
+++ b/drivers/char/drm/r128_drv.h
@@ -383,6 +383,8 @@ extern long r128_compat_ioctl(struct file *filp, unsigned int cmd,
383 383
384#define R128_PERFORMANCE_BOXES 0 384#define R128_PERFORMANCE_BOXES 0
385 385
386#define R128_PCIGART_TABLE_SIZE 32768
387
386#define R128_READ(reg) DRM_READ32( dev_priv->mmio, (reg) ) 388#define R128_READ(reg) DRM_READ32( dev_priv->mmio, (reg) )
387#define R128_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, (reg), (val) ) 389#define R128_WRITE(reg,val) DRM_WRITE32( dev_priv->mmio, (reg), (val) )
388#define R128_READ8(reg) DRM_READ8( dev_priv->mmio, (reg) ) 390#define R128_READ8(reg) DRM_READ8( dev_priv->mmio, (reg) )
diff --git a/drivers/char/drm/r300_reg.h b/drivers/char/drm/r300_reg.h
index a881f96c983e..ecda760ae8c0 100644
--- a/drivers/char/drm/r300_reg.h
+++ b/drivers/char/drm/r300_reg.h
@@ -293,7 +293,7 @@ I am fairly certain that they are correct unless stated otherwise in comments.
293# define R300_PVS_CNTL_1_PROGRAM_START_SHIFT 0 293# define R300_PVS_CNTL_1_PROGRAM_START_SHIFT 0
294# define R300_PVS_CNTL_1_POS_END_SHIFT 10 294# define R300_PVS_CNTL_1_POS_END_SHIFT 10
295# define R300_PVS_CNTL_1_PROGRAM_END_SHIFT 20 295# define R300_PVS_CNTL_1_PROGRAM_END_SHIFT 20
296/* Addresses are relative the the vertex program parameters area. */ 296/* Addresses are relative to the vertex program parameters area. */
297#define R300_VAP_PVS_CNTL_2 0x22D4 297#define R300_VAP_PVS_CNTL_2 0x22D4
298# define R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT 0 298# define R300_PVS_CNTL_2_PARAM_OFFSET_SHIFT 0
299# define R300_PVS_CNTL_2_PARAM_COUNT_SHIFT 16 299# define R300_PVS_CNTL_2_PARAM_COUNT_SHIFT 16
diff --git a/drivers/char/drm/radeon_cp.c b/drivers/char/drm/radeon_cp.c
index c1850ecac302..68338389d836 100644
--- a/drivers/char/drm/radeon_cp.c
+++ b/drivers/char/drm/radeon_cp.c
@@ -830,6 +830,15 @@ static int RADEON_READ_PCIE(drm_radeon_private_t *dev_priv, int addr)
830 return RADEON_READ(RADEON_PCIE_DATA); 830 return RADEON_READ(RADEON_PCIE_DATA);
831} 831}
832 832
833static u32 RADEON_READ_IGPGART(drm_radeon_private_t *dev_priv, int addr)
834{
835 u32 ret;
836 RADEON_WRITE(RADEON_IGPGART_INDEX, addr & 0x7f);
837 ret = RADEON_READ(RADEON_IGPGART_DATA);
838 RADEON_WRITE(RADEON_IGPGART_INDEX, 0x7f);
839 return ret;
840}
841
833#if RADEON_FIFO_DEBUG 842#if RADEON_FIFO_DEBUG
834static void radeon_status(drm_radeon_private_t * dev_priv) 843static void radeon_status(drm_radeon_private_t * dev_priv)
835{ 844{
@@ -1267,7 +1276,44 @@ static void radeon_test_writeback(drm_radeon_private_t * dev_priv)
1267 } 1276 }
1268} 1277}
1269 1278
1270/* Enable or disable PCI-E GART on the chip */ 1279/* Enable or disable IGP GART on the chip */
1280static void radeon_set_igpgart(drm_radeon_private_t * dev_priv, int on)
1281{
1282 u32 temp, tmp;
1283
1284 tmp = RADEON_READ(RADEON_AIC_CNTL);
1285 if (on) {
1286 DRM_DEBUG("programming igpgart %08X %08lX %08X\n",
1287 dev_priv->gart_vm_start,
1288 (long)dev_priv->gart_info.bus_addr,
1289 dev_priv->gart_size);
1290
1291 RADEON_WRITE_IGPGART(RADEON_IGPGART_UNK_18, 0x1000);
1292 RADEON_WRITE_IGPGART(RADEON_IGPGART_ENABLE, 0x1);
1293 RADEON_WRITE_IGPGART(RADEON_IGPGART_CTRL, 0x42040800);
1294 RADEON_WRITE_IGPGART(RADEON_IGPGART_BASE_ADDR,
1295 dev_priv->gart_info.bus_addr);
1296
1297 temp = RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_UNK_39);
1298 RADEON_WRITE_IGPGART(RADEON_IGPGART_UNK_39, temp);
1299
1300 RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev_priv->gart_vm_start);
1301 dev_priv->gart_size = 32*1024*1024;
1302 RADEON_WRITE(RADEON_MC_AGP_LOCATION,
1303 (((dev_priv->gart_vm_start - 1 +
1304 dev_priv->gart_size) & 0xffff0000) |
1305 (dev_priv->gart_vm_start >> 16)));
1306
1307 temp = RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_ENABLE);
1308 RADEON_WRITE_IGPGART(RADEON_IGPGART_ENABLE, temp);
1309
1310 RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_FLUSH);
1311 RADEON_WRITE_IGPGART(RADEON_IGPGART_FLUSH, 0x1);
1312 RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_FLUSH);
1313 RADEON_WRITE_IGPGART(RADEON_IGPGART_FLUSH, 0x0);
1314 }
1315}
1316
1271static void radeon_set_pciegart(drm_radeon_private_t * dev_priv, int on) 1317static void radeon_set_pciegart(drm_radeon_private_t * dev_priv, int on)
1272{ 1318{
1273 u32 tmp = RADEON_READ_PCIE(dev_priv, RADEON_PCIE_TX_GART_CNTL); 1319 u32 tmp = RADEON_READ_PCIE(dev_priv, RADEON_PCIE_TX_GART_CNTL);
@@ -1302,6 +1348,11 @@ static void radeon_set_pcigart(drm_radeon_private_t * dev_priv, int on)
1302{ 1348{
1303 u32 tmp; 1349 u32 tmp;
1304 1350
1351 if (dev_priv->flags & RADEON_IS_IGPGART) {
1352 radeon_set_igpgart(dev_priv, on);
1353 return;
1354 }
1355
1305 if (dev_priv->flags & RADEON_IS_PCIE) { 1356 if (dev_priv->flags & RADEON_IS_PCIE) {
1306 radeon_set_pciegart(dev_priv, on); 1357 radeon_set_pciegart(dev_priv, on);
1307 return; 1358 return;
@@ -1620,20 +1671,22 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1620#endif 1671#endif
1621 { 1672 {
1622 /* if we have an offset set from userspace */ 1673 /* if we have an offset set from userspace */
1623 if (dev_priv->pcigart_offset) { 1674 if (dev_priv->pcigart_offset_set) {
1624 dev_priv->gart_info.bus_addr = 1675 dev_priv->gart_info.bus_addr =
1625 dev_priv->pcigart_offset + dev_priv->fb_location; 1676 dev_priv->pcigart_offset + dev_priv->fb_location;
1626 dev_priv->gart_info.mapping.offset = 1677 dev_priv->gart_info.mapping.offset =
1627 dev_priv->gart_info.bus_addr; 1678 dev_priv->gart_info.bus_addr;
1628 dev_priv->gart_info.mapping.size = 1679 dev_priv->gart_info.mapping.size =
1629 RADEON_PCIGART_TABLE_SIZE; 1680 dev_priv->gart_info.table_size;
1630 1681
1631 drm_core_ioremap(&dev_priv->gart_info.mapping, dev); 1682 drm_core_ioremap(&dev_priv->gart_info.mapping, dev);
1632 dev_priv->gart_info.addr = 1683 dev_priv->gart_info.addr =
1633 dev_priv->gart_info.mapping.handle; 1684 dev_priv->gart_info.mapping.handle;
1634 1685
1635 dev_priv->gart_info.is_pcie = 1686 if (dev_priv->flags & RADEON_IS_PCIE)
1636 !!(dev_priv->flags & RADEON_IS_PCIE); 1687 dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCIE;
1688 else
1689 dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
1637 dev_priv->gart_info.gart_table_location = 1690 dev_priv->gart_info.gart_table_location =
1638 DRM_ATI_GART_FB; 1691 DRM_ATI_GART_FB;
1639 1692
@@ -1641,6 +1694,10 @@ static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
1641 dev_priv->gart_info.addr, 1694 dev_priv->gart_info.addr,
1642 dev_priv->pcigart_offset); 1695 dev_priv->pcigart_offset);
1643 } else { 1696 } else {
1697 if (dev_priv->flags & RADEON_IS_IGPGART)
1698 dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_IGP;
1699 else
1700 dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
1644 dev_priv->gart_info.gart_table_location = 1701 dev_priv->gart_info.gart_table_location =
1645 DRM_ATI_GART_MAIN; 1702 DRM_ATI_GART_MAIN;
1646 dev_priv->gart_info.addr = NULL; 1703 dev_priv->gart_info.addr = NULL;
@@ -1714,7 +1771,7 @@ static int radeon_do_cleanup_cp(drm_device_t * dev)
1714 if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB) 1771 if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB)
1715 { 1772 {
1716 drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev); 1773 drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev);
1717 dev_priv->gart_info.addr = NULL; 1774 dev_priv->gart_info.addr = 0;
1718 } 1775 }
1719 } 1776 }
1720 /* only clear to the start of flags */ 1777 /* only clear to the start of flags */
@@ -2222,6 +2279,8 @@ int radeon_driver_firstopen(struct drm_device *dev)
2222 drm_local_map_t *map; 2279 drm_local_map_t *map;
2223 drm_radeon_private_t *dev_priv = dev->dev_private; 2280 drm_radeon_private_t *dev_priv = dev->dev_private;
2224 2281
2282 dev_priv->gart_info.table_size = RADEON_PCIGART_TABLE_SIZE;
2283
2225 ret = drm_addmap(dev, drm_get_resource_start(dev, 2), 2284 ret = drm_addmap(dev, drm_get_resource_start(dev, 2),
2226 drm_get_resource_len(dev, 2), _DRM_REGISTERS, 2285 drm_get_resource_len(dev, 2), _DRM_REGISTERS,
2227 _DRM_READ_ONLY, &dev_priv->mmio); 2286 _DRM_READ_ONLY, &dev_priv->mmio);
diff --git a/drivers/char/drm/radeon_drm.h b/drivers/char/drm/radeon_drm.h
index 8d6350dd5360..66c4b6fed04f 100644
--- a/drivers/char/drm/radeon_drm.h
+++ b/drivers/char/drm/radeon_drm.h
@@ -707,6 +707,7 @@ typedef struct drm_radeon_setparam {
707#define RADEON_SETPARAM_SWITCH_TILING 2 /* enable/disable color tiling */ 707#define RADEON_SETPARAM_SWITCH_TILING 2 /* enable/disable color tiling */
708#define RADEON_SETPARAM_PCIGART_LOCATION 3 /* PCI Gart Location */ 708#define RADEON_SETPARAM_PCIGART_LOCATION 3 /* PCI Gart Location */
709#define RADEON_SETPARAM_NEW_MEMMAP 4 /* Use new memory map */ 709#define RADEON_SETPARAM_NEW_MEMMAP 4 /* Use new memory map */
710#define RADEON_SETPARAM_PCIGART_TABLE_SIZE 5 /* PCI GART Table Size */
710 711
711/* 1.14: Clients can allocate/free a surface 712/* 1.14: Clients can allocate/free a surface
712 */ 713 */
diff --git a/drivers/char/drm/radeon_drv.h b/drivers/char/drm/radeon_drv.h
index 8b105f1460a7..54f49ef4bef0 100644
--- a/drivers/char/drm/radeon_drv.h
+++ b/drivers/char/drm/radeon_drv.h
@@ -95,9 +95,11 @@
95 * 1.24- Add general-purpose packet for manipulating scratch registers (r300) 95 * 1.24- Add general-purpose packet for manipulating scratch registers (r300)
96 * 1.25- Add support for r200 vertex programs (R200_EMIT_VAP_PVS_CNTL, 96 * 1.25- Add support for r200 vertex programs (R200_EMIT_VAP_PVS_CNTL,
97 * new packet type) 97 * new packet type)
98 * 1.26- Add support for variable size PCI(E) gart aperture
99 * 1.27- Add support for IGP GART
98 */ 100 */
99#define DRIVER_MAJOR 1 101#define DRIVER_MAJOR 1
100#define DRIVER_MINOR 25 102#define DRIVER_MINOR 27
101#define DRIVER_PATCHLEVEL 0 103#define DRIVER_PATCHLEVEL 0
102 104
103/* 105/*
@@ -143,6 +145,7 @@ enum radeon_chip_flags {
143 RADEON_IS_PCIE = 0x00200000UL, 145 RADEON_IS_PCIE = 0x00200000UL,
144 RADEON_NEW_MEMMAP = 0x00400000UL, 146 RADEON_NEW_MEMMAP = 0x00400000UL,
145 RADEON_IS_PCI = 0x00800000UL, 147 RADEON_IS_PCI = 0x00800000UL,
148 RADEON_IS_IGPGART = 0x01000000UL,
146}; 149};
147 150
148#define GET_RING_HEAD(dev_priv) (dev_priv->writeback_works ? \ 151#define GET_RING_HEAD(dev_priv) (dev_priv->writeback_works ? \
@@ -240,7 +243,6 @@ typedef struct drm_radeon_private {
240 243
241 int do_boxes; 244 int do_boxes;
242 int page_flipping; 245 int page_flipping;
243 int current_page;
244 246
245 u32 color_fmt; 247 u32 color_fmt;
246 unsigned int front_offset; 248 unsigned int front_offset;
@@ -280,6 +282,7 @@ typedef struct drm_radeon_private {
280 struct radeon_virt_surface virt_surfaces[2 * RADEON_MAX_SURFACES]; 282 struct radeon_virt_surface virt_surfaces[2 * RADEON_MAX_SURFACES];
281 283
282 unsigned long pcigart_offset; 284 unsigned long pcigart_offset;
285 unsigned int pcigart_offset_set;
283 drm_ati_pcigart_info gart_info; 286 drm_ati_pcigart_info gart_info;
284 287
285 u32 scratch_ages[5]; 288 u32 scratch_ages[5];
@@ -432,6 +435,15 @@ extern int r300_do_cp_cmdbuf(drm_device_t * dev, DRMFILE filp,
432#define RADEON_PCIE_TX_GART_END_LO 0x16 435#define RADEON_PCIE_TX_GART_END_LO 0x16
433#define RADEON_PCIE_TX_GART_END_HI 0x17 436#define RADEON_PCIE_TX_GART_END_HI 0x17
434 437
438#define RADEON_IGPGART_INDEX 0x168
439#define RADEON_IGPGART_DATA 0x16c
440#define RADEON_IGPGART_UNK_18 0x18
441#define RADEON_IGPGART_CTRL 0x2b
442#define RADEON_IGPGART_BASE_ADDR 0x2c
443#define RADEON_IGPGART_FLUSH 0x2e
444#define RADEON_IGPGART_ENABLE 0x38
445#define RADEON_IGPGART_UNK_39 0x39
446
435#define RADEON_MPP_TB_CONFIG 0x01c0 447#define RADEON_MPP_TB_CONFIG 0x01c0
436#define RADEON_MEM_CNTL 0x0140 448#define RADEON_MEM_CNTL 0x0140
437#define RADEON_MEM_SDRAM_MODE_REG 0x0158 449#define RADEON_MEM_SDRAM_MODE_REG 0x0158
@@ -964,6 +976,14 @@ do { \
964 RADEON_WRITE( RADEON_CLOCK_CNTL_DATA, (val) ); \ 976 RADEON_WRITE( RADEON_CLOCK_CNTL_DATA, (val) ); \
965} while (0) 977} while (0)
966 978
979#define RADEON_WRITE_IGPGART( addr, val ) \
980do { \
981 RADEON_WRITE( RADEON_IGPGART_INDEX, \
982 ((addr) & 0x7f) | (1 << 8)); \
983 RADEON_WRITE( RADEON_IGPGART_DATA, (val) ); \
984 RADEON_WRITE( RADEON_IGPGART_INDEX, 0x7f ); \
985} while (0)
986
967#define RADEON_WRITE_PCIE( addr, val ) \ 987#define RADEON_WRITE_PCIE( addr, val ) \
968do { \ 988do { \
969 RADEON_WRITE8( RADEON_PCIE_INDEX, \ 989 RADEON_WRITE8( RADEON_PCIE_INDEX, \
diff --git a/drivers/char/drm/radeon_state.c b/drivers/char/drm/radeon_state.c
index 938eccb78cc0..98c5f1d3a8e7 100644
--- a/drivers/char/drm/radeon_state.c
+++ b/drivers/char/drm/radeon_state.c
@@ -773,7 +773,7 @@ static void radeon_clear_box(drm_radeon_private_t * dev_priv,
773 RADEON_GMC_SRC_DATATYPE_COLOR | 773 RADEON_GMC_SRC_DATATYPE_COLOR |
774 RADEON_ROP3_P | RADEON_GMC_CLR_CMP_CNTL_DIS); 774 RADEON_ROP3_P | RADEON_GMC_CLR_CMP_CNTL_DIS);
775 775
776 if (dev_priv->page_flipping && dev_priv->current_page == 1) { 776 if (dev_priv->sarea_priv->pfCurrentPage == 1) {
777 OUT_RING(dev_priv->front_pitch_offset); 777 OUT_RING(dev_priv->front_pitch_offset);
778 } else { 778 } else {
779 OUT_RING(dev_priv->back_pitch_offset); 779 OUT_RING(dev_priv->back_pitch_offset);
@@ -861,7 +861,7 @@ static void radeon_cp_dispatch_clear(drm_device_t * dev,
861 861
862 dev_priv->stats.clears++; 862 dev_priv->stats.clears++;
863 863
864 if (dev_priv->page_flipping && dev_priv->current_page == 1) { 864 if (dev_priv->sarea_priv->pfCurrentPage == 1) {
865 unsigned int tmp = flags; 865 unsigned int tmp = flags;
866 866
867 flags &= ~(RADEON_FRONT | RADEON_BACK); 867 flags &= ~(RADEON_FRONT | RADEON_BACK);
@@ -1382,7 +1382,7 @@ static void radeon_cp_dispatch_swap(drm_device_t * dev)
1382 /* Make this work even if front & back are flipped: 1382 /* Make this work even if front & back are flipped:
1383 */ 1383 */
1384 OUT_RING(CP_PACKET0(RADEON_SRC_PITCH_OFFSET, 1)); 1384 OUT_RING(CP_PACKET0(RADEON_SRC_PITCH_OFFSET, 1));
1385 if (dev_priv->current_page == 0) { 1385 if (dev_priv->sarea_priv->pfCurrentPage == 0) {
1386 OUT_RING(dev_priv->back_pitch_offset); 1386 OUT_RING(dev_priv->back_pitch_offset);
1387 OUT_RING(dev_priv->front_pitch_offset); 1387 OUT_RING(dev_priv->front_pitch_offset);
1388 } else { 1388 } else {
@@ -1416,12 +1416,12 @@ static void radeon_cp_dispatch_flip(drm_device_t * dev)
1416{ 1416{
1417 drm_radeon_private_t *dev_priv = dev->dev_private; 1417 drm_radeon_private_t *dev_priv = dev->dev_private;
1418 drm_sarea_t *sarea = (drm_sarea_t *) dev_priv->sarea->handle; 1418 drm_sarea_t *sarea = (drm_sarea_t *) dev_priv->sarea->handle;
1419 int offset = (dev_priv->current_page == 1) 1419 int offset = (dev_priv->sarea_priv->pfCurrentPage == 1)
1420 ? dev_priv->front_offset : dev_priv->back_offset; 1420 ? dev_priv->front_offset : dev_priv->back_offset;
1421 RING_LOCALS; 1421 RING_LOCALS;
1422 DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n", 1422 DRM_DEBUG("%s: pfCurrentPage=%d\n",
1423 __FUNCTION__, 1423 __FUNCTION__,
1424 dev_priv->current_page, dev_priv->sarea_priv->pfCurrentPage); 1424 dev_priv->sarea_priv->pfCurrentPage);
1425 1425
1426 /* Do some trivial performance monitoring... 1426 /* Do some trivial performance monitoring...
1427 */ 1427 */
@@ -1449,8 +1449,8 @@ static void radeon_cp_dispatch_flip(drm_device_t * dev)
1449 * performing the swapbuffer ioctl. 1449 * performing the swapbuffer ioctl.
1450 */ 1450 */
1451 dev_priv->sarea_priv->last_frame++; 1451 dev_priv->sarea_priv->last_frame++;
1452 dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page = 1452 dev_priv->sarea_priv->pfCurrentPage =
1453 1 - dev_priv->current_page; 1453 1 - dev_priv->sarea_priv->pfCurrentPage;
1454 1454
1455 BEGIN_RING(2); 1455 BEGIN_RING(2);
1456 1456
@@ -2152,24 +2152,10 @@ static int radeon_do_init_pageflip(drm_device_t * dev)
2152 ADVANCE_RING(); 2152 ADVANCE_RING();
2153 2153
2154 dev_priv->page_flipping = 1; 2154 dev_priv->page_flipping = 1;
2155 dev_priv->current_page = 0;
2156 dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page;
2157 2155
2158 return 0; 2156 if (dev_priv->sarea_priv->pfCurrentPage != 1)
2159} 2157 dev_priv->sarea_priv->pfCurrentPage = 0;
2160
2161/* Called whenever a client dies, from drm_release.
2162 * NOTE: Lock isn't necessarily held when this is called!
2163 */
2164static int radeon_do_cleanup_pageflip(drm_device_t * dev)
2165{
2166 drm_radeon_private_t *dev_priv = dev->dev_private;
2167 DRM_DEBUG("\n");
2168
2169 if (dev_priv->current_page != 0)
2170 radeon_cp_dispatch_flip(dev);
2171 2158
2172 dev_priv->page_flipping = 0;
2173 return 0; 2159 return 0;
2174} 2160}
2175 2161
@@ -3145,10 +3131,16 @@ static int radeon_cp_setparam(DRM_IOCTL_ARGS)
3145 break; 3131 break;
3146 case RADEON_SETPARAM_PCIGART_LOCATION: 3132 case RADEON_SETPARAM_PCIGART_LOCATION:
3147 dev_priv->pcigart_offset = sp.value; 3133 dev_priv->pcigart_offset = sp.value;
3134 dev_priv->pcigart_offset_set = 1;
3148 break; 3135 break;
3149 case RADEON_SETPARAM_NEW_MEMMAP: 3136 case RADEON_SETPARAM_NEW_MEMMAP:
3150 dev_priv->new_memmap = sp.value; 3137 dev_priv->new_memmap = sp.value;
3151 break; 3138 break;
3139 case RADEON_SETPARAM_PCIGART_TABLE_SIZE:
3140 dev_priv->gart_info.table_size = sp.value;
3141 if (dev_priv->gart_info.table_size < RADEON_PCIGART_TABLE_SIZE)
3142 dev_priv->gart_info.table_size = RADEON_PCIGART_TABLE_SIZE;
3143 break;
3152 default: 3144 default:
3153 DRM_DEBUG("Invalid parameter %d\n", sp.param); 3145 DRM_DEBUG("Invalid parameter %d\n", sp.param);
3154 return DRM_ERR(EINVAL); 3146 return DRM_ERR(EINVAL);
@@ -3168,9 +3160,7 @@ void radeon_driver_preclose(drm_device_t * dev, DRMFILE filp)
3168{ 3160{
3169 if (dev->dev_private) { 3161 if (dev->dev_private) {
3170 drm_radeon_private_t *dev_priv = dev->dev_private; 3162 drm_radeon_private_t *dev_priv = dev->dev_private;
3171 if (dev_priv->page_flipping) { 3163 dev_priv->page_flipping = 0;
3172 radeon_do_cleanup_pageflip(dev);
3173 }
3174 radeon_mem_release(filp, dev_priv->gart_heap); 3164 radeon_mem_release(filp, dev_priv->gart_heap);
3175 radeon_mem_release(filp, dev_priv->fb_heap); 3165 radeon_mem_release(filp, dev_priv->fb_heap);
3176 radeon_surfaces_release(filp, dev_priv); 3166 radeon_surfaces_release(filp, dev_priv);
@@ -3179,6 +3169,14 @@ void radeon_driver_preclose(drm_device_t * dev, DRMFILE filp)
3179 3169
3180void radeon_driver_lastclose(drm_device_t * dev) 3170void radeon_driver_lastclose(drm_device_t * dev)
3181{ 3171{
3172 if (dev->dev_private) {
3173 drm_radeon_private_t *dev_priv = dev->dev_private;
3174
3175 if (dev_priv->sarea_priv &&
3176 dev_priv->sarea_priv->pfCurrentPage != 0)
3177 radeon_cp_dispatch_flip(dev);
3178 }
3179
3182 radeon_do_release(dev); 3180 radeon_do_release(dev);
3183} 3181}
3184 3182
diff --git a/drivers/char/drm/via_dma.c b/drivers/char/drm/via_dma.c
index c0539c6299cf..13a9c5ca4593 100644
--- a/drivers/char/drm/via_dma.c
+++ b/drivers/char/drm/via_dma.c
@@ -252,7 +252,7 @@ static int via_dma_init(DRM_IOCTL_ARGS)
252 break; 252 break;
253 case VIA_DMA_INITIALIZED: 253 case VIA_DMA_INITIALIZED:
254 retcode = (dev_priv->ring.virtual_start != NULL) ? 254 retcode = (dev_priv->ring.virtual_start != NULL) ?
255 0 : DRM_ERR(EFAULT); 255 0 : DRM_ERR(EFAULT);
256 break; 256 break;
257 default: 257 default:
258 retcode = DRM_ERR(EINVAL); 258 retcode = DRM_ERR(EINVAL);
@@ -432,56 +432,34 @@ static int via_hook_segment(drm_via_private_t * dev_priv,
432{ 432{
433 int paused, count; 433 int paused, count;
434 volatile uint32_t *paused_at = dev_priv->last_pause_ptr; 434 volatile uint32_t *paused_at = dev_priv->last_pause_ptr;
435 uint32_t reader,ptr;
435 436
437 paused = 0;
436 via_flush_write_combine(); 438 via_flush_write_combine();
437 while (!*(via_get_dma(dev_priv) - 1)) ; 439 (void) *(volatile uint32_t *)(via_get_dma(dev_priv) -1);
438 *dev_priv->last_pause_ptr = pause_addr_lo; 440 *paused_at = pause_addr_lo;
439 via_flush_write_combine(); 441 via_flush_write_combine();
440 442 (void) *paused_at;
441 /* 443 reader = *(dev_priv->hw_addr_ptr);
442 * The below statement is inserted to really force the flush. 444 ptr = ((volatile char *)paused_at - dev_priv->dma_ptr) +
443 * Not sure it is needed. 445 dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4;
444 */
445
446 while (!*dev_priv->last_pause_ptr) ;
447 dev_priv->last_pause_ptr = via_get_dma(dev_priv) - 1; 446 dev_priv->last_pause_ptr = via_get_dma(dev_priv) - 1;
448 while (!*dev_priv->last_pause_ptr) ;
449 447
450 paused = 0; 448 if ((ptr - reader) <= dev_priv->dma_diff ) {
451 count = 20; 449 count = 10000000;
452 450 while (!(paused = (VIA_READ(0x41c) & 0x80000000)) && count--);
453 while (!(paused = (VIA_READ(0x41c) & 0x80000000)) && count--) ;
454 if ((count <= 8) && (count >= 0)) {
455 uint32_t rgtr, ptr;
456 rgtr = *(dev_priv->hw_addr_ptr);
457 ptr = ((volatile char *)dev_priv->last_pause_ptr -
458 dev_priv->dma_ptr) + dev_priv->dma_offset +
459 (uint32_t) dev_priv->agpAddr + 4 - CMDBUF_ALIGNMENT_SIZE;
460 if (rgtr <= ptr) {
461 DRM_ERROR
462 ("Command regulator\npaused at count %d, address %x, "
463 "while current pause address is %x.\n"
464 "Please mail this message to "
465 "<unichrome-devel@lists.sourceforge.net>\n", count,
466 rgtr, ptr);
467 }
468 } 451 }
469 452
470 if (paused && !no_pci_fire) { 453 if (paused && !no_pci_fire) {
471 uint32_t rgtr, ptr; 454 reader = *(dev_priv->hw_addr_ptr);
472 uint32_t ptr_low; 455 if ((ptr - reader) == dev_priv->dma_diff) {
473 456
474 count = 1000000; 457 /*
475 while ((VIA_READ(VIA_REG_STATUS) & VIA_CMD_RGTR_BUSY) 458 * There is a concern that these writes may stall the PCI bus
476 && count--) ; 459 * if the GPU is not idle. However, idling the GPU first
460 * doesn't make a difference.
461 */
477 462
478 rgtr = *(dev_priv->hw_addr_ptr);
479 ptr = ((volatile char *)paused_at - dev_priv->dma_ptr) +
480 dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4;
481
482 ptr_low = (ptr > 3 * CMDBUF_ALIGNMENT_SIZE) ?
483 ptr - 3 * CMDBUF_ALIGNMENT_SIZE : 0;
484 if (rgtr <= ptr && rgtr >= ptr_low) {
485 VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16)); 463 VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16));
486 VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_hi); 464 VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_hi);
487 VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_lo); 465 VIA_WRITE(VIA_REG_TRANSPACE, pause_addr_lo);
@@ -494,6 +472,9 @@ static int via_hook_segment(drm_via_private_t * dev_priv,
494static int via_wait_idle(drm_via_private_t * dev_priv) 472static int via_wait_idle(drm_via_private_t * dev_priv)
495{ 473{
496 int count = 10000000; 474 int count = 10000000;
475
476 while (!(VIA_READ(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) && count--);
477
497 while (count-- && (VIA_READ(VIA_REG_STATUS) & 478 while (count-- && (VIA_READ(VIA_REG_STATUS) &
498 (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY | 479 (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY |
499 VIA_3D_ENG_BUSY))) ; 480 VIA_3D_ENG_BUSY))) ;
@@ -537,6 +518,9 @@ static void via_cmdbuf_start(drm_via_private_t * dev_priv)
537 uint32_t end_addr, end_addr_lo; 518 uint32_t end_addr, end_addr_lo;
538 uint32_t command; 519 uint32_t command;
539 uint32_t agp_base; 520 uint32_t agp_base;
521 uint32_t ptr;
522 uint32_t reader;
523 int count;
540 524
541 dev_priv->dma_low = 0; 525 dev_priv->dma_low = 0;
542 526
@@ -554,7 +538,7 @@ static void via_cmdbuf_start(drm_via_private_t * dev_priv)
554 &pause_addr_hi, &pause_addr_lo, 1) - 1; 538 &pause_addr_hi, &pause_addr_lo, 1) - 1;
555 539
556 via_flush_write_combine(); 540 via_flush_write_combine();
557 while (!*dev_priv->last_pause_ptr) ; 541 (void) *(volatile uint32_t *)dev_priv->last_pause_ptr;
558 542
559 VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16)); 543 VIA_WRITE(VIA_REG_TRANSET, (HC_ParaType_PreCR << 16));
560 VIA_WRITE(VIA_REG_TRANSPACE, command); 544 VIA_WRITE(VIA_REG_TRANSPACE, command);
@@ -566,6 +550,24 @@ static void via_cmdbuf_start(drm_via_private_t * dev_priv)
566 DRM_WRITEMEMORYBARRIER(); 550 DRM_WRITEMEMORYBARRIER();
567 VIA_WRITE(VIA_REG_TRANSPACE, command | HC_HAGPCMNT_MASK); 551 VIA_WRITE(VIA_REG_TRANSPACE, command | HC_HAGPCMNT_MASK);
568 VIA_READ(VIA_REG_TRANSPACE); 552 VIA_READ(VIA_REG_TRANSPACE);
553
554 dev_priv->dma_diff = 0;
555
556 count = 10000000;
557 while (!(VIA_READ(0x41c) & 0x80000000) && count--);
558
559 reader = *(dev_priv->hw_addr_ptr);
560 ptr = ((volatile char *)dev_priv->last_pause_ptr - dev_priv->dma_ptr) +
561 dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr + 4;
562
563 /*
564 * This is the difference between where we tell the
565 * command reader to pause and where it actually pauses.
566 * This differs between hw implementation so we need to
567 * detect it.
568 */
569
570 dev_priv->dma_diff = ptr - reader;
569} 571}
570 572
571static void via_pad_cache(drm_via_private_t * dev_priv, int qwords) 573static void via_pad_cache(drm_via_private_t * dev_priv, int qwords)
@@ -592,7 +594,6 @@ static void via_cmdbuf_jump(drm_via_private_t * dev_priv)
592 uint32_t pause_addr_lo, pause_addr_hi; 594 uint32_t pause_addr_lo, pause_addr_hi;
593 uint32_t jump_addr_lo, jump_addr_hi; 595 uint32_t jump_addr_lo, jump_addr_hi;
594 volatile uint32_t *last_pause_ptr; 596 volatile uint32_t *last_pause_ptr;
595 uint32_t dma_low_save1, dma_low_save2;
596 597
597 agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr; 598 agp_base = dev_priv->dma_offset + (uint32_t) dev_priv->agpAddr;
598 via_align_cmd(dev_priv, HC_HAGPBpID_JUMP, 0, &jump_addr_hi, 599 via_align_cmd(dev_priv, HC_HAGPBpID_JUMP, 0, &jump_addr_hi,
@@ -619,31 +620,11 @@ static void via_cmdbuf_jump(drm_via_private_t * dev_priv)
619 &pause_addr_lo, 0); 620 &pause_addr_lo, 0);
620 621
621 *last_pause_ptr = pause_addr_lo; 622 *last_pause_ptr = pause_addr_lo;
622 dma_low_save1 = dev_priv->dma_low;
623
624 /*
625 * Now, set a trap that will pause the regulator if it tries to rerun the old
626 * command buffer. (Which may happen if via_hook_segment detecs a command regulator pause
627 * and reissues the jump command over PCI, while the regulator has already taken the jump
628 * and actually paused at the current buffer end).
629 * There appears to be no other way to detect this condition, since the hw_addr_pointer
630 * does not seem to get updated immediately when a jump occurs.
631 */
632 623
633 last_pause_ptr = 624 via_hook_segment( dev_priv, jump_addr_hi, jump_addr_lo, 0);
634 via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
635 &pause_addr_lo, 0) - 1;
636 via_align_cmd(dev_priv, HC_HAGPBpID_PAUSE, 0, &pause_addr_hi,
637 &pause_addr_lo, 0);
638 *last_pause_ptr = pause_addr_lo;
639
640 dma_low_save2 = dev_priv->dma_low;
641 dev_priv->dma_low = dma_low_save1;
642 via_hook_segment(dev_priv, jump_addr_hi, jump_addr_lo, 0);
643 dev_priv->dma_low = dma_low_save2;
644 via_hook_segment(dev_priv, pause_addr_hi, pause_addr_lo, 0);
645} 625}
646 626
627
647static void via_cmdbuf_rewind(drm_via_private_t * dev_priv) 628static void via_cmdbuf_rewind(drm_via_private_t * dev_priv)
648{ 629{
649 via_cmdbuf_jump(dev_priv); 630 via_cmdbuf_jump(dev_priv);
diff --git a/drivers/char/drm/via_drv.h b/drivers/char/drm/via_drv.h
index 8b8778d4a423..b46ca8e6306d 100644
--- a/drivers/char/drm/via_drv.h
+++ b/drivers/char/drm/via_drv.h
@@ -29,11 +29,11 @@
29 29
30#define DRIVER_NAME "via" 30#define DRIVER_NAME "via"
31#define DRIVER_DESC "VIA Unichrome / Pro" 31#define DRIVER_DESC "VIA Unichrome / Pro"
32#define DRIVER_DATE "20061227" 32#define DRIVER_DATE "20070202"
33 33
34#define DRIVER_MAJOR 2 34#define DRIVER_MAJOR 2
35#define DRIVER_MINOR 11 35#define DRIVER_MINOR 11
36#define DRIVER_PATCHLEVEL 0 36#define DRIVER_PATCHLEVEL 1
37 37
38#include "via_verifier.h" 38#include "via_verifier.h"
39 39
@@ -93,6 +93,7 @@ typedef struct drm_via_private {
93 unsigned long vram_offset; 93 unsigned long vram_offset;
94 unsigned long agp_offset; 94 unsigned long agp_offset;
95 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES]; 95 drm_via_blitq_t blit_queues[VIA_NUM_BLIT_ENGINES];
96 uint32_t dma_diff;
96} drm_via_private_t; 97} drm_via_private_t;
97 98
98enum via_family { 99enum via_family {
diff --git a/drivers/char/ds1620.c b/drivers/char/ds1620.c
index 3d7efc26aad6..334ad5bbe6b6 100644
--- a/drivers/char/ds1620.c
+++ b/drivers/char/ds1620.c
@@ -4,7 +4,6 @@
4 */ 4 */
5#include <linux/module.h> 5#include <linux/module.h>
6#include <linux/miscdevice.h> 6#include <linux/miscdevice.h>
7#include <linux/smp_lock.h>
8#include <linux/delay.h> 7#include <linux/delay.h>
9#include <linux/proc_fs.h> 8#include <linux/proc_fs.h>
10#include <linux/capability.h> 9#include <linux/capability.h>
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index db984e481d4c..9b8278e1f4f8 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -32,7 +32,6 @@
32#include <linux/fs.h> 32#include <linux/fs.h>
33#include <linux/mm.h> 33#include <linux/mm.h>
34#include <linux/init.h> 34#include <linux/init.h>
35#include <linux/smp_lock.h>
36#include <linux/device.h> 35#include <linux/device.h>
37 36
38#include <asm/atarihw.h> 37#include <asm/atarihw.h>
diff --git a/drivers/char/dtlk.c b/drivers/char/dtlk.c
index d8dbdb916232..abde6ddefe69 100644
--- a/drivers/char/dtlk.c
+++ b/drivers/char/dtlk.c
@@ -62,7 +62,6 @@
62#include <linux/init.h> /* for __init, module_{init,exit} */ 62#include <linux/init.h> /* for __init, module_{init,exit} */
63#include <linux/poll.h> /* for POLLIN, etc. */ 63#include <linux/poll.h> /* for POLLIN, etc. */
64#include <linux/dtlk.h> /* local header file for DoubleTalk values */ 64#include <linux/dtlk.h> /* local header file for DoubleTalk values */
65#include <linux/smp_lock.h>
66 65
67#ifdef TRACING 66#ifdef TRACING
68#define TRACE_TEXT(str) printk(str); 67#define TRACE_TEXT(str) printk(str);
@@ -325,16 +324,22 @@ static int dtlk_release(struct inode *inode, struct file *file)
325 324
326static int __init dtlk_init(void) 325static int __init dtlk_init(void)
327{ 326{
327 int err;
328
328 dtlk_port_lpc = 0; 329 dtlk_port_lpc = 0;
329 dtlk_port_tts = 0; 330 dtlk_port_tts = 0;
330 dtlk_busy = 0; 331 dtlk_busy = 0;
331 dtlk_major = register_chrdev(0, "dtlk", &dtlk_fops); 332 dtlk_major = register_chrdev(0, "dtlk", &dtlk_fops);
332 if (dtlk_major == 0) { 333 if (dtlk_major < 0) {
333 printk(KERN_ERR "DoubleTalk PC - cannot register device\n"); 334 printk(KERN_ERR "DoubleTalk PC - cannot register device\n");
334 return 0; 335 return dtlk_major;
336 }
337 err = dtlk_dev_probe();
338 if (err) {
339 unregister_chrdev(dtlk_major, "dtlk");
340 return err;
335 } 341 }
336 if (dtlk_dev_probe() == 0) 342 printk(", MAJOR %d\n", dtlk_major);
337 printk(", MAJOR %d\n", dtlk_major);
338 343
339 init_waitqueue_head(&dtlk_process_list); 344 init_waitqueue_head(&dtlk_process_list);
340 345
diff --git a/drivers/char/ec3104_keyb.c b/drivers/char/ec3104_keyb.c
index 77f58ed6d59a..020011495d91 100644
--- a/drivers/char/ec3104_keyb.c
+++ b/drivers/char/ec3104_keyb.c
@@ -41,7 +41,6 @@
41#include <linux/miscdevice.h> 41#include <linux/miscdevice.h>
42#include <linux/slab.h> 42#include <linux/slab.h>
43#include <linux/kbd_kern.h> 43#include <linux/kbd_kern.h>
44#include <linux/smp_lock.h>
45#include <linux/bitops.h> 44#include <linux/bitops.h>
46 45
47#include <asm/keyboard.h> 46#include <asm/keyboard.h>
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index de5be30484ad..c6c56fb8ba50 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -949,7 +949,7 @@ static int block_til_ready(struct tty_struct *tty,
949 949
950 } /* End forever while */ 950 } /* End forever while */
951 951
952 current->state = TASK_RUNNING; 952 __set_current_state(TASK_RUNNING);
953 remove_wait_queue(&ch->open_wait, &wait); 953 remove_wait_queue(&ch->open_wait, &wait);
954 if (!tty_hung_up_p(filp)) 954 if (!tty_hung_up_p(filp))
955 ch->count++; 955 ch->count++;
diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
index 23b25ada65ea..9e1fc02967ff 100644
--- a/drivers/char/genrtc.c
+++ b/drivers/char/genrtc.c
@@ -12,7 +12,7 @@
12 * 12 *
13 * This driver allows use of the real time clock (built into 13 * This driver allows use of the real time clock (built into
14 * nearly all computers) from user space. It exports the /dev/rtc 14 * nearly all computers) from user space. It exports the /dev/rtc
15 * interface supporting various ioctl() and also the /proc/dev/rtc 15 * interface supporting various ioctl() and also the /proc/driver/rtc
16 * pseudo-file for status information. 16 * pseudo-file for status information.
17 * 17 *
18 * The ioctls can be used to set the interrupt behaviour where 18 * The ioctls can be used to set the interrupt behaviour where
@@ -207,7 +207,7 @@ static ssize_t gen_rtc_read(struct file *file, char __user *buf,
207 sizeof(unsigned long); 207 sizeof(unsigned long);
208 } 208 }
209 out: 209 out:
210 current->state = TASK_RUNNING; 210 __set_current_state(TASK_RUNNING);
211 remove_wait_queue(&gen_rtc_wait, &wait); 211 remove_wait_queue(&gen_rtc_wait, &wait);
212 212
213 return retval; 213 return retval;
@@ -377,7 +377,7 @@ static int gen_rtc_release(struct inode *inode, struct file *file)
377#ifdef CONFIG_PROC_FS 377#ifdef CONFIG_PROC_FS
378 378
379/* 379/*
380 * Info exported via "/proc/rtc". 380 * Info exported via "/proc/driver/rtc".
381 */ 381 */
382 382
383static int gen_rtc_proc_output(char *buf) 383static int gen_rtc_proc_output(char *buf)
diff --git a/drivers/char/hangcheck-timer.c b/drivers/char/hangcheck-timer.c
index ae76a9ffe89f..0e8ceea5ea78 100644
--- a/drivers/char/hangcheck-timer.c
+++ b/drivers/char/hangcheck-timer.c
@@ -44,12 +44,11 @@
44#include <linux/fs.h> 44#include <linux/fs.h>
45#include <linux/mm.h> 45#include <linux/mm.h>
46#include <linux/reboot.h> 46#include <linux/reboot.h>
47#include <linux/smp_lock.h>
48#include <linux/init.h> 47#include <linux/init.h>
49#include <linux/delay.h> 48#include <linux/delay.h>
50#include <asm/uaccess.h> 49#include <asm/uaccess.h>
51#include <linux/sysrq.h> 50#include <linux/sysrq.h>
52 51#include <linux/timer.h>
53 52
54#define VERSION_STR "0.9.0" 53#define VERSION_STR "0.9.0"
55 54
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index 0f9ed7b46a6d..322bc5f7d86b 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -111,7 +111,7 @@ static int last_hvc = -1;
111 * lock held. If successful, this function increments the kobject reference 111 * lock held. If successful, this function increments the kobject reference
112 * count against the target hvc_struct so it should be released when finished. 112 * count against the target hvc_struct so it should be released when finished.
113 */ 113 */
114struct hvc_struct *hvc_get_by_index(int index) 114static struct hvc_struct *hvc_get_by_index(int index)
115{ 115{
116 struct hvc_struct *hp; 116 struct hvc_struct *hp;
117 unsigned long flags; 117 unsigned long flags;
@@ -150,7 +150,8 @@ static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] =
150 * hvc_console_setup() finds adapters. 150 * hvc_console_setup() finds adapters.
151 */ 151 */
152 152
153void hvc_console_print(struct console *co, const char *b, unsigned count) 153static void hvc_console_print(struct console *co, const char *b,
154 unsigned count)
154{ 155{
155 char c[N_OUTBUF] __ALIGNED__; 156 char c[N_OUTBUF] __ALIGNED__;
156 unsigned i = 0, n = 0; 157 unsigned i = 0, n = 0;
@@ -208,7 +209,7 @@ static int __init hvc_console_setup(struct console *co, char *options)
208 return 0; 209 return 0;
209} 210}
210 211
211struct console hvc_con_driver = { 212static struct console hvc_con_driver = {
212 .name = "hvc", 213 .name = "hvc",
213 .write = hvc_console_print, 214 .write = hvc_console_print,
214 .device = hvc_console_device, 215 .device = hvc_console_device,
@@ -278,7 +279,6 @@ int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops)
278 279
279 return 0; 280 return 0;
280} 281}
281EXPORT_SYMBOL(hvc_instantiate);
282 282
283/* Wake the sleeping khvcd */ 283/* Wake the sleeping khvcd */
284static void hvc_kick(void) 284static void hvc_kick(void)
@@ -792,7 +792,6 @@ struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int irq,
792 792
793 return hp; 793 return hp;
794} 794}
795EXPORT_SYMBOL(hvc_alloc);
796 795
797int __devexit hvc_remove(struct hvc_struct *hp) 796int __devexit hvc_remove(struct hvc_struct *hp)
798{ 797{
@@ -828,11 +827,10 @@ int __devexit hvc_remove(struct hvc_struct *hp)
828 tty_hangup(tty); 827 tty_hangup(tty);
829 return 0; 828 return 0;
830} 829}
831EXPORT_SYMBOL(hvc_remove);
832 830
833/* Driver initialization. Follow console initialization. This is where the TTY 831/* Driver initialization. Follow console initialization. This is where the TTY
834 * interfaces start to become available. */ 832 * interfaces start to become available. */
835int __init hvc_init(void) 833static int __init hvc_init(void)
836{ 834{
837 struct tty_driver *drv; 835 struct tty_driver *drv;
838 836
diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c
index ec420fe8a908..b37f1d5a5be6 100644
--- a/drivers/char/hvc_iseries.c
+++ b/drivers/char/hvc_iseries.c
@@ -579,7 +579,7 @@ static int hvc_find_vtys(void)
579 if (!vtermno) 579 if (!vtermno)
580 continue; 580 continue;
581 581
582 if (!device_is_compatible(vty, "IBM,iSeries-vty")) 582 if (!of_device_is_compatible(vty, "IBM,iSeries-vty"))
583 continue; 583 continue;
584 584
585 if (num_found == 0) 585 if (num_found == 0)
diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c
index 94a542e20efb..79711aa4b41d 100644
--- a/drivers/char/hvc_vio.c
+++ b/drivers/char/hvc_vio.c
@@ -157,7 +157,7 @@ static int hvc_find_vtys(void)
157 if (!vtermno) 157 if (!vtermno)
158 continue; 158 continue;
159 159
160 if (device_is_compatible(vty, "hvterm1")) { 160 if (of_device_is_compatible(vty, "hvterm1")) {
161 hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops); 161 hvc_instantiate(*vtermno, num_found, &hvc_get_put_ops);
162 ++num_found; 162 ++num_found;
163 } 163 }
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 5f3acd8e64b8..7cda04b33534 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -91,3 +91,17 @@ config HW_RANDOM_OMAP
91 module will be called omap-rng. 91 module will be called omap-rng.
92 92
93 If unsure, say Y. 93 If unsure, say Y.
94
95config HW_RANDOM_PASEMI
96 tristate "PA Semi HW Random Number Generator support"
97 depends on HW_RANDOM && PPC_PASEMI
98 default HW_RANDOM
99 ---help---
100 This driver provides kernel-side support for the Random Number
101 Generator hardware found on PA6T-1682M processor.
102
103 To compile this driver as a module, choose M here: the
104 module will be called pasemi-rng.
105
106 If unsure, say Y.
107
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index c41fa19454e3..c8b7300e2fb1 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -10,3 +10,4 @@ obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o
10obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o 10obj-$(CONFIG_HW_RANDOM_VIA) += via-rng.o
11obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o 11obj-$(CONFIG_HW_RANDOM_IXP4XX) += ixp4xx-rng.o
12obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o 12obj-$(CONFIG_HW_RANDOM_OMAP) += omap-rng.o
13obj-$(CONFIG_HW_RANDOM_PASEMI) += pasemi-rng.o
diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index cc1046e6ee02..4ae9811d1a6c 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -24,10 +24,11 @@
24 * warranty of any kind, whether express or implied. 24 * warranty of any kind, whether express or implied.
25 */ 25 */
26 26
27#include <linux/module.h> 27#include <linux/hw_random.h>
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/module.h>
29#include <linux/pci.h> 30#include <linux/pci.h>
30#include <linux/hw_random.h> 31#include <linux/stop_machine.h>
31#include <asm/io.h> 32#include <asm/io.h>
32 33
33 34
@@ -217,30 +218,117 @@ static struct hwrng intel_rng = {
217 .data_read = intel_rng_data_read, 218 .data_read = intel_rng_data_read,
218}; 219};
219 220
221struct intel_rng_hw {
222 struct pci_dev *dev;
223 void __iomem *mem;
224 u8 bios_cntl_off;
225 u8 bios_cntl_val;
226 u8 fwh_dec_en1_off;
227 u8 fwh_dec_en1_val;
228};
220 229
221#ifdef CONFIG_SMP 230static int __init intel_rng_hw_init(void *_intel_rng_hw)
222static char __initdata waitflag; 231{
232 struct intel_rng_hw *intel_rng_hw = _intel_rng_hw;
233 u8 mfc, dvc;
234
235 /* interrupts disabled in stop_machine_run call */
236
237 if (!(intel_rng_hw->fwh_dec_en1_val & FWH_F8_EN_MASK))
238 pci_write_config_byte(intel_rng_hw->dev,
239 intel_rng_hw->fwh_dec_en1_off,
240 intel_rng_hw->fwh_dec_en1_val |
241 FWH_F8_EN_MASK);
242 if (!(intel_rng_hw->bios_cntl_val & BIOS_CNTL_WRITE_ENABLE_MASK))
243 pci_write_config_byte(intel_rng_hw->dev,
244 intel_rng_hw->bios_cntl_off,
245 intel_rng_hw->bios_cntl_val |
246 BIOS_CNTL_WRITE_ENABLE_MASK);
247
248 writeb(INTEL_FWH_RESET_CMD, intel_rng_hw->mem);
249 writeb(INTEL_FWH_READ_ID_CMD, intel_rng_hw->mem);
250 mfc = readb(intel_rng_hw->mem + INTEL_FWH_MANUFACTURER_CODE_ADDRESS);
251 dvc = readb(intel_rng_hw->mem + INTEL_FWH_DEVICE_CODE_ADDRESS);
252 writeb(INTEL_FWH_RESET_CMD, intel_rng_hw->mem);
253
254 if (!(intel_rng_hw->bios_cntl_val &
255 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK)))
256 pci_write_config_byte(intel_rng_hw->dev,
257 intel_rng_hw->bios_cntl_off,
258 intel_rng_hw->bios_cntl_val);
259 if (!(intel_rng_hw->fwh_dec_en1_val & FWH_F8_EN_MASK))
260 pci_write_config_byte(intel_rng_hw->dev,
261 intel_rng_hw->fwh_dec_en1_off,
262 intel_rng_hw->fwh_dec_en1_val);
223 263
224static void __init intel_init_wait(void *unused) 264 if (mfc != INTEL_FWH_MANUFACTURER_CODE ||
265 (dvc != INTEL_FWH_DEVICE_CODE_8M &&
266 dvc != INTEL_FWH_DEVICE_CODE_4M)) {
267 printk(KERN_ERR PFX "FWH not detected\n");
268 return -ENODEV;
269 }
270
271 return 0;
272}
273
274static int __init intel_init_hw_struct(struct intel_rng_hw *intel_rng_hw,
275 struct pci_dev *dev)
225{ 276{
226 while (waitflag) 277 intel_rng_hw->bios_cntl_val = 0xff;
227 cpu_relax(); 278 intel_rng_hw->fwh_dec_en1_val = 0xff;
279 intel_rng_hw->dev = dev;
280
281 /* Check for Intel 82802 */
282 if (dev->device < 0x2640) {
283 intel_rng_hw->fwh_dec_en1_off = FWH_DEC_EN1_REG_OLD;
284 intel_rng_hw->bios_cntl_off = BIOS_CNTL_REG_OLD;
285 } else {
286 intel_rng_hw->fwh_dec_en1_off = FWH_DEC_EN1_REG_NEW;
287 intel_rng_hw->bios_cntl_off = BIOS_CNTL_REG_NEW;
288 }
289
290 pci_read_config_byte(dev, intel_rng_hw->fwh_dec_en1_off,
291 &intel_rng_hw->fwh_dec_en1_val);
292 pci_read_config_byte(dev, intel_rng_hw->bios_cntl_off,
293 &intel_rng_hw->bios_cntl_val);
294
295 if ((intel_rng_hw->bios_cntl_val &
296 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK))
297 == BIOS_CNTL_LOCK_ENABLE_MASK) {
298 static __initdata /*const*/ char warning[] =
299 KERN_WARNING PFX "Firmware space is locked read-only. "
300 KERN_WARNING PFX "If you can't or\n don't want to "
301 KERN_WARNING PFX "disable this in firmware setup, and "
302 KERN_WARNING PFX "if\n you are certain that your "
303 KERN_WARNING PFX "system has a functional\n RNG, try"
304 KERN_WARNING PFX "using the 'no_fwh_detect' option.\n";
305
306 if (no_fwh_detect)
307 return -ENODEV;
308 printk(warning);
309 return -EBUSY;
310 }
311
312 intel_rng_hw->mem = ioremap_nocache(INTEL_FWH_ADDR, INTEL_FWH_ADDR_LEN);
313 if (intel_rng_hw->mem == NULL)
314 return -EBUSY;
315
316 return 0;
228} 317}
229#endif 318
230 319
231static int __init mod_init(void) 320static int __init mod_init(void)
232{ 321{
233 int err = -ENODEV; 322 int err = -ENODEV;
234 unsigned i; 323 int i;
235 struct pci_dev *dev = NULL; 324 struct pci_dev *dev = NULL;
236 void __iomem *mem; 325 void __iomem *mem = mem;
237 unsigned long flags; 326 u8 hw_status;
238 u8 bios_cntl_off, fwh_dec_en1_off; 327 struct intel_rng_hw *intel_rng_hw;
239 u8 bios_cntl_val = 0xff, fwh_dec_en1_val = 0xff;
240 u8 hw_status, mfc, dvc;
241 328
242 for (i = 0; !dev && pci_tbl[i].vendor; ++i) 329 for (i = 0; !dev && pci_tbl[i].vendor; ++i)
243 dev = pci_get_device(pci_tbl[i].vendor, pci_tbl[i].device, NULL); 330 dev = pci_get_device(pci_tbl[i].vendor, pci_tbl[i].device,
331 NULL);
244 332
245 if (!dev) 333 if (!dev)
246 goto out; /* Device not found. */ 334 goto out; /* Device not found. */
@@ -250,39 +338,18 @@ static int __init mod_init(void)
250 goto fwh_done; 338 goto fwh_done;
251 } 339 }
252 340
253 /* Check for Intel 82802 */ 341 intel_rng_hw = kmalloc(sizeof(*intel_rng_hw), GFP_KERNEL);
254 if (dev->device < 0x2640) { 342 if (!intel_rng_hw) {
255 fwh_dec_en1_off = FWH_DEC_EN1_REG_OLD;
256 bios_cntl_off = BIOS_CNTL_REG_OLD;
257 } else {
258 fwh_dec_en1_off = FWH_DEC_EN1_REG_NEW;
259 bios_cntl_off = BIOS_CNTL_REG_NEW;
260 }
261
262 pci_read_config_byte(dev, fwh_dec_en1_off, &fwh_dec_en1_val);
263 pci_read_config_byte(dev, bios_cntl_off, &bios_cntl_val);
264
265 if ((bios_cntl_val &
266 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK))
267 == BIOS_CNTL_LOCK_ENABLE_MASK) {
268 static __initdata /*const*/ char warning[] =
269 KERN_WARNING PFX "Firmware space is locked read-only. If you can't or\n"
270 KERN_WARNING PFX "don't want to disable this in firmware setup, and if\n"
271 KERN_WARNING PFX "you are certain that your system has a functional\n"
272 KERN_WARNING PFX "RNG, try using the 'no_fwh_detect' option.\n";
273
274 pci_dev_put(dev); 343 pci_dev_put(dev);
275 if (no_fwh_detect)
276 goto fwh_done;
277 printk(warning);
278 err = -EBUSY;
279 goto out; 344 goto out;
280 } 345 }
281 346
282 mem = ioremap_nocache(INTEL_FWH_ADDR, INTEL_FWH_ADDR_LEN); 347 err = intel_init_hw_struct(intel_rng_hw, dev);
283 if (mem == NULL) { 348 if (err) {
284 pci_dev_put(dev); 349 pci_dev_put(dev);
285 err = -EBUSY; 350 kfree(intel_rng_hw);
351 if (err == -ENODEV)
352 goto fwh_done;
286 goto out; 353 goto out;
287 } 354 }
288 355
@@ -290,59 +357,18 @@ static int __init mod_init(void)
290 * Since the BIOS code/data is going to disappear from its normal 357 * Since the BIOS code/data is going to disappear from its normal
291 * location with the Read ID command, all activity on the system 358 * location with the Read ID command, all activity on the system
292 * must be stopped until the state is back to normal. 359 * must be stopped until the state is back to normal.
360 *
361 * Use stop_machine_run because IPIs can be blocked by disabling
362 * interrupts.
293 */ 363 */
294#ifdef CONFIG_SMP 364 err = stop_machine_run(intel_rng_hw_init, intel_rng_hw, NR_CPUS);
295 set_mb(waitflag, 1);
296 if (smp_call_function(intel_init_wait, NULL, 1, 0) != 0) {
297 set_mb(waitflag, 0);
298 pci_dev_put(dev);
299 printk(KERN_ERR PFX "cannot run on all processors\n");
300 err = -EAGAIN;
301 goto err_unmap;
302 }
303#endif
304 local_irq_save(flags);
305
306 if (!(fwh_dec_en1_val & FWH_F8_EN_MASK))
307 pci_write_config_byte(dev,
308 fwh_dec_en1_off,
309 fwh_dec_en1_val | FWH_F8_EN_MASK);
310 if (!(bios_cntl_val & BIOS_CNTL_WRITE_ENABLE_MASK))
311 pci_write_config_byte(dev,
312 bios_cntl_off,
313 bios_cntl_val | BIOS_CNTL_WRITE_ENABLE_MASK);
314
315 writeb(INTEL_FWH_RESET_CMD, mem);
316 writeb(INTEL_FWH_READ_ID_CMD, mem);
317 mfc = readb(mem + INTEL_FWH_MANUFACTURER_CODE_ADDRESS);
318 dvc = readb(mem + INTEL_FWH_DEVICE_CODE_ADDRESS);
319 writeb(INTEL_FWH_RESET_CMD, mem);
320
321 if (!(bios_cntl_val &
322 (BIOS_CNTL_LOCK_ENABLE_MASK|BIOS_CNTL_WRITE_ENABLE_MASK)))
323 pci_write_config_byte(dev, bios_cntl_off, bios_cntl_val);
324 if (!(fwh_dec_en1_val & FWH_F8_EN_MASK))
325 pci_write_config_byte(dev, fwh_dec_en1_off, fwh_dec_en1_val);
326
327 local_irq_restore(flags);
328#ifdef CONFIG_SMP
329 /* Tell other CPUs to resume. */
330 set_mb(waitflag, 0);
331#endif
332
333 iounmap(mem);
334 pci_dev_put(dev); 365 pci_dev_put(dev);
335 366 iounmap(intel_rng_hw->mem);
336 if (mfc != INTEL_FWH_MANUFACTURER_CODE || 367 kfree(intel_rng_hw);
337 (dvc != INTEL_FWH_DEVICE_CODE_8M && 368 if (err)
338 dvc != INTEL_FWH_DEVICE_CODE_4M)) {
339 printk(KERN_ERR PFX "FWH not detected\n");
340 err = -ENODEV;
341 goto out; 369 goto out;
342 }
343 370
344fwh_done: 371fwh_done:
345
346 err = -ENOMEM; 372 err = -ENOMEM;
347 mem = ioremap(INTEL_RNG_ADDR, INTEL_RNG_ADDR_LEN); 373 mem = ioremap(INTEL_RNG_ADDR, INTEL_RNG_ADDR_LEN);
348 if (!mem) 374 if (!mem)
@@ -352,22 +378,21 @@ fwh_done:
352 /* Check for Random Number Generator */ 378 /* Check for Random Number Generator */
353 err = -ENODEV; 379 err = -ENODEV;
354 hw_status = hwstatus_get(mem); 380 hw_status = hwstatus_get(mem);
355 if ((hw_status & INTEL_RNG_PRESENT) == 0) 381 if ((hw_status & INTEL_RNG_PRESENT) == 0) {
356 goto err_unmap; 382 iounmap(mem);
383 goto out;
384 }
357 385
358 printk(KERN_INFO "Intel 82802 RNG detected\n"); 386 printk(KERN_INFO "Intel 82802 RNG detected\n");
359 err = hwrng_register(&intel_rng); 387 err = hwrng_register(&intel_rng);
360 if (err) { 388 if (err) {
361 printk(KERN_ERR PFX "RNG registering failed (%d)\n", 389 printk(KERN_ERR PFX "RNG registering failed (%d)\n",
362 err); 390 err);
363 goto err_unmap; 391 iounmap(mem);
364 } 392 }
365out: 393out:
366 return err; 394 return err;
367 395
368err_unmap:
369 iounmap(mem);
370 goto out;
371} 396}
372 397
373static void __exit mod_exit(void) 398static void __exit mod_exit(void)
diff --git a/drivers/char/hw_random/pasemi-rng.c b/drivers/char/hw_random/pasemi-rng.c
new file mode 100644
index 000000000000..fa6040b6c8f2
--- /dev/null
+++ b/drivers/char/hw_random/pasemi-rng.c
@@ -0,0 +1,156 @@
1/*
2 * Copyright (C) 2006-2007 PA Semi, Inc
3 *
4 * Maintained by: Olof Johansson <olof@lixom.net>
5 *
6 * Driver for the PWRficient onchip rng
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 version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/platform_device.h>
25#include <linux/hw_random.h>
26#include <asm/of_platform.h>
27#include <asm/io.h>
28
29#define SDCRNG_CTL_REG 0x00
30#define SDCRNG_CTL_FVLD_M 0x0000f000
31#define SDCRNG_CTL_FVLD_S 12
32#define SDCRNG_CTL_KSZ 0x00000800
33#define SDCRNG_CTL_RSRC_CRG 0x00000010
34#define SDCRNG_CTL_RSRC_RRG 0x00000000
35#define SDCRNG_CTL_CE 0x00000004
36#define SDCRNG_CTL_RE 0x00000002
37#define SDCRNG_CTL_DR 0x00000001
38#define SDCRNG_CTL_SELECT_RRG_RNG (SDCRNG_CTL_RE | SDCRNG_CTL_RSRC_RRG)
39#define SDCRNG_CTL_SELECT_CRG_RNG (SDCRNG_CTL_CE | SDCRNG_CTL_RSRC_CRG)
40#define SDCRNG_VAL_REG 0x20
41
42#define MODULE_NAME "pasemi_rng"
43
44static int pasemi_rng_data_present(struct hwrng *rng)
45{
46 void __iomem *rng_regs = (void __iomem *)rng->priv;
47
48 return (in_le32(rng_regs + SDCRNG_CTL_REG)
49 & SDCRNG_CTL_FVLD_M) ? 1 : 0;
50}
51
52static int pasemi_rng_data_read(struct hwrng *rng, u32 *data)
53{
54 void __iomem *rng_regs = (void __iomem *)rng->priv;
55 *data = in_le32(rng_regs + SDCRNG_VAL_REG);
56 return 4;
57}
58
59static int pasemi_rng_init(struct hwrng *rng)
60{
61 void __iomem *rng_regs = (void __iomem *)rng->priv;
62 u32 ctl;
63
64 ctl = SDCRNG_CTL_DR | SDCRNG_CTL_SELECT_RRG_RNG | SDCRNG_CTL_KSZ;
65 out_le32(rng_regs + SDCRNG_CTL_REG, ctl);
66 out_le32(rng_regs + SDCRNG_CTL_REG, ctl & ~SDCRNG_CTL_DR);
67
68 return 0;
69}
70
71static void pasemi_rng_cleanup(struct hwrng *rng)
72{
73 void __iomem *rng_regs = (void __iomem *)rng->priv;
74 u32 ctl;
75
76 ctl = SDCRNG_CTL_RE | SDCRNG_CTL_CE;
77 out_le32(rng_regs + SDCRNG_CTL_REG,
78 in_le32(rng_regs + SDCRNG_CTL_REG) & ~ctl);
79}
80
81static struct hwrng pasemi_rng = {
82 .name = MODULE_NAME,
83 .init = pasemi_rng_init,
84 .cleanup = pasemi_rng_cleanup,
85 .data_present = pasemi_rng_data_present,
86 .data_read = pasemi_rng_data_read,
87};
88
89static int __devinit rng_probe(struct of_device *ofdev,
90 const struct of_device_id *match)
91{
92 void __iomem *rng_regs;
93 struct device_node *rng_np = ofdev->node;
94 struct resource res;
95 int err = 0;
96
97 err = of_address_to_resource(rng_np, 0, &res);
98 if (err)
99 return -ENODEV;
100
101 rng_regs = ioremap(res.start, 0x100);
102
103 if (!rng_regs)
104 return -ENOMEM;
105
106 pasemi_rng.priv = (unsigned long)rng_regs;
107
108 printk(KERN_INFO "Registering PA Semi RNG\n");
109
110 err = hwrng_register(&pasemi_rng);
111
112 if (err)
113 iounmap(rng_regs);
114
115 return err;
116}
117
118static int __devexit rng_remove(struct of_device *dev)
119{
120 void __iomem *rng_regs = (void __iomem *)pasemi_rng.priv;
121
122 hwrng_unregister(&pasemi_rng);
123 iounmap(rng_regs);
124
125 return 0;
126}
127
128static struct of_device_id rng_match[] = {
129 {
130 .compatible = "1682m-rng",
131 },
132 {},
133};
134
135static struct of_platform_driver rng_driver = {
136 .name = "pasemi-rng",
137 .match_table = rng_match,
138 .probe = rng_probe,
139 .remove = rng_remove,
140};
141
142static int __init rng_init(void)
143{
144 return of_register_platform_driver(&rng_driver);
145}
146module_init(rng_init);
147
148static void __exit rng_exit(void)
149{
150 of_unregister_platform_driver(&rng_driver);
151}
152module_exit(rng_exit);
153
154MODULE_LICENSE("GPL");
155MODULE_AUTHOR("Egor Martovetsky <egor@pasemi.com>");
156MODULE_DESCRIPTION("H/W RNG driver for PA Semi processor");
diff --git a/drivers/char/i8k.c b/drivers/char/i8k.c
index 353d9f3cf8d7..0289705967de 100644
--- a/drivers/char/i8k.c
+++ b/drivers/char/i8k.c
@@ -22,6 +22,7 @@
22#include <linux/proc_fs.h> 22#include <linux/proc_fs.h>
23#include <linux/seq_file.h> 23#include <linux/seq_file.h>
24#include <linux/dmi.h> 24#include <linux/dmi.h>
25#include <linux/capability.h>
25#include <asm/uaccess.h> 26#include <asm/uaccess.h>
26#include <asm/io.h> 27#include <asm/io.h>
27 28
diff --git a/drivers/char/ip27-rtc.c b/drivers/char/ip27-rtc.c
index a48da02aad2f..932264a657d0 100644
--- a/drivers/char/ip27-rtc.c
+++ b/drivers/char/ip27-rtc.c
@@ -35,7 +35,6 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/poll.h> 36#include <linux/poll.h>
37#include <linux/proc_fs.h> 37#include <linux/proc_fs.h>
38#include <linux/smp_lock.h>
39 38
40#include <asm/m48t35.h> 39#include <asm/m48t35.h>
41#include <asm/sn/ioc3.h> 40#include <asm/sn/ioc3.h>
diff --git a/drivers/char/ipmi/Kconfig b/drivers/char/ipmi/Kconfig
index a6dcb2918157..b894f67fdf14 100644
--- a/drivers/char/ipmi/Kconfig
+++ b/drivers/char/ipmi/Kconfig
@@ -3,6 +3,8 @@
3# 3#
4 4
5menu "IPMI" 5menu "IPMI"
6 depends on HAS_IOMEM
7
6config IPMI_HANDLER 8config IPMI_HANDLER
7 tristate 'IPMI top-level message handler' 9 tristate 'IPMI top-level message handler'
8 help 10 help
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index e22146546add..78e1b962fe35 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -9,6 +9,7 @@
9 * source@mvista.com 9 * source@mvista.com
10 * 10 *
11 * Copyright 2002 MontaVista Software Inc. 11 * Copyright 2002 MontaVista Software Inc.
12 * Copyright 2006 IBM Corp., Christian Krafft <krafft@de.ibm.com>
12 * 13 *
13 * This program is free software; you can redistribute it and/or modify it 14 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the 15 * under the terms of the GNU General Public License as published by the
@@ -64,6 +65,11 @@
64#include <linux/string.h> 65#include <linux/string.h>
65#include <linux/ctype.h> 66#include <linux/ctype.h>
66 67
68#ifdef CONFIG_PPC_OF
69#include <asm/of_device.h>
70#include <asm/of_platform.h>
71#endif
72
67#define PFX "ipmi_si: " 73#define PFX "ipmi_si: "
68 74
69/* Measure times between events in the driver. */ 75/* Measure times between events in the driver. */
@@ -76,6 +82,12 @@
76#define SI_SHORT_TIMEOUT_USEC 250 /* .25ms when the SM request a 82#define SI_SHORT_TIMEOUT_USEC 250 /* .25ms when the SM request a
77 short timeout */ 83 short timeout */
78 84
85/* Bit for BMC global enables. */
86#define IPMI_BMC_RCV_MSG_INTR 0x01
87#define IPMI_BMC_EVT_MSG_INTR 0x02
88#define IPMI_BMC_EVT_MSG_BUFF 0x04
89#define IPMI_BMC_SYS_LOG 0x08
90
79enum si_intf_state { 91enum si_intf_state {
80 SI_NORMAL, 92 SI_NORMAL,
81 SI_GETTING_FLAGS, 93 SI_GETTING_FLAGS,
@@ -84,7 +96,9 @@ enum si_intf_state {
84 SI_CLEARING_FLAGS_THEN_SET_IRQ, 96 SI_CLEARING_FLAGS_THEN_SET_IRQ,
85 SI_GETTING_MESSAGES, 97 SI_GETTING_MESSAGES,
86 SI_ENABLE_INTERRUPTS1, 98 SI_ENABLE_INTERRUPTS1,
87 SI_ENABLE_INTERRUPTS2 99 SI_ENABLE_INTERRUPTS2,
100 SI_DISABLE_INTERRUPTS1,
101 SI_DISABLE_INTERRUPTS2
88 /* FIXME - add watchdog stuff. */ 102 /* FIXME - add watchdog stuff. */
89}; 103};
90 104
@@ -333,6 +347,17 @@ static void start_enable_irq(struct smi_info *smi_info)
333 smi_info->si_state = SI_ENABLE_INTERRUPTS1; 347 smi_info->si_state = SI_ENABLE_INTERRUPTS1;
334} 348}
335 349
350static void start_disable_irq(struct smi_info *smi_info)
351{
352 unsigned char msg[2];
353
354 msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
355 msg[1] = IPMI_GET_BMC_GLOBAL_ENABLES_CMD;
356
357 smi_info->handlers->start_transaction(smi_info->si_sm, msg, 2);
358 smi_info->si_state = SI_DISABLE_INTERRUPTS1;
359}
360
336static void start_clear_flags(struct smi_info *smi_info) 361static void start_clear_flags(struct smi_info *smi_info)
337{ 362{
338 unsigned char msg[3]; 363 unsigned char msg[3];
@@ -353,7 +378,7 @@ static void start_clear_flags(struct smi_info *smi_info)
353static inline void disable_si_irq(struct smi_info *smi_info) 378static inline void disable_si_irq(struct smi_info *smi_info)
354{ 379{
355 if ((smi_info->irq) && (!smi_info->interrupt_disabled)) { 380 if ((smi_info->irq) && (!smi_info->interrupt_disabled)) {
356 disable_irq_nosync(smi_info->irq); 381 start_disable_irq(smi_info);
357 smi_info->interrupt_disabled = 1; 382 smi_info->interrupt_disabled = 1;
358 } 383 }
359} 384}
@@ -361,7 +386,7 @@ static inline void disable_si_irq(struct smi_info *smi_info)
361static inline void enable_si_irq(struct smi_info *smi_info) 386static inline void enable_si_irq(struct smi_info *smi_info)
362{ 387{
363 if ((smi_info->irq) && (smi_info->interrupt_disabled)) { 388 if ((smi_info->irq) && (smi_info->interrupt_disabled)) {
364 enable_irq(smi_info->irq); 389 start_enable_irq(smi_info);
365 smi_info->interrupt_disabled = 0; 390 smi_info->interrupt_disabled = 0;
366 } 391 }
367} 392}
@@ -583,7 +608,9 @@ static void handle_transaction_done(struct smi_info *smi_info)
583 } else { 608 } else {
584 msg[0] = (IPMI_NETFN_APP_REQUEST << 2); 609 msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
585 msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD; 610 msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
586 msg[2] = msg[3] | 1; /* enable msg queue int */ 611 msg[2] = (msg[3] |
612 IPMI_BMC_RCV_MSG_INTR |
613 IPMI_BMC_EVT_MSG_INTR);
587 smi_info->handlers->start_transaction( 614 smi_info->handlers->start_transaction(
588 smi_info->si_sm, msg, 3); 615 smi_info->si_sm, msg, 3);
589 smi_info->si_state = SI_ENABLE_INTERRUPTS2; 616 smi_info->si_state = SI_ENABLE_INTERRUPTS2;
@@ -605,6 +632,45 @@ static void handle_transaction_done(struct smi_info *smi_info)
605 smi_info->si_state = SI_NORMAL; 632 smi_info->si_state = SI_NORMAL;
606 break; 633 break;
607 } 634 }
635
636 case SI_DISABLE_INTERRUPTS1:
637 {
638 unsigned char msg[4];
639
640 /* We got the flags from the SMI, now handle them. */
641 smi_info->handlers->get_result(smi_info->si_sm, msg, 4);
642 if (msg[2] != 0) {
643 printk(KERN_WARNING
644 "ipmi_si: Could not disable interrupts"
645 ", failed get.\n");
646 smi_info->si_state = SI_NORMAL;
647 } else {
648 msg[0] = (IPMI_NETFN_APP_REQUEST << 2);
649 msg[1] = IPMI_SET_BMC_GLOBAL_ENABLES_CMD;
650 msg[2] = (msg[3] &
651 ~(IPMI_BMC_RCV_MSG_INTR |
652 IPMI_BMC_EVT_MSG_INTR));
653 smi_info->handlers->start_transaction(
654 smi_info->si_sm, msg, 3);
655 smi_info->si_state = SI_DISABLE_INTERRUPTS2;
656 }
657 break;
658 }
659
660 case SI_DISABLE_INTERRUPTS2:
661 {
662 unsigned char msg[4];
663
664 /* We got the flags from the SMI, now handle them. */
665 smi_info->handlers->get_result(smi_info->si_sm, msg, 4);
666 if (msg[2] != 0) {
667 printk(KERN_WARNING
668 "ipmi_si: Could not disable interrupts"
669 ", failed set.\n");
670 }
671 smi_info->si_state = SI_NORMAL;
672 break;
673 }
608 } 674 }
609} 675}
610 676
@@ -858,9 +924,6 @@ static void smi_timeout(unsigned long data)
858 struct timeval t; 924 struct timeval t;
859#endif 925#endif
860 926
861 if (atomic_read(&smi_info->stop_operation))
862 return;
863
864 spin_lock_irqsave(&(smi_info->si_lock), flags); 927 spin_lock_irqsave(&(smi_info->si_lock), flags);
865#ifdef DEBUG_TIMING 928#ifdef DEBUG_TIMING
866 do_gettimeofday(&t); 929 do_gettimeofday(&t);
@@ -916,15 +979,11 @@ static irqreturn_t si_irq_handler(int irq, void *data)
916 smi_info->interrupts++; 979 smi_info->interrupts++;
917 spin_unlock(&smi_info->count_lock); 980 spin_unlock(&smi_info->count_lock);
918 981
919 if (atomic_read(&smi_info->stop_operation))
920 goto out;
921
922#ifdef DEBUG_TIMING 982#ifdef DEBUG_TIMING
923 do_gettimeofday(&t); 983 do_gettimeofday(&t);
924 printk("**Interrupt: %d.%9.9d\n", t.tv_sec, t.tv_usec); 984 printk("**Interrupt: %d.%9.9d\n", t.tv_sec, t.tv_usec);
925#endif 985#endif
926 smi_event_handler(smi_info, 0); 986 smi_event_handler(smi_info, 0);
927 out:
928 spin_unlock_irqrestore(&(smi_info->si_lock), flags); 987 spin_unlock_irqrestore(&(smi_info->si_lock), flags);
929 return IRQ_HANDLED; 988 return IRQ_HANDLED;
930} 989}
@@ -1006,6 +1065,7 @@ static DEFINE_MUTEX(smi_infos_lock);
1006static int smi_num; /* Used to sequence the SMIs */ 1065static int smi_num; /* Used to sequence the SMIs */
1007 1066
1008#define DEFAULT_REGSPACING 1 1067#define DEFAULT_REGSPACING 1
1068#define DEFAULT_REGSIZE 1
1009 1069
1010static int si_trydefaults = 1; 1070static int si_trydefaults = 1;
1011static char *si_type[SI_MAX_PARMS]; 1071static char *si_type[SI_MAX_PARMS];
@@ -1111,7 +1171,7 @@ static int std_irq_setup(struct smi_info *info)
1111 if (info->si_type == SI_BT) { 1171 if (info->si_type == SI_BT) {
1112 rv = request_irq(info->irq, 1172 rv = request_irq(info->irq,
1113 si_bt_irq_handler, 1173 si_bt_irq_handler,
1114 IRQF_DISABLED, 1174 IRQF_SHARED | IRQF_DISABLED,
1115 DEVICE_NAME, 1175 DEVICE_NAME,
1116 info); 1176 info);
1117 if (!rv) 1177 if (!rv)
@@ -1121,7 +1181,7 @@ static int std_irq_setup(struct smi_info *info)
1121 } else 1181 } else
1122 rv = request_irq(info->irq, 1182 rv = request_irq(info->irq,
1123 si_irq_handler, 1183 si_irq_handler,
1124 IRQF_DISABLED, 1184 IRQF_SHARED | IRQF_DISABLED,
1125 DEVICE_NAME, 1185 DEVICE_NAME,
1126 info); 1186 info);
1127 if (rv) { 1187 if (rv) {
@@ -1701,15 +1761,11 @@ static u32 ipmi_acpi_gpe(void *context)
1701 smi_info->interrupts++; 1761 smi_info->interrupts++;
1702 spin_unlock(&smi_info->count_lock); 1762 spin_unlock(&smi_info->count_lock);
1703 1763
1704 if (atomic_read(&smi_info->stop_operation))
1705 goto out;
1706
1707#ifdef DEBUG_TIMING 1764#ifdef DEBUG_TIMING
1708 do_gettimeofday(&t); 1765 do_gettimeofday(&t);
1709 printk("**ACPI_GPE: %d.%9.9d\n", t.tv_sec, t.tv_usec); 1766 printk("**ACPI_GPE: %d.%9.9d\n", t.tv_sec, t.tv_usec);
1710#endif 1767#endif
1711 smi_event_handler(smi_info, 0); 1768 smi_event_handler(smi_info, 0);
1712 out:
1713 spin_unlock_irqrestore(&(smi_info->si_lock), flags); 1769 spin_unlock_irqrestore(&(smi_info->si_lock), flags);
1714 1770
1715 return ACPI_INTERRUPT_HANDLED; 1771 return ACPI_INTERRUPT_HANDLED;
@@ -1859,10 +1915,10 @@ static __devinit int try_init_acpi(struct SPMITable *spmi)
1859 1915
1860 if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) { 1916 if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_MEMORY) {
1861 info->io_setup = mem_setup; 1917 info->io_setup = mem_setup;
1862 info->io.addr_type = IPMI_IO_ADDR_SPACE; 1918 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
1863 } else if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_IO) { 1919 } else if (spmi->addr.space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
1864 info->io_setup = port_setup; 1920 info->io_setup = port_setup;
1865 info->io.addr_type = IPMI_MEM_ADDR_SPACE; 1921 info->io.addr_type = IPMI_IO_ADDR_SPACE;
1866 } else { 1922 } else {
1867 kfree(info); 1923 kfree(info);
1868 printk("ipmi_si: Unknown ACPI I/O Address type\n"); 1924 printk("ipmi_si: Unknown ACPI I/O Address type\n");
@@ -2133,12 +2189,15 @@ static int __devinit ipmi_pci_probe(struct pci_dev *pdev,
2133 info->irq_setup = std_irq_setup; 2189 info->irq_setup = std_irq_setup;
2134 2190
2135 info->dev = &pdev->dev; 2191 info->dev = &pdev->dev;
2192 pci_set_drvdata(pdev, info);
2136 2193
2137 return try_smi_init(info); 2194 return try_smi_init(info);
2138} 2195}
2139 2196
2140static void __devexit ipmi_pci_remove(struct pci_dev *pdev) 2197static void __devexit ipmi_pci_remove(struct pci_dev *pdev)
2141{ 2198{
2199 struct smi_info *info = pci_get_drvdata(pdev);
2200 cleanup_one_si(info);
2142} 2201}
2143 2202
2144#ifdef CONFIG_PM 2203#ifdef CONFIG_PM
@@ -2172,6 +2231,99 @@ static struct pci_driver ipmi_pci_driver = {
2172#endif /* CONFIG_PCI */ 2231#endif /* CONFIG_PCI */
2173 2232
2174 2233
2234#ifdef CONFIG_PPC_OF
2235static int __devinit ipmi_of_probe(struct of_device *dev,
2236 const struct of_device_id *match)
2237{
2238 struct smi_info *info;
2239 struct resource resource;
2240 const int *regsize, *regspacing, *regshift;
2241 struct device_node *np = dev->node;
2242 int ret;
2243 int proplen;
2244
2245 dev_info(&dev->dev, PFX "probing via device tree\n");
2246
2247 ret = of_address_to_resource(np, 0, &resource);
2248 if (ret) {
2249 dev_warn(&dev->dev, PFX "invalid address from OF\n");
2250 return ret;
2251 }
2252
2253 regsize = get_property(np, "reg-size", &proplen);
2254 if (regsize && proplen != 4) {
2255 dev_warn(&dev->dev, PFX "invalid regsize from OF\n");
2256 return -EINVAL;
2257 }
2258
2259 regspacing = get_property(np, "reg-spacing", &proplen);
2260 if (regspacing && proplen != 4) {
2261 dev_warn(&dev->dev, PFX "invalid regspacing from OF\n");
2262 return -EINVAL;
2263 }
2264
2265 regshift = get_property(np, "reg-shift", &proplen);
2266 if (regshift && proplen != 4) {
2267 dev_warn(&dev->dev, PFX "invalid regshift from OF\n");
2268 return -EINVAL;
2269 }
2270
2271 info = kzalloc(sizeof(*info), GFP_KERNEL);
2272
2273 if (!info) {
2274 dev_err(&dev->dev,
2275 PFX "could not allocate memory for OF probe\n");
2276 return -ENOMEM;
2277 }
2278
2279 info->si_type = (enum si_type) match->data;
2280 info->addr_source = "device-tree";
2281 info->io_setup = mem_setup;
2282 info->irq_setup = std_irq_setup;
2283
2284 info->io.addr_type = IPMI_MEM_ADDR_SPACE;
2285 info->io.addr_data = resource.start;
2286
2287 info->io.regsize = regsize ? *regsize : DEFAULT_REGSIZE;
2288 info->io.regspacing = regspacing ? *regspacing : DEFAULT_REGSPACING;
2289 info->io.regshift = regshift ? *regshift : 0;
2290
2291 info->irq = irq_of_parse_and_map(dev->node, 0);
2292 info->dev = &dev->dev;
2293
2294 dev_dbg(&dev->dev, "addr 0x%lx regsize %ld spacing %ld irq %x\n",
2295 info->io.addr_data, info->io.regsize, info->io.regspacing,
2296 info->irq);
2297
2298 dev->dev.driver_data = (void*) info;
2299
2300 return try_smi_init(info);
2301}
2302
2303static int __devexit ipmi_of_remove(struct of_device *dev)
2304{
2305 cleanup_one_si(dev->dev.driver_data);
2306 return 0;
2307}
2308
2309static struct of_device_id ipmi_match[] =
2310{
2311 { .type = "ipmi", .compatible = "ipmi-kcs", .data = (void *)(unsigned long) SI_KCS },
2312 { .type = "ipmi", .compatible = "ipmi-smic", .data = (void *)(unsigned long) SI_SMIC },
2313 { .type = "ipmi", .compatible = "ipmi-bt", .data = (void *)(unsigned long) SI_BT },
2314 {},
2315};
2316
2317static struct of_platform_driver ipmi_of_platform_driver =
2318{
2319 .name = "ipmi",
2320 .match_table = ipmi_match,
2321 .probe = ipmi_of_probe,
2322 .remove = __devexit_p(ipmi_of_remove),
2323};
2324#endif /* CONFIG_PPC_OF */
2325
2326
2175static int try_get_dev_id(struct smi_info *smi_info) 2327static int try_get_dev_id(struct smi_info *smi_info)
2176{ 2328{
2177 unsigned char msg[2]; 2329 unsigned char msg[2];
@@ -2801,6 +2953,10 @@ static __devinit int init_ipmi_si(void)
2801 } 2953 }
2802#endif 2954#endif
2803 2955
2956#ifdef CONFIG_PPC_OF
2957 of_register_platform_driver(&ipmi_of_platform_driver);
2958#endif
2959
2804 if (si_trydefaults) { 2960 if (si_trydefaults) {
2805 mutex_lock(&smi_infos_lock); 2961 mutex_lock(&smi_infos_lock);
2806 if (list_empty(&smi_infos)) { 2962 if (list_empty(&smi_infos)) {
@@ -2818,6 +2974,10 @@ static __devinit int init_ipmi_si(void)
2818#ifdef CONFIG_PCI 2974#ifdef CONFIG_PCI
2819 pci_unregister_driver(&ipmi_pci_driver); 2975 pci_unregister_driver(&ipmi_pci_driver);
2820#endif 2976#endif
2977
2978#ifdef CONFIG_PPC_OF
2979 of_unregister_platform_driver(&ipmi_of_platform_driver);
2980#endif
2821 driver_unregister(&ipmi_driver); 2981 driver_unregister(&ipmi_driver);
2822 printk("ipmi_si: Unable to find any System Interface(s)\n"); 2982 printk("ipmi_si: Unable to find any System Interface(s)\n");
2823 return -ENODEV; 2983 return -ENODEV;
@@ -2838,28 +2998,33 @@ static void cleanup_one_si(struct smi_info *to_clean)
2838 2998
2839 list_del(&to_clean->link); 2999 list_del(&to_clean->link);
2840 3000
2841 /* Tell the timer and interrupt handlers that we are shutting 3001 /* Tell the driver that we are shutting down. */
2842 down. */
2843 spin_lock_irqsave(&(to_clean->si_lock), flags);
2844 spin_lock(&(to_clean->msg_lock));
2845
2846 atomic_inc(&to_clean->stop_operation); 3002 atomic_inc(&to_clean->stop_operation);
2847 3003
2848 if (to_clean->irq_cleanup) 3004 /* Make sure the timer and thread are stopped and will not run
2849 to_clean->irq_cleanup(to_clean); 3005 again. */
2850
2851 spin_unlock(&(to_clean->msg_lock));
2852 spin_unlock_irqrestore(&(to_clean->si_lock), flags);
2853
2854 /* Wait until we know that we are out of any interrupt
2855 handlers might have been running before we freed the
2856 interrupt. */
2857 synchronize_sched();
2858
2859 wait_for_timer_and_thread(to_clean); 3006 wait_for_timer_and_thread(to_clean);
2860 3007
2861 /* Interrupts and timeouts are stopped, now make sure the 3008 /* Timeouts are stopped, now make sure the interrupts are off
2862 interface is in a clean state. */ 3009 for the device. A little tricky with locks to make sure
3010 there are no races. */
3011 spin_lock_irqsave(&to_clean->si_lock, flags);
3012 while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
3013 spin_unlock_irqrestore(&to_clean->si_lock, flags);
3014 poll(to_clean);
3015 schedule_timeout_uninterruptible(1);
3016 spin_lock_irqsave(&to_clean->si_lock, flags);
3017 }
3018 disable_si_irq(to_clean);
3019 spin_unlock_irqrestore(&to_clean->si_lock, flags);
3020 while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
3021 poll(to_clean);
3022 schedule_timeout_uninterruptible(1);
3023 }
3024
3025 /* Clean up interrupts and make sure that everything is done. */
3026 if (to_clean->irq_cleanup)
3027 to_clean->irq_cleanup(to_clean);
2863 while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) { 3028 while (to_clean->curr_msg || (to_clean->si_state != SI_NORMAL)) {
2864 poll(to_clean); 3029 poll(to_clean);
2865 schedule_timeout_uninterruptible(1); 3030 schedule_timeout_uninterruptible(1);
@@ -2898,6 +3063,10 @@ static __exit void cleanup_ipmi_si(void)
2898 pci_unregister_driver(&ipmi_pci_driver); 3063 pci_unregister_driver(&ipmi_pci_driver);
2899#endif 3064#endif
2900 3065
3066#ifdef CONFIG_PPC_OF
3067 of_unregister_platform_driver(&ipmi_of_platform_driver);
3068#endif
3069
2901 mutex_lock(&smi_infos_lock); 3070 mutex_lock(&smi_infos_lock);
2902 list_for_each_entry_safe(e, tmp_e, &smi_infos, link) 3071 list_for_each_entry_safe(e, tmp_e, &smi_infos, link)
2903 cleanup_one_si(e); 3072 cleanup_one_si(e);
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 6b634e8d9519..41f78e2c158f 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -39,6 +39,7 @@
39#include <linux/miscdevice.h> 39#include <linux/miscdevice.h>
40#include <linux/init.h> 40#include <linux/init.h>
41#include <linux/completion.h> 41#include <linux/completion.h>
42#include <linux/kdebug.h>
42#include <linux/rwsem.h> 43#include <linux/rwsem.h>
43#include <linux/errno.h> 44#include <linux/errno.h>
44#include <asm/uaccess.h> 45#include <asm/uaccess.h>
@@ -50,6 +51,7 @@
50#include <linux/string.h> 51#include <linux/string.h>
51#include <linux/ctype.h> 52#include <linux/ctype.h>
52#include <asm/atomic.h> 53#include <asm/atomic.h>
54
53#ifdef CONFIG_X86_LOCAL_APIC 55#ifdef CONFIG_X86_LOCAL_APIC
54#include <asm/apic.h> 56#include <asm/apic.h>
55#endif 57#endif
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 43ab9edc76f5..761f77740d67 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -137,11 +137,10 @@
137#define InterruptTheCard(base) outw(0, (base) + 0xc) 137#define InterruptTheCard(base) outw(0, (base) + 0xc)
138#define ClearInterrupt(base) inw((base) + 0x0a) 138#define ClearInterrupt(base) inw((base) + 0x0a)
139 139
140#define pr_dbg(str...) pr_debug("ISICOM: " str)
140#ifdef DEBUG 141#ifdef DEBUG
141#define pr_dbg(str...) printk(KERN_DEBUG "ISICOM: " str)
142#define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c)) 142#define isicom_paranoia_check(a, b, c) __isicom_paranoia_check((a), (b), (c))
143#else 143#else
144#define pr_dbg(str...) do { } while (0)
145#define isicom_paranoia_check(a, b, c) 0 144#define isicom_paranoia_check(a, b, c) 0
146#endif 145#endif
147 146
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index c06e86ad1dab..1b094509b1d2 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -109,7 +109,7 @@ struct kbd_struct kbd_table[MAX_NR_CONSOLES];
109static struct kbd_struct *kbd = kbd_table; 109static struct kbd_struct *kbd = kbd_table;
110 110
111struct vt_spawn_console vt_spawn_con = { 111struct vt_spawn_console vt_spawn_con = {
112 .lock = SPIN_LOCK_UNLOCKED, 112 .lock = __SPIN_LOCK_UNLOCKED(vt_spawn_con.lock),
113 .pid = NULL, 113 .pid = NULL,
114 .sig = 0, 114 .sig = 0,
115}; 115};
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index b51d08be0bcf..62051f8b0910 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -118,7 +118,6 @@
118#include <linux/kernel.h> 118#include <linux/kernel.h>
119#include <linux/major.h> 119#include <linux/major.h>
120#include <linux/sched.h> 120#include <linux/sched.h>
121#include <linux/smp_lock.h>
122#include <linux/slab.h> 121#include <linux/slab.h>
123#include <linux/fcntl.h> 122#include <linux/fcntl.h>
124#include <linux/delay.h> 123#include <linux/delay.h>
@@ -139,9 +138,6 @@
139/* if you have more than 8 printers, remember to increase LP_NO */ 138/* if you have more than 8 printers, remember to increase LP_NO */
140#define LP_NO 8 139#define LP_NO 8
141 140
142/* ROUND_UP macro from fs/select.c */
143#define ROUND_UP(x,y) (((x)+(y)-1)/(y))
144
145static struct lp_struct lp_table[LP_NO]; 141static struct lp_struct lp_table[LP_NO];
146 142
147static unsigned int lp_count = 0; 143static unsigned int lp_count = 0;
@@ -652,7 +648,7 @@ static int lp_ioctl(struct inode *inode, struct file *file,
652 (par_timeout.tv_usec < 0)) { 648 (par_timeout.tv_usec < 0)) {
653 return -EINVAL; 649 return -EINVAL;
654 } 650 }
655 to_jiffies = ROUND_UP(par_timeout.tv_usec, 1000000/HZ); 651 to_jiffies = DIV_ROUND_UP(par_timeout.tv_usec, 1000000/HZ);
656 to_jiffies += par_timeout.tv_sec * (long) HZ; 652 to_jiffies += par_timeout.tv_sec * (long) HZ;
657 if (to_jiffies <= 0) { 653 if (to_jiffies <= 0) {
658 return -EINVAL; 654 return -EINVAL;
@@ -803,7 +799,7 @@ static int lp_register(int nr, struct parport *port)
803 if (reset) 799 if (reset)
804 lp_reset(nr); 800 lp_reset(nr);
805 801
806 class_device_create(lp_class, NULL, MKDEV(LP_MAJOR, nr), NULL, 802 class_device_create(lp_class, NULL, MKDEV(LP_MAJOR, nr), port->dev,
807 "lp%d", nr); 803 "lp%d", nr);
808 804
809 printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name, 805 printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name,
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 5f066963f171..cc9a9d0df979 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -18,7 +18,6 @@
18#include <linux/raw.h> 18#include <linux/raw.h>
19#include <linux/tty.h> 19#include <linux/tty.h>
20#include <linux/capability.h> 20#include <linux/capability.h>
21#include <linux/smp_lock.h>
22#include <linux/ptrace.h> 21#include <linux/ptrace.h>
23#include <linux/device.h> 22#include <linux/device.h>
24#include <linux/highmem.h> 23#include <linux/highmem.h>
@@ -552,7 +551,7 @@ static ssize_t write_kmem(struct file * file, const char __user * buf,
552 return virtr + wrote; 551 return virtr + wrote;
553} 552}
554 553
555#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__) 554#ifdef CONFIG_DEVPORT
556static ssize_t read_port(struct file * file, char __user * buf, 555static ssize_t read_port(struct file * file, char __user * buf,
557 size_t count, loff_t *ppos) 556 size_t count, loff_t *ppos)
558{ 557{
@@ -835,7 +834,7 @@ static const struct file_operations null_fops = {
835 .splice_write = splice_write_null, 834 .splice_write = splice_write_null,
836}; 835};
837 836
838#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__) 837#ifdef CONFIG_DEVPORT
839static const struct file_operations port_fops = { 838static const struct file_operations port_fops = {
840 .llseek = memory_lseek, 839 .llseek = memory_lseek,
841 .read = read_port, 840 .read = read_port,
@@ -913,7 +912,7 @@ static int memory_open(struct inode * inode, struct file * filp)
913 case 3: 912 case 3:
914 filp->f_op = &null_fops; 913 filp->f_op = &null_fops;
915 break; 914 break;
916#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__) 915#ifdef CONFIG_DEVPORT
917 case 4: 916 case 4:
918 filp->f_op = &port_fops; 917 filp->f_op = &port_fops;
919 break; 918 break;
@@ -960,7 +959,7 @@ static const struct {
960 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops}, 959 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops},
961 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops}, 960 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops},
962 {3, "null", S_IRUGO | S_IWUGO, &null_fops}, 961 {3, "null", S_IRUGO | S_IWUGO, &null_fops},
963#if (defined(CONFIG_ISA) || defined(CONFIG_PCI)) && !defined(__mc68000__) 962#ifdef CONFIG_DEVPORT
964 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops}, 963 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops},
965#endif 964#endif
966 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops}, 965 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops},
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 7e975f606924..4e6fb9651a16 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -41,6 +41,7 @@
41#include <linux/kernel.h> 41#include <linux/kernel.h>
42#include <linux/major.h> 42#include <linux/major.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/mutex.h>
44#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
45#include <linux/seq_file.h> 46#include <linux/seq_file.h>
46#include <linux/stat.h> 47#include <linux/stat.h>
@@ -53,7 +54,7 @@
53 * Head entry for the doubly linked miscdevice list 54 * Head entry for the doubly linked miscdevice list
54 */ 55 */
55static LIST_HEAD(misc_list); 56static LIST_HEAD(misc_list);
56static DECLARE_MUTEX(misc_sem); 57static DEFINE_MUTEX(misc_mtx);
57 58
58/* 59/*
59 * Assigned numbers, used for dynamic minors 60 * Assigned numbers, used for dynamic minors
@@ -69,7 +70,7 @@ static void *misc_seq_start(struct seq_file *seq, loff_t *pos)
69 struct miscdevice *p; 70 struct miscdevice *p;
70 loff_t off = 0; 71 loff_t off = 0;
71 72
72 down(&misc_sem); 73 mutex_lock(&misc_mtx);
73 list_for_each_entry(p, &misc_list, list) { 74 list_for_each_entry(p, &misc_list, list) {
74 if (*pos == off++) 75 if (*pos == off++)
75 return p; 76 return p;
@@ -89,7 +90,7 @@ static void *misc_seq_next(struct seq_file *seq, void *v, loff_t *pos)
89 90
90static void misc_seq_stop(struct seq_file *seq, void *v) 91static void misc_seq_stop(struct seq_file *seq, void *v)
91{ 92{
92 up(&misc_sem); 93 mutex_unlock(&misc_mtx);
93} 94}
94 95
95static int misc_seq_show(struct seq_file *seq, void *v) 96static int misc_seq_show(struct seq_file *seq, void *v)
@@ -129,7 +130,7 @@ static int misc_open(struct inode * inode, struct file * file)
129 int err = -ENODEV; 130 int err = -ENODEV;
130 const struct file_operations *old_fops, *new_fops = NULL; 131 const struct file_operations *old_fops, *new_fops = NULL;
131 132
132 down(&misc_sem); 133 mutex_lock(&misc_mtx);
133 134
134 list_for_each_entry(c, &misc_list, list) { 135 list_for_each_entry(c, &misc_list, list) {
135 if (c->minor == minor) { 136 if (c->minor == minor) {
@@ -139,9 +140,9 @@ static int misc_open(struct inode * inode, struct file * file)
139 } 140 }
140 141
141 if (!new_fops) { 142 if (!new_fops) {
142 up(&misc_sem); 143 mutex_unlock(&misc_mtx);
143 request_module("char-major-%d-%d", MISC_MAJOR, minor); 144 request_module("char-major-%d-%d", MISC_MAJOR, minor);
144 down(&misc_sem); 145 mutex_lock(&misc_mtx);
145 146
146 list_for_each_entry(c, &misc_list, list) { 147 list_for_each_entry(c, &misc_list, list) {
147 if (c->minor == minor) { 148 if (c->minor == minor) {
@@ -165,7 +166,7 @@ static int misc_open(struct inode * inode, struct file * file)
165 } 166 }
166 fops_put(old_fops); 167 fops_put(old_fops);
167fail: 168fail:
168 up(&misc_sem); 169 mutex_unlock(&misc_mtx);
169 return err; 170 return err;
170} 171}
171 172
@@ -201,10 +202,10 @@ int misc_register(struct miscdevice * misc)
201 202
202 INIT_LIST_HEAD(&misc->list); 203 INIT_LIST_HEAD(&misc->list);
203 204
204 down(&misc_sem); 205 mutex_lock(&misc_mtx);
205 list_for_each_entry(c, &misc_list, list) { 206 list_for_each_entry(c, &misc_list, list) {
206 if (c->minor == misc->minor) { 207 if (c->minor == misc->minor) {
207 up(&misc_sem); 208 mutex_unlock(&misc_mtx);
208 return -EBUSY; 209 return -EBUSY;
209 } 210 }
210 } 211 }
@@ -215,7 +216,7 @@ int misc_register(struct miscdevice * misc)
215 if ( (misc_minors[i>>3] & (1 << (i&7))) == 0) 216 if ( (misc_minors[i>>3] & (1 << (i&7))) == 0)
216 break; 217 break;
217 if (i<0) { 218 if (i<0) {
218 up(&misc_sem); 219 mutex_unlock(&misc_mtx);
219 return -EBUSY; 220 return -EBUSY;
220 } 221 }
221 misc->minor = i; 222 misc->minor = i;
@@ -238,7 +239,7 @@ int misc_register(struct miscdevice * misc)
238 */ 239 */
239 list_add(&misc->list, &misc_list); 240 list_add(&misc->list, &misc_list);
240 out: 241 out:
241 up(&misc_sem); 242 mutex_unlock(&misc_mtx);
242 return err; 243 return err;
243} 244}
244 245
@@ -259,13 +260,13 @@ int misc_deregister(struct miscdevice * misc)
259 if (list_empty(&misc->list)) 260 if (list_empty(&misc->list))
260 return -EINVAL; 261 return -EINVAL;
261 262
262 down(&misc_sem); 263 mutex_lock(&misc_mtx);
263 list_del(&misc->list); 264 list_del(&misc->list);
264 device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor)); 265 device_destroy(misc_class, MKDEV(MISC_MAJOR, misc->minor));
265 if (i < DYNAMIC_MINORS && i>0) { 266 if (i < DYNAMIC_MINORS && i>0) {
266 misc_minors[i>>3] &= ~(1 << (misc->minor & 7)); 267 misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
267 } 268 }
268 up(&misc_sem); 269 mutex_unlock(&misc_mtx);
269 return 0; 270 return 0;
270} 271}
271 272
diff --git a/drivers/char/mmtimer.c b/drivers/char/mmtimer.c
index c09160383a53..6e55cfb9c65a 100644
--- a/drivers/char/mmtimer.c
+++ b/drivers/char/mmtimer.c
@@ -705,15 +705,13 @@ static int __init mmtimer_init(void)
705 maxn++; 705 maxn++;
706 706
707 /* Allocate list of node ptrs to mmtimer_t's */ 707 /* Allocate list of node ptrs to mmtimer_t's */
708 timers = kmalloc(sizeof(mmtimer_t *)*maxn, GFP_KERNEL); 708 timers = kzalloc(sizeof(mmtimer_t *)*maxn, GFP_KERNEL);
709 if (timers == NULL) { 709 if (timers == NULL) {
710 printk(KERN_ERR "%s: failed to allocate memory for device\n", 710 printk(KERN_ERR "%s: failed to allocate memory for device\n",
711 MMTIMER_NAME); 711 MMTIMER_NAME);
712 goto out3; 712 goto out3;
713 } 713 }
714 714
715 memset(timers,0,(sizeof(mmtimer_t *)*maxn));
716
717 /* Allocate mmtimer_t's for each online node */ 715 /* Allocate mmtimer_t's for each online node */
718 for_each_online_node(node) { 716 for_each_online_node(node) {
719 timers[node] = kmalloc_node(sizeof(mmtimer_t)*NUM_COMPARATORS, GFP_KERNEL, node); 717 timers[node] = kmalloc_node(sizeof(mmtimer_t)*NUM_COMPARATORS, GFP_KERNEL, node);
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index 7dbaee8d9402..e0d35c20c04f 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -1582,7 +1582,7 @@ copy:
1582 1582
1583 if(copy_from_user(&dltmp, argp, sizeof(struct dl_str))) 1583 if(copy_from_user(&dltmp, argp, sizeof(struct dl_str)))
1584 return -EFAULT; 1584 return -EFAULT;
1585 if(dltmp.cardno < 0 || dltmp.cardno >= MAX_BOARDS) 1585 if(dltmp.cardno < 0 || dltmp.cardno >= MAX_BOARDS || dltmp.len < 0)
1586 return -EINVAL; 1586 return -EINVAL;
1587 1587
1588 switch(cmd) 1588 switch(cmd)
@@ -2529,6 +2529,8 @@ static int moxaloadbios(int cardno, unsigned char __user *tmp, int len)
2529 void __iomem *baseAddr; 2529 void __iomem *baseAddr;
2530 int i; 2530 int i;
2531 2531
2532 if(len < 0 || len > sizeof(moxaBuff))
2533 return -EINVAL;
2532 if(copy_from_user(moxaBuff, tmp, len)) 2534 if(copy_from_user(moxaBuff, tmp, len))
2533 return -EFAULT; 2535 return -EFAULT;
2534 baseAddr = moxa_boards[cardno].basemem; 2536 baseAddr = moxa_boards[cardno].basemem;
@@ -2576,7 +2578,7 @@ static int moxaload320b(int cardno, unsigned char __user *tmp, int len)
2576 void __iomem *baseAddr; 2578 void __iomem *baseAddr;
2577 int i; 2579 int i;
2578 2580
2579 if(len > sizeof(moxaBuff)) 2581 if(len < 0 || len > sizeof(moxaBuff))
2580 return -EINVAL; 2582 return -EINVAL;
2581 if(copy_from_user(moxaBuff, tmp, len)) 2583 if(copy_from_user(moxaBuff, tmp, len))
2582 return -EFAULT; 2584 return -EFAULT;
@@ -2596,6 +2598,8 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2596 void __iomem *baseAddr, *ofsAddr; 2598 void __iomem *baseAddr, *ofsAddr;
2597 int retval, port, i; 2599 int retval, port, i;
2598 2600
2601 if(len < 0 || len > sizeof(moxaBuff))
2602 return -EINVAL;
2599 if(copy_from_user(moxaBuff, tmp, len)) 2603 if(copy_from_user(moxaBuff, tmp, len))
2600 return -EFAULT; 2604 return -EFAULT;
2601 baseAddr = moxa_boards[cardno].basemem; 2605 baseAddr = moxa_boards[cardno].basemem;
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 80a01150b86c..5953a45d7e96 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -54,7 +54,6 @@
54#include <linux/gfp.h> 54#include <linux/gfp.h>
55#include <linux/ioport.h> 55#include <linux/ioport.h>
56#include <linux/mm.h> 56#include <linux/mm.h>
57#include <linux/smp_lock.h>
58#include <linux/delay.h> 57#include <linux/delay.h>
59#include <linux/pci.h> 58#include <linux/pci.h>
60 59
diff --git a/drivers/char/mxser_new.c b/drivers/char/mxser_new.c
index f7603b6aeb87..6cde448cd5b2 100644
--- a/drivers/char/mxser_new.c
+++ b/drivers/char/mxser_new.c
@@ -37,7 +37,6 @@
37#include <linux/gfp.h> 37#include <linux/gfp.h>
38#include <linux/ioport.h> 38#include <linux/ioport.h>
39#include <linux/mm.h> 39#include <linux/mm.h>
40#include <linux/smp_lock.h>
41#include <linux/delay.h> 40#include <linux/delay.h>
42#include <linux/pci.h> 41#include <linux/pci.h>
43 42
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index 65f2d3a96b85..14557a4822c0 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -1088,13 +1088,13 @@ static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1088 /* block until there is a message: */ 1088 /* block until there is a message: */
1089 add_wait_queue(&pInfo->read_wait, &wait); 1089 add_wait_queue(&pInfo->read_wait, &wait);
1090repeat: 1090repeat:
1091 current->state = TASK_INTERRUPTIBLE; 1091 __set_current_state(TASK_INTERRUPTIBLE);
1092 pMsg = remove_msg(pInfo, pClient); 1092 pMsg = remove_msg(pInfo, pClient);
1093 if (!pMsg && !signal_pending(current)) { 1093 if (!pMsg && !signal_pending(current)) {
1094 schedule(); 1094 schedule();
1095 goto repeat; 1095 goto repeat;
1096 } 1096 }
1097 current->state = TASK_RUNNING; 1097 __set_current_state(TASK_RUNNING);
1098 remove_wait_queue(&pInfo->read_wait, &wait); 1098 remove_wait_queue(&pInfo->read_wait, &wait);
1099 } 1099 }
1100 1100
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index 6ac3ca4c723c..b3d4ccc33a47 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -1544,21 +1544,18 @@ static unsigned int normal_poll(struct tty_struct * tty, struct file * file, pol
1544} 1544}
1545 1545
1546struct tty_ldisc tty_ldisc_N_TTY = { 1546struct tty_ldisc tty_ldisc_N_TTY = {
1547 TTY_LDISC_MAGIC, /* magic */ 1547 .magic = TTY_LDISC_MAGIC,
1548 "n_tty", /* name */ 1548 .name = "n_tty",
1549 0, /* num */ 1549 .open = n_tty_open,
1550 0, /* flags */ 1550 .close = n_tty_close,
1551 n_tty_open, /* open */ 1551 .flush_buffer = n_tty_flush_buffer,
1552 n_tty_close, /* close */ 1552 .chars_in_buffer = n_tty_chars_in_buffer,
1553 n_tty_flush_buffer, /* flush_buffer */ 1553 .read = read_chan,
1554 n_tty_chars_in_buffer, /* chars_in_buffer */ 1554 .write = write_chan,
1555 read_chan, /* read */ 1555 .ioctl = n_tty_ioctl,
1556 write_chan, /* write */ 1556 .set_termios = n_tty_set_termios,
1557 n_tty_ioctl, /* ioctl */ 1557 .poll = normal_poll,
1558 n_tty_set_termios, /* set_termios */ 1558 .receive_buf = n_tty_receive_buf,
1559 normal_poll, /* poll */ 1559 .write_wakeup = n_tty_write_wakeup
1560 NULL, /* hangup */
1561 n_tty_receive_buf, /* receive_buf */
1562 n_tty_write_wakeup /* write_wakeup */
1563}; 1560};
1564 1561
diff --git a/drivers/char/pcmcia/Kconfig b/drivers/char/pcmcia/Kconfig
index 27c1179ee527..f25facd97bb4 100644
--- a/drivers/char/pcmcia/Kconfig
+++ b/drivers/char/pcmcia/Kconfig
@@ -21,6 +21,7 @@ config SYNCLINK_CS
21config CARDMAN_4000 21config CARDMAN_4000
22 tristate "Omnikey Cardman 4000 support" 22 tristate "Omnikey Cardman 4000 support"
23 depends on PCMCIA 23 depends on PCMCIA
24 select BITREVERSE
24 help 25 help
25 Enable support for the Omnikey Cardman 4000 PCMCIA Smartcard 26 Enable support for the Omnikey Cardman 4000 PCMCIA Smartcard
26 reader. 27 reader.
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index e91b43a014b0..fee58e03dbe2 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -31,6 +31,7 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/fs.h> 32#include <linux/fs.h>
33#include <linux/delay.h> 33#include <linux/delay.h>
34#include <linux/bitrev.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
35#include <asm/io.h> 36#include <asm/io.h>
36 37
@@ -194,41 +195,17 @@ static inline unsigned char xinb(unsigned short port)
194} 195}
195#endif 196#endif
196 197
197#define b_0000 15 198static inline unsigned char invert_revert(unsigned char ch)
198#define b_0001 14 199{
199#define b_0010 13 200 return bitrev8(~ch);
200#define b_0011 12 201}
201#define b_0100 11
202#define b_0101 10
203#define b_0110 9
204#define b_0111 8
205#define b_1000 7
206#define b_1001 6
207#define b_1010 5
208#define b_1011 4
209#define b_1100 3
210#define b_1101 2
211#define b_1110 1
212#define b_1111 0
213
214static unsigned char irtab[16] = {
215 b_0000, b_1000, b_0100, b_1100,
216 b_0010, b_1010, b_0110, b_1110,
217 b_0001, b_1001, b_0101, b_1101,
218 b_0011, b_1011, b_0111, b_1111
219};
220 202
221static void str_invert_revert(unsigned char *b, int len) 203static void str_invert_revert(unsigned char *b, int len)
222{ 204{
223 int i; 205 int i;
224 206
225 for (i = 0; i < len; i++) 207 for (i = 0; i < len; i++)
226 b[i] = (irtab[b[i] & 0x0f] << 4) | irtab[b[i] >> 4]; 208 b[i] = invert_revert(b[i]);
227}
228
229static unsigned char invert_revert(unsigned char ch)
230{
231 return (irtab[ch & 0x0f] << 4) | irtab[ch >> 4];
232} 209}
233 210
234#define ATRLENCK(dev,pos) \ 211#define ATRLENCK(dev,pos) \
@@ -1114,7 +1091,7 @@ static ssize_t cmm_write(struct file *filp, const char __user *buf,
1114 /* 1091 /*
1115 * wait for atr to become valid. 1092 * wait for atr to become valid.
1116 * note: it is important to lock this code. if we dont, the monitor 1093 * note: it is important to lock this code. if we dont, the monitor
1117 * could be run between test_bit and the the call the sleep on the 1094 * could be run between test_bit and the call to sleep on the
1118 * atr-queue. if *then* the monitor detects atr valid, it will wake up 1095 * atr-queue. if *then* the monitor detects atr valid, it will wake up
1119 * any process on the atr-queue, *but* since we have been interrupted, 1096 * any process on the atr-queue, *but* since we have been interrupted,
1120 * we do not yet sleep on this queue. this would result in a missed 1097 * we do not yet sleep on this queue. this would result in a missed
@@ -1881,8 +1858,11 @@ static int cm4000_probe(struct pcmcia_device *link)
1881 init_waitqueue_head(&dev->readq); 1858 init_waitqueue_head(&dev->readq);
1882 1859
1883 ret = cm4000_config(link, i); 1860 ret = cm4000_config(link, i);
1884 if (ret) 1861 if (ret) {
1862 dev_table[i] = NULL;
1863 kfree(dev);
1885 return ret; 1864 return ret;
1865 }
1886 1866
1887 class_device_create(cmm_class, NULL, MKDEV(major, i), NULL, 1867 class_device_create(cmm_class, NULL, MKDEV(major, i), NULL,
1888 "cmm%d", i); 1868 "cmm%d", i);
@@ -1907,7 +1887,7 @@ static void cm4000_detach(struct pcmcia_device *link)
1907 cm4000_release(link); 1887 cm4000_release(link);
1908 1888
1909 dev_table[devno] = NULL; 1889 dev_table[devno] = NULL;
1910 kfree(dev); 1890 kfree(dev);
1911 1891
1912 class_device_destroy(cmm_class, MKDEV(major, devno)); 1892 class_device_destroy(cmm_class, MKDEV(major, devno));
1913 1893
@@ -1956,12 +1936,14 @@ static int __init cmm_init(void)
1956 if (major < 0) { 1936 if (major < 0) {
1957 printk(KERN_WARNING MODULE_NAME 1937 printk(KERN_WARNING MODULE_NAME
1958 ": could not get major number\n"); 1938 ": could not get major number\n");
1939 class_destroy(cmm_class);
1959 return major; 1940 return major;
1960 } 1941 }
1961 1942
1962 rc = pcmcia_register_driver(&cm4000_driver); 1943 rc = pcmcia_register_driver(&cm4000_driver);
1963 if (rc < 0) { 1944 if (rc < 0) {
1964 unregister_chrdev(major, DEVICE_NAME); 1945 unregister_chrdev(major, DEVICE_NAME);
1946 class_destroy(cmm_class);
1965 return rc; 1947 return rc;
1966 } 1948 }
1967 1949
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index f2e4ec4fd407..af88181a17f4 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -636,8 +636,11 @@ static int reader_probe(struct pcmcia_device *link)
636 setup_timer(&dev->poll_timer, cm4040_do_poll, 0); 636 setup_timer(&dev->poll_timer, cm4040_do_poll, 0);
637 637
638 ret = reader_config(link, i); 638 ret = reader_config(link, i);
639 if (ret) 639 if (ret) {
640 dev_table[i] = NULL;
641 kfree(dev);
640 return ret; 642 return ret;
643 }
641 644
642 class_device_create(cmx_class, NULL, MKDEV(major, i), NULL, 645 class_device_create(cmx_class, NULL, MKDEV(major, i), NULL,
643 "cmx%d", i); 646 "cmx%d", i);
@@ -708,12 +711,14 @@ static int __init cm4040_init(void)
708 if (major < 0) { 711 if (major < 0) {
709 printk(KERN_WARNING MODULE_NAME 712 printk(KERN_WARNING MODULE_NAME
710 ": could not get major number\n"); 713 ": could not get major number\n");
714 class_destroy(cmx_class);
711 return major; 715 return major;
712 } 716 }
713 717
714 rc = pcmcia_register_driver(&reader_driver); 718 rc = pcmcia_register_driver(&reader_driver);
715 if (rc < 0) { 719 if (rc < 0) {
716 unregister_chrdev(major, DEVICE_NAME); 720 unregister_chrdev(major, DEVICE_NAME);
721 class_destroy(cmx_class);
717 return rc; 722 return rc;
718 } 723 }
719 724
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index 4abd1eff61d6..84ac64fc48a1 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -66,7 +66,6 @@
66#include <linux/poll.h> 66#include <linux/poll.h>
67#include <linux/major.h> 67#include <linux/major.h>
68#include <linux/ppdev.h> 68#include <linux/ppdev.h>
69#include <linux/smp_lock.h>
70#include <linux/device.h> 69#include <linux/device.h>
71#include <asm/uaccess.h> 70#include <asm/uaccess.h>
72 71
@@ -752,7 +751,7 @@ static const struct file_operations pp_fops = {
752 751
753static void pp_attach(struct parport *port) 752static void pp_attach(struct parport *port)
754{ 753{
755 device_create(ppdev_class, NULL, MKDEV(PP_MAJOR, port->number), 754 device_create(ppdev_class, port->dev, MKDEV(PP_MAJOR, port->number),
756 "parport%d", port->number); 755 "parport%d", port->number);
757} 756}
758 757
diff --git a/drivers/char/rio/riocmd.c b/drivers/char/rio/riocmd.c
index 245f03195b7c..8cc60b693460 100644
--- a/drivers/char/rio/riocmd.c
+++ b/drivers/char/rio/riocmd.c
@@ -402,7 +402,7 @@ static int RIOCommandRup(struct rio_info *p, uint Rup, struct Host *HostP, struc
402 rio_dprintk(RIO_DEBUG_CMD, "CONTROL information: Host number %Zd, 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);
403 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);
404 404
405 if (Rup >= (unsigned short) MAX_RUP) { 405 if (Rup < (unsigned short) MAX_RUP) {
406 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);
407 } else 407 } else
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); 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);
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index 70145254fb9d..3494e3fc44bf 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -980,7 +980,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
980 } 980 }
981 schedule(); 981 schedule();
982 } 982 }
983 current->state = TASK_RUNNING; 983 __set_current_state(TASK_RUNNING);
984 remove_wait_queue(&port->open_wait, &wait); 984 remove_wait_queue(&port->open_wait, &wait);
985 if (!tty_hung_up_p(filp)) 985 if (!tty_hung_up_p(filp))
986 port->count++; 986 port->count++;
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index 76357c855ce3..a3fd7e7ba5a9 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -65,10 +65,6 @@
65 65
66/****** Kernel includes ******/ 66/****** Kernel includes ******/
67 67
68#ifdef MODVERSIONS
69#include <config/modversions.h>
70#endif
71
72#include <linux/module.h> 68#include <linux/module.h>
73#include <linux/errno.h> 69#include <linux/errno.h>
74#include <linux/major.h> 70#include <linux/major.h>
@@ -85,6 +81,7 @@
85#include <linux/string.h> 81#include <linux/string.h>
86#include <linux/fcntl.h> 82#include <linux/fcntl.h>
87#include <linux/ptrace.h> 83#include <linux/ptrace.h>
84#include <linux/mutex.h>
88#include <linux/ioport.h> 85#include <linux/ioport.h>
89#include <linux/delay.h> 86#include <linux/delay.h>
90#include <linux/wait.h> 87#include <linux/wait.h>
@@ -93,7 +90,6 @@
93#include <asm/atomic.h> 90#include <asm/atomic.h>
94#include <linux/bitops.h> 91#include <linux/bitops.h>
95#include <linux/spinlock.h> 92#include <linux/spinlock.h>
96#include <asm/semaphore.h>
97#include <linux/init.h> 93#include <linux/init.h>
98 94
99/****** RocketPort includes ******/ 95/****** RocketPort includes ******/
@@ -702,7 +698,7 @@ static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
702 } 698 }
703 } 699 }
704 spin_lock_init(&info->slock); 700 spin_lock_init(&info->slock);
705 sema_init(&info->write_sem, 1); 701 mutex_init(&info->write_mtx);
706 rp_table[line] = info; 702 rp_table[line] = info;
707 if (pci_dev) 703 if (pci_dev)
708 tty_register_device(rocket_driver, line, &pci_dev->dev); 704 tty_register_device(rocket_driver, line, &pci_dev->dev);
@@ -947,7 +943,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
947#endif 943#endif
948 schedule(); /* Don't hold spinlock here, will hang PC */ 944 schedule(); /* Don't hold spinlock here, will hang PC */
949 } 945 }
950 current->state = TASK_RUNNING; 946 __set_current_state(TASK_RUNNING);
951 remove_wait_queue(&info->open_wait, &wait); 947 remove_wait_queue(&info->open_wait, &wait);
952 948
953 spin_lock_irqsave(&info->slock, flags); 949 spin_lock_irqsave(&info->slock, flags);
@@ -1018,9 +1014,6 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
1018 /* 1014 /*
1019 * Info->count is now 1; so it's safe to sleep now. 1015 * Info->count is now 1; so it's safe to sleep now.
1020 */ 1016 */
1021 info->session = process_session(current);
1022 info->pgrp = process_group(current);
1023
1024 if ((info->flags & ROCKET_INITIALIZED) == 0) { 1017 if ((info->flags & ROCKET_INITIALIZED) == 0) {
1025 cp = &info->channel; 1018 cp = &info->channel;
1026 sSetRxTrigger(cp, TRIG_1); 1019 sSetRxTrigger(cp, TRIG_1);
@@ -1602,7 +1595,7 @@ static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
1602 if (signal_pending(current)) 1595 if (signal_pending(current))
1603 break; 1596 break;
1604 } 1597 }
1605 current->state = TASK_RUNNING; 1598 __set_current_state(TASK_RUNNING);
1606#ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT 1599#ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
1607 printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies); 1600 printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies);
1608#endif 1601#endif
@@ -1661,8 +1654,11 @@ static void rp_put_char(struct tty_struct *tty, unsigned char ch)
1661 if (rocket_paranoia_check(info, "rp_put_char")) 1654 if (rocket_paranoia_check(info, "rp_put_char"))
1662 return; 1655 return;
1663 1656
1664 /* Grab the port write semaphore, locking out other processes that try to write to this port */ 1657 /*
1665 down(&info->write_sem); 1658 * Grab the port write mutex, locking out other processes that try to
1659 * write to this port
1660 */
1661 mutex_lock(&info->write_mtx);
1666 1662
1667#ifdef ROCKET_DEBUG_WRITE 1663#ifdef ROCKET_DEBUG_WRITE
1668 printk(KERN_INFO "rp_put_char %c...", ch); 1664 printk(KERN_INFO "rp_put_char %c...", ch);
@@ -1684,12 +1680,12 @@ static void rp_put_char(struct tty_struct *tty, unsigned char ch)
1684 info->xmit_fifo_room--; 1680 info->xmit_fifo_room--;
1685 } 1681 }
1686 spin_unlock_irqrestore(&info->slock, flags); 1682 spin_unlock_irqrestore(&info->slock, flags);
1687 up(&info->write_sem); 1683 mutex_unlock(&info->write_mtx);
1688} 1684}
1689 1685
1690/* 1686/*
1691 * Exception handler - write routine, called when user app writes to the device. 1687 * Exception handler - write routine, called when user app writes to the device.
1692 * A per port write semaphore is used to protect from another process writing to 1688 * A per port write mutex is used to protect from another process writing to
1693 * this port at the same time. This other process could be running on the other CPU 1689 * this port at the same time. This other process could be running on the other CPU
1694 * or get control of the CPU if the copy_from_user() blocks due to a page fault (swapped out). 1690 * or get control of the CPU if the copy_from_user() blocks due to a page fault (swapped out).
1695 * Spinlocks protect the info xmit members. 1691 * Spinlocks protect the info xmit members.
@@ -1706,7 +1702,7 @@ static int rp_write(struct tty_struct *tty,
1706 if (count <= 0 || rocket_paranoia_check(info, "rp_write")) 1702 if (count <= 0 || rocket_paranoia_check(info, "rp_write"))
1707 return 0; 1703 return 0;
1708 1704
1709 down_interruptible(&info->write_sem); 1705 mutex_lock_interruptible(&info->write_mtx);
1710 1706
1711#ifdef ROCKET_DEBUG_WRITE 1707#ifdef ROCKET_DEBUG_WRITE
1712 printk(KERN_INFO "rp_write %d chars...", count); 1708 printk(KERN_INFO "rp_write %d chars...", count);
@@ -1777,7 +1773,7 @@ end:
1777 wake_up_interruptible(&tty->poll_wait); 1773 wake_up_interruptible(&tty->poll_wait);
1778#endif 1774#endif
1779 } 1775 }
1780 up(&info->write_sem); 1776 mutex_unlock(&info->write_mtx);
1781 return retval; 1777 return retval;
1782} 1778}
1783 1779
@@ -1852,6 +1848,12 @@ static void rp_flush_buffer(struct tty_struct *tty)
1852 1848
1853#ifdef CONFIG_PCI 1849#ifdef CONFIG_PCI
1854 1850
1851static struct pci_device_id __devinitdata rocket_pci_ids[] = {
1852 { PCI_DEVICE(PCI_VENDOR_ID_RP, PCI_ANY_ID) },
1853 { }
1854};
1855MODULE_DEVICE_TABLE(pci, rocket_pci_ids);
1856
1855/* 1857/*
1856 * Called when a PCI card is found. Retrieves and stores model information, 1858 * Called when a PCI card is found. Retrieves and stores model information,
1857 * init's aiopic and serial port hardware. 1859 * init's aiopic and serial port hardware.
diff --git a/drivers/char/rocket_int.h b/drivers/char/rocket_int.h
index 3a8bcc85bc14..b4c53dfa7951 100644
--- a/drivers/char/rocket_int.h
+++ b/drivers/char/rocket_int.h
@@ -15,6 +15,8 @@
15#define ROCKET_TYPE_MODEMIII 3 15#define ROCKET_TYPE_MODEMIII 3
16#define ROCKET_TYPE_PC104 4 16#define ROCKET_TYPE_PC104 4
17 17
18#include <linux/mutex.h>
19
18#include <asm/io.h> 20#include <asm/io.h>
19#include <asm/byteorder.h> 21#include <asm/byteorder.h>
20 22
@@ -1156,8 +1158,6 @@ struct r_port {
1156 int xmit_head; 1158 int xmit_head;
1157 int xmit_tail; 1159 int xmit_tail;
1158 int xmit_cnt; 1160 int xmit_cnt;
1159 int session;
1160 int pgrp;
1161 int cd_status; 1161 int cd_status;
1162 int ignore_status_mask; 1162 int ignore_status_mask;
1163 int read_status_mask; 1163 int read_status_mask;
@@ -1171,7 +1171,7 @@ struct r_port {
1171 struct wait_queue *close_wait; 1171 struct wait_queue *close_wait;
1172#endif 1172#endif
1173 spinlock_t slock; 1173 spinlock_t slock;
1174 struct semaphore write_sem; 1174 struct mutex write_mtx;
1175}; 1175};
1176 1176
1177#define RPORT_MAGIC 0x525001 1177#define RPORT_MAGIC 0x525001
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index c7dac9b13351..20380a2c4dee 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -388,7 +388,7 @@ static ssize_t rtc_read(struct file *file, char __user *buf,
388 if (!retval) 388 if (!retval)
389 retval = count; 389 retval = count;
390 out: 390 out:
391 current->state = TASK_RUNNING; 391 __set_current_state(TASK_RUNNING);
392 remove_wait_queue(&rtc_wait, &wait); 392 remove_wait_queue(&rtc_wait, &wait);
393 393
394 return retval; 394 return retval;
diff --git a/drivers/char/selection.c b/drivers/char/selection.c
index 74cff839c857..a69f094d1ed3 100644
--- a/drivers/char/selection.c
+++ b/drivers/char/selection.c
@@ -299,7 +299,7 @@ int paste_selection(struct tty_struct *tty)
299 pasted += count; 299 pasted += count;
300 } 300 }
301 remove_wait_queue(&vc->paste_wait, &wait); 301 remove_wait_queue(&vc->paste_wait, &wait);
302 current->state = TASK_RUNNING; 302 __set_current_state(TASK_RUNNING);
303 303
304 tty_ldisc_deref(ld); 304 tty_ldisc_deref(ld);
305 return 0; 305 return 0;
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index 5fd314adc1f2..c585b4738f86 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -1892,7 +1892,7 @@ block_til_ready(struct tty_struct *tty, struct file *filp,
1892#endif 1892#endif
1893 schedule(); 1893 schedule();
1894 } 1894 }
1895 current->state = TASK_RUNNING; 1895 __set_current_state(TASK_RUNNING);
1896 remove_wait_queue(&info->open_wait, &wait); 1896 remove_wait_queue(&info->open_wait, &wait);
1897 if (!tty_hung_up_p(filp)) { 1897 if (!tty_hung_up_p(filp)) {
1898 info->count++; 1898 info->count++;
diff --git a/drivers/char/snsc_event.c b/drivers/char/snsc_event.c
index 2f56e8c54897..1b75b0b7d542 100644
--- a/drivers/char/snsc_event.c
+++ b/drivers/char/snsc_event.c
@@ -203,8 +203,6 @@ scdrv_dispatch_event(char *event, int len)
203 class = (code & EV_CLASS_MASK); 203 class = (code & EV_CLASS_MASK);
204 204
205 if (class == EV_CLASS_PWRD_NOTIFY || code == ENV_PWRDN_PEND) { 205 if (class == EV_CLASS_PWRD_NOTIFY || code == ENV_PWRDN_PEND) {
206 struct task_struct *p;
207
208 if (snsc_shutting_down) 206 if (snsc_shutting_down)
209 return; 207 return;
210 208
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index ce4db6f52362..f02a0795983f 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -4010,8 +4010,13 @@ static int mgsl_alloc_intermediate_txbuffer_memory(struct mgsl_struct *info)
4010 for ( i=0; i<info->num_tx_holding_buffers; ++i) { 4010 for ( i=0; i<info->num_tx_holding_buffers; ++i) {
4011 info->tx_holding_buffers[i].buffer = 4011 info->tx_holding_buffers[i].buffer =
4012 kmalloc(info->max_frame_size, GFP_KERNEL); 4012 kmalloc(info->max_frame_size, GFP_KERNEL);
4013 if ( info->tx_holding_buffers[i].buffer == NULL ) 4013 if (info->tx_holding_buffers[i].buffer == NULL) {
4014 for (--i; i >= 0; i--) {
4015 kfree(info->tx_holding_buffers[i].buffer);
4016 info->tx_holding_buffers[i].buffer = NULL;
4017 }
4014 return -ENOMEM; 4018 return -ENOMEM;
4019 }
4015 } 4020 }
4016 4021
4017 return 0; 4022 return 0;
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 0a367cd4121f..02b49bc00028 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -1171,6 +1171,112 @@ static int ioctl(struct tty_struct *tty, struct file *file,
1171} 1171}
1172 1172
1173/* 1173/*
1174 * support for 32 bit ioctl calls on 64 bit systems
1175 */
1176#ifdef CONFIG_COMPAT
1177static long get_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *user_params)
1178{
1179 struct MGSL_PARAMS32 tmp_params;
1180
1181 DBGINFO(("%s get_params32\n", info->device_name));
1182 tmp_params.mode = (compat_ulong_t)info->params.mode;
1183 tmp_params.loopback = info->params.loopback;
1184 tmp_params.flags = info->params.flags;
1185 tmp_params.encoding = info->params.encoding;
1186 tmp_params.clock_speed = (compat_ulong_t)info->params.clock_speed;
1187 tmp_params.addr_filter = info->params.addr_filter;
1188 tmp_params.crc_type = info->params.crc_type;
1189 tmp_params.preamble_length = info->params.preamble_length;
1190 tmp_params.preamble = info->params.preamble;
1191 tmp_params.data_rate = (compat_ulong_t)info->params.data_rate;
1192 tmp_params.data_bits = info->params.data_bits;
1193 tmp_params.stop_bits = info->params.stop_bits;
1194 tmp_params.parity = info->params.parity;
1195 if (copy_to_user(user_params, &tmp_params, sizeof(struct MGSL_PARAMS32)))
1196 return -EFAULT;
1197 return 0;
1198}
1199
1200static long set_params32(struct slgt_info *info, struct MGSL_PARAMS32 __user *new_params)
1201{
1202 struct MGSL_PARAMS32 tmp_params;
1203
1204 DBGINFO(("%s set_params32\n", info->device_name));
1205 if (copy_from_user(&tmp_params, new_params, sizeof(struct MGSL_PARAMS32)))
1206 return -EFAULT;
1207
1208 spin_lock(&info->lock);
1209 info->params.mode = tmp_params.mode;
1210 info->params.loopback = tmp_params.loopback;
1211 info->params.flags = tmp_params.flags;
1212 info->params.encoding = tmp_params.encoding;
1213 info->params.clock_speed = tmp_params.clock_speed;
1214 info->params.addr_filter = tmp_params.addr_filter;
1215 info->params.crc_type = tmp_params.crc_type;
1216 info->params.preamble_length = tmp_params.preamble_length;
1217 info->params.preamble = tmp_params.preamble;
1218 info->params.data_rate = tmp_params.data_rate;
1219 info->params.data_bits = tmp_params.data_bits;
1220 info->params.stop_bits = tmp_params.stop_bits;
1221 info->params.parity = tmp_params.parity;
1222 spin_unlock(&info->lock);
1223
1224 change_params(info);
1225
1226 return 0;
1227}
1228
1229static long slgt_compat_ioctl(struct tty_struct *tty, struct file *file,
1230 unsigned int cmd, unsigned long arg)
1231{
1232 struct slgt_info *info = tty->driver_data;
1233 int rc = -ENOIOCTLCMD;
1234
1235 if (sanity_check(info, tty->name, "compat_ioctl"))
1236 return -ENODEV;
1237 DBGINFO(("%s compat_ioctl() cmd=%08X\n", info->device_name, cmd));
1238
1239 switch (cmd) {
1240
1241 case MGSL_IOCSPARAMS32:
1242 rc = set_params32(info, compat_ptr(arg));
1243 break;
1244
1245 case MGSL_IOCGPARAMS32:
1246 rc = get_params32(info, compat_ptr(arg));
1247 break;
1248
1249 case MGSL_IOCGPARAMS:
1250 case MGSL_IOCSPARAMS:
1251 case MGSL_IOCGTXIDLE:
1252 case MGSL_IOCGSTATS:
1253 case MGSL_IOCWAITEVENT:
1254 case MGSL_IOCGIF:
1255 case MGSL_IOCSGPIO:
1256 case MGSL_IOCGGPIO:
1257 case MGSL_IOCWAITGPIO:
1258 case TIOCGICOUNT:
1259 rc = ioctl(tty, file, cmd, (unsigned long)(compat_ptr(arg)));
1260 break;
1261
1262 case MGSL_IOCSTXIDLE:
1263 case MGSL_IOCTXENABLE:
1264 case MGSL_IOCRXENABLE:
1265 case MGSL_IOCTXABORT:
1266 case TIOCMIWAIT:
1267 case MGSL_IOCSIF:
1268 rc = ioctl(tty, file, cmd, arg);
1269 break;
1270 }
1271
1272 DBGINFO(("%s compat_ioctl() cmd=%08X rc=%d\n", info->device_name, cmd, rc));
1273 return rc;
1274}
1275#else
1276#define slgt_compat_ioctl NULL
1277#endif /* ifdef CONFIG_COMPAT */
1278
1279/*
1174 * proc fs support 1280 * proc fs support
1175 */ 1281 */
1176static inline int line_info(char *buf, struct slgt_info *info) 1282static inline int line_info(char *buf, struct slgt_info *info)
@@ -3415,6 +3521,9 @@ static void device_init(int adapter_num, struct pci_dev *pdev)
3415 } 3521 }
3416 } 3522 }
3417 } 3523 }
3524
3525 for (i=0; i < port_count; ++i)
3526 tty_register_device(serial_driver, port_array[i]->line, &(port_array[i]->pdev->dev));
3418} 3527}
3419 3528
3420static int __devinit init_one(struct pci_dev *dev, 3529static int __devinit init_one(struct pci_dev *dev,
@@ -3443,6 +3552,7 @@ static const struct tty_operations ops = {
3443 .chars_in_buffer = chars_in_buffer, 3552 .chars_in_buffer = chars_in_buffer,
3444 .flush_buffer = flush_buffer, 3553 .flush_buffer = flush_buffer,
3445 .ioctl = ioctl, 3554 .ioctl = ioctl,
3555 .compat_ioctl = slgt_compat_ioctl,
3446 .throttle = throttle, 3556 .throttle = throttle,
3447 .unthrottle = unthrottle, 3557 .unthrottle = unthrottle,
3448 .send_xchar = send_xchar, 3558 .send_xchar = send_xchar,
@@ -3466,6 +3576,8 @@ static void slgt_cleanup(void)
3466 printk("unload %s %s\n", driver_name, driver_version); 3576 printk("unload %s %s\n", driver_name, driver_version);
3467 3577
3468 if (serial_driver) { 3578 if (serial_driver) {
3579 for (info=slgt_device_list ; info != NULL ; info=info->next_device)
3580 tty_unregister_device(serial_driver, info->line);
3469 if ((rc = tty_unregister_driver(serial_driver))) 3581 if ((rc = tty_unregister_driver(serial_driver)))
3470 DBGERR(("tty_unregister_driver error=%d\n", rc)); 3582 DBGERR(("tty_unregister_driver error=%d\n", rc));
3471 put_tty_driver(serial_driver); 3583 put_tty_driver(serial_driver);
@@ -3506,23 +3618,10 @@ static int __init slgt_init(void)
3506 3618
3507 printk("%s %s\n", driver_name, driver_version); 3619 printk("%s %s\n", driver_name, driver_version);
3508 3620
3509 slgt_device_count = 0;
3510 if ((rc = pci_register_driver(&pci_driver)) < 0) {
3511 printk("%s pci_register_driver error=%d\n", driver_name, rc);
3512 return rc;
3513 }
3514 pci_registered = 1;
3515
3516 if (!slgt_device_list) {
3517 printk("%s no devices found\n",driver_name);
3518 pci_unregister_driver(&pci_driver);
3519 return -ENODEV;
3520 }
3521
3522 serial_driver = alloc_tty_driver(MAX_DEVICES); 3621 serial_driver = alloc_tty_driver(MAX_DEVICES);
3523 if (!serial_driver) { 3622 if (!serial_driver) {
3524 rc = -ENOMEM; 3623 printk("%s can't allocate tty driver\n", driver_name);
3525 goto error; 3624 return -ENOMEM;
3526 } 3625 }
3527 3626
3528 /* Initialize the tty_driver structure */ 3627 /* Initialize the tty_driver structure */
@@ -3539,7 +3638,7 @@ static int __init slgt_init(void)
3539 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 3638 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
3540 serial_driver->init_termios.c_ispeed = 9600; 3639 serial_driver->init_termios.c_ispeed = 9600;
3541 serial_driver->init_termios.c_ospeed = 9600; 3640 serial_driver->init_termios.c_ospeed = 9600;
3542 serial_driver->flags = TTY_DRIVER_REAL_RAW; 3641 serial_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
3543 tty_set_operations(serial_driver, &ops); 3642 tty_set_operations(serial_driver, &ops);
3544 if ((rc = tty_register_driver(serial_driver)) < 0) { 3643 if ((rc = tty_register_driver(serial_driver)) < 0) {
3545 DBGERR(("%s can't register serial driver\n", driver_name)); 3644 DBGERR(("%s can't register serial driver\n", driver_name));
@@ -3552,6 +3651,16 @@ static int __init slgt_init(void)
3552 driver_name, driver_version, 3651 driver_name, driver_version,
3553 serial_driver->major); 3652 serial_driver->major);
3554 3653
3654 slgt_device_count = 0;
3655 if ((rc = pci_register_driver(&pci_driver)) < 0) {
3656 printk("%s pci_register_driver error=%d\n", driver_name, rc);
3657 goto error;
3658 }
3659 pci_registered = 1;
3660
3661 if (!slgt_device_list)
3662 printk("%s no devices found\n",driver_name);
3663
3555 return 0; 3664 return 0;
3556 3665
3557error: 3666error:
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index 1d8c4ae61551..39cc318011ea 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -24,7 +24,6 @@
24#include <linux/sysrq.h> 24#include <linux/sysrq.h>
25#include <linux/kbd_kern.h> 25#include <linux/kbd_kern.h>
26#include <linux/quotaops.h> 26#include <linux/quotaops.h>
27#include <linux/smp_lock.h>
28#include <linux/kernel.h> 27#include <linux/kernel.h>
29#include <linux/module.h> 28#include <linux/module.h>
30#include <linux/suspend.h> 29#include <linux/suspend.h>
diff --git a/drivers/char/tipar.c b/drivers/char/tipar.c
index 47fb20f69695..35b40b996534 100644
--- a/drivers/char/tipar.c
+++ b/drivers/char/tipar.c
@@ -442,7 +442,7 @@ tipar_register(int nr, struct parport *port)
442 } 442 }
443 443
444 class_device_create(tipar_class, NULL, MKDEV(TIPAR_MAJOR, 444 class_device_create(tipar_class, NULL, MKDEV(TIPAR_MAJOR,
445 TIPAR_MINOR + nr), NULL, "par%d", nr); 445 TIPAR_MINOR + nr), port->dev, "par%d", nr);
446 446
447 /* Display informations */ 447 /* Display informations */
448 pr_info("tipar%d: using %s (%s)\n", nr, port->name, (port->irq == 448 pr_info("tipar%d: using %s (%s)\n", nr, port->name, (port->irq ==
diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index fe00c7dfb649..dc4e1ff7f56f 100644
--- a/drivers/char/tpm/Kconfig
+++ b/drivers/char/tpm/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "TPM devices" 5menu "TPM devices"
6 depends on HAS_IOMEM
6 7
7config TCG_TPM 8config TCG_TPM
8 tristate "TPM Hardware Support" 9 tristate "TPM Hardware Support"
@@ -33,7 +34,7 @@ config TCG_NSC
33 tristate "National Semiconductor TPM Interface" 34 tristate "National Semiconductor TPM Interface"
34 depends on TCG_TPM && PNPACPI 35 depends on TCG_TPM && PNPACPI
35 ---help--- 36 ---help---
36 If you have a TPM security chip from National Semicondutor 37 If you have a TPM security chip from National Semiconductor
37 say Yes and it will be accessible from within Linux. To 38 say Yes and it will be accessible from within Linux. To
38 compile this driver as a module, choose M here; the module 39 compile this driver as a module, choose M here; the module
39 will be called tpm_nsc. 40 will be called tpm_nsc.
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index e5a254a434f8..9bb542913b86 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -24,7 +24,9 @@
24 */ 24 */
25 25
26#include <linux/poll.h> 26#include <linux/poll.h>
27#include <linux/mutex.h>
27#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29
28#include "tpm.h" 30#include "tpm.h"
29 31
30enum tpm_const { 32enum tpm_const {
@@ -328,10 +330,10 @@ static void timeout_work(struct work_struct *work)
328{ 330{
329 struct tpm_chip *chip = container_of(work, struct tpm_chip, work); 331 struct tpm_chip *chip = container_of(work, struct tpm_chip, work);
330 332
331 down(&chip->buffer_mutex); 333 mutex_lock(&chip->buffer_mutex);
332 atomic_set(&chip->data_pending, 0); 334 atomic_set(&chip->data_pending, 0);
333 memset(chip->data_buffer, 0, TPM_BUFSIZE); 335 memset(chip->data_buffer, 0, TPM_BUFSIZE);
334 up(&chip->buffer_mutex); 336 mutex_unlock(&chip->buffer_mutex);
335} 337}
336 338
337/* 339/*
@@ -380,7 +382,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
380 return -E2BIG; 382 return -E2BIG;
381 } 383 }
382 384
383 down(&chip->tpm_mutex); 385 mutex_lock(&chip->tpm_mutex);
384 386
385 if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) { 387 if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) {
386 dev_err(chip->dev, 388 dev_err(chip->dev,
@@ -419,7 +421,7 @@ out_recv:
419 dev_err(chip->dev, 421 dev_err(chip->dev,
420 "tpm_transmit: tpm_recv: error %zd\n", rc); 422 "tpm_transmit: tpm_recv: error %zd\n", rc);
421out: 423out:
422 up(&chip->tpm_mutex); 424 mutex_unlock(&chip->tpm_mutex);
423 return rc; 425 return rc;
424} 426}
425 427
@@ -942,12 +944,12 @@ int tpm_release(struct inode *inode, struct file *file)
942{ 944{
943 struct tpm_chip *chip = file->private_data; 945 struct tpm_chip *chip = file->private_data;
944 946
947 flush_scheduled_work();
945 spin_lock(&driver_lock); 948 spin_lock(&driver_lock);
946 file->private_data = NULL; 949 file->private_data = NULL;
947 chip->num_opens--;
948 del_singleshot_timer_sync(&chip->user_read_timer); 950 del_singleshot_timer_sync(&chip->user_read_timer);
949 flush_scheduled_work();
950 atomic_set(&chip->data_pending, 0); 951 atomic_set(&chip->data_pending, 0);
952 chip->num_opens--;
951 put_device(chip->dev); 953 put_device(chip->dev);
952 kfree(chip->data_buffer); 954 kfree(chip->data_buffer);
953 spin_unlock(&driver_lock); 955 spin_unlock(&driver_lock);
@@ -966,14 +968,14 @@ ssize_t tpm_write(struct file *file, const char __user *buf,
966 while (atomic_read(&chip->data_pending) != 0) 968 while (atomic_read(&chip->data_pending) != 0)
967 msleep(TPM_TIMEOUT); 969 msleep(TPM_TIMEOUT);
968 970
969 down(&chip->buffer_mutex); 971 mutex_lock(&chip->buffer_mutex);
970 972
971 if (in_size > TPM_BUFSIZE) 973 if (in_size > TPM_BUFSIZE)
972 in_size = TPM_BUFSIZE; 974 in_size = TPM_BUFSIZE;
973 975
974 if (copy_from_user 976 if (copy_from_user
975 (chip->data_buffer, (void __user *) buf, in_size)) { 977 (chip->data_buffer, (void __user *) buf, in_size)) {
976 up(&chip->buffer_mutex); 978 mutex_unlock(&chip->buffer_mutex);
977 return -EFAULT; 979 return -EFAULT;
978 } 980 }
979 981
@@ -981,7 +983,7 @@ ssize_t tpm_write(struct file *file, const char __user *buf,
981 out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE); 983 out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE);
982 984
983 atomic_set(&chip->data_pending, out_size); 985 atomic_set(&chip->data_pending, out_size);
984 up(&chip->buffer_mutex); 986 mutex_unlock(&chip->buffer_mutex);
985 987
986 /* Set a timeout by which the reader must come claim the result */ 988 /* Set a timeout by which the reader must come claim the result */
987 mod_timer(&chip->user_read_timer, jiffies + (60 * HZ)); 989 mod_timer(&chip->user_read_timer, jiffies + (60 * HZ));
@@ -1004,10 +1006,10 @@ ssize_t tpm_read(struct file *file, char __user *buf,
1004 if (size < ret_size) 1006 if (size < ret_size)
1005 ret_size = size; 1007 ret_size = size;
1006 1008
1007 down(&chip->buffer_mutex); 1009 mutex_lock(&chip->buffer_mutex);
1008 if (copy_to_user(buf, chip->data_buffer, ret_size)) 1010 if (copy_to_user(buf, chip->data_buffer, ret_size))
1009 ret_size = -EFAULT; 1011 ret_size = -EFAULT;
1010 up(&chip->buffer_mutex); 1012 mutex_unlock(&chip->buffer_mutex);
1011 } 1013 }
1012 1014
1013 return ret_size; 1015 return ret_size;
@@ -1097,11 +1099,16 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1097 1099
1098 /* Driver specific per-device data */ 1100 /* Driver specific per-device data */
1099 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1101 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1100 if (chip == NULL) 1102 devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
1103
1104 if (chip == NULL || devname == NULL) {
1105 kfree(chip);
1106 kfree(devname);
1101 return NULL; 1107 return NULL;
1108 }
1102 1109
1103 init_MUTEX(&chip->buffer_mutex); 1110 mutex_init(&chip->buffer_mutex);
1104 init_MUTEX(&chip->tpm_mutex); 1111 mutex_init(&chip->tpm_mutex);
1105 INIT_LIST_HEAD(&chip->list); 1112 INIT_LIST_HEAD(&chip->list);
1106 1113
1107 INIT_WORK(&chip->work, timeout_work); 1114 INIT_WORK(&chip->work, timeout_work);
@@ -1124,7 +1131,6 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1124 1131
1125 set_bit(chip->dev_num, dev_mask); 1132 set_bit(chip->dev_num, dev_mask);
1126 1133
1127 devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
1128 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); 1134 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
1129 chip->vendor.miscdev.name = devname; 1135 chip->vendor.miscdev.name = devname;
1130 1136
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 9f273f032b0f..b2e2b002a1bb 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -21,6 +21,7 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/fs.h> 23#include <linux/fs.h>
24#include <linux/mutex.h>
24#include <linux/sched.h> 25#include <linux/sched.h>
25#include <linux/miscdevice.h> 26#include <linux/miscdevice.h>
26#include <linux/platform_device.h> 27#include <linux/platform_device.h>
@@ -94,11 +95,11 @@ struct tpm_chip {
94 /* Data passed to and from the tpm via the read/write calls */ 95 /* Data passed to and from the tpm via the read/write calls */
95 u8 *data_buffer; 96 u8 *data_buffer;
96 atomic_t data_pending; 97 atomic_t data_pending;
97 struct semaphore buffer_mutex; 98 struct mutex buffer_mutex;
98 99
99 struct timer_list user_read_timer; /* user needs to claim result */ 100 struct timer_list user_read_timer; /* user needs to claim result */
100 struct work_struct work; 101 struct work_struct work;
101 struct semaphore tpm_mutex; /* tpm is processing */ 102 struct mutex tpm_mutex; /* tpm is processing */
102 103
103 struct tpm_vendor_specific vendor; 104 struct tpm_vendor_specific vendor;
104 105
diff --git a/drivers/char/tpm/tpm_atmel.h b/drivers/char/tpm/tpm_atmel.h
index 3c852009196e..9363bcf0a402 100644
--- a/drivers/char/tpm/tpm_atmel.h
+++ b/drivers/char/tpm/tpm_atmel.h
@@ -23,6 +23,9 @@
23 */ 23 */
24 24
25#ifdef CONFIG_PPC64 25#ifdef CONFIG_PPC64
26
27#include <asm/prom.h>
28
26#define atmel_getb(chip, offset) readb(chip->vendor->iobase + offset); 29#define atmel_getb(chip, offset) readb(chip->vendor->iobase + offset);
27#define atmel_putb(val, chip, offset) writeb(val, chip->vendor->iobase + offset) 30#define atmel_putb(val, chip, offset) writeb(val, chip->vendor->iobase + offset)
28#define atmel_request_region request_mem_region 31#define atmel_request_region request_mem_region
@@ -47,12 +50,12 @@ static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
47 if (!dn) 50 if (!dn)
48 return NULL; 51 return NULL;
49 52
50 if (!device_is_compatible(dn, "AT97SC3201")) { 53 if (!of_device_is_compatible(dn, "AT97SC3201")) {
51 of_node_put(dn); 54 of_node_put(dn);
52 return NULL; 55 return NULL;
53 } 56 }
54 57
55 reg = get_property(dn, "reg", &reglen); 58 reg = of_get_property(dn, "reg", &reglen);
56 naddrc = of_n_addr_cells(dn); 59 naddrc = of_n_addr_cells(dn);
57 nsizec = of_n_size_cells(dn); 60 nsizec = of_n_size_cells(dn);
58 61
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
index 1353b5a6bae8..967002a5a1e5 100644
--- a/drivers/char/tpm/tpm_infineon.c
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -30,12 +30,60 @@
30#define TPM_MAX_TRIES 5000 30#define TPM_MAX_TRIES 5000
31#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1 31#define TPM_INFINEON_DEV_VEN_VALUE 0x15D1
32 32
33/* These values will be filled after PnP-call */ 33#define TPM_INF_IO_PORT 0x0
34static int TPM_INF_DATA; 34#define TPM_INF_IO_MEM 0x1
35static int TPM_INF_ADDR; 35
36static int TPM_INF_BASE; 36#define TPM_INF_ADDR 0x0
37static int TPM_INF_ADDR_LEN; 37#define TPM_INF_DATA 0x1
38static int TPM_INF_PORT_LEN; 38
39struct tpm_inf_dev {
40 int iotype;
41
42 void __iomem *mem_base; /* MMIO ioremap'd addr */
43 unsigned long map_base; /* phys MMIO base */
44 unsigned long map_size; /* MMIO region size */
45 unsigned int index_off; /* index register offset */
46
47 unsigned int data_regs; /* Data registers */
48 unsigned int data_size;
49
50 unsigned int config_port; /* IO Port config index reg */
51 unsigned int config_size;
52};
53
54static struct tpm_inf_dev tpm_dev;
55
56static inline void tpm_data_out(unsigned char data, unsigned char offset)
57{
58 if (tpm_dev.iotype == TPM_INF_IO_PORT)
59 outb(data, tpm_dev.data_regs + offset);
60 else
61 writeb(data, tpm_dev.mem_base + tpm_dev.data_regs + offset);
62}
63
64static inline unsigned char tpm_data_in(unsigned char offset)
65{
66 if (tpm_dev.iotype == TPM_INF_IO_PORT)
67 return inb(tpm_dev.data_regs + offset);
68 else
69 return readb(tpm_dev.mem_base + tpm_dev.data_regs + offset);
70}
71
72static inline void tpm_config_out(unsigned char data, unsigned char offset)
73{
74 if (tpm_dev.iotype == TPM_INF_IO_PORT)
75 outb(data, tpm_dev.config_port + offset);
76 else
77 writeb(data, tpm_dev.mem_base + tpm_dev.index_off + offset);
78}
79
80static inline unsigned char tpm_config_in(unsigned char offset)
81{
82 if (tpm_dev.iotype == TPM_INF_IO_PORT)
83 return inb(tpm_dev.config_port + offset);
84 else
85 return readb(tpm_dev.mem_base + tpm_dev.index_off + offset);
86}
39 87
40/* TPM header definitions */ 88/* TPM header definitions */
41enum infineon_tpm_header { 89enum infineon_tpm_header {
@@ -105,7 +153,7 @@ static int empty_fifo(struct tpm_chip *chip, int clear_wrfifo)
105 153
106 if (clear_wrfifo) { 154 if (clear_wrfifo) {
107 for (i = 0; i < 4096; i++) { 155 for (i = 0; i < 4096; i++) {
108 status = inb(chip->vendor.base + WRFIFO); 156 status = tpm_data_in(WRFIFO);
109 if (status == 0xff) { 157 if (status == 0xff) {
110 if (check == 5) 158 if (check == 5)
111 break; 159 break;
@@ -125,8 +173,8 @@ static int empty_fifo(struct tpm_chip *chip, int clear_wrfifo)
125 */ 173 */
126 i = 0; 174 i = 0;
127 do { 175 do {
128 status = inb(chip->vendor.base + RDFIFO); 176 status = tpm_data_in(RDFIFO);
129 status = inb(chip->vendor.base + STAT); 177 status = tpm_data_in(STAT);
130 i++; 178 i++;
131 if (i == TPM_MAX_TRIES) 179 if (i == TPM_MAX_TRIES)
132 return -EIO; 180 return -EIO;
@@ -139,7 +187,7 @@ static int wait(struct tpm_chip *chip, int wait_for_bit)
139 int status; 187 int status;
140 int i; 188 int i;
141 for (i = 0; i < TPM_MAX_TRIES; i++) { 189 for (i = 0; i < TPM_MAX_TRIES; i++) {
142 status = inb(chip->vendor.base + STAT); 190 status = tpm_data_in(STAT);
143 /* check the status-register if wait_for_bit is set */ 191 /* check the status-register if wait_for_bit is set */
144 if (status & 1 << wait_for_bit) 192 if (status & 1 << wait_for_bit)
145 break; 193 break;
@@ -158,7 +206,7 @@ static int wait(struct tpm_chip *chip, int wait_for_bit)
158static void wait_and_send(struct tpm_chip *chip, u8 sendbyte) 206static void wait_and_send(struct tpm_chip *chip, u8 sendbyte)
159{ 207{
160 wait(chip, STAT_XFE); 208 wait(chip, STAT_XFE);
161 outb(sendbyte, chip->vendor.base + WRFIFO); 209 tpm_data_out(sendbyte, WRFIFO);
162} 210}
163 211
164 /* Note: WTX means Waiting-Time-Extension. Whenever the TPM needs more 212 /* Note: WTX means Waiting-Time-Extension. Whenever the TPM needs more
@@ -205,7 +253,7 @@ recv_begin:
205 ret = wait(chip, STAT_RDA); 253 ret = wait(chip, STAT_RDA);
206 if (ret) 254 if (ret)
207 return -EIO; 255 return -EIO;
208 buf[i] = inb(chip->vendor.base + RDFIFO); 256 buf[i] = tpm_data_in(RDFIFO);
209 } 257 }
210 258
211 if (buf[0] != TPM_VL_VER) { 259 if (buf[0] != TPM_VL_VER) {
@@ -220,7 +268,7 @@ recv_begin:
220 268
221 for (i = 0; i < size; i++) { 269 for (i = 0; i < size; i++) {
222 wait(chip, STAT_RDA); 270 wait(chip, STAT_RDA);
223 buf[i] = inb(chip->vendor.base + RDFIFO); 271 buf[i] = tpm_data_in(RDFIFO);
224 } 272 }
225 273
226 if ((size == 0x6D00) && (buf[1] == 0x80)) { 274 if ((size == 0x6D00) && (buf[1] == 0x80)) {
@@ -269,7 +317,7 @@ static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count)
269 u8 count_high, count_low, count_4, count_3, count_2, count_1; 317 u8 count_high, count_low, count_4, count_3, count_2, count_1;
270 318
271 /* Disabling Reset, LP and IRQC */ 319 /* Disabling Reset, LP and IRQC */
272 outb(RESET_LP_IRQC_DISABLE, chip->vendor.base + CMD); 320 tpm_data_out(RESET_LP_IRQC_DISABLE, CMD);
273 321
274 ret = empty_fifo(chip, 1); 322 ret = empty_fifo(chip, 1);
275 if (ret) { 323 if (ret) {
@@ -320,7 +368,7 @@ static void tpm_inf_cancel(struct tpm_chip *chip)
320 368
321static u8 tpm_inf_status(struct tpm_chip *chip) 369static u8 tpm_inf_status(struct tpm_chip *chip)
322{ 370{
323 return inb(chip->vendor.base + STAT); 371 return tpm_data_in(STAT);
324} 372}
325 373
326static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 374static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
@@ -381,51 +429,88 @@ static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
381 /* read IO-ports through PnP */ 429 /* read IO-ports through PnP */
382 if (pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) && 430 if (pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) &&
383 !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) { 431 !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) {
384 TPM_INF_ADDR = pnp_port_start(dev, 0); 432
385 TPM_INF_ADDR_LEN = pnp_port_len(dev, 0); 433 tpm_dev.iotype = TPM_INF_IO_PORT;
386 TPM_INF_DATA = (TPM_INF_ADDR + 1); 434
387 TPM_INF_BASE = pnp_port_start(dev, 1); 435 tpm_dev.config_port = pnp_port_start(dev, 0);
388 TPM_INF_PORT_LEN = pnp_port_len(dev, 1); 436 tpm_dev.config_size = pnp_port_len(dev, 0);
389 if ((TPM_INF_PORT_LEN < 4) || (TPM_INF_ADDR_LEN < 2)) { 437 tpm_dev.data_regs = pnp_port_start(dev, 1);
438 tpm_dev.data_size = pnp_port_len(dev, 1);
439 if ((tpm_dev.data_size < 4) || (tpm_dev.config_size < 2)) {
390 rc = -EINVAL; 440 rc = -EINVAL;
391 goto err_last; 441 goto err_last;
392 } 442 }
393 dev_info(&dev->dev, "Found %s with ID %s\n", 443 dev_info(&dev->dev, "Found %s with ID %s\n",
394 dev->name, dev_id->id); 444 dev->name, dev_id->id);
395 if (!((TPM_INF_BASE >> 8) & 0xff)) { 445 if (!((tpm_dev.data_regs >> 8) & 0xff)) {
396 rc = -EINVAL; 446 rc = -EINVAL;
397 goto err_last; 447 goto err_last;
398 } 448 }
399 /* publish my base address and request region */ 449 /* publish my base address and request region */
400 if (request_region 450 if (request_region(tpm_dev.data_regs, tpm_dev.data_size,
401 (TPM_INF_BASE, TPM_INF_PORT_LEN, "tpm_infineon0") == NULL) { 451 "tpm_infineon0") == NULL) {
402 rc = -EINVAL; 452 rc = -EINVAL;
403 goto err_last; 453 goto err_last;
404 } 454 }
405 if (request_region 455 if (request_region(tpm_dev.config_port, tpm_dev.config_size,
406 (TPM_INF_ADDR, TPM_INF_ADDR_LEN, "tpm_infineon0") == NULL) { 456 "tpm_infineon0") == NULL) {
457 release_region(tpm_dev.data_regs, tpm_dev.data_size);
407 rc = -EINVAL; 458 rc = -EINVAL;
408 goto err_last; 459 goto err_last;
409 } 460 }
461 } else if (pnp_mem_valid(dev, 0) &&
462 !(pnp_mem_flags(dev, 0) & IORESOURCE_DISABLED)) {
463
464 tpm_dev.iotype = TPM_INF_IO_MEM;
465
466 tpm_dev.map_base = pnp_mem_start(dev, 0);
467 tpm_dev.map_size = pnp_mem_len(dev, 0);
468
469 dev_info(&dev->dev, "Found %s with ID %s\n",
470 dev->name, dev_id->id);
471
472 /* publish my base address and request region */
473 if (request_mem_region(tpm_dev.map_base, tpm_dev.map_size,
474 "tpm_infineon0") == NULL) {
475 rc = -EINVAL;
476 goto err_last;
477 }
478
479 tpm_dev.mem_base = ioremap(tpm_dev.map_base, tpm_dev.map_size);
480 if (tpm_dev.mem_base == NULL) {
481 release_mem_region(tpm_dev.map_base, tpm_dev.map_size);
482 rc = -EINVAL;
483 goto err_last;
484 }
485
486 /*
487 * The only known MMIO based Infineon TPM system provides
488 * a single large mem region with the device config
489 * registers at the default TPM_ADDR. The data registers
490 * seem like they could be placed anywhere within the MMIO
491 * region, but lets just put them at zero offset.
492 */
493 tpm_dev.index_off = TPM_ADDR;
494 tpm_dev.data_regs = 0x0;
410 } else { 495 } else {
411 rc = -EINVAL; 496 rc = -EINVAL;
412 goto err_last; 497 goto err_last;
413 } 498 }
414 499
415 /* query chip for its vendor, its version number a.s.o. */ 500 /* query chip for its vendor, its version number a.s.o. */
416 outb(ENABLE_REGISTER_PAIR, TPM_INF_ADDR); 501 tpm_config_out(ENABLE_REGISTER_PAIR, TPM_INF_ADDR);
417 outb(IDVENL, TPM_INF_ADDR); 502 tpm_config_out(IDVENL, TPM_INF_ADDR);
418 vendorid[1] = inb(TPM_INF_DATA); 503 vendorid[1] = tpm_config_in(TPM_INF_DATA);
419 outb(IDVENH, TPM_INF_ADDR); 504 tpm_config_out(IDVENH, TPM_INF_ADDR);
420 vendorid[0] = inb(TPM_INF_DATA); 505 vendorid[0] = tpm_config_in(TPM_INF_DATA);
421 outb(IDPDL, TPM_INF_ADDR); 506 tpm_config_out(IDPDL, TPM_INF_ADDR);
422 productid[1] = inb(TPM_INF_DATA); 507 productid[1] = tpm_config_in(TPM_INF_DATA);
423 outb(IDPDH, TPM_INF_ADDR); 508 tpm_config_out(IDPDH, TPM_INF_ADDR);
424 productid[0] = inb(TPM_INF_DATA); 509 productid[0] = tpm_config_in(TPM_INF_DATA);
425 outb(CHIP_ID1, TPM_INF_ADDR); 510 tpm_config_out(CHIP_ID1, TPM_INF_ADDR);
426 version[1] = inb(TPM_INF_DATA); 511 version[1] = tpm_config_in(TPM_INF_DATA);
427 outb(CHIP_ID2, TPM_INF_ADDR); 512 tpm_config_out(CHIP_ID2, TPM_INF_ADDR);
428 version[0] = inb(TPM_INF_DATA); 513 version[0] = tpm_config_in(TPM_INF_DATA);
429 514
430 switch ((productid[0] << 8) | productid[1]) { 515 switch ((productid[0] << 8) | productid[1]) {
431 case 6: 516 case 6:
@@ -442,51 +527,54 @@ static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
442 if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) { 527 if ((vendorid[0] << 8 | vendorid[1]) == (TPM_INFINEON_DEV_VEN_VALUE)) {
443 528
444 /* configure TPM with IO-ports */ 529 /* configure TPM with IO-ports */
445 outb(IOLIMH, TPM_INF_ADDR); 530 tpm_config_out(IOLIMH, TPM_INF_ADDR);
446 outb(((TPM_INF_BASE >> 8) & 0xff), TPM_INF_DATA); 531 tpm_config_out((tpm_dev.data_regs >> 8) & 0xff, TPM_INF_DATA);
447 outb(IOLIML, TPM_INF_ADDR); 532 tpm_config_out(IOLIML, TPM_INF_ADDR);
448 outb((TPM_INF_BASE & 0xff), TPM_INF_DATA); 533 tpm_config_out((tpm_dev.data_regs & 0xff), TPM_INF_DATA);
449 534
450 /* control if IO-ports are set correctly */ 535 /* control if IO-ports are set correctly */
451 outb(IOLIMH, TPM_INF_ADDR); 536 tpm_config_out(IOLIMH, TPM_INF_ADDR);
452 ioh = inb(TPM_INF_DATA); 537 ioh = tpm_config_in(TPM_INF_DATA);
453 outb(IOLIML, TPM_INF_ADDR); 538 tpm_config_out(IOLIML, TPM_INF_ADDR);
454 iol = inb(TPM_INF_DATA); 539 iol = tpm_config_in(TPM_INF_DATA);
455 540
456 if ((ioh << 8 | iol) != TPM_INF_BASE) { 541 if ((ioh << 8 | iol) != tpm_dev.data_regs) {
457 dev_err(&dev->dev, 542 dev_err(&dev->dev,
458 "Could not set IO-ports to 0x%x\n", 543 "Could not set IO-data registers to 0x%x\n",
459 TPM_INF_BASE); 544 tpm_dev.data_regs);
460 rc = -EIO; 545 rc = -EIO;
461 goto err_release_region; 546 goto err_release_region;
462 } 547 }
463 548
464 /* activate register */ 549 /* activate register */
465 outb(TPM_DAR, TPM_INF_ADDR); 550 tpm_config_out(TPM_DAR, TPM_INF_ADDR);
466 outb(0x01, TPM_INF_DATA); 551 tpm_config_out(0x01, TPM_INF_DATA);
467 outb(DISABLE_REGISTER_PAIR, TPM_INF_ADDR); 552 tpm_config_out(DISABLE_REGISTER_PAIR, TPM_INF_ADDR);
468 553
469 /* disable RESET, LP and IRQC */ 554 /* disable RESET, LP and IRQC */
470 outb(RESET_LP_IRQC_DISABLE, TPM_INF_BASE + CMD); 555 tpm_data_out(RESET_LP_IRQC_DISABLE, CMD);
471 556
472 /* Finally, we're done, print some infos */ 557 /* Finally, we're done, print some infos */
473 dev_info(&dev->dev, "TPM found: " 558 dev_info(&dev->dev, "TPM found: "
474 "config base 0x%x, " 559 "config base 0x%lx, "
475 "io base 0x%x, " 560 "data base 0x%lx, "
476 "chip version 0x%02x%02x, " 561 "chip version 0x%02x%02x, "
477 "vendor id 0x%x%x (Infineon), " 562 "vendor id 0x%x%x (Infineon), "
478 "product id 0x%02x%02x" 563 "product id 0x%02x%02x"
479 "%s\n", 564 "%s\n",
480 TPM_INF_ADDR, 565 tpm_dev.iotype == TPM_INF_IO_PORT ?
481 TPM_INF_BASE, 566 tpm_dev.config_port :
567 tpm_dev.map_base + tpm_dev.index_off,
568 tpm_dev.iotype == TPM_INF_IO_PORT ?
569 tpm_dev.data_regs :
570 tpm_dev.map_base + tpm_dev.data_regs,
482 version[0], version[1], 571 version[0], version[1],
483 vendorid[0], vendorid[1], 572 vendorid[0], vendorid[1],
484 productid[0], productid[1], chipname); 573 productid[0], productid[1], chipname);
485 574
486 if (!(chip = tpm_register_hardware(&dev->dev, &tpm_inf))) { 575 if (!(chip = tpm_register_hardware(&dev->dev, &tpm_inf)))
487 goto err_release_region; 576 goto err_release_region;
488 } 577
489 chip->vendor.base = TPM_INF_BASE;
490 return 0; 578 return 0;
491 } else { 579 } else {
492 rc = -ENODEV; 580 rc = -ENODEV;
@@ -494,8 +582,13 @@ static int __devinit tpm_inf_pnp_probe(struct pnp_dev *dev,
494 } 582 }
495 583
496err_release_region: 584err_release_region:
497 release_region(TPM_INF_BASE, TPM_INF_PORT_LEN); 585 if (tpm_dev.iotype == TPM_INF_IO_PORT) {
498 release_region(TPM_INF_ADDR, TPM_INF_ADDR_LEN); 586 release_region(tpm_dev.data_regs, tpm_dev.data_size);
587 release_region(tpm_dev.config_port, tpm_dev.config_size);
588 } else {
589 iounmap(tpm_dev.mem_base);
590 release_mem_region(tpm_dev.map_base, tpm_dev.map_size);
591 }
499 592
500err_last: 593err_last:
501 return rc; 594 return rc;
@@ -506,8 +599,14 @@ static __devexit void tpm_inf_pnp_remove(struct pnp_dev *dev)
506 struct tpm_chip *chip = pnp_get_drvdata(dev); 599 struct tpm_chip *chip = pnp_get_drvdata(dev);
507 600
508 if (chip) { 601 if (chip) {
509 release_region(TPM_INF_BASE, TPM_INF_PORT_LEN); 602 if (tpm_dev.iotype == TPM_INF_IO_PORT) {
510 release_region(TPM_INF_ADDR, TPM_INF_ADDR_LEN); 603 release_region(tpm_dev.data_regs, tpm_dev.data_size);
604 release_region(tpm_dev.config_port,
605 tpm_dev.config_size);
606 } else {
607 iounmap(tpm_dev.mem_base);
608 release_mem_region(tpm_dev.map_base, tpm_dev.map_size);
609 }
511 tpm_remove_hardware(chip->dev); 610 tpm_remove_hardware(chip->dev);
512 } 611 }
513} 612}
@@ -539,5 +638,5 @@ module_exit(cleanup_inf);
539 638
540MODULE_AUTHOR("Marcel Selhorst <selhorst@crypto.rub.de>"); 639MODULE_AUTHOR("Marcel Selhorst <selhorst@crypto.rub.de>");
541MODULE_DESCRIPTION("Driver for Infineon TPM SLD 9630 TT 1.1 / SLB 9635 TT 1.2"); 640MODULE_DESCRIPTION("Driver for Infineon TPM SLD 9630 TT 1.1 / SLB 9635 TT 1.2");
542MODULE_VERSION("1.8"); 641MODULE_VERSION("1.9");
543MODULE_LICENSE("GPL"); 642MODULE_LICENSE("GPL");
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 389da364e6b6..75d2a46e106f 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -141,8 +141,6 @@ static DECLARE_MUTEX(allocated_ptys_lock);
141static int ptmx_open(struct inode *, struct file *); 141static int ptmx_open(struct inode *, struct file *);
142#endif 142#endif
143 143
144extern void disable_early_printk(void);
145
146static void initialize_tty_struct(struct tty_struct *tty); 144static void initialize_tty_struct(struct tty_struct *tty);
147 145
148static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *); 146static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
@@ -153,10 +151,16 @@ static int tty_open(struct inode *, struct file *);
153static int tty_release(struct inode *, struct file *); 151static int tty_release(struct inode *, struct file *);
154int tty_ioctl(struct inode * inode, struct file * file, 152int tty_ioctl(struct inode * inode, struct file * file,
155 unsigned int cmd, unsigned long arg); 153 unsigned int cmd, unsigned long arg);
154#ifdef CONFIG_COMPAT
155static long tty_compat_ioctl(struct file * file, unsigned int cmd,
156 unsigned long arg);
157#else
158#define tty_compat_ioctl NULL
159#endif
156static int tty_fasync(int fd, struct file * filp, int on); 160static int tty_fasync(int fd, struct file * filp, int on);
157static void release_tty(struct tty_struct *tty, int idx); 161static void release_tty(struct tty_struct *tty, int idx);
158static struct pid *__proc_set_tty(struct task_struct *tsk, 162static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
159 struct tty_struct *tty); 163static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
160 164
161/** 165/**
162 * alloc_tty_struct - allocate a tty object 166 * alloc_tty_struct - allocate a tty object
@@ -365,6 +369,29 @@ static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
365} 369}
366 370
367/** 371/**
372 * tty_buffer_flush - flush full tty buffers
373 * @tty: tty to flush
374 *
375 * flush all the buffers containing receive data
376 *
377 * Locking: none
378 */
379
380static void tty_buffer_flush(struct tty_struct *tty)
381{
382 struct tty_buffer *thead;
383 unsigned long flags;
384
385 spin_lock_irqsave(&tty->buf.lock, flags);
386 while((thead = tty->buf.head) != NULL) {
387 tty->buf.head = thead->next;
388 tty_buffer_free(tty, thead);
389 }
390 tty->buf.tail = NULL;
391 spin_unlock_irqrestore(&tty->buf.lock, flags);
392}
393
394/**
368 * tty_buffer_find - find a free tty buffer 395 * tty_buffer_find - find a free tty buffer
369 * @tty: tty owning the buffer 396 * @tty: tty owning the buffer
370 * @size: characters wanted 397 * @size: characters wanted
@@ -936,13 +963,6 @@ restart:
936 return -EINVAL; 963 return -EINVAL;
937 964
938 /* 965 /*
939 * No more input please, we are switching. The new ldisc
940 * will update this value in the ldisc open function
941 */
942
943 tty->receive_room = 0;
944
945 /*
946 * Problem: What do we do if this blocks ? 966 * Problem: What do we do if this blocks ?
947 */ 967 */
948 968
@@ -953,6 +973,13 @@ restart:
953 return 0; 973 return 0;
954 } 974 }
955 975
976 /*
977 * No more input please, we are switching. The new ldisc
978 * will update this value in the ldisc open function
979 */
980
981 tty->receive_room = 0;
982
956 o_ldisc = tty->ldisc; 983 o_ldisc = tty->ldisc;
957 o_tty = tty->link; 984 o_tty = tty->link;
958 985
@@ -1145,8 +1172,8 @@ static unsigned int hung_up_tty_poll(struct file * filp, poll_table * wait)
1145 return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM; 1172 return POLLIN | POLLOUT | POLLERR | POLLHUP | POLLRDNORM | POLLWRNORM;
1146} 1173}
1147 1174
1148static int hung_up_tty_ioctl(struct inode * inode, struct file * file, 1175static long hung_up_tty_ioctl(struct file * file,
1149 unsigned int cmd, unsigned long arg) 1176 unsigned int cmd, unsigned long arg)
1150{ 1177{
1151 return cmd == TIOCSPGRP ? -ENOTTY : -EIO; 1178 return cmd == TIOCSPGRP ? -ENOTTY : -EIO;
1152} 1179}
@@ -1157,6 +1184,7 @@ static const struct file_operations tty_fops = {
1157 .write = tty_write, 1184 .write = tty_write,
1158 .poll = tty_poll, 1185 .poll = tty_poll,
1159 .ioctl = tty_ioctl, 1186 .ioctl = tty_ioctl,
1187 .compat_ioctl = tty_compat_ioctl,
1160 .open = tty_open, 1188 .open = tty_open,
1161 .release = tty_release, 1189 .release = tty_release,
1162 .fasync = tty_fasync, 1190 .fasync = tty_fasync,
@@ -1169,6 +1197,7 @@ static const struct file_operations ptmx_fops = {
1169 .write = tty_write, 1197 .write = tty_write,
1170 .poll = tty_poll, 1198 .poll = tty_poll,
1171 .ioctl = tty_ioctl, 1199 .ioctl = tty_ioctl,
1200 .compat_ioctl = tty_compat_ioctl,
1172 .open = ptmx_open, 1201 .open = ptmx_open,
1173 .release = tty_release, 1202 .release = tty_release,
1174 .fasync = tty_fasync, 1203 .fasync = tty_fasync,
@@ -1181,6 +1210,7 @@ static const struct file_operations console_fops = {
1181 .write = redirected_tty_write, 1210 .write = redirected_tty_write,
1182 .poll = tty_poll, 1211 .poll = tty_poll,
1183 .ioctl = tty_ioctl, 1212 .ioctl = tty_ioctl,
1213 .compat_ioctl = tty_compat_ioctl,
1184 .open = tty_open, 1214 .open = tty_open,
1185 .release = tty_release, 1215 .release = tty_release,
1186 .fasync = tty_fasync, 1216 .fasync = tty_fasync,
@@ -1191,7 +1221,8 @@ static const struct file_operations hung_up_tty_fops = {
1191 .read = hung_up_tty_read, 1221 .read = hung_up_tty_read,
1192 .write = hung_up_tty_write, 1222 .write = hung_up_tty_write,
1193 .poll = hung_up_tty_poll, 1223 .poll = hung_up_tty_poll,
1194 .ioctl = hung_up_tty_ioctl, 1224 .unlocked_ioctl = hung_up_tty_ioctl,
1225 .compat_ioctl = hung_up_tty_ioctl,
1195 .release = tty_release, 1226 .release = tty_release,
1196}; 1227};
1197 1228
@@ -1240,6 +1271,7 @@ void tty_ldisc_flush(struct tty_struct *tty)
1240 ld->flush_buffer(tty); 1271 ld->flush_buffer(tty);
1241 tty_ldisc_deref(ld); 1272 tty_ldisc_deref(ld);
1242 } 1273 }
1274 tty_buffer_flush(tty);
1243} 1275}
1244 1276
1245EXPORT_SYMBOL_GPL(tty_ldisc_flush); 1277EXPORT_SYMBOL_GPL(tty_ldisc_flush);
@@ -1534,10 +1566,9 @@ void disassociate_ctty(int on_exit)
1534 } 1566 }
1535 1567
1536 spin_lock_irq(&current->sighand->siglock); 1568 spin_lock_irq(&current->sighand->siglock);
1537 tty_pgrp = current->signal->tty_old_pgrp; 1569 put_pid(current->signal->tty_old_pgrp);
1538 current->signal->tty_old_pgrp = NULL; 1570 current->signal->tty_old_pgrp = NULL;
1539 spin_unlock_irq(&current->sighand->siglock); 1571 spin_unlock_irq(&current->sighand->siglock);
1540 put_pid(tty_pgrp);
1541 1572
1542 mutex_lock(&tty_mutex); 1573 mutex_lock(&tty_mutex);
1543 /* It is possible that do_tty_hangup has free'd this tty */ 1574 /* It is possible that do_tty_hangup has free'd this tty */
@@ -1562,13 +1593,25 @@ void disassociate_ctty(int on_exit)
1562 unlock_kernel(); 1593 unlock_kernel();
1563} 1594}
1564 1595
1596/**
1597 *
1598 * no_tty - Ensure the current process does not have a controlling tty
1599 */
1600void no_tty(void)
1601{
1602 struct task_struct *tsk = current;
1603 if (tsk->signal->leader)
1604 disassociate_ctty(0);
1605 proc_clear_tty(tsk);
1606}
1607
1565 1608
1566/** 1609/**
1567 * stop_tty - propogate flow control 1610 * stop_tty - propagate flow control
1568 * @tty: tty to stop 1611 * @tty: tty to stop
1569 * 1612 *
1570 * Perform flow control to the driver. For PTY/TTY pairs we 1613 * Perform flow control to the driver. For PTY/TTY pairs we
1571 * must also propogate the TIOCKPKT status. May be called 1614 * must also propagate the TIOCKPKT status. May be called
1572 * on an already stopped device and will not re-call the driver 1615 * on an already stopped device and will not re-call the driver
1573 * method. 1616 * method.
1574 * 1617 *
@@ -1598,11 +1641,11 @@ void stop_tty(struct tty_struct *tty)
1598EXPORT_SYMBOL(stop_tty); 1641EXPORT_SYMBOL(stop_tty);
1599 1642
1600/** 1643/**
1601 * start_tty - propogate flow control 1644 * start_tty - propagate flow control
1602 * @tty: tty to start 1645 * @tty: tty to start
1603 * 1646 *
1604 * Start a tty that has been stopped if at all possible. Perform 1647 * Start a tty that has been stopped if at all possible. Perform
1605 * any neccessary wakeups and propogate the TIOCPKT status. If this 1648 * any neccessary wakeups and propagate the TIOCPKT status. If this
1606 * is the tty was previous stopped and is being started then the 1649 * is the tty was previous stopped and is being started then the
1607 * driver start method is invoked and the line discipline woken. 1650 * driver start method is invoked and the line discipline woken.
1608 * 1651 *
@@ -2508,7 +2551,6 @@ static int tty_open(struct inode * inode, struct file * filp)
2508 int index; 2551 int index;
2509 dev_t device = inode->i_rdev; 2552 dev_t device = inode->i_rdev;
2510 unsigned short saved_flags = filp->f_flags; 2553 unsigned short saved_flags = filp->f_flags;
2511 struct pid *old_pgrp;
2512 2554
2513 nonseekable_open(inode, filp); 2555 nonseekable_open(inode, filp);
2514 2556
@@ -2602,17 +2644,15 @@ got_driver:
2602 goto retry_open; 2644 goto retry_open;
2603 } 2645 }
2604 2646
2605 old_pgrp = NULL;
2606 mutex_lock(&tty_mutex); 2647 mutex_lock(&tty_mutex);
2607 spin_lock_irq(&current->sighand->siglock); 2648 spin_lock_irq(&current->sighand->siglock);
2608 if (!noctty && 2649 if (!noctty &&
2609 current->signal->leader && 2650 current->signal->leader &&
2610 !current->signal->tty && 2651 !current->signal->tty &&
2611 tty->session == NULL) 2652 tty->session == NULL)
2612 old_pgrp = __proc_set_tty(current, tty); 2653 __proc_set_tty(current, tty);
2613 spin_unlock_irq(&current->sighand->siglock); 2654 spin_unlock_irq(&current->sighand->siglock);
2614 mutex_unlock(&tty_mutex); 2655 mutex_unlock(&tty_mutex);
2615 put_pid(old_pgrp);
2616 return 0; 2656 return 0;
2617} 2657}
2618 2658
@@ -3287,9 +3327,7 @@ int tty_ioctl(struct inode * inode, struct file * file,
3287 case TIOCNOTTY: 3327 case TIOCNOTTY:
3288 if (current->signal->tty != tty) 3328 if (current->signal->tty != tty)
3289 return -ENOTTY; 3329 return -ENOTTY;
3290 if (current->signal->leader) 3330 no_tty();
3291 disassociate_ctty(0);
3292 proc_clear_tty(current);
3293 return 0; 3331 return 0;
3294 case TIOCSCTTY: 3332 case TIOCSCTTY:
3295 return tiocsctty(tty, arg); 3333 return tiocsctty(tty, arg);
@@ -3336,6 +3374,15 @@ int tty_ioctl(struct inode * inode, struct file * file,
3336 case TIOCMBIC: 3374 case TIOCMBIC:
3337 case TIOCMBIS: 3375 case TIOCMBIS:
3338 return tty_tiocmset(tty, file, cmd, p); 3376 return tty_tiocmset(tty, file, cmd, p);
3377 case TCFLSH:
3378 switch (arg) {
3379 case TCIFLUSH:
3380 case TCIOFLUSH:
3381 /* flush tty buffer and allow ldisc to process ioctl */
3382 tty_buffer_flush(tty);
3383 break;
3384 }
3385 break;
3339 } 3386 }
3340 if (tty->driver->ioctl) { 3387 if (tty->driver->ioctl) {
3341 retval = (tty->driver->ioctl)(tty, file, cmd, arg); 3388 retval = (tty->driver->ioctl)(tty, file, cmd, arg);
@@ -3353,6 +3400,32 @@ int tty_ioctl(struct inode * inode, struct file * file,
3353 return retval; 3400 return retval;
3354} 3401}
3355 3402
3403#ifdef CONFIG_COMPAT
3404static long tty_compat_ioctl(struct file * file, unsigned int cmd,
3405 unsigned long arg)
3406{
3407 struct inode *inode = file->f_dentry->d_inode;
3408 struct tty_struct *tty = file->private_data;
3409 struct tty_ldisc *ld;
3410 int retval = -ENOIOCTLCMD;
3411
3412 if (tty_paranoia_check(tty, inode, "tty_ioctl"))
3413 return -EINVAL;
3414
3415 if (tty->driver->compat_ioctl) {
3416 retval = (tty->driver->compat_ioctl)(tty, file, cmd, arg);
3417 if (retval != -ENOIOCTLCMD)
3418 return retval;
3419 }
3420
3421 ld = tty_ldisc_ref_wait(tty);
3422 if (ld->compat_ioctl)
3423 retval = ld->compat_ioctl(tty, file, cmd, arg);
3424 tty_ldisc_deref(ld);
3425
3426 return retval;
3427}
3428#endif
3356 3429
3357/* 3430/*
3358 * This implements the "Secure Attention Key" --- the idea is to 3431 * This implements the "Secure Attention Key" --- the idea is to
@@ -3685,6 +3758,7 @@ void tty_set_operations(struct tty_driver *driver,
3685 driver->write_room = op->write_room; 3758 driver->write_room = op->write_room;
3686 driver->chars_in_buffer = op->chars_in_buffer; 3759 driver->chars_in_buffer = op->chars_in_buffer;
3687 driver->ioctl = op->ioctl; 3760 driver->ioctl = op->ioctl;
3761 driver->compat_ioctl = op->compat_ioctl;
3688 driver->set_termios = op->set_termios; 3762 driver->set_termios = op->set_termios;
3689 driver->throttle = op->throttle; 3763 driver->throttle = op->throttle;
3690 driver->unthrottle = op->unthrottle; 3764 driver->unthrottle = op->unthrottle;
@@ -3766,7 +3840,9 @@ int tty_register_driver(struct tty_driver *driver)
3766 if (!driver->put_char) 3840 if (!driver->put_char)
3767 driver->put_char = tty_default_put_char; 3841 driver->put_char = tty_default_put_char;
3768 3842
3843 mutex_lock(&tty_mutex);
3769 list_add(&driver->tty_drivers, &tty_drivers); 3844 list_add(&driver->tty_drivers, &tty_drivers);
3845 mutex_unlock(&tty_mutex);
3770 3846
3771 if ( !(driver->flags & TTY_DRIVER_DYNAMIC_DEV) ) { 3847 if ( !(driver->flags & TTY_DRIVER_DYNAMIC_DEV) ) {
3772 for(i = 0; i < driver->num; i++) 3848 for(i = 0; i < driver->num; i++)
@@ -3792,8 +3868,9 @@ int tty_unregister_driver(struct tty_driver *driver)
3792 3868
3793 unregister_chrdev_region(MKDEV(driver->major, driver->minor_start), 3869 unregister_chrdev_region(MKDEV(driver->major, driver->minor_start),
3794 driver->num); 3870 driver->num);
3795 3871 mutex_lock(&tty_mutex);
3796 list_del(&driver->tty_drivers); 3872 list_del(&driver->tty_drivers);
3873 mutex_unlock(&tty_mutex);
3797 3874
3798 /* 3875 /*
3799 * Free the termios and termios_locked structures because 3876 * Free the termios and termios_locked structures because
@@ -3838,9 +3915,8 @@ void proc_clear_tty(struct task_struct *p)
3838} 3915}
3839EXPORT_SYMBOL(proc_clear_tty); 3916EXPORT_SYMBOL(proc_clear_tty);
3840 3917
3841static struct pid *__proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 3918static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3842{ 3919{
3843 struct pid *old_pgrp;
3844 if (tty) { 3920 if (tty) {
3845 /* We should not have a session or pgrp to here but.... */ 3921 /* We should not have a session or pgrp to here but.... */
3846 put_pid(tty->session); 3922 put_pid(tty->session);
@@ -3848,21 +3924,16 @@ static struct pid *__proc_set_tty(struct task_struct *tsk, struct tty_struct *tt
3848 tty->session = get_pid(task_session(tsk)); 3924 tty->session = get_pid(task_session(tsk));
3849 tty->pgrp = get_pid(task_pgrp(tsk)); 3925 tty->pgrp = get_pid(task_pgrp(tsk));
3850 } 3926 }
3851 old_pgrp = tsk->signal->tty_old_pgrp; 3927 put_pid(tsk->signal->tty_old_pgrp);
3852 tsk->signal->tty = tty; 3928 tsk->signal->tty = tty;
3853 tsk->signal->tty_old_pgrp = NULL; 3929 tsk->signal->tty_old_pgrp = NULL;
3854 return old_pgrp;
3855} 3930}
3856 3931
3857void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 3932static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3858{ 3933{
3859 struct pid *old_pgrp;
3860
3861 spin_lock_irq(&tsk->sighand->siglock); 3934 spin_lock_irq(&tsk->sighand->siglock);
3862 old_pgrp = __proc_set_tty(tsk, tty); 3935 __proc_set_tty(tsk, tty);
3863 spin_unlock_irq(&tsk->sighand->siglock); 3936 spin_unlock_irq(&tsk->sighand->siglock);
3864
3865 put_pid(old_pgrp);
3866} 3937}
3867 3938
3868struct tty_struct *get_current_tty(void) 3939struct tty_struct *get_current_tty(void)
@@ -3897,9 +3968,6 @@ void __init console_init(void)
3897 * set up the console device so that later boot sequences can 3968 * set up the console device so that later boot sequences can
3898 * inform about problems etc.. 3969 * inform about problems etc..
3899 */ 3970 */
3900#ifdef CONFIG_EARLY_PRINTK
3901 disable_early_printk();
3902#endif
3903 call = __con_initcall_start; 3971 call = __con_initcall_start;
3904 while (call < __con_initcall_end) { 3972 while (call < __con_initcall_end) {
3905 (*call)(); 3973 (*call)();
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index 791930320a13..83aeedda200c 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -28,12 +28,13 @@
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/mm.h> 29#include <linux/mm.h>
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/mutex.h>
31#include <linux/vt_kern.h> 32#include <linux/vt_kern.h>
32#include <linux/selection.h> 33#include <linux/selection.h>
33#include <linux/kbd_kern.h> 34#include <linux/kbd_kern.h>
34#include <linux/console.h> 35#include <linux/console.h>
35#include <linux/smp_lock.h>
36#include <linux/device.h> 36#include <linux/device.h>
37
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38#include <asm/byteorder.h> 39#include <asm/byteorder.h>
39#include <asm/unaligned.h> 40#include <asm/unaligned.h>
@@ -70,11 +71,11 @@ static loff_t vcs_lseek(struct file *file, loff_t offset, int orig)
70{ 71{
71 int size; 72 int size;
72 73
73 down(&con_buf_sem); 74 mutex_lock(&con_buf_mtx);
74 size = vcs_size(file->f_path.dentry->d_inode); 75 size = vcs_size(file->f_path.dentry->d_inode);
75 switch (orig) { 76 switch (orig) {
76 default: 77 default:
77 up(&con_buf_sem); 78 mutex_unlock(&con_buf_mtx);
78 return -EINVAL; 79 return -EINVAL;
79 case 2: 80 case 2:
80 offset += size; 81 offset += size;
@@ -85,11 +86,11 @@ static loff_t vcs_lseek(struct file *file, loff_t offset, int orig)
85 break; 86 break;
86 } 87 }
87 if (offset < 0 || offset > size) { 88 if (offset < 0 || offset > size) {
88 up(&con_buf_sem); 89 mutex_unlock(&con_buf_mtx);
89 return -EINVAL; 90 return -EINVAL;
90 } 91 }
91 file->f_pos = offset; 92 file->f_pos = offset;
92 up(&con_buf_sem); 93 mutex_unlock(&con_buf_mtx);
93 return file->f_pos; 94 return file->f_pos;
94} 95}
95 96
@@ -106,7 +107,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
106 unsigned short *org = NULL; 107 unsigned short *org = NULL;
107 ssize_t ret; 108 ssize_t ret;
108 109
109 down(&con_buf_sem); 110 mutex_lock(&con_buf_mtx);
110 111
111 pos = *ppos; 112 pos = *ppos;
112 113
@@ -263,7 +264,7 @@ vcs_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
263 ret = read; 264 ret = read;
264unlock_out: 265unlock_out:
265 release_console_sem(); 266 release_console_sem();
266 up(&con_buf_sem); 267 mutex_unlock(&con_buf_mtx);
267 return ret; 268 return ret;
268} 269}
269 270
@@ -280,7 +281,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
280 u16 *org0 = NULL, *org = NULL; 281 u16 *org0 = NULL, *org = NULL;
281 size_t ret; 282 size_t ret;
282 283
283 down(&con_buf_sem); 284 mutex_lock(&con_buf_mtx);
284 285
285 pos = *ppos; 286 pos = *ppos;
286 287
@@ -450,7 +451,7 @@ vcs_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
450unlock_out: 451unlock_out:
451 release_console_sem(); 452 release_console_sem();
452 453
453 up(&con_buf_sem); 454 mutex_unlock(&con_buf_mtx);
454 455
455 return ret; 456 return ret;
456} 457}
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 1bbb45b937fd..bbd9fc412877 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -86,6 +86,7 @@
86#include <linux/mm.h> 86#include <linux/mm.h>
87#include <linux/console.h> 87#include <linux/console.h>
88#include <linux/init.h> 88#include <linux/init.h>
89#include <linux/mutex.h>
89#include <linux/vt_kern.h> 90#include <linux/vt_kern.h>
90#include <linux/selection.h> 91#include <linux/selection.h>
91#include <linux/tiocl.h> 92#include <linux/tiocl.h>
@@ -157,6 +158,8 @@ static void blank_screen_t(unsigned long dummy);
157static void set_palette(struct vc_data *vc); 158static void set_palette(struct vc_data *vc);
158 159
159static int printable; /* Is console ready for printing? */ 160static int printable; /* Is console ready for printing? */
161static int default_utf8;
162module_param(default_utf8, int, S_IRUGO | S_IWUSR);
160 163
161/* 164/*
162 * ignore_poke: don't unblank the screen when things are typed. This is 165 * ignore_poke: don't unblank the screen when things are typed. This is
@@ -348,10 +351,12 @@ void update_region(struct vc_data *vc, unsigned long start, int count)
348 351
349/* Structure of attributes is hardware-dependent */ 352/* Structure of attributes is hardware-dependent */
350 353
351static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, u8 _underline, u8 _reverse) 354static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink,
355 u8 _underline, u8 _reverse, u8 _italic)
352{ 356{
353 if (vc->vc_sw->con_build_attr) 357 if (vc->vc_sw->con_build_attr)
354 return vc->vc_sw->con_build_attr(vc, _color, _intensity, _blink, _underline, _reverse); 358 return vc->vc_sw->con_build_attr(vc, _color, _intensity,
359 _blink, _underline, _reverse, _italic);
355 360
356#ifndef VT_BUF_VRAM_ONLY 361#ifndef VT_BUF_VRAM_ONLY
357/* 362/*
@@ -368,10 +373,13 @@ static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, u8
368 u8 a = vc->vc_color; 373 u8 a = vc->vc_color;
369 if (!vc->vc_can_do_color) 374 if (!vc->vc_can_do_color)
370 return _intensity | 375 return _intensity |
376 (_italic ? 2 : 0) |
371 (_underline ? 4 : 0) | 377 (_underline ? 4 : 0) |
372 (_reverse ? 8 : 0) | 378 (_reverse ? 8 : 0) |
373 (_blink ? 0x80 : 0); 379 (_blink ? 0x80 : 0);
374 if (_underline) 380 if (_italic)
381 a = (a & 0xF0) | vc->vc_itcolor;
382 else if (_underline)
375 a = (a & 0xf0) | vc->vc_ulcolor; 383 a = (a & 0xf0) | vc->vc_ulcolor;
376 else if (_intensity == 0) 384 else if (_intensity == 0)
377 a = (a & 0xf0) | vc->vc_ulcolor; 385 a = (a & 0xf0) | vc->vc_ulcolor;
@@ -392,8 +400,10 @@ static u8 build_attr(struct vc_data *vc, u8 _color, u8 _intensity, u8 _blink, u8
392 400
393static void update_attr(struct vc_data *vc) 401static void update_attr(struct vc_data *vc)
394{ 402{
395 vc->vc_attr = build_attr(vc, vc->vc_color, vc->vc_intensity, vc->vc_blink, vc->vc_underline, vc->vc_reverse ^ vc->vc_decscnm); 403 vc->vc_attr = build_attr(vc, vc->vc_color, vc->vc_intensity,
396 vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm) << 8) | ' '; 404 vc->vc_blink, vc->vc_underline,
405 vc->vc_reverse ^ vc->vc_decscnm, vc->vc_italic);
406 vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm, 0) << 8) | ' ';
397} 407}
398 408
399/* Note: inverting the screen twice should revert to the original state */ 409/* Note: inverting the screen twice should revert to the original state */
@@ -934,6 +944,10 @@ int default_grn[] = {0x00,0x00,0xaa,0x55,0x00,0x00,0xaa,0xaa,
934int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa, 944int default_blu[] = {0x00,0x00,0x00,0x00,0xaa,0xaa,0xaa,0xaa,
935 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff}; 945 0x55,0x55,0x55,0x55,0xff,0xff,0xff,0xff};
936 946
947module_param_array(default_red, int, NULL, S_IRUGO | S_IWUSR);
948module_param_array(default_grn, int, NULL, S_IRUGO | S_IWUSR);
949module_param_array(default_blu, int, NULL, S_IRUGO | S_IWUSR);
950
937/* 951/*
938 * gotoxy() must verify all boundaries, because the arguments 952 * gotoxy() must verify all boundaries, because the arguments
939 * might also be negative. If the given position is out of 953 * might also be negative. If the given position is out of
@@ -1132,6 +1146,7 @@ static void csi_X(struct vc_data *vc, int vpar) /* erase the following vpar posi
1132static void default_attr(struct vc_data *vc) 1146static void default_attr(struct vc_data *vc)
1133{ 1147{
1134 vc->vc_intensity = 1; 1148 vc->vc_intensity = 1;
1149 vc->vc_italic = 0;
1135 vc->vc_underline = 0; 1150 vc->vc_underline = 0;
1136 vc->vc_reverse = 0; 1151 vc->vc_reverse = 0;
1137 vc->vc_blink = 0; 1152 vc->vc_blink = 0;
@@ -1154,6 +1169,9 @@ static void csi_m(struct vc_data *vc)
1154 case 2: 1169 case 2:
1155 vc->vc_intensity = 0; 1170 vc->vc_intensity = 0;
1156 break; 1171 break;
1172 case 3:
1173 vc->vc_italic = 1;
1174 break;
1157 case 4: 1175 case 4:
1158 vc->vc_underline = 1; 1176 vc->vc_underline = 1;
1159 break; 1177 break;
@@ -1194,6 +1212,9 @@ static void csi_m(struct vc_data *vc)
1194 case 22: 1212 case 22:
1195 vc->vc_intensity = 1; 1213 vc->vc_intensity = 1;
1196 break; 1214 break;
1215 case 23:
1216 vc->vc_italic = 0;
1217 break;
1197 case 24: 1218 case 24:
1198 vc->vc_underline = 0; 1219 vc->vc_underline = 0;
1199 break; 1220 break;
@@ -1454,6 +1475,7 @@ static void save_cur(struct vc_data *vc)
1454 vc->vc_saved_x = vc->vc_x; 1475 vc->vc_saved_x = vc->vc_x;
1455 vc->vc_saved_y = vc->vc_y; 1476 vc->vc_saved_y = vc->vc_y;
1456 vc->vc_s_intensity = vc->vc_intensity; 1477 vc->vc_s_intensity = vc->vc_intensity;
1478 vc->vc_s_italic = vc->vc_italic;
1457 vc->vc_s_underline = vc->vc_underline; 1479 vc->vc_s_underline = vc->vc_underline;
1458 vc->vc_s_blink = vc->vc_blink; 1480 vc->vc_s_blink = vc->vc_blink;
1459 vc->vc_s_reverse = vc->vc_reverse; 1481 vc->vc_s_reverse = vc->vc_reverse;
@@ -1468,6 +1490,7 @@ static void restore_cur(struct vc_data *vc)
1468{ 1490{
1469 gotoxy(vc, vc->vc_saved_x, vc->vc_saved_y); 1491 gotoxy(vc, vc->vc_saved_x, vc->vc_saved_y);
1470 vc->vc_intensity = vc->vc_s_intensity; 1492 vc->vc_intensity = vc->vc_s_intensity;
1493 vc->vc_italic = vc->vc_s_italic;
1471 vc->vc_underline = vc->vc_s_underline; 1494 vc->vc_underline = vc->vc_s_underline;
1472 vc->vc_blink = vc->vc_s_blink; 1495 vc->vc_blink = vc->vc_s_blink;
1473 vc->vc_reverse = vc->vc_s_reverse; 1496 vc->vc_reverse = vc->vc_s_reverse;
@@ -1497,7 +1520,7 @@ static void reset_terminal(struct vc_data *vc, int do_clear)
1497 vc->vc_charset = 0; 1520 vc->vc_charset = 0;
1498 vc->vc_need_wrap = 0; 1521 vc->vc_need_wrap = 0;
1499 vc->vc_report_mouse = 0; 1522 vc->vc_report_mouse = 0;
1500 vc->vc_utf = 0; 1523 vc->vc_utf = default_utf8;
1501 vc->vc_utf_count = 0; 1524 vc->vc_utf_count = 0;
1502 1525
1503 vc->vc_disp_ctrl = 0; 1526 vc->vc_disp_ctrl = 0;
@@ -1930,7 +1953,47 @@ static void do_con_trol(struct tty_struct *tty, struct vc_data *vc, int c)
1930 * kernel memory allocation is available. 1953 * kernel memory allocation is available.
1931 */ 1954 */
1932char con_buf[CON_BUF_SIZE]; 1955char con_buf[CON_BUF_SIZE];
1933DECLARE_MUTEX(con_buf_sem); 1956DEFINE_MUTEX(con_buf_mtx);
1957
1958/* is_double_width() is based on the wcwidth() implementation by
1959 * Markus Kuhn -- 2003-05-20 (Unicode 4.0)
1960 * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
1961 */
1962struct interval {
1963 uint32_t first;
1964 uint32_t last;
1965};
1966
1967static int bisearch(uint32_t ucs, const struct interval *table, int max)
1968{
1969 int min = 0;
1970 int mid;
1971
1972 if (ucs < table[0].first || ucs > table[max].last)
1973 return 0;
1974 while (max >= min) {
1975 mid = (min + max) / 2;
1976 if (ucs > table[mid].last)
1977 min = mid + 1;
1978 else if (ucs < table[mid].first)
1979 max = mid - 1;
1980 else
1981 return 1;
1982 }
1983 return 0;
1984}
1985
1986static int is_double_width(uint32_t ucs)
1987{
1988 static const struct interval double_width[] = {
1989 { 0x1100, 0x115F }, { 0x2329, 0x232A }, { 0x2E80, 0x303E },
1990 { 0x3040, 0xA4CF }, { 0xAC00, 0xD7A3 }, { 0xF900, 0xFAFF },
1991 { 0xFE30, 0xFE6F }, { 0xFF00, 0xFF60 }, { 0xFFE0, 0xFFE6 },
1992 { 0x20000, 0x2FFFD }, { 0x30000, 0x3FFFD }
1993 };
1994 return bisearch(ucs, double_width,
1995 sizeof(double_width) / sizeof(*double_width) - 1);
1996}
1934 1997
1935/* acquires console_sem */ 1998/* acquires console_sem */
1936static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count) 1999static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int count)
@@ -1948,6 +2011,10 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
1948 unsigned int currcons; 2011 unsigned int currcons;
1949 unsigned long draw_from = 0, draw_to = 0; 2012 unsigned long draw_from = 0, draw_to = 0;
1950 struct vc_data *vc; 2013 struct vc_data *vc;
2014 unsigned char vc_attr;
2015 uint8_t rescan;
2016 uint8_t inverse;
2017 uint8_t width;
1951 u16 himask, charmask; 2018 u16 himask, charmask;
1952 const unsigned char *orig_buf = NULL; 2019 const unsigned char *orig_buf = NULL;
1953 int orig_count; 2020 int orig_count;
@@ -1983,7 +2050,7 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
1983 2050
1984 /* At this point 'buf' is guaranteed to be a kernel buffer 2051 /* At this point 'buf' is guaranteed to be a kernel buffer
1985 * and therefore no access to userspace (and therefore sleeping) 2052 * and therefore no access to userspace (and therefore sleeping)
1986 * will be needed. The con_buf_sem serializes all tty based 2053 * will be needed. The con_buf_mtx serializes all tty based
1987 * console rendering and vcs write/read operations. We hold 2054 * console rendering and vcs write/read operations. We hold
1988 * the console spinlock during the entire write. 2055 * the console spinlock during the entire write.
1989 */ 2056 */
@@ -2010,53 +2077,86 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2010 buf++; 2077 buf++;
2011 n++; 2078 n++;
2012 count--; 2079 count--;
2080 rescan = 0;
2081 inverse = 0;
2082 width = 1;
2013 2083
2014 /* Do no translation at all in control states */ 2084 /* Do no translation at all in control states */
2015 if (vc->vc_state != ESnormal) { 2085 if (vc->vc_state != ESnormal) {
2016 tc = c; 2086 tc = c;
2017 } else if (vc->vc_utf && !vc->vc_disp_ctrl) { 2087 } else if (vc->vc_utf && !vc->vc_disp_ctrl) {
2018 /* Combine UTF-8 into Unicode */ 2088 /* Combine UTF-8 into Unicode in vc_utf_char.
2019 /* Malformed sequences as sequences of replacement glyphs */ 2089 * vc_utf_count is the number of continuation bytes still
2090 * expected to arrive.
2091 * vc_npar is the number of continuation bytes arrived so
2092 * far
2093 */
2020rescan_last_byte: 2094rescan_last_byte:
2021 if(c > 0x7f) { 2095 if ((c & 0xc0) == 0x80) {
2096 /* Continuation byte received */
2097 static const uint32_t utf8_length_changes[] = { 0x0000007f, 0x000007ff, 0x0000ffff, 0x001fffff, 0x03ffffff, 0x7fffffff };
2022 if (vc->vc_utf_count) { 2098 if (vc->vc_utf_count) {
2023 if ((c & 0xc0) == 0x80) { 2099 vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f);
2024 vc->vc_utf_char = (vc->vc_utf_char << 6) | (c & 0x3f); 2100 vc->vc_npar++;
2025 if (--vc->vc_utf_count) { 2101 if (--vc->vc_utf_count) {
2026 vc->vc_npar++; 2102 /* Still need some bytes */
2027 continue;
2028 }
2029 tc = c = vc->vc_utf_char;
2030 } else
2031 goto replacement_glyph;
2032 } else {
2033 vc->vc_npar = 0;
2034 if ((c & 0xe0) == 0xc0) {
2035 vc->vc_utf_count = 1;
2036 vc->vc_utf_char = (c & 0x1f);
2037 } else if ((c & 0xf0) == 0xe0) {
2038 vc->vc_utf_count = 2;
2039 vc->vc_utf_char = (c & 0x0f);
2040 } else if ((c & 0xf8) == 0xf0) {
2041 vc->vc_utf_count = 3;
2042 vc->vc_utf_char = (c & 0x07);
2043 } else if ((c & 0xfc) == 0xf8) {
2044 vc->vc_utf_count = 4;
2045 vc->vc_utf_char = (c & 0x03);
2046 } else if ((c & 0xfe) == 0xfc) {
2047 vc->vc_utf_count = 5;
2048 vc->vc_utf_char = (c & 0x01);
2049 } else
2050 goto replacement_glyph;
2051 continue; 2103 continue;
2052 } 2104 }
2105 /* Got a whole character */
2106 c = vc->vc_utf_char;
2107 /* Reject overlong sequences */
2108 if (c <= utf8_length_changes[vc->vc_npar - 1] ||
2109 c > utf8_length_changes[vc->vc_npar])
2110 c = 0xfffd;
2111 } else {
2112 /* Unexpected continuation byte */
2113 vc->vc_utf_count = 0;
2114 c = 0xfffd;
2115 }
2053 } else { 2116 } else {
2054 if (vc->vc_utf_count) 2117 /* Single ASCII byte or first byte of a sequence received */
2055 goto replacement_glyph; 2118 if (vc->vc_utf_count) {
2056 tc = c; 2119 /* Continuation byte expected */
2120 rescan = 1;
2121 vc->vc_utf_count = 0;
2122 c = 0xfffd;
2123 } else if (c > 0x7f) {
2124 /* First byte of a multibyte sequence received */
2125 vc->vc_npar = 0;
2126 if ((c & 0xe0) == 0xc0) {
2127 vc->vc_utf_count = 1;
2128 vc->vc_utf_char = (c & 0x1f);
2129 } else if ((c & 0xf0) == 0xe0) {
2130 vc->vc_utf_count = 2;
2131 vc->vc_utf_char = (c & 0x0f);
2132 } else if ((c & 0xf8) == 0xf0) {
2133 vc->vc_utf_count = 3;
2134 vc->vc_utf_char = (c & 0x07);
2135 } else if ((c & 0xfc) == 0xf8) {
2136 vc->vc_utf_count = 4;
2137 vc->vc_utf_char = (c & 0x03);
2138 } else if ((c & 0xfe) == 0xfc) {
2139 vc->vc_utf_count = 5;
2140 vc->vc_utf_char = (c & 0x01);
2141 } else {
2142 /* 254 and 255 are invalid */
2143 c = 0xfffd;
2144 }
2145 if (vc->vc_utf_count) {
2146 /* Still need some bytes */
2147 continue;
2148 }
2149 }
2150 /* Nothing to do if an ASCII byte was received */
2057 } 2151 }
2152 /* End of UTF-8 decoding. */
2153 /* c is the received character, or U+FFFD for invalid sequences. */
2154 /* Replace invalid Unicode code points with U+FFFD too */
2155 if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff)
2156 c = 0xfffd;
2157 tc = c;
2058 } else { /* no utf or alternate charset mode */ 2158 } else { /* no utf or alternate charset mode */
2059 tc = vc->vc_translate[vc->vc_toggle_meta ? (c | 0x80) : c]; 2159 tc = vc->vc_translate[vc->vc_toggle_meta ? (c | 0x80) : c];
2060 } 2160 }
2061 2161
2062 /* If the original code was a control character we 2162 /* If the original code was a control character we
@@ -2076,56 +2176,80 @@ rescan_last_byte:
2076 && (c != 128+27); 2176 && (c != 128+27);
2077 2177
2078 if (vc->vc_state == ESnormal && ok) { 2178 if (vc->vc_state == ESnormal && ok) {
2179 if (vc->vc_utf && !vc->vc_disp_ctrl) {
2180 if (is_double_width(c))
2181 width = 2;
2182 }
2079 /* Now try to find out how to display it */ 2183 /* Now try to find out how to display it */
2080 tc = conv_uni_to_pc(vc, tc); 2184 tc = conv_uni_to_pc(vc, tc);
2081 if (tc & ~charmask) { 2185 if (tc & ~charmask) {
2082 if ( tc == -4 ) { 2186 if (tc == -1 || tc == -2) {
2083 /* If we got -4 (not found) then see if we have 2187 continue; /* nothing to display */
2084 defined a replacement character (U+FFFD) */ 2188 }
2085replacement_glyph: 2189 /* Glyph not found */
2086 tc = conv_uni_to_pc(vc, 0xfffd); 2190 if (!(vc->vc_utf && !vc->vc_disp_ctrl) && !(c & ~charmask)) {
2087 if (!(tc & ~charmask)) 2191 /* In legacy mode use the glyph we get by a 1:1 mapping.
2088 goto display_glyph; 2192 This would make absolutely no sense with Unicode in mind. */
2089 } else if ( tc != -3 ) 2193 tc = c;
2090 continue; /* nothing to display */ 2194 } else {
2091 /* no hash table or no replacement -- 2195 /* Display U+FFFD. If it's not found, display an inverse question mark. */
2092 * hope for the best */ 2196 tc = conv_uni_to_pc(vc, 0xfffd);
2093 if ( c & ~charmask ) 2197 if (tc < 0) {
2094 tc = '?'; 2198 inverse = 1;
2095 else 2199 tc = conv_uni_to_pc(vc, '?');
2096 tc = c; 2200 if (tc < 0) tc = '?';
2201 }
2202 }
2097 } 2203 }
2098 2204
2099display_glyph: 2205 if (!inverse) {
2100 if (vc->vc_need_wrap || vc->vc_decim) 2206 vc_attr = vc->vc_attr;
2101 FLUSH
2102 if (vc->vc_need_wrap) {
2103 cr(vc);
2104 lf(vc);
2105 }
2106 if (vc->vc_decim)
2107 insert_char(vc, 1);
2108 scr_writew(himask ?
2109 ((vc->vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) :
2110 (vc->vc_attr << 8) + tc,
2111 (u16 *) vc->vc_pos);
2112 if (DO_UPDATE(vc) && draw_x < 0) {
2113 draw_x = vc->vc_x;
2114 draw_from = vc->vc_pos;
2115 }
2116 if (vc->vc_x == vc->vc_cols - 1) {
2117 vc->vc_need_wrap = vc->vc_decawm;
2118 draw_to = vc->vc_pos + 2;
2119 } else { 2207 } else {
2120 vc->vc_x++; 2208 /* invert vc_attr */
2121 draw_to = (vc->vc_pos += 2); 2209 if (!vc->vc_can_do_color) {
2210 vc_attr = (vc->vc_attr) ^ 0x08;
2211 } else if (vc->vc_hi_font_mask == 0x100) {
2212 vc_attr = ((vc->vc_attr) & 0x11) | (((vc->vc_attr) & 0xe0) >> 4) | (((vc->vc_attr) & 0x0e) << 4);
2213 } else {
2214 vc_attr = ((vc->vc_attr) & 0x88) | (((vc->vc_attr) & 0x70) >> 4) | (((vc->vc_attr) & 0x07) << 4);
2215 }
2122 } 2216 }
2123 if (vc->vc_utf_count) { 2217
2124 if (vc->vc_npar) { 2218 while (1) {
2125 vc->vc_npar--; 2219 if (vc->vc_need_wrap || vc->vc_decim)
2126 goto display_glyph; 2220 FLUSH
2221 if (vc->vc_need_wrap) {
2222 cr(vc);
2223 lf(vc);
2224 }
2225 if (vc->vc_decim)
2226 insert_char(vc, 1);
2227 scr_writew(himask ?
2228 ((vc_attr << 8) & ~himask) + ((tc & 0x100) ? himask : 0) + (tc & 0xff) :
2229 (vc_attr << 8) + tc,
2230 (u16 *) vc->vc_pos);
2231 if (DO_UPDATE(vc) && draw_x < 0) {
2232 draw_x = vc->vc_x;
2233 draw_from = vc->vc_pos;
2234 }
2235 if (vc->vc_x == vc->vc_cols - 1) {
2236 vc->vc_need_wrap = vc->vc_decawm;
2237 draw_to = vc->vc_pos + 2;
2238 } else {
2239 vc->vc_x++;
2240 draw_to = (vc->vc_pos += 2);
2127 } 2241 }
2128 vc->vc_utf_count = 0; 2242
2243 if (!--width) break;
2244
2245 tc = conv_uni_to_pc(vc, ' '); /* A space is printed in the second column */
2246 if (tc < 0) tc = ' ';
2247 }
2248
2249 if (rescan) {
2250 rescan = 0;
2251 inverse = 0;
2252 width = 1;
2129 c = orig; 2253 c = orig;
2130 goto rescan_last_byte; 2254 goto rescan_last_byte;
2131 } 2255 }
@@ -2581,6 +2705,11 @@ static void con_close(struct tty_struct *tty, struct file *filp)
2581 mutex_unlock(&tty_mutex); 2705 mutex_unlock(&tty_mutex);
2582} 2706}
2583 2707
2708static int default_italic_color = 2; // green (ASCII)
2709static int default_underline_color = 3; // cyan (ASCII)
2710module_param_named(italic, default_italic_color, int, S_IRUGO | S_IWUSR);
2711module_param_named(underline, default_underline_color, int, S_IRUGO | S_IWUSR);
2712
2584static void vc_init(struct vc_data *vc, unsigned int rows, 2713static void vc_init(struct vc_data *vc, unsigned int rows,
2585 unsigned int cols, int do_clear) 2714 unsigned int cols, int do_clear)
2586{ 2715{
@@ -2600,7 +2729,8 @@ static void vc_init(struct vc_data *vc, unsigned int rows,
2600 vc->vc_palette[k++] = default_blu[j] ; 2729 vc->vc_palette[k++] = default_blu[j] ;
2601 } 2730 }
2602 vc->vc_def_color = 0x07; /* white */ 2731 vc->vc_def_color = 0x07; /* white */
2603 vc->vc_ulcolor = 0x0f; /* bold white */ 2732 vc->vc_ulcolor = default_underline_color;
2733 vc->vc_itcolor = default_italic_color;
2604 vc->vc_halfcolor = 0x08; /* grey */ 2734 vc->vc_halfcolor = 0x08; /* grey */
2605 init_waitqueue_head(&vc->paste_wait); 2735 init_waitqueue_head(&vc->paste_wait);
2606 reset_terminal(vc, do_clear); 2736 reset_terminal(vc, do_clear);
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index c9f2dd620e87..c6f6f4209739 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -1061,7 +1061,7 @@ int vt_waitactive(int vt)
1061 schedule(); 1061 schedule();
1062 } 1062 }
1063 remove_wait_queue(&vt_activate_queue, &wait); 1063 remove_wait_queue(&vt_activate_queue, &wait);
1064 current->state = TASK_RUNNING; 1064 __set_current_state(TASK_RUNNING);
1065 return retval; 1065 return retval;
1066} 1066}
1067 1067
diff --git a/drivers/char/watchdog/Kconfig b/drivers/char/watchdog/Kconfig
index 60198a78974c..1cad32c62ed3 100644
--- a/drivers/char/watchdog/Kconfig
+++ b/drivers/char/watchdog/Kconfig
@@ -2,9 +2,7 @@
2# Watchdog device configuration 2# Watchdog device configuration
3# 3#
4 4
5menu "Watchdog Cards" 5menuconfig WATCHDOG
6
7config WATCHDOG
8 bool "Watchdog Timer Support" 6 bool "Watchdog Timer Support"
9 ---help--- 7 ---help---
10 If you say Y here (and to one of the following options) and create a 8 If you say Y here (and to one of the following options) and create a
@@ -28,9 +26,10 @@ config WATCHDOG
28 26
29 If unsure, say N. 27 If unsure, say N.
30 28
29if WATCHDOG
30
31config WATCHDOG_NOWAYOUT 31config WATCHDOG_NOWAYOUT
32 bool "Disable watchdog shutdown on close" 32 bool "Disable watchdog shutdown on close"
33 depends on WATCHDOG
34 help 33 help
35 The default watchdog behaviour (which you get if you say N here) is 34 The default watchdog behaviour (which you get if you say N here) is
36 to stop the timer if the process managing it closes the file 35 to stop the timer if the process managing it closes the file
@@ -43,13 +42,11 @@ config WATCHDOG_NOWAYOUT
43# 42#
44 43
45comment "Watchdog Device Drivers" 44comment "Watchdog Device Drivers"
46 depends on WATCHDOG
47 45
48# Architecture Independent 46# Architecture Independent
49 47
50config SOFT_WATCHDOG 48config SOFT_WATCHDOG
51 tristate "Software watchdog" 49 tristate "Software watchdog"
52 depends on WATCHDOG
53 help 50 help
54 A software monitoring watchdog. This will fail to reboot your system 51 A software monitoring watchdog. This will fail to reboot your system
55 from some situations that the hardware watchdog will recover 52 from some situations that the hardware watchdog will recover
@@ -62,14 +59,14 @@ config SOFT_WATCHDOG
62 59
63config AT91RM9200_WATCHDOG 60config AT91RM9200_WATCHDOG
64 tristate "AT91RM9200 watchdog" 61 tristate "AT91RM9200 watchdog"
65 depends on WATCHDOG && ARCH_AT91RM9200 62 depends on ARCH_AT91RM9200
66 help 63 help
67 Watchdog timer embedded into AT91RM9200 chips. This will reboot your 64 Watchdog timer embedded into AT91RM9200 chips. This will reboot your
68 system when the timeout is reached. 65 system when the timeout is reached.
69 66
70config 21285_WATCHDOG 67config 21285_WATCHDOG
71 tristate "DC21285 watchdog" 68 tristate "DC21285 watchdog"
72 depends on WATCHDOG && FOOTBRIDGE 69 depends on FOOTBRIDGE
73 help 70 help
74 The Intel Footbridge chip contains a built-in watchdog circuit. Say Y 71 The Intel Footbridge chip contains a built-in watchdog circuit. Say Y
75 here if you wish to use this. Alternatively say M to compile the 72 here if you wish to use this. Alternatively say M to compile the
@@ -83,7 +80,7 @@ config 21285_WATCHDOG
83 80
84config 977_WATCHDOG 81config 977_WATCHDOG
85 tristate "NetWinder WB83C977 watchdog" 82 tristate "NetWinder WB83C977 watchdog"
86 depends on WATCHDOG && FOOTBRIDGE && ARCH_NETWINDER 83 depends on FOOTBRIDGE && ARCH_NETWINDER
87 help 84 help
88 Say Y here to include support for the WB977 watchdog included in 85 Say Y here to include support for the WB977 watchdog included in
89 NetWinder machines. Alternatively say M to compile the driver as 86 NetWinder machines. Alternatively say M to compile the driver as
@@ -93,7 +90,7 @@ config 977_WATCHDOG
93 90
94config IXP2000_WATCHDOG 91config IXP2000_WATCHDOG
95 tristate "IXP2000 Watchdog" 92 tristate "IXP2000 Watchdog"
96 depends on WATCHDOG && ARCH_IXP2000 93 depends on ARCH_IXP2000
97 help 94 help
98 Say Y here if to include support for the watchdog timer 95 Say Y here if to include support for the watchdog timer
99 in the Intel IXP2000(2400, 2800, 2850) network processors. 96 in the Intel IXP2000(2400, 2800, 2850) network processors.
@@ -104,7 +101,7 @@ config IXP2000_WATCHDOG
104 101
105config IXP4XX_WATCHDOG 102config IXP4XX_WATCHDOG
106 tristate "IXP4xx Watchdog" 103 tristate "IXP4xx Watchdog"
107 depends on WATCHDOG && ARCH_IXP4XX 104 depends on ARCH_IXP4XX
108 help 105 help
109 Say Y here if to include support for the watchdog timer 106 Say Y here if to include support for the watchdog timer
110 in the Intel IXP4xx network processors. This driver can 107 in the Intel IXP4xx network processors. This driver can
@@ -120,7 +117,7 @@ config IXP4XX_WATCHDOG
120 117
121config S3C2410_WATCHDOG 118config S3C2410_WATCHDOG
122 tristate "S3C2410 Watchdog" 119 tristate "S3C2410 Watchdog"
123 depends on WATCHDOG && ARCH_S3C2410 120 depends on ARCH_S3C2410
124 help 121 help
125 Watchdog timer block in the Samsung S3C2410 chips. This will 122 Watchdog timer block in the Samsung S3C2410 chips. This will
126 reboot the system when the timer expires with the watchdog 123 reboot the system when the timer expires with the watchdog
@@ -136,7 +133,7 @@ config S3C2410_WATCHDOG
136 133
137config SA1100_WATCHDOG 134config SA1100_WATCHDOG
138 tristate "SA1100/PXA2xx watchdog" 135 tristate "SA1100/PXA2xx watchdog"
139 depends on WATCHDOG && ( ARCH_SA1100 || ARCH_PXA ) 136 depends on ARCH_SA1100 || ARCH_PXA
140 help 137 help
141 Watchdog timer embedded into SA11x0 and PXA2xx chips. This will 138 Watchdog timer embedded into SA11x0 and PXA2xx chips. This will
142 reboot your system when timeout is reached. 139 reboot your system when timeout is reached.
@@ -148,7 +145,7 @@ config SA1100_WATCHDOG
148 145
149config MPCORE_WATCHDOG 146config MPCORE_WATCHDOG
150 tristate "MPcore watchdog" 147 tristate "MPcore watchdog"
151 depends on WATCHDOG && ARM_MPCORE_PLATFORM && LOCAL_TIMERS 148 depends on ARM_MPCORE_PLATFORM && LOCAL_TIMERS
152 help 149 help
153 Watchdog timer embedded into the MPcore system. 150 Watchdog timer embedded into the MPcore system.
154 151
@@ -157,7 +154,7 @@ config MPCORE_WATCHDOG
157 154
158config EP93XX_WATCHDOG 155config EP93XX_WATCHDOG
159 tristate "EP93xx Watchdog" 156 tristate "EP93xx Watchdog"
160 depends on WATCHDOG && ARCH_EP93XX 157 depends on ARCH_EP93XX
161 help 158 help
162 Say Y here if to include support for the watchdog timer 159 Say Y here if to include support for the watchdog timer
163 embedded in the Cirrus Logic EP93xx family of devices. 160 embedded in the Cirrus Logic EP93xx family of devices.
@@ -167,14 +164,14 @@ config EP93XX_WATCHDOG
167 164
168config OMAP_WATCHDOG 165config OMAP_WATCHDOG
169 tristate "OMAP Watchdog" 166 tristate "OMAP Watchdog"
170 depends on WATCHDOG && (ARCH_OMAP16XX || ARCH_OMAP24XX) 167 depends on ARCH_OMAP16XX || ARCH_OMAP24XX
171 help 168 help
172 Support for TI OMAP1610/OMAP1710/OMAP2420 watchdog. Say 'Y' here to 169 Support for TI OMAP1610/OMAP1710/OMAP2420 watchdog. Say 'Y' here to
173 enable the OMAP1610/OMAP1710 watchdog timer. 170 enable the OMAP1610/OMAP1710 watchdog timer.
174 171
175config PNX4008_WATCHDOG 172config PNX4008_WATCHDOG
176 tristate "PNX4008 Watchdog" 173 tristate "PNX4008 Watchdog"
177 depends on WATCHDOG && ARCH_PNX4008 174 depends on ARCH_PNX4008
178 help 175 help
179 Say Y here if to include support for the watchdog timer 176 Say Y here if to include support for the watchdog timer
180 in the PNX4008 processor. 177 in the PNX4008 processor.
@@ -187,7 +184,7 @@ config PNX4008_WATCHDOG
187 184
188config ACQUIRE_WDT 185config ACQUIRE_WDT
189 tristate "Acquire SBC Watchdog Timer" 186 tristate "Acquire SBC Watchdog Timer"
190 depends on WATCHDOG && X86 187 depends on X86
191 ---help--- 188 ---help---
192 This is the driver for the hardware watchdog on Single Board 189 This is the driver for the hardware watchdog on Single Board
193 Computers produced by Acquire Inc (and others). This watchdog 190 Computers produced by Acquire Inc (and others). This watchdog
@@ -201,7 +198,7 @@ config ACQUIRE_WDT
201 198
202config ADVANTECH_WDT 199config ADVANTECH_WDT
203 tristate "Advantech SBC Watchdog Timer" 200 tristate "Advantech SBC Watchdog Timer"
204 depends on WATCHDOG && X86 201 depends on X86
205 help 202 help
206 If you are configuring a Linux kernel for the Advantech single-board 203 If you are configuring a Linux kernel for the Advantech single-board
207 computer, say `Y' here to support its built-in watchdog timer 204 computer, say `Y' here to support its built-in watchdog timer
@@ -210,7 +207,7 @@ config ADVANTECH_WDT
210 207
211config ALIM1535_WDT 208config ALIM1535_WDT
212 tristate "ALi M1535 PMU Watchdog Timer" 209 tristate "ALi M1535 PMU Watchdog Timer"
213 depends on WATCHDOG && X86 && PCI 210 depends on X86 && PCI
214 ---help--- 211 ---help---
215 This is the driver for the hardware watchdog on the ALi M1535 PMU. 212 This is the driver for the hardware watchdog on the ALi M1535 PMU.
216 213
@@ -221,7 +218,7 @@ config ALIM1535_WDT
221 218
222config ALIM7101_WDT 219config ALIM7101_WDT
223 tristate "ALi M7101 PMU Computer Watchdog" 220 tristate "ALi M7101 PMU Computer Watchdog"
224 depends on WATCHDOG && X86 && PCI 221 depends on X86 && PCI
225 help 222 help
226 This is the driver for the hardware watchdog on the ALi M7101 PMU 223 This is the driver for the hardware watchdog on the ALi M7101 PMU
227 as used in the x86 Cobalt servers. 224 as used in the x86 Cobalt servers.
@@ -233,7 +230,7 @@ config ALIM7101_WDT
233 230
234config SC520_WDT 231config SC520_WDT
235 tristate "AMD Elan SC520 processor Watchdog" 232 tristate "AMD Elan SC520 processor Watchdog"
236 depends on WATCHDOG && X86 233 depends on X86
237 help 234 help
238 This is the driver for the hardware watchdog built in to the 235 This is the driver for the hardware watchdog built in to the
239 AMD "Elan" SC520 microcomputer commonly used in embedded systems. 236 AMD "Elan" SC520 microcomputer commonly used in embedded systems.
@@ -246,7 +243,7 @@ config SC520_WDT
246 243
247config EUROTECH_WDT 244config EUROTECH_WDT
248 tristate "Eurotech CPU-1220/1410 Watchdog Timer" 245 tristate "Eurotech CPU-1220/1410 Watchdog Timer"
249 depends on WATCHDOG && X86 246 depends on X86
250 help 247 help
251 Enable support for the watchdog timer on the Eurotech CPU-1220 and 248 Enable support for the watchdog timer on the Eurotech CPU-1220 and
252 CPU-1410 cards. These are PC/104 SBCs. Spec sheets and product 249 CPU-1410 cards. These are PC/104 SBCs. Spec sheets and product
@@ -254,7 +251,7 @@ config EUROTECH_WDT
254 251
255config IB700_WDT 252config IB700_WDT
256 tristate "IB700 SBC Watchdog Timer" 253 tristate "IB700 SBC Watchdog Timer"
257 depends on WATCHDOG && X86 254 depends on X86
258 ---help--- 255 ---help---
259 This is the driver for the hardware watchdog on the IB700 Single 256 This is the driver for the hardware watchdog on the IB700 Single
260 Board Computer produced by TMC Technology (www.tmc-uk.com). This watchdog 257 Board Computer produced by TMC Technology (www.tmc-uk.com). This watchdog
@@ -270,7 +267,7 @@ config IB700_WDT
270 267
271config IBMASR 268config IBMASR
272 tristate "IBM Automatic Server Restart" 269 tristate "IBM Automatic Server Restart"
273 depends on WATCHDOG && X86 270 depends on X86
274 help 271 help
275 This is the driver for the IBM Automatic Server Restart watchdog 272 This is the driver for the IBM Automatic Server Restart watchdog
276 timer built-in into some eServer xSeries machines. 273 timer built-in into some eServer xSeries machines.
@@ -280,7 +277,7 @@ config IBMASR
280 277
281config WAFER_WDT 278config WAFER_WDT
282 tristate "ICP Wafer 5823 Single Board Computer Watchdog" 279 tristate "ICP Wafer 5823 Single Board Computer Watchdog"
283 depends on WATCHDOG && X86 280 depends on X86
284 help 281 help
285 This is a driver for the hardware watchdog on the ICP Wafer 5823 282 This is a driver for the hardware watchdog on the ICP Wafer 5823
286 Single Board Computer (and probably other similar models). 283 Single Board Computer (and probably other similar models).
@@ -290,7 +287,7 @@ config WAFER_WDT
290 287
291config I6300ESB_WDT 288config I6300ESB_WDT
292 tristate "Intel 6300ESB Timer/Watchdog" 289 tristate "Intel 6300ESB Timer/Watchdog"
293 depends on WATCHDOG && X86 && PCI 290 depends on X86 && PCI
294 ---help--- 291 ---help---
295 Hardware driver for the watchdog timer built into the Intel 292 Hardware driver for the watchdog timer built into the Intel
296 6300ESB controller hub. 293 6300ESB controller hub.
@@ -298,31 +295,9 @@ config I6300ESB_WDT
298 To compile this driver as a module, choose M here: the 295 To compile this driver as a module, choose M here: the
299 module will be called i6300esb. 296 module will be called i6300esb.
300 297
301config I8XX_TCO
302 tristate "Intel i8xx TCO Timer/Watchdog"
303 depends on WATCHDOG && (X86 || IA64) && PCI
304 default n
305 ---help---
306 Hardware driver for the TCO timer built into the Intel 82801
307 I/O Controller Hub family. The TCO (Total Cost of Ownership)
308 timer is a watchdog timer that will reboot the machine after
309 its second expiration. The expiration time can be configured
310 with the "heartbeat" parameter.
311
312 On some motherboards the driver may fail to reset the chipset's
313 NO_REBOOT flag which prevents the watchdog from rebooting the
314 machine. If this is the case you will get a kernel message like
315 "failed to reset NO_REBOOT flag, reboot disabled by hardware".
316
317 To compile this driver as a module, choose M here: the
318 module will be called i8xx_tco.
319
320 Note: This driver will be removed in the near future. Please
321 use the Intel TCO Timer/Watchdog driver.
322
323config ITCO_WDT 298config ITCO_WDT
324 tristate "Intel TCO Timer/Watchdog" 299 tristate "Intel TCO Timer/Watchdog"
325 depends on WATCHDOG && (X86 || IA64) && PCI 300 depends on (X86 || IA64) && PCI
326 ---help--- 301 ---help---
327 Hardware driver for the intel TCO timer based watchdog devices. 302 Hardware driver for the intel TCO timer based watchdog devices.
328 These drivers are included in the Intel 82801 I/O Controller 303 These drivers are included in the Intel 82801 I/O Controller
@@ -351,7 +326,7 @@ config ITCO_VENDOR_SUPPORT
351 326
352config SC1200_WDT 327config SC1200_WDT
353 tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog" 328 tristate "National Semiconductor PC87307/PC97307 (ala SC1200) Watchdog"
354 depends on WATCHDOG && X86 329 depends on X86
355 help 330 help
356 This is a driver for National Semiconductor PC87307/PC97307 hardware 331 This is a driver for National Semiconductor PC87307/PC97307 hardware
357 watchdog cards as found on the SC1200. This watchdog is mainly used 332 watchdog cards as found on the SC1200. This watchdog is mainly used
@@ -365,7 +340,7 @@ config SC1200_WDT
365 340
366config SCx200_WDT 341config SCx200_WDT
367 tristate "National Semiconductor SCx200 Watchdog" 342 tristate "National Semiconductor SCx200 Watchdog"
368 depends on WATCHDOG && SCx200 && PCI 343 depends on SCx200 && PCI
369 help 344 help
370 Enable the built-in watchdog timer support on the National 345 Enable the built-in watchdog timer support on the National
371 Semiconductor SCx200 processors. 346 Semiconductor SCx200 processors.
@@ -374,7 +349,7 @@ config SCx200_WDT
374 349
375config PC87413_WDT 350config PC87413_WDT
376 tristate "NS PC87413 watchdog" 351 tristate "NS PC87413 watchdog"
377 depends on WATCHDOG && X86 352 depends on X86
378 ---help--- 353 ---help---
379 This is the driver for the hardware watchdog on the PC87413 chipset 354 This is the driver for the hardware watchdog on the PC87413 chipset
380 This watchdog simply watches your kernel to make sure it doesn't 355 This watchdog simply watches your kernel to make sure it doesn't
@@ -388,7 +363,7 @@ config PC87413_WDT
388 363
389config 60XX_WDT 364config 60XX_WDT
390 tristate "SBC-60XX Watchdog Timer" 365 tristate "SBC-60XX Watchdog Timer"
391 depends on WATCHDOG && X86 366 depends on X86
392 help 367 help
393 This driver can be used with the watchdog timer found on some 368 This driver can be used with the watchdog timer found on some
394 single board computers, namely the 6010 PII based computer. 369 single board computers, namely the 6010 PII based computer.
@@ -402,7 +377,7 @@ config 60XX_WDT
402 377
403config SBC8360_WDT 378config SBC8360_WDT
404 tristate "SBC8360 Watchdog Timer" 379 tristate "SBC8360 Watchdog Timer"
405 depends on WATCHDOG && X86 380 depends on X86
406 ---help--- 381 ---help---
407 382
408 This is the driver for the hardware watchdog on the SBC8360 Single 383 This is the driver for the hardware watchdog on the SBC8360 Single
@@ -415,7 +390,7 @@ config SBC8360_WDT
415 390
416config CPU5_WDT 391config CPU5_WDT
417 tristate "SMA CPU5 Watchdog" 392 tristate "SMA CPU5 Watchdog"
418 depends on WATCHDOG && X86 393 depends on X86
419 ---help--- 394 ---help---
420 TBD. 395 TBD.
421 To compile this driver as a module, choose M here: the 396 To compile this driver as a module, choose M here: the
@@ -423,7 +398,7 @@ config CPU5_WDT
423 398
424config SMSC37B787_WDT 399config SMSC37B787_WDT
425 tristate "Winbond SMsC37B787 Watchdog Timer" 400 tristate "Winbond SMsC37B787 Watchdog Timer"
426 depends on WATCHDOG && X86 401 depends on X86
427 ---help--- 402 ---help---
428 This is the driver for the hardware watchdog component on the 403 This is the driver for the hardware watchdog component on the
429 Winbond SMsC37B787 chipset as used on the NetRunner Mainboard 404 Winbond SMsC37B787 chipset as used on the NetRunner Mainboard
@@ -443,7 +418,7 @@ config SMSC37B787_WDT
443 418
444config W83627HF_WDT 419config W83627HF_WDT
445 tristate "W83627HF Watchdog Timer" 420 tristate "W83627HF Watchdog Timer"
446 depends on WATCHDOG && X86 421 depends on X86
447 ---help--- 422 ---help---
448 This is the driver for the hardware watchdog on the W83627HF chipset 423 This is the driver for the hardware watchdog on the W83627HF chipset
449 as used in Advantech PC-9578 and Tyan S2721-533 motherboards 424 as used in Advantech PC-9578 and Tyan S2721-533 motherboards
@@ -458,7 +433,7 @@ config W83627HF_WDT
458 433
459config W83697HF_WDT 434config W83697HF_WDT
460 tristate "W83697HF/W83697HG Watchdog Timer" 435 tristate "W83697HF/W83697HG Watchdog Timer"
461 depends on WATCHDOG && X86 436 depends on X86
462 ---help--- 437 ---help---
463 This is the driver for the hardware watchdog on the W83697HF/HG 438 This is the driver for the hardware watchdog on the W83697HF/HG
464 chipset as used in Dedibox/VIA motherboards (and likely others). 439 chipset as used in Dedibox/VIA motherboards (and likely others).
@@ -473,7 +448,7 @@ config W83697HF_WDT
473 448
474config W83877F_WDT 449config W83877F_WDT
475 tristate "W83877F (EMACS) Watchdog Timer" 450 tristate "W83877F (EMACS) Watchdog Timer"
476 depends on WATCHDOG && X86 451 depends on X86
477 ---help--- 452 ---help---
478 This is the driver for the hardware watchdog on the W83877F chipset 453 This is the driver for the hardware watchdog on the W83877F chipset
479 as used in EMACS PC-104 motherboards (and likely others). This 454 as used in EMACS PC-104 motherboards (and likely others). This
@@ -488,7 +463,7 @@ config W83877F_WDT
488 463
489config W83977F_WDT 464config W83977F_WDT
490 tristate "W83977F (PCM-5335) Watchdog Timer" 465 tristate "W83977F (PCM-5335) Watchdog Timer"
491 depends on WATCHDOG && X86 466 depends on X86
492 ---help--- 467 ---help---
493 This is the driver for the hardware watchdog on the W83977F I/O chip 468 This is the driver for the hardware watchdog on the W83977F I/O chip
494 as used in AAEON's PCM-5335 SBC (and likely others). This 469 as used in AAEON's PCM-5335 SBC (and likely others). This
@@ -501,7 +476,7 @@ config W83977F_WDT
501 476
502config MACHZ_WDT 477config MACHZ_WDT
503 tristate "ZF MachZ Watchdog" 478 tristate "ZF MachZ Watchdog"
504 depends on WATCHDOG && X86 479 depends on X86
505 ---help--- 480 ---help---
506 If you are using a ZF Micro MachZ processor, say Y here, otherwise 481 If you are using a ZF Micro MachZ processor, say Y here, otherwise
507 N. This is the driver for the watchdog timer built-in on that 482 N. This is the driver for the watchdog timer built-in on that
@@ -514,7 +489,7 @@ config MACHZ_WDT
514 489
515config SBC_EPX_C3_WATCHDOG 490config SBC_EPX_C3_WATCHDOG
516 tristate "Winsystems SBC EPX-C3 watchdog" 491 tristate "Winsystems SBC EPX-C3 watchdog"
517 depends on WATCHDOG && X86 492 depends on X86
518 ---help--- 493 ---help---
519 This is the driver for the built-in watchdog timer on the EPX-C3 494 This is the driver for the built-in watchdog timer on the EPX-C3
520 Single-board computer made by Winsystems, Inc. 495 Single-board computer made by Winsystems, Inc.
@@ -537,19 +512,19 @@ config SBC_EPX_C3_WATCHDOG
537 512
538config 8xx_WDT 513config 8xx_WDT
539 tristate "MPC8xx Watchdog Timer" 514 tristate "MPC8xx Watchdog Timer"
540 depends on WATCHDOG && 8xx 515 depends on 8xx
541 516
542config 83xx_WDT 517config 83xx_WDT
543 tristate "MPC83xx Watchdog Timer" 518 tristate "MPC83xx Watchdog Timer"
544 depends on WATCHDOG && PPC_83xx 519 depends on PPC_83xx
545 520
546config MV64X60_WDT 521config MV64X60_WDT
547 tristate "MV64X60 (Marvell Discovery) Watchdog Timer" 522 tristate "MV64X60 (Marvell Discovery) Watchdog Timer"
548 depends on WATCHDOG && MV64X60 523 depends on MV64X60
549 524
550config BOOKE_WDT 525config BOOKE_WDT
551 bool "PowerPC Book-E Watchdog Timer" 526 bool "PowerPC Book-E Watchdog Timer"
552 depends on WATCHDOG && (BOOKE || 4xx) 527 depends on BOOKE || 4xx
553 ---help--- 528 ---help---
554 Please see Documentation/watchdog/watchdog-api.txt for 529 Please see Documentation/watchdog/watchdog-api.txt for
555 more information. 530 more information.
@@ -558,7 +533,7 @@ config BOOKE_WDT
558 533
559config WATCHDOG_RTAS 534config WATCHDOG_RTAS
560 tristate "RTAS watchdog" 535 tristate "RTAS watchdog"
561 depends on WATCHDOG && PPC_RTAS 536 depends on PPC_RTAS
562 help 537 help
563 This driver adds watchdog support for the RTAS watchdog. 538 This driver adds watchdog support for the RTAS watchdog.
564 539
@@ -569,16 +544,23 @@ config WATCHDOG_RTAS
569 544
570config INDYDOG 545config INDYDOG
571 tristate "Indy/I2 Hardware Watchdog" 546 tristate "Indy/I2 Hardware Watchdog"
572 depends on WATCHDOG && SGI_IP22 547 depends on SGI_IP22
573 help 548 help
574 Hardware driver for the Indy's/I2's watchdog. This is a 549 Hardware driver for the Indy's/I2's watchdog. This is a
575 watchdog timer that will reboot the machine after a 60 second 550 watchdog timer that will reboot the machine after a 60 second
576 timer expired and no process has written to /dev/watchdog during 551 timer expired and no process has written to /dev/watchdog during
577 that time. 552 that time.
578 553
554config WDT_MTX1
555 tristate "MTX-1 Hardware Watchdog"
556 depends on MIPS_MTX1
557 help
558 Hardware driver for the MTX-1 boards. This is a watchdog timer that
559 will reboot the machine after a 100 seconds timer expired.
560
579config WDT_RM9K_GPI 561config WDT_RM9K_GPI
580 tristate "RM9000/GPI hardware watchdog" 562 tristate "RM9000/GPI hardware watchdog"
581 depends on WATCHDOG && CPU_RM9000 563 depends on CPU_RM9000
582 help 564 help
583 Watchdog implementation using the GPI hardware found on 565 Watchdog implementation using the GPI hardware found on
584 PMC-Sierra RM9xxx CPUs. 566 PMC-Sierra RM9xxx CPUs.
@@ -590,7 +572,7 @@ config WDT_RM9K_GPI
590 572
591config ZVM_WATCHDOG 573config ZVM_WATCHDOG
592 tristate "z/VM Watchdog Timer" 574 tristate "z/VM Watchdog Timer"
593 depends on WATCHDOG && S390 575 depends on S390
594 help 576 help
595 IBM s/390 and zSeries machines running under z/VM 5.1 or later 577 IBM s/390 and zSeries machines running under z/VM 5.1 or later
596 provide a virtual watchdog timer to their guest that cause a 578 provide a virtual watchdog timer to their guest that cause a
@@ -604,7 +586,7 @@ config ZVM_WATCHDOG
604 586
605config SH_WDT 587config SH_WDT
606 tristate "SuperH Watchdog" 588 tristate "SuperH Watchdog"
607 depends on WATCHDOG && SUPERH 589 depends on SUPERH
608 help 590 help
609 This driver adds watchdog support for the integrated watchdog in the 591 This driver adds watchdog support for the integrated watchdog in the
610 SuperH processors. If you have one of these processors and wish 592 SuperH processors. If you have one of these processors and wish
@@ -631,7 +613,7 @@ config SH_WDT_MMAP
631 613
632config WATCHDOG_CP1XXX 614config WATCHDOG_CP1XXX
633 tristate "CP1XXX Hardware Watchdog support" 615 tristate "CP1XXX Hardware Watchdog support"
634 depends on WATCHDOG && SPARC64 && PCI 616 depends on SPARC64 && PCI
635 ---help--- 617 ---help---
636 This is the driver for the hardware watchdog timers present on 618 This is the driver for the hardware watchdog timers present on
637 Sun Microsystems CompactPCI models CP1400 and CP1500. 619 Sun Microsystems CompactPCI models CP1400 and CP1500.
@@ -645,7 +627,7 @@ config WATCHDOG_CP1XXX
645 627
646config WATCHDOG_RIO 628config WATCHDOG_RIO
647 tristate "RIO Hardware Watchdog support" 629 tristate "RIO Hardware Watchdog support"
648 depends on WATCHDOG && SPARC64 && PCI 630 depends on SPARC64 && PCI
649 help 631 help
650 Say Y here to support the hardware watchdog capability on Sun RIO 632 Say Y here to support the hardware watchdog capability on Sun RIO
651 machines. The watchdog timeout period is normally one minute but 633 machines. The watchdog timeout period is normally one minute but
@@ -656,11 +638,11 @@ config WATCHDOG_RIO
656# 638#
657 639
658comment "ISA-based Watchdog Cards" 640comment "ISA-based Watchdog Cards"
659 depends on WATCHDOG && ISA 641 depends on ISA
660 642
661config PCWATCHDOG 643config PCWATCHDOG
662 tristate "Berkshire Products ISA-PC Watchdog" 644 tristate "Berkshire Products ISA-PC Watchdog"
663 depends on WATCHDOG && ISA 645 depends on ISA
664 ---help--- 646 ---help---
665 This is the driver for the Berkshire Products ISA-PC Watchdog card. 647 This is the driver for the Berkshire Products ISA-PC Watchdog card.
666 This card simply watches your kernel to make sure it doesn't freeze, 648 This card simply watches your kernel to make sure it doesn't freeze,
@@ -676,7 +658,7 @@ config PCWATCHDOG
676 658
677config MIXCOMWD 659config MIXCOMWD
678 tristate "Mixcom Watchdog" 660 tristate "Mixcom Watchdog"
679 depends on WATCHDOG && ISA 661 depends on ISA
680 ---help--- 662 ---help---
681 This is a driver for the Mixcom hardware watchdog cards. This 663 This is a driver for the Mixcom hardware watchdog cards. This
682 watchdog simply watches your kernel to make sure it doesn't freeze, 664 watchdog simply watches your kernel to make sure it doesn't freeze,
@@ -690,7 +672,7 @@ config MIXCOMWD
690 672
691config WDT 673config WDT
692 tristate "WDT Watchdog timer" 674 tristate "WDT Watchdog timer"
693 depends on WATCHDOG && ISA 675 depends on ISA
694 ---help--- 676 ---help---
695 If you have a WDT500P or WDT501P watchdog board, say Y here, 677 If you have a WDT500P or WDT501P watchdog board, say Y here,
696 otherwise N. It is not possible to probe for this board, which means 678 otherwise N. It is not possible to probe for this board, which means
@@ -720,11 +702,11 @@ config WDT_501
720# 702#
721 703
722comment "PCI-based Watchdog Cards" 704comment "PCI-based Watchdog Cards"
723 depends on WATCHDOG && PCI 705 depends on PCI
724 706
725config PCIPCWATCHDOG 707config PCIPCWATCHDOG
726 tristate "Berkshire Products PCI-PC Watchdog" 708 tristate "Berkshire Products PCI-PC Watchdog"
727 depends on WATCHDOG && PCI 709 depends on PCI
728 ---help--- 710 ---help---
729 This is the driver for the Berkshire Products PCI-PC Watchdog card. 711 This is the driver for the Berkshire Products PCI-PC Watchdog card.
730 This card simply watches your kernel to make sure it doesn't freeze, 712 This card simply watches your kernel to make sure it doesn't freeze,
@@ -739,7 +721,7 @@ config PCIPCWATCHDOG
739 721
740config WDTPCI 722config WDTPCI
741 tristate "PCI-WDT500/501 Watchdog timer" 723 tristate "PCI-WDT500/501 Watchdog timer"
742 depends on WATCHDOG && PCI 724 depends on PCI
743 ---help--- 725 ---help---
744 If you have a PCI-WDT500/501 watchdog board, say Y here, otherwise N. 726 If you have a PCI-WDT500/501 watchdog board, say Y here, otherwise N.
745 727
@@ -766,11 +748,11 @@ config WDT_501_PCI
766# 748#
767 749
768comment "USB-based Watchdog Cards" 750comment "USB-based Watchdog Cards"
769 depends on WATCHDOG && USB 751 depends on USB
770 752
771config USBPCWATCHDOG 753config USBPCWATCHDOG
772 tristate "Berkshire Products USB-PC Watchdog" 754 tristate "Berkshire Products USB-PC Watchdog"
773 depends on WATCHDOG && USB 755 depends on USB
774 ---help--- 756 ---help---
775 This is the driver for the Berkshire Products USB-PC Watchdog card. 757 This is the driver for the Berkshire Products USB-PC Watchdog card.
776 This card simply watches your kernel to make sure it doesn't freeze, 758 This card simply watches your kernel to make sure it doesn't freeze,
@@ -783,4 +765,4 @@ config USBPCWATCHDOG
783 765
784 Most people will say N. 766 Most people will say N.
785 767
786endmenu 768endif # WATCHDOG
diff --git a/drivers/char/watchdog/Makefile b/drivers/char/watchdog/Makefile
index 2cd8ff8d10ac..8bfc00cc7c2b 100644
--- a/drivers/char/watchdog/Makefile
+++ b/drivers/char/watchdog/Makefile
@@ -46,7 +46,6 @@ obj-$(CONFIG_IB700_WDT) += ib700wdt.o
46obj-$(CONFIG_IBMASR) += ibmasr.o 46obj-$(CONFIG_IBMASR) += ibmasr.o
47obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o 47obj-$(CONFIG_WAFER_WDT) += wafer5823wdt.o
48obj-$(CONFIG_I6300ESB_WDT) += i6300esb.o 48obj-$(CONFIG_I6300ESB_WDT) += i6300esb.o
49obj-$(CONFIG_I8XX_TCO) += i8xx_tco.o
50obj-$(CONFIG_ITCO_WDT) += iTCO_wdt.o iTCO_vendor_support.o 49obj-$(CONFIG_ITCO_WDT) += iTCO_wdt.o iTCO_vendor_support.o
51obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o 50obj-$(CONFIG_SC1200_WDT) += sc1200wdt.o
52obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o 51obj-$(CONFIG_SCx200_WDT) += scx200_wdt.o
@@ -73,6 +72,7 @@ obj-$(CONFIG_WATCHDOG_RTAS) += wdrtas.o
73 72
74# MIPS Architecture 73# MIPS Architecture
75obj-$(CONFIG_INDYDOG) += indydog.o 74obj-$(CONFIG_INDYDOG) += indydog.o
75obj-$(CONFIG_WDT_MTX1) += mtx-1_wdt.o
76obj-$(CONFIG_WDT_RM9K_GPI) += rm9k_wdt.o 76obj-$(CONFIG_WDT_RM9K_GPI) += rm9k_wdt.o
77 77
78# S390 Architecture 78# S390 Architecture
diff --git a/drivers/char/watchdog/booke_wdt.c b/drivers/char/watchdog/booke_wdt.c
index 0e23f29f71ab..0f5c77ddd39d 100644
--- a/drivers/char/watchdog/booke_wdt.c
+++ b/drivers/char/watchdog/booke_wdt.c
@@ -24,7 +24,7 @@
24#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25#include <asm/system.h> 25#include <asm/system.h>
26 26
27/* If the kernel parameter wdt_enable=1, the watchdog will be enabled at boot. 27/* If the kernel parameter wdt=1, the watchdog will be enabled at boot.
28 * Also, the wdt_period sets the watchdog timer period timeout. 28 * Also, the wdt_period sets the watchdog timer period timeout.
29 * For E500 cpus the wdt_period sets which bit changing from 0->1 will 29 * For E500 cpus the wdt_period sets which bit changing from 0->1 will
30 * trigger a watchog timeout. This watchdog timeout will occur 3 times, the 30 * trigger a watchog timeout. This watchdog timeout will occur 3 times, the
diff --git a/drivers/char/watchdog/cpu5wdt.c b/drivers/char/watchdog/cpu5wdt.c
index bcd7e36ca0aa..d0d45a8b09f0 100644
--- a/drivers/char/watchdog/cpu5wdt.c
+++ b/drivers/char/watchdog/cpu5wdt.c
@@ -220,17 +220,17 @@ static int __devinit cpu5wdt_init(void)
220 if ( verbose ) 220 if ( verbose )
221 printk(KERN_DEBUG PFX "port=0x%x, verbose=%i\n", port, verbose); 221 printk(KERN_DEBUG PFX "port=0x%x, verbose=%i\n", port, verbose);
222 222
223 if ( (err = misc_register(&cpu5wdt_misc)) < 0 ) {
224 printk(KERN_ERR PFX "misc_register failed\n");
225 goto no_misc;
226 }
227
228 if ( !request_region(port, CPU5WDT_EXTENT, PFX) ) { 223 if ( !request_region(port, CPU5WDT_EXTENT, PFX) ) {
229 printk(KERN_ERR PFX "request_region failed\n"); 224 printk(KERN_ERR PFX "request_region failed\n");
230 err = -EBUSY; 225 err = -EBUSY;
231 goto no_port; 226 goto no_port;
232 } 227 }
233 228
229 if ( (err = misc_register(&cpu5wdt_misc)) < 0 ) {
230 printk(KERN_ERR PFX "misc_register failed\n");
231 goto no_misc;
232 }
233
234 /* watchdog reboot? */ 234 /* watchdog reboot? */
235 val = inb(port + CPU5WDT_STATUS_REG); 235 val = inb(port + CPU5WDT_STATUS_REG);
236 val = (val >> 2) & 1; 236 val = (val >> 2) & 1;
@@ -250,9 +250,9 @@ static int __devinit cpu5wdt_init(void)
250 250
251 return 0; 251 return 0;
252 252
253no_port:
254 misc_deregister(&cpu5wdt_misc);
255no_misc: 253no_misc:
254 release_region(port, CPU5WDT_EXTENT);
255no_port:
256 return err; 256 return err;
257} 257}
258 258
diff --git a/drivers/char/watchdog/eurotechwdt.c b/drivers/char/watchdog/eurotechwdt.c
index f70387f01b2b..b070324e27a6 100644
--- a/drivers/char/watchdog/eurotechwdt.c
+++ b/drivers/char/watchdog/eurotechwdt.c
@@ -413,17 +413,10 @@ static int __init eurwdt_init(void)
413{ 413{
414 int ret; 414 int ret;
415 415
416 ret = misc_register(&eurwdt_miscdev);
417 if (ret) {
418 printk(KERN_ERR "eurwdt: can't misc_register on minor=%d\n",
419 WATCHDOG_MINOR);
420 goto out;
421 }
422
423 ret = request_irq(irq, eurwdt_interrupt, IRQF_DISABLED, "eurwdt", NULL); 416 ret = request_irq(irq, eurwdt_interrupt, IRQF_DISABLED, "eurwdt", NULL);
424 if(ret) { 417 if(ret) {
425 printk(KERN_ERR "eurwdt: IRQ %d is not free.\n", irq); 418 printk(KERN_ERR "eurwdt: IRQ %d is not free.\n", irq);
426 goto outmisc; 419 goto out;
427 } 420 }
428 421
429 if (!request_region(io, 2, "eurwdt")) { 422 if (!request_region(io, 2, "eurwdt")) {
@@ -438,6 +431,13 @@ static int __init eurwdt_init(void)
438 goto outreg; 431 goto outreg;
439 } 432 }
440 433
434 ret = misc_register(&eurwdt_miscdev);
435 if (ret) {
436 printk(KERN_ERR "eurwdt: can't misc_register on minor=%d\n",
437 WATCHDOG_MINOR);
438 goto outreboot;
439 }
440
441 eurwdt_unlock_chip(); 441 eurwdt_unlock_chip();
442 442
443 ret = 0; 443 ret = 0;
@@ -448,14 +448,14 @@ static int __init eurwdt_init(void)
448out: 448out:
449 return ret; 449 return ret;
450 450
451outreboot:
452 unregister_reboot_notifier(&eurwdt_notifier);
453
451outreg: 454outreg:
452 release_region(io, 2); 455 release_region(io, 2);
453 456
454outirq: 457outirq:
455 free_irq(irq, NULL); 458 free_irq(irq, NULL);
456
457outmisc:
458 misc_deregister(&eurwdt_miscdev);
459 goto out; 459 goto out;
460} 460}
461 461
diff --git a/drivers/char/watchdog/i8xx_tco.c b/drivers/char/watchdog/i8xx_tco.c
deleted file mode 100644
index a62ef48a15ae..000000000000
--- a/drivers/char/watchdog/i8xx_tco.c
+++ /dev/null
@@ -1,571 +0,0 @@
1/*
2 * i8xx_tco: TCO timer driver for i8xx chipsets
3 *
4 * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>, All Rights Reserved.
5 * http://www.kernelconcepts.de
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * Neither kernel concepts nor Nils Faerber admit liability nor provide
13 * warranty for any of this software. This material is provided
14 * "AS-IS" and at no charge.
15 *
16 * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>
17 * developed for
18 * Jentro AG, Haar/Munich (Germany)
19 *
20 * TCO timer driver for i8xx chipsets
21 * based on softdog.c by Alan Cox <alan@redhat.com>
22 *
23 * The TCO timer is implemented in the following I/O controller hubs:
24 * (See the intel documentation on http://developer.intel.com.)
25 * 82801AA (ICH) : document number 290655-003, 290677-014,
26 * 82801AB (ICHO) : document number 290655-003, 290677-014,
27 * 82801BA (ICH2) : document number 290687-002, 298242-027,
28 * 82801BAM (ICH2-M) : document number 290687-002, 298242-027,
29 * 82801CA (ICH3-S) : document number 290733-003, 290739-013,
30 * 82801CAM (ICH3-M) : document number 290716-001, 290718-007,
31 * 82801DB (ICH4) : document number 290744-001, 290745-020,
32 * 82801DBM (ICH4-M) : document number 252337-001, 252663-005,
33 * 82801E (C-ICH) : document number 273599-001, 273645-002,
34 * 82801EB (ICH5) : document number 252516-001, 252517-003,
35 * 82801ER (ICH5R) : document number 252516-001, 252517-003,
36 *
37 * 20000710 Nils Faerber
38 * Initial Version 0.01
39 * 20000728 Nils Faerber
40 * 0.02 Fix for SMI_EN->TCO_EN bit, some cleanups
41 * 20011214 Matt Domsch <Matt_Domsch@dell.com>
42 * 0.03 Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT
43 * Didn't add timeout option as i810_margin already exists.
44 * 20020224 Joel Becker, Wim Van Sebroeck
45 * 0.04 Support for 82801CA(M) chipset, timer margin needs to be > 3,
46 * add support for WDIOC_SETTIMEOUT and WDIOC_GETTIMEOUT.
47 * 20020412 Rob Radez <rob@osinvestor.com>, Wim Van Sebroeck
48 * 0.05 Fix possible timer_alive race, add expect close support,
49 * clean up ioctls (WDIOC_GETSTATUS, WDIOC_GETBOOTSTATUS and
50 * WDIOC_SETOPTIONS), made i810tco_getdevice __init,
51 * removed boot_status, removed tco_timer_read,
52 * added support for 82801DB and 82801E chipset,
53 * added support for 82801EB and 8280ER chipset,
54 * general cleanup.
55 * 20030921 Wim Van Sebroeck <wim@iguana.be>
56 * 0.06 change i810_margin to heartbeat, use module_param,
57 * added notify system support, renamed module to i8xx_tco.
58 * 20050128 Wim Van Sebroeck <wim@iguana.be>
59 * 0.07 Added support for the ICH4-M, ICH6, ICH6R, ICH6-M, ICH6W and ICH6RW
60 * chipsets. Also added support for the "undocumented" ICH7 chipset.
61 * 20050807 Wim Van Sebroeck <wim@iguana.be>
62 * 0.08 Make sure that the watchdog is only "armed" when started.
63 * (Kernel Bug 4251)
64 * 20060416 Wim Van Sebroeck <wim@iguana.be>
65 * 0.09 Remove support for the ICH6, ICH6R, ICH6-M, ICH6W and ICH6RW and
66 * ICH7 chipsets. (See Kernel Bug 6031 - other code will support these
67 * chipsets)
68 */
69
70/*
71 * Includes, defines, variables, module parameters, ...
72 */
73
74#include <linux/module.h>
75#include <linux/moduleparam.h>
76#include <linux/types.h>
77#include <linux/miscdevice.h>
78#include <linux/watchdog.h>
79#include <linux/notifier.h>
80#include <linux/reboot.h>
81#include <linux/init.h>
82#include <linux/fs.h>
83#include <linux/pci.h>
84#include <linux/ioport.h>
85
86#include <asm/uaccess.h>
87#include <asm/io.h>
88
89#include "i8xx_tco.h"
90
91/* Module and version information */
92#define TCO_VERSION "0.09"
93#define TCO_MODULE_NAME "i8xx TCO timer"
94#define TCO_DRIVER_NAME TCO_MODULE_NAME ", v" TCO_VERSION
95#define PFX TCO_MODULE_NAME ": "
96
97/* internal variables */
98static unsigned int ACPIBASE;
99static spinlock_t tco_lock; /* Guards the hardware */
100static unsigned long timer_alive;
101static char tco_expect_close;
102static struct pci_dev *i8xx_tco_pci;
103
104/* module parameters */
105#define WATCHDOG_HEARTBEAT 30 /* 30 sec default heartbeat (2<heartbeat<39) */
106static int heartbeat = WATCHDOG_HEARTBEAT; /* in seconds */
107module_param(heartbeat, int, 0);
108MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<heartbeat<39, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
109
110static int nowayout = WATCHDOG_NOWAYOUT;
111module_param(nowayout, int, 0);
112MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
113
114/*
115 * Some TCO specific functions
116 */
117
118static inline unsigned char seconds_to_ticks(int seconds)
119{
120 /* the internal timer is stored as ticks which decrement
121 * every 0.6 seconds */
122 return (seconds * 10) / 6;
123}
124
125static int tco_timer_start (void)
126{
127 unsigned char val;
128
129 spin_lock(&tco_lock);
130
131 /* disable chipset's NO_REBOOT bit */
132 pci_read_config_byte (i8xx_tco_pci, 0xd4, &val);
133 val &= 0xfd;
134 pci_write_config_byte (i8xx_tco_pci, 0xd4, val);
135
136 /* Bit 11: TCO Timer Halt -> 0 = The TCO timer is enabled to count */
137 val = inb (TCO1_CNT + 1);
138 val &= 0xf7;
139 outb (val, TCO1_CNT + 1);
140 val = inb (TCO1_CNT + 1);
141
142 spin_unlock(&tco_lock);
143
144 if (val & 0x08)
145 return -1;
146 return 0;
147}
148
149static int tco_timer_stop (void)
150{
151 unsigned char val, val1;
152
153 spin_lock(&tco_lock);
154 /* Bit 11: TCO Timer Halt -> 1 = The TCO timer is disabled */
155 val = inb (TCO1_CNT + 1);
156 val |= 0x08;
157 outb (val, TCO1_CNT + 1);
158 val = inb (TCO1_CNT + 1);
159
160 /* Set the NO_REBOOT bit to prevent later reboots, just for sure */
161 pci_read_config_byte (i8xx_tco_pci, 0xd4, &val1);
162 val1 |= 0x02;
163 pci_write_config_byte (i8xx_tco_pci, 0xd4, val1);
164
165 spin_unlock(&tco_lock);
166
167 if ((val & 0x08) == 0)
168 return -1;
169 return 0;
170}
171
172static int tco_timer_keepalive (void)
173{
174 spin_lock(&tco_lock);
175 /* Reload the timer by writing to the TCO Timer Reload register */
176 outb (0x01, TCO1_RLD);
177 spin_unlock(&tco_lock);
178 return 0;
179}
180
181static int tco_timer_set_heartbeat (int t)
182{
183 unsigned char val;
184 unsigned char tmrval;
185
186 tmrval = seconds_to_ticks(t);
187 /* from the specs: */
188 /* "Values of 0h-3h are ignored and should not be attempted" */
189 if (tmrval > 0x3f || tmrval < 0x04)
190 return -EINVAL;
191
192 /* Write new heartbeat to watchdog */
193 spin_lock(&tco_lock);
194 val = inb (TCO1_TMR);
195 val &= 0xc0;
196 val |= tmrval;
197 outb (val, TCO1_TMR);
198 val = inb (TCO1_TMR);
199 spin_unlock(&tco_lock);
200
201 if ((val & 0x3f) != tmrval)
202 return -EINVAL;
203
204 heartbeat = t;
205 return 0;
206}
207
208static int tco_timer_get_timeleft (int *time_left)
209{
210 unsigned char val;
211
212 spin_lock(&tco_lock);
213
214 /* read the TCO Timer */
215 val = inb (TCO1_RLD);
216 val &= 0x3f;
217
218 spin_unlock(&tco_lock);
219
220 *time_left = (int)((val * 6) / 10);
221
222 return 0;
223}
224
225/*
226 * /dev/watchdog handling
227 */
228
229static int i8xx_tco_open (struct inode *inode, struct file *file)
230{
231 /* /dev/watchdog can only be opened once */
232 if (test_and_set_bit(0, &timer_alive))
233 return -EBUSY;
234
235 /*
236 * Reload and activate timer
237 */
238 tco_timer_keepalive ();
239 tco_timer_start ();
240 return nonseekable_open(inode, file);
241}
242
243static int i8xx_tco_release (struct inode *inode, struct file *file)
244{
245 /*
246 * Shut off the timer.
247 */
248 if (tco_expect_close == 42) {
249 tco_timer_stop ();
250 } else {
251 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
252 tco_timer_keepalive ();
253 }
254 clear_bit(0, &timer_alive);
255 tco_expect_close = 0;
256 return 0;
257}
258
259static ssize_t i8xx_tco_write (struct file *file, const char __user *data,
260 size_t len, loff_t * ppos)
261{
262 /* See if we got the magic character 'V' and reload the timer */
263 if (len) {
264 if (!nowayout) {
265 size_t i;
266
267 /* note: just in case someone wrote the magic character
268 * five months ago... */
269 tco_expect_close = 0;
270
271 /* scan to see whether or not we got the magic character */
272 for (i = 0; i != len; i++) {
273 char c;
274 if(get_user(c, data+i))
275 return -EFAULT;
276 if (c == 'V')
277 tco_expect_close = 42;
278 }
279 }
280
281 /* someone wrote to us, we should reload the timer */
282 tco_timer_keepalive ();
283 }
284 return len;
285}
286
287static int i8xx_tco_ioctl (struct inode *inode, struct file *file,
288 unsigned int cmd, unsigned long arg)
289{
290 int new_options, retval = -EINVAL;
291 int new_heartbeat;
292 int time_left;
293 void __user *argp = (void __user *)arg;
294 int __user *p = argp;
295 static struct watchdog_info ident = {
296 .options = WDIOF_SETTIMEOUT |
297 WDIOF_KEEPALIVEPING |
298 WDIOF_MAGICCLOSE,
299 .firmware_version = 0,
300 .identity = TCO_MODULE_NAME,
301 };
302
303 switch (cmd) {
304 case WDIOC_GETSUPPORT:
305 return copy_to_user(argp, &ident,
306 sizeof (ident)) ? -EFAULT : 0;
307
308 case WDIOC_GETSTATUS:
309 case WDIOC_GETBOOTSTATUS:
310 return put_user (0, p);
311
312 case WDIOC_KEEPALIVE:
313 tco_timer_keepalive ();
314 return 0;
315
316 case WDIOC_SETOPTIONS:
317 {
318 if (get_user (new_options, p))
319 return -EFAULT;
320
321 if (new_options & WDIOS_DISABLECARD) {
322 tco_timer_stop ();
323 retval = 0;
324 }
325
326 if (new_options & WDIOS_ENABLECARD) {
327 tco_timer_keepalive ();
328 tco_timer_start ();
329 retval = 0;
330 }
331
332 return retval;
333 }
334
335 case WDIOC_SETTIMEOUT:
336 {
337 if (get_user(new_heartbeat, p))
338 return -EFAULT;
339
340 if (tco_timer_set_heartbeat(new_heartbeat))
341 return -EINVAL;
342
343 tco_timer_keepalive ();
344 /* Fall */
345 }
346
347 case WDIOC_GETTIMEOUT:
348 return put_user(heartbeat, p);
349
350 case WDIOC_GETTIMELEFT:
351 {
352 if (tco_timer_get_timeleft(&time_left))
353 return -EINVAL;
354
355 return put_user(time_left, p);
356 }
357
358 default:
359 return -ENOTTY;
360 }
361}
362
363/*
364 * Notify system
365 */
366
367static int i8xx_tco_notify_sys (struct notifier_block *this, unsigned long code, void *unused)
368{
369 if (code==SYS_DOWN || code==SYS_HALT) {
370 /* Turn the WDT off */
371 tco_timer_stop ();
372 }
373
374 return NOTIFY_DONE;
375}
376
377/*
378 * Kernel Interfaces
379 */
380
381static const struct file_operations i8xx_tco_fops = {
382 .owner = THIS_MODULE,
383 .llseek = no_llseek,
384 .write = i8xx_tco_write,
385 .ioctl = i8xx_tco_ioctl,
386 .open = i8xx_tco_open,
387 .release = i8xx_tco_release,
388};
389
390static struct miscdevice i8xx_tco_miscdev = {
391 .minor = WATCHDOG_MINOR,
392 .name = "watchdog",
393 .fops = &i8xx_tco_fops,
394};
395
396static struct notifier_block i8xx_tco_notifier = {
397 .notifier_call = i8xx_tco_notify_sys,
398};
399
400/*
401 * Data for PCI driver interface
402 *
403 * This data only exists for exporting the supported
404 * PCI ids via MODULE_DEVICE_TABLE. We do not actually
405 * register a pci_driver, because someone else might one day
406 * want to register another driver on the same PCI id.
407 */
408static struct pci_device_id i8xx_tco_pci_tbl[] = {
409 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0) },
410 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0) },
411 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0) },
412 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10) },
413 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0) },
414 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12) },
415 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0) },
416 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12) },
417 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801E_0) },
418 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0) },
419 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1) },
420 { }, /* End of list */
421};
422MODULE_DEVICE_TABLE (pci, i8xx_tco_pci_tbl);
423
424/*
425 * Init & exit routines
426 */
427
428static unsigned char __init i8xx_tco_getdevice (void)
429{
430 struct pci_dev *dev = NULL;
431 u8 val1, val2;
432 u16 badr;
433 /*
434 * Find the PCI device
435 */
436
437 for_each_pci_dev(dev)
438 if (pci_match_id(i8xx_tco_pci_tbl, dev)) {
439 i8xx_tco_pci = dev;
440 break;
441 }
442
443 if (i8xx_tco_pci) {
444 /*
445 * Find the ACPI base I/O address which is the base
446 * for the TCO registers (TCOBASE=ACPIBASE + 0x60)
447 * ACPIBASE is bits [15:7] from 0x40-0x43
448 */
449 pci_read_config_byte (i8xx_tco_pci, 0x40, &val1);
450 pci_read_config_byte (i8xx_tco_pci, 0x41, &val2);
451 badr = ((val2 << 1) | (val1 >> 7)) << 7;
452 ACPIBASE = badr;
453 /* Something's wrong here, ACPIBASE has to be set */
454 if (badr == 0x0001 || badr == 0x0000) {
455 printk (KERN_ERR PFX "failed to get TCOBASE address\n");
456 pci_dev_put(i8xx_tco_pci);
457 return 0;
458 }
459
460 /* Check chipset's NO_REBOOT bit */
461 pci_read_config_byte (i8xx_tco_pci, 0xd4, &val1);
462 if (val1 & 0x02) {
463 val1 &= 0xfd;
464 pci_write_config_byte (i8xx_tco_pci, 0xd4, val1);
465 pci_read_config_byte (i8xx_tco_pci, 0xd4, &val1);
466 if (val1 & 0x02) {
467 printk (KERN_ERR PFX "failed to reset NO_REBOOT flag, reboot disabled by hardware\n");
468 pci_dev_put(i8xx_tco_pci);
469 return 0; /* Cannot reset NO_REBOOT bit */
470 }
471 }
472 /* Disable reboots untill the watchdog starts */
473 val1 |= 0x02;
474 pci_write_config_byte (i8xx_tco_pci, 0xd4, val1);
475
476 /* Set the TCO_EN bit in SMI_EN register */
477 if (!request_region (SMI_EN + 1, 1, "i8xx TCO")) {
478 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
479 SMI_EN + 1);
480 pci_dev_put(i8xx_tco_pci);
481 return 0;
482 }
483 val1 = inb (SMI_EN + 1);
484 val1 &= 0xdf;
485 outb (val1, SMI_EN + 1);
486 release_region (SMI_EN + 1, 1);
487 return 1;
488 }
489 return 0;
490}
491
492static int __init watchdog_init (void)
493{
494 int ret;
495
496 spin_lock_init(&tco_lock);
497
498 /* Check whether or not the hardware watchdog is there */
499 if (!i8xx_tco_getdevice () || i8xx_tco_pci == NULL)
500 return -ENODEV;
501
502 if (!request_region (TCOBASE, 0x10, "i8xx TCO")) {
503 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
504 TCOBASE);
505 ret = -EIO;
506 goto out;
507 }
508
509 /* Clear out the (probably old) status */
510 outb (0, TCO1_STS);
511 outb (3, TCO2_STS);
512
513 /* Check that the heartbeat value is within it's range ; if not reset to the default */
514 if (tco_timer_set_heartbeat (heartbeat)) {
515 heartbeat = WATCHDOG_HEARTBEAT;
516 tco_timer_set_heartbeat (heartbeat);
517 printk(KERN_INFO PFX "heartbeat value must be 2<heartbeat<39, using %d\n",
518 heartbeat);
519 }
520
521 ret = register_reboot_notifier(&i8xx_tco_notifier);
522 if (ret != 0) {
523 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
524 ret);
525 goto unreg_region;
526 }
527
528 ret = misc_register(&i8xx_tco_miscdev);
529 if (ret != 0) {
530 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
531 WATCHDOG_MINOR, ret);
532 goto unreg_notifier;
533 }
534
535 tco_timer_stop ();
536
537 printk (KERN_INFO PFX "initialized (0x%04x). heartbeat=%d sec (nowayout=%d)\n",
538 TCOBASE, heartbeat, nowayout);
539
540 return 0;
541
542unreg_notifier:
543 unregister_reboot_notifier(&i8xx_tco_notifier);
544unreg_region:
545 release_region (TCOBASE, 0x10);
546out:
547 pci_dev_put(i8xx_tco_pci);
548 return ret;
549}
550
551static void __exit watchdog_cleanup (void)
552{
553 /* Stop the timer before we leave */
554 if (!nowayout)
555 tco_timer_stop ();
556
557 /* Deregister */
558 misc_deregister (&i8xx_tco_miscdev);
559 unregister_reboot_notifier(&i8xx_tco_notifier);
560 release_region (TCOBASE, 0x10);
561
562 pci_dev_put(i8xx_tco_pci);
563}
564
565module_init(watchdog_init);
566module_exit(watchdog_cleanup);
567
568MODULE_AUTHOR("Nils Faerber");
569MODULE_DESCRIPTION("TCO timer driver for i8xx chipsets");
570MODULE_LICENSE("GPL");
571MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/char/watchdog/i8xx_tco.h b/drivers/char/watchdog/i8xx_tco.h
deleted file mode 100644
index cc14eb8ac3d6..000000000000
--- a/drivers/char/watchdog/i8xx_tco.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * i8xx_tco: TCO timer driver for i8xx chipsets
3 *
4 * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>, All Rights Reserved.
5 * http://www.kernelconcepts.de
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * Neither kernel concepts nor Nils Faerber admit liability nor provide
13 * warranty for any of this software. This material is provided
14 * "AS-IS" and at no charge.
15 *
16 * (c) Copyright 2000 kernel concepts <nils@kernelconcepts.de>
17 * developed for
18 * Jentro AG, Haar/Munich (Germany)
19 *
20 * TCO timer driver for i8xx chipsets
21 * based on softdog.c by Alan Cox <alan@redhat.com>
22 *
23 * For history and the complete list of supported I/O Controller Hub's
24 * see i8xx_tco.c
25 */
26
27
28/*
29 * Some address definitions for the TCO
30 */
31
32#define TCOBASE ACPIBASE + 0x60 /* TCO base address */
33#define TCO1_RLD TCOBASE + 0x00 /* TCO Timer Reload and Current Value */
34#define TCO1_TMR TCOBASE + 0x01 /* TCO Timer Initial Value */
35#define TCO1_DAT_IN TCOBASE + 0x02 /* TCO Data In Register */
36#define TCO1_DAT_OUT TCOBASE + 0x03 /* TCO Data Out Register */
37#define TCO1_STS TCOBASE + 0x04 /* TCO1 Status Register */
38#define TCO2_STS TCOBASE + 0x06 /* TCO2 Status Register */
39#define TCO1_CNT TCOBASE + 0x08 /* TCO1 Control Register */
40#define TCO2_CNT TCOBASE + 0x0a /* TCO2 Control Register */
41
42#define SMI_EN ACPIBASE + 0x30 /* SMI Control and Enable Register */
diff --git a/drivers/char/watchdog/iTCO_wdt.c b/drivers/char/watchdog/iTCO_wdt.c
index 3c9684ccd2f9..eac4f9b9f007 100644
--- a/drivers/char/watchdog/iTCO_wdt.c
+++ b/drivers/char/watchdog/iTCO_wdt.c
@@ -571,7 +571,7 @@ static int iTCO_wdt_init(struct pci_dev *pdev, const struct pci_device_id *ent,
571 * ACPIBASE is bits [15:7] from 0x40-0x43 571 * ACPIBASE is bits [15:7] from 0x40-0x43
572 */ 572 */
573 pci_read_config_dword(pdev, 0x40, &base_address); 573 pci_read_config_dword(pdev, 0x40, &base_address);
574 base_address &= 0x00007f80; 574 base_address &= 0x0000ff80;
575 if (base_address == 0x00000000) { 575 if (base_address == 0x00000000) {
576 /* Something's wrong here, ACPIBASE has to be set */ 576 /* Something's wrong here, ACPIBASE has to be set */
577 printk(KERN_ERR PFX "failed to get TCOBASE address\n"); 577 printk(KERN_ERR PFX "failed to get TCOBASE address\n");
diff --git a/drivers/char/watchdog/ibmasr.c b/drivers/char/watchdog/ibmasr.c
index 8195f5023d85..94155f6136c2 100644
--- a/drivers/char/watchdog/ibmasr.c
+++ b/drivers/char/watchdog/ibmasr.c
@@ -367,18 +367,17 @@ static int __init ibmasr_init(void)
367 if (!asr_type) 367 if (!asr_type)
368 return -ENODEV; 368 return -ENODEV;
369 369
370 rc = asr_get_base_address();
371 if (rc)
372 return rc;
373
370 rc = misc_register(&asr_miscdev); 374 rc = misc_register(&asr_miscdev);
371 if (rc < 0) { 375 if (rc < 0) {
376 release_region(asr_base, asr_length);
372 printk(KERN_ERR PFX "failed to register misc device\n"); 377 printk(KERN_ERR PFX "failed to register misc device\n");
373 return rc; 378 return rc;
374 } 379 }
375 380
376 rc = asr_get_base_address();
377 if (rc) {
378 misc_deregister(&asr_miscdev);
379 return rc;
380 }
381
382 return 0; 381 return 0;
383} 382}
384 383
diff --git a/drivers/char/watchdog/machzwd.c b/drivers/char/watchdog/machzwd.c
index 76c7fa37fa6c..a0d27160c80e 100644
--- a/drivers/char/watchdog/machzwd.c
+++ b/drivers/char/watchdog/machzwd.c
@@ -440,13 +440,6 @@ static int __init zf_init(void)
440 spin_lock_init(&zf_lock); 440 spin_lock_init(&zf_lock);
441 spin_lock_init(&zf_port_lock); 441 spin_lock_init(&zf_port_lock);
442 442
443 ret = misc_register(&zf_miscdev);
444 if (ret){
445 printk(KERN_ERR "can't misc_register on minor=%d\n",
446 WATCHDOG_MINOR);
447 goto out;
448 }
449
450 if(!request_region(ZF_IOBASE, 3, "MachZ ZFL WDT")){ 443 if(!request_region(ZF_IOBASE, 3, "MachZ ZFL WDT")){
451 printk(KERN_ERR "cannot reserve I/O ports at %d\n", 444 printk(KERN_ERR "cannot reserve I/O ports at %d\n",
452 ZF_IOBASE); 445 ZF_IOBASE);
@@ -461,16 +454,23 @@ static int __init zf_init(void)
461 goto no_reboot; 454 goto no_reboot;
462 } 455 }
463 456
457 ret = misc_register(&zf_miscdev);
458 if (ret){
459 printk(KERN_ERR "can't misc_register on minor=%d\n",
460 WATCHDOG_MINOR);
461 goto no_misc;
462 }
463
464 zf_set_status(0); 464 zf_set_status(0);
465 zf_set_control(0); 465 zf_set_control(0);
466 466
467 return 0; 467 return 0;
468 468
469no_misc:
470 unregister_reboot_notifier(&zf_notifier);
469no_reboot: 471no_reboot:
470 release_region(ZF_IOBASE, 3); 472 release_region(ZF_IOBASE, 3);
471no_region: 473no_region:
472 misc_deregister(&zf_miscdev);
473out:
474 return ret; 474 return ret;
475} 475}
476 476
diff --git a/drivers/char/watchdog/mtx-1_wdt.c b/drivers/char/watchdog/mtx-1_wdt.c
new file mode 100644
index 000000000000..419ab445c944
--- /dev/null
+++ b/drivers/char/watchdog/mtx-1_wdt.c
@@ -0,0 +1,238 @@
1/*
2 * Driver for the MTX-1 Watchdog.
3 *
4 * (C) Copyright 2005 4G Systems <info@4g-systems.biz>, All Rights Reserved.
5 * http://www.4g-systems.biz
6 *
7 * (C) Copyright 2007 OpenWrt.org, Florian Fainelli <florian@openwrt.org>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 *
14 * Neither Michael Stickel nor 4G Systems admit liability nor provide
15 * warranty for any of this software. This material is provided
16 * "AS-IS" and at no charge.
17 *
18 * (c) Copyright 2005 4G Systems <info@4g-systems.biz>
19 *
20 * Release 0.01.
21 * Author: Michael Stickel michael.stickel@4g-systems.biz
22 *
23 * Release 0.02.
24 * Author: Florian Fainelli florian@openwrt.org
25 * use the Linux watchdog/timer APIs
26 *
27 * The Watchdog is configured to reset the MTX-1
28 * if it is not triggered for 100 seconds.
29 * It should not be triggered more often than 1.6 seconds.
30 *
31 * A timer triggers the watchdog every 5 seconds, until
32 * it is opened for the first time. After the first open
33 * it MUST be triggered every 2..95 seconds.
34 */
35
36#include <linux/module.h>
37#include <linux/moduleparam.h>
38#include <linux/types.h>
39#include <linux/errno.h>
40#include <linux/miscdevice.h>
41#include <linux/fs.h>
42#include <linux/init.h>
43#include <linux/ioport.h>
44#include <linux/timer.h>
45#include <linux/completion.h>
46#include <linux/jiffies.h>
47#include <linux/watchdog.h>
48#include <asm/io.h>
49#include <asm/uaccess.h>
50
51#include <asm/mach-au1x00/au1000.h>
52
53#define MTX1_WDT_INTERVAL (5 * HZ)
54
55static int ticks = 100 * HZ;
56
57static struct {
58 struct completion stop;
59 volatile int running;
60 struct timer_list timer;
61 volatile int queue;
62 int default_ticks;
63 unsigned long inuse;
64} mtx1_wdt_device;
65
66static void mtx1_wdt_trigger(unsigned long unused)
67{
68 u32 tmp;
69
70 if (mtx1_wdt_device.running)
71 ticks--;
72 /*
73 * toggle GPIO2_15
74 */
75 tmp = au_readl(GPIO2_DIR);
76 tmp = (tmp & ~(1<<15)) | ((~tmp) & (1<<15));
77 au_writel (tmp, GPIO2_DIR);
78
79 if (mtx1_wdt_device.queue && ticks)
80 mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL);
81 else {
82 complete(&mtx1_wdt_device.stop);
83 }
84}
85
86static void mtx1_wdt_reset(void)
87{
88 ticks = mtx1_wdt_device.default_ticks;
89}
90
91
92static void mtx1_wdt_start(void)
93{
94 if (!mtx1_wdt_device.queue) {
95 mtx1_wdt_device.queue = 1;
96 au_writel (au_readl(GPIO2_DIR) | (u32)(1<<15), GPIO2_DIR);
97 mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL);
98 }
99 mtx1_wdt_device.running++;
100}
101
102static int mtx1_wdt_stop(void)
103{
104 if (mtx1_wdt_device.queue) {
105 mtx1_wdt_device.queue = 0;
106 au_writel (au_readl(GPIO2_DIR) & ~((u32)(1<<15)), GPIO2_DIR);
107 }
108
109 ticks = mtx1_wdt_device.default_ticks;
110
111 return 0;
112}
113
114/* Filesystem functions */
115
116static int mtx1_wdt_open(struct inode *inode, struct file *file)
117{
118 if (test_and_set_bit(0, &mtx1_wdt_device.inuse))
119 return -EBUSY;
120
121 return nonseekable_open(inode, file);
122}
123
124
125static int mtx1_wdt_release(struct inode *inode, struct file *file)
126{
127 clear_bit(0, &mtx1_wdt_device.inuse);
128 return 0;
129}
130
131static int mtx1_wdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
132{
133 void __user *argp = (void __user *)arg;
134 unsigned int value;
135 static struct watchdog_info ident =
136 {
137 .options = WDIOF_CARDRESET,
138 .identity = "MTX-1 WDT",
139 };
140
141 switch(cmd) {
142 case WDIOC_KEEPALIVE:
143 mtx1_wdt_reset();
144 break;
145 case WDIOC_GETSTATUS:
146 if ( copy_to_user(argp, &value, sizeof(int)) )
147 return -EFAULT;
148 break;
149 case WDIOC_GETSUPPORT:
150 if ( copy_to_user(argp, &ident, sizeof(ident)) )
151 return -EFAULT;
152 break;
153 case WDIOC_SETOPTIONS:
154 if ( copy_from_user(&value, argp, sizeof(int)) )
155 return -EFAULT;
156 switch(value) {
157 case WDIOS_ENABLECARD:
158 mtx1_wdt_start();
159 break;
160 case WDIOS_DISABLECARD:
161 return mtx1_wdt_stop();
162 default:
163 return -EINVAL;
164 }
165 break;
166 default:
167 return -ENOTTY;
168 }
169 return 0;
170}
171
172
173static ssize_t mtx1_wdt_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
174{
175 if (!count)
176 return -EIO;
177
178 mtx1_wdt_reset();
179 return count;
180}
181
182static struct file_operations mtx1_wdt_fops = {
183 .owner = THIS_MODULE,
184 .llseek = no_llseek,
185 .ioctl = mtx1_wdt_ioctl,
186 .open = mtx1_wdt_open,
187 .write = mtx1_wdt_write,
188 .release = mtx1_wdt_release
189};
190
191
192static struct miscdevice mtx1_wdt_misc = {
193 .minor = WATCHDOG_MINOR,
194 .name = "watchdog",
195 .fops = &mtx1_wdt_fops
196};
197
198
199static int __init mtx1_wdt_init(void)
200{
201 int ret;
202
203 if ((ret = misc_register(&mtx1_wdt_misc)) < 0) {
204 printk(KERN_ERR " mtx-1_wdt : failed to register\n");
205 return ret;
206 }
207
208 init_completion(&mtx1_wdt_device.stop);
209 mtx1_wdt_device.queue = 0;
210
211 clear_bit(0, &mtx1_wdt_device.inuse);
212
213 setup_timer(&mtx1_wdt_device.timer, mtx1_wdt_trigger, 0L);
214
215 mtx1_wdt_device.default_ticks = ticks;
216
217 mtx1_wdt_start();
218
219 printk(KERN_INFO "MTX-1 Watchdog driver\n");
220
221 return 0;
222}
223
224static void __exit mtx1_wdt_exit(void)
225{
226 if (mtx1_wdt_device.queue) {
227 mtx1_wdt_device.queue = 0;
228 wait_for_completion(&mtx1_wdt_device.stop);
229 }
230 misc_deregister(&mtx1_wdt_misc);
231}
232
233module_init(mtx1_wdt_init);
234module_exit(mtx1_wdt_exit);
235
236MODULE_AUTHOR("Michael Stickel, Florian Fainelli");
237MODULE_DESCRIPTION("Driver for the MTX-1 watchdog");
238MODULE_LICENSE("GPL");
diff --git a/drivers/char/watchdog/omap_wdt.c b/drivers/char/watchdog/omap_wdt.c
index 84074a697dce..b36fa8de2131 100644
--- a/drivers/char/watchdog/omap_wdt.c
+++ b/drivers/char/watchdog/omap_wdt.c
@@ -34,7 +34,6 @@
34#include <linux/miscdevice.h> 34#include <linux/miscdevice.h>
35#include <linux/watchdog.h> 35#include <linux/watchdog.h>
36#include <linux/reboot.h> 36#include <linux/reboot.h>
37#include <linux/smp_lock.h>
38#include <linux/init.h> 37#include <linux/init.h>
39#include <linux/err.h> 38#include <linux/err.h>
40#include <linux/platform_device.h> 39#include <linux/platform_device.h>
diff --git a/drivers/char/watchdog/pcwd.c b/drivers/char/watchdog/pcwd.c
index 6e8b5705b5b7..7b41434fac8c 100644
--- a/drivers/char/watchdog/pcwd.c
+++ b/drivers/char/watchdog/pcwd.c
@@ -59,10 +59,10 @@
59#include <linux/jiffies.h> /* For jiffies stuff */ 59#include <linux/jiffies.h> /* For jiffies stuff */
60#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */ 60#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
61#include <linux/watchdog.h> /* For the watchdog specific items */ 61#include <linux/watchdog.h> /* For the watchdog specific items */
62#include <linux/notifier.h> /* For notifier support */ 62#include <linux/reboot.h> /* For kernel_power_off() */
63#include <linux/reboot.h> /* For reboot_notifier stuff */
64#include <linux/init.h> /* For __init/__exit/... */ 63#include <linux/init.h> /* For __init/__exit/... */
65#include <linux/fs.h> /* For file operations */ 64#include <linux/fs.h> /* For file operations */
65#include <linux/isa.h> /* For isa devices */
66#include <linux/ioport.h> /* For io-port access */ 66#include <linux/ioport.h> /* For io-port access */
67#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */ 67#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
68 68
@@ -70,8 +70,8 @@
70#include <asm/io.h> /* For inb/outb/... */ 70#include <asm/io.h> /* For inb/outb/... */
71 71
72/* Module and version information */ 72/* Module and version information */
73#define WATCHDOG_VERSION "1.18" 73#define WATCHDOG_VERSION "1.20"
74#define WATCHDOG_DATE "21 Jan 2007" 74#define WATCHDOG_DATE "18 Feb 2007"
75#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog" 75#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog"
76#define WATCHDOG_NAME "pcwd" 76#define WATCHDOG_NAME "pcwd"
77#define PFX WATCHDOG_NAME ": " 77#define PFX WATCHDOG_NAME ": "
@@ -89,6 +89,15 @@
89#define PCWD_REVISION_C 2 89#define PCWD_REVISION_C 2
90 90
91/* 91/*
92 * These are the auto-probe addresses available.
93 *
94 * Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350.
95 * Revision A has an address range of 2 addresses, while Revision C has 4.
96 */
97#define PCWD_ISA_NR_CARDS 3
98static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
99
100/*
92 * These are the defines that describe the control status bits for the 101 * These are the defines that describe the control status bits for the
93 * PCI-PC Watchdog card. 102 * PCI-PC Watchdog card.
94*/ 103*/
@@ -485,7 +494,7 @@ static int pcwd_get_status(int *status)
485 if (control_status & WD_T110) { 494 if (control_status & WD_T110) {
486 *status |= WDIOF_OVERHEAT; 495 *status |= WDIOF_OVERHEAT;
487 if (temp_panic) { 496 if (temp_panic) {
488 printk (KERN_INFO PFX "Temperature overheat trip!\n"); 497 printk(KERN_INFO PFX "Temperature overheat trip!\n");
489 kernel_power_off(); 498 kernel_power_off();
490 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */ 499 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
491 } 500 }
@@ -497,7 +506,7 @@ static int pcwd_get_status(int *status)
497 if (control_status & WD_REVC_TTRP) { 506 if (control_status & WD_REVC_TTRP) {
498 *status |= WDIOF_OVERHEAT; 507 *status |= WDIOF_OVERHEAT;
499 if (temp_panic) { 508 if (temp_panic) {
500 printk (KERN_INFO PFX "Temperature overheat trip!\n"); 509 printk(KERN_INFO PFX "Temperature overheat trip!\n");
501 kernel_power_off(); 510 kernel_power_off();
502 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */ 511 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
503 } 512 }
@@ -734,20 +743,6 @@ static int pcwd_temp_close(struct inode *inode, struct file *file)
734} 743}
735 744
736/* 745/*
737 * Notify system
738 */
739
740static int pcwd_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
741{
742 if (code==SYS_DOWN || code==SYS_HALT) {
743 /* Turn the WDT off */
744 pcwd_stop();
745 }
746
747 return NOTIFY_DONE;
748}
749
750/*
751 * Kernel Interfaces 746 * Kernel Interfaces
752 */ 747 */
753 748
@@ -780,10 +775,6 @@ static struct miscdevice temp_miscdev = {
780 .fops = &pcwd_temp_fops, 775 .fops = &pcwd_temp_fops,
781}; 776};
782 777
783static struct notifier_block pcwd_notifier = {
784 .notifier_call = pcwd_notify_sys,
785};
786
787/* 778/*
788 * Init & exit routines 779 * Init & exit routines
789 */ 780 */
@@ -803,10 +794,67 @@ static inline int get_revision(void)
803 return r; 794 return r;
804} 795}
805 796
806static int __devinit pcwatchdog_init(int base_addr) 797/*
798 * The ISA cards have a heartbeat bit in one of the registers, which
799 * register is card dependent. The heartbeat bit is monitored, and if
800 * found, is considered proof that a Berkshire card has been found.
801 * The initial rate is once per second at board start up, then twice
802 * per second for normal operation.
803 */
804static int __devinit pcwd_isa_match(struct device *dev, unsigned int id)
805{
806 int base_addr=pcwd_ioports[id];
807 int port0, last_port0; /* Reg 0, in case it's REV A */
808 int port1, last_port1; /* Register 1 for REV C cards */
809 int i;
810 int retval;
811
812 if (debug >= DEBUG)
813 printk(KERN_DEBUG PFX "pcwd_isa_match id=%d\n",
814 id);
815
816 if (!request_region (base_addr, 4, "PCWD")) {
817 printk(KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
818 return 0;
819 }
820
821 retval = 0;
822
823 port0 = inb_p(base_addr); /* For REV A boards */
824 port1 = inb_p(base_addr + 1); /* For REV C boards */
825 if (port0 != 0xff || port1 != 0xff) {
826 /* Not an 'ff' from a floating bus, so must be a card! */
827 for (i = 0; i < 4; ++i) {
828
829 msleep(500);
830
831 last_port0 = port0;
832 last_port1 = port1;
833
834 port0 = inb_p(base_addr);
835 port1 = inb_p(base_addr + 1);
836
837 /* Has either hearbeat bit changed? */
838 if ((port0 ^ last_port0) & WD_HRTBT ||
839 (port1 ^ last_port1) & WD_REVC_HRBT) {
840 retval = 1;
841 break;
842 }
843 }
844 }
845 release_region (base_addr, 4);
846
847 return retval;
848}
849
850static int __devinit pcwd_isa_probe(struct device *dev, unsigned int id)
807{ 851{
808 int ret; 852 int ret;
809 853
854 if (debug >= DEBUG)
855 printk(KERN_DEBUG PFX "pcwd_isa_probe id=%d\n",
856 id);
857
810 cards_found++; 858 cards_found++;
811 if (cards_found == 1) 859 if (cards_found == 1)
812 printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER); 860 printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
@@ -816,11 +864,13 @@ static int __devinit pcwatchdog_init(int base_addr)
816 return -ENODEV; 864 return -ENODEV;
817 } 865 }
818 866
819 if (base_addr == 0x0000) { 867 if (pcwd_ioports[id] == 0x0000) {
820 printk(KERN_ERR PFX "No I/O-Address for card detected\n"); 868 printk(KERN_ERR PFX "No I/O-Address for card detected\n");
821 return -ENODEV; 869 return -ENODEV;
822 } 870 }
823 pcwd_private.io_addr = base_addr; 871 pcwd_private.io_addr = pcwd_ioports[id];
872
873 spin_lock_init(&pcwd_private.io_lock);
824 874
825 /* Check card's revision */ 875 /* Check card's revision */
826 pcwd_private.revision = get_revision(); 876 pcwd_private.revision = get_revision();
@@ -828,8 +878,8 @@ static int __devinit pcwatchdog_init(int base_addr)
828 if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) { 878 if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
829 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", 879 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
830 pcwd_private.io_addr); 880 pcwd_private.io_addr);
831 pcwd_private.io_addr = 0x0000; 881 ret=-EIO;
832 return -EIO; 882 goto error_request_region;
833 } 883 }
834 884
835 /* Initial variables */ 885 /* Initial variables */
@@ -865,24 +915,12 @@ static int __devinit pcwatchdog_init(int base_addr)
865 WATCHDOG_HEARTBEAT); 915 WATCHDOG_HEARTBEAT);
866 } 916 }
867 917
868 ret = register_reboot_notifier(&pcwd_notifier);
869 if (ret) {
870 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
871 ret);
872 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
873 pcwd_private.io_addr = 0x0000;
874 return ret;
875 }
876
877 if (pcwd_private.supports_temp) { 918 if (pcwd_private.supports_temp) {
878 ret = misc_register(&temp_miscdev); 919 ret = misc_register(&temp_miscdev);
879 if (ret) { 920 if (ret) {
880 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", 921 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
881 TEMP_MINOR, ret); 922 TEMP_MINOR, ret);
882 unregister_reboot_notifier(&pcwd_notifier); 923 goto error_misc_register_temp;
883 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
884 pcwd_private.io_addr = 0x0000;
885 return ret;
886 } 924 }
887 } 925 }
888 926
@@ -890,22 +928,34 @@ static int __devinit pcwatchdog_init(int base_addr)
890 if (ret) { 928 if (ret) {
891 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", 929 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
892 WATCHDOG_MINOR, ret); 930 WATCHDOG_MINOR, ret);
893 if (pcwd_private.supports_temp) 931 goto error_misc_register_watchdog;
894 misc_deregister(&temp_miscdev);
895 unregister_reboot_notifier(&pcwd_notifier);
896 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
897 pcwd_private.io_addr = 0x0000;
898 return ret;
899 } 932 }
900 933
901 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n", 934 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
902 heartbeat, nowayout); 935 heartbeat, nowayout);
903 936
904 return 0; 937 return 0;
938
939error_misc_register_watchdog:
940 if (pcwd_private.supports_temp)
941 misc_deregister(&temp_miscdev);
942error_misc_register_temp:
943 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
944error_request_region:
945 pcwd_private.io_addr = 0x0000;
946 cards_found--;
947 return ret;
905} 948}
906 949
907static void __devexit pcwatchdog_exit(void) 950static int __devexit pcwd_isa_remove(struct device *dev, unsigned int id)
908{ 951{
952 if (debug >= DEBUG)
953 printk(KERN_DEBUG PFX "pcwd_isa_remove id=%d\n",
954 id);
955
956 if (!pcwd_private.io_addr)
957 return 1;
958
909 /* Disable the board */ 959 /* Disable the board */
910 if (!nowayout) 960 if (!nowayout)
911 pcwd_stop(); 961 pcwd_stop();
@@ -914,102 +964,50 @@ static void __devexit pcwatchdog_exit(void)
914 misc_deregister(&pcwd_miscdev); 964 misc_deregister(&pcwd_miscdev);
915 if (pcwd_private.supports_temp) 965 if (pcwd_private.supports_temp)
916 misc_deregister(&temp_miscdev); 966 misc_deregister(&temp_miscdev);
917 unregister_reboot_notifier(&pcwd_notifier);
918 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); 967 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
919 pcwd_private.io_addr = 0x0000; 968 pcwd_private.io_addr = 0x0000;
920 cards_found--; 969 cards_found--;
970
971 return 0;
921} 972}
922 973
923/* 974static void pcwd_isa_shutdown(struct device *dev, unsigned int id)
924 * The ISA cards have a heartbeat bit in one of the registers, which
925 * register is card dependent. The heartbeat bit is monitored, and if
926 * found, is considered proof that a Berkshire card has been found.
927 * The initial rate is once per second at board start up, then twice
928 * per second for normal operation.
929 */
930static int __init pcwd_checkcard(int base_addr)
931{ 975{
932 int port0, last_port0; /* Reg 0, in case it's REV A */ 976 if (debug >= DEBUG)
933 int port1, last_port1; /* Register 1 for REV C cards */ 977 printk(KERN_DEBUG PFX "pcwd_isa_shutdown id=%d\n",
934 int i; 978 id);
935 int retval;
936
937 if (!request_region (base_addr, 4, "PCWD")) {
938 printk (KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
939 return 0;
940 }
941
942 retval = 0;
943
944 port0 = inb_p(base_addr); /* For REV A boards */
945 port1 = inb_p(base_addr + 1); /* For REV C boards */
946 if (port0 != 0xff || port1 != 0xff) {
947 /* Not an 'ff' from a floating bus, so must be a card! */
948 for (i = 0; i < 4; ++i) {
949
950 msleep(500);
951
952 last_port0 = port0;
953 last_port1 = port1;
954
955 port0 = inb_p(base_addr);
956 port1 = inb_p(base_addr + 1);
957
958 /* Has either hearbeat bit changed? */
959 if ((port0 ^ last_port0) & WD_HRTBT ||
960 (port1 ^ last_port1) & WD_REVC_HRBT) {
961 retval = 1;
962 break;
963 }
964 }
965 }
966 release_region (base_addr, 4);
967 979
968 return retval; 980 pcwd_stop();
969} 981}
970 982
971/* 983static struct isa_driver pcwd_isa_driver = {
972 * These are the auto-probe addresses available. 984 .match = pcwd_isa_match,
973 * 985 .probe = pcwd_isa_probe,
974 * Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350. 986 .remove = __devexit_p(pcwd_isa_remove),
975 * Revision A has an address range of 2 addresses, while Revision C has 4. 987 .shutdown = pcwd_isa_shutdown,
976 */ 988 .driver = {
977static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 }; 989 .owner = THIS_MODULE,
990 .name = WATCHDOG_NAME,
991 },
992};
978 993
979static int __init pcwd_init_module(void) 994static int __init pcwd_init_module(void)
980{ 995{
981 int i, found = 0; 996 return isa_register_driver(&pcwd_isa_driver, PCWD_ISA_NR_CARDS);
982
983 spin_lock_init(&pcwd_private.io_lock);
984
985 for (i = 0; pcwd_ioports[i] != 0; i++) {
986 if (pcwd_checkcard(pcwd_ioports[i])) {
987 if (!(pcwatchdog_init(pcwd_ioports[i])))
988 found++;
989 }
990 }
991
992 if (!found) {
993 printk (KERN_INFO PFX "No card detected, or port not available\n");
994 return -ENODEV;
995 }
996
997 return 0;
998} 997}
999 998
1000static void __exit pcwd_cleanup_module(void) 999static void __exit pcwd_cleanup_module(void)
1001{ 1000{
1002 if (pcwd_private.io_addr) 1001 isa_unregister_driver(&pcwd_isa_driver);
1003 pcwatchdog_exit();
1004
1005 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n"); 1002 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
1006} 1003}
1007 1004
1008module_init(pcwd_init_module); 1005module_init(pcwd_init_module);
1009module_exit(pcwd_cleanup_module); 1006module_exit(pcwd_cleanup_module);
1010 1007
1011MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>"); 1008MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, Wim Van Sebroeck <wim@iguana.be>");
1012MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver"); 1009MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
1010MODULE_VERSION(WATCHDOG_VERSION);
1013MODULE_LICENSE("GPL"); 1011MODULE_LICENSE("GPL");
1014MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); 1012MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
1015MODULE_ALIAS_MISCDEV(TEMP_MINOR); 1013MODULE_ALIAS_MISCDEV(TEMP_MINOR);
diff --git a/drivers/char/watchdog/pcwd_usb.c b/drivers/char/watchdog/pcwd_usb.c
index 31037f9c9ffe..1e7a6719d5ba 100644
--- a/drivers/char/watchdog/pcwd_usb.c
+++ b/drivers/char/watchdog/pcwd_usb.c
@@ -146,7 +146,7 @@ struct usb_pcwd_private {
146 atomic_t cmd_received; /* true if we received a report after a command */ 146 atomic_t cmd_received; /* true if we received a report after a command */
147 147
148 int exists; /* Wether or not the device exists */ 148 int exists; /* Wether or not the device exists */
149 struct semaphore sem; /* locks this structure */ 149 struct mutex mtx; /* locks this structure */
150}; 150};
151static struct usb_pcwd_private *usb_pcwd_device; 151static struct usb_pcwd_private *usb_pcwd_device;
152 152
@@ -635,7 +635,7 @@ static int usb_pcwd_probe(struct usb_interface *interface, const struct usb_devi
635 635
636 usb_pcwd_device = usb_pcwd; 636 usb_pcwd_device = usb_pcwd;
637 637
638 init_MUTEX (&usb_pcwd->sem); 638 mutex_init(&usb_pcwd->mtx);
639 usb_pcwd->udev = udev; 639 usb_pcwd->udev = udev;
640 usb_pcwd->interface = interface; 640 usb_pcwd->interface = interface;
641 usb_pcwd->interface_number = iface_desc->desc.bInterfaceNumber; 641 usb_pcwd->interface_number = iface_desc->desc.bInterfaceNumber;
@@ -763,7 +763,7 @@ static void usb_pcwd_disconnect(struct usb_interface *interface)
763 usb_pcwd = usb_get_intfdata (interface); 763 usb_pcwd = usb_get_intfdata (interface);
764 usb_set_intfdata (interface, NULL); 764 usb_set_intfdata (interface, NULL);
765 765
766 down (&usb_pcwd->sem); 766 mutex_lock(&usb_pcwd->mtx);
767 767
768 /* Stop the timer before we leave */ 768 /* Stop the timer before we leave */
769 if (!nowayout) 769 if (!nowayout)
@@ -777,7 +777,7 @@ static void usb_pcwd_disconnect(struct usb_interface *interface)
777 misc_deregister(&usb_pcwd_temperature_miscdev); 777 misc_deregister(&usb_pcwd_temperature_miscdev);
778 unregister_reboot_notifier(&usb_pcwd_notifier); 778 unregister_reboot_notifier(&usb_pcwd_notifier);
779 779
780 up (&usb_pcwd->sem); 780 mutex_unlock(&usb_pcwd->mtx);
781 781
782 /* Delete the USB PCWD device */ 782 /* Delete the USB PCWD device */
783 usb_pcwd_delete(usb_pcwd); 783 usb_pcwd_delete(usb_pcwd);
diff --git a/drivers/char/watchdog/s3c2410_wdt.c b/drivers/char/watchdog/s3c2410_wdt.c
index dff6cb5dc9a7..20fa29ca7404 100644
--- a/drivers/char/watchdog/s3c2410_wdt.c
+++ b/drivers/char/watchdog/s3c2410_wdt.c
@@ -379,14 +379,14 @@ static int s3c2410wdt_probe(struct platform_device *pdev)
379 379
380 DBG("probe: mapped wdt_base=%p\n", wdt_base); 380 DBG("probe: mapped wdt_base=%p\n", wdt_base);
381 381
382 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 382 wdt_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
383 if (res == NULL) { 383 if (wdt_irq == NULL) {
384 printk(KERN_INFO PFX "failed to get irq resource\n"); 384 printk(KERN_INFO PFX "failed to get irq resource\n");
385 ret = -ENOENT; 385 ret = -ENOENT;
386 goto err_map; 386 goto err_map;
387 } 387 }
388 388
389 ret = request_irq(res->start, s3c2410wdt_irq, 0, pdev->name, pdev); 389 ret = request_irq(wdt_irq->start, s3c2410wdt_irq, 0, pdev->name, pdev);
390 if (ret != 0) { 390 if (ret != 0) {
391 printk(KERN_INFO PFX "failed to install irq (%d)\n", ret); 391 printk(KERN_INFO PFX "failed to install irq (%d)\n", ret);
392 goto err_map; 392 goto err_map;
diff --git a/drivers/char/watchdog/sbc8360.c b/drivers/char/watchdog/sbc8360.c
index 67ae42685e75..285d85289532 100644
--- a/drivers/char/watchdog/sbc8360.c
+++ b/drivers/char/watchdog/sbc8360.c
@@ -333,18 +333,17 @@ static int __init sbc8360_init(void)
333 int res; 333 int res;
334 unsigned long int mseconds = 60000; 334 unsigned long int mseconds = 60000;
335 335
336 spin_lock_init(&sbc8360_lock); 336 if (timeout < 0 || timeout > 63) {
337 res = misc_register(&sbc8360_miscdev); 337 printk(KERN_ERR PFX "Invalid timeout index (must be 0-63).\n");
338 if (res) { 338 res = -EINVAL;
339 printk(KERN_ERR PFX "failed to register misc device\n"); 339 goto out;
340 goto out_nomisc;
341 } 340 }
342 341
343 if (!request_region(SBC8360_ENABLE, 1, "SBC8360")) { 342 if (!request_region(SBC8360_ENABLE, 1, "SBC8360")) {
344 printk(KERN_ERR PFX "ENABLE method I/O %X is not available.\n", 343 printk(KERN_ERR PFX "ENABLE method I/O %X is not available.\n",
345 SBC8360_ENABLE); 344 SBC8360_ENABLE);
346 res = -EIO; 345 res = -EIO;
347 goto out_noenablereg; 346 goto out;
348 } 347 }
349 if (!request_region(SBC8360_BASETIME, 1, "SBC8360")) { 348 if (!request_region(SBC8360_BASETIME, 1, "SBC8360")) {
350 printk(KERN_ERR PFX 349 printk(KERN_ERR PFX
@@ -360,10 +359,11 @@ static int __init sbc8360_init(void)
360 goto out_noreboot; 359 goto out_noreboot;
361 } 360 }
362 361
363 if (timeout < 0 || timeout > 63) { 362 spin_lock_init(&sbc8360_lock);
364 printk(KERN_ERR PFX "Invalid timeout index (must be 0-63).\n"); 363 res = misc_register(&sbc8360_miscdev);
365 res = -EINVAL; 364 if (res) {
366 goto out_noreboot; 365 printk(KERN_ERR PFX "failed to register misc device\n");
366 goto out_nomisc;
367 } 367 }
368 368
369 wd_margin = wd_times[timeout][0]; 369 wd_margin = wd_times[timeout][0];
@@ -383,13 +383,13 @@ static int __init sbc8360_init(void)
383 383
384 return 0; 384 return 0;
385 385
386 out_nomisc:
387 unregister_reboot_notifier(&sbc8360_notifier);
386 out_noreboot: 388 out_noreboot:
387 release_region(SBC8360_ENABLE, 1);
388 release_region(SBC8360_BASETIME, 1); 389 release_region(SBC8360_BASETIME, 1);
389 out_noenablereg:
390 out_nobasetimereg: 390 out_nobasetimereg:
391 misc_deregister(&sbc8360_miscdev); 391 release_region(SBC8360_ENABLE, 1);
392 out_nomisc: 392 out:
393 return res; 393 return res;
394} 394}
395 395
diff --git a/drivers/char/watchdog/w83627hf_wdt.c b/drivers/char/watchdog/w83627hf_wdt.c
index 337ee42c90dd..b46e7f47d705 100644
--- a/drivers/char/watchdog/w83627hf_wdt.c
+++ b/drivers/char/watchdog/w83627hf_wdt.c
@@ -1,5 +1,8 @@
1/* 1/*
2 * w83627hf WDT driver 2 * w83627hf/thf WDT driver
3 *
4 * (c) Copyright 2007 Vlad Drukker <vlad@storewiz.com>
5 * added support for W83627THF.
3 * 6 *
4 * (c) Copyright 2003 Pádraig Brady <P@draigBrady.com> 7 * (c) Copyright 2003 Pádraig Brady <P@draigBrady.com>
5 * 8 *
@@ -39,7 +42,7 @@
39#include <asm/uaccess.h> 42#include <asm/uaccess.h>
40#include <asm/system.h> 43#include <asm/system.h>
41 44
42#define WATCHDOG_NAME "w83627hf WDT" 45#define WATCHDOG_NAME "w83627hf/thf WDT"
43#define PFX WATCHDOG_NAME ": " 46#define PFX WATCHDOG_NAME ": "
44#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */ 47#define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */
45 48
@@ -50,7 +53,7 @@ static spinlock_t io_lock;
50/* You must set this - there is no sane way to probe for this board. */ 53/* You must set this - there is no sane way to probe for this board. */
51static int wdt_io = 0x2E; 54static int wdt_io = 0x2E;
52module_param(wdt_io, int, 0); 55module_param(wdt_io, int, 0);
53MODULE_PARM_DESC(wdt_io, "w83627hf WDT io port (default 0x2E)"); 56MODULE_PARM_DESC(wdt_io, "w83627hf/thf WDT io port (default 0x2E)");
54 57
55static int timeout = WATCHDOG_TIMEOUT; /* in seconds */ 58static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
56module_param(timeout, int, 0); 59module_param(timeout, int, 0);
@@ -71,9 +74,19 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" _
71static void 74static void
72w83627hf_select_wd_register(void) 75w83627hf_select_wd_register(void)
73{ 76{
77 unsigned char c;
74 outb_p(0x87, WDT_EFER); /* Enter extended function mode */ 78 outb_p(0x87, WDT_EFER); /* Enter extended function mode */
75 outb_p(0x87, WDT_EFER); /* Again according to manual */ 79 outb_p(0x87, WDT_EFER); /* Again according to manual */
76 80
81 outb(0x20, WDT_EFER); /* check chip version */
82 c = inb(WDT_EFDR);
83 if (c == 0x82) { /* W83627THF */
84 outb_p(0x2b, WDT_EFER); /* select GPIO3 */
85 c = ((inb_p(WDT_EFDR) & 0xf7) | 0x04); /* select WDT0 */
86 outb_p(0x2b, WDT_EFER);
87 outb_p(c, WDT_EFDR); /* set GPIO3 to WDT0 */
88 }
89
77 outb_p(0x07, WDT_EFER); /* point to logical device number reg */ 90 outb_p(0x07, WDT_EFER); /* point to logical device number reg */
78 outb_p(0x08, WDT_EFDR); /* select logical device 8 (GPIO2) */ 91 outb_p(0x08, WDT_EFDR); /* select logical device 8 (GPIO2) */
79 outb_p(0x30, WDT_EFER); /* select CR30 */ 92 outb_p(0x30, WDT_EFER); /* select CR30 */
@@ -311,7 +324,7 @@ wdt_init(void)
311 324
312 spin_lock_init(&io_lock); 325 spin_lock_init(&io_lock);
313 326
314 printk(KERN_INFO "WDT driver for the Winbond(TM) W83627HF Super I/O chip initialising.\n"); 327 printk(KERN_INFO "WDT driver for the Winbond(TM) W83627HF/THF Super I/O chip initialising.\n");
315 328
316 if (wdt_set_heartbeat(timeout)) { 329 if (wdt_set_heartbeat(timeout)) {
317 wdt_set_heartbeat(WATCHDOG_TIMEOUT); 330 wdt_set_heartbeat(WATCHDOG_TIMEOUT);
@@ -367,5 +380,5 @@ module_exit(wdt_exit);
367 380
368MODULE_LICENSE("GPL"); 381MODULE_LICENSE("GPL");
369MODULE_AUTHOR("Pádraig Brady <P@draigBrady.com>"); 382MODULE_AUTHOR("Pádraig Brady <P@draigBrady.com>");
370MODULE_DESCRIPTION("w83627hf WDT driver"); 383MODULE_DESCRIPTION("w83627hf/thf WDT driver");
371MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); 384MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 893dbaf386fb..eb37fba9b7ef 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1685,9 +1685,11 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
1685 if (sys_dev) { 1685 if (sys_dev) {
1686 switch (action) { 1686 switch (action) {
1687 case CPU_ONLINE: 1687 case CPU_ONLINE:
1688 case CPU_ONLINE_FROZEN:
1688 cpufreq_add_dev(sys_dev); 1689 cpufreq_add_dev(sys_dev);
1689 break; 1690 break;
1690 case CPU_DOWN_PREPARE: 1691 case CPU_DOWN_PREPARE:
1692 case CPU_DOWN_PREPARE_FROZEN:
1691 if (unlikely(lock_policy_rwsem_write(cpu))) 1693 if (unlikely(lock_policy_rwsem_write(cpu)))
1692 BUG(); 1694 BUG();
1693 1695
@@ -1699,6 +1701,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
1699 __cpufreq_remove_dev(sys_dev); 1701 __cpufreq_remove_dev(sys_dev);
1700 break; 1702 break;
1701 case CPU_DOWN_FAILED: 1703 case CPU_DOWN_FAILED:
1704 case CPU_DOWN_FAILED_FROZEN:
1702 cpufreq_add_dev(sys_dev); 1705 cpufreq_add_dev(sys_dev);
1703 break; 1706 break;
1704 } 1707 }
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index 8d053f500fc2..8532bb79e5fc 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -470,7 +470,7 @@ static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
470 dbs_info->enable = 1; 470 dbs_info->enable = 1;
471 ondemand_powersave_bias_init(); 471 ondemand_powersave_bias_init();
472 dbs_info->sample_type = DBS_NORMAL_SAMPLE; 472 dbs_info->sample_type = DBS_NORMAL_SAMPLE;
473 INIT_DELAYED_WORK(&dbs_info->work, do_dbs_timer); 473 INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer);
474 queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work, 474 queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work,
475 delay); 475 delay);
476} 476}
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index d1c7cac9316c..d2f0cbd8b8f3 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -313,9 +313,11 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
313 313
314 switch (action) { 314 switch (action) {
315 case CPU_ONLINE: 315 case CPU_ONLINE:
316 case CPU_ONLINE_FROZEN:
316 cpufreq_update_policy(cpu); 317 cpufreq_update_policy(cpu);
317 break; 318 break;
318 case CPU_DEAD: 319 case CPU_DEAD:
320 case CPU_DEAD_FROZEN:
319 cpufreq_stats_free_table(cpu); 321 cpufreq_stats_free_table(cpu);
320 break; 322 break;
321 } 323 }
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index f21fe66c9eef..bb90cbd7ca51 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -1,10 +1,10 @@
1menu "Hardware crypto devices" 1menu "Hardware crypto devices"
2 2
3config CRYPTO_DEV_PADLOCK 3config CRYPTO_DEV_PADLOCK
4 bool "Support for VIA PadLock ACE" 4 tristate "Support for VIA PadLock ACE"
5 depends on X86_32 5 depends on X86_32
6 select CRYPTO_ALGAPI 6 select CRYPTO_ALGAPI
7 default y 7 default m
8 help 8 help
9 Some VIA processors come with an integrated crypto engine 9 Some VIA processors come with an integrated crypto engine
10 (so called VIA PadLock ACE, Advanced Cryptography Engine) 10 (so called VIA PadLock ACE, Advanced Cryptography Engine)
@@ -51,9 +51,31 @@ config CRYPTO_DEV_GEODE
51 default m 51 default m
52 help 52 help
53 Say 'Y' here to use the AMD Geode LX processor on-board AES 53 Say 'Y' here to use the AMD Geode LX processor on-board AES
54 engine for the CryptoAPI AES alogrithm. 54 engine for the CryptoAPI AES algorithm.
55 55
56 To compile this driver as a module, choose M here: the module 56 To compile this driver as a module, choose M here: the module
57 will be called geode-aes. 57 will be called geode-aes.
58 58
59config ZCRYPT
60 tristate "Support for PCI-attached cryptographic adapters"
61 depends on S390
62 select ZCRYPT_MONOLITHIC if ZCRYPT="y"
63 default "m"
64 help
65 Select this option if you want to use a PCI-attached cryptographic
66 adapter like:
67 + PCI Cryptographic Accelerator (PCICA)
68 + PCI Cryptographic Coprocessor (PCICC)
69 + PCI-X Cryptographic Coprocessor (PCIXCC)
70 + Crypto Express2 Coprocessor (CEX2C)
71 + Crypto Express2 Accelerator (CEX2A)
72
73config ZCRYPT_MONOLITHIC
74 bool "Monolithic zcrypt module"
75 depends on ZCRYPT="m"
76 help
77 Select this option if you want to have a single module z90crypt.ko
78 that contains all parts of the crypto device driver (ap bus,
79 request router and all the card drivers).
80
59endmenu 81endmenu
diff --git a/drivers/dma/Kconfig b/drivers/dma/Kconfig
index 30d021d1a07c..72be6c63edfc 100644
--- a/drivers/dma/Kconfig
+++ b/drivers/dma/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "DMA Engine support" 5menu "DMA Engine support"
6 depends on !S390
6 7
7config DMA_ENGINE 8config DMA_ENGINE
8 bool "Support for DMA engines" 9 bool "Support for DMA engines"
diff --git a/drivers/edac/Kconfig b/drivers/edac/Kconfig
index 4f0898400c6d..807c402df049 100644
--- a/drivers/edac/Kconfig
+++ b/drivers/edac/Kconfig
@@ -7,6 +7,7 @@
7# 7#
8 8
9menu 'EDAC - error detection and reporting (RAS) (EXPERIMENTAL)' 9menu 'EDAC - error detection and reporting (RAS) (EXPERIMENTAL)'
10 depends on HAS_IOMEM
10 11
11config EDAC 12config EDAC
12 tristate "EDAC core system error reporting (EXPERIMENTAL)" 13 tristate "EDAC core system error reporting (EXPERIMENTAL)"
diff --git a/drivers/edac/i82875p_edac.c b/drivers/edac/i82875p_edac.c
index 161fe09a6d38..2800b3e614a9 100644
--- a/drivers/edac/i82875p_edac.c
+++ b/drivers/edac/i82875p_edac.c
@@ -261,10 +261,6 @@ static void i82875p_check(struct mem_ctl_info *mci)
261 i82875p_process_error_info(mci, &info, 1); 261 i82875p_process_error_info(mci, &info, 1);
262} 262}
263 263
264#ifdef CONFIG_PROC_FS
265extern int pci_proc_attach_device(struct pci_dev *);
266#endif
267
268/* Return 0 on success or 1 on failure. */ 264/* Return 0 on success or 1 on failure. */
269static int i82875p_setup_overfl_dev(struct pci_dev *pdev, 265static int i82875p_setup_overfl_dev(struct pci_dev *pdev,
270 struct pci_dev **ovrfl_pdev, void __iomem **ovrfl_window) 266 struct pci_dev **ovrfl_pdev, void __iomem **ovrfl_window)
@@ -287,17 +283,12 @@ static int i82875p_setup_overfl_dev(struct pci_dev *pdev,
287 283
288 if (dev == NULL) 284 if (dev == NULL)
289 return 1; 285 return 1;
286
287 pci_bus_add_device(dev);
290 } 288 }
291 289
292 *ovrfl_pdev = dev; 290 *ovrfl_pdev = dev;
293 291
294#ifdef CONFIG_PROC_FS
295 if ((dev->procent == NULL) && pci_proc_attach_device(dev)) {
296 i82875p_printk(KERN_ERR, "%s(): Failed to attach overflow "
297 "device\n", __func__);
298 return 1;
299 }
300#endif /* CONFIG_PROC_FS */
301 if (pci_enable_device(dev)) { 292 if (pci_enable_device(dev)) {
302 i82875p_printk(KERN_ERR, "%s(): Failed to enable overflow " 293 i82875p_printk(KERN_ERR, "%s(): Failed to enable overflow "
303 "device\n", __func__); 294 "device\n", __func__);
diff --git a/drivers/eisa/virtual_root.c b/drivers/eisa/virtual_root.c
index 9b4fcac03ad5..3074879f231f 100644
--- a/drivers/eisa/virtual_root.c
+++ b/drivers/eisa/virtual_root.c
@@ -47,7 +47,7 @@ static void virtual_eisa_release (struct device *dev)
47 /* nothing really to do here */ 47 /* nothing really to do here */
48} 48}
49 49
50static int virtual_eisa_root_init (void) 50static int __init virtual_eisa_root_init (void)
51{ 51{
52 int r; 52 int r;
53 53
diff --git a/drivers/firewire/Kconfig b/drivers/firewire/Kconfig
new file mode 100644
index 000000000000..5932c72f9e42
--- /dev/null
+++ b/drivers/firewire/Kconfig
@@ -0,0 +1,61 @@
1# -*- shell-script -*-
2
3comment "An alternative FireWire stack is available with EXPERIMENTAL=y"
4 depends on EXPERIMENTAL=n
5
6config FIREWIRE
7 tristate "IEEE 1394 (FireWire) support (JUJU alternative stack, experimental)"
8 depends on EXPERIMENTAL
9 select CRC_ITU_T
10 help
11 IEEE 1394 describes a high performance serial bus, which is also
12 known as FireWire(tm) or i.Link(tm) and is used for connecting all
13 sorts of devices (most notably digital video cameras) to your
14 computer.
15
16 If you have FireWire hardware and want to use it, say Y here. This
17 is the core support only, you will also need to select a driver for
18 your IEEE 1394 adapter.
19
20 To compile this driver as a module, say M here: the module will be
21 called fw-core.
22
23 This is the "JUJU" FireWire stack, an alternative implementation
24 designed for robustness and simplicity. You can build either this
25 stack, or the classic stack (the ieee1394 driver, ohci1394 etc.)
26 or both.
27
28config FIREWIRE_OHCI
29 tristate "Support for OHCI FireWire host controllers"
30 depends on PCI && FIREWIRE
31 help
32 Enable this driver if you have a FireWire controller based
33 on the OHCI specification. For all practical purposes, this
34 is the only chipset in use, so say Y here.
35
36 To compile this driver as a module, say M here: The module will be
37 called fw-ohci.
38
39 If you also build ohci1394 of the classic IEEE 1394 driver stack,
40 blacklist either ohci1394 or fw-ohci to let hotplug load the desired
41 driver.
42
43config FIREWIRE_SBP2
44 tristate "Support for storage devices (SBP-2 protocol driver)"
45 depends on FIREWIRE && SCSI
46 help
47 This option enables you to use SBP-2 devices connected to a
48 FireWire bus. SBP-2 devices include storage devices like
49 harddisks and DVD drives, also some other FireWire devices
50 like scanners.
51
52 To compile this driver as a module, say M here: The module will be
53 called fw-sbp2.
54
55 You should also enable support for disks, CD-ROMs, etc. in the SCSI
56 configuration section.
57
58 If you also build sbp2 of the classic IEEE 1394 driver stack,
59 blacklist either sbp2 or fw-sbp2 to let hotplug load the desired
60 driver.
61
diff --git a/drivers/firewire/Makefile b/drivers/firewire/Makefile
new file mode 100644
index 000000000000..fc7d59d4bce0
--- /dev/null
+++ b/drivers/firewire/Makefile
@@ -0,0 +1,10 @@
1#
2# Makefile for the Linux IEEE 1394 implementation
3#
4
5fw-core-y += fw-card.o fw-topology.o fw-transaction.o fw-iso.o \
6 fw-device.o fw-cdev.o
7
8obj-$(CONFIG_FIREWIRE) += fw-core.o
9obj-$(CONFIG_FIREWIRE_OHCI) += fw-ohci.o
10obj-$(CONFIG_FIREWIRE_SBP2) += fw-sbp2.o
diff --git a/drivers/firewire/fw-card.c b/drivers/firewire/fw-card.c
new file mode 100644
index 000000000000..636151a64add
--- /dev/null
+++ b/drivers/firewire/fw-card.c
@@ -0,0 +1,560 @@
1/*
2 * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#include <linux/module.h>
20#include <linux/errno.h>
21#include <linux/device.h>
22#include <linux/mutex.h>
23#include <linux/crc-itu-t.h>
24#include "fw-transaction.h"
25#include "fw-topology.h"
26#include "fw-device.h"
27
28int fw_compute_block_crc(u32 *block)
29{
30 __be32 be32_block[256];
31 int i, length;
32
33 length = (*block >> 16) & 0xff;
34 for (i = 0; i < length; i++)
35 be32_block[i] = cpu_to_be32(block[i + 1]);
36 *block |= crc_itu_t(0, (u8 *) be32_block, length * 4);
37
38 return length;
39}
40
41static DEFINE_MUTEX(card_mutex);
42static LIST_HEAD(card_list);
43
44static LIST_HEAD(descriptor_list);
45static int descriptor_count;
46
47#define BIB_CRC(v) ((v) << 0)
48#define BIB_CRC_LENGTH(v) ((v) << 16)
49#define BIB_INFO_LENGTH(v) ((v) << 24)
50
51#define BIB_LINK_SPEED(v) ((v) << 0)
52#define BIB_GENERATION(v) ((v) << 4)
53#define BIB_MAX_ROM(v) ((v) << 8)
54#define BIB_MAX_RECEIVE(v) ((v) << 12)
55#define BIB_CYC_CLK_ACC(v) ((v) << 16)
56#define BIB_PMC ((1) << 27)
57#define BIB_BMC ((1) << 28)
58#define BIB_ISC ((1) << 29)
59#define BIB_CMC ((1) << 30)
60#define BIB_IMC ((1) << 31)
61
62static u32 *
63generate_config_rom(struct fw_card *card, size_t *config_rom_length)
64{
65 struct fw_descriptor *desc;
66 static u32 config_rom[256];
67 int i, j, length;
68
69 /*
70 * Initialize contents of config rom buffer. On the OHCI
71 * controller, block reads to the config rom accesses the host
72 * memory, but quadlet read access the hardware bus info block
73 * registers. That's just crack, but it means we should make
74 * sure the contents of bus info block in host memory mathces
75 * the version stored in the OHCI registers.
76 */
77
78 memset(config_rom, 0, sizeof(config_rom));
79 config_rom[0] = BIB_CRC_LENGTH(4) | BIB_INFO_LENGTH(4) | BIB_CRC(0);
80 config_rom[1] = 0x31333934;
81
82 config_rom[2] =
83 BIB_LINK_SPEED(card->link_speed) |
84 BIB_GENERATION(card->config_rom_generation++ % 14 + 2) |
85 BIB_MAX_ROM(2) |
86 BIB_MAX_RECEIVE(card->max_receive) |
87 BIB_BMC | BIB_ISC | BIB_CMC | BIB_IMC;
88 config_rom[3] = card->guid >> 32;
89 config_rom[4] = card->guid;
90
91 /* Generate root directory. */
92 i = 5;
93 config_rom[i++] = 0;
94 config_rom[i++] = 0x0c0083c0; /* node capabilities */
95 j = i + descriptor_count;
96
97 /* Generate root directory entries for descriptors. */
98 list_for_each_entry (desc, &descriptor_list, link) {
99 if (desc->immediate > 0)
100 config_rom[i++] = desc->immediate;
101 config_rom[i] = desc->key | (j - i);
102 i++;
103 j += desc->length;
104 }
105
106 /* Update root directory length. */
107 config_rom[5] = (i - 5 - 1) << 16;
108
109 /* End of root directory, now copy in descriptors. */
110 list_for_each_entry (desc, &descriptor_list, link) {
111 memcpy(&config_rom[i], desc->data, desc->length * 4);
112 i += desc->length;
113 }
114
115 /* Calculate CRCs for all blocks in the config rom. This
116 * assumes that CRC length and info length are identical for
117 * the bus info block, which is always the case for this
118 * implementation. */
119 for (i = 0; i < j; i += length + 1)
120 length = fw_compute_block_crc(config_rom + i);
121
122 *config_rom_length = j;
123
124 return config_rom;
125}
126
127static void
128update_config_roms(void)
129{
130 struct fw_card *card;
131 u32 *config_rom;
132 size_t length;
133
134 list_for_each_entry (card, &card_list, link) {
135 config_rom = generate_config_rom(card, &length);
136 card->driver->set_config_rom(card, config_rom, length);
137 }
138}
139
140int
141fw_core_add_descriptor(struct fw_descriptor *desc)
142{
143 size_t i;
144
145 /*
146 * Check descriptor is valid; the length of all blocks in the
147 * descriptor has to add up to exactly the length of the
148 * block.
149 */
150 i = 0;
151 while (i < desc->length)
152 i += (desc->data[i] >> 16) + 1;
153
154 if (i != desc->length)
155 return -EINVAL;
156
157 mutex_lock(&card_mutex);
158
159 list_add_tail(&desc->link, &descriptor_list);
160 descriptor_count++;
161 if (desc->immediate > 0)
162 descriptor_count++;
163 update_config_roms();
164
165 mutex_unlock(&card_mutex);
166
167 return 0;
168}
169EXPORT_SYMBOL(fw_core_add_descriptor);
170
171void
172fw_core_remove_descriptor(struct fw_descriptor *desc)
173{
174 mutex_lock(&card_mutex);
175
176 list_del(&desc->link);
177 descriptor_count--;
178 if (desc->immediate > 0)
179 descriptor_count--;
180 update_config_roms();
181
182 mutex_unlock(&card_mutex);
183}
184EXPORT_SYMBOL(fw_core_remove_descriptor);
185
186static const char gap_count_table[] = {
187 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40
188};
189
190struct bm_data {
191 struct fw_transaction t;
192 struct {
193 __be32 arg;
194 __be32 data;
195 } lock;
196 u32 old;
197 int rcode;
198 struct completion done;
199};
200
201static void
202complete_bm_lock(struct fw_card *card, int rcode,
203 void *payload, size_t length, void *data)
204{
205 struct bm_data *bmd = data;
206
207 if (rcode == RCODE_COMPLETE)
208 bmd->old = be32_to_cpu(*(__be32 *) payload);
209 bmd->rcode = rcode;
210 complete(&bmd->done);
211}
212
213static void
214fw_card_bm_work(struct work_struct *work)
215{
216 struct fw_card *card = container_of(work, struct fw_card, work.work);
217 struct fw_device *root;
218 struct bm_data bmd;
219 unsigned long flags;
220 int root_id, new_root_id, irm_id, gap_count, generation, grace;
221 int do_reset = 0;
222
223 spin_lock_irqsave(&card->lock, flags);
224
225 generation = card->generation;
226 root = card->root_node->data;
227 root_id = card->root_node->node_id;
228 grace = time_after(jiffies, card->reset_jiffies + DIV_ROUND_UP(HZ, 10));
229
230 if (card->bm_generation + 1 == generation ||
231 (card->bm_generation != generation && grace)) {
232 /*
233 * This first step is to figure out who is IRM and
234 * then try to become bus manager. If the IRM is not
235 * well defined (e.g. does not have an active link
236 * layer or does not responds to our lock request, we
237 * will have to do a little vigilante bus management.
238 * In that case, we do a goto into the gap count logic
239 * so that when we do the reset, we still optimize the
240 * gap count. That could well save a reset in the
241 * next generation.
242 */
243
244 irm_id = card->irm_node->node_id;
245 if (!card->irm_node->link_on) {
246 new_root_id = card->local_node->node_id;
247 fw_notify("IRM has link off, making local node (%02x) root.\n",
248 new_root_id);
249 goto pick_me;
250 }
251
252 bmd.lock.arg = cpu_to_be32(0x3f);
253 bmd.lock.data = cpu_to_be32(card->local_node->node_id);
254
255 spin_unlock_irqrestore(&card->lock, flags);
256
257 init_completion(&bmd.done);
258 fw_send_request(card, &bmd.t, TCODE_LOCK_COMPARE_SWAP,
259 irm_id, generation,
260 SCODE_100, CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID,
261 &bmd.lock, sizeof(bmd.lock),
262 complete_bm_lock, &bmd);
263 wait_for_completion(&bmd.done);
264
265 if (bmd.rcode == RCODE_GENERATION) {
266 /*
267 * Another bus reset happened. Just return,
268 * the BM work has been rescheduled.
269 */
270 return;
271 }
272
273 if (bmd.rcode == RCODE_COMPLETE && bmd.old != 0x3f)
274 /* Somebody else is BM, let them do the work. */
275 return;
276
277 spin_lock_irqsave(&card->lock, flags);
278 if (bmd.rcode != RCODE_COMPLETE) {
279 /*
280 * The lock request failed, maybe the IRM
281 * isn't really IRM capable after all. Let's
282 * do a bus reset and pick the local node as
283 * root, and thus, IRM.
284 */
285 new_root_id = card->local_node->node_id;
286 fw_notify("BM lock failed, making local node (%02x) root.\n",
287 new_root_id);
288 goto pick_me;
289 }
290 } else if (card->bm_generation != generation) {
291 /*
292 * OK, we weren't BM in the last generation, and it's
293 * less than 100ms since last bus reset. Reschedule
294 * this task 100ms from now.
295 */
296 spin_unlock_irqrestore(&card->lock, flags);
297 schedule_delayed_work(&card->work, DIV_ROUND_UP(HZ, 10));
298 return;
299 }
300
301 /*
302 * We're bus manager for this generation, so next step is to
303 * make sure we have an active cycle master and do gap count
304 * optimization.
305 */
306 card->bm_generation = generation;
307
308 if (root == NULL) {
309 /*
310 * Either link_on is false, or we failed to read the
311 * config rom. In either case, pick another root.
312 */
313 new_root_id = card->local_node->node_id;
314 } else if (atomic_read(&root->state) != FW_DEVICE_RUNNING) {
315 /*
316 * If we haven't probed this device yet, bail out now
317 * and let's try again once that's done.
318 */
319 spin_unlock_irqrestore(&card->lock, flags);
320 return;
321 } else if (root->config_rom[2] & BIB_CMC) {
322 /*
323 * FIXME: I suppose we should set the cmstr bit in the
324 * STATE_CLEAR register of this node, as described in
325 * 1394-1995, 8.4.2.6. Also, send out a force root
326 * packet for this node.
327 */
328 new_root_id = root_id;
329 } else {
330 /*
331 * Current root has an active link layer and we
332 * successfully read the config rom, but it's not
333 * cycle master capable.
334 */
335 new_root_id = card->local_node->node_id;
336 }
337
338 pick_me:
339 /* Now figure out what gap count to set. */
340 if (card->topology_type == FW_TOPOLOGY_A &&
341 card->root_node->max_hops < ARRAY_SIZE(gap_count_table))
342 gap_count = gap_count_table[card->root_node->max_hops];
343 else
344 gap_count = 63;
345
346 /*
347 * Finally, figure out if we should do a reset or not. If we've
348 * done less that 5 resets with the same physical topology and we
349 * have either a new root or a new gap count setting, let's do it.
350 */
351
352 if (card->bm_retries++ < 5 &&
353 (card->gap_count != gap_count || new_root_id != root_id))
354 do_reset = 1;
355
356 spin_unlock_irqrestore(&card->lock, flags);
357
358 if (do_reset) {
359 fw_notify("phy config: card %d, new root=%x, gap_count=%d\n",
360 card->index, new_root_id, gap_count);
361 fw_send_phy_config(card, new_root_id, generation, gap_count);
362 fw_core_initiate_bus_reset(card, 1);
363 }
364}
365
366static void
367flush_timer_callback(unsigned long data)
368{
369 struct fw_card *card = (struct fw_card *)data;
370
371 fw_flush_transactions(card);
372}
373
374void
375fw_card_initialize(struct fw_card *card, const struct fw_card_driver *driver,
376 struct device *device)
377{
378 static atomic_t index = ATOMIC_INIT(-1);
379
380 kref_init(&card->kref);
381 card->index = atomic_inc_return(&index);
382 card->driver = driver;
383 card->device = device;
384 card->current_tlabel = 0;
385 card->tlabel_mask = 0;
386 card->color = 0;
387
388 INIT_LIST_HEAD(&card->transaction_list);
389 spin_lock_init(&card->lock);
390 setup_timer(&card->flush_timer,
391 flush_timer_callback, (unsigned long)card);
392
393 card->local_node = NULL;
394
395 INIT_DELAYED_WORK(&card->work, fw_card_bm_work);
396}
397EXPORT_SYMBOL(fw_card_initialize);
398
399int
400fw_card_add(struct fw_card *card,
401 u32 max_receive, u32 link_speed, u64 guid)
402{
403 u32 *config_rom;
404 size_t length;
405
406 card->max_receive = max_receive;
407 card->link_speed = link_speed;
408 card->guid = guid;
409
410 /* Activate link_on bit and contender bit in our self ID packets.*/
411 if (card->driver->update_phy_reg(card, 4, 0,
412 PHY_LINK_ACTIVE | PHY_CONTENDER) < 0)
413 return -EIO;
414
415 /*
416 * The subsystem grabs a reference when the card is added and
417 * drops it when the driver calls fw_core_remove_card.
418 */
419 fw_card_get(card);
420
421 mutex_lock(&card_mutex);
422 config_rom = generate_config_rom(card, &length);
423 list_add_tail(&card->link, &card_list);
424 mutex_unlock(&card_mutex);
425
426 return card->driver->enable(card, config_rom, length);
427}
428EXPORT_SYMBOL(fw_card_add);
429
430
431/*
432 * The next few functions implements a dummy driver that use once a
433 * card driver shuts down an fw_card. This allows the driver to
434 * cleanly unload, as all IO to the card will be handled by the dummy
435 * driver instead of calling into the (possibly) unloaded module. The
436 * dummy driver just fails all IO.
437 */
438
439static int
440dummy_enable(struct fw_card *card, u32 *config_rom, size_t length)
441{
442 BUG();
443 return -1;
444}
445
446static int
447dummy_update_phy_reg(struct fw_card *card, int address,
448 int clear_bits, int set_bits)
449{
450 return -ENODEV;
451}
452
453static int
454dummy_set_config_rom(struct fw_card *card,
455 u32 *config_rom, size_t length)
456{
457 /*
458 * We take the card out of card_list before setting the dummy
459 * driver, so this should never get called.
460 */
461 BUG();
462 return -1;
463}
464
465static void
466dummy_send_request(struct fw_card *card, struct fw_packet *packet)
467{
468 packet->callback(packet, card, -ENODEV);
469}
470
471static void
472dummy_send_response(struct fw_card *card, struct fw_packet *packet)
473{
474 packet->callback(packet, card, -ENODEV);
475}
476
477static int
478dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet)
479{
480 return -ENOENT;
481}
482
483static int
484dummy_enable_phys_dma(struct fw_card *card,
485 int node_id, int generation)
486{
487 return -ENODEV;
488}
489
490static struct fw_card_driver dummy_driver = {
491 .name = "dummy",
492 .enable = dummy_enable,
493 .update_phy_reg = dummy_update_phy_reg,
494 .set_config_rom = dummy_set_config_rom,
495 .send_request = dummy_send_request,
496 .cancel_packet = dummy_cancel_packet,
497 .send_response = dummy_send_response,
498 .enable_phys_dma = dummy_enable_phys_dma,
499};
500
501void
502fw_core_remove_card(struct fw_card *card)
503{
504 card->driver->update_phy_reg(card, 4,
505 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
506 fw_core_initiate_bus_reset(card, 1);
507
508 mutex_lock(&card_mutex);
509 list_del(&card->link);
510 mutex_unlock(&card_mutex);
511
512 /* Set up the dummy driver. */
513 card->driver = &dummy_driver;
514
515 fw_flush_transactions(card);
516
517 fw_destroy_nodes(card);
518
519 fw_card_put(card);
520}
521EXPORT_SYMBOL(fw_core_remove_card);
522
523struct fw_card *
524fw_card_get(struct fw_card *card)
525{
526 kref_get(&card->kref);
527
528 return card;
529}
530EXPORT_SYMBOL(fw_card_get);
531
532static void
533release_card(struct kref *kref)
534{
535 struct fw_card *card = container_of(kref, struct fw_card, kref);
536
537 kfree(card);
538}
539
540/*
541 * An assumption for fw_card_put() is that the card driver allocates
542 * the fw_card struct with kalloc and that it has been shut down
543 * before the last ref is dropped.
544 */
545void
546fw_card_put(struct fw_card *card)
547{
548 kref_put(&card->kref, release_card);
549}
550EXPORT_SYMBOL(fw_card_put);
551
552int
553fw_core_initiate_bus_reset(struct fw_card *card, int short_reset)
554{
555 int reg = short_reset ? 5 : 1;
556 int bit = short_reset ? PHY_BUS_SHORT_RESET : PHY_BUS_RESET;
557
558 return card->driver->update_phy_reg(card, reg, 0, bit);
559}
560EXPORT_SYMBOL(fw_core_initiate_bus_reset);
diff --git a/drivers/firewire/fw-cdev.c b/drivers/firewire/fw-cdev.c
new file mode 100644
index 000000000000..0fa5bd54c6a1
--- /dev/null
+++ b/drivers/firewire/fw-cdev.c
@@ -0,0 +1,961 @@
1/*
2 * Char device for device raw access
3 *
4 * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/wait.h>
24#include <linux/errno.h>
25#include <linux/device.h>
26#include <linux/vmalloc.h>
27#include <linux/poll.h>
28#include <linux/delay.h>
29#include <linux/mm.h>
30#include <linux/idr.h>
31#include <linux/compat.h>
32#include <linux/firewire-cdev.h>
33#include <asm/uaccess.h>
34#include "fw-transaction.h"
35#include "fw-topology.h"
36#include "fw-device.h"
37
38struct client;
39struct client_resource {
40 struct list_head link;
41 void (*release)(struct client *client, struct client_resource *r);
42 u32 handle;
43};
44
45/*
46 * dequeue_event() just kfree()'s the event, so the event has to be
47 * the first field in the struct.
48 */
49
50struct event {
51 struct { void *data; size_t size; } v[2];
52 struct list_head link;
53};
54
55struct bus_reset {
56 struct event event;
57 struct fw_cdev_event_bus_reset reset;
58};
59
60struct response {
61 struct event event;
62 struct fw_transaction transaction;
63 struct client *client;
64 struct client_resource resource;
65 struct fw_cdev_event_response response;
66};
67
68struct iso_interrupt {
69 struct event event;
70 struct fw_cdev_event_iso_interrupt interrupt;
71};
72
73struct client {
74 u32 version;
75 struct fw_device *device;
76 spinlock_t lock;
77 u32 resource_handle;
78 struct list_head resource_list;
79 struct list_head event_list;
80 wait_queue_head_t wait;
81 u64 bus_reset_closure;
82
83 struct fw_iso_context *iso_context;
84 u64 iso_closure;
85 struct fw_iso_buffer buffer;
86 unsigned long vm_start;
87
88 struct list_head link;
89};
90
91static inline void __user *
92u64_to_uptr(__u64 value)
93{
94 return (void __user *)(unsigned long)value;
95}
96
97static inline __u64
98uptr_to_u64(void __user *ptr)
99{
100 return (__u64)(unsigned long)ptr;
101}
102
103static int fw_device_op_open(struct inode *inode, struct file *file)
104{
105 struct fw_device *device;
106 struct client *client;
107 unsigned long flags;
108
109 device = fw_device_from_devt(inode->i_rdev);
110 if (device == NULL)
111 return -ENODEV;
112
113 client = kzalloc(sizeof(*client), GFP_KERNEL);
114 if (client == NULL)
115 return -ENOMEM;
116
117 client->device = fw_device_get(device);
118 INIT_LIST_HEAD(&client->event_list);
119 INIT_LIST_HEAD(&client->resource_list);
120 spin_lock_init(&client->lock);
121 init_waitqueue_head(&client->wait);
122
123 file->private_data = client;
124
125 spin_lock_irqsave(&device->card->lock, flags);
126 list_add_tail(&client->link, &device->client_list);
127 spin_unlock_irqrestore(&device->card->lock, flags);
128
129 return 0;
130}
131
132static void queue_event(struct client *client, struct event *event,
133 void *data0, size_t size0, void *data1, size_t size1)
134{
135 unsigned long flags;
136
137 event->v[0].data = data0;
138 event->v[0].size = size0;
139 event->v[1].data = data1;
140 event->v[1].size = size1;
141
142 spin_lock_irqsave(&client->lock, flags);
143
144 list_add_tail(&event->link, &client->event_list);
145 wake_up_interruptible(&client->wait);
146
147 spin_unlock_irqrestore(&client->lock, flags);
148}
149
150static int
151dequeue_event(struct client *client, char __user *buffer, size_t count)
152{
153 unsigned long flags;
154 struct event *event;
155 size_t size, total;
156 int i, retval;
157
158 retval = wait_event_interruptible(client->wait,
159 !list_empty(&client->event_list) ||
160 fw_device_is_shutdown(client->device));
161 if (retval < 0)
162 return retval;
163
164 if (list_empty(&client->event_list) &&
165 fw_device_is_shutdown(client->device))
166 return -ENODEV;
167
168 spin_lock_irqsave(&client->lock, flags);
169 event = container_of(client->event_list.next, struct event, link);
170 list_del(&event->link);
171 spin_unlock_irqrestore(&client->lock, flags);
172
173 total = 0;
174 for (i = 0; i < ARRAY_SIZE(event->v) && total < count; i++) {
175 size = min(event->v[i].size, count - total);
176 if (copy_to_user(buffer + total, event->v[i].data, size)) {
177 retval = -EFAULT;
178 goto out;
179 }
180 total += size;
181 }
182 retval = total;
183
184 out:
185 kfree(event);
186
187 return retval;
188}
189
190static ssize_t
191fw_device_op_read(struct file *file,
192 char __user *buffer, size_t count, loff_t *offset)
193{
194 struct client *client = file->private_data;
195
196 return dequeue_event(client, buffer, count);
197}
198
199static void
200fill_bus_reset_event(struct fw_cdev_event_bus_reset *event,
201 struct client *client)
202{
203 struct fw_card *card = client->device->card;
204
205 event->closure = client->bus_reset_closure;
206 event->type = FW_CDEV_EVENT_BUS_RESET;
207 event->node_id = client->device->node_id;
208 event->local_node_id = card->local_node->node_id;
209 event->bm_node_id = 0; /* FIXME: We don't track the BM. */
210 event->irm_node_id = card->irm_node->node_id;
211 event->root_node_id = card->root_node->node_id;
212 event->generation = card->generation;
213}
214
215static void
216for_each_client(struct fw_device *device,
217 void (*callback)(struct client *client))
218{
219 struct fw_card *card = device->card;
220 struct client *c;
221 unsigned long flags;
222
223 spin_lock_irqsave(&card->lock, flags);
224
225 list_for_each_entry(c, &device->client_list, link)
226 callback(c);
227
228 spin_unlock_irqrestore(&card->lock, flags);
229}
230
231static void
232queue_bus_reset_event(struct client *client)
233{
234 struct bus_reset *bus_reset;
235
236 bus_reset = kzalloc(sizeof(*bus_reset), GFP_ATOMIC);
237 if (bus_reset == NULL) {
238 fw_notify("Out of memory when allocating bus reset event\n");
239 return;
240 }
241
242 fill_bus_reset_event(&bus_reset->reset, client);
243
244 queue_event(client, &bus_reset->event,
245 &bus_reset->reset, sizeof(bus_reset->reset), NULL, 0);
246}
247
248void fw_device_cdev_update(struct fw_device *device)
249{
250 for_each_client(device, queue_bus_reset_event);
251}
252
253static void wake_up_client(struct client *client)
254{
255 wake_up_interruptible(&client->wait);
256}
257
258void fw_device_cdev_remove(struct fw_device *device)
259{
260 for_each_client(device, wake_up_client);
261}
262
263static int ioctl_get_info(struct client *client, void *buffer)
264{
265 struct fw_cdev_get_info *get_info = buffer;
266 struct fw_cdev_event_bus_reset bus_reset;
267
268 client->version = get_info->version;
269 get_info->version = FW_CDEV_VERSION;
270
271 if (get_info->rom != 0) {
272 void __user *uptr = u64_to_uptr(get_info->rom);
273 size_t want = get_info->rom_length;
274 size_t have = client->device->config_rom_length * 4;
275
276 if (copy_to_user(uptr, client->device->config_rom,
277 min(want, have)))
278 return -EFAULT;
279 }
280 get_info->rom_length = client->device->config_rom_length * 4;
281
282 client->bus_reset_closure = get_info->bus_reset_closure;
283 if (get_info->bus_reset != 0) {
284 void __user *uptr = u64_to_uptr(get_info->bus_reset);
285
286 fill_bus_reset_event(&bus_reset, client);
287 if (copy_to_user(uptr, &bus_reset, sizeof(bus_reset)))
288 return -EFAULT;
289 }
290
291 get_info->card = client->device->card->index;
292
293 return 0;
294}
295
296static void
297add_client_resource(struct client *client, struct client_resource *resource)
298{
299 unsigned long flags;
300
301 spin_lock_irqsave(&client->lock, flags);
302 list_add_tail(&resource->link, &client->resource_list);
303 resource->handle = client->resource_handle++;
304 spin_unlock_irqrestore(&client->lock, flags);
305}
306
307static int
308release_client_resource(struct client *client, u32 handle,
309 struct client_resource **resource)
310{
311 struct client_resource *r;
312 unsigned long flags;
313
314 spin_lock_irqsave(&client->lock, flags);
315 list_for_each_entry(r, &client->resource_list, link) {
316 if (r->handle == handle) {
317 list_del(&r->link);
318 break;
319 }
320 }
321 spin_unlock_irqrestore(&client->lock, flags);
322
323 if (&r->link == &client->resource_list)
324 return -EINVAL;
325
326 if (resource)
327 *resource = r;
328 else
329 r->release(client, r);
330
331 return 0;
332}
333
334static void
335release_transaction(struct client *client, struct client_resource *resource)
336{
337 struct response *response =
338 container_of(resource, struct response, resource);
339
340 fw_cancel_transaction(client->device->card, &response->transaction);
341}
342
343static void
344complete_transaction(struct fw_card *card, int rcode,
345 void *payload, size_t length, void *data)
346{
347 struct response *response = data;
348 struct client *client = response->client;
349 unsigned long flags;
350
351 if (length < response->response.length)
352 response->response.length = length;
353 if (rcode == RCODE_COMPLETE)
354 memcpy(response->response.data, payload,
355 response->response.length);
356
357 spin_lock_irqsave(&client->lock, flags);
358 list_del(&response->resource.link);
359 spin_unlock_irqrestore(&client->lock, flags);
360
361 response->response.type = FW_CDEV_EVENT_RESPONSE;
362 response->response.rcode = rcode;
363 queue_event(client, &response->event,
364 &response->response, sizeof(response->response),
365 response->response.data, response->response.length);
366}
367
368static ssize_t ioctl_send_request(struct client *client, void *buffer)
369{
370 struct fw_device *device = client->device;
371 struct fw_cdev_send_request *request = buffer;
372 struct response *response;
373
374 /* What is the biggest size we'll accept, really? */
375 if (request->length > 4096)
376 return -EINVAL;
377
378 response = kmalloc(sizeof(*response) + request->length, GFP_KERNEL);
379 if (response == NULL)
380 return -ENOMEM;
381
382 response->client = client;
383 response->response.length = request->length;
384 response->response.closure = request->closure;
385
386 if (request->data &&
387 copy_from_user(response->response.data,
388 u64_to_uptr(request->data), request->length)) {
389 kfree(response);
390 return -EFAULT;
391 }
392
393 response->resource.release = release_transaction;
394 add_client_resource(client, &response->resource);
395
396 fw_send_request(device->card, &response->transaction,
397 request->tcode & 0x1f,
398 device->node->node_id,
399 request->generation,
400 device->node->max_speed,
401 request->offset,
402 response->response.data, request->length,
403 complete_transaction, response);
404
405 if (request->data)
406 return sizeof(request) + request->length;
407 else
408 return sizeof(request);
409}
410
411struct address_handler {
412 struct fw_address_handler handler;
413 __u64 closure;
414 struct client *client;
415 struct client_resource resource;
416};
417
418struct request {
419 struct fw_request *request;
420 void *data;
421 size_t length;
422 struct client_resource resource;
423};
424
425struct request_event {
426 struct event event;
427 struct fw_cdev_event_request request;
428};
429
430static void
431release_request(struct client *client, struct client_resource *resource)
432{
433 struct request *request =
434 container_of(resource, struct request, resource);
435
436 fw_send_response(client->device->card, request->request,
437 RCODE_CONFLICT_ERROR);
438 kfree(request);
439}
440
441static void
442handle_request(struct fw_card *card, struct fw_request *r,
443 int tcode, int destination, int source,
444 int generation, int speed,
445 unsigned long long offset,
446 void *payload, size_t length, void *callback_data)
447{
448 struct address_handler *handler = callback_data;
449 struct request *request;
450 struct request_event *e;
451 struct client *client = handler->client;
452
453 request = kmalloc(sizeof(*request), GFP_ATOMIC);
454 e = kmalloc(sizeof(*e), GFP_ATOMIC);
455 if (request == NULL || e == NULL) {
456 kfree(request);
457 kfree(e);
458 fw_send_response(card, r, RCODE_CONFLICT_ERROR);
459 return;
460 }
461
462 request->request = r;
463 request->data = payload;
464 request->length = length;
465
466 request->resource.release = release_request;
467 add_client_resource(client, &request->resource);
468
469 e->request.type = FW_CDEV_EVENT_REQUEST;
470 e->request.tcode = tcode;
471 e->request.offset = offset;
472 e->request.length = length;
473 e->request.handle = request->resource.handle;
474 e->request.closure = handler->closure;
475
476 queue_event(client, &e->event,
477 &e->request, sizeof(e->request), payload, length);
478}
479
480static void
481release_address_handler(struct client *client,
482 struct client_resource *resource)
483{
484 struct address_handler *handler =
485 container_of(resource, struct address_handler, resource);
486
487 fw_core_remove_address_handler(&handler->handler);
488 kfree(handler);
489}
490
491static int ioctl_allocate(struct client *client, void *buffer)
492{
493 struct fw_cdev_allocate *request = buffer;
494 struct address_handler *handler;
495 struct fw_address_region region;
496
497 handler = kmalloc(sizeof(*handler), GFP_KERNEL);
498 if (handler == NULL)
499 return -ENOMEM;
500
501 region.start = request->offset;
502 region.end = request->offset + request->length;
503 handler->handler.length = request->length;
504 handler->handler.address_callback = handle_request;
505 handler->handler.callback_data = handler;
506 handler->closure = request->closure;
507 handler->client = client;
508
509 if (fw_core_add_address_handler(&handler->handler, &region) < 0) {
510 kfree(handler);
511 return -EBUSY;
512 }
513
514 handler->resource.release = release_address_handler;
515 add_client_resource(client, &handler->resource);
516 request->handle = handler->resource.handle;
517
518 return 0;
519}
520
521static int ioctl_deallocate(struct client *client, void *buffer)
522{
523 struct fw_cdev_deallocate *request = buffer;
524
525 return release_client_resource(client, request->handle, NULL);
526}
527
528static int ioctl_send_response(struct client *client, void *buffer)
529{
530 struct fw_cdev_send_response *request = buffer;
531 struct client_resource *resource;
532 struct request *r;
533
534 if (release_client_resource(client, request->handle, &resource) < 0)
535 return -EINVAL;
536 r = container_of(resource, struct request, resource);
537 if (request->length < r->length)
538 r->length = request->length;
539 if (copy_from_user(r->data, u64_to_uptr(request->data), r->length))
540 return -EFAULT;
541
542 fw_send_response(client->device->card, r->request, request->rcode);
543 kfree(r);
544
545 return 0;
546}
547
548static int ioctl_initiate_bus_reset(struct client *client, void *buffer)
549{
550 struct fw_cdev_initiate_bus_reset *request = buffer;
551 int short_reset;
552
553 short_reset = (request->type == FW_CDEV_SHORT_RESET);
554
555 return fw_core_initiate_bus_reset(client->device->card, short_reset);
556}
557
558struct descriptor {
559 struct fw_descriptor d;
560 struct client_resource resource;
561 u32 data[0];
562};
563
564static void release_descriptor(struct client *client,
565 struct client_resource *resource)
566{
567 struct descriptor *descriptor =
568 container_of(resource, struct descriptor, resource);
569
570 fw_core_remove_descriptor(&descriptor->d);
571 kfree(descriptor);
572}
573
574static int ioctl_add_descriptor(struct client *client, void *buffer)
575{
576 struct fw_cdev_add_descriptor *request = buffer;
577 struct descriptor *descriptor;
578 int retval;
579
580 if (request->length > 256)
581 return -EINVAL;
582
583 descriptor =
584 kmalloc(sizeof(*descriptor) + request->length * 4, GFP_KERNEL);
585 if (descriptor == NULL)
586 return -ENOMEM;
587
588 if (copy_from_user(descriptor->data,
589 u64_to_uptr(request->data), request->length * 4)) {
590 kfree(descriptor);
591 return -EFAULT;
592 }
593
594 descriptor->d.length = request->length;
595 descriptor->d.immediate = request->immediate;
596 descriptor->d.key = request->key;
597 descriptor->d.data = descriptor->data;
598
599 retval = fw_core_add_descriptor(&descriptor->d);
600 if (retval < 0) {
601 kfree(descriptor);
602 return retval;
603 }
604
605 descriptor->resource.release = release_descriptor;
606 add_client_resource(client, &descriptor->resource);
607 request->handle = descriptor->resource.handle;
608
609 return 0;
610}
611
612static int ioctl_remove_descriptor(struct client *client, void *buffer)
613{
614 struct fw_cdev_remove_descriptor *request = buffer;
615
616 return release_client_resource(client, request->handle, NULL);
617}
618
619static void
620iso_callback(struct fw_iso_context *context, u32 cycle,
621 size_t header_length, void *header, void *data)
622{
623 struct client *client = data;
624 struct iso_interrupt *interrupt;
625
626 interrupt = kzalloc(sizeof(*interrupt) + header_length, GFP_ATOMIC);
627 if (interrupt == NULL)
628 return;
629
630 interrupt->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT;
631 interrupt->interrupt.closure = client->iso_closure;
632 interrupt->interrupt.cycle = cycle;
633 interrupt->interrupt.header_length = header_length;
634 memcpy(interrupt->interrupt.header, header, header_length);
635 queue_event(client, &interrupt->event,
636 &interrupt->interrupt,
637 sizeof(interrupt->interrupt) + header_length, NULL, 0);
638}
639
640static int ioctl_create_iso_context(struct client *client, void *buffer)
641{
642 struct fw_cdev_create_iso_context *request = buffer;
643
644 if (request->channel > 63)
645 return -EINVAL;
646
647 switch (request->type) {
648 case FW_ISO_CONTEXT_RECEIVE:
649 if (request->header_size < 4 || (request->header_size & 3))
650 return -EINVAL;
651
652 break;
653
654 case FW_ISO_CONTEXT_TRANSMIT:
655 if (request->speed > SCODE_3200)
656 return -EINVAL;
657
658 break;
659
660 default:
661 return -EINVAL;
662 }
663
664 client->iso_closure = request->closure;
665 client->iso_context = fw_iso_context_create(client->device->card,
666 request->type,
667 request->channel,
668 request->speed,
669 request->header_size,
670 iso_callback, client);
671 if (IS_ERR(client->iso_context))
672 return PTR_ERR(client->iso_context);
673
674 /* We only support one context at this time. */
675 request->handle = 0;
676
677 return 0;
678}
679
680static int ioctl_queue_iso(struct client *client, void *buffer)
681{
682 struct fw_cdev_queue_iso *request = buffer;
683 struct fw_cdev_iso_packet __user *p, *end, *next;
684 struct fw_iso_context *ctx = client->iso_context;
685 unsigned long payload, buffer_end, header_length;
686 int count;
687 struct {
688 struct fw_iso_packet packet;
689 u8 header[256];
690 } u;
691
692 if (ctx == NULL || request->handle != 0)
693 return -EINVAL;
694
695 /*
696 * If the user passes a non-NULL data pointer, has mmap()'ed
697 * the iso buffer, and the pointer points inside the buffer,
698 * we setup the payload pointers accordingly. Otherwise we
699 * set them both to 0, which will still let packets with
700 * payload_length == 0 through. In other words, if no packets
701 * use the indirect payload, the iso buffer need not be mapped
702 * and the request->data pointer is ignored.
703 */
704
705 payload = (unsigned long)request->data - client->vm_start;
706 buffer_end = client->buffer.page_count << PAGE_SHIFT;
707 if (request->data == 0 || client->buffer.pages == NULL ||
708 payload >= buffer_end) {
709 payload = 0;
710 buffer_end = 0;
711 }
712
713 if (!access_ok(VERIFY_READ, request->packets, request->size))
714 return -EFAULT;
715
716 p = (struct fw_cdev_iso_packet __user *)u64_to_uptr(request->packets);
717 end = (void __user *)p + request->size;
718 count = 0;
719 while (p < end) {
720 if (__copy_from_user(&u.packet, p, sizeof(*p)))
721 return -EFAULT;
722
723 if (ctx->type == FW_ISO_CONTEXT_TRANSMIT) {
724 header_length = u.packet.header_length;
725 } else {
726 /*
727 * We require that header_length is a multiple of
728 * the fixed header size, ctx->header_size.
729 */
730 if (ctx->header_size == 0) {
731 if (u.packet.header_length > 0)
732 return -EINVAL;
733 } else if (u.packet.header_length % ctx->header_size != 0) {
734 return -EINVAL;
735 }
736 header_length = 0;
737 }
738
739 next = (struct fw_cdev_iso_packet __user *)
740 &p->header[header_length / 4];
741 if (next > end)
742 return -EINVAL;
743 if (__copy_from_user
744 (u.packet.header, p->header, header_length))
745 return -EFAULT;
746 if (u.packet.skip && ctx->type == FW_ISO_CONTEXT_TRANSMIT &&
747 u.packet.header_length + u.packet.payload_length > 0)
748 return -EINVAL;
749 if (payload + u.packet.payload_length > buffer_end)
750 return -EINVAL;
751
752 if (fw_iso_context_queue(ctx, &u.packet,
753 &client->buffer, payload))
754 break;
755
756 p = next;
757 payload += u.packet.payload_length;
758 count++;
759 }
760
761 request->size -= uptr_to_u64(p) - request->packets;
762 request->packets = uptr_to_u64(p);
763 request->data = client->vm_start + payload;
764
765 return count;
766}
767
768static int ioctl_start_iso(struct client *client, void *buffer)
769{
770 struct fw_cdev_start_iso *request = buffer;
771
772 if (request->handle != 0)
773 return -EINVAL;
774 if (client->iso_context->type == FW_ISO_CONTEXT_RECEIVE) {
775 if (request->tags == 0 || request->tags > 15)
776 return -EINVAL;
777
778 if (request->sync > 15)
779 return -EINVAL;
780 }
781
782 return fw_iso_context_start(client->iso_context, request->cycle,
783 request->sync, request->tags);
784}
785
786static int ioctl_stop_iso(struct client *client, void *buffer)
787{
788 struct fw_cdev_stop_iso *request = buffer;
789
790 if (request->handle != 0)
791 return -EINVAL;
792
793 return fw_iso_context_stop(client->iso_context);
794}
795
796static int (* const ioctl_handlers[])(struct client *client, void *buffer) = {
797 ioctl_get_info,
798 ioctl_send_request,
799 ioctl_allocate,
800 ioctl_deallocate,
801 ioctl_send_response,
802 ioctl_initiate_bus_reset,
803 ioctl_add_descriptor,
804 ioctl_remove_descriptor,
805 ioctl_create_iso_context,
806 ioctl_queue_iso,
807 ioctl_start_iso,
808 ioctl_stop_iso,
809};
810
811static int
812dispatch_ioctl(struct client *client, unsigned int cmd, void __user *arg)
813{
814 char buffer[256];
815 int retval;
816
817 if (_IOC_TYPE(cmd) != '#' ||
818 _IOC_NR(cmd) >= ARRAY_SIZE(ioctl_handlers))
819 return -EINVAL;
820
821 if (_IOC_DIR(cmd) & _IOC_WRITE) {
822 if (_IOC_SIZE(cmd) > sizeof(buffer) ||
823 copy_from_user(buffer, arg, _IOC_SIZE(cmd)))
824 return -EFAULT;
825 }
826
827 retval = ioctl_handlers[_IOC_NR(cmd)](client, buffer);
828 if (retval < 0)
829 return retval;
830
831 if (_IOC_DIR(cmd) & _IOC_READ) {
832 if (_IOC_SIZE(cmd) > sizeof(buffer) ||
833 copy_to_user(arg, buffer, _IOC_SIZE(cmd)))
834 return -EFAULT;
835 }
836
837 return 0;
838}
839
840static long
841fw_device_op_ioctl(struct file *file,
842 unsigned int cmd, unsigned long arg)
843{
844 struct client *client = file->private_data;
845
846 return dispatch_ioctl(client, cmd, (void __user *) arg);
847}
848
849#ifdef CONFIG_COMPAT
850static long
851fw_device_op_compat_ioctl(struct file *file,
852 unsigned int cmd, unsigned long arg)
853{
854 struct client *client = file->private_data;
855
856 return dispatch_ioctl(client, cmd, compat_ptr(arg));
857}
858#endif
859
860static int fw_device_op_mmap(struct file *file, struct vm_area_struct *vma)
861{
862 struct client *client = file->private_data;
863 enum dma_data_direction direction;
864 unsigned long size;
865 int page_count, retval;
866
867 /* FIXME: We could support multiple buffers, but we don't. */
868 if (client->buffer.pages != NULL)
869 return -EBUSY;
870
871 if (!(vma->vm_flags & VM_SHARED))
872 return -EINVAL;
873
874 if (vma->vm_start & ~PAGE_MASK)
875 return -EINVAL;
876
877 client->vm_start = vma->vm_start;
878 size = vma->vm_end - vma->vm_start;
879 page_count = size >> PAGE_SHIFT;
880 if (size & ~PAGE_MASK)
881 return -EINVAL;
882
883 if (vma->vm_flags & VM_WRITE)
884 direction = DMA_TO_DEVICE;
885 else
886 direction = DMA_FROM_DEVICE;
887
888 retval = fw_iso_buffer_init(&client->buffer, client->device->card,
889 page_count, direction);
890 if (retval < 0)
891 return retval;
892
893 retval = fw_iso_buffer_map(&client->buffer, vma);
894 if (retval < 0)
895 fw_iso_buffer_destroy(&client->buffer, client->device->card);
896
897 return retval;
898}
899
900static int fw_device_op_release(struct inode *inode, struct file *file)
901{
902 struct client *client = file->private_data;
903 struct event *e, *next_e;
904 struct client_resource *r, *next_r;
905 unsigned long flags;
906
907 if (client->buffer.pages)
908 fw_iso_buffer_destroy(&client->buffer, client->device->card);
909
910 if (client->iso_context)
911 fw_iso_context_destroy(client->iso_context);
912
913 list_for_each_entry_safe(r, next_r, &client->resource_list, link)
914 r->release(client, r);
915
916 /*
917 * FIXME: We should wait for the async tasklets to stop
918 * running before freeing the memory.
919 */
920
921 list_for_each_entry_safe(e, next_e, &client->event_list, link)
922 kfree(e);
923
924 spin_lock_irqsave(&client->device->card->lock, flags);
925 list_del(&client->link);
926 spin_unlock_irqrestore(&client->device->card->lock, flags);
927
928 fw_device_put(client->device);
929 kfree(client);
930
931 return 0;
932}
933
934static unsigned int fw_device_op_poll(struct file *file, poll_table * pt)
935{
936 struct client *client = file->private_data;
937 unsigned int mask = 0;
938
939 poll_wait(file, &client->wait, pt);
940
941 if (fw_device_is_shutdown(client->device))
942 mask |= POLLHUP | POLLERR;
943 if (!list_empty(&client->event_list))
944 mask |= POLLIN | POLLRDNORM;
945
946 return mask;
947}
948
949const struct file_operations fw_device_ops = {
950 .owner = THIS_MODULE,
951 .open = fw_device_op_open,
952 .read = fw_device_op_read,
953 .unlocked_ioctl = fw_device_op_ioctl,
954 .poll = fw_device_op_poll,
955 .release = fw_device_op_release,
956 .mmap = fw_device_op_mmap,
957
958#ifdef CONFIG_COMPAT
959 .compat_ioctl = fw_device_op_compat_ioctl,
960#endif
961};
diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c
new file mode 100644
index 000000000000..c1ce465d9710
--- /dev/null
+++ b/drivers/firewire/fw-device.c
@@ -0,0 +1,813 @@
1/*
2 * Device probing and sysfs code.
3 *
4 * Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/module.h>
22#include <linux/wait.h>
23#include <linux/errno.h>
24#include <linux/kthread.h>
25#include <linux/device.h>
26#include <linux/delay.h>
27#include <linux/idr.h>
28#include <linux/rwsem.h>
29#include <asm/semaphore.h>
30#include <linux/ctype.h>
31#include "fw-transaction.h"
32#include "fw-topology.h"
33#include "fw-device.h"
34
35void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 * p)
36{
37 ci->p = p + 1;
38 ci->end = ci->p + (p[0] >> 16);
39}
40EXPORT_SYMBOL(fw_csr_iterator_init);
41
42int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value)
43{
44 *key = *ci->p >> 24;
45 *value = *ci->p & 0xffffff;
46
47 return ci->p++ < ci->end;
48}
49EXPORT_SYMBOL(fw_csr_iterator_next);
50
51static int is_fw_unit(struct device *dev);
52
53static int match_unit_directory(u32 * directory, const struct fw_device_id *id)
54{
55 struct fw_csr_iterator ci;
56 int key, value, match;
57
58 match = 0;
59 fw_csr_iterator_init(&ci, directory);
60 while (fw_csr_iterator_next(&ci, &key, &value)) {
61 if (key == CSR_VENDOR && value == id->vendor)
62 match |= FW_MATCH_VENDOR;
63 if (key == CSR_MODEL && value == id->model)
64 match |= FW_MATCH_MODEL;
65 if (key == CSR_SPECIFIER_ID && value == id->specifier_id)
66 match |= FW_MATCH_SPECIFIER_ID;
67 if (key == CSR_VERSION && value == id->version)
68 match |= FW_MATCH_VERSION;
69 }
70
71 return (match & id->match_flags) == id->match_flags;
72}
73
74static int fw_unit_match(struct device *dev, struct device_driver *drv)
75{
76 struct fw_unit *unit = fw_unit(dev);
77 struct fw_driver *driver = fw_driver(drv);
78 int i;
79
80 /* We only allow binding to fw_units. */
81 if (!is_fw_unit(dev))
82 return 0;
83
84 for (i = 0; driver->id_table[i].match_flags != 0; i++) {
85 if (match_unit_directory(unit->directory, &driver->id_table[i]))
86 return 1;
87 }
88
89 return 0;
90}
91
92static int get_modalias(struct fw_unit *unit, char *buffer, size_t buffer_size)
93{
94 struct fw_device *device = fw_device(unit->device.parent);
95 struct fw_csr_iterator ci;
96
97 int key, value;
98 int vendor = 0;
99 int model = 0;
100 int specifier_id = 0;
101 int version = 0;
102
103 fw_csr_iterator_init(&ci, &device->config_rom[5]);
104 while (fw_csr_iterator_next(&ci, &key, &value)) {
105 switch (key) {
106 case CSR_VENDOR:
107 vendor = value;
108 break;
109 case CSR_MODEL:
110 model = value;
111 break;
112 }
113 }
114
115 fw_csr_iterator_init(&ci, unit->directory);
116 while (fw_csr_iterator_next(&ci, &key, &value)) {
117 switch (key) {
118 case CSR_SPECIFIER_ID:
119 specifier_id = value;
120 break;
121 case CSR_VERSION:
122 version = value;
123 break;
124 }
125 }
126
127 return snprintf(buffer, buffer_size,
128 "ieee1394:ven%08Xmo%08Xsp%08Xver%08X",
129 vendor, model, specifier_id, version);
130}
131
132static int
133fw_unit_uevent(struct device *dev, char **envp, int num_envp,
134 char *buffer, int buffer_size)
135{
136 struct fw_unit *unit = fw_unit(dev);
137 char modalias[64];
138 int length = 0;
139 int i = 0;
140
141 get_modalias(unit, modalias, sizeof(modalias));
142
143 if (add_uevent_var(envp, num_envp, &i,
144 buffer, buffer_size, &length,
145 "MODALIAS=%s", modalias))
146 return -ENOMEM;
147
148 envp[i] = NULL;
149
150 return 0;
151}
152
153struct bus_type fw_bus_type = {
154 .name = "firewire",
155 .match = fw_unit_match,
156};
157EXPORT_SYMBOL(fw_bus_type);
158
159struct fw_device *fw_device_get(struct fw_device *device)
160{
161 get_device(&device->device);
162
163 return device;
164}
165
166void fw_device_put(struct fw_device *device)
167{
168 put_device(&device->device);
169}
170
171static void fw_device_release(struct device *dev)
172{
173 struct fw_device *device = fw_device(dev);
174 unsigned long flags;
175
176 /*
177 * Take the card lock so we don't set this to NULL while a
178 * FW_NODE_UPDATED callback is being handled.
179 */
180 spin_lock_irqsave(&device->card->lock, flags);
181 device->node->data = NULL;
182 spin_unlock_irqrestore(&device->card->lock, flags);
183
184 fw_node_put(device->node);
185 fw_card_put(device->card);
186 kfree(device->config_rom);
187 kfree(device);
188}
189
190int fw_device_enable_phys_dma(struct fw_device *device)
191{
192 return device->card->driver->enable_phys_dma(device->card,
193 device->node_id,
194 device->generation);
195}
196EXPORT_SYMBOL(fw_device_enable_phys_dma);
197
198struct config_rom_attribute {
199 struct device_attribute attr;
200 u32 key;
201};
202
203static ssize_t
204show_immediate(struct device *dev, struct device_attribute *dattr, char *buf)
205{
206 struct config_rom_attribute *attr =
207 container_of(dattr, struct config_rom_attribute, attr);
208 struct fw_csr_iterator ci;
209 u32 *dir;
210 int key, value;
211
212 if (is_fw_unit(dev))
213 dir = fw_unit(dev)->directory;
214 else
215 dir = fw_device(dev)->config_rom + 5;
216
217 fw_csr_iterator_init(&ci, dir);
218 while (fw_csr_iterator_next(&ci, &key, &value))
219 if (attr->key == key)
220 return snprintf(buf, buf ? PAGE_SIZE : 0,
221 "0x%06x\n", value);
222
223 return -ENOENT;
224}
225
226#define IMMEDIATE_ATTR(name, key) \
227 { __ATTR(name, S_IRUGO, show_immediate, NULL), key }
228
229static ssize_t
230show_text_leaf(struct device *dev, struct device_attribute *dattr, char *buf)
231{
232 struct config_rom_attribute *attr =
233 container_of(dattr, struct config_rom_attribute, attr);
234 struct fw_csr_iterator ci;
235 u32 *dir, *block = NULL, *p, *end;
236 int length, key, value, last_key = 0;
237 char *b;
238
239 if (is_fw_unit(dev))
240 dir = fw_unit(dev)->directory;
241 else
242 dir = fw_device(dev)->config_rom + 5;
243
244 fw_csr_iterator_init(&ci, dir);
245 while (fw_csr_iterator_next(&ci, &key, &value)) {
246 if (attr->key == last_key &&
247 key == (CSR_DESCRIPTOR | CSR_LEAF))
248 block = ci.p - 1 + value;
249 last_key = key;
250 }
251
252 if (block == NULL)
253 return -ENOENT;
254
255 length = min(block[0] >> 16, 256U);
256 if (length < 3)
257 return -ENOENT;
258
259 if (block[1] != 0 || block[2] != 0)
260 /* Unknown encoding. */
261 return -ENOENT;
262
263 if (buf == NULL)
264 return length * 4;
265
266 b = buf;
267 end = &block[length + 1];
268 for (p = &block[3]; p < end; p++, b += 4)
269 * (u32 *) b = (__force u32) __cpu_to_be32(*p);
270
271 /* Strip trailing whitespace and add newline. */
272 while (b--, (isspace(*b) || *b == '\0') && b > buf);
273 strcpy(b + 1, "\n");
274
275 return b + 2 - buf;
276}
277
278#define TEXT_LEAF_ATTR(name, key) \
279 { __ATTR(name, S_IRUGO, show_text_leaf, NULL), key }
280
281static struct config_rom_attribute config_rom_attributes[] = {
282 IMMEDIATE_ATTR(vendor, CSR_VENDOR),
283 IMMEDIATE_ATTR(hardware_version, CSR_HARDWARE_VERSION),
284 IMMEDIATE_ATTR(specifier_id, CSR_SPECIFIER_ID),
285 IMMEDIATE_ATTR(version, CSR_VERSION),
286 IMMEDIATE_ATTR(model, CSR_MODEL),
287 TEXT_LEAF_ATTR(vendor_name, CSR_VENDOR),
288 TEXT_LEAF_ATTR(model_name, CSR_MODEL),
289 TEXT_LEAF_ATTR(hardware_version_name, CSR_HARDWARE_VERSION),
290};
291
292static void
293init_fw_attribute_group(struct device *dev,
294 struct device_attribute *attrs,
295 struct fw_attribute_group *group)
296{
297 struct device_attribute *attr;
298 int i, j;
299
300 for (j = 0; attrs[j].attr.name != NULL; j++)
301 group->attrs[j] = &attrs[j].attr;
302
303 for (i = 0; i < ARRAY_SIZE(config_rom_attributes); i++) {
304 attr = &config_rom_attributes[i].attr;
305 if (attr->show(dev, attr, NULL) < 0)
306 continue;
307 group->attrs[j++] = &attr->attr;
308 }
309
310 BUG_ON(j >= ARRAY_SIZE(group->attrs));
311 group->attrs[j++] = NULL;
312 group->groups[0] = &group->group;
313 group->groups[1] = NULL;
314 group->group.attrs = group->attrs;
315 dev->groups = group->groups;
316}
317
318static ssize_t
319modalias_show(struct device *dev,
320 struct device_attribute *attr, char *buf)
321{
322 struct fw_unit *unit = fw_unit(dev);
323 int length;
324
325 length = get_modalias(unit, buf, PAGE_SIZE);
326 strcpy(buf + length, "\n");
327
328 return length + 1;
329}
330
331static ssize_t
332rom_index_show(struct device *dev,
333 struct device_attribute *attr, char *buf)
334{
335 struct fw_device *device = fw_device(dev->parent);
336 struct fw_unit *unit = fw_unit(dev);
337
338 return snprintf(buf, PAGE_SIZE, "%d\n",
339 (int)(unit->directory - device->config_rom));
340}
341
342static struct device_attribute fw_unit_attributes[] = {
343 __ATTR_RO(modalias),
344 __ATTR_RO(rom_index),
345 __ATTR_NULL,
346};
347
348static ssize_t
349config_rom_show(struct device *dev, struct device_attribute *attr, char *buf)
350{
351 struct fw_device *device = fw_device(dev);
352
353 memcpy(buf, device->config_rom, device->config_rom_length * 4);
354
355 return device->config_rom_length * 4;
356}
357
358static ssize_t
359guid_show(struct device *dev, struct device_attribute *attr, char *buf)
360{
361 struct fw_device *device = fw_device(dev);
362 u64 guid;
363
364 guid = ((u64)device->config_rom[3] << 32) | device->config_rom[4];
365
366 return snprintf(buf, PAGE_SIZE, "0x%016llx\n",
367 (unsigned long long)guid);
368}
369
370static struct device_attribute fw_device_attributes[] = {
371 __ATTR_RO(config_rom),
372 __ATTR_RO(guid),
373 __ATTR_NULL,
374};
375
376struct read_quadlet_callback_data {
377 struct completion done;
378 int rcode;
379 u32 data;
380};
381
382static void
383complete_transaction(struct fw_card *card, int rcode,
384 void *payload, size_t length, void *data)
385{
386 struct read_quadlet_callback_data *callback_data = data;
387
388 if (rcode == RCODE_COMPLETE)
389 callback_data->data = be32_to_cpu(*(__be32 *)payload);
390 callback_data->rcode = rcode;
391 complete(&callback_data->done);
392}
393
394static int read_rom(struct fw_device *device, int index, u32 * data)
395{
396 struct read_quadlet_callback_data callback_data;
397 struct fw_transaction t;
398 u64 offset;
399
400 init_completion(&callback_data.done);
401
402 offset = 0xfffff0000400ULL + index * 4;
403 fw_send_request(device->card, &t, TCODE_READ_QUADLET_REQUEST,
404 device->node_id,
405 device->generation, SCODE_100,
406 offset, NULL, 4, complete_transaction, &callback_data);
407
408 wait_for_completion(&callback_data.done);
409
410 *data = callback_data.data;
411
412 return callback_data.rcode;
413}
414
415static int read_bus_info_block(struct fw_device *device)
416{
417 static u32 rom[256];
418 u32 stack[16], sp, key;
419 int i, end, length;
420
421 /* First read the bus info block. */
422 for (i = 0; i < 5; i++) {
423 if (read_rom(device, i, &rom[i]) != RCODE_COMPLETE)
424 return -1;
425 /*
426 * As per IEEE1212 7.2, during power-up, devices can
427 * reply with a 0 for the first quadlet of the config
428 * rom to indicate that they are booting (for example,
429 * if the firmware is on the disk of a external
430 * harddisk). In that case we just fail, and the
431 * retry mechanism will try again later.
432 */
433 if (i == 0 && rom[i] == 0)
434 return -1;
435 }
436
437 /*
438 * Now parse the config rom. The config rom is a recursive
439 * directory structure so we parse it using a stack of
440 * references to the blocks that make up the structure. We
441 * push a reference to the root directory on the stack to
442 * start things off.
443 */
444 length = i;
445 sp = 0;
446 stack[sp++] = 0xc0000005;
447 while (sp > 0) {
448 /*
449 * Pop the next block reference of the stack. The
450 * lower 24 bits is the offset into the config rom,
451 * the upper 8 bits are the type of the reference the
452 * block.
453 */
454 key = stack[--sp];
455 i = key & 0xffffff;
456 if (i >= ARRAY_SIZE(rom))
457 /*
458 * The reference points outside the standard
459 * config rom area, something's fishy.
460 */
461 return -1;
462
463 /* Read header quadlet for the block to get the length. */
464 if (read_rom(device, i, &rom[i]) != RCODE_COMPLETE)
465 return -1;
466 end = i + (rom[i] >> 16) + 1;
467 i++;
468 if (end > ARRAY_SIZE(rom))
469 /*
470 * This block extends outside standard config
471 * area (and the array we're reading it
472 * into). That's broken, so ignore this
473 * device.
474 */
475 return -1;
476
477 /*
478 * Now read in the block. If this is a directory
479 * block, check the entries as we read them to see if
480 * it references another block, and push it in that case.
481 */
482 while (i < end) {
483 if (read_rom(device, i, &rom[i]) != RCODE_COMPLETE)
484 return -1;
485 if ((key >> 30) == 3 && (rom[i] >> 30) > 1 &&
486 sp < ARRAY_SIZE(stack))
487 stack[sp++] = i + rom[i];
488 i++;
489 }
490 if (length < i)
491 length = i;
492 }
493
494 device->config_rom = kmalloc(length * 4, GFP_KERNEL);
495 if (device->config_rom == NULL)
496 return -1;
497 memcpy(device->config_rom, rom, length * 4);
498 device->config_rom_length = length;
499
500 return 0;
501}
502
503static void fw_unit_release(struct device *dev)
504{
505 struct fw_unit *unit = fw_unit(dev);
506
507 kfree(unit);
508}
509
510static struct device_type fw_unit_type = {
511 .uevent = fw_unit_uevent,
512 .release = fw_unit_release,
513};
514
515static int is_fw_unit(struct device *dev)
516{
517 return dev->type == &fw_unit_type;
518}
519
520static void create_units(struct fw_device *device)
521{
522 struct fw_csr_iterator ci;
523 struct fw_unit *unit;
524 int key, value, i;
525
526 i = 0;
527 fw_csr_iterator_init(&ci, &device->config_rom[5]);
528 while (fw_csr_iterator_next(&ci, &key, &value)) {
529 if (key != (CSR_UNIT | CSR_DIRECTORY))
530 continue;
531
532 /*
533 * Get the address of the unit directory and try to
534 * match the drivers id_tables against it.
535 */
536 unit = kzalloc(sizeof(*unit), GFP_KERNEL);
537 if (unit == NULL) {
538 fw_error("failed to allocate memory for unit\n");
539 continue;
540 }
541
542 unit->directory = ci.p + value - 1;
543 unit->device.bus = &fw_bus_type;
544 unit->device.type = &fw_unit_type;
545 unit->device.parent = &device->device;
546 snprintf(unit->device.bus_id, sizeof(unit->device.bus_id),
547 "%s.%d", device->device.bus_id, i++);
548
549 init_fw_attribute_group(&unit->device,
550 fw_unit_attributes,
551 &unit->attribute_group);
552 if (device_register(&unit->device) < 0)
553 goto skip_unit;
554
555 continue;
556
557 skip_unit:
558 kfree(unit);
559 }
560}
561
562static int shutdown_unit(struct device *device, void *data)
563{
564 device_unregister(device);
565
566 return 0;
567}
568
569static DECLARE_RWSEM(idr_rwsem);
570static DEFINE_IDR(fw_device_idr);
571int fw_cdev_major;
572
573struct fw_device *fw_device_from_devt(dev_t devt)
574{
575 struct fw_device *device;
576
577 down_read(&idr_rwsem);
578 device = idr_find(&fw_device_idr, MINOR(devt));
579 up_read(&idr_rwsem);
580
581 return device;
582}
583
584static void fw_device_shutdown(struct work_struct *work)
585{
586 struct fw_device *device =
587 container_of(work, struct fw_device, work.work);
588 int minor = MINOR(device->device.devt);
589
590 down_write(&idr_rwsem);
591 idr_remove(&fw_device_idr, minor);
592 up_write(&idr_rwsem);
593
594 fw_device_cdev_remove(device);
595 device_for_each_child(&device->device, NULL, shutdown_unit);
596 device_unregister(&device->device);
597}
598
599static struct device_type fw_device_type = {
600 .release = fw_device_release,
601};
602
603/*
604 * These defines control the retry behavior for reading the config
605 * rom. It shouldn't be necessary to tweak these; if the device
606 * doesn't respond to a config rom read within 10 seconds, it's not
607 * going to respond at all. As for the initial delay, a lot of
608 * devices will be able to respond within half a second after bus
609 * reset. On the other hand, it's not really worth being more
610 * aggressive than that, since it scales pretty well; if 10 devices
611 * are plugged in, they're all getting read within one second.
612 */
613
614#define MAX_RETRIES 10
615#define RETRY_DELAY (3 * HZ)
616#define INITIAL_DELAY (HZ / 2)
617
618static void fw_device_init(struct work_struct *work)
619{
620 struct fw_device *device =
621 container_of(work, struct fw_device, work.work);
622 int minor, err;
623
624 /*
625 * All failure paths here set node->data to NULL, so that we
626 * don't try to do device_for_each_child() on a kfree()'d
627 * device.
628 */
629
630 if (read_bus_info_block(device) < 0) {
631 if (device->config_rom_retries < MAX_RETRIES) {
632 device->config_rom_retries++;
633 schedule_delayed_work(&device->work, RETRY_DELAY);
634 } else {
635 fw_notify("giving up on config rom for node id %x\n",
636 device->node_id);
637 if (device->node == device->card->root_node)
638 schedule_delayed_work(&device->card->work, 0);
639 fw_device_release(&device->device);
640 }
641 return;
642 }
643
644 err = -ENOMEM;
645 down_write(&idr_rwsem);
646 if (idr_pre_get(&fw_device_idr, GFP_KERNEL))
647 err = idr_get_new(&fw_device_idr, device, &minor);
648 up_write(&idr_rwsem);
649 if (err < 0)
650 goto error;
651
652 device->device.bus = &fw_bus_type;
653 device->device.type = &fw_device_type;
654 device->device.parent = device->card->device;
655 device->device.devt = MKDEV(fw_cdev_major, minor);
656 snprintf(device->device.bus_id, sizeof(device->device.bus_id),
657 "fw%d", minor);
658
659 init_fw_attribute_group(&device->device,
660 fw_device_attributes,
661 &device->attribute_group);
662 if (device_add(&device->device)) {
663 fw_error("Failed to add device.\n");
664 goto error_with_cdev;
665 }
666
667 create_units(device);
668
669 /*
670 * Transition the device to running state. If it got pulled
671 * out from under us while we did the intialization work, we
672 * have to shut down the device again here. Normally, though,
673 * fw_node_event will be responsible for shutting it down when
674 * necessary. We have to use the atomic cmpxchg here to avoid
675 * racing with the FW_NODE_DESTROYED case in
676 * fw_node_event().
677 */
678 if (atomic_cmpxchg(&device->state,
679 FW_DEVICE_INITIALIZING,
680 FW_DEVICE_RUNNING) == FW_DEVICE_SHUTDOWN)
681 fw_device_shutdown(&device->work.work);
682 else
683 fw_notify("created new fw device %s (%d config rom retries)\n",
684 device->device.bus_id, device->config_rom_retries);
685
686 /*
687 * Reschedule the IRM work if we just finished reading the
688 * root node config rom. If this races with a bus reset we
689 * just end up running the IRM work a couple of extra times -
690 * pretty harmless.
691 */
692 if (device->node == device->card->root_node)
693 schedule_delayed_work(&device->card->work, 0);
694
695 return;
696
697 error_with_cdev:
698 down_write(&idr_rwsem);
699 idr_remove(&fw_device_idr, minor);
700 up_write(&idr_rwsem);
701 error:
702 put_device(&device->device);
703}
704
705static int update_unit(struct device *dev, void *data)
706{
707 struct fw_unit *unit = fw_unit(dev);
708 struct fw_driver *driver = (struct fw_driver *)dev->driver;
709
710 if (is_fw_unit(dev) && driver != NULL && driver->update != NULL) {
711 down(&dev->sem);
712 driver->update(unit);
713 up(&dev->sem);
714 }
715
716 return 0;
717}
718
719static void fw_device_update(struct work_struct *work)
720{
721 struct fw_device *device =
722 container_of(work, struct fw_device, work.work);
723
724 fw_device_cdev_update(device);
725 device_for_each_child(&device->device, NULL, update_unit);
726}
727
728void fw_node_event(struct fw_card *card, struct fw_node *node, int event)
729{
730 struct fw_device *device;
731
732 switch (event) {
733 case FW_NODE_CREATED:
734 case FW_NODE_LINK_ON:
735 if (!node->link_on)
736 break;
737
738 device = kzalloc(sizeof(*device), GFP_ATOMIC);
739 if (device == NULL)
740 break;
741
742 /*
743 * Do minimal intialization of the device here, the
744 * rest will happen in fw_device_init(). We need the
745 * card and node so we can read the config rom and we
746 * need to do device_initialize() now so
747 * device_for_each_child() in FW_NODE_UPDATED is
748 * doesn't freak out.
749 */
750 device_initialize(&device->device);
751 atomic_set(&device->state, FW_DEVICE_INITIALIZING);
752 device->card = fw_card_get(card);
753 device->node = fw_node_get(node);
754 device->node_id = node->node_id;
755 device->generation = card->generation;
756 INIT_LIST_HEAD(&device->client_list);
757
758 /*
759 * Set the node data to point back to this device so
760 * FW_NODE_UPDATED callbacks can update the node_id
761 * and generation for the device.
762 */
763 node->data = device;
764
765 /*
766 * Many devices are slow to respond after bus resets,
767 * especially if they are bus powered and go through
768 * power-up after getting plugged in. We schedule the
769 * first config rom scan half a second after bus reset.
770 */
771 INIT_DELAYED_WORK(&device->work, fw_device_init);
772 schedule_delayed_work(&device->work, INITIAL_DELAY);
773 break;
774
775 case FW_NODE_UPDATED:
776 if (!node->link_on || node->data == NULL)
777 break;
778
779 device = node->data;
780 device->node_id = node->node_id;
781 device->generation = card->generation;
782 if (atomic_read(&device->state) == FW_DEVICE_RUNNING) {
783 PREPARE_DELAYED_WORK(&device->work, fw_device_update);
784 schedule_delayed_work(&device->work, 0);
785 }
786 break;
787
788 case FW_NODE_DESTROYED:
789 case FW_NODE_LINK_OFF:
790 if (!node->data)
791 break;
792
793 /*
794 * Destroy the device associated with the node. There
795 * are two cases here: either the device is fully
796 * initialized (FW_DEVICE_RUNNING) or we're in the
797 * process of reading its config rom
798 * (FW_DEVICE_INITIALIZING). If it is fully
799 * initialized we can reuse device->work to schedule a
800 * full fw_device_shutdown(). If not, there's work
801 * scheduled to read it's config rom, and we just put
802 * the device in shutdown state to have that code fail
803 * to create the device.
804 */
805 device = node->data;
806 if (atomic_xchg(&device->state,
807 FW_DEVICE_SHUTDOWN) == FW_DEVICE_RUNNING) {
808 PREPARE_DELAYED_WORK(&device->work, fw_device_shutdown);
809 schedule_delayed_work(&device->work, 0);
810 }
811 break;
812 }
813}
diff --git a/drivers/firewire/fw-device.h b/drivers/firewire/fw-device.h
new file mode 100644
index 000000000000..0ba9d64ccf4c
--- /dev/null
+++ b/drivers/firewire/fw-device.h
@@ -0,0 +1,146 @@
1/*
2 * Copyright (C) 2005-2006 Kristian Hoegsberg <krh@bitplanet.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef __fw_device_h
20#define __fw_device_h
21
22#include <linux/fs.h>
23#include <linux/cdev.h>
24#include <asm/atomic.h>
25
26enum fw_device_state {
27 FW_DEVICE_INITIALIZING,
28 FW_DEVICE_RUNNING,
29 FW_DEVICE_SHUTDOWN,
30};
31
32struct fw_attribute_group {
33 struct attribute_group *groups[2];
34 struct attribute_group group;
35 struct attribute *attrs[11];
36};
37
38struct fw_device {
39 atomic_t state;
40 struct fw_node *node;
41 int node_id;
42 int generation;
43 struct fw_card *card;
44 struct device device;
45 struct list_head link;
46 struct list_head client_list;
47 u32 *config_rom;
48 size_t config_rom_length;
49 int config_rom_retries;
50 struct delayed_work work;
51 struct fw_attribute_group attribute_group;
52};
53
54static inline struct fw_device *
55fw_device(struct device *dev)
56{
57 return container_of(dev, struct fw_device, device);
58}
59
60static inline int
61fw_device_is_shutdown(struct fw_device *device)
62{
63 return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
64}
65
66struct fw_device *fw_device_get(struct fw_device *device);
67void fw_device_put(struct fw_device *device);
68int fw_device_enable_phys_dma(struct fw_device *device);
69
70void fw_device_cdev_update(struct fw_device *device);
71void fw_device_cdev_remove(struct fw_device *device);
72
73struct fw_device *fw_device_from_devt(dev_t devt);
74extern int fw_cdev_major;
75
76struct fw_unit {
77 struct device device;
78 u32 *directory;
79 struct fw_attribute_group attribute_group;
80};
81
82static inline struct fw_unit *
83fw_unit(struct device *dev)
84{
85 return container_of(dev, struct fw_unit, device);
86}
87
88#define CSR_OFFSET 0x40
89#define CSR_LEAF 0x80
90#define CSR_DIRECTORY 0xc0
91
92#define CSR_DESCRIPTOR 0x01
93#define CSR_VENDOR 0x03
94#define CSR_HARDWARE_VERSION 0x04
95#define CSR_NODE_CAPABILITIES 0x0c
96#define CSR_UNIT 0x11
97#define CSR_SPECIFIER_ID 0x12
98#define CSR_VERSION 0x13
99#define CSR_DEPENDENT_INFO 0x14
100#define CSR_MODEL 0x17
101#define CSR_INSTANCE 0x18
102
103#define SBP2_COMMAND_SET_SPECIFIER 0x38
104#define SBP2_COMMAND_SET 0x39
105#define SBP2_COMMAND_SET_REVISION 0x3b
106#define SBP2_FIRMWARE_REVISION 0x3c
107
108struct fw_csr_iterator {
109 u32 *p;
110 u32 *end;
111};
112
113void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
114int fw_csr_iterator_next(struct fw_csr_iterator *ci,
115 int *key, int *value);
116
117#define FW_MATCH_VENDOR 0x0001
118#define FW_MATCH_MODEL 0x0002
119#define FW_MATCH_SPECIFIER_ID 0x0004
120#define FW_MATCH_VERSION 0x0008
121
122struct fw_device_id {
123 u32 match_flags;
124 u32 vendor;
125 u32 model;
126 u32 specifier_id;
127 u32 version;
128 void *driver_data;
129};
130
131struct fw_driver {
132 struct device_driver driver;
133 /* Called when the parent device sits through a bus reset. */
134 void (*update) (struct fw_unit *unit);
135 const struct fw_device_id *id_table;
136};
137
138static inline struct fw_driver *
139fw_driver(struct device_driver *drv)
140{
141 return container_of(drv, struct fw_driver, driver);
142}
143
144extern const struct file_operations fw_device_ops;
145
146#endif /* __fw_device_h */
diff --git a/drivers/firewire/fw-iso.c b/drivers/firewire/fw-iso.c
new file mode 100644
index 000000000000..2b640e9be6de
--- /dev/null
+++ b/drivers/firewire/fw-iso.c
@@ -0,0 +1,163 @@
1/*
2 * Isochronous IO functionality
3 *
4 * Copyright (C) 2006 Kristian Hoegsberg <krh@bitplanet.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/dma-mapping.h>
24#include <linux/vmalloc.h>
25#include <linux/mm.h>
26
27#include "fw-transaction.h"
28#include "fw-topology.h"
29#include "fw-device.h"
30
31int
32fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
33 int page_count, enum dma_data_direction direction)
34{
35 int i, j, retval = -ENOMEM;
36 dma_addr_t address;
37
38 buffer->page_count = page_count;
39 buffer->direction = direction;
40
41 buffer->pages = kmalloc(page_count * sizeof(buffer->pages[0]),
42 GFP_KERNEL);
43 if (buffer->pages == NULL)
44 goto out;
45
46 for (i = 0; i < buffer->page_count; i++) {
47 buffer->pages[i] = alloc_page(GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
48 if (buffer->pages[i] == NULL)
49 goto out_pages;
50
51 address = dma_map_page(card->device, buffer->pages[i],
52 0, PAGE_SIZE, direction);
53 if (dma_mapping_error(address)) {
54 __free_page(buffer->pages[i]);
55 goto out_pages;
56 }
57 set_page_private(buffer->pages[i], address);
58 }
59
60 return 0;
61
62 out_pages:
63 for (j = 0; j < i; j++) {
64 address = page_private(buffer->pages[j]);
65 dma_unmap_page(card->device, address,
66 PAGE_SIZE, DMA_TO_DEVICE);
67 __free_page(buffer->pages[j]);
68 }
69 kfree(buffer->pages);
70 out:
71 buffer->pages = NULL;
72 return retval;
73}
74
75int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma)
76{
77 unsigned long uaddr;
78 int i, retval;
79
80 uaddr = vma->vm_start;
81 for (i = 0; i < buffer->page_count; i++) {
82 retval = vm_insert_page(vma, uaddr, buffer->pages[i]);
83 if (retval)
84 return retval;
85 uaddr += PAGE_SIZE;
86 }
87
88 return 0;
89}
90
91void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
92 struct fw_card *card)
93{
94 int i;
95 dma_addr_t address;
96
97 for (i = 0; i < buffer->page_count; i++) {
98 address = page_private(buffer->pages[i]);
99 dma_unmap_page(card->device, address,
100 PAGE_SIZE, DMA_TO_DEVICE);
101 __free_page(buffer->pages[i]);
102 }
103
104 kfree(buffer->pages);
105 buffer->pages = NULL;
106}
107
108struct fw_iso_context *
109fw_iso_context_create(struct fw_card *card, int type,
110 int channel, int speed, size_t header_size,
111 fw_iso_callback_t callback, void *callback_data)
112{
113 struct fw_iso_context *ctx;
114
115 ctx = card->driver->allocate_iso_context(card, type, header_size);
116 if (IS_ERR(ctx))
117 return ctx;
118
119 ctx->card = card;
120 ctx->type = type;
121 ctx->channel = channel;
122 ctx->speed = speed;
123 ctx->header_size = header_size;
124 ctx->callback = callback;
125 ctx->callback_data = callback_data;
126
127 return ctx;
128}
129EXPORT_SYMBOL(fw_iso_context_create);
130
131void fw_iso_context_destroy(struct fw_iso_context *ctx)
132{
133 struct fw_card *card = ctx->card;
134
135 card->driver->free_iso_context(ctx);
136}
137EXPORT_SYMBOL(fw_iso_context_destroy);
138
139int
140fw_iso_context_start(struct fw_iso_context *ctx, int cycle, int sync, int tags)
141{
142 return ctx->card->driver->start_iso(ctx, cycle, sync, tags);
143}
144EXPORT_SYMBOL(fw_iso_context_start);
145
146int
147fw_iso_context_queue(struct fw_iso_context *ctx,
148 struct fw_iso_packet *packet,
149 struct fw_iso_buffer *buffer,
150 unsigned long payload)
151{
152 struct fw_card *card = ctx->card;
153
154 return card->driver->queue_iso(ctx, packet, buffer, payload);
155}
156EXPORT_SYMBOL(fw_iso_context_queue);
157
158int
159fw_iso_context_stop(struct fw_iso_context *ctx)
160{
161 return ctx->card->driver->stop_iso(ctx);
162}
163EXPORT_SYMBOL(fw_iso_context_stop);
diff --git a/drivers/firewire/fw-ohci.c b/drivers/firewire/fw-ohci.c
new file mode 100644
index 000000000000..c17342d3e6fd
--- /dev/null
+++ b/drivers/firewire/fw-ohci.c
@@ -0,0 +1,1944 @@
1/*
2 * Driver for OHCI 1394 controllers
3 *
4 * Copyright (C) 2003-2006 Kristian Hoegsberg <krh@bitplanet.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/pci.h>
26#include <linux/delay.h>
27#include <linux/poll.h>
28#include <linux/dma-mapping.h>
29#include <linux/mm.h>
30
31#include <asm/uaccess.h>
32#include <asm/semaphore.h>
33
34#include "fw-transaction.h"
35#include "fw-ohci.h"
36
37#define DESCRIPTOR_OUTPUT_MORE 0
38#define DESCRIPTOR_OUTPUT_LAST (1 << 12)
39#define DESCRIPTOR_INPUT_MORE (2 << 12)
40#define DESCRIPTOR_INPUT_LAST (3 << 12)
41#define DESCRIPTOR_STATUS (1 << 11)
42#define DESCRIPTOR_KEY_IMMEDIATE (2 << 8)
43#define DESCRIPTOR_PING (1 << 7)
44#define DESCRIPTOR_YY (1 << 6)
45#define DESCRIPTOR_NO_IRQ (0 << 4)
46#define DESCRIPTOR_IRQ_ERROR (1 << 4)
47#define DESCRIPTOR_IRQ_ALWAYS (3 << 4)
48#define DESCRIPTOR_BRANCH_ALWAYS (3 << 2)
49#define DESCRIPTOR_WAIT (3 << 0)
50
51struct descriptor {
52 __le16 req_count;
53 __le16 control;
54 __le32 data_address;
55 __le32 branch_address;
56 __le16 res_count;
57 __le16 transfer_status;
58} __attribute__((aligned(16)));
59
60struct db_descriptor {
61 __le16 first_size;
62 __le16 control;
63 __le16 second_req_count;
64 __le16 first_req_count;
65 __le32 branch_address;
66 __le16 second_res_count;
67 __le16 first_res_count;
68 __le32 reserved0;
69 __le32 first_buffer;
70 __le32 second_buffer;
71 __le32 reserved1;
72} __attribute__((aligned(16)));
73
74#define CONTROL_SET(regs) (regs)
75#define CONTROL_CLEAR(regs) ((regs) + 4)
76#define COMMAND_PTR(regs) ((regs) + 12)
77#define CONTEXT_MATCH(regs) ((regs) + 16)
78
79struct ar_buffer {
80 struct descriptor descriptor;
81 struct ar_buffer *next;
82 __le32 data[0];
83};
84
85struct ar_context {
86 struct fw_ohci *ohci;
87 struct ar_buffer *current_buffer;
88 struct ar_buffer *last_buffer;
89 void *pointer;
90 u32 regs;
91 struct tasklet_struct tasklet;
92};
93
94struct context;
95
96typedef int (*descriptor_callback_t)(struct context *ctx,
97 struct descriptor *d,
98 struct descriptor *last);
99struct context {
100 struct fw_ohci *ohci;
101 u32 regs;
102
103 struct descriptor *buffer;
104 dma_addr_t buffer_bus;
105 size_t buffer_size;
106 struct descriptor *head_descriptor;
107 struct descriptor *tail_descriptor;
108 struct descriptor *tail_descriptor_last;
109 struct descriptor *prev_descriptor;
110
111 descriptor_callback_t callback;
112
113 struct tasklet_struct tasklet;
114};
115
116#define IT_HEADER_SY(v) ((v) << 0)
117#define IT_HEADER_TCODE(v) ((v) << 4)
118#define IT_HEADER_CHANNEL(v) ((v) << 8)
119#define IT_HEADER_TAG(v) ((v) << 14)
120#define IT_HEADER_SPEED(v) ((v) << 16)
121#define IT_HEADER_DATA_LENGTH(v) ((v) << 16)
122
123struct iso_context {
124 struct fw_iso_context base;
125 struct context context;
126 void *header;
127 size_t header_length;
128};
129
130#define CONFIG_ROM_SIZE 1024
131
132struct fw_ohci {
133 struct fw_card card;
134
135 u32 version;
136 __iomem char *registers;
137 dma_addr_t self_id_bus;
138 __le32 *self_id_cpu;
139 struct tasklet_struct bus_reset_tasklet;
140 int node_id;
141 int generation;
142 int request_generation;
143 u32 bus_seconds;
144
145 /*
146 * Spinlock for accessing fw_ohci data. Never call out of
147 * this driver with this lock held.
148 */
149 spinlock_t lock;
150 u32 self_id_buffer[512];
151
152 /* Config rom buffers */
153 __be32 *config_rom;
154 dma_addr_t config_rom_bus;
155 __be32 *next_config_rom;
156 dma_addr_t next_config_rom_bus;
157 u32 next_header;
158
159 struct ar_context ar_request_ctx;
160 struct ar_context ar_response_ctx;
161 struct context at_request_ctx;
162 struct context at_response_ctx;
163
164 u32 it_context_mask;
165 struct iso_context *it_context_list;
166 u32 ir_context_mask;
167 struct iso_context *ir_context_list;
168};
169
170static inline struct fw_ohci *fw_ohci(struct fw_card *card)
171{
172 return container_of(card, struct fw_ohci, card);
173}
174
175#define IT_CONTEXT_CYCLE_MATCH_ENABLE 0x80000000
176#define IR_CONTEXT_BUFFER_FILL 0x80000000
177#define IR_CONTEXT_ISOCH_HEADER 0x40000000
178#define IR_CONTEXT_CYCLE_MATCH_ENABLE 0x20000000
179#define IR_CONTEXT_MULTI_CHANNEL_MODE 0x10000000
180#define IR_CONTEXT_DUAL_BUFFER_MODE 0x08000000
181
182#define CONTEXT_RUN 0x8000
183#define CONTEXT_WAKE 0x1000
184#define CONTEXT_DEAD 0x0800
185#define CONTEXT_ACTIVE 0x0400
186
187#define OHCI1394_MAX_AT_REQ_RETRIES 0x2
188#define OHCI1394_MAX_AT_RESP_RETRIES 0x2
189#define OHCI1394_MAX_PHYS_RESP_RETRIES 0x8
190
191#define FW_OHCI_MAJOR 240
192#define OHCI1394_REGISTER_SIZE 0x800
193#define OHCI_LOOP_COUNT 500
194#define OHCI1394_PCI_HCI_Control 0x40
195#define SELF_ID_BUF_SIZE 0x800
196#define OHCI_TCODE_PHY_PACKET 0x0e
197#define OHCI_VERSION_1_1 0x010010
198#define ISO_BUFFER_SIZE (64 * 1024)
199#define AT_BUFFER_SIZE 4096
200
201static char ohci_driver_name[] = KBUILD_MODNAME;
202
203static inline void reg_write(const struct fw_ohci *ohci, int offset, u32 data)
204{
205 writel(data, ohci->registers + offset);
206}
207
208static inline u32 reg_read(const struct fw_ohci *ohci, int offset)
209{
210 return readl(ohci->registers + offset);
211}
212
213static inline void flush_writes(const struct fw_ohci *ohci)
214{
215 /* Do a dummy read to flush writes. */
216 reg_read(ohci, OHCI1394_Version);
217}
218
219static int
220ohci_update_phy_reg(struct fw_card *card, int addr,
221 int clear_bits, int set_bits)
222{
223 struct fw_ohci *ohci = fw_ohci(card);
224 u32 val, old;
225
226 reg_write(ohci, OHCI1394_PhyControl, OHCI1394_PhyControl_Read(addr));
227 msleep(2);
228 val = reg_read(ohci, OHCI1394_PhyControl);
229 if ((val & OHCI1394_PhyControl_ReadDone) == 0) {
230 fw_error("failed to set phy reg bits.\n");
231 return -EBUSY;
232 }
233
234 old = OHCI1394_PhyControl_ReadData(val);
235 old = (old & ~clear_bits) | set_bits;
236 reg_write(ohci, OHCI1394_PhyControl,
237 OHCI1394_PhyControl_Write(addr, old));
238
239 return 0;
240}
241
242static int ar_context_add_page(struct ar_context *ctx)
243{
244 struct device *dev = ctx->ohci->card.device;
245 struct ar_buffer *ab;
246 dma_addr_t ab_bus;
247 size_t offset;
248
249 ab = (struct ar_buffer *) __get_free_page(GFP_ATOMIC);
250 if (ab == NULL)
251 return -ENOMEM;
252
253 ab_bus = dma_map_single(dev, ab, PAGE_SIZE, DMA_BIDIRECTIONAL);
254 if (dma_mapping_error(ab_bus)) {
255 free_page((unsigned long) ab);
256 return -ENOMEM;
257 }
258
259 memset(&ab->descriptor, 0, sizeof(ab->descriptor));
260 ab->descriptor.control = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
261 DESCRIPTOR_STATUS |
262 DESCRIPTOR_BRANCH_ALWAYS);
263 offset = offsetof(struct ar_buffer, data);
264 ab->descriptor.req_count = cpu_to_le16(PAGE_SIZE - offset);
265 ab->descriptor.data_address = cpu_to_le32(ab_bus + offset);
266 ab->descriptor.res_count = cpu_to_le16(PAGE_SIZE - offset);
267 ab->descriptor.branch_address = 0;
268
269 dma_sync_single_for_device(dev, ab_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
270
271 ctx->last_buffer->descriptor.branch_address = ab_bus | 1;
272 ctx->last_buffer->next = ab;
273 ctx->last_buffer = ab;
274
275 reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE);
276 flush_writes(ctx->ohci);
277
278 return 0;
279}
280
281static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
282{
283 struct fw_ohci *ohci = ctx->ohci;
284 struct fw_packet p;
285 u32 status, length, tcode;
286
287 p.header[0] = le32_to_cpu(buffer[0]);
288 p.header[1] = le32_to_cpu(buffer[1]);
289 p.header[2] = le32_to_cpu(buffer[2]);
290
291 tcode = (p.header[0] >> 4) & 0x0f;
292 switch (tcode) {
293 case TCODE_WRITE_QUADLET_REQUEST:
294 case TCODE_READ_QUADLET_RESPONSE:
295 p.header[3] = (__force __u32) buffer[3];
296 p.header_length = 16;
297 p.payload_length = 0;
298 break;
299
300 case TCODE_READ_BLOCK_REQUEST :
301 p.header[3] = le32_to_cpu(buffer[3]);
302 p.header_length = 16;
303 p.payload_length = 0;
304 break;
305
306 case TCODE_WRITE_BLOCK_REQUEST:
307 case TCODE_READ_BLOCK_RESPONSE:
308 case TCODE_LOCK_REQUEST:
309 case TCODE_LOCK_RESPONSE:
310 p.header[3] = le32_to_cpu(buffer[3]);
311 p.header_length = 16;
312 p.payload_length = p.header[3] >> 16;
313 break;
314
315 case TCODE_WRITE_RESPONSE:
316 case TCODE_READ_QUADLET_REQUEST:
317 case OHCI_TCODE_PHY_PACKET:
318 p.header_length = 12;
319 p.payload_length = 0;
320 break;
321 }
322
323 p.payload = (void *) buffer + p.header_length;
324
325 /* FIXME: What to do about evt_* errors? */
326 length = (p.header_length + p.payload_length + 3) / 4;
327 status = le32_to_cpu(buffer[length]);
328
329 p.ack = ((status >> 16) & 0x1f) - 16;
330 p.speed = (status >> 21) & 0x7;
331 p.timestamp = status & 0xffff;
332 p.generation = ohci->request_generation;
333
334 /*
335 * The OHCI bus reset handler synthesizes a phy packet with
336 * the new generation number when a bus reset happens (see
337 * section 8.4.2.3). This helps us determine when a request
338 * was received and make sure we send the response in the same
339 * generation. We only need this for requests; for responses
340 * we use the unique tlabel for finding the matching
341 * request.
342 */
343
344 if (p.ack + 16 == 0x09)
345 ohci->request_generation = (buffer[2] >> 16) & 0xff;
346 else if (ctx == &ohci->ar_request_ctx)
347 fw_core_handle_request(&ohci->card, &p);
348 else
349 fw_core_handle_response(&ohci->card, &p);
350
351 return buffer + length + 1;
352}
353
354static void ar_context_tasklet(unsigned long data)
355{
356 struct ar_context *ctx = (struct ar_context *)data;
357 struct fw_ohci *ohci = ctx->ohci;
358 struct ar_buffer *ab;
359 struct descriptor *d;
360 void *buffer, *end;
361
362 ab = ctx->current_buffer;
363 d = &ab->descriptor;
364
365 if (d->res_count == 0) {
366 size_t size, rest, offset;
367
368 /*
369 * This descriptor is finished and we may have a
370 * packet split across this and the next buffer. We
371 * reuse the page for reassembling the split packet.
372 */
373
374 offset = offsetof(struct ar_buffer, data);
375 dma_unmap_single(ohci->card.device,
376 ab->descriptor.data_address - offset,
377 PAGE_SIZE, DMA_BIDIRECTIONAL);
378
379 buffer = ab;
380 ab = ab->next;
381 d = &ab->descriptor;
382 size = buffer + PAGE_SIZE - ctx->pointer;
383 rest = le16_to_cpu(d->req_count) - le16_to_cpu(d->res_count);
384 memmove(buffer, ctx->pointer, size);
385 memcpy(buffer + size, ab->data, rest);
386 ctx->current_buffer = ab;
387 ctx->pointer = (void *) ab->data + rest;
388 end = buffer + size + rest;
389
390 while (buffer < end)
391 buffer = handle_ar_packet(ctx, buffer);
392
393 free_page((unsigned long)buffer);
394 ar_context_add_page(ctx);
395 } else {
396 buffer = ctx->pointer;
397 ctx->pointer = end =
398 (void *) ab + PAGE_SIZE - le16_to_cpu(d->res_count);
399
400 while (buffer < end)
401 buffer = handle_ar_packet(ctx, buffer);
402 }
403}
404
405static int
406ar_context_init(struct ar_context *ctx, struct fw_ohci *ohci, u32 regs)
407{
408 struct ar_buffer ab;
409
410 ctx->regs = regs;
411 ctx->ohci = ohci;
412 ctx->last_buffer = &ab;
413 tasklet_init(&ctx->tasklet, ar_context_tasklet, (unsigned long)ctx);
414
415 ar_context_add_page(ctx);
416 ar_context_add_page(ctx);
417 ctx->current_buffer = ab.next;
418 ctx->pointer = ctx->current_buffer->data;
419
420 reg_write(ctx->ohci, COMMAND_PTR(ctx->regs), ab.descriptor.branch_address);
421 reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN);
422 flush_writes(ctx->ohci);
423
424 return 0;
425}
426
427static void context_tasklet(unsigned long data)
428{
429 struct context *ctx = (struct context *) data;
430 struct fw_ohci *ohci = ctx->ohci;
431 struct descriptor *d, *last;
432 u32 address;
433 int z;
434
435 dma_sync_single_for_cpu(ohci->card.device, ctx->buffer_bus,
436 ctx->buffer_size, DMA_TO_DEVICE);
437
438 d = ctx->tail_descriptor;
439 last = ctx->tail_descriptor_last;
440
441 while (last->branch_address != 0) {
442 address = le32_to_cpu(last->branch_address);
443 z = address & 0xf;
444 d = ctx->buffer + (address - ctx->buffer_bus) / sizeof(*d);
445 last = (z == 2) ? d : d + z - 1;
446
447 if (!ctx->callback(ctx, d, last))
448 break;
449
450 ctx->tail_descriptor = d;
451 ctx->tail_descriptor_last = last;
452 }
453}
454
455static int
456context_init(struct context *ctx, struct fw_ohci *ohci,
457 size_t buffer_size, u32 regs,
458 descriptor_callback_t callback)
459{
460 ctx->ohci = ohci;
461 ctx->regs = regs;
462 ctx->buffer_size = buffer_size;
463 ctx->buffer = kmalloc(buffer_size, GFP_KERNEL);
464 if (ctx->buffer == NULL)
465 return -ENOMEM;
466
467 tasklet_init(&ctx->tasklet, context_tasklet, (unsigned long)ctx);
468 ctx->callback = callback;
469
470 ctx->buffer_bus =
471 dma_map_single(ohci->card.device, ctx->buffer,
472 buffer_size, DMA_TO_DEVICE);
473 if (dma_mapping_error(ctx->buffer_bus)) {
474 kfree(ctx->buffer);
475 return -ENOMEM;
476 }
477
478 ctx->head_descriptor = ctx->buffer;
479 ctx->prev_descriptor = ctx->buffer;
480 ctx->tail_descriptor = ctx->buffer;
481 ctx->tail_descriptor_last = ctx->buffer;
482
483 /*
484 * We put a dummy descriptor in the buffer that has a NULL
485 * branch address and looks like it's been sent. That way we
486 * have a descriptor to append DMA programs to. Also, the
487 * ring buffer invariant is that it always has at least one
488 * element so that head == tail means buffer full.
489 */
490
491 memset(ctx->head_descriptor, 0, sizeof(*ctx->head_descriptor));
492 ctx->head_descriptor->control = cpu_to_le16(DESCRIPTOR_OUTPUT_LAST);
493 ctx->head_descriptor->transfer_status = cpu_to_le16(0x8011);
494 ctx->head_descriptor++;
495
496 return 0;
497}
498
499static void
500context_release(struct context *ctx)
501{
502 struct fw_card *card = &ctx->ohci->card;
503
504 dma_unmap_single(card->device, ctx->buffer_bus,
505 ctx->buffer_size, DMA_TO_DEVICE);
506 kfree(ctx->buffer);
507}
508
509static struct descriptor *
510context_get_descriptors(struct context *ctx, int z, dma_addr_t *d_bus)
511{
512 struct descriptor *d, *tail, *end;
513
514 d = ctx->head_descriptor;
515 tail = ctx->tail_descriptor;
516 end = ctx->buffer + ctx->buffer_size / sizeof(*d);
517
518 if (d + z <= tail) {
519 goto has_space;
520 } else if (d > tail && d + z <= end) {
521 goto has_space;
522 } else if (d > tail && ctx->buffer + z <= tail) {
523 d = ctx->buffer;
524 goto has_space;
525 }
526
527 return NULL;
528
529 has_space:
530 memset(d, 0, z * sizeof(*d));
531 *d_bus = ctx->buffer_bus + (d - ctx->buffer) * sizeof(*d);
532
533 return d;
534}
535
536static void context_run(struct context *ctx, u32 extra)
537{
538 struct fw_ohci *ohci = ctx->ohci;
539
540 reg_write(ohci, COMMAND_PTR(ctx->regs),
541 le32_to_cpu(ctx->tail_descriptor_last->branch_address));
542 reg_write(ohci, CONTROL_CLEAR(ctx->regs), ~0);
543 reg_write(ohci, CONTROL_SET(ctx->regs), CONTEXT_RUN | extra);
544 flush_writes(ohci);
545}
546
547static void context_append(struct context *ctx,
548 struct descriptor *d, int z, int extra)
549{
550 dma_addr_t d_bus;
551
552 d_bus = ctx->buffer_bus + (d - ctx->buffer) * sizeof(*d);
553
554 ctx->head_descriptor = d + z + extra;
555 ctx->prev_descriptor->branch_address = cpu_to_le32(d_bus | z);
556 ctx->prev_descriptor = z == 2 ? d : d + z - 1;
557
558 dma_sync_single_for_device(ctx->ohci->card.device, ctx->buffer_bus,
559 ctx->buffer_size, DMA_TO_DEVICE);
560
561 reg_write(ctx->ohci, CONTROL_SET(ctx->regs), CONTEXT_WAKE);
562 flush_writes(ctx->ohci);
563}
564
565static void context_stop(struct context *ctx)
566{
567 u32 reg;
568 int i;
569
570 reg_write(ctx->ohci, CONTROL_CLEAR(ctx->regs), CONTEXT_RUN);
571 flush_writes(ctx->ohci);
572
573 for (i = 0; i < 10; i++) {
574 reg = reg_read(ctx->ohci, CONTROL_SET(ctx->regs));
575 if ((reg & CONTEXT_ACTIVE) == 0)
576 break;
577
578 fw_notify("context_stop: still active (0x%08x)\n", reg);
579 msleep(1);
580 }
581}
582
583struct driver_data {
584 struct fw_packet *packet;
585};
586
587/*
588 * This function apppends a packet to the DMA queue for transmission.
589 * Must always be called with the ochi->lock held to ensure proper
590 * generation handling and locking around packet queue manipulation.
591 */
592static int
593at_context_queue_packet(struct context *ctx, struct fw_packet *packet)
594{
595 struct fw_ohci *ohci = ctx->ohci;
596 dma_addr_t d_bus, payload_bus;
597 struct driver_data *driver_data;
598 struct descriptor *d, *last;
599 __le32 *header;
600 int z, tcode;
601 u32 reg;
602
603 d = context_get_descriptors(ctx, 4, &d_bus);
604 if (d == NULL) {
605 packet->ack = RCODE_SEND_ERROR;
606 return -1;
607 }
608
609 d[0].control = cpu_to_le16(DESCRIPTOR_KEY_IMMEDIATE);
610 d[0].res_count = cpu_to_le16(packet->timestamp);
611
612 /*
613 * The DMA format for asyncronous link packets is different
614 * from the IEEE1394 layout, so shift the fields around
615 * accordingly. If header_length is 8, it's a PHY packet, to
616 * which we need to prepend an extra quadlet.
617 */
618
619 header = (__le32 *) &d[1];
620 if (packet->header_length > 8) {
621 header[0] = cpu_to_le32((packet->header[0] & 0xffff) |
622 (packet->speed << 16));
623 header[1] = cpu_to_le32((packet->header[1] & 0xffff) |
624 (packet->header[0] & 0xffff0000));
625 header[2] = cpu_to_le32(packet->header[2]);
626
627 tcode = (packet->header[0] >> 4) & 0x0f;
628 if (TCODE_IS_BLOCK_PACKET(tcode))
629 header[3] = cpu_to_le32(packet->header[3]);
630 else
631 header[3] = (__force __le32) packet->header[3];
632
633 d[0].req_count = cpu_to_le16(packet->header_length);
634 } else {
635 header[0] = cpu_to_le32((OHCI1394_phy_tcode << 4) |
636 (packet->speed << 16));
637 header[1] = cpu_to_le32(packet->header[0]);
638 header[2] = cpu_to_le32(packet->header[1]);
639 d[0].req_count = cpu_to_le16(12);
640 }
641
642 driver_data = (struct driver_data *) &d[3];
643 driver_data->packet = packet;
644 packet->driver_data = driver_data;
645
646 if (packet->payload_length > 0) {
647 payload_bus =
648 dma_map_single(ohci->card.device, packet->payload,
649 packet->payload_length, DMA_TO_DEVICE);
650 if (dma_mapping_error(payload_bus)) {
651 packet->ack = RCODE_SEND_ERROR;
652 return -1;
653 }
654
655 d[2].req_count = cpu_to_le16(packet->payload_length);
656 d[2].data_address = cpu_to_le32(payload_bus);
657 last = &d[2];
658 z = 3;
659 } else {
660 last = &d[0];
661 z = 2;
662 }
663
664 last->control |= cpu_to_le16(DESCRIPTOR_OUTPUT_LAST |
665 DESCRIPTOR_IRQ_ALWAYS |
666 DESCRIPTOR_BRANCH_ALWAYS);
667
668 /* FIXME: Document how the locking works. */
669 if (ohci->generation != packet->generation) {
670 packet->ack = RCODE_GENERATION;
671 return -1;
672 }
673
674 context_append(ctx, d, z, 4 - z);
675
676 /* If the context isn't already running, start it up. */
677 reg = reg_read(ctx->ohci, CONTROL_SET(ctx->regs));
678 if ((reg & CONTEXT_RUN) == 0)
679 context_run(ctx, 0);
680
681 return 0;
682}
683
684static int handle_at_packet(struct context *context,
685 struct descriptor *d,
686 struct descriptor *last)
687{
688 struct driver_data *driver_data;
689 struct fw_packet *packet;
690 struct fw_ohci *ohci = context->ohci;
691 dma_addr_t payload_bus;
692 int evt;
693
694 if (last->transfer_status == 0)
695 /* This descriptor isn't done yet, stop iteration. */
696 return 0;
697
698 driver_data = (struct driver_data *) &d[3];
699 packet = driver_data->packet;
700 if (packet == NULL)
701 /* This packet was cancelled, just continue. */
702 return 1;
703
704 payload_bus = le32_to_cpu(last->data_address);
705 if (payload_bus != 0)
706 dma_unmap_single(ohci->card.device, payload_bus,
707 packet->payload_length, DMA_TO_DEVICE);
708
709 evt = le16_to_cpu(last->transfer_status) & 0x1f;
710 packet->timestamp = le16_to_cpu(last->res_count);
711
712 switch (evt) {
713 case OHCI1394_evt_timeout:
714 /* Async response transmit timed out. */
715 packet->ack = RCODE_CANCELLED;
716 break;
717
718 case OHCI1394_evt_flushed:
719 /*
720 * The packet was flushed should give same error as
721 * when we try to use a stale generation count.
722 */
723 packet->ack = RCODE_GENERATION;
724 break;
725
726 case OHCI1394_evt_missing_ack:
727 /*
728 * Using a valid (current) generation count, but the
729 * node is not on the bus or not sending acks.
730 */
731 packet->ack = RCODE_NO_ACK;
732 break;
733
734 case ACK_COMPLETE + 0x10:
735 case ACK_PENDING + 0x10:
736 case ACK_BUSY_X + 0x10:
737 case ACK_BUSY_A + 0x10:
738 case ACK_BUSY_B + 0x10:
739 case ACK_DATA_ERROR + 0x10:
740 case ACK_TYPE_ERROR + 0x10:
741 packet->ack = evt - 0x10;
742 break;
743
744 default:
745 packet->ack = RCODE_SEND_ERROR;
746 break;
747 }
748
749 packet->callback(packet, &ohci->card, packet->ack);
750
751 return 1;
752}
753
754#define HEADER_GET_DESTINATION(q) (((q) >> 16) & 0xffff)
755#define HEADER_GET_TCODE(q) (((q) >> 4) & 0x0f)
756#define HEADER_GET_OFFSET_HIGH(q) (((q) >> 0) & 0xffff)
757#define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff)
758#define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff)
759
760static void
761handle_local_rom(struct fw_ohci *ohci, struct fw_packet *packet, u32 csr)
762{
763 struct fw_packet response;
764 int tcode, length, i;
765
766 tcode = HEADER_GET_TCODE(packet->header[0]);
767 if (TCODE_IS_BLOCK_PACKET(tcode))
768 length = HEADER_GET_DATA_LENGTH(packet->header[3]);
769 else
770 length = 4;
771
772 i = csr - CSR_CONFIG_ROM;
773 if (i + length > CONFIG_ROM_SIZE) {
774 fw_fill_response(&response, packet->header,
775 RCODE_ADDRESS_ERROR, NULL, 0);
776 } else if (!TCODE_IS_READ_REQUEST(tcode)) {
777 fw_fill_response(&response, packet->header,
778 RCODE_TYPE_ERROR, NULL, 0);
779 } else {
780 fw_fill_response(&response, packet->header, RCODE_COMPLETE,
781 (void *) ohci->config_rom + i, length);
782 }
783
784 fw_core_handle_response(&ohci->card, &response);
785}
786
787static void
788handle_local_lock(struct fw_ohci *ohci, struct fw_packet *packet, u32 csr)
789{
790 struct fw_packet response;
791 int tcode, length, ext_tcode, sel;
792 __be32 *payload, lock_old;
793 u32 lock_arg, lock_data;
794
795 tcode = HEADER_GET_TCODE(packet->header[0]);
796 length = HEADER_GET_DATA_LENGTH(packet->header[3]);
797 payload = packet->payload;
798 ext_tcode = HEADER_GET_EXTENDED_TCODE(packet->header[3]);
799
800 if (tcode == TCODE_LOCK_REQUEST &&
801 ext_tcode == EXTCODE_COMPARE_SWAP && length == 8) {
802 lock_arg = be32_to_cpu(payload[0]);
803 lock_data = be32_to_cpu(payload[1]);
804 } else if (tcode == TCODE_READ_QUADLET_REQUEST) {
805 lock_arg = 0;
806 lock_data = 0;
807 } else {
808 fw_fill_response(&response, packet->header,
809 RCODE_TYPE_ERROR, NULL, 0);
810 goto out;
811 }
812
813 sel = (csr - CSR_BUS_MANAGER_ID) / 4;
814 reg_write(ohci, OHCI1394_CSRData, lock_data);
815 reg_write(ohci, OHCI1394_CSRCompareData, lock_arg);
816 reg_write(ohci, OHCI1394_CSRControl, sel);
817
818 if (reg_read(ohci, OHCI1394_CSRControl) & 0x80000000)
819 lock_old = cpu_to_be32(reg_read(ohci, OHCI1394_CSRData));
820 else
821 fw_notify("swap not done yet\n");
822
823 fw_fill_response(&response, packet->header,
824 RCODE_COMPLETE, &lock_old, sizeof(lock_old));
825 out:
826 fw_core_handle_response(&ohci->card, &response);
827}
828
829static void
830handle_local_request(struct context *ctx, struct fw_packet *packet)
831{
832 u64 offset;
833 u32 csr;
834
835 if (ctx == &ctx->ohci->at_request_ctx) {
836 packet->ack = ACK_PENDING;
837 packet->callback(packet, &ctx->ohci->card, packet->ack);
838 }
839
840 offset =
841 ((unsigned long long)
842 HEADER_GET_OFFSET_HIGH(packet->header[1]) << 32) |
843 packet->header[2];
844 csr = offset - CSR_REGISTER_BASE;
845
846 /* Handle config rom reads. */
847 if (csr >= CSR_CONFIG_ROM && csr < CSR_CONFIG_ROM_END)
848 handle_local_rom(ctx->ohci, packet, csr);
849 else switch (csr) {
850 case CSR_BUS_MANAGER_ID:
851 case CSR_BANDWIDTH_AVAILABLE:
852 case CSR_CHANNELS_AVAILABLE_HI:
853 case CSR_CHANNELS_AVAILABLE_LO:
854 handle_local_lock(ctx->ohci, packet, csr);
855 break;
856 default:
857 if (ctx == &ctx->ohci->at_request_ctx)
858 fw_core_handle_request(&ctx->ohci->card, packet);
859 else
860 fw_core_handle_response(&ctx->ohci->card, packet);
861 break;
862 }
863
864 if (ctx == &ctx->ohci->at_response_ctx) {
865 packet->ack = ACK_COMPLETE;
866 packet->callback(packet, &ctx->ohci->card, packet->ack);
867 }
868}
869
870static void
871at_context_transmit(struct context *ctx, struct fw_packet *packet)
872{
873 unsigned long flags;
874 int retval;
875
876 spin_lock_irqsave(&ctx->ohci->lock, flags);
877
878 if (HEADER_GET_DESTINATION(packet->header[0]) == ctx->ohci->node_id &&
879 ctx->ohci->generation == packet->generation) {
880 spin_unlock_irqrestore(&ctx->ohci->lock, flags);
881 handle_local_request(ctx, packet);
882 return;
883 }
884
885 retval = at_context_queue_packet(ctx, packet);
886 spin_unlock_irqrestore(&ctx->ohci->lock, flags);
887
888 if (retval < 0)
889 packet->callback(packet, &ctx->ohci->card, packet->ack);
890
891}
892
893static void bus_reset_tasklet(unsigned long data)
894{
895 struct fw_ohci *ohci = (struct fw_ohci *)data;
896 int self_id_count, i, j, reg;
897 int generation, new_generation;
898 unsigned long flags;
899
900 reg = reg_read(ohci, OHCI1394_NodeID);
901 if (!(reg & OHCI1394_NodeID_idValid)) {
902 fw_error("node ID not valid, new bus reset in progress\n");
903 return;
904 }
905 ohci->node_id = reg & 0xffff;
906
907 /*
908 * The count in the SelfIDCount register is the number of
909 * bytes in the self ID receive buffer. Since we also receive
910 * the inverted quadlets and a header quadlet, we shift one
911 * bit extra to get the actual number of self IDs.
912 */
913
914 self_id_count = (reg_read(ohci, OHCI1394_SelfIDCount) >> 3) & 0x3ff;
915 generation = (le32_to_cpu(ohci->self_id_cpu[0]) >> 16) & 0xff;
916
917 for (i = 1, j = 0; j < self_id_count; i += 2, j++) {
918 if (ohci->self_id_cpu[i] != ~ohci->self_id_cpu[i + 1])
919 fw_error("inconsistent self IDs\n");
920 ohci->self_id_buffer[j] = le32_to_cpu(ohci->self_id_cpu[i]);
921 }
922
923 /*
924 * Check the consistency of the self IDs we just read. The
925 * problem we face is that a new bus reset can start while we
926 * read out the self IDs from the DMA buffer. If this happens,
927 * the DMA buffer will be overwritten with new self IDs and we
928 * will read out inconsistent data. The OHCI specification
929 * (section 11.2) recommends a technique similar to
930 * linux/seqlock.h, where we remember the generation of the
931 * self IDs in the buffer before reading them out and compare
932 * it to the current generation after reading them out. If
933 * the two generations match we know we have a consistent set
934 * of self IDs.
935 */
936
937 new_generation = (reg_read(ohci, OHCI1394_SelfIDCount) >> 16) & 0xff;
938 if (new_generation != generation) {
939 fw_notify("recursive bus reset detected, "
940 "discarding self ids\n");
941 return;
942 }
943
944 /* FIXME: Document how the locking works. */
945 spin_lock_irqsave(&ohci->lock, flags);
946
947 ohci->generation = generation;
948 context_stop(&ohci->at_request_ctx);
949 context_stop(&ohci->at_response_ctx);
950 reg_write(ohci, OHCI1394_IntEventClear, OHCI1394_busReset);
951
952 /*
953 * This next bit is unrelated to the AT context stuff but we
954 * have to do it under the spinlock also. If a new config rom
955 * was set up before this reset, the old one is now no longer
956 * in use and we can free it. Update the config rom pointers
957 * to point to the current config rom and clear the
958 * next_config_rom pointer so a new udpate can take place.
959 */
960
961 if (ohci->next_config_rom != NULL) {
962 dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
963 ohci->config_rom, ohci->config_rom_bus);
964 ohci->config_rom = ohci->next_config_rom;
965 ohci->config_rom_bus = ohci->next_config_rom_bus;
966 ohci->next_config_rom = NULL;
967
968 /*
969 * Restore config_rom image and manually update
970 * config_rom registers. Writing the header quadlet
971 * will indicate that the config rom is ready, so we
972 * do that last.
973 */
974 reg_write(ohci, OHCI1394_BusOptions,
975 be32_to_cpu(ohci->config_rom[2]));
976 ohci->config_rom[0] = cpu_to_be32(ohci->next_header);
977 reg_write(ohci, OHCI1394_ConfigROMhdr, ohci->next_header);
978 }
979
980 spin_unlock_irqrestore(&ohci->lock, flags);
981
982 fw_core_handle_bus_reset(&ohci->card, ohci->node_id, generation,
983 self_id_count, ohci->self_id_buffer);
984}
985
986static irqreturn_t irq_handler(int irq, void *data)
987{
988 struct fw_ohci *ohci = data;
989 u32 event, iso_event, cycle_time;
990 int i;
991
992 event = reg_read(ohci, OHCI1394_IntEventClear);
993
994 if (!event)
995 return IRQ_NONE;
996
997 reg_write(ohci, OHCI1394_IntEventClear, event);
998
999 if (event & OHCI1394_selfIDComplete)
1000 tasklet_schedule(&ohci->bus_reset_tasklet);
1001
1002 if (event & OHCI1394_RQPkt)
1003 tasklet_schedule(&ohci->ar_request_ctx.tasklet);
1004
1005 if (event & OHCI1394_RSPkt)
1006 tasklet_schedule(&ohci->ar_response_ctx.tasklet);
1007
1008 if (event & OHCI1394_reqTxComplete)
1009 tasklet_schedule(&ohci->at_request_ctx.tasklet);
1010
1011 if (event & OHCI1394_respTxComplete)
1012 tasklet_schedule(&ohci->at_response_ctx.tasklet);
1013
1014 iso_event = reg_read(ohci, OHCI1394_IsoRecvIntEventClear);
1015 reg_write(ohci, OHCI1394_IsoRecvIntEventClear, iso_event);
1016
1017 while (iso_event) {
1018 i = ffs(iso_event) - 1;
1019 tasklet_schedule(&ohci->ir_context_list[i].context.tasklet);
1020 iso_event &= ~(1 << i);
1021 }
1022
1023 iso_event = reg_read(ohci, OHCI1394_IsoXmitIntEventClear);
1024 reg_write(ohci, OHCI1394_IsoXmitIntEventClear, iso_event);
1025
1026 while (iso_event) {
1027 i = ffs(iso_event) - 1;
1028 tasklet_schedule(&ohci->it_context_list[i].context.tasklet);
1029 iso_event &= ~(1 << i);
1030 }
1031
1032 if (event & OHCI1394_cycle64Seconds) {
1033 cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer);
1034 if ((cycle_time & 0x80000000) == 0)
1035 ohci->bus_seconds++;
1036 }
1037
1038 return IRQ_HANDLED;
1039}
1040
1041static int ohci_enable(struct fw_card *card, u32 *config_rom, size_t length)
1042{
1043 struct fw_ohci *ohci = fw_ohci(card);
1044 struct pci_dev *dev = to_pci_dev(card->device);
1045
1046 /*
1047 * When the link is not yet enabled, the atomic config rom
1048 * update mechanism described below in ohci_set_config_rom()
1049 * is not active. We have to update ConfigRomHeader and
1050 * BusOptions manually, and the write to ConfigROMmap takes
1051 * effect immediately. We tie this to the enabling of the
1052 * link, so we have a valid config rom before enabling - the
1053 * OHCI requires that ConfigROMhdr and BusOptions have valid
1054 * values before enabling.
1055 *
1056 * However, when the ConfigROMmap is written, some controllers
1057 * always read back quadlets 0 and 2 from the config rom to
1058 * the ConfigRomHeader and BusOptions registers on bus reset.
1059 * They shouldn't do that in this initial case where the link
1060 * isn't enabled. This means we have to use the same
1061 * workaround here, setting the bus header to 0 and then write
1062 * the right values in the bus reset tasklet.
1063 */
1064
1065 ohci->next_config_rom =
1066 dma_alloc_coherent(ohci->card.device, CONFIG_ROM_SIZE,
1067 &ohci->next_config_rom_bus, GFP_KERNEL);
1068 if (ohci->next_config_rom == NULL)
1069 return -ENOMEM;
1070
1071 memset(ohci->next_config_rom, 0, CONFIG_ROM_SIZE);
1072 fw_memcpy_to_be32(ohci->next_config_rom, config_rom, length * 4);
1073
1074 ohci->next_header = config_rom[0];
1075 ohci->next_config_rom[0] = 0;
1076 reg_write(ohci, OHCI1394_ConfigROMhdr, 0);
1077 reg_write(ohci, OHCI1394_BusOptions, config_rom[2]);
1078 reg_write(ohci, OHCI1394_ConfigROMmap, ohci->next_config_rom_bus);
1079
1080 reg_write(ohci, OHCI1394_AsReqFilterHiSet, 0x80000000);
1081
1082 if (request_irq(dev->irq, irq_handler,
1083 IRQF_SHARED, ohci_driver_name, ohci)) {
1084 fw_error("Failed to allocate shared interrupt %d.\n",
1085 dev->irq);
1086 dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
1087 ohci->config_rom, ohci->config_rom_bus);
1088 return -EIO;
1089 }
1090
1091 reg_write(ohci, OHCI1394_HCControlSet,
1092 OHCI1394_HCControl_linkEnable |
1093 OHCI1394_HCControl_BIBimageValid);
1094 flush_writes(ohci);
1095
1096 /*
1097 * We are ready to go, initiate bus reset to finish the
1098 * initialization.
1099 */
1100
1101 fw_core_initiate_bus_reset(&ohci->card, 1);
1102
1103 return 0;
1104}
1105
1106static int
1107ohci_set_config_rom(struct fw_card *card, u32 *config_rom, size_t length)
1108{
1109 struct fw_ohci *ohci;
1110 unsigned long flags;
1111 int retval = 0;
1112 __be32 *next_config_rom;
1113 dma_addr_t next_config_rom_bus;
1114
1115 ohci = fw_ohci(card);
1116
1117 /*
1118 * When the OHCI controller is enabled, the config rom update
1119 * mechanism is a bit tricky, but easy enough to use. See
1120 * section 5.5.6 in the OHCI specification.
1121 *
1122 * The OHCI controller caches the new config rom address in a
1123 * shadow register (ConfigROMmapNext) and needs a bus reset
1124 * for the changes to take place. When the bus reset is
1125 * detected, the controller loads the new values for the
1126 * ConfigRomHeader and BusOptions registers from the specified
1127 * config rom and loads ConfigROMmap from the ConfigROMmapNext
1128 * shadow register. All automatically and atomically.
1129 *
1130 * Now, there's a twist to this story. The automatic load of
1131 * ConfigRomHeader and BusOptions doesn't honor the
1132 * noByteSwapData bit, so with a be32 config rom, the
1133 * controller will load be32 values in to these registers
1134 * during the atomic update, even on litte endian
1135 * architectures. The workaround we use is to put a 0 in the
1136 * header quadlet; 0 is endian agnostic and means that the
1137 * config rom isn't ready yet. In the bus reset tasklet we
1138 * then set up the real values for the two registers.
1139 *
1140 * We use ohci->lock to avoid racing with the code that sets
1141 * ohci->next_config_rom to NULL (see bus_reset_tasklet).
1142 */
1143
1144 next_config_rom =
1145 dma_alloc_coherent(ohci->card.device, CONFIG_ROM_SIZE,
1146 &next_config_rom_bus, GFP_KERNEL);
1147 if (next_config_rom == NULL)
1148 return -ENOMEM;
1149
1150 spin_lock_irqsave(&ohci->lock, flags);
1151
1152 if (ohci->next_config_rom == NULL) {
1153 ohci->next_config_rom = next_config_rom;
1154 ohci->next_config_rom_bus = next_config_rom_bus;
1155
1156 memset(ohci->next_config_rom, 0, CONFIG_ROM_SIZE);
1157 fw_memcpy_to_be32(ohci->next_config_rom, config_rom,
1158 length * 4);
1159
1160 ohci->next_header = config_rom[0];
1161 ohci->next_config_rom[0] = 0;
1162
1163 reg_write(ohci, OHCI1394_ConfigROMmap,
1164 ohci->next_config_rom_bus);
1165 } else {
1166 dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
1167 next_config_rom, next_config_rom_bus);
1168 retval = -EBUSY;
1169 }
1170
1171 spin_unlock_irqrestore(&ohci->lock, flags);
1172
1173 /*
1174 * Now initiate a bus reset to have the changes take
1175 * effect. We clean up the old config rom memory and DMA
1176 * mappings in the bus reset tasklet, since the OHCI
1177 * controller could need to access it before the bus reset
1178 * takes effect.
1179 */
1180 if (retval == 0)
1181 fw_core_initiate_bus_reset(&ohci->card, 1);
1182
1183 return retval;
1184}
1185
1186static void ohci_send_request(struct fw_card *card, struct fw_packet *packet)
1187{
1188 struct fw_ohci *ohci = fw_ohci(card);
1189
1190 at_context_transmit(&ohci->at_request_ctx, packet);
1191}
1192
1193static void ohci_send_response(struct fw_card *card, struct fw_packet *packet)
1194{
1195 struct fw_ohci *ohci = fw_ohci(card);
1196
1197 at_context_transmit(&ohci->at_response_ctx, packet);
1198}
1199
1200static int ohci_cancel_packet(struct fw_card *card, struct fw_packet *packet)
1201{
1202 struct fw_ohci *ohci = fw_ohci(card);
1203 struct context *ctx = &ohci->at_request_ctx;
1204 struct driver_data *driver_data = packet->driver_data;
1205 int retval = -ENOENT;
1206
1207 tasklet_disable(&ctx->tasklet);
1208
1209 if (packet->ack != 0)
1210 goto out;
1211
1212 driver_data->packet = NULL;
1213 packet->ack = RCODE_CANCELLED;
1214 packet->callback(packet, &ohci->card, packet->ack);
1215 retval = 0;
1216
1217 out:
1218 tasklet_enable(&ctx->tasklet);
1219
1220 return retval;
1221}
1222
1223static int
1224ohci_enable_phys_dma(struct fw_card *card, int node_id, int generation)
1225{
1226 struct fw_ohci *ohci = fw_ohci(card);
1227 unsigned long flags;
1228 int n, retval = 0;
1229
1230 /*
1231 * FIXME: Make sure this bitmask is cleared when we clear the busReset
1232 * interrupt bit. Clear physReqResourceAllBuses on bus reset.
1233 */
1234
1235 spin_lock_irqsave(&ohci->lock, flags);
1236
1237 if (ohci->generation != generation) {
1238 retval = -ESTALE;
1239 goto out;
1240 }
1241
1242 /*
1243 * Note, if the node ID contains a non-local bus ID, physical DMA is
1244 * enabled for _all_ nodes on remote buses.
1245 */
1246
1247 n = (node_id & 0xffc0) == LOCAL_BUS ? node_id & 0x3f : 63;
1248 if (n < 32)
1249 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, 1 << n);
1250 else
1251 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, 1 << (n - 32));
1252
1253 flush_writes(ohci);
1254 out:
1255 spin_unlock_irqrestore(&ohci->lock, flags);
1256 return retval;
1257}
1258
1259static u64
1260ohci_get_bus_time(struct fw_card *card)
1261{
1262 struct fw_ohci *ohci = fw_ohci(card);
1263 u32 cycle_time;
1264 u64 bus_time;
1265
1266 cycle_time = reg_read(ohci, OHCI1394_IsochronousCycleTimer);
1267 bus_time = ((u64) ohci->bus_seconds << 32) | cycle_time;
1268
1269 return bus_time;
1270}
1271
1272static int handle_ir_dualbuffer_packet(struct context *context,
1273 struct descriptor *d,
1274 struct descriptor *last)
1275{
1276 struct iso_context *ctx =
1277 container_of(context, struct iso_context, context);
1278 struct db_descriptor *db = (struct db_descriptor *) d;
1279 __le32 *ir_header;
1280 size_t header_length;
1281 void *p, *end;
1282 int i;
1283
1284 if (db->first_res_count > 0 && db->second_res_count > 0)
1285 /* This descriptor isn't done yet, stop iteration. */
1286 return 0;
1287
1288 header_length = le16_to_cpu(db->first_req_count) -
1289 le16_to_cpu(db->first_res_count);
1290
1291 i = ctx->header_length;
1292 p = db + 1;
1293 end = p + header_length;
1294 while (p < end && i + ctx->base.header_size <= PAGE_SIZE) {
1295 /*
1296 * The iso header is byteswapped to little endian by
1297 * the controller, but the remaining header quadlets
1298 * are big endian. We want to present all the headers
1299 * as big endian, so we have to swap the first
1300 * quadlet.
1301 */
1302 *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4));
1303 memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4);
1304 i += ctx->base.header_size;
1305 p += ctx->base.header_size + 4;
1306 }
1307
1308 ctx->header_length = i;
1309
1310 if (le16_to_cpu(db->control) & DESCRIPTOR_IRQ_ALWAYS) {
1311 ir_header = (__le32 *) (db + 1);
1312 ctx->base.callback(&ctx->base,
1313 le32_to_cpu(ir_header[0]) & 0xffff,
1314 ctx->header_length, ctx->header,
1315 ctx->base.callback_data);
1316 ctx->header_length = 0;
1317 }
1318
1319 return 1;
1320}
1321
1322static int handle_it_packet(struct context *context,
1323 struct descriptor *d,
1324 struct descriptor *last)
1325{
1326 struct iso_context *ctx =
1327 container_of(context, struct iso_context, context);
1328
1329 if (last->transfer_status == 0)
1330 /* This descriptor isn't done yet, stop iteration. */
1331 return 0;
1332
1333 if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS)
1334 ctx->base.callback(&ctx->base, le16_to_cpu(last->res_count),
1335 0, NULL, ctx->base.callback_data);
1336
1337 return 1;
1338}
1339
1340static struct fw_iso_context *
1341ohci_allocate_iso_context(struct fw_card *card, int type, size_t header_size)
1342{
1343 struct fw_ohci *ohci = fw_ohci(card);
1344 struct iso_context *ctx, *list;
1345 descriptor_callback_t callback;
1346 u32 *mask, regs;
1347 unsigned long flags;
1348 int index, retval = -ENOMEM;
1349
1350 if (type == FW_ISO_CONTEXT_TRANSMIT) {
1351 mask = &ohci->it_context_mask;
1352 list = ohci->it_context_list;
1353 callback = handle_it_packet;
1354 } else {
1355 mask = &ohci->ir_context_mask;
1356 list = ohci->ir_context_list;
1357 callback = handle_ir_dualbuffer_packet;
1358 }
1359
1360 /* FIXME: We need a fallback for pre 1.1 OHCI. */
1361 if (callback == handle_ir_dualbuffer_packet &&
1362 ohci->version < OHCI_VERSION_1_1)
1363 return ERR_PTR(-EINVAL);
1364
1365 spin_lock_irqsave(&ohci->lock, flags);
1366 index = ffs(*mask) - 1;
1367 if (index >= 0)
1368 *mask &= ~(1 << index);
1369 spin_unlock_irqrestore(&ohci->lock, flags);
1370
1371 if (index < 0)
1372 return ERR_PTR(-EBUSY);
1373
1374 if (type == FW_ISO_CONTEXT_TRANSMIT)
1375 regs = OHCI1394_IsoXmitContextBase(index);
1376 else
1377 regs = OHCI1394_IsoRcvContextBase(index);
1378
1379 ctx = &list[index];
1380 memset(ctx, 0, sizeof(*ctx));
1381 ctx->header_length = 0;
1382 ctx->header = (void *) __get_free_page(GFP_KERNEL);
1383 if (ctx->header == NULL)
1384 goto out;
1385
1386 retval = context_init(&ctx->context, ohci, ISO_BUFFER_SIZE,
1387 regs, callback);
1388 if (retval < 0)
1389 goto out_with_header;
1390
1391 return &ctx->base;
1392
1393 out_with_header:
1394 free_page((unsigned long)ctx->header);
1395 out:
1396 spin_lock_irqsave(&ohci->lock, flags);
1397 *mask |= 1 << index;
1398 spin_unlock_irqrestore(&ohci->lock, flags);
1399
1400 return ERR_PTR(retval);
1401}
1402
1403static int ohci_start_iso(struct fw_iso_context *base,
1404 s32 cycle, u32 sync, u32 tags)
1405{
1406 struct iso_context *ctx = container_of(base, struct iso_context, base);
1407 struct fw_ohci *ohci = ctx->context.ohci;
1408 u32 control, match;
1409 int index;
1410
1411 if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) {
1412 index = ctx - ohci->it_context_list;
1413 match = 0;
1414 if (cycle >= 0)
1415 match = IT_CONTEXT_CYCLE_MATCH_ENABLE |
1416 (cycle & 0x7fff) << 16;
1417
1418 reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 1 << index);
1419 reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, 1 << index);
1420 context_run(&ctx->context, match);
1421 } else {
1422 index = ctx - ohci->ir_context_list;
1423 control = IR_CONTEXT_DUAL_BUFFER_MODE | IR_CONTEXT_ISOCH_HEADER;
1424 match = (tags << 28) | (sync << 8) | ctx->base.channel;
1425 if (cycle >= 0) {
1426 match |= (cycle & 0x07fff) << 12;
1427 control |= IR_CONTEXT_CYCLE_MATCH_ENABLE;
1428 }
1429
1430 reg_write(ohci, OHCI1394_IsoRecvIntEventClear, 1 << index);
1431 reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1 << index);
1432 reg_write(ohci, CONTEXT_MATCH(ctx->context.regs), match);
1433 context_run(&ctx->context, control);
1434 }
1435
1436 return 0;
1437}
1438
1439static int ohci_stop_iso(struct fw_iso_context *base)
1440{
1441 struct fw_ohci *ohci = fw_ohci(base->card);
1442 struct iso_context *ctx = container_of(base, struct iso_context, base);
1443 int index;
1444
1445 if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) {
1446 index = ctx - ohci->it_context_list;
1447 reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 1 << index);
1448 } else {
1449 index = ctx - ohci->ir_context_list;
1450 reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 1 << index);
1451 }
1452 flush_writes(ohci);
1453 context_stop(&ctx->context);
1454
1455 return 0;
1456}
1457
1458static void ohci_free_iso_context(struct fw_iso_context *base)
1459{
1460 struct fw_ohci *ohci = fw_ohci(base->card);
1461 struct iso_context *ctx = container_of(base, struct iso_context, base);
1462 unsigned long flags;
1463 int index;
1464
1465 ohci_stop_iso(base);
1466 context_release(&ctx->context);
1467 free_page((unsigned long)ctx->header);
1468
1469 spin_lock_irqsave(&ohci->lock, flags);
1470
1471 if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) {
1472 index = ctx - ohci->it_context_list;
1473 ohci->it_context_mask |= 1 << index;
1474 } else {
1475 index = ctx - ohci->ir_context_list;
1476 ohci->ir_context_mask |= 1 << index;
1477 }
1478
1479 spin_unlock_irqrestore(&ohci->lock, flags);
1480}
1481
1482static int
1483ohci_queue_iso_transmit(struct fw_iso_context *base,
1484 struct fw_iso_packet *packet,
1485 struct fw_iso_buffer *buffer,
1486 unsigned long payload)
1487{
1488 struct iso_context *ctx = container_of(base, struct iso_context, base);
1489 struct descriptor *d, *last, *pd;
1490 struct fw_iso_packet *p;
1491 __le32 *header;
1492 dma_addr_t d_bus, page_bus;
1493 u32 z, header_z, payload_z, irq;
1494 u32 payload_index, payload_end_index, next_page_index;
1495 int page, end_page, i, length, offset;
1496
1497 /*
1498 * FIXME: Cycle lost behavior should be configurable: lose
1499 * packet, retransmit or terminate..
1500 */
1501
1502 p = packet;
1503 payload_index = payload;
1504
1505 if (p->skip)
1506 z = 1;
1507 else
1508 z = 2;
1509 if (p->header_length > 0)
1510 z++;
1511
1512 /* Determine the first page the payload isn't contained in. */
1513 end_page = PAGE_ALIGN(payload_index + p->payload_length) >> PAGE_SHIFT;
1514 if (p->payload_length > 0)
1515 payload_z = end_page - (payload_index >> PAGE_SHIFT);
1516 else
1517 payload_z = 0;
1518
1519 z += payload_z;
1520
1521 /* Get header size in number of descriptors. */
1522 header_z = DIV_ROUND_UP(p->header_length, sizeof(*d));
1523
1524 d = context_get_descriptors(&ctx->context, z + header_z, &d_bus);
1525 if (d == NULL)
1526 return -ENOMEM;
1527
1528 if (!p->skip) {
1529 d[0].control = cpu_to_le16(DESCRIPTOR_KEY_IMMEDIATE);
1530 d[0].req_count = cpu_to_le16(8);
1531
1532 header = (__le32 *) &d[1];
1533 header[0] = cpu_to_le32(IT_HEADER_SY(p->sy) |
1534 IT_HEADER_TAG(p->tag) |
1535 IT_HEADER_TCODE(TCODE_STREAM_DATA) |
1536 IT_HEADER_CHANNEL(ctx->base.channel) |
1537 IT_HEADER_SPEED(ctx->base.speed));
1538 header[1] =
1539 cpu_to_le32(IT_HEADER_DATA_LENGTH(p->header_length +
1540 p->payload_length));
1541 }
1542
1543 if (p->header_length > 0) {
1544 d[2].req_count = cpu_to_le16(p->header_length);
1545 d[2].data_address = cpu_to_le32(d_bus + z * sizeof(*d));
1546 memcpy(&d[z], p->header, p->header_length);
1547 }
1548
1549 pd = d + z - payload_z;
1550 payload_end_index = payload_index + p->payload_length;
1551 for (i = 0; i < payload_z; i++) {
1552 page = payload_index >> PAGE_SHIFT;
1553 offset = payload_index & ~PAGE_MASK;
1554 next_page_index = (page + 1) << PAGE_SHIFT;
1555 length =
1556 min(next_page_index, payload_end_index) - payload_index;
1557 pd[i].req_count = cpu_to_le16(length);
1558
1559 page_bus = page_private(buffer->pages[page]);
1560 pd[i].data_address = cpu_to_le32(page_bus + offset);
1561
1562 payload_index += length;
1563 }
1564
1565 if (p->interrupt)
1566 irq = DESCRIPTOR_IRQ_ALWAYS;
1567 else
1568 irq = DESCRIPTOR_NO_IRQ;
1569
1570 last = z == 2 ? d : d + z - 1;
1571 last->control |= cpu_to_le16(DESCRIPTOR_OUTPUT_LAST |
1572 DESCRIPTOR_STATUS |
1573 DESCRIPTOR_BRANCH_ALWAYS |
1574 irq);
1575
1576 context_append(&ctx->context, d, z, header_z);
1577
1578 return 0;
1579}
1580
1581static int
1582ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base,
1583 struct fw_iso_packet *packet,
1584 struct fw_iso_buffer *buffer,
1585 unsigned long payload)
1586{
1587 struct iso_context *ctx = container_of(base, struct iso_context, base);
1588 struct db_descriptor *db = NULL;
1589 struct descriptor *d;
1590 struct fw_iso_packet *p;
1591 dma_addr_t d_bus, page_bus;
1592 u32 z, header_z, length, rest;
1593 int page, offset, packet_count, header_size;
1594
1595 /*
1596 * FIXME: Cycle lost behavior should be configurable: lose
1597 * packet, retransmit or terminate..
1598 */
1599
1600 if (packet->skip) {
1601 d = context_get_descriptors(&ctx->context, 2, &d_bus);
1602 if (d == NULL)
1603 return -ENOMEM;
1604
1605 db = (struct db_descriptor *) d;
1606 db->control = cpu_to_le16(DESCRIPTOR_STATUS |
1607 DESCRIPTOR_BRANCH_ALWAYS |
1608 DESCRIPTOR_WAIT);
1609 db->first_size = cpu_to_le16(ctx->base.header_size + 4);
1610 context_append(&ctx->context, d, 2, 0);
1611 }
1612
1613 p = packet;
1614 z = 2;
1615
1616 /*
1617 * The OHCI controller puts the status word in the header
1618 * buffer too, so we need 4 extra bytes per packet.
1619 */
1620 packet_count = p->header_length / ctx->base.header_size;
1621 header_size = packet_count * (ctx->base.header_size + 4);
1622
1623 /* Get header size in number of descriptors. */
1624 header_z = DIV_ROUND_UP(header_size, sizeof(*d));
1625 page = payload >> PAGE_SHIFT;
1626 offset = payload & ~PAGE_MASK;
1627 rest = p->payload_length;
1628
1629 /* FIXME: OHCI 1.0 doesn't support dual buffer receive */
1630 /* FIXME: make packet-per-buffer/dual-buffer a context option */
1631 while (rest > 0) {
1632 d = context_get_descriptors(&ctx->context,
1633 z + header_z, &d_bus);
1634 if (d == NULL)
1635 return -ENOMEM;
1636
1637 db = (struct db_descriptor *) d;
1638 db->control = cpu_to_le16(DESCRIPTOR_STATUS |
1639 DESCRIPTOR_BRANCH_ALWAYS);
1640 db->first_size = cpu_to_le16(ctx->base.header_size + 4);
1641 db->first_req_count = cpu_to_le16(header_size);
1642 db->first_res_count = db->first_req_count;
1643 db->first_buffer = cpu_to_le32(d_bus + sizeof(*db));
1644
1645 if (offset + rest < PAGE_SIZE)
1646 length = rest;
1647 else
1648 length = PAGE_SIZE - offset;
1649
1650 db->second_req_count = cpu_to_le16(length);
1651 db->second_res_count = db->second_req_count;
1652 page_bus = page_private(buffer->pages[page]);
1653 db->second_buffer = cpu_to_le32(page_bus + offset);
1654
1655 if (p->interrupt && length == rest)
1656 db->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS);
1657
1658 context_append(&ctx->context, d, z, header_z);
1659 offset = (offset + length) & ~PAGE_MASK;
1660 rest -= length;
1661 page++;
1662 }
1663
1664 return 0;
1665}
1666
1667static int
1668ohci_queue_iso(struct fw_iso_context *base,
1669 struct fw_iso_packet *packet,
1670 struct fw_iso_buffer *buffer,
1671 unsigned long payload)
1672{
1673 struct iso_context *ctx = container_of(base, struct iso_context, base);
1674
1675 if (base->type == FW_ISO_CONTEXT_TRANSMIT)
1676 return ohci_queue_iso_transmit(base, packet, buffer, payload);
1677 else if (ctx->context.ohci->version >= OHCI_VERSION_1_1)
1678 return ohci_queue_iso_receive_dualbuffer(base, packet,
1679 buffer, payload);
1680 else
1681 /* FIXME: Implement fallback for OHCI 1.0 controllers. */
1682 return -EINVAL;
1683}
1684
1685static const struct fw_card_driver ohci_driver = {
1686 .name = ohci_driver_name,
1687 .enable = ohci_enable,
1688 .update_phy_reg = ohci_update_phy_reg,
1689 .set_config_rom = ohci_set_config_rom,
1690 .send_request = ohci_send_request,
1691 .send_response = ohci_send_response,
1692 .cancel_packet = ohci_cancel_packet,
1693 .enable_phys_dma = ohci_enable_phys_dma,
1694 .get_bus_time = ohci_get_bus_time,
1695
1696 .allocate_iso_context = ohci_allocate_iso_context,
1697 .free_iso_context = ohci_free_iso_context,
1698 .queue_iso = ohci_queue_iso,
1699 .start_iso = ohci_start_iso,
1700 .stop_iso = ohci_stop_iso,
1701};
1702
1703static int software_reset(struct fw_ohci *ohci)
1704{
1705 int i;
1706
1707 reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_softReset);
1708
1709 for (i = 0; i < OHCI_LOOP_COUNT; i++) {
1710 if ((reg_read(ohci, OHCI1394_HCControlSet) &
1711 OHCI1394_HCControl_softReset) == 0)
1712 return 0;
1713 msleep(1);
1714 }
1715
1716 return -EBUSY;
1717}
1718
1719static int __devinit
1720pci_probe(struct pci_dev *dev, const struct pci_device_id *ent)
1721{
1722 struct fw_ohci *ohci;
1723 u32 bus_options, max_receive, link_speed;
1724 u64 guid;
1725 int err;
1726 size_t size;
1727
1728 ohci = kzalloc(sizeof(*ohci), GFP_KERNEL);
1729 if (ohci == NULL) {
1730 fw_error("Could not malloc fw_ohci data.\n");
1731 return -ENOMEM;
1732 }
1733
1734 fw_card_initialize(&ohci->card, &ohci_driver, &dev->dev);
1735
1736 err = pci_enable_device(dev);
1737 if (err) {
1738 fw_error("Failed to enable OHCI hardware.\n");
1739 goto fail_put_card;
1740 }
1741
1742 pci_set_master(dev);
1743 pci_write_config_dword(dev, OHCI1394_PCI_HCI_Control, 0);
1744 pci_set_drvdata(dev, ohci);
1745
1746 spin_lock_init(&ohci->lock);
1747
1748 tasklet_init(&ohci->bus_reset_tasklet,
1749 bus_reset_tasklet, (unsigned long)ohci);
1750
1751 err = pci_request_region(dev, 0, ohci_driver_name);
1752 if (err) {
1753 fw_error("MMIO resource unavailable\n");
1754 goto fail_disable;
1755 }
1756
1757 ohci->registers = pci_iomap(dev, 0, OHCI1394_REGISTER_SIZE);
1758 if (ohci->registers == NULL) {
1759 fw_error("Failed to remap registers\n");
1760 err = -ENXIO;
1761 goto fail_iomem;
1762 }
1763
1764 if (software_reset(ohci)) {
1765 fw_error("Failed to reset ohci card.\n");
1766 err = -EBUSY;
1767 goto fail_registers;
1768 }
1769
1770 /*
1771 * Now enable LPS, which we need in order to start accessing
1772 * most of the registers. In fact, on some cards (ALI M5251),
1773 * accessing registers in the SClk domain without LPS enabled
1774 * will lock up the machine. Wait 50msec to make sure we have
1775 * full link enabled.
1776 */
1777 reg_write(ohci, OHCI1394_HCControlSet,
1778 OHCI1394_HCControl_LPS |
1779 OHCI1394_HCControl_postedWriteEnable);
1780 flush_writes(ohci);
1781 msleep(50);
1782
1783 reg_write(ohci, OHCI1394_HCControlClear,
1784 OHCI1394_HCControl_noByteSwapData);
1785
1786 reg_write(ohci, OHCI1394_LinkControlSet,
1787 OHCI1394_LinkControl_rcvSelfID |
1788 OHCI1394_LinkControl_cycleTimerEnable |
1789 OHCI1394_LinkControl_cycleMaster);
1790
1791 ar_context_init(&ohci->ar_request_ctx, ohci,
1792 OHCI1394_AsReqRcvContextControlSet);
1793
1794 ar_context_init(&ohci->ar_response_ctx, ohci,
1795 OHCI1394_AsRspRcvContextControlSet);
1796
1797 context_init(&ohci->at_request_ctx, ohci, AT_BUFFER_SIZE,
1798 OHCI1394_AsReqTrContextControlSet, handle_at_packet);
1799
1800 context_init(&ohci->at_response_ctx, ohci, AT_BUFFER_SIZE,
1801 OHCI1394_AsRspTrContextControlSet, handle_at_packet);
1802
1803 reg_write(ohci, OHCI1394_ATRetries,
1804 OHCI1394_MAX_AT_REQ_RETRIES |
1805 (OHCI1394_MAX_AT_RESP_RETRIES << 4) |
1806 (OHCI1394_MAX_PHYS_RESP_RETRIES << 8));
1807
1808 reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, ~0);
1809 ohci->it_context_mask = reg_read(ohci, OHCI1394_IsoRecvIntMaskSet);
1810 reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, ~0);
1811 size = sizeof(struct iso_context) * hweight32(ohci->it_context_mask);
1812 ohci->it_context_list = kzalloc(size, GFP_KERNEL);
1813
1814 reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0);
1815 ohci->ir_context_mask = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet);
1816 reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0);
1817 size = sizeof(struct iso_context) * hweight32(ohci->ir_context_mask);
1818 ohci->ir_context_list = kzalloc(size, GFP_KERNEL);
1819
1820 if (ohci->it_context_list == NULL || ohci->ir_context_list == NULL) {
1821 fw_error("Out of memory for it/ir contexts.\n");
1822 err = -ENOMEM;
1823 goto fail_registers;
1824 }
1825
1826 /* self-id dma buffer allocation */
1827 ohci->self_id_cpu = dma_alloc_coherent(ohci->card.device,
1828 SELF_ID_BUF_SIZE,
1829 &ohci->self_id_bus,
1830 GFP_KERNEL);
1831 if (ohci->self_id_cpu == NULL) {
1832 fw_error("Out of memory for self ID buffer.\n");
1833 err = -ENOMEM;
1834 goto fail_registers;
1835 }
1836
1837 reg_write(ohci, OHCI1394_SelfIDBuffer, ohci->self_id_bus);
1838 reg_write(ohci, OHCI1394_PhyUpperBound, 0x00010000);
1839 reg_write(ohci, OHCI1394_IntEventClear, ~0);
1840 reg_write(ohci, OHCI1394_IntMaskClear, ~0);
1841 reg_write(ohci, OHCI1394_IntMaskSet,
1842 OHCI1394_selfIDComplete |
1843 OHCI1394_RQPkt | OHCI1394_RSPkt |
1844 OHCI1394_reqTxComplete | OHCI1394_respTxComplete |
1845 OHCI1394_isochRx | OHCI1394_isochTx |
1846 OHCI1394_masterIntEnable |
1847 OHCI1394_cycle64Seconds);
1848
1849 bus_options = reg_read(ohci, OHCI1394_BusOptions);
1850 max_receive = (bus_options >> 12) & 0xf;
1851 link_speed = bus_options & 0x7;
1852 guid = ((u64) reg_read(ohci, OHCI1394_GUIDHi) << 32) |
1853 reg_read(ohci, OHCI1394_GUIDLo);
1854
1855 err = fw_card_add(&ohci->card, max_receive, link_speed, guid);
1856 if (err < 0)
1857 goto fail_self_id;
1858
1859 ohci->version = reg_read(ohci, OHCI1394_Version) & 0x00ff00ff;
1860 fw_notify("Added fw-ohci device %s, OHCI version %x.%x\n",
1861 dev->dev.bus_id, ohci->version >> 16, ohci->version & 0xff);
1862
1863 return 0;
1864
1865 fail_self_id:
1866 dma_free_coherent(ohci->card.device, SELF_ID_BUF_SIZE,
1867 ohci->self_id_cpu, ohci->self_id_bus);
1868 fail_registers:
1869 kfree(ohci->it_context_list);
1870 kfree(ohci->ir_context_list);
1871 pci_iounmap(dev, ohci->registers);
1872 fail_iomem:
1873 pci_release_region(dev, 0);
1874 fail_disable:
1875 pci_disable_device(dev);
1876 fail_put_card:
1877 fw_card_put(&ohci->card);
1878
1879 return err;
1880}
1881
1882static void pci_remove(struct pci_dev *dev)
1883{
1884 struct fw_ohci *ohci;
1885
1886 ohci = pci_get_drvdata(dev);
1887 reg_write(ohci, OHCI1394_IntMaskClear, ~0);
1888 flush_writes(ohci);
1889 fw_core_remove_card(&ohci->card);
1890
1891 /*
1892 * FIXME: Fail all pending packets here, now that the upper
1893 * layers can't queue any more.
1894 */
1895
1896 software_reset(ohci);
1897 free_irq(dev->irq, ohci);
1898 dma_free_coherent(ohci->card.device, SELF_ID_BUF_SIZE,
1899 ohci->self_id_cpu, ohci->self_id_bus);
1900 kfree(ohci->it_context_list);
1901 kfree(ohci->ir_context_list);
1902 pci_iounmap(dev, ohci->registers);
1903 pci_release_region(dev, 0);
1904 pci_disable_device(dev);
1905 fw_card_put(&ohci->card);
1906
1907 fw_notify("Removed fw-ohci device.\n");
1908}
1909
1910static struct pci_device_id pci_table[] = {
1911 { PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_FIREWIRE_OHCI, ~0) },
1912 { }
1913};
1914
1915MODULE_DEVICE_TABLE(pci, pci_table);
1916
1917static struct pci_driver fw_ohci_pci_driver = {
1918 .name = ohci_driver_name,
1919 .id_table = pci_table,
1920 .probe = pci_probe,
1921 .remove = pci_remove,
1922};
1923
1924MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>");
1925MODULE_DESCRIPTION("Driver for PCI OHCI IEEE1394 controllers");
1926MODULE_LICENSE("GPL");
1927
1928/* Provide a module alias so root-on-sbp2 initrds don't break. */
1929#ifndef CONFIG_IEEE1394_OHCI1394_MODULE
1930MODULE_ALIAS("ohci1394");
1931#endif
1932
1933static int __init fw_ohci_init(void)
1934{
1935 return pci_register_driver(&fw_ohci_pci_driver);
1936}
1937
1938static void __exit fw_ohci_cleanup(void)
1939{
1940 pci_unregister_driver(&fw_ohci_pci_driver);
1941}
1942
1943module_init(fw_ohci_init);
1944module_exit(fw_ohci_cleanup);
diff --git a/drivers/firewire/fw-ohci.h b/drivers/firewire/fw-ohci.h
new file mode 100644
index 000000000000..fa15706397d7
--- /dev/null
+++ b/drivers/firewire/fw-ohci.h
@@ -0,0 +1,153 @@
1#ifndef __fw_ohci_h
2#define __fw_ohci_h
3
4/* OHCI register map */
5
6#define OHCI1394_Version 0x000
7#define OHCI1394_GUID_ROM 0x004
8#define OHCI1394_ATRetries 0x008
9#define OHCI1394_CSRData 0x00C
10#define OHCI1394_CSRCompareData 0x010
11#define OHCI1394_CSRControl 0x014
12#define OHCI1394_ConfigROMhdr 0x018
13#define OHCI1394_BusID 0x01C
14#define OHCI1394_BusOptions 0x020
15#define OHCI1394_GUIDHi 0x024
16#define OHCI1394_GUIDLo 0x028
17#define OHCI1394_ConfigROMmap 0x034
18#define OHCI1394_PostedWriteAddressLo 0x038
19#define OHCI1394_PostedWriteAddressHi 0x03C
20#define OHCI1394_VendorID 0x040
21#define OHCI1394_HCControlSet 0x050
22#define OHCI1394_HCControlClear 0x054
23#define OHCI1394_HCControl_BIBimageValid 0x80000000
24#define OHCI1394_HCControl_noByteSwapData 0x40000000
25#define OHCI1394_HCControl_programPhyEnable 0x00800000
26#define OHCI1394_HCControl_aPhyEnhanceEnable 0x00400000
27#define OHCI1394_HCControl_LPS 0x00080000
28#define OHCI1394_HCControl_postedWriteEnable 0x00040000
29#define OHCI1394_HCControl_linkEnable 0x00020000
30#define OHCI1394_HCControl_softReset 0x00010000
31#define OHCI1394_SelfIDBuffer 0x064
32#define OHCI1394_SelfIDCount 0x068
33#define OHCI1394_IRMultiChanMaskHiSet 0x070
34#define OHCI1394_IRMultiChanMaskHiClear 0x074
35#define OHCI1394_IRMultiChanMaskLoSet 0x078
36#define OHCI1394_IRMultiChanMaskLoClear 0x07C
37#define OHCI1394_IntEventSet 0x080
38#define OHCI1394_IntEventClear 0x084
39#define OHCI1394_IntMaskSet 0x088
40#define OHCI1394_IntMaskClear 0x08C
41#define OHCI1394_IsoXmitIntEventSet 0x090
42#define OHCI1394_IsoXmitIntEventClear 0x094
43#define OHCI1394_IsoXmitIntMaskSet 0x098
44#define OHCI1394_IsoXmitIntMaskClear 0x09C
45#define OHCI1394_IsoRecvIntEventSet 0x0A0
46#define OHCI1394_IsoRecvIntEventClear 0x0A4
47#define OHCI1394_IsoRecvIntMaskSet 0x0A8
48#define OHCI1394_IsoRecvIntMaskClear 0x0AC
49#define OHCI1394_InitialBandwidthAvailable 0x0B0
50#define OHCI1394_InitialChannelsAvailableHi 0x0B4
51#define OHCI1394_InitialChannelsAvailableLo 0x0B8
52#define OHCI1394_FairnessControl 0x0DC
53#define OHCI1394_LinkControlSet 0x0E0
54#define OHCI1394_LinkControlClear 0x0E4
55#define OHCI1394_LinkControl_rcvSelfID (1 << 9)
56#define OHCI1394_LinkControl_rcvPhyPkt (1 << 10)
57#define OHCI1394_LinkControl_cycleTimerEnable (1 << 20)
58#define OHCI1394_LinkControl_cycleMaster (1 << 21)
59#define OHCI1394_LinkControl_cycleSource (1 << 22)
60#define OHCI1394_NodeID 0x0E8
61#define OHCI1394_NodeID_idValid 0x80000000
62#define OHCI1394_PhyControl 0x0EC
63#define OHCI1394_PhyControl_Read(addr) (((addr) << 8) | 0x00008000)
64#define OHCI1394_PhyControl_ReadDone 0x80000000
65#define OHCI1394_PhyControl_ReadData(r) (((r) & 0x00ff0000) >> 16)
66#define OHCI1394_PhyControl_Write(addr, data) (((addr) << 8) | (data) | 0x00004000)
67#define OHCI1394_PhyControl_WriteDone 0x00004000
68#define OHCI1394_IsochronousCycleTimer 0x0F0
69#define OHCI1394_AsReqFilterHiSet 0x100
70#define OHCI1394_AsReqFilterHiClear 0x104
71#define OHCI1394_AsReqFilterLoSet 0x108
72#define OHCI1394_AsReqFilterLoClear 0x10C
73#define OHCI1394_PhyReqFilterHiSet 0x110
74#define OHCI1394_PhyReqFilterHiClear 0x114
75#define OHCI1394_PhyReqFilterLoSet 0x118
76#define OHCI1394_PhyReqFilterLoClear 0x11C
77#define OHCI1394_PhyUpperBound 0x120
78
79#define OHCI1394_AsReqTrContextBase 0x180
80#define OHCI1394_AsReqTrContextControlSet 0x180
81#define OHCI1394_AsReqTrContextControlClear 0x184
82#define OHCI1394_AsReqTrCommandPtr 0x18C
83
84#define OHCI1394_AsRspTrContextBase 0x1A0
85#define OHCI1394_AsRspTrContextControlSet 0x1A0
86#define OHCI1394_AsRspTrContextControlClear 0x1A4
87#define OHCI1394_AsRspTrCommandPtr 0x1AC
88
89#define OHCI1394_AsReqRcvContextBase 0x1C0
90#define OHCI1394_AsReqRcvContextControlSet 0x1C0
91#define OHCI1394_AsReqRcvContextControlClear 0x1C4
92#define OHCI1394_AsReqRcvCommandPtr 0x1CC
93
94#define OHCI1394_AsRspRcvContextBase 0x1E0
95#define OHCI1394_AsRspRcvContextControlSet 0x1E0
96#define OHCI1394_AsRspRcvContextControlClear 0x1E4
97#define OHCI1394_AsRspRcvCommandPtr 0x1EC
98
99/* Isochronous transmit registers */
100#define OHCI1394_IsoXmitContextBase(n) (0x200 + 16 * (n))
101#define OHCI1394_IsoXmitContextControlSet(n) (0x200 + 16 * (n))
102#define OHCI1394_IsoXmitContextControlClear(n) (0x204 + 16 * (n))
103#define OHCI1394_IsoXmitCommandPtr(n) (0x20C + 16 * (n))
104
105/* Isochronous receive registers */
106#define OHCI1394_IsoRcvContextBase(n) (0x400 + 32 * (n))
107#define OHCI1394_IsoRcvContextControlSet(n) (0x400 + 32 * (n))
108#define OHCI1394_IsoRcvContextControlClear(n) (0x404 + 32 * (n))
109#define OHCI1394_IsoRcvCommandPtr(n) (0x40C + 32 * (n))
110#define OHCI1394_IsoRcvContextMatch(n) (0x410 + 32 * (n))
111
112/* Interrupts Mask/Events */
113#define OHCI1394_reqTxComplete 0x00000001
114#define OHCI1394_respTxComplete 0x00000002
115#define OHCI1394_ARRQ 0x00000004
116#define OHCI1394_ARRS 0x00000008
117#define OHCI1394_RQPkt 0x00000010
118#define OHCI1394_RSPkt 0x00000020
119#define OHCI1394_isochTx 0x00000040
120#define OHCI1394_isochRx 0x00000080
121#define OHCI1394_postedWriteErr 0x00000100
122#define OHCI1394_lockRespErr 0x00000200
123#define OHCI1394_selfIDComplete 0x00010000
124#define OHCI1394_busReset 0x00020000
125#define OHCI1394_phy 0x00080000
126#define OHCI1394_cycleSynch 0x00100000
127#define OHCI1394_cycle64Seconds 0x00200000
128#define OHCI1394_cycleLost 0x00400000
129#define OHCI1394_cycleInconsistent 0x00800000
130#define OHCI1394_unrecoverableError 0x01000000
131#define OHCI1394_cycleTooLong 0x02000000
132#define OHCI1394_phyRegRcvd 0x04000000
133#define OHCI1394_masterIntEnable 0x80000000
134
135#define OHCI1394_evt_no_status 0x0
136#define OHCI1394_evt_long_packet 0x2
137#define OHCI1394_evt_missing_ack 0x3
138#define OHCI1394_evt_underrun 0x4
139#define OHCI1394_evt_overrun 0x5
140#define OHCI1394_evt_descriptor_read 0x6
141#define OHCI1394_evt_data_read 0x7
142#define OHCI1394_evt_data_write 0x8
143#define OHCI1394_evt_bus_reset 0x9
144#define OHCI1394_evt_timeout 0xa
145#define OHCI1394_evt_tcode_err 0xb
146#define OHCI1394_evt_reserved_b 0xc
147#define OHCI1394_evt_reserved_c 0xd
148#define OHCI1394_evt_unknown 0xe
149#define OHCI1394_evt_flushed 0xf
150
151#define OHCI1394_phy_tcode 0xe
152
153#endif /* __fw_ohci_h */
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c
new file mode 100644
index 000000000000..68300414e5f4
--- /dev/null
+++ b/drivers/firewire/fw-sbp2.c
@@ -0,0 +1,1147 @@
1/*
2 * SBP2 driver (SCSI over IEEE1394)
3 *
4 * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21/*
22 * The basic structure of this driver is based on the old storage driver,
23 * drivers/ieee1394/sbp2.c, originally written by
24 * James Goodwin <jamesg@filanet.com>
25 * with later contributions and ongoing maintenance from
26 * Ben Collins <bcollins@debian.org>,
27 * Stefan Richter <stefanr@s5r6.in-berlin.de>
28 * and many others.
29 */
30
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/mod_devicetable.h>
34#include <linux/device.h>
35#include <linux/scatterlist.h>
36#include <linux/dma-mapping.h>
37#include <linux/timer.h>
38
39#include <scsi/scsi.h>
40#include <scsi/scsi_cmnd.h>
41#include <scsi/scsi_dbg.h>
42#include <scsi/scsi_device.h>
43#include <scsi/scsi_host.h>
44
45#include "fw-transaction.h"
46#include "fw-topology.h"
47#include "fw-device.h"
48
49/* I don't know why the SCSI stack doesn't define something like this... */
50typedef void (*scsi_done_fn_t)(struct scsi_cmnd *);
51
52static const char sbp2_driver_name[] = "sbp2";
53
54struct sbp2_device {
55 struct kref kref;
56 struct fw_unit *unit;
57 struct fw_address_handler address_handler;
58 struct list_head orb_list;
59 u64 management_agent_address;
60 u64 command_block_agent_address;
61 u32 workarounds;
62 int login_id;
63
64 /*
65 * We cache these addresses and only update them once we've
66 * logged in or reconnected to the sbp2 device. That way, any
67 * IO to the device will automatically fail and get retried if
68 * it happens in a window where the device is not ready to
69 * handle it (e.g. after a bus reset but before we reconnect).
70 */
71 int node_id;
72 int address_high;
73 int generation;
74
75 int retries;
76 struct delayed_work work;
77};
78
79#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000
80#define SBP2_MAX_SECTORS 255 /* Max sectors supported */
81#define SBP2_ORB_TIMEOUT 2000 /* Timeout in ms */
82
83#define SBP2_ORB_NULL 0x80000000
84
85#define SBP2_DIRECTION_TO_MEDIA 0x0
86#define SBP2_DIRECTION_FROM_MEDIA 0x1
87
88/* Unit directory keys */
89#define SBP2_COMMAND_SET_SPECIFIER 0x38
90#define SBP2_COMMAND_SET 0x39
91#define SBP2_COMMAND_SET_REVISION 0x3b
92#define SBP2_FIRMWARE_REVISION 0x3c
93
94/* Flags for detected oddities and brokeness */
95#define SBP2_WORKAROUND_128K_MAX_TRANS 0x1
96#define SBP2_WORKAROUND_INQUIRY_36 0x2
97#define SBP2_WORKAROUND_MODE_SENSE_8 0x4
98#define SBP2_WORKAROUND_FIX_CAPACITY 0x8
99#define SBP2_WORKAROUND_OVERRIDE 0x100
100
101/* Management orb opcodes */
102#define SBP2_LOGIN_REQUEST 0x0
103#define SBP2_QUERY_LOGINS_REQUEST 0x1
104#define SBP2_RECONNECT_REQUEST 0x3
105#define SBP2_SET_PASSWORD_REQUEST 0x4
106#define SBP2_LOGOUT_REQUEST 0x7
107#define SBP2_ABORT_TASK_REQUEST 0xb
108#define SBP2_ABORT_TASK_SET 0xc
109#define SBP2_LOGICAL_UNIT_RESET 0xe
110#define SBP2_TARGET_RESET_REQUEST 0xf
111
112/* Offsets for command block agent registers */
113#define SBP2_AGENT_STATE 0x00
114#define SBP2_AGENT_RESET 0x04
115#define SBP2_ORB_POINTER 0x08
116#define SBP2_DOORBELL 0x10
117#define SBP2_UNSOLICITED_STATUS_ENABLE 0x14
118
119/* Status write response codes */
120#define SBP2_STATUS_REQUEST_COMPLETE 0x0
121#define SBP2_STATUS_TRANSPORT_FAILURE 0x1
122#define SBP2_STATUS_ILLEGAL_REQUEST 0x2
123#define SBP2_STATUS_VENDOR_DEPENDENT 0x3
124
125#define STATUS_GET_ORB_HIGH(v) ((v).status & 0xffff)
126#define STATUS_GET_SBP_STATUS(v) (((v).status >> 16) & 0xff)
127#define STATUS_GET_LEN(v) (((v).status >> 24) & 0x07)
128#define STATUS_GET_DEAD(v) (((v).status >> 27) & 0x01)
129#define STATUS_GET_RESPONSE(v) (((v).status >> 28) & 0x03)
130#define STATUS_GET_SOURCE(v) (((v).status >> 30) & 0x03)
131#define STATUS_GET_ORB_LOW(v) ((v).orb_low)
132#define STATUS_GET_DATA(v) ((v).data)
133
134struct sbp2_status {
135 u32 status;
136 u32 orb_low;
137 u8 data[24];
138};
139
140struct sbp2_pointer {
141 u32 high;
142 u32 low;
143};
144
145struct sbp2_orb {
146 struct fw_transaction t;
147 dma_addr_t request_bus;
148 int rcode;
149 struct sbp2_pointer pointer;
150 void (*callback)(struct sbp2_orb * orb, struct sbp2_status * status);
151 struct list_head link;
152};
153
154#define MANAGEMENT_ORB_LUN(v) ((v))
155#define MANAGEMENT_ORB_FUNCTION(v) ((v) << 16)
156#define MANAGEMENT_ORB_RECONNECT(v) ((v) << 20)
157#define MANAGEMENT_ORB_EXCLUSIVE ((1) << 28)
158#define MANAGEMENT_ORB_REQUEST_FORMAT(v) ((v) << 29)
159#define MANAGEMENT_ORB_NOTIFY ((1) << 31)
160
161#define MANAGEMENT_ORB_RESPONSE_LENGTH(v) ((v))
162#define MANAGEMENT_ORB_PASSWORD_LENGTH(v) ((v) << 16)
163
164struct sbp2_management_orb {
165 struct sbp2_orb base;
166 struct {
167 struct sbp2_pointer password;
168 struct sbp2_pointer response;
169 u32 misc;
170 u32 length;
171 struct sbp2_pointer status_fifo;
172 } request;
173 __be32 response[4];
174 dma_addr_t response_bus;
175 struct completion done;
176 struct sbp2_status status;
177};
178
179#define LOGIN_RESPONSE_GET_LOGIN_ID(v) ((v).misc & 0xffff)
180#define LOGIN_RESPONSE_GET_LENGTH(v) (((v).misc >> 16) & 0xffff)
181
182struct sbp2_login_response {
183 u32 misc;
184 struct sbp2_pointer command_block_agent;
185 u32 reconnect_hold;
186};
187#define COMMAND_ORB_DATA_SIZE(v) ((v))
188#define COMMAND_ORB_PAGE_SIZE(v) ((v) << 16)
189#define COMMAND_ORB_PAGE_TABLE_PRESENT ((1) << 19)
190#define COMMAND_ORB_MAX_PAYLOAD(v) ((v) << 20)
191#define COMMAND_ORB_SPEED(v) ((v) << 24)
192#define COMMAND_ORB_DIRECTION(v) ((v) << 27)
193#define COMMAND_ORB_REQUEST_FORMAT(v) ((v) << 29)
194#define COMMAND_ORB_NOTIFY ((1) << 31)
195
196struct sbp2_command_orb {
197 struct sbp2_orb base;
198 struct {
199 struct sbp2_pointer next;
200 struct sbp2_pointer data_descriptor;
201 u32 misc;
202 u8 command_block[12];
203 } request;
204 struct scsi_cmnd *cmd;
205 scsi_done_fn_t done;
206 struct fw_unit *unit;
207
208 struct sbp2_pointer page_table[SG_ALL];
209 dma_addr_t page_table_bus;
210 dma_addr_t request_buffer_bus;
211};
212
213/*
214 * List of devices with known bugs.
215 *
216 * The firmware_revision field, masked with 0xffff00, is the best
217 * indicator for the type of bridge chip of a device. It yields a few
218 * false positives but this did not break correctly behaving devices
219 * so far. We use ~0 as a wildcard, since the 24 bit values we get
220 * from the config rom can never match that.
221 */
222static const struct {
223 u32 firmware_revision;
224 u32 model;
225 unsigned workarounds;
226} sbp2_workarounds_table[] = {
227 /* DViCO Momobay CX-1 with TSB42AA9 bridge */ {
228 .firmware_revision = 0x002800,
229 .model = 0x001010,
230 .workarounds = SBP2_WORKAROUND_INQUIRY_36 |
231 SBP2_WORKAROUND_MODE_SENSE_8,
232 },
233 /* Initio bridges, actually only needed for some older ones */ {
234 .firmware_revision = 0x000200,
235 .model = ~0,
236 .workarounds = SBP2_WORKAROUND_INQUIRY_36,
237 },
238 /* Symbios bridge */ {
239 .firmware_revision = 0xa0b800,
240 .model = ~0,
241 .workarounds = SBP2_WORKAROUND_128K_MAX_TRANS,
242 },
243
244 /*
245 * There are iPods (2nd gen, 3rd gen) with model_id == 0, but
246 * these iPods do not feature the read_capacity bug according
247 * to one report. Read_capacity behaviour as well as model_id
248 * could change due to Apple-supplied firmware updates though.
249 */
250
251 /* iPod 4th generation. */ {
252 .firmware_revision = 0x0a2700,
253 .model = 0x000021,
254 .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
255 },
256 /* iPod mini */ {
257 .firmware_revision = 0x0a2700,
258 .model = 0x000023,
259 .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
260 },
261 /* iPod Photo */ {
262 .firmware_revision = 0x0a2700,
263 .model = 0x00007e,
264 .workarounds = SBP2_WORKAROUND_FIX_CAPACITY,
265 }
266};
267
268static void
269sbp2_status_write(struct fw_card *card, struct fw_request *request,
270 int tcode, int destination, int source,
271 int generation, int speed,
272 unsigned long long offset,
273 void *payload, size_t length, void *callback_data)
274{
275 struct sbp2_device *sd = callback_data;
276 struct sbp2_orb *orb;
277 struct sbp2_status status;
278 size_t header_size;
279 unsigned long flags;
280
281 if (tcode != TCODE_WRITE_BLOCK_REQUEST ||
282 length == 0 || length > sizeof(status)) {
283 fw_send_response(card, request, RCODE_TYPE_ERROR);
284 return;
285 }
286
287 header_size = min(length, 2 * sizeof(u32));
288 fw_memcpy_from_be32(&status, payload, header_size);
289 if (length > header_size)
290 memcpy(status.data, payload + 8, length - header_size);
291 if (STATUS_GET_SOURCE(status) == 2 || STATUS_GET_SOURCE(status) == 3) {
292 fw_notify("non-orb related status write, not handled\n");
293 fw_send_response(card, request, RCODE_COMPLETE);
294 return;
295 }
296
297 /* Lookup the orb corresponding to this status write. */
298 spin_lock_irqsave(&card->lock, flags);
299 list_for_each_entry(orb, &sd->orb_list, link) {
300 if (STATUS_GET_ORB_HIGH(status) == 0 &&
301 STATUS_GET_ORB_LOW(status) == orb->request_bus &&
302 orb->rcode == RCODE_COMPLETE) {
303 list_del(&orb->link);
304 break;
305 }
306 }
307 spin_unlock_irqrestore(&card->lock, flags);
308
309 if (&orb->link != &sd->orb_list)
310 orb->callback(orb, &status);
311 else
312 fw_error("status write for unknown orb\n");
313
314 fw_send_response(card, request, RCODE_COMPLETE);
315}
316
317static void
318complete_transaction(struct fw_card *card, int rcode,
319 void *payload, size_t length, void *data)
320{
321 struct sbp2_orb *orb = data;
322 unsigned long flags;
323
324 orb->rcode = rcode;
325 if (rcode != RCODE_COMPLETE) {
326 spin_lock_irqsave(&card->lock, flags);
327 list_del(&orb->link);
328 spin_unlock_irqrestore(&card->lock, flags);
329 orb->callback(orb, NULL);
330 }
331}
332
333static void
334sbp2_send_orb(struct sbp2_orb *orb, struct fw_unit *unit,
335 int node_id, int generation, u64 offset)
336{
337 struct fw_device *device = fw_device(unit->device.parent);
338 struct sbp2_device *sd = unit->device.driver_data;
339 unsigned long flags;
340
341 orb->pointer.high = 0;
342 orb->pointer.low = orb->request_bus;
343 fw_memcpy_to_be32(&orb->pointer, &orb->pointer, sizeof(orb->pointer));
344
345 spin_lock_irqsave(&device->card->lock, flags);
346 list_add_tail(&orb->link, &sd->orb_list);
347 spin_unlock_irqrestore(&device->card->lock, flags);
348
349 fw_send_request(device->card, &orb->t, TCODE_WRITE_BLOCK_REQUEST,
350 node_id, generation,
351 device->node->max_speed, offset,
352 &orb->pointer, sizeof(orb->pointer),
353 complete_transaction, orb);
354}
355
356static int sbp2_cancel_orbs(struct fw_unit *unit)
357{
358 struct fw_device *device = fw_device(unit->device.parent);
359 struct sbp2_device *sd = unit->device.driver_data;
360 struct sbp2_orb *orb, *next;
361 struct list_head list;
362 unsigned long flags;
363 int retval = -ENOENT;
364
365 INIT_LIST_HEAD(&list);
366 spin_lock_irqsave(&device->card->lock, flags);
367 list_splice_init(&sd->orb_list, &list);
368 spin_unlock_irqrestore(&device->card->lock, flags);
369
370 list_for_each_entry_safe(orb, next, &list, link) {
371 retval = 0;
372 if (fw_cancel_transaction(device->card, &orb->t) == 0)
373 continue;
374
375 orb->rcode = RCODE_CANCELLED;
376 orb->callback(orb, NULL);
377 }
378
379 return retval;
380}
381
382static void
383complete_management_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
384{
385 struct sbp2_management_orb *orb =
386 (struct sbp2_management_orb *)base_orb;
387
388 if (status)
389 memcpy(&orb->status, status, sizeof(*status));
390 complete(&orb->done);
391}
392
393static int
394sbp2_send_management_orb(struct fw_unit *unit, int node_id, int generation,
395 int function, int lun, void *response)
396{
397 struct fw_device *device = fw_device(unit->device.parent);
398 struct sbp2_device *sd = unit->device.driver_data;
399 struct sbp2_management_orb *orb;
400 int retval = -ENOMEM;
401
402 orb = kzalloc(sizeof(*orb), GFP_ATOMIC);
403 if (orb == NULL)
404 return -ENOMEM;
405
406 /*
407 * The sbp2 device is going to send a block read request to
408 * read out the request from host memory, so map it for dma.
409 */
410 orb->base.request_bus =
411 dma_map_single(device->card->device, &orb->request,
412 sizeof(orb->request), DMA_TO_DEVICE);
413 if (dma_mapping_error(orb->base.request_bus))
414 goto out;
415
416 orb->response_bus =
417 dma_map_single(device->card->device, &orb->response,
418 sizeof(orb->response), DMA_FROM_DEVICE);
419 if (dma_mapping_error(orb->response_bus))
420 goto out;
421
422 orb->request.response.high = 0;
423 orb->request.response.low = orb->response_bus;
424
425 orb->request.misc =
426 MANAGEMENT_ORB_NOTIFY |
427 MANAGEMENT_ORB_FUNCTION(function) |
428 MANAGEMENT_ORB_LUN(lun);
429 orb->request.length =
430 MANAGEMENT_ORB_RESPONSE_LENGTH(sizeof(orb->response));
431
432 orb->request.status_fifo.high = sd->address_handler.offset >> 32;
433 orb->request.status_fifo.low = sd->address_handler.offset;
434
435 /*
436 * FIXME: Yeah, ok this isn't elegant, we hardwire exclusive
437 * login and 1 second reconnect time. The reconnect setting
438 * is probably fine, but the exclusive login should be an option.
439 */
440 if (function == SBP2_LOGIN_REQUEST) {
441 orb->request.misc |=
442 MANAGEMENT_ORB_EXCLUSIVE |
443 MANAGEMENT_ORB_RECONNECT(0);
444 }
445
446 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request));
447
448 init_completion(&orb->done);
449 orb->base.callback = complete_management_orb;
450
451 sbp2_send_orb(&orb->base, unit,
452 node_id, generation, sd->management_agent_address);
453
454 wait_for_completion_timeout(&orb->done,
455 msecs_to_jiffies(SBP2_ORB_TIMEOUT));
456
457 retval = -EIO;
458 if (sbp2_cancel_orbs(unit) == 0) {
459 fw_error("orb reply timed out, rcode=0x%02x\n",
460 orb->base.rcode);
461 goto out;
462 }
463
464 if (orb->base.rcode != RCODE_COMPLETE) {
465 fw_error("management write failed, rcode 0x%02x\n",
466 orb->base.rcode);
467 goto out;
468 }
469
470 if (STATUS_GET_RESPONSE(orb->status) != 0 ||
471 STATUS_GET_SBP_STATUS(orb->status) != 0) {
472 fw_error("error status: %d:%d\n",
473 STATUS_GET_RESPONSE(orb->status),
474 STATUS_GET_SBP_STATUS(orb->status));
475 goto out;
476 }
477
478 retval = 0;
479 out:
480 dma_unmap_single(device->card->device, orb->base.request_bus,
481 sizeof(orb->request), DMA_TO_DEVICE);
482 dma_unmap_single(device->card->device, orb->response_bus,
483 sizeof(orb->response), DMA_FROM_DEVICE);
484
485 if (response)
486 fw_memcpy_from_be32(response,
487 orb->response, sizeof(orb->response));
488 kfree(orb);
489
490 return retval;
491}
492
493static void
494complete_agent_reset_write(struct fw_card *card, int rcode,
495 void *payload, size_t length, void *data)
496{
497 struct fw_transaction *t = data;
498
499 kfree(t);
500}
501
502static int sbp2_agent_reset(struct fw_unit *unit)
503{
504 struct fw_device *device = fw_device(unit->device.parent);
505 struct sbp2_device *sd = unit->device.driver_data;
506 struct fw_transaction *t;
507 static u32 zero;
508
509 t = kzalloc(sizeof(*t), GFP_ATOMIC);
510 if (t == NULL)
511 return -ENOMEM;
512
513 fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST,
514 sd->node_id, sd->generation, SCODE_400,
515 sd->command_block_agent_address + SBP2_AGENT_RESET,
516 &zero, sizeof(zero), complete_agent_reset_write, t);
517
518 return 0;
519}
520
521static void sbp2_reconnect(struct work_struct *work);
522static struct scsi_host_template scsi_driver_template;
523
524static void
525release_sbp2_device(struct kref *kref)
526{
527 struct sbp2_device *sd = container_of(kref, struct sbp2_device, kref);
528 struct Scsi_Host *host =
529 container_of((void *)sd, struct Scsi_Host, hostdata[0]);
530
531 sbp2_send_management_orb(sd->unit, sd->node_id, sd->generation,
532 SBP2_LOGOUT_REQUEST, sd->login_id, NULL);
533
534 scsi_remove_host(host);
535 fw_core_remove_address_handler(&sd->address_handler);
536 fw_notify("removed sbp2 unit %s\n", sd->unit->device.bus_id);
537 put_device(&sd->unit->device);
538 scsi_host_put(host);
539}
540
541static void sbp2_login(struct work_struct *work)
542{
543 struct sbp2_device *sd =
544 container_of(work, struct sbp2_device, work.work);
545 struct Scsi_Host *host =
546 container_of((void *)sd, struct Scsi_Host, hostdata[0]);
547 struct fw_unit *unit = sd->unit;
548 struct fw_device *device = fw_device(unit->device.parent);
549 struct sbp2_login_response response;
550 int generation, node_id, local_node_id, lun, retval;
551
552 /* FIXME: Make this work for multi-lun devices. */
553 lun = 0;
554
555 generation = device->card->generation;
556 node_id = device->node->node_id;
557 local_node_id = device->card->local_node->node_id;
558
559 if (sbp2_send_management_orb(unit, node_id, generation,
560 SBP2_LOGIN_REQUEST, lun, &response) < 0) {
561 if (sd->retries++ < 5) {
562 schedule_delayed_work(&sd->work, DIV_ROUND_UP(HZ, 5));
563 } else {
564 fw_error("failed to login to %s\n",
565 unit->device.bus_id);
566 kref_put(&sd->kref, release_sbp2_device);
567 }
568 return;
569 }
570
571 sd->generation = generation;
572 sd->node_id = node_id;
573 sd->address_high = local_node_id << 16;
574
575 /* Get command block agent offset and login id. */
576 sd->command_block_agent_address =
577 ((u64) (response.command_block_agent.high & 0xffff) << 32) |
578 response.command_block_agent.low;
579 sd->login_id = LOGIN_RESPONSE_GET_LOGIN_ID(response);
580
581 fw_notify("logged in to sbp2 unit %s (%d retries)\n",
582 unit->device.bus_id, sd->retries);
583 fw_notify(" - management_agent_address: 0x%012llx\n",
584 (unsigned long long) sd->management_agent_address);
585 fw_notify(" - command_block_agent_address: 0x%012llx\n",
586 (unsigned long long) sd->command_block_agent_address);
587 fw_notify(" - status write address: 0x%012llx\n",
588 (unsigned long long) sd->address_handler.offset);
589
590#if 0
591 /* FIXME: The linux1394 sbp2 does this last step. */
592 sbp2_set_busy_timeout(scsi_id);
593#endif
594
595 PREPARE_DELAYED_WORK(&sd->work, sbp2_reconnect);
596 sbp2_agent_reset(unit);
597
598 /* FIXME: Loop over luns here. */
599 lun = 0;
600 retval = scsi_add_device(host, 0, 0, lun);
601 if (retval < 0) {
602 sbp2_send_management_orb(unit, sd->node_id, sd->generation,
603 SBP2_LOGOUT_REQUEST, sd->login_id,
604 NULL);
605 /*
606 * Set this back to sbp2_login so we fall back and
607 * retry login on bus reset.
608 */
609 PREPARE_DELAYED_WORK(&sd->work, sbp2_login);
610 }
611 kref_put(&sd->kref, release_sbp2_device);
612}
613
614static int sbp2_probe(struct device *dev)
615{
616 struct fw_unit *unit = fw_unit(dev);
617 struct fw_device *device = fw_device(unit->device.parent);
618 struct sbp2_device *sd;
619 struct fw_csr_iterator ci;
620 struct Scsi_Host *host;
621 int i, key, value, err;
622 u32 model, firmware_revision;
623
624 err = -ENOMEM;
625 host = scsi_host_alloc(&scsi_driver_template, sizeof(*sd));
626 if (host == NULL)
627 goto fail;
628
629 sd = (struct sbp2_device *) host->hostdata;
630 unit->device.driver_data = sd;
631 sd->unit = unit;
632 INIT_LIST_HEAD(&sd->orb_list);
633 kref_init(&sd->kref);
634
635 sd->address_handler.length = 0x100;
636 sd->address_handler.address_callback = sbp2_status_write;
637 sd->address_handler.callback_data = sd;
638
639 err = fw_core_add_address_handler(&sd->address_handler,
640 &fw_high_memory_region);
641 if (err < 0)
642 goto fail_host;
643
644 err = fw_device_enable_phys_dma(device);
645 if (err < 0)
646 goto fail_address_handler;
647
648 err = scsi_add_host(host, &unit->device);
649 if (err < 0)
650 goto fail_address_handler;
651
652 /*
653 * Scan unit directory to get management agent address,
654 * firmware revison and model. Initialize firmware_revision
655 * and model to values that wont match anything in our table.
656 */
657 firmware_revision = 0xff000000;
658 model = 0xff000000;
659 fw_csr_iterator_init(&ci, unit->directory);
660 while (fw_csr_iterator_next(&ci, &key, &value)) {
661 switch (key) {
662 case CSR_DEPENDENT_INFO | CSR_OFFSET:
663 sd->management_agent_address =
664 0xfffff0000000ULL + 4 * value;
665 break;
666 case SBP2_FIRMWARE_REVISION:
667 firmware_revision = value;
668 break;
669 case CSR_MODEL:
670 model = value;
671 break;
672 }
673 }
674
675 for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) {
676 if (sbp2_workarounds_table[i].firmware_revision !=
677 (firmware_revision & 0xffffff00))
678 continue;
679 if (sbp2_workarounds_table[i].model != model &&
680 sbp2_workarounds_table[i].model != ~0)
681 continue;
682 sd->workarounds |= sbp2_workarounds_table[i].workarounds;
683 break;
684 }
685
686 if (sd->workarounds)
687 fw_notify("Workarounds for node %s: 0x%x "
688 "(firmware_revision 0x%06x, model_id 0x%06x)\n",
689 unit->device.bus_id,
690 sd->workarounds, firmware_revision, model);
691
692 get_device(&unit->device);
693
694 /*
695 * We schedule work to do the login so we can easily
696 * reschedule retries. Always get the ref before scheduling
697 * work.
698 */
699 INIT_DELAYED_WORK(&sd->work, sbp2_login);
700 if (schedule_delayed_work(&sd->work, 0))
701 kref_get(&sd->kref);
702
703 return 0;
704
705 fail_address_handler:
706 fw_core_remove_address_handler(&sd->address_handler);
707 fail_host:
708 scsi_host_put(host);
709 fail:
710 return err;
711}
712
713static int sbp2_remove(struct device *dev)
714{
715 struct fw_unit *unit = fw_unit(dev);
716 struct sbp2_device *sd = unit->device.driver_data;
717
718 kref_put(&sd->kref, release_sbp2_device);
719
720 return 0;
721}
722
723static void sbp2_reconnect(struct work_struct *work)
724{
725 struct sbp2_device *sd =
726 container_of(work, struct sbp2_device, work.work);
727 struct fw_unit *unit = sd->unit;
728 struct fw_device *device = fw_device(unit->device.parent);
729 int generation, node_id, local_node_id;
730
731 generation = device->card->generation;
732 node_id = device->node->node_id;
733 local_node_id = device->card->local_node->node_id;
734
735 if (sbp2_send_management_orb(unit, node_id, generation,
736 SBP2_RECONNECT_REQUEST,
737 sd->login_id, NULL) < 0) {
738 if (sd->retries++ >= 5) {
739 fw_error("failed to reconnect to %s\n",
740 unit->device.bus_id);
741 /* Fall back and try to log in again. */
742 sd->retries = 0;
743 PREPARE_DELAYED_WORK(&sd->work, sbp2_login);
744 }
745 schedule_delayed_work(&sd->work, DIV_ROUND_UP(HZ, 5));
746 return;
747 }
748
749 sd->generation = generation;
750 sd->node_id = node_id;
751 sd->address_high = local_node_id << 16;
752
753 fw_notify("reconnected to unit %s (%d retries)\n",
754 unit->device.bus_id, sd->retries);
755 sbp2_agent_reset(unit);
756 sbp2_cancel_orbs(unit);
757 kref_put(&sd->kref, release_sbp2_device);
758}
759
760static void sbp2_update(struct fw_unit *unit)
761{
762 struct fw_device *device = fw_device(unit->device.parent);
763 struct sbp2_device *sd = unit->device.driver_data;
764
765 sd->retries = 0;
766 fw_device_enable_phys_dma(device);
767 if (schedule_delayed_work(&sd->work, 0))
768 kref_get(&sd->kref);
769}
770
771#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
772#define SBP2_SW_VERSION_ENTRY 0x00010483
773
774static const struct fw_device_id sbp2_id_table[] = {
775 {
776 .match_flags = FW_MATCH_SPECIFIER_ID | FW_MATCH_VERSION,
777 .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY,
778 .version = SBP2_SW_VERSION_ENTRY,
779 },
780 { }
781};
782
783static struct fw_driver sbp2_driver = {
784 .driver = {
785 .owner = THIS_MODULE,
786 .name = sbp2_driver_name,
787 .bus = &fw_bus_type,
788 .probe = sbp2_probe,
789 .remove = sbp2_remove,
790 },
791 .update = sbp2_update,
792 .id_table = sbp2_id_table,
793};
794
795static unsigned int
796sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data)
797{
798 int sam_status;
799
800 sense_data[0] = 0x70;
801 sense_data[1] = 0x0;
802 sense_data[2] = sbp2_status[1];
803 sense_data[3] = sbp2_status[4];
804 sense_data[4] = sbp2_status[5];
805 sense_data[5] = sbp2_status[6];
806 sense_data[6] = sbp2_status[7];
807 sense_data[7] = 10;
808 sense_data[8] = sbp2_status[8];
809 sense_data[9] = sbp2_status[9];
810 sense_data[10] = sbp2_status[10];
811 sense_data[11] = sbp2_status[11];
812 sense_data[12] = sbp2_status[2];
813 sense_data[13] = sbp2_status[3];
814 sense_data[14] = sbp2_status[12];
815 sense_data[15] = sbp2_status[13];
816
817 sam_status = sbp2_status[0] & 0x3f;
818
819 switch (sam_status) {
820 case SAM_STAT_GOOD:
821 case SAM_STAT_CHECK_CONDITION:
822 case SAM_STAT_CONDITION_MET:
823 case SAM_STAT_BUSY:
824 case SAM_STAT_RESERVATION_CONFLICT:
825 case SAM_STAT_COMMAND_TERMINATED:
826 return DID_OK << 16 | sam_status;
827
828 default:
829 return DID_ERROR << 16;
830 }
831}
832
833static void
834complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status)
835{
836 struct sbp2_command_orb *orb = (struct sbp2_command_orb *)base_orb;
837 struct fw_unit *unit = orb->unit;
838 struct fw_device *device = fw_device(unit->device.parent);
839 struct scatterlist *sg;
840 int result;
841
842 if (status != NULL) {
843 if (STATUS_GET_DEAD(*status))
844 sbp2_agent_reset(unit);
845
846 switch (STATUS_GET_RESPONSE(*status)) {
847 case SBP2_STATUS_REQUEST_COMPLETE:
848 result = DID_OK << 16;
849 break;
850 case SBP2_STATUS_TRANSPORT_FAILURE:
851 result = DID_BUS_BUSY << 16;
852 break;
853 case SBP2_STATUS_ILLEGAL_REQUEST:
854 case SBP2_STATUS_VENDOR_DEPENDENT:
855 default:
856 result = DID_ERROR << 16;
857 break;
858 }
859
860 if (result == DID_OK << 16 && STATUS_GET_LEN(*status) > 1)
861 result = sbp2_status_to_sense_data(STATUS_GET_DATA(*status),
862 orb->cmd->sense_buffer);
863 } else {
864 /*
865 * If the orb completes with status == NULL, something
866 * went wrong, typically a bus reset happened mid-orb
867 * or when sending the write (less likely).
868 */
869 result = DID_BUS_BUSY << 16;
870 }
871
872 dma_unmap_single(device->card->device, orb->base.request_bus,
873 sizeof(orb->request), DMA_TO_DEVICE);
874
875 if (orb->cmd->use_sg > 0) {
876 sg = (struct scatterlist *)orb->cmd->request_buffer;
877 dma_unmap_sg(device->card->device, sg, orb->cmd->use_sg,
878 orb->cmd->sc_data_direction);
879 }
880
881 if (orb->page_table_bus != 0)
882 dma_unmap_single(device->card->device, orb->page_table_bus,
883 sizeof(orb->page_table_bus), DMA_TO_DEVICE);
884
885 if (orb->request_buffer_bus != 0)
886 dma_unmap_single(device->card->device, orb->request_buffer_bus,
887 sizeof(orb->request_buffer_bus),
888 DMA_FROM_DEVICE);
889
890 orb->cmd->result = result;
891 orb->done(orb->cmd);
892 kfree(orb);
893}
894
895static int sbp2_command_orb_map_scatterlist(struct sbp2_command_orb *orb)
896{
897 struct sbp2_device *sd =
898 (struct sbp2_device *)orb->cmd->device->host->hostdata;
899 struct fw_unit *unit = sd->unit;
900 struct fw_device *device = fw_device(unit->device.parent);
901 struct scatterlist *sg;
902 int sg_len, l, i, j, count;
903 size_t size;
904 dma_addr_t sg_addr;
905
906 sg = (struct scatterlist *)orb->cmd->request_buffer;
907 count = dma_map_sg(device->card->device, sg, orb->cmd->use_sg,
908 orb->cmd->sc_data_direction);
909 if (count == 0)
910 goto fail;
911
912 /*
913 * Handle the special case where there is only one element in
914 * the scatter list by converting it to an immediate block
915 * request. This is also a workaround for broken devices such
916 * as the second generation iPod which doesn't support page
917 * tables.
918 */
919 if (count == 1 && sg_dma_len(sg) < SBP2_MAX_SG_ELEMENT_LENGTH) {
920 orb->request.data_descriptor.high = sd->address_high;
921 orb->request.data_descriptor.low = sg_dma_address(sg);
922 orb->request.misc |=
923 COMMAND_ORB_DATA_SIZE(sg_dma_len(sg));
924 return 0;
925 }
926
927 /*
928 * Convert the scatterlist to an sbp2 page table. If any
929 * scatterlist entries are too big for sbp2, we split them as we
930 * go. Even if we ask the block I/O layer to not give us sg
931 * elements larger than 65535 bytes, some IOMMUs may merge sg elements
932 * during DMA mapping, and Linux currently doesn't prevent this.
933 */
934 for (i = 0, j = 0; i < count; i++) {
935 sg_len = sg_dma_len(sg + i);
936 sg_addr = sg_dma_address(sg + i);
937 while (sg_len) {
938 l = min(sg_len, SBP2_MAX_SG_ELEMENT_LENGTH);
939 orb->page_table[j].low = sg_addr;
940 orb->page_table[j].high = (l << 16);
941 sg_addr += l;
942 sg_len -= l;
943 j++;
944 }
945 }
946
947 size = sizeof(orb->page_table[0]) * j;
948
949 /*
950 * The data_descriptor pointer is the one case where we need
951 * to fill in the node ID part of the address. All other
952 * pointers assume that the data referenced reside on the
953 * initiator (i.e. us), but data_descriptor can refer to data
954 * on other nodes so we need to put our ID in descriptor.high.
955 */
956
957 orb->page_table_bus =
958 dma_map_single(device->card->device, orb->page_table,
959 size, DMA_TO_DEVICE);
960 if (dma_mapping_error(orb->page_table_bus))
961 goto fail_page_table;
962 orb->request.data_descriptor.high = sd->address_high;
963 orb->request.data_descriptor.low = orb->page_table_bus;
964 orb->request.misc |=
965 COMMAND_ORB_PAGE_TABLE_PRESENT |
966 COMMAND_ORB_DATA_SIZE(j);
967
968 fw_memcpy_to_be32(orb->page_table, orb->page_table, size);
969
970 return 0;
971
972 fail_page_table:
973 dma_unmap_sg(device->card->device, sg, orb->cmd->use_sg,
974 orb->cmd->sc_data_direction);
975 fail:
976 return -ENOMEM;
977}
978
979/* SCSI stack integration */
980
981static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
982{
983 struct sbp2_device *sd =
984 (struct sbp2_device *)cmd->device->host->hostdata;
985 struct fw_unit *unit = sd->unit;
986 struct fw_device *device = fw_device(unit->device.parent);
987 struct sbp2_command_orb *orb;
988
989 /*
990 * Bidirectional commands are not yet implemented, and unknown
991 * transfer direction not handled.
992 */
993 if (cmd->sc_data_direction == DMA_BIDIRECTIONAL) {
994 fw_error("Cannot handle DMA_BIDIRECTIONAL - rejecting command");
995 cmd->result = DID_ERROR << 16;
996 done(cmd);
997 return 0;
998 }
999
1000 orb = kzalloc(sizeof(*orb), GFP_ATOMIC);
1001 if (orb == NULL) {
1002 fw_notify("failed to alloc orb\n");
1003 goto fail_alloc;
1004 }
1005
1006 /* Initialize rcode to something not RCODE_COMPLETE. */
1007 orb->base.rcode = -1;
1008 orb->base.request_bus =
1009 dma_map_single(device->card->device, &orb->request,
1010 sizeof(orb->request), DMA_TO_DEVICE);
1011 if (dma_mapping_error(orb->base.request_bus))
1012 goto fail_mapping;
1013
1014 orb->unit = unit;
1015 orb->done = done;
1016 orb->cmd = cmd;
1017
1018 orb->request.next.high = SBP2_ORB_NULL;
1019 orb->request.next.low = 0x0;
1020 /*
1021 * At speed 100 we can do 512 bytes per packet, at speed 200,
1022 * 1024 bytes per packet etc. The SBP-2 max_payload field
1023 * specifies the max payload size as 2 ^ (max_payload + 2), so
1024 * if we set this to max_speed + 7, we get the right value.
1025 */
1026 orb->request.misc =
1027 COMMAND_ORB_MAX_PAYLOAD(device->node->max_speed + 7) |
1028 COMMAND_ORB_SPEED(device->node->max_speed) |
1029 COMMAND_ORB_NOTIFY;
1030
1031 if (cmd->sc_data_direction == DMA_FROM_DEVICE)
1032 orb->request.misc |=
1033 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_FROM_MEDIA);
1034 else if (cmd->sc_data_direction == DMA_TO_DEVICE)
1035 orb->request.misc |=
1036 COMMAND_ORB_DIRECTION(SBP2_DIRECTION_TO_MEDIA);
1037
1038 if (cmd->use_sg && sbp2_command_orb_map_scatterlist(orb) < 0)
1039 goto fail_map_payload;
1040
1041 fw_memcpy_to_be32(&orb->request, &orb->request, sizeof(orb->request));
1042
1043 memset(orb->request.command_block,
1044 0, sizeof(orb->request.command_block));
1045 memcpy(orb->request.command_block, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
1046
1047 orb->base.callback = complete_command_orb;
1048
1049 sbp2_send_orb(&orb->base, unit, sd->node_id, sd->generation,
1050 sd->command_block_agent_address + SBP2_ORB_POINTER);
1051
1052 return 0;
1053
1054 fail_map_payload:
1055 dma_unmap_single(device->card->device, orb->base.request_bus,
1056 sizeof(orb->request), DMA_TO_DEVICE);
1057 fail_mapping:
1058 kfree(orb);
1059 fail_alloc:
1060 return SCSI_MLQUEUE_HOST_BUSY;
1061}
1062
1063static int sbp2_scsi_slave_alloc(struct scsi_device *sdev)
1064{
1065 struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata;
1066
1067 sdev->allow_restart = 1;
1068
1069 if (sd->workarounds & SBP2_WORKAROUND_INQUIRY_36)
1070 sdev->inquiry_len = 36;
1071 return 0;
1072}
1073
1074static int sbp2_scsi_slave_configure(struct scsi_device *sdev)
1075{
1076 struct sbp2_device *sd = (struct sbp2_device *)sdev->host->hostdata;
1077 struct fw_unit *unit = sd->unit;
1078
1079 sdev->use_10_for_rw = 1;
1080
1081 if (sdev->type == TYPE_ROM)
1082 sdev->use_10_for_ms = 1;
1083 if (sdev->type == TYPE_DISK &&
1084 sd->workarounds & SBP2_WORKAROUND_MODE_SENSE_8)
1085 sdev->skip_ms_page_8 = 1;
1086 if (sd->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) {
1087 fw_notify("setting fix_capacity for %s\n", unit->device.bus_id);
1088 sdev->fix_capacity = 1;
1089 }
1090
1091 return 0;
1092}
1093
1094/*
1095 * Called by scsi stack when something has really gone wrong. Usually
1096 * called when a command has timed-out for some reason.
1097 */
1098static int sbp2_scsi_abort(struct scsi_cmnd *cmd)
1099{
1100 struct sbp2_device *sd =
1101 (struct sbp2_device *)cmd->device->host->hostdata;
1102 struct fw_unit *unit = sd->unit;
1103
1104 fw_notify("sbp2_scsi_abort\n");
1105 sbp2_agent_reset(unit);
1106 sbp2_cancel_orbs(unit);
1107
1108 return SUCCESS;
1109}
1110
1111static struct scsi_host_template scsi_driver_template = {
1112 .module = THIS_MODULE,
1113 .name = "SBP-2 IEEE-1394",
1114 .proc_name = (char *)sbp2_driver_name,
1115 .queuecommand = sbp2_scsi_queuecommand,
1116 .slave_alloc = sbp2_scsi_slave_alloc,
1117 .slave_configure = sbp2_scsi_slave_configure,
1118 .eh_abort_handler = sbp2_scsi_abort,
1119 .this_id = -1,
1120 .sg_tablesize = SG_ALL,
1121 .use_clustering = ENABLE_CLUSTERING,
1122 .cmd_per_lun = 1,
1123 .can_queue = 1,
1124};
1125
1126MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>");
1127MODULE_DESCRIPTION("SCSI over IEEE1394");
1128MODULE_LICENSE("GPL");
1129MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
1130
1131/* Provide a module alias so root-on-sbp2 initrds don't break. */
1132#ifndef CONFIG_IEEE1394_SBP2_MODULE
1133MODULE_ALIAS("sbp2");
1134#endif
1135
1136static int __init sbp2_init(void)
1137{
1138 return driver_register(&sbp2_driver.driver);
1139}
1140
1141static void __exit sbp2_cleanup(void)
1142{
1143 driver_unregister(&sbp2_driver.driver);
1144}
1145
1146module_init(sbp2_init);
1147module_exit(sbp2_cleanup);
diff --git a/drivers/firewire/fw-topology.c b/drivers/firewire/fw-topology.c
new file mode 100644
index 000000000000..7aebb8ae0efa
--- /dev/null
+++ b/drivers/firewire/fw-topology.c
@@ -0,0 +1,537 @@
1/*
2 * Incremental bus scan, based on bus topology
3 *
4 * Copyright (C) 2004-2006 Kristian Hoegsberg <krh@bitplanet.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/module.h>
22#include <linux/wait.h>
23#include <linux/errno.h>
24#include "fw-transaction.h"
25#include "fw-topology.h"
26
27#define SELF_ID_PHY_ID(q) (((q) >> 24) & 0x3f)
28#define SELF_ID_EXTENDED(q) (((q) >> 23) & 0x01)
29#define SELF_ID_LINK_ON(q) (((q) >> 22) & 0x01)
30#define SELF_ID_GAP_COUNT(q) (((q) >> 16) & 0x3f)
31#define SELF_ID_PHY_SPEED(q) (((q) >> 14) & 0x03)
32#define SELF_ID_CONTENDER(q) (((q) >> 11) & 0x01)
33#define SELF_ID_PHY_INITIATOR(q) (((q) >> 1) & 0x01)
34#define SELF_ID_MORE_PACKETS(q) (((q) >> 0) & 0x01)
35
36#define SELF_ID_EXT_SEQUENCE(q) (((q) >> 20) & 0x07)
37
38static u32 *count_ports(u32 *sid, int *total_port_count, int *child_port_count)
39{
40 u32 q;
41 int port_type, shift, seq;
42
43 *total_port_count = 0;
44 *child_port_count = 0;
45
46 shift = 6;
47 q = *sid;
48 seq = 0;
49
50 while (1) {
51 port_type = (q >> shift) & 0x03;
52 switch (port_type) {
53 case SELFID_PORT_CHILD:
54 (*child_port_count)++;
55 case SELFID_PORT_PARENT:
56 case SELFID_PORT_NCONN:
57 (*total_port_count)++;
58 case SELFID_PORT_NONE:
59 break;
60 }
61
62 shift -= 2;
63 if (shift == 0) {
64 if (!SELF_ID_MORE_PACKETS(q))
65 return sid + 1;
66
67 shift = 16;
68 sid++;
69 q = *sid;
70
71 /*
72 * Check that the extra packets actually are
73 * extended self ID packets and that the
74 * sequence numbers in the extended self ID
75 * packets increase as expected.
76 */
77
78 if (!SELF_ID_EXTENDED(q) ||
79 seq != SELF_ID_EXT_SEQUENCE(q))
80 return NULL;
81
82 seq++;
83 }
84 }
85}
86
87static int get_port_type(u32 *sid, int port_index)
88{
89 int index, shift;
90
91 index = (port_index + 5) / 8;
92 shift = 16 - ((port_index + 5) & 7) * 2;
93 return (sid[index] >> shift) & 0x03;
94}
95
96static struct fw_node *fw_node_create(u32 sid, int port_count, int color)
97{
98 struct fw_node *node;
99
100 node = kzalloc(sizeof(*node) + port_count * sizeof(node->ports[0]),
101 GFP_ATOMIC);
102 if (node == NULL)
103 return NULL;
104
105 node->color = color;
106 node->node_id = LOCAL_BUS | SELF_ID_PHY_ID(sid);
107 node->link_on = SELF_ID_LINK_ON(sid);
108 node->phy_speed = SELF_ID_PHY_SPEED(sid);
109 node->port_count = port_count;
110
111 atomic_set(&node->ref_count, 1);
112 INIT_LIST_HEAD(&node->link);
113
114 return node;
115}
116
117/*
118 * Compute the maximum hop count for this node and it's children. The
119 * maximum hop count is the maximum number of connections between any
120 * two nodes in the subtree rooted at this node. We need this for
121 * setting the gap count. As we build the tree bottom up in
122 * build_tree() below, this is fairly easy to do: for each node we
123 * maintain the max hop count and the max depth, ie the number of hops
124 * to the furthest leaf. Computing the max hop count breaks down into
125 * two cases: either the path goes through this node, in which case
126 * the hop count is the sum of the two biggest child depths plus 2.
127 * Or it could be the case that the max hop path is entirely
128 * containted in a child tree, in which case the max hop count is just
129 * the max hop count of this child.
130 */
131static void update_hop_count(struct fw_node *node)
132{
133 int depths[2] = { -1, -1 };
134 int max_child_hops = 0;
135 int i;
136
137 for (i = 0; i < node->port_count; i++) {
138 if (node->ports[i].node == NULL)
139 continue;
140
141 if (node->ports[i].node->max_hops > max_child_hops)
142 max_child_hops = node->ports[i].node->max_hops;
143
144 if (node->ports[i].node->max_depth > depths[0]) {
145 depths[1] = depths[0];
146 depths[0] = node->ports[i].node->max_depth;
147 } else if (node->ports[i].node->max_depth > depths[1])
148 depths[1] = node->ports[i].node->max_depth;
149 }
150
151 node->max_depth = depths[0] + 1;
152 node->max_hops = max(max_child_hops, depths[0] + depths[1] + 2);
153}
154
155
156/**
157 * build_tree - Build the tree representation of the topology
158 * @self_ids: array of self IDs to create the tree from
159 * @self_id_count: the length of the self_ids array
160 * @local_id: the node ID of the local node
161 *
162 * This function builds the tree representation of the topology given
163 * by the self IDs from the latest bus reset. During the construction
164 * of the tree, the function checks that the self IDs are valid and
165 * internally consistent. On succcess this funtions returns the
166 * fw_node corresponding to the local card otherwise NULL.
167 */
168static struct fw_node *build_tree(struct fw_card *card,
169 u32 *sid, int self_id_count)
170{
171 struct fw_node *node, *child, *local_node, *irm_node;
172 struct list_head stack, *h;
173 u32 *next_sid, *end, q;
174 int i, port_count, child_port_count, phy_id, parent_count, stack_depth;
175 int gap_count, topology_type;
176
177 local_node = NULL;
178 node = NULL;
179 INIT_LIST_HEAD(&stack);
180 stack_depth = 0;
181 end = sid + self_id_count;
182 phy_id = 0;
183 irm_node = NULL;
184 gap_count = SELF_ID_GAP_COUNT(*sid);
185 topology_type = 0;
186
187 while (sid < end) {
188 next_sid = count_ports(sid, &port_count, &child_port_count);
189
190 if (next_sid == NULL) {
191 fw_error("Inconsistent extended self IDs.\n");
192 return NULL;
193 }
194
195 q = *sid;
196 if (phy_id != SELF_ID_PHY_ID(q)) {
197 fw_error("PHY ID mismatch in self ID: %d != %d.\n",
198 phy_id, SELF_ID_PHY_ID(q));
199 return NULL;
200 }
201
202 if (child_port_count > stack_depth) {
203 fw_error("Topology stack underflow\n");
204 return NULL;
205 }
206
207 /*
208 * Seek back from the top of our stack to find the
209 * start of the child nodes for this node.
210 */
211 for (i = 0, h = &stack; i < child_port_count; i++)
212 h = h->prev;
213 child = fw_node(h);
214
215 node = fw_node_create(q, port_count, card->color);
216 if (node == NULL) {
217 fw_error("Out of memory while building topology.");
218 return NULL;
219 }
220
221 if (phy_id == (card->node_id & 0x3f))
222 local_node = node;
223
224 if (SELF_ID_CONTENDER(q))
225 irm_node = node;
226
227 if (node->phy_speed == SCODE_BETA)
228 topology_type |= FW_TOPOLOGY_B;
229 else
230 topology_type |= FW_TOPOLOGY_A;
231
232 parent_count = 0;
233
234 for (i = 0; i < port_count; i++) {
235 switch (get_port_type(sid, i)) {
236 case SELFID_PORT_PARENT:
237 /*
238 * Who's your daddy? We dont know the
239 * parent node at this time, so we
240 * temporarily abuse node->color for
241 * remembering the entry in the
242 * node->ports array where the parent
243 * node should be. Later, when we
244 * handle the parent node, we fix up
245 * the reference.
246 */
247 parent_count++;
248 node->color = i;
249 break;
250
251 case SELFID_PORT_CHILD:
252 node->ports[i].node = child;
253 /*
254 * Fix up parent reference for this
255 * child node.
256 */
257 child->ports[child->color].node = node;
258 child->color = card->color;
259 child = fw_node(child->link.next);
260 break;
261 }
262 }
263
264 /*
265 * Check that the node reports exactly one parent
266 * port, except for the root, which of course should
267 * have no parents.
268 */
269 if ((next_sid == end && parent_count != 0) ||
270 (next_sid < end && parent_count != 1)) {
271 fw_error("Parent port inconsistency for node %d: "
272 "parent_count=%d\n", phy_id, parent_count);
273 return NULL;
274 }
275
276 /* Pop the child nodes off the stack and push the new node. */
277 __list_del(h->prev, &stack);
278 list_add_tail(&node->link, &stack);
279 stack_depth += 1 - child_port_count;
280
281 /*
282 * If all PHYs does not report the same gap count
283 * setting, we fall back to 63 which will force a gap
284 * count reconfiguration and a reset.
285 */
286 if (SELF_ID_GAP_COUNT(q) != gap_count)
287 gap_count = 63;
288
289 update_hop_count(node);
290
291 sid = next_sid;
292 phy_id++;
293 }
294
295 card->root_node = node;
296 card->irm_node = irm_node;
297 card->gap_count = gap_count;
298 card->topology_type = topology_type;
299
300 return local_node;
301}
302
303typedef void (*fw_node_callback_t)(struct fw_card * card,
304 struct fw_node * node,
305 struct fw_node * parent);
306
307static void
308for_each_fw_node(struct fw_card *card, struct fw_node *root,
309 fw_node_callback_t callback)
310{
311 struct list_head list;
312 struct fw_node *node, *next, *child, *parent;
313 int i;
314
315 INIT_LIST_HEAD(&list);
316
317 fw_node_get(root);
318 list_add_tail(&root->link, &list);
319 parent = NULL;
320 list_for_each_entry(node, &list, link) {
321 node->color = card->color;
322
323 for (i = 0; i < node->port_count; i++) {
324 child = node->ports[i].node;
325 if (!child)
326 continue;
327 if (child->color == card->color)
328 parent = child;
329 else {
330 fw_node_get(child);
331 list_add_tail(&child->link, &list);
332 }
333 }
334
335 callback(card, node, parent);
336 }
337
338 list_for_each_entry_safe(node, next, &list, link)
339 fw_node_put(node);
340}
341
342static void
343report_lost_node(struct fw_card *card,
344 struct fw_node *node, struct fw_node *parent)
345{
346 fw_node_event(card, node, FW_NODE_DESTROYED);
347 fw_node_put(node);
348}
349
350static void
351report_found_node(struct fw_card *card,
352 struct fw_node *node, struct fw_node *parent)
353{
354 int b_path = (node->phy_speed == SCODE_BETA);
355
356 if (parent != NULL) {
357 /* min() macro doesn't work here with gcc 3.4 */
358 node->max_speed = parent->max_speed < node->phy_speed ?
359 parent->max_speed : node->phy_speed;
360 node->b_path = parent->b_path && b_path;
361 } else {
362 node->max_speed = node->phy_speed;
363 node->b_path = b_path;
364 }
365
366 fw_node_event(card, node, FW_NODE_CREATED);
367}
368
369void fw_destroy_nodes(struct fw_card *card)
370{
371 unsigned long flags;
372
373 spin_lock_irqsave(&card->lock, flags);
374 card->color++;
375 if (card->local_node != NULL)
376 for_each_fw_node(card, card->local_node, report_lost_node);
377 spin_unlock_irqrestore(&card->lock, flags);
378}
379
380static void move_tree(struct fw_node *node0, struct fw_node *node1, int port)
381{
382 struct fw_node *tree;
383 int i;
384
385 tree = node1->ports[port].node;
386 node0->ports[port].node = tree;
387 for (i = 0; i < tree->port_count; i++) {
388 if (tree->ports[i].node == node1) {
389 tree->ports[i].node = node0;
390 break;
391 }
392 }
393}
394
395/**
396 * update_tree - compare the old topology tree for card with the new
397 * one specified by root. Queue the nodes and mark them as either
398 * found, lost or updated. Update the nodes in the card topology tree
399 * as we go.
400 */
401static void
402update_tree(struct fw_card *card, struct fw_node *root)
403{
404 struct list_head list0, list1;
405 struct fw_node *node0, *node1;
406 int i, event;
407
408 INIT_LIST_HEAD(&list0);
409 list_add_tail(&card->local_node->link, &list0);
410 INIT_LIST_HEAD(&list1);
411 list_add_tail(&root->link, &list1);
412
413 node0 = fw_node(list0.next);
414 node1 = fw_node(list1.next);
415
416 while (&node0->link != &list0) {
417
418 /* assert(node0->port_count == node1->port_count); */
419 if (node0->link_on && !node1->link_on)
420 event = FW_NODE_LINK_OFF;
421 else if (!node0->link_on && node1->link_on)
422 event = FW_NODE_LINK_ON;
423 else
424 event = FW_NODE_UPDATED;
425
426 node0->node_id = node1->node_id;
427 node0->color = card->color;
428 node0->link_on = node1->link_on;
429 node0->initiated_reset = node1->initiated_reset;
430 node0->max_hops = node1->max_hops;
431 node1->color = card->color;
432 fw_node_event(card, node0, event);
433
434 if (card->root_node == node1)
435 card->root_node = node0;
436 if (card->irm_node == node1)
437 card->irm_node = node0;
438
439 for (i = 0; i < node0->port_count; i++) {
440 if (node0->ports[i].node && node1->ports[i].node) {
441 /*
442 * This port didn't change, queue the
443 * connected node for further
444 * investigation.
445 */
446 if (node0->ports[i].node->color == card->color)
447 continue;
448 list_add_tail(&node0->ports[i].node->link,
449 &list0);
450 list_add_tail(&node1->ports[i].node->link,
451 &list1);
452 } else if (node0->ports[i].node) {
453 /*
454 * The nodes connected here were
455 * unplugged; unref the lost nodes and
456 * queue FW_NODE_LOST callbacks for
457 * them.
458 */
459
460 for_each_fw_node(card, node0->ports[i].node,
461 report_lost_node);
462 node0->ports[i].node = NULL;
463 } else if (node1->ports[i].node) {
464 /*
465 * One or more node were connected to
466 * this port. Move the new nodes into
467 * the tree and queue FW_NODE_CREATED
468 * callbacks for them.
469 */
470 move_tree(node0, node1, i);
471 for_each_fw_node(card, node0->ports[i].node,
472 report_found_node);
473 }
474 }
475
476 node0 = fw_node(node0->link.next);
477 node1 = fw_node(node1->link.next);
478 }
479}
480
481static void
482update_topology_map(struct fw_card *card, u32 *self_ids, int self_id_count)
483{
484 int node_count;
485
486 card->topology_map[1]++;
487 node_count = (card->root_node->node_id & 0x3f) + 1;
488 card->topology_map[2] = (node_count << 16) | self_id_count;
489 card->topology_map[0] = (self_id_count + 2) << 16;
490 memcpy(&card->topology_map[3], self_ids, self_id_count * 4);
491 fw_compute_block_crc(card->topology_map);
492}
493
494void
495fw_core_handle_bus_reset(struct fw_card *card,
496 int node_id, int generation,
497 int self_id_count, u32 * self_ids)
498{
499 struct fw_node *local_node;
500 unsigned long flags;
501
502 fw_flush_transactions(card);
503
504 spin_lock_irqsave(&card->lock, flags);
505
506 /*
507 * If the new topology has a different self_id_count the topology
508 * changed, either nodes were added or removed. In that case we
509 * reset the IRM reset counter.
510 */
511 if (card->self_id_count != self_id_count)
512 card->bm_retries = 0;
513
514 card->node_id = node_id;
515 card->generation = generation;
516 card->reset_jiffies = jiffies;
517 schedule_delayed_work(&card->work, 0);
518
519 local_node = build_tree(card, self_ids, self_id_count);
520
521 update_topology_map(card, self_ids, self_id_count);
522
523 card->color++;
524
525 if (local_node == NULL) {
526 fw_error("topology build failed\n");
527 /* FIXME: We need to issue a bus reset in this case. */
528 } else if (card->local_node == NULL) {
529 card->local_node = local_node;
530 for_each_fw_node(card, local_node, report_found_node);
531 } else {
532 update_tree(card, local_node);
533 }
534
535 spin_unlock_irqrestore(&card->lock, flags);
536}
537EXPORT_SYMBOL(fw_core_handle_bus_reset);
diff --git a/drivers/firewire/fw-topology.h b/drivers/firewire/fw-topology.h
new file mode 100644
index 000000000000..363b6cbcd0b3
--- /dev/null
+++ b/drivers/firewire/fw-topology.h
@@ -0,0 +1,92 @@
1/*
2 * Copyright (C) 2003-2006 Kristian Hoegsberg <krh@bitplanet.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef __fw_topology_h
20#define __fw_topology_h
21
22enum {
23 FW_TOPOLOGY_A = 0x01,
24 FW_TOPOLOGY_B = 0x02,
25 FW_TOPOLOGY_MIXED = 0x03,
26};
27
28enum {
29 FW_NODE_CREATED = 0x00,
30 FW_NODE_UPDATED = 0x01,
31 FW_NODE_DESTROYED = 0x02,
32 FW_NODE_LINK_ON = 0x03,
33 FW_NODE_LINK_OFF = 0x04,
34};
35
36struct fw_port {
37 struct fw_node *node;
38 unsigned speed : 3; /* S100, S200, ... S3200 */
39};
40
41struct fw_node {
42 u16 node_id;
43 u8 color;
44 u8 port_count;
45 unsigned link_on : 1;
46 unsigned initiated_reset : 1;
47 unsigned b_path : 1;
48 u8 phy_speed : 3; /* As in the self ID packet. */
49 u8 max_speed : 5; /* Minimum of all phy-speeds and port speeds on
50 * the path from the local node to this node. */
51 u8 max_depth : 4; /* Maximum depth to any leaf node */
52 u8 max_hops : 4; /* Max hops in this sub tree */
53 atomic_t ref_count;
54
55 /* For serializing node topology into a list. */
56 struct list_head link;
57
58 /* Upper layer specific data. */
59 void *data;
60
61 struct fw_port ports[0];
62};
63
64static inline struct fw_node *
65fw_node(struct list_head *l)
66{
67 return list_entry(l, struct fw_node, link);
68}
69
70static inline struct fw_node *
71fw_node_get(struct fw_node *node)
72{
73 atomic_inc(&node->ref_count);
74
75 return node;
76}
77
78static inline void
79fw_node_put(struct fw_node *node)
80{
81 if (atomic_dec_and_test(&node->ref_count))
82 kfree(node);
83}
84
85void
86fw_destroy_nodes(struct fw_card *card);
87
88int
89fw_compute_block_crc(u32 *block);
90
91
92#endif /* __fw_topology_h */
diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c
new file mode 100644
index 000000000000..80d0121463d0
--- /dev/null
+++ b/drivers/firewire/fw-transaction.c
@@ -0,0 +1,910 @@
1/*
2 * Core IEEE1394 transaction logic
3 *
4 * Copyright (C) 2004-2006 Kristian Hoegsberg <krh@bitplanet.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/pci.h>
26#include <linux/delay.h>
27#include <linux/poll.h>
28#include <linux/list.h>
29#include <linux/kthread.h>
30#include <asm/uaccess.h>
31#include <asm/semaphore.h>
32
33#include "fw-transaction.h"
34#include "fw-topology.h"
35#include "fw-device.h"
36
37#define HEADER_PRI(pri) ((pri) << 0)
38#define HEADER_TCODE(tcode) ((tcode) << 4)
39#define HEADER_RETRY(retry) ((retry) << 8)
40#define HEADER_TLABEL(tlabel) ((tlabel) << 10)
41#define HEADER_DESTINATION(destination) ((destination) << 16)
42#define HEADER_SOURCE(source) ((source) << 16)
43#define HEADER_RCODE(rcode) ((rcode) << 12)
44#define HEADER_OFFSET_HIGH(offset_high) ((offset_high) << 0)
45#define HEADER_DATA_LENGTH(length) ((length) << 16)
46#define HEADER_EXTENDED_TCODE(tcode) ((tcode) << 0)
47
48#define HEADER_GET_TCODE(q) (((q) >> 4) & 0x0f)
49#define HEADER_GET_TLABEL(q) (((q) >> 10) & 0x3f)
50#define HEADER_GET_RCODE(q) (((q) >> 12) & 0x0f)
51#define HEADER_GET_DESTINATION(q) (((q) >> 16) & 0xffff)
52#define HEADER_GET_SOURCE(q) (((q) >> 16) & 0xffff)
53#define HEADER_GET_OFFSET_HIGH(q) (((q) >> 0) & 0xffff)
54#define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff)
55#define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff)
56
57#define PHY_CONFIG_GAP_COUNT(gap_count) (((gap_count) << 16) | (1 << 22))
58#define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23))
59#define PHY_IDENTIFIER(id) ((id) << 30)
60
61static int
62close_transaction(struct fw_transaction *transaction,
63 struct fw_card *card, int rcode,
64 u32 *payload, size_t length)
65{
66 struct fw_transaction *t;
67 unsigned long flags;
68
69 spin_lock_irqsave(&card->lock, flags);
70 list_for_each_entry(t, &card->transaction_list, link) {
71 if (t == transaction) {
72 list_del(&t->link);
73 card->tlabel_mask &= ~(1 << t->tlabel);
74 break;
75 }
76 }
77 spin_unlock_irqrestore(&card->lock, flags);
78
79 if (&t->link != &card->transaction_list) {
80 t->callback(card, rcode, payload, length, t->callback_data);
81 return 0;
82 }
83
84 return -ENOENT;
85}
86
87/*
88 * Only valid for transactions that are potentially pending (ie have
89 * been sent).
90 */
91int
92fw_cancel_transaction(struct fw_card *card,
93 struct fw_transaction *transaction)
94{
95 /*
96 * Cancel the packet transmission if it's still queued. That
97 * will call the packet transmission callback which cancels
98 * the transaction.
99 */
100
101 if (card->driver->cancel_packet(card, &transaction->packet) == 0)
102 return 0;
103
104 /*
105 * If the request packet has already been sent, we need to see
106 * if the transaction is still pending and remove it in that case.
107 */
108
109 return close_transaction(transaction, card, RCODE_CANCELLED, NULL, 0);
110}
111EXPORT_SYMBOL(fw_cancel_transaction);
112
113static void
114transmit_complete_callback(struct fw_packet *packet,
115 struct fw_card *card, int status)
116{
117 struct fw_transaction *t =
118 container_of(packet, struct fw_transaction, packet);
119
120 switch (status) {
121 case ACK_COMPLETE:
122 close_transaction(t, card, RCODE_COMPLETE, NULL, 0);
123 break;
124 case ACK_PENDING:
125 t->timestamp = packet->timestamp;
126 break;
127 case ACK_BUSY_X:
128 case ACK_BUSY_A:
129 case ACK_BUSY_B:
130 close_transaction(t, card, RCODE_BUSY, NULL, 0);
131 break;
132 case ACK_DATA_ERROR:
133 close_transaction(t, card, RCODE_DATA_ERROR, NULL, 0);
134 break;
135 case ACK_TYPE_ERROR:
136 close_transaction(t, card, RCODE_TYPE_ERROR, NULL, 0);
137 break;
138 default:
139 /*
140 * In this case the ack is really a juju specific
141 * rcode, so just forward that to the callback.
142 */
143 close_transaction(t, card, status, NULL, 0);
144 break;
145 }
146}
147
148static void
149fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
150 int node_id, int source_id, int generation, int speed,
151 unsigned long long offset, void *payload, size_t length)
152{
153 int ext_tcode;
154
155 if (tcode > 0x10) {
156 ext_tcode = tcode - 0x10;
157 tcode = TCODE_LOCK_REQUEST;
158 } else
159 ext_tcode = 0;
160
161 packet->header[0] =
162 HEADER_RETRY(RETRY_X) |
163 HEADER_TLABEL(tlabel) |
164 HEADER_TCODE(tcode) |
165 HEADER_DESTINATION(node_id);
166 packet->header[1] =
167 HEADER_OFFSET_HIGH(offset >> 32) | HEADER_SOURCE(source_id);
168 packet->header[2] =
169 offset;
170
171 switch (tcode) {
172 case TCODE_WRITE_QUADLET_REQUEST:
173 packet->header[3] = *(u32 *)payload;
174 packet->header_length = 16;
175 packet->payload_length = 0;
176 break;
177
178 case TCODE_LOCK_REQUEST:
179 case TCODE_WRITE_BLOCK_REQUEST:
180 packet->header[3] =
181 HEADER_DATA_LENGTH(length) |
182 HEADER_EXTENDED_TCODE(ext_tcode);
183 packet->header_length = 16;
184 packet->payload = payload;
185 packet->payload_length = length;
186 break;
187
188 case TCODE_READ_QUADLET_REQUEST:
189 packet->header_length = 12;
190 packet->payload_length = 0;
191 break;
192
193 case TCODE_READ_BLOCK_REQUEST:
194 packet->header[3] =
195 HEADER_DATA_LENGTH(length) |
196 HEADER_EXTENDED_TCODE(ext_tcode);
197 packet->header_length = 16;
198 packet->payload_length = 0;
199 break;
200 }
201
202 packet->speed = speed;
203 packet->generation = generation;
204 packet->ack = 0;
205}
206
207/**
208 * This function provides low-level access to the IEEE1394 transaction
209 * logic. Most C programs would use either fw_read(), fw_write() or
210 * fw_lock() instead - those function are convenience wrappers for
211 * this function. The fw_send_request() function is primarily
212 * provided as a flexible, one-stop entry point for languages bindings
213 * and protocol bindings.
214 *
215 * FIXME: Document this function further, in particular the possible
216 * values for rcode in the callback. In short, we map ACK_COMPLETE to
217 * RCODE_COMPLETE, internal errors set errno and set rcode to
218 * RCODE_SEND_ERROR (which is out of range for standard ieee1394
219 * rcodes). All other rcodes are forwarded unchanged. For all
220 * errors, payload is NULL, length is 0.
221 *
222 * Can not expect the callback to be called before the function
223 * returns, though this does happen in some cases (ACK_COMPLETE and
224 * errors).
225 *
226 * The payload is only used for write requests and must not be freed
227 * until the callback has been called.
228 *
229 * @param card the card from which to send the request
230 * @param tcode the tcode for this transaction. Do not use
231 * TCODE_LOCK_REQUEST directly, insted use TCODE_LOCK_MASK_SWAP
232 * etc. to specify tcode and ext_tcode.
233 * @param node_id the destination node ID (bus ID and PHY ID concatenated)
234 * @param generation the generation for which node_id is valid
235 * @param speed the speed to use for sending the request
236 * @param offset the 48 bit offset on the destination node
237 * @param payload the data payload for the request subaction
238 * @param length the length in bytes of the data to read
239 * @param callback function to be called when the transaction is completed
240 * @param callback_data pointer to arbitrary data, which will be
241 * passed to the callback
242 */
243void
244fw_send_request(struct fw_card *card, struct fw_transaction *t,
245 int tcode, int node_id, int generation, int speed,
246 unsigned long long offset,
247 void *payload, size_t length,
248 fw_transaction_callback_t callback, void *callback_data)
249{
250 unsigned long flags;
251 int tlabel, source;
252
253 /*
254 * Bump the flush timer up 100ms first of all so we
255 * don't race with a flush timer callback.
256 */
257
258 mod_timer(&card->flush_timer, jiffies + DIV_ROUND_UP(HZ, 10));
259
260 /*
261 * Allocate tlabel from the bitmap and put the transaction on
262 * the list while holding the card spinlock.
263 */
264
265 spin_lock_irqsave(&card->lock, flags);
266
267 source = card->node_id;
268 tlabel = card->current_tlabel;
269 if (card->tlabel_mask & (1 << tlabel)) {
270 spin_unlock_irqrestore(&card->lock, flags);
271 callback(card, RCODE_SEND_ERROR, NULL, 0, callback_data);
272 return;
273 }
274
275 card->current_tlabel = (card->current_tlabel + 1) & 0x1f;
276 card->tlabel_mask |= (1 << tlabel);
277
278 list_add_tail(&t->link, &card->transaction_list);
279
280 spin_unlock_irqrestore(&card->lock, flags);
281
282 /* Initialize rest of transaction, fill out packet and send it. */
283 t->node_id = node_id;
284 t->tlabel = tlabel;
285 t->callback = callback;
286 t->callback_data = callback_data;
287
288 fw_fill_request(&t->packet, tcode, t->tlabel,
289 node_id, source, generation,
290 speed, offset, payload, length);
291 t->packet.callback = transmit_complete_callback;
292
293 card->driver->send_request(card, &t->packet);
294}
295EXPORT_SYMBOL(fw_send_request);
296
297static void
298transmit_phy_packet_callback(struct fw_packet *packet,
299 struct fw_card *card, int status)
300{
301 kfree(packet);
302}
303
304static void send_phy_packet(struct fw_card *card, u32 data, int generation)
305{
306 struct fw_packet *packet;
307
308 packet = kzalloc(sizeof(*packet), GFP_ATOMIC);
309 if (packet == NULL)
310 return;
311
312 packet->header[0] = data;
313 packet->header[1] = ~data;
314 packet->header_length = 8;
315 packet->payload_length = 0;
316 packet->speed = SCODE_100;
317 packet->generation = generation;
318 packet->callback = transmit_phy_packet_callback;
319
320 card->driver->send_request(card, packet);
321}
322
323void fw_send_phy_config(struct fw_card *card,
324 int node_id, int generation, int gap_count)
325{
326 u32 q;
327
328 q = PHY_IDENTIFIER(PHY_PACKET_CONFIG) |
329 PHY_CONFIG_ROOT_ID(node_id) |
330 PHY_CONFIG_GAP_COUNT(gap_count);
331
332 send_phy_packet(card, q, generation);
333}
334
335void fw_flush_transactions(struct fw_card *card)
336{
337 struct fw_transaction *t, *next;
338 struct list_head list;
339 unsigned long flags;
340
341 INIT_LIST_HEAD(&list);
342 spin_lock_irqsave(&card->lock, flags);
343 list_splice_init(&card->transaction_list, &list);
344 card->tlabel_mask = 0;
345 spin_unlock_irqrestore(&card->lock, flags);
346
347 list_for_each_entry_safe(t, next, &list, link) {
348 card->driver->cancel_packet(card, &t->packet);
349
350 /*
351 * At this point cancel_packet will never call the
352 * transaction callback, since we just took all the
353 * transactions out of the list. So do it here.
354 */
355 t->callback(card, RCODE_CANCELLED, NULL, 0, t->callback_data);
356 }
357}
358
359static struct fw_address_handler *
360lookup_overlapping_address_handler(struct list_head *list,
361 unsigned long long offset, size_t length)
362{
363 struct fw_address_handler *handler;
364
365 list_for_each_entry(handler, list, link) {
366 if (handler->offset < offset + length &&
367 offset < handler->offset + handler->length)
368 return handler;
369 }
370
371 return NULL;
372}
373
374static struct fw_address_handler *
375lookup_enclosing_address_handler(struct list_head *list,
376 unsigned long long offset, size_t length)
377{
378 struct fw_address_handler *handler;
379
380 list_for_each_entry(handler, list, link) {
381 if (handler->offset <= offset &&
382 offset + length <= handler->offset + handler->length)
383 return handler;
384 }
385
386 return NULL;
387}
388
389static DEFINE_SPINLOCK(address_handler_lock);
390static LIST_HEAD(address_handler_list);
391
392const struct fw_address_region fw_low_memory_region =
393 { .start = 0x000000000000ULL, .end = 0x000100000000ULL, };
394const struct fw_address_region fw_high_memory_region =
395 { .start = 0x000100000000ULL, .end = 0xffffe0000000ULL, };
396const struct fw_address_region fw_private_region =
397 { .start = 0xffffe0000000ULL, .end = 0xfffff0000000ULL, };
398const struct fw_address_region fw_csr_region =
399 { .start = 0xfffff0000000ULL, .end = 0xfffff0000800ULL, };
400const struct fw_address_region fw_unit_space_region =
401 { .start = 0xfffff0000900ULL, .end = 0x1000000000000ULL, };
402EXPORT_SYMBOL(fw_low_memory_region);
403EXPORT_SYMBOL(fw_high_memory_region);
404EXPORT_SYMBOL(fw_private_region);
405EXPORT_SYMBOL(fw_csr_region);
406EXPORT_SYMBOL(fw_unit_space_region);
407
408/**
409 * Allocate a range of addresses in the node space of the OHCI
410 * controller. When a request is received that falls within the
411 * specified address range, the specified callback is invoked. The
412 * parameters passed to the callback give the details of the
413 * particular request
414 */
415int
416fw_core_add_address_handler(struct fw_address_handler *handler,
417 const struct fw_address_region *region)
418{
419 struct fw_address_handler *other;
420 unsigned long flags;
421 int ret = -EBUSY;
422
423 spin_lock_irqsave(&address_handler_lock, flags);
424
425 handler->offset = region->start;
426 while (handler->offset + handler->length <= region->end) {
427 other =
428 lookup_overlapping_address_handler(&address_handler_list,
429 handler->offset,
430 handler->length);
431 if (other != NULL) {
432 handler->offset += other->length;
433 } else {
434 list_add_tail(&handler->link, &address_handler_list);
435 ret = 0;
436 break;
437 }
438 }
439
440 spin_unlock_irqrestore(&address_handler_lock, flags);
441
442 return ret;
443}
444EXPORT_SYMBOL(fw_core_add_address_handler);
445
446/**
447 * Deallocate a range of addresses allocated with fw_allocate. This
448 * will call the associated callback one last time with a the special
449 * tcode TCODE_DEALLOCATE, to let the client destroy the registered
450 * callback data. For convenience, the callback parameters offset and
451 * length are set to the start and the length respectively for the
452 * deallocated region, payload is set to NULL.
453 */
454void fw_core_remove_address_handler(struct fw_address_handler *handler)
455{
456 unsigned long flags;
457
458 spin_lock_irqsave(&address_handler_lock, flags);
459 list_del(&handler->link);
460 spin_unlock_irqrestore(&address_handler_lock, flags);
461}
462EXPORT_SYMBOL(fw_core_remove_address_handler);
463
464struct fw_request {
465 struct fw_packet response;
466 u32 request_header[4];
467 int ack;
468 u32 length;
469 u32 data[0];
470};
471
472static void
473free_response_callback(struct fw_packet *packet,
474 struct fw_card *card, int status)
475{
476 struct fw_request *request;
477
478 request = container_of(packet, struct fw_request, response);
479 kfree(request);
480}
481
482void
483fw_fill_response(struct fw_packet *response, u32 *request_header,
484 int rcode, void *payload, size_t length)
485{
486 int tcode, tlabel, extended_tcode, source, destination;
487
488 tcode = HEADER_GET_TCODE(request_header[0]);
489 tlabel = HEADER_GET_TLABEL(request_header[0]);
490 source = HEADER_GET_DESTINATION(request_header[0]);
491 destination = HEADER_GET_SOURCE(request_header[1]);
492 extended_tcode = HEADER_GET_EXTENDED_TCODE(request_header[3]);
493
494 response->header[0] =
495 HEADER_RETRY(RETRY_1) |
496 HEADER_TLABEL(tlabel) |
497 HEADER_DESTINATION(destination);
498 response->header[1] =
499 HEADER_SOURCE(source) |
500 HEADER_RCODE(rcode);
501 response->header[2] = 0;
502
503 switch (tcode) {
504 case TCODE_WRITE_QUADLET_REQUEST:
505 case TCODE_WRITE_BLOCK_REQUEST:
506 response->header[0] |= HEADER_TCODE(TCODE_WRITE_RESPONSE);
507 response->header_length = 12;
508 response->payload_length = 0;
509 break;
510
511 case TCODE_READ_QUADLET_REQUEST:
512 response->header[0] |=
513 HEADER_TCODE(TCODE_READ_QUADLET_RESPONSE);
514 if (payload != NULL)
515 response->header[3] = *(u32 *)payload;
516 else
517 response->header[3] = 0;
518 response->header_length = 16;
519 response->payload_length = 0;
520 break;
521
522 case TCODE_READ_BLOCK_REQUEST:
523 case TCODE_LOCK_REQUEST:
524 response->header[0] |= HEADER_TCODE(tcode + 2);
525 response->header[3] =
526 HEADER_DATA_LENGTH(length) |
527 HEADER_EXTENDED_TCODE(extended_tcode);
528 response->header_length = 16;
529 response->payload = payload;
530 response->payload_length = length;
531 break;
532
533 default:
534 BUG();
535 return;
536 }
537}
538EXPORT_SYMBOL(fw_fill_response);
539
540static struct fw_request *
541allocate_request(struct fw_packet *p)
542{
543 struct fw_request *request;
544 u32 *data, length;
545 int request_tcode, t;
546
547 request_tcode = HEADER_GET_TCODE(p->header[0]);
548 switch (request_tcode) {
549 case TCODE_WRITE_QUADLET_REQUEST:
550 data = &p->header[3];
551 length = 4;
552 break;
553
554 case TCODE_WRITE_BLOCK_REQUEST:
555 case TCODE_LOCK_REQUEST:
556 data = p->payload;
557 length = HEADER_GET_DATA_LENGTH(p->header[3]);
558 break;
559
560 case TCODE_READ_QUADLET_REQUEST:
561 data = NULL;
562 length = 4;
563 break;
564
565 case TCODE_READ_BLOCK_REQUEST:
566 data = NULL;
567 length = HEADER_GET_DATA_LENGTH(p->header[3]);
568 break;
569
570 default:
571 BUG();
572 return NULL;
573 }
574
575 request = kmalloc(sizeof(*request) + length, GFP_ATOMIC);
576 if (request == NULL)
577 return NULL;
578
579 t = (p->timestamp & 0x1fff) + 4000;
580 if (t >= 8000)
581 t = (p->timestamp & ~0x1fff) + 0x2000 + t - 8000;
582 else
583 t = (p->timestamp & ~0x1fff) + t;
584
585 request->response.speed = p->speed;
586 request->response.timestamp = t;
587 request->response.generation = p->generation;
588 request->response.ack = 0;
589 request->response.callback = free_response_callback;
590 request->ack = p->ack;
591 request->length = length;
592 if (data)
593 memcpy(request->data, data, length);
594
595 memcpy(request->request_header, p->header, sizeof(p->header));
596
597 return request;
598}
599
600void
601fw_send_response(struct fw_card *card, struct fw_request *request, int rcode)
602{
603 /*
604 * Broadcast packets are reported as ACK_COMPLETE, so this
605 * check is sufficient to ensure we don't send response to
606 * broadcast packets or posted writes.
607 */
608 if (request->ack != ACK_PENDING)
609 return;
610
611 if (rcode == RCODE_COMPLETE)
612 fw_fill_response(&request->response, request->request_header,
613 rcode, request->data, request->length);
614 else
615 fw_fill_response(&request->response, request->request_header,
616 rcode, NULL, 0);
617
618 card->driver->send_response(card, &request->response);
619}
620EXPORT_SYMBOL(fw_send_response);
621
622void
623fw_core_handle_request(struct fw_card *card, struct fw_packet *p)
624{
625 struct fw_address_handler *handler;
626 struct fw_request *request;
627 unsigned long long offset;
628 unsigned long flags;
629 int tcode, destination, source;
630
631 if (p->payload_length > 2048) {
632 /* FIXME: send error response. */
633 return;
634 }
635
636 if (p->ack != ACK_PENDING && p->ack != ACK_COMPLETE)
637 return;
638
639 request = allocate_request(p);
640 if (request == NULL) {
641 /* FIXME: send statically allocated busy packet. */
642 return;
643 }
644
645 offset =
646 ((unsigned long long)
647 HEADER_GET_OFFSET_HIGH(p->header[1]) << 32) | p->header[2];
648 tcode = HEADER_GET_TCODE(p->header[0]);
649 destination = HEADER_GET_DESTINATION(p->header[0]);
650 source = HEADER_GET_SOURCE(p->header[0]);
651
652 spin_lock_irqsave(&address_handler_lock, flags);
653 handler = lookup_enclosing_address_handler(&address_handler_list,
654 offset, request->length);
655 spin_unlock_irqrestore(&address_handler_lock, flags);
656
657 /*
658 * FIXME: lookup the fw_node corresponding to the sender of
659 * this request and pass that to the address handler instead
660 * of the node ID. We may also want to move the address
661 * allocations to fw_node so we only do this callback if the
662 * upper layers registered it for this node.
663 */
664
665 if (handler == NULL)
666 fw_send_response(card, request, RCODE_ADDRESS_ERROR);
667 else
668 handler->address_callback(card, request,
669 tcode, destination, source,
670 p->generation, p->speed, offset,
671 request->data, request->length,
672 handler->callback_data);
673}
674EXPORT_SYMBOL(fw_core_handle_request);
675
676void
677fw_core_handle_response(struct fw_card *card, struct fw_packet *p)
678{
679 struct fw_transaction *t;
680 unsigned long flags;
681 u32 *data;
682 size_t data_length;
683 int tcode, tlabel, destination, source, rcode;
684
685 tcode = HEADER_GET_TCODE(p->header[0]);
686 tlabel = HEADER_GET_TLABEL(p->header[0]);
687 destination = HEADER_GET_DESTINATION(p->header[0]);
688 source = HEADER_GET_SOURCE(p->header[1]);
689 rcode = HEADER_GET_RCODE(p->header[1]);
690
691 spin_lock_irqsave(&card->lock, flags);
692 list_for_each_entry(t, &card->transaction_list, link) {
693 if (t->node_id == source && t->tlabel == tlabel) {
694 list_del(&t->link);
695 card->tlabel_mask &= ~(1 << t->tlabel);
696 break;
697 }
698 }
699 spin_unlock_irqrestore(&card->lock, flags);
700
701 if (&t->link == &card->transaction_list) {
702 fw_notify("Unsolicited response (source %x, tlabel %x)\n",
703 source, tlabel);
704 return;
705 }
706
707 /*
708 * FIXME: sanity check packet, is length correct, does tcodes
709 * and addresses match.
710 */
711
712 switch (tcode) {
713 case TCODE_READ_QUADLET_RESPONSE:
714 data = (u32 *) &p->header[3];
715 data_length = 4;
716 break;
717
718 case TCODE_WRITE_RESPONSE:
719 data = NULL;
720 data_length = 0;
721 break;
722
723 case TCODE_READ_BLOCK_RESPONSE:
724 case TCODE_LOCK_RESPONSE:
725 data = p->payload;
726 data_length = HEADER_GET_DATA_LENGTH(p->header[3]);
727 break;
728
729 default:
730 /* Should never happen, this is just to shut up gcc. */
731 data = NULL;
732 data_length = 0;
733 break;
734 }
735
736 t->callback(card, rcode, data, data_length, t->callback_data);
737}
738EXPORT_SYMBOL(fw_core_handle_response);
739
740const struct fw_address_region topology_map_region =
741 { .start = 0xfffff0001000ull, .end = 0xfffff0001400ull, };
742
743static void
744handle_topology_map(struct fw_card *card, struct fw_request *request,
745 int tcode, int destination, int source,
746 int generation, int speed,
747 unsigned long long offset,
748 void *payload, size_t length, void *callback_data)
749{
750 int i, start, end;
751 u32 *map;
752
753 if (!TCODE_IS_READ_REQUEST(tcode)) {
754 fw_send_response(card, request, RCODE_TYPE_ERROR);
755 return;
756 }
757
758 if ((offset & 3) > 0 || (length & 3) > 0) {
759 fw_send_response(card, request, RCODE_ADDRESS_ERROR);
760 return;
761 }
762
763 start = (offset - topology_map_region.start) / 4;
764 end = start + length / 4;
765 map = payload;
766
767 for (i = 0; i < length / 4; i++)
768 map[i] = cpu_to_be32(card->topology_map[start + i]);
769
770 fw_send_response(card, request, RCODE_COMPLETE);
771}
772
773static struct fw_address_handler topology_map = {
774 .length = 0x200,
775 .address_callback = handle_topology_map,
776};
777
778const struct fw_address_region registers_region =
779 { .start = 0xfffff0000000ull, .end = 0xfffff0000400ull, };
780
781static void
782handle_registers(struct fw_card *card, struct fw_request *request,
783 int tcode, int destination, int source,
784 int generation, int speed,
785 unsigned long long offset,
786 void *payload, size_t length, void *callback_data)
787{
788 int reg = offset - CSR_REGISTER_BASE;
789 unsigned long long bus_time;
790 __be32 *data = payload;
791
792 switch (reg) {
793 case CSR_CYCLE_TIME:
794 case CSR_BUS_TIME:
795 if (!TCODE_IS_READ_REQUEST(tcode) || length != 4) {
796 fw_send_response(card, request, RCODE_TYPE_ERROR);
797 break;
798 }
799
800 bus_time = card->driver->get_bus_time(card);
801 if (reg == CSR_CYCLE_TIME)
802 *data = cpu_to_be32(bus_time);
803 else
804 *data = cpu_to_be32(bus_time >> 25);
805 fw_send_response(card, request, RCODE_COMPLETE);
806 break;
807
808 case CSR_BUS_MANAGER_ID:
809 case CSR_BANDWIDTH_AVAILABLE:
810 case CSR_CHANNELS_AVAILABLE_HI:
811 case CSR_CHANNELS_AVAILABLE_LO:
812 /*
813 * FIXME: these are handled by the OHCI hardware and
814 * the stack never sees these request. If we add
815 * support for a new type of controller that doesn't
816 * handle this in hardware we need to deal with these
817 * transactions.
818 */
819 BUG();
820 break;
821
822 case CSR_BUSY_TIMEOUT:
823 /* FIXME: Implement this. */
824 default:
825 fw_send_response(card, request, RCODE_ADDRESS_ERROR);
826 break;
827 }
828}
829
830static struct fw_address_handler registers = {
831 .length = 0x400,
832 .address_callback = handle_registers,
833};
834
835MODULE_AUTHOR("Kristian Hoegsberg <krh@bitplanet.net>");
836MODULE_DESCRIPTION("Core IEEE1394 transaction logic");
837MODULE_LICENSE("GPL");
838
839static const u32 vendor_textual_descriptor[] = {
840 /* textual descriptor leaf () */
841 0x00060000,
842 0x00000000,
843 0x00000000,
844 0x4c696e75, /* L i n u */
845 0x78204669, /* x F i */
846 0x72657769, /* r e w i */
847 0x72650000, /* r e */
848};
849
850static const u32 model_textual_descriptor[] = {
851 /* model descriptor leaf () */
852 0x00030000,
853 0x00000000,
854 0x00000000,
855 0x4a756a75, /* J u j u */
856};
857
858static struct fw_descriptor vendor_id_descriptor = {
859 .length = ARRAY_SIZE(vendor_textual_descriptor),
860 .immediate = 0x03d00d1e,
861 .key = 0x81000000,
862 .data = vendor_textual_descriptor,
863};
864
865static struct fw_descriptor model_id_descriptor = {
866 .length = ARRAY_SIZE(model_textual_descriptor),
867 .immediate = 0x17000001,
868 .key = 0x81000000,
869 .data = model_textual_descriptor,
870};
871
872static int __init fw_core_init(void)
873{
874 int retval;
875
876 retval = bus_register(&fw_bus_type);
877 if (retval < 0)
878 return retval;
879
880 fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops);
881 if (fw_cdev_major < 0) {
882 bus_unregister(&fw_bus_type);
883 return fw_cdev_major;
884 }
885
886 retval = fw_core_add_address_handler(&topology_map,
887 &topology_map_region);
888 BUG_ON(retval < 0);
889
890 retval = fw_core_add_address_handler(&registers,
891 &registers_region);
892 BUG_ON(retval < 0);
893
894 /* Add the vendor textual descriptor. */
895 retval = fw_core_add_descriptor(&vendor_id_descriptor);
896 BUG_ON(retval < 0);
897 retval = fw_core_add_descriptor(&model_id_descriptor);
898 BUG_ON(retval < 0);
899
900 return 0;
901}
902
903static void __exit fw_core_cleanup(void)
904{
905 unregister_chrdev(fw_cdev_major, "firewire");
906 bus_unregister(&fw_bus_type);
907}
908
909module_init(fw_core_init);
910module_exit(fw_core_cleanup);
diff --git a/drivers/firewire/fw-transaction.h b/drivers/firewire/fw-transaction.h
new file mode 100644
index 000000000000..acdc3be38c61
--- /dev/null
+++ b/drivers/firewire/fw-transaction.h
@@ -0,0 +1,458 @@
1/*
2 * Copyright (C) 2003-2006 Kristian Hoegsberg <krh@bitplanet.net>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef __fw_transaction_h
20#define __fw_transaction_h
21
22#include <linux/device.h>
23#include <linux/timer.h>
24#include <linux/interrupt.h>
25#include <linux/list.h>
26#include <linux/fs.h>
27#include <linux/dma-mapping.h>
28#include <linux/firewire-constants.h>
29
30#define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4)
31#define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0)
32#define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0)
33#define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0)
34#define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4)
35#define TCODE_HAS_RESPONSE_DATA(tcode) (((tcode) & 12) != 0)
36
37#define LOCAL_BUS 0xffc0
38
39#define SELFID_PORT_CHILD 0x3
40#define SELFID_PORT_PARENT 0x2
41#define SELFID_PORT_NCONN 0x1
42#define SELFID_PORT_NONE 0x0
43
44#define PHY_PACKET_CONFIG 0x0
45#define PHY_PACKET_LINK_ON 0x1
46#define PHY_PACKET_SELF_ID 0x2
47
48/* Bit fields _within_ the PHY registers. */
49#define PHY_LINK_ACTIVE 0x80
50#define PHY_CONTENDER 0x40
51#define PHY_BUS_RESET 0x40
52#define PHY_BUS_SHORT_RESET 0x40
53
54#define CSR_REGISTER_BASE 0xfffff0000000ULL
55
56/* register offsets relative to CSR_REGISTER_BASE */
57#define CSR_STATE_CLEAR 0x0
58#define CSR_STATE_SET 0x4
59#define CSR_NODE_IDS 0x8
60#define CSR_RESET_START 0xc
61#define CSR_SPLIT_TIMEOUT_HI 0x18
62#define CSR_SPLIT_TIMEOUT_LO 0x1c
63#define CSR_CYCLE_TIME 0x200
64#define CSR_BUS_TIME 0x204
65#define CSR_BUSY_TIMEOUT 0x210
66#define CSR_BUS_MANAGER_ID 0x21c
67#define CSR_BANDWIDTH_AVAILABLE 0x220
68#define CSR_CHANNELS_AVAILABLE 0x224
69#define CSR_CHANNELS_AVAILABLE_HI 0x224
70#define CSR_CHANNELS_AVAILABLE_LO 0x228
71#define CSR_BROADCAST_CHANNEL 0x234
72#define CSR_CONFIG_ROM 0x400
73#define CSR_CONFIG_ROM_END 0x800
74#define CSR_FCP_COMMAND 0xB00
75#define CSR_FCP_RESPONSE 0xD00
76#define CSR_FCP_END 0xF00
77#define CSR_TOPOLOGY_MAP 0x1000
78#define CSR_TOPOLOGY_MAP_END 0x1400
79#define CSR_SPEED_MAP 0x2000
80#define CSR_SPEED_MAP_END 0x3000
81
82#define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
83#define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
84#define fw_debug(s, args...) printk(KERN_DEBUG KBUILD_MODNAME ": " s, ## args)
85
86static inline void
87fw_memcpy_from_be32(void *_dst, void *_src, size_t size)
88{
89 u32 *dst = _dst;
90 u32 *src = _src;
91 int i;
92
93 for (i = 0; i < size / 4; i++)
94 dst[i] = cpu_to_be32(src[i]);
95}
96
97static inline void
98fw_memcpy_to_be32(void *_dst, void *_src, size_t size)
99{
100 fw_memcpy_from_be32(_dst, _src, size);
101}
102
103struct fw_card;
104struct fw_packet;
105struct fw_node;
106struct fw_request;
107
108struct fw_descriptor {
109 struct list_head link;
110 size_t length;
111 u32 immediate;
112 u32 key;
113 const u32 *data;
114};
115
116int fw_core_add_descriptor(struct fw_descriptor *desc);
117void fw_core_remove_descriptor(struct fw_descriptor *desc);
118
119typedef void (*fw_packet_callback_t)(struct fw_packet *packet,
120 struct fw_card *card, int status);
121
122typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode,
123 void *data,
124 size_t length,
125 void *callback_data);
126
127typedef void (*fw_address_callback_t)(struct fw_card *card,
128 struct fw_request *request,
129 int tcode, int destination, int source,
130 int generation, int speed,
131 unsigned long long offset,
132 void *data, size_t length,
133 void *callback_data);
134
135typedef void (*fw_bus_reset_callback_t)(struct fw_card *handle,
136 int node_id, int generation,
137 u32 *self_ids,
138 int self_id_count,
139 void *callback_data);
140
141struct fw_packet {
142 int speed;
143 int generation;
144 u32 header[4];
145 size_t header_length;
146 void *payload;
147 size_t payload_length;
148 u32 timestamp;
149
150 /*
151 * This callback is called when the packet transmission has
152 * completed; for successful transmission, the status code is
153 * the ack received from the destination, otherwise it's a
154 * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO.
155 * The callback can be called from tasklet context and thus
156 * must never block.
157 */
158 fw_packet_callback_t callback;
159 int ack;
160 struct list_head link;
161 void *driver_data;
162};
163
164struct fw_transaction {
165 int node_id; /* The generation is implied; it is always the current. */
166 int tlabel;
167 int timestamp;
168 struct list_head link;
169
170 struct fw_packet packet;
171
172 /*
173 * The data passed to the callback is valid only during the
174 * callback.
175 */
176 fw_transaction_callback_t callback;
177 void *callback_data;
178};
179
180static inline struct fw_packet *
181fw_packet(struct list_head *l)
182{
183 return list_entry(l, struct fw_packet, link);
184}
185
186struct fw_address_handler {
187 u64 offset;
188 size_t length;
189 fw_address_callback_t address_callback;
190 void *callback_data;
191 struct list_head link;
192};
193
194
195struct fw_address_region {
196 u64 start;
197 u64 end;
198};
199
200extern const struct fw_address_region fw_low_memory_region;
201extern const struct fw_address_region fw_high_memory_region;
202extern const struct fw_address_region fw_private_region;
203extern const struct fw_address_region fw_csr_region;
204extern const struct fw_address_region fw_unit_space_region;
205
206int fw_core_add_address_handler(struct fw_address_handler *handler,
207 const struct fw_address_region *region);
208void fw_core_remove_address_handler(struct fw_address_handler *handler);
209void fw_fill_response(struct fw_packet *response, u32 *request_header,
210 int rcode, void *payload, size_t length);
211void fw_send_response(struct fw_card *card,
212 struct fw_request *request, int rcode);
213
214extern struct bus_type fw_bus_type;
215
216struct fw_card {
217 const struct fw_card_driver *driver;
218 struct device *device;
219 struct kref kref;
220
221 int node_id;
222 int generation;
223 /* This is the generation used for timestamping incoming requests. */
224 int request_generation;
225 int current_tlabel, tlabel_mask;
226 struct list_head transaction_list;
227 struct timer_list flush_timer;
228 unsigned long reset_jiffies;
229
230 unsigned long long guid;
231 int max_receive;
232 int link_speed;
233 int config_rom_generation;
234
235 /*
236 * We need to store up to 4 self ID for a maximum of 63
237 * devices plus 3 words for the topology map header.
238 */
239 int self_id_count;
240 u32 topology_map[252 + 3];
241
242 spinlock_t lock; /* Take this lock when handling the lists in
243 * this struct. */
244 struct fw_node *local_node;
245 struct fw_node *root_node;
246 struct fw_node *irm_node;
247 int color;
248 int gap_count;
249 int topology_type;
250
251 int index;
252
253 struct list_head link;
254
255 /* Work struct for BM duties. */
256 struct delayed_work work;
257 int bm_retries;
258 int bm_generation;
259};
260
261struct fw_card *fw_card_get(struct fw_card *card);
262void fw_card_put(struct fw_card *card);
263
264/*
265 * The iso packet format allows for an immediate header/payload part
266 * stored in 'header' immediately after the packet info plus an
267 * indirect payload part that is pointer to by the 'payload' field.
268 * Applications can use one or the other or both to implement simple
269 * low-bandwidth streaming (e.g. audio) or more advanced
270 * scatter-gather streaming (e.g. assembling video frame automatically).
271 */
272
273struct fw_iso_packet {
274 u16 payload_length; /* Length of indirect payload. */
275 u32 interrupt : 1; /* Generate interrupt on this packet */
276 u32 skip : 1; /* Set to not send packet at all. */
277 u32 tag : 2;
278 u32 sy : 4;
279 u32 header_length : 8; /* Length of immediate header. */
280 u32 header[0];
281};
282
283#define FW_ISO_CONTEXT_TRANSMIT 0
284#define FW_ISO_CONTEXT_RECEIVE 1
285
286#define FW_ISO_CONTEXT_MATCH_TAG0 1
287#define FW_ISO_CONTEXT_MATCH_TAG1 2
288#define FW_ISO_CONTEXT_MATCH_TAG2 4
289#define FW_ISO_CONTEXT_MATCH_TAG3 8
290#define FW_ISO_CONTEXT_MATCH_ALL_TAGS 15
291
292struct fw_iso_context;
293
294typedef void (*fw_iso_callback_t)(struct fw_iso_context *context,
295 u32 cycle,
296 size_t header_length,
297 void *header,
298 void *data);
299
300/*
301 * An iso buffer is just a set of pages mapped for DMA in the
302 * specified direction. Since the pages are to be used for DMA, they
303 * are not mapped into the kernel virtual address space. We store the
304 * DMA address in the page private. The helper function
305 * fw_iso_buffer_map() will map the pages into a given vma.
306 */
307
308struct fw_iso_buffer {
309 enum dma_data_direction direction;
310 struct page **pages;
311 int page_count;
312};
313
314struct fw_iso_context {
315 struct fw_card *card;
316 int type;
317 int channel;
318 int speed;
319 size_t header_size;
320 fw_iso_callback_t callback;
321 void *callback_data;
322};
323
324int
325fw_iso_buffer_init(struct fw_iso_buffer *buffer,
326 struct fw_card *card,
327 int page_count,
328 enum dma_data_direction direction);
329int
330fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma);
331void
332fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card);
333
334struct fw_iso_context *
335fw_iso_context_create(struct fw_card *card, int type,
336 int channel, int speed, size_t header_size,
337 fw_iso_callback_t callback, void *callback_data);
338
339void
340fw_iso_context_destroy(struct fw_iso_context *ctx);
341
342int
343fw_iso_context_queue(struct fw_iso_context *ctx,
344 struct fw_iso_packet *packet,
345 struct fw_iso_buffer *buffer,
346 unsigned long payload);
347
348int
349fw_iso_context_start(struct fw_iso_context *ctx,
350 int cycle, int sync, int tags);
351
352int
353fw_iso_context_stop(struct fw_iso_context *ctx);
354
355struct fw_card_driver {
356 const char *name;
357
358 /*
359 * Enable the given card with the given initial config rom.
360 * This function is expected to activate the card, and either
361 * enable the PHY or set the link_on bit and initiate a bus
362 * reset.
363 */
364 int (*enable)(struct fw_card *card, u32 *config_rom, size_t length);
365
366 int (*update_phy_reg)(struct fw_card *card, int address,
367 int clear_bits, int set_bits);
368
369 /*
370 * Update the config rom for an enabled card. This function
371 * should change the config rom that is presented on the bus
372 * an initiate a bus reset.
373 */
374 int (*set_config_rom)(struct fw_card *card,
375 u32 *config_rom, size_t length);
376
377 void (*send_request)(struct fw_card *card, struct fw_packet *packet);
378 void (*send_response)(struct fw_card *card, struct fw_packet *packet);
379 /* Calling cancel is valid once a packet has been submitted. */
380 int (*cancel_packet)(struct fw_card *card, struct fw_packet *packet);
381
382 /*
383 * Allow the specified node ID to do direct DMA out and in of
384 * host memory. The card will disable this for all node when
385 * a bus reset happens, so driver need to reenable this after
386 * bus reset. Returns 0 on success, -ENODEV if the card
387 * doesn't support this, -ESTALE if the generation doesn't
388 * match.
389 */
390 int (*enable_phys_dma)(struct fw_card *card,
391 int node_id, int generation);
392
393 u64 (*get_bus_time)(struct fw_card *card);
394
395 struct fw_iso_context *
396 (*allocate_iso_context)(struct fw_card *card,
397 int type, size_t header_size);
398 void (*free_iso_context)(struct fw_iso_context *ctx);
399
400 int (*start_iso)(struct fw_iso_context *ctx,
401 s32 cycle, u32 sync, u32 tags);
402
403 int (*queue_iso)(struct fw_iso_context *ctx,
404 struct fw_iso_packet *packet,
405 struct fw_iso_buffer *buffer,
406 unsigned long payload);
407
408 int (*stop_iso)(struct fw_iso_context *ctx);
409};
410
411int
412fw_core_initiate_bus_reset(struct fw_card *card, int short_reset);
413
414void
415fw_send_request(struct fw_card *card, struct fw_transaction *t,
416 int tcode, int node_id, int generation, int speed,
417 unsigned long long offset,
418 void *data, size_t length,
419 fw_transaction_callback_t callback, void *callback_data);
420
421int fw_cancel_transaction(struct fw_card *card,
422 struct fw_transaction *transaction);
423
424void fw_flush_transactions(struct fw_card *card);
425
426void fw_send_phy_config(struct fw_card *card,
427 int node_id, int generation, int gap_count);
428
429/*
430 * Called by the topology code to inform the device code of node
431 * activity; found, lost, or updated nodes.
432 */
433void
434fw_node_event(struct fw_card *card, struct fw_node *node, int event);
435
436/* API used by card level drivers */
437
438void
439fw_card_initialize(struct fw_card *card, const struct fw_card_driver *driver,
440 struct device *device);
441int
442fw_card_add(struct fw_card *card,
443 u32 max_receive, u32 link_speed, u64 guid);
444
445void
446fw_core_remove_card(struct fw_card *card);
447
448void
449fw_core_handle_bus_reset(struct fw_card *card,
450 int node_id, int generation,
451 int self_id_count, u32 *self_ids);
452void
453fw_core_handle_request(struct fw_card *card, struct fw_packet *request);
454
455void
456fw_core_handle_response(struct fw_card *card, struct fw_packet *packet);
457
458#endif /* __fw_transaction_h */
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 62e21cc73938..6ec04e79f685 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -20,7 +20,6 @@
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/smp_lock.h>
24#include <linux/spinlock.h> 23#include <linux/spinlock.h>
25#include <asm/unaligned.h> 24#include <asm/unaligned.h>
26#include <asm/byteorder.h> 25#include <asm/byteorder.h>
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index a19b65ed3119..7f817897b178 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -240,11 +240,94 @@ static inline void hidinput_pb_setup(struct input_dev *input)
240} 240}
241#endif 241#endif
242 242
243static inline int match_scancode(int code, int scancode)
244{
245 if (scancode == 0)
246 return 1;
247 return ((code & (HID_USAGE_PAGE | HID_USAGE)) == scancode);
248}
249
250static inline int match_keycode(int code, int keycode)
251{
252 if (keycode == 0)
253 return 1;
254 return (code == keycode);
255}
256
257static struct hid_usage *hidinput_find_key(struct hid_device *hid,
258 int scancode, int keycode)
259{
260 int i, j, k;
261 struct hid_report *report;
262 struct hid_usage *usage;
263
264 for (k = HID_INPUT_REPORT; k <= HID_OUTPUT_REPORT; k++) {
265 list_for_each_entry(report, &hid->report_enum[k].report_list, list) {
266 for (i = 0; i < report->maxfield; i++) {
267 for ( j = 0; j < report->field[i]->maxusage; j++) {
268 usage = report->field[i]->usage + j;
269 if (usage->type == EV_KEY &&
270 match_scancode(usage->hid, scancode) &&
271 match_keycode(usage->code, keycode))
272 return usage;
273 }
274 }
275 }
276 }
277 return NULL;
278}
279
280static int hidinput_getkeycode(struct input_dev *dev, int scancode,
281 int *keycode)
282{
283 struct hid_device *hid = dev->private;
284 struct hid_usage *usage;
285
286 usage = hidinput_find_key(hid, scancode, 0);
287 if (usage) {
288 *keycode = usage->code;
289 return 0;
290 }
291 return -EINVAL;
292}
293
294static int hidinput_setkeycode(struct input_dev *dev, int scancode,
295 int keycode)
296{
297 struct hid_device *hid = dev->private;
298 struct hid_usage *usage;
299 int old_keycode;
300
301 if (keycode < 0 || keycode > KEY_MAX)
302 return -EINVAL;
303
304 usage = hidinput_find_key(hid, scancode, 0);
305 if (usage) {
306 old_keycode = usage->code;
307 usage->code = keycode;
308
309 clear_bit(old_keycode, dev->keybit);
310 set_bit(usage->code, dev->keybit);
311#ifdef CONFIG_HID_DEBUG
312 printk (KERN_DEBUG "Assigned keycode %d to HID usage code %x\n", keycode, scancode);
313#endif
314 /* Set the keybit for the old keycode if the old keycode is used
315 * by another key */
316 if (hidinput_find_key (hid, 0, old_keycode))
317 set_bit(old_keycode, dev->keybit);
318
319 return 0;
320 }
321
322 return -EINVAL;
323}
324
325
243static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field, 326static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_field *field,
244 struct hid_usage *usage) 327 struct hid_usage *usage)
245{ 328{
246 struct input_dev *input = hidinput->input; 329 struct input_dev *input = hidinput->input;
247 struct hid_device *device = input->private; 330 struct hid_device *device = input_get_drvdata(input);
248 int max = 0, code; 331 int max = 0, code;
249 unsigned long *bit = NULL; 332 unsigned long *bit = NULL;
250 333
@@ -553,6 +636,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
553 case 0x1015: map_key_clear(KEY_RECORD); break; 636 case 0x1015: map_key_clear(KEY_RECORD); break;
554 case 0x1016: map_key_clear(KEY_PLAYER); break; 637 case 0x1016: map_key_clear(KEY_PLAYER); break;
555 case 0x1017: map_key_clear(KEY_EJECTCD); break; 638 case 0x1017: map_key_clear(KEY_EJECTCD); break;
639 case 0x1018: map_key_clear(KEY_MEDIA); break;
556 case 0x1019: map_key_clear(KEY_PROG1); break; 640 case 0x1019: map_key_clear(KEY_PROG1); break;
557 case 0x101a: map_key_clear(KEY_PROG2); break; 641 case 0x101a: map_key_clear(KEY_PROG2); break;
558 case 0x101b: map_key_clear(KEY_PROG3); break; 642 case 0x101b: map_key_clear(KEY_PROG3); break;
@@ -560,9 +644,12 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
560 case 0x1020: map_key_clear(KEY_ZOOMOUT); break; 644 case 0x1020: map_key_clear(KEY_ZOOMOUT); break;
561 case 0x1021: map_key_clear(KEY_ZOOMRESET); break; 645 case 0x1021: map_key_clear(KEY_ZOOMRESET); break;
562 case 0x1023: map_key_clear(KEY_CLOSE); break; 646 case 0x1023: map_key_clear(KEY_CLOSE); break;
647 case 0x1027: map_key_clear(KEY_MENU); break;
563 /* this one is marked as 'Rotate' */ 648 /* this one is marked as 'Rotate' */
564 case 0x1028: map_key_clear(KEY_ANGLE); break; 649 case 0x1028: map_key_clear(KEY_ANGLE); break;
565 case 0x1029: map_key_clear(KEY_SHUFFLE); break; 650 case 0x1029: map_key_clear(KEY_SHUFFLE); break;
651 case 0x102a: map_key_clear(KEY_BACK); break;
652 case 0x102b: map_key_clear(KEY_CYCLEWINDOWS); break;
566 case 0x1041: map_key_clear(KEY_BATTERY); break; 653 case 0x1041: map_key_clear(KEY_BATTERY); break;
567 case 0x1042: map_key_clear(KEY_WORDPROCESSOR); break; 654 case 0x1042: map_key_clear(KEY_WORDPROCESSOR); break;
568 case 0x1043: map_key_clear(KEY_SPREADSHEET); break; 655 case 0x1043: map_key_clear(KEY_SPREADSHEET); break;
@@ -855,13 +942,15 @@ EXPORT_SYMBOL_GPL(hidinput_find_field);
855 942
856static int hidinput_open(struct input_dev *dev) 943static int hidinput_open(struct input_dev *dev)
857{ 944{
858 struct hid_device *hid = dev->private; 945 struct hid_device *hid = input_get_drvdata(dev);
946
859 return hid->hid_open(hid); 947 return hid->hid_open(hid);
860} 948}
861 949
862static void hidinput_close(struct input_dev *dev) 950static void hidinput_close(struct input_dev *dev)
863{ 951{
864 struct hid_device *hid = dev->private; 952 struct hid_device *hid = input_get_drvdata(dev);
953
865 hid->hid_close(hid); 954 hid->hid_close(hid);
866} 955}
867 956
@@ -909,10 +998,12 @@ int hidinput_connect(struct hid_device *hid)
909 return -1; 998 return -1;
910 } 999 }
911 1000
912 input_dev->private = hid; 1001 input_set_drvdata(input_dev, hid);
913 input_dev->event = hid->hidinput_input_event; 1002 input_dev->event = hid->hidinput_input_event;
914 input_dev->open = hidinput_open; 1003 input_dev->open = hidinput_open;
915 input_dev->close = hidinput_close; 1004 input_dev->close = hidinput_close;
1005 input_dev->setkeycode = hidinput_setkeycode;
1006 input_dev->getkeycode = hidinput_getkeycode;
916 1007
917 input_dev->name = hid->name; 1008 input_dev->name = hid->name;
918 input_dev->phys = hid->phys; 1009 input_dev->phys = hid->phys;
@@ -921,7 +1012,7 @@ int hidinput_connect(struct hid_device *hid)
921 input_dev->id.vendor = hid->vendor; 1012 input_dev->id.vendor = hid->vendor;
922 input_dev->id.product = hid->product; 1013 input_dev->id.product = hid->product;
923 input_dev->id.version = hid->version; 1014 input_dev->id.version = hid->version;
924 input_dev->cdev.dev = hid->dev; 1015 input_dev->dev.parent = hid->dev;
925 hidinput->input = input_dev; 1016 hidinput->input = input_dev;
926 list_add_tail(&hidinput->list, &hid->inputs); 1017 list_add_tail(&hidinput->list, &hid->inputs);
927 } 1018 }
diff --git a/drivers/hid/usbhid/Kconfig b/drivers/hid/usbhid/Kconfig
index 7c87bdc538bc..1b4b572f899b 100644
--- a/drivers/hid/usbhid/Kconfig
+++ b/drivers/hid/usbhid/Kconfig
@@ -25,12 +25,12 @@ comment "Input core support is needed for USB HID input layer or HIDBP support"
25 depends on USB_HID && INPUT=n 25 depends on USB_HID && INPUT=n
26 26
27config USB_HIDINPUT_POWERBOOK 27config USB_HIDINPUT_POWERBOOK
28 bool "Enable support for iBook/PowerBook special keys" 28 bool "Enable support for iBook/PowerBook/MacBook/MacBookPro special keys"
29 default n 29 default n
30 depends on USB_HID 30 depends on USB_HID
31 help 31 help
32 Say Y here if you want support for the special keys (Fn, Numlock) on 32 Say Y here if you want support for the special keys (Fn, Numlock) on
33 Apple iBooks and PowerBooks. 33 Apple iBooks, PowerBooks, MacBooks and MacBook Pros.
34 34
35 If unsure, say N. 35 If unsure, say N.
36 36
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 91d610358d57..d91b9dac6dff 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -446,7 +446,7 @@ void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, uns
446 446
447static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 447static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
448{ 448{
449 struct hid_device *hid = dev->private; 449 struct hid_device *hid = input_get_drvdata(dev);
450 struct hid_field *field; 450 struct hid_field *field;
451 int offset; 451 int offset;
452 452
@@ -626,14 +626,10 @@ static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
626{ 626{
627 struct usbhid_device *usbhid = hid->driver_data; 627 struct usbhid_device *usbhid = hid->driver_data;
628 628
629 if (usbhid->inbuf) 629 usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma);
630 usb_buffer_free(dev, usbhid->bufsize, usbhid->inbuf, usbhid->inbuf_dma); 630 usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma);
631 if (usbhid->outbuf) 631 usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma);
632 usb_buffer_free(dev, usbhid->bufsize, usbhid->outbuf, usbhid->outbuf_dma); 632 usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma);
633 if (usbhid->cr)
634 usb_buffer_free(dev, sizeof(*(usbhid->cr)), usbhid->cr, usbhid->cr_dma);
635 if (usbhid->ctrlbuf)
636 usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma);
637} 633}
638 634
639/* 635/*
@@ -692,6 +688,30 @@ static void hid_fixup_logitech_descriptor(unsigned char *rdesc, int rsize)
692 } 688 }
693} 689}
694 690
691/*
692 * Some USB barcode readers from cypress have usage min and usage max in
693 * the wrong order
694 */
695static void hid_fixup_cypress_descriptor(unsigned char *rdesc, int rsize)
696{
697 short fixed = 0;
698 int i;
699
700 for (i = 0; i < rsize - 4; i++) {
701 if (rdesc[i] == 0x29 && rdesc [i+2] == 0x19) {
702 unsigned char tmp;
703
704 rdesc[i] = 0x19; rdesc[i+2] = 0x29;
705 tmp = rdesc[i+3];
706 rdesc[i+3] = rdesc[i+1];
707 rdesc[i+1] = tmp;
708 }
709 }
710
711 if (fixed)
712 info("Fixing up Cypress report descriptor");
713}
714
695static struct hid_device *usb_hid_configure(struct usb_interface *intf) 715static struct hid_device *usb_hid_configure(struct usb_interface *intf)
696{ 716{
697 struct usb_host_interface *interface = intf->cur_altsetting; 717 struct usb_host_interface *interface = intf->cur_altsetting;
@@ -758,6 +778,9 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
758 if (quirks & HID_QUIRK_LOGITECH_DESCRIPTOR) 778 if (quirks & HID_QUIRK_LOGITECH_DESCRIPTOR)
759 hid_fixup_logitech_descriptor(rdesc, rsize); 779 hid_fixup_logitech_descriptor(rdesc, rsize);
760 780
781 if (quirks & HID_QUIRK_SWAPPED_MIN_MAX)
782 hid_fixup_cypress_descriptor(rdesc, rsize);
783
761#ifdef CONFIG_HID_DEBUG 784#ifdef CONFIG_HID_DEBUG
762 printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n); 785 printk(KERN_DEBUG __FILE__ ": report descriptor (size %u, read %d) = ", rsize, n);
763 for (n = 0; n < rsize; n++) 786 for (n = 0; n < rsize; n++)
diff --git a/drivers/hid/usbhid/hid-lgff.c b/drivers/hid/usbhid/hid-lgff.c
index 92d2553f17b6..c5cd4107d6af 100644
--- a/drivers/hid/usbhid/hid-lgff.c
+++ b/drivers/hid/usbhid/hid-lgff.c
@@ -60,7 +60,7 @@ static const struct dev_type devices[] = {
60 60
61static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) 61static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
62{ 62{
63 struct hid_device *hid = dev->private; 63 struct hid_device *hid = input_get_drvdata(dev);
64 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 64 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
65 struct hid_report *report = list_entry(report_list->next, struct hid_report, list); 65 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
66 int x, y; 66 int x, y;
diff --git a/drivers/hid/usbhid/hid-plff.c b/drivers/hid/usbhid/hid-plff.c
index 76d2e6e14db4..d6a8f2b49bd2 100644
--- a/drivers/hid/usbhid/hid-plff.c
+++ b/drivers/hid/usbhid/hid-plff.c
@@ -37,7 +37,7 @@ struct plff_device {
37static int hid_plff_play(struct input_dev *dev, void *data, 37static int hid_plff_play(struct input_dev *dev, void *data,
38 struct ff_effect *effect) 38 struct ff_effect *effect)
39{ 39{
40 struct hid_device *hid = dev->private; 40 struct hid_device *hid = input_get_drvdata(dev);
41 struct plff_device *plff = data; 41 struct plff_device *plff = data;
42 int left, right; 42 int left, right;
43 43
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index 17a87555e32f..f6c4145dc202 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -92,6 +92,8 @@
92#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001 92#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001
93#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500 93#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500
94#define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417 94#define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417
95#define USB_DEVICE_ID_CYPRESS_BARCODE_1 0xde61
96#define USB_DEVICE_ID_CYPRESS_BARCODE_2 0xde64
95 97
96#define USB_VENDOR_ID_DELL 0x413c 98#define USB_VENDOR_ID_DELL 0x413c
97#define USB_DEVICE_ID_DELL_W7658 0x2005 99#define USB_DEVICE_ID_DELL_W7658 0x2005
@@ -193,6 +195,7 @@
193 195
194#define USB_VENDOR_ID_LOGITECH 0x046d 196#define USB_VENDOR_ID_LOGITECH 0x046d
195#define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101 197#define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101
198#define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294
196#define USB_DEVICE_ID_S510_RECEIVER 0xc50c 199#define USB_DEVICE_ID_S510_RECEIVER 0xc50c
197#define USB_DEVICE_ID_S510_RECEIVER_2 0xc517 200#define USB_DEVICE_ID_S510_RECEIVER_2 0xc517
198#define USB_DEVICE_ID_MX3000_RECEIVER 0xc513 201#define USB_DEVICE_ID_MX3000_RECEIVER 0xc513
@@ -422,6 +425,7 @@ static const struct hid_blacklist {
422 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 425 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
423 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET }, 426 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVM, HID_QUIRK_NOGET },
424 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 427 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
428 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL, HID_QUIRK_NOGET },
425 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, 429 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
426 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, 430 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
427 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 431 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
@@ -445,6 +449,9 @@ static const struct hid_blacklist {
445 449
446 { USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658, HID_QUIRK_RESET_LEDS }, 450 { USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658, HID_QUIRK_RESET_LEDS },
447 451
452 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1, HID_QUIRK_SWAPPED_MIN_MAX },
453 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2, HID_QUIRK_SWAPPED_MIN_MAX },
454
448 { 0, 0 } 455 { 0, 0 }
449}; 456};
450 457
diff --git a/drivers/hid/usbhid/hid-tmff.c b/drivers/hid/usbhid/hid-tmff.c
index ab67331620d0..ab5ba6ef891c 100644
--- a/drivers/hid/usbhid/hid-tmff.c
+++ b/drivers/hid/usbhid/hid-tmff.c
@@ -59,7 +59,7 @@ static inline int hid_tmff_scale(unsigned int in, int minimum, int maximum)
59 59
60static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect) 60static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
61{ 61{
62 struct hid_device *hid = dev->private; 62 struct hid_device *hid = input_get_drvdata(dev);
63 struct tmff_device *tmff = data; 63 struct tmff_device *tmff = data;
64 int left, right; /* Rumbling */ 64 int left, right; /* Rumbling */
65 65
diff --git a/drivers/hid/usbhid/hid-zpff.c b/drivers/hid/usbhid/hid-zpff.c
index 7bd8238ca212..a7fbffcdaf36 100644
--- a/drivers/hid/usbhid/hid-zpff.c
+++ b/drivers/hid/usbhid/hid-zpff.c
@@ -37,7 +37,7 @@ struct zpff_device {
37static int hid_zpff_play(struct input_dev *dev, void *data, 37static int hid_zpff_play(struct input_dev *dev, void *data,
38 struct ff_effect *effect) 38 struct ff_effect *effect)
39{ 39{
40 struct hid_device *hid = dev->private; 40 struct hid_device *hid = input_get_drvdata(dev);
41 struct zpff_device *zpff = data; 41 struct zpff_device *zpff = data;
42 int left, right; 42 int left, right;
43 43
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index a8b3d66cd498..488d61bdbf2c 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -51,6 +51,7 @@ struct hiddev {
51 wait_queue_head_t wait; 51 wait_queue_head_t wait;
52 struct hid_device *hid; 52 struct hid_device *hid;
53 struct list_head list; 53 struct list_head list;
54 spinlock_t list_lock;
54}; 55};
55 56
56struct hiddev_list { 57struct hiddev_list {
@@ -161,7 +162,9 @@ static void hiddev_send_event(struct hid_device *hid,
161{ 162{
162 struct hiddev *hiddev = hid->hiddev; 163 struct hiddev *hiddev = hid->hiddev;
163 struct hiddev_list *list; 164 struct hiddev_list *list;
165 unsigned long flags;
164 166
167 spin_lock_irqsave(&hiddev->list_lock, flags);
165 list_for_each_entry(list, &hiddev->list, node) { 168 list_for_each_entry(list, &hiddev->list, node) {
166 if (uref->field_index != HID_FIELD_INDEX_NONE || 169 if (uref->field_index != HID_FIELD_INDEX_NONE ||
167 (list->flags & HIDDEV_FLAG_REPORT) != 0) { 170 (list->flags & HIDDEV_FLAG_REPORT) != 0) {
@@ -171,6 +174,7 @@ static void hiddev_send_event(struct hid_device *hid,
171 kill_fasync(&list->fasync, SIGIO, POLL_IN); 174 kill_fasync(&list->fasync, SIGIO, POLL_IN);
172 } 175 }
173 } 176 }
177 spin_unlock_irqrestore(&hiddev->list_lock, flags);
174 178
175 wake_up_interruptible(&hiddev->wait); 179 wake_up_interruptible(&hiddev->wait);
176} 180}
@@ -235,9 +239,13 @@ static int hiddev_fasync(int fd, struct file *file, int on)
235static int hiddev_release(struct inode * inode, struct file * file) 239static int hiddev_release(struct inode * inode, struct file * file)
236{ 240{
237 struct hiddev_list *list = file->private_data; 241 struct hiddev_list *list = file->private_data;
242 unsigned long flags;
238 243
239 hiddev_fasync(-1, file, 0); 244 hiddev_fasync(-1, file, 0);
245
246 spin_lock_irqsave(&list->hiddev->list_lock, flags);
240 list_del(&list->node); 247 list_del(&list->node);
248 spin_unlock_irqrestore(&list->hiddev->list_lock, flags);
241 249
242 if (!--list->hiddev->open) { 250 if (!--list->hiddev->open) {
243 if (list->hiddev->exist) 251 if (list->hiddev->exist)
@@ -257,6 +265,7 @@ static int hiddev_release(struct inode * inode, struct file * file)
257static int hiddev_open(struct inode *inode, struct file *file) 265static int hiddev_open(struct inode *inode, struct file *file)
258{ 266{
259 struct hiddev_list *list; 267 struct hiddev_list *list;
268 unsigned long flags;
260 269
261 int i = iminor(inode) - HIDDEV_MINOR_BASE; 270 int i = iminor(inode) - HIDDEV_MINOR_BASE;
262 271
@@ -267,7 +276,11 @@ static int hiddev_open(struct inode *inode, struct file *file)
267 return -ENOMEM; 276 return -ENOMEM;
268 277
269 list->hiddev = hiddev_table[i]; 278 list->hiddev = hiddev_table[i];
279
280 spin_lock_irqsave(&list->hiddev->list_lock, flags);
270 list_add_tail(&list->node, &hiddev_table[i]->list); 281 list_add_tail(&list->node, &hiddev_table[i]->list);
282 spin_unlock_irqrestore(&list->hiddev->list_lock, flags);
283
271 file->private_data = list; 284 file->private_data = list;
272 285
273 if (!list->hiddev->open++) 286 if (!list->hiddev->open++)
@@ -773,6 +786,7 @@ int hiddev_connect(struct hid_device *hid)
773 786
774 init_waitqueue_head(&hiddev->wait); 787 init_waitqueue_head(&hiddev->wait);
775 INIT_LIST_HEAD(&hiddev->list); 788 INIT_LIST_HEAD(&hiddev->list);
789 spin_lock_init(&hiddev->list_lock);
776 hiddev->hid = hid; 790 hiddev->hid = hid;
777 hiddev->exist = 1; 791 hiddev->exist = 1;
778 792
diff --git a/drivers/hid/usbhid/usbkbd.c b/drivers/hid/usbhid/usbkbd.c
index 65aa12e8d7b3..130978780713 100644
--- a/drivers/hid/usbhid/usbkbd.c
+++ b/drivers/hid/usbhid/usbkbd.c
@@ -133,12 +133,11 @@ resubmit:
133static int usb_kbd_event(struct input_dev *dev, unsigned int type, 133static int usb_kbd_event(struct input_dev *dev, unsigned int type,
134 unsigned int code, int value) 134 unsigned int code, int value)
135{ 135{
136 struct usb_kbd *kbd = dev->private; 136 struct usb_kbd *kbd = input_get_drvdata(dev);
137 137
138 if (type != EV_LED) 138 if (type != EV_LED)
139 return -1; 139 return -1;
140 140
141
142 kbd->newleds = (!!test_bit(LED_KANA, dev->led) << 3) | (!!test_bit(LED_COMPOSE, dev->led) << 3) | 141 kbd->newleds = (!!test_bit(LED_KANA, dev->led) << 3) | (!!test_bit(LED_COMPOSE, dev->led) << 3) |
143 (!!test_bit(LED_SCROLLL, dev->led) << 2) | (!!test_bit(LED_CAPSL, dev->led) << 1) | 142 (!!test_bit(LED_SCROLLL, dev->led) << 2) | (!!test_bit(LED_CAPSL, dev->led) << 1) |
144 (!!test_bit(LED_NUML, dev->led)); 143 (!!test_bit(LED_NUML, dev->led));
@@ -175,7 +174,7 @@ static void usb_kbd_led(struct urb *urb)
175 174
176static int usb_kbd_open(struct input_dev *dev) 175static int usb_kbd_open(struct input_dev *dev)
177{ 176{
178 struct usb_kbd *kbd = dev->private; 177 struct usb_kbd *kbd = input_get_drvdata(dev);
179 178
180 kbd->irq->dev = kbd->usbdev; 179 kbd->irq->dev = kbd->usbdev;
181 if (usb_submit_urb(kbd->irq, GFP_KERNEL)) 180 if (usb_submit_urb(kbd->irq, GFP_KERNEL))
@@ -186,7 +185,7 @@ static int usb_kbd_open(struct input_dev *dev)
186 185
187static void usb_kbd_close(struct input_dev *dev) 186static void usb_kbd_close(struct input_dev *dev)
188{ 187{
189 struct usb_kbd *kbd = dev->private; 188 struct usb_kbd *kbd = input_get_drvdata(dev);
190 189
191 usb_kill_urb(kbd->irq); 190 usb_kill_urb(kbd->irq);
192} 191}
@@ -211,12 +210,9 @@ static void usb_kbd_free_mem(struct usb_device *dev, struct usb_kbd *kbd)
211{ 210{
212 usb_free_urb(kbd->irq); 211 usb_free_urb(kbd->irq);
213 usb_free_urb(kbd->led); 212 usb_free_urb(kbd->led);
214 if (kbd->new) 213 usb_buffer_free(dev, 8, kbd->new, kbd->new_dma);
215 usb_buffer_free(dev, 8, kbd->new, kbd->new_dma); 214 usb_buffer_free(dev, sizeof(struct usb_ctrlrequest), kbd->cr, kbd->cr_dma);
216 if (kbd->cr) 215 usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma);
217 usb_buffer_free(dev, sizeof(struct usb_ctrlrequest), kbd->cr, kbd->cr_dma);
218 if (kbd->leds)
219 usb_buffer_free(dev, 1, kbd->leds, kbd->leds_dma);
220} 216}
221 217
222static int usb_kbd_probe(struct usb_interface *iface, 218static int usb_kbd_probe(struct usb_interface *iface,
@@ -274,8 +270,9 @@ static int usb_kbd_probe(struct usb_interface *iface,
274 input_dev->name = kbd->name; 270 input_dev->name = kbd->name;
275 input_dev->phys = kbd->phys; 271 input_dev->phys = kbd->phys;
276 usb_to_input_id(dev, &input_dev->id); 272 usb_to_input_id(dev, &input_dev->id);
277 input_dev->cdev.dev = &iface->dev; 273 input_dev->dev.parent = &iface->dev;
278 input_dev->private = kbd; 274
275 input_set_drvdata(input_dev, kbd);
279 276
280 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP); 277 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_LED) | BIT(EV_REP);
281 input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL) | BIT(LED_COMPOSE) | BIT(LED_KANA); 278 input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL) | BIT(LED_COMPOSE) | BIT(LED_KANA);
diff --git a/drivers/hid/usbhid/usbmouse.c b/drivers/hid/usbhid/usbmouse.c
index 573776d865e1..5345c73bcf62 100644
--- a/drivers/hid/usbhid/usbmouse.c
+++ b/drivers/hid/usbhid/usbmouse.c
@@ -96,7 +96,7 @@ resubmit:
96 96
97static int usb_mouse_open(struct input_dev *dev) 97static int usb_mouse_open(struct input_dev *dev)
98{ 98{
99 struct usb_mouse *mouse = dev->private; 99 struct usb_mouse *mouse = input_get_drvdata(dev);
100 100
101 mouse->irq->dev = mouse->usbdev; 101 mouse->irq->dev = mouse->usbdev;
102 if (usb_submit_urb(mouse->irq, GFP_KERNEL)) 102 if (usb_submit_urb(mouse->irq, GFP_KERNEL))
@@ -107,7 +107,7 @@ static int usb_mouse_open(struct input_dev *dev)
107 107
108static void usb_mouse_close(struct input_dev *dev) 108static void usb_mouse_close(struct input_dev *dev)
109{ 109{
110 struct usb_mouse *mouse = dev->private; 110 struct usb_mouse *mouse = input_get_drvdata(dev);
111 111
112 usb_kill_urb(mouse->irq); 112 usb_kill_urb(mouse->irq);
113} 113}
@@ -171,7 +171,7 @@ static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_i
171 input_dev->name = mouse->name; 171 input_dev->name = mouse->name;
172 input_dev->phys = mouse->phys; 172 input_dev->phys = mouse->phys;
173 usb_to_input_id(dev, &input_dev->id); 173 usb_to_input_id(dev, &input_dev->id);
174 input_dev->cdev.dev = &intf->dev; 174 input_dev->dev.parent = &intf->dev;
175 175
176 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); 176 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL);
177 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); 177 input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE);
@@ -179,7 +179,8 @@ static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_i
179 input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA); 179 input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA);
180 input_dev->relbit[0] |= BIT(REL_WHEEL); 180 input_dev->relbit[0] |= BIT(REL_WHEEL);
181 181
182 input_dev->private = mouse; 182 input_set_drvdata(input_dev, mouse);
183
183 input_dev->open = usb_mouse_open; 184 input_dev->open = usb_mouse_open;
184 input_dev->close = usb_mouse_close; 185 input_dev->close = usb_mouse_close;
185 186
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 6d105a1d41b1..4d1cb5b855d1 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -2,10 +2,9 @@
2# Hardware monitoring chip drivers configuration 2# Hardware monitoring chip drivers configuration
3# 3#
4 4
5menu "Hardware Monitoring support" 5menuconfig HWMON
6
7config HWMON
8 tristate "Hardware Monitoring support" 6 tristate "Hardware Monitoring support"
7 depends on HAS_IOMEM
9 default y 8 default y
10 help 9 help
11 Hardware monitoring devices let you monitor the hardware health 10 Hardware monitoring devices let you monitor the hardware health
@@ -23,13 +22,15 @@ config HWMON
23 This support can also be built as a module. If so, the module 22 This support can also be built as a module. If so, the module
24 will be called hwmon. 23 will be called hwmon.
25 24
25if HWMON
26
26config HWMON_VID 27config HWMON_VID
27 tristate 28 tristate
28 default n 29 default n
29 30
30config SENSORS_ABITUGURU 31config SENSORS_ABITUGURU
31 tristate "Abit uGuru" 32 tristate "Abit uGuru"
32 depends on HWMON && EXPERIMENTAL 33 depends on EXPERIMENTAL
33 help 34 help
34 If you say yes here you get support for the Abit uGuru chips 35 If you say yes here you get support for the Abit uGuru chips
35 sensor part. The voltage and frequency control parts of the Abit 36 sensor part. The voltage and frequency control parts of the Abit
@@ -39,9 +40,19 @@ config SENSORS_ABITUGURU
39 This driver can also be built as a module. If so, the module 40 This driver can also be built as a module. If so, the module
40 will be called abituguru. 41 will be called abituguru.
41 42
43config SENSORS_AD7418
44 tristate "Analog Devices AD7416, AD7417 and AD7418"
45 depends on I2C && EXPERIMENTAL
46 help
47 If you say yes here you get support for the Analog Devices
48 AD7416, AD7417 and AD7418 temperature monitoring chips.
49
50 This driver can also be built as a module. If so, the module
51 will be called ad7418.
52
42config SENSORS_ADM1021 53config SENSORS_ADM1021
43 tristate "Analog Devices ADM1021 and compatibles" 54 tristate "Analog Devices ADM1021 and compatibles"
44 depends on HWMON && I2C 55 depends on I2C
45 help 56 help
46 If you say yes here you get support for Analog Devices ADM1021 57 If you say yes here you get support for Analog Devices ADM1021
47 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A, 58 and ADM1023 sensor chips and clones: Maxim MAX1617 and MAX1617A,
@@ -53,7 +64,7 @@ config SENSORS_ADM1021
53 64
54config SENSORS_ADM1025 65config SENSORS_ADM1025
55 tristate "Analog Devices ADM1025 and compatibles" 66 tristate "Analog Devices ADM1025 and compatibles"
56 depends on HWMON && I2C 67 depends on I2C
57 select HWMON_VID 68 select HWMON_VID
58 help 69 help
59 If you say yes here you get support for Analog Devices ADM1025 70 If you say yes here you get support for Analog Devices ADM1025
@@ -64,7 +75,7 @@ config SENSORS_ADM1025
64 75
65config SENSORS_ADM1026 76config SENSORS_ADM1026
66 tristate "Analog Devices ADM1026 and compatibles" 77 tristate "Analog Devices ADM1026 and compatibles"
67 depends on HWMON && I2C && EXPERIMENTAL 78 depends on I2C && EXPERIMENTAL
68 select HWMON_VID 79 select HWMON_VID
69 help 80 help
70 If you say yes here you get support for Analog Devices ADM1026 81 If you say yes here you get support for Analog Devices ADM1026
@@ -75,7 +86,7 @@ config SENSORS_ADM1026
75 86
76config SENSORS_ADM1029 87config SENSORS_ADM1029
77 tristate "Analog Devices ADM1029" 88 tristate "Analog Devices ADM1029"
78 depends on HWMON && I2C && EXPERIMENTAL 89 depends on I2C && EXPERIMENTAL
79 help 90 help
80 If you say yes here you get support for Analog Devices ADM1029 91 If you say yes here you get support for Analog Devices ADM1029
81 sensor chip. 92 sensor chip.
@@ -86,7 +97,7 @@ config SENSORS_ADM1029
86 97
87config SENSORS_ADM1031 98config SENSORS_ADM1031
88 tristate "Analog Devices ADM1031 and compatibles" 99 tristate "Analog Devices ADM1031 and compatibles"
89 depends on HWMON && I2C && EXPERIMENTAL 100 depends on I2C && EXPERIMENTAL
90 help 101 help
91 If you say yes here you get support for Analog Devices ADM1031 102 If you say yes here you get support for Analog Devices ADM1031
92 and ADM1030 sensor chips. 103 and ADM1030 sensor chips.
@@ -96,7 +107,7 @@ config SENSORS_ADM1031
96 107
97config SENSORS_ADM9240 108config SENSORS_ADM9240
98 tristate "Analog Devices ADM9240 and compatibles" 109 tristate "Analog Devices ADM9240 and compatibles"
99 depends on HWMON && I2C && EXPERIMENTAL 110 depends on I2C && EXPERIMENTAL
100 select HWMON_VID 111 select HWMON_VID
101 help 112 help
102 If you say yes here you get support for Analog Devices ADM9240, 113 If you say yes here you get support for Analog Devices ADM9240,
@@ -107,7 +118,7 @@ config SENSORS_ADM9240
107 118
108config SENSORS_K8TEMP 119config SENSORS_K8TEMP
109 tristate "AMD Athlon64/FX or Opteron temperature sensor" 120 tristate "AMD Athlon64/FX or Opteron temperature sensor"
110 depends on HWMON && X86 && PCI && EXPERIMENTAL 121 depends on X86 && PCI && EXPERIMENTAL
111 help 122 help
112 If you say yes here you get support for the temperature 123 If you say yes here you get support for the temperature
113 sensor(s) inside your CPU. Supported is whole AMD K8 124 sensor(s) inside your CPU. Supported is whole AMD K8
@@ -119,7 +130,7 @@ config SENSORS_K8TEMP
119 130
120config SENSORS_AMS 131config SENSORS_AMS
121 tristate "Apple Motion Sensor driver" 132 tristate "Apple Motion Sensor driver"
122 depends on HWMON && PPC_PMAC && !PPC64 && INPUT && ((ADB_PMU && I2C = y) || (ADB_PMU && !I2C) || I2C) && EXPERIMENTAL 133 depends on PPC_PMAC && !PPC64 && INPUT && ((ADB_PMU && I2C = y) || (ADB_PMU && !I2C) || I2C) && EXPERIMENTAL
123 help 134 help
124 Support for the motion sensor included in PowerBooks. Includes 135 Support for the motion sensor included in PowerBooks. Includes
125 implementations for PMU and I2C. 136 implementations for PMU and I2C.
@@ -144,7 +155,7 @@ config SENSORS_AMS_I2C
144 155
145config SENSORS_ASB100 156config SENSORS_ASB100
146 tristate "Asus ASB100 Bach" 157 tristate "Asus ASB100 Bach"
147 depends on HWMON && I2C && EXPERIMENTAL 158 depends on I2C && EXPERIMENTAL
148 select HWMON_VID 159 select HWMON_VID
149 help 160 help
150 If you say yes here you get support for the ASB100 Bach sensor 161 If you say yes here you get support for the ASB100 Bach sensor
@@ -155,7 +166,7 @@ config SENSORS_ASB100
155 166
156config SENSORS_ATXP1 167config SENSORS_ATXP1
157 tristate "Attansic ATXP1 VID controller" 168 tristate "Attansic ATXP1 VID controller"
158 depends on HWMON && I2C && EXPERIMENTAL 169 depends on I2C && EXPERIMENTAL
159 select HWMON_VID 170 select HWMON_VID
160 help 171 help
161 If you say yes here you get support for the Attansic ATXP1 VID 172 If you say yes here you get support for the Attansic ATXP1 VID
@@ -169,7 +180,7 @@ config SENSORS_ATXP1
169 180
170config SENSORS_DS1621 181config SENSORS_DS1621
171 tristate "Dallas Semiconductor DS1621 and DS1625" 182 tristate "Dallas Semiconductor DS1621 and DS1625"
172 depends on HWMON && I2C 183 depends on I2C
173 help 184 help
174 If you say yes here you get support for Dallas Semiconductor 185 If you say yes here you get support for Dallas Semiconductor
175 DS1621 and DS1625 sensor chips. 186 DS1621 and DS1625 sensor chips.
@@ -179,7 +190,7 @@ config SENSORS_DS1621
179 190
180config SENSORS_F71805F 191config SENSORS_F71805F
181 tristate "Fintek F71805F/FG and F71872F/FG" 192 tristate "Fintek F71805F/FG and F71872F/FG"
182 depends on HWMON && EXPERIMENTAL 193 depends on EXPERIMENTAL
183 help 194 help
184 If you say yes here you get support for hardware monitoring 195 If you say yes here you get support for hardware monitoring
185 features of the Fintek F71805F/FG and F71872F/FG Super-I/O 196 features of the Fintek F71805F/FG and F71872F/FG Super-I/O
@@ -190,7 +201,7 @@ config SENSORS_F71805F
190 201
191config SENSORS_FSCHER 202config SENSORS_FSCHER
192 tristate "FSC Hermes" 203 tristate "FSC Hermes"
193 depends on HWMON && I2C 204 depends on I2C
194 help 205 help
195 If you say yes here you get support for Fujitsu Siemens 206 If you say yes here you get support for Fujitsu Siemens
196 Computers Hermes sensor chips. 207 Computers Hermes sensor chips.
@@ -200,7 +211,7 @@ config SENSORS_FSCHER
200 211
201config SENSORS_FSCPOS 212config SENSORS_FSCPOS
202 tristate "FSC Poseidon" 213 tristate "FSC Poseidon"
203 depends on HWMON && I2C 214 depends on I2C
204 help 215 help
205 If you say yes here you get support for Fujitsu Siemens 216 If you say yes here you get support for Fujitsu Siemens
206 Computers Poseidon sensor chips. 217 Computers Poseidon sensor chips.
@@ -210,7 +221,7 @@ config SENSORS_FSCPOS
210 221
211config SENSORS_GL518SM 222config SENSORS_GL518SM
212 tristate "Genesys Logic GL518SM" 223 tristate "Genesys Logic GL518SM"
213 depends on HWMON && I2C 224 depends on I2C
214 help 225 help
215 If you say yes here you get support for Genesys Logic GL518SM 226 If you say yes here you get support for Genesys Logic GL518SM
216 sensor chips. 227 sensor chips.
@@ -220,7 +231,7 @@ config SENSORS_GL518SM
220 231
221config SENSORS_GL520SM 232config SENSORS_GL520SM
222 tristate "Genesys Logic GL520SM" 233 tristate "Genesys Logic GL520SM"
223 depends on HWMON && I2C 234 depends on I2C
224 select HWMON_VID 235 select HWMON_VID
225 help 236 help
226 If you say yes here you get support for Genesys Logic GL520SM 237 If you say yes here you get support for Genesys Logic GL520SM
@@ -229,9 +240,17 @@ config SENSORS_GL520SM
229 This driver can also be built as a module. If so, the module 240 This driver can also be built as a module. If so, the module
230 will be called gl520sm. 241 will be called gl520sm.
231 242
243config SENSORS_CORETEMP
244 tristate "Intel Core (2) Duo/Solo temperature sensor"
245 depends on X86 && EXPERIMENTAL
246 help
247 If you say yes here you get support for the temperature
248 sensor inside your CPU. Supported all are all known variants
249 of Intel Core family.
250
232config SENSORS_IT87 251config SENSORS_IT87
233 tristate "ITE IT87xx and compatibles" 252 tristate "ITE IT87xx and compatibles"
234 depends on HWMON && I2C 253 depends on I2C
235 select I2C_ISA 254 select I2C_ISA
236 select HWMON_VID 255 select HWMON_VID
237 help 256 help
@@ -243,7 +262,7 @@ config SENSORS_IT87
243 262
244config SENSORS_LM63 263config SENSORS_LM63
245 tristate "National Semiconductor LM63" 264 tristate "National Semiconductor LM63"
246 depends on HWMON && I2C 265 depends on I2C
247 help 266 help
248 If you say yes here you get support for the National Semiconductor 267 If you say yes here you get support for the National Semiconductor
249 LM63 remote diode digital temperature sensor with integrated fan 268 LM63 remote diode digital temperature sensor with integrated fan
@@ -255,7 +274,7 @@ config SENSORS_LM63
255 274
256config SENSORS_LM70 275config SENSORS_LM70
257 tristate "National Semiconductor LM70" 276 tristate "National Semiconductor LM70"
258 depends on HWMON && SPI_MASTER && EXPERIMENTAL 277 depends on SPI_MASTER && EXPERIMENTAL
259 help 278 help
260 If you say yes here you get support for the National Semiconductor 279 If you say yes here you get support for the National Semiconductor
261 LM70 digital temperature sensor chip. 280 LM70 digital temperature sensor chip.
@@ -265,7 +284,7 @@ config SENSORS_LM70
265 284
266config SENSORS_LM75 285config SENSORS_LM75
267 tristate "National Semiconductor LM75 and compatibles" 286 tristate "National Semiconductor LM75 and compatibles"
268 depends on HWMON && I2C 287 depends on I2C
269 help 288 help
270 If you say yes here you get support for National Semiconductor LM75 289 If you say yes here you get support for National Semiconductor LM75
271 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in 290 sensor chips and clones: Dallas Semiconductor DS75 and DS1775 (in
@@ -280,7 +299,7 @@ config SENSORS_LM75
280 299
281config SENSORS_LM77 300config SENSORS_LM77
282 tristate "National Semiconductor LM77" 301 tristate "National Semiconductor LM77"
283 depends on HWMON && I2C 302 depends on I2C
284 help 303 help
285 If you say yes here you get support for National Semiconductor LM77 304 If you say yes here you get support for National Semiconductor LM77
286 sensor chips. 305 sensor chips.
@@ -290,8 +309,7 @@ config SENSORS_LM77
290 309
291config SENSORS_LM78 310config SENSORS_LM78
292 tristate "National Semiconductor LM78 and compatibles" 311 tristate "National Semiconductor LM78 and compatibles"
293 depends on HWMON && I2C 312 depends on I2C
294 select I2C_ISA
295 select HWMON_VID 313 select HWMON_VID
296 help 314 help
297 If you say yes here you get support for National Semiconductor LM78, 315 If you say yes here you get support for National Semiconductor LM78,
@@ -302,7 +320,7 @@ config SENSORS_LM78
302 320
303config SENSORS_LM80 321config SENSORS_LM80
304 tristate "National Semiconductor LM80" 322 tristate "National Semiconductor LM80"
305 depends on HWMON && I2C && EXPERIMENTAL 323 depends on I2C && EXPERIMENTAL
306 help 324 help
307 If you say yes here you get support for National Semiconductor 325 If you say yes here you get support for National Semiconductor
308 LM80 sensor chips. 326 LM80 sensor chips.
@@ -312,7 +330,7 @@ config SENSORS_LM80
312 330
313config SENSORS_LM83 331config SENSORS_LM83
314 tristate "National Semiconductor LM83 and compatibles" 332 tristate "National Semiconductor LM83 and compatibles"
315 depends on HWMON && I2C 333 depends on I2C
316 help 334 help
317 If you say yes here you get support for National Semiconductor 335 If you say yes here you get support for National Semiconductor
318 LM82 and LM83 sensor chips. 336 LM82 and LM83 sensor chips.
@@ -322,7 +340,7 @@ config SENSORS_LM83
322 340
323config SENSORS_LM85 341config SENSORS_LM85
324 tristate "National Semiconductor LM85 and compatibles" 342 tristate "National Semiconductor LM85 and compatibles"
325 depends on HWMON && I2C && EXPERIMENTAL 343 depends on I2C && EXPERIMENTAL
326 select HWMON_VID 344 select HWMON_VID
327 help 345 help
328 If you say yes here you get support for National Semiconductor LM85 346 If you say yes here you get support for National Semiconductor LM85
@@ -333,7 +351,7 @@ config SENSORS_LM85
333 351
334config SENSORS_LM87 352config SENSORS_LM87
335 tristate "National Semiconductor LM87" 353 tristate "National Semiconductor LM87"
336 depends on HWMON && I2C 354 depends on I2C
337 select HWMON_VID 355 select HWMON_VID
338 help 356 help
339 If you say yes here you get support for National Semiconductor LM87 357 If you say yes here you get support for National Semiconductor LM87
@@ -344,7 +362,7 @@ config SENSORS_LM87
344 362
345config SENSORS_LM90 363config SENSORS_LM90
346 tristate "National Semiconductor LM90 and compatibles" 364 tristate "National Semiconductor LM90 and compatibles"
347 depends on HWMON && I2C 365 depends on I2C
348 help 366 help
349 If you say yes here you get support for National Semiconductor LM90, 367 If you say yes here you get support for National Semiconductor LM90,
350 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and 368 LM86, LM89 and LM99, Analog Devices ADM1032 and Maxim MAX6657 and
@@ -358,7 +376,7 @@ config SENSORS_LM90
358 376
359config SENSORS_LM92 377config SENSORS_LM92
360 tristate "National Semiconductor LM92 and compatibles" 378 tristate "National Semiconductor LM92 and compatibles"
361 depends on HWMON && I2C 379 depends on I2C
362 help 380 help
363 If you say yes here you get support for National Semiconductor LM92 381 If you say yes here you get support for National Semiconductor LM92
364 and Maxim MAX6635 sensor chips. 382 and Maxim MAX6635 sensor chips.
@@ -368,16 +386,26 @@ config SENSORS_LM92
368 386
369config SENSORS_MAX1619 387config SENSORS_MAX1619
370 tristate "Maxim MAX1619 sensor chip" 388 tristate "Maxim MAX1619 sensor chip"
371 depends on HWMON && I2C 389 depends on I2C
372 help 390 help
373 If you say yes here you get support for MAX1619 sensor chip. 391 If you say yes here you get support for MAX1619 sensor chip.
374 392
375 This driver can also be built as a module. If so, the module 393 This driver can also be built as a module. If so, the module
376 will be called max1619. 394 will be called max1619.
377 395
396config SENSORS_MAX6650
397 tristate "Maxim MAX6650 sensor chip"
398 depends on I2C && EXPERIMENTAL
399 help
400 If you say yes here you get support for the MAX6650 / MAX6651
401 sensor chips.
402
403 This driver can also be built as a module. If so, the module
404 will be called max6650.
405
378config SENSORS_PC87360 406config SENSORS_PC87360
379 tristate "National Semiconductor PC87360 family" 407 tristate "National Semiconductor PC87360 family"
380 depends on HWMON && I2C && EXPERIMENTAL 408 depends on I2C && EXPERIMENTAL
381 select I2C_ISA 409 select I2C_ISA
382 select HWMON_VID 410 select HWMON_VID
383 help 411 help
@@ -392,7 +420,7 @@ config SENSORS_PC87360
392 420
393config SENSORS_PC87427 421config SENSORS_PC87427
394 tristate "National Semiconductor PC87427" 422 tristate "National Semiconductor PC87427"
395 depends on HWMON && EXPERIMENTAL 423 depends on EXPERIMENTAL
396 help 424 help
397 If you say yes here you get access to the hardware monitoring 425 If you say yes here you get access to the hardware monitoring
398 functions of the National Semiconductor PC87427 Super-I/O chip. 426 functions of the National Semiconductor PC87427 Super-I/O chip.
@@ -405,7 +433,7 @@ config SENSORS_PC87427
405 433
406config SENSORS_SIS5595 434config SENSORS_SIS5595
407 tristate "Silicon Integrated Systems Corp. SiS5595" 435 tristate "Silicon Integrated Systems Corp. SiS5595"
408 depends on HWMON && I2C && PCI && EXPERIMENTAL 436 depends on I2C && PCI && EXPERIMENTAL
409 select I2C_ISA 437 select I2C_ISA
410 help 438 help
411 If you say yes here you get support for the integrated sensors in 439 If you say yes here you get support for the integrated sensors in
@@ -416,28 +444,28 @@ config SENSORS_SIS5595
416 444
417config SENSORS_SMSC47M1 445config SENSORS_SMSC47M1
418 tristate "SMSC LPC47M10x and compatibles" 446 tristate "SMSC LPC47M10x and compatibles"
419 depends on HWMON && I2C
420 select I2C_ISA
421 help 447 help
422 If you say yes here you get support for the integrated fan 448 If you say yes here you get support for the integrated fan
423 monitoring and control capabilities of the SMSC LPC47B27x, 449 monitoring and control capabilities of the SMSC LPC47B27x,
424 LPC47M10x, LPC47M112, LPC47M13x, LPC47M14x, LPC47M15x, 450 LPC47M10x, LPC47M112, LPC47M13x, LPC47M14x, LPC47M15x,
425 LPC47M192 and LPC47M997 chips. 451 LPC47M192, LPC47M292 and LPC47M997 chips.
426 452
427 The temperature and voltage sensor features of the LPC47M192 453 The temperature and voltage sensor features of the LPC47M15x,
428 and LPC47M997 are supported by another driver, select also 454 LPC47M192, LPC47M292 and LPC47M997 are supported by another
429 "SMSC LPC47M192 and compatibles" below for those. 455 driver, select also "SMSC LPC47M192 and compatibles" below for
456 those.
430 457
431 This driver can also be built as a module. If so, the module 458 This driver can also be built as a module. If so, the module
432 will be called smsc47m1. 459 will be called smsc47m1.
433 460
434config SENSORS_SMSC47M192 461config SENSORS_SMSC47M192
435 tristate "SMSC LPC47M192 and compatibles" 462 tristate "SMSC LPC47M192 and compatibles"
436 depends on HWMON && I2C && EXPERIMENTAL 463 depends on I2C && EXPERIMENTAL
437 select HWMON_VID 464 select HWMON_VID
438 help 465 help
439 If you say yes here you get support for the temperature and 466 If you say yes here you get support for the temperature and
440 voltage sensors of the SMSC LPC47M192 and LPC47M997 chips. 467 voltage sensors of the SMSC LPC47M192, LPC47M15x, LPC47M292
468 and LPC47M997 chips.
441 469
442 The fan monitoring and control capabilities of these chips 470 The fan monitoring and control capabilities of these chips
443 are supported by another driver, select 471 are supported by another driver, select
@@ -449,8 +477,7 @@ config SENSORS_SMSC47M192
449 477
450config SENSORS_SMSC47B397 478config SENSORS_SMSC47B397
451 tristate "SMSC LPC47B397-NC" 479 tristate "SMSC LPC47B397-NC"
452 depends on HWMON && I2C && EXPERIMENTAL 480 depends on EXPERIMENTAL
453 select I2C_ISA
454 help 481 help
455 If you say yes here you get support for the SMSC LPC47B397-NC 482 If you say yes here you get support for the SMSC LPC47B397-NC
456 sensor chip. 483 sensor chip.
@@ -460,7 +487,7 @@ config SENSORS_SMSC47B397
460 487
461config SENSORS_VIA686A 488config SENSORS_VIA686A
462 tristate "VIA686A" 489 tristate "VIA686A"
463 depends on HWMON && I2C && PCI 490 depends on I2C && PCI
464 select I2C_ISA 491 select I2C_ISA
465 help 492 help
466 If you say yes here you get support for the integrated sensors in 493 If you say yes here you get support for the integrated sensors in
@@ -471,7 +498,7 @@ config SENSORS_VIA686A
471 498
472config SENSORS_VT1211 499config SENSORS_VT1211
473 tristate "VIA VT1211" 500 tristate "VIA VT1211"
474 depends on HWMON && EXPERIMENTAL 501 depends on EXPERIMENTAL
475 select HWMON_VID 502 select HWMON_VID
476 help 503 help
477 If you say yes here then you get support for hardware monitoring 504 If you say yes here then you get support for hardware monitoring
@@ -482,7 +509,7 @@ config SENSORS_VT1211
482 509
483config SENSORS_VT8231 510config SENSORS_VT8231
484 tristate "VIA VT8231" 511 tristate "VIA VT8231"
485 depends on HWMON && I2C && PCI && EXPERIMENTAL 512 depends on I2C && PCI && EXPERIMENTAL
486 select HWMON_VID 513 select HWMON_VID
487 select I2C_ISA 514 select I2C_ISA
488 help 515 help
@@ -494,8 +521,7 @@ config SENSORS_VT8231
494 521
495config SENSORS_W83781D 522config SENSORS_W83781D
496 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F" 523 tristate "Winbond W83781D, W83782D, W83783S, W83627HF, Asus AS99127F"
497 depends on HWMON && I2C 524 depends on I2C
498 select I2C_ISA
499 select HWMON_VID 525 select HWMON_VID
500 help 526 help
501 If you say yes here you get support for the Winbond W8378x series 527 If you say yes here you get support for the Winbond W8378x series
@@ -507,7 +533,7 @@ config SENSORS_W83781D
507 533
508config SENSORS_W83791D 534config SENSORS_W83791D
509 tristate "Winbond W83791D" 535 tristate "Winbond W83791D"
510 depends on HWMON && I2C && EXPERIMENTAL 536 depends on I2C && EXPERIMENTAL
511 select HWMON_VID 537 select HWMON_VID
512 help 538 help
513 If you say yes here you get support for the Winbond W83791D chip. 539 If you say yes here you get support for the Winbond W83791D chip.
@@ -517,7 +543,7 @@ config SENSORS_W83791D
517 543
518config SENSORS_W83792D 544config SENSORS_W83792D
519 tristate "Winbond W83792D" 545 tristate "Winbond W83792D"
520 depends on HWMON && I2C && EXPERIMENTAL 546 depends on I2C && EXPERIMENTAL
521 help 547 help
522 If you say yes here you get support for the Winbond W83792D chip. 548 If you say yes here you get support for the Winbond W83792D chip.
523 549
@@ -526,7 +552,7 @@ config SENSORS_W83792D
526 552
527config SENSORS_W83793 553config SENSORS_W83793
528 tristate "Winbond W83793" 554 tristate "Winbond W83793"
529 depends on HWMON && I2C && EXPERIMENTAL 555 depends on I2C && EXPERIMENTAL
530 select HWMON_VID 556 select HWMON_VID
531 help 557 help
532 If you say yes here you get support for the Winbond W83793 558 If you say yes here you get support for the Winbond W83793
@@ -537,7 +563,7 @@ config SENSORS_W83793
537 563
538config SENSORS_W83L785TS 564config SENSORS_W83L785TS
539 tristate "Winbond W83L785TS-S" 565 tristate "Winbond W83L785TS-S"
540 depends on HWMON && I2C && EXPERIMENTAL 566 depends on I2C && EXPERIMENTAL
541 help 567 help
542 If you say yes here you get support for the Winbond W83L785TS-S 568 If you say yes here you get support for the Winbond W83L785TS-S
543 sensor chip, which is used on the Asus A7N8X, among other 569 sensor chip, which is used on the Asus A7N8X, among other
@@ -548,8 +574,6 @@ config SENSORS_W83L785TS
548 574
549config SENSORS_W83627HF 575config SENSORS_W83627HF
550 tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF" 576 tristate "Winbond W83627HF, W83627THF, W83637HF, W83687THF, W83697HF"
551 depends on HWMON && I2C
552 select I2C_ISA
553 select HWMON_VID 577 select HWMON_VID
554 help 578 help
555 If you say yes here you get support for the Winbond W836X7 series 579 If you say yes here you get support for the Winbond W836X7 series
@@ -561,7 +585,7 @@ config SENSORS_W83627HF
561 585
562config SENSORS_W83627EHF 586config SENSORS_W83627EHF
563 tristate "Winbond W83627EHF" 587 tristate "Winbond W83627EHF"
564 depends on HWMON && I2C && EXPERIMENTAL 588 depends on I2C && EXPERIMENTAL
565 select I2C_ISA 589 select I2C_ISA
566 help 590 help
567 If you say yes here you get preliminary support for the hardware 591 If you say yes here you get preliminary support for the hardware
@@ -577,7 +601,7 @@ config SENSORS_W83627EHF
577 601
578config SENSORS_HDAPS 602config SENSORS_HDAPS
579 tristate "IBM Hard Drive Active Protection System (hdaps)" 603 tristate "IBM Hard Drive Active Protection System (hdaps)"
580 depends on HWMON && INPUT && X86 604 depends on INPUT && X86
581 default n 605 default n
582 help 606 help
583 This driver provides support for the IBM Hard Drive Active Protection 607 This driver provides support for the IBM Hard Drive Active Protection
@@ -594,9 +618,32 @@ config SENSORS_HDAPS
594 Say Y here if you have an applicable laptop and want to experience 618 Say Y here if you have an applicable laptop and want to experience
595 the awesome power of hdaps. 619 the awesome power of hdaps.
596 620
621config SENSORS_APPLESMC
622 tristate "Apple SMC (Motion sensor, light sensor, keyboard backlight)"
623 depends on HWMON && INPUT && X86
624 select NEW_LEDS
625 select LEDS_CLASS
626 default n
627 help
628 This driver provides support for the Apple System Management
629 Controller, which provides an accelerometer (Apple Sudden Motion
630 Sensor), light sensors, temperature sensors, keyboard backlight
631 control and fan control.
632
633 Only Intel-based Apple's computers are supported (MacBook Pro,
634 MacBook, MacMini).
635
636 Data from the different sensors, keyboard backlight control and fan
637 control are accessible via sysfs.
638
639 This driver also provides an absolute input class device, allowing
640 the laptop to act as a pinball machine-esque joystick.
641
642 Say Y here if you have an applicable laptop and want to experience
643 the awesome power of applesmc.
644
597config HWMON_DEBUG_CHIP 645config HWMON_DEBUG_CHIP
598 bool "Hardware Monitoring Chip debugging messages" 646 bool "Hardware Monitoring Chip debugging messages"
599 depends on HWMON
600 default n 647 default n
601 help 648 help
602 Say Y here if you want the I2C chip drivers to produce a bunch of 649 Say Y here if you want the I2C chip drivers to produce a bunch of
@@ -604,4 +651,4 @@ config HWMON_DEBUG_CHIP
604 a problem with I2C support and want to see more of what is going 651 a problem with I2C support and want to see more of what is going
605 on. 652 on.
606 653
607endmenu 654endif # HWMON
diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
index 4165c27a2f25..cfaf338919dd 100644
--- a/drivers/hwmon/Makefile
+++ b/drivers/hwmon/Makefile
@@ -14,14 +14,17 @@ obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
14obj-$(CONFIG_SENSORS_W83791D) += w83791d.o 14obj-$(CONFIG_SENSORS_W83791D) += w83791d.o
15 15
16obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o 16obj-$(CONFIG_SENSORS_ABITUGURU) += abituguru.o
17obj-$(CONFIG_SENSORS_AD7418) += ad7418.o
17obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o 18obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
18obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o 19obj-$(CONFIG_SENSORS_ADM1025) += adm1025.o
19obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o 20obj-$(CONFIG_SENSORS_ADM1026) += adm1026.o
20obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o 21obj-$(CONFIG_SENSORS_ADM1029) += adm1029.o
21obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o 22obj-$(CONFIG_SENSORS_ADM1031) += adm1031.o
22obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o 23obj-$(CONFIG_SENSORS_ADM9240) += adm9240.o
24obj-$(CONFIG_SENSORS_APPLESMC) += applesmc.o
23obj-$(CONFIG_SENSORS_AMS) += ams/ 25obj-$(CONFIG_SENSORS_AMS) += ams/
24obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o 26obj-$(CONFIG_SENSORS_ATXP1) += atxp1.o
27obj-$(CONFIG_SENSORS_CORETEMP) += coretemp.o
25obj-$(CONFIG_SENSORS_DS1621) += ds1621.o 28obj-$(CONFIG_SENSORS_DS1621) += ds1621.o
26obj-$(CONFIG_SENSORS_F71805F) += f71805f.o 29obj-$(CONFIG_SENSORS_F71805F) += f71805f.o
27obj-$(CONFIG_SENSORS_FSCHER) += fscher.o 30obj-$(CONFIG_SENSORS_FSCHER) += fscher.o
@@ -43,6 +46,7 @@ obj-$(CONFIG_SENSORS_LM87) += lm87.o
43obj-$(CONFIG_SENSORS_LM90) += lm90.o 46obj-$(CONFIG_SENSORS_LM90) += lm90.o
44obj-$(CONFIG_SENSORS_LM92) += lm92.o 47obj-$(CONFIG_SENSORS_LM92) += lm92.o
45obj-$(CONFIG_SENSORS_MAX1619) += max1619.o 48obj-$(CONFIG_SENSORS_MAX1619) += max1619.o
49obj-$(CONFIG_SENSORS_MAX6650) += max6650.o
46obj-$(CONFIG_SENSORS_PC87360) += pc87360.o 50obj-$(CONFIG_SENSORS_PC87360) += pc87360.o
47obj-$(CONFIG_SENSORS_PC87427) += pc87427.o 51obj-$(CONFIG_SENSORS_PC87427) += pc87427.o
48obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o 52obj-$(CONFIG_SENSORS_SIS5595) += sis5595.o
diff --git a/drivers/hwmon/ad7418.c b/drivers/hwmon/ad7418.c
new file mode 100644
index 000000000000..cc8b624a1e51
--- /dev/null
+++ b/drivers/hwmon/ad7418.c
@@ -0,0 +1,373 @@
1/*
2 * An hwmon driver for the Analog Devices AD7416/17/18
3 * Copyright (C) 2006-07 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * Based on lm75.c
8 * Copyright (C) 1998-99 Frodo Looijaard <frodol@dds.nl>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License,
12 * as published by the Free Software Foundation - version 2.
13 */
14
15#include <linux/module.h>
16#include <linux/jiffies.h>
17#include <linux/i2c.h>
18#include <linux/hwmon.h>
19#include <linux/hwmon-sysfs.h>
20#include <linux/err.h>
21#include <linux/mutex.h>
22#include <linux/delay.h>
23
24#include "lm75.h"
25
26#define DRV_VERSION "0.3"
27
28/* Addresses to scan */
29static unsigned short normal_i2c[] = { 0x28, I2C_CLIENT_END };
30/* Insmod parameters */
31I2C_CLIENT_INSMOD_3(ad7416, ad7417, ad7418);
32
33/* AD7418 registers */
34#define AD7418_REG_TEMP_IN 0x00
35#define AD7418_REG_CONF 0x01
36#define AD7418_REG_TEMP_HYST 0x02
37#define AD7418_REG_TEMP_OS 0x03
38#define AD7418_REG_ADC 0x04
39#define AD7418_REG_CONF2 0x05
40
41#define AD7418_REG_ADC_CH(x) ((x) << 5)
42#define AD7418_CH_TEMP AD7418_REG_ADC_CH(0)
43
44static const u8 AD7418_REG_TEMP[] = { AD7418_REG_TEMP_IN,
45 AD7418_REG_TEMP_HYST,
46 AD7418_REG_TEMP_OS };
47
48struct ad7418_data {
49 struct i2c_client client;
50 struct class_device *class_dev;
51 struct attribute_group attrs;
52 enum chips type;
53 struct mutex lock;
54 int adc_max; /* number of ADC channels */
55 char valid;
56 unsigned long last_updated; /* In jiffies */
57 s16 temp[3]; /* Register values */
58 u16 in[4];
59};
60
61static int ad7418_attach_adapter(struct i2c_adapter *adapter);
62static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind);
63static int ad7418_detach_client(struct i2c_client *client);
64
65static struct i2c_driver ad7418_driver = {
66 .driver = {
67 .name = "ad7418",
68 },
69 .attach_adapter = ad7418_attach_adapter,
70 .detach_client = ad7418_detach_client,
71};
72
73/* All registers are word-sized, except for the configuration registers.
74 * AD7418 uses a high-byte first convention. Do NOT use those functions to
75 * access the configuration registers CONF and CONF2, as they are byte-sized.
76 */
77static inline int ad7418_read(struct i2c_client *client, u8 reg)
78{
79 return swab16(i2c_smbus_read_word_data(client, reg));
80}
81
82static inline int ad7418_write(struct i2c_client *client, u8 reg, u16 value)
83{
84 return i2c_smbus_write_word_data(client, reg, swab16(value));
85}
86
87static void ad7418_init_client(struct i2c_client *client)
88{
89 struct ad7418_data *data = i2c_get_clientdata(client);
90
91 int reg = i2c_smbus_read_byte_data(client, AD7418_REG_CONF);
92 if (reg < 0) {
93 dev_err(&client->dev, "cannot read configuration register\n");
94 } else {
95 dev_info(&client->dev, "configuring for mode 1\n");
96 i2c_smbus_write_byte_data(client, AD7418_REG_CONF, reg & 0xfe);
97
98 if (data->type == ad7417 || data->type == ad7418)
99 i2c_smbus_write_byte_data(client,
100 AD7418_REG_CONF2, 0x00);
101 }
102}
103
104static struct ad7418_data *ad7418_update_device(struct device *dev)
105{
106 struct i2c_client *client = to_i2c_client(dev);
107 struct ad7418_data *data = i2c_get_clientdata(client);
108
109 mutex_lock(&data->lock);
110
111 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
112 || !data->valid) {
113 u8 cfg;
114 int i, ch;
115
116 /* read config register and clear channel bits */
117 cfg = i2c_smbus_read_byte_data(client, AD7418_REG_CONF);
118 cfg &= 0x1F;
119
120 i2c_smbus_write_byte_data(client, AD7418_REG_CONF,
121 cfg | AD7418_CH_TEMP);
122 udelay(30);
123
124 for (i = 0; i < 3; i++) {
125 data->temp[i] = ad7418_read(client, AD7418_REG_TEMP[i]);
126 }
127
128 for (i = 0, ch = 4; i < data->adc_max; i++, ch--) {
129 i2c_smbus_write_byte_data(client,
130 AD7418_REG_CONF,
131 cfg | AD7418_REG_ADC_CH(ch));
132
133 udelay(15);
134 data->in[data->adc_max - 1 - i] =
135 ad7418_read(client, AD7418_REG_ADC);
136 }
137
138 /* restore old configuration value */
139 ad7418_write(client, AD7418_REG_CONF, cfg);
140
141 data->last_updated = jiffies;
142 data->valid = 1;
143 }
144
145 mutex_unlock(&data->lock);
146
147 return data;
148}
149
150static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
151 char *buf)
152{
153 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
154 struct ad7418_data *data = ad7418_update_device(dev);
155 return sprintf(buf, "%d\n",
156 LM75_TEMP_FROM_REG(data->temp[attr->index]));
157}
158
159static ssize_t show_adc(struct device *dev, struct device_attribute *devattr,
160 char *buf)
161{
162 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
163 struct ad7418_data *data = ad7418_update_device(dev);
164
165 return sprintf(buf, "%d\n",
166 ((data->in[attr->index] >> 6) * 2500 + 512) / 1024);
167}
168
169static ssize_t set_temp(struct device *dev, struct device_attribute *devattr,
170 const char *buf, size_t count)
171{
172 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
173 struct i2c_client *client = to_i2c_client(dev);
174 struct ad7418_data *data = i2c_get_clientdata(client);
175 int temp = simple_strtol(buf, NULL, 10);
176
177 mutex_lock(&data->lock);
178 data->temp[attr->index] = LM75_TEMP_TO_REG(temp);
179 ad7418_write(client, AD7418_REG_TEMP[attr->index], data->temp[attr->index]);
180 mutex_unlock(&data->lock);
181 return count;
182}
183
184static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
185static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
186 show_temp, set_temp, 1);
187static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
188 show_temp, set_temp, 2);
189
190static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_adc, NULL, 0);
191static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_adc, NULL, 1);
192static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_adc, NULL, 2);
193static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_adc, NULL, 3);
194
195static int ad7418_attach_adapter(struct i2c_adapter *adapter)
196{
197 if (!(adapter->class & I2C_CLASS_HWMON))
198 return 0;
199 return i2c_probe(adapter, &addr_data, ad7418_detect);
200}
201
202static struct attribute *ad7416_attributes[] = {
203 &sensor_dev_attr_temp1_max.dev_attr.attr,
204 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
205 &sensor_dev_attr_temp1_input.dev_attr.attr,
206 NULL
207};
208
209static struct attribute *ad7417_attributes[] = {
210 &sensor_dev_attr_temp1_max.dev_attr.attr,
211 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
212 &sensor_dev_attr_temp1_input.dev_attr.attr,
213 &sensor_dev_attr_in1_input.dev_attr.attr,
214 &sensor_dev_attr_in2_input.dev_attr.attr,
215 &sensor_dev_attr_in3_input.dev_attr.attr,
216 &sensor_dev_attr_in4_input.dev_attr.attr,
217 NULL
218};
219
220static struct attribute *ad7418_attributes[] = {
221 &sensor_dev_attr_temp1_max.dev_attr.attr,
222 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
223 &sensor_dev_attr_temp1_input.dev_attr.attr,
224 &sensor_dev_attr_in1_input.dev_attr.attr,
225 NULL
226};
227
228static int ad7418_detect(struct i2c_adapter *adapter, int address, int kind)
229{
230 struct i2c_client *client;
231 struct ad7418_data *data;
232 int err = 0;
233
234 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA |
235 I2C_FUNC_SMBUS_WORD_DATA))
236 goto exit;
237
238 if (!(data = kzalloc(sizeof(struct ad7418_data), GFP_KERNEL))) {
239 err = -ENOMEM;
240 goto exit;
241 }
242
243 client = &data->client;
244 client->addr = address;
245 client->adapter = adapter;
246 client->driver = &ad7418_driver;
247
248 i2c_set_clientdata(client, data);
249
250 mutex_init(&data->lock);
251
252 /* AD7418 has a curious behaviour on registers 6 and 7. They
253 * both always read 0xC071 and are not documented on the datasheet.
254 * We use them to detect the chip.
255 */
256 if (kind <= 0) {
257 int reg, reg6, reg7;
258
259 /* the AD7416 lies within this address range, but I have
260 * no means to check.
261 */
262 if (address >= 0x48 && address <= 0x4f) {
263 /* XXX add tests for AD7416 here */
264 /* data->type = ad7416; */
265 }
266 /* here we might have AD7417 or AD7418 */
267 else if (address >= 0x28 && address <= 0x2f) {
268 reg6 = i2c_smbus_read_word_data(client, 0x06);
269 reg7 = i2c_smbus_read_word_data(client, 0x07);
270
271 if (address == 0x28 && reg6 == 0xC071 && reg7 == 0xC071)
272 data->type = ad7418;
273
274 /* XXX add tests for AD7417 here */
275
276
277 /* both AD7417 and AD7418 have bits 0-5 of
278 * the CONF2 register at 0
279 */
280 reg = i2c_smbus_read_byte_data(client,
281 AD7418_REG_CONF2);
282 if (reg & 0x3F)
283 data->type = any_chip; /* detection failed */
284 }
285 } else {
286 dev_dbg(&adapter->dev, "detection forced\n");
287 }
288
289 if (kind > 0)
290 data->type = kind;
291 else if (kind < 0 && data->type == any_chip) {
292 err = -ENODEV;
293 goto exit_free;
294 }
295
296 switch (data->type) {
297 case any_chip:
298 case ad7416:
299 data->adc_max = 0;
300 data->attrs.attrs = ad7416_attributes;
301 strlcpy(client->name, "ad7416", I2C_NAME_SIZE);
302 break;
303
304 case ad7417:
305 data->adc_max = 4;
306 data->attrs.attrs = ad7417_attributes;
307 strlcpy(client->name, "ad7417", I2C_NAME_SIZE);
308 break;
309
310 case ad7418:
311 data->adc_max = 1;
312 data->attrs.attrs = ad7418_attributes;
313 strlcpy(client->name, "ad7418", I2C_NAME_SIZE);
314 break;
315 }
316
317 if ((err = i2c_attach_client(client)))
318 goto exit_free;
319
320 dev_info(&client->dev, "%s chip found\n", client->name);
321
322 /* Initialize the AD7418 chip */
323 ad7418_init_client(client);
324
325 /* Register sysfs hooks */
326 if ((err = sysfs_create_group(&client->dev.kobj, &data->attrs)))
327 goto exit_detach;
328
329 data->class_dev = hwmon_device_register(&client->dev);
330 if (IS_ERR(data->class_dev)) {
331 err = PTR_ERR(data->class_dev);
332 goto exit_remove;
333 }
334
335 return 0;
336
337exit_remove:
338 sysfs_remove_group(&client->dev.kobj, &data->attrs);
339exit_detach:
340 i2c_detach_client(client);
341exit_free:
342 kfree(data);
343exit:
344 return err;
345}
346
347static int ad7418_detach_client(struct i2c_client *client)
348{
349 struct ad7418_data *data = i2c_get_clientdata(client);
350 hwmon_device_unregister(data->class_dev);
351 sysfs_remove_group(&client->dev.kobj, &data->attrs);
352 i2c_detach_client(client);
353 kfree(data);
354 return 0;
355}
356
357static int __init ad7418_init(void)
358{
359 return i2c_add_driver(&ad7418_driver);
360}
361
362static void __exit ad7418_exit(void)
363{
364 i2c_del_driver(&ad7418_driver);
365}
366
367MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
368MODULE_DESCRIPTION("AD7416/17/18 driver");
369MODULE_LICENSE("GPL");
370MODULE_VERSION(DRV_VERSION);
371
372module_init(ad7418_init);
373module_exit(ad7418_exit);
diff --git a/drivers/hwmon/ams/ams-core.c b/drivers/hwmon/ams/ams-core.c
index f5ebad561412..6db973739725 100644
--- a/drivers/hwmon/ams/ams-core.c
+++ b/drivers/hwmon/ams/ams-core.c
@@ -144,7 +144,7 @@ int ams_sensor_attach(void)
144 const u32 *prop; 144 const u32 *prop;
145 145
146 /* Get orientation */ 146 /* Get orientation */
147 prop = get_property(ams_info.of_node, "orientation", NULL); 147 prop = of_get_property(ams_info.of_node, "orientation", NULL);
148 if (!prop) 148 if (!prop)
149 return -ENODEV; 149 return -ENODEV;
150 ams_info.orient1 = *prop; 150 ams_info.orient1 = *prop;
@@ -208,20 +208,17 @@ int __init ams_init(void)
208 208
209#ifdef CONFIG_SENSORS_AMS_I2C 209#ifdef CONFIG_SENSORS_AMS_I2C
210 np = of_find_node_by_name(NULL, "accelerometer"); 210 np = of_find_node_by_name(NULL, "accelerometer");
211 if (np && device_is_compatible(np, "AAPL,accelerometer_1")) 211 if (np && of_device_is_compatible(np, "AAPL,accelerometer_1"))
212 /* Found I2C motion sensor */ 212 /* Found I2C motion sensor */
213 return ams_i2c_init(np); 213 return ams_i2c_init(np);
214#endif 214#endif
215 215
216#ifdef CONFIG_SENSORS_AMS_PMU 216#ifdef CONFIG_SENSORS_AMS_PMU
217 np = of_find_node_by_name(NULL, "sms"); 217 np = of_find_node_by_name(NULL, "sms");
218 if (np && device_is_compatible(np, "sms")) 218 if (np && of_device_is_compatible(np, "sms"))
219 /* Found PMU motion sensor */ 219 /* Found PMU motion sensor */
220 return ams_pmu_init(np); 220 return ams_pmu_init(np);
221#endif 221#endif
222
223 printk(KERN_ERR "ams: No motion sensor found.\n");
224
225 return -ENODEV; 222 return -ENODEV;
226} 223}
227 224
diff --git a/drivers/hwmon/ams/ams-i2c.c b/drivers/hwmon/ams/ams-i2c.c
index 485d333bcb3e..957760536a4c 100644
--- a/drivers/hwmon/ams/ams-i2c.c
+++ b/drivers/hwmon/ams/ams-i2c.c
@@ -85,17 +85,17 @@ static int ams_i2c_write(u8 reg, u8 value)
85static int ams_i2c_cmd(enum ams_i2c_cmd cmd) 85static int ams_i2c_cmd(enum ams_i2c_cmd cmd)
86{ 86{
87 s32 result; 87 s32 result;
88 int remaining = HZ / 20; 88 int count = 3;
89 89
90 ams_i2c_write(AMS_COMMAND, cmd); 90 ams_i2c_write(AMS_COMMAND, cmd);
91 mdelay(5); 91 msleep(5);
92 92
93 while (remaining) { 93 while (count--) {
94 result = ams_i2c_read(AMS_COMMAND); 94 result = ams_i2c_read(AMS_COMMAND);
95 if (result == 0 || result & 0x80) 95 if (result == 0 || result & 0x80)
96 return 0; 96 return 0;
97 97
98 remaining = schedule_timeout(remaining); 98 schedule_timeout_uninterruptible(HZ / 20);
99 } 99 }
100 100
101 return -1; 101 return -1;
@@ -276,7 +276,7 @@ int __init ams_i2c_init(struct device_node *np)
276 ams_info.bustype = BUS_I2C; 276 ams_info.bustype = BUS_I2C;
277 277
278 /* look for bus either using "reg" or by path */ 278 /* look for bus either using "reg" or by path */
279 prop = get_property(ams_info.of_node, "reg", NULL); 279 prop = of_get_property(ams_info.of_node, "reg", NULL);
280 if (!prop) { 280 if (!prop) {
281 result = -ENODEV; 281 result = -ENODEV;
282 282
diff --git a/drivers/hwmon/ams/ams-input.c b/drivers/hwmon/ams/ams-input.c
index 18210164e307..ca7095d96ad0 100644
--- a/drivers/hwmon/ams/ams-input.c
+++ b/drivers/hwmon/ams/ams-input.c
@@ -87,7 +87,7 @@ static void ams_input_enable(void)
87 ams_info.idev->id.vendor = 0; 87 ams_info.idev->id.vendor = 0;
88 ams_info.idev->open = ams_input_open; 88 ams_info.idev->open = ams_input_open;
89 ams_info.idev->close = ams_input_close; 89 ams_info.idev->close = ams_input_close;
90 ams_info.idev->cdev.dev = &ams_info.of_dev->dev; 90 ams_info.idev->dev.parent = &ams_info.of_dev->dev;
91 91
92 input_set_abs_params(ams_info.idev, ABS_X, -50, 50, 3, 0); 92 input_set_abs_params(ams_info.idev, ABS_X, -50, 50, 3, 0);
93 input_set_abs_params(ams_info.idev, ABS_Y, -50, 50, 3, 0); 93 input_set_abs_params(ams_info.idev, ABS_Y, -50, 50, 3, 0);
diff --git a/drivers/hwmon/ams/ams-pmu.c b/drivers/hwmon/ams/ams-pmu.c
index 1b01c215bfe7..9463e9768f6f 100644
--- a/drivers/hwmon/ams/ams-pmu.c
+++ b/drivers/hwmon/ams/ams-pmu.c
@@ -160,7 +160,7 @@ int __init ams_pmu_init(struct device_node *np)
160 ams_info.bustype = BUS_HOST; 160 ams_info.bustype = BUS_HOST;
161 161
162 /* Get PMU command, should be 0x4e, but we can never know */ 162 /* Get PMU command, should be 0x4e, but we can never know */
163 prop = get_property(ams_info.of_node, "reg", NULL); 163 prop = of_get_property(ams_info.of_node, "reg", NULL);
164 if (!prop) { 164 if (!prop) {
165 result = -ENODEV; 165 result = -ENODEV;
166 goto exit; 166 goto exit;
diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
new file mode 100644
index 000000000000..0c160675b3ac
--- /dev/null
+++ b/drivers/hwmon/applesmc.c
@@ -0,0 +1,1340 @@
1/*
2 * drivers/hwmon/applesmc.c - driver for Apple's SMC (accelerometer, temperature
3 * sensors, fan control, keyboard backlight control) used in Intel-based Apple
4 * computers.
5 *
6 * Copyright (C) 2007 Nicolas Boichat <nicolas@boichat.ch>
7 *
8 * Based on hdaps.c driver:
9 * Copyright (C) 2005 Robert Love <rml@novell.com>
10 * Copyright (C) 2005 Jesper Juhl <jesper.juhl@gmail.com>
11 *
12 * Fan control based on smcFanControl:
13 * Copyright (C) 2006 Hendrik Holtmann <holtmann@mac.com>
14 *
15 * This program is free software; you can redistribute it and/or modify it
16 * under the terms of the GNU General Public License v2 as published by the
17 * Free Software Foundation.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT
20 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 * more details.
23 *
24 * You should have received a copy of the GNU General Public License along with
25 * this program; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
27 */
28
29#include <linux/delay.h>
30#include <linux/platform_device.h>
31#include <linux/input.h>
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/timer.h>
35#include <linux/dmi.h>
36#include <linux/mutex.h>
37#include <linux/hwmon-sysfs.h>
38#include <asm/io.h>
39#include <linux/leds.h>
40#include <linux/hwmon.h>
41#include <linux/workqueue.h>
42
43/* data port used by Apple SMC */
44#define APPLESMC_DATA_PORT 0x300
45/* command/status port used by Apple SMC */
46#define APPLESMC_CMD_PORT 0x304
47
48#define APPLESMC_NR_PORTS 32 /* 0x300-0x31f */
49
50#define APPLESMC_MAX_DATA_LENGTH 32
51
52#define APPLESMC_STATUS_MASK 0x0f
53#define APPLESMC_READ_CMD 0x10
54#define APPLESMC_WRITE_CMD 0x11
55#define APPLESMC_GET_KEY_BY_INDEX_CMD 0x12
56#define APPLESMC_GET_KEY_TYPE_CMD 0x13
57
58#define KEY_COUNT_KEY "#KEY" /* r-o ui32 */
59
60#define LIGHT_SENSOR_LEFT_KEY "ALV0" /* r-o {alv (6 bytes) */
61#define LIGHT_SENSOR_RIGHT_KEY "ALV1" /* r-o {alv (6 bytes) */
62#define BACKLIGHT_KEY "LKSB" /* w-o {lkb (2 bytes) */
63
64#define CLAMSHELL_KEY "MSLD" /* r-o ui8 (unused) */
65
66#define MOTION_SENSOR_X_KEY "MO_X" /* r-o sp78 (2 bytes) */
67#define MOTION_SENSOR_Y_KEY "MO_Y" /* r-o sp78 (2 bytes) */
68#define MOTION_SENSOR_Z_KEY "MO_Z" /* r-o sp78 (2 bytes) */
69#define MOTION_SENSOR_KEY "MOCN" /* r/w ui16 */
70
71#define FANS_COUNT "FNum" /* r-o ui8 */
72#define FANS_MANUAL "FS! " /* r-w ui16 */
73#define FAN_ACTUAL_SPEED "F0Ac" /* r-o fpe2 (2 bytes) */
74#define FAN_MIN_SPEED "F0Mn" /* r-o fpe2 (2 bytes) */
75#define FAN_MAX_SPEED "F0Mx" /* r-o fpe2 (2 bytes) */
76#define FAN_SAFE_SPEED "F0Sf" /* r-o fpe2 (2 bytes) */
77#define FAN_TARGET_SPEED "F0Tg" /* r-w fpe2 (2 bytes) */
78#define FAN_POSITION "F0ID" /* r-o char[16] */
79
80/*
81 * Temperature sensors keys (sp78 - 2 bytes).
82 * First set for Macbook(Pro), second for Macmini.
83 */
84static const char* temperature_sensors_sets[][13] = {
85 { "TA0P", "TB0T", "TC0D", "TC0P", "TG0H", "TG0P", "TG0T", "Th0H",
86 "Th1H", "Tm0P", "Ts0P", "Ts1P", NULL },
87 { "TC0D", "TC0P", NULL }
88};
89
90/* List of keys used to read/write fan speeds */
91static const char* fan_speed_keys[] = {
92 FAN_ACTUAL_SPEED,
93 FAN_MIN_SPEED,
94 FAN_MAX_SPEED,
95 FAN_SAFE_SPEED,
96 FAN_TARGET_SPEED
97};
98
99#define INIT_TIMEOUT_MSECS 5000 /* wait up to 5s for device init ... */
100#define INIT_WAIT_MSECS 50 /* ... in 50ms increments */
101
102#define APPLESMC_POLL_PERIOD (HZ/20) /* poll for input every 1/20s */
103#define APPLESMC_INPUT_FUZZ 4 /* input event threshold */
104#define APPLESMC_INPUT_FLAT 4
105
106#define SENSOR_X 0
107#define SENSOR_Y 1
108#define SENSOR_Z 2
109
110/* Structure to be passed to DMI_MATCH function */
111struct dmi_match_data {
112/* Indicates whether this computer has an accelerometer. */
113 int accelerometer;
114/* Indicates whether this computer has light sensors and keyboard backlight. */
115 int light;
116/* Indicates which temperature sensors set to use. */
117 int temperature_set;
118};
119
120static const int debug;
121static struct platform_device *pdev;
122static s16 rest_x;
123static s16 rest_y;
124static struct timer_list applesmc_timer;
125static struct input_dev *applesmc_idev;
126static struct class_device *hwmon_class_dev;
127
128/* Indicates whether this computer has an accelerometer. */
129static unsigned int applesmc_accelerometer;
130
131/* Indicates whether this computer has light sensors and keyboard backlight. */
132static unsigned int applesmc_light;
133
134/* Indicates which temperature sensors set to use. */
135static unsigned int applesmc_temperature_set;
136
137static struct mutex applesmc_lock;
138
139/*
140 * Last index written to key_at_index sysfs file, and value to use for all other
141 * key_at_index_* sysfs files.
142 */
143static unsigned int key_at_index;
144
145static struct workqueue_struct *applesmc_led_wq;
146
147/*
148 * __wait_status - Wait up to 2ms for the status port to get a certain value
149 * (masked with 0x0f), returning zero if the value is obtained. Callers must
150 * hold applesmc_lock.
151 */
152static int __wait_status(u8 val)
153{
154 unsigned int i;
155
156 val = val & APPLESMC_STATUS_MASK;
157
158 for (i = 0; i < 200; i++) {
159 if ((inb(APPLESMC_CMD_PORT) & APPLESMC_STATUS_MASK) == val) {
160 if (debug)
161 printk(KERN_DEBUG
162 "Waited %d us for status %x\n",
163 i*10, val);
164 return 0;
165 }
166 udelay(10);
167 }
168
169 printk(KERN_WARNING "applesmc: wait status failed: %x != %x\n",
170 val, inb(APPLESMC_CMD_PORT));
171
172 return -EIO;
173}
174
175/*
176 * applesmc_read_key - reads len bytes from a given key, and put them in buffer.
177 * Returns zero on success or a negative error on failure. Callers must
178 * hold applesmc_lock.
179 */
180static int applesmc_read_key(const char* key, u8* buffer, u8 len)
181{
182 int i;
183
184 if (len > APPLESMC_MAX_DATA_LENGTH) {
185 printk(KERN_ERR "applesmc_read_key: cannot read more than "
186 "%d bytes\n", APPLESMC_MAX_DATA_LENGTH);
187 return -EINVAL;
188 }
189
190 outb(APPLESMC_READ_CMD, APPLESMC_CMD_PORT);
191 if (__wait_status(0x0c))
192 return -EIO;
193
194 for (i = 0; i < 4; i++) {
195 outb(key[i], APPLESMC_DATA_PORT);
196 if (__wait_status(0x04))
197 return -EIO;
198 }
199 if (debug)
200 printk(KERN_DEBUG "<%s", key);
201
202 outb(len, APPLESMC_DATA_PORT);
203 if (debug)
204 printk(KERN_DEBUG ">%x", len);
205
206 for (i = 0; i < len; i++) {
207 if (__wait_status(0x05))
208 return -EIO;
209 buffer[i] = inb(APPLESMC_DATA_PORT);
210 if (debug)
211 printk(KERN_DEBUG "<%x", buffer[i]);
212 }
213 if (debug)
214 printk(KERN_DEBUG "\n");
215
216 return 0;
217}
218
219/*
220 * applesmc_write_key - writes len bytes from buffer to a given key.
221 * Returns zero on success or a negative error on failure. Callers must
222 * hold applesmc_lock.
223 */
224static int applesmc_write_key(const char* key, u8* buffer, u8 len)
225{
226 int i;
227
228 if (len > APPLESMC_MAX_DATA_LENGTH) {
229 printk(KERN_ERR "applesmc_write_key: cannot write more than "
230 "%d bytes\n", APPLESMC_MAX_DATA_LENGTH);
231 return -EINVAL;
232 }
233
234 outb(APPLESMC_WRITE_CMD, APPLESMC_CMD_PORT);
235 if (__wait_status(0x0c))
236 return -EIO;
237
238 for (i = 0; i < 4; i++) {
239 outb(key[i], APPLESMC_DATA_PORT);
240 if (__wait_status(0x04))
241 return -EIO;
242 }
243
244 outb(len, APPLESMC_DATA_PORT);
245
246 for (i = 0; i < len; i++) {
247 if (__wait_status(0x04))
248 return -EIO;
249 outb(buffer[i], APPLESMC_DATA_PORT);
250 }
251
252 return 0;
253}
254
255/*
256 * applesmc_get_key_at_index - get key at index, and put the result in key
257 * (char[6]). Returns zero on success or a negative error on failure. Callers
258 * must hold applesmc_lock.
259 */
260static int applesmc_get_key_at_index(int index, char* key)
261{
262 int i;
263 u8 readkey[4];
264 readkey[0] = index >> 24;
265 readkey[1] = index >> 16;
266 readkey[2] = index >> 8;
267 readkey[3] = index;
268
269 outb(APPLESMC_GET_KEY_BY_INDEX_CMD, APPLESMC_CMD_PORT);
270 if (__wait_status(0x0c))
271 return -EIO;
272
273 for (i = 0; i < 4; i++) {
274 outb(readkey[i], APPLESMC_DATA_PORT);
275 if (__wait_status(0x04))
276 return -EIO;
277 }
278
279 outb(4, APPLESMC_DATA_PORT);
280
281 for (i = 0; i < 4; i++) {
282 if (__wait_status(0x05))
283 return -EIO;
284 key[i] = inb(APPLESMC_DATA_PORT);
285 }
286 key[4] = 0;
287
288 return 0;
289}
290
291/*
292 * applesmc_get_key_type - get key type, and put the result in type (char[6]).
293 * Returns zero on success or a negative error on failure. Callers must
294 * hold applesmc_lock.
295 */
296static int applesmc_get_key_type(char* key, char* type)
297{
298 int i;
299
300 outb(APPLESMC_GET_KEY_TYPE_CMD, APPLESMC_CMD_PORT);
301 if (__wait_status(0x0c))
302 return -EIO;
303
304 for (i = 0; i < 4; i++) {
305 outb(key[i], APPLESMC_DATA_PORT);
306 if (__wait_status(0x04))
307 return -EIO;
308 }
309
310 outb(5, APPLESMC_DATA_PORT);
311
312 for (i = 0; i < 6; i++) {
313 if (__wait_status(0x05))
314 return -EIO;
315 type[i] = inb(APPLESMC_DATA_PORT);
316 }
317 type[5] = 0;
318
319 return 0;
320}
321
322/*
323 * applesmc_read_motion_sensor - Read motion sensor (X, Y or Z). Callers must
324 * hold applesmc_lock.
325 */
326static int applesmc_read_motion_sensor(int index, s16* value)
327{
328 u8 buffer[2];
329 int ret;
330
331 switch (index) {
332 case SENSOR_X:
333 ret = applesmc_read_key(MOTION_SENSOR_X_KEY, buffer, 2);
334 break;
335 case SENSOR_Y:
336 ret = applesmc_read_key(MOTION_SENSOR_Y_KEY, buffer, 2);
337 break;
338 case SENSOR_Z:
339 ret = applesmc_read_key(MOTION_SENSOR_Z_KEY, buffer, 2);
340 break;
341 default:
342 ret = -EINVAL;
343 }
344
345 *value = ((s16)buffer[0] << 8) | buffer[1];
346
347 return ret;
348}
349
350/*
351 * applesmc_device_init - initialize the accelerometer. Returns zero on success
352 * and negative error code on failure. Can sleep.
353 */
354static int applesmc_device_init(void)
355{
356 int total, ret = -ENXIO;
357 u8 buffer[2];
358
359 if (!applesmc_accelerometer)
360 return 0;
361
362 mutex_lock(&applesmc_lock);
363
364 for (total = INIT_TIMEOUT_MSECS; total > 0; total -= INIT_WAIT_MSECS) {
365 if (debug)
366 printk(KERN_DEBUG "applesmc try %d\n", total);
367 if (!applesmc_read_key(MOTION_SENSOR_KEY, buffer, 2) &&
368 (buffer[0] != 0x00 || buffer[1] != 0x00)) {
369 if (total == INIT_TIMEOUT_MSECS) {
370 printk(KERN_DEBUG "applesmc: device has"
371 " already been initialized"
372 " (0x%02x, 0x%02x).\n",
373 buffer[0], buffer[1]);
374 } else {
375 printk(KERN_DEBUG "applesmc: device"
376 " successfully initialized"
377 " (0x%02x, 0x%02x).\n",
378 buffer[0], buffer[1]);
379 }
380 ret = 0;
381 goto out;
382 }
383 buffer[0] = 0xe0;
384 buffer[1] = 0x00;
385 applesmc_write_key(MOTION_SENSOR_KEY, buffer, 2);
386 msleep(INIT_WAIT_MSECS);
387 }
388
389 printk(KERN_WARNING "applesmc: failed to init the device\n");
390
391out:
392 mutex_unlock(&applesmc_lock);
393 return ret;
394}
395
396/*
397 * applesmc_get_fan_count - get the number of fans. Callers must NOT hold
398 * applesmc_lock.
399 */
400static int applesmc_get_fan_count(void)
401{
402 int ret;
403 u8 buffer[1];
404
405 mutex_lock(&applesmc_lock);
406
407 ret = applesmc_read_key(FANS_COUNT, buffer, 1);
408
409 mutex_unlock(&applesmc_lock);
410 if (ret)
411 return ret;
412 else
413 return buffer[0];
414}
415
416/* Device model stuff */
417static int applesmc_probe(struct platform_device *dev)
418{
419 int ret;
420
421 ret = applesmc_device_init();
422 if (ret)
423 return ret;
424
425 printk(KERN_INFO "applesmc: device successfully initialized.\n");
426 return 0;
427}
428
429static int applesmc_resume(struct platform_device *dev)
430{
431 return applesmc_device_init();
432}
433
434static struct platform_driver applesmc_driver = {
435 .probe = applesmc_probe,
436 .resume = applesmc_resume,
437 .driver = {
438 .name = "applesmc",
439 .owner = THIS_MODULE,
440 },
441};
442
443/*
444 * applesmc_calibrate - Set our "resting" values. Callers must
445 * hold applesmc_lock.
446 */
447static void applesmc_calibrate(void)
448{
449 applesmc_read_motion_sensor(SENSOR_X, &rest_x);
450 applesmc_read_motion_sensor(SENSOR_Y, &rest_y);
451 rest_x = -rest_x;
452}
453
454static int applesmc_idev_open(struct input_dev *dev)
455{
456 add_timer(&applesmc_timer);
457
458 return 0;
459}
460
461static void applesmc_idev_close(struct input_dev *dev)
462{
463 del_timer_sync(&applesmc_timer);
464}
465
466static void applesmc_idev_poll(unsigned long unused)
467{
468 s16 x, y;
469
470 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */
471 if (!mutex_trylock(&applesmc_lock)) {
472 mod_timer(&applesmc_timer, jiffies + APPLESMC_POLL_PERIOD);
473 return;
474 }
475
476 if (applesmc_read_motion_sensor(SENSOR_X, &x))
477 goto out;
478 if (applesmc_read_motion_sensor(SENSOR_Y, &y))
479 goto out;
480
481 x = -x;
482 input_report_abs(applesmc_idev, ABS_X, x - rest_x);
483 input_report_abs(applesmc_idev, ABS_Y, y - rest_y);
484 input_sync(applesmc_idev);
485
486out:
487 mod_timer(&applesmc_timer, jiffies + APPLESMC_POLL_PERIOD);
488
489 mutex_unlock(&applesmc_lock);
490}
491
492/* Sysfs Files */
493
494static ssize_t applesmc_position_show(struct device *dev,
495 struct device_attribute *attr, char *buf)
496{
497 int ret;
498 s16 x, y, z;
499
500 mutex_lock(&applesmc_lock);
501
502 ret = applesmc_read_motion_sensor(SENSOR_X, &x);
503 if (ret)
504 goto out;
505 ret = applesmc_read_motion_sensor(SENSOR_Y, &y);
506 if (ret)
507 goto out;
508 ret = applesmc_read_motion_sensor(SENSOR_Z, &z);
509 if (ret)
510 goto out;
511
512out:
513 mutex_unlock(&applesmc_lock);
514 if (ret)
515 return ret;
516 else
517 return snprintf(buf, PAGE_SIZE, "(%d,%d,%d)\n", x, y, z);
518}
519
520static ssize_t applesmc_light_show(struct device *dev,
521 struct device_attribute *attr, char *sysfsbuf)
522{
523 int ret;
524 u8 left = 0, right = 0;
525 u8 buffer[6];
526
527 mutex_lock(&applesmc_lock);
528
529 ret = applesmc_read_key(LIGHT_SENSOR_LEFT_KEY, buffer, 6);
530 left = buffer[2];
531 if (ret)
532 goto out;
533 ret = applesmc_read_key(LIGHT_SENSOR_RIGHT_KEY, buffer, 6);
534 right = buffer[2];
535
536out:
537 mutex_unlock(&applesmc_lock);
538 if (ret)
539 return ret;
540 else
541 return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", left, right);
542}
543
544/* Displays degree Celsius * 1000 */
545static ssize_t applesmc_show_temperature(struct device *dev,
546 struct device_attribute *devattr, char *sysfsbuf)
547{
548 int ret;
549 u8 buffer[2];
550 unsigned int temp;
551 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
552 const char* key =
553 temperature_sensors_sets[applesmc_temperature_set][attr->index];
554
555 mutex_lock(&applesmc_lock);
556
557 ret = applesmc_read_key(key, buffer, 2);
558 temp = buffer[0]*1000;
559 temp += (buffer[1] >> 6) * 250;
560
561 mutex_unlock(&applesmc_lock);
562
563 if (ret)
564 return ret;
565 else
566 return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", temp);
567}
568
569static ssize_t applesmc_show_fan_speed(struct device *dev,
570 struct device_attribute *attr, char *sysfsbuf)
571{
572 int ret;
573 unsigned int speed = 0;
574 char newkey[5];
575 u8 buffer[2];
576 struct sensor_device_attribute_2 *sensor_attr =
577 to_sensor_dev_attr_2(attr);
578
579 newkey[0] = fan_speed_keys[sensor_attr->nr][0];
580 newkey[1] = '0' + sensor_attr->index;
581 newkey[2] = fan_speed_keys[sensor_attr->nr][2];
582 newkey[3] = fan_speed_keys[sensor_attr->nr][3];
583 newkey[4] = 0;
584
585 mutex_lock(&applesmc_lock);
586
587 ret = applesmc_read_key(newkey, buffer, 2);
588 speed = ((buffer[0] << 8 | buffer[1]) >> 2);
589
590 mutex_unlock(&applesmc_lock);
591 if (ret)
592 return ret;
593 else
594 return snprintf(sysfsbuf, PAGE_SIZE, "%u\n", speed);
595}
596
597static ssize_t applesmc_store_fan_speed(struct device *dev,
598 struct device_attribute *attr,
599 const char *sysfsbuf, size_t count)
600{
601 int ret;
602 u32 speed;
603 char newkey[5];
604 u8 buffer[2];
605 struct sensor_device_attribute_2 *sensor_attr =
606 to_sensor_dev_attr_2(attr);
607
608 speed = simple_strtoul(sysfsbuf, NULL, 10);
609
610 if (speed > 0x4000) /* Bigger than a 14-bit value */
611 return -EINVAL;
612
613 newkey[0] = fan_speed_keys[sensor_attr->nr][0];
614 newkey[1] = '0' + sensor_attr->index;
615 newkey[2] = fan_speed_keys[sensor_attr->nr][2];
616 newkey[3] = fan_speed_keys[sensor_attr->nr][3];
617 newkey[4] = 0;
618
619 mutex_lock(&applesmc_lock);
620
621 buffer[0] = (speed >> 6) & 0xff;
622 buffer[1] = (speed << 2) & 0xff;
623 ret = applesmc_write_key(newkey, buffer, 2);
624
625 mutex_unlock(&applesmc_lock);
626 if (ret)
627 return ret;
628 else
629 return count;
630}
631
632static ssize_t applesmc_show_fan_manual(struct device *dev,
633 struct device_attribute *devattr, char *sysfsbuf)
634{
635 int ret;
636 u16 manual = 0;
637 u8 buffer[2];
638 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
639
640 mutex_lock(&applesmc_lock);
641
642 ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
643 manual = ((buffer[0] << 8 | buffer[1]) >> attr->index) & 0x01;
644
645 mutex_unlock(&applesmc_lock);
646 if (ret)
647 return ret;
648 else
649 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", manual);
650}
651
652static ssize_t applesmc_store_fan_manual(struct device *dev,
653 struct device_attribute *devattr,
654 const char *sysfsbuf, size_t count)
655{
656 int ret;
657 u8 buffer[2];
658 u32 input;
659 u16 val;
660 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
661
662 input = simple_strtoul(sysfsbuf, NULL, 10);
663
664 mutex_lock(&applesmc_lock);
665
666 ret = applesmc_read_key(FANS_MANUAL, buffer, 2);
667 val = (buffer[0] << 8 | buffer[1]);
668 if (ret)
669 goto out;
670
671 if (input)
672 val = val | (0x01 << attr->index);
673 else
674 val = val & ~(0x01 << attr->index);
675
676 buffer[0] = (val >> 8) & 0xFF;
677 buffer[1] = val & 0xFF;
678
679 ret = applesmc_write_key(FANS_MANUAL, buffer, 2);
680
681out:
682 mutex_unlock(&applesmc_lock);
683 if (ret)
684 return ret;
685 else
686 return count;
687}
688
689static ssize_t applesmc_show_fan_position(struct device *dev,
690 struct device_attribute *attr, char *sysfsbuf)
691{
692 int ret;
693 char newkey[5];
694 u8 buffer[17];
695 struct sensor_device_attribute_2 *sensor_attr =
696 to_sensor_dev_attr_2(attr);
697
698 newkey[0] = FAN_POSITION[0];
699 newkey[1] = '0' + sensor_attr->index;
700 newkey[2] = FAN_POSITION[2];
701 newkey[3] = FAN_POSITION[3];
702 newkey[4] = 0;
703
704 mutex_lock(&applesmc_lock);
705
706 ret = applesmc_read_key(newkey, buffer, 16);
707 buffer[16] = 0;
708
709 mutex_unlock(&applesmc_lock);
710 if (ret)
711 return ret;
712 else
713 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", buffer+4);
714}
715
716static ssize_t applesmc_calibrate_show(struct device *dev,
717 struct device_attribute *attr, char *sysfsbuf)
718{
719 return snprintf(sysfsbuf, PAGE_SIZE, "(%d,%d)\n", rest_x, rest_y);
720}
721
722static ssize_t applesmc_calibrate_store(struct device *dev,
723 struct device_attribute *attr, const char *sysfsbuf, size_t count)
724{
725 mutex_lock(&applesmc_lock);
726 applesmc_calibrate();
727 mutex_unlock(&applesmc_lock);
728
729 return count;
730}
731
732/* Store the next backlight value to be written by the work */
733static unsigned int backlight_value;
734
735static void applesmc_backlight_set(struct work_struct *work)
736{
737 u8 buffer[2];
738
739 mutex_lock(&applesmc_lock);
740 buffer[0] = backlight_value;
741 buffer[1] = 0x00;
742 applesmc_write_key(BACKLIGHT_KEY, buffer, 2);
743 mutex_unlock(&applesmc_lock);
744}
745static DECLARE_WORK(backlight_work, &applesmc_backlight_set);
746
747static void applesmc_brightness_set(struct led_classdev *led_cdev,
748 enum led_brightness value)
749{
750 int ret;
751
752 backlight_value = value;
753 ret = queue_work(applesmc_led_wq, &backlight_work);
754
755 if (debug && (!ret))
756 printk(KERN_DEBUG "applesmc: work was already on the queue.\n");
757}
758
759static ssize_t applesmc_key_count_show(struct device *dev,
760 struct device_attribute *attr, char *sysfsbuf)
761{
762 int ret;
763 u8 buffer[4];
764 u32 count;
765
766 mutex_lock(&applesmc_lock);
767
768 ret = applesmc_read_key(KEY_COUNT_KEY, buffer, 4);
769 count = ((u32)buffer[0]<<24) + ((u32)buffer[1]<<16) +
770 ((u32)buffer[2]<<8) + buffer[3];
771
772 mutex_unlock(&applesmc_lock);
773 if (ret)
774 return ret;
775 else
776 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", count);
777}
778
779static ssize_t applesmc_key_at_index_read_show(struct device *dev,
780 struct device_attribute *attr, char *sysfsbuf)
781{
782 char key[5];
783 char info[6];
784 int ret;
785
786 mutex_lock(&applesmc_lock);
787
788 ret = applesmc_get_key_at_index(key_at_index, key);
789
790 if (ret || !key[0]) {
791 mutex_unlock(&applesmc_lock);
792
793 return -EINVAL;
794 }
795
796 ret = applesmc_get_key_type(key, info);
797
798 if (ret) {
799 mutex_unlock(&applesmc_lock);
800
801 return ret;
802 }
803
804 /*
805 * info[0] maximum value (APPLESMC_MAX_DATA_LENGTH) is much lower than
806 * PAGE_SIZE, so we don't need any checks before writing to sysfsbuf.
807 */
808 ret = applesmc_read_key(key, sysfsbuf, info[0]);
809
810 mutex_unlock(&applesmc_lock);
811
812 if (!ret) {
813 return info[0];
814 }
815 else {
816 return ret;
817 }
818}
819
820static ssize_t applesmc_key_at_index_data_length_show(struct device *dev,
821 struct device_attribute *attr, char *sysfsbuf)
822{
823 char key[5];
824 char info[6];
825 int ret;
826
827 mutex_lock(&applesmc_lock);
828
829 ret = applesmc_get_key_at_index(key_at_index, key);
830
831 if (ret || !key[0]) {
832 mutex_unlock(&applesmc_lock);
833
834 return -EINVAL;
835 }
836
837 ret = applesmc_get_key_type(key, info);
838
839 mutex_unlock(&applesmc_lock);
840
841 if (!ret)
842 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", info[0]);
843 else
844 return ret;
845}
846
847static ssize_t applesmc_key_at_index_type_show(struct device *dev,
848 struct device_attribute *attr, char *sysfsbuf)
849{
850 char key[5];
851 char info[6];
852 int ret;
853
854 mutex_lock(&applesmc_lock);
855
856 ret = applesmc_get_key_at_index(key_at_index, key);
857
858 if (ret || !key[0]) {
859 mutex_unlock(&applesmc_lock);
860
861 return -EINVAL;
862 }
863
864 ret = applesmc_get_key_type(key, info);
865
866 mutex_unlock(&applesmc_lock);
867
868 if (!ret)
869 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", info+1);
870 else
871 return ret;
872}
873
874static ssize_t applesmc_key_at_index_name_show(struct device *dev,
875 struct device_attribute *attr, char *sysfsbuf)
876{
877 char key[5];
878 int ret;
879
880 mutex_lock(&applesmc_lock);
881
882 ret = applesmc_get_key_at_index(key_at_index, key);
883
884 mutex_unlock(&applesmc_lock);
885
886 if (!ret && key[0])
887 return snprintf(sysfsbuf, PAGE_SIZE, "%s\n", key);
888 else
889 return -EINVAL;
890}
891
892static ssize_t applesmc_key_at_index_show(struct device *dev,
893 struct device_attribute *attr, char *sysfsbuf)
894{
895 return snprintf(sysfsbuf, PAGE_SIZE, "%d\n", key_at_index);
896}
897
898static ssize_t applesmc_key_at_index_store(struct device *dev,
899 struct device_attribute *attr, const char *sysfsbuf, size_t count)
900{
901 mutex_lock(&applesmc_lock);
902
903 key_at_index = simple_strtoul(sysfsbuf, NULL, 10);
904
905 mutex_unlock(&applesmc_lock);
906
907 return count;
908}
909
910static struct led_classdev applesmc_backlight = {
911 .name = "smc:kbd_backlight",
912 .default_trigger = "nand-disk",
913 .brightness_set = applesmc_brightness_set,
914};
915
916static DEVICE_ATTR(position, 0444, applesmc_position_show, NULL);
917static DEVICE_ATTR(calibrate, 0644,
918 applesmc_calibrate_show, applesmc_calibrate_store);
919
920static struct attribute *accelerometer_attributes[] = {
921 &dev_attr_position.attr,
922 &dev_attr_calibrate.attr,
923 NULL
924};
925
926static const struct attribute_group accelerometer_attributes_group =
927 { .attrs = accelerometer_attributes };
928
929static DEVICE_ATTR(light, 0444, applesmc_light_show, NULL);
930
931static DEVICE_ATTR(key_count, 0444, applesmc_key_count_show, NULL);
932static DEVICE_ATTR(key_at_index, 0644,
933 applesmc_key_at_index_show, applesmc_key_at_index_store);
934static DEVICE_ATTR(key_at_index_name, 0444,
935 applesmc_key_at_index_name_show, NULL);
936static DEVICE_ATTR(key_at_index_type, 0444,
937 applesmc_key_at_index_type_show, NULL);
938static DEVICE_ATTR(key_at_index_data_length, 0444,
939 applesmc_key_at_index_data_length_show, NULL);
940static DEVICE_ATTR(key_at_index_data, 0444,
941 applesmc_key_at_index_read_show, NULL);
942
943static struct attribute *key_enumeration_attributes[] = {
944 &dev_attr_key_count.attr,
945 &dev_attr_key_at_index.attr,
946 &dev_attr_key_at_index_name.attr,
947 &dev_attr_key_at_index_type.attr,
948 &dev_attr_key_at_index_data_length.attr,
949 &dev_attr_key_at_index_data.attr,
950 NULL
951};
952
953static const struct attribute_group key_enumeration_group =
954 { .attrs = key_enumeration_attributes };
955
956/*
957 * Macro defining SENSOR_DEVICE_ATTR for a fan sysfs entries.
958 * - show actual speed
959 * - show/store minimum speed
960 * - show maximum speed
961 * - show safe speed
962 * - show/store target speed
963 * - show/store manual mode
964 */
965#define sysfs_fan_speeds_offset(offset) \
966static SENSOR_DEVICE_ATTR_2(fan##offset##_input, S_IRUGO, \
967 applesmc_show_fan_speed, NULL, 0, offset-1); \
968\
969static SENSOR_DEVICE_ATTR_2(fan##offset##_min, S_IRUGO | S_IWUSR, \
970 applesmc_show_fan_speed, applesmc_store_fan_speed, 1, offset-1); \
971\
972static SENSOR_DEVICE_ATTR_2(fan##offset##_max, S_IRUGO, \
973 applesmc_show_fan_speed, NULL, 2, offset-1); \
974\
975static SENSOR_DEVICE_ATTR_2(fan##offset##_safe, S_IRUGO, \
976 applesmc_show_fan_speed, NULL, 3, offset-1); \
977\
978static SENSOR_DEVICE_ATTR_2(fan##offset##_output, S_IRUGO | S_IWUSR, \
979 applesmc_show_fan_speed, applesmc_store_fan_speed, 4, offset-1); \
980\
981static SENSOR_DEVICE_ATTR(fan##offset##_manual, S_IRUGO | S_IWUSR, \
982 applesmc_show_fan_manual, applesmc_store_fan_manual, offset-1); \
983\
984static SENSOR_DEVICE_ATTR(fan##offset##_label, S_IRUGO, \
985 applesmc_show_fan_position, NULL, offset-1); \
986\
987static struct attribute *fan##offset##_attributes[] = { \
988 &sensor_dev_attr_fan##offset##_input.dev_attr.attr, \
989 &sensor_dev_attr_fan##offset##_min.dev_attr.attr, \
990 &sensor_dev_attr_fan##offset##_max.dev_attr.attr, \
991 &sensor_dev_attr_fan##offset##_safe.dev_attr.attr, \
992 &sensor_dev_attr_fan##offset##_output.dev_attr.attr, \
993 &sensor_dev_attr_fan##offset##_manual.dev_attr.attr, \
994 &sensor_dev_attr_fan##offset##_label.dev_attr.attr, \
995 NULL \
996};
997
998/*
999 * Create the needed functions for each fan using the macro defined above
1000 * (2 fans are supported)
1001 */
1002sysfs_fan_speeds_offset(1);
1003sysfs_fan_speeds_offset(2);
1004
1005static const struct attribute_group fan_attribute_groups[] = {
1006 { .attrs = fan1_attributes },
1007 { .attrs = fan2_attributes }
1008};
1009
1010/*
1011 * Temperature sensors sysfs entries.
1012 */
1013static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO,
1014 applesmc_show_temperature, NULL, 0);
1015static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO,
1016 applesmc_show_temperature, NULL, 1);
1017static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO,
1018 applesmc_show_temperature, NULL, 2);
1019static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO,
1020 applesmc_show_temperature, NULL, 3);
1021static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO,
1022 applesmc_show_temperature, NULL, 4);
1023static SENSOR_DEVICE_ATTR(temp6_input, S_IRUGO,
1024 applesmc_show_temperature, NULL, 5);
1025static SENSOR_DEVICE_ATTR(temp7_input, S_IRUGO,
1026 applesmc_show_temperature, NULL, 6);
1027static SENSOR_DEVICE_ATTR(temp8_input, S_IRUGO,
1028 applesmc_show_temperature, NULL, 7);
1029static SENSOR_DEVICE_ATTR(temp9_input, S_IRUGO,
1030 applesmc_show_temperature, NULL, 8);
1031static SENSOR_DEVICE_ATTR(temp10_input, S_IRUGO,
1032 applesmc_show_temperature, NULL, 9);
1033static SENSOR_DEVICE_ATTR(temp11_input, S_IRUGO,
1034 applesmc_show_temperature, NULL, 10);
1035static SENSOR_DEVICE_ATTR(temp12_input, S_IRUGO,
1036 applesmc_show_temperature, NULL, 11);
1037
1038static struct attribute *temperature_attributes[] = {
1039 &sensor_dev_attr_temp1_input.dev_attr.attr,
1040 &sensor_dev_attr_temp2_input.dev_attr.attr,
1041 &sensor_dev_attr_temp3_input.dev_attr.attr,
1042 &sensor_dev_attr_temp4_input.dev_attr.attr,
1043 &sensor_dev_attr_temp5_input.dev_attr.attr,
1044 &sensor_dev_attr_temp6_input.dev_attr.attr,
1045 &sensor_dev_attr_temp7_input.dev_attr.attr,
1046 &sensor_dev_attr_temp8_input.dev_attr.attr,
1047 &sensor_dev_attr_temp9_input.dev_attr.attr,
1048 &sensor_dev_attr_temp10_input.dev_attr.attr,
1049 &sensor_dev_attr_temp11_input.dev_attr.attr,
1050 &sensor_dev_attr_temp12_input.dev_attr.attr,
1051 NULL
1052};
1053
1054static const struct attribute_group temperature_attributes_group =
1055 { .attrs = temperature_attributes };
1056
1057/* Module stuff */
1058
1059/*
1060 * applesmc_dmi_match - found a match. return one, short-circuiting the hunt.
1061 */
1062static int applesmc_dmi_match(struct dmi_system_id *id)
1063{
1064 int i = 0;
1065 struct dmi_match_data* dmi_data = id->driver_data;
1066 printk(KERN_INFO "applesmc: %s detected:\n", id->ident);
1067 applesmc_accelerometer = dmi_data->accelerometer;
1068 printk(KERN_INFO "applesmc: - Model %s accelerometer\n",
1069 applesmc_accelerometer ? "with" : "without");
1070 applesmc_light = dmi_data->light;
1071 printk(KERN_INFO "applesmc: - Model %s light sensors and backlight\n",
1072 applesmc_light ? "with" : "without");
1073
1074 applesmc_temperature_set = dmi_data->temperature_set;
1075 while (temperature_sensors_sets[applesmc_temperature_set][i] != NULL)
1076 i++;
1077 printk(KERN_INFO "applesmc: - Model with %d temperature sensors\n", i);
1078 return 1;
1079}
1080
1081/* Create accelerometer ressources */
1082static int applesmc_create_accelerometer(void)
1083{
1084 int ret;
1085
1086 ret = sysfs_create_group(&pdev->dev.kobj,
1087 &accelerometer_attributes_group);
1088 if (ret)
1089 goto out;
1090
1091 applesmc_idev = input_allocate_device();
1092 if (!applesmc_idev) {
1093 ret = -ENOMEM;
1094 goto out_sysfs;
1095 }
1096
1097 /* initial calibrate for the input device */
1098 applesmc_calibrate();
1099
1100 /* initialize the input class */
1101 applesmc_idev->name = "applesmc";
1102 applesmc_idev->id.bustype = BUS_HOST;
1103 applesmc_idev->dev.parent = &pdev->dev;
1104 applesmc_idev->evbit[0] = BIT(EV_ABS);
1105 applesmc_idev->open = applesmc_idev_open;
1106 applesmc_idev->close = applesmc_idev_close;
1107 input_set_abs_params(applesmc_idev, ABS_X,
1108 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT);
1109 input_set_abs_params(applesmc_idev, ABS_Y,
1110 -256, 256, APPLESMC_INPUT_FUZZ, APPLESMC_INPUT_FLAT);
1111
1112 ret = input_register_device(applesmc_idev);
1113 if (ret)
1114 goto out_idev;
1115
1116 /* start up our timer for the input device */
1117 init_timer(&applesmc_timer);
1118 applesmc_timer.function = applesmc_idev_poll;
1119 applesmc_timer.expires = jiffies + APPLESMC_POLL_PERIOD;
1120
1121 return 0;
1122
1123out_idev:
1124 input_free_device(applesmc_idev);
1125
1126out_sysfs:
1127 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group);
1128
1129out:
1130 printk(KERN_WARNING "applesmc: driver init failed (ret=%d)!\n", ret);
1131 return ret;
1132}
1133
1134/* Release all ressources used by the accelerometer */
1135static void applesmc_release_accelerometer(void)
1136{
1137 del_timer_sync(&applesmc_timer);
1138 input_unregister_device(applesmc_idev);
1139 sysfs_remove_group(&pdev->dev.kobj, &accelerometer_attributes_group);
1140}
1141
1142static __initdata struct dmi_match_data applesmc_dmi_data[] = {
1143/* MacBook Pro: accelerometer, backlight and temperature set 0 */
1144 { .accelerometer = 1, .light = 1, .temperature_set = 0 },
1145/* MacBook: accelerometer and temperature set 0 */
1146 { .accelerometer = 1, .light = 0, .temperature_set = 0 },
1147/* MacBook: temperature set 1 */
1148 { .accelerometer = 0, .light = 0, .temperature_set = 1 }
1149};
1150
1151/* Note that DMI_MATCH(...,"MacBook") will match "MacBookPro1,1".
1152 * So we need to put "Apple MacBook Pro" before "Apple MacBook". */
1153static __initdata struct dmi_system_id applesmc_whitelist[] = {
1154 { applesmc_dmi_match, "Apple MacBook Pro", {
1155 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
1156 DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro") },
1157 (void*)&applesmc_dmi_data[0]},
1158 { applesmc_dmi_match, "Apple MacBook", {
1159 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
1160 DMI_MATCH(DMI_PRODUCT_NAME,"MacBook") },
1161 (void*)&applesmc_dmi_data[1]},
1162 { applesmc_dmi_match, "Apple Macmini", {
1163 DMI_MATCH(DMI_BOARD_VENDOR,"Apple"),
1164 DMI_MATCH(DMI_PRODUCT_NAME,"Macmini") },
1165 (void*)&applesmc_dmi_data[2]},
1166 { .ident = NULL }
1167};
1168
1169static int __init applesmc_init(void)
1170{
1171 int ret;
1172 int count;
1173 int i;
1174
1175 mutex_init(&applesmc_lock);
1176
1177 if (!dmi_check_system(applesmc_whitelist)) {
1178 printk(KERN_WARNING "applesmc: supported laptop not found!\n");
1179 ret = -ENODEV;
1180 goto out;
1181 }
1182
1183 if (!request_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS,
1184 "applesmc")) {
1185 ret = -ENXIO;
1186 goto out;
1187 }
1188
1189 ret = platform_driver_register(&applesmc_driver);
1190 if (ret)
1191 goto out_region;
1192
1193 pdev = platform_device_register_simple("applesmc", APPLESMC_DATA_PORT,
1194 NULL, 0);
1195 if (IS_ERR(pdev)) {
1196 ret = PTR_ERR(pdev);
1197 goto out_driver;
1198 }
1199
1200 /* Create key enumeration sysfs files */
1201 ret = sysfs_create_group(&pdev->dev.kobj, &key_enumeration_group);
1202 if (ret)
1203 goto out_device;
1204
1205 /* create fan files */
1206 count = applesmc_get_fan_count();
1207 if (count < 0) {
1208 printk(KERN_ERR "applesmc: Cannot get the number of fans.\n");
1209 } else {
1210 printk(KERN_INFO "applesmc: %d fans found.\n", count);
1211
1212 switch (count) {
1213 default:
1214 printk(KERN_WARNING "applesmc: More than 2 fans found,"
1215 " but at most 2 fans are supported"
1216 " by the driver.\n");
1217 case 2:
1218 ret = sysfs_create_group(&pdev->dev.kobj,
1219 &fan_attribute_groups[1]);
1220 if (ret)
1221 goto out_key_enumeration;
1222 case 1:
1223 ret = sysfs_create_group(&pdev->dev.kobj,
1224 &fan_attribute_groups[0]);
1225 if (ret)
1226 goto out_fan_1;
1227 case 0:
1228 ;
1229 }
1230 }
1231
1232 for (i = 0;
1233 temperature_sensors_sets[applesmc_temperature_set][i] != NULL;
1234 i++) {
1235 if (temperature_attributes[i] == NULL) {
1236 printk(KERN_ERR "applesmc: More temperature sensors "
1237 "in temperature_sensors_sets (at least %i)"
1238 "than available sysfs files in "
1239 "temperature_attributes (%i), please report "
1240 "this bug.\n", i, i-1);
1241 goto out_temperature;
1242 }
1243 ret = sysfs_create_file(&pdev->dev.kobj,
1244 temperature_attributes[i]);
1245 if (ret)
1246 goto out_temperature;
1247 }
1248
1249 if (applesmc_accelerometer) {
1250 ret = applesmc_create_accelerometer();
1251 if (ret)
1252 goto out_temperature;
1253 }
1254
1255 if (applesmc_light) {
1256 /* Add light sensor file */
1257 ret = sysfs_create_file(&pdev->dev.kobj, &dev_attr_light.attr);
1258 if (ret)
1259 goto out_accelerometer;
1260
1261 /* Create the workqueue */
1262 applesmc_led_wq = create_singlethread_workqueue("applesmc-led");
1263 if (!applesmc_led_wq) {
1264 ret = -ENOMEM;
1265 goto out_light_sysfs;
1266 }
1267
1268 /* register as a led device */
1269 ret = led_classdev_register(&pdev->dev, &applesmc_backlight);
1270 if (ret < 0)
1271 goto out_light_wq;
1272 }
1273
1274 hwmon_class_dev = hwmon_device_register(&pdev->dev);
1275 if (IS_ERR(hwmon_class_dev)) {
1276 ret = PTR_ERR(hwmon_class_dev);
1277 goto out_light_ledclass;
1278 }
1279
1280 printk(KERN_INFO "applesmc: driver successfully loaded.\n");
1281
1282 return 0;
1283
1284out_light_ledclass:
1285 if (applesmc_light)
1286 led_classdev_unregister(&applesmc_backlight);
1287out_light_wq:
1288 if (applesmc_light)
1289 destroy_workqueue(applesmc_led_wq);
1290out_light_sysfs:
1291 if (applesmc_light)
1292 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr);
1293out_accelerometer:
1294 if (applesmc_accelerometer)
1295 applesmc_release_accelerometer();
1296out_temperature:
1297 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
1298 sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[0]);
1299out_fan_1:
1300 sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[1]);
1301out_key_enumeration:
1302 sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group);
1303out_device:
1304 platform_device_unregister(pdev);
1305out_driver:
1306 platform_driver_unregister(&applesmc_driver);
1307out_region:
1308 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS);
1309out:
1310 printk(KERN_WARNING "applesmc: driver init failed (ret=%d)!\n", ret);
1311 return ret;
1312}
1313
1314static void __exit applesmc_exit(void)
1315{
1316 hwmon_device_unregister(hwmon_class_dev);
1317 if (applesmc_light) {
1318 led_classdev_unregister(&applesmc_backlight);
1319 destroy_workqueue(applesmc_led_wq);
1320 sysfs_remove_file(&pdev->dev.kobj, &dev_attr_light.attr);
1321 }
1322 if (applesmc_accelerometer)
1323 applesmc_release_accelerometer();
1324 sysfs_remove_group(&pdev->dev.kobj, &temperature_attributes_group);
1325 sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[0]);
1326 sysfs_remove_group(&pdev->dev.kobj, &fan_attribute_groups[1]);
1327 sysfs_remove_group(&pdev->dev.kobj, &key_enumeration_group);
1328 platform_device_unregister(pdev);
1329 platform_driver_unregister(&applesmc_driver);
1330 release_region(APPLESMC_DATA_PORT, APPLESMC_NR_PORTS);
1331
1332 printk(KERN_INFO "applesmc: driver unloaded.\n");
1333}
1334
1335module_init(applesmc_init);
1336module_exit(applesmc_exit);
1337
1338MODULE_AUTHOR("Nicolas Boichat");
1339MODULE_DESCRIPTION("Apple SMC");
1340MODULE_LICENSE("GPL v2");
diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
new file mode 100644
index 000000000000..75e3911810a3
--- /dev/null
+++ b/drivers/hwmon/coretemp.c
@@ -0,0 +1,408 @@
1/*
2 * coretemp.c - Linux kernel module for hardware monitoring
3 *
4 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
5 *
6 * Inspired from many hwmon drivers
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; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 * 02110-1301 USA.
21 */
22
23#include <linux/module.h>
24#include <linux/delay.h>
25#include <linux/init.h>
26#include <linux/slab.h>
27#include <linux/jiffies.h>
28#include <linux/hwmon.h>
29#include <linux/sysfs.h>
30#include <linux/hwmon-sysfs.h>
31#include <linux/err.h>
32#include <linux/mutex.h>
33#include <linux/list.h>
34#include <linux/platform_device.h>
35#include <linux/cpu.h>
36#include <asm/msr.h>
37#include <asm/processor.h>
38
39#define DRVNAME "coretemp"
40
41typedef enum { SHOW_TEMP, SHOW_TJMAX, SHOW_LABEL, SHOW_NAME } SHOW;
42
43/*
44 * Functions declaration
45 */
46
47static struct coretemp_data *coretemp_update_device(struct device *dev);
48
49struct coretemp_data {
50 struct class_device *class_dev;
51 struct mutex update_lock;
52 const char *name;
53 u32 id;
54 char valid; /* zero until following fields are valid */
55 unsigned long last_updated; /* in jiffies */
56 int temp;
57 int tjmax;
58 u8 alarm;
59};
60
61static struct coretemp_data *coretemp_update_device(struct device *dev);
62
63/*
64 * Sysfs stuff
65 */
66
67static ssize_t show_name(struct device *dev, struct device_attribute
68 *devattr, char *buf)
69{
70 int ret;
71 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
72 struct coretemp_data *data = dev_get_drvdata(dev);
73
74 if (attr->index == SHOW_NAME)
75 ret = sprintf(buf, "%s\n", data->name);
76 else /* show label */
77 ret = sprintf(buf, "Core %d\n", data->id);
78 return ret;
79}
80
81static ssize_t show_alarm(struct device *dev, struct device_attribute
82 *devattr, char *buf)
83{
84 struct coretemp_data *data = coretemp_update_device(dev);
85 /* read the Out-of-spec log, never clear */
86 return sprintf(buf, "%d\n", data->alarm);
87}
88
89static ssize_t show_temp(struct device *dev,
90 struct device_attribute *devattr, char *buf)
91{
92 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
93 struct coretemp_data *data = coretemp_update_device(dev);
94 int err;
95
96 if (attr->index == SHOW_TEMP)
97 err = data->valid ? sprintf(buf, "%d\n", data->temp) : -EAGAIN;
98 else
99 err = sprintf(buf, "%d\n", data->tjmax);
100
101 return err;
102}
103
104static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL,
105 SHOW_TEMP);
106static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp, NULL,
107 SHOW_TJMAX);
108static DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL);
109static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_name, NULL, SHOW_LABEL);
110static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, SHOW_NAME);
111
112static struct attribute *coretemp_attributes[] = {
113 &sensor_dev_attr_name.dev_attr.attr,
114 &sensor_dev_attr_temp1_label.dev_attr.attr,
115 &dev_attr_temp1_crit_alarm.attr,
116 &sensor_dev_attr_temp1_input.dev_attr.attr,
117 &sensor_dev_attr_temp1_crit.dev_attr.attr,
118 NULL
119};
120
121static const struct attribute_group coretemp_group = {
122 .attrs = coretemp_attributes,
123};
124
125static struct coretemp_data *coretemp_update_device(struct device *dev)
126{
127 struct coretemp_data *data = dev_get_drvdata(dev);
128
129 mutex_lock(&data->update_lock);
130
131 if (!data->valid || time_after(jiffies, data->last_updated + HZ)) {
132 u32 eax, edx;
133
134 data->valid = 0;
135 rdmsr_on_cpu(data->id, MSR_IA32_THERM_STATUS, &eax, &edx);
136 data->alarm = (eax >> 5) & 1;
137 /* update only if data has been valid */
138 if (eax & 0x80000000) {
139 data->temp = data->tjmax - (((eax >> 16)
140 & 0x7f) * 1000);
141 data->valid = 1;
142 } else {
143 dev_dbg(dev, "Temperature data invalid (0x%x)\n", eax);
144 }
145 data->last_updated = jiffies;
146 }
147
148 mutex_unlock(&data->update_lock);
149 return data;
150}
151
152static int __devinit coretemp_probe(struct platform_device *pdev)
153{
154 struct coretemp_data *data;
155 struct cpuinfo_x86 *c = &(cpu_data)[pdev->id];
156 int err;
157 u32 eax, edx;
158
159 if (!(data = kzalloc(sizeof(struct coretemp_data), GFP_KERNEL))) {
160 err = -ENOMEM;
161 dev_err(&pdev->dev, "Out of memory\n");
162 goto exit;
163 }
164
165 data->id = pdev->id;
166 data->name = "coretemp";
167 mutex_init(&data->update_lock);
168 /* Tjmax default is 100 degrees C */
169 data->tjmax = 100000;
170
171 /* test if we can access the THERM_STATUS MSR */
172 err = rdmsr_safe_on_cpu(data->id, MSR_IA32_THERM_STATUS, &eax, &edx);
173 if (err) {
174 dev_err(&pdev->dev,
175 "Unable to access THERM_STATUS MSR, giving up\n");
176 goto exit_free;
177 }
178
179 /* Some processors have Tjmax 85 following magic should detect it
180 Intel won't disclose the information without signed NDA, but
181 individuals cannot sign it. Catch(ed) 22.
182 */
183
184 if (((c->x86_model == 0xf) && (c->x86_mask > 3)) ||
185 (c->x86_model == 0xe)) {
186 err = rdmsr_safe_on_cpu(data->id, 0xee, &eax, &edx);
187 if (err) {
188 dev_warn(&pdev->dev,
189 "Unable to access MSR 0xEE, Tjmax left at %d "
190 "degrees C\n", data->tjmax/1000);
191 } else if (eax & 0x40000000) {
192 data->tjmax = 85000;
193 }
194 }
195
196 platform_set_drvdata(pdev, data);
197
198 if ((err = sysfs_create_group(&pdev->dev.kobj, &coretemp_group)))
199 goto exit_free;
200
201 data->class_dev = hwmon_device_register(&pdev->dev);
202 if (IS_ERR(data->class_dev)) {
203 err = PTR_ERR(data->class_dev);
204 dev_err(&pdev->dev, "Class registration failed (%d)\n",
205 err);
206 goto exit_class;
207 }
208
209 return 0;
210
211exit_class:
212 sysfs_remove_group(&pdev->dev.kobj, &coretemp_group);
213exit_free:
214 kfree(data);
215exit:
216 return err;
217}
218
219static int __devexit coretemp_remove(struct platform_device *pdev)
220{
221 struct coretemp_data *data = platform_get_drvdata(pdev);
222
223 hwmon_device_unregister(data->class_dev);
224 sysfs_remove_group(&pdev->dev.kobj, &coretemp_group);
225 platform_set_drvdata(pdev, NULL);
226 kfree(data);
227 return 0;
228}
229
230static struct platform_driver coretemp_driver = {
231 .driver = {
232 .owner = THIS_MODULE,
233 .name = DRVNAME,
234 },
235 .probe = coretemp_probe,
236 .remove = __devexit_p(coretemp_remove),
237};
238
239struct pdev_entry {
240 struct list_head list;
241 struct platform_device *pdev;
242 unsigned int cpu;
243};
244
245static LIST_HEAD(pdev_list);
246static DEFINE_MUTEX(pdev_list_mutex);
247
248static int __cpuinit coretemp_device_add(unsigned int cpu)
249{
250 int err;
251 struct platform_device *pdev;
252 struct pdev_entry *pdev_entry;
253
254 pdev = platform_device_alloc(DRVNAME, cpu);
255 if (!pdev) {
256 err = -ENOMEM;
257 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
258 goto exit;
259 }
260
261 pdev_entry = kzalloc(sizeof(struct pdev_entry), GFP_KERNEL);
262 if (!pdev_entry) {
263 err = -ENOMEM;
264 goto exit_device_put;
265 }
266
267 err = platform_device_add(pdev);
268 if (err) {
269 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
270 err);
271 goto exit_device_free;
272 }
273
274 pdev_entry->pdev = pdev;
275 pdev_entry->cpu = cpu;
276 mutex_lock(&pdev_list_mutex);
277 list_add_tail(&pdev_entry->list, &pdev_list);
278 mutex_unlock(&pdev_list_mutex);
279
280 return 0;
281
282exit_device_free:
283 kfree(pdev_entry);
284exit_device_put:
285 platform_device_put(pdev);
286exit:
287 return err;
288}
289
290#ifdef CONFIG_HOTPLUG_CPU
291void coretemp_device_remove(unsigned int cpu)
292{
293 struct pdev_entry *p, *n;
294 mutex_lock(&pdev_list_mutex);
295 list_for_each_entry_safe(p, n, &pdev_list, list) {
296 if (p->cpu == cpu) {
297 platform_device_unregister(p->pdev);
298 list_del(&p->list);
299 kfree(p);
300 }
301 }
302 mutex_unlock(&pdev_list_mutex);
303}
304
305static int coretemp_cpu_callback(struct notifier_block *nfb,
306 unsigned long action, void *hcpu)
307{
308 unsigned int cpu = (unsigned long) hcpu;
309
310 switch (action) {
311 case CPU_ONLINE:
312 case CPU_ONLINE_FROZEN:
313 coretemp_device_add(cpu);
314 break;
315 case CPU_DEAD:
316 case CPU_DEAD_FROZEN:
317 coretemp_device_remove(cpu);
318 break;
319 }
320 return NOTIFY_OK;
321}
322
323static struct notifier_block __cpuinitdata coretemp_cpu_notifier = {
324 .notifier_call = coretemp_cpu_callback,
325};
326#endif /* !CONFIG_HOTPLUG_CPU */
327
328static int __init coretemp_init(void)
329{
330 int i, err = -ENODEV;
331 struct pdev_entry *p, *n;
332
333 printk(KERN_NOTICE DRVNAME ": This driver uses undocumented features "
334 "of Core CPU. Temperature might be wrong!\n");
335
336 /* quick check if we run Intel */
337 if (cpu_data[0].x86_vendor != X86_VENDOR_INTEL)
338 goto exit;
339
340 err = platform_driver_register(&coretemp_driver);
341 if (err)
342 goto exit;
343
344 for_each_online_cpu(i) {
345 struct cpuinfo_x86 *c = &(cpu_data)[i];
346
347 /* check if family 6, models e, f */
348 if ((c->cpuid_level < 0) || (c->x86 != 0x6) ||
349 !((c->x86_model == 0xe) || (c->x86_model == 0xf))) {
350
351 /* supported CPU not found, but report the unknown
352 family 6 CPU */
353 if ((c->x86 == 0x6) && (c->x86_model > 0xf))
354 printk(KERN_WARNING DRVNAME ": Unknown CPU "
355 "model %x\n", c->x86_model);
356 continue;
357 }
358
359 err = coretemp_device_add(i);
360 if (err)
361 goto exit_devices_unreg;
362 }
363 if (list_empty(&pdev_list)) {
364 err = -ENODEV;
365 goto exit_driver_unreg;
366 }
367
368#ifdef CONFIG_HOTPLUG_CPU
369 register_hotcpu_notifier(&coretemp_cpu_notifier);
370#endif
371 return 0;
372
373exit_devices_unreg:
374 mutex_lock(&pdev_list_mutex);
375 list_for_each_entry_safe(p, n, &pdev_list, list) {
376 platform_device_unregister(p->pdev);
377 list_del(&p->list);
378 kfree(p);
379 }
380 mutex_unlock(&pdev_list_mutex);
381exit_driver_unreg:
382 platform_driver_unregister(&coretemp_driver);
383exit:
384 return err;
385}
386
387static void __exit coretemp_exit(void)
388{
389 struct pdev_entry *p, *n;
390#ifdef CONFIG_HOTPLUG_CPU
391 unregister_hotcpu_notifier(&coretemp_cpu_notifier);
392#endif
393 mutex_lock(&pdev_list_mutex);
394 list_for_each_entry_safe(p, n, &pdev_list, list) {
395 platform_device_unregister(p->pdev);
396 list_del(&p->list);
397 kfree(p);
398 }
399 mutex_unlock(&pdev_list_mutex);
400 platform_driver_unregister(&coretemp_driver);
401}
402
403MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>");
404MODULE_DESCRIPTION("Intel Core temperature monitor");
405MODULE_LICENSE("GPL");
406
407module_init(coretemp_init)
408module_exit(coretemp_exit)
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index 7c2973487122..cdbe309b8fc4 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -35,6 +35,7 @@
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/sysfs.h> 37#include <linux/sysfs.h>
38#include <linux/ioport.h>
38#include <asm/io.h> 39#include <asm/io.h>
39 40
40static struct platform_device *pdev; 41static struct platform_device *pdev;
@@ -1140,6 +1141,13 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
1140 } 1141 }
1141 1142
1142 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 1143 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1144 if (!request_region(res->start + ADDR_REG_OFFSET, 2, DRVNAME)) {
1145 err = -EBUSY;
1146 dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n",
1147 (unsigned long)(res->start + ADDR_REG_OFFSET),
1148 (unsigned long)(res->start + ADDR_REG_OFFSET + 1));
1149 goto exit_free;
1150 }
1143 data->addr = res->start; 1151 data->addr = res->start;
1144 data->name = names[sio_data->kind]; 1152 data->name = names[sio_data->kind];
1145 mutex_init(&data->update_lock); 1153 mutex_init(&data->update_lock);
@@ -1165,7 +1173,7 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
1165 1173
1166 /* Register sysfs interface files */ 1174 /* Register sysfs interface files */
1167 if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group))) 1175 if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group)))
1168 goto exit_free; 1176 goto exit_release_region;
1169 if (data->has_in & (1 << 4)) { /* in4 */ 1177 if (data->has_in & (1 << 4)) { /* in4 */
1170 if ((err = sysfs_create_group(&pdev->dev.kobj, 1178 if ((err = sysfs_create_group(&pdev->dev.kobj,
1171 &f71805f_group_optin[0]))) 1179 &f71805f_group_optin[0])))
@@ -1219,6 +1227,8 @@ exit_remove_files:
1219 for (i = 0; i < 4; i++) 1227 for (i = 0; i < 4; i++)
1220 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]); 1228 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_optin[i]);
1221 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); 1229 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq);
1230exit_release_region:
1231 release_region(res->start + ADDR_REG_OFFSET, 2);
1222exit_free: 1232exit_free:
1223 platform_set_drvdata(pdev, NULL); 1233 platform_set_drvdata(pdev, NULL);
1224 kfree(data); 1234 kfree(data);
@@ -1229,6 +1239,7 @@ exit:
1229static int __devexit f71805f_remove(struct platform_device *pdev) 1239static int __devexit f71805f_remove(struct platform_device *pdev)
1230{ 1240{
1231 struct f71805f_data *data = platform_get_drvdata(pdev); 1241 struct f71805f_data *data = platform_get_drvdata(pdev);
1242 struct resource *res;
1232 int i; 1243 int i;
1233 1244
1234 platform_set_drvdata(pdev, NULL); 1245 platform_set_drvdata(pdev, NULL);
@@ -1239,6 +1250,9 @@ static int __devexit f71805f_remove(struct platform_device *pdev)
1239 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq); 1250 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq);
1240 kfree(data); 1251 kfree(data);
1241 1252
1253 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1254 release_region(res->start + ADDR_REG_OFFSET, 2);
1255
1242 return 0; 1256 return 0;
1243} 1257}
1244 1258
diff --git a/drivers/hwmon/hdaps.c b/drivers/hwmon/hdaps.c
index bf759ea545ac..e0cf5e6fe5bc 100644
--- a/drivers/hwmon/hdaps.c
+++ b/drivers/hwmon/hdaps.c
@@ -30,10 +30,12 @@
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/input.h> 31#include <linux/input.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/mutex.h>
33#include <linux/module.h> 34#include <linux/module.h>
34#include <linux/timer.h> 35#include <linux/timer.h>
35#include <linux/dmi.h> 36#include <linux/dmi.h>
36#include <linux/jiffies.h> 37#include <linux/jiffies.h>
38
37#include <asm/io.h> 39#include <asm/io.h>
38 40
39#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */ 41#define HDAPS_LOW_PORT 0x1600 /* first port used by hdaps */
@@ -71,10 +73,10 @@ static u8 km_activity;
71static int rest_x; 73static int rest_x;
72static int rest_y; 74static int rest_y;
73 75
74static DECLARE_MUTEX(hdaps_sem); 76static DEFINE_MUTEX(hdaps_mtx);
75 77
76/* 78/*
77 * __get_latch - Get the value from a given port. Callers must hold hdaps_sem. 79 * __get_latch - Get the value from a given port. Callers must hold hdaps_mtx.
78 */ 80 */
79static inline u8 __get_latch(u16 port) 81static inline u8 __get_latch(u16 port)
80{ 82{
@@ -83,7 +85,7 @@ static inline u8 __get_latch(u16 port)
83 85
84/* 86/*
85 * __check_latch - Check a port latch for a given value. Returns zero if the 87 * __check_latch - Check a port latch for a given value. Returns zero if the
86 * port contains the given value. Callers must hold hdaps_sem. 88 * port contains the given value. Callers must hold hdaps_mtx.
87 */ 89 */
88static inline int __check_latch(u16 port, u8 val) 90static inline int __check_latch(u16 port, u8 val)
89{ 91{
@@ -94,7 +96,7 @@ static inline int __check_latch(u16 port, u8 val)
94 96
95/* 97/*
96 * __wait_latch - Wait up to 100us for a port latch to get a certain value, 98 * __wait_latch - Wait up to 100us for a port latch to get a certain value,
97 * returning zero if the value is obtained. Callers must hold hdaps_sem. 99 * returning zero if the value is obtained. Callers must hold hdaps_mtx.
98 */ 100 */
99static int __wait_latch(u16 port, u8 val) 101static int __wait_latch(u16 port, u8 val)
100{ 102{
@@ -111,7 +113,7 @@ static int __wait_latch(u16 port, u8 val)
111 113
112/* 114/*
113 * __device_refresh - request a refresh from the accelerometer. Does not wait 115 * __device_refresh - request a refresh from the accelerometer. Does not wait
114 * for refresh to complete. Callers must hold hdaps_sem. 116 * for refresh to complete. Callers must hold hdaps_mtx.
115 */ 117 */
116static void __device_refresh(void) 118static void __device_refresh(void)
117{ 119{
@@ -125,7 +127,7 @@ static void __device_refresh(void)
125/* 127/*
126 * __device_refresh_sync - request a synchronous refresh from the 128 * __device_refresh_sync - request a synchronous refresh from the
127 * accelerometer. We wait for the refresh to complete. Returns zero if 129 * accelerometer. We wait for the refresh to complete. Returns zero if
128 * successful and nonzero on error. Callers must hold hdaps_sem. 130 * successful and nonzero on error. Callers must hold hdaps_mtx.
129 */ 131 */
130static int __device_refresh_sync(void) 132static int __device_refresh_sync(void)
131{ 133{
@@ -135,7 +137,7 @@ static int __device_refresh_sync(void)
135 137
136/* 138/*
137 * __device_complete - indicate to the accelerometer that we are done reading 139 * __device_complete - indicate to the accelerometer that we are done reading
138 * data, and then initiate an async refresh. Callers must hold hdaps_sem. 140 * data, and then initiate an async refresh. Callers must hold hdaps_mtx.
139 */ 141 */
140static inline void __device_complete(void) 142static inline void __device_complete(void)
141{ 143{
@@ -153,7 +155,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
153{ 155{
154 int ret; 156 int ret;
155 157
156 down(&hdaps_sem); 158 mutex_lock(&hdaps_mtx);
157 159
158 /* do a sync refresh -- we need to be sure that we read fresh data */ 160 /* do a sync refresh -- we need to be sure that we read fresh data */
159 ret = __device_refresh_sync(); 161 ret = __device_refresh_sync();
@@ -164,7 +166,7 @@ static int hdaps_readb_one(unsigned int port, u8 *val)
164 __device_complete(); 166 __device_complete();
165 167
166out: 168out:
167 up(&hdaps_sem); 169 mutex_unlock(&hdaps_mtx);
168 return ret; 170 return ret;
169} 171}
170 172
@@ -199,9 +201,9 @@ static int hdaps_read_pair(unsigned int port1, unsigned int port2,
199{ 201{
200 int ret; 202 int ret;
201 203
202 down(&hdaps_sem); 204 mutex_lock(&hdaps_mtx);
203 ret = __hdaps_read_pair(port1, port2, val1, val2); 205 ret = __hdaps_read_pair(port1, port2, val1, val2);
204 up(&hdaps_sem); 206 mutex_unlock(&hdaps_mtx);
205 207
206 return ret; 208 return ret;
207} 209}
@@ -214,7 +216,7 @@ static int hdaps_device_init(void)
214{ 216{
215 int total, ret = -ENXIO; 217 int total, ret = -ENXIO;
216 218
217 down(&hdaps_sem); 219 mutex_lock(&hdaps_mtx);
218 220
219 outb(0x13, 0x1610); 221 outb(0x13, 0x1610);
220 outb(0x01, 0x161f); 222 outb(0x01, 0x161f);
@@ -280,7 +282,7 @@ static int hdaps_device_init(void)
280 } 282 }
281 283
282out: 284out:
283 up(&hdaps_sem); 285 mutex_unlock(&hdaps_mtx);
284 return ret; 286 return ret;
285} 287}
286 288
@@ -314,7 +316,7 @@ static struct platform_driver hdaps_driver = {
314}; 316};
315 317
316/* 318/*
317 * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_sem. 319 * hdaps_calibrate - Set our "resting" values. Callers must hold hdaps_mtx.
318 */ 320 */
319static void hdaps_calibrate(void) 321static void hdaps_calibrate(void)
320{ 322{
@@ -326,7 +328,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
326 int x, y; 328 int x, y;
327 329
328 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */ 330 /* Cannot sleep. Try nonblockingly. If we fail, try again later. */
329 if (down_trylock(&hdaps_sem)) { 331 if (mutex_trylock(&hdaps_mtx)) {
330 mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD); 332 mod_timer(&hdaps_timer,jiffies + HDAPS_POLL_PERIOD);
331 return; 333 return;
332 } 334 }
@@ -341,7 +343,7 @@ static void hdaps_mousedev_poll(unsigned long unused)
341 mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD); 343 mod_timer(&hdaps_timer, jiffies + HDAPS_POLL_PERIOD);
342 344
343out: 345out:
344 up(&hdaps_sem); 346 mutex_unlock(&hdaps_mtx);
345} 347}
346 348
347 349
@@ -421,9 +423,9 @@ static ssize_t hdaps_calibrate_store(struct device *dev,
421 struct device_attribute *attr, 423 struct device_attribute *attr,
422 const char *buf, size_t count) 424 const char *buf, size_t count)
423{ 425{
424 down(&hdaps_sem); 426 mutex_lock(&hdaps_mtx);
425 hdaps_calibrate(); 427 hdaps_calibrate();
426 up(&hdaps_sem); 428 mutex_unlock(&hdaps_mtx);
427 429
428 return count; 430 return count;
429} 431}
@@ -572,7 +574,7 @@ static int __init hdaps_init(void)
572 574
573 /* initialize the input class */ 575 /* initialize the input class */
574 hdaps_idev->name = "hdaps"; 576 hdaps_idev->name = "hdaps";
575 hdaps_idev->cdev.dev = &pdev->dev; 577 hdaps_idev->dev.parent = &pdev->dev;
576 hdaps_idev->evbit[0] = BIT(EV_ABS); 578 hdaps_idev->evbit[0] = BIT(EV_ABS);
577 input_set_abs_params(hdaps_idev, ABS_X, 579 input_set_abs_params(hdaps_idev, ABS_X,
578 -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT); 580 -256, 256, HDAPS_INPUT_FUZZ, HDAPS_INPUT_FLAT);
diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
index b80f6ed5acfc..5aab23b93e24 100644
--- a/drivers/hwmon/hwmon-vid.c
+++ b/drivers/hwmon/hwmon-vid.c
@@ -166,16 +166,16 @@ static struct vrm_model vrm_models[] = {
166 {X86_VENDOR_INTEL, 0x6, 0xE, ANY, 14}, /* Intel Core (65 nm) */ 166 {X86_VENDOR_INTEL, 0x6, 0xE, ANY, 14}, /* Intel Core (65 nm) */
167 {X86_VENDOR_INTEL, 0x6, 0xF, ANY, 110}, /* Intel Conroe */ 167 {X86_VENDOR_INTEL, 0x6, 0xF, ANY, 110}, /* Intel Conroe */
168 {X86_VENDOR_INTEL, 0x6, ANY, ANY, 82}, /* any P6 */ 168 {X86_VENDOR_INTEL, 0x6, ANY, ANY, 82}, /* any P6 */
169 {X86_VENDOR_INTEL, 0x7, ANY, ANY, 0}, /* Itanium */
170 {X86_VENDOR_INTEL, 0xF, 0x0, ANY, 90}, /* P4 */ 169 {X86_VENDOR_INTEL, 0xF, 0x0, ANY, 90}, /* P4 */
171 {X86_VENDOR_INTEL, 0xF, 0x1, ANY, 90}, /* P4 Willamette */ 170 {X86_VENDOR_INTEL, 0xF, 0x1, ANY, 90}, /* P4 Willamette */
172 {X86_VENDOR_INTEL, 0xF, 0x2, ANY, 90}, /* P4 Northwood */ 171 {X86_VENDOR_INTEL, 0xF, 0x2, ANY, 90}, /* P4 Northwood */
173 {X86_VENDOR_INTEL, 0xF, ANY, ANY, 100}, /* Prescott and above assume VRD 10 */ 172 {X86_VENDOR_INTEL, 0xF, ANY, ANY, 100}, /* Prescott and above assume VRD 10 */
174 {X86_VENDOR_INTEL, 0x10, ANY, ANY, 0}, /* Itanium 2 */
175 {X86_VENDOR_CENTAUR, 0x6, 0x7, ANY, 85}, /* Eden ESP/Ezra */ 173 {X86_VENDOR_CENTAUR, 0x6, 0x7, ANY, 85}, /* Eden ESP/Ezra */
176 {X86_VENDOR_CENTAUR, 0x6, 0x8, 0x7, 85}, /* Ezra T */ 174 {X86_VENDOR_CENTAUR, 0x6, 0x8, 0x7, 85}, /* Ezra T */
177 {X86_VENDOR_CENTAUR, 0x6, 0x9, 0x7, 85}, /* Nemiah */ 175 {X86_VENDOR_CENTAUR, 0x6, 0x9, 0x7, 85}, /* Nemiah */
178 {X86_VENDOR_CENTAUR, 0x6, 0x9, ANY, 17}, /* C3-M */ 176 {X86_VENDOR_CENTAUR, 0x6, 0x9, ANY, 17}, /* C3-M, Eden-N */
177 {X86_VENDOR_CENTAUR, 0x6, 0xA, 0x7, 0}, /* No information */
178 {X86_VENDOR_CENTAUR, 0x6, 0xA, ANY, 13}, /* C7, Esther */
179 {X86_VENDOR_UNKNOWN, ANY, ANY, ANY, 0} /* stop here */ 179 {X86_VENDOR_UNKNOWN, ANY, ANY, ANY, 0} /* stop here */
180}; 180};
181 181
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 7c65b8bb6d72..a40166ffad12 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -24,6 +24,7 @@
24#include <linux/jiffies.h> 24#include <linux/jiffies.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26#include <linux/hwmon.h> 26#include <linux/hwmon.h>
27#include <linux/hwmon-sysfs.h>
27#include <linux/err.h> 28#include <linux/err.h>
28#include <linux/mutex.h> 29#include <linux/mutex.h>
29#include "lm75.h" 30#include "lm75.h"
@@ -39,10 +40,12 @@ I2C_CLIENT_INSMOD_1(lm75);
39/* Many LM75 constants specified below */ 40/* Many LM75 constants specified below */
40 41
41/* The LM75 registers */ 42/* The LM75 registers */
42#define LM75_REG_TEMP 0x00
43#define LM75_REG_CONF 0x01 43#define LM75_REG_CONF 0x01
44#define LM75_REG_TEMP_HYST 0x02 44static const u8 LM75_REG_TEMP[3] = {
45#define LM75_REG_TEMP_OS 0x03 45 0x00, /* input */
46 0x03, /* max */
47 0x02, /* hyst */
48};
46 49
47/* Each client has this additional data */ 50/* Each client has this additional data */
48struct lm75_data { 51struct lm75_data {
@@ -51,9 +54,10 @@ struct lm75_data {
51 struct mutex update_lock; 54 struct mutex update_lock;
52 char valid; /* !=0 if following fields are valid */ 55 char valid; /* !=0 if following fields are valid */
53 unsigned long last_updated; /* In jiffies */ 56 unsigned long last_updated; /* In jiffies */
54 u16 temp_input; /* Register values */ 57 u16 temp[3]; /* Register values,
55 u16 temp_max; 58 0 = input
56 u16 temp_hyst; 59 1 = max
60 2 = hyst */
57}; 61};
58 62
59static int lm75_attach_adapter(struct i2c_adapter *adapter); 63static int lm75_attach_adapter(struct i2c_adapter *adapter);
@@ -75,35 +79,36 @@ static struct i2c_driver lm75_driver = {
75 .detach_client = lm75_detach_client, 79 .detach_client = lm75_detach_client,
76}; 80};
77 81
78#define show(value) \ 82static ssize_t show_temp(struct device *dev, struct device_attribute *da,
79static ssize_t show_##value(struct device *dev, struct device_attribute *attr, char *buf) \ 83 char *buf)
80{ \ 84{
81 struct lm75_data *data = lm75_update_device(dev); \ 85 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
82 return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->value)); \ 86 struct lm75_data *data = lm75_update_device(dev);
87 return sprintf(buf, "%d\n",
88 LM75_TEMP_FROM_REG(data->temp[attr->index]));
83} 89}
84show(temp_max); 90
85show(temp_hyst); 91static ssize_t set_temp(struct device *dev, struct device_attribute *da,
86show(temp_input); 92 const char *buf, size_t count)
87 93{
88#define set(value, reg) \ 94 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
89static ssize_t set_##value(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 95 struct i2c_client *client = to_i2c_client(dev);
90{ \ 96 struct lm75_data *data = i2c_get_clientdata(client);
91 struct i2c_client *client = to_i2c_client(dev); \ 97 int nr = attr->index;
92 struct lm75_data *data = i2c_get_clientdata(client); \ 98 unsigned long temp = simple_strtoul(buf, NULL, 10);
93 int temp = simple_strtoul(buf, NULL, 10); \ 99
94 \ 100 mutex_lock(&data->update_lock);
95 mutex_lock(&data->update_lock); \ 101 data->temp[nr] = LM75_TEMP_TO_REG(temp);
96 data->value = LM75_TEMP_TO_REG(temp); \ 102 lm75_write_value(client, LM75_REG_TEMP[nr], data->temp[nr]);
97 lm75_write_value(client, reg, data->value); \ 103 mutex_unlock(&data->update_lock);
98 mutex_unlock(&data->update_lock); \ 104 return count;
99 return count; \
100} 105}
101set(temp_max, LM75_REG_TEMP_OS);
102set(temp_hyst, LM75_REG_TEMP_HYST);
103 106
104static DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO, show_temp_max, set_temp_max); 107static SENSOR_DEVICE_ATTR(temp1_max, S_IWUSR | S_IRUGO,
105static DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO, show_temp_hyst, set_temp_hyst); 108 show_temp, set_temp, 1);
106static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL); 109static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IWUSR | S_IRUGO,
110 show_temp, set_temp, 2);
111static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
107 112
108static int lm75_attach_adapter(struct i2c_adapter *adapter) 113static int lm75_attach_adapter(struct i2c_adapter *adapter)
109{ 114{
@@ -113,9 +118,9 @@ static int lm75_attach_adapter(struct i2c_adapter *adapter)
113} 118}
114 119
115static struct attribute *lm75_attributes[] = { 120static struct attribute *lm75_attributes[] = {
116 &dev_attr_temp1_input.attr, 121 &sensor_dev_attr_temp1_input.dev_attr.attr,
117 &dev_attr_temp1_max.attr, 122 &sensor_dev_attr_temp1_max.dev_attr.attr,
118 &dev_attr_temp1_max_hyst.attr, 123 &sensor_dev_attr_temp1_max_hyst.dev_attr.attr,
119 124
120 NULL 125 NULL
121}; 126};
@@ -283,11 +288,12 @@ static struct lm75_data *lm75_update_device(struct device *dev)
283 288
284 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 289 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
285 || !data->valid) { 290 || !data->valid) {
291 int i;
286 dev_dbg(&client->dev, "Starting lm75 update\n"); 292 dev_dbg(&client->dev, "Starting lm75 update\n");
287 293
288 data->temp_input = lm75_read_value(client, LM75_REG_TEMP); 294 for (i = 0; i < ARRAY_SIZE(data->temp); i++)
289 data->temp_max = lm75_read_value(client, LM75_REG_TEMP_OS); 295 data->temp[i] = lm75_read_value(client,
290 data->temp_hyst = lm75_read_value(client, LM75_REG_TEMP_HYST); 296 LM75_REG_TEMP[i]);
291 data->last_updated = jiffies; 297 data->last_updated = jiffies;
292 data->valid = 1; 298 data->valid = 1;
293 } 299 }
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index 886786c33916..9fb572f03ba5 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -2,6 +2,7 @@
2 lm78.c - Part of lm_sensors, Linux kernel modules for hardware 2 lm78.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> 4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
5 Copyright (c) 2007 Jean Delvare <khali@linux-fr.org>
5 6
6 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
@@ -23,13 +24,18 @@
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include <linux/jiffies.h> 25#include <linux/jiffies.h>
25#include <linux/i2c.h> 26#include <linux/i2c.h>
26#include <linux/i2c-isa.h> 27#include <linux/platform_device.h>
28#include <linux/ioport.h>
27#include <linux/hwmon.h> 29#include <linux/hwmon.h>
28#include <linux/hwmon-vid.h> 30#include <linux/hwmon-vid.h>
31#include <linux/hwmon-sysfs.h>
29#include <linux/err.h> 32#include <linux/err.h>
30#include <linux/mutex.h> 33#include <linux/mutex.h>
31#include <asm/io.h> 34#include <asm/io.h>
32 35
36/* ISA device, if found */
37static struct platform_device *pdev;
38
33/* Addresses to scan */ 39/* Addresses to scan */
34static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 40static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24,
35 0x25, 0x26, 0x27, 0x28, 0x29, 41 0x25, 0x26, 0x27, 0x28, 0x29,
@@ -121,12 +127,8 @@ static inline int TEMP_FROM_REG(s8 val)
121 a bit - except if there could be more than one SMBus. Groan. No solution 127 a bit - except if there could be more than one SMBus. Groan. No solution
122 for this yet. */ 128 for this yet. */
123 129
124/* This module may seem overly long and complicated. In fact, it is not so 130/* For ISA chips, we abuse the i2c_client addr and name fields. We also use
125 bad. Quite a lot of bookkeeping is done. A real driver can often cut 131 the driver field to differentiate between I2C and ISA chips. */
126 some corners. */
127
128/* For each registered chip, we need to keep some data in memory.
129 The structure is dynamically allocated. */
130struct lm78_data { 132struct lm78_data {
131 struct i2c_client client; 133 struct i2c_client client;
132 struct class_device *class_dev; 134 struct class_device *class_dev;
@@ -152,14 +154,16 @@ struct lm78_data {
152 154
153 155
154static int lm78_attach_adapter(struct i2c_adapter *adapter); 156static int lm78_attach_adapter(struct i2c_adapter *adapter);
155static int lm78_isa_attach_adapter(struct i2c_adapter *adapter);
156static int lm78_detect(struct i2c_adapter *adapter, int address, int kind); 157static int lm78_detect(struct i2c_adapter *adapter, int address, int kind);
157static int lm78_detach_client(struct i2c_client *client); 158static int lm78_detach_client(struct i2c_client *client);
158 159
159static int lm78_read_value(struct i2c_client *client, u8 reg); 160static int __devinit lm78_isa_probe(struct platform_device *pdev);
160static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value); 161static int __devexit lm78_isa_remove(struct platform_device *pdev);
162
163static int lm78_read_value(struct lm78_data *data, u8 reg);
164static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value);
161static struct lm78_data *lm78_update_device(struct device *dev); 165static struct lm78_data *lm78_update_device(struct device *dev);
162static void lm78_init_client(struct i2c_client *client); 166static void lm78_init_device(struct lm78_data *data);
163 167
164 168
165static struct i2c_driver lm78_driver = { 169static struct i2c_driver lm78_driver = {
@@ -171,95 +175,78 @@ static struct i2c_driver lm78_driver = {
171 .detach_client = lm78_detach_client, 175 .detach_client = lm78_detach_client,
172}; 176};
173 177
174static struct i2c_driver lm78_isa_driver = { 178static struct platform_driver lm78_isa_driver = {
175 .driver = { 179 .driver = {
176 .owner = THIS_MODULE, 180 .owner = THIS_MODULE,
177 .name = "lm78-isa", 181 .name = "lm78",
178 }, 182 },
179 .attach_adapter = lm78_isa_attach_adapter, 183 .probe = lm78_isa_probe,
180 .detach_client = lm78_detach_client, 184 .remove = lm78_isa_remove,
181}; 185};
182 186
183 187
184/* 7 Voltages */ 188/* 7 Voltages */
185static ssize_t show_in(struct device *dev, char *buf, int nr) 189static ssize_t show_in(struct device *dev, struct device_attribute *da,
190 char *buf)
186{ 191{
192 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
187 struct lm78_data *data = lm78_update_device(dev); 193 struct lm78_data *data = lm78_update_device(dev);
188 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); 194 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[attr->index]));
189} 195}
190 196
191static ssize_t show_in_min(struct device *dev, char *buf, int nr) 197static ssize_t show_in_min(struct device *dev, struct device_attribute *da,
198 char *buf)
192{ 199{
200 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
193 struct lm78_data *data = lm78_update_device(dev); 201 struct lm78_data *data = lm78_update_device(dev);
194 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); 202 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[attr->index]));
195} 203}
196 204
197static ssize_t show_in_max(struct device *dev, char *buf, int nr) 205static ssize_t show_in_max(struct device *dev, struct device_attribute *da,
206 char *buf)
198{ 207{
208 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
199 struct lm78_data *data = lm78_update_device(dev); 209 struct lm78_data *data = lm78_update_device(dev);
200 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); 210 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[attr->index]));
201} 211}
202 212
203static ssize_t set_in_min(struct device *dev, const char *buf, 213static ssize_t set_in_min(struct device *dev, struct device_attribute *da,
204 size_t count, int nr) 214 const char *buf, size_t count)
205{ 215{
206 struct i2c_client *client = to_i2c_client(dev); 216 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
207 struct lm78_data *data = i2c_get_clientdata(client); 217 struct lm78_data *data = dev_get_drvdata(dev);
208 unsigned long val = simple_strtoul(buf, NULL, 10); 218 unsigned long val = simple_strtoul(buf, NULL, 10);
219 int nr = attr->index;
209 220
210 mutex_lock(&data->update_lock); 221 mutex_lock(&data->update_lock);
211 data->in_min[nr] = IN_TO_REG(val); 222 data->in_min[nr] = IN_TO_REG(val);
212 lm78_write_value(client, LM78_REG_IN_MIN(nr), data->in_min[nr]); 223 lm78_write_value(data, LM78_REG_IN_MIN(nr), data->in_min[nr]);
213 mutex_unlock(&data->update_lock); 224 mutex_unlock(&data->update_lock);
214 return count; 225 return count;
215} 226}
216 227
217static ssize_t set_in_max(struct device *dev, const char *buf, 228static ssize_t set_in_max(struct device *dev, struct device_attribute *da,
218 size_t count, int nr) 229 const char *buf, size_t count)
219{ 230{
220 struct i2c_client *client = to_i2c_client(dev); 231 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
221 struct lm78_data *data = i2c_get_clientdata(client); 232 struct lm78_data *data = dev_get_drvdata(dev);
222 unsigned long val = simple_strtoul(buf, NULL, 10); 233 unsigned long val = simple_strtoul(buf, NULL, 10);
234 int nr = attr->index;
223 235
224 mutex_lock(&data->update_lock); 236 mutex_lock(&data->update_lock);
225 data->in_max[nr] = IN_TO_REG(val); 237 data->in_max[nr] = IN_TO_REG(val);
226 lm78_write_value(client, LM78_REG_IN_MAX(nr), data->in_max[nr]); 238 lm78_write_value(data, LM78_REG_IN_MAX(nr), data->in_max[nr]);
227 mutex_unlock(&data->update_lock); 239 mutex_unlock(&data->update_lock);
228 return count; 240 return count;
229} 241}
230 242
231#define show_in_offset(offset) \ 243#define show_in_offset(offset) \
232static ssize_t \ 244static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
233 show_in##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 245 show_in, NULL, offset); \
234{ \ 246static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
235 return show_in(dev, buf, offset); \ 247 show_in_min, set_in_min, offset); \
236} \ 248static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
237static DEVICE_ATTR(in##offset##_input, S_IRUGO, \ 249 show_in_max, set_in_max, offset);
238 show_in##offset, NULL); \
239static ssize_t \
240 show_in##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
241{ \
242 return show_in_min(dev, buf, offset); \
243} \
244static ssize_t \
245 show_in##offset##_max (struct device *dev, struct device_attribute *attr, char *buf) \
246{ \
247 return show_in_max(dev, buf, offset); \
248} \
249static ssize_t set_in##offset##_min (struct device *dev, struct device_attribute *attr, \
250 const char *buf, size_t count) \
251{ \
252 return set_in_min(dev, buf, count, offset); \
253} \
254static ssize_t set_in##offset##_max (struct device *dev, struct device_attribute *attr, \
255 const char *buf, size_t count) \
256{ \
257 return set_in_max(dev, buf, count, offset); \
258} \
259static DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
260 show_in##offset##_min, set_in##offset##_min); \
261static DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
262 show_in##offset##_max, set_in##offset##_max);
263 250
264show_in_offset(0); 251show_in_offset(0);
265show_in_offset(1); 252show_in_offset(1);
@@ -270,46 +257,49 @@ show_in_offset(5);
270show_in_offset(6); 257show_in_offset(6);
271 258
272/* Temperature */ 259/* Temperature */
273static ssize_t show_temp(struct device *dev, struct device_attribute *attr, char *buf) 260static ssize_t show_temp(struct device *dev, struct device_attribute *da,
261 char *buf)
274{ 262{
275 struct lm78_data *data = lm78_update_device(dev); 263 struct lm78_data *data = lm78_update_device(dev);
276 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp)); 264 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
277} 265}
278 266
279static ssize_t show_temp_over(struct device *dev, struct device_attribute *attr, char *buf) 267static ssize_t show_temp_over(struct device *dev, struct device_attribute *da,
268 char *buf)
280{ 269{
281 struct lm78_data *data = lm78_update_device(dev); 270 struct lm78_data *data = lm78_update_device(dev);
282 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over)); 271 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
283} 272}
284 273
285static ssize_t set_temp_over(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 274static ssize_t set_temp_over(struct device *dev, struct device_attribute *da,
275 const char *buf, size_t count)
286{ 276{
287 struct i2c_client *client = to_i2c_client(dev); 277 struct lm78_data *data = dev_get_drvdata(dev);
288 struct lm78_data *data = i2c_get_clientdata(client);
289 long val = simple_strtol(buf, NULL, 10); 278 long val = simple_strtol(buf, NULL, 10);
290 279
291 mutex_lock(&data->update_lock); 280 mutex_lock(&data->update_lock);
292 data->temp_over = TEMP_TO_REG(val); 281 data->temp_over = TEMP_TO_REG(val);
293 lm78_write_value(client, LM78_REG_TEMP_OVER, data->temp_over); 282 lm78_write_value(data, LM78_REG_TEMP_OVER, data->temp_over);
294 mutex_unlock(&data->update_lock); 283 mutex_unlock(&data->update_lock);
295 return count; 284 return count;
296} 285}
297 286
298static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *attr, char *buf) 287static ssize_t show_temp_hyst(struct device *dev, struct device_attribute *da,
288 char *buf)
299{ 289{
300 struct lm78_data *data = lm78_update_device(dev); 290 struct lm78_data *data = lm78_update_device(dev);
301 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst)); 291 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
302} 292}
303 293
304static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 294static ssize_t set_temp_hyst(struct device *dev, struct device_attribute *da,
295 const char *buf, size_t count)
305{ 296{
306 struct i2c_client *client = to_i2c_client(dev); 297 struct lm78_data *data = dev_get_drvdata(dev);
307 struct lm78_data *data = i2c_get_clientdata(client);
308 long val = simple_strtol(buf, NULL, 10); 298 long val = simple_strtol(buf, NULL, 10);
309 299
310 mutex_lock(&data->update_lock); 300 mutex_lock(&data->update_lock);
311 data->temp_hyst = TEMP_TO_REG(val); 301 data->temp_hyst = TEMP_TO_REG(val);
312 lm78_write_value(client, LM78_REG_TEMP_HYST, data->temp_hyst); 302 lm78_write_value(data, LM78_REG_TEMP_HYST, data->temp_hyst);
313 mutex_unlock(&data->update_lock); 303 mutex_unlock(&data->update_lock);
314 return count; 304 return count;
315} 305}
@@ -321,49 +311,59 @@ static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
321 show_temp_hyst, set_temp_hyst); 311 show_temp_hyst, set_temp_hyst);
322 312
323/* 3 Fans */ 313/* 3 Fans */
324static ssize_t show_fan(struct device *dev, char *buf, int nr) 314static ssize_t show_fan(struct device *dev, struct device_attribute *da,
315 char *buf)
325{ 316{
317 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
326 struct lm78_data *data = lm78_update_device(dev); 318 struct lm78_data *data = lm78_update_device(dev);
319 int nr = attr->index;
327 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], 320 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
328 DIV_FROM_REG(data->fan_div[nr])) ); 321 DIV_FROM_REG(data->fan_div[nr])) );
329} 322}
330 323
331static ssize_t show_fan_min(struct device *dev, char *buf, int nr) 324static ssize_t show_fan_min(struct device *dev, struct device_attribute *da,
325 char *buf)
332{ 326{
327 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
333 struct lm78_data *data = lm78_update_device(dev); 328 struct lm78_data *data = lm78_update_device(dev);
329 int nr = attr->index;
334 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr], 330 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
335 DIV_FROM_REG(data->fan_div[nr])) ); 331 DIV_FROM_REG(data->fan_div[nr])) );
336} 332}
337 333
338static ssize_t set_fan_min(struct device *dev, const char *buf, 334static ssize_t set_fan_min(struct device *dev, struct device_attribute *da,
339 size_t count, int nr) 335 const char *buf, size_t count)
340{ 336{
341 struct i2c_client *client = to_i2c_client(dev); 337 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
342 struct lm78_data *data = i2c_get_clientdata(client); 338 struct lm78_data *data = dev_get_drvdata(dev);
339 int nr = attr->index;
343 unsigned long val = simple_strtoul(buf, NULL, 10); 340 unsigned long val = simple_strtoul(buf, NULL, 10);
344 341
345 mutex_lock(&data->update_lock); 342 mutex_lock(&data->update_lock);
346 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); 343 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]); 344 lm78_write_value(data, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
348 mutex_unlock(&data->update_lock); 345 mutex_unlock(&data->update_lock);
349 return count; 346 return count;
350} 347}
351 348
352static ssize_t show_fan_div(struct device *dev, char *buf, int nr) 349static ssize_t show_fan_div(struct device *dev, struct device_attribute *da,
350 char *buf)
353{ 351{
352 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
354 struct lm78_data *data = lm78_update_device(dev); 353 struct lm78_data *data = lm78_update_device(dev);
355 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) ); 354 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
356} 355}
357 356
358/* Note: we save and restore the fan minimum here, because its value is 357/* Note: we save and restore the fan minimum here, because its value is
359 determined in part by the fan divisor. This follows the principle of 358 determined in part by the fan divisor. This follows the principle of
360 least surprise; the user doesn't expect the fan minimum to change just 359 least surprise; the user doesn't expect the fan minimum to change just
361 because the divisor changed. */ 360 because the divisor changed. */
362static ssize_t set_fan_div(struct device *dev, const char *buf, 361static ssize_t set_fan_div(struct device *dev, struct device_attribute *da,
363 size_t count, int nr) 362 const char *buf, size_t count)
364{ 363{
365 struct i2c_client *client = to_i2c_client(dev); 364 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
366 struct lm78_data *data = i2c_get_clientdata(client); 365 struct lm78_data *data = dev_get_drvdata(dev);
366 int nr = attr->index;
367 unsigned long val = simple_strtoul(buf, NULL, 10); 367 unsigned long val = simple_strtoul(buf, NULL, 10);
368 unsigned long min; 368 unsigned long min;
369 u8 reg; 369 u8 reg;
@@ -378,13 +378,13 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
378 case 4: data->fan_div[nr] = 2; break; 378 case 4: data->fan_div[nr] = 2; break;
379 case 8: data->fan_div[nr] = 3; break; 379 case 8: data->fan_div[nr] = 3; break;
380 default: 380 default:
381 dev_err(&client->dev, "fan_div value %ld not " 381 dev_err(dev, "fan_div value %ld not "
382 "supported. Choose one of 1, 2, 4 or 8!\n", val); 382 "supported. Choose one of 1, 2, 4 or 8!\n", val);
383 mutex_unlock(&data->update_lock); 383 mutex_unlock(&data->update_lock);
384 return -EINVAL; 384 return -EINVAL;
385 } 385 }
386 386
387 reg = lm78_read_value(client, LM78_REG_VID_FANDIV); 387 reg = lm78_read_value(data, LM78_REG_VID_FANDIV);
388 switch (nr) { 388 switch (nr) {
389 case 0: 389 case 0:
390 reg = (reg & 0xcf) | (data->fan_div[nr] << 4); 390 reg = (reg & 0xcf) | (data->fan_div[nr] << 4);
@@ -393,63 +393,36 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
393 reg = (reg & 0x3f) | (data->fan_div[nr] << 6); 393 reg = (reg & 0x3f) | (data->fan_div[nr] << 6);
394 break; 394 break;
395 } 395 }
396 lm78_write_value(client, LM78_REG_VID_FANDIV, reg); 396 lm78_write_value(data, LM78_REG_VID_FANDIV, reg);
397 397
398 data->fan_min[nr] = 398 data->fan_min[nr] =
399 FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 399 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]); 400 lm78_write_value(data, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
401 mutex_unlock(&data->update_lock); 401 mutex_unlock(&data->update_lock);
402 402
403 return count; 403 return count;
404} 404}
405 405
406#define show_fan_offset(offset) \ 406#define show_fan_offset(offset) \
407static ssize_t show_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 407static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
408{ \ 408 show_fan, NULL, offset - 1); \
409 return show_fan(dev, buf, offset - 1); \ 409static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
410} \ 410 show_fan_min, set_fan_min, offset - 1);
411static ssize_t show_fan_##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \
412{ \
413 return show_fan_min(dev, buf, offset - 1); \
414} \
415static ssize_t show_fan_##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \
416{ \
417 return show_fan_div(dev, buf, offset - 1); \
418} \
419static ssize_t set_fan_##offset##_min (struct device *dev, struct device_attribute *attr, \
420 const char *buf, size_t count) \
421{ \
422 return set_fan_min(dev, buf, count, offset - 1); \
423} \
424static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_fan_##offset, NULL);\
425static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
426 show_fan_##offset##_min, set_fan_##offset##_min);
427
428static ssize_t set_fan_1_div(struct device *dev, struct device_attribute *attr, const char *buf,
429 size_t count)
430{
431 return set_fan_div(dev, buf, count, 0) ;
432}
433
434static ssize_t set_fan_2_div(struct device *dev, struct device_attribute *attr, const char *buf,
435 size_t count)
436{
437 return set_fan_div(dev, buf, count, 1) ;
438}
439 411
440show_fan_offset(1); 412show_fan_offset(1);
441show_fan_offset(2); 413show_fan_offset(2);
442show_fan_offset(3); 414show_fan_offset(3);
443 415
444/* Fan 3 divisor is locked in H/W */ 416/* Fan 3 divisor is locked in H/W */
445static DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, 417static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
446 show_fan_1_div, set_fan_1_div); 418 show_fan_div, set_fan_div, 0);
447static DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, 419static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
448 show_fan_2_div, set_fan_2_div); 420 show_fan_div, set_fan_div, 1);
449static DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_3_div, NULL); 421static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2);
450 422
451/* VID */ 423/* VID */
452static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf) 424static ssize_t show_vid(struct device *dev, struct device_attribute *da,
425 char *buf)
453{ 426{
454 struct lm78_data *data = lm78_update_device(dev); 427 struct lm78_data *data = lm78_update_device(dev);
455 return sprintf(buf, "%d\n", vid_from_reg(data->vid, 82)); 428 return sprintf(buf, "%d\n", vid_from_reg(data->vid, 82));
@@ -457,7 +430,8 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char
457static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 430static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
458 431
459/* Alarms */ 432/* Alarms */
460static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 433static ssize_t show_alarms(struct device *dev, struct device_attribute *da,
434 char *buf)
461{ 435{
462 struct lm78_data *data = lm78_update_device(dev); 436 struct lm78_data *data = lm78_update_device(dev);
463 return sprintf(buf, "%u\n", data->alarms); 437 return sprintf(buf, "%u\n", data->alarms);
@@ -475,45 +449,40 @@ static int lm78_attach_adapter(struct i2c_adapter *adapter)
475 return i2c_probe(adapter, &addr_data, lm78_detect); 449 return i2c_probe(adapter, &addr_data, lm78_detect);
476} 450}
477 451
478static int lm78_isa_attach_adapter(struct i2c_adapter *adapter)
479{
480 return lm78_detect(adapter, isa_address, -1);
481}
482
483static struct attribute *lm78_attributes[] = { 452static struct attribute *lm78_attributes[] = {
484 &dev_attr_in0_input.attr, 453 &sensor_dev_attr_in0_input.dev_attr.attr,
485 &dev_attr_in0_min.attr, 454 &sensor_dev_attr_in0_min.dev_attr.attr,
486 &dev_attr_in0_max.attr, 455 &sensor_dev_attr_in0_max.dev_attr.attr,
487 &dev_attr_in1_input.attr, 456 &sensor_dev_attr_in1_input.dev_attr.attr,
488 &dev_attr_in1_min.attr, 457 &sensor_dev_attr_in1_min.dev_attr.attr,
489 &dev_attr_in1_max.attr, 458 &sensor_dev_attr_in1_max.dev_attr.attr,
490 &dev_attr_in2_input.attr, 459 &sensor_dev_attr_in2_input.dev_attr.attr,
491 &dev_attr_in2_min.attr, 460 &sensor_dev_attr_in2_min.dev_attr.attr,
492 &dev_attr_in2_max.attr, 461 &sensor_dev_attr_in2_max.dev_attr.attr,
493 &dev_attr_in3_input.attr, 462 &sensor_dev_attr_in3_input.dev_attr.attr,
494 &dev_attr_in3_min.attr, 463 &sensor_dev_attr_in3_min.dev_attr.attr,
495 &dev_attr_in3_max.attr, 464 &sensor_dev_attr_in3_max.dev_attr.attr,
496 &dev_attr_in4_input.attr, 465 &sensor_dev_attr_in4_input.dev_attr.attr,
497 &dev_attr_in4_min.attr, 466 &sensor_dev_attr_in4_min.dev_attr.attr,
498 &dev_attr_in4_max.attr, 467 &sensor_dev_attr_in4_max.dev_attr.attr,
499 &dev_attr_in5_input.attr, 468 &sensor_dev_attr_in5_input.dev_attr.attr,
500 &dev_attr_in5_min.attr, 469 &sensor_dev_attr_in5_min.dev_attr.attr,
501 &dev_attr_in5_max.attr, 470 &sensor_dev_attr_in5_max.dev_attr.attr,
502 &dev_attr_in6_input.attr, 471 &sensor_dev_attr_in6_input.dev_attr.attr,
503 &dev_attr_in6_min.attr, 472 &sensor_dev_attr_in6_min.dev_attr.attr,
504 &dev_attr_in6_max.attr, 473 &sensor_dev_attr_in6_max.dev_attr.attr,
505 &dev_attr_temp1_input.attr, 474 &dev_attr_temp1_input.attr,
506 &dev_attr_temp1_max.attr, 475 &dev_attr_temp1_max.attr,
507 &dev_attr_temp1_max_hyst.attr, 476 &dev_attr_temp1_max_hyst.attr,
508 &dev_attr_fan1_input.attr, 477 &sensor_dev_attr_fan1_input.dev_attr.attr,
509 &dev_attr_fan1_min.attr, 478 &sensor_dev_attr_fan1_min.dev_attr.attr,
510 &dev_attr_fan1_div.attr, 479 &sensor_dev_attr_fan1_div.dev_attr.attr,
511 &dev_attr_fan2_input.attr, 480 &sensor_dev_attr_fan2_input.dev_attr.attr,
512 &dev_attr_fan2_min.attr, 481 &sensor_dev_attr_fan2_min.dev_attr.attr,
513 &dev_attr_fan2_div.attr, 482 &sensor_dev_attr_fan2_div.dev_attr.attr,
514 &dev_attr_fan3_input.attr, 483 &sensor_dev_attr_fan3_input.dev_attr.attr,
515 &dev_attr_fan3_min.attr, 484 &sensor_dev_attr_fan3_min.dev_attr.attr,
516 &dev_attr_fan3_div.attr, 485 &sensor_dev_attr_fan3_div.dev_attr.attr,
517 &dev_attr_alarms.attr, 486 &dev_attr_alarms.attr,
518 &dev_attr_cpu0_vid.attr, 487 &dev_attr_cpu0_vid.attr,
519 488
@@ -524,6 +493,17 @@ static const struct attribute_group lm78_group = {
524 .attrs = lm78_attributes, 493 .attrs = lm78_attributes,
525}; 494};
526 495
496/* I2C devices get this name attribute automatically, but for ISA devices
497 we must create it by ourselves. */
498static ssize_t show_name(struct device *dev, struct device_attribute
499 *devattr, char *buf)
500{
501 struct lm78_data *data = dev_get_drvdata(dev);
502
503 return sprintf(buf, "%s\n", data->client.name);
504}
505static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
506
527/* This function is called by i2c_probe */ 507/* This function is called by i2c_probe */
528static int lm78_detect(struct i2c_adapter *adapter, int address, int kind) 508static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
529{ 509{
@@ -531,54 +511,10 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
531 struct i2c_client *new_client; 511 struct i2c_client *new_client;
532 struct lm78_data *data; 512 struct lm78_data *data;
533 const char *client_name = ""; 513 const char *client_name = "";
534 int is_isa = i2c_is_isa_adapter(adapter);
535 514
536 if (!is_isa && 515 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
537 !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
538 err = -ENODEV; 516 err = -ENODEV;
539 goto ERROR0; 517 goto ERROR1;
540 }
541
542 /* Reserve the ISA region */
543 if (is_isa)
544 if (!request_region(address, LM78_EXTENT,
545 lm78_isa_driver.driver.name)) {
546 err = -EBUSY;
547 goto ERROR0;
548 }
549
550 /* Probe whether there is anything available on this address. Already
551 done for SMBus clients */
552 if (kind < 0) {
553 if (is_isa) {
554
555#define REALLY_SLOW_IO
556 /* We need the timeouts for at least some LM78-like
557 chips. But only if we read 'undefined' registers. */
558 i = inb_p(address + 1);
559 if (inb_p(address + 2) != i) {
560 err = -ENODEV;
561 goto ERROR1;
562 }
563 if (inb_p(address + 3) != i) {
564 err = -ENODEV;
565 goto ERROR1;
566 }
567 if (inb_p(address + 7) != i) {
568 err = -ENODEV;
569 goto ERROR1;
570 }
571#undef REALLY_SLOW_IO
572
573 /* Let's just hope nothing breaks here */
574 i = inb_p(address + 5) & 0x7f;
575 outb_p(~i & 0x7f, address + 5);
576 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) {
577 outb_p(i, address + 5);
578 err = -ENODEV;
579 goto ERROR1;
580 }
581 }
582 } 518 }
583 519
584 /* OK. For now, we presume we have a valid client. We now create the 520 /* OK. For now, we presume we have a valid client. We now create the
@@ -591,22 +527,19 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
591 } 527 }
592 528
593 new_client = &data->client; 529 new_client = &data->client;
594 if (is_isa)
595 mutex_init(&data->lock);
596 i2c_set_clientdata(new_client, data); 530 i2c_set_clientdata(new_client, data);
597 new_client->addr = address; 531 new_client->addr = address;
598 new_client->adapter = adapter; 532 new_client->adapter = adapter;
599 new_client->driver = is_isa ? &lm78_isa_driver : &lm78_driver; 533 new_client->driver = &lm78_driver;
600 new_client->flags = 0;
601 534
602 /* Now, we do the remaining detection. */ 535 /* Now, we do the remaining detection. */
603 if (kind < 0) { 536 if (kind < 0) {
604 if (lm78_read_value(new_client, LM78_REG_CONFIG) & 0x80) { 537 if (lm78_read_value(data, LM78_REG_CONFIG) & 0x80) {
605 err = -ENODEV; 538 err = -ENODEV;
606 goto ERROR2; 539 goto ERROR2;
607 } 540 }
608 if (!is_isa && (lm78_read_value( 541 if (lm78_read_value(data, LM78_REG_I2C_ADDR) !=
609 new_client, LM78_REG_I2C_ADDR) != address)) { 542 address) {
610 err = -ENODEV; 543 err = -ENODEV;
611 goto ERROR2; 544 goto ERROR2;
612 } 545 }
@@ -614,7 +547,7 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
614 547
615 /* Determine the chip type. */ 548 /* Determine the chip type. */
616 if (kind <= 0) { 549 if (kind <= 0) {
617 i = lm78_read_value(new_client, LM78_REG_CHIPID); 550 i = lm78_read_value(data, LM78_REG_CHIPID);
618 if (i == 0x00 || i == 0x20 /* LM78 */ 551 if (i == 0x00 || i == 0x20 /* LM78 */
619 || i == 0x40) /* LM78-J */ 552 || i == 0x40) /* LM78-J */
620 kind = lm78; 553 kind = lm78;
@@ -641,21 +574,12 @@ static int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
641 strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 574 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
642 data->type = kind; 575 data->type = kind;
643 576
644 data->valid = 0;
645 mutex_init(&data->update_lock);
646
647 /* Tell the I2C layer a new client has arrived */ 577 /* Tell the I2C layer a new client has arrived */
648 if ((err = i2c_attach_client(new_client))) 578 if ((err = i2c_attach_client(new_client)))
649 goto ERROR2; 579 goto ERROR2;
650 580
651 /* Initialize the LM78 chip */ 581 /* Initialize the LM78 chip */
652 lm78_init_client(new_client); 582 lm78_init_device(data);
653
654 /* A few vars need to be filled upon startup */
655 for (i = 0; i < 3; i++) {
656 data->fan_min[i] = lm78_read_value(new_client,
657 LM78_REG_FAN_MIN(i));
658 }
659 583
660 /* Register sysfs hooks */ 584 /* Register sysfs hooks */
661 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm78_group))) 585 if ((err = sysfs_create_group(&new_client->dev.kobj, &lm78_group)))
@@ -676,9 +600,6 @@ ERROR3:
676ERROR2: 600ERROR2:
677 kfree(data); 601 kfree(data);
678ERROR1: 602ERROR1:
679 if (is_isa)
680 release_region(address, LM78_EXTENT);
681ERROR0:
682 return err; 603 return err;
683} 604}
684 605
@@ -693,9 +614,77 @@ static int lm78_detach_client(struct i2c_client *client)
693 if ((err = i2c_detach_client(client))) 614 if ((err = i2c_detach_client(client)))
694 return err; 615 return err;
695 616
696 if(i2c_is_isa_client(client)) 617 kfree(data);
697 release_region(client->addr, LM78_EXTENT); 618
619 return 0;
620}
621
622static int __devinit lm78_isa_probe(struct platform_device *pdev)
623{
624 int err;
625 struct lm78_data *data;
626 struct resource *res;
627 const char *name;
628
629 /* Reserve the ISA region */
630 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
631 if (!request_region(res->start, LM78_EXTENT, "lm78")) {
632 err = -EBUSY;
633 goto exit;
634 }
635
636 if (!(data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL))) {
637 err = -ENOMEM;
638 goto exit_release_region;
639 }
640 mutex_init(&data->lock);
641 data->client.addr = res->start;
642 i2c_set_clientdata(&data->client, data);
643 platform_set_drvdata(pdev, data);
644
645 if (lm78_read_value(data, LM78_REG_CHIPID) & 0x80) {
646 data->type = lm79;
647 name = "lm79";
648 } else {
649 data->type = lm78;
650 name = "lm78";
651 }
652 strlcpy(data->client.name, name, I2C_NAME_SIZE);
653
654 /* Initialize the LM78 chip */
655 lm78_init_device(data);
656
657 /* Register sysfs hooks */
658 if ((err = sysfs_create_group(&pdev->dev.kobj, &lm78_group))
659 || (err = device_create_file(&pdev->dev, &dev_attr_name)))
660 goto exit_remove_files;
661
662 data->class_dev = hwmon_device_register(&pdev->dev);
663 if (IS_ERR(data->class_dev)) {
664 err = PTR_ERR(data->class_dev);
665 goto exit_remove_files;
666 }
667
668 return 0;
669
670 exit_remove_files:
671 sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
672 device_remove_file(&pdev->dev, &dev_attr_name);
673 kfree(data);
674 exit_release_region:
675 release_region(res->start, LM78_EXTENT);
676 exit:
677 return err;
678}
679
680static int __devexit lm78_isa_remove(struct platform_device *pdev)
681{
682 struct lm78_data *data = platform_get_drvdata(pdev);
698 683
684 hwmon_device_unregister(data->class_dev);
685 sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
686 device_remove_file(&pdev->dev, &dev_attr_name);
687 release_region(data->client.addr, LM78_EXTENT);
699 kfree(data); 688 kfree(data);
700 689
701 return 0; 690 return 0;
@@ -706,11 +695,12 @@ static int lm78_detach_client(struct i2c_client *client)
706 separately. 695 separately.
707 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks, 696 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
708 would slow down the LM78 access and should not be necessary. */ 697 would slow down the LM78 access and should not be necessary. */
709static int lm78_read_value(struct i2c_client *client, u8 reg) 698static int lm78_read_value(struct lm78_data *data, u8 reg)
710{ 699{
711 int res; 700 struct i2c_client *client = &data->client;
712 if (i2c_is_isa_client(client)) { 701
713 struct lm78_data *data = i2c_get_clientdata(client); 702 if (!client->driver) { /* ISA device */
703 int res;
714 mutex_lock(&data->lock); 704 mutex_lock(&data->lock);
715 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); 705 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
716 res = inb_p(client->addr + LM78_DATA_REG_OFFSET); 706 res = inb_p(client->addr + LM78_DATA_REG_OFFSET);
@@ -727,10 +717,11 @@ static int lm78_read_value(struct i2c_client *client, u8 reg)
727 would slow down the LM78 access and should not be necessary. 717 would slow down the LM78 access and should not be necessary.
728 There are some ugly typecasts here, but the good new is - they should 718 There are some ugly typecasts here, but the good new is - they should
729 nowhere else be necessary! */ 719 nowhere else be necessary! */
730static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value) 720static int lm78_write_value(struct lm78_data *data, u8 reg, u8 value)
731{ 721{
732 if (i2c_is_isa_client(client)) { 722 struct i2c_client *client = &data->client;
733 struct lm78_data *data = i2c_get_clientdata(client); 723
724 if (!client->driver) { /* ISA device */
734 mutex_lock(&data->lock); 725 mutex_lock(&data->lock);
735 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); 726 outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
736 outb_p(value, client->addr + LM78_DATA_REG_OFFSET); 727 outb_p(value, client->addr + LM78_DATA_REG_OFFSET);
@@ -740,20 +731,29 @@ static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value)
740 return i2c_smbus_write_byte_data(client, reg, value); 731 return i2c_smbus_write_byte_data(client, reg, value);
741} 732}
742 733
743static void lm78_init_client(struct i2c_client *client) 734static void lm78_init_device(struct lm78_data *data)
744{ 735{
745 u8 config = lm78_read_value(client, LM78_REG_CONFIG); 736 u8 config;
737 int i;
746 738
747 /* Start monitoring */ 739 /* Start monitoring */
748 if (!(config & 0x01)) 740 config = lm78_read_value(data, LM78_REG_CONFIG);
749 lm78_write_value(client, LM78_REG_CONFIG, 741 if ((config & 0x09) != 0x01)
742 lm78_write_value(data, LM78_REG_CONFIG,
750 (config & 0xf7) | 0x01); 743 (config & 0xf7) | 0x01);
744
745 /* A few vars need to be filled upon startup */
746 for (i = 0; i < 3; i++) {
747 data->fan_min[i] = lm78_read_value(data,
748 LM78_REG_FAN_MIN(i));
749 }
750
751 mutex_init(&data->update_lock);
751} 752}
752 753
753static struct lm78_data *lm78_update_device(struct device *dev) 754static struct lm78_data *lm78_update_device(struct device *dev)
754{ 755{
755 struct i2c_client *client = to_i2c_client(dev); 756 struct lm78_data *data = dev_get_drvdata(dev);
756 struct lm78_data *data = i2c_get_clientdata(client);
757 int i; 757 int i;
758 758
759 mutex_lock(&data->update_lock); 759 mutex_lock(&data->update_lock);
@@ -761,39 +761,39 @@ static struct lm78_data *lm78_update_device(struct device *dev)
761 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) 761 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
762 || !data->valid) { 762 || !data->valid) {
763 763
764 dev_dbg(&client->dev, "Starting lm78 update\n"); 764 dev_dbg(dev, "Starting lm78 update\n");
765 765
766 for (i = 0; i <= 6; i++) { 766 for (i = 0; i <= 6; i++) {
767 data->in[i] = 767 data->in[i] =
768 lm78_read_value(client, LM78_REG_IN(i)); 768 lm78_read_value(data, LM78_REG_IN(i));
769 data->in_min[i] = 769 data->in_min[i] =
770 lm78_read_value(client, LM78_REG_IN_MIN(i)); 770 lm78_read_value(data, LM78_REG_IN_MIN(i));
771 data->in_max[i] = 771 data->in_max[i] =
772 lm78_read_value(client, LM78_REG_IN_MAX(i)); 772 lm78_read_value(data, LM78_REG_IN_MAX(i));
773 } 773 }
774 for (i = 0; i < 3; i++) { 774 for (i = 0; i < 3; i++) {
775 data->fan[i] = 775 data->fan[i] =
776 lm78_read_value(client, LM78_REG_FAN(i)); 776 lm78_read_value(data, LM78_REG_FAN(i));
777 data->fan_min[i] = 777 data->fan_min[i] =
778 lm78_read_value(client, LM78_REG_FAN_MIN(i)); 778 lm78_read_value(data, LM78_REG_FAN_MIN(i));
779 } 779 }
780 data->temp = lm78_read_value(client, LM78_REG_TEMP); 780 data->temp = lm78_read_value(data, LM78_REG_TEMP);
781 data->temp_over = 781 data->temp_over =
782 lm78_read_value(client, LM78_REG_TEMP_OVER); 782 lm78_read_value(data, LM78_REG_TEMP_OVER);
783 data->temp_hyst = 783 data->temp_hyst =
784 lm78_read_value(client, LM78_REG_TEMP_HYST); 784 lm78_read_value(data, LM78_REG_TEMP_HYST);
785 i = lm78_read_value(client, LM78_REG_VID_FANDIV); 785 i = lm78_read_value(data, LM78_REG_VID_FANDIV);
786 data->vid = i & 0x0f; 786 data->vid = i & 0x0f;
787 if (data->type == lm79) 787 if (data->type == lm79)
788 data->vid |= 788 data->vid |=
789 (lm78_read_value(client, LM78_REG_CHIPID) & 789 (lm78_read_value(data, LM78_REG_CHIPID) &
790 0x01) << 4; 790 0x01) << 4;
791 else 791 else
792 data->vid |= 0x10; 792 data->vid |= 0x10;
793 data->fan_div[0] = (i >> 4) & 0x03; 793 data->fan_div[0] = (i >> 4) & 0x03;
794 data->fan_div[1] = i >> 6; 794 data->fan_div[1] = i >> 6;
795 data->alarms = lm78_read_value(client, LM78_REG_ALARM1) + 795 data->alarms = lm78_read_value(data, LM78_REG_ALARM1) +
796 (lm78_read_value(client, LM78_REG_ALARM2) << 8); 796 (lm78_read_value(data, LM78_REG_ALARM2) << 8);
797 data->last_updated = jiffies; 797 data->last_updated = jiffies;
798 data->valid = 1; 798 data->valid = 1;
799 799
@@ -805,26 +805,154 @@ static struct lm78_data *lm78_update_device(struct device *dev)
805 return data; 805 return data;
806} 806}
807 807
808/* return 1 if a supported chip is found, 0 otherwise */
809static int __init lm78_isa_found(unsigned short address)
810{
811 int val, save, found = 0;
812
813 if (!request_region(address, LM78_EXTENT, "lm78"))
814 return 0;
815
816#define REALLY_SLOW_IO
817 /* We need the timeouts for at least some LM78-like
818 chips. But only if we read 'undefined' registers. */
819 val = inb_p(address + 1);
820 if (inb_p(address + 2) != val
821 || inb_p(address + 3) != val
822 || inb_p(address + 7) != val)
823 goto release;
824#undef REALLY_SLOW_IO
825
826 /* We should be able to change the 7 LSB of the address port. The
827 MSB (busy flag) should be clear initially, set after the write. */
828 save = inb_p(address + LM78_ADDR_REG_OFFSET);
829 if (save & 0x80)
830 goto release;
831 val = ~save & 0x7f;
832 outb_p(val, address + LM78_ADDR_REG_OFFSET);
833 if (inb_p(address + LM78_ADDR_REG_OFFSET) != (val | 0x80)) {
834 outb_p(save, address + LM78_ADDR_REG_OFFSET);
835 goto release;
836 }
837
838 /* We found a device, now see if it could be an LM78 */
839 outb_p(LM78_REG_CONFIG, address + LM78_ADDR_REG_OFFSET);
840 val = inb_p(address + LM78_DATA_REG_OFFSET);
841 if (val & 0x80)
842 goto release;
843 outb_p(LM78_REG_I2C_ADDR, address + LM78_ADDR_REG_OFFSET);
844 val = inb_p(address + LM78_DATA_REG_OFFSET);
845 if (val < 0x03 || val > 0x77) /* Not a valid I2C address */
846 goto release;
847
848 /* The busy flag should be clear again */
849 if (inb_p(address + LM78_ADDR_REG_OFFSET) & 0x80)
850 goto release;
851
852 /* Explicitly prevent the misdetection of Winbond chips */
853 outb_p(0x4f, address + LM78_ADDR_REG_OFFSET);
854 val = inb_p(address + LM78_DATA_REG_OFFSET);
855 if (val == 0xa3 || val == 0x5c)
856 goto release;
857
858 /* Explicitly prevent the misdetection of ITE chips */
859 outb_p(0x58, address + LM78_ADDR_REG_OFFSET);
860 val = inb_p(address + LM78_DATA_REG_OFFSET);
861 if (val == 0x90)
862 goto release;
863
864 /* Determine the chip type */
865 outb_p(LM78_REG_CHIPID, address + LM78_ADDR_REG_OFFSET);
866 val = inb_p(address + LM78_DATA_REG_OFFSET);
867 if (val == 0x00 /* LM78 */
868 || val == 0x40 /* LM78-J */
869 || (val & 0xfe) == 0xc0) /* LM79 */
870 found = 1;
871
872 if (found)
873 pr_info("lm78: Found an %s chip at %#x\n",
874 val & 0x80 ? "LM79" : "LM78", (int)address);
875
876 release:
877 release_region(address, LM78_EXTENT);
878 return found;
879}
880
881static int __init lm78_isa_device_add(unsigned short address)
882{
883 struct resource res = {
884 .start = address,
885 .end = address + LM78_EXTENT,
886 .name = "lm78",
887 .flags = IORESOURCE_IO,
888 };
889 int err;
890
891 pdev = platform_device_alloc("lm78", address);
892 if (!pdev) {
893 err = -ENOMEM;
894 printk(KERN_ERR "lm78: Device allocation failed\n");
895 goto exit;
896 }
897
898 err = platform_device_add_resources(pdev, &res, 1);
899 if (err) {
900 printk(KERN_ERR "lm78: Device resource addition failed "
901 "(%d)\n", err);
902 goto exit_device_put;
903 }
904
905 err = platform_device_add(pdev);
906 if (err) {
907 printk(KERN_ERR "lm78: Device addition failed (%d)\n",
908 err);
909 goto exit_device_put;
910 }
911
912 return 0;
913
914 exit_device_put:
915 platform_device_put(pdev);
916 exit:
917 pdev = NULL;
918 return err;
919}
920
808static int __init sm_lm78_init(void) 921static int __init sm_lm78_init(void)
809{ 922{
810 int res; 923 int res;
811 924
812 res = i2c_add_driver(&lm78_driver); 925 res = i2c_add_driver(&lm78_driver);
813 if (res) 926 if (res)
814 return res; 927 goto exit;
815 928
816 /* Don't exit if this one fails, we still want the I2C variants 929 if (lm78_isa_found(isa_address)) {
817 to work! */ 930 res = platform_driver_register(&lm78_isa_driver);
818 if (i2c_isa_add_driver(&lm78_isa_driver)) 931 if (res)
819 isa_address = 0; 932 goto exit_unreg_i2c_driver;
933
934 /* Sets global pdev as a side effect */
935 res = lm78_isa_device_add(isa_address);
936 if (res)
937 goto exit_unreg_isa_driver;
938 }
820 939
821 return 0; 940 return 0;
941
942 exit_unreg_isa_driver:
943 platform_driver_unregister(&lm78_isa_driver);
944 exit_unreg_i2c_driver:
945 i2c_del_driver(&lm78_driver);
946 exit:
947 return res;
822} 948}
823 949
824static void __exit sm_lm78_exit(void) 950static void __exit sm_lm78_exit(void)
825{ 951{
826 if (isa_address) 952 if (pdev) {
827 i2c_isa_del_driver(&lm78_isa_driver); 953 platform_device_unregister(pdev);
954 platform_driver_unregister(&lm78_isa_driver);
955 }
828 i2c_del_driver(&lm78_driver); 956 i2c_del_driver(&lm78_driver);
829} 957}
830 958
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index 3ce825489e34..988ae1c4aada 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -747,6 +747,7 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
747 } 747 }
748 748
749 if (!(data->channel & CHAN_NO_VID)) { 749 if (!(data->channel & CHAN_NO_VID)) {
750 data->vrm = vid_which_vrm();
750 if ((err = device_create_file(&new_client->dev, 751 if ((err = device_create_file(&new_client->dev,
751 &dev_attr_cpu0_vid)) 752 &dev_attr_cpu0_vid))
752 || (err = device_create_file(&new_client->dev, 753 || (err = device_create_file(&new_client->dev,
@@ -779,7 +780,6 @@ static void lm87_init_client(struct i2c_client *client)
779 u8 config; 780 u8 config;
780 781
781 data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE); 782 data->channel = lm87_read_value(client, LM87_REG_CHANNEL_MODE);
782 data->vrm = vid_which_vrm();
783 783
784 config = lm87_read_value(client, LM87_REG_CONFIG); 784 config = lm87_read_value(client, LM87_REG_CONFIG);
785 if (!(config & 0x01)) { 785 if (!(config & 0x01)) {
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c
new file mode 100644
index 000000000000..8415664f33c2
--- /dev/null
+++ b/drivers/hwmon/max6650.c
@@ -0,0 +1,693 @@
1/*
2 * max6650.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring.
4 *
5 * (C) 2007 by Hans J. Koch <hjk@linutronix.de>
6 *
7 * based on code written by John Morris <john.morris@spirentcom.com>
8 * Copyright (c) 2003 Spirent Communications
9 * and Claus Gindhart <claus.gindhart@kontron.com>
10 *
11 * This module has only been tested with the MAX6650 chip. It should
12 * also work with the MAX6651. It does not distinguish max6650 and max6651
13 * chips.
14 *
15 * Tha datasheet was last seen at:
16 *
17 * http://pdfserv.maxim-ic.com/en/ds/MAX6650-MAX6651.pdf
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 */
33
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/slab.h>
37#include <linux/jiffies.h>
38#include <linux/i2c.h>
39#include <linux/hwmon.h>
40#include <linux/hwmon-sysfs.h>
41#include <linux/err.h>
42
43/*
44 * Addresses to scan. There are four disjoint possibilities, by pin config.
45 */
46
47static unsigned short normal_i2c[] = {0x1b, 0x1f, 0x48, 0x4b, I2C_CLIENT_END};
48
49/*
50 * Insmod parameters
51 */
52
53/* fan_voltage: 5=5V fan, 12=12V fan, 0=don't change */
54static int fan_voltage;
55/* prescaler: Possible values are 1, 2, 4, 8, 16 or 0 for don't change */
56static int prescaler;
57/* clock: The clock frequency of the chip the driver should assume */
58static int clock = 254000;
59
60module_param(fan_voltage, int, S_IRUGO);
61module_param(prescaler, int, S_IRUGO);
62module_param(clock, int, S_IRUGO);
63
64I2C_CLIENT_INSMOD_1(max6650);
65
66/*
67 * MAX 6650/6651 registers
68 */
69
70#define MAX6650_REG_SPEED 0x00
71#define MAX6650_REG_CONFIG 0x02
72#define MAX6650_REG_GPIO_DEF 0x04
73#define MAX6650_REG_DAC 0x06
74#define MAX6650_REG_ALARM_EN 0x08
75#define MAX6650_REG_ALARM 0x0A
76#define MAX6650_REG_TACH0 0x0C
77#define MAX6650_REG_TACH1 0x0E
78#define MAX6650_REG_TACH2 0x10
79#define MAX6650_REG_TACH3 0x12
80#define MAX6650_REG_GPIO_STAT 0x14
81#define MAX6650_REG_COUNT 0x16
82
83/*
84 * Config register bits
85 */
86
87#define MAX6650_CFG_V12 0x08
88#define MAX6650_CFG_PRESCALER_MASK 0x07
89#define MAX6650_CFG_PRESCALER_2 0x01
90#define MAX6650_CFG_PRESCALER_4 0x02
91#define MAX6650_CFG_PRESCALER_8 0x03
92#define MAX6650_CFG_PRESCALER_16 0x04
93#define MAX6650_CFG_MODE_MASK 0x30
94#define MAX6650_CFG_MODE_ON 0x00
95#define MAX6650_CFG_MODE_OFF 0x10
96#define MAX6650_CFG_MODE_CLOSED_LOOP 0x20
97#define MAX6650_CFG_MODE_OPEN_LOOP 0x30
98#define MAX6650_COUNT_MASK 0x03
99
100/* Minimum and maximum values of the FAN-RPM */
101#define FAN_RPM_MIN 240
102#define FAN_RPM_MAX 30000
103
104#define DIV_FROM_REG(reg) (1 << (reg & 7))
105
106static int max6650_attach_adapter(struct i2c_adapter *adapter);
107static int max6650_detect(struct i2c_adapter *adapter, int address, int kind);
108static int max6650_init_client(struct i2c_client *client);
109static int max6650_detach_client(struct i2c_client *client);
110static struct max6650_data *max6650_update_device(struct device *dev);
111
112/*
113 * Driver data (common to all clients)
114 */
115
116static struct i2c_driver max6650_driver = {
117 .driver = {
118 .name = "max6650",
119 },
120 .attach_adapter = max6650_attach_adapter,
121 .detach_client = max6650_detach_client,
122};
123
124/*
125 * Client data (each client gets its own)
126 */
127
128struct max6650_data
129{
130 struct i2c_client client;
131 struct class_device *class_dev;
132 struct mutex update_lock;
133 char valid; /* zero until following fields are valid */
134 unsigned long last_updated; /* in jiffies */
135
136 /* register values */
137 u8 speed;
138 u8 config;
139 u8 tach[4];
140 u8 count;
141 u8 dac;
142};
143
144static ssize_t get_fan(struct device *dev, struct device_attribute *devattr,
145 char *buf)
146{
147 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
148 struct max6650_data *data = max6650_update_device(dev);
149 int rpm;
150
151 /*
152 * Calculation details:
153 *
154 * Each tachometer counts over an interval given by the "count"
155 * register (0.25, 0.5, 1 or 2 seconds). This module assumes
156 * that the fans produce two pulses per revolution (this seems
157 * to be the most common).
158 */
159
160 rpm = ((data->tach[attr->index] * 120) / DIV_FROM_REG(data->count));
161 return sprintf(buf, "%d\n", rpm);
162}
163
164/*
165 * Set the fan speed to the specified RPM (or read back the RPM setting).
166 * This works in closed loop mode only. Use pwm1 for open loop speed setting.
167 *
168 * The MAX6650/1 will automatically control fan speed when in closed loop
169 * mode.
170 *
171 * Assumptions:
172 *
173 * 1) The MAX6650/1 internal 254kHz clock frequency is set correctly. Use
174 * the clock module parameter if you need to fine tune this.
175 *
176 * 2) The prescaler (low three bits of the config register) has already
177 * been set to an appropriate value. Use the prescaler module parameter
178 * if your BIOS doesn't initialize the chip properly.
179 *
180 * The relevant equations are given on pages 21 and 22 of the datasheet.
181 *
182 * From the datasheet, the relevant equation when in regulation is:
183 *
184 * [fCLK / (128 x (KTACH + 1))] = 2 x FanSpeed / KSCALE
185 *
186 * where:
187 *
188 * fCLK is the oscillator frequency (either the 254kHz internal
189 * oscillator or the externally applied clock)
190 *
191 * KTACH is the value in the speed register
192 *
193 * FanSpeed is the speed of the fan in rps
194 *
195 * KSCALE is the prescaler value (1, 2, 4, 8, or 16)
196 *
197 * When reading, we need to solve for FanSpeed. When writing, we need to
198 * solve for KTACH.
199 *
200 * Note: this tachometer is completely separate from the tachometers
201 * used to measure the fan speeds. Only one fan's speed (fan1) is
202 * controlled.
203 */
204
205static ssize_t get_target(struct device *dev, struct device_attribute *devattr,
206 char *buf)
207{
208 struct max6650_data *data = max6650_update_device(dev);
209 int kscale, ktach, rpm;
210
211 /*
212 * Use the datasheet equation:
213 *
214 * FanSpeed = KSCALE x fCLK / [256 x (KTACH + 1)]
215 *
216 * then multiply by 60 to give rpm.
217 */
218
219 kscale = DIV_FROM_REG(data->config);
220 ktach = data->speed;
221 rpm = 60 * kscale * clock / (256 * (ktach + 1));
222 return sprintf(buf, "%d\n", rpm);
223}
224
225static ssize_t set_target(struct device *dev, struct device_attribute *devattr,
226 const char *buf, size_t count)
227{
228 struct i2c_client *client = to_i2c_client(dev);
229 struct max6650_data *data = i2c_get_clientdata(client);
230 int rpm = simple_strtoul(buf, NULL, 10);
231 int kscale, ktach;
232
233 rpm = SENSORS_LIMIT(rpm, FAN_RPM_MIN, FAN_RPM_MAX);
234
235 /*
236 * Divide the required speed by 60 to get from rpm to rps, then
237 * use the datasheet equation:
238 *
239 * KTACH = [(fCLK x KSCALE) / (256 x FanSpeed)] - 1
240 */
241
242 mutex_lock(&data->update_lock);
243
244 kscale = DIV_FROM_REG(data->config);
245 ktach = ((clock * kscale) / (256 * rpm / 60)) - 1;
246 if (ktach < 0)
247 ktach = 0;
248 if (ktach > 255)
249 ktach = 255;
250 data->speed = ktach;
251
252 i2c_smbus_write_byte_data(client, MAX6650_REG_SPEED, data->speed);
253
254 mutex_unlock(&data->update_lock);
255
256 return count;
257}
258
259/*
260 * Get/set the fan speed in open loop mode using pwm1 sysfs file.
261 * Speed is given as a relative value from 0 to 255, where 255 is maximum
262 * speed. Note that this is done by writing directly to the chip's DAC,
263 * it won't change the closed loop speed set by fan1_target.
264 * Also note that due to rounding errors it is possible that you don't read
265 * back exactly the value you have set.
266 */
267
268static ssize_t get_pwm(struct device *dev, struct device_attribute *devattr,
269 char *buf)
270{
271 int pwm;
272 struct max6650_data *data = max6650_update_device(dev);
273
274 /* Useful range for dac is 0-180 for 12V fans and 0-76 for 5V fans.
275 Lower DAC values mean higher speeds. */
276 if (data->config & MAX6650_CFG_V12)
277 pwm = 255 - (255 * (int)data->dac)/180;
278 else
279 pwm = 255 - (255 * (int)data->dac)/76;
280
281 if (pwm < 0)
282 pwm = 0;
283
284 return sprintf(buf, "%d\n", pwm);
285}
286
287static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
288 const char *buf, size_t count)
289{
290 struct i2c_client *client = to_i2c_client(dev);
291 struct max6650_data *data = i2c_get_clientdata(client);
292 int pwm = simple_strtoul(buf, NULL, 10);
293
294 pwm = SENSORS_LIMIT(pwm, 0, 255);
295
296 mutex_lock(&data->update_lock);
297
298 if (data->config & MAX6650_CFG_V12)
299 data->dac = 180 - (180 * pwm)/255;
300 else
301 data->dac = 76 - (76 * pwm)/255;
302
303 i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, data->dac);
304
305 mutex_unlock(&data->update_lock);
306
307 return count;
308}
309
310/*
311 * Get/Set controller mode:
312 * Possible values:
313 * 0 = Fan always on
314 * 1 = Open loop, Voltage is set according to speed, not regulated.
315 * 2 = Closed loop, RPM for all fans regulated by fan1 tachometer
316 */
317
318static ssize_t get_enable(struct device *dev, struct device_attribute *devattr,
319 char *buf)
320{
321 struct max6650_data *data = max6650_update_device(dev);
322 int mode = (data->config & MAX6650_CFG_MODE_MASK) >> 4;
323 int sysfs_modes[4] = {0, 1, 2, 1};
324
325 return sprintf(buf, "%d\n", sysfs_modes[mode]);
326}
327
328static ssize_t set_enable(struct device *dev, struct device_attribute *devattr,
329 const char *buf, size_t count)
330{
331 struct i2c_client *client = to_i2c_client(dev);
332 struct max6650_data *data = i2c_get_clientdata(client);
333 int mode = simple_strtoul(buf, NULL, 10);
334 int max6650_modes[3] = {0, 3, 2};
335
336 if ((mode < 0)||(mode > 2)) {
337 dev_err(&client->dev,
338 "illegal value for pwm1_enable (%d)\n", mode);
339 return -EINVAL;
340 }
341
342 mutex_lock(&data->update_lock);
343
344 data->config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG);
345 data->config = (data->config & ~MAX6650_CFG_MODE_MASK)
346 | (max6650_modes[mode] << 4);
347
348 i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, data->config);
349
350 mutex_unlock(&data->update_lock);
351
352 return count;
353}
354
355/*
356 * Read/write functions for fan1_div sysfs file. The MAX6650 has no such
357 * divider. We handle this by converting between divider and counttime:
358 *
359 * (counttime == k) <==> (divider == 2^k), k = 0, 1, 2, or 3
360 *
361 * Lower values of k allow to connect a faster fan without the risk of
362 * counter overflow. The price is lower resolution. You can also set counttime
363 * using the module parameter. Note that the module parameter "prescaler" also
364 * influences the behaviour. Unfortunately, there's no sysfs attribute
365 * defined for that. See the data sheet for details.
366 */
367
368static ssize_t get_div(struct device *dev, struct device_attribute *devattr,
369 char *buf)
370{
371 struct max6650_data *data = max6650_update_device(dev);
372
373 return sprintf(buf, "%d\n", DIV_FROM_REG(data->count));
374}
375
376static ssize_t set_div(struct device *dev, struct device_attribute *devattr,
377 const char *buf, size_t count)
378{
379 struct i2c_client *client = to_i2c_client(dev);
380 struct max6650_data *data = i2c_get_clientdata(client);
381 int div = simple_strtoul(buf, NULL, 10);
382
383 mutex_lock(&data->update_lock);
384 switch (div) {
385 case 1:
386 data->count = 0;
387 break;
388 case 2:
389 data->count = 1;
390 break;
391 case 4:
392 data->count = 2;
393 break;
394 case 8:
395 data->count = 3;
396 break;
397 default:
398 dev_err(&client->dev,
399 "illegal value for fan divider (%d)\n", div);
400 return -EINVAL;
401 }
402
403 i2c_smbus_write_byte_data(client, MAX6650_REG_COUNT, data->count);
404 mutex_unlock(&data->update_lock);
405
406 return count;
407}
408
409static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, get_fan, NULL, 0);
410static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, get_fan, NULL, 1);
411static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, get_fan, NULL, 2);
412static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, get_fan, NULL, 3);
413static DEVICE_ATTR(fan1_target, S_IWUSR | S_IRUGO, get_target, set_target);
414static DEVICE_ATTR(fan1_div, S_IWUSR | S_IRUGO, get_div, set_div);
415static DEVICE_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, get_enable, set_enable);
416static DEVICE_ATTR(pwm1, S_IWUSR | S_IRUGO, get_pwm, set_pwm);
417
418
419static struct attribute *max6650_attrs[] = {
420 &sensor_dev_attr_fan1_input.dev_attr.attr,
421 &sensor_dev_attr_fan2_input.dev_attr.attr,
422 &sensor_dev_attr_fan3_input.dev_attr.attr,
423 &sensor_dev_attr_fan4_input.dev_attr.attr,
424 &dev_attr_fan1_target.attr,
425 &dev_attr_fan1_div.attr,
426 &dev_attr_pwm1_enable.attr,
427 &dev_attr_pwm1.attr,
428 NULL
429};
430
431static struct attribute_group max6650_attr_grp = {
432 .attrs = max6650_attrs,
433};
434
435/*
436 * Real code
437 */
438
439static int max6650_attach_adapter(struct i2c_adapter *adapter)
440{
441 if (!(adapter->class & I2C_CLASS_HWMON)) {
442 dev_dbg(&adapter->dev,
443 "FATAL: max6650_attach_adapter class HWMON not set\n");
444 return 0;
445 }
446
447 return i2c_probe(adapter, &addr_data, max6650_detect);
448}
449
450/*
451 * The following function does more than just detection. If detection
452 * succeeds, it also registers the new chip.
453 */
454
455static int max6650_detect(struct i2c_adapter *adapter, int address, int kind)
456{
457 struct i2c_client *client;
458 struct max6650_data *data;
459 int err = -ENODEV;
460
461 dev_dbg(&adapter->dev, "max6650_detect called, kind = %d\n", kind);
462
463 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
464 dev_dbg(&adapter->dev, "max6650: I2C bus doesn't support "
465 "byte read mode, skipping.\n");
466 return 0;
467 }
468
469 if (!(data = kzalloc(sizeof(struct max6650_data), GFP_KERNEL))) {
470 dev_err(&adapter->dev, "max6650: out of memory.\n");
471 return -ENOMEM;
472 }
473
474 client = &data->client;
475 i2c_set_clientdata(client, data);
476 client->addr = address;
477 client->adapter = adapter;
478 client->driver = &max6650_driver;
479
480 /*
481 * Now we do the remaining detection. A negative kind means that
482 * the driver was loaded with no force parameter (default), so we
483 * must both detect and identify the chip (actually there is only
484 * one possible kind of chip for now, max6650). A zero kind means that
485 * the driver was loaded with the force parameter, the detection
486 * step shall be skipped. A positive kind means that the driver
487 * was loaded with the force parameter and a given kind of chip is
488 * requested, so both the detection and the identification steps
489 * are skipped.
490 *
491 * Currently I can find no way to distinguish between a MAX6650 and
492 * a MAX6651. This driver has only been tried on the former.
493 */
494
495 if ((kind < 0) &&
496 ( (i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG) & 0xC0)
497 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_GPIO_STAT) & 0xE0)
498 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM_EN) & 0xE0)
499 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_ALARM) & 0xE0)
500 ||(i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT) & 0xFC))) {
501 dev_dbg(&adapter->dev,
502 "max6650: detection failed at 0x%02x.\n", address);
503 goto err_free;
504 }
505
506 dev_info(&adapter->dev, "max6650: chip found at 0x%02x.\n", address);
507
508 strlcpy(client->name, "max6650", I2C_NAME_SIZE);
509 mutex_init(&data->update_lock);
510
511 if ((err = i2c_attach_client(client))) {
512 dev_err(&adapter->dev, "max6650: failed to attach client.\n");
513 goto err_free;
514 }
515
516 /*
517 * Initialize the max6650 chip
518 */
519 if (max6650_init_client(client))
520 goto err_detach;
521
522 err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp);
523 if (err)
524 goto err_detach;
525
526 data->class_dev = hwmon_device_register(&client->dev);
527 if (!IS_ERR(data->class_dev))
528 return 0;
529
530 err = PTR_ERR(data->class_dev);
531 dev_err(&client->dev, "error registering hwmon device.\n");
532 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
533err_detach:
534 i2c_detach_client(client);
535err_free:
536 kfree(data);
537 return err;
538}
539
540static int max6650_detach_client(struct i2c_client *client)
541{
542 struct max6650_data *data = i2c_get_clientdata(client);
543 int err;
544
545 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
546 hwmon_device_unregister(data->class_dev);
547 err = i2c_detach_client(client);
548 if (!err)
549 kfree(data);
550 return err;
551}
552
553static int max6650_init_client(struct i2c_client *client)
554{
555 struct max6650_data *data = i2c_get_clientdata(client);
556 int config;
557 int err = -EIO;
558
559 config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG);
560
561 if (config < 0) {
562 dev_err(&client->dev, "Error reading config, aborting.\n");
563 return err;
564 }
565
566 switch (fan_voltage) {
567 case 0:
568 break;
569 case 5:
570 config &= ~MAX6650_CFG_V12;
571 break;
572 case 12:
573 config |= MAX6650_CFG_V12;
574 break;
575 default:
576 dev_err(&client->dev,
577 "illegal value for fan_voltage (%d)\n",
578 fan_voltage);
579 }
580
581 dev_info(&client->dev, "Fan voltage is set to %dV.\n",
582 (config & MAX6650_CFG_V12) ? 12 : 5);
583
584 switch (prescaler) {
585 case 0:
586 break;
587 case 1:
588 config &= ~MAX6650_CFG_PRESCALER_MASK;
589 break;
590 case 2:
591 config = (config & ~MAX6650_CFG_PRESCALER_MASK)
592 | MAX6650_CFG_PRESCALER_2;
593 break;
594 case 4:
595 config = (config & ~MAX6650_CFG_PRESCALER_MASK)
596 | MAX6650_CFG_PRESCALER_4;
597 break;
598 case 8:
599 config = (config & ~MAX6650_CFG_PRESCALER_MASK)
600 | MAX6650_CFG_PRESCALER_8;
601 break;
602 case 16:
603 config = (config & ~MAX6650_CFG_PRESCALER_MASK)
604 | MAX6650_CFG_PRESCALER_16;
605 break;
606 default:
607 dev_err(&client->dev,
608 "illegal value for prescaler (%d)\n",
609 prescaler);
610 }
611
612 dev_info(&client->dev, "Prescaler is set to %d.\n",
613 1 << (config & MAX6650_CFG_PRESCALER_MASK));
614
615 /* If mode is set to "full off", we change it to "open loop" and
616 * set DAC to 255, which has the same effect. We do this because
617 * there's no "full off" mode defined in hwmon specifcations.
618 */
619
620 if ((config & MAX6650_CFG_MODE_MASK) == MAX6650_CFG_MODE_OFF) {
621 dev_dbg(&client->dev, "Change mode to open loop, full off.\n");
622 config = (config & ~MAX6650_CFG_MODE_MASK)
623 | MAX6650_CFG_MODE_OPEN_LOOP;
624 if (i2c_smbus_write_byte_data(client, MAX6650_REG_DAC, 255)) {
625 dev_err(&client->dev, "DAC write error, aborting.\n");
626 return err;
627 }
628 }
629
630 if (i2c_smbus_write_byte_data(client, MAX6650_REG_CONFIG, config)) {
631 dev_err(&client->dev, "Config write error, aborting.\n");
632 return err;
633 }
634
635 data->config = config;
636 data->count = i2c_smbus_read_byte_data(client, MAX6650_REG_COUNT);
637
638 return 0;
639}
640
641static const u8 tach_reg[] = {
642 MAX6650_REG_TACH0,
643 MAX6650_REG_TACH1,
644 MAX6650_REG_TACH2,
645 MAX6650_REG_TACH3,
646};
647
648static struct max6650_data *max6650_update_device(struct device *dev)
649{
650 int i;
651 struct i2c_client *client = to_i2c_client(dev);
652 struct max6650_data *data = i2c_get_clientdata(client);
653
654 mutex_lock(&data->update_lock);
655
656 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
657 data->speed = i2c_smbus_read_byte_data(client,
658 MAX6650_REG_SPEED);
659 data->config = i2c_smbus_read_byte_data(client,
660 MAX6650_REG_CONFIG);
661 for (i = 0; i < 4; i++) {
662 data->tach[i] = i2c_smbus_read_byte_data(client,
663 tach_reg[i]);
664 }
665 data->count = i2c_smbus_read_byte_data(client,
666 MAX6650_REG_COUNT);
667 data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC);
668
669 data->last_updated = jiffies;
670 data->valid = 1;
671 }
672
673 mutex_unlock(&data->update_lock);
674
675 return data;
676}
677
678static int __init sensors_max6650_init(void)
679{
680 return i2c_add_driver(&max6650_driver);
681}
682
683static void __exit sensors_max6650_exit(void)
684{
685 i2c_del_driver(&max6650_driver);
686}
687
688MODULE_AUTHOR("Hans J. Koch");
689MODULE_DESCRIPTION("MAX6650 sensor driver");
690MODULE_LICENSE("GPL");
691
692module_init(sensors_max6650_init);
693module_exit(sensors_max6650_exit);
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
index affa21a5ccfd..29354fa26f81 100644
--- a/drivers/hwmon/pc87427.c
+++ b/drivers/hwmon/pc87427.c
@@ -31,6 +31,7 @@
31#include <linux/err.h> 31#include <linux/err.h>
32#include <linux/mutex.h> 32#include <linux/mutex.h>
33#include <linux/sysfs.h> 33#include <linux/sysfs.h>
34#include <linux/ioport.h>
34#include <asm/io.h> 35#include <asm/io.h>
35 36
36static struct platform_device *pdev; 37static struct platform_device *pdev;
@@ -429,6 +430,12 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
429 /* This will need to be revisited when we add support for 430 /* This will need to be revisited when we add support for
430 temperature and voltage monitoring. */ 431 temperature and voltage monitoring. */
431 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 432 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
433 if (!request_region(res->start, res->end - res->start + 1, DRVNAME)) {
434 err = -EBUSY;
435 dev_err(&pdev->dev, "Failed to request region 0x%lx-0x%lx\n",
436 (unsigned long)res->start, (unsigned long)res->end);
437 goto exit_kfree;
438 }
432 data->address[0] = res->start; 439 data->address[0] = res->start;
433 440
434 mutex_init(&data->lock); 441 mutex_init(&data->lock);
@@ -438,7 +445,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
438 445
439 /* Register sysfs hooks */ 446 /* Register sysfs hooks */
440 if ((err = device_create_file(&pdev->dev, &dev_attr_name))) 447 if ((err = device_create_file(&pdev->dev, &dev_attr_name)))
441 goto exit_kfree; 448 goto exit_release_region;
442 for (i = 0; i < 8; i++) { 449 for (i = 0; i < 8; i++) {
443 if (!(data->fan_enabled & (1 << i))) 450 if (!(data->fan_enabled & (1 << i)))
444 continue; 451 continue;
@@ -462,6 +469,8 @@ exit_remove_files:
462 continue; 469 continue;
463 sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]); 470 sysfs_remove_group(&pdev->dev.kobj, &pc87427_group_fan[i]);
464 } 471 }
472exit_release_region:
473 release_region(res->start, res->end - res->start + 1);
465exit_kfree: 474exit_kfree:
466 platform_set_drvdata(pdev, NULL); 475 platform_set_drvdata(pdev, NULL);
467 kfree(data); 476 kfree(data);
@@ -472,6 +481,7 @@ exit:
472static int __devexit pc87427_remove(struct platform_device *pdev) 481static int __devexit pc87427_remove(struct platform_device *pdev)
473{ 482{
474 struct pc87427_data *data = platform_get_drvdata(pdev); 483 struct pc87427_data *data = platform_get_drvdata(pdev);
484 struct resource *res;
475 int i; 485 int i;
476 486
477 platform_set_drvdata(pdev, NULL); 487 platform_set_drvdata(pdev, NULL);
@@ -484,6 +494,9 @@ static int __devexit pc87427_remove(struct platform_device *pdev)
484 } 494 }
485 kfree(data); 495 kfree(data);
486 496
497 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
498 release_region(res->start, res->end - res->start + 1);
499
487 return 0; 500 return 0;
488} 501}
489 502
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index 72b0e2d8650c..943abbd95ab5 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -30,16 +30,17 @@
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/ioport.h> 31#include <linux/ioport.h>
32#include <linux/jiffies.h> 32#include <linux/jiffies.h>
33#include <linux/i2c.h> 33#include <linux/platform_device.h>
34#include <linux/i2c-isa.h>
35#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/hwmon-sysfs.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 <linux/mutex.h>
39#include <asm/io.h> 39#include <asm/io.h>
40 40
41/* Address is autodetected, there is no default value */ 41static struct platform_device *pdev;
42static unsigned short address; 42
43#define DRVNAME "smsc47b397"
43 44
44/* Super-I/0 registers and commands */ 45/* Super-I/0 registers and commands */
45 46
@@ -91,7 +92,8 @@ static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80};
91#define SMSC47B397_REG_FAN_MSB(nr) (0x29 + 2 * (nr)) 92#define SMSC47B397_REG_FAN_MSB(nr) (0x29 + 2 * (nr))
92 93
93struct smsc47b397_data { 94struct smsc47b397_data {
94 struct i2c_client client; 95 unsigned short addr;
96 const char *name;
95 struct class_device *class_dev; 97 struct class_device *class_dev;
96 struct mutex lock; 98 struct mutex lock;
97 99
@@ -104,45 +106,43 @@ struct smsc47b397_data {
104 u8 temp[4]; 106 u8 temp[4];
105}; 107};
106 108
107static int smsc47b397_read_value(struct i2c_client *client, u8 reg) 109static int smsc47b397_read_value(struct smsc47b397_data* data, u8 reg)
108{ 110{
109 struct smsc47b397_data *data = i2c_get_clientdata(client);
110 int res; 111 int res;
111 112
112 mutex_lock(&data->lock); 113 mutex_lock(&data->lock);
113 outb(reg, client->addr); 114 outb(reg, data->addr);
114 res = inb_p(client->addr + 1); 115 res = inb_p(data->addr + 1);
115 mutex_unlock(&data->lock); 116 mutex_unlock(&data->lock);
116 return res; 117 return res;
117} 118}
118 119
119static struct smsc47b397_data *smsc47b397_update_device(struct device *dev) 120static struct smsc47b397_data *smsc47b397_update_device(struct device *dev)
120{ 121{
121 struct i2c_client *client = to_i2c_client(dev); 122 struct smsc47b397_data *data = dev_get_drvdata(dev);
122 struct smsc47b397_data *data = i2c_get_clientdata(client);
123 int i; 123 int i;
124 124
125 mutex_lock(&data->update_lock); 125 mutex_lock(&data->update_lock);
126 126
127 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 127 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
128 dev_dbg(&client->dev, "starting device update...\n"); 128 dev_dbg(dev, "starting device update...\n");
129 129
130 /* 4 temperature inputs, 4 fan inputs */ 130 /* 4 temperature inputs, 4 fan inputs */
131 for (i = 0; i < 4; i++) { 131 for (i = 0; i < 4; i++) {
132 data->temp[i] = smsc47b397_read_value(client, 132 data->temp[i] = smsc47b397_read_value(data,
133 SMSC47B397_REG_TEMP(i)); 133 SMSC47B397_REG_TEMP(i));
134 134
135 /* must read LSB first */ 135 /* must read LSB first */
136 data->fan[i] = smsc47b397_read_value(client, 136 data->fan[i] = smsc47b397_read_value(data,
137 SMSC47B397_REG_FAN_LSB(i)); 137 SMSC47B397_REG_FAN_LSB(i));
138 data->fan[i] |= smsc47b397_read_value(client, 138 data->fan[i] |= smsc47b397_read_value(data,
139 SMSC47B397_REG_FAN_MSB(i)) << 8; 139 SMSC47B397_REG_FAN_MSB(i)) << 8;
140 } 140 }
141 141
142 data->last_updated = jiffies; 142 data->last_updated = jiffies;
143 data->valid = 1; 143 data->valid = 1;
144 144
145 dev_dbg(&client->dev, "... device update complete\n"); 145 dev_dbg(dev, "... device update complete\n");
146 } 146 }
147 147
148 mutex_unlock(&data->update_lock); 148 mutex_unlock(&data->update_lock);
@@ -157,24 +157,18 @@ static int temp_from_reg(u8 reg)
157 return (s8)reg * 1000; 157 return (s8)reg * 1000;
158} 158}
159 159
160/* 0 <= nr <= 3 */ 160static ssize_t show_temp(struct device *dev, struct device_attribute
161static ssize_t show_temp(struct device *dev, char *buf, int nr) 161 *devattr, char *buf)
162{ 162{
163 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
163 struct smsc47b397_data *data = smsc47b397_update_device(dev); 164 struct smsc47b397_data *data = smsc47b397_update_device(dev);
164 return sprintf(buf, "%d\n", temp_from_reg(data->temp[nr])); 165 return sprintf(buf, "%d\n", temp_from_reg(data->temp[attr->index]));
165} 166}
166 167
167#define sysfs_temp(num) \ 168static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
168static ssize_t show_temp##num(struct device *dev, struct device_attribute *attr, char *buf) \ 169static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
169{ \ 170static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
170 return show_temp(dev, buf, num-1); \ 171static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3);
171} \
172static DEVICE_ATTR(temp##num##_input, S_IRUGO, show_temp##num, NULL)
173
174sysfs_temp(1);
175sysfs_temp(2);
176sysfs_temp(3);
177sysfs_temp(4);
178 172
179/* FAN: 1 RPM/bit 173/* FAN: 1 RPM/bit
180 REG: count of 90kHz pulses / revolution */ 174 REG: count of 90kHz pulses / revolution */
@@ -183,35 +177,37 @@ static int fan_from_reg(u16 reg)
183 return 90000 * 60 / reg; 177 return 90000 * 60 / reg;
184} 178}
185 179
186/* 0 <= nr <= 3 */ 180static ssize_t show_fan(struct device *dev, struct device_attribute
187static ssize_t show_fan(struct device *dev, char *buf, int nr) 181 *devattr, char *buf)
188{ 182{
189 struct smsc47b397_data *data = smsc47b397_update_device(dev); 183 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
190 return sprintf(buf, "%d\n", fan_from_reg(data->fan[nr])); 184 struct smsc47b397_data *data = smsc47b397_update_device(dev);
185 return sprintf(buf, "%d\n", fan_from_reg(data->fan[attr->index]));
191} 186}
187static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
188static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
189static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
190static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
192 191
193#define sysfs_fan(num) \ 192static ssize_t show_name(struct device *dev, struct device_attribute
194static ssize_t show_fan##num(struct device *dev, struct device_attribute *attr, char *buf) \ 193 *devattr, char *buf)
195{ \ 194{
196 return show_fan(dev, buf, num-1); \ 195 struct smsc47b397_data *data = dev_get_drvdata(dev);
197} \ 196 return sprintf(buf, "%s\n", data->name);
198static DEVICE_ATTR(fan##num##_input, S_IRUGO, show_fan##num, NULL) 197}
199 198static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
200sysfs_fan(1);
201sysfs_fan(2);
202sysfs_fan(3);
203sysfs_fan(4);
204 199
205static struct attribute *smsc47b397_attributes[] = { 200static struct attribute *smsc47b397_attributes[] = {
206 &dev_attr_temp1_input.attr, 201 &sensor_dev_attr_temp1_input.dev_attr.attr,
207 &dev_attr_temp2_input.attr, 202 &sensor_dev_attr_temp2_input.dev_attr.attr,
208 &dev_attr_temp3_input.attr, 203 &sensor_dev_attr_temp3_input.dev_attr.attr,
209 &dev_attr_temp4_input.attr, 204 &sensor_dev_attr_temp4_input.dev_attr.attr,
210 &dev_attr_fan1_input.attr, 205 &sensor_dev_attr_fan1_input.dev_attr.attr,
211 &dev_attr_fan2_input.attr, 206 &sensor_dev_attr_fan2_input.dev_attr.attr,
212 &dev_attr_fan3_input.attr, 207 &sensor_dev_attr_fan3_input.dev_attr.attr,
213 &dev_attr_fan4_input.attr, 208 &sensor_dev_attr_fan4_input.dev_attr.attr,
214 209
210 &dev_attr_name.attr,
215 NULL 211 NULL
216}; 212};
217 213
@@ -219,44 +215,44 @@ static const struct attribute_group smsc47b397_group = {
219 .attrs = smsc47b397_attributes, 215 .attrs = smsc47b397_attributes,
220}; 216};
221 217
222static int smsc47b397_detach_client(struct i2c_client *client) 218static int __devexit smsc47b397_remove(struct platform_device *pdev)
223{ 219{
224 struct smsc47b397_data *data = i2c_get_clientdata(client); 220 struct smsc47b397_data *data = platform_get_drvdata(pdev);
225 int err; 221 struct resource *res;
226 222
227 hwmon_device_unregister(data->class_dev); 223 hwmon_device_unregister(data->class_dev);
228 sysfs_remove_group(&client->dev.kobj, &smsc47b397_group); 224 sysfs_remove_group(&pdev->dev.kobj, &smsc47b397_group);
229 225 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
230 if ((err = i2c_detach_client(client))) 226 release_region(res->start, SMSC_EXTENT);
231 return err;
232
233 release_region(client->addr, SMSC_EXTENT);
234 kfree(data); 227 kfree(data);
235 228
236 return 0; 229 return 0;
237} 230}
238 231
239static int smsc47b397_detect(struct i2c_adapter *adapter); 232static int smsc47b397_probe(struct platform_device *pdev);
240 233
241static struct i2c_driver smsc47b397_driver = { 234static struct platform_driver smsc47b397_driver = {
242 .driver = { 235 .driver = {
243 .owner = THIS_MODULE, 236 .owner = THIS_MODULE,
244 .name = "smsc47b397", 237 .name = DRVNAME,
245 }, 238 },
246 .attach_adapter = smsc47b397_detect, 239 .probe = smsc47b397_probe,
247 .detach_client = smsc47b397_detach_client, 240 .remove = __devexit_p(smsc47b397_remove),
248}; 241};
249 242
250static int smsc47b397_detect(struct i2c_adapter *adapter) 243static int __devinit smsc47b397_probe(struct platform_device *pdev)
251{ 244{
252 struct i2c_client *new_client; 245 struct device *dev = &pdev->dev;
253 struct smsc47b397_data *data; 246 struct smsc47b397_data *data;
247 struct resource *res;
254 int err = 0; 248 int err = 0;
255 249
256 if (!request_region(address, SMSC_EXTENT, 250 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
251 if (!request_region(res->start, SMSC_EXTENT,
257 smsc47b397_driver.driver.name)) { 252 smsc47b397_driver.driver.name)) {
258 dev_err(&adapter->dev, "Region 0x%x already in use!\n", 253 dev_err(dev, "Region 0x%lx-0x%lx already in use!\n",
259 address); 254 (unsigned long)res->start,
255 (unsigned long)res->start + SMSC_EXTENT - 1);
260 return -EBUSY; 256 return -EBUSY;
261 } 257 }
262 258
@@ -265,25 +261,16 @@ static int smsc47b397_detect(struct i2c_adapter *adapter)
265 goto error_release; 261 goto error_release;
266 } 262 }
267 263
268 new_client = &data->client; 264 data->addr = res->start;
269 i2c_set_clientdata(new_client, data); 265 data->name = "smsc47b397";
270 new_client->addr = address;
271 mutex_init(&data->lock); 266 mutex_init(&data->lock);
272 new_client->adapter = adapter;
273 new_client->driver = &smsc47b397_driver;
274 new_client->flags = 0;
275
276 strlcpy(new_client->name, "smsc47b397", I2C_NAME_SIZE);
277
278 mutex_init(&data->update_lock); 267 mutex_init(&data->update_lock);
268 platform_set_drvdata(pdev, data);
279 269
280 if ((err = i2c_attach_client(new_client))) 270 if ((err = sysfs_create_group(&dev->kobj, &smsc47b397_group)))
281 goto error_free; 271 goto error_free;
282 272
283 if ((err = sysfs_create_group(&new_client->dev.kobj, &smsc47b397_group))) 273 data->class_dev = hwmon_device_register(dev);
284 goto error_detach;
285
286 data->class_dev = hwmon_device_register(&new_client->dev);
287 if (IS_ERR(data->class_dev)) { 274 if (IS_ERR(data->class_dev)) {
288 err = PTR_ERR(data->class_dev); 275 err = PTR_ERR(data->class_dev);
289 goto error_remove; 276 goto error_remove;
@@ -292,13 +279,50 @@ static int smsc47b397_detect(struct i2c_adapter *adapter)
292 return 0; 279 return 0;
293 280
294error_remove: 281error_remove:
295 sysfs_remove_group(&new_client->dev.kobj, &smsc47b397_group); 282 sysfs_remove_group(&dev->kobj, &smsc47b397_group);
296error_detach:
297 i2c_detach_client(new_client);
298error_free: 283error_free:
299 kfree(data); 284 kfree(data);
300error_release: 285error_release:
301 release_region(address, SMSC_EXTENT); 286 release_region(res->start, SMSC_EXTENT);
287 return err;
288}
289
290static int __init smsc47b397_device_add(unsigned short address)
291{
292 struct resource res = {
293 .start = address,
294 .end = address + SMSC_EXTENT - 1,
295 .name = DRVNAME,
296 .flags = IORESOURCE_IO,
297 };
298 int err;
299
300 pdev = platform_device_alloc(DRVNAME, address);
301 if (!pdev) {
302 err = -ENOMEM;
303 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
304 goto exit;
305 }
306
307 err = platform_device_add_resources(pdev, &res, 1);
308 if (err) {
309 printk(KERN_ERR DRVNAME ": Device resource addition failed "
310 "(%d)\n", err);
311 goto exit_device_put;
312 }
313
314 err = platform_device_add(pdev);
315 if (err) {
316 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
317 err);
318 goto exit_device_put;
319 }
320
321 return 0;
322
323exit_device_put:
324 platform_device_put(pdev);
325exit:
302 return err; 326 return err;
303} 327}
304 328
@@ -320,7 +344,7 @@ static int __init smsc47b397_find(unsigned short *addr)
320 *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8) 344 *addr = (superio_inb(SUPERIO_REG_BASE_MSB) << 8)
321 | superio_inb(SUPERIO_REG_BASE_LSB); 345 | superio_inb(SUPERIO_REG_BASE_LSB);
322 346
323 printk(KERN_INFO "smsc47b397: found SMSC %s " 347 printk(KERN_INFO DRVNAME ": found SMSC %s "
324 "(base address 0x%04x, revision %u)\n", 348 "(base address 0x%04x, revision %u)\n",
325 id == 0x81 ? "SCH5307-NS" : "LPC47B397-NC", *addr, rev); 349 id == 0x81 ? "SCH5307-NS" : "LPC47B397-NC", *addr, rev);
326 350
@@ -330,17 +354,33 @@ static int __init smsc47b397_find(unsigned short *addr)
330 354
331static int __init smsc47b397_init(void) 355static int __init smsc47b397_init(void)
332{ 356{
357 unsigned short address;
333 int ret; 358 int ret;
334 359
335 if ((ret = smsc47b397_find(&address))) 360 if ((ret = smsc47b397_find(&address)))
336 return ret; 361 return ret;
337 362
338 return i2c_isa_add_driver(&smsc47b397_driver); 363 ret = platform_driver_register(&smsc47b397_driver);
364 if (ret)
365 goto exit;
366
367 /* Sets global pdev as a side effect */
368 ret = smsc47b397_device_add(address);
369 if (ret)
370 goto exit_driver;
371
372 return 0;
373
374exit_driver:
375 platform_driver_unregister(&smsc47b397_driver);
376exit:
377 return ret;
339} 378}
340 379
341static void __exit smsc47b397_exit(void) 380static void __exit smsc47b397_exit(void)
342{ 381{
343 i2c_isa_del_driver(&smsc47b397_driver); 382 platform_device_unregister(pdev);
383 platform_driver_unregister(&smsc47b397_driver);
344} 384}
345 385
346MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); 386MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>");
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c
index beb881c4b2e8..1e21c8cc948f 100644
--- a/drivers/hwmon/smsc47m1.c
+++ b/drivers/hwmon/smsc47m1.c
@@ -3,10 +3,11 @@
3 for hardware monitoring 3 for hardware monitoring
4 4
5 Supports the SMSC LPC47B27x, LPC47M10x, LPC47M112, LPC47M13x, 5 Supports the SMSC LPC47B27x, LPC47M10x, LPC47M112, LPC47M13x,
6 LPC47M14x, LPC47M15x, LPC47M192 and LPC47M997 Super-I/O chips. 6 LPC47M14x, LPC47M15x, LPC47M192, LPC47M292 and LPC47M997
7 Super-I/O chips.
7 8
8 Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> 9 Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
9 Copyright (C) 2004 Jean Delvare <khali@linux-fr.org> 10 Copyright (C) 2004-2007 Jean Delvare <khali@linux-fr.org>
10 Ported to Linux 2.6 by Gabriele Gorla <gorlik@yahoo.com> 11 Ported to Linux 2.6 by Gabriele Gorla <gorlik@yahoo.com>
11 and Jean Delvare 12 and Jean Delvare
12 13
@@ -29,17 +30,19 @@
29#include <linux/slab.h> 30#include <linux/slab.h>
30#include <linux/ioport.h> 31#include <linux/ioport.h>
31#include <linux/jiffies.h> 32#include <linux/jiffies.h>
32#include <linux/i2c.h> 33#include <linux/platform_device.h>
33#include <linux/i2c-isa.h>
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/hwmon-sysfs.h>
35#include <linux/err.h> 36#include <linux/err.h>
36#include <linux/init.h> 37#include <linux/init.h>
37#include <linux/mutex.h> 38#include <linux/mutex.h>
38#include <linux/sysfs.h> 39#include <linux/sysfs.h>
39#include <asm/io.h> 40#include <asm/io.h>
40 41
41/* Address is autodetected, there is no default value */ 42static struct platform_device *pdev;
42static unsigned short address; 43
44#define DRVNAME "smsc47m1"
45enum chips { smsc47m1, smsc47m2 };
43 46
44/* Super-I/0 registers and commands */ 47/* Super-I/0 registers and commands */
45 48
@@ -87,10 +90,18 @@ superio_exit(void)
87#define SMSC47M1_REG_ALARM 0x04 90#define SMSC47M1_REG_ALARM 0x04
88#define SMSC47M1_REG_TPIN(nr) (0x34 - (nr)) 91#define SMSC47M1_REG_TPIN(nr) (0x34 - (nr))
89#define SMSC47M1_REG_PPIN(nr) (0x36 - (nr)) 92#define SMSC47M1_REG_PPIN(nr) (0x36 - (nr))
90#define SMSC47M1_REG_PWM(nr) (0x56 + (nr))
91#define SMSC47M1_REG_FANDIV 0x58 93#define SMSC47M1_REG_FANDIV 0x58
92#define SMSC47M1_REG_FAN(nr) (0x59 + (nr)) 94
93#define SMSC47M1_REG_FAN_PRELOAD(nr) (0x5B + (nr)) 95static const u8 SMSC47M1_REG_FAN[3] = { 0x59, 0x5a, 0x6b };
96static const u8 SMSC47M1_REG_FAN_PRELOAD[3] = { 0x5b, 0x5c, 0x6c };
97static const u8 SMSC47M1_REG_PWM[3] = { 0x56, 0x57, 0x69 };
98
99#define SMSC47M2_REG_ALARM6 0x09
100#define SMSC47M2_REG_TPIN1 0x38
101#define SMSC47M2_REG_TPIN2 0x37
102#define SMSC47M2_REG_TPIN3 0x2d
103#define SMSC47M2_REG_PPIN3 0x2c
104#define SMSC47M2_REG_FANDIV3 0x6a
94 105
95#define MIN_FROM_REG(reg,div) ((reg)>=192 ? 0 : \ 106#define MIN_FROM_REG(reg,div) ((reg)>=192 ? 0 : \
96 983040/((192-(reg))*(div))) 107 983040/((192-(reg))*(div)))
@@ -102,45 +113,57 @@ superio_exit(void)
102#define PWM_TO_REG(reg) (((reg) >> 1) & 0x7E) 113#define PWM_TO_REG(reg) (((reg) >> 1) & 0x7E)
103 114
104struct smsc47m1_data { 115struct smsc47m1_data {
105 struct i2c_client client; 116 unsigned short addr;
117 const char *name;
118 enum chips type;
106 struct class_device *class_dev; 119 struct class_device *class_dev;
107 struct mutex lock;
108 120
109 struct mutex update_lock; 121 struct mutex update_lock;
110 unsigned long last_updated; /* In jiffies */ 122 unsigned long last_updated; /* In jiffies */
111 123
112 u8 fan[2]; /* Register value */ 124 u8 fan[3]; /* Register value */
113 u8 fan_preload[2]; /* Register value */ 125 u8 fan_preload[3]; /* Register value */
114 u8 fan_div[2]; /* Register encoding, shifted right */ 126 u8 fan_div[3]; /* Register encoding, shifted right */
115 u8 alarms; /* Register encoding */ 127 u8 alarms; /* Register encoding */
116 u8 pwm[2]; /* Register value (bit 7 is enable) */ 128 u8 pwm[3]; /* Register value (bit 0 is disable) */
117}; 129};
118 130
131struct smsc47m1_sio_data {
132 enum chips type;
133};
119 134
120static int smsc47m1_detect(struct i2c_adapter *adapter);
121static int smsc47m1_detach_client(struct i2c_client *client);
122
123static int smsc47m1_read_value(struct i2c_client *client, u8 reg);
124static void smsc47m1_write_value(struct i2c_client *client, u8 reg, u8 value);
125 135
136static int smsc47m1_probe(struct platform_device *pdev);
137static int smsc47m1_remove(struct platform_device *pdev);
126static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, 138static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
127 int init); 139 int init);
128 140
141static inline int smsc47m1_read_value(struct smsc47m1_data *data, u8 reg)
142{
143 return inb_p(data->addr + reg);
144}
129 145
130static struct i2c_driver smsc47m1_driver = { 146static inline void smsc47m1_write_value(struct smsc47m1_data *data, u8 reg,
147 u8 value)
148{
149 outb_p(value, data->addr + reg);
150}
151
152static struct platform_driver smsc47m1_driver = {
131 .driver = { 153 .driver = {
132 .owner = THIS_MODULE, 154 .owner = THIS_MODULE,
133 .name = "smsc47m1", 155 .name = DRVNAME,
134 }, 156 },
135 .attach_adapter = smsc47m1_detect, 157 .probe = smsc47m1_probe,
136 .detach_client = smsc47m1_detach_client, 158 .remove = __devexit_p(smsc47m1_remove),
137}; 159};
138 160
139/* nr is 0 or 1 in the callback functions below */ 161static ssize_t get_fan(struct device *dev, struct device_attribute
140 162 *devattr, char *buf)
141static ssize_t get_fan(struct device *dev, char *buf, int nr)
142{ 163{
164 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
143 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0); 165 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
166 int nr = attr->index;
144 /* This chip (stupidly) stops monitoring fan speed if PWM is 167 /* This chip (stupidly) stops monitoring fan speed if PWM is
145 enabled and duty cycle is 0%. This is fine if the monitoring 168 enabled and duty cycle is 0%. This is fine if the monitoring
146 and control concern the same fan, but troublesome if they are 169 and control concern the same fan, but troublesome if they are
@@ -152,43 +175,54 @@ static ssize_t get_fan(struct device *dev, char *buf, int nr)
152 return sprintf(buf, "%d\n", rpm); 175 return sprintf(buf, "%d\n", rpm);
153} 176}
154 177
155static ssize_t get_fan_min(struct device *dev, char *buf, int nr) 178static ssize_t get_fan_min(struct device *dev, struct device_attribute
179 *devattr, char *buf)
156{ 180{
181 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
157 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0); 182 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
183 int nr = attr->index;
158 int rpm = MIN_FROM_REG(data->fan_preload[nr], 184 int rpm = MIN_FROM_REG(data->fan_preload[nr],
159 DIV_FROM_REG(data->fan_div[nr])); 185 DIV_FROM_REG(data->fan_div[nr]));
160 return sprintf(buf, "%d\n", rpm); 186 return sprintf(buf, "%d\n", rpm);
161} 187}
162 188
163static ssize_t get_fan_div(struct device *dev, char *buf, int nr) 189static ssize_t get_fan_div(struct device *dev, struct device_attribute
190 *devattr, char *buf)
164{ 191{
192 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
165 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0); 193 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
166 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); 194 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[attr->index]));
167} 195}
168 196
169static ssize_t get_pwm(struct device *dev, char *buf, int nr) 197static ssize_t get_pwm(struct device *dev, struct device_attribute
198 *devattr, char *buf)
170{ 199{
200 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
171 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0); 201 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
172 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[nr])); 202 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm[attr->index]));
173} 203}
174 204
175static ssize_t get_pwm_en(struct device *dev, char *buf, int nr) 205static ssize_t get_pwm_en(struct device *dev, struct device_attribute
206 *devattr, char *buf)
176{ 207{
208 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
177 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0); 209 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
178 return sprintf(buf, "%d\n", PWM_EN_FROM_REG(data->pwm[nr])); 210 return sprintf(buf, "%d\n", PWM_EN_FROM_REG(data->pwm[attr->index]));
179} 211}
180 212
181static ssize_t get_alarms(struct device *dev, struct device_attribute *attr, char *buf) 213static ssize_t get_alarms(struct device *dev, struct device_attribute
214 *devattr, char *buf)
182{ 215{
183 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0); 216 struct smsc47m1_data *data = smsc47m1_update_device(dev, 0);
184 return sprintf(buf, "%d\n", data->alarms); 217 return sprintf(buf, "%d\n", data->alarms);
185} 218}
186 219
187static ssize_t set_fan_min(struct device *dev, const char *buf, 220static ssize_t set_fan_min(struct device *dev, struct device_attribute
188 size_t count, int nr) 221 *devattr, const char *buf, size_t count)
189{ 222{
190 struct i2c_client *client = to_i2c_client(dev); 223 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
191 struct smsc47m1_data *data = i2c_get_clientdata(client); 224 struct smsc47m1_data *data = dev_get_drvdata(dev);
225 int nr = attr->index;
192 long rpmdiv, val = simple_strtol(buf, NULL, 10); 226 long rpmdiv, val = simple_strtol(buf, NULL, 10);
193 227
194 mutex_lock(&data->update_lock); 228 mutex_lock(&data->update_lock);
@@ -200,7 +234,7 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
200 } 234 }
201 235
202 data->fan_preload[nr] = 192 - ((983040 + rpmdiv / 2) / rpmdiv); 236 data->fan_preload[nr] = 192 - ((983040 + rpmdiv / 2) / rpmdiv);
203 smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr), 237 smsc47m1_write_value(data, SMSC47M1_REG_FAN_PRELOAD[nr],
204 data->fan_preload[nr]); 238 data->fan_preload[nr]);
205 mutex_unlock(&data->update_lock); 239 mutex_unlock(&data->update_lock);
206 240
@@ -211,12 +245,12 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
211 determined in part by the fan clock divider. This follows the principle 245 determined in part by the fan clock divider. This follows the principle
212 of least surprise; the user doesn't expect the fan minimum to change just 246 of least surprise; the user doesn't expect the fan minimum to change just
213 because the divider changed. */ 247 because the divider changed. */
214static ssize_t set_fan_div(struct device *dev, const char *buf, 248static ssize_t set_fan_div(struct device *dev, struct device_attribute
215 size_t count, int nr) 249 *devattr, const char *buf, size_t count)
216{ 250{
217 struct i2c_client *client = to_i2c_client(dev); 251 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
218 struct smsc47m1_data *data = i2c_get_clientdata(client); 252 struct smsc47m1_data *data = dev_get_drvdata(dev);
219 253 int nr = attr->index;
220 long new_div = simple_strtol(buf, NULL, 10), tmp; 254 long new_div = simple_strtol(buf, NULL, 10), tmp;
221 u8 old_div = DIV_FROM_REG(data->fan_div[nr]); 255 u8 old_div = DIV_FROM_REG(data->fan_div[nr]);
222 256
@@ -234,27 +268,38 @@ static ssize_t set_fan_div(struct device *dev, const char *buf,
234 return -EINVAL; 268 return -EINVAL;
235 } 269 }
236 270
237 tmp = smsc47m1_read_value(client, SMSC47M1_REG_FANDIV) & 0x0F; 271 switch (nr) {
238 tmp |= (data->fan_div[0] << 4) | (data->fan_div[1] << 6); 272 case 0:
239 smsc47m1_write_value(client, SMSC47M1_REG_FANDIV, tmp); 273 case 1:
274 tmp = smsc47m1_read_value(data, SMSC47M1_REG_FANDIV)
275 & ~(0x03 << (4 + 2 * nr));
276 tmp |= data->fan_div[nr] << (4 + 2 * nr);
277 smsc47m1_write_value(data, SMSC47M1_REG_FANDIV, tmp);
278 break;
279 case 2:
280 tmp = smsc47m1_read_value(data, SMSC47M2_REG_FANDIV3) & 0xCF;
281 tmp |= data->fan_div[2] << 4;
282 smsc47m1_write_value(data, SMSC47M2_REG_FANDIV3, tmp);
283 break;
284 }
240 285
241 /* Preserve fan min */ 286 /* Preserve fan min */
242 tmp = 192 - (old_div * (192 - data->fan_preload[nr]) 287 tmp = 192 - (old_div * (192 - data->fan_preload[nr])
243 + new_div / 2) / new_div; 288 + new_div / 2) / new_div;
244 data->fan_preload[nr] = SENSORS_LIMIT(tmp, 0, 191); 289 data->fan_preload[nr] = SENSORS_LIMIT(tmp, 0, 191);
245 smsc47m1_write_value(client, SMSC47M1_REG_FAN_PRELOAD(nr), 290 smsc47m1_write_value(data, SMSC47M1_REG_FAN_PRELOAD[nr],
246 data->fan_preload[nr]); 291 data->fan_preload[nr]);
247 mutex_unlock(&data->update_lock); 292 mutex_unlock(&data->update_lock);
248 293
249 return count; 294 return count;
250} 295}
251 296
252static ssize_t set_pwm(struct device *dev, const char *buf, 297static ssize_t set_pwm(struct device *dev, struct device_attribute
253 size_t count, int nr) 298 *devattr, const char *buf, size_t count)
254{ 299{
255 struct i2c_client *client = to_i2c_client(dev); 300 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
256 struct smsc47m1_data *data = i2c_get_clientdata(client); 301 struct smsc47m1_data *data = dev_get_drvdata(dev);
257 302 int nr = attr->index;
258 long val = simple_strtol(buf, NULL, 10); 303 long val = simple_strtol(buf, NULL, 10);
259 304
260 if (val < 0 || val > 255) 305 if (val < 0 || val > 255)
@@ -263,19 +308,19 @@ static ssize_t set_pwm(struct device *dev, const char *buf,
263 mutex_lock(&data->update_lock); 308 mutex_lock(&data->update_lock);
264 data->pwm[nr] &= 0x81; /* Preserve additional bits */ 309 data->pwm[nr] &= 0x81; /* Preserve additional bits */
265 data->pwm[nr] |= PWM_TO_REG(val); 310 data->pwm[nr] |= PWM_TO_REG(val);
266 smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr), 311 smsc47m1_write_value(data, SMSC47M1_REG_PWM[nr],
267 data->pwm[nr]); 312 data->pwm[nr]);
268 mutex_unlock(&data->update_lock); 313 mutex_unlock(&data->update_lock);
269 314
270 return count; 315 return count;
271} 316}
272 317
273static ssize_t set_pwm_en(struct device *dev, const char *buf, 318static ssize_t set_pwm_en(struct device *dev, struct device_attribute
274 size_t count, int nr) 319 *devattr, const char *buf, size_t count)
275{ 320{
276 struct i2c_client *client = to_i2c_client(dev); 321 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
277 struct smsc47m1_data *data = i2c_get_clientdata(client); 322 struct smsc47m1_data *data = dev_get_drvdata(dev);
278 323 int nr = attr->index;
279 long val = simple_strtol(buf, NULL, 10); 324 long val = simple_strtol(buf, NULL, 10);
280 325
281 if (val != 0 && val != 1) 326 if (val != 0 && val != 1)
@@ -284,7 +329,7 @@ static ssize_t set_pwm_en(struct device *dev, const char *buf,
284 mutex_lock(&data->update_lock); 329 mutex_lock(&data->update_lock);
285 data->pwm[nr] &= 0xFE; /* preserve the other bits */ 330 data->pwm[nr] &= 0xFE; /* preserve the other bits */
286 data->pwm[nr] |= !val; 331 data->pwm[nr] |= !val;
287 smsc47m1_write_value(client, SMSC47M1_REG_PWM(nr), 332 smsc47m1_write_value(data, SMSC47M1_REG_PWM[nr],
288 data->pwm[nr]); 333 data->pwm[nr]);
289 mutex_unlock(&data->update_lock); 334 mutex_unlock(&data->update_lock);
290 335
@@ -292,79 +337,55 @@ static ssize_t set_pwm_en(struct device *dev, const char *buf,
292} 337}
293 338
294#define fan_present(offset) \ 339#define fan_present(offset) \
295static ssize_t get_fan##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 340static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, get_fan, \
296{ \ 341 NULL, offset - 1); \
297 return get_fan(dev, buf, offset - 1); \ 342static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
298} \ 343 get_fan_min, set_fan_min, offset - 1); \
299static ssize_t get_fan##offset##_min (struct device *dev, struct device_attribute *attr, char *buf) \ 344static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
300{ \ 345 get_fan_div, set_fan_div, offset - 1); \
301 return get_fan_min(dev, buf, offset - 1); \ 346static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
302} \ 347 get_pwm, set_pwm, offset - 1); \
303static ssize_t set_fan##offset##_min (struct device *dev, struct device_attribute *attr, \ 348static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
304 const char *buf, size_t count) \ 349 get_pwm_en, set_pwm_en, offset - 1)
305{ \
306 return set_fan_min(dev, buf, count, offset - 1); \
307} \
308static ssize_t get_fan##offset##_div (struct device *dev, struct device_attribute *attr, char *buf) \
309{ \
310 return get_fan_div(dev, buf, offset - 1); \
311} \
312static ssize_t set_fan##offset##_div (struct device *dev, struct device_attribute *attr, \
313 const char *buf, size_t count) \
314{ \
315 return set_fan_div(dev, buf, count, offset - 1); \
316} \
317static ssize_t get_pwm##offset (struct device *dev, struct device_attribute *attr, char *buf) \
318{ \
319 return get_pwm(dev, buf, offset - 1); \
320} \
321static ssize_t set_pwm##offset (struct device *dev, struct device_attribute *attr, \
322 const char *buf, size_t count) \
323{ \
324 return set_pwm(dev, buf, count, offset - 1); \
325} \
326static ssize_t get_pwm##offset##_en (struct device *dev, struct device_attribute *attr, char *buf) \
327{ \
328 return get_pwm_en(dev, buf, offset - 1); \
329} \
330static ssize_t set_pwm##offset##_en (struct device *dev, struct device_attribute *attr, \
331 const char *buf, size_t count) \
332{ \
333 return set_pwm_en(dev, buf, count, offset - 1); \
334} \
335static DEVICE_ATTR(fan##offset##_input, S_IRUGO, get_fan##offset, \
336 NULL); \
337static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
338 get_fan##offset##_min, set_fan##offset##_min); \
339static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
340 get_fan##offset##_div, set_fan##offset##_div); \
341static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
342 get_pwm##offset, set_pwm##offset); \
343static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
344 get_pwm##offset##_en, set_pwm##offset##_en);
345 350
346fan_present(1); 351fan_present(1);
347fan_present(2); 352fan_present(2);
353fan_present(3);
348 354
349static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL); 355static DEVICE_ATTR(alarms, S_IRUGO, get_alarms, NULL);
350 356
357static ssize_t show_name(struct device *dev, struct device_attribute
358 *devattr, char *buf)
359{
360 struct smsc47m1_data *data = dev_get_drvdata(dev);
361
362 return sprintf(buf, "%s\n", data->name);
363}
364static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
365
351/* Almost all sysfs files may or may not be created depending on the chip 366/* Almost all sysfs files may or may not be created depending on the chip
352 setup so we create them individually. It is still convenient to define a 367 setup so we create them individually. It is still convenient to define a
353 group to remove them all at once. */ 368 group to remove them all at once. */
354static struct attribute *smsc47m1_attributes[] = { 369static struct attribute *smsc47m1_attributes[] = {
355 &dev_attr_fan1_input.attr, 370 &sensor_dev_attr_fan1_input.dev_attr.attr,
356 &dev_attr_fan1_min.attr, 371 &sensor_dev_attr_fan1_min.dev_attr.attr,
357 &dev_attr_fan1_div.attr, 372 &sensor_dev_attr_fan1_div.dev_attr.attr,
358 &dev_attr_fan2_input.attr, 373 &sensor_dev_attr_fan2_input.dev_attr.attr,
359 &dev_attr_fan2_min.attr, 374 &sensor_dev_attr_fan2_min.dev_attr.attr,
360 &dev_attr_fan2_div.attr, 375 &sensor_dev_attr_fan2_div.dev_attr.attr,
361 376 &sensor_dev_attr_fan3_input.dev_attr.attr,
362 &dev_attr_pwm1.attr, 377 &sensor_dev_attr_fan3_min.dev_attr.attr,
363 &dev_attr_pwm1_enable.attr, 378 &sensor_dev_attr_fan3_div.dev_attr.attr,
364 &dev_attr_pwm2.attr, 379
365 &dev_attr_pwm2_enable.attr, 380 &sensor_dev_attr_pwm1.dev_attr.attr,
381 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
382 &sensor_dev_attr_pwm2.dev_attr.attr,
383 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
384 &sensor_dev_attr_pwm3.dev_attr.attr,
385 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
366 386
367 &dev_attr_alarms.attr, 387 &dev_attr_alarms.attr,
388 &dev_attr_name.attr,
368 NULL 389 NULL
369}; 390};
370 391
@@ -372,7 +393,8 @@ static const struct attribute_group smsc47m1_group = {
372 .attrs = smsc47m1_attributes, 393 .attrs = smsc47m1_attributes,
373}; 394};
374 395
375static int __init smsc47m1_find(unsigned short *addr) 396static int __init smsc47m1_find(unsigned short *addr,
397 struct smsc47m1_sio_data *sio_data)
376{ 398{
377 u8 val; 399 u8 val;
378 400
@@ -386,18 +408,32 @@ static int __init smsc47m1_find(unsigned short *addr)
386 * can do much more besides (device id 0x60). 408 * can do much more besides (device id 0x60).
387 * The LPC47M997 is undocumented, but seems to be compatible with 409 * The LPC47M997 is undocumented, but seems to be compatible with
388 * the LPC47M192, and has the same device id. 410 * the LPC47M192, and has the same device id.
411 * The LPC47M292 (device id 0x6B) is somewhat compatible, but it
412 * supports a 3rd fan, and the pin configuration registers are
413 * unfortunately different.
389 */ 414 */
390 if (val == 0x51) 415 switch (val) {
391 printk(KERN_INFO "smsc47m1: Found SMSC LPC47B27x\n"); 416 case 0x51:
392 else if (val == 0x59) 417 pr_info(DRVNAME ": Found SMSC LPC47B27x\n");
393 printk(KERN_INFO "smsc47m1: Found SMSC " 418 sio_data->type = smsc47m1;
394 "LPC47M10x/LPC47M112/LPC47M13x\n"); 419 break;
395 else if (val == 0x5F) 420 case 0x59:
396 printk(KERN_INFO "smsc47m1: Found SMSC LPC47M14x\n"); 421 pr_info(DRVNAME ": Found SMSC LPC47M10x/LPC47M112/LPC47M13x\n");
397 else if (val == 0x60) 422 sio_data->type = smsc47m1;
398 printk(KERN_INFO "smsc47m1: Found SMSC " 423 break;
399 "LPC47M15x/LPC47M192/LPC47M997\n"); 424 case 0x5F:
400 else { 425 pr_info(DRVNAME ": Found SMSC LPC47M14x\n");
426 sio_data->type = smsc47m1;
427 break;
428 case 0x60:
429 pr_info(DRVNAME ": Found SMSC LPC47M15x/LPC47M192/LPC47M997\n");
430 sio_data->type = smsc47m1;
431 break;
432 case 0x6B:
433 pr_info(DRVNAME ": Found SMSC LPC47M292\n");
434 sio_data->type = smsc47m2;
435 break;
436 default:
401 superio_exit(); 437 superio_exit();
402 return -ENODEV; 438 return -ENODEV;
403 } 439 }
@@ -407,7 +443,7 @@ static int __init smsc47m1_find(unsigned short *addr)
407 | superio_inb(SUPERIO_REG_BASE + 1); 443 | superio_inb(SUPERIO_REG_BASE + 1);
408 val = superio_inb(SUPERIO_REG_ACT); 444 val = superio_inb(SUPERIO_REG_ACT);
409 if (*addr == 0 || (val & 0x01) == 0) { 445 if (*addr == 0 || (val & 0x01) == 0) {
410 printk(KERN_INFO "smsc47m1: Device is disabled, will not use\n"); 446 pr_info(DRVNAME ": Device is disabled, will not use\n");
411 superio_exit(); 447 superio_exit();
412 return -ENODEV; 448 return -ENODEV;
413 } 449 }
@@ -416,15 +452,25 @@ static int __init smsc47m1_find(unsigned short *addr)
416 return 0; 452 return 0;
417} 453}
418 454
419static int smsc47m1_detect(struct i2c_adapter *adapter) 455static int __devinit smsc47m1_probe(struct platform_device *pdev)
420{ 456{
421 struct i2c_client *new_client; 457 struct device *dev = &pdev->dev;
458 struct smsc47m1_sio_data *sio_data = dev->platform_data;
422 struct smsc47m1_data *data; 459 struct smsc47m1_data *data;
460 struct resource *res;
423 int err = 0; 461 int err = 0;
424 int fan1, fan2, pwm1, pwm2; 462 int fan1, fan2, fan3, pwm1, pwm2, pwm3;
425 463
426 if (!request_region(address, SMSC_EXTENT, smsc47m1_driver.driver.name)) { 464 static const char *names[] = {
427 dev_err(&adapter->dev, "Region 0x%x already in use!\n", address); 465 "smsc47m1",
466 "smsc47m2",
467 };
468
469 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
470 if (!request_region(res->start, SMSC_EXTENT, DRVNAME)) {
471 dev_err(dev, "Region 0x%lx-0x%lx already in use!\n",
472 (unsigned long)res->start,
473 (unsigned long)res->end);
428 return -EBUSY; 474 return -EBUSY;
429 } 475 }
430 476
@@ -433,93 +479,114 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
433 goto error_release; 479 goto error_release;
434 } 480 }
435 481
436 new_client = &data->client; 482 data->addr = res->start;
437 i2c_set_clientdata(new_client, data); 483 data->type = sio_data->type;
438 new_client->addr = address; 484 data->name = names[sio_data->type];
439 mutex_init(&data->lock);
440 new_client->adapter = adapter;
441 new_client->driver = &smsc47m1_driver;
442 new_client->flags = 0;
443
444 strlcpy(new_client->name, "smsc47m1", I2C_NAME_SIZE);
445 mutex_init(&data->update_lock); 485 mutex_init(&data->update_lock);
486 platform_set_drvdata(pdev, data);
446 487
447 /* If no function is properly configured, there's no point in 488 /* If no function is properly configured, there's no point in
448 actually registering the chip. */ 489 actually registering the chip. */
449 fan1 = (smsc47m1_read_value(new_client, SMSC47M1_REG_TPIN(0)) & 0x05) 490 pwm1 = (smsc47m1_read_value(data, SMSC47M1_REG_PPIN(0)) & 0x05)
450 == 0x05;
451 fan2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_TPIN(1)) & 0x05)
452 == 0x05;
453 pwm1 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(0)) & 0x05)
454 == 0x04; 491 == 0x04;
455 pwm2 = (smsc47m1_read_value(new_client, SMSC47M1_REG_PPIN(1)) & 0x05) 492 pwm2 = (smsc47m1_read_value(data, SMSC47M1_REG_PPIN(1)) & 0x05)
456 == 0x04; 493 == 0x04;
457 if (!(fan1 || fan2 || pwm1 || pwm2)) { 494 if (data->type == smsc47m2) {
458 dev_warn(&adapter->dev, "Device at 0x%x is not configured, " 495 fan1 = (smsc47m1_read_value(data, SMSC47M2_REG_TPIN1)
459 "will not use\n", new_client->addr); 496 & 0x0d) == 0x09;
497 fan2 = (smsc47m1_read_value(data, SMSC47M2_REG_TPIN2)
498 & 0x0d) == 0x09;
499 fan3 = (smsc47m1_read_value(data, SMSC47M2_REG_TPIN3)
500 & 0x0d) == 0x0d;
501 pwm3 = (smsc47m1_read_value(data, SMSC47M2_REG_PPIN3)
502 & 0x0d) == 0x08;
503 } else {
504 fan1 = (smsc47m1_read_value(data, SMSC47M1_REG_TPIN(0))
505 & 0x05) == 0x05;
506 fan2 = (smsc47m1_read_value(data, SMSC47M1_REG_TPIN(1))
507 & 0x05) == 0x05;
508 fan3 = 0;
509 pwm3 = 0;
510 }
511 if (!(fan1 || fan2 || fan3 || pwm1 || pwm2 || pwm3)) {
512 dev_warn(dev, "Device not configured, will not use\n");
460 err = -ENODEV; 513 err = -ENODEV;
461 goto error_free; 514 goto error_free;
462 } 515 }
463 516
464 if ((err = i2c_attach_client(new_client)))
465 goto error_free;
466
467 /* Some values (fan min, clock dividers, pwm registers) may be 517 /* Some values (fan min, clock dividers, pwm registers) may be
468 needed before any update is triggered, so we better read them 518 needed before any update is triggered, so we better read them
469 at least once here. We don't usually do it that way, but in 519 at least once here. We don't usually do it that way, but in
470 this particular case, manually reading 5 registers out of 8 520 this particular case, manually reading 5 registers out of 8
471 doesn't make much sense and we're better using the existing 521 doesn't make much sense and we're better using the existing
472 function. */ 522 function. */
473 smsc47m1_update_device(&new_client->dev, 1); 523 smsc47m1_update_device(dev, 1);
474 524
475 /* Register sysfs hooks */ 525 /* Register sysfs hooks */
476 if (fan1) { 526 if (fan1) {
477 if ((err = device_create_file(&new_client->dev, 527 if ((err = device_create_file(dev,
478 &dev_attr_fan1_input)) 528 &sensor_dev_attr_fan1_input.dev_attr))
479 || (err = device_create_file(&new_client->dev, 529 || (err = device_create_file(dev,
480 &dev_attr_fan1_min)) 530 &sensor_dev_attr_fan1_min.dev_attr))
481 || (err = device_create_file(&new_client->dev, 531 || (err = device_create_file(dev,
482 &dev_attr_fan1_div))) 532 &sensor_dev_attr_fan1_div.dev_attr)))
483 goto error_remove_files; 533 goto error_remove_files;
484 } else 534 } else
485 dev_dbg(&new_client->dev, "Fan 1 not enabled by hardware, " 535 dev_dbg(dev, "Fan 1 not enabled by hardware, skipping\n");
486 "skipping\n");
487 536
488 if (fan2) { 537 if (fan2) {
489 if ((err = device_create_file(&new_client->dev, 538 if ((err = device_create_file(dev,
490 &dev_attr_fan2_input)) 539 &sensor_dev_attr_fan2_input.dev_attr))
491 || (err = device_create_file(&new_client->dev, 540 || (err = device_create_file(dev,
492 &dev_attr_fan2_min)) 541 &sensor_dev_attr_fan2_min.dev_attr))
493 || (err = device_create_file(&new_client->dev, 542 || (err = device_create_file(dev,
494 &dev_attr_fan2_div))) 543 &sensor_dev_attr_fan2_div.dev_attr)))
495 goto error_remove_files; 544 goto error_remove_files;
496 } else 545 } else
497 dev_dbg(&new_client->dev, "Fan 2 not enabled by hardware, " 546 dev_dbg(dev, "Fan 2 not enabled by hardware, skipping\n");
498 "skipping\n"); 547
548 if (fan3) {
549 if ((err = device_create_file(dev,
550 &sensor_dev_attr_fan3_input.dev_attr))
551 || (err = device_create_file(dev,
552 &sensor_dev_attr_fan3_min.dev_attr))
553 || (err = device_create_file(dev,
554 &sensor_dev_attr_fan3_div.dev_attr)))
555 goto error_remove_files;
556 } else
557 dev_dbg(dev, "Fan 3 not enabled by hardware, skipping\n");
499 558
500 if (pwm1) { 559 if (pwm1) {
501 if ((err = device_create_file(&new_client->dev, 560 if ((err = device_create_file(dev,
502 &dev_attr_pwm1)) 561 &sensor_dev_attr_pwm1.dev_attr))
503 || (err = device_create_file(&new_client->dev, 562 || (err = device_create_file(dev,
504 &dev_attr_pwm1_enable))) 563 &sensor_dev_attr_pwm1_enable.dev_attr)))
505 goto error_remove_files; 564 goto error_remove_files;
506 } else 565 } else
507 dev_dbg(&new_client->dev, "PWM 1 not enabled by hardware, " 566 dev_dbg(dev, "PWM 1 not enabled by hardware, skipping\n");
508 "skipping\n"); 567
509 if (pwm2) { 568 if (pwm2) {
510 if ((err = device_create_file(&new_client->dev, 569 if ((err = device_create_file(dev,
511 &dev_attr_pwm2)) 570 &sensor_dev_attr_pwm2.dev_attr))
512 || (err = device_create_file(&new_client->dev, 571 || (err = device_create_file(dev,
513 &dev_attr_pwm2_enable))) 572 &sensor_dev_attr_pwm2_enable.dev_attr)))
573 goto error_remove_files;
574 } else
575 dev_dbg(dev, "PWM 2 not enabled by hardware, skipping\n");
576
577 if (pwm3) {
578 if ((err = device_create_file(dev,
579 &sensor_dev_attr_pwm3.dev_attr))
580 || (err = device_create_file(dev,
581 &sensor_dev_attr_pwm3_enable.dev_attr)))
514 goto error_remove_files; 582 goto error_remove_files;
515 } else 583 } else
516 dev_dbg(&new_client->dev, "PWM 2 not enabled by hardware, " 584 dev_dbg(dev, "PWM 3 not enabled by hardware, skipping\n");
517 "skipping\n");
518 585
519 if ((err = device_create_file(&new_client->dev, &dev_attr_alarms))) 586 if ((err = device_create_file(dev, &dev_attr_alarms)))
520 goto error_remove_files; 587 goto error_remove_files;
521 588
522 data->class_dev = hwmon_device_register(&new_client->dev); 589 data->class_dev = hwmon_device_register(dev);
523 if (IS_ERR(data->class_dev)) { 590 if (IS_ERR(data->class_dev)) {
524 err = PTR_ERR(data->class_dev); 591 err = PTR_ERR(data->class_dev);
525 goto error_remove_files; 592 goto error_remove_files;
@@ -528,78 +595,71 @@ static int smsc47m1_detect(struct i2c_adapter *adapter)
528 return 0; 595 return 0;
529 596
530error_remove_files: 597error_remove_files:
531 sysfs_remove_group(&new_client->dev.kobj, &smsc47m1_group); 598 sysfs_remove_group(&dev->kobj, &smsc47m1_group);
532 i2c_detach_client(new_client);
533error_free: 599error_free:
534 kfree(data); 600 kfree(data);
535error_release: 601error_release:
536 release_region(address, SMSC_EXTENT); 602 release_region(res->start, SMSC_EXTENT);
537 return err; 603 return err;
538} 604}
539 605
540static int smsc47m1_detach_client(struct i2c_client *client) 606static int __devexit smsc47m1_remove(struct platform_device *pdev)
541{ 607{
542 struct smsc47m1_data *data = i2c_get_clientdata(client); 608 struct smsc47m1_data *data = platform_get_drvdata(pdev);
543 int err; 609 struct resource *res;
544 610
611 platform_set_drvdata(pdev, NULL);
545 hwmon_device_unregister(data->class_dev); 612 hwmon_device_unregister(data->class_dev);
546 sysfs_remove_group(&client->dev.kobj, &smsc47m1_group); 613 sysfs_remove_group(&pdev->dev.kobj, &smsc47m1_group);
547
548 if ((err = i2c_detach_client(client)))
549 return err;
550 614
551 release_region(client->addr, SMSC_EXTENT); 615 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
616 release_region(res->start, SMSC_EXTENT);
552 kfree(data); 617 kfree(data);
553 618
554 return 0; 619 return 0;
555} 620}
556 621
557static int smsc47m1_read_value(struct i2c_client *client, u8 reg)
558{
559 int res;
560
561 mutex_lock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
562 res = inb_p(client->addr + reg);
563 mutex_unlock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
564 return res;
565}
566
567static void smsc47m1_write_value(struct i2c_client *client, u8 reg, u8 value)
568{
569 mutex_lock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
570 outb_p(value, client->addr + reg);
571 mutex_unlock(&((struct smsc47m1_data *) i2c_get_clientdata(client))->lock);
572}
573
574static struct smsc47m1_data *smsc47m1_update_device(struct device *dev, 622static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
575 int init) 623 int init)
576{ 624{
577 struct i2c_client *client = to_i2c_client(dev); 625 struct smsc47m1_data *data = dev_get_drvdata(dev);
578 struct smsc47m1_data *data = i2c_get_clientdata(client);
579 626
580 mutex_lock(&data->update_lock); 627 mutex_lock(&data->update_lock);
581 628
582 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) { 629 if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || init) {
583 int i; 630 int i, fan_nr;
584 631 fan_nr = data->type == smsc47m2 ? 3 : 2;
585 for (i = 0; i < 2; i++) { 632
586 data->fan[i] = smsc47m1_read_value(client, 633 for (i = 0; i < fan_nr; i++) {
587 SMSC47M1_REG_FAN(i)); 634 data->fan[i] = smsc47m1_read_value(data,
588 data->fan_preload[i] = smsc47m1_read_value(client, 635 SMSC47M1_REG_FAN[i]);
589 SMSC47M1_REG_FAN_PRELOAD(i)); 636 data->fan_preload[i] = smsc47m1_read_value(data,
590 data->pwm[i] = smsc47m1_read_value(client, 637 SMSC47M1_REG_FAN_PRELOAD[i]);
591 SMSC47M1_REG_PWM(i)); 638 data->pwm[i] = smsc47m1_read_value(data,
639 SMSC47M1_REG_PWM[i]);
592 } 640 }
593 641
594 i = smsc47m1_read_value(client, SMSC47M1_REG_FANDIV); 642 i = smsc47m1_read_value(data, SMSC47M1_REG_FANDIV);
595 data->fan_div[0] = (i >> 4) & 0x03; 643 data->fan_div[0] = (i >> 4) & 0x03;
596 data->fan_div[1] = i >> 6; 644 data->fan_div[1] = i >> 6;
597 645
598 data->alarms = smsc47m1_read_value(client, 646 data->alarms = smsc47m1_read_value(data,
599 SMSC47M1_REG_ALARM) >> 6; 647 SMSC47M1_REG_ALARM) >> 6;
600 /* Clear alarms if needed */ 648 /* Clear alarms if needed */
601 if (data->alarms) 649 if (data->alarms)
602 smsc47m1_write_value(client, SMSC47M1_REG_ALARM, 0xC0); 650 smsc47m1_write_value(data, SMSC47M1_REG_ALARM, 0xC0);
651
652 if (fan_nr >= 3) {
653 data->fan_div[2] = (smsc47m1_read_value(data,
654 SMSC47M2_REG_FANDIV3) >> 4) & 0x03;
655 data->alarms |= (smsc47m1_read_value(data,
656 SMSC47M2_REG_ALARM6) & 0x40) >> 4;
657 /* Clear alarm if needed */
658 if (data->alarms & 0x04)
659 smsc47m1_write_value(data,
660 SMSC47M2_REG_ALARM6,
661 0x40);
662 }
603 663
604 data->last_updated = jiffies; 664 data->last_updated = jiffies;
605 } 665 }
@@ -608,18 +668,86 @@ static struct smsc47m1_data *smsc47m1_update_device(struct device *dev,
608 return data; 668 return data;
609} 669}
610 670
671static int __init smsc47m1_device_add(unsigned short address,
672 const struct smsc47m1_sio_data *sio_data)
673{
674 struct resource res = {
675 .start = address,
676 .end = address + SMSC_EXTENT - 1,
677 .name = DRVNAME,
678 .flags = IORESOURCE_IO,
679 };
680 int err;
681
682 pdev = platform_device_alloc(DRVNAME, address);
683 if (!pdev) {
684 err = -ENOMEM;
685 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
686 goto exit;
687 }
688
689 err = platform_device_add_resources(pdev, &res, 1);
690 if (err) {
691 printk(KERN_ERR DRVNAME ": Device resource addition failed "
692 "(%d)\n", err);
693 goto exit_device_put;
694 }
695
696 pdev->dev.platform_data = kmalloc(sizeof(struct smsc47m1_sio_data),
697 GFP_KERNEL);
698 if (!pdev->dev.platform_data) {
699 err = -ENOMEM;
700 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
701 goto exit_device_put;
702 }
703 memcpy(pdev->dev.platform_data, sio_data,
704 sizeof(struct smsc47m1_sio_data));
705
706 err = platform_device_add(pdev);
707 if (err) {
708 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
709 err);
710 goto exit_device_put;
711 }
712
713 return 0;
714
715exit_device_put:
716 platform_device_put(pdev);
717exit:
718 return err;
719}
720
611static int __init sm_smsc47m1_init(void) 721static int __init sm_smsc47m1_init(void)
612{ 722{
613 if (smsc47m1_find(&address)) { 723 int err;
724 unsigned short address;
725 struct smsc47m1_sio_data sio_data;
726
727 if (smsc47m1_find(&address, &sio_data))
614 return -ENODEV; 728 return -ENODEV;
615 }
616 729
617 return i2c_isa_add_driver(&smsc47m1_driver); 730 err = platform_driver_register(&smsc47m1_driver);
731 if (err)
732 goto exit;
733
734 /* Sets global pdev as a side effect */
735 err = smsc47m1_device_add(address, &sio_data);
736 if (err)
737 goto exit_driver;
738
739 return 0;
740
741exit_driver:
742 platform_driver_unregister(&smsc47m1_driver);
743exit:
744 return err;
618} 745}
619 746
620static void __exit sm_smsc47m1_exit(void) 747static void __exit sm_smsc47m1_exit(void)
621{ 748{
622 i2c_isa_del_driver(&smsc47m1_driver); 749 platform_device_unregister(pdev);
750 platform_driver_unregister(&smsc47m1_driver);
623} 751}
624 752
625MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>"); 753MODULE_AUTHOR("Mark D. Studebaker <mdsxyz123@yahoo.com>");
diff --git a/drivers/hwmon/smsc47m192.c b/drivers/hwmon/smsc47m192.c
index a6833f437395..a012f396f354 100644
--- a/drivers/hwmon/smsc47m192.c
+++ b/drivers/hwmon/smsc47m192.c
@@ -1,6 +1,6 @@
1/* 1/*
2 smsc47m192.c - Support for hardware monitoring block of 2 smsc47m192.c - Support for hardware monitoring block of
3 SMSC LPC47M192 and LPC47M997 Super I/O chips 3 SMSC LPC47M192 and compatible Super I/O chips
4 4
5 Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de> 5 Copyright (C) 2006 Hartmut Rick <linux@rick.claranet.de>
6 6
@@ -518,7 +518,7 @@ static int smsc47m192_detect(struct i2c_adapter *adapter, int address,
518 && (i2c_smbus_read_byte_data(client, 518 && (i2c_smbus_read_byte_data(client,
519 SMSC47M192_REG_VID4) & 0xfe) == 0x80) { 519 SMSC47M192_REG_VID4) & 0xfe) == 0x80) {
520 dev_info(&adapter->dev, 520 dev_info(&adapter->dev,
521 "found SMSC47M192 or SMSC47M997, " 521 "found SMSC47M192 or compatible, "
522 "version 2, stepping A%d\n", version & 0x0f); 522 "version 2, stepping A%d\n", version & 0x0f);
523 } else { 523 } else {
524 dev_dbg(&adapter->dev, 524 dev_dbg(&adapter->dev,
diff --git a/drivers/hwmon/vt1211.c b/drivers/hwmon/vt1211.c
index 89c23d6add7b..9f3e332c5b7f 100644
--- a/drivers/hwmon/vt1211.c
+++ b/drivers/hwmon/vt1211.c
@@ -31,6 +31,7 @@
31#include <linux/hwmon-vid.h> 31#include <linux/hwmon-vid.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/mutex.h> 33#include <linux/mutex.h>
34#include <linux/ioport.h>
34#include <asm/io.h> 35#include <asm/io.h>
35 36
36static int uch_config = -1; 37static int uch_config = -1;
@@ -1130,6 +1131,12 @@ static int __devinit vt1211_probe(struct platform_device *pdev)
1130 } 1131 }
1131 1132
1132 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 1133 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1134 if (!request_region(res->start, res->end - res->start + 1, DRVNAME)) {
1135 err = -EBUSY;
1136 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
1137 (unsigned long)res->start, (unsigned long)res->end);
1138 goto EXIT_KFREE;
1139 }
1133 data->addr = res->start; 1140 data->addr = res->start;
1134 data->name = DRVNAME; 1141 data->name = DRVNAME;
1135 mutex_init(&data->update_lock); 1142 mutex_init(&data->update_lock);
@@ -1197,6 +1204,8 @@ EXIT_DEV_REMOVE:
1197 dev_err(dev, "Sysfs interface creation failed (%d)\n", err); 1204 dev_err(dev, "Sysfs interface creation failed (%d)\n", err);
1198EXIT_DEV_REMOVE_SILENT: 1205EXIT_DEV_REMOVE_SILENT:
1199 vt1211_remove_sysfs(pdev); 1206 vt1211_remove_sysfs(pdev);
1207 release_region(res->start, res->end - res->start + 1);
1208EXIT_KFREE:
1200 platform_set_drvdata(pdev, NULL); 1209 platform_set_drvdata(pdev, NULL);
1201 kfree(data); 1210 kfree(data);
1202EXIT: 1211EXIT:
@@ -1206,12 +1215,16 @@ EXIT:
1206static int __devexit vt1211_remove(struct platform_device *pdev) 1215static int __devexit vt1211_remove(struct platform_device *pdev)
1207{ 1216{
1208 struct vt1211_data *data = platform_get_drvdata(pdev); 1217 struct vt1211_data *data = platform_get_drvdata(pdev);
1218 struct resource *res;
1209 1219
1210 hwmon_device_unregister(data->class_dev); 1220 hwmon_device_unregister(data->class_dev);
1211 vt1211_remove_sysfs(pdev); 1221 vt1211_remove_sysfs(pdev);
1212 platform_set_drvdata(pdev, NULL); 1222 platform_set_drvdata(pdev, NULL);
1213 kfree(data); 1223 kfree(data);
1214 1224
1225 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1226 release_region(res->start, res->end - res->start + 1);
1227
1215 return 0; 1228 return 0;
1216} 1229}
1217 1230
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index d7e240635b3b..a5b774b07cbd 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -5,6 +5,7 @@
5 Philip Edelbrock <phil@netroedge.com>, 5 Philip Edelbrock <phil@netroedge.com>,
6 and Mark Studebaker <mdsxyz123@yahoo.com> 6 and Mark Studebaker <mdsxyz123@yahoo.com>
7 Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org> 7 Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org>
8 Copyright (c) 2007 Jean Delvare <khali@linux-fr.org>
8 9
9 This program is free software; you can redistribute it and/or modify 10 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 it under the terms of the GNU General Public License as published by
@@ -42,15 +43,20 @@
42#include <linux/init.h> 43#include <linux/init.h>
43#include <linux/slab.h> 44#include <linux/slab.h>
44#include <linux/jiffies.h> 45#include <linux/jiffies.h>
45#include <linux/i2c.h> 46#include <linux/platform_device.h>
46#include <linux/i2c-isa.h>
47#include <linux/hwmon.h> 47#include <linux/hwmon.h>
48#include <linux/hwmon-vid.h> 48#include <linux/hwmon-vid.h>
49#include <linux/err.h> 49#include <linux/err.h>
50#include <linux/mutex.h> 50#include <linux/mutex.h>
51#include <linux/ioport.h>
51#include <asm/io.h> 52#include <asm/io.h>
52#include "lm75.h" 53#include "lm75.h"
53 54
55static struct platform_device *pdev;
56
57#define DRVNAME "w83627hf"
58enum chips { w83627hf, w83627thf, w83697hf, w83637hf, w83687thf };
59
54static u16 force_addr; 60static u16 force_addr;
55module_param(force_addr, ushort, 0); 61module_param(force_addr, ushort, 0);
56MODULE_PARM_DESC(force_addr, 62MODULE_PARM_DESC(force_addr,
@@ -60,12 +66,6 @@ module_param(force_i2c, byte, 0);
60MODULE_PARM_DESC(force_i2c, 66MODULE_PARM_DESC(force_i2c,
61 "Initialize the i2c address of the sensors"); 67 "Initialize the i2c address of the sensors");
62 68
63/* The actual ISA address is read from Super-I/O configuration space */
64static unsigned short address;
65
66/* Insmod parameters */
67enum chips { any_chip, w83627hf, w83627thf, w83697hf, w83637hf, w83687thf };
68
69static int reset; 69static int reset;
70module_param(reset, bool, 0); 70module_param(reset, bool, 0);
71MODULE_PARM_DESC(reset, "Set to one to reset chip on load"); 71MODULE_PARM_DESC(reset, "Set to one to reset chip on load");
@@ -156,9 +156,9 @@ superio_exit(void)
156#define WINB_REGION_OFFSET 5 156#define WINB_REGION_OFFSET 5
157#define WINB_REGION_SIZE 2 157#define WINB_REGION_SIZE 2
158 158
159/* Where are the sensors address/data registers relative to the base address */ 159/* Where are the sensors address/data registers relative to the region offset */
160#define W83781D_ADDR_REG_OFFSET 5 160#define W83781D_ADDR_REG_OFFSET 0
161#define W83781D_DATA_REG_OFFSET 6 161#define W83781D_DATA_REG_OFFSET 1
162 162
163/* The W83781D registers */ 163/* The W83781D registers */
164/* The W83782D registers for nr=7,8 are in bank 5 */ 164/* The W83782D registers for nr=7,8 are in bank 5 */
@@ -289,7 +289,8 @@ static inline u8 DIV_TO_REG(long val)
289/* For each registered chip, we need to keep some data in memory. 289/* For each registered chip, we need to keep some data in memory.
290 The structure is dynamically allocated. */ 290 The structure is dynamically allocated. */
291struct w83627hf_data { 291struct w83627hf_data {
292 struct i2c_client client; 292 unsigned short addr;
293 const char *name;
293 struct class_device *class_dev; 294 struct class_device *class_dev;
294 struct mutex lock; 295 struct mutex lock;
295 enum chips type; 296 enum chips type;
@@ -298,9 +299,6 @@ struct w83627hf_data {
298 char valid; /* !=0 if following fields are valid */ 299 char valid; /* !=0 if following fields are valid */
299 unsigned long last_updated; /* In jiffies */ 300 unsigned long last_updated; /* In jiffies */
300 301
301 struct i2c_client *lm75; /* for secondary I2C addresses */
302 /* pointer to array of 2 subclients */
303
304 u8 in[9]; /* Register value */ 302 u8 in[9]; /* Register value */
305 u8 in_max[9]; /* Register value */ 303 u8 in_max[9]; /* Register value */
306 u8 in_min[9]; /* Register value */ 304 u8 in_min[9]; /* Register value */
@@ -327,22 +325,26 @@ struct w83627hf_data {
327 u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */ 325 u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */
328}; 326};
329 327
328struct w83627hf_sio_data {
329 enum chips type;
330};
331
330 332
331static int w83627hf_detect(struct i2c_adapter *adapter); 333static int w83627hf_probe(struct platform_device *pdev);
332static int w83627hf_detach_client(struct i2c_client *client); 334static int w83627hf_remove(struct platform_device *pdev);
333 335
334static int w83627hf_read_value(struct i2c_client *client, u16 reg); 336static int w83627hf_read_value(struct w83627hf_data *data, u16 reg);
335static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value); 337static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value);
336static struct w83627hf_data *w83627hf_update_device(struct device *dev); 338static struct w83627hf_data *w83627hf_update_device(struct device *dev);
337static void w83627hf_init_client(struct i2c_client *client); 339static void w83627hf_init_device(struct platform_device *pdev);
338 340
339static struct i2c_driver w83627hf_driver = { 341static struct platform_driver w83627hf_driver = {
340 .driver = { 342 .driver = {
341 .owner = THIS_MODULE, 343 .owner = THIS_MODULE,
342 .name = "w83627hf", 344 .name = DRVNAME,
343 }, 345 },
344 .attach_adapter = w83627hf_detect, 346 .probe = w83627hf_probe,
345 .detach_client = w83627hf_detach_client, 347 .remove = __devexit_p(w83627hf_remove),
346}; 348};
347 349
348/* following are the sysfs callback functions */ 350/* following are the sysfs callback functions */
@@ -360,15 +362,14 @@ show_in_reg(in_max)
360static ssize_t \ 362static ssize_t \
361store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \ 363store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \
362{ \ 364{ \
363 struct i2c_client *client = to_i2c_client(dev); \ 365 struct w83627hf_data *data = dev_get_drvdata(dev); \
364 struct w83627hf_data *data = i2c_get_clientdata(client); \
365 u32 val; \ 366 u32 val; \
366 \ 367 \
367 val = simple_strtoul(buf, NULL, 10); \ 368 val = simple_strtoul(buf, NULL, 10); \
368 \ 369 \
369 mutex_lock(&data->update_lock); \ 370 mutex_lock(&data->update_lock); \
370 data->in_##reg[nr] = IN_TO_REG(val); \ 371 data->in_##reg[nr] = IN_TO_REG(val); \
371 w83627hf_write_value(client, W83781D_REG_IN_##REG(nr), \ 372 w83627hf_write_value(data, W83781D_REG_IN_##REG(nr), \
372 data->in_##reg[nr]); \ 373 data->in_##reg[nr]); \
373 \ 374 \
374 mutex_unlock(&data->update_lock); \ 375 mutex_unlock(&data->update_lock); \
@@ -452,8 +453,7 @@ static ssize_t show_regs_in_max0(struct device *dev, struct device_attribute *at
452static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *attr, 453static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *attr,
453 const char *buf, size_t count) 454 const char *buf, size_t count)
454{ 455{
455 struct i2c_client *client = to_i2c_client(dev); 456 struct w83627hf_data *data = dev_get_drvdata(dev);
456 struct w83627hf_data *data = i2c_get_clientdata(client);
457 u32 val; 457 u32 val;
458 458
459 val = simple_strtoul(buf, NULL, 10); 459 val = simple_strtoul(buf, NULL, 10);
@@ -472,7 +472,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a
472 /* use VRM8 (standard) calculation */ 472 /* use VRM8 (standard) calculation */
473 data->in_min[0] = IN_TO_REG(val); 473 data->in_min[0] = IN_TO_REG(val);
474 474
475 w83627hf_write_value(client, W83781D_REG_IN_MIN(0), data->in_min[0]); 475 w83627hf_write_value(data, W83781D_REG_IN_MIN(0), data->in_min[0]);
476 mutex_unlock(&data->update_lock); 476 mutex_unlock(&data->update_lock);
477 return count; 477 return count;
478} 478}
@@ -480,8 +480,7 @@ static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *a
480static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *attr, 480static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *attr,
481 const char *buf, size_t count) 481 const char *buf, size_t count)
482{ 482{
483 struct i2c_client *client = to_i2c_client(dev); 483 struct w83627hf_data *data = dev_get_drvdata(dev);
484 struct w83627hf_data *data = i2c_get_clientdata(client);
485 u32 val; 484 u32 val;
486 485
487 val = simple_strtoul(buf, NULL, 10); 486 val = simple_strtoul(buf, NULL, 10);
@@ -500,7 +499,7 @@ static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *a
500 /* use VRM8 (standard) calculation */ 499 /* use VRM8 (standard) calculation */
501 data->in_max[0] = IN_TO_REG(val); 500 data->in_max[0] = IN_TO_REG(val);
502 501
503 w83627hf_write_value(client, W83781D_REG_IN_MAX(0), data->in_max[0]); 502 w83627hf_write_value(data, W83781D_REG_IN_MAX(0), data->in_max[0]);
504 mutex_unlock(&data->update_lock); 503 mutex_unlock(&data->update_lock);
505 return count; 504 return count;
506} 505}
@@ -525,8 +524,7 @@ show_fan_reg(fan_min);
525static ssize_t 524static ssize_t
526store_fan_min(struct device *dev, const char *buf, size_t count, int nr) 525store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
527{ 526{
528 struct i2c_client *client = to_i2c_client(dev); 527 struct w83627hf_data *data = dev_get_drvdata(dev);
529 struct w83627hf_data *data = i2c_get_clientdata(client);
530 u32 val; 528 u32 val;
531 529
532 val = simple_strtoul(buf, NULL, 10); 530 val = simple_strtoul(buf, NULL, 10);
@@ -534,7 +532,7 @@ store_fan_min(struct device *dev, const char *buf, size_t count, int nr)
534 mutex_lock(&data->update_lock); 532 mutex_lock(&data->update_lock);
535 data->fan_min[nr - 1] = 533 data->fan_min[nr - 1] =
536 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); 534 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1]));
537 w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr), 535 w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr),
538 data->fan_min[nr - 1]); 536 data->fan_min[nr - 1]);
539 537
540 mutex_unlock(&data->update_lock); 538 mutex_unlock(&data->update_lock);
@@ -587,8 +585,7 @@ show_temp_reg(temp_max_hyst);
587static ssize_t \ 585static ssize_t \
588store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ 586store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
589{ \ 587{ \
590 struct i2c_client *client = to_i2c_client(dev); \ 588 struct w83627hf_data *data = dev_get_drvdata(dev); \
591 struct w83627hf_data *data = i2c_get_clientdata(client); \
592 u32 val; \ 589 u32 val; \
593 \ 590 \
594 val = simple_strtoul(buf, NULL, 10); \ 591 val = simple_strtoul(buf, NULL, 10); \
@@ -597,11 +594,11 @@ store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \
597 \ 594 \
598 if (nr >= 2) { /* TEMP2 and TEMP3 */ \ 595 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
599 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ 596 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
600 w83627hf_write_value(client, W83781D_REG_TEMP_##REG(nr), \ 597 w83627hf_write_value(data, W83781D_REG_TEMP_##REG(nr), \
601 data->temp_##reg##_add[nr-2]); \ 598 data->temp_##reg##_add[nr-2]); \
602 } else { /* TEMP1 */ \ 599 } else { /* TEMP1 */ \
603 data->temp_##reg = TEMP_TO_REG(val); \ 600 data->temp_##reg = TEMP_TO_REG(val); \
604 w83627hf_write_value(client, W83781D_REG_TEMP_##REG(nr), \ 601 w83627hf_write_value(data, W83781D_REG_TEMP_##REG(nr), \
605 data->temp_##reg); \ 602 data->temp_##reg); \
606 } \ 603 } \
607 \ 604 \
@@ -659,8 +656,7 @@ show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
659static ssize_t 656static ssize_t
660store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 657store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
661{ 658{
662 struct i2c_client *client = to_i2c_client(dev); 659 struct w83627hf_data *data = dev_get_drvdata(dev);
663 struct w83627hf_data *data = i2c_get_clientdata(client);
664 u32 val; 660 u32 val;
665 661
666 val = simple_strtoul(buf, NULL, 10); 662 val = simple_strtoul(buf, NULL, 10);
@@ -695,8 +691,7 @@ static ssize_t
695store_beep_reg(struct device *dev, const char *buf, size_t count, 691store_beep_reg(struct device *dev, const char *buf, size_t count,
696 int update_mask) 692 int update_mask)
697{ 693{
698 struct i2c_client *client = to_i2c_client(dev); 694 struct w83627hf_data *data = dev_get_drvdata(dev);
699 struct w83627hf_data *data = i2c_get_clientdata(client);
700 u32 val, val2; 695 u32 val, val2;
701 696
702 val = simple_strtoul(buf, NULL, 10); 697 val = simple_strtoul(buf, NULL, 10);
@@ -705,18 +700,18 @@ store_beep_reg(struct device *dev, const char *buf, size_t count,
705 700
706 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ 701 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */
707 data->beep_mask = BEEP_MASK_TO_REG(val); 702 data->beep_mask = BEEP_MASK_TO_REG(val);
708 w83627hf_write_value(client, W83781D_REG_BEEP_INTS1, 703 w83627hf_write_value(data, W83781D_REG_BEEP_INTS1,
709 data->beep_mask & 0xff); 704 data->beep_mask & 0xff);
710 w83627hf_write_value(client, W83781D_REG_BEEP_INTS3, 705 w83627hf_write_value(data, W83781D_REG_BEEP_INTS3,
711 ((data->beep_mask) >> 16) & 0xff); 706 ((data->beep_mask) >> 16) & 0xff);
712 val2 = (data->beep_mask >> 8) & 0x7f; 707 val2 = (data->beep_mask >> 8) & 0x7f;
713 } else { /* We are storing beep_enable */ 708 } else { /* We are storing beep_enable */
714 val2 = 709 val2 =
715 w83627hf_read_value(client, W83781D_REG_BEEP_INTS2) & 0x7f; 710 w83627hf_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f;
716 data->beep_enable = BEEP_ENABLE_TO_REG(val); 711 data->beep_enable = BEEP_ENABLE_TO_REG(val);
717 } 712 }
718 713
719 w83627hf_write_value(client, W83781D_REG_BEEP_INTS2, 714 w83627hf_write_value(data, W83781D_REG_BEEP_INTS2,
720 val2 | data->beep_enable << 7); 715 val2 | data->beep_enable << 7);
721 716
722 mutex_unlock(&data->update_lock); 717 mutex_unlock(&data->update_lock);
@@ -754,8 +749,7 @@ show_fan_div_reg(struct device *dev, char *buf, int nr)
754static ssize_t 749static ssize_t
755store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) 750store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
756{ 751{
757 struct i2c_client *client = to_i2c_client(dev); 752 struct w83627hf_data *data = dev_get_drvdata(dev);
758 struct w83627hf_data *data = i2c_get_clientdata(client);
759 unsigned long min; 753 unsigned long min;
760 u8 reg; 754 u8 reg;
761 unsigned long val = simple_strtoul(buf, NULL, 10); 755 unsigned long val = simple_strtoul(buf, NULL, 10);
@@ -768,19 +762,19 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
768 762
769 data->fan_div[nr] = DIV_TO_REG(val); 763 data->fan_div[nr] = DIV_TO_REG(val);
770 764
771 reg = (w83627hf_read_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV) 765 reg = (w83627hf_read_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV)
772 & (nr==0 ? 0xcf : 0x3f)) 766 & (nr==0 ? 0xcf : 0x3f))
773 | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6)); 767 | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6));
774 w83627hf_write_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg); 768 w83627hf_write_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg);
775 769
776 reg = (w83627hf_read_value(client, W83781D_REG_VBAT) 770 reg = (w83627hf_read_value(data, W83781D_REG_VBAT)
777 & ~(1 << (5 + nr))) 771 & ~(1 << (5 + nr)))
778 | ((data->fan_div[nr] & 0x04) << (3 + nr)); 772 | ((data->fan_div[nr] & 0x04) << (3 + nr));
779 w83627hf_write_value(client, W83781D_REG_VBAT, reg); 773 w83627hf_write_value(data, W83781D_REG_VBAT, reg);
780 774
781 /* Restore fan_min */ 775 /* Restore fan_min */
782 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 776 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
783 w83627hf_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); 777 w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]);
784 778
785 mutex_unlock(&data->update_lock); 779 mutex_unlock(&data->update_lock);
786 return count; 780 return count;
@@ -814,8 +808,7 @@ show_pwm_reg(struct device *dev, char *buf, int nr)
814static ssize_t 808static ssize_t
815store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) 809store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
816{ 810{
817 struct i2c_client *client = to_i2c_client(dev); 811 struct w83627hf_data *data = dev_get_drvdata(dev);
818 struct w83627hf_data *data = i2c_get_clientdata(client);
819 u32 val; 812 u32 val;
820 813
821 val = simple_strtoul(buf, NULL, 10); 814 val = simple_strtoul(buf, NULL, 10);
@@ -825,14 +818,14 @@ store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr)
825 if (data->type == w83627thf) { 818 if (data->type == w83627thf) {
826 /* bits 0-3 are reserved in 627THF */ 819 /* bits 0-3 are reserved in 627THF */
827 data->pwm[nr - 1] = PWM_TO_REG(val) & 0xf0; 820 data->pwm[nr - 1] = PWM_TO_REG(val) & 0xf0;
828 w83627hf_write_value(client, 821 w83627hf_write_value(data,
829 W836X7HF_REG_PWM(data->type, nr), 822 W836X7HF_REG_PWM(data->type, nr),
830 data->pwm[nr - 1] | 823 data->pwm[nr - 1] |
831 (w83627hf_read_value(client, 824 (w83627hf_read_value(data,
832 W836X7HF_REG_PWM(data->type, nr)) & 0x0f)); 825 W836X7HF_REG_PWM(data->type, nr)) & 0x0f));
833 } else { 826 } else {
834 data->pwm[nr - 1] = PWM_TO_REG(val); 827 data->pwm[nr - 1] = PWM_TO_REG(val);
835 w83627hf_write_value(client, 828 w83627hf_write_value(data,
836 W836X7HF_REG_PWM(data->type, nr), 829 W836X7HF_REG_PWM(data->type, nr),
837 data->pwm[nr - 1]); 830 data->pwm[nr - 1]);
838 } 831 }
@@ -868,8 +861,7 @@ show_sensor_reg(struct device *dev, char *buf, int nr)
868static ssize_t 861static ssize_t
869store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) 862store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
870{ 863{
871 struct i2c_client *client = to_i2c_client(dev); 864 struct w83627hf_data *data = dev_get_drvdata(dev);
872 struct w83627hf_data *data = i2c_get_clientdata(client);
873 u32 val, tmp; 865 u32 val, tmp;
874 866
875 val = simple_strtoul(buf, NULL, 10); 867 val = simple_strtoul(buf, NULL, 10);
@@ -878,31 +870,31 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
878 870
879 switch (val) { 871 switch (val) {
880 case 1: /* PII/Celeron diode */ 872 case 1: /* PII/Celeron diode */
881 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); 873 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1);
882 w83627hf_write_value(client, W83781D_REG_SCFG1, 874 w83627hf_write_value(data, W83781D_REG_SCFG1,
883 tmp | BIT_SCFG1[nr - 1]); 875 tmp | BIT_SCFG1[nr - 1]);
884 tmp = w83627hf_read_value(client, W83781D_REG_SCFG2); 876 tmp = w83627hf_read_value(data, W83781D_REG_SCFG2);
885 w83627hf_write_value(client, W83781D_REG_SCFG2, 877 w83627hf_write_value(data, W83781D_REG_SCFG2,
886 tmp | BIT_SCFG2[nr - 1]); 878 tmp | BIT_SCFG2[nr - 1]);
887 data->sens[nr - 1] = val; 879 data->sens[nr - 1] = val;
888 break; 880 break;
889 case 2: /* 3904 */ 881 case 2: /* 3904 */
890 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); 882 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1);
891 w83627hf_write_value(client, W83781D_REG_SCFG1, 883 w83627hf_write_value(data, W83781D_REG_SCFG1,
892 tmp | BIT_SCFG1[nr - 1]); 884 tmp | BIT_SCFG1[nr - 1]);
893 tmp = w83627hf_read_value(client, W83781D_REG_SCFG2); 885 tmp = w83627hf_read_value(data, W83781D_REG_SCFG2);
894 w83627hf_write_value(client, W83781D_REG_SCFG2, 886 w83627hf_write_value(data, W83781D_REG_SCFG2,
895 tmp & ~BIT_SCFG2[nr - 1]); 887 tmp & ~BIT_SCFG2[nr - 1]);
896 data->sens[nr - 1] = val; 888 data->sens[nr - 1] = val;
897 break; 889 break;
898 case W83781D_DEFAULT_BETA: /* thermistor */ 890 case W83781D_DEFAULT_BETA: /* thermistor */
899 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1); 891 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1);
900 w83627hf_write_value(client, W83781D_REG_SCFG1, 892 w83627hf_write_value(data, W83781D_REG_SCFG1,
901 tmp & ~BIT_SCFG1[nr - 1]); 893 tmp & ~BIT_SCFG1[nr - 1]);
902 data->sens[nr - 1] = val; 894 data->sens[nr - 1] = val;
903 break; 895 break;
904 default: 896 default:
905 dev_err(&client->dev, 897 dev_err(dev,
906 "Invalid sensor type %ld; must be 1, 2, or %d\n", 898 "Invalid sensor type %ld; must be 1, 2, or %d\n",
907 (long) val, W83781D_DEFAULT_BETA); 899 (long) val, W83781D_DEFAULT_BETA);
908 break; 900 break;
@@ -929,35 +921,85 @@ sysfs_sensor(1);
929sysfs_sensor(2); 921sysfs_sensor(2);
930sysfs_sensor(3); 922sysfs_sensor(3);
931 923
932static int __init w83627hf_find(int sioaddr, unsigned short *addr) 924static ssize_t show_name(struct device *dev, struct device_attribute
925 *devattr, char *buf)
926{
927 struct w83627hf_data *data = dev_get_drvdata(dev);
928
929 return sprintf(buf, "%s\n", data->name);
930}
931static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
932
933static int __init w83627hf_find(int sioaddr, unsigned short *addr,
934 struct w83627hf_sio_data *sio_data)
933{ 935{
936 int err = -ENODEV;
934 u16 val; 937 u16 val;
935 938
939 static const __initdata char *names[] = {
940 "W83627HF",
941 "W83627THF",
942 "W83697HF",
943 "W83637HF",
944 "W83687THF",
945 };
946
936 REG = sioaddr; 947 REG = sioaddr;
937 VAL = sioaddr + 1; 948 VAL = sioaddr + 1;
938 949
939 superio_enter(); 950 superio_enter();
940 val= superio_inb(DEVID); 951 val= superio_inb(DEVID);
941 if(val != W627_DEVID && 952 switch (val) {
942 val != W627THF_DEVID && 953 case W627_DEVID:
943 val != W697_DEVID && 954 sio_data->type = w83627hf;
944 val != W637_DEVID && 955 break;
945 val != W687THF_DEVID) { 956 case W627THF_DEVID:
946 superio_exit(); 957 sio_data->type = w83627thf;
947 return -ENODEV; 958 break;
959 case W697_DEVID:
960 sio_data->type = w83697hf;
961 break;
962 case W637_DEVID:
963 sio_data->type = w83637hf;
964 break;
965 case W687THF_DEVID:
966 sio_data->type = w83687thf;
967 break;
968 default:
969 pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n", val);
970 goto exit;
948 } 971 }
949 972
950 superio_select(W83627HF_LD_HWM); 973 superio_select(W83627HF_LD_HWM);
974 force_addr &= WINB_ALIGNMENT;
975 if (force_addr) {
976 printk(KERN_WARNING DRVNAME ": Forcing address 0x%x\n",
977 force_addr);
978 superio_outb(WINB_BASE_REG, force_addr >> 8);
979 superio_outb(WINB_BASE_REG + 1, force_addr & 0xff);
980 }
951 val = (superio_inb(WINB_BASE_REG) << 8) | 981 val = (superio_inb(WINB_BASE_REG) << 8) |
952 superio_inb(WINB_BASE_REG + 1); 982 superio_inb(WINB_BASE_REG + 1);
953 *addr = val & WINB_ALIGNMENT; 983 *addr = val & WINB_ALIGNMENT;
954 if (*addr == 0 && force_addr == 0) { 984 if (*addr == 0) {
955 superio_exit(); 985 printk(KERN_WARNING DRVNAME ": Base address not set, "
956 return -ENODEV; 986 "skipping\n");
987 goto exit;
957 } 988 }
958 989
990 val = superio_inb(WINB_ACT_REG);
991 if (!(val & 0x01)) {
992 printk(KERN_WARNING DRVNAME ": Enabling HWM logical device\n");
993 superio_outb(WINB_ACT_REG, val | 0x01);
994 }
995
996 err = 0;
997 pr_info(DRVNAME ": Found %s chip at %#x\n",
998 names[sio_data->type], *addr);
999
1000 exit:
959 superio_exit(); 1001 superio_exit();
960 return 0; 1002 return err;
961} 1003}
962 1004
963static struct attribute *w83627hf_attributes[] = { 1005static struct attribute *w83627hf_attributes[] = {
@@ -1003,6 +1045,7 @@ static struct attribute *w83627hf_attributes[] = {
1003 &dev_attr_pwm1.attr, 1045 &dev_attr_pwm1.attr,
1004 &dev_attr_pwm2.attr, 1046 &dev_attr_pwm2.attr,
1005 1047
1048 &dev_attr_name.attr,
1006 NULL 1049 NULL
1007}; 1050};
1008 1051
@@ -1039,161 +1082,92 @@ static const struct attribute_group w83627hf_group_opt = {
1039 .attrs = w83627hf_attributes_opt, 1082 .attrs = w83627hf_attributes_opt,
1040}; 1083};
1041 1084
1042static int w83627hf_detect(struct i2c_adapter *adapter) 1085static int __devinit w83627hf_probe(struct platform_device *pdev)
1043{ 1086{
1044 int val, kind; 1087 struct device *dev = &pdev->dev;
1045 struct i2c_client *new_client; 1088 struct w83627hf_sio_data *sio_data = dev->platform_data;
1046 struct w83627hf_data *data; 1089 struct w83627hf_data *data;
1047 int err = 0; 1090 struct resource *res;
1048 const char *client_name = ""; 1091 int err;
1049
1050 if(force_addr)
1051 address = force_addr & WINB_ALIGNMENT;
1052 1092
1053 if (!request_region(address + WINB_REGION_OFFSET, WINB_REGION_SIZE, 1093 static const char *names[] = {
1054 w83627hf_driver.driver.name)) { 1094 "w83627hf",
1095 "w83627thf",
1096 "w83697hf",
1097 "w83637hf",
1098 "w83687thf",
1099 };
1100
1101 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1102 if (!request_region(res->start, WINB_REGION_SIZE, DRVNAME)) {
1103 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
1104 (unsigned long)res->start,
1105 (unsigned long)(res->start + WINB_REGION_SIZE - 1));
1055 err = -EBUSY; 1106 err = -EBUSY;
1056 goto ERROR0; 1107 goto ERROR0;
1057 } 1108 }
1058 1109
1059 if(force_addr) {
1060 printk("w83627hf.o: forcing ISA address 0x%04X\n", address);
1061 superio_enter();
1062 superio_select(W83627HF_LD_HWM);
1063 superio_outb(WINB_BASE_REG, address >> 8);
1064 superio_outb(WINB_BASE_REG+1, address & 0xff);
1065 superio_exit();
1066 }
1067
1068 superio_enter();
1069 val= superio_inb(DEVID);
1070 if(val == W627_DEVID)
1071 kind = w83627hf;
1072 else if(val == W697_DEVID)
1073 kind = w83697hf;
1074 else if(val == W627THF_DEVID)
1075 kind = w83627thf;
1076 else if(val == W637_DEVID)
1077 kind = w83637hf;
1078 else if (val == W687THF_DEVID)
1079 kind = w83687thf;
1080 else {
1081 dev_info(&adapter->dev,
1082 "Unsupported chip (dev_id=0x%02X).\n", val);
1083 goto ERROR1;
1084 }
1085
1086 superio_select(W83627HF_LD_HWM);
1087 if((val = 0x01 & superio_inb(WINB_ACT_REG)) == 0)
1088 superio_outb(WINB_ACT_REG, 1);
1089 superio_exit();
1090
1091 /* OK. For now, we presume we have a valid client. We now create the
1092 client structure, even though we cannot fill it completely yet.
1093 But it allows us to access w83627hf_{read,write}_value. */
1094
1095 if (!(data = kzalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) { 1110 if (!(data = kzalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) {
1096 err = -ENOMEM; 1111 err = -ENOMEM;
1097 goto ERROR1; 1112 goto ERROR1;
1098 } 1113 }
1099 1114 data->addr = res->start;
1100 new_client = &data->client; 1115 data->type = sio_data->type;
1101 i2c_set_clientdata(new_client, data); 1116 data->name = names[sio_data->type];
1102 new_client->addr = address;
1103 mutex_init(&data->lock); 1117 mutex_init(&data->lock);
1104 new_client->adapter = adapter;
1105 new_client->driver = &w83627hf_driver;
1106 new_client->flags = 0;
1107
1108
1109 if (kind == w83627hf) {
1110 client_name = "w83627hf";
1111 } else if (kind == w83627thf) {
1112 client_name = "w83627thf";
1113 } else if (kind == w83697hf) {
1114 client_name = "w83697hf";
1115 } else if (kind == w83637hf) {
1116 client_name = "w83637hf";
1117 } else if (kind == w83687thf) {
1118 client_name = "w83687thf";
1119 }
1120
1121 /* Fill in the remaining client fields and put into the global list */
1122 strlcpy(new_client->name, client_name, I2C_NAME_SIZE);
1123 data->type = kind;
1124 data->valid = 0;
1125 mutex_init(&data->update_lock); 1118 mutex_init(&data->update_lock);
1126 1119 platform_set_drvdata(pdev, data);
1127 /* Tell the I2C layer a new client has arrived */
1128 if ((err = i2c_attach_client(new_client)))
1129 goto ERROR2;
1130
1131 data->lm75 = NULL;
1132 1120
1133 /* Initialize the chip */ 1121 /* Initialize the chip */
1134 w83627hf_init_client(new_client); 1122 w83627hf_init_device(pdev);
1135 1123
1136 /* A few vars need to be filled upon startup */ 1124 /* A few vars need to be filled upon startup */
1137 data->fan_min[0] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(1)); 1125 data->fan_min[0] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(1));
1138 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2)); 1126 data->fan_min[1] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(2));
1139 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); 1127 data->fan_min[2] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(3));
1140 1128
1141 /* Register common device attributes */ 1129 /* Register common device attributes */
1142 if ((err = sysfs_create_group(&new_client->dev.kobj, &w83627hf_group))) 1130 if ((err = sysfs_create_group(&dev->kobj, &w83627hf_group)))
1143 goto ERROR3; 1131 goto ERROR3;
1144 1132
1145 /* Register chip-specific device attributes */ 1133 /* Register chip-specific device attributes */
1146 if (kind == w83627hf || kind == w83697hf) 1134 if (data->type == w83627hf || data->type == w83697hf)
1147 if ((err = device_create_file(&new_client->dev, 1135 if ((err = device_create_file(dev, &dev_attr_in5_input))
1148 &dev_attr_in5_input)) 1136 || (err = device_create_file(dev, &dev_attr_in5_min))
1149 || (err = device_create_file(&new_client->dev, 1137 || (err = device_create_file(dev, &dev_attr_in5_max))
1150 &dev_attr_in5_min)) 1138 || (err = device_create_file(dev, &dev_attr_in6_input))
1151 || (err = device_create_file(&new_client->dev, 1139 || (err = device_create_file(dev, &dev_attr_in6_min))
1152 &dev_attr_in5_max)) 1140 || (err = device_create_file(dev, &dev_attr_in6_max)))
1153 || (err = device_create_file(&new_client->dev,
1154 &dev_attr_in6_input))
1155 || (err = device_create_file(&new_client->dev,
1156 &dev_attr_in6_min))
1157 || (err = device_create_file(&new_client->dev,
1158 &dev_attr_in6_max)))
1159 goto ERROR4; 1141 goto ERROR4;
1160 1142
1161 if (kind != w83697hf) 1143 if (data->type != w83697hf)
1162 if ((err = device_create_file(&new_client->dev, 1144 if ((err = device_create_file(dev, &dev_attr_in1_input))
1163 &dev_attr_in1_input)) 1145 || (err = device_create_file(dev, &dev_attr_in1_min))
1164 || (err = device_create_file(&new_client->dev, 1146 || (err = device_create_file(dev, &dev_attr_in1_max))
1165 &dev_attr_in1_min)) 1147 || (err = device_create_file(dev, &dev_attr_fan3_input))
1166 || (err = device_create_file(&new_client->dev, 1148 || (err = device_create_file(dev, &dev_attr_fan3_min))
1167 &dev_attr_in1_max)) 1149 || (err = device_create_file(dev, &dev_attr_fan3_div))
1168 || (err = device_create_file(&new_client->dev, 1150 || (err = device_create_file(dev, &dev_attr_temp3_input))
1169 &dev_attr_fan3_input)) 1151 || (err = device_create_file(dev, &dev_attr_temp3_max))
1170 || (err = device_create_file(&new_client->dev, 1152 || (err = device_create_file(dev, &dev_attr_temp3_max_hyst))
1171 &dev_attr_fan3_min)) 1153 || (err = device_create_file(dev, &dev_attr_temp3_type)))
1172 || (err = device_create_file(&new_client->dev,
1173 &dev_attr_fan3_div))
1174 || (err = device_create_file(&new_client->dev,
1175 &dev_attr_temp3_input))
1176 || (err = device_create_file(&new_client->dev,
1177 &dev_attr_temp3_max))
1178 || (err = device_create_file(&new_client->dev,
1179 &dev_attr_temp3_max_hyst))
1180 || (err = device_create_file(&new_client->dev,
1181 &dev_attr_temp3_type)))
1182 goto ERROR4; 1154 goto ERROR4;
1183 1155
1184 if (kind != w83697hf && data->vid != 0xff) 1156 if (data->type != w83697hf && data->vid != 0xff) {
1185 if ((err = device_create_file(&new_client->dev, 1157 /* Convert VID to voltage based on VRM */
1186 &dev_attr_cpu0_vid)) 1158 data->vrm = vid_which_vrm();
1187 || (err = device_create_file(&new_client->dev, 1159
1188 &dev_attr_vrm))) 1160 if ((err = device_create_file(dev, &dev_attr_cpu0_vid))
1161 || (err = device_create_file(dev, &dev_attr_vrm)))
1189 goto ERROR4; 1162 goto ERROR4;
1163 }
1190 1164
1191 if (kind == w83627thf || kind == w83637hf || kind == w83687thf) 1165 if (data->type == w83627thf || data->type == w83637hf
1192 if ((err = device_create_file(&new_client->dev, 1166 || data->type == w83687thf)
1193 &dev_attr_pwm3))) 1167 if ((err = device_create_file(dev, &dev_attr_pwm3)))
1194 goto ERROR4; 1168 goto ERROR4;
1195 1169
1196 data->class_dev = hwmon_device_register(&new_client->dev); 1170 data->class_dev = hwmon_device_register(dev);
1197 if (IS_ERR(data->class_dev)) { 1171 if (IS_ERR(data->class_dev)) {
1198 err = PTR_ERR(data->class_dev); 1172 err = PTR_ERR(data->class_dev);
1199 goto ERROR4; 1173 goto ERROR4;
@@ -1202,47 +1176,37 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1202 return 0; 1176 return 0;
1203 1177
1204 ERROR4: 1178 ERROR4:
1205 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group); 1179 sysfs_remove_group(&dev->kobj, &w83627hf_group);
1206 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group_opt); 1180 sysfs_remove_group(&dev->kobj, &w83627hf_group_opt);
1207 ERROR3: 1181 ERROR3:
1208 i2c_detach_client(new_client);
1209 ERROR2:
1210 kfree(data); 1182 kfree(data);
1211 ERROR1: 1183 ERROR1:
1212 release_region(address + WINB_REGION_OFFSET, WINB_REGION_SIZE); 1184 release_region(res->start, WINB_REGION_SIZE);
1213 ERROR0: 1185 ERROR0:
1214 return err; 1186 return err;
1215} 1187}
1216 1188
1217static int w83627hf_detach_client(struct i2c_client *client) 1189static int __devexit w83627hf_remove(struct platform_device *pdev)
1218{ 1190{
1219 struct w83627hf_data *data = i2c_get_clientdata(client); 1191 struct w83627hf_data *data = platform_get_drvdata(pdev);
1220 int err; 1192 struct resource *res;
1221 1193
1194 platform_set_drvdata(pdev, NULL);
1222 hwmon_device_unregister(data->class_dev); 1195 hwmon_device_unregister(data->class_dev);
1223 1196
1224 sysfs_remove_group(&client->dev.kobj, &w83627hf_group); 1197 sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group);
1225 sysfs_remove_group(&client->dev.kobj, &w83627hf_group_opt); 1198 sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group_opt);
1226
1227 if ((err = i2c_detach_client(client)))
1228 return err;
1229
1230 release_region(client->addr + WINB_REGION_OFFSET, WINB_REGION_SIZE);
1231 kfree(data); 1199 kfree(data);
1232 1200
1201 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1202 release_region(res->start, WINB_REGION_SIZE);
1203
1233 return 0; 1204 return 0;
1234} 1205}
1235 1206
1236 1207
1237/* 1208static int w83627hf_read_value(struct w83627hf_data *data, u16 reg)
1238 ISA access must always be locked explicitly!
1239 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
1240 would slow down the W83781D access and should not be necessary.
1241 There are some ugly typecasts here, but the good news is - they should
1242 nowhere else be necessary! */
1243static int w83627hf_read_value(struct i2c_client *client, u16 reg)
1244{ 1209{
1245 struct w83627hf_data *data = i2c_get_clientdata(client);
1246 int res, word_sized; 1210 int res, word_sized;
1247 1211
1248 mutex_lock(&data->lock); 1212 mutex_lock(&data->lock);
@@ -1253,29 +1217,29 @@ static int w83627hf_read_value(struct i2c_client *client, u16 reg)
1253 || ((reg & 0x00ff) == 0x55)); 1217 || ((reg & 0x00ff) == 0x55));
1254 if (reg & 0xff00) { 1218 if (reg & 0xff00) {
1255 outb_p(W83781D_REG_BANK, 1219 outb_p(W83781D_REG_BANK,
1256 client->addr + W83781D_ADDR_REG_OFFSET); 1220 data->addr + W83781D_ADDR_REG_OFFSET);
1257 outb_p(reg >> 8, 1221 outb_p(reg >> 8,
1258 client->addr + W83781D_DATA_REG_OFFSET); 1222 data->addr + W83781D_DATA_REG_OFFSET);
1259 } 1223 }
1260 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET); 1224 outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET);
1261 res = inb_p(client->addr + W83781D_DATA_REG_OFFSET); 1225 res = inb_p(data->addr + W83781D_DATA_REG_OFFSET);
1262 if (word_sized) { 1226 if (word_sized) {
1263 outb_p((reg & 0xff) + 1, 1227 outb_p((reg & 0xff) + 1,
1264 client->addr + W83781D_ADDR_REG_OFFSET); 1228 data->addr + W83781D_ADDR_REG_OFFSET);
1265 res = 1229 res =
1266 (res << 8) + inb_p(client->addr + 1230 (res << 8) + inb_p(data->addr +
1267 W83781D_DATA_REG_OFFSET); 1231 W83781D_DATA_REG_OFFSET);
1268 } 1232 }
1269 if (reg & 0xff00) { 1233 if (reg & 0xff00) {
1270 outb_p(W83781D_REG_BANK, 1234 outb_p(W83781D_REG_BANK,
1271 client->addr + W83781D_ADDR_REG_OFFSET); 1235 data->addr + W83781D_ADDR_REG_OFFSET);
1272 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); 1236 outb_p(0, data->addr + W83781D_DATA_REG_OFFSET);
1273 } 1237 }
1274 mutex_unlock(&data->lock); 1238 mutex_unlock(&data->lock);
1275 return res; 1239 return res;
1276} 1240}
1277 1241
1278static int w83627thf_read_gpio5(struct i2c_client *client) 1242static int __devinit w83627thf_read_gpio5(struct platform_device *pdev)
1279{ 1243{
1280 int res = 0xff, sel; 1244 int res = 0xff, sel;
1281 1245
@@ -1284,7 +1248,7 @@ static int w83627thf_read_gpio5(struct i2c_client *client)
1284 1248
1285 /* Make sure these GPIO pins are enabled */ 1249 /* Make sure these GPIO pins are enabled */
1286 if (!(superio_inb(W83627THF_GPIO5_EN) & (1<<3))) { 1250 if (!(superio_inb(W83627THF_GPIO5_EN) & (1<<3))) {
1287 dev_dbg(&client->dev, "GPIO5 disabled, no VID function\n"); 1251 dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n");
1288 goto exit; 1252 goto exit;
1289 } 1253 }
1290 1254
@@ -1292,12 +1256,12 @@ static int w83627thf_read_gpio5(struct i2c_client *client)
1292 There must be at least five (VRM 9), and possibly 6 (VRM 10) */ 1256 There must be at least five (VRM 9), and possibly 6 (VRM 10) */
1293 sel = superio_inb(W83627THF_GPIO5_IOSR) & 0x3f; 1257 sel = superio_inb(W83627THF_GPIO5_IOSR) & 0x3f;
1294 if ((sel & 0x1f) != 0x1f) { 1258 if ((sel & 0x1f) != 0x1f) {
1295 dev_dbg(&client->dev, "GPIO5 not configured for VID " 1259 dev_dbg(&pdev->dev, "GPIO5 not configured for VID "
1296 "function\n"); 1260 "function\n");
1297 goto exit; 1261 goto exit;
1298 } 1262 }
1299 1263
1300 dev_info(&client->dev, "Reading VID from GPIO5\n"); 1264 dev_info(&pdev->dev, "Reading VID from GPIO5\n");
1301 res = superio_inb(W83627THF_GPIO5_DR) & sel; 1265 res = superio_inb(W83627THF_GPIO5_DR) & sel;
1302 1266
1303exit: 1267exit:
@@ -1305,7 +1269,7 @@ exit:
1305 return res; 1269 return res;
1306} 1270}
1307 1271
1308static int w83687thf_read_vid(struct i2c_client *client) 1272static int __devinit w83687thf_read_vid(struct platform_device *pdev)
1309{ 1273{
1310 int res = 0xff; 1274 int res = 0xff;
1311 1275
@@ -1314,13 +1278,13 @@ static int w83687thf_read_vid(struct i2c_client *client)
1314 1278
1315 /* Make sure these GPIO pins are enabled */ 1279 /* Make sure these GPIO pins are enabled */
1316 if (!(superio_inb(W83687THF_VID_EN) & (1 << 2))) { 1280 if (!(superio_inb(W83687THF_VID_EN) & (1 << 2))) {
1317 dev_dbg(&client->dev, "VID disabled, no VID function\n"); 1281 dev_dbg(&pdev->dev, "VID disabled, no VID function\n");
1318 goto exit; 1282 goto exit;
1319 } 1283 }
1320 1284
1321 /* Make sure the pins are configured for input */ 1285 /* Make sure the pins are configured for input */
1322 if (!(superio_inb(W83687THF_VID_CFG) & (1 << 4))) { 1286 if (!(superio_inb(W83687THF_VID_CFG) & (1 << 4))) {
1323 dev_dbg(&client->dev, "VID configured as output, " 1287 dev_dbg(&pdev->dev, "VID configured as output, "
1324 "no VID function\n"); 1288 "no VID function\n");
1325 goto exit; 1289 goto exit;
1326 } 1290 }
@@ -1332,9 +1296,8 @@ exit:
1332 return res; 1296 return res;
1333} 1297}
1334 1298
1335static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value) 1299static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value)
1336{ 1300{
1337 struct w83627hf_data *data = i2c_get_clientdata(client);
1338 int word_sized; 1301 int word_sized;
1339 1302
1340 mutex_lock(&data->lock); 1303 mutex_lock(&data->lock);
@@ -1344,33 +1307,33 @@ static int w83627hf_write_value(struct i2c_client *client, u16 reg, u16 value)
1344 || ((reg & 0x00ff) == 0x55)); 1307 || ((reg & 0x00ff) == 0x55));
1345 if (reg & 0xff00) { 1308 if (reg & 0xff00) {
1346 outb_p(W83781D_REG_BANK, 1309 outb_p(W83781D_REG_BANK,
1347 client->addr + W83781D_ADDR_REG_OFFSET); 1310 data->addr + W83781D_ADDR_REG_OFFSET);
1348 outb_p(reg >> 8, 1311 outb_p(reg >> 8,
1349 client->addr + W83781D_DATA_REG_OFFSET); 1312 data->addr + W83781D_DATA_REG_OFFSET);
1350 } 1313 }
1351 outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET); 1314 outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET);
1352 if (word_sized) { 1315 if (word_sized) {
1353 outb_p(value >> 8, 1316 outb_p(value >> 8,
1354 client->addr + W83781D_DATA_REG_OFFSET); 1317 data->addr + W83781D_DATA_REG_OFFSET);
1355 outb_p((reg & 0xff) + 1, 1318 outb_p((reg & 0xff) + 1,
1356 client->addr + W83781D_ADDR_REG_OFFSET); 1319 data->addr + W83781D_ADDR_REG_OFFSET);
1357 } 1320 }
1358 outb_p(value & 0xff, 1321 outb_p(value & 0xff,
1359 client->addr + W83781D_DATA_REG_OFFSET); 1322 data->addr + W83781D_DATA_REG_OFFSET);
1360 if (reg & 0xff00) { 1323 if (reg & 0xff00) {
1361 outb_p(W83781D_REG_BANK, 1324 outb_p(W83781D_REG_BANK,
1362 client->addr + W83781D_ADDR_REG_OFFSET); 1325 data->addr + W83781D_ADDR_REG_OFFSET);
1363 outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); 1326 outb_p(0, data->addr + W83781D_DATA_REG_OFFSET);
1364 } 1327 }
1365 mutex_unlock(&data->lock); 1328 mutex_unlock(&data->lock);
1366 return 0; 1329 return 0;
1367} 1330}
1368 1331
1369static void w83627hf_init_client(struct i2c_client *client) 1332static void __devinit w83627hf_init_device(struct platform_device *pdev)
1370{ 1333{
1371 struct w83627hf_data *data = i2c_get_clientdata(client); 1334 struct w83627hf_data *data = platform_get_drvdata(pdev);
1372 int i; 1335 int i;
1373 int type = data->type; 1336 enum chips type = data->type;
1374 u8 tmp; 1337 u8 tmp;
1375 1338
1376 if (reset) { 1339 if (reset) {
@@ -1379,57 +1342,53 @@ static void w83627hf_init_client(struct i2c_client *client)
1379 speed...) so it is now optional. It might even go away if 1342 speed...) so it is now optional. It might even go away if
1380 nobody reports it as being useful, as I see very little 1343 nobody reports it as being useful, as I see very little
1381 reason why this would be needed at all. */ 1344 reason why this would be needed at all. */
1382 dev_info(&client->dev, "If reset=1 solved a problem you were " 1345 dev_info(&pdev->dev, "If reset=1 solved a problem you were "
1383 "having, please report!\n"); 1346 "having, please report!\n");
1384 1347
1385 /* save this register */ 1348 /* save this register */
1386 i = w83627hf_read_value(client, W83781D_REG_BEEP_CONFIG); 1349 i = w83627hf_read_value(data, W83781D_REG_BEEP_CONFIG);
1387 /* Reset all except Watchdog values and last conversion values 1350 /* Reset all except Watchdog values and last conversion values
1388 This sets fan-divs to 2, among others */ 1351 This sets fan-divs to 2, among others */
1389 w83627hf_write_value(client, W83781D_REG_CONFIG, 0x80); 1352 w83627hf_write_value(data, W83781D_REG_CONFIG, 0x80);
1390 /* Restore the register and disable power-on abnormal beep. 1353 /* Restore the register and disable power-on abnormal beep.
1391 This saves FAN 1/2/3 input/output values set by BIOS. */ 1354 This saves FAN 1/2/3 input/output values set by BIOS. */
1392 w83627hf_write_value(client, W83781D_REG_BEEP_CONFIG, i | 0x80); 1355 w83627hf_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80);
1393 /* Disable master beep-enable (reset turns it on). 1356 /* Disable master beep-enable (reset turns it on).
1394 Individual beeps should be reset to off but for some reason 1357 Individual beeps should be reset to off but for some reason
1395 disabling this bit helps some people not get beeped */ 1358 disabling this bit helps some people not get beeped */
1396 w83627hf_write_value(client, W83781D_REG_BEEP_INTS2, 0); 1359 w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, 0);
1397 } 1360 }
1398 1361
1399 /* Minimize conflicts with other winbond i2c-only clients... */ 1362 /* Minimize conflicts with other winbond i2c-only clients... */
1400 /* disable i2c subclients... how to disable main i2c client?? */ 1363 /* disable i2c subclients... how to disable main i2c client?? */
1401 /* force i2c address to relatively uncommon address */ 1364 /* force i2c address to relatively uncommon address */
1402 w83627hf_write_value(client, W83781D_REG_I2C_SUBADDR, 0x89); 1365 w83627hf_write_value(data, W83781D_REG_I2C_SUBADDR, 0x89);
1403 w83627hf_write_value(client, W83781D_REG_I2C_ADDR, force_i2c); 1366 w83627hf_write_value(data, W83781D_REG_I2C_ADDR, force_i2c);
1404 1367
1405 /* Read VID only once */ 1368 /* Read VID only once */
1406 if (w83627hf == data->type || w83637hf == data->type) { 1369 if (type == w83627hf || type == w83637hf) {
1407 int lo = w83627hf_read_value(client, W83781D_REG_VID_FANDIV); 1370 int lo = w83627hf_read_value(data, W83781D_REG_VID_FANDIV);
1408 int hi = w83627hf_read_value(client, W83781D_REG_CHIPID); 1371 int hi = w83627hf_read_value(data, W83781D_REG_CHIPID);
1409 data->vid = (lo & 0x0f) | ((hi & 0x01) << 4); 1372 data->vid = (lo & 0x0f) | ((hi & 0x01) << 4);
1410 } else if (w83627thf == data->type) { 1373 } else if (type == w83627thf) {
1411 data->vid = w83627thf_read_gpio5(client); 1374 data->vid = w83627thf_read_gpio5(pdev);
1412 } else if (w83687thf == data->type) { 1375 } else if (type == w83687thf) {
1413 data->vid = w83687thf_read_vid(client); 1376 data->vid = w83687thf_read_vid(pdev);
1414 } 1377 }
1415 1378
1416 /* Read VRM & OVT Config only once */ 1379 /* Read VRM & OVT Config only once */
1417 if (w83627thf == data->type || w83637hf == data->type 1380 if (type == w83627thf || type == w83637hf || type == w83687thf) {
1418 || w83687thf == data->type) {
1419 data->vrm_ovt = 1381 data->vrm_ovt =
1420 w83627hf_read_value(client, W83627THF_REG_VRM_OVT_CFG); 1382 w83627hf_read_value(data, W83627THF_REG_VRM_OVT_CFG);
1421 } 1383 }
1422 1384
1423 /* Convert VID to voltage based on VRM */ 1385 tmp = w83627hf_read_value(data, W83781D_REG_SCFG1);
1424 data->vrm = vid_which_vrm();
1425
1426 tmp = w83627hf_read_value(client, W83781D_REG_SCFG1);
1427 for (i = 1; i <= 3; i++) { 1386 for (i = 1; i <= 3; i++) {
1428 if (!(tmp & BIT_SCFG1[i - 1])) { 1387 if (!(tmp & BIT_SCFG1[i - 1])) {
1429 data->sens[i - 1] = W83781D_DEFAULT_BETA; 1388 data->sens[i - 1] = W83781D_DEFAULT_BETA;
1430 } else { 1389 } else {
1431 if (w83627hf_read_value 1390 if (w83627hf_read_value
1432 (client, 1391 (data,
1433 W83781D_REG_SCFG2) & BIT_SCFG2[i - 1]) 1392 W83781D_REG_SCFG2) & BIT_SCFG2[i - 1])
1434 data->sens[i - 1] = 1; 1393 data->sens[i - 1] = 1;
1435 else 1394 else
@@ -1441,38 +1400,37 @@ static void w83627hf_init_client(struct i2c_client *client)
1441 1400
1442 if(init) { 1401 if(init) {
1443 /* Enable temp2 */ 1402 /* Enable temp2 */
1444 tmp = w83627hf_read_value(client, W83781D_REG_TEMP2_CONFIG); 1403 tmp = w83627hf_read_value(data, W83781D_REG_TEMP2_CONFIG);
1445 if (tmp & 0x01) { 1404 if (tmp & 0x01) {
1446 dev_warn(&client->dev, "Enabling temp2, readings " 1405 dev_warn(&pdev->dev, "Enabling temp2, readings "
1447 "might not make sense\n"); 1406 "might not make sense\n");
1448 w83627hf_write_value(client, W83781D_REG_TEMP2_CONFIG, 1407 w83627hf_write_value(data, W83781D_REG_TEMP2_CONFIG,
1449 tmp & 0xfe); 1408 tmp & 0xfe);
1450 } 1409 }
1451 1410
1452 /* Enable temp3 */ 1411 /* Enable temp3 */
1453 if (type != w83697hf) { 1412 if (type != w83697hf) {
1454 tmp = w83627hf_read_value(client, 1413 tmp = w83627hf_read_value(data,
1455 W83781D_REG_TEMP3_CONFIG); 1414 W83781D_REG_TEMP3_CONFIG);
1456 if (tmp & 0x01) { 1415 if (tmp & 0x01) {
1457 dev_warn(&client->dev, "Enabling temp3, " 1416 dev_warn(&pdev->dev, "Enabling temp3, "
1458 "readings might not make sense\n"); 1417 "readings might not make sense\n");
1459 w83627hf_write_value(client, 1418 w83627hf_write_value(data,
1460 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe); 1419 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe);
1461 } 1420 }
1462 } 1421 }
1463 } 1422 }
1464 1423
1465 /* Start monitoring */ 1424 /* Start monitoring */
1466 w83627hf_write_value(client, W83781D_REG_CONFIG, 1425 w83627hf_write_value(data, W83781D_REG_CONFIG,
1467 (w83627hf_read_value(client, 1426 (w83627hf_read_value(data,
1468 W83781D_REG_CONFIG) & 0xf7) 1427 W83781D_REG_CONFIG) & 0xf7)
1469 | 0x01); 1428 | 0x01);
1470} 1429}
1471 1430
1472static struct w83627hf_data *w83627hf_update_device(struct device *dev) 1431static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1473{ 1432{
1474 struct i2c_client *client = to_i2c_client(dev); 1433 struct w83627hf_data *data = dev_get_drvdata(dev);
1475 struct w83627hf_data *data = i2c_get_clientdata(client);
1476 int i; 1434 int i;
1477 1435
1478 mutex_lock(&data->update_lock); 1436 mutex_lock(&data->update_lock);
@@ -1486,23 +1444,23 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1486 && (i == 5 || i == 6))) 1444 && (i == 5 || i == 6)))
1487 continue; 1445 continue;
1488 data->in[i] = 1446 data->in[i] =
1489 w83627hf_read_value(client, W83781D_REG_IN(i)); 1447 w83627hf_read_value(data, W83781D_REG_IN(i));
1490 data->in_min[i] = 1448 data->in_min[i] =
1491 w83627hf_read_value(client, 1449 w83627hf_read_value(data,
1492 W83781D_REG_IN_MIN(i)); 1450 W83781D_REG_IN_MIN(i));
1493 data->in_max[i] = 1451 data->in_max[i] =
1494 w83627hf_read_value(client, 1452 w83627hf_read_value(data,
1495 W83781D_REG_IN_MAX(i)); 1453 W83781D_REG_IN_MAX(i));
1496 } 1454 }
1497 for (i = 1; i <= 3; i++) { 1455 for (i = 1; i <= 3; i++) {
1498 data->fan[i - 1] = 1456 data->fan[i - 1] =
1499 w83627hf_read_value(client, W83781D_REG_FAN(i)); 1457 w83627hf_read_value(data, W83781D_REG_FAN(i));
1500 data->fan_min[i - 1] = 1458 data->fan_min[i - 1] =
1501 w83627hf_read_value(client, 1459 w83627hf_read_value(data,
1502 W83781D_REG_FAN_MIN(i)); 1460 W83781D_REG_FAN_MIN(i));
1503 } 1461 }
1504 for (i = 1; i <= 3; i++) { 1462 for (i = 1; i <= 3; i++) {
1505 u8 tmp = w83627hf_read_value(client, 1463 u8 tmp = w83627hf_read_value(data,
1506 W836X7HF_REG_PWM(data->type, i)); 1464 W836X7HF_REG_PWM(data->type, i));
1507 /* bits 0-3 are reserved in 627THF */ 1465 /* bits 0-3 are reserved in 627THF */
1508 if (data->type == w83627thf) 1466 if (data->type == w83627thf)
@@ -1513,47 +1471,47 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1513 break; 1471 break;
1514 } 1472 }
1515 1473
1516 data->temp = w83627hf_read_value(client, W83781D_REG_TEMP(1)); 1474 data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1));
1517 data->temp_max = 1475 data->temp_max =
1518 w83627hf_read_value(client, W83781D_REG_TEMP_OVER(1)); 1476 w83627hf_read_value(data, W83781D_REG_TEMP_OVER(1));
1519 data->temp_max_hyst = 1477 data->temp_max_hyst =
1520 w83627hf_read_value(client, W83781D_REG_TEMP_HYST(1)); 1478 w83627hf_read_value(data, W83781D_REG_TEMP_HYST(1));
1521 data->temp_add[0] = 1479 data->temp_add[0] =
1522 w83627hf_read_value(client, W83781D_REG_TEMP(2)); 1480 w83627hf_read_value(data, W83781D_REG_TEMP(2));
1523 data->temp_max_add[0] = 1481 data->temp_max_add[0] =
1524 w83627hf_read_value(client, W83781D_REG_TEMP_OVER(2)); 1482 w83627hf_read_value(data, W83781D_REG_TEMP_OVER(2));
1525 data->temp_max_hyst_add[0] = 1483 data->temp_max_hyst_add[0] =
1526 w83627hf_read_value(client, W83781D_REG_TEMP_HYST(2)); 1484 w83627hf_read_value(data, W83781D_REG_TEMP_HYST(2));
1527 if (data->type != w83697hf) { 1485 if (data->type != w83697hf) {
1528 data->temp_add[1] = 1486 data->temp_add[1] =
1529 w83627hf_read_value(client, W83781D_REG_TEMP(3)); 1487 w83627hf_read_value(data, W83781D_REG_TEMP(3));
1530 data->temp_max_add[1] = 1488 data->temp_max_add[1] =
1531 w83627hf_read_value(client, W83781D_REG_TEMP_OVER(3)); 1489 w83627hf_read_value(data, W83781D_REG_TEMP_OVER(3));
1532 data->temp_max_hyst_add[1] = 1490 data->temp_max_hyst_add[1] =
1533 w83627hf_read_value(client, W83781D_REG_TEMP_HYST(3)); 1491 w83627hf_read_value(data, W83781D_REG_TEMP_HYST(3));
1534 } 1492 }
1535 1493
1536 i = w83627hf_read_value(client, W83781D_REG_VID_FANDIV); 1494 i = w83627hf_read_value(data, W83781D_REG_VID_FANDIV);
1537 data->fan_div[0] = (i >> 4) & 0x03; 1495 data->fan_div[0] = (i >> 4) & 0x03;
1538 data->fan_div[1] = (i >> 6) & 0x03; 1496 data->fan_div[1] = (i >> 6) & 0x03;
1539 if (data->type != w83697hf) { 1497 if (data->type != w83697hf) {
1540 data->fan_div[2] = (w83627hf_read_value(client, 1498 data->fan_div[2] = (w83627hf_read_value(data,
1541 W83781D_REG_PIN) >> 6) & 0x03; 1499 W83781D_REG_PIN) >> 6) & 0x03;
1542 } 1500 }
1543 i = w83627hf_read_value(client, W83781D_REG_VBAT); 1501 i = w83627hf_read_value(data, W83781D_REG_VBAT);
1544 data->fan_div[0] |= (i >> 3) & 0x04; 1502 data->fan_div[0] |= (i >> 3) & 0x04;
1545 data->fan_div[1] |= (i >> 4) & 0x04; 1503 data->fan_div[1] |= (i >> 4) & 0x04;
1546 if (data->type != w83697hf) 1504 if (data->type != w83697hf)
1547 data->fan_div[2] |= (i >> 5) & 0x04; 1505 data->fan_div[2] |= (i >> 5) & 0x04;
1548 data->alarms = 1506 data->alarms =
1549 w83627hf_read_value(client, W83781D_REG_ALARM1) | 1507 w83627hf_read_value(data, W83781D_REG_ALARM1) |
1550 (w83627hf_read_value(client, W83781D_REG_ALARM2) << 8) | 1508 (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) |
1551 (w83627hf_read_value(client, W83781D_REG_ALARM3) << 16); 1509 (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16);
1552 i = w83627hf_read_value(client, W83781D_REG_BEEP_INTS2); 1510 i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2);
1553 data->beep_enable = i >> 7; 1511 data->beep_enable = i >> 7;
1554 data->beep_mask = ((i & 0x7f) << 8) | 1512 data->beep_mask = ((i & 0x7f) << 8) |
1555 w83627hf_read_value(client, W83781D_REG_BEEP_INTS1) | 1513 w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) |
1556 w83627hf_read_value(client, W83781D_REG_BEEP_INTS3) << 16; 1514 w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16;
1557 data->last_updated = jiffies; 1515 data->last_updated = jiffies;
1558 data->valid = 1; 1516 data->valid = 1;
1559 } 1517 }
@@ -1563,19 +1521,87 @@ static struct w83627hf_data *w83627hf_update_device(struct device *dev)
1563 return data; 1521 return data;
1564} 1522}
1565 1523
1524static int __init w83627hf_device_add(unsigned short address,
1525 const struct w83627hf_sio_data *sio_data)
1526{
1527 struct resource res = {
1528 .start = address + WINB_REGION_OFFSET,
1529 .end = address + WINB_REGION_OFFSET + WINB_REGION_SIZE - 1,
1530 .name = DRVNAME,
1531 .flags = IORESOURCE_IO,
1532 };
1533 int err;
1534
1535 pdev = platform_device_alloc(DRVNAME, address);
1536 if (!pdev) {
1537 err = -ENOMEM;
1538 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
1539 goto exit;
1540 }
1541
1542 err = platform_device_add_resources(pdev, &res, 1);
1543 if (err) {
1544 printk(KERN_ERR DRVNAME ": Device resource addition failed "
1545 "(%d)\n", err);
1546 goto exit_device_put;
1547 }
1548
1549 pdev->dev.platform_data = kmalloc(sizeof(struct w83627hf_sio_data),
1550 GFP_KERNEL);
1551 if (!pdev->dev.platform_data) {
1552 err = -ENOMEM;
1553 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
1554 goto exit_device_put;
1555 }
1556 memcpy(pdev->dev.platform_data, sio_data,
1557 sizeof(struct w83627hf_sio_data));
1558
1559 err = platform_device_add(pdev);
1560 if (err) {
1561 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1562 err);
1563 goto exit_device_put;
1564 }
1565
1566 return 0;
1567
1568exit_device_put:
1569 platform_device_put(pdev);
1570exit:
1571 return err;
1572}
1573
1566static int __init sensors_w83627hf_init(void) 1574static int __init sensors_w83627hf_init(void)
1567{ 1575{
1568 if (w83627hf_find(0x2e, &address) 1576 int err;
1569 && w83627hf_find(0x4e, &address)) { 1577 unsigned short address;
1578 struct w83627hf_sio_data sio_data;
1579
1580 if (w83627hf_find(0x2e, &address, &sio_data)
1581 && w83627hf_find(0x4e, &address, &sio_data))
1570 return -ENODEV; 1582 return -ENODEV;
1571 }
1572 1583
1573 return i2c_isa_add_driver(&w83627hf_driver); 1584 err = platform_driver_register(&w83627hf_driver);
1585 if (err)
1586 goto exit;
1587
1588 /* Sets global pdev as a side effect */
1589 err = w83627hf_device_add(address, &sio_data);
1590 if (err)
1591 goto exit_driver;
1592
1593 return 0;
1594
1595exit_driver:
1596 platform_driver_unregister(&w83627hf_driver);
1597exit:
1598 return err;
1574} 1599}
1575 1600
1576static void __exit sensors_w83627hf_exit(void) 1601static void __exit sensors_w83627hf_exit(void)
1577{ 1602{
1578 i2c_isa_del_driver(&w83627hf_driver); 1603 platform_device_unregister(pdev);
1604 platform_driver_unregister(&w83627hf_driver);
1579} 1605}
1580 1606
1581MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " 1607MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index a47da3ec5472..f85b48fea1c4 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -2,8 +2,9 @@
2 w83781d.c - Part of lm_sensors, Linux kernel modules for hardware 2 w83781d.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 monitoring
4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>, 4 Copyright (c) 1998 - 2001 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, 5 Philip Edelbrock <phil@netroedge.com>,
6 and Mark Studebaker <mdsxyz123@yahoo.com> 6 and Mark Studebaker <mdsxyz123@yahoo.com>
7 Copyright (c) 2007 Jean Delvare <khali@linux-fr.org>
7 8
8 This program is free software; you can redistribute it and/or modify 9 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 it under the terms of the GNU General Public License as published by
@@ -38,15 +39,20 @@
38#include <linux/slab.h> 39#include <linux/slab.h>
39#include <linux/jiffies.h> 40#include <linux/jiffies.h>
40#include <linux/i2c.h> 41#include <linux/i2c.h>
41#include <linux/i2c-isa.h> 42#include <linux/platform_device.h>
43#include <linux/ioport.h>
42#include <linux/hwmon.h> 44#include <linux/hwmon.h>
43#include <linux/hwmon-vid.h> 45#include <linux/hwmon-vid.h>
46#include <linux/hwmon-sysfs.h>
44#include <linux/sysfs.h> 47#include <linux/sysfs.h>
45#include <linux/err.h> 48#include <linux/err.h>
46#include <linux/mutex.h> 49#include <linux/mutex.h>
47#include <asm/io.h> 50#include <asm/io.h>
48#include "lm75.h" 51#include "lm75.h"
49 52
53/* ISA device, if found */
54static struct platform_device *pdev;
55
50/* Addresses to scan */ 56/* Addresses to scan */
51static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 57static unsigned short normal_i2c[] = { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
52 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 58 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
@@ -75,8 +81,8 @@ MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
75#define W83781D_ADDR_REG_OFFSET 5 81#define W83781D_ADDR_REG_OFFSET 5
76#define W83781D_DATA_REG_OFFSET 6 82#define W83781D_DATA_REG_OFFSET 6
77 83
78/* The W83781D registers */ 84/* The device registers */
79/* The W83782D registers for nr=7,8 are in bank 5 */ 85/* in nr from 0 to 8 */
80#define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \ 86#define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \
81 (0x554 + (((nr) - 7) * 2))) 87 (0x554 + (((nr) - 7) * 2)))
82#define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \ 88#define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \
@@ -84,12 +90,14 @@ MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
84#define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ 90#define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \
85 (0x550 + (nr) - 7)) 91 (0x550 + (nr) - 7))
86 92
87#define W83781D_REG_FAN_MIN(nr) (0x3a + (nr)) 93/* fan nr from 0 to 2 */
88#define W83781D_REG_FAN(nr) (0x27 + (nr)) 94#define W83781D_REG_FAN_MIN(nr) (0x3b + (nr))
95#define W83781D_REG_FAN(nr) (0x28 + (nr))
89 96
90#define W83781D_REG_BANK 0x4E 97#define W83781D_REG_BANK 0x4E
91#define W83781D_REG_TEMP2_CONFIG 0x152 98#define W83781D_REG_TEMP2_CONFIG 0x152
92#define W83781D_REG_TEMP3_CONFIG 0x252 99#define W83781D_REG_TEMP3_CONFIG 0x252
100/* temp nr from 1 to 3 */
93#define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \ 101#define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \
94 ((nr == 2) ? (0x0150) : \ 102 ((nr == 2) ? (0x0150) : \
95 (0x27))) 103 (0x27)))
@@ -127,19 +135,9 @@ MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization");
127#define W83781D_REG_VBAT 0x5D 135#define W83781D_REG_VBAT 0x5D
128 136
129/* PWM 782D (1-4) and 783S (1-2) only */ 137/* PWM 782D (1-4) and 783S (1-2) only */
130#define W83781D_REG_PWM1 0x5B /* 782d and 783s/627hf datasheets disagree */ 138static const u8 W83781D_REG_PWM[] = { 0x5B, 0x5A, 0x5E, 0x5F };
131 /* on which is which; */
132#define W83781D_REG_PWM2 0x5A /* We follow the 782d convention here, */
133 /* However 782d is probably wrong. */
134#define W83781D_REG_PWM3 0x5E
135#define W83781D_REG_PWM4 0x5F
136#define W83781D_REG_PWMCLK12 0x5C 139#define W83781D_REG_PWMCLK12 0x5C
137#define W83781D_REG_PWMCLK34 0x45C 140#define W83781D_REG_PWMCLK34 0x45C
138static const u8 regpwm[] = { W83781D_REG_PWM1, W83781D_REG_PWM2,
139 W83781D_REG_PWM3, W83781D_REG_PWM4
140};
141
142#define W83781D_REG_PWM(nr) (regpwm[(nr) - 1])
143 141
144#define W83781D_REG_I2C_ADDR 0x48 142#define W83781D_REG_I2C_ADDR 0x48
145#define W83781D_REG_I2C_SUBADDR 0x4A 143#define W83781D_REG_I2C_SUBADDR 0x4A
@@ -159,12 +157,9 @@ static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 };
159#define W83781D_REG_RT_IDX 0x50 157#define W83781D_REG_RT_IDX 0x50
160#define W83781D_REG_RT_VAL 0x51 158#define W83781D_REG_RT_VAL 0x51
161 159
162/* Conversions. Rounding and limit checking is only done on the TO_REG 160/* Conversions */
163 variants. Note that you should be a bit careful with which arguments 161#define IN_TO_REG(val) SENSORS_LIMIT(((val) + 8) / 16, 0, 255)
164 these macros are called: arguments may be evaluated more than once. 162#define IN_FROM_REG(val) ((val) * 16)
165 Fixing this is just not worth it. */
166#define IN_TO_REG(val) (SENSORS_LIMIT((((val) * 10 + 8)/16),0,255))
167#define IN_FROM_REG(val) (((val) * 16) / 10)
168 163
169static inline u8 164static inline u8
170FAN_TO_REG(long rpm, int div) 165FAN_TO_REG(long rpm, int div)
@@ -175,24 +170,24 @@ FAN_TO_REG(long rpm, int div)
175 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254); 170 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
176} 171}
177 172
178#define FAN_FROM_REG(val,div) ((val) == 0 ? -1 : \ 173static inline long
179 ((val) == 255 ? 0 : \ 174FAN_FROM_REG(u8 val, int div)
180 1350000 / ((val) * (div)))) 175{
176 if (val == 0)
177 return -1;
178 if (val == 255)
179 return 0;
180 return 1350000 / (val * div);
181}
181 182
182#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (val)+0x100*1000 \ 183#define TEMP_TO_REG(val) SENSORS_LIMIT((val) / 1000, -127, 128)
183 : (val)) / 1000, 0, 0xff)) 184#define TEMP_FROM_REG(val) ((val) * 1000)
184#define TEMP_FROM_REG(val) (((val) & 0x80 ? (val)-0x100 : (val)) * 1000)
185 185
186#define PWM_FROM_REG(val) (val)
187#define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255))
188#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \ 186#define BEEP_MASK_FROM_REG(val,type) ((type) == as99127f ? \
189 (val) ^ 0x7fff : (val)) 187 (val) ^ 0x7fff : (val))
190#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \ 188#define BEEP_MASK_TO_REG(val,type) ((type) == as99127f ? \
191 (~(val)) & 0x7fff : (val) & 0xffffff) 189 (~(val)) & 0x7fff : (val) & 0xffffff)
192 190
193#define BEEP_ENABLE_TO_REG(val) ((val) ? 1 : 0)
194#define BEEP_ENABLE_FROM_REG(val) ((val) ? 1 : 0)
195
196#define DIV_FROM_REG(val) (1 << (val)) 191#define DIV_FROM_REG(val) (1 << (val))
197 192
198static inline u8 193static inline u8
@@ -207,7 +202,7 @@ DIV_TO_REG(long val, enum chips type)
207 break; 202 break;
208 val >>= 1; 203 val >>= 1;
209 } 204 }
210 return ((u8) i); 205 return i;
211} 206}
212 207
213/* There are some complications in a module like this. First off, W83781D chips 208/* There are some complications in a module like this. First off, W83781D chips
@@ -221,8 +216,8 @@ DIV_TO_REG(long val, enum chips type)
221 a bit - except if there could be more than one SMBus. Groan. No solution 216 a bit - except if there could be more than one SMBus. Groan. No solution
222 for this yet. */ 217 for this yet. */
223 218
224/* For each registered chip, we need to keep some data in memory. 219/* For ISA chips, we abuse the i2c_client addr and name fields. We also use
225 The structure is dynamically allocated. */ 220 the driver field to differentiate between I2C and ISA chips. */
226struct w83781d_data { 221struct w83781d_data {
227 struct i2c_client client; 222 struct i2c_client client;
228 struct class_device *class_dev; 223 struct class_device *class_dev;
@@ -241,9 +236,9 @@ struct w83781d_data {
241 u8 in_min[9]; /* Register value - 8 & 9 for 782D only */ 236 u8 in_min[9]; /* Register value - 8 & 9 for 782D only */
242 u8 fan[3]; /* Register value */ 237 u8 fan[3]; /* Register value */
243 u8 fan_min[3]; /* Register value */ 238 u8 fan_min[3]; /* Register value */
244 u8 temp; 239 s8 temp; /* Register value */
245 u8 temp_max; /* Register value */ 240 s8 temp_max; /* Register value */
246 u8 temp_max_hyst; /* Register value */ 241 s8 temp_max_hyst; /* Register value */
247 u16 temp_add[2]; /* Register value */ 242 u16 temp_add[2]; /* Register value */
248 u16 temp_max_add[2]; /* Register value */ 243 u16 temp_max_add[2]; /* Register value */
249 u16 temp_max_hyst_add[2]; /* Register value */ 244 u16 temp_max_hyst_add[2]; /* Register value */
@@ -253,7 +248,7 @@ struct w83781d_data {
253 u32 beep_mask; /* Register encoding, combined */ 248 u32 beep_mask; /* Register encoding, combined */
254 u8 beep_enable; /* Boolean */ 249 u8 beep_enable; /* Boolean */
255 u8 pwm[4]; /* Register value */ 250 u8 pwm[4]; /* Register value */
256 u8 pwmenable[4]; /* Boolean */ 251 u8 pwm2_enable; /* Boolean */
257 u16 sens[3]; /* 782D/783S only. 252 u16 sens[3]; /* 782D/783S only.
258 1 = pentium diode; 2 = 3904 diode; 253 1 = pentium diode; 2 = 3904 diode;
259 3000-5000 = thermistor beta. 254 3000-5000 = thermistor beta.
@@ -263,14 +258,16 @@ struct w83781d_data {
263}; 258};
264 259
265static int w83781d_attach_adapter(struct i2c_adapter *adapter); 260static int w83781d_attach_adapter(struct i2c_adapter *adapter);
266static int w83781d_isa_attach_adapter(struct i2c_adapter *adapter);
267static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind); 261static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind);
268static int w83781d_detach_client(struct i2c_client *client); 262static int w83781d_detach_client(struct i2c_client *client);
269 263
270static int w83781d_read_value(struct i2c_client *client, u16 reg); 264static int __devinit w83781d_isa_probe(struct platform_device *pdev);
271static int w83781d_write_value(struct i2c_client *client, u16 reg, u16 value); 265static int __devexit w83781d_isa_remove(struct platform_device *pdev);
266
267static int w83781d_read_value(struct w83781d_data *data, u16 reg);
268static int w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value);
272static struct w83781d_data *w83781d_update_device(struct device *dev); 269static struct w83781d_data *w83781d_update_device(struct device *dev);
273static void w83781d_init_client(struct i2c_client *client); 270static void w83781d_init_device(struct device *dev);
274 271
275static struct i2c_driver w83781d_driver = { 272static struct i2c_driver w83781d_driver = {
276 .driver = { 273 .driver = {
@@ -281,39 +278,44 @@ static struct i2c_driver w83781d_driver = {
281 .detach_client = w83781d_detach_client, 278 .detach_client = w83781d_detach_client,
282}; 279};
283 280
284static struct i2c_driver w83781d_isa_driver = { 281static struct platform_driver w83781d_isa_driver = {
285 .driver = { 282 .driver = {
286 .owner = THIS_MODULE, 283 .owner = THIS_MODULE,
287 .name = "w83781d-isa", 284 .name = "w83781d",
288 }, 285 },
289 .attach_adapter = w83781d_isa_attach_adapter, 286 .probe = w83781d_isa_probe,
290 .detach_client = w83781d_detach_client, 287 .remove = w83781d_isa_remove,
291}; 288};
292 289
293 290
294/* following are the sysfs callback functions */ 291/* following are the sysfs callback functions */
295#define show_in_reg(reg) \ 292#define show_in_reg(reg) \
296static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 293static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
294 char *buf) \
297{ \ 295{ \
296 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
298 struct w83781d_data *data = w83781d_update_device(dev); \ 297 struct w83781d_data *data = w83781d_update_device(dev); \
299 return sprintf(buf,"%ld\n", (long)IN_FROM_REG(data->reg[nr] * 10)); \ 298 return sprintf(buf, "%ld\n", \
299 (long)IN_FROM_REG(data->reg[attr->index])); \
300} 300}
301show_in_reg(in); 301show_in_reg(in);
302show_in_reg(in_min); 302show_in_reg(in_min);
303show_in_reg(in_max); 303show_in_reg(in_max);
304 304
305#define store_in_reg(REG, reg) \ 305#define store_in_reg(REG, reg) \
306static ssize_t store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \ 306static ssize_t store_in_##reg (struct device *dev, struct device_attribute \
307 *da, const char *buf, size_t count) \
307{ \ 308{ \
308 struct i2c_client *client = to_i2c_client(dev); \ 309 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
309 struct w83781d_data *data = i2c_get_clientdata(client); \ 310 struct w83781d_data *data = dev_get_drvdata(dev); \
311 int nr = attr->index; \
310 u32 val; \ 312 u32 val; \
311 \ 313 \
312 val = simple_strtoul(buf, NULL, 10) / 10; \ 314 val = simple_strtoul(buf, NULL, 10); \
313 \ 315 \
314 mutex_lock(&data->update_lock); \ 316 mutex_lock(&data->update_lock); \
315 data->in_##reg[nr] = IN_TO_REG(val); \ 317 data->in_##reg[nr] = IN_TO_REG(val); \
316 w83781d_write_value(client, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \ 318 w83781d_write_value(data, W83781D_REG_IN_##REG(nr), data->in_##reg[nr]); \
317 \ 319 \
318 mutex_unlock(&data->update_lock); \ 320 mutex_unlock(&data->update_lock); \
319 return count; \ 321 return count; \
@@ -321,29 +323,13 @@ static ssize_t store_in_##reg (struct device *dev, const char *buf, size_t count
321store_in_reg(MIN, min); 323store_in_reg(MIN, min);
322store_in_reg(MAX, max); 324store_in_reg(MAX, max);
323 325
324#define sysfs_in_offset(offset) \
325static ssize_t \
326show_regs_in_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
327{ \
328 return show_in(dev, buf, offset); \
329} \
330static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_regs_in_##offset, NULL);
331
332#define sysfs_in_reg_offset(reg, offset) \
333static ssize_t show_regs_in_##reg##offset (struct device *dev, struct device_attribute *attr, char *buf) \
334{ \
335 return show_in_##reg (dev, buf, offset); \
336} \
337static ssize_t store_regs_in_##reg##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
338{ \
339 return store_in_##reg (dev, buf, count, offset); \
340} \
341static DEVICE_ATTR(in##offset##_##reg, S_IRUGO| S_IWUSR, show_regs_in_##reg##offset, store_regs_in_##reg##offset);
342
343#define sysfs_in_offsets(offset) \ 326#define sysfs_in_offsets(offset) \
344sysfs_in_offset(offset); \ 327static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
345sysfs_in_reg_offset(min, offset); \ 328 show_in, NULL, offset); \
346sysfs_in_reg_offset(max, offset); 329static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
330 show_in_min, store_in_min, offset); \
331static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
332 show_in_max, store_in_max, offset)
347 333
348sysfs_in_offsets(0); 334sysfs_in_offsets(0);
349sysfs_in_offsets(1); 335sysfs_in_offsets(1);
@@ -356,63 +342,56 @@ sysfs_in_offsets(7);
356sysfs_in_offsets(8); 342sysfs_in_offsets(8);
357 343
358#define show_fan_reg(reg) \ 344#define show_fan_reg(reg) \
359static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 345static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
346 char *buf) \
360{ \ 347{ \
348 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
361 struct w83781d_data *data = w83781d_update_device(dev); \ 349 struct w83781d_data *data = w83781d_update_device(dev); \
362 return sprintf(buf,"%ld\n", \ 350 return sprintf(buf,"%ld\n", \
363 FAN_FROM_REG(data->reg[nr-1], (long)DIV_FROM_REG(data->fan_div[nr-1]))); \ 351 FAN_FROM_REG(data->reg[attr->index], \
352 DIV_FROM_REG(data->fan_div[attr->index]))); \
364} 353}
365show_fan_reg(fan); 354show_fan_reg(fan);
366show_fan_reg(fan_min); 355show_fan_reg(fan_min);
367 356
368static ssize_t 357static ssize_t
369store_fan_min(struct device *dev, const char *buf, size_t count, int nr) 358store_fan_min(struct device *dev, struct device_attribute *da,
359 const char *buf, size_t count)
370{ 360{
371 struct i2c_client *client = to_i2c_client(dev); 361 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
372 struct w83781d_data *data = i2c_get_clientdata(client); 362 struct w83781d_data *data = dev_get_drvdata(dev);
363 int nr = attr->index;
373 u32 val; 364 u32 val;
374 365
375 val = simple_strtoul(buf, NULL, 10); 366 val = simple_strtoul(buf, NULL, 10);
376 367
377 mutex_lock(&data->update_lock); 368 mutex_lock(&data->update_lock);
378 data->fan_min[nr - 1] = 369 data->fan_min[nr] =
379 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); 370 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
380 w83781d_write_value(client, W83781D_REG_FAN_MIN(nr), 371 w83781d_write_value(data, W83781D_REG_FAN_MIN(nr),
381 data->fan_min[nr - 1]); 372 data->fan_min[nr]);
382 373
383 mutex_unlock(&data->update_lock); 374 mutex_unlock(&data->update_lock);
384 return count; 375 return count;
385} 376}
386 377
387#define sysfs_fan_offset(offset) \ 378static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
388static ssize_t show_regs_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 379static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
389{ \ 380 show_fan_min, store_fan_min, 0);
390 return show_fan(dev, buf, offset); \ 381static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
391} \ 382static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
392static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_regs_fan_##offset, NULL); 383 show_fan_min, store_fan_min, 1);
393 384static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
394#define sysfs_fan_min_offset(offset) \ 385static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR,
395static ssize_t show_regs_fan_min##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 386 show_fan_min, store_fan_min, 2);
396{ \
397 return show_fan_min(dev, buf, offset); \
398} \
399static ssize_t store_regs_fan_min##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
400{ \
401 return store_fan_min(dev, buf, count, offset); \
402} \
403static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, show_regs_fan_min##offset, store_regs_fan_min##offset);
404
405sysfs_fan_offset(1);
406sysfs_fan_min_offset(1);
407sysfs_fan_offset(2);
408sysfs_fan_min_offset(2);
409sysfs_fan_offset(3);
410sysfs_fan_min_offset(3);
411 387
412#define show_temp_reg(reg) \ 388#define show_temp_reg(reg) \
413static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 389static ssize_t show_##reg (struct device *dev, struct device_attribute *da, \
390 char *buf) \
414{ \ 391{ \
392 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
415 struct w83781d_data *data = w83781d_update_device(dev); \ 393 struct w83781d_data *data = w83781d_update_device(dev); \
394 int nr = attr->index; \
416 if (nr >= 2) { /* TEMP2 and TEMP3 */ \ 395 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
417 return sprintf(buf,"%d\n", \ 396 return sprintf(buf,"%d\n", \
418 LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \ 397 LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \
@@ -425,10 +404,12 @@ show_temp_reg(temp_max);
425show_temp_reg(temp_max_hyst); 404show_temp_reg(temp_max_hyst);
426 405
427#define store_temp_reg(REG, reg) \ 406#define store_temp_reg(REG, reg) \
428static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ 407static ssize_t store_temp_##reg (struct device *dev, \
408 struct device_attribute *da, const char *buf, size_t count) \
429{ \ 409{ \
430 struct i2c_client *client = to_i2c_client(dev); \ 410 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); \
431 struct w83781d_data *data = i2c_get_clientdata(client); \ 411 struct w83781d_data *data = dev_get_drvdata(dev); \
412 int nr = attr->index; \
432 s32 val; \ 413 s32 val; \
433 \ 414 \
434 val = simple_strtol(buf, NULL, 10); \ 415 val = simple_strtol(buf, NULL, 10); \
@@ -437,11 +418,11 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou
437 \ 418 \
438 if (nr >= 2) { /* TEMP2 and TEMP3 */ \ 419 if (nr >= 2) { /* TEMP2 and TEMP3 */ \
439 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ 420 data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \
440 w83781d_write_value(client, W83781D_REG_TEMP_##REG(nr), \ 421 w83781d_write_value(data, W83781D_REG_TEMP_##REG(nr), \
441 data->temp_##reg##_add[nr-2]); \ 422 data->temp_##reg##_add[nr-2]); \
442 } else { /* TEMP1 */ \ 423 } else { /* TEMP1 */ \
443 data->temp_##reg = TEMP_TO_REG(val); \ 424 data->temp_##reg = TEMP_TO_REG(val); \
444 w83781d_write_value(client, W83781D_REG_TEMP_##REG(nr), \ 425 w83781d_write_value(data, W83781D_REG_TEMP_##REG(nr), \
445 data->temp_##reg); \ 426 data->temp_##reg); \
446 } \ 427 } \
447 \ 428 \
@@ -451,29 +432,13 @@ static ssize_t store_temp_##reg (struct device *dev, const char *buf, size_t cou
451store_temp_reg(OVER, max); 432store_temp_reg(OVER, max);
452store_temp_reg(HYST, max_hyst); 433store_temp_reg(HYST, max_hyst);
453 434
454#define sysfs_temp_offset(offset) \
455static ssize_t \
456show_regs_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
457{ \
458 return show_temp(dev, buf, offset); \
459} \
460static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_regs_temp_##offset, NULL);
461
462#define sysfs_temp_reg_offset(reg, offset) \
463static ssize_t show_regs_temp_##reg##offset (struct device *dev, struct device_attribute *attr, char *buf) \
464{ \
465 return show_temp_##reg (dev, buf, offset); \
466} \
467static ssize_t store_regs_temp_##reg##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
468{ \
469 return store_temp_##reg (dev, buf, count, offset); \
470} \
471static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, show_regs_temp_##reg##offset, store_regs_temp_##reg##offset);
472
473#define sysfs_temp_offsets(offset) \ 435#define sysfs_temp_offsets(offset) \
474sysfs_temp_offset(offset); \ 436static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
475sysfs_temp_reg_offset(max, offset); \ 437 show_temp, NULL, offset); \
476sysfs_temp_reg_offset(max_hyst, offset); 438static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
439 show_temp_max, store_temp_max, offset); \
440static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
441 show_temp_max_hyst, store_temp_max_hyst, offset);
477 442
478sysfs_temp_offsets(1); 443sysfs_temp_offsets(1);
479sysfs_temp_offsets(2); 444sysfs_temp_offsets(2);
@@ -498,8 +463,7 @@ show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
498static ssize_t 463static ssize_t
499store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 464store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
500{ 465{
501 struct i2c_client *client = to_i2c_client(dev); 466 struct w83781d_data *data = dev_get_drvdata(dev);
502 struct w83781d_data *data = i2c_get_clientdata(client);
503 u32 val; 467 u32 val;
504 468
505 val = simple_strtoul(buf, NULL, 10); 469 val = simple_strtoul(buf, NULL, 10);
@@ -528,68 +492,67 @@ static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr
528static ssize_t show_beep_enable (struct device *dev, struct device_attribute *attr, char *buf) 492static ssize_t show_beep_enable (struct device *dev, struct device_attribute *attr, char *buf)
529{ 493{
530 struct w83781d_data *data = w83781d_update_device(dev); 494 struct w83781d_data *data = w83781d_update_device(dev);
531 return sprintf(buf, "%ld\n", 495 return sprintf(buf, "%ld\n", (long)data->beep_enable);
532 (long)BEEP_ENABLE_FROM_REG(data->beep_enable));
533} 496}
534 497
535#define BEEP_ENABLE 0 /* Store beep_enable */
536#define BEEP_MASK 1 /* Store beep_mask */
537
538static ssize_t 498static ssize_t
539store_beep_reg(struct device *dev, const char *buf, size_t count, 499store_beep_mask(struct device *dev, struct device_attribute *attr,
540 int update_mask) 500 const char *buf, size_t count)
541{ 501{
542 struct i2c_client *client = to_i2c_client(dev); 502 struct w83781d_data *data = dev_get_drvdata(dev);
543 struct w83781d_data *data = i2c_get_clientdata(client); 503 u32 val;
544 u32 val, val2;
545 504
546 val = simple_strtoul(buf, NULL, 10); 505 val = simple_strtoul(buf, NULL, 10);
547 506
548 mutex_lock(&data->update_lock); 507 mutex_lock(&data->update_lock);
508 data->beep_mask = BEEP_MASK_TO_REG(val, data->type);
509 w83781d_write_value(data, W83781D_REG_BEEP_INTS1,
510 data->beep_mask & 0xff);
511 w83781d_write_value(data, W83781D_REG_BEEP_INTS2,
512 ((data->beep_mask >> 8) & 0x7f)
513 | data->beep_enable << 7);
514 if (data->type != w83781d && data->type != as99127f) {
515 w83781d_write_value(data, W83781D_REG_BEEP_INTS3,
516 ((data->beep_mask) >> 16) & 0xff);
517 }
518 mutex_unlock(&data->update_lock);
549 519
550 if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ 520 return count;
551 data->beep_mask = BEEP_MASK_TO_REG(val, data->type); 521}
552 w83781d_write_value(client, W83781D_REG_BEEP_INTS1,
553 data->beep_mask & 0xff);
554
555 if ((data->type != w83781d) && (data->type != as99127f)) {
556 w83781d_write_value(client, W83781D_REG_BEEP_INTS3,
557 ((data->beep_mask) >> 16) & 0xff);
558 }
559 522
560 val2 = (data->beep_mask >> 8) & 0x7f; 523static ssize_t
561 } else { /* We are storing beep_enable */ 524store_beep_enable(struct device *dev, struct device_attribute *attr,
562 val2 = w83781d_read_value(client, W83781D_REG_BEEP_INTS2) & 0x7f; 525 const char *buf, size_t count)
563 data->beep_enable = BEEP_ENABLE_TO_REG(val); 526{
564 } 527 struct w83781d_data *data = dev_get_drvdata(dev);
528 u32 val;
565 529
566 w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 530 val = simple_strtoul(buf, NULL, 10);
567 val2 | data->beep_enable << 7); 531 if (val != 0 && val != 1)
532 return -EINVAL;
568 533
534 mutex_lock(&data->update_lock);
535 data->beep_enable = val;
536 val = w83781d_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f;
537 val |= data->beep_enable << 7;
538 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, val);
569 mutex_unlock(&data->update_lock); 539 mutex_unlock(&data->update_lock);
540
570 return count; 541 return count;
571} 542}
572 543
573#define sysfs_beep(REG, reg) \ 544static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
574static ssize_t show_regs_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ 545 show_beep_mask, store_beep_mask);
575{ \ 546static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
576 return show_beep_##reg(dev, attr, buf); \ 547 show_beep_enable, store_beep_enable);
577} \
578static ssize_t store_regs_beep_##reg (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \
579{ \
580 return store_beep_reg(dev, buf, count, BEEP_##REG); \
581} \
582static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, show_regs_beep_##reg, store_regs_beep_##reg);
583
584sysfs_beep(ENABLE, enable);
585sysfs_beep(MASK, mask);
586 548
587static ssize_t 549static ssize_t
588show_fan_div_reg(struct device *dev, char *buf, int nr) 550show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
589{ 551{
552 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
590 struct w83781d_data *data = w83781d_update_device(dev); 553 struct w83781d_data *data = w83781d_update_device(dev);
591 return sprintf(buf, "%ld\n", 554 return sprintf(buf, "%ld\n",
592 (long) DIV_FROM_REG(data->fan_div[nr - 1])); 555 (long) DIV_FROM_REG(data->fan_div[attr->index]));
593} 556}
594 557
595/* Note: we save and restore the fan minimum here, because its value is 558/* Note: we save and restore the fan minimum here, because its value is
@@ -597,11 +560,13 @@ show_fan_div_reg(struct device *dev, char *buf, int nr)
597 least surprise; the user doesn't expect the fan minimum to change just 560 least surprise; the user doesn't expect the fan minimum to change just
598 because the divisor changed. */ 561 because the divisor changed. */
599static ssize_t 562static ssize_t
600store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) 563store_fan_div(struct device *dev, struct device_attribute *da,
564 const char *buf, size_t count)
601{ 565{
602 struct i2c_client *client = to_i2c_client(dev); 566 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
603 struct w83781d_data *data = i2c_get_clientdata(client); 567 struct w83781d_data *data = dev_get_drvdata(dev);
604 unsigned long min; 568 unsigned long min;
569 int nr = attr->index;
605 u8 reg; 570 u8 reg;
606 unsigned long val = simple_strtoul(buf, NULL, 10); 571 unsigned long val = simple_strtoul(buf, NULL, 10);
607 572
@@ -613,77 +578,72 @@ store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr)
613 578
614 data->fan_div[nr] = DIV_TO_REG(val, data->type); 579 data->fan_div[nr] = DIV_TO_REG(val, data->type);
615 580
616 reg = (w83781d_read_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV) 581 reg = (w83781d_read_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV)
617 & (nr==0 ? 0xcf : 0x3f)) 582 & (nr==0 ? 0xcf : 0x3f))
618 | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6)); 583 | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6));
619 w83781d_write_value(client, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg); 584 w83781d_write_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg);
620 585
621 /* w83781d and as99127f don't have extended divisor bits */ 586 /* w83781d and as99127f don't have extended divisor bits */
622 if (data->type != w83781d && data->type != as99127f) { 587 if (data->type != w83781d && data->type != as99127f) {
623 reg = (w83781d_read_value(client, W83781D_REG_VBAT) 588 reg = (w83781d_read_value(data, W83781D_REG_VBAT)
624 & ~(1 << (5 + nr))) 589 & ~(1 << (5 + nr)))
625 | ((data->fan_div[nr] & 0x04) << (3 + nr)); 590 | ((data->fan_div[nr] & 0x04) << (3 + nr));
626 w83781d_write_value(client, W83781D_REG_VBAT, reg); 591 w83781d_write_value(data, W83781D_REG_VBAT, reg);
627 } 592 }
628 593
629 /* Restore fan_min */ 594 /* Restore fan_min */
630 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); 595 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
631 w83781d_write_value(client, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); 596 w83781d_write_value(data, W83781D_REG_FAN_MIN(nr), data->fan_min[nr]);
632 597
633 mutex_unlock(&data->update_lock); 598 mutex_unlock(&data->update_lock);
634 return count; 599 return count;
635} 600}
636 601
637#define sysfs_fan_div(offset) \ 602static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR,
638static ssize_t show_regs_fan_div_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 603 show_fan_div, store_fan_div, 0);
639{ \ 604static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR,
640 return show_fan_div_reg(dev, buf, offset); \ 605 show_fan_div, store_fan_div, 1);
641} \ 606static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR,
642static ssize_t store_regs_fan_div_##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 607 show_fan_div, store_fan_div, 2);
643{ \
644 return store_fan_div_reg(dev, buf, count, offset - 1); \
645} \
646static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, show_regs_fan_div_##offset, store_regs_fan_div_##offset);
647
648sysfs_fan_div(1);
649sysfs_fan_div(2);
650sysfs_fan_div(3);
651 608
652static ssize_t 609static ssize_t
653show_pwm_reg(struct device *dev, char *buf, int nr) 610show_pwm(struct device *dev, struct device_attribute *da, char *buf)
654{ 611{
612 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
655 struct w83781d_data *data = w83781d_update_device(dev); 613 struct w83781d_data *data = w83781d_update_device(dev);
656 return sprintf(buf, "%ld\n", (long) PWM_FROM_REG(data->pwm[nr - 1])); 614 return sprintf(buf, "%d\n", (int)data->pwm[attr->index]);
657} 615}
658 616
659static ssize_t 617static ssize_t
660show_pwmenable_reg(struct device *dev, char *buf, int nr) 618show_pwm2_enable(struct device *dev, struct device_attribute *da, char *buf)
661{ 619{
662 struct w83781d_data *data = w83781d_update_device(dev); 620 struct w83781d_data *data = w83781d_update_device(dev);
663 return sprintf(buf, "%ld\n", (long) data->pwmenable[nr - 1]); 621 return sprintf(buf, "%d\n", (int)data->pwm2_enable);
664} 622}
665 623
666static ssize_t 624static ssize_t
667store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) 625store_pwm(struct device *dev, struct device_attribute *da, const char *buf,
626 size_t count)
668{ 627{
669 struct i2c_client *client = to_i2c_client(dev); 628 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
670 struct w83781d_data *data = i2c_get_clientdata(client); 629 struct w83781d_data *data = dev_get_drvdata(dev);
630 int nr = attr->index;
671 u32 val; 631 u32 val;
672 632
673 val = simple_strtoul(buf, NULL, 10); 633 val = simple_strtoul(buf, NULL, 10);
674 634
675 mutex_lock(&data->update_lock); 635 mutex_lock(&data->update_lock);
676 data->pwm[nr - 1] = PWM_TO_REG(val); 636 data->pwm[nr] = SENSORS_LIMIT(val, 0, 255);
677 w83781d_write_value(client, W83781D_REG_PWM(nr), data->pwm[nr - 1]); 637 w83781d_write_value(data, W83781D_REG_PWM[nr], data->pwm[nr]);
678 mutex_unlock(&data->update_lock); 638 mutex_unlock(&data->update_lock);
679 return count; 639 return count;
680} 640}
681 641
682static ssize_t 642static ssize_t
683store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr) 643store_pwm2_enable(struct device *dev, struct device_attribute *da,
644 const char *buf, size_t count)
684{ 645{
685 struct i2c_client *client = to_i2c_client(dev); 646 struct w83781d_data *data = dev_get_drvdata(dev);
686 struct w83781d_data *data = i2c_get_clientdata(client);
687 u32 val, reg; 647 u32 val, reg;
688 648
689 val = simple_strtoul(buf, NULL, 10); 649 val = simple_strtoul(buf, NULL, 10);
@@ -693,15 +653,15 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr)
693 switch (val) { 653 switch (val) {
694 case 0: 654 case 0:
695 case 1: 655 case 1:
696 reg = w83781d_read_value(client, W83781D_REG_PWMCLK12); 656 reg = w83781d_read_value(data, W83781D_REG_PWMCLK12);
697 w83781d_write_value(client, W83781D_REG_PWMCLK12, 657 w83781d_write_value(data, W83781D_REG_PWMCLK12,
698 (reg & 0xf7) | (val << 3)); 658 (reg & 0xf7) | (val << 3));
699 659
700 reg = w83781d_read_value(client, W83781D_REG_BEEP_CONFIG); 660 reg = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
701 w83781d_write_value(client, W83781D_REG_BEEP_CONFIG, 661 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG,
702 (reg & 0xef) | (!val << 4)); 662 (reg & 0xef) | (!val << 4));
703 663
704 data->pwmenable[nr - 1] = val; 664 data->pwm2_enable = val;
705 break; 665 break;
706 666
707 default: 667 default:
@@ -713,50 +673,29 @@ store_pwmenable_reg(struct device *dev, const char *buf, size_t count, int nr)
713 return count; 673 return count;
714} 674}
715 675
716#define sysfs_pwm(offset) \ 676static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0);
717static ssize_t show_regs_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 677static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 1);
718{ \ 678static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 2);
719 return show_pwm_reg(dev, buf, offset); \ 679static SENSOR_DEVICE_ATTR(pwm4, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 3);
720} \ 680/* only PWM2 can be enabled/disabled */
721static ssize_t store_regs_pwm_##offset (struct device *dev, struct device_attribute *attr, \ 681static DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
722 const char *buf, size_t count) \ 682 show_pwm2_enable, store_pwm2_enable);
723{ \
724 return store_pwm_reg(dev, buf, count, offset); \
725} \
726static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
727 show_regs_pwm_##offset, store_regs_pwm_##offset);
728
729#define sysfs_pwmenable(offset) \
730static ssize_t show_regs_pwmenable_##offset (struct device *dev, struct device_attribute *attr, char *buf) \
731{ \
732 return show_pwmenable_reg(dev, buf, offset); \
733} \
734static ssize_t store_regs_pwmenable_##offset (struct device *dev, struct device_attribute *attr, \
735 const char *buf, size_t count) \
736{ \
737 return store_pwmenable_reg(dev, buf, count, offset); \
738} \
739static DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
740 show_regs_pwmenable_##offset, store_regs_pwmenable_##offset);
741
742sysfs_pwm(1);
743sysfs_pwm(2);
744sysfs_pwmenable(2); /* only PWM2 can be enabled/disabled */
745sysfs_pwm(3);
746sysfs_pwm(4);
747 683
748static ssize_t 684static ssize_t
749show_sensor_reg(struct device *dev, char *buf, int nr) 685show_sensor(struct device *dev, struct device_attribute *da, char *buf)
750{ 686{
687 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
751 struct w83781d_data *data = w83781d_update_device(dev); 688 struct w83781d_data *data = w83781d_update_device(dev);
752 return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]); 689 return sprintf(buf, "%d\n", (int)data->sens[attr->index]);
753} 690}
754 691
755static ssize_t 692static ssize_t
756store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) 693store_sensor(struct device *dev, struct device_attribute *da,
694 const char *buf, size_t count)
757{ 695{
758 struct i2c_client *client = to_i2c_client(dev); 696 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
759 struct w83781d_data *data = i2c_get_clientdata(client); 697 struct w83781d_data *data = dev_get_drvdata(dev);
698 int nr = attr->index;
760 u32 val, tmp; 699 u32 val, tmp;
761 700
762 val = simple_strtoul(buf, NULL, 10); 701 val = simple_strtoul(buf, NULL, 10);
@@ -765,28 +704,28 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
765 704
766 switch (val) { 705 switch (val) {
767 case 1: /* PII/Celeron diode */ 706 case 1: /* PII/Celeron diode */
768 tmp = w83781d_read_value(client, W83781D_REG_SCFG1); 707 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
769 w83781d_write_value(client, W83781D_REG_SCFG1, 708 w83781d_write_value(data, W83781D_REG_SCFG1,
770 tmp | BIT_SCFG1[nr - 1]); 709 tmp | BIT_SCFG1[nr]);
771 tmp = w83781d_read_value(client, W83781D_REG_SCFG2); 710 tmp = w83781d_read_value(data, W83781D_REG_SCFG2);
772 w83781d_write_value(client, W83781D_REG_SCFG2, 711 w83781d_write_value(data, W83781D_REG_SCFG2,
773 tmp | BIT_SCFG2[nr - 1]); 712 tmp | BIT_SCFG2[nr]);
774 data->sens[nr - 1] = val; 713 data->sens[nr] = val;
775 break; 714 break;
776 case 2: /* 3904 */ 715 case 2: /* 3904 */
777 tmp = w83781d_read_value(client, W83781D_REG_SCFG1); 716 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
778 w83781d_write_value(client, W83781D_REG_SCFG1, 717 w83781d_write_value(data, W83781D_REG_SCFG1,
779 tmp | BIT_SCFG1[nr - 1]); 718 tmp | BIT_SCFG1[nr]);
780 tmp = w83781d_read_value(client, W83781D_REG_SCFG2); 719 tmp = w83781d_read_value(data, W83781D_REG_SCFG2);
781 w83781d_write_value(client, W83781D_REG_SCFG2, 720 w83781d_write_value(data, W83781D_REG_SCFG2,
782 tmp & ~BIT_SCFG2[nr - 1]); 721 tmp & ~BIT_SCFG2[nr]);
783 data->sens[nr - 1] = val; 722 data->sens[nr] = val;
784 break; 723 break;
785 case W83781D_DEFAULT_BETA: /* thermistor */ 724 case W83781D_DEFAULT_BETA: /* thermistor */
786 tmp = w83781d_read_value(client, W83781D_REG_SCFG1); 725 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
787 w83781d_write_value(client, W83781D_REG_SCFG1, 726 w83781d_write_value(data, W83781D_REG_SCFG1,
788 tmp & ~BIT_SCFG1[nr - 1]); 727 tmp & ~BIT_SCFG1[nr]);
789 data->sens[nr - 1] = val; 728 data->sens[nr] = val;
790 break; 729 break;
791 default: 730 default:
792 dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or %d\n", 731 dev_err(dev, "Invalid sensor type %ld; must be 1, 2, or %d\n",
@@ -798,20 +737,22 @@ store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr)
798 return count; 737 return count;
799} 738}
800 739
801#define sysfs_sensor(offset) \ 740static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR,
802static ssize_t show_regs_sensor_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ 741 show_sensor, store_sensor, 0);
803{ \ 742static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR,
804 return show_sensor_reg(dev, buf, offset); \ 743 show_sensor, store_sensor, 0);
805} \ 744static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR,
806static ssize_t store_regs_sensor_##offset (struct device *dev, struct device_attribute *attr, const char *buf, size_t count) \ 745 show_sensor, store_sensor, 0);
807{ \
808 return store_sensor_reg(dev, buf, count, offset); \
809} \
810static DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, show_regs_sensor_##offset, store_regs_sensor_##offset);
811 746
812sysfs_sensor(1); 747/* I2C devices get this name attribute automatically, but for ISA devices
813sysfs_sensor(2); 748 we must create it by ourselves. */
814sysfs_sensor(3); 749static ssize_t
750show_name(struct device *dev, struct device_attribute *devattr, char *buf)
751{
752 struct w83781d_data *data = dev_get_drvdata(dev);
753 return sprintf(buf, "%s\n", data->client.name);
754}
755static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
815 756
816/* This function is called when: 757/* This function is called when:
817 * w83781d_driver is inserted (when this module is loaded), for each 758 * w83781d_driver is inserted (when this module is loaded), for each
@@ -825,12 +766,6 @@ w83781d_attach_adapter(struct i2c_adapter *adapter)
825 return i2c_probe(adapter, &addr_data, w83781d_detect); 766 return i2c_probe(adapter, &addr_data, w83781d_detect);
826} 767}
827 768
828static int
829w83781d_isa_attach_adapter(struct i2c_adapter *adapter)
830{
831 return w83781d_detect(adapter, isa_address, -1);
832}
833
834/* Assumes that adapter is of I2C, not ISA variety. 769/* Assumes that adapter is of I2C, not ISA variety.
835 * OTHERWISE DON'T CALL THIS 770 * OTHERWISE DON'T CALL THIS
836 */ 771 */
@@ -862,12 +797,12 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
862 goto ERROR_SC_1; 797 goto ERROR_SC_1;
863 } 798 }
864 } 799 }
865 w83781d_write_value(new_client, W83781D_REG_I2C_SUBADDR, 800 w83781d_write_value(data, W83781D_REG_I2C_SUBADDR,
866 (force_subclients[2] & 0x07) | 801 (force_subclients[2] & 0x07) |
867 ((force_subclients[3] & 0x07) << 4)); 802 ((force_subclients[3] & 0x07) << 4));
868 data->lm75[0]->addr = force_subclients[2]; 803 data->lm75[0]->addr = force_subclients[2];
869 } else { 804 } else {
870 val1 = w83781d_read_value(new_client, W83781D_REG_I2C_SUBADDR); 805 val1 = w83781d_read_value(data, W83781D_REG_I2C_SUBADDR);
871 data->lm75[0]->addr = 0x48 + (val1 & 0x07); 806 data->lm75[0]->addr = 0x48 + (val1 & 0x07);
872 } 807 }
873 808
@@ -937,20 +872,20 @@ ERROR_SC_0:
937 return err; 872 return err;
938} 873}
939 874
940#define IN_UNIT_ATTRS(X) \ 875#define IN_UNIT_ATTRS(X) \
941 &dev_attr_in##X##_input.attr, \ 876 &sensor_dev_attr_in##X##_input.dev_attr.attr, \
942 &dev_attr_in##X##_min.attr, \ 877 &sensor_dev_attr_in##X##_min.dev_attr.attr, \
943 &dev_attr_in##X##_max.attr 878 &sensor_dev_attr_in##X##_max.dev_attr.attr
944 879
945#define FAN_UNIT_ATTRS(X) \ 880#define FAN_UNIT_ATTRS(X) \
946 &dev_attr_fan##X##_input.attr, \ 881 &sensor_dev_attr_fan##X##_input.dev_attr.attr, \
947 &dev_attr_fan##X##_min.attr, \ 882 &sensor_dev_attr_fan##X##_min.dev_attr.attr, \
948 &dev_attr_fan##X##_div.attr 883 &sensor_dev_attr_fan##X##_div.dev_attr.attr
949 884
950#define TEMP_UNIT_ATTRS(X) \ 885#define TEMP_UNIT_ATTRS(X) \
951 &dev_attr_temp##X##_input.attr, \ 886 &sensor_dev_attr_temp##X##_input.dev_attr.attr, \
952 &dev_attr_temp##X##_max.attr, \ 887 &sensor_dev_attr_temp##X##_max.dev_attr.attr, \
953 &dev_attr_temp##X##_max_hyst.attr 888 &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr
954 889
955static struct attribute* w83781d_attributes[] = { 890static struct attribute* w83781d_attributes[] = {
956 IN_UNIT_ATTRS(0), 891 IN_UNIT_ATTRS(0),
@@ -980,91 +915,115 @@ static struct attribute *w83781d_attributes_opt[] = {
980 IN_UNIT_ATTRS(7), 915 IN_UNIT_ATTRS(7),
981 IN_UNIT_ATTRS(8), 916 IN_UNIT_ATTRS(8),
982 TEMP_UNIT_ATTRS(3), 917 TEMP_UNIT_ATTRS(3),
983 &dev_attr_pwm1.attr, 918 &sensor_dev_attr_pwm1.dev_attr.attr,
984 &dev_attr_pwm2.attr, 919 &sensor_dev_attr_pwm2.dev_attr.attr,
920 &sensor_dev_attr_pwm3.dev_attr.attr,
921 &sensor_dev_attr_pwm4.dev_attr.attr,
985 &dev_attr_pwm2_enable.attr, 922 &dev_attr_pwm2_enable.attr,
986 &dev_attr_pwm3.attr, 923 &sensor_dev_attr_temp1_type.dev_attr.attr,
987 &dev_attr_pwm4.attr, 924 &sensor_dev_attr_temp2_type.dev_attr.attr,
988 &dev_attr_temp1_type.attr, 925 &sensor_dev_attr_temp3_type.dev_attr.attr,
989 &dev_attr_temp2_type.attr,
990 &dev_attr_temp3_type.attr,
991 NULL 926 NULL
992}; 927};
993static const struct attribute_group w83781d_group_opt = { 928static const struct attribute_group w83781d_group_opt = {
994 .attrs = w83781d_attributes_opt, 929 .attrs = w83781d_attributes_opt,
995}; 930};
996 931
932/* No clean up is done on error, it's up to the caller */
997static int 933static int
998w83781d_detect(struct i2c_adapter *adapter, int address, int kind) 934w83781d_create_files(struct device *dev, int kind, int is_isa)
999{ 935{
1000 int i = 0, val1 = 0, val2;
1001 struct i2c_client *client;
1002 struct device *dev;
1003 struct w83781d_data *data;
1004 int err; 936 int err;
1005 const char *client_name = "";
1006 int is_isa = i2c_is_isa_adapter(adapter);
1007 enum vendor { winbond, asus } vendid;
1008 937
1009 if (!is_isa 938 if ((err = sysfs_create_group(&dev->kobj, &w83781d_group)))
1010 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 939 return err;
1011 err = -EINVAL; 940
1012 goto ERROR0; 941 if (kind != w83783s) {
942 if ((err = device_create_file(dev,
943 &sensor_dev_attr_in1_input.dev_attr))
944 || (err = device_create_file(dev,
945 &sensor_dev_attr_in1_min.dev_attr))
946 || (err = device_create_file(dev,
947 &sensor_dev_attr_in1_max.dev_attr)))
948 return err;
949 }
950 if (kind != as99127f && kind != w83781d && kind != w83783s) {
951 if ((err = device_create_file(dev,
952 &sensor_dev_attr_in7_input.dev_attr))
953 || (err = device_create_file(dev,
954 &sensor_dev_attr_in7_min.dev_attr))
955 || (err = device_create_file(dev,
956 &sensor_dev_attr_in7_max.dev_attr))
957 || (err = device_create_file(dev,
958 &sensor_dev_attr_in8_input.dev_attr))
959 || (err = device_create_file(dev,
960 &sensor_dev_attr_in8_min.dev_attr))
961 || (err = device_create_file(dev,
962 &sensor_dev_attr_in8_max.dev_attr)))
963 return err;
964 }
965 if (kind != w83783s) {
966 if ((err = device_create_file(dev,
967 &sensor_dev_attr_temp3_input.dev_attr))
968 || (err = device_create_file(dev,
969 &sensor_dev_attr_temp3_max.dev_attr))
970 || (err = device_create_file(dev,
971 &sensor_dev_attr_temp3_max_hyst.dev_attr)))
972 return err;
1013 } 973 }
1014 974
1015 /* Prevent users from forcing a kind for a bus it isn't supposed 975 if (kind != w83781d && kind != as99127f) {
1016 to possibly be on */ 976 if ((err = device_create_file(dev,
1017 if (is_isa && (kind == as99127f || kind == w83783s)) { 977 &sensor_dev_attr_pwm1.dev_attr))
1018 dev_err(&adapter->dev, 978 || (err = device_create_file(dev,
1019 "Cannot force I2C-only chip for ISA address 0x%02x.\n", 979 &sensor_dev_attr_pwm2.dev_attr))
1020 address); 980 || (err = device_create_file(dev, &dev_attr_pwm2_enable)))
1021 err = -EINVAL; 981 return err;
1022 goto ERROR0;
1023 } 982 }
1024 983 if (kind == w83782d && !is_isa) {
1025 if (is_isa) 984 if ((err = device_create_file(dev,
1026 if (!request_region(address, W83781D_EXTENT, 985 &sensor_dev_attr_pwm3.dev_attr))
1027 w83781d_isa_driver.driver.name)) { 986 || (err = device_create_file(dev,
1028 dev_dbg(&adapter->dev, "Request of region " 987 &sensor_dev_attr_pwm4.dev_attr)))
1029 "0x%x-0x%x for w83781d failed\n", address, 988 return err;
1030 address + W83781D_EXTENT - 1); 989 }
1031 err = -EBUSY; 990
1032 goto ERROR0; 991 if (kind != as99127f && kind != w83781d) {
992 if ((err = device_create_file(dev,
993 &sensor_dev_attr_temp1_type.dev_attr))
994 || (err = device_create_file(dev,
995 &sensor_dev_attr_temp2_type.dev_attr)))
996 return err;
997 if (kind != w83783s) {
998 if ((err = device_create_file(dev,
999 &sensor_dev_attr_temp3_type.dev_attr)))
1000 return err;
1033 } 1001 }
1002 }
1034 1003
1035 /* Probe whether there is anything available on this address. Already 1004 if (is_isa) {
1036 done for SMBus clients */ 1005 err = device_create_file(&pdev->dev, &dev_attr_name);
1037 if (kind < 0) { 1006 if (err)
1038 if (is_isa) { 1007 return err;
1008 }
1039 1009
1040#define REALLY_SLOW_IO 1010 return 0;
1041 /* We need the timeouts for at least some LM78-like 1011}
1042 chips. But only if we read 'undefined' registers. */
1043 i = inb_p(address + 1);
1044 if (inb_p(address + 2) != i
1045 || inb_p(address + 3) != i
1046 || inb_p(address + 7) != i) {
1047 dev_dbg(&adapter->dev, "Detection of w83781d "
1048 "chip failed at step 1\n");
1049 err = -ENODEV;
1050 goto ERROR1;
1051 }
1052#undef REALLY_SLOW_IO
1053 1012
1054 /* Let's just hope nothing breaks here */ 1013static int
1055 i = inb_p(address + 5) & 0x7f; 1014w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1056 outb_p(~i & 0x7f, address + 5); 1015{
1057 val2 = inb_p(address + 5) & 0x7f; 1016 int val1 = 0, val2;
1058 if (val2 != (~i & 0x7f)) { 1017 struct i2c_client *client;
1059 outb_p(i, address + 5); 1018 struct device *dev;
1060 dev_dbg(&adapter->dev, "Detection of w83781d " 1019 struct w83781d_data *data;
1061 "chip failed at step 2 (0x%x != " 1020 int err;
1062 "0x%x at 0x%x)\n", val2, ~i & 0x7f, 1021 const char *client_name = "";
1063 address + 5); 1022 enum vendor { winbond, asus } vendid;
1064 err = -ENODEV; 1023
1065 goto ERROR1; 1024 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
1066 } 1025 err = -EINVAL;
1067 } 1026 goto ERROR1;
1068 } 1027 }
1069 1028
1070 /* OK. For now, we presume we have a valid client. We now create the 1029 /* OK. For now, we presume we have a valid client. We now create the
@@ -1081,8 +1040,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1081 client->addr = address; 1040 client->addr = address;
1082 mutex_init(&data->lock); 1041 mutex_init(&data->lock);
1083 client->adapter = adapter; 1042 client->adapter = adapter;
1084 client->driver = is_isa ? &w83781d_isa_driver : &w83781d_driver; 1043 client->driver = &w83781d_driver;
1085 client->flags = 0;
1086 dev = &client->dev; 1044 dev = &client->dev;
1087 1045
1088 /* Now, we do the remaining detection. */ 1046 /* Now, we do the remaining detection. */
@@ -1092,14 +1050,14 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1092 force_*=... parameter, and the Winbond will be reset to the right 1050 force_*=... parameter, and the Winbond will be reset to the right
1093 bank. */ 1051 bank. */
1094 if (kind < 0) { 1052 if (kind < 0) {
1095 if (w83781d_read_value(client, W83781D_REG_CONFIG) & 0x80) { 1053 if (w83781d_read_value(data, W83781D_REG_CONFIG) & 0x80) {
1096 dev_dbg(&adapter->dev, "Detection of w83781d chip " 1054 dev_dbg(&adapter->dev, "Detection of w83781d chip "
1097 "failed at step 3\n"); 1055 "failed at step 3\n");
1098 err = -ENODEV; 1056 err = -ENODEV;
1099 goto ERROR2; 1057 goto ERROR2;
1100 } 1058 }
1101 val1 = w83781d_read_value(client, W83781D_REG_BANK); 1059 val1 = w83781d_read_value(data, W83781D_REG_BANK);
1102 val2 = w83781d_read_value(client, W83781D_REG_CHIPMAN); 1060 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN);
1103 /* Check for Winbond or Asus ID if in bank 0 */ 1061 /* Check for Winbond or Asus ID if in bank 0 */
1104 if ((!(val1 & 0x07)) && 1062 if ((!(val1 & 0x07)) &&
1105 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3)) 1063 (((!(val1 & 0x80)) && (val2 != 0xa3) && (val2 != 0xc3))
@@ -1111,10 +1069,10 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1111 } 1069 }
1112 /* If Winbond SMBus, check address at 0x48. 1070 /* If Winbond SMBus, check address at 0x48.
1113 Asus doesn't support, except for as99127f rev.2 */ 1071 Asus doesn't support, except for as99127f rev.2 */
1114 if ((!is_isa) && (((!(val1 & 0x80)) && (val2 == 0xa3)) || 1072 if ((!(val1 & 0x80) && (val2 == 0xa3)) ||
1115 ((val1 & 0x80) && (val2 == 0x5c)))) { 1073 ((val1 & 0x80) && (val2 == 0x5c))) {
1116 if (w83781d_read_value 1074 if (w83781d_read_value
1117 (client, W83781D_REG_I2C_ADDR) != address) { 1075 (data, W83781D_REG_I2C_ADDR) != address) {
1118 dev_dbg(&adapter->dev, "Detection of w83781d " 1076 dev_dbg(&adapter->dev, "Detection of w83781d "
1119 "chip failed at step 5\n"); 1077 "chip failed at step 5\n");
1120 err = -ENODEV; 1078 err = -ENODEV;
@@ -1125,14 +1083,14 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1125 1083
1126 /* We have either had a force parameter, or we have already detected the 1084 /* We have either had a force parameter, or we have already detected the
1127 Winbond. Put it now into bank 0 and Vendor ID High Byte */ 1085 Winbond. Put it now into bank 0 and Vendor ID High Byte */
1128 w83781d_write_value(client, W83781D_REG_BANK, 1086 w83781d_write_value(data, W83781D_REG_BANK,
1129 (w83781d_read_value(client, W83781D_REG_BANK) 1087 (w83781d_read_value(data, W83781D_REG_BANK)
1130 & 0x78) | 0x80); 1088 & 0x78) | 0x80);
1131 1089
1132 /* Determine the chip type. */ 1090 /* Determine the chip type. */
1133 if (kind <= 0) { 1091 if (kind <= 0) {
1134 /* get vendor ID */ 1092 /* get vendor ID */
1135 val2 = w83781d_read_value(client, W83781D_REG_CHIPMAN); 1093 val2 = w83781d_read_value(data, W83781D_REG_CHIPMAN);
1136 if (val2 == 0x5c) 1094 if (val2 == 0x5c)
1137 vendid = winbond; 1095 vendid = winbond;
1138 else if (val2 == 0x12) 1096 else if (val2 == 0x12)
@@ -1144,17 +1102,16 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1144 goto ERROR2; 1102 goto ERROR2;
1145 } 1103 }
1146 1104
1147 val1 = w83781d_read_value(client, W83781D_REG_WCHIPID); 1105 val1 = w83781d_read_value(data, W83781D_REG_WCHIPID);
1148 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond) 1106 if ((val1 == 0x10 || val1 == 0x11) && vendid == winbond)
1149 kind = w83781d; 1107 kind = w83781d;
1150 else if (val1 == 0x30 && vendid == winbond) 1108 else if (val1 == 0x30 && vendid == winbond)
1151 kind = w83782d; 1109 kind = w83782d;
1152 else if (val1 == 0x40 && vendid == winbond && !is_isa 1110 else if (val1 == 0x40 && vendid == winbond && address == 0x2d)
1153 && address == 0x2d)
1154 kind = w83783s; 1111 kind = w83783s;
1155 else if (val1 == 0x21 && vendid == winbond) 1112 else if (val1 == 0x21 && vendid == winbond)
1156 kind = w83627hf; 1113 kind = w83627hf;
1157 else if (val1 == 0x31 && !is_isa && address >= 0x28) 1114 else if (val1 == 0x31 && address >= 0x28)
1158 kind = as99127f; 1115 kind = as99127f;
1159 else { 1116 else {
1160 if (kind == 0) 1117 if (kind == 0)
@@ -1182,86 +1139,23 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
1182 strlcpy(client->name, client_name, I2C_NAME_SIZE); 1139 strlcpy(client->name, client_name, I2C_NAME_SIZE);
1183 data->type = kind; 1140 data->type = kind;
1184 1141
1185 data->valid = 0;
1186 mutex_init(&data->update_lock);
1187
1188 /* Tell the I2C layer a new client has arrived */ 1142 /* Tell the I2C layer a new client has arrived */
1189 if ((err = i2c_attach_client(client))) 1143 if ((err = i2c_attach_client(client)))
1190 goto ERROR2; 1144 goto ERROR2;
1191 1145
1192 /* attach secondary i2c lm75-like clients */ 1146 /* attach secondary i2c lm75-like clients */
1193 if (!is_isa) { 1147 if ((err = w83781d_detect_subclients(adapter, address,
1194 if ((err = w83781d_detect_subclients(adapter, address, 1148 kind, client)))
1195 kind, client))) 1149 goto ERROR3;
1196 goto ERROR3;
1197 } else {
1198 data->lm75[0] = NULL;
1199 data->lm75[1] = NULL;
1200 }
1201 1150
1202 /* Initialize the chip */ 1151 /* Initialize the chip */
1203 w83781d_init_client(client); 1152 w83781d_init_device(dev);
1204
1205 /* A few vars need to be filled upon startup */
1206 for (i = 1; i <= 3; i++) {
1207 data->fan_min[i - 1] = w83781d_read_value(client,
1208 W83781D_REG_FAN_MIN(i));
1209 }
1210 if (kind != w83781d && kind != as99127f)
1211 for (i = 0; i < 4; i++)
1212 data->pwmenable[i] = 1;
1213 1153
1214 /* Register sysfs hooks */ 1154 /* Register sysfs hooks */
1215 if ((err = sysfs_create_group(&dev->kobj, &w83781d_group))) 1155 err = w83781d_create_files(dev, kind, 0);
1156 if (err)
1216 goto ERROR4; 1157 goto ERROR4;
1217 1158
1218 if (kind != w83783s) {
1219 if ((err = device_create_file(dev, &dev_attr_in1_input))
1220 || (err = device_create_file(dev, &dev_attr_in1_min))
1221 || (err = device_create_file(dev, &dev_attr_in1_max)))
1222 goto ERROR4;
1223 }
1224 if (kind != as99127f && kind != w83781d && kind != w83783s) {
1225 if ((err = device_create_file(dev, &dev_attr_in7_input))
1226 || (err = device_create_file(dev, &dev_attr_in7_min))
1227 || (err = device_create_file(dev, &dev_attr_in7_max))
1228 || (err = device_create_file(dev, &dev_attr_in8_input))
1229 || (err = device_create_file(dev, &dev_attr_in8_min))
1230 || (err = device_create_file(dev, &dev_attr_in8_max)))
1231 goto ERROR4;
1232 }
1233 if (kind != w83783s) {
1234 if ((err = device_create_file(dev, &dev_attr_temp3_input))
1235 || (err = device_create_file(dev, &dev_attr_temp3_max))
1236 || (err = device_create_file(dev,
1237 &dev_attr_temp3_max_hyst)))
1238 goto ERROR4;
1239 }
1240
1241 if (kind != w83781d && kind != as99127f) {
1242 if ((err = device_create_file(dev, &dev_attr_pwm1))
1243 || (err = device_create_file(dev, &dev_attr_pwm2))
1244 || (err = device_create_file(dev, &dev_attr_pwm2_enable)))
1245 goto ERROR4;
1246 }
1247 if (kind == w83782d && !is_isa) {
1248 if ((err = device_create_file(dev, &dev_attr_pwm3))
1249 || (err = device_create_file(dev, &dev_attr_pwm4)))
1250 goto ERROR4;
1251 }
1252
1253 if (kind != as99127f && kind != w83781d) {
1254 if ((err = device_create_file(dev, &dev_attr_temp1_type))
1255 || (err = device_create_file(dev,
1256 &dev_attr_temp2_type)))
1257 goto ERROR4;
1258 if (kind != w83783s) {
1259 if ((err = device_create_file(dev,
1260 &dev_attr_temp3_type)))
1261 goto ERROR4;
1262 }
1263 }
1264
1265 data->class_dev = hwmon_device_register(dev); 1159 data->class_dev = hwmon_device_register(dev);
1266 if (IS_ERR(data->class_dev)) { 1160 if (IS_ERR(data->class_dev)) {
1267 err = PTR_ERR(data->class_dev); 1161 err = PTR_ERR(data->class_dev);
@@ -1287,9 +1181,6 @@ ERROR3:
1287ERROR2: 1181ERROR2:
1288 kfree(data); 1182 kfree(data);
1289ERROR1: 1183ERROR1:
1290 if (is_isa)
1291 release_region(address, W83781D_EXTENT);
1292ERROR0:
1293 return err; 1184 return err;
1294} 1185}
1295 1186
@@ -1305,8 +1196,6 @@ w83781d_detach_client(struct i2c_client *client)
1305 sysfs_remove_group(&client->dev.kobj, &w83781d_group); 1196 sysfs_remove_group(&client->dev.kobj, &w83781d_group);
1306 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt); 1197 sysfs_remove_group(&client->dev.kobj, &w83781d_group_opt);
1307 } 1198 }
1308 if (i2c_is_isa_client(client))
1309 release_region(client->addr, W83781D_EXTENT);
1310 1199
1311 if ((err = i2c_detach_client(client))) 1200 if ((err = i2c_detach_client(client)))
1312 return err; 1201 return err;
@@ -1322,6 +1211,88 @@ w83781d_detach_client(struct i2c_client *client)
1322 return 0; 1211 return 0;
1323} 1212}
1324 1213
1214static int __devinit
1215w83781d_isa_probe(struct platform_device *pdev)
1216{
1217 int err, reg;
1218 struct w83781d_data *data;
1219 struct resource *res;
1220 const char *name;
1221
1222 /* Reserve the ISA region */
1223 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
1224 if (!request_region(res->start, W83781D_EXTENT, "w83781d")) {
1225 err = -EBUSY;
1226 goto exit;
1227 }
1228
1229 if (!(data = kzalloc(sizeof(struct w83781d_data), GFP_KERNEL))) {
1230 err = -ENOMEM;
1231 goto exit_release_region;
1232 }
1233 mutex_init(&data->lock);
1234 data->client.addr = res->start;
1235 i2c_set_clientdata(&data->client, data);
1236 platform_set_drvdata(pdev, data);
1237
1238 reg = w83781d_read_value(data, W83781D_REG_WCHIPID);
1239 switch (reg) {
1240 case 0x21:
1241 data->type = w83627hf;
1242 name = "w83627hf";
1243 break;
1244 case 0x30:
1245 data->type = w83782d;
1246 name = "w83782d";
1247 break;
1248 default:
1249 data->type = w83781d;
1250 name = "w83781d";
1251 }
1252 strlcpy(data->client.name, name, I2C_NAME_SIZE);
1253
1254 /* Initialize the W83781D chip */
1255 w83781d_init_device(&pdev->dev);
1256
1257 /* Register sysfs hooks */
1258 err = w83781d_create_files(&pdev->dev, data->type, 1);
1259 if (err)
1260 goto exit_remove_files;
1261
1262 data->class_dev = hwmon_device_register(&pdev->dev);
1263 if (IS_ERR(data->class_dev)) {
1264 err = PTR_ERR(data->class_dev);
1265 goto exit_remove_files;
1266 }
1267
1268 return 0;
1269
1270 exit_remove_files:
1271 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1272 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1273 device_remove_file(&pdev->dev, &dev_attr_name);
1274 kfree(data);
1275 exit_release_region:
1276 release_region(res->start, W83781D_EXTENT);
1277 exit:
1278 return err;
1279}
1280
1281static int __devexit
1282w83781d_isa_remove(struct platform_device *pdev)
1283{
1284 struct w83781d_data *data = platform_get_drvdata(pdev);
1285
1286 hwmon_device_unregister(data->class_dev);
1287 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group);
1288 sysfs_remove_group(&pdev->dev.kobj, &w83781d_group_opt);
1289 device_remove_file(&pdev->dev, &dev_attr_name);
1290 release_region(data->client.addr, W83781D_EXTENT);
1291 kfree(data);
1292
1293 return 0;
1294}
1295
1325/* The SMBus locks itself, usually, but nothing may access the Winbond between 1296/* The SMBus locks itself, usually, but nothing may access the Winbond between
1326 bank switches. ISA access must always be locked explicitly! 1297 bank switches. ISA access must always be locked explicitly!
1327 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks, 1298 We ignore the W83781D BUSY flag at this moment - it could lead to deadlocks,
@@ -1329,14 +1300,14 @@ w83781d_detach_client(struct i2c_client *client)
1329 There are some ugly typecasts here, but the good news is - they should 1300 There are some ugly typecasts here, but the good news is - they should
1330 nowhere else be necessary! */ 1301 nowhere else be necessary! */
1331static int 1302static int
1332w83781d_read_value(struct i2c_client *client, u16 reg) 1303w83781d_read_value(struct w83781d_data *data, u16 reg)
1333{ 1304{
1334 struct w83781d_data *data = i2c_get_clientdata(client); 1305 struct i2c_client *client = &data->client;
1335 int res, word_sized, bank; 1306 int res, word_sized, bank;
1336 struct i2c_client *cl; 1307 struct i2c_client *cl;
1337 1308
1338 mutex_lock(&data->lock); 1309 mutex_lock(&data->lock);
1339 if (i2c_is_isa_client(client)) { 1310 if (!client->driver) { /* ISA device */
1340 word_sized = (((reg & 0xff00) == 0x100) 1311 word_sized = (((reg & 0xff00) == 0x100)
1341 || ((reg & 0xff00) == 0x200)) 1312 || ((reg & 0xff00) == 0x200))
1342 && (((reg & 0x00ff) == 0x50) 1313 && (((reg & 0x00ff) == 0x50)
@@ -1398,14 +1369,14 @@ w83781d_read_value(struct i2c_client *client, u16 reg)
1398} 1369}
1399 1370
1400static int 1371static int
1401w83781d_write_value(struct i2c_client *client, u16 reg, u16 value) 1372w83781d_write_value(struct w83781d_data *data, u16 reg, u16 value)
1402{ 1373{
1403 struct w83781d_data *data = i2c_get_clientdata(client); 1374 struct i2c_client *client = &data->client;
1404 int word_sized, bank; 1375 int word_sized, bank;
1405 struct i2c_client *cl; 1376 struct i2c_client *cl;
1406 1377
1407 mutex_lock(&data->lock); 1378 mutex_lock(&data->lock);
1408 if (i2c_is_isa_client(client)) { 1379 if (!client->driver) { /* ISA device */
1409 word_sized = (((reg & 0xff00) == 0x100) 1380 word_sized = (((reg & 0xff00) == 0x100)
1410 || ((reg & 0xff00) == 0x200)) 1381 || ((reg & 0xff00) == 0x200))
1411 && (((reg & 0x00ff) == 0x53) 1382 && (((reg & 0x00ff) == 0x53)
@@ -1462,13 +1433,18 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value)
1462} 1433}
1463 1434
1464static void 1435static void
1465w83781d_init_client(struct i2c_client *client) 1436w83781d_init_device(struct device *dev)
1466{ 1437{
1467 struct w83781d_data *data = i2c_get_clientdata(client); 1438 struct w83781d_data *data = dev_get_drvdata(dev);
1468 int i, p; 1439 int i, p;
1469 int type = data->type; 1440 int type = data->type;
1470 u8 tmp; 1441 u8 tmp;
1471 1442
1443 if (type == w83627hf)
1444 dev_info(dev, "The W83627HF chip is better supported by the "
1445 "w83627hf driver, support will be dropped from the "
1446 "w83781d driver soon\n");
1447
1472 if (reset && type != as99127f) { /* this resets registers we don't have 1448 if (reset && type != as99127f) { /* this resets registers we don't have
1473 documentation for on the as99127f */ 1449 documentation for on the as99127f */
1474 /* Resetting the chip has been the default for a long time, 1450 /* Resetting the chip has been the default for a long time,
@@ -1477,42 +1453,42 @@ w83781d_init_client(struct i2c_client *client)
1477 It might even go away if nobody reports it as being useful, 1453 It might even go away if nobody reports it as being useful,
1478 as I see very little reason why this would be needed at 1454 as I see very little reason why this would be needed at
1479 all. */ 1455 all. */
1480 dev_info(&client->dev, "If reset=1 solved a problem you were " 1456 dev_info(dev, "If reset=1 solved a problem you were "
1481 "having, please report!\n"); 1457 "having, please report!\n");
1482 1458
1483 /* save these registers */ 1459 /* save these registers */
1484 i = w83781d_read_value(client, W83781D_REG_BEEP_CONFIG); 1460 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
1485 p = w83781d_read_value(client, W83781D_REG_PWMCLK12); 1461 p = w83781d_read_value(data, W83781D_REG_PWMCLK12);
1486 /* Reset all except Watchdog values and last conversion values 1462 /* Reset all except Watchdog values and last conversion values
1487 This sets fan-divs to 2, among others */ 1463 This sets fan-divs to 2, among others */
1488 w83781d_write_value(client, W83781D_REG_CONFIG, 0x80); 1464 w83781d_write_value(data, W83781D_REG_CONFIG, 0x80);
1489 /* Restore the registers and disable power-on abnormal beep. 1465 /* Restore the registers and disable power-on abnormal beep.
1490 This saves FAN 1/2/3 input/output values set by BIOS. */ 1466 This saves FAN 1/2/3 input/output values set by BIOS. */
1491 w83781d_write_value(client, W83781D_REG_BEEP_CONFIG, i | 0x80); 1467 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80);
1492 w83781d_write_value(client, W83781D_REG_PWMCLK12, p); 1468 w83781d_write_value(data, W83781D_REG_PWMCLK12, p);
1493 /* Disable master beep-enable (reset turns it on). 1469 /* Disable master beep-enable (reset turns it on).
1494 Individual beep_mask should be reset to off but for some reason 1470 Individual beep_mask should be reset to off but for some reason
1495 disabling this bit helps some people not get beeped */ 1471 disabling this bit helps some people not get beeped */
1496 w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 0); 1472 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, 0);
1497 } 1473 }
1498 1474
1499 /* Disable power-on abnormal beep, as advised by the datasheet. 1475 /* Disable power-on abnormal beep, as advised by the datasheet.
1500 Already done if reset=1. */ 1476 Already done if reset=1. */
1501 if (init && !reset && type != as99127f) { 1477 if (init && !reset && type != as99127f) {
1502 i = w83781d_read_value(client, W83781D_REG_BEEP_CONFIG); 1478 i = w83781d_read_value(data, W83781D_REG_BEEP_CONFIG);
1503 w83781d_write_value(client, W83781D_REG_BEEP_CONFIG, i | 0x80); 1479 w83781d_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80);
1504 } 1480 }
1505 1481
1506 data->vrm = vid_which_vrm(); 1482 data->vrm = vid_which_vrm();
1507 1483
1508 if ((type != w83781d) && (type != as99127f)) { 1484 if ((type != w83781d) && (type != as99127f)) {
1509 tmp = w83781d_read_value(client, W83781D_REG_SCFG1); 1485 tmp = w83781d_read_value(data, W83781D_REG_SCFG1);
1510 for (i = 1; i <= 3; i++) { 1486 for (i = 1; i <= 3; i++) {
1511 if (!(tmp & BIT_SCFG1[i - 1])) { 1487 if (!(tmp & BIT_SCFG1[i - 1])) {
1512 data->sens[i - 1] = W83781D_DEFAULT_BETA; 1488 data->sens[i - 1] = W83781D_DEFAULT_BETA;
1513 } else { 1489 } else {
1514 if (w83781d_read_value 1490 if (w83781d_read_value
1515 (client, 1491 (data,
1516 W83781D_REG_SCFG2) & BIT_SCFG2[i - 1]) 1492 W83781D_REG_SCFG2) & BIT_SCFG2[i - 1])
1517 data->sens[i - 1] = 1; 1493 data->sens[i - 1] = 1;
1518 else 1494 else
@@ -1525,38 +1501,46 @@ w83781d_init_client(struct i2c_client *client)
1525 1501
1526 if (init && type != as99127f) { 1502 if (init && type != as99127f) {
1527 /* Enable temp2 */ 1503 /* Enable temp2 */
1528 tmp = w83781d_read_value(client, W83781D_REG_TEMP2_CONFIG); 1504 tmp = w83781d_read_value(data, W83781D_REG_TEMP2_CONFIG);
1529 if (tmp & 0x01) { 1505 if (tmp & 0x01) {
1530 dev_warn(&client->dev, "Enabling temp2, readings " 1506 dev_warn(dev, "Enabling temp2, readings "
1531 "might not make sense\n"); 1507 "might not make sense\n");
1532 w83781d_write_value(client, W83781D_REG_TEMP2_CONFIG, 1508 w83781d_write_value(data, W83781D_REG_TEMP2_CONFIG,
1533 tmp & 0xfe); 1509 tmp & 0xfe);
1534 } 1510 }
1535 1511
1536 /* Enable temp3 */ 1512 /* Enable temp3 */
1537 if (type != w83783s) { 1513 if (type != w83783s) {
1538 tmp = w83781d_read_value(client, 1514 tmp = w83781d_read_value(data,
1539 W83781D_REG_TEMP3_CONFIG); 1515 W83781D_REG_TEMP3_CONFIG);
1540 if (tmp & 0x01) { 1516 if (tmp & 0x01) {
1541 dev_warn(&client->dev, "Enabling temp3, " 1517 dev_warn(dev, "Enabling temp3, "
1542 "readings might not make sense\n"); 1518 "readings might not make sense\n");
1543 w83781d_write_value(client, 1519 w83781d_write_value(data,
1544 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe); 1520 W83781D_REG_TEMP3_CONFIG, tmp & 0xfe);
1545 } 1521 }
1546 } 1522 }
1547 } 1523 }
1548 1524
1549 /* Start monitoring */ 1525 /* Start monitoring */
1550 w83781d_write_value(client, W83781D_REG_CONFIG, 1526 w83781d_write_value(data, W83781D_REG_CONFIG,
1551 (w83781d_read_value(client, 1527 (w83781d_read_value(data,
1552 W83781D_REG_CONFIG) & 0xf7) 1528 W83781D_REG_CONFIG) & 0xf7)
1553 | 0x01); 1529 | 0x01);
1530
1531 /* A few vars need to be filled upon startup */
1532 for (i = 0; i < 3; i++) {
1533 data->fan_min[i] = w83781d_read_value(data,
1534 W83781D_REG_FAN_MIN(i));
1535 }
1536
1537 mutex_init(&data->update_lock);
1554} 1538}
1555 1539
1556static struct w83781d_data *w83781d_update_device(struct device *dev) 1540static struct w83781d_data *w83781d_update_device(struct device *dev)
1557{ 1541{
1558 struct i2c_client *client = to_i2c_client(dev); 1542 struct w83781d_data *data = dev_get_drvdata(dev);
1559 struct w83781d_data *data = i2c_get_clientdata(client); 1543 struct i2c_client *client = &data->client;
1560 int i; 1544 int i;
1561 1545
1562 mutex_lock(&data->update_lock); 1546 mutex_lock(&data->update_lock);
@@ -1569,98 +1553,97 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1569 if (data->type == w83783s && i == 1) 1553 if (data->type == w83783s && i == 1)
1570 continue; /* 783S has no in1 */ 1554 continue; /* 783S has no in1 */
1571 data->in[i] = 1555 data->in[i] =
1572 w83781d_read_value(client, W83781D_REG_IN(i)); 1556 w83781d_read_value(data, W83781D_REG_IN(i));
1573 data->in_min[i] = 1557 data->in_min[i] =
1574 w83781d_read_value(client, W83781D_REG_IN_MIN(i)); 1558 w83781d_read_value(data, W83781D_REG_IN_MIN(i));
1575 data->in_max[i] = 1559 data->in_max[i] =
1576 w83781d_read_value(client, W83781D_REG_IN_MAX(i)); 1560 w83781d_read_value(data, W83781D_REG_IN_MAX(i));
1577 if ((data->type != w83782d) 1561 if ((data->type != w83782d)
1578 && (data->type != w83627hf) && (i == 6)) 1562 && (data->type != w83627hf) && (i == 6))
1579 break; 1563 break;
1580 } 1564 }
1581 for (i = 1; i <= 3; i++) { 1565 for (i = 0; i < 3; i++) {
1582 data->fan[i - 1] = 1566 data->fan[i] =
1583 w83781d_read_value(client, W83781D_REG_FAN(i)); 1567 w83781d_read_value(data, W83781D_REG_FAN(i));
1584 data->fan_min[i - 1] = 1568 data->fan_min[i] =
1585 w83781d_read_value(client, W83781D_REG_FAN_MIN(i)); 1569 w83781d_read_value(data, W83781D_REG_FAN_MIN(i));
1586 } 1570 }
1587 if (data->type != w83781d && data->type != as99127f) { 1571 if (data->type != w83781d && data->type != as99127f) {
1588 for (i = 1; i <= 4; i++) { 1572 for (i = 0; i < 4; i++) {
1589 data->pwm[i - 1] = 1573 data->pwm[i] =
1590 w83781d_read_value(client, 1574 w83781d_read_value(data,
1591 W83781D_REG_PWM(i)); 1575 W83781D_REG_PWM[i]);
1592 if ((data->type != w83782d 1576 if ((data->type != w83782d || !client->driver)
1593 || i2c_is_isa_client(client)) 1577 && i == 1)
1594 && i == 2)
1595 break; 1578 break;
1596 } 1579 }
1597 /* Only PWM2 can be disabled */ 1580 /* Only PWM2 can be disabled */
1598 data->pwmenable[1] = (w83781d_read_value(client, 1581 data->pwm2_enable = (w83781d_read_value(data,
1599 W83781D_REG_PWMCLK12) & 0x08) >> 3; 1582 W83781D_REG_PWMCLK12) & 0x08) >> 3;
1600 } 1583 }
1601 1584
1602 data->temp = w83781d_read_value(client, W83781D_REG_TEMP(1)); 1585 data->temp = w83781d_read_value(data, W83781D_REG_TEMP(1));
1603 data->temp_max = 1586 data->temp_max =
1604 w83781d_read_value(client, W83781D_REG_TEMP_OVER(1)); 1587 w83781d_read_value(data, W83781D_REG_TEMP_OVER(1));
1605 data->temp_max_hyst = 1588 data->temp_max_hyst =
1606 w83781d_read_value(client, W83781D_REG_TEMP_HYST(1)); 1589 w83781d_read_value(data, W83781D_REG_TEMP_HYST(1));
1607 data->temp_add[0] = 1590 data->temp_add[0] =
1608 w83781d_read_value(client, W83781D_REG_TEMP(2)); 1591 w83781d_read_value(data, W83781D_REG_TEMP(2));
1609 data->temp_max_add[0] = 1592 data->temp_max_add[0] =
1610 w83781d_read_value(client, W83781D_REG_TEMP_OVER(2)); 1593 w83781d_read_value(data, W83781D_REG_TEMP_OVER(2));
1611 data->temp_max_hyst_add[0] = 1594 data->temp_max_hyst_add[0] =
1612 w83781d_read_value(client, W83781D_REG_TEMP_HYST(2)); 1595 w83781d_read_value(data, W83781D_REG_TEMP_HYST(2));
1613 if (data->type != w83783s) { 1596 if (data->type != w83783s) {
1614 data->temp_add[1] = 1597 data->temp_add[1] =
1615 w83781d_read_value(client, W83781D_REG_TEMP(3)); 1598 w83781d_read_value(data, W83781D_REG_TEMP(3));
1616 data->temp_max_add[1] = 1599 data->temp_max_add[1] =
1617 w83781d_read_value(client, 1600 w83781d_read_value(data,
1618 W83781D_REG_TEMP_OVER(3)); 1601 W83781D_REG_TEMP_OVER(3));
1619 data->temp_max_hyst_add[1] = 1602 data->temp_max_hyst_add[1] =
1620 w83781d_read_value(client, 1603 w83781d_read_value(data,
1621 W83781D_REG_TEMP_HYST(3)); 1604 W83781D_REG_TEMP_HYST(3));
1622 } 1605 }
1623 i = w83781d_read_value(client, W83781D_REG_VID_FANDIV); 1606 i = w83781d_read_value(data, W83781D_REG_VID_FANDIV);
1624 data->vid = i & 0x0f; 1607 data->vid = i & 0x0f;
1625 data->vid |= (w83781d_read_value(client, 1608 data->vid |= (w83781d_read_value(data,
1626 W83781D_REG_CHIPID) & 0x01) << 4; 1609 W83781D_REG_CHIPID) & 0x01) << 4;
1627 data->fan_div[0] = (i >> 4) & 0x03; 1610 data->fan_div[0] = (i >> 4) & 0x03;
1628 data->fan_div[1] = (i >> 6) & 0x03; 1611 data->fan_div[1] = (i >> 6) & 0x03;
1629 data->fan_div[2] = (w83781d_read_value(client, 1612 data->fan_div[2] = (w83781d_read_value(data,
1630 W83781D_REG_PIN) >> 6) & 0x03; 1613 W83781D_REG_PIN) >> 6) & 0x03;
1631 if ((data->type != w83781d) && (data->type != as99127f)) { 1614 if ((data->type != w83781d) && (data->type != as99127f)) {
1632 i = w83781d_read_value(client, W83781D_REG_VBAT); 1615 i = w83781d_read_value(data, W83781D_REG_VBAT);
1633 data->fan_div[0] |= (i >> 3) & 0x04; 1616 data->fan_div[0] |= (i >> 3) & 0x04;
1634 data->fan_div[1] |= (i >> 4) & 0x04; 1617 data->fan_div[1] |= (i >> 4) & 0x04;
1635 data->fan_div[2] |= (i >> 5) & 0x04; 1618 data->fan_div[2] |= (i >> 5) & 0x04;
1636 } 1619 }
1637 if ((data->type == w83782d) || (data->type == w83627hf)) { 1620 if ((data->type == w83782d) || (data->type == w83627hf)) {
1638 data->alarms = w83781d_read_value(client, 1621 data->alarms = w83781d_read_value(data,
1639 W83782D_REG_ALARM1) 1622 W83782D_REG_ALARM1)
1640 | (w83781d_read_value(client, 1623 | (w83781d_read_value(data,
1641 W83782D_REG_ALARM2) << 8) 1624 W83782D_REG_ALARM2) << 8)
1642 | (w83781d_read_value(client, 1625 | (w83781d_read_value(data,
1643 W83782D_REG_ALARM3) << 16); 1626 W83782D_REG_ALARM3) << 16);
1644 } else if (data->type == w83783s) { 1627 } else if (data->type == w83783s) {
1645 data->alarms = w83781d_read_value(client, 1628 data->alarms = w83781d_read_value(data,
1646 W83782D_REG_ALARM1) 1629 W83782D_REG_ALARM1)
1647 | (w83781d_read_value(client, 1630 | (w83781d_read_value(data,
1648 W83782D_REG_ALARM2) << 8); 1631 W83782D_REG_ALARM2) << 8);
1649 } else { 1632 } else {
1650 /* No real-time status registers, fall back to 1633 /* No real-time status registers, fall back to
1651 interrupt status registers */ 1634 interrupt status registers */
1652 data->alarms = w83781d_read_value(client, 1635 data->alarms = w83781d_read_value(data,
1653 W83781D_REG_ALARM1) 1636 W83781D_REG_ALARM1)
1654 | (w83781d_read_value(client, 1637 | (w83781d_read_value(data,
1655 W83781D_REG_ALARM2) << 8); 1638 W83781D_REG_ALARM2) << 8);
1656 } 1639 }
1657 i = w83781d_read_value(client, W83781D_REG_BEEP_INTS2); 1640 i = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
1658 data->beep_enable = i >> 7; 1641 data->beep_enable = i >> 7;
1659 data->beep_mask = ((i & 0x7f) << 8) + 1642 data->beep_mask = ((i & 0x7f) << 8) +
1660 w83781d_read_value(client, W83781D_REG_BEEP_INTS1); 1643 w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
1661 if ((data->type != w83781d) && (data->type != as99127f)) { 1644 if ((data->type != w83781d) && (data->type != as99127f)) {
1662 data->beep_mask |= 1645 data->beep_mask |=
1663 w83781d_read_value(client, 1646 w83781d_read_value(data,
1664 W83781D_REG_BEEP_INTS3) << 16; 1647 W83781D_REG_BEEP_INTS3) << 16;
1665 } 1648 }
1666 data->last_updated = jiffies; 1649 data->last_updated = jiffies;
@@ -1672,6 +1655,133 @@ static struct w83781d_data *w83781d_update_device(struct device *dev)
1672 return data; 1655 return data;
1673} 1656}
1674 1657
1658/* return 1 if a supported chip is found, 0 otherwise */
1659static int __init
1660w83781d_isa_found(unsigned short address)
1661{
1662 int val, save, found = 0;
1663
1664 if (!request_region(address, W83781D_EXTENT, "w83781d"))
1665 return 0;
1666
1667#define REALLY_SLOW_IO
1668 /* We need the timeouts for at least some W83781D-like
1669 chips. But only if we read 'undefined' registers. */
1670 val = inb_p(address + 1);
1671 if (inb_p(address + 2) != val
1672 || inb_p(address + 3) != val
1673 || inb_p(address + 7) != val) {
1674 pr_debug("w83781d: Detection failed at step 1\n");
1675 goto release;
1676 }
1677#undef REALLY_SLOW_IO
1678
1679 /* We should be able to change the 7 LSB of the address port. The
1680 MSB (busy flag) should be clear initially, set after the write. */
1681 save = inb_p(address + W83781D_ADDR_REG_OFFSET);
1682 if (save & 0x80) {
1683 pr_debug("w83781d: Detection failed at step 2\n");
1684 goto release;
1685 }
1686 val = ~save & 0x7f;
1687 outb_p(val, address + W83781D_ADDR_REG_OFFSET);
1688 if (inb_p(address + W83781D_ADDR_REG_OFFSET) != (val | 0x80)) {
1689 outb_p(save, address + W83781D_ADDR_REG_OFFSET);
1690 pr_debug("w83781d: Detection failed at step 3\n");
1691 goto release;
1692 }
1693
1694 /* We found a device, now see if it could be a W83781D */
1695 outb_p(W83781D_REG_CONFIG, address + W83781D_ADDR_REG_OFFSET);
1696 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1697 if (val & 0x80) {
1698 pr_debug("w83781d: Detection failed at step 4\n");
1699 goto release;
1700 }
1701 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET);
1702 save = inb_p(address + W83781D_DATA_REG_OFFSET);
1703 outb_p(W83781D_REG_CHIPMAN, address + W83781D_ADDR_REG_OFFSET);
1704 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1705 if ((!(save & 0x80) && (val != 0xa3))
1706 || ((save & 0x80) && (val != 0x5c))) {
1707 pr_debug("w83781d: Detection failed at step 5\n");
1708 goto release;
1709 }
1710 outb_p(W83781D_REG_I2C_ADDR, address + W83781D_ADDR_REG_OFFSET);
1711 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1712 if (val < 0x03 || val > 0x77) { /* Not a valid I2C address */
1713 pr_debug("w83781d: Detection failed at step 6\n");
1714 goto release;
1715 }
1716
1717 /* The busy flag should be clear again */
1718 if (inb_p(address + W83781D_ADDR_REG_OFFSET) & 0x80) {
1719 pr_debug("w83781d: Detection failed at step 7\n");
1720 goto release;
1721 }
1722
1723 /* Determine the chip type */
1724 outb_p(W83781D_REG_BANK, address + W83781D_ADDR_REG_OFFSET);
1725 save = inb_p(address + W83781D_DATA_REG_OFFSET);
1726 outb_p(save & 0xf8, address + W83781D_DATA_REG_OFFSET);
1727 outb_p(W83781D_REG_WCHIPID, address + W83781D_ADDR_REG_OFFSET);
1728 val = inb_p(address + W83781D_DATA_REG_OFFSET);
1729 if ((val & 0xfe) == 0x10 /* W83781D */
1730 || val == 0x30 /* W83782D */
1731 || val == 0x21) /* W83627HF */
1732 found = 1;
1733
1734 if (found)
1735 pr_info("w83781d: Found a %s chip at %#x\n",
1736 val == 0x21 ? "W83627HF" :
1737 val == 0x30 ? "W83782D" : "W83781D", (int)address);
1738
1739 release:
1740 release_region(address, W83781D_EXTENT);
1741 return found;
1742}
1743
1744static int __init
1745w83781d_isa_device_add(unsigned short address)
1746{
1747 struct resource res = {
1748 .start = address,
1749 .end = address + W83781D_EXTENT,
1750 .name = "w83781d",
1751 .flags = IORESOURCE_IO,
1752 };
1753 int err;
1754
1755 pdev = platform_device_alloc("w83781d", address);
1756 if (!pdev) {
1757 err = -ENOMEM;
1758 printk(KERN_ERR "w83781d: Device allocation failed\n");
1759 goto exit;
1760 }
1761
1762 err = platform_device_add_resources(pdev, &res, 1);
1763 if (err) {
1764 printk(KERN_ERR "w83781d: Device resource addition failed "
1765 "(%d)\n", err);
1766 goto exit_device_put;
1767 }
1768
1769 err = platform_device_add(pdev);
1770 if (err) {
1771 printk(KERN_ERR "w83781d: Device addition failed (%d)\n",
1772 err);
1773 goto exit_device_put;
1774 }
1775
1776 return 0;
1777
1778 exit_device_put:
1779 platform_device_put(pdev);
1780 exit:
1781 pdev = NULL;
1782 return err;
1783}
1784
1675static int __init 1785static int __init
1676sensors_w83781d_init(void) 1786sensors_w83781d_init(void)
1677{ 1787{
@@ -1679,21 +1789,36 @@ sensors_w83781d_init(void)
1679 1789
1680 res = i2c_add_driver(&w83781d_driver); 1790 res = i2c_add_driver(&w83781d_driver);
1681 if (res) 1791 if (res)
1682 return res; 1792 goto exit;
1793
1794 if (w83781d_isa_found(isa_address)) {
1795 res = platform_driver_register(&w83781d_isa_driver);
1796 if (res)
1797 goto exit_unreg_i2c_driver;
1683 1798
1684 /* Don't exit if this one fails, we still want the I2C variants 1799 /* Sets global pdev as a side effect */
1685 to work! */ 1800 res = w83781d_isa_device_add(isa_address);
1686 if (i2c_isa_add_driver(&w83781d_isa_driver)) 1801 if (res)
1687 isa_address = 0; 1802 goto exit_unreg_isa_driver;
1803 }
1688 1804
1689 return 0; 1805 return 0;
1806
1807 exit_unreg_isa_driver:
1808 platform_driver_unregister(&w83781d_isa_driver);
1809 exit_unreg_i2c_driver:
1810 i2c_del_driver(&w83781d_driver);
1811 exit:
1812 return res;
1690} 1813}
1691 1814
1692static void __exit 1815static void __exit
1693sensors_w83781d_exit(void) 1816sensors_w83781d_exit(void)
1694{ 1817{
1695 if (isa_address) 1818 if (pdev) {
1696 i2c_isa_del_driver(&w83781d_isa_driver); 1819 platform_device_unregister(pdev);
1820 platform_driver_unregister(&w83781d_isa_driver);
1821 }
1697 i2c_del_driver(&w83781d_driver); 1822 i2c_del_driver(&w83781d_driver);
1698} 1823}
1699 1824
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 434a61b415a3..96867347bcbf 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -4,6 +4,7 @@
4 4
5menuconfig I2C 5menuconfig I2C
6 tristate "I2C support" 6 tristate "I2C support"
7 depends on HAS_IOMEM
7 ---help--- 8 ---help---
8 I2C (pronounce: I-square-C) is a slow serial bus protocol used in 9 I2C (pronounce: I-square-C) is a slow serial bus protocol used in
9 many micro controller applications and developed by Philips. SMBus, 10 many micro controller applications and developed by Philips. SMBus,
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index f35156c58922..9c8b6d5eaec9 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -16,6 +16,7 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/version.h> 17#include <linux/version.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/err.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20#include <linux/types.h> 21#include <linux/types.h>
21#include <linux/delay.h> 22#include <linux/delay.h>
@@ -226,13 +227,14 @@ static int __devinit at91_i2c_probe(struct platform_device *pdev)
226 adapter->algo = &at91_algorithm; 227 adapter->algo = &at91_algorithm;
227 adapter->class = I2C_CLASS_HWMON; 228 adapter->class = I2C_CLASS_HWMON;
228 adapter->dev.parent = &pdev->dev; 229 adapter->dev.parent = &pdev->dev;
230 /* adapter->id == 0 ... only one TWI controller for now */
229 231
230 platform_set_drvdata(pdev, adapter); 232 platform_set_drvdata(pdev, adapter);
231 233
232 clk_enable(twi_clk); /* enable peripheral clock */ 234 clk_enable(twi_clk); /* enable peripheral clock */
233 at91_twi_hwinit(); /* initialize TWI controller */ 235 at91_twi_hwinit(); /* initialize TWI controller */
234 236
235 rc = i2c_add_adapter(adapter); 237 rc = i2c_add_numbered_adapter(adapter);
236 if (rc) { 238 if (rc) {
237 dev_err(&pdev->dev, "Adapter %s registration failed\n", 239 dev_err(&pdev->dev, "Adapter %s registration failed\n",
238 adapter->name); 240 adapter->name);
@@ -295,6 +297,9 @@ static int at91_i2c_resume(struct platform_device *pdev)
295#define at91_i2c_resume NULL 297#define at91_i2c_resume NULL
296#endif 298#endif
297 299
300/* work with "modprobe at91_i2c" from hotplugging or coldplugging */
301MODULE_ALIAS("at91_i2c");
302
298static struct platform_driver at91_i2c_driver = { 303static struct platform_driver at91_i2c_driver = {
299 .probe = at91_i2c_probe, 304 .probe = at91_i2c_probe,
300 .remove = __devexit_p(at91_i2c_remove), 305 .remove = __devexit_p(at91_i2c_remove),
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 8c953707253f..039a07fde908 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -175,6 +175,7 @@ static void i2c_parport_attach (struct parport *port)
175 } 175 }
176 adapter->algo_data.data = port; 176 adapter->algo_data.data = port;
177 adapter->adapter.algo_data = &adapter->algo_data; 177 adapter->adapter.algo_data = &adapter->algo_data;
178 adapter->adapter.dev.parent = port->physport->dev;
178 179
179 if (parport_claim_or_block(adapter->pdev) < 0) { 180 if (parport_claim_or_block(adapter->pdev) < 0) {
180 printk(KERN_ERR "i2c-parport: Could not claim parallel port\n"); 181 printk(KERN_ERR "i2c-parport: Could not claim parallel port\n");
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 873544ab598e..8a0a99b93641 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -548,7 +548,7 @@ static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
548 */ 548 */
549 icr = readl(_ICR(i2c)); 549 icr = readl(_ICR(i2c));
550 icr &= ~(ICR_STOP | ICR_ACKNAK); 550 icr &= ~(ICR_STOP | ICR_ACKNAK);
551 writel(icr, _IRC(i2c)); 551 writel(icr, _ICR(i2c));
552} 552}
553 553
554/* 554/*
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index e68a96f589fd..e4540fcf6476 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -830,7 +830,8 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
830 830
831 i2c->irq = res; 831 i2c->irq = res;
832 832
833 dev_dbg(&pdev->dev, "irq resource %p (%ld)\n", res, res->start); 833 dev_dbg(&pdev->dev, "irq resource %p (%lu)\n", res,
834 (unsigned long)res->start);
834 835
835 ret = i2c_add_adapter(&i2c->adap); 836 ret = i2c_add_adapter(&i2c->adap);
836 if (ret < 0) { 837 if (ret < 0) {
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
index 907999049d50..cb9abe7565a7 100644
--- a/drivers/i2c/busses/i2c-tiny-usb.c
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -208,7 +208,7 @@ static int i2c_tiny_usb_probe(struct usb_interface *interface,
208 dev->adapter.class = I2C_CLASS_HWMON; 208 dev->adapter.class = I2C_CLASS_HWMON;
209 dev->adapter.algo = &usb_algorithm; 209 dev->adapter.algo = &usb_algorithm;
210 dev->adapter.algo_data = dev; 210 dev->adapter.algo_data = dev;
211 snprintf(dev->adapter.name, I2C_NAME_SIZE, 211 snprintf(dev->adapter.name, sizeof(dev->adapter.name),
212 "i2c-tiny-usb at bus %03d device %03d", 212 "i2c-tiny-usb at bus %03d device %03d",
213 dev->usb_dev->bus->busnum, dev->usb_dev->devnum); 213 dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
214 214
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 0db56e7bc34e..0d6bd4f7b7fa 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -28,7 +28,6 @@
28#include <linux/kernel.h> 28#include <linux/kernel.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/smp_lock.h>
32#include <linux/pci.h> 31#include <linux/pci.h>
33#include <linux/delay.h> 32#include <linux/delay.h>
34#include <linux/mutex.h> 33#include <linux/mutex.h>
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 7ed92dc3d833..3c3f2ebf3fc9 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -354,7 +354,7 @@ static void tps65010_interrupt(struct tps65010 *tps)
354 * also needs to get error handling and probably 354 * also needs to get error handling and probably
355 * an #ifdef CONFIG_SOFTWARE_SUSPEND 355 * an #ifdef CONFIG_SOFTWARE_SUSPEND
356 */ 356 */
357 pm_suspend(PM_SUSPEND_DISK); 357 hibernate();
358#endif 358#endif
359 poll = 1; 359 poll = 1;
360 } 360 }
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 64f8e56d300e..435925eba437 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -697,9 +697,10 @@ int i2c_attach_client(struct i2c_client *client)
697 if (client->driver) 697 if (client->driver)
698 client->dev.driver = &client->driver->driver; 698 client->dev.driver = &client->driver->driver;
699 699
700 if (client->driver && !is_newstyle_driver(client->driver)) 700 if (client->driver && !is_newstyle_driver(client->driver)) {
701 client->dev.release = i2c_client_release; 701 client->dev.release = i2c_client_release;
702 else 702 client->dev.uevent_suppress = 1;
703 } else
703 client->dev.release = i2c_client_dev_release; 704 client->dev.release = i2c_client_dev_release;
704 705
705 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id), 706 snprintf(&client->dev.bus_id[0], sizeof(client->dev.bus_id),
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index cb4fa9bef8cd..e7a709710592 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -30,7 +30,6 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/fs.h> 31#include <linux/fs.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/smp_lock.h>
34#include <linux/init.h> 33#include <linux/init.h>
35#include <linux/list.h> 34#include <linux/list.h>
36#include <linux/i2c.h> 35#include <linux/i2c.h>
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 5bdf64b77913..b1a9b81c211f 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -4,12 +4,10 @@
4# Andre Hedrick <andre@linux-ide.org> 4# Andre Hedrick <andre@linux-ide.org>
5# 5#
6 6
7if BLOCK 7menuconfig IDE
8
9menu "ATA/ATAPI/MFM/RLL support"
10
11config IDE
12 tristate "ATA/ATAPI/MFM/RLL support" 8 tristate "ATA/ATAPI/MFM/RLL support"
9 depends on BLOCK
10 depends on HAS_IOMEM
13 ---help--- 11 ---help---
14 If you say Y here, your kernel will be able to manage low cost mass 12 If you say Y here, your kernel will be able to manage low cost mass
15 storage units such as ATA/(E)IDE and ATAPI units. The most common 13 storage units such as ATA/(E)IDE and ATAPI units. The most common
@@ -291,6 +289,17 @@ config IDE_TASK_IOCTL
291 289
292 If you are unsure, say N here. 290 If you are unsure, say N here.
293 291
292config IDE_PROC_FS
293 bool "legacy /proc/ide/ support"
294 depends on IDE && PROC_FS
295 default y
296 help
297 This option enables support for the various files in
298 /proc/ide. In Linux 2.6 this has been superseded by
299 files in sysfs but many legacy applications rely on this.
300
301 If unsure say Y.
302
294comment "IDE chipset support/bugfixes" 303comment "IDE chipset support/bugfixes"
295 304
296config IDE_GENERIC 305config IDE_GENERIC
@@ -360,6 +369,9 @@ config IDEPCI_SHARE_IRQ
360 It is safe to say Y to this question, in most cases. 369 It is safe to say Y to this question, in most cases.
361 If unsure, say N. 370 If unsure, say N.
362 371
372config IDEPCI_PCIBUS_ORDER
373 def_bool PCI && BLK_DEV_IDE=y && BLK_DEV_IDEPCI
374
363config BLK_DEV_OFFBOARD 375config BLK_DEV_OFFBOARD
364 bool "Boot off-board chipsets first support" 376 bool "Boot off-board chipsets first support"
365 depends on PCI && BLK_DEV_IDEPCI 377 depends on PCI && BLK_DEV_IDEPCI
@@ -1084,8 +1096,4 @@ config BLK_DEV_HD_ONLY
1084config BLK_DEV_HD 1096config BLK_DEV_HD
1085 def_bool BLK_DEV_HD_IDE || BLK_DEV_HD_ONLY 1097 def_bool BLK_DEV_HD_IDE || BLK_DEV_HD_ONLY
1086 1098
1087endif 1099endif # IDE
1088
1089endmenu
1090
1091endif
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index d9f029e8ff74..75dc6969e0a7 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -20,7 +20,7 @@ ide-core-$(CONFIG_BLK_DEV_CMD640) += pci/cmd640.o
20# Core IDE code - must come before legacy 20# Core IDE code - must come before legacy
21ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o 21ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o
22ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o 22ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o
23ide-core-$(CONFIG_PROC_FS) += ide-proc.o 23ide-core-$(CONFIG_IDE_PROC_FS) += ide-proc.o
24ide-core-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o 24ide-core-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
25ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o 25ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o
26 26
diff --git a/drivers/ide/arm/bast-ide.c b/drivers/ide/arm/bast-ide.c
index 9d474e5fd8dc..f7449d04114a 100644
--- a/drivers/ide/arm/bast-ide.c
+++ b/drivers/ide/arm/bast-ide.c
@@ -45,7 +45,7 @@ bastide_register(unsigned int base, unsigned int aux, int irq,
45 hw.io_ports[IDE_CONTROL_OFFSET] = aux + (6 * 0x20); 45 hw.io_ports[IDE_CONTROL_OFFSET] = aux + (6 * 0x20);
46 hw.irq = irq; 46 hw.irq = irq;
47 47
48 ide_register_hw(&hw, hwif); 48 ide_register_hw(&hw, 0, hwif);
49 49
50 return 0; 50 return 0;
51} 51}
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index e2953fc1fafb..66f826252aee 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -342,7 +342,7 @@ static int icside_dma_check(ide_drive_t *drive)
342 * Enable DMA on any drive that has multiword DMA 342 * Enable DMA on any drive that has multiword DMA
343 */ 343 */
344 if (id->field_valid & 2) { 344 if (id->field_valid & 2) {
345 xfer_mode = ide_dma_speed(drive, 0); 345 xfer_mode = ide_max_dma_mode(drive);
346 goto out; 346 goto out;
347 } 347 }
348 348
@@ -565,8 +565,7 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec)
565 ide_hwif_t *hwif; 565 ide_hwif_t *hwif;
566 void __iomem *base; 566 void __iomem *base;
567 567
568 base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), 568 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
569 ecard_resource_len(ec, ECARD_RES_MEMC));
570 if (!base) 569 if (!base)
571 return -ENOMEM; 570 return -ENOMEM;
572 571
@@ -574,8 +573,8 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec)
574 573
575 ec->irqaddr = base + ICS_ARCIN_V5_INTRSTAT; 574 ec->irqaddr = base + ICS_ARCIN_V5_INTRSTAT;
576 ec->irqmask = 1; 575 ec->irqmask = 1;
577 ec->irq_data = state; 576
578 ec->ops = &icside_ops_arcin_v5; 577 ecard_setirq(ec, &icside_ops_arcin_v5, state);
579 578
580 /* 579 /*
581 * Be on the safe side - disable interrupts 580 * Be on the safe side - disable interrupts
@@ -583,15 +582,14 @@ icside_register_v5(struct icside_state *state, struct expansion_card *ec)
583 icside_irqdisable_arcin_v5(ec, 0); 582 icside_irqdisable_arcin_v5(ec, 0);
584 583
585 hwif = icside_setup(base, &icside_cardinfo_v5, ec); 584 hwif = icside_setup(base, &icside_cardinfo_v5, ec);
586 if (!hwif) { 585 if (!hwif)
587 iounmap(base);
588 return -ENODEV; 586 return -ENODEV;
589 }
590 587
591 state->hwif[0] = hwif; 588 state->hwif[0] = hwif;
592 589
593 probe_hwif_init(hwif); 590 probe_hwif_init(hwif);
594 create_proc_ide_interfaces(); 591
592 ide_proc_register_port(hwif);
595 593
596 return 0; 594 return 0;
597} 595}
@@ -604,8 +602,7 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
604 unsigned int sel = 0; 602 unsigned int sel = 0;
605 int ret; 603 int ret;
606 604
607 ioc_base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 605 ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
608 ecard_resource_len(ec, ECARD_RES_IOCFAST));
609 if (!ioc_base) { 606 if (!ioc_base) {
610 ret = -ENOMEM; 607 ret = -ENOMEM;
611 goto out; 608 goto out;
@@ -614,11 +611,10 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
614 easi_base = ioc_base; 611 easi_base = ioc_base;
615 612
616 if (ecard_resource_flags(ec, ECARD_RES_EASI)) { 613 if (ecard_resource_flags(ec, ECARD_RES_EASI)) {
617 easi_base = ioremap(ecard_resource_start(ec, ECARD_RES_EASI), 614 easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0);
618 ecard_resource_len(ec, ECARD_RES_EASI));
619 if (!easi_base) { 615 if (!easi_base) {
620 ret = -ENOMEM; 616 ret = -ENOMEM;
621 goto unmap_slot; 617 goto out;
622 } 618 }
623 619
624 /* 620 /*
@@ -629,8 +625,7 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
629 625
630 writeb(sel, ioc_base); 626 writeb(sel, ioc_base);
631 627
632 ec->irq_data = state; 628 ecard_setirq(ec, &icside_ops_arcin_v6, state);
633 ec->ops = &icside_ops_arcin_v6;
634 629
635 state->irq_port = easi_base; 630 state->irq_port = easi_base;
636 state->ioc_base = ioc_base; 631 state->ioc_base = ioc_base;
@@ -648,7 +643,7 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
648 643
649 if (!hwif || !mate) { 644 if (!hwif || !mate) {
650 ret = -ENODEV; 645 ret = -ENODEV;
651 goto unmap_port; 646 goto out;
652 } 647 }
653 648
654 state->hwif[0] = hwif; 649 state->hwif[0] = hwif;
@@ -679,15 +674,12 @@ icside_register_v6(struct icside_state *state, struct expansion_card *ec)
679 674
680 probe_hwif_init(hwif); 675 probe_hwif_init(hwif);
681 probe_hwif_init(mate); 676 probe_hwif_init(mate);
682 create_proc_ide_interfaces(); 677
678 ide_proc_register_port(hwif);
679 ide_proc_register_port(mate);
683 680
684 return 0; 681 return 0;
685 682
686 unmap_port:
687 if (easi_base != ioc_base)
688 iounmap(easi_base);
689 unmap_slot:
690 iounmap(ioc_base);
691 out: 683 out:
692 return ret; 684 return ret;
693} 685}
@@ -713,8 +705,7 @@ icside_probe(struct expansion_card *ec, const struct ecard_id *id)
713 state->type = ICS_TYPE_NOTYPE; 705 state->type = ICS_TYPE_NOTYPE;
714 state->dev = &ec->dev; 706 state->dev = &ec->dev;
715 707
716 idmem = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 708 idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
717 ecard_resource_len(ec, ECARD_RES_IOCFAST));
718 if (idmem) { 709 if (idmem) {
719 unsigned int type; 710 unsigned int type;
720 711
@@ -722,7 +713,7 @@ icside_probe(struct expansion_card *ec, const struct ecard_id *id)
722 type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1; 713 type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1;
723 type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2; 714 type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2;
724 type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3; 715 type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3;
725 iounmap(idmem); 716 ecardm_iounmap(ec, idmem);
726 717
727 state->type = type; 718 state->type = type;
728 } 719 }
@@ -790,13 +781,6 @@ static void __devexit icside_remove(struct expansion_card *ec)
790 } 781 }
791 782
792 ecard_set_drvdata(ec, NULL); 783 ecard_set_drvdata(ec, NULL);
793 ec->ops = NULL;
794 ec->irq_data = NULL;
795
796 if (state->ioc_base)
797 iounmap(state->ioc_base);
798 if (state->ioc_base != state->irq_port)
799 iounmap(state->irq_port);
800 784
801 kfree(state); 785 kfree(state);
802 ecard_release_resources(ec); 786 ecard_release_resources(ec);
diff --git a/drivers/ide/arm/ide_arm.c b/drivers/ide/arm/ide_arm.c
index 23488c4d1fcd..a3d6744e870a 100644
--- a/drivers/ide/arm/ide_arm.c
+++ b/drivers/ide/arm/ide_arm.c
@@ -38,6 +38,6 @@ void __init ide_arm_init(void)
38 memset(&hw, 0, sizeof(hw)); 38 memset(&hw, 0, sizeof(hw));
39 ide_std_init_ports(&hw, IDE_ARM_IO, IDE_ARM_IO + 0x206); 39 ide_std_init_ports(&hw, IDE_ARM_IO, IDE_ARM_IO + 0x206);
40 hw.irq = IDE_ARM_IRQ; 40 hw.irq = IDE_ARM_IRQ;
41 ide_register_hw(&hw, NULL); 41 ide_register_hw(&hw, 1, NULL);
42 } 42 }
43} 43}
diff --git a/drivers/ide/arm/rapide.c b/drivers/ide/arm/rapide.c
index 9c6c49fdd2b1..83811af11610 100644
--- a/drivers/ide/arm/rapide.c
+++ b/drivers/ide/arm/rapide.c
@@ -63,8 +63,7 @@ rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
63 if (ret) 63 if (ret)
64 goto out; 64 goto out;
65 65
66 base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), 66 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
67 ecard_resource_len(ec, ECARD_RES_MEMC));
68 if (!base) { 67 if (!base) {
69 ret = -ENOMEM; 68 ret = -ENOMEM;
70 goto release; 69 goto release;
@@ -76,12 +75,11 @@ rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
76 hwif->gendev.parent = &ec->dev; 75 hwif->gendev.parent = &ec->dev;
77 hwif->noprobe = 0; 76 hwif->noprobe = 0;
78 probe_hwif_init(hwif); 77 probe_hwif_init(hwif);
79 create_proc_ide_interfaces(); 78 ide_proc_register_port(hwif);
80 ecard_set_drvdata(ec, hwif); 79 ecard_set_drvdata(ec, hwif);
81 goto out; 80 goto out;
82 } 81 }
83 82
84 iounmap(base);
85 release: 83 release:
86 ecard_release_resources(ec); 84 ecard_release_resources(ec);
87 out: 85 out:
@@ -96,7 +94,6 @@ static void __devexit rapide_remove(struct expansion_card *ec)
96 94
97 /* there must be a better way */ 95 /* there must be a better way */
98 ide_unregister(hwif - ide_hwifs); 96 ide_unregister(hwif - ide_hwifs);
99 iounmap(hwif->hwif_data);
100 ecard_release_resources(ec); 97 ecard_release_resources(ec);
101} 98}
102 99
diff --git a/drivers/ide/cris/ide-cris.c b/drivers/ide/cris/ide-cris.c
index 5e8efc89255a..ca0341c05e55 100644
--- a/drivers/ide/cris/ide-cris.c
+++ b/drivers/ide/cris/ide-cris.c
@@ -796,7 +796,7 @@ init_e100_ide (void)
796 ide_offsets, 796 ide_offsets,
797 0, 0, cris_ide_ack_intr, 797 0, 0, cris_ide_ack_intr,
798 ide_default_irq(0)); 798 ide_default_irq(0));
799 ide_register_hw(&hw, &hwif); 799 ide_register_hw(&hw, 1, &hwif);
800 hwif->mmio = 1; 800 hwif->mmio = 1;
801 hwif->chipset = ide_etrax100; 801 hwif->chipset = ide_etrax100;
802 hwif->tuneproc = &tune_cris_ide; 802 hwif->tuneproc = &tune_cris_ide;
@@ -1002,18 +1002,6 @@ static int cris_ide_build_dmatable (ide_drive_t *drive)
1002 return 1; /* let the PIO routines handle this weirdness */ 1002 return 1; /* let the PIO routines handle this weirdness */
1003} 1003}
1004 1004
1005static int cris_config_drive_for_dma (ide_drive_t *drive)
1006{
1007 u8 speed = ide_dma_speed(drive, 1);
1008
1009 if (!speed)
1010 return 0;
1011
1012 speed_cris_ide(drive, speed);
1013
1014 return ide_dma_enable(drive);
1015}
1016
1017/* 1005/*
1018 * cris_dma_intr() is the handler for disk read/write DMA interrupts 1006 * cris_dma_intr() is the handler for disk read/write DMA interrupts
1019 */ 1007 */
@@ -1043,7 +1031,7 @@ static ide_startstop_t cris_dma_intr (ide_drive_t *drive)
1043 1031
1044static int cris_dma_check(ide_drive_t *drive) 1032static int cris_dma_check(ide_drive_t *drive)
1045{ 1033{
1046 if (ide_use_dma(drive) && cris_config_drive_for_dma(drive)) 1034 if (ide_tune_dma(drive))
1047 return 0; 1035 return 0;
1048 1036
1049 return -1; 1037 return -1;
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c
index 88750a300337..6d26ad7360d5 100644
--- a/drivers/ide/h8300/ide-h8300.c
+++ b/drivers/ide/h8300/ide-h8300.c
@@ -101,7 +101,7 @@ void __init h8300_ide_init(void)
101 hw_setup(&hw); 101 hw_setup(&hw);
102 102
103 /* register if */ 103 /* register if */
104 idx = ide_register_hw(&hw, &hwif); 104 idx = ide_register_hw(&hw, 1, &hwif);
105 if (idx == -1) { 105 if (idx == -1) {
106 printk(KERN_ERR "ide-h8300: IDE I/F register failed\n"); 106 printk(KERN_ERR "ide-h8300: IDE I/F register failed\n");
107 return; 107 return;
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 638becda81c6..252ab8295edf 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -3059,10 +3059,14 @@ int ide_cdrom_probe_capabilities (ide_drive_t *drive)
3059 return nslots; 3059 return nslots;
3060} 3060}
3061 3061
3062#ifdef CONFIG_IDE_PROC_FS
3062static void ide_cdrom_add_settings(ide_drive_t *drive) 3063static void ide_cdrom_add_settings(ide_drive_t *drive)
3063{ 3064{
3064 ide_add_setting(drive, "dsc_overlap", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL); 3065 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL);
3065} 3066}
3067#else
3068static inline void ide_cdrom_add_settings(ide_drive_t *drive) { ; }
3069#endif
3066 3070
3067/* 3071/*
3068 * standard prep_rq_fn that builds 10 byte cmds 3072 * standard prep_rq_fn that builds 10 byte cmds
@@ -3274,7 +3278,7 @@ int ide_cdrom_setup (ide_drive_t *drive)
3274 return 0; 3278 return 0;
3275} 3279}
3276 3280
3277#ifdef CONFIG_PROC_FS 3281#ifdef CONFIG_IDE_PROC_FS
3278static 3282static
3279sector_t ide_cdrom_capacity (ide_drive_t *drive) 3283sector_t ide_cdrom_capacity (ide_drive_t *drive)
3280{ 3284{
@@ -3291,7 +3295,7 @@ static void ide_cd_remove(ide_drive_t *drive)
3291{ 3295{
3292 struct cdrom_info *info = drive->driver_data; 3296 struct cdrom_info *info = drive->driver_data;
3293 3297
3294 ide_unregister_subdriver(drive, info->driver); 3298 ide_proc_unregister_driver(drive, info->driver);
3295 3299
3296 del_gendisk(info->disk); 3300 del_gendisk(info->disk);
3297 3301
@@ -3321,7 +3325,7 @@ static void ide_cd_release(struct kref *kref)
3321 3325
3322static int ide_cd_probe(ide_drive_t *); 3326static int ide_cd_probe(ide_drive_t *);
3323 3327
3324#ifdef CONFIG_PROC_FS 3328#ifdef CONFIG_IDE_PROC_FS
3325static int proc_idecd_read_capacity 3329static int proc_idecd_read_capacity
3326 (char *page, char **start, off_t off, int count, int *eof, void *data) 3330 (char *page, char **start, off_t off, int count, int *eof, void *data)
3327{ 3331{
@@ -3336,8 +3340,6 @@ static ide_proc_entry_t idecd_proc[] = {
3336 { "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL }, 3340 { "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL },
3337 { NULL, 0, NULL, NULL } 3341 { NULL, 0, NULL, NULL }
3338}; 3342};
3339#else
3340# define idecd_proc NULL
3341#endif 3343#endif
3342 3344
3343static ide_driver_t ide_cdrom_driver = { 3345static ide_driver_t ide_cdrom_driver = {
@@ -3355,7 +3357,9 @@ static ide_driver_t ide_cdrom_driver = {
3355 .end_request = ide_end_request, 3357 .end_request = ide_end_request,
3356 .error = __ide_error, 3358 .error = __ide_error,
3357 .abort = __ide_abort, 3359 .abort = __ide_abort,
3360#ifdef CONFIG_IDE_PROC_FS
3358 .proc = idecd_proc, 3361 .proc = idecd_proc,
3362#endif
3359}; 3363};
3360 3364
3361static int idecd_open(struct inode * inode, struct file * file) 3365static int idecd_open(struct inode * inode, struct file * file)
@@ -3517,7 +3521,7 @@ static int ide_cd_probe(ide_drive_t *drive)
3517 3521
3518 ide_init_disk(g, drive); 3522 ide_init_disk(g, drive);
3519 3523
3520 ide_register_subdriver(drive, &ide_cdrom_driver); 3524 ide_proc_register_driver(drive, &ide_cdrom_driver);
3521 3525
3522 kref_init(&info->kref); 3526 kref_init(&info->kref);
3523 3527
@@ -3534,7 +3538,7 @@ static int ide_cd_probe(ide_drive_t *drive)
3534 g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE; 3538 g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE;
3535 if (ide_cdrom_setup(drive)) { 3539 if (ide_cdrom_setup(drive)) {
3536 struct cdrom_device_info *devinfo = &info->devinfo; 3540 struct cdrom_device_info *devinfo = &info->devinfo;
3537 ide_unregister_subdriver(drive, &ide_cdrom_driver); 3541 ide_proc_unregister_driver(drive, &ide_cdrom_driver);
3538 kfree(info->buffer); 3542 kfree(info->buffer);
3539 kfree(info->toc); 3543 kfree(info->toc);
3540 kfree(info->changer_info); 3544 kfree(info->changer_info);
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 37aa6ddd9702..7fff773f2df7 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -559,8 +559,7 @@ static sector_t idedisk_capacity (ide_drive_t *drive)
559 return drive->capacity64 - drive->sect0; 559 return drive->capacity64 - drive->sect0;
560} 560}
561 561
562#ifdef CONFIG_PROC_FS 562#ifdef CONFIG_IDE_PROC_FS
563
564static int smart_enable(ide_drive_t *drive) 563static int smart_enable(ide_drive_t *drive)
565{ 564{
566 ide_task_t args; 565 ide_task_t args;
@@ -678,12 +677,7 @@ static ide_proc_entry_t idedisk_proc[] = {
678 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_smart_thresholds, NULL }, 677 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_smart_thresholds, NULL },
679 { NULL, 0, NULL, NULL } 678 { NULL, 0, NULL, NULL }
680}; 679};
681 680#endif /* CONFIG_IDE_PROC_FS */
682#else
683
684#define idedisk_proc NULL
685
686#endif /* CONFIG_PROC_FS */
687 681
688static void idedisk_prepare_flush(request_queue_t *q, struct request *rq) 682static void idedisk_prepare_flush(request_queue_t *q, struct request *rq)
689{ 683{
@@ -737,6 +731,9 @@ static int set_multcount(ide_drive_t *drive, int arg)
737{ 731{
738 struct request rq; 732 struct request rq;
739 733
734 if (arg < 0 || arg > drive->id->max_multsect)
735 return -EINVAL;
736
740 if (drive->special.b.set_multmode) 737 if (drive->special.b.set_multmode)
741 return -EBUSY; 738 return -EBUSY;
742 ide_init_drive_cmd (&rq); 739 ide_init_drive_cmd (&rq);
@@ -749,6 +746,9 @@ static int set_multcount(ide_drive_t *drive, int arg)
749 746
750static int set_nowerr(ide_drive_t *drive, int arg) 747static int set_nowerr(ide_drive_t *drive, int arg)
751{ 748{
749 if (arg < 0 || arg > 1)
750 return -EINVAL;
751
752 if (ide_spin_wait_hwgroup(drive)) 752 if (ide_spin_wait_hwgroup(drive))
753 return -EBUSY; 753 return -EBUSY;
754 drive->nowerr = arg; 754 drive->nowerr = arg;
@@ -800,6 +800,9 @@ static int write_cache(ide_drive_t *drive, int arg)
800 ide_task_t args; 800 ide_task_t args;
801 int err = 1; 801 int err = 1;
802 802
803 if (arg < 0 || arg > 1)
804 return -EINVAL;
805
803 if (ide_id_has_flush_cache(drive->id)) { 806 if (ide_id_has_flush_cache(drive->id)) {
804 memset(&args, 0, sizeof(ide_task_t)); 807 memset(&args, 0, sizeof(ide_task_t));
805 args.tfRegister[IDE_FEATURE_OFFSET] = (arg) ? 808 args.tfRegister[IDE_FEATURE_OFFSET] = (arg) ?
@@ -835,6 +838,9 @@ static int set_acoustic (ide_drive_t *drive, int arg)
835{ 838{
836 ide_task_t args; 839 ide_task_t args;
837 840
841 if (arg < 0 || arg > 254)
842 return -EINVAL;
843
838 memset(&args, 0, sizeof(ide_task_t)); 844 memset(&args, 0, sizeof(ide_task_t));
839 args.tfRegister[IDE_FEATURE_OFFSET] = (arg) ? SETFEATURES_EN_AAM : 845 args.tfRegister[IDE_FEATURE_OFFSET] = (arg) ? SETFEATURES_EN_AAM :
840 SETFEATURES_DIS_AAM; 846 SETFEATURES_DIS_AAM;
@@ -855,6 +861,9 @@ static int set_acoustic (ide_drive_t *drive, int arg)
855 */ 861 */
856static int set_lba_addressing(ide_drive_t *drive, int arg) 862static int set_lba_addressing(ide_drive_t *drive, int arg)
857{ 863{
864 if (arg < 0 || arg > 2)
865 return -EINVAL;
866
858 drive->addressing = 0; 867 drive->addressing = 0;
859 868
860 if (HWIF(drive)->no_lba48) 869 if (HWIF(drive)->no_lba48)
@@ -866,23 +875,27 @@ static int set_lba_addressing(ide_drive_t *drive, int arg)
866 return 0; 875 return 0;
867} 876}
868 877
878#ifdef CONFIG_IDE_PROC_FS
869static void idedisk_add_settings(ide_drive_t *drive) 879static void idedisk_add_settings(ide_drive_t *drive)
870{ 880{
871 struct hd_driveid *id = drive->id; 881 struct hd_driveid *id = drive->id;
872 882
873 ide_add_setting(drive, "bios_cyl", SETTING_RW, -1, -1, TYPE_INT, 0, 65535, 1, 1, &drive->bios_cyl, NULL); 883 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 65535, 1, 1, &drive->bios_cyl, NULL);
874 ide_add_setting(drive, "bios_head", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL); 884 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL);
875 ide_add_setting(drive, "bios_sect", SETTING_RW, -1, -1, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL); 885 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL);
876 ide_add_setting(drive, "address", SETTING_RW, HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, TYPE_INTA, 0, 2, 1, 1, &drive->addressing, set_lba_addressing); 886 ide_add_setting(drive, "address", SETTING_RW, TYPE_BYTE, 0, 2, 1, 1, &drive->addressing, set_lba_addressing);
877 ide_add_setting(drive, "bswap", SETTING_READ, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->bswap, NULL); 887 ide_add_setting(drive, "bswap", SETTING_READ, TYPE_BYTE, 0, 1, 1, 1, &drive->bswap, NULL);
878 ide_add_setting(drive, "multcount", id ? SETTING_RW : SETTING_READ, HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, TYPE_BYTE, 0, id ? id->max_multsect : 0, 1, 1, &drive->mult_count, set_multcount); 888 ide_add_setting(drive, "multcount", SETTING_RW, TYPE_BYTE, 0, id->max_multsect, 1, 1, &drive->mult_count, set_multcount);
879 ide_add_setting(drive, "nowerr", SETTING_RW, HDIO_GET_NOWERR, HDIO_SET_NOWERR, TYPE_BYTE, 0, 1, 1, 1, &drive->nowerr, set_nowerr); 889 ide_add_setting(drive, "nowerr", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->nowerr, set_nowerr);
880 ide_add_setting(drive, "lun", SETTING_RW, -1, -1, TYPE_INT, 0, 7, 1, 1, &drive->lun, NULL); 890 ide_add_setting(drive, "lun", SETTING_RW, TYPE_INT, 0, 7, 1, 1, &drive->lun, NULL);
881 ide_add_setting(drive, "wcache", SETTING_RW, HDIO_GET_WCACHE, HDIO_SET_WCACHE, TYPE_BYTE, 0, 1, 1, 1, &drive->wcache, write_cache); 891 ide_add_setting(drive, "wcache", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->wcache, write_cache);
882 ide_add_setting(drive, "acoustic", SETTING_RW, HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, TYPE_BYTE, 0, 254, 1, 1, &drive->acoustic, set_acoustic); 892 ide_add_setting(drive, "acoustic", SETTING_RW, TYPE_BYTE, 0, 254, 1, 1, &drive->acoustic, set_acoustic);
883 ide_add_setting(drive, "failures", SETTING_RW, -1, -1, TYPE_INT, 0, 65535, 1, 1, &drive->failures, NULL); 893 ide_add_setting(drive, "failures", SETTING_RW, TYPE_INT, 0, 65535, 1, 1, &drive->failures, NULL);
884 ide_add_setting(drive, "max_failures", SETTING_RW, -1, -1, TYPE_INT, 0, 65535, 1, 1, &drive->max_failures, NULL); 894 ide_add_setting(drive, "max_failures", SETTING_RW, TYPE_INT, 0, 65535, 1, 1, &drive->max_failures, NULL);
885} 895}
896#else
897static inline void idedisk_add_settings(ide_drive_t *drive) { ; }
898#endif
886 899
887static void idedisk_setup (ide_drive_t *drive) 900static void idedisk_setup (ide_drive_t *drive)
888{ 901{
@@ -1001,7 +1014,7 @@ static void ide_disk_remove(ide_drive_t *drive)
1001 struct ide_disk_obj *idkp = drive->driver_data; 1014 struct ide_disk_obj *idkp = drive->driver_data;
1002 struct gendisk *g = idkp->disk; 1015 struct gendisk *g = idkp->disk;
1003 1016
1004 ide_unregister_subdriver(drive, idkp->driver); 1017 ide_proc_unregister_driver(drive, idkp->driver);
1005 1018
1006 del_gendisk(g); 1019 del_gendisk(g);
1007 1020
@@ -1066,7 +1079,9 @@ static ide_driver_t idedisk_driver = {
1066 .end_request = ide_end_request, 1079 .end_request = ide_end_request,
1067 .error = __ide_error, 1080 .error = __ide_error,
1068 .abort = __ide_abort, 1081 .abort = __ide_abort,
1082#ifdef CONFIG_IDE_PROC_FS
1069 .proc = idedisk_proc, 1083 .proc = idedisk_proc,
1084#endif
1070}; 1085};
1071 1086
1072static int idedisk_open(struct inode *inode, struct file *filp) 1087static int idedisk_open(struct inode *inode, struct file *filp)
@@ -1140,9 +1155,49 @@ static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1140static int idedisk_ioctl(struct inode *inode, struct file *file, 1155static int idedisk_ioctl(struct inode *inode, struct file *file,
1141 unsigned int cmd, unsigned long arg) 1156 unsigned int cmd, unsigned long arg)
1142{ 1157{
1158 unsigned long flags;
1143 struct block_device *bdev = inode->i_bdev; 1159 struct block_device *bdev = inode->i_bdev;
1144 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk); 1160 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
1145 return generic_ide_ioctl(idkp->drive, file, bdev, cmd, arg); 1161 ide_drive_t *drive = idkp->drive;
1162 int err, (*setfunc)(ide_drive_t *, int);
1163 u8 *val;
1164
1165 switch (cmd) {
1166 case HDIO_GET_ADDRESS: val = &drive->addressing; goto read_val;
1167 case HDIO_GET_MULTCOUNT: val = &drive->mult_count; goto read_val;
1168 case HDIO_GET_NOWERR: val = &drive->nowerr; goto read_val;
1169 case HDIO_GET_WCACHE: val = &drive->wcache; goto read_val;
1170 case HDIO_GET_ACOUSTIC: val = &drive->acoustic; goto read_val;
1171 case HDIO_SET_ADDRESS: setfunc = set_lba_addressing; goto set_val;
1172 case HDIO_SET_MULTCOUNT: setfunc = set_multcount; goto set_val;
1173 case HDIO_SET_NOWERR: setfunc = set_nowerr; goto set_val;
1174 case HDIO_SET_WCACHE: setfunc = write_cache; goto set_val;
1175 case HDIO_SET_ACOUSTIC: setfunc = set_acoustic; goto set_val;
1176 }
1177
1178 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
1179
1180read_val:
1181 down(&ide_setting_sem);
1182 spin_lock_irqsave(&ide_lock, flags);
1183 err = *val;
1184 spin_unlock_irqrestore(&ide_lock, flags);
1185 up(&ide_setting_sem);
1186 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1187
1188set_val:
1189 if (bdev != bdev->bd_contains)
1190 err = -EINVAL;
1191 else {
1192 if (!capable(CAP_SYS_ADMIN))
1193 err = -EACCES;
1194 else {
1195 down(&ide_setting_sem);
1196 err = setfunc(drive, arg);
1197 up(&ide_setting_sem);
1198 }
1199 }
1200 return err;
1146} 1201}
1147 1202
1148static int idedisk_media_changed(struct gendisk *disk) 1203static int idedisk_media_changed(struct gendisk *disk)
@@ -1202,7 +1257,7 @@ static int ide_disk_probe(ide_drive_t *drive)
1202 1257
1203 ide_init_disk(g, drive); 1258 ide_init_disk(g, drive);
1204 1259
1205 ide_register_subdriver(drive, &idedisk_driver); 1260 ide_proc_register_driver(drive, &idedisk_driver);
1206 1261
1207 kref_init(&idkp->kref); 1262 kref_init(&idkp->kref);
1208 1263
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index fd213088b06b..b77b7d138c49 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -670,40 +670,105 @@ int __ide_dma_good_drive (ide_drive_t *drive)
670 670
671EXPORT_SYMBOL(__ide_dma_good_drive); 671EXPORT_SYMBOL(__ide_dma_good_drive);
672 672
673int ide_use_dma(ide_drive_t *drive) 673static const u8 xfer_mode_bases[] = {
674 XFER_UDMA_0,
675 XFER_MW_DMA_0,
676 XFER_SW_DMA_0,
677};
678
679static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base)
674{ 680{
675 struct hd_driveid *id = drive->id; 681 struct hd_driveid *id = drive->id;
676 ide_hwif_t *hwif = drive->hwif; 682 ide_hwif_t *hwif = drive->hwif;
683 unsigned int mask = 0;
684
685 switch(base) {
686 case XFER_UDMA_0:
687 if ((id->field_valid & 4) == 0)
688 break;
689
690 mask = id->dma_ultra & hwif->ultra_mask;
691
692 if (hwif->udma_filter)
693 mask &= hwif->udma_filter(drive);
694
695 if ((mask & 0x78) && (eighty_ninty_three(drive) == 0))
696 mask &= 0x07;
697 break;
698 case XFER_MW_DMA_0:
699 if (id->field_valid & 2)
700 mask = id->dma_mword & hwif->mwdma_mask;
701 break;
702 case XFER_SW_DMA_0:
703 if (id->field_valid & 2)
704 mask = id->dma_1word & hwif->swdma_mask;
705 break;
706 default:
707 BUG();
708 break;
709 }
710
711 return mask;
712}
713
714/**
715 * ide_max_dma_mode - compute DMA speed
716 * @drive: IDE device
717 *
718 * Checks the drive capabilities and returns the speed to use
719 * for the DMA transfer. Returns 0 if the drive is incapable
720 * of DMA transfers.
721 */
722
723u8 ide_max_dma_mode(ide_drive_t *drive)
724{
725 ide_hwif_t *hwif = drive->hwif;
726 unsigned int mask;
727 int x, i;
728 u8 mode = 0;
677 729
678 if ((id->capability & 1) == 0 || drive->autodma == 0) 730 if (drive->media != ide_disk && hwif->atapi_dma == 0)
731 return 0;
732
733 for (i = 0; i < ARRAY_SIZE(xfer_mode_bases); i++) {
734 mask = ide_get_mode_mask(drive, xfer_mode_bases[i]);
735 x = fls(mask) - 1;
736 if (x >= 0) {
737 mode = xfer_mode_bases[i] + x;
738 break;
739 }
740 }
741
742 printk(KERN_DEBUG "%s: selected mode 0x%x\n", drive->name, mode);
743
744 return mode;
745}
746
747EXPORT_SYMBOL_GPL(ide_max_dma_mode);
748
749int ide_tune_dma(ide_drive_t *drive)
750{
751 u8 speed;
752
753 if ((drive->id->capability & 1) == 0 || drive->autodma == 0)
679 return 0; 754 return 0;
680 755
681 /* consult the list of known "bad" drives */ 756 /* consult the list of known "bad" drives */
682 if (__ide_dma_bad_drive(drive)) 757 if (__ide_dma_bad_drive(drive))
683 return 0; 758 return 0;
684 759
685 /* capable of UltraDMA modes */ 760 speed = ide_max_dma_mode(drive);
686 if (id->field_valid & 4) {
687 if (hwif->ultra_mask & id->dma_ultra)
688 return 1;
689 }
690 761
691 /* capable of regular DMA modes */ 762 if (!speed)
692 if (id->field_valid & 2) { 763 return 0;
693 if (hwif->mwdma_mask & id->dma_mword)
694 return 1;
695 if (hwif->swdma_mask & id->dma_1word)
696 return 1;
697 }
698 764
699 /* consult the list of known "good" drives */ 765 if (drive->hwif->speedproc(drive, speed))
700 if (__ide_dma_good_drive(drive) && id->eide_dma_time < 150) 766 return 0;
701 return 1;
702 767
703 return 0; 768 return 1;
704} 769}
705 770
706EXPORT_SYMBOL_GPL(ide_use_dma); 771EXPORT_SYMBOL_GPL(ide_tune_dma);
707 772
708void ide_dma_verbose(ide_drive_t *drive) 773void ide_dma_verbose(ide_drive_t *drive)
709{ 774{
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 57cd21c5b2c1..f429be88c4f9 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -1811,18 +1811,22 @@ static int idefloppy_identify_device (ide_drive_t *drive,struct hd_driveid *id)
1811 return 0; 1811 return 0;
1812} 1812}
1813 1813
1814#ifdef CONFIG_IDE_PROC_FS
1814static void idefloppy_add_settings(ide_drive_t *drive) 1815static void idefloppy_add_settings(ide_drive_t *drive)
1815{ 1816{
1816 idefloppy_floppy_t *floppy = drive->driver_data; 1817 idefloppy_floppy_t *floppy = drive->driver_data;
1817 1818
1818/* 1819/*
1819 * drive setting name read/write ioctl ioctl data type min max mul_factor div_factor data pointer set function 1820 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
1820 */ 1821 */
1821 ide_add_setting(drive, "bios_cyl", SETTING_RW, -1, -1, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL); 1822 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL);
1822 ide_add_setting(drive, "bios_head", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL); 1823 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL);
1823 ide_add_setting(drive, "bios_sect", SETTING_RW, -1, -1, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL); 1824 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL);
1824 ide_add_setting(drive, "ticks", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &floppy->ticks, NULL); 1825 ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &floppy->ticks, NULL);
1825} 1826}
1827#else
1828static inline void idefloppy_add_settings(ide_drive_t *drive) { ; }
1829#endif
1826 1830
1827/* 1831/*
1828 * Driver initialization. 1832 * Driver initialization.
@@ -1873,7 +1877,7 @@ static void ide_floppy_remove(ide_drive_t *drive)
1873 idefloppy_floppy_t *floppy = drive->driver_data; 1877 idefloppy_floppy_t *floppy = drive->driver_data;
1874 struct gendisk *g = floppy->disk; 1878 struct gendisk *g = floppy->disk;
1875 1879
1876 ide_unregister_subdriver(drive, floppy->driver); 1880 ide_proc_unregister_driver(drive, floppy->driver);
1877 1881
1878 del_gendisk(g); 1882 del_gendisk(g);
1879 1883
@@ -1892,8 +1896,7 @@ static void ide_floppy_release(struct kref *kref)
1892 kfree(floppy); 1896 kfree(floppy);
1893} 1897}
1894 1898
1895#ifdef CONFIG_PROC_FS 1899#ifdef CONFIG_IDE_PROC_FS
1896
1897static int proc_idefloppy_read_capacity 1900static int proc_idefloppy_read_capacity
1898 (char *page, char **start, off_t off, int count, int *eof, void *data) 1901 (char *page, char **start, off_t off, int count, int *eof, void *data)
1899{ 1902{
@@ -1909,12 +1912,7 @@ static ide_proc_entry_t idefloppy_proc[] = {
1909 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, 1912 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
1910 { NULL, 0, NULL, NULL } 1913 { NULL, 0, NULL, NULL }
1911}; 1914};
1912 1915#endif /* CONFIG_IDE_PROC_FS */
1913#else
1914
1915#define idefloppy_proc NULL
1916
1917#endif /* CONFIG_PROC_FS */
1918 1916
1919static int ide_floppy_probe(ide_drive_t *); 1917static int ide_floppy_probe(ide_drive_t *);
1920 1918
@@ -1933,7 +1931,9 @@ static ide_driver_t idefloppy_driver = {
1933 .end_request = idefloppy_do_end_request, 1931 .end_request = idefloppy_do_end_request,
1934 .error = __ide_error, 1932 .error = __ide_error,
1935 .abort = __ide_abort, 1933 .abort = __ide_abort,
1934#ifdef CONFIG_IDE_PROC_FS
1936 .proc = idefloppy_proc, 1935 .proc = idefloppy_proc,
1936#endif
1937}; 1937};
1938 1938
1939static int idefloppy_open(struct inode *inode, struct file *filp) 1939static int idefloppy_open(struct inode *inode, struct file *filp)
@@ -2159,7 +2159,7 @@ static int ide_floppy_probe(ide_drive_t *drive)
2159 2159
2160 ide_init_disk(g, drive); 2160 ide_init_disk(g, drive);
2161 2161
2162 ide_register_subdriver(drive, &idefloppy_driver); 2162 ide_proc_register_driver(drive, &idefloppy_driver);
2163 2163
2164 kref_init(&floppy->kref); 2164 kref_init(&floppy->kref);
2165 2165
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index 99fd56151131..0f72b98d727f 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -22,8 +22,6 @@ static int __init ide_generic_init(void)
22 if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET]) 22 if (ide_hwifs[0].io_ports[IDE_DATA_OFFSET])
23 ide_release_lock(); /* for atari only */ 23 ide_release_lock(); /* for atari only */
24 24
25 create_proc_ide_interfaces();
26
27 return 0; 25 return 0;
28} 26}
29 27
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 8670112f1d39..bfe8f1b712ba 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -172,15 +172,6 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
172 172
173 memset(args, 0, sizeof(*args)); 173 memset(args, 0, sizeof(*args));
174 174
175 if (drive->media != ide_disk) {
176 /*
177 * skip idedisk_pm_restore_pio and idedisk_pm_idle for ATAPI
178 * devices
179 */
180 if (pm->pm_step == idedisk_pm_restore_pio)
181 pm->pm_step = ide_pm_restore_dma;
182 }
183
184 switch (pm->pm_step) { 175 switch (pm->pm_step) {
185 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) */ 176 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) */
186 if (drive->media != ide_disk) 177 if (drive->media != ide_disk)
@@ -207,7 +198,13 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
207 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */ 198 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
208 if (drive->hwif->tuneproc != NULL) 199 if (drive->hwif->tuneproc != NULL)
209 drive->hwif->tuneproc(drive, 255); 200 drive->hwif->tuneproc(drive, 255);
210 ide_complete_power_step(drive, rq, 0, 0); 201 /*
202 * skip idedisk_pm_idle for ATAPI devices
203 */
204 if (drive->media != ide_disk)
205 pm->pm_step = ide_pm_restore_dma;
206 else
207 ide_complete_power_step(drive, rq, 0, 0);
211 return ide_stopped; 208 return ide_stopped;
212 209
213 case idedisk_pm_idle: /* Resume step 2 (idle) */ 210 case idedisk_pm_idle: /* Resume step 2 (idle) */
@@ -226,6 +223,7 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
226 break; 223 break;
227 if (drive->hwif->ide_dma_check == NULL) 224 if (drive->hwif->ide_dma_check == NULL)
228 break; 225 break;
226 drive->hwif->dma_off_quietly(drive);
229 ide_set_dma(drive); 227 ide_set_dma(drive);
230 break; 228 break;
231 } 229 }
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 3caa176b3155..f0be5f665a0e 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -571,51 +571,54 @@ EXPORT_SYMBOL(ide_wait_stat);
571 */ 571 */
572u8 eighty_ninty_three (ide_drive_t *drive) 572u8 eighty_ninty_three (ide_drive_t *drive)
573{ 573{
574 if(HWIF(drive)->udma_four == 0) 574 ide_hwif_t *hwif = drive->hwif;
575 return 0; 575 struct hd_driveid *id = drive->id;
576
577 if (hwif->udma_four == 0)
578 goto no_80w;
576 579
577 /* Check for SATA but only if we are ATA5 or higher */ 580 /* Check for SATA but only if we are ATA5 or higher */
578 if (drive->id->hw_config == 0 && (drive->id->major_rev_num & 0x7FE0)) 581 if (id->hw_config == 0 && (id->major_rev_num & 0x7FE0))
579 return 1; 582 return 1;
580 if (!(drive->id->hw_config & 0x6000)) 583
581 return 0;
582#ifndef CONFIG_IDEDMA_IVB
583 if(!(drive->id->hw_config & 0x4000))
584 return 0;
585#endif /* CONFIG_IDEDMA_IVB */
586 /* 584 /*
587 * FIXME: 585 * FIXME:
588 * - change master/slave IDENTIFY order 586 * - change master/slave IDENTIFY order
589 * - force bit13 (80c cable present) check 587 * - force bit13 (80c cable present) check
590 * (unless the slave device is pre-ATA3) 588 * (unless the slave device is pre-ATA3)
591 */ 589 */
592 return 1; 590#ifndef CONFIG_IDEDMA_IVB
593} 591 if (id->hw_config & 0x4000)
592#else
593 if (id->hw_config & 0x6000)
594#endif
595 return 1;
596
597no_80w:
598 if (drive->udma33_warned == 1)
599 return 0;
594 600
595EXPORT_SYMBOL(eighty_ninty_three); 601 printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, "
602 "limiting max speed to UDMA33\n",
603 drive->name, hwif->udma_four ? "drive" : "host");
604
605 drive->udma33_warned = 1;
606
607 return 0;
608}
596 609
597int ide_ata66_check (ide_drive_t *drive, ide_task_t *args) 610int ide_ata66_check (ide_drive_t *drive, ide_task_t *args)
598{ 611{
599 if ((args->tfRegister[IDE_COMMAND_OFFSET] == WIN_SETFEATURES) && 612 if ((args->tfRegister[IDE_COMMAND_OFFSET] == WIN_SETFEATURES) &&
600 (args->tfRegister[IDE_SECTOR_OFFSET] > XFER_UDMA_2) && 613 (args->tfRegister[IDE_SECTOR_OFFSET] > XFER_UDMA_2) &&
601 (args->tfRegister[IDE_FEATURE_OFFSET] == SETFEATURES_XFER)) { 614 (args->tfRegister[IDE_FEATURE_OFFSET] == SETFEATURES_XFER)) {
602#ifndef CONFIG_IDEDMA_IVB 615 if (eighty_ninty_three(drive) == 0) {
603 if ((drive->id->hw_config & 0x6000) == 0) { 616 printk(KERN_WARNING "%s: UDMA speeds >UDMA33 cannot "
604#else /* !CONFIG_IDEDMA_IVB */ 617 "be set\n", drive->name);
605 if (((drive->id->hw_config & 0x2000) == 0) ||
606 ((drive->id->hw_config & 0x4000) == 0)) {
607#endif /* CONFIG_IDEDMA_IVB */
608 printk("%s: Speed warnings UDMA 3/4/5 is not "
609 "functional.\n", drive->name);
610 return 1;
611 }
612 if (!HWIF(drive)->udma_four) {
613 printk("%s: Speed warnings UDMA 3/4/5 is not "
614 "functional.\n",
615 HWIF(drive)->name);
616 return 1; 618 return 1;
617 } 619 }
618 } 620 }
621
619 return 0; 622 return 0;
620} 623}
621 624
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 68719314df3f..074bb32a4a40 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -69,123 +69,41 @@ char *ide_xfer_verbose (u8 xfer_rate)
69EXPORT_SYMBOL(ide_xfer_verbose); 69EXPORT_SYMBOL(ide_xfer_verbose);
70 70
71/** 71/**
72 * ide_dma_speed - compute DMA speed 72 * ide_rate_filter - filter transfer mode
73 * @drive: drive 73 * @drive: IDE device
74 * @mode: modes available
75 *
76 * Checks the drive capabilities and returns the speed to use
77 * for the DMA transfer. Returns 0 if the drive is incapable
78 * of DMA transfers.
79 */
80
81u8 ide_dma_speed(ide_drive_t *drive, u8 mode)
82{
83 struct hd_driveid *id = drive->id;
84 ide_hwif_t *hwif = HWIF(drive);
85 u8 ultra_mask, mwdma_mask, swdma_mask;
86 u8 speed = 0;
87
88 if (drive->media != ide_disk && hwif->atapi_dma == 0)
89 return 0;
90
91 /* Capable of UltraDMA modes? */
92 ultra_mask = id->dma_ultra & hwif->ultra_mask;
93
94 if (!(id->field_valid & 4))
95 mode = 0; /* fallback to MW/SW DMA if no UltraDMA */
96
97 switch (mode) {
98 case 4:
99 if (ultra_mask & 0x40) {
100 speed = XFER_UDMA_6;
101 break;
102 }
103 case 3:
104 if (ultra_mask & 0x20) {
105 speed = XFER_UDMA_5;
106 break;
107 }
108 case 2:
109 if (ultra_mask & 0x10) {
110 speed = XFER_UDMA_4;
111 break;
112 }
113 if (ultra_mask & 0x08) {
114 speed = XFER_UDMA_3;
115 break;
116 }
117 case 1:
118 if (ultra_mask & 0x04) {
119 speed = XFER_UDMA_2;
120 break;
121 }
122 if (ultra_mask & 0x02) {
123 speed = XFER_UDMA_1;
124 break;
125 }
126 if (ultra_mask & 0x01) {
127 speed = XFER_UDMA_0;
128 break;
129 }
130 case 0:
131 mwdma_mask = id->dma_mword & hwif->mwdma_mask;
132
133 if (mwdma_mask & 0x04) {
134 speed = XFER_MW_DMA_2;
135 break;
136 }
137 if (mwdma_mask & 0x02) {
138 speed = XFER_MW_DMA_1;
139 break;
140 }
141 if (mwdma_mask & 0x01) {
142 speed = XFER_MW_DMA_0;
143 break;
144 }
145
146 swdma_mask = id->dma_1word & hwif->swdma_mask;
147
148 if (swdma_mask & 0x04) {
149 speed = XFER_SW_DMA_2;
150 break;
151 }
152 if (swdma_mask & 0x02) {
153 speed = XFER_SW_DMA_1;
154 break;
155 }
156 if (swdma_mask & 0x01) {
157 speed = XFER_SW_DMA_0;
158 break;
159 }
160 }
161
162 return speed;
163}
164EXPORT_SYMBOL(ide_dma_speed);
165
166
167/**
168 * ide_rate_filter - return best speed for mode
169 * @mode: modes available
170 * @speed: desired speed 74 * @speed: desired speed
171 * 75 *
172 * Given the available DMA/UDMA mode this function returns 76 * Given the available transfer modes this function returns
173 * the best available speed at or below the speed requested. 77 * the best available speed at or below the speed requested.
78 *
79 * FIXME: filter also PIO/SWDMA/MWDMA modes
174 */ 80 */
175 81
176u8 ide_rate_filter (u8 mode, u8 speed) 82u8 ide_rate_filter(ide_drive_t *drive, u8 speed)
177{ 83{
178#ifdef CONFIG_BLK_DEV_IDEDMA 84#ifdef CONFIG_BLK_DEV_IDEDMA
179 static u8 speed_max[] = { 85 ide_hwif_t *hwif = drive->hwif;
180 XFER_MW_DMA_2, XFER_UDMA_2, XFER_UDMA_4, 86 u8 mask = hwif->ultra_mask, mode = XFER_MW_DMA_2;
181 XFER_UDMA_5, XFER_UDMA_6 87
182 }; 88 if (hwif->udma_filter)
89 mask = hwif->udma_filter(drive);
90
91 /*
92 * TODO: speed > XFER_UDMA_2 extra check is needed to avoid false
93 * cable warning from eighty_ninty_three(), moving ide_rate_filter()
94 * calls from ->speedproc to core code will make this hack go away
95 */
96 if (speed > XFER_UDMA_2) {
97 if ((mask & 0x78) && (eighty_ninty_three(drive) == 0))
98 mask &= 0x07;
99 }
100
101 if (mask)
102 mode = fls(mask) - 1 + XFER_UDMA_0;
183 103
184// printk("%s: mode 0x%02x, speed 0x%02x\n", __FUNCTION__, mode, speed); 104// printk("%s: mode 0x%02x, speed 0x%02x\n", __FUNCTION__, mode, speed);
185 105
186 /* So that we remember to update this if new modes appear */ 106 return min(speed, mode);
187 BUG_ON(mode > 4);
188 return min(speed, speed_max[mode]);
189#else /* !CONFIG_BLK_DEV_IDEDMA */ 107#else /* !CONFIG_BLK_DEV_IDEDMA */
190 return min(speed, (u8)XFER_PIO_4); 108 return min(speed, (u8)XFER_PIO_4);
191#endif /* CONFIG_BLK_DEV_IDEDMA */ 109#endif /* CONFIG_BLK_DEV_IDEDMA */
@@ -193,18 +111,6 @@ u8 ide_rate_filter (u8 mode, u8 speed)
193 111
194EXPORT_SYMBOL(ide_rate_filter); 112EXPORT_SYMBOL(ide_rate_filter);
195 113
196int ide_dma_enable (ide_drive_t *drive)
197{
198 ide_hwif_t *hwif = HWIF(drive);
199 struct hd_driveid *id = drive->id;
200
201 return ((int) ((((id->dma_ultra >> 8) & hwif->ultra_mask) ||
202 ((id->dma_mword >> 8) & hwif->mwdma_mask) ||
203 ((id->dma_1word >> 8) & hwif->swdma_mask)) ? 1 : 0));
204}
205
206EXPORT_SYMBOL(ide_dma_enable);
207
208int ide_use_fast_pio(ide_drive_t *drive) 114int ide_use_fast_pio(ide_drive_t *drive)
209{ 115{
210 struct hd_driveid *id = drive->id; 116 struct hd_driveid *id = drive->id;
diff --git a/drivers/ide/ide-pnp.c b/drivers/ide/ide-pnp.c
index 98410ca044cf..2b8009c50e91 100644
--- a/drivers/ide/ide-pnp.c
+++ b/drivers/ide/ide-pnp.c
@@ -42,7 +42,7 @@ static int idepnp_probe(struct pnp_dev * dev, const struct pnp_device_id *dev_id
42 hw.irq = pnp_irq(dev, 0); 42 hw.irq = pnp_irq(dev, 0);
43 hw.dma = NO_DMA; 43 hw.dma = NO_DMA;
44 44
45 index = ide_register_hw(&hw, &hwif); 45 index = ide_register_hw(&hw, 1, &hwif);
46 46
47 if (index != -1) { 47 if (index != -1) {
48 printk(KERN_INFO "ide%d: generic PnP IDE interface\n", index); 48 printk(KERN_INFO "ide%d: generic PnP IDE interface\n", index);
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 8f15c23aa70d..3cebed77f55d 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -1427,6 +1427,9 @@ int ideprobe_init (void)
1427 } 1427 }
1428 } 1428 }
1429 } 1429 }
1430 for (index = 0; index < MAX_HWIFS; ++index)
1431 if (probe[index])
1432 ide_proc_register_port(&ide_hwifs[index]);
1430 return 0; 1433 return 0;
1431} 1434}
1432 1435
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index a9e0b30fb1f2..d50bd996ff22 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright (C) 1997-1998 Mark Lord 4 * Copyright (C) 1997-1998 Mark Lord
5 * Copyright (C) 2003 Red Hat <alan@redhat.com> 5 * Copyright (C) 2003 Red Hat <alan@redhat.com>
6 *
7 * Some code was moved here from ide.c, see it for original copyrights.
6 */ 8 */
7 9
8/* 10/*
@@ -37,6 +39,8 @@
37 39
38#include <asm/io.h> 40#include <asm/io.h>
39 41
42static struct proc_dir_entry *proc_ide_root;
43
40static int proc_ide_read_imodel 44static int proc_ide_read_imodel
41 (char *page, char **start, off_t off, int count, int *eof, void *data) 45 (char *page, char **start, off_t off, int count, int *eof, void *data)
42{ 46{
@@ -121,6 +125,265 @@ static int proc_ide_read_identify
121 PROC_IDE_READ_RETURN(page,start,off,count,eof,len); 125 PROC_IDE_READ_RETURN(page,start,off,count,eof,len);
122} 126}
123 127
128/**
129 * __ide_add_setting - add an ide setting option
130 * @drive: drive to use
131 * @name: setting name
132 * @rw: true if the function is read write
133 * @data_type: type of data
134 * @min: range minimum
135 * @max: range maximum
136 * @mul_factor: multiplication scale
137 * @div_factor: divison scale
138 * @data: private data field
139 * @set: setting
140 * @auto_remove: setting auto removal flag
141 *
142 * Removes the setting named from the device if it is present.
143 * The function takes the settings_lock to protect against
144 * parallel changes. This function must not be called from IRQ
145 * context. Returns 0 on success or -1 on failure.
146 *
147 * BUGS: This code is seriously over-engineered. There is also
148 * magic about how the driver specific features are setup. If
149 * a driver is attached we assume the driver settings are auto
150 * remove.
151 */
152
153static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set, int auto_remove)
154{
155 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
156
157 down(&ide_setting_sem);
158 while ((*p) && strcmp((*p)->name, name) < 0)
159 p = &((*p)->next);
160 if ((setting = kzalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
161 goto abort;
162 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
163 goto abort;
164 strcpy(setting->name, name);
165 setting->rw = rw;
166 setting->data_type = data_type;
167 setting->min = min;
168 setting->max = max;
169 setting->mul_factor = mul_factor;
170 setting->div_factor = div_factor;
171 setting->data = data;
172 setting->set = set;
173
174 setting->next = *p;
175 if (auto_remove)
176 setting->auto_remove = 1;
177 *p = setting;
178 up(&ide_setting_sem);
179 return 0;
180abort:
181 up(&ide_setting_sem);
182 kfree(setting);
183 return -1;
184}
185
186int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set)
187{
188 return __ide_add_setting(drive, name, rw, data_type, min, max, mul_factor, div_factor, data, set, 1);
189}
190
191EXPORT_SYMBOL(ide_add_setting);
192
193/**
194 * __ide_remove_setting - remove an ide setting option
195 * @drive: drive to use
196 * @name: setting name
197 *
198 * Removes the setting named from the device if it is present.
199 * The caller must hold the setting semaphore.
200 */
201
202static void __ide_remove_setting (ide_drive_t *drive, char *name)
203{
204 ide_settings_t **p, *setting;
205
206 p = (ide_settings_t **) &drive->settings;
207
208 while ((*p) && strcmp((*p)->name, name))
209 p = &((*p)->next);
210 if ((setting = (*p)) == NULL)
211 return;
212
213 (*p) = setting->next;
214
215 kfree(setting->name);
216 kfree(setting);
217}
218
219/**
220 * auto_remove_settings - remove driver specific settings
221 * @drive: drive
222 *
223 * Automatically remove all the driver specific settings for this
224 * drive. This function may not be called from IRQ context. The
225 * caller must hold ide_setting_sem.
226 */
227
228static void auto_remove_settings (ide_drive_t *drive)
229{
230 ide_settings_t *setting;
231repeat:
232 setting = drive->settings;
233 while (setting) {
234 if (setting->auto_remove) {
235 __ide_remove_setting(drive, setting->name);
236 goto repeat;
237 }
238 setting = setting->next;
239 }
240}
241
242/**
243 * ide_find_setting_by_name - find a drive specific setting
244 * @drive: drive to scan
245 * @name: setting name
246 *
247 * Scan's the device setting table for a matching entry and returns
248 * this or NULL if no entry is found. The caller must hold the
249 * setting semaphore
250 */
251
252static ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name)
253{
254 ide_settings_t *setting = drive->settings;
255
256 while (setting) {
257 if (strcmp(setting->name, name) == 0)
258 break;
259 setting = setting->next;
260 }
261 return setting;
262}
263
264/**
265 * ide_read_setting - read an IDE setting
266 * @drive: drive to read from
267 * @setting: drive setting
268 *
269 * Read a drive setting and return the value. The caller
270 * must hold the ide_setting_sem when making this call.
271 *
272 * BUGS: the data return and error are the same return value
273 * so an error -EINVAL and true return of the same value cannot
274 * be told apart
275 */
276
277static int ide_read_setting(ide_drive_t *drive, ide_settings_t *setting)
278{
279 int val = -EINVAL;
280 unsigned long flags;
281
282 if ((setting->rw & SETTING_READ)) {
283 spin_lock_irqsave(&ide_lock, flags);
284 switch(setting->data_type) {
285 case TYPE_BYTE:
286 val = *((u8 *) setting->data);
287 break;
288 case TYPE_SHORT:
289 val = *((u16 *) setting->data);
290 break;
291 case TYPE_INT:
292 val = *((u32 *) setting->data);
293 break;
294 }
295 spin_unlock_irqrestore(&ide_lock, flags);
296 }
297 return val;
298}
299
300/**
301 * ide_write_setting - read an IDE setting
302 * @drive: drive to read from
303 * @setting: drive setting
304 * @val: value
305 *
306 * Write a drive setting if it is possible. The caller
307 * must hold the ide_setting_sem when making this call.
308 *
309 * BUGS: the data return and error are the same return value
310 * so an error -EINVAL and true return of the same value cannot
311 * be told apart
312 *
313 * FIXME: This should be changed to enqueue a special request
314 * to the driver to change settings, and then wait on a sema for completion.
315 * The current scheme of polling is kludgy, though safe enough.
316 */
317
318static int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val)
319{
320 if (!capable(CAP_SYS_ADMIN))
321 return -EACCES;
322 if (setting->set)
323 return setting->set(drive, val);
324 if (!(setting->rw & SETTING_WRITE))
325 return -EPERM;
326 if (val < setting->min || val > setting->max)
327 return -EINVAL;
328 if (ide_spin_wait_hwgroup(drive))
329 return -EBUSY;
330 switch (setting->data_type) {
331 case TYPE_BYTE:
332 *((u8 *) setting->data) = val;
333 break;
334 case TYPE_SHORT:
335 *((u16 *) setting->data) = val;
336 break;
337 case TYPE_INT:
338 *((u32 *) setting->data) = val;
339 break;
340 }
341 spin_unlock_irq(&ide_lock);
342 return 0;
343}
344
345static int set_xfer_rate (ide_drive_t *drive, int arg)
346{
347 int err;
348
349 if (arg < 0 || arg > 70)
350 return -EINVAL;
351
352 err = ide_wait_cmd(drive,
353 WIN_SETFEATURES, (u8) arg,
354 SETFEATURES_XFER, 0, NULL);
355
356 if (!err && arg) {
357 ide_set_xfer_rate(drive, (u8) arg);
358 ide_driveid_update(drive);
359 }
360 return err;
361}
362
363/**
364 * ide_add_generic_settings - generic ide settings
365 * @drive: drive being configured
366 *
367 * Add the generic parts of the system settings to the /proc files.
368 * The caller must not be holding the ide_setting_sem.
369 */
370
371void ide_add_generic_settings (ide_drive_t *drive)
372{
373/*
374 * drive setting name read/write access data type min max mul_factor div_factor data pointer set function
375 */
376 __ide_add_setting(drive, "io_32bit", drive->no_io_32bit ? SETTING_READ : SETTING_RW, TYPE_BYTE, 0, 1 + (SUPPORT_VLB_SYNC << 1), 1, 1, &drive->io_32bit, set_io_32bit, 0);
377 __ide_add_setting(drive, "keepsettings", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL, 0);
378 __ide_add_setting(drive, "nice1", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL, 0);
379 __ide_add_setting(drive, "pio_mode", SETTING_WRITE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode, 0);
380 __ide_add_setting(drive, "unmaskirq", drive->no_unmask ? SETTING_READ : SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->unmask, NULL, 0);
381 __ide_add_setting(drive, "using_dma", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->using_dma, set_using_dma, 0);
382 __ide_add_setting(drive, "init_speed", SETTING_RW, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL, 0);
383 __ide_add_setting(drive, "current_speed", SETTING_RW, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate, 0);
384 __ide_add_setting(drive, "number", SETTING_RW, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL, 0);
385}
386
124static void proc_ide_settings_warn(void) 387static void proc_ide_settings_warn(void)
125{ 388{
126 static int warned = 0; 389 static int warned = 0;
@@ -399,7 +662,7 @@ static ide_proc_entry_t generic_drive_entries[] = {
399 { NULL, 0, NULL, NULL } 662 { NULL, 0, NULL, NULL }
400}; 663};
401 664
402void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data) 665static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
403{ 666{
404 struct proc_dir_entry *ent; 667 struct proc_dir_entry *ent;
405 668
@@ -415,7 +678,7 @@ void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void
415 } 678 }
416} 679}
417 680
418void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p) 681static void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
419{ 682{
420 if (!dir || !p) 683 if (!dir || !p)
421 return; 684 return;
@@ -425,6 +688,51 @@ void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p)
425 } 688 }
426} 689}
427 690
691void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver)
692{
693 ide_add_proc_entries(drive->proc, driver->proc, drive);
694}
695
696EXPORT_SYMBOL(ide_proc_register_driver);
697
698/**
699 * ide_proc_unregister_driver - remove driver specific data
700 * @drive: drive
701 * @driver: driver
702 *
703 * Clean up the driver specific /proc files and IDE settings
704 * for a given drive.
705 *
706 * Takes ide_setting_sem and ide_lock.
707 * Caller must hold none of the locks.
708 */
709
710void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver)
711{
712 unsigned long flags;
713
714 ide_remove_proc_entries(drive->proc, driver->proc);
715
716 down(&ide_setting_sem);
717 spin_lock_irqsave(&ide_lock, flags);
718 /*
719 * ide_setting_sem protects the settings list
720 * ide_lock protects the use of settings
721 *
722 * so we need to hold both, ide_settings_sem because we want to
723 * modify the settings list, and ide_lock because we cannot take
724 * a setting out that is being used.
725 *
726 * OTOH both ide_{read,write}_setting are only ever used under
727 * ide_setting_sem.
728 */
729 auto_remove_settings(drive);
730 spin_unlock_irqrestore(&ide_lock, flags);
731 up(&ide_setting_sem);
732}
733
734EXPORT_SYMBOL(ide_proc_unregister_driver);
735
428static void create_proc_ide_drives(ide_hwif_t *hwif) 736static void create_proc_ide_drives(ide_hwif_t *hwif)
429{ 737{
430 int d; 738 int d;
@@ -477,26 +785,24 @@ static ide_proc_entry_t hwif_entries[] = {
477 { NULL, 0, NULL, NULL } 785 { NULL, 0, NULL, NULL }
478}; 786};
479 787
480void create_proc_ide_interfaces(void) 788void ide_proc_register_port(ide_hwif_t *hwif)
481{ 789{
482 int h; 790 if (!hwif->present)
791 return;
483 792
484 for (h = 0; h < MAX_HWIFS; h++) { 793 if (!hwif->proc) {
485 ide_hwif_t *hwif = &ide_hwifs[h]; 794 hwif->proc = proc_mkdir(hwif->name, proc_ide_root);
486 795
487 if (!hwif->present) 796 if (!hwif->proc)
488 continue; 797 return;
489 if (!hwif->proc) { 798
490 hwif->proc = proc_mkdir(hwif->name, proc_ide_root); 799 ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
491 if (!hwif->proc)
492 return;
493 ide_add_proc_entries(hwif->proc, hwif_entries, hwif);
494 }
495 create_proc_ide_drives(hwif);
496 } 800 }
801
802 create_proc_ide_drives(hwif);
497} 803}
498 804
499EXPORT_SYMBOL(create_proc_ide_interfaces); 805EXPORT_SYMBOL_GPL(ide_proc_register_port);
500 806
501#ifdef CONFIG_BLK_DEV_IDEPCI 807#ifdef CONFIG_BLK_DEV_IDEPCI
502void ide_pci_create_host_proc(const char *name, get_info_t *get_info) 808void ide_pci_create_host_proc(const char *name, get_info_t *get_info)
@@ -507,7 +813,7 @@ void ide_pci_create_host_proc(const char *name, get_info_t *get_info)
507EXPORT_SYMBOL_GPL(ide_pci_create_host_proc); 813EXPORT_SYMBOL_GPL(ide_pci_create_host_proc);
508#endif 814#endif
509 815
510void destroy_proc_ide_interface(ide_hwif_t *hwif) 816void ide_proc_unregister_port(ide_hwif_t *hwif)
511{ 817{
512 if (hwif->proc) { 818 if (hwif->proc) {
513 destroy_proc_ide_drives(hwif); 819 destroy_proc_ide_drives(hwif);
@@ -554,11 +860,11 @@ void proc_ide_create(void)
554{ 860{
555 struct proc_dir_entry *entry; 861 struct proc_dir_entry *entry;
556 862
863 proc_ide_root = proc_mkdir("ide", NULL);
864
557 if (!proc_ide_root) 865 if (!proc_ide_root)
558 return; 866 return;
559 867
560 create_proc_ide_interfaces();
561
562 entry = create_proc_entry("drivers", 0, proc_ide_root); 868 entry = create_proc_entry("drivers", 0, proc_ide_root);
563 if (entry) 869 if (entry)
564 entry->proc_fops = &ide_drivers_operations; 870 entry->proc_fops = &ide_drivers_operations;
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 4e59239fef75..e82bfa5e0ab8 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -4561,28 +4561,33 @@ static void idetape_get_blocksize_from_block_descriptor(ide_drive_t *drive)
4561 printk(KERN_INFO "ide-tape: Adjusted block size - %d\n", tape->tape_block_size); 4561 printk(KERN_INFO "ide-tape: Adjusted block size - %d\n", tape->tape_block_size);
4562#endif /* IDETAPE_DEBUG_INFO */ 4562#endif /* IDETAPE_DEBUG_INFO */
4563} 4563}
4564
4565#ifdef CONFIG_IDE_PROC_FS
4564static void idetape_add_settings (ide_drive_t *drive) 4566static void idetape_add_settings (ide_drive_t *drive)
4565{ 4567{
4566 idetape_tape_t *tape = drive->driver_data; 4568 idetape_tape_t *tape = drive->driver_data;
4567 4569
4568/* 4570/*
4569 * drive setting name read/write ioctl ioctl data type min max mul_factor div_factor data pointer set function 4571 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
4570 */ 4572 */
4571 ide_add_setting(drive, "buffer", SETTING_READ, -1, -1, TYPE_SHORT, 0, 0xffff, 1, 2, &tape->capabilities.buffer_size, NULL); 4573 ide_add_setting(drive, "buffer", SETTING_READ, TYPE_SHORT, 0, 0xffff, 1, 2, &tape->capabilities.buffer_size, NULL);
4572 ide_add_setting(drive, "pipeline_min", SETTING_RW, -1, -1, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->min_pipeline, NULL); 4574 ide_add_setting(drive, "pipeline_min", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->min_pipeline, NULL);
4573 ide_add_setting(drive, "pipeline", SETTING_RW, -1, -1, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_stages, NULL); 4575 ide_add_setting(drive, "pipeline", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_stages, NULL);
4574 ide_add_setting(drive, "pipeline_max", SETTING_RW, -1, -1, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_pipeline, NULL); 4576 ide_add_setting(drive, "pipeline_max", SETTING_RW, TYPE_INT, 1, 0xffff, tape->stage_size / 1024, 1, &tape->max_pipeline, NULL);
4575 ide_add_setting(drive, "pipeline_used",SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages, NULL); 4577 ide_add_setting(drive, "pipeline_used", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_stages, NULL);
4576 ide_add_setting(drive, "pipeline_pending",SETTING_READ,-1, -1, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_pending_stages, NULL); 4578 ide_add_setting(drive, "pipeline_pending", SETTING_READ, TYPE_INT, 0, 0xffff, tape->stage_size / 1024, 1, &tape->nr_pending_stages, NULL);
4577 ide_add_setting(drive, "speed", SETTING_READ, -1, -1, TYPE_SHORT, 0, 0xffff, 1, 1, &tape->capabilities.speed, NULL); 4579 ide_add_setting(drive, "speed", SETTING_READ, TYPE_SHORT, 0, 0xffff, 1, 1, &tape->capabilities.speed, NULL);
4578 ide_add_setting(drive, "stage", SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, 1, 1024, &tape->stage_size, NULL); 4580 ide_add_setting(drive, "stage", SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1024, &tape->stage_size, NULL);
4579 ide_add_setting(drive, "tdsc", SETTING_RW, -1, -1, TYPE_INT, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_frequency, NULL); 4581 ide_add_setting(drive, "tdsc", SETTING_RW, TYPE_INT, IDETAPE_DSC_RW_MIN, IDETAPE_DSC_RW_MAX, 1000, HZ, &tape->best_dsc_rw_frequency, NULL);
4580 ide_add_setting(drive, "dsc_overlap", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL); 4582 ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, &drive->dsc_overlap, NULL);
4581 ide_add_setting(drive, "pipeline_head_speed_c",SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, 1, 1, &tape->controlled_pipeline_head_speed, NULL); 4583 ide_add_setting(drive, "pipeline_head_speed_c",SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1, &tape->controlled_pipeline_head_speed, NULL);
4582 ide_add_setting(drive, "pipeline_head_speed_u",SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, 1, 1, &tape->uncontrolled_pipeline_head_speed, NULL); 4584 ide_add_setting(drive, "pipeline_head_speed_u",SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1, &tape->uncontrolled_pipeline_head_speed,NULL);
4583 ide_add_setting(drive, "avg_speed", SETTING_READ, -1, -1, TYPE_INT, 0, 0xffff, 1, 1, &tape->avg_speed, NULL); 4585 ide_add_setting(drive, "avg_speed", SETTING_READ, TYPE_INT, 0, 0xffff, 1, 1, &tape->avg_speed, NULL);
4584 ide_add_setting(drive, "debug_level",SETTING_RW, -1, -1, TYPE_INT, 0, 0xffff, 1, 1, &tape->debug_level, NULL); 4586 ide_add_setting(drive, "debug_level", SETTING_RW, TYPE_INT, 0, 0xffff, 1, 1, &tape->debug_level, NULL);
4585} 4587}
4588#else
4589static inline void idetape_add_settings(ide_drive_t *drive) { ; }
4590#endif
4586 4591
4587/* 4592/*
4588 * ide_setup is called to: 4593 * ide_setup is called to:
@@ -4703,7 +4708,7 @@ static void ide_tape_remove(ide_drive_t *drive)
4703{ 4708{
4704 idetape_tape_t *tape = drive->driver_data; 4709 idetape_tape_t *tape = drive->driver_data;
4705 4710
4706 ide_unregister_subdriver(drive, tape->driver); 4711 ide_proc_unregister_driver(drive, tape->driver);
4707 4712
4708 ide_unregister_region(tape->disk); 4713 ide_unregister_region(tape->disk);
4709 4714
@@ -4730,8 +4735,7 @@ static void ide_tape_release(struct kref *kref)
4730 kfree(tape); 4735 kfree(tape);
4731} 4736}
4732 4737
4733#ifdef CONFIG_PROC_FS 4738#ifdef CONFIG_IDE_PROC_FS
4734
4735static int proc_idetape_read_name 4739static int proc_idetape_read_name
4736 (char *page, char **start, off_t off, int count, int *eof, void *data) 4740 (char *page, char **start, off_t off, int count, int *eof, void *data)
4737{ 4741{
@@ -4749,11 +4753,6 @@ static ide_proc_entry_t idetape_proc[] = {
4749 { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL }, 4753 { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL },
4750 { NULL, 0, NULL, NULL } 4754 { NULL, 0, NULL, NULL }
4751}; 4755};
4752
4753#else
4754
4755#define idetape_proc NULL
4756
4757#endif 4756#endif
4758 4757
4759static int ide_tape_probe(ide_drive_t *); 4758static int ide_tape_probe(ide_drive_t *);
@@ -4773,7 +4772,9 @@ static ide_driver_t idetape_driver = {
4773 .end_request = idetape_end_request, 4772 .end_request = idetape_end_request,
4774 .error = __ide_error, 4773 .error = __ide_error,
4775 .abort = __ide_abort, 4774 .abort = __ide_abort,
4775#ifdef CONFIG_IDE_PROC_FS
4776 .proc = idetape_proc, 4776 .proc = idetape_proc,
4777#endif
4777}; 4778};
4778 4779
4779/* 4780/*
@@ -4864,7 +4865,7 @@ static int ide_tape_probe(ide_drive_t *drive)
4864 4865
4865 ide_init_disk(g, drive); 4866 ide_init_disk(g, drive);
4866 4867
4867 ide_register_subdriver(drive, &idetape_driver); 4868 ide_proc_register_driver(drive, &idetape_driver);
4868 4869
4869 kref_init(&tape->kref); 4870 kref_init(&tape->kref);
4870 4871
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index ae5bf2be6f52..6002713a20a1 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -168,12 +168,11 @@ static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
168 168
169static int idebus_parameter; /* holds the "idebus=" parameter */ 169static int idebus_parameter; /* holds the "idebus=" parameter */
170static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */ 170static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
171static int initializing; /* set while initializing built-in drivers */
172 171
173DECLARE_MUTEX(ide_cfg_sem); 172DECLARE_MUTEX(ide_cfg_sem);
174 __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock); 173 __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
175 174
176#ifdef CONFIG_BLK_DEV_IDEPCI 175#ifdef CONFIG_IDEPCI_PCIBUS_ORDER
177static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */ 176static int ide_scan_direction; /* THIS was formerly 2.2.x pci=reverse */
178#endif 177#endif
179 178
@@ -216,9 +215,6 @@ static void init_hwif_data(ide_hwif_t *hwif, unsigned int index)
216 hwif->bus_state = BUSSTATE_ON; 215 hwif->bus_state = BUSSTATE_ON;
217 216
218 hwif->atapi_dma = 0; /* disable all atapi dma */ 217 hwif->atapi_dma = 0; /* disable all atapi dma */
219 hwif->ultra_mask = 0x80; /* disable all ultra */
220 hwif->mwdma_mask = 0x80; /* disable all mwdma */
221 hwif->swdma_mask = 0x80; /* disable all swdma */
222 218
223 init_completion(&hwif->gendev_rel_comp); 219 init_completion(&hwif->gendev_rel_comp);
224 220
@@ -305,9 +301,7 @@ static void __init init_ide_data (void)
305#endif 301#endif
306 } 302 }
307#ifdef CONFIG_IDE_ARM 303#ifdef CONFIG_IDE_ARM
308 initializing = 1;
309 ide_arm_init(); 304 ide_arm_init();
310 initializing = 0;
311#endif 305#endif
312} 306}
313 307
@@ -353,10 +347,6 @@ static int ide_system_bus_speed(void)
353 return system_bus_speed; 347 return system_bus_speed;
354} 348}
355 349
356#ifdef CONFIG_PROC_FS
357struct proc_dir_entry *proc_ide_root;
358#endif
359
360static struct resource* hwif_request_region(ide_hwif_t *hwif, 350static struct resource* hwif_request_region(ide_hwif_t *hwif,
361 unsigned long addr, int num) 351 unsigned long addr, int num)
362{ 352{
@@ -480,6 +470,7 @@ static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
480 470
481 hwif->tuneproc = tmp_hwif->tuneproc; 471 hwif->tuneproc = tmp_hwif->tuneproc;
482 hwif->speedproc = tmp_hwif->speedproc; 472 hwif->speedproc = tmp_hwif->speedproc;
473 hwif->udma_filter = tmp_hwif->udma_filter;
483 hwif->selectproc = tmp_hwif->selectproc; 474 hwif->selectproc = tmp_hwif->selectproc;
484 hwif->reset_poll = tmp_hwif->reset_poll; 475 hwif->reset_poll = tmp_hwif->reset_poll;
485 hwif->pre_reset = tmp_hwif->pre_reset; 476 hwif->pre_reset = tmp_hwif->pre_reset;
@@ -599,7 +590,7 @@ void ide_unregister(unsigned int index)
599 590
600 spin_unlock_irq(&ide_lock); 591 spin_unlock_irq(&ide_lock);
601 592
602 destroy_proc_ide_interface(hwif); 593 ide_proc_unregister_port(hwif);
603 594
604 hwgroup = hwif->hwgroup; 595 hwgroup = hwif->hwgroup;
605 /* 596 /*
@@ -751,6 +742,7 @@ void ide_setup_ports ( hw_regs_t *hw,
751/** 742/**
752 * ide_register_hw_with_fixup - register IDE interface 743 * ide_register_hw_with_fixup - register IDE interface
753 * @hw: hardware registers 744 * @hw: hardware registers
745 * @initializing: set while initializing built-in drivers
754 * @hwifp: pointer to returned hwif 746 * @hwifp: pointer to returned hwif
755 * @fixup: fixup function 747 * @fixup: fixup function
756 * 748 *
@@ -760,7 +752,9 @@ void ide_setup_ports ( hw_regs_t *hw,
760 * Returns -1 on error. 752 * Returns -1 on error.
761 */ 753 */
762 754
763int ide_register_hw_with_fixup(hw_regs_t *hw, ide_hwif_t **hwifp, void(*fixup)(ide_hwif_t *hwif)) 755int ide_register_hw_with_fixup(hw_regs_t *hw, int initializing,
756 ide_hwif_t **hwifp,
757 void(*fixup)(ide_hwif_t *hwif))
764{ 758{
765 int index, retry = 1; 759 int index, retry = 1;
766 ide_hwif_t *hwif; 760 ide_hwif_t *hwif;
@@ -801,7 +795,7 @@ found:
801 795
802 if (!initializing) { 796 if (!initializing) {
803 probe_hwif_init_with_fixup(hwif, fixup); 797 probe_hwif_init_with_fixup(hwif, fixup);
804 create_proc_ide_interfaces(); 798 ide_proc_register_port(hwif);
805 } 799 }
806 800
807 if (hwifp) 801 if (hwifp)
@@ -812,9 +806,9 @@ found:
812 806
813EXPORT_SYMBOL(ide_register_hw_with_fixup); 807EXPORT_SYMBOL(ide_register_hw_with_fixup);
814 808
815int ide_register_hw(hw_regs_t *hw, ide_hwif_t **hwifp) 809int ide_register_hw(hw_regs_t *hw, int initializing, ide_hwif_t **hwifp)
816{ 810{
817 return ide_register_hw_with_fixup(hw, hwifp, NULL); 811 return ide_register_hw_with_fixup(hw, initializing, hwifp, NULL);
818} 812}
819 813
820EXPORT_SYMBOL(ide_register_hw); 814EXPORT_SYMBOL(ide_register_hw);
@@ -825,205 +819,7 @@ EXPORT_SYMBOL(ide_register_hw);
825 819
826DECLARE_MUTEX(ide_setting_sem); 820DECLARE_MUTEX(ide_setting_sem);
827 821
828/** 822EXPORT_SYMBOL_GPL(ide_setting_sem);
829 * __ide_add_setting - add an ide setting option
830 * @drive: drive to use
831 * @name: setting name
832 * @rw: true if the function is read write
833 * @read_ioctl: function to call on read
834 * @write_ioctl: function to call on write
835 * @data_type: type of data
836 * @min: range minimum
837 * @max: range maximum
838 * @mul_factor: multiplication scale
839 * @div_factor: divison scale
840 * @data: private data field
841 * @set: setting
842 * @auto_remove: setting auto removal flag
843 *
844 * Removes the setting named from the device if it is present.
845 * The function takes the settings_lock to protect against
846 * parallel changes. This function must not be called from IRQ
847 * context. Returns 0 on success or -1 on failure.
848 *
849 * BUGS: This code is seriously over-engineered. There is also
850 * magic about how the driver specific features are setup. If
851 * a driver is attached we assume the driver settings are auto
852 * remove.
853 */
854
855static int __ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set, int auto_remove)
856{
857 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
858
859 down(&ide_setting_sem);
860 while ((*p) && strcmp((*p)->name, name) < 0)
861 p = &((*p)->next);
862 if ((setting = kzalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
863 goto abort;
864 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
865 goto abort;
866 strcpy(setting->name, name);
867 setting->rw = rw;
868 setting->read_ioctl = read_ioctl;
869 setting->write_ioctl = write_ioctl;
870 setting->data_type = data_type;
871 setting->min = min;
872 setting->max = max;
873 setting->mul_factor = mul_factor;
874 setting->div_factor = div_factor;
875 setting->data = data;
876 setting->set = set;
877
878 setting->next = *p;
879 if (auto_remove)
880 setting->auto_remove = 1;
881 *p = setting;
882 up(&ide_setting_sem);
883 return 0;
884abort:
885 up(&ide_setting_sem);
886 kfree(setting);
887 return -1;
888}
889
890int ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set)
891{
892 return __ide_add_setting(drive, name, rw, read_ioctl, write_ioctl, data_type, min, max, mul_factor, div_factor, data, set, 1);
893}
894
895EXPORT_SYMBOL(ide_add_setting);
896
897/**
898 * __ide_remove_setting - remove an ide setting option
899 * @drive: drive to use
900 * @name: setting name
901 *
902 * Removes the setting named from the device if it is present.
903 * The caller must hold the setting semaphore.
904 */
905
906static void __ide_remove_setting (ide_drive_t *drive, char *name)
907{
908 ide_settings_t **p, *setting;
909
910 p = (ide_settings_t **) &drive->settings;
911
912 while ((*p) && strcmp((*p)->name, name))
913 p = &((*p)->next);
914 if ((setting = (*p)) == NULL)
915 return;
916
917 (*p) = setting->next;
918
919 kfree(setting->name);
920 kfree(setting);
921}
922
923/**
924 * ide_find_setting_by_ioctl - find a drive specific ioctl
925 * @drive: drive to scan
926 * @cmd: ioctl command to handle
927 *
928 * Scan's the device setting table for a matching entry and returns
929 * this or NULL if no entry is found. The caller must hold the
930 * setting semaphore
931 */
932
933static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd)
934{
935 ide_settings_t *setting = drive->settings;
936
937 while (setting) {
938 if (setting->read_ioctl == cmd || setting->write_ioctl == cmd)
939 break;
940 setting = setting->next;
941 }
942
943 return setting;
944}
945
946/**
947 * ide_find_setting_by_name - find a drive specific setting
948 * @drive: drive to scan
949 * @name: setting name
950 *
951 * Scan's the device setting table for a matching entry and returns
952 * this or NULL if no entry is found. The caller must hold the
953 * setting semaphore
954 */
955
956ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name)
957{
958 ide_settings_t *setting = drive->settings;
959
960 while (setting) {
961 if (strcmp(setting->name, name) == 0)
962 break;
963 setting = setting->next;
964 }
965 return setting;
966}
967
968/**
969 * auto_remove_settings - remove driver specific settings
970 * @drive: drive
971 *
972 * Automatically remove all the driver specific settings for this
973 * drive. This function may not be called from IRQ context. The
974 * caller must hold ide_setting_sem.
975 */
976
977static void auto_remove_settings (ide_drive_t *drive)
978{
979 ide_settings_t *setting;
980repeat:
981 setting = drive->settings;
982 while (setting) {
983 if (setting->auto_remove) {
984 __ide_remove_setting(drive, setting->name);
985 goto repeat;
986 }
987 setting = setting->next;
988 }
989}
990
991/**
992 * ide_read_setting - read an IDE setting
993 * @drive: drive to read from
994 * @setting: drive setting
995 *
996 * Read a drive setting and return the value. The caller
997 * must hold the ide_setting_sem when making this call.
998 *
999 * BUGS: the data return and error are the same return value
1000 * so an error -EINVAL and true return of the same value cannot
1001 * be told apart
1002 */
1003
1004int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting)
1005{
1006 int val = -EINVAL;
1007 unsigned long flags;
1008
1009 if ((setting->rw & SETTING_READ)) {
1010 spin_lock_irqsave(&ide_lock, flags);
1011 switch(setting->data_type) {
1012 case TYPE_BYTE:
1013 val = *((u8 *) setting->data);
1014 break;
1015 case TYPE_SHORT:
1016 val = *((u16 *) setting->data);
1017 break;
1018 case TYPE_INT:
1019 case TYPE_INTA:
1020 val = *((u32 *) setting->data);
1021 break;
1022 }
1023 spin_unlock_irqrestore(&ide_lock, flags);
1024 }
1025 return val;
1026}
1027 823
1028/** 824/**
1029 * ide_spin_wait_hwgroup - wait for group 825 * ide_spin_wait_hwgroup - wait for group
@@ -1058,61 +854,14 @@ int ide_spin_wait_hwgroup (ide_drive_t *drive)
1058 854
1059EXPORT_SYMBOL(ide_spin_wait_hwgroup); 855EXPORT_SYMBOL(ide_spin_wait_hwgroup);
1060 856
1061/** 857int set_io_32bit(ide_drive_t *drive, int arg)
1062 * ide_write_setting - read an IDE setting
1063 * @drive: drive to read from
1064 * @setting: drive setting
1065 * @val: value
1066 *
1067 * Write a drive setting if it is possible. The caller
1068 * must hold the ide_setting_sem when making this call.
1069 *
1070 * BUGS: the data return and error are the same return value
1071 * so an error -EINVAL and true return of the same value cannot
1072 * be told apart
1073 *
1074 * FIXME: This should be changed to enqueue a special request
1075 * to the driver to change settings, and then wait on a sema for completion.
1076 * The current scheme of polling is kludgy, though safe enough.
1077 */
1078
1079int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val)
1080{ 858{
1081 int i; 859 if (drive->no_io_32bit)
1082 u32 *p;
1083
1084 if (!capable(CAP_SYS_ADMIN))
1085 return -EACCES;
1086 if (!(setting->rw & SETTING_WRITE))
1087 return -EPERM; 860 return -EPERM;
1088 if (val < setting->min || val > setting->max) 861
862 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
1089 return -EINVAL; 863 return -EINVAL;
1090 if (setting->set)
1091 return setting->set(drive, val);
1092 if (ide_spin_wait_hwgroup(drive))
1093 return -EBUSY;
1094 switch (setting->data_type) {
1095 case TYPE_BYTE:
1096 *((u8 *) setting->data) = val;
1097 break;
1098 case TYPE_SHORT:
1099 *((u16 *) setting->data) = val;
1100 break;
1101 case TYPE_INT:
1102 *((u32 *) setting->data) = val;
1103 break;
1104 case TYPE_INTA:
1105 p = (u32 *) setting->data;
1106 for (i = 0; i < 1 << PARTN_BITS; i++, p++)
1107 *p = val;
1108 break;
1109 }
1110 spin_unlock_irq(&ide_lock);
1111 return 0;
1112}
1113 864
1114static int set_io_32bit(ide_drive_t *drive, int arg)
1115{
1116 drive->io_32bit = arg; 865 drive->io_32bit = arg;
1117#ifdef CONFIG_BLK_DEV_DTC2278 866#ifdef CONFIG_BLK_DEV_DTC2278
1118 if (HWIF(drive)->chipset == ide_dtc2278) 867 if (HWIF(drive)->chipset == ide_dtc2278)
@@ -1121,12 +870,28 @@ static int set_io_32bit(ide_drive_t *drive, int arg)
1121 return 0; 870 return 0;
1122} 871}
1123 872
1124static int set_using_dma (ide_drive_t *drive, int arg) 873static int set_ksettings(ide_drive_t *drive, int arg)
874{
875 if (arg < 0 || arg > 1)
876 return -EINVAL;
877
878 if (ide_spin_wait_hwgroup(drive))
879 return -EBUSY;
880 drive->keep_settings = arg;
881 spin_unlock_irq(&ide_lock);
882
883 return 0;
884}
885
886int set_using_dma(ide_drive_t *drive, int arg)
1125{ 887{
1126#ifdef CONFIG_BLK_DEV_IDEDMA 888#ifdef CONFIG_BLK_DEV_IDEDMA
1127 ide_hwif_t *hwif = drive->hwif; 889 ide_hwif_t *hwif = drive->hwif;
1128 int err = -EPERM; 890 int err = -EPERM;
1129 891
892 if (arg < 0 || arg > 1)
893 return -EINVAL;
894
1130 if (!drive->id || !(drive->id->capability & 1)) 895 if (!drive->id || !(drive->id->capability & 1))
1131 goto out; 896 goto out;
1132 897
@@ -1145,6 +910,7 @@ static int set_using_dma (ide_drive_t *drive, int arg)
1145 err = 0; 910 err = 0;
1146 911
1147 if (arg) { 912 if (arg) {
913 hwif->dma_off_quietly(drive);
1148 if (ide_set_dma(drive) || hwif->ide_dma_on(drive)) 914 if (ide_set_dma(drive) || hwif->ide_dma_on(drive))
1149 err = -EIO; 915 err = -EIO;
1150 } else 916 } else
@@ -1159,14 +925,20 @@ static int set_using_dma (ide_drive_t *drive, int arg)
1159out: 925out:
1160 return err; 926 return err;
1161#else 927#else
928 if (arg < 0 || arg > 1)
929 return -EINVAL;
930
1162 return -EPERM; 931 return -EPERM;
1163#endif 932#endif
1164} 933}
1165 934
1166static int set_pio_mode (ide_drive_t *drive, int arg) 935int set_pio_mode(ide_drive_t *drive, int arg)
1167{ 936{
1168 struct request rq; 937 struct request rq;
1169 938
939 if (arg < 0 || arg > 255)
940 return -EINVAL;
941
1170 if (!HWIF(drive)->tuneproc) 942 if (!HWIF(drive)->tuneproc)
1171 return -ENOSYS; 943 return -ENOSYS;
1172 if (drive->special.b.set_tune) 944 if (drive->special.b.set_tune)
@@ -1178,42 +950,20 @@ static int set_pio_mode (ide_drive_t *drive, int arg)
1178 return 0; 950 return 0;
1179} 951}
1180 952
1181static int set_xfer_rate (ide_drive_t *drive, int arg) 953static int set_unmaskirq(ide_drive_t *drive, int arg)
1182{ 954{
1183 int err = ide_wait_cmd(drive, 955 if (drive->no_unmask)
1184 WIN_SETFEATURES, (u8) arg, 956 return -EPERM;
1185 SETFEATURES_XFER, 0, NULL);
1186 957
1187 if (!err && arg) { 958 if (arg < 0 || arg > 1)
1188 ide_set_xfer_rate(drive, (u8) arg); 959 return -EINVAL;
1189 ide_driveid_update(drive);
1190 }
1191 return err;
1192}
1193 960
1194/** 961 if (ide_spin_wait_hwgroup(drive))
1195 * ide_add_generic_settings - generic ide settings 962 return -EBUSY;
1196 * @drive: drive being configured 963 drive->unmask = arg;
1197 * 964 spin_unlock_irq(&ide_lock);
1198 * Add the generic parts of the system settings to the /proc files and
1199 * ioctls for this IDE device. The caller must not be holding the
1200 * ide_setting_sem.
1201 */
1202 965
1203void ide_add_generic_settings (ide_drive_t *drive) 966 return 0;
1204{
1205/*
1206 * drive setting name read/write access read ioctl write ioctl data type min max mul_factor div_factor data pointer set function
1207 */
1208 __ide_add_setting(drive, "io_32bit", drive->no_io_32bit ? SETTING_READ : SETTING_RW, HDIO_GET_32BIT, HDIO_SET_32BIT, TYPE_BYTE, 0, 1 + (SUPPORT_VLB_SYNC << 1), 1, 1, &drive->io_32bit, set_io_32bit, 0);
1209 __ide_add_setting(drive, "keepsettings", SETTING_RW, HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL, 0);
1210 __ide_add_setting(drive, "nice1", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL, 0);
1211 __ide_add_setting(drive, "pio_mode", SETTING_WRITE, -1, HDIO_SET_PIO_MODE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode, 0);
1212 __ide_add_setting(drive, "unmaskirq", drive->no_unmask ? SETTING_READ : SETTING_RW, HDIO_GET_UNMASKINTR, HDIO_SET_UNMASKINTR, TYPE_BYTE, 0, 1, 1, 1, &drive->unmask, NULL, 0);
1213 __ide_add_setting(drive, "using_dma", SETTING_RW, HDIO_GET_DMA, HDIO_SET_DMA, TYPE_BYTE, 0, 1, 1, 1, &drive->using_dma, set_using_dma, 0);
1214 __ide_add_setting(drive, "init_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL, 0);
1215 __ide_add_setting(drive, "current_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate, 0);
1216 __ide_add_setting(drive, "number", SETTING_RW, -1, -1, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL, 0);
1217} 967}
1218 968
1219/** 969/**
@@ -1285,27 +1035,23 @@ static int generic_ide_resume(struct device *dev)
1285int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev, 1035int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
1286 unsigned int cmd, unsigned long arg) 1036 unsigned int cmd, unsigned long arg)
1287{ 1037{
1288 ide_settings_t *setting; 1038 unsigned long flags;
1289 ide_driver_t *drv; 1039 ide_driver_t *drv;
1290 int err = 0;
1291 void __user *p = (void __user *)arg; 1040 void __user *p = (void __user *)arg;
1041 int err = 0, (*setfunc)(ide_drive_t *, int);
1042 u8 *val;
1292 1043
1293 down(&ide_setting_sem); 1044 switch (cmd) {
1294 if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) { 1045 case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
1295 if (cmd == setting->read_ioctl) { 1046 case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
1296 err = ide_read_setting(drive, setting); 1047 case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
1297 up(&ide_setting_sem); 1048 case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
1298 return err >= 0 ? put_user(err, (long __user *)arg) : err; 1049 case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
1299 } else { 1050 case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
1300 if (bdev != bdev->bd_contains) 1051 case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
1301 err = -EINVAL; 1052 case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
1302 else 1053 case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
1303 err = ide_write_setting(drive, setting, arg);
1304 up(&ide_setting_sem);
1305 return err;
1306 }
1307 } 1054 }
1308 up(&ide_setting_sem);
1309 1055
1310 switch (cmd) { 1056 switch (cmd) {
1311 case HDIO_OBSOLETE_IDENTITY: 1057 case HDIO_OBSOLETE_IDENTITY:
@@ -1359,7 +1105,7 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
1359 ide_init_hwif_ports(&hw, (unsigned long) args[0], 1105 ide_init_hwif_ports(&hw, (unsigned long) args[0],
1360 (unsigned long) args[1], NULL); 1106 (unsigned long) args[1], NULL);
1361 hw.irq = args[2]; 1107 hw.irq = args[2];
1362 if (ide_register_hw(&hw, NULL) == -1) 1108 if (ide_register_hw(&hw, 0, NULL) == -1)
1363 return -EIO; 1109 return -EIO;
1364 return 0; 1110 return 0;
1365 } 1111 }
@@ -1434,6 +1180,28 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
1434 default: 1180 default:
1435 return -EINVAL; 1181 return -EINVAL;
1436 } 1182 }
1183
1184read_val:
1185 down(&ide_setting_sem);
1186 spin_lock_irqsave(&ide_lock, flags);
1187 err = *val;
1188 spin_unlock_irqrestore(&ide_lock, flags);
1189 up(&ide_setting_sem);
1190 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1191
1192set_val:
1193 if (bdev != bdev->bd_contains)
1194 err = -EINVAL;
1195 else {
1196 if (!capable(CAP_SYS_ADMIN))
1197 err = -EACCES;
1198 else {
1199 down(&ide_setting_sem);
1200 err = setfunc(drive, arg);
1201 up(&ide_setting_sem);
1202 }
1203 }
1204 return err;
1437} 1205}
1438 1206
1439EXPORT_SYMBOL(generic_ide_ioctl); 1207EXPORT_SYMBOL(generic_ide_ioctl);
@@ -1566,13 +1334,13 @@ static int __init ide_setup(char *s)
1566 return 1; 1334 return 1;
1567 } 1335 }
1568 1336
1569#ifdef CONFIG_BLK_DEV_IDEPCI 1337#ifdef CONFIG_IDEPCI_PCIBUS_ORDER
1570 if (!strcmp(s, "ide=reverse")) { 1338 if (!strcmp(s, "ide=reverse")) {
1571 ide_scan_direction = 1; 1339 ide_scan_direction = 1;
1572 printk(" : Enabled support for IDE inverse scan order.\n"); 1340 printk(" : Enabled support for IDE inverse scan order.\n");
1573 return 1; 1341 return 1;
1574 } 1342 }
1575#endif /* CONFIG_BLK_DEV_IDEPCI */ 1343#endif
1576 1344
1577#ifdef CONFIG_BLK_DEV_IDEACPI 1345#ifdef CONFIG_BLK_DEV_IDEACPI
1578 if (!strcmp(s, "ide=noacpi")) { 1346 if (!strcmp(s, "ide=noacpi")) {
@@ -1832,9 +1600,9 @@ extern void __init h8300_ide_init(void);
1832 */ 1600 */
1833static void __init probe_for_hwifs (void) 1601static void __init probe_for_hwifs (void)
1834{ 1602{
1835#ifdef CONFIG_BLK_DEV_IDEPCI 1603#ifdef CONFIG_IDEPCI_PCIBUS_ORDER
1836 ide_scan_pcibus(ide_scan_direction); 1604 ide_scan_pcibus(ide_scan_direction);
1837#endif /* CONFIG_BLK_DEV_IDEPCI */ 1605#endif
1838 1606
1839#ifdef CONFIG_ETRAX_IDE 1607#ifdef CONFIG_ETRAX_IDE
1840 { 1608 {
@@ -1892,54 +1660,6 @@ static void __init probe_for_hwifs (void)
1892#endif 1660#endif
1893} 1661}
1894 1662
1895void ide_register_subdriver(ide_drive_t *drive, ide_driver_t *driver)
1896{
1897#ifdef CONFIG_PROC_FS
1898 ide_add_proc_entries(drive->proc, driver->proc, drive);
1899#endif
1900}
1901
1902EXPORT_SYMBOL(ide_register_subdriver);
1903
1904/**
1905 * ide_unregister_subdriver - disconnect drive from driver
1906 * @drive: drive to unplug
1907 * @driver: driver
1908 *
1909 * Disconnect a drive from the driver it was attached to and then
1910 * clean up the various proc files and other objects attached to it.
1911 *
1912 * Takes ide_setting_sem and ide_lock.
1913 * Caller must hold none of the locks.
1914 */
1915
1916void ide_unregister_subdriver(ide_drive_t *drive, ide_driver_t *driver)
1917{
1918 unsigned long flags;
1919
1920#ifdef CONFIG_PROC_FS
1921 ide_remove_proc_entries(drive->proc, driver->proc);
1922#endif
1923 down(&ide_setting_sem);
1924 spin_lock_irqsave(&ide_lock, flags);
1925 /*
1926 * ide_setting_sem protects the settings list
1927 * ide_lock protects the use of settings
1928 *
1929 * so we need to hold both, ide_settings_sem because we want to
1930 * modify the settings list, and ide_lock because we cannot take
1931 * a setting out that is being used.
1932 *
1933 * OTOH both ide_{read,write}_setting are only ever used under
1934 * ide_setting_sem.
1935 */
1936 auto_remove_settings(drive);
1937 spin_unlock_irqrestore(&ide_lock, flags);
1938 up(&ide_setting_sem);
1939}
1940
1941EXPORT_SYMBOL(ide_unregister_subdriver);
1942
1943/* 1663/*
1944 * Probe module 1664 * Probe module
1945 */ 1665 */
@@ -2071,9 +1791,7 @@ static int __init ide_init(void)
2071 1791
2072 init_ide_data(); 1792 init_ide_data();
2073 1793
2074#ifdef CONFIG_PROC_FS 1794 proc_ide_create();
2075 proc_ide_root = proc_mkdir("ide", NULL);
2076#endif
2077 1795
2078#ifdef CONFIG_BLK_DEV_ALI14XX 1796#ifdef CONFIG_BLK_DEV_ALI14XX
2079 if (probe_ali14xx) 1797 if (probe_ali14xx)
@@ -2096,14 +1814,9 @@ static int __init ide_init(void)
2096 (void)qd65xx_init(); 1814 (void)qd65xx_init();
2097#endif 1815#endif
2098 1816
2099 initializing = 1;
2100 /* Probe for special PCI and other "known" interface chipsets. */ 1817 /* Probe for special PCI and other "known" interface chipsets. */
2101 probe_for_hwifs(); 1818 probe_for_hwifs();
2102 initializing = 0;
2103 1819
2104#ifdef CONFIG_PROC_FS
2105 proc_ide_create();
2106#endif
2107 return 0; 1820 return 0;
2108} 1821}
2109 1822
@@ -2143,9 +1856,7 @@ void __exit cleanup_module (void)
2143 pnpide_exit(); 1856 pnpide_exit();
2144#endif 1857#endif
2145 1858
2146#ifdef CONFIG_PROC_FS
2147 proc_ide_destroy(); 1859 proc_ide_destroy();
2148#endif
2149 1860
2150 bus_unregister(&ide_bus_type); 1861 bus_unregister(&ide_bus_type);
2151} 1862}
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index 91961aa03047..df17ed68c0bc 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/ali14xx.c
@@ -223,7 +223,8 @@ static int __init ali14xx_probe(void)
223 probe_hwif_init(hwif); 223 probe_hwif_init(hwif);
224 probe_hwif_init(mate); 224 probe_hwif_init(mate);
225 225
226 create_proc_ide_interfaces(); 226 ide_proc_register_port(hwif);
227 ide_proc_register_port(mate);
227 228
228 return 0; 229 return 0;
229} 230}
diff --git a/drivers/ide/legacy/buddha.c b/drivers/ide/legacy/buddha.c
index 1ed224a01f79..101aee1711c4 100644
--- a/drivers/ide/legacy/buddha.c
+++ b/drivers/ide/legacy/buddha.c
@@ -213,7 +213,7 @@ fail_base2:
213 IRQ_AMIGA_PORTS); 213 IRQ_AMIGA_PORTS);
214 } 214 }
215 215
216 index = ide_register_hw(&hw, &hwif); 216 index = ide_register_hw(&hw, 1, &hwif);
217 if (index != -1) { 217 if (index != -1) {
218 hwif->mmio = 1; 218 hwif->mmio = 1;
219 printk("ide%d: ", index); 219 printk("ide%d: ", index);
diff --git a/drivers/ide/legacy/dtc2278.c b/drivers/ide/legacy/dtc2278.c
index 0219ffa64db6..36a3f0ac6162 100644
--- a/drivers/ide/legacy/dtc2278.c
+++ b/drivers/ide/legacy/dtc2278.c
@@ -138,7 +138,8 @@ static int __init dtc2278_probe(void)
138 probe_hwif_init(hwif); 138 probe_hwif_init(hwif);
139 probe_hwif_init(mate); 139 probe_hwif_init(mate);
140 140
141 create_proc_ide_interfaces(); 141 ide_proc_register_port(hwif);
142 ide_proc_register_port(mate);
142 143
143 return 0; 144 return 0;
144} 145}
diff --git a/drivers/ide/legacy/falconide.c b/drivers/ide/legacy/falconide.c
index a9f2cd5bb81e..e1e9d9d6893f 100644
--- a/drivers/ide/legacy/falconide.c
+++ b/drivers/ide/legacy/falconide.c
@@ -70,7 +70,7 @@ void __init falconide_init(void)
70 0, 0, NULL, 70 0, 0, NULL,
71// falconide_iops, 71// falconide_iops,
72 IRQ_MFP_IDE); 72 IRQ_MFP_IDE);
73 index = ide_register_hw(&hw, NULL); 73 index = ide_register_hw(&hw, 1, NULL);
74 74
75 if (index != -1) 75 if (index != -1)
76 printk("ide%d: Falcon IDE interface\n", index); 76 printk("ide%d: Falcon IDE interface\n", index);
diff --git a/drivers/ide/legacy/gayle.c b/drivers/ide/legacy/gayle.c
index dcfadbbf55d8..0830a021bbb6 100644
--- a/drivers/ide/legacy/gayle.c
+++ b/drivers/ide/legacy/gayle.c
@@ -165,7 +165,7 @@ found:
165// &gayle_iops, 165// &gayle_iops,
166 IRQ_AMIGA_PORTS); 166 IRQ_AMIGA_PORTS);
167 167
168 index = ide_register_hw(&hw, &hwif); 168 index = ide_register_hw(&hw, 1, &hwif);
169 if (index != -1) { 169 if (index != -1) {
170 hwif->mmio = 1; 170 hwif->mmio = 1;
171 switch (i) { 171 switch (i) {
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index a2832643c522..c8f353b1296f 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -357,7 +357,8 @@ int __init ht6560b_init(void)
357 probe_hwif_init(hwif); 357 probe_hwif_init(hwif);
358 probe_hwif_init(mate); 358 probe_hwif_init(mate);
359 359
360 create_proc_ide_interfaces(); 360 ide_proc_register_port(hwif);
361 ide_proc_register_port(mate);
361 362
362 return 0; 363 return 0;
363 364
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index c6522a64d7ec..2f3977f195b7 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -153,7 +153,7 @@ static int idecs_register(unsigned long io, unsigned long ctl, unsigned long irq
153 hw.irq = irq; 153 hw.irq = irq;
154 hw.chipset = ide_pci; 154 hw.chipset = ide_pci;
155 hw.dev = &handle->dev; 155 hw.dev = &handle->dev;
156 return ide_register_hw_with_fixup(&hw, NULL, ide_undecoded_slave); 156 return ide_register_hw_with_fixup(&hw, 0, NULL, ide_undecoded_slave);
157} 157}
158 158
159/*====================================================================== 159/*======================================================================
diff --git a/drivers/ide/legacy/macide.c b/drivers/ide/legacy/macide.c
index 4c0079ad52ac..c211fc78345d 100644
--- a/drivers/ide/legacy/macide.c
+++ b/drivers/ide/legacy/macide.c
@@ -102,21 +102,21 @@ void macide_init(void)
102 0, 0, macide_ack_intr, 102 0, 0, macide_ack_intr,
103// quadra_ide_iops, 103// quadra_ide_iops,
104 IRQ_NUBUS_F); 104 IRQ_NUBUS_F);
105 index = ide_register_hw(&hw, &hwif); 105 index = ide_register_hw(&hw, 1, &hwif);
106 break; 106 break;
107 case MAC_IDE_PB: 107 case MAC_IDE_PB:
108 ide_setup_ports(&hw, IDE_BASE, macide_offsets, 108 ide_setup_ports(&hw, IDE_BASE, macide_offsets,
109 0, 0, macide_ack_intr, 109 0, 0, macide_ack_intr,
110// macide_pb_iops, 110// macide_pb_iops,
111 IRQ_NUBUS_C); 111 IRQ_NUBUS_C);
112 index = ide_register_hw(&hw, &hwif); 112 index = ide_register_hw(&hw, 1, &hwif);
113 break; 113 break;
114 case MAC_IDE_BABOON: 114 case MAC_IDE_BABOON:
115 ide_setup_ports(&hw, BABOON_BASE, macide_offsets, 115 ide_setup_ports(&hw, BABOON_BASE, macide_offsets,
116 0, 0, NULL, 116 0, 0, NULL,
117// macide_baboon_iops, 117// macide_baboon_iops,
118 IRQ_BABOON_1); 118 IRQ_BABOON_1);
119 index = ide_register_hw(&hw, &hwif); 119 index = ide_register_hw(&hw, 1, &hwif);
120 if (index == -1) break; 120 if (index == -1) break;
121 if (macintosh_config->ident == MAC_MODEL_PB190) { 121 if (macintosh_config->ident == MAC_MODEL_PB190) {
122 122
diff --git a/drivers/ide/legacy/q40ide.c b/drivers/ide/legacy/q40ide.c
index 74f08124eabb..e628a983ce33 100644
--- a/drivers/ide/legacy/q40ide.c
+++ b/drivers/ide/legacy/q40ide.c
@@ -142,7 +142,7 @@ void q40ide_init(void)
142 0, NULL, 142 0, NULL,
143// m68kide_iops, 143// m68kide_iops,
144 q40ide_default_irq(pcide_bases[i])); 144 q40ide_default_irq(pcide_bases[i]));
145 index = ide_register_hw(&hw, &hwif); 145 index = ide_register_hw(&hw, 1, &hwif);
146 // **FIXME** 146 // **FIXME**
147 if (index != -1) 147 if (index != -1)
148 hwif->mmio = 1; 148 hwif->mmio = 1;
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c
index 2fb8f50f1293..d1414a75b523 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/legacy/qd65xx.c
@@ -427,7 +427,7 @@ static int __init qd_probe(int base)
427 qd_setup(hwif, base, config, QD6500_DEF_DATA, QD6500_DEF_DATA, 427 qd_setup(hwif, base, config, QD6500_DEF_DATA, QD6500_DEF_DATA,
428 &qd6500_tune_drive); 428 &qd6500_tune_drive);
429 429
430 create_proc_ide_interfaces(); 430 ide_proc_register_port(hwif);
431 431
432 return 1; 432 return 1;
433 } 433 }
@@ -459,7 +459,7 @@ static int __init qd_probe(int base)
459 &qd6580_tune_drive); 459 &qd6580_tune_drive);
460 qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT); 460 qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT);
461 461
462 create_proc_ide_interfaces(); 462 ide_proc_register_port(hwif);
463 463
464 return 1; 464 return 1;
465 } else { 465 } else {
@@ -479,7 +479,8 @@ static int __init qd_probe(int base)
479 &qd6580_tune_drive); 479 &qd6580_tune_drive);
480 qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT); 480 qd_write_reg(QD_DEF_CONTR,QD_CONTROL_PORT);
481 481
482 create_proc_ide_interfaces(); 482 ide_proc_register_port(hwif);
483 ide_proc_register_port(mate);
483 484
484 return 0; /* no other qd65xx possible */ 485 return 0; /* no other qd65xx possible */
485 } 486 }
diff --git a/drivers/ide/legacy/umc8672.c b/drivers/ide/legacy/umc8672.c
index ca7974455578..ddc403a0bd82 100644
--- a/drivers/ide/legacy/umc8672.c
+++ b/drivers/ide/legacy/umc8672.c
@@ -160,7 +160,8 @@ static int __init umc8672_probe(void)
160 probe_hwif_init(hwif); 160 probe_hwif_init(hwif);
161 probe_hwif_init(mate); 161 probe_hwif_init(mate);
162 162
163 create_proc_ide_interfaces(); 163 ide_proc_register_port(hwif);
164 ide_proc_register_port(mate);
164 165
165 return 0; 166 return 0;
166} 167}
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index d54d9fe92a7d..ca95e990862e 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -760,6 +760,9 @@ static int au_ide_probe(struct device *dev)
760#endif 760#endif
761 761
762 probe_hwif_init(hwif); 762 probe_hwif_init(hwif);
763
764 ide_proc_register_port(hwif);
765
763 dev_set_drvdata(dev, hwif); 766 dev_set_drvdata(dev, hwif);
764 767
765 printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode ); 768 printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode );
diff --git a/drivers/ide/mips/swarm.c b/drivers/ide/mips/swarm.c
index 81fa06851b27..6e935d7c63fd 100644
--- a/drivers/ide/mips/swarm.c
+++ b/drivers/ide/mips/swarm.c
@@ -129,6 +129,9 @@ static int __devinit swarm_ide_probe(struct device *dev)
129 hwif->irq = hwif->hw.irq; 129 hwif->irq = hwif->hw.irq;
130 130
131 probe_hwif_init(hwif); 131 probe_hwif_init(hwif);
132
133 ide_proc_register_port(hwif);
134
132 dev_set_drvdata(dev, hwif); 135 dev_set_drvdata(dev, hwif);
133 136
134 return 0; 137 return 0;
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index 73bdf64dbbfc..b173bc66ce1e 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -87,38 +87,12 @@ static u8 pci_bus_clock_list_ultra (u8 speed, struct chipset_bus_clock_list_entr
87 return chipset_table->ultra_settings; 87 return chipset_table->ultra_settings;
88} 88}
89 89
90static u8 aec62xx_ratemask (ide_drive_t *drive)
91{
92 ide_hwif_t *hwif = HWIF(drive);
93 u8 mode;
94
95 switch(hwif->pci_dev->device) {
96 case PCI_DEVICE_ID_ARTOP_ATP865:
97 case PCI_DEVICE_ID_ARTOP_ATP865R:
98 mode = (inb(hwif->channel ?
99 hwif->mate->dma_status :
100 hwif->dma_status) & 0x10) ? 4 : 3;
101 break;
102 case PCI_DEVICE_ID_ARTOP_ATP860:
103 case PCI_DEVICE_ID_ARTOP_ATP860R:
104 mode = 2;
105 break;
106 case PCI_DEVICE_ID_ARTOP_ATP850UF:
107 default:
108 return 1;
109 }
110
111 if (!eighty_ninty_three(drive))
112 mode = min(mode, (u8)1);
113 return mode;
114}
115
116static int aec6210_tune_chipset (ide_drive_t *drive, u8 xferspeed) 90static int aec6210_tune_chipset (ide_drive_t *drive, u8 xferspeed)
117{ 91{
118 ide_hwif_t *hwif = HWIF(drive); 92 ide_hwif_t *hwif = HWIF(drive);
119 struct pci_dev *dev = hwif->pci_dev; 93 struct pci_dev *dev = hwif->pci_dev;
120 u16 d_conf = 0; 94 u16 d_conf = 0;
121 u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed); 95 u8 speed = ide_rate_filter(drive, xferspeed);
122 u8 ultra = 0, ultra_conf = 0; 96 u8 ultra = 0, ultra_conf = 0;
123 u8 tmp0 = 0, tmp1 = 0, tmp2 = 0; 97 u8 tmp0 = 0, tmp1 = 0, tmp2 = 0;
124 unsigned long flags; 98 unsigned long flags;
@@ -145,7 +119,7 @@ static int aec6260_tune_chipset (ide_drive_t *drive, u8 xferspeed)
145{ 119{
146 ide_hwif_t *hwif = HWIF(drive); 120 ide_hwif_t *hwif = HWIF(drive);
147 struct pci_dev *dev = hwif->pci_dev; 121 struct pci_dev *dev = hwif->pci_dev;
148 u8 speed = ide_rate_filter(aec62xx_ratemask(drive), xferspeed); 122 u8 speed = ide_rate_filter(drive, xferspeed);
149 u8 unit = (drive->select.b.unit & 0x01); 123 u8 unit = (drive->select.b.unit & 0x01);
150 u8 tmp1 = 0, tmp2 = 0; 124 u8 tmp1 = 0, tmp2 = 0;
151 u8 ultra = 0, drive_conf = 0, ultra_conf = 0; 125 u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
@@ -181,17 +155,6 @@ static int aec62xx_tune_chipset (ide_drive_t *drive, u8 speed)
181 } 155 }
182} 156}
183 157
184static int config_chipset_for_dma (ide_drive_t *drive)
185{
186 u8 speed = ide_dma_speed(drive, aec62xx_ratemask(drive));
187
188 if (!(speed))
189 return 0;
190
191 (void) aec62xx_tune_chipset(drive, speed);
192 return ide_dma_enable(drive);
193}
194
195static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio) 158static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio)
196{ 159{
197 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 160 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
@@ -200,7 +163,7 @@ static void aec62xx_tune_drive (ide_drive_t *drive, u8 pio)
200 163
201static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive) 164static int aec62xx_config_drive_xfer_rate (ide_drive_t *drive)
202{ 165{
203 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 166 if (ide_tune_dma(drive))
204 return 0; 167 return 0;
205 168
206 if (ide_use_fast_pio(drive)) 169 if (ide_use_fast_pio(drive))
@@ -261,11 +224,13 @@ static unsigned int __devinit init_chipset_aec62xx(struct pci_dev *dev, const ch
261 224
262static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif) 225static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
263{ 226{
227 struct pci_dev *dev = hwif->pci_dev;
228
264 hwif->autodma = 0; 229 hwif->autodma = 0;
265 hwif->tuneproc = &aec62xx_tune_drive; 230 hwif->tuneproc = &aec62xx_tune_drive;
266 hwif->speedproc = &aec62xx_tune_chipset; 231 hwif->speedproc = &aec62xx_tune_chipset;
267 232
268 if (hwif->pci_dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF) 233 if (dev->device == PCI_DEVICE_ID_ARTOP_ATP850UF)
269 hwif->serialized = hwif->channel; 234 hwif->serialized = hwif->channel;
270 235
271 if (hwif->mate) 236 if (hwif->mate)
@@ -277,7 +242,15 @@ static void __devinit init_hwif_aec62xx(ide_hwif_t *hwif)
277 return; 242 return;
278 } 243 }
279 244
280 hwif->ultra_mask = 0x7f; 245 hwif->ultra_mask = hwif->cds->udma_mask;
246
247 /* atp865 and atp865r */
248 if (hwif->ultra_mask == 0x3f) {
249 /* check bit 0x10 of DMA status register */
250 if (inb(pci_resource_start(dev, 4) + 2) & 0x10)
251 hwif->ultra_mask = 0x7f; /* udma0-6 */
252 }
253
281 hwif->mwdma_mask = 0x07; 254 hwif->mwdma_mask = 0x07;
282 255
283 hwif->ide_dma_check = &aec62xx_config_drive_xfer_rate; 256 hwif->ide_dma_check = &aec62xx_config_drive_xfer_rate;
@@ -344,6 +317,7 @@ static ide_pci_device_t aec62xx_chipsets[] __devinitdata = {
344 .autodma = AUTODMA, 317 .autodma = AUTODMA,
345 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 318 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
346 .bootable = OFF_BOARD, 319 .bootable = OFF_BOARD,
320 .udma_mask = 0x07, /* udma0-2 */
347 },{ /* 1 */ 321 },{ /* 1 */
348 .name = "AEC6260", 322 .name = "AEC6260",
349 .init_setup = init_setup_aec62xx, 323 .init_setup = init_setup_aec62xx,
@@ -353,6 +327,7 @@ static ide_pci_device_t aec62xx_chipsets[] __devinitdata = {
353 .channels = 2, 327 .channels = 2,
354 .autodma = NOAUTODMA, 328 .autodma = NOAUTODMA,
355 .bootable = OFF_BOARD, 329 .bootable = OFF_BOARD,
330 .udma_mask = 0x1f, /* udma0-4 */
356 },{ /* 2 */ 331 },{ /* 2 */
357 .name = "AEC6260R", 332 .name = "AEC6260R",
358 .init_setup = init_setup_aec62xx, 333 .init_setup = init_setup_aec62xx,
@@ -363,6 +338,7 @@ static ide_pci_device_t aec62xx_chipsets[] __devinitdata = {
363 .autodma = AUTODMA, 338 .autodma = AUTODMA,
364 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 339 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
365 .bootable = NEVER_BOARD, 340 .bootable = NEVER_BOARD,
341 .udma_mask = 0x1f, /* udma0-4 */
366 },{ /* 3 */ 342 },{ /* 3 */
367 .name = "AEC6X80", 343 .name = "AEC6X80",
368 .init_setup = init_setup_aec6x80, 344 .init_setup = init_setup_aec6x80,
@@ -372,6 +348,7 @@ static ide_pci_device_t aec62xx_chipsets[] __devinitdata = {
372 .channels = 2, 348 .channels = 2,
373 .autodma = AUTODMA, 349 .autodma = AUTODMA,
374 .bootable = OFF_BOARD, 350 .bootable = OFF_BOARD,
351 .udma_mask = 0x3f, /* udma0-5 */
375 },{ /* 4 */ 352 },{ /* 4 */
376 .name = "AEC6X80R", 353 .name = "AEC6X80R",
377 .init_setup = init_setup_aec6x80, 354 .init_setup = init_setup_aec6x80,
@@ -382,6 +359,7 @@ static ide_pci_device_t aec62xx_chipsets[] __devinitdata = {
382 .autodma = AUTODMA, 359 .autodma = AUTODMA,
383 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}}, 360 .enablebits = {{0x4a,0x02,0x02}, {0x4a,0x04,0x04}},
384 .bootable = OFF_BOARD, 361 .bootable = OFF_BOARD,
362 .udma_mask = 0x3f, /* udma0-5 */
385 } 363 }
386}; 364};
387 365
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 946a12746cb5..27525ec2e19a 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -50,7 +50,7 @@ static u8 m5229_revision;
50static u8 chip_is_1543c_e; 50static u8 chip_is_1543c_e;
51static struct pci_dev *isa_dev; 51static struct pci_dev *isa_dev;
52 52
53#if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) 53#if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
54#include <linux/stat.h> 54#include <linux/stat.h>
55#include <linux/proc_fs.h> 55#include <linux/proc_fs.h>
56 56
@@ -278,7 +278,7 @@ static int ali_get_info (char *buffer, char **addr, off_t offset, int count)
278 278
279 return p-buffer; /* => must be less than 4k! */ 279 return p-buffer; /* => must be less than 4k! */
280} 280}
281#endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) */ 281#endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS) */
282 282
283/** 283/**
284 * ali15x3_tune_pio - set up chipset for PIO mode 284 * ali15x3_tune_pio - set up chipset for PIO mode
@@ -378,74 +378,31 @@ static void ali15x3_tune_drive (ide_drive_t *drive, u8 pio)
378} 378}
379 379
380/** 380/**
381 * ali15x3_can_ultra - check for ultra DMA support 381 * ali_udma_filter - compute UDMA mask
382 * @drive: drive to do the check 382 * @drive: IDE device
383 * 383 *
384 * Check the drive and controller revisions. Return 0 if UDMA is 384 * Return available UDMA modes.
385 * not available, or 1 if UDMA can be used. The actual rules for 385 *
386 * the ALi are 386 * The actual rules for the ALi are:
387 * No UDMA on revisions <= 0x20 387 * No UDMA on revisions <= 0x20
388 * Disk only for revisions < 0xC2 388 * Disk only for revisions < 0xC2
389 * Not WDC drives for revisions < 0xC2 389 * Not WDC drives for revisions < 0xC2
390 * 390 *
391 * FIXME: WDC ifdef needs to die 391 * FIXME: WDC ifdef needs to die
392 */ 392 */
393
394static u8 ali15x3_can_ultra (ide_drive_t *drive)
395{
396#ifndef CONFIG_WDC_ALI15X3
397 struct hd_driveid *id = drive->id;
398#endif /* CONFIG_WDC_ALI15X3 */
399 393
400 if (m5229_revision <= 0x20) { 394static u8 ali_udma_filter(ide_drive_t *drive)
401 return 0;
402 } else if ((m5229_revision < 0xC2) &&
403#ifndef CONFIG_WDC_ALI15X3
404 ((chip_is_1543c_e && strstr(id->model, "WDC ")) ||
405 (drive->media!=ide_disk))) {
406#else /* CONFIG_WDC_ALI15X3 */
407 (drive->media!=ide_disk)) {
408#endif /* CONFIG_WDC_ALI15X3 */
409 return 0;
410 } else {
411 return 1;
412 }
413}
414
415/**
416 * ali15x3_ratemask - generate DMA mode list
417 * @drive: drive to compute against
418 *
419 * Generate a list of the available DMA modes for the drive.
420 * FIXME: this function contains lots of bogus masking we can dump
421 *
422 * Return the highest available mode (UDMA33, UDMA66, UDMA100,..)
423 */
424
425static u8 ali15x3_ratemask (ide_drive_t *drive)
426{ 395{
427 u8 mode = 0, can_ultra = ali15x3_can_ultra(drive); 396 if (m5229_revision > 0x20 && m5229_revision < 0xC2) {
428 397 if (drive->media != ide_disk)
429 if (m5229_revision > 0xC4 && can_ultra) { 398 return 0;
430 mode = 4; 399#ifndef CONFIG_WDC_ALI15X3
431 } else if (m5229_revision == 0xC4 && can_ultra) { 400 if (chip_is_1543c_e && strstr(drive->id->model, "WDC "))
432 mode = 3; 401 return 0;
433 } else if (m5229_revision >= 0xC2 && can_ultra) { 402#endif
434 mode = 2;
435 } else if (can_ultra) {
436 return 1;
437 } else {
438 return 0;
439 } 403 }
440 404
441 /* 405 return drive->hwif->ultra_mask;
442 * If the drive sees no suitable cable then UDMA 33
443 * is the highest permitted mode
444 */
445
446 if (!eighty_ninty_three(drive))
447 mode = min(mode, (u8)1);
448 return mode;
449} 406}
450 407
451/** 408/**
@@ -461,7 +418,7 @@ static int ali15x3_tune_chipset (ide_drive_t *drive, u8 xferspeed)
461{ 418{
462 ide_hwif_t *hwif = HWIF(drive); 419 ide_hwif_t *hwif = HWIF(drive);
463 struct pci_dev *dev = hwif->pci_dev; 420 struct pci_dev *dev = hwif->pci_dev;
464 u8 speed = ide_rate_filter(ali15x3_ratemask(drive), xferspeed); 421 u8 speed = ide_rate_filter(drive, xferspeed);
465 u8 speed1 = speed; 422 u8 speed1 = speed;
466 u8 unit = (drive->select.b.unit & 0x01); 423 u8 unit = (drive->select.b.unit & 0x01);
467 u8 tmpbyte = 0x00; 424 u8 tmpbyte = 0x00;
@@ -498,28 +455,6 @@ static int ali15x3_tune_chipset (ide_drive_t *drive, u8 xferspeed)
498 return (ide_config_drive_speed(drive, speed)); 455 return (ide_config_drive_speed(drive, speed));
499} 456}
500 457
501
502/**
503 * config_chipset_for_dma - set up DMA mode
504 * @drive: drive to configure for
505 *
506 * Place a drive into DMA mode and tune the chipset for
507 * the selected speed.
508 *
509 * Returns true if DMA mode can be used
510 */
511
512static int config_chipset_for_dma (ide_drive_t *drive)
513{
514 u8 speed = ide_dma_speed(drive, ali15x3_ratemask(drive));
515
516 if (!(speed))
517 return 0;
518
519 (void) ali15x3_tune_chipset(drive, speed);
520 return ide_dma_enable(drive);
521}
522
523/** 458/**
524 * ali15x3_config_drive_for_dma - configure for DMA 459 * ali15x3_config_drive_for_dma - configure for DMA
525 * @drive: drive to configure 460 * @drive: drive to configure
@@ -530,48 +465,14 @@ static int config_chipset_for_dma (ide_drive_t *drive)
530 465
531static int ali15x3_config_drive_for_dma(ide_drive_t *drive) 466static int ali15x3_config_drive_for_dma(ide_drive_t *drive)
532{ 467{
533 ide_hwif_t *hwif = HWIF(drive);
534 struct hd_driveid *id = drive->id;
535
536 if ((m5229_revision<=0x20) && (drive->media!=ide_disk))
537 goto ata_pio;
538
539 drive->init_speed = 0; 468 drive->init_speed = 0;
540 469
541 if ((id != NULL) && ((id->capability & 1) != 0) && drive->autodma) { 470 if (ide_tune_dma(drive))
542 /* Consult the list of known "bad" drives */ 471 return 0;
543 if (__ide_dma_bad_drive(drive))
544 goto ata_pio;
545 if ((id->field_valid & 4) && (m5229_revision >= 0xC2)) {
546 if (id->dma_ultra & hwif->ultra_mask) {
547 /* Force if Capable UltraDMA */
548 int dma = config_chipset_for_dma(drive);
549 if ((id->field_valid & 2) && !dma)
550 goto try_dma_modes;
551 }
552 } else if (id->field_valid & 2) {
553try_dma_modes:
554 if ((id->dma_mword & hwif->mwdma_mask) ||
555 (id->dma_1word & hwif->swdma_mask)) {
556 /* Force if Capable regular DMA modes */
557 if (!config_chipset_for_dma(drive))
558 goto ata_pio;
559 }
560 } else if (__ide_dma_good_drive(drive) &&
561 (id->eide_dma_time < 150)) {
562 /* Consult the list of known "good" drives */
563 if (!config_chipset_for_dma(drive))
564 goto ata_pio;
565 } else {
566 goto ata_pio;
567 }
568 } else {
569ata_pio:
570 hwif->tuneproc(drive, 255);
571 return -1;
572 }
573 472
574 return 0; 473 ali15x3_tune_drive(drive, 255);
474
475 return -1;
575} 476}
576 477
577/** 478/**
@@ -609,13 +510,13 @@ static unsigned int __devinit init_chipset_ali15x3 (struct pci_dev *dev, const c
609 510
610 isa_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL); 511 isa_dev = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
611 512
612#if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) 513#if defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
613 if (!ali_proc) { 514 if (!ali_proc) {
614 ali_proc = 1; 515 ali_proc = 1;
615 bmide_dev = dev; 516 bmide_dev = dev;
616 ide_pci_create_host_proc("ali", ali_get_info); 517 ide_pci_create_host_proc("ali", ali_get_info);
617 } 518 }
618#endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_PROC_FS) */ 519#endif /* defined(DISPLAY_ALI_TIMINGS) && defined(CONFIG_IDE_PROC_FS) */
619 520
620 local_irq_save(flags); 521 local_irq_save(flags);
621 522
@@ -771,6 +672,7 @@ static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
771 hwif->autodma = 0; 672 hwif->autodma = 0;
772 hwif->tuneproc = &ali15x3_tune_drive; 673 hwif->tuneproc = &ali15x3_tune_drive;
773 hwif->speedproc = &ali15x3_tune_chipset; 674 hwif->speedproc = &ali15x3_tune_chipset;
675 hwif->udma_filter = &ali_udma_filter;
774 676
775 /* don't use LBA48 DMA on ALi devices before rev 0xC5 */ 677 /* don't use LBA48 DMA on ALi devices before rev 0xC5 */
776 hwif->no_lba48_dma = (m5229_revision <= 0xC4) ? 1 : 0; 678 hwif->no_lba48_dma = (m5229_revision <= 0xC4) ? 1 : 0;
@@ -781,10 +683,20 @@ static void __devinit init_hwif_common_ali15x3 (ide_hwif_t *hwif)
781 return; 683 return;
782 } 684 }
783 685
784 hwif->atapi_dma = 1;
785
786 if (m5229_revision > 0x20) 686 if (m5229_revision > 0x20)
787 hwif->ultra_mask = 0x7f; 687 hwif->atapi_dma = 1;
688
689 if (m5229_revision <= 0x20)
690 hwif->ultra_mask = 0x00; /* no udma */
691 else if (m5229_revision < 0xC2)
692 hwif->ultra_mask = 0x07; /* udma0-2 */
693 else if (m5229_revision == 0xC2 || m5229_revision == 0xC3)
694 hwif->ultra_mask = 0x1f; /* udma0-4 */
695 else if (m5229_revision == 0xC4)
696 hwif->ultra_mask = 0x3f; /* udma0-5 */
697 else
698 hwif->ultra_mask = 0x7f; /* udma0-6 */
699
788 hwif->mwdma_mask = 0x07; 700 hwif->mwdma_mask = 0x07;
789 hwif->swdma_mask = 0x07; 701 hwif->swdma_mask = 0x07;
790 702
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 7989bdd842a2..becb1a5648b0 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -92,7 +92,7 @@ static unsigned char amd_cyc2udma[] = { 6, 6, 5, 4, 0, 1, 1, 2, 2, 3, 3, 3, 3, 3
92 * AMD /proc entry. 92 * AMD /proc entry.
93 */ 93 */
94 94
95#ifdef CONFIG_PROC_FS 95#ifdef CONFIG_IDE_PROC_FS
96 96
97#include <linux/stat.h> 97#include <linux/stat.h>
98#include <linux/proc_fs.h> 98#include <linux/proc_fs.h>
@@ -402,14 +402,14 @@ static unsigned int __devinit init_chipset_amd74xx(struct pci_dev *dev, const ch
402 * Register /proc/ide/amd74xx entry 402 * Register /proc/ide/amd74xx entry
403 */ 403 */
404 404
405#if defined(DISPLAY_AMD_TIMINGS) && defined(CONFIG_PROC_FS) 405#if defined(DISPLAY_AMD_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
406 if (!amd74xx_proc) { 406 if (!amd74xx_proc) {
407 amd_base = pci_resource_start(dev, 4); 407 amd_base = pci_resource_start(dev, 4);
408 bmide_dev = dev; 408 bmide_dev = dev;
409 ide_pci_create_host_proc("amd74xx", amd74xx_get_info); 409 ide_pci_create_host_proc("amd74xx", amd74xx_get_info);
410 amd74xx_proc = 1; 410 amd74xx_proc = 1;
411 } 411 }
412#endif /* DISPLAY_AMD_TIMINGS && CONFIG_PROC_FS */ 412#endif /* DISPLAY_AMD_TIMINGS && CONFIG_IDE_PROC_FS */
413 413
414 return dev->irq; 414 return dev->irq;
415} 415}
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index 2d48af32e3f4..0e52ad722a72 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -49,22 +49,6 @@ static int save_mdma_mode[4];
49static DEFINE_SPINLOCK(atiixp_lock); 49static DEFINE_SPINLOCK(atiixp_lock);
50 50
51/** 51/**
52 * atiixp_ratemask - compute rate mask for ATIIXP IDE
53 * @drive: IDE drive to compute for
54 *
55 * Returns the available modes for the ATIIXP IDE controller.
56 */
57
58static u8 atiixp_ratemask(ide_drive_t *drive)
59{
60 u8 mode = 3;
61
62 if (!eighty_ninty_three(drive))
63 mode = min(mode, (u8)1);
64 return mode;
65}
66
67/**
68 * atiixp_dma_2_pio - return the PIO mode matching DMA 52 * atiixp_dma_2_pio - return the PIO mode matching DMA
69 * @xfer_rate: transfer speed 53 * @xfer_rate: transfer speed
70 * 54 *
@@ -189,7 +173,7 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
189 u16 tmp16; 173 u16 tmp16;
190 u8 speed, pio; 174 u8 speed, pio;
191 175
192 speed = ide_rate_filter(atiixp_ratemask(drive), xferspeed); 176 speed = ide_rate_filter(drive, xferspeed);
193 177
194 spin_lock_irqsave(&atiixp_lock, flags); 178 spin_lock_irqsave(&atiixp_lock, flags);
195 179
@@ -223,26 +207,6 @@ static int atiixp_speedproc(ide_drive_t *drive, u8 xferspeed)
223} 207}
224 208
225/** 209/**
226 * atiixp_config_drive_for_dma - configure drive for DMA
227 * @drive: IDE drive to configure
228 *
229 * Set up a ATIIXP interface channel for the best available speed.
230 * We prefer UDMA if it is available and then MWDMA. If DMA is
231 * not available we switch to PIO and return 0.
232 */
233
234static int atiixp_config_drive_for_dma(ide_drive_t *drive)
235{
236 u8 speed = ide_dma_speed(drive, atiixp_ratemask(drive));
237
238 if (!speed)
239 return 0;
240
241 (void) atiixp_speedproc(drive, speed);
242 return ide_dma_enable(drive);
243}
244
245/**
246 * atiixp_dma_check - set up an IDE device 210 * atiixp_dma_check - set up an IDE device
247 * @drive: IDE drive to configure 211 * @drive: IDE drive to configure
248 * 212 *
@@ -256,7 +220,7 @@ static int atiixp_dma_check(ide_drive_t *drive)
256 220
257 drive->init_speed = 0; 221 drive->init_speed = 0;
258 222
259 if (ide_use_dma(drive) && atiixp_config_drive_for_dma(drive)) 223 if (ide_tune_dma(drive))
260 return 0; 224 return 0;
261 225
262 if (ide_use_fast_pio(drive)) { 226 if (ide_use_fast_pio(drive)) {
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 77f51ab6d439..7c57dc696f52 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -74,7 +74,7 @@
74#define UDIDETCR1 0x7B 74#define UDIDETCR1 0x7B
75#define DTPR1 0x7C 75#define DTPR1 0x7C
76 76
77#if defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS) 77#if defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
78#include <linux/stat.h> 78#include <linux/stat.h>
79#include <linux/proc_fs.h> 79#include <linux/proc_fs.h>
80 80
@@ -165,7 +165,7 @@ static int cmd64x_get_info (char *buffer, char **addr, off_t offset, int count)
165 return p-buffer; /* => must be less than 4k! */ 165 return p-buffer; /* => must be less than 4k! */
166} 166}
167 167
168#endif /* defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS) */ 168#endif /* defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_IDE_PROC_FS) */
169 169
170static u8 quantize_timing(int timing, int quant) 170static u8 quantize_timing(int timing, int quant)
171{ 171{
@@ -292,55 +292,6 @@ static void cmd64x_tune_drive (ide_drive_t *drive, u8 pio)
292 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio); 292 (void) ide_config_drive_speed(drive, XFER_PIO_0 + pio);
293} 293}
294 294
295static u8 cmd64x_ratemask (ide_drive_t *drive)
296{
297 struct pci_dev *dev = HWIF(drive)->pci_dev;
298 u8 mode = 0;
299
300 switch(dev->device) {
301 case PCI_DEVICE_ID_CMD_649:
302 mode = 3;
303 break;
304 case PCI_DEVICE_ID_CMD_648:
305 mode = 2;
306 break;
307 case PCI_DEVICE_ID_CMD_643:
308 return 0;
309
310 case PCI_DEVICE_ID_CMD_646:
311 {
312 unsigned int class_rev = 0;
313 pci_read_config_dword(dev,
314 PCI_CLASS_REVISION, &class_rev);
315 class_rev &= 0xff;
316 /*
317 * UltraDMA only supported on PCI646U and PCI646U2, which
318 * correspond to revisions 0x03, 0x05 and 0x07 respectively.
319 * Actually, although the CMD tech support people won't
320 * tell me the details, the 0x03 revision cannot support
321 * UDMA correctly without hardware modifications, and even
322 * then it only works with Quantum disks due to some
323 * hold time assumptions in the 646U part which are fixed
324 * in the 646U2.
325 *
326 * So we only do UltraDMA on revision 0x05 and 0x07 chipsets.
327 */
328 switch(class_rev) {
329 case 0x07:
330 case 0x05:
331 return 1;
332 case 0x03:
333 case 0x01:
334 default:
335 return 0;
336 }
337 }
338 }
339 if (!eighty_ninty_three(drive))
340 mode = min(mode, (u8)1);
341 return mode;
342}
343
344static int cmd64x_tune_chipset (ide_drive_t *drive, u8 speed) 295static int cmd64x_tune_chipset (ide_drive_t *drive, u8 speed)
345{ 296{
346 ide_hwif_t *hwif = HWIF(drive); 297 ide_hwif_t *hwif = HWIF(drive);
@@ -348,7 +299,7 @@ static int cmd64x_tune_chipset (ide_drive_t *drive, u8 speed)
348 u8 unit = drive->dn & 0x01; 299 u8 unit = drive->dn & 0x01;
349 u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0; 300 u8 regU = 0, pciU = hwif->channel ? UDIDETCR1 : UDIDETCR0;
350 301
351 speed = ide_rate_filter(cmd64x_ratemask(drive), speed); 302 speed = ide_rate_filter(drive, speed);
352 303
353 if (speed >= XFER_SW_DMA_0) { 304 if (speed >= XFER_SW_DMA_0) {
354 (void) pci_read_config_byte(dev, pciU, &regU); 305 (void) pci_read_config_byte(dev, pciU, &regU);
@@ -401,22 +352,9 @@ static int cmd64x_tune_chipset (ide_drive_t *drive, u8 speed)
401 return ide_config_drive_speed(drive, speed); 352 return ide_config_drive_speed(drive, speed);
402} 353}
403 354
404static int config_chipset_for_dma (ide_drive_t *drive)
405{
406 u8 speed = ide_dma_speed(drive, cmd64x_ratemask(drive));
407
408 if (!speed)
409 return 0;
410
411 if (cmd64x_tune_chipset(drive, speed))
412 return 0;
413
414 return ide_dma_enable(drive);
415}
416
417static int cmd64x_config_drive_for_dma (ide_drive_t *drive) 355static int cmd64x_config_drive_for_dma (ide_drive_t *drive)
418{ 356{
419 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 357 if (ide_tune_dma(drive))
420 return 0; 358 return 0;
421 359
422 if (ide_use_fast_pio(drive)) 360 if (ide_use_fast_pio(drive))
@@ -597,7 +535,7 @@ static unsigned int __devinit init_chipset_cmd64x(struct pci_dev *dev, const cha
597 (void) pci_write_config_byte(dev, UDIDETCR0, 0xf0); 535 (void) pci_write_config_byte(dev, UDIDETCR0, 0xf0);
598#endif /* CONFIG_PPC */ 536#endif /* CONFIG_PPC */
599 537
600#if defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_PROC_FS) 538#if defined(DISPLAY_CMD64X_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
601 539
602 cmd_devs[n_cmd_devs++] = dev; 540 cmd_devs[n_cmd_devs++] = dev;
603 541
@@ -605,7 +543,7 @@ static unsigned int __devinit init_chipset_cmd64x(struct pci_dev *dev, const cha
605 cmd64x_proc = 1; 543 cmd64x_proc = 1;
606 ide_pci_create_host_proc("cmd64x", cmd64x_get_info); 544 ide_pci_create_host_proc("cmd64x", cmd64x_get_info);
607 } 545 }
608#endif /* DISPLAY_CMD64X_TIMINGS && CONFIG_PROC_FS */ 546#endif /* DISPLAY_CMD64X_TIMINGS && CONFIG_IDE_PROC_FS */
609 547
610 return 0; 548 return 0;
611} 549}
@@ -644,15 +582,24 @@ static void __devinit init_hwif_cmd64x(ide_hwif_t *hwif)
644 582
645 hwif->atapi_dma = 1; 583 hwif->atapi_dma = 1;
646 584
647 hwif->ultra_mask = 0x3f; 585 hwif->ultra_mask = hwif->cds->udma_mask;
648 hwif->mwdma_mask = 0x07;
649 586
650 if (dev->device == PCI_DEVICE_ID_CMD_643) 587 /*
651 hwif->ultra_mask = 0x80; 588 * UltraDMA only supported on PCI646U and PCI646U2, which
652 if (dev->device == PCI_DEVICE_ID_CMD_646) 589 * correspond to revisions 0x03, 0x05 and 0x07 respectively.
653 hwif->ultra_mask = (class_rev > 0x04) ? 0x07 : 0x80; 590 * Actually, although the CMD tech support people won't
654 if (dev->device == PCI_DEVICE_ID_CMD_648) 591 * tell me the details, the 0x03 revision cannot support
655 hwif->ultra_mask = 0x1f; 592 * UDMA correctly without hardware modifications, and even
593 * then it only works with Quantum disks due to some
594 * hold time assumptions in the 646U part which are fixed
595 * in the 646U2.
596 *
597 * So we only do UltraDMA on revision 0x05 and 0x07 chipsets.
598 */
599 if (dev->device == PCI_DEVICE_ID_CMD_646 && class_rev < 5)
600 hwif->ultra_mask = 0x00;
601
602 hwif->mwdma_mask = 0x07;
656 603
657 hwif->ide_dma_check = &cmd64x_config_drive_for_dma; 604 hwif->ide_dma_check = &cmd64x_config_drive_for_dma;
658 if (!(hwif->udma_four)) 605 if (!(hwif->udma_four))
@@ -716,6 +663,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
716 .autodma = AUTODMA, 663 .autodma = AUTODMA,
717 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}}, 664 .enablebits = {{0x00,0x00,0x00}, {0x51,0x08,0x08}},
718 .bootable = ON_BOARD, 665 .bootable = ON_BOARD,
666 .udma_mask = 0x00, /* no udma */
719 },{ /* 1 */ 667 },{ /* 1 */
720 .name = "CMD646", 668 .name = "CMD646",
721 .init_setup = init_setup_cmd646, 669 .init_setup = init_setup_cmd646,
@@ -725,6 +673,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
725 .autodma = AUTODMA, 673 .autodma = AUTODMA,
726 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 674 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
727 .bootable = ON_BOARD, 675 .bootable = ON_BOARD,
676 .udma_mask = 0x07, /* udma0-2 */
728 },{ /* 2 */ 677 },{ /* 2 */
729 .name = "CMD648", 678 .name = "CMD648",
730 .init_setup = init_setup_cmd64x, 679 .init_setup = init_setup_cmd64x,
@@ -734,6 +683,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
734 .autodma = AUTODMA, 683 .autodma = AUTODMA,
735 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 684 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
736 .bootable = ON_BOARD, 685 .bootable = ON_BOARD,
686 .udma_mask = 0x1f, /* udma0-4 */
737 },{ /* 3 */ 687 },{ /* 3 */
738 .name = "CMD649", 688 .name = "CMD649",
739 .init_setup = init_setup_cmd64x, 689 .init_setup = init_setup_cmd64x,
@@ -743,6 +693,7 @@ static ide_pci_device_t cmd64x_chipsets[] __devinitdata = {
743 .autodma = AUTODMA, 693 .autodma = AUTODMA,
744 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}}, 694 .enablebits = {{0x51,0x04,0x04}, {0x51,0x08,0x08}},
745 .bootable = ON_BOARD, 695 .bootable = ON_BOARD,
696 .udma_mask = 0x3f, /* udma0-5 */
746 } 697 }
747}; 698};
748 699
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index 400859a839f7..3b88a3a56116 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -213,6 +213,7 @@ static ide_pci_device_t cyrix_chipsets[] __devinitdata = {
213 213
214static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id) 214static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id)
215{ 215{
216 ide_hwif_t *hwif = NULL, *mate = NULL;
216 ata_index_t index; 217 ata_index_t index;
217 ide_pci_device_t *d = &cyrix_chipsets[id->driver_data]; 218 ide_pci_device_t *d = &cyrix_chipsets[id->driver_data];
218 219
@@ -239,10 +240,21 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
239 240
240 ide_pci_setup_ports(dev, d, 14, &index); 241 ide_pci_setup_ports(dev, d, 14, &index);
241 242
242 if((index.b.low & 0xf0) != 0xf0) 243 if ((index.b.low & 0xf0) != 0xf0)
243 probe_hwif_init(&ide_hwifs[index.b.low]); 244 hwif = &ide_hwifs[index.b.low];
244 if((index.b.high & 0xf0) != 0xf0) 245 if ((index.b.high & 0xf0) != 0xf0)
245 probe_hwif_init(&ide_hwifs[index.b.high]); 246 mate = &ide_hwifs[index.b.high];
247
248 if (hwif)
249 probe_hwif_init(hwif);
250 if (mate)
251 probe_hwif_init(mate);
252
253 if (hwif)
254 ide_proc_register_port(hwif);
255 if (mate)
256 ide_proc_register_port(mate);
257
246 return 0; 258 return 0;
247} 259}
248 260
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index b2d7c132ef4b..1eec1f308d16 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * linux/drivers/ide/pci/cs5530.c Version 0.7 Sept 10, 2002 2 * linux/drivers/ide/pci/cs5530.c Version 0.73 Mar 10 2007
3 * 3 *
4 * Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 2000 Andre Hedrick <andre@linux-ide.org>
5 * Ditto of GNU General Public License.
6 *
7 * Copyright (C) 2000 Mark Lord <mlord@pobox.com> 5 * Copyright (C) 2000 Mark Lord <mlord@pobox.com>
6 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
7 *
8 * May be copied or modified under the terms of the GNU General Public License 8 * May be copied or modified under the terms of the GNU General Public License
9 * 9 *
10 * Development of this chipset driver was funded 10 * Development of this chipset driver was funded
@@ -62,6 +62,14 @@ static unsigned int cs5530_pio_timings[2][5] = {
62#define CS5530_BAD_PIO(timings) (((timings)&~0x80000000)==0x0000e132) 62#define CS5530_BAD_PIO(timings) (((timings)&~0x80000000)==0x0000e132)
63#define CS5530_BASEREG(hwif) (((hwif)->dma_base & ~0xf) + ((hwif)->channel ? 0x30 : 0x20)) 63#define CS5530_BASEREG(hwif) (((hwif)->dma_base & ~0xf) + ((hwif)->channel ? 0x30 : 0x20))
64 64
65static void cs5530_tunepio(ide_drive_t *drive, u8 pio)
66{
67 unsigned long basereg = CS5530_BASEREG(drive->hwif);
68 unsigned int format = (inl(basereg + 4) >> 31) & 1;
69
70 outl(cs5530_pio_timings[format][pio], basereg + ((drive->dn & 1)<<3));
71}
72
65/** 73/**
66 * cs5530_tuneproc - select/set PIO modes 74 * cs5530_tuneproc - select/set PIO modes
67 * 75 *
@@ -74,98 +82,78 @@ static unsigned int cs5530_pio_timings[2][5] = {
74 82
75static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autotune" */ 83static void cs5530_tuneproc (ide_drive_t *drive, u8 pio) /* pio=255 means "autotune" */
76{ 84{
77 ide_hwif_t *hwif = HWIF(drive);
78 unsigned int format;
79 unsigned long basereg = CS5530_BASEREG(hwif);
80 static u8 modes[5] = { XFER_PIO_0, XFER_PIO_1, XFER_PIO_2, XFER_PIO_3, XFER_PIO_4};
81
82 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 85 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
83 if (!cs5530_set_xfer_mode(drive, modes[pio])) { 86
84 format = (inl(basereg + 4) >> 31) & 1; 87 if (cs5530_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0)
85 outl(cs5530_pio_timings[format][pio], 88 cs5530_tunepio(drive, pio);
86 basereg+(drive->select.b.unit<<3)); 89}
90
91/**
92 * cs5530_udma_filter - UDMA filter
93 * @drive: drive
94 *
95 * cs5530_udma_filter() does UDMA mask filtering for the given drive
96 * taking into the consideration capabilities of the mate device.
97 *
98 * The CS5530 specifies that two drives sharing a cable cannot mix
99 * UDMA/MDMA. It has to be one or the other, for the pair, though
100 * different timings can still be chosen for each drive. We could
101 * set the appropriate timing bits on the fly, but that might be
102 * a bit confusing. So, for now we statically handle this requirement
103 * by looking at our mate drive to see what it is capable of, before
104 * choosing a mode for our own drive.
105 *
106 * Note: This relies on the fact we never fail from UDMA to MWDMA2
107 * but instead drop to PIO.
108 */
109
110static u8 cs5530_udma_filter(ide_drive_t *drive)
111{
112 ide_hwif_t *hwif = drive->hwif;
113 ide_drive_t *mate = &hwif->drives[(drive->dn & 1) ^ 1];
114 struct hd_driveid *mateid = mate->id;
115 u8 mask = hwif->ultra_mask;
116
117 if (mate->present == 0)
118 goto out;
119
120 if ((mateid->capability & 1) && __ide_dma_bad_drive(mate) == 0) {
121 if ((mateid->field_valid & 4) && (mateid->dma_ultra & 7))
122 goto out;
123 if ((mateid->field_valid & 2) && (mateid->dma_mword & 7))
124 mask = 0;
87 } 125 }
126out:
127 return mask;
88} 128}
89 129
90/** 130/**
91 * cs5530_config_dma - select/set DMA and UDMA modes 131 * cs5530_config_dma - set DMA/UDMA mode
92 * @drive: drive to tune 132 * @drive: drive to tune
93 * 133 *
94 * cs5530_config_dma() handles selection/setting of DMA/UDMA modes 134 * cs5530_config_dma() handles setting of DMA/UDMA mode
95 * for both the chipset and drive. The CS5530 has limitations about 135 * for both the chipset and drive.
96 * mixing DMA/UDMA on the same cable.
97 */ 136 */
98 137
99static int cs5530_config_dma (ide_drive_t *drive) 138static int cs5530_config_dma(ide_drive_t *drive)
100{ 139{
101 int udma_ok = 1, mode = 0; 140 if (ide_tune_dma(drive))
102 ide_hwif_t *hwif = HWIF(drive); 141 return 0;
103 int unit = drive->select.b.unit;
104 ide_drive_t *mate = &hwif->drives[unit^1];
105 struct hd_driveid *id = drive->id;
106 unsigned int reg, timings = 0;
107 unsigned long basereg;
108 142
109 /* 143 return 1;
110 * Default to DMA-off in case we run into trouble here. 144}
111 */
112 hwif->dma_off_quietly(drive);
113 145
114 /* 146static int cs5530_tune_chipset(ide_drive_t *drive, u8 mode)
115 * The CS5530 specifies that two drives sharing a cable cannot 147{
116 * mix UDMA/MDMA. It has to be one or the other, for the pair, 148 unsigned long basereg;
117 * though different timings can still be chosen for each drive. 149 unsigned int reg, timings = 0;
118 * We could set the appropriate timing bits on the fly,
119 * but that might be a bit confusing. So, for now we statically
120 * handle this requirement by looking at our mate drive to see
121 * what it is capable of, before choosing a mode for our own drive.
122 *
123 * Note: This relies on the fact we never fail from UDMA to MWDMA_2
124 * but instead drop to PIO
125 */
126 if (mate->present) {
127 struct hd_driveid *mateid = mate->id;
128 if (mateid && (mateid->capability & 1) &&
129 !__ide_dma_bad_drive(mate)) {
130 if ((mateid->field_valid & 4) &&
131 (mateid->dma_ultra & 7))
132 udma_ok = 1;
133 else if ((mateid->field_valid & 2) &&
134 (mateid->dma_mword & 7))
135 udma_ok = 0;
136 else
137 udma_ok = 1;
138 }
139 }
140 150
141 /* 151 mode = ide_rate_filter(drive, mode);
142 * Now see what the current drive is capable of,
143 * selecting UDMA only if the mate said it was ok.
144 */
145 if (id && (id->capability & 1) && drive->autodma &&
146 !__ide_dma_bad_drive(drive)) {
147 if (udma_ok && (id->field_valid & 4) && (id->dma_ultra & 7)) {
148 if (id->dma_ultra & 4)
149 mode = XFER_UDMA_2;
150 else if (id->dma_ultra & 2)
151 mode = XFER_UDMA_1;
152 else if (id->dma_ultra & 1)
153 mode = XFER_UDMA_0;
154 }
155 if (!mode && (id->field_valid & 2) && (id->dma_mword & 7)) {
156 if (id->dma_mword & 4)
157 mode = XFER_MW_DMA_2;
158 else if (id->dma_mword & 2)
159 mode = XFER_MW_DMA_1;
160 else if (id->dma_mword & 1)
161 mode = XFER_MW_DMA_0;
162 }
163 }
164 152
165 /* 153 /*
166 * Tell the drive to switch to the new mode; abort on failure. 154 * Tell the drive to switch to the new mode; abort on failure.
167 */ 155 */
168 if (!mode || cs5530_set_xfer_mode(drive, mode)) 156 if (cs5530_set_xfer_mode(drive, mode))
169 return 1; /* failure */ 157 return 1; /* failure */
170 158
171 /* 159 /*
@@ -178,14 +166,21 @@ static int cs5530_config_dma (ide_drive_t *drive)
178 case XFER_MW_DMA_0: timings = 0x00077771; break; 166 case XFER_MW_DMA_0: timings = 0x00077771; break;
179 case XFER_MW_DMA_1: timings = 0x00012121; break; 167 case XFER_MW_DMA_1: timings = 0x00012121; break;
180 case XFER_MW_DMA_2: timings = 0x00002020; break; 168 case XFER_MW_DMA_2: timings = 0x00002020; break;
169 case XFER_PIO_4:
170 case XFER_PIO_3:
171 case XFER_PIO_2:
172 case XFER_PIO_1:
173 case XFER_PIO_0:
174 cs5530_tunepio(drive, mode - XFER_PIO_0);
175 return 0;
181 default: 176 default:
182 BUG(); 177 BUG();
183 break; 178 break;
184 } 179 }
185 basereg = CS5530_BASEREG(hwif); 180 basereg = CS5530_BASEREG(drive->hwif);
186 reg = inl(basereg + 4); /* get drive0 config register */ 181 reg = inl(basereg + 4); /* get drive0 config register */
187 timings |= reg & 0x80000000; /* preserve PIO format bit */ 182 timings |= reg & 0x80000000; /* preserve PIO format bit */
188 if (unit == 0) { /* are we configuring drive0? */ 183 if ((drive-> dn & 1) == 0) { /* are we configuring drive0? */
189 outl(timings, basereg + 4); /* write drive0 config register */ 184 outl(timings, basereg + 4); /* write drive0 config register */
190 } else { 185 } else {
191 if (timings & 0x00100000) 186 if (timings & 0x00100000)
@@ -311,6 +306,8 @@ static void __devinit init_hwif_cs5530 (ide_hwif_t *hwif)
311 hwif->serialized = hwif->mate->serialized = 1; 306 hwif->serialized = hwif->mate->serialized = 1;
312 307
313 hwif->tuneproc = &cs5530_tuneproc; 308 hwif->tuneproc = &cs5530_tuneproc;
309 hwif->speedproc = &cs5530_tune_chipset;
310
314 basereg = CS5530_BASEREG(hwif); 311 basereg = CS5530_BASEREG(hwif);
315 d0_timings = inl(basereg + 0); 312 d0_timings = inl(basereg + 0);
316 if (CS5530_BAD_PIO(d0_timings)) { 313 if (CS5530_BAD_PIO(d0_timings)) {
@@ -332,6 +329,7 @@ static void __devinit init_hwif_cs5530 (ide_hwif_t *hwif)
332 hwif->ultra_mask = 0x07; 329 hwif->ultra_mask = 0x07;
333 hwif->mwdma_mask = 0x07; 330 hwif->mwdma_mask = 0x07;
334 331
332 hwif->udma_filter = cs5530_udma_filter;
335 hwif->ide_dma_check = &cs5530_config_dma; 333 hwif->ide_dma_check = &cs5530_config_dma;
336 if (!noautodma) 334 if (!noautodma)
337 hwif->autodma = 1; 335 hwif->autodma = 1;
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 45f43efbf92c..41925c47ef05 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -127,20 +127,6 @@ static void cs5535_set_speed(ide_drive_t *drive, u8 speed)
127 } 127 }
128} 128}
129 129
130static u8 cs5535_ratemask(ide_drive_t *drive)
131{
132 /* eighty93 will return 1 if it's 80core and capable of
133 exceeding udma2, 0 otherwise. we need ratemask to set
134 the max speed and if we can > udma2 then we return 2
135 which selects speed_max as udma4 which is the 5535's max
136 speed, and 1 selects udma2 which is the max for 40c */
137 if (!eighty_ninty_three(drive))
138 return 1;
139
140 return 2;
141}
142
143
144/**** 130/****
145 * cs5535_set_drive - Configure the drive to the new speed 131 * cs5535_set_drive - Configure the drive to the new speed
146 * @drive: Drive to set up 132 * @drive: Drive to set up
@@ -151,7 +137,7 @@ static u8 cs5535_ratemask(ide_drive_t *drive)
151 */ 137 */
152static int cs5535_set_drive(ide_drive_t *drive, u8 speed) 138static int cs5535_set_drive(ide_drive_t *drive, u8 speed)
153{ 139{
154 speed = ide_rate_filter(cs5535_ratemask(drive), speed); 140 speed = ide_rate_filter(drive, speed);
155 ide_config_drive_speed(drive, speed); 141 ide_config_drive_speed(drive, speed);
156 cs5535_set_speed(drive, speed); 142 cs5535_set_speed(drive, speed);
157 143
@@ -178,28 +164,13 @@ static void cs5535_tuneproc(ide_drive_t *drive, u8 xferspeed)
178 cs5535_set_speed(drive, xferspeed); 164 cs5535_set_speed(drive, xferspeed);
179} 165}
180 166
181static int cs5535_config_drive_for_dma(ide_drive_t *drive)
182{
183 u8 speed;
184
185 speed = ide_dma_speed(drive, cs5535_ratemask(drive));
186
187 /* If no DMA speed was available then let dma_check hit pio */
188 if (!speed) {
189 return 0;
190 }
191
192 cs5535_set_drive(drive, speed);
193 return ide_dma_enable(drive);
194}
195
196static int cs5535_dma_check(ide_drive_t *drive) 167static int cs5535_dma_check(ide_drive_t *drive)
197{ 168{
198 u8 speed; 169 u8 speed;
199 170
200 drive->init_speed = 0; 171 drive->init_speed = 0;
201 172
202 if (ide_use_dma(drive) && cs5535_config_drive_for_dma(drive)) 173 if (ide_tune_dma(drive))
203 return 0; 174 return 0;
204 175
205 if (ide_use_fast_pio(drive)) { 176 if (ide_use_fast_pio(drive)) {
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c
index dd7ec37fdeab..46f4a888c037 100644
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/pci/delkin_cb.c
@@ -80,7 +80,7 @@ delkin_cb_probe (struct pci_dev *dev, const struct pci_device_id *id)
80 hw.irq = dev->irq; 80 hw.irq = dev->irq;
81 hw.chipset = ide_pci; /* this enables IRQ sharing */ 81 hw.chipset = ide_pci; /* this enables IRQ sharing */
82 82
83 rc = ide_register_hw_with_fixup(&hw, &hwif, ide_undecoded_slave); 83 rc = ide_register_hw_with_fixup(&hw, 0, &hwif, ide_undecoded_slave);
84 if (rc < 0) { 84 if (rc < 0) {
85 printk(KERN_ERR "delkin_cb: ide_register_hw failed (%d)\n", rc); 85 printk(KERN_ERR "delkin_cb: ide_register_hw failed (%d)\n", rc);
86 pci_disable_device(dev); 86 pci_disable_device(dev);
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index 924eaa3a5708..2c24c3de8846 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -43,15 +43,10 @@
43 43
44#define HPT343_DEBUG_DRIVE_INFO 0 44#define HPT343_DEBUG_DRIVE_INFO 0
45 45
46static u8 hpt34x_ratemask (ide_drive_t *drive)
47{
48 return 1;
49}
50
51static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed) 46static int hpt34x_tune_chipset (ide_drive_t *drive, u8 xferspeed)
52{ 47{
53 struct pci_dev *dev = HWIF(drive)->pci_dev; 48 struct pci_dev *dev = HWIF(drive)->pci_dev;
54 u8 speed = ide_rate_filter(hpt34x_ratemask(drive), xferspeed); 49 u8 speed = ide_rate_filter(drive, xferspeed);
55 u32 reg1= 0, tmp1 = 0, reg2 = 0, tmp2 = 0; 50 u32 reg1= 0, tmp1 = 0, reg2 = 0, tmp2 = 0;
56 u8 hi_speed, lo_speed; 51 u8 hi_speed, lo_speed;
57 52
@@ -89,29 +84,11 @@ static void hpt34x_tune_drive (ide_drive_t *drive, u8 pio)
89 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio)); 84 (void) hpt34x_tune_chipset(drive, (XFER_PIO_0 + pio));
90} 85}
91 86
92/*
93 * This allows the configuration of ide_pci chipset registers
94 * for cards that learn about the drive's UDMA, DMA, PIO capabilities
95 * after the drive is reported by the OS. Initially for designed for
96 * HPT343 UDMA chipset by HighPoint|Triones Technologies, Inc.
97 */
98
99static int config_chipset_for_dma (ide_drive_t *drive)
100{
101 u8 speed = ide_dma_speed(drive, hpt34x_ratemask(drive));
102
103 if (!(speed))
104 return 0;
105
106 (void) hpt34x_tune_chipset(drive, speed);
107 return ide_dma_enable(drive);
108}
109
110static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive) 87static int hpt34x_config_drive_xfer_rate (ide_drive_t *drive)
111{ 88{
112 drive->init_speed = 0; 89 drive->init_speed = 0;
113 90
114 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 91 if (ide_tune_dma(drive))
115#ifndef CONFIG_HPT34X_AUTODMA 92#ifndef CONFIG_HPT34X_AUTODMA
116 return -1; 93 return -1;
117#else 94#else
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index cf9d344d19f8..fcbc5605b38e 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -514,43 +514,31 @@ static int check_in_drive_list(ide_drive_t *drive, const char **list)
514 return 0; 514 return 0;
515} 515}
516 516
517static u8 hpt3xx_ratemask(ide_drive_t *drive)
518{
519 struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev);
520 u8 mode = info->max_mode;
521
522 if (!eighty_ninty_three(drive) && mode)
523 mode = min(mode, (u8)1);
524 return mode;
525}
526
527/* 517/*
528 * Note for the future; the SATA hpt37x we must set 518 * Note for the future; the SATA hpt37x we must set
529 * either PIO or UDMA modes 0,4,5 519 * either PIO or UDMA modes 0,4,5
530 */ 520 */
531 521
532static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed) 522static u8 hpt3xx_udma_filter(ide_drive_t *drive)
533{ 523{
534 struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev); 524 struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev);
535 u8 chip_type = info->chip_type; 525 u8 chip_type = info->chip_type;
536 u8 mode = hpt3xx_ratemask(drive); 526 u8 mode = info->max_mode;
537 527 u8 mask;
538 if (drive->media != ide_disk)
539 return min(speed, (u8)XFER_PIO_4);
540 528
541 switch (mode) { 529 switch (mode) {
542 case 0x04: 530 case 0x04:
543 speed = min_t(u8, speed, XFER_UDMA_6); 531 mask = 0x7f;
544 break; 532 break;
545 case 0x03: 533 case 0x03:
546 speed = min_t(u8, speed, XFER_UDMA_5); 534 mask = 0x3f;
547 if (chip_type >= HPT374) 535 if (chip_type >= HPT374)
548 break; 536 break;
549 if (!check_in_drive_list(drive, bad_ata100_5)) 537 if (!check_in_drive_list(drive, bad_ata100_5))
550 goto check_bad_ata33; 538 goto check_bad_ata33;
551 /* fall thru */ 539 /* fall thru */
552 case 0x02: 540 case 0x02:
553 speed = min_t(u8, speed, XFER_UDMA_4); 541 mask = 0x1f;
554 542
555 /* 543 /*
556 * CHECK ME, Does this need to be changed to HPT374 ?? 544 * CHECK ME, Does this need to be changed to HPT374 ??
@@ -561,13 +549,13 @@ static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed)
561 !check_in_drive_list(drive, bad_ata66_4)) 549 !check_in_drive_list(drive, bad_ata66_4))
562 goto check_bad_ata33; 550 goto check_bad_ata33;
563 551
564 speed = min_t(u8, speed, XFER_UDMA_3); 552 mask = 0x0f;
565 if (HPT366_ALLOW_ATA66_3 && 553 if (HPT366_ALLOW_ATA66_3 &&
566 !check_in_drive_list(drive, bad_ata66_3)) 554 !check_in_drive_list(drive, bad_ata66_3))
567 goto check_bad_ata33; 555 goto check_bad_ata33;
568 /* fall thru */ 556 /* fall thru */
569 case 0x01: 557 case 0x01:
570 speed = min_t(u8, speed, XFER_UDMA_2); 558 mask = 0x07;
571 559
572 check_bad_ata33: 560 check_bad_ata33:
573 if (chip_type >= HPT370A) 561 if (chip_type >= HPT370A)
@@ -577,10 +565,10 @@ static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed)
577 /* fall thru */ 565 /* fall thru */
578 case 0x00: 566 case 0x00:
579 default: 567 default:
580 speed = min_t(u8, speed, XFER_MW_DMA_2); 568 mask = 0x00;
581 break; 569 break;
582 } 570 }
583 return speed; 571 return mask;
584} 572}
585 573
586static u32 get_speed_setting(u8 speed, struct hpt_info *info) 574static u32 get_speed_setting(u8 speed, struct hpt_info *info)
@@ -608,12 +596,19 @@ static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
608 ide_hwif_t *hwif = HWIF(drive); 596 ide_hwif_t *hwif = HWIF(drive);
609 struct pci_dev *dev = hwif->pci_dev; 597 struct pci_dev *dev = hwif->pci_dev;
610 struct hpt_info *info = pci_get_drvdata(dev); 598 struct hpt_info *info = pci_get_drvdata(dev);
611 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 599 u8 speed = ide_rate_filter(drive, xferspeed);
612 u8 itr_addr = drive->dn ? 0x44 : 0x40; 600 u8 itr_addr = drive->dn ? 0x44 : 0x40;
613 u32 itr_mask = speed < XFER_MW_DMA_0 ? 0x30070000 :
614 (speed < XFER_UDMA_0 ? 0xc0070000 : 0xc03800ff);
615 u32 new_itr = get_speed_setting(speed, info);
616 u32 old_itr = 0; 601 u32 old_itr = 0;
602 u32 itr_mask, new_itr;
603
604 /* TODO: move this to ide_rate_filter() [ check ->atapi_dma ] */
605 if (drive->media != ide_disk)
606 speed = min_t(u8, speed, XFER_PIO_4);
607
608 itr_mask = speed < XFER_MW_DMA_0 ? 0x30070000 :
609 (speed < XFER_UDMA_0 ? 0xc0070000 : 0xc03800ff);
610
611 new_itr = get_speed_setting(speed, info);
617 612
618 /* 613 /*
619 * Disable on-chip PIO FIFO/buffer (and PIO MST mode as well) 614 * Disable on-chip PIO FIFO/buffer (and PIO MST mode as well)
@@ -633,12 +628,19 @@ static int hpt37x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
633 ide_hwif_t *hwif = HWIF(drive); 628 ide_hwif_t *hwif = HWIF(drive);
634 struct pci_dev *dev = hwif->pci_dev; 629 struct pci_dev *dev = hwif->pci_dev;
635 struct hpt_info *info = pci_get_drvdata(dev); 630 struct hpt_info *info = pci_get_drvdata(dev);
636 u8 speed = hpt3xx_ratefilter(drive, xferspeed); 631 u8 speed = ide_rate_filter(drive, xferspeed);
637 u8 itr_addr = 0x40 + (drive->dn * 4); 632 u8 itr_addr = 0x40 + (drive->dn * 4);
638 u32 itr_mask = speed < XFER_MW_DMA_0 ? 0x303c0000 :
639 (speed < XFER_UDMA_0 ? 0xc03c0000 : 0xc1c001ff);
640 u32 new_itr = get_speed_setting(speed, info);
641 u32 old_itr = 0; 633 u32 old_itr = 0;
634 u32 itr_mask, new_itr;
635
636 /* TODO: move this to ide_rate_filter() [ check ->atapi_dma ] */
637 if (drive->media != ide_disk)
638 speed = min_t(u8, speed, XFER_PIO_4);
639
640 itr_mask = speed < XFER_MW_DMA_0 ? 0x303c0000 :
641 (speed < XFER_UDMA_0 ? 0xc03c0000 : 0xc1c001ff);
642
643 new_itr = get_speed_setting(speed, info);
642 644
643 pci_read_config_dword(dev, itr_addr, &old_itr); 645 pci_read_config_dword(dev, itr_addr, &old_itr);
644 new_itr = (new_itr & ~itr_mask) | (old_itr & itr_mask); 646 new_itr = (new_itr & ~itr_mask) | (old_itr & itr_mask);
@@ -667,24 +669,6 @@ static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio)
667 (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio); 669 (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio);
668} 670}
669 671
670/*
671 * This allows the configuration of ide_pci chipset registers
672 * for cards that learn about the drive's UDMA, DMA, PIO capabilities
673 * after the drive is reported by the OS. Initially designed for
674 * HPT366 UDMA chipset by HighPoint|Triones Technologies, Inc.
675 *
676 */
677static int config_chipset_for_dma(ide_drive_t *drive)
678{
679 u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive));
680
681 if (!speed)
682 return 0;
683
684 (void) hpt3xx_tune_chipset(drive, speed);
685 return ide_dma_enable(drive);
686}
687
688static int hpt3xx_quirkproc(ide_drive_t *drive) 672static int hpt3xx_quirkproc(ide_drive_t *drive)
689{ 673{
690 struct hd_driveid *id = drive->id; 674 struct hd_driveid *id = drive->id;
@@ -739,7 +723,7 @@ static int hpt366_config_drive_xfer_rate(ide_drive_t *drive)
739{ 723{
740 drive->init_speed = 0; 724 drive->init_speed = 0;
741 725
742 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 726 if (ide_tune_dma(drive))
743 return 0; 727 return 0;
744 728
745 if (ide_use_fast_pio(drive)) 729 if (ide_use_fast_pio(drive))
@@ -1271,6 +1255,7 @@ static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1271 hwif->intrproc = &hpt3xx_intrproc; 1255 hwif->intrproc = &hpt3xx_intrproc;
1272 hwif->maskproc = &hpt3xx_maskproc; 1256 hwif->maskproc = &hpt3xx_maskproc;
1273 hwif->busproc = &hpt3xx_busproc; 1257 hwif->busproc = &hpt3xx_busproc;
1258 hwif->udma_filter = &hpt3xx_udma_filter;
1274 1259
1275 /* 1260 /*
1276 * HPT3xxN chips have some complications: 1261 * HPT3xxN chips have some complications:
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 424f00bb160d..c04a02687b95 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -17,22 +17,6 @@
17 17
18#include <asm/io.h> 18#include <asm/io.h>
19 19
20/*
21 * it8213_ratemask - Compute available modes
22 * @drive: IDE drive
23 *
24 * Compute the available speeds for the devices on the interface. This
25 * is all modes to ATA133 clipped by drive cable setup.
26 */
27
28static u8 it8213_ratemask (ide_drive_t *drive)
29{
30 u8 mode = 4;
31 if (!eighty_ninty_three(drive))
32 mode = min_t(u8, mode, 1);
33 return mode;
34}
35
36/** 20/**
37 * it8213_dma_2_pio - return the PIO mode matching DMA 21 * it8213_dma_2_pio - return the PIO mode matching DMA
38 * @xfer_rate: transfer speed 22 * @xfer_rate: transfer speed
@@ -145,7 +129,7 @@ static int it8213_tune_chipset (ide_drive_t *drive, u8 xferspeed)
145 ide_hwif_t *hwif = HWIF(drive); 129 ide_hwif_t *hwif = HWIF(drive);
146 struct pci_dev *dev = hwif->pci_dev; 130 struct pci_dev *dev = hwif->pci_dev;
147 u8 maslave = 0x40; 131 u8 maslave = 0x40;
148 u8 speed = ide_rate_filter(it8213_ratemask(drive), xferspeed); 132 u8 speed = ide_rate_filter(drive, xferspeed);
149 int a_speed = 3 << (drive->dn * 4); 133 int a_speed = 3 << (drive->dn * 4);
150 int u_flag = 1 << drive->dn; 134 int u_flag = 1 << drive->dn;
151 int v_flag = 0x01 << drive->dn; 135 int v_flag = 0x01 << drive->dn;
@@ -213,25 +197,6 @@ static int it8213_tune_chipset (ide_drive_t *drive, u8 xferspeed)
213 return ide_config_drive_speed(drive, speed); 197 return ide_config_drive_speed(drive, speed);
214} 198}
215 199
216/*
217 * config_chipset_for_dma - configure for DMA
218 * @drive: drive to configure
219 *
220 * Called by the IDE layer when it wants the timings set up.
221 */
222
223static int config_chipset_for_dma (ide_drive_t *drive)
224{
225 u8 speed = ide_dma_speed(drive, it8213_ratemask(drive));
226
227 if (!speed)
228 return 0;
229
230 it8213_tune_chipset(drive, speed);
231
232 return ide_dma_enable(drive);
233}
234
235/** 200/**
236 * it8213_configure_drive_for_dma - set up for DMA transfers 201 * it8213_configure_drive_for_dma - set up for DMA transfers
237 * @drive: drive we are going to set up 202 * @drive: drive we are going to set up
@@ -246,7 +211,7 @@ static int it8213_config_drive_for_dma (ide_drive_t *drive)
246{ 211{
247 u8 pio; 212 u8 pio;
248 213
249 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 214 if (ide_tune_dma(drive))
250 return 0; 215 return 0;
251 216
252 pio = ide_get_best_pio_mode(drive, 255, 4, NULL); 217 pio = ide_get_best_pio_mode(drive, 255, 4, NULL);
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index 4e1254813ee0..5faaff87d580 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -229,22 +229,6 @@ static void it821x_clock_strategy(ide_drive_t *drive)
229} 229}
230 230
231/** 231/**
232 * it821x_ratemask - Compute available modes
233 * @drive: IDE drive
234 *
235 * Compute the available speeds for the devices on the interface. This
236 * is all modes to ATA133 clipped by drive cable setup.
237 */
238
239static u8 it821x_ratemask (ide_drive_t *drive)
240{
241 u8 mode = 4;
242 if (!eighty_ninty_three(drive))
243 mode = min(mode, (u8)1);
244 return mode;
245}
246
247/**
248 * it821x_tunepio - tune a drive 232 * it821x_tunepio - tune a drive
249 * @drive: drive to tune 233 * @drive: drive to tune
250 * @pio: the desired PIO mode 234 * @pio: the desired PIO mode
@@ -438,7 +422,7 @@ static int it821x_tune_chipset (ide_drive_t *drive, byte xferspeed)
438 422
439 ide_hwif_t *hwif = drive->hwif; 423 ide_hwif_t *hwif = drive->hwif;
440 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 424 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
441 u8 speed = ide_rate_filter(it821x_ratemask(drive), xferspeed); 425 u8 speed = ide_rate_filter(drive, xferspeed);
442 426
443 switch (speed) { 427 switch (speed) {
444 case XFER_PIO_4: 428 case XFER_PIO_4:
@@ -480,25 +464,6 @@ static int it821x_tune_chipset (ide_drive_t *drive, byte xferspeed)
480} 464}
481 465
482/** 466/**
483 * config_chipset_for_dma - configure for DMA
484 * @drive: drive to configure
485 *
486 * Called by the IDE layer when it wants the timings set up.
487 */
488
489static int config_chipset_for_dma (ide_drive_t *drive)
490{
491 u8 speed = ide_dma_speed(drive, it821x_ratemask(drive));
492
493 if (speed == 0)
494 return 0;
495
496 it821x_tune_chipset(drive, speed);
497
498 return ide_dma_enable(drive);
499}
500
501/**
502 * it821x_configure_drive_for_dma - set up for DMA transfers 467 * it821x_configure_drive_for_dma - set up for DMA transfers
503 * @drive: drive we are going to set up 468 * @drive: drive we are going to set up
504 * 469 *
@@ -510,7 +475,7 @@ static int config_chipset_for_dma (ide_drive_t *drive)
510 475
511static int it821x_config_drive_for_dma (ide_drive_t *drive) 476static int it821x_config_drive_for_dma (ide_drive_t *drive)
512{ 477{
513 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 478 if (ide_tune_dma(drive))
514 return 0; 479 return 0;
515 480
516 it821x_tuneproc(drive, 255); 481 it821x_tuneproc(drive, 255);
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index be4fc96c29e0..76ed25147229 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -22,22 +22,6 @@ typedef enum {
22} port_type; 22} port_type;
23 23
24/** 24/**
25 * jmicron_ratemask - Compute available modes
26 * @drive: IDE drive
27 *
28 * Compute the available speeds for the devices on the interface. This
29 * is all modes to ATA133 clipped by drive cable setup.
30 */
31
32static u8 jmicron_ratemask(ide_drive_t *drive)
33{
34 u8 mode = 4;
35 if (!eighty_ninty_three(drive))
36 mode = min(mode, (u8)1);
37 return mode;
38}
39
40/**
41 * ata66_jmicron - Cable check 25 * ata66_jmicron - Cable check
42 * @hwif: IDE port 26 * @hwif: IDE port
43 * 27 *
@@ -129,32 +113,12 @@ static void config_jmicron_chipset_for_pio (ide_drive_t *drive, byte set_speed)
129 113
130static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed) 114static int jmicron_tune_chipset (ide_drive_t *drive, byte xferspeed)
131{ 115{
132 116 u8 speed = ide_rate_filter(drive, xferspeed);
133 u8 speed = ide_rate_filter(jmicron_ratemask(drive), xferspeed);
134 117
135 return ide_config_drive_speed(drive, speed); 118 return ide_config_drive_speed(drive, speed);
136} 119}
137 120
138/** 121/**
139 * config_chipset_for_dma - configure for DMA
140 * @drive: drive to configure
141 *
142 * As the JMicron snoops for timings all we actually need to do is
143 * make sure we don't set an invalid mode.
144 */
145
146static int config_chipset_for_dma (ide_drive_t *drive)
147{
148 u8 speed = ide_dma_speed(drive, jmicron_ratemask(drive));
149
150 if (!speed)
151 return 0;
152
153 jmicron_tune_chipset(drive, speed);
154 return ide_dma_enable(drive);
155}
156
157/**
158 * jmicron_configure_drive_for_dma - set up for DMA transfers 122 * jmicron_configure_drive_for_dma - set up for DMA transfers
159 * @drive: drive we are going to set up 123 * @drive: drive we are going to set up
160 * 124 *
@@ -164,7 +128,7 @@ static int config_chipset_for_dma (ide_drive_t *drive)
164 128
165static int jmicron_config_drive_for_dma (ide_drive_t *drive) 129static int jmicron_config_drive_for_dma (ide_drive_t *drive)
166{ 130{
167 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 131 if (ide_tune_dma(drive))
168 return 0; 132 return 0;
169 133
170 config_jmicron_chipset_for_pio(drive, 1); 134 config_jmicron_chipset_for_pio(drive, 1);
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 2da5cbb53566..cc0bfdcf1f19 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -37,8 +37,6 @@
37#include <asm/pci-bridge.h> 37#include <asm/pci-bridge.h>
38#endif 38#endif
39 39
40#define PDC202_DEBUG_CABLE 0
41
42#undef DEBUG 40#undef DEBUG
43 41
44#ifdef DEBUG 42#ifdef DEBUG
@@ -82,16 +80,6 @@ static u8 max_dma_rate(struct pci_dev *pdev)
82 return mode; 80 return mode;
83} 81}
84 82
85static u8 pdcnew_ratemask(ide_drive_t *drive)
86{
87 u8 mode = max_dma_rate(HWIF(drive)->pci_dev);
88
89 if (!eighty_ninty_three(drive))
90 mode = min_t(u8, mode, 1);
91
92 return mode;
93}
94
95/** 83/**
96 * get_indexed_reg - Get indexed register 84 * get_indexed_reg - Get indexed register
97 * @hwif: for the port address 85 * @hwif: for the port address
@@ -164,7 +152,7 @@ static int pdcnew_tune_chipset(ide_drive_t *drive, u8 speed)
164 u8 adj = (drive->dn & 1) ? 0x08 : 0x00; 152 u8 adj = (drive->dn & 1) ? 0x08 : 0x00;
165 int err; 153 int err;
166 154
167 speed = ide_rate_filter(pdcnew_ratemask(drive), speed); 155 speed = ide_rate_filter(drive, speed);
168 156
169 /* 157 /*
170 * Issue SETFEATURES_XFER to the drive first. PDC202xx hardware will 158 * Issue SETFEATURES_XFER to the drive first. PDC202xx hardware will
@@ -240,47 +228,11 @@ static u8 pdcnew_cable_detect(ide_hwif_t *hwif)
240 return get_indexed_reg(hwif, 0x0b) & 0x04; 228 return get_indexed_reg(hwif, 0x0b) & 0x04;
241} 229}
242 230
243static int config_chipset_for_dma(ide_drive_t *drive)
244{
245 struct hd_driveid *id = drive->id;
246 ide_hwif_t *hwif = HWIF(drive);
247 u8 ultra_66 = (id->dma_ultra & 0x0078) ? 1 : 0;
248 u8 cable = pdcnew_cable_detect(hwif);
249 u8 speed;
250
251 if (ultra_66 && cable) {
252 printk(KERN_WARNING "Warning: %s channel "
253 "requires an 80-pin cable for operation.\n",
254 hwif->channel ? "Secondary" : "Primary");
255 printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name);
256 }
257
258 if (id->capability & 4) {
259 /*
260 * Set IORDY_EN & PREFETCH_EN (this seems to have
261 * NO real effect since this register is reloaded
262 * by hardware when the transfer mode is selected)
263 */
264 u8 tmp, adj = (drive->dn & 1) ? 0x08 : 0x00;
265
266 tmp = get_indexed_reg(hwif, 0x13 + adj);
267 set_indexed_reg(hwif, 0x13 + adj, tmp | 0x03);
268 }
269
270 speed = ide_dma_speed(drive, pdcnew_ratemask(drive));
271
272 if (!speed)
273 return 0;
274
275 (void) hwif->speedproc(drive, speed);
276 return ide_dma_enable(drive);
277}
278
279static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive) 231static int pdcnew_config_drive_xfer_rate(ide_drive_t *drive)
280{ 232{
281 drive->init_speed = 0; 233 drive->init_speed = 0;
282 234
283 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 235 if (ide_tune_dma(drive))
284 return 0; 236 return 0;
285 237
286 if (ide_use_fast_pio(drive)) 238 if (ide_use_fast_pio(drive))
@@ -395,7 +347,7 @@ static void __devinit apple_kiwi_init(struct pci_dev *pdev)
395 unsigned int class_rev = 0; 347 unsigned int class_rev = 0;
396 u8 conf; 348 u8 conf;
397 349
398 if (np == NULL || !device_is_compatible(np, "kiwi-root")) 350 if (np == NULL || !of_device_is_compatible(np, "kiwi-root"))
399 return; 351 return;
400 352
401 pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class_rev); 353 pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class_rev);
@@ -543,7 +495,8 @@ static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif)
543 hwif->drives[0].autotune = hwif->drives[1].autotune = 1; 495 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
544 496
545 hwif->atapi_dma = 1; 497 hwif->atapi_dma = 1;
546 hwif->ultra_mask = 0x7f; 498
499 hwif->ultra_mask = hwif->cds->udma_mask;
547 hwif->mwdma_mask = 0x07; 500 hwif->mwdma_mask = 0x07;
548 501
549 hwif->err_stops_fifo = 1; 502 hwif->err_stops_fifo = 1;
@@ -556,11 +509,6 @@ static void __devinit init_hwif_pdc202new(ide_hwif_t *hwif)
556 if (!noautodma) 509 if (!noautodma)
557 hwif->autodma = 1; 510 hwif->autodma = 1;
558 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma; 511 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
559
560#if PDC202_DEBUG_CABLE
561 printk(KERN_DEBUG "%s: %s-pin cable\n",
562 hwif->name, hwif->udma_four ? "80" : "40");
563#endif /* PDC202_DEBUG_CABLE */
564} 512}
565 513
566static int __devinit init_setup_pdcnew(struct pci_dev *dev, ide_pci_device_t *d) 514static int __devinit init_setup_pdcnew(struct pci_dev *dev, ide_pci_device_t *d)
@@ -619,6 +567,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
619 .channels = 2, 567 .channels = 2,
620 .autodma = AUTODMA, 568 .autodma = AUTODMA,
621 .bootable = OFF_BOARD, 569 .bootable = OFF_BOARD,
570 .udma_mask = 0x3f, /* udma0-5 */
622 },{ /* 1 */ 571 },{ /* 1 */
623 .name = "PDC20269", 572 .name = "PDC20269",
624 .init_setup = init_setup_pdcnew, 573 .init_setup = init_setup_pdcnew,
@@ -627,6 +576,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
627 .channels = 2, 576 .channels = 2,
628 .autodma = AUTODMA, 577 .autodma = AUTODMA,
629 .bootable = OFF_BOARD, 578 .bootable = OFF_BOARD,
579 .udma_mask = 0x7f, /* udma0-6*/
630 },{ /* 2 */ 580 },{ /* 2 */
631 .name = "PDC20270", 581 .name = "PDC20270",
632 .init_setup = init_setup_pdc20270, 582 .init_setup = init_setup_pdc20270,
@@ -635,6 +585,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
635 .channels = 2, 585 .channels = 2,
636 .autodma = AUTODMA, 586 .autodma = AUTODMA,
637 .bootable = OFF_BOARD, 587 .bootable = OFF_BOARD,
588 .udma_mask = 0x3f, /* udma0-5 */
638 },{ /* 3 */ 589 },{ /* 3 */
639 .name = "PDC20271", 590 .name = "PDC20271",
640 .init_setup = init_setup_pdcnew, 591 .init_setup = init_setup_pdcnew,
@@ -643,6 +594,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
643 .channels = 2, 594 .channels = 2,
644 .autodma = AUTODMA, 595 .autodma = AUTODMA,
645 .bootable = OFF_BOARD, 596 .bootable = OFF_BOARD,
597 .udma_mask = 0x7f, /* udma0-6*/
646 },{ /* 4 */ 598 },{ /* 4 */
647 .name = "PDC20275", 599 .name = "PDC20275",
648 .init_setup = init_setup_pdcnew, 600 .init_setup = init_setup_pdcnew,
@@ -651,6 +603,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
651 .channels = 2, 603 .channels = 2,
652 .autodma = AUTODMA, 604 .autodma = AUTODMA,
653 .bootable = OFF_BOARD, 605 .bootable = OFF_BOARD,
606 .udma_mask = 0x7f, /* udma0-6*/
654 },{ /* 5 */ 607 },{ /* 5 */
655 .name = "PDC20276", 608 .name = "PDC20276",
656 .init_setup = init_setup_pdc20276, 609 .init_setup = init_setup_pdc20276,
@@ -659,6 +612,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
659 .channels = 2, 612 .channels = 2,
660 .autodma = AUTODMA, 613 .autodma = AUTODMA,
661 .bootable = OFF_BOARD, 614 .bootable = OFF_BOARD,
615 .udma_mask = 0x7f, /* udma0-6*/
662 },{ /* 6 */ 616 },{ /* 6 */
663 .name = "PDC20277", 617 .name = "PDC20277",
664 .init_setup = init_setup_pdcnew, 618 .init_setup = init_setup_pdcnew,
@@ -667,6 +621,7 @@ static ide_pci_device_t pdcnew_chipsets[] __devinitdata = {
667 .channels = 2, 621 .channels = 2,
668 .autodma = AUTODMA, 622 .autodma = AUTODMA,
669 .bootable = OFF_BOARD, 623 .bootable = OFF_BOARD,
624 .udma_mask = 0x7f, /* udma0-6*/
670 } 625 }
671}; 626};
672 627
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index a7a639fe1eaf..23844687deea 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -1,8 +1,9 @@
1/* 1/*
2 * linux/drivers/ide/pci/pdc202xx_old.c Version 0.36 Sept 11, 2002 2 * linux/drivers/ide/pci/pdc202xx_old.c Version 0.50 Mar 3, 2007
3 * 3 *
4 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 1998-2002 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2006-2007 MontaVista Software, Inc. 5 * Copyright (C) 2006-2007 MontaVista Software, Inc.
6 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
6 * 7 *
7 * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this 8 * Promise Ultra33 cards with BIOS v1.20 through 1.28 will need this
8 * compiled into the kernel if you have more than one card installed. 9 * compiled into the kernel if you have more than one card installed.
@@ -46,7 +47,6 @@
46#include <asm/io.h> 47#include <asm/io.h>
47#include <asm/irq.h> 48#include <asm/irq.h>
48 49
49#define PDC202_DEBUG_CABLE 0
50#define PDC202XX_DEBUG_DRIVE_INFO 0 50#define PDC202XX_DEBUG_DRIVE_INFO 0
51 51
52static const char *pdc_quirk_drives[] = { 52static const char *pdc_quirk_drives[] = {
@@ -61,122 +61,34 @@ static const char *pdc_quirk_drives[] = {
61 NULL 61 NULL
62}; 62};
63 63
64/* A Register */ 64static void pdc_old_disable_66MHz_clock(ide_hwif_t *);
65#define SYNC_ERRDY_EN 0xC0
66
67#define SYNC_IN 0x80 /* control bit, different for master vs. slave drives */
68#define ERRDY_EN 0x40 /* control bit, different for master vs. slave drives */
69#define IORDY_EN 0x20 /* PIO: IOREADY */
70#define PREFETCH_EN 0x10 /* PIO: PREFETCH */
71
72#define PA3 0x08 /* PIO"A" timing */
73#define PA2 0x04 /* PIO"A" timing */
74#define PA1 0x02 /* PIO"A" timing */
75#define PA0 0x01 /* PIO"A" timing */
76
77/* B Register */
78
79#define MB2 0x80 /* DMA"B" timing */
80#define MB1 0x40 /* DMA"B" timing */
81#define MB0 0x20 /* DMA"B" timing */
82
83#define PB4 0x10 /* PIO_FORCE 1:0 */
84
85#define PB3 0x08 /* PIO"B" timing */ /* PIO flow Control mode */
86#define PB2 0x04 /* PIO"B" timing */ /* PIO 4 */
87#define PB1 0x02 /* PIO"B" timing */ /* PIO 3 half */
88#define PB0 0x01 /* PIO"B" timing */ /* PIO 3 other half */
89
90/* C Register */
91#define IORDYp_NO_SPEED 0x4F
92#define SPEED_DIS 0x0F
93
94#define DMARQp 0x80
95#define IORDYp 0x40
96#define DMAR_EN 0x20
97#define DMAW_EN 0x10
98
99#define MC3 0x08 /* DMA"C" timing */
100#define MC2 0x04 /* DMA"C" timing */
101#define MC1 0x02 /* DMA"C" timing */
102#define MC0 0x01 /* DMA"C" timing */
103
104static u8 pdc202xx_ratemask (ide_drive_t *drive)
105{
106 u8 mode;
107
108 switch(HWIF(drive)->pci_dev->device) {
109 case PCI_DEVICE_ID_PROMISE_20267:
110 case PCI_DEVICE_ID_PROMISE_20265:
111 mode = 3;
112 break;
113 case PCI_DEVICE_ID_PROMISE_20263:
114 case PCI_DEVICE_ID_PROMISE_20262:
115 mode = 2;
116 break;
117 case PCI_DEVICE_ID_PROMISE_20246:
118 return 1;
119 default:
120 return 0;
121 }
122 if (!eighty_ninty_three(drive))
123 mode = min(mode, (u8)1);
124 return mode;
125}
126 65
127static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed) 66static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
128{ 67{
129 ide_hwif_t *hwif = HWIF(drive); 68 ide_hwif_t *hwif = HWIF(drive);
130 struct pci_dev *dev = hwif->pci_dev; 69 struct pci_dev *dev = hwif->pci_dev;
131 u8 drive_pci = 0x60 + (drive->dn << 2); 70 u8 drive_pci = 0x60 + (drive->dn << 2);
132 u8 speed = ide_rate_filter(pdc202xx_ratemask(drive), xferspeed); 71 u8 speed = ide_rate_filter(drive, xferspeed);
133 72
134 u32 drive_conf; 73 u8 AP = 0, BP = 0, CP = 0;
135 u8 AP, BP, CP, DP;
136 u8 TA = 0, TB = 0, TC = 0; 74 u8 TA = 0, TB = 0, TC = 0;
137 75
138 if (drive->media != ide_disk && 76#if PDC202XX_DEBUG_DRIVE_INFO
139 drive->media != ide_cdrom && speed < XFER_SW_DMA_0) 77 u32 drive_conf = 0;
140 return -1;
141
142 pci_read_config_dword(dev, drive_pci, &drive_conf); 78 pci_read_config_dword(dev, drive_pci, &drive_conf);
143 pci_read_config_byte(dev, (drive_pci), &AP); 79#endif
144 pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
145 pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
146 pci_read_config_byte(dev, (drive_pci)|0x03, &DP);
147
148 if (speed < XFER_SW_DMA_0) {
149 if ((AP & 0x0F) || (BP & 0x07)) {
150 /* clear PIO modes of lower 8421 bits of A Register */
151 pci_write_config_byte(dev, (drive_pci), AP &~0x0F);
152 pci_read_config_byte(dev, (drive_pci), &AP);
153 80
154 /* clear PIO modes of lower 421 bits of B Register */ 81 /*
155 pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0x07); 82 * TODO: do this once per channel
156 pci_read_config_byte(dev, (drive_pci)|0x01, &BP); 83 */
157 84 if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
158 pci_read_config_byte(dev, (drive_pci), &AP); 85 pdc_old_disable_66MHz_clock(hwif);
159 pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
160 }
161 } else {
162 if ((BP & 0xF0) && (CP & 0x0F)) {
163 /* clear DMA modes of upper 842 bits of B Register */
164 /* clear PIO forced mode upper 1 bit of B Register */
165 pci_write_config_byte(dev, (drive_pci)|0x01, BP &~0xF0);
166 pci_read_config_byte(dev, (drive_pci)|0x01, &BP);
167
168 /* clear DMA modes of lower 8421 bits of C Register */
169 pci_write_config_byte(dev, (drive_pci)|0x02, CP &~0x0F);
170 pci_read_config_byte(dev, (drive_pci)|0x02, &CP);
171 }
172 }
173 86
174 pci_read_config_byte(dev, (drive_pci), &AP); 87 pci_read_config_byte(dev, drive_pci, &AP);
175 pci_read_config_byte(dev, (drive_pci)|0x01, &BP); 88 pci_read_config_byte(dev, drive_pci + 1, &BP);
176 pci_read_config_byte(dev, (drive_pci)|0x02, &CP); 89 pci_read_config_byte(dev, drive_pci + 2, &CP);
177 90
178 switch(speed) { 91 switch(speed) {
179 case XFER_UDMA_6: speed = XFER_UDMA_5;
180 case XFER_UDMA_5: 92 case XFER_UDMA_5:
181 case XFER_UDMA_4: TB = 0x20; TC = 0x01; break; 93 case XFER_UDMA_4: TB = 0x20; TC = 0x01; break;
182 case XFER_UDMA_2: TB = 0x20; TC = 0x01; break; 94 case XFER_UDMA_2: TB = 0x20; TC = 0x01; break;
@@ -185,7 +97,7 @@ static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
185 case XFER_UDMA_0: 97 case XFER_UDMA_0:
186 case XFER_MW_DMA_2: TB = 0x60; TC = 0x03; break; 98 case XFER_MW_DMA_2: TB = 0x60; TC = 0x03; break;
187 case XFER_MW_DMA_1: TB = 0x60; TC = 0x04; break; 99 case XFER_MW_DMA_1: TB = 0x60; TC = 0x04; break;
188 case XFER_MW_DMA_0: 100 case XFER_MW_DMA_0: TB = 0xE0; TC = 0x0F; break;
189 case XFER_SW_DMA_2: TB = 0x60; TC = 0x05; break; 101 case XFER_SW_DMA_2: TB = 0x60; TC = 0x05; break;
190 case XFER_SW_DMA_1: TB = 0x80; TC = 0x06; break; 102 case XFER_SW_DMA_1: TB = 0x80; TC = 0x06; break;
191 case XFER_SW_DMA_0: TB = 0xC0; TC = 0x0B; break; 103 case XFER_SW_DMA_0: TB = 0xC0; TC = 0x0B; break;
@@ -198,25 +110,39 @@ static int pdc202xx_tune_chipset (ide_drive_t *drive, u8 xferspeed)
198 } 110 }
199 111
200 if (speed < XFER_SW_DMA_0) { 112 if (speed < XFER_SW_DMA_0) {
201 pci_write_config_byte(dev, (drive_pci), AP|TA); 113 /*
202 pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB); 114 * preserve SYNC_INT / ERDDY_EN bits while clearing
115 * Prefetch_EN / IORDY_EN / PA[3:0] bits of register A
116 */
117 AP &= ~0x3f;
118 if (drive->id->capability & 4)
119 AP |= 0x20; /* set IORDY_EN bit */
120 if (drive->media == ide_disk)
121 AP |= 0x10; /* set Prefetch_EN bit */
122 /* clear PB[4:0] bits of register B */
123 BP &= ~0x1f;
124 pci_write_config_byte(dev, drive_pci, AP | TA);
125 pci_write_config_byte(dev, drive_pci + 1, BP | TB);
203 } else { 126 } else {
204 pci_write_config_byte(dev, (drive_pci)|0x01, BP|TB); 127 /* clear MB[2:0] bits of register B */
205 pci_write_config_byte(dev, (drive_pci)|0x02, CP|TC); 128 BP &= ~0xe0;
129 /* clear MC[3:0] bits of register C */
130 CP &= ~0x0f;
131 pci_write_config_byte(dev, drive_pci + 1, BP | TB);
132 pci_write_config_byte(dev, drive_pci + 2, CP | TC);
206 } 133 }
207 134
208#if PDC202XX_DEBUG_DRIVE_INFO 135#if PDC202XX_DEBUG_DRIVE_INFO
209 printk(KERN_DEBUG "%s: %s drive%d 0x%08x ", 136 printk(KERN_DEBUG "%s: %s drive%d 0x%08x ",
210 drive->name, ide_xfer_verbose(speed), 137 drive->name, ide_xfer_verbose(speed),
211 drive->dn, drive_conf); 138 drive->dn, drive_conf);
212 pci_read_config_dword(dev, drive_pci, &drive_conf); 139 pci_read_config_dword(dev, drive_pci, &drive_conf);
213 printk("0x%08x\n", drive_conf); 140 printk("0x%08x\n", drive_conf);
214#endif /* PDC202XX_DEBUG_DRIVE_INFO */ 141#endif
215 142
216 return (ide_config_drive_speed(drive, speed)); 143 return ide_config_drive_speed(drive, speed);
217} 144}
218 145
219
220static void pdc202xx_tune_drive(ide_drive_t *drive, u8 pio) 146static void pdc202xx_tune_drive(ide_drive_t *drive, u8 pio)
221{ 147{
222 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 148 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
@@ -234,6 +160,8 @@ static u8 pdc202xx_old_cable_detect (ide_hwif_t *hwif)
234 * Set the control register to use the 66MHz system 160 * Set the control register to use the 66MHz system
235 * clock for UDMA 3/4/5 mode operation when necessary. 161 * clock for UDMA 3/4/5 mode operation when necessary.
236 * 162 *
163 * FIXME: this register is shared by both channels, some locking is needed
164 *
237 * It may also be possible to leave the 66MHz clock on 165 * It may also be possible to leave the 66MHz clock on
238 * and readjust the timing parameters. 166 * and readjust the timing parameters.
239 */ 167 */
@@ -253,78 +181,11 @@ static void pdc_old_disable_66MHz_clock(ide_hwif_t *hwif)
253 outb(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg); 181 outb(clock & ~(hwif->channel ? 0x08 : 0x02), clock_reg);
254} 182}
255 183
256static int config_chipset_for_dma (ide_drive_t *drive)
257{
258 struct hd_driveid *id = drive->id;
259 ide_hwif_t *hwif = HWIF(drive);
260 struct pci_dev *dev = hwif->pci_dev;
261 u32 drive_conf = 0;
262 u8 drive_pci = 0x60 + (drive->dn << 2);
263 u8 test1 = 0, test2 = 0, speed = -1;
264 u8 AP = 0, cable = 0;
265
266 u8 ultra_66 = ((id->dma_ultra & 0x0010) ||
267 (id->dma_ultra & 0x0008)) ? 1 : 0;
268
269 if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
270 cable = pdc202xx_old_cable_detect(hwif);
271 else
272 ultra_66 = 0;
273
274 if (ultra_66 && cable) {
275 printk(KERN_WARNING "Warning: %s channel requires an 80-pin cable for operation.\n", hwif->channel ? "Secondary":"Primary");
276 printk(KERN_WARNING "%s reduced to Ultra33 mode.\n", drive->name);
277 }
278
279 if (dev->device != PCI_DEVICE_ID_PROMISE_20246)
280 pdc_old_disable_66MHz_clock(drive->hwif);
281
282 drive_pci = 0x60 + (drive->dn << 2);
283 pci_read_config_dword(dev, drive_pci, &drive_conf);
284 if ((drive_conf != 0x004ff304) && (drive_conf != 0x004ff3c4))
285 goto chipset_is_set;
286
287 pci_read_config_byte(dev, drive_pci, &test1);
288 if (!(test1 & SYNC_ERRDY_EN)) {
289 if (drive->select.b.unit & 0x01) {
290 pci_read_config_byte(dev, drive_pci - 4, &test2);
291 if ((test2 & SYNC_ERRDY_EN) &&
292 !(test1 & SYNC_ERRDY_EN)) {
293 pci_write_config_byte(dev, drive_pci,
294 test1|SYNC_ERRDY_EN);
295 }
296 } else {
297 pci_write_config_byte(dev, drive_pci,
298 test1|SYNC_ERRDY_EN);
299 }
300 }
301
302chipset_is_set:
303
304 pci_read_config_byte(dev, (drive_pci), &AP);
305 if (id->capability & 4) /* IORDY_EN */
306 pci_write_config_byte(dev, (drive_pci), AP|IORDY_EN);
307 pci_read_config_byte(dev, (drive_pci), &AP);
308 if (drive->media == ide_disk) /* PREFETCH_EN */
309 pci_write_config_byte(dev, (drive_pci), AP|PREFETCH_EN);
310
311 speed = ide_dma_speed(drive, pdc202xx_ratemask(drive));
312
313 if (!(speed)) {
314 /* restore original pci-config space */
315 pci_write_config_dword(dev, drive_pci, drive_conf);
316 return 0;
317 }
318
319 (void) hwif->speedproc(drive, speed);
320 return ide_dma_enable(drive);
321}
322
323static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive) 184static int pdc202xx_config_drive_xfer_rate (ide_drive_t *drive)
324{ 185{
325 drive->init_speed = 0; 186 drive->init_speed = 0;
326 187
327 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 188 if (ide_tune_dma(drive))
328 return 0; 189 return 0;
329 190
330 if (ide_use_fast_pio(drive)) 191 if (ide_use_fast_pio(drive))
@@ -478,7 +339,7 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
478 339
479 hwif->drives[0].autotune = hwif->drives[1].autotune = 1; 340 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
480 341
481 hwif->ultra_mask = 0x3f; 342 hwif->ultra_mask = hwif->cds->udma_mask;
482 hwif->mwdma_mask = 0x07; 343 hwif->mwdma_mask = 0x07;
483 hwif->swdma_mask = 0x07; 344 hwif->swdma_mask = 0x07;
484 hwif->atapi_dma = 1; 345 hwif->atapi_dma = 1;
@@ -500,10 +361,6 @@ static void __devinit init_hwif_pdc202xx(ide_hwif_t *hwif)
500 if (!noautodma) 361 if (!noautodma)
501 hwif->autodma = 1; 362 hwif->autodma = 1;
502 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma; 363 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
503#if PDC202_DEBUG_CABLE
504 printk(KERN_DEBUG "%s: %s-pin cable\n",
505 hwif->name, hwif->udma_four ? "80" : "40");
506#endif /* PDC202_DEBUG_CABLE */
507} 364}
508 365
509static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase) 366static void __devinit init_dma_pdc202xx(ide_hwif_t *hwif, unsigned long dmabase)
@@ -587,6 +444,7 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
587 .autodma = AUTODMA, 444 .autodma = AUTODMA,
588 .bootable = OFF_BOARD, 445 .bootable = OFF_BOARD,
589 .extra = 16, 446 .extra = 16,
447 .udma_mask = 0x07, /* udma0-2 */
590 },{ /* 1 */ 448 },{ /* 1 */
591 .name = "PDC20262", 449 .name = "PDC20262",
592 .init_setup = init_setup_pdc202ata4, 450 .init_setup = init_setup_pdc202ata4,
@@ -597,6 +455,7 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
597 .autodma = AUTODMA, 455 .autodma = AUTODMA,
598 .bootable = OFF_BOARD, 456 .bootable = OFF_BOARD,
599 .extra = 48, 457 .extra = 48,
458 .udma_mask = 0x1f, /* udma0-4 */
600 },{ /* 2 */ 459 },{ /* 2 */
601 .name = "PDC20263", 460 .name = "PDC20263",
602 .init_setup = init_setup_pdc202ata4, 461 .init_setup = init_setup_pdc202ata4,
@@ -607,6 +466,7 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
607 .autodma = AUTODMA, 466 .autodma = AUTODMA,
608 .bootable = OFF_BOARD, 467 .bootable = OFF_BOARD,
609 .extra = 48, 468 .extra = 48,
469 .udma_mask = 0x1f, /* udma0-4 */
610 },{ /* 3 */ 470 },{ /* 3 */
611 .name = "PDC20265", 471 .name = "PDC20265",
612 .init_setup = init_setup_pdc20265, 472 .init_setup = init_setup_pdc20265,
@@ -617,6 +477,7 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
617 .autodma = AUTODMA, 477 .autodma = AUTODMA,
618 .bootable = OFF_BOARD, 478 .bootable = OFF_BOARD,
619 .extra = 48, 479 .extra = 48,
480 .udma_mask = 0x3f, /* udma0-5 */
620 },{ /* 4 */ 481 },{ /* 4 */
621 .name = "PDC20267", 482 .name = "PDC20267",
622 .init_setup = init_setup_pdc202xx, 483 .init_setup = init_setup_pdc202xx,
@@ -627,6 +488,7 @@ static ide_pci_device_t pdc202xx_chipsets[] __devinitdata = {
627 .autodma = AUTODMA, 488 .autodma = AUTODMA,
628 .bootable = OFF_BOARD, 489 .bootable = OFF_BOARD,
629 .extra = 48, 490 .extra = 48,
491 .udma_mask = 0x3f, /* udma0-5 */
630 } 492 }
631}; 493};
632 494
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index 061d300ab8be..8b219dd63024 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -106,68 +106,6 @@
106static int no_piix_dma; 106static int no_piix_dma;
107 107
108/** 108/**
109 * piix_ratemask - compute rate mask for PIIX IDE
110 * @drive: IDE drive to compute for
111 *
112 * Returns the available modes for the PIIX IDE controller.
113 */
114
115static u8 piix_ratemask (ide_drive_t *drive)
116{
117 struct pci_dev *dev = HWIF(drive)->pci_dev;
118 u8 mode;
119
120 switch(dev->device) {
121 case PCI_DEVICE_ID_INTEL_82801EB_1:
122 mode = 3;
123 break;
124 /* UDMA 100 capable */
125 case PCI_DEVICE_ID_INTEL_82801BA_8:
126 case PCI_DEVICE_ID_INTEL_82801BA_9:
127 case PCI_DEVICE_ID_INTEL_82801CA_10:
128 case PCI_DEVICE_ID_INTEL_82801CA_11:
129 case PCI_DEVICE_ID_INTEL_82801E_11:
130 case PCI_DEVICE_ID_INTEL_82801DB_1:
131 case PCI_DEVICE_ID_INTEL_82801DB_10:
132 case PCI_DEVICE_ID_INTEL_82801DB_11:
133 case PCI_DEVICE_ID_INTEL_82801EB_11:
134 case PCI_DEVICE_ID_INTEL_ESB_2:
135 case PCI_DEVICE_ID_INTEL_ICH6_19:
136 case PCI_DEVICE_ID_INTEL_ICH7_21:
137 case PCI_DEVICE_ID_INTEL_ESB2_18:
138 case PCI_DEVICE_ID_INTEL_ICH8_6:
139 mode = 3;
140 break;
141 /* UDMA 66 capable */
142 case PCI_DEVICE_ID_INTEL_82801AA_1:
143 case PCI_DEVICE_ID_INTEL_82372FB_1:
144 mode = 2;
145 break;
146 /* UDMA 33 capable */
147 case PCI_DEVICE_ID_INTEL_82371AB:
148 case PCI_DEVICE_ID_INTEL_82443MX_1:
149 case PCI_DEVICE_ID_INTEL_82451NX:
150 case PCI_DEVICE_ID_INTEL_82801AB_1:
151 return 1;
152 /* Non UDMA capable (MWDMA2) */
153 case PCI_DEVICE_ID_INTEL_82371SB_1:
154 case PCI_DEVICE_ID_INTEL_82371FB_1:
155 case PCI_DEVICE_ID_INTEL_82371FB_0:
156 case PCI_DEVICE_ID_INTEL_82371MX:
157 default:
158 return 0;
159 }
160
161 /*
162 * If we are UDMA66 capable fall back to UDMA33
163 * if the drive cannot see an 80pin cable.
164 */
165 if (!eighty_ninty_three(drive))
166 mode = min_t(u8, mode, 1);
167 return mode;
168}
169
170/**
171 * piix_dma_2_pio - return the PIO mode matching DMA 109 * piix_dma_2_pio - return the PIO mode matching DMA
172 * @xfer_rate: transfer speed 110 * @xfer_rate: transfer speed
173 * 111 *
@@ -301,7 +239,7 @@ static int piix_tune_chipset (ide_drive_t *drive, u8 xferspeed)
301 ide_hwif_t *hwif = HWIF(drive); 239 ide_hwif_t *hwif = HWIF(drive);
302 struct pci_dev *dev = hwif->pci_dev; 240 struct pci_dev *dev = hwif->pci_dev;
303 u8 maslave = hwif->channel ? 0x42 : 0x40; 241 u8 maslave = hwif->channel ? 0x42 : 0x40;
304 u8 speed = ide_rate_filter(piix_ratemask(drive), xferspeed); 242 u8 speed = ide_rate_filter(drive, xferspeed);
305 int a_speed = 3 << (drive->dn * 4); 243 int a_speed = 3 << (drive->dn * 4);
306 int u_flag = 1 << drive->dn; 244 int u_flag = 1 << drive->dn;
307 int v_flag = 0x01 << drive->dn; 245 int v_flag = 0x01 << drive->dn;
@@ -366,30 +304,6 @@ static int piix_tune_chipset (ide_drive_t *drive, u8 xferspeed)
366} 304}
367 305
368/** 306/**
369 * piix_config_drive_for_dma - configure drive for DMA
370 * @drive: IDE drive to configure
371 *
372 * Set up a PIIX interface channel for the best available speed.
373 * We prefer UDMA if it is available and then MWDMA. If DMA is
374 * not available we switch to PIO and return 0.
375 */
376
377static int piix_config_drive_for_dma (ide_drive_t *drive)
378{
379 u8 speed = ide_dma_speed(drive, piix_ratemask(drive));
380
381 /*
382 * If no DMA speed was available or the chipset has DMA bugs
383 * then disable DMA and use PIO
384 */
385 if (!speed)
386 return 0;
387
388 (void) piix_tune_chipset(drive, speed);
389 return ide_dma_enable(drive);
390}
391
392/**
393 * piix_config_drive_xfer_rate - set up an IDE device 307 * piix_config_drive_xfer_rate - set up an IDE device
394 * @drive: IDE drive to configure 308 * @drive: IDE drive to configure
395 * 309 *
@@ -401,7 +315,7 @@ static int piix_config_drive_xfer_rate (ide_drive_t *drive)
401{ 315{
402 drive->init_speed = 0; 316 drive->init_speed = 0;
403 317
404 if (ide_use_dma(drive) && piix_config_drive_for_dma(drive)) 318 if (ide_tune_dma(drive))
405 return 0; 319 return 0;
406 320
407 if (ide_use_fast_pio(drive)) 321 if (ide_use_fast_pio(drive))
@@ -524,26 +438,14 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
524 hwif->ide_dma_clear_irq = &piix_dma_clear_irq; 438 hwif->ide_dma_clear_irq = &piix_dma_clear_irq;
525 439
526 hwif->atapi_dma = 1; 440 hwif->atapi_dma = 1;
527 hwif->ultra_mask = 0x3f; 441
442 hwif->ultra_mask = hwif->cds->udma_mask;
528 hwif->mwdma_mask = 0x06; 443 hwif->mwdma_mask = 0x06;
529 hwif->swdma_mask = 0x04; 444 hwif->swdma_mask = 0x04;
530 445
531 switch(hwif->pci_dev->device) { 446 if (hwif->ultra_mask & 0x78) {
532 case PCI_DEVICE_ID_INTEL_82371FB_0: 447 if (!hwif->udma_four)
533 case PCI_DEVICE_ID_INTEL_82371FB_1: 448 hwif->udma_four = piix_cable_detect(hwif);
534 case PCI_DEVICE_ID_INTEL_82371SB_1:
535 hwif->ultra_mask = 0x80;
536 break;
537 case PCI_DEVICE_ID_INTEL_82371AB:
538 case PCI_DEVICE_ID_INTEL_82443MX_1:
539 case PCI_DEVICE_ID_INTEL_82451NX:
540 case PCI_DEVICE_ID_INTEL_82801AB_1:
541 hwif->ultra_mask = 0x07;
542 break;
543 default:
544 if (!hwif->udma_four)
545 hwif->udma_four = piix_cable_detect(hwif);
546 break;
547 } 449 }
548 450
549 if (no_piix_dma) 451 if (no_piix_dma)
@@ -557,7 +459,7 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
557 hwif->drives[0].autodma = hwif->autodma; 459 hwif->drives[0].autodma = hwif->autodma;
558} 460}
559 461
560#define DECLARE_PIIX_DEV(name_str) \ 462#define DECLARE_PIIX_DEV(name_str, udma) \
561 { \ 463 { \
562 .name = name_str, \ 464 .name = name_str, \
563 .init_chipset = init_chipset_piix, \ 465 .init_chipset = init_chipset_piix, \
@@ -566,11 +468,12 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
566 .autodma = AUTODMA, \ 468 .autodma = AUTODMA, \
567 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 469 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
568 .bootable = ON_BOARD, \ 470 .bootable = ON_BOARD, \
471 .udma_mask = udma, \
569 } 472 }
570 473
571static ide_pci_device_t piix_pci_info[] __devinitdata = { 474static ide_pci_device_t piix_pci_info[] __devinitdata = {
572 /* 0 */ DECLARE_PIIX_DEV("PIIXa"), 475 /* 0 */ DECLARE_PIIX_DEV("PIIXa", 0x00), /* no udma */
573 /* 1 */ DECLARE_PIIX_DEV("PIIXb"), 476 /* 1 */ DECLARE_PIIX_DEV("PIIXb", 0x00), /* no udma */
574 477
575 /* 2 */ 478 /* 2 */
576 { /* 479 { /*
@@ -587,28 +490,28 @@ static ide_pci_device_t piix_pci_info[] __devinitdata = {
587 .flags = IDEPCI_FLAG_ISA_PORTS 490 .flags = IDEPCI_FLAG_ISA_PORTS
588 }, 491 },
589 492
590 /* 3 */ DECLARE_PIIX_DEV("PIIX3"), 493 /* 3 */ DECLARE_PIIX_DEV("PIIX3", 0x00), /* no udma */
591 /* 4 */ DECLARE_PIIX_DEV("PIIX4"), 494 /* 4 */ DECLARE_PIIX_DEV("PIIX4", 0x07), /* udma0-2 */
592 /* 5 */ DECLARE_PIIX_DEV("ICH0"), 495 /* 5 */ DECLARE_PIIX_DEV("ICH0", 0x07), /* udma0-2 */
593 /* 6 */ DECLARE_PIIX_DEV("PIIX4"), 496 /* 6 */ DECLARE_PIIX_DEV("PIIX4", 0x07), /* udma0-2 */
594 /* 7 */ DECLARE_PIIX_DEV("ICH"), 497 /* 7 */ DECLARE_PIIX_DEV("ICH", 0x1f), /* udma0-4 */
595 /* 8 */ DECLARE_PIIX_DEV("PIIX4"), 498 /* 8 */ DECLARE_PIIX_DEV("PIIX4", 0x1f), /* udma0-4 */
596 /* 9 */ DECLARE_PIIX_DEV("PIIX4"), 499 /* 9 */ DECLARE_PIIX_DEV("PIIX4", 0x07), /* udma0-2 */
597 /* 10 */ DECLARE_PIIX_DEV("ICH2"), 500 /* 10 */ DECLARE_PIIX_DEV("ICH2", 0x3f), /* udma0-5 */
598 /* 11 */ DECLARE_PIIX_DEV("ICH2M"), 501 /* 11 */ DECLARE_PIIX_DEV("ICH2M", 0x3f), /* udma0-5 */
599 /* 12 */ DECLARE_PIIX_DEV("ICH3M"), 502 /* 12 */ DECLARE_PIIX_DEV("ICH3M", 0x3f), /* udma0-5 */
600 /* 13 */ DECLARE_PIIX_DEV("ICH3"), 503 /* 13 */ DECLARE_PIIX_DEV("ICH3", 0x3f), /* udma0-5 */
601 /* 14 */ DECLARE_PIIX_DEV("ICH4"), 504 /* 14 */ DECLARE_PIIX_DEV("ICH4", 0x3f), /* udma0-5 */
602 /* 15 */ DECLARE_PIIX_DEV("ICH5"), 505 /* 15 */ DECLARE_PIIX_DEV("ICH5", 0x3f), /* udma0-5 */
603 /* 16 */ DECLARE_PIIX_DEV("C-ICH"), 506 /* 16 */ DECLARE_PIIX_DEV("C-ICH", 0x3f), /* udma0-5 */
604 /* 17 */ DECLARE_PIIX_DEV("ICH4"), 507 /* 17 */ DECLARE_PIIX_DEV("ICH4", 0x3f), /* udma0-5 */
605 /* 18 */ DECLARE_PIIX_DEV("ICH5-SATA"), 508 /* 18 */ DECLARE_PIIX_DEV("ICH5-SATA", 0x3f), /* udma0-5 */
606 /* 19 */ DECLARE_PIIX_DEV("ICH5"), 509 /* 19 */ DECLARE_PIIX_DEV("ICH5", 0x3f), /* udma0-5 */
607 /* 20 */ DECLARE_PIIX_DEV("ICH6"), 510 /* 20 */ DECLARE_PIIX_DEV("ICH6", 0x3f), /* udma0-5 */
608 /* 21 */ DECLARE_PIIX_DEV("ICH7"), 511 /* 21 */ DECLARE_PIIX_DEV("ICH7", 0x3f), /* udma0-5 */
609 /* 22 */ DECLARE_PIIX_DEV("ICH4"), 512 /* 22 */ DECLARE_PIIX_DEV("ICH4", 0x3f), /* udma0-5 */
610 /* 23 */ DECLARE_PIIX_DEV("ESB2"), 513 /* 23 */ DECLARE_PIIX_DEV("ESB2", 0x3f), /* udma0-5 */
611 /* 24 */ DECLARE_PIIX_DEV("ICH8M"), 514 /* 24 */ DECLARE_PIIX_DEV("ICH8M", 0x3f), /* udma0-5 */
612}; 515};
613 516
614/** 517/**
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index b5ae0c50e216..523363c93794 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -1,7 +1,9 @@
1/* 1/*
2 * linux/drivers/ide/pci/sc1200.c Version 0.91 28-Jan-2003 2 * linux/drivers/ide/pci/sc1200.c Version 0.94 Mar 10 2007
3 * 3 *
4 * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com> 4 * Copyright (C) 2000-2002 Mark Lord <mlord@pobox.com>
5 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
6 *
5 * May be copied or modified under the terms of the GNU General Public License 7 * May be copied or modified under the terms of the GNU General Public License
6 * 8 *
7 * Development of this chipset driver was funded 9 * Development of this chipset driver was funded
@@ -93,64 +95,50 @@ static const unsigned int sc1200_pio_timings[4][5] =
93 */ 95 */
94//#define SC1200_BAD_PIO(timings) (((timings)&~0x80000000)==0x00009172) 96//#define SC1200_BAD_PIO(timings) (((timings)&~0x80000000)==0x00009172)
95 97
96static int sc1200_autoselect_dma_mode (ide_drive_t *drive) 98static void sc1200_tunepio(ide_drive_t *drive, u8 pio)
97{ 99{
98 int udma_ok = 1, mode = 0; 100 ide_hwif_t *hwif = drive->hwif;
99 ide_hwif_t *hwif = HWIF(drive); 101 struct pci_dev *pdev = hwif->pci_dev;
100 int unit = drive->select.b.unit; 102 unsigned int basereg = hwif->channel ? 0x50 : 0x40, format = 0;
101 ide_drive_t *mate = &hwif->drives[unit^1]; 103
102 struct hd_driveid *id = drive->id; 104 pci_read_config_dword(pdev, basereg + 4, &format);
103 105 format = (format >> 31) & 1;
104 /* 106 if (format)
105 * The SC1200 specifies that two drives sharing a cable cannot 107 format += sc1200_get_pci_clock();
106 * mix UDMA/MDMA. It has to be one or the other, for the pair, 108 pci_write_config_dword(pdev, basereg + ((drive->dn & 1) << 3),
107 * though different timings can still be chosen for each drive. 109 sc1200_pio_timings[format][pio]);
108 * We could set the appropriate timing bits on the fly,
109 * but that might be a bit confusing. So, for now we statically
110 * handle this requirement by looking at our mate drive to see
111 * what it is capable of, before choosing a mode for our own drive.
112 */
113 if (mate->present) {
114 struct hd_driveid *mateid = mate->id;
115 if (mateid && (mateid->capability & 1) && !__ide_dma_bad_drive(mate)) {
116 if ((mateid->field_valid & 4) && (mateid->dma_ultra & 7))
117 udma_ok = 1;
118 else if ((mateid->field_valid & 2) && (mateid->dma_mword & 7))
119 udma_ok = 0;
120 else
121 udma_ok = 1;
122 }
123 }
124 /*
125 * Now see what the current drive is capable of,
126 * selecting UDMA only if the mate said it was ok.
127 */
128 if (id && (id->capability & 1) && hwif->autodma && !__ide_dma_bad_drive(drive)) {
129 if (udma_ok && (id->field_valid & 4) && (id->dma_ultra & 7)) {
130 if (id->dma_ultra & 4)
131 mode = XFER_UDMA_2;
132 else if (id->dma_ultra & 2)
133 mode = XFER_UDMA_1;
134 else if (id->dma_ultra & 1)
135 mode = XFER_UDMA_0;
136 }
137 if (!mode && (id->field_valid & 2) && (id->dma_mword & 7)) {
138 if (id->dma_mword & 4)
139 mode = XFER_MW_DMA_2;
140 else if (id->dma_mword & 2)
141 mode = XFER_MW_DMA_1;
142 else if (id->dma_mword & 1)
143 mode = XFER_MW_DMA_0;
144 }
145 }
146 return mode;
147} 110}
148 111
149/* 112/*
150 * sc1200_config_dma2() handles selection/setting of DMA/UDMA modes 113 * The SC1200 specifies that two drives sharing a cable cannot mix
151 * for both the chipset and drive. 114 * UDMA/MDMA. It has to be one or the other, for the pair, though
115 * different timings can still be chosen for each drive. We could
116 * set the appropriate timing bits on the fly, but that might be
117 * a bit confusing. So, for now we statically handle this requirement
118 * by looking at our mate drive to see what it is capable of, before
119 * choosing a mode for our own drive.
152 */ 120 */
153static int sc1200_config_dma2 (ide_drive_t *drive, int mode) 121static u8 sc1200_udma_filter(ide_drive_t *drive)
122{
123 ide_hwif_t *hwif = drive->hwif;
124 ide_drive_t *mate = &hwif->drives[(drive->dn & 1) ^ 1];
125 struct hd_driveid *mateid = mate->id;
126 u8 mask = hwif->ultra_mask;
127
128 if (mate->present == 0)
129 goto out;
130
131 if ((mateid->capability & 1) && __ide_dma_bad_drive(mate) == 0) {
132 if ((mateid->field_valid & 4) && (mateid->dma_ultra & 7))
133 goto out;
134 if ((mateid->field_valid & 2) && (mateid->dma_mword & 7))
135 mask = 0;
136 }
137out:
138 return mask;
139}
140
141static int sc1200_tune_chipset(ide_drive_t *drive, u8 mode)
154{ 142{
155 ide_hwif_t *hwif = HWIF(drive); 143 ide_hwif_t *hwif = HWIF(drive);
156 int unit = drive->select.b.unit; 144 int unit = drive->select.b.unit;
@@ -158,20 +146,26 @@ static int sc1200_config_dma2 (ide_drive_t *drive, int mode)
158 unsigned short pci_clock; 146 unsigned short pci_clock;
159 unsigned int basereg = hwif->channel ? 0x50 : 0x40; 147 unsigned int basereg = hwif->channel ? 0x50 : 0x40;
160 148
161 /* 149 mode = ide_rate_filter(drive, mode);
162 * Default to DMA-off in case we run into trouble here.
163 */
164 hwif->dma_off_quietly(drive); /* turn off DMA while we fiddle */
165 outb(inb(hwif->dma_base+2)&~(unit?0x40:0x20), hwif->dma_base+2); /* clear DMA_capable bit */
166 150
167 /* 151 /*
168 * Tell the drive to switch to the new mode; abort on failure. 152 * Tell the drive to switch to the new mode; abort on failure.
169 */ 153 */
170 if (!mode || sc1200_set_xfer_mode(drive, mode)) { 154 if (sc1200_set_xfer_mode(drive, mode)) {
171 printk("SC1200: set xfer mode failure\n"); 155 printk("SC1200: set xfer mode failure\n");
172 return 1; /* failure */ 156 return 1; /* failure */
173 } 157 }
174 158
159 switch (mode) {
160 case XFER_PIO_4:
161 case XFER_PIO_3:
162 case XFER_PIO_2:
163 case XFER_PIO_1:
164 case XFER_PIO_0:
165 sc1200_tunepio(drive, mode - XFER_PIO_0);
166 return 0;
167 }
168
175 pci_clock = sc1200_get_pci_clock(); 169 pci_clock = sc1200_get_pci_clock();
176 170
177 /* 171 /*
@@ -224,11 +218,9 @@ static int sc1200_config_dma2 (ide_drive_t *drive, int mode)
224 case PCI_CLK_66: timings = 0x00015151; break; 218 case PCI_CLK_66: timings = 0x00015151; break;
225 } 219 }
226 break; 220 break;
227 } 221 default:
228 222 BUG();
229 if (timings == 0) { 223 break;
230 printk("%s: sc1200_config_dma: huh? mode=%02x clk=%x \n", drive->name, mode, pci_clock);
231 return 1; /* failure */
232 } 224 }
233 225
234 if (unit == 0) { /* are we configuring drive0? */ 226 if (unit == 0) { /* are we configuring drive0? */
@@ -239,8 +231,6 @@ static int sc1200_config_dma2 (ide_drive_t *drive, int mode)
239 pci_write_config_dword(hwif->pci_dev, basereg+12, timings); 231 pci_write_config_dword(hwif->pci_dev, basereg+12, timings);
240 } 232 }
241 233
242 outb(inb(hwif->dma_base+2)|(unit?0x40:0x20), hwif->dma_base+2); /* set DMA_capable bit */
243
244 return 0; /* success */ 234 return 0; /* success */
245} 235}
246 236
@@ -250,7 +240,10 @@ static int sc1200_config_dma2 (ide_drive_t *drive, int mode)
250 */ 240 */
251static int sc1200_config_dma (ide_drive_t *drive) 241static int sc1200_config_dma (ide_drive_t *drive)
252{ 242{
253 return sc1200_config_dma2(drive, sc1200_autoselect_dma_mode(drive)); 243 if (ide_tune_dma(drive))
244 return 0;
245
246 return 1;
254} 247}
255 248
256 249
@@ -290,10 +283,11 @@ static int sc1200_ide_dma_end (ide_drive_t *drive)
290static void sc1200_tuneproc (ide_drive_t *drive, byte pio) /* mode=255 means "autotune" */ 283static void sc1200_tuneproc (ide_drive_t *drive, byte pio) /* mode=255 means "autotune" */
291{ 284{
292 ide_hwif_t *hwif = HWIF(drive); 285 ide_hwif_t *hwif = HWIF(drive);
293 unsigned int format;
294 static byte modes[5] = {XFER_PIO_0, XFER_PIO_1, XFER_PIO_2, XFER_PIO_3, XFER_PIO_4};
295 int mode = -1; 286 int mode = -1;
296 287
288 /*
289 * bad abuse of ->tuneproc interface
290 */
297 switch (pio) { 291 switch (pio) {
298 case 200: mode = XFER_UDMA_0; break; 292 case 200: mode = XFER_UDMA_0; break;
299 case 201: mode = XFER_UDMA_1; break; 293 case 201: mode = XFER_UDMA_1; break;
@@ -304,20 +298,17 @@ static void sc1200_tuneproc (ide_drive_t *drive, byte pio) /* mode=255 means "au
304 } 298 }
305 if (mode != -1) { 299 if (mode != -1) {
306 printk("SC1200: %s: changing (U)DMA mode\n", drive->name); 300 printk("SC1200: %s: changing (U)DMA mode\n", drive->name);
307 (void)sc1200_config_dma2(drive, mode); 301 hwif->dma_off_quietly(drive);
302 if (sc1200_tune_chipset(drive, mode) == 0)
303 hwif->dma_host_on(drive);
308 return; 304 return;
309 } 305 }
310 306
311 pio = ide_get_best_pio_mode(drive, pio, 4, NULL); 307 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
312 printk("SC1200: %s: setting PIO mode%d\n", drive->name, pio); 308 printk("SC1200: %s: setting PIO mode%d\n", drive->name, pio);
313 if (!sc1200_set_xfer_mode(drive, modes[pio])) { 309
314 unsigned int basereg = hwif->channel ? 0x50 : 0x40; 310 if (sc1200_set_xfer_mode(drive, XFER_PIO_0 + pio) == 0)
315 pci_read_config_dword (hwif->pci_dev, basereg+4, &format); 311 sc1200_tunepio(drive, pio);
316 format = (format >> 31) & 1;
317 if (format)
318 format += sc1200_get_pci_clock();
319 pci_write_config_dword(hwif->pci_dev, basereg + (drive->select.b.unit << 3), sc1200_pio_timings[format][pio]);
320 }
321} 312}
322 313
323#ifdef CONFIG_PM 314#ifdef CONFIG_PM
@@ -438,12 +429,12 @@ static int sc1200_resume (struct pci_dev *dev)
438 for (d = 0; d < MAX_DRIVES; ++d) { 429 for (d = 0; d < MAX_DRIVES; ++d) {
439 ide_drive_t *drive = &(hwif->drives[d]); 430 ide_drive_t *drive = &(hwif->drives[d]);
440 if (drive->present && !__ide_dma_bad_drive(drive)) { 431 if (drive->present && !__ide_dma_bad_drive(drive)) {
441 int was_using_dma = drive->using_dma; 432 int enable_dma = drive->using_dma;
442 hwif->dma_off_quietly(drive); 433 hwif->dma_off_quietly(drive);
443 sc1200_config_dma(drive); 434 if (sc1200_config_dma(drive))
444 if (!was_using_dma && drive->using_dma) { 435 enable_dma = 0;
445 hwif->dma_off_quietly(drive); 436 if (enable_dma)
446 } 437 hwif->dma_host_on(drive);
447 } 438 }
448 } 439 }
449 } 440 }
@@ -461,11 +452,13 @@ static void __devinit init_hwif_sc1200 (ide_hwif_t *hwif)
461 hwif->serialized = hwif->mate->serialized = 1; 452 hwif->serialized = hwif->mate->serialized = 1;
462 hwif->autodma = 0; 453 hwif->autodma = 0;
463 if (hwif->dma_base) { 454 if (hwif->dma_base) {
455 hwif->udma_filter = sc1200_udma_filter;
464 hwif->ide_dma_check = &sc1200_config_dma; 456 hwif->ide_dma_check = &sc1200_config_dma;
465 hwif->ide_dma_end = &sc1200_ide_dma_end; 457 hwif->ide_dma_end = &sc1200_ide_dma_end;
466 if (!noautodma) 458 if (!noautodma)
467 hwif->autodma = 1; 459 hwif->autodma = 1;
468 hwif->tuneproc = &sc1200_tuneproc; 460 hwif->tuneproc = &sc1200_tuneproc;
461 hwif->speedproc = &sc1200_tune_chipset;
469 } 462 }
470 hwif->atapi_dma = 1; 463 hwif->atapi_dma = 1;
471 hwif->ultra_mask = 0x07; 464 hwif->ultra_mask = 0x07;
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index f84bf791f72e..55bc0a32e34f 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -190,23 +190,6 @@ scc_ide_outsl(unsigned long port, void *addr, u32 count)
190} 190}
191 191
192/** 192/**
193 * scc_ratemask - Compute available modes
194 * @drive: IDE drive
195 *
196 * Compute the available speeds for the devices on the interface.
197 * Enforce UDMA33 as a limit if there is no 80pin cable present.
198 */
199
200static u8 scc_ratemask(ide_drive_t *drive)
201{
202 u8 mode = 4;
203
204 if (!eighty_ninty_three(drive))
205 mode = min(mode, (u8)1);
206 return mode;
207}
208
209/**
210 * scc_tuneproc - tune a drive PIO mode 193 * scc_tuneproc - tune a drive PIO mode
211 * @drive: drive to tune 194 * @drive: drive to tune
212 * @mode_wanted: the target operating mode 195 * @mode_wanted: the target operating mode
@@ -273,7 +256,7 @@ static void scc_tuneproc(ide_drive_t *drive, byte mode_wanted)
273static int scc_tune_chipset(ide_drive_t *drive, byte xferspeed) 256static int scc_tune_chipset(ide_drive_t *drive, byte xferspeed)
274{ 257{
275 ide_hwif_t *hwif = HWIF(drive); 258 ide_hwif_t *hwif = HWIF(drive);
276 u8 speed = ide_rate_filter(scc_ratemask(drive), xferspeed); 259 u8 speed = ide_rate_filter(drive, xferspeed);
277 struct scc_ports *ports = ide_get_hwifdata(hwif); 260 struct scc_ports *ports = ide_get_hwifdata(hwif);
278 unsigned long ctl_base = ports->ctl; 261 unsigned long ctl_base = ports->ctl;
279 unsigned long cckctrl_port = ctl_base + 0xff0; 262 unsigned long cckctrl_port = ctl_base + 0xff0;
@@ -339,26 +322,6 @@ static int scc_tune_chipset(ide_drive_t *drive, byte xferspeed)
339} 322}
340 323
341/** 324/**
342 * scc_config_chipset_for_dma - configure for DMA
343 * @drive: drive to configure
344 *
345 * Called by scc_config_drive_for_dma().
346 */
347
348static int scc_config_chipset_for_dma(ide_drive_t *drive)
349{
350 u8 speed = ide_dma_speed(drive, scc_ratemask(drive));
351
352 if (!speed)
353 return 0;
354
355 if (scc_tune_chipset(drive, speed))
356 return 0;
357
358 return ide_dma_enable(drive);
359}
360
361/**
362 * scc_configure_drive_for_dma - set up for DMA transfers 325 * scc_configure_drive_for_dma - set up for DMA transfers
363 * @drive: drive we are going to set up 326 * @drive: drive we are going to set up
364 * 327 *
@@ -371,7 +334,7 @@ static int scc_config_chipset_for_dma(ide_drive_t *drive)
371 334
372static int scc_config_drive_for_dma(ide_drive_t *drive) 335static int scc_config_drive_for_dma(ide_drive_t *drive)
373{ 336{
374 if (ide_use_dma(drive) && scc_config_chipset_for_dma(drive)) 337 if (ide_tune_dma(drive))
375 return 0; 338 return 0;
376 339
377 if (ide_use_fast_pio(drive)) 340 if (ide_use_fast_pio(drive))
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index dbcd37a0c652..6234f806c6b5 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -1,9 +1,10 @@
1/* 1/*
2 * linux/drivers/ide/pci/serverworks.c Version 0.8 25 Ebr 2003 2 * linux/drivers/ide/pci/serverworks.c Version 0.9 Mar 4 2007
3 * 3 *
4 * Copyright (C) 1998-2000 Michel Aubry 4 * Copyright (C) 1998-2000 Michel Aubry
5 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz 5 * Copyright (C) 1998-2000 Andrzej Krzysztofowicz
6 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org> 6 * Copyright (C) 1998-2000 Andre Hedrick <andre@linux-ide.org>
7 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
7 * Portions copyright (c) 2001 Sun Microsystems 8 * Portions copyright (c) 2001 Sun Microsystems
8 * 9 *
9 * 10 *
@@ -65,16 +66,16 @@ static int check_in_drive_lists (ide_drive_t *drive, const char **list)
65 return 0; 66 return 0;
66} 67}
67 68
68static u8 svwks_ratemask (ide_drive_t *drive) 69static u8 svwks_udma_filter(ide_drive_t *drive)
69{ 70{
70 struct pci_dev *dev = HWIF(drive)->pci_dev; 71 struct pci_dev *dev = HWIF(drive)->pci_dev;
71 u8 mode = 0; 72 u8 mask = 0;
72 73
73 if (!svwks_revision) 74 if (!svwks_revision)
74 pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision); 75 pci_read_config_byte(dev, PCI_REVISION_ID, &svwks_revision);
75 76
76 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE) 77 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_HT1000IDE)
77 return 2; 78 return 0x1f;
78 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) { 79 if (dev->device == PCI_DEVICE_ID_SERVERWORKS_OSB4IDE) {
79 u32 reg = 0; 80 u32 reg = 0;
80 if (isa_dev) 81 if (isa_dev)
@@ -86,25 +87,31 @@ static u8 svwks_ratemask (ide_drive_t *drive)
86 if(drive->media == ide_disk) 87 if(drive->media == ide_disk)
87 return 0; 88 return 0;
88 /* Check the OSB4 DMA33 enable bit */ 89 /* Check the OSB4 DMA33 enable bit */
89 return ((reg & 0x00004000) == 0x00004000) ? 1 : 0; 90 return ((reg & 0x00004000) == 0x00004000) ? 0x07 : 0;
90 } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) { 91 } else if (svwks_revision < SVWKS_CSB5_REVISION_NEW) {
91 return 1; 92 return 0x07;
92 } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) { 93 } else if (svwks_revision >= SVWKS_CSB5_REVISION_NEW) {
93 u8 btr = 0; 94 u8 btr = 0, mode;
94 pci_read_config_byte(dev, 0x5A, &btr); 95 pci_read_config_byte(dev, 0x5A, &btr);
95 mode = btr & 0x3; 96 mode = btr & 0x3;
96 if (!eighty_ninty_three(drive)) 97
97 mode = min(mode, (u8)1);
98 /* If someone decides to do UDMA133 on CSB5 the same 98 /* If someone decides to do UDMA133 on CSB5 the same
99 issue will bite so be inclusive */ 99 issue will bite so be inclusive */
100 if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100)) 100 if (mode > 2 && check_in_drive_lists(drive, svwks_bad_ata100))
101 mode = 2; 101 mode = 2;
102
103 switch(mode) {
104 case 2: mask = 0x1f; break;
105 case 1: mask = 0x07; break;
106 default: mask = 0x00; break;
107 }
102 } 108 }
103 if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) || 109 if (((dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE) ||
104 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) && 110 (dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB6IDE2)) &&
105 (!(PCI_FUNC(dev->devfn) & 1))) 111 (!(PCI_FUNC(dev->devfn) & 1)))
106 mode = 2; 112 mask = 0x1f;
107 return mode; 113
114 return mask;
108} 115}
109 116
110static u8 svwks_csb_check (struct pci_dev *dev) 117static u8 svwks_csb_check (struct pci_dev *dev)
@@ -130,19 +137,14 @@ static int svwks_tune_chipset (ide_drive_t *drive, u8 xferspeed)
130 137
131 ide_hwif_t *hwif = HWIF(drive); 138 ide_hwif_t *hwif = HWIF(drive);
132 struct pci_dev *dev = hwif->pci_dev; 139 struct pci_dev *dev = hwif->pci_dev;
133 u8 speed; 140 u8 speed = ide_rate_filter(drive, xferspeed);
134 u8 pio = ide_get_best_pio_mode(drive, 255, 5, NULL); 141 u8 pio = ide_get_best_pio_mode(drive, 255, 4, NULL);
135 u8 unit = (drive->select.b.unit & 0x01); 142 u8 unit = (drive->select.b.unit & 0x01);
136 u8 csb5 = svwks_csb_check(dev); 143 u8 csb5 = svwks_csb_check(dev);
137 u8 ultra_enable = 0, ultra_timing = 0; 144 u8 ultra_enable = 0, ultra_timing = 0;
138 u8 dma_timing = 0, pio_timing = 0; 145 u8 dma_timing = 0, pio_timing = 0;
139 u16 csb5_pio = 0; 146 u16 csb5_pio = 0;
140 147
141 if (xferspeed == 255) /* PIO auto-tuning */
142 speed = XFER_PIO_0 + pio;
143 else
144 speed = ide_rate_filter(svwks_ratemask(drive), xferspeed);
145
146 /* If we are about to put a disk into UDMA mode we screwed up. 148 /* If we are about to put a disk into UDMA mode we screwed up.
147 Our code assumes we never _ever_ do this on an OSB4 */ 149 Our code assumes we never _ever_ do this on an OSB4 */
148 150
@@ -225,6 +227,9 @@ oem_setup_failed:
225 case XFER_MW_DMA_2: 227 case XFER_MW_DMA_2:
226 case XFER_MW_DMA_1: 228 case XFER_MW_DMA_1:
227 case XFER_MW_DMA_0: 229 case XFER_MW_DMA_0:
230 /*
231 * TODO: always setup PIO mode so this won't be needed
232 */
228 pio_timing |= pio_modes[pio]; 233 pio_timing |= pio_modes[pio];
229 csb5_pio |= (pio << (4*drive->dn)); 234 csb5_pio |= (pio << (4*drive->dn));
230 dma_timing |= dma_modes[speed - XFER_MW_DMA_0]; 235 dma_timing |= dma_modes[speed - XFER_MW_DMA_0];
@@ -236,6 +241,9 @@ oem_setup_failed:
236 case XFER_UDMA_2: 241 case XFER_UDMA_2:
237 case XFER_UDMA_1: 242 case XFER_UDMA_1:
238 case XFER_UDMA_0: 243 case XFER_UDMA_0:
244 /*
245 * TODO: always setup PIO mode so this won't be needed
246 */
239 pio_timing |= pio_modes[pio]; 247 pio_timing |= pio_modes[pio];
240 csb5_pio |= (pio << (4*drive->dn)); 248 csb5_pio |= (pio << (4*drive->dn));
241 dma_timing |= dma_modes[2]; 249 dma_timing |= dma_modes[2];
@@ -256,72 +264,21 @@ oem_setup_failed:
256 return (ide_config_drive_speed(drive, speed)); 264 return (ide_config_drive_speed(drive, speed));
257} 265}
258 266
259static void config_chipset_for_pio (ide_drive_t *drive)
260{
261 u16 eide_pio_timing[6] = {960, 480, 240, 180, 120, 90};
262 u16 xfer_pio = drive->id->eide_pio_modes;
263 u8 timing, speed, pio;
264
265 pio = ide_get_best_pio_mode(drive, 255, 5, NULL);
266
267 if (xfer_pio > 4)
268 xfer_pio = 0;
269
270 if (drive->id->eide_pio_iordy > 0)
271 for (xfer_pio = 5;
272 xfer_pio>0 &&
273 drive->id->eide_pio_iordy>eide_pio_timing[xfer_pio];
274 xfer_pio--);
275 else
276 xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 :
277 (drive->id->eide_pio_modes & 2) ? 0x04 :
278 (drive->id->eide_pio_modes & 1) ? 0x03 :
279 (drive->id->tPIO & 2) ? 0x02 :
280 (drive->id->tPIO & 1) ? 0x01 : xfer_pio;
281
282 timing = (xfer_pio >= pio) ? xfer_pio : pio;
283
284 switch(timing) {
285 case 4: speed = XFER_PIO_4;break;
286 case 3: speed = XFER_PIO_3;break;
287 case 2: speed = XFER_PIO_2;break;
288 case 1: speed = XFER_PIO_1;break;
289 default:
290 speed = (!drive->id->tPIO) ? XFER_PIO_0 : XFER_PIO_SLOW;
291 break;
292 }
293 (void) svwks_tune_chipset(drive, speed);
294 drive->current_speed = speed;
295}
296
297static void svwks_tune_drive (ide_drive_t *drive, u8 pio) 267static void svwks_tune_drive (ide_drive_t *drive, u8 pio)
298{ 268{
299 if(pio == 255) 269 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
300 (void) svwks_tune_chipset(drive, 255); 270 (void)svwks_tune_chipset(drive, XFER_PIO_0 + pio);
301 else
302 (void) svwks_tune_chipset(drive, (XFER_PIO_0 + pio));
303}
304
305static int config_chipset_for_dma (ide_drive_t *drive)
306{
307 u8 speed = ide_dma_speed(drive, svwks_ratemask(drive));
308
309 if (!(speed))
310 speed = XFER_PIO_0 + ide_get_best_pio_mode(drive, 255, 5, NULL);
311
312 (void) svwks_tune_chipset(drive, speed);
313 return ide_dma_enable(drive);
314} 271}
315 272
316static int svwks_config_drive_xfer_rate (ide_drive_t *drive) 273static int svwks_config_drive_xfer_rate (ide_drive_t *drive)
317{ 274{
318 drive->init_speed = 0; 275 drive->init_speed = 0;
319 276
320 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 277 if (ide_tune_dma(drive))
321 return 0; 278 return 0;
322 279
323 if (ide_use_fast_pio(drive)) 280 if (ide_use_fast_pio(drive))
324 config_chipset_for_pio(drive); 281 svwks_tune_drive(drive, 255);
325 282
326 return -1; 283 return -1;
327} 284}
@@ -500,6 +457,7 @@ static void __devinit init_hwif_svwks (ide_hwif_t *hwif)
500 457
501 hwif->tuneproc = &svwks_tune_drive; 458 hwif->tuneproc = &svwks_tune_drive;
502 hwif->speedproc = &svwks_tune_chipset; 459 hwif->speedproc = &svwks_tune_chipset;
460 hwif->udma_filter = &svwks_udma_filter;
503 461
504 hwif->atapi_dma = 1; 462 hwif->atapi_dma = 1;
505 463
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index fd09b295a69d..d3185e29a38e 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -692,7 +692,7 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t * d)
692 return -EIO; 692 return -EIO;
693 693
694 /* Create /proc/ide entries */ 694 /* Create /proc/ide entries */
695 create_proc_ide_interfaces(); 695 ide_proc_register_port(hwif);
696 696
697 return 0; 697 return 0;
698} 698}
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index c0188de3cc66..1a4444e7226a 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -122,45 +122,41 @@ static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
122} 122}
123 123
124/** 124/**
125 * siimage_ratemask - Compute available modes 125 * sil_udma_filter - compute UDMA mask
126 * @drive: IDE drive 126 * @drive: IDE device
127 *
128 * Compute the available UDMA speeds for the device on the interface.
127 * 129 *
128 * Compute the available speeds for the devices on the interface.
129 * For the CMD680 this depends on the clocking mode (scsc), for the 130 * For the CMD680 this depends on the clocking mode (scsc), for the
130 * SI3312 SATA controller life is a bit simpler. Enforce UDMA33 131 * SI3112 SATA controller life is a bit simpler.
131 * as a limit if there is no 80pin cable present.
132 */ 132 */
133 133
134static byte siimage_ratemask (ide_drive_t *drive) 134static u8 sil_udma_filter(ide_drive_t *drive)
135{ 135{
136 ide_hwif_t *hwif = HWIF(drive); 136 ide_hwif_t *hwif = drive->hwif;
137 u8 mode = 0, scsc = 0;
138 unsigned long base = (unsigned long) hwif->hwif_data; 137 unsigned long base = (unsigned long) hwif->hwif_data;
138 u8 mask = 0, scsc = 0;
139 139
140 if (hwif->mmio) 140 if (hwif->mmio)
141 scsc = hwif->INB(base + 0x4A); 141 scsc = hwif->INB(base + 0x4A);
142 else 142 else
143 pci_read_config_byte(hwif->pci_dev, 0x8A, &scsc); 143 pci_read_config_byte(hwif->pci_dev, 0x8A, &scsc);
144 144
145 if(is_sata(hwif)) 145 if (is_sata(hwif)) {
146 { 146 mask = strstr(drive->id->model, "Maxtor") ? 0x3f : 0x7f;
147 if(strstr(drive->id->model, "Maxtor")) 147 goto out;
148 return 3;
149 return 4;
150 } 148 }
151 149
152 if ((scsc & 0x30) == 0x10) /* 133 */ 150 if ((scsc & 0x30) == 0x10) /* 133 */
153 mode = 4; 151 mask = 0x7f;
154 else if ((scsc & 0x30) == 0x20) /* 2xPCI */ 152 else if ((scsc & 0x30) == 0x20) /* 2xPCI */
155 mode = 4; 153 mask = 0x7f;
156 else if ((scsc & 0x30) == 0x00) /* 100 */ 154 else if ((scsc & 0x30) == 0x00) /* 100 */
157 mode = 3; 155 mask = 0x3f;
158 else /* Disabled ? */ 156 else /* Disabled ? */
159 BUG(); 157 BUG();
160 158out:
161 if (!eighty_ninty_three(drive)) 159 return mask;
162 mode = min(mode, (u8)1);
163 return mode;
164} 160}
165 161
166/** 162/**
@@ -306,7 +302,7 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed)
306 ide_hwif_t *hwif = HWIF(drive); 302 ide_hwif_t *hwif = HWIF(drive);
307 u16 ultra = 0, multi = 0; 303 u16 ultra = 0, multi = 0;
308 u8 mode = 0, unit = drive->select.b.unit; 304 u8 mode = 0, unit = drive->select.b.unit;
309 u8 speed = ide_rate_filter(siimage_ratemask(drive), xferspeed); 305 u8 speed = ide_rate_filter(drive, xferspeed);
310 unsigned long base = (unsigned long)hwif->hwif_data; 306 unsigned long base = (unsigned long)hwif->hwif_data;
311 u8 scsc = 0, addr_mask = ((hwif->channel) ? 307 u8 scsc = 0, addr_mask = ((hwif->channel) ?
312 ((hwif->mmio) ? 0xF4 : 0x84) : 308 ((hwif->mmio) ? 0xF4 : 0x84) :
@@ -379,28 +375,6 @@ static int siimage_tune_chipset (ide_drive_t *drive, byte xferspeed)
379} 375}
380 376
381/** 377/**
382 * config_chipset_for_dma - configure for DMA
383 * @drive: drive to configure
384 *
385 * Called by the IDE layer when it wants the timings set up.
386 * For the CMD680 we also need to set up the PIO timings and
387 * enable DMA.
388 */
389
390static int config_chipset_for_dma (ide_drive_t *drive)
391{
392 u8 speed = ide_dma_speed(drive, siimage_ratemask(drive));
393
394 if (!speed)
395 return 0;
396
397 if (siimage_tune_chipset(drive, speed))
398 return 0;
399
400 return ide_dma_enable(drive);
401}
402
403/**
404 * siimage_configure_drive_for_dma - set up for DMA transfers 378 * siimage_configure_drive_for_dma - set up for DMA transfers
405 * @drive: drive we are going to set up 379 * @drive: drive we are going to set up
406 * 380 *
@@ -412,7 +386,7 @@ static int config_chipset_for_dma (ide_drive_t *drive)
412 386
413static int siimage_config_drive_for_dma (ide_drive_t *drive) 387static int siimage_config_drive_for_dma (ide_drive_t *drive)
414{ 388{
415 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 389 if (ide_tune_dma(drive))
416 return 0; 390 return 0;
417 391
418 if (ide_use_fast_pio(drive)) 392 if (ide_use_fast_pio(drive))
@@ -831,7 +805,7 @@ static void __devinit init_mmio_iops_siimage(ide_hwif_t *hwif)
831 805
832 /* 806 /*
833 * Now set up the hw. We have to do this ourselves as 807 * Now set up the hw. We have to do this ourselves as
834 * the MMIO layout isnt the same as the the standard port 808 * the MMIO layout isnt the same as the standard port
835 * based I/O 809 * based I/O
836 */ 810 */
837 811
@@ -989,6 +963,7 @@ static void __devinit init_hwif_siimage(ide_hwif_t *hwif)
989 hwif->tuneproc = &siimage_tuneproc; 963 hwif->tuneproc = &siimage_tuneproc;
990 hwif->reset_poll = &siimage_reset_poll; 964 hwif->reset_poll = &siimage_reset_poll;
991 hwif->pre_reset = &siimage_pre_reset; 965 hwif->pre_reset = &siimage_pre_reset;
966 hwif->udma_filter = &sil_udma_filter;
992 967
993 if(is_sata(hwif)) { 968 if(is_sata(hwif)) {
994 static int first = 1; 969 static int first = 1;
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 2ba0669f36a1..bb6cc4aedd63 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -1,9 +1,11 @@
1/* 1/*
2 * linux/drivers/ide/pci/sis5513.c Version 0.16ac+vp Jun 18, 2003 2 * linux/drivers/ide/pci/sis5513.c Version 0.20 Mar 4, 2007
3 * 3 *
4 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org> 4 * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org>
5 * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer 5 * Copyright (C) 2002 Lionel Bouton <Lionel.Bouton@inet6.fr>, Maintainer
6 * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz> 6 * Copyright (C) 2003 Vojtech Pavlik <vojtech@suse.cz>
7 * Copyright (C) 2007 Bartlomiej Zolnierkiewicz
8 *
7 * May be copied or modified under the terms of the GNU General Public License 9 * May be copied or modified under the terms of the GNU General Public License
8 * 10 *
9 * 11 *
@@ -191,7 +193,7 @@ static char* chipset_capability[] = {
191 "ATA 133 (1st gen)", "ATA 133 (2nd gen)" 193 "ATA 133 (1st gen)", "ATA 133 (2nd gen)"
192}; 194};
193 195
194#if defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_PROC_FS) 196#if defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
195#include <linux/stat.h> 197#include <linux/stat.h>
196#include <linux/proc_fs.h> 198#include <linux/proc_fs.h>
197 199
@@ -426,17 +428,7 @@ static int sis_get_info (char *buffer, char **addr, off_t offset, int count)
426 428
427 return len > count ? count : len; 429 return len > count ? count : len;
428} 430}
429#endif /* defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_PROC_FS) */ 431#endif /* defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_IDE_PROC_FS) */
430
431static u8 sis5513_ratemask (ide_drive_t *drive)
432{
433 u8 rates[] = { 0, 0, 1, 2, 3, 3, 4, 4 };
434 u8 mode = rates[chipset_family];
435
436 if (!eighty_ninty_three(drive))
437 mode = min(mode, (u8)1);
438 return mode;
439}
440 432
441/* 433/*
442 * Configuration functions 434 * Configuration functions
@@ -458,36 +450,15 @@ static void config_drive_art_rwp (ide_drive_t *drive)
458 pci_write_config_byte(dev, 0x4b, reg4bh|rw_prefetch); 450 pci_write_config_byte(dev, 0x4b, reg4bh|rw_prefetch);
459} 451}
460 452
461
462/* Set per-drive active and recovery time */ 453/* Set per-drive active and recovery time */
463static void config_art_rwp_pio (ide_drive_t *drive, u8 pio) 454static void config_art_rwp_pio (ide_drive_t *drive, u8 pio)
464{ 455{
465 ide_hwif_t *hwif = HWIF(drive); 456 ide_hwif_t *hwif = HWIF(drive);
466 struct pci_dev *dev = hwif->pci_dev; 457 struct pci_dev *dev = hwif->pci_dev;
467 458
468 u8 timing, drive_pci, test1, test2; 459 u8 drive_pci, test1, test2;
469
470 u16 eide_pio_timing[6] = {600, 390, 240, 180, 120, 90};
471 u16 xfer_pio = drive->id->eide_pio_modes;
472 460
473 config_drive_art_rwp(drive); 461 config_drive_art_rwp(drive);
474 pio = ide_get_best_pio_mode(drive, 255, pio, NULL);
475
476 if (xfer_pio> 4)
477 xfer_pio = 0;
478
479 if (drive->id->eide_pio_iordy > 0) {
480 for (xfer_pio = 5;
481 (xfer_pio > 0) &&
482 (drive->id->eide_pio_iordy > eide_pio_timing[xfer_pio]);
483 xfer_pio--);
484 } else {
485 xfer_pio = (drive->id->eide_pio_modes & 4) ? 0x05 :
486 (drive->id->eide_pio_modes & 2) ? 0x04 :
487 (drive->id->eide_pio_modes & 1) ? 0x03 : xfer_pio;
488 }
489
490 timing = (xfer_pio >= pio) ? xfer_pio : pio;
491 462
492 /* In pre ATA_133 case, drives sit at 0x40 + 4*drive->dn */ 463 /* In pre ATA_133 case, drives sit at 0x40 + 4*drive->dn */
493 drive_pci = 0x40; 464 drive_pci = 0x40;
@@ -510,17 +481,18 @@ static void config_art_rwp_pio (ide_drive_t *drive, u8 pio)
510 test1 &= ~0x0F; 481 test1 &= ~0x0F;
511 test2 &= ~0x07; 482 test2 &= ~0x07;
512 483
513 switch(timing) { 484 switch(pio) {
514 case 4: test1 |= 0x01; test2 |= 0x03; break; 485 case 4: test1 |= 0x01; test2 |= 0x03; break;
515 case 3: test1 |= 0x03; test2 |= 0x03; break; 486 case 3: test1 |= 0x03; test2 |= 0x03; break;
516 case 2: test1 |= 0x04; test2 |= 0x04; break; 487 case 2: test1 |= 0x04; test2 |= 0x04; break;
517 case 1: test1 |= 0x07; test2 |= 0x06; break; 488 case 1: test1 |= 0x07; test2 |= 0x06; break;
489 case 0: /* PIO0: register setting == X000 */
518 default: break; 490 default: break;
519 } 491 }
520 pci_write_config_byte(dev, drive_pci, test1); 492 pci_write_config_byte(dev, drive_pci, test1);
521 pci_write_config_byte(dev, drive_pci+1, test2); 493 pci_write_config_byte(dev, drive_pci+1, test2);
522 } else if (chipset_family < ATA_133) { 494 } else if (chipset_family < ATA_133) {
523 switch(timing) { /* active recovery 495 switch(pio) { /* active recovery
524 v v */ 496 v v */
525 case 4: test1 = 0x30|0x01; break; 497 case 4: test1 = 0x30|0x01; break;
526 case 3: test1 = 0x30|0x03; break; 498 case 3: test1 = 0x30|0x03; break;
@@ -535,24 +507,28 @@ static void config_art_rwp_pio (ide_drive_t *drive, u8 pio)
535 pci_read_config_dword(dev, drive_pci, &test3); 507 pci_read_config_dword(dev, drive_pci, &test3);
536 test3 &= 0xc0c00fff; 508 test3 &= 0xc0c00fff;
537 if (test3 & 0x08) { 509 if (test3 & 0x08) {
538 test3 |= (unsigned long)ini_time_value[ATA_133][timing] << 12; 510 test3 |= ini_time_value[ATA_133][pio] << 12;
539 test3 |= (unsigned long)act_time_value[ATA_133][timing] << 16; 511 test3 |= act_time_value[ATA_133][pio] << 16;
540 test3 |= (unsigned long)rco_time_value[ATA_133][timing] << 24; 512 test3 |= rco_time_value[ATA_133][pio] << 24;
541 } else { 513 } else {
542 test3 |= (unsigned long)ini_time_value[ATA_100][timing] << 12; 514 test3 |= ini_time_value[ATA_100][pio] << 12;
543 test3 |= (unsigned long)act_time_value[ATA_100][timing] << 16; 515 test3 |= act_time_value[ATA_100][pio] << 16;
544 test3 |= (unsigned long)rco_time_value[ATA_100][timing] << 24; 516 test3 |= rco_time_value[ATA_100][pio] << 24;
545 } 517 }
546 pci_write_config_dword(dev, drive_pci, test3); 518 pci_write_config_dword(dev, drive_pci, test3);
547 } 519 }
548} 520}
549 521
550static int config_chipset_for_pio (ide_drive_t *drive, u8 pio) 522static int sis5513_tune_drive(ide_drive_t *drive, u8 pio)
551{ 523{
552 if (pio == 255) 524 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
553 pio = ide_find_best_mode(drive, XFER_PIO | XFER_EPIO) - XFER_PIO_0;
554 config_art_rwp_pio(drive, pio); 525 config_art_rwp_pio(drive, pio);
555 return ide_config_drive_speed(drive, XFER_PIO_0 + min_t(u8, pio, 4)); 526 return ide_config_drive_speed(drive, XFER_PIO_0 + pio);
527}
528
529static void sis5513_tuneproc(ide_drive_t *drive, u8 pio)
530{
531 (void)sis5513_tune_drive(drive, pio);
556} 532}
557 533
558static int sis5513_tune_chipset (ide_drive_t *drive, u8 xferspeed) 534static int sis5513_tune_chipset (ide_drive_t *drive, u8 xferspeed)
@@ -563,7 +539,7 @@ static int sis5513_tune_chipset (ide_drive_t *drive, u8 xferspeed)
563 u8 drive_pci, reg, speed; 539 u8 drive_pci, reg, speed;
564 u32 regdw; 540 u32 regdw;
565 541
566 speed = ide_rate_filter(sis5513_ratemask(drive), xferspeed); 542 speed = ide_rate_filter(drive, xferspeed);
567 543
568 /* See config_art_rwp_pio for drive pci config registers */ 544 /* See config_art_rwp_pio for drive pci config registers */
569 drive_pci = 0x40; 545 drive_pci = 0x40;
@@ -632,52 +608,34 @@ static int sis5513_tune_chipset (ide_drive_t *drive, u8 xferspeed)
632 case XFER_SW_DMA_1: 608 case XFER_SW_DMA_1:
633 case XFER_SW_DMA_0: 609 case XFER_SW_DMA_0:
634 break; 610 break;
635 case XFER_PIO_4: return((int) config_chipset_for_pio(drive, 4)); 611 case XFER_PIO_4:
636 case XFER_PIO_3: return((int) config_chipset_for_pio(drive, 3)); 612 case XFER_PIO_3:
637 case XFER_PIO_2: return((int) config_chipset_for_pio(drive, 2)); 613 case XFER_PIO_2:
638 case XFER_PIO_1: return((int) config_chipset_for_pio(drive, 1)); 614 case XFER_PIO_1:
639 case XFER_PIO_0: 615 case XFER_PIO_0:
640 default: return((int) config_chipset_for_pio(drive, 0)); 616 return sis5513_tune_drive(drive, speed - XFER_PIO_0);
617 default:
618 BUG();
619 break;
641 } 620 }
642 621
643 return ((int) ide_config_drive_speed(drive, speed)); 622 return ide_config_drive_speed(drive, speed);
644}
645
646static void sis5513_tune_drive (ide_drive_t *drive, u8 pio)
647{
648 (void) config_chipset_for_pio(drive, pio);
649}
650
651/*
652 * ((id->hw_config & 0x4000|0x2000) && (HWIF(drive)->udma_four))
653 */
654static int config_chipset_for_dma (ide_drive_t *drive)
655{
656 u8 speed = ide_dma_speed(drive, sis5513_ratemask(drive));
657
658#ifdef DEBUG
659 printk("SIS5513: config_chipset_for_dma, drive %d, ultra %x\n",
660 drive->dn, drive->id->dma_ultra);
661#endif
662
663 if (!(speed))
664 return 0;
665
666 sis5513_tune_chipset(drive, speed);
667 return ide_dma_enable(drive);
668} 623}
669 624
670static int sis5513_config_xfer_rate(ide_drive_t *drive) 625static int sis5513_config_xfer_rate(ide_drive_t *drive)
671{ 626{
672 config_art_rwp_pio(drive, 5); 627 /*
628 * TODO: always set PIO mode and remove this
629 */
630 sis5513_tuneproc(drive, 255);
673 631
674 drive->init_speed = 0; 632 drive->init_speed = 0;
675 633
676 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 634 if (ide_tune_dma(drive))
677 return 0; 635 return 0;
678 636
679 if (ide_use_fast_pio(drive)) 637 if (ide_use_fast_pio(drive))
680 sis5513_tune_drive(drive, 5); 638 sis5513_tuneproc(drive, 255);
681 639
682 return -1; 640 return -1;
683} 641}
@@ -826,7 +784,7 @@ static unsigned int __devinit init_chipset_sis5513 (struct pci_dev *dev, const c
826 break; 784 break;
827 } 785 }
828 786
829#if defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_PROC_FS) 787#if defined(DISPLAY_SIS_TIMINGS) && defined(CONFIG_IDE_PROC_FS)
830 if (!sis_proc) { 788 if (!sis_proc) {
831 sis_proc = 1; 789 sis_proc = 1;
832 bmide_dev = dev; 790 bmide_dev = dev;
@@ -858,12 +816,14 @@ static unsigned int __devinit ata66_sis5513 (ide_hwif_t *hwif)
858 816
859static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif) 817static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
860{ 818{
819 u8 udma_rates[] = { 0x00, 0x00, 0x07, 0x1f, 0x3f, 0x3f, 0x7f, 0x7f };
820
861 hwif->autodma = 0; 821 hwif->autodma = 0;
862 822
863 if (!hwif->irq) 823 if (!hwif->irq)
864 hwif->irq = hwif->channel ? 15 : 14; 824 hwif->irq = hwif->channel ? 15 : 14;
865 825
866 hwif->tuneproc = &sis5513_tune_drive; 826 hwif->tuneproc = &sis5513_tuneproc;
867 hwif->speedproc = &sis5513_tune_chipset; 827 hwif->speedproc = &sis5513_tune_chipset;
868 828
869 if (!(hwif->dma_base)) { 829 if (!(hwif->dma_base)) {
@@ -873,7 +833,8 @@ static void __devinit init_hwif_sis5513 (ide_hwif_t *hwif)
873 } 833 }
874 834
875 hwif->atapi_dma = 1; 835 hwif->atapi_dma = 1;
876 hwif->ultra_mask = 0x7f; 836
837 hwif->ultra_mask = udma_rates[chipset_family];
877 hwif->mwdma_mask = 0x07; 838 hwif->mwdma_mask = 0x07;
878 hwif->swdma_mask = 0x07; 839 hwif->swdma_mask = 0x07;
879 840
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index fe3b4b91f854..7c383d9cc472 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -82,7 +82,14 @@ static u8 sl82c105_tune_pio(ide_drive_t *drive, u8 pio)
82 82
83 pio = ide_get_best_pio_mode(drive, pio, 5, &p); 83 pio = ide_get_best_pio_mode(drive, pio, 5, &p);
84 84
85 drive->drive_data = drv_ctrl = get_pio_timings(&p); 85 drv_ctrl = get_pio_timings(&p);
86
87 /*
88 * Store the PIO timings so that we can restore them
89 * in case DMA will be turned off...
90 */
91 drive->drive_data &= 0xffff0000;
92 drive->drive_data |= drv_ctrl;
86 93
87 if (!drive->using_dma) { 94 if (!drive->using_dma) {
88 /* 95 /*
@@ -100,17 +107,55 @@ static u8 sl82c105_tune_pio(ide_drive_t *drive, u8 pio)
100} 107}
101 108
102/* 109/*
103 * Configure the drive for DMA. 110 * Configure the drive and chipset for a new transfer speed.
104 * We'll program the chipset only when DMA is actually turned on.
105 */ 111 */
106static int config_for_dma(ide_drive_t *drive) 112static int sl82c105_tune_chipset(ide_drive_t *drive, u8 speed)
107{ 113{
108 DBG(("config_for_dma(drive:%s)\n", drive->name)); 114 static u16 mwdma_timings[] = {0x0707, 0x0201, 0x0200};
115 u16 drv_ctrl;
109 116
110 if (ide_config_drive_speed(drive, XFER_MW_DMA_2) != 0) 117 DBG(("sl82c105_tune_chipset(drive:%s, speed:%s)\n",
111 return 0; 118 drive->name, ide_xfer_verbose(speed)));
112 119
113 return ide_dma_enable(drive); 120 speed = ide_rate_filter(drive, speed);
121
122 switch (speed) {
123 case XFER_MW_DMA_2:
124 case XFER_MW_DMA_1:
125 case XFER_MW_DMA_0:
126 drv_ctrl = mwdma_timings[speed - XFER_MW_DMA_0];
127
128 /*
129 * Store the DMA timings so that we can actually program
130 * them when DMA will be turned on...
131 */
132 drive->drive_data &= 0x0000ffff;
133 drive->drive_data |= (unsigned long)drv_ctrl << 16;
134
135 /*
136 * If we are already using DMA, we just reprogram
137 * the drive control register.
138 */
139 if (drive->using_dma) {
140 struct pci_dev *dev = HWIF(drive)->pci_dev;
141 int reg = 0x44 + drive->dn * 4;
142
143 pci_write_config_word(dev, reg, drv_ctrl);
144 }
145 break;
146 case XFER_PIO_5:
147 case XFER_PIO_4:
148 case XFER_PIO_3:
149 case XFER_PIO_2:
150 case XFER_PIO_1:
151 case XFER_PIO_0:
152 (void) sl82c105_tune_pio(drive, speed - XFER_PIO_0);
153 break;
154 default:
155 return -1;
156 }
157
158 return ide_config_drive_speed(drive, speed);
114} 159}
115 160
116/* 161/*
@@ -120,7 +165,7 @@ static int sl82c105_ide_dma_check(ide_drive_t *drive)
120{ 165{
121 DBG(("sl82c105_ide_dma_check(drive:%s)\n", drive->name)); 166 DBG(("sl82c105_ide_dma_check(drive:%s)\n", drive->name));
122 167
123 if (ide_use_dma(drive) && config_for_dma(drive)) 168 if (ide_tune_dma(drive))
124 return 0; 169 return 0;
125 170
126 return -1; 171 return -1;
@@ -219,7 +264,7 @@ static int sl82c105_ide_dma_on(ide_drive_t *drive)
219 264
220 rc = __ide_dma_on(drive); 265 rc = __ide_dma_on(drive);
221 if (rc == 0) { 266 if (rc == 0) {
222 pci_write_config_word(dev, reg, 0x0200); 267 pci_write_config_word(dev, reg, drive->drive_data >> 16);
223 268
224 printk(KERN_INFO "%s: DMA enabled\n", drive->name); 269 printk(KERN_INFO "%s: DMA enabled\n", drive->name);
225 } 270 }
@@ -304,7 +349,7 @@ static unsigned int sl82c105_bridge_revision(struct pci_dev *dev)
304 /* 349 /*
305 * The bridge should be part of the same device, but function 0. 350 * The bridge should be part of the same device, but function 0.
306 */ 351 */
307 bridge = pci_find_slot(dev->bus->number, 352 bridge = pci_get_bus_and_slot(dev->bus->number,
308 PCI_DEVFN(PCI_SLOT(dev->devfn), 0)); 353 PCI_DEVFN(PCI_SLOT(dev->devfn), 0));
309 if (!bridge) 354 if (!bridge)
310 return -1; 355 return -1;
@@ -314,13 +359,15 @@ static unsigned int sl82c105_bridge_revision(struct pci_dev *dev)
314 */ 359 */
315 if (bridge->vendor != PCI_VENDOR_ID_WINBOND || 360 if (bridge->vendor != PCI_VENDOR_ID_WINBOND ||
316 bridge->device != PCI_DEVICE_ID_WINBOND_83C553 || 361 bridge->device != PCI_DEVICE_ID_WINBOND_83C553 ||
317 bridge->class >> 8 != PCI_CLASS_BRIDGE_ISA) 362 bridge->class >> 8 != PCI_CLASS_BRIDGE_ISA) {
363 pci_dev_put(bridge);
318 return -1; 364 return -1;
319 365 }
320 /* 366 /*
321 * We need to find function 0's revision, not function 1 367 * We need to find function 0's revision, not function 1
322 */ 368 */
323 pci_read_config_byte(bridge, PCI_REVISION_ID, &rev); 369 pci_read_config_byte(bridge, PCI_REVISION_ID, &rev);
370 pci_dev_put(bridge);
324 371
325 return rev; 372 return rev;
326} 373}
@@ -357,6 +404,7 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
357 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index)); 404 DBG(("init_hwif_sl82c105(hwif: ide%d)\n", hwif->index));
358 405
359 hwif->tuneproc = &sl82c105_tune_drive; 406 hwif->tuneproc = &sl82c105_tune_drive;
407 hwif->speedproc = &sl82c105_tune_chipset;
360 hwif->selectproc = &sl82c105_selectproc; 408 hwif->selectproc = &sl82c105_selectproc;
361 hwif->resetproc = &sl82c105_resetproc; 409 hwif->resetproc = &sl82c105_resetproc;
362 410
@@ -388,7 +436,7 @@ static void __devinit init_hwif_sl82c105(ide_hwif_t *hwif)
388 } 436 }
389 437
390 hwif->atapi_dma = 1; 438 hwif->atapi_dma = 1;
391 hwif->mwdma_mask = 0x04; 439 hwif->mwdma_mask = 0x07;
392 440
393 hwif->ide_dma_check = &sl82c105_ide_dma_check; 441 hwif->ide_dma_check = &sl82c105_ide_dma_check;
394 hwif->ide_dma_on = &sl82c105_ide_dma_on; 442 hwif->ide_dma_on = &sl82c105_ide_dma_on;
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index 852ccb36da1d..c40f291f91e0 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -21,15 +21,6 @@
21 21
22#include <asm/io.h> 22#include <asm/io.h>
23 23
24static u8 slc90e66_ratemask (ide_drive_t *drive)
25{
26 u8 mode = 2;
27
28 if (!eighty_ninty_three(drive))
29 mode = min_t(u8, mode, 1);
30 return mode;
31}
32
33static u8 slc90e66_dma_2_pio (u8 xfer_rate) { 24static u8 slc90e66_dma_2_pio (u8 xfer_rate) {
34 switch(xfer_rate) { 25 switch(xfer_rate) {
35 case XFER_UDMA_4: 26 case XFER_UDMA_4:
@@ -122,7 +113,7 @@ static int slc90e66_tune_chipset (ide_drive_t *drive, u8 xferspeed)
122 ide_hwif_t *hwif = HWIF(drive); 113 ide_hwif_t *hwif = HWIF(drive);
123 struct pci_dev *dev = hwif->pci_dev; 114 struct pci_dev *dev = hwif->pci_dev;
124 u8 maslave = hwif->channel ? 0x42 : 0x40; 115 u8 maslave = hwif->channel ? 0x42 : 0x40;
125 u8 speed = ide_rate_filter(slc90e66_ratemask(drive), xferspeed); 116 u8 speed = ide_rate_filter(drive, xferspeed);
126 int sitre = 0, a_speed = 7 << (drive->dn * 4); 117 int sitre = 0, a_speed = 7 << (drive->dn * 4);
127 int u_speed = 0, u_flag = 1 << drive->dn; 118 int u_speed = 0, u_flag = 1 << drive->dn;
128 u16 reg4042, reg44, reg48, reg4a; 119 u16 reg4042, reg44, reg48, reg4a;
@@ -169,22 +160,11 @@ static int slc90e66_tune_chipset (ide_drive_t *drive, u8 xferspeed)
169 return ide_config_drive_speed(drive, speed); 160 return ide_config_drive_speed(drive, speed);
170} 161}
171 162
172static int slc90e66_config_drive_for_dma (ide_drive_t *drive)
173{
174 u8 speed = ide_dma_speed(drive, slc90e66_ratemask(drive));
175
176 if (!speed)
177 return 0;
178
179 (void) slc90e66_tune_chipset(drive, speed);
180 return ide_dma_enable(drive);
181}
182
183static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive) 163static int slc90e66_config_drive_xfer_rate (ide_drive_t *drive)
184{ 164{
185 drive->init_speed = 0; 165 drive->init_speed = 0;
186 166
187 if (ide_use_dma(drive) && slc90e66_config_drive_for_dma(drive)) 167 if (ide_tune_dma(drive))
188 return 0; 168 return 0;
189 169
190 if (ide_use_fast_pio(drive)) 170 if (ide_use_fast_pio(drive))
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 0b6d81d6ce48..cee619bb2eaf 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -13,18 +13,13 @@
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/ide.h> 14#include <linux/ide.h>
15 15
16static inline u8 tc86c001_ratemask(ide_drive_t *drive)
17{
18 return eighty_ninty_three(drive) ? 2 : 1;
19}
20
21static int tc86c001_tune_chipset(ide_drive_t *drive, u8 speed) 16static int tc86c001_tune_chipset(ide_drive_t *drive, u8 speed)
22{ 17{
23 ide_hwif_t *hwif = HWIF(drive); 18 ide_hwif_t *hwif = HWIF(drive);
24 unsigned long scr_port = hwif->config_data + (drive->dn ? 0x02 : 0x00); 19 unsigned long scr_port = hwif->config_data + (drive->dn ? 0x02 : 0x00);
25 u16 mode, scr = hwif->INW(scr_port); 20 u16 mode, scr = hwif->INW(scr_port);
26 21
27 speed = ide_rate_filter(tc86c001_ratemask(drive), speed); 22 speed = ide_rate_filter(drive, speed);
28 23
29 switch (speed) { 24 switch (speed) {
30 case XFER_UDMA_4: mode = 0x00c0; break; 25 case XFER_UDMA_4: mode = 0x00c0; break;
@@ -172,20 +167,9 @@ static int tc86c001_busproc(ide_drive_t *drive, int state)
172 return 0; 167 return 0;
173} 168}
174 169
175static int config_chipset_for_dma(ide_drive_t *drive)
176{
177 u8 speed = ide_dma_speed(drive, tc86c001_ratemask(drive));
178
179 if (!speed)
180 return 0;
181
182 (void) tc86c001_tune_chipset(drive, speed);
183 return ide_dma_enable(drive);
184}
185
186static int tc86c001_config_drive_xfer_rate(ide_drive_t *drive) 170static int tc86c001_config_drive_xfer_rate(ide_drive_t *drive)
187{ 171{
188 if (ide_use_dma(drive) && config_chipset_for_dma(drive)) 172 if (ide_tune_dma(drive))
189 return 0; 173 return 0;
190 174
191 if (ide_use_fast_pio(drive)) 175 if (ide_use_fast_pio(drive))
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index 5e06179c3469..35e8c612638f 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -48,7 +48,7 @@ static int triflex_tune_chipset(ide_drive_t *drive, u8 xferspeed)
48 u16 timing = 0; 48 u16 timing = 0;
49 u32 triflex_timings = 0; 49 u32 triflex_timings = 0;
50 u8 unit = (drive->select.b.unit & 0x01); 50 u8 unit = (drive->select.b.unit & 0x01);
51 u8 speed = ide_rate_filter(0, xferspeed); 51 u8 speed = ide_rate_filter(drive, xferspeed);
52 52
53 pci_read_config_dword(dev, channel_offset, &triflex_timings); 53 pci_read_config_dword(dev, channel_offset, &triflex_timings);
54 54
@@ -100,20 +100,9 @@ static void triflex_tune_drive(ide_drive_t *drive, u8 pio)
100 (void) triflex_tune_chipset(drive, (XFER_PIO_0 + use_pio)); 100 (void) triflex_tune_chipset(drive, (XFER_PIO_0 + use_pio));
101} 101}
102 102
103static int triflex_config_drive_for_dma(ide_drive_t *drive)
104{
105 int speed = ide_dma_speed(drive, 0); /* No ultra speeds */
106
107 if (!speed)
108 return 0;
109
110 (void) triflex_tune_chipset(drive, speed);
111 return ide_dma_enable(drive);
112}
113
114static int triflex_config_drive_xfer_rate(ide_drive_t *drive) 103static int triflex_config_drive_xfer_rate(ide_drive_t *drive)
115{ 104{
116 if (ide_use_dma(drive) && triflex_config_drive_for_dma(drive)) 105 if (ide_tune_dma(drive))
117 return 0; 106 return 0;
118 107
119 triflex_tune_drive(drive, 255); 108 triflex_tune_drive(drive, 255);
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index 071a030ec26e..45fc36f0f219 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -1157,32 +1157,32 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1157 1157
1158 pmif->cable_80 = 0; 1158 pmif->cable_80 = 0;
1159 pmif->broken_dma = pmif->broken_dma_warn = 0; 1159 pmif->broken_dma = pmif->broken_dma_warn = 0;
1160 if (device_is_compatible(np, "shasta-ata")) 1160 if (of_device_is_compatible(np, "shasta-ata"))
1161 pmif->kind = controller_sh_ata6; 1161 pmif->kind = controller_sh_ata6;
1162 else if (device_is_compatible(np, "kauai-ata")) 1162 else if (of_device_is_compatible(np, "kauai-ata"))
1163 pmif->kind = controller_un_ata6; 1163 pmif->kind = controller_un_ata6;
1164 else if (device_is_compatible(np, "K2-UATA")) 1164 else if (of_device_is_compatible(np, "K2-UATA"))
1165 pmif->kind = controller_k2_ata6; 1165 pmif->kind = controller_k2_ata6;
1166 else if (device_is_compatible(np, "keylargo-ata")) { 1166 else if (of_device_is_compatible(np, "keylargo-ata")) {
1167 if (strcmp(np->name, "ata-4") == 0) 1167 if (strcmp(np->name, "ata-4") == 0)
1168 pmif->kind = controller_kl_ata4; 1168 pmif->kind = controller_kl_ata4;
1169 else 1169 else
1170 pmif->kind = controller_kl_ata3; 1170 pmif->kind = controller_kl_ata3;
1171 } else if (device_is_compatible(np, "heathrow-ata")) 1171 } else if (of_device_is_compatible(np, "heathrow-ata"))
1172 pmif->kind = controller_heathrow; 1172 pmif->kind = controller_heathrow;
1173 else { 1173 else {
1174 pmif->kind = controller_ohare; 1174 pmif->kind = controller_ohare;
1175 pmif->broken_dma = 1; 1175 pmif->broken_dma = 1;
1176 } 1176 }
1177 1177
1178 bidp = get_property(np, "AAPL,bus-id", NULL); 1178 bidp = of_get_property(np, "AAPL,bus-id", NULL);
1179 pmif->aapl_bus_id = bidp ? *bidp : 0; 1179 pmif->aapl_bus_id = bidp ? *bidp : 0;
1180 1180
1181 /* Get cable type from device-tree */ 1181 /* Get cable type from device-tree */
1182 if (pmif->kind == controller_kl_ata4 || pmif->kind == controller_un_ata6 1182 if (pmif->kind == controller_kl_ata4 || pmif->kind == controller_un_ata6
1183 || pmif->kind == controller_k2_ata6 1183 || pmif->kind == controller_k2_ata6
1184 || pmif->kind == controller_sh_ata6) { 1184 || pmif->kind == controller_sh_ata6) {
1185 const char* cable = get_property(np, "cable-type", NULL); 1185 const char* cable = of_get_property(np, "cable-type", NULL);
1186 if (cable && !strncmp(cable, "80-", 3)) 1186 if (cable && !strncmp(cable, "80-", 3))
1187 pmif->cable_80 = 1; 1187 pmif->cable_80 = 1;
1188 } 1188 }
@@ -1190,8 +1190,8 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1190 * they have a 80 conductor cable, this seem to be always the case unless 1190 * they have a 80 conductor cable, this seem to be always the case unless
1191 * the user mucked around 1191 * the user mucked around
1192 */ 1192 */
1193 if (device_is_compatible(np, "K2-UATA") || 1193 if (of_device_is_compatible(np, "K2-UATA") ||
1194 device_is_compatible(np, "shasta-ata")) 1194 of_device_is_compatible(np, "shasta-ata"))
1195 pmif->cable_80 = 1; 1195 pmif->cable_80 = 1;
1196 1196
1197 /* On Kauai-type controllers, we make sure the FCR is correct */ 1197 /* On Kauai-type controllers, we make sure the FCR is correct */
@@ -1276,6 +1276,8 @@ pmac_ide_setup_device(pmac_ide_hwif_t *pmif, ide_hwif_t *hwif)
1276 /* We probe the hwif now */ 1276 /* We probe the hwif now */
1277 probe_hwif_init(hwif); 1277 probe_hwif_init(hwif);
1278 1278
1279 ide_proc_register_port(hwif);
1280
1279 return 0; 1281 return 0;
1280} 1282}
1281 1283
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index 118fb3205ca8..67035ba4bf5e 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -702,6 +702,7 @@ out:
702 702
703int ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d) 703int ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d)
704{ 704{
705 ide_hwif_t *hwif = NULL, *mate = NULL;
705 ata_index_t index_list; 706 ata_index_t index_list;
706 int ret; 707 int ret;
707 708
@@ -710,11 +711,19 @@ int ide_setup_pci_device(struct pci_dev *dev, ide_pci_device_t *d)
710 goto out; 711 goto out;
711 712
712 if ((index_list.b.low & 0xf0) != 0xf0) 713 if ((index_list.b.low & 0xf0) != 0xf0)
713 probe_hwif_init_with_fixup(&ide_hwifs[index_list.b.low], d->fixup); 714 hwif = &ide_hwifs[index_list.b.low];
714 if ((index_list.b.high & 0xf0) != 0xf0) 715 if ((index_list.b.high & 0xf0) != 0xf0)
715 probe_hwif_init_with_fixup(&ide_hwifs[index_list.b.high], d->fixup); 716 mate = &ide_hwifs[index_list.b.high];
716 717
717 create_proc_ide_interfaces(); 718 if (hwif)
719 probe_hwif_init_with_fixup(hwif, d->fixup);
720 if (mate)
721 probe_hwif_init_with_fixup(mate, d->fixup);
722
723 if (hwif)
724 ide_proc_register_port(hwif);
725 if (mate)
726 ide_proc_register_port(mate);
718out: 727out:
719 return ret; 728 return ret;
720} 729}
@@ -748,13 +757,22 @@ int ide_setup_pci_devices(struct pci_dev *dev1, struct pci_dev *dev2,
748 } 757 }
749 } 758 }
750 759
751 create_proc_ide_interfaces(); 760 for (i = 0; i < 2; i++) {
761 u8 idx[2] = { index_list[i].b.low, index_list[i].b.high };
762 int j;
763
764 for (j = 0; j < 2; j++) {
765 if ((idx[j] & 0xf0) != 0xf0)
766 ide_proc_register_port(ide_hwifs + idx[j]);
767 }
768 }
752out: 769out:
753 return ret; 770 return ret;
754} 771}
755 772
756EXPORT_SYMBOL_GPL(ide_setup_pci_devices); 773EXPORT_SYMBOL_GPL(ide_setup_pci_devices);
757 774
775#ifdef CONFIG_IDEPCI_PCIBUS_ORDER
758/* 776/*
759 * Module interfaces 777 * Module interfaces
760 */ 778 */
@@ -861,3 +879,4 @@ void __init ide_scan_pcibus (int scan_direction)
861 __pci_register_driver(d, d->driver.owner, d->driver.mod_name); 879 __pci_register_driver(d, d->driver.owner, d->driver.mod_name);
862 } 880 }
863} 881}
882#endif
diff --git a/drivers/ieee1394/Kconfig b/drivers/ieee1394/Kconfig
index 61d7809a5a26..8012b3b0ce75 100644
--- a/drivers/ieee1394/Kconfig
+++ b/drivers/ieee1394/Kconfig
@@ -1,4 +1,7 @@
1menu "IEEE 1394 (FireWire) support" 1menu "IEEE 1394 (FireWire) support"
2 depends on PCI || BROKEN
3
4source "drivers/firewire/Kconfig"
2 5
3config IEEE1394 6config IEEE1394
4 tristate "IEEE 1394 (FireWire) support" 7 tristate "IEEE 1394 (FireWire) support"
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index 026e38face5c..208141377612 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -94,7 +94,6 @@
94#include <linux/pci.h> 94#include <linux/pci.h>
95#include <linux/fs.h> 95#include <linux/fs.h>
96#include <linux/poll.h> 96#include <linux/poll.h>
97#include <linux/smp_lock.h>
98#include <linux/mutex.h> 97#include <linux/mutex.h>
99#include <linux/bitops.h> 98#include <linux/bitops.h>
100#include <asm/byteorder.h> 99#include <asm/byteorder.h>
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 6a1a0572275e..835937e38529 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -1702,7 +1702,7 @@ static int nodemgr_host_thread(void *__hi)
1702 generation = get_hpsb_generation(host); 1702 generation = get_hpsb_generation(host);
1703 1703
1704 /* If we get a reset before we are done waiting, then 1704 /* If we get a reset before we are done waiting, then
1705 * start the the waiting over again */ 1705 * start the waiting over again */
1706 if (generation != g) 1706 if (generation != g)
1707 g = generation, i = 0; 1707 g = generation, i = 0;
1708 } 1708 }
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index c6aefd9ad0e8..d382500f4210 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -35,7 +35,6 @@
35#include <linux/poll.h> 35#include <linux/poll.h>
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/smp_lock.h>
39#include <linux/interrupt.h> 38#include <linux/interrupt.h>
40#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
41#include <linux/cdev.h> 40#include <linux/cdev.h>
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index 95ca26d75272..87ebd0846c34 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -39,7 +39,6 @@
39#include <linux/pci.h> 39#include <linux/pci.h>
40#include <linux/fs.h> 40#include <linux/fs.h>
41#include <linux/poll.h> 41#include <linux/poll.h>
42#include <linux/smp_lock.h>
43#include <linux/delay.h> 42#include <linux/delay.h>
44#include <linux/bitops.h> 43#include <linux/bitops.h>
45#include <linux/types.h> 44#include <linux/types.h>
diff --git a/drivers/infiniband/Kconfig b/drivers/infiniband/Kconfig
index 66b36de9fa6f..994decc7bcf2 100644
--- a/drivers/infiniband/Kconfig
+++ b/drivers/infiniband/Kconfig
@@ -1,4 +1,5 @@
1menu "InfiniBand support" 1menu "InfiniBand support"
2 depends on HAS_IOMEM
2 3
3config INFINIBAND 4config INFINIBAND
4 depends on PCI || BROKEN 5 depends on PCI || BROKEN
@@ -29,6 +30,11 @@ config INFINIBAND_USER_ACCESS
29 libibverbs, libibcm and a hardware driver library from 30 libibverbs, libibcm and a hardware driver library from
30 <http://www.openib.org>. 31 <http://www.openib.org>.
31 32
33config INFINIBAND_USER_MEM
34 bool
35 depends on INFINIBAND_USER_ACCESS != n
36 default y
37
32config INFINIBAND_ADDR_TRANS 38config INFINIBAND_ADDR_TRANS
33 bool 39 bool
34 depends on INFINIBAND && INET 40 depends on INFINIBAND && INET
@@ -40,6 +46,8 @@ source "drivers/infiniband/hw/ehca/Kconfig"
40source "drivers/infiniband/hw/amso1100/Kconfig" 46source "drivers/infiniband/hw/amso1100/Kconfig"
41source "drivers/infiniband/hw/cxgb3/Kconfig" 47source "drivers/infiniband/hw/cxgb3/Kconfig"
42 48
49source "drivers/infiniband/hw/mlx4/Kconfig"
50
43source "drivers/infiniband/ulp/ipoib/Kconfig" 51source "drivers/infiniband/ulp/ipoib/Kconfig"
44 52
45source "drivers/infiniband/ulp/srp/Kconfig" 53source "drivers/infiniband/ulp/srp/Kconfig"
diff --git a/drivers/infiniband/Makefile b/drivers/infiniband/Makefile
index da2066c4f22c..75f325e40b54 100644
--- a/drivers/infiniband/Makefile
+++ b/drivers/infiniband/Makefile
@@ -4,6 +4,7 @@ obj-$(CONFIG_INFINIBAND_IPATH) += hw/ipath/
4obj-$(CONFIG_INFINIBAND_EHCA) += hw/ehca/ 4obj-$(CONFIG_INFINIBAND_EHCA) += hw/ehca/
5obj-$(CONFIG_INFINIBAND_AMSO1100) += hw/amso1100/ 5obj-$(CONFIG_INFINIBAND_AMSO1100) += hw/amso1100/
6obj-$(CONFIG_INFINIBAND_CXGB3) += hw/cxgb3/ 6obj-$(CONFIG_INFINIBAND_CXGB3) += hw/cxgb3/
7obj-$(CONFIG_MLX4_INFINIBAND) += hw/mlx4/
7obj-$(CONFIG_INFINIBAND_IPOIB) += ulp/ipoib/ 8obj-$(CONFIG_INFINIBAND_IPOIB) += ulp/ipoib/
8obj-$(CONFIG_INFINIBAND_SRP) += ulp/srp/ 9obj-$(CONFIG_INFINIBAND_SRP) += ulp/srp/
9obj-$(CONFIG_INFINIBAND_ISER) += ulp/iser/ 10obj-$(CONFIG_INFINIBAND_ISER) += ulp/iser/
diff --git a/drivers/infiniband/core/Makefile b/drivers/infiniband/core/Makefile
index 189e5d4b9b17..cb1ab3ea4998 100644
--- a/drivers/infiniband/core/Makefile
+++ b/drivers/infiniband/core/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_INFINIBAND_USER_ACCESS) += ib_uverbs.o ib_ucm.o \
9 9
10ib_core-y := packer.o ud_header.o verbs.o sysfs.o \ 10ib_core-y := packer.o ud_header.o verbs.o sysfs.o \
11 device.o fmr_pool.o cache.o 11 device.o fmr_pool.o cache.o
12ib_core-$(CONFIG_INFINIBAND_USER_MEM) += umem.o
12 13
13ib_mad-y := mad.o smi.o agent.o mad_rmpp.o 14ib_mad-y := mad.o smi.o agent.o mad_rmpp.o
14 15
@@ -28,5 +29,4 @@ ib_umad-y := user_mad.o
28 29
29ib_ucm-y := ucm.o 30ib_ucm-y := ucm.o
30 31
31ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_mem.o \ 32ib_uverbs-y := uverbs_main.o uverbs_cmd.o uverbs_marshall.o
32 uverbs_marshall.o
diff --git a/drivers/infiniband/core/cache.c b/drivers/infiniband/core/cache.c
index 558c9a0fc8b9..e85f7013de57 100644
--- a/drivers/infiniband/core/cache.c
+++ b/drivers/infiniband/core/cache.c
@@ -38,6 +38,7 @@
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/errno.h> 39#include <linux/errno.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/workqueue.h>
41 42
42#include <rdma/ib_cache.h> 43#include <rdma/ib_cache.h>
43 44
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index eff591deeb46..e840434a96d8 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -306,7 +306,9 @@ static int cm_alloc_id(struct cm_id_private *cm_id_priv)
306 do { 306 do {
307 spin_lock_irqsave(&cm.lock, flags); 307 spin_lock_irqsave(&cm.lock, flags);
308 ret = idr_get_new_above(&cm.local_id_table, cm_id_priv, 308 ret = idr_get_new_above(&cm.local_id_table, cm_id_priv,
309 next_id++, &id); 309 next_id, &id);
310 if (!ret)
311 next_id = ((unsigned) id + 1) & MAX_ID_MASK;
310 spin_unlock_irqrestore(&cm.lock, flags); 312 spin_unlock_irqrestore(&cm.lock, flags);
311 } while( (ret == -EAGAIN) && idr_pre_get(&cm.local_id_table, GFP_KERNEL) ); 313 } while( (ret == -EAGAIN) && idr_pre_get(&cm.local_id_table, GFP_KERNEL) );
312 314
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
index fde92ce45153..2eb52b7a71da 100644
--- a/drivers/infiniband/core/cma.c
+++ b/drivers/infiniband/core/cma.c
@@ -346,12 +346,33 @@ static void cma_deref_id(struct rdma_id_private *id_priv)
346 complete(&id_priv->comp); 346 complete(&id_priv->comp);
347} 347}
348 348
349static void cma_release_remove(struct rdma_id_private *id_priv) 349static int cma_disable_remove(struct rdma_id_private *id_priv,
350 enum cma_state state)
351{
352 unsigned long flags;
353 int ret;
354
355 spin_lock_irqsave(&id_priv->lock, flags);
356 if (id_priv->state == state) {
357 atomic_inc(&id_priv->dev_remove);
358 ret = 0;
359 } else
360 ret = -EINVAL;
361 spin_unlock_irqrestore(&id_priv->lock, flags);
362 return ret;
363}
364
365static void cma_enable_remove(struct rdma_id_private *id_priv)
350{ 366{
351 if (atomic_dec_and_test(&id_priv->dev_remove)) 367 if (atomic_dec_and_test(&id_priv->dev_remove))
352 wake_up(&id_priv->wait_remove); 368 wake_up(&id_priv->wait_remove);
353} 369}
354 370
371static int cma_has_cm_dev(struct rdma_id_private *id_priv)
372{
373 return (id_priv->id.device && id_priv->cm_id.ib);
374}
375
355struct rdma_cm_id *rdma_create_id(rdma_cm_event_handler event_handler, 376struct rdma_cm_id *rdma_create_id(rdma_cm_event_handler event_handler,
356 void *context, enum rdma_port_space ps) 377 void *context, enum rdma_port_space ps)
357{ 378{
@@ -884,9 +905,8 @@ static int cma_ib_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
884 struct rdma_cm_event event; 905 struct rdma_cm_event event;
885 int ret = 0; 906 int ret = 0;
886 907
887 atomic_inc(&id_priv->dev_remove); 908 if (cma_disable_remove(id_priv, CMA_CONNECT))
888 if (!cma_comp(id_priv, CMA_CONNECT)) 909 return 0;
889 goto out;
890 910
891 memset(&event, 0, sizeof event); 911 memset(&event, 0, sizeof event);
892 switch (ib_event->event) { 912 switch (ib_event->event) {
@@ -942,12 +962,12 @@ static int cma_ib_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
942 /* Destroy the CM ID by returning a non-zero value. */ 962 /* Destroy the CM ID by returning a non-zero value. */
943 id_priv->cm_id.ib = NULL; 963 id_priv->cm_id.ib = NULL;
944 cma_exch(id_priv, CMA_DESTROYING); 964 cma_exch(id_priv, CMA_DESTROYING);
945 cma_release_remove(id_priv); 965 cma_enable_remove(id_priv);
946 rdma_destroy_id(&id_priv->id); 966 rdma_destroy_id(&id_priv->id);
947 return ret; 967 return ret;
948 } 968 }
949out: 969out:
950 cma_release_remove(id_priv); 970 cma_enable_remove(id_priv);
951 return ret; 971 return ret;
952} 972}
953 973
@@ -1057,11 +1077,8 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
1057 int offset, ret; 1077 int offset, ret;
1058 1078
1059 listen_id = cm_id->context; 1079 listen_id = cm_id->context;
1060 atomic_inc(&listen_id->dev_remove); 1080 if (cma_disable_remove(listen_id, CMA_LISTEN))
1061 if (!cma_comp(listen_id, CMA_LISTEN)) { 1081 return -ECONNABORTED;
1062 ret = -ECONNABORTED;
1063 goto out;
1064 }
1065 1082
1066 memset(&event, 0, sizeof event); 1083 memset(&event, 0, sizeof event);
1067 offset = cma_user_data_offset(listen_id->id.ps); 1084 offset = cma_user_data_offset(listen_id->id.ps);
@@ -1101,11 +1118,11 @@ static int cma_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *ib_event)
1101 1118
1102release_conn_id: 1119release_conn_id:
1103 cma_exch(conn_id, CMA_DESTROYING); 1120 cma_exch(conn_id, CMA_DESTROYING);
1104 cma_release_remove(conn_id); 1121 cma_enable_remove(conn_id);
1105 rdma_destroy_id(&conn_id->id); 1122 rdma_destroy_id(&conn_id->id);
1106 1123
1107out: 1124out:
1108 cma_release_remove(listen_id); 1125 cma_enable_remove(listen_id);
1109 return ret; 1126 return ret;
1110} 1127}
1111 1128
@@ -1171,9 +1188,10 @@ static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event)
1171 struct sockaddr_in *sin; 1188 struct sockaddr_in *sin;
1172 int ret = 0; 1189 int ret = 0;
1173 1190
1174 memset(&event, 0, sizeof event); 1191 if (cma_disable_remove(id_priv, CMA_CONNECT))
1175 atomic_inc(&id_priv->dev_remove); 1192 return 0;
1176 1193
1194 memset(&event, 0, sizeof event);
1177 switch (iw_event->event) { 1195 switch (iw_event->event) {
1178 case IW_CM_EVENT_CLOSE: 1196 case IW_CM_EVENT_CLOSE:
1179 event.event = RDMA_CM_EVENT_DISCONNECTED; 1197 event.event = RDMA_CM_EVENT_DISCONNECTED;
@@ -1214,12 +1232,12 @@ static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event)
1214 /* Destroy the CM ID by returning a non-zero value. */ 1232 /* Destroy the CM ID by returning a non-zero value. */
1215 id_priv->cm_id.iw = NULL; 1233 id_priv->cm_id.iw = NULL;
1216 cma_exch(id_priv, CMA_DESTROYING); 1234 cma_exch(id_priv, CMA_DESTROYING);
1217 cma_release_remove(id_priv); 1235 cma_enable_remove(id_priv);
1218 rdma_destroy_id(&id_priv->id); 1236 rdma_destroy_id(&id_priv->id);
1219 return ret; 1237 return ret;
1220 } 1238 }
1221 1239
1222 cma_release_remove(id_priv); 1240 cma_enable_remove(id_priv);
1223 return ret; 1241 return ret;
1224} 1242}
1225 1243
@@ -1234,11 +1252,8 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
1234 int ret; 1252 int ret;
1235 1253
1236 listen_id = cm_id->context; 1254 listen_id = cm_id->context;
1237 atomic_inc(&listen_id->dev_remove); 1255 if (cma_disable_remove(listen_id, CMA_LISTEN))
1238 if (!cma_comp(listen_id, CMA_LISTEN)) { 1256 return -ECONNABORTED;
1239 ret = -ECONNABORTED;
1240 goto out;
1241 }
1242 1257
1243 /* Create a new RDMA id for the new IW CM ID */ 1258 /* Create a new RDMA id for the new IW CM ID */
1244 new_cm_id = rdma_create_id(listen_id->id.event_handler, 1259 new_cm_id = rdma_create_id(listen_id->id.event_handler,
@@ -1255,13 +1270,13 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
1255 dev = ip_dev_find(iw_event->local_addr.sin_addr.s_addr); 1270 dev = ip_dev_find(iw_event->local_addr.sin_addr.s_addr);
1256 if (!dev) { 1271 if (!dev) {
1257 ret = -EADDRNOTAVAIL; 1272 ret = -EADDRNOTAVAIL;
1258 cma_release_remove(conn_id); 1273 cma_enable_remove(conn_id);
1259 rdma_destroy_id(new_cm_id); 1274 rdma_destroy_id(new_cm_id);
1260 goto out; 1275 goto out;
1261 } 1276 }
1262 ret = rdma_copy_addr(&conn_id->id.route.addr.dev_addr, dev, NULL); 1277 ret = rdma_copy_addr(&conn_id->id.route.addr.dev_addr, dev, NULL);
1263 if (ret) { 1278 if (ret) {
1264 cma_release_remove(conn_id); 1279 cma_enable_remove(conn_id);
1265 rdma_destroy_id(new_cm_id); 1280 rdma_destroy_id(new_cm_id);
1266 goto out; 1281 goto out;
1267 } 1282 }
@@ -1270,7 +1285,7 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
1270 ret = cma_acquire_dev(conn_id); 1285 ret = cma_acquire_dev(conn_id);
1271 mutex_unlock(&lock); 1286 mutex_unlock(&lock);
1272 if (ret) { 1287 if (ret) {
1273 cma_release_remove(conn_id); 1288 cma_enable_remove(conn_id);
1274 rdma_destroy_id(new_cm_id); 1289 rdma_destroy_id(new_cm_id);
1275 goto out; 1290 goto out;
1276 } 1291 }
@@ -1293,14 +1308,14 @@ static int iw_conn_req_handler(struct iw_cm_id *cm_id,
1293 /* User wants to destroy the CM ID */ 1308 /* User wants to destroy the CM ID */
1294 conn_id->cm_id.iw = NULL; 1309 conn_id->cm_id.iw = NULL;
1295 cma_exch(conn_id, CMA_DESTROYING); 1310 cma_exch(conn_id, CMA_DESTROYING);
1296 cma_release_remove(conn_id); 1311 cma_enable_remove(conn_id);
1297 rdma_destroy_id(&conn_id->id); 1312 rdma_destroy_id(&conn_id->id);
1298 } 1313 }
1299 1314
1300out: 1315out:
1301 if (dev) 1316 if (dev)
1302 dev_put(dev); 1317 dev_put(dev);
1303 cma_release_remove(listen_id); 1318 cma_enable_remove(listen_id);
1304 return ret; 1319 return ret;
1305} 1320}
1306 1321
@@ -1519,7 +1534,7 @@ static void cma_work_handler(struct work_struct *_work)
1519 destroy = 1; 1534 destroy = 1;
1520 } 1535 }
1521out: 1536out:
1522 cma_release_remove(id_priv); 1537 cma_enable_remove(id_priv);
1523 cma_deref_id(id_priv); 1538 cma_deref_id(id_priv);
1524 if (destroy) 1539 if (destroy)
1525 rdma_destroy_id(&id_priv->id); 1540 rdma_destroy_id(&id_priv->id);
@@ -1711,13 +1726,13 @@ static void addr_handler(int status, struct sockaddr *src_addr,
1711 1726
1712 if (id_priv->id.event_handler(&id_priv->id, &event)) { 1727 if (id_priv->id.event_handler(&id_priv->id, &event)) {
1713 cma_exch(id_priv, CMA_DESTROYING); 1728 cma_exch(id_priv, CMA_DESTROYING);
1714 cma_release_remove(id_priv); 1729 cma_enable_remove(id_priv);
1715 cma_deref_id(id_priv); 1730 cma_deref_id(id_priv);
1716 rdma_destroy_id(&id_priv->id); 1731 rdma_destroy_id(&id_priv->id);
1717 return; 1732 return;
1718 } 1733 }
1719out: 1734out:
1720 cma_release_remove(id_priv); 1735 cma_enable_remove(id_priv);
1721 cma_deref_id(id_priv); 1736 cma_deref_id(id_priv);
1722} 1737}
1723 1738
@@ -2042,11 +2057,10 @@ static int cma_sidr_rep_handler(struct ib_cm_id *cm_id,
2042 struct ib_cm_sidr_rep_event_param *rep = &ib_event->param.sidr_rep_rcvd; 2057 struct ib_cm_sidr_rep_event_param *rep = &ib_event->param.sidr_rep_rcvd;
2043 int ret = 0; 2058 int ret = 0;
2044 2059
2045 memset(&event, 0, sizeof event); 2060 if (cma_disable_remove(id_priv, CMA_CONNECT))
2046 atomic_inc(&id_priv->dev_remove); 2061 return 0;
2047 if (!cma_comp(id_priv, CMA_CONNECT))
2048 goto out;
2049 2062
2063 memset(&event, 0, sizeof event);
2050 switch (ib_event->event) { 2064 switch (ib_event->event) {
2051 case IB_CM_SIDR_REQ_ERROR: 2065 case IB_CM_SIDR_REQ_ERROR:
2052 event.event = RDMA_CM_EVENT_UNREACHABLE; 2066 event.event = RDMA_CM_EVENT_UNREACHABLE;
@@ -2084,12 +2098,12 @@ static int cma_sidr_rep_handler(struct ib_cm_id *cm_id,
2084 /* Destroy the CM ID by returning a non-zero value. */ 2098 /* Destroy the CM ID by returning a non-zero value. */
2085 id_priv->cm_id.ib = NULL; 2099 id_priv->cm_id.ib = NULL;
2086 cma_exch(id_priv, CMA_DESTROYING); 2100 cma_exch(id_priv, CMA_DESTROYING);
2087 cma_release_remove(id_priv); 2101 cma_enable_remove(id_priv);
2088 rdma_destroy_id(&id_priv->id); 2102 rdma_destroy_id(&id_priv->id);
2089 return ret; 2103 return ret;
2090 } 2104 }
2091out: 2105out:
2092 cma_release_remove(id_priv); 2106 cma_enable_remove(id_priv);
2093 return ret; 2107 return ret;
2094} 2108}
2095 2109
@@ -2413,7 +2427,7 @@ int rdma_notify(struct rdma_cm_id *id, enum ib_event_type event)
2413 int ret; 2427 int ret;
2414 2428
2415 id_priv = container_of(id, struct rdma_id_private, id); 2429 id_priv = container_of(id, struct rdma_id_private, id);
2416 if (!cma_comp(id_priv, CMA_CONNECT)) 2430 if (!cma_has_cm_dev(id_priv))
2417 return -EINVAL; 2431 return -EINVAL;
2418 2432
2419 switch (id->device->node_type) { 2433 switch (id->device->node_type) {
@@ -2435,7 +2449,7 @@ int rdma_reject(struct rdma_cm_id *id, const void *private_data,
2435 int ret; 2449 int ret;
2436 2450
2437 id_priv = container_of(id, struct rdma_id_private, id); 2451 id_priv = container_of(id, struct rdma_id_private, id);
2438 if (!cma_comp(id_priv, CMA_CONNECT)) 2452 if (!cma_has_cm_dev(id_priv))
2439 return -EINVAL; 2453 return -EINVAL;
2440 2454
2441 switch (rdma_node_get_transport(id->device->node_type)) { 2455 switch (rdma_node_get_transport(id->device->node_type)) {
@@ -2466,8 +2480,7 @@ int rdma_disconnect(struct rdma_cm_id *id)
2466 int ret; 2480 int ret;
2467 2481
2468 id_priv = container_of(id, struct rdma_id_private, id); 2482 id_priv = container_of(id, struct rdma_id_private, id);
2469 if (!cma_comp(id_priv, CMA_CONNECT) && 2483 if (!cma_has_cm_dev(id_priv))
2470 !cma_comp(id_priv, CMA_DISCONNECT))
2471 return -EINVAL; 2484 return -EINVAL;
2472 2485
2473 switch (rdma_node_get_transport(id->device->node_type)) { 2486 switch (rdma_node_get_transport(id->device->node_type)) {
@@ -2499,10 +2512,9 @@ static int cma_ib_mc_handler(int status, struct ib_sa_multicast *multicast)
2499 int ret; 2512 int ret;
2500 2513
2501 id_priv = mc->id_priv; 2514 id_priv = mc->id_priv;
2502 atomic_inc(&id_priv->dev_remove); 2515 if (cma_disable_remove(id_priv, CMA_ADDR_BOUND) &&
2503 if (!cma_comp(id_priv, CMA_ADDR_BOUND) && 2516 cma_disable_remove(id_priv, CMA_ADDR_RESOLVED))
2504 !cma_comp(id_priv, CMA_ADDR_RESOLVED)) 2517 return 0;
2505 goto out;
2506 2518
2507 if (!status && id_priv->id.qp) 2519 if (!status && id_priv->id.qp)
2508 status = ib_attach_mcast(id_priv->id.qp, &multicast->rec.mgid, 2520 status = ib_attach_mcast(id_priv->id.qp, &multicast->rec.mgid,
@@ -2524,12 +2536,12 @@ static int cma_ib_mc_handler(int status, struct ib_sa_multicast *multicast)
2524 ret = id_priv->id.event_handler(&id_priv->id, &event); 2536 ret = id_priv->id.event_handler(&id_priv->id, &event);
2525 if (ret) { 2537 if (ret) {
2526 cma_exch(id_priv, CMA_DESTROYING); 2538 cma_exch(id_priv, CMA_DESTROYING);
2527 cma_release_remove(id_priv); 2539 cma_enable_remove(id_priv);
2528 rdma_destroy_id(&id_priv->id); 2540 rdma_destroy_id(&id_priv->id);
2529 return 0; 2541 return 0;
2530 } 2542 }
2531out: 2543
2532 cma_release_remove(id_priv); 2544 cma_enable_remove(id_priv);
2533 return 0; 2545 return 0;
2534} 2546}
2535 2547
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 7fabb425b033..3ada17c0f239 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -40,6 +40,7 @@
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/mutex.h> 42#include <linux/mutex.h>
43#include <linux/workqueue.h>
43 44
44#include "core_priv.h" 45#include "core_priv.h"
45 46
@@ -149,6 +150,18 @@ static int alloc_name(char *name)
149 return 0; 150 return 0;
150} 151}
151 152
153static int start_port(struct ib_device *device)
154{
155 return (device->node_type == RDMA_NODE_IB_SWITCH) ? 0 : 1;
156}
157
158
159static int end_port(struct ib_device *device)
160{
161 return (device->node_type == RDMA_NODE_IB_SWITCH) ?
162 0 : device->phys_port_cnt;
163}
164
152/** 165/**
153 * ib_alloc_device - allocate an IB device struct 166 * ib_alloc_device - allocate an IB device struct
154 * @size:size of structure to allocate 167 * @size:size of structure to allocate
@@ -208,6 +221,45 @@ static int add_client_context(struct ib_device *device, struct ib_client *client
208 return 0; 221 return 0;
209} 222}
210 223
224static int read_port_table_lengths(struct ib_device *device)
225{
226 struct ib_port_attr *tprops = NULL;
227 int num_ports, ret = -ENOMEM;
228 u8 port_index;
229
230 tprops = kmalloc(sizeof *tprops, GFP_KERNEL);
231 if (!tprops)
232 goto out;
233
234 num_ports = end_port(device) - start_port(device) + 1;
235
236 device->pkey_tbl_len = kmalloc(sizeof *device->pkey_tbl_len * num_ports,
237 GFP_KERNEL);
238 device->gid_tbl_len = kmalloc(sizeof *device->gid_tbl_len * num_ports,
239 GFP_KERNEL);
240 if (!device->pkey_tbl_len || !device->gid_tbl_len)
241 goto err;
242
243 for (port_index = 0; port_index < num_ports; ++port_index) {
244 ret = ib_query_port(device, port_index + start_port(device),
245 tprops);
246 if (ret)
247 goto err;
248 device->pkey_tbl_len[port_index] = tprops->pkey_tbl_len;
249 device->gid_tbl_len[port_index] = tprops->gid_tbl_len;
250 }
251
252 ret = 0;
253 goto out;
254
255err:
256 kfree(device->gid_tbl_len);
257 kfree(device->pkey_tbl_len);
258out:
259 kfree(tprops);
260 return ret;
261}
262
211/** 263/**
212 * ib_register_device - Register an IB device with IB core 264 * ib_register_device - Register an IB device with IB core
213 * @device:Device to register 265 * @device:Device to register
@@ -239,10 +291,19 @@ int ib_register_device(struct ib_device *device)
239 spin_lock_init(&device->event_handler_lock); 291 spin_lock_init(&device->event_handler_lock);
240 spin_lock_init(&device->client_data_lock); 292 spin_lock_init(&device->client_data_lock);
241 293
294 ret = read_port_table_lengths(device);
295 if (ret) {
296 printk(KERN_WARNING "Couldn't create table lengths cache for device %s\n",
297 device->name);
298 goto out;
299 }
300
242 ret = ib_device_register_sysfs(device); 301 ret = ib_device_register_sysfs(device);
243 if (ret) { 302 if (ret) {
244 printk(KERN_WARNING "Couldn't register device %s with driver model\n", 303 printk(KERN_WARNING "Couldn't register device %s with driver model\n",
245 device->name); 304 device->name);
305 kfree(device->gid_tbl_len);
306 kfree(device->pkey_tbl_len);
246 goto out; 307 goto out;
247 } 308 }
248 309
@@ -284,6 +345,9 @@ void ib_unregister_device(struct ib_device *device)
284 345
285 list_del(&device->core_list); 346 list_del(&device->core_list);
286 347
348 kfree(device->gid_tbl_len);
349 kfree(device->pkey_tbl_len);
350
287 mutex_unlock(&device_mutex); 351 mutex_unlock(&device_mutex);
288 352
289 spin_lock_irqsave(&device->client_data_lock, flags); 353 spin_lock_irqsave(&device->client_data_lock, flags);
@@ -506,10 +570,7 @@ int ib_query_port(struct ib_device *device,
506 u8 port_num, 570 u8 port_num,
507 struct ib_port_attr *port_attr) 571 struct ib_port_attr *port_attr)
508{ 572{
509 if (device->node_type == RDMA_NODE_IB_SWITCH) { 573 if (port_num < start_port(device) || port_num > end_port(device))
510 if (port_num)
511 return -EINVAL;
512 } else if (port_num < 1 || port_num > device->phys_port_cnt)
513 return -EINVAL; 574 return -EINVAL;
514 575
515 return device->query_port(device, port_num, port_attr); 576 return device->query_port(device, port_num, port_attr);
@@ -581,10 +642,7 @@ int ib_modify_port(struct ib_device *device,
581 u8 port_num, int port_modify_mask, 642 u8 port_num, int port_modify_mask,
582 struct ib_port_modify *port_modify) 643 struct ib_port_modify *port_modify)
583{ 644{
584 if (device->node_type == RDMA_NODE_IB_SWITCH) { 645 if (port_num < start_port(device) || port_num > end_port(device))
585 if (port_num)
586 return -EINVAL;
587 } else if (port_num < 1 || port_num > device->phys_port_cnt)
588 return -EINVAL; 646 return -EINVAL;
589 647
590 return device->modify_port(device, port_num, port_modify_mask, 648 return device->modify_port(device, port_num, port_modify_mask,
@@ -592,6 +650,68 @@ int ib_modify_port(struct ib_device *device,
592} 650}
593EXPORT_SYMBOL(ib_modify_port); 651EXPORT_SYMBOL(ib_modify_port);
594 652
653/**
654 * ib_find_gid - Returns the port number and GID table index where
655 * a specified GID value occurs.
656 * @device: The device to query.
657 * @gid: The GID value to search for.
658 * @port_num: The port number of the device where the GID value was found.
659 * @index: The index into the GID table where the GID was found. This
660 * parameter may be NULL.
661 */
662int ib_find_gid(struct ib_device *device, union ib_gid *gid,
663 u8 *port_num, u16 *index)
664{
665 union ib_gid tmp_gid;
666 int ret, port, i;
667
668 for (port = start_port(device); port <= end_port(device); ++port) {
669 for (i = 0; i < device->gid_tbl_len[port - start_port(device)]; ++i) {
670 ret = ib_query_gid(device, port, i, &tmp_gid);
671 if (ret)
672 return ret;
673 if (!memcmp(&tmp_gid, gid, sizeof *gid)) {
674 *port_num = port;
675 if (index)
676 *index = i;
677 return 0;
678 }
679 }
680 }
681
682 return -ENOENT;
683}
684EXPORT_SYMBOL(ib_find_gid);
685
686/**
687 * ib_find_pkey - Returns the PKey table index where a specified
688 * PKey value occurs.
689 * @device: The device to query.
690 * @port_num: The port number of the device to search for the PKey.
691 * @pkey: The PKey value to search for.
692 * @index: The index into the PKey table where the PKey was found.
693 */
694int ib_find_pkey(struct ib_device *device,
695 u8 port_num, u16 pkey, u16 *index)
696{
697 int ret, i;
698 u16 tmp_pkey;
699
700 for (i = 0; i < device->pkey_tbl_len[port_num - start_port(device)]; ++i) {
701 ret = ib_query_pkey(device, port_num, i, &tmp_pkey);
702 if (ret)
703 return ret;
704
705 if (pkey == tmp_pkey) {
706 *index = i;
707 return 0;
708 }
709 }
710
711 return -ENOENT;
712}
713EXPORT_SYMBOL(ib_find_pkey);
714
595static int __init ib_core_init(void) 715static int __init ib_core_init(void)
596{ 716{
597 int ret; 717 int ret;
@@ -613,6 +733,8 @@ static void __exit ib_core_cleanup(void)
613{ 733{
614 ib_cache_cleanup(); 734 ib_cache_cleanup();
615 ib_sysfs_cleanup(); 735 ib_sysfs_cleanup();
736 /* Make sure that any pending umem accounting work is done. */
737 flush_scheduled_work();
616} 738}
617 739
618module_init(ib_core_init); 740module_init(ib_core_init);
diff --git a/drivers/infiniband/core/uverbs_mem.c b/drivers/infiniband/core/umem.c
index c95fe952abd5..b4aec5103c99 100644
--- a/drivers/infiniband/core/uverbs_mem.c
+++ b/drivers/infiniband/core/umem.c
@@ -36,16 +36,10 @@
36 36
37#include <linux/mm.h> 37#include <linux/mm.h>
38#include <linux/dma-mapping.h> 38#include <linux/dma-mapping.h>
39#include <linux/sched.h>
39 40
40#include "uverbs.h" 41#include "uverbs.h"
41 42
42struct ib_umem_account_work {
43 struct work_struct work;
44 struct mm_struct *mm;
45 unsigned long diff;
46};
47
48
49static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dirty) 43static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int dirty)
50{ 44{
51 struct ib_umem_chunk *chunk, *tmp; 45 struct ib_umem_chunk *chunk, *tmp;
@@ -64,35 +58,56 @@ static void __ib_umem_release(struct ib_device *dev, struct ib_umem *umem, int d
64 } 58 }
65} 59}
66 60
67int ib_umem_get(struct ib_device *dev, struct ib_umem *mem, 61/**
68 void *addr, size_t size, int write) 62 * ib_umem_get - Pin and DMA map userspace memory.
63 * @context: userspace context to pin memory for
64 * @addr: userspace virtual address to start at
65 * @size: length of region to pin
66 * @access: IB_ACCESS_xxx flags for memory being pinned
67 */
68struct ib_umem *ib_umem_get(struct ib_ucontext *context, unsigned long addr,
69 size_t size, int access)
69{ 70{
71 struct ib_umem *umem;
70 struct page **page_list; 72 struct page **page_list;
71 struct ib_umem_chunk *chunk; 73 struct ib_umem_chunk *chunk;
72 unsigned long locked; 74 unsigned long locked;
73 unsigned long lock_limit; 75 unsigned long lock_limit;
74 unsigned long cur_base; 76 unsigned long cur_base;
75 unsigned long npages; 77 unsigned long npages;
76 int ret = 0; 78 int ret;
77 int off; 79 int off;
78 int i; 80 int i;
79 81
80 if (!can_do_mlock()) 82 if (!can_do_mlock())
81 return -EPERM; 83 return ERR_PTR(-EPERM);
82 84
83 page_list = (struct page **) __get_free_page(GFP_KERNEL); 85 umem = kmalloc(sizeof *umem, GFP_KERNEL);
84 if (!page_list) 86 if (!umem)
85 return -ENOMEM; 87 return ERR_PTR(-ENOMEM);
86 88
87 mem->user_base = (unsigned long) addr; 89 umem->context = context;
88 mem->length = size; 90 umem->length = size;
89 mem->offset = (unsigned long) addr & ~PAGE_MASK; 91 umem->offset = addr & ~PAGE_MASK;
90 mem->page_size = PAGE_SIZE; 92 umem->page_size = PAGE_SIZE;
91 mem->writable = write; 93 /*
94 * We ask for writable memory if any access flags other than
95 * "remote read" are set. "Local write" and "remote write"
96 * obviously require write access. "Remote atomic" can do
97 * things like fetch and add, which will modify memory, and
98 * "MW bind" can change permissions by binding a window.
99 */
100 umem->writable = !!(access & ~IB_ACCESS_REMOTE_READ);
92 101
93 INIT_LIST_HEAD(&mem->chunk_list); 102 INIT_LIST_HEAD(&umem->chunk_list);
94 103
95 npages = PAGE_ALIGN(size + mem->offset) >> PAGE_SHIFT; 104 page_list = (struct page **) __get_free_page(GFP_KERNEL);
105 if (!page_list) {
106 kfree(umem);
107 return ERR_PTR(-ENOMEM);
108 }
109
110 npages = PAGE_ALIGN(size + umem->offset) >> PAGE_SHIFT;
96 111
97 down_write(&current->mm->mmap_sem); 112 down_write(&current->mm->mmap_sem);
98 113
@@ -104,13 +119,13 @@ int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,
104 goto out; 119 goto out;
105 } 120 }
106 121
107 cur_base = (unsigned long) addr & PAGE_MASK; 122 cur_base = addr & PAGE_MASK;
108 123
109 while (npages) { 124 while (npages) {
110 ret = get_user_pages(current, current->mm, cur_base, 125 ret = get_user_pages(current, current->mm, cur_base,
111 min_t(int, npages, 126 min_t(int, npages,
112 PAGE_SIZE / sizeof (struct page *)), 127 PAGE_SIZE / sizeof (struct page *)),
113 1, !write, page_list, NULL); 128 1, !umem->writable, page_list, NULL);
114 129
115 if (ret < 0) 130 if (ret < 0)
116 goto out; 131 goto out;
@@ -136,7 +151,7 @@ int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,
136 chunk->page_list[i].length = PAGE_SIZE; 151 chunk->page_list[i].length = PAGE_SIZE;
137 } 152 }
138 153
139 chunk->nmap = ib_dma_map_sg(dev, 154 chunk->nmap = ib_dma_map_sg(context->device,
140 &chunk->page_list[0], 155 &chunk->page_list[0],
141 chunk->nents, 156 chunk->nents,
142 DMA_BIDIRECTIONAL); 157 DMA_BIDIRECTIONAL);
@@ -151,75 +166,96 @@ int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,
151 166
152 ret -= chunk->nents; 167 ret -= chunk->nents;
153 off += chunk->nents; 168 off += chunk->nents;
154 list_add_tail(&chunk->list, &mem->chunk_list); 169 list_add_tail(&chunk->list, &umem->chunk_list);
155 } 170 }
156 171
157 ret = 0; 172 ret = 0;
158 } 173 }
159 174
160out: 175out:
161 if (ret < 0) 176 if (ret < 0) {
162 __ib_umem_release(dev, mem, 0); 177 __ib_umem_release(context->device, umem, 0);
163 else 178 kfree(umem);
179 } else
164 current->mm->locked_vm = locked; 180 current->mm->locked_vm = locked;
165 181
166 up_write(&current->mm->mmap_sem); 182 up_write(&current->mm->mmap_sem);
167 free_page((unsigned long) page_list); 183 free_page((unsigned long) page_list);
168 184
169 return ret; 185 return ret < 0 ? ERR_PTR(ret) : umem;
170} 186}
187EXPORT_SYMBOL(ib_umem_get);
171 188
172void ib_umem_release(struct ib_device *dev, struct ib_umem *umem) 189static void ib_umem_account(struct work_struct *work)
173{ 190{
174 __ib_umem_release(dev, umem, 1); 191 struct ib_umem *umem = container_of(work, struct ib_umem, work);
175 192
176 down_write(&current->mm->mmap_sem); 193 down_write(&umem->mm->mmap_sem);
177 current->mm->locked_vm -= 194 umem->mm->locked_vm -= umem->diff;
178 PAGE_ALIGN(umem->length + umem->offset) >> PAGE_SHIFT; 195 up_write(&umem->mm->mmap_sem);
179 up_write(&current->mm->mmap_sem); 196 mmput(umem->mm);
197 kfree(umem);
180} 198}
181 199
182static void ib_umem_account(struct work_struct *_work) 200/**
183{ 201 * ib_umem_release - release memory pinned with ib_umem_get
184 struct ib_umem_account_work *work = 202 * @umem: umem struct to release
185 container_of(_work, struct ib_umem_account_work, work); 203 */
186 204void ib_umem_release(struct ib_umem *umem)
187 down_write(&work->mm->mmap_sem);
188 work->mm->locked_vm -= work->diff;
189 up_write(&work->mm->mmap_sem);
190 mmput(work->mm);
191 kfree(work);
192}
193
194void ib_umem_release_on_close(struct ib_device *dev, struct ib_umem *umem)
195{ 205{
196 struct ib_umem_account_work *work; 206 struct ib_ucontext *context = umem->context;
197 struct mm_struct *mm; 207 struct mm_struct *mm;
208 unsigned long diff;
198 209
199 __ib_umem_release(dev, umem, 1); 210 __ib_umem_release(umem->context->device, umem, 1);
200 211
201 mm = get_task_mm(current); 212 mm = get_task_mm(current);
202 if (!mm) 213 if (!mm) {
214 kfree(umem);
203 return; 215 return;
216 }
217
218 diff = PAGE_ALIGN(umem->length + umem->offset) >> PAGE_SHIFT;
204 219
205 /* 220 /*
206 * We may be called with the mm's mmap_sem already held. This 221 * We may be called with the mm's mmap_sem already held. This
207 * can happen when a userspace munmap() is the call that drops 222 * can happen when a userspace munmap() is the call that drops
208 * the last reference to our file and calls our release 223 * the last reference to our file and calls our release
209 * method. If there are memory regions to destroy, we'll end 224 * method. If there are memory regions to destroy, we'll end
210 * up here and not be able to take the mmap_sem. Therefore we 225 * up here and not be able to take the mmap_sem. In that case
211 * defer the vm_locked accounting to the system workqueue. 226 * we defer the vm_locked accounting to the system workqueue.
212 */ 227 */
228 if (context->closing && !down_write_trylock(&mm->mmap_sem)) {
229 INIT_WORK(&umem->work, ib_umem_account);
230 umem->mm = mm;
231 umem->diff = diff;
213 232
214 work = kmalloc(sizeof *work, GFP_KERNEL); 233 schedule_work(&umem->work);
215 if (!work) {
216 mmput(mm);
217 return; 234 return;
218 } 235 } else
236 down_write(&mm->mmap_sem);
237
238 current->mm->locked_vm -= diff;
239 up_write(&mm->mmap_sem);
240 mmput(mm);
241 kfree(umem);
242}
243EXPORT_SYMBOL(ib_umem_release);
244
245int ib_umem_page_count(struct ib_umem *umem)
246{
247 struct ib_umem_chunk *chunk;
248 int shift;
249 int i;
250 int n;
251
252 shift = ilog2(umem->page_size);
219 253
220 INIT_WORK(&work->work, ib_umem_account); 254 n = 0;
221 work->mm = mm; 255 list_for_each_entry(chunk, &umem->chunk_list, list)
222 work->diff = PAGE_ALIGN(umem->length + umem->offset) >> PAGE_SHIFT; 256 for (i = 0; i < chunk->nmap; ++i)
257 n += sg_dma_len(&chunk->page_list[i]) >> shift;
223 258
224 schedule_work(&work->work); 259 return n;
225} 260}
261EXPORT_SYMBOL(ib_umem_page_count);
diff --git a/drivers/infiniband/core/uverbs.h b/drivers/infiniband/core/uverbs.h
index 102a59c033ff..c33546f9e961 100644
--- a/drivers/infiniband/core/uverbs.h
+++ b/drivers/infiniband/core/uverbs.h
@@ -45,6 +45,7 @@
45#include <linux/completion.h> 45#include <linux/completion.h>
46 46
47#include <rdma/ib_verbs.h> 47#include <rdma/ib_verbs.h>
48#include <rdma/ib_umem.h>
48#include <rdma/ib_user_verbs.h> 49#include <rdma/ib_user_verbs.h>
49 50
50/* 51/*
@@ -163,11 +164,6 @@ void ib_uverbs_srq_event_handler(struct ib_event *event, void *context_ptr);
163void ib_uverbs_event_handler(struct ib_event_handler *handler, 164void ib_uverbs_event_handler(struct ib_event_handler *handler,
164 struct ib_event *event); 165 struct ib_event *event);
165 166
166int ib_umem_get(struct ib_device *dev, struct ib_umem *mem,
167 void *addr, size_t size, int write);
168void ib_umem_release(struct ib_device *dev, struct ib_umem *umem);
169void ib_umem_release_on_close(struct ib_device *dev, struct ib_umem *umem);
170
171#define IB_UVERBS_DECLARE_CMD(name) \ 167#define IB_UVERBS_DECLARE_CMD(name) \
172 ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \ 168 ssize_t ib_uverbs_##name(struct ib_uverbs_file *file, \
173 const char __user *buf, int in_len, \ 169 const char __user *buf, int in_len, \
diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
index bab66769be14..01d70084aebe 100644
--- a/drivers/infiniband/core/uverbs_cmd.c
+++ b/drivers/infiniband/core/uverbs_cmd.c
@@ -1,6 +1,6 @@
1/* 1/*
2 * Copyright (c) 2005 Topspin Communications. All rights reserved. 2 * Copyright (c) 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005, 2006 Cisco Systems. All rights reserved. 3 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
4 * Copyright (c) 2005 PathScale, Inc. All rights reserved. 4 * Copyright (c) 2005 PathScale, Inc. All rights reserved.
5 * Copyright (c) 2006 Mellanox Technologies. All rights reserved. 5 * Copyright (c) 2006 Mellanox Technologies. All rights reserved.
6 * 6 *
@@ -295,6 +295,7 @@ ssize_t ib_uverbs_get_context(struct ib_uverbs_file *file,
295 INIT_LIST_HEAD(&ucontext->qp_list); 295 INIT_LIST_HEAD(&ucontext->qp_list);
296 INIT_LIST_HEAD(&ucontext->srq_list); 296 INIT_LIST_HEAD(&ucontext->srq_list);
297 INIT_LIST_HEAD(&ucontext->ah_list); 297 INIT_LIST_HEAD(&ucontext->ah_list);
298 ucontext->closing = 0;
298 299
299 resp.num_comp_vectors = file->device->num_comp_vectors; 300 resp.num_comp_vectors = file->device->num_comp_vectors;
300 301
@@ -573,7 +574,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
573 struct ib_uverbs_reg_mr cmd; 574 struct ib_uverbs_reg_mr cmd;
574 struct ib_uverbs_reg_mr_resp resp; 575 struct ib_uverbs_reg_mr_resp resp;
575 struct ib_udata udata; 576 struct ib_udata udata;
576 struct ib_umem_object *obj; 577 struct ib_uobject *uobj;
577 struct ib_pd *pd; 578 struct ib_pd *pd;
578 struct ib_mr *mr; 579 struct ib_mr *mr;
579 int ret; 580 int ret;
@@ -599,35 +600,21 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
599 !(cmd.access_flags & IB_ACCESS_LOCAL_WRITE)) 600 !(cmd.access_flags & IB_ACCESS_LOCAL_WRITE))
600 return -EINVAL; 601 return -EINVAL;
601 602
602 obj = kmalloc(sizeof *obj, GFP_KERNEL); 603 uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
603 if (!obj) 604 if (!uobj)
604 return -ENOMEM; 605 return -ENOMEM;
605 606
606 init_uobj(&obj->uobject, 0, file->ucontext, &mr_lock_key); 607 init_uobj(uobj, 0, file->ucontext, &mr_lock_key);
607 down_write(&obj->uobject.mutex); 608 down_write(&uobj->mutex);
608
609 /*
610 * We ask for writable memory if any access flags other than
611 * "remote read" are set. "Local write" and "remote write"
612 * obviously require write access. "Remote atomic" can do
613 * things like fetch and add, which will modify memory, and
614 * "MW bind" can change permissions by binding a window.
615 */
616 ret = ib_umem_get(file->device->ib_dev, &obj->umem,
617 (void *) (unsigned long) cmd.start, cmd.length,
618 !!(cmd.access_flags & ~IB_ACCESS_REMOTE_READ));
619 if (ret)
620 goto err_free;
621
622 obj->umem.virt_base = cmd.hca_va;
623 609
624 pd = idr_read_pd(cmd.pd_handle, file->ucontext); 610 pd = idr_read_pd(cmd.pd_handle, file->ucontext);
625 if (!pd) { 611 if (!pd) {
626 ret = -EINVAL; 612 ret = -EINVAL;
627 goto err_release; 613 goto err_free;
628 } 614 }
629 615
630 mr = pd->device->reg_user_mr(pd, &obj->umem, cmd.access_flags, &udata); 616 mr = pd->device->reg_user_mr(pd, cmd.start, cmd.length, cmd.hca_va,
617 cmd.access_flags, &udata);
631 if (IS_ERR(mr)) { 618 if (IS_ERR(mr)) {
632 ret = PTR_ERR(mr); 619 ret = PTR_ERR(mr);
633 goto err_put; 620 goto err_put;
@@ -635,19 +622,19 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
635 622
636 mr->device = pd->device; 623 mr->device = pd->device;
637 mr->pd = pd; 624 mr->pd = pd;
638 mr->uobject = &obj->uobject; 625 mr->uobject = uobj;
639 atomic_inc(&pd->usecnt); 626 atomic_inc(&pd->usecnt);
640 atomic_set(&mr->usecnt, 0); 627 atomic_set(&mr->usecnt, 0);
641 628
642 obj->uobject.object = mr; 629 uobj->object = mr;
643 ret = idr_add_uobj(&ib_uverbs_mr_idr, &obj->uobject); 630 ret = idr_add_uobj(&ib_uverbs_mr_idr, uobj);
644 if (ret) 631 if (ret)
645 goto err_unreg; 632 goto err_unreg;
646 633
647 memset(&resp, 0, sizeof resp); 634 memset(&resp, 0, sizeof resp);
648 resp.lkey = mr->lkey; 635 resp.lkey = mr->lkey;
649 resp.rkey = mr->rkey; 636 resp.rkey = mr->rkey;
650 resp.mr_handle = obj->uobject.id; 637 resp.mr_handle = uobj->id;
651 638
652 if (copy_to_user((void __user *) (unsigned long) cmd.response, 639 if (copy_to_user((void __user *) (unsigned long) cmd.response,
653 &resp, sizeof resp)) { 640 &resp, sizeof resp)) {
@@ -658,17 +645,17 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
658 put_pd_read(pd); 645 put_pd_read(pd);
659 646
660 mutex_lock(&file->mutex); 647 mutex_lock(&file->mutex);
661 list_add_tail(&obj->uobject.list, &file->ucontext->mr_list); 648 list_add_tail(&uobj->list, &file->ucontext->mr_list);
662 mutex_unlock(&file->mutex); 649 mutex_unlock(&file->mutex);
663 650
664 obj->uobject.live = 1; 651 uobj->live = 1;
665 652
666 up_write(&obj->uobject.mutex); 653 up_write(&uobj->mutex);
667 654
668 return in_len; 655 return in_len;
669 656
670err_copy: 657err_copy:
671 idr_remove_uobj(&ib_uverbs_mr_idr, &obj->uobject); 658 idr_remove_uobj(&ib_uverbs_mr_idr, uobj);
672 659
673err_unreg: 660err_unreg:
674 ib_dereg_mr(mr); 661 ib_dereg_mr(mr);
@@ -676,11 +663,8 @@ err_unreg:
676err_put: 663err_put:
677 put_pd_read(pd); 664 put_pd_read(pd);
678 665
679err_release:
680 ib_umem_release(file->device->ib_dev, &obj->umem);
681
682err_free: 666err_free:
683 put_uobj_write(&obj->uobject); 667 put_uobj_write(uobj);
684 return ret; 668 return ret;
685} 669}
686 670
@@ -691,7 +675,6 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
691 struct ib_uverbs_dereg_mr cmd; 675 struct ib_uverbs_dereg_mr cmd;
692 struct ib_mr *mr; 676 struct ib_mr *mr;
693 struct ib_uobject *uobj; 677 struct ib_uobject *uobj;
694 struct ib_umem_object *memobj;
695 int ret = -EINVAL; 678 int ret = -EINVAL;
696 679
697 if (copy_from_user(&cmd, buf, sizeof cmd)) 680 if (copy_from_user(&cmd, buf, sizeof cmd))
@@ -701,8 +684,7 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
701 if (!uobj) 684 if (!uobj)
702 return -EINVAL; 685 return -EINVAL;
703 686
704 memobj = container_of(uobj, struct ib_umem_object, uobject); 687 mr = uobj->object;
705 mr = uobj->object;
706 688
707 ret = ib_dereg_mr(mr); 689 ret = ib_dereg_mr(mr);
708 if (!ret) 690 if (!ret)
@@ -719,8 +701,6 @@ ssize_t ib_uverbs_dereg_mr(struct ib_uverbs_file *file,
719 list_del(&uobj->list); 701 list_del(&uobj->list);
720 mutex_unlock(&file->mutex); 702 mutex_unlock(&file->mutex);
721 703
722 ib_umem_release(file->device->ib_dev, &memobj->umem);
723
724 put_uobj(uobj); 704 put_uobj(uobj);
725 705
726 return in_len; 706 return in_len;
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index d44e54799651..14d7ccd89195 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -183,6 +183,8 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
183 if (!context) 183 if (!context)
184 return 0; 184 return 0;
185 185
186 context->closing = 1;
187
186 list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) { 188 list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) {
187 struct ib_ah *ah = uobj->object; 189 struct ib_ah *ah = uobj->object;
188 190
@@ -230,16 +232,10 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
230 232
231 list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) { 233 list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) {
232 struct ib_mr *mr = uobj->object; 234 struct ib_mr *mr = uobj->object;
233 struct ib_device *mrdev = mr->device;
234 struct ib_umem_object *memobj;
235 235
236 idr_remove_uobj(&ib_uverbs_mr_idr, uobj); 236 idr_remove_uobj(&ib_uverbs_mr_idr, uobj);
237 ib_dereg_mr(mr); 237 ib_dereg_mr(mr);
238 238 kfree(uobj);
239 memobj = container_of(uobj, struct ib_umem_object, uobject);
240 ib_umem_release_on_close(mrdev, &memobj->umem);
241
242 kfree(memobj);
243 } 239 }
244 240
245 list_for_each_entry_safe(uobj, tmp, &context->pd_list, list) { 241 list_for_each_entry_safe(uobj, tmp, &context->pd_list, list) {
@@ -906,7 +902,6 @@ static void __exit ib_uverbs_cleanup(void)
906 unregister_filesystem(&uverbs_event_fs); 902 unregister_filesystem(&uverbs_event_fs);
907 class_destroy(uverbs_class); 903 class_destroy(uverbs_class);
908 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES); 904 unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
909 flush_scheduled_work();
910 idr_destroy(&ib_uverbs_pd_idr); 905 idr_destroy(&ib_uverbs_pd_idr);
911 idr_destroy(&ib_uverbs_mr_idr); 906 idr_destroy(&ib_uverbs_mr_idr);
912 idr_destroy(&ib_uverbs_mw_idr); 907 idr_destroy(&ib_uverbs_mw_idr);
diff --git a/drivers/infiniband/hw/amso1100/c2_provider.c b/drivers/infiniband/hw/amso1100/c2_provider.c
index 109166223c09..997cf1530762 100644
--- a/drivers/infiniband/hw/amso1100/c2_provider.c
+++ b/drivers/infiniband/hw/amso1100/c2_provider.c
@@ -56,6 +56,7 @@
56#include <asm/byteorder.h> 56#include <asm/byteorder.h>
57 57
58#include <rdma/ib_smi.h> 58#include <rdma/ib_smi.h>
59#include <rdma/ib_umem.h>
59#include <rdma/ib_user_verbs.h> 60#include <rdma/ib_user_verbs.h>
60#include "c2.h" 61#include "c2.h"
61#include "c2_provider.h" 62#include "c2_provider.h"
@@ -396,6 +397,7 @@ static struct ib_mr *c2_reg_phys_mr(struct ib_pd *ib_pd,
396 } 397 }
397 398
398 mr->pd = to_c2pd(ib_pd); 399 mr->pd = to_c2pd(ib_pd);
400 mr->umem = NULL;
399 pr_debug("%s - page shift %d, pbl_depth %d, total_len %u, " 401 pr_debug("%s - page shift %d, pbl_depth %d, total_len %u, "
400 "*iova_start %llx, first pa %llx, last pa %llx\n", 402 "*iova_start %llx, first pa %llx, last pa %llx\n",
401 __FUNCTION__, page_shift, pbl_depth, total_len, 403 __FUNCTION__, page_shift, pbl_depth, total_len,
@@ -428,8 +430,8 @@ static struct ib_mr *c2_get_dma_mr(struct ib_pd *pd, int acc)
428 return c2_reg_phys_mr(pd, &bl, 1, acc, &kva); 430 return c2_reg_phys_mr(pd, &bl, 1, acc, &kva);
429} 431}
430 432
431static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, struct ib_umem *region, 433static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
432 int acc, struct ib_udata *udata) 434 u64 virt, int acc, struct ib_udata *udata)
433{ 435{
434 u64 *pages; 436 u64 *pages;
435 u64 kva = 0; 437 u64 kva = 0;
@@ -441,15 +443,23 @@ static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
441 struct c2_mr *c2mr; 443 struct c2_mr *c2mr;
442 444
443 pr_debug("%s:%u\n", __FUNCTION__, __LINE__); 445 pr_debug("%s:%u\n", __FUNCTION__, __LINE__);
444 shift = ffs(region->page_size) - 1;
445 446
446 c2mr = kmalloc(sizeof(*c2mr), GFP_KERNEL); 447 c2mr = kmalloc(sizeof(*c2mr), GFP_KERNEL);
447 if (!c2mr) 448 if (!c2mr)
448 return ERR_PTR(-ENOMEM); 449 return ERR_PTR(-ENOMEM);
449 c2mr->pd = c2pd; 450 c2mr->pd = c2pd;
450 451
452 c2mr->umem = ib_umem_get(pd->uobject->context, start, length, acc);
453 if (IS_ERR(c2mr->umem)) {
454 err = PTR_ERR(c2mr->umem);
455 kfree(c2mr);
456 return ERR_PTR(err);
457 }
458
459 shift = ffs(c2mr->umem->page_size) - 1;
460
451 n = 0; 461 n = 0;
452 list_for_each_entry(chunk, &region->chunk_list, list) 462 list_for_each_entry(chunk, &c2mr->umem->chunk_list, list)
453 n += chunk->nents; 463 n += chunk->nents;
454 464
455 pages = kmalloc(n * sizeof(u64), GFP_KERNEL); 465 pages = kmalloc(n * sizeof(u64), GFP_KERNEL);
@@ -459,35 +469,34 @@ static struct ib_mr *c2_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
459 } 469 }
460 470
461 i = 0; 471 i = 0;
462 list_for_each_entry(chunk, &region->chunk_list, list) { 472 list_for_each_entry(chunk, &c2mr->umem->chunk_list, list) {
463 for (j = 0; j < chunk->nmap; ++j) { 473 for (j = 0; j < chunk->nmap; ++j) {
464 len = sg_dma_len(&chunk->page_list[j]) >> shift; 474 len = sg_dma_len(&chunk->page_list[j]) >> shift;
465 for (k = 0; k < len; ++k) { 475 for (k = 0; k < len; ++k) {
466 pages[i++] = 476 pages[i++] =
467 sg_dma_address(&chunk->page_list[j]) + 477 sg_dma_address(&chunk->page_list[j]) +
468 (region->page_size * k); 478 (c2mr->umem->page_size * k);
469 } 479 }
470 } 480 }
471 } 481 }
472 482
473 kva = (u64)region->virt_base; 483 kva = virt;
474 err = c2_nsmr_register_phys_kern(to_c2dev(pd->device), 484 err = c2_nsmr_register_phys_kern(to_c2dev(pd->device),
475 pages, 485 pages,
476 region->page_size, 486 c2mr->umem->page_size,
477 i, 487 i,
478 region->length, 488 length,
479 region->offset, 489 c2mr->umem->offset,
480 &kva, 490 &kva,
481 c2_convert_access(acc), 491 c2_convert_access(acc),
482 c2mr); 492 c2mr);
483 kfree(pages); 493 kfree(pages);
484 if (err) { 494 if (err)
485 kfree(c2mr); 495 goto err;
486 return ERR_PTR(err);
487 }
488 return &c2mr->ibmr; 496 return &c2mr->ibmr;
489 497
490err: 498err:
499 ib_umem_release(c2mr->umem);
491 kfree(c2mr); 500 kfree(c2mr);
492 return ERR_PTR(err); 501 return ERR_PTR(err);
493} 502}
@@ -502,8 +511,11 @@ static int c2_dereg_mr(struct ib_mr *ib_mr)
502 err = c2_stag_dealloc(to_c2dev(ib_mr->device), ib_mr->lkey); 511 err = c2_stag_dealloc(to_c2dev(ib_mr->device), ib_mr->lkey);
503 if (err) 512 if (err)
504 pr_debug("c2_stag_dealloc failed: %d\n", err); 513 pr_debug("c2_stag_dealloc failed: %d\n", err);
505 else 514 else {
515 if (mr->umem)
516 ib_umem_release(mr->umem);
506 kfree(mr); 517 kfree(mr);
518 }
507 519
508 return err; 520 return err;
509} 521}
diff --git a/drivers/infiniband/hw/amso1100/c2_provider.h b/drivers/infiniband/hw/amso1100/c2_provider.h
index fc906223220f..1076df2ee96a 100644
--- a/drivers/infiniband/hw/amso1100/c2_provider.h
+++ b/drivers/infiniband/hw/amso1100/c2_provider.h
@@ -73,6 +73,7 @@ struct c2_pd {
73struct c2_mr { 73struct c2_mr {
74 struct ib_mr ibmr; 74 struct ib_mr ibmr;
75 struct c2_pd *pd; 75 struct c2_pd *pd;
76 struct ib_umem *umem;
76}; 77};
77 78
78struct c2_av; 79struct c2_av;
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.c b/drivers/infiniband/hw/cxgb3/iwch_provider.c
index a891493fd340..e7c2c3948037 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.c
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.c
@@ -47,6 +47,7 @@
47#include <rdma/iw_cm.h> 47#include <rdma/iw_cm.h>
48#include <rdma/ib_verbs.h> 48#include <rdma/ib_verbs.h>
49#include <rdma/ib_smi.h> 49#include <rdma/ib_smi.h>
50#include <rdma/ib_umem.h>
50#include <rdma/ib_user_verbs.h> 51#include <rdma/ib_user_verbs.h>
51 52
52#include "cxio_hal.h" 53#include "cxio_hal.h"
@@ -443,6 +444,8 @@ static int iwch_dereg_mr(struct ib_mr *ib_mr)
443 remove_handle(rhp, &rhp->mmidr, mmid); 444 remove_handle(rhp, &rhp->mmidr, mmid);
444 if (mhp->kva) 445 if (mhp->kva)
445 kfree((void *) (unsigned long) mhp->kva); 446 kfree((void *) (unsigned long) mhp->kva);
447 if (mhp->umem)
448 ib_umem_release(mhp->umem);
446 PDBG("%s mmid 0x%x ptr %p\n", __FUNCTION__, mmid, mhp); 449 PDBG("%s mmid 0x%x ptr %p\n", __FUNCTION__, mmid, mhp);
447 kfree(mhp); 450 kfree(mhp);
448 return 0; 451 return 0;
@@ -577,8 +580,8 @@ static int iwch_reregister_phys_mem(struct ib_mr *mr,
577} 580}
578 581
579 582
580static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region, 583static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
581 int acc, struct ib_udata *udata) 584 u64 virt, int acc, struct ib_udata *udata)
582{ 585{
583 __be64 *pages; 586 __be64 *pages;
584 int shift, n, len; 587 int shift, n, len;
@@ -591,7 +594,6 @@ static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
591 struct iwch_reg_user_mr_resp uresp; 594 struct iwch_reg_user_mr_resp uresp;
592 595
593 PDBG("%s ib_pd %p\n", __FUNCTION__, pd); 596 PDBG("%s ib_pd %p\n", __FUNCTION__, pd);
594 shift = ffs(region->page_size) - 1;
595 597
596 php = to_iwch_pd(pd); 598 php = to_iwch_pd(pd);
597 rhp = php->rhp; 599 rhp = php->rhp;
@@ -599,8 +601,17 @@ static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
599 if (!mhp) 601 if (!mhp)
600 return ERR_PTR(-ENOMEM); 602 return ERR_PTR(-ENOMEM);
601 603
604 mhp->umem = ib_umem_get(pd->uobject->context, start, length, acc);
605 if (IS_ERR(mhp->umem)) {
606 err = PTR_ERR(mhp->umem);
607 kfree(mhp);
608 return ERR_PTR(err);
609 }
610
611 shift = ffs(mhp->umem->page_size) - 1;
612
602 n = 0; 613 n = 0;
603 list_for_each_entry(chunk, &region->chunk_list, list) 614 list_for_each_entry(chunk, &mhp->umem->chunk_list, list)
604 n += chunk->nents; 615 n += chunk->nents;
605 616
606 pages = kmalloc(n * sizeof(u64), GFP_KERNEL); 617 pages = kmalloc(n * sizeof(u64), GFP_KERNEL);
@@ -611,13 +622,13 @@ static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
611 622
612 i = n = 0; 623 i = n = 0;
613 624
614 list_for_each_entry(chunk, &region->chunk_list, list) 625 list_for_each_entry(chunk, &mhp->umem->chunk_list, list)
615 for (j = 0; j < chunk->nmap; ++j) { 626 for (j = 0; j < chunk->nmap; ++j) {
616 len = sg_dma_len(&chunk->page_list[j]) >> shift; 627 len = sg_dma_len(&chunk->page_list[j]) >> shift;
617 for (k = 0; k < len; ++k) { 628 for (k = 0; k < len; ++k) {
618 pages[i++] = cpu_to_be64(sg_dma_address( 629 pages[i++] = cpu_to_be64(sg_dma_address(
619 &chunk->page_list[j]) + 630 &chunk->page_list[j]) +
620 region->page_size * k); 631 mhp->umem->page_size * k);
621 } 632 }
622 } 633 }
623 634
@@ -625,9 +636,9 @@ static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
625 mhp->attr.pdid = php->pdid; 636 mhp->attr.pdid = php->pdid;
626 mhp->attr.zbva = 0; 637 mhp->attr.zbva = 0;
627 mhp->attr.perms = iwch_ib_to_tpt_access(acc); 638 mhp->attr.perms = iwch_ib_to_tpt_access(acc);
628 mhp->attr.va_fbo = region->virt_base; 639 mhp->attr.va_fbo = virt;
629 mhp->attr.page_size = shift - 12; 640 mhp->attr.page_size = shift - 12;
630 mhp->attr.len = (u32) region->length; 641 mhp->attr.len = (u32) length;
631 mhp->attr.pbl_size = i; 642 mhp->attr.pbl_size = i;
632 err = iwch_register_mem(rhp, php, mhp, shift, pages); 643 err = iwch_register_mem(rhp, php, mhp, shift, pages);
633 kfree(pages); 644 kfree(pages);
@@ -650,6 +661,7 @@ static struct ib_mr *iwch_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
650 return &mhp->ibmr; 661 return &mhp->ibmr;
651 662
652err: 663err:
664 ib_umem_release(mhp->umem);
653 kfree(mhp); 665 kfree(mhp);
654 return ERR_PTR(err); 666 return ERR_PTR(err);
655} 667}
diff --git a/drivers/infiniband/hw/cxgb3/iwch_provider.h b/drivers/infiniband/hw/cxgb3/iwch_provider.h
index 93bcc56756bd..48833f3f3bd0 100644
--- a/drivers/infiniband/hw/cxgb3/iwch_provider.h
+++ b/drivers/infiniband/hw/cxgb3/iwch_provider.h
@@ -73,6 +73,7 @@ struct tpt_attributes {
73 73
74struct iwch_mr { 74struct iwch_mr {
75 struct ib_mr ibmr; 75 struct ib_mr ibmr;
76 struct ib_umem *umem;
76 struct iwch_dev *rhp; 77 struct iwch_dev *rhp;
77 u64 kva; 78 u64 kva;
78 struct tpt_attributes attr; 79 struct tpt_attributes attr;
diff --git a/drivers/infiniband/hw/ehca/ehca_classes.h b/drivers/infiniband/hw/ehca/ehca_classes.h
index 10fb8fbafa0c..1d286d3cc2d5 100644
--- a/drivers/infiniband/hw/ehca/ehca_classes.h
+++ b/drivers/infiniband/hw/ehca/ehca_classes.h
@@ -176,6 +176,7 @@ struct ehca_mr {
176 struct ib_mr ib_mr; /* must always be first in ehca_mr */ 176 struct ib_mr ib_mr; /* must always be first in ehca_mr */
177 struct ib_fmr ib_fmr; /* must always be first in ehca_mr */ 177 struct ib_fmr ib_fmr; /* must always be first in ehca_mr */
178 } ib; 178 } ib;
179 struct ib_umem *umem;
179 spinlock_t mrlock; 180 spinlock_t mrlock;
180 181
181 enum ehca_mr_flag flags; 182 enum ehca_mr_flag flags;
@@ -276,6 +277,7 @@ void ehca_cleanup_mrmw_cache(void);
276 277
277extern spinlock_t ehca_qp_idr_lock; 278extern spinlock_t ehca_qp_idr_lock;
278extern spinlock_t ehca_cq_idr_lock; 279extern spinlock_t ehca_cq_idr_lock;
280extern spinlock_t hcall_lock;
279extern struct idr ehca_qp_idr; 281extern struct idr ehca_qp_idr;
280extern struct idr ehca_cq_idr; 282extern struct idr ehca_cq_idr;
281 283
diff --git a/drivers/infiniband/hw/ehca/ehca_irq.c b/drivers/infiniband/hw/ehca/ehca_irq.c
index f284be1c9166..100329ba3343 100644
--- a/drivers/infiniband/hw/ehca/ehca_irq.c
+++ b/drivers/infiniband/hw/ehca/ehca_irq.c
@@ -517,12 +517,11 @@ void ehca_process_eq(struct ehca_shca *shca, int is_irq)
517 else { 517 else {
518 struct ehca_cq *cq = eq->eqe_cache[i].cq; 518 struct ehca_cq *cq = eq->eqe_cache[i].cq;
519 comp_event_callback(cq); 519 comp_event_callback(cq);
520 spin_lock_irqsave(&ehca_cq_idr_lock, flags); 520 spin_lock(&ehca_cq_idr_lock);
521 cq->nr_events--; 521 cq->nr_events--;
522 if (!cq->nr_events) 522 if (!cq->nr_events)
523 wake_up(&cq->wait_completion); 523 wake_up(&cq->wait_completion);
524 spin_unlock_irqrestore(&ehca_cq_idr_lock, 524 spin_unlock(&ehca_cq_idr_lock);
525 flags);
526 } 525 }
527 } else { 526 } else {
528 ehca_dbg(&shca->ib_device, "Got non completion event"); 527 ehca_dbg(&shca->ib_device, "Got non completion event");
@@ -711,6 +710,7 @@ static void destroy_comp_task(struct ehca_comp_pool *pool,
711 kthread_stop(task); 710 kthread_stop(task);
712} 711}
713 712
713#ifdef CONFIG_HOTPLUG_CPU
714static void take_over_work(struct ehca_comp_pool *pool, 714static void take_over_work(struct ehca_comp_pool *pool,
715 int cpu) 715 int cpu)
716{ 716{
@@ -735,7 +735,6 @@ static void take_over_work(struct ehca_comp_pool *pool,
735 735
736} 736}
737 737
738#ifdef CONFIG_HOTPLUG_CPU
739static int comp_pool_callback(struct notifier_block *nfb, 738static int comp_pool_callback(struct notifier_block *nfb,
740 unsigned long action, 739 unsigned long action,
741 void *hcpu) 740 void *hcpu)
@@ -745,6 +744,7 @@ static int comp_pool_callback(struct notifier_block *nfb,
745 744
746 switch (action) { 745 switch (action) {
747 case CPU_UP_PREPARE: 746 case CPU_UP_PREPARE:
747 case CPU_UP_PREPARE_FROZEN:
748 ehca_gen_dbg("CPU: %x (CPU_PREPARE)", cpu); 748 ehca_gen_dbg("CPU: %x (CPU_PREPARE)", cpu);
749 if(!create_comp_task(pool, cpu)) { 749 if(!create_comp_task(pool, cpu)) {
750 ehca_gen_err("Can't create comp_task for cpu: %x", cpu); 750 ehca_gen_err("Can't create comp_task for cpu: %x", cpu);
@@ -752,24 +752,29 @@ static int comp_pool_callback(struct notifier_block *nfb,
752 } 752 }
753 break; 753 break;
754 case CPU_UP_CANCELED: 754 case CPU_UP_CANCELED:
755 case CPU_UP_CANCELED_FROZEN:
755 ehca_gen_dbg("CPU: %x (CPU_CANCELED)", cpu); 756 ehca_gen_dbg("CPU: %x (CPU_CANCELED)", cpu);
756 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu); 757 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
757 kthread_bind(cct->task, any_online_cpu(cpu_online_map)); 758 kthread_bind(cct->task, any_online_cpu(cpu_online_map));
758 destroy_comp_task(pool, cpu); 759 destroy_comp_task(pool, cpu);
759 break; 760 break;
760 case CPU_ONLINE: 761 case CPU_ONLINE:
762 case CPU_ONLINE_FROZEN:
761 ehca_gen_dbg("CPU: %x (CPU_ONLINE)", cpu); 763 ehca_gen_dbg("CPU: %x (CPU_ONLINE)", cpu);
762 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu); 764 cct = per_cpu_ptr(pool->cpu_comp_tasks, cpu);
763 kthread_bind(cct->task, cpu); 765 kthread_bind(cct->task, cpu);
764 wake_up_process(cct->task); 766 wake_up_process(cct->task);
765 break; 767 break;
766 case CPU_DOWN_PREPARE: 768 case CPU_DOWN_PREPARE:
769 case CPU_DOWN_PREPARE_FROZEN:
767 ehca_gen_dbg("CPU: %x (CPU_DOWN_PREPARE)", cpu); 770 ehca_gen_dbg("CPU: %x (CPU_DOWN_PREPARE)", cpu);
768 break; 771 break;
769 case CPU_DOWN_FAILED: 772 case CPU_DOWN_FAILED:
773 case CPU_DOWN_FAILED_FROZEN:
770 ehca_gen_dbg("CPU: %x (CPU_DOWN_FAILED)", cpu); 774 ehca_gen_dbg("CPU: %x (CPU_DOWN_FAILED)", cpu);
771 break; 775 break;
772 case CPU_DEAD: 776 case CPU_DEAD:
777 case CPU_DEAD_FROZEN:
773 ehca_gen_dbg("CPU: %x (CPU_DEAD)", cpu); 778 ehca_gen_dbg("CPU: %x (CPU_DEAD)", cpu);
774 destroy_comp_task(pool, cpu); 779 destroy_comp_task(pool, cpu);
775 take_over_work(pool, cpu); 780 take_over_work(pool, cpu);
diff --git a/drivers/infiniband/hw/ehca/ehca_iverbs.h b/drivers/infiniband/hw/ehca/ehca_iverbs.h
index e14b029332c8..37e7fe0908cf 100644
--- a/drivers/infiniband/hw/ehca/ehca_iverbs.h
+++ b/drivers/infiniband/hw/ehca/ehca_iverbs.h
@@ -78,8 +78,7 @@ struct ib_mr *ehca_reg_phys_mr(struct ib_pd *pd,
78 int num_phys_buf, 78 int num_phys_buf,
79 int mr_access_flags, u64 *iova_start); 79 int mr_access_flags, u64 *iova_start);
80 80
81struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, 81struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, u64 virt,
82 struct ib_umem *region,
83 int mr_access_flags, struct ib_udata *udata); 82 int mr_access_flags, struct ib_udata *udata);
84 83
85int ehca_rereg_phys_mr(struct ib_mr *mr, 84int ehca_rereg_phys_mr(struct ib_mr *mr,
diff --git a/drivers/infiniband/hw/ehca/ehca_main.c b/drivers/infiniband/hw/ehca/ehca_main.c
index 2d370543e96d..c3f99f33b49c 100644
--- a/drivers/infiniband/hw/ehca/ehca_main.c
+++ b/drivers/infiniband/hw/ehca/ehca_main.c
@@ -52,7 +52,7 @@
52MODULE_LICENSE("Dual BSD/GPL"); 52MODULE_LICENSE("Dual BSD/GPL");
53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>"); 53MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
54MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver"); 54MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver");
55MODULE_VERSION("SVNEHCA_0022"); 55MODULE_VERSION("SVNEHCA_0023");
56 56
57int ehca_open_aqp1 = 0; 57int ehca_open_aqp1 = 0;
58int ehca_debug_level = 0; 58int ehca_debug_level = 0;
@@ -62,7 +62,7 @@ int ehca_use_hp_mr = 0;
62int ehca_port_act_time = 30; 62int ehca_port_act_time = 30;
63int ehca_poll_all_eqs = 1; 63int ehca_poll_all_eqs = 1;
64int ehca_static_rate = -1; 64int ehca_static_rate = -1;
65int ehca_scaling_code = 1; 65int ehca_scaling_code = 0;
66 66
67module_param_named(open_aqp1, ehca_open_aqp1, int, 0); 67module_param_named(open_aqp1, ehca_open_aqp1, int, 0);
68module_param_named(debug_level, ehca_debug_level, int, 0); 68module_param_named(debug_level, ehca_debug_level, int, 0);
@@ -98,6 +98,7 @@ MODULE_PARM_DESC(scaling_code,
98 98
99spinlock_t ehca_qp_idr_lock; 99spinlock_t ehca_qp_idr_lock;
100spinlock_t ehca_cq_idr_lock; 100spinlock_t ehca_cq_idr_lock;
101spinlock_t hcall_lock;
101DEFINE_IDR(ehca_qp_idr); 102DEFINE_IDR(ehca_qp_idr);
102DEFINE_IDR(ehca_cq_idr); 103DEFINE_IDR(ehca_cq_idr);
103 104
@@ -453,15 +454,14 @@ static ssize_t ehca_store_debug_level(struct device_driver *ddp,
453DRIVER_ATTR(debug_level, S_IRUSR | S_IWUSR, 454DRIVER_ATTR(debug_level, S_IRUSR | S_IWUSR,
454 ehca_show_debug_level, ehca_store_debug_level); 455 ehca_show_debug_level, ehca_store_debug_level);
455 456
456void ehca_create_driver_sysfs(struct ibmebus_driver *drv) 457static struct attribute *ehca_drv_attrs[] = {
457{ 458 &driver_attr_debug_level.attr,
458 driver_create_file(&drv->driver, &driver_attr_debug_level); 459 NULL
459} 460};
460 461
461void ehca_remove_driver_sysfs(struct ibmebus_driver *drv) 462static struct attribute_group ehca_drv_attr_grp = {
462{ 463 .attrs = ehca_drv_attrs
463 driver_remove_file(&drv->driver, &driver_attr_debug_level); 464};
464}
465 465
466#define EHCA_RESOURCE_ATTR(name) \ 466#define EHCA_RESOURCE_ATTR(name) \
467static ssize_t ehca_show_##name(struct device *dev, \ 467static ssize_t ehca_show_##name(struct device *dev, \
@@ -523,44 +523,28 @@ static ssize_t ehca_show_adapter_handle(struct device *dev,
523} 523}
524static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL); 524static DEVICE_ATTR(adapter_handle, S_IRUGO, ehca_show_adapter_handle, NULL);
525 525
526static struct attribute *ehca_dev_attrs[] = {
527 &dev_attr_adapter_handle.attr,
528 &dev_attr_num_ports.attr,
529 &dev_attr_hw_ver.attr,
530 &dev_attr_max_eq.attr,
531 &dev_attr_cur_eq.attr,
532 &dev_attr_max_cq.attr,
533 &dev_attr_cur_cq.attr,
534 &dev_attr_max_qp.attr,
535 &dev_attr_cur_qp.attr,
536 &dev_attr_max_mr.attr,
537 &dev_attr_cur_mr.attr,
538 &dev_attr_max_mw.attr,
539 &dev_attr_cur_mw.attr,
540 &dev_attr_max_pd.attr,
541 &dev_attr_max_ah.attr,
542 NULL
543};
526 544
527void ehca_create_device_sysfs(struct ibmebus_dev *dev) 545static struct attribute_group ehca_dev_attr_grp = {
528{ 546 .attrs = ehca_dev_attrs
529 device_create_file(&dev->ofdev.dev, &dev_attr_adapter_handle); 547};
530 device_create_file(&dev->ofdev.dev, &dev_attr_num_ports);
531 device_create_file(&dev->ofdev.dev, &dev_attr_hw_ver);
532 device_create_file(&dev->ofdev.dev, &dev_attr_max_eq);
533 device_create_file(&dev->ofdev.dev, &dev_attr_cur_eq);
534 device_create_file(&dev->ofdev.dev, &dev_attr_max_cq);
535 device_create_file(&dev->ofdev.dev, &dev_attr_cur_cq);
536 device_create_file(&dev->ofdev.dev, &dev_attr_max_qp);
537 device_create_file(&dev->ofdev.dev, &dev_attr_cur_qp);
538 device_create_file(&dev->ofdev.dev, &dev_attr_max_mr);
539 device_create_file(&dev->ofdev.dev, &dev_attr_cur_mr);
540 device_create_file(&dev->ofdev.dev, &dev_attr_max_mw);
541 device_create_file(&dev->ofdev.dev, &dev_attr_cur_mw);
542 device_create_file(&dev->ofdev.dev, &dev_attr_max_pd);
543 device_create_file(&dev->ofdev.dev, &dev_attr_max_ah);
544}
545
546void ehca_remove_device_sysfs(struct ibmebus_dev *dev)
547{
548 device_remove_file(&dev->ofdev.dev, &dev_attr_adapter_handle);
549 device_remove_file(&dev->ofdev.dev, &dev_attr_num_ports);
550 device_remove_file(&dev->ofdev.dev, &dev_attr_hw_ver);
551 device_remove_file(&dev->ofdev.dev, &dev_attr_max_eq);
552 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_eq);
553 device_remove_file(&dev->ofdev.dev, &dev_attr_max_cq);
554 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_cq);
555 device_remove_file(&dev->ofdev.dev, &dev_attr_max_qp);
556 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_qp);
557 device_remove_file(&dev->ofdev.dev, &dev_attr_max_mr);
558 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_mr);
559 device_remove_file(&dev->ofdev.dev, &dev_attr_max_mw);
560 device_remove_file(&dev->ofdev.dev, &dev_attr_cur_mw);
561 device_remove_file(&dev->ofdev.dev, &dev_attr_max_pd);
562 device_remove_file(&dev->ofdev.dev, &dev_attr_max_ah);
563}
564 548
565static int __devinit ehca_probe(struct ibmebus_dev *dev, 549static int __devinit ehca_probe(struct ibmebus_dev *dev,
566 const struct of_device_id *id) 550 const struct of_device_id *id)
@@ -570,7 +554,7 @@ static int __devinit ehca_probe(struct ibmebus_dev *dev,
570 struct ib_pd *ibpd; 554 struct ib_pd *ibpd;
571 int ret; 555 int ret;
572 556
573 handle = get_property(dev->ofdev.node, "ibm,hca-handle", NULL); 557 handle = of_get_property(dev->ofdev.node, "ibm,hca-handle", NULL);
574 if (!handle) { 558 if (!handle) {
575 ehca_gen_err("Cannot get eHCA handle for adapter: %s.", 559 ehca_gen_err("Cannot get eHCA handle for adapter: %s.",
576 dev->ofdev.node->full_name); 560 dev->ofdev.node->full_name);
@@ -668,7 +652,10 @@ static int __devinit ehca_probe(struct ibmebus_dev *dev,
668 } 652 }
669 } 653 }
670 654
671 ehca_create_device_sysfs(dev); 655 ret = sysfs_create_group(&dev->ofdev.dev.kobj, &ehca_dev_attr_grp);
656 if (ret) /* only complain; we can live without attributes */
657 ehca_err(&shca->ib_device,
658 "Cannot create device attributes ret=%d", ret);
672 659
673 spin_lock(&shca_list_lock); 660 spin_lock(&shca_list_lock);
674 list_add(&shca->shca_list, &shca_list); 661 list_add(&shca->shca_list, &shca_list);
@@ -720,7 +707,7 @@ static int __devexit ehca_remove(struct ibmebus_dev *dev)
720 struct ehca_shca *shca = dev->ofdev.dev.driver_data; 707 struct ehca_shca *shca = dev->ofdev.dev.driver_data;
721 int ret; 708 int ret;
722 709
723 ehca_remove_device_sysfs(dev); 710 sysfs_remove_group(&dev->ofdev.dev.kobj, &ehca_dev_attr_grp);
724 711
725 if (ehca_open_aqp1 == 1) { 712 if (ehca_open_aqp1 == 1) {
726 int i; 713 int i;
@@ -812,11 +799,12 @@ int __init ehca_module_init(void)
812 int ret; 799 int ret;
813 800
814 printk(KERN_INFO "eHCA Infiniband Device Driver " 801 printk(KERN_INFO "eHCA Infiniband Device Driver "
815 "(Rel.: SVNEHCA_0022)\n"); 802 "(Rel.: SVNEHCA_0023)\n");
816 idr_init(&ehca_qp_idr); 803 idr_init(&ehca_qp_idr);
817 idr_init(&ehca_cq_idr); 804 idr_init(&ehca_cq_idr);
818 spin_lock_init(&ehca_qp_idr_lock); 805 spin_lock_init(&ehca_qp_idr_lock);
819 spin_lock_init(&ehca_cq_idr_lock); 806 spin_lock_init(&ehca_cq_idr_lock);
807 spin_lock_init(&hcall_lock);
820 808
821 INIT_LIST_HEAD(&shca_list); 809 INIT_LIST_HEAD(&shca_list);
822 spin_lock_init(&shca_list_lock); 810 spin_lock_init(&shca_list_lock);
@@ -838,7 +826,9 @@ int __init ehca_module_init(void)
838 goto module_init2; 826 goto module_init2;
839 } 827 }
840 828
841 ehca_create_driver_sysfs(&ehca_driver); 829 ret = sysfs_create_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
830 if (ret) /* only complain; we can live without attributes */
831 ehca_gen_err("Cannot create driver attributes ret=%d", ret);
842 832
843 if (ehca_poll_all_eqs != 1) { 833 if (ehca_poll_all_eqs != 1) {
844 ehca_gen_err("WARNING!!!"); 834 ehca_gen_err("WARNING!!!");
@@ -865,7 +855,7 @@ void __exit ehca_module_exit(void)
865 if (ehca_poll_all_eqs == 1) 855 if (ehca_poll_all_eqs == 1)
866 del_timer_sync(&poll_eqs_timer); 856 del_timer_sync(&poll_eqs_timer);
867 857
868 ehca_remove_driver_sysfs(&ehca_driver); 858 sysfs_remove_group(&ehca_driver.driver.kobj, &ehca_drv_attr_grp);
869 ibmebus_unregister_driver(&ehca_driver); 859 ibmebus_unregister_driver(&ehca_driver);
870 860
871 ehca_destroy_slab_caches(); 861 ehca_destroy_slab_caches();
diff --git a/drivers/infiniband/hw/ehca/ehca_mrmw.c b/drivers/infiniband/hw/ehca/ehca_mrmw.c
index d22ab563633f..add79bd44e39 100644
--- a/drivers/infiniband/hw/ehca/ehca_mrmw.c
+++ b/drivers/infiniband/hw/ehca/ehca_mrmw.c
@@ -39,6 +39,8 @@
39 * POSSIBILITY OF SUCH DAMAGE. 39 * POSSIBILITY OF SUCH DAMAGE.
40 */ 40 */
41 41
42#include <rdma/ib_umem.h>
43
42#include <asm/current.h> 44#include <asm/current.h>
43 45
44#include "ehca_iverbs.h" 46#include "ehca_iverbs.h"
@@ -238,10 +240,8 @@ reg_phys_mr_exit0:
238 240
239/*----------------------------------------------------------------------*/ 241/*----------------------------------------------------------------------*/
240 242
241struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, 243struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, u64 virt,
242 struct ib_umem *region, 244 int mr_access_flags, struct ib_udata *udata)
243 int mr_access_flags,
244 struct ib_udata *udata)
245{ 245{
246 struct ib_mr *ib_mr; 246 struct ib_mr *ib_mr;
247 struct ehca_mr *e_mr; 247 struct ehca_mr *e_mr;
@@ -257,11 +257,7 @@ struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd,
257 ehca_gen_err("bad pd=%p", pd); 257 ehca_gen_err("bad pd=%p", pd);
258 return ERR_PTR(-EFAULT); 258 return ERR_PTR(-EFAULT);
259 } 259 }
260 if (!region) { 260
261 ehca_err(pd->device, "bad input values: region=%p", region);
262 ib_mr = ERR_PTR(-EINVAL);
263 goto reg_user_mr_exit0;
264 }
265 if (((mr_access_flags & IB_ACCESS_REMOTE_WRITE) && 261 if (((mr_access_flags & IB_ACCESS_REMOTE_WRITE) &&
266 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE)) || 262 !(mr_access_flags & IB_ACCESS_LOCAL_WRITE)) ||
267 ((mr_access_flags & IB_ACCESS_REMOTE_ATOMIC) && 263 ((mr_access_flags & IB_ACCESS_REMOTE_ATOMIC) &&
@@ -275,17 +271,10 @@ struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd,
275 ib_mr = ERR_PTR(-EINVAL); 271 ib_mr = ERR_PTR(-EINVAL);
276 goto reg_user_mr_exit0; 272 goto reg_user_mr_exit0;
277 } 273 }
278 if (region->page_size != PAGE_SIZE) {
279 ehca_err(pd->device, "page size not supported, "
280 "region->page_size=%x", region->page_size);
281 ib_mr = ERR_PTR(-EINVAL);
282 goto reg_user_mr_exit0;
283 }
284 274
285 if ((region->length == 0) || 275 if (length == 0 || virt + length < virt) {
286 ((region->virt_base + region->length) < region->virt_base)) {
287 ehca_err(pd->device, "bad input values: length=%lx " 276 ehca_err(pd->device, "bad input values: length=%lx "
288 "virt_base=%lx", region->length, region->virt_base); 277 "virt_base=%lx", length, virt);
289 ib_mr = ERR_PTR(-EINVAL); 278 ib_mr = ERR_PTR(-EINVAL);
290 goto reg_user_mr_exit0; 279 goto reg_user_mr_exit0;
291 } 280 }
@@ -297,40 +286,55 @@ struct ib_mr *ehca_reg_user_mr(struct ib_pd *pd,
297 goto reg_user_mr_exit0; 286 goto reg_user_mr_exit0;
298 } 287 }
299 288
289 e_mr->umem = ib_umem_get(pd->uobject->context, start, length,
290 mr_access_flags);
291 if (IS_ERR(e_mr->umem)) {
292 ib_mr = (void *) e_mr->umem;
293 goto reg_user_mr_exit1;
294 }
295
296 if (e_mr->umem->page_size != PAGE_SIZE) {
297 ehca_err(pd->device, "page size not supported, "
298 "e_mr->umem->page_size=%x", e_mr->umem->page_size);
299 ib_mr = ERR_PTR(-EINVAL);
300 goto reg_user_mr_exit2;
301 }
302
300 /* determine number of MR pages */ 303 /* determine number of MR pages */
301 num_pages_mr = (((region->virt_base % PAGE_SIZE) + region->length + 304 num_pages_mr = (((virt % PAGE_SIZE) + length + PAGE_SIZE - 1) /
302 PAGE_SIZE - 1) / PAGE_SIZE); 305 PAGE_SIZE);
303 num_pages_4k = (((region->virt_base % EHCA_PAGESIZE) + region->length + 306 num_pages_4k = (((virt % EHCA_PAGESIZE) + length + EHCA_PAGESIZE - 1) /
304 EHCA_PAGESIZE - 1) / EHCA_PAGESIZE); 307 EHCA_PAGESIZE);
305 308
306 /* register MR on HCA */ 309 /* register MR on HCA */
307 pginfo.type = EHCA_MR_PGI_USER; 310 pginfo.type = EHCA_MR_PGI_USER;
308 pginfo.num_pages = num_pages_mr; 311 pginfo.num_pages = num_pages_mr;
309 pginfo.num_4k = num_pages_4k; 312 pginfo.num_4k = num_pages_4k;
310 pginfo.region = region; 313 pginfo.region = e_mr->umem;
311 pginfo.next_4k = region->offset / EHCA_PAGESIZE; 314 pginfo.next_4k = e_mr->umem->offset / EHCA_PAGESIZE;
312 pginfo.next_chunk = list_prepare_entry(pginfo.next_chunk, 315 pginfo.next_chunk = list_prepare_entry(pginfo.next_chunk,
313 (&region->chunk_list), 316 (&e_mr->umem->chunk_list),
314 list); 317 list);
315 318
316 ret = ehca_reg_mr(shca, e_mr, (u64*)region->virt_base, 319 ret = ehca_reg_mr(shca, e_mr, (u64*) virt, length, mr_access_flags, e_pd,
317 region->length, mr_access_flags, e_pd, &pginfo, 320 &pginfo, &e_mr->ib.ib_mr.lkey, &e_mr->ib.ib_mr.rkey);
318 &e_mr->ib.ib_mr.lkey, &e_mr->ib.ib_mr.rkey);
319 if (ret) { 321 if (ret) {
320 ib_mr = ERR_PTR(ret); 322 ib_mr = ERR_PTR(ret);
321 goto reg_user_mr_exit1; 323 goto reg_user_mr_exit2;
322 } 324 }
323 325
324 /* successful registration of all pages */ 326 /* successful registration of all pages */
325 return &e_mr->ib.ib_mr; 327 return &e_mr->ib.ib_mr;
326 328
329reg_user_mr_exit2:
330 ib_umem_release(e_mr->umem);
327reg_user_mr_exit1: 331reg_user_mr_exit1:
328 ehca_mr_delete(e_mr); 332 ehca_mr_delete(e_mr);
329reg_user_mr_exit0: 333reg_user_mr_exit0:
330 if (IS_ERR(ib_mr)) 334 if (IS_ERR(ib_mr))
331 ehca_err(pd->device, "rc=%lx pd=%p region=%p mr_access_flags=%x" 335 ehca_err(pd->device, "rc=%lx pd=%p mr_access_flags=%x"
332 " udata=%p", 336 " udata=%p",
333 PTR_ERR(ib_mr), pd, region, mr_access_flags, udata); 337 PTR_ERR(ib_mr), pd, mr_access_flags, udata);
334 return ib_mr; 338 return ib_mr;
335} /* end ehca_reg_user_mr() */ 339} /* end ehca_reg_user_mr() */
336 340
@@ -596,6 +600,9 @@ int ehca_dereg_mr(struct ib_mr *mr)
596 goto dereg_mr_exit0; 600 goto dereg_mr_exit0;
597 } 601 }
598 602
603 if (e_mr->umem)
604 ib_umem_release(e_mr->umem);
605
599 /* successful deregistration */ 606 /* successful deregistration */
600 ehca_mr_delete(e_mr); 607 ehca_mr_delete(e_mr);
601 608
@@ -2043,13 +2050,10 @@ int ehca_mrmw_map_hrc_alloc(const u64 hipz_rc)
2043 switch (hipz_rc) { 2050 switch (hipz_rc) {
2044 case H_SUCCESS: /* successful completion */ 2051 case H_SUCCESS: /* successful completion */
2045 return 0; 2052 return 0;
2046 case H_ADAPTER_PARM: /* invalid adapter handle */
2047 case H_RT_PARM: /* invalid resource type */
2048 case H_NOT_ENOUGH_RESOURCES: /* insufficient resources */ 2053 case H_NOT_ENOUGH_RESOURCES: /* insufficient resources */
2049 case H_MLENGTH_PARM: /* invalid memory length */
2050 case H_MEM_ACCESS_PARM: /* invalid access controls */
2051 case H_CONSTRAINED: /* resource constraint */ 2054 case H_CONSTRAINED: /* resource constraint */
2052 return -EINVAL; 2055 case H_NO_MEM:
2056 return -ENOMEM;
2053 case H_BUSY: /* long busy */ 2057 case H_BUSY: /* long busy */
2054 return -EBUSY; 2058 return -EBUSY;
2055 default: 2059 default:
diff --git a/drivers/infiniband/hw/ehca/ehca_qp.c b/drivers/infiniband/hw/ehca/ehca_qp.c
index df0516f24379..b5bc787c77b6 100644
--- a/drivers/infiniband/hw/ehca/ehca_qp.c
+++ b/drivers/infiniband/hw/ehca/ehca_qp.c
@@ -523,6 +523,8 @@ struct ib_qp *ehca_create_qp(struct ib_pd *pd,
523 goto create_qp_exit1; 523 goto create_qp_exit1;
524 } 524 }
525 525
526 my_qp->ib_qp.qp_num = my_qp->real_qp_num;
527
526 switch (init_attr->qp_type) { 528 switch (init_attr->qp_type) {
527 case IB_QPT_RC: 529 case IB_QPT_RC:
528 if (isdaqp == 0) { 530 if (isdaqp == 0) {
@@ -568,7 +570,7 @@ struct ib_qp *ehca_create_qp(struct ib_pd *pd,
568 parms.act_nr_recv_wqes = init_attr->cap.max_recv_wr; 570 parms.act_nr_recv_wqes = init_attr->cap.max_recv_wr;
569 parms.act_nr_send_sges = init_attr->cap.max_send_sge; 571 parms.act_nr_send_sges = init_attr->cap.max_send_sge;
570 parms.act_nr_recv_sges = init_attr->cap.max_recv_sge; 572 parms.act_nr_recv_sges = init_attr->cap.max_recv_sge;
571 my_qp->real_qp_num = 573 my_qp->ib_qp.qp_num =
572 (init_attr->qp_type == IB_QPT_SMI) ? 0 : 1; 574 (init_attr->qp_type == IB_QPT_SMI) ? 0 : 1;
573 } 575 }
574 576
@@ -595,7 +597,6 @@ struct ib_qp *ehca_create_qp(struct ib_pd *pd,
595 my_qp->ib_qp.recv_cq = init_attr->recv_cq; 597 my_qp->ib_qp.recv_cq = init_attr->recv_cq;
596 my_qp->ib_qp.send_cq = init_attr->send_cq; 598 my_qp->ib_qp.send_cq = init_attr->send_cq;
597 599
598 my_qp->ib_qp.qp_num = my_qp->real_qp_num;
599 my_qp->ib_qp.qp_type = init_attr->qp_type; 600 my_qp->ib_qp.qp_type = init_attr->qp_type;
600 601
601 my_qp->qp_type = init_attr->qp_type; 602 my_qp->qp_type = init_attr->qp_type;
@@ -968,17 +969,21 @@ static int internal_modify_qp(struct ib_qp *ibqp,
968 ((ehca_mult - 1) / ah_mult) : 0; 969 ((ehca_mult - 1) / ah_mult) : 0;
969 else 970 else
970 mqpcb->max_static_rate = 0; 971 mqpcb->max_static_rate = 0;
971
972 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE, 1); 972 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_MAX_STATIC_RATE, 1);
973 973
974 /* 974 /*
975 * Always supply the GRH flag, even if it's zero, to give the
976 * hypervisor a clear "yes" or "no" instead of a "perhaps"
977 */
978 update_mask |= EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1);
979
980 /*
975 * only if GRH is TRUE we might consider SOURCE_GID_IDX 981 * only if GRH is TRUE we might consider SOURCE_GID_IDX
976 * and DEST_GID otherwise phype will return H_ATTR_PARM!!! 982 * and DEST_GID otherwise phype will return H_ATTR_PARM!!!
977 */ 983 */
978 if (attr->ah_attr.ah_flags == IB_AH_GRH) { 984 if (attr->ah_attr.ah_flags == IB_AH_GRH) {
979 mqpcb->send_grh_flag = 1 << 31; 985 mqpcb->send_grh_flag = 1;
980 update_mask |= 986
981 EHCA_BMASK_SET(MQPCB_MASK_SEND_GRH_FLAG, 1);
982 mqpcb->source_gid_idx = attr->ah_attr.grh.sgid_index; 987 mqpcb->source_gid_idx = attr->ah_attr.grh.sgid_index;
983 update_mask |= 988 update_mask |=
984 EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX, 1); 989 EHCA_BMASK_SET(MQPCB_MASK_SOURCE_GID_IDX, 1);
diff --git a/drivers/infiniband/hw/ehca/hcp_if.c b/drivers/infiniband/hw/ehca/hcp_if.c
index b564fcd3b282..7f0beec74f70 100644
--- a/drivers/infiniband/hw/ehca/hcp_if.c
+++ b/drivers/infiniband/hw/ehca/hcp_if.c
@@ -154,7 +154,8 @@ static long ehca_plpar_hcall9(unsigned long opcode,
154 unsigned long arg9) 154 unsigned long arg9)
155{ 155{
156 long ret; 156 long ret;
157 int i, sleep_msecs; 157 int i, sleep_msecs, lock_is_set = 0;
158 unsigned long flags;
158 159
159 ehca_gen_dbg("opcode=%lx arg1=%lx arg2=%lx arg3=%lx arg4=%lx " 160 ehca_gen_dbg("opcode=%lx arg1=%lx arg2=%lx arg3=%lx arg4=%lx "
160 "arg5=%lx arg6=%lx arg7=%lx arg8=%lx arg9=%lx", 161 "arg5=%lx arg6=%lx arg7=%lx arg8=%lx arg9=%lx",
@@ -162,10 +163,18 @@ static long ehca_plpar_hcall9(unsigned long opcode,
162 arg8, arg9); 163 arg8, arg9);
163 164
164 for (i = 0; i < 5; i++) { 165 for (i = 0; i < 5; i++) {
166 if ((opcode == H_ALLOC_RESOURCE) && (arg2 == 5)) {
167 spin_lock_irqsave(&hcall_lock, flags);
168 lock_is_set = 1;
169 }
170
165 ret = plpar_hcall9(opcode, outs, 171 ret = plpar_hcall9(opcode, outs,
166 arg1, arg2, arg3, arg4, arg5, 172 arg1, arg2, arg3, arg4, arg5,
167 arg6, arg7, arg8, arg9); 173 arg6, arg7, arg8, arg9);
168 174
175 if (lock_is_set)
176 spin_unlock_irqrestore(&hcall_lock, flags);
177
169 if (H_IS_LONG_BUSY(ret)) { 178 if (H_IS_LONG_BUSY(ret)) {
170 sleep_msecs = get_longbusy_msecs(ret); 179 sleep_msecs = get_longbusy_msecs(ret);
171 msleep_interruptible(sleep_msecs); 180 msleep_interruptible(sleep_msecs);
@@ -193,11 +202,11 @@ static long ehca_plpar_hcall9(unsigned long opcode,
193 opcode, ret, outs[0], outs[1], outs[2], outs[3], 202 opcode, ret, outs[0], outs[1], outs[2], outs[3],
194 outs[4], outs[5], outs[6], outs[7], outs[8]); 203 outs[4], outs[5], outs[6], outs[7], outs[8]);
195 return ret; 204 return ret;
196
197 } 205 }
198 206
199 return H_BUSY; 207 return H_BUSY;
200} 208}
209
201u64 hipz_h_alloc_resource_eq(const struct ipz_adapter_handle adapter_handle, 210u64 hipz_h_alloc_resource_eq(const struct ipz_adapter_handle adapter_handle,
202 struct ehca_pfeq *pfeq, 211 struct ehca_pfeq *pfeq,
203 const u32 neq_control, 212 const u32 neq_control,
diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
index 036ed1ef1796..ebd5c7bd2cdb 100644
--- a/drivers/infiniband/hw/ipath/ipath_fs.c
+++ b/drivers/infiniband/hw/ipath/ipath_fs.c
@@ -523,7 +523,7 @@ static int ipathfs_fill_super(struct super_block *sb, void *data,
523 int ret; 523 int ret;
524 524
525 static struct tree_descr files[] = { 525 static struct tree_descr files[] = {
526 [1] = {"atomic_stats", &atomic_stats_ops, S_IRUGO}, 526 [2] = {"atomic_stats", &atomic_stats_ops, S_IRUGO},
527 {""}, 527 {""},
528 }; 528 };
529 529
diff --git a/drivers/infiniband/hw/ipath/ipath_iba6120.c b/drivers/infiniband/hw/ipath/ipath_iba6120.c
index 1b9c30857754..4e2e3dfeb2c8 100644
--- a/drivers/infiniband/hw/ipath/ipath_iba6120.c
+++ b/drivers/infiniband/hw/ipath/ipath_iba6120.c
@@ -747,7 +747,6 @@ static void ipath_pe_quiet_serdes(struct ipath_devdata *dd)
747 747
748static int ipath_pe_intconfig(struct ipath_devdata *dd) 748static int ipath_pe_intconfig(struct ipath_devdata *dd)
749{ 749{
750 u64 val;
751 u32 chiprev; 750 u32 chiprev;
752 751
753 /* 752 /*
@@ -760,9 +759,9 @@ static int ipath_pe_intconfig(struct ipath_devdata *dd)
760 if ((chiprev & INFINIPATH_R_CHIPREVMINOR_MASK) > 1) { 759 if ((chiprev & INFINIPATH_R_CHIPREVMINOR_MASK) > 1) {
761 /* Rev2+ reports extra errors via internal GPIO pins */ 760 /* Rev2+ reports extra errors via internal GPIO pins */
762 dd->ipath_flags |= IPATH_GPIO_ERRINTRS; 761 dd->ipath_flags |= IPATH_GPIO_ERRINTRS;
763 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_mask); 762 dd->ipath_gpio_mask |= IPATH_GPIO_ERRINTR_MASK;
764 val |= IPATH_GPIO_ERRINTR_MASK; 763 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
765 ipath_write_kreg( dd, dd->ipath_kregs->kr_gpio_mask, val); 764 dd->ipath_gpio_mask);
766 } 765 }
767 return 0; 766 return 0;
768} 767}
diff --git a/drivers/infiniband/hw/ipath/ipath_intr.c b/drivers/infiniband/hw/ipath/ipath_intr.c
index 45d033169c6e..a90d3b5699c4 100644
--- a/drivers/infiniband/hw/ipath/ipath_intr.c
+++ b/drivers/infiniband/hw/ipath/ipath_intr.c
@@ -1056,7 +1056,7 @@ irqreturn_t ipath_intr(int irq, void *data)
1056 gpiostatus &= ~(1 << IPATH_GPIO_PORT0_BIT); 1056 gpiostatus &= ~(1 << IPATH_GPIO_PORT0_BIT);
1057 chk0rcv = 1; 1057 chk0rcv = 1;
1058 } 1058 }
1059 if (unlikely(gpiostatus)) { 1059 if (gpiostatus) {
1060 /* 1060 /*
1061 * Some unexpected bits remain. If they could have 1061 * Some unexpected bits remain. If they could have
1062 * caused the interrupt, complain and clear. 1062 * caused the interrupt, complain and clear.
@@ -1065,9 +1065,8 @@ irqreturn_t ipath_intr(int irq, void *data)
1065 * GPIO interrupts, possibly on a "three strikes" 1065 * GPIO interrupts, possibly on a "three strikes"
1066 * basis. 1066 * basis.
1067 */ 1067 */
1068 u32 mask; 1068 const u32 mask = (u32) dd->ipath_gpio_mask;
1069 mask = ipath_read_kreg32( 1069
1070 dd, dd->ipath_kregs->kr_gpio_mask);
1071 if (mask & gpiostatus) { 1070 if (mask & gpiostatus) {
1072 ipath_dbg("Unexpected GPIO IRQ bits %x\n", 1071 ipath_dbg("Unexpected GPIO IRQ bits %x\n",
1073 gpiostatus & mask); 1072 gpiostatus & mask);
diff --git a/drivers/infiniband/hw/ipath/ipath_kernel.h b/drivers/infiniband/hw/ipath/ipath_kernel.h
index e900c2593f44..12194f3dd8cc 100644
--- a/drivers/infiniband/hw/ipath/ipath_kernel.h
+++ b/drivers/infiniband/hw/ipath/ipath_kernel.h
@@ -397,6 +397,8 @@ struct ipath_devdata {
397 unsigned long ipath_pioavailshadow[8]; 397 unsigned long ipath_pioavailshadow[8];
398 /* shadow of kr_gpio_out, for rmw ops */ 398 /* shadow of kr_gpio_out, for rmw ops */
399 u64 ipath_gpio_out; 399 u64 ipath_gpio_out;
400 /* shadow the gpio mask register */
401 u64 ipath_gpio_mask;
400 /* kr_revision shadow */ 402 /* kr_revision shadow */
401 u64 ipath_revision; 403 u64 ipath_revision;
402 /* 404 /*
diff --git a/drivers/infiniband/hw/ipath/ipath_mr.c b/drivers/infiniband/hw/ipath/ipath_mr.c
index 31e70732e369..bdeef8d4f279 100644
--- a/drivers/infiniband/hw/ipath/ipath_mr.c
+++ b/drivers/infiniband/hw/ipath/ipath_mr.c
@@ -31,6 +31,7 @@
31 * SOFTWARE. 31 * SOFTWARE.
32 */ 32 */
33 33
34#include <rdma/ib_umem.h>
34#include <rdma/ib_pack.h> 35#include <rdma/ib_pack.h>
35#include <rdma/ib_smi.h> 36#include <rdma/ib_smi.h>
36 37
@@ -147,6 +148,7 @@ struct ib_mr *ipath_reg_phys_mr(struct ib_pd *pd,
147 mr->mr.offset = 0; 148 mr->mr.offset = 0;
148 mr->mr.access_flags = acc; 149 mr->mr.access_flags = acc;
149 mr->mr.max_segs = num_phys_buf; 150 mr->mr.max_segs = num_phys_buf;
151 mr->umem = NULL;
150 152
151 m = 0; 153 m = 0;
152 n = 0; 154 n = 0;
@@ -170,46 +172,56 @@ bail:
170/** 172/**
171 * ipath_reg_user_mr - register a userspace memory region 173 * ipath_reg_user_mr - register a userspace memory region
172 * @pd: protection domain for this memory region 174 * @pd: protection domain for this memory region
173 * @region: the user memory region 175 * @start: starting userspace address
176 * @length: length of region to register
177 * @virt_addr: virtual address to use (from HCA's point of view)
174 * @mr_access_flags: access flags for this memory region 178 * @mr_access_flags: access flags for this memory region
175 * @udata: unused by the InfiniPath driver 179 * @udata: unused by the InfiniPath driver
176 * 180 *
177 * Returns the memory region on success, otherwise returns an errno. 181 * Returns the memory region on success, otherwise returns an errno.
178 */ 182 */
179struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd, struct ib_umem *region, 183struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
180 int mr_access_flags, struct ib_udata *udata) 184 u64 virt_addr, int mr_access_flags,
185 struct ib_udata *udata)
181{ 186{
182 struct ipath_mr *mr; 187 struct ipath_mr *mr;
188 struct ib_umem *umem;
183 struct ib_umem_chunk *chunk; 189 struct ib_umem_chunk *chunk;
184 int n, m, i; 190 int n, m, i;
185 struct ib_mr *ret; 191 struct ib_mr *ret;
186 192
187 if (region->length == 0) { 193 if (length == 0) {
188 ret = ERR_PTR(-EINVAL); 194 ret = ERR_PTR(-EINVAL);
189 goto bail; 195 goto bail;
190 } 196 }
191 197
198 umem = ib_umem_get(pd->uobject->context, start, length, mr_access_flags);
199 if (IS_ERR(umem))
200 return (void *) umem;
201
192 n = 0; 202 n = 0;
193 list_for_each_entry(chunk, &region->chunk_list, list) 203 list_for_each_entry(chunk, &umem->chunk_list, list)
194 n += chunk->nents; 204 n += chunk->nents;
195 205
196 mr = alloc_mr(n, &to_idev(pd->device)->lk_table); 206 mr = alloc_mr(n, &to_idev(pd->device)->lk_table);
197 if (!mr) { 207 if (!mr) {
198 ret = ERR_PTR(-ENOMEM); 208 ret = ERR_PTR(-ENOMEM);
209 ib_umem_release(umem);
199 goto bail; 210 goto bail;
200 } 211 }
201 212
202 mr->mr.pd = pd; 213 mr->mr.pd = pd;
203 mr->mr.user_base = region->user_base; 214 mr->mr.user_base = start;
204 mr->mr.iova = region->virt_base; 215 mr->mr.iova = virt_addr;
205 mr->mr.length = region->length; 216 mr->mr.length = length;
206 mr->mr.offset = region->offset; 217 mr->mr.offset = umem->offset;
207 mr->mr.access_flags = mr_access_flags; 218 mr->mr.access_flags = mr_access_flags;
208 mr->mr.max_segs = n; 219 mr->mr.max_segs = n;
220 mr->umem = umem;
209 221
210 m = 0; 222 m = 0;
211 n = 0; 223 n = 0;
212 list_for_each_entry(chunk, &region->chunk_list, list) { 224 list_for_each_entry(chunk, &umem->chunk_list, list) {
213 for (i = 0; i < chunk->nents; i++) { 225 for (i = 0; i < chunk->nents; i++) {
214 void *vaddr; 226 void *vaddr;
215 227
@@ -219,7 +231,7 @@ struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
219 goto bail; 231 goto bail;
220 } 232 }
221 mr->mr.map[m]->segs[n].vaddr = vaddr; 233 mr->mr.map[m]->segs[n].vaddr = vaddr;
222 mr->mr.map[m]->segs[n].length = region->page_size; 234 mr->mr.map[m]->segs[n].length = umem->page_size;
223 n++; 235 n++;
224 if (n == IPATH_SEGSZ) { 236 if (n == IPATH_SEGSZ) {
225 m++; 237 m++;
@@ -253,6 +265,10 @@ int ipath_dereg_mr(struct ib_mr *ibmr)
253 i--; 265 i--;
254 kfree(mr->mr.map[i]); 266 kfree(mr->mr.map[i]);
255 } 267 }
268
269 if (mr->umem)
270 ib_umem_release(mr->umem);
271
256 kfree(mr); 272 kfree(mr);
257 return 0; 273 return 0;
258} 274}
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.c b/drivers/infiniband/hw/ipath/ipath_verbs.c
index 12933e77c7e9..bb70845279b8 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.c
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.c
@@ -1387,13 +1387,12 @@ static int enable_timer(struct ipath_devdata *dd)
1387 * processing. 1387 * processing.
1388 */ 1388 */
1389 if (dd->ipath_flags & IPATH_GPIO_INTR) { 1389 if (dd->ipath_flags & IPATH_GPIO_INTR) {
1390 u64 val;
1391 ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect, 1390 ipath_write_kreg(dd, dd->ipath_kregs->kr_debugportselect,
1392 0x2074076542310ULL); 1391 0x2074076542310ULL);
1393 /* Enable GPIO bit 2 interrupt */ 1392 /* Enable GPIO bit 2 interrupt */
1394 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_mask); 1393 dd->ipath_gpio_mask |= (u64) (1 << IPATH_GPIO_PORT0_BIT);
1395 val |= (u64) (1 << IPATH_GPIO_PORT0_BIT); 1394 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
1396 ipath_write_kreg( dd, dd->ipath_kregs->kr_gpio_mask, val); 1395 dd->ipath_gpio_mask);
1397 } 1396 }
1398 1397
1399 init_timer(&dd->verbs_timer); 1398 init_timer(&dd->verbs_timer);
@@ -1412,8 +1411,9 @@ static int disable_timer(struct ipath_devdata *dd)
1412 u64 val; 1411 u64 val;
1413 /* Disable GPIO bit 2 interrupt */ 1412 /* Disable GPIO bit 2 interrupt */
1414 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_mask); 1413 val = ipath_read_kreg64(dd, dd->ipath_kregs->kr_gpio_mask);
1415 val &= ~((u64) (1 << IPATH_GPIO_PORT0_BIT)); 1414 dd->ipath_gpio_mask &= ~((u64) (1 << IPATH_GPIO_PORT0_BIT));
1416 ipath_write_kreg( dd, dd->ipath_kregs->kr_gpio_mask, val); 1415 ipath_write_kreg(dd, dd->ipath_kregs->kr_gpio_mask,
1416 dd->ipath_gpio_mask);
1417 /* 1417 /*
1418 * We might want to undo changes to debugportselect, 1418 * We might want to undo changes to debugportselect,
1419 * but how? 1419 * but how?
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs.h b/drivers/infiniband/hw/ipath/ipath_verbs.h
index 7064fc222727..088b837ebea8 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs.h
+++ b/drivers/infiniband/hw/ipath/ipath_verbs.h
@@ -251,6 +251,7 @@ struct ipath_sge {
251/* Memory region */ 251/* Memory region */
252struct ipath_mr { 252struct ipath_mr {
253 struct ib_mr ibmr; 253 struct ib_mr ibmr;
254 struct ib_umem *umem;
254 struct ipath_mregion mr; /* must be last */ 255 struct ipath_mregion mr; /* must be last */
255}; 256};
256 257
@@ -751,8 +752,8 @@ struct ib_mr *ipath_reg_phys_mr(struct ib_pd *pd,
751 struct ib_phys_buf *buffer_list, 752 struct ib_phys_buf *buffer_list,
752 int num_phys_buf, int acc, u64 *iova_start); 753 int num_phys_buf, int acc, u64 *iova_start);
753 754
754struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd, struct ib_umem *region, 755struct ib_mr *ipath_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
755 int mr_access_flags, 756 u64 virt_addr, int mr_access_flags,
756 struct ib_udata *udata); 757 struct ib_udata *udata);
757 758
758int ipath_dereg_mr(struct ib_mr *ibmr); 759int ipath_dereg_mr(struct ib_mr *ibmr);
diff --git a/drivers/infiniband/hw/ipath/ipath_verbs_mcast.c b/drivers/infiniband/hw/ipath/ipath_verbs_mcast.c
index 085e28b939ec..dd691cfa5079 100644
--- a/drivers/infiniband/hw/ipath/ipath_verbs_mcast.c
+++ b/drivers/infiniband/hw/ipath/ipath_verbs_mcast.c
@@ -165,10 +165,9 @@ static int ipath_mcast_add(struct ipath_ibdev *dev,
165{ 165{
166 struct rb_node **n = &mcast_tree.rb_node; 166 struct rb_node **n = &mcast_tree.rb_node;
167 struct rb_node *pn = NULL; 167 struct rb_node *pn = NULL;
168 unsigned long flags;
169 int ret; 168 int ret;
170 169
171 spin_lock_irqsave(&mcast_lock, flags); 170 spin_lock_irq(&mcast_lock);
172 171
173 while (*n) { 172 while (*n) {
174 struct ipath_mcast *tmcast; 173 struct ipath_mcast *tmcast;
@@ -228,7 +227,7 @@ static int ipath_mcast_add(struct ipath_ibdev *dev,
228 ret = 0; 227 ret = 0;
229 228
230bail: 229bail:
231 spin_unlock_irqrestore(&mcast_lock, flags); 230 spin_unlock_irq(&mcast_lock);
232 231
233 return ret; 232 return ret;
234} 233}
@@ -289,17 +288,16 @@ int ipath_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
289 struct ipath_mcast *mcast = NULL; 288 struct ipath_mcast *mcast = NULL;
290 struct ipath_mcast_qp *p, *tmp; 289 struct ipath_mcast_qp *p, *tmp;
291 struct rb_node *n; 290 struct rb_node *n;
292 unsigned long flags;
293 int last = 0; 291 int last = 0;
294 int ret; 292 int ret;
295 293
296 spin_lock_irqsave(&mcast_lock, flags); 294 spin_lock_irq(&mcast_lock);
297 295
298 /* Find the GID in the mcast table. */ 296 /* Find the GID in the mcast table. */
299 n = mcast_tree.rb_node; 297 n = mcast_tree.rb_node;
300 while (1) { 298 while (1) {
301 if (n == NULL) { 299 if (n == NULL) {
302 spin_unlock_irqrestore(&mcast_lock, flags); 300 spin_unlock_irq(&mcast_lock);
303 ret = -EINVAL; 301 ret = -EINVAL;
304 goto bail; 302 goto bail;
305 } 303 }
@@ -334,7 +332,7 @@ int ipath_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
334 break; 332 break;
335 } 333 }
336 334
337 spin_unlock_irqrestore(&mcast_lock, flags); 335 spin_unlock_irq(&mcast_lock);
338 336
339 if (p) { 337 if (p) {
340 /* 338 /*
@@ -348,9 +346,9 @@ int ipath_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
348 atomic_dec(&mcast->refcount); 346 atomic_dec(&mcast->refcount);
349 wait_event(mcast->wait, !atomic_read(&mcast->refcount)); 347 wait_event(mcast->wait, !atomic_read(&mcast->refcount));
350 ipath_mcast_free(mcast); 348 ipath_mcast_free(mcast);
351 spin_lock(&dev->n_mcast_grps_lock); 349 spin_lock_irq(&dev->n_mcast_grps_lock);
352 dev->n_mcast_grps_allocated--; 350 dev->n_mcast_grps_allocated--;
353 spin_unlock(&dev->n_mcast_grps_lock); 351 spin_unlock_irq(&dev->n_mcast_grps_lock);
354 } 352 }
355 353
356 ret = 0; 354 ret = 0;
diff --git a/drivers/infiniband/hw/mlx4/Kconfig b/drivers/infiniband/hw/mlx4/Kconfig
new file mode 100644
index 000000000000..b8912cdb9663
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/Kconfig
@@ -0,0 +1,9 @@
1config MLX4_INFINIBAND
2 tristate "Mellanox ConnectX HCA support"
3 depends on INFINIBAND
4 select MLX4_CORE
5 ---help---
6 This driver provides low-level InfiniBand support for
7 Mellanox ConnectX PCI Express host channel adapters (HCAs).
8 This is required to use InfiniBand protocols such as
9 IP-over-IB or SRP with these devices.
diff --git a/drivers/infiniband/hw/mlx4/Makefile b/drivers/infiniband/hw/mlx4/Makefile
new file mode 100644
index 000000000000..70f09c7826da
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_MLX4_INFINIBAND) += mlx4_ib.o
2
3mlx4_ib-y := ah.o cq.o doorbell.o mad.o main.o mr.o qp.o srq.o
diff --git a/drivers/infiniband/hw/mlx4/ah.c b/drivers/infiniband/hw/mlx4/ah.c
new file mode 100644
index 000000000000..c75ac9463e20
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/ah.c
@@ -0,0 +1,100 @@
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include "mlx4_ib.h"
34
35struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr)
36{
37 struct mlx4_dev *dev = to_mdev(pd->device)->dev;
38 struct mlx4_ib_ah *ah;
39
40 ah = kmalloc(sizeof *ah, GFP_ATOMIC);
41 if (!ah)
42 return ERR_PTR(-ENOMEM);
43
44 memset(&ah->av, 0, sizeof ah->av);
45
46 ah->av.port_pd = cpu_to_be32(to_mpd(pd)->pdn | (ah_attr->port_num << 24));
47 ah->av.g_slid = ah_attr->src_path_bits;
48 ah->av.dlid = cpu_to_be16(ah_attr->dlid);
49 if (ah_attr->static_rate) {
50 ah->av.stat_rate = ah_attr->static_rate + MLX4_STAT_RATE_OFFSET;
51 while (ah->av.stat_rate > IB_RATE_2_5_GBPS + MLX4_STAT_RATE_OFFSET &&
52 !(1 << ah->av.stat_rate & dev->caps.stat_rate_support))
53 --ah->av.stat_rate;
54 }
55 ah->av.sl_tclass_flowlabel = cpu_to_be32(ah_attr->sl << 28);
56 if (ah_attr->ah_flags & IB_AH_GRH) {
57 ah->av.g_slid |= 0x80;
58 ah->av.gid_index = ah_attr->grh.sgid_index;
59 ah->av.hop_limit = ah_attr->grh.hop_limit;
60 ah->av.sl_tclass_flowlabel |=
61 cpu_to_be32((ah_attr->grh.traffic_class << 20) |
62 ah_attr->grh.flow_label);
63 memcpy(ah->av.dgid, ah_attr->grh.dgid.raw, 16);
64 }
65
66 return &ah->ibah;
67}
68
69int mlx4_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr)
70{
71 struct mlx4_ib_ah *ah = to_mah(ibah);
72
73 memset(ah_attr, 0, sizeof *ah_attr);
74 ah_attr->dlid = be16_to_cpu(ah->av.dlid);
75 ah_attr->sl = be32_to_cpu(ah->av.sl_tclass_flowlabel) >> 28;
76 ah_attr->port_num = be32_to_cpu(ah->av.port_pd) >> 24;
77 if (ah->av.stat_rate)
78 ah_attr->static_rate = ah->av.stat_rate - MLX4_STAT_RATE_OFFSET;
79 ah_attr->src_path_bits = ah->av.g_slid & 0x7F;
80
81 if (mlx4_ib_ah_grh_present(ah)) {
82 ah_attr->ah_flags = IB_AH_GRH;
83
84 ah_attr->grh.traffic_class =
85 be32_to_cpu(ah->av.sl_tclass_flowlabel) >> 20;
86 ah_attr->grh.flow_label =
87 be32_to_cpu(ah->av.sl_tclass_flowlabel) & 0xfffff;
88 ah_attr->grh.hop_limit = ah->av.hop_limit;
89 ah_attr->grh.sgid_index = ah->av.gid_index;
90 memcpy(ah_attr->grh.dgid.raw, ah->av.dgid, 16);
91 }
92
93 return 0;
94}
95
96int mlx4_ib_destroy_ah(struct ib_ah *ah)
97{
98 kfree(to_mah(ah));
99 return 0;
100}
diff --git a/drivers/infiniband/hw/mlx4/cq.c b/drivers/infiniband/hw/mlx4/cq.c
new file mode 100644
index 000000000000..b2a290c6703a
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/cq.c
@@ -0,0 +1,525 @@
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/mlx4/cq.h>
34#include <linux/mlx4/qp.h>
35
36#include "mlx4_ib.h"
37#include "user.h"
38
39static void mlx4_ib_cq_comp(struct mlx4_cq *cq)
40{
41 struct ib_cq *ibcq = &to_mibcq(cq)->ibcq;
42 ibcq->comp_handler(ibcq, ibcq->cq_context);
43}
44
45static void mlx4_ib_cq_event(struct mlx4_cq *cq, enum mlx4_event type)
46{
47 struct ib_event event;
48 struct ib_cq *ibcq;
49
50 if (type != MLX4_EVENT_TYPE_CQ_ERROR) {
51 printk(KERN_WARNING "mlx4_ib: Unexpected event type %d "
52 "on CQ %06x\n", type, cq->cqn);
53 return;
54 }
55
56 ibcq = &to_mibcq(cq)->ibcq;
57 if (ibcq->event_handler) {
58 event.device = ibcq->device;
59 event.event = IB_EVENT_CQ_ERR;
60 event.element.cq = ibcq;
61 ibcq->event_handler(&event, ibcq->cq_context);
62 }
63}
64
65static void *get_cqe_from_buf(struct mlx4_ib_cq_buf *buf, int n)
66{
67 int offset = n * sizeof (struct mlx4_cqe);
68
69 if (buf->buf.nbufs == 1)
70 return buf->buf.u.direct.buf + offset;
71 else
72 return buf->buf.u.page_list[offset >> PAGE_SHIFT].buf +
73 (offset & (PAGE_SIZE - 1));
74}
75
76static void *get_cqe(struct mlx4_ib_cq *cq, int n)
77{
78 return get_cqe_from_buf(&cq->buf, n);
79}
80
81static void *get_sw_cqe(struct mlx4_ib_cq *cq, int n)
82{
83 struct mlx4_cqe *cqe = get_cqe(cq, n & cq->ibcq.cqe);
84
85 return (!!(cqe->owner_sr_opcode & MLX4_CQE_OWNER_MASK) ^
86 !!(n & (cq->ibcq.cqe + 1))) ? NULL : cqe;
87}
88
89static struct mlx4_cqe *next_cqe_sw(struct mlx4_ib_cq *cq)
90{
91 return get_sw_cqe(cq, cq->mcq.cons_index);
92}
93
94struct ib_cq *mlx4_ib_create_cq(struct ib_device *ibdev, int entries, int vector,
95 struct ib_ucontext *context,
96 struct ib_udata *udata)
97{
98 struct mlx4_ib_dev *dev = to_mdev(ibdev);
99 struct mlx4_ib_cq *cq;
100 struct mlx4_uar *uar;
101 int buf_size;
102 int err;
103
104 if (entries < 1 || entries > dev->dev->caps.max_cqes)
105 return ERR_PTR(-EINVAL);
106
107 cq = kmalloc(sizeof *cq, GFP_KERNEL);
108 if (!cq)
109 return ERR_PTR(-ENOMEM);
110
111 entries = roundup_pow_of_two(entries + 1);
112 cq->ibcq.cqe = entries - 1;
113 buf_size = entries * sizeof (struct mlx4_cqe);
114 spin_lock_init(&cq->lock);
115
116 if (context) {
117 struct mlx4_ib_create_cq ucmd;
118
119 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
120 err = -EFAULT;
121 goto err_cq;
122 }
123
124 cq->umem = ib_umem_get(context, ucmd.buf_addr, buf_size,
125 IB_ACCESS_LOCAL_WRITE);
126 if (IS_ERR(cq->umem)) {
127 err = PTR_ERR(cq->umem);
128 goto err_cq;
129 }
130
131 err = mlx4_mtt_init(dev->dev, ib_umem_page_count(cq->umem),
132 ilog2(cq->umem->page_size), &cq->buf.mtt);
133 if (err)
134 goto err_buf;
135
136 err = mlx4_ib_umem_write_mtt(dev, &cq->buf.mtt, cq->umem);
137 if (err)
138 goto err_mtt;
139
140 err = mlx4_ib_db_map_user(to_mucontext(context), ucmd.db_addr,
141 &cq->db);
142 if (err)
143 goto err_mtt;
144
145 uar = &to_mucontext(context)->uar;
146 } else {
147 err = mlx4_ib_db_alloc(dev, &cq->db, 1);
148 if (err)
149 goto err_cq;
150
151 cq->mcq.set_ci_db = cq->db.db;
152 cq->mcq.arm_db = cq->db.db + 1;
153 *cq->mcq.set_ci_db = 0;
154 *cq->mcq.arm_db = 0;
155
156 if (mlx4_buf_alloc(dev->dev, buf_size, PAGE_SIZE * 2, &cq->buf.buf)) {
157 err = -ENOMEM;
158 goto err_db;
159 }
160
161 err = mlx4_mtt_init(dev->dev, cq->buf.buf.npages, cq->buf.buf.page_shift,
162 &cq->buf.mtt);
163 if (err)
164 goto err_buf;
165
166 err = mlx4_buf_write_mtt(dev->dev, &cq->buf.mtt, &cq->buf.buf);
167 if (err)
168 goto err_mtt;
169
170 uar = &dev->priv_uar;
171 }
172
173 err = mlx4_cq_alloc(dev->dev, entries, &cq->buf.mtt, uar,
174 cq->db.dma, &cq->mcq);
175 if (err)
176 goto err_dbmap;
177
178 cq->mcq.comp = mlx4_ib_cq_comp;
179 cq->mcq.event = mlx4_ib_cq_event;
180
181 if (context)
182 if (ib_copy_to_udata(udata, &cq->mcq.cqn, sizeof (__u32))) {
183 err = -EFAULT;
184 goto err_dbmap;
185 }
186
187 return &cq->ibcq;
188
189err_dbmap:
190 if (context)
191 mlx4_ib_db_unmap_user(to_mucontext(context), &cq->db);
192
193err_mtt:
194 mlx4_mtt_cleanup(dev->dev, &cq->buf.mtt);
195
196err_buf:
197 if (context)
198 ib_umem_release(cq->umem);
199 else
200 mlx4_buf_free(dev->dev, entries * sizeof (struct mlx4_cqe),
201 &cq->buf.buf);
202
203err_db:
204 if (!context)
205 mlx4_ib_db_free(dev, &cq->db);
206
207err_cq:
208 kfree(cq);
209
210 return ERR_PTR(err);
211}
212
213int mlx4_ib_destroy_cq(struct ib_cq *cq)
214{
215 struct mlx4_ib_dev *dev = to_mdev(cq->device);
216 struct mlx4_ib_cq *mcq = to_mcq(cq);
217
218 mlx4_cq_free(dev->dev, &mcq->mcq);
219 mlx4_mtt_cleanup(dev->dev, &mcq->buf.mtt);
220
221 if (cq->uobject) {
222 mlx4_ib_db_unmap_user(to_mucontext(cq->uobject->context), &mcq->db);
223 ib_umem_release(mcq->umem);
224 } else {
225 mlx4_buf_free(dev->dev, (cq->cqe + 1) * sizeof (struct mlx4_cqe),
226 &mcq->buf.buf);
227 mlx4_ib_db_free(dev, &mcq->db);
228 }
229
230 kfree(mcq);
231
232 return 0;
233}
234
235static void dump_cqe(void *cqe)
236{
237 __be32 *buf = cqe;
238
239 printk(KERN_DEBUG "CQE contents %08x %08x %08x %08x %08x %08x %08x %08x\n",
240 be32_to_cpu(buf[0]), be32_to_cpu(buf[1]), be32_to_cpu(buf[2]),
241 be32_to_cpu(buf[3]), be32_to_cpu(buf[4]), be32_to_cpu(buf[5]),
242 be32_to_cpu(buf[6]), be32_to_cpu(buf[7]));
243}
244
245static void mlx4_ib_handle_error_cqe(struct mlx4_err_cqe *cqe,
246 struct ib_wc *wc)
247{
248 if (cqe->syndrome == MLX4_CQE_SYNDROME_LOCAL_QP_OP_ERR) {
249 printk(KERN_DEBUG "local QP operation err "
250 "(QPN %06x, WQE index %x, vendor syndrome %02x, "
251 "opcode = %02x)\n",
252 be32_to_cpu(cqe->my_qpn), be16_to_cpu(cqe->wqe_index),
253 cqe->vendor_err_syndrome,
254 cqe->owner_sr_opcode & ~MLX4_CQE_OWNER_MASK);
255 dump_cqe(cqe);
256 }
257
258 switch (cqe->syndrome) {
259 case MLX4_CQE_SYNDROME_LOCAL_LENGTH_ERR:
260 wc->status = IB_WC_LOC_LEN_ERR;
261 break;
262 case MLX4_CQE_SYNDROME_LOCAL_QP_OP_ERR:
263 wc->status = IB_WC_LOC_QP_OP_ERR;
264 break;
265 case MLX4_CQE_SYNDROME_LOCAL_PROT_ERR:
266 wc->status = IB_WC_LOC_PROT_ERR;
267 break;
268 case MLX4_CQE_SYNDROME_WR_FLUSH_ERR:
269 wc->status = IB_WC_WR_FLUSH_ERR;
270 break;
271 case MLX4_CQE_SYNDROME_MW_BIND_ERR:
272 wc->status = IB_WC_MW_BIND_ERR;
273 break;
274 case MLX4_CQE_SYNDROME_BAD_RESP_ERR:
275 wc->status = IB_WC_BAD_RESP_ERR;
276 break;
277 case MLX4_CQE_SYNDROME_LOCAL_ACCESS_ERR:
278 wc->status = IB_WC_LOC_ACCESS_ERR;
279 break;
280 case MLX4_CQE_SYNDROME_REMOTE_INVAL_REQ_ERR:
281 wc->status = IB_WC_REM_INV_REQ_ERR;
282 break;
283 case MLX4_CQE_SYNDROME_REMOTE_ACCESS_ERR:
284 wc->status = IB_WC_REM_ACCESS_ERR;
285 break;
286 case MLX4_CQE_SYNDROME_REMOTE_OP_ERR:
287 wc->status = IB_WC_REM_OP_ERR;
288 break;
289 case MLX4_CQE_SYNDROME_TRANSPORT_RETRY_EXC_ERR:
290 wc->status = IB_WC_RETRY_EXC_ERR;
291 break;
292 case MLX4_CQE_SYNDROME_RNR_RETRY_EXC_ERR:
293 wc->status = IB_WC_RNR_RETRY_EXC_ERR;
294 break;
295 case MLX4_CQE_SYNDROME_REMOTE_ABORTED_ERR:
296 wc->status = IB_WC_REM_ABORT_ERR;
297 break;
298 default:
299 wc->status = IB_WC_GENERAL_ERR;
300 break;
301 }
302
303 wc->vendor_err = cqe->vendor_err_syndrome;
304}
305
306static int mlx4_ib_poll_one(struct mlx4_ib_cq *cq,
307 struct mlx4_ib_qp **cur_qp,
308 struct ib_wc *wc)
309{
310 struct mlx4_cqe *cqe;
311 struct mlx4_qp *mqp;
312 struct mlx4_ib_wq *wq;
313 struct mlx4_ib_srq *srq;
314 int is_send;
315 int is_error;
316 u16 wqe_ctr;
317
318 cqe = next_cqe_sw(cq);
319 if (!cqe)
320 return -EAGAIN;
321
322 ++cq->mcq.cons_index;
323
324 /*
325 * Make sure we read CQ entry contents after we've checked the
326 * ownership bit.
327 */
328 rmb();
329
330 is_send = cqe->owner_sr_opcode & MLX4_CQE_IS_SEND_MASK;
331 is_error = (cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) ==
332 MLX4_CQE_OPCODE_ERROR;
333
334 if (!*cur_qp ||
335 (be32_to_cpu(cqe->my_qpn) & 0xffffff) != (*cur_qp)->mqp.qpn) {
336 /*
337 * We do not have to take the QP table lock here,
338 * because CQs will be locked while QPs are removed
339 * from the table.
340 */
341 mqp = __mlx4_qp_lookup(to_mdev(cq->ibcq.device)->dev,
342 be32_to_cpu(cqe->my_qpn));
343 if (unlikely(!mqp)) {
344 printk(KERN_WARNING "CQ %06x with entry for unknown QPN %06x\n",
345 cq->mcq.cqn, be32_to_cpu(cqe->my_qpn) & 0xffffff);
346 return -EINVAL;
347 }
348
349 *cur_qp = to_mibqp(mqp);
350 }
351
352 wc->qp = &(*cur_qp)->ibqp;
353
354 if (is_send) {
355 wq = &(*cur_qp)->sq;
356 wqe_ctr = be16_to_cpu(cqe->wqe_index);
357 wq->tail += wqe_ctr - (u16) wq->tail;
358 wc->wr_id = wq->wrid[wq->tail & (wq->max - 1)];
359 ++wq->tail;
360 } else if ((*cur_qp)->ibqp.srq) {
361 srq = to_msrq((*cur_qp)->ibqp.srq);
362 wqe_ctr = be16_to_cpu(cqe->wqe_index);
363 wc->wr_id = srq->wrid[wqe_ctr];
364 mlx4_ib_free_srq_wqe(srq, wqe_ctr);
365 } else {
366 wq = &(*cur_qp)->rq;
367 wc->wr_id = wq->wrid[wq->tail & (wq->max - 1)];
368 ++wq->tail;
369 }
370
371 if (unlikely(is_error)) {
372 mlx4_ib_handle_error_cqe((struct mlx4_err_cqe *) cqe, wc);
373 return 0;
374 }
375
376 wc->status = IB_WC_SUCCESS;
377
378 if (is_send) {
379 wc->wc_flags = 0;
380 switch (cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) {
381 case MLX4_OPCODE_RDMA_WRITE_IMM:
382 wc->wc_flags |= IB_WC_WITH_IMM;
383 case MLX4_OPCODE_RDMA_WRITE:
384 wc->opcode = IB_WC_RDMA_WRITE;
385 break;
386 case MLX4_OPCODE_SEND_IMM:
387 wc->wc_flags |= IB_WC_WITH_IMM;
388 case MLX4_OPCODE_SEND:
389 wc->opcode = IB_WC_SEND;
390 break;
391 case MLX4_OPCODE_RDMA_READ:
392 wc->opcode = IB_WC_SEND;
393 wc->byte_len = be32_to_cpu(cqe->byte_cnt);
394 break;
395 case MLX4_OPCODE_ATOMIC_CS:
396 wc->opcode = IB_WC_COMP_SWAP;
397 wc->byte_len = 8;
398 break;
399 case MLX4_OPCODE_ATOMIC_FA:
400 wc->opcode = IB_WC_FETCH_ADD;
401 wc->byte_len = 8;
402 break;
403 case MLX4_OPCODE_BIND_MW:
404 wc->opcode = IB_WC_BIND_MW;
405 break;
406 }
407 } else {
408 wc->byte_len = be32_to_cpu(cqe->byte_cnt);
409
410 switch (cqe->owner_sr_opcode & MLX4_CQE_OPCODE_MASK) {
411 case MLX4_RECV_OPCODE_RDMA_WRITE_IMM:
412 wc->opcode = IB_WC_RECV_RDMA_WITH_IMM;
413 wc->wc_flags = IB_WC_WITH_IMM;
414 wc->imm_data = cqe->immed_rss_invalid;
415 break;
416 case MLX4_RECV_OPCODE_SEND:
417 wc->opcode = IB_WC_RECV;
418 wc->wc_flags = 0;
419 break;
420 case MLX4_RECV_OPCODE_SEND_IMM:
421 wc->opcode = IB_WC_RECV;
422 wc->wc_flags = IB_WC_WITH_IMM;
423 wc->imm_data = cqe->immed_rss_invalid;
424 break;
425 }
426
427 wc->slid = be16_to_cpu(cqe->rlid);
428 wc->sl = cqe->sl >> 4;
429 wc->src_qp = be32_to_cpu(cqe->g_mlpath_rqpn) & 0xffffff;
430 wc->dlid_path_bits = (be32_to_cpu(cqe->g_mlpath_rqpn) >> 24) & 0x7f;
431 wc->wc_flags |= be32_to_cpu(cqe->g_mlpath_rqpn) & 0x80000000 ?
432 IB_WC_GRH : 0;
433 wc->pkey_index = be32_to_cpu(cqe->immed_rss_invalid) >> 16;
434 }
435
436 return 0;
437}
438
439int mlx4_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc)
440{
441 struct mlx4_ib_cq *cq = to_mcq(ibcq);
442 struct mlx4_ib_qp *cur_qp = NULL;
443 unsigned long flags;
444 int npolled;
445 int err = 0;
446
447 spin_lock_irqsave(&cq->lock, flags);
448
449 for (npolled = 0; npolled < num_entries; ++npolled) {
450 err = mlx4_ib_poll_one(cq, &cur_qp, wc + npolled);
451 if (err)
452 break;
453 }
454
455 if (npolled)
456 mlx4_cq_set_ci(&cq->mcq);
457
458 spin_unlock_irqrestore(&cq->lock, flags);
459
460 if (err == 0 || err == -EAGAIN)
461 return npolled;
462 else
463 return err;
464}
465
466int mlx4_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags)
467{
468 mlx4_cq_arm(&to_mcq(ibcq)->mcq,
469 (flags & IB_CQ_SOLICITED_MASK) == IB_CQ_SOLICITED ?
470 MLX4_CQ_DB_REQ_NOT_SOL : MLX4_CQ_DB_REQ_NOT,
471 to_mdev(ibcq->device)->uar_map,
472 MLX4_GET_DOORBELL_LOCK(&to_mdev(ibcq->device)->uar_lock));
473
474 return 0;
475}
476
477void __mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq)
478{
479 u32 prod_index;
480 int nfreed = 0;
481 struct mlx4_cqe *cqe;
482
483 /*
484 * First we need to find the current producer index, so we
485 * know where to start cleaning from. It doesn't matter if HW
486 * adds new entries after this loop -- the QP we're worried
487 * about is already in RESET, so the new entries won't come
488 * from our QP and therefore don't need to be checked.
489 */
490 for (prod_index = cq->mcq.cons_index; get_sw_cqe(cq, prod_index); ++prod_index)
491 if (prod_index == cq->mcq.cons_index + cq->ibcq.cqe)
492 break;
493
494 /*
495 * Now sweep backwards through the CQ, removing CQ entries
496 * that match our QP by copying older entries on top of them.
497 */
498 while ((int) --prod_index - (int) cq->mcq.cons_index >= 0) {
499 cqe = get_cqe(cq, prod_index & cq->ibcq.cqe);
500 if ((be32_to_cpu(cqe->my_qpn) & 0xffffff) == qpn) {
501 if (srq && !(cqe->owner_sr_opcode & MLX4_CQE_IS_SEND_MASK))
502 mlx4_ib_free_srq_wqe(srq, be16_to_cpu(cqe->wqe_index));
503 ++nfreed;
504 } else if (nfreed)
505 memcpy(get_cqe(cq, (prod_index + nfreed) & cq->ibcq.cqe),
506 cqe, sizeof *cqe);
507 }
508
509 if (nfreed) {
510 cq->mcq.cons_index += nfreed;
511 /*
512 * Make sure update of buffer contents is done before
513 * updating consumer index.
514 */
515 wmb();
516 mlx4_cq_set_ci(&cq->mcq);
517 }
518}
519
520void mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq)
521{
522 spin_lock_irq(&cq->lock);
523 __mlx4_ib_cq_clean(cq, qpn, srq);
524 spin_unlock_irq(&cq->lock);
525}
diff --git a/drivers/infiniband/hw/mlx4/doorbell.c b/drivers/infiniband/hw/mlx4/doorbell.c
new file mode 100644
index 000000000000..1c36087aef14
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/doorbell.c
@@ -0,0 +1,216 @@
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/slab.h>
34
35#include "mlx4_ib.h"
36
37struct mlx4_ib_db_pgdir {
38 struct list_head list;
39 DECLARE_BITMAP(order0, MLX4_IB_DB_PER_PAGE);
40 DECLARE_BITMAP(order1, MLX4_IB_DB_PER_PAGE / 2);
41 unsigned long *bits[2];
42 __be32 *db_page;
43 dma_addr_t db_dma;
44};
45
46static struct mlx4_ib_db_pgdir *mlx4_ib_alloc_db_pgdir(struct mlx4_ib_dev *dev)
47{
48 struct mlx4_ib_db_pgdir *pgdir;
49
50 pgdir = kzalloc(sizeof *pgdir, GFP_KERNEL);
51 if (!pgdir)
52 return NULL;
53
54 bitmap_fill(pgdir->order1, MLX4_IB_DB_PER_PAGE / 2);
55 pgdir->bits[0] = pgdir->order0;
56 pgdir->bits[1] = pgdir->order1;
57 pgdir->db_page = dma_alloc_coherent(dev->ib_dev.dma_device,
58 PAGE_SIZE, &pgdir->db_dma,
59 GFP_KERNEL);
60 if (!pgdir->db_page) {
61 kfree(pgdir);
62 return NULL;
63 }
64
65 return pgdir;
66}
67
68static int mlx4_ib_alloc_db_from_pgdir(struct mlx4_ib_db_pgdir *pgdir,
69 struct mlx4_ib_db *db, int order)
70{
71 int o;
72 int i;
73
74 for (o = order; o <= 1; ++o) {
75 i = find_first_bit(pgdir->bits[o], MLX4_IB_DB_PER_PAGE >> o);
76 if (i < MLX4_IB_DB_PER_PAGE >> o)
77 goto found;
78 }
79
80 return -ENOMEM;
81
82found:
83 clear_bit(i, pgdir->bits[o]);
84
85 i <<= o;
86
87 if (o > order)
88 set_bit(i ^ 1, pgdir->bits[order]);
89
90 db->u.pgdir = pgdir;
91 db->index = i;
92 db->db = pgdir->db_page + db->index;
93 db->dma = pgdir->db_dma + db->index * 4;
94 db->order = order;
95
96 return 0;
97}
98
99int mlx4_ib_db_alloc(struct mlx4_ib_dev *dev, struct mlx4_ib_db *db, int order)
100{
101 struct mlx4_ib_db_pgdir *pgdir;
102 int ret = 0;
103
104 mutex_lock(&dev->pgdir_mutex);
105
106 list_for_each_entry(pgdir, &dev->pgdir_list, list)
107 if (!mlx4_ib_alloc_db_from_pgdir(pgdir, db, order))
108 goto out;
109
110 pgdir = mlx4_ib_alloc_db_pgdir(dev);
111 if (!pgdir) {
112 ret = -ENOMEM;
113 goto out;
114 }
115
116 list_add(&pgdir->list, &dev->pgdir_list);
117
118 /* This should never fail -- we just allocated an empty page: */
119 WARN_ON(mlx4_ib_alloc_db_from_pgdir(pgdir, db, order));
120
121out:
122 mutex_unlock(&dev->pgdir_mutex);
123
124 return ret;
125}
126
127void mlx4_ib_db_free(struct mlx4_ib_dev *dev, struct mlx4_ib_db *db)
128{
129 int o;
130 int i;
131
132 mutex_lock(&dev->pgdir_mutex);
133
134 o = db->order;
135 i = db->index;
136
137 if (db->order == 0 && test_bit(i ^ 1, db->u.pgdir->order0)) {
138 clear_bit(i ^ 1, db->u.pgdir->order0);
139 ++o;
140 }
141
142 i >>= o;
143 set_bit(i, db->u.pgdir->bits[o]);
144
145 if (bitmap_full(db->u.pgdir->order1, MLX4_IB_DB_PER_PAGE / 2)) {
146 dma_free_coherent(dev->ib_dev.dma_device, PAGE_SIZE,
147 db->u.pgdir->db_page, db->u.pgdir->db_dma);
148 list_del(&db->u.pgdir->list);
149 kfree(db->u.pgdir);
150 }
151
152 mutex_unlock(&dev->pgdir_mutex);
153}
154
155struct mlx4_ib_user_db_page {
156 struct list_head list;
157 struct ib_umem *umem;
158 unsigned long user_virt;
159 int refcnt;
160};
161
162int mlx4_ib_db_map_user(struct mlx4_ib_ucontext *context, unsigned long virt,
163 struct mlx4_ib_db *db)
164{
165 struct mlx4_ib_user_db_page *page;
166 struct ib_umem_chunk *chunk;
167 int err = 0;
168
169 mutex_lock(&context->db_page_mutex);
170
171 list_for_each_entry(page, &context->db_page_list, list)
172 if (page->user_virt == (virt & PAGE_MASK))
173 goto found;
174
175 page = kmalloc(sizeof *page, GFP_KERNEL);
176 if (!page) {
177 err = -ENOMEM;
178 goto out;
179 }
180
181 page->user_virt = (virt & PAGE_MASK);
182 page->refcnt = 0;
183 page->umem = ib_umem_get(&context->ibucontext, virt & PAGE_MASK,
184 PAGE_SIZE, 0);
185 if (IS_ERR(page->umem)) {
186 err = PTR_ERR(page->umem);
187 kfree(page);
188 goto out;
189 }
190
191 list_add(&page->list, &context->db_page_list);
192
193found:
194 chunk = list_entry(page->umem->chunk_list.next, struct ib_umem_chunk, list);
195 db->dma = sg_dma_address(chunk->page_list) + (virt & ~PAGE_MASK);
196 db->u.user_page = page;
197 ++page->refcnt;
198
199out:
200 mutex_unlock(&context->db_page_mutex);
201
202 return err;
203}
204
205void mlx4_ib_db_unmap_user(struct mlx4_ib_ucontext *context, struct mlx4_ib_db *db)
206{
207 mutex_lock(&context->db_page_mutex);
208
209 if (!--db->u.user_page->refcnt) {
210 list_del(&db->u.user_page->list);
211 ib_umem_release(db->u.user_page->umem);
212 kfree(db->u.user_page);
213 }
214
215 mutex_unlock(&context->db_page_mutex);
216}
diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
new file mode 100644
index 000000000000..333091787c5f
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/mad.c
@@ -0,0 +1,339 @@
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <rdma/ib_mad.h>
34#include <rdma/ib_smi.h>
35
36#include <linux/mlx4/cmd.h>
37
38#include "mlx4_ib.h"
39
40enum {
41 MLX4_IB_VENDOR_CLASS1 = 0x9,
42 MLX4_IB_VENDOR_CLASS2 = 0xa
43};
44
45int mlx4_MAD_IFC(struct mlx4_ib_dev *dev, int ignore_mkey, int ignore_bkey,
46 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
47 void *in_mad, void *response_mad)
48{
49 struct mlx4_cmd_mailbox *inmailbox, *outmailbox;
50 void *inbox;
51 int err;
52 u32 in_modifier = port;
53 u8 op_modifier = 0;
54
55 inmailbox = mlx4_alloc_cmd_mailbox(dev->dev);
56 if (IS_ERR(inmailbox))
57 return PTR_ERR(inmailbox);
58 inbox = inmailbox->buf;
59
60 outmailbox = mlx4_alloc_cmd_mailbox(dev->dev);
61 if (IS_ERR(outmailbox)) {
62 mlx4_free_cmd_mailbox(dev->dev, inmailbox);
63 return PTR_ERR(outmailbox);
64 }
65
66 memcpy(inbox, in_mad, 256);
67
68 /*
69 * Key check traps can't be generated unless we have in_wc to
70 * tell us where to send the trap.
71 */
72 if (ignore_mkey || !in_wc)
73 op_modifier |= 0x1;
74 if (ignore_bkey || !in_wc)
75 op_modifier |= 0x2;
76
77 if (in_wc) {
78 struct {
79 __be32 my_qpn;
80 u32 reserved1;
81 __be32 rqpn;
82 u8 sl;
83 u8 g_path;
84 u16 reserved2[2];
85 __be16 pkey;
86 u32 reserved3[11];
87 u8 grh[40];
88 } *ext_info;
89
90 memset(inbox + 256, 0, 256);
91 ext_info = inbox + 256;
92
93 ext_info->my_qpn = cpu_to_be32(in_wc->qp->qp_num);
94 ext_info->rqpn = cpu_to_be32(in_wc->src_qp);
95 ext_info->sl = in_wc->sl << 4;
96 ext_info->g_path = in_wc->dlid_path_bits |
97 (in_wc->wc_flags & IB_WC_GRH ? 0x80 : 0);
98 ext_info->pkey = cpu_to_be16(in_wc->pkey_index);
99
100 if (in_grh)
101 memcpy(ext_info->grh, in_grh, 40);
102
103 op_modifier |= 0x4;
104
105 in_modifier |= in_wc->slid << 16;
106 }
107
108 err = mlx4_cmd_box(dev->dev, inmailbox->dma, outmailbox->dma,
109 in_modifier, op_modifier,
110 MLX4_CMD_MAD_IFC, MLX4_CMD_TIME_CLASS_C);
111
112 if (!err);
113 memcpy(response_mad, outmailbox->buf, 256);
114
115 mlx4_free_cmd_mailbox(dev->dev, inmailbox);
116 mlx4_free_cmd_mailbox(dev->dev, outmailbox);
117
118 return err;
119}
120
121static void update_sm_ah(struct mlx4_ib_dev *dev, u8 port_num, u16 lid, u8 sl)
122{
123 struct ib_ah *new_ah;
124 struct ib_ah_attr ah_attr;
125
126 if (!dev->send_agent[port_num - 1][0])
127 return;
128
129 memset(&ah_attr, 0, sizeof ah_attr);
130 ah_attr.dlid = lid;
131 ah_attr.sl = sl;
132 ah_attr.port_num = port_num;
133
134 new_ah = ib_create_ah(dev->send_agent[port_num - 1][0]->qp->pd,
135 &ah_attr);
136 if (IS_ERR(new_ah))
137 return;
138
139 spin_lock(&dev->sm_lock);
140 if (dev->sm_ah[port_num - 1])
141 ib_destroy_ah(dev->sm_ah[port_num - 1]);
142 dev->sm_ah[port_num - 1] = new_ah;
143 spin_unlock(&dev->sm_lock);
144}
145
146/*
147 * Snoop SM MADs for port info and P_Key table sets, so we can
148 * synthesize LID change and P_Key change events.
149 */
150static void smp_snoop(struct ib_device *ibdev, u8 port_num, struct ib_mad *mad)
151{
152 struct ib_event event;
153
154 if ((mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
155 mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) &&
156 mad->mad_hdr.method == IB_MGMT_METHOD_SET) {
157 if (mad->mad_hdr.attr_id == IB_SMP_ATTR_PORT_INFO) {
158 struct ib_port_info *pinfo =
159 (struct ib_port_info *) ((struct ib_smp *) mad)->data;
160
161 update_sm_ah(to_mdev(ibdev), port_num,
162 be16_to_cpu(pinfo->sm_lid),
163 pinfo->neighbormtu_mastersmsl & 0xf);
164
165 event.device = ibdev;
166 event.element.port_num = port_num;
167
168 if(pinfo->clientrereg_resv_subnetto & 0x80)
169 event.event = IB_EVENT_CLIENT_REREGISTER;
170 else
171 event.event = IB_EVENT_LID_CHANGE;
172
173 ib_dispatch_event(&event);
174 }
175
176 if (mad->mad_hdr.attr_id == IB_SMP_ATTR_PKEY_TABLE) {
177 event.device = ibdev;
178 event.event = IB_EVENT_PKEY_CHANGE;
179 event.element.port_num = port_num;
180 ib_dispatch_event(&event);
181 }
182 }
183}
184
185static void node_desc_override(struct ib_device *dev,
186 struct ib_mad *mad)
187{
188 if ((mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
189 mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) &&
190 mad->mad_hdr.method == IB_MGMT_METHOD_GET_RESP &&
191 mad->mad_hdr.attr_id == IB_SMP_ATTR_NODE_DESC) {
192 spin_lock(&to_mdev(dev)->sm_lock);
193 memcpy(((struct ib_smp *) mad)->data, dev->node_desc, 64);
194 spin_unlock(&to_mdev(dev)->sm_lock);
195 }
196}
197
198static void forward_trap(struct mlx4_ib_dev *dev, u8 port_num, struct ib_mad *mad)
199{
200 int qpn = mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED;
201 struct ib_mad_send_buf *send_buf;
202 struct ib_mad_agent *agent = dev->send_agent[port_num - 1][qpn];
203 int ret;
204
205 if (agent) {
206 send_buf = ib_create_send_mad(agent, qpn, 0, 0, IB_MGMT_MAD_HDR,
207 IB_MGMT_MAD_DATA, GFP_ATOMIC);
208 /*
209 * We rely here on the fact that MLX QPs don't use the
210 * address handle after the send is posted (this is
211 * wrong following the IB spec strictly, but we know
212 * it's OK for our devices).
213 */
214 spin_lock(&dev->sm_lock);
215 memcpy(send_buf->mad, mad, sizeof *mad);
216 if ((send_buf->ah = dev->sm_ah[port_num - 1]))
217 ret = ib_post_send_mad(send_buf, NULL);
218 else
219 ret = -EINVAL;
220 spin_unlock(&dev->sm_lock);
221
222 if (ret)
223 ib_free_send_mad(send_buf);
224 }
225}
226
227int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
228 struct ib_wc *in_wc, struct ib_grh *in_grh,
229 struct ib_mad *in_mad, struct ib_mad *out_mad)
230{
231 u16 slid;
232 int err;
233
234 slid = in_wc ? in_wc->slid : be16_to_cpu(IB_LID_PERMISSIVE);
235
236 if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP && slid == 0) {
237 forward_trap(to_mdev(ibdev), port_num, in_mad);
238 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
239 }
240
241 if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_LID_ROUTED ||
242 in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) {
243 if (in_mad->mad_hdr.method != IB_MGMT_METHOD_GET &&
244 in_mad->mad_hdr.method != IB_MGMT_METHOD_SET &&
245 in_mad->mad_hdr.method != IB_MGMT_METHOD_TRAP_REPRESS)
246 return IB_MAD_RESULT_SUCCESS;
247
248 /*
249 * Don't process SMInfo queries or vendor-specific
250 * MADs -- the SMA can't handle them.
251 */
252 if (in_mad->mad_hdr.attr_id == IB_SMP_ATTR_SM_INFO ||
253 ((in_mad->mad_hdr.attr_id & IB_SMP_ATTR_VENDOR_MASK) ==
254 IB_SMP_ATTR_VENDOR_MASK))
255 return IB_MAD_RESULT_SUCCESS;
256 } else if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_PERF_MGMT ||
257 in_mad->mad_hdr.mgmt_class == MLX4_IB_VENDOR_CLASS1 ||
258 in_mad->mad_hdr.mgmt_class == MLX4_IB_VENDOR_CLASS2) {
259 if (in_mad->mad_hdr.method != IB_MGMT_METHOD_GET &&
260 in_mad->mad_hdr.method != IB_MGMT_METHOD_SET)
261 return IB_MAD_RESULT_SUCCESS;
262 } else
263 return IB_MAD_RESULT_SUCCESS;
264
265 err = mlx4_MAD_IFC(to_mdev(ibdev),
266 mad_flags & IB_MAD_IGNORE_MKEY,
267 mad_flags & IB_MAD_IGNORE_BKEY,
268 port_num, in_wc, in_grh, in_mad, out_mad);
269 if (err)
270 return IB_MAD_RESULT_FAILURE;
271
272 if (!out_mad->mad_hdr.status) {
273 smp_snoop(ibdev, port_num, in_mad);
274 node_desc_override(ibdev, out_mad);
275 }
276
277 /* set return bit in status of directed route responses */
278 if (in_mad->mad_hdr.mgmt_class == IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
279 out_mad->mad_hdr.status |= cpu_to_be16(1 << 15);
280
281 if (in_mad->mad_hdr.method == IB_MGMT_METHOD_TRAP_REPRESS)
282 /* no response for trap repress */
283 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_CONSUMED;
284
285 return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;
286}
287
288static void send_handler(struct ib_mad_agent *agent,
289 struct ib_mad_send_wc *mad_send_wc)
290{
291 ib_free_send_mad(mad_send_wc->send_buf);
292}
293
294int mlx4_ib_mad_init(struct mlx4_ib_dev *dev)
295{
296 struct ib_mad_agent *agent;
297 int p, q;
298 int ret;
299
300 for (p = 0; p < dev->dev->caps.num_ports; ++p)
301 for (q = 0; q <= 1; ++q) {
302 agent = ib_register_mad_agent(&dev->ib_dev, p + 1,
303 q ? IB_QPT_GSI : IB_QPT_SMI,
304 NULL, 0, send_handler,
305 NULL, NULL);
306 if (IS_ERR(agent)) {
307 ret = PTR_ERR(agent);
308 goto err;
309 }
310 dev->send_agent[p][q] = agent;
311 }
312
313 return 0;
314
315err:
316 for (p = 0; p < dev->dev->caps.num_ports; ++p)
317 for (q = 0; q <= 1; ++q)
318 if (dev->send_agent[p][q])
319 ib_unregister_mad_agent(dev->send_agent[p][q]);
320
321 return ret;
322}
323
324void mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev)
325{
326 struct ib_mad_agent *agent;
327 int p, q;
328
329 for (p = 0; p < dev->dev->caps.num_ports; ++p) {
330 for (q = 0; q <= 1; ++q) {
331 agent = dev->send_agent[p][q];
332 dev->send_agent[p][q] = NULL;
333 ib_unregister_mad_agent(agent);
334 }
335
336 if (dev->sm_ah[p])
337 ib_destroy_ah(dev->sm_ah[p]);
338 }
339}
diff --git a/drivers/infiniband/hw/mlx4/main.c b/drivers/infiniband/hw/mlx4/main.c
new file mode 100644
index 000000000000..402f3a20ec0a
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/main.c
@@ -0,0 +1,652 @@
1/*
2 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/module.h>
34#include <linux/init.h>
35#include <linux/errno.h>
36
37#include <rdma/ib_smi.h>
38#include <rdma/ib_user_verbs.h>
39
40#include <linux/mlx4/driver.h>
41#include <linux/mlx4/cmd.h>
42
43#include "mlx4_ib.h"
44#include "user.h"
45
46#define DRV_NAME "mlx4_ib"
47#define DRV_VERSION "0.01"
48#define DRV_RELDATE "May 1, 2006"
49
50MODULE_AUTHOR("Roland Dreier");
51MODULE_DESCRIPTION("Mellanox ConnectX HCA InfiniBand driver");
52MODULE_LICENSE("Dual BSD/GPL");
53MODULE_VERSION(DRV_VERSION);
54
55static const char mlx4_ib_version[] __devinitdata =
56 DRV_NAME ": Mellanox ConnectX InfiniBand driver v"
57 DRV_VERSION " (" DRV_RELDATE ")\n";
58
59static void init_query_mad(struct ib_smp *mad)
60{
61 mad->base_version = 1;
62 mad->mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
63 mad->class_version = 1;
64 mad->method = IB_MGMT_METHOD_GET;
65}
66
67static int mlx4_ib_query_device(struct ib_device *ibdev,
68 struct ib_device_attr *props)
69{
70 struct mlx4_ib_dev *dev = to_mdev(ibdev);
71 struct ib_smp *in_mad = NULL;
72 struct ib_smp *out_mad = NULL;
73 int err = -ENOMEM;
74
75 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
76 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
77 if (!in_mad || !out_mad)
78 goto out;
79
80 init_query_mad(in_mad);
81 in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
82
83 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, 1, NULL, NULL, in_mad, out_mad);
84 if (err)
85 goto out;
86
87 memset(props, 0, sizeof *props);
88
89 props->fw_ver = dev->dev->caps.fw_ver;
90 props->device_cap_flags = IB_DEVICE_CHANGE_PHY_PORT |
91 IB_DEVICE_PORT_ACTIVE_EVENT |
92 IB_DEVICE_SYS_IMAGE_GUID |
93 IB_DEVICE_RC_RNR_NAK_GEN;
94 if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_BAD_PKEY_CNTR)
95 props->device_cap_flags |= IB_DEVICE_BAD_PKEY_CNTR;
96 if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_BAD_QKEY_CNTR)
97 props->device_cap_flags |= IB_DEVICE_BAD_QKEY_CNTR;
98 if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_APM)
99 props->device_cap_flags |= IB_DEVICE_AUTO_PATH_MIG;
100 if (dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_UD_AV_PORT)
101 props->device_cap_flags |= IB_DEVICE_UD_AV_PORT_ENFORCE;
102
103 props->vendor_id = be32_to_cpup((__be32 *) (out_mad->data + 36)) &
104 0xffffff;
105 props->vendor_part_id = be16_to_cpup((__be16 *) (out_mad->data + 30));
106 props->hw_ver = be32_to_cpup((__be32 *) (out_mad->data + 32));
107 memcpy(&props->sys_image_guid, out_mad->data + 4, 8);
108
109 props->max_mr_size = ~0ull;
110 props->page_size_cap = dev->dev->caps.page_size_cap;
111 props->max_qp = dev->dev->caps.num_qps - dev->dev->caps.reserved_qps;
112 props->max_qp_wr = dev->dev->caps.max_wqes;
113 props->max_sge = min(dev->dev->caps.max_sq_sg,
114 dev->dev->caps.max_rq_sg);
115 props->max_cq = dev->dev->caps.num_cqs - dev->dev->caps.reserved_cqs;
116 props->max_cqe = dev->dev->caps.max_cqes;
117 props->max_mr = dev->dev->caps.num_mpts - dev->dev->caps.reserved_mrws;
118 props->max_pd = dev->dev->caps.num_pds - dev->dev->caps.reserved_pds;
119 props->max_qp_rd_atom = dev->dev->caps.max_qp_dest_rdma;
120 props->max_qp_init_rd_atom = dev->dev->caps.max_qp_init_rdma;
121 props->max_res_rd_atom = props->max_qp_rd_atom * props->max_qp;
122 props->max_srq = dev->dev->caps.num_srqs - dev->dev->caps.reserved_srqs;
123 props->max_srq_wr = dev->dev->caps.max_srq_wqes;
124 props->max_srq_sge = dev->dev->caps.max_srq_sge;
125 props->local_ca_ack_delay = dev->dev->caps.local_ca_ack_delay;
126 props->atomic_cap = dev->dev->caps.flags & MLX4_DEV_CAP_FLAG_ATOMIC ?
127 IB_ATOMIC_HCA : IB_ATOMIC_NONE;
128 props->max_pkeys = dev->dev->caps.pkey_table_len;
129 props->max_mcast_grp = dev->dev->caps.num_mgms + dev->dev->caps.num_amgms;
130 props->max_mcast_qp_attach = dev->dev->caps.num_qp_per_mgm;
131 props->max_total_mcast_qp_attach = props->max_mcast_qp_attach *
132 props->max_mcast_grp;
133 props->max_map_per_fmr = (1 << (32 - ilog2(dev->dev->caps.num_mpts))) - 1;
134
135out:
136 kfree(in_mad);
137 kfree(out_mad);
138
139 return err;
140}
141
142static int mlx4_ib_query_port(struct ib_device *ibdev, u8 port,
143 struct ib_port_attr *props)
144{
145 struct ib_smp *in_mad = NULL;
146 struct ib_smp *out_mad = NULL;
147 int err = -ENOMEM;
148
149 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
150 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
151 if (!in_mad || !out_mad)
152 goto out;
153
154 memset(props, 0, sizeof *props);
155
156 init_query_mad(in_mad);
157 in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
158 in_mad->attr_mod = cpu_to_be32(port);
159
160 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
161 if (err)
162 goto out;
163
164 props->lid = be16_to_cpup((__be16 *) (out_mad->data + 16));
165 props->lmc = out_mad->data[34] & 0x7;
166 props->sm_lid = be16_to_cpup((__be16 *) (out_mad->data + 18));
167 props->sm_sl = out_mad->data[36] & 0xf;
168 props->state = out_mad->data[32] & 0xf;
169 props->phys_state = out_mad->data[33] >> 4;
170 props->port_cap_flags = be32_to_cpup((__be32 *) (out_mad->data + 20));
171 props->gid_tbl_len = to_mdev(ibdev)->dev->caps.gid_table_len;
172 props->max_msg_sz = 0x80000000;
173 props->pkey_tbl_len = to_mdev(ibdev)->dev->caps.pkey_table_len;
174 props->bad_pkey_cntr = be16_to_cpup((__be16 *) (out_mad->data + 46));
175 props->qkey_viol_cntr = be16_to_cpup((__be16 *) (out_mad->data + 48));
176 props->active_width = out_mad->data[31] & 0xf;
177 props->active_speed = out_mad->data[35] >> 4;
178 props->max_mtu = out_mad->data[41] & 0xf;
179 props->active_mtu = out_mad->data[36] >> 4;
180 props->subnet_timeout = out_mad->data[51] & 0x1f;
181 props->max_vl_num = out_mad->data[37] >> 4;
182 props->init_type_reply = out_mad->data[41] >> 4;
183
184out:
185 kfree(in_mad);
186 kfree(out_mad);
187
188 return err;
189}
190
191static int mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
192 union ib_gid *gid)
193{
194 struct ib_smp *in_mad = NULL;
195 struct ib_smp *out_mad = NULL;
196 int err = -ENOMEM;
197
198 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
199 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
200 if (!in_mad || !out_mad)
201 goto out;
202
203 init_query_mad(in_mad);
204 in_mad->attr_id = IB_SMP_ATTR_PORT_INFO;
205 in_mad->attr_mod = cpu_to_be32(port);
206
207 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
208 if (err)
209 goto out;
210
211 memcpy(gid->raw, out_mad->data + 8, 8);
212
213 init_query_mad(in_mad);
214 in_mad->attr_id = IB_SMP_ATTR_GUID_INFO;
215 in_mad->attr_mod = cpu_to_be32(index / 8);
216
217 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
218 if (err)
219 goto out;
220
221 memcpy(gid->raw + 8, out_mad->data + (index % 8) * 8, 8);
222
223out:
224 kfree(in_mad);
225 kfree(out_mad);
226 return err;
227}
228
229static int mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
230 u16 *pkey)
231{
232 struct ib_smp *in_mad = NULL;
233 struct ib_smp *out_mad = NULL;
234 int err = -ENOMEM;
235
236 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
237 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
238 if (!in_mad || !out_mad)
239 goto out;
240
241 init_query_mad(in_mad);
242 in_mad->attr_id = IB_SMP_ATTR_PKEY_TABLE;
243 in_mad->attr_mod = cpu_to_be32(index / 32);
244
245 err = mlx4_MAD_IFC(to_mdev(ibdev), 1, 1, port, NULL, NULL, in_mad, out_mad);
246 if (err)
247 goto out;
248
249 *pkey = be16_to_cpu(((__be16 *) out_mad->data)[index % 32]);
250
251out:
252 kfree(in_mad);
253 kfree(out_mad);
254 return err;
255}
256
257static int mlx4_ib_modify_device(struct ib_device *ibdev, int mask,
258 struct ib_device_modify *props)
259{
260 if (mask & ~IB_DEVICE_MODIFY_NODE_DESC)
261 return -EOPNOTSUPP;
262
263 if (mask & IB_DEVICE_MODIFY_NODE_DESC) {
264 spin_lock(&to_mdev(ibdev)->sm_lock);
265 memcpy(ibdev->node_desc, props->node_desc, 64);
266 spin_unlock(&to_mdev(ibdev)->sm_lock);
267 }
268
269 return 0;
270}
271
272static int mlx4_SET_PORT(struct mlx4_ib_dev *dev, u8 port, int reset_qkey_viols,
273 u32 cap_mask)
274{
275 struct mlx4_cmd_mailbox *mailbox;
276 int err;
277
278 mailbox = mlx4_alloc_cmd_mailbox(dev->dev);
279 if (IS_ERR(mailbox))
280 return PTR_ERR(mailbox);
281
282 memset(mailbox->buf, 0, 256);
283 *(u8 *) mailbox->buf = !!reset_qkey_viols << 6;
284 ((__be32 *) mailbox->buf)[2] = cpu_to_be32(cap_mask);
285
286 err = mlx4_cmd(dev->dev, mailbox->dma, port, 0, MLX4_CMD_SET_PORT,
287 MLX4_CMD_TIME_CLASS_B);
288
289 mlx4_free_cmd_mailbox(dev->dev, mailbox);
290 return err;
291}
292
293static int mlx4_ib_modify_port(struct ib_device *ibdev, u8 port, int mask,
294 struct ib_port_modify *props)
295{
296 struct ib_port_attr attr;
297 u32 cap_mask;
298 int err;
299
300 mutex_lock(&to_mdev(ibdev)->cap_mask_mutex);
301
302 err = mlx4_ib_query_port(ibdev, port, &attr);
303 if (err)
304 goto out;
305
306 cap_mask = (attr.port_cap_flags | props->set_port_cap_mask) &
307 ~props->clr_port_cap_mask;
308
309 err = mlx4_SET_PORT(to_mdev(ibdev), port,
310 !!(mask & IB_PORT_RESET_QKEY_CNTR),
311 cap_mask);
312
313out:
314 mutex_unlock(&to_mdev(ibdev)->cap_mask_mutex);
315 return err;
316}
317
318static struct ib_ucontext *mlx4_ib_alloc_ucontext(struct ib_device *ibdev,
319 struct ib_udata *udata)
320{
321 struct mlx4_ib_dev *dev = to_mdev(ibdev);
322 struct mlx4_ib_ucontext *context;
323 struct mlx4_ib_alloc_ucontext_resp resp;
324 int err;
325
326 resp.qp_tab_size = dev->dev->caps.num_qps;
327 resp.bf_reg_size = dev->dev->caps.bf_reg_size;
328 resp.bf_regs_per_page = dev->dev->caps.bf_regs_per_page;
329
330 context = kmalloc(sizeof *context, GFP_KERNEL);
331 if (!context)
332 return ERR_PTR(-ENOMEM);
333
334 err = mlx4_uar_alloc(to_mdev(ibdev)->dev, &context->uar);
335 if (err) {
336 kfree(context);
337 return ERR_PTR(err);
338 }
339
340 INIT_LIST_HEAD(&context->db_page_list);
341 mutex_init(&context->db_page_mutex);
342
343 err = ib_copy_to_udata(udata, &resp, sizeof resp);
344 if (err) {
345 mlx4_uar_free(to_mdev(ibdev)->dev, &context->uar);
346 kfree(context);
347 return ERR_PTR(-EFAULT);
348 }
349
350 return &context->ibucontext;
351}
352
353static int mlx4_ib_dealloc_ucontext(struct ib_ucontext *ibcontext)
354{
355 struct mlx4_ib_ucontext *context = to_mucontext(ibcontext);
356
357 mlx4_uar_free(to_mdev(ibcontext->device)->dev, &context->uar);
358 kfree(context);
359
360 return 0;
361}
362
363static int mlx4_ib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma)
364{
365 struct mlx4_ib_dev *dev = to_mdev(context->device);
366
367 if (vma->vm_end - vma->vm_start != PAGE_SIZE)
368 return -EINVAL;
369
370 if (vma->vm_pgoff == 0) {
371 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
372
373 if (io_remap_pfn_range(vma, vma->vm_start,
374 to_mucontext(context)->uar.pfn,
375 PAGE_SIZE, vma->vm_page_prot))
376 return -EAGAIN;
377 } else if (vma->vm_pgoff == 1 && dev->dev->caps.bf_reg_size != 0) {
378 /* FIXME want pgprot_writecombine() for BlueFlame pages */
379 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
380
381 if (io_remap_pfn_range(vma, vma->vm_start,
382 to_mucontext(context)->uar.pfn +
383 dev->dev->caps.num_uars,
384 PAGE_SIZE, vma->vm_page_prot))
385 return -EAGAIN;
386 } else
387 return -EINVAL;
388
389 return 0;
390}
391
392static struct ib_pd *mlx4_ib_alloc_pd(struct ib_device *ibdev,
393 struct ib_ucontext *context,
394 struct ib_udata *udata)
395{
396 struct mlx4_ib_pd *pd;
397 int err;
398
399 pd = kmalloc(sizeof *pd, GFP_KERNEL);
400 if (!pd)
401 return ERR_PTR(-ENOMEM);
402
403 err = mlx4_pd_alloc(to_mdev(ibdev)->dev, &pd->pdn);
404 if (err) {
405 kfree(pd);
406 return ERR_PTR(err);
407 }
408
409 if (context)
410 if (ib_copy_to_udata(udata, &pd->pdn, sizeof (__u32))) {
411 mlx4_pd_free(to_mdev(ibdev)->dev, pd->pdn);
412 kfree(pd);
413 return ERR_PTR(-EFAULT);
414 }
415
416 return &pd->ibpd;
417}
418
419static int mlx4_ib_dealloc_pd(struct ib_pd *pd)
420{
421 mlx4_pd_free(to_mdev(pd->device)->dev, to_mpd(pd)->pdn);
422 kfree(pd);
423
424 return 0;
425}
426
427static int mlx4_ib_mcg_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
428{
429 return mlx4_multicast_attach(to_mdev(ibqp->device)->dev,
430 &to_mqp(ibqp)->mqp, gid->raw);
431}
432
433static int mlx4_ib_mcg_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid)
434{
435 return mlx4_multicast_detach(to_mdev(ibqp->device)->dev,
436 &to_mqp(ibqp)->mqp, gid->raw);
437}
438
439static int init_node_data(struct mlx4_ib_dev *dev)
440{
441 struct ib_smp *in_mad = NULL;
442 struct ib_smp *out_mad = NULL;
443 int err = -ENOMEM;
444
445 in_mad = kzalloc(sizeof *in_mad, GFP_KERNEL);
446 out_mad = kmalloc(sizeof *out_mad, GFP_KERNEL);
447 if (!in_mad || !out_mad)
448 goto out;
449
450 init_query_mad(in_mad);
451 in_mad->attr_id = IB_SMP_ATTR_NODE_DESC;
452
453 err = mlx4_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad);
454 if (err)
455 goto out;
456
457 memcpy(dev->ib_dev.node_desc, out_mad->data, 64);
458
459 in_mad->attr_id = IB_SMP_ATTR_NODE_INFO;
460
461 err = mlx4_MAD_IFC(dev, 1, 1, 1, NULL, NULL, in_mad, out_mad);
462 if (err)
463 goto out;
464
465 memcpy(&dev->ib_dev.node_guid, out_mad->data + 12, 8);
466
467out:
468 kfree(in_mad);
469 kfree(out_mad);
470 return err;
471}
472
473static void *mlx4_ib_add(struct mlx4_dev *dev)
474{
475 struct mlx4_ib_dev *ibdev;
476
477 ibdev = (struct mlx4_ib_dev *) ib_alloc_device(sizeof *ibdev);
478 if (!ibdev) {
479 dev_err(&dev->pdev->dev, "Device struct alloc failed\n");
480 return NULL;
481 }
482
483 if (mlx4_pd_alloc(dev, &ibdev->priv_pdn))
484 goto err_dealloc;
485
486 if (mlx4_uar_alloc(dev, &ibdev->priv_uar))
487 goto err_pd;
488
489 ibdev->uar_map = ioremap(ibdev->priv_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
490 if (!ibdev->uar_map)
491 goto err_uar;
492 MLX4_INIT_DOORBELL_LOCK(&ibdev->uar_lock);
493
494 INIT_LIST_HEAD(&ibdev->pgdir_list);
495 mutex_init(&ibdev->pgdir_mutex);
496
497 ibdev->dev = dev;
498
499 strlcpy(ibdev->ib_dev.name, "mlx4_%d", IB_DEVICE_NAME_MAX);
500 ibdev->ib_dev.owner = THIS_MODULE;
501 ibdev->ib_dev.node_type = RDMA_NODE_IB_CA;
502 ibdev->ib_dev.phys_port_cnt = dev->caps.num_ports;
503 ibdev->ib_dev.num_comp_vectors = 1;
504 ibdev->ib_dev.dma_device = &dev->pdev->dev;
505
506 ibdev->ib_dev.uverbs_abi_ver = MLX4_IB_UVERBS_ABI_VERSION;
507 ibdev->ib_dev.uverbs_cmd_mask =
508 (1ull << IB_USER_VERBS_CMD_GET_CONTEXT) |
509 (1ull << IB_USER_VERBS_CMD_QUERY_DEVICE) |
510 (1ull << IB_USER_VERBS_CMD_QUERY_PORT) |
511 (1ull << IB_USER_VERBS_CMD_ALLOC_PD) |
512 (1ull << IB_USER_VERBS_CMD_DEALLOC_PD) |
513 (1ull << IB_USER_VERBS_CMD_REG_MR) |
514 (1ull << IB_USER_VERBS_CMD_DEREG_MR) |
515 (1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL) |
516 (1ull << IB_USER_VERBS_CMD_CREATE_CQ) |
517 (1ull << IB_USER_VERBS_CMD_DESTROY_CQ) |
518 (1ull << IB_USER_VERBS_CMD_CREATE_QP) |
519 (1ull << IB_USER_VERBS_CMD_MODIFY_QP) |
520 (1ull << IB_USER_VERBS_CMD_DESTROY_QP) |
521 (1ull << IB_USER_VERBS_CMD_ATTACH_MCAST) |
522 (1ull << IB_USER_VERBS_CMD_DETACH_MCAST) |
523 (1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |
524 (1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |
525 (1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);
526
527 ibdev->ib_dev.query_device = mlx4_ib_query_device;
528 ibdev->ib_dev.query_port = mlx4_ib_query_port;
529 ibdev->ib_dev.query_gid = mlx4_ib_query_gid;
530 ibdev->ib_dev.query_pkey = mlx4_ib_query_pkey;
531 ibdev->ib_dev.modify_device = mlx4_ib_modify_device;
532 ibdev->ib_dev.modify_port = mlx4_ib_modify_port;
533 ibdev->ib_dev.alloc_ucontext = mlx4_ib_alloc_ucontext;
534 ibdev->ib_dev.dealloc_ucontext = mlx4_ib_dealloc_ucontext;
535 ibdev->ib_dev.mmap = mlx4_ib_mmap;
536 ibdev->ib_dev.alloc_pd = mlx4_ib_alloc_pd;
537 ibdev->ib_dev.dealloc_pd = mlx4_ib_dealloc_pd;
538 ibdev->ib_dev.create_ah = mlx4_ib_create_ah;
539 ibdev->ib_dev.query_ah = mlx4_ib_query_ah;
540 ibdev->ib_dev.destroy_ah = mlx4_ib_destroy_ah;
541 ibdev->ib_dev.create_srq = mlx4_ib_create_srq;
542 ibdev->ib_dev.modify_srq = mlx4_ib_modify_srq;
543 ibdev->ib_dev.destroy_srq = mlx4_ib_destroy_srq;
544 ibdev->ib_dev.post_srq_recv = mlx4_ib_post_srq_recv;
545 ibdev->ib_dev.create_qp = mlx4_ib_create_qp;
546 ibdev->ib_dev.modify_qp = mlx4_ib_modify_qp;
547 ibdev->ib_dev.destroy_qp = mlx4_ib_destroy_qp;
548 ibdev->ib_dev.post_send = mlx4_ib_post_send;
549 ibdev->ib_dev.post_recv = mlx4_ib_post_recv;
550 ibdev->ib_dev.create_cq = mlx4_ib_create_cq;
551 ibdev->ib_dev.destroy_cq = mlx4_ib_destroy_cq;
552 ibdev->ib_dev.poll_cq = mlx4_ib_poll_cq;
553 ibdev->ib_dev.req_notify_cq = mlx4_ib_arm_cq;
554 ibdev->ib_dev.get_dma_mr = mlx4_ib_get_dma_mr;
555 ibdev->ib_dev.reg_user_mr = mlx4_ib_reg_user_mr;
556 ibdev->ib_dev.dereg_mr = mlx4_ib_dereg_mr;
557 ibdev->ib_dev.attach_mcast = mlx4_ib_mcg_attach;
558 ibdev->ib_dev.detach_mcast = mlx4_ib_mcg_detach;
559 ibdev->ib_dev.process_mad = mlx4_ib_process_mad;
560
561 if (init_node_data(ibdev))
562 goto err_map;
563
564 spin_lock_init(&ibdev->sm_lock);
565 mutex_init(&ibdev->cap_mask_mutex);
566
567 if (ib_register_device(&ibdev->ib_dev))
568 goto err_map;
569
570 if (mlx4_ib_mad_init(ibdev))
571 goto err_reg;
572
573 return ibdev;
574
575err_reg:
576 ib_unregister_device(&ibdev->ib_dev);
577
578err_map:
579 iounmap(ibdev->uar_map);
580
581err_uar:
582 mlx4_uar_free(dev, &ibdev->priv_uar);
583
584err_pd:
585 mlx4_pd_free(dev, ibdev->priv_pdn);
586
587err_dealloc:
588 ib_dealloc_device(&ibdev->ib_dev);
589
590 return NULL;
591}
592
593static void mlx4_ib_remove(struct mlx4_dev *dev, void *ibdev_ptr)
594{
595 struct mlx4_ib_dev *ibdev = ibdev_ptr;
596 int p;
597
598 for (p = 1; p <= dev->caps.num_ports; ++p)
599 mlx4_CLOSE_PORT(dev, p);
600
601 mlx4_ib_mad_cleanup(ibdev);
602 ib_unregister_device(&ibdev->ib_dev);
603 iounmap(ibdev->uar_map);
604 mlx4_uar_free(dev, &ibdev->priv_uar);
605 mlx4_pd_free(dev, ibdev->priv_pdn);
606 ib_dealloc_device(&ibdev->ib_dev);
607}
608
609static void mlx4_ib_event(struct mlx4_dev *dev, void *ibdev_ptr,
610 enum mlx4_dev_event event, int subtype,
611 int port)
612{
613 struct ib_event ibev;
614
615 switch (event) {
616 case MLX4_EVENT_TYPE_PORT_CHANGE:
617 ibev.event = subtype == MLX4_PORT_CHANGE_SUBTYPE_ACTIVE ?
618 IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR;
619 break;
620
621 case MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR:
622 ibev.event = IB_EVENT_DEVICE_FATAL;
623 break;
624
625 default:
626 return;
627 }
628
629 ibev.device = ibdev_ptr;
630 ibev.element.port_num = port;
631
632 ib_dispatch_event(&ibev);
633}
634
635static struct mlx4_interface mlx4_ib_interface = {
636 .add = mlx4_ib_add,
637 .remove = mlx4_ib_remove,
638 .event = mlx4_ib_event
639};
640
641static int __init mlx4_ib_init(void)
642{
643 return mlx4_register_interface(&mlx4_ib_interface);
644}
645
646static void __exit mlx4_ib_cleanup(void)
647{
648 mlx4_unregister_interface(&mlx4_ib_interface);
649}
650
651module_init(mlx4_ib_init);
652module_exit(mlx4_ib_cleanup);
diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
new file mode 100644
index 000000000000..93dac71f3230
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
@@ -0,0 +1,285 @@
1/*
2 * Copyright (c) 2006, 2007 Cisco Systems. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef MLX4_IB_H
34#define MLX4_IB_H
35
36#include <linux/compiler.h>
37#include <linux/list.h>
38
39#include <rdma/ib_verbs.h>
40#include <rdma/ib_umem.h>
41
42#include <linux/mlx4/device.h>
43#include <linux/mlx4/doorbell.h>
44
45enum {
46 MLX4_IB_DB_PER_PAGE = PAGE_SIZE / 4
47};
48
49struct mlx4_ib_db_pgdir;
50struct mlx4_ib_user_db_page;
51
52struct mlx4_ib_db {
53 __be32 *db;
54 union {
55 struct mlx4_ib_db_pgdir *pgdir;
56 struct mlx4_ib_user_db_page *user_page;
57 } u;
58 dma_addr_t dma;
59 int index;
60 int order;
61};
62
63struct mlx4_ib_ucontext {
64 struct ib_ucontext ibucontext;
65 struct mlx4_uar uar;
66 struct list_head db_page_list;
67 struct mutex db_page_mutex;
68};
69
70struct mlx4_ib_pd {
71 struct ib_pd ibpd;
72 u32 pdn;
73};
74
75struct mlx4_ib_cq_buf {
76 struct mlx4_buf buf;
77 struct mlx4_mtt mtt;
78};
79
80struct mlx4_ib_cq {
81 struct ib_cq ibcq;
82 struct mlx4_cq mcq;
83 struct mlx4_ib_cq_buf buf;
84 struct mlx4_ib_db db;
85 spinlock_t lock;
86 struct ib_umem *umem;
87};
88
89struct mlx4_ib_mr {
90 struct ib_mr ibmr;
91 struct mlx4_mr mmr;
92 struct ib_umem *umem;
93};
94
95struct mlx4_ib_wq {
96 u64 *wrid;
97 spinlock_t lock;
98 int max;
99 int max_gs;
100 int offset;
101 int wqe_shift;
102 unsigned head;
103 unsigned tail;
104};
105
106struct mlx4_ib_qp {
107 struct ib_qp ibqp;
108 struct mlx4_qp mqp;
109 struct mlx4_buf buf;
110
111 struct mlx4_ib_db db;
112 struct mlx4_ib_wq rq;
113
114 u32 doorbell_qpn;
115 __be32 sq_signal_bits;
116 struct mlx4_ib_wq sq;
117
118 struct ib_umem *umem;
119 struct mlx4_mtt mtt;
120 int buf_size;
121 struct mutex mutex;
122 u8 port;
123 u8 alt_port;
124 u8 atomic_rd_en;
125 u8 resp_depth;
126 u8 state;
127};
128
129struct mlx4_ib_srq {
130 struct ib_srq ibsrq;
131 struct mlx4_srq msrq;
132 struct mlx4_buf buf;
133 struct mlx4_ib_db db;
134 u64 *wrid;
135 spinlock_t lock;
136 int head;
137 int tail;
138 u16 wqe_ctr;
139 struct ib_umem *umem;
140 struct mlx4_mtt mtt;
141 struct mutex mutex;
142};
143
144struct mlx4_ib_ah {
145 struct ib_ah ibah;
146 struct mlx4_av av;
147};
148
149struct mlx4_ib_dev {
150 struct ib_device ib_dev;
151 struct mlx4_dev *dev;
152 void __iomem *uar_map;
153
154 struct list_head pgdir_list;
155 struct mutex pgdir_mutex;
156
157 struct mlx4_uar priv_uar;
158 u32 priv_pdn;
159 MLX4_DECLARE_DOORBELL_LOCK(uar_lock);
160
161 struct ib_mad_agent *send_agent[MLX4_MAX_PORTS][2];
162 struct ib_ah *sm_ah[MLX4_MAX_PORTS];
163 spinlock_t sm_lock;
164
165 struct mutex cap_mask_mutex;
166};
167
168static inline struct mlx4_ib_dev *to_mdev(struct ib_device *ibdev)
169{
170 return container_of(ibdev, struct mlx4_ib_dev, ib_dev);
171}
172
173static inline struct mlx4_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
174{
175 return container_of(ibucontext, struct mlx4_ib_ucontext, ibucontext);
176}
177
178static inline struct mlx4_ib_pd *to_mpd(struct ib_pd *ibpd)
179{
180 return container_of(ibpd, struct mlx4_ib_pd, ibpd);
181}
182
183static inline struct mlx4_ib_cq *to_mcq(struct ib_cq *ibcq)
184{
185 return container_of(ibcq, struct mlx4_ib_cq, ibcq);
186}
187
188static inline struct mlx4_ib_cq *to_mibcq(struct mlx4_cq *mcq)
189{
190 return container_of(mcq, struct mlx4_ib_cq, mcq);
191}
192
193static inline struct mlx4_ib_mr *to_mmr(struct ib_mr *ibmr)
194{
195 return container_of(ibmr, struct mlx4_ib_mr, ibmr);
196}
197
198static inline struct mlx4_ib_qp *to_mqp(struct ib_qp *ibqp)
199{
200 return container_of(ibqp, struct mlx4_ib_qp, ibqp);
201}
202
203static inline struct mlx4_ib_qp *to_mibqp(struct mlx4_qp *mqp)
204{
205 return container_of(mqp, struct mlx4_ib_qp, mqp);
206}
207
208static inline struct mlx4_ib_srq *to_msrq(struct ib_srq *ibsrq)
209{
210 return container_of(ibsrq, struct mlx4_ib_srq, ibsrq);
211}
212
213static inline struct mlx4_ib_srq *to_mibsrq(struct mlx4_srq *msrq)
214{
215 return container_of(msrq, struct mlx4_ib_srq, msrq);
216}
217
218static inline struct mlx4_ib_ah *to_mah(struct ib_ah *ibah)
219{
220 return container_of(ibah, struct mlx4_ib_ah, ibah);
221}
222
223int mlx4_ib_db_alloc(struct mlx4_ib_dev *dev, struct mlx4_ib_db *db, int order);
224void mlx4_ib_db_free(struct mlx4_ib_dev *dev, struct mlx4_ib_db *db);
225int mlx4_ib_db_map_user(struct mlx4_ib_ucontext *context, unsigned long virt,
226 struct mlx4_ib_db *db);
227void mlx4_ib_db_unmap_user(struct mlx4_ib_ucontext *context, struct mlx4_ib_db *db);
228
229struct ib_mr *mlx4_ib_get_dma_mr(struct ib_pd *pd, int acc);
230int mlx4_ib_umem_write_mtt(struct mlx4_ib_dev *dev, struct mlx4_mtt *mtt,
231 struct ib_umem *umem);
232struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
233 u64 virt_addr, int access_flags,
234 struct ib_udata *udata);
235int mlx4_ib_dereg_mr(struct ib_mr *mr);
236
237struct ib_cq *mlx4_ib_create_cq(struct ib_device *ibdev, int entries, int vector,
238 struct ib_ucontext *context,
239 struct ib_udata *udata);
240int mlx4_ib_destroy_cq(struct ib_cq *cq);
241int mlx4_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
242int mlx4_ib_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);
243void __mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq);
244void mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq);
245
246struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr);
247int mlx4_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
248int mlx4_ib_destroy_ah(struct ib_ah *ah);
249
250struct ib_srq *mlx4_ib_create_srq(struct ib_pd *pd,
251 struct ib_srq_init_attr *init_attr,
252 struct ib_udata *udata);
253int mlx4_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
254 enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
255int mlx4_ib_destroy_srq(struct ib_srq *srq);
256void mlx4_ib_free_srq_wqe(struct mlx4_ib_srq *srq, int wqe_index);
257int mlx4_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
258 struct ib_recv_wr **bad_wr);
259
260struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,
261 struct ib_qp_init_attr *init_attr,
262 struct ib_udata *udata);
263int mlx4_ib_destroy_qp(struct ib_qp *qp);
264int mlx4_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
265 int attr_mask, struct ib_udata *udata);
266int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
267 struct ib_send_wr **bad_wr);
268int mlx4_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
269 struct ib_recv_wr **bad_wr);
270
271int mlx4_MAD_IFC(struct mlx4_ib_dev *dev, int ignore_mkey, int ignore_bkey,
272 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
273 void *in_mad, void *response_mad);
274int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
275 struct ib_wc *in_wc, struct ib_grh *in_grh,
276 struct ib_mad *in_mad, struct ib_mad *out_mad);
277int mlx4_ib_mad_init(struct mlx4_ib_dev *dev);
278void mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev);
279
280static inline int mlx4_ib_ah_grh_present(struct mlx4_ib_ah *ah)
281{
282 return !!(ah->av.g_slid & 0x80);
283}
284
285#endif /* MLX4_IB_H */
diff --git a/drivers/infiniband/hw/mlx4/mr.c b/drivers/infiniband/hw/mlx4/mr.c
new file mode 100644
index 000000000000..85ae906f1d12
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/mr.c
@@ -0,0 +1,184 @@
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include "mlx4_ib.h"
34
35static u32 convert_access(int acc)
36{
37 return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX4_PERM_ATOMIC : 0) |
38 (acc & IB_ACCESS_REMOTE_WRITE ? MLX4_PERM_REMOTE_WRITE : 0) |
39 (acc & IB_ACCESS_REMOTE_READ ? MLX4_PERM_REMOTE_READ : 0) |
40 (acc & IB_ACCESS_LOCAL_WRITE ? MLX4_PERM_LOCAL_WRITE : 0) |
41 MLX4_PERM_LOCAL_READ;
42}
43
44struct ib_mr *mlx4_ib_get_dma_mr(struct ib_pd *pd, int acc)
45{
46 struct mlx4_ib_mr *mr;
47 int err;
48
49 mr = kmalloc(sizeof *mr, GFP_KERNEL);
50 if (!mr)
51 return ERR_PTR(-ENOMEM);
52
53 err = mlx4_mr_alloc(to_mdev(pd->device)->dev, to_mpd(pd)->pdn, 0,
54 ~0ull, convert_access(acc), 0, 0, &mr->mmr);
55 if (err)
56 goto err_free;
57
58 err = mlx4_mr_enable(to_mdev(pd->device)->dev, &mr->mmr);
59 if (err)
60 goto err_mr;
61
62 mr->ibmr.rkey = mr->ibmr.lkey = mr->mmr.key;
63 mr->umem = NULL;
64
65 return &mr->ibmr;
66
67err_mr:
68 mlx4_mr_free(to_mdev(pd->device)->dev, &mr->mmr);
69
70err_free:
71 kfree(mr);
72
73 return ERR_PTR(err);
74}
75
76int mlx4_ib_umem_write_mtt(struct mlx4_ib_dev *dev, struct mlx4_mtt *mtt,
77 struct ib_umem *umem)
78{
79 u64 *pages;
80 struct ib_umem_chunk *chunk;
81 int i, j, k;
82 int n;
83 int len;
84 int err = 0;
85
86 pages = (u64 *) __get_free_page(GFP_KERNEL);
87 if (!pages)
88 return -ENOMEM;
89
90 i = n = 0;
91
92 list_for_each_entry(chunk, &umem->chunk_list, list)
93 for (j = 0; j < chunk->nmap; ++j) {
94 len = sg_dma_len(&chunk->page_list[j]) >> mtt->page_shift;
95 for (k = 0; k < len; ++k) {
96 pages[i++] = sg_dma_address(&chunk->page_list[j]) +
97 umem->page_size * k;
98 /*
99 * Be friendly to WRITE_MTT firmware
100 * command, and pass it chunks of
101 * appropriate size.
102 */
103 if (i == PAGE_SIZE / sizeof (u64) - 2) {
104 err = mlx4_write_mtt(dev->dev, mtt, n,
105 i, pages);
106 if (err)
107 goto out;
108 n += i;
109 i = 0;
110 }
111 }
112 }
113
114 if (i)
115 err = mlx4_write_mtt(dev->dev, mtt, n, i, pages);
116
117out:
118 free_page((unsigned long) pages);
119 return err;
120}
121
122struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
123 u64 virt_addr, int access_flags,
124 struct ib_udata *udata)
125{
126 struct mlx4_ib_dev *dev = to_mdev(pd->device);
127 struct mlx4_ib_mr *mr;
128 int shift;
129 int err;
130 int n;
131
132 mr = kmalloc(sizeof *mr, GFP_KERNEL);
133 if (!mr)
134 return ERR_PTR(-ENOMEM);
135
136 mr->umem = ib_umem_get(pd->uobject->context, start, length, access_flags);
137 if (IS_ERR(mr->umem)) {
138 err = PTR_ERR(mr->umem);
139 goto err_free;
140 }
141
142 n = ib_umem_page_count(mr->umem);
143 shift = ilog2(mr->umem->page_size);
144
145 err = mlx4_mr_alloc(dev->dev, to_mpd(pd)->pdn, virt_addr, length,
146 convert_access(access_flags), n, shift, &mr->mmr);
147 if (err)
148 goto err_umem;
149
150 err = mlx4_ib_umem_write_mtt(dev, &mr->mmr.mtt, mr->umem);
151 if (err)
152 goto err_mr;
153
154 err = mlx4_mr_enable(dev->dev, &mr->mmr);
155 if (err)
156 goto err_mr;
157
158 mr->ibmr.rkey = mr->ibmr.lkey = mr->mmr.key;
159
160 return &mr->ibmr;
161
162err_mr:
163 mlx4_mr_free(to_mdev(pd->device)->dev, &mr->mmr);
164
165err_umem:
166 ib_umem_release(mr->umem);
167
168err_free:
169 kfree(mr);
170
171 return ERR_PTR(err);
172}
173
174int mlx4_ib_dereg_mr(struct ib_mr *ibmr)
175{
176 struct mlx4_ib_mr *mr = to_mmr(ibmr);
177
178 mlx4_mr_free(to_mdev(ibmr->device)->dev, &mr->mmr);
179 if (mr->umem)
180 ib_umem_release(mr->umem);
181 kfree(mr);
182
183 return 0;
184}
diff --git a/drivers/infiniband/hw/mlx4/qp.c b/drivers/infiniband/hw/mlx4/qp.c
new file mode 100644
index 000000000000..a824bc5f79fd
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/qp.c
@@ -0,0 +1,1371 @@
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <rdma/ib_cache.h>
34#include <rdma/ib_pack.h>
35
36#include <linux/mlx4/qp.h>
37
38#include "mlx4_ib.h"
39#include "user.h"
40
41enum {
42 MLX4_IB_ACK_REQ_FREQ = 8,
43};
44
45enum {
46 MLX4_IB_DEFAULT_SCHED_QUEUE = 0x83,
47 MLX4_IB_DEFAULT_QP0_SCHED_QUEUE = 0x3f
48};
49
50enum {
51 /*
52 * Largest possible UD header: send with GRH and immediate data.
53 */
54 MLX4_IB_UD_HEADER_SIZE = 72
55};
56
57struct mlx4_ib_sqp {
58 struct mlx4_ib_qp qp;
59 int pkey_index;
60 u32 qkey;
61 u32 send_psn;
62 struct ib_ud_header ud_header;
63 u8 header_buf[MLX4_IB_UD_HEADER_SIZE];
64};
65
66static const __be32 mlx4_ib_opcode[] = {
67 [IB_WR_SEND] = __constant_cpu_to_be32(MLX4_OPCODE_SEND),
68 [IB_WR_SEND_WITH_IMM] = __constant_cpu_to_be32(MLX4_OPCODE_SEND_IMM),
69 [IB_WR_RDMA_WRITE] = __constant_cpu_to_be32(MLX4_OPCODE_RDMA_WRITE),
70 [IB_WR_RDMA_WRITE_WITH_IMM] = __constant_cpu_to_be32(MLX4_OPCODE_RDMA_WRITE_IMM),
71 [IB_WR_RDMA_READ] = __constant_cpu_to_be32(MLX4_OPCODE_RDMA_READ),
72 [IB_WR_ATOMIC_CMP_AND_SWP] = __constant_cpu_to_be32(MLX4_OPCODE_ATOMIC_CS),
73 [IB_WR_ATOMIC_FETCH_AND_ADD] = __constant_cpu_to_be32(MLX4_OPCODE_ATOMIC_FA),
74};
75
76static struct mlx4_ib_sqp *to_msqp(struct mlx4_ib_qp *mqp)
77{
78 return container_of(mqp, struct mlx4_ib_sqp, qp);
79}
80
81static int is_sqp(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp)
82{
83 return qp->mqp.qpn >= dev->dev->caps.sqp_start &&
84 qp->mqp.qpn <= dev->dev->caps.sqp_start + 3;
85}
86
87static int is_qp0(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp)
88{
89 return qp->mqp.qpn >= dev->dev->caps.sqp_start &&
90 qp->mqp.qpn <= dev->dev->caps.sqp_start + 1;
91}
92
93static void *get_wqe(struct mlx4_ib_qp *qp, int offset)
94{
95 if (qp->buf.nbufs == 1)
96 return qp->buf.u.direct.buf + offset;
97 else
98 return qp->buf.u.page_list[offset >> PAGE_SHIFT].buf +
99 (offset & (PAGE_SIZE - 1));
100}
101
102static void *get_recv_wqe(struct mlx4_ib_qp *qp, int n)
103{
104 return get_wqe(qp, qp->rq.offset + (n << qp->rq.wqe_shift));
105}
106
107static void *get_send_wqe(struct mlx4_ib_qp *qp, int n)
108{
109 return get_wqe(qp, qp->sq.offset + (n << qp->sq.wqe_shift));
110}
111
112static void mlx4_ib_qp_event(struct mlx4_qp *qp, enum mlx4_event type)
113{
114 struct ib_event event;
115 struct ib_qp *ibqp = &to_mibqp(qp)->ibqp;
116
117 if (type == MLX4_EVENT_TYPE_PATH_MIG)
118 to_mibqp(qp)->port = to_mibqp(qp)->alt_port;
119
120 if (ibqp->event_handler) {
121 event.device = ibqp->device;
122 event.element.qp = ibqp;
123 switch (type) {
124 case MLX4_EVENT_TYPE_PATH_MIG:
125 event.event = IB_EVENT_PATH_MIG;
126 break;
127 case MLX4_EVENT_TYPE_COMM_EST:
128 event.event = IB_EVENT_COMM_EST;
129 break;
130 case MLX4_EVENT_TYPE_SQ_DRAINED:
131 event.event = IB_EVENT_SQ_DRAINED;
132 break;
133 case MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE:
134 event.event = IB_EVENT_QP_LAST_WQE_REACHED;
135 break;
136 case MLX4_EVENT_TYPE_WQ_CATAS_ERROR:
137 event.event = IB_EVENT_QP_FATAL;
138 break;
139 case MLX4_EVENT_TYPE_PATH_MIG_FAILED:
140 event.event = IB_EVENT_PATH_MIG_ERR;
141 break;
142 case MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
143 event.event = IB_EVENT_QP_REQ_ERR;
144 break;
145 case MLX4_EVENT_TYPE_WQ_ACCESS_ERROR:
146 event.event = IB_EVENT_QP_ACCESS_ERR;
147 break;
148 default:
149 printk(KERN_WARNING "mlx4_ib: Unexpected event type %d "
150 "on QP %06x\n", type, qp->qpn);
151 return;
152 }
153
154 ibqp->event_handler(&event, ibqp->qp_context);
155 }
156}
157
158static int send_wqe_overhead(enum ib_qp_type type)
159{
160 /*
161 * UD WQEs must have a datagram segment.
162 * RC and UC WQEs might have a remote address segment.
163 * MLX WQEs need two extra inline data segments (for the UD
164 * header and space for the ICRC).
165 */
166 switch (type) {
167 case IB_QPT_UD:
168 return sizeof (struct mlx4_wqe_ctrl_seg) +
169 sizeof (struct mlx4_wqe_datagram_seg);
170 case IB_QPT_UC:
171 return sizeof (struct mlx4_wqe_ctrl_seg) +
172 sizeof (struct mlx4_wqe_raddr_seg);
173 case IB_QPT_RC:
174 return sizeof (struct mlx4_wqe_ctrl_seg) +
175 sizeof (struct mlx4_wqe_atomic_seg) +
176 sizeof (struct mlx4_wqe_raddr_seg);
177 case IB_QPT_SMI:
178 case IB_QPT_GSI:
179 return sizeof (struct mlx4_wqe_ctrl_seg) +
180 ALIGN(MLX4_IB_UD_HEADER_SIZE +
181 sizeof (struct mlx4_wqe_inline_seg),
182 sizeof (struct mlx4_wqe_data_seg)) +
183 ALIGN(4 +
184 sizeof (struct mlx4_wqe_inline_seg),
185 sizeof (struct mlx4_wqe_data_seg));
186 default:
187 return sizeof (struct mlx4_wqe_ctrl_seg);
188 }
189}
190
191static int set_rq_size(struct mlx4_ib_dev *dev, struct ib_qp_cap *cap,
192 struct mlx4_ib_qp *qp)
193{
194 /* Sanity check RQ size before proceeding */
195 if (cap->max_recv_wr > dev->dev->caps.max_wqes ||
196 cap->max_recv_sge > dev->dev->caps.max_rq_sg)
197 return -EINVAL;
198
199 qp->rq.max = cap->max_recv_wr ? roundup_pow_of_two(cap->max_recv_wr) : 0;
200
201 qp->rq.wqe_shift = ilog2(roundup_pow_of_two(cap->max_recv_sge *
202 sizeof (struct mlx4_wqe_data_seg)));
203 qp->rq.max_gs = (1 << qp->rq.wqe_shift) / sizeof (struct mlx4_wqe_data_seg);
204
205 cap->max_recv_wr = qp->rq.max;
206 cap->max_recv_sge = qp->rq.max_gs;
207
208 return 0;
209}
210
211static int set_kernel_sq_size(struct mlx4_ib_dev *dev, struct ib_qp_cap *cap,
212 enum ib_qp_type type, struct mlx4_ib_qp *qp)
213{
214 /* Sanity check SQ size before proceeding */
215 if (cap->max_send_wr > dev->dev->caps.max_wqes ||
216 cap->max_send_sge > dev->dev->caps.max_sq_sg ||
217 cap->max_inline_data + send_wqe_overhead(type) +
218 sizeof (struct mlx4_wqe_inline_seg) > dev->dev->caps.max_sq_desc_sz)
219 return -EINVAL;
220
221 /*
222 * For MLX transport we need 2 extra S/G entries:
223 * one for the header and one for the checksum at the end
224 */
225 if ((type == IB_QPT_SMI || type == IB_QPT_GSI) &&
226 cap->max_send_sge + 2 > dev->dev->caps.max_sq_sg)
227 return -EINVAL;
228
229 qp->sq.max = cap->max_send_wr ? roundup_pow_of_two(cap->max_send_wr) : 1;
230
231 qp->sq.wqe_shift = ilog2(roundup_pow_of_two(max(cap->max_send_sge *
232 sizeof (struct mlx4_wqe_data_seg),
233 cap->max_inline_data +
234 sizeof (struct mlx4_wqe_inline_seg)) +
235 send_wqe_overhead(type)));
236 qp->sq.max_gs = ((1 << qp->sq.wqe_shift) - send_wqe_overhead(type)) /
237 sizeof (struct mlx4_wqe_data_seg);
238
239 qp->buf_size = (qp->rq.max << qp->rq.wqe_shift) +
240 (qp->sq.max << qp->sq.wqe_shift);
241 if (qp->rq.wqe_shift > qp->sq.wqe_shift) {
242 qp->rq.offset = 0;
243 qp->sq.offset = qp->rq.max << qp->rq.wqe_shift;
244 } else {
245 qp->rq.offset = qp->sq.max << qp->sq.wqe_shift;
246 qp->sq.offset = 0;
247 }
248
249 cap->max_send_wr = qp->sq.max;
250 cap->max_send_sge = qp->sq.max_gs;
251 cap->max_inline_data = (1 << qp->sq.wqe_shift) - send_wqe_overhead(type) -
252 sizeof (struct mlx4_wqe_inline_seg);
253
254 return 0;
255}
256
257static int set_user_sq_size(struct mlx4_ib_qp *qp,
258 struct mlx4_ib_create_qp *ucmd)
259{
260 qp->sq.max = 1 << ucmd->log_sq_bb_count;
261 qp->sq.wqe_shift = ucmd->log_sq_stride;
262
263 qp->buf_size = (qp->rq.max << qp->rq.wqe_shift) +
264 (qp->sq.max << qp->sq.wqe_shift);
265
266 return 0;
267}
268
269static int create_qp_common(struct mlx4_ib_dev *dev, struct ib_pd *pd,
270 struct ib_qp_init_attr *init_attr,
271 struct ib_udata *udata, int sqpn, struct mlx4_ib_qp *qp)
272{
273 struct mlx4_wqe_ctrl_seg *ctrl;
274 int err;
275 int i;
276
277 mutex_init(&qp->mutex);
278 spin_lock_init(&qp->sq.lock);
279 spin_lock_init(&qp->rq.lock);
280
281 qp->state = IB_QPS_RESET;
282 qp->atomic_rd_en = 0;
283 qp->resp_depth = 0;
284
285 qp->rq.head = 0;
286 qp->rq.tail = 0;
287 qp->sq.head = 0;
288 qp->sq.tail = 0;
289
290 err = set_rq_size(dev, &init_attr->cap, qp);
291 if (err)
292 goto err;
293
294 if (pd->uobject) {
295 struct mlx4_ib_create_qp ucmd;
296
297 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
298 err = -EFAULT;
299 goto err;
300 }
301
302 err = set_user_sq_size(qp, &ucmd);
303 if (err)
304 goto err;
305
306 qp->umem = ib_umem_get(pd->uobject->context, ucmd.buf_addr,
307 qp->buf_size, 0);
308 if (IS_ERR(qp->umem)) {
309 err = PTR_ERR(qp->umem);
310 goto err;
311 }
312
313 err = mlx4_mtt_init(dev->dev, ib_umem_page_count(qp->umem),
314 ilog2(qp->umem->page_size), &qp->mtt);
315 if (err)
316 goto err_buf;
317
318 err = mlx4_ib_umem_write_mtt(dev, &qp->mtt, qp->umem);
319 if (err)
320 goto err_mtt;
321
322 err = mlx4_ib_db_map_user(to_mucontext(pd->uobject->context),
323 ucmd.db_addr, &qp->db);
324 if (err)
325 goto err_mtt;
326 } else {
327 err = set_kernel_sq_size(dev, &init_attr->cap, init_attr->qp_type, qp);
328 if (err)
329 goto err;
330
331 err = mlx4_ib_db_alloc(dev, &qp->db, 0);
332 if (err)
333 goto err;
334
335 *qp->db.db = 0;
336
337 if (mlx4_buf_alloc(dev->dev, qp->buf_size, PAGE_SIZE * 2, &qp->buf)) {
338 err = -ENOMEM;
339 goto err_db;
340 }
341
342 err = mlx4_mtt_init(dev->dev, qp->buf.npages, qp->buf.page_shift,
343 &qp->mtt);
344 if (err)
345 goto err_buf;
346
347 err = mlx4_buf_write_mtt(dev->dev, &qp->mtt, &qp->buf);
348 if (err)
349 goto err_mtt;
350
351 for (i = 0; i < qp->sq.max; ++i) {
352 ctrl = get_send_wqe(qp, i);
353 ctrl->owner_opcode = cpu_to_be32(1 << 31);
354 }
355
356 qp->sq.wrid = kmalloc(qp->sq.max * sizeof (u64), GFP_KERNEL);
357 qp->rq.wrid = kmalloc(qp->rq.max * sizeof (u64), GFP_KERNEL);
358
359 if (!qp->sq.wrid || !qp->rq.wrid) {
360 err = -ENOMEM;
361 goto err_wrid;
362 }
363
364 /* We don't support inline sends for kernel QPs (yet) */
365 init_attr->cap.max_inline_data = 0;
366 }
367
368 err = mlx4_qp_alloc(dev->dev, sqpn, &qp->mqp);
369 if (err)
370 goto err_wrid;
371
372 /*
373 * Hardware wants QPN written in big-endian order (after
374 * shifting) for send doorbell. Precompute this value to save
375 * a little bit when posting sends.
376 */
377 qp->doorbell_qpn = swab32(qp->mqp.qpn << 8);
378
379 if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
380 qp->sq_signal_bits = cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE);
381 else
382 qp->sq_signal_bits = 0;
383
384 qp->mqp.event = mlx4_ib_qp_event;
385
386 return 0;
387
388err_wrid:
389 if (pd->uobject)
390 mlx4_ib_db_unmap_user(to_mucontext(pd->uobject->context), &qp->db);
391 else {
392 kfree(qp->sq.wrid);
393 kfree(qp->rq.wrid);
394 }
395
396err_mtt:
397 mlx4_mtt_cleanup(dev->dev, &qp->mtt);
398
399err_buf:
400 if (pd->uobject)
401 ib_umem_release(qp->umem);
402 else
403 mlx4_buf_free(dev->dev, qp->buf_size, &qp->buf);
404
405err_db:
406 if (!pd->uobject)
407 mlx4_ib_db_free(dev, &qp->db);
408
409err:
410 return err;
411}
412
413static enum mlx4_qp_state to_mlx4_state(enum ib_qp_state state)
414{
415 switch (state) {
416 case IB_QPS_RESET: return MLX4_QP_STATE_RST;
417 case IB_QPS_INIT: return MLX4_QP_STATE_INIT;
418 case IB_QPS_RTR: return MLX4_QP_STATE_RTR;
419 case IB_QPS_RTS: return MLX4_QP_STATE_RTS;
420 case IB_QPS_SQD: return MLX4_QP_STATE_SQD;
421 case IB_QPS_SQE: return MLX4_QP_STATE_SQER;
422 case IB_QPS_ERR: return MLX4_QP_STATE_ERR;
423 default: return -1;
424 }
425}
426
427static void mlx4_ib_lock_cqs(struct mlx4_ib_cq *send_cq, struct mlx4_ib_cq *recv_cq)
428{
429 if (send_cq == recv_cq)
430 spin_lock_irq(&send_cq->lock);
431 else if (send_cq->mcq.cqn < recv_cq->mcq.cqn) {
432 spin_lock_irq(&send_cq->lock);
433 spin_lock_nested(&recv_cq->lock, SINGLE_DEPTH_NESTING);
434 } else {
435 spin_lock_irq(&recv_cq->lock);
436 spin_lock_nested(&send_cq->lock, SINGLE_DEPTH_NESTING);
437 }
438}
439
440static void mlx4_ib_unlock_cqs(struct mlx4_ib_cq *send_cq, struct mlx4_ib_cq *recv_cq)
441{
442 if (send_cq == recv_cq)
443 spin_unlock_irq(&send_cq->lock);
444 else if (send_cq->mcq.cqn < recv_cq->mcq.cqn) {
445 spin_unlock(&recv_cq->lock);
446 spin_unlock_irq(&send_cq->lock);
447 } else {
448 spin_unlock(&send_cq->lock);
449 spin_unlock_irq(&recv_cq->lock);
450 }
451}
452
453static void destroy_qp_common(struct mlx4_ib_dev *dev, struct mlx4_ib_qp *qp,
454 int is_user)
455{
456 struct mlx4_ib_cq *send_cq, *recv_cq;
457
458 if (qp->state != IB_QPS_RESET)
459 if (mlx4_qp_modify(dev->dev, NULL, to_mlx4_state(qp->state),
460 MLX4_QP_STATE_RST, NULL, 0, 0, &qp->mqp))
461 printk(KERN_WARNING "mlx4_ib: modify QP %06x to RESET failed.\n",
462 qp->mqp.qpn);
463
464 send_cq = to_mcq(qp->ibqp.send_cq);
465 recv_cq = to_mcq(qp->ibqp.recv_cq);
466
467 mlx4_ib_lock_cqs(send_cq, recv_cq);
468
469 if (!is_user) {
470 __mlx4_ib_cq_clean(recv_cq, qp->mqp.qpn,
471 qp->ibqp.srq ? to_msrq(qp->ibqp.srq): NULL);
472 if (send_cq != recv_cq)
473 __mlx4_ib_cq_clean(send_cq, qp->mqp.qpn, NULL);
474 }
475
476 mlx4_qp_remove(dev->dev, &qp->mqp);
477
478 mlx4_ib_unlock_cqs(send_cq, recv_cq);
479
480 mlx4_qp_free(dev->dev, &qp->mqp);
481 mlx4_mtt_cleanup(dev->dev, &qp->mtt);
482
483 if (is_user) {
484 mlx4_ib_db_unmap_user(to_mucontext(qp->ibqp.uobject->context),
485 &qp->db);
486 ib_umem_release(qp->umem);
487 } else {
488 kfree(qp->sq.wrid);
489 kfree(qp->rq.wrid);
490 mlx4_buf_free(dev->dev, qp->buf_size, &qp->buf);
491 mlx4_ib_db_free(dev, &qp->db);
492 }
493}
494
495struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,
496 struct ib_qp_init_attr *init_attr,
497 struct ib_udata *udata)
498{
499 struct mlx4_ib_dev *dev = to_mdev(pd->device);
500 struct mlx4_ib_sqp *sqp;
501 struct mlx4_ib_qp *qp;
502 int err;
503
504 switch (init_attr->qp_type) {
505 case IB_QPT_RC:
506 case IB_QPT_UC:
507 case IB_QPT_UD:
508 {
509 qp = kmalloc(sizeof *qp, GFP_KERNEL);
510 if (!qp)
511 return ERR_PTR(-ENOMEM);
512
513 err = create_qp_common(dev, pd, init_attr, udata, 0, qp);
514 if (err) {
515 kfree(qp);
516 return ERR_PTR(err);
517 }
518
519 qp->ibqp.qp_num = qp->mqp.qpn;
520
521 break;
522 }
523 case IB_QPT_SMI:
524 case IB_QPT_GSI:
525 {
526 /* Userspace is not allowed to create special QPs: */
527 if (pd->uobject)
528 return ERR_PTR(-EINVAL);
529
530 sqp = kmalloc(sizeof *sqp, GFP_KERNEL);
531 if (!sqp)
532 return ERR_PTR(-ENOMEM);
533
534 qp = &sqp->qp;
535
536 err = create_qp_common(dev, pd, init_attr, udata,
537 dev->dev->caps.sqp_start +
538 (init_attr->qp_type == IB_QPT_SMI ? 0 : 2) +
539 init_attr->port_num - 1,
540 qp);
541 if (err) {
542 kfree(sqp);
543 return ERR_PTR(err);
544 }
545
546 qp->port = init_attr->port_num;
547 qp->ibqp.qp_num = init_attr->qp_type == IB_QPT_SMI ? 0 : 1;
548
549 break;
550 }
551 default:
552 /* Don't support raw QPs */
553 return ERR_PTR(-EINVAL);
554 }
555
556 return &qp->ibqp;
557}
558
559int mlx4_ib_destroy_qp(struct ib_qp *qp)
560{
561 struct mlx4_ib_dev *dev = to_mdev(qp->device);
562 struct mlx4_ib_qp *mqp = to_mqp(qp);
563
564 if (is_qp0(dev, mqp))
565 mlx4_CLOSE_PORT(dev->dev, mqp->port);
566
567 destroy_qp_common(dev, mqp, !!qp->pd->uobject);
568
569 if (is_sqp(dev, mqp))
570 kfree(to_msqp(mqp));
571 else
572 kfree(mqp);
573
574 return 0;
575}
576
577static void init_port(struct mlx4_ib_dev *dev, int port)
578{
579 struct mlx4_init_port_param param;
580 int err;
581
582 memset(&param, 0, sizeof param);
583
584 param.port_width_cap = dev->dev->caps.port_width_cap;
585 param.vl_cap = dev->dev->caps.vl_cap;
586 param.mtu = ib_mtu_enum_to_int(dev->dev->caps.mtu_cap);
587 param.max_gid = dev->dev->caps.gid_table_len;
588 param.max_pkey = dev->dev->caps.pkey_table_len;
589
590 err = mlx4_INIT_PORT(dev->dev, &param, port);
591 if (err)
592 printk(KERN_WARNING "INIT_PORT failed, return code %d.\n", err);
593}
594
595static int to_mlx4_st(enum ib_qp_type type)
596{
597 switch (type) {
598 case IB_QPT_RC: return MLX4_QP_ST_RC;
599 case IB_QPT_UC: return MLX4_QP_ST_UC;
600 case IB_QPT_UD: return MLX4_QP_ST_UD;
601 case IB_QPT_SMI:
602 case IB_QPT_GSI: return MLX4_QP_ST_MLX;
603 default: return -1;
604 }
605}
606
607static __be32 to_mlx4_access_flags(struct mlx4_ib_qp *qp, const struct ib_qp_attr *attr,
608 int attr_mask)
609{
610 u8 dest_rd_atomic;
611 u32 access_flags;
612 u32 hw_access_flags = 0;
613
614 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
615 dest_rd_atomic = attr->max_dest_rd_atomic;
616 else
617 dest_rd_atomic = qp->resp_depth;
618
619 if (attr_mask & IB_QP_ACCESS_FLAGS)
620 access_flags = attr->qp_access_flags;
621 else
622 access_flags = qp->atomic_rd_en;
623
624 if (!dest_rd_atomic)
625 access_flags &= IB_ACCESS_REMOTE_WRITE;
626
627 if (access_flags & IB_ACCESS_REMOTE_READ)
628 hw_access_flags |= MLX4_QP_BIT_RRE;
629 if (access_flags & IB_ACCESS_REMOTE_ATOMIC)
630 hw_access_flags |= MLX4_QP_BIT_RAE;
631 if (access_flags & IB_ACCESS_REMOTE_WRITE)
632 hw_access_flags |= MLX4_QP_BIT_RWE;
633
634 return cpu_to_be32(hw_access_flags);
635}
636
637static void store_sqp_attrs(struct mlx4_ib_sqp *sqp, const struct ib_qp_attr *attr,
638 int attr_mask)
639{
640 if (attr_mask & IB_QP_PKEY_INDEX)
641 sqp->pkey_index = attr->pkey_index;
642 if (attr_mask & IB_QP_QKEY)
643 sqp->qkey = attr->qkey;
644 if (attr_mask & IB_QP_SQ_PSN)
645 sqp->send_psn = attr->sq_psn;
646}
647
648static void mlx4_set_sched(struct mlx4_qp_path *path, u8 port)
649{
650 path->sched_queue = (path->sched_queue & 0xbf) | ((port - 1) << 6);
651}
652
653static int mlx4_set_path(struct mlx4_ib_dev *dev, const struct ib_ah_attr *ah,
654 struct mlx4_qp_path *path, u8 port)
655{
656 path->grh_mylmc = ah->src_path_bits & 0x7f;
657 path->rlid = cpu_to_be16(ah->dlid);
658 if (ah->static_rate) {
659 path->static_rate = ah->static_rate + MLX4_STAT_RATE_OFFSET;
660 while (path->static_rate > IB_RATE_2_5_GBPS + MLX4_STAT_RATE_OFFSET &&
661 !(1 << path->static_rate & dev->dev->caps.stat_rate_support))
662 --path->static_rate;
663 } else
664 path->static_rate = 0;
665 path->counter_index = 0xff;
666
667 if (ah->ah_flags & IB_AH_GRH) {
668 if (ah->grh.sgid_index >= dev->dev->caps.gid_table_len) {
669 printk(KERN_ERR "sgid_index (%u) too large. max is %d\n",
670 ah->grh.sgid_index, dev->dev->caps.gid_table_len - 1);
671 return -1;
672 }
673
674 path->grh_mylmc |= 1 << 7;
675 path->mgid_index = ah->grh.sgid_index;
676 path->hop_limit = ah->grh.hop_limit;
677 path->tclass_flowlabel =
678 cpu_to_be32((ah->grh.traffic_class << 20) |
679 (ah->grh.flow_label));
680 memcpy(path->rgid, ah->grh.dgid.raw, 16);
681 }
682
683 path->sched_queue = MLX4_IB_DEFAULT_SCHED_QUEUE |
684 ((port - 1) << 6) | ((ah->sl & 0xf) << 2);
685
686 return 0;
687}
688
689static int __mlx4_ib_modify_qp(struct ib_qp *ibqp,
690 const struct ib_qp_attr *attr, int attr_mask,
691 enum ib_qp_state cur_state, enum ib_qp_state new_state)
692{
693 struct mlx4_ib_dev *dev = to_mdev(ibqp->device);
694 struct mlx4_ib_qp *qp = to_mqp(ibqp);
695 struct mlx4_qp_context *context;
696 enum mlx4_qp_optpar optpar = 0;
697 int sqd_event;
698 int err = -EINVAL;
699
700 context = kzalloc(sizeof *context, GFP_KERNEL);
701 if (!context)
702 return -ENOMEM;
703
704 context->flags = cpu_to_be32((to_mlx4_state(new_state) << 28) |
705 (to_mlx4_st(ibqp->qp_type) << 16));
706 context->flags |= cpu_to_be32(1 << 8); /* DE? */
707
708 if (!(attr_mask & IB_QP_PATH_MIG_STATE))
709 context->flags |= cpu_to_be32(MLX4_QP_PM_MIGRATED << 11);
710 else {
711 optpar |= MLX4_QP_OPTPAR_PM_STATE;
712 switch (attr->path_mig_state) {
713 case IB_MIG_MIGRATED:
714 context->flags |= cpu_to_be32(MLX4_QP_PM_MIGRATED << 11);
715 break;
716 case IB_MIG_REARM:
717 context->flags |= cpu_to_be32(MLX4_QP_PM_REARM << 11);
718 break;
719 case IB_MIG_ARMED:
720 context->flags |= cpu_to_be32(MLX4_QP_PM_ARMED << 11);
721 break;
722 }
723 }
724
725 if (ibqp->qp_type == IB_QPT_GSI || ibqp->qp_type == IB_QPT_SMI ||
726 ibqp->qp_type == IB_QPT_UD)
727 context->mtu_msgmax = (IB_MTU_4096 << 5) | 11;
728 else if (attr_mask & IB_QP_PATH_MTU) {
729 if (attr->path_mtu < IB_MTU_256 || attr->path_mtu > IB_MTU_4096) {
730 printk(KERN_ERR "path MTU (%u) is invalid\n",
731 attr->path_mtu);
732 return -EINVAL;
733 }
734 context->mtu_msgmax = (attr->path_mtu << 5) | 31;
735 }
736
737 if (qp->rq.max)
738 context->rq_size_stride = ilog2(qp->rq.max) << 3;
739 context->rq_size_stride |= qp->rq.wqe_shift - 4;
740
741 if (qp->sq.max)
742 context->sq_size_stride = ilog2(qp->sq.max) << 3;
743 context->sq_size_stride |= qp->sq.wqe_shift - 4;
744
745 if (qp->ibqp.uobject)
746 context->usr_page = cpu_to_be32(to_mucontext(ibqp->uobject->context)->uar.index);
747 else
748 context->usr_page = cpu_to_be32(dev->priv_uar.index);
749
750 if (attr_mask & IB_QP_DEST_QPN)
751 context->remote_qpn = cpu_to_be32(attr->dest_qp_num);
752
753 if (attr_mask & IB_QP_PORT) {
754 if (cur_state == IB_QPS_SQD && new_state == IB_QPS_SQD &&
755 !(attr_mask & IB_QP_AV)) {
756 mlx4_set_sched(&context->pri_path, attr->port_num);
757 optpar |= MLX4_QP_OPTPAR_SCHED_QUEUE;
758 }
759 }
760
761 if (attr_mask & IB_QP_PKEY_INDEX) {
762 context->pri_path.pkey_index = attr->pkey_index;
763 optpar |= MLX4_QP_OPTPAR_PKEY_INDEX;
764 }
765
766 if (attr_mask & IB_QP_RNR_RETRY) {
767 context->params1 |= cpu_to_be32(attr->rnr_retry << 13);
768 optpar |= MLX4_QP_OPTPAR_RNR_RETRY;
769 }
770
771 if (attr_mask & IB_QP_AV) {
772 if (mlx4_set_path(dev, &attr->ah_attr, &context->pri_path,
773 attr_mask & IB_QP_PORT ? attr->port_num : qp->port)) {
774 err = -EINVAL;
775 goto out;
776 }
777
778 optpar |= (MLX4_QP_OPTPAR_PRIMARY_ADDR_PATH |
779 MLX4_QP_OPTPAR_SCHED_QUEUE);
780 }
781
782 if (attr_mask & IB_QP_TIMEOUT) {
783 context->pri_path.ackto = attr->timeout << 3;
784 optpar |= MLX4_QP_OPTPAR_ACK_TIMEOUT;
785 }
786
787 if (attr_mask & IB_QP_ALT_PATH) {
788 if (attr->alt_pkey_index >= dev->dev->caps.pkey_table_len)
789 return -EINVAL;
790
791 if (attr->alt_port_num == 0 ||
792 attr->alt_port_num > dev->dev->caps.num_ports)
793 return -EINVAL;
794
795 if (mlx4_set_path(dev, &attr->alt_ah_attr, &context->alt_path,
796 attr->alt_port_num))
797 return -EINVAL;
798
799 context->alt_path.pkey_index = attr->alt_pkey_index;
800 context->alt_path.ackto = attr->alt_timeout << 3;
801 optpar |= MLX4_QP_OPTPAR_ALT_ADDR_PATH;
802 }
803
804 context->pd = cpu_to_be32(to_mpd(ibqp->pd)->pdn);
805 context->params1 = cpu_to_be32(MLX4_IB_ACK_REQ_FREQ << 28);
806 if (attr_mask & IB_QP_RETRY_CNT) {
807 context->params1 |= cpu_to_be32(attr->retry_cnt << 16);
808 optpar |= MLX4_QP_OPTPAR_RETRY_COUNT;
809 }
810
811 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) {
812 if (attr->max_rd_atomic)
813 context->params1 |=
814 cpu_to_be32(fls(attr->max_rd_atomic - 1) << 21);
815 optpar |= MLX4_QP_OPTPAR_SRA_MAX;
816 }
817
818 if (attr_mask & IB_QP_SQ_PSN)
819 context->next_send_psn = cpu_to_be32(attr->sq_psn);
820
821 context->cqn_send = cpu_to_be32(to_mcq(ibqp->send_cq)->mcq.cqn);
822
823 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) {
824 if (attr->max_dest_rd_atomic)
825 context->params2 |=
826 cpu_to_be32(fls(attr->max_dest_rd_atomic - 1) << 21);
827 optpar |= MLX4_QP_OPTPAR_RRA_MAX;
828 }
829
830 if (attr_mask & (IB_QP_ACCESS_FLAGS | IB_QP_MAX_DEST_RD_ATOMIC)) {
831 context->params2 |= to_mlx4_access_flags(qp, attr, attr_mask);
832 optpar |= MLX4_QP_OPTPAR_RWE | MLX4_QP_OPTPAR_RRE | MLX4_QP_OPTPAR_RAE;
833 }
834
835 if (ibqp->srq)
836 context->params2 |= cpu_to_be32(MLX4_QP_BIT_RIC);
837
838 if (attr_mask & IB_QP_MIN_RNR_TIMER) {
839 context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24);
840 optpar |= MLX4_QP_OPTPAR_RNR_TIMEOUT;
841 }
842 if (attr_mask & IB_QP_RQ_PSN)
843 context->rnr_nextrecvpsn |= cpu_to_be32(attr->rq_psn);
844
845 context->cqn_recv = cpu_to_be32(to_mcq(ibqp->recv_cq)->mcq.cqn);
846
847 if (attr_mask & IB_QP_QKEY) {
848 context->qkey = cpu_to_be32(attr->qkey);
849 optpar |= MLX4_QP_OPTPAR_Q_KEY;
850 }
851
852 if (ibqp->srq)
853 context->srqn = cpu_to_be32(1 << 24 | to_msrq(ibqp->srq)->msrq.srqn);
854
855 if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT)
856 context->db_rec_addr = cpu_to_be64(qp->db.dma);
857
858 if (cur_state == IB_QPS_INIT &&
859 new_state == IB_QPS_RTR &&
860 (ibqp->qp_type == IB_QPT_GSI || ibqp->qp_type == IB_QPT_SMI ||
861 ibqp->qp_type == IB_QPT_UD)) {
862 context->pri_path.sched_queue = (qp->port - 1) << 6;
863 if (is_qp0(dev, qp))
864 context->pri_path.sched_queue |= MLX4_IB_DEFAULT_QP0_SCHED_QUEUE;
865 else
866 context->pri_path.sched_queue |= MLX4_IB_DEFAULT_SCHED_QUEUE;
867 }
868
869 if (cur_state == IB_QPS_RTS && new_state == IB_QPS_SQD &&
870 attr_mask & IB_QP_EN_SQD_ASYNC_NOTIFY && attr->en_sqd_async_notify)
871 sqd_event = 1;
872 else
873 sqd_event = 0;
874
875 err = mlx4_qp_modify(dev->dev, &qp->mtt, to_mlx4_state(cur_state),
876 to_mlx4_state(new_state), context, optpar,
877 sqd_event, &qp->mqp);
878 if (err)
879 goto out;
880
881 qp->state = new_state;
882
883 if (attr_mask & IB_QP_ACCESS_FLAGS)
884 qp->atomic_rd_en = attr->qp_access_flags;
885 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC)
886 qp->resp_depth = attr->max_dest_rd_atomic;
887 if (attr_mask & IB_QP_PORT)
888 qp->port = attr->port_num;
889 if (attr_mask & IB_QP_ALT_PATH)
890 qp->alt_port = attr->alt_port_num;
891
892 if (is_sqp(dev, qp))
893 store_sqp_attrs(to_msqp(qp), attr, attr_mask);
894
895 /*
896 * If we moved QP0 to RTR, bring the IB link up; if we moved
897 * QP0 to RESET or ERROR, bring the link back down.
898 */
899 if (is_qp0(dev, qp)) {
900 if (cur_state != IB_QPS_RTR && new_state == IB_QPS_RTR)
901 init_port(dev, qp->port);
902
903 if (cur_state != IB_QPS_RESET && cur_state != IB_QPS_ERR &&
904 (new_state == IB_QPS_RESET || new_state == IB_QPS_ERR))
905 mlx4_CLOSE_PORT(dev->dev, qp->port);
906 }
907
908 /*
909 * If we moved a kernel QP to RESET, clean up all old CQ
910 * entries and reinitialize the QP.
911 */
912 if (new_state == IB_QPS_RESET && !ibqp->uobject) {
913 mlx4_ib_cq_clean(to_mcq(ibqp->recv_cq), qp->mqp.qpn,
914 ibqp->srq ? to_msrq(ibqp->srq): NULL);
915 if (ibqp->send_cq != ibqp->recv_cq)
916 mlx4_ib_cq_clean(to_mcq(ibqp->send_cq), qp->mqp.qpn, NULL);
917
918 qp->rq.head = 0;
919 qp->rq.tail = 0;
920 qp->sq.head = 0;
921 qp->sq.tail = 0;
922 *qp->db.db = 0;
923 }
924
925out:
926 kfree(context);
927 return err;
928}
929
930static const struct ib_qp_attr mlx4_ib_qp_attr = { .port_num = 1 };
931static const int mlx4_ib_qp_attr_mask_table[IB_QPT_UD + 1] = {
932 [IB_QPT_UD] = (IB_QP_PKEY_INDEX |
933 IB_QP_PORT |
934 IB_QP_QKEY),
935 [IB_QPT_UC] = (IB_QP_PKEY_INDEX |
936 IB_QP_PORT |
937 IB_QP_ACCESS_FLAGS),
938 [IB_QPT_RC] = (IB_QP_PKEY_INDEX |
939 IB_QP_PORT |
940 IB_QP_ACCESS_FLAGS),
941 [IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
942 IB_QP_QKEY),
943 [IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
944 IB_QP_QKEY),
945};
946
947int mlx4_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
948 int attr_mask, struct ib_udata *udata)
949{
950 struct mlx4_ib_dev *dev = to_mdev(ibqp->device);
951 struct mlx4_ib_qp *qp = to_mqp(ibqp);
952 enum ib_qp_state cur_state, new_state;
953 int err = -EINVAL;
954
955 mutex_lock(&qp->mutex);
956
957 cur_state = attr_mask & IB_QP_CUR_STATE ? attr->cur_qp_state : qp->state;
958 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
959
960 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type, attr_mask))
961 goto out;
962
963 if ((attr_mask & IB_QP_PKEY_INDEX) &&
964 attr->pkey_index >= dev->dev->caps.pkey_table_len) {
965 goto out;
966 }
967
968 if ((attr_mask & IB_QP_PORT) &&
969 (attr->port_num == 0 || attr->port_num > dev->dev->caps.num_ports)) {
970 goto out;
971 }
972
973 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC &&
974 attr->max_rd_atomic > dev->dev->caps.max_qp_init_rdma) {
975 goto out;
976 }
977
978 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC &&
979 attr->max_dest_rd_atomic > dev->dev->caps.max_qp_dest_rdma) {
980 goto out;
981 }
982
983 if (cur_state == new_state && cur_state == IB_QPS_RESET) {
984 err = 0;
985 goto out;
986 }
987
988 if (cur_state == IB_QPS_RESET && new_state == IB_QPS_ERR) {
989 err = __mlx4_ib_modify_qp(ibqp, &mlx4_ib_qp_attr,
990 mlx4_ib_qp_attr_mask_table[ibqp->qp_type],
991 IB_QPS_RESET, IB_QPS_INIT);
992 if (err)
993 goto out;
994 cur_state = IB_QPS_INIT;
995 }
996
997 err = __mlx4_ib_modify_qp(ibqp, attr, attr_mask, cur_state, new_state);
998
999out:
1000 mutex_unlock(&qp->mutex);
1001 return err;
1002}
1003
1004static int build_mlx_header(struct mlx4_ib_sqp *sqp, struct ib_send_wr *wr,
1005 void *wqe)
1006{
1007 struct ib_device *ib_dev = &to_mdev(sqp->qp.ibqp.device)->ib_dev;
1008 struct mlx4_wqe_mlx_seg *mlx = wqe;
1009 struct mlx4_wqe_inline_seg *inl = wqe + sizeof *mlx;
1010 struct mlx4_ib_ah *ah = to_mah(wr->wr.ud.ah);
1011 u16 pkey;
1012 int send_size;
1013 int header_size;
1014 int i;
1015
1016 send_size = 0;
1017 for (i = 0; i < wr->num_sge; ++i)
1018 send_size += wr->sg_list[i].length;
1019
1020 ib_ud_header_init(send_size, mlx4_ib_ah_grh_present(ah), &sqp->ud_header);
1021
1022 sqp->ud_header.lrh.service_level =
1023 be32_to_cpu(ah->av.sl_tclass_flowlabel) >> 28;
1024 sqp->ud_header.lrh.destination_lid = ah->av.dlid;
1025 sqp->ud_header.lrh.source_lid = cpu_to_be16(ah->av.g_slid & 0x7f);
1026 if (mlx4_ib_ah_grh_present(ah)) {
1027 sqp->ud_header.grh.traffic_class =
1028 (be32_to_cpu(ah->av.sl_tclass_flowlabel) >> 20) & 0xff;
1029 sqp->ud_header.grh.flow_label =
1030 ah->av.sl_tclass_flowlabel & cpu_to_be32(0xfffff);
1031 sqp->ud_header.grh.hop_limit = ah->av.hop_limit;
1032 ib_get_cached_gid(ib_dev, be32_to_cpu(ah->av.port_pd) >> 24,
1033 ah->av.gid_index, &sqp->ud_header.grh.source_gid);
1034 memcpy(sqp->ud_header.grh.destination_gid.raw,
1035 ah->av.dgid, 16);
1036 }
1037
1038 mlx->flags &= cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE);
1039 mlx->flags |= cpu_to_be32((!sqp->qp.ibqp.qp_num ? MLX4_WQE_MLX_VL15 : 0) |
1040 (sqp->ud_header.lrh.destination_lid ==
1041 IB_LID_PERMISSIVE ? MLX4_WQE_MLX_SLR : 0) |
1042 (sqp->ud_header.lrh.service_level << 8));
1043 mlx->rlid = sqp->ud_header.lrh.destination_lid;
1044
1045 switch (wr->opcode) {
1046 case IB_WR_SEND:
1047 sqp->ud_header.bth.opcode = IB_OPCODE_UD_SEND_ONLY;
1048 sqp->ud_header.immediate_present = 0;
1049 break;
1050 case IB_WR_SEND_WITH_IMM:
1051 sqp->ud_header.bth.opcode = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE;
1052 sqp->ud_header.immediate_present = 1;
1053 sqp->ud_header.immediate_data = wr->imm_data;
1054 break;
1055 default:
1056 return -EINVAL;
1057 }
1058
1059 sqp->ud_header.lrh.virtual_lane = !sqp->qp.ibqp.qp_num ? 15 : 0;
1060 if (sqp->ud_header.lrh.destination_lid == IB_LID_PERMISSIVE)
1061 sqp->ud_header.lrh.source_lid = IB_LID_PERMISSIVE;
1062 sqp->ud_header.bth.solicited_event = !!(wr->send_flags & IB_SEND_SOLICITED);
1063 if (!sqp->qp.ibqp.qp_num)
1064 ib_get_cached_pkey(ib_dev, sqp->qp.port, sqp->pkey_index, &pkey);
1065 else
1066 ib_get_cached_pkey(ib_dev, sqp->qp.port, wr->wr.ud.pkey_index, &pkey);
1067 sqp->ud_header.bth.pkey = cpu_to_be16(pkey);
1068 sqp->ud_header.bth.destination_qpn = cpu_to_be32(wr->wr.ud.remote_qpn);
1069 sqp->ud_header.bth.psn = cpu_to_be32((sqp->send_psn++) & ((1 << 24) - 1));
1070 sqp->ud_header.deth.qkey = cpu_to_be32(wr->wr.ud.remote_qkey & 0x80000000 ?
1071 sqp->qkey : wr->wr.ud.remote_qkey);
1072 sqp->ud_header.deth.source_qpn = cpu_to_be32(sqp->qp.ibqp.qp_num);
1073
1074 header_size = ib_ud_header_pack(&sqp->ud_header, sqp->header_buf);
1075
1076 if (0) {
1077 printk(KERN_ERR "built UD header of size %d:\n", header_size);
1078 for (i = 0; i < header_size / 4; ++i) {
1079 if (i % 8 == 0)
1080 printk(" [%02x] ", i * 4);
1081 printk(" %08x",
1082 be32_to_cpu(((__be32 *) sqp->header_buf)[i]));
1083 if ((i + 1) % 8 == 0)
1084 printk("\n");
1085 }
1086 printk("\n");
1087 }
1088
1089 inl->byte_count = cpu_to_be32(1 << 31 | header_size);
1090 memcpy(inl + 1, sqp->header_buf, header_size);
1091
1092 return ALIGN(sizeof (struct mlx4_wqe_inline_seg) + header_size, 16);
1093}
1094
1095static int mlx4_wq_overflow(struct mlx4_ib_wq *wq, int nreq, struct ib_cq *ib_cq)
1096{
1097 unsigned cur;
1098 struct mlx4_ib_cq *cq;
1099
1100 cur = wq->head - wq->tail;
1101 if (likely(cur + nreq < wq->max))
1102 return 0;
1103
1104 cq = to_mcq(ib_cq);
1105 spin_lock(&cq->lock);
1106 cur = wq->head - wq->tail;
1107 spin_unlock(&cq->lock);
1108
1109 return cur + nreq >= wq->max;
1110}
1111
1112int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr,
1113 struct ib_send_wr **bad_wr)
1114{
1115 struct mlx4_ib_qp *qp = to_mqp(ibqp);
1116 void *wqe;
1117 struct mlx4_wqe_ctrl_seg *ctrl;
1118 unsigned long flags;
1119 int nreq;
1120 int err = 0;
1121 int ind;
1122 int size;
1123 int i;
1124
1125 spin_lock_irqsave(&qp->rq.lock, flags);
1126
1127 ind = qp->sq.head;
1128
1129 for (nreq = 0; wr; ++nreq, wr = wr->next) {
1130 if (mlx4_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq)) {
1131 err = -ENOMEM;
1132 *bad_wr = wr;
1133 goto out;
1134 }
1135
1136 if (unlikely(wr->num_sge > qp->sq.max_gs)) {
1137 err = -EINVAL;
1138 *bad_wr = wr;
1139 goto out;
1140 }
1141
1142 ctrl = wqe = get_send_wqe(qp, ind & (qp->sq.max - 1));
1143 qp->sq.wrid[ind & (qp->sq.max - 1)] = wr->wr_id;
1144
1145 ctrl->srcrb_flags =
1146 (wr->send_flags & IB_SEND_SIGNALED ?
1147 cpu_to_be32(MLX4_WQE_CTRL_CQ_UPDATE) : 0) |
1148 (wr->send_flags & IB_SEND_SOLICITED ?
1149 cpu_to_be32(MLX4_WQE_CTRL_SOLICITED) : 0) |
1150 qp->sq_signal_bits;
1151
1152 if (wr->opcode == IB_WR_SEND_WITH_IMM ||
1153 wr->opcode == IB_WR_RDMA_WRITE_WITH_IMM)
1154 ctrl->imm = wr->imm_data;
1155 else
1156 ctrl->imm = 0;
1157
1158 wqe += sizeof *ctrl;
1159 size = sizeof *ctrl / 16;
1160
1161 switch (ibqp->qp_type) {
1162 case IB_QPT_RC:
1163 case IB_QPT_UC:
1164 switch (wr->opcode) {
1165 case IB_WR_ATOMIC_CMP_AND_SWP:
1166 case IB_WR_ATOMIC_FETCH_AND_ADD:
1167 ((struct mlx4_wqe_raddr_seg *) wqe)->raddr =
1168 cpu_to_be64(wr->wr.atomic.remote_addr);
1169 ((struct mlx4_wqe_raddr_seg *) wqe)->rkey =
1170 cpu_to_be32(wr->wr.atomic.rkey);
1171 ((struct mlx4_wqe_raddr_seg *) wqe)->reserved = 0;
1172
1173 wqe += sizeof (struct mlx4_wqe_raddr_seg);
1174
1175 if (wr->opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
1176 ((struct mlx4_wqe_atomic_seg *) wqe)->swap_add =
1177 cpu_to_be64(wr->wr.atomic.swap);
1178 ((struct mlx4_wqe_atomic_seg *) wqe)->compare =
1179 cpu_to_be64(wr->wr.atomic.compare_add);
1180 } else {
1181 ((struct mlx4_wqe_atomic_seg *) wqe)->swap_add =
1182 cpu_to_be64(wr->wr.atomic.compare_add);
1183 ((struct mlx4_wqe_atomic_seg *) wqe)->compare = 0;
1184 }
1185
1186 wqe += sizeof (struct mlx4_wqe_atomic_seg);
1187 size += (sizeof (struct mlx4_wqe_raddr_seg) +
1188 sizeof (struct mlx4_wqe_atomic_seg)) / 16;
1189
1190 break;
1191
1192 case IB_WR_RDMA_READ:
1193 case IB_WR_RDMA_WRITE:
1194 case IB_WR_RDMA_WRITE_WITH_IMM:
1195 ((struct mlx4_wqe_raddr_seg *) wqe)->raddr =
1196 cpu_to_be64(wr->wr.rdma.remote_addr);
1197 ((struct mlx4_wqe_raddr_seg *) wqe)->rkey =
1198 cpu_to_be32(wr->wr.rdma.rkey);
1199 ((struct mlx4_wqe_raddr_seg *) wqe)->reserved = 0;
1200
1201 wqe += sizeof (struct mlx4_wqe_raddr_seg);
1202 size += sizeof (struct mlx4_wqe_raddr_seg) / 16;
1203
1204 break;
1205
1206 default:
1207 /* No extra segments required for sends */
1208 break;
1209 }
1210 break;
1211
1212 case IB_QPT_UD:
1213 memcpy(((struct mlx4_wqe_datagram_seg *) wqe)->av,
1214 &to_mah(wr->wr.ud.ah)->av, sizeof (struct mlx4_av));
1215 ((struct mlx4_wqe_datagram_seg *) wqe)->dqpn =
1216 cpu_to_be32(wr->wr.ud.remote_qpn);
1217 ((struct mlx4_wqe_datagram_seg *) wqe)->qkey =
1218 cpu_to_be32(wr->wr.ud.remote_qkey);
1219
1220 wqe += sizeof (struct mlx4_wqe_datagram_seg);
1221 size += sizeof (struct mlx4_wqe_datagram_seg) / 16;
1222 break;
1223
1224 case IB_QPT_SMI:
1225 case IB_QPT_GSI:
1226 err = build_mlx_header(to_msqp(qp), wr, ctrl);
1227 if (err < 0) {
1228 *bad_wr = wr;
1229 goto out;
1230 }
1231 wqe += err;
1232 size += err / 16;
1233
1234 err = 0;
1235 break;
1236
1237 default:
1238 break;
1239 }
1240
1241 for (i = 0; i < wr->num_sge; ++i) {
1242 ((struct mlx4_wqe_data_seg *) wqe)->byte_count =
1243 cpu_to_be32(wr->sg_list[i].length);
1244 ((struct mlx4_wqe_data_seg *) wqe)->lkey =
1245 cpu_to_be32(wr->sg_list[i].lkey);
1246 ((struct mlx4_wqe_data_seg *) wqe)->addr =
1247 cpu_to_be64(wr->sg_list[i].addr);
1248
1249 wqe += sizeof (struct mlx4_wqe_data_seg);
1250 size += sizeof (struct mlx4_wqe_data_seg) / 16;
1251 }
1252
1253 /* Add one more inline data segment for ICRC for MLX sends */
1254 if (qp->ibqp.qp_type == IB_QPT_SMI || qp->ibqp.qp_type == IB_QPT_GSI) {
1255 ((struct mlx4_wqe_inline_seg *) wqe)->byte_count =
1256 cpu_to_be32((1 << 31) | 4);
1257 ((u32 *) wqe)[1] = 0;
1258 wqe += sizeof (struct mlx4_wqe_data_seg);
1259 size += sizeof (struct mlx4_wqe_data_seg) / 16;
1260 }
1261
1262 ctrl->fence_size = (wr->send_flags & IB_SEND_FENCE ?
1263 MLX4_WQE_CTRL_FENCE : 0) | size;
1264
1265 /*
1266 * Make sure descriptor is fully written before
1267 * setting ownership bit (because HW can start
1268 * executing as soon as we do).
1269 */
1270 wmb();
1271
1272 if (wr->opcode < 0 || wr->opcode >= ARRAY_SIZE(mlx4_ib_opcode)) {
1273 err = -EINVAL;
1274 goto out;
1275 }
1276
1277 ctrl->owner_opcode = mlx4_ib_opcode[wr->opcode] |
1278 (ind & qp->sq.max ? cpu_to_be32(1 << 31) : 0);
1279
1280 ++ind;
1281 }
1282
1283out:
1284 if (likely(nreq)) {
1285 qp->sq.head += nreq;
1286
1287 /*
1288 * Make sure that descriptors are written before
1289 * doorbell record.
1290 */
1291 wmb();
1292
1293 writel(qp->doorbell_qpn,
1294 to_mdev(ibqp->device)->uar_map + MLX4_SEND_DOORBELL);
1295
1296 /*
1297 * Make sure doorbells don't leak out of SQ spinlock
1298 * and reach the HCA out of order.
1299 */
1300 mmiowb();
1301 }
1302
1303 spin_unlock_irqrestore(&qp->rq.lock, flags);
1304
1305 return err;
1306}
1307
1308int mlx4_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr,
1309 struct ib_recv_wr **bad_wr)
1310{
1311 struct mlx4_ib_qp *qp = to_mqp(ibqp);
1312 struct mlx4_wqe_data_seg *scat;
1313 unsigned long flags;
1314 int err = 0;
1315 int nreq;
1316 int ind;
1317 int i;
1318
1319 spin_lock_irqsave(&qp->rq.lock, flags);
1320
1321 ind = qp->rq.head & (qp->rq.max - 1);
1322
1323 for (nreq = 0; wr; ++nreq, wr = wr->next) {
1324 if (mlx4_wq_overflow(&qp->rq, nreq, qp->ibqp.send_cq)) {
1325 err = -ENOMEM;
1326 *bad_wr = wr;
1327 goto out;
1328 }
1329
1330 if (unlikely(wr->num_sge > qp->rq.max_gs)) {
1331 err = -EINVAL;
1332 *bad_wr = wr;
1333 goto out;
1334 }
1335
1336 scat = get_recv_wqe(qp, ind);
1337
1338 for (i = 0; i < wr->num_sge; ++i) {
1339 scat[i].byte_count = cpu_to_be32(wr->sg_list[i].length);
1340 scat[i].lkey = cpu_to_be32(wr->sg_list[i].lkey);
1341 scat[i].addr = cpu_to_be64(wr->sg_list[i].addr);
1342 }
1343
1344 if (i < qp->rq.max_gs) {
1345 scat[i].byte_count = 0;
1346 scat[i].lkey = cpu_to_be32(MLX4_INVALID_LKEY);
1347 scat[i].addr = 0;
1348 }
1349
1350 qp->rq.wrid[ind] = wr->wr_id;
1351
1352 ind = (ind + 1) & (qp->rq.max - 1);
1353 }
1354
1355out:
1356 if (likely(nreq)) {
1357 qp->rq.head += nreq;
1358
1359 /*
1360 * Make sure that descriptors are written before
1361 * doorbell record.
1362 */
1363 wmb();
1364
1365 *qp->db.db = cpu_to_be32(qp->rq.head & 0xffff);
1366 }
1367
1368 spin_unlock_irqrestore(&qp->rq.lock, flags);
1369
1370 return err;
1371}
diff --git a/drivers/infiniband/hw/mlx4/srq.c b/drivers/infiniband/hw/mlx4/srq.c
new file mode 100644
index 000000000000..12fac1c8989d
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/srq.c
@@ -0,0 +1,340 @@
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/mlx4/qp.h>
34#include <linux/mlx4/srq.h>
35
36#include "mlx4_ib.h"
37#include "user.h"
38
39static void *get_wqe(struct mlx4_ib_srq *srq, int n)
40{
41 int offset = n << srq->msrq.wqe_shift;
42
43 if (srq->buf.nbufs == 1)
44 return srq->buf.u.direct.buf + offset;
45 else
46 return srq->buf.u.page_list[offset >> PAGE_SHIFT].buf +
47 (offset & (PAGE_SIZE - 1));
48}
49
50static void mlx4_ib_srq_event(struct mlx4_srq *srq, enum mlx4_event type)
51{
52 struct ib_event event;
53 struct ib_srq *ibsrq = &to_mibsrq(srq)->ibsrq;
54
55 if (ibsrq->event_handler) {
56 event.device = ibsrq->device;
57 event.element.srq = ibsrq;
58 switch (type) {
59 case MLX4_EVENT_TYPE_SRQ_LIMIT:
60 event.event = IB_EVENT_SRQ_LIMIT_REACHED;
61 break;
62 case MLX4_EVENT_TYPE_SRQ_CATAS_ERROR:
63 event.event = IB_EVENT_SRQ_ERR;
64 break;
65 default:
66 printk(KERN_WARNING "mlx4_ib: Unexpected event type %d "
67 "on SRQ %06x\n", type, srq->srqn);
68 return;
69 }
70
71 ibsrq->event_handler(&event, ibsrq->srq_context);
72 }
73}
74
75struct ib_srq *mlx4_ib_create_srq(struct ib_pd *pd,
76 struct ib_srq_init_attr *init_attr,
77 struct ib_udata *udata)
78{
79 struct mlx4_ib_dev *dev = to_mdev(pd->device);
80 struct mlx4_ib_srq *srq;
81 struct mlx4_wqe_srq_next_seg *next;
82 int desc_size;
83 int buf_size;
84 int err;
85 int i;
86
87 /* Sanity check SRQ size before proceeding */
88 if (init_attr->attr.max_wr >= dev->dev->caps.max_srq_wqes ||
89 init_attr->attr.max_sge > dev->dev->caps.max_srq_sge)
90 return ERR_PTR(-EINVAL);
91
92 srq = kmalloc(sizeof *srq, GFP_KERNEL);
93 if (!srq)
94 return ERR_PTR(-ENOMEM);
95
96 mutex_init(&srq->mutex);
97 spin_lock_init(&srq->lock);
98 srq->msrq.max = roundup_pow_of_two(init_attr->attr.max_wr + 1);
99 srq->msrq.max_gs = init_attr->attr.max_sge;
100
101 desc_size = max(32UL,
102 roundup_pow_of_two(sizeof (struct mlx4_wqe_srq_next_seg) +
103 srq->msrq.max_gs *
104 sizeof (struct mlx4_wqe_data_seg)));
105 srq->msrq.wqe_shift = ilog2(desc_size);
106
107 buf_size = srq->msrq.max * desc_size;
108
109 if (pd->uobject) {
110 struct mlx4_ib_create_srq ucmd;
111
112 if (ib_copy_from_udata(&ucmd, udata, sizeof ucmd)) {
113 err = -EFAULT;
114 goto err_srq;
115 }
116
117 srq->umem = ib_umem_get(pd->uobject->context, ucmd.buf_addr,
118 buf_size, 0);
119 if (IS_ERR(srq->umem)) {
120 err = PTR_ERR(srq->umem);
121 goto err_srq;
122 }
123
124 err = mlx4_mtt_init(dev->dev, ib_umem_page_count(srq->umem),
125 ilog2(srq->umem->page_size), &srq->mtt);
126 if (err)
127 goto err_buf;
128
129 err = mlx4_ib_umem_write_mtt(dev, &srq->mtt, srq->umem);
130 if (err)
131 goto err_mtt;
132
133 err = mlx4_ib_db_map_user(to_mucontext(pd->uobject->context),
134 ucmd.db_addr, &srq->db);
135 if (err)
136 goto err_mtt;
137 } else {
138 err = mlx4_ib_db_alloc(dev, &srq->db, 0);
139 if (err)
140 goto err_srq;
141
142 *srq->db.db = 0;
143
144 if (mlx4_buf_alloc(dev->dev, buf_size, PAGE_SIZE * 2, &srq->buf)) {
145 err = -ENOMEM;
146 goto err_db;
147 }
148
149 srq->head = 0;
150 srq->tail = srq->msrq.max - 1;
151 srq->wqe_ctr = 0;
152
153 for (i = 0; i < srq->msrq.max; ++i) {
154 next = get_wqe(srq, i);
155 next->next_wqe_index =
156 cpu_to_be16((i + 1) & (srq->msrq.max - 1));
157 }
158
159 err = mlx4_mtt_init(dev->dev, srq->buf.npages, srq->buf.page_shift,
160 &srq->mtt);
161 if (err)
162 goto err_buf;
163
164 err = mlx4_buf_write_mtt(dev->dev, &srq->mtt, &srq->buf);
165 if (err)
166 goto err_mtt;
167
168 srq->wrid = kmalloc(srq->msrq.max * sizeof (u64), GFP_KERNEL);
169 if (!srq->wrid) {
170 err = -ENOMEM;
171 goto err_mtt;
172 }
173 }
174
175 err = mlx4_srq_alloc(dev->dev, to_mpd(pd)->pdn, &srq->mtt,
176 srq->db.dma, &srq->msrq);
177 if (err)
178 goto err_wrid;
179
180 srq->msrq.event = mlx4_ib_srq_event;
181
182 if (pd->uobject)
183 if (ib_copy_to_udata(udata, &srq->msrq.srqn, sizeof (__u32))) {
184 err = -EFAULT;
185 goto err_wrid;
186 }
187
188 init_attr->attr.max_wr = srq->msrq.max - 1;
189
190 return &srq->ibsrq;
191
192err_wrid:
193 if (pd->uobject)
194 mlx4_ib_db_unmap_user(to_mucontext(pd->uobject->context), &srq->db);
195 else
196 kfree(srq->wrid);
197
198err_mtt:
199 mlx4_mtt_cleanup(dev->dev, &srq->mtt);
200
201err_buf:
202 if (pd->uobject)
203 ib_umem_release(srq->umem);
204 else
205 mlx4_buf_free(dev->dev, buf_size, &srq->buf);
206
207err_db:
208 if (!pd->uobject)
209 mlx4_ib_db_free(dev, &srq->db);
210
211err_srq:
212 kfree(srq);
213
214 return ERR_PTR(err);
215}
216
217int mlx4_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
218 enum ib_srq_attr_mask attr_mask, struct ib_udata *udata)
219{
220 struct mlx4_ib_dev *dev = to_mdev(ibsrq->device);
221 struct mlx4_ib_srq *srq = to_msrq(ibsrq);
222 int ret;
223
224 /* We don't support resizing SRQs (yet?) */
225 if (attr_mask & IB_SRQ_MAX_WR)
226 return -EINVAL;
227
228 if (attr_mask & IB_SRQ_LIMIT) {
229 if (attr->srq_limit >= srq->msrq.max)
230 return -EINVAL;
231
232 mutex_lock(&srq->mutex);
233 ret = mlx4_srq_arm(dev->dev, &srq->msrq, attr->srq_limit);
234 mutex_unlock(&srq->mutex);
235
236 if (ret)
237 return ret;
238 }
239
240 return 0;
241}
242
243int mlx4_ib_destroy_srq(struct ib_srq *srq)
244{
245 struct mlx4_ib_dev *dev = to_mdev(srq->device);
246 struct mlx4_ib_srq *msrq = to_msrq(srq);
247
248 mlx4_srq_free(dev->dev, &msrq->msrq);
249 mlx4_mtt_cleanup(dev->dev, &msrq->mtt);
250
251 if (srq->uobject) {
252 mlx4_ib_db_unmap_user(to_mucontext(srq->uobject->context), &msrq->db);
253 ib_umem_release(msrq->umem);
254 } else {
255 kfree(msrq->wrid);
256 mlx4_buf_free(dev->dev, msrq->msrq.max << msrq->msrq.wqe_shift,
257 &msrq->buf);
258 mlx4_ib_db_free(dev, &msrq->db);
259 }
260
261 kfree(msrq);
262
263 return 0;
264}
265
266void mlx4_ib_free_srq_wqe(struct mlx4_ib_srq *srq, int wqe_index)
267{
268 struct mlx4_wqe_srq_next_seg *next;
269
270 /* always called with interrupts disabled. */
271 spin_lock(&srq->lock);
272
273 next = get_wqe(srq, srq->tail);
274 next->next_wqe_index = cpu_to_be16(wqe_index);
275 srq->tail = wqe_index;
276
277 spin_unlock(&srq->lock);
278}
279
280int mlx4_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
281 struct ib_recv_wr **bad_wr)
282{
283 struct mlx4_ib_srq *srq = to_msrq(ibsrq);
284 struct mlx4_wqe_srq_next_seg *next;
285 struct mlx4_wqe_data_seg *scat;
286 unsigned long flags;
287 int err = 0;
288 int nreq;
289 int i;
290
291 spin_lock_irqsave(&srq->lock, flags);
292
293 for (nreq = 0; wr; ++nreq, wr = wr->next) {
294 if (unlikely(wr->num_sge > srq->msrq.max_gs)) {
295 err = -EINVAL;
296 *bad_wr = wr;
297 break;
298 }
299
300 if (unlikely(srq->head == srq->tail)) {
301 err = -ENOMEM;
302 *bad_wr = wr;
303 break;
304 }
305
306 srq->wrid[srq->head] = wr->wr_id;
307
308 next = get_wqe(srq, srq->head);
309 srq->head = be16_to_cpu(next->next_wqe_index);
310 scat = (struct mlx4_wqe_data_seg *) (next + 1);
311
312 for (i = 0; i < wr->num_sge; ++i) {
313 scat[i].byte_count = cpu_to_be32(wr->sg_list[i].length);
314 scat[i].lkey = cpu_to_be32(wr->sg_list[i].lkey);
315 scat[i].addr = cpu_to_be64(wr->sg_list[i].addr);
316 }
317
318 if (i < srq->msrq.max_gs) {
319 scat[i].byte_count = 0;
320 scat[i].lkey = cpu_to_be32(MLX4_INVALID_LKEY);
321 scat[i].addr = 0;
322 }
323 }
324
325 if (likely(nreq)) {
326 srq->wqe_ctr += nreq;
327
328 /*
329 * Make sure that descriptors are written before
330 * doorbell record.
331 */
332 wmb();
333
334 *srq->db.db = cpu_to_be32(srq->wqe_ctr);
335 }
336
337 spin_unlock_irqrestore(&srq->lock, flags);
338
339 return err;
340}
diff --git a/drivers/infiniband/hw/mlx4/user.h b/drivers/infiniband/hw/mlx4/user.h
new file mode 100644
index 000000000000..88c72d56368b
--- /dev/null
+++ b/drivers/infiniband/hw/mlx4/user.h
@@ -0,0 +1,95 @@
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#ifndef MLX4_IB_USER_H
34#define MLX4_IB_USER_H
35
36#include <linux/types.h>
37
38/*
39 * Increment this value if any changes that break userspace ABI
40 * compatibility are made.
41 */
42#define MLX4_IB_UVERBS_ABI_VERSION 2
43
44/*
45 * Make sure that all structs defined in this file remain laid out so
46 * that they pack the same way on 32-bit and 64-bit architectures (to
47 * avoid incompatibility between 32-bit userspace and 64-bit kernels).
48 * In particular do not use pointer types -- pass pointers in __u64
49 * instead.
50 */
51
52struct mlx4_ib_alloc_ucontext_resp {
53 __u32 qp_tab_size;
54 __u16 bf_reg_size;
55 __u16 bf_regs_per_page;
56};
57
58struct mlx4_ib_alloc_pd_resp {
59 __u32 pdn;
60 __u32 reserved;
61};
62
63struct mlx4_ib_create_cq {
64 __u64 buf_addr;
65 __u64 db_addr;
66};
67
68struct mlx4_ib_create_cq_resp {
69 __u32 cqn;
70 __u32 reserved;
71};
72
73struct mlx4_ib_resize_cq {
74 __u64 buf_addr;
75};
76
77struct mlx4_ib_create_srq {
78 __u64 buf_addr;
79 __u64 db_addr;
80};
81
82struct mlx4_ib_create_srq_resp {
83 __u32 srqn;
84 __u32 reserved;
85};
86
87struct mlx4_ib_create_qp {
88 __u64 buf_addr;
89 __u64 db_addr;
90 __u8 log_sq_bb_count;
91 __u8 log_sq_stride;
92 __u8 reserved[6];
93};
94
95#endif /* MLX4_IB_USER_H */
diff --git a/drivers/infiniband/hw/mthca/mthca_av.c b/drivers/infiniband/hw/mthca/mthca_av.c
index 27caf3b0648a..4b111a852ff6 100644
--- a/drivers/infiniband/hw/mthca/mthca_av.c
+++ b/drivers/infiniband/hw/mthca/mthca_av.c
@@ -279,6 +279,7 @@ int mthca_read_ah(struct mthca_dev *dev, struct mthca_ah *ah,
279 (be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 20) & 0xff; 279 (be32_to_cpu(ah->av->sl_tclass_flowlabel) >> 20) & 0xff;
280 header->grh.flow_label = 280 header->grh.flow_label =
281 ah->av->sl_tclass_flowlabel & cpu_to_be32(0xfffff); 281 ah->av->sl_tclass_flowlabel & cpu_to_be32(0xfffff);
282 header->grh.hop_limit = ah->av->hop_limit;
282 ib_get_cached_gid(&dev->ib_dev, 283 ib_get_cached_gid(&dev->ib_dev,
283 be32_to_cpu(ah->av->port_pd) >> 24, 284 be32_to_cpu(ah->av->port_pd) >> 24,
284 ah->av->gid_index % dev->limits.gid_table_len, 285 ah->av->gid_index % dev->limits.gid_table_len,
diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
index 71314460b11e..38102520ffb3 100644
--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
@@ -37,6 +37,7 @@
37#include <linux/completion.h> 37#include <linux/completion.h>
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/errno.h> 39#include <linux/errno.h>
40#include <linux/sched.h>
40#include <asm/io.h> 41#include <asm/io.h>
41#include <rdma/ib_mad.h> 42#include <rdma/ib_mad.h>
42 43
diff --git a/drivers/infiniband/hw/mthca/mthca_cq.c b/drivers/infiniband/hw/mthca/mthca_cq.c
index cf0868f6e965..be6e1e03bdab 100644
--- a/drivers/infiniband/hw/mthca/mthca_cq.c
+++ b/drivers/infiniband/hw/mthca/mthca_cq.c
@@ -37,6 +37,7 @@
37 */ 37 */
38 38
39#include <linux/hardirq.h> 39#include <linux/hardirq.h>
40#include <linux/sched.h>
40 41
41#include <asm/io.h> 42#include <asm/io.h>
42 43
@@ -284,7 +285,7 @@ void mthca_cq_clean(struct mthca_dev *dev, struct mthca_cq *cq, u32 qpn,
284{ 285{
285 struct mthca_cqe *cqe; 286 struct mthca_cqe *cqe;
286 u32 prod_index; 287 u32 prod_index;
287 int nfreed = 0; 288 int i, nfreed = 0;
288 289
289 spin_lock_irq(&cq->lock); 290 spin_lock_irq(&cq->lock);
290 291
@@ -321,6 +322,8 @@ void mthca_cq_clean(struct mthca_dev *dev, struct mthca_cq *cq, u32 qpn,
321 } 322 }
322 323
323 if (nfreed) { 324 if (nfreed) {
325 for (i = 0; i < nfreed; ++i)
326 set_cqe_hw(get_cqe(cq, (cq->cons_index + i) & cq->ibcq.cqe));
324 wmb(); 327 wmb();
325 cq->cons_index += nfreed; 328 cq->cons_index += nfreed;
326 update_cons_index(dev, cq, nfreed); 329 update_cons_index(dev, cq, nfreed);
diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
index 773145e29947..aa563e61de65 100644
--- a/drivers/infiniband/hw/mthca/mthca_main.c
+++ b/drivers/infiniband/hw/mthca/mthca_main.c
@@ -1250,12 +1250,14 @@ static void __mthca_remove_one(struct pci_dev *pdev)
1250int __mthca_restart_one(struct pci_dev *pdev) 1250int __mthca_restart_one(struct pci_dev *pdev)
1251{ 1251{
1252 struct mthca_dev *mdev; 1252 struct mthca_dev *mdev;
1253 int hca_type;
1253 1254
1254 mdev = pci_get_drvdata(pdev); 1255 mdev = pci_get_drvdata(pdev);
1255 if (!mdev) 1256 if (!mdev)
1256 return -ENODEV; 1257 return -ENODEV;
1258 hca_type = mdev->hca_type;
1257 __mthca_remove_one(pdev); 1259 __mthca_remove_one(pdev);
1258 return __mthca_init_one(pdev, mdev->hca_type); 1260 return __mthca_init_one(pdev, hca_type);
1259} 1261}
1260 1262
1261static int __devinit mthca_init_one(struct pci_dev *pdev, 1263static int __devinit mthca_init_one(struct pci_dev *pdev,
diff --git a/drivers/infiniband/hw/mthca/mthca_memfree.c b/drivers/infiniband/hw/mthca/mthca_memfree.c
index 48f7c65e9aed..e61f3e626980 100644
--- a/drivers/infiniband/hw/mthca/mthca_memfree.c
+++ b/drivers/infiniband/hw/mthca/mthca_memfree.c
@@ -36,6 +36,7 @@
36 36
37#include <linux/mm.h> 37#include <linux/mm.h>
38#include <linux/scatterlist.h> 38#include <linux/scatterlist.h>
39#include <linux/sched.h>
39 40
40#include <asm/page.h> 41#include <asm/page.h>
41 42
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
index 1c05486c3c68..6bcde1cb9688 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.c
+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
@@ -37,6 +37,7 @@
37 */ 37 */
38 38
39#include <rdma/ib_smi.h> 39#include <rdma/ib_smi.h>
40#include <rdma/ib_umem.h>
40#include <rdma/ib_user_verbs.h> 41#include <rdma/ib_user_verbs.h>
41#include <linux/mm.h> 42#include <linux/mm.h>
42 43
@@ -908,6 +909,8 @@ static struct ib_mr *mthca_get_dma_mr(struct ib_pd *pd, int acc)
908 return ERR_PTR(err); 909 return ERR_PTR(err);
909 } 910 }
910 911
912 mr->umem = NULL;
913
911 return &mr->ibmr; 914 return &mr->ibmr;
912} 915}
913 916
@@ -1003,11 +1006,13 @@ static struct ib_mr *mthca_reg_phys_mr(struct ib_pd *pd,
1003 } 1006 }
1004 1007
1005 kfree(page_list); 1008 kfree(page_list);
1009 mr->umem = NULL;
1010
1006 return &mr->ibmr; 1011 return &mr->ibmr;
1007} 1012}
1008 1013
1009static struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, struct ib_umem *region, 1014static struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
1010 int acc, struct ib_udata *udata) 1015 u64 virt, int acc, struct ib_udata *udata)
1011{ 1016{
1012 struct mthca_dev *dev = to_mdev(pd->device); 1017 struct mthca_dev *dev = to_mdev(pd->device);
1013 struct ib_umem_chunk *chunk; 1018 struct ib_umem_chunk *chunk;
@@ -1018,20 +1023,26 @@ static struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
1018 int err = 0; 1023 int err = 0;
1019 int write_mtt_size; 1024 int write_mtt_size;
1020 1025
1021 shift = ffs(region->page_size) - 1;
1022
1023 mr = kmalloc(sizeof *mr, GFP_KERNEL); 1026 mr = kmalloc(sizeof *mr, GFP_KERNEL);
1024 if (!mr) 1027 if (!mr)
1025 return ERR_PTR(-ENOMEM); 1028 return ERR_PTR(-ENOMEM);
1026 1029
1030 mr->umem = ib_umem_get(pd->uobject->context, start, length, acc);
1031 if (IS_ERR(mr->umem)) {
1032 err = PTR_ERR(mr->umem);
1033 goto err;
1034 }
1035
1036 shift = ffs(mr->umem->page_size) - 1;
1037
1027 n = 0; 1038 n = 0;
1028 list_for_each_entry(chunk, &region->chunk_list, list) 1039 list_for_each_entry(chunk, &mr->umem->chunk_list, list)
1029 n += chunk->nents; 1040 n += chunk->nents;
1030 1041
1031 mr->mtt = mthca_alloc_mtt(dev, n); 1042 mr->mtt = mthca_alloc_mtt(dev, n);
1032 if (IS_ERR(mr->mtt)) { 1043 if (IS_ERR(mr->mtt)) {
1033 err = PTR_ERR(mr->mtt); 1044 err = PTR_ERR(mr->mtt);
1034 goto err; 1045 goto err_umem;
1035 } 1046 }
1036 1047
1037 pages = (u64 *) __get_free_page(GFP_KERNEL); 1048 pages = (u64 *) __get_free_page(GFP_KERNEL);
@@ -1044,12 +1055,12 @@ static struct ib_mr *mthca_reg_user_mr(struct ib_pd *pd, struct ib_umem *region,
1044 1055
1045 write_mtt_size = min(mthca_write_mtt_size(dev), (int) (PAGE_SIZE / sizeof *pages)); 1056 write_mtt_size = min(mthca_write_mtt_size(dev), (int) (PAGE_SIZE / sizeof *pages));
1046 1057
1047 list_for_each_entry(chunk, &region->chunk_list, list) 1058 list_for_each_entry(chunk, &mr->umem->chunk_list, list)
1048 for (j = 0; j < chunk->nmap; ++j) { 1059 for (j = 0; j < chunk->nmap; ++j) {
1049 len = sg_dma_len(&chunk->page_list[j]) >> shift; 1060 len = sg_dma_len(&chunk->page_list[j]) >> shift;
1050 for (k = 0; k < len; ++k) { 1061 for (k = 0; k < len; ++k) {
1051 pages[i++] = sg_dma_address(&chunk->page_list[j]) + 1062 pages[i++] = sg_dma_address(&chunk->page_list[j]) +
1052 region->page_size * k; 1063 mr->umem->page_size * k;
1053 /* 1064 /*
1054 * Be friendly to write_mtt and pass it chunks 1065 * Be friendly to write_mtt and pass it chunks
1055 * of appropriate size. 1066 * of appropriate size.
@@ -1071,8 +1082,8 @@ mtt_done:
1071 if (err) 1082 if (err)
1072 goto err_mtt; 1083 goto err_mtt;
1073 1084
1074 err = mthca_mr_alloc(dev, to_mpd(pd)->pd_num, shift, region->virt_base, 1085 err = mthca_mr_alloc(dev, to_mpd(pd)->pd_num, shift, virt, length,
1075 region->length, convert_access(acc), mr); 1086 convert_access(acc), mr);
1076 1087
1077 if (err) 1088 if (err)
1078 goto err_mtt; 1089 goto err_mtt;
@@ -1082,6 +1093,9 @@ mtt_done:
1082err_mtt: 1093err_mtt:
1083 mthca_free_mtt(dev, mr->mtt); 1094 mthca_free_mtt(dev, mr->mtt);
1084 1095
1096err_umem:
1097 ib_umem_release(mr->umem);
1098
1085err: 1099err:
1086 kfree(mr); 1100 kfree(mr);
1087 return ERR_PTR(err); 1101 return ERR_PTR(err);
@@ -1090,8 +1104,12 @@ err:
1090static int mthca_dereg_mr(struct ib_mr *mr) 1104static int mthca_dereg_mr(struct ib_mr *mr)
1091{ 1105{
1092 struct mthca_mr *mmr = to_mmr(mr); 1106 struct mthca_mr *mmr = to_mmr(mr);
1107
1093 mthca_free_mr(to_mdev(mr->device), mmr); 1108 mthca_free_mr(to_mdev(mr->device), mmr);
1109 if (mmr->umem)
1110 ib_umem_release(mmr->umem);
1094 kfree(mmr); 1111 kfree(mmr);
1112
1095 return 0; 1113 return 0;
1096} 1114}
1097 1115
diff --git a/drivers/infiniband/hw/mthca/mthca_provider.h b/drivers/infiniband/hw/mthca/mthca_provider.h
index 1d266ac2e094..262616c8ebb6 100644
--- a/drivers/infiniband/hw/mthca/mthca_provider.h
+++ b/drivers/infiniband/hw/mthca/mthca_provider.h
@@ -73,6 +73,7 @@ struct mthca_mtt;
73 73
74struct mthca_mr { 74struct mthca_mr {
75 struct ib_mr ibmr; 75 struct ib_mr ibmr;
76 struct ib_umem *umem;
76 struct mthca_mtt *mtt; 77 struct mthca_mtt *mtt;
77}; 78};
78 79
diff --git a/drivers/infiniband/hw/mthca/mthca_qp.c b/drivers/infiniband/hw/mthca/mthca_qp.c
index fee60c852d14..027664979fe2 100644
--- a/drivers/infiniband/hw/mthca/mthca_qp.c
+++ b/drivers/infiniband/hw/mthca/mthca_qp.c
@@ -37,6 +37,7 @@
37 37
38#include <linux/string.h> 38#include <linux/string.h>
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/sched.h>
40 41
41#include <asm/io.h> 42#include <asm/io.h>
42 43
@@ -295,7 +296,7 @@ static int to_mthca_st(int transport)
295 } 296 }
296} 297}
297 298
298static void store_attrs(struct mthca_sqp *sqp, struct ib_qp_attr *attr, 299static void store_attrs(struct mthca_sqp *sqp, const struct ib_qp_attr *attr,
299 int attr_mask) 300 int attr_mask)
300{ 301{
301 if (attr_mask & IB_QP_PKEY_INDEX) 302 if (attr_mask & IB_QP_PKEY_INDEX)
@@ -327,7 +328,7 @@ static void init_port(struct mthca_dev *dev, int port)
327 mthca_warn(dev, "INIT_IB returned status %02x.\n", status); 328 mthca_warn(dev, "INIT_IB returned status %02x.\n", status);
328} 329}
329 330
330static __be32 get_hw_access_flags(struct mthca_qp *qp, struct ib_qp_attr *attr, 331static __be32 get_hw_access_flags(struct mthca_qp *qp, const struct ib_qp_attr *attr,
331 int attr_mask) 332 int attr_mask)
332{ 333{
333 u8 dest_rd_atomic; 334 u8 dest_rd_atomic;
@@ -510,7 +511,7 @@ out:
510 return err; 511 return err;
511} 512}
512 513
513static int mthca_path_set(struct mthca_dev *dev, struct ib_ah_attr *ah, 514static int mthca_path_set(struct mthca_dev *dev, const struct ib_ah_attr *ah,
514 struct mthca_qp_path *path, u8 port) 515 struct mthca_qp_path *path, u8 port)
515{ 516{
516 path->g_mylmc = ah->src_path_bits & 0x7f; 517 path->g_mylmc = ah->src_path_bits & 0x7f;
@@ -538,12 +539,12 @@ static int mthca_path_set(struct mthca_dev *dev, struct ib_ah_attr *ah,
538 return 0; 539 return 0;
539} 540}
540 541
541int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask, 542static int __mthca_modify_qp(struct ib_qp *ibqp,
542 struct ib_udata *udata) 543 const struct ib_qp_attr *attr, int attr_mask,
544 enum ib_qp_state cur_state, enum ib_qp_state new_state)
543{ 545{
544 struct mthca_dev *dev = to_mdev(ibqp->device); 546 struct mthca_dev *dev = to_mdev(ibqp->device);
545 struct mthca_qp *qp = to_mqp(ibqp); 547 struct mthca_qp *qp = to_mqp(ibqp);
546 enum ib_qp_state cur_state, new_state;
547 struct mthca_mailbox *mailbox; 548 struct mthca_mailbox *mailbox;
548 struct mthca_qp_param *qp_param; 549 struct mthca_qp_param *qp_param;
549 struct mthca_qp_context *qp_context; 550 struct mthca_qp_context *qp_context;
@@ -551,60 +552,6 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
551 u8 status; 552 u8 status;
552 int err = -EINVAL; 553 int err = -EINVAL;
553 554
554 mutex_lock(&qp->mutex);
555
556 if (attr_mask & IB_QP_CUR_STATE) {
557 cur_state = attr->cur_qp_state;
558 } else {
559 spin_lock_irq(&qp->sq.lock);
560 spin_lock(&qp->rq.lock);
561 cur_state = qp->state;
562 spin_unlock(&qp->rq.lock);
563 spin_unlock_irq(&qp->sq.lock);
564 }
565
566 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
567
568 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type, attr_mask)) {
569 mthca_dbg(dev, "Bad QP transition (transport %d) "
570 "%d->%d with attr 0x%08x\n",
571 qp->transport, cur_state, new_state,
572 attr_mask);
573 goto out;
574 }
575
576 if (cur_state == new_state && cur_state == IB_QPS_RESET) {
577 err = 0;
578 goto out;
579 }
580
581 if ((attr_mask & IB_QP_PKEY_INDEX) &&
582 attr->pkey_index >= dev->limits.pkey_table_len) {
583 mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n",
584 attr->pkey_index, dev->limits.pkey_table_len-1);
585 goto out;
586 }
587
588 if ((attr_mask & IB_QP_PORT) &&
589 (attr->port_num == 0 || attr->port_num > dev->limits.num_ports)) {
590 mthca_dbg(dev, "Port number (%u) is invalid\n", attr->port_num);
591 goto out;
592 }
593
594 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC &&
595 attr->max_rd_atomic > dev->limits.max_qp_init_rdma) {
596 mthca_dbg(dev, "Max rdma_atomic as initiator %u too large (max is %d)\n",
597 attr->max_rd_atomic, dev->limits.max_qp_init_rdma);
598 goto out;
599 }
600
601 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC &&
602 attr->max_dest_rd_atomic > 1 << dev->qp_table.rdb_shift) {
603 mthca_dbg(dev, "Max rdma_atomic as responder %u too large (max %d)\n",
604 attr->max_dest_rd_atomic, 1 << dev->qp_table.rdb_shift);
605 goto out;
606 }
607
608 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL); 555 mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
609 if (IS_ERR(mailbox)) { 556 if (IS_ERR(mailbox)) {
610 err = PTR_ERR(mailbox); 557 err = PTR_ERR(mailbox);
@@ -891,6 +838,98 @@ int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
891 838
892out_mailbox: 839out_mailbox:
893 mthca_free_mailbox(dev, mailbox); 840 mthca_free_mailbox(dev, mailbox);
841out:
842 return err;
843}
844
845static const struct ib_qp_attr dummy_init_attr = { .port_num = 1 };
846static const int dummy_init_attr_mask[] = {
847 [IB_QPT_UD] = (IB_QP_PKEY_INDEX |
848 IB_QP_PORT |
849 IB_QP_QKEY),
850 [IB_QPT_UC] = (IB_QP_PKEY_INDEX |
851 IB_QP_PORT |
852 IB_QP_ACCESS_FLAGS),
853 [IB_QPT_RC] = (IB_QP_PKEY_INDEX |
854 IB_QP_PORT |
855 IB_QP_ACCESS_FLAGS),
856 [IB_QPT_SMI] = (IB_QP_PKEY_INDEX |
857 IB_QP_QKEY),
858 [IB_QPT_GSI] = (IB_QP_PKEY_INDEX |
859 IB_QP_QKEY),
860};
861
862int mthca_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, int attr_mask,
863 struct ib_udata *udata)
864{
865 struct mthca_dev *dev = to_mdev(ibqp->device);
866 struct mthca_qp *qp = to_mqp(ibqp);
867 enum ib_qp_state cur_state, new_state;
868 int err = -EINVAL;
869
870 mutex_lock(&qp->mutex);
871 if (attr_mask & IB_QP_CUR_STATE) {
872 cur_state = attr->cur_qp_state;
873 } else {
874 spin_lock_irq(&qp->sq.lock);
875 spin_lock(&qp->rq.lock);
876 cur_state = qp->state;
877 spin_unlock(&qp->rq.lock);
878 spin_unlock_irq(&qp->sq.lock);
879 }
880
881 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
882
883 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type, attr_mask)) {
884 mthca_dbg(dev, "Bad QP transition (transport %d) "
885 "%d->%d with attr 0x%08x\n",
886 qp->transport, cur_state, new_state,
887 attr_mask);
888 goto out;
889 }
890
891 if ((attr_mask & IB_QP_PKEY_INDEX) &&
892 attr->pkey_index >= dev->limits.pkey_table_len) {
893 mthca_dbg(dev, "P_Key index (%u) too large. max is %d\n",
894 attr->pkey_index, dev->limits.pkey_table_len-1);
895 goto out;
896 }
897
898 if ((attr_mask & IB_QP_PORT) &&
899 (attr->port_num == 0 || attr->port_num > dev->limits.num_ports)) {
900 mthca_dbg(dev, "Port number (%u) is invalid\n", attr->port_num);
901 goto out;
902 }
903
904 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC &&
905 attr->max_rd_atomic > dev->limits.max_qp_init_rdma) {
906 mthca_dbg(dev, "Max rdma_atomic as initiator %u too large (max is %d)\n",
907 attr->max_rd_atomic, dev->limits.max_qp_init_rdma);
908 goto out;
909 }
910
911 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC &&
912 attr->max_dest_rd_atomic > 1 << dev->qp_table.rdb_shift) {
913 mthca_dbg(dev, "Max rdma_atomic as responder %u too large (max %d)\n",
914 attr->max_dest_rd_atomic, 1 << dev->qp_table.rdb_shift);
915 goto out;
916 }
917
918 if (cur_state == new_state && cur_state == IB_QPS_RESET) {
919 err = 0;
920 goto out;
921 }
922
923 if (cur_state == IB_QPS_RESET && new_state == IB_QPS_ERR) {
924 err = __mthca_modify_qp(ibqp, &dummy_init_attr,
925 dummy_init_attr_mask[ibqp->qp_type],
926 IB_QPS_RESET, IB_QPS_INIT);
927 if (err)
928 goto out;
929 cur_state = IB_QPS_INIT;
930 }
931
932 err = __mthca_modify_qp(ibqp, attr, attr_mask, cur_state, new_state);
894 933
895out: 934out:
896 mutex_unlock(&qp->mutex); 935 mutex_unlock(&qp->mutex);
@@ -1862,6 +1901,7 @@ int mthca_tavor_post_receive(struct ib_qp *ibqp, struct ib_recv_wr *wr,
1862 dev->kar + MTHCA_RECEIVE_DOORBELL, 1901 dev->kar + MTHCA_RECEIVE_DOORBELL,
1863 MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock)); 1902 MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
1864 1903
1904 qp->rq.next_ind = ind;
1865 qp->rq.head += MTHCA_TAVOR_MAX_WQES_PER_RECV_DB; 1905 qp->rq.head += MTHCA_TAVOR_MAX_WQES_PER_RECV_DB;
1866 size0 = 0; 1906 size0 = 0;
1867 } 1907 }
diff --git a/drivers/infiniband/hw/mthca/mthca_srq.c b/drivers/infiniband/hw/mthca/mthca_srq.c
index 61974b0296ca..b8f05a526673 100644
--- a/drivers/infiniband/hw/mthca/mthca_srq.c
+++ b/drivers/infiniband/hw/mthca/mthca_srq.c
@@ -34,6 +34,7 @@
34 34
35#include <linux/slab.h> 35#include <linux/slab.h>
36#include <linux/string.h> 36#include <linux/string.h>
37#include <linux/sched.h>
37 38
38#include <asm/io.h> 39#include <asm/io.h>
39 40
diff --git a/drivers/infiniband/ulp/ipoib/ipoib.h b/drivers/infiniband/ulp/ipoib/ipoib.h
index 87310eeb6df0..a0b3782c7625 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib.h
+++ b/drivers/infiniband/ulp/ipoib/ipoib.h
@@ -132,12 +132,46 @@ struct ipoib_cm_data {
132 __be32 mtu; 132 __be32 mtu;
133}; 133};
134 134
135/*
136 * Quoting 10.3.1 Queue Pair and EE Context States:
137 *
138 * Note, for QPs that are associated with an SRQ, the Consumer should take the
139 * QP through the Error State before invoking a Destroy QP or a Modify QP to the
140 * Reset State. The Consumer may invoke the Destroy QP without first performing
141 * a Modify QP to the Error State and waiting for the Affiliated Asynchronous
142 * Last WQE Reached Event. However, if the Consumer does not wait for the
143 * Affiliated Asynchronous Last WQE Reached Event, then WQE and Data Segment
144 * leakage may occur. Therefore, it is good programming practice to tear down a
145 * QP that is associated with an SRQ by using the following process:
146 *
147 * - Put the QP in the Error State
148 * - Wait for the Affiliated Asynchronous Last WQE Reached Event;
149 * - either:
150 * drain the CQ by invoking the Poll CQ verb and either wait for CQ
151 * to be empty or the number of Poll CQ operations has exceeded
152 * CQ capacity size;
153 * - or
154 * post another WR that completes on the same CQ and wait for this
155 * WR to return as a WC;
156 * - and then invoke a Destroy QP or Reset QP.
157 *
158 * We use the second option and wait for a completion on the
159 * rx_drain_qp before destroying QPs attached to our SRQ.
160 */
161
162enum ipoib_cm_state {
163 IPOIB_CM_RX_LIVE,
164 IPOIB_CM_RX_ERROR, /* Ignored by stale task */
165 IPOIB_CM_RX_FLUSH /* Last WQE Reached event observed */
166};
167
135struct ipoib_cm_rx { 168struct ipoib_cm_rx {
136 struct ib_cm_id *id; 169 struct ib_cm_id *id;
137 struct ib_qp *qp; 170 struct ib_qp *qp;
138 struct list_head list; 171 struct list_head list;
139 struct net_device *dev; 172 struct net_device *dev;
140 unsigned long jiffies; 173 unsigned long jiffies;
174 enum ipoib_cm_state state;
141}; 175};
142 176
143struct ipoib_cm_tx { 177struct ipoib_cm_tx {
@@ -165,10 +199,16 @@ struct ipoib_cm_dev_priv {
165 struct ib_srq *srq; 199 struct ib_srq *srq;
166 struct ipoib_cm_rx_buf *srq_ring; 200 struct ipoib_cm_rx_buf *srq_ring;
167 struct ib_cm_id *id; 201 struct ib_cm_id *id;
168 struct list_head passive_ids; 202 struct ib_qp *rx_drain_qp; /* generates WR described in 10.3.1 */
203 struct list_head passive_ids; /* state: LIVE */
204 struct list_head rx_error_list; /* state: ERROR */
205 struct list_head rx_flush_list; /* state: FLUSH, drain not started */
206 struct list_head rx_drain_list; /* state: FLUSH, drain started */
207 struct list_head rx_reap_list; /* state: FLUSH, drain done */
169 struct work_struct start_task; 208 struct work_struct start_task;
170 struct work_struct reap_task; 209 struct work_struct reap_task;
171 struct work_struct skb_task; 210 struct work_struct skb_task;
211 struct work_struct rx_reap_task;
172 struct delayed_work stale_task; 212 struct delayed_work stale_task;
173 struct sk_buff_head skb_queue; 213 struct sk_buff_head skb_queue;
174 struct list_head start_list; 214 struct list_head start_list;
@@ -201,15 +241,17 @@ struct ipoib_dev_priv {
201 struct list_head multicast_list; 241 struct list_head multicast_list;
202 struct rb_root multicast_tree; 242 struct rb_root multicast_tree;
203 243
204 struct delayed_work pkey_task; 244 struct delayed_work pkey_poll_task;
205 struct delayed_work mcast_task; 245 struct delayed_work mcast_task;
206 struct work_struct flush_task; 246 struct work_struct flush_task;
207 struct work_struct restart_task; 247 struct work_struct restart_task;
208 struct delayed_work ah_reap_task; 248 struct delayed_work ah_reap_task;
249 struct work_struct pkey_event_task;
209 250
210 struct ib_device *ca; 251 struct ib_device *ca;
211 u8 port; 252 u8 port;
212 u16 pkey; 253 u16 pkey;
254 u16 pkey_index;
213 struct ib_pd *pd; 255 struct ib_pd *pd;
214 struct ib_mr *mr; 256 struct ib_mr *mr;
215 struct ib_cq *cq; 257 struct ib_cq *cq;
@@ -333,12 +375,13 @@ struct ipoib_dev_priv *ipoib_intf_alloc(const char *format);
333 375
334int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port); 376int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
335void ipoib_ib_dev_flush(struct work_struct *work); 377void ipoib_ib_dev_flush(struct work_struct *work);
378void ipoib_pkey_event(struct work_struct *work);
336void ipoib_ib_dev_cleanup(struct net_device *dev); 379void ipoib_ib_dev_cleanup(struct net_device *dev);
337 380
338int ipoib_ib_dev_open(struct net_device *dev); 381int ipoib_ib_dev_open(struct net_device *dev);
339int ipoib_ib_dev_up(struct net_device *dev); 382int ipoib_ib_dev_up(struct net_device *dev);
340int ipoib_ib_dev_down(struct net_device *dev, int flush); 383int ipoib_ib_dev_down(struct net_device *dev, int flush);
341int ipoib_ib_dev_stop(struct net_device *dev); 384int ipoib_ib_dev_stop(struct net_device *dev, int flush);
342 385
343int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port); 386int ipoib_dev_init(struct net_device *dev, struct ib_device *ca, int port);
344void ipoib_dev_cleanup(struct net_device *dev); 387void ipoib_dev_cleanup(struct net_device *dev);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_cm.c b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
index 785bc8505f2a..ffec794b7913 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c
@@ -37,6 +37,7 @@
37#include <net/dst.h> 37#include <net/dst.h>
38#include <net/icmp.h> 38#include <net/icmp.h>
39#include <linux/icmpv6.h> 39#include <linux/icmpv6.h>
40#include <linux/delay.h>
40 41
41#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA 42#ifdef CONFIG_INFINIBAND_IPOIB_DEBUG_DATA
42static int data_debug_level; 43static int data_debug_level;
@@ -62,6 +63,16 @@ struct ipoib_cm_id {
62 u32 remote_mtu; 63 u32 remote_mtu;
63}; 64};
64 65
66static struct ib_qp_attr ipoib_cm_err_attr = {
67 .qp_state = IB_QPS_ERR
68};
69
70#define IPOIB_CM_RX_DRAIN_WRID 0x7fffffff
71
72static struct ib_recv_wr ipoib_cm_rx_drain_wr = {
73 .wr_id = IPOIB_CM_RX_DRAIN_WRID
74};
75
65static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id, 76static int ipoib_cm_tx_handler(struct ib_cm_id *cm_id,
66 struct ib_cm_event *event); 77 struct ib_cm_event *event);
67 78
@@ -150,11 +161,44 @@ partial_error:
150 return NULL; 161 return NULL;
151} 162}
152 163
164static void ipoib_cm_start_rx_drain(struct ipoib_dev_priv* priv)
165{
166 struct ib_recv_wr *bad_wr;
167
168 /* rx_drain_qp send queue depth is 1, so
169 * make sure we have at most 1 outstanding WR. */
170 if (list_empty(&priv->cm.rx_flush_list) ||
171 !list_empty(&priv->cm.rx_drain_list))
172 return;
173
174 if (ib_post_recv(priv->cm.rx_drain_qp, &ipoib_cm_rx_drain_wr, &bad_wr))
175 ipoib_warn(priv, "failed to post rx_drain wr\n");
176
177 list_splice_init(&priv->cm.rx_flush_list, &priv->cm.rx_drain_list);
178}
179
180static void ipoib_cm_rx_event_handler(struct ib_event *event, void *ctx)
181{
182 struct ipoib_cm_rx *p = ctx;
183 struct ipoib_dev_priv *priv = netdev_priv(p->dev);
184 unsigned long flags;
185
186 if (event->event != IB_EVENT_QP_LAST_WQE_REACHED)
187 return;
188
189 spin_lock_irqsave(&priv->lock, flags);
190 list_move(&p->list, &priv->cm.rx_flush_list);
191 p->state = IPOIB_CM_RX_FLUSH;
192 ipoib_cm_start_rx_drain(priv);
193 spin_unlock_irqrestore(&priv->lock, flags);
194}
195
153static struct ib_qp *ipoib_cm_create_rx_qp(struct net_device *dev, 196static struct ib_qp *ipoib_cm_create_rx_qp(struct net_device *dev,
154 struct ipoib_cm_rx *p) 197 struct ipoib_cm_rx *p)
155{ 198{
156 struct ipoib_dev_priv *priv = netdev_priv(dev); 199 struct ipoib_dev_priv *priv = netdev_priv(dev);
157 struct ib_qp_init_attr attr = { 200 struct ib_qp_init_attr attr = {
201 .event_handler = ipoib_cm_rx_event_handler,
158 .send_cq = priv->cq, /* does not matter, we never send anything */ 202 .send_cq = priv->cq, /* does not matter, we never send anything */
159 .recv_cq = priv->cq, 203 .recv_cq = priv->cq,
160 .srq = priv->cm.srq, 204 .srq = priv->cm.srq,
@@ -256,11 +300,13 @@ static int ipoib_cm_req_handler(struct ib_cm_id *cm_id, struct ib_cm_event *even
256 300
257 cm_id->context = p; 301 cm_id->context = p;
258 p->jiffies = jiffies; 302 p->jiffies = jiffies;
303 p->state = IPOIB_CM_RX_LIVE;
259 spin_lock_irq(&priv->lock); 304 spin_lock_irq(&priv->lock);
305 if (list_empty(&priv->cm.passive_ids))
306 queue_delayed_work(ipoib_workqueue,
307 &priv->cm.stale_task, IPOIB_CM_RX_DELAY);
260 list_add(&p->list, &priv->cm.passive_ids); 308 list_add(&p->list, &priv->cm.passive_ids);
261 spin_unlock_irq(&priv->lock); 309 spin_unlock_irq(&priv->lock);
262 queue_delayed_work(ipoib_workqueue,
263 &priv->cm.stale_task, IPOIB_CM_RX_DELAY);
264 return 0; 310 return 0;
265 311
266err_rep: 312err_rep:
@@ -276,7 +322,6 @@ static int ipoib_cm_rx_handler(struct ib_cm_id *cm_id,
276{ 322{
277 struct ipoib_cm_rx *p; 323 struct ipoib_cm_rx *p;
278 struct ipoib_dev_priv *priv; 324 struct ipoib_dev_priv *priv;
279 int ret;
280 325
281 switch (event->event) { 326 switch (event->event) {
282 case IB_CM_REQ_RECEIVED: 327 case IB_CM_REQ_RECEIVED:
@@ -288,20 +333,9 @@ static int ipoib_cm_rx_handler(struct ib_cm_id *cm_id,
288 case IB_CM_REJ_RECEIVED: 333 case IB_CM_REJ_RECEIVED:
289 p = cm_id->context; 334 p = cm_id->context;
290 priv = netdev_priv(p->dev); 335 priv = netdev_priv(p->dev);
291 spin_lock_irq(&priv->lock); 336 if (ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE))
292 if (list_empty(&p->list)) 337 ipoib_warn(priv, "unable to move qp to error state\n");
293 ret = 0; /* Connection is going away already. */ 338 /* Fall through */
294 else {
295 list_del_init(&p->list);
296 ret = -ECONNRESET;
297 }
298 spin_unlock_irq(&priv->lock);
299 if (ret) {
300 ib_destroy_qp(p->qp);
301 kfree(p);
302 return ret;
303 }
304 return 0;
305 default: 339 default:
306 return 0; 340 return 0;
307 } 341 }
@@ -353,8 +387,15 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
353 wr_id, wc->status); 387 wr_id, wc->status);
354 388
355 if (unlikely(wr_id >= ipoib_recvq_size)) { 389 if (unlikely(wr_id >= ipoib_recvq_size)) {
356 ipoib_warn(priv, "cm recv completion event with wrid %d (> %d)\n", 390 if (wr_id == (IPOIB_CM_RX_DRAIN_WRID & ~IPOIB_CM_OP_SRQ)) {
357 wr_id, ipoib_recvq_size); 391 spin_lock_irqsave(&priv->lock, flags);
392 list_splice_init(&priv->cm.rx_drain_list, &priv->cm.rx_reap_list);
393 ipoib_cm_start_rx_drain(priv);
394 queue_work(ipoib_workqueue, &priv->cm.rx_reap_task);
395 spin_unlock_irqrestore(&priv->lock, flags);
396 } else
397 ipoib_warn(priv, "cm recv completion event with wrid %d (> %d)\n",
398 wr_id, ipoib_recvq_size);
358 return; 399 return;
359 } 400 }
360 401
@@ -373,13 +414,11 @@ void ipoib_cm_handle_rx_wc(struct net_device *dev, struct ib_wc *wc)
373 if (p && time_after_eq(jiffies, p->jiffies + IPOIB_CM_RX_UPDATE_TIME)) { 414 if (p && time_after_eq(jiffies, p->jiffies + IPOIB_CM_RX_UPDATE_TIME)) {
374 spin_lock_irqsave(&priv->lock, flags); 415 spin_lock_irqsave(&priv->lock, flags);
375 p->jiffies = jiffies; 416 p->jiffies = jiffies;
376 /* Move this entry to list head, but do 417 /* Move this entry to list head, but do not re-add it
377 * not re-add it if it has been removed. */ 418 * if it has been moved out of list. */
378 if (!list_empty(&p->list)) 419 if (p->state == IPOIB_CM_RX_LIVE)
379 list_move(&p->list, &priv->cm.passive_ids); 420 list_move(&p->list, &priv->cm.passive_ids);
380 spin_unlock_irqrestore(&priv->lock, flags); 421 spin_unlock_irqrestore(&priv->lock, flags);
381 queue_delayed_work(ipoib_workqueue,
382 &priv->cm.stale_task, IPOIB_CM_RX_DELAY);
383 } 422 }
384 } 423 }
385 424
@@ -584,17 +623,43 @@ static void ipoib_cm_tx_completion(struct ib_cq *cq, void *tx_ptr)
584int ipoib_cm_dev_open(struct net_device *dev) 623int ipoib_cm_dev_open(struct net_device *dev)
585{ 624{
586 struct ipoib_dev_priv *priv = netdev_priv(dev); 625 struct ipoib_dev_priv *priv = netdev_priv(dev);
626 struct ib_qp_init_attr qp_init_attr = {
627 .send_cq = priv->cq, /* does not matter, we never send anything */
628 .recv_cq = priv->cq,
629 .cap.max_send_wr = 1, /* FIXME: 0 Seems not to work */
630 .cap.max_send_sge = 1, /* FIXME: 0 Seems not to work */
631 .cap.max_recv_wr = 1,
632 .cap.max_recv_sge = 1, /* FIXME: 0 Seems not to work */
633 .sq_sig_type = IB_SIGNAL_ALL_WR,
634 .qp_type = IB_QPT_UC,
635 };
587 int ret; 636 int ret;
588 637
589 if (!IPOIB_CM_SUPPORTED(dev->dev_addr)) 638 if (!IPOIB_CM_SUPPORTED(dev->dev_addr))
590 return 0; 639 return 0;
591 640
641 priv->cm.rx_drain_qp = ib_create_qp(priv->pd, &qp_init_attr);
642 if (IS_ERR(priv->cm.rx_drain_qp)) {
643 printk(KERN_WARNING "%s: failed to create CM ID\n", priv->ca->name);
644 ret = PTR_ERR(priv->cm.rx_drain_qp);
645 return ret;
646 }
647
648 /*
649 * We put the QP in error state directly. This way, a "flush
650 * error" WC will be immediately generated for each WR we post.
651 */
652 ret = ib_modify_qp(priv->cm.rx_drain_qp, &ipoib_cm_err_attr, IB_QP_STATE);
653 if (ret) {
654 ipoib_warn(priv, "failed to modify drain QP to error: %d\n", ret);
655 goto err_qp;
656 }
657
592 priv->cm.id = ib_create_cm_id(priv->ca, ipoib_cm_rx_handler, dev); 658 priv->cm.id = ib_create_cm_id(priv->ca, ipoib_cm_rx_handler, dev);
593 if (IS_ERR(priv->cm.id)) { 659 if (IS_ERR(priv->cm.id)) {
594 printk(KERN_WARNING "%s: failed to create CM ID\n", priv->ca->name); 660 printk(KERN_WARNING "%s: failed to create CM ID\n", priv->ca->name);
595 ret = PTR_ERR(priv->cm.id); 661 ret = PTR_ERR(priv->cm.id);
596 priv->cm.id = NULL; 662 goto err_cm;
597 return ret;
598 } 663 }
599 664
600 ret = ib_cm_listen(priv->cm.id, cpu_to_be64(IPOIB_CM_IETF_ID | priv->qp->qp_num), 665 ret = ib_cm_listen(priv->cm.id, cpu_to_be64(IPOIB_CM_IETF_ID | priv->qp->qp_num),
@@ -602,35 +667,79 @@ int ipoib_cm_dev_open(struct net_device *dev)
602 if (ret) { 667 if (ret) {
603 printk(KERN_WARNING "%s: failed to listen on ID 0x%llx\n", priv->ca->name, 668 printk(KERN_WARNING "%s: failed to listen on ID 0x%llx\n", priv->ca->name,
604 IPOIB_CM_IETF_ID | priv->qp->qp_num); 669 IPOIB_CM_IETF_ID | priv->qp->qp_num);
605 ib_destroy_cm_id(priv->cm.id); 670 goto err_listen;
606 priv->cm.id = NULL;
607 return ret;
608 } 671 }
672
609 return 0; 673 return 0;
674
675err_listen:
676 ib_destroy_cm_id(priv->cm.id);
677err_cm:
678 priv->cm.id = NULL;
679err_qp:
680 ib_destroy_qp(priv->cm.rx_drain_qp);
681 return ret;
610} 682}
611 683
612void ipoib_cm_dev_stop(struct net_device *dev) 684void ipoib_cm_dev_stop(struct net_device *dev)
613{ 685{
614 struct ipoib_dev_priv *priv = netdev_priv(dev); 686 struct ipoib_dev_priv *priv = netdev_priv(dev);
615 struct ipoib_cm_rx *p; 687 struct ipoib_cm_rx *p, *n;
688 unsigned long begin;
689 LIST_HEAD(list);
690 int ret;
616 691
617 if (!IPOIB_CM_SUPPORTED(dev->dev_addr) || !priv->cm.id) 692 if (!IPOIB_CM_SUPPORTED(dev->dev_addr) || !priv->cm.id)
618 return; 693 return;
619 694
620 ib_destroy_cm_id(priv->cm.id); 695 ib_destroy_cm_id(priv->cm.id);
621 priv->cm.id = NULL; 696 priv->cm.id = NULL;
697
622 spin_lock_irq(&priv->lock); 698 spin_lock_irq(&priv->lock);
623 while (!list_empty(&priv->cm.passive_ids)) { 699 while (!list_empty(&priv->cm.passive_ids)) {
624 p = list_entry(priv->cm.passive_ids.next, typeof(*p), list); 700 p = list_entry(priv->cm.passive_ids.next, typeof(*p), list);
625 list_del_init(&p->list); 701 list_move(&p->list, &priv->cm.rx_error_list);
702 p->state = IPOIB_CM_RX_ERROR;
626 spin_unlock_irq(&priv->lock); 703 spin_unlock_irq(&priv->lock);
704 ret = ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE);
705 if (ret)
706 ipoib_warn(priv, "unable to move qp to error state: %d\n", ret);
707 spin_lock_irq(&priv->lock);
708 }
709
710 /* Wait for all RX to be drained */
711 begin = jiffies;
712
713 while (!list_empty(&priv->cm.rx_error_list) ||
714 !list_empty(&priv->cm.rx_flush_list) ||
715 !list_empty(&priv->cm.rx_drain_list)) {
716 if (!time_after(jiffies, begin + 5 * HZ)) {
717 ipoib_warn(priv, "RX drain timing out\n");
718
719 /*
720 * assume the HW is wedged and just free up everything.
721 */
722 list_splice_init(&priv->cm.rx_flush_list, &list);
723 list_splice_init(&priv->cm.rx_error_list, &list);
724 list_splice_init(&priv->cm.rx_drain_list, &list);
725 break;
726 }
727 spin_unlock_irq(&priv->lock);
728 msleep(1);
729 spin_lock_irq(&priv->lock);
730 }
731
732 list_splice_init(&priv->cm.rx_reap_list, &list);
733
734 spin_unlock_irq(&priv->lock);
735
736 list_for_each_entry_safe(p, n, &list, list) {
627 ib_destroy_cm_id(p->id); 737 ib_destroy_cm_id(p->id);
628 ib_destroy_qp(p->qp); 738 ib_destroy_qp(p->qp);
629 kfree(p); 739 kfree(p);
630 spin_lock_irq(&priv->lock);
631 } 740 }
632 spin_unlock_irq(&priv->lock);
633 741
742 ib_destroy_qp(priv->cm.rx_drain_qp);
634 cancel_delayed_work(&priv->cm.stale_task); 743 cancel_delayed_work(&priv->cm.stale_task);
635} 744}
636 745
@@ -1080,26 +1189,50 @@ void ipoib_cm_skb_too_long(struct net_device* dev, struct sk_buff *skb,
1080 queue_work(ipoib_workqueue, &priv->cm.skb_task); 1189 queue_work(ipoib_workqueue, &priv->cm.skb_task);
1081} 1190}
1082 1191
1192static void ipoib_cm_rx_reap(struct work_struct *work)
1193{
1194 struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
1195 cm.rx_reap_task);
1196 struct ipoib_cm_rx *p, *n;
1197 LIST_HEAD(list);
1198
1199 spin_lock_irq(&priv->lock);
1200 list_splice_init(&priv->cm.rx_reap_list, &list);
1201 spin_unlock_irq(&priv->lock);
1202
1203 list_for_each_entry_safe(p, n, &list, list) {
1204 ib_destroy_cm_id(p->id);
1205 ib_destroy_qp(p->qp);
1206 kfree(p);
1207 }
1208}
1209
1083static void ipoib_cm_stale_task(struct work_struct *work) 1210static void ipoib_cm_stale_task(struct work_struct *work)
1084{ 1211{
1085 struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv, 1212 struct ipoib_dev_priv *priv = container_of(work, struct ipoib_dev_priv,
1086 cm.stale_task.work); 1213 cm.stale_task.work);
1087 struct ipoib_cm_rx *p; 1214 struct ipoib_cm_rx *p;
1215 int ret;
1088 1216
1089 spin_lock_irq(&priv->lock); 1217 spin_lock_irq(&priv->lock);
1090 while (!list_empty(&priv->cm.passive_ids)) { 1218 while (!list_empty(&priv->cm.passive_ids)) {
1091 /* List if sorted by LRU, start from tail, 1219 /* List is sorted by LRU, start from tail,
1092 * stop when we see a recently used entry */ 1220 * stop when we see a recently used entry */
1093 p = list_entry(priv->cm.passive_ids.prev, typeof(*p), list); 1221 p = list_entry(priv->cm.passive_ids.prev, typeof(*p), list);
1094 if (time_before_eq(jiffies, p->jiffies + IPOIB_CM_RX_TIMEOUT)) 1222 if (time_before_eq(jiffies, p->jiffies + IPOIB_CM_RX_TIMEOUT))
1095 break; 1223 break;
1096 list_del_init(&p->list); 1224 list_move(&p->list, &priv->cm.rx_error_list);
1225 p->state = IPOIB_CM_RX_ERROR;
1097 spin_unlock_irq(&priv->lock); 1226 spin_unlock_irq(&priv->lock);
1098 ib_destroy_cm_id(p->id); 1227 ret = ib_modify_qp(p->qp, &ipoib_cm_err_attr, IB_QP_STATE);
1099 ib_destroy_qp(p->qp); 1228 if (ret)
1100 kfree(p); 1229 ipoib_warn(priv, "unable to move qp to error state: %d\n", ret);
1101 spin_lock_irq(&priv->lock); 1230 spin_lock_irq(&priv->lock);
1102 } 1231 }
1232
1233 if (!list_empty(&priv->cm.passive_ids))
1234 queue_delayed_work(ipoib_workqueue,
1235 &priv->cm.stale_task, IPOIB_CM_RX_DELAY);
1103 spin_unlock_irq(&priv->lock); 1236 spin_unlock_irq(&priv->lock);
1104} 1237}
1105 1238
@@ -1161,9 +1294,14 @@ int ipoib_cm_dev_init(struct net_device *dev)
1161 INIT_LIST_HEAD(&priv->cm.passive_ids); 1294 INIT_LIST_HEAD(&priv->cm.passive_ids);
1162 INIT_LIST_HEAD(&priv->cm.reap_list); 1295 INIT_LIST_HEAD(&priv->cm.reap_list);
1163 INIT_LIST_HEAD(&priv->cm.start_list); 1296 INIT_LIST_HEAD(&priv->cm.start_list);
1297 INIT_LIST_HEAD(&priv->cm.rx_error_list);
1298 INIT_LIST_HEAD(&priv->cm.rx_flush_list);
1299 INIT_LIST_HEAD(&priv->cm.rx_drain_list);
1300 INIT_LIST_HEAD(&priv->cm.rx_reap_list);
1164 INIT_WORK(&priv->cm.start_task, ipoib_cm_tx_start); 1301 INIT_WORK(&priv->cm.start_task, ipoib_cm_tx_start);
1165 INIT_WORK(&priv->cm.reap_task, ipoib_cm_tx_reap); 1302 INIT_WORK(&priv->cm.reap_task, ipoib_cm_tx_reap);
1166 INIT_WORK(&priv->cm.skb_task, ipoib_cm_skb_reap); 1303 INIT_WORK(&priv->cm.skb_task, ipoib_cm_skb_reap);
1304 INIT_WORK(&priv->cm.rx_reap_task, ipoib_cm_rx_reap);
1167 INIT_DELAYED_WORK(&priv->cm.stale_task, ipoib_cm_stale_task); 1305 INIT_DELAYED_WORK(&priv->cm.stale_task, ipoib_cm_stale_task);
1168 1306
1169 skb_queue_head_init(&priv->cm.skb_queue); 1307 skb_queue_head_init(&priv->cm.skb_queue);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_ib.c b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
index 68d72c6f7ffb..c1aad06eb4e9 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_ib.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_ib.c
@@ -448,6 +448,13 @@ int ipoib_ib_dev_open(struct net_device *dev)
448 struct ipoib_dev_priv *priv = netdev_priv(dev); 448 struct ipoib_dev_priv *priv = netdev_priv(dev);
449 int ret; 449 int ret;
450 450
451 if (ib_find_pkey(priv->ca, priv->port, priv->pkey, &priv->pkey_index)) {
452 ipoib_warn(priv, "P_Key 0x%04x not found\n", priv->pkey);
453 clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
454 return -1;
455 }
456 set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
457
451 ret = ipoib_init_qp(dev); 458 ret = ipoib_init_qp(dev);
452 if (ret) { 459 if (ret) {
453 ipoib_warn(priv, "ipoib_init_qp returned %d\n", ret); 460 ipoib_warn(priv, "ipoib_init_qp returned %d\n", ret);
@@ -457,14 +464,14 @@ int ipoib_ib_dev_open(struct net_device *dev)
457 ret = ipoib_ib_post_receives(dev); 464 ret = ipoib_ib_post_receives(dev);
458 if (ret) { 465 if (ret) {
459 ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret); 466 ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret);
460 ipoib_ib_dev_stop(dev); 467 ipoib_ib_dev_stop(dev, 1);
461 return -1; 468 return -1;
462 } 469 }
463 470
464 ret = ipoib_cm_dev_open(dev); 471 ret = ipoib_cm_dev_open(dev);
465 if (ret) { 472 if (ret) {
466 ipoib_warn(priv, "ipoib_ib_post_receives returned %d\n", ret); 473 ipoib_warn(priv, "ipoib_cm_dev_open returned %d\n", ret);
467 ipoib_ib_dev_stop(dev); 474 ipoib_ib_dev_stop(dev, 1);
468 return -1; 475 return -1;
469 } 476 }
470 477
@@ -516,7 +523,7 @@ int ipoib_ib_dev_down(struct net_device *dev, int flush)
516 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) { 523 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags)) {
517 mutex_lock(&pkey_mutex); 524 mutex_lock(&pkey_mutex);
518 set_bit(IPOIB_PKEY_STOP, &priv->flags); 525 set_bit(IPOIB_PKEY_STOP, &priv->flags);
519 cancel_delayed_work(&priv->pkey_task); 526 cancel_delayed_work(&priv->pkey_poll_task);
520 mutex_unlock(&pkey_mutex); 527 mutex_unlock(&pkey_mutex);
521 if (flush) 528 if (flush)
522 flush_workqueue(ipoib_workqueue); 529 flush_workqueue(ipoib_workqueue);
@@ -543,7 +550,7 @@ static int recvs_pending(struct net_device *dev)
543 return pending; 550 return pending;
544} 551}
545 552
546int ipoib_ib_dev_stop(struct net_device *dev) 553int ipoib_ib_dev_stop(struct net_device *dev, int flush)
547{ 554{
548 struct ipoib_dev_priv *priv = netdev_priv(dev); 555 struct ipoib_dev_priv *priv = netdev_priv(dev);
549 struct ib_qp_attr qp_attr; 556 struct ib_qp_attr qp_attr;
@@ -629,7 +636,8 @@ timeout:
629 /* Wait for all AHs to be reaped */ 636 /* Wait for all AHs to be reaped */
630 set_bit(IPOIB_STOP_REAPER, &priv->flags); 637 set_bit(IPOIB_STOP_REAPER, &priv->flags);
631 cancel_delayed_work(&priv->ah_reap_task); 638 cancel_delayed_work(&priv->ah_reap_task);
632 flush_workqueue(ipoib_workqueue); 639 if (flush)
640 flush_workqueue(ipoib_workqueue);
633 641
634 begin = jiffies; 642 begin = jiffies;
635 643
@@ -673,13 +681,24 @@ int ipoib_ib_dev_init(struct net_device *dev, struct ib_device *ca, int port)
673 return 0; 681 return 0;
674} 682}
675 683
676void ipoib_ib_dev_flush(struct work_struct *work) 684static void __ipoib_ib_dev_flush(struct ipoib_dev_priv *priv, int pkey_event)
677{ 685{
678 struct ipoib_dev_priv *cpriv, *priv = 686 struct ipoib_dev_priv *cpriv;
679 container_of(work, struct ipoib_dev_priv, flush_task);
680 struct net_device *dev = priv->dev; 687 struct net_device *dev = priv->dev;
688 u16 new_index;
689
690 mutex_lock(&priv->vlan_mutex);
681 691
682 if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags) ) { 692 /*
693 * Flush any child interfaces too -- they might be up even if
694 * the parent is down.
695 */
696 list_for_each_entry(cpriv, &priv->child_intfs, list)
697 __ipoib_ib_dev_flush(cpriv, pkey_event);
698
699 mutex_unlock(&priv->vlan_mutex);
700
701 if (!test_bit(IPOIB_FLAG_INITIALIZED, &priv->flags)) {
683 ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n"); 702 ipoib_dbg(priv, "Not flushing - IPOIB_FLAG_INITIALIZED not set.\n");
684 return; 703 return;
685 } 704 }
@@ -689,10 +708,32 @@ void ipoib_ib_dev_flush(struct work_struct *work)
689 return; 708 return;
690 } 709 }
691 710
711 if (pkey_event) {
712 if (ib_find_pkey(priv->ca, priv->port, priv->pkey, &new_index)) {
713 clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
714 ipoib_ib_dev_down(dev, 0);
715 ipoib_pkey_dev_delay_open(dev);
716 return;
717 }
718 set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
719
720 /* restart QP only if P_Key index is changed */
721 if (new_index == priv->pkey_index) {
722 ipoib_dbg(priv, "Not flushing - P_Key index not changed.\n");
723 return;
724 }
725 priv->pkey_index = new_index;
726 }
727
692 ipoib_dbg(priv, "flushing\n"); 728 ipoib_dbg(priv, "flushing\n");
693 729
694 ipoib_ib_dev_down(dev, 0); 730 ipoib_ib_dev_down(dev, 0);
695 731
732 if (pkey_event) {
733 ipoib_ib_dev_stop(dev, 0);
734 ipoib_ib_dev_open(dev);
735 }
736
696 /* 737 /*
697 * The device could have been brought down between the start and when 738 * The device could have been brought down between the start and when
698 * we get here, don't bring it back up if it's not configured up 739 * we get here, don't bring it back up if it's not configured up
@@ -701,14 +742,24 @@ void ipoib_ib_dev_flush(struct work_struct *work)
701 ipoib_ib_dev_up(dev); 742 ipoib_ib_dev_up(dev);
702 ipoib_mcast_restart_task(&priv->restart_task); 743 ipoib_mcast_restart_task(&priv->restart_task);
703 } 744 }
745}
704 746
705 mutex_lock(&priv->vlan_mutex); 747void ipoib_ib_dev_flush(struct work_struct *work)
748{
749 struct ipoib_dev_priv *priv =
750 container_of(work, struct ipoib_dev_priv, flush_task);
706 751
707 /* Flush any child interfaces too */ 752 ipoib_dbg(priv, "Flushing %s\n", priv->dev->name);
708 list_for_each_entry(cpriv, &priv->child_intfs, list) 753 __ipoib_ib_dev_flush(priv, 0);
709 ipoib_ib_dev_flush(&cpriv->flush_task); 754}
710 755
711 mutex_unlock(&priv->vlan_mutex); 756void ipoib_pkey_event(struct work_struct *work)
757{
758 struct ipoib_dev_priv *priv =
759 container_of(work, struct ipoib_dev_priv, pkey_event_task);
760
761 ipoib_dbg(priv, "Flushing %s and restarting its QP\n", priv->dev->name);
762 __ipoib_ib_dev_flush(priv, 1);
712} 763}
713 764
714void ipoib_ib_dev_cleanup(struct net_device *dev) 765void ipoib_ib_dev_cleanup(struct net_device *dev)
@@ -736,7 +787,7 @@ void ipoib_ib_dev_cleanup(struct net_device *dev)
736void ipoib_pkey_poll(struct work_struct *work) 787void ipoib_pkey_poll(struct work_struct *work)
737{ 788{
738 struct ipoib_dev_priv *priv = 789 struct ipoib_dev_priv *priv =
739 container_of(work, struct ipoib_dev_priv, pkey_task.work); 790 container_of(work, struct ipoib_dev_priv, pkey_poll_task.work);
740 struct net_device *dev = priv->dev; 791 struct net_device *dev = priv->dev;
741 792
742 ipoib_pkey_dev_check_presence(dev); 793 ipoib_pkey_dev_check_presence(dev);
@@ -747,7 +798,7 @@ void ipoib_pkey_poll(struct work_struct *work)
747 mutex_lock(&pkey_mutex); 798 mutex_lock(&pkey_mutex);
748 if (!test_bit(IPOIB_PKEY_STOP, &priv->flags)) 799 if (!test_bit(IPOIB_PKEY_STOP, &priv->flags))
749 queue_delayed_work(ipoib_workqueue, 800 queue_delayed_work(ipoib_workqueue,
750 &priv->pkey_task, 801 &priv->pkey_poll_task,
751 HZ); 802 HZ);
752 mutex_unlock(&pkey_mutex); 803 mutex_unlock(&pkey_mutex);
753 } 804 }
@@ -766,7 +817,7 @@ int ipoib_pkey_dev_delay_open(struct net_device *dev)
766 mutex_lock(&pkey_mutex); 817 mutex_lock(&pkey_mutex);
767 clear_bit(IPOIB_PKEY_STOP, &priv->flags); 818 clear_bit(IPOIB_PKEY_STOP, &priv->flags);
768 queue_delayed_work(ipoib_workqueue, 819 queue_delayed_work(ipoib_workqueue,
769 &priv->pkey_task, 820 &priv->pkey_poll_task,
770 HZ); 821 HZ);
771 mutex_unlock(&pkey_mutex); 822 mutex_unlock(&pkey_mutex);
772 return 1; 823 return 1;
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c
index 0a428f2b05c7..894b1dcdf3eb 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_main.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c
@@ -107,7 +107,7 @@ int ipoib_open(struct net_device *dev)
107 return -EINVAL; 107 return -EINVAL;
108 108
109 if (ipoib_ib_dev_up(dev)) { 109 if (ipoib_ib_dev_up(dev)) {
110 ipoib_ib_dev_stop(dev); 110 ipoib_ib_dev_stop(dev, 1);
111 return -EINVAL; 111 return -EINVAL;
112 } 112 }
113 113
@@ -152,7 +152,7 @@ static int ipoib_stop(struct net_device *dev)
152 flush_workqueue(ipoib_workqueue); 152 flush_workqueue(ipoib_workqueue);
153 153
154 ipoib_ib_dev_down(dev, 1); 154 ipoib_ib_dev_down(dev, 1);
155 ipoib_ib_dev_stop(dev); 155 ipoib_ib_dev_stop(dev, 1);
156 156
157 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) { 157 if (!test_bit(IPOIB_FLAG_SUBINTERFACE, &priv->flags)) {
158 struct ipoib_dev_priv *cpriv; 158 struct ipoib_dev_priv *cpriv;
@@ -988,7 +988,8 @@ static void ipoib_setup(struct net_device *dev)
988 INIT_LIST_HEAD(&priv->dead_ahs); 988 INIT_LIST_HEAD(&priv->dead_ahs);
989 INIT_LIST_HEAD(&priv->multicast_list); 989 INIT_LIST_HEAD(&priv->multicast_list);
990 990
991 INIT_DELAYED_WORK(&priv->pkey_task, ipoib_pkey_poll); 991 INIT_DELAYED_WORK(&priv->pkey_poll_task, ipoib_pkey_poll);
992 INIT_WORK(&priv->pkey_event_task, ipoib_pkey_event);
992 INIT_DELAYED_WORK(&priv->mcast_task, ipoib_mcast_join_task); 993 INIT_DELAYED_WORK(&priv->mcast_task, ipoib_mcast_join_task);
993 INIT_WORK(&priv->flush_task, ipoib_ib_dev_flush); 994 INIT_WORK(&priv->flush_task, ipoib_ib_dev_flush);
994 INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task); 995 INIT_WORK(&priv->restart_task, ipoib_mcast_restart_task);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
index 54fbead4de01..aae367057a56 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_multicast.c
@@ -524,7 +524,7 @@ void ipoib_mcast_join_task(struct work_struct *work)
524 return; 524 return;
525 525
526 if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid)) 526 if (ib_query_gid(priv->ca, priv->port, 0, &priv->local_gid))
527 ipoib_warn(priv, "ib_gid_entry_get() failed\n"); 527 ipoib_warn(priv, "ib_query_gid() failed\n");
528 else 528 else
529 memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid)); 529 memcpy(priv->dev->dev_addr + 4, priv->local_gid.raw, sizeof (union ib_gid));
530 530
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
index 5c3c6a43a52b..982eb88e27ec 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_verbs.c
@@ -33,8 +33,6 @@
33 * $Id: ipoib_verbs.c 1349 2004-12-16 21:09:43Z roland $ 33 * $Id: ipoib_verbs.c 1349 2004-12-16 21:09:43Z roland $
34 */ 34 */
35 35
36#include <rdma/ib_cache.h>
37
38#include "ipoib.h" 36#include "ipoib.h"
39 37
40int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid) 38int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
@@ -49,7 +47,7 @@ int ipoib_mcast_attach(struct net_device *dev, u16 mlid, union ib_gid *mgid)
49 if (!qp_attr) 47 if (!qp_attr)
50 goto out; 48 goto out;
51 49
52 if (ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index)) { 50 if (ib_find_pkey(priv->ca, priv->port, priv->pkey, &pkey_index)) {
53 clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags); 51 clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
54 ret = -ENXIO; 52 ret = -ENXIO;
55 goto out; 53 goto out;
@@ -94,26 +92,16 @@ int ipoib_init_qp(struct net_device *dev)
94{ 92{
95 struct ipoib_dev_priv *priv = netdev_priv(dev); 93 struct ipoib_dev_priv *priv = netdev_priv(dev);
96 int ret; 94 int ret;
97 u16 pkey_index;
98 struct ib_qp_attr qp_attr; 95 struct ib_qp_attr qp_attr;
99 int attr_mask; 96 int attr_mask;
100 97
101 /* 98 if (!test_bit(IPOIB_PKEY_ASSIGNED, &priv->flags))
102 * Search through the port P_Key table for the requested pkey value. 99 return -1;
103 * The port has to be assigned to the respective IB partition in
104 * advance.
105 */
106 ret = ib_find_cached_pkey(priv->ca, priv->port, priv->pkey, &pkey_index);
107 if (ret) {
108 clear_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
109 return ret;
110 }
111 set_bit(IPOIB_PKEY_ASSIGNED, &priv->flags);
112 100
113 qp_attr.qp_state = IB_QPS_INIT; 101 qp_attr.qp_state = IB_QPS_INIT;
114 qp_attr.qkey = 0; 102 qp_attr.qkey = 0;
115 qp_attr.port_num = priv->port; 103 qp_attr.port_num = priv->port;
116 qp_attr.pkey_index = pkey_index; 104 qp_attr.pkey_index = priv->pkey_index;
117 attr_mask = 105 attr_mask =
118 IB_QP_QKEY | 106 IB_QP_QKEY |
119 IB_QP_PORT | 107 IB_QP_PORT |
@@ -185,7 +173,7 @@ int ipoib_transport_dev_init(struct net_device *dev, struct ib_device *ca)
185 size = ipoib_sendq_size + ipoib_recvq_size + 1; 173 size = ipoib_sendq_size + ipoib_recvq_size + 1;
186 ret = ipoib_cm_dev_init(dev); 174 ret = ipoib_cm_dev_init(dev);
187 if (!ret) 175 if (!ret)
188 size += ipoib_recvq_size; 176 size += ipoib_recvq_size + 1 /* 1 extra for rx_drain_qp */;
189 177
190 priv->cq = ib_create_cq(priv->ca, ipoib_ib_completion, NULL, dev, size, 0); 178 priv->cq = ib_create_cq(priv->ca, ipoib_ib_completion, NULL, dev, size, 0);
191 if (IS_ERR(priv->cq)) { 179 if (IS_ERR(priv->cq)) {
@@ -259,14 +247,18 @@ void ipoib_event(struct ib_event_handler *handler,
259 struct ipoib_dev_priv *priv = 247 struct ipoib_dev_priv *priv =
260 container_of(handler, struct ipoib_dev_priv, event_handler); 248 container_of(handler, struct ipoib_dev_priv, event_handler);
261 249
262 if ((record->event == IB_EVENT_PORT_ERR || 250 if (record->element.port_num != priv->port)
263 record->event == IB_EVENT_PKEY_CHANGE || 251 return;
264 record->event == IB_EVENT_PORT_ACTIVE || 252
265 record->event == IB_EVENT_LID_CHANGE || 253 if (record->event == IB_EVENT_PORT_ERR ||
266 record->event == IB_EVENT_SM_CHANGE || 254 record->event == IB_EVENT_PORT_ACTIVE ||
267 record->event == IB_EVENT_CLIENT_REREGISTER) && 255 record->event == IB_EVENT_LID_CHANGE ||
268 record->element.port_num == priv->port) { 256 record->event == IB_EVENT_SM_CHANGE ||
257 record->event == IB_EVENT_CLIENT_REREGISTER) {
269 ipoib_dbg(priv, "Port state change event\n"); 258 ipoib_dbg(priv, "Port state change event\n");
270 queue_work(ipoib_workqueue, &priv->flush_task); 259 queue_work(ipoib_workqueue, &priv->flush_task);
260 } else if (record->event == IB_EVENT_PKEY_CHANGE) {
261 ipoib_dbg(priv, "P_Key change event on port:%d\n", priv->port);
262 queue_work(ipoib_workqueue, &priv->pkey_event_task);
271 } 263 }
272} 264}
diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
index 89d6008bb673..3702e2375553 100644
--- a/drivers/infiniband/ulp/iser/iser_verbs.c
+++ b/drivers/infiniband/ulp/iser/iser_verbs.c
@@ -35,7 +35,6 @@
35#include <asm/io.h> 35#include <asm/io.h>
36#include <linux/kernel.h> 36#include <linux/kernel.h>
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/smp_lock.h>
39#include <linux/delay.h> 38#include <linux/delay.h>
40#include <linux/version.h> 39#include <linux/version.h>
41 40
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 0e9b69535ad6..f814fb3a469d 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "Input device support" 5menu "Input device support"
6 depends on !S390
6 7
7config INPUT 8config INPUT
8 tristate "Generic input layer (needed for keyboard, mouse, ...)" if EMBEDDED 9 tristate "Generic input layer (needed for keyboard, mouse, ...)" if EMBEDDED
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index a4c3729d3960..b234729706be 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -18,7 +18,6 @@
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/input.h> 19#include <linux/input.h>
20#include <linux/major.h> 20#include <linux/major.h>
21#include <linux/smp_lock.h>
22#include <linux/device.h> 21#include <linux/device.h>
23#include <linux/compat.h> 22#include <linux/compat.h>
24 23
@@ -337,7 +336,7 @@ static int bits_to_user(unsigned long *bits, unsigned int maxbit,
337 336
338 if (compat) { 337 if (compat) {
339 len = NBITS_COMPAT(maxbit) * sizeof(compat_long_t); 338 len = NBITS_COMPAT(maxbit) * sizeof(compat_long_t);
340 if (len < maxlen) 339 if (len > maxlen)
341 len = maxlen; 340 len = maxlen;
342 341
343 for (i = 0; i < len / sizeof(compat_long_t); i++) 342 for (i = 0; i < len / sizeof(compat_long_t); i++)
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 915e9ab7cab0..ccd8abafcb70 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -11,7 +11,6 @@
11 */ 11 */
12 12
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/smp_lock.h>
15#include <linux/input.h> 14#include <linux/input.h>
16#include <linux/module.h> 15#include <linux/module.h>
17#include <linux/random.h> 16#include <linux/random.h>
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index 9bcc5425049b..06f0541b24da 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -24,7 +24,6 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/poll.h> 25#include <linux/poll.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/smp_lock.h>
28#include <linux/device.h> 27#include <linux/device.h>
29 28
30MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); 29MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index 82f563e24fdb..b0023452ec90 100644
--- a/drivers/input/joystick/Kconfig
+++ b/drivers/input/joystick/Kconfig
@@ -255,6 +255,7 @@ config JOYSTICK_JOYDUMP
255 255
256config JOYSTICK_XPAD 256config JOYSTICK_XPAD
257 tristate "X-Box gamepad support" 257 tristate "X-Box gamepad support"
258 depends on USB_ARCH_HAS_HCD
258 select USB 259 select USB
259 help 260 help
260 Say Y here if you want to use the X-Box pad with your computer. 261 Say Y here if you want to use the X-Box pad with your computer.
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 735723912950..8c8cd95a6989 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -74,7 +74,6 @@
74#include <linux/stat.h> 74#include <linux/stat.h>
75#include <linux/module.h> 75#include <linux/module.h>
76#include <linux/moduleparam.h> 76#include <linux/moduleparam.h>
77#include <linux/smp_lock.h>
78#include <linux/usb/input.h> 77#include <linux/usb/input.h>
79 78
80#define DRIVER_VERSION "v0.0.6" 79#define DRIVER_VERSION "v0.0.6"
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 6013ace94d98..842a7b4d16f8 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -84,6 +84,7 @@ config INPUT_ATLAS_BTNS
84 84
85config INPUT_ATI_REMOTE 85config INPUT_ATI_REMOTE
86 tristate "ATI / X10 USB RF remote control" 86 tristate "ATI / X10 USB RF remote control"
87 depends on USB_ARCH_HAS_HCD
87 select USB 88 select USB
88 help 89 help
89 Say Y here if you want to use an ATI or X10 "Lola" USB remote control. 90 Say Y here if you want to use an ATI or X10 "Lola" USB remote control.
@@ -99,6 +100,7 @@ config INPUT_ATI_REMOTE
99 100
100config INPUT_ATI_REMOTE2 101config INPUT_ATI_REMOTE2
101 tristate "ATI / Philips USB RF remote control" 102 tristate "ATI / Philips USB RF remote control"
103 depends on USB_ARCH_HAS_HCD
102 select USB 104 select USB
103 help 105 help
104 Say Y here if you want to use an ATI or Philips USB RF remote control. 106 Say Y here if you want to use an ATI or Philips USB RF remote control.
@@ -114,6 +116,7 @@ config INPUT_ATI_REMOTE2
114config INPUT_KEYSPAN_REMOTE 116config INPUT_KEYSPAN_REMOTE
115 tristate "Keyspan DMR USB remote control (EXPERIMENTAL)" 117 tristate "Keyspan DMR USB remote control (EXPERIMENTAL)"
116 depends on EXPERIMENTAL 118 depends on EXPERIMENTAL
119 depends on USB_ARCH_HAS_HCD
117 select USB 120 select USB
118 help 121 help
119 Say Y here if you want to use a Keyspan DMR USB remote control. 122 Say Y here if you want to use a Keyspan DMR USB remote control.
@@ -128,6 +131,7 @@ config INPUT_KEYSPAN_REMOTE
128 131
129config INPUT_POWERMATE 132config INPUT_POWERMATE
130 tristate "Griffin PowerMate and Contour Jog support" 133 tristate "Griffin PowerMate and Contour Jog support"
134 depends on USB_ARCH_HAS_HCD
131 select USB 135 select USB
132 help 136 help
133 Say Y here if you want to use Griffin PowerMate or Contour Jog devices. 137 Say Y here if you want to use Griffin PowerMate or Contour Jog devices.
@@ -144,6 +148,7 @@ config INPUT_POWERMATE
144config INPUT_YEALINK 148config INPUT_YEALINK
145 tristate "Yealink usb-p1k voip phone" 149 tristate "Yealink usb-p1k voip phone"
146 depends EXPERIMENTAL 150 depends EXPERIMENTAL
151 depends on USB_ARCH_HAS_HCD
147 select USB 152 select USB
148 help 153 help
149 Say Y here if you want to enable keyboard and LCD functions of the 154 Say Y here if you want to enable keyboard and LCD functions of the
diff --git a/drivers/input/misc/ixp4xx-beeper.c b/drivers/input/misc/ixp4xx-beeper.c
index 3d4b619dadab..e759944041ab 100644
--- a/drivers/input/misc/ixp4xx-beeper.c
+++ b/drivers/input/misc/ixp4xx-beeper.c
@@ -51,7 +51,7 @@ static void ixp4xx_spkr_control(unsigned int pin, unsigned int count)
51 51
52static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 52static int ixp4xx_spkr_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
53{ 53{
54 unsigned int pin = (unsigned int) input_get_drvdata(input_dev); 54 unsigned int pin = (unsigned int) input_get_drvdata(dev);
55 unsigned int count = 0; 55 unsigned int count = 0;
56 56
57 if (type != EV_SND) 57 if (type != EV_SND)
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 2ccc114b3ff6..eb0167e9f0cb 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -111,6 +111,7 @@ config MOUSE_SERIAL
111 111
112config MOUSE_APPLETOUCH 112config MOUSE_APPLETOUCH
113 tristate "Apple USB Touchpad support" 113 tristate "Apple USB Touchpad support"
114 depends on USB_ARCH_HAS_HCD
114 select USB 115 select USB
115 help 116 help
116 Say Y here if you want to use an Apple USB Touchpad. 117 Say Y here if you want to use an Apple USB Touchpad.
diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
index 7678e9876550..8675f9509393 100644
--- a/drivers/input/mousedev.c
+++ b/drivers/input/mousedev.c
@@ -19,7 +19,6 @@
19#include <linux/moduleparam.h> 19#include <linux/moduleparam.h>
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/input.h> 21#include <linux/input.h>
22#include <linux/smp_lock.h>
23#include <linux/random.h> 22#include <linux/random.h>
24#include <linux/major.h> 23#include <linux/major.h>
25#include <linux/device.h> 24#include <linux/device.h>
diff --git a/drivers/input/tablet/Kconfig b/drivers/input/tablet/Kconfig
index 12dfb0eb3262..d371c0bdc0bd 100644
--- a/drivers/input/tablet/Kconfig
+++ b/drivers/input/tablet/Kconfig
@@ -13,6 +13,7 @@ if INPUT_TABLET
13 13
14config TABLET_USB_ACECAD 14config TABLET_USB_ACECAD
15 tristate "Acecad Flair tablet support (USB)" 15 tristate "Acecad Flair tablet support (USB)"
16 depends on USB_ARCH_HAS_HCD
16 select USB 17 select USB
17 help 18 help
18 Say Y here if you want to use the USB version of the Acecad Flair 19 Say Y here if you want to use the USB version of the Acecad Flair
@@ -25,6 +26,7 @@ config TABLET_USB_ACECAD
25 26
26config TABLET_USB_AIPTEK 27config TABLET_USB_AIPTEK
27 tristate "Aiptek 6000U/8000U tablet support (USB)" 28 tristate "Aiptek 6000U/8000U tablet support (USB)"
29 depends on USB_ARCH_HAS_HCD
28 select USB 30 select USB
29 help 31 help
30 Say Y here if you want to use the USB version of the Aiptek 6000U 32 Say Y here if you want to use the USB version of the Aiptek 6000U
@@ -49,6 +51,7 @@ config TABLET_USB_GTCO
49 51
50config TABLET_USB_KBTAB 52config TABLET_USB_KBTAB
51 tristate "KB Gear JamStudio tablet support (USB)" 53 tristate "KB Gear JamStudio tablet support (USB)"
54 depends on USB_ARCH_HAS_HCD
52 select USB 55 select USB
53 help 56 help
54 Say Y here if you want to use the USB version of the KB Gear 57 Say Y here if you want to use the USB version of the KB Gear
@@ -61,6 +64,7 @@ config TABLET_USB_KBTAB
61 64
62config TABLET_USB_WACOM 65config TABLET_USB_WACOM
63 tristate "Wacom Intuos/Graphire tablet support (USB)" 66 tristate "Wacom Intuos/Graphire tablet support (USB)"
67 depends on USB_ARCH_HAS_HCD
64 select USB 68 select USB
65 help 69 help
66 Say Y here if you want to use the USB version of the Wacom Intuos 70 Say Y here if you want to use the USB version of the Wacom Intuos
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index c0b36cc5ff0a..e5cca9bd0406 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -166,6 +166,7 @@ config TOUCHSCREEN_UCB1400
166 166
167config TOUCHSCREEN_USB_COMPOSITE 167config TOUCHSCREEN_USB_COMPOSITE
168 tristate "USB Touchscreen Driver" 168 tristate "USB Touchscreen Driver"
169 depends on USB_ARCH_HAS_HCD
169 select USB 170 select USB
170 help 171 help
171 USB Touchscreen driver for: 172 USB Touchscreen driver for:
diff --git a/drivers/input/touchscreen/hp680_ts_input.c b/drivers/input/touchscreen/hp680_ts_input.c
index 61c15024c2a0..1a15475aedfc 100644
--- a/drivers/input/touchscreen/hp680_ts_input.c
+++ b/drivers/input/touchscreen/hp680_ts_input.c
@@ -1,7 +1,6 @@
1#include <linux/input.h> 1#include <linux/input.h>
2#include <linux/module.h> 2#include <linux/module.h>
3#include <linux/init.h> 3#include <linux/init.h>
4
5#include <linux/interrupt.h> 4#include <linux/interrupt.h>
6#include <asm/io.h> 5#include <asm/io.h>
7#include <asm/delay.h> 6#include <asm/delay.h>
@@ -18,12 +17,12 @@
18#define PHDR 0xa400012e 17#define PHDR 0xa400012e
19#define SCPDR 0xa4000136 18#define SCPDR 0xa4000136
20 19
21static void do_softint(void *data); 20static void do_softint(struct work_struct *work);
22 21
23static struct input_dev *hp680_ts_dev; 22static struct input_dev *hp680_ts_dev;
24static DECLARE_WORK(work, do_softint); 23static DECLARE_DELAYED_WORK(work, do_softint);
25 24
26static void do_softint(void *data) 25static void do_softint(struct work_struct *work)
27{ 26{
28 int absx = 0, absy = 0; 27 int absx = 0, absy = 0;
29 u8 scpdr; 28 u8 scpdr;
diff --git a/drivers/input/tsdev.c b/drivers/input/tsdev.c
index 5e5b5c91d75b..8238b13874c2 100644
--- a/drivers/input/tsdev.c
+++ b/drivers/input/tsdev.c
@@ -48,7 +48,6 @@
48#include <linux/init.h> 48#include <linux/init.h>
49#include <linux/input.h> 49#include <linux/input.h>
50#include <linux/major.h> 50#include <linux/major.h>
51#include <linux/smp_lock.h>
52#include <linux/random.h> 51#include <linux/random.h>
53#include <linux/time.h> 52#include <linux/time.h>
54#include <linux/device.h> 53#include <linux/device.h>
diff --git a/drivers/isdn/Kconfig b/drivers/isdn/Kconfig
index c90afeea54aa..d42fe89cddf6 100644
--- a/drivers/isdn/Kconfig
+++ b/drivers/isdn/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "ISDN subsystem" 5menu "ISDN subsystem"
6 depends on !S390
6 7
7config ISDN 8config ISDN
8 tristate "ISDN support" 9 tristate "ISDN support"
diff --git a/drivers/isdn/capi/Kconfig b/drivers/isdn/capi/Kconfig
index c921d6c522f5..c92f9d764fce 100644
--- a/drivers/isdn/capi/Kconfig
+++ b/drivers/isdn/capi/Kconfig
@@ -17,7 +17,7 @@ config CAPI_TRACE
17 help 17 help
18 If you say Y here, the kernelcapi driver can make verbose traces 18 If you say Y here, the kernelcapi driver can make verbose traces
19 of CAPI messages. This feature can be enabled/disabled via IOCTL for 19 of CAPI messages. This feature can be enabled/disabled via IOCTL for
20 every controler (default disabled). 20 every controller (default disabled).
21 This will increase the size of the kernelcapi module by 20 KB. 21 This will increase the size of the kernelcapi module by 20 KB.
22 If unsure, say Y. 22 If unsure, say Y.
23 23
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index db1260f73f10..81661b8bd3a8 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -18,8 +18,8 @@
18#include <linux/fcntl.h> 18#include <linux/fcntl.h>
19#include <linux/fs.h> 19#include <linux/fs.h>
20#include <linux/signal.h> 20#include <linux/signal.h>
21#include <linux/mutex.h>
21#include <linux/mm.h> 22#include <linux/mm.h>
22#include <linux/smp_lock.h>
23#include <linux/timer.h> 23#include <linux/timer.h>
24#include <linux/wait.h> 24#include <linux/wait.h>
25#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE 25#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
@@ -147,7 +147,7 @@ struct capidev {
147 147
148 struct capincci *nccis; 148 struct capincci *nccis;
149 149
150 struct semaphore ncci_list_sem; 150 struct mutex ncci_list_mtx;
151}; 151};
152 152
153/* -------- global variables ---------------------------------------- */ 153/* -------- global variables ---------------------------------------- */
@@ -395,7 +395,7 @@ static struct capidev *capidev_alloc(void)
395 if (!cdev) 395 if (!cdev)
396 return NULL; 396 return NULL;
397 397
398 init_MUTEX(&cdev->ncci_list_sem); 398 mutex_init(&cdev->ncci_list_mtx);
399 skb_queue_head_init(&cdev->recvqueue); 399 skb_queue_head_init(&cdev->recvqueue);
400 init_waitqueue_head(&cdev->recvwait); 400 init_waitqueue_head(&cdev->recvwait);
401 write_lock_irqsave(&capidev_list_lock, flags); 401 write_lock_irqsave(&capidev_list_lock, flags);
@@ -414,9 +414,9 @@ static void capidev_free(struct capidev *cdev)
414 } 414 }
415 skb_queue_purge(&cdev->recvqueue); 415 skb_queue_purge(&cdev->recvqueue);
416 416
417 down(&cdev->ncci_list_sem); 417 mutex_lock(&cdev->ncci_list_mtx);
418 capincci_free(cdev, 0xffffffff); 418 capincci_free(cdev, 0xffffffff);
419 up(&cdev->ncci_list_sem); 419 mutex_unlock(&cdev->ncci_list_mtx);
420 420
421 write_lock_irqsave(&capidev_list_lock, flags); 421 write_lock_irqsave(&capidev_list_lock, flags);
422 list_del(&cdev->list); 422 list_del(&cdev->list);
@@ -603,15 +603,15 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
603 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) { 603 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) {
604 u16 info = CAPIMSG_U16(skb->data, 12); // Info field 604 u16 info = CAPIMSG_U16(skb->data, 12); // Info field
605 if (info == 0) { 605 if (info == 0) {
606 down(&cdev->ncci_list_sem); 606 mutex_lock(&cdev->ncci_list_mtx);
607 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); 607 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
608 up(&cdev->ncci_list_sem); 608 mutex_unlock(&cdev->ncci_list_mtx);
609 } 609 }
610 } 610 }
611 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) { 611 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_IND) {
612 down(&cdev->ncci_list_sem); 612 mutex_lock(&cdev->ncci_list_mtx);
613 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); 613 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
614 up(&cdev->ncci_list_sem); 614 mutex_unlock(&cdev->ncci_list_mtx);
615 } 615 }
616 spin_lock_irqsave(&workaround_lock, flags); 616 spin_lock_irqsave(&workaround_lock, flags);
617 if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) { 617 if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) {
@@ -752,9 +752,9 @@ capi_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos
752 CAPIMSG_SETAPPID(skb->data, cdev->ap.applid); 752 CAPIMSG_SETAPPID(skb->data, cdev->ap.applid);
753 753
754 if (CAPIMSG_CMD(skb->data) == CAPI_DISCONNECT_B3_RESP) { 754 if (CAPIMSG_CMD(skb->data) == CAPI_DISCONNECT_B3_RESP) {
755 down(&cdev->ncci_list_sem); 755 mutex_lock(&cdev->ncci_list_mtx);
756 capincci_free(cdev, CAPIMSG_NCCI(skb->data)); 756 capincci_free(cdev, CAPIMSG_NCCI(skb->data));
757 up(&cdev->ncci_list_sem); 757 mutex_unlock(&cdev->ncci_list_mtx);
758 } 758 }
759 759
760 cdev->errcode = capi20_put_message(&cdev->ap, skb); 760 cdev->errcode = capi20_put_message(&cdev->ap, skb);
@@ -939,9 +939,9 @@ capi_ioctl(struct inode *inode, struct file *file,
939 if (copy_from_user(&ncci, argp, sizeof(ncci))) 939 if (copy_from_user(&ncci, argp, sizeof(ncci)))
940 return -EFAULT; 940 return -EFAULT;
941 941
942 down(&cdev->ncci_list_sem); 942 mutex_lock(&cdev->ncci_list_mtx);
943 if ((nccip = capincci_find(cdev, (u32) ncci)) == 0) { 943 if ((nccip = capincci_find(cdev, (u32) ncci)) == 0) {
944 up(&cdev->ncci_list_sem); 944 mutex_unlock(&cdev->ncci_list_mtx);
945 return 0; 945 return 0;
946 } 946 }
947#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE 947#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
@@ -949,7 +949,7 @@ capi_ioctl(struct inode *inode, struct file *file,
949 count += atomic_read(&mp->ttyopencount); 949 count += atomic_read(&mp->ttyopencount);
950 } 950 }
951#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ 951#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
952 up(&cdev->ncci_list_sem); 952 mutex_unlock(&cdev->ncci_list_mtx);
953 return count; 953 return count;
954 } 954 }
955 return 0; 955 return 0;
@@ -964,14 +964,14 @@ capi_ioctl(struct inode *inode, struct file *file,
964 if (copy_from_user(&ncci, argp, 964 if (copy_from_user(&ncci, argp,
965 sizeof(ncci))) 965 sizeof(ncci)))
966 return -EFAULT; 966 return -EFAULT;
967 down(&cdev->ncci_list_sem); 967 mutex_lock(&cdev->ncci_list_mtx);
968 nccip = capincci_find(cdev, (u32) ncci); 968 nccip = capincci_find(cdev, (u32) ncci);
969 if (!nccip || (mp = nccip->minorp) == 0) { 969 if (!nccip || (mp = nccip->minorp) == 0) {
970 up(&cdev->ncci_list_sem); 970 mutex_unlock(&cdev->ncci_list_mtx);
971 return -ESRCH; 971 return -ESRCH;
972 } 972 }
973 unit = mp->minor; 973 unit = mp->minor;
974 up(&cdev->ncci_list_sem); 974 mutex_unlock(&cdev->ncci_list_mtx);
975 return unit; 975 return unit;
976 } 976 }
977 return 0; 977 return 0;
diff --git a/drivers/isdn/capi/capiutil.c b/drivers/isdn/capi/capiutil.c
index ad1e2702c2d1..22379b94e88f 100644
--- a/drivers/isdn/capi/capiutil.c
+++ b/drivers/isdn/capi/capiutil.c
@@ -855,7 +855,7 @@ static _cdebbuf *g_debbuf;
855static u_long g_debbuf_lock; 855static u_long g_debbuf_lock;
856static _cmsg *g_cmsg; 856static _cmsg *g_cmsg;
857 857
858_cdebbuf *cdebbuf_alloc(void) 858static _cdebbuf *cdebbuf_alloc(void)
859{ 859{
860 _cdebbuf *cdb; 860 _cdebbuf *cdb;
861 861
@@ -989,11 +989,6 @@ _cdebbuf *capi_cmsg2str(_cmsg * cmsg)
989 return &g_debbuf; 989 return &g_debbuf;
990} 990}
991 991
992_cdebbuf *cdebbuf_alloc(void)
993{
994 return &g_debbuf;
995}
996
997void cdebbuf_free(_cdebbuf *cdb) 992void cdebbuf_free(_cdebbuf *cdb)
998{ 993{
999} 994}
@@ -1009,7 +1004,6 @@ void __exit cdebug_exit(void)
1009 1004
1010#endif 1005#endif
1011 1006
1012EXPORT_SYMBOL(cdebbuf_alloc);
1013EXPORT_SYMBOL(cdebbuf_free); 1007EXPORT_SYMBOL(cdebbuf_free);
1014EXPORT_SYMBOL(capi_cmsg2message); 1008EXPORT_SYMBOL(capi_cmsg2message);
1015EXPORT_SYMBOL(capi_message2cmsg); 1009EXPORT_SYMBOL(capi_message2cmsg);
diff --git a/drivers/isdn/divert/divert_procfs.c b/drivers/isdn/divert/divert_procfs.c
index 53a189003355..be77ee625bb7 100644
--- a/drivers/isdn/divert/divert_procfs.c
+++ b/drivers/isdn/divert/divert_procfs.c
@@ -11,7 +11,6 @@
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/poll.h> 13#include <linux/poll.h>
14#include <linux/smp_lock.h>
15#ifdef CONFIG_PROC_FS 14#ifdef CONFIG_PROC_FS
16#include <linux/proc_fs.h> 15#include <linux/proc_fs.h>
17#else 16#else
diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
index c8e1c357cec8..a1263019df5e 100644
--- a/drivers/isdn/gigaset/usb-gigaset.c
+++ b/drivers/isdn/gigaset/usb-gigaset.c
@@ -138,8 +138,6 @@ struct usb_cardstate {
138 char bchars[6]; /* for request 0x19 */ 138 char bchars[6]; /* for request 0x19 */
139}; 139};
140 140
141struct usb_bc_state {};
142
143static inline unsigned tiocm_to_gigaset(unsigned state) 141static inline unsigned tiocm_to_gigaset(unsigned state)
144{ 142{
145 return ((state & TIOCM_DTR) ? 1 : 0) | ((state & TIOCM_RTS) ? 2 : 0); 143 return ((state & TIOCM_DTR) ? 1 : 0) | ((state & TIOCM_RTS) ? 2 : 0);
@@ -579,25 +577,21 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
579 577
580static int gigaset_freebcshw(struct bc_state *bcs) 578static int gigaset_freebcshw(struct bc_state *bcs)
581{ 579{
582 if (!bcs->hw.usb) 580 /* unused */
583 return 0;
584 //FIXME
585 kfree(bcs->hw.usb);
586 return 1; 581 return 1;
587} 582}
588 583
589/* Initialize the b-channel structure */ 584/* Initialize the b-channel structure */
590static int gigaset_initbcshw(struct bc_state *bcs) 585static int gigaset_initbcshw(struct bc_state *bcs)
591{ 586{
592 bcs->hw.usb = kmalloc(sizeof(struct usb_bc_state), GFP_KERNEL); 587 /* unused */
593 if (!bcs->hw.usb) 588 bcs->hw.usb = NULL;
594 return 0;
595
596 return 1; 589 return 1;
597} 590}
598 591
599static void gigaset_reinitbcshw(struct bc_state *bcs) 592static void gigaset_reinitbcshw(struct bc_state *bcs)
600{ 593{
594 /* nothing to do for M10x */
601} 595}
602 596
603static void gigaset_freecshw(struct cardstate *cs) 597static void gigaset_freecshw(struct cardstate *cs)
diff --git a/drivers/isdn/hardware/eicon/capimain.c b/drivers/isdn/hardware/eicon/capimain.c
index 7a74ed35b1bf..98fcdfc7ca55 100644
--- a/drivers/isdn/hardware/eicon/capimain.c
+++ b/drivers/isdn/hardware/eicon/capimain.c
@@ -13,7 +13,6 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <asm/uaccess.h> 15#include <asm/uaccess.h>
16#include <linux/smp_lock.h>
17#include <linux/skbuff.h> 16#include <linux/skbuff.h>
18 17
19#include "os_capi.h" 18#include "os_capi.h"
diff --git a/drivers/isdn/hardware/eicon/dbgioctl.h b/drivers/isdn/hardware/eicon/dbgioctl.h
deleted file mode 100644
index 0fb6f5e88b60..000000000000
--- a/drivers/isdn/hardware/eicon/dbgioctl.h
+++ /dev/null
@@ -1,198 +0,0 @@
1
2/*
3 *
4 Copyright (c) Eicon Technology Corporation, 2000.
5 *
6 This source file is supplied for the use with Eicon
7 Technology Corporation's range of DIVA Server Adapters.
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 OF ANY KIND WHATSOEVER INCLUDING ANY
16 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 See the 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 */
24/*------------------------------------------------------------------*/
25/* file: dbgioctl.h */
26/*------------------------------------------------------------------*/
27
28#if !defined(__DBGIOCTL_H__)
29
30#define __DBGIOCTL_H__
31
32#ifdef NOT_YET_NEEDED
33/*
34 * The requested operation is passed in arg0 of DbgIoctlArgs,
35 * additional arguments (if any) in arg1, arg2 and arg3.
36 */
37
38typedef struct
39{ ULONG arg0 ;
40 ULONG arg1 ;
41 ULONG arg2 ;
42 ULONG arg3 ;
43} DbgIoctlArgs ;
44
45#define DBG_COPY_LOGS 0 /* copy debugs to user until buffer full */
46 /* arg1: size threshold */
47 /* arg2: timeout in milliseconds */
48
49#define DBG_FLUSH_LOGS 1 /* flush pending debugs to user buffer */
50 /* arg1: internal driver id */
51
52#define DBG_LIST_DRVS 2 /* return the list of registered drivers */
53
54#define DBG_GET_MASK 3 /* get current debug mask of driver */
55 /* arg1: internal driver id */
56
57#define DBG_SET_MASK 4 /* set/change debug mask of driver */
58 /* arg1: internal driver id */
59 /* arg2: new debug mask */
60
61#define DBG_GET_BUFSIZE 5 /* get current buffer size of driver */
62 /* arg1: internal driver id */
63 /* arg2: new debug mask */
64
65#define DBG_SET_BUFSIZE 6 /* set new buffer size of driver */
66 /* arg1: new buffer size */
67
68/*
69 * common internal debug message structure
70 */
71
72typedef struct
73{ unsigned short id ; /* virtual driver id */
74 unsigned short type ; /* special message type */
75 unsigned long seq ; /* sequence number of message */
76 unsigned long size ; /* size of message in bytes */
77 unsigned long next ; /* offset to next buffered message */
78 LARGE_INTEGER NTtime ; /* 100 ns since 1.1.1601 */
79 unsigned char data[4] ;/* message data */
80} OldDbgMessage ;
81
82typedef struct
83{ LARGE_INTEGER NTtime ; /* 100 ns since 1.1.1601 */
84 unsigned short size ; /* size of message in bytes */
85 unsigned short ffff ; /* always 0xffff to indicate new msg */
86 unsigned short id ; /* virtual driver id */
87 unsigned short type ; /* special message type */
88 unsigned long seq ; /* sequence number of message */
89 unsigned char data[4] ;/* message data */
90} DbgMessage ;
91
92#endif
93
94#define DRV_ID_UNKNOWN 0x0C /* for messages via prtComp() */
95
96#define MSG_PROC_FLAG 0x80
97#define MSG_PROC_NO_GET(x) (((x) & MSG_PROC_FLAG) ? (((x) >> 4) & 7) : -1)
98#define MSG_PROC_NO_SET(x) (MSG_PROC_FLAG | (((x) & 7) << 4))
99
100#define MSG_TYPE_DRV_ID 0x0001
101#define MSG_TYPE_FLAGS 0x0002
102#define MSG_TYPE_STRING 0x0003
103#define MSG_TYPE_BINARY 0x0004
104
105#define MSG_HEAD_SIZE ((unsigned long)&(((DbgMessage *)0)->data[0]))
106#define MSG_ALIGN(len) (((unsigned long)(len) + MSG_HEAD_SIZE + 3) & ~3)
107#define MSG_SIZE(pMsg) MSG_ALIGN((pMsg)->size)
108#define MSG_NEXT(pMsg) ((DbgMessage *)( ((char *)(pMsg)) + MSG_SIZE(pMsg) ))
109
110#define OLD_MSG_HEAD_SIZE ((unsigned long)&(((OldDbgMessage *)0)->data[0]))
111#define OLD_MSG_ALIGN(len) (((unsigned long)(len)+OLD_MSG_HEAD_SIZE+3) & ~3)
112
113/*
114 * manifest constants
115 */
116
117#define MSG_FRAME_MAX_SIZE 2150 /* maximum size of B1 frame */
118#define MSG_TEXT_MAX_SIZE 1024 /* maximum size of msg text */
119#define MSG_MAX_SIZE MSG_ALIGN(MSG_FRAME_MAX_SIZE)
120#define DBG_MIN_BUFFER_SIZE 0x00008000 /* minimal total buffer size 32 KB */
121#define DBG_DEF_BUFFER_SIZE 0x00020000 /* default total buffer size 128 KB */
122#define DBG_MAX_BUFFER_SIZE 0x00400000 /* maximal total buffer size 4 MB */
123
124#define DBGDRV_NAME "Diehl_DIMAINT"
125#define UNIDBG_DRIVER L"\\Device\\Diehl_DIMAINT" /* UNICODE name for kernel */
126#define DEBUG_DRIVER "\\\\.\\" DBGDRV_NAME /* traditional string for apps */
127#define DBGVXD_NAME "DIMAINT"
128#define DEBUG_VXD "\\\\.\\" DBGVXD_NAME /* traditional string for apps */
129
130/*
131 * Special IDI interface debug construction
132 */
133
134#define DBG_IDI_SIG_REQ (unsigned long)0xF479C402
135#define DBG_IDI_SIG_IND (unsigned long)0xF479C403
136#define DBG_IDI_NL_REQ (unsigned long)0xF479C404
137#define DBG_IDI_NL_IND (unsigned long)0xF479C405
138
139typedef struct
140{ unsigned long magic_type ;
141 unsigned short data_len ;
142 unsigned char layer_ID ;
143 unsigned char entity_ID ;
144 unsigned char request ;
145 unsigned char ret_code ;
146 unsigned char indication ;
147 unsigned char complete ;
148 unsigned char data[4] ;
149} DbgIdiAct, *DbgIdiAction ;
150
151/*
152 * We want to use the same IOCTL codes in Win95 and WinNT.
153 * The official constructor for IOCTL codes is the CTL_CODE macro
154 * from <winoctl.h> (<devioctl.h> in WinNT DDK environment).
155 * The problem here is that we don't know how to get <winioctl.h>
156 * working in a Win95 DDK environment!
157 */
158
159# ifdef CTL_CODE /*{*/
160
161/* Assert that we have the same idea of the CTL_CODE macro. */
162
163#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
164 ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
165)
166
167# else /* !CTL_CODE */ /*}{*/
168
169/* Use the definitions stolen from <winioctl.h>. */
170
171#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
172 ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
173)
174
175#define METHOD_BUFFERED 0
176#define METHOD_IN_DIRECT 1
177#define METHOD_OUT_DIRECT 2
178#define METHOD_NEITHER 3
179
180#define FILE_ANY_ACCESS 0
181#define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
182#define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
183
184# endif /* CTL_CODE */ /*}*/
185
186/*
187 * Now we can define WinNT/Win95 DeviceIoControl codes.
188 *
189 * These codes are defined in di_defs.h too, a possible mismatch will be
190 * detected when the dbgtool is compiled.
191 */
192
193#define IOCTL_DRIVER_LNK \
194 CTL_CODE(0x8001U,0x701,METHOD_OUT_DIRECT,FILE_ANY_ACCESS)
195#define IOCTL_DRIVER_DBG \
196 CTL_CODE(0x8001U,0x702,METHOD_OUT_DIRECT,FILE_ANY_ACCESS)
197
198#endif /* __DBGIOCTL_H__ */
diff --git a/drivers/isdn/hardware/eicon/divamnt.c b/drivers/isdn/hardware/eicon/divamnt.c
index 4aba5c502d8e..c90928974249 100644
--- a/drivers/isdn/hardware/eicon/divamnt.c
+++ b/drivers/isdn/hardware/eicon/divamnt.c
@@ -13,7 +13,6 @@
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/smp_lock.h>
17#include <linux/poll.h> 16#include <linux/poll.h>
18#include <asm/uaccess.h> 17#include <asm/uaccess.h>
19 18
diff --git a/drivers/isdn/hardware/eicon/divasi.c b/drivers/isdn/hardware/eicon/divasi.c
index 556b19615bc7..78f141e77466 100644
--- a/drivers/isdn/hardware/eicon/divasi.c
+++ b/drivers/isdn/hardware/eicon/divasi.c
@@ -14,7 +14,6 @@
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/smp_lock.h>
18#include <linux/poll.h> 17#include <linux/poll.h>
19#include <linux/proc_fs.h> 18#include <linux/proc_fs.h>
20#include <linux/skbuff.h> 19#include <linux/skbuff.h>
diff --git a/drivers/isdn/hardware/eicon/divasmain.c b/drivers/isdn/hardware/eicon/divasmain.c
index 5e862e244117..6d39f9360766 100644
--- a/drivers/isdn/hardware/eicon/divasmain.c
+++ b/drivers/isdn/hardware/eicon/divasmain.c
@@ -17,7 +17,6 @@
17#include <linux/ioport.h> 17#include <linux/ioport.h>
18#include <linux/workqueue.h> 18#include <linux/workqueue.h>
19#include <linux/pci.h> 19#include <linux/pci.h>
20#include <linux/smp_lock.h>
21#include <linux/interrupt.h> 20#include <linux/interrupt.h>
22#include <linux/list.h> 21#include <linux/list.h>
23#include <linux/poll.h> 22#include <linux/poll.h>
diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
index af3eb9e795b5..85784a7ffb25 100644
--- a/drivers/isdn/hardware/eicon/divasync.h
+++ b/drivers/isdn/hardware/eicon/divasync.h
@@ -216,7 +216,7 @@ typedef struct
216#define SERIAL_HOOK_RING 0x85 216#define SERIAL_HOOK_RING 0x85
217#define SERIAL_HOOK_DETACH 0x8f 217#define SERIAL_HOOK_DETACH 0x8f
218 unsigned char Flags; /* function refinements */ 218 unsigned char Flags; /* function refinements */
219 /* parameters passed by the the ATTACH request */ 219 /* parameters passed by the ATTACH request */
220 SERIAL_INT_CB InterruptHandler; /* called on each interrupt */ 220 SERIAL_INT_CB InterruptHandler; /* called on each interrupt */
221 SERIAL_DPC_CB DeferredHandler; /* called on hook state changes */ 221 SERIAL_DPC_CB DeferredHandler; /* called on hook state changes */
222 void *HandlerContext; /* context for both handlers */ 222 void *HandlerContext; /* context for both handlers */
diff --git a/drivers/isdn/hardware/eicon/main_if.h b/drivers/isdn/hardware/eicon/main_if.h
deleted file mode 100644
index 0ea339afd424..000000000000
--- a/drivers/isdn/hardware/eicon/main_if.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/*
2 *
3 Copyright (c) Eicon Technology Corporation, 2000.
4 *
5 This source file is supplied for the use with Eicon
6 Technology Corporation's range of DIVA Server Adapters.
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, or (at your option)
11 any later version.
12 *
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
15 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 See the GNU General Public License for more details.
17 *
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23/*------------------------------------------------------------------*/
24/* file: main_if.h */
25/*------------------------------------------------------------------*/
26# ifndef MAIN_IF___H
27# define MAIN_IF___H
28
29# include "debug_if.h"
30
31void DI_lock (void) ;
32void DI_unlock (void) ;
33
34#ifdef NOT_YET_NEEDED
35void DI_nttime (LARGE_INTEGER *NTtime) ;
36void DI_ntlcltime(LARGE_INTEGER *NTtime, LARGE_INTEGER *lclNTtime) ;
37void DI_nttimefields(LARGE_INTEGER *NTtime, TIME_FIELDS *TimeFields);
38unsigned long DI_wintime(LARGE_INTEGER *NTtime) ;
39
40unsigned short DiInsertProcessorNumber (int type) ;
41void DiProcessEventLog (unsigned short id, unsigned long msgID, va_list ap);
42
43void StartIoctlTimer (void (*Handler)(void), unsigned long msec) ;
44void StopIoctlTimer (void) ;
45void UnpendIoctl (DbgRequest *pDbgReq) ;
46#endif
47
48void add_to_q(int, char* , unsigned int);
49# endif /* MAIN_IF___H */
50
diff --git a/drivers/isdn/hardware/eicon/platform.h b/drivers/isdn/hardware/eicon/platform.h
index ff09f07f440a..15d4942de53b 100644
--- a/drivers/isdn/hardware/eicon/platform.h
+++ b/drivers/isdn/hardware/eicon/platform.h
@@ -26,7 +26,6 @@
26#include <linux/vmalloc.h> 26#include <linux/vmalloc.h>
27#include <linux/proc_fs.h> 27#include <linux/proc_fs.h>
28#include <linux/interrupt.h> 28#include <linux/interrupt.h>
29#include <linux/smp_lock.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <linux/list.h> 30#include <linux/list.h>
32#include <asm/types.h> 31#include <asm/types.h>
diff --git a/drivers/isdn/hisax/hfc_usb.c b/drivers/isdn/hisax/hfc_usb.c
index 9f44d3e69fb0..1f18f1993387 100644
--- a/drivers/isdn/hisax/hfc_usb.c
+++ b/drivers/isdn/hisax/hfc_usb.c
@@ -37,7 +37,6 @@
37#include <linux/kernel_stat.h> 37#include <linux/kernel_stat.h>
38#include <linux/usb.h> 38#include <linux/usb.h>
39#include <linux/kernel.h> 39#include <linux/kernel.h>
40#include <linux/smp_lock.h>
41#include "hisax.h" 40#include "hisax.h"
42#include "hisax_if.h" 41#include "hisax_if.h"
43#include "hfc_usb.h" 42#include "hfc_usb.h"
@@ -1218,11 +1217,11 @@ usb_init(hfcusb_data * hfc)
1218 /* aux = output, reset off */ 1217 /* aux = output, reset off */
1219 write_usb(hfc, HFCUSB_CIRM, 0x10); 1218 write_usb(hfc, HFCUSB_CIRM, 0x10);
1220 1219
1221 /* set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers */ 1220 /* set USB_SIZE to match the wMaxPacketSize for INT or BULK transfers */
1222 write_usb(hfc, HFCUSB_USB_SIZE, 1221 write_usb(hfc, HFCUSB_USB_SIZE,
1223 (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4)); 1222 (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4));
1224 1223
1225 /* set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers */ 1224 /* set USB_SIZE_I to match the wMaxPacketSize for ISO transfers */
1226 write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size); 1225 write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
1227 1226
1228 /* enable PCM/GCI master mode */ 1227 /* enable PCM/GCI master mode */
diff --git a/drivers/isdn/hysdn/boardergo.c b/drivers/isdn/hysdn/boardergo.c
index 84dccd526ac0..6cdbad3a9926 100644
--- a/drivers/isdn/hysdn/boardergo.c
+++ b/drivers/isdn/hysdn/boardergo.c
@@ -443,7 +443,7 @@ ergo_inithardware(hysdn_card * card)
443 card->waitpofready = ergo_waitpofready; 443 card->waitpofready = ergo_waitpofready;
444 card->set_errlog_state = ergo_set_errlog_state; 444 card->set_errlog_state = ergo_set_errlog_state;
445 INIT_WORK(&card->irq_queue, ergo_irq_bh); 445 INIT_WORK(&card->irq_queue, ergo_irq_bh);
446 card->hysdn_lock = SPIN_LOCK_UNLOCKED; 446 spin_lock_init(&card->hysdn_lock);
447 447
448 return (0); 448 return (0);
449} /* ergo_inithardware */ 449} /* ergo_inithardware */
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index 4c7dedac0e51..27b3991fb0ec 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -297,8 +297,6 @@ hysdn_log_close(struct inode *ino, struct file *filep)
297 struct procdata *pd; 297 struct procdata *pd;
298 hysdn_card *card; 298 hysdn_card *card;
299 int retval = 0; 299 int retval = 0;
300 unsigned long flags;
301 spinlock_t hysdn_lock = SPIN_LOCK_UNLOCKED;
302 300
303 lock_kernel(); 301 lock_kernel();
304 if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) { 302 if ((filep->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_WRITE) {
@@ -308,7 +306,6 @@ hysdn_log_close(struct inode *ino, struct file *filep)
308 /* read access -> log/debug read, mark one further file as closed */ 306 /* read access -> log/debug read, mark one further file as closed */
309 307
310 pd = NULL; 308 pd = NULL;
311 spin_lock_irqsave(&hysdn_lock, flags);
312 inf = *((struct log_data **) filep->private_data); /* get first log entry */ 309 inf = *((struct log_data **) filep->private_data); /* get first log entry */
313 if (inf) 310 if (inf)
314 pd = (struct procdata *) inf->proc_ctrl; /* still entries there */ 311 pd = (struct procdata *) inf->proc_ctrl; /* still entries there */
@@ -331,7 +328,6 @@ hysdn_log_close(struct inode *ino, struct file *filep)
331 inf->usage_cnt--; /* decrement usage count for buffers */ 328 inf->usage_cnt--; /* decrement usage count for buffers */
332 inf = inf->next; 329 inf = inf->next;
333 } 330 }
334 spin_unlock_irqrestore(&hysdn_lock, flags);
335 331
336 if (pd) 332 if (pd)
337 if (pd->if_used <= 0) /* delete buffers if last file closed */ 333 if (pd->if_used <= 0) /* delete buffers if last file closed */
diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
index 1e699bcaba0f..82d957bde299 100644
--- a/drivers/isdn/icn/icn.c
+++ b/drivers/isdn/icn/icn.c
@@ -12,6 +12,7 @@
12#include "icn.h" 12#include "icn.h"
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/sched.h>
15 16
16static int portbase = ICN_BASEADDR; 17static int portbase = ICN_BASEADDR;
17static unsigned long membase = ICN_MEMADDR; 18static unsigned long membase = ICN_MEMADDR;
diff --git a/drivers/isdn/isdnloop/isdnloop.c b/drivers/isdn/isdnloop/isdnloop.c
index e93ad59f60bf..bb92e3cd9334 100644
--- a/drivers/isdn/isdnloop/isdnloop.c
+++ b/drivers/isdn/isdnloop/isdnloop.c
@@ -1462,7 +1462,7 @@ isdnloop_initcard(char *id)
1462 skb_queue_head_init(&card->bqueue[i]); 1462 skb_queue_head_init(&card->bqueue[i]);
1463 } 1463 }
1464 skb_queue_head_init(&card->dqueue); 1464 skb_queue_head_init(&card->dqueue);
1465 card->isdnloop_lock = SPIN_LOCK_UNLOCKED; 1465 spin_lock_init(&card->isdnloop_lock);
1466 card->next = cards; 1466 card->next = cards;
1467 cards = card; 1467 cards = card;
1468 if (!register_isdn(&card->interface)) { 1468 if (!register_isdn(&card->interface)) {
diff --git a/drivers/isdn/sc/message.c b/drivers/isdn/sc/message.c
index c5a307e3c496..0b4c4f15abdd 100644
--- a/drivers/isdn/sc/message.c
+++ b/drivers/isdn/sc/message.c
@@ -16,7 +16,7 @@
16 * +1 (416) 297-8565 16 * +1 (416) 297-8565
17 * +1 (416) 297-6433 Facsimile 17 * +1 (416) 297-6433 Facsimile
18 */ 18 */
19 19#include <linux/sched.h>
20#include "includes.h" 20#include "includes.h"
21#include "hardware.h" 21#include "hardware.h"
22#include "message.h" 22#include "message.h"
diff --git a/drivers/kvm/Kconfig b/drivers/kvm/Kconfig
index 703cc88d1ef9..e8e37d826478 100644
--- a/drivers/kvm/Kconfig
+++ b/drivers/kvm/Kconfig
@@ -2,6 +2,7 @@
2# KVM configuration 2# KVM configuration
3# 3#
4menu "Virtualization" 4menu "Virtualization"
5 depends on X86
5 6
6config KVM 7config KVM
7 tristate "Kernel-based Virtual Machine (KVM) support" 8 tristate "Kernel-based Virtual Machine (KVM) support"
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 41634fde8e13..1c040d80c641 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -11,6 +11,7 @@
11#include <linux/mutex.h> 11#include <linux/mutex.h>
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/mm.h> 13#include <linux/mm.h>
14#include <asm/signal.h>
14 15
15#include "vmx.h" 16#include "vmx.h"
16#include <linux/kvm.h> 17#include <linux/kvm.h>
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index c8b8cfa332bb..da985b31b17e 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -40,6 +40,7 @@
40#include <linux/file.h> 40#include <linux/file.h>
41#include <linux/fs.h> 41#include <linux/fs.h>
42#include <linux/mount.h> 42#include <linux/mount.h>
43#include <linux/sched.h>
43 44
44#include "x86_emulate.h" 45#include "x86_emulate.h"
45#include "segment_descriptor.h" 46#include "segment_descriptor.h"
@@ -2889,7 +2890,9 @@ static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
2889 2890
2890 switch (val) { 2891 switch (val) {
2891 case CPU_DOWN_PREPARE: 2892 case CPU_DOWN_PREPARE:
2893 case CPU_DOWN_PREPARE_FROZEN:
2892 case CPU_UP_CANCELED: 2894 case CPU_UP_CANCELED:
2895 case CPU_UP_CANCELED_FROZEN:
2893 printk(KERN_INFO "kvm: disabling virtualization on CPU%d\n", 2896 printk(KERN_INFO "kvm: disabling virtualization on CPU%d\n",
2894 cpu); 2897 cpu);
2895 decache_vcpus_on_cpu(cpu); 2898 decache_vcpus_on_cpu(cpu);
@@ -2897,6 +2900,7 @@ static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
2897 NULL, 0, 1); 2900 NULL, 0, 1);
2898 break; 2901 break;
2899 case CPU_ONLINE: 2902 case CPU_ONLINE:
2903 case CPU_ONLINE_FROZEN:
2900 printk(KERN_INFO "kvm: enabling virtualization on CPU%d\n", 2904 printk(KERN_INFO "kvm: enabling virtualization on CPU%d\n",
2901 cpu); 2905 cpu);
2902 smp_call_function_single(cpu, kvm_arch_ops->hardware_enable, 2906 smp_call_function_single(cpu, kvm_arch_ops->hardware_enable,
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 9c15f32eea18..fa17d6d4f0cb 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -19,6 +19,7 @@
19#include <linux/vmalloc.h> 19#include <linux/vmalloc.h>
20#include <linux/highmem.h> 20#include <linux/highmem.h>
21#include <linux/profile.h> 21#include <linux/profile.h>
22#include <linux/sched.h>
22#include <asm/desc.h> 23#include <asm/desc.h>
23 24
24#include "kvm_svm.h" 25#include "kvm_svm.h"
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 724db0027f00..e6e4d240b2a6 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -22,6 +22,7 @@
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/highmem.h> 23#include <linux/highmem.h>
24#include <linux/profile.h> 24#include <linux/profile.h>
25#include <linux/sched.h>
25#include <asm/io.h> 26#include <asm/io.h>
26#include <asm/desc.h> 27#include <asm/desc.h>
27 28
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 80acd08f0e97..87d2046f866c 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -1,5 +1,6 @@
1 1
2menu "LED devices" 2menu "LED devices"
3 depends on HAS_IOMEM
3 4
4config NEW_LEDS 5config NEW_LEDS
5 bool "LED Support" 6 bool "LED Support"
diff --git a/drivers/leds/leds-h1940.c b/drivers/leds/leds-h1940.c
index 1d49d2ade557..677c99325be5 100644
--- a/drivers/leds/leds-h1940.c
+++ b/drivers/leds/leds-h1940.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * drivers/leds/h1940-leds.c 2 * drivers/leds/leds-h1940.c
3 * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org> 3 * Copyright (c) Arnaud Patard <arnaud.patard@rtp-net.org>
4 * 4 *
5 * This file is subject to the terms and conditions of the GNU General Public 5 * This file is subject to the terms and conditions of the GNU General Public
diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index 1a86387e23be..58926da0ae18 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -1,6 +1,10 @@
1 1
2menu "Macintosh device drivers" 2menuconfig MACINTOSH_DRIVERS
3 bool "Macintosh device drivers"
3 depends on PPC || MAC || X86 4 depends on PPC || MAC || X86
5 default y
6
7if MACINTOSH_DRIVERS
4 8
5config ADB 9config ADB
6 bool "Apple Desktop Bus (ADB) support" 10 bool "Apple Desktop Bus (ADB) support"
@@ -109,7 +113,9 @@ config PMAC_SMU
109 113
110config PMAC_APM_EMU 114config PMAC_APM_EMU
111 tristate "APM emulation" 115 tristate "APM emulation"
112 depends on PPC_PMAC && PPC32 && PM && ADB_PMU 116 select SYS_SUPPORTS_APM_EMULATION
117 select APM_EMULATION
118 depends on ADB_PMU && PM
113 119
114config PMAC_MEDIABAY 120config PMAC_MEDIABAY
115 bool "Support PowerBook hotswap media bay" 121 bool "Support PowerBook hotswap media bay"
@@ -231,7 +237,7 @@ config PMAC_RACKMETER
231 tristate "Support for Apple XServe front panel LEDs" 237 tristate "Support for Apple XServe front panel LEDs"
232 depends on PPC_PMAC 238 depends on PPC_PMAC
233 help 239 help
234 This driver procides some support to control the front panel 240 This driver provides some support to control the front panel
235 blue LEDs "vu-meter" of the XServer macs. 241 blue LEDs "vu-meter" of the XServer macs.
236 242
237endmenu 243endif # MACINTOSH_DRIVERS
diff --git a/drivers/macintosh/apm_emu.c b/drivers/macintosh/apm_emu.c
index cdb0bead9917..9821e6361e60 100644
--- a/drivers/macintosh/apm_emu.c
+++ b/drivers/macintosh/apm_emu.c
@@ -1,9 +1,7 @@
1/* APM emulation layer for PowerMac 1/*
2 * 2 * APM emulation for PMU-based machines
3 * Copyright 2001 Benjamin Herrenschmidt (benh@kernel.crashing.org)
4 * 3 *
5 * Lots of code inherited from apm.c, see appropriate notice in 4 * Copyright 2001 Benjamin Herrenschmidt (benh@kernel.crashing.org)
6 * arch/i386/kernel/apm.c
7 * 5 *
8 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the 7 * under the terms of the GNU General Public License as published by the
@@ -18,429 +16,39 @@
18 * 16 *
19 */ 17 */
20 18
21#include <linux/module.h>
22
23#include <linux/poll.h>
24#include <linux/types.h>
25#include <linux/stddef.h>
26#include <linux/timer.h>
27#include <linux/fcntl.h>
28#include <linux/slab.h>
29#include <linux/stat.h>
30#include <linux/proc_fs.h>
31#include <linux/miscdevice.h>
32#include <linux/apm_bios.h>
33#include <linux/init.h>
34#include <linux/sched.h>
35#include <linux/pm.h>
36#include <linux/kernel.h> 19#include <linux/kernel.h>
37#include <linux/smp_lock.h> 20#include <linux/module.h>
38 21#include <linux/apm-emulation.h>
39#include <linux/adb.h> 22#include <linux/adb.h>
40#include <linux/pmu.h> 23#include <linux/pmu.h>
41 24
42#include <asm/system.h>
43#include <asm/uaccess.h>
44#include <asm/machdep.h>
45
46#undef DEBUG
47
48#ifdef DEBUG
49#define DBG(args...) printk(KERN_DEBUG args)
50//#define DBG(args...) xmon_printf(args)
51#else
52#define DBG(args...) do { } while (0)
53#endif
54
55/*
56 * The apm_bios device is one of the misc char devices.
57 * This is its minor number.
58 */
59#define APM_MINOR_DEV 134
60
61/*
62 * Maximum number of events stored
63 */
64#define APM_MAX_EVENTS 20
65
66#define FAKE_APM_BIOS_VERSION 0x0101
67
68#define APM_USER_NOTIFY_TIMEOUT (5*HZ)
69
70/*
71 * The per-file APM data
72 */
73struct apm_user {
74 int magic;
75 struct apm_user * next;
76 int suser: 1;
77 int suspend_waiting: 1;
78 int suspends_pending;
79 int suspends_read;
80 int event_head;
81 int event_tail;
82 apm_event_t events[APM_MAX_EVENTS];
83};
84
85/*
86 * The magic number in apm_user
87 */
88#define APM_BIOS_MAGIC 0x4101
89
90/*
91 * Local variables
92 */
93static int suspends_pending;
94
95static DECLARE_WAIT_QUEUE_HEAD(apm_waitqueue);
96static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
97static struct apm_user * user_list;
98
99static void apm_notify_sleep(struct pmu_sleep_notifier *self, int when);
100static struct pmu_sleep_notifier apm_sleep_notifier = {
101 apm_notify_sleep,
102 SLEEP_LEVEL_USERLAND,
103};
104
105static const char driver_version[] = "0.5"; /* no spaces */
106
107#ifdef DEBUG
108static char * apm_event_name[] = {
109 "system standby",
110 "system suspend",
111 "normal resume",
112 "critical resume",
113 "low battery",
114 "power status change",
115 "update time",
116 "critical suspend",
117 "user standby",
118 "user suspend",
119 "system standby resume",
120 "capabilities change"
121};
122#define NR_APM_EVENT_NAME \
123 (sizeof(apm_event_name) / sizeof(apm_event_name[0]))
124
125#endif
126
127static int queue_empty(struct apm_user *as)
128{
129 return as->event_head == as->event_tail;
130}
131
132static apm_event_t get_queued_event(struct apm_user *as)
133{
134 as->event_tail = (as->event_tail + 1) % APM_MAX_EVENTS;
135 return as->events[as->event_tail];
136}
137
138static void queue_event(apm_event_t event, struct apm_user *sender)
139{
140 struct apm_user * as;
141
142 DBG("apm_emu: queue_event(%s)\n", apm_event_name[event-1]);
143 if (user_list == NULL)
144 return;
145 for (as = user_list; as != NULL; as = as->next) {
146 if (as == sender)
147 continue;
148 as->event_head = (as->event_head + 1) % APM_MAX_EVENTS;
149 if (as->event_head == as->event_tail) {
150 static int notified;
151
152 if (notified++ == 0)
153 printk(KERN_ERR "apm_emu: an event queue overflowed\n");
154 as->event_tail = (as->event_tail + 1) % APM_MAX_EVENTS;
155 }
156 as->events[as->event_head] = event;
157 if (!as->suser)
158 continue;
159 switch (event) {
160 case APM_SYS_SUSPEND:
161 case APM_USER_SUSPEND:
162 as->suspends_pending++;
163 suspends_pending++;
164 break;
165 case APM_NORMAL_RESUME:
166 as->suspend_waiting = 0;
167 break;
168 }
169 }
170 wake_up_interruptible(&apm_waitqueue);
171}
172
173static int check_apm_user(struct apm_user *as, const char *func)
174{
175 if ((as == NULL) || (as->magic != APM_BIOS_MAGIC)) {
176 printk(KERN_ERR "apm_emu: %s passed bad filp\n", func);
177 return 1;
178 }
179 return 0;
180}
181
182static ssize_t do_read(struct file *fp, char __user *buf, size_t count, loff_t *ppos)
183{
184 struct apm_user * as;
185 size_t i;
186 apm_event_t event;
187 DECLARE_WAITQUEUE(wait, current);
188
189 as = fp->private_data;
190 if (check_apm_user(as, "read"))
191 return -EIO;
192 if (count < sizeof(apm_event_t))
193 return -EINVAL;
194 if (queue_empty(as)) {
195 if (fp->f_flags & O_NONBLOCK)
196 return -EAGAIN;
197 add_wait_queue(&apm_waitqueue, &wait);
198repeat:
199 set_current_state(TASK_INTERRUPTIBLE);
200 if (queue_empty(as) && !signal_pending(current)) {
201 schedule();
202 goto repeat;
203 }
204 set_current_state(TASK_RUNNING);
205 remove_wait_queue(&apm_waitqueue, &wait);
206 }
207 i = count;
208 while ((i >= sizeof(event)) && !queue_empty(as)) {
209 event = get_queued_event(as);
210 DBG("apm_emu: do_read, returning: %s\n", apm_event_name[event-1]);
211 if (copy_to_user(buf, &event, sizeof(event))) {
212 if (i < count)
213 break;
214 return -EFAULT;
215 }
216 switch (event) {
217 case APM_SYS_SUSPEND:
218 case APM_USER_SUSPEND:
219 as->suspends_read++;
220 break;
221 }
222 buf += sizeof(event);
223 i -= sizeof(event);
224 }
225 if (i < count)
226 return count - i;
227 if (signal_pending(current))
228 return -ERESTARTSYS;
229 return 0;
230}
231
232static unsigned int do_poll(struct file *fp, poll_table * wait)
233{
234 struct apm_user * as;
235
236 as = fp->private_data;
237 if (check_apm_user(as, "poll"))
238 return 0;
239 poll_wait(fp, &apm_waitqueue, wait);
240 if (!queue_empty(as))
241 return POLLIN | POLLRDNORM;
242 return 0;
243}
244
245static int do_ioctl(struct inode * inode, struct file *filp,
246 u_int cmd, u_long arg)
247{
248 struct apm_user * as;
249 DECLARE_WAITQUEUE(wait, current);
250
251 as = filp->private_data;
252 if (check_apm_user(as, "ioctl"))
253 return -EIO;
254 if (!as->suser)
255 return -EPERM;
256 switch (cmd) {
257 case APM_IOC_SUSPEND:
258 /* If a suspend message was sent to userland, we
259 * consider this as a confirmation message
260 */
261 if (as->suspends_read > 0) {
262 as->suspends_read--;
263 as->suspends_pending--;
264 suspends_pending--;
265 } else {
266 // Route to PMU suspend ?
267 break;
268 }
269 as->suspend_waiting = 1;
270 add_wait_queue(&apm_waitqueue, &wait);
271 DBG("apm_emu: ioctl waking up sleep waiter !\n");
272 wake_up(&apm_suspend_waitqueue);
273 mb();
274 while(as->suspend_waiting && !signal_pending(current)) {
275 set_current_state(TASK_INTERRUPTIBLE);
276 schedule();
277 }
278 set_current_state(TASK_RUNNING);
279 remove_wait_queue(&apm_waitqueue, &wait);
280 break;
281 default:
282 return -EINVAL;
283 }
284 return 0;
285}
286
287static int do_release(struct inode * inode, struct file * filp)
288{
289 struct apm_user * as;
290
291 as = filp->private_data;
292 if (check_apm_user(as, "release"))
293 return 0;
294 filp->private_data = NULL;
295 lock_kernel();
296 if (as->suspends_pending > 0) {
297 suspends_pending -= as->suspends_pending;
298 if (suspends_pending <= 0)
299 wake_up(&apm_suspend_waitqueue);
300 }
301 if (user_list == as)
302 user_list = as->next;
303 else {
304 struct apm_user * as1;
305
306 for (as1 = user_list;
307 (as1 != NULL) && (as1->next != as);
308 as1 = as1->next)
309 ;
310 if (as1 == NULL)
311 printk(KERN_ERR "apm: filp not in user list\n");
312 else
313 as1->next = as->next;
314 }
315 unlock_kernel();
316 kfree(as);
317 return 0;
318}
319
320static int do_open(struct inode * inode, struct file * filp)
321{
322 struct apm_user * as;
323
324 as = kmalloc(sizeof(*as), GFP_KERNEL);
325 if (as == NULL) {
326 printk(KERN_ERR "apm: cannot allocate struct of size %d bytes\n",
327 sizeof(*as));
328 return -ENOMEM;
329 }
330 as->magic = APM_BIOS_MAGIC;
331 as->event_tail = as->event_head = 0;
332 as->suspends_pending = 0;
333 as->suspends_read = 0;
334 /*
335 * XXX - this is a tiny bit broken, when we consider BSD
336 * process accounting. If the device is opened by root, we
337 * instantly flag that we used superuser privs. Who knows,
338 * we might close the device immediately without doing a
339 * privileged operation -- cevans
340 */
341 as->suser = capable(CAP_SYS_ADMIN);
342 as->next = user_list;
343 user_list = as;
344 filp->private_data = as;
345
346 DBG("apm_emu: opened by %s, suser: %d\n", current->comm, (int)as->suser);
347
348 return 0;
349}
350
351/* Wait for all clients to ack the suspend request. APM API
352 * doesn't provide a way to NAK, but this could be added
353 * here.
354 */
355static void wait_all_suspend(void)
356{
357 DECLARE_WAITQUEUE(wait, current);
358
359 add_wait_queue(&apm_suspend_waitqueue, &wait);
360 DBG("apm_emu: wait_all_suspend(), suspends_pending: %d\n", suspends_pending);
361 while(suspends_pending > 0) {
362 set_current_state(TASK_UNINTERRUPTIBLE);
363 schedule();
364 }
365 set_current_state(TASK_RUNNING);
366 remove_wait_queue(&apm_suspend_waitqueue, &wait);
367
368 DBG("apm_emu: wait_all_suspend() - complete !\n");
369}
370
371static void apm_notify_sleep(struct pmu_sleep_notifier *self, int when)
372{
373 switch(when) {
374 case PBOOK_SLEEP_REQUEST:
375 queue_event(APM_SYS_SUSPEND, NULL);
376 wait_all_suspend();
377 break;
378 case PBOOK_WAKE:
379 queue_event(APM_NORMAL_RESUME, NULL);
380 break;
381 }
382}
383
384#define APM_CRITICAL 10 25#define APM_CRITICAL 10
385#define APM_LOW 30 26#define APM_LOW 30
386 27
387static int apm_emu_get_info(char *buf, char **start, off_t fpos, int length) 28static void pmu_apm_get_power_status(struct apm_power_info *info)
388{ 29{
389 /* Arguments, with symbols from linux/apm_bios.h. Information is 30 int percentage = -1;
390 from the Get Power Status (0x0a) call unless otherwise noted. 31 int batteries = 0;
32 int time_units = -1;
33 int real_count = 0;
34 int i;
35 char charging = 0;
36 long charge = -1;
37 long amperage = 0;
38 unsigned long btype = 0;
39
40 info->battery_status = APM_BATTERY_STATUS_UNKNOWN;
41 info->battery_flag = APM_BATTERY_FLAG_UNKNOWN;
42 info->units = APM_UNITS_MINS;
43
44 if (pmu_power_flags & PMU_PWR_AC_PRESENT)
45 info->ac_line_status = APM_AC_ONLINE;
46 else
47 info->ac_line_status = APM_AC_OFFLINE;
391 48
392 0) Linux driver version (this will change if format changes)
393 1) APM BIOS Version. Usually 1.0, 1.1 or 1.2.
394 2) APM flags from APM Installation Check (0x00):
395 bit 0: APM_16_BIT_SUPPORT
396 bit 1: APM_32_BIT_SUPPORT
397 bit 2: APM_IDLE_SLOWS_CLOCK
398 bit 3: APM_BIOS_DISABLED
399 bit 4: APM_BIOS_DISENGAGED
400 3) AC line status
401 0x00: Off-line
402 0x01: On-line
403 0x02: On backup power (BIOS >= 1.1 only)
404 0xff: Unknown
405 4) Battery status
406 0x00: High
407 0x01: Low
408 0x02: Critical
409 0x03: Charging
410 0x04: Selected battery not present (BIOS >= 1.2 only)
411 0xff: Unknown
412 5) Battery flag
413 bit 0: High
414 bit 1: Low
415 bit 2: Critical
416 bit 3: Charging
417 bit 7: No system battery
418 0xff: Unknown
419 6) Remaining battery life (percentage of charge):
420 0-100: valid
421 -1: Unknown
422 7) Remaining battery life (time units):
423 Number of remaining minutes or seconds
424 -1: Unknown
425 8) min = minutes; sec = seconds */
426
427 unsigned short ac_line_status;
428 unsigned short battery_status = 0;
429 unsigned short battery_flag = 0xff;
430 int percentage = -1;
431 int time_units = -1;
432 int real_count = 0;
433 int i;
434 char * p = buf;
435 char charging = 0;
436 long charge = -1;
437 long amperage = 0;
438 unsigned long btype = 0;
439
440 ac_line_status = ((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0);
441 for (i=0; i<pmu_battery_count; i++) { 49 for (i=0; i<pmu_battery_count; i++) {
442 if (pmu_batteries[i].flags & PMU_BATT_PRESENT) { 50 if (pmu_batteries[i].flags & PMU_BATT_PRESENT) {
443 battery_status++; 51 batteries++;
444 if (percentage < 0) 52 if (percentage < 0)
445 percentage = 0; 53 percentage = 0;
446 if (charge < 0) 54 if (charge < 0)
@@ -456,9 +64,9 @@ static int apm_emu_get_info(char *buf, char **start, off_t fpos, int length)
456 charging++; 64 charging++;
457 } 65 }
458 } 66 }
459 if (0 == battery_status) 67 if (batteries == 0)
460 ac_line_status = 1; 68 info->ac_line_status = APM_AC_ONLINE;
461 battery_status = 0xff; 69
462 if (real_count) { 70 if (real_count) {
463 if (amperage < 0) { 71 if (amperage < 0) {
464 if (btype == PMU_BATT_TYPE_SMART) 72 if (btype == PMU_BATT_TYPE_SMART)
@@ -468,85 +76,44 @@ static int apm_emu_get_info(char *buf, char **start, off_t fpos, int length)
468 } 76 }
469 percentage /= real_count; 77 percentage /= real_count;
470 if (charging > 0) { 78 if (charging > 0) {
471 battery_status = 0x03; 79 info->battery_status = APM_BATTERY_STATUS_CHARGING;
472 battery_flag = 0x08; 80 info->battery_flag = APM_BATTERY_FLAG_CHARGING;
473 } else if (percentage <= APM_CRITICAL) { 81 } else if (percentage <= APM_CRITICAL) {
474 battery_status = 0x02; 82 info->battery_status = APM_BATTERY_STATUS_CRITICAL;
475 battery_flag = 0x04; 83 info->battery_flag = APM_BATTERY_FLAG_CRITICAL;
476 } else if (percentage <= APM_LOW) { 84 } else if (percentage <= APM_LOW) {
477 battery_status = 0x01; 85 info->battery_status = APM_BATTERY_STATUS_LOW;
478 battery_flag = 0x02; 86 info->battery_flag = APM_BATTERY_FLAG_LOW;
479 } else { 87 } else {
480 battery_status = 0x00; 88 info->battery_status = APM_BATTERY_STATUS_HIGH;
481 battery_flag = 0x01; 89 info->battery_flag = APM_BATTERY_FLAG_HIGH;
482 } 90 }
483 } 91 }
484 p += sprintf(p, "%s %d.%d 0x%02x 0x%02x 0x%02x 0x%02x %d%% %d %s\n",
485 driver_version,
486 (FAKE_APM_BIOS_VERSION >> 8) & 0xff,
487 FAKE_APM_BIOS_VERSION & 0xff,
488 0,
489 ac_line_status,
490 battery_status,
491 battery_flag,
492 percentage,
493 time_units,
494 "min");
495 92
496 return p - buf; 93 info->battery_life = percentage;
94 info->time = time_units;
497} 95}
498 96
499static const struct file_operations apm_bios_fops = {
500 .owner = THIS_MODULE,
501 .read = do_read,
502 .poll = do_poll,
503 .ioctl = do_ioctl,
504 .open = do_open,
505 .release = do_release,
506};
507
508static struct miscdevice apm_device = {
509 APM_MINOR_DEV,
510 "apm_bios",
511 &apm_bios_fops
512};
513
514static int __init apm_emu_init(void) 97static int __init apm_emu_init(void)
515{ 98{
516 struct proc_dir_entry *apm_proc; 99 apm_get_power_status = pmu_apm_get_power_status;
517
518 if (sys_ctrler != SYS_CTRLER_PMU) {
519 printk(KERN_INFO "apm_emu: Requires a machine with a PMU.\n");
520 return -ENODEV;
521 }
522
523 apm_proc = create_proc_info_entry("apm", 0, NULL, apm_emu_get_info);
524 if (apm_proc)
525 apm_proc->owner = THIS_MODULE;
526 100
527 if (misc_register(&apm_device) != 0) 101 printk(KERN_INFO "apm_emu: PMU APM Emulation initialized.\n");
528 printk(KERN_INFO "Could not create misc. device for apm\n");
529
530 pmu_register_sleep_notifier(&apm_sleep_notifier);
531
532 printk(KERN_INFO "apm_emu: APM Emulation %s initialized.\n", driver_version);
533 102
534 return 0; 103 return 0;
535} 104}
536 105
537static void __exit apm_emu_exit(void) 106static void __exit apm_emu_exit(void)
538{ 107{
539 pmu_unregister_sleep_notifier(&apm_sleep_notifier); 108 if (apm_get_power_status == pmu_apm_get_power_status)
540 misc_deregister(&apm_device); 109 apm_get_power_status = NULL;
541 remove_proc_entry("apm", NULL);
542 110
543 printk(KERN_INFO "apm_emu: APM Emulation removed.\n"); 111 printk(KERN_INFO "apm_emu: PMU APM Emulation removed.\n");
544} 112}
545 113
546module_init(apm_emu_init); 114module_init(apm_emu_init);
547module_exit(apm_emu_exit); 115module_exit(apm_emu_exit);
548 116
549MODULE_AUTHOR("Benjamin Herrenschmidt"); 117MODULE_AUTHOR("Benjamin Herrenschmidt");
550MODULE_DESCRIPTION("APM emulation layer for PowerMac"); 118MODULE_DESCRIPTION("APM emulation for PowerMac");
551MODULE_LICENSE("GPL"); 119MODULE_LICENSE("GPL");
552
diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
index 1599dc34f15f..76c1e8e4a487 100644
--- a/drivers/macintosh/mac_hid.c
+++ b/drivers/macintosh/mac_hid.c
@@ -24,7 +24,7 @@ static int mouse_last_keycode;
24 24
25#if defined(CONFIG_SYSCTL) 25#if defined(CONFIG_SYSCTL)
26/* file(s) in /proc/sys/dev/mac_hid */ 26/* file(s) in /proc/sys/dev/mac_hid */
27ctl_table mac_hid_files[] = { 27static ctl_table mac_hid_files[] = {
28 { 28 {
29 .ctl_name = DEV_MAC_HID_MOUSE_BUTTON_EMULATION, 29 .ctl_name = DEV_MAC_HID_MOUSE_BUTTON_EMULATION,
30 .procname = "mouse_button_emulation", 30 .procname = "mouse_button_emulation",
@@ -53,7 +53,7 @@ ctl_table mac_hid_files[] = {
53}; 53};
54 54
55/* dir in /proc/sys/dev */ 55/* dir in /proc/sys/dev */
56ctl_table mac_hid_dir[] = { 56static ctl_table mac_hid_dir[] = {
57 { 57 {
58 .ctl_name = DEV_MAC_HID, 58 .ctl_name = DEV_MAC_HID,
59 .procname = "mac_hid", 59 .procname = "mac_hid",
@@ -65,7 +65,7 @@ ctl_table mac_hid_dir[] = {
65}; 65};
66 66
67/* /proc/sys/dev itself, in case that is not there yet */ 67/* /proc/sys/dev itself, in case that is not there yet */
68ctl_table mac_hid_root_dir[] = { 68static ctl_table mac_hid_root_dir[] = {
69 { 69 {
70 .ctl_name = CTL_DEV, 70 .ctl_name = CTL_DEV,
71 .procname = "dev", 71 .procname = "dev",
@@ -127,7 +127,7 @@ static int emumousebtn_input_register(void)
127 return ret; 127 return ret;
128} 128}
129 129
130int __init mac_hid_init(void) 130static int __init mac_hid_init(void)
131{ 131{
132 int err; 132 int err;
133 133
diff --git a/drivers/macintosh/macio_sysfs.c b/drivers/macintosh/macio_sysfs.c
index cc8267912656..112e5ef728f1 100644
--- a/drivers/macintosh/macio_sysfs.c
+++ b/drivers/macintosh/macio_sysfs.c
@@ -41,28 +41,15 @@ compatible_show (struct device *dev, struct device_attribute *attr, char *buf)
41static ssize_t modalias_show (struct device *dev, struct device_attribute *attr, 41static ssize_t modalias_show (struct device *dev, struct device_attribute *attr,
42 char *buf) 42 char *buf)
43{ 43{
44 struct of_device *of; 44 struct of_device *ofdev = to_of_device(dev);
45 const char *compat; 45 int len;
46 int cplen;
47 int length;
48 46
49 of = &to_macio_device (dev)->ofdev; 47 len = of_device_get_modalias(ofdev, buf, PAGE_SIZE);
50 compat = of_get_property(of->node, "compatible", &cplen);
51 if (!compat) compat = "", cplen = 1;
52 length = sprintf (buf, "of:N%sT%s", of->node->name, of->node->type);
53 buf += length;
54 while (cplen > 0) {
55 int l;
56 l = sprintf (buf, "C%s", compat);
57 length += l;
58 buf += l;
59 l = strlen (compat) + 1;
60 compat += l;
61 cplen -= l;
62 }
63 length += sprintf(buf, "\n");
64 48
65 return length; 49 buf[len] = '\n';
50 buf[len+1] = 0;
51
52 return len+1;
66} 53}
67 54
68macio_config_of_attr (name, "%s\n"); 55macio_config_of_attr (name, "%s\n");
diff --git a/drivers/macintosh/mediabay.c b/drivers/macintosh/mediabay.c
index 0acf2f7fd9d7..c803d2bba65d 100644
--- a/drivers/macintosh/mediabay.c
+++ b/drivers/macintosh/mediabay.c
@@ -563,7 +563,7 @@ static void media_bay_step(int i)
563 ide_init_hwif_ports(&hw, (unsigned long) bay->cd_base, (unsigned long) 0, NULL); 563 ide_init_hwif_ports(&hw, (unsigned long) bay->cd_base, (unsigned long) 0, NULL);
564 hw.irq = bay->cd_irq; 564 hw.irq = bay->cd_irq;
565 hw.chipset = ide_pmac; 565 hw.chipset = ide_pmac;
566 bay->cd_index = ide_register_hw(&hw, NULL); 566 bay->cd_index = ide_register_hw(&hw, 0, NULL);
567 pmu_resume(); 567 pmu_resume();
568 } 568 }
569 if (bay->cd_index == -1) { 569 if (bay->cd_index == -1) {
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index a98a328b1cfc..f8e1a135bf9d 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -606,7 +606,7 @@ static void smu_expose_childs(struct work_struct *unused)
606 struct device_node *np; 606 struct device_node *np;
607 607
608 for (np = NULL; (np = of_get_next_child(smu->of_node, np)) != NULL;) 608 for (np = NULL; (np = of_get_next_child(smu->of_node, np)) != NULL;)
609 if (device_is_compatible(np, "smu-sensors")) 609 if (of_device_is_compatible(np, "smu-sensors"))
610 of_platform_device_create(np, "smu-sensors", 610 of_platform_device_create(np, "smu-sensors",
611 &smu->of_dev->dev); 611 &smu->of_dev->dev);
612} 612}
diff --git a/drivers/macintosh/therm_adt746x.c b/drivers/macintosh/therm_adt746x.c
index 228903403cfc..bd55e6ab99fc 100644
--- a/drivers/macintosh/therm_adt746x.c
+++ b/drivers/macintosh/therm_adt746x.c
@@ -19,7 +19,6 @@
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/init.h> 20#include <linux/init.h>
21#include <linux/spinlock.h> 21#include <linux/spinlock.h>
22#include <linux/smp_lock.h>
23#include <linux/wait.h> 22#include <linux/wait.h>
24#include <linux/suspend.h> 23#include <linux/suspend.h>
25#include <linux/kthread.h> 24#include <linux/kthread.h>
@@ -560,9 +559,9 @@ thermostat_init(void)
560 np = of_find_node_by_name(NULL, "fan"); 559 np = of_find_node_by_name(NULL, "fan");
561 if (!np) 560 if (!np)
562 return -ENODEV; 561 return -ENODEV;
563 if (device_is_compatible(np, "adt7460")) 562 if (of_device_is_compatible(np, "adt7460"))
564 therm_type = ADT7460; 563 therm_type = ADT7460;
565 else if (device_is_compatible(np, "adt7467")) 564 else if (of_device_is_compatible(np, "adt7467"))
566 therm_type = ADT7467; 565 therm_type = ADT7467;
567 else 566 else
568 return -ENODEV; 567 return -ENODEV;
diff --git a/drivers/macintosh/therm_pm72.c b/drivers/macintosh/therm_pm72.c
index 78ff18617139..dbb22403979f 100644
--- a/drivers/macintosh/therm_pm72.c
+++ b/drivers/macintosh/therm_pm72.c
@@ -117,7 +117,6 @@
117#include <linux/slab.h> 117#include <linux/slab.h>
118#include <linux/init.h> 118#include <linux/init.h>
119#include <linux/spinlock.h> 119#include <linux/spinlock.h>
120#include <linux/smp_lock.h>
121#include <linux/wait.h> 120#include <linux/wait.h>
122#include <linux/reboot.h> 121#include <linux/reboot.h>
123#include <linux/kmod.h> 122#include <linux/kmod.h>
diff --git a/drivers/macintosh/via-pmu-led.c b/drivers/macintosh/via-pmu-led.c
index fc89a7047cd0..55ad95671387 100644
--- a/drivers/macintosh/via-pmu-led.c
+++ b/drivers/macintosh/via-pmu-led.c
@@ -31,7 +31,6 @@ static spinlock_t pmu_blink_lock;
31static struct adb_request pmu_blink_req; 31static struct adb_request pmu_blink_req;
32/* -1: no change, 0: request off, 1: request on */ 32/* -1: no change, 0: request off, 1: request on */
33static int requested_change; 33static int requested_change;
34static int sleeping;
35 34
36static void pmu_req_done(struct adb_request * req) 35static void pmu_req_done(struct adb_request * req)
37{ 36{
@@ -41,7 +40,7 @@ static void pmu_req_done(struct adb_request * req)
41 /* if someone requested a change in the meantime 40 /* if someone requested a change in the meantime
42 * (we only see the last one which is fine) 41 * (we only see the last one which is fine)
43 * then apply it now */ 42 * then apply it now */
44 if (requested_change != -1 && !sleeping) 43 if (requested_change != -1 && !pmu_sys_suspended)
45 pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change); 44 pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
46 /* reset requested change */ 45 /* reset requested change */
47 requested_change = -1; 46 requested_change = -1;
@@ -66,7 +65,7 @@ static void pmu_led_set(struct led_classdev *led_cdev,
66 break; 65 break;
67 } 66 }
68 /* if request isn't done, then don't do anything */ 67 /* if request isn't done, then don't do anything */
69 if (pmu_blink_req.complete && !sleeping) 68 if (pmu_blink_req.complete && !pmu_sys_suspended)
70 pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change); 69 pmu_request(&pmu_blink_req, NULL, 4, 0xee, 4, 0, requested_change);
71 out: 70 out:
72 spin_unlock_irqrestore(&pmu_blink_lock, flags); 71 spin_unlock_irqrestore(&pmu_blink_lock, flags);
@@ -80,32 +79,6 @@ static struct led_classdev pmu_led = {
80 .brightness_set = pmu_led_set, 79 .brightness_set = pmu_led_set,
81}; 80};
82 81
83#ifdef CONFIG_PM
84static void pmu_led_sleep_call(struct pmu_sleep_notifier *self, int when)
85{
86 unsigned long flags;
87
88 spin_lock_irqsave(&pmu_blink_lock, flags);
89
90 switch (when) {
91 case PBOOK_SLEEP_REQUEST:
92 sleeping = 1;
93 break;
94 case PBOOK_WAKE:
95 sleeping = 0;
96 break;
97 default:
98 /* do nothing */
99 break;
100 }
101 spin_unlock_irqrestore(&pmu_blink_lock, flags);
102}
103
104static struct pmu_sleep_notifier via_pmu_led_sleep_notif = {
105 .notifier_call = pmu_led_sleep_call,
106};
107#endif
108
109static int __init via_pmu_led_init(void) 82static int __init via_pmu_led_init(void)
110{ 83{
111 struct device_node *dt; 84 struct device_node *dt;
@@ -135,9 +108,7 @@ static int __init via_pmu_led_init(void)
135 /* no outstanding req */ 108 /* no outstanding req */
136 pmu_blink_req.complete = 1; 109 pmu_blink_req.complete = 1;
137 pmu_blink_req.done = pmu_req_done; 110 pmu_blink_req.done = pmu_req_done;
138#ifdef CONFIG_PM 111
139 pmu_register_sleep_notifier(&via_pmu_led_sleep_notif);
140#endif
141 return led_classdev_register(NULL, &pmu_led); 112 return led_classdev_register(NULL, &pmu_led);
142} 113}
143 114
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 1729d3fd7a11..157080b3b468 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -310,14 +310,14 @@ int __init find_via_pmu(void)
310 PMU_INT_TICK; 310 PMU_INT_TICK;
311 311
312 if (vias->parent->name && ((strcmp(vias->parent->name, "ohare") == 0) 312 if (vias->parent->name && ((strcmp(vias->parent->name, "ohare") == 0)
313 || device_is_compatible(vias->parent, "ohare"))) 313 || of_device_is_compatible(vias->parent, "ohare")))
314 pmu_kind = PMU_OHARE_BASED; 314 pmu_kind = PMU_OHARE_BASED;
315 else if (device_is_compatible(vias->parent, "paddington")) 315 else if (of_device_is_compatible(vias->parent, "paddington"))
316 pmu_kind = PMU_PADDINGTON_BASED; 316 pmu_kind = PMU_PADDINGTON_BASED;
317 else if (device_is_compatible(vias->parent, "heathrow")) 317 else if (of_device_is_compatible(vias->parent, "heathrow"))
318 pmu_kind = PMU_HEATHROW_BASED; 318 pmu_kind = PMU_HEATHROW_BASED;
319 else if (device_is_compatible(vias->parent, "Keylargo") 319 else if (of_device_is_compatible(vias->parent, "Keylargo")
320 || device_is_compatible(vias->parent, "K2-Keylargo")) { 320 || of_device_is_compatible(vias->parent, "K2-Keylargo")) {
321 struct device_node *gpiop; 321 struct device_node *gpiop;
322 struct device_node *adbp; 322 struct device_node *adbp;
323 u64 gaddr = OF_BAD_ADDR; 323 u64 gaddr = OF_BAD_ADDR;
@@ -2759,7 +2759,7 @@ pmu_polled_request(struct adb_request *req)
2759 2759
2760#if defined(CONFIG_PM) && defined(CONFIG_PPC32) 2760#if defined(CONFIG_PM) && defined(CONFIG_PPC32)
2761 2761
2762static int pmu_sys_suspended; 2762int pmu_sys_suspended;
2763 2763
2764static int pmu_sys_suspend(struct sys_device *sysdev, pm_message_t state) 2764static int pmu_sys_suspend(struct sys_device *sysdev, pm_message_t state)
2765{ 2765{
diff --git a/drivers/macintosh/windfarm_core.c b/drivers/macintosh/windfarm_core.c
index 94c117ef20c1..11ced17f438a 100644
--- a/drivers/macintosh/windfarm_core.c
+++ b/drivers/macintosh/windfarm_core.c
@@ -27,7 +27,6 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/spinlock.h> 29#include <linux/spinlock.h>
30#include <linux/smp_lock.h>
31#include <linux/kthread.h> 30#include <linux/kthread.h>
32#include <linux/jiffies.h> 31#include <linux/jiffies.h>
33#include <linux/reboot.h> 32#include <linux/reboot.h>
@@ -217,7 +216,10 @@ int wf_register_control(struct wf_control *new_ct)
217 new_ct->attr.attr.mode = 0644; 216 new_ct->attr.attr.mode = 0644;
218 new_ct->attr.show = wf_show_control; 217 new_ct->attr.show = wf_show_control;
219 new_ct->attr.store = wf_store_control; 218 new_ct->attr.store = wf_store_control;
220 device_create_file(&wf_platform_device.dev, &new_ct->attr); 219 if (device_create_file(&wf_platform_device.dev, &new_ct->attr))
220 printk(KERN_WARNING "windfarm: device_create_file failed"
221 " for %s\n", new_ct->name);
222 /* the subsystem still does useful work without the file */
221 223
222 DBG("wf: Registered control %s\n", new_ct->name); 224 DBG("wf: Registered control %s\n", new_ct->name);
223 225
@@ -327,7 +329,10 @@ int wf_register_sensor(struct wf_sensor *new_sr)
327 new_sr->attr.attr.mode = 0444; 329 new_sr->attr.attr.mode = 0444;
328 new_sr->attr.show = wf_show_sensor; 330 new_sr->attr.show = wf_show_sensor;
329 new_sr->attr.store = NULL; 331 new_sr->attr.store = NULL;
330 device_create_file(&wf_platform_device.dev, &new_sr->attr); 332 if (device_create_file(&wf_platform_device.dev, &new_sr->attr))
333 printk(KERN_WARNING "windfarm: device_create_file failed"
334 " for %s\n", new_sr->name);
335 /* the subsystem still does useful work without the file */
331 336
332 DBG("wf: Registered sensor %s\n", new_sr->name); 337 DBG("wf: Registered sensor %s\n", new_sr->name);
333 338
diff --git a/drivers/macintosh/windfarm_lm75_sensor.c b/drivers/macintosh/windfarm_lm75_sensor.c
index ab4d1b63f63e..a0fabf3c2008 100644
--- a/drivers/macintosh/windfarm_lm75_sensor.c
+++ b/drivers/macintosh/windfarm_lm75_sensor.c
@@ -188,10 +188,10 @@ static int wf_lm75_attach(struct i2c_adapter *adapter)
188 if (loc == NULL || addr == 0) 188 if (loc == NULL || addr == 0)
189 continue; 189 continue;
190 /* real lm75 */ 190 /* real lm75 */
191 if (device_is_compatible(dev, "lm75")) 191 if (of_device_is_compatible(dev, "lm75"))
192 wf_lm75_create(adapter, addr, 0, loc); 192 wf_lm75_create(adapter, addr, 0, loc);
193 /* ds1775 (compatible, better resolution */ 193 /* ds1775 (compatible, better resolution */
194 else if (device_is_compatible(dev, "ds1775")) 194 else if (of_device_is_compatible(dev, "ds1775"))
195 wf_lm75_create(adapter, addr, 1, loc); 195 wf_lm75_create(adapter, addr, 1, loc);
196 } 196 }
197 return 0; 197 return 0;
diff --git a/drivers/macintosh/windfarm_max6690_sensor.c b/drivers/macintosh/windfarm_max6690_sensor.c
index eaa74afa175b..5f03aab9fb5d 100644
--- a/drivers/macintosh/windfarm_max6690_sensor.c
+++ b/drivers/macintosh/windfarm_max6690_sensor.c
@@ -131,7 +131,7 @@ static int wf_max6690_attach(struct i2c_adapter *adapter)
131 */ 131 */
132 if (!pmac_i2c_match_adapter(dev, adapter)) 132 if (!pmac_i2c_match_adapter(dev, adapter))
133 continue; 133 continue;
134 if (!device_is_compatible(dev, "max6690")) 134 if (!of_device_is_compatible(dev, "max6690"))
135 continue; 135 continue;
136 addr = pmac_i2c_get_dev_addr(dev); 136 addr = pmac_i2c_get_dev_addr(dev);
137 loc = of_get_property(dev, "hwsensor-location", NULL); 137 loc = of_get_property(dev, "hwsensor-location", NULL);
diff --git a/drivers/macintosh/windfarm_smu_controls.c b/drivers/macintosh/windfarm_smu_controls.c
index ff398adc0283..58c2590f05ec 100644
--- a/drivers/macintosh/windfarm_smu_controls.c
+++ b/drivers/macintosh/windfarm_smu_controls.c
@@ -263,7 +263,7 @@ static int __init smu_controls_init(void)
263 /* Look for RPM fans */ 263 /* Look for RPM fans */
264 for (fans = NULL; (fans = of_get_next_child(smu, fans)) != NULL;) 264 for (fans = NULL; (fans = of_get_next_child(smu, fans)) != NULL;)
265 if (!strcmp(fans->name, "rpm-fans") || 265 if (!strcmp(fans->name, "rpm-fans") ||
266 device_is_compatible(fans, "smu-rpm-fans")) 266 of_device_is_compatible(fans, "smu-rpm-fans"))
267 break; 267 break;
268 for (fan = NULL; 268 for (fan = NULL;
269 fans && (fan = of_get_next_child(fans, fan)) != NULL;) { 269 fans && (fan = of_get_next_child(fans, fan)) != NULL;) {
diff --git a/drivers/macintosh/windfarm_smu_sat.c b/drivers/macintosh/windfarm_smu_sat.c
index 9a6c2cf8fd0e..1043b39aa123 100644
--- a/drivers/macintosh/windfarm_smu_sat.c
+++ b/drivers/macintosh/windfarm_smu_sat.c
@@ -380,7 +380,7 @@ static int wf_sat_attach(struct i2c_adapter *adapter)
380 busnode = pmac_i2c_get_bus_node(bus); 380 busnode = pmac_i2c_get_bus_node(bus);
381 381
382 while ((dev = of_get_next_child(busnode, dev)) != NULL) 382 while ((dev = of_get_next_child(busnode, dev)) != NULL)
383 if (device_is_compatible(dev, "smu-sat")) 383 if (of_device_is_compatible(dev, "smu-sat"))
384 wf_sat_create(adapter, dev); 384 wf_sat_create(adapter, dev);
385 return 0; 385 return 0;
386} 386}
diff --git a/drivers/mca/mca-bus.c b/drivers/mca/mca-bus.c
index da862e4632dd..67b8e9453b19 100644
--- a/drivers/mca/mca-bus.c
+++ b/drivers/mca/mca-bus.c
@@ -47,19 +47,25 @@ static int mca_bus_match (struct device *dev, struct device_driver *drv)
47{ 47{
48 struct mca_device *mca_dev = to_mca_device (dev); 48 struct mca_device *mca_dev = to_mca_device (dev);
49 struct mca_driver *mca_drv = to_mca_driver (drv); 49 struct mca_driver *mca_drv = to_mca_driver (drv);
50 const short *mca_ids = mca_drv->id_table; 50 const unsigned short *mca_ids = mca_drv->id_table;
51 int i; 51 int i = 0;
52 52
53 if (!mca_ids) 53 if (mca_ids) {
54 return 0; 54 for(i = 0; mca_ids[i]; i++) {
55 55 if (mca_ids[i] == mca_dev->pos_id) {
56 for(i = 0; mca_ids[i]; i++) { 56 mca_dev->index = i;
57 if (mca_ids[i] == mca_dev->pos_id) { 57 return 1;
58 mca_dev->index = i; 58 }
59 return 1;
60 } 59 }
61 } 60 }
62 61 /* If the integrated id is present, treat it as though it were an
62 * additional id in the id_table (it can't be because by definition,
63 * integrated id's overflow a short */
64 if (mca_drv->integrated_id && mca_dev->pos_id ==
65 mca_drv->integrated_id) {
66 mca_dev->index = i;
67 return 1;
68 }
63 return 0; 69 return 0;
64} 70}
65 71
diff --git a/drivers/mca/mca-driver.c b/drivers/mca/mca-driver.c
index 2223466b3d8a..32cd39bcc715 100644
--- a/drivers/mca/mca-driver.c
+++ b/drivers/mca/mca-driver.c
@@ -36,12 +36,25 @@ int mca_register_driver(struct mca_driver *mca_drv)
36 mca_drv->driver.bus = &mca_bus_type; 36 mca_drv->driver.bus = &mca_bus_type;
37 if ((r = driver_register(&mca_drv->driver)) < 0) 37 if ((r = driver_register(&mca_drv->driver)) < 0)
38 return r; 38 return r;
39 mca_drv->integrated_id = 0;
39 } 40 }
40 41
41 return 0; 42 return 0;
42} 43}
43EXPORT_SYMBOL(mca_register_driver); 44EXPORT_SYMBOL(mca_register_driver);
44 45
46int mca_register_driver_integrated(struct mca_driver *mca_driver,
47 int integrated_id)
48{
49 int r = mca_register_driver(mca_driver);
50
51 if (!r)
52 mca_driver->integrated_id = integrated_id;
53
54 return r;
55}
56EXPORT_SYMBOL(mca_register_driver_integrated);
57
45void mca_unregister_driver(struct mca_driver *mca_drv) 58void mca_unregister_driver(struct mca_driver *mca_drv)
46{ 59{
47 if (MCA_bus) 60 if (MCA_bus)
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 4540ade6b6b5..7df934d69134 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -262,6 +262,15 @@ config DM_MULTIPATH_EMC
262 ---help--- 262 ---help---
263 Multipath support for EMC CX/AX series hardware. 263 Multipath support for EMC CX/AX series hardware.
264 264
265config DM_DELAY
266 tristate "I/O delaying target (EXPERIMENTAL)"
267 depends on BLK_DEV_DM && EXPERIMENTAL
268 ---help---
269 A target that delays reads and/or writes and can send
270 them to different devices. Useful for testing.
271
272 If unsure, say N.
273
265endmenu 274endmenu
266 275
267endif 276endif
diff --git a/drivers/md/Makefile b/drivers/md/Makefile
index 34957a68d921..38754084eac7 100644
--- a/drivers/md/Makefile
+++ b/drivers/md/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_MD_FAULTY) += faulty.o
31obj-$(CONFIG_BLK_DEV_MD) += md-mod.o 31obj-$(CONFIG_BLK_DEV_MD) += md-mod.o
32obj-$(CONFIG_BLK_DEV_DM) += dm-mod.o 32obj-$(CONFIG_BLK_DEV_DM) += dm-mod.o
33obj-$(CONFIG_DM_CRYPT) += dm-crypt.o 33obj-$(CONFIG_DM_CRYPT) += dm-crypt.o
34obj-$(CONFIG_DM_DELAY) += dm-delay.o
34obj-$(CONFIG_DM_MULTIPATH) += dm-multipath.o dm-round-robin.o 35obj-$(CONFIG_DM_MULTIPATH) += dm-multipath.o dm-round-robin.o
35obj-$(CONFIG_DM_MULTIPATH_EMC) += dm-emc.o 36obj-$(CONFIG_DM_MULTIPATH_EMC) += dm-emc.o
36obj-$(CONFIG_DM_SNAPSHOT) += dm-snapshot.o 37obj-$(CONFIG_DM_SNAPSHOT) += dm-snapshot.o
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index e61e0efe9ec7..5a4a74c1097c 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -1456,10 +1456,10 @@ int bitmap_create(mddev_t *mddev)
1456 bitmap->offset = mddev->bitmap_offset; 1456 bitmap->offset = mddev->bitmap_offset;
1457 if (file) { 1457 if (file) {
1458 get_file(file); 1458 get_file(file);
1459 do_sync_file_range(file, 0, LLONG_MAX, 1459 do_sync_mapping_range(file->f_mapping, 0, LLONG_MAX,
1460 SYNC_FILE_RANGE_WAIT_BEFORE | 1460 SYNC_FILE_RANGE_WAIT_BEFORE |
1461 SYNC_FILE_RANGE_WRITE | 1461 SYNC_FILE_RANGE_WRITE |
1462 SYNC_FILE_RANGE_WAIT_AFTER); 1462 SYNC_FILE_RANGE_WAIT_AFTER);
1463 } 1463 }
1464 /* read superblock from bitmap file (this sets bitmap->chunksize) */ 1464 /* read superblock from bitmap file (this sets bitmap->chunksize) */
1465 err = bitmap_read_sb(bitmap); 1465 err = bitmap_read_sb(bitmap);
diff --git a/drivers/md/dm-bio-list.h b/drivers/md/dm-bio-list.h
index da4349649f7f..c6be88826fae 100644
--- a/drivers/md/dm-bio-list.h
+++ b/drivers/md/dm-bio-list.h
@@ -8,17 +8,43 @@
8#define DM_BIO_LIST_H 8#define DM_BIO_LIST_H
9 9
10#include <linux/bio.h> 10#include <linux/bio.h>
11#include <linux/prefetch.h>
11 12
12struct bio_list { 13struct bio_list {
13 struct bio *head; 14 struct bio *head;
14 struct bio *tail; 15 struct bio *tail;
15}; 16};
16 17
18static inline int bio_list_empty(const struct bio_list *bl)
19{
20 return bl->head == NULL;
21}
22
23#define BIO_LIST_INIT { .head = NULL, .tail = NULL }
24
25#define BIO_LIST(bl) \
26 struct bio_list bl = BIO_LIST_INIT
27
17static inline void bio_list_init(struct bio_list *bl) 28static inline void bio_list_init(struct bio_list *bl)
18{ 29{
19 bl->head = bl->tail = NULL; 30 bl->head = bl->tail = NULL;
20} 31}
21 32
33#define bio_list_for_each(bio, bl) \
34 for (bio = (bl)->head; bio && ({ prefetch(bio->bi_next); 1; }); \
35 bio = bio->bi_next)
36
37static inline unsigned bio_list_size(const struct bio_list *bl)
38{
39 unsigned sz = 0;
40 struct bio *bio;
41
42 bio_list_for_each(bio, bl)
43 sz++;
44
45 return sz;
46}
47
22static inline void bio_list_add(struct bio_list *bl, struct bio *bio) 48static inline void bio_list_add(struct bio_list *bl, struct bio *bio)
23{ 49{
24 bio->bi_next = NULL; 50 bio->bi_next = NULL;
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index d8121234c347..7b0fcfc9eaa5 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -33,7 +33,6 @@
33struct crypt_io { 33struct crypt_io {
34 struct dm_target *target; 34 struct dm_target *target;
35 struct bio *base_bio; 35 struct bio *base_bio;
36 struct bio *first_clone;
37 struct work_struct work; 36 struct work_struct work;
38 atomic_t pending; 37 atomic_t pending;
39 int error; 38 int error;
@@ -107,6 +106,8 @@ struct crypt_config {
107 106
108static struct kmem_cache *_crypt_io_pool; 107static struct kmem_cache *_crypt_io_pool;
109 108
109static void clone_init(struct crypt_io *, struct bio *);
110
110/* 111/*
111 * Different IV generation algorithms: 112 * Different IV generation algorithms:
112 * 113 *
@@ -120,6 +121,9 @@ static struct kmem_cache *_crypt_io_pool;
120 * benbi: the 64-bit "big-endian 'narrow block'-count", starting at 1 121 * benbi: the 64-bit "big-endian 'narrow block'-count", starting at 1
121 * (needed for LRW-32-AES and possible other narrow block modes) 122 * (needed for LRW-32-AES and possible other narrow block modes)
122 * 123 *
124 * null: the initial vector is always zero. Provides compatibility with
125 * obsolete loop_fish2 devices. Do not use for new devices.
126 *
123 * plumb: unimplemented, see: 127 * plumb: unimplemented, see:
124 * http://article.gmane.org/gmane.linux.kernel.device-mapper.dm-crypt/454 128 * http://article.gmane.org/gmane.linux.kernel.device-mapper.dm-crypt/454
125 */ 129 */
@@ -256,6 +260,13 @@ static int crypt_iv_benbi_gen(struct crypt_config *cc, u8 *iv, sector_t sector)
256 return 0; 260 return 0;
257} 261}
258 262
263static int crypt_iv_null_gen(struct crypt_config *cc, u8 *iv, sector_t sector)
264{
265 memset(iv, 0, cc->iv_size);
266
267 return 0;
268}
269
259static struct crypt_iv_operations crypt_iv_plain_ops = { 270static struct crypt_iv_operations crypt_iv_plain_ops = {
260 .generator = crypt_iv_plain_gen 271 .generator = crypt_iv_plain_gen
261}; 272};
@@ -272,6 +283,10 @@ static struct crypt_iv_operations crypt_iv_benbi_ops = {
272 .generator = crypt_iv_benbi_gen 283 .generator = crypt_iv_benbi_gen
273}; 284};
274 285
286static struct crypt_iv_operations crypt_iv_null_ops = {
287 .generator = crypt_iv_null_gen
288};
289
275static int 290static int
276crypt_convert_scatterlist(struct crypt_config *cc, struct scatterlist *out, 291crypt_convert_scatterlist(struct crypt_config *cc, struct scatterlist *out,
277 struct scatterlist *in, unsigned int length, 292 struct scatterlist *in, unsigned int length,
@@ -378,36 +393,21 @@ static int crypt_convert(struct crypt_config *cc,
378 * This should never violate the device limitations 393 * This should never violate the device limitations
379 * May return a smaller bio when running out of pages 394 * May return a smaller bio when running out of pages
380 */ 395 */
381static struct bio * 396static struct bio *crypt_alloc_buffer(struct crypt_io *io, unsigned int size)
382crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
383 struct bio *base_bio, unsigned int *bio_vec_idx)
384{ 397{
398 struct crypt_config *cc = io->target->private;
385 struct bio *clone; 399 struct bio *clone;
386 unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT; 400 unsigned int nr_iovecs = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
387 gfp_t gfp_mask = GFP_NOIO | __GFP_HIGHMEM; 401 gfp_t gfp_mask = GFP_NOIO | __GFP_HIGHMEM;
388 unsigned int i; 402 unsigned int i;
389 403
390 if (base_bio) { 404 clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, cc->bs);
391 clone = bio_alloc_bioset(GFP_NOIO, base_bio->bi_max_vecs, cc->bs);
392 __bio_clone(clone, base_bio);
393 } else
394 clone = bio_alloc_bioset(GFP_NOIO, nr_iovecs, cc->bs);
395
396 if (!clone) 405 if (!clone)
397 return NULL; 406 return NULL;
398 407
399 clone->bi_destructor = dm_crypt_bio_destructor; 408 clone_init(io, clone);
400
401 /* if the last bio was not complete, continue where that one ended */
402 clone->bi_idx = *bio_vec_idx;
403 clone->bi_vcnt = *bio_vec_idx;
404 clone->bi_size = 0;
405 clone->bi_flags &= ~(1 << BIO_SEG_VALID);
406
407 /* clone->bi_idx pages have already been allocated */
408 size -= clone->bi_idx * PAGE_SIZE;
409 409
410 for (i = clone->bi_idx; i < nr_iovecs; i++) { 410 for (i = 0; i < nr_iovecs; i++) {
411 struct bio_vec *bv = bio_iovec_idx(clone, i); 411 struct bio_vec *bv = bio_iovec_idx(clone, i);
412 412
413 bv->bv_page = mempool_alloc(cc->page_pool, gfp_mask); 413 bv->bv_page = mempool_alloc(cc->page_pool, gfp_mask);
@@ -419,7 +419,7 @@ crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
419 * return a partially allocated bio, the caller will then try 419 * return a partially allocated bio, the caller will then try
420 * to allocate additional bios while submitting this partial bio 420 * to allocate additional bios while submitting this partial bio
421 */ 421 */
422 if ((i - clone->bi_idx) == (MIN_BIO_PAGES - 1)) 422 if (i == (MIN_BIO_PAGES - 1))
423 gfp_mask = (gfp_mask | __GFP_NOWARN) & ~__GFP_WAIT; 423 gfp_mask = (gfp_mask | __GFP_NOWARN) & ~__GFP_WAIT;
424 424
425 bv->bv_offset = 0; 425 bv->bv_offset = 0;
@@ -438,12 +438,6 @@ crypt_alloc_buffer(struct crypt_config *cc, unsigned int size,
438 return NULL; 438 return NULL;
439 } 439 }
440 440
441 /*
442 * Remember the last bio_vec allocated to be able
443 * to correctly continue after the splitting.
444 */
445 *bio_vec_idx = clone->bi_vcnt;
446
447 return clone; 441 return clone;
448} 442}
449 443
@@ -495,9 +489,6 @@ static void dec_pending(struct crypt_io *io, int error)
495 if (!atomic_dec_and_test(&io->pending)) 489 if (!atomic_dec_and_test(&io->pending))
496 return; 490 return;
497 491
498 if (io->first_clone)
499 bio_put(io->first_clone);
500
501 bio_endio(io->base_bio, io->base_bio->bi_size, io->error); 492 bio_endio(io->base_bio, io->base_bio->bi_size, io->error);
502 493
503 mempool_free(io, cc->io_pool); 494 mempool_free(io, cc->io_pool);
@@ -562,6 +553,7 @@ static void clone_init(struct crypt_io *io, struct bio *clone)
562 clone->bi_end_io = crypt_endio; 553 clone->bi_end_io = crypt_endio;
563 clone->bi_bdev = cc->dev->bdev; 554 clone->bi_bdev = cc->dev->bdev;
564 clone->bi_rw = io->base_bio->bi_rw; 555 clone->bi_rw = io->base_bio->bi_rw;
556 clone->bi_destructor = dm_crypt_bio_destructor;
565} 557}
566 558
567static void process_read(struct crypt_io *io) 559static void process_read(struct crypt_io *io)
@@ -585,7 +577,6 @@ static void process_read(struct crypt_io *io)
585 } 577 }
586 578
587 clone_init(io, clone); 579 clone_init(io, clone);
588 clone->bi_destructor = dm_crypt_bio_destructor;
589 clone->bi_idx = 0; 580 clone->bi_idx = 0;
590 clone->bi_vcnt = bio_segments(base_bio); 581 clone->bi_vcnt = bio_segments(base_bio);
591 clone->bi_size = base_bio->bi_size; 582 clone->bi_size = base_bio->bi_size;
@@ -604,7 +595,6 @@ static void process_write(struct crypt_io *io)
604 struct convert_context ctx; 595 struct convert_context ctx;
605 unsigned remaining = base_bio->bi_size; 596 unsigned remaining = base_bio->bi_size;
606 sector_t sector = base_bio->bi_sector - io->target->begin; 597 sector_t sector = base_bio->bi_sector - io->target->begin;
607 unsigned bvec_idx = 0;
608 598
609 atomic_inc(&io->pending); 599 atomic_inc(&io->pending);
610 600
@@ -615,14 +605,14 @@ static void process_write(struct crypt_io *io)
615 * so repeat the whole process until all the data can be handled. 605 * so repeat the whole process until all the data can be handled.
616 */ 606 */
617 while (remaining) { 607 while (remaining) {
618 clone = crypt_alloc_buffer(cc, base_bio->bi_size, 608 clone = crypt_alloc_buffer(io, remaining);
619 io->first_clone, &bvec_idx);
620 if (unlikely(!clone)) { 609 if (unlikely(!clone)) {
621 dec_pending(io, -ENOMEM); 610 dec_pending(io, -ENOMEM);
622 return; 611 return;
623 } 612 }
624 613
625 ctx.bio_out = clone; 614 ctx.bio_out = clone;
615 ctx.idx_out = 0;
626 616
627 if (unlikely(crypt_convert(cc, &ctx) < 0)) { 617 if (unlikely(crypt_convert(cc, &ctx) < 0)) {
628 crypt_free_buffer_pages(cc, clone, clone->bi_size); 618 crypt_free_buffer_pages(cc, clone, clone->bi_size);
@@ -631,31 +621,26 @@ static void process_write(struct crypt_io *io)
631 return; 621 return;
632 } 622 }
633 623
634 clone_init(io, clone); 624 /* crypt_convert should have filled the clone bio */
635 clone->bi_sector = cc->start + sector; 625 BUG_ON(ctx.idx_out < clone->bi_vcnt);
636
637 if (!io->first_clone) {
638 /*
639 * hold a reference to the first clone, because it
640 * holds the bio_vec array and that can't be freed
641 * before all other clones are released
642 */
643 bio_get(clone);
644 io->first_clone = clone;
645 }
646 626
627 clone->bi_sector = cc->start + sector;
647 remaining -= clone->bi_size; 628 remaining -= clone->bi_size;
648 sector += bio_sectors(clone); 629 sector += bio_sectors(clone);
649 630
650 /* prevent bio_put of first_clone */ 631 /* Grab another reference to the io struct
632 * before we kick off the request */
651 if (remaining) 633 if (remaining)
652 atomic_inc(&io->pending); 634 atomic_inc(&io->pending);
653 635
654 generic_make_request(clone); 636 generic_make_request(clone);
655 637
638 /* Do not reference clone after this - it
639 * may be gone already. */
640
656 /* out of memory -> run queues */ 641 /* out of memory -> run queues */
657 if (remaining) 642 if (remaining)
658 congestion_wait(bio_data_dir(clone), HZ/100); 643 congestion_wait(WRITE, HZ/100);
659 } 644 }
660} 645}
661 646
@@ -832,6 +817,8 @@ static int crypt_ctr(struct dm_target *ti, unsigned int argc, char **argv)
832 cc->iv_gen_ops = &crypt_iv_essiv_ops; 817 cc->iv_gen_ops = &crypt_iv_essiv_ops;
833 else if (strcmp(ivmode, "benbi") == 0) 818 else if (strcmp(ivmode, "benbi") == 0)
834 cc->iv_gen_ops = &crypt_iv_benbi_ops; 819 cc->iv_gen_ops = &crypt_iv_benbi_ops;
820 else if (strcmp(ivmode, "null") == 0)
821 cc->iv_gen_ops = &crypt_iv_null_ops;
835 else { 822 else {
836 ti->error = "Invalid IV mode"; 823 ti->error = "Invalid IV mode";
837 goto bad2; 824 goto bad2;
@@ -954,10 +941,12 @@ static int crypt_map(struct dm_target *ti, struct bio *bio,
954 struct crypt_config *cc = ti->private; 941 struct crypt_config *cc = ti->private;
955 struct crypt_io *io; 942 struct crypt_io *io;
956 943
944 if (bio_barrier(bio))
945 return -EOPNOTSUPP;
946
957 io = mempool_alloc(cc->io_pool, GFP_NOIO); 947 io = mempool_alloc(cc->io_pool, GFP_NOIO);
958 io->target = ti; 948 io->target = ti;
959 io->base_bio = bio; 949 io->base_bio = bio;
960 io->first_clone = NULL;
961 io->error = io->post_process = 0; 950 io->error = io->post_process = 0;
962 atomic_set(&io->pending, 0); 951 atomic_set(&io->pending, 0);
963 kcryptd_queue_io(io); 952 kcryptd_queue_io(io);
@@ -1057,7 +1046,7 @@ error:
1057 1046
1058static struct target_type crypt_target = { 1047static struct target_type crypt_target = {
1059 .name = "crypt", 1048 .name = "crypt",
1060 .version= {1, 3, 0}, 1049 .version= {1, 5, 0},
1061 .module = THIS_MODULE, 1050 .module = THIS_MODULE,
1062 .ctr = crypt_ctr, 1051 .ctr = crypt_ctr,
1063 .dtr = crypt_dtr, 1052 .dtr = crypt_dtr,
diff --git a/drivers/md/dm-delay.c b/drivers/md/dm-delay.c
new file mode 100644
index 000000000000..52c7cf9e5803
--- /dev/null
+++ b/drivers/md/dm-delay.c
@@ -0,0 +1,383 @@
1/*
2 * Copyright (C) 2005-2007 Red Hat GmbH
3 *
4 * A target that delays reads and/or writes and can send
5 * them to different devices.
6 *
7 * This file is released under the GPL.
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/blkdev.h>
13#include <linux/bio.h>
14#include <linux/slab.h>
15
16#include "dm.h"
17#include "dm-bio-list.h"
18
19#define DM_MSG_PREFIX "delay"
20
21struct delay_c {
22 struct timer_list delay_timer;
23 struct semaphore timer_lock;
24 struct work_struct flush_expired_bios;
25 struct list_head delayed_bios;
26 atomic_t may_delay;
27 mempool_t *delayed_pool;
28
29 struct dm_dev *dev_read;
30 sector_t start_read;
31 unsigned read_delay;
32 unsigned reads;
33
34 struct dm_dev *dev_write;
35 sector_t start_write;
36 unsigned write_delay;
37 unsigned writes;
38};
39
40struct delay_info {
41 struct delay_c *context;
42 struct list_head list;
43 struct bio *bio;
44 unsigned long expires;
45};
46
47static DEFINE_MUTEX(delayed_bios_lock);
48
49static struct workqueue_struct *kdelayd_wq;
50static struct kmem_cache *delayed_cache;
51
52static void handle_delayed_timer(unsigned long data)
53{
54 struct delay_c *dc = (struct delay_c *)data;
55
56 queue_work(kdelayd_wq, &dc->flush_expired_bios);
57}
58
59static void queue_timeout(struct delay_c *dc, unsigned long expires)
60{
61 down(&dc->timer_lock);
62
63 if (!timer_pending(&dc->delay_timer) || expires < dc->delay_timer.expires)
64 mod_timer(&dc->delay_timer, expires);
65
66 up(&dc->timer_lock);
67}
68
69static void flush_bios(struct bio *bio)
70{
71 struct bio *n;
72
73 while (bio) {
74 n = bio->bi_next;
75 bio->bi_next = NULL;
76 generic_make_request(bio);
77 bio = n;
78 }
79}
80
81static struct bio *flush_delayed_bios(struct delay_c *dc, int flush_all)
82{
83 struct delay_info *delayed, *next;
84 unsigned long next_expires = 0;
85 int start_timer = 0;
86 BIO_LIST(flush_bios);
87
88 mutex_lock(&delayed_bios_lock);
89 list_for_each_entry_safe(delayed, next, &dc->delayed_bios, list) {
90 if (flush_all || time_after_eq(jiffies, delayed->expires)) {
91 list_del(&delayed->list);
92 bio_list_add(&flush_bios, delayed->bio);
93 if ((bio_data_dir(delayed->bio) == WRITE))
94 delayed->context->writes--;
95 else
96 delayed->context->reads--;
97 mempool_free(delayed, dc->delayed_pool);
98 continue;
99 }
100
101 if (!start_timer) {
102 start_timer = 1;
103 next_expires = delayed->expires;
104 } else
105 next_expires = min(next_expires, delayed->expires);
106 }
107
108 mutex_unlock(&delayed_bios_lock);
109
110 if (start_timer)
111 queue_timeout(dc, next_expires);
112
113 return bio_list_get(&flush_bios);
114}
115
116static void flush_expired_bios(struct work_struct *work)
117{
118 struct delay_c *dc;
119
120 dc = container_of(work, struct delay_c, flush_expired_bios);
121 flush_bios(flush_delayed_bios(dc, 0));
122}
123
124/*
125 * Mapping parameters:
126 * <device> <offset> <delay> [<write_device> <write_offset> <write_delay>]
127 *
128 * With separate write parameters, the first set is only used for reads.
129 * Delays are specified in milliseconds.
130 */
131static int delay_ctr(struct dm_target *ti, unsigned int argc, char **argv)
132{
133 struct delay_c *dc;
134 unsigned long long tmpll;
135
136 if (argc != 3 && argc != 6) {
137 ti->error = "requires exactly 3 or 6 arguments";
138 return -EINVAL;
139 }
140
141 dc = kmalloc(sizeof(*dc), GFP_KERNEL);
142 if (!dc) {
143 ti->error = "Cannot allocate context";
144 return -ENOMEM;
145 }
146
147 dc->reads = dc->writes = 0;
148
149 if (sscanf(argv[1], "%llu", &tmpll) != 1) {
150 ti->error = "Invalid device sector";
151 goto bad;
152 }
153 dc->start_read = tmpll;
154
155 if (sscanf(argv[2], "%u", &dc->read_delay) != 1) {
156 ti->error = "Invalid delay";
157 goto bad;
158 }
159
160 if (dm_get_device(ti, argv[0], dc->start_read, ti->len,
161 dm_table_get_mode(ti->table), &dc->dev_read)) {
162 ti->error = "Device lookup failed";
163 goto bad;
164 }
165
166 if (argc == 3) {
167 dc->dev_write = NULL;
168 goto out;
169 }
170
171 if (sscanf(argv[4], "%llu", &tmpll) != 1) {
172 ti->error = "Invalid write device sector";
173 goto bad;
174 }
175 dc->start_write = tmpll;
176
177 if (sscanf(argv[5], "%u", &dc->write_delay) != 1) {
178 ti->error = "Invalid write delay";
179 goto bad;
180 }
181
182 if (dm_get_device(ti, argv[3], dc->start_write, ti->len,
183 dm_table_get_mode(ti->table), &dc->dev_write)) {
184 ti->error = "Write device lookup failed";
185 dm_put_device(ti, dc->dev_read);
186 goto bad;
187 }
188
189out:
190 dc->delayed_pool = mempool_create_slab_pool(128, delayed_cache);
191 if (!dc->delayed_pool) {
192 DMERR("Couldn't create delayed bio pool.");
193 goto bad;
194 }
195
196 init_timer(&dc->delay_timer);
197 dc->delay_timer.function = handle_delayed_timer;
198 dc->delay_timer.data = (unsigned long)dc;
199
200 INIT_WORK(&dc->flush_expired_bios, flush_expired_bios);
201 INIT_LIST_HEAD(&dc->delayed_bios);
202 init_MUTEX(&dc->timer_lock);
203 atomic_set(&dc->may_delay, 1);
204
205 ti->private = dc;
206 return 0;
207
208bad:
209 kfree(dc);
210 return -EINVAL;
211}
212
213static void delay_dtr(struct dm_target *ti)
214{
215 struct delay_c *dc = ti->private;
216
217 flush_workqueue(kdelayd_wq);
218
219 dm_put_device(ti, dc->dev_read);
220
221 if (dc->dev_write)
222 dm_put_device(ti, dc->dev_write);
223
224 mempool_destroy(dc->delayed_pool);
225 kfree(dc);
226}
227
228static int delay_bio(struct delay_c *dc, int delay, struct bio *bio)
229{
230 struct delay_info *delayed;
231 unsigned long expires = 0;
232
233 if (!delay || !atomic_read(&dc->may_delay))
234 return 1;
235
236 delayed = mempool_alloc(dc->delayed_pool, GFP_NOIO);
237
238 delayed->context = dc;
239 delayed->bio = bio;
240 delayed->expires = expires = jiffies + (delay * HZ / 1000);
241
242 mutex_lock(&delayed_bios_lock);
243
244 if (bio_data_dir(bio) == WRITE)
245 dc->writes++;
246 else
247 dc->reads++;
248
249 list_add_tail(&delayed->list, &dc->delayed_bios);
250
251 mutex_unlock(&delayed_bios_lock);
252
253 queue_timeout(dc, expires);
254
255 return 0;
256}
257
258static void delay_presuspend(struct dm_target *ti)
259{
260 struct delay_c *dc = ti->private;
261
262 atomic_set(&dc->may_delay, 0);
263 del_timer_sync(&dc->delay_timer);
264 flush_bios(flush_delayed_bios(dc, 1));
265}
266
267static void delay_resume(struct dm_target *ti)
268{
269 struct delay_c *dc = ti->private;
270
271 atomic_set(&dc->may_delay, 1);
272}
273
274static int delay_map(struct dm_target *ti, struct bio *bio,
275 union map_info *map_context)
276{
277 struct delay_c *dc = ti->private;
278
279 if ((bio_data_dir(bio) == WRITE) && (dc->dev_write)) {
280 bio->bi_bdev = dc->dev_write->bdev;
281 bio->bi_sector = dc->start_write +
282 (bio->bi_sector - ti->begin);
283
284 return delay_bio(dc, dc->write_delay, bio);
285 }
286
287 bio->bi_bdev = dc->dev_read->bdev;
288 bio->bi_sector = dc->start_read +
289 (bio->bi_sector - ti->begin);
290
291 return delay_bio(dc, dc->read_delay, bio);
292}
293
294static int delay_status(struct dm_target *ti, status_type_t type,
295 char *result, unsigned maxlen)
296{
297 struct delay_c *dc = ti->private;
298 int sz = 0;
299
300 switch (type) {
301 case STATUSTYPE_INFO:
302 DMEMIT("%u %u", dc->reads, dc->writes);
303 break;
304
305 case STATUSTYPE_TABLE:
306 DMEMIT("%s %llu %u", dc->dev_read->name,
307 (unsigned long long) dc->start_read,
308 dc->read_delay);
309 if (dc->dev_write)
310 DMEMIT("%s %llu %u", dc->dev_write->name,
311 (unsigned long long) dc->start_write,
312 dc->write_delay);
313 break;
314 }
315
316 return 0;
317}
318
319static struct target_type delay_target = {
320 .name = "delay",
321 .version = {1, 0, 2},
322 .module = THIS_MODULE,
323 .ctr = delay_ctr,
324 .dtr = delay_dtr,
325 .map = delay_map,
326 .presuspend = delay_presuspend,
327 .resume = delay_resume,
328 .status = delay_status,
329};
330
331static int __init dm_delay_init(void)
332{
333 int r = -ENOMEM;
334
335 kdelayd_wq = create_workqueue("kdelayd");
336 if (!kdelayd_wq) {
337 DMERR("Couldn't start kdelayd");
338 goto bad_queue;
339 }
340
341 delayed_cache = kmem_cache_create("dm-delay",
342 sizeof(struct delay_info),
343 __alignof__(struct delay_info),
344 0, NULL, NULL);
345 if (!delayed_cache) {
346 DMERR("Couldn't create delayed bio cache.");
347 goto bad_memcache;
348 }
349
350 r = dm_register_target(&delay_target);
351 if (r < 0) {
352 DMERR("register failed %d", r);
353 goto bad_register;
354 }
355
356 return 0;
357
358bad_register:
359 kmem_cache_destroy(delayed_cache);
360bad_memcache:
361 destroy_workqueue(kdelayd_wq);
362bad_queue:
363 return r;
364}
365
366static void __exit dm_delay_exit(void)
367{
368 int r = dm_unregister_target(&delay_target);
369
370 if (r < 0)
371 DMERR("unregister failed %d", r);
372
373 kmem_cache_destroy(delayed_cache);
374 destroy_workqueue(kdelayd_wq);
375}
376
377/* Module hooks */
378module_init(dm_delay_init);
379module_exit(dm_delay_exit);
380
381MODULE_DESCRIPTION(DM_NAME " delay target");
382MODULE_AUTHOR("Heinz Mauelshagen <mauelshagen@redhat.com>");
383MODULE_LICENSE("GPL");
diff --git a/drivers/md/dm-exception-store.c b/drivers/md/dm-exception-store.c
index 99cdffa7fbfe..07e0a0c84f6e 100644
--- a/drivers/md/dm-exception-store.c
+++ b/drivers/md/dm-exception-store.c
@@ -1,7 +1,8 @@
1/* 1/*
2 * dm-snapshot.c 2 * dm-exception-store.c
3 * 3 *
4 * Copyright (C) 2001-2002 Sistina Software (UK) Limited. 4 * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
5 * Copyright (C) 2006 Red Hat GmbH
5 * 6 *
6 * This file is released under the GPL. 7 * This file is released under the GPL.
7 */ 8 */
@@ -123,6 +124,7 @@ struct pstore {
123 atomic_t pending_count; 124 atomic_t pending_count;
124 uint32_t callback_count; 125 uint32_t callback_count;
125 struct commit_callback *callbacks; 126 struct commit_callback *callbacks;
127 struct dm_io_client *io_client;
126}; 128};
127 129
128static inline unsigned int sectors_to_pages(unsigned int sectors) 130static inline unsigned int sectors_to_pages(unsigned int sectors)
@@ -159,14 +161,20 @@ static void free_area(struct pstore *ps)
159 */ 161 */
160static int chunk_io(struct pstore *ps, uint32_t chunk, int rw) 162static int chunk_io(struct pstore *ps, uint32_t chunk, int rw)
161{ 163{
162 struct io_region where; 164 struct io_region where = {
163 unsigned long bits; 165 .bdev = ps->snap->cow->bdev,
164 166 .sector = ps->snap->chunk_size * chunk,
165 where.bdev = ps->snap->cow->bdev; 167 .count = ps->snap->chunk_size,
166 where.sector = ps->snap->chunk_size * chunk; 168 };
167 where.count = ps->snap->chunk_size; 169 struct dm_io_request io_req = {
168 170 .bi_rw = rw,
169 return dm_io_sync_vm(1, &where, rw, ps->area, &bits); 171 .mem.type = DM_IO_VMA,
172 .mem.ptr.vma = ps->area,
173 .client = ps->io_client,
174 .notify.fn = NULL,
175 };
176
177 return dm_io(&io_req, 1, &where, NULL);
170} 178}
171 179
172/* 180/*
@@ -213,17 +221,18 @@ static int read_header(struct pstore *ps, int *new_snapshot)
213 chunk_size_supplied = 0; 221 chunk_size_supplied = 0;
214 } 222 }
215 223
216 r = dm_io_get(sectors_to_pages(ps->snap->chunk_size)); 224 ps->io_client = dm_io_client_create(sectors_to_pages(ps->snap->
217 if (r) 225 chunk_size));
218 return r; 226 if (IS_ERR(ps->io_client))
227 return PTR_ERR(ps->io_client);
219 228
220 r = alloc_area(ps); 229 r = alloc_area(ps);
221 if (r) 230 if (r)
222 goto bad1; 231 return r;
223 232
224 r = chunk_io(ps, 0, READ); 233 r = chunk_io(ps, 0, READ);
225 if (r) 234 if (r)
226 goto bad2; 235 goto bad;
227 236
228 dh = (struct disk_header *) ps->area; 237 dh = (struct disk_header *) ps->area;
229 238
@@ -235,7 +244,7 @@ static int read_header(struct pstore *ps, int *new_snapshot)
235 if (le32_to_cpu(dh->magic) != SNAP_MAGIC) { 244 if (le32_to_cpu(dh->magic) != SNAP_MAGIC) {
236 DMWARN("Invalid or corrupt snapshot"); 245 DMWARN("Invalid or corrupt snapshot");
237 r = -ENXIO; 246 r = -ENXIO;
238 goto bad2; 247 goto bad;
239 } 248 }
240 249
241 *new_snapshot = 0; 250 *new_snapshot = 0;
@@ -252,27 +261,22 @@ static int read_header(struct pstore *ps, int *new_snapshot)
252 (unsigned long long)ps->snap->chunk_size); 261 (unsigned long long)ps->snap->chunk_size);
253 262
254 /* We had a bogus chunk_size. Fix stuff up. */ 263 /* We had a bogus chunk_size. Fix stuff up. */
255 dm_io_put(sectors_to_pages(ps->snap->chunk_size));
256 free_area(ps); 264 free_area(ps);
257 265
258 ps->snap->chunk_size = chunk_size; 266 ps->snap->chunk_size = chunk_size;
259 ps->snap->chunk_mask = chunk_size - 1; 267 ps->snap->chunk_mask = chunk_size - 1;
260 ps->snap->chunk_shift = ffs(chunk_size) - 1; 268 ps->snap->chunk_shift = ffs(chunk_size) - 1;
261 269
262 r = dm_io_get(sectors_to_pages(chunk_size)); 270 r = dm_io_client_resize(sectors_to_pages(ps->snap->chunk_size),
271 ps->io_client);
263 if (r) 272 if (r)
264 return r; 273 return r;
265 274
266 r = alloc_area(ps); 275 r = alloc_area(ps);
267 if (r) 276 return r;
268 goto bad1;
269
270 return 0;
271 277
272bad2: 278bad:
273 free_area(ps); 279 free_area(ps);
274bad1:
275 dm_io_put(sectors_to_pages(ps->snap->chunk_size));
276 return r; 280 return r;
277} 281}
278 282
@@ -405,7 +409,7 @@ static void persistent_destroy(struct exception_store *store)
405{ 409{
406 struct pstore *ps = get_info(store); 410 struct pstore *ps = get_info(store);
407 411
408 dm_io_put(sectors_to_pages(ps->snap->chunk_size)); 412 dm_io_client_destroy(ps->io_client);
409 vfree(ps->callbacks); 413 vfree(ps->callbacks);
410 free_area(ps); 414 free_area(ps);
411 kfree(ps); 415 kfree(ps);
diff --git a/drivers/md/dm-hw-handler.h b/drivers/md/dm-hw-handler.h
index 32eff28e4adc..e0832e6fcf36 100644
--- a/drivers/md/dm-hw-handler.h
+++ b/drivers/md/dm-hw-handler.h
@@ -16,6 +16,7 @@
16struct hw_handler_type; 16struct hw_handler_type;
17struct hw_handler { 17struct hw_handler {
18 struct hw_handler_type *type; 18 struct hw_handler_type *type;
19 struct mapped_device *md;
19 void *context; 20 void *context;
20}; 21};
21 22
diff --git a/drivers/md/dm-io.c b/drivers/md/dm-io.c
index 8bdc8a87b249..352c6fbeac53 100644
--- a/drivers/md/dm-io.c
+++ b/drivers/md/dm-io.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (C) 2003 Sistina Software 2 * Copyright (C) 2003 Sistina Software
3 * Copyright (C) 2006 Red Hat GmbH
3 * 4 *
4 * This file is released under the GPL. 5 * This file is released under the GPL.
5 */ 6 */
@@ -12,13 +13,17 @@
12#include <linux/sched.h> 13#include <linux/sched.h>
13#include <linux/slab.h> 14#include <linux/slab.h>
14 15
15static struct bio_set *_bios; 16struct dm_io_client {
17 mempool_t *pool;
18 struct bio_set *bios;
19};
16 20
17/* FIXME: can we shrink this ? */ 21/* FIXME: can we shrink this ? */
18struct io { 22struct io {
19 unsigned long error; 23 unsigned long error;
20 atomic_t count; 24 atomic_t count;
21 struct task_struct *sleeper; 25 struct task_struct *sleeper;
26 struct dm_io_client *client;
22 io_notify_fn callback; 27 io_notify_fn callback;
23 void *context; 28 void *context;
24}; 29};
@@ -26,63 +31,58 @@ struct io {
26/* 31/*
27 * io contexts are only dynamically allocated for asynchronous 32 * io contexts are only dynamically allocated for asynchronous
28 * io. Since async io is likely to be the majority of io we'll 33 * io. Since async io is likely to be the majority of io we'll
29 * have the same number of io contexts as buffer heads ! (FIXME: 34 * have the same number of io contexts as bios! (FIXME: must reduce this).
30 * must reduce this).
31 */ 35 */
32static unsigned _num_ios;
33static mempool_t *_io_pool;
34 36
35static unsigned int pages_to_ios(unsigned int pages) 37static unsigned int pages_to_ios(unsigned int pages)
36{ 38{
37 return 4 * pages; /* too many ? */ 39 return 4 * pages; /* too many ? */
38} 40}
39 41
40static int resize_pool(unsigned int new_ios) 42/*
43 * Create a client with mempool and bioset.
44 */
45struct dm_io_client *dm_io_client_create(unsigned num_pages)
41{ 46{
42 int r = 0; 47 unsigned ios = pages_to_ios(num_pages);
43 48 struct dm_io_client *client;
44 if (_io_pool) {
45 if (new_ios == 0) {
46 /* free off the pool */
47 mempool_destroy(_io_pool);
48 _io_pool = NULL;
49 bioset_free(_bios);
50
51 } else {
52 /* resize the pool */
53 r = mempool_resize(_io_pool, new_ios, GFP_KERNEL);
54 }
55 49
56 } else { 50 client = kmalloc(sizeof(*client), GFP_KERNEL);
57 /* create new pool */ 51 if (!client)
58 _io_pool = mempool_create_kmalloc_pool(new_ios, 52 return ERR_PTR(-ENOMEM);
59 sizeof(struct io)); 53
60 if (!_io_pool) 54 client->pool = mempool_create_kmalloc_pool(ios, sizeof(struct io));
61 return -ENOMEM; 55 if (!client->pool)
62 56 goto bad;
63 _bios = bioset_create(16, 16);
64 if (!_bios) {
65 mempool_destroy(_io_pool);
66 _io_pool = NULL;
67 return -ENOMEM;
68 }
69 }
70 57
71 if (!r) 58 client->bios = bioset_create(16, 16);
72 _num_ios = new_ios; 59 if (!client->bios)
60 goto bad;
73 61
74 return r; 62 return client;
63
64 bad:
65 if (client->pool)
66 mempool_destroy(client->pool);
67 kfree(client);
68 return ERR_PTR(-ENOMEM);
75} 69}
70EXPORT_SYMBOL(dm_io_client_create);
76 71
77int dm_io_get(unsigned int num_pages) 72int dm_io_client_resize(unsigned num_pages, struct dm_io_client *client)
78{ 73{
79 return resize_pool(_num_ios + pages_to_ios(num_pages)); 74 return mempool_resize(client->pool, pages_to_ios(num_pages),
75 GFP_KERNEL);
80} 76}
77EXPORT_SYMBOL(dm_io_client_resize);
81 78
82void dm_io_put(unsigned int num_pages) 79void dm_io_client_destroy(struct dm_io_client *client)
83{ 80{
84 resize_pool(_num_ios - pages_to_ios(num_pages)); 81 mempool_destroy(client->pool);
82 bioset_free(client->bios);
83 kfree(client);
85} 84}
85EXPORT_SYMBOL(dm_io_client_destroy);
86 86
87/*----------------------------------------------------------------- 87/*-----------------------------------------------------------------
88 * We need to keep track of which region a bio is doing io for. 88 * We need to keep track of which region a bio is doing io for.
@@ -118,7 +118,7 @@ static void dec_count(struct io *io, unsigned int region, int error)
118 io_notify_fn fn = io->callback; 118 io_notify_fn fn = io->callback;
119 void *context = io->context; 119 void *context = io->context;
120 120
121 mempool_free(io, _io_pool); 121 mempool_free(io, io->client->pool);
122 fn(r, context); 122 fn(r, context);
123 } 123 }
124 } 124 }
@@ -126,7 +126,8 @@ static void dec_count(struct io *io, unsigned int region, int error)
126 126
127static int endio(struct bio *bio, unsigned int done, int error) 127static int endio(struct bio *bio, unsigned int done, int error)
128{ 128{
129 struct io *io = (struct io *) bio->bi_private; 129 struct io *io;
130 unsigned region;
130 131
131 /* keep going until we've finished */ 132 /* keep going until we've finished */
132 if (bio->bi_size) 133 if (bio->bi_size)
@@ -135,10 +136,17 @@ static int endio(struct bio *bio, unsigned int done, int error)
135 if (error && bio_data_dir(bio) == READ) 136 if (error && bio_data_dir(bio) == READ)
136 zero_fill_bio(bio); 137 zero_fill_bio(bio);
137 138
138 dec_count(io, bio_get_region(bio), error); 139 /*
140 * The bio destructor in bio_put() may use the io object.
141 */
142 io = bio->bi_private;
143 region = bio_get_region(bio);
144
139 bio->bi_max_vecs++; 145 bio->bi_max_vecs++;
140 bio_put(bio); 146 bio_put(bio);
141 147
148 dec_count(io, region, error);
149
142 return 0; 150 return 0;
143} 151}
144 152
@@ -209,6 +217,9 @@ static void bvec_dp_init(struct dpages *dp, struct bio_vec *bvec)
209 dp->context_ptr = bvec; 217 dp->context_ptr = bvec;
210} 218}
211 219
220/*
221 * Functions for getting the pages from a VMA.
222 */
212static void vm_get_page(struct dpages *dp, 223static void vm_get_page(struct dpages *dp,
213 struct page **p, unsigned long *len, unsigned *offset) 224 struct page **p, unsigned long *len, unsigned *offset)
214{ 225{
@@ -233,7 +244,34 @@ static void vm_dp_init(struct dpages *dp, void *data)
233 244
234static void dm_bio_destructor(struct bio *bio) 245static void dm_bio_destructor(struct bio *bio)
235{ 246{
236 bio_free(bio, _bios); 247 struct io *io = bio->bi_private;
248
249 bio_free(bio, io->client->bios);
250}
251
252/*
253 * Functions for getting the pages from kernel memory.
254 */
255static void km_get_page(struct dpages *dp, struct page **p, unsigned long *len,
256 unsigned *offset)
257{
258 *p = virt_to_page(dp->context_ptr);
259 *offset = dp->context_u;
260 *len = PAGE_SIZE - dp->context_u;
261}
262
263static void km_next_page(struct dpages *dp)
264{
265 dp->context_ptr += PAGE_SIZE - dp->context_u;
266 dp->context_u = 0;
267}
268
269static void km_dp_init(struct dpages *dp, void *data)
270{
271 dp->get_page = km_get_page;
272 dp->next_page = km_next_page;
273 dp->context_u = ((unsigned long) data) & (PAGE_SIZE - 1);
274 dp->context_ptr = data;
237} 275}
238 276
239/*----------------------------------------------------------------- 277/*-----------------------------------------------------------------
@@ -256,7 +294,7 @@ static void do_region(int rw, unsigned int region, struct io_region *where,
256 * to hide it from bio_add_page(). 294 * to hide it from bio_add_page().
257 */ 295 */
258 num_bvecs = (remaining / (PAGE_SIZE >> SECTOR_SHIFT)) + 2; 296 num_bvecs = (remaining / (PAGE_SIZE >> SECTOR_SHIFT)) + 2;
259 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, _bios); 297 bio = bio_alloc_bioset(GFP_NOIO, num_bvecs, io->client->bios);
260 bio->bi_sector = where->sector + (where->count - remaining); 298 bio->bi_sector = where->sector + (where->count - remaining);
261 bio->bi_bdev = where->bdev; 299 bio->bi_bdev = where->bdev;
262 bio->bi_end_io = endio; 300 bio->bi_end_io = endio;
@@ -311,8 +349,9 @@ static void dispatch_io(int rw, unsigned int num_regions,
311 dec_count(io, 0, 0); 349 dec_count(io, 0, 0);
312} 350}
313 351
314static int sync_io(unsigned int num_regions, struct io_region *where, 352static int sync_io(struct dm_io_client *client, unsigned int num_regions,
315 int rw, struct dpages *dp, unsigned long *error_bits) 353 struct io_region *where, int rw, struct dpages *dp,
354 unsigned long *error_bits)
316{ 355{
317 struct io io; 356 struct io io;
318 357
@@ -324,6 +363,7 @@ static int sync_io(unsigned int num_regions, struct io_region *where,
324 io.error = 0; 363 io.error = 0;
325 atomic_set(&io.count, 1); /* see dispatch_io() */ 364 atomic_set(&io.count, 1); /* see dispatch_io() */
326 io.sleeper = current; 365 io.sleeper = current;
366 io.client = client;
327 367
328 dispatch_io(rw, num_regions, where, dp, &io, 1); 368 dispatch_io(rw, num_regions, where, dp, &io, 1);
329 369
@@ -340,12 +380,15 @@ static int sync_io(unsigned int num_regions, struct io_region *where,
340 if (atomic_read(&io.count)) 380 if (atomic_read(&io.count))
341 return -EINTR; 381 return -EINTR;
342 382
343 *error_bits = io.error; 383 if (error_bits)
384 *error_bits = io.error;
385
344 return io.error ? -EIO : 0; 386 return io.error ? -EIO : 0;
345} 387}
346 388
347static int async_io(unsigned int num_regions, struct io_region *where, int rw, 389static int async_io(struct dm_io_client *client, unsigned int num_regions,
348 struct dpages *dp, io_notify_fn fn, void *context) 390 struct io_region *where, int rw, struct dpages *dp,
391 io_notify_fn fn, void *context)
349{ 392{
350 struct io *io; 393 struct io *io;
351 394
@@ -355,10 +398,11 @@ static int async_io(unsigned int num_regions, struct io_region *where, int rw,
355 return -EIO; 398 return -EIO;
356 } 399 }
357 400
358 io = mempool_alloc(_io_pool, GFP_NOIO); 401 io = mempool_alloc(client->pool, GFP_NOIO);
359 io->error = 0; 402 io->error = 0;
360 atomic_set(&io->count, 1); /* see dispatch_io() */ 403 atomic_set(&io->count, 1); /* see dispatch_io() */
361 io->sleeper = NULL; 404 io->sleeper = NULL;
405 io->client = client;
362 io->callback = fn; 406 io->callback = fn;
363 io->context = context; 407 io->context = context;
364 408
@@ -366,61 +410,51 @@ static int async_io(unsigned int num_regions, struct io_region *where, int rw,
366 return 0; 410 return 0;
367} 411}
368 412
369int dm_io_sync(unsigned int num_regions, struct io_region *where, int rw, 413static int dp_init(struct dm_io_request *io_req, struct dpages *dp)
370 struct page_list *pl, unsigned int offset,
371 unsigned long *error_bits)
372{ 414{
373 struct dpages dp; 415 /* Set up dpages based on memory type */
374 list_dp_init(&dp, pl, offset); 416 switch (io_req->mem.type) {
375 return sync_io(num_regions, where, rw, &dp, error_bits); 417 case DM_IO_PAGE_LIST:
376} 418 list_dp_init(dp, io_req->mem.ptr.pl, io_req->mem.offset);
419 break;
420
421 case DM_IO_BVEC:
422 bvec_dp_init(dp, io_req->mem.ptr.bvec);
423 break;
424
425 case DM_IO_VMA:
426 vm_dp_init(dp, io_req->mem.ptr.vma);
427 break;
428
429 case DM_IO_KMEM:
430 km_dp_init(dp, io_req->mem.ptr.addr);
431 break;
432
433 default:
434 return -EINVAL;
435 }
377 436
378int dm_io_sync_bvec(unsigned int num_regions, struct io_region *where, int rw, 437 return 0;
379 struct bio_vec *bvec, unsigned long *error_bits)
380{
381 struct dpages dp;
382 bvec_dp_init(&dp, bvec);
383 return sync_io(num_regions, where, rw, &dp, error_bits);
384} 438}
385 439
386int dm_io_sync_vm(unsigned int num_regions, struct io_region *where, int rw, 440/*
387 void *data, unsigned long *error_bits) 441 * New collapsed (a)synchronous interface
442 */
443int dm_io(struct dm_io_request *io_req, unsigned num_regions,
444 struct io_region *where, unsigned long *sync_error_bits)
388{ 445{
446 int r;
389 struct dpages dp; 447 struct dpages dp;
390 vm_dp_init(&dp, data);
391 return sync_io(num_regions, where, rw, &dp, error_bits);
392}
393 448
394int dm_io_async(unsigned int num_regions, struct io_region *where, int rw, 449 r = dp_init(io_req, &dp);
395 struct page_list *pl, unsigned int offset, 450 if (r)
396 io_notify_fn fn, void *context) 451 return r;
397{
398 struct dpages dp;
399 list_dp_init(&dp, pl, offset);
400 return async_io(num_regions, where, rw, &dp, fn, context);
401}
402 452
403int dm_io_async_bvec(unsigned int num_regions, struct io_region *where, int rw, 453 if (!io_req->notify.fn)
404 struct bio_vec *bvec, io_notify_fn fn, void *context) 454 return sync_io(io_req->client, num_regions, where,
405{ 455 io_req->bi_rw, &dp, sync_error_bits);
406 struct dpages dp;
407 bvec_dp_init(&dp, bvec);
408 return async_io(num_regions, where, rw, &dp, fn, context);
409}
410 456
411int dm_io_async_vm(unsigned int num_regions, struct io_region *where, int rw, 457 return async_io(io_req->client, num_regions, where, io_req->bi_rw,
412 void *data, io_notify_fn fn, void *context) 458 &dp, io_req->notify.fn, io_req->notify.context);
413{
414 struct dpages dp;
415 vm_dp_init(&dp, data);
416 return async_io(num_regions, where, rw, &dp, fn, context);
417} 459}
418 460EXPORT_SYMBOL(dm_io);
419EXPORT_SYMBOL(dm_io_get);
420EXPORT_SYMBOL(dm_io_put);
421EXPORT_SYMBOL(dm_io_sync);
422EXPORT_SYMBOL(dm_io_async);
423EXPORT_SYMBOL(dm_io_sync_bvec);
424EXPORT_SYMBOL(dm_io_async_bvec);
425EXPORT_SYMBOL(dm_io_sync_vm);
426EXPORT_SYMBOL(dm_io_async_vm);
diff --git a/drivers/md/dm-io.h b/drivers/md/dm-io.h
index f9035bfd1a9f..f647e2cceaa6 100644
--- a/drivers/md/dm-io.h
+++ b/drivers/md/dm-io.h
@@ -12,7 +12,7 @@
12struct io_region { 12struct io_region {
13 struct block_device *bdev; 13 struct block_device *bdev;
14 sector_t sector; 14 sector_t sector;
15 sector_t count; 15 sector_t count; /* If this is zero the region is ignored. */
16}; 16};
17 17
18struct page_list { 18struct page_list {
@@ -20,55 +20,60 @@ struct page_list {
20 struct page *page; 20 struct page *page;
21}; 21};
22 22
23
24/*
25 * 'error' is a bitset, with each bit indicating whether an error
26 * occurred doing io to the corresponding region.
27 */
28typedef void (*io_notify_fn)(unsigned long error, void *context); 23typedef void (*io_notify_fn)(unsigned long error, void *context);
29 24
25enum dm_io_mem_type {
26 DM_IO_PAGE_LIST,/* Page list */
27 DM_IO_BVEC, /* Bio vector */
28 DM_IO_VMA, /* Virtual memory area */
29 DM_IO_KMEM, /* Kernel memory */
30};
31
32struct dm_io_memory {
33 enum dm_io_mem_type type;
34
35 union {
36 struct page_list *pl;
37 struct bio_vec *bvec;
38 void *vma;
39 void *addr;
40 } ptr;
41
42 unsigned offset;
43};
44
45struct dm_io_notify {
46 io_notify_fn fn; /* Callback for asynchronous requests */
47 void *context; /* Passed to callback */
48};
30 49
31/* 50/*
32 * Before anyone uses the IO interface they should call 51 * IO request structure
33 * dm_io_get(), specifying roughly how many pages they are
34 * expecting to perform io on concurrently.
35 *
36 * This function may block.
37 */ 52 */
38int dm_io_get(unsigned int num_pages); 53struct dm_io_client;
39void dm_io_put(unsigned int num_pages); 54struct dm_io_request {
55 int bi_rw; /* READ|WRITE - not READA */
56 struct dm_io_memory mem; /* Memory to use for io */
57 struct dm_io_notify notify; /* Synchronous if notify.fn is NULL */
58 struct dm_io_client *client; /* Client memory handler */
59};
40 60
41/* 61/*
42 * Synchronous IO. 62 * For async io calls, users can alternatively use the dm_io() function below
63 * and dm_io_client_create() to create private mempools for the client.
43 * 64 *
44 * Please ensure that the rw flag in the next two functions is 65 * Create/destroy may block.
45 * either READ or WRITE, ie. we don't take READA. Any
46 * regions with a zero count field will be ignored.
47 */ 66 */
48int dm_io_sync(unsigned int num_regions, struct io_region *where, int rw, 67struct dm_io_client *dm_io_client_create(unsigned num_pages);
49 struct page_list *pl, unsigned int offset, 68int dm_io_client_resize(unsigned num_pages, struct dm_io_client *client);
50 unsigned long *error_bits); 69void dm_io_client_destroy(struct dm_io_client *client);
51
52int dm_io_sync_bvec(unsigned int num_regions, struct io_region *where, int rw,
53 struct bio_vec *bvec, unsigned long *error_bits);
54
55int dm_io_sync_vm(unsigned int num_regions, struct io_region *where, int rw,
56 void *data, unsigned long *error_bits);
57 70
58/* 71/*
59 * Aynchronous IO. 72 * IO interface using private per-client pools.
60 * 73 * Each bit in the optional 'sync_error_bits' bitset indicates whether an
61 * The 'where' array may be safely allocated on the stack since 74 * error occurred doing io to the corresponding region.
62 * the function takes a copy.
63 */ 75 */
64int dm_io_async(unsigned int num_regions, struct io_region *where, int rw, 76int dm_io(struct dm_io_request *io_req, unsigned num_regions,
65 struct page_list *pl, unsigned int offset, 77 struct io_region *region, unsigned long *sync_error_bits);
66 io_notify_fn fn, void *context);
67
68int dm_io_async_bvec(unsigned int num_regions, struct io_region *where, int rw,
69 struct bio_vec *bvec, io_notify_fn fn, void *context);
70
71int dm_io_async_vm(unsigned int num_regions, struct io_region *where, int rw,
72 void *data, io_notify_fn fn, void *context);
73 78
74#endif 79#endif
diff --git a/drivers/md/dm-log.c b/drivers/md/dm-log.c
index 6a9261351848..a66428d860fe 100644
--- a/drivers/md/dm-log.c
+++ b/drivers/md/dm-log.c
@@ -149,9 +149,12 @@ struct log_c {
149 FORCESYNC, /* Force a sync to happen */ 149 FORCESYNC, /* Force a sync to happen */
150 } sync; 150 } sync;
151 151
152 struct dm_io_request io_req;
153
152 /* 154 /*
153 * Disk log fields 155 * Disk log fields
154 */ 156 */
157 int log_dev_failed;
155 struct dm_dev *log_dev; 158 struct dm_dev *log_dev;
156 struct log_header header; 159 struct log_header header;
157 160
@@ -199,13 +202,20 @@ static void header_from_disk(struct log_header *core, struct log_header *disk)
199 core->nr_regions = le64_to_cpu(disk->nr_regions); 202 core->nr_regions = le64_to_cpu(disk->nr_regions);
200} 203}
201 204
205static int rw_header(struct log_c *lc, int rw)
206{
207 lc->io_req.bi_rw = rw;
208 lc->io_req.mem.ptr.vma = lc->disk_header;
209 lc->io_req.notify.fn = NULL;
210
211 return dm_io(&lc->io_req, 1, &lc->header_location, NULL);
212}
213
202static int read_header(struct log_c *log) 214static int read_header(struct log_c *log)
203{ 215{
204 int r; 216 int r;
205 unsigned long ebits;
206 217
207 r = dm_io_sync_vm(1, &log->header_location, READ, 218 r = rw_header(log, READ);
208 log->disk_header, &ebits);
209 if (r) 219 if (r)
210 return r; 220 return r;
211 221
@@ -233,11 +243,8 @@ static int read_header(struct log_c *log)
233 243
234static inline int write_header(struct log_c *log) 244static inline int write_header(struct log_c *log)
235{ 245{
236 unsigned long ebits;
237
238 header_to_disk(&log->header, log->disk_header); 246 header_to_disk(&log->header, log->disk_header);
239 return dm_io_sync_vm(1, &log->header_location, WRITE, 247 return rw_header(log, WRITE);
240 log->disk_header, &ebits);
241} 248}
242 249
243/*---------------------------------------------------------------- 250/*----------------------------------------------------------------
@@ -256,6 +263,7 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti,
256 uint32_t region_size; 263 uint32_t region_size;
257 unsigned int region_count; 264 unsigned int region_count;
258 size_t bitset_size, buf_size; 265 size_t bitset_size, buf_size;
266 int r;
259 267
260 if (argc < 1 || argc > 2) { 268 if (argc < 1 || argc > 2) {
261 DMWARN("wrong number of arguments to mirror log"); 269 DMWARN("wrong number of arguments to mirror log");
@@ -315,6 +323,7 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti,
315 lc->disk_header = NULL; 323 lc->disk_header = NULL;
316 } else { 324 } else {
317 lc->log_dev = dev; 325 lc->log_dev = dev;
326 lc->log_dev_failed = 0;
318 lc->header_location.bdev = lc->log_dev->bdev; 327 lc->header_location.bdev = lc->log_dev->bdev;
319 lc->header_location.sector = 0; 328 lc->header_location.sector = 0;
320 329
@@ -324,6 +333,15 @@ static int create_log_context(struct dirty_log *log, struct dm_target *ti,
324 buf_size = dm_round_up((LOG_OFFSET << SECTOR_SHIFT) + 333 buf_size = dm_round_up((LOG_OFFSET << SECTOR_SHIFT) +
325 bitset_size, ti->limits.hardsect_size); 334 bitset_size, ti->limits.hardsect_size);
326 lc->header_location.count = buf_size >> SECTOR_SHIFT; 335 lc->header_location.count = buf_size >> SECTOR_SHIFT;
336 lc->io_req.mem.type = DM_IO_VMA;
337 lc->io_req.client = dm_io_client_create(dm_div_up(buf_size,
338 PAGE_SIZE));
339 if (IS_ERR(lc->io_req.client)) {
340 r = PTR_ERR(lc->io_req.client);
341 DMWARN("couldn't allocate disk io client");
342 kfree(lc);
343 return -ENOMEM;
344 }
327 345
328 lc->disk_header = vmalloc(buf_size); 346 lc->disk_header = vmalloc(buf_size);
329 if (!lc->disk_header) { 347 if (!lc->disk_header) {
@@ -424,6 +442,7 @@ static void disk_dtr(struct dirty_log *log)
424 442
425 dm_put_device(lc->ti, lc->log_dev); 443 dm_put_device(lc->ti, lc->log_dev);
426 vfree(lc->disk_header); 444 vfree(lc->disk_header);
445 dm_io_client_destroy(lc->io_req.client);
427 destroy_log_context(lc); 446 destroy_log_context(lc);
428} 447}
429 448
@@ -437,6 +456,15 @@ static int count_bits32(uint32_t *addr, unsigned size)
437 return count; 456 return count;
438} 457}
439 458
459static void fail_log_device(struct log_c *lc)
460{
461 if (lc->log_dev_failed)
462 return;
463
464 lc->log_dev_failed = 1;
465 dm_table_event(lc->ti->table);
466}
467
440static int disk_resume(struct dirty_log *log) 468static int disk_resume(struct dirty_log *log)
441{ 469{
442 int r; 470 int r;
@@ -446,8 +474,19 @@ static int disk_resume(struct dirty_log *log)
446 474
447 /* read the disk header */ 475 /* read the disk header */
448 r = read_header(lc); 476 r = read_header(lc);
449 if (r) 477 if (r) {
450 return r; 478 DMWARN("%s: Failed to read header on mirror log device",
479 lc->log_dev->name);
480 fail_log_device(lc);
481 /*
482 * If the log device cannot be read, we must assume
483 * all regions are out-of-sync. If we simply return
484 * here, the state will be uninitialized and could
485 * lead us to return 'in-sync' status for regions
486 * that are actually 'out-of-sync'.
487 */
488 lc->header.nr_regions = 0;
489 }
451 490
452 /* set or clear any new bits -- device has grown */ 491 /* set or clear any new bits -- device has grown */
453 if (lc->sync == NOSYNC) 492 if (lc->sync == NOSYNC)
@@ -472,7 +511,14 @@ static int disk_resume(struct dirty_log *log)
472 lc->header.nr_regions = lc->region_count; 511 lc->header.nr_regions = lc->region_count;
473 512
474 /* write the new header */ 513 /* write the new header */
475 return write_header(lc); 514 r = write_header(lc);
515 if (r) {
516 DMWARN("%s: Failed to write header on mirror log device",
517 lc->log_dev->name);
518 fail_log_device(lc);
519 }
520
521 return r;
476} 522}
477 523
478static uint32_t core_get_region_size(struct dirty_log *log) 524static uint32_t core_get_region_size(struct dirty_log *log)
@@ -516,7 +562,9 @@ static int disk_flush(struct dirty_log *log)
516 return 0; 562 return 0;
517 563
518 r = write_header(lc); 564 r = write_header(lc);
519 if (!r) 565 if (r)
566 fail_log_device(lc);
567 else
520 lc->touched = 0; 568 lc->touched = 0;
521 569
522 return r; 570 return r;
@@ -591,6 +639,7 @@ static int core_status(struct dirty_log *log, status_type_t status,
591 639
592 switch(status) { 640 switch(status) {
593 case STATUSTYPE_INFO: 641 case STATUSTYPE_INFO:
642 DMEMIT("1 %s", log->type->name);
594 break; 643 break;
595 644
596 case STATUSTYPE_TABLE: 645 case STATUSTYPE_TABLE:
@@ -606,17 +655,17 @@ static int disk_status(struct dirty_log *log, status_type_t status,
606 char *result, unsigned int maxlen) 655 char *result, unsigned int maxlen)
607{ 656{
608 int sz = 0; 657 int sz = 0;
609 char buffer[16];
610 struct log_c *lc = log->context; 658 struct log_c *lc = log->context;
611 659
612 switch(status) { 660 switch(status) {
613 case STATUSTYPE_INFO: 661 case STATUSTYPE_INFO:
662 DMEMIT("3 %s %s %c", log->type->name, lc->log_dev->name,
663 lc->log_dev_failed ? 'D' : 'A');
614 break; 664 break;
615 665
616 case STATUSTYPE_TABLE: 666 case STATUSTYPE_TABLE:
617 format_dev_t(buffer, lc->log_dev->bdev->bd_dev);
618 DMEMIT("%s %u %s %u ", log->type->name, 667 DMEMIT("%s %u %s %u ", log->type->name,
619 lc->sync == DEFAULTSYNC ? 2 : 3, buffer, 668 lc->sync == DEFAULTSYNC ? 2 : 3, lc->log_dev->name,
620 lc->region_size); 669 lc->region_size);
621 DMEMIT_SYNC; 670 DMEMIT_SYNC;
622 } 671 }
diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 3aa013506967..de54b39e6ffe 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -668,6 +668,9 @@ static int parse_hw_handler(struct arg_set *as, struct multipath *m)
668 return -EINVAL; 668 return -EINVAL;
669 } 669 }
670 670
671 m->hw_handler.md = dm_table_get_md(ti->table);
672 dm_put(m->hw_handler.md);
673
671 r = hwht->create(&m->hw_handler, hw_argc - 1, as->argv); 674 r = hwht->create(&m->hw_handler, hw_argc - 1, as->argv);
672 if (r) { 675 if (r) {
673 dm_put_hw_handler(hwht); 676 dm_put_hw_handler(hwht);
diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
index 23a642619bed..ef124b71ccc8 100644
--- a/drivers/md/dm-raid1.c
+++ b/drivers/md/dm-raid1.c
@@ -21,15 +21,11 @@
21#include <linux/workqueue.h> 21#include <linux/workqueue.h>
22 22
23#define DM_MSG_PREFIX "raid1" 23#define DM_MSG_PREFIX "raid1"
24#define DM_IO_PAGES 64
24 25
25static struct workqueue_struct *_kmirrord_wq; 26#define DM_RAID1_HANDLE_ERRORS 0x01
26static struct work_struct _kmirrord_work;
27static DECLARE_WAIT_QUEUE_HEAD(_kmirrord_recovery_stopped);
28 27
29static inline void wake(void) 28static DECLARE_WAIT_QUEUE_HEAD(_kmirrord_recovery_stopped);
30{
31 queue_work(_kmirrord_wq, &_kmirrord_work);
32}
33 29
34/*----------------------------------------------------------------- 30/*-----------------------------------------------------------------
35 * Region hash 31 * Region hash
@@ -125,17 +121,23 @@ struct mirror_set {
125 struct list_head list; 121 struct list_head list;
126 struct region_hash rh; 122 struct region_hash rh;
127 struct kcopyd_client *kcopyd_client; 123 struct kcopyd_client *kcopyd_client;
124 uint64_t features;
128 125
129 spinlock_t lock; /* protects the next two lists */ 126 spinlock_t lock; /* protects the next two lists */
130 struct bio_list reads; 127 struct bio_list reads;
131 struct bio_list writes; 128 struct bio_list writes;
132 129
130 struct dm_io_client *io_client;
131
133 /* recovery */ 132 /* recovery */
134 region_t nr_regions; 133 region_t nr_regions;
135 int in_sync; 134 int in_sync;
136 135
137 struct mirror *default_mirror; /* Default mirror */ 136 struct mirror *default_mirror; /* Default mirror */
138 137
138 struct workqueue_struct *kmirrord_wq;
139 struct work_struct kmirrord_work;
140
139 unsigned int nr_mirrors; 141 unsigned int nr_mirrors;
140 struct mirror mirror[0]; 142 struct mirror mirror[0];
141}; 143};
@@ -153,6 +155,11 @@ static inline sector_t region_to_sector(struct region_hash *rh, region_t region)
153 return region << rh->region_shift; 155 return region << rh->region_shift;
154} 156}
155 157
158static void wake(struct mirror_set *ms)
159{
160 queue_work(ms->kmirrord_wq, &ms->kmirrord_work);
161}
162
156/* FIXME move this */ 163/* FIXME move this */
157static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw); 164static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw);
158 165
@@ -398,8 +405,7 @@ static void rh_update_states(struct region_hash *rh)
398 mempool_free(reg, rh->region_pool); 405 mempool_free(reg, rh->region_pool);
399 } 406 }
400 407
401 if (!list_empty(&recovered)) 408 rh->log->type->flush(rh->log);
402 rh->log->type->flush(rh->log);
403 409
404 list_for_each_entry_safe (reg, next, &clean, list) 410 list_for_each_entry_safe (reg, next, &clean, list)
405 mempool_free(reg, rh->region_pool); 411 mempool_free(reg, rh->region_pool);
@@ -471,7 +477,7 @@ static void rh_dec(struct region_hash *rh, region_t region)
471 spin_unlock_irqrestore(&rh->region_lock, flags); 477 spin_unlock_irqrestore(&rh->region_lock, flags);
472 478
473 if (should_wake) 479 if (should_wake)
474 wake(); 480 wake(rh->ms);
475} 481}
476 482
477/* 483/*
@@ -558,7 +564,7 @@ static void rh_recovery_end(struct region *reg, int success)
558 list_add(&reg->list, &reg->rh->recovered_regions); 564 list_add(&reg->list, &reg->rh->recovered_regions);
559 spin_unlock_irq(&rh->region_lock); 565 spin_unlock_irq(&rh->region_lock);
560 566
561 wake(); 567 wake(rh->ms);
562} 568}
563 569
564static void rh_flush(struct region_hash *rh) 570static void rh_flush(struct region_hash *rh)
@@ -592,7 +598,7 @@ static void rh_start_recovery(struct region_hash *rh)
592 for (i = 0; i < MAX_RECOVERY; i++) 598 for (i = 0; i < MAX_RECOVERY; i++)
593 up(&rh->recovery_count); 599 up(&rh->recovery_count);
594 600
595 wake(); 601 wake(rh->ms);
596} 602}
597 603
598/* 604/*
@@ -735,7 +741,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
735 /* 741 /*
736 * We can only read balance if the region is in sync. 742 * We can only read balance if the region is in sync.
737 */ 743 */
738 if (rh_in_sync(&ms->rh, region, 0)) 744 if (rh_in_sync(&ms->rh, region, 1))
739 m = choose_mirror(ms, bio->bi_sector); 745 m = choose_mirror(ms, bio->bi_sector);
740 else 746 else
741 m = ms->default_mirror; 747 m = ms->default_mirror;
@@ -792,6 +798,14 @@ static void do_write(struct mirror_set *ms, struct bio *bio)
792 unsigned int i; 798 unsigned int i;
793 struct io_region io[KCOPYD_MAX_REGIONS+1]; 799 struct io_region io[KCOPYD_MAX_REGIONS+1];
794 struct mirror *m; 800 struct mirror *m;
801 struct dm_io_request io_req = {
802 .bi_rw = WRITE,
803 .mem.type = DM_IO_BVEC,
804 .mem.ptr.bvec = bio->bi_io_vec + bio->bi_idx,
805 .notify.fn = write_callback,
806 .notify.context = bio,
807 .client = ms->io_client,
808 };
795 809
796 for (i = 0; i < ms->nr_mirrors; i++) { 810 for (i = 0; i < ms->nr_mirrors; i++) {
797 m = ms->mirror + i; 811 m = ms->mirror + i;
@@ -802,9 +816,8 @@ static void do_write(struct mirror_set *ms, struct bio *bio)
802 } 816 }
803 817
804 bio_set_ms(bio, ms); 818 bio_set_ms(bio, ms);
805 dm_io_async_bvec(ms->nr_mirrors, io, WRITE, 819
806 bio->bi_io_vec + bio->bi_idx, 820 (void) dm_io(&io_req, ms->nr_mirrors, io, NULL);
807 write_callback, bio);
808} 821}
809 822
810static void do_writes(struct mirror_set *ms, struct bio_list *writes) 823static void do_writes(struct mirror_set *ms, struct bio_list *writes)
@@ -870,11 +883,10 @@ static void do_writes(struct mirror_set *ms, struct bio_list *writes)
870/*----------------------------------------------------------------- 883/*-----------------------------------------------------------------
871 * kmirrord 884 * kmirrord
872 *---------------------------------------------------------------*/ 885 *---------------------------------------------------------------*/
873static LIST_HEAD(_mirror_sets); 886static void do_mirror(struct work_struct *work)
874static DECLARE_RWSEM(_mirror_sets_lock);
875
876static void do_mirror(struct mirror_set *ms)
877{ 887{
888 struct mirror_set *ms =container_of(work, struct mirror_set,
889 kmirrord_work);
878 struct bio_list reads, writes; 890 struct bio_list reads, writes;
879 891
880 spin_lock(&ms->lock); 892 spin_lock(&ms->lock);
@@ -890,16 +902,6 @@ static void do_mirror(struct mirror_set *ms)
890 do_writes(ms, &writes); 902 do_writes(ms, &writes);
891} 903}
892 904
893static void do_work(struct work_struct *ignored)
894{
895 struct mirror_set *ms;
896
897 down_read(&_mirror_sets_lock);
898 list_for_each_entry (ms, &_mirror_sets, list)
899 do_mirror(ms);
900 up_read(&_mirror_sets_lock);
901}
902
903/*----------------------------------------------------------------- 905/*-----------------------------------------------------------------
904 * Target functions 906 * Target functions
905 *---------------------------------------------------------------*/ 907 *---------------------------------------------------------------*/
@@ -931,6 +933,13 @@ static struct mirror_set *alloc_context(unsigned int nr_mirrors,
931 ms->in_sync = 0; 933 ms->in_sync = 0;
932 ms->default_mirror = &ms->mirror[DEFAULT_MIRROR]; 934 ms->default_mirror = &ms->mirror[DEFAULT_MIRROR];
933 935
936 ms->io_client = dm_io_client_create(DM_IO_PAGES);
937 if (IS_ERR(ms->io_client)) {
938 ti->error = "Error creating dm_io client";
939 kfree(ms);
940 return NULL;
941 }
942
934 if (rh_init(&ms->rh, ms, dl, region_size, ms->nr_regions)) { 943 if (rh_init(&ms->rh, ms, dl, region_size, ms->nr_regions)) {
935 ti->error = "Error creating dirty region hash"; 944 ti->error = "Error creating dirty region hash";
936 kfree(ms); 945 kfree(ms);
@@ -946,6 +955,7 @@ static void free_context(struct mirror_set *ms, struct dm_target *ti,
946 while (m--) 955 while (m--)
947 dm_put_device(ti, ms->mirror[m].dev); 956 dm_put_device(ti, ms->mirror[m].dev);
948 957
958 dm_io_client_destroy(ms->io_client);
949 rh_exit(&ms->rh); 959 rh_exit(&ms->rh);
950 kfree(ms); 960 kfree(ms);
951} 961}
@@ -978,23 +988,6 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
978 return 0; 988 return 0;
979} 989}
980 990
981static int add_mirror_set(struct mirror_set *ms)
982{
983 down_write(&_mirror_sets_lock);
984 list_add_tail(&ms->list, &_mirror_sets);
985 up_write(&_mirror_sets_lock);
986 wake();
987
988 return 0;
989}
990
991static void del_mirror_set(struct mirror_set *ms)
992{
993 down_write(&_mirror_sets_lock);
994 list_del(&ms->list);
995 up_write(&_mirror_sets_lock);
996}
997
998/* 991/*
999 * Create dirty log: log_type #log_params <log_params> 992 * Create dirty log: log_type #log_params <log_params>
1000 */ 993 */
@@ -1037,16 +1030,55 @@ static struct dirty_log *create_dirty_log(struct dm_target *ti,
1037 return dl; 1030 return dl;
1038} 1031}
1039 1032
1033static int parse_features(struct mirror_set *ms, unsigned argc, char **argv,
1034 unsigned *args_used)
1035{
1036 unsigned num_features;
1037 struct dm_target *ti = ms->ti;
1038
1039 *args_used = 0;
1040
1041 if (!argc)
1042 return 0;
1043
1044 if (sscanf(argv[0], "%u", &num_features) != 1) {
1045 ti->error = "Invalid number of features";
1046 return -EINVAL;
1047 }
1048
1049 argc--;
1050 argv++;
1051 (*args_used)++;
1052
1053 if (num_features > argc) {
1054 ti->error = "Not enough arguments to support feature count";
1055 return -EINVAL;
1056 }
1057
1058 if (!strcmp("handle_errors", argv[0]))
1059 ms->features |= DM_RAID1_HANDLE_ERRORS;
1060 else {
1061 ti->error = "Unrecognised feature requested";
1062 return -EINVAL;
1063 }
1064
1065 (*args_used)++;
1066
1067 return 0;
1068}
1069
1040/* 1070/*
1041 * Construct a mirror mapping: 1071 * Construct a mirror mapping:
1042 * 1072 *
1043 * log_type #log_params <log_params> 1073 * log_type #log_params <log_params>
1044 * #mirrors [mirror_path offset]{2,} 1074 * #mirrors [mirror_path offset]{2,}
1075 * [#features <features>]
1045 * 1076 *
1046 * log_type is "core" or "disk" 1077 * log_type is "core" or "disk"
1047 * #log_params is between 1 and 3 1078 * #log_params is between 1 and 3
1079 *
1080 * If present, features must be "handle_errors".
1048 */ 1081 */
1049#define DM_IO_PAGES 64
1050static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv) 1082static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1051{ 1083{
1052 int r; 1084 int r;
@@ -1070,8 +1102,8 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1070 1102
1071 argv++, argc--; 1103 argv++, argc--;
1072 1104
1073 if (argc != nr_mirrors * 2) { 1105 if (argc < nr_mirrors * 2) {
1074 ti->error = "Wrong number of mirror arguments"; 1106 ti->error = "Too few mirror arguments";
1075 dm_destroy_dirty_log(dl); 1107 dm_destroy_dirty_log(dl);
1076 return -EINVAL; 1108 return -EINVAL;
1077 } 1109 }
@@ -1096,13 +1128,37 @@ static int mirror_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1096 ti->private = ms; 1128 ti->private = ms;
1097 ti->split_io = ms->rh.region_size; 1129 ti->split_io = ms->rh.region_size;
1098 1130
1131 ms->kmirrord_wq = create_singlethread_workqueue("kmirrord");
1132 if (!ms->kmirrord_wq) {
1133 DMERR("couldn't start kmirrord");
1134 free_context(ms, ti, m);
1135 return -ENOMEM;
1136 }
1137 INIT_WORK(&ms->kmirrord_work, do_mirror);
1138
1139 r = parse_features(ms, argc, argv, &args_used);
1140 if (r) {
1141 free_context(ms, ti, ms->nr_mirrors);
1142 return r;
1143 }
1144
1145 argv += args_used;
1146 argc -= args_used;
1147
1148 if (argc) {
1149 ti->error = "Too many mirror arguments";
1150 free_context(ms, ti, ms->nr_mirrors);
1151 return -EINVAL;
1152 }
1153
1099 r = kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client); 1154 r = kcopyd_client_create(DM_IO_PAGES, &ms->kcopyd_client);
1100 if (r) { 1155 if (r) {
1156 destroy_workqueue(ms->kmirrord_wq);
1101 free_context(ms, ti, ms->nr_mirrors); 1157 free_context(ms, ti, ms->nr_mirrors);
1102 return r; 1158 return r;
1103 } 1159 }
1104 1160
1105 add_mirror_set(ms); 1161 wake(ms);
1106 return 0; 1162 return 0;
1107} 1163}
1108 1164
@@ -1110,8 +1166,9 @@ static void mirror_dtr(struct dm_target *ti)
1110{ 1166{
1111 struct mirror_set *ms = (struct mirror_set *) ti->private; 1167 struct mirror_set *ms = (struct mirror_set *) ti->private;
1112 1168
1113 del_mirror_set(ms); 1169 flush_workqueue(ms->kmirrord_wq);
1114 kcopyd_client_destroy(ms->kcopyd_client); 1170 kcopyd_client_destroy(ms->kcopyd_client);
1171 destroy_workqueue(ms->kmirrord_wq);
1115 free_context(ms, ti, ms->nr_mirrors); 1172 free_context(ms, ti, ms->nr_mirrors);
1116} 1173}
1117 1174
@@ -1127,7 +1184,7 @@ static void queue_bio(struct mirror_set *ms, struct bio *bio, int rw)
1127 spin_unlock(&ms->lock); 1184 spin_unlock(&ms->lock);
1128 1185
1129 if (should_wake) 1186 if (should_wake)
1130 wake(); 1187 wake(ms);
1131} 1188}
1132 1189
1133/* 1190/*
@@ -1222,11 +1279,9 @@ static void mirror_resume(struct dm_target *ti)
1222static int mirror_status(struct dm_target *ti, status_type_t type, 1279static int mirror_status(struct dm_target *ti, status_type_t type,
1223 char *result, unsigned int maxlen) 1280 char *result, unsigned int maxlen)
1224{ 1281{
1225 unsigned int m, sz; 1282 unsigned int m, sz = 0;
1226 struct mirror_set *ms = (struct mirror_set *) ti->private; 1283 struct mirror_set *ms = (struct mirror_set *) ti->private;
1227 1284
1228 sz = ms->rh.log->type->status(ms->rh.log, type, result, maxlen);
1229
1230 switch (type) { 1285 switch (type) {
1231 case STATUSTYPE_INFO: 1286 case STATUSTYPE_INFO:
1232 DMEMIT("%d ", ms->nr_mirrors); 1287 DMEMIT("%d ", ms->nr_mirrors);
@@ -1237,13 +1292,21 @@ static int mirror_status(struct dm_target *ti, status_type_t type,
1237 (unsigned long long)ms->rh.log->type-> 1292 (unsigned long long)ms->rh.log->type->
1238 get_sync_count(ms->rh.log), 1293 get_sync_count(ms->rh.log),
1239 (unsigned long long)ms->nr_regions); 1294 (unsigned long long)ms->nr_regions);
1295
1296 sz = ms->rh.log->type->status(ms->rh.log, type, result, maxlen);
1297
1240 break; 1298 break;
1241 1299
1242 case STATUSTYPE_TABLE: 1300 case STATUSTYPE_TABLE:
1301 sz = ms->rh.log->type->status(ms->rh.log, type, result, maxlen);
1302
1243 DMEMIT("%d", ms->nr_mirrors); 1303 DMEMIT("%d", ms->nr_mirrors);
1244 for (m = 0; m < ms->nr_mirrors; m++) 1304 for (m = 0; m < ms->nr_mirrors; m++)
1245 DMEMIT(" %s %llu", ms->mirror[m].dev->name, 1305 DMEMIT(" %s %llu", ms->mirror[m].dev->name,
1246 (unsigned long long)ms->mirror[m].offset); 1306 (unsigned long long)ms->mirror[m].offset);
1307
1308 if (ms->features & DM_RAID1_HANDLE_ERRORS)
1309 DMEMIT(" 1 handle_errors");
1247 } 1310 }
1248 1311
1249 return 0; 1312 return 0;
@@ -1251,7 +1314,7 @@ static int mirror_status(struct dm_target *ti, status_type_t type,
1251 1314
1252static struct target_type mirror_target = { 1315static struct target_type mirror_target = {
1253 .name = "mirror", 1316 .name = "mirror",
1254 .version = {1, 0, 2}, 1317 .version = {1, 0, 3},
1255 .module = THIS_MODULE, 1318 .module = THIS_MODULE,
1256 .ctr = mirror_ctr, 1319 .ctr = mirror_ctr,
1257 .dtr = mirror_dtr, 1320 .dtr = mirror_dtr,
@@ -1270,20 +1333,11 @@ static int __init dm_mirror_init(void)
1270 if (r) 1333 if (r)
1271 return r; 1334 return r;
1272 1335
1273 _kmirrord_wq = create_singlethread_workqueue("kmirrord");
1274 if (!_kmirrord_wq) {
1275 DMERR("couldn't start kmirrord");
1276 dm_dirty_log_exit();
1277 return r;
1278 }
1279 INIT_WORK(&_kmirrord_work, do_work);
1280
1281 r = dm_register_target(&mirror_target); 1336 r = dm_register_target(&mirror_target);
1282 if (r < 0) { 1337 if (r < 0) {
1283 DMERR("%s: Failed to register mirror target", 1338 DMERR("%s: Failed to register mirror target",
1284 mirror_target.name); 1339 mirror_target.name);
1285 dm_dirty_log_exit(); 1340 dm_dirty_log_exit();
1286 destroy_workqueue(_kmirrord_wq);
1287 } 1341 }
1288 1342
1289 return r; 1343 return r;
@@ -1297,7 +1351,6 @@ static void __exit dm_mirror_exit(void)
1297 if (r < 0) 1351 if (r < 0)
1298 DMERR("%s: unregister failed %d", mirror_target.name, r); 1352 DMERR("%s: unregister failed %d", mirror_target.name, r);
1299 1353
1300 destroy_workqueue(_kmirrord_wq);
1301 dm_dirty_log_exit(); 1354 dm_dirty_log_exit();
1302} 1355}
1303 1356
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index 05befa91807a..2fc199b0016b 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -425,13 +425,15 @@ static void close_dev(struct dm_dev *d, struct mapped_device *md)
425} 425}
426 426
427/* 427/*
428 * If possible (ie. blk_size[major] is set), this checks an area 428 * If possible, this checks an area of a destination device is valid.
429 * of a destination device is valid.
430 */ 429 */
431static int check_device_area(struct dm_dev *dd, sector_t start, sector_t len) 430static int check_device_area(struct dm_dev *dd, sector_t start, sector_t len)
432{ 431{
433 sector_t dev_size; 432 sector_t dev_size = dd->bdev->bd_inode->i_size >> SECTOR_SHIFT;
434 dev_size = dd->bdev->bd_inode->i_size >> SECTOR_SHIFT; 433
434 if (!dev_size)
435 return 1;
436
435 return ((start < dev_size) && (len <= (dev_size - start))); 437 return ((start < dev_size) && (len <= (dev_size - start)));
436} 438}
437 439
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index 11a98df298ec..2717a355dc5b 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -1236,6 +1236,7 @@ void dm_put(struct mapped_device *md)
1236 free_dev(md); 1236 free_dev(md);
1237 } 1237 }
1238} 1238}
1239EXPORT_SYMBOL_GPL(dm_put);
1239 1240
1240/* 1241/*
1241 * Process the deferred bios 1242 * Process the deferred bios
diff --git a/drivers/md/kcopyd.c b/drivers/md/kcopyd.c
index b46f6c575f7e..dbc234e3c69f 100644
--- a/drivers/md/kcopyd.c
+++ b/drivers/md/kcopyd.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (C) 2002 Sistina Software (UK) Limited. 2 * Copyright (C) 2002 Sistina Software (UK) Limited.
3 * Copyright (C) 2006 Red Hat GmbH
3 * 4 *
4 * This file is released under the GPL. 5 * This file is released under the GPL.
5 * 6 *
@@ -45,6 +46,8 @@ struct kcopyd_client {
45 unsigned int nr_pages; 46 unsigned int nr_pages;
46 unsigned int nr_free_pages; 47 unsigned int nr_free_pages;
47 48
49 struct dm_io_client *io_client;
50
48 wait_queue_head_t destroyq; 51 wait_queue_head_t destroyq;
49 atomic_t nr_jobs; 52 atomic_t nr_jobs;
50}; 53};
@@ -342,16 +345,20 @@ static void complete_io(unsigned long error, void *context)
342static int run_io_job(struct kcopyd_job *job) 345static int run_io_job(struct kcopyd_job *job)
343{ 346{
344 int r; 347 int r;
348 struct dm_io_request io_req = {
349 .bi_rw = job->rw,
350 .mem.type = DM_IO_PAGE_LIST,
351 .mem.ptr.pl = job->pages,
352 .mem.offset = job->offset,
353 .notify.fn = complete_io,
354 .notify.context = job,
355 .client = job->kc->io_client,
356 };
345 357
346 if (job->rw == READ) 358 if (job->rw == READ)
347 r = dm_io_async(1, &job->source, job->rw, 359 r = dm_io(&io_req, 1, &job->source, NULL);
348 job->pages,
349 job->offset, complete_io, job);
350
351 else 360 else
352 r = dm_io_async(job->num_dests, job->dests, job->rw, 361 r = dm_io(&io_req, job->num_dests, job->dests, NULL);
353 job->pages,
354 job->offset, complete_io, job);
355 362
356 return r; 363 return r;
357} 364}
@@ -670,8 +677,9 @@ int kcopyd_client_create(unsigned int nr_pages, struct kcopyd_client **result)
670 return r; 677 return r;
671 } 678 }
672 679
673 r = dm_io_get(nr_pages); 680 kc->io_client = dm_io_client_create(nr_pages);
674 if (r) { 681 if (IS_ERR(kc->io_client)) {
682 r = PTR_ERR(kc->io_client);
675 client_free_pages(kc); 683 client_free_pages(kc);
676 kfree(kc); 684 kfree(kc);
677 kcopyd_exit(); 685 kcopyd_exit();
@@ -691,7 +699,7 @@ void kcopyd_client_destroy(struct kcopyd_client *kc)
691 /* Wait for completion of all jobs submitted by this client. */ 699 /* Wait for completion of all jobs submitted by this client. */
692 wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs)); 700 wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs));
693 701
694 dm_io_put(kc->nr_pages); 702 dm_io_client_destroy(kc->io_client);
695 client_free_pages(kc); 703 client_free_pages(kc);
696 client_del(kc); 704 client_del(kc);
697 kfree(kc); 705 kfree(kc);
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 2b4315d7e5d6..c10ce91b64e9 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -33,6 +33,7 @@
33*/ 33*/
34 34
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/kernel.h>
36#include <linux/kthread.h> 37#include <linux/kthread.h>
37#include <linux/linkage.h> 38#include <linux/linkage.h>
38#include <linux/raid/md.h> 39#include <linux/raid/md.h>
@@ -273,6 +274,7 @@ static mddev_t * mddev_find(dev_t unit)
273 atomic_set(&new->active, 1); 274 atomic_set(&new->active, 1);
274 spin_lock_init(&new->write_lock); 275 spin_lock_init(&new->write_lock);
275 init_waitqueue_head(&new->sb_wait); 276 init_waitqueue_head(&new->sb_wait);
277 new->reshape_position = MaxSector;
276 278
277 new->queue = blk_alloc_queue(GFP_KERNEL); 279 new->queue = blk_alloc_queue(GFP_KERNEL);
278 if (!new->queue) { 280 if (!new->queue) {
@@ -589,14 +591,41 @@ abort:
589 return ret; 591 return ret;
590} 592}
591 593
594
595static u32 md_csum_fold(u32 csum)
596{
597 csum = (csum & 0xffff) + (csum >> 16);
598 return (csum & 0xffff) + (csum >> 16);
599}
600
592static unsigned int calc_sb_csum(mdp_super_t * sb) 601static unsigned int calc_sb_csum(mdp_super_t * sb)
593{ 602{
603 u64 newcsum = 0;
604 u32 *sb32 = (u32*)sb;
605 int i;
594 unsigned int disk_csum, csum; 606 unsigned int disk_csum, csum;
595 607
596 disk_csum = sb->sb_csum; 608 disk_csum = sb->sb_csum;
597 sb->sb_csum = 0; 609 sb->sb_csum = 0;
598 csum = csum_partial((void *)sb, MD_SB_BYTES, 0); 610
611 for (i = 0; i < MD_SB_BYTES/4 ; i++)
612 newcsum += sb32[i];
613 csum = (newcsum & 0xffffffff) + (newcsum>>32);
614
615
616#ifdef CONFIG_ALPHA
617 /* This used to use csum_partial, which was wrong for several
618 * reasons including that different results are returned on
619 * different architectures. It isn't critical that we get exactly
620 * the same return value as before (we always csum_fold before
621 * testing, and that removes any differences). However as we
622 * know that csum_partial always returned a 16bit value on
623 * alphas, do a fold to maximise conformity to previous behaviour.
624 */
625 sb->sb_csum = md_csum_fold(disk_csum);
626#else
599 sb->sb_csum = disk_csum; 627 sb->sb_csum = disk_csum;
628#endif
600 return csum; 629 return csum;
601} 630}
602 631
@@ -684,7 +713,7 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
684 if (sb->raid_disks <= 0) 713 if (sb->raid_disks <= 0)
685 goto abort; 714 goto abort;
686 715
687 if (csum_fold(calc_sb_csum(sb)) != csum_fold(sb->sb_csum)) { 716 if (md_csum_fold(calc_sb_csum(sb)) != md_csum_fold(sb->sb_csum)) {
688 printk(KERN_WARNING "md: invalid superblock checksum on %s\n", 717 printk(KERN_WARNING "md: invalid superblock checksum on %s\n",
689 b); 718 b);
690 goto abort; 719 goto abort;
@@ -694,6 +723,17 @@ static int super_90_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version
694 rdev->data_offset = 0; 723 rdev->data_offset = 0;
695 rdev->sb_size = MD_SB_BYTES; 724 rdev->sb_size = MD_SB_BYTES;
696 725
726 if (sb->state & (1<<MD_SB_BITMAP_PRESENT)) {
727 if (sb->level != 1 && sb->level != 4
728 && sb->level != 5 && sb->level != 6
729 && sb->level != 10) {
730 /* FIXME use a better test */
731 printk(KERN_WARNING
732 "md: bitmaps not supported for this level.\n");
733 goto abort;
734 }
735 }
736
697 if (sb->level == LEVEL_MULTIPATH) 737 if (sb->level == LEVEL_MULTIPATH)
698 rdev->desc_nr = -1; 738 rdev->desc_nr = -1;
699 else 739 else
@@ -792,16 +832,8 @@ static int super_90_validate(mddev_t *mddev, mdk_rdev_t *rdev)
792 mddev->max_disks = MD_SB_DISKS; 832 mddev->max_disks = MD_SB_DISKS;
793 833
794 if (sb->state & (1<<MD_SB_BITMAP_PRESENT) && 834 if (sb->state & (1<<MD_SB_BITMAP_PRESENT) &&
795 mddev->bitmap_file == NULL) { 835 mddev->bitmap_file == NULL)
796 if (mddev->level != 1 && mddev->level != 4
797 && mddev->level != 5 && mddev->level != 6
798 && mddev->level != 10) {
799 /* FIXME use a better test */
800 printk(KERN_WARNING "md: bitmaps not supported for this level.\n");
801 return -EINVAL;
802 }
803 mddev->bitmap_offset = mddev->default_bitmap_offset; 836 mddev->bitmap_offset = mddev->default_bitmap_offset;
804 }
805 837
806 } else if (mddev->pers == NULL) { 838 } else if (mddev->pers == NULL) {
807 /* Insist on good event counter while assembling */ 839 /* Insist on good event counter while assembling */
@@ -1058,6 +1090,18 @@ static int super_1_load(mdk_rdev_t *rdev, mdk_rdev_t *refdev, int minor_version)
1058 bdevname(rdev->bdev,b)); 1090 bdevname(rdev->bdev,b));
1059 return -EINVAL; 1091 return -EINVAL;
1060 } 1092 }
1093 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET)) {
1094 if (sb->level != cpu_to_le32(1) &&
1095 sb->level != cpu_to_le32(4) &&
1096 sb->level != cpu_to_le32(5) &&
1097 sb->level != cpu_to_le32(6) &&
1098 sb->level != cpu_to_le32(10)) {
1099 printk(KERN_WARNING
1100 "md: bitmaps not supported for this level.\n");
1101 return -EINVAL;
1102 }
1103 }
1104
1061 rdev->preferred_minor = 0xffff; 1105 rdev->preferred_minor = 0xffff;
1062 rdev->data_offset = le64_to_cpu(sb->data_offset); 1106 rdev->data_offset = le64_to_cpu(sb->data_offset);
1063 atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read)); 1107 atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
@@ -1141,14 +1185,9 @@ static int super_1_validate(mddev_t *mddev, mdk_rdev_t *rdev)
1141 mddev->max_disks = (4096-256)/2; 1185 mddev->max_disks = (4096-256)/2;
1142 1186
1143 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) && 1187 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_BITMAP_OFFSET) &&
1144 mddev->bitmap_file == NULL ) { 1188 mddev->bitmap_file == NULL )
1145 if (mddev->level != 1 && mddev->level != 5 && mddev->level != 6
1146 && mddev->level != 10) {
1147 printk(KERN_WARNING "md: bitmaps not supported for this level.\n");
1148 return -EINVAL;
1149 }
1150 mddev->bitmap_offset = (__s32)le32_to_cpu(sb->bitmap_offset); 1189 mddev->bitmap_offset = (__s32)le32_to_cpu(sb->bitmap_offset);
1151 } 1190
1152 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) { 1191 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE)) {
1153 mddev->reshape_position = le64_to_cpu(sb->reshape_position); 1192 mddev->reshape_position = le64_to_cpu(sb->reshape_position);
1154 mddev->delta_disks = le32_to_cpu(sb->delta_disks); 1193 mddev->delta_disks = le32_to_cpu(sb->delta_disks);
@@ -2204,6 +2243,10 @@ static ssize_t
2204layout_show(mddev_t *mddev, char *page) 2243layout_show(mddev_t *mddev, char *page)
2205{ 2244{
2206 /* just a number, not meaningful for all levels */ 2245 /* just a number, not meaningful for all levels */
2246 if (mddev->reshape_position != MaxSector &&
2247 mddev->layout != mddev->new_layout)
2248 return sprintf(page, "%d (%d)\n",
2249 mddev->new_layout, mddev->layout);
2207 return sprintf(page, "%d\n", mddev->layout); 2250 return sprintf(page, "%d\n", mddev->layout);
2208} 2251}
2209 2252
@@ -2212,13 +2255,16 @@ layout_store(mddev_t *mddev, const char *buf, size_t len)
2212{ 2255{
2213 char *e; 2256 char *e;
2214 unsigned long n = simple_strtoul(buf, &e, 10); 2257 unsigned long n = simple_strtoul(buf, &e, 10);
2215 if (mddev->pers)
2216 return -EBUSY;
2217 2258
2218 if (!*buf || (*e && *e != '\n')) 2259 if (!*buf || (*e && *e != '\n'))
2219 return -EINVAL; 2260 return -EINVAL;
2220 2261
2221 mddev->layout = n; 2262 if (mddev->pers)
2263 return -EBUSY;
2264 if (mddev->reshape_position != MaxSector)
2265 mddev->new_layout = n;
2266 else
2267 mddev->layout = n;
2222 return len; 2268 return len;
2223} 2269}
2224static struct md_sysfs_entry md_layout = 2270static struct md_sysfs_entry md_layout =
@@ -2230,6 +2276,10 @@ raid_disks_show(mddev_t *mddev, char *page)
2230{ 2276{
2231 if (mddev->raid_disks == 0) 2277 if (mddev->raid_disks == 0)
2232 return 0; 2278 return 0;
2279 if (mddev->reshape_position != MaxSector &&
2280 mddev->delta_disks != 0)
2281 return sprintf(page, "%d (%d)\n", mddev->raid_disks,
2282 mddev->raid_disks - mddev->delta_disks);
2233 return sprintf(page, "%d\n", mddev->raid_disks); 2283 return sprintf(page, "%d\n", mddev->raid_disks);
2234} 2284}
2235 2285
@@ -2247,7 +2297,11 @@ raid_disks_store(mddev_t *mddev, const char *buf, size_t len)
2247 2297
2248 if (mddev->pers) 2298 if (mddev->pers)
2249 rv = update_raid_disks(mddev, n); 2299 rv = update_raid_disks(mddev, n);
2250 else 2300 else if (mddev->reshape_position != MaxSector) {
2301 int olddisks = mddev->raid_disks - mddev->delta_disks;
2302 mddev->delta_disks = n - olddisks;
2303 mddev->raid_disks = n;
2304 } else
2251 mddev->raid_disks = n; 2305 mddev->raid_disks = n;
2252 return rv ? rv : len; 2306 return rv ? rv : len;
2253} 2307}
@@ -2257,6 +2311,10 @@ __ATTR(raid_disks, S_IRUGO|S_IWUSR, raid_disks_show, raid_disks_store);
2257static ssize_t 2311static ssize_t
2258chunk_size_show(mddev_t *mddev, char *page) 2312chunk_size_show(mddev_t *mddev, char *page)
2259{ 2313{
2314 if (mddev->reshape_position != MaxSector &&
2315 mddev->chunk_size != mddev->new_chunk)
2316 return sprintf(page, "%d (%d)\n", mddev->new_chunk,
2317 mddev->chunk_size);
2260 return sprintf(page, "%d\n", mddev->chunk_size); 2318 return sprintf(page, "%d\n", mddev->chunk_size);
2261} 2319}
2262 2320
@@ -2267,12 +2325,15 @@ chunk_size_store(mddev_t *mddev, const char *buf, size_t len)
2267 char *e; 2325 char *e;
2268 unsigned long n = simple_strtoul(buf, &e, 10); 2326 unsigned long n = simple_strtoul(buf, &e, 10);
2269 2327
2270 if (mddev->pers)
2271 return -EBUSY;
2272 if (!*buf || (*e && *e != '\n')) 2328 if (!*buf || (*e && *e != '\n'))
2273 return -EINVAL; 2329 return -EINVAL;
2274 2330
2275 mddev->chunk_size = n; 2331 if (mddev->pers)
2332 return -EBUSY;
2333 else if (mddev->reshape_position != MaxSector)
2334 mddev->new_chunk = n;
2335 else
2336 mddev->chunk_size = n;
2276 return len; 2337 return len;
2277} 2338}
2278static struct md_sysfs_entry md_chunk_size = 2339static struct md_sysfs_entry md_chunk_size =
@@ -2637,8 +2698,7 @@ metadata_store(mddev_t *mddev, const char *buf, size_t len)
2637 minor = simple_strtoul(buf, &e, 10); 2698 minor = simple_strtoul(buf, &e, 10);
2638 if (e==buf || (*e && *e != '\n') ) 2699 if (e==buf || (*e && *e != '\n') )
2639 return -EINVAL; 2700 return -EINVAL;
2640 if (major >= sizeof(super_types)/sizeof(super_types[0]) || 2701 if (major >= ARRAY_SIZE(super_types) || super_types[major].name == NULL)
2641 super_types[major].name == NULL)
2642 return -ENOENT; 2702 return -ENOENT;
2643 mddev->major_version = major; 2703 mddev->major_version = major;
2644 mddev->minor_version = minor; 2704 mddev->minor_version = minor;
@@ -2859,6 +2919,37 @@ suspend_hi_store(mddev_t *mddev, const char *buf, size_t len)
2859static struct md_sysfs_entry md_suspend_hi = 2919static struct md_sysfs_entry md_suspend_hi =
2860__ATTR(suspend_hi, S_IRUGO|S_IWUSR, suspend_hi_show, suspend_hi_store); 2920__ATTR(suspend_hi, S_IRUGO|S_IWUSR, suspend_hi_show, suspend_hi_store);
2861 2921
2922static ssize_t
2923reshape_position_show(mddev_t *mddev, char *page)
2924{
2925 if (mddev->reshape_position != MaxSector)
2926 return sprintf(page, "%llu\n",
2927 (unsigned long long)mddev->reshape_position);
2928 strcpy(page, "none\n");
2929 return 5;
2930}
2931
2932static ssize_t
2933reshape_position_store(mddev_t *mddev, const char *buf, size_t len)
2934{
2935 char *e;
2936 unsigned long long new = simple_strtoull(buf, &e, 10);
2937 if (mddev->pers)
2938 return -EBUSY;
2939 if (buf == e || (*e && *e != '\n'))
2940 return -EINVAL;
2941 mddev->reshape_position = new;
2942 mddev->delta_disks = 0;
2943 mddev->new_level = mddev->level;
2944 mddev->new_layout = mddev->layout;
2945 mddev->new_chunk = mddev->chunk_size;
2946 return len;
2947}
2948
2949static struct md_sysfs_entry md_reshape_position =
2950__ATTR(reshape_position, S_IRUGO|S_IWUSR, reshape_position_show,
2951 reshape_position_store);
2952
2862 2953
2863static struct attribute *md_default_attrs[] = { 2954static struct attribute *md_default_attrs[] = {
2864 &md_level.attr, 2955 &md_level.attr,
@@ -2871,6 +2962,7 @@ static struct attribute *md_default_attrs[] = {
2871 &md_new_device.attr, 2962 &md_new_device.attr,
2872 &md_safe_delay.attr, 2963 &md_safe_delay.attr,
2873 &md_array_state.attr, 2964 &md_array_state.attr,
2965 &md_reshape_position.attr,
2874 NULL, 2966 NULL,
2875}; 2967};
2876 2968
@@ -3409,6 +3501,7 @@ static int do_md_stop(mddev_t * mddev, int mode)
3409 mddev->size = 0; 3501 mddev->size = 0;
3410 mddev->raid_disks = 0; 3502 mddev->raid_disks = 0;
3411 mddev->recovery_cp = 0; 3503 mddev->recovery_cp = 0;
3504 mddev->reshape_position = MaxSector;
3412 3505
3413 } else if (mddev->pers) 3506 } else if (mddev->pers)
3414 printk(KERN_INFO "md: %s switched to read-only mode.\n", 3507 printk(KERN_INFO "md: %s switched to read-only mode.\n",
@@ -4019,7 +4112,7 @@ static int set_array_info(mddev_t * mddev, mdu_array_info_t *info)
4019 if (info->raid_disks == 0) { 4112 if (info->raid_disks == 0) {
4020 /* just setting version number for superblock loading */ 4113 /* just setting version number for superblock loading */
4021 if (info->major_version < 0 || 4114 if (info->major_version < 0 ||
4022 info->major_version >= sizeof(super_types)/sizeof(super_types[0]) || 4115 info->major_version >= ARRAY_SIZE(super_types) ||
4023 super_types[info->major_version].name == NULL) { 4116 super_types[info->major_version].name == NULL) {
4024 /* maybe try to auto-load a module? */ 4117 /* maybe try to auto-load a module? */
4025 printk(KERN_INFO 4118 printk(KERN_INFO
@@ -4941,15 +5034,6 @@ static int md_seq_open(struct inode *inode, struct file *file)
4941 return error; 5034 return error;
4942} 5035}
4943 5036
4944static int md_seq_release(struct inode *inode, struct file *file)
4945{
4946 struct seq_file *m = file->private_data;
4947 struct mdstat_info *mi = m->private;
4948 m->private = NULL;
4949 kfree(mi);
4950 return seq_release(inode, file);
4951}
4952
4953static unsigned int mdstat_poll(struct file *filp, poll_table *wait) 5037static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
4954{ 5038{
4955 struct seq_file *m = filp->private_data; 5039 struct seq_file *m = filp->private_data;
@@ -4971,7 +5055,7 @@ static const struct file_operations md_seq_fops = {
4971 .open = md_seq_open, 5055 .open = md_seq_open,
4972 .read = seq_read, 5056 .read = seq_read,
4973 .llseek = seq_lseek, 5057 .llseek = seq_lseek,
4974 .release = md_seq_release, 5058 .release = seq_release_private,
4975 .poll = mdstat_poll, 5059 .poll = mdstat_poll,
4976}; 5060};
4977 5061
@@ -5019,7 +5103,7 @@ static int is_mddev_idle(mddev_t *mddev)
5019 * 5103 *
5020 * Note: the following is an unsigned comparison. 5104 * Note: the following is an unsigned comparison.
5021 */ 5105 */
5022 if ((curr_events - rdev->last_events + 4096) > 8192) { 5106 if ((long)curr_events - (long)rdev->last_events > 4096) {
5023 rdev->last_events = curr_events; 5107 rdev->last_events = curr_events;
5024 idle = 0; 5108 idle = 0;
5025 } 5109 }
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index 97ee870b265d..3a95cc5e029c 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -271,21 +271,25 @@ static int raid1_end_read_request(struct bio *bio, unsigned int bytes_done, int
271 */ 271 */
272 update_head_pos(mirror, r1_bio); 272 update_head_pos(mirror, r1_bio);
273 273
274 if (uptodate || (conf->raid_disks - conf->mddev->degraded) <= 1) { 274 if (uptodate)
275 /* 275 set_bit(R1BIO_Uptodate, &r1_bio->state);
276 * Set R1BIO_Uptodate in our master bio, so that 276 else {
277 * we will return a good error code for to the higher 277 /* If all other devices have failed, we want to return
278 * levels even if IO on some other mirrored buffer fails. 278 * the error upwards rather than fail the last device.
279 * 279 * Here we redefine "uptodate" to mean "Don't want to retry"
280 * The 'master' represents the composite IO operation to
281 * user-side. So if something waits for IO, then it will
282 * wait for the 'master' bio.
283 */ 280 */
284 if (uptodate) 281 unsigned long flags;
285 set_bit(R1BIO_Uptodate, &r1_bio->state); 282 spin_lock_irqsave(&conf->device_lock, flags);
283 if (r1_bio->mddev->degraded == conf->raid_disks ||
284 (r1_bio->mddev->degraded == conf->raid_disks-1 &&
285 !test_bit(Faulty, &conf->mirrors[mirror].rdev->flags)))
286 uptodate = 1;
287 spin_unlock_irqrestore(&conf->device_lock, flags);
288 }
286 289
290 if (uptodate)
287 raid_end_bio_io(r1_bio); 291 raid_end_bio_io(r1_bio);
288 } else { 292 else {
289 /* 293 /*
290 * oops, read error: 294 * oops, read error:
291 */ 295 */
@@ -992,13 +996,14 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
992 unsigned long flags; 996 unsigned long flags;
993 spin_lock_irqsave(&conf->device_lock, flags); 997 spin_lock_irqsave(&conf->device_lock, flags);
994 mddev->degraded++; 998 mddev->degraded++;
999 set_bit(Faulty, &rdev->flags);
995 spin_unlock_irqrestore(&conf->device_lock, flags); 1000 spin_unlock_irqrestore(&conf->device_lock, flags);
996 /* 1001 /*
997 * if recovery is running, make sure it aborts. 1002 * if recovery is running, make sure it aborts.
998 */ 1003 */
999 set_bit(MD_RECOVERY_ERR, &mddev->recovery); 1004 set_bit(MD_RECOVERY_ERR, &mddev->recovery);
1000 } 1005 } else
1001 set_bit(Faulty, &rdev->flags); 1006 set_bit(Faulty, &rdev->flags);
1002 set_bit(MD_CHANGE_DEVS, &mddev->flags); 1007 set_bit(MD_CHANGE_DEVS, &mddev->flags);
1003 printk(KERN_ALERT "raid1: Disk failure on %s, disabling device. \n" 1008 printk(KERN_ALERT "raid1: Disk failure on %s, disabling device. \n"
1004 " Operation continuing on %d devices\n", 1009 " Operation continuing on %d devices\n",
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index 8d59914f2057..061375ee6592 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -353,8 +353,8 @@ static int grow_stripes(raid5_conf_t *conf, int num)
353 struct kmem_cache *sc; 353 struct kmem_cache *sc;
354 int devs = conf->raid_disks; 354 int devs = conf->raid_disks;
355 355
356 sprintf(conf->cache_name[0], "raid5/%s", mdname(conf->mddev)); 356 sprintf(conf->cache_name[0], "raid5-%s", mdname(conf->mddev));
357 sprintf(conf->cache_name[1], "raid5/%s-alt", mdname(conf->mddev)); 357 sprintf(conf->cache_name[1], "raid5-%s-alt", mdname(conf->mddev));
358 conf->active_name = 0; 358 conf->active_name = 0;
359 sc = kmem_cache_create(conf->cache_name[conf->active_name], 359 sc = kmem_cache_create(conf->cache_name[conf->active_name],
360 sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev), 360 sizeof(struct stripe_head)+(devs-1)*sizeof(struct r5dev),
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 91d25798ae4a..624b21cef5b3 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "Multimedia devices" 5menu "Multimedia devices"
6 depends on HAS_IOMEM
6 7
7config VIDEO_DEV 8config VIDEO_DEV
8 tristate "Video For Linux" 9 tristate "Video For Linux"
@@ -86,6 +87,14 @@ config VIDEO_TVEEPROM
86 tristate 87 tristate
87 depends on I2C 88 depends on I2C
88 89
90config DAB
91 boolean "DAB adapters"
92 default y
93 ---help---
94 Allow selecting support for for Digital Audio Broadcasting (DAB)
95 Receiver adapters.
96
97if DAB
89config USB_DABUSB 98config USB_DABUSB
90 tristate "DABUSB driver" 99 tristate "DABUSB driver"
91 depends on USB 100 depends on USB
@@ -99,5 +108,6 @@ config USB_DABUSB
99 108
100 To compile this driver as a module, choose M here: the 109 To compile this driver as a module, choose M here: the
101 module will be called dabusb. 110 module will be called dabusb.
111endif # DAB
102 112
103endmenu 113endmenu
diff --git a/drivers/media/Makefile b/drivers/media/Makefile
index c578a529e7a8..8fa19939c2b6 100644
--- a/drivers/media/Makefile
+++ b/drivers/media/Makefile
@@ -5,4 +5,4 @@
5obj-y := common/ 5obj-y := common/
6obj-$(CONFIG_VIDEO_DEV) += video/ 6obj-$(CONFIG_VIDEO_DEV) += video/
7obj-$(CONFIG_VIDEO_DEV) += radio/ 7obj-$(CONFIG_VIDEO_DEV) += radio/
8obj-$(CONFIG_DVB) += dvb/ 8obj-$(CONFIG_DVB_CORE) += dvb/
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index 86cbdbcf9d7d..ef3e54cd9407 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -136,28 +136,45 @@ char *saa7146_vmalloc_build_pgtable(struct pci_dev *pci, long length, struct saa
136 char *mem = vmalloc_32(length); 136 char *mem = vmalloc_32(length);
137 int slen = 0; 137 int slen = 0;
138 138
139 if (NULL == mem) { 139 if (NULL == mem)
140 return NULL; 140 goto err_null;
141 }
142 141
143 if (!(pt->slist = vmalloc_to_sg(mem, pages))) { 142 if (!(pt->slist = vmalloc_to_sg(mem, pages)))
144 vfree(mem); 143 goto err_free_mem;
145 return NULL;
146 }
147 144
148 if (saa7146_pgtable_alloc(pci, pt)) { 145 if (saa7146_pgtable_alloc(pci, pt))
149 kfree(pt->slist); 146 goto err_free_slist;
150 pt->slist = NULL;
151 vfree(mem);
152 return NULL;
153 }
154 147
155 slen = pci_map_sg(pci,pt->slist,pages,PCI_DMA_FROMDEVICE); 148 pt->nents = pages;
156 if (0 != saa7146_pgtable_build_single(pci, pt, pt->slist, slen)) { 149 slen = pci_map_sg(pci,pt->slist,pt->nents,PCI_DMA_FROMDEVICE);
157 return NULL; 150 if (0 == slen)
158 } 151 goto err_free_pgtable;
152
153 if (0 != saa7146_pgtable_build_single(pci, pt, pt->slist, slen))
154 goto err_unmap_sg;
159 155
160 return mem; 156 return mem;
157
158err_unmap_sg:
159 pci_unmap_sg(pci, pt->slist, pt->nents, PCI_DMA_FROMDEVICE);
160err_free_pgtable:
161 saa7146_pgtable_free(pci, pt);
162err_free_slist:
163 kfree(pt->slist);
164 pt->slist = NULL;
165err_free_mem:
166 vfree(mem);
167err_null:
168 return NULL;
169}
170
171void saa7146_vfree_destroy_pgtable(struct pci_dev *pci, char *mem, struct saa7146_pgtable *pt)
172{
173 pci_unmap_sg(pci, pt->slist, pt->nents, PCI_DMA_FROMDEVICE);
174 saa7146_pgtable_free(pci, pt);
175 kfree(pt->slist);
176 pt->slist = NULL;
177 vfree(mem);
161} 178}
162 179
163void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt) 180void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt)
@@ -166,8 +183,6 @@ void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt)
166 return; 183 return;
167 pci_free_consistent(pci, pt->size, pt->cpu, pt->dma); 184 pci_free_consistent(pci, pt->size, pt->cpu, pt->dma);
168 pt->cpu = NULL; 185 pt->cpu = NULL;
169 kfree(pt->slist);
170 pt->slist = NULL;
171} 186}
172 187
173int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt) 188int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt)
@@ -528,6 +543,7 @@ EXPORT_SYMBOL_GPL(saa7146_pgtable_alloc);
528EXPORT_SYMBOL_GPL(saa7146_pgtable_free); 543EXPORT_SYMBOL_GPL(saa7146_pgtable_free);
529EXPORT_SYMBOL_GPL(saa7146_pgtable_build_single); 544EXPORT_SYMBOL_GPL(saa7146_pgtable_build_single);
530EXPORT_SYMBOL_GPL(saa7146_vmalloc_build_pgtable); 545EXPORT_SYMBOL_GPL(saa7146_vmalloc_build_pgtable);
546EXPORT_SYMBOL_GPL(saa7146_vfree_destroy_pgtable);
531EXPORT_SYMBOL_GPL(saa7146_wait_for_debi_done); 547EXPORT_SYMBOL_GPL(saa7146_wait_for_debi_done);
532 548
533EXPORT_SYMBOL_GPL(saa7146_setgpio); 549EXPORT_SYMBOL_GPL(saa7146_setgpio);
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index c18a5da64934..b4770aecc01d 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -307,7 +307,6 @@ static int fops_release(struct inode *inode, struct file *file)
307 return 0; 307 return 0;
308} 308}
309 309
310int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int cmd, void *arg);
311static int fops_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) 310static int fops_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
312{ 311{
313/* 312/*
diff --git a/drivers/media/dvb/Kconfig b/drivers/media/dvb/Kconfig
index a97c8f5e9a5d..efd2b7468158 100644
--- a/drivers/media/dvb/Kconfig
+++ b/drivers/media/dvb/Kconfig
@@ -2,24 +2,16 @@
2# Multimedia device configuration 2# Multimedia device configuration
3# 3#
4 4
5menu "Digital Video Broadcasting Devices" 5source "drivers/media/dvb/dvb-core/Kconfig"
6 6
7config DVB 7menuconfig DVB_CAPTURE_DRIVERS
8 bool "DVB For Linux" 8 bool "DVB/ATSC adapters"
9 depends on NET && INET 9 depends on DVB_CORE
10 default y
10 ---help--- 11 ---help---
11 Support Digital Video Broadcasting hardware. Enable this if you 12 Say Y to select Digital TV adapters
12 own a DVB adapter and want to use it or if you compile Linux for
13 a digital SetTopBox.
14
15 API specs and user tools are available from <http://www.linuxtv.org/>.
16 13
17 Please report problems regarding this driver to the LinuxDVB 14if DVB_CAPTURE_DRIVERS
18 mailing list.
19
20 If unsure say N.
21
22source "drivers/media/dvb/dvb-core/Kconfig"
23 15
24comment "Supported SAA7146 based PCI Adapters" 16comment "Supported SAA7146 based PCI Adapters"
25 depends on DVB_CORE && PCI && I2C 17 depends on DVB_CORE && PCI && I2C
@@ -48,4 +40,4 @@ comment "Supported DVB Frontends"
48 depends on DVB_CORE 40 depends on DVB_CORE
49source "drivers/media/dvb/frontends/Kconfig" 41source "drivers/media/dvb/frontends/Kconfig"
50 42
51endmenu 43endif # DVB_CAPTURE_DRIVERS
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 0393a3d19920..e908e3cf1e50 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1721,9 +1721,6 @@ static void dst_release(struct dvb_frontend *fe)
1721 symbol_put(dst_ca_attach); 1721 symbol_put(dst_ca_attach);
1722#endif 1722#endif
1723 } 1723 }
1724#ifdef CONFIG_DVB_CORE_ATTACH
1725 symbol_put(dst_attach);
1726#endif
1727 kfree(state); 1724 kfree(state);
1728} 1725}
1729 1726
diff --git a/drivers/media/dvb/bt8xx/dst_common.h b/drivers/media/dvb/bt8xx/dst_common.h
index 3bf084f2e522..87623d203a89 100644
--- a/drivers/media/dvb/bt8xx/dst_common.h
+++ b/drivers/media/dvb/bt8xx/dst_common.h
@@ -22,7 +22,6 @@
22#ifndef DST_COMMON_H 22#ifndef DST_COMMON_H
23#define DST_COMMON_H 23#define DST_COMMON_H
24 24
25#include <linux/smp_lock.h>
26#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
27#include <linux/device.h> 26#include <linux/device.h>
28#include <linux/mutex.h> 27#include <linux/mutex.h>
diff --git a/drivers/media/dvb/dvb-core/Kconfig b/drivers/media/dvb/dvb-core/Kconfig
index 1990eda10c46..e3e6839f8073 100644
--- a/drivers/media/dvb/dvb-core/Kconfig
+++ b/drivers/media/dvb/dvb-core/Kconfig
@@ -1,12 +1,22 @@
1config DVB_CORE 1config DVB_CORE
2 tristate "DVB Core Support" 2 tristate "DVB for Linux"
3 depends on DVB 3 depends on NET && INET
4 select CRC32 4 select CRC32
5 help 5 help
6 Support Digital Video Broadcasting hardware. Enable this if you
7 own a DVB adapter and want to use it or if you compile Linux for
8 a digital SetTopBox.
9
6 DVB core utility functions for device handling, software fallbacks etc. 10 DVB core utility functions for device handling, software fallbacks etc.
7 Say Y when you have a DVB card and want to use it. Say Y if your want 11 Say Y when you have a DVB card and want to use it. Say Y if your want
8 to build your drivers outside the kernel, but need the DVB core. All 12 to build your drivers outside the kernel, but need the DVB core. All
9 in-kernel drivers will select this automatically if needed. 13 in-kernel drivers will select this automatically if needed.
14
15 API specs and user tools are available from <http://www.linuxtv.org/>.
16
17 Please report problems regarding this driver to the LinuxDVB
18 mailing list.
19
10 If unsure say N. 20 If unsure say N.
11 21
12config DVB_CORE_ATTACH 22config DVB_CORE_ATTACH
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index e23d8a0ea1d3..a9fa3337dd81 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -200,7 +200,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
200{ 200{
201 struct dvb_device *dvbdev; 201 struct dvb_device *dvbdev;
202 struct file_operations *dvbdevfops; 202 struct file_operations *dvbdevfops;
203 203 struct class_device *clsdev;
204 int id; 204 int id;
205 205
206 mutex_lock(&dvbdev_register_lock); 206 mutex_lock(&dvbdev_register_lock);
@@ -242,8 +242,15 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
242 242
243 mutex_unlock(&dvbdev_register_lock); 243 mutex_unlock(&dvbdev_register_lock);
244 244
245 class_device_create(dvb_class, NULL, MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)), 245 clsdev = class_device_create(dvb_class, NULL, MKDEV(DVB_MAJOR,
246 adap->device, "dvb%d.%s%d", adap->num, dnames[type], id); 246 nums2minor(adap->num, type, id)),
247 adap->device, "dvb%d.%s%d", adap->num,
248 dnames[type], id);
249 if (IS_ERR(clsdev)) {
250 printk(KERN_ERR "%s: failed to create device dvb%d.%s%d (%ld)\n",
251 __FUNCTION__, adap->num, dnames[type], id, PTR_ERR(clsdev));
252 return PTR_ERR(clsdev);
253 }
247 254
248 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n", 255 dprintk("DVB: register adapter%d/%s%d @ minor: %i (0x%02x)\n",
249 adap->num, dnames[type], id, nums2minor(adap->num, type, id), 256 adap->num, dnames[type], id, nums2minor(adap->num, type, id),
@@ -431,7 +438,7 @@ static void __exit exit_dvbdev(void)
431 unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS); 438 unregister_chrdev_region(MKDEV(DVB_MAJOR, 0), MAX_DVB_MINORS);
432} 439}
433 440
434module_init(init_dvbdev); 441subsys_initcall(init_dvbdev);
435module_exit(exit_dvbdev); 442module_exit(exit_dvbdev);
436 443
437MODULE_DESCRIPTION("DVB Core Driver"); 444MODULE_DESCRIPTION("DVB Core Driver");
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 97715f7514d6..403081689de1 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -19,6 +19,7 @@
19#define USB_VID_COMPRO_UNK 0x145f 19#define USB_VID_COMPRO_UNK 0x145f
20#define USB_VID_CYPRESS 0x04b4 20#define USB_VID_CYPRESS 0x04b4
21#define USB_VID_DIBCOM 0x10b8 21#define USB_VID_DIBCOM 0x10b8
22#define USB_VID_DPOSH 0x1498
22#define USB_VID_DVICO 0x0fe9 23#define USB_VID_DVICO 0x0fe9
23#define USB_VID_EMPIA 0xeb1a 24#define USB_VID_EMPIA 0xeb1a
24#define USB_VID_GENPIX 0x09c0 25#define USB_VID_GENPIX 0x09c0
@@ -61,6 +62,8 @@
61#define USB_PID_DIBCOM_STK7700P 0x1e14 62#define USB_PID_DIBCOM_STK7700P 0x1e14
62#define USB_PID_DIBCOM_STK7700P_PC 0x1e78 63#define USB_PID_DIBCOM_STK7700P_PC 0x1e78
63#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131 64#define USB_PID_DIBCOM_ANCHOR_2135_COLD 0x2131
65#define USB_PID_DPOSH_M9206_COLD 0x9206
66#define USB_PID_DPOSH_M9206_WARM 0xa090
64#define USB_PID_UNIWILL_STK7700P 0x6003 67#define USB_PID_UNIWILL_STK7700P 0x6003
65#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0 68#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0
66#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1 69#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1
@@ -145,6 +148,8 @@
145#define USB_PID_MSI_DIGI_VOX_MINI_II 0x1513 148#define USB_PID_MSI_DIGI_VOX_MINI_II 0x1513
146#define USB_PID_OPERA1_COLD 0x2830 149#define USB_PID_OPERA1_COLD 0x2830
147#define USB_PID_OPERA1_WARM 0x3829 150#define USB_PID_OPERA1_WARM 0x3829
151#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD 0x0514
152#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM 0x0513
148 153
149 154
150#endif 155#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
index 68ed3a788083..9200a30dd1b9 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-remote.c
@@ -3,7 +3,7 @@
3 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de) 3 * Copyright (C) 2004-6 Patrick Boettcher (patrick.boettcher@desy.de)
4 * see dvb-usb-init.c for copyright information. 4 * see dvb-usb-init.c for copyright information.
5 * 5 *
6 * This file contains functions for initializing the the input-device and for handling remote-control-queries. 6 * This file contains functions for initializing the input-device and for handling remote-control-queries.
7 */ 7 */
8#include "dvb-usb-common.h" 8#include "dvb-usb-common.h"
9#include <linux/usb/input.h> 9#include <linux/usb/input.h>
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index 0d721731a524..6f824a569e14 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -119,7 +119,7 @@ struct usb_data_stream_properties {
119 * @caps: capabilities of the DVB USB device. 119 * @caps: capabilities of the DVB USB device.
120 * @pid_filter_count: number of PID filter position in the optional hardware 120 * @pid_filter_count: number of PID filter position in the optional hardware
121 * PID-filter. 121 * PID-filter.
122 * @streaming_crtl: called to start and stop the MPEG2-TS streaming of the 122 * @streaming_ctrl: called to start and stop the MPEG2-TS streaming of the
123 * device (not URB submitting/killing). 123 * device (not URB submitting/killing).
124 * @pid_filter_ctrl: called to en/disable the PID filter, if any. 124 * @pid_filter_ctrl: called to en/disable the PID filter, if any.
125 * @pid_filter: called to set/unset a PID for filtering. 125 * @pid_filter: called to set/unset a PID for filtering.
diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c
index 45d7bc214c18..c546ddeda5d4 100644
--- a/drivers/media/dvb/dvb-usb/m920x.c
+++ b/drivers/media/dvb/dvb-usb/m920x.c
@@ -3,8 +3,8 @@
3 * Copyright (C) 2006 Aapo Tahkola (aet@rasterburn.org) 3 * Copyright (C) 2006 Aapo Tahkola (aet@rasterburn.org)
4 * 4 *
5 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free 6 * under the terms of the GNU General Public License as published by the
7 * Software Foundation, version 2. 7 * Free Software Foundation, version 2.
8 * 8 *
9 * see Documentation/dvb/README.dvb-usb for more information 9 * see Documentation/dvb/README.dvb-usb for more information
10 */ 10 */
@@ -22,26 +22,7 @@ static int dvb_usb_m920x_debug;
22module_param_named(debug,dvb_usb_m920x_debug, int, 0644); 22module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
23MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 23MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
24 24
25static struct dvb_usb_rc_key megasky_rc_keys [] = { 25static inline int m920x_read(struct usb_device *udev, u8 request, u16 value,
26 { 0x0, 0x12, KEY_POWER },
27 { 0x0, 0x1e, KEY_CYCLEWINDOWS }, /* min/max */
28 { 0x0, 0x02, KEY_CHANNELUP },
29 { 0x0, 0x05, KEY_CHANNELDOWN },
30 { 0x0, 0x03, KEY_VOLUMEUP },
31 { 0x0, 0x06, KEY_VOLUMEDOWN },
32 { 0x0, 0x04, KEY_MUTE },
33 { 0x0, 0x07, KEY_OK }, /* TS */
34 { 0x0, 0x08, KEY_STOP },
35 { 0x0, 0x09, KEY_MENU }, /* swap */
36 { 0x0, 0x0a, KEY_REWIND },
37 { 0x0, 0x1b, KEY_PAUSE },
38 { 0x0, 0x1f, KEY_FASTFORWARD },
39 { 0x0, 0x0c, KEY_RECORD },
40 { 0x0, 0x0d, KEY_CAMERA }, /* screenshot */
41 { 0x0, 0x0e, KEY_COFFEE }, /* "MTS" */
42};
43
44static inline int m9206_read(struct usb_device *udev, u8 request, u16 value,\
45 u16 index, void *data, int size) 26 u16 index, void *data, int size)
46{ 27{
47 int ret; 28 int ret;
@@ -55,14 +36,14 @@ static inline int m9206_read(struct usb_device *udev, u8 request, u16 value,\
55 } 36 }
56 37
57 if (ret != size) { 38 if (ret != size) {
58 deb_rc("m920x_read = no data\n"); 39 deb("m920x_read = no data\n");
59 return -EIO; 40 return -EIO;
60 } 41 }
61 42
62 return 0; 43 return 0;
63} 44}
64 45
65static inline int m9206_write(struct usb_device *udev, u8 request, 46static inline int m920x_write(struct usb_device *udev, u8 request,
66 u16 value, u16 index) 47 u16 value, u16 index)
67{ 48{
68 int ret; 49 int ret;
@@ -74,32 +55,40 @@ static inline int m9206_write(struct usb_device *udev, u8 request,
74 return ret; 55 return ret;
75} 56}
76 57
77static int m9206_init(struct dvb_usb_device *d) 58static int m920x_init(struct dvb_usb_device *d, struct m920x_inits *rc_seq)
78{ 59{
79 int ret = 0; 60 int ret = 0;
80 61
81 /* Remote controller init. */ 62 /* Remote controller init. */
82 if (d->props.rc_query) { 63 if (d->props.rc_query) {
83 if ((ret = m9206_write(d->udev, M9206_CORE, 0xa8, M9206_RC_INIT2)) != 0) 64 deb("Initialising remote control\n");
84 return ret; 65 while (rc_seq->address) {
66 if ((ret = m920x_write(d->udev, M9206_CORE,
67 rc_seq->data,
68 rc_seq->address)) != 0) {
69 deb("Initialising remote control failed\n");
70 return ret;
71 }
85 72
86 if ((ret = m9206_write(d->udev, M9206_CORE, 0x51, M9206_RC_INIT1)) != 0) 73 rc_seq++;
87 return ret; 74 }
75
76 deb("Initialising remote control success\n");
88 } 77 }
89 78
90 return ret; 79 return ret;
91} 80}
92 81
93static int m9206_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 82static int m920x_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
94{ 83{
95 struct m9206_state *m = d->priv; 84 struct m920x_state *m = d->priv;
96 int i, ret = 0; 85 int i, ret = 0;
97 u8 rc_state[2]; 86 u8 rc_state[2];
98 87
99 if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0) 88 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_STATE, rc_state, 1)) != 0)
100 goto unlock; 89 goto unlock;
101 90
102 if ((ret = m9206_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0) 91 if ((ret = m920x_read(d->udev, M9206_CORE, 0x0, M9206_RC_KEY, rc_state + 1, 1)) != 0)
103 goto unlock; 92 goto unlock;
104 93
105 for (i = 0; i < d->props.rc_key_map_size; i++) 94 for (i = 0; i < d->props.rc_key_map_size; i++)
@@ -111,6 +100,14 @@ static int m9206_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
111 *state = REMOTE_NO_KEY_PRESSED; 100 *state = REMOTE_NO_KEY_PRESSED;
112 goto unlock; 101 goto unlock;
113 102
103 case 0x88: /* framing error or "invalid code" */
104 case 0x99:
105 case 0xc0:
106 case 0xd8:
107 *state = REMOTE_NO_KEY_PRESSED;
108 m->rep_count = 0;
109 goto unlock;
110
114 case 0x93: 111 case 0x93:
115 case 0x92: 112 case 0x92:
116 m->rep_count = 0; 113 m->rep_count = 0;
@@ -118,31 +115,32 @@ static int m9206_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
118 goto unlock; 115 goto unlock;
119 116
120 case 0x91: 117 case 0x91:
121 /* For comfort. */ 118 /* prevent immediate auto-repeat */
122 if (++m->rep_count > 2) 119 if (++m->rep_count > 2)
123 *state = REMOTE_KEY_REPEAT; 120 *state = REMOTE_KEY_REPEAT;
121 else
122 *state = REMOTE_NO_KEY_PRESSED;
124 goto unlock; 123 goto unlock;
125 124
126 default: 125 default:
127 deb_rc("Unexpected rc response %x\n", rc_state[0]); 126 deb("Unexpected rc state %02x\n", rc_state[0]);
128 *state = REMOTE_NO_KEY_PRESSED; 127 *state = REMOTE_NO_KEY_PRESSED;
129 goto unlock; 128 goto unlock;
130 } 129 }
131 } 130 }
132 131
133 if (rc_state[1] != 0) 132 if (rc_state[1] != 0)
134 deb_rc("Unknown rc key %x\n", rc_state[1]); 133 deb("Unknown rc key %02x\n", rc_state[1]);
135 134
136 *state = REMOTE_NO_KEY_PRESSED; 135 *state = REMOTE_NO_KEY_PRESSED;
137 136
138 unlock: 137 unlock:
139 138
140 return ret; 139 return ret;
141} 140}
142 141
143/* I2C */ 142/* I2C */
144static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], 143static int m920x_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
145 int num)
146{ 144{
147 struct dvb_usb_device *d = i2c_get_adapdata(adap); 145 struct dvb_usb_device *d = i2c_get_adapdata(adap);
148 int i, j; 146 int i, j;
@@ -155,33 +153,40 @@ static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
155 return -EAGAIN; 153 return -EAGAIN;
156 154
157 for (i = 0; i < num; i++) { 155 for (i = 0; i < num; i++) {
158 if (msg[i].flags & (I2C_M_NO_RD_ACK|I2C_M_IGNORE_NAK|I2C_M_TEN) || 156 if (msg[i].flags & (I2C_M_NO_RD_ACK | I2C_M_IGNORE_NAK | I2C_M_TEN) || msg[i].len == 0) {
159 msg[i].len == 0) { 157 /* For a 0 byte message, I think sending the address
160 /* For a 0 byte message, I think sending the address to index 0x80|0x40 158 * to index 0x80|0x40 would be the correct thing to
161 * would be the correct thing to do. However, zero byte messages are 159 * do. However, zero byte messages are only used for
162 * only used for probing, and since we don't know how to get the slave's 160 * probing, and since we don't know how to get the
163 * ack, we can't probe. */ 161 * slave's ack, we can't probe. */
164 ret = -ENOTSUPP; 162 ret = -ENOTSUPP;
165 goto unlock; 163 goto unlock;
166 } 164 }
167 /* Send START & address/RW bit */ 165 /* Send START & address/RW bit */
168 if (!(msg[i].flags & I2C_M_NOSTART)) { 166 if (!(msg[i].flags & I2C_M_NOSTART)) {
169 if ((ret = m9206_write(d->udev, M9206_I2C, (msg[i].addr<<1)|(msg[i].flags&I2C_M_RD?0x01:0), 0x80)) != 0) 167 if ((ret = m920x_write(d->udev, M9206_I2C,
168 (msg[i].addr << 1) |
169 (msg[i].flags & I2C_M_RD ? 0x01 : 0), 0x80)) != 0)
170 goto unlock; 170 goto unlock;
171 /* Should check for ack here, if we knew how. */ 171 /* Should check for ack here, if we knew how. */
172 } 172 }
173 if (msg[i].flags & I2C_M_RD) { 173 if (msg[i].flags & I2C_M_RD) {
174 for (j = 0; j < msg[i].len; j++) { 174 for (j = 0; j < msg[i].len; j++) {
175 /* Last byte of transaction? Send STOP, otherwise send ACK. */ 175 /* Last byte of transaction?
176 int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x01; 176 * Send STOP, otherwise send ACK. */
177 if ((ret = m9206_read(d->udev, M9206_I2C, 0x0, 0x20|stop, &msg[i].buf[j], 1)) != 0) 177 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x01;
178
179 if ((ret = m920x_read(d->udev, M9206_I2C, 0x0,
180 0x20 | stop,
181 &msg[i].buf[j], 1)) != 0)
178 goto unlock; 182 goto unlock;
179 } 183 }
180 } else { 184 } else {
181 for (j = 0; j < msg[i].len; j++) { 185 for (j = 0; j < msg[i].len; j++) {
182 /* Last byte of transaction? Then send STOP. */ 186 /* Last byte of transaction? Then send STOP. */
183 int stop = (i+1 == num && j+1 == msg[i].len)?0x40:0x00; 187 int stop = (i+1 == num && j+1 == msg[i].len) ? 0x40 : 0x00;
184 if ((ret = m9206_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0) 188
189 if ((ret = m920x_write(d->udev, M9206_I2C, msg[i].buf[j], stop)) != 0)
185 goto unlock; 190 goto unlock;
186 /* Should check for ack here too. */ 191 /* Should check for ack here too. */
187 } 192 }
@@ -189,25 +194,25 @@ static int m9206_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
189 } 194 }
190 ret = num; 195 ret = num;
191 196
192unlock: 197 unlock:
193 mutex_unlock(&d->i2c_mutex); 198 mutex_unlock(&d->i2c_mutex);
194 199
195 return ret; 200 return ret;
196} 201}
197 202
198static u32 m9206_i2c_func(struct i2c_adapter *adapter) 203static u32 m920x_i2c_func(struct i2c_adapter *adapter)
199{ 204{
200 return I2C_FUNC_I2C; 205 return I2C_FUNC_I2C;
201} 206}
202 207
203static struct i2c_algorithm m9206_i2c_algo = { 208static struct i2c_algorithm m920x_i2c_algo = {
204 .master_xfer = m9206_i2c_xfer, 209 .master_xfer = m920x_i2c_xfer,
205 .functionality = m9206_i2c_func, 210 .functionality = m920x_i2c_func,
206}; 211};
207 212
208 213/* pid filter */
209static int m9206_set_filter(struct dvb_usb_adapter *adap, int type, int idx, 214static int m920x_set_filter(struct dvb_usb_adapter *adap,
210 int pid) 215 int type, int idx, int pid)
211{ 216{
212 int ret = 0; 217 int ret = 0;
213 218
@@ -216,18 +221,18 @@ static int m9206_set_filter(struct dvb_usb_adapter *adap, int type, int idx,
216 221
217 pid |= 0x8000; 222 pid |= 0x8000;
218 223
219 if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0) 224 if ((ret = m920x_write(adap->dev->udev, M9206_FILTER, pid, (type << 8) | (idx * 4) )) != 0)
220 return ret; 225 return ret;
221 226
222 if ((ret = m9206_write(adap->dev->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0) 227 if ((ret = m920x_write(adap->dev->udev, M9206_FILTER, 0, (type << 8) | (idx * 4) )) != 0)
223 return ret; 228 return ret;
224 229
225 return ret; 230 return ret;
226} 231}
227 232
228static int m9206_update_filters(struct dvb_usb_adapter *adap) 233static int m920x_update_filters(struct dvb_usb_adapter *adap)
229{ 234{
230 struct m9206_state *m = adap->dev->priv; 235 struct m920x_state *m = adap->dev->priv;
231 int enabled = m->filtering_enabled; 236 int enabled = m->filtering_enabled;
232 int i, ret = 0, filter = 0; 237 int i, ret = 0, filter = 0;
233 238
@@ -236,14 +241,14 @@ static int m9206_update_filters(struct dvb_usb_adapter *adap)
236 enabled = 0; 241 enabled = 0;
237 242
238 /* Disable all filters */ 243 /* Disable all filters */
239 if ((ret = m9206_set_filter(adap, 0x81, 1, enabled)) != 0) 244 if ((ret = m920x_set_filter(adap, 0x81, 1, enabled)) != 0)
240 return ret; 245 return ret;
241 246
242 for (i = 0; i < M9206_MAX_FILTERS; i++) 247 for (i = 0; i < M9206_MAX_FILTERS; i++)
243 if ((ret = m9206_set_filter(adap, 0x81, i + 2, 0)) != 0) 248 if ((ret = m920x_set_filter(adap, 0x81, i + 2, 0)) != 0)
244 return ret; 249 return ret;
245 250
246 if ((ret = m9206_set_filter(adap, 0x82, 0, 0x0)) != 0) 251 if ((ret = m920x_set_filter(adap, 0x82, 0, 0x0)) != 0)
247 return ret; 252 return ret;
248 253
249 /* Set */ 254 /* Set */
@@ -252,40 +257,38 @@ static int m9206_update_filters(struct dvb_usb_adapter *adap)
252 if (m->filters[i] == 0) 257 if (m->filters[i] == 0)
253 continue; 258 continue;
254 259
255 if ((ret = m9206_set_filter(adap, 0x81, filter + 2, m->filters[i])) != 0) 260 if ((ret = m920x_set_filter(adap, 0x81, filter + 2, m->filters[i])) != 0)
256 return ret; 261 return ret;
257 262
258 filter++; 263 filter++;
259 } 264 }
260 } 265 }
261 266
262 if ((ret = m9206_set_filter(adap, 0x82, 0, 0x02f5)) != 0) 267 if ((ret = m920x_set_filter(adap, 0x82, 0, 0x02f5)) != 0)
263 return ret; 268 return ret;
264 269
265 return ret; 270 return ret;
266} 271}
267 272
268static int m9206_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff) 273static int m920x_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
269{ 274{
270 struct m9206_state *m = adap->dev->priv; 275 struct m920x_state *m = adap->dev->priv;
271 276
272 m->filtering_enabled = onoff ? 1 : 0; 277 m->filtering_enabled = onoff ? 1 : 0;
273 278
274 return m9206_update_filters(adap); 279 return m920x_update_filters(adap);
275} 280}
276 281
277static int m9206_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, 282static int m920x_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid, int onoff)
278 int onoff)
279{ 283{
280 struct m9206_state *m = adap->dev->priv; 284 struct m920x_state *m = adap->dev->priv;
281 285
282 m->filters[index] = onoff ? pid : 0; 286 m->filters[index] = onoff ? pid : 0;
283 287
284 return m9206_update_filters(adap); 288 return m920x_update_filters(adap);
285} 289}
286 290
287static int m9206_firmware_download(struct usb_device *udev, 291static int m920x_firmware_download(struct usb_device *udev, const struct firmware *fw)
288 const struct firmware *fw)
289{ 292{
290 u16 value, index, size; 293 u16 value, index, size;
291 u8 read[4], *buff; 294 u8 read[4], *buff;
@@ -293,13 +296,13 @@ static int m9206_firmware_download(struct usb_device *udev,
293 296
294 buff = kmalloc(65536, GFP_KERNEL); 297 buff = kmalloc(65536, GFP_KERNEL);
295 298
296 if ((ret = m9206_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0) 299 if ((ret = m920x_read(udev, M9206_FILTER, 0x0, 0x8000, read, 4)) != 0)
297 goto done; 300 goto done;
298 deb_rc("%x %x %x %x\n", read[0], read[1], read[2], read[3]); 301 deb("%x %x %x %x\n", read[0], read[1], read[2], read[3]);
299 302
300 if ((ret = m9206_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0) 303 if ((ret = m920x_read(udev, M9206_FW, 0x0, 0x0, read, 1)) != 0)
301 goto done; 304 goto done;
302 deb_rc("%x\n", read[0]); 305 deb("%x\n", read[0]);
303 306
304 for (pass = 0; pass < 2; pass++) { 307 for (pass = 0; pass < 2; pass++) {
305 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) { 308 for (i = 0; i + (sizeof(u16) * 3) < fw->size;) {
@@ -317,11 +320,11 @@ static int m9206_firmware_download(struct usb_device *udev,
317 memcpy(buff, fw->data + i, size); 320 memcpy(buff, fw->data + i, size);
318 321
319 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0), 322 ret = usb_control_msg(udev, usb_sndctrlpipe(udev,0),
320 M9206_FW, 323 M9206_FW,
321 USB_TYPE_VENDOR | USB_DIR_OUT, 324 USB_TYPE_VENDOR | USB_DIR_OUT,
322 value, index, buff, size, 20); 325 value, index, buff, size, 20);
323 if (ret != size) { 326 if (ret != size) {
324 deb_rc("error while uploading fw!\n"); 327 deb("error while uploading fw!\n");
325 ret = -EIO; 328 ret = -EIO;
326 goto done; 329 goto done;
327 } 330 }
@@ -330,7 +333,7 @@ static int m9206_firmware_download(struct usb_device *udev,
330 i += size; 333 i += size;
331 } 334 }
332 if (i != fw->size) { 335 if (i != fw->size) {
333 deb_rc("bad firmware file!\n"); 336 deb("bad firmware file!\n");
334 ret = -EINVAL; 337 ret = -EINVAL;
335 goto done; 338 goto done;
336 } 339 }
@@ -338,11 +341,11 @@ static int m9206_firmware_download(struct usb_device *udev,
338 341
339 msleep(36); 342 msleep(36);
340 343
341 /* m9206 will disconnect itself from the bus after this. */ 344 /* m920x will disconnect itself from the bus after this. */
342 (void) m9206_write(udev, M9206_CORE, 0x01, M9206_FW_GO); 345 (void) m920x_write(udev, M9206_CORE, 0x01, M9206_FW_GO);
343 deb_rc("firmware uploaded!\n"); 346 deb("firmware uploaded!\n");
344 347
345 done: 348 done:
346 kfree(buff); 349 kfree(buff);
347 350
348 return ret; 351 return ret;
@@ -362,7 +365,8 @@ static int m920x_identify_state(struct usb_device *udev,
362 return 0; 365 return 0;
363} 366}
364 367
365static int megasky_mt352_demod_init(struct dvb_frontend *fe) 368/* demod configurations */
369static int m920x_mt352_demod_init(struct dvb_frontend *fe)
366{ 370{
367 u8 config[] = { CONFIG, 0x3d }; 371 u8 config[] = { CONFIG, 0x3d };
368 u8 clock[] = { CLOCK_CTL, 0x30 }; 372 u8 clock[] = { CLOCK_CTL, 0x30 };
@@ -382,74 +386,174 @@ static int megasky_mt352_demod_init(struct dvb_frontend *fe)
382 mt352_write(fe, unk1, ARRAY_SIZE(unk1)); 386 mt352_write(fe, unk1, ARRAY_SIZE(unk1));
383 mt352_write(fe, unk2, ARRAY_SIZE(unk2)); 387 mt352_write(fe, unk2, ARRAY_SIZE(unk2));
384 388
385 deb_rc("Demod init!\n"); 389 deb("Demod init!\n");
386 390
387 return 0; 391 return 0;
388} 392}
389 393
390static struct mt352_config megasky_mt352_config = { 394static struct mt352_config m920x_mt352_config = {
391 .demod_address = 0x0f, 395 .demod_address = 0x0f,
392 .no_tuner = 1, 396 .no_tuner = 1,
393 .demod_init = megasky_mt352_demod_init, 397 .demod_init = m920x_mt352_demod_init,
398};
399
400static struct tda1004x_config m920x_tda10046_08_config = {
401 .demod_address = 0x08,
402 .invert = 0,
403 .invert_oclk = 0,
404 .ts_mode = TDA10046_TS_SERIAL,
405 .xtal_freq = TDA10046_XTAL_16M,
406 .if_freq = TDA10046_FREQ_045,
407 .agc_config = TDA10046_AGC_TDA827X,
408 .gpio_config = TDA10046_GPTRI,
409 .request_firmware = NULL,
410};
411
412static struct tda1004x_config m920x_tda10046_0b_config = {
413 .demod_address = 0x0b,
414 .invert = 0,
415 .invert_oclk = 0,
416 .ts_mode = TDA10046_TS_SERIAL,
417 .xtal_freq = TDA10046_XTAL_16M,
418 .if_freq = TDA10046_FREQ_045,
419 .agc_config = TDA10046_AGC_TDA827X,
420 .gpio_config = TDA10046_GPTRI,
421 .request_firmware = NULL, /* uses firmware EEPROM */
422};
423
424/* tuner configurations */
425static struct qt1010_config m920x_qt1010_config = {
426 .i2c_address = 0x62
394}; 427};
395 428
396static int megasky_mt352_frontend_attach(struct dvb_usb_adapter *adap) 429/* Callbacks for DVB USB */
430static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
397{ 431{
398 deb_rc("megasky_frontend_attach!\n"); 432 deb("%s\n",__FUNCTION__);
399 433
400 if ((adap->fe = dvb_attach(mt352_attach, &megasky_mt352_config, &adap->dev->i2c_adap)) == NULL) 434 if ((adap->fe = dvb_attach(mt352_attach,
435 &m920x_mt352_config,
436 &adap->dev->i2c_adap)) == NULL)
401 return -EIO; 437 return -EIO;
402 438
403 return 0; 439 return 0;
404} 440}
405 441
406static struct qt1010_config megasky_qt1010_config = { 442static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
407 .i2c_address = 0x62
408};
409
410static int megasky_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
411{ 443{
412 if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, 444 deb("%s\n",__FUNCTION__);
413 &megasky_qt1010_config) == NULL) 445
414 return -ENODEV; 446 if ((adap->fe = dvb_attach(tda10046_attach,
447 &m920x_tda10046_08_config,
448 &adap->dev->i2c_adap)) == NULL)
449 return -EIO;
415 450
416 return 0; 451 return 0;
417} 452}
418 453
419static struct tda1004x_config digivox_tda10046_config = { 454static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
420 .demod_address = 0x08,
421 .invert = 0,
422 .invert_oclk = 0,
423 .ts_mode = TDA10046_TS_SERIAL,
424 .xtal_freq = TDA10046_XTAL_16M,
425 .if_freq = TDA10046_FREQ_045,
426 .agc_config = TDA10046_AGC_TDA827X,
427 .gpio_config = TDA10046_GPTRI,
428 .request_firmware = NULL,
429};
430
431static int digivox_tda10046_frontend_attach(struct dvb_usb_adapter *adap)
432{ 455{
433 deb_rc("digivox_tda10046_frontend_attach!\n"); 456 deb("%s\n",__FUNCTION__);
434 457
435 if ((adap->fe = dvb_attach(tda10046_attach, &digivox_tda10046_config, 458 if ((adap->fe = dvb_attach(tda10046_attach,
459 &m920x_tda10046_0b_config,
436 &adap->dev->i2c_adap)) == NULL) 460 &adap->dev->i2c_adap)) == NULL)
437 return -EIO; 461 return -EIO;
438 462
439 return 0; 463 return 0;
440} 464}
441 465
442static int digivox_tda8275_tuner_attach(struct dvb_usb_adapter *adap) 466static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
443{ 467{
444 if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, 468 deb("%s\n",__FUNCTION__);
445 NULL) == NULL) 469
470 if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
446 return -ENODEV; 471 return -ENODEV;
472
447 return 0; 473 return 0;
448} 474}
449 475
476static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
477{
478 deb("%s\n",__FUNCTION__);
479
480 if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
481 return -ENODEV;
482
483 return 0;
484}
485
486static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
487{
488 deb("%s\n",__FUNCTION__);
489
490 if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
491 return -ENODEV;
492
493 return 0;
494}
495
496/* device-specific initialization */
497static struct m920x_inits megasky_rc_init [] = {
498 { M9206_RC_INIT2, 0xa8 },
499 { M9206_RC_INIT1, 0x51 },
500 { } /* terminating entry */
501};
502
503static struct m920x_inits tvwalkertwin_rc_init [] = {
504 { M9206_RC_INIT2, 0x00 },
505 { M9206_RC_INIT1, 0xef },
506 { 0xff28, 0x00 },
507 { 0xff23, 0x00 },
508 { 0xff21, 0x30 },
509 { } /* terminating entry */
510};
511
512/* ir keymaps */
513static struct dvb_usb_rc_key megasky_rc_keys [] = {
514 { 0x0, 0x12, KEY_POWER },
515 { 0x0, 0x1e, KEY_CYCLEWINDOWS }, /* min/max */
516 { 0x0, 0x02, KEY_CHANNELUP },
517 { 0x0, 0x05, KEY_CHANNELDOWN },
518 { 0x0, 0x03, KEY_VOLUMEUP },
519 { 0x0, 0x06, KEY_VOLUMEDOWN },
520 { 0x0, 0x04, KEY_MUTE },
521 { 0x0, 0x07, KEY_OK }, /* TS */
522 { 0x0, 0x08, KEY_STOP },
523 { 0x0, 0x09, KEY_MENU }, /* swap */
524 { 0x0, 0x0a, KEY_REWIND },
525 { 0x0, 0x1b, KEY_PAUSE },
526 { 0x0, 0x1f, KEY_FASTFORWARD },
527 { 0x0, 0x0c, KEY_RECORD },
528 { 0x0, 0x0d, KEY_CAMERA }, /* screenshot */
529 { 0x0, 0x0e, KEY_COFFEE }, /* "MTS" */
530};
531
532static struct dvb_usb_rc_key tvwalkertwin_rc_keys [] = {
533 { 0x0, 0x01, KEY_ZOOM }, /* Full Screen */
534 { 0x0, 0x02, KEY_CAMERA }, /* snapshot */
535 { 0x0, 0x03, KEY_MUTE },
536 { 0x0, 0x04, KEY_REWIND },
537 { 0x0, 0x05, KEY_PLAYPAUSE }, /* Play/Pause */
538 { 0x0, 0x06, KEY_FASTFORWARD },
539 { 0x0, 0x07, KEY_RECORD },
540 { 0x0, 0x08, KEY_STOP },
541 { 0x0, 0x09, KEY_TIME }, /* Timeshift */
542 { 0x0, 0x0c, KEY_COFFEE }, /* Recall */
543 { 0x0, 0x0e, KEY_CHANNELUP },
544 { 0x0, 0x12, KEY_POWER },
545 { 0x0, 0x15, KEY_MENU }, /* source */
546 { 0x0, 0x18, KEY_CYCLEWINDOWS }, /* TWIN PIP */
547 { 0x0, 0x1a, KEY_CHANNELDOWN },
548 { 0x0, 0x1b, KEY_VOLUMEDOWN },
549 { 0x0, 0x1e, KEY_VOLUMEUP },
550};
551
450/* DVB USB Driver stuff */ 552/* DVB USB Driver stuff */
451static struct dvb_usb_device_properties megasky_properties; 553static struct dvb_usb_device_properties megasky_properties;
452static struct dvb_usb_device_properties digivox_mini_ii_properties; 554static struct dvb_usb_device_properties digivox_mini_ii_properties;
555static struct dvb_usb_device_properties tvwalkertwin_properties;
556static struct dvb_usb_device_properties dposh_properties;
453 557
454static int m920x_probe(struct usb_interface *intf, 558static int m920x_probe(struct usb_interface *intf,
455 const struct usb_device_id *id) 559 const struct usb_device_id *id)
@@ -457,19 +561,57 @@ static int m920x_probe(struct usb_interface *intf,
457 struct dvb_usb_device *d; 561 struct dvb_usb_device *d;
458 struct usb_host_interface *alt; 562 struct usb_host_interface *alt;
459 int ret; 563 int ret;
564 struct m920x_inits *rc_init_seq = NULL;
565 int bInterfaceNumber = intf->cur_altsetting->desc.bInterfaceNumber;
460 566
461 deb_rc("Probed!\n"); 567 deb("Probing for m920x device at interface %d\n", bInterfaceNumber);
462 568
463 if (((ret = dvb_usb_device_init(intf, &megasky_properties, THIS_MODULE, &d)) == 0) || 569 if (bInterfaceNumber == 0) {
464 ((ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties, THIS_MODULE, &d)) == 0)) 570 /* Single-tuner device, or first interface on
465 goto found; 571 * multi-tuner device
572 */
466 573
467 return ret; 574 if ((ret = dvb_usb_device_init(intf, &megasky_properties,
575 THIS_MODULE, &d)) == 0) {
576 rc_init_seq = megasky_rc_init;
577 goto found;
578 }
579
580 if ((ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
581 THIS_MODULE, &d)) == 0) {
582 /* No remote control, so no rc_init_seq */
583 goto found;
584 }
585
586 /* This configures both tuners on the TV Walker Twin */
587 if ((ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
588 THIS_MODULE, &d)) == 0) {
589 rc_init_seq = tvwalkertwin_rc_init;
590 goto found;
591 }
592
593 if ((ret = dvb_usb_device_init(intf, &dposh_properties,
594 THIS_MODULE, &d)) == 0) {
595 /* Remote controller not supported yet. */
596 goto found;
597 }
598
599 return ret;
600 } else {
601 /* Another interface on a multi-tuner device */
468 602
469found: 603 /* The LifeView TV Walker Twin gets here, but struct
604 * tvwalkertwin_properties already configured both
605 * tuners, so there is nothing for us to do here
606 */
607
608 return -ENODEV;
609 }
610
611 found:
470 alt = usb_altnum_to_altsetting(intf, 1); 612 alt = usb_altnum_to_altsetting(intf, 1);
471 if (alt == NULL) { 613 if (alt == NULL) {
472 deb_rc("No alt found!\n"); 614 deb("No alt found!\n");
473 return -ENODEV; 615 return -ENODEV;
474 } 616 }
475 617
@@ -478,7 +620,7 @@ found:
478 if (ret < 0) 620 if (ret < 0)
479 return ret; 621 return ret;
480 622
481 if ((ret = m9206_init(d)) != 0) 623 if ((ret = m920x_init(d, rc_init_seq)) != 0)
482 return ret; 624 return ret;
483 625
484 return ret; 626 return ret;
@@ -488,6 +630,12 @@ static struct usb_device_id m920x_table [] = {
488 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) }, 630 { USB_DEVICE(USB_VID_MSI, USB_PID_MSI_MEGASKY580) },
489 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC, 631 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
490 USB_PID_MSI_DIGI_VOX_MINI_II) }, 632 USB_PID_MSI_DIGI_VOX_MINI_II) },
633 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
634 USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD) },
635 { USB_DEVICE(USB_VID_ANUBIS_ELECTRONIC,
636 USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM) },
637 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_COLD) },
638 { USB_DEVICE(USB_VID_DPOSH, USB_PID_DPOSH_M9206_WARM) },
491 { } /* Terminating entry */ 639 { } /* Terminating entry */
492}; 640};
493MODULE_DEVICE_TABLE (usb, m920x_table); 641MODULE_DEVICE_TABLE (usb, m920x_table);
@@ -497,14 +645,14 @@ static struct dvb_usb_device_properties megasky_properties = {
497 645
498 .usb_ctrl = DEVICE_SPECIFIC, 646 .usb_ctrl = DEVICE_SPECIFIC,
499 .firmware = "dvb-usb-megasky-02.fw", 647 .firmware = "dvb-usb-megasky-02.fw",
500 .download_firmware = m9206_firmware_download, 648 .download_firmware = m920x_firmware_download,
501 649
502 .rc_interval = 100, 650 .rc_interval = 100,
503 .rc_key_map = megasky_rc_keys, 651 .rc_key_map = megasky_rc_keys,
504 .rc_key_map_size = ARRAY_SIZE(megasky_rc_keys), 652 .rc_key_map_size = ARRAY_SIZE(megasky_rc_keys),
505 .rc_query = m9206_rc_query, 653 .rc_query = m920x_rc_query,
506 654
507 .size_of_priv = sizeof(struct m9206_state), 655 .size_of_priv = sizeof(struct m920x_state),
508 656
509 .identify_state = m920x_identify_state, 657 .identify_state = m920x_identify_state,
510 .num_adapters = 1, 658 .num_adapters = 1,
@@ -513,11 +661,11 @@ static struct dvb_usb_device_properties megasky_properties = {
513 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 661 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
514 662
515 .pid_filter_count = 8, 663 .pid_filter_count = 8,
516 .pid_filter = m9206_pid_filter, 664 .pid_filter = m920x_pid_filter,
517 .pid_filter_ctrl = m9206_pid_filter_ctrl, 665 .pid_filter_ctrl = m920x_pid_filter_ctrl,
518 666
519 .frontend_attach = megasky_mt352_frontend_attach, 667 .frontend_attach = m920x_mt352_frontend_attach,
520 .tuner_attach = megasky_qt1010_tuner_attach, 668 .tuner_attach = m920x_qt1010_tuner_attach,
521 669
522 .stream = { 670 .stream = {
523 .type = USB_BULK, 671 .type = USB_BULK,
@@ -530,7 +678,7 @@ static struct dvb_usb_device_properties megasky_properties = {
530 } 678 }
531 }, 679 },
532 }}, 680 }},
533 .i2c_algo = &m9206_i2c_algo, 681 .i2c_algo = &m920x_i2c_algo,
534 682
535 .num_device_descs = 1, 683 .num_device_descs = 1,
536 .devices = { 684 .devices = {
@@ -546,22 +694,22 @@ static struct dvb_usb_device_properties digivox_mini_ii_properties = {
546 694
547 .usb_ctrl = DEVICE_SPECIFIC, 695 .usb_ctrl = DEVICE_SPECIFIC,
548 .firmware = "dvb-usb-digivox-02.fw", 696 .firmware = "dvb-usb-digivox-02.fw",
549 .download_firmware = m9206_firmware_download, 697 .download_firmware = m920x_firmware_download,
550 698
551 .size_of_priv = sizeof(struct m9206_state), 699 .size_of_priv = sizeof(struct m920x_state),
552 700
553 .identify_state = m920x_identify_state, 701 .identify_state = m920x_identify_state,
554 .num_adapters = 1, 702 .num_adapters = 1,
555 .adapter = {{ 703 .adapter = {{
556 .caps = DVB_USB_ADAP_HAS_PID_FILTER | 704 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
557 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF, 705 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
558 706
559 .pid_filter_count = 8, 707 .pid_filter_count = 8,
560 .pid_filter = m9206_pid_filter, 708 .pid_filter = m920x_pid_filter,
561 .pid_filter_ctrl = m9206_pid_filter_ctrl, 709 .pid_filter_ctrl = m920x_pid_filter_ctrl,
562 710
563 .frontend_attach = digivox_tda10046_frontend_attach, 711 .frontend_attach = m920x_tda10046_08_frontend_attach,
564 .tuner_attach = digivox_tda8275_tuner_attach, 712 .tuner_attach = m920x_tda8275_60_tuner_attach,
565 713
566 .stream = { 714 .stream = {
567 .type = USB_BULK, 715 .type = USB_BULK,
@@ -574,7 +722,7 @@ static struct dvb_usb_device_properties digivox_mini_ii_properties = {
574 } 722 }
575 }, 723 },
576 }}, 724 }},
577 .i2c_algo = &m9206_i2c_algo, 725 .i2c_algo = &m920x_i2c_algo,
578 726
579 .num_device_descs = 1, 727 .num_device_descs = 1,
580 .devices = { 728 .devices = {
@@ -585,6 +733,122 @@ static struct dvb_usb_device_properties digivox_mini_ii_properties = {
585 } 733 }
586}; 734};
587 735
736/* LifeView TV Walker Twin support by Nick Andrew <nick@nick-andrew.net>
737 *
738 * LifeView TV Walker Twin has 1 x M9206, 2 x TDA10046, 2 x TDA8275A
739 * TDA10046 #0 is located at i2c address 0x08
740 * TDA10046 #1 is located at i2c address 0x0b (presently disabled - not yet working)
741 * TDA8275A #0 is located at i2c address 0x60
742 * TDA8275A #1 is located at i2c address 0x61 (presently disabled - not yet working)
743 */
744static struct dvb_usb_device_properties tvwalkertwin_properties = {
745 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
746
747 .usb_ctrl = DEVICE_SPECIFIC,
748 .firmware = "dvb-usb-tvwalkert.fw",
749 .download_firmware = m920x_firmware_download,
750
751 .rc_interval = 100,
752 .rc_key_map = tvwalkertwin_rc_keys,
753 .rc_key_map_size = ARRAY_SIZE(tvwalkertwin_rc_keys),
754 .rc_query = m920x_rc_query,
755
756 .size_of_priv = sizeof(struct m920x_state),
757
758 .identify_state = m920x_identify_state,
759 .num_adapters = 1,
760 .adapter = {{
761 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
762 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
763
764 .pid_filter_count = 8,
765 .pid_filter = m920x_pid_filter,
766 .pid_filter_ctrl = m920x_pid_filter_ctrl,
767
768 .frontend_attach = m920x_tda10046_08_frontend_attach,
769 .tuner_attach = m920x_tda8275_60_tuner_attach,
770
771 .stream = {
772 .type = USB_BULK,
773 .count = 8,
774 .endpoint = 0x81,
775 .u = {
776 .bulk = {
777 .buffersize = 512,
778 }
779 }
780 }},{
781 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
782 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
783
784 .pid_filter_count = 8,
785 .pid_filter = m920x_pid_filter,
786 .pid_filter_ctrl = m920x_pid_filter_ctrl,
787
788 .frontend_attach = m920x_tda10046_0b_frontend_attach,
789 .tuner_attach = m920x_tda8275_61_tuner_attach,
790
791 .stream = {
792 .type = USB_BULK,
793 .count = 8,
794 .endpoint = 0x82,
795 .u = {
796 .bulk = {
797 .buffersize = 512,
798 }
799 }
800 },
801 }},
802 .i2c_algo = &m920x_i2c_algo,
803
804 .num_device_descs = 1,
805 .devices = {
806 { .name = "LifeView TV Walker Twin DVB-T USB2.0",
807 .cold_ids = { &m920x_table[2], NULL },
808 .warm_ids = { &m920x_table[3], NULL },
809 },
810 }
811};
812
813static struct dvb_usb_device_properties dposh_properties = {
814 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
815
816 .usb_ctrl = DEVICE_SPECIFIC,
817 .firmware = "dvb-usb-dposh-01.fw",
818 .download_firmware = m920x_firmware_download,
819
820 .size_of_priv = sizeof(struct m920x_state),
821
822 .identify_state = m920x_identify_state,
823 .num_adapters = 1,
824 .adapter = {{
825 /* Hardware pid filters don't work with this device/firmware */
826
827 .frontend_attach = m920x_mt352_frontend_attach,
828 .tuner_attach = m920x_qt1010_tuner_attach,
829
830 .stream = {
831 .type = USB_BULK,
832 .count = 8,
833 .endpoint = 0x81,
834 .u = {
835 .bulk = {
836 .buffersize = 512,
837 }
838 }
839 },
840 }},
841 .i2c_algo = &m920x_i2c_algo,
842
843 .num_device_descs = 1,
844 .devices = {
845 { .name = "Dposh DVB-T USB2.0",
846 .cold_ids = { &m920x_table[4], NULL },
847 .warm_ids = { &m920x_table[5], NULL },
848 },
849 }
850};
851
588static struct usb_driver m920x_driver = { 852static struct usb_driver m920x_driver = {
589 .name = "dvb_usb_m920x", 853 .name = "dvb_usb_m920x",
590 .probe = m920x_probe, 854 .probe = m920x_probe,
@@ -615,6 +879,11 @@ module_init (m920x_module_init);
615module_exit (m920x_module_exit); 879module_exit (m920x_module_exit);
616 880
617MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>"); 881MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
618MODULE_DESCRIPTION("Driver MSI Mega Sky 580 DVB-T USB2.0 / Uli m920x"); 882MODULE_DESCRIPTION("DVB Driver for ULI M920x");
619MODULE_VERSION("0.1"); 883MODULE_VERSION("0.1");
620MODULE_LICENSE("GPL"); 884MODULE_LICENSE("GPL");
885
886/*
887 * Local variables:
888 * c-basic-offset: 8
889 */
diff --git a/drivers/media/dvb/dvb-usb/m920x.h b/drivers/media/dvb/dvb-usb/m920x.h
index 7dd3db65c80e..2c8942d04222 100644
--- a/drivers/media/dvb/dvb-usb/m920x.h
+++ b/drivers/media/dvb/dvb-usb/m920x.h
@@ -4,7 +4,7 @@
4#define DVB_USB_LOG_PREFIX "m920x" 4#define DVB_USB_LOG_PREFIX "m920x"
5#include "dvb-usb.h" 5#include "dvb-usb.h"
6 6
7#define deb_rc(args...) dprintk(dvb_usb_m920x_debug,0x01,args) 7#define deb(args...) dprintk(dvb_usb_m920x_debug,0x01,args)
8 8
9#define M9206_CORE 0x22 9#define M9206_CORE 0x22
10#define M9206_RC_STATE 0xff51 10#define M9206_RC_STATE 0xff51
@@ -59,9 +59,18 @@ What any other bits might mean, or how to get the slave's ACK/NACK
59response to a write, is unknown. 59response to a write, is unknown.
60*/ 60*/
61 61
62struct m9206_state { 62struct m920x_state {
63 u16 filters[M9206_MAX_FILTERS]; 63 u16 filters[M9206_MAX_FILTERS];
64 int filtering_enabled; 64 int filtering_enabled;
65 int rep_count; 65 int rep_count;
66}; 66};
67
68/* Initialisation data for the m920x
69 */
70
71struct m920x_inits {
72 u16 address;
73 u8 data;
74};
75
67#endif 76#endif
diff --git a/drivers/media/dvb/dvb-usb/vp702x-fe.c b/drivers/media/dvb/dvb-usb/vp702x-fe.c
index 3ecb2e0ce80f..c3fdc7cd094e 100644
--- a/drivers/media/dvb/dvb-usb/vp702x-fe.c
+++ b/drivers/media/dvb/dvb-usb/vp702x-fe.c
@@ -204,8 +204,8 @@ static int vp702x_fe_get_frontend(struct dvb_frontend* fe,
204static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe, 204static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
205 struct dvb_diseqc_master_cmd *m) 205 struct dvb_diseqc_master_cmd *m)
206{ 206{
207 //struct vp702x_fe_state *st = fe->demodulator_priv; 207 struct vp702x_fe_state *st = fe->demodulator_priv;
208 u8 cmd[8];//,ibuf[10]; 208 u8 cmd[8],ibuf[10];
209 memset(cmd,0,8); 209 memset(cmd,0,8);
210 210
211 deb_fe("%s\n",__FUNCTION__); 211 deb_fe("%s\n",__FUNCTION__);
@@ -218,12 +218,12 @@ static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
218 memcpy(&cmd[3], m->msg, m->msg_len); 218 memcpy(&cmd[3], m->msg, m->msg_len);
219 cmd[7] = vp702x_chksum(cmd,0,7); 219 cmd[7] = vp702x_chksum(cmd,0,7);
220 220
221// vp702x_usb_inout_op(st->d,cmd,8,ibuf,10,100); 221 vp702x_usb_inout_op(st->d,cmd,8,ibuf,10,100);
222 222
223// if (ibuf[2] == 0 && ibuf[3] == 0) 223 if (ibuf[2] == 0 && ibuf[3] == 0)
224// deb_fe("diseqc cmd failed.\n"); 224 deb_fe("diseqc cmd failed.\n");
225// else 225 else
226// deb_fe("diseqc cmd succeeded.\n"); 226 deb_fe("diseqc cmd succeeded.\n");
227 227
228 return 0; 228 return 0;
229} 229}
diff --git a/drivers/media/dvb/frontends/dib7000m.c b/drivers/media/dvb/frontends/dib7000m.c
index f5d40aa3d27f..f64546c6aeb5 100644
--- a/drivers/media/dvb/frontends/dib7000m.c
+++ b/drivers/media/dvb/frontends/dib7000m.c
@@ -266,7 +266,7 @@ static int dib7000m_sad_calib(struct dib7000m_state *state)
266{ 266{
267 267
268/* internal */ 268/* internal */
269// dib7000m_write_word(state, 928, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is writting in set_bandwidth 269// dib7000m_write_word(state, 928, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is written in set_bandwidth
270 dib7000m_write_word(state, 929, (0 << 1) | (0 << 0)); 270 dib7000m_write_word(state, 929, (0 << 1) | (0 << 0));
271 dib7000m_write_word(state, 930, 776); // 0.625*3.3 / 4096 271 dib7000m_write_word(state, 930, 776); // 0.625*3.3 / 4096
272 272
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index 0349a4b5da3f..aece458cfe12 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -223,7 +223,7 @@ static int dib7000p_set_bandwidth(struct dvb_frontend *demod, u8 BW_Idx)
223static int dib7000p_sad_calib(struct dib7000p_state *state) 223static int dib7000p_sad_calib(struct dib7000p_state *state)
224{ 224{
225/* internal */ 225/* internal */
226// dib7000p_write_word(state, 72, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is writting in set_bandwidth 226// dib7000p_write_word(state, 72, (3 << 14) | (1 << 12) | (524 << 0)); // sampling clock of the SAD is written in set_bandwidth
227 dib7000p_write_word(state, 73, (0 << 1) | (0 << 0)); 227 dib7000p_write_word(state, 73, (0 << 1) | (0 << 0));
228 dib7000p_write_word(state, 74, 776); // 0.625*3.3 / 4096 228 dib7000p_write_word(state, 74, 776); // 0.625*3.3 / 4096
229 229
diff --git a/drivers/media/dvb/frontends/tda10021.c b/drivers/media/dvb/frontends/tda10021.c
index 110536843e8e..e725f612a6b7 100644
--- a/drivers/media/dvb/frontends/tda10021.c
+++ b/drivers/media/dvb/frontends/tda10021.c
@@ -1,6 +1,6 @@
1/* 1/*
2 TDA10021 - Single Chip Cable Channel Receiver driver module 2 TDA10021 - Single Chip Cable Channel Receiver driver module
3 used on the the Siemens DVB-C cards 3 used on the Siemens DVB-C cards
4 4
5 Copyright (C) 1999 Convergence Integrated Media GmbH <ralph@convergence.de> 5 Copyright (C) 1999 Convergence Integrated Media GmbH <ralph@convergence.de>
6 Copyright (C) 2004 Markus Schulz <msc@antzsystem.de> 6 Copyright (C) 2004 Markus Schulz <msc@antzsystem.de>
diff --git a/drivers/media/dvb/frontends/ves1x93.c b/drivers/media/dvb/frontends/ves1x93.c
index 54d7b07571b8..23fd0303c91b 100644
--- a/drivers/media/dvb/frontends/ves1x93.c
+++ b/drivers/media/dvb/frontends/ves1x93.c
@@ -306,7 +306,7 @@ static int ves1x93_read_status(struct dvb_frontend* fe, fe_status_t* status)
306 * The ves1893 sometimes returns sync values that make no sense, 306 * The ves1893 sometimes returns sync values that make no sense,
307 * because, e.g., the SIGNAL bit is 0, while some of the higher 307 * because, e.g., the SIGNAL bit is 0, while some of the higher
308 * bits are 1 (and how can there be a CARRIER w/o a SIGNAL?). 308 * bits are 1 (and how can there be a CARRIER w/o a SIGNAL?).
309 * Tests showed that the the VITERBI and SYNC bits are returned 309 * Tests showed that the VITERBI and SYNC bits are returned
310 * reliably, while the SIGNAL and CARRIER bits ar sometimes wrong. 310 * reliably, while the SIGNAL and CARRIER bits ar sometimes wrong.
311 * If such a case occurs, we read the value again, until we get a 311 * If such a case occurs, we read the value again, until we get a
312 * valid value. 312 * valid value.
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
index 058df5c10034..08a2599ed74a 100644
--- a/drivers/media/dvb/pluto2/pluto2.c
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -293,12 +293,20 @@ static void pluto_dma_end(struct pluto *pluto, unsigned int nbpackets)
293 * but no packets have been transfered. 293 * but no packets have been transfered.
294 * [2] Sometimes (actually very often) NBPACKETS stays at zero 294 * [2] Sometimes (actually very often) NBPACKETS stays at zero
295 * although one packet has been transfered. 295 * although one packet has been transfered.
296 * [3] Sometimes (actually rarely), the card gets into an erroneous
297 * mode where it continuously generates interrupts, claiming it
298 * has recieved nbpackets>TS_DMA_PACKETS packets, but no packet
299 * has been transfered. Only a reset seems to solve this
296 */ 300 */
297 if ((nbpackets == 0) || (nbpackets > TS_DMA_PACKETS)) { 301 if ((nbpackets == 0) || (nbpackets > TS_DMA_PACKETS)) {
298 unsigned int i = 0; 302 unsigned int i = 0;
299 while (pluto->dma_buf[i] == 0x47) 303 while (pluto->dma_buf[i] == 0x47)
300 i += 188; 304 i += 188;
301 nbpackets = i / 188; 305 nbpackets = i / 188;
306 if (i == 0) {
307 pluto_reset_ts(pluto, 1);
308 dev_printk(KERN_DEBUG, &pluto->pdev->dev, "resetting TS because of invalid packet counter\n");
309 }
302 } 310 }
303 311
304 dvb_dmx_swfilter_packets(&pluto->demux, pluto->dma_buf, nbpackets); 312 dvb_dmx_swfilter_packets(&pluto->demux, pluto->dma_buf, nbpackets);
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 67becdd4db60..ef1108c0bf11 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -1246,6 +1246,9 @@ static void vpeirq(unsigned long data)
1246 if (!budget->feeding1 || (newdma == olddma)) 1246 if (!budget->feeding1 || (newdma == olddma))
1247 return; 1247 return;
1248 1248
1249 /* Ensure streamed PCI data is synced to CPU */
1250 pci_dma_sync_sg_for_cpu(budget->dev->pci, budget->pt.slist, budget->pt.nents, PCI_DMA_FROMDEVICE);
1251
1249#if 0 1252#if 0
1250 /* track rps1 activity */ 1253 /* track rps1 activity */
1251 printk("vpeirq: %02x Event Counter 1 0x%04x\n", 1254 printk("vpeirq: %02x Event Counter 1 0x%04x\n",
@@ -2679,8 +2682,8 @@ err_iobuf_vfree_6:
2679err_pci_free_5: 2682err_pci_free_5:
2680 pci_free_consistent(pdev, 8192, av7110->debi_virt, av7110->debi_bus); 2683 pci_free_consistent(pdev, 8192, av7110->debi_virt, av7110->debi_bus);
2681err_saa71466_vfree_4: 2684err_saa71466_vfree_4:
2682 if (!av7110->grabbing) 2685 if (av7110->grabbing)
2683 saa7146_pgtable_free(pdev, &av7110->pt); 2686 saa7146_vfree_destroy_pgtable(pdev, av7110->grabbing, &av7110->pt);
2684err_i2c_del_3: 2687err_i2c_del_3:
2685 i2c_del_adapter(&av7110->i2c_adap); 2688 i2c_del_adapter(&av7110->i2c_adap);
2686err_dvb_unregister_adapter_2: 2689err_dvb_unregister_adapter_2:
@@ -2710,7 +2713,7 @@ static int __devexit av7110_detach(struct saa7146_dev* saa)
2710 SAA7146_ISR_CLEAR(saa, MASK_10); 2713 SAA7146_ISR_CLEAR(saa, MASK_10);
2711 msleep(50); 2714 msleep(50);
2712 tasklet_kill(&av7110->vpe_tasklet); 2715 tasklet_kill(&av7110->vpe_tasklet);
2713 saa7146_pgtable_free(saa->pci, &av7110->pt); 2716 saa7146_vfree_destroy_pgtable(saa->pci, av7110->grabbing, &av7110->pt);
2714 } 2717 }
2715 av7110_exit_v4l(av7110); 2718 av7110_exit_v4l(av7110);
2716 2719
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index 654c9e919e04..58678c05aa53 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -32,7 +32,6 @@
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/smp_lock.h>
36#include <linux/fs.h> 35#include <linux/fs.h>
37 36
38#include "av7110.h" 37#include "av7110.h"
diff --git a/drivers/media/dvb/ttpci/av7110_ca.c b/drivers/media/dvb/ttpci/av7110_ca.c
index e9b4e88e7932..e1c1294bb767 100644
--- a/drivers/media/dvb/ttpci/av7110_ca.c
+++ b/drivers/media/dvb/ttpci/av7110_ca.c
@@ -34,7 +34,6 @@
34#include <linux/fs.h> 34#include <linux/fs.h>
35#include <linux/timer.h> 35#include <linux/timer.h>
36#include <linux/poll.h> 36#include <linux/poll.h>
37#include <linux/smp_lock.h>
38 37
39#include "av7110.h" 38#include "av7110.h"
40#include "av7110_hw.h" 39#include "av7110_hw.h"
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
index 4d7150e15d1e..70aee4eb5da4 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ b/drivers/media/dvb/ttpci/av7110_hw.c
@@ -33,7 +33,6 @@
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/string.h> 34#include <linux/string.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/smp_lock.h>
37#include <linux/fs.h> 36#include <linux/fs.h>
38 37
39#include "av7110.h" 38#include "av7110.h"
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index cde5d3ae7ec7..fcd9994058d0 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -31,7 +31,6 @@
31#include <linux/fs.h> 31#include <linux/fs.h>
32#include <linux/timer.h> 32#include <linux/timer.h>
33#include <linux/poll.h> 33#include <linux/poll.h>
34#include <linux/smp_lock.h>
35 34
36#include "av7110.h" 35#include "av7110.h"
37#include "av7110_hw.h" 36#include "av7110_hw.h"
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index 4ed4599ce816..9d42f88ebb0e 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -904,7 +904,7 @@ static int dvbc_philips_tdm1316l_tuner_set_params(struct dvb_frontend *fe, struc
904 band = 1; 904 band = 1;
905 } else if (tuner_frequency < 200000000) { 905 } else if (tuner_frequency < 200000000) {
906 cp = 6; 906 cp = 6;
907 band = 2; 907 band = 1;
908 } else if (tuner_frequency < 290000000) { 908 } else if (tuner_frequency < 290000000) {
909 cp = 3; 909 cp = 3;
910 band = 2; 910 band = 2;
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
index 6b97dc1e6b65..2557ac9620d0 100644
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ b/drivers/media/dvb/ttpci/budget-core.c
@@ -195,6 +195,9 @@ static void vpeirq(unsigned long data)
195 u32 newdma = saa7146_read(budget->dev, PCI_VDP3); 195 u32 newdma = saa7146_read(budget->dev, PCI_VDP3);
196 u32 count; 196 u32 count;
197 197
198 /* Ensure streamed PCI data is synced to CPU */
199 pci_dma_sync_sg_for_cpu(budget->dev->pci, budget->pt.slist, budget->pt.nents, PCI_DMA_FROMDEVICE);
200
198 /* nearest lower position divisible by 188 */ 201 /* nearest lower position divisible by 188 */
199 newdma -= newdma % 188; 202 newdma -= newdma % 188;
200 203
@@ -504,16 +507,16 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
504 strcpy(budget->i2c_adap.name, budget->card->name); 507 strcpy(budget->i2c_adap.name, budget->card->name);
505 508
506 if (i2c_add_adapter(&budget->i2c_adap) < 0) { 509 if (i2c_add_adapter(&budget->i2c_adap) < 0) {
507 dvb_unregister_adapter(&budget->dvb_adapter); 510 ret = -ENOMEM;
508 return -ENOMEM; 511 goto err_dvb_unregister;
509 } 512 }
510 513
511 ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac); 514 ttpci_eeprom_parse_mac(&budget->i2c_adap, budget->dvb_adapter.proposed_mac);
512 515
513 if (NULL == 516 budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, budget->buffer_size, &budget->pt);
514 (budget->grabbing = saa7146_vmalloc_build_pgtable(dev->pci, budget->buffer_size, &budget->pt))) { 517 if (NULL == budget->grabbing) {
515 ret = -ENOMEM; 518 ret = -ENOMEM;
516 goto err; 519 goto err_del_i2c;
517 } 520 }
518 521
519 saa7146_write(dev, PCI_BT_V1, 0x001c0000); 522 saa7146_write(dev, PCI_BT_V1, 0x001c0000);
@@ -526,14 +529,16 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
526 if (bi->type != BUDGET_FS_ACTIVY) 529 if (bi->type != BUDGET_FS_ACTIVY)
527 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI); 530 saa7146_setgpio(dev, 2, SAA7146_GPIO_OUTHI);
528 531
529 if (budget_register(budget) == 0) { 532 if (budget_register(budget) == 0)
530 return 0; 533 return 0; /* Everything OK */
531 } 534
532err: 535 /* An error occurred, cleanup resources */
533 i2c_del_adapter(&budget->i2c_adap); 536 saa7146_vfree_destroy_pgtable(dev->pci, budget->grabbing, &budget->pt);
534 537
535 vfree(budget->grabbing); 538err_del_i2c:
539 i2c_del_adapter(&budget->i2c_adap);
536 540
541err_dvb_unregister:
537 dvb_unregister_adapter(&budget->dvb_adapter); 542 dvb_unregister_adapter(&budget->dvb_adapter);
538 543
539 return ret; 544 return ret;
@@ -555,15 +560,13 @@ int ttpci_budget_deinit(struct budget *budget)
555 560
556 budget_unregister(budget); 561 budget_unregister(budget);
557 562
558 i2c_del_adapter(&budget->i2c_adap);
559
560 dvb_unregister_adapter(&budget->dvb_adapter);
561
562 tasklet_kill(&budget->vpe_tasklet); 563 tasklet_kill(&budget->vpe_tasklet);
563 564
564 saa7146_pgtable_free(dev->pci, &budget->pt); 565 saa7146_vfree_destroy_pgtable(dev->pci, budget->grabbing, &budget->pt);
565 566
566 vfree(budget->grabbing); 567 i2c_del_adapter(&budget->i2c_adap);
568
569 dvb_unregister_adapter(&budget->dvb_adapter);
567 570
568 return 0; 571 return 0;
569} 572}
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index af66a5d5ecd8..a6ac82a609d4 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -2,8 +2,14 @@
2# Multimedia Video device configuration 2# Multimedia Video device configuration
3# 3#
4 4
5menu "Radio Adapters" 5menuconfig RADIO_ADAPTERS
6 bool "Radio Adapters"
6 depends on VIDEO_DEV 7 depends on VIDEO_DEV
8 default y
9 ---help---
10 Say Y here to enable selecting AM/FM radio adapters.
11
12if RADIO_ADAPTERS
7 13
8config RADIO_CADET 14config RADIO_CADET
9 tristate "ADS Cadet AM/FM Tuner" 15 tristate "ADS Cadet AM/FM Tuner"
@@ -328,4 +334,5 @@ config USB_DSBR
328 334
329 To compile this driver as a module, choose M here: the 335 To compile this driver as a module, choose M here: the
330 module will be called dsbr100. 336 module will be called dsbr100.
331endmenu 337
338endif # RADIO_ADAPTERS
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c
index df8d0520d1d1..3bd07f7e3774 100644
--- a/drivers/media/radio/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
@@ -33,6 +33,10 @@
33 33
34 History: 34 History:
35 35
36 Version 0.42:
37 Converted dsbr100 to use video_ioctl2
38 by Douglas Landgraf <dougsland@gmail.com>
39
36 Version 0.41-ac1: 40 Version 0.41-ac1:
37 Alan Cox: Some cleanups and fixes 41 Alan Cox: Some cleanups and fixes
38 42
@@ -79,7 +83,6 @@
79#include <linux/videodev2.h> 83#include <linux/videodev2.h>
80#include <media/v4l2-common.h> 84#include <media/v4l2-common.h>
81#include <linux/usb.h> 85#include <linux/usb.h>
82#include <linux/smp_lock.h>
83 86
84/* 87/*
85 * Version Information 88 * Version Information
@@ -122,8 +125,6 @@ devices, that would be 76 and 91. */
122static int usb_dsbr100_probe(struct usb_interface *intf, 125static int usb_dsbr100_probe(struct usb_interface *intf,
123 const struct usb_device_id *id); 126 const struct usb_device_id *id);
124static void usb_dsbr100_disconnect(struct usb_interface *intf); 127static void usb_dsbr100_disconnect(struct usb_interface *intf);
125static int usb_dsbr100_ioctl(struct inode *inode, struct file *file,
126 unsigned int cmd, unsigned long arg);
127static int usb_dsbr100_open(struct inode *inode, struct file *file); 128static int usb_dsbr100_open(struct inode *inode, struct file *file);
128static int usb_dsbr100_close(struct inode *inode, struct file *file); 129static int usb_dsbr100_close(struct inode *inode, struct file *file);
129 130
@@ -143,26 +144,6 @@ struct dsbr100_device {
143}; 144};
144 145
145 146
146/* File system interface */
147static const struct file_operations usb_dsbr100_fops = {
148 .owner = THIS_MODULE,
149 .open = usb_dsbr100_open,
150 .release = usb_dsbr100_close,
151 .ioctl = usb_dsbr100_ioctl,
152 .compat_ioctl = v4l_compat_ioctl32,
153 .llseek = no_llseek,
154};
155
156/* V4L interface */
157static struct video_device dsbr100_videodev_template=
158{
159 .owner = THIS_MODULE,
160 .name = "D-Link DSB-R 100",
161 .type = VID_TYPE_TUNER,
162 .fops = &usb_dsbr100_fops,
163 .release = video_device_release,
164};
165
166static struct usb_device_id usb_dsbr100_device_table [] = { 147static struct usb_device_id usb_dsbr100_device_table [] = {
167 { USB_DEVICE(DSB100_VENDOR, DSB100_PRODUCT) }, 148 { USB_DEVICE(DSB100_VENDOR, DSB100_PRODUCT) },
168 { } /* Terminating entry */ 149 { } /* Terminating entry */
@@ -253,37 +234,6 @@ static void dsbr100_getstat(struct dsbr100_device *radio)
253 234
254/* USB subsystem interface begins here */ 235/* USB subsystem interface begins here */
255 236
256/* check if the device is present and register with v4l and
257usb if it is */
258static int usb_dsbr100_probe(struct usb_interface *intf,
259 const struct usb_device_id *id)
260{
261 struct dsbr100_device *radio;
262
263 if (!(radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL)))
264 return -ENOMEM;
265 if (!(radio->videodev = video_device_alloc())) {
266 kfree(radio);
267 return -ENOMEM;
268 }
269 memcpy(radio->videodev, &dsbr100_videodev_template,
270 sizeof(dsbr100_videodev_template));
271 radio->removed = 0;
272 radio->users = 0;
273 radio->usbdev = interface_to_usbdev(intf);
274 radio->curfreq = FREQ_MIN*FREQ_MUL;
275 video_set_drvdata(radio->videodev, radio);
276 if (video_register_device(radio->videodev, VFL_TYPE_RADIO,
277 radio_nr)) {
278 warn("Could not register video device");
279 video_device_release(radio->videodev);
280 kfree(radio);
281 return -EIO;
282 }
283 usb_set_intfdata(intf, radio);
284 return 0;
285}
286
287/* handle unplugging of the device, release data structures 237/* handle unplugging of the device, release data structures
288if nothing keeps us from doing it. If something is still 238if nothing keeps us from doing it. If something is still
289keeping us busy, the release callback of v4l will take care 239keeping us busy, the release callback of v4l will take care
@@ -308,133 +258,147 @@ static void usb_dsbr100_disconnect(struct usb_interface *intf)
308} 258}
309 259
310 260
311/* Video for Linux interface */ 261static int vidioc_querycap(struct file *file, void *priv,
262 struct v4l2_capability *v)
263{
264 strlcpy(v->driver, "dsbr100", sizeof(v->driver));
265 strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof(v->card));
266 sprintf(v->bus_info, "ISA");
267 v->version = RADIO_VERSION;
268 v->capabilities = V4L2_CAP_TUNER;
269 return 0;
270}
312 271
313static int usb_dsbr100_do_ioctl(struct inode *inode, struct file *file, 272static int vidioc_g_tuner(struct file *file, void *priv,
314 unsigned int cmd, void *arg) 273 struct v4l2_tuner *v)
315{ 274{
316 struct dsbr100_device *radio=video_get_drvdata(video_devdata(file)); 275 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
276
277 if (v->index > 0)
278 return -EINVAL;
279
280 dsbr100_getstat(radio);
281 strcpy(v->name, "FM");
282 v->type = V4L2_TUNER_RADIO;
283 v->rangelow = FREQ_MIN*FREQ_MUL;
284 v->rangehigh = FREQ_MAX*FREQ_MUL;
285 v->rxsubchans = V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
286 v->capability = V4L2_TUNER_CAP_LOW;
287 if(radio->stereo)
288 v->audmode = V4L2_TUNER_MODE_STEREO;
289 else
290 v->audmode = V4L2_TUNER_MODE_MONO;
291 v->signal = 0xffff; /* We can't get the signal strength */
292 return 0;
293}
317 294
318 if (!radio) 295static int vidioc_s_tuner(struct file *file, void *priv,
319 return -EIO; 296 struct v4l2_tuner *v)
297{
298 if (v->index > 0)
299 return -EINVAL;
320 300
321 switch(cmd) { 301 return 0;
322 case VIDIOC_QUERYCAP: 302}
323 {
324 struct v4l2_capability *v = arg;
325 memset(v,0,sizeof(*v));
326 strlcpy(v->driver, "dsbr100", sizeof (v->driver));
327 strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof (v->card));
328 sprintf(v->bus_info,"ISA");
329 v->version = RADIO_VERSION;
330 v->capabilities = V4L2_CAP_TUNER;
331 303
332 return 0; 304static int vidioc_s_frequency(struct file *file, void *priv,
333 } 305 struct v4l2_frequency *f)
334 case VIDIOC_G_TUNER: 306{
335 { 307 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
336 struct v4l2_tuner *v = arg;
337 308
338 if (v->index > 0) 309 radio->curfreq = f->frequency;
339 return -EINVAL; 310 if (dsbr100_setfreq(radio, radio->curfreq)==-1)
311 warn("Set frequency failed");
312 return 0;
313}
340 314
341 dsbr100_getstat(radio); 315static int vidioc_g_frequency(struct file *file, void *priv,
316 struct v4l2_frequency *f)
317{
318 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
342 319
343 memset(v,0,sizeof(*v)); 320 f->type = V4L2_TUNER_RADIO;
344 strcpy(v->name, "FM"); 321 f->frequency = radio->curfreq;
345 v->type = V4L2_TUNER_RADIO; 322 return 0;
323}
346 324
347 v->rangelow = FREQ_MIN*FREQ_MUL; 325static int vidioc_queryctrl(struct file *file, void *priv,
348 v->rangehigh = FREQ_MAX*FREQ_MUL; 326 struct v4l2_queryctrl *qc)
349 v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO; 327{
350 v->capability=V4L2_TUNER_CAP_LOW; 328 int i;
351 if(radio->stereo)
352 v->audmode = V4L2_TUNER_MODE_STEREO;
353 else
354 v->audmode = V4L2_TUNER_MODE_MONO;
355 v->signal = 0xFFFF; /* We can't get the signal strength */
356 329
330 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
331 if (qc->id && qc->id == radio_qctrl[i].id) {
332 memcpy(qc, &(radio_qctrl[i]),
333 sizeof(*qc));
357 return 0; 334 return 0;
358 } 335 }
359 case VIDIOC_S_TUNER: 336 }
360 { 337 return -EINVAL;
361 struct v4l2_tuner *v = arg; 338}
362
363 if (v->index > 0)
364 return -EINVAL;
365 339
366 return 0; 340static int vidioc_g_ctrl(struct file *file, void *priv,
367 } 341 struct v4l2_control *ctrl)
368 case VIDIOC_S_FREQUENCY: 342{
369 { 343 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
370 struct v4l2_frequency *f = arg;
371 344
372 radio->curfreq = f->frequency; 345 switch (ctrl->id) {
373 if (dsbr100_setfreq(radio, radio->curfreq)==-1) 346 case V4L2_CID_AUDIO_MUTE:
374 warn("Set frequency failed"); 347 ctrl->value = radio->muted;
375 return 0; 348 return 0;
376 } 349 }
377 case VIDIOC_G_FREQUENCY: 350 return -EINVAL;
378 { 351}
379 struct v4l2_frequency *f = arg;
380 352
381 f->type = V4L2_TUNER_RADIO; 353static int vidioc_s_ctrl(struct file *file, void *priv,
382 f->frequency = radio->curfreq; 354 struct v4l2_control *ctrl)
355{
356 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
383 357
384 return 0; 358 switch (ctrl->id) {
385 } 359 case V4L2_CID_AUDIO_MUTE:
386 case VIDIOC_QUERYCTRL: 360 if (ctrl->value) {
387 { 361 if (dsbr100_stop(radio)==-1)
388 struct v4l2_queryctrl *qc = arg; 362 warn("Radio did not respond properly");
389 int i; 363 } else {
390 364 if (dsbr100_start(radio)==-1)
391 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 365 warn("Radio did not respond properly");
392 if (qc->id && qc->id == radio_qctrl[i].id) {
393 memcpy(qc, &(radio_qctrl[i]),
394 sizeof(*qc));
395 return 0;
396 }
397 }
398 return -EINVAL;
399 }
400 case VIDIOC_G_CTRL:
401 {
402 struct v4l2_control *ctrl= arg;
403
404 switch (ctrl->id) {
405 case V4L2_CID_AUDIO_MUTE:
406 ctrl->value=radio->muted;
407 return 0;
408 }
409 return -EINVAL;
410 }
411 case VIDIOC_S_CTRL:
412 {
413 struct v4l2_control *ctrl= arg;
414
415 switch (ctrl->id) {
416 case V4L2_CID_AUDIO_MUTE:
417 if (ctrl->value) {
418 if (dsbr100_stop(radio)==-1)
419 warn("Radio did not respond properly");
420 } else {
421 if (dsbr100_start(radio)==-1)
422 warn("Radio did not respond properly");
423 }
424 return 0;
425 }
426 return -EINVAL;
427 } 366 }
428 default: 367 return 0;
429 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
430 usb_dsbr100_do_ioctl);
431 } 368 }
369 return -EINVAL;
432} 370}
433 371
434static int usb_dsbr100_ioctl(struct inode *inode, struct file *file, 372static int vidioc_g_audio(struct file *file, void *priv,
435 unsigned int cmd, unsigned long arg) 373 struct v4l2_audio *a)
436{ 374{
437 return video_usercopy(inode, file, cmd, arg, usb_dsbr100_do_ioctl); 375 if (a->index > 1)
376 return -EINVAL;
377
378 strcpy(a->name, "Radio");
379 a->capability = V4L2_AUDCAP_STEREO;
380 return 0;
381}
382
383static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
384{
385 *i = 0;
386 return 0;
387}
388
389static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
390{
391 if (i != 0)
392 return -EINVAL;
393 return 0;
394}
395
396static int vidioc_s_audio(struct file *file, void *priv,
397 struct v4l2_audio *a)
398{
399 if (a->index != 0)
400 return -EINVAL;
401 return 0;
438} 402}
439 403
440static int usb_dsbr100_open(struct inode *inode, struct file *file) 404static int usb_dsbr100_open(struct inode *inode, struct file *file)
@@ -466,6 +430,68 @@ static int usb_dsbr100_close(struct inode *inode, struct file *file)
466 return 0; 430 return 0;
467} 431}
468 432
433/* File system interface */
434static const struct file_operations usb_dsbr100_fops = {
435 .owner = THIS_MODULE,
436 .open = usb_dsbr100_open,
437 .release = usb_dsbr100_close,
438 .ioctl = video_ioctl2,
439 .compat_ioctl = v4l_compat_ioctl32,
440 .llseek = no_llseek,
441};
442
443/* V4L2 interface */
444static struct video_device dsbr100_videodev_template =
445{
446 .owner = THIS_MODULE,
447 .name = "D-Link DSB-R 100",
448 .type = VID_TYPE_TUNER,
449 .fops = &usb_dsbr100_fops,
450 .release = video_device_release,
451 .vidioc_querycap = vidioc_querycap,
452 .vidioc_g_tuner = vidioc_g_tuner,
453 .vidioc_s_tuner = vidioc_s_tuner,
454 .vidioc_g_frequency = vidioc_g_frequency,
455 .vidioc_s_frequency = vidioc_s_frequency,
456 .vidioc_queryctrl = vidioc_queryctrl,
457 .vidioc_g_ctrl = vidioc_g_ctrl,
458 .vidioc_s_ctrl = vidioc_s_ctrl,
459 .vidioc_g_audio = vidioc_g_audio,
460 .vidioc_s_audio = vidioc_s_audio,
461 .vidioc_g_input = vidioc_g_input,
462 .vidioc_s_input = vidioc_s_input,
463};
464
465/* check if the device is present and register with v4l and
466usb if it is */
467static int usb_dsbr100_probe(struct usb_interface *intf,
468 const struct usb_device_id *id)
469{
470 struct dsbr100_device *radio;
471
472 if (!(radio = kmalloc(sizeof(struct dsbr100_device), GFP_KERNEL)))
473 return -ENOMEM;
474 if (!(radio->videodev = video_device_alloc())) {
475 kfree(radio);
476 return -ENOMEM;
477 }
478 memcpy(radio->videodev, &dsbr100_videodev_template,
479 sizeof(dsbr100_videodev_template));
480 radio->removed = 0;
481 radio->users = 0;
482 radio->usbdev = interface_to_usbdev(intf);
483 radio->curfreq = FREQ_MIN*FREQ_MUL;
484 video_set_drvdata(radio->videodev, radio);
485 if (video_register_device(radio->videodev, VFL_TYPE_RADIO,radio_nr)) {
486 warn("Could not register video device");
487 video_device_release(radio->videodev);
488 kfree(radio);
489 return -EIO;
490 }
491 usb_set_intfdata(intf, radio);
492 return 0;
493}
494
469static int __init dsbr100_init(void) 495static int __init dsbr100_init(void)
470{ 496{
471 int retval = usb_register(&usb_dsbr100_driver); 497 int retval = usb_register(&usb_dsbr100_driver);
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index 8fbf0d8bd278..8cf2e9df5c8a 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -48,6 +48,25 @@
48 48
49#define CADET_VERSION KERNEL_VERSION(0,3,3) 49#define CADET_VERSION KERNEL_VERSION(0,3,3)
50 50
51static struct v4l2_queryctrl radio_qctrl[] = {
52 {
53 .id = V4L2_CID_AUDIO_MUTE,
54 .name = "Mute",
55 .minimum = 0,
56 .maximum = 1,
57 .default_value = 1,
58 .type = V4L2_CTRL_TYPE_BOOLEAN,
59 },{
60 .id = V4L2_CID_AUDIO_VOLUME,
61 .name = "Volume",
62 .minimum = 0,
63 .maximum = 0xff,
64 .step = 1,
65 .default_value = 0xff,
66 .type = V4L2_CTRL_TYPE_INTEGER,
67 }
68};
69
51static int io=-1; /* default to isapnp activation */ 70static int io=-1; /* default to isapnp activation */
52static int radio_nr = -1; 71static int radio_nr = -1;
53static int users=0; 72static int users=0;
@@ -347,135 +366,165 @@ cadet_read(struct file *file, char __user *data, size_t count, loff_t *ppos)
347} 366}
348 367
349 368
369static int vidioc_querycap(struct file *file, void *priv,
370 struct v4l2_capability *v)
371{
372 v->capabilities =
373 V4L2_CAP_TUNER |
374 V4L2_CAP_READWRITE;
375 v->version = CADET_VERSION;
376 strcpy(v->driver, "ADS Cadet");
377 strcpy(v->card, "ADS Cadet");
378 return 0;
379}
350 380
351static int cadet_do_ioctl(struct inode *inode, struct file *file, 381static int vidioc_g_tuner(struct file *file, void *priv,
352 unsigned int cmd, void *arg) 382 struct v4l2_tuner *v)
353{ 383{
354 switch(cmd) 384 v->type = V4L2_TUNER_RADIO;
355 { 385 switch (v->index) {
356 case VIDIOC_QUERYCAP: 386 case 0:
357 { 387 strcpy(v->name, "FM");
358 struct v4l2_capability *cap = arg; 388 v->capability = V4L2_TUNER_CAP_STEREO;
359 memset(cap,0,sizeof(*cap)); 389 v->rangelow = 1400; /* 87.5 MHz */
360 cap->capabilities = 390 v->rangehigh = 1728; /* 108.0 MHz */
361 V4L2_CAP_TUNER | 391 v->rxsubchans=cadet_getstereo();
362 V4L2_CAP_READWRITE; 392 switch (v->rxsubchans){
363 cap->version = CADET_VERSION; 393 case V4L2_TUNER_SUB_MONO:
364 strcpy(cap->driver, "ADS Cadet"); 394 v->audmode = V4L2_TUNER_MODE_MONO;
365 strcpy(cap->card, "ADS Cadet"); 395 break;
366 return 0; 396 case V4L2_TUNER_SUB_STEREO:
397 v->audmode = V4L2_TUNER_MODE_STEREO;
398 break;
399 default: ;
367 } 400 }
368 case VIDIOC_G_TUNER: 401 break;
369 { 402 case 1:
370 struct v4l2_tuner *t = arg; 403 strcpy(v->name, "AM");
371 memset(t,0,sizeof(*t)); 404 v->capability = V4L2_TUNER_CAP_LOW;
372 t->type = V4L2_TUNER_RADIO; 405 v->rangelow = 8320; /* 520 kHz */
373 switch (t->index) 406 v->rangehigh = 26400; /* 1650 kHz */
374 { 407 v->rxsubchans = V4L2_TUNER_SUB_MONO;
375 case 0: strcpy(t->name, "FM"); 408 v->audmode = V4L2_TUNER_MODE_MONO;
376 t->capability = V4L2_TUNER_CAP_STEREO; 409 break;
377 t->rangelow = 1400; /* 87.5 MHz */ 410 default:
378 t->rangehigh = 1728; /* 108.0 MHz */ 411 return -EINVAL;
379 t->rxsubchans=cadet_getstereo(); 412 }
380 switch (t->rxsubchans){ 413 v->signal = sigstrength; /* We might need to modify scaling of this */
381 case V4L2_TUNER_SUB_MONO: 414 return 0;
382 t->audmode = V4L2_TUNER_MODE_MONO; 415}
383 break;
384 case V4L2_TUNER_SUB_STEREO:
385 t->audmode = V4L2_TUNER_MODE_STEREO;
386 break;
387 default: ;
388 }
389 break;
390 case 1: strcpy(t->name, "AM");
391 t->capability = V4L2_TUNER_CAP_LOW;
392 t->rangelow = 8320; /* 520 kHz */
393 t->rangehigh = 26400; /* 1650 kHz */
394 t->rxsubchans = V4L2_TUNER_SUB_MONO;
395 t->audmode = V4L2_TUNER_MODE_MONO;
396 break;
397 default:
398 return -EINVAL;
399 }
400 416
401 t->signal = sigstrength; /* We might need to modify scaling of this */ 417static int vidioc_s_tuner(struct file *file, void *priv,
402 return 0; 418 struct v4l2_tuner *v)
403 } 419{
404 case VIDIOC_S_TUNER: 420 if((v->index != 0)&&(v->index != 1))
405 { 421 return -EINVAL;
406 struct v4l2_tuner *t = arg; 422 curtuner = v->index;
407 if((t->index != 0)&&(t->index != 1)) 423 return 0;
408 return -EINVAL; 424}
409 425
410 curtuner = t->index; 426static int vidioc_g_frequency(struct file *file, void *priv,
411 return 0; 427 struct v4l2_frequency *f)
412 } 428{
413 case VIDIOC_G_FREQUENCY: 429 f->tuner = curtuner;
414 { 430 f->type = V4L2_TUNER_RADIO;
415 struct v4l2_frequency *f = arg; 431 f->frequency = cadet_getfreq();
416 memset(f,0,sizeof(*f)); 432 return 0;
417 f->tuner = curtuner; 433}
418 f->type = V4L2_TUNER_RADIO; 434
419 f->frequency = cadet_getfreq(); 435
420 return 0; 436static int vidioc_s_frequency(struct file *file, void *priv,
421 } 437 struct v4l2_frequency *f)
422 case VIDIOC_S_FREQUENCY: 438{
423 { 439 if (f->type != V4L2_TUNER_RADIO)
424 struct v4l2_frequency *f = arg; 440 return -EINVAL;
425 if (f->type != V4L2_TUNER_RADIO){ 441 if((curtuner==0)&&((f->frequency<1400)||(f->frequency>1728)))
426 return -EINVAL; 442 return -EINVAL;
427 } 443 if((curtuner==1)&&((f->frequency<8320)||(f->frequency>26400)))
428 if((curtuner==0)&&((f->frequency<1400)||(f->frequency>1728))) { 444 return -EINVAL;
429 return -EINVAL; 445 cadet_setfreq(f->frequency);
430 } 446 return 0;
431 if((curtuner==1)&&((f->frequency<8320)||(f->frequency>26400))) { 447}
432 return -EINVAL; 448
433 } 449static int vidioc_queryctrl(struct file *file, void *priv,
434 cadet_setfreq(f->frequency); 450 struct v4l2_queryctrl *qc)
435 return 0; 451{
436 } 452 int i;
437 case VIDIOC_G_CTRL: 453
438 { 454 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
439 struct v4l2_control *c = arg; 455 if (qc->id && qc->id == radio_qctrl[i].id) {
440 switch (c->id){ 456 memcpy(qc, &(radio_qctrl[i]),
441 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */ 457 sizeof(*qc));
442 c->value = (cadet_getvol() == 0);
443 break;
444 case V4L2_CID_AUDIO_VOLUME:
445 c->value = cadet_getvol();
446 break;
447 default:
448 return -EINVAL;
449 }
450 return 0;
451 }
452 case VIDIOC_S_CTRL:
453 {
454 struct v4l2_control *c = arg;
455 switch (c->id){
456 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
457 if (c->value) cadet_setvol(0);
458 else cadet_setvol(0xffff);
459 break;
460 case V4L2_CID_AUDIO_VOLUME:
461 cadet_setvol(c->value);
462 break;
463 default:
464 return -EINVAL;
465 }
466 return 0; 458 return 0;
467 } 459 }
460 }
461 return -EINVAL;
462}
468 463
469 default: 464static int vidioc_g_ctrl(struct file *file, void *priv,
470 return -ENOIOCTLCMD; 465 struct v4l2_control *ctrl)
466{
467 switch (ctrl->id){
468 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
469 ctrl->value = (cadet_getvol() == 0);
470 break;
471 case V4L2_CID_AUDIO_VOLUME:
472 ctrl->value = cadet_getvol();
473 break;
474 default:
475 return -EINVAL;
471 } 476 }
477 return 0;
472} 478}
473 479
474static int 480static int vidioc_s_ctrl(struct file *file, void *priv,
475cadet_ioctl(struct inode *inode, struct file *file, 481 struct v4l2_control *ctrl)
476 unsigned int cmd, unsigned long arg)
477{ 482{
478 return video_usercopy(inode, file, cmd, arg, cadet_do_ioctl); 483 switch (ctrl->id){
484 case V4L2_CID_AUDIO_MUTE: /* TODO: Handle this correctly */
485 if (ctrl->value)
486 cadet_setvol(0);
487 else
488 cadet_setvol(0xffff);
489 break;
490 case V4L2_CID_AUDIO_VOLUME:
491 cadet_setvol(ctrl->value);
492 break;
493 default:
494 return -EINVAL;
495 }
496 return 0;
497}
498
499static int vidioc_g_audio(struct file *file, void *priv,
500 struct v4l2_audio *a)
501{
502 if (a->index > 1)
503 return -EINVAL;
504 strcpy(a->name, "Radio");
505 a->capability = V4L2_AUDCAP_STEREO;
506 return 0;
507}
508
509static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
510{
511 *i = 0;
512 return 0;
513}
514
515static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
516{
517 if (i != 0)
518 return -EINVAL;
519 return 0;
520}
521
522static int vidioc_s_audio(struct file *file, void *priv,
523 struct v4l2_audio *a)
524{
525 if (a->index != 0)
526 return -EINVAL;
527 return 0;
479} 528}
480 529
481static int 530static int
@@ -512,7 +561,7 @@ static const struct file_operations cadet_fops = {
512 .open = cadet_open, 561 .open = cadet_open,
513 .release = cadet_release, 562 .release = cadet_release,
514 .read = cadet_read, 563 .read = cadet_read,
515 .ioctl = cadet_ioctl, 564 .ioctl = video_ioctl2,
516 .poll = cadet_poll, 565 .poll = cadet_poll,
517 .compat_ioctl = v4l_compat_ioctl32, 566 .compat_ioctl = v4l_compat_ioctl32,
518 .llseek = no_llseek, 567 .llseek = no_llseek,
@@ -524,6 +573,18 @@ static struct video_device cadet_radio=
524 .name = "Cadet radio", 573 .name = "Cadet radio",
525 .type = VID_TYPE_TUNER, 574 .type = VID_TYPE_TUNER,
526 .fops = &cadet_fops, 575 .fops = &cadet_fops,
576 .vidioc_querycap = vidioc_querycap,
577 .vidioc_g_tuner = vidioc_g_tuner,
578 .vidioc_s_tuner = vidioc_s_tuner,
579 .vidioc_g_frequency = vidioc_g_frequency,
580 .vidioc_s_frequency = vidioc_s_frequency,
581 .vidioc_queryctrl = vidioc_queryctrl,
582 .vidioc_g_ctrl = vidioc_g_ctrl,
583 .vidioc_s_ctrl = vidioc_s_ctrl,
584 .vidioc_g_audio = vidioc_g_audio,
585 .vidioc_s_audio = vidioc_s_audio,
586 .vidioc_g_input = vidioc_g_input,
587 .vidioc_s_input = vidioc_s_input,
527}; 588};
528 589
529static struct pnp_device_id cadet_pnp_devices[] = { 590static struct pnp_device_id cadet_pnp_devices[] = {
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index 11f80cacd6ed..8e33a19a22a3 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -24,7 +24,6 @@
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <asm/io.h> 25#include <asm/io.h>
26#include <asm/uaccess.h> 26#include <asm/uaccess.h>
27#include <linux/mutex.h>
28#include <linux/pci.h> 27#include <linux/pci.h>
29#include <linux/videodev2.h> 28#include <linux/videodev2.h>
30#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
@@ -110,7 +109,6 @@ struct radio_device {
110 muted, /* VIDEO_AUDIO_MUTE */ 109 muted, /* VIDEO_AUDIO_MUTE */
111 stereo, /* VIDEO_TUNER_STEREO_ON */ 110 stereo, /* VIDEO_TUNER_STEREO_ON */
112 tuned; /* signal strength (0 or 0xffff) */ 111 tuned; /* signal strength (0 or 0xffff) */
113 struct mutex lock;
114}; 112};
115 113
116static u32 radio_bits_get(struct radio_device *dev) 114static u32 radio_bits_get(struct radio_device *dev)
@@ -394,7 +392,6 @@ static int __devinit maestro_probe(struct pci_dev *pdev,
394 } 392 }
395 393
396 radio_unit->io = pci_resource_start(pdev, 0) + GPIO_DATA; 394 radio_unit->io = pci_resource_start(pdev, 0) + GPIO_DATA;
397 mutex_init(&radio_unit->lock);
398 395
399 maestro_radio_inst = video_device_alloc(); 396 maestro_radio_inst = video_device_alloc();
400 if (maestro_radio_inst == NULL) { 397 if (maestro_radio_inst == NULL) {
diff --git a/drivers/media/radio/radio-zoltrix.c b/drivers/media/radio/radio-zoltrix.c
index a4715901512d..203f4373eeb8 100644
--- a/drivers/media/radio/radio-zoltrix.c
+++ b/drivers/media/radio/radio-zoltrix.c
@@ -410,7 +410,6 @@ static struct video_device zoltrix_radio =
410 .owner = THIS_MODULE, 410 .owner = THIS_MODULE,
411 .name = "Zoltrix Radio Plus", 411 .name = "Zoltrix Radio Plus",
412 .type = VID_TYPE_TUNER, 412 .type = VID_TYPE_TUNER,
413 .hardware = 0,
414 .fops = &zoltrix_fops, 413 .fops = &zoltrix_fops,
415 .vidioc_querycap = vidioc_querycap, 414 .vidioc_querycap = vidioc_querycap,
416 .vidioc_g_tuner = vidioc_g_tuner, 415 .vidioc_g_tuner = vidioc_g_tuner,
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index bc773781993a..5cb3f54b548b 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -2,14 +2,19 @@
2# Multimedia Video device configuration 2# Multimedia Video device configuration
3# 3#
4 4
5menu "Video Capture Adapters" 5menuconfig VIDEO_CAPTURE_DRIVERS
6 bool "Video capture adapters"
6 depends on VIDEO_DEV 7 depends on VIDEO_DEV
8 default y
9 ---help---
10 Say Y here to enable selecting the video adapters for
11 webcams, analog TV, and hybrid analog/digital TV.
12 Some of those devices also supports FM radio.
7 13
8comment "Video Capture Adapters" 14if VIDEO_CAPTURE_DRIVERS
9 15
10config VIDEO_ADV_DEBUG 16config VIDEO_ADV_DEBUG
11 bool "Enable advanced debug functionality" 17 bool "Enable advanced debug functionality"
12 depends on VIDEO_DEV
13 default n 18 default n
14 ---help--- 19 ---help---
15 Say Y here to enable advanced debugging functionality on some 20 Say Y here to enable advanced debugging functionality on some
@@ -34,7 +39,7 @@ config VIDEO_HELPER_CHIPS_AUTO
34# 39#
35 40
36menu "Encoders/decoders and other helper chips" 41menu "Encoders/decoders and other helper chips"
37 depends on VIDEO_DEV && !VIDEO_HELPER_CHIPS_AUTO 42 depends on !VIDEO_HELPER_CHIPS_AUTO
38 43
39comment "Audio decoders" 44comment "Audio decoders"
40 45
@@ -61,7 +66,7 @@ config VIDEO_TDA7432
61 66
62config VIDEO_TDA9840 67config VIDEO_TDA9840
63 tristate "Philips TDA9840 audio processor" 68 tristate "Philips TDA9840 audio processor"
64 depends on VIDEO_DEV && I2C 69 depends on I2C
65 ---help--- 70 ---help---
66 Support for tda9840 audio decoder chip found on some Zoran boards. 71 Support for tda9840 audio decoder chip found on some Zoran boards.
67 72
@@ -79,7 +84,7 @@ config VIDEO_TDA9875
79 84
80config VIDEO_TEA6415C 85config VIDEO_TEA6415C
81 tristate "Philips TEA6415C audio processor" 86 tristate "Philips TEA6415C audio processor"
82 depends on VIDEO_DEV && I2C 87 depends on I2C
83 ---help--- 88 ---help---
84 Support for tea6415c audio decoder chip found on some bt8xx boards. 89 Support for tea6415c audio decoder chip found on some bt8xx boards.
85 90
@@ -88,7 +93,7 @@ config VIDEO_TEA6415C
88 93
89config VIDEO_TEA6420 94config VIDEO_TEA6420
90 tristate "Philips TEA6420 audio processor" 95 tristate "Philips TEA6420 audio processor"
91 depends on VIDEO_DEV && I2C 96 depends on I2C
92 ---help--- 97 ---help---
93 Support for tea6420 audio decoder chip found on some bt8xx boards. 98 Support for tea6420 audio decoder chip found on some bt8xx boards.
94 99
@@ -469,7 +474,7 @@ config VIDEO_SAA5246A
469 474
470config VIDEO_SAA5249 475config VIDEO_SAA5249
471 tristate "SAA5249 Teletext processor" 476 tristate "SAA5249 Teletext processor"
472 depends on VIDEO_DEV && I2C && VIDEO_V4L2 477 depends on I2C && VIDEO_V4L2
473 help 478 help
474 Support for I2C bus based teletext using the SAA5249 chip. At the 479 Support for I2C bus based teletext using the SAA5249 chip. At the
475 moment this is only useful on some European WinTV cards. 480 moment this is only useful on some European WinTV cards.
@@ -479,7 +484,7 @@ config VIDEO_SAA5249
479 484
480config TUNER_3036 485config TUNER_3036
481 tristate "SAB3036 tuner" 486 tristate "SAB3036 tuner"
482 depends on VIDEO_DEV && I2C && VIDEO_V4L1 487 depends on I2C && VIDEO_V4L1
483 help 488 help
484 Say Y here to include support for Philips SAB3036 compatible tuners. 489 Say Y here to include support for Philips SAB3036 compatible tuners.
485 If in doubt, say N. 490 If in doubt, say N.
@@ -681,8 +686,12 @@ config VIDEO_CAFE_CCIC
681# USB Multimedia device configuration 686# USB Multimedia device configuration
682# 687#
683 688
684menu "V4L USB devices" 689menuconfig V4L_USB_DRIVERS
685 depends on USB && VIDEO_DEV 690 bool "V4L USB devices"
691 depends on USB
692 default y
693
694if V4L_USB_DRIVERS
686 695
687source "drivers/media/video/pvrusb2/Kconfig" 696source "drivers/media/video/pvrusb2/Kconfig"
688 697
@@ -707,7 +716,7 @@ config VIDEO_OVCAMCHIP
707 716
708config USB_W9968CF 717config USB_W9968CF
709 tristate "USB W996[87]CF JPEG Dual Mode Camera support" 718 tristate "USB W996[87]CF JPEG Dual Mode Camera support"
710 depends on USB && VIDEO_V4L1 && I2C 719 depends on VIDEO_V4L1 && I2C
711 select VIDEO_OVCAMCHIP 720 select VIDEO_OVCAMCHIP
712 ---help--- 721 ---help---
713 Say Y here if you want support for cameras based on OV681 or 722 Say Y here if you want support for cameras based on OV681 or
@@ -725,7 +734,7 @@ config USB_W9968CF
725 734
726config USB_OV511 735config USB_OV511
727 tristate "USB OV511 Camera support" 736 tristate "USB OV511 Camera support"
728 depends on USB && VIDEO_V4L1 737 depends on VIDEO_V4L1
729 ---help--- 738 ---help---
730 Say Y here if you want to connect this type of camera to your 739 Say Y here if you want to connect this type of camera to your
731 computer's USB port. See <file:Documentation/video4linux/ov511.txt> 740 computer's USB port. See <file:Documentation/video4linux/ov511.txt>
@@ -736,7 +745,7 @@ config USB_OV511
736 745
737config USB_SE401 746config USB_SE401
738 tristate "USB SE401 Camera support" 747 tristate "USB SE401 Camera support"
739 depends on USB && VIDEO_V4L1 748 depends on VIDEO_V4L1
740 ---help--- 749 ---help---
741 Say Y here if you want to connect this type of camera to your 750 Say Y here if you want to connect this type of camera to your
742 computer's USB port. See <file:Documentation/video4linux/se401.txt> 751 computer's USB port. See <file:Documentation/video4linux/se401.txt>
@@ -749,7 +758,7 @@ source "drivers/media/video/sn9c102/Kconfig"
749 758
750config USB_STV680 759config USB_STV680
751 tristate "USB STV680 (Pencam) Camera support" 760 tristate "USB STV680 (Pencam) Camera support"
752 depends on USB && VIDEO_V4L1 761 depends on VIDEO_V4L1
753 ---help--- 762 ---help---
754 Say Y here if you want to connect this type of camera to your 763 Say Y here if you want to connect this type of camera to your
755 computer's USB port. This includes the Pencam line of cameras. 764 computer's USB port. This includes the Pencam line of cameras.
@@ -765,7 +774,7 @@ source "drivers/media/video/pwc/Kconfig"
765 774
766config USB_ZR364XX 775config USB_ZR364XX
767 tristate "USB ZR364XX Camera support" 776 tristate "USB ZR364XX Camera support"
768 depends on USB && VIDEO_V4L2 777 depends on VIDEO_V4L2
769 ---help--- 778 ---help---
770 Say Y here if you want to connect this type of camera to your 779 Say Y here if you want to connect this type of camera to your
771 computer's USB port. 780 computer's USB port.
@@ -775,6 +784,6 @@ config USB_ZR364XX
775 To compile this driver as a module, choose M here: the 784 To compile this driver as a module, choose M here: the
776 module will be called zr364xx. 785 module will be called zr364xx.
777 786
778endmenu # V4L USB devices 787endif # V4L_USB_DRIVERS
779 788
780endmenu 789endif # VIDEO_CAPTURE_DRIVERS
diff --git a/drivers/media/video/cafe_ccic-regs.h b/drivers/media/video/cafe_ccic-regs.h
index b2c22a0d6643..8e2a87cdc791 100644
--- a/drivers/media/video/cafe_ccic-regs.h
+++ b/drivers/media/video/cafe_ccic-regs.h
@@ -150,6 +150,12 @@
150#define REG_GL_IMASK 0x300c /* Interrupt mask register */ 150#define REG_GL_IMASK 0x300c /* Interrupt mask register */
151#define GIMSK_CCIC_EN 0x00000004 /* CCIC Interrupt enable */ 151#define GIMSK_CCIC_EN 0x00000004 /* CCIC Interrupt enable */
152 152
153#define REG_GL_FCR 0x3038 /* GPIO functional control register */
154#define GFCR_GPIO_ON 0x08 /* Camera GPIO enabled */
155#define REG_GL_GPIOR 0x315c /* GPIO register */
156#define GGPIO_OUT 0x80000 /* GPIO output */
157#define GGPIO_VAL 0x00008 /* Output pin value */
158
153#define REG_LEN REG_GL_IMASK + 4 159#define REG_LEN REG_GL_IMASK + 4
154 160
155 161
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index 96254dbaf625..c08f650df423 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -775,6 +775,12 @@ static void cafe_ctlr_power_up(struct cafe_camera *cam)
775 spin_lock_irqsave(&cam->dev_lock, flags); 775 spin_lock_irqsave(&cam->dev_lock, flags);
776 cafe_reg_clear_bit(cam, REG_CTRL1, C1_PWRDWN); 776 cafe_reg_clear_bit(cam, REG_CTRL1, C1_PWRDWN);
777 /* 777 /*
778 * Part one of the sensor dance: turn the global
779 * GPIO signal on.
780 */
781 cafe_reg_write(cam, REG_GL_FCR, GFCR_GPIO_ON);
782 cafe_reg_write(cam, REG_GL_GPIOR, GGPIO_OUT|GGPIO_VAL);
783 /*
778 * Put the sensor into operational mode (assumes OLPC-style 784 * Put the sensor into operational mode (assumes OLPC-style
779 * wiring). Control 0 is reset - set to 1 to operate. 785 * wiring). Control 0 is reset - set to 1 to operate.
780 * Control 1 is power down, set to 0 to operate. 786 * Control 1 is power down, set to 0 to operate.
@@ -784,6 +790,7 @@ static void cafe_ctlr_power_up(struct cafe_camera *cam)
784 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0); 790 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C0);
785// mdelay(1); /* Enough? */ 791// mdelay(1); /* Enough? */
786 spin_unlock_irqrestore(&cam->dev_lock, flags); 792 spin_unlock_irqrestore(&cam->dev_lock, flags);
793 msleep(5); /* Just to be sure */
787} 794}
788 795
789static void cafe_ctlr_power_down(struct cafe_camera *cam) 796static void cafe_ctlr_power_down(struct cafe_camera *cam)
@@ -792,6 +799,8 @@ static void cafe_ctlr_power_down(struct cafe_camera *cam)
792 799
793 spin_lock_irqsave(&cam->dev_lock, flags); 800 spin_lock_irqsave(&cam->dev_lock, flags);
794 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C1); 801 cafe_reg_write(cam, REG_GPR, GPR_C1EN|GPR_C0EN|GPR_C1);
802 cafe_reg_write(cam, REG_GL_FCR, GFCR_GPIO_ON);
803 cafe_reg_write(cam, REG_GL_GPIOR, GGPIO_OUT);
795 cafe_reg_set_bit(cam, REG_CTRL1, C1_PWRDWN); 804 cafe_reg_set_bit(cam, REG_CTRL1, C1_PWRDWN);
796 spin_unlock_irqrestore(&cam->dev_lock, flags); 805 spin_unlock_irqrestore(&cam->dev_lock, flags);
797} 806}
@@ -851,6 +860,7 @@ static int cafe_cam_init(struct cafe_camera *cam)
851 ret = 0; 860 ret = 0;
852 cam->state = S_IDLE; 861 cam->state = S_IDLE;
853 out: 862 out:
863 cafe_ctlr_power_down(cam);
854 mutex_unlock(&cam->s_mutex); 864 mutex_unlock(&cam->s_mutex);
855 return ret; 865 return ret;
856} 866}
@@ -2103,10 +2113,16 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2103 ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam); 2113 ret = request_irq(pdev->irq, cafe_irq, IRQF_SHARED, "cafe-ccic", cam);
2104 if (ret) 2114 if (ret)
2105 goto out_iounmap; 2115 goto out_iounmap;
2116 /*
2117 * Initialize the controller and leave it powered up. It will
2118 * stay that way until the sensor driver shows up.
2119 */
2106 cafe_ctlr_init(cam); 2120 cafe_ctlr_init(cam);
2107 cafe_ctlr_power_up(cam); 2121 cafe_ctlr_power_up(cam);
2108 /* 2122 /*
2109 * Set up I2C/SMBUS communications 2123 * Set up I2C/SMBUS communications. We have to drop the mutex here
2124 * because the sensor could attach in this call chain, leading to
2125 * unsightly deadlocks.
2110 */ 2126 */
2111 mutex_unlock(&cam->s_mutex); /* attach can deadlock */ 2127 mutex_unlock(&cam->s_mutex); /* attach can deadlock */
2112 ret = cafe_smbus_setup(cam); 2128 ret = cafe_smbus_setup(cam);
diff --git a/drivers/media/video/cpia.h b/drivers/media/video/cpia.h
index 6eaa692021c5..78392fb6f94e 100644
--- a/drivers/media/video/cpia.h
+++ b/drivers/media/video/cpia.h
@@ -47,7 +47,6 @@
47#include <linux/videodev.h> 47#include <linux/videodev.h>
48#include <media/v4l2-common.h> 48#include <media/v4l2-common.h>
49#include <linux/list.h> 49#include <linux/list.h>
50#include <linux/smp_lock.h>
51#include <linux/mutex.h> 50#include <linux/mutex.h>
52 51
53struct cpia_camera_ops 52struct cpia_camera_ops
diff --git a/drivers/media/video/cpia_pp.c b/drivers/media/video/cpia_pp.c
index 19711aaf9a3e..c431df8248d6 100644
--- a/drivers/media/video/cpia_pp.c
+++ b/drivers/media/video/cpia_pp.c
@@ -34,7 +34,6 @@
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/workqueue.h> 36#include <linux/workqueue.h>
37#include <linux/smp_lock.h>
38#include <linux/sched.h> 37#include <linux/sched.h>
39 38
40#include <linux/kmod.h> 39#include <linux/kmod.h>
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 1757a588970f..67bda9f9a44b 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -555,7 +555,7 @@ static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
555{ 555{
556 struct v4l2_pix_format *pix; 556 struct v4l2_pix_format *pix;
557 int HSC, VSC, Vsrc, Hsrc, filter, Vlines; 557 int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
558 int is_pal = !(cx25840_get_v4lstd(client) & V4L2_STD_NTSC); 558 int is_50Hz = !(cx25840_get_v4lstd(client) & V4L2_STD_525_60);
559 559
560 switch (fmt->type) { 560 switch (fmt->type) {
561 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 561 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
@@ -567,7 +567,7 @@ static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
567 Hsrc = (cx25840_read(client, 0x472) & 0x3f) << 4; 567 Hsrc = (cx25840_read(client, 0x472) & 0x3f) << 4;
568 Hsrc |= (cx25840_read(client, 0x471) & 0xf0) >> 4; 568 Hsrc |= (cx25840_read(client, 0x471) & 0xf0) >> 4;
569 569
570 Vlines = pix->height + (is_pal ? 4 : 7); 570 Vlines = pix->height + (is_50Hz ? 4 : 7);
571 571
572 if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) || 572 if ((pix->width * 16 < Hsrc) || (Hsrc < pix->width) ||
573 (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) { 573 (Vlines * 8 < Vsrc) || (Vsrc < Vlines)) {
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index 2ebde2fdbcbe..543b05ebc0e7 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -28,6 +28,7 @@
28#include <linux/device.h> 28#include <linux/device.h>
29#include <linux/dma-mapping.h> 29#include <linux/dma-mapping.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/dma-mapping.h>
31#include <asm/delay.h> 32#include <asm/delay.h>
32 33
33#include "cx88.h" 34#include "cx88.h"
@@ -612,7 +613,7 @@ struct cx8802_driver * cx8802_get_driver(struct cx8802_dev *dev, enum cx88_board
612} 613}
613 614
614/* Driver asked for hardware access. */ 615/* Driver asked for hardware access. */
615int cx8802_request_acquire(struct cx8802_driver *drv) 616static int cx8802_request_acquire(struct cx8802_driver *drv)
616{ 617{
617 struct cx88_core *core = drv->core; 618 struct cx88_core *core = drv->core;
618 619
@@ -632,7 +633,7 @@ int cx8802_request_acquire(struct cx8802_driver *drv)
632} 633}
633 634
634/* Driver asked to release hardware. */ 635/* Driver asked to release hardware. */
635int cx8802_request_release(struct cx8802_driver *drv) 636static int cx8802_request_release(struct cx8802_driver *drv)
636{ 637{
637 struct cx88_core *core = drv->core; 638 struct cx88_core *core = drv->core;
638 639
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index e627062fde3a..259ea08e784f 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -49,7 +49,6 @@
49#include <linux/interrupt.h> 49#include <linux/interrupt.h>
50#include <linux/vmalloc.h> 50#include <linux/vmalloc.h>
51#include <linux/init.h> 51#include <linux/init.h>
52#include <linux/smp_lock.h>
53#include <linux/delay.h> 52#include <linux/delay.h>
54#include <linux/kthread.h> 53#include <linux/kthread.h>
55 54
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index b94ef8ab28c1..98fa35421bdd 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -36,6 +36,7 @@
36#include <linux/dma-mapping.h> 36#include <linux/dma-mapping.h>
37#include <linux/delay.h> 37#include <linux/delay.h>
38#include <linux/kthread.h> 38#include <linux/kthread.h>
39#include <linux/dma-mapping.h>
39#include <asm/div64.h> 40#include <asm/div64.h>
40 41
41#include "cx88.h" 42#include "cx88.h"
diff --git a/drivers/media/video/cx88/cx88-vp3054-i2c.c b/drivers/media/video/cx88/cx88-vp3054-i2c.c
index 6068c9bf82cd..82bc3a28aa22 100644
--- a/drivers/media/video/cx88/cx88-vp3054-i2c.c
+++ b/drivers/media/video/cx88/cx88-vp3054-i2c.c
@@ -111,10 +111,6 @@ static struct i2c_adapter vp3054_i2c_adap_template = {
111 .id = I2C_HW_B_CX2388x, 111 .id = I2C_HW_B_CX2388x,
112}; 112};
113 113
114static struct i2c_client vp3054_i2c_client_template = {
115 .name = "VP-3054",
116};
117
118int vp3054_i2c_probe(struct cx8802_dev *dev) 114int vp3054_i2c_probe(struct cx8802_dev *dev)
119{ 115{
120 struct cx88_core *core = dev->core; 116 struct cx88_core *core = dev->core;
@@ -133,8 +129,6 @@ int vp3054_i2c_probe(struct cx8802_dev *dev)
133 sizeof(vp3054_i2c->adap)); 129 sizeof(vp3054_i2c->adap));
134 memcpy(&vp3054_i2c->algo, &vp3054_i2c_algo_template, 130 memcpy(&vp3054_i2c->algo, &vp3054_i2c_algo_template,
135 sizeof(vp3054_i2c->algo)); 131 sizeof(vp3054_i2c->algo));
136 memcpy(&vp3054_i2c->client, &vp3054_i2c_client_template,
137 sizeof(vp3054_i2c->client));
138 132
139 vp3054_i2c->adap.class |= I2C_CLASS_TV_DIGITAL; 133 vp3054_i2c->adap.class |= I2C_CLASS_TV_DIGITAL;
140 134
@@ -144,7 +138,6 @@ int vp3054_i2c_probe(struct cx8802_dev *dev)
144 vp3054_i2c->algo.data = dev; 138 vp3054_i2c->algo.data = dev;
145 i2c_set_adapdata(&vp3054_i2c->adap, dev); 139 i2c_set_adapdata(&vp3054_i2c->adap, dev);
146 vp3054_i2c->adap.algo_data = &vp3054_i2c->algo; 140 vp3054_i2c->adap.algo_data = &vp3054_i2c->algo;
147 vp3054_i2c->client.adapter = &vp3054_i2c->adap;
148 141
149 vp3054_bit_setscl(dev,1); 142 vp3054_bit_setscl(dev,1);
150 vp3054_bit_setsda(dev,1); 143 vp3054_bit_setsda(dev,1);
diff --git a/drivers/media/video/cx88/cx88-vp3054-i2c.h b/drivers/media/video/cx88/cx88-vp3054-i2c.h
index b7a0a04d2423..637a7d232238 100644
--- a/drivers/media/video/cx88/cx88-vp3054-i2c.h
+++ b/drivers/media/video/cx88/cx88-vp3054-i2c.h
@@ -26,7 +26,6 @@
26struct vp3054_i2c_state { 26struct vp3054_i2c_state {
27 struct i2c_adapter adap; 27 struct i2c_adapter adap;
28 struct i2c_algo_bit_data algo; 28 struct i2c_algo_bit_data algo;
29 struct i2c_client client;
30 u32 state; 29 u32 state;
31}; 30};
32 31
diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c
index ff4b238090ac..a5731f90be0f 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -37,7 +37,6 @@
37#include <asm/atomic.h> 37#include <asm/atomic.h>
38#include <linux/delay.h> 38#include <linux/delay.h>
39#include <linux/usb.h> 39#include <linux/usb.h>
40#include <linux/smp_lock.h>
41#include <linux/mutex.h> 40#include <linux/mutex.h>
42 41
43#include "dabusb.h" 42#include "dabusb.h"
diff --git a/drivers/media/video/em28xx/Kconfig b/drivers/media/video/em28xx/Kconfig
index 9285a58e47aa..5b6a40371602 100644
--- a/drivers/media/video/em28xx/Kconfig
+++ b/drivers/media/video/em28xx/Kconfig
@@ -1,7 +1,6 @@
1config VIDEO_EM28XX 1config VIDEO_EM28XX
2 tristate "Empia EM2800/2820/2840 USB video capture support" 2 tristate "Empia EM2800/2820/2840 USB video capture support"
3 depends on VIDEO_V4L1 && USB && I2C 3 depends on VIDEO_V4L1 && I2C
4 select VIDEO_BUF
5 select VIDEO_TUNER 4 select VIDEO_TUNER
6 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
7 select VIDEO_IR 6 select VIDEO_IR
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index 563a8319e608..54ccc6e1f92e 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -70,7 +70,7 @@ static int em2800_i2c_send_max4(struct em28xx *dev, unsigned char addr,
70 70
71 ret = dev->em28xx_write_regs(dev, 4 - len, &b2[4 - len], 2 + len); 71 ret = dev->em28xx_write_regs(dev, 4 - len, &b2[4 - len], 2 + len);
72 if (ret != 2 + len) { 72 if (ret != 2 + len) {
73 em28xx_warn("writting to i2c device failed (error=%i)\n", ret); 73 em28xx_warn("writing to i2c device failed (error=%i)\n", ret);
74 return -EIO; 74 return -EIO;
75 } 75 }
76 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0; 76 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0;
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index bec67609500f..2c7b158ce7e1 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -1729,7 +1729,7 @@ static int em28xx_usb_probe(struct usb_interface *interface,
1729 1729
1730 endpoint = &interface->cur_altsetting->endpoint[1].desc; 1730 endpoint = &interface->cur_altsetting->endpoint[1].desc;
1731 1731
1732 /* check if the the device has the iso in endpoint at the correct place */ 1732 /* check if the device has the iso in endpoint at the correct place */
1733 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 1733 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
1734 USB_ENDPOINT_XFER_ISOC) { 1734 USB_ENDPOINT_XFER_ISOC) {
1735 em28xx_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n"); 1735 em28xx_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n");
diff --git a/drivers/media/video/et61x251/Kconfig b/drivers/media/video/et61x251/Kconfig
index c6bff705688d..664676f44068 100644
--- a/drivers/media/video/et61x251/Kconfig
+++ b/drivers/media/video/et61x251/Kconfig
@@ -1,6 +1,6 @@
1config USB_ET61X251 1config USB_ET61X251
2 tristate "USB ET61X[12]51 PC Camera Controller support" 2 tristate "USB ET61X[12]51 PC Camera Controller support"
3 depends on USB && VIDEO_V4L1 3 depends on VIDEO_V4L1
4 ---help--- 4 ---help---
5 Say Y here if you want support for cameras based on Etoms ET61X151 5 Say Y here if you want support for cameras based on Etoms ET61X151
6 or ET61X251 PC Camera Controllers. 6 or ET61X251 PC Camera Controllers.
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index e854f3f1b70f..1aaeaa02f158 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_IVTV 1config VIDEO_IVTV
2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support" 2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support"
3 depends on VIDEO_V4L1 && VIDEO_V4L2 && USB && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L1 && VIDEO_V4L2 && PCI && I2C && EXPERIMENTAL
4 select FW_LOADER 4 select FW_LOADER
5 select VIDEO_TUNER 5 select VIDEO_TUNER
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 45b9328a538f..e29f949adf57 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -74,7 +74,7 @@ int ivtv_first_minor = 0;
74struct ivtv *ivtv_cards[IVTV_MAX_CARDS]; 74struct ivtv *ivtv_cards[IVTV_MAX_CARDS];
75 75
76/* Protects ivtv_cards_active */ 76/* Protects ivtv_cards_active */
77spinlock_t ivtv_cards_lock = SPIN_LOCK_UNLOCKED; 77DEFINE_SPINLOCK(ivtv_cards_lock);
78 78
79/* add your revision and whatnot here */ 79/* add your revision and whatnot here */
80static struct pci_device_id ivtv_pci_tbl[] __devinitdata = { 80static struct pci_device_id ivtv_pci_tbl[] __devinitdata = {
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 9a412d6c6d06..552f04511ead 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -67,14 +67,6 @@
67 67
68#include <media/ivtv.h> 68#include <media/ivtv.h>
69 69
70#ifdef CONFIG_LIRC_I2C
71# error "This driver is not compatible with the LIRC I2C kernel configuration option."
72#endif /* CONFIG_LIRC_I2C */
73
74#ifndef CONFIG_PCI
75# error "This driver requires kernel PCI support."
76#endif /* CONFIG_PCI */
77
78#define IVTV_ENCODER_OFFSET 0x00000000 70#define IVTV_ENCODER_OFFSET 0x00000000
79#define IVTV_ENCODER_SIZE 0x00800000 /* Last half isn't needed 0x01000000 */ 71#define IVTV_ENCODER_SIZE 0x00800000 /* Last half isn't needed 0x01000000 */
80 72
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index 1637097ddec7..8976487a65f3 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -804,7 +804,7 @@ int ivtv_v4l2_open(struct inode *inode, struct file *filp)
804 struct ivtv_open_id *item; 804 struct ivtv_open_id *item;
805 struct ivtv *itv = NULL; 805 struct ivtv *itv = NULL;
806 struct ivtv_stream *s = NULL; 806 struct ivtv_stream *s = NULL;
807 int minor = MINOR(inode->i_rdev); 807 int minor = iminor(inode);
808 808
809 /* Find which card this open was on */ 809 /* Find which card this open was on */
810 spin_lock(&ivtv_cards_lock); 810 spin_lock(&ivtv_cards_lock);
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index 794a6a02f82f..1989ec1cb973 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -362,8 +362,6 @@ static int ivtv_get_fmt(struct ivtv *itv, int streamtype, struct v4l2_format *fm
362 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 362 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
363 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) 363 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
364 return -EINVAL; 364 return -EINVAL;
365 fmt->fmt.pix.left = itv->main_rect.left;
366 fmt->fmt.pix.top = itv->main_rect.top;
367 fmt->fmt.pix.width = itv->main_rect.width; 365 fmt->fmt.pix.width = itv->main_rect.width;
368 fmt->fmt.pix.height = itv->main_rect.height; 366 fmt->fmt.pix.height = itv->main_rect.height;
369 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 367 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
@@ -402,8 +400,6 @@ static int ivtv_get_fmt(struct ivtv *itv, int streamtype, struct v4l2_format *fm
402 break; 400 break;
403 401
404 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 402 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
405 fmt->fmt.pix.left = 0;
406 fmt->fmt.pix.top = 0;
407 fmt->fmt.pix.width = itv->params.width; 403 fmt->fmt.pix.width = itv->params.width;
408 fmt->fmt.pix.height = itv->params.height; 404 fmt->fmt.pix.height = itv->params.height;
409 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 405 fmt->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
@@ -498,15 +494,13 @@ static int ivtv_try_or_set_fmt(struct ivtv *itv, int streamtype,
498 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) 494 if (!(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
499 return -EINVAL; 495 return -EINVAL;
500 field = fmt->fmt.pix.field; 496 field = fmt->fmt.pix.field;
501 r.top = fmt->fmt.pix.top; 497 r.top = 0;
502 r.left = fmt->fmt.pix.left; 498 r.left = 0;
503 r.width = fmt->fmt.pix.width; 499 r.width = fmt->fmt.pix.width;
504 r.height = fmt->fmt.pix.height; 500 r.height = fmt->fmt.pix.height;
505 ivtv_get_fmt(itv, streamtype, fmt); 501 ivtv_get_fmt(itv, streamtype, fmt);
506 if (itv->output_mode != OUT_UDMA_YUV) { 502 if (itv->output_mode != OUT_UDMA_YUV) {
507 /* TODO: would setting the rect also be valid for this mode? */ 503 /* TODO: would setting the rect also be valid for this mode? */
508 fmt->fmt.pix.top = r.top;
509 fmt->fmt.pix.left = r.left;
510 fmt->fmt.pix.width = r.width; 504 fmt->fmt.pix.width = r.width;
511 fmt->fmt.pix.height = r.height; 505 fmt->fmt.pix.height = r.height;
512 } 506 }
@@ -1141,8 +1135,6 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1141 fb->fmt.pixelformat = itv->osd_pixelformat; 1135 fb->fmt.pixelformat = itv->osd_pixelformat;
1142 fb->fmt.width = itv->osd_rect.width; 1136 fb->fmt.width = itv->osd_rect.width;
1143 fb->fmt.height = itv->osd_rect.height; 1137 fb->fmt.height = itv->osd_rect.height;
1144 fb->fmt.left = itv->osd_rect.left;
1145 fb->fmt.top = itv->osd_rect.top;
1146 fb->base = (void *)itv->osd_video_pbase; 1138 fb->base = (void *)itv->osd_video_pbase;
1147 if (itv->osd_global_alpha_state) 1139 if (itv->osd_global_alpha_state)
1148 fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA; 1140 fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
diff --git a/drivers/media/video/ov511.h b/drivers/media/video/ov511.h
index 68b082bcee1d..18c64222dd11 100644
--- a/drivers/media/video/ov511.h
+++ b/drivers/media/video/ov511.h
@@ -4,7 +4,6 @@
4#include <asm/uaccess.h> 4#include <asm/uaccess.h>
5#include <linux/videodev.h> 5#include <linux/videodev.h>
6#include <media/v4l2-common.h> 6#include <media/v4l2-common.h>
7#include <linux/smp_lock.h>
8#include <linux/usb.h> 7#include <linux/usb.h>
9#include <linux/mutex.h> 8#include <linux/mutex.h>
10 9
diff --git a/drivers/media/video/ov7670.c b/drivers/media/video/ov7670.c
index 03bc369a9e49..3ceb8a6249dd 100644
--- a/drivers/media/video/ov7670.c
+++ b/drivers/media/video/ov7670.c
@@ -720,12 +720,22 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt)
720 struct ov7670_format_struct *ovfmt; 720 struct ov7670_format_struct *ovfmt;
721 struct ov7670_win_size *wsize; 721 struct ov7670_win_size *wsize;
722 struct ov7670_info *info = i2c_get_clientdata(c); 722 struct ov7670_info *info = i2c_get_clientdata(c);
723 unsigned char com7; 723 unsigned char com7, clkrc;
724 724
725 ret = ov7670_try_fmt(c, fmt, &ovfmt, &wsize); 725 ret = ov7670_try_fmt(c, fmt, &ovfmt, &wsize);
726 if (ret) 726 if (ret)
727 return ret; 727 return ret;
728 /* 728 /*
729 * HACK: if we're running rgb565 we need to grab then rewrite
730 * CLKRC. If we're *not*, however, then rewriting clkrc hoses
731 * the colors.
732 */
733 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565) {
734 ret = ov7670_read(c, REG_CLKRC, &clkrc);
735 if (ret)
736 return ret;
737 }
738 /*
729 * COM7 is a pain in the ass, it doesn't like to be read then 739 * COM7 is a pain in the ass, it doesn't like to be read then
730 * quickly written afterward. But we have everything we need 740 * quickly written afterward. But we have everything we need
731 * to set it absolutely here, as long as the format-specific 741 * to set it absolutely here, as long as the format-specific
@@ -744,7 +754,10 @@ static int ov7670_s_fmt(struct i2c_client *c, struct v4l2_format *fmt)
744 if (wsize->regs) 754 if (wsize->regs)
745 ret = ov7670_write_array(c, wsize->regs); 755 ret = ov7670_write_array(c, wsize->regs);
746 info->fmt = ovfmt; 756 info->fmt = ovfmt;
747 return 0; 757
758 if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_RGB565 && ret == 0)
759 ret = ov7670_write(c, REG_CLKRC, clkrc);
760 return ret;
748} 761}
749 762
750/* 763/*
@@ -1267,7 +1280,9 @@ static int ov7670_attach(struct i2c_adapter *adapter)
1267 ret = ov7670_detect(client); 1280 ret = ov7670_detect(client);
1268 if (ret) 1281 if (ret)
1269 goto out_free_info; 1282 goto out_free_info;
1270 i2c_attach_client(client); 1283 ret = i2c_attach_client(client);
1284 if (ret)
1285 goto out_free_info;
1271 return 0; 1286 return 0;
1272 1287
1273 out_free_info: 1288 out_free_info:
diff --git a/drivers/media/video/pvrusb2/Kconfig b/drivers/media/video/pvrusb2/Kconfig
index 5645c9318890..d0c2cd785430 100644
--- a/drivers/media/video/pvrusb2/Kconfig
+++ b/drivers/media/video/pvrusb2/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_PVRUSB2 1config VIDEO_PVRUSB2
2 tristate "Hauppauge WinTV-PVR USB2 support" 2 tristate "Hauppauge WinTV-PVR USB2 support"
3 depends on VIDEO_V4L2 && USB && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
4 select FW_LOADER 4 select FW_LOADER
5 select VIDEO_TUNER 5 select VIDEO_TUNER
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
index 5669c8ca9ca3..20b614436d2c 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
@@ -391,22 +391,29 @@ static int pvr2_encoder_prep_config(struct pvr2_hdw *hdw)
391int pvr2_encoder_configure(struct pvr2_hdw *hdw) 391int pvr2_encoder_configure(struct pvr2_hdw *hdw)
392{ 392{
393 int ret; 393 int ret;
394 int val;
394 pvr2_trace(PVR2_TRACE_ENCODER,"pvr2_encoder_configure" 395 pvr2_trace(PVR2_TRACE_ENCODER,"pvr2_encoder_configure"
395 " (cx2341x module)"); 396 " (cx2341x module)");
396 hdw->enc_ctl_state.port = CX2341X_PORT_STREAMING; 397 hdw->enc_ctl_state.port = CX2341X_PORT_STREAMING;
397 hdw->enc_ctl_state.width = hdw->res_hor_val; 398 hdw->enc_ctl_state.width = hdw->res_hor_val;
398 hdw->enc_ctl_state.height = hdw->res_ver_val; 399 hdw->enc_ctl_state.height = hdw->res_ver_val;
399 hdw->enc_ctl_state.is_50hz = ((hdw->std_mask_cur & 400 hdw->enc_ctl_state.is_50hz = ((hdw->std_mask_cur & V4L2_STD_525_60) ?
400 (V4L2_STD_NTSC|V4L2_STD_PAL_M)) ?
401 0 : 1); 401 0 : 1);
402 402
403 ret = 0; 403 ret = 0;
404 404
405 ret |= pvr2_encoder_prep_config(hdw); 405 ret |= pvr2_encoder_prep_config(hdw);
406 406
407 /* saa7115: 0xf0 */
408 val = 0xf0;
409 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) {
410 /* ivtv cx25840: 0x140 */
411 val = 0x140;
412 }
413
407 if (!ret) ret = pvr2_encoder_vcmd( 414 if (!ret) ret = pvr2_encoder_vcmd(
408 hdw,CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 415 hdw,CX2341X_ENC_SET_NUM_VSYNC_LINES, 2,
409 0xf0, 0xf0); 416 val, val);
410 417
411 /* setup firmware to notify us about some events (don't know why...) */ 418 /* setup firmware to notify us about some events (don't know why...) */
412 if (!ret) ret = pvr2_encoder_vcmd( 419 if (!ret) ret = pvr2_encoder_vcmd(
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index acf651e01f94..1311891e7ee3 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -83,7 +83,7 @@ static struct pvr2_string_table pvr2_client_lists[] = {
83}; 83};
84 84
85static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL}; 85static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL};
86static DECLARE_MUTEX(pvr2_unit_sem); 86static DEFINE_MUTEX(pvr2_unit_mtx);
87 87
88static int ctlchg = 0; 88static int ctlchg = 0;
89static int initusbreset = 1; 89static int initusbreset = 1;
@@ -2076,14 +2076,14 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2076 hdw->ctl_read_urb = usb_alloc_urb(0,GFP_KERNEL); 2076 hdw->ctl_read_urb = usb_alloc_urb(0,GFP_KERNEL);
2077 if (!hdw->ctl_read_urb) goto fail; 2077 if (!hdw->ctl_read_urb) goto fail;
2078 2078
2079 down(&pvr2_unit_sem); do { 2079 mutex_lock(&pvr2_unit_mtx); do {
2080 for (idx = 0; idx < PVR_NUM; idx++) { 2080 for (idx = 0; idx < PVR_NUM; idx++) {
2081 if (unit_pointers[idx]) continue; 2081 if (unit_pointers[idx]) continue;
2082 hdw->unit_number = idx; 2082 hdw->unit_number = idx;
2083 unit_pointers[idx] = hdw; 2083 unit_pointers[idx] = hdw;
2084 break; 2084 break;
2085 } 2085 }
2086 } while (0); up(&pvr2_unit_sem); 2086 } while (0); mutex_unlock(&pvr2_unit_mtx);
2087 2087
2088 cnt1 = 0; 2088 cnt1 = 0;
2089 cnt2 = scnprintf(hdw->name+cnt1,sizeof(hdw->name)-cnt1,"pvrusb2"); 2089 cnt2 = scnprintf(hdw->name+cnt1,sizeof(hdw->name)-cnt1,"pvrusb2");
@@ -2186,13 +2186,13 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2186 } 2186 }
2187 pvr2_i2c_core_done(hdw); 2187 pvr2_i2c_core_done(hdw);
2188 pvr2_hdw_remove_usb_stuff(hdw); 2188 pvr2_hdw_remove_usb_stuff(hdw);
2189 down(&pvr2_unit_sem); do { 2189 mutex_lock(&pvr2_unit_mtx); do {
2190 if ((hdw->unit_number >= 0) && 2190 if ((hdw->unit_number >= 0) &&
2191 (hdw->unit_number < PVR_NUM) && 2191 (hdw->unit_number < PVR_NUM) &&
2192 (unit_pointers[hdw->unit_number] == hdw)) { 2192 (unit_pointers[hdw->unit_number] == hdw)) {
2193 unit_pointers[hdw->unit_number] = NULL; 2193 unit_pointers[hdw->unit_number] = NULL;
2194 } 2194 }
2195 } while (0); up(&pvr2_unit_sem); 2195 } while (0); mutex_unlock(&pvr2_unit_mtx);
2196 kfree(hdw->controls); 2196 kfree(hdw->controls);
2197 kfree(hdw->mpeg_ctrl_info); 2197 kfree(hdw->mpeg_ctrl_info);
2198 kfree(hdw->std_defs); 2198 kfree(hdw->std_defs);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index 58fc3c730fe1..6786d3c0c98b 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -23,6 +23,7 @@
23#include "pvrusb2-hdw-internal.h" 23#include "pvrusb2-hdw-internal.h"
24#include "pvrusb2-debug.h" 24#include "pvrusb2-debug.h"
25#include "pvrusb2-fx2-cmd.h" 25#include "pvrusb2-fx2-cmd.h"
26#include "pvrusb2.h"
26 27
27#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__) 28#define trace_i2c(...) pvr2_trace(PVR2_TRACE_I2C,__VA_ARGS__)
28 29
@@ -38,6 +39,10 @@ static unsigned int i2c_scan = 0;
38module_param(i2c_scan, int, S_IRUGO|S_IWUSR); 39module_param(i2c_scan, int, S_IRUGO|S_IWUSR);
39MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time"); 40MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
40 41
42static int ir_mode[PVR_NUM] = { [0 ... PVR_NUM-1] = 1 };
43module_param_array(ir_mode, int, NULL, 0444);
44MODULE_PARM_DESC(ir_mode,"specify: 0=disable IR reception, 1=normal IR");
45
41static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp, 46static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp,
42 unsigned int detail, 47 unsigned int detail,
43 char *buf,unsigned int maxlen); 48 char *buf,unsigned int maxlen);
@@ -273,6 +278,15 @@ static int i2c_hack_wm8775(struct pvr2_hdw *hdw,
273 return pvr2_i2c_basic_op(hdw,i2c_addr,wdata,wlen,rdata,rlen); 278 return pvr2_i2c_basic_op(hdw,i2c_addr,wdata,wlen,rdata,rlen);
274} 279}
275 280
281/* This is an entry point designed to always fail any attempt to perform a
282 transfer. We use this to cause certain I2C addresses to not be
283 probed. */
284static int i2c_black_hole(struct pvr2_hdw *hdw,
285 u8 i2c_addr,u8 *wdata,u16 wlen,u8 *rdata,u16 rlen)
286{
287 return -EIO;
288}
289
276/* This is a special entry point that is entered if an I2C operation is 290/* This is a special entry point that is entered if an I2C operation is
277 attempted to a cx25840 chip on model 24xxx hardware. This chip can 291 attempted to a cx25840 chip on model 24xxx hardware. This chip can
278 sometimes wedge itself. Worse still, when this happens msp3400 can 292 sometimes wedge itself. Worse still, when this happens msp3400 can
@@ -994,10 +1008,17 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
994 } 1008 }
995 1009
996 /* However, deal with various special cases for 24xxx hardware. */ 1010 /* However, deal with various special cases for 24xxx hardware. */
1011 if (ir_mode[hdw->unit_number] == 0) {
1012 printk(KERN_INFO "%s: IR disabled\n",hdw->name);
1013 hdw->i2c_func[0x18] = i2c_black_hole;
1014 } else if (ir_mode[hdw->unit_number] == 1) {
1015 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) {
1016 hdw->i2c_func[0x18] = i2c_24xxx_ir;
1017 }
1018 }
997 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) { 1019 if (hdw->hdw_type == PVR2_HDW_TYPE_24XXX) {
998 hdw->i2c_func[0x1b] = i2c_hack_wm8775; 1020 hdw->i2c_func[0x1b] = i2c_hack_wm8775;
999 hdw->i2c_func[0x44] = i2c_hack_cx25840; 1021 hdw->i2c_func[0x44] = i2c_hack_cx25840;
1000 hdw->i2c_func[0x18] = i2c_24xxx_ir;
1001 } 1022 }
1002 1023
1003 // Configure the adapter and set up everything else related to it. 1024 // Configure the adapter and set up everything else related to it.
diff --git a/drivers/media/video/pvrusb2/pvrusb2-main.c b/drivers/media/video/pvrusb2/pvrusb2-main.c
index e976c484c058..9ea41c6699bb 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-main.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-main.c
@@ -25,7 +25,6 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/moduleparam.h> 27#include <linux/moduleparam.h>
28#include <linux/smp_lock.h>
29#include <linux/usb.h> 28#include <linux/usb.h>
30#include <linux/videodev2.h> 29#include <linux/videodev2.h>
31 30
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index a741c556a39a..7ab79baa1c8c 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -518,40 +518,32 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
518 } 518 }
519 sfp->item_last = cip; 519 sfp->item_last = cip;
520 520
521 cip->attr_name.attr.owner = THIS_MODULE;
522 cip->attr_name.attr.name = "name"; 521 cip->attr_name.attr.name = "name";
523 cip->attr_name.attr.mode = S_IRUGO; 522 cip->attr_name.attr.mode = S_IRUGO;
524 cip->attr_name.show = fp->show_name; 523 cip->attr_name.show = fp->show_name;
525 524
526 cip->attr_type.attr.owner = THIS_MODULE;
527 cip->attr_type.attr.name = "type"; 525 cip->attr_type.attr.name = "type";
528 cip->attr_type.attr.mode = S_IRUGO; 526 cip->attr_type.attr.mode = S_IRUGO;
529 cip->attr_type.show = fp->show_type; 527 cip->attr_type.show = fp->show_type;
530 528
531 cip->attr_min.attr.owner = THIS_MODULE;
532 cip->attr_min.attr.name = "min_val"; 529 cip->attr_min.attr.name = "min_val";
533 cip->attr_min.attr.mode = S_IRUGO; 530 cip->attr_min.attr.mode = S_IRUGO;
534 cip->attr_min.show = fp->show_min; 531 cip->attr_min.show = fp->show_min;
535 532
536 cip->attr_max.attr.owner = THIS_MODULE;
537 cip->attr_max.attr.name = "max_val"; 533 cip->attr_max.attr.name = "max_val";
538 cip->attr_max.attr.mode = S_IRUGO; 534 cip->attr_max.attr.mode = S_IRUGO;
539 cip->attr_max.show = fp->show_max; 535 cip->attr_max.show = fp->show_max;
540 536
541 cip->attr_val.attr.owner = THIS_MODULE;
542 cip->attr_val.attr.name = "cur_val"; 537 cip->attr_val.attr.name = "cur_val";
543 cip->attr_val.attr.mode = S_IRUGO; 538 cip->attr_val.attr.mode = S_IRUGO;
544 539
545 cip->attr_custom.attr.owner = THIS_MODULE;
546 cip->attr_custom.attr.name = "custom_val"; 540 cip->attr_custom.attr.name = "custom_val";
547 cip->attr_custom.attr.mode = S_IRUGO; 541 cip->attr_custom.attr.mode = S_IRUGO;
548 542
549 cip->attr_enum.attr.owner = THIS_MODULE;
550 cip->attr_enum.attr.name = "enum_val"; 543 cip->attr_enum.attr.name = "enum_val";
551 cip->attr_enum.attr.mode = S_IRUGO; 544 cip->attr_enum.attr.mode = S_IRUGO;
552 cip->attr_enum.show = fp->show_enum; 545 cip->attr_enum.show = fp->show_enum;
553 546
554 cip->attr_bits.attr.owner = THIS_MODULE;
555 cip->attr_bits.attr.name = "bit_val"; 547 cip->attr_bits.attr.name = "bit_val";
556 cip->attr_bits.attr.mode = S_IRUGO; 548 cip->attr_bits.attr.mode = S_IRUGO;
557 cip->attr_bits.show = fp->show_bits; 549 cip->attr_bits.show = fp->show_bits;
@@ -616,12 +608,10 @@ static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
616 608
617 dip = kzalloc(sizeof(*dip),GFP_KERNEL); 609 dip = kzalloc(sizeof(*dip),GFP_KERNEL);
618 if (!dip) return; 610 if (!dip) return;
619 dip->attr_debugcmd.attr.owner = THIS_MODULE;
620 dip->attr_debugcmd.attr.name = "debugcmd"; 611 dip->attr_debugcmd.attr.name = "debugcmd";
621 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP; 612 dip->attr_debugcmd.attr.mode = S_IRUGO|S_IWUSR|S_IWGRP;
622 dip->attr_debugcmd.show = debugcmd_show; 613 dip->attr_debugcmd.show = debugcmd_show;
623 dip->attr_debugcmd.store = debugcmd_store; 614 dip->attr_debugcmd.store = debugcmd_store;
624 dip->attr_debuginfo.attr.owner = THIS_MODULE;
625 dip->attr_debuginfo.attr.name = "debuginfo"; 615 dip->attr_debuginfo.attr.name = "debuginfo";
626 dip->attr_debuginfo.attr.mode = S_IRUGO; 616 dip->attr_debuginfo.attr.mode = S_IRUGO;
627 dip->attr_debuginfo.show = debuginfo_show; 617 dip->attr_debuginfo.show = debuginfo_show;
@@ -811,7 +801,6 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
811 return; 801 return;
812 } 802 }
813 803
814 sfp->attr_v4l_minor_number.attr.owner = THIS_MODULE;
815 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number"; 804 sfp->attr_v4l_minor_number.attr.name = "v4l_minor_number";
816 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO; 805 sfp->attr_v4l_minor_number.attr.mode = S_IRUGO;
817 sfp->attr_v4l_minor_number.show = v4l_minor_number_show; 806 sfp->attr_v4l_minor_number.show = v4l_minor_number_show;
@@ -825,7 +814,6 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
825 sfp->v4l_minor_number_created_ok = !0; 814 sfp->v4l_minor_number_created_ok = !0;
826 } 815 }
827 816
828 sfp->attr_v4l_radio_minor_number.attr.owner = THIS_MODULE;
829 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number"; 817 sfp->attr_v4l_radio_minor_number.attr.name = "v4l_radio_minor_number";
830 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO; 818 sfp->attr_v4l_radio_minor_number.attr.mode = S_IRUGO;
831 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show; 819 sfp->attr_v4l_radio_minor_number.show = v4l_radio_minor_number_show;
@@ -839,7 +827,6 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
839 sfp->v4l_radio_minor_number_created_ok = !0; 827 sfp->v4l_radio_minor_number_created_ok = !0;
840 } 828 }
841 829
842 sfp->attr_unit_number.attr.owner = THIS_MODULE;
843 sfp->attr_unit_number.attr.name = "unit_number"; 830 sfp->attr_unit_number.attr.name = "unit_number";
844 sfp->attr_unit_number.attr.mode = S_IRUGO; 831 sfp->attr_unit_number.attr.mode = S_IRUGO;
845 sfp->attr_unit_number.show = unit_number_show; 832 sfp->attr_unit_number.show = unit_number_show;
@@ -852,7 +839,6 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
852 sfp->unit_number_created_ok = !0; 839 sfp->unit_number_created_ok = !0;
853 } 840 }
854 841
855 sfp->attr_bus_info.attr.owner = THIS_MODULE;
856 sfp->attr_bus_info.attr.name = "bus_info_str"; 842 sfp->attr_bus_info.attr.name = "bus_info_str";
857 sfp->attr_bus_info.attr.mode = S_IRUGO; 843 sfp->attr_bus_info.attr.mode = S_IRUGO;
858 sfp->attr_bus_info.show = bus_info_show; 844 sfp->attr_bus_info.show = bus_info_show;
diff --git a/drivers/media/video/pwc/Kconfig b/drivers/media/video/pwc/Kconfig
index 8fdf7101d3bf..7298cf2e1650 100644
--- a/drivers/media/video/pwc/Kconfig
+++ b/drivers/media/video/pwc/Kconfig
@@ -1,6 +1,6 @@
1config USB_PWC 1config USB_PWC
2 tristate "USB Philips Cameras" 2 tristate "USB Philips Cameras"
3 depends on USB && VIDEO_V4L1 3 depends on VIDEO_V4L1
4 ---help--- 4 ---help---
5 Say Y or M here if you want to use one of these Philips & OEM 5 Say Y or M here if you want to use one of these Philips & OEM
6 webcams: 6 webcams:
diff --git a/drivers/media/video/pwc/philips.txt b/drivers/media/video/pwc/philips.txt
index f5e848410311..f9f3584281d8 100644
--- a/drivers/media/video/pwc/philips.txt
+++ b/drivers/media/video/pwc/philips.txt
@@ -54,9 +54,9 @@ fps
54 Specifies the desired framerate. Is an integer in the range of 4-30. 54 Specifies the desired framerate. Is an integer in the range of 4-30.
55 55
56fbufs 56fbufs
57 This paramter specifies the number of internal buffers to use for storing 57 This parameter specifies the number of internal buffers to use for storing
58 frames from the cam. This will help if the process that reads images from 58 frames from the cam. This will help if the process that reads images from
59 the cam is a bit slow or momentarely busy. However, on slow machines it 59 the cam is a bit slow or momentarily busy. However, on slow machines it
60 only introduces lag, so choose carefully. The default is 3, which is 60 only introduces lag, so choose carefully. The default is 3, which is
61 reasonable. You can set it between 2 and 5. 61 reasonable. You can set it between 2 and 5.
62 62
@@ -209,7 +209,7 @@ trace
209 209
210 128 0x80 PWCX debugging Off 210 128 0x80 PWCX debugging Off
211 211
212 For example, to trace the open() & read() fuctions, sum 8 + 4 = 12, 212 For example, to trace the open() & read() functions, sum 8 + 4 = 12,
213 so you would supply trace=12 during insmod or modprobe. If 213 so you would supply trace=12 during insmod or modprobe. If
214 you want to turn the initialization and probing tracing off, set trace=0. 214 you want to turn the initialization and probing tracing off, set trace=0.
215 The default value for trace is 35 (0x23). 215 The default value for trace is 35 (0x23).
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 4ea479baee74..50f15adfa7c8 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -1170,6 +1170,42 @@ struct saa7134_board saa7134_boards[] = {
1170 .amux = LINE2, 1170 .amux = LINE2,
1171 }, 1171 },
1172 }, 1172 },
1173 [SAA7134_BOARD_ECS_TVP3XP_4CB6] = {
1174 /* Barry Scott <barry.scott@onelan.co.uk> */
1175 .name = "Elitegroup ECS TVP3XP FM1246 Tuner Card (PAL,FM)",
1176 .audio_clock = 0x187de7,
1177 .tuner_type = TUNER_PHILIPS_PAL_I,
1178 .radio_type = UNSET,
1179 .tuner_addr = ADDR_UNSET,
1180 .radio_addr = ADDR_UNSET,
1181 .inputs = {{
1182 .name = name_tv,
1183 .vmux = 1,
1184 .amux = TV,
1185 .tv = 1,
1186 },{
1187 .name = name_tv_mono,
1188 .vmux = 1,
1189 .amux = LINE2,
1190 .tv = 1,
1191 },{
1192 .name = name_comp1,
1193 .vmux = 3,
1194 .amux = LINE1,
1195 },{
1196 .name = name_svideo,
1197 .vmux = 8,
1198 .amux = LINE1,
1199 },{
1200 .name = "CVid over SVid",
1201 .vmux = 0,
1202 .amux = LINE1,
1203 }},
1204 .radio = {
1205 .name = name_radio,
1206 .amux = LINE2,
1207 },
1208 },
1173 [SAA7134_BOARD_AVACSSMARTTV] = { 1209 [SAA7134_BOARD_AVACSSMARTTV] = {
1174 /* Roman Pszonczenko <romka@kolos.math.uni.lodz.pl> */ 1210 /* Roman Pszonczenko <romka@kolos.math.uni.lodz.pl> */
1175 .name = "AVACS SmartTV", 1211 .name = "AVACS SmartTV",
@@ -2754,6 +2790,35 @@ struct saa7134_board saa7134_boards[] = {
2754 .amux = LINE1, 2790 .amux = LINE1,
2755 }, 2791 },
2756 }, 2792 },
2793 [SAA7134_BOARD_KWORLD_DVBT_210] = {
2794 .name = "KWorld DVB-T 210",
2795 .audio_clock = 0x00187de7,
2796 .tuner_type = TUNER_PHILIPS_TDA8290,
2797 .radio_type = UNSET,
2798 .tuner_addr = ADDR_UNSET,
2799 .radio_addr = ADDR_UNSET,
2800 .mpeg = SAA7134_MPEG_DVB,
2801 .gpiomask = 1 << 21,
2802 .inputs = {{
2803 .name = name_tv,
2804 .vmux = 1,
2805 .amux = TV,
2806 .tv = 1,
2807 },{
2808 .name = name_comp1,
2809 .vmux = 3,
2810 .amux = LINE1,
2811 },{
2812 .name = name_svideo,
2813 .vmux = 8,
2814 .amux = LINE1,
2815 }},
2816 .radio = {
2817 .name = name_radio,
2818 .amux = TV,
2819 .gpio = 0x0200000,
2820 },
2821 },
2757 [SAA7134_BOARD_KWORLD_ATSC110] = { 2822 [SAA7134_BOARD_KWORLD_ATSC110] = {
2758 .name = "Kworld ATSC110", 2823 .name = "Kworld ATSC110",
2759 .audio_clock = 0x00187de7, 2824 .audio_clock = 0x00187de7,
@@ -3407,6 +3472,36 @@ struct saa7134_board saa7134_boards[] = {
3407 .gpio = 0x0200000, 3472 .gpio = 0x0200000,
3408 }, 3473 },
3409 }, 3474 },
3475 [SAA7134_BOARD_SABRENT_TV_PCB05] = {
3476 .name = "Sabrent PCMCIA TV-PCB05",
3477 .audio_clock = 0x00187de7,
3478 .tuner_type = TUNER_PHILIPS_TDA8290,
3479 .radio_type = UNSET,
3480 .tuner_addr = ADDR_UNSET,
3481 .radio_addr = ADDR_UNSET,
3482 .inputs = {{
3483 .name = name_tv,
3484 .vmux = 1,
3485 .amux = TV,
3486 .tv = 1,
3487 },{
3488 .name = name_comp1,
3489 .vmux = 3,
3490 .amux = LINE1,
3491 },{
3492 .name = name_comp2,
3493 .vmux = 0,
3494 .amux = LINE1,
3495 },{
3496 .name = name_svideo,
3497 .vmux = 8,
3498 .amux = LINE1,
3499 }},
3500 .mute = {
3501 .name = name_mute,
3502 .amux = TV,
3503 },
3504 },
3410}; 3505};
3411 3506
3412const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 3507const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -3515,7 +3610,13 @@ struct pci_device_id saa7134_pci_tbl[] = {
3515 .vendor = PCI_VENDOR_ID_PHILIPS, 3610 .vendor = PCI_VENDOR_ID_PHILIPS,
3516 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 3611 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3517 .subvendor = 0x5168, /* Animation Technologies (LifeView) */ 3612 .subvendor = 0x5168, /* Animation Technologies (LifeView) */
3518 .subdevice = 0x0214, /* Standard PCI, LR214WF */ 3613 .subdevice = 0x0214, /* Standard PCI, LR214 Rev E and earlier (SAA7135) */
3614 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM,
3615 },{
3616 .vendor = PCI_VENDOR_ID_PHILIPS,
3617 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3618 .subvendor = 0x5168, /* Animation Technologies (LifeView) */
3619 .subdevice = 0x5214, /* Standard PCI, LR214 Rev F onwards (SAA7131) */
3519 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM, 3620 .driver_data = SAA7134_BOARD_FLYTVPLATINUM_FM,
3520 },{ 3621 },{
3521 .vendor = PCI_VENDOR_ID_PHILIPS, 3622 .vendor = PCI_VENDOR_ID_PHILIPS,
@@ -3689,6 +3790,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
3689 .driver_data = SAA7134_BOARD_ECS_TVP3XP_4CB5, 3790 .driver_data = SAA7134_BOARD_ECS_TVP3XP_4CB5,
3690 },{ 3791 },{
3691 .vendor = PCI_VENDOR_ID_PHILIPS, 3792 .vendor = PCI_VENDOR_ID_PHILIPS,
3793 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
3794 .subvendor = 0x1019,
3795 .subdevice = 0x4cb6,
3796 .driver_data = SAA7134_BOARD_ECS_TVP3XP_4CB6,
3797 },{
3798 .vendor = PCI_VENDOR_ID_PHILIPS,
3692 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 3799 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
3693 .subvendor = 0x12ab, 3800 .subvendor = 0x12ab,
3694 .subdevice = 0x0800, 3801 .subdevice = 0x0800,
@@ -3915,6 +4022,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
3915 .driver_data = SAA7134_BOARD_TEVION_DVBT_220RF, 4022 .driver_data = SAA7134_BOARD_TEVION_DVBT_220RF,
3916 },{ 4023 },{
3917 .vendor = PCI_VENDOR_ID_PHILIPS, 4024 .vendor = PCI_VENDOR_ID_PHILIPS,
4025 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4026 .subvendor = 0x17de,
4027 .subdevice = 0x7250,
4028 .driver_data = SAA7134_BOARD_KWORLD_DVBT_210,
4029 },{
4030 .vendor = PCI_VENDOR_ID_PHILIPS,
3918 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, /* SAA7135HL */ 4031 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, /* SAA7135HL */
3919 .subvendor = 0x17de, 4032 .subvendor = 0x17de,
3920 .subdevice = 0x7350, 4033 .subdevice = 0x7350,
@@ -4100,6 +4213,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
4100 .subdevice = 0x4857, 4213 .subdevice = 0x4857,
4101 .driver_data = SAA7134_BOARD_ASUSTeK_P7131_DUAL, 4214 .driver_data = SAA7134_BOARD_ASUSTeK_P7131_DUAL,
4102 },{ 4215 },{
4216 .vendor = PCI_VENDOR_ID_PHILIPS,
4217 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
4218 .subvendor = 0x0919, /* SinoVideo PCI 2309 Proteus (7134) */
4219 .subdevice = 0x2003, /* OEM cardbus */
4220 .driver_data = SAA7134_BOARD_SABRENT_TV_PCB05,
4221 },{
4103 /* --- boards without eeprom + subsystem ID --- */ 4222 /* --- boards without eeprom + subsystem ID --- */
4104 .vendor = PCI_VENDOR_ID_PHILIPS, 4223 .vendor = PCI_VENDOR_ID_PHILIPS,
4105 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 4224 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -4178,6 +4297,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
4178 case SAA7134_BOARD_CINERGY600_MK3: 4297 case SAA7134_BOARD_CINERGY600_MK3:
4179 case SAA7134_BOARD_ECS_TVP3XP: 4298 case SAA7134_BOARD_ECS_TVP3XP:
4180 case SAA7134_BOARD_ECS_TVP3XP_4CB5: 4299 case SAA7134_BOARD_ECS_TVP3XP_4CB5:
4300 case SAA7134_BOARD_ECS_TVP3XP_4CB6:
4181 case SAA7134_BOARD_MD2819: 4301 case SAA7134_BOARD_MD2819:
4182 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: 4302 case SAA7134_BOARD_KWORLD_VSTREAM_XPERT:
4183 case SAA7134_BOARD_KWORLD_XPERT: 4303 case SAA7134_BOARD_KWORLD_XPERT:
@@ -4426,6 +4546,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
4426 } 4546 }
4427 break; 4547 break;
4428 case SAA7134_BOARD_PINNACLE_PCTV_310i: 4548 case SAA7134_BOARD_PINNACLE_PCTV_310i:
4549 case SAA7134_BOARD_KWORLD_DVBT_210:
4429 case SAA7134_BOARD_TEVION_DVBT_220RF: 4550 case SAA7134_BOARD_TEVION_DVBT_220RF:
4430 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 4551 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
4431 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: 4552 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index 65aec881bbde..e0eec80088c7 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -887,6 +887,20 @@ static struct tda1004x_config asus_p7131_hybrid_lna_config = {
887 .antenna_switch= 2, 887 .antenna_switch= 2,
888 .request_firmware = philips_tda1004x_request_firmware 888 .request_firmware = philips_tda1004x_request_firmware
889}; 889};
890static struct tda1004x_config kworld_dvb_t_210_config = {
891 .demod_address = 0x08,
892 .invert = 1,
893 .invert_oclk = 0,
894 .xtal_freq = TDA10046_XTAL_16M,
895 .agc_config = TDA10046_AGC_TDA827X,
896 .gpio_config = TDA10046_GP11_I,
897 .if_freq = TDA10046_FREQ_045,
898 .i2c_gate = 0x4b,
899 .tuner_address = 0x61,
900 .tuner_config = 2,
901 .antenna_switch= 1,
902 .request_firmware = philips_tda1004x_request_firmware
903};
890/* ------------------------------------------------------------------ 904/* ------------------------------------------------------------------
891 * special case: this card uses saa713x GPIO22 for the mode switch 905 * special case: this card uses saa713x GPIO22 for the mode switch
892 */ 906 */
@@ -1039,6 +1053,9 @@ static int dvb_init(struct saa7134_dev *dev)
1039 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set; 1053 dev->dvb.frontend->ops.tuner_ops.set_params = philips_tda6651_pll_set;
1040 } 1054 }
1041 break; 1055 break;
1056 case SAA7134_BOARD_KWORLD_DVBT_210:
1057 configure_tda827x_fe(dev, &kworld_dvb_t_210_config);
1058 break;
1042 case SAA7134_BOARD_PHILIPS_TIGER: 1059 case SAA7134_BOARD_PHILIPS_TIGER:
1043 configure_tda827x_fe(dev, &philips_tiger_config); 1060 configure_tda827x_fe(dev, &philips_tiger_config);
1044 break; 1061 break;
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index dd759d6d8d25..7b56041186dc 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -27,7 +27,6 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/delay.h> 29#include <linux/delay.h>
30#include <linux/smp_lock.h>
31#include <asm/div64.h> 30#include <asm/div64.h>
32 31
33#include "saa7134-reg.h" 32#include "saa7134-reg.h"
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 62224cc958f1..15623b27ad2e 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -235,6 +235,9 @@ struct saa7134_format {
235#define SAA7134_BOARD_AVERMEDIA_M102 110 235#define SAA7134_BOARD_AVERMEDIA_M102 110
236#define SAA7134_BOARD_ASUS_P7131_4871 111 236#define SAA7134_BOARD_ASUS_P7131_4871 111
237#define SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA 112 237#define SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA 112
238#define SAA7134_BOARD_ECS_TVP3XP_4CB6 113
239#define SAA7134_BOARD_KWORLD_DVBT_210 114
240#define SAA7134_BOARD_SABRENT_TV_PCB05 115
238 241
239#define SAA7134_MAXBOARDS 8 242#define SAA7134_MAXBOARDS 8
240#define SAA7134_INPUT_MAX 8 243#define SAA7134_INPUT_MAX 8
diff --git a/drivers/media/video/se401.h b/drivers/media/video/se401.h
index c0891b3e0018..835ef872e803 100644
--- a/drivers/media/video/se401.h
+++ b/drivers/media/video/se401.h
@@ -5,7 +5,6 @@
5#include <asm/uaccess.h> 5#include <asm/uaccess.h>
6#include <linux/videodev.h> 6#include <linux/videodev.h>
7#include <media/v4l2-common.h> 7#include <media/v4l2-common.h>
8#include <linux/smp_lock.h>
9#include <linux/mutex.h> 8#include <linux/mutex.h>
10 9
11#define se401_DEBUG /* Turn on debug messages */ 10#define se401_DEBUG /* Turn on debug messages */
diff --git a/drivers/media/video/sn9c102/Kconfig b/drivers/media/video/sn9c102/Kconfig
index 19204f5686e1..f71f272776de 100644
--- a/drivers/media/video/sn9c102/Kconfig
+++ b/drivers/media/video/sn9c102/Kconfig
@@ -1,6 +1,6 @@
1config USB_SN9C102 1config USB_SN9C102
2 tristate "USB SN9C1xx PC Camera Controller support" 2 tristate "USB SN9C1xx PC Camera Controller support"
3 depends on USB && VIDEO_V4L2 3 depends on VIDEO_V4L2
4 ---help--- 4 ---help---
5 Say Y here if you want support for cameras based on SONiX SN9C101, 5 Say Y here if you want support for cameras based on SONiX SN9C101,
6 SN9C102, SN9C103, SN9C105 and SN9C120 PC Camera Controllers. 6 SN9C102, SN9C103, SN9C105 and SN9C120 PC Camera Controllers.
diff --git a/drivers/media/video/sn9c102/sn9c102.h b/drivers/media/video/sn9c102/sn9c102.h
index 680e74634527..11fcb49f5b99 100644
--- a/drivers/media/video/sn9c102/sn9c102.h
+++ b/drivers/media/video/sn9c102/sn9c102.h
@@ -141,7 +141,7 @@ sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id)
141 141
142void 142void
143sn9c102_attach_sensor(struct sn9c102_device* cam, 143sn9c102_attach_sensor(struct sn9c102_device* cam,
144 struct sn9c102_sensor* sensor) 144 const struct sn9c102_sensor* sensor)
145{ 145{
146 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor)); 146 memcpy(&cam->sensor, sensor, sizeof(struct sn9c102_sensor));
147} 147}
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 89f83354de3b..74a204f8ebc8 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -48,8 +48,8 @@
48#define SN9C102_MODULE_AUTHOR "(C) 2004-2007 Luca Risolia" 48#define SN9C102_MODULE_AUTHOR "(C) 2004-2007 Luca Risolia"
49#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>" 49#define SN9C102_AUTHOR_EMAIL "<luca.risolia@studio.unibo.it>"
50#define SN9C102_MODULE_LICENSE "GPL" 50#define SN9C102_MODULE_LICENSE "GPL"
51#define SN9C102_MODULE_VERSION "1:1.39" 51#define SN9C102_MODULE_VERSION "1:1.44"
52#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 39) 52#define SN9C102_MODULE_VERSION_CODE KERNEL_VERSION(1, 1, 44)
53 53
54/*****************************************************************************/ 54/*****************************************************************************/
55 55
@@ -209,38 +209,41 @@ static void sn9c102_queue_unusedframes(struct sn9c102_device* cam)
209} 209}
210 210
211/*****************************************************************************/ 211/*****************************************************************************/
212
212/* 213/*
213 * Write a sequence of count value/register pairs. Returns -1 after the 214 Write a sequence of count value/register pairs. Returns -1 after the first
214 * first failed write, or 0 for no errors. 215 failed write, or 0 for no errors.
215 */ 216*/
216int sn9c102_write_regs(struct sn9c102_device* cam, const u8 valreg[][2], 217int sn9c102_write_regs(struct sn9c102_device* cam, const u8 valreg[][2],
217 int count) 218 int count)
218{ 219{
219 struct usb_device* udev = cam->usbdev; 220 struct usb_device* udev = cam->usbdev;
220 u8* value = cam->control_buffer; /* Needed for DMA'able memory */ 221 u8* buff = cam->control_buffer;
221 int i, res; 222 int i, res;
222 223
223 for (i = 0; i < count; i++) { 224 for (i = 0; i < count; i++) {
224 u8 index = valreg[i][1]; 225 u8 index = valreg[i][1];
225 226
226 /* 227 /*
227 * index is a u8, so it must be <256 and can't be out of range. 228 index is a u8, so it must be <256 and can't be out of range.
228 * If we put in a check anyway, gcc annoys us with a warning 229 If we put in a check anyway, gcc annoys us with a warning
229 * that our check is useless. People get all uppity when they 230 hat our check is useless. People get all uppity when they
230 * see warnings in the kernel compile. 231 see warnings in the kernel compile.
231 */ 232 */
232 233
233 *value = valreg[i][0]; 234 *buff = valreg[i][0];
234 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 235
235 0x08, 0x41, index, 0, 236 res = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x08,
236 value, 1, SN9C102_CTRL_TIMEOUT); 237 0x41, index, 0, buff, 1,
238 SN9C102_CTRL_TIMEOUT);
239
237 if (res < 0) { 240 if (res < 0) {
238 DBG(3, "Failed to write a register (value 0x%02X, " 241 DBG(3, "Failed to write a register (value 0x%02X, "
239 "index 0x%02X, error %d)", *value, index, res); 242 "index 0x%02X, error %d)", *buff, index, res);
240 return -1; 243 return -1;
241 } 244 }
242 245
243 cam->reg[index] = *value; 246 cam->reg[index] = *buff;
244 } 247 }
245 248
246 return 0; 249 return 0;
@@ -272,8 +275,8 @@ int sn9c102_write_reg(struct sn9c102_device* cam, u8 value, u16 index)
272} 275}
273 276
274 277
275/* NOTE: reading some registers always returns 0 */ 278/* NOTE: with the SN9C10[123] reading some registers always returns 0 */
276static int sn9c102_read_reg(struct sn9c102_device* cam, u16 index) 279int sn9c102_read_reg(struct sn9c102_device* cam, u16 index)
277{ 280{
278 struct usb_device* udev = cam->usbdev; 281 struct usb_device* udev = cam->usbdev;
279 u8* buff = cam->control_buffer; 282 u8* buff = cam->control_buffer;
@@ -299,7 +302,8 @@ int sn9c102_pread_reg(struct sn9c102_device* cam, u16 index)
299 302
300 303
301static int 304static int
302sn9c102_i2c_wait(struct sn9c102_device* cam, struct sn9c102_sensor* sensor) 305sn9c102_i2c_wait(struct sn9c102_device* cam,
306 const struct sn9c102_sensor* sensor)
303{ 307{
304 int i, r; 308 int i, r;
305 309
@@ -320,7 +324,7 @@ sn9c102_i2c_wait(struct sn9c102_device* cam, struct sn9c102_sensor* sensor)
320 324
321static int 325static int
322sn9c102_i2c_detect_read_error(struct sn9c102_device* cam, 326sn9c102_i2c_detect_read_error(struct sn9c102_device* cam,
323 struct sn9c102_sensor* sensor) 327 const struct sn9c102_sensor* sensor)
324{ 328{
325 int r , err = 0; 329 int r , err = 0;
326 330
@@ -342,7 +346,7 @@ sn9c102_i2c_detect_read_error(struct sn9c102_device* cam,
342 346
343static int 347static int
344sn9c102_i2c_detect_write_error(struct sn9c102_device* cam, 348sn9c102_i2c_detect_write_error(struct sn9c102_device* cam,
345 struct sn9c102_sensor* sensor) 349 const struct sn9c102_sensor* sensor)
346{ 350{
347 int r; 351 int r;
348 r = sn9c102_read_reg(cam, 0x08); 352 r = sn9c102_read_reg(cam, 0x08);
@@ -352,12 +356,12 @@ sn9c102_i2c_detect_write_error(struct sn9c102_device* cam,
352 356
353int 357int
354sn9c102_i2c_try_raw_read(struct sn9c102_device* cam, 358sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
355 struct sn9c102_sensor* sensor, u8 data0, u8 data1, 359 const struct sn9c102_sensor* sensor, u8 data0,
356 u8 n, u8 buffer[]) 360 u8 data1, u8 n, u8 buffer[])
357{ 361{
358 struct usb_device* udev = cam->usbdev; 362 struct usb_device* udev = cam->usbdev;
359 u8* data = cam->control_buffer; 363 u8* data = cam->control_buffer;
360 int err = 0, res; 364 int i = 0, err = 0, res;
361 365
362 /* Write cycle */ 366 /* Write cycle */
363 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) | 367 data[0] = ((sensor->interface == SN9C102_I2C_2WIRES) ? 0x80 : 0) |
@@ -402,7 +406,8 @@ sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
402 } 406 }
403 407
404 if (buffer) 408 if (buffer)
405 memcpy(buffer, data, sizeof(buffer)); 409 for (i = 0; i < n && i < 5; i++)
410 buffer[n-i-1] = data[4-i];
406 411
407 return (int)data[4]; 412 return (int)data[4];
408} 413}
@@ -410,7 +415,7 @@ sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
410 415
411int 416int
412sn9c102_i2c_try_raw_write(struct sn9c102_device* cam, 417sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
413 struct sn9c102_sensor* sensor, u8 n, u8 data0, 418 const struct sn9c102_sensor* sensor, u8 n, u8 data0,
414 u8 data1, u8 data2, u8 data3, u8 data4, u8 data5) 419 u8 data1, u8 data2, u8 data3, u8 data4, u8 data5)
415{ 420{
416 struct usb_device* udev = cam->usbdev; 421 struct usb_device* udev = cam->usbdev;
@@ -449,7 +454,7 @@ sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
449 454
450int 455int
451sn9c102_i2c_try_read(struct sn9c102_device* cam, 456sn9c102_i2c_try_read(struct sn9c102_device* cam,
452 struct sn9c102_sensor* sensor, u8 address) 457 const struct sn9c102_sensor* sensor, u8 address)
453{ 458{
454 return sn9c102_i2c_try_raw_read(cam, sensor, sensor->i2c_slave_id, 459 return sn9c102_i2c_try_raw_read(cam, sensor, sensor->i2c_slave_id,
455 address, 1, NULL); 460 address, 1, NULL);
@@ -458,7 +463,7 @@ sn9c102_i2c_try_read(struct sn9c102_device* cam,
458 463
459int 464int
460sn9c102_i2c_try_write(struct sn9c102_device* cam, 465sn9c102_i2c_try_write(struct sn9c102_device* cam,
461 struct sn9c102_sensor* sensor, u8 address, u8 value) 466 const struct sn9c102_sensor* sensor, u8 address, u8 value)
462{ 467{
463 return sn9c102_i2c_try_raw_write(cam, sensor, 3, 468 return sn9c102_i2c_try_raw_write(cam, sensor, 3,
464 sensor->i2c_slave_id, address, 469 sensor->i2c_slave_id, address,
@@ -657,16 +662,6 @@ sn9c102_write_jpegheader(struct sn9c102_device* cam, struct sn9c102_frame_t* f)
657} 662}
658 663
659 664
660static void
661sn9c102_write_eoimarker(struct sn9c102_device* cam, struct sn9c102_frame_t* f)
662{
663 static const u8 eoi_marker[2] = {0xff, 0xd9};
664
665 memcpy(f->bufmem + f->buf.bytesused, eoi_marker, sizeof(eoi_marker));
666 f->buf.bytesused += sizeof(eoi_marker);
667}
668
669
670static void sn9c102_urb_complete(struct urb *urb) 665static void sn9c102_urb_complete(struct urb *urb)
671{ 666{
672 struct sn9c102_device* cam = urb->context; 667 struct sn9c102_device* cam = urb->context;
@@ -3181,14 +3176,14 @@ static int sn9c102_ioctl(struct inode* inode, struct file* filp,
3181 3176
3182static const struct file_operations sn9c102_fops = { 3177static const struct file_operations sn9c102_fops = {
3183 .owner = THIS_MODULE, 3178 .owner = THIS_MODULE,
3184 .open = sn9c102_open, 3179 .open = sn9c102_open,
3185 .release = sn9c102_release, 3180 .release = sn9c102_release,
3186 .ioctl = sn9c102_ioctl, 3181 .ioctl = sn9c102_ioctl,
3187 .compat_ioctl = v4l_compat_ioctl32, 3182 .compat_ioctl = v4l_compat_ioctl32,
3188 .read = sn9c102_read, 3183 .read = sn9c102_read,
3189 .poll = sn9c102_poll, 3184 .poll = sn9c102_poll,
3190 .mmap = sn9c102_mmap, 3185 .mmap = sn9c102_mmap,
3191 .llseek = no_llseek, 3186 .llseek = no_llseek,
3192}; 3187};
3193 3188
3194/*****************************************************************************/ 3189/*****************************************************************************/
@@ -3251,7 +3246,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3251 break; 3246 break;
3252 } 3247 }
3253 3248
3254 for (i = 0; sn9c102_sensor_table[i]; i++) { 3249 for (i = 0; i < ARRAY_SIZE(sn9c102_sensor_table); i++) {
3255 err = sn9c102_sensor_table[i](cam); 3250 err = sn9c102_sensor_table[i](cam);
3256 if (!err) 3251 if (!err)
3257 break; 3252 break;
@@ -3262,7 +3257,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3262 DBG(3, "Support for %s maintained by %s", 3257 DBG(3, "Support for %s maintained by %s",
3263 cam->sensor.name, cam->sensor.maintainer); 3258 cam->sensor.name, cam->sensor.maintainer);
3264 } else { 3259 } else {
3265 DBG(1, "No supported image sensor detected"); 3260 DBG(1, "No supported image sensor detected for this bridge");
3266 err = -ENODEV; 3261 err = -ENODEV;
3267 goto fail; 3262 goto fail;
3268 } 3263 }
diff --git a/drivers/media/video/sn9c102/sn9c102_devtable.h b/drivers/media/video/sn9c102/sn9c102_devtable.h
index f49bd8c5b86e..916054faf9be 100644
--- a/drivers/media/video/sn9c102/sn9c102_devtable.h
+++ b/drivers/media/video/sn9c102/sn9c102_devtable.h
@@ -86,6 +86,8 @@ static const struct usb_device_id sn9c102_id_table[] = {
86 { SN9C102_USB_DEVICE(0x0c45, 0x60bc, BRIDGE_SN9C103), }, 86 { SN9C102_USB_DEVICE(0x0c45, 0x60bc, BRIDGE_SN9C103), },
87 { SN9C102_USB_DEVICE(0x0c45, 0x60be, BRIDGE_SN9C103), }, 87 { SN9C102_USB_DEVICE(0x0c45, 0x60be, BRIDGE_SN9C103), },
88 /* SN9C105 */ 88 /* SN9C105 */
89 { SN9C102_USB_DEVICE(0x045e, 0x00f5, BRIDGE_SN9C105), },
90 { SN9C102_USB_DEVICE(0x045e, 0x00f7, BRIDGE_SN9C105), },
89 { SN9C102_USB_DEVICE(0x0471, 0x0327, BRIDGE_SN9C105), }, 91 { SN9C102_USB_DEVICE(0x0471, 0x0327, BRIDGE_SN9C105), },
90 { SN9C102_USB_DEVICE(0x0471, 0x0328, BRIDGE_SN9C105), }, 92 { SN9C102_USB_DEVICE(0x0471, 0x0328, BRIDGE_SN9C105), },
91 { SN9C102_USB_DEVICE(0x0c45, 0x60c0, BRIDGE_SN9C105), }, 93 { SN9C102_USB_DEVICE(0x0c45, 0x60c0, BRIDGE_SN9C105), },
@@ -100,6 +102,7 @@ static const struct usb_device_id sn9c102_id_table[] = {
100 { SN9C102_USB_DEVICE(0x0c45, 0x60fc, BRIDGE_SN9C105), }, 102 { SN9C102_USB_DEVICE(0x0c45, 0x60fc, BRIDGE_SN9C105), },
101 { SN9C102_USB_DEVICE(0x0c45, 0x60fe, BRIDGE_SN9C105), }, 103 { SN9C102_USB_DEVICE(0x0c45, 0x60fe, BRIDGE_SN9C105), },
102 /* SN9C120 */ 104 /* SN9C120 */
105 { SN9C102_USB_DEVICE(0x0458, 0x7025, BRIDGE_SN9C120), },
103 { SN9C102_USB_DEVICE(0x0c45, 0x6102, BRIDGE_SN9C120), }, 106 { SN9C102_USB_DEVICE(0x0c45, 0x6102, BRIDGE_SN9C120), },
104 { SN9C102_USB_DEVICE(0x0c45, 0x6108, BRIDGE_SN9C120), }, 107 { SN9C102_USB_DEVICE(0x0c45, 0x6108, BRIDGE_SN9C120), },
105 { SN9C102_USB_DEVICE(0x0c45, 0x610f, BRIDGE_SN9C120), }, 108 { SN9C102_USB_DEVICE(0x0c45, 0x610f, BRIDGE_SN9C120), },
@@ -148,7 +151,6 @@ static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = {
148 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */ 151 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */
149 &sn9c102_probe_tas5110d, /* detection based on USB pid/vid */ 152 &sn9c102_probe_tas5110d, /* detection based on USB pid/vid */
150 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */ 153 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */
151 NULL,
152}; 154};
153 155
154#endif /* _SN9C102_DEVTABLE_H_ */ 156#endif /* _SN9C102_DEVTABLE_H_ */
diff --git a/drivers/media/video/sn9c102/sn9c102_hv7131d.c b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
index 28a861aed044..eaf9ad0dc8a6 100644
--- a/drivers/media/video/sn9c102/sn9c102_hv7131d.c
+++ b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
@@ -144,7 +144,7 @@ static int hv7131d_set_pix_format(struct sn9c102_device* cam,
144} 144}
145 145
146 146
147static struct sn9c102_sensor hv7131d = { 147static const struct sn9c102_sensor hv7131d = {
148 .name = "HV7131D", 148 .name = "HV7131D",
149 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 149 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
150 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 150 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
@@ -248,12 +248,10 @@ int sn9c102_probe_hv7131d(struct sn9c102_device* cam)
248 248
249 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01}, 249 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
250 {0x28, 0x17}); 250 {0x28, 0x17});
251 if (err)
252 return -EIO;
253 251
254 r0 = sn9c102_i2c_try_read(cam, &hv7131d, 0x00); 252 r0 = sn9c102_i2c_try_read(cam, &hv7131d, 0x00);
255 r1 = sn9c102_i2c_try_read(cam, &hv7131d, 0x01); 253 r1 = sn9c102_i2c_try_read(cam, &hv7131d, 0x01);
256 if (r0 < 0 || r1 < 0) 254 if (err || r0 < 0 || r1 < 0)
257 return -EIO; 255 return -EIO;
258 256
259 if (r0 != 0x00 || r1 != 0x04) 257 if (r0 != 0x00 || r1 != 0x04)
diff --git a/drivers/media/video/sn9c102/sn9c102_hv7131r.c b/drivers/media/video/sn9c102/sn9c102_hv7131r.c
index 5a495baa5f95..0fc401223cfc 100644
--- a/drivers/media/video/sn9c102/sn9c102_hv7131r.c
+++ b/drivers/media/video/sn9c102/sn9c102_hv7131r.c
@@ -44,7 +44,6 @@ static int hv7131r_init(struct sn9c102_device* cam)
44 {0xb0, 0x2b}, {0xc0, 0x2c}, 44 {0xb0, 0x2b}, {0xc0, 0x2c},
45 {0xd0, 0x2d}, {0xe0, 0x2e}, 45 {0xd0, 0x2d}, {0xe0, 0x2e},
46 {0xf0, 0x2f}, {0xff, 0x30}); 46 {0xf0, 0x2f}, {0xff, 0x30});
47
48 break; 47 break;
49 case BRIDGE_SN9C105: 48 case BRIDGE_SN9C105:
50 case BRIDGE_SN9C120: 49 case BRIDGE_SN9C120:
@@ -254,7 +253,7 @@ static int hv7131r_set_pix_format(struct sn9c102_device* cam,
254} 253}
255 254
256 255
257static struct sn9c102_sensor hv7131r = { 256static const struct sn9c102_sensor hv7131r = {
258 .name = "HV7131R", 257 .name = "HV7131R",
259 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 258 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
260 .supported_bridge = BRIDGE_SN9C103 | BRIDGE_SN9C105 | BRIDGE_SN9C120, 259 .supported_bridge = BRIDGE_SN9C103 | BRIDGE_SN9C105 | BRIDGE_SN9C120,
@@ -350,11 +349,8 @@ int sn9c102_probe_hv7131r(struct sn9c102_device* cam)
350 {0x34, 0x01}, {0x20, 0x17}, 349 {0x34, 0x01}, {0x20, 0x17},
351 {0x34, 0x01}, {0x46, 0x01}); 350 {0x34, 0x01}, {0x46, 0x01});
352 351
353 if (err)
354 return -EIO;
355
356 devid = sn9c102_i2c_try_read(cam, &hv7131r, 0x00); 352 devid = sn9c102_i2c_try_read(cam, &hv7131r, 0x00);
357 if (devid < 0) 353 if (err || devid < 0)
358 return -EIO; 354 return -EIO;
359 355
360 if (devid != 0x02) 356 if (devid != 0x02)
diff --git a/drivers/media/video/sn9c102/sn9c102_mi0343.c b/drivers/media/video/sn9c102/sn9c102_mi0343.c
index 9200845d011b..00b134ca0a3d 100644
--- a/drivers/media/video/sn9c102/sn9c102_mi0343.c
+++ b/drivers/media/video/sn9c102/sn9c102_mi0343.c
@@ -55,45 +55,45 @@ static int mi0343_get_ctrl(struct sn9c102_device* cam,
55 struct v4l2_control* ctrl) 55 struct v4l2_control* ctrl)
56{ 56{
57 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 57 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
58 u8 data[5+1]; 58 u8 data[2];
59 59
60 switch (ctrl->id) { 60 switch (ctrl->id) {
61 case V4L2_CID_EXPOSURE: 61 case V4L2_CID_EXPOSURE:
62 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 62 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 2,
63 2+1, data) < 0) 63 data) < 0)
64 return -EIO; 64 return -EIO;
65 ctrl->value = data[2]; 65 ctrl->value = data[0];
66 return 0; 66 return 0;
67 case V4L2_CID_GAIN: 67 case V4L2_CID_GAIN:
68 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 68 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 2,
69 2+1, data) < 0) 69 data) < 0)
70 return -EIO; 70 return -EIO;
71 break; 71 break;
72 case V4L2_CID_HFLIP: 72 case V4L2_CID_HFLIP:
73 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 73 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
74 2+1, data) < 0) 74 data) < 0)
75 return -EIO; 75 return -EIO;
76 ctrl->value = data[3] & 0x20 ? 1 : 0; 76 ctrl->value = data[1] & 0x20 ? 1 : 0;
77 return 0; 77 return 0;
78 case V4L2_CID_VFLIP: 78 case V4L2_CID_VFLIP:
79 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 79 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
80 2+1, data) < 0) 80 data) < 0)
81 return -EIO; 81 return -EIO;
82 ctrl->value = data[3] & 0x80 ? 1 : 0; 82 ctrl->value = data[1] & 0x80 ? 1 : 0;
83 return 0; 83 return 0;
84 case V4L2_CID_RED_BALANCE: 84 case V4L2_CID_RED_BALANCE:
85 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 85 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 2,
86 2+1, data) < 0) 86 data) < 0)
87 return -EIO; 87 return -EIO;
88 break; 88 break;
89 case V4L2_CID_BLUE_BALANCE: 89 case V4L2_CID_BLUE_BALANCE:
90 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 90 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 2,
91 2+1, data) < 0) 91 data) < 0)
92 return -EIO; 92 return -EIO;
93 break; 93 break;
94 case SN9C102_V4L2_CID_GREEN_BALANCE: 94 case SN9C102_V4L2_CID_GREEN_BALANCE:
95 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 95 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 2,
96 2+1, data) < 0) 96 data) < 0)
97 return -EIO; 97 return -EIO;
98 break; 98 break;
99 default: 99 default:
@@ -105,7 +105,7 @@ static int mi0343_get_ctrl(struct sn9c102_device* cam,
105 case V4L2_CID_RED_BALANCE: 105 case V4L2_CID_RED_BALANCE:
106 case V4L2_CID_BLUE_BALANCE: 106 case V4L2_CID_BLUE_BALANCE:
107 case SN9C102_V4L2_CID_GREEN_BALANCE: 107 case SN9C102_V4L2_CID_GREEN_BALANCE:
108 ctrl->value = data[3] | (data[2] << 8); 108 ctrl->value = data[1] | (data[0] << 8);
109 if (ctrl->value >= 0x10 && ctrl->value <= 0x3f) 109 if (ctrl->value >= 0x10 && ctrl->value <= 0x3f)
110 ctrl->value -= 0x10; 110 ctrl->value -= 0x10;
111 else if (ctrl->value >= 0x60 && ctrl->value <= 0x7f) 111 else if (ctrl->value >= 0x60 && ctrl->value <= 0x7f)
@@ -223,7 +223,7 @@ static int mi0343_set_pix_format(struct sn9c102_device* cam,
223} 223}
224 224
225 225
226static struct sn9c102_sensor mi0343 = { 226static const struct sn9c102_sensor mi0343 = {
227 .name = "MI-0343", 227 .name = "MI-0343",
228 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 228 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
229 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 229 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
@@ -332,20 +332,17 @@ static struct sn9c102_sensor mi0343 = {
332 332
333int sn9c102_probe_mi0343(struct sn9c102_device* cam) 333int sn9c102_probe_mi0343(struct sn9c102_device* cam)
334{ 334{
335 u8 data[5+1]; 335 u8 data[2];
336 int err = 0;
337
338 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
339 {0x28, 0x17});
340 336
341 if (err) 337 if (sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
338 {0x28, 0x17}))
342 return -EIO; 339 return -EIO;
343 340
344 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 0x00, 341 if (sn9c102_i2c_try_raw_read(cam, &mi0343, mi0343.i2c_slave_id, 0x00,
345 2, data) < 0) 342 2, data) < 0)
346 return -EIO; 343 return -EIO;
347 344
348 if (data[4] != 0x32 || data[3] != 0xe3) 345 if (data[1] != 0x42 || data[0] != 0xe3)
349 return -ENODEV; 346 return -ENODEV;
350 347
351 sn9c102_attach_sensor(cam, &mi0343); 348 sn9c102_attach_sensor(cam, &mi0343);
diff --git a/drivers/media/video/sn9c102/sn9c102_mi0360.c b/drivers/media/video/sn9c102/sn9c102_mi0360.c
index 64698acb0b15..f8d81d82e8d5 100644
--- a/drivers/media/video/sn9c102/sn9c102_mi0360.c
+++ b/drivers/media/video/sn9c102/sn9c102_mi0360.c
@@ -27,20 +27,105 @@ static int mi0360_init(struct sn9c102_device* cam)
27 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 27 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
28 int err = 0; 28 int err = 0;
29 29
30 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, {0x00, 0x11}, 30 switch (sn9c102_get_bridge(cam)) {
31 {0x0a, 0x14}, {0x40, 0x01}, 31 case BRIDGE_SN9C103:
32 {0x20, 0x17}, {0x07, 0x18}, 32 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, {0x00, 0x11},
33 {0xa0, 0x19}, {0x02, 0x1c}, 33 {0x0a, 0x14}, {0x40, 0x01},
34 {0x03, 0x1d}, {0x0f, 0x1e}, 34 {0x20, 0x17}, {0x07, 0x18},
35 {0x0c, 0x1f}, {0x00, 0x20}, 35 {0xa0, 0x19}, {0x02, 0x1c},
36 {0x10, 0x21}, {0x20, 0x22}, 36 {0x03, 0x1d}, {0x0f, 0x1e},
37 {0x30, 0x23}, {0x40, 0x24}, 37 {0x0c, 0x1f}, {0x00, 0x20},
38 {0x50, 0x25}, {0x60, 0x26}, 38 {0x10, 0x21}, {0x20, 0x22},
39 {0x70, 0x27}, {0x80, 0x28}, 39 {0x30, 0x23}, {0x40, 0x24},
40 {0x90, 0x29}, {0xa0, 0x2a}, 40 {0x50, 0x25}, {0x60, 0x26},
41 {0xb0, 0x2b}, {0xc0, 0x2c}, 41 {0x70, 0x27}, {0x80, 0x28},
42 {0xd0, 0x2d}, {0xe0, 0x2e}, 42 {0x90, 0x29}, {0xa0, 0x2a},
43 {0xf0, 0x2f}, {0xff, 0x30}); 43 {0xb0, 0x2b}, {0xc0, 0x2c},
44 {0xd0, 0x2d}, {0xe0, 0x2e},
45 {0xf0, 0x2f}, {0xff, 0x30});
46 break;
47 case BRIDGE_SN9C105:
48 case BRIDGE_SN9C120:
49 err = sn9c102_write_const_regs(cam, {0x44, 0x01}, {0x40, 0x02},
50 {0x00, 0x03}, {0x1a, 0x04},
51 {0x50, 0x05}, {0x20, 0x06},
52 {0x10, 0x07}, {0x03, 0x10},
53 {0x08, 0x14}, {0xa2, 0x17},
54 {0x47, 0x18}, {0x00, 0x19},
55 {0x1d, 0x1a}, {0x10, 0x1b},
56 {0x02, 0x1c}, {0x03, 0x1d},
57 {0x0f, 0x1e}, {0x0c, 0x1f},
58 {0x00, 0x20}, {0x29, 0x21},
59 {0x40, 0x22}, {0x54, 0x23},
60 {0x66, 0x24}, {0x76, 0x25},
61 {0x85, 0x26}, {0x94, 0x27},
62 {0xa1, 0x28}, {0xae, 0x29},
63 {0xbb, 0x2a}, {0xc7, 0x2b},
64 {0xd3, 0x2c}, {0xde, 0x2d},
65 {0xea, 0x2e}, {0xf4, 0x2f},
66 {0xff, 0x30}, {0x00, 0x3F},
67 {0xC7, 0x40}, {0x01, 0x41},
68 {0x44, 0x42}, {0x00, 0x43},
69 {0x44, 0x44}, {0x00, 0x45},
70 {0x44, 0x46}, {0x00, 0x47},
71 {0xC7, 0x48}, {0x01, 0x49},
72 {0xC7, 0x4A}, {0x01, 0x4B},
73 {0xC7, 0x4C}, {0x01, 0x4D},
74 {0x44, 0x4E}, {0x00, 0x4F},
75 {0x44, 0x50}, {0x00, 0x51},
76 {0x44, 0x52}, {0x00, 0x53},
77 {0xC7, 0x54}, {0x01, 0x55},
78 {0xC7, 0x56}, {0x01, 0x57},
79 {0xC7, 0x58}, {0x01, 0x59},
80 {0x44, 0x5A}, {0x00, 0x5B},
81 {0x44, 0x5C}, {0x00, 0x5D},
82 {0x44, 0x5E}, {0x00, 0x5F},
83 {0xC7, 0x60}, {0x01, 0x61},
84 {0xC7, 0x62}, {0x01, 0x63},
85 {0xC7, 0x64}, {0x01, 0x65},
86 {0x44, 0x66}, {0x00, 0x67},
87 {0x44, 0x68}, {0x00, 0x69},
88 {0x44, 0x6A}, {0x00, 0x6B},
89 {0xC7, 0x6C}, {0x01, 0x6D},
90 {0xC7, 0x6E}, {0x01, 0x6F},
91 {0xC7, 0x70}, {0x01, 0x71},
92 {0x44, 0x72}, {0x00, 0x73},
93 {0x44, 0x74}, {0x00, 0x75},
94 {0x44, 0x76}, {0x00, 0x77},
95 {0xC7, 0x78}, {0x01, 0x79},
96 {0xC7, 0x7A}, {0x01, 0x7B},
97 {0xC7, 0x7C}, {0x01, 0x7D},
98 {0x44, 0x7E}, {0x00, 0x7F},
99 {0x14, 0x84}, {0x00, 0x85},
100 {0x27, 0x86}, {0x00, 0x87},
101 {0x07, 0x88}, {0x00, 0x89},
102 {0xEC, 0x8A}, {0x0f, 0x8B},
103 {0xD8, 0x8C}, {0x0f, 0x8D},
104 {0x3D, 0x8E}, {0x00, 0x8F},
105 {0x3D, 0x90}, {0x00, 0x91},
106 {0xCD, 0x92}, {0x0f, 0x93},
107 {0xf7, 0x94}, {0x0f, 0x95},
108 {0x0C, 0x96}, {0x00, 0x97},
109 {0x00, 0x98}, {0x66, 0x99},
110 {0x05, 0x9A}, {0x00, 0x9B},
111 {0x04, 0x9C}, {0x00, 0x9D},
112 {0x08, 0x9E}, {0x00, 0x9F},
113 {0x2D, 0xC0}, {0x2D, 0xC1},
114 {0x3A, 0xC2}, {0x05, 0xC3},
115 {0x04, 0xC4}, {0x3F, 0xC5},
116 {0x00, 0xC6}, {0x00, 0xC7},
117 {0x50, 0xC8}, {0x3C, 0xC9},
118 {0x28, 0xCA}, {0xD8, 0xCB},
119 {0x14, 0xCC}, {0xEC, 0xCD},
120 {0x32, 0xCE}, {0xDD, 0xCF},
121 {0x32, 0xD0}, {0xDD, 0xD1},
122 {0x6A, 0xD2}, {0x50, 0xD3},
123 {0x00, 0xD4}, {0x00, 0xD5},
124 {0x00, 0xD6});
125 break;
126 default:
127 break;
128 }
44 129
45 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x0d, 130 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 0x0d,
46 0x00, 0x01, 0, 0); 131 0x00, 0x01, 0, 0);
@@ -65,50 +150,50 @@ static int mi0360_get_ctrl(struct sn9c102_device* cam,
65 struct v4l2_control* ctrl) 150 struct v4l2_control* ctrl)
66{ 151{
67 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 152 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
68 u8 data[5+1]; 153 u8 data[2];
69 154
70 switch (ctrl->id) { 155 switch (ctrl->id) {
71 case V4L2_CID_EXPOSURE: 156 case V4L2_CID_EXPOSURE:
72 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 157 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x09, 2,
73 2+1, data) < 0) 158 data) < 0)
74 return -EIO; 159 return -EIO;
75 ctrl->value = data[2]; 160 ctrl->value = data[0];
76 return 0; 161 return 0;
77 case V4L2_CID_GAIN: 162 case V4L2_CID_GAIN:
78 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 163 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x35, 2,
79 2+1, data) < 0) 164 data) < 0)
80 return -EIO; 165 return -EIO;
81 ctrl->value = data[3]; 166 ctrl->value = data[1];
82 return 0; 167 return 0;
83 case V4L2_CID_RED_BALANCE: 168 case V4L2_CID_RED_BALANCE:
84 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 169 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2c, 2,
85 2+1, data) < 0) 170 data) < 0)
86 return -EIO; 171 return -EIO;
87 ctrl->value = data[3]; 172 ctrl->value = data[1];
88 return 0; 173 return 0;
89 case V4L2_CID_BLUE_BALANCE: 174 case V4L2_CID_BLUE_BALANCE:
90 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 175 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2d, 2,
91 2+1, data) < 0) 176 data) < 0)
92 return -EIO; 177 return -EIO;
93 ctrl->value = data[3]; 178 ctrl->value = data[1];
94 return 0; 179 return 0;
95 case SN9C102_V4L2_CID_GREEN_BALANCE: 180 case SN9C102_V4L2_CID_GREEN_BALANCE:
96 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 181 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x2e, 2,
97 2+1, data) < 0) 182 data) < 0)
98 return -EIO; 183 return -EIO;
99 ctrl->value = data[3]; 184 ctrl->value = data[1];
100 return 0; 185 return 0;
101 case V4L2_CID_HFLIP: 186 case V4L2_CID_HFLIP:
102 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 187 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
103 2+1, data) < 0) 188 data) < 0)
104 return -EIO; 189 return -EIO;
105 ctrl->value = data[3] & 0x20 ? 1 : 0; 190 ctrl->value = data[1] & 0x20 ? 1 : 0;
106 return 0; 191 return 0;
107 case V4L2_CID_VFLIP: 192 case V4L2_CID_VFLIP:
108 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 193 if (sn9c102_i2c_try_raw_read(cam, s, s->i2c_slave_id, 0x20, 2,
109 2+1, data) < 0) 194 data) < 0)
110 return -EIO; 195 return -EIO;
111 ctrl->value = data[3] & 0x80 ? 1 : 0; 196 ctrl->value = data[1] & 0x80 ? 1 : 0;
112 return 0; 197 return 0;
113 default: 198 default:
114 return -EINVAL; 199 return -EINVAL;
@@ -178,8 +263,19 @@ static int mi0360_set_crop(struct sn9c102_device* cam,
178{ 263{
179 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 264 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
180 int err = 0; 265 int err = 0;
181 u8 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 0, 266 u8 h_start = 0, v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1;
182 v_start = (u8)(rect->top - s->cropcap.bounds.top) + 1; 267
268 switch (sn9c102_get_bridge(cam)) {
269 case BRIDGE_SN9C103:
270 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 0;
271 break;
272 case BRIDGE_SN9C105:
273 case BRIDGE_SN9C120:
274 h_start = (u8)(rect->left - s->cropcap.bounds.left) + 1;
275 break;
276 default:
277 break;
278 }
183 279
184 err += sn9c102_write_reg(cam, h_start, 0x12); 280 err += sn9c102_write_reg(cam, h_start, 0x12);
185 err += sn9c102_write_reg(cam, v_start, 0x13); 281 err += sn9c102_write_reg(cam, v_start, 0x13);
@@ -194,24 +290,30 @@ static int mi0360_set_pix_format(struct sn9c102_device* cam,
194 struct sn9c102_sensor* s = sn9c102_get_sensor(cam); 290 struct sn9c102_sensor* s = sn9c102_get_sensor(cam);
195 int err = 0; 291 int err = 0;
196 292
197 if (pix->pixelformat == V4L2_PIX_FMT_SN9C10X) { 293 if (pix->pixelformat == V4L2_PIX_FMT_SBGGR8) {
198 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id,
199 0x0a, 0x00, 0x02, 0, 0);
200 err += sn9c102_write_reg(cam, 0x20, 0x19);
201 } else {
202 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id, 294 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id,
203 0x0a, 0x00, 0x05, 0, 0); 295 0x0a, 0x00, 0x05, 0, 0);
204 err += sn9c102_write_reg(cam, 0x60, 0x19); 296 err += sn9c102_write_reg(cam, 0x60, 0x19);
297 if (sn9c102_get_bridge(cam) == BRIDGE_SN9C105 ||
298 sn9c102_get_bridge(cam) == BRIDGE_SN9C120)
299 err += sn9c102_write_reg(cam, 0xa6, 0x17);
300 } else {
301 err += sn9c102_i2c_try_raw_write(cam, s, 4, s->i2c_slave_id,
302 0x0a, 0x00, 0x02, 0, 0);
303 err += sn9c102_write_reg(cam, 0x20, 0x19);
304 if (sn9c102_get_bridge(cam) == BRIDGE_SN9C105 ||
305 sn9c102_get_bridge(cam) == BRIDGE_SN9C120)
306 err += sn9c102_write_reg(cam, 0xa2, 0x17);
205 } 307 }
206 308
207 return err; 309 return err;
208} 310}
209 311
210 312
211static struct sn9c102_sensor mi0360 = { 313static const struct sn9c102_sensor mi0360 = {
212 .name = "MI-0360", 314 .name = "MI-0360",
213 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 315 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
214 .supported_bridge = BRIDGE_SN9C103, 316 .supported_bridge = BRIDGE_SN9C103 | BRIDGE_SN9C105 | BRIDGE_SN9C120,
215 .frequency = SN9C102_I2C_100KHZ, 317 .frequency = SN9C102_I2C_100KHZ,
216 .interface = SN9C102_I2C_2WIRES, 318 .interface = SN9C102_I2C_2WIRES,
217 .i2c_slave_id = 0x5d, 319 .i2c_slave_id = 0x5d,
@@ -317,19 +419,31 @@ static struct sn9c102_sensor mi0360 = {
317 419
318int sn9c102_probe_mi0360(struct sn9c102_device* cam) 420int sn9c102_probe_mi0360(struct sn9c102_device* cam)
319{ 421{
320 u8 data[5+1];
321 int err;
322 422
323 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01}, 423 u8 data[2];
324 {0x28, 0x17}); 424
325 if (err) 425 switch (sn9c102_get_bridge(cam)) {
326 return -EIO; 426 case BRIDGE_SN9C103:
427 if (sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
428 {0x28, 0x17}))
429 return -EIO;
430 break;
431 case BRIDGE_SN9C105:
432 case BRIDGE_SN9C120:
433 if (sn9c102_write_const_regs(cam, {0x01, 0xf1}, {0x00, 0xf1},
434 {0x01, 0x01}, {0x00, 0x01},
435 {0x28, 0x17}))
436 return -EIO;
437 break;
438 default:
439 break;
440 }
327 441
328 if (sn9c102_i2c_try_raw_read(cam, &mi0360, mi0360.i2c_slave_id, 0x00, 442 if (sn9c102_i2c_try_raw_read(cam, &mi0360, mi0360.i2c_slave_id, 0x00,
329 2+1, data) < 0) 443 2, data) < 0)
330 return -EIO; 444 return -EIO;
331 445
332 if (data[2] != 0x82 || data[3] != 0x43) 446 if (data[0] != 0x82 || data[1] != 0x43)
333 return -ENODEV; 447 return -ENODEV;
334 448
335 sn9c102_attach_sensor(cam, &mi0360); 449 sn9c102_attach_sensor(cam, &mi0360);
diff --git a/drivers/media/video/sn9c102/sn9c102_ov7630.c b/drivers/media/video/sn9c102/sn9c102_ov7630.c
index 31b6080b0615..e6832347894f 100644
--- a/drivers/media/video/sn9c102/sn9c102_ov7630.c
+++ b/drivers/media/video/sn9c102/sn9c102_ov7630.c
@@ -29,9 +29,8 @@ static int ov7630_init(struct sn9c102_device* cam)
29 switch (sn9c102_get_bridge(cam)) { 29 switch (sn9c102_get_bridge(cam)) {
30 case BRIDGE_SN9C101: 30 case BRIDGE_SN9C101:
31 case BRIDGE_SN9C102: 31 case BRIDGE_SN9C102:
32 err = sn9c102_write_const_regs(cam, {0x00, 0x14}, 32 err = sn9c102_write_const_regs(cam, {0x00, 0x14}, {0x60, 0x17},
33 {0x60, 0x17}, {0x0f, 0x18}, 33 {0x0f, 0x18}, {0x50, 0x19});
34 {0x50, 0x19});
35 34
36 err += sn9c102_i2c_write(cam, 0x12, 0x8d); 35 err += sn9c102_i2c_write(cam, 0x12, 0x8d);
37 err += sn9c102_i2c_write(cam, 0x12, 0x0d); 36 err += sn9c102_i2c_write(cam, 0x12, 0x0d);
@@ -61,7 +60,6 @@ static int ov7630_init(struct sn9c102_device* cam)
61 err += sn9c102_i2c_write(cam, 0x71, 0x00); 60 err += sn9c102_i2c_write(cam, 0x71, 0x00);
62 err += sn9c102_i2c_write(cam, 0x74, 0x21); 61 err += sn9c102_i2c_write(cam, 0x74, 0x21);
63 err += sn9c102_i2c_write(cam, 0x7d, 0xf7); 62 err += sn9c102_i2c_write(cam, 0x7d, 0xf7);
64
65 break; 63 break;
66 case BRIDGE_SN9C103: 64 case BRIDGE_SN9C103:
67 err = sn9c102_write_const_regs(cam, {0x00, 0x02}, {0x00, 0x03}, 65 err = sn9c102_write_const_regs(cam, {0x00, 0x02}, {0x00, 0x03},
@@ -253,7 +251,7 @@ static int ov7630_set_pix_format(struct sn9c102_device* cam,
253} 251}
254 252
255 253
256static struct sn9c102_sensor ov7630 = { 254static const struct sn9c102_sensor ov7630 = {
257 .name = "OV7630", 255 .name = "OV7630",
258 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 256 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
259 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103, 257 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
@@ -408,19 +406,16 @@ int sn9c102_probe_ov7630(struct sn9c102_device* cam)
408 switch (sn9c102_get_bridge(cam)) { 406 switch (sn9c102_get_bridge(cam)) {
409 case BRIDGE_SN9C101: 407 case BRIDGE_SN9C101:
410 case BRIDGE_SN9C102: 408 case BRIDGE_SN9C102:
411 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, 409 err = sn9c102_write_const_regs(cam, {0x01, 0x01}, {0x00, 0x01},
412 {0x00, 0x01}, {0x28, 0x17}); 410 {0x28, 0x17});
413
414 break; 411 break;
415 case BRIDGE_SN9C103: /* do _not_ change anything! */ 412 case BRIDGE_SN9C103: /* do _not_ change anything! */
416 err = sn9c102_write_const_regs(cam, {0x09, 0x01}, 413 err = sn9c102_write_const_regs(cam, {0x09, 0x01}, {0x42, 0x01},
417 {0x42, 0x01}, {0x28, 0x17}, 414 {0x28, 0x17}, {0x44, 0x02});
418 {0x44, 0x02});
419 pid = sn9c102_i2c_try_read(cam, &ov7630, 0x0a); 415 pid = sn9c102_i2c_try_read(cam, &ov7630, 0x0a);
420 if (err || pid < 0) { /* try a different initialization */ 416 if (err || pid < 0) /* try a different initialization */
421 err = sn9c102_write_reg(cam, 0x01, 0x01); 417 err += sn9c102_write_const_regs(cam, {0x01, 0x01},
422 err += sn9c102_write_reg(cam, 0x00, 0x01); 418 {0x00, 0x01});
423 }
424 break; 419 break;
425 default: 420 default:
426 break; 421 break;
diff --git a/drivers/media/video/sn9c102/sn9c102_ov7660.c b/drivers/media/video/sn9c102/sn9c102_ov7660.c
index c898e948fe8d..4b6474048a72 100644
--- a/drivers/media/video/sn9c102/sn9c102_ov7660.c
+++ b/drivers/media/video/sn9c102/sn9c102_ov7660.c
@@ -104,8 +104,8 @@ static int ov7660_init(struct sn9c102_device* cam)
104 err += sn9c102_i2c_write(cam, 0x12, 0x80); 104 err += sn9c102_i2c_write(cam, 0x12, 0x80);
105 err += sn9c102_i2c_write(cam, 0x11, 0x09); 105 err += sn9c102_i2c_write(cam, 0x11, 0x09);
106 err += sn9c102_i2c_write(cam, 0x00, 0x0A); 106 err += sn9c102_i2c_write(cam, 0x00, 0x0A);
107 err += sn9c102_i2c_write(cam, 0x01, 0x78); 107 err += sn9c102_i2c_write(cam, 0x01, 0x80);
108 err += sn9c102_i2c_write(cam, 0x02, 0x90); 108 err += sn9c102_i2c_write(cam, 0x02, 0x80);
109 err += sn9c102_i2c_write(cam, 0x03, 0x00); 109 err += sn9c102_i2c_write(cam, 0x03, 0x00);
110 err += sn9c102_i2c_write(cam, 0x04, 0x00); 110 err += sn9c102_i2c_write(cam, 0x04, 0x00);
111 err += sn9c102_i2c_write(cam, 0x05, 0x08); 111 err += sn9c102_i2c_write(cam, 0x05, 0x08);
@@ -122,7 +122,7 @@ static int ov7660_init(struct sn9c102_device* cam)
122 err += sn9c102_i2c_write(cam, 0x10, 0x20); 122 err += sn9c102_i2c_write(cam, 0x10, 0x20);
123 err += sn9c102_i2c_write(cam, 0x11, 0x03); 123 err += sn9c102_i2c_write(cam, 0x11, 0x03);
124 err += sn9c102_i2c_write(cam, 0x12, 0x05); 124 err += sn9c102_i2c_write(cam, 0x12, 0x05);
125 err += sn9c102_i2c_write(cam, 0x13, 0xF8); 125 err += sn9c102_i2c_write(cam, 0x13, 0xC7);
126 err += sn9c102_i2c_write(cam, 0x14, 0x2C); 126 err += sn9c102_i2c_write(cam, 0x14, 0x2C);
127 err += sn9c102_i2c_write(cam, 0x15, 0x00); 127 err += sn9c102_i2c_write(cam, 0x15, 0x00);
128 err += sn9c102_i2c_write(cam, 0x16, 0x02); 128 err += sn9c102_i2c_write(cam, 0x16, 0x02);
@@ -162,7 +162,7 @@ static int ov7660_init(struct sn9c102_device* cam)
162 err += sn9c102_i2c_write(cam, 0x38, 0x02); 162 err += sn9c102_i2c_write(cam, 0x38, 0x02);
163 err += sn9c102_i2c_write(cam, 0x39, 0x43); 163 err += sn9c102_i2c_write(cam, 0x39, 0x43);
164 err += sn9c102_i2c_write(cam, 0x3A, 0x00); 164 err += sn9c102_i2c_write(cam, 0x3A, 0x00);
165 err += sn9c102_i2c_write(cam, 0x3B, 0x02); 165 err += sn9c102_i2c_write(cam, 0x3B, 0x0A);
166 err += sn9c102_i2c_write(cam, 0x3C, 0x6C); 166 err += sn9c102_i2c_write(cam, 0x3C, 0x6C);
167 err += sn9c102_i2c_write(cam, 0x3D, 0x99); 167 err += sn9c102_i2c_write(cam, 0x3D, 0x99);
168 err += sn9c102_i2c_write(cam, 0x3E, 0x0E); 168 err += sn9c102_i2c_write(cam, 0x3E, 0x0E);
@@ -281,25 +281,34 @@ static int ov7660_get_ctrl(struct sn9c102_device* cam,
281 return -EIO; 281 return -EIO;
282 break; 282 break;
283 case V4L2_CID_DO_WHITE_BALANCE: 283 case V4L2_CID_DO_WHITE_BALANCE:
284 ctrl->value = sn9c102_pread_reg(cam, 0x02); 284 if ((ctrl->value = sn9c102_read_reg(cam, 0x02)) < 0)
285 return -EIO;
285 ctrl->value = (ctrl->value & 0x04) ? 1 : 0; 286 ctrl->value = (ctrl->value & 0x04) ? 1 : 0;
286 break; 287 break;
287 case V4L2_CID_RED_BALANCE: 288 case V4L2_CID_RED_BALANCE:
288 ctrl->value = sn9c102_pread_reg(cam, 0x05); 289 if ((ctrl->value = sn9c102_read_reg(cam, 0x05)) < 0)
290 return -EIO;
289 ctrl->value &= 0x7f; 291 ctrl->value &= 0x7f;
290 break; 292 break;
291 case V4L2_CID_BLUE_BALANCE: 293 case V4L2_CID_BLUE_BALANCE:
292 ctrl->value = sn9c102_pread_reg(cam, 0x06); 294 if ((ctrl->value = sn9c102_read_reg(cam, 0x06)) < 0)
295 return -EIO;
293 ctrl->value &= 0x7f; 296 ctrl->value &= 0x7f;
294 break; 297 break;
295 case SN9C102_V4L2_CID_GREEN_BALANCE: 298 case SN9C102_V4L2_CID_GREEN_BALANCE:
296 ctrl->value = sn9c102_pread_reg(cam, 0x07); 299 if ((ctrl->value = sn9c102_read_reg(cam, 0x07)) < 0)
300 return -EIO;
297 ctrl->value &= 0x7f; 301 ctrl->value &= 0x7f;
298 break; 302 break;
303 case SN9C102_V4L2_CID_BAND_FILTER:
304 if ((ctrl->value = sn9c102_i2c_read(cam, 0x3b)) < 0)
305 return -EIO;
306 ctrl->value &= 0x08;
307 break;
299 case V4L2_CID_GAIN: 308 case V4L2_CID_GAIN:
300 if ((ctrl->value = sn9c102_i2c_read(cam, 0x00)) < 0) 309 if ((ctrl->value = sn9c102_i2c_read(cam, 0x00)) < 0)
301 return -EIO; 310 return -EIO;
302 ctrl->value &= 0x7f; 311 ctrl->value &= 0x1f;
303 break; 312 break;
304 case V4L2_CID_AUTOGAIN: 313 case V4L2_CID_AUTOGAIN:
305 if ((ctrl->value = sn9c102_i2c_read(cam, 0x13)) < 0) 314 if ((ctrl->value = sn9c102_i2c_read(cam, 0x13)) < 0)
@@ -335,12 +344,15 @@ static int ov7660_set_ctrl(struct sn9c102_device* cam,
335 case SN9C102_V4L2_CID_GREEN_BALANCE: 344 case SN9C102_V4L2_CID_GREEN_BALANCE:
336 err += sn9c102_write_reg(cam, ctrl->value, 0x07); 345 err += sn9c102_write_reg(cam, ctrl->value, 0x07);
337 break; 346 break;
347 case SN9C102_V4L2_CID_BAND_FILTER:
348 err += sn9c102_i2c_write(cam, ctrl->value << 3, 0x3b);
349 break;
338 case V4L2_CID_GAIN: 350 case V4L2_CID_GAIN:
339 err += sn9c102_i2c_write(cam, 0x00, ctrl->value); 351 err += sn9c102_i2c_write(cam, 0x00, 0x60 + ctrl->value);
340 break; 352 break;
341 case V4L2_CID_AUTOGAIN: 353 case V4L2_CID_AUTOGAIN:
342 err += sn9c102_i2c_write(cam, 0x13, 0xf0 | ctrl->value | 354 err += sn9c102_i2c_write(cam, 0x13, 0xc0 |
343 (ctrl->value << 1)); 355 (ctrl->value * 0x07));
344 break; 356 break;
345 default: 357 default:
346 return -EINVAL; 358 return -EINVAL;
@@ -386,7 +398,7 @@ static int ov7660_set_pix_format(struct sn9c102_device* cam,
386} 398}
387 399
388 400
389static struct sn9c102_sensor ov7660 = { 401static const struct sn9c102_sensor ov7660 = {
390 .name = "OV7660", 402 .name = "OV7660",
391 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 403 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
392 .supported_bridge = BRIDGE_SN9C105 | BRIDGE_SN9C120, 404 .supported_bridge = BRIDGE_SN9C105 | BRIDGE_SN9C120,
@@ -401,9 +413,9 @@ static struct sn9c102_sensor ov7660 = {
401 .type = V4L2_CTRL_TYPE_INTEGER, 413 .type = V4L2_CTRL_TYPE_INTEGER,
402 .name = "global gain", 414 .name = "global gain",
403 .minimum = 0x00, 415 .minimum = 0x00,
404 .maximum = 0x7f, 416 .maximum = 0x1f,
405 .step = 0x01, 417 .step = 0x01,
406 .default_value = 0x0a, 418 .default_value = 0x09,
407 .flags = 0, 419 .flags = 0,
408 }, 420 },
409 { 421 {
@@ -413,7 +425,7 @@ static struct sn9c102_sensor ov7660 = {
413 .minimum = 0x00, 425 .minimum = 0x00,
414 .maximum = 0xff, 426 .maximum = 0xff,
415 .step = 0x01, 427 .step = 0x01,
416 .default_value = 0x50, 428 .default_value = 0x27,
417 .flags = 0, 429 .flags = 0,
418 }, 430 },
419 { 431 {
@@ -433,7 +445,7 @@ static struct sn9c102_sensor ov7660 = {
433 .minimum = 0x00, 445 .minimum = 0x00,
434 .maximum = 0x7f, 446 .maximum = 0x7f,
435 .step = 0x01, 447 .step = 0x01,
436 .default_value = 0x1f, 448 .default_value = 0x14,
437 .flags = 0, 449 .flags = 0,
438 }, 450 },
439 { 451 {
@@ -443,7 +455,7 @@ static struct sn9c102_sensor ov7660 = {
443 .minimum = 0x00, 455 .minimum = 0x00,
444 .maximum = 0x7f, 456 .maximum = 0x7f,
445 .step = 0x01, 457 .step = 0x01,
446 .default_value = 0x1e, 458 .default_value = 0x14,
447 .flags = 0, 459 .flags = 0,
448 }, 460 },
449 { 461 {
@@ -453,7 +465,7 @@ static struct sn9c102_sensor ov7660 = {
453 .minimum = 0x00, 465 .minimum = 0x00,
454 .maximum = 0x01, 466 .maximum = 0x01,
455 .step = 0x01, 467 .step = 0x01,
456 .default_value = 0x00, 468 .default_value = 0x01,
457 .flags = 0, 469 .flags = 0,
458 }, 470 },
459 { 471 {
@@ -463,7 +475,17 @@ static struct sn9c102_sensor ov7660 = {
463 .minimum = 0x00, 475 .minimum = 0x00,
464 .maximum = 0x7f, 476 .maximum = 0x7f,
465 .step = 0x01, 477 .step = 0x01,
466 .default_value = 0x20, 478 .default_value = 0x14,
479 .flags = 0,
480 },
481 {
482 .id = SN9C102_V4L2_CID_BAND_FILTER,
483 .type = V4L2_CTRL_TYPE_BOOLEAN,
484 .name = "band filter",
485 .minimum = 0x00,
486 .maximum = 0x01,
487 .step = 0x01,
488 .default_value = 0x00,
467 .flags = 0, 489 .flags = 0,
468 }, 490 },
469 }, 491 },
@@ -508,6 +530,7 @@ int sn9c102_probe_ov7660(struct sn9c102_device* cam)
508 return -EIO; 530 return -EIO;
509 if (pid != 0x76 || ver != 0x60) 531 if (pid != 0x76 || ver != 0x60)
510 return -ENODEV; 532 return -ENODEV;
533
511 sn9c102_attach_sensor(cam, &ov7660); 534 sn9c102_attach_sensor(cam, &ov7660);
512 535
513 return 0; 536 return 0;
diff --git a/drivers/media/video/sn9c102/sn9c102_pas106b.c b/drivers/media/video/sn9c102/sn9c102_pas106b.c
index 67151964801f..360f2a848bc0 100644
--- a/drivers/media/video/sn9c102/sn9c102_pas106b.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas106b.c
@@ -163,7 +163,7 @@ static int pas106b_set_pix_format(struct sn9c102_device* cam,
163} 163}
164 164
165 165
166static struct sn9c102_sensor pas106b = { 166static const struct sn9c102_sensor pas106b = {
167 .name = "PAS106B", 167 .name = "PAS106B",
168 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 168 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
169 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 169 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
@@ -273,23 +273,21 @@ static struct sn9c102_sensor pas106b = {
273 273
274int sn9c102_probe_pas106b(struct sn9c102_device* cam) 274int sn9c102_probe_pas106b(struct sn9c102_device* cam)
275{ 275{
276 int r0 = 0, r1 = 0, err; 276 int r0 = 0, r1 = 0;
277 unsigned int pid = 0; 277 unsigned int pid = 0;
278 278
279 /* 279 /*
280 Minimal initialization to enable the I2C communication 280 Minimal initialization to enable the I2C communication
281 NOTE: do NOT change the values! 281 NOTE: do NOT change the values!
282 */ 282 */
283 err = sn9c102_write_const_regs(cam, 283 if (sn9c102_write_const_regs(cam,
284 {0x01, 0x01}, /* sensor power down */ 284 {0x01, 0x01}, /* sensor power down */
285 {0x00, 0x01}, /* sensor power on */ 285 {0x00, 0x01}, /* sensor power on */
286 {0x28, 0x17});/* sensor clock 24 MHz */ 286 {0x28, 0x17})) /* sensor clock at 24 MHz */
287 if (err)
288 return -EIO; 287 return -EIO;
289 288
290 r0 = sn9c102_i2c_try_read(cam, &pas106b, 0x00); 289 r0 = sn9c102_i2c_try_read(cam, &pas106b, 0x00);
291 r1 = sn9c102_i2c_try_read(cam, &pas106b, 0x01); 290 r1 = sn9c102_i2c_try_read(cam, &pas106b, 0x01);
292
293 if (r0 < 0 || r1 < 0) 291 if (r0 < 0 || r1 < 0)
294 return -EIO; 292 return -EIO;
295 293
diff --git a/drivers/media/video/sn9c102/sn9c102_pas202bcb.c b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
index c1b8d6b63b47..ca4a1506ed3d 100644
--- a/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
@@ -35,29 +35,28 @@ static int pas202bcb_init(struct sn9c102_device* cam)
35 switch (sn9c102_get_bridge(cam)) { 35 switch (sn9c102_get_bridge(cam)) {
36 case BRIDGE_SN9C101: 36 case BRIDGE_SN9C101:
37 case BRIDGE_SN9C102: 37 case BRIDGE_SN9C102:
38 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, 38 err = sn9c102_write_const_regs(cam, {0x00, 0x10}, {0x00, 0x11},
39 {0x00, 0x11}, {0x00, 0x14}, 39 {0x00, 0x14}, {0x20, 0x17},
40 {0x20, 0x17}, {0x30, 0x19}, 40 {0x30, 0x19}, {0x09, 0x18});
41 {0x09, 0x18});
42 break; 41 break;
43 case BRIDGE_SN9C103: 42 case BRIDGE_SN9C103:
44 err = sn9c102_write_const_regs(cam, {0x00, 0x02}, 43 err = sn9c102_write_const_regs(cam, {0x00, 0x02}, {0x00, 0x03},
45 {0x00, 0x03}, {0x1a, 0x04}, 44 {0x1a, 0x04}, {0x20, 0x05},
46 {0x20, 0x05}, {0x20, 0x06}, 45 {0x20, 0x06}, {0x20, 0x07},
47 {0x20, 0x07}, {0x00, 0x10}, 46 {0x00, 0x10}, {0x00, 0x11},
48 {0x00, 0x11}, {0x00, 0x14}, 47 {0x00, 0x14}, {0x20, 0x17},
49 {0x20, 0x17}, {0x30, 0x19}, 48 {0x30, 0x19}, {0x09, 0x18},
50 {0x09, 0x18}, {0x02, 0x1c}, 49 {0x02, 0x1c}, {0x03, 0x1d},
51 {0x03, 0x1d}, {0x0f, 0x1e}, 50 {0x0f, 0x1e}, {0x0c, 0x1f},
52 {0x0c, 0x1f}, {0x00, 0x20}, 51 {0x00, 0x20}, {0x10, 0x21},
53 {0x10, 0x21}, {0x20, 0x22}, 52 {0x20, 0x22}, {0x30, 0x23},
54 {0x30, 0x23}, {0x40, 0x24}, 53 {0x40, 0x24}, {0x50, 0x25},
55 {0x50, 0x25}, {0x60, 0x26}, 54 {0x60, 0x26}, {0x70, 0x27},
56 {0x70, 0x27}, {0x80, 0x28}, 55 {0x80, 0x28}, {0x90, 0x29},
57 {0x90, 0x29}, {0xa0, 0x2a}, 56 {0xa0, 0x2a}, {0xb0, 0x2b},
58 {0xb0, 0x2b}, {0xc0, 0x2c}, 57 {0xc0, 0x2c}, {0xd0, 0x2d},
59 {0xd0, 0x2d}, {0xe0, 0x2e}, 58 {0xe0, 0x2e}, {0xf0, 0x2f},
60 {0xf0, 0x2f}, {0xff, 0x30}); 59 {0xff, 0x30});
61 break; 60 break;
62 default: 61 default:
63 break; 62 break;
@@ -197,7 +196,7 @@ static int pas202bcb_set_crop(struct sn9c102_device* cam,
197} 196}
198 197
199 198
200static struct sn9c102_sensor pas202bcb = { 199static const struct sn9c102_sensor pas202bcb = {
201 .name = "PAS202BCB", 200 .name = "PAS202BCB",
202 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 201 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
203 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103, 202 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102 | BRIDGE_SN9C103,
@@ -313,9 +312,8 @@ int sn9c102_probe_pas202bcb(struct sn9c102_device* cam)
313 {0x28, 0x17});/* clock 24 MHz */ 312 {0x28, 0x17});/* clock 24 MHz */
314 break; 313 break;
315 case BRIDGE_SN9C103: /* do _not_ change anything! */ 314 case BRIDGE_SN9C103: /* do _not_ change anything! */
316 err = sn9c102_write_const_regs(cam, {0x09, 0x01}, 315 err = sn9c102_write_const_regs(cam, {0x09, 0x01}, {0x44, 0x01},
317 {0x44, 0x01}, {0x44, 0x02}, 316 {0x44, 0x02}, {0x29, 0x17});
318 {0x29, 0x17});
319 break; 317 break;
320 default: 318 default:
321 break; 319 break;
diff --git a/drivers/media/video/sn9c102/sn9c102_sensor.h b/drivers/media/video/sn9c102/sn9c102_sensor.h
index 1bbf64c897a2..2d7d786b8430 100644
--- a/drivers/media/video/sn9c102/sn9c102_sensor.h
+++ b/drivers/media/video/sn9c102/sn9c102_sensor.h
@@ -22,7 +22,7 @@
22#define _SN9C102_SENSOR_H_ 22#define _SN9C102_SENSOR_H_
23 23
24#include <linux/usb.h> 24#include <linux/usb.h>
25#include <linux/videodev.h> 25#include <linux/videodev2.h>
26#include <linux/device.h> 26#include <linux/device.h>
27#include <linux/stddef.h> 27#include <linux/stddef.h>
28#include <linux/errno.h> 28#include <linux/errno.h>
@@ -74,7 +74,7 @@ sn9c102_match_id(struct sn9c102_device* cam, const struct usb_device_id *id);
74/* Attach a probed sensor to the camera. */ 74/* Attach a probed sensor to the camera. */
75extern void 75extern void
76sn9c102_attach_sensor(struct sn9c102_device* cam, 76sn9c102_attach_sensor(struct sn9c102_device* cam,
77 struct sn9c102_sensor* sensor); 77 const struct sn9c102_sensor* sensor);
78 78
79/* 79/*
80 Read/write routines: they always return -1 on error, 0 or the read value 80 Read/write routines: they always return -1 on error, 0 or the read value
@@ -85,10 +85,11 @@ sn9c102_attach_sensor(struct sn9c102_device* cam,
85*/ 85*/
86 86
87/* The "try" I2C I/O versions are used when probing the sensor */ 87/* The "try" I2C I/O versions are used when probing the sensor */
88extern int sn9c102_i2c_try_write(struct sn9c102_device*,struct sn9c102_sensor*, 88extern int sn9c102_i2c_try_write(struct sn9c102_device*,
89 u8 address, u8 value); 89 const struct sn9c102_sensor*, u8 address,
90extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*, 90 u8 value);
91 u8 address); 91extern int sn9c102_i2c_try_read(struct sn9c102_device*,
92 const struct sn9c102_sensor*, u8 address);
92 93
93/* 94/*
94 These must be used if and only if the sensor doesn't implement the standard 95 These must be used if and only if the sensor doesn't implement the standard
@@ -102,29 +103,31 @@ extern int sn9c102_i2c_try_read(struct sn9c102_device*,struct sn9c102_sensor*,
102 byte. 103 byte.
103*/ 104*/
104extern int sn9c102_i2c_try_raw_write(struct sn9c102_device* cam, 105extern int sn9c102_i2c_try_raw_write(struct sn9c102_device* cam,
105 struct sn9c102_sensor* sensor, u8 n, 106 const struct sn9c102_sensor* sensor, u8 n,
106 u8 data0, u8 data1, u8 data2, u8 data3, 107 u8 data0, u8 data1, u8 data2, u8 data3,
107 u8 data4, u8 data5); 108 u8 data4, u8 data5);
108extern int sn9c102_i2c_try_raw_read(struct sn9c102_device* cam, 109extern int sn9c102_i2c_try_raw_read(struct sn9c102_device* cam,
109 struct sn9c102_sensor* sensor, u8 data0, 110 const struct sn9c102_sensor* sensor,
110 u8 data1, u8 n, u8 buffer[]); 111 u8 data0, u8 data1, u8 n, u8 buffer[]);
111 112
112/* To be used after the sensor struct has been attached to the camera struct */ 113/* To be used after the sensor struct has been attached to the camera struct */
113extern int sn9c102_i2c_write(struct sn9c102_device*, u8 address, u8 value); 114extern int sn9c102_i2c_write(struct sn9c102_device*, u8 address, u8 value);
114extern int sn9c102_i2c_read(struct sn9c102_device*, u8 address); 115extern int sn9c102_i2c_read(struct sn9c102_device*, u8 address);
115 116
116/* I/O on registers in the bridge. Could be used by the sensor methods too */ 117/* I/O on registers in the bridge. Could be used by the sensor methods too */
118extern int sn9c102_read_reg(struct sn9c102_device*, u16 index);
117extern int sn9c102_pread_reg(struct sn9c102_device*, u16 index); 119extern int sn9c102_pread_reg(struct sn9c102_device*, u16 index);
118extern int sn9c102_write_reg(struct sn9c102_device*, u8 value, u16 index); 120extern int sn9c102_write_reg(struct sn9c102_device*, u8 value, u16 index);
119extern int sn9c102_write_regs(struct sn9c102_device*, const u8 valreg[][2], 121extern int sn9c102_write_regs(struct sn9c102_device*, const u8 valreg[][2],
120 int count); 122 int count);
121/* 123/*
122 * Write multiple registers with constant values. For example: 124 Write multiple registers with constant values. For example:
123 * sn9c102_write_const_regs(cam, {0x00, 0x14}, {0x60, 0x17}, {0x0f, 0x18}); 125 sn9c102_write_const_regs(cam, {0x00, 0x14}, {0x60, 0x17}, {0x0f, 0x18});
124 */ 126 Register adresses must be < 256.
125#define sn9c102_write_const_regs(device, data...) \ 127*/
126 ({ const static u8 _data[][2] = {data}; \ 128#define sn9c102_write_const_regs(sn9c102_device, data...) \
127 sn9c102_write_regs(device, _data, ARRAY_SIZE(_data)); }) 129 ({ const static u8 _valreg[][2] = {data}; \
130 sn9c102_write_regs(sn9c102_device, _valreg, ARRAY_SIZE(_valreg)); })
128 131
129/*****************************************************************************/ 132/*****************************************************************************/
130 133
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
index 0e7ec8662c70..e7d2de2bace1 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
@@ -88,7 +88,7 @@ static int tas5110c1b_set_pix_format(struct sn9c102_device* cam,
88} 88}
89 89
90 90
91static struct sn9c102_sensor tas5110c1b = { 91static const struct sn9c102_sensor tas5110c1b = {
92 .name = "TAS5110C1B", 92 .name = "TAS5110C1B",
93 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 93 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
94 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 94 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5110d.c b/drivers/media/video/sn9c102/sn9c102_tas5110d.c
index 83a39e8b5e71..d32fdbccdc5e 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5110d.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5110d.c
@@ -68,7 +68,7 @@ static int tas5110d_set_pix_format(struct sn9c102_device* cam,
68} 68}
69 69
70 70
71static struct sn9c102_sensor tas5110d = { 71static const struct sn9c102_sensor tas5110d = {
72 .name = "TAS5110D", 72 .name = "TAS5110D",
73 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 73 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
74 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 74 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
index 50406503fc40..56fb1d575a8a 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
@@ -89,7 +89,7 @@ static int tas5130d1b_set_pix_format(struct sn9c102_device* cam,
89} 89}
90 90
91 91
92static struct sn9c102_sensor tas5130d1b = { 92static const struct sn9c102_sensor tas5130d1b = {
93 .name = "TAS5130D1B", 93 .name = "TAS5130D1B",
94 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>", 94 .maintainer = "Luca Risolia <luca.risolia@studio.unibo.it>",
95 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102, 95 .supported_bridge = BRIDGE_SN9C101 | BRIDGE_SN9C102,
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index 1b9b0742f753..c40b92ce1fad 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -205,9 +205,13 @@ static void default_set_tv_freq(struct i2c_client *c, unsigned int freq)
205 /* 0x01 -> ??? no change ??? */ 205 /* 0x01 -> ??? no change ??? */
206 /* 0x02 -> PAL BDGHI / SECAM L */ 206 /* 0x02 -> PAL BDGHI / SECAM L */
207 /* 0x04 -> ??? PAL others / SECAM others ??? */ 207 /* 0x04 -> ??? PAL others / SECAM others ??? */
208 cb &= ~0x02; 208 cb &= ~0x03;
209 if (t->std & V4L2_STD_SECAM) 209 if (t->std & V4L2_STD_SECAM_L) //also valid for V4L2_STD_SECAM
210 cb |= 0x02; 210 cb |= PHILIPS_MF_SET_PAL_L;
211 else if (t->std & V4L2_STD_SECAM_LC)
212 cb |= PHILIPS_MF_SET_PAL_L2;
213 else /* V4L2_STD_B|V4L2_STD_GH */
214 cb |= PHILIPS_MF_SET_BG;
211 break; 215 break;
212 216
213 case TUNER_TEMIC_4046FM5: 217 case TUNER_TEMIC_4046FM5:
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index a2da5d2affff..c9bf9dbc2ea3 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -26,7 +26,6 @@
26#include <linux/videodev.h> 26#include <linux/videodev.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/smp_lock.h>
30#include <linux/kthread.h> 29#include <linux/kthread.h>
31#include <linux/freezer.h> 30#include <linux/freezer.h>
32 31
diff --git a/drivers/media/video/usbvideo/Kconfig b/drivers/media/video/usbvideo/Kconfig
index a0fd82b924f2..e4cb99c1f94b 100644
--- a/drivers/media/video/usbvideo/Kconfig
+++ b/drivers/media/video/usbvideo/Kconfig
@@ -3,7 +3,7 @@ config VIDEO_USBVIDEO
3 3
4config USB_VICAM 4config USB_VICAM
5 tristate "USB 3com HomeConnect (aka vicam) support (EXPERIMENTAL)" 5 tristate "USB 3com HomeConnect (aka vicam) support (EXPERIMENTAL)"
6 depends on USB && VIDEO_DEV && VIDEO_V4L1 && EXPERIMENTAL 6 depends on VIDEO_V4L1 && EXPERIMENTAL
7 select VIDEO_USBVIDEO 7 select VIDEO_USBVIDEO
8 ---help--- 8 ---help---
9 Say Y here if you have 3com homeconnect camera (vicam). 9 Say Y here if you have 3com homeconnect camera (vicam).
@@ -13,7 +13,7 @@ config USB_VICAM
13 13
14config USB_IBMCAM 14config USB_IBMCAM
15 tristate "USB IBM (Xirlink) C-it Camera support" 15 tristate "USB IBM (Xirlink) C-it Camera support"
16 depends on USB && VIDEO_DEV && VIDEO_V4L1 16 depends on VIDEO_V4L1
17 select VIDEO_USBVIDEO 17 select VIDEO_USBVIDEO
18 ---help--- 18 ---help---
19 Say Y here if you want to connect a IBM "C-It" camera, also known as 19 Say Y here if you want to connect a IBM "C-It" camera, also known as
@@ -28,7 +28,7 @@ config USB_IBMCAM
28 28
29config USB_KONICAWC 29config USB_KONICAWC
30 tristate "USB Konica Webcam support" 30 tristate "USB Konica Webcam support"
31 depends on USB && VIDEO_DEV && VIDEO_V4L1 31 depends on VIDEO_V4L1
32 select VIDEO_USBVIDEO 32 select VIDEO_USBVIDEO
33 ---help--- 33 ---help---
34 Say Y here if you want support for webcams based on a Konica 34 Say Y here if you want support for webcams based on a Konica
@@ -39,7 +39,7 @@ config USB_KONICAWC
39 39
40config USB_QUICKCAM_MESSENGER 40config USB_QUICKCAM_MESSENGER
41 tristate "USB Logitech Quickcam Messenger" 41 tristate "USB Logitech Quickcam Messenger"
42 depends on USB && VIDEO_DEV && VIDEO_V4L1 42 depends on VIDEO_V4L1
43 select VIDEO_USBVIDEO 43 select VIDEO_USBVIDEO
44 ---help--- 44 ---help---
45 Say Y or M here to enable support for the USB Logitech Quickcam 45 Say Y or M here to enable support for the USB Logitech Quickcam
diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
index 687f026753b2..37ce36b9e587 100644
--- a/drivers/media/video/usbvideo/usbvideo.c
+++ b/drivers/media/video/usbvideo/usbvideo.c
@@ -20,7 +20,6 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/mm.h> 22#include <linux/mm.h>
23#include <linux/smp_lock.h>
24#include <linux/vmalloc.h> 23#include <linux/vmalloc.h>
25#include <linux/init.h> 24#include <linux/init.h>
26#include <linux/spinlock.h> 25#include <linux/spinlock.h>
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/media/video/usbvideo/vicam.c
index 876fd2768242..982b115193f8 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -28,7 +28,7 @@
28 * 28 *
29 * Portions of this code were also copied from usbvideo.c 29 * Portions of this code were also copied from usbvideo.c
30 * 30 *
31 * Special thanks to the the whole team at Sourceforge for help making 31 * Special thanks to the whole team at Sourceforge for help making
32 * this driver become a reality. Notably: 32 * this driver become a reality. Notably:
33 * Andy Armstrong who reverse engineered the color encoding and 33 * Andy Armstrong who reverse engineered the color encoding and
34 * Pavel Machek and Chris Cheney who worked on reverse engineering the 34 * Pavel Machek and Chris Cheney who worked on reverse engineering the
diff --git a/drivers/media/video/usbvision/Kconfig b/drivers/media/video/usbvision/Kconfig
index c43a5d899091..fc24ef05b3f3 100644
--- a/drivers/media/video/usbvision/Kconfig
+++ b/drivers/media/video/usbvision/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_USBVISION 1config VIDEO_USBVISION
2 tristate "USB video devices based on Nogatech NT1003/1004/1005" 2 tristate "USB video devices based on Nogatech NT1003/1004/1005"
3 depends on I2C && VIDEO_V4L2 && USB 3 depends on I2C && VIDEO_V4L2
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO 5 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
6 ---help--- 6 ---help---
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index bcb551adb7e6..9118a6227ea6 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -30,7 +30,6 @@
30#include <linux/mm.h> 30#include <linux/mm.h>
31#include <linux/utsname.h> 31#include <linux/utsname.h>
32#include <linux/highmem.h> 32#include <linux/highmem.h>
33#include <linux/smp_lock.h>
34#include <linux/videodev.h> 33#include <linux/videodev.h>
35#include <linux/vmalloc.h> 34#include <linux/vmalloc.h>
36#include <linux/module.h> 35#include <linux/module.h>
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index 216704170a4c..aa3258bbb4af 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -52,7 +52,6 @@
52#include <linux/mm.h> 52#include <linux/mm.h>
53#include <linux/utsname.h> 53#include <linux/utsname.h>
54#include <linux/highmem.h> 54#include <linux/highmem.h>
55#include <linux/smp_lock.h>
56#include <linux/videodev.h> 55#include <linux/videodev.h>
57#include <linux/vmalloc.h> 56#include <linux/vmalloc.h>
58#include <linux/module.h> 57#include <linux/module.h>
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index d2c1ae0dbfba..ede8543818bf 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -23,7 +23,6 @@
23#include <linux/types.h> 23#include <linux/types.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/sched.h> 25#include <linux/sched.h>
26#include <linux/smp_lock.h>
27#include <linux/mm.h> 26#include <linux/mm.h>
28#include <linux/fs.h> 27#include <linux/fs.h>
29#include <linux/file.h> 28#include <linux/file.h>
@@ -128,7 +127,7 @@ set_v4l_control(struct inode *inode,
128 127
129/* ----------------------------------------------------------------- */ 128/* ----------------------------------------------------------------- */
130 129
131static int palette2pixelformat[] = { 130const static unsigned int palette2pixelformat[] = {
132 [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY, 131 [VIDEO_PALETTE_GREY] = V4L2_PIX_FMT_GREY,
133 [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555, 132 [VIDEO_PALETTE_RGB555] = V4L2_PIX_FMT_RGB555,
134 [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565, 133 [VIDEO_PALETTE_RGB565] = V4L2_PIX_FMT_RGB565,
@@ -146,7 +145,7 @@ static int palette2pixelformat[] = {
146 [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P, 145 [VIDEO_PALETTE_YUV422P] = V4L2_PIX_FMT_YUV422P,
147}; 146};
148 147
149static unsigned int 148static unsigned int __attribute_pure__
150palette_to_pixelformat(unsigned int palette) 149palette_to_pixelformat(unsigned int palette)
151{ 150{
152 if (palette < ARRAY_SIZE(palette2pixelformat)) 151 if (palette < ARRAY_SIZE(palette2pixelformat))
@@ -155,8 +154,8 @@ palette_to_pixelformat(unsigned int palette)
155 return 0; 154 return 0;
156} 155}
157 156
158static unsigned int 157static unsigned int __attribute_const__
159pixelformat_to_palette(int pixelformat) 158pixelformat_to_palette(unsigned int pixelformat)
160{ 159{
161 int palette = 0; 160 int palette = 0;
162 switch (pixelformat) 161 switch (pixelformat)
@@ -617,6 +616,8 @@ v4l_compat_translate_ioctl(struct inode *inode,
617 case VIDIOCSPICT: /* set tone controls & partial capture format */ 616 case VIDIOCSPICT: /* set tone controls & partial capture format */
618 { 617 {
619 struct video_picture *pict = arg; 618 struct video_picture *pict = arg;
619 int mem_err = 0, ovl_err = 0;
620
620 memset(&fbuf2, 0, sizeof(fbuf2)); 621 memset(&fbuf2, 0, sizeof(fbuf2));
621 622
622 set_v4l_control(inode, file, 623 set_v4l_control(inode, file,
@@ -629,33 +630,59 @@ v4l_compat_translate_ioctl(struct inode *inode,
629 V4L2_CID_SATURATION, pict->colour, drv); 630 V4L2_CID_SATURATION, pict->colour, drv);
630 set_v4l_control(inode, file, 631 set_v4l_control(inode, file,
631 V4L2_CID_WHITENESS, pict->whiteness, drv); 632 V4L2_CID_WHITENESS, pict->whiteness, drv);
633 /*
634 * V4L1 uses this ioctl to set both memory capture and overlay
635 * pixel format, while V4L2 has two different ioctls for this.
636 * Some cards may not support one or the other, and may support
637 * different pixel formats for memory vs overlay.
638 */
632 639
633 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL); 640 fmt2 = kzalloc(sizeof(*fmt2),GFP_KERNEL);
634 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 641 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
635 err = drv(inode, file, VIDIOC_G_FMT, fmt2); 642 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
636 if (err < 0) 643 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
644 support memory capture. Trying to set the memory capture
645 parameters would be pointless. */
646 if (err < 0) {
637 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n",err); 647 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n",err);
638 if (fmt2->fmt.pix.pixelformat != 648 mem_err = -1000; /* didn't even try */
639 palette_to_pixelformat(pict->palette)) { 649 } else if (fmt2->fmt.pix.pixelformat !=
650 palette_to_pixelformat(pict->palette)) {
640 fmt2->fmt.pix.pixelformat = palette_to_pixelformat( 651 fmt2->fmt.pix.pixelformat = palette_to_pixelformat(
641 pict->palette); 652 pict->palette);
642 err = drv(inode, file, VIDIOC_S_FMT, fmt2); 653 mem_err = drv(inode, file, VIDIOC_S_FMT, fmt2);
643 if (err < 0) 654 if (mem_err < 0)
644 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",err); 655 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
656 mem_err);
645 } 657 }
646 658
647 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2); 659 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
648 if (err < 0) 660 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
661 support overlay. Trying to set the overlay parameters
662 would be quite pointless. */
663 if (err < 0) {
649 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n",err); 664 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n",err);
650 if (fbuf2.fmt.pixelformat != 665 ovl_err = -1000; /* didn't even try */
651 palette_to_pixelformat(pict->palette)) { 666 } else if (fbuf2.fmt.pixelformat !=
667 palette_to_pixelformat(pict->palette)) {
652 fbuf2.fmt.pixelformat = palette_to_pixelformat( 668 fbuf2.fmt.pixelformat = palette_to_pixelformat(
653 pict->palette); 669 pict->palette);
654 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2); 670 ovl_err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2);
655 if (err < 0) 671 if (ovl_err < 0)
656 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",err); 672 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
657 err = 0; /* likely fails for non-root */ 673 ovl_err);
658 } 674 }
675 if (ovl_err < 0 && mem_err < 0)
676 /* ioctl failed, couldn't set either parameter */
677 if (mem_err != -1000) {
678 err = mem_err;
679 } else if (ovl_err == -EPERM) {
680 err = 0;
681 } else {
682 err = ovl_err;
683 }
684 else
685 err = 0;
659 break; 686 break;
660 } 687 }
661 case VIDIOCGTUNER: /* get tuner information */ 688 case VIDIOCGTUNER: /* get tuner information */
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 49f1df74aa21..13ee550d3215 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -47,7 +47,6 @@
47#include <linux/module.h> 47#include <linux/module.h>
48#include <linux/types.h> 48#include <linux/types.h>
49#include <linux/kernel.h> 49#include <linux/kernel.h>
50#include <linux/smp_lock.h>
51#include <linux/mm.h> 50#include <linux/mm.h>
52#include <linux/string.h> 51#include <linux/string.h>
53#include <linux/errno.h> 52#include <linux/errno.h>
diff --git a/drivers/media/video/video-buf.c b/drivers/media/video/video-buf.c
index 459786ff459a..a32dfbe0585a 100644
--- a/drivers/media/video/video-buf.c
+++ b/drivers/media/video/video-buf.c
@@ -702,9 +702,7 @@ videobuf_qbuf(struct videobuf_queue *q,
702 dprintk(1,"qbuf: memory type is wrong.\n"); 702 dprintk(1,"qbuf: memory type is wrong.\n");
703 goto done; 703 goto done;
704 } 704 }
705 if (buf->state == STATE_QUEUED || 705 if (buf->state != STATE_NEEDS_INIT && buf->state != STATE_IDLE) {
706 buf->state == STATE_PREPARED ||
707 buf->state == STATE_ACTIVE) {
708 dprintk(1,"qbuf: buffer is already queued or active.\n"); 706 dprintk(1,"qbuf: buffer is already queued or active.\n");
709 goto done; 707 goto done;
710 } 708 }
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index 80ac5f86d9e5..b876aca69c73 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -30,7 +30,6 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/types.h> 31#include <linux/types.h>
32#include <linux/kernel.h> 32#include <linux/kernel.h>
33#include <linux/smp_lock.h>
34#include <linux/mm.h> 33#include <linux/mm.h>
35#include <linux/string.h> 34#include <linux/string.h>
36#include <linux/errno.h> 35#include <linux/errno.h>
@@ -434,13 +433,43 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
434 int ret = -EINVAL; 433 int ret = -EINVAL;
435 434
436 if ( (vfd->debug & V4L2_DEBUG_IOCTL) && 435 if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
437 !(vfd->debug | V4L2_DEBUG_IOCTL_ARG)) { 436 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
438 v4l_print_ioctl(vfd->name, cmd); 437 v4l_print_ioctl(vfd->name, cmd);
439 } 438 }
440 439
440#ifdef CONFIG_VIDEO_V4L1_COMPAT
441 /***********************************************************
442 Handles calls to the obsoleted V4L1 API
443 Due to the nature of VIDIOCGMBUF, each driver that supports
444 V4L1 should implement its own handler for this ioctl.
445 ***********************************************************/
446
447 /* --- streaming capture ------------------------------------- */
448 if (cmd == VIDIOCGMBUF) {
449 struct video_mbuf *p=arg;
450
451 memset(p,0,sizeof(p));
452
453 if (!vfd->vidiocgmbuf)
454 return ret;
455 ret=vfd->vidiocgmbuf(file, fh, p);
456 if (!ret)
457 dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
458 p->size, p->frames,
459 (unsigned long)p->offsets);
460 return ret;
461 }
462
463 /********************************************************
464 All other V4L1 calls are handled by v4l1_compat module.
465 Those calls will be translated into V4L2 calls, and
466 __video_do_ioctl will be called again, with one or more
467 V4L2 ioctls.
468 ********************************************************/
441 if (_IOC_TYPE(cmd)=='v') 469 if (_IOC_TYPE(cmd)=='v')
442 return v4l_compat_translate_ioctl(inode,file,cmd,arg, 470 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
443 __video_do_ioctl); 471 __video_do_ioctl);
472#endif
444 473
445 switch(cmd) { 474 switch(cmd) {
446 /* --- capabilities ------------------------------------------ */ 475 /* --- capabilities ------------------------------------------ */
@@ -792,24 +821,6 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
792 ret=vfd->vidioc_overlay(file, fh, *i); 821 ret=vfd->vidioc_overlay(file, fh, *i);
793 break; 822 break;
794 } 823 }
795#ifdef CONFIG_VIDEO_V4L1_COMPAT
796 /* --- streaming capture ------------------------------------- */
797 case VIDIOCGMBUF:
798 {
799 struct video_mbuf *p=arg;
800
801 memset(p,0,sizeof(p));
802
803 if (!vfd->vidiocgmbuf)
804 break;
805 ret=vfd->vidiocgmbuf(file, fh, p);
806 if (!ret)
807 dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
808 p->size, p->frames,
809 (unsigned long)p->offsets);
810 break;
811 }
812#endif
813 case VIDIOC_G_FBUF: 824 case VIDIOC_G_FBUF:
814 { 825 {
815 struct v4l2_framebuffer *p=arg; 826 struct v4l2_framebuffer *p=arg;
diff --git a/drivers/media/video/zc0301/Kconfig b/drivers/media/video/zc0301/Kconfig
index a859a6920189..47cd93f9c7de 100644
--- a/drivers/media/video/zc0301/Kconfig
+++ b/drivers/media/video/zc0301/Kconfig
@@ -1,6 +1,6 @@
1config USB_ZC0301 1config USB_ZC0301
2 tristate "USB ZC0301[P] Image Processor and Control Chip support" 2 tristate "USB ZC0301[P] Image Processor and Control Chip support"
3 depends on USB && VIDEO_V4L1 3 depends on VIDEO_V4L1
4 ---help--- 4 ---help---
5 Say Y here if you want support for cameras based on the ZC0301 or 5 Say Y here if you want support for cameras based on the ZC0301 or
6 ZC0301P Image Processors and Control Chips. 6 ZC0301P Image Processors and Control Chips.
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index 074323733352..cf0ed6cbb0e3 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -2034,7 +2034,7 @@ zoran_do_ioctl (struct inode *inode,
2034 * but moving the free code outside the munmap() handler fixes 2034 * but moving the free code outside the munmap() handler fixes
2035 * all this... If someone knows why, please explain me (Ronald) 2035 * all this... If someone knows why, please explain me (Ronald)
2036 */ 2036 */
2037 if (!!mutex_trylock(&zr->resource_lock)) { 2037 if (mutex_trylock(&zr->resource_lock)) {
2038 /* we obtained it! Let's try to free some things */ 2038 /* we obtained it! Let's try to free some things */
2039 if (fh->jpg_buffers.ready_to_be_freed) 2039 if (fh->jpg_buffers.ready_to_be_freed)
2040 jpg_fbuffer_free(file); 2040 jpg_fbuffer_free(file);
diff --git a/drivers/message/fusion/Kconfig b/drivers/message/fusion/Kconfig
index 71037f91c222..c88cc75ab49b 100644
--- a/drivers/message/fusion/Kconfig
+++ b/drivers/message/fusion/Kconfig
@@ -1,5 +1,6 @@
1 1
2menu "Fusion MPT device support" 2menu "Fusion MPT device support"
3 depends on PCI
3 4
4config FUSION 5config FUSION
5 bool 6 bool
diff --git a/drivers/message/fusion/lsi/mpi_history.txt b/drivers/message/fusion/lsi/mpi_history.txt
index d6b4c607453b..ddc7ae029dd3 100644
--- a/drivers/message/fusion/lsi/mpi_history.txt
+++ b/drivers/message/fusion/lsi/mpi_history.txt
@@ -571,7 +571,7 @@ mpi_fc.h
571 * 11-02-00 01.01.01 Original release for post 1.0 work 571 * 11-02-00 01.01.01 Original release for post 1.0 work
572 * 12-04-00 01.01.02 Added messages for Common Transport Send and 572 * 12-04-00 01.01.02 Added messages for Common Transport Send and
573 * Primitive Send. 573 * Primitive Send.
574 * 01-09-01 01.01.03 Modifed some of the new flags to have an MPI prefix 574 * 01-09-01 01.01.03 Modified some of the new flags to have an MPI prefix
575 * and modified the FcPrimitiveSend flags. 575 * and modified the FcPrimitiveSend flags.
576 * 01-25-01 01.01.04 Move InitiatorIndex in LinkServiceRsp reply to a larger 576 * 01-25-01 01.01.04 Move InitiatorIndex in LinkServiceRsp reply to a larger
577 * field. 577 * field.
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index 97471af4309c..5021d1a2a1d4 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -3585,7 +3585,7 @@ initChainBuffers(MPT_ADAPTER *ioc)
3585 * index = chain_idx 3585 * index = chain_idx
3586 * 3586 *
3587 * Calculate the number of chain buffers needed(plus 1) per I/O 3587 * Calculate the number of chain buffers needed(plus 1) per I/O
3588 * then multiply the the maximum number of simultaneous cmds 3588 * then multiply the maximum number of simultaneous cmds
3589 * 3589 *
3590 * num_sge = num sge in request frame + last chain buffer 3590 * num_sge = num sge in request frame + last chain buffer
3591 * scale = num sge per chain buffer if no chain element 3591 * scale = num sge per chain buffer if no chain element
diff --git a/drivers/message/i2o/Kconfig b/drivers/message/i2o/Kconfig
index 6443392bffff..f4ac21e5771e 100644
--- a/drivers/message/i2o/Kconfig
+++ b/drivers/message/i2o/Kconfig
@@ -1,5 +1,6 @@
1 1
2menu "I2O device support" 2menu "I2O device support"
3 depends on PCI
3 4
4config I2O 5config I2O
5 tristate "I2O support" 6 tristate "I2O support"
diff --git a/drivers/message/i2o/i2o_lan.h b/drivers/message/i2o/i2o_lan.h
deleted file mode 100644
index 6502b817df58..000000000000
--- a/drivers/message/i2o/i2o_lan.h
+++ /dev/null
@@ -1,159 +0,0 @@
1/*
2 * i2o_lan.h I2O LAN Class definitions
3 *
4 * I2O LAN CLASS OSM May 26th 2000
5 *
6 * (C) Copyright 1999, 2000 University of Helsinki,
7 * Department of Computer Science
8 *
9 * This code is still under development / test.
10 *
11 * Author: Auvo Häkkinen <Auvo.Hakkinen@cs.Helsinki.FI>
12 * Juha Sievänen <Juha.Sievanen@cs.Helsinki.FI>
13 * Taneli Vähäkangas <Taneli.Vahakangas@cs.Helsinki.FI>
14 */
15
16#ifndef _I2O_LAN_H
17#define _I2O_LAN_H
18
19/* Default values for tunable parameters first */
20
21#define I2O_LAN_MAX_BUCKETS_OUT 96
22#define I2O_LAN_BUCKET_THRESH 18 /* 9 buckets in one message */
23#define I2O_LAN_RX_COPYBREAK 200
24#define I2O_LAN_TX_TIMEOUT (1*HZ)
25#define I2O_LAN_TX_BATCH_MODE 2 /* 2=automatic, 1=on, 0=off */
26#define I2O_LAN_EVENT_MASK 0 /* 0=None, 0xFFC00002=All */
27
28/* LAN types */
29#define I2O_LAN_ETHERNET 0x0030
30#define I2O_LAN_100VG 0x0040
31#define I2O_LAN_TR 0x0050
32#define I2O_LAN_FDDI 0x0060
33#define I2O_LAN_FIBRE_CHANNEL 0x0070
34#define I2O_LAN_UNKNOWN 0x00000000
35
36/* Connector types */
37
38/* Ethernet */
39#define I2O_LAN_AUI (I2O_LAN_ETHERNET << 4) + 0x00000001
40#define I2O_LAN_10BASE5 (I2O_LAN_ETHERNET << 4) + 0x00000002
41#define I2O_LAN_FIORL (I2O_LAN_ETHERNET << 4) + 0x00000003
42#define I2O_LAN_10BASE2 (I2O_LAN_ETHERNET << 4) + 0x00000004
43#define I2O_LAN_10BROAD36 (I2O_LAN_ETHERNET << 4) + 0x00000005
44#define I2O_LAN_10BASE_T (I2O_LAN_ETHERNET << 4) + 0x00000006
45#define I2O_LAN_10BASE_FP (I2O_LAN_ETHERNET << 4) + 0x00000007
46#define I2O_LAN_10BASE_FB (I2O_LAN_ETHERNET << 4) + 0x00000008
47#define I2O_LAN_10BASE_FL (I2O_LAN_ETHERNET << 4) + 0x00000009
48#define I2O_LAN_100BASE_TX (I2O_LAN_ETHERNET << 4) + 0x0000000A
49#define I2O_LAN_100BASE_FX (I2O_LAN_ETHERNET << 4) + 0x0000000B
50#define I2O_LAN_100BASE_T4 (I2O_LAN_ETHERNET << 4) + 0x0000000C
51#define I2O_LAN_1000BASE_SX (I2O_LAN_ETHERNET << 4) + 0x0000000D
52#define I2O_LAN_1000BASE_LX (I2O_LAN_ETHERNET << 4) + 0x0000000E
53#define I2O_LAN_1000BASE_CX (I2O_LAN_ETHERNET << 4) + 0x0000000F
54#define I2O_LAN_1000BASE_T (I2O_LAN_ETHERNET << 4) + 0x00000010
55
56/* AnyLAN */
57#define I2O_LAN_100VG_ETHERNET (I2O_LAN_100VG << 4) + 0x00000001
58#define I2O_LAN_100VG_TR (I2O_LAN_100VG << 4) + 0x00000002
59
60/* Token Ring */
61#define I2O_LAN_4MBIT (I2O_LAN_TR << 4) + 0x00000001
62#define I2O_LAN_16MBIT (I2O_LAN_TR << 4) + 0x00000002
63
64/* FDDI */
65#define I2O_LAN_125MBAUD (I2O_LAN_FDDI << 4) + 0x00000001
66
67/* Fibre Channel */
68#define I2O_LAN_POINT_POINT (I2O_LAN_FIBRE_CHANNEL << 4) + 0x00000001
69#define I2O_LAN_ARB_LOOP (I2O_LAN_FIBRE_CHANNEL << 4) + 0x00000002
70#define I2O_LAN_PUBLIC_LOOP (I2O_LAN_FIBRE_CHANNEL << 4) + 0x00000003
71#define I2O_LAN_FABRIC (I2O_LAN_FIBRE_CHANNEL << 4) + 0x00000004
72
73#define I2O_LAN_EMULATION 0x00000F00
74#define I2O_LAN_OTHER 0x00000F01
75#define I2O_LAN_DEFAULT 0xFFFFFFFF
76
77/* LAN class functions */
78
79#define LAN_PACKET_SEND 0x3B
80#define LAN_SDU_SEND 0x3D
81#define LAN_RECEIVE_POST 0x3E
82#define LAN_RESET 0x35
83#define LAN_SUSPEND 0x37
84
85/* LAN DetailedStatusCode defines */
86#define I2O_LAN_DSC_SUCCESS 0x00
87#define I2O_LAN_DSC_DEVICE_FAILURE 0x01
88#define I2O_LAN_DSC_DESTINATION_NOT_FOUND 0x02
89#define I2O_LAN_DSC_TRANSMIT_ERROR 0x03
90#define I2O_LAN_DSC_TRANSMIT_ABORTED 0x04
91#define I2O_LAN_DSC_RECEIVE_ERROR 0x05
92#define I2O_LAN_DSC_RECEIVE_ABORTED 0x06
93#define I2O_LAN_DSC_DMA_ERROR 0x07
94#define I2O_LAN_DSC_BAD_PACKET_DETECTED 0x08
95#define I2O_LAN_DSC_OUT_OF_MEMORY 0x09
96#define I2O_LAN_DSC_BUCKET_OVERRUN 0x0A
97#define I2O_LAN_DSC_IOP_INTERNAL_ERROR 0x0B
98#define I2O_LAN_DSC_CANCELED 0x0C
99#define I2O_LAN_DSC_INVALID_TRANSACTION_CONTEXT 0x0D
100#define I2O_LAN_DSC_DEST_ADDRESS_DETECTED 0x0E
101#define I2O_LAN_DSC_DEST_ADDRESS_OMITTED 0x0F
102#define I2O_LAN_DSC_PARTIAL_PACKET_RETURNED 0x10
103#define I2O_LAN_DSC_SUSPENDED 0x11
104
105struct i2o_packet_info {
106 u32 offset:24;
107 u32 flags:8;
108 u32 len:24;
109 u32 status:8;
110};
111
112struct i2o_bucket_descriptor {
113 u32 context; /* FIXME: 64bit support */
114 struct i2o_packet_info packet_info[1];
115};
116
117/* Event Indicator Mask Flags for LAN OSM */
118
119#define I2O_LAN_EVT_LINK_DOWN 0x01
120#define I2O_LAN_EVT_LINK_UP 0x02
121#define I2O_LAN_EVT_MEDIA_CHANGE 0x04
122
123#include <linux/netdevice.h>
124#include <linux/fddidevice.h>
125
126struct i2o_lan_local {
127 u8 unit;
128 struct i2o_device *i2o_dev;
129
130 struct fddi_statistics stats; /* see also struct net_device_stats */
131 unsigned short (*type_trans) (struct sk_buff *, struct net_device *);
132 atomic_t buckets_out; /* nbr of unused buckets on DDM */
133 atomic_t tx_out; /* outstanding TXes */
134 u8 tx_count; /* packets in one TX message frame */
135 u16 tx_max_out; /* DDM's Tx queue len */
136 u8 sgl_max; /* max SGLs in one message frame */
137 u32 m; /* IOP address of the batch msg frame */
138
139 struct work_struct i2o_batch_send_task;
140 int send_active;
141 struct sk_buff **i2o_fbl; /* Free bucket list (to reuse skbs) */
142 int i2o_fbl_tail;
143 spinlock_t fbl_lock;
144
145 spinlock_t tx_lock;
146
147 u32 max_size_mc_table; /* max number of multicast addresses */
148
149 /* LAN OSM configurable parameters are here: */
150
151 u16 max_buckets_out; /* max nbr of buckets to send to DDM */
152 u16 bucket_thresh; /* send more when this many used */
153 u16 rx_copybreak;
154
155 u8 tx_batch_mode; /* Set when using batch mode sends */
156 u32 i2o_event_mask; /* To turn on interesting event flags */
157};
158
159#endif /* _I2O_LAN_H */
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index ab6e985275b2..a20a51efe118 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "Multifunction device drivers" 5menu "Multifunction device drivers"
6 depends on HAS_IOMEM
6 7
7config MFD_SM501 8config MFD_SM501
8 tristate "Support for Silicon Motion SM501" 9 tristate "Support for Silicon Motion SM501"
diff --git a/drivers/mfd/ucb1x00-ts.c b/drivers/mfd/ucb1x00-ts.c
index b023eae3c3ec..7772bd1d92b4 100644
--- a/drivers/mfd/ucb1x00-ts.c
+++ b/drivers/mfd/ucb1x00-ts.c
@@ -21,7 +21,6 @@
21#include <linux/moduleparam.h> 21#include <linux/moduleparam.h>
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/smp.h> 23#include <linux/smp.h>
24#include <linux/smp_lock.h>
25#include <linux/sched.h> 24#include <linux/sched.h>
26#include <linux/completion.h> 25#include <linux/completion.h>
27#include <linux/delay.h> 26#include <linux/delay.h>
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index a3c525b2616a..2f2fbffafbe0 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -25,6 +25,15 @@ config IBM_ASM
25 information on the specific driver level and support statement 25 information on the specific driver level and support statement
26 for your IBM server. 26 for your IBM server.
27 27
28config PHANTOM
29 tristate "Sensable PHANToM"
30 depends on PCI
31 help
32 Say Y here if you want to build a driver for Sensable PHANToM device.
33
34 If you choose to build module, its name will be phantom. If unsure,
35 say N here.
36
28 37
29 If unsure, say N. 38 If unsure, say N.
30 39
@@ -121,7 +130,7 @@ config SONY_LAPTOP
121 130
122 Read <file:Documentation/sony-laptop.txt> for more information. 131 Read <file:Documentation/sony-laptop.txt> for more information.
123 132
124config SONY_LAPTOP_OLD 133config SONYPI_COMPAT
125 bool "Sonypi compatibility" 134 bool "Sonypi compatibility"
126 depends on SONY_LAPTOP 135 depends on SONY_LAPTOP
127 ---help--- 136 ---help---
@@ -178,4 +187,13 @@ config THINKPAD_ACPI_BAY
178 187
179 If you are not sure, say Y here. 188 If you are not sure, say Y here.
180 189
190config BLINK
191 tristate "Keyboard blink driver"
192 help
193 Driver that when loaded will blink the keyboard LEDs continuously.
194 This is useful for debugging and for kernels that cannot necessarily
195 output something to the screen like kexec kernels to give the user
196 a visual indication that the kernel is doing something.
197
198
181endmenu 199endmenu
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index e32516459138..5b6d46de005c 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -7,9 +7,11 @@ obj-$(CONFIG_IBM_ASM) += ibmasm/
7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/ 7obj-$(CONFIG_HDPU_FEATURES) += hdpuftrs/
8obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o 8obj-$(CONFIG_MSI_LAPTOP) += msi-laptop.o
9obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o 9obj-$(CONFIG_ASUS_LAPTOP) += asus-laptop.o
10obj-$(CONFIG_BLINK) += blink.o
10obj-$(CONFIG_LKDTM) += lkdtm.o 11obj-$(CONFIG_LKDTM) += lkdtm.o
11obj-$(CONFIG_TIFM_CORE) += tifm_core.o 12obj-$(CONFIG_TIFM_CORE) += tifm_core.o
12obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o 13obj-$(CONFIG_TIFM_7XX1) += tifm_7xx1.o
14obj-$(CONFIG_PHANTOM) += phantom.o
13obj-$(CONFIG_SGI_IOC4) += ioc4.o 15obj-$(CONFIG_SGI_IOC4) += ioc4.o
14obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o 16obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o
15obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o 17obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
diff --git a/drivers/misc/asus-laptop.c b/drivers/misc/asus-laptop.c
index 65c32a95e121..4f9060a2a2f2 100644
--- a/drivers/misc/asus-laptop.c
+++ b/drivers/misc/asus-laptop.c
@@ -30,7 +30,7 @@
30 * Eric Burghard - LED display support for W1N 30 * Eric Burghard - LED display support for W1N
31 * Josh Green - Light Sens support 31 * Josh Green - Light Sens support
32 * Thomas Tuttle - His first patch for led support was very helpfull 32 * Thomas Tuttle - His first patch for led support was very helpfull
33 * 33 * Sam Lin - GPS support
34 */ 34 */
35 35
36#include <linux/autoconf.h> 36#include <linux/autoconf.h>
@@ -48,7 +48,7 @@
48#include <acpi/acpi_bus.h> 48#include <acpi/acpi_bus.h>
49#include <asm/uaccess.h> 49#include <asm/uaccess.h>
50 50
51#define ASUS_LAPTOP_VERSION "0.41" 51#define ASUS_LAPTOP_VERSION "0.42"
52 52
53#define ASUS_HOTK_NAME "Asus Laptop Support" 53#define ASUS_HOTK_NAME "Asus Laptop Support"
54#define ASUS_HOTK_CLASS "hotkey" 54#define ASUS_HOTK_CLASS "hotkey"
@@ -83,6 +83,7 @@
83#define PLED_ON 0x20 //Phone LED 83#define PLED_ON 0x20 //Phone LED
84#define GLED_ON 0x40 //Gaming LED 84#define GLED_ON 0x40 //Gaming LED
85#define LCD_ON 0x80 //LCD backlight 85#define LCD_ON 0x80 //LCD backlight
86#define GPS_ON 0x100 //GPS
86 87
87#define ASUS_LOG ASUS_HOTK_FILE ": " 88#define ASUS_LOG ASUS_HOTK_FILE ": "
88#define ASUS_ERR KERN_ERR ASUS_LOG 89#define ASUS_ERR KERN_ERR ASUS_LOG
@@ -148,7 +149,7 @@ ASUS_HANDLE(display_set, ASUS_HOTK_PREFIX "SDSP");
148ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD", /* A6B, A6K A6R A7D F3JM L4R M6R A3G 149ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD", /* A6B, A6K A6R A7D F3JM L4R M6R A3G
149 M6A M6V VX-1 V6J V6V W3Z */ 150 M6A M6V VX-1 V6J V6V W3Z */
150 "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V 151 "\\_SB.PCI0.P0P2.VGA.GETD", /* A3E A4K, A4D A4L A6J A7J A8J Z71V M9V
151 S5A M5A z33A W1Jc W2V */ 152 S5A M5A z33A W1Jc W2V G1 */
152 "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */ 153 "\\_SB.PCI0.P0P3.VGA.GETD", /* A6V A6Q */
153 "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */ 154 "\\_SB.PCI0.P0PA.VGA.GETD", /* A6T, A6M */
154 "\\_SB.PCI0.PCI1.VGAC.NMAP", /* L3C */ 155 "\\_SB.PCI0.PCI1.VGAC.NMAP", /* L3C */
@@ -162,6 +163,12 @@ ASUS_HANDLE(display_get, "\\_SB.PCI0.P0P1.VGA.GETD", /* A6B, A6K A6R A7D F3JM L
162ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */ 163ASUS_HANDLE(ls_switch, ASUS_HOTK_PREFIX "ALSC"); /* Z71A Z71V */
163ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */ 164ASUS_HANDLE(ls_level, ASUS_HOTK_PREFIX "ALSL"); /* Z71A Z71V */
164 165
166/* GPS */
167/* R2H use different handle for GPS on/off */
168ASUS_HANDLE(gps_on, ASUS_HOTK_PREFIX "SDON"); /* R2H */
169ASUS_HANDLE(gps_off, ASUS_HOTK_PREFIX "SDOF"); /* R2H */
170ASUS_HANDLE(gps_status, ASUS_HOTK_PREFIX "GPST");
171
165/* 172/*
166 * This is the main structure, we can use it to store anything interesting 173 * This is the main structure, we can use it to store anything interesting
167 * about the hotk device 174 * about the hotk device
@@ -278,12 +285,28 @@ static int read_wireless_status(int mask)
278 return (hotk->status & mask) ? 1 : 0; 285 return (hotk->status & mask) ? 1 : 0;
279} 286}
280 287
288static int read_gps_status(void)
289{
290 ulong status;
291 acpi_status rv = AE_OK;
292
293 rv = acpi_evaluate_integer(gps_status_handle, NULL, NULL, &status);
294 if (ACPI_FAILURE(rv))
295 printk(ASUS_WARNING "Error reading GPS status\n");
296 else
297 return status ? 1 : 0;
298
299 return (hotk->status & GPS_ON) ? 1 : 0;
300}
301
281/* Generic LED functions */ 302/* Generic LED functions */
282static int read_status(int mask) 303static int read_status(int mask)
283{ 304{
284 /* There is a special method for both wireless devices */ 305 /* There is a special method for both wireless devices */
285 if (mask == BT_ON || mask == WL_ON) 306 if (mask == BT_ON || mask == WL_ON)
286 return read_wireless_status(mask); 307 return read_wireless_status(mask);
308 else if (mask == GPS_ON)
309 return read_gps_status();
287 310
288 return (hotk->status & mask) ? 1 : 0; 311 return (hotk->status & mask) ? 1 : 0;
289} 312}
@@ -299,6 +322,10 @@ static void write_status(acpi_handle handle, int out, int mask)
299 case GLED_ON: 322 case GLED_ON:
300 out = (out & 0x1) + 1; 323 out = (out & 0x1) + 1;
301 break; 324 break;
325 case GPS_ON:
326 handle = (out) ? gps_on_handle : gps_off_handle;
327 out = 0x02;
328 break;
302 default: 329 default:
303 out &= 0x1; 330 out &= 0x1;
304 break; 331 break;
@@ -667,6 +694,21 @@ static ssize_t store_lslvl(struct device *dev, struct device_attribute *attr,
667 return rv; 694 return rv;
668} 695}
669 696
697/*
698 * GPS
699 */
700static ssize_t show_gps(struct device *dev,
701 struct device_attribute *attr, char *buf)
702{
703 return sprintf(buf, "%d\n", read_status(GPS_ON));
704}
705
706static ssize_t store_gps(struct device *dev, struct device_attribute *attr,
707 const char *buf, size_t count)
708{
709 return store_status(buf, count, NULL, GPS_ON);
710}
711
670static void asus_hotk_notify(acpi_handle handle, u32 event, void *data) 712static void asus_hotk_notify(acpi_handle handle, u32 event, void *data)
671{ 713{
672 /* TODO Find a better way to handle events count. */ 714 /* TODO Find a better way to handle events count. */
@@ -715,6 +757,7 @@ static ASUS_CREATE_DEVICE_ATTR(display);
715static ASUS_CREATE_DEVICE_ATTR(ledd); 757static ASUS_CREATE_DEVICE_ATTR(ledd);
716static ASUS_CREATE_DEVICE_ATTR(ls_switch); 758static ASUS_CREATE_DEVICE_ATTR(ls_switch);
717static ASUS_CREATE_DEVICE_ATTR(ls_level); 759static ASUS_CREATE_DEVICE_ATTR(ls_level);
760static ASUS_CREATE_DEVICE_ATTR(gps);
718 761
719static struct attribute *asuspf_attributes[] = { 762static struct attribute *asuspf_attributes[] = {
720 &dev_attr_infos.attr, 763 &dev_attr_infos.attr,
@@ -724,6 +767,7 @@ static struct attribute *asuspf_attributes[] = {
724 &dev_attr_ledd.attr, 767 &dev_attr_ledd.attr,
725 &dev_attr_ls_switch.attr, 768 &dev_attr_ls_switch.attr,
726 &dev_attr_ls_level.attr, 769 &dev_attr_ls_level.attr,
770 &dev_attr_gps.attr,
727 NULL 771 NULL
728}; 772};
729 773
@@ -763,6 +807,9 @@ static void asus_hotk_add_fs(void)
763 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl); 807 ASUS_SET_DEVICE_ATTR(ls_level, 0644, show_lslvl, store_lslvl);
764 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw); 808 ASUS_SET_DEVICE_ATTR(ls_switch, 0644, show_lssw, store_lssw);
765 } 809 }
810
811 if (gps_status_handle && gps_on_handle && gps_off_handle)
812 ASUS_SET_DEVICE_ATTR(gps, 0644, show_gps, store_gps);
766} 813}
767 814
768static int asus_handle_init(char *name, acpi_handle * handle, 815static int asus_handle_init(char *name, acpi_handle * handle,
@@ -890,9 +937,13 @@ static int asus_hotk_get_info(void)
890 937
891 /* There is a lot of models with "ALSL", but a few get 938 /* There is a lot of models with "ALSL", but a few get
892 a real light sens, so we need to check it. */ 939 a real light sens, so we need to check it. */
893 if (ASUS_HANDLE_INIT(ls_switch)) 940 if (!ASUS_HANDLE_INIT(ls_switch))
894 ASUS_HANDLE_INIT(ls_level); 941 ASUS_HANDLE_INIT(ls_level);
895 942
943 ASUS_HANDLE_INIT(gps_on);
944 ASUS_HANDLE_INIT(gps_off);
945 ASUS_HANDLE_INIT(gps_status);
946
896 kfree(model); 947 kfree(model);
897 948
898 return AE_OK; 949 return AE_OK;
@@ -950,7 +1001,7 @@ static int asus_hotk_add(struct acpi_device *device)
950 * We install the handler, it will receive the hotk in parameter, so, we 1001 * We install the handler, it will receive the hotk in parameter, so, we
951 * could add other data to the hotk struct 1002 * could add other data to the hotk struct
952 */ 1003 */
953 status = acpi_install_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY, 1004 status = acpi_install_notify_handler(hotk->handle, ACPI_ALL_NOTIFY,
954 asus_hotk_notify, hotk); 1005 asus_hotk_notify, hotk);
955 if (ACPI_FAILURE(status)) 1006 if (ACPI_FAILURE(status))
956 printk(ASUS_ERR "Error installing notify handler\n"); 1007 printk(ASUS_ERR "Error installing notify handler\n");
@@ -981,6 +1032,9 @@ static int asus_hotk_add(struct acpi_device *device)
981 if (ls_level_handle) 1032 if (ls_level_handle)
982 set_light_sens_level(hotk->light_level); 1033 set_light_sens_level(hotk->light_level);
983 1034
1035 /* GPS is on by default */
1036 write_status(NULL, 1, GPS_ON);
1037
984 end: 1038 end:
985 if (result) { 1039 if (result) {
986 kfree(hotk->name); 1040 kfree(hotk->name);
@@ -997,7 +1051,7 @@ static int asus_hotk_remove(struct acpi_device *device, int type)
997 if (!device || !acpi_driver_data(device)) 1051 if (!device || !acpi_driver_data(device))
998 return -EINVAL; 1052 return -EINVAL;
999 1053
1000 status = acpi_remove_notify_handler(hotk->handle, ACPI_SYSTEM_NOTIFY, 1054 status = acpi_remove_notify_handler(hotk->handle, ACPI_ALL_NOTIFY,
1001 asus_hotk_notify); 1055 asus_hotk_notify);
1002 if (ACPI_FAILURE(status)) 1056 if (ACPI_FAILURE(status))
1003 printk(ASUS_ERR "Error removing notify handler\n"); 1057 printk(ASUS_ERR "Error removing notify handler\n");
diff --git a/drivers/misc/blink.c b/drivers/misc/blink.c
new file mode 100644
index 000000000000..634431ce1184
--- /dev/null
+++ b/drivers/misc/blink.c
@@ -0,0 +1,27 @@
1#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/timer.h>
4#include <linux/jiffies.h>
5
6static void do_blink(unsigned long data);
7
8static DEFINE_TIMER(blink_timer, do_blink, 0 ,0);
9
10static void do_blink(unsigned long data)
11{
12 static long count;
13 if (panic_blink)
14 panic_blink(count++);
15 blink_timer.expires = jiffies + msecs_to_jiffies(1);
16 add_timer(&blink_timer);
17}
18
19static int blink_init(void)
20{
21 printk(KERN_INFO "Enabling keyboard blinking\n");
22 do_blink(0);
23 return 0;
24}
25
26module_init(blink_init);
27
diff --git a/drivers/misc/msi-laptop.c b/drivers/misc/msi-laptop.c
index 68c4b58525ba..41e901f53e7c 100644
--- a/drivers/misc/msi-laptop.c
+++ b/drivers/misc/msi-laptop.c
@@ -85,7 +85,7 @@ static int set_lcd_level(int level)
85 buf[0] = 0x80; 85 buf[0] = 0x80;
86 buf[1] = (u8) (level*31); 86 buf[1] = (u8) (level*31);
87 87
88 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, buf, sizeof(buf), NULL, 0); 88 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, buf, sizeof(buf), NULL, 0, 1);
89} 89}
90 90
91static int get_lcd_level(void) 91static int get_lcd_level(void)
@@ -93,7 +93,7 @@ static int get_lcd_level(void)
93 u8 wdata = 0, rdata; 93 u8 wdata = 0, rdata;
94 int result; 94 int result;
95 95
96 result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1); 96 result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1, 1);
97 if (result < 0) 97 if (result < 0)
98 return result; 98 return result;
99 99
@@ -105,7 +105,7 @@ static int get_auto_brightness(void)
105 u8 wdata = 4, rdata; 105 u8 wdata = 4, rdata;
106 int result; 106 int result;
107 107
108 result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1); 108 result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, &wdata, 1, &rdata, 1, 1);
109 if (result < 0) 109 if (result < 0)
110 return result; 110 return result;
111 111
@@ -119,14 +119,14 @@ static int set_auto_brightness(int enable)
119 119
120 wdata[0] = 4; 120 wdata[0] = 4;
121 121
122 result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 1, &rdata, 1); 122 result = ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 1, &rdata, 1, 1);
123 if (result < 0) 123 if (result < 0)
124 return result; 124 return result;
125 125
126 wdata[0] = 0x84; 126 wdata[0] = 0x84;
127 wdata[1] = (rdata & 0xF7) | (enable ? 8 : 0); 127 wdata[1] = (rdata & 0xF7) | (enable ? 8 : 0);
128 128
129 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0); 129 return ec_transaction(MSI_EC_COMMAND_LCD_LEVEL, wdata, 2, NULL, 0, 1);
130} 130}
131 131
132static int get_wireless_state(int *wlan, int *bluetooth) 132static int get_wireless_state(int *wlan, int *bluetooth)
@@ -134,7 +134,7 @@ static int get_wireless_state(int *wlan, int *bluetooth)
134 u8 wdata = 0, rdata; 134 u8 wdata = 0, rdata;
135 int result; 135 int result;
136 136
137 result = ec_transaction(MSI_EC_COMMAND_WIRELESS, &wdata, 1, &rdata, 1); 137 result = ec_transaction(MSI_EC_COMMAND_WIRELESS, &wdata, 1, &rdata, 1, 1);
138 if (result < 0) 138 if (result < 0)
139 return -1; 139 return -1;
140 140
diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
new file mode 100644
index 000000000000..35b139b0e5f2
--- /dev/null
+++ b/drivers/misc/phantom.c
@@ -0,0 +1,463 @@
1/*
2 * Copyright (C) 2005-2007 Jiri Slaby <jirislaby@gmail.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * You need an userspace library to cooperate with this driver. It (and other
10 * info) may be obtained here:
11 * http://www.fi.muni.cz/~xslaby/phantom.html
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/device.h>
17#include <linux/pci.h>
18#include <linux/fs.h>
19#include <linux/poll.h>
20#include <linux/interrupt.h>
21#include <linux/cdev.h>
22#include <linux/phantom.h>
23
24#include <asm/atomic.h>
25#include <asm/io.h>
26
27#define PHANTOM_VERSION "n0.9.5"
28
29#define PHANTOM_MAX_MINORS 8
30
31#define PHN_IRQCTL 0x4c /* irq control in caddr space */
32
33#define PHB_RUNNING 1
34
35static struct class *phantom_class;
36static int phantom_major;
37
38struct phantom_device {
39 unsigned int opened;
40 void __iomem *caddr;
41 u32 __iomem *iaddr;
42 u32 __iomem *oaddr;
43 unsigned long status;
44 atomic_t counter;
45
46 wait_queue_head_t wait;
47 struct cdev cdev;
48
49 struct mutex open_lock;
50};
51
52static unsigned char phantom_devices[PHANTOM_MAX_MINORS];
53
54static int phantom_status(struct phantom_device *dev, unsigned long newstat)
55{
56 pr_debug("phantom_status %lx %lx\n", dev->status, newstat);
57
58 if (!(dev->status & PHB_RUNNING) && (newstat & PHB_RUNNING)) {
59 atomic_set(&dev->counter, 0);
60 iowrite32(PHN_CTL_IRQ, dev->iaddr + PHN_CONTROL);
61 iowrite32(0x43, dev->caddr + PHN_IRQCTL);
62 } else if ((dev->status & PHB_RUNNING) && !(newstat & PHB_RUNNING))
63 iowrite32(0, dev->caddr + PHN_IRQCTL);
64
65 dev->status = newstat;
66
67 return 0;
68}
69
70/*
71 * File ops
72 */
73
74static int phantom_ioctl(struct inode *inode, struct file *file, u_int cmd,
75 u_long arg)
76{
77 struct phantom_device *dev = file->private_data;
78 struct phm_regs rs;
79 struct phm_reg r;
80 void __user *argp = (void __user *)arg;
81 unsigned int i;
82
83 if (_IOC_TYPE(cmd) != PH_IOC_MAGIC ||
84 _IOC_NR(cmd) > PH_IOC_MAXNR)
85 return -ENOTTY;
86
87 switch (cmd) {
88 case PHN_SET_REG:
89 if (copy_from_user(&r, argp, sizeof(r)))
90 return -EFAULT;
91
92 if (r.reg > 7)
93 return -EINVAL;
94
95 if (r.reg == PHN_CONTROL && (r.value & PHN_CTL_IRQ) &&
96 phantom_status(dev, dev->status | PHB_RUNNING))
97 return -ENODEV;
98
99 pr_debug("phantom: writing %x to %u\n", r.value, r.reg);
100 iowrite32(r.value, dev->iaddr + r.reg);
101
102 if (r.reg == PHN_CONTROL && !(r.value & PHN_CTL_IRQ))
103 phantom_status(dev, dev->status & ~PHB_RUNNING);
104 break;
105 case PHN_SET_REGS:
106 if (copy_from_user(&rs, argp, sizeof(rs)))
107 return -EFAULT;
108
109 pr_debug("phantom: SRS %u regs %x\n", rs.count, rs.mask);
110 for (i = 0; i < min(rs.count, 8U); i++)
111 if ((1 << i) & rs.mask)
112 iowrite32(rs.values[i], dev->oaddr + i);
113 break;
114 case PHN_GET_REG:
115 if (copy_from_user(&r, argp, sizeof(r)))
116 return -EFAULT;
117
118 if (r.reg > 7)
119 return -EINVAL;
120
121 r.value = ioread32(dev->iaddr + r.reg);
122
123 if (copy_to_user(argp, &r, sizeof(r)))
124 return -EFAULT;
125 break;
126 case PHN_GET_REGS:
127 if (copy_from_user(&rs, argp, sizeof(rs)))
128 return -EFAULT;
129
130 pr_debug("phantom: GRS %u regs %x\n", rs.count, rs.mask);
131 for (i = 0; i < min(rs.count, 8U); i++)
132 if ((1 << i) & rs.mask)
133 rs.values[i] = ioread32(dev->iaddr + i);
134
135 if (copy_to_user(argp, &rs, sizeof(rs)))
136 return -EFAULT;
137 break;
138 default:
139 return -ENOTTY;
140 }
141
142 return 0;
143}
144
145static int phantom_open(struct inode *inode, struct file *file)
146{
147 struct phantom_device *dev = container_of(inode->i_cdev,
148 struct phantom_device, cdev);
149
150 nonseekable_open(inode, file);
151
152 if (mutex_lock_interruptible(&dev->open_lock))
153 return -ERESTARTSYS;
154
155 if (dev->opened) {
156 mutex_unlock(&dev->open_lock);
157 return -EINVAL;
158 }
159
160 file->private_data = dev;
161
162 dev->opened++;
163 mutex_unlock(&dev->open_lock);
164
165 return 0;
166}
167
168static int phantom_release(struct inode *inode, struct file *file)
169{
170 struct phantom_device *dev = file->private_data;
171
172 mutex_lock(&dev->open_lock);
173
174 dev->opened = 0;
175 phantom_status(dev, dev->status & ~PHB_RUNNING);
176
177 mutex_unlock(&dev->open_lock);
178
179 return 0;
180}
181
182static unsigned int phantom_poll(struct file *file, poll_table *wait)
183{
184 struct phantom_device *dev = file->private_data;
185 unsigned int mask = 0;
186
187 pr_debug("phantom_poll: %d\n", atomic_read(&dev->counter));
188 poll_wait(file, &dev->wait, wait);
189 if (atomic_read(&dev->counter)) {
190 mask = POLLIN | POLLRDNORM;
191 atomic_dec(&dev->counter);
192 } else if ((dev->status & PHB_RUNNING) == 0)
193 mask = POLLIN | POLLRDNORM | POLLERR;
194 pr_debug("phantom_poll end: %x/%d\n", mask, atomic_read(&dev->counter));
195
196 return mask;
197}
198
199static struct file_operations phantom_file_ops = {
200 .open = phantom_open,
201 .release = phantom_release,
202 .ioctl = phantom_ioctl,
203 .poll = phantom_poll,
204};
205
206static irqreturn_t phantom_isr(int irq, void *data)
207{
208 struct phantom_device *dev = data;
209
210 if (!(ioread32(dev->iaddr + PHN_CONTROL) & PHN_CTL_IRQ))
211 return IRQ_NONE;
212
213 iowrite32(0, dev->iaddr);
214 iowrite32(0xc0, dev->iaddr);
215
216 atomic_inc(&dev->counter);
217 wake_up_interruptible(&dev->wait);
218
219 return IRQ_HANDLED;
220}
221
222/*
223 * Init and deinit driver
224 */
225
226static unsigned int __devinit phantom_get_free(void)
227{
228 unsigned int i;
229
230 for (i = 0; i < PHANTOM_MAX_MINORS; i++)
231 if (phantom_devices[i] == 0)
232 break;
233
234 return i;
235}
236
237static int __devinit phantom_probe(struct pci_dev *pdev,
238 const struct pci_device_id *pci_id)
239{
240 struct phantom_device *pht;
241 unsigned int minor;
242 int retval;
243
244 retval = pci_enable_device(pdev);
245 if (retval)
246 goto err;
247
248 minor = phantom_get_free();
249 if (minor == PHANTOM_MAX_MINORS) {
250 dev_err(&pdev->dev, "too many devices found!\n");
251 retval = -EIO;
252 goto err_dis;
253 }
254
255 phantom_devices[minor] = 1;
256
257 retval = pci_request_regions(pdev, "phantom");
258 if (retval)
259 goto err_null;
260
261 retval = -ENOMEM;
262 pht = kzalloc(sizeof(*pht), GFP_KERNEL);
263 if (pht == NULL) {
264 dev_err(&pdev->dev, "unable to allocate device\n");
265 goto err_reg;
266 }
267
268 pht->caddr = pci_iomap(pdev, 0, 0);
269 if (pht->caddr == NULL) {
270 dev_err(&pdev->dev, "can't remap conf space\n");
271 goto err_fr;
272 }
273 pht->iaddr = pci_iomap(pdev, 2, 0);
274 if (pht->iaddr == NULL) {
275 dev_err(&pdev->dev, "can't remap input space\n");
276 goto err_unmc;
277 }
278 pht->oaddr = pci_iomap(pdev, 3, 0);
279 if (pht->oaddr == NULL) {
280 dev_err(&pdev->dev, "can't remap output space\n");
281 goto err_unmi;
282 }
283
284 mutex_init(&pht->open_lock);
285 init_waitqueue_head(&pht->wait);
286 cdev_init(&pht->cdev, &phantom_file_ops);
287 pht->cdev.owner = THIS_MODULE;
288
289 iowrite32(0, pht->caddr + PHN_IRQCTL);
290 retval = request_irq(pdev->irq, phantom_isr,
291 IRQF_SHARED | IRQF_DISABLED, "phantom", pht);
292 if (retval) {
293 dev_err(&pdev->dev, "can't establish ISR\n");
294 goto err_unmo;
295 }
296
297 retval = cdev_add(&pht->cdev, MKDEV(phantom_major, minor), 1);
298 if (retval) {
299 dev_err(&pdev->dev, "chardev registration failed\n");
300 goto err_irq;
301 }
302
303 if (IS_ERR(device_create(phantom_class, &pdev->dev, MKDEV(phantom_major,
304 minor), "phantom%u", minor)))
305 dev_err(&pdev->dev, "can't create device\n");
306
307 pci_set_drvdata(pdev, pht);
308
309 return 0;
310err_irq:
311 free_irq(pdev->irq, pht);
312err_unmo:
313 pci_iounmap(pdev, pht->oaddr);
314err_unmi:
315 pci_iounmap(pdev, pht->iaddr);
316err_unmc:
317 pci_iounmap(pdev, pht->caddr);
318err_fr:
319 kfree(pht);
320err_reg:
321 pci_release_regions(pdev);
322err_null:
323 phantom_devices[minor] = 0;
324err_dis:
325 pci_disable_device(pdev);
326err:
327 return retval;
328}
329
330static void __devexit phantom_remove(struct pci_dev *pdev)
331{
332 struct phantom_device *pht = pci_get_drvdata(pdev);
333 unsigned int minor = MINOR(pht->cdev.dev);
334
335 device_destroy(phantom_class, MKDEV(phantom_major, minor));
336
337 cdev_del(&pht->cdev);
338
339 iowrite32(0, pht->caddr + PHN_IRQCTL);
340 free_irq(pdev->irq, pht);
341
342 pci_iounmap(pdev, pht->oaddr);
343 pci_iounmap(pdev, pht->iaddr);
344 pci_iounmap(pdev, pht->caddr);
345
346 kfree(pht);
347
348 pci_release_regions(pdev);
349
350 phantom_devices[minor] = 0;
351
352 pci_disable_device(pdev);
353}
354
355#ifdef CONFIG_PM
356static int phantom_suspend(struct pci_dev *pdev, pm_message_t state)
357{
358 struct phantom_device *dev = pci_get_drvdata(pdev);
359
360 iowrite32(0, dev->caddr + PHN_IRQCTL);
361
362 return 0;
363}
364
365static int phantom_resume(struct pci_dev *pdev)
366{
367 struct phantom_device *dev = pci_get_drvdata(pdev);
368
369 iowrite32(0, dev->caddr + PHN_IRQCTL);
370
371 return 0;
372}
373#else
374#define phantom_suspend NULL
375#define phantom_resume NULL
376#endif
377
378static struct pci_device_id phantom_pci_tbl[] __devinitdata = {
379 { PCI_DEVICE(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050),
380 .class = PCI_CLASS_BRIDGE_OTHER << 8, .class_mask = 0xffff00 },
381 { 0, }
382};
383MODULE_DEVICE_TABLE(pci, phantom_pci_tbl);
384
385static struct pci_driver phantom_pci_driver = {
386 .name = "phantom",
387 .id_table = phantom_pci_tbl,
388 .probe = phantom_probe,
389 .remove = __devexit_p(phantom_remove),
390 .suspend = phantom_suspend,
391 .resume = phantom_resume
392};
393
394static ssize_t phantom_show_version(struct class *cls, char *buf)
395{
396 return sprintf(buf, PHANTOM_VERSION "\n");
397}
398
399static CLASS_ATTR(version, 0444, phantom_show_version, NULL);
400
401static int __init phantom_init(void)
402{
403 int retval;
404 dev_t dev;
405
406 phantom_class = class_create(THIS_MODULE, "phantom");
407 if (IS_ERR(phantom_class)) {
408 retval = PTR_ERR(phantom_class);
409 printk(KERN_ERR "phantom: can't register phantom class\n");
410 goto err;
411 }
412 retval = class_create_file(phantom_class, &class_attr_version);
413 if (retval) {
414 printk(KERN_ERR "phantom: can't create sysfs version file\n");
415 goto err_class;
416 }
417
418 retval = alloc_chrdev_region(&dev, 0, PHANTOM_MAX_MINORS, "phantom");
419 if (retval) {
420 printk(KERN_ERR "phantom: can't register character device\n");
421 goto err_attr;
422 }
423 phantom_major = MAJOR(dev);
424
425 retval = pci_register_driver(&phantom_pci_driver);
426 if (retval) {
427 printk(KERN_ERR "phantom: can't register pci driver\n");
428 goto err_unchr;
429 }
430
431 printk(KERN_INFO "Phantom Linux Driver, version " PHANTOM_VERSION ", "
432 "init OK\n");
433
434 return 0;
435err_unchr:
436 unregister_chrdev_region(dev, PHANTOM_MAX_MINORS);
437err_attr:
438 class_remove_file(phantom_class, &class_attr_version);
439err_class:
440 class_destroy(phantom_class);
441err:
442 return retval;
443}
444
445static void __exit phantom_exit(void)
446{
447 pci_unregister_driver(&phantom_pci_driver);
448
449 unregister_chrdev_region(MKDEV(phantom_major, 0), PHANTOM_MAX_MINORS);
450
451 class_remove_file(phantom_class, &class_attr_version);
452 class_destroy(phantom_class);
453
454 pr_debug("phantom: module successfully removed\n");
455}
456
457module_init(phantom_init);
458module_exit(phantom_exit);
459
460MODULE_AUTHOR("Jiri Slaby <jirislaby@gmail.com>");
461MODULE_DESCRIPTION("Sensable Phantom driver");
462MODULE_LICENSE("GPL");
463MODULE_VERSION(PHANTOM_VERSION);
diff --git a/drivers/misc/sony-laptop.c b/drivers/misc/sony-laptop.c
index c15c1f61bd1b..8ee0321ef1c8 100644
--- a/drivers/misc/sony-laptop.c
+++ b/drivers/misc/sony-laptop.c
@@ -63,7 +63,7 @@
63#include <asm/uaccess.h> 63#include <asm/uaccess.h>
64#include <linux/sonypi.h> 64#include <linux/sonypi.h>
65#include <linux/sony-laptop.h> 65#include <linux/sony-laptop.h>
66#ifdef CONFIG_SONY_LAPTOP_OLD 66#ifdef CONFIG_SONYPI_COMPAT
67#include <linux/poll.h> 67#include <linux/poll.h>
68#include <linux/miscdevice.h> 68#include <linux/miscdevice.h>
69#endif 69#endif
@@ -114,7 +114,7 @@ MODULE_PARM_DESC(camera,
114 "set this to 1 to enable Motion Eye camera controls " 114 "set this to 1 to enable Motion Eye camera controls "
115 "(only use it if you have a C1VE or C1VN model)"); 115 "(only use it if you have a C1VE or C1VN model)");
116 116
117#ifdef CONFIG_SONY_LAPTOP_OLD 117#ifdef CONFIG_SONYPI_COMPAT
118static int minor = -1; 118static int minor = -1;
119module_param(minor, int, 0); 119module_param(minor, int, 0);
120MODULE_PARM_DESC(minor, 120MODULE_PARM_DESC(minor,
@@ -1504,7 +1504,7 @@ static struct attribute_group spic_attribute_group = {
1504}; 1504};
1505 1505
1506/******** SONYPI compatibility **********/ 1506/******** SONYPI compatibility **********/
1507#ifdef CONFIG_SONY_LAPTOP_OLD 1507#ifdef CONFIG_SONYPI_COMPAT
1508 1508
1509/* battery / brightness / temperature addresses */ 1509/* battery / brightness / temperature addresses */
1510#define SONYPI_BAT_FLAGS 0x81 1510#define SONYPI_BAT_FLAGS 0x81
@@ -1798,7 +1798,7 @@ static void sonypi_compat_exit(void)
1798static int sonypi_compat_init(void) { return 0; } 1798static int sonypi_compat_init(void) { return 0; }
1799static void sonypi_compat_exit(void) { } 1799static void sonypi_compat_exit(void) { }
1800static void sonypi_compat_report_event(u8 event) { } 1800static void sonypi_compat_report_event(u8 event) { }
1801#endif /* CONFIG_SONY_LAPTOP_OLD */ 1801#endif /* CONFIG_SONYPI_COMPAT */
1802 1802
1803/* 1803/*
1804 * ACPI callbacks 1804 * ACPI callbacks
diff --git a/drivers/misc/tifm_7xx1.c b/drivers/misc/tifm_7xx1.c
index 1ba6c085419a..c08ad8f823d2 100644
--- a/drivers/misc/tifm_7xx1.c
+++ b/drivers/misc/tifm_7xx1.c
@@ -105,7 +105,8 @@ static unsigned char tifm_7xx1_toggle_sock_power(char __iomem *sock_addr)
105 == TIFM_TYPE_XD) 105 == TIFM_TYPE_XD)
106 msleep(40); 106 msleep(40);
107 107
108 writel((s_state & 7) | 0x0c00, sock_addr + SOCK_CONTROL); 108 writel((s_state & TIFM_CTRL_POWER_MASK) | 0x0c00,
109 sock_addr + SOCK_CONTROL);
109 /* wait for power to stabilize */ 110 /* wait for power to stabilize */
110 msleep(20); 111 msleep(20);
111 for (cnt = 16; cnt <= 256; cnt <<= 1) { 112 for (cnt = 16; cnt <= 256; cnt <<= 1) {
@@ -122,6 +123,12 @@ static unsigned char tifm_7xx1_toggle_sock_power(char __iomem *sock_addr)
122 return (readl(sock_addr + SOCK_PRESENT_STATE) >> 4) & 7; 123 return (readl(sock_addr + SOCK_PRESENT_STATE) >> 4) & 7;
123} 124}
124 125
126inline static void tifm_7xx1_sock_power_off(char __iomem *sock_addr)
127{
128 writel((~TIFM_CTRL_POWER_MASK) & readl(sock_addr + SOCK_CONTROL),
129 sock_addr + SOCK_CONTROL);
130}
131
125inline static char __iomem * 132inline static char __iomem *
126tifm_7xx1_sock_addr(char __iomem *base_addr, unsigned int sock_num) 133tifm_7xx1_sock_addr(char __iomem *base_addr, unsigned int sock_num)
127{ 134{
@@ -133,6 +140,7 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
133 struct tifm_adapter *fm = container_of(work, struct tifm_adapter, 140 struct tifm_adapter *fm = container_of(work, struct tifm_adapter,
134 media_switcher); 141 media_switcher);
135 struct tifm_dev *sock; 142 struct tifm_dev *sock;
143 char __iomem *sock_addr;
136 unsigned long flags; 144 unsigned long flags;
137 unsigned char media_id; 145 unsigned char media_id;
138 unsigned int socket_change_set, cnt; 146 unsigned int socket_change_set, cnt;
@@ -158,11 +166,12 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
158 "%s : demand removing card from socket %u:%u\n", 166 "%s : demand removing card from socket %u:%u\n",
159 fm->cdev.class_id, fm->id, cnt); 167 fm->cdev.class_id, fm->id, cnt);
160 fm->sockets[cnt] = NULL; 168 fm->sockets[cnt] = NULL;
169 sock_addr = sock->addr;
161 spin_unlock_irqrestore(&fm->lock, flags); 170 spin_unlock_irqrestore(&fm->lock, flags);
162 device_unregister(&sock->dev); 171 device_unregister(&sock->dev);
163 spin_lock_irqsave(&fm->lock, flags); 172 spin_lock_irqsave(&fm->lock, flags);
164 writel(0x0e00, tifm_7xx1_sock_addr(fm->addr, cnt) 173 tifm_7xx1_sock_power_off(sock_addr);
165 + SOCK_CONTROL); 174 writel(0x0e00, sock_addr + SOCK_CONTROL);
166 } 175 }
167 176
168 spin_unlock_irqrestore(&fm->lock, flags); 177 spin_unlock_irqrestore(&fm->lock, flags);
@@ -205,8 +214,16 @@ static void tifm_7xx1_switch_media(struct work_struct *work)
205 214
206static int tifm_7xx1_suspend(struct pci_dev *dev, pm_message_t state) 215static int tifm_7xx1_suspend(struct pci_dev *dev, pm_message_t state)
207{ 216{
217 struct tifm_adapter *fm = pci_get_drvdata(dev);
218 int cnt;
219
208 dev_dbg(&dev->dev, "suspending host\n"); 220 dev_dbg(&dev->dev, "suspending host\n");
209 221
222 for (cnt = 0; cnt < fm->num_sockets; cnt++) {
223 if (fm->sockets[cnt])
224 tifm_7xx1_sock_power_off(fm->sockets[cnt]->addr);
225 }
226
210 pci_save_state(dev); 227 pci_save_state(dev);
211 pci_enable_wake(dev, pci_choose_state(dev, state), 0); 228 pci_enable_wake(dev, pci_choose_state(dev, state), 0);
212 pci_disable_device(dev); 229 pci_disable_device(dev);
@@ -357,6 +374,7 @@ err_out:
357static void tifm_7xx1_remove(struct pci_dev *dev) 374static void tifm_7xx1_remove(struct pci_dev *dev)
358{ 375{
359 struct tifm_adapter *fm = pci_get_drvdata(dev); 376 struct tifm_adapter *fm = pci_get_drvdata(dev);
377 int cnt;
360 378
361 fm->eject = tifm_7xx1_dummy_eject; 379 fm->eject = tifm_7xx1_dummy_eject;
362 writel(TIFM_IRQ_SETALL, fm->addr + FM_CLEAR_INTERRUPT_ENABLE); 380 writel(TIFM_IRQ_SETALL, fm->addr + FM_CLEAR_INTERRUPT_ENABLE);
@@ -365,6 +383,9 @@ static void tifm_7xx1_remove(struct pci_dev *dev)
365 383
366 tifm_remove_adapter(fm); 384 tifm_remove_adapter(fm);
367 385
386 for (cnt = 0; cnt < fm->num_sockets; cnt++)
387 tifm_7xx1_sock_power_off(tifm_7xx1_sock_addr(fm->addr, cnt));
388
368 pci_set_drvdata(dev, NULL); 389 pci_set_drvdata(dev, NULL);
369 390
370 iounmap(fm->addr); 391 iounmap(fm->addr);
diff --git a/drivers/mmc/Kconfig b/drivers/mmc/Kconfig
index 6c97491543db..c0b41e8bcd9d 100644
--- a/drivers/mmc/Kconfig
+++ b/drivers/mmc/Kconfig
@@ -2,10 +2,9 @@
2# MMC subsystem configuration 2# MMC subsystem configuration
3# 3#
4 4
5menu "MMC/SD Card support" 5menuconfig MMC
6 6 tristate "MMC/SD card support"
7config MMC 7 depends on HAS_IOMEM
8 tristate "MMC support"
9 help 8 help
10 MMC is the "multi-media card" bus protocol. 9 MMC is the "multi-media card" bus protocol.
11 10
@@ -19,10 +18,12 @@ config MMC_DEBUG
19 This is an option for use by developers; most people should 18 This is an option for use by developers; most people should
20 say N here. This enables MMC core and driver debugging. 19 say N here. This enables MMC core and driver debugging.
21 20
21if MMC
22
22source "drivers/mmc/core/Kconfig" 23source "drivers/mmc/core/Kconfig"
23 24
24source "drivers/mmc/card/Kconfig" 25source "drivers/mmc/card/Kconfig"
25 26
26source "drivers/mmc/host/Kconfig" 27source "drivers/mmc/host/Kconfig"
27 28
28endmenu 29endif # MMC
diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
index 01a9fd376a1f..9320a8c73239 100644
--- a/drivers/mmc/card/Kconfig
+++ b/drivers/mmc/card/Kconfig
@@ -3,11 +3,10 @@
3# 3#
4 4
5comment "MMC/SD Card Drivers" 5comment "MMC/SD Card Drivers"
6 depends MMC
7 6
8config MMC_BLOCK 7config MMC_BLOCK
9 tristate "MMC block device driver" 8 tristate "MMC block device driver"
10 depends on MMC && BLOCK 9 depends on BLOCK
11 default y 10 default y
12 help 11 help
13 Say Y here to enable the MMC block device driver support. 12 Say Y here to enable the MMC block device driver support.
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index d24ab234394c..a7562f7fc0b3 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -45,8 +45,6 @@
45 */ 45 */
46#define MMC_SHIFT 3 46#define MMC_SHIFT 3
47 47
48static int major;
49
50/* 48/*
51 * There is one mmc_blk_data per slot. 49 * There is one mmc_blk_data per slot.
52 */ 50 */
@@ -466,7 +464,7 @@ static struct mmc_blk_data *mmc_blk_alloc(struct mmc_card *card)
466 md->queue.issue_fn = mmc_blk_issue_rq; 464 md->queue.issue_fn = mmc_blk_issue_rq;
467 md->queue.data = md; 465 md->queue.data = md;
468 466
469 md->disk->major = major; 467 md->disk->major = MMC_BLOCK_MAJOR;
470 md->disk->first_minor = devidx << MMC_SHIFT; 468 md->disk->first_minor = devidx << MMC_SHIFT;
471 md->disk->fops = &mmc_bdops; 469 md->disk->fops = &mmc_bdops;
472 md->disk->private_data = md; 470 md->disk->private_data = md;
@@ -634,14 +632,9 @@ static int __init mmc_blk_init(void)
634{ 632{
635 int res = -ENOMEM; 633 int res = -ENOMEM;
636 634
637 res = register_blkdev(major, "mmc"); 635 res = register_blkdev(MMC_BLOCK_MAJOR, "mmc");
638 if (res < 0) { 636 if (res)
639 printk(KERN_WARNING "Unable to get major %d for MMC media: %d\n",
640 major, res);
641 goto out; 637 goto out;
642 }
643 if (major == 0)
644 major = res;
645 638
646 return mmc_register_driver(&mmc_driver); 639 return mmc_register_driver(&mmc_driver);
647 640
@@ -652,7 +645,7 @@ static int __init mmc_blk_init(void)
652static void __exit mmc_blk_exit(void) 645static void __exit mmc_blk_exit(void)
653{ 646{
654 mmc_unregister_driver(&mmc_driver); 647 mmc_unregister_driver(&mmc_driver);
655 unregister_blkdev(major, "mmc"); 648 unregister_blkdev(MMC_BLOCK_MAJOR, "mmc");
656} 649}
657 650
658module_init(mmc_blk_init); 651module_init(mmc_blk_init);
@@ -661,5 +654,3 @@ module_exit(mmc_blk_exit);
661MODULE_LICENSE("GPL"); 654MODULE_LICENSE("GPL");
662MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver"); 655MODULE_DESCRIPTION("Multimedia Card (MMC) block device driver");
663 656
664module_param(major, int, 0444);
665MODULE_PARM_DESC(major, "specify the major device number for MMC block driver");
diff --git a/drivers/mmc/core/Kconfig b/drivers/mmc/core/Kconfig
index 94222b9a15ea..ab37a6d9d32a 100644
--- a/drivers/mmc/core/Kconfig
+++ b/drivers/mmc/core/Kconfig
@@ -4,7 +4,6 @@
4 4
5config MMC_UNSAFE_RESUME 5config MMC_UNSAFE_RESUME
6 bool "Allow unsafe resume (DANGEROUS)" 6 bool "Allow unsafe resume (DANGEROUS)"
7 depends on MMC != n
8 help 7 help
9 If you say Y here, the MMC layer will assume that all cards 8 If you say Y here, the MMC layer will assume that all cards
10 stayed in their respective slots during the suspend. The 9 stayed in their respective slots during the suspend. The
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 72c7cf4a9f9d..7385acfa1dd9 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -500,9 +500,10 @@ void __mmc_release_bus(struct mmc_host *host)
500void mmc_detect_change(struct mmc_host *host, unsigned long delay) 500void mmc_detect_change(struct mmc_host *host, unsigned long delay)
501{ 501{
502#ifdef CONFIG_MMC_DEBUG 502#ifdef CONFIG_MMC_DEBUG
503 mmc_claim_host(host); 503 unsigned long flags;
504 spin_lock_irqsave(&host->lock, flags);
504 BUG_ON(host->removed); 505 BUG_ON(host->removed);
505 mmc_release_host(host); 506 spin_unlock_irqrestore(&host->lock, flags);
506#endif 507#endif
507 508
508 mmc_schedule_delayed_work(&host->detect, delay); 509 mmc_schedule_delayed_work(&host->detect, delay);
@@ -625,9 +626,10 @@ EXPORT_SYMBOL(mmc_add_host);
625void mmc_remove_host(struct mmc_host *host) 626void mmc_remove_host(struct mmc_host *host)
626{ 627{
627#ifdef CONFIG_MMC_DEBUG 628#ifdef CONFIG_MMC_DEBUG
628 mmc_claim_host(host); 629 unsigned long flags;
630 spin_lock_irqsave(&host->lock, flags);
629 host->removed = 1; 631 host->removed = 1;
630 mmc_release_host(host); 632 spin_unlock_irqrestore(&host->lock, flags);
631#endif 633#endif
632 634
633 mmc_flush_scheduled_work(); 635 mmc_flush_scheduled_work();
diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig
index ed4deab2203d..e23082fe88d0 100644
--- a/drivers/mmc/host/Kconfig
+++ b/drivers/mmc/host/Kconfig
@@ -3,11 +3,10 @@
3# 3#
4 4
5comment "MMC/SD Host Controller Drivers" 5comment "MMC/SD Host Controller Drivers"
6 depends on MMC
7 6
8config MMC_ARMMMCI 7config MMC_ARMMMCI
9 tristate "ARM AMBA Multimedia Card Interface support" 8 tristate "ARM AMBA Multimedia Card Interface support"
10 depends on ARM_AMBA && MMC 9 depends on ARM_AMBA
11 help 10 help
12 This selects the ARM(R) AMBA(R) PrimeCell Multimedia Card 11 This selects the ARM(R) AMBA(R) PrimeCell Multimedia Card
13 Interface (PL180 and PL181) support. If you have an ARM(R) 12 Interface (PL180 and PL181) support. If you have an ARM(R)
@@ -17,7 +16,7 @@ config MMC_ARMMMCI
17 16
18config MMC_PXA 17config MMC_PXA
19 tristate "Intel PXA25x/26x/27x Multimedia Card Interface support" 18 tristate "Intel PXA25x/26x/27x Multimedia Card Interface support"
20 depends on ARCH_PXA && MMC 19 depends on ARCH_PXA
21 help 20 help
22 This selects the Intel(R) PXA(R) Multimedia card Interface. 21 This selects the Intel(R) PXA(R) Multimedia card Interface.
23 If you have a PXA(R) platform with a Multimedia Card slot, 22 If you have a PXA(R) platform with a Multimedia Card slot,
@@ -27,7 +26,7 @@ config MMC_PXA
27 26
28config MMC_SDHCI 27config MMC_SDHCI
29 tristate "Secure Digital Host Controller Interface support (EXPERIMENTAL)" 28 tristate "Secure Digital Host Controller Interface support (EXPERIMENTAL)"
30 depends on PCI && MMC && EXPERIMENTAL 29 depends on PCI && EXPERIMENTAL
31 help 30 help
32 This select the generic Secure Digital Host Controller Interface. 31 This select the generic Secure Digital Host Controller Interface.
33 It is used by manufacturers such as Texas Instruments(R), Ricoh(R) 32 It is used by manufacturers such as Texas Instruments(R), Ricoh(R)
@@ -38,7 +37,7 @@ config MMC_SDHCI
38 37
39config MMC_OMAP 38config MMC_OMAP
40 tristate "TI OMAP Multimedia Card Interface support" 39 tristate "TI OMAP Multimedia Card Interface support"
41 depends on ARCH_OMAP && MMC 40 depends on ARCH_OMAP
42 select TPS65010 if MACH_OMAP_H2 41 select TPS65010 if MACH_OMAP_H2
43 help 42 help
44 This selects the TI OMAP Multimedia card Interface. 43 This selects the TI OMAP Multimedia card Interface.
@@ -49,7 +48,7 @@ config MMC_OMAP
49 48
50config MMC_WBSD 49config MMC_WBSD
51 tristate "Winbond W83L51xD SD/MMC Card Interface support" 50 tristate "Winbond W83L51xD SD/MMC Card Interface support"
52 depends on MMC && ISA_DMA_API 51 depends on ISA_DMA_API
53 help 52 help
54 This selects the Winbond(R) W83L51xD Secure digital and 53 This selects the Winbond(R) W83L51xD Secure digital and
55 Multimedia card Interface. 54 Multimedia card Interface.
@@ -60,7 +59,7 @@ config MMC_WBSD
60 59
61config MMC_AU1X 60config MMC_AU1X
62 tristate "Alchemy AU1XX0 MMC Card Interface support" 61 tristate "Alchemy AU1XX0 MMC Card Interface support"
63 depends on MMC && SOC_AU1200 62 depends on SOC_AU1200
64 help 63 help
65 This selects the AMD Alchemy(R) Multimedia card interface. 64 This selects the AMD Alchemy(R) Multimedia card interface.
66 If you have a Alchemy platform with a MMC slot, say Y or M here. 65 If you have a Alchemy platform with a MMC slot, say Y or M here.
@@ -69,7 +68,7 @@ config MMC_AU1X
69 68
70config MMC_AT91 69config MMC_AT91
71 tristate "AT91 SD/MMC Card Interface support" 70 tristate "AT91 SD/MMC Card Interface support"
72 depends on ARCH_AT91 && MMC 71 depends on ARCH_AT91
73 help 72 help
74 This selects the AT91 MCI controller. 73 This selects the AT91 MCI controller.
75 74
@@ -77,7 +76,7 @@ config MMC_AT91
77 76
78config MMC_IMX 77config MMC_IMX
79 tristate "Motorola i.MX Multimedia Card Interface support" 78 tristate "Motorola i.MX Multimedia Card Interface support"
80 depends on ARCH_IMX && MMC 79 depends on ARCH_IMX
81 help 80 help
82 This selects the Motorola i.MX Multimedia card Interface. 81 This selects the Motorola i.MX Multimedia card Interface.
83 If you have a i.MX platform with a Multimedia Card slot, 82 If you have a i.MX platform with a Multimedia Card slot,
@@ -87,7 +86,7 @@ config MMC_IMX
87 86
88config MMC_TIFM_SD 87config MMC_TIFM_SD
89 tristate "TI Flash Media MMC/SD Interface support (EXPERIMENTAL)" 88 tristate "TI Flash Media MMC/SD Interface support (EXPERIMENTAL)"
90 depends on MMC && EXPERIMENTAL && PCI 89 depends on EXPERIMENTAL && PCI
91 select TIFM_CORE 90 select TIFM_CORE
92 help 91 help
93 Say Y here if you want to be able to access MMC/SD cards with 92 Say Y here if you want to be able to access MMC/SD cards with
diff --git a/drivers/mmc/host/au1xmmc.c b/drivers/mmc/host/au1xmmc.c
index b7156a4555b5..f967226d7505 100644
--- a/drivers/mmc/host/au1xmmc.c
+++ b/drivers/mmc/host/au1xmmc.c
@@ -187,9 +187,8 @@ static void au1xmmc_tasklet_finish(unsigned long param)
187} 187}
188 188
189static int au1xmmc_send_command(struct au1xmmc_host *host, int wait, 189static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
190 struct mmc_command *cmd) 190 struct mmc_command *cmd, unsigned int flags)
191{ 191{
192
193 u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT); 192 u32 mmccmd = (cmd->opcode << SD_CMD_CI_SHIFT);
194 193
195 switch (mmc_resp_type(cmd)) { 194 switch (mmc_resp_type(cmd)) {
@@ -213,24 +212,16 @@ static int au1xmmc_send_command(struct au1xmmc_host *host, int wait,
213 return MMC_ERR_INVALID; 212 return MMC_ERR_INVALID;
214 } 213 }
215 214
216 switch(cmd->opcode) { 215 if (flags & MMC_DATA_READ) {
217 case MMC_READ_SINGLE_BLOCK: 216 if (flags & MMC_DATA_MULTI)
218 case SD_APP_SEND_SCR: 217 mmccmd |= SD_CMD_CT_4;
219 mmccmd |= SD_CMD_CT_2; 218 else
220 break; 219 mmccmd |= SD_CMD_CT_2;
221 case MMC_READ_MULTIPLE_BLOCK: 220 } else if (flags & MMC_DATA_WRITE) {
222 mmccmd |= SD_CMD_CT_4; 221 if (flags & MMC_DATA_MULTI)
223 break; 222 mmccmd |= SD_CMD_CT_3;
224 case MMC_WRITE_BLOCK: 223 else
225 mmccmd |= SD_CMD_CT_1; 224 mmccmd |= SD_CMD_CT_1;
226 break;
227
228 case MMC_WRITE_MULTIPLE_BLOCK:
229 mmccmd |= SD_CMD_CT_3;
230 break;
231 case MMC_STOP_TRANSMISSION:
232 mmccmd |= SD_CMD_CT_7;
233 break;
234 } 225 }
235 226
236 au_writel(cmd->arg, HOST_CMDARG(host)); 227 au_writel(cmd->arg, HOST_CMDARG(host));
@@ -665,6 +656,7 @@ static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
665{ 656{
666 657
667 struct au1xmmc_host *host = mmc_priv(mmc); 658 struct au1xmmc_host *host = mmc_priv(mmc);
659 unsigned int flags = 0;
668 int ret = MMC_ERR_NONE; 660 int ret = MMC_ERR_NONE;
669 661
670 WARN_ON(irqs_disabled()); 662 WARN_ON(irqs_disabled());
@@ -677,11 +669,12 @@ static void au1xmmc_request(struct mmc_host* mmc, struct mmc_request* mrq)
677 669
678 if (mrq->data) { 670 if (mrq->data) {
679 FLUSH_FIFO(host); 671 FLUSH_FIFO(host);
672 flags = mrq->data->flags;
680 ret = au1xmmc_prepare_data(host, mrq->data); 673 ret = au1xmmc_prepare_data(host, mrq->data);
681 } 674 }
682 675
683 if (ret == MMC_ERR_NONE) 676 if (ret == MMC_ERR_NONE)
684 ret = au1xmmc_send_command(host, 0, mrq->cmd); 677 ret = au1xmmc_send_command(host, 0, mrq->cmd, flags);
685 678
686 if (ret != MMC_ERR_NONE) { 679 if (ret != MMC_ERR_NONE) {
687 mrq->cmd->error = ret; 680 mrq->cmd->error = ret;
diff --git a/drivers/mmc/host/pxamci.c b/drivers/mmc/host/pxamci.c
index d97d3864b57f..f8985c508bb9 100644
--- a/drivers/mmc/host/pxamci.c
+++ b/drivers/mmc/host/pxamci.c
@@ -232,20 +232,14 @@ static int pxamci_cmd_done(struct pxamci_host *host, unsigned int stat)
232 /* 232 /*
233 * workaround for erratum #42: 233 * workaround for erratum #42:
234 * Intel PXA27x Family Processor Specification Update Rev 001 234 * Intel PXA27x Family Processor Specification Update Rev 001
235 * A bogus CRC error can appear if the msb of a 136 bit
236 * response is a one.
235 */ 237 */
236 if (cmd->opcode == MMC_ALL_SEND_CID || 238 if (cmd->flags & MMC_RSP_136 && cmd->resp[0] & 0x80000000) {
237 cmd->opcode == MMC_SEND_CSD || 239 pr_debug("ignoring CRC from command %d - *risky*\n", cmd->opcode);
238 cmd->opcode == MMC_SEND_CID) { 240 } else
239 /* a bogus CRC error can appear if the msb of
240 the 15 byte response is a one */
241 if ((cmd->resp[0] & 0x80000000) == 0)
242 cmd->error = MMC_ERR_BADCRC;
243 } else {
244 pr_debug("ignoring CRC from command %d - *risky*\n",cmd->opcode);
245 }
246#else
247 cmd->error = MMC_ERR_BADCRC;
248#endif 241#endif
242 cmd->error = MMC_ERR_BADCRC;
249 } 243 }
250 244
251 pxamci_disable_irq(host, END_CMD_RES); 245 pxamci_disable_irq(host, END_CMD_RES);
diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c
index ff5bf73cdd25..a359efdd77eb 100644
--- a/drivers/mmc/host/sdhci.c
+++ b/drivers/mmc/host/sdhci.c
@@ -963,6 +963,15 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
963 if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) 963 if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
964 sdhci_transfer_pio(host); 964 sdhci_transfer_pio(host);
965 965
966 /*
967 * We currently don't do anything fancy with DMA
968 * boundaries, but as we can't disable the feature
969 * we need to at least restart the transfer.
970 */
971 if (intmask & SDHCI_INT_DMA_END)
972 writel(readl(host->ioaddr + SDHCI_DMA_ADDRESS),
973 host->ioaddr + SDHCI_DMA_ADDRESS);
974
966 if (intmask & SDHCI_INT_DATA_END) 975 if (intmask & SDHCI_INT_DATA_END)
967 sdhci_finish_data(host); 976 sdhci_finish_data(host);
968 } 977 }
diff --git a/drivers/mmc/host/tifm_sd.c b/drivers/mmc/host/tifm_sd.c
index 7511f961c67b..8b736e968447 100644
--- a/drivers/mmc/host/tifm_sd.c
+++ b/drivers/mmc/host/tifm_sd.c
@@ -1021,10 +1021,6 @@ static void tifm_sd_remove(struct tifm_dev *sock)
1021 mmc_remove_host(mmc); 1021 mmc_remove_host(mmc);
1022 dev_dbg(&sock->dev, "after remove\n"); 1022 dev_dbg(&sock->dev, "after remove\n");
1023 1023
1024 /* The meaning of the bit majority in this constant is unknown. */
1025 writel(0xfff8 & readl(sock->addr + SOCK_CONTROL),
1026 sock->addr + SOCK_CONTROL);
1027
1028 mmc_free_host(mmc); 1024 mmc_free_host(mmc);
1029} 1025}
1030 1026
@@ -1032,14 +1028,7 @@ static void tifm_sd_remove(struct tifm_dev *sock)
1032 1028
1033static int tifm_sd_suspend(struct tifm_dev *sock, pm_message_t state) 1029static int tifm_sd_suspend(struct tifm_dev *sock, pm_message_t state)
1034{ 1030{
1035 struct mmc_host *mmc = tifm_get_drvdata(sock); 1031 return mmc_suspend_host(tifm_get_drvdata(sock), state);
1036 int rc;
1037
1038 rc = mmc_suspend_host(mmc, state);
1039 /* The meaning of the bit majority in this constant is unknown. */
1040 writel(0xfff8 & readl(sock->addr + SOCK_CONTROL),
1041 sock->addr + SOCK_CONTROL);
1042 return rc;
1043} 1032}
1044 1033
1045static int tifm_sd_resume(struct tifm_dev *sock) 1034static int tifm_sd_resume(struct tifm_dev *sock)
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index c1b47db29bd2..fbec8cd55e38 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -2,6 +2,7 @@
2 2
3menuconfig MTD 3menuconfig MTD
4 tristate "Memory Technology Device (MTD) support" 4 tristate "Memory Technology Device (MTD) support"
5 depends on HAS_IOMEM
5 help 6 help
6 Memory Technology Devices are flash, RAM and similar chips, often 7 Memory Technology Devices are flash, RAM and similar chips, often
7 used for solid state file systems on embedded devices. This option 8 used for solid state file systems on embedded devices. This option
diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig
index d28e0fc85e12..479d32b57a1e 100644
--- a/drivers/mtd/chips/Kconfig
+++ b/drivers/mtd/chips/Kconfig
@@ -1,5 +1,4 @@
1# drivers/mtd/chips/Kconfig 1# drivers/mtd/chips/Kconfig
2# $Id: Kconfig,v 1.18 2005/11/07 11:14:22 gleixner Exp $
3 2
4menu "RAM/ROM/Flash chip drivers" 3menu "RAM/ROM/Flash chip drivers"
5 depends on MTD!=n 4 depends on MTD!=n
@@ -231,45 +230,6 @@ config MTD_ABSENT
231 the system regardless of media presence. Device nodes created 230 the system regardless of media presence. Device nodes created
232 with this driver will return -ENODEV upon access. 231 with this driver will return -ENODEV upon access.
233 232
234config MTD_OBSOLETE_CHIPS
235 bool "Older (theoretically obsoleted now) drivers for non-CFI chips"
236 help
237 This option does not enable any code directly, but will allow you to
238 select some other chip drivers which are now considered obsolete,
239 because the generic CONFIG_JEDECPROBE code above should now detect
240 the chips which are supported by these drivers, and allow the generic
241 CFI-compatible drivers to drive the chips. Say 'N' here unless you have
242 already tried the CONFIG_JEDECPROBE method and reported its failure
243 to the MTD mailing list at <linux-mtd@lists.infradead.org>
244
245config MTD_AMDSTD
246 tristate "AMD compatible flash chip support (non-CFI)"
247 depends on MTD_OBSOLETE_CHIPS && BROKEN
248 help
249 This option enables support for flash chips using AMD-compatible
250 commands, including some which are not CFI-compatible and hence
251 cannot be used with the CONFIG_MTD_CFI_AMDSTD option.
252
253 It also works on AMD compatible chips that do conform to CFI.
254
255config MTD_SHARP
256 tristate "pre-CFI Sharp chip support"
257 depends on MTD_OBSOLETE_CHIPS
258 help
259 This option enables support for flash chips using Sharp-compatible
260 commands, including some which are not CFI-compatible and hence
261 cannot be used with the CONFIG_MTD_CFI_INTELxxx options.
262
263config MTD_JEDEC
264 tristate "JEDEC device support"
265 depends on MTD_OBSOLETE_CHIPS && BROKEN
266 help
267 Enable older JEDEC flash interface devices for self
268 programming flash. It is commonly used in older AMD chips. It is
269 only called JEDEC because the JEDEC association
270 <http://www.jedec.org/> distributes the identification codes for the
271 chips.
272
273config MTD_XIP 233config MTD_XIP
274 bool "XIP aware MTD support" 234 bool "XIP aware MTD support"
275 depends on !SMP && (MTD_CFI_INTELEXT || MTD_CFI_AMDSTD) && EXPERIMENTAL && ARCH_MTD_XIP 235 depends on !SMP && (MTD_CFI_INTELEXT || MTD_CFI_AMDSTD) && EXPERIMENTAL && ARCH_MTD_XIP
diff --git a/drivers/mtd/chips/Makefile b/drivers/mtd/chips/Makefile
index 75bc1c2a0f43..36582412ccda 100644
--- a/drivers/mtd/chips/Makefile
+++ b/drivers/mtd/chips/Makefile
@@ -1,19 +1,15 @@
1# 1#
2# linux/drivers/chips/Makefile 2# linux/drivers/chips/Makefile
3# 3#
4# $Id: Makefile.common,v 1.5 2005/11/07 11:14:22 gleixner Exp $
5 4
6obj-$(CONFIG_MTD) += chipreg.o 5obj-$(CONFIG_MTD) += chipreg.o
7obj-$(CONFIG_MTD_AMDSTD) += amd_flash.o
8obj-$(CONFIG_MTD_CFI) += cfi_probe.o 6obj-$(CONFIG_MTD_CFI) += cfi_probe.o
9obj-$(CONFIG_MTD_CFI_UTIL) += cfi_util.o 7obj-$(CONFIG_MTD_CFI_UTIL) += cfi_util.o
10obj-$(CONFIG_MTD_CFI_STAA) += cfi_cmdset_0020.o 8obj-$(CONFIG_MTD_CFI_STAA) += cfi_cmdset_0020.o
11obj-$(CONFIG_MTD_CFI_AMDSTD) += cfi_cmdset_0002.o 9obj-$(CONFIG_MTD_CFI_AMDSTD) += cfi_cmdset_0002.o
12obj-$(CONFIG_MTD_CFI_INTELEXT) += cfi_cmdset_0001.o 10obj-$(CONFIG_MTD_CFI_INTELEXT) += cfi_cmdset_0001.o
13obj-$(CONFIG_MTD_GEN_PROBE) += gen_probe.o 11obj-$(CONFIG_MTD_GEN_PROBE) += gen_probe.o
14obj-$(CONFIG_MTD_JEDEC) += jedec.o
15obj-$(CONFIG_MTD_JEDECPROBE) += jedec_probe.o 12obj-$(CONFIG_MTD_JEDECPROBE) += jedec_probe.o
16obj-$(CONFIG_MTD_RAM) += map_ram.o 13obj-$(CONFIG_MTD_RAM) += map_ram.o
17obj-$(CONFIG_MTD_ROM) += map_rom.o 14obj-$(CONFIG_MTD_ROM) += map_rom.o
18obj-$(CONFIG_MTD_SHARP) += sharp.o
19obj-$(CONFIG_MTD_ABSENT) += map_absent.o 15obj-$(CONFIG_MTD_ABSENT) += map_absent.o
diff --git a/drivers/mtd/chips/amd_flash.c b/drivers/mtd/chips/amd_flash.c
deleted file mode 100644
index e7999f15d85a..000000000000
--- a/drivers/mtd/chips/amd_flash.c
+++ /dev/null
@@ -1,1396 +0,0 @@
1/*
2 * MTD map driver for AMD compatible flash chips (non-CFI)
3 *
4 * Author: Jonas Holmberg <jonas.holmberg@axis.com>
5 *
6 * $Id: amd_flash.c,v 1.28 2005/11/07 11:14:22 gleixner Exp $
7 *
8 * Copyright (c) 2001 Axis Communications AB
9 *
10 * This file is under GPL.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/types.h>
16#include <linux/kernel.h>
17#include <linux/sched.h>
18#include <linux/errno.h>
19#include <linux/slab.h>
20#include <linux/delay.h>
21#include <linux/interrupt.h>
22#include <linux/init.h>
23#include <linux/mtd/map.h>
24#include <linux/mtd/mtd.h>
25#include <linux/mtd/flashchip.h>
26
27/* There's no limit. It exists only to avoid realloc. */
28#define MAX_AMD_CHIPS 8
29
30#define DEVICE_TYPE_X8 (8 / 8)
31#define DEVICE_TYPE_X16 (16 / 8)
32#define DEVICE_TYPE_X32 (32 / 8)
33
34/* Addresses */
35#define ADDR_MANUFACTURER 0x0000
36#define ADDR_DEVICE_ID 0x0001
37#define ADDR_SECTOR_LOCK 0x0002
38#define ADDR_HANDSHAKE 0x0003
39#define ADDR_UNLOCK_1 0x0555
40#define ADDR_UNLOCK_2 0x02AA
41
42/* Commands */
43#define CMD_UNLOCK_DATA_1 0x00AA
44#define CMD_UNLOCK_DATA_2 0x0055
45#define CMD_MANUFACTURER_UNLOCK_DATA 0x0090
46#define CMD_UNLOCK_BYPASS_MODE 0x0020
47#define CMD_PROGRAM_UNLOCK_DATA 0x00A0
48#define CMD_RESET_DATA 0x00F0
49#define CMD_SECTOR_ERASE_UNLOCK_DATA 0x0080
50#define CMD_SECTOR_ERASE_UNLOCK_DATA_2 0x0030
51
52#define CMD_UNLOCK_SECTOR 0x0060
53
54/* Manufacturers */
55#define MANUFACTURER_AMD 0x0001
56#define MANUFACTURER_ATMEL 0x001F
57#define MANUFACTURER_FUJITSU 0x0004
58#define MANUFACTURER_ST 0x0020
59#define MANUFACTURER_SST 0x00BF
60#define MANUFACTURER_TOSHIBA 0x0098
61
62/* AMD */
63#define AM29F800BB 0x2258
64#define AM29F800BT 0x22D6
65#define AM29LV800BB 0x225B
66#define AM29LV800BT 0x22DA
67#define AM29LV160DT 0x22C4
68#define AM29LV160DB 0x2249
69#define AM29BDS323D 0x22D1
70
71/* Atmel */
72#define AT49xV16x 0x00C0
73#define AT49xV16xT 0x00C2
74
75/* Fujitsu */
76#define MBM29LV160TE 0x22C4
77#define MBM29LV160BE 0x2249
78#define MBM29LV800BB 0x225B
79
80/* ST - www.st.com */
81#define M29W800T 0x00D7
82#define M29W160DT 0x22C4
83#define M29W160DB 0x2249
84
85/* SST */
86#define SST39LF800 0x2781
87#define SST39LF160 0x2782
88
89/* Toshiba */
90#define TC58FVT160 0x00C2
91#define TC58FVB160 0x0043
92
93#define D6_MASK 0x40
94
95struct amd_flash_private {
96 int device_type;
97 int interleave;
98 int numchips;
99 unsigned long chipshift;
100 struct flchip chips[0];
101};
102
103struct amd_flash_info {
104 const __u16 mfr_id;
105 const __u16 dev_id;
106 const char *name;
107 const u_long size;
108 const int numeraseregions;
109 const struct mtd_erase_region_info regions[4];
110};
111
112
113
114static int amd_flash_read(struct mtd_info *, loff_t, size_t, size_t *,
115 u_char *);
116static int amd_flash_write(struct mtd_info *, loff_t, size_t, size_t *,
117 const u_char *);
118static int amd_flash_erase(struct mtd_info *, struct erase_info *);
119static void amd_flash_sync(struct mtd_info *);
120static int amd_flash_suspend(struct mtd_info *);
121static void amd_flash_resume(struct mtd_info *);
122static void amd_flash_destroy(struct mtd_info *);
123static struct mtd_info *amd_flash_probe(struct map_info *map);
124
125
126static struct mtd_chip_driver amd_flash_chipdrv = {
127 .probe = amd_flash_probe,
128 .destroy = amd_flash_destroy,
129 .name = "amd_flash",
130 .module = THIS_MODULE
131};
132
133static inline __u32 wide_read(struct map_info *map, __u32 addr)
134{
135 if (map->buswidth == 1) {
136 return map_read8(map, addr);
137 } else if (map->buswidth == 2) {
138 return map_read16(map, addr);
139 } else if (map->buswidth == 4) {
140 return map_read32(map, addr);
141 }
142
143 return 0;
144}
145
146static inline void wide_write(struct map_info *map, __u32 val, __u32 addr)
147{
148 if (map->buswidth == 1) {
149 map_write8(map, val, addr);
150 } else if (map->buswidth == 2) {
151 map_write16(map, val, addr);
152 } else if (map->buswidth == 4) {
153 map_write32(map, val, addr);
154 }
155}
156
157static inline __u32 make_cmd(struct map_info *map, __u32 cmd)
158{
159 const struct amd_flash_private *private = map->fldrv_priv;
160 if ((private->interleave == 2) &&
161 (private->device_type == DEVICE_TYPE_X16)) {
162 cmd |= (cmd << 16);
163 }
164
165 return cmd;
166}
167
168static inline void send_unlock(struct map_info *map, unsigned long base)
169{
170 wide_write(map, (CMD_UNLOCK_DATA_1 << 16) | CMD_UNLOCK_DATA_1,
171 base + (map->buswidth * ADDR_UNLOCK_1));
172 wide_write(map, (CMD_UNLOCK_DATA_2 << 16) | CMD_UNLOCK_DATA_2,
173 base + (map->buswidth * ADDR_UNLOCK_2));
174}
175
176static inline void send_cmd(struct map_info *map, unsigned long base, __u32 cmd)
177{
178 send_unlock(map, base);
179 wide_write(map, make_cmd(map, cmd),
180 base + (map->buswidth * ADDR_UNLOCK_1));
181}
182
183static inline void send_cmd_to_addr(struct map_info *map, unsigned long base,
184 __u32 cmd, unsigned long addr)
185{
186 send_unlock(map, base);
187 wide_write(map, make_cmd(map, cmd), addr);
188}
189
190static inline int flash_is_busy(struct map_info *map, unsigned long addr,
191 int interleave)
192{
193
194 if ((interleave == 2) && (map->buswidth == 4)) {
195 __u32 read1, read2;
196
197 read1 = wide_read(map, addr);
198 read2 = wide_read(map, addr);
199
200 return (((read1 >> 16) & D6_MASK) !=
201 ((read2 >> 16) & D6_MASK)) ||
202 (((read1 & 0xffff) & D6_MASK) !=
203 ((read2 & 0xffff) & D6_MASK));
204 }
205
206 return ((wide_read(map, addr) & D6_MASK) !=
207 (wide_read(map, addr) & D6_MASK));
208}
209
210static inline void unlock_sector(struct map_info *map, unsigned long sect_addr,
211 int unlock)
212{
213 /* Sector lock address. A6 = 1 for unlock, A6 = 0 for lock */
214 int SLA = unlock ?
215 (sect_addr | (0x40 * map->buswidth)) :
216 (sect_addr & ~(0x40 * map->buswidth)) ;
217
218 __u32 cmd = make_cmd(map, CMD_UNLOCK_SECTOR);
219
220 wide_write(map, make_cmd(map, CMD_RESET_DATA), 0);
221 wide_write(map, cmd, SLA); /* 1st cycle: write cmd to any address */
222 wide_write(map, cmd, SLA); /* 2nd cycle: write cmd to any address */
223 wide_write(map, cmd, SLA); /* 3rd cycle: write cmd to SLA */
224}
225
226static inline int is_sector_locked(struct map_info *map,
227 unsigned long sect_addr)
228{
229 int status;
230
231 wide_write(map, CMD_RESET_DATA, 0);
232 send_cmd(map, sect_addr, CMD_MANUFACTURER_UNLOCK_DATA);
233
234 /* status is 0x0000 for unlocked and 0x0001 for locked */
235 status = wide_read(map, sect_addr + (map->buswidth * ADDR_SECTOR_LOCK));
236 wide_write(map, CMD_RESET_DATA, 0);
237 return status;
238}
239
240static int amd_flash_do_unlock(struct mtd_info *mtd, loff_t ofs, size_t len,
241 int is_unlock)
242{
243 struct map_info *map;
244 struct mtd_erase_region_info *merip;
245 int eraseoffset, erasesize, eraseblocks;
246 int i;
247 int retval = 0;
248 int lock_status;
249
250 map = mtd->priv;
251
252 /* Pass the whole chip through sector by sector and check for each
253 sector if the sector and the given interval overlap */
254 for(i = 0; i < mtd->numeraseregions; i++) {
255 merip = &mtd->eraseregions[i];
256
257 eraseoffset = merip->offset;
258 erasesize = merip->erasesize;
259 eraseblocks = merip->numblocks;
260
261 if (ofs > eraseoffset + erasesize)
262 continue;
263
264 while (eraseblocks > 0) {
265 if (ofs < eraseoffset + erasesize && ofs + len > eraseoffset) {
266 unlock_sector(map, eraseoffset, is_unlock);
267
268 lock_status = is_sector_locked(map, eraseoffset);
269
270 if (is_unlock && lock_status) {
271 printk("Cannot unlock sector at address %x length %xx\n",
272 eraseoffset, merip->erasesize);
273 retval = -1;
274 } else if (!is_unlock && !lock_status) {
275 printk("Cannot lock sector at address %x length %x\n",
276 eraseoffset, merip->erasesize);
277 retval = -1;
278 }
279 }
280 eraseoffset += erasesize;
281 eraseblocks --;
282 }
283 }
284 return retval;
285}
286
287static int amd_flash_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
288{
289 return amd_flash_do_unlock(mtd, ofs, len, 1);
290}
291
292static int amd_flash_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
293{
294 return amd_flash_do_unlock(mtd, ofs, len, 0);
295}
296
297
298/*
299 * Reads JEDEC manufacturer ID and device ID and returns the index of the first
300 * matching table entry (-1 if not found or alias for already found chip).
301 */
302static int probe_new_chip(struct mtd_info *mtd, __u32 base,
303 struct flchip *chips,
304 struct amd_flash_private *private,
305 const struct amd_flash_info *table, int table_size)
306{
307 __u32 mfr_id;
308 __u32 dev_id;
309 struct map_info *map = mtd->priv;
310 struct amd_flash_private temp;
311 int i;
312
313 temp.device_type = DEVICE_TYPE_X16; // Assume X16 (FIXME)
314 temp.interleave = 2;
315 map->fldrv_priv = &temp;
316
317 /* Enter autoselect mode. */
318 send_cmd(map, base, CMD_RESET_DATA);
319 send_cmd(map, base, CMD_MANUFACTURER_UNLOCK_DATA);
320
321 mfr_id = wide_read(map, base + (map->buswidth * ADDR_MANUFACTURER));
322 dev_id = wide_read(map, base + (map->buswidth * ADDR_DEVICE_ID));
323
324 if ((map->buswidth == 4) && ((mfr_id >> 16) == (mfr_id & 0xffff)) &&
325 ((dev_id >> 16) == (dev_id & 0xffff))) {
326 mfr_id &= 0xffff;
327 dev_id &= 0xffff;
328 } else {
329 temp.interleave = 1;
330 }
331
332 for (i = 0; i < table_size; i++) {
333 if ((mfr_id == table[i].mfr_id) &&
334 (dev_id == table[i].dev_id)) {
335 if (chips) {
336 int j;
337
338 /* Is this an alias for an already found chip?
339 * In that case that chip should be in
340 * autoselect mode now.
341 */
342 for (j = 0; j < private->numchips; j++) {
343 __u32 mfr_id_other;
344 __u32 dev_id_other;
345
346 mfr_id_other =
347 wide_read(map, chips[j].start +
348 (map->buswidth *
349 ADDR_MANUFACTURER
350 ));
351 dev_id_other =
352 wide_read(map, chips[j].start +
353 (map->buswidth *
354 ADDR_DEVICE_ID));
355 if (temp.interleave == 2) {
356 mfr_id_other &= 0xffff;
357 dev_id_other &= 0xffff;
358 }
359 if ((mfr_id_other == mfr_id) &&
360 (dev_id_other == dev_id)) {
361
362 /* Exit autoselect mode. */
363 send_cmd(map, base,
364 CMD_RESET_DATA);
365
366 return -1;
367 }
368 }
369
370 if (private->numchips == MAX_AMD_CHIPS) {
371 printk(KERN_WARNING
372 "%s: Too many flash chips "
373 "detected. Increase "
374 "MAX_AMD_CHIPS from %d.\n",
375 map->name, MAX_AMD_CHIPS);
376
377 return -1;
378 }
379
380 chips[private->numchips].start = base;
381 chips[private->numchips].state = FL_READY;
382 chips[private->numchips].mutex =
383 &chips[private->numchips]._spinlock;
384 private->numchips++;
385 }
386
387 printk("%s: Found %d x %ldMiB %s at 0x%x\n", map->name,
388 temp.interleave, (table[i].size)/(1024*1024),
389 table[i].name, base);
390
391 mtd->size += table[i].size * temp.interleave;
392 mtd->numeraseregions += table[i].numeraseregions;
393
394 break;
395 }
396 }
397
398 /* Exit autoselect mode. */
399 send_cmd(map, base, CMD_RESET_DATA);
400
401 if (i == table_size) {
402 printk(KERN_DEBUG "%s: unknown flash device at 0x%x, "
403 "mfr id 0x%x, dev id 0x%x\n", map->name,
404 base, mfr_id, dev_id);
405 map->fldrv_priv = NULL;
406
407 return -1;
408 }
409
410 private->device_type = temp.device_type;
411 private->interleave = temp.interleave;
412
413 return i;
414}
415
416
417
418static struct mtd_info *amd_flash_probe(struct map_info *map)
419{
420 static const struct amd_flash_info table[] = {
421 {
422 .mfr_id = MANUFACTURER_AMD,
423 .dev_id = AM29LV160DT,
424 .name = "AMD AM29LV160DT",
425 .size = 0x00200000,
426 .numeraseregions = 4,
427 .regions = {
428 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },
429 { .offset = 0x1F0000, .erasesize = 0x08000, .numblocks = 1 },
430 { .offset = 0x1F8000, .erasesize = 0x02000, .numblocks = 2 },
431 { .offset = 0x1FC000, .erasesize = 0x04000, .numblocks = 1 }
432 }
433 }, {
434 .mfr_id = MANUFACTURER_AMD,
435 .dev_id = AM29LV160DB,
436 .name = "AMD AM29LV160DB",
437 .size = 0x00200000,
438 .numeraseregions = 4,
439 .regions = {
440 { .offset = 0x000000, .erasesize = 0x04000, .numblocks = 1 },
441 { .offset = 0x004000, .erasesize = 0x02000, .numblocks = 2 },
442 { .offset = 0x008000, .erasesize = 0x08000, .numblocks = 1 },
443 { .offset = 0x010000, .erasesize = 0x10000, .numblocks = 31 }
444 }
445 }, {
446 .mfr_id = MANUFACTURER_TOSHIBA,
447 .dev_id = TC58FVT160,
448 .name = "Toshiba TC58FVT160",
449 .size = 0x00200000,
450 .numeraseregions = 4,
451 .regions = {
452 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },
453 { .offset = 0x1F0000, .erasesize = 0x08000, .numblocks = 1 },
454 { .offset = 0x1F8000, .erasesize = 0x02000, .numblocks = 2 },
455 { .offset = 0x1FC000, .erasesize = 0x04000, .numblocks = 1 }
456 }
457 }, {
458 .mfr_id = MANUFACTURER_FUJITSU,
459 .dev_id = MBM29LV160TE,
460 .name = "Fujitsu MBM29LV160TE",
461 .size = 0x00200000,
462 .numeraseregions = 4,
463 .regions = {
464 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },
465 { .offset = 0x1F0000, .erasesize = 0x08000, .numblocks = 1 },
466 { .offset = 0x1F8000, .erasesize = 0x02000, .numblocks = 2 },
467 { .offset = 0x1FC000, .erasesize = 0x04000, .numblocks = 1 }
468 }
469 }, {
470 .mfr_id = MANUFACTURER_TOSHIBA,
471 .dev_id = TC58FVB160,
472 .name = "Toshiba TC58FVB160",
473 .size = 0x00200000,
474 .numeraseregions = 4,
475 .regions = {
476 { .offset = 0x000000, .erasesize = 0x04000, .numblocks = 1 },
477 { .offset = 0x004000, .erasesize = 0x02000, .numblocks = 2 },
478 { .offset = 0x008000, .erasesize = 0x08000, .numblocks = 1 },
479 { .offset = 0x010000, .erasesize = 0x10000, .numblocks = 31 }
480 }
481 }, {
482 .mfr_id = MANUFACTURER_FUJITSU,
483 .dev_id = MBM29LV160BE,
484 .name = "Fujitsu MBM29LV160BE",
485 .size = 0x00200000,
486 .numeraseregions = 4,
487 .regions = {
488 { .offset = 0x000000, .erasesize = 0x04000, .numblocks = 1 },
489 { .offset = 0x004000, .erasesize = 0x02000, .numblocks = 2 },
490 { .offset = 0x008000, .erasesize = 0x08000, .numblocks = 1 },
491 { .offset = 0x010000, .erasesize = 0x10000, .numblocks = 31 }
492 }
493 }, {
494 .mfr_id = MANUFACTURER_AMD,
495 .dev_id = AM29LV800BB,
496 .name = "AMD AM29LV800BB",
497 .size = 0x00100000,
498 .numeraseregions = 4,
499 .regions = {
500 { .offset = 0x000000, .erasesize = 0x04000, .numblocks = 1 },
501 { .offset = 0x004000, .erasesize = 0x02000, .numblocks = 2 },
502 { .offset = 0x008000, .erasesize = 0x08000, .numblocks = 1 },
503 { .offset = 0x010000, .erasesize = 0x10000, .numblocks = 15 }
504 }
505 }, {
506 .mfr_id = MANUFACTURER_AMD,
507 .dev_id = AM29F800BB,
508 .name = "AMD AM29F800BB",
509 .size = 0x00100000,
510 .numeraseregions = 4,
511 .regions = {
512 { .offset = 0x000000, .erasesize = 0x04000, .numblocks = 1 },
513 { .offset = 0x004000, .erasesize = 0x02000, .numblocks = 2 },
514 { .offset = 0x008000, .erasesize = 0x08000, .numblocks = 1 },
515 { .offset = 0x010000, .erasesize = 0x10000, .numblocks = 15 }
516 }
517 }, {
518 .mfr_id = MANUFACTURER_AMD,
519 .dev_id = AM29LV800BT,
520 .name = "AMD AM29LV800BT",
521 .size = 0x00100000,
522 .numeraseregions = 4,
523 .regions = {
524 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 15 },
525 { .offset = 0x0F0000, .erasesize = 0x08000, .numblocks = 1 },
526 { .offset = 0x0F8000, .erasesize = 0x02000, .numblocks = 2 },
527 { .offset = 0x0FC000, .erasesize = 0x04000, .numblocks = 1 }
528 }
529 }, {
530 .mfr_id = MANUFACTURER_AMD,
531 .dev_id = AM29F800BT,
532 .name = "AMD AM29F800BT",
533 .size = 0x00100000,
534 .numeraseregions = 4,
535 .regions = {
536 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 15 },
537 { .offset = 0x0F0000, .erasesize = 0x08000, .numblocks = 1 },
538 { .offset = 0x0F8000, .erasesize = 0x02000, .numblocks = 2 },
539 { .offset = 0x0FC000, .erasesize = 0x04000, .numblocks = 1 }
540 }
541 }, {
542 .mfr_id = MANUFACTURER_AMD,
543 .dev_id = AM29LV800BB,
544 .name = "AMD AM29LV800BB",
545 .size = 0x00100000,
546 .numeraseregions = 4,
547 .regions = {
548 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 15 },
549 { .offset = 0x0F0000, .erasesize = 0x08000, .numblocks = 1 },
550 { .offset = 0x0F8000, .erasesize = 0x02000, .numblocks = 2 },
551 { .offset = 0x0FC000, .erasesize = 0x04000, .numblocks = 1 }
552 }
553 }, {
554 .mfr_id = MANUFACTURER_FUJITSU,
555 .dev_id = MBM29LV800BB,
556 .name = "Fujitsu MBM29LV800BB",
557 .size = 0x00100000,
558 .numeraseregions = 4,
559 .regions = {
560 { .offset = 0x000000, .erasesize = 0x04000, .numblocks = 1 },
561 { .offset = 0x004000, .erasesize = 0x02000, .numblocks = 2 },
562 { .offset = 0x008000, .erasesize = 0x08000, .numblocks = 1 },
563 { .offset = 0x010000, .erasesize = 0x10000, .numblocks = 15 }
564 }
565 }, {
566 .mfr_id = MANUFACTURER_ST,
567 .dev_id = M29W800T,
568 .name = "ST M29W800T",
569 .size = 0x00100000,
570 .numeraseregions = 4,
571 .regions = {
572 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 15 },
573 { .offset = 0x0F0000, .erasesize = 0x08000, .numblocks = 1 },
574 { .offset = 0x0F8000, .erasesize = 0x02000, .numblocks = 2 },
575 { .offset = 0x0FC000, .erasesize = 0x04000, .numblocks = 1 }
576 }
577 }, {
578 .mfr_id = MANUFACTURER_ST,
579 .dev_id = M29W160DT,
580 .name = "ST M29W160DT",
581 .size = 0x00200000,
582 .numeraseregions = 4,
583 .regions = {
584 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },
585 { .offset = 0x1F0000, .erasesize = 0x08000, .numblocks = 1 },
586 { .offset = 0x1F8000, .erasesize = 0x02000, .numblocks = 2 },
587 { .offset = 0x1FC000, .erasesize = 0x04000, .numblocks = 1 }
588 }
589 }, {
590 .mfr_id = MANUFACTURER_ST,
591 .dev_id = M29W160DB,
592 .name = "ST M29W160DB",
593 .size = 0x00200000,
594 .numeraseregions = 4,
595 .regions = {
596 { .offset = 0x000000, .erasesize = 0x04000, .numblocks = 1 },
597 { .offset = 0x004000, .erasesize = 0x02000, .numblocks = 2 },
598 { .offset = 0x008000, .erasesize = 0x08000, .numblocks = 1 },
599 { .offset = 0x010000, .erasesize = 0x10000, .numblocks = 31 }
600 }
601 }, {
602 .mfr_id = MANUFACTURER_AMD,
603 .dev_id = AM29BDS323D,
604 .name = "AMD AM29BDS323D",
605 .size = 0x00400000,
606 .numeraseregions = 3,
607 .regions = {
608 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 48 },
609 { .offset = 0x300000, .erasesize = 0x10000, .numblocks = 15 },
610 { .offset = 0x3f0000, .erasesize = 0x02000, .numblocks = 8 },
611 }
612 }, {
613 .mfr_id = MANUFACTURER_ATMEL,
614 .dev_id = AT49xV16x,
615 .name = "Atmel AT49xV16x",
616 .size = 0x00200000,
617 .numeraseregions = 2,
618 .regions = {
619 { .offset = 0x000000, .erasesize = 0x02000, .numblocks = 8 },
620 { .offset = 0x010000, .erasesize = 0x10000, .numblocks = 31 }
621 }
622 }, {
623 .mfr_id = MANUFACTURER_ATMEL,
624 .dev_id = AT49xV16xT,
625 .name = "Atmel AT49xV16xT",
626 .size = 0x00200000,
627 .numeraseregions = 2,
628 .regions = {
629 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 31 },
630 { .offset = 0x1F0000, .erasesize = 0x02000, .numblocks = 8 }
631 }
632 }
633 };
634
635 struct mtd_info *mtd;
636 struct flchip chips[MAX_AMD_CHIPS];
637 int table_pos[MAX_AMD_CHIPS];
638 struct amd_flash_private temp;
639 struct amd_flash_private *private;
640 u_long size;
641 unsigned long base;
642 int i;
643 int reg_idx;
644 int offset;
645
646 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
647 if (!mtd) {
648 printk(KERN_WARNING
649 "%s: kmalloc failed for info structure\n", map->name);
650 return NULL;
651 }
652 mtd->priv = map;
653
654 memset(&temp, 0, sizeof(temp));
655
656 printk("%s: Probing for AMD compatible flash...\n", map->name);
657
658 if ((table_pos[0] = probe_new_chip(mtd, 0, NULL, &temp, table,
659 ARRAY_SIZE(table)))
660 == -1) {
661 printk(KERN_WARNING
662 "%s: Found no AMD compatible device at location zero\n",
663 map->name);
664 kfree(mtd);
665
666 return NULL;
667 }
668
669 chips[0].start = 0;
670 chips[0].state = FL_READY;
671 chips[0].mutex = &chips[0]._spinlock;
672 temp.numchips = 1;
673 for (size = mtd->size; size > 1; size >>= 1) {
674 temp.chipshift++;
675 }
676 switch (temp.interleave) {
677 case 2:
678 temp.chipshift += 1;
679 break;
680 case 4:
681 temp.chipshift += 2;
682 break;
683 }
684
685 /* Find out if there are any more chips in the map. */
686 for (base = (1 << temp.chipshift);
687 base < map->size;
688 base += (1 << temp.chipshift)) {
689 int numchips = temp.numchips;
690 table_pos[numchips] = probe_new_chip(mtd, base, chips,
691 &temp, table, ARRAY_SIZE(table));
692 }
693
694 mtd->eraseregions = kmalloc(sizeof(struct mtd_erase_region_info) *
695 mtd->numeraseregions, GFP_KERNEL);
696 if (!mtd->eraseregions) {
697 printk(KERN_WARNING "%s: Failed to allocate "
698 "memory for MTD erase region info\n", map->name);
699 kfree(mtd);
700 map->fldrv_priv = NULL;
701 return NULL;
702 }
703
704 reg_idx = 0;
705 offset = 0;
706 for (i = 0; i < temp.numchips; i++) {
707 int dev_size;
708 int j;
709
710 dev_size = 0;
711 for (j = 0; j < table[table_pos[i]].numeraseregions; j++) {
712 mtd->eraseregions[reg_idx].offset = offset +
713 (table[table_pos[i]].regions[j].offset *
714 temp.interleave);
715 mtd->eraseregions[reg_idx].erasesize =
716 table[table_pos[i]].regions[j].erasesize *
717 temp.interleave;
718 mtd->eraseregions[reg_idx].numblocks =
719 table[table_pos[i]].regions[j].numblocks;
720 if (mtd->erasesize <
721 mtd->eraseregions[reg_idx].erasesize) {
722 mtd->erasesize =
723 mtd->eraseregions[reg_idx].erasesize;
724 }
725 dev_size += mtd->eraseregions[reg_idx].erasesize *
726 mtd->eraseregions[reg_idx].numblocks;
727 reg_idx++;
728 }
729 offset += dev_size;
730 }
731 mtd->type = MTD_NORFLASH;
732 mtd->writesize = 1;
733 mtd->flags = MTD_CAP_NORFLASH;
734 mtd->name = map->name;
735 mtd->erase = amd_flash_erase;
736 mtd->read = amd_flash_read;
737 mtd->write = amd_flash_write;
738 mtd->sync = amd_flash_sync;
739 mtd->suspend = amd_flash_suspend;
740 mtd->resume = amd_flash_resume;
741 mtd->lock = amd_flash_lock;
742 mtd->unlock = amd_flash_unlock;
743
744 private = kmalloc(sizeof(*private) + (sizeof(struct flchip) *
745 temp.numchips), GFP_KERNEL);
746 if (!private) {
747 printk(KERN_WARNING
748 "%s: kmalloc failed for private structure\n", map->name);
749 kfree(mtd);
750 map->fldrv_priv = NULL;
751 return NULL;
752 }
753 memcpy(private, &temp, sizeof(temp));
754 memcpy(private->chips, chips,
755 sizeof(struct flchip) * private->numchips);
756 for (i = 0; i < private->numchips; i++) {
757 init_waitqueue_head(&private->chips[i].wq);
758 spin_lock_init(&private->chips[i]._spinlock);
759 }
760
761 map->fldrv_priv = private;
762
763 map->fldrv = &amd_flash_chipdrv;
764
765 __module_get(THIS_MODULE);
766 return mtd;
767}
768
769
770
771static inline int read_one_chip(struct map_info *map, struct flchip *chip,
772 loff_t adr, size_t len, u_char *buf)
773{
774 DECLARE_WAITQUEUE(wait, current);
775 unsigned long timeo = jiffies + HZ;
776
777retry:
778 spin_lock_bh(chip->mutex);
779
780 if (chip->state != FL_READY){
781 printk(KERN_INFO "%s: waiting for chip to read, state = %d\n",
782 map->name, chip->state);
783 set_current_state(TASK_UNINTERRUPTIBLE);
784 add_wait_queue(&chip->wq, &wait);
785
786 spin_unlock_bh(chip->mutex);
787
788 schedule();
789 remove_wait_queue(&chip->wq, &wait);
790
791 if(signal_pending(current)) {
792 return -EINTR;
793 }
794
795 timeo = jiffies + HZ;
796
797 goto retry;
798 }
799
800 adr += chip->start;
801
802 chip->state = FL_READY;
803
804 map_copy_from(map, buf, adr, len);
805
806 wake_up(&chip->wq);
807 spin_unlock_bh(chip->mutex);
808
809 return 0;
810}
811
812
813
814static int amd_flash_read(struct mtd_info *mtd, loff_t from, size_t len,
815 size_t *retlen, u_char *buf)
816{
817 struct map_info *map = mtd->priv;
818 struct amd_flash_private *private = map->fldrv_priv;
819 unsigned long ofs;
820 int chipnum;
821 int ret = 0;
822
823 if ((from + len) > mtd->size) {
824 printk(KERN_WARNING "%s: read request past end of device "
825 "(0x%lx)\n", map->name, (unsigned long)from + len);
826
827 return -EINVAL;
828 }
829
830 /* Offset within the first chip that the first read should start. */
831 chipnum = (from >> private->chipshift);
832 ofs = from - (chipnum << private->chipshift);
833
834 *retlen = 0;
835
836 while (len) {
837 unsigned long this_len;
838
839 if (chipnum >= private->numchips) {
840 break;
841 }
842
843 if ((len + ofs - 1) >> private->chipshift) {
844 this_len = (1 << private->chipshift) - ofs;
845 } else {
846 this_len = len;
847 }
848
849 ret = read_one_chip(map, &private->chips[chipnum], ofs,
850 this_len, buf);
851 if (ret) {
852 break;
853 }
854
855 *retlen += this_len;
856 len -= this_len;
857 buf += this_len;
858
859 ofs = 0;
860 chipnum++;
861 }
862
863 return ret;
864}
865
866
867
868static int write_one_word(struct map_info *map, struct flchip *chip,
869 unsigned long adr, __u32 datum)
870{
871 unsigned long timeo = jiffies + HZ;
872 struct amd_flash_private *private = map->fldrv_priv;
873 DECLARE_WAITQUEUE(wait, current);
874 int ret = 0;
875 int times_left;
876
877retry:
878 spin_lock_bh(chip->mutex);
879
880 if (chip->state != FL_READY){
881 printk("%s: waiting for chip to write, state = %d\n",
882 map->name, chip->state);
883 set_current_state(TASK_UNINTERRUPTIBLE);
884 add_wait_queue(&chip->wq, &wait);
885
886 spin_unlock_bh(chip->mutex);
887
888 schedule();
889 remove_wait_queue(&chip->wq, &wait);
890 printk(KERN_INFO "%s: woke up to write\n", map->name);
891 if(signal_pending(current))
892 return -EINTR;
893
894 timeo = jiffies + HZ;
895
896 goto retry;
897 }
898
899 chip->state = FL_WRITING;
900
901 adr += chip->start;
902 ENABLE_VPP(map);
903 send_cmd(map, chip->start, CMD_PROGRAM_UNLOCK_DATA);
904 wide_write(map, datum, adr);
905
906 times_left = 500000;
907 while (times_left-- && flash_is_busy(map, adr, private->interleave)) {
908 if (need_resched()) {
909 spin_unlock_bh(chip->mutex);
910 schedule();
911 spin_lock_bh(chip->mutex);
912 }
913 }
914
915 if (!times_left) {
916 printk(KERN_WARNING "%s: write to 0x%lx timed out!\n",
917 map->name, adr);
918 ret = -EIO;
919 } else {
920 __u32 verify;
921 if ((verify = wide_read(map, adr)) != datum) {
922 printk(KERN_WARNING "%s: write to 0x%lx failed. "
923 "datum = %x, verify = %x\n",
924 map->name, adr, datum, verify);
925 ret = -EIO;
926 }
927 }
928
929 DISABLE_VPP(map);
930 chip->state = FL_READY;
931 wake_up(&chip->wq);
932 spin_unlock_bh(chip->mutex);
933
934 return ret;
935}
936
937
938
939static int amd_flash_write(struct mtd_info *mtd, loff_t to , size_t len,
940 size_t *retlen, const u_char *buf)
941{
942 struct map_info *map = mtd->priv;
943 struct amd_flash_private *private = map->fldrv_priv;
944 int ret = 0;
945 int chipnum;
946 unsigned long ofs;
947 unsigned long chipstart;
948
949 *retlen = 0;
950 if (!len) {
951 return 0;
952 }
953
954 chipnum = to >> private->chipshift;
955 ofs = to - (chipnum << private->chipshift);
956 chipstart = private->chips[chipnum].start;
957
958 /* If it's not bus-aligned, do the first byte write. */
959 if (ofs & (map->buswidth - 1)) {
960 unsigned long bus_ofs = ofs & ~(map->buswidth - 1);
961 int i = ofs - bus_ofs;
962 int n = 0;
963 u_char tmp_buf[4];
964 __u32 datum;
965
966 map_copy_from(map, tmp_buf,
967 bus_ofs + private->chips[chipnum].start,
968 map->buswidth);
969 while (len && i < map->buswidth)
970 tmp_buf[i++] = buf[n++], len--;
971
972 if (map->buswidth == 2) {
973 datum = *(__u16*)tmp_buf;
974 } else if (map->buswidth == 4) {
975 datum = *(__u32*)tmp_buf;
976 } else {
977 return -EINVAL; /* should never happen, but be safe */
978 }
979
980 ret = write_one_word(map, &private->chips[chipnum], bus_ofs,
981 datum);
982 if (ret) {
983 return ret;
984 }
985
986 ofs += n;
987 buf += n;
988 (*retlen) += n;
989
990 if (ofs >> private->chipshift) {
991 chipnum++;
992 ofs = 0;
993 if (chipnum == private->numchips) {
994 return 0;
995 }
996 }
997 }
998
999 /* We are now aligned, write as much as possible. */
1000 while(len >= map->buswidth) {
1001 __u32 datum;
1002
1003 if (map->buswidth == 1) {
1004 datum = *(__u8*)buf;
1005 } else if (map->buswidth == 2) {
1006 datum = *(__u16*)buf;
1007 } else if (map->buswidth == 4) {
1008 datum = *(__u32*)buf;
1009 } else {
1010 return -EINVAL;
1011 }
1012
1013 ret = write_one_word(map, &private->chips[chipnum], ofs, datum);
1014
1015 if (ret) {
1016 return ret;
1017 }
1018
1019 ofs += map->buswidth;
1020 buf += map->buswidth;
1021 (*retlen) += map->buswidth;
1022 len -= map->buswidth;
1023
1024 if (ofs >> private->chipshift) {
1025 chipnum++;
1026 ofs = 0;
1027 if (chipnum == private->numchips) {
1028 return 0;
1029 }
1030 chipstart = private->chips[chipnum].start;
1031 }
1032 }
1033
1034 if (len & (map->buswidth - 1)) {
1035 int i = 0, n = 0;
1036 u_char tmp_buf[2];
1037 __u32 datum;
1038
1039 map_copy_from(map, tmp_buf,
1040 ofs + private->chips[chipnum].start,
1041 map->buswidth);
1042 while (len--) {
1043 tmp_buf[i++] = buf[n++];
1044 }
1045
1046 if (map->buswidth == 2) {
1047 datum = *(__u16*)tmp_buf;
1048 } else if (map->buswidth == 4) {
1049 datum = *(__u32*)tmp_buf;
1050 } else {
1051 return -EINVAL; /* should never happen, but be safe */
1052 }
1053
1054 ret = write_one_word(map, &private->chips[chipnum], ofs, datum);
1055
1056 if (ret) {
1057 return ret;
1058 }
1059
1060 (*retlen) += n;
1061 }
1062
1063 return 0;
1064}
1065
1066
1067
1068static inline int erase_one_block(struct map_info *map, struct flchip *chip,
1069 unsigned long adr, u_long size)
1070{
1071 unsigned long timeo = jiffies + HZ;
1072 struct amd_flash_private *private = map->fldrv_priv;
1073 DECLARE_WAITQUEUE(wait, current);
1074
1075retry:
1076 spin_lock_bh(chip->mutex);
1077
1078 if (chip->state != FL_READY){
1079 set_current_state(TASK_UNINTERRUPTIBLE);
1080 add_wait_queue(&chip->wq, &wait);
1081
1082 spin_unlock_bh(chip->mutex);
1083
1084 schedule();
1085 remove_wait_queue(&chip->wq, &wait);
1086
1087 if (signal_pending(current)) {
1088 return -EINTR;
1089 }
1090
1091 timeo = jiffies + HZ;
1092
1093 goto retry;
1094 }
1095
1096 chip->state = FL_ERASING;
1097
1098 adr += chip->start;
1099 ENABLE_VPP(map);
1100 send_cmd(map, chip->start, CMD_SECTOR_ERASE_UNLOCK_DATA);
1101 send_cmd_to_addr(map, chip->start, CMD_SECTOR_ERASE_UNLOCK_DATA_2, adr);
1102
1103 timeo = jiffies + (HZ * 20);
1104
1105 spin_unlock_bh(chip->mutex);
1106 msleep(1000);
1107 spin_lock_bh(chip->mutex);
1108
1109 while (flash_is_busy(map, adr, private->interleave)) {
1110
1111 if (chip->state != FL_ERASING) {
1112 /* Someone's suspended the erase. Sleep */
1113 set_current_state(TASK_UNINTERRUPTIBLE);
1114 add_wait_queue(&chip->wq, &wait);
1115
1116 spin_unlock_bh(chip->mutex);
1117 printk(KERN_INFO "%s: erase suspended. Sleeping\n",
1118 map->name);
1119 schedule();
1120 remove_wait_queue(&chip->wq, &wait);
1121
1122 if (signal_pending(current)) {
1123 return -EINTR;
1124 }
1125
1126 timeo = jiffies + (HZ*2); /* FIXME */
1127 spin_lock_bh(chip->mutex);
1128 continue;
1129 }
1130
1131 /* OK Still waiting */
1132 if (time_after(jiffies, timeo)) {
1133 chip->state = FL_READY;
1134 spin_unlock_bh(chip->mutex);
1135 printk(KERN_WARNING "%s: waiting for erase to complete "
1136 "timed out.\n", map->name);
1137 DISABLE_VPP(map);
1138
1139 return -EIO;
1140 }
1141
1142 /* Latency issues. Drop the lock, wait a while and retry */
1143 spin_unlock_bh(chip->mutex);
1144
1145 if (need_resched())
1146 schedule();
1147 else
1148 udelay(1);
1149
1150 spin_lock_bh(chip->mutex);
1151 }
1152
1153 /* Verify every single word */
1154 {
1155 int address;
1156 int error = 0;
1157 __u8 verify;
1158
1159 for (address = adr; address < (adr + size); address++) {
1160 if ((verify = map_read8(map, address)) != 0xFF) {
1161 error = 1;
1162 break;
1163 }
1164 }
1165 if (error) {
1166 chip->state = FL_READY;
1167 spin_unlock_bh(chip->mutex);
1168 printk(KERN_WARNING
1169 "%s: verify error at 0x%x, size %ld.\n",
1170 map->name, address, size);
1171 DISABLE_VPP(map);
1172
1173 return -EIO;
1174 }
1175 }
1176
1177 DISABLE_VPP(map);
1178 chip->state = FL_READY;
1179 wake_up(&chip->wq);
1180 spin_unlock_bh(chip->mutex);
1181
1182 return 0;
1183}
1184
1185
1186
1187static int amd_flash_erase(struct mtd_info *mtd, struct erase_info *instr)
1188{
1189 struct map_info *map = mtd->priv;
1190 struct amd_flash_private *private = map->fldrv_priv;
1191 unsigned long adr, len;
1192 int chipnum;
1193 int ret = 0;
1194 int i;
1195 int first;
1196 struct mtd_erase_region_info *regions = mtd->eraseregions;
1197
1198 if (instr->addr > mtd->size) {
1199 return -EINVAL;
1200 }
1201
1202 if ((instr->len + instr->addr) > mtd->size) {
1203 return -EINVAL;
1204 }
1205
1206 /* Check that both start and end of the requested erase are
1207 * aligned with the erasesize at the appropriate addresses.
1208 */
1209
1210 i = 0;
1211
1212 /* Skip all erase regions which are ended before the start of
1213 the requested erase. Actually, to save on the calculations,
1214 we skip to the first erase region which starts after the
1215 start of the requested erase, and then go back one.
1216 */
1217
1218 while ((i < mtd->numeraseregions) &&
1219 (instr->addr >= regions[i].offset)) {
1220 i++;
1221 }
1222 i--;
1223
1224 /* OK, now i is pointing at the erase region in which this
1225 * erase request starts. Check the start of the requested
1226 * erase range is aligned with the erase size which is in
1227 * effect here.
1228 */
1229
1230 if (instr->addr & (regions[i].erasesize-1)) {
1231 return -EINVAL;
1232 }
1233
1234 /* Remember the erase region we start on. */
1235
1236 first = i;
1237
1238 /* Next, check that the end of the requested erase is aligned
1239 * with the erase region at that address.
1240 */
1241
1242 while ((i < mtd->numeraseregions) &&
1243 ((instr->addr + instr->len) >= regions[i].offset)) {
1244 i++;
1245 }
1246
1247 /* As before, drop back one to point at the region in which
1248 * the address actually falls.
1249 */
1250
1251 i--;
1252
1253 if ((instr->addr + instr->len) & (regions[i].erasesize-1)) {
1254 return -EINVAL;
1255 }
1256
1257 chipnum = instr->addr >> private->chipshift;
1258 adr = instr->addr - (chipnum << private->chipshift);
1259 len = instr->len;
1260
1261 i = first;
1262
1263 while (len) {
1264 ret = erase_one_block(map, &private->chips[chipnum], adr,
1265 regions[i].erasesize);
1266
1267 if (ret) {
1268 return ret;
1269 }
1270
1271 adr += regions[i].erasesize;
1272 len -= regions[i].erasesize;
1273
1274 if ((adr % (1 << private->chipshift)) ==
1275 ((regions[i].offset + (regions[i].erasesize *
1276 regions[i].numblocks))
1277 % (1 << private->chipshift))) {
1278 i++;
1279 }
1280
1281 if (adr >> private->chipshift) {
1282 adr = 0;
1283 chipnum++;
1284 if (chipnum >= private->numchips) {
1285 break;
1286 }
1287 }
1288 }
1289
1290 instr->state = MTD_ERASE_DONE;
1291 mtd_erase_callback(instr);
1292
1293 return 0;
1294}
1295
1296
1297
1298static void amd_flash_sync(struct mtd_info *mtd)
1299{
1300 struct map_info *map = mtd->priv;
1301 struct amd_flash_private *private = map->fldrv_priv;
1302 int i;
1303 struct flchip *chip;
1304 int ret = 0;
1305 DECLARE_WAITQUEUE(wait, current);
1306
1307 for (i = 0; !ret && (i < private->numchips); i++) {
1308 chip = &private->chips[i];
1309
1310 retry:
1311 spin_lock_bh(chip->mutex);
1312
1313 switch(chip->state) {
1314 case FL_READY:
1315 case FL_STATUS:
1316 case FL_CFI_QUERY:
1317 case FL_JEDEC_QUERY:
1318 chip->oldstate = chip->state;
1319 chip->state = FL_SYNCING;
1320 /* No need to wake_up() on this state change -
1321 * as the whole point is that nobody can do anything
1322 * with the chip now anyway.
1323 */
1324 case FL_SYNCING:
1325 spin_unlock_bh(chip->mutex);
1326 break;
1327
1328 default:
1329 /* Not an idle state */
1330 add_wait_queue(&chip->wq, &wait);
1331
1332 spin_unlock_bh(chip->mutex);
1333
1334 schedule();
1335
1336 remove_wait_queue(&chip->wq, &wait);
1337
1338 goto retry;
1339 }
1340 }
1341
1342 /* Unlock the chips again */
1343 for (i--; i >= 0; i--) {
1344 chip = &private->chips[i];
1345
1346 spin_lock_bh(chip->mutex);
1347
1348 if (chip->state == FL_SYNCING) {
1349 chip->state = chip->oldstate;
1350 wake_up(&chip->wq);
1351 }
1352 spin_unlock_bh(chip->mutex);
1353 }
1354}
1355
1356
1357
1358static int amd_flash_suspend(struct mtd_info *mtd)
1359{
1360printk("amd_flash_suspend(): not implemented!\n");
1361 return -EINVAL;
1362}
1363
1364
1365
1366static void amd_flash_resume(struct mtd_info *mtd)
1367{
1368printk("amd_flash_resume(): not implemented!\n");
1369}
1370
1371
1372
1373static void amd_flash_destroy(struct mtd_info *mtd)
1374{
1375 struct map_info *map = mtd->priv;
1376 struct amd_flash_private *private = map->fldrv_priv;
1377 kfree(private);
1378}
1379
1380int __init amd_flash_init(void)
1381{
1382 register_mtd_chip_driver(&amd_flash_chipdrv);
1383 return 0;
1384}
1385
1386void __exit amd_flash_exit(void)
1387{
1388 unregister_mtd_chip_driver(&amd_flash_chipdrv);
1389}
1390
1391module_init(amd_flash_init);
1392module_exit(amd_flash_exit);
1393
1394MODULE_LICENSE("GPL");
1395MODULE_AUTHOR("Jonas Holmberg <jonas.holmberg@axis.com>");
1396MODULE_DESCRIPTION("Old MTD chip driver for AMD flash chips");
diff --git a/drivers/mtd/chips/jedec.c b/drivers/mtd/chips/jedec.c
deleted file mode 100644
index 14e57b2bf842..000000000000
--- a/drivers/mtd/chips/jedec.c
+++ /dev/null
@@ -1,935 +0,0 @@
1
2/* JEDEC Flash Interface.
3 * This is an older type of interface for self programming flash. It is
4 * commonly use in older AMD chips and is obsolete compared with CFI.
5 * It is called JEDEC because the JEDEC association distributes the ID codes
6 * for the chips.
7 *
8 * See the AMD flash databook for information on how to operate the interface.
9 *
10 * This code does not support anything wider than 8 bit flash chips, I am
11 * not going to guess how to send commands to them, plus I expect they will
12 * all speak CFI..
13 *
14 * $Id: jedec.c,v 1.22 2005/01/05 18:05:11 dwmw2 Exp $
15 */
16
17#include <linux/init.h>
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/slab.h>
21#include <linux/mtd/jedec.h>
22#include <linux/mtd/map.h>
23#include <linux/mtd/mtd.h>
24#include <linux/mtd/compatmac.h>
25
26static struct mtd_info *jedec_probe(struct map_info *);
27static int jedec_probe8(struct map_info *map,unsigned long base,
28 struct jedec_private *priv);
29static int jedec_probe16(struct map_info *map,unsigned long base,
30 struct jedec_private *priv);
31static int jedec_probe32(struct map_info *map,unsigned long base,
32 struct jedec_private *priv);
33static void jedec_flash_chip_scan(struct jedec_private *priv,unsigned long start,
34 unsigned long len);
35static int flash_erase(struct mtd_info *mtd, struct erase_info *instr);
36static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
37 size_t *retlen, const u_char *buf);
38
39static unsigned long my_bank_size;
40
41/* Listing of parts and sizes. We need this table to learn the sector
42 size of the chip and the total length */
43static const struct JEDECTable JEDEC_table[] = {
44 {
45 .jedec = 0x013D,
46 .name = "AMD Am29F017D",
47 .size = 2*1024*1024,
48 .sectorsize = 64*1024,
49 .capabilities = MTD_CAP_NORFLASH
50 },
51 {
52 .jedec = 0x01AD,
53 .name = "AMD Am29F016",
54 .size = 2*1024*1024,
55 .sectorsize = 64*1024,
56 .capabilities = MTD_CAP_NORFLASH
57 },
58 {
59 .jedec = 0x01D5,
60 .name = "AMD Am29F080",
61 .size = 1*1024*1024,
62 .sectorsize = 64*1024,
63 .capabilities = MTD_CAP_NORFLASH
64 },
65 {
66 .jedec = 0x01A4,
67 .name = "AMD Am29F040",
68 .size = 512*1024,
69 .sectorsize = 64*1024,
70 .capabilities = MTD_CAP_NORFLASH
71 },
72 {
73 .jedec = 0x20E3,
74 .name = "AMD Am29W040B",
75 .size = 512*1024,
76 .sectorsize = 64*1024,
77 .capabilities = MTD_CAP_NORFLASH
78 },
79 {
80 .jedec = 0xC2AD,
81 .name = "Macronix MX29F016",
82 .size = 2*1024*1024,
83 .sectorsize = 64*1024,
84 .capabilities = MTD_CAP_NORFLASH
85 },
86 { .jedec = 0x0 }
87};
88
89static const struct JEDECTable *jedec_idtoinf(__u8 mfr,__u8 id);
90static void jedec_sync(struct mtd_info *mtd) {};
91static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len,
92 size_t *retlen, u_char *buf);
93static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len,
94 size_t *retlen, u_char *buf);
95
96static struct mtd_info *jedec_probe(struct map_info *map);
97
98
99
100static struct mtd_chip_driver jedec_chipdrv = {
101 .probe = jedec_probe,
102 .name = "jedec",
103 .module = THIS_MODULE
104};
105
106/* Probe entry point */
107
108static struct mtd_info *jedec_probe(struct map_info *map)
109{
110 struct mtd_info *MTD;
111 struct jedec_private *priv;
112 unsigned long Base;
113 unsigned long SectorSize;
114 unsigned count;
115 unsigned I,Uniq;
116 char Part[200];
117 memset(&priv,0,sizeof(priv));
118
119 MTD = kzalloc(sizeof(struct mtd_info) + sizeof(struct jedec_private), GFP_KERNEL);
120 if (!MTD)
121 return NULL;
122
123 priv = (struct jedec_private *)&MTD[1];
124
125 my_bank_size = map->size;
126
127 if (map->size/my_bank_size > MAX_JEDEC_CHIPS)
128 {
129 printk("mtd: Increase MAX_JEDEC_CHIPS, too many banks.\n");
130 kfree(MTD);
131 return NULL;
132 }
133
134 for (Base = 0; Base < map->size; Base += my_bank_size)
135 {
136 // Perhaps zero could designate all tests?
137 if (map->buswidth == 0)
138 map->buswidth = 1;
139
140 if (map->buswidth == 1){
141 if (jedec_probe8(map,Base,priv) == 0) {
142 printk("did recognize jedec chip\n");
143 kfree(MTD);
144 return NULL;
145 }
146 }
147 if (map->buswidth == 2)
148 jedec_probe16(map,Base,priv);
149 if (map->buswidth == 4)
150 jedec_probe32(map,Base,priv);
151 }
152
153 // Get the biggest sector size
154 SectorSize = 0;
155 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
156 {
157 // printk("priv->chips[%d].jedec is %x\n",I,priv->chips[I].jedec);
158 // printk("priv->chips[%d].sectorsize is %lx\n",I,priv->chips[I].sectorsize);
159 if (priv->chips[I].sectorsize > SectorSize)
160 SectorSize = priv->chips[I].sectorsize;
161 }
162
163 // Quickly ensure that the other sector sizes are factors of the largest
164 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
165 {
166 if ((SectorSize/priv->chips[I].sectorsize)*priv->chips[I].sectorsize != SectorSize)
167 {
168 printk("mtd: Failed. Device has incompatible mixed sector sizes\n");
169 kfree(MTD);
170 return NULL;
171 }
172 }
173
174 /* Generate a part name that includes the number of different chips and
175 other configuration information */
176 count = 1;
177 strlcpy(Part,map->name,sizeof(Part)-10);
178 strcat(Part," ");
179 Uniq = 0;
180 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
181 {
182 const struct JEDECTable *JEDEC;
183
184 if (priv->chips[I+1].jedec == priv->chips[I].jedec)
185 {
186 count++;
187 continue;
188 }
189
190 // Locate the chip in the jedec table
191 JEDEC = jedec_idtoinf(priv->chips[I].jedec >> 8,priv->chips[I].jedec);
192 if (JEDEC == 0)
193 {
194 printk("mtd: Internal Error, JEDEC not set\n");
195 kfree(MTD);
196 return NULL;
197 }
198
199 if (Uniq != 0)
200 strcat(Part,",");
201 Uniq++;
202
203 if (count != 1)
204 sprintf(Part+strlen(Part),"%x*[%s]",count,JEDEC->name);
205 else
206 sprintf(Part+strlen(Part),"%s",JEDEC->name);
207 if (strlen(Part) > sizeof(Part)*2/3)
208 break;
209 count = 1;
210 }
211
212 /* Determine if the chips are organized in a linear fashion, or if there
213 are empty banks. Note, the last bank does not count here, only the
214 first banks are important. Holes on non-bank boundaries can not exist
215 due to the way the detection algorithm works. */
216 if (priv->size < my_bank_size)
217 my_bank_size = priv->size;
218 priv->is_banked = 0;
219 //printk("priv->size is %x, my_bank_size is %x\n",priv->size,my_bank_size);
220 //printk("priv->bank_fill[0] is %x\n",priv->bank_fill[0]);
221 if (!priv->size) {
222 printk("priv->size is zero\n");
223 kfree(MTD);
224 return NULL;
225 }
226 if (priv->size/my_bank_size) {
227 if (priv->size/my_bank_size == 1) {
228 priv->size = my_bank_size;
229 }
230 else {
231 for (I = 0; I != priv->size/my_bank_size - 1; I++)
232 {
233 if (priv->bank_fill[I] != my_bank_size)
234 priv->is_banked = 1;
235
236 /* This even could be eliminated, but new de-optimized read/write
237 functions have to be written */
238 printk("priv->bank_fill[%d] is %lx, priv->bank_fill[0] is %lx\n",I,priv->bank_fill[I],priv->bank_fill[0]);
239 if (priv->bank_fill[I] != priv->bank_fill[0])
240 {
241 printk("mtd: Failed. Cannot handle unsymmetric banking\n");
242 kfree(MTD);
243 return NULL;
244 }
245 }
246 }
247 }
248 if (priv->is_banked == 1)
249 strcat(Part,", banked");
250
251 // printk("Part: '%s'\n",Part);
252
253 memset(MTD,0,sizeof(*MTD));
254 // strlcpy(MTD->name,Part,sizeof(MTD->name));
255 MTD->name = map->name;
256 MTD->type = MTD_NORFLASH;
257 MTD->flags = MTD_CAP_NORFLASH;
258 MTD->writesize = 1;
259 MTD->erasesize = SectorSize*(map->buswidth);
260 // printk("MTD->erasesize is %x\n",(unsigned int)MTD->erasesize);
261 MTD->size = priv->size;
262 // printk("MTD->size is %x\n",(unsigned int)MTD->size);
263 //MTD->module = THIS_MODULE; // ? Maybe this should be the low level module?
264 MTD->erase = flash_erase;
265 if (priv->is_banked == 1)
266 MTD->read = jedec_read_banked;
267 else
268 MTD->read = jedec_read;
269 MTD->write = flash_write;
270 MTD->sync = jedec_sync;
271 MTD->priv = map;
272 map->fldrv_priv = priv;
273 map->fldrv = &jedec_chipdrv;
274 __module_get(THIS_MODULE);
275 return MTD;
276}
277
278/* Helper for the JEDEC function, JEDEC numbers all have odd parity */
279static int checkparity(u_char C)
280{
281 u_char parity = 0;
282 while (C != 0)
283 {
284 parity ^= C & 1;
285 C >>= 1;
286 }
287
288 return parity == 1;
289}
290
291
292/* Take an array of JEDEC numbers that represent interleved flash chips
293 and process them. Check to make sure they are good JEDEC numbers, look
294 them up and then add them to the chip list */
295static int handle_jedecs(struct map_info *map,__u8 *Mfg,__u8 *Id,unsigned Count,
296 unsigned long base,struct jedec_private *priv)
297{
298 unsigned I,J;
299 unsigned long Size;
300 unsigned long SectorSize;
301 const struct JEDECTable *JEDEC;
302
303 // Test #2 JEDEC numbers exhibit odd parity
304 for (I = 0; I != Count; I++)
305 {
306 if (checkparity(Mfg[I]) == 0 || checkparity(Id[I]) == 0)
307 return 0;
308 }
309
310 // Finally, just make sure all the chip sizes are the same
311 JEDEC = jedec_idtoinf(Mfg[0],Id[0]);
312
313 if (JEDEC == 0)
314 {
315 printk("mtd: Found JEDEC flash chip, but do not have a table entry for %x:%x\n",Mfg[0],Mfg[1]);
316 return 0;
317 }
318
319 Size = JEDEC->size;
320 SectorSize = JEDEC->sectorsize;
321 for (I = 0; I != Count; I++)
322 {
323 JEDEC = jedec_idtoinf(Mfg[0],Id[0]);
324 if (JEDEC == 0)
325 {
326 printk("mtd: Found JEDEC flash chip, but do not have a table entry for %x:%x\n",Mfg[0],Mfg[1]);
327 return 0;
328 }
329
330 if (Size != JEDEC->size || SectorSize != JEDEC->sectorsize)
331 {
332 printk("mtd: Failed. Interleved flash does not have matching characteristics\n");
333 return 0;
334 }
335 }
336
337 // Load the Chips
338 for (I = 0; I != MAX_JEDEC_CHIPS; I++)
339 {
340 if (priv->chips[I].jedec == 0)
341 break;
342 }
343
344 if (I + Count > MAX_JEDEC_CHIPS)
345 {
346 printk("mtd: Device has too many chips. Increase MAX_JEDEC_CHIPS\n");
347 return 0;
348 }
349
350 // Add them to the table
351 for (J = 0; J != Count; J++)
352 {
353 unsigned long Bank;
354
355 JEDEC = jedec_idtoinf(Mfg[J],Id[J]);
356 priv->chips[I].jedec = (Mfg[J] << 8) | Id[J];
357 priv->chips[I].size = JEDEC->size;
358 priv->chips[I].sectorsize = JEDEC->sectorsize;
359 priv->chips[I].base = base + J;
360 priv->chips[I].datashift = J*8;
361 priv->chips[I].capabilities = JEDEC->capabilities;
362 priv->chips[I].offset = priv->size + J;
363
364 // log2 n :|
365 priv->chips[I].addrshift = 0;
366 for (Bank = Count; Bank != 1; Bank >>= 1, priv->chips[I].addrshift++);
367
368 // Determine how filled this bank is.
369 Bank = base & (~(my_bank_size-1));
370 if (priv->bank_fill[Bank/my_bank_size] < base +
371 (JEDEC->size << priv->chips[I].addrshift) - Bank)
372 priv->bank_fill[Bank/my_bank_size] = base + (JEDEC->size << priv->chips[I].addrshift) - Bank;
373 I++;
374 }
375
376 priv->size += priv->chips[I-1].size*Count;
377
378 return priv->chips[I-1].size;
379}
380
381/* Lookup the chip information from the JEDEC ID table. */
382static const struct JEDECTable *jedec_idtoinf(__u8 mfr,__u8 id)
383{
384 __u16 Id = (mfr << 8) | id;
385 unsigned long I = 0;
386 for (I = 0; JEDEC_table[I].jedec != 0; I++)
387 if (JEDEC_table[I].jedec == Id)
388 return JEDEC_table + I;
389 return NULL;
390}
391
392// Look for flash using an 8 bit bus interface
393static int jedec_probe8(struct map_info *map,unsigned long base,
394 struct jedec_private *priv)
395{
396 #define flread(x) map_read8(map,base+x)
397 #define flwrite(v,x) map_write8(map,v,base+x)
398
399 const unsigned long AutoSel1 = 0xAA;
400 const unsigned long AutoSel2 = 0x55;
401 const unsigned long AutoSel3 = 0x90;
402 const unsigned long Reset = 0xF0;
403 __u32 OldVal;
404 __u8 Mfg[1];
405 __u8 Id[1];
406 unsigned I;
407 unsigned long Size;
408
409 // Wait for any write/erase operation to settle
410 OldVal = flread(base);
411 for (I = 0; OldVal != flread(base) && I < 10000; I++)
412 OldVal = flread(base);
413
414 // Reset the chip
415 flwrite(Reset,0x555);
416
417 // Send the sequence
418 flwrite(AutoSel1,0x555);
419 flwrite(AutoSel2,0x2AA);
420 flwrite(AutoSel3,0x555);
421
422 // Get the JEDEC numbers
423 Mfg[0] = flread(0);
424 Id[0] = flread(1);
425 // printk("Mfg is %x, Id is %x\n",Mfg[0],Id[0]);
426
427 Size = handle_jedecs(map,Mfg,Id,1,base,priv);
428 // printk("handle_jedecs Size is %x\n",(unsigned int)Size);
429 if (Size == 0)
430 {
431 flwrite(Reset,0x555);
432 return 0;
433 }
434
435
436 // Reset.
437 flwrite(Reset,0x555);
438
439 return 1;
440
441 #undef flread
442 #undef flwrite
443}
444
445// Look for flash using a 16 bit bus interface (ie 2 8-bit chips)
446static int jedec_probe16(struct map_info *map,unsigned long base,
447 struct jedec_private *priv)
448{
449 return 0;
450}
451
452// Look for flash using a 32 bit bus interface (ie 4 8-bit chips)
453static int jedec_probe32(struct map_info *map,unsigned long base,
454 struct jedec_private *priv)
455{
456 #define flread(x) map_read32(map,base+((x)<<2))
457 #define flwrite(v,x) map_write32(map,v,base+((x)<<2))
458
459 const unsigned long AutoSel1 = 0xAAAAAAAA;
460 const unsigned long AutoSel2 = 0x55555555;
461 const unsigned long AutoSel3 = 0x90909090;
462 const unsigned long Reset = 0xF0F0F0F0;
463 __u32 OldVal;
464 __u8 Mfg[4];
465 __u8 Id[4];
466 unsigned I;
467 unsigned long Size;
468
469 // Wait for any write/erase operation to settle
470 OldVal = flread(base);
471 for (I = 0; OldVal != flread(base) && I < 10000; I++)
472 OldVal = flread(base);
473
474 // Reset the chip
475 flwrite(Reset,0x555);
476
477 // Send the sequence
478 flwrite(AutoSel1,0x555);
479 flwrite(AutoSel2,0x2AA);
480 flwrite(AutoSel3,0x555);
481
482 // Test #1, JEDEC numbers are readable from 0x??00/0x??01
483 if (flread(0) != flread(0x100) ||
484 flread(1) != flread(0x101))
485 {
486 flwrite(Reset,0x555);
487 return 0;
488 }
489
490 // Split up the JEDEC numbers
491 OldVal = flread(0);
492 for (I = 0; I != 4; I++)
493 Mfg[I] = (OldVal >> (I*8));
494 OldVal = flread(1);
495 for (I = 0; I != 4; I++)
496 Id[I] = (OldVal >> (I*8));
497
498 Size = handle_jedecs(map,Mfg,Id,4,base,priv);
499 if (Size == 0)
500 {
501 flwrite(Reset,0x555);
502 return 0;
503 }
504
505 /* Check if there is address wrap around within a single bank, if this
506 returns JEDEC numbers then we assume that it is wrap around. Notice
507 we call this routine with the JEDEC return still enabled, if two or
508 more flashes have a truncated address space the probe test will still
509 work */
510 if (base + (Size<<2)+0x555 < map->size &&
511 base + (Size<<2)+0x555 < (base & (~(my_bank_size-1))) + my_bank_size)
512 {
513 if (flread(base+Size) != flread(base+Size + 0x100) ||
514 flread(base+Size + 1) != flread(base+Size + 0x101))
515 {
516 jedec_probe32(map,base+Size,priv);
517 }
518 }
519
520 // Reset.
521 flwrite(0xF0F0F0F0,0x555);
522
523 return 1;
524
525 #undef flread
526 #undef flwrite
527}
528
529/* Linear read. */
530static int jedec_read(struct mtd_info *mtd, loff_t from, size_t len,
531 size_t *retlen, u_char *buf)
532{
533 struct map_info *map = mtd->priv;
534
535 map_copy_from(map, buf, from, len);
536 *retlen = len;
537 return 0;
538}
539
540/* Banked read. Take special care to jump past the holes in the bank
541 mapping. This version assumes symetry in the holes.. */
542static int jedec_read_banked(struct mtd_info *mtd, loff_t from, size_t len,
543 size_t *retlen, u_char *buf)
544{
545 struct map_info *map = mtd->priv;
546 struct jedec_private *priv = map->fldrv_priv;
547
548 *retlen = 0;
549 while (len > 0)
550 {
551 // Determine what bank and offset into that bank the first byte is
552 unsigned long bank = from & (~(priv->bank_fill[0]-1));
553 unsigned long offset = from & (priv->bank_fill[0]-1);
554 unsigned long get = len;
555 if (priv->bank_fill[0] - offset < len)
556 get = priv->bank_fill[0] - offset;
557
558 bank /= priv->bank_fill[0];
559 map_copy_from(map,buf + *retlen,bank*my_bank_size + offset,get);
560
561 len -= get;
562 *retlen += get;
563 from += get;
564 }
565 return 0;
566}
567
568/* Pass the flags value that the flash return before it re-entered read
569 mode. */
570static void jedec_flash_failed(unsigned char code)
571{
572 /* Bit 5 being high indicates that there was an internal device
573 failure, erasure time limits exceeded or something */
574 if ((code & (1 << 5)) != 0)
575 {
576 printk("mtd: Internal Flash failure\n");
577 return;
578 }
579 printk("mtd: Programming didn't take\n");
580}
581
582/* This uses the erasure function described in the AMD Flash Handbook,
583 it will work for flashes with a fixed sector size only. Flashes with
584 a selection of sector sizes (ie the AMD Am29F800B) will need a different
585 routine. This routine tries to parallize erasing multiple chips/sectors
586 where possible */
587static int flash_erase(struct mtd_info *mtd, struct erase_info *instr)
588{
589 // Does IO to the currently selected chip
590 #define flread(x) map_read8(map,chip->base+((x)<<chip->addrshift))
591 #define flwrite(v,x) map_write8(map,v,chip->base+((x)<<chip->addrshift))
592
593 unsigned long Time = 0;
594 unsigned long NoTime = 0;
595 unsigned long start = instr->addr, len = instr->len;
596 unsigned int I;
597 struct map_info *map = mtd->priv;
598 struct jedec_private *priv = map->fldrv_priv;
599
600 // Verify the arguments..
601 if (start + len > mtd->size ||
602 (start % mtd->erasesize) != 0 ||
603 (len % mtd->erasesize) != 0 ||
604 (len/mtd->erasesize) == 0)
605 return -EINVAL;
606
607 jedec_flash_chip_scan(priv,start,len);
608
609 // Start the erase sequence on each chip
610 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
611 {
612 unsigned long off;
613 struct jedec_flash_chip *chip = priv->chips + I;
614
615 if (chip->length == 0)
616 continue;
617
618 if (chip->start + chip->length > chip->size)
619 {
620 printk("DIE\n");
621 return -EIO;
622 }
623
624 flwrite(0xF0,chip->start + 0x555);
625 flwrite(0xAA,chip->start + 0x555);
626 flwrite(0x55,chip->start + 0x2AA);
627 flwrite(0x80,chip->start + 0x555);
628 flwrite(0xAA,chip->start + 0x555);
629 flwrite(0x55,chip->start + 0x2AA);
630
631 /* Once we start selecting the erase sectors the delay between each
632 command must not exceed 50us or it will immediately start erasing
633 and ignore the other sectors */
634 for (off = 0; off < len; off += chip->sectorsize)
635 {
636 // Check to make sure we didn't timeout
637 flwrite(0x30,chip->start + off);
638 if (off == 0)
639 continue;
640 if ((flread(chip->start + off) & (1 << 3)) != 0)
641 {
642 printk("mtd: Ack! We timed out the erase timer!\n");
643 return -EIO;
644 }
645 }
646 }
647
648 /* We could split this into a timer routine and return early, performing
649 background erasure.. Maybe later if the need warrents */
650
651 /* Poll the flash for erasure completion, specs say this can take as long
652 as 480 seconds to do all the sectors (for a 2 meg flash).
653 Erasure time is dependent on chip age, temp and wear.. */
654
655 /* This being a generic routine assumes a 32 bit bus. It does read32s
656 and bundles interleved chips into the same grouping. This will work
657 for all bus widths */
658 Time = 0;
659 NoTime = 0;
660 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
661 {
662 struct jedec_flash_chip *chip = priv->chips + I;
663 unsigned long off = 0;
664 unsigned todo[4] = {0,0,0,0};
665 unsigned todo_left = 0;
666 unsigned J;
667
668 if (chip->length == 0)
669 continue;
670
671 /* Find all chips in this data line, realistically this is all
672 or nothing up to the interleve count */
673 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++)
674 {
675 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) ==
676 (chip->base & (~((1<<chip->addrshift)-1))))
677 {
678 todo_left++;
679 todo[priv->chips[J].base & ((1<<chip->addrshift)-1)] = 1;
680 }
681 }
682
683 /* printk("todo: %x %x %x %x\n",(short)todo[0],(short)todo[1],
684 (short)todo[2],(short)todo[3]);
685 */
686 while (1)
687 {
688 __u32 Last[4];
689 unsigned long Count = 0;
690
691 /* During erase bit 7 is held low and bit 6 toggles, we watch this,
692 should it stop toggling or go high then the erase is completed,
693 or this is not really flash ;> */
694 switch (map->buswidth) {
695 case 1:
696 Last[0] = map_read8(map,(chip->base >> chip->addrshift) + chip->start + off);
697 Last[1] = map_read8(map,(chip->base >> chip->addrshift) + chip->start + off);
698 Last[2] = map_read8(map,(chip->base >> chip->addrshift) + chip->start + off);
699 break;
700 case 2:
701 Last[0] = map_read16(map,(chip->base >> chip->addrshift) + chip->start + off);
702 Last[1] = map_read16(map,(chip->base >> chip->addrshift) + chip->start + off);
703 Last[2] = map_read16(map,(chip->base >> chip->addrshift) + chip->start + off);
704 break;
705 case 3:
706 Last[0] = map_read32(map,(chip->base >> chip->addrshift) + chip->start + off);
707 Last[1] = map_read32(map,(chip->base >> chip->addrshift) + chip->start + off);
708 Last[2] = map_read32(map,(chip->base >> chip->addrshift) + chip->start + off);
709 break;
710 }
711 Count = 3;
712 while (todo_left != 0)
713 {
714 for (J = 0; J != 4; J++)
715 {
716 __u8 Byte1 = (Last[(Count-1)%4] >> (J*8)) & 0xFF;
717 __u8 Byte2 = (Last[(Count-2)%4] >> (J*8)) & 0xFF;
718 __u8 Byte3 = (Last[(Count-3)%4] >> (J*8)) & 0xFF;
719 if (todo[J] == 0)
720 continue;
721
722 if ((Byte1 & (1 << 7)) == 0 && Byte1 != Byte2)
723 {
724// printk("Check %x %x %x\n",(short)J,(short)Byte1,(short)Byte2);
725 continue;
726 }
727
728 if (Byte1 == Byte2)
729 {
730 jedec_flash_failed(Byte3);
731 return -EIO;
732 }
733
734 todo[J] = 0;
735 todo_left--;
736 }
737
738/* if (NoTime == 0)
739 Time += HZ/10 - schedule_timeout(HZ/10);*/
740 NoTime = 0;
741
742 switch (map->buswidth) {
743 case 1:
744 Last[Count % 4] = map_read8(map,(chip->base >> chip->addrshift) + chip->start + off);
745 break;
746 case 2:
747 Last[Count % 4] = map_read16(map,(chip->base >> chip->addrshift) + chip->start + off);
748 break;
749 case 4:
750 Last[Count % 4] = map_read32(map,(chip->base >> chip->addrshift) + chip->start + off);
751 break;
752 }
753 Count++;
754
755/* // Count time, max of 15s per sector (according to AMD)
756 if (Time > 15*len/mtd->erasesize*HZ)
757 {
758 printk("mtd: Flash Erase Timed out\n");
759 return -EIO;
760 } */
761 }
762
763 // Skip to the next chip if we used chip erase
764 if (chip->length == chip->size)
765 off = chip->size;
766 else
767 off += chip->sectorsize;
768
769 if (off >= chip->length)
770 break;
771 NoTime = 1;
772 }
773
774 for (J = 0; priv->chips[J].jedec != 0 && J < MAX_JEDEC_CHIPS; J++)
775 {
776 if ((priv->chips[J].base & (~((1<<chip->addrshift)-1))) ==
777 (chip->base & (~((1<<chip->addrshift)-1))))
778 priv->chips[J].length = 0;
779 }
780 }
781
782 //printk("done\n");
783 instr->state = MTD_ERASE_DONE;
784 mtd_erase_callback(instr);
785 return 0;
786
787 #undef flread
788 #undef flwrite
789}
790
791/* This is the simple flash writing function. It writes to every byte, in
792 sequence. It takes care of how to properly address the flash if
793 the flash is interleved. It can only be used if all the chips in the
794 array are identical!*/
795static int flash_write(struct mtd_info *mtd, loff_t start, size_t len,
796 size_t *retlen, const u_char *buf)
797{
798 /* Does IO to the currently selected chip. It takes the bank addressing
799 base (which is divisible by the chip size) adds the necessary lower bits
800 of addrshift (interleave index) and then adds the control register index. */
801 #define flread(x) map_read8(map,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift))
802 #define flwrite(v,x) map_write8(map,v,base+(off&((1<<chip->addrshift)-1))+((x)<<chip->addrshift))
803
804 struct map_info *map = mtd->priv;
805 struct jedec_private *priv = map->fldrv_priv;
806 unsigned long base;
807 unsigned long off;
808 size_t save_len = len;
809
810 if (start + len > mtd->size)
811 return -EIO;
812
813 //printk("Here");
814
815 //printk("flash_write: start is %x, len is %x\n",start,(unsigned long)len);
816 while (len != 0)
817 {
818 struct jedec_flash_chip *chip = priv->chips;
819 unsigned long bank;
820 unsigned long boffset;
821
822 // Compute the base of the flash.
823 off = ((unsigned long)start) % (chip->size << chip->addrshift);
824 base = start - off;
825
826 // Perform banked addressing translation.
827 bank = base & (~(priv->bank_fill[0]-1));
828 boffset = base & (priv->bank_fill[0]-1);
829 bank = (bank/priv->bank_fill[0])*my_bank_size;
830 base = bank + boffset;
831
832 // printk("Flasing %X %X %X\n",base,chip->size,len);
833 // printk("off is %x, compare with %x\n",off,chip->size << chip->addrshift);
834
835 // Loop over this page
836 for (; off != (chip->size << chip->addrshift) && len != 0; start++, len--, off++,buf++)
837 {
838 unsigned char oldbyte = map_read8(map,base+off);
839 unsigned char Last[4];
840 unsigned long Count = 0;
841
842 if (oldbyte == *buf) {
843 // printk("oldbyte and *buf is %x,len is %x\n",oldbyte,len);
844 continue;
845 }
846 if (((~oldbyte) & *buf) != 0)
847 printk("mtd: warn: Trying to set a 0 to a 1\n");
848
849 // Write
850 flwrite(0xAA,0x555);
851 flwrite(0x55,0x2AA);
852 flwrite(0xA0,0x555);
853 map_write8(map,*buf,base + off);
854 Last[0] = map_read8(map,base + off);
855 Last[1] = map_read8(map,base + off);
856 Last[2] = map_read8(map,base + off);
857
858 /* Wait for the flash to finish the operation. We store the last 4
859 status bytes that have been retrieved so we can determine why
860 it failed. The toggle bits keep toggling when there is a
861 failure */
862 for (Count = 3; Last[(Count - 1) % 4] != Last[(Count - 2) % 4] &&
863 Count < 10000; Count++)
864 Last[Count % 4] = map_read8(map,base + off);
865 if (Last[(Count - 1) % 4] != *buf)
866 {
867 jedec_flash_failed(Last[(Count - 3) % 4]);
868 return -EIO;
869 }
870 }
871 }
872 *retlen = save_len;
873 return 0;
874}
875
876/* This is used to enhance the speed of the erase routine,
877 when things are being done to multiple chips it is possible to
878 parallize the operations, particularly full memory erases of multi
879 chip memories benifit */
880static void jedec_flash_chip_scan(struct jedec_private *priv,unsigned long start,
881 unsigned long len)
882{
883 unsigned int I;
884
885 // Zero the records
886 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
887 priv->chips[I].start = priv->chips[I].length = 0;
888
889 // Intersect the region with each chip
890 for (I = 0; priv->chips[I].jedec != 0 && I < MAX_JEDEC_CHIPS; I++)
891 {
892 struct jedec_flash_chip *chip = priv->chips + I;
893 unsigned long ByteStart;
894 unsigned long ChipEndByte = chip->offset + (chip->size << chip->addrshift);
895
896 // End is before this chip or the start is after it
897 if (start+len < chip->offset ||
898 ChipEndByte - (1 << chip->addrshift) < start)
899 continue;
900
901 if (start < chip->offset)
902 {
903 ByteStart = chip->offset;
904 chip->start = 0;
905 }
906 else
907 {
908 chip->start = (start - chip->offset + (1 << chip->addrshift)-1) >> chip->addrshift;
909 ByteStart = start;
910 }
911
912 if (start + len >= ChipEndByte)
913 chip->length = (ChipEndByte - ByteStart) >> chip->addrshift;
914 else
915 chip->length = (start + len - ByteStart + (1 << chip->addrshift)-1) >> chip->addrshift;
916 }
917}
918
919int __init jedec_init(void)
920{
921 register_mtd_chip_driver(&jedec_chipdrv);
922 return 0;
923}
924
925static void __exit jedec_exit(void)
926{
927 unregister_mtd_chip_driver(&jedec_chipdrv);
928}
929
930module_init(jedec_init);
931module_exit(jedec_exit);
932
933MODULE_LICENSE("GPL");
934MODULE_AUTHOR("Jason Gunthorpe <jgg@deltatee.com> et al.");
935MODULE_DESCRIPTION("Old MTD chip driver for JEDEC-compliant flash chips");
diff --git a/drivers/mtd/chips/sharp.c b/drivers/mtd/chips/sharp.c
deleted file mode 100644
index c9cd3d21ccfa..000000000000
--- a/drivers/mtd/chips/sharp.c
+++ /dev/null
@@ -1,601 +0,0 @@
1/*
2 * MTD chip driver for pre-CFI Sharp flash chips
3 *
4 * Copyright 2000,2001 David A. Schleef <ds@schleef.org>
5 * 2000,2001 Lineo, Inc.
6 *
7 * $Id: sharp.c,v 1.17 2005/11/29 14:28:28 gleixner Exp $
8 *
9 * Devices supported:
10 * LH28F016SCT Symmetrical block flash memory, 2Mx8
11 * LH28F008SCT Symmetrical block flash memory, 1Mx8
12 *
13 * Documentation:
14 * http://www.sharpmeg.com/datasheets/memic/flashcmp/
15 * http://www.sharpmeg.com/datasheets/memic/flashcmp/01symf/16m/016sctl9.pdf
16 * 016sctl9.pdf
17 *
18 * Limitations:
19 * This driver only supports 4x1 arrangement of chips.
20 * Not tested on anything but PowerPC.
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/types.h>
26#include <linux/sched.h>
27#include <linux/errno.h>
28#include <linux/interrupt.h>
29#include <linux/mtd/map.h>
30#include <linux/mtd/mtd.h>
31#include <linux/mtd/cfi.h>
32#include <linux/delay.h>
33#include <linux/init.h>
34#include <linux/slab.h>
35
36#define CMD_RESET 0xffffffff
37#define CMD_READ_ID 0x90909090
38#define CMD_READ_STATUS 0x70707070
39#define CMD_CLEAR_STATUS 0x50505050
40#define CMD_BLOCK_ERASE_1 0x20202020
41#define CMD_BLOCK_ERASE_2 0xd0d0d0d0
42#define CMD_BYTE_WRITE 0x40404040
43#define CMD_SUSPEND 0xb0b0b0b0
44#define CMD_RESUME 0xd0d0d0d0
45#define CMD_SET_BLOCK_LOCK_1 0x60606060
46#define CMD_SET_BLOCK_LOCK_2 0x01010101
47#define CMD_SET_MASTER_LOCK_1 0x60606060
48#define CMD_SET_MASTER_LOCK_2 0xf1f1f1f1
49#define CMD_CLEAR_BLOCK_LOCKS_1 0x60606060
50#define CMD_CLEAR_BLOCK_LOCKS_2 0xd0d0d0d0
51
52#define SR_READY 0x80808080 // 1 = ready
53#define SR_ERASE_SUSPEND 0x40404040 // 1 = block erase suspended
54#define SR_ERROR_ERASE 0x20202020 // 1 = error in block erase or clear lock bits
55#define SR_ERROR_WRITE 0x10101010 // 1 = error in byte write or set lock bit
56#define SR_VPP 0x08080808 // 1 = Vpp is low
57#define SR_WRITE_SUSPEND 0x04040404 // 1 = byte write suspended
58#define SR_PROTECT 0x02020202 // 1 = lock bit set
59#define SR_RESERVED 0x01010101
60
61#define SR_ERRORS (SR_ERROR_ERASE|SR_ERROR_WRITE|SR_VPP|SR_PROTECT)
62
63/* Configuration options */
64
65#undef AUTOUNLOCK /* automatically unlocks blocks before erasing */
66
67static struct mtd_info *sharp_probe(struct map_info *);
68
69static int sharp_probe_map(struct map_info *map,struct mtd_info *mtd);
70
71static int sharp_read(struct mtd_info *mtd, loff_t from, size_t len,
72 size_t *retlen, u_char *buf);
73static int sharp_write(struct mtd_info *mtd, loff_t from, size_t len,
74 size_t *retlen, const u_char *buf);
75static int sharp_erase(struct mtd_info *mtd, struct erase_info *instr);
76static void sharp_sync(struct mtd_info *mtd);
77static int sharp_suspend(struct mtd_info *mtd);
78static void sharp_resume(struct mtd_info *mtd);
79static void sharp_destroy(struct mtd_info *mtd);
80
81static int sharp_write_oneword(struct map_info *map, struct flchip *chip,
82 unsigned long adr, __u32 datum);
83static int sharp_erase_oneblock(struct map_info *map, struct flchip *chip,
84 unsigned long adr);
85#ifdef AUTOUNLOCK
86static void sharp_unlock_oneblock(struct map_info *map, struct flchip *chip,
87 unsigned long adr);
88#endif
89
90
91struct sharp_info{
92 struct flchip *chip;
93 int bogus;
94 int chipshift;
95 int numchips;
96 struct flchip chips[1];
97};
98
99static void sharp_destroy(struct mtd_info *mtd);
100
101static struct mtd_chip_driver sharp_chipdrv = {
102 .probe = sharp_probe,
103 .destroy = sharp_destroy,
104 .name = "sharp",
105 .module = THIS_MODULE
106};
107
108
109static struct mtd_info *sharp_probe(struct map_info *map)
110{
111 struct mtd_info *mtd = NULL;
112 struct sharp_info *sharp = NULL;
113 int width;
114
115 mtd = kzalloc(sizeof(*mtd), GFP_KERNEL);
116 if(!mtd)
117 return NULL;
118
119 sharp = kzalloc(sizeof(*sharp), GFP_KERNEL);
120 if(!sharp) {
121 kfree(mtd);
122 return NULL;
123 }
124
125 width = sharp_probe_map(map,mtd);
126 if(!width){
127 kfree(mtd);
128 kfree(sharp);
129 return NULL;
130 }
131
132 mtd->priv = map;
133 mtd->type = MTD_NORFLASH;
134 mtd->erase = sharp_erase;
135 mtd->read = sharp_read;
136 mtd->write = sharp_write;
137 mtd->sync = sharp_sync;
138 mtd->suspend = sharp_suspend;
139 mtd->resume = sharp_resume;
140 mtd->flags = MTD_CAP_NORFLASH;
141 mtd->writesize = 1;
142 mtd->name = map->name;
143
144 sharp->chipshift = 23;
145 sharp->numchips = 1;
146 sharp->chips[0].start = 0;
147 sharp->chips[0].state = FL_READY;
148 sharp->chips[0].mutex = &sharp->chips[0]._spinlock;
149 sharp->chips[0].word_write_time = 0;
150 init_waitqueue_head(&sharp->chips[0].wq);
151 spin_lock_init(&sharp->chips[0]._spinlock);
152
153 map->fldrv = &sharp_chipdrv;
154 map->fldrv_priv = sharp;
155
156 __module_get(THIS_MODULE);
157 return mtd;
158}
159
160static inline void sharp_send_cmd(struct map_info *map, unsigned long cmd, unsigned long adr)
161{
162 map_word map_cmd;
163 map_cmd.x[0] = cmd;
164 map_write(map, map_cmd, adr);
165}
166
167static int sharp_probe_map(struct map_info *map,struct mtd_info *mtd)
168{
169 map_word tmp, read0, read4;
170 unsigned long base = 0;
171 int width = 4;
172
173 tmp = map_read(map, base+0);
174
175 sharp_send_cmd(map, CMD_READ_ID, base+0);
176
177 read0 = map_read(map, base+0);
178 read4 = map_read(map, base+4);
179 if(read0.x[0] == 0x89898989){
180 printk("Looks like sharp flash\n");
181 switch(read4.x[0]){
182 case 0xaaaaaaaa:
183 case 0xa0a0a0a0:
184 /* aa - LH28F016SCT-L95 2Mx8, 32 64k blocks*/
185 /* a0 - LH28F016SCT-Z4 2Mx8, 32 64k blocks*/
186 mtd->erasesize = 0x10000 * width;
187 mtd->size = 0x200000 * width;
188 return width;
189 case 0xa6a6a6a6:
190 /* a6 - LH28F008SCT-L12 1Mx8, 16 64k blocks*/
191 /* a6 - LH28F008SCR-L85 1Mx8, 16 64k blocks*/
192 mtd->erasesize = 0x10000 * width;
193 mtd->size = 0x100000 * width;
194 return width;
195#if 0
196 case 0x00000000: /* unknown */
197 /* XX - LH28F004SCT 512kx8, 8 64k blocks*/
198 mtd->erasesize = 0x10000 * width;
199 mtd->size = 0x80000 * width;
200 return width;
201#endif
202 default:
203 printk("Sort-of looks like sharp flash, 0x%08lx 0x%08lx\n",
204 read0.x[0], read4.x[0]);
205 }
206 }else if((map_read(map, base+0).x[0] == CMD_READ_ID)){
207 /* RAM, probably */
208 printk("Looks like RAM\n");
209 map_write(map, tmp, base+0);
210 }else{
211 printk("Doesn't look like sharp flash, 0x%08lx 0x%08lx\n",
212 read0.x[0], read4.x[0]);
213 }
214
215 return 0;
216}
217
218/* This function returns with the chip->mutex lock held. */
219static int sharp_wait(struct map_info *map, struct flchip *chip)
220{
221 int i;
222 map_word status;
223 unsigned long timeo = jiffies + HZ;
224 DECLARE_WAITQUEUE(wait, current);
225 int adr = 0;
226
227retry:
228 spin_lock_bh(chip->mutex);
229
230 switch(chip->state){
231 case FL_READY:
232 sharp_send_cmd(map, CMD_READ_STATUS, adr);
233 chip->state = FL_STATUS;
234 case FL_STATUS:
235 for(i=0;i<100;i++){
236 status = map_read(map, adr);
237 if((status.x[0] & SR_READY)==SR_READY)
238 break;
239 udelay(1);
240 }
241 break;
242 default:
243 printk("Waiting for chip\n");
244
245 set_current_state(TASK_INTERRUPTIBLE);
246 add_wait_queue(&chip->wq, &wait);
247
248 spin_unlock_bh(chip->mutex);
249
250 schedule();
251 remove_wait_queue(&chip->wq, &wait);
252
253 if(signal_pending(current))
254 return -EINTR;
255
256 timeo = jiffies + HZ;
257
258 goto retry;
259 }
260
261 sharp_send_cmd(map, CMD_RESET, adr);
262
263 chip->state = FL_READY;
264
265 return 0;
266}
267
268static void sharp_release(struct flchip *chip)
269{
270 wake_up(&chip->wq);
271 spin_unlock_bh(chip->mutex);
272}
273
274static int sharp_read(struct mtd_info *mtd, loff_t from, size_t len,
275 size_t *retlen, u_char *buf)
276{
277 struct map_info *map = mtd->priv;
278 struct sharp_info *sharp = map->fldrv_priv;
279 int chipnum;
280 int ret = 0;
281 int ofs = 0;
282
283 chipnum = (from >> sharp->chipshift);
284 ofs = from & ((1 << sharp->chipshift)-1);
285
286 *retlen = 0;
287
288 while(len){
289 unsigned long thislen;
290
291 if(chipnum>=sharp->numchips)
292 break;
293
294 thislen = len;
295 if(ofs+thislen >= (1<<sharp->chipshift))
296 thislen = (1<<sharp->chipshift) - ofs;
297
298 ret = sharp_wait(map,&sharp->chips[chipnum]);
299 if(ret<0)
300 break;
301
302 map_copy_from(map,buf,ofs,thislen);
303
304 sharp_release(&sharp->chips[chipnum]);
305
306 *retlen += thislen;
307 len -= thislen;
308 buf += thislen;
309
310 ofs = 0;
311 chipnum++;
312 }
313 return ret;
314}
315
316static int sharp_write(struct mtd_info *mtd, loff_t to, size_t len,
317 size_t *retlen, const u_char *buf)
318{
319 struct map_info *map = mtd->priv;
320 struct sharp_info *sharp = map->fldrv_priv;
321 int ret = 0;
322 int i,j;
323 int chipnum;
324 unsigned long ofs;
325 union { u32 l; unsigned char uc[4]; } tbuf;
326
327 *retlen = 0;
328
329 while(len){
330 tbuf.l = 0xffffffff;
331 chipnum = to >> sharp->chipshift;
332 ofs = to & ((1<<sharp->chipshift)-1);
333
334 j=0;
335 for(i=ofs&3;i<4 && len;i++){
336 tbuf.uc[i] = *buf;
337 buf++;
338 to++;
339 len--;
340 j++;
341 }
342 sharp_write_oneword(map, &sharp->chips[chipnum], ofs&~3, tbuf.l);
343 if(ret<0)
344 return ret;
345 (*retlen)+=j;
346 }
347
348 return 0;
349}
350
351static int sharp_write_oneword(struct map_info *map, struct flchip *chip,
352 unsigned long adr, __u32 datum)
353{
354 int ret;
355 int timeo;
356 int try;
357 int i;
358 map_word data, status;
359
360 status.x[0] = 0;
361 ret = sharp_wait(map,chip);
362
363 for(try=0;try<10;try++){
364 sharp_send_cmd(map, CMD_BYTE_WRITE, adr);
365 /* cpu_to_le32 -> hack to fix the writel be->le conversion */
366 data.x[0] = cpu_to_le32(datum);
367 map_write(map, data, adr);
368
369 chip->state = FL_WRITING;
370
371 timeo = jiffies + (HZ/2);
372
373 sharp_send_cmd(map, CMD_READ_STATUS, adr);
374 for(i=0;i<100;i++){
375 status = map_read(map, adr);
376 if((status.x[0] & SR_READY) == SR_READY)
377 break;
378 }
379 if(i==100){
380 printk("sharp: timed out writing\n");
381 }
382
383 if(!(status.x[0] & SR_ERRORS))
384 break;
385
386 printk("sharp: error writing byte at addr=%08lx status=%08lx\n", adr, status.x[0]);
387
388 sharp_send_cmd(map, CMD_CLEAR_STATUS, adr);
389 }
390 sharp_send_cmd(map, CMD_RESET, adr);
391 chip->state = FL_READY;
392
393 wake_up(&chip->wq);
394 spin_unlock_bh(chip->mutex);
395
396 return 0;
397}
398
399static int sharp_erase(struct mtd_info *mtd, struct erase_info *instr)
400{
401 struct map_info *map = mtd->priv;
402 struct sharp_info *sharp = map->fldrv_priv;
403 unsigned long adr,len;
404 int chipnum, ret=0;
405
406//printk("sharp_erase()\n");
407 if(instr->addr & (mtd->erasesize - 1))
408 return -EINVAL;
409 if(instr->len & (mtd->erasesize - 1))
410 return -EINVAL;
411 if(instr->len + instr->addr > mtd->size)
412 return -EINVAL;
413
414 chipnum = instr->addr >> sharp->chipshift;
415 adr = instr->addr & ((1<<sharp->chipshift)-1);
416 len = instr->len;
417
418 while(len){
419 ret = sharp_erase_oneblock(map, &sharp->chips[chipnum], adr);
420 if(ret)return ret;
421
422 adr += mtd->erasesize;
423 len -= mtd->erasesize;
424 if(adr >> sharp->chipshift){
425 adr = 0;
426 chipnum++;
427 if(chipnum>=sharp->numchips)
428 break;
429 }
430 }
431
432 instr->state = MTD_ERASE_DONE;
433 mtd_erase_callback(instr);
434
435 return 0;
436}
437
438static int sharp_do_wait_for_ready(struct map_info *map, struct flchip *chip,
439 unsigned long adr)
440{
441 int ret;
442 unsigned long timeo;
443 map_word status;
444 DECLARE_WAITQUEUE(wait, current);
445
446 sharp_send_cmd(map, CMD_READ_STATUS, adr);
447 status = map_read(map, adr);
448
449 timeo = jiffies + HZ;
450
451 while(time_before(jiffies, timeo)){
452 sharp_send_cmd(map, CMD_READ_STATUS, adr);
453 status = map_read(map, adr);
454 if((status.x[0] & SR_READY)==SR_READY){
455 ret = 0;
456 goto out;
457 }
458 set_current_state(TASK_INTERRUPTIBLE);
459 add_wait_queue(&chip->wq, &wait);
460
461 //spin_unlock_bh(chip->mutex);
462
463 schedule_timeout(1);
464 schedule();
465 remove_wait_queue(&chip->wq, &wait);
466
467 //spin_lock_bh(chip->mutex);
468
469 if (signal_pending(current)){
470 ret = -EINTR;
471 goto out;
472 }
473
474 }
475 ret = -ETIME;
476out:
477 return ret;
478}
479
480static int sharp_erase_oneblock(struct map_info *map, struct flchip *chip,
481 unsigned long adr)
482{
483 int ret;
484 //int timeo;
485 map_word status;
486 //int i;
487
488//printk("sharp_erase_oneblock()\n");
489
490#ifdef AUTOUNLOCK
491 /* This seems like a good place to do an unlock */
492 sharp_unlock_oneblock(map,chip,adr);
493#endif
494
495 sharp_send_cmd(map, CMD_BLOCK_ERASE_1, adr);
496 sharp_send_cmd(map, CMD_BLOCK_ERASE_2, adr);
497
498 chip->state = FL_ERASING;
499
500 ret = sharp_do_wait_for_ready(map,chip,adr);
501 if(ret<0)return ret;
502
503 sharp_send_cmd(map, CMD_READ_STATUS, adr);
504 status = map_read(map, adr);
505
506 if(!(status.x[0] & SR_ERRORS)){
507 sharp_send_cmd(map, CMD_RESET, adr);
508 chip->state = FL_READY;
509 //spin_unlock_bh(chip->mutex);
510 return 0;
511 }
512
513 printk("sharp: error erasing block at addr=%08lx status=%08lx\n", adr, status.x[0]);
514 sharp_send_cmd(map, CMD_CLEAR_STATUS, adr);
515
516 //spin_unlock_bh(chip->mutex);
517
518 return -EIO;
519}
520
521#ifdef AUTOUNLOCK
522static void sharp_unlock_oneblock(struct map_info *map, struct flchip *chip,
523 unsigned long adr)
524{
525 int i;
526 map_word status;
527
528 sharp_send_cmd(map, CMD_CLEAR_BLOCK_LOCKS_1, adr);
529 sharp_send_cmd(map, CMD_CLEAR_BLOCK_LOCKS_2, adr);
530
531 udelay(100);
532
533 status = map_read(map, adr);
534 printk("status=%08lx\n", status.x[0]);
535
536 for(i=0;i<1000;i++){
537 //sharp_send_cmd(map, CMD_READ_STATUS, adr);
538 status = map_read(map, adr);
539 if((status.x[0] & SR_READY) == SR_READY)
540 break;
541 udelay(100);
542 }
543 if(i==1000){
544 printk("sharp: timed out unlocking block\n");
545 }
546
547 if(!(status.x[0] & SR_ERRORS)){
548 sharp_send_cmd(map, CMD_RESET, adr);
549 chip->state = FL_READY;
550 return;
551 }
552
553 printk("sharp: error unlocking block at addr=%08lx status=%08lx\n", adr, status.x[0]);
554 sharp_send_cmd(map, CMD_CLEAR_STATUS, adr);
555}
556#endif
557
558static void sharp_sync(struct mtd_info *mtd)
559{
560 //printk("sharp_sync()\n");
561}
562
563static int sharp_suspend(struct mtd_info *mtd)
564{
565 printk("sharp_suspend()\n");
566 return -EINVAL;
567}
568
569static void sharp_resume(struct mtd_info *mtd)
570{
571 printk("sharp_resume()\n");
572
573}
574
575static void sharp_destroy(struct mtd_info *mtd)
576{
577 printk("sharp_destroy()\n");
578
579}
580
581static int __init sharp_probe_init(void)
582{
583 printk("MTD Sharp chip driver <ds@lineo.com>\n");
584
585 register_mtd_chip_driver(&sharp_chipdrv);
586
587 return 0;
588}
589
590static void __exit sharp_probe_exit(void)
591{
592 unregister_mtd_chip_driver(&sharp_chipdrv);
593}
594
595module_init(sharp_probe_init);
596module_exit(sharp_probe_exit);
597
598
599MODULE_LICENSE("GPL");
600MODULE_AUTHOR("David Schleef <ds@schleef.org>");
601MODULE_DESCRIPTION("Old MTD chip driver for pre-CFI Sharp flash chips");
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index fc4cc8ba9e29..be4b9948c762 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -373,7 +373,7 @@ static inline void kill_final_newline(char *str)
373 373
374#ifndef MODULE 374#ifndef MODULE
375static int block2mtd_init_called = 0; 375static int block2mtd_init_called = 0;
376static __initdata char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */ 376static char block2mtd_paramline[80 + 12]; /* 80 for device, 12 for erase size */
377#endif 377#endif
378 378
379 379
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index d990d8141ef5..b665e4ac2208 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -60,7 +60,7 @@ config MTD_PHYSMAP_BANKWIDTH
60 (i.e., run-time calling physmap_configure()). 60 (i.e., run-time calling physmap_configure()).
61 61
62config MTD_PHYSMAP_OF 62config MTD_PHYSMAP_OF
63 tristate "Flash device in physical memory map based on OF descirption" 63 tristate "Flash device in physical memory map based on OF description"
64 depends on PPC_OF && (MTD_CFI || MTD_JEDECPROBE || MTD_ROM) 64 depends on PPC_OF && (MTD_CFI || MTD_JEDECPROBE || MTD_ROM)
65 help 65 help
66 This provides a 'mapping' driver which allows the NOR Flash and 66 This provides a 'mapping' driver which allows the NOR Flash and
@@ -358,22 +358,6 @@ config MTD_CFI_FLAGADM
358 Mapping for the Flaga digital module. If you don't have one, ignore 358 Mapping for the Flaga digital module. If you don't have one, ignore
359 this setting. 359 this setting.
360 360
361config MTD_BEECH
362 tristate "CFI Flash device mapped on IBM 405LP Beech"
363 depends on MTD_CFI && BEECH
364 help
365 This enables access routines for the flash chips on the IBM
366 405LP Beech board. If you have one of these boards and would like
367 to use the flash chips on it, say 'Y'.
368
369config MTD_ARCTIC
370 tristate "CFI Flash device mapped on IBM 405LP Arctic"
371 depends on MTD_CFI && ARCTIC2
372 help
373 This enables access routines for the flash chips on the IBM 405LP
374 Arctic board. If you have one of these boards and would like to
375 use the flash chips on it, say 'Y'.
376
377config MTD_WALNUT 361config MTD_WALNUT
378 tristate "Flash device mapped on IBM 405GP Walnut" 362 tristate "Flash device mapped on IBM 405GP Walnut"
379 depends on MTD_JEDECPROBE && WALNUT 363 depends on MTD_JEDECPROBE && WALNUT
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index de036c5e6139..3acbb5d01ca4 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -58,8 +58,6 @@ obj-$(CONFIG_MTD_NETtel) += nettel.o
58obj-$(CONFIG_MTD_SCB2_FLASH) += scb2_flash.o 58obj-$(CONFIG_MTD_SCB2_FLASH) += scb2_flash.o
59obj-$(CONFIG_MTD_EBONY) += ebony.o 59obj-$(CONFIG_MTD_EBONY) += ebony.o
60obj-$(CONFIG_MTD_OCOTEA) += ocotea.o 60obj-$(CONFIG_MTD_OCOTEA) += ocotea.o
61obj-$(CONFIG_MTD_BEECH) += beech-mtd.o
62obj-$(CONFIG_MTD_ARCTIC) += arctic-mtd.o
63obj-$(CONFIG_MTD_WALNUT) += walnut.o 61obj-$(CONFIG_MTD_WALNUT) += walnut.o
64obj-$(CONFIG_MTD_H720X) += h720x-flash.o 62obj-$(CONFIG_MTD_H720X) += h720x-flash.o
65obj-$(CONFIG_MTD_SBC8240) += sbc8240.o 63obj-$(CONFIG_MTD_SBC8240) += sbc8240.o
diff --git a/drivers/mtd/maps/arctic-mtd.c b/drivers/mtd/maps/arctic-mtd.c
deleted file mode 100644
index 2cc902436275..000000000000
--- a/drivers/mtd/maps/arctic-mtd.c
+++ /dev/null
@@ -1,145 +0,0 @@
1/*
2 * $Id: arctic-mtd.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
3 *
4 * drivers/mtd/maps/arctic-mtd.c MTD mappings and partition tables for
5 * IBM 405LP Arctic boards.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Copyright (C) 2002, International Business Machines Corporation
22 * All Rights Reserved.
23 *
24 * Bishop Brock
25 * IBM Research, Austin Center for Low-Power Computing
26 * bcbrock@us.ibm.com
27 * March 2002
28 *
29 * modified for Arctic by,
30 * David Gibson
31 * IBM OzLabs, Canberra, Australia
32 * <arctic@gibson.dropbear.id.au>
33 */
34
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/types.h>
38#include <linux/init.h>
39
40#include <linux/mtd/mtd.h>
41#include <linux/mtd/map.h>
42#include <linux/mtd/partitions.h>
43
44#include <asm/io.h>
45#include <asm/ibm4xx.h>
46
47/*
48 * 0 : 0xFE00 0000 - 0xFEFF FFFF : Filesystem 1 (16MiB)
49 * 1 : 0xFF00 0000 - 0xFF4F FFFF : kernel (5.12MiB)
50 * 2 : 0xFF50 0000 - 0xFFF5 FFFF : Filesystem 2 (10.624MiB) (if non-XIP)
51 * 3 : 0xFFF6 0000 - 0xFFFF FFFF : PIBS Firmware (640KiB)
52 */
53
54#define FFS1_SIZE 0x01000000 /* 16MiB */
55#define KERNEL_SIZE 0x00500000 /* 5.12MiB */
56#define FFS2_SIZE 0x00a60000 /* 10.624MiB */
57#define FIRMWARE_SIZE 0x000a0000 /* 640KiB */
58
59
60#define NAME "Arctic Linux Flash"
61#define PADDR SUBZERO_BOOTFLASH_PADDR
62#define BUSWIDTH 2
63#define SIZE SUBZERO_BOOTFLASH_SIZE
64#define PARTITIONS 4
65
66/* Flash memories on these boards are memory resources, accessed big-endian. */
67
68{
69 /* do nothing for now */
70}
71
72static struct map_info arctic_mtd_map = {
73 .name = NAME,
74 .size = SIZE,
75 .bankwidth = BUSWIDTH,
76 .phys = PADDR,
77};
78
79static struct mtd_info *arctic_mtd;
80
81static struct mtd_partition arctic_partitions[PARTITIONS] = {
82 { .name = "Filesystem",
83 .size = FFS1_SIZE,
84 .offset = 0,},
85 { .name = "Kernel",
86 .size = KERNEL_SIZE,
87 .offset = FFS1_SIZE,},
88 { .name = "Filesystem",
89 .size = FFS2_SIZE,
90 .offset = FFS1_SIZE + KERNEL_SIZE,},
91 { .name = "Firmware",
92 .size = FIRMWARE_SIZE,
93 .offset = SUBZERO_BOOTFLASH_SIZE - FIRMWARE_SIZE,},
94};
95
96static int __init
97init_arctic_mtd(void)
98{
99 int err;
100
101 printk("%s: 0x%08x at 0x%08x\n", NAME, SIZE, PADDR);
102
103 arctic_mtd_map.virt = ioremap(PADDR, SIZE);
104
105 if (!arctic_mtd_map.virt) {
106 printk("%s: failed to ioremap 0x%x\n", NAME, PADDR);
107 return -EIO;
108 }
109 simple_map_init(&arctic_mtd_map);
110
111 printk("%s: probing %d-bit flash bus\n", NAME, BUSWIDTH * 8);
112 arctic_mtd = do_map_probe("cfi_probe", &arctic_mtd_map);
113
114 if (!arctic_mtd) {
115 iounmap(arctic_mtd_map.virt);
116 return -ENXIO;
117 }
118
119 arctic_mtd->owner = THIS_MODULE;
120
121 err = add_mtd_partitions(arctic_mtd, arctic_partitions, PARTITIONS);
122 if (err) {
123 printk("%s: add_mtd_partitions failed\n", NAME);
124 iounmap(arctic_mtd_map.virt);
125 }
126
127 return err;
128}
129
130static void __exit
131cleanup_arctic_mtd(void)
132{
133 if (arctic_mtd) {
134 del_mtd_partitions(arctic_mtd);
135 map_destroy(arctic_mtd);
136 iounmap((void *) arctic_mtd_map.virt);
137 }
138}
139
140module_init(init_arctic_mtd);
141module_exit(cleanup_arctic_mtd);
142
143MODULE_LICENSE("GPL");
144MODULE_AUTHOR("David Gibson <arctic@gibson.dropbear.id.au>");
145MODULE_DESCRIPTION("MTD map and partitions for IBM 405LP Arctic boards");
diff --git a/drivers/mtd/maps/beech-mtd.c b/drivers/mtd/maps/beech-mtd.c
deleted file mode 100644
index d76d5981b863..000000000000
--- a/drivers/mtd/maps/beech-mtd.c
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2 * $Id: beech-mtd.c,v 1.11 2005/11/07 11:14:26 gleixner Exp $
3 *
4 * drivers/mtd/maps/beech-mtd.c MTD mappings and partition tables for
5 * IBM 405LP Beech boards.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Copyright (C) 2002, International Business Machines Corporation
22 * All Rights Reserved.
23 *
24 * Bishop Brock
25 * IBM Research, Austin Center for Low-Power Computing
26 * bcbrock@us.ibm.com
27 * March 2002
28 *
29 */
30
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/types.h>
34#include <linux/init.h>
35
36#include <linux/mtd/mtd.h>
37#include <linux/mtd/map.h>
38#include <linux/mtd/partitions.h>
39
40#include <asm/io.h>
41#include <asm/ibm4xx.h>
42
43#define NAME "Beech Linux Flash"
44#define PADDR BEECH_BIGFLASH_PADDR
45#define SIZE BEECH_BIGFLASH_SIZE
46#define BUSWIDTH 1
47
48/* Flash memories on these boards are memory resources, accessed big-endian. */
49
50
51static struct map_info beech_mtd_map = {
52 .name = NAME,
53 .size = SIZE,
54 .bankwidth = BUSWIDTH,
55 .phys = PADDR
56};
57
58static struct mtd_info *beech_mtd;
59
60static struct mtd_partition beech_partitions[2] = {
61 {
62 .name = "Linux Kernel",
63 .size = BEECH_KERNEL_SIZE,
64 .offset = BEECH_KERNEL_OFFSET
65 }, {
66 .name = "Free Area",
67 .size = BEECH_FREE_AREA_SIZE,
68 .offset = BEECH_FREE_AREA_OFFSET
69 }
70};
71
72static int __init
73init_beech_mtd(void)
74{
75 int err;
76
77 printk("%s: 0x%08x at 0x%08x\n", NAME, SIZE, PADDR);
78
79 beech_mtd_map.virt = ioremap(PADDR, SIZE);
80
81 if (!beech_mtd_map.virt) {
82 printk("%s: failed to ioremap 0x%x\n", NAME, PADDR);
83 return -EIO;
84 }
85
86 simple_map_init(&beech_mtd_map);
87
88 printk("%s: probing %d-bit flash bus\n", NAME, BUSWIDTH * 8);
89 beech_mtd = do_map_probe("cfi_probe", &beech_mtd_map);
90
91 if (!beech_mtd) {
92 iounmap(beech_mtd_map.virt);
93 return -ENXIO;
94 }
95
96 beech_mtd->owner = THIS_MODULE;
97
98 err = add_mtd_partitions(beech_mtd, beech_partitions, 2);
99 if (err) {
100 printk("%s: add_mtd_partitions failed\n", NAME);
101 iounmap(beech_mtd_map.virt);
102 }
103
104 return err;
105}
106
107static void __exit
108cleanup_beech_mtd(void)
109{
110 if (beech_mtd) {
111 del_mtd_partitions(beech_mtd);
112 map_destroy(beech_mtd);
113 iounmap((void *) beech_mtd_map.virt);
114 }
115}
116
117module_init(init_beech_mtd);
118module_exit(cleanup_beech_mtd);
119
120MODULE_LICENSE("GPL");
121MODULE_AUTHOR("Bishop Brock <bcbrock@us.ibm.com>");
122MODULE_DESCRIPTION("MTD map and partitions for IBM 405LP Beech boards");
diff --git a/drivers/mtd/maps/nettel.c b/drivers/mtd/maps/nettel.c
index 9f53c655af3a..7b96cd02f82b 100644
--- a/drivers/mtd/maps/nettel.c
+++ b/drivers/mtd/maps/nettel.c
@@ -358,7 +358,7 @@ int __init nettel_init(void)
358 /* Turn other PAR off so the first probe doesn't find it */ 358 /* Turn other PAR off so the first probe doesn't find it */
359 *intel1par = 0; 359 *intel1par = 0;
360 360
361 /* Probe for the the size of the first Intel flash */ 361 /* Probe for the size of the first Intel flash */
362 nettel_intel_map.size = maxsize; 362 nettel_intel_map.size = maxsize;
363 nettel_intel_map.phys = intel0addr; 363 nettel_intel_map.phys = intel0addr;
364 nettel_intel_map.virt = ioremap_nocache(intel0addr, maxsize); 364 nettel_intel_map.virt = ioremap_nocache(intel0addr, maxsize);
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index 7efe744ad31e..bbb42c35b69b 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -48,7 +48,7 @@ static int parse_flash_partitions(struct device_node *node,
48 const u32 *part; 48 const u32 *part;
49 const char *name; 49 const char *name;
50 50
51 part = get_property(node, "partitions", &plen); 51 part = of_get_property(node, "partitions", &plen);
52 if (part == NULL) 52 if (part == NULL)
53 goto err; 53 goto err;
54 54
@@ -59,7 +59,7 @@ static int parse_flash_partitions(struct device_node *node,
59 goto err; 59 goto err;
60 } 60 }
61 61
62 name = get_property(node, "partition-names", &plen); 62 name = of_get_property(node, "partition-names", &plen);
63 63
64 for (i = 0; i < retval; i++) { 64 for (i = 0; i < retval; i++) {
65 (*parts)[i].offset = *part++; 65 (*parts)[i].offset = *part++;
@@ -153,7 +153,7 @@ static int __devinit of_physmap_probe(struct of_device *dev, const struct of_dev
153 goto err_out; 153 goto err_out;
154 } 154 }
155 155
156 width = get_property(dp, "bank-width", NULL); 156 width = of_get_property(dp, "bank-width", NULL);
157 if (width == NULL) { 157 if (width == NULL) {
158 dev_err(&dev->dev, "Can't get the flash bank width!\n"); 158 dev_err(&dev->dev, "Can't get the flash bank width!\n");
159 err = -EINVAL; 159 err = -EINVAL;
@@ -174,7 +174,7 @@ static int __devinit of_physmap_probe(struct of_device *dev, const struct of_dev
174 174
175 simple_map_init(&info->map); 175 simple_map_init(&info->map);
176 176
177 of_probe = get_property(dp, "probe-type", NULL); 177 of_probe = of_get_property(dp, "probe-type", NULL);
178 if (of_probe == NULL) { 178 if (of_probe == NULL) {
179 probe_type = rom_probe_types; 179 probe_type = rom_probe_types;
180 for (; info->mtd == NULL && *probe_type != NULL; probe_type++) 180 for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
@@ -186,7 +186,7 @@ static int __devinit of_physmap_probe(struct of_device *dev, const struct of_dev
186 else { 186 else {
187 if (strcmp(of_probe, "ROM")) 187 if (strcmp(of_probe, "ROM"))
188 dev_dbg(&dev->dev, "map_probe: don't know probe type " 188 dev_dbg(&dev->dev, "map_probe: don't know probe type "
189 "'%s', mapping as rom\n"); 189 "'%s', mapping as rom\n", of_probe);
190 info->mtd = do_map_probe("mtd_rom", &info->map); 190 info->mtd = do_map_probe("mtd_rom", &info->map);
191 } 191 }
192 if (info->mtd == NULL) { 192 if (info->mtd == NULL) {
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 524b83b5ebf5..51bc7e2f1f22 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -216,7 +216,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
216 int last_devnum = -1; 216 int last_devnum = -1;
217 struct gendisk *gd; 217 struct gendisk *gd;
218 218
219 if (!!mutex_trylock(&mtd_table_mutex)) { 219 if (mutex_trylock(&mtd_table_mutex)) {
220 mutex_unlock(&mtd_table_mutex); 220 mutex_unlock(&mtd_table_mutex);
221 BUG(); 221 BUG();
222 } 222 }
@@ -294,7 +294,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
294 294
295int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old) 295int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
296{ 296{
297 if (!!mutex_trylock(&mtd_table_mutex)) { 297 if (mutex_trylock(&mtd_table_mutex)) {
298 mutex_unlock(&mtd_table_mutex); 298 mutex_unlock(&mtd_table_mutex);
299 BUG(); 299 BUG();
300 } 300 }
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 1af989023c66..9c6236852942 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -347,7 +347,6 @@ int add_mtd_partitions(struct mtd_info *master,
347 slave->mtd.subpage_sft = master->subpage_sft; 347 slave->mtd.subpage_sft = master->subpage_sft;
348 348
349 slave->mtd.name = parts[i].name; 349 slave->mtd.name = parts[i].name;
350 slave->mtd.bank_size = master->bank_size;
351 slave->mtd.owner = master->owner; 350 slave->mtd.owner = master->owner;
352 351
353 slave->mtd.read = part_read; 352 slave->mtd.read = part_read;
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index d05873b8c155..f1d60b6f048e 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -232,11 +232,13 @@ config MTD_NAND_BASLER_EXCITE
232 will be named "excite_nandflash.ko". 232 will be named "excite_nandflash.ko".
233 233
234config MTD_NAND_CAFE 234config MTD_NAND_CAFE
235 tristate "NAND support for OLPC CAFÉ chip" 235 tristate "NAND support for OLPC CAFÉ chip"
236 depends on PCI 236 depends on PCI
237 help 237 select REED_SOLOMON
238 Use NAND flash attached to the CAFÉ chip designed for the $100 238 select REED_SOLOMON_DEC16
239 laptop. 239 help
240 Use NAND flash attached to the CAFÉ chip designed for the $100
241 laptop.
240 242
241config MTD_NAND_CS553X 243config MTD_NAND_CS553X
242 tristate "NAND support for CS5535/CS5536 (AMD Geode companion chip)" 244 tristate "NAND support for CS5535/CS5536 (AMD Geode companion chip)"
@@ -270,4 +272,13 @@ config MTD_NAND_NANDSIM
270 The simulator may simulate various NAND flash chips for the 272 The simulator may simulate various NAND flash chips for the
271 MTD nand layer. 273 MTD nand layer.
272 274
275config MTD_NAND_PLATFORM
276 tristate "Support for generic platform NAND driver"
277 depends on MTD_NAND
278 help
279 This implements a generic NAND driver for on-SOC platform
280 devices. You will need to provide platform-specific functions
281 via platform_data.
282
283
273endif # MTD_NAND 284endif # MTD_NAND
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index 6872031a3fb2..edba1db14bfa 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -26,6 +26,6 @@ obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o 26obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o
27obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o 27obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o
28obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o 28obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o
29obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o
29 30
30nand-objs := nand_base.o nand_bbt.o 31nand-objs := nand_base.o nand_bbt.o
31cafe_nand-objs := cafe.o cafe_ecc.o
diff --git a/drivers/mtd/nand/at91_nand.c b/drivers/mtd/nand/at91_nand.c
index 14b80cc90a7b..512e999177f7 100644
--- a/drivers/mtd/nand/at91_nand.c
+++ b/drivers/mtd/nand/at91_nand.c
@@ -82,6 +82,10 @@ static void at91_nand_disable(struct at91_nand_host *host)
82 at91_set_gpio_value(host->board->enable_pin, 1); 82 at91_set_gpio_value(host->board->enable_pin, 1);
83} 83}
84 84
85#ifdef CONFIG_MTD_PARTITIONS
86const char *part_probes[] = { "cmdlinepart", NULL };
87#endif
88
85/* 89/*
86 * Probe for the NAND device. 90 * Probe for the NAND device.
87 */ 91 */
@@ -151,6 +155,12 @@ static int __init at91_nand_probe(struct platform_device *pdev)
151#ifdef CONFIG_MTD_PARTITIONS 155#ifdef CONFIG_MTD_PARTITIONS
152 if (host->board->partition_info) 156 if (host->board->partition_info)
153 partitions = host->board->partition_info(mtd->size, &num_partitions); 157 partitions = host->board->partition_info(mtd->size, &num_partitions);
158#ifdef CONFIG_MTD_CMDLINE_PARTS
159 else {
160 mtd->name = "at91_nand";
161 num_partitions = parse_mtd_partitions(mtd, part_probes, &partitions, 0);
162 }
163#endif
154 164
155 if ((!partitions) || (num_partitions == 0)) { 165 if ((!partitions) || (num_partitions == 0)) {
156 printk(KERN_ERR "at91_nand: No parititions defined, or unsupported device.\n"); 166 printk(KERN_ERR "at91_nand: No parititions defined, or unsupported device.\n");
diff --git a/drivers/mtd/nand/cafe_ecc.c b/drivers/mtd/nand/cafe_ecc.c
deleted file mode 100644
index ea5c8491d2c5..000000000000
--- a/drivers/mtd/nand/cafe_ecc.c
+++ /dev/null
@@ -1,1381 +0,0 @@
1/* Error correction for CAFÉ NAND controller
2 *
3 * © 2006 Marvell, Inc.
4 * Author: Tom Chiou
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * this program; if not, write to the Free Software Foundation, Inc., 59
18 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/errno.h>
24
25static unsigned short gf4096_mul(unsigned short, unsigned short);
26static unsigned short gf64_mul(unsigned short, unsigned short);
27static unsigned short gf4096_inv(unsigned short);
28static unsigned short err_pos(unsigned short);
29static void find_4bit_err_coefs(unsigned short, unsigned short, unsigned short,
30 unsigned short, unsigned short, unsigned short,
31 unsigned short, unsigned short, unsigned short *);
32static void zero_4x5_col3(unsigned short[4][5]);
33static void zero_4x5_col2(unsigned short[4][5]);
34static void zero_4x5_col1(unsigned short[4][5]);
35static void swap_4x5_rows(unsigned short[4][5], int, int, int);
36static void swap_2x3_rows(unsigned short m[2][3]);
37static void solve_4x5(unsigned short m[4][5], unsigned short *, int *);
38static void sort_coefs(int *, unsigned short *, int);
39static void find_4bit_err_pats(unsigned short, unsigned short, unsigned short,
40 unsigned short, unsigned short, unsigned short,
41 unsigned short, unsigned short, unsigned short *);
42static void find_3bit_err_coefs(unsigned short, unsigned short, unsigned short,
43 unsigned short, unsigned short, unsigned short,
44 unsigned short *);
45static void zero_3x4_col2(unsigned short[3][4]);
46static void zero_3x4_col1(unsigned short[3][4]);
47static void swap_3x4_rows(unsigned short[3][4], int, int, int);
48static void solve_3x4(unsigned short[3][4], unsigned short *, int *);
49static void find_3bit_err_pats(unsigned short, unsigned short, unsigned short,
50 unsigned short, unsigned short, unsigned short,
51 unsigned short *);
52
53static void find_2bit_err_pats(unsigned short, unsigned short, unsigned short,
54 unsigned short, unsigned short *);
55static void find_2x2_soln(unsigned short, unsigned short, unsigned short,
56 unsigned short, unsigned short, unsigned short,
57 unsigned short *);
58static void solve_2x3(unsigned short[2][3], unsigned short *);
59static int chk_no_err_only(unsigned short *, unsigned short *);
60static int chk_1_err_only(unsigned short *, unsigned short *);
61static int chk_2_err_only(unsigned short *, unsigned short *);
62static int chk_3_err_only(unsigned short *, unsigned short *);
63static int chk_4_err_only(unsigned short *, unsigned short *);
64
65static unsigned short gf64_mul(unsigned short a, unsigned short b)
66{
67 unsigned short tmp1, tmp2, tmp3, tmp4, tmp5;
68 unsigned short c_bit0, c_bit1, c_bit2, c_bit3, c_bit4, c_bit5, c;
69
70 tmp1 = ((a) ^ (a >> 5));
71 tmp2 = ((a >> 4) ^ (a >> 5));
72 tmp3 = ((a >> 3) ^ (a >> 4));
73 tmp4 = ((a >> 2) ^ (a >> 3));
74 tmp5 = ((a >> 1) ^ (a >> 2));
75
76 c_bit0 = ((a & b) ^ ((a >> 5) & (b >> 1)) ^ ((a >> 4) & (b >> 2)) ^
77 ((a >> 3) & (b >> 3)) ^ ((a >> 2) & (b >> 4)) ^ ((a >> 1) & (b >> 5))) & 0x1;
78
79 c_bit1 = (((a >> 1) & b) ^ (tmp1 & (b >> 1)) ^ (tmp2 & (b >> 2)) ^
80 (tmp3 & (b >> 3)) ^ (tmp4 & (b >> 4)) ^ (tmp5 & (b >> 5))) & 0x1;
81
82 c_bit2 = (((a >> 2) & b) ^ ((a >> 1) & (b >> 1)) ^ (tmp1 & (b >> 2)) ^
83 (tmp2 & (b >> 3)) ^ (tmp3 & (b >> 4)) ^ (tmp4 & (b >> 5))) & 0x1;
84
85 c_bit3 = (((a >> 3) & b) ^ ((a >> 2) & (b >> 1)) ^ ((a >> 1) & (b >> 2)) ^
86 (tmp1 & (b >> 3)) ^ (tmp2 & (b >> 4)) ^ (tmp3 & (b >> 5))) & 0x1;
87
88 c_bit4 = (((a >> 4) & b) ^ ((a >> 3) & (b >> 1)) ^ ((a >> 2) & (b >> 2)) ^
89 ((a >> 1) & (b >> 3)) ^ (tmp1 & (b >> 4)) ^ (tmp2 & (b >> 5))) & 0x1;
90
91 c_bit5 = (((a >> 5) & b) ^ ((a >> 4) & (b >> 1)) ^ ((a >> 3) & (b >> 2)) ^
92 ((a >> 2) & (b >> 3)) ^ ((a >> 1) & (b >> 4)) ^ (tmp1 & (b >> 5))) & 0x1;
93
94 c = c_bit0 | (c_bit1 << 1) | (c_bit2 << 2) | (c_bit3 << 3) | (c_bit4 << 4) | (c_bit5 << 5);
95
96 return c;
97}
98
99static unsigned short gf4096_mul(unsigned short a, unsigned short b)
100{
101 unsigned short ah, al, bh, bl, alxah, blxbh, ablh, albl, ahbh, ahbhB, c;
102
103 ah = (a >> 6) & 0x3f;
104 al = a & 0x3f;
105 bh = (b >> 6) & 0x3f;
106 bl = b & 0x3f;
107 alxah = al ^ ah;
108 blxbh = bl ^ bh;
109
110 ablh = gf64_mul(alxah, blxbh);
111 albl = gf64_mul(al, bl);
112 ahbh = gf64_mul(ah, bh);
113
114 ahbhB = ((ahbh & 0x1) << 5) |
115 ((ahbh & 0x20) >> 1) |
116 ((ahbh & 0x10) >> 1) | ((ahbh & 0x8) >> 1) | ((ahbh & 0x4) >> 1) | (((ahbh >> 1) ^ ahbh) & 0x1);
117
118 c = ((ablh ^ albl) << 6) | (ahbhB ^ albl);
119 return c;
120}
121
122static void find_2bit_err_pats(unsigned short s0, unsigned short s1, unsigned short r0, unsigned short r1, unsigned short *pats)
123{
124 find_2x2_soln(0x1, 0x1, r0, r1, s0, s1, pats);
125}
126
127static void find_3bit_err_coefs(unsigned short s0, unsigned short s1,
128 unsigned short s2, unsigned short s3, unsigned short s4, unsigned short s5, unsigned short *coefs)
129{
130 unsigned short m[3][4];
131 int row_order[3];
132
133 row_order[0] = 0;
134 row_order[1] = 1;
135 row_order[2] = 2;
136 m[0][0] = s2;
137 m[0][1] = s1;
138 m[0][2] = s0;
139 m[0][3] = s3;
140 m[1][0] = s3;
141 m[1][1] = s2;
142 m[1][2] = s1;
143 m[1][3] = s4;
144 m[2][0] = s4;
145 m[2][1] = s3;
146 m[2][2] = s2;
147 m[2][3] = s5;
148
149 if (m[0][2] != 0x0) {
150 zero_3x4_col2(m);
151 } else if (m[1][2] != 0x0) {
152 swap_3x4_rows(m, 0, 1, 4);
153 zero_3x4_col2(m);
154 } else if (m[2][2] != 0x0) {
155 swap_3x4_rows(m, 0, 2, 4);
156 zero_3x4_col2(m);
157 } else {
158 printk(KERN_ERR "Error: find_3bit_err_coefs, s0,s1,s2 all zeros!\n");
159 }
160
161 if (m[1][1] != 0x0) {
162 zero_3x4_col1(m);
163 } else if (m[2][1] != 0x0) {
164 swap_3x4_rows(m, 1, 2, 4);
165 zero_3x4_col1(m);
166 } else {
167 printk(KERN_ERR "Error: find_3bit_err_coefs, cannot resolve col 1!\n");
168 }
169
170 /* solve coefs */
171 solve_3x4(m, coefs, row_order);
172}
173
174static void zero_3x4_col2(unsigned short m[3][4])
175{
176 unsigned short minv1, minv2;
177
178 minv1 = gf4096_mul(m[1][2], gf4096_inv(m[0][2]));
179 minv2 = gf4096_mul(m[2][2], gf4096_inv(m[0][2]));
180 m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv1);
181 m[1][1] = m[1][1] ^ gf4096_mul(m[0][1], minv1);
182 m[1][3] = m[1][3] ^ gf4096_mul(m[0][3], minv1);
183 m[2][0] = m[2][0] ^ gf4096_mul(m[0][0], minv2);
184 m[2][1] = m[2][1] ^ gf4096_mul(m[0][1], minv2);
185 m[2][3] = m[2][3] ^ gf4096_mul(m[0][3], minv2);
186}
187
188static void zero_3x4_col1(unsigned short m[3][4])
189{
190 unsigned short minv;
191 minv = gf4096_mul(m[2][1], gf4096_inv(m[1][1]));
192 m[2][0] = m[2][0] ^ gf4096_mul(m[1][0], minv);
193 m[2][3] = m[2][3] ^ gf4096_mul(m[1][3], minv);
194}
195
196static void swap_3x4_rows(unsigned short m[3][4], int i, int j, int col_width)
197{
198 unsigned short tmp0;
199 int cnt;
200 for (cnt = 0; cnt < col_width; cnt++) {
201 tmp0 = m[i][cnt];
202 m[i][cnt] = m[j][cnt];
203 m[j][cnt] = tmp0;
204 }
205}
206
207static void solve_3x4(unsigned short m[3][4], unsigned short *coefs, int *row_order)
208{
209 unsigned short tmp[3];
210 tmp[0] = gf4096_mul(m[2][3], gf4096_inv(m[2][0]));
211 tmp[1] = gf4096_mul((gf4096_mul(tmp[0], m[1][0]) ^ m[1][3]), gf4096_inv(m[1][1]));
212 tmp[2] = gf4096_mul((gf4096_mul(tmp[0], m[0][0]) ^ gf4096_mul(tmp[1], m[0][1]) ^ m[0][3]), gf4096_inv(m[0][2]));
213 sort_coefs(row_order, tmp, 3);
214 coefs[0] = tmp[0];
215 coefs[1] = tmp[1];
216 coefs[2] = tmp[2];
217}
218
219static void find_3bit_err_pats(unsigned short s0, unsigned short s1,
220 unsigned short s2, unsigned short r0,
221 unsigned short r1, unsigned short r2,
222 unsigned short *pats)
223{
224 find_2x2_soln(r0 ^ r2, r1 ^ r2,
225 gf4096_mul(r0, r0 ^ r2), gf4096_mul(r1, r1 ^ r2),
226 gf4096_mul(s0, r2) ^ s1, gf4096_mul(s1, r2) ^ s2, pats);
227 pats[2] = s0 ^ pats[0] ^ pats[1];
228}
229
230static void find_4bit_err_coefs(unsigned short s0, unsigned short s1,
231 unsigned short s2, unsigned short s3,
232 unsigned short s4, unsigned short s5,
233 unsigned short s6, unsigned short s7,
234 unsigned short *coefs)
235{
236 unsigned short m[4][5];
237 int row_order[4];
238
239 row_order[0] = 0;
240 row_order[1] = 1;
241 row_order[2] = 2;
242 row_order[3] = 3;
243
244 m[0][0] = s3;
245 m[0][1] = s2;
246 m[0][2] = s1;
247 m[0][3] = s0;
248 m[0][4] = s4;
249 m[1][0] = s4;
250 m[1][1] = s3;
251 m[1][2] = s2;
252 m[1][3] = s1;
253 m[1][4] = s5;
254 m[2][0] = s5;
255 m[2][1] = s4;
256 m[2][2] = s3;
257 m[2][3] = s2;
258 m[2][4] = s6;
259 m[3][0] = s6;
260 m[3][1] = s5;
261 m[3][2] = s4;
262 m[3][3] = s3;
263 m[3][4] = s7;
264
265 if (m[0][3] != 0x0) {
266 zero_4x5_col3(m);
267 } else if (m[1][3] != 0x0) {
268 swap_4x5_rows(m, 0, 1, 5);
269 zero_4x5_col3(m);
270 } else if (m[2][3] != 0x0) {
271 swap_4x5_rows(m, 0, 2, 5);
272 zero_4x5_col3(m);
273 } else if (m[3][3] != 0x0) {
274 swap_4x5_rows(m, 0, 3, 5);
275 zero_4x5_col3(m);
276 } else {
277 printk(KERN_ERR "Error: find_4bit_err_coefs, s0,s1,s2,s3 all zeros!\n");
278 }
279
280 if (m[1][2] != 0x0) {
281 zero_4x5_col2(m);
282 } else if (m[2][2] != 0x0) {
283 swap_4x5_rows(m, 1, 2, 5);
284 zero_4x5_col2(m);
285 } else if (m[3][2] != 0x0) {
286 swap_4x5_rows(m, 1, 3, 5);
287 zero_4x5_col2(m);
288 } else {
289 printk(KERN_ERR "Error: find_4bit_err_coefs, cannot resolve col 2!\n");
290 }
291
292 if (m[2][1] != 0x0) {
293 zero_4x5_col1(m);
294 } else if (m[3][1] != 0x0) {
295 swap_4x5_rows(m, 2, 3, 5);
296 zero_4x5_col1(m);
297 } else {
298 printk(KERN_ERR "Error: find_4bit_err_coefs, cannot resolve col 1!\n");
299 }
300
301 solve_4x5(m, coefs, row_order);
302}
303
304static void zero_4x5_col3(unsigned short m[4][5])
305{
306 unsigned short minv1, minv2, minv3;
307
308 minv1 = gf4096_mul(m[1][3], gf4096_inv(m[0][3]));
309 minv2 = gf4096_mul(m[2][3], gf4096_inv(m[0][3]));
310 minv3 = gf4096_mul(m[3][3], gf4096_inv(m[0][3]));
311
312 m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv1);
313 m[1][1] = m[1][1] ^ gf4096_mul(m[0][1], minv1);
314 m[1][2] = m[1][2] ^ gf4096_mul(m[0][2], minv1);
315 m[1][4] = m[1][4] ^ gf4096_mul(m[0][4], minv1);
316 m[2][0] = m[2][0] ^ gf4096_mul(m[0][0], minv2);
317 m[2][1] = m[2][1] ^ gf4096_mul(m[0][1], minv2);
318 m[2][2] = m[2][2] ^ gf4096_mul(m[0][2], minv2);
319 m[2][4] = m[2][4] ^ gf4096_mul(m[0][4], minv2);
320 m[3][0] = m[3][0] ^ gf4096_mul(m[0][0], minv3);
321 m[3][1] = m[3][1] ^ gf4096_mul(m[0][1], minv3);
322 m[3][2] = m[3][2] ^ gf4096_mul(m[0][2], minv3);
323 m[3][4] = m[3][4] ^ gf4096_mul(m[0][4], minv3);
324}
325
326static void zero_4x5_col2(unsigned short m[4][5])
327{
328 unsigned short minv2, minv3;
329
330 minv2 = gf4096_mul(m[2][2], gf4096_inv(m[1][2]));
331 minv3 = gf4096_mul(m[3][2], gf4096_inv(m[1][2]));
332
333 m[2][0] = m[2][0] ^ gf4096_mul(m[1][0], minv2);
334 m[2][1] = m[2][1] ^ gf4096_mul(m[1][1], minv2);
335 m[2][4] = m[2][4] ^ gf4096_mul(m[1][4], minv2);
336 m[3][0] = m[3][0] ^ gf4096_mul(m[1][0], minv3);
337 m[3][1] = m[3][1] ^ gf4096_mul(m[1][1], minv3);
338 m[3][4] = m[3][4] ^ gf4096_mul(m[1][4], minv3);
339}
340
341static void zero_4x5_col1(unsigned short m[4][5])
342{
343 unsigned short minv;
344
345 minv = gf4096_mul(m[3][1], gf4096_inv(m[2][1]));
346
347 m[3][0] = m[3][0] ^ gf4096_mul(m[2][0], minv);
348 m[3][4] = m[3][4] ^ gf4096_mul(m[2][4], minv);
349}
350
351static void swap_4x5_rows(unsigned short m[4][5], int i, int j, int col_width)
352{
353 unsigned short tmp0;
354 int cnt;
355
356 for (cnt = 0; cnt < col_width; cnt++) {
357 tmp0 = m[i][cnt];
358 m[i][cnt] = m[j][cnt];
359 m[j][cnt] = tmp0;
360 }
361}
362
363static void solve_4x5(unsigned short m[4][5], unsigned short *coefs, int *row_order)
364{
365 unsigned short tmp[4];
366
367 tmp[0] = gf4096_mul(m[3][4], gf4096_inv(m[3][0]));
368 tmp[1] = gf4096_mul((gf4096_mul(tmp[0], m[2][0]) ^ m[2][4]), gf4096_inv(m[2][1]));
369 tmp[2] = gf4096_mul((gf4096_mul(tmp[0], m[1][0]) ^ gf4096_mul(tmp[1], m[1][1]) ^ m[1][4]), gf4096_inv(m[1][2]));
370 tmp[3] = gf4096_mul((gf4096_mul(tmp[0], m[0][0]) ^
371 gf4096_mul(tmp[1], m[0][1]) ^ gf4096_mul(tmp[2], m[0][2]) ^ m[0][4]), gf4096_inv(m[0][3]));
372 sort_coefs(row_order, tmp, 4);
373 coefs[0] = tmp[0];
374 coefs[1] = tmp[1];
375 coefs[2] = tmp[2];
376 coefs[3] = tmp[3];
377}
378
379static void sort_coefs(int *order, unsigned short *soln, int len)
380{
381 int cnt, start_cnt, least_ord, least_cnt;
382 unsigned short tmp0;
383 for (start_cnt = 0; start_cnt < len; start_cnt++) {
384 for (cnt = start_cnt; cnt < len; cnt++) {
385 if (cnt == start_cnt) {
386 least_ord = order[cnt];
387 least_cnt = start_cnt;
388 } else {
389 if (least_ord > order[cnt]) {
390 least_ord = order[cnt];
391 least_cnt = cnt;
392 }
393 }
394 }
395 if (least_cnt != start_cnt) {
396 tmp0 = order[least_cnt];
397 order[least_cnt] = order[start_cnt];
398 order[start_cnt] = tmp0;
399 tmp0 = soln[least_cnt];
400 soln[least_cnt] = soln[start_cnt];
401 soln[start_cnt] = tmp0;
402 }
403 }
404}
405
406static void find_4bit_err_pats(unsigned short s0, unsigned short s1,
407 unsigned short s2, unsigned short s3,
408 unsigned short z1, unsigned short z2,
409 unsigned short z3, unsigned short z4,
410 unsigned short *pats)
411{
412 unsigned short z4_z1, z3z4_z3z3, z4_z2, s0z4_s1, z1z4_z1z1,
413 z4_z3, z2z4_z2z2, s1z4_s2, z3z3z4_z3z3z3, z1z1z4_z1z1z1, z2z2z4_z2z2z2, s2z4_s3;
414 unsigned short tmp0, tmp1, tmp2, tmp3;
415
416 z4_z1 = z4 ^ z1;
417 z3z4_z3z3 = gf4096_mul(z3, z4) ^ gf4096_mul(z3, z3);
418 z4_z2 = z4 ^ z2;
419 s0z4_s1 = gf4096_mul(s0, z4) ^ s1;
420 z1z4_z1z1 = gf4096_mul(z1, z4) ^ gf4096_mul(z1, z1);
421 z4_z3 = z4 ^ z3;
422 z2z4_z2z2 = gf4096_mul(z2, z4) ^ gf4096_mul(z2, z2);
423 s1z4_s2 = gf4096_mul(s1, z4) ^ s2;
424 z3z3z4_z3z3z3 = gf4096_mul(gf4096_mul(z3, z3), z4) ^ gf4096_mul(gf4096_mul(z3, z3), z3);
425 z1z1z4_z1z1z1 = gf4096_mul(gf4096_mul(z1, z1), z4) ^ gf4096_mul(gf4096_mul(z1, z1), z1);
426 z2z2z4_z2z2z2 = gf4096_mul(gf4096_mul(z2, z2), z4) ^ gf4096_mul(gf4096_mul(z2, z2), z2);
427 s2z4_s3 = gf4096_mul(s2, z4) ^ s3;
428
429 //find err pat 0,1
430 find_2x2_soln(gf4096_mul(z4_z1, z3z4_z3z3) ^
431 gf4096_mul(z1z4_z1z1, z4_z3), gf4096_mul(z4_z2,
432 z3z4_z3z3) ^
433 gf4096_mul(z2z4_z2z2, z4_z3), gf4096_mul(z1z4_z1z1,
434 z3z3z4_z3z3z3) ^
435 gf4096_mul(z1z1z4_z1z1z1, z3z4_z3z3),
436 gf4096_mul(z2z4_z2z2,
437 z3z3z4_z3z3z3) ^ gf4096_mul(z2z2z4_z2z2z2,
438 z3z4_z3z3),
439 gf4096_mul(s0z4_s1, z3z4_z3z3) ^ gf4096_mul(s1z4_s2,
440 z4_z3),
441 gf4096_mul(s1z4_s2, z3z3z4_z3z3z3) ^ gf4096_mul(s2z4_s3, z3z4_z3z3), pats);
442 tmp0 = pats[0];
443 tmp1 = pats[1];
444 tmp2 = pats[0] ^ pats[1] ^ s0;
445 tmp3 = gf4096_mul(pats[0], z1) ^ gf4096_mul(pats[1], z2) ^ s1;
446
447 //find err pat 2,3
448 find_2x2_soln(0x1, 0x1, z3, z4, tmp2, tmp3, pats);
449 pats[2] = pats[0];
450 pats[3] = pats[1];
451 pats[0] = tmp0;
452 pats[1] = tmp1;
453}
454
455static void find_2x2_soln(unsigned short c00, unsigned short c01,
456 unsigned short c10, unsigned short c11,
457 unsigned short lval0, unsigned short lval1,
458 unsigned short *soln)
459{
460 unsigned short m[2][3];
461 m[0][0] = c00;
462 m[0][1] = c01;
463 m[0][2] = lval0;
464 m[1][0] = c10;
465 m[1][1] = c11;
466 m[1][2] = lval1;
467
468 if (m[0][1] != 0x0) {
469 /* */
470 } else if (m[1][1] != 0x0) {
471 swap_2x3_rows(m);
472 } else {
473 printk(KERN_ERR "Warning: find_2bit_err_coefs, s0,s1 all zeros!\n");
474 }
475
476 solve_2x3(m, soln);
477}
478
479static void swap_2x3_rows(unsigned short m[2][3])
480{
481 unsigned short tmp0;
482 int cnt;
483
484 for (cnt = 0; cnt < 3; cnt++) {
485 tmp0 = m[0][cnt];
486 m[0][cnt] = m[1][cnt];
487 m[1][cnt] = tmp0;
488 }
489}
490
491static void solve_2x3(unsigned short m[2][3], unsigned short *coefs)
492{
493 unsigned short minv;
494
495 minv = gf4096_mul(m[1][1], gf4096_inv(m[0][1]));
496 m[1][0] = m[1][0] ^ gf4096_mul(m[0][0], minv);
497 m[1][2] = m[1][2] ^ gf4096_mul(m[0][2], minv);
498 coefs[0] = gf4096_mul(m[1][2], gf4096_inv(m[1][0]));
499 coefs[1] = gf4096_mul((gf4096_mul(coefs[0], m[0][0]) ^ m[0][2]), gf4096_inv(m[0][1]));
500}
501
502static unsigned char gf64_inv[64] = {
503 0, 1, 33, 62, 49, 43, 31, 44, 57, 37, 52, 28, 46, 40, 22, 25,
504 61, 54, 51, 39, 26, 35, 14, 24, 23, 15, 20, 34, 11, 53, 45, 6,
505 63, 2, 27, 21, 56, 9, 50, 19, 13, 47, 48, 5, 7, 30, 12, 41,
506 42, 4, 38, 18, 10, 29, 17, 60, 36, 8, 59, 58, 55, 16, 3, 32
507};
508
509static unsigned short gf4096_inv(unsigned short din)
510{
511 unsigned short alahxal, ah2B, deno, inv, bl, bh;
512 unsigned short ah, al, ahxal;
513 unsigned short dout;
514
515 ah = (din >> 6) & 0x3f;
516 al = din & 0x3f;
517 ahxal = ah ^ al;
518 ah2B = (((ah ^ (ah >> 3)) & 0x1) << 5) |
519 ((ah >> 1) & 0x10) |
520 ((((ah >> 5) ^ (ah >> 2)) & 0x1) << 3) |
521 ((ah >> 2) & 0x4) | ((((ah >> 4) ^ (ah >> 1)) & 0x1) << 1) | (ah & 0x1);
522 alahxal = gf64_mul(ahxal, al);
523 deno = alahxal ^ ah2B;
524 inv = gf64_inv[deno];
525 bl = gf64_mul(inv, ahxal);
526 bh = gf64_mul(inv, ah);
527 dout = ((bh & 0x3f) << 6) | (bl & 0x3f);
528 return (((bh & 0x3f) << 6) | (bl & 0x3f));
529}
530
531static unsigned short err_pos_lut[4096] = {
532 0xfff, 0x000, 0x451, 0xfff, 0xfff, 0x3cf, 0xfff, 0x041,
533 0xfff, 0xfff, 0xfff, 0xfff, 0x28a, 0xfff, 0x492, 0xfff,
534 0x145, 0xfff, 0xfff, 0x514, 0xfff, 0x082, 0xfff, 0xfff,
535 0xfff, 0x249, 0x38e, 0x410, 0xfff, 0x104, 0x208, 0x1c7,
536 0xfff, 0xfff, 0xfff, 0xfff, 0x2cb, 0xfff, 0xfff, 0xfff,
537 0x0c3, 0x34d, 0x4d3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
538 0xfff, 0xfff, 0xfff, 0x186, 0xfff, 0xfff, 0xfff, 0xfff,
539 0xfff, 0x30c, 0x555, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
540 0xfff, 0xfff, 0xfff, 0x166, 0xfff, 0xfff, 0xfff, 0xfff,
541 0x385, 0x14e, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e1,
542 0xfff, 0xfff, 0xfff, 0xfff, 0x538, 0xfff, 0x16d, 0xfff,
543 0xfff, 0xfff, 0x45b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
544 0xfff, 0xfff, 0xfff, 0x29c, 0x2cc, 0x30b, 0x2b3, 0xfff,
545 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0b3, 0xfff, 0x2f7,
546 0xfff, 0x32b, 0xfff, 0xfff, 0xfff, 0xfff, 0x0a7, 0xfff,
547 0xfff, 0x2da, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
548 0xfff, 0x07e, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
549 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x11c, 0xfff, 0xfff,
550 0xfff, 0xfff, 0xfff, 0x22f, 0xfff, 0x1f4, 0xfff, 0xfff,
551 0x2b0, 0x504, 0xfff, 0x114, 0xfff, 0xfff, 0xfff, 0x21d,
552 0xfff, 0xfff, 0xfff, 0xfff, 0x00d, 0x3c4, 0x340, 0x10f,
553 0xfff, 0xfff, 0x266, 0x02e, 0xfff, 0xfff, 0xfff, 0x4f8,
554 0x337, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
555 0xfff, 0xfff, 0xfff, 0x07b, 0x168, 0xfff, 0xfff, 0x0fe,
556 0xfff, 0xfff, 0x51a, 0xfff, 0x458, 0xfff, 0x36d, 0xfff,
557 0xfff, 0xfff, 0xfff, 0x073, 0x37d, 0x415, 0x550, 0xfff,
558 0xfff, 0xfff, 0x23b, 0x4b4, 0xfff, 0xfff, 0xfff, 0x1a1,
559 0xfff, 0xfff, 0x3aa, 0xfff, 0x117, 0x04d, 0x341, 0xfff,
560 0xfff, 0xfff, 0xfff, 0x518, 0x03e, 0x0f2, 0xfff, 0xfff,
561 0xfff, 0xfff, 0xfff, 0x363, 0xfff, 0x0b9, 0xfff, 0xfff,
562 0x241, 0xfff, 0xfff, 0x049, 0xfff, 0xfff, 0xfff, 0xfff,
563 0x15f, 0x52d, 0xfff, 0xfff, 0xfff, 0x29e, 0xfff, 0xfff,
564 0xfff, 0xfff, 0x4cf, 0x0fc, 0xfff, 0x36f, 0x3d3, 0xfff,
565 0x228, 0xfff, 0xfff, 0x45e, 0xfff, 0xfff, 0xfff, 0xfff,
566 0x238, 0xfff, 0xfff, 0xfff, 0xfff, 0x47f, 0xfff, 0xfff,
567 0x43a, 0x265, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3e8,
568 0xfff, 0xfff, 0x01a, 0xfff, 0xfff, 0xfff, 0xfff, 0x21e,
569 0x1fc, 0x40b, 0xfff, 0xfff, 0xfff, 0x2d0, 0x159, 0xfff,
570 0xfff, 0x313, 0xfff, 0xfff, 0x05c, 0x4cc, 0xfff, 0xfff,
571 0x0f6, 0x3d5, 0xfff, 0xfff, 0xfff, 0x54f, 0xfff, 0xfff,
572 0xfff, 0x172, 0x1e4, 0x07c, 0xfff, 0xfff, 0xfff, 0xfff,
573 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x53c, 0x1ad, 0x535,
574 0x19b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
575 0xfff, 0xfff, 0x092, 0xfff, 0x2be, 0xfff, 0xfff, 0x482,
576 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0e6, 0xfff, 0xfff,
577 0xfff, 0xfff, 0xfff, 0x476, 0xfff, 0x51d, 0xfff, 0xfff,
578 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
579 0xfff, 0xfff, 0x342, 0x2b5, 0x22e, 0x09a, 0xfff, 0x08d,
580 0x44f, 0x3ed, 0xfff, 0xfff, 0xfff, 0xfff, 0x3d1, 0xfff,
581 0xfff, 0x543, 0xfff, 0x48f, 0xfff, 0x3d2, 0xfff, 0x0d5,
582 0x113, 0x0ec, 0x427, 0xfff, 0xfff, 0xfff, 0x4c4, 0xfff,
583 0xfff, 0x50a, 0xfff, 0x144, 0xfff, 0x105, 0x39f, 0x294,
584 0x164, 0xfff, 0x31a, 0xfff, 0xfff, 0x49a, 0xfff, 0x130,
585 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
586 0x1be, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
587 0xfff, 0xfff, 0x49e, 0x371, 0xfff, 0xfff, 0xfff, 0xfff,
588 0xfff, 0xfff, 0xfff, 0xfff, 0x0e8, 0x49c, 0x0f4, 0xfff,
589 0x338, 0x1a7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
590 0xfff, 0x36c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
591 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
592 0xfff, 0x1ae, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
593 0xfff, 0x31b, 0xfff, 0xfff, 0x2dd, 0x522, 0xfff, 0xfff,
594 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2f4,
595 0x3c6, 0x30d, 0xfff, 0xfff, 0xfff, 0xfff, 0x34c, 0x18f,
596 0x30a, 0xfff, 0x01f, 0x079, 0xfff, 0xfff, 0x54d, 0x46b,
597 0x28c, 0x37f, 0xfff, 0xfff, 0xfff, 0xfff, 0x355, 0xfff,
598 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x14f, 0xfff, 0xfff,
599 0xfff, 0xfff, 0xfff, 0x359, 0x3fe, 0x3c5, 0xfff, 0xfff,
600 0xfff, 0xfff, 0x423, 0xfff, 0xfff, 0x34a, 0x22c, 0xfff,
601 0x25a, 0xfff, 0xfff, 0x4ad, 0xfff, 0x28d, 0xfff, 0xfff,
602 0xfff, 0xfff, 0xfff, 0x547, 0xfff, 0xfff, 0xfff, 0xfff,
603 0x2e2, 0xfff, 0xfff, 0x1d5, 0xfff, 0x2a8, 0xfff, 0xfff,
604 0x03f, 0xfff, 0xfff, 0xfff, 0xfff, 0x3eb, 0x0fa, 0xfff,
605 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x55b, 0xfff,
606 0x08e, 0xfff, 0x3ae, 0xfff, 0x3a4, 0xfff, 0x282, 0x158,
607 0xfff, 0x382, 0xfff, 0xfff, 0x499, 0xfff, 0xfff, 0x08a,
608 0xfff, 0xfff, 0xfff, 0x456, 0x3be, 0xfff, 0x1e2, 0xfff,
609 0xfff, 0xfff, 0xfff, 0xfff, 0x559, 0xfff, 0x1a0, 0xfff,
610 0xfff, 0x0b4, 0xfff, 0xfff, 0xfff, 0x2df, 0xfff, 0xfff,
611 0xfff, 0x07f, 0x4f5, 0xfff, 0xfff, 0x27c, 0x133, 0x017,
612 0xfff, 0x3fd, 0xfff, 0xfff, 0xfff, 0x44d, 0x4cd, 0x17a,
613 0x0d7, 0x537, 0xfff, 0xfff, 0x353, 0xfff, 0xfff, 0x351,
614 0x366, 0xfff, 0x44a, 0xfff, 0x1a6, 0xfff, 0xfff, 0xfff,
615 0x291, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1e3,
616 0xfff, 0xfff, 0xfff, 0xfff, 0x389, 0xfff, 0x07a, 0xfff,
617 0x1b6, 0x2ed, 0xfff, 0xfff, 0xfff, 0xfff, 0x24e, 0x074,
618 0xfff, 0xfff, 0x3dc, 0xfff, 0x4e3, 0xfff, 0xfff, 0xfff,
619 0xfff, 0x4eb, 0xfff, 0xfff, 0x3b8, 0x4de, 0xfff, 0x19c,
620 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x262,
621 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x076, 0x4e8, 0x3da,
622 0xfff, 0x531, 0xfff, 0xfff, 0x14a, 0xfff, 0x0a2, 0x433,
623 0x3df, 0x1e9, 0xfff, 0xfff, 0xfff, 0xfff, 0x3e7, 0x285,
624 0x2d8, 0xfff, 0xfff, 0xfff, 0x349, 0x18d, 0x098, 0xfff,
625 0x0df, 0x4bf, 0xfff, 0xfff, 0x0b2, 0xfff, 0x346, 0x24d,
626 0xfff, 0xfff, 0xfff, 0x24f, 0x4fa, 0x2f9, 0xfff, 0xfff,
627 0x3c9, 0xfff, 0x2b4, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
628 0xfff, 0x056, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
629 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
630 0xfff, 0x179, 0xfff, 0x0e9, 0x3f0, 0x33d, 0xfff, 0xfff,
631 0xfff, 0xfff, 0xfff, 0x1fd, 0xfff, 0xfff, 0x526, 0xfff,
632 0xfff, 0xfff, 0x53d, 0xfff, 0xfff, 0xfff, 0x170, 0x331,
633 0xfff, 0x068, 0xfff, 0xfff, 0xfff, 0x3f7, 0xfff, 0x3d8,
634 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
635 0xfff, 0x09f, 0x556, 0xfff, 0xfff, 0x02d, 0xfff, 0xfff,
636 0x553, 0xfff, 0xfff, 0xfff, 0x1f0, 0xfff, 0xfff, 0x4d6,
637 0x41e, 0xfff, 0xfff, 0xfff, 0xfff, 0x4d5, 0xfff, 0xfff,
638 0xfff, 0xfff, 0xfff, 0x248, 0xfff, 0xfff, 0xfff, 0x0a3,
639 0xfff, 0x217, 0xfff, 0xfff, 0xfff, 0x4f1, 0x209, 0xfff,
640 0xfff, 0x475, 0x234, 0x52b, 0x398, 0xfff, 0x08b, 0xfff,
641 0xfff, 0xfff, 0xfff, 0x2c2, 0xfff, 0xfff, 0xfff, 0xfff,
642 0xfff, 0xfff, 0x268, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
643 0xfff, 0x4a3, 0xfff, 0x0aa, 0xfff, 0x1d9, 0xfff, 0xfff,
644 0xfff, 0xfff, 0x155, 0xfff, 0xfff, 0xfff, 0xfff, 0x0bf,
645 0x539, 0xfff, 0xfff, 0x2f1, 0x545, 0xfff, 0xfff, 0xfff,
646 0xfff, 0xfff, 0xfff, 0x2a7, 0x06f, 0xfff, 0x378, 0xfff,
647 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x25e, 0xfff,
648 0xfff, 0xfff, 0xfff, 0x15d, 0x02a, 0xfff, 0xfff, 0x0bc,
649 0x235, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
650 0x150, 0xfff, 0x1a9, 0xfff, 0xfff, 0xfff, 0xfff, 0x381,
651 0xfff, 0x04e, 0x270, 0x13f, 0xfff, 0xfff, 0x405, 0xfff,
652 0x3cd, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
653 0xfff, 0x2ef, 0xfff, 0x06a, 0xfff, 0xfff, 0xfff, 0x34f,
654 0x212, 0xfff, 0xfff, 0x0e2, 0xfff, 0x083, 0x298, 0xfff,
655 0xfff, 0xfff, 0x0c2, 0xfff, 0xfff, 0x52e, 0xfff, 0x488,
656 0xfff, 0xfff, 0xfff, 0x36b, 0xfff, 0xfff, 0xfff, 0x442,
657 0x091, 0xfff, 0x41c, 0xfff, 0xfff, 0x3a5, 0xfff, 0x4e6,
658 0xfff, 0xfff, 0x40d, 0x31d, 0xfff, 0xfff, 0xfff, 0x4c1,
659 0x053, 0xfff, 0x418, 0x13c, 0xfff, 0x350, 0xfff, 0x0ae,
660 0xfff, 0xfff, 0x41f, 0xfff, 0x470, 0xfff, 0x4ca, 0xfff,
661 0xfff, 0xfff, 0x02b, 0x450, 0xfff, 0x1f8, 0xfff, 0xfff,
662 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x293, 0xfff,
663 0xfff, 0xfff, 0xfff, 0x411, 0xfff, 0xfff, 0xfff, 0xfff,
664 0xfff, 0xfff, 0xfff, 0xfff, 0x0b8, 0xfff, 0xfff, 0xfff,
665 0x3e1, 0xfff, 0xfff, 0xfff, 0xfff, 0x43c, 0xfff, 0x2b2,
666 0x2ab, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ec,
667 0xfff, 0xfff, 0xfff, 0x3f8, 0x034, 0xfff, 0xfff, 0xfff,
668 0xfff, 0xfff, 0xfff, 0x11a, 0xfff, 0x541, 0x45c, 0x134,
669 0x1cc, 0xfff, 0xfff, 0xfff, 0x469, 0xfff, 0xfff, 0x44b,
670 0x161, 0xfff, 0xfff, 0xfff, 0x055, 0xfff, 0xfff, 0xfff,
671 0xfff, 0x307, 0xfff, 0xfff, 0xfff, 0xfff, 0x2d1, 0xfff,
672 0xfff, 0xfff, 0x124, 0x37b, 0x26b, 0x336, 0xfff, 0xfff,
673 0x2e4, 0x3cb, 0xfff, 0xfff, 0x0f8, 0x3c8, 0xfff, 0xfff,
674 0xfff, 0x461, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4b5,
675 0x2cf, 0xfff, 0xfff, 0xfff, 0x20f, 0xfff, 0x35a, 0xfff,
676 0x490, 0xfff, 0x185, 0xfff, 0xfff, 0xfff, 0xfff, 0x42e,
677 0xfff, 0xfff, 0xfff, 0xfff, 0x54b, 0xfff, 0xfff, 0xfff,
678 0x146, 0xfff, 0x412, 0xfff, 0xfff, 0xfff, 0x1ff, 0xfff,
679 0xfff, 0x3e0, 0xfff, 0xfff, 0xfff, 0xfff, 0x2d5, 0xfff,
680 0x4df, 0x505, 0xfff, 0x413, 0xfff, 0x1a5, 0xfff, 0x3b2,
681 0xfff, 0xfff, 0xfff, 0x35b, 0xfff, 0x116, 0xfff, 0xfff,
682 0x171, 0x4d0, 0xfff, 0x154, 0x12d, 0xfff, 0xfff, 0xfff,
683 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x468, 0x4db, 0xfff,
684 0xfff, 0x1df, 0xfff, 0xfff, 0xfff, 0xfff, 0x05a, 0xfff,
685 0x0f1, 0x403, 0xfff, 0x22b, 0x2e0, 0xfff, 0xfff, 0xfff,
686 0x2b7, 0x373, 0xfff, 0xfff, 0xfff, 0xfff, 0x13e, 0xfff,
687 0xfff, 0xfff, 0x0d0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
688 0x329, 0x1d2, 0x3fa, 0x047, 0xfff, 0x2f2, 0xfff, 0xfff,
689 0x141, 0x0ac, 0x1d7, 0xfff, 0x07d, 0xfff, 0xfff, 0xfff,
690 0x1c1, 0xfff, 0x487, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
691 0xfff, 0xfff, 0xfff, 0x045, 0xfff, 0xfff, 0xfff, 0xfff,
692 0x288, 0x0cd, 0xfff, 0xfff, 0xfff, 0xfff, 0x226, 0x1d8,
693 0xfff, 0x153, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4cb,
694 0x528, 0xfff, 0xfff, 0xfff, 0x20a, 0x343, 0x3a1, 0xfff,
695 0xfff, 0xfff, 0x2d7, 0x2d3, 0x1aa, 0x4c5, 0xfff, 0xfff,
696 0xfff, 0x42b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
697 0xfff, 0xfff, 0xfff, 0xfff, 0x3e9, 0xfff, 0x20b, 0x260,
698 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x37c, 0x2fd,
699 0xfff, 0xfff, 0x2c8, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
700 0xfff, 0x31e, 0xfff, 0x335, 0xfff, 0xfff, 0xfff, 0xfff,
701 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
702 0xfff, 0xfff, 0x135, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
703 0xfff, 0xfff, 0x35c, 0x4dd, 0x129, 0xfff, 0xfff, 0xfff,
704 0xfff, 0xfff, 0x1ef, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
705 0xfff, 0x34e, 0xfff, 0xfff, 0xfff, 0xfff, 0x407, 0xfff,
706 0xfff, 0xfff, 0xfff, 0xfff, 0x3ad, 0xfff, 0xfff, 0xfff,
707 0x379, 0xfff, 0xfff, 0x1d0, 0x38d, 0xfff, 0xfff, 0x1e8,
708 0x184, 0x3c1, 0x1c4, 0xfff, 0x1f9, 0xfff, 0xfff, 0x424,
709 0xfff, 0xfff, 0xfff, 0xfff, 0x1d3, 0x0d4, 0xfff, 0x4e9,
710 0xfff, 0xfff, 0xfff, 0x530, 0x107, 0xfff, 0x106, 0x04f,
711 0xfff, 0xfff, 0x4c7, 0x503, 0xfff, 0xfff, 0xfff, 0xfff,
712 0xfff, 0x15c, 0xfff, 0x23f, 0xfff, 0xfff, 0xfff, 0xfff,
713 0xfff, 0xfff, 0xfff, 0xfff, 0x4f3, 0xfff, 0xfff, 0x3c7,
714 0xfff, 0x278, 0xfff, 0xfff, 0x0a6, 0xfff, 0xfff, 0xfff,
715 0x122, 0x1cf, 0xfff, 0x327, 0xfff, 0x2e5, 0xfff, 0x29d,
716 0xfff, 0xfff, 0x3f1, 0xfff, 0xfff, 0x48d, 0xfff, 0xfff,
717 0xfff, 0xfff, 0x054, 0xfff, 0xfff, 0xfff, 0xfff, 0x178,
718 0x27e, 0x4e0, 0x352, 0x02f, 0x09c, 0xfff, 0x2a0, 0xfff,
719 0xfff, 0x46a, 0x457, 0xfff, 0xfff, 0x501, 0xfff, 0x2ba,
720 0xfff, 0xfff, 0xfff, 0x54e, 0x2e7, 0xfff, 0xfff, 0xfff,
721 0xfff, 0xfff, 0x551, 0xfff, 0xfff, 0x1db, 0x2aa, 0xfff,
722 0xfff, 0x4bc, 0xfff, 0xfff, 0x395, 0xfff, 0x0de, 0xfff,
723 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x455, 0xfff, 0x17e,
724 0xfff, 0x221, 0x4a7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
725 0x388, 0xfff, 0xfff, 0xfff, 0x308, 0xfff, 0xfff, 0xfff,
726 0x20e, 0x4b9, 0xfff, 0x273, 0x20c, 0x09e, 0xfff, 0x057,
727 0xfff, 0xfff, 0xfff, 0xfff, 0x3f2, 0xfff, 0x1a8, 0x3a6,
728 0x14c, 0xfff, 0xfff, 0x071, 0xfff, 0xfff, 0x53a, 0xfff,
729 0xfff, 0xfff, 0xfff, 0x109, 0xfff, 0xfff, 0x399, 0xfff,
730 0x061, 0x4f0, 0x39e, 0x244, 0xfff, 0x035, 0xfff, 0xfff,
731 0x305, 0x47e, 0x297, 0xfff, 0xfff, 0x2b8, 0xfff, 0xfff,
732 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1bc, 0xfff, 0x2fc,
733 0xfff, 0xfff, 0x554, 0xfff, 0xfff, 0xfff, 0xfff, 0x3b6,
734 0xfff, 0xfff, 0xfff, 0x515, 0x397, 0xfff, 0xfff, 0x12f,
735 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e5,
736 0xfff, 0x4fc, 0xfff, 0xfff, 0x05e, 0xfff, 0xfff, 0xfff,
737 0xfff, 0xfff, 0x0a8, 0x3af, 0x015, 0xfff, 0xfff, 0xfff,
738 0xfff, 0x138, 0xfff, 0xfff, 0xfff, 0x540, 0xfff, 0xfff,
739 0xfff, 0x027, 0x523, 0x2f0, 0xfff, 0xfff, 0xfff, 0xfff,
740 0xfff, 0xfff, 0x16c, 0xfff, 0x27d, 0xfff, 0xfff, 0xfff,
741 0xfff, 0x04c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4dc,
742 0xfff, 0xfff, 0x059, 0x301, 0xfff, 0xfff, 0xfff, 0xfff,
743 0xfff, 0xfff, 0xfff, 0x1a3, 0xfff, 0x15a, 0xfff, 0xfff,
744 0x0a5, 0xfff, 0x435, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
745 0xfff, 0x051, 0xfff, 0xfff, 0x131, 0xfff, 0x4f4, 0xfff,
746 0xfff, 0xfff, 0xfff, 0x441, 0xfff, 0x4fb, 0xfff, 0x03b,
747 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ed, 0x274,
748 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d3, 0x55e, 0x1b3,
749 0xfff, 0x0bd, 0xfff, 0xfff, 0xfff, 0xfff, 0x225, 0xfff,
750 0xfff, 0xfff, 0xfff, 0xfff, 0x4b7, 0xfff, 0xfff, 0x2ff,
751 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4c3, 0xfff,
752 0x383, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2f6,
753 0xfff, 0xfff, 0x1ee, 0xfff, 0x03d, 0xfff, 0xfff, 0xfff,
754 0xfff, 0xfff, 0x26f, 0x1dc, 0xfff, 0x0db, 0xfff, 0xfff,
755 0xfff, 0xfff, 0xfff, 0x0ce, 0xfff, 0xfff, 0x127, 0x03a,
756 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x311, 0xfff,
757 0xfff, 0x13d, 0x09d, 0x47b, 0x2a6, 0x50d, 0x510, 0x19a,
758 0xfff, 0x354, 0x414, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
759 0xfff, 0xfff, 0x44c, 0x3b0, 0xfff, 0x23d, 0x429, 0xfff,
760 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
761 0x4c0, 0x416, 0xfff, 0x05b, 0xfff, 0xfff, 0x137, 0xfff,
762 0x25f, 0x49f, 0xfff, 0x279, 0x013, 0xfff, 0xfff, 0xfff,
763 0x269, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
764 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3d0, 0xfff, 0xfff,
765 0xfff, 0xfff, 0xfff, 0xfff, 0x077, 0xfff, 0xfff, 0x3fb,
766 0xfff, 0xfff, 0xfff, 0xfff, 0x271, 0x3a0, 0xfff, 0xfff,
767 0x40f, 0xfff, 0xfff, 0x3de, 0xfff, 0xfff, 0xfff, 0xfff,
768 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ab, 0x26a,
769 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x489, 0xfff, 0xfff,
770 0x252, 0xfff, 0xfff, 0xfff, 0xfff, 0x1b7, 0x42f, 0xfff,
771 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x3b7,
772 0xfff, 0x2bb, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
773 0xfff, 0xfff, 0xfff, 0x0f7, 0x01d, 0xfff, 0x067, 0xfff,
774 0xfff, 0xfff, 0xfff, 0x4e2, 0xfff, 0xfff, 0x4bb, 0xfff,
775 0xfff, 0xfff, 0x17b, 0xfff, 0x0ee, 0xfff, 0xfff, 0xfff,
776 0xfff, 0xfff, 0x36e, 0xfff, 0xfff, 0xfff, 0x533, 0xfff,
777 0xfff, 0xfff, 0x4d4, 0x356, 0xfff, 0xfff, 0x375, 0xfff,
778 0xfff, 0xfff, 0xfff, 0x4a4, 0x513, 0xfff, 0xfff, 0xfff,
779 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4ff, 0xfff, 0x2af,
780 0xfff, 0xfff, 0x026, 0xfff, 0x0ad, 0xfff, 0xfff, 0xfff,
781 0xfff, 0x26e, 0xfff, 0xfff, 0xfff, 0xfff, 0x493, 0xfff,
782 0x463, 0x4d2, 0x4be, 0xfff, 0xfff, 0xfff, 0xfff, 0x4f2,
783 0x0b6, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
784 0xfff, 0x32d, 0x315, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
785 0xfff, 0x13a, 0x4a1, 0xfff, 0x27a, 0xfff, 0xfff, 0xfff,
786 0x47a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
787 0x334, 0xfff, 0xfff, 0xfff, 0xfff, 0x54c, 0xfff, 0xfff,
788 0xfff, 0x0c9, 0x007, 0xfff, 0xfff, 0x12e, 0xfff, 0x0ff,
789 0xfff, 0xfff, 0x3f5, 0x509, 0xfff, 0xfff, 0xfff, 0xfff,
790 0x1c3, 0x2ad, 0xfff, 0xfff, 0x47c, 0x261, 0xfff, 0xfff,
791 0xfff, 0xfff, 0xfff, 0x152, 0xfff, 0xfff, 0xfff, 0x339,
792 0xfff, 0x243, 0x1c0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
793 0x063, 0xfff, 0xfff, 0x254, 0xfff, 0xfff, 0x173, 0xfff,
794 0x0c7, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
795 0xfff, 0x362, 0x259, 0x485, 0x374, 0x0dc, 0x3ab, 0xfff,
796 0x1c5, 0x534, 0x544, 0xfff, 0xfff, 0x508, 0xfff, 0x402,
797 0x408, 0xfff, 0x0e7, 0xfff, 0xfff, 0x00a, 0x205, 0xfff,
798 0xfff, 0x2b9, 0xfff, 0xfff, 0xfff, 0x465, 0xfff, 0xfff,
799 0xfff, 0xfff, 0xfff, 0xfff, 0x23a, 0xfff, 0xfff, 0xfff,
800 0xfff, 0x147, 0x19d, 0x115, 0x214, 0xfff, 0x090, 0x368,
801 0xfff, 0x210, 0xfff, 0xfff, 0x280, 0x52a, 0x163, 0x148,
802 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x326, 0xfff, 0xfff,
803 0xfff, 0xfff, 0xfff, 0x2de, 0xfff, 0xfff, 0xfff, 0xfff,
804 0x206, 0x2c1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
805 0x189, 0xfff, 0xfff, 0xfff, 0xfff, 0x367, 0xfff, 0x1a4,
806 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x443, 0xfff, 0x27b,
807 0xfff, 0xfff, 0x251, 0x549, 0xfff, 0xfff, 0xfff, 0xfff,
808 0xfff, 0xfff, 0x188, 0x04b, 0xfff, 0xfff, 0xfff, 0x31f,
809 0x4a6, 0xfff, 0x246, 0x1de, 0x156, 0xfff, 0xfff, 0xfff,
810 0x3a9, 0xfff, 0xfff, 0xfff, 0x2fa, 0xfff, 0x128, 0x0d1,
811 0x449, 0x255, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
812 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
813 0xfff, 0xfff, 0xfff, 0xfff, 0x258, 0xfff, 0xfff, 0xfff,
814 0x532, 0xfff, 0xfff, 0xfff, 0x303, 0x517, 0xfff, 0xfff,
815 0x2a9, 0x24a, 0xfff, 0xfff, 0x231, 0xfff, 0xfff, 0xfff,
816 0xfff, 0xfff, 0x4b6, 0x516, 0xfff, 0xfff, 0x0e4, 0x0eb,
817 0xfff, 0x4e4, 0xfff, 0x275, 0xfff, 0xfff, 0x031, 0xfff,
818 0xfff, 0xfff, 0xfff, 0xfff, 0x025, 0x21a, 0xfff, 0x0cc,
819 0x45f, 0x3d9, 0x289, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
820 0xfff, 0xfff, 0x23e, 0xfff, 0xfff, 0xfff, 0x438, 0x097,
821 0x419, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
822 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
823 0xfff, 0xfff, 0x0a9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
824 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
825 0x37e, 0x0e0, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x431,
826 0x372, 0xfff, 0xfff, 0xfff, 0x1ba, 0x06e, 0xfff, 0x1b1,
827 0xfff, 0xfff, 0x12a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
828 0xfff, 0xfff, 0x193, 0xfff, 0xfff, 0xfff, 0xfff, 0x10a,
829 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x048, 0x1b4,
830 0xfff, 0xfff, 0xfff, 0xfff, 0x295, 0x140, 0x108, 0xfff,
831 0xfff, 0xfff, 0xfff, 0x16f, 0xfff, 0x0a4, 0x37a, 0xfff,
832 0x29a, 0xfff, 0x284, 0xfff, 0xfff, 0xfff, 0xfff, 0x4c6,
833 0x2a2, 0x3a3, 0xfff, 0x201, 0xfff, 0xfff, 0xfff, 0x4bd,
834 0x005, 0x54a, 0x3b5, 0x204, 0x2ee, 0x11d, 0x436, 0xfff,
835 0xfff, 0xfff, 0xfff, 0xfff, 0x3ec, 0xfff, 0xfff, 0xfff,
836 0xfff, 0xfff, 0xfff, 0xfff, 0x11f, 0x498, 0x21c, 0xfff,
837 0xfff, 0xfff, 0x3d6, 0xfff, 0x4ab, 0xfff, 0x432, 0x2eb,
838 0x542, 0x4fd, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
839 0xfff, 0xfff, 0xfff, 0x4ce, 0xfff, 0xfff, 0x2fb, 0xfff,
840 0xfff, 0x2e1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
841 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x1b9, 0x037, 0x0dd,
842 0xfff, 0xfff, 0xfff, 0x2bf, 0x521, 0x496, 0x095, 0xfff,
843 0xfff, 0x328, 0x070, 0x1bf, 0xfff, 0x393, 0xfff, 0xfff,
844 0x102, 0xfff, 0xfff, 0x21b, 0xfff, 0x142, 0x263, 0x519,
845 0xfff, 0x2a5, 0x177, 0xfff, 0x14d, 0x471, 0x4ae, 0xfff,
846 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
847 0x1f6, 0xfff, 0x481, 0xfff, 0xfff, 0xfff, 0x151, 0xfff,
848 0xfff, 0xfff, 0x085, 0x33f, 0xfff, 0xfff, 0xfff, 0x084,
849 0xfff, 0xfff, 0xfff, 0x345, 0x3a2, 0xfff, 0xfff, 0x0a0,
850 0x0da, 0x024, 0xfff, 0xfff, 0xfff, 0x1bd, 0xfff, 0x55c,
851 0x467, 0x445, 0xfff, 0xfff, 0xfff, 0x052, 0xfff, 0xfff,
852 0xfff, 0xfff, 0x51e, 0xfff, 0xfff, 0x39d, 0xfff, 0x35f,
853 0xfff, 0x376, 0x3ee, 0xfff, 0xfff, 0xfff, 0xfff, 0x448,
854 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x16a,
855 0xfff, 0x036, 0x38f, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
856 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x211,
857 0xfff, 0xfff, 0xfff, 0x230, 0xfff, 0xfff, 0x3ba, 0xfff,
858 0xfff, 0xfff, 0x3ce, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
859 0xfff, 0xfff, 0xfff, 0x229, 0xfff, 0x176, 0xfff, 0xfff,
860 0xfff, 0xfff, 0xfff, 0x00b, 0xfff, 0x162, 0x018, 0xfff,
861 0xfff, 0x233, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
862 0x400, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
863 0xfff, 0xfff, 0xfff, 0x12b, 0xfff, 0xfff, 0xfff, 0xfff,
864 0xfff, 0x3f4, 0xfff, 0x0f0, 0xfff, 0x1ac, 0xfff, 0xfff,
865 0x119, 0xfff, 0x2c0, 0xfff, 0xfff, 0xfff, 0x49b, 0xfff,
866 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x23c, 0xfff,
867 0x4b3, 0x010, 0x064, 0xfff, 0xfff, 0x4ba, 0xfff, 0xfff,
868 0xfff, 0xfff, 0xfff, 0x3c2, 0xfff, 0xfff, 0xfff, 0xfff,
869 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x006, 0x196, 0xfff,
870 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x100, 0x191, 0xfff,
871 0x1ea, 0x29f, 0xfff, 0xfff, 0xfff, 0x276, 0xfff, 0xfff,
872 0x2b1, 0x3b9, 0xfff, 0x03c, 0xfff, 0xfff, 0xfff, 0x180,
873 0xfff, 0x08f, 0xfff, 0xfff, 0x19e, 0x019, 0xfff, 0x0b0,
874 0x0fd, 0x332, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
875 0xfff, 0x06b, 0x2e8, 0xfff, 0x446, 0xfff, 0xfff, 0x004,
876 0x247, 0x197, 0xfff, 0x112, 0x169, 0x292, 0xfff, 0x302,
877 0xfff, 0xfff, 0x33b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
878 0xfff, 0xfff, 0xfff, 0x287, 0x21f, 0xfff, 0x3ea, 0xfff,
879 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x4e7, 0xfff, 0xfff,
880 0xfff, 0xfff, 0xfff, 0x3a8, 0xfff, 0xfff, 0x2bc, 0xfff,
881 0x484, 0x296, 0xfff, 0x1c9, 0x08c, 0x1e5, 0x48a, 0xfff,
882 0x360, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
883 0x1ca, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
884 0xfff, 0xfff, 0xfff, 0x10d, 0xfff, 0xfff, 0xfff, 0xfff,
885 0xfff, 0xfff, 0x066, 0x2ea, 0x28b, 0x25b, 0xfff, 0x072,
886 0xfff, 0xfff, 0xfff, 0xfff, 0x2b6, 0xfff, 0xfff, 0x272,
887 0xfff, 0xfff, 0x525, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
888 0x2ca, 0xfff, 0xfff, 0xfff, 0x299, 0xfff, 0xfff, 0xfff,
889 0x558, 0x41a, 0xfff, 0x4f7, 0x557, 0xfff, 0x4a0, 0x344,
890 0x12c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x125,
891 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
892 0x40e, 0xfff, 0xfff, 0x502, 0xfff, 0x103, 0x3e6, 0xfff,
893 0x527, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
894 0xfff, 0xfff, 0xfff, 0x45d, 0xfff, 0xfff, 0xfff, 0xfff,
895 0x44e, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d2, 0x4c9, 0x35e,
896 0x459, 0x2d9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x17d,
897 0x0c4, 0xfff, 0xfff, 0xfff, 0x3ac, 0x390, 0x094, 0xfff,
898 0x483, 0x0ab, 0xfff, 0x253, 0xfff, 0x391, 0xfff, 0xfff,
899 0xfff, 0xfff, 0x123, 0x0ef, 0xfff, 0xfff, 0xfff, 0x330,
900 0x38c, 0xfff, 0xfff, 0x2ae, 0xfff, 0xfff, 0xfff, 0x042,
901 0x012, 0x06d, 0xfff, 0xfff, 0xfff, 0x32a, 0x3db, 0x364,
902 0x2dc, 0xfff, 0x30f, 0x3d7, 0x4a5, 0x050, 0xfff, 0xfff,
903 0x029, 0xfff, 0xfff, 0xfff, 0xfff, 0x1d1, 0xfff, 0xfff,
904 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x480, 0xfff,
905 0x4ed, 0x081, 0x0a1, 0xfff, 0xfff, 0xfff, 0x30e, 0x52f,
906 0x257, 0xfff, 0xfff, 0x447, 0xfff, 0xfff, 0xfff, 0xfff,
907 0xfff, 0xfff, 0xfff, 0x401, 0x3cc, 0xfff, 0xfff, 0x0fb,
908 0x2c9, 0x42a, 0x314, 0x33e, 0x3bd, 0x318, 0xfff, 0x10e,
909 0x2a1, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x24c,
910 0x506, 0xfff, 0x267, 0xfff, 0xfff, 0x219, 0xfff, 0x1eb,
911 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
912 0x309, 0x3e2, 0x46c, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
913 0x384, 0xfff, 0xfff, 0xfff, 0xfff, 0x50c, 0xfff, 0x24b,
914 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x038,
915 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x194,
916 0x143, 0x3e3, 0xfff, 0xfff, 0xfff, 0x4c2, 0xfff, 0xfff,
917 0x0e1, 0x25c, 0xfff, 0x237, 0xfff, 0x1fe, 0xfff, 0xfff,
918 0xfff, 0x065, 0x2a4, 0xfff, 0x386, 0x55a, 0x11b, 0xfff,
919 0xfff, 0x192, 0xfff, 0x183, 0x00e, 0xfff, 0xfff, 0xfff,
920 0xfff, 0xfff, 0xfff, 0x4b2, 0x18e, 0xfff, 0xfff, 0xfff,
921 0xfff, 0x486, 0x4ef, 0x0c6, 0x380, 0xfff, 0x4a8, 0xfff,
922 0x0c5, 0xfff, 0xfff, 0xfff, 0xfff, 0x093, 0x1b8, 0xfff,
923 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2e6,
924 0xfff, 0x0f3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
925 0x28e, 0xfff, 0x53b, 0x420, 0x22a, 0x33a, 0xfff, 0x387,
926 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2a3, 0xfff, 0xfff,
927 0xfff, 0x428, 0x500, 0xfff, 0xfff, 0x120, 0x2c6, 0x290,
928 0x2f5, 0x0e3, 0xfff, 0x0b7, 0xfff, 0x319, 0x474, 0xfff,
929 0xfff, 0xfff, 0x529, 0x014, 0xfff, 0x41b, 0x40a, 0x18b,
930 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x0d9,
931 0xfff, 0x38a, 0xfff, 0xfff, 0xfff, 0xfff, 0x1ce, 0xfff,
932 0xfff, 0xfff, 0xfff, 0xfff, 0x3b1, 0xfff, 0xfff, 0x05d,
933 0x2c4, 0xfff, 0xfff, 0x4af, 0xfff, 0x030, 0xfff, 0xfff,
934 0x203, 0xfff, 0x277, 0x256, 0xfff, 0xfff, 0xfff, 0x4f9,
935 0xfff, 0x2c7, 0xfff, 0x466, 0x016, 0x1cd, 0xfff, 0x167,
936 0xfff, 0xfff, 0x0c8, 0xfff, 0x43d, 0xfff, 0xfff, 0x020,
937 0xfff, 0xfff, 0x232, 0x1cb, 0x1e0, 0xfff, 0xfff, 0x347,
938 0xfff, 0x478, 0xfff, 0x365, 0xfff, 0xfff, 0xfff, 0xfff,
939 0x358, 0xfff, 0x10b, 0xfff, 0x35d, 0xfff, 0xfff, 0xfff,
940 0xfff, 0xfff, 0x452, 0x22d, 0xfff, 0xfff, 0x47d, 0xfff,
941 0x2f3, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x460, 0xfff,
942 0xfff, 0xfff, 0x50b, 0xfff, 0xfff, 0xfff, 0x2ec, 0xfff,
943 0xfff, 0xfff, 0xfff, 0xfff, 0x4b1, 0x422, 0xfff, 0xfff,
944 0xfff, 0x2d4, 0xfff, 0x239, 0xfff, 0xfff, 0xfff, 0x439,
945 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
946 0xfff, 0x491, 0x075, 0xfff, 0xfff, 0xfff, 0x06c, 0xfff,
947 0xfff, 0x0f9, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
948 0xfff, 0x139, 0xfff, 0x4f6, 0xfff, 0xfff, 0x409, 0xfff,
949 0xfff, 0x15b, 0xfff, 0xfff, 0x348, 0xfff, 0xfff, 0xfff,
950 0xfff, 0x4a2, 0x49d, 0xfff, 0x033, 0x175, 0xfff, 0x039,
951 0xfff, 0x312, 0x40c, 0xfff, 0xfff, 0x325, 0xfff, 0xfff,
952 0xfff, 0xfff, 0xfff, 0xfff, 0x4aa, 0xfff, 0xfff, 0xfff,
953 0xfff, 0xfff, 0xfff, 0x165, 0x3bc, 0x48c, 0x310, 0x096,
954 0xfff, 0xfff, 0x250, 0x1a2, 0xfff, 0xfff, 0xfff, 0xfff,
955 0x20d, 0x2ac, 0xfff, 0xfff, 0x39b, 0xfff, 0x377, 0xfff,
956 0x512, 0x495, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
957 0xfff, 0xfff, 0xfff, 0xfff, 0x357, 0x4ea, 0xfff, 0xfff,
958 0xfff, 0xfff, 0x198, 0xfff, 0xfff, 0xfff, 0x434, 0x04a,
959 0xfff, 0xfff, 0xfff, 0xfff, 0x062, 0xfff, 0x1d6, 0x1c8,
960 0xfff, 0x1f3, 0x281, 0xfff, 0x462, 0xfff, 0xfff, 0xfff,
961 0x4b0, 0xfff, 0x207, 0xfff, 0xfff, 0xfff, 0xfff, 0x3dd,
962 0xfff, 0xfff, 0x55d, 0xfff, 0x552, 0x494, 0x1af, 0xfff,
963 0xfff, 0xfff, 0xfff, 0xfff, 0x227, 0xfff, 0xfff, 0x069,
964 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x43e,
965 0x0b5, 0xfff, 0x524, 0x2d2, 0xfff, 0xfff, 0xfff, 0x28f,
966 0xfff, 0x01b, 0x50e, 0xfff, 0xfff, 0x1bb, 0xfff, 0xfff,
967 0x41d, 0xfff, 0x32e, 0x48e, 0xfff, 0x1f7, 0x224, 0xfff,
968 0xfff, 0xfff, 0xfff, 0xfff, 0x394, 0xfff, 0xfff, 0xfff,
969 0xfff, 0x52c, 0xfff, 0xfff, 0xfff, 0x392, 0xfff, 0x1e7,
970 0xfff, 0xfff, 0x3f9, 0x3a7, 0xfff, 0x51f, 0xfff, 0x0bb,
971 0x118, 0x3ca, 0xfff, 0x1dd, 0xfff, 0x48b, 0xfff, 0xfff,
972 0xfff, 0xfff, 0x50f, 0xfff, 0x0d6, 0xfff, 0x1fa, 0xfff,
973 0x11e, 0xfff, 0xfff, 0xfff, 0xfff, 0x4d7, 0xfff, 0x078,
974 0x008, 0xfff, 0x25d, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
975 0x032, 0x33c, 0xfff, 0x4d9, 0x160, 0xfff, 0xfff, 0x300,
976 0x0b1, 0xfff, 0x322, 0xfff, 0x4ec, 0xfff, 0xfff, 0x200,
977 0x00c, 0x369, 0x473, 0xfff, 0xfff, 0x32c, 0xfff, 0xfff,
978 0xfff, 0xfff, 0xfff, 0xfff, 0x53e, 0x3d4, 0x417, 0xfff,
979 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
980 0x34b, 0x001, 0x39a, 0x02c, 0xfff, 0xfff, 0x2ce, 0x00f,
981 0xfff, 0x0ba, 0xfff, 0xfff, 0xfff, 0xfff, 0x060, 0xfff,
982 0x406, 0xfff, 0xfff, 0xfff, 0x4ee, 0x4ac, 0xfff, 0x43f,
983 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x29b, 0xfff, 0xfff,
984 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x216,
985 0x190, 0xfff, 0x396, 0x464, 0xfff, 0xfff, 0x323, 0xfff,
986 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x2e9, 0xfff, 0x26d,
987 0x2cd, 0x040, 0xfff, 0xfff, 0xfff, 0xfff, 0x38b, 0x3c0,
988 0xfff, 0xfff, 0xfff, 0x1f2, 0xfff, 0x0ea, 0xfff, 0xfff,
989 0x472, 0xfff, 0x1fb, 0xfff, 0xfff, 0x0af, 0x27f, 0xfff,
990 0xfff, 0xfff, 0x479, 0x023, 0xfff, 0x0d8, 0x3b3, 0xfff,
991 0xfff, 0xfff, 0x121, 0xfff, 0xfff, 0x3bf, 0xfff, 0xfff,
992 0x16b, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
993 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
994 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
995 0x45a, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
996 0xfff, 0x0be, 0xfff, 0xfff, 0xfff, 0x111, 0xfff, 0x220,
997 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
998 0xfff, 0xfff, 0x09b, 0x218, 0xfff, 0x022, 0x202, 0xfff,
999 0x4c8, 0xfff, 0x0ed, 0xfff, 0xfff, 0x182, 0xfff, 0xfff,
1000 0xfff, 0x17f, 0x213, 0xfff, 0x321, 0x36a, 0xfff, 0x086,
1001 0xfff, 0xfff, 0xfff, 0x43b, 0x088, 0xfff, 0xfff, 0xfff,
1002 0xfff, 0x26c, 0xfff, 0x2f8, 0x3b4, 0xfff, 0xfff, 0xfff,
1003 0x132, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x333, 0x444,
1004 0x0c1, 0x4d8, 0x46d, 0x264, 0xfff, 0xfff, 0xfff, 0xfff,
1005 0x426, 0xfff, 0xfff, 0xfff, 0xfff, 0x2fe, 0xfff, 0xfff,
1006 0xfff, 0xfff, 0x011, 0xfff, 0x05f, 0xfff, 0xfff, 0xfff,
1007 0xfff, 0x10c, 0x101, 0xfff, 0xfff, 0xfff, 0xfff, 0x110,
1008 0xfff, 0x044, 0x304, 0x361, 0x404, 0xfff, 0x51b, 0x099,
1009 0xfff, 0x440, 0xfff, 0xfff, 0xfff, 0x222, 0xfff, 0xfff,
1010 0xfff, 0xfff, 0x1b5, 0xfff, 0x136, 0x430, 0xfff, 0x1da,
1011 0xfff, 0xfff, 0xfff, 0x043, 0xfff, 0x17c, 0xfff, 0xfff,
1012 0xfff, 0x01c, 0xfff, 0xfff, 0xfff, 0x425, 0x236, 0xfff,
1013 0x317, 0xfff, 0xfff, 0x437, 0x3fc, 0xfff, 0x1f1, 0xfff,
1014 0x324, 0xfff, 0xfff, 0x0ca, 0x306, 0xfff, 0x548, 0xfff,
1015 0x46e, 0xfff, 0xfff, 0xfff, 0x4b8, 0x1c2, 0x286, 0xfff,
1016 0xfff, 0x087, 0x18a, 0x19f, 0xfff, 0xfff, 0xfff, 0xfff,
1017 0x18c, 0xfff, 0x215, 0xfff, 0xfff, 0xfff, 0xfff, 0x283,
1018 0xfff, 0xfff, 0xfff, 0x126, 0xfff, 0xfff, 0x370, 0xfff,
1019 0x53f, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0x31c, 0xfff,
1020 0x4d1, 0xfff, 0xfff, 0xfff, 0x021, 0xfff, 0x157, 0xfff,
1021 0xfff, 0x028, 0x16e, 0xfff, 0x421, 0xfff, 0x1c6, 0xfff,
1022 0xfff, 0x511, 0xfff, 0xfff, 0x39c, 0x46f, 0x1b2, 0xfff,
1023 0xfff, 0x316, 0xfff, 0xfff, 0x009, 0xfff, 0xfff, 0x195,
1024 0xfff, 0x240, 0x546, 0xfff, 0xfff, 0x520, 0xfff, 0xfff,
1025 0xfff, 0xfff, 0xfff, 0xfff, 0x454, 0xfff, 0xfff, 0xfff,
1026 0x3f3, 0xfff, 0xfff, 0x187, 0xfff, 0x4a9, 0xfff, 0xfff,
1027 0xfff, 0xfff, 0xfff, 0xfff, 0x51c, 0x453, 0x1e6, 0xfff,
1028 0xfff, 0xfff, 0x1b0, 0xfff, 0x477, 0xfff, 0xfff, 0xfff,
1029 0x4fe, 0xfff, 0x32f, 0xfff, 0xfff, 0x15e, 0x1d4, 0xfff,
1030 0x0e5, 0xfff, 0xfff, 0xfff, 0x242, 0x14b, 0x046, 0xfff,
1031 0x3f6, 0x3bb, 0x3e4, 0xfff, 0xfff, 0x2e3, 0xfff, 0x245,
1032 0xfff, 0x149, 0xfff, 0xfff, 0xfff, 0x2db, 0xfff, 0xfff,
1033 0x181, 0xfff, 0x089, 0x2c5, 0xfff, 0x1f5, 0xfff, 0x2d6,
1034 0x507, 0xfff, 0x42d, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
1035 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
1036 0x080, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff, 0xfff,
1037 0xfff, 0xfff, 0xfff, 0xfff, 0x3c3, 0x320, 0xfff, 0x1e1,
1038 0xfff, 0x0f5, 0x13b, 0xfff, 0xfff, 0xfff, 0x003, 0x4da,
1039 0xfff, 0xfff, 0xfff, 0x42c, 0xfff, 0xfff, 0x0cb, 0xfff,
1040 0x536, 0x2c3, 0xfff, 0xfff, 0xfff, 0xfff, 0x199, 0xfff,
1041 0xfff, 0x0c0, 0xfff, 0x01e, 0x497, 0xfff, 0xfff, 0x3e5,
1042 0xfff, 0xfff, 0xfff, 0x0cf, 0xfff, 0x2bd, 0xfff, 0x223,
1043 0xfff, 0x3ff, 0xfff, 0x058, 0x174, 0x3ef, 0xfff, 0x002
1044};
1045
1046static unsigned short err_pos(unsigned short din)
1047{
1048 BUG_ON(din >= ARRAY_SIZE(err_pos_lut));
1049 return err_pos_lut[din];
1050}
1051static int chk_no_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1052{
1053 if ((chk_syndrome_list[0] | chk_syndrome_list[1] |
1054 chk_syndrome_list[2] | chk_syndrome_list[3] |
1055 chk_syndrome_list[4] | chk_syndrome_list[5] |
1056 chk_syndrome_list[6] | chk_syndrome_list[7]) != 0x0) {
1057 return -EINVAL;
1058 } else {
1059 err_info[0] = 0x0;
1060 return 0;
1061 }
1062}
1063static int chk_1_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1064{
1065 unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;
1066 tmp0 = gf4096_mul(chk_syndrome_list[1], gf4096_inv(chk_syndrome_list[0]));
1067 tmp1 = gf4096_mul(chk_syndrome_list[2], gf4096_inv(chk_syndrome_list[1]));
1068 tmp2 = gf4096_mul(chk_syndrome_list[3], gf4096_inv(chk_syndrome_list[2]));
1069 tmp3 = gf4096_mul(chk_syndrome_list[4], gf4096_inv(chk_syndrome_list[3]));
1070 tmp4 = gf4096_mul(chk_syndrome_list[5], gf4096_inv(chk_syndrome_list[4]));
1071 tmp5 = gf4096_mul(chk_syndrome_list[6], gf4096_inv(chk_syndrome_list[5]));
1072 tmp6 = gf4096_mul(chk_syndrome_list[7], gf4096_inv(chk_syndrome_list[6]));
1073 if ((tmp0 == tmp1) & (tmp1 == tmp2) & (tmp2 == tmp3) & (tmp3 == tmp4) & (tmp4 == tmp5) & (tmp5 == tmp6)) {
1074 err_info[0] = 0x1; // encode 1-symbol error as 0x1
1075 err_info[1] = err_pos(tmp0);
1076 err_info[1] = (unsigned short)(0x55e - err_info[1]);
1077 err_info[5] = chk_syndrome_list[0];
1078 return 0;
1079 } else
1080 return -EINVAL;
1081}
1082static int chk_2_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1083{
1084 unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
1085 unsigned short coefs[4];
1086 unsigned short err_pats[4];
1087 int found_num_root = 0;
1088 unsigned short bit2_root0, bit2_root1;
1089 unsigned short bit2_root0_inv, bit2_root1_inv;
1090 unsigned short err_loc_eqn, test_root;
1091 unsigned short bit2_loc0, bit2_loc1;
1092 unsigned short bit2_pat0, bit2_pat1;
1093
1094 find_2x2_soln(chk_syndrome_list[1],
1095 chk_syndrome_list[0],
1096 chk_syndrome_list[2], chk_syndrome_list[1], chk_syndrome_list[2], chk_syndrome_list[3], coefs);
1097 for (test_root = 0x1; test_root < 0xfff; test_root++) {
1098 err_loc_eqn =
1099 gf4096_mul(coefs[1], gf4096_mul(test_root, test_root)) ^ gf4096_mul(coefs[0], test_root) ^ 0x1;
1100 if (err_loc_eqn == 0x0) {
1101 if (found_num_root == 0) {
1102 bit2_root0 = test_root;
1103 found_num_root = 1;
1104 } else if (found_num_root == 1) {
1105 bit2_root1 = test_root;
1106 found_num_root = 2;
1107 break;
1108 }
1109 }
1110 }
1111 if (found_num_root != 2)
1112 return -EINVAL;
1113 else {
1114 bit2_root0_inv = gf4096_inv(bit2_root0);
1115 bit2_root1_inv = gf4096_inv(bit2_root1);
1116 find_2bit_err_pats(chk_syndrome_list[0],
1117 chk_syndrome_list[1], bit2_root0_inv, bit2_root1_inv, err_pats);
1118 bit2_pat0 = err_pats[0];
1119 bit2_pat1 = err_pats[1];
1120 //for(x+1)
1121 tmp0 = gf4096_mul(gf4096_mul(bit2_root0_inv, bit2_root0_inv), gf4096_mul(bit2_root0_inv, bit2_root0_inv)); //rinv0^4
1122 tmp1 = gf4096_mul(bit2_root0_inv, tmp0); //rinv0^5
1123 tmp2 = gf4096_mul(bit2_root0_inv, tmp1); //rinv0^6
1124 tmp3 = gf4096_mul(bit2_root0_inv, tmp2); //rinv0^7
1125 tmp4 = gf4096_mul(gf4096_mul(bit2_root1_inv, bit2_root1_inv), gf4096_mul(bit2_root1_inv, bit2_root1_inv)); //rinv1^4
1126 tmp5 = gf4096_mul(bit2_root1_inv, tmp4); //rinv1^5
1127 tmp6 = gf4096_mul(bit2_root1_inv, tmp5); //rinv1^6
1128 tmp7 = gf4096_mul(bit2_root1_inv, tmp6); //rinv1^7
1129 //check if only 2-bit error
1130 if ((chk_syndrome_list[4] ==
1131 (gf4096_mul(bit2_pat0, tmp0) ^
1132 gf4096_mul(bit2_pat1,
1133 tmp4))) & (chk_syndrome_list[5] ==
1134 (gf4096_mul(bit2_pat0, tmp1) ^
1135 gf4096_mul(bit2_pat1,
1136 tmp5))) &
1137 (chk_syndrome_list[6] ==
1138 (gf4096_mul(bit2_pat0, tmp2) ^
1139 gf4096_mul(bit2_pat1,
1140 tmp6))) & (chk_syndrome_list[7] ==
1141 (gf4096_mul(bit2_pat0, tmp3) ^ gf4096_mul(bit2_pat1, tmp7)))) {
1142 if ((err_pos(bit2_root0_inv) == 0xfff) | (err_pos(bit2_root1_inv) == 0xfff)) {
1143 return -EINVAL;
1144 } else {
1145 bit2_loc0 = 0x55e - err_pos(bit2_root0_inv);
1146 bit2_loc1 = 0x55e - err_pos(bit2_root1_inv);
1147 err_info[0] = 0x2; // encode 2-symbol error as 0x2
1148 err_info[1] = bit2_loc0;
1149 err_info[2] = bit2_loc1;
1150 err_info[5] = bit2_pat0;
1151 err_info[6] = bit2_pat1;
1152 return 0;
1153 }
1154 } else
1155 return -EINVAL;
1156 }
1157}
1158static int chk_3_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1159{
1160 unsigned short tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;
1161 unsigned short coefs[4];
1162 unsigned short err_pats[4];
1163 int found_num_root = 0;
1164 unsigned short bit3_root0, bit3_root1, bit3_root2;
1165 unsigned short bit3_root0_inv, bit3_root1_inv, bit3_root2_inv;
1166 unsigned short err_loc_eqn, test_root;
1167
1168 find_3bit_err_coefs(chk_syndrome_list[0], chk_syndrome_list[1],
1169 chk_syndrome_list[2], chk_syndrome_list[3],
1170 chk_syndrome_list[4], chk_syndrome_list[5], coefs);
1171
1172 for (test_root = 0x1; test_root < 0xfff; test_root++) {
1173 err_loc_eqn = gf4096_mul(coefs[2],
1174 gf4096_mul(gf4096_mul(test_root, test_root),
1175 test_root)) ^ gf4096_mul(coefs[1], gf4096_mul(test_root, test_root))
1176 ^ gf4096_mul(coefs[0], test_root) ^ 0x1;
1177
1178 if (err_loc_eqn == 0x0) {
1179 if (found_num_root == 0) {
1180 bit3_root0 = test_root;
1181 found_num_root = 1;
1182 } else if (found_num_root == 1) {
1183 bit3_root1 = test_root;
1184 found_num_root = 2;
1185 } else if (found_num_root == 2) {
1186 bit3_root2 = test_root;
1187 found_num_root = 3;
1188 break;
1189 }
1190 }
1191 }
1192 if (found_num_root != 3)
1193 return -EINVAL;
1194 else {
1195 bit3_root0_inv = gf4096_inv(bit3_root0);
1196 bit3_root1_inv = gf4096_inv(bit3_root1);
1197 bit3_root2_inv = gf4096_inv(bit3_root2);
1198
1199 find_3bit_err_pats(chk_syndrome_list[0], chk_syndrome_list[1],
1200 chk_syndrome_list[2], bit3_root0_inv,
1201 bit3_root1_inv, bit3_root2_inv, err_pats);
1202
1203 //check if only 3-bit error
1204 tmp0 = gf4096_mul(bit3_root0_inv, bit3_root0_inv);
1205 tmp0 = gf4096_mul(tmp0, tmp0);
1206 tmp0 = gf4096_mul(tmp0, bit3_root0_inv);
1207 tmp0 = gf4096_mul(tmp0, bit3_root0_inv); //rinv0^6
1208 tmp1 = gf4096_mul(tmp0, bit3_root0_inv); //rinv0^7
1209 tmp2 = gf4096_mul(bit3_root1_inv, bit3_root1_inv);
1210 tmp2 = gf4096_mul(tmp2, tmp2);
1211 tmp2 = gf4096_mul(tmp2, bit3_root1_inv);
1212 tmp2 = gf4096_mul(tmp2, bit3_root1_inv); //rinv1^6
1213 tmp3 = gf4096_mul(tmp2, bit3_root1_inv); //rinv1^7
1214 tmp4 = gf4096_mul(bit3_root2_inv, bit3_root2_inv);
1215 tmp4 = gf4096_mul(tmp4, tmp4);
1216 tmp4 = gf4096_mul(tmp4, bit3_root2_inv);
1217 tmp4 = gf4096_mul(tmp4, bit3_root2_inv); //rinv2^6
1218 tmp5 = gf4096_mul(tmp4, bit3_root2_inv); //rinv2^7
1219
1220 //check if only 3 errors
1221 if ((chk_syndrome_list[6] == (gf4096_mul(err_pats[0], tmp0) ^
1222 gf4096_mul(err_pats[1], tmp2) ^
1223 gf4096_mul(err_pats[2], tmp4))) &
1224 (chk_syndrome_list[7] == (gf4096_mul(err_pats[0], tmp1) ^
1225 gf4096_mul(err_pats[1], tmp3) ^ gf4096_mul(err_pats[2], tmp5)))) {
1226 if ((err_pos(bit3_root0_inv) == 0xfff) |
1227 (err_pos(bit3_root1_inv) == 0xfff) | (err_pos(bit3_root2_inv) == 0xfff)) {
1228 return -EINVAL;
1229 } else {
1230 err_info[0] = 0x3;
1231 err_info[1] = (0x55e - err_pos(bit3_root0_inv));
1232 err_info[2] = (0x55e - err_pos(bit3_root1_inv));
1233 err_info[3] = (0x55e - err_pos(bit3_root2_inv));
1234 err_info[5] = err_pats[0];
1235 err_info[6] = err_pats[1];
1236 err_info[7] = err_pats[2];
1237 return 0;
1238 }
1239 } else
1240 return -EINVAL;
1241 }
1242}
1243static int chk_4_err_only(unsigned short *chk_syndrome_list, unsigned short *err_info)
1244{
1245 unsigned short coefs[4];
1246 unsigned short err_pats[4];
1247 int found_num_root = 0;
1248 unsigned short bit4_root0, bit4_root1, bit4_root2, bit4_root3;
1249 unsigned short bit4_root0_inv, bit4_root1_inv, bit4_root2_inv, bit4_root3_inv;
1250 unsigned short err_loc_eqn, test_root;
1251
1252 find_4bit_err_coefs(chk_syndrome_list[0],
1253 chk_syndrome_list[1],
1254 chk_syndrome_list[2],
1255 chk_syndrome_list[3],
1256 chk_syndrome_list[4],
1257 chk_syndrome_list[5], chk_syndrome_list[6], chk_syndrome_list[7], coefs);
1258
1259 for (test_root = 0x1; test_root < 0xfff; test_root++) {
1260 err_loc_eqn =
1261 gf4096_mul(coefs[3],
1262 gf4096_mul(gf4096_mul
1263 (gf4096_mul(test_root, test_root),
1264 test_root),
1265 test_root)) ^ gf4096_mul(coefs[2],
1266 gf4096_mul
1267 (gf4096_mul(test_root, test_root), test_root))
1268 ^ gf4096_mul(coefs[1], gf4096_mul(test_root, test_root)) ^ gf4096_mul(coefs[0], test_root)
1269 ^ 0x1;
1270 if (err_loc_eqn == 0x0) {
1271 if (found_num_root == 0) {
1272 bit4_root0 = test_root;
1273 found_num_root = 1;
1274 } else if (found_num_root == 1) {
1275 bit4_root1 = test_root;
1276 found_num_root = 2;
1277 } else if (found_num_root == 2) {
1278 bit4_root2 = test_root;
1279 found_num_root = 3;
1280 } else {
1281 found_num_root = 4;
1282 bit4_root3 = test_root;
1283 break;
1284 }
1285 }
1286 }
1287 if (found_num_root != 4) {
1288 return -EINVAL;
1289 } else {
1290 bit4_root0_inv = gf4096_inv(bit4_root0);
1291 bit4_root1_inv = gf4096_inv(bit4_root1);
1292 bit4_root2_inv = gf4096_inv(bit4_root2);
1293 bit4_root3_inv = gf4096_inv(bit4_root3);
1294 find_4bit_err_pats(chk_syndrome_list[0],
1295 chk_syndrome_list[1],
1296 chk_syndrome_list[2],
1297 chk_syndrome_list[3],
1298 bit4_root0_inv, bit4_root1_inv, bit4_root2_inv, bit4_root3_inv, err_pats);
1299 err_info[0] = 0x4;
1300 err_info[1] = (0x55e - err_pos(bit4_root0_inv));
1301 err_info[2] = (0x55e - err_pos(bit4_root1_inv));
1302 err_info[3] = (0x55e - err_pos(bit4_root2_inv));
1303 err_info[4] = (0x55e - err_pos(bit4_root3_inv));
1304 err_info[5] = err_pats[0];
1305 err_info[6] = err_pats[1];
1306 err_info[7] = err_pats[2];
1307 err_info[8] = err_pats[3];
1308 return 0;
1309 }
1310}
1311
1312void correct_12bit_symbol(unsigned char *buf, unsigned short sym,
1313 unsigned short val)
1314{
1315 if (unlikely(sym > 1366)) {
1316 printk(KERN_ERR "Error: symbol %d out of range; cannot correct\n", sym);
1317 } else if (sym == 0) {
1318 buf[0] ^= val;
1319 } else if (sym & 1) {
1320 buf[1+(3*(sym-1))/2] ^= (val >> 4);
1321 buf[2+(3*(sym-1))/2] ^= ((val & 0xf) << 4);
1322 } else {
1323 buf[2+(3*(sym-2))/2] ^= (val >> 8);
1324 buf[3+(3*(sym-2))/2] ^= (val & 0xff);
1325 }
1326}
1327
1328static int debugecc = 0;
1329module_param(debugecc, int, 0644);
1330
1331int cafe_correct_ecc(unsigned char *buf,
1332 unsigned short *chk_syndrome_list)
1333{
1334 unsigned short err_info[9];
1335 int i;
1336
1337 if (debugecc) {
1338 printk(KERN_WARNING "cafe_correct_ecc invoked. Syndromes %x %x %x %x %x %x %x %x\n",
1339 chk_syndrome_list[0], chk_syndrome_list[1],
1340 chk_syndrome_list[2], chk_syndrome_list[3],
1341 chk_syndrome_list[4], chk_syndrome_list[5],
1342 chk_syndrome_list[6], chk_syndrome_list[7]);
1343 for (i=0; i < 2048; i+=16) {
1344 printk(KERN_WARNING "D %04x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
1345 i,
1346 buf[i], buf[i+1], buf[i+2], buf[i+3],
1347 buf[i+4], buf[i+5], buf[i+6], buf[i+7],
1348 buf[i+8], buf[i+9], buf[i+10], buf[i+11],
1349 buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
1350 }
1351 for ( ; i < 2112; i+=16) {
1352 printk(KERN_WARNING "O %02x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
1353 i - 2048,
1354 buf[i], buf[i+1], buf[i+2], buf[i+3],
1355 buf[i+4], buf[i+5], buf[i+6], buf[i+7],
1356 buf[i+8], buf[i+9], buf[i+10], buf[i+11],
1357 buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
1358 }
1359 }
1360
1361
1362
1363 if (chk_no_err_only(chk_syndrome_list, err_info) &&
1364 chk_1_err_only(chk_syndrome_list, err_info) &&
1365 chk_2_err_only(chk_syndrome_list, err_info) &&
1366 chk_3_err_only(chk_syndrome_list, err_info) &&
1367 chk_4_err_only(chk_syndrome_list, err_info)) {
1368 return -EIO;
1369 }
1370
1371 for (i=0; i < err_info[0]; i++) {
1372 if (debugecc)
1373 printk(KERN_WARNING "Correct symbol %d with 0x%03x\n",
1374 err_info[1+i], err_info[5+i]);
1375
1376 correct_12bit_symbol(buf, err_info[1+i], err_info[5+i]);
1377 }
1378
1379 return err_info[0];
1380}
1381
diff --git a/drivers/mtd/nand/cafe.c b/drivers/mtd/nand/cafe_nand.c
index c328a7514510..cff969d05d4a 100644
--- a/drivers/mtd/nand/cafe.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -11,6 +11,7 @@
11#undef DEBUG 11#undef DEBUG
12#include <linux/mtd/mtd.h> 12#include <linux/mtd/mtd.h>
13#include <linux/mtd/nand.h> 13#include <linux/mtd/nand.h>
14#include <linux/rslib.h>
14#include <linux/pci.h> 15#include <linux/pci.h>
15#include <linux/delay.h> 16#include <linux/delay.h>
16#include <linux/interrupt.h> 17#include <linux/interrupt.h>
@@ -46,13 +47,14 @@
46#define CAFE_GLOBAL_IRQ_MASK 0x300c 47#define CAFE_GLOBAL_IRQ_MASK 0x300c
47#define CAFE_NAND_RESET 0x3034 48#define CAFE_NAND_RESET 0x3034
48 49
49int cafe_correct_ecc(unsigned char *buf, 50/* Missing from the datasheet: bit 19 of CTRL1 sets CE0 vs. CE1 */
50 unsigned short *chk_syndrome_list); 51#define CTRL1_CHIPSELECT (1<<19)
51 52
52struct cafe_priv { 53struct cafe_priv {
53 struct nand_chip nand; 54 struct nand_chip nand;
54 struct pci_dev *pdev; 55 struct pci_dev *pdev;
55 void __iomem *mmio; 56 void __iomem *mmio;
57 struct rs_control *rs;
56 uint32_t ctl1; 58 uint32_t ctl1;
57 uint32_t ctl2; 59 uint32_t ctl2;
58 int datalen; 60 int datalen;
@@ -195,8 +197,8 @@ static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
195 197
196 cafe->data_pos = cafe->datalen = 0; 198 cafe->data_pos = cafe->datalen = 0;
197 199
198 /* Set command valid bit */ 200 /* Set command valid bit, mask in the chip select bit */
199 ctl1 = 0x80000000 | command; 201 ctl1 = 0x80000000 | command | (cafe->ctl1 & CTRL1_CHIPSELECT);
200 202
201 /* Set RD or WR bits as appropriate */ 203 /* Set RD or WR bits as appropriate */
202 if (command == NAND_CMD_READID || command == NAND_CMD_STATUS) { 204 if (command == NAND_CMD_READID || command == NAND_CMD_STATUS) {
@@ -309,8 +311,16 @@ static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
309 311
310static void cafe_select_chip(struct mtd_info *mtd, int chipnr) 312static void cafe_select_chip(struct mtd_info *mtd, int chipnr)
311{ 313{
312 //struct cafe_priv *cafe = mtd->priv; 314 struct cafe_priv *cafe = mtd->priv;
313 // cafe_dev_dbg(&cafe->pdev->dev, "select_chip %d\n", chipnr); 315
316 cafe_dev_dbg(&cafe->pdev->dev, "select_chip %d\n", chipnr);
317
318 /* Mask the appropriate bit into the stored value of ctl1
319 which will be used by cafe_nand_cmdfunc() */
320 if (chipnr)
321 cafe->ctl1 |= CTRL1_CHIPSELECT;
322 else
323 cafe->ctl1 &= ~CTRL1_CHIPSELECT;
314} 324}
315 325
316static int cafe_nand_interrupt(int irq, void *id) 326static int cafe_nand_interrupt(int irq, void *id)
@@ -374,28 +384,66 @@ static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
374 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); 384 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
375 385
376 if (checkecc && cafe_readl(cafe, NAND_ECC_RESULT) & (1<<18)) { 386 if (checkecc && cafe_readl(cafe, NAND_ECC_RESULT) & (1<<18)) {
377 unsigned short syn[8]; 387 unsigned short syn[8], pat[4];
378 int i; 388 int pos[4];
389 u8 *oob = chip->oob_poi;
390 int i, n;
379 391
380 for (i=0; i<8; i+=2) { 392 for (i=0; i<8; i+=2) {
381 uint32_t tmp = cafe_readl(cafe, NAND_ECC_SYN01 + (i*2)); 393 uint32_t tmp = cafe_readl(cafe, NAND_ECC_SYN01 + (i*2));
382 syn[i] = tmp & 0xfff; 394 syn[i] = cafe->rs->index_of[tmp & 0xfff];
383 syn[i+1] = (tmp >> 16) & 0xfff; 395 syn[i+1] = cafe->rs->index_of[(tmp >> 16) & 0xfff];
396 }
397
398 n = decode_rs16(cafe->rs, NULL, NULL, 1367, syn, 0, pos, 0,
399 pat);
400
401 for (i = 0; i < n; i++) {
402 int p = pos[i];
403
404 /* The 12-bit symbols are mapped to bytes here */
405
406 if (p > 1374) {
407 /* out of range */
408 n = -1374;
409 } else if (p == 0) {
410 /* high four bits do not correspond to data */
411 if (pat[i] > 0xff)
412 n = -2048;
413 else
414 buf[0] ^= pat[i];
415 } else if (p == 1365) {
416 buf[2047] ^= pat[i] >> 4;
417 oob[0] ^= pat[i] << 4;
418 } else if (p > 1365) {
419 if ((p & 1) == 1) {
420 oob[3*p/2 - 2048] ^= pat[i] >> 4;
421 oob[3*p/2 - 2047] ^= pat[i] << 4;
422 } else {
423 oob[3*p/2 - 2049] ^= pat[i] >> 8;
424 oob[3*p/2 - 2048] ^= pat[i];
425 }
426 } else if ((p & 1) == 1) {
427 buf[3*p/2] ^= pat[i] >> 4;
428 buf[3*p/2 + 1] ^= pat[i] << 4;
429 } else {
430 buf[3*p/2 - 1] ^= pat[i] >> 8;
431 buf[3*p/2] ^= pat[i];
432 }
384 } 433 }
385 434
386 if ((i = cafe_correct_ecc(buf, syn)) < 0) { 435 if (n < 0) {
387 dev_dbg(&cafe->pdev->dev, "Failed to correct ECC at %08x\n", 436 dev_dbg(&cafe->pdev->dev, "Failed to correct ECC at %08x\n",
388 cafe_readl(cafe, NAND_ADDR2) * 2048); 437 cafe_readl(cafe, NAND_ADDR2) * 2048);
389 for (i=0; i< 0x5c; i+=4) 438 for (i = 0; i < 0x5c; i += 4)
390 printk("Register %x: %08x\n", i, readl(cafe->mmio + i)); 439 printk("Register %x: %08x\n", i, readl(cafe->mmio + i));
391 mtd->ecc_stats.failed++; 440 mtd->ecc_stats.failed++;
392 } else { 441 } else {
393 dev_dbg(&cafe->pdev->dev, "Corrected %d symbol errors\n", i); 442 dev_dbg(&cafe->pdev->dev, "Corrected %d symbol errors\n", n);
394 mtd->ecc_stats.corrected += i; 443 mtd->ecc_stats.corrected += n;
395 } 444 }
396 } 445 }
397 446
398
399 return 0; 447 return 0;
400} 448}
401 449
@@ -416,7 +464,7 @@ static uint8_t cafe_mirror_pattern_512[] = { 0xBC };
416 464
417static struct nand_bbt_descr cafe_bbt_main_descr_2048 = { 465static struct nand_bbt_descr cafe_bbt_main_descr_2048 = {
418 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE 466 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
419 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, 467 | NAND_BBT_2BIT | NAND_BBT_VERSION,
420 .offs = 14, 468 .offs = 14,
421 .len = 4, 469 .len = 4,
422 .veroffs = 18, 470 .veroffs = 18,
@@ -426,7 +474,7 @@ static struct nand_bbt_descr cafe_bbt_main_descr_2048 = {
426 474
427static struct nand_bbt_descr cafe_bbt_mirror_descr_2048 = { 475static struct nand_bbt_descr cafe_bbt_mirror_descr_2048 = {
428 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE 476 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
429 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, 477 | NAND_BBT_2BIT | NAND_BBT_VERSION,
430 .offs = 14, 478 .offs = 14,
431 .len = 4, 479 .len = 4,
432 .veroffs = 18, 480 .veroffs = 18,
@@ -442,7 +490,7 @@ static struct nand_ecclayout cafe_oobinfo_512 = {
442 490
443static struct nand_bbt_descr cafe_bbt_main_descr_512 = { 491static struct nand_bbt_descr cafe_bbt_main_descr_512 = {
444 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE 492 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
445 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, 493 | NAND_BBT_2BIT | NAND_BBT_VERSION,
446 .offs = 14, 494 .offs = 14,
447 .len = 1, 495 .len = 1,
448 .veroffs = 15, 496 .veroffs = 15,
@@ -452,7 +500,7 @@ static struct nand_bbt_descr cafe_bbt_main_descr_512 = {
452 500
453static struct nand_bbt_descr cafe_bbt_mirror_descr_512 = { 501static struct nand_bbt_descr cafe_bbt_mirror_descr_512 = {
454 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE 502 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
455 | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, 503 | NAND_BBT_2BIT | NAND_BBT_VERSION,
456 .offs = 14, 504 .offs = 14,
457 .len = 1, 505 .len = 1,
458 .veroffs = 15, 506 .veroffs = 15,
@@ -525,6 +573,48 @@ static int cafe_nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
525 return 0; 573 return 0;
526} 574}
527 575
576/* F_2[X]/(X**6+X+1) */
577static unsigned short __devinit gf64_mul(u8 a, u8 b)
578{
579 u8 c;
580 unsigned int i;
581
582 c = 0;
583 for (i = 0; i < 6; i++) {
584 if (a & 1)
585 c ^= b;
586 a >>= 1;
587 b <<= 1;
588 if ((b & 0x40) != 0)
589 b ^= 0x43;
590 }
591
592 return c;
593}
594
595/* F_64[X]/(X**2+X+A**-1) with A the generator of F_64[X] */
596static u16 __devinit gf4096_mul(u16 a, u16 b)
597{
598 u8 ah, al, bh, bl, ch, cl;
599
600 ah = a >> 6;
601 al = a & 0x3f;
602 bh = b >> 6;
603 bl = b & 0x3f;
604
605 ch = gf64_mul(ah ^ al, bh ^ bl) ^ gf64_mul(al, bl);
606 cl = gf64_mul(gf64_mul(ah, bh), 0x21) ^ gf64_mul(al, bl);
607
608 return (ch << 6) ^ cl;
609}
610
611static int __devinit cafe_mul(int x)
612{
613 if (x == 0)
614 return 1;
615 return gf4096_mul(x, 0xe01);
616}
617
528static int __devinit cafe_nand_probe(struct pci_dev *pdev, 618static int __devinit cafe_nand_probe(struct pci_dev *pdev,
529 const struct pci_device_id *ent) 619 const struct pci_device_id *ent)
530{ 620{
@@ -564,6 +654,12 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
564 } 654 }
565 cafe->nand.buffers = (void *)cafe->dmabuf + 2112; 655 cafe->nand.buffers = (void *)cafe->dmabuf + 2112;
566 656
657 cafe->rs = init_rs_non_canonical(12, &cafe_mul, 0, 1, 8);
658 if (!cafe->rs) {
659 err = -ENOMEM;
660 goto out_ior;
661 }
662
567 cafe->nand.cmdfunc = cafe_nand_cmdfunc; 663 cafe->nand.cmdfunc = cafe_nand_cmdfunc;
568 cafe->nand.dev_ready = cafe_device_ready; 664 cafe->nand.dev_ready = cafe_device_ready;
569 cafe->nand.read_byte = cafe_read_byte; 665 cafe->nand.read_byte = cafe_read_byte;
@@ -646,7 +742,7 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
646 cafe_readl(cafe, GLOBAL_CTRL), cafe_readl(cafe, GLOBAL_IRQ_MASK)); 742 cafe_readl(cafe, GLOBAL_CTRL), cafe_readl(cafe, GLOBAL_IRQ_MASK));
647 743
648 /* Scan to find existence of the device */ 744 /* Scan to find existence of the device */
649 if (nand_scan_ident(mtd, 1)) { 745 if (nand_scan_ident(mtd, 2)) {
650 err = -ENXIO; 746 err = -ENXIO;
651 goto out_irq; 747 goto out_irq;
652 } 748 }
@@ -713,6 +809,7 @@ static void __devexit cafe_nand_remove(struct pci_dev *pdev)
713 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK); 809 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK);
714 free_irq(pdev->irq, mtd); 810 free_irq(pdev->irq, mtd);
715 nand_release(mtd); 811 nand_release(mtd);
812 free_rs(cafe->rs);
716 pci_iounmap(pdev, cafe->mmio); 813 pci_iounmap(pdev, cafe->mmio);
717 dma_free_coherent(&cafe->pdev->dev, 2112, cafe->dmabuf, cafe->dmaaddr); 814 dma_free_coherent(&cafe->pdev->dev, 2112, cafe->dmabuf, cafe->dmaaddr);
718 kfree(mtd); 815 kfree(mtd);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 04de315e4937..7e68203fe1ba 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -303,28 +303,27 @@ static int nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
303 struct nand_chip *chip = mtd->priv; 303 struct nand_chip *chip = mtd->priv;
304 u16 bad; 304 u16 bad;
305 305
306 page = (int)(ofs >> chip->page_shift) & chip->pagemask;
307
306 if (getchip) { 308 if (getchip) {
307 page = (int)(ofs >> chip->page_shift);
308 chipnr = (int)(ofs >> chip->chip_shift); 309 chipnr = (int)(ofs >> chip->chip_shift);
309 310
310 nand_get_device(chip, mtd, FL_READING); 311 nand_get_device(chip, mtd, FL_READING);
311 312
312 /* Select the NAND device */ 313 /* Select the NAND device */
313 chip->select_chip(mtd, chipnr); 314 chip->select_chip(mtd, chipnr);
314 } else 315 }
315 page = (int)(ofs >> chip->page_shift);
316 316
317 if (chip->options & NAND_BUSWIDTH_16) { 317 if (chip->options & NAND_BUSWIDTH_16) {
318 chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos & 0xFE, 318 chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos & 0xFE,
319 page & chip->pagemask); 319 page);
320 bad = cpu_to_le16(chip->read_word(mtd)); 320 bad = cpu_to_le16(chip->read_word(mtd));
321 if (chip->badblockpos & 0x1) 321 if (chip->badblockpos & 0x1)
322 bad >>= 8; 322 bad >>= 8;
323 if ((bad & 0xFF) != 0xff) 323 if ((bad & 0xFF) != 0xff)
324 res = 1; 324 res = 1;
325 } else { 325 } else {
326 chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, 326 chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, page);
327 page & chip->pagemask);
328 if (chip->read_byte(mtd) != 0xff) 327 if (chip->read_byte(mtd) != 0xff)
329 res = 1; 328 res = 1;
330 } 329 }
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
new file mode 100644
index 000000000000..cd725fc5e813
--- /dev/null
+++ b/drivers/mtd/nand/plat_nand.c
@@ -0,0 +1,150 @@
1/*
2 * Generic NAND driver
3 *
4 * Author: Vitaly Wool <vitalywool@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/io.h>
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <linux/slab.h>
16#include <linux/mtd/mtd.h>
17#include <linux/mtd/nand.h>
18#include <linux/mtd/partitions.h>
19
20struct plat_nand_data {
21 struct nand_chip chip;
22 struct mtd_info mtd;
23 void __iomem *io_base;
24#ifdef CONFIG_MTD_PARTITIONS
25 int nr_parts;
26 struct mtd_partition *parts;
27#endif
28};
29
30/*
31 * Probe for the NAND device.
32 */
33static int __init plat_nand_probe(struct platform_device *pdev)
34{
35 struct platform_nand_data *pdata = pdev->dev.platform_data;
36 struct plat_nand_data *data;
37 int res = 0;
38
39 /* Allocate memory for the device structure (and zero it) */
40 data = kzalloc(sizeof(struct plat_nand_data), GFP_KERNEL);
41 if (!data) {
42 dev_err(&pdev->dev, "failed to allocate device structure.\n");
43 return -ENOMEM;
44 }
45
46 data->io_base = ioremap(pdev->resource[0].start,
47 pdev->resource[0].end - pdev->resource[0].start + 1);
48 if (data->io_base == NULL) {
49 dev_err(&pdev->dev, "ioremap failed\n");
50 kfree(data);
51 return -EIO;
52 }
53
54 data->chip.priv = &data;
55 data->mtd.priv = &data->chip;
56 data->mtd.owner = THIS_MODULE;
57
58 data->chip.IO_ADDR_R = data->io_base;
59 data->chip.IO_ADDR_W = data->io_base;
60 data->chip.cmd_ctrl = pdata->ctrl.cmd_ctrl;
61 data->chip.dev_ready = pdata->ctrl.dev_ready;
62 data->chip.select_chip = pdata->ctrl.select_chip;
63 data->chip.chip_delay = pdata->chip.chip_delay;
64 data->chip.options |= pdata->chip.options;
65
66 data->chip.ecc.hwctl = pdata->ctrl.hwcontrol;
67 data->chip.ecc.layout = pdata->chip.ecclayout;
68 data->chip.ecc.mode = NAND_ECC_SOFT;
69
70 platform_set_drvdata(pdev, data);
71
72 /* Scan to find existance of the device */
73 if (nand_scan(&data->mtd, 1)) {
74 res = -ENXIO;
75 goto out;
76 }
77
78#ifdef CONFIG_MTD_PARTITIONS
79 if (pdata->chip.part_probe_types) {
80 res = parse_mtd_partitions(&data->mtd,
81 pdata->chip.part_probe_types,
82 &data->parts, 0);
83 if (res > 0) {
84 add_mtd_partitions(&data->mtd, data->parts, res);
85 return 0;
86 }
87 }
88 if (pdata->chip.partitions) {
89 data->parts = pdata->chip.partitions;
90 res = add_mtd_partitions(&data->mtd, data->parts,
91 pdata->chip.nr_partitions);
92 } else
93#endif
94 res = add_mtd_device(&data->mtd);
95
96 if (!res)
97 return res;
98
99 nand_release(&data->mtd);
100out:
101 platform_set_drvdata(pdev, NULL);
102 iounmap(data->io_base);
103 kfree(data);
104 return res;
105}
106
107/*
108 * Remove a NAND device.
109 */
110static int __devexit plat_nand_remove(struct platform_device *pdev)
111{
112 struct plat_nand_data *data = platform_get_drvdata(pdev);
113 struct platform_nand_data *pdata = pdev->dev.platform_data;
114
115 nand_release(&data->mtd);
116#ifdef CONFIG_MTD_PARTITIONS
117 if (data->parts && data->parts != pdata->chip.partitions)
118 kfree(data->parts);
119#endif
120 iounmap(data->io_base);
121 kfree(data);
122
123 return 0;
124}
125
126static struct platform_driver plat_nand_driver = {
127 .probe = plat_nand_probe,
128 .remove = plat_nand_remove,
129 .driver = {
130 .name = "gen_nand",
131 .owner = THIS_MODULE,
132 },
133};
134
135static int __init plat_nand_init(void)
136{
137 return platform_driver_register(&plat_nand_driver);
138}
139
140static void __exit plat_nand_exit(void)
141{
142 platform_driver_unregister(&plat_nand_driver);
143}
144
145module_init(plat_nand_init);
146module_exit(plat_nand_exit);
147
148MODULE_LICENSE("GPL");
149MODULE_AUTHOR("Vitaly Wool");
150MODULE_DESCRIPTION("Simple generic NAND driver");
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 000794c6caf5..0537fac8de74 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -2192,7 +2192,7 @@ static int onenand_check_maf(int manuf)
2192 * @param mtd MTD device structure 2192 * @param mtd MTD device structure
2193 * 2193 *
2194 * OneNAND detection method: 2194 * OneNAND detection method:
2195 * Compare the the values from command with ones from register 2195 * Compare the values from command with ones from register
2196 */ 2196 */
2197static int onenand_probe(struct mtd_info *mtd) 2197static int onenand_probe(struct mtd_info *mtd)
2198{ 2198{
diff --git a/drivers/mtd/ubi/eba.c b/drivers/mtd/ubi/eba.c
index 3dba5733ed1f..74002945b71b 100644
--- a/drivers/mtd/ubi/eba.c
+++ b/drivers/mtd/ubi/eba.c
@@ -940,9 +940,6 @@ static void ltree_entry_ctor(void *obj, struct kmem_cache *cache,
940{ 940{
941 struct ltree_entry *le = obj; 941 struct ltree_entry *le = obj;
942 942
943 if (flags & SLAB_CTOR_CONSTRUCTOR)
944 return;
945
946 le->users = 0; 943 le->users = 0;
947 init_rwsem(&le->mutex); 944 init_rwsem(&le->mutex);
948} 945}
diff --git a/drivers/net/3c509.c b/drivers/net/3c509.c
index 9588da3a30e7..127f60841b10 100644
--- a/drivers/net/3c509.c
+++ b/drivers/net/3c509.c
@@ -95,8 +95,7 @@ static int max_interrupt_work = 10;
95#include <asm/io.h> 95#include <asm/io.h>
96#include <asm/irq.h> 96#include <asm/irq.h>
97 97
98static char versionA[] __initdata = DRV_NAME ".c:" DRV_VERSION " " DRV_RELDATE " becker@scyld.com\n"; 98static char version[] __initdata = DRV_NAME ".c:" DRV_VERSION " " DRV_RELDATE " becker@scyld.com\n";
99static char versionB[] __initdata = "http://www.scyld.com/network/3c509.html\n";
100 99
101#if defined(CONFIG_PM) && (defined(CONFIG_MCA) || defined(CONFIG_EISA)) 100#if defined(CONFIG_PM) && (defined(CONFIG_MCA) || defined(CONFIG_EISA))
102#define EL3_SUSPEND 101#define EL3_SUSPEND
@@ -360,7 +359,7 @@ static int __init el3_common_init(struct net_device *dev)
360 printk(", IRQ %d.\n", dev->irq); 359 printk(", IRQ %d.\n", dev->irq);
361 360
362 if (el3_debug > 0) 361 if (el3_debug > 0)
363 printk(KERN_INFO "%s" KERN_INFO "%s", versionA, versionB); 362 printk(KERN_INFO "%s", version);
364 return 0; 363 return 0;
365 364
366} 365}
diff --git a/drivers/net/3c59x.c b/drivers/net/3c59x.c
index 80924f76dee8..f26ca331615e 100644
--- a/drivers/net/3c59x.c
+++ b/drivers/net/3c59x.c
@@ -103,7 +103,7 @@ static int vortex_debug = 1;
103 103
104 104
105static char version[] __devinitdata = 105static char version[] __devinitdata =
106DRV_NAME ": Donald Becker and others. www.scyld.com/network/vortex.html\n"; 106DRV_NAME ": Donald Becker and others.\n";
107 107
108MODULE_AUTHOR("Donald Becker <becker@scyld.com>"); 108MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
109MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver "); 109MODULE_DESCRIPTION("3Com 3c59x/3c9xx ethernet driver ");
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 279ec625cec4..c5baa197bc08 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -1104,7 +1104,7 @@ config ETH16I
1104 1104
1105config NE2000 1105config NE2000
1106 tristate "NE2000/NE1000 support" 1106 tristate "NE2000/NE1000 support"
1107 depends on NET_ISA || (Q40 && m) || M32R 1107 depends on NET_ISA || (Q40 && m) || M32R || TOSHIBA_RBTX4927 || TOSHIBA_RBTX4938
1108 select CRC32 1108 select CRC32
1109 ---help--- 1109 ---help---
1110 If you have a network (Ethernet) card of this type, say Y and read 1110 If you have a network (Ethernet) card of this type, say Y and read
@@ -1898,8 +1898,12 @@ endmenu
1898# Gigabit Ethernet 1898# Gigabit Ethernet
1899# 1899#
1900 1900
1901menu "Ethernet (1000 Mbit)" 1901menuconfig NETDEV_1000
1902 bool "Ethernet (1000 Mbit)"
1902 depends on !UML 1903 depends on !UML
1904 default y
1905
1906if NETDEV_1000
1903 1907
1904config ACENIC 1908config ACENIC
1905 tristate "Alteon AceNIC/3Com 3C985/NetGear GA620 Gigabit support" 1909 tristate "Alteon AceNIC/3Com 3C985/NetGear GA620 Gigabit support"
@@ -2299,7 +2303,7 @@ config UGETH_TX_ON_DEMAND
2299 2303
2300config MV643XX_ETH 2304config MV643XX_ETH
2301 tristate "MV-643XX Ethernet support" 2305 tristate "MV-643XX Ethernet support"
2302 depends on MOMENCO_OCELOT_C || MOMENCO_JAGUAR_ATX || MV64360 || MOMENCO_OCELOT_3 || (PPC_MULTIPLATFORM && PPC32) 2306 depends on MOMENCO_OCELOT_C || MOMENCO_JAGUAR_ATX || MV64360 || MV64X60 || MOMENCO_OCELOT_3 || (PPC_MULTIPLATFORM && PPC32)
2303 select MII 2307 select MII
2304 help 2308 help
2305 This driver supports the gigabit Ethernet on the Marvell MV643XX 2309 This driver supports the gigabit Ethernet on the Marvell MV643XX
@@ -2326,14 +2330,18 @@ config ATL1
2326 To compile this driver as a module, choose M here. The module 2330 To compile this driver as a module, choose M here. The module
2327 will be called atl1. 2331 will be called atl1.
2328 2332
2329endmenu 2333endif # NETDEV_1000
2330 2334
2331# 2335#
2332# 10 Gigabit Ethernet 2336# 10 Gigabit Ethernet
2333# 2337#
2334 2338
2335menu "Ethernet (10000 Mbit)" 2339menuconfig NETDEV_10000
2340 bool "Ethernet (10000 Mbit)"
2336 depends on !UML 2341 depends on !UML
2342 default y
2343
2344if NETDEV_10000
2337 2345
2338config CHELSIO_T1 2346config CHELSIO_T1
2339 tristate "Chelsio 10Gb Ethernet support" 2347 tristate "Chelsio 10Gb Ethernet support"
@@ -2488,16 +2496,34 @@ config NETXEN_NIC
2488config PASEMI_MAC 2496config PASEMI_MAC
2489 tristate "PA Semi 1/10Gbit MAC" 2497 tristate "PA Semi 1/10Gbit MAC"
2490 depends on PPC64 && PCI 2498 depends on PPC64 && PCI
2499 select PHYLIB
2491 help 2500 help
2492 This driver supports the on-chip 1/10Gbit Ethernet controller on 2501 This driver supports the on-chip 1/10Gbit Ethernet controller on
2493 PA Semi's PWRficient line of chips. 2502 PA Semi's PWRficient line of chips.
2494 2503
2495endmenu 2504config MLX4_CORE
2505 tristate
2506 depends on PCI
2507 default n
2508
2509config MLX4_DEBUG
2510 bool "Verbose debugging output" if (MLX4_CORE && EMBEDDED)
2511 depends on MLX4_CORE
2512 default y
2513 ---help---
2514 This option causes debugging code to be compiled into the
2515 mlx4_core driver. The output can be turned on via the
2516 debug_level module parameter (which can also be set after
2517 the driver is loaded through sysfs).
2518
2519endif # NETDEV_10000
2496 2520
2497source "drivers/net/tokenring/Kconfig" 2521source "drivers/net/tokenring/Kconfig"
2498 2522
2499source "drivers/net/wireless/Kconfig" 2523source "drivers/net/wireless/Kconfig"
2500 2524
2525source "drivers/net/usb/Kconfig"
2526
2501source "drivers/net/pcmcia/Kconfig" 2527source "drivers/net/pcmcia/Kconfig"
2502 2528
2503source "drivers/net/wan/Kconfig" 2529source "drivers/net/wan/Kconfig"
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index 59c0459a037c..a77affa4f6e6 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -197,6 +197,7 @@ obj-$(CONFIG_SMC911X) += smc911x.o
197obj-$(CONFIG_DM9000) += dm9000.o 197obj-$(CONFIG_DM9000) += dm9000.o
198obj-$(CONFIG_FEC_8XX) += fec_8xx/ 198obj-$(CONFIG_FEC_8XX) += fec_8xx/
199obj-$(CONFIG_PASEMI_MAC) += pasemi_mac.o 199obj-$(CONFIG_PASEMI_MAC) += pasemi_mac.o
200obj-$(CONFIG_MLX4_CORE) += mlx4/
200 201
201obj-$(CONFIG_MACB) += macb.o 202obj-$(CONFIG_MACB) += macb.o
202 203
@@ -206,6 +207,14 @@ obj-$(CONFIG_TR) += tokenring/
206obj-$(CONFIG_WAN) += wan/ 207obj-$(CONFIG_WAN) += wan/
207obj-$(CONFIG_ARCNET) += arcnet/ 208obj-$(CONFIG_ARCNET) += arcnet/
208obj-$(CONFIG_NET_PCMCIA) += pcmcia/ 209obj-$(CONFIG_NET_PCMCIA) += pcmcia/
210
211obj-$(CONFIG_USB_CATC) += usb/
212obj-$(CONFIG_USB_KAWETH) += usb/
213obj-$(CONFIG_USB_PEGASUS) += usb/
214obj-$(CONFIG_USB_RTL8150) += usb/
215obj-$(CONFIG_USB_USBNET) += usb/
216obj-$(CONFIG_USB_ZD1201) += usb/
217
209obj-y += wireless/ 218obj-y += wireless/
210obj-$(CONFIG_NET_TULIP) += tulip/ 219obj-$(CONFIG_NET_TULIP) += tulip/
211obj-$(CONFIG_HAMRADIO) += hamradio/ 220obj-$(CONFIG_HAMRADIO) += hamradio/
diff --git a/drivers/net/arm/at91_ether.c b/drivers/net/arm/at91_ether.c
index 152fa7a042b8..ef2cc80256a3 100644
--- a/drivers/net/arm/at91_ether.c
+++ b/drivers/net/arm/at91_ether.c
@@ -225,6 +225,16 @@ static irqreturn_t at91ether_phy_interrupt(int irq, void *dev_id)
225 if (!(phy & ((1 << 2) | 1))) 225 if (!(phy & ((1 << 2) | 1)))
226 goto done; 226 goto done;
227 } 227 }
228 else if (lp->phy_type == MII_T78Q21x3_ID) { /* ack interrupt in Teridian PHY */
229 read_phy(lp->phy_address, MII_T78Q21INT_REG, &phy);
230 if (!(phy & ((1 << 2) | 1)))
231 goto done;
232 }
233 else if (lp->phy_type == MII_DP83848_ID) {
234 read_phy(lp->phy_address, MII_DPPHYSTS_REG, &phy); /* ack interrupt in DP83848 PHY */
235 if (!(phy & (1 << 7)))
236 goto done;
237 }
228 238
229 update_linkspeed(dev, 0); 239 update_linkspeed(dev, 0);
230 240
@@ -280,6 +290,19 @@ static void enable_phyirq(struct net_device *dev)
280 dsintr = (1 << 10) | ( 1 << 8); 290 dsintr = (1 << 10) | ( 1 << 8);
281 write_phy(lp->phy_address, MII_TPISTATUS, dsintr); 291 write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
282 } 292 }
293 else if (lp->phy_type == MII_T78Q21x3_ID) { /* for Teridian PHY */
294 read_phy(lp->phy_address, MII_T78Q21INT_REG, &dsintr);
295 dsintr = dsintr | 0x500; /* set bits 8, 10 */
296 write_phy(lp->phy_address, MII_T78Q21INT_REG, dsintr);
297 }
298 else if (lp->phy_type == MII_DP83848_ID) { /* National Semiconductor DP83848 PHY */
299 read_phy(lp->phy_address, MII_DPMISR_REG, &dsintr);
300 dsintr = dsintr | 0x3c; /* set bits 2..5 */
301 write_phy(lp->phy_address, MII_DPMISR_REG, dsintr);
302 read_phy(lp->phy_address, MII_DPMICR_REG, &dsintr);
303 dsintr = dsintr | 0x3; /* set bits 0,1 */
304 write_phy(lp->phy_address, MII_DPMICR_REG, dsintr);
305 }
283 306
284 disable_mdi(); 307 disable_mdi();
285 spin_unlock_irq(&lp->lock); 308 spin_unlock_irq(&lp->lock);
@@ -323,6 +346,19 @@ static void disable_phyirq(struct net_device *dev)
323 dsintr = ~((1 << 10) | (1 << 8)); 346 dsintr = ~((1 << 10) | (1 << 8));
324 write_phy(lp->phy_address, MII_TPISTATUS, dsintr); 347 write_phy(lp->phy_address, MII_TPISTATUS, dsintr);
325 } 348 }
349 else if (lp->phy_type == MII_T78Q21x3_ID) { /* for Teridian PHY */
350 read_phy(lp->phy_address, MII_T78Q21INT_REG, &dsintr);
351 dsintr = dsintr & ~0x500; /* clear bits 8, 10 */
352 write_phy(lp->phy_address, MII_T78Q21INT_REG, dsintr);
353 }
354 else if (lp->phy_type == MII_DP83848_ID) { /* National Semiconductor DP83848 PHY */
355 read_phy(lp->phy_address, MII_DPMICR_REG, &dsintr);
356 dsintr = dsintr & ~0x3; /* clear bits 0, 1 */
357 write_phy(lp->phy_address, MII_DPMICR_REG, dsintr);
358 read_phy(lp->phy_address, MII_DPMISR_REG, &dsintr);
359 dsintr = dsintr & ~0x3c; /* clear bits 2..5 */
360 write_phy(lp->phy_address, MII_DPMISR_REG, dsintr);
361 }
326 362
327 disable_mdi(); 363 disable_mdi();
328 spin_unlock_irq(&lp->lock); 364 spin_unlock_irq(&lp->lock);
@@ -535,8 +571,8 @@ static void at91ether_sethashtable(struct net_device *dev)
535 mc_filter[bitnr >> 5] |= 1 << (bitnr & 31); 571 mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
536 } 572 }
537 573
538 at91_emac_write(AT91_EMAC_HSH, mc_filter[0]); 574 at91_emac_write(AT91_EMAC_HSL, mc_filter[0]);
539 at91_emac_write(AT91_EMAC_HSL, mc_filter[1]); 575 at91_emac_write(AT91_EMAC_HSH, mc_filter[1]);
540} 576}
541 577
542/* 578/*
@@ -1062,10 +1098,16 @@ static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_add
1062 printk(KERN_INFO "%s: Broadcom BCM5221 PHY\n", dev->name); 1098 printk(KERN_INFO "%s: Broadcom BCM5221 PHY\n", dev->name);
1063 else if (phy_type == MII_DP83847_ID) 1099 else if (phy_type == MII_DP83847_ID)
1064 printk(KERN_INFO "%s: National Semiconductor DP83847 PHY\n", dev->name); 1100 printk(KERN_INFO "%s: National Semiconductor DP83847 PHY\n", dev->name);
1101 else if (phy_type == MII_DP83848_ID)
1102 printk(KERN_INFO "%s: National Semiconductor DP83848 PHY\n", dev->name);
1065 else if (phy_type == MII_AC101L_ID) 1103 else if (phy_type == MII_AC101L_ID)
1066 printk(KERN_INFO "%s: Altima AC101L PHY\n", dev->name); 1104 printk(KERN_INFO "%s: Altima AC101L PHY\n", dev->name);
1067 else if (phy_type == MII_KS8721_ID) 1105 else if (phy_type == MII_KS8721_ID)
1068 printk(KERN_INFO "%s: Micrel KS8721 PHY\n", dev->name); 1106 printk(KERN_INFO "%s: Micrel KS8721 PHY\n", dev->name);
1107 else if (phy_type == MII_T78Q21x3_ID)
1108 printk(KERN_INFO "%s: Teridian 78Q21x3 PHY\n", dev->name);
1109 else if (phy_type == MII_LAN83C185_ID)
1110 printk(KERN_INFO "%s: SMSC LAN83C185 PHY\n", dev->name);
1069 1111
1070 return 0; 1112 return 0;
1071} 1113}
@@ -1103,8 +1145,11 @@ static int __init at91ether_probe(struct platform_device *pdev)
1103 case MII_RTL8201_ID: /* Realtek RTL8201: PHY_ID1 = 0, PHY_ID2 = 0x8201 */ 1145 case MII_RTL8201_ID: /* Realtek RTL8201: PHY_ID1 = 0, PHY_ID2 = 0x8201 */
1104 case MII_BCM5221_ID: /* Broadcom BCM5221: PHY_ID1 = 0x40, PHY_ID2 = 0x61e0 */ 1146 case MII_BCM5221_ID: /* Broadcom BCM5221: PHY_ID1 = 0x40, PHY_ID2 = 0x61e0 */
1105 case MII_DP83847_ID: /* National Semiconductor DP83847: */ 1147 case MII_DP83847_ID: /* National Semiconductor DP83847: */
1148 case MII_DP83848_ID: /* National Semiconductor DP83848: */
1106 case MII_AC101L_ID: /* Altima AC101L: PHY_ID1 = 0x22, PHY_ID2 = 0x5520 */ 1149 case MII_AC101L_ID: /* Altima AC101L: PHY_ID1 = 0x22, PHY_ID2 = 0x5520 */
1107 case MII_KS8721_ID: /* Micrel KS8721: PHY_ID1 = 0x22, PHY_ID2 = 0x1610 */ 1150 case MII_KS8721_ID: /* Micrel KS8721: PHY_ID1 = 0x22, PHY_ID2 = 0x1610 */
1151 case MII_T78Q21x3_ID: /* Teridian 78Q21x3: PHY_ID1 = 0x0E, PHY_ID2 = 7237 */
1152 case MII_LAN83C185_ID: /* SMSC LAN83C185: PHY_ID1 = 0x0007, PHY_ID2 = 0xC0A1 */
1108 detected = at91ether_setup(phy_id, phy_address, pdev, ether_clk); 1153 detected = at91ether_setup(phy_id, phy_address, pdev, ether_clk);
1109 break; 1154 break;
1110 } 1155 }
diff --git a/drivers/net/arm/at91_ether.h b/drivers/net/arm/at91_ether.h
index b6b665de2ea0..a38fd2d053a6 100644
--- a/drivers/net/arm/at91_ether.h
+++ b/drivers/net/arm/at91_ether.h
@@ -17,39 +17,46 @@
17 17
18 18
19/* Davicom 9161 PHY */ 19/* Davicom 9161 PHY */
20#define MII_DM9161_ID 0x0181b880 20#define MII_DM9161_ID 0x0181b880
21#define MII_DM9161A_ID 0x0181b8a0 21#define MII_DM9161A_ID 0x0181b8a0
22 22#define MII_DSCR_REG 16
23/* Davicom specific registers */ 23#define MII_DSCSR_REG 17
24#define MII_DSCR_REG 16 24#define MII_DSINTR_REG 21
25#define MII_DSCSR_REG 17
26#define MII_DSINTR_REG 21
27 25
28/* Intel LXT971A PHY */ 26/* Intel LXT971A PHY */
29#define MII_LXT971A_ID 0x001378E0 27#define MII_LXT971A_ID 0x001378E0
30 28#define MII_ISINTE_REG 18
31/* Intel specific registers */ 29#define MII_ISINTS_REG 19
32#define MII_ISINTE_REG 18 30#define MII_LEDCTRL_REG 20
33#define MII_ISINTS_REG 19
34#define MII_LEDCTRL_REG 20
35 31
36/* Realtek RTL8201 PHY */ 32/* Realtek RTL8201 PHY */
37#define MII_RTL8201_ID 0x00008200 33#define MII_RTL8201_ID 0x00008200
38 34
39/* Broadcom BCM5221 PHY */ 35/* Broadcom BCM5221 PHY */
40#define MII_BCM5221_ID 0x004061e0 36#define MII_BCM5221_ID 0x004061e0
41 37#define MII_BCMINTR_REG 26
42/* Broadcom specific registers */
43#define MII_BCMINTR_REG 26
44 38
45/* National Semiconductor DP83847 */ 39/* National Semiconductor DP83847 */
46#define MII_DP83847_ID 0x20005c30 40#define MII_DP83847_ID 0x20005c30
41
42/* National Semiconductor DP83848 */
43#define MII_DP83848_ID 0x20005c90
44#define MII_DPPHYSTS_REG 16
45#define MII_DPMICR_REG 17
46#define MII_DPMISR_REG 18
47 47
48/* Altima AC101L PHY */ 48/* Altima AC101L PHY */
49#define MII_AC101L_ID 0x00225520 49#define MII_AC101L_ID 0x00225520
50 50
51/* Micrel KS8721 PHY */ 51/* Micrel KS8721 PHY */
52#define MII_KS8721_ID 0x00221610 52#define MII_KS8721_ID 0x00221610
53
54/* Teridian 78Q2123/78Q2133 */
55#define MII_T78Q21x3_ID 0x000e7230
56#define MII_T78Q21INT_REG 17
57
58/* SMSC LAN83C185 */
59#define MII_LAN83C185_ID 0x0007C0A0
53 60
54/* ........................................................................ */ 61/* ........................................................................ */
55 62
diff --git a/drivers/net/arm/ether1.c b/drivers/net/arm/ether1.c
index f075cebe84ad..f21148e7b579 100644
--- a/drivers/net/arm/ether1.c
+++ b/drivers/net/arm/ether1.c
@@ -1014,8 +1014,7 @@ ether1_probe(struct expansion_card *ec, const struct ecard_id *id)
1014 SET_NETDEV_DEV(dev, &ec->dev); 1014 SET_NETDEV_DEV(dev, &ec->dev);
1015 1015
1016 dev->irq = ec->irq; 1016 dev->irq = ec->irq;
1017 priv(dev)->base = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), 1017 priv(dev)->base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
1018 ecard_resource_len(ec, ECARD_RES_IOCFAST));
1019 if (!priv(dev)->base) { 1018 if (!priv(dev)->base) {
1020 ret = -ENOMEM; 1019 ret = -ENOMEM;
1021 goto free; 1020 goto free;
@@ -1056,8 +1055,6 @@ ether1_probe(struct expansion_card *ec, const struct ecard_id *id)
1056 return 0; 1055 return 0;
1057 1056
1058 free: 1057 free:
1059 if (priv(dev)->base)
1060 iounmap(priv(dev)->base);
1061 free_netdev(dev); 1058 free_netdev(dev);
1062 release: 1059 release:
1063 ecard_release_resources(ec); 1060 ecard_release_resources(ec);
@@ -1072,7 +1069,6 @@ static void __devexit ether1_remove(struct expansion_card *ec)
1072 ecard_set_drvdata(ec, NULL); 1069 ecard_set_drvdata(ec, NULL);
1073 1070
1074 unregister_netdev(dev); 1071 unregister_netdev(dev);
1075 iounmap(priv(dev)->base);
1076 free_netdev(dev); 1072 free_netdev(dev);
1077 ecard_release_resources(ec); 1073 ecard_release_resources(ec);
1078} 1074}
diff --git a/drivers/net/arm/ether3.c b/drivers/net/arm/ether3.c
index 32da2eb9bcee..da713500654d 100644
--- a/drivers/net/arm/ether3.c
+++ b/drivers/net/arm/ether3.c
@@ -793,8 +793,7 @@ ether3_probe(struct expansion_card *ec, const struct ecard_id *id)
793 SET_MODULE_OWNER(dev); 793 SET_MODULE_OWNER(dev);
794 SET_NETDEV_DEV(dev, &ec->dev); 794 SET_NETDEV_DEV(dev, &ec->dev);
795 795
796 priv(dev)->base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), 796 priv(dev)->base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
797 ecard_resource_len(ec, ECARD_RES_MEMC));
798 if (!priv(dev)->base) { 797 if (!priv(dev)->base) {
799 ret = -ENOMEM; 798 ret = -ENOMEM;
800 goto free; 799 goto free;
@@ -869,8 +868,6 @@ ether3_probe(struct expansion_card *ec, const struct ecard_id *id)
869 return 0; 868 return 0;
870 869
871 free: 870 free:
872 if (priv(dev)->base)
873 iounmap(priv(dev)->base);
874 free_netdev(dev); 871 free_netdev(dev);
875 release: 872 release:
876 ecard_release_resources(ec); 873 ecard_release_resources(ec);
@@ -885,7 +882,6 @@ static void __devexit ether3_remove(struct expansion_card *ec)
885 ecard_set_drvdata(ec, NULL); 882 ecard_set_drvdata(ec, NULL);
886 883
887 unregister_netdev(dev); 884 unregister_netdev(dev);
888 iounmap(priv(dev)->base);
889 free_netdev(dev); 885 free_netdev(dev);
890 ecard_release_resources(ec); 886 ecard_release_resources(ec);
891} 887}
diff --git a/drivers/net/arm/etherh.c b/drivers/net/arm/etherh.c
index 61f574aa3a99..769ba69451f4 100644
--- a/drivers/net/arm/etherh.c
+++ b/drivers/net/arm/etherh.c
@@ -686,7 +686,7 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
686 eh->supported = data->supported; 686 eh->supported = data->supported;
687 eh->ctrl = 0; 687 eh->ctrl = 0;
688 eh->id = ec->cid.product; 688 eh->id = ec->cid.product;
689 eh->memc = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC), PAGE_SIZE); 689 eh->memc = ecardm_iomap(ec, ECARD_RES_MEMC, 0, PAGE_SIZE);
690 if (!eh->memc) { 690 if (!eh->memc) {
691 ret = -ENOMEM; 691 ret = -ENOMEM;
692 goto free; 692 goto free;
@@ -694,7 +694,7 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
694 694
695 eh->ctrl_port = eh->memc; 695 eh->ctrl_port = eh->memc;
696 if (data->ctrl_ioc) { 696 if (data->ctrl_ioc) {
697 eh->ioc_fast = ioremap(ecard_resource_start(ec, ECARD_RES_IOCFAST), PAGE_SIZE); 697 eh->ioc_fast = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, PAGE_SIZE);
698 if (!eh->ioc_fast) { 698 if (!eh->ioc_fast) {
699 ret = -ENOMEM; 699 ret = -ENOMEM;
700 goto free; 700 goto free;
@@ -710,8 +710,7 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
710 * IRQ and control port handling - only for non-NIC slot cards. 710 * IRQ and control port handling - only for non-NIC slot cards.
711 */ 711 */
712 if (ec->slot_no != 8) { 712 if (ec->slot_no != 8) {
713 ec->ops = &etherh_ops; 713 ecard_setirq(ec, &etherh_ops, eh);
714 ec->irq_data = eh;
715 } else { 714 } else {
716 /* 715 /*
717 * If we're in the NIC slot, make sure the IRQ is enabled 716 * If we're in the NIC slot, make sure the IRQ is enabled
@@ -759,10 +758,6 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
759 return 0; 758 return 0;
760 759
761 free: 760 free:
762 if (eh->ioc_fast)
763 iounmap(eh->ioc_fast);
764 if (eh->memc)
765 iounmap(eh->memc);
766 free_netdev(dev); 761 free_netdev(dev);
767 release: 762 release:
768 ecard_release_resources(ec); 763 ecard_release_resources(ec);
@@ -773,16 +768,10 @@ etherh_probe(struct expansion_card *ec, const struct ecard_id *id)
773static void __devexit etherh_remove(struct expansion_card *ec) 768static void __devexit etherh_remove(struct expansion_card *ec)
774{ 769{
775 struct net_device *dev = ecard_get_drvdata(ec); 770 struct net_device *dev = ecard_get_drvdata(ec);
776 struct etherh_priv *eh = etherh_priv(dev);
777 771
778 ecard_set_drvdata(ec, NULL); 772 ecard_set_drvdata(ec, NULL);
779 773
780 unregister_netdev(dev); 774 unregister_netdev(dev);
781 ec->ops = NULL;
782
783 if (eh->ioc_fast)
784 iounmap(eh->ioc_fast);
785 iounmap(eh->memc);
786 775
787 free_netdev(dev); 776 free_netdev(dev);
788 777
diff --git a/drivers/net/atl1/atl1_ethtool.c b/drivers/net/atl1/atl1_ethtool.c
index c11c27798e5c..1f616c5c1473 100644
--- a/drivers/net/atl1/atl1_ethtool.c
+++ b/drivers/net/atl1/atl1_ethtool.c
@@ -156,8 +156,7 @@ static int atl1_set_settings(struct net_device *netdev,
156 u16 old_media_type = hw->media_type; 156 u16 old_media_type = hw->media_type;
157 157
158 if (netif_running(adapter->netdev)) { 158 if (netif_running(adapter->netdev)) {
159 printk(KERN_DEBUG "%s: ethtool shutting down adapter\n", 159 dev_dbg(&adapter->pdev->dev, "ethtool shutting down adapter\n");
160 atl1_driver_name);
161 atl1_down(adapter); 160 atl1_down(adapter);
162 } 161 }
163 162
@@ -166,9 +165,8 @@ static int atl1_set_settings(struct net_device *netdev,
166 else { 165 else {
167 if (ecmd->speed == SPEED_1000) { 166 if (ecmd->speed == SPEED_1000) {
168 if (ecmd->duplex != DUPLEX_FULL) { 167 if (ecmd->duplex != DUPLEX_FULL) {
169 printk(KERN_WARNING 168 dev_warn(&adapter->pdev->dev,
170 "%s: can't force to 1000M half duplex\n", 169 "can't force to 1000M half duplex\n");
171 atl1_driver_name);
172 ret_val = -EINVAL; 170 ret_val = -EINVAL;
173 goto exit_sset; 171 goto exit_sset;
174 } 172 }
@@ -206,9 +204,8 @@ static int atl1_set_settings(struct net_device *netdev,
206 } 204 }
207 if (atl1_phy_setup_autoneg_adv(hw)) { 205 if (atl1_phy_setup_autoneg_adv(hw)) {
208 ret_val = -EINVAL; 206 ret_val = -EINVAL;
209 printk(KERN_WARNING 207 dev_warn(&adapter->pdev->dev,
210 "%s: invalid ethtool speed/duplex setting\n", 208 "invalid ethtool speed/duplex setting\n");
211 atl1_driver_name);
212 goto exit_sset; 209 goto exit_sset;
213 } 210 }
214 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR || 211 if (hw->media_type == MEDIA_TYPE_AUTO_SENSOR ||
@@ -239,12 +236,10 @@ exit_sset:
239 hw->media_type = old_media_type; 236 hw->media_type = old_media_type;
240 237
241 if (netif_running(adapter->netdev)) { 238 if (netif_running(adapter->netdev)) {
242 printk(KERN_DEBUG "%s: ethtool starting adapter\n", 239 dev_dbg(&adapter->pdev->dev, "ethtool starting adapter\n");
243 atl1_driver_name);
244 atl1_up(adapter); 240 atl1_up(adapter);
245 } else if (!ret_val) { 241 } else if (!ret_val) {
246 printk(KERN_DEBUG "%s: ethtool resetting adapter\n", 242 dev_dbg(&adapter->pdev->dev, "ethtool resetting adapter\n");
247 atl1_driver_name);
248 atl1_reset(adapter); 243 atl1_reset(adapter);
249 } 244 }
250 return ret_val; 245 return ret_val;
diff --git a/drivers/net/atl1/atl1_hw.c b/drivers/net/atl1/atl1_hw.c
index 69482e0d849b..ef886bdeac13 100644
--- a/drivers/net/atl1/atl1_hw.c
+++ b/drivers/net/atl1/atl1_hw.c
@@ -2,20 +2,20 @@
2 * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved. 2 * Copyright(c) 2005 - 2006 Attansic Corporation. All rights reserved.
3 * Copyright(c) 2006 Chris Snook <csnook@redhat.com> 3 * Copyright(c) 2006 Chris Snook <csnook@redhat.com>
4 * Copyright(c) 2006 Jay Cliburn <jcliburn@gmail.com> 4 * Copyright(c) 2006 Jay Cliburn <jcliburn@gmail.com>
5 * 5 *
6 * Derived from Intel e1000 driver 6 * Derived from Intel e1000 driver
7 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved. 7 * Copyright(c) 1999 - 2005 Intel Corporation. All rights reserved.
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify it 9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free 10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option) 11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version. 12 * any later version.
13 * 13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT 14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details. 17 * more details.
18 * 18 *
19 * You should have received a copy of the GNU General Public License along with 19 * You should have received a copy of the GNU General Public License along with
20 * this program; if not, write to the Free Software Foundation, Inc., 59 20 * this program; if not, write to the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
@@ -38,12 +38,13 @@
38 */ 38 */
39s32 atl1_reset_hw(struct atl1_hw *hw) 39s32 atl1_reset_hw(struct atl1_hw *hw)
40{ 40{
41 struct pci_dev *pdev = hw->back->pdev;
41 u32 icr; 42 u32 icr;
42 int i; 43 int i;
43 44
44 /* 45 /*
45 * Clear Interrupt mask to stop board from generating 46 * Clear Interrupt mask to stop board from generating
46 * interrupts & Clear any pending interrupt events 47 * interrupts & Clear any pending interrupt events
47 */ 48 */
48 /* 49 /*
49 * iowrite32(0, hw->hw_addr + REG_IMR); 50 * iowrite32(0, hw->hw_addr + REG_IMR);
@@ -74,7 +75,7 @@ s32 atl1_reset_hw(struct atl1_hw *hw)
74 } 75 }
75 76
76 if (icr) { 77 if (icr) {
77 printk (KERN_DEBUG "icr = %x\n", icr); 78 dev_dbg(&pdev->dev, "ICR = 0x%x\n", icr);
78 return icr; 79 return icr;
79 } 80 }
80 81
@@ -136,8 +137,8 @@ s32 atl1_read_phy_reg(struct atl1_hw *hw, u16 reg_addr, u16 *phy_data)
136 int i; 137 int i;
137 138
138 val = ((u32) (reg_addr & MDIO_REG_ADDR_MASK)) << MDIO_REG_ADDR_SHIFT | 139 val = ((u32) (reg_addr & MDIO_REG_ADDR_MASK)) << MDIO_REG_ADDR_SHIFT |
139 MDIO_START | MDIO_SUP_PREAMBLE | MDIO_RW | MDIO_CLK_25_4 << 140 MDIO_START | MDIO_SUP_PREAMBLE | MDIO_RW | MDIO_CLK_25_4 <<
140 MDIO_CLK_SEL_SHIFT; 141 MDIO_CLK_SEL_SHIFT;
141 iowrite32(val, hw->hw_addr + REG_MDIO_CTRL); 142 iowrite32(val, hw->hw_addr + REG_MDIO_CTRL);
142 ioread32(hw->hw_addr + REG_MDIO_CTRL); 143 ioread32(hw->hw_addr + REG_MDIO_CTRL);
143 144
@@ -204,7 +205,7 @@ static bool atl1_spi_read(struct atl1_hw *hw, u32 addr, u32 *buf)
204 205
205/* 206/*
206 * get_permanent_address 207 * get_permanent_address
207 * return 0 if get valid mac address, 208 * return 0 if get valid mac address,
208 */ 209 */
209static int atl1_get_permanent_address(struct atl1_hw *hw) 210static int atl1_get_permanent_address(struct atl1_hw *hw)
210{ 211{
@@ -301,7 +302,7 @@ static int atl1_get_permanent_address(struct atl1_hw *hw)
301} 302}
302 303
303/* 304/*
304 * Reads the adapter's MAC address from the EEPROM 305 * Reads the adapter's MAC address from the EEPROM
305 * hw - Struct containing variables accessed by shared code 306 * hw - Struct containing variables accessed by shared code
306 */ 307 */
307s32 atl1_read_mac_addr(struct atl1_hw *hw) 308s32 atl1_read_mac_addr(struct atl1_hw *hw)
@@ -437,6 +438,7 @@ s32 atl1_phy_enter_power_saving(struct atl1_hw *hw)
437 */ 438 */
438static s32 atl1_phy_reset(struct atl1_hw *hw) 439static s32 atl1_phy_reset(struct atl1_hw *hw)
439{ 440{
441 struct pci_dev *pdev = hw->back->pdev;
440 s32 ret_val; 442 s32 ret_val;
441 u16 phy_data; 443 u16 phy_data;
442 444
@@ -468,8 +470,7 @@ static s32 atl1_phy_reset(struct atl1_hw *hw)
468 u32 val; 470 u32 val;
469 int i; 471 int i;
470 /* pcie serdes link may be down! */ 472 /* pcie serdes link may be down! */
471 printk(KERN_DEBUG "%s: autoneg caused pcie phy link down\n", 473 dev_dbg(&pdev->dev, "pcie phy link down\n");
472 atl1_driver_name);
473 474
474 for (i = 0; i < 25; i++) { 475 for (i = 0; i < 25; i++) {
475 msleep(1); 476 msleep(1);
@@ -479,9 +480,7 @@ static s32 atl1_phy_reset(struct atl1_hw *hw)
479 } 480 }
480 481
481 if ((val & (MDIO_START | MDIO_BUSY)) != 0) { 482 if ((val & (MDIO_START | MDIO_BUSY)) != 0) {
482 printk(KERN_WARNING 483 dev_warn(&pdev->dev, "pcie link down at least 25ms\n");
483 "%s: pcie link down at least for 25ms\n",
484 atl1_driver_name);
485 return ret_val; 484 return ret_val;
486 } 485 }
487 } 486 }
@@ -571,6 +570,7 @@ s32 atl1_phy_setup_autoneg_adv(struct atl1_hw *hw)
571 */ 570 */
572static s32 atl1_setup_link(struct atl1_hw *hw) 571static s32 atl1_setup_link(struct atl1_hw *hw)
573{ 572{
573 struct pci_dev *pdev = hw->back->pdev;
574 s32 ret_val; 574 s32 ret_val;
575 575
576 /* 576 /*
@@ -581,15 +581,13 @@ static s32 atl1_setup_link(struct atl1_hw *hw)
581 */ 581 */
582 ret_val = atl1_phy_setup_autoneg_adv(hw); 582 ret_val = atl1_phy_setup_autoneg_adv(hw);
583 if (ret_val) { 583 if (ret_val) {
584 printk(KERN_DEBUG "%s: error setting up autonegotiation\n", 584 dev_dbg(&pdev->dev, "error setting up autonegotiation\n");
585 atl1_driver_name);
586 return ret_val; 585 return ret_val;
587 } 586 }
588 /* SW.Reset , En-Auto-Neg if needed */ 587 /* SW.Reset , En-Auto-Neg if needed */
589 ret_val = atl1_phy_reset(hw); 588 ret_val = atl1_phy_reset(hw);
590 if (ret_val) { 589 if (ret_val) {
591 printk(KERN_DEBUG "%s: error resetting the phy\n", 590 dev_dbg(&pdev->dev, "error resetting phy\n");
592 atl1_driver_name);
593 return ret_val; 591 return ret_val;
594 } 592 }
595 hw->phy_configured = true; 593 hw->phy_configured = true;
@@ -631,7 +629,7 @@ static void atl1_init_flash_opcode(struct atl1_hw *hw)
631 * Performs basic configuration of the adapter. 629 * Performs basic configuration of the adapter.
632 * hw - Struct containing variables accessed by shared code 630 * hw - Struct containing variables accessed by shared code
633 * Assumes that the controller has previously been reset and is in a 631 * Assumes that the controller has previously been reset and is in a
634 * post-reset uninitialized state. Initializes multicast table, 632 * post-reset uninitialized state. Initializes multicast table,
635 * and Calls routines to setup link 633 * and Calls routines to setup link
636 * Leaves the transmit and receive units disabled and uninitialized. 634 * Leaves the transmit and receive units disabled and uninitialized.
637 */ 635 */
@@ -669,6 +667,7 @@ s32 atl1_init_hw(struct atl1_hw *hw)
669 */ 667 */
670s32 atl1_get_speed_and_duplex(struct atl1_hw *hw, u16 *speed, u16 *duplex) 668s32 atl1_get_speed_and_duplex(struct atl1_hw *hw, u16 *speed, u16 *duplex)
671{ 669{
670 struct pci_dev *pdev = hw->back->pdev;
672 s32 ret_val; 671 s32 ret_val;
673 u16 phy_data; 672 u16 phy_data;
674 673
@@ -691,8 +690,7 @@ s32 atl1_get_speed_and_duplex(struct atl1_hw *hw, u16 *speed, u16 *duplex)
691 *speed = SPEED_10; 690 *speed = SPEED_10;
692 break; 691 break;
693 default: 692 default:
694 printk(KERN_DEBUG "%s: error getting speed\n", 693 dev_dbg(&pdev->dev, "error getting speed\n");
695 atl1_driver_name);
696 return ATL1_ERR_PHY_SPEED; 694 return ATL1_ERR_PHY_SPEED;
697 break; 695 break;
698 } 696 }
diff --git a/drivers/net/atl1/atl1_main.c b/drivers/net/atl1/atl1_main.c
index 4b1d4d153ecf..78cf00ff3d38 100644
--- a/drivers/net/atl1/atl1_main.c
+++ b/drivers/net/atl1/atl1_main.c
@@ -188,8 +188,7 @@ s32 atl1_setup_ring_resources(struct atl1_adapter *adapter)
188 size = sizeof(struct atl1_buffer) * (tpd_ring->count + rfd_ring->count); 188 size = sizeof(struct atl1_buffer) * (tpd_ring->count + rfd_ring->count);
189 tpd_ring->buffer_info = kzalloc(size, GFP_KERNEL); 189 tpd_ring->buffer_info = kzalloc(size, GFP_KERNEL);
190 if (unlikely(!tpd_ring->buffer_info)) { 190 if (unlikely(!tpd_ring->buffer_info)) {
191 printk(KERN_WARNING "%s: kzalloc failed , size = D%d\n", 191 dev_err(&pdev->dev, "kzalloc failed , size = D%d\n", size);
192 atl1_driver_name, size);
193 goto err_nomem; 192 goto err_nomem;
194 } 193 }
195 rfd_ring->buffer_info = 194 rfd_ring->buffer_info =
@@ -207,9 +206,7 @@ s32 atl1_setup_ring_resources(struct atl1_adapter *adapter)
207 ring_header->desc = pci_alloc_consistent(pdev, ring_header->size, 206 ring_header->desc = pci_alloc_consistent(pdev, ring_header->size,
208 &ring_header->dma); 207 &ring_header->dma);
209 if (unlikely(!ring_header->desc)) { 208 if (unlikely(!ring_header->desc)) {
210 printk(KERN_WARNING 209 dev_err(&pdev->dev, "pci_alloc_consistent failed\n");
211 "%s: pci_alloc_consistent failed, size = D%d\n",
212 atl1_driver_name, size);
213 goto err_nomem; 210 goto err_nomem;
214 } 211 }
215 212
@@ -373,8 +370,7 @@ static void atl1_rx_checksum(struct atl1_adapter *adapter,
373 if (rrd->err_flg & (ERR_FLAG_CRC | ERR_FLAG_TRUNC | 370 if (rrd->err_flg & (ERR_FLAG_CRC | ERR_FLAG_TRUNC |
374 ERR_FLAG_CODE | ERR_FLAG_OV)) { 371 ERR_FLAG_CODE | ERR_FLAG_OV)) {
375 adapter->hw_csum_err++; 372 adapter->hw_csum_err++;
376 printk(KERN_DEBUG "%s: rx checksum error\n", 373 dev_dbg(&adapter->pdev->dev, "rx checksum error\n");
377 atl1_driver_name);
378 return; 374 return;
379 } 375 }
380 } 376 }
@@ -393,8 +389,9 @@ static void atl1_rx_checksum(struct atl1_adapter *adapter,
393 } 389 }
394 390
395 /* IPv4, but hardware thinks its checksum is wrong */ 391 /* IPv4, but hardware thinks its checksum is wrong */
396 printk(KERN_DEBUG "%s: hw csum wrong pkt_flag:%x, err_flag:%x\n", 392 dev_dbg(&adapter->pdev->dev,
397 atl1_driver_name, rrd->pkt_flg, rrd->err_flg); 393 "hw csum wrong, pkt_flag:%x, err_flag:%x\n",
394 rrd->pkt_flg, rrd->err_flg);
398 skb->ip_summed = CHECKSUM_COMPLETE; 395 skb->ip_summed = CHECKSUM_COMPLETE;
399 skb->csum = htons(rrd->xsz.xsum_sz.rx_chksum); 396 skb->csum = htons(rrd->xsz.xsum_sz.rx_chksum);
400 adapter->hw_csum_err++; 397 adapter->hw_csum_err++;
@@ -507,14 +504,13 @@ chk_rrd:
507 /* rrd seems to be bad */ 504 /* rrd seems to be bad */
508 if (unlikely(i-- > 0)) { 505 if (unlikely(i-- > 0)) {
509 /* rrd may not be DMAed completely */ 506 /* rrd may not be DMAed completely */
510 printk(KERN_DEBUG 507 dev_dbg(&adapter->pdev->dev,
511 "%s: RRD may not be DMAed completely\n", 508 "incomplete RRD DMA transfer\n");
512 atl1_driver_name);
513 udelay(1); 509 udelay(1);
514 goto chk_rrd; 510 goto chk_rrd;
515 } 511 }
516 /* bad rrd */ 512 /* bad rrd */
517 printk(KERN_DEBUG "%s: bad RRD\n", atl1_driver_name); 513 dev_dbg(&adapter->pdev->dev, "bad RRD\n");
518 /* see if update RFD index */ 514 /* see if update RFD index */
519 if (rrd->num_buf > 1) { 515 if (rrd->num_buf > 1) {
520 u16 num_buf; 516 u16 num_buf;
@@ -685,8 +681,8 @@ static void atl1_check_for_link(struct atl1_adapter *adapter)
685 /* notify upper layer link down ASAP */ 681 /* notify upper layer link down ASAP */
686 if (!(phy_data & BMSR_LSTATUS)) { /* Link Down */ 682 if (!(phy_data & BMSR_LSTATUS)) { /* Link Down */
687 if (netif_carrier_ok(netdev)) { /* old link state: Up */ 683 if (netif_carrier_ok(netdev)) { /* old link state: Up */
688 printk(KERN_INFO "%s: %s link is down\n", 684 dev_info(&adapter->pdev->dev, "%s link is down\n",
689 atl1_driver_name, netdev->name); 685 netdev->name);
690 adapter->link_speed = SPEED_0; 686 adapter->link_speed = SPEED_0;
691 netif_carrier_off(netdev); 687 netif_carrier_off(netdev);
692 netif_stop_queue(netdev); 688 netif_stop_queue(netdev);
@@ -731,8 +727,8 @@ static irqreturn_t atl1_intr(int irq, void *data)
731 727
732 /* check if PCIE PHY Link down */ 728 /* check if PCIE PHY Link down */
733 if (status & ISR_PHY_LINKDOWN) { 729 if (status & ISR_PHY_LINKDOWN) {
734 printk(KERN_DEBUG "%s: pcie phy link down %x\n", 730 dev_dbg(&adapter->pdev->dev, "pcie phy link down %x\n",
735 atl1_driver_name, status); 731 status);
736 if (netif_running(adapter->netdev)) { /* reset MAC */ 732 if (netif_running(adapter->netdev)) { /* reset MAC */
737 iowrite32(0, adapter->hw.hw_addr + REG_IMR); 733 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
738 schedule_work(&adapter->pcie_dma_to_rst_task); 734 schedule_work(&adapter->pcie_dma_to_rst_task);
@@ -742,9 +738,9 @@ static irqreturn_t atl1_intr(int irq, void *data)
742 738
743 /* check if DMA read/write error ? */ 739 /* check if DMA read/write error ? */
744 if (status & (ISR_DMAR_TO_RST | ISR_DMAW_TO_RST)) { 740 if (status & (ISR_DMAR_TO_RST | ISR_DMAW_TO_RST)) {
745 printk(KERN_DEBUG 741 dev_dbg(&adapter->pdev->dev,
746 "%s: pcie DMA r/w error (status = 0x%x)\n", 742 "pcie DMA r/w error (status = 0x%x)\n",
747 atl1_driver_name, status); 743 status);
748 iowrite32(0, adapter->hw.hw_addr + REG_IMR); 744 iowrite32(0, adapter->hw.hw_addr + REG_IMR);
749 schedule_work(&adapter->pcie_dma_to_rst_task); 745 schedule_work(&adapter->pcie_dma_to_rst_task);
750 return IRQ_HANDLED; 746 return IRQ_HANDLED;
@@ -762,14 +758,13 @@ static irqreturn_t atl1_intr(int irq, void *data)
762 758
763 /* rx exception */ 759 /* rx exception */
764 if (unlikely(status & (ISR_RXF_OV | ISR_RFD_UNRUN | 760 if (unlikely(status & (ISR_RXF_OV | ISR_RFD_UNRUN |
761 ISR_RRD_OV | ISR_HOST_RFD_UNRUN |
762 ISR_HOST_RRD_OV | ISR_CMB_RX))) {
763 if (status & (ISR_RXF_OV | ISR_RFD_UNRUN |
765 ISR_RRD_OV | ISR_HOST_RFD_UNRUN | 764 ISR_RRD_OV | ISR_HOST_RFD_UNRUN |
766 ISR_HOST_RRD_OV | ISR_CMB_RX))) { 765 ISR_HOST_RRD_OV))
767 if (status & 766 dev_dbg(&adapter->pdev->dev,
768 (ISR_RXF_OV | ISR_RFD_UNRUN | ISR_RRD_OV | 767 "rx exception, ISR = 0x%x\n", status);
769 ISR_HOST_RFD_UNRUN | ISR_HOST_RRD_OV))
770 printk(KERN_INFO
771 "%s: rx exception: status = 0x%x\n",
772 atl1_driver_name, status);
773 atl1_intr_rx(adapter); 768 atl1_intr_rx(adapter);
774 } 769 }
775 770
@@ -874,8 +869,7 @@ static u32 atl1_check_link(struct atl1_adapter *adapter)
874 atl1_read_phy_reg(hw, MII_BMSR, &phy_data); 869 atl1_read_phy_reg(hw, MII_BMSR, &phy_data);
875 if (!(phy_data & BMSR_LSTATUS)) { /* link down */ 870 if (!(phy_data & BMSR_LSTATUS)) { /* link down */
876 if (netif_carrier_ok(netdev)) { /* old link state: Up */ 871 if (netif_carrier_ok(netdev)) { /* old link state: Up */
877 printk(KERN_INFO "%s: link is down\n", 872 dev_info(&adapter->pdev->dev, "link is down\n");
878 atl1_driver_name);
879 adapter->link_speed = SPEED_0; 873 adapter->link_speed = SPEED_0;
880 netif_carrier_off(netdev); 874 netif_carrier_off(netdev);
881 netif_stop_queue(netdev); 875 netif_stop_queue(netdev);
@@ -918,11 +912,11 @@ static u32 atl1_check_link(struct atl1_adapter *adapter)
918 adapter->link_speed = speed; 912 adapter->link_speed = speed;
919 adapter->link_duplex = duplex; 913 adapter->link_duplex = duplex;
920 atl1_setup_mac_ctrl(adapter); 914 atl1_setup_mac_ctrl(adapter);
921 printk(KERN_INFO "%s: %s link is up %d Mbps %s\n", 915 dev_info(&adapter->pdev->dev,
922 atl1_driver_name, netdev->name, 916 "%s link is up %d Mbps %s\n",
923 adapter->link_speed, 917 netdev->name, adapter->link_speed,
924 adapter->link_duplex == 918 adapter->link_duplex == FULL_DUPLEX ?
925 FULL_DUPLEX ? "full duplex" : "half duplex"); 919 "full duplex" : "half duplex");
926 } 920 }
927 if (!netif_carrier_ok(netdev)) { /* Link down -> Up */ 921 if (!netif_carrier_ok(netdev)) { /* Link down -> Up */
928 netif_carrier_on(netdev); 922 netif_carrier_on(netdev);
@@ -1330,8 +1324,8 @@ static int atl1_tx_csum(struct atl1_adapter *adapter, struct sk_buff *skb,
1330 cso = skb_transport_offset(skb); 1324 cso = skb_transport_offset(skb);
1331 css = cso + skb->csum_offset; 1325 css = cso + skb->csum_offset;
1332 if (unlikely(cso & 0x1)) { 1326 if (unlikely(cso & 0x1)) {
1333 printk(KERN_DEBUG "%s: payload offset != even number\n", 1327 dev_dbg(&adapter->pdev->dev,
1334 atl1_driver_name); 1328 "payload offset not an even number\n");
1335 return -1; 1329 return -1;
1336 } 1330 }
1337 csum->csumpl |= (cso & CSUM_PARAM_PLOADOFFSET_MASK) << 1331 csum->csumpl |= (cso & CSUM_PARAM_PLOADOFFSET_MASK) <<
@@ -1579,7 +1573,7 @@ static int atl1_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1579 if (!spin_trylock(&adapter->lock)) { 1573 if (!spin_trylock(&adapter->lock)) {
1580 /* Can't get lock - tell upper layer to requeue */ 1574 /* Can't get lock - tell upper layer to requeue */
1581 local_irq_restore(flags); 1575 local_irq_restore(flags);
1582 printk(KERN_DEBUG "%s: TX locked\n", atl1_driver_name); 1576 dev_dbg(&adapter->pdev->dev, "tx locked\n");
1583 return NETDEV_TX_LOCKED; 1577 return NETDEV_TX_LOCKED;
1584 } 1578 }
1585 1579
@@ -1587,7 +1581,7 @@ static int atl1_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1587 /* not enough descriptors */ 1581 /* not enough descriptors */
1588 netif_stop_queue(netdev); 1582 netif_stop_queue(netdev);
1589 spin_unlock_irqrestore(&adapter->lock, flags); 1583 spin_unlock_irqrestore(&adapter->lock, flags);
1590 printk(KERN_DEBUG "%s: TX busy\n", atl1_driver_name); 1584 dev_dbg(&adapter->pdev->dev, "tx busy\n");
1591 return NETDEV_TX_BUSY; 1585 return NETDEV_TX_BUSY;
1592 } 1586 }
1593 1587
@@ -1841,8 +1835,7 @@ static int atl1_change_mtu(struct net_device *netdev, int new_mtu)
1841 1835
1842 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) || 1836 if ((max_frame < MINIMUM_ETHERNET_FRAME_SIZE) ||
1843 (max_frame > MAX_JUMBO_FRAME_SIZE)) { 1837 (max_frame > MAX_JUMBO_FRAME_SIZE)) {
1844 printk(KERN_WARNING "%s: invalid MTU setting\n", 1838 dev_warn(&adapter->pdev->dev, "invalid MTU setting\n");
1845 atl1_driver_name);
1846 return -EINVAL; 1839 return -EINVAL;
1847 } 1840 }
1848 1841
@@ -2045,6 +2038,15 @@ static int atl1_close(struct net_device *netdev)
2045 return 0; 2038 return 0;
2046} 2039}
2047 2040
2041#ifdef CONFIG_NET_POLL_CONTROLLER
2042static void atl1_poll_controller(struct net_device *netdev)
2043{
2044 disable_irq(netdev->irq);
2045 atl1_intr(netdev->irq, netdev);
2046 enable_irq(netdev->irq);
2047}
2048#endif
2049
2048/* 2050/*
2049 * If TPD Buffer size equal to 0, PCIE DMAR_TO_INT 2051 * If TPD Buffer size equal to 0, PCIE DMAR_TO_INT
2050 * will assert. We do soft reset <0x1400=1> according 2052 * will assert. We do soft reset <0x1400=1> according
@@ -2136,9 +2138,7 @@ static int __devinit atl1_probe(struct pci_dev *pdev,
2136 if (err) { 2138 if (err) {
2137 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 2139 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
2138 if (err) { 2140 if (err) {
2139 printk(KERN_DEBUG 2141 dev_err(&pdev->dev, "no usable DMA configuration\n");
2140 "%s: no usable DMA configuration, aborting\n",
2141 atl1_driver_name);
2142 goto err_dma; 2142 goto err_dma;
2143 } 2143 }
2144 pci_using_64 = false; 2144 pci_using_64 = false;
@@ -2175,7 +2175,9 @@ static int __devinit atl1_probe(struct pci_dev *pdev,
2175 goto err_pci_iomap; 2175 goto err_pci_iomap;
2176 } 2176 }
2177 /* get device revision number */ 2177 /* get device revision number */
2178 adapter->hw.dev_rev = ioread16(adapter->hw.hw_addr + (REG_MASTER_CTRL + 2)); 2178 adapter->hw.dev_rev = ioread16(adapter->hw.hw_addr +
2179 (REG_MASTER_CTRL + 2));
2180 dev_info(&pdev->dev, "version %s\n", DRIVER_VERSION);
2179 2181
2180 /* set default ring resource counts */ 2182 /* set default ring resource counts */
2181 adapter->rfd_ring.count = adapter->rrd_ring.count = ATL1_DEFAULT_RFD; 2183 adapter->rfd_ring.count = adapter->rrd_ring.count = ATL1_DEFAULT_RFD;
@@ -2197,6 +2199,9 @@ static int __devinit atl1_probe(struct pci_dev *pdev,
2197 netdev->do_ioctl = &atl1_ioctl; 2199 netdev->do_ioctl = &atl1_ioctl;
2198 netdev->tx_timeout = &atl1_tx_timeout; 2200 netdev->tx_timeout = &atl1_tx_timeout;
2199 netdev->watchdog_timeo = 5 * HZ; 2201 netdev->watchdog_timeo = 5 * HZ;
2202#ifdef CONFIG_NET_POLL_CONTROLLER
2203 netdev->poll_controller = atl1_poll_controller;
2204#endif
2200 netdev->vlan_rx_register = atl1_vlan_rx_register; 2205 netdev->vlan_rx_register = atl1_vlan_rx_register;
2201 netdev->vlan_rx_add_vid = atl1_vlan_rx_add_vid; 2206 netdev->vlan_rx_add_vid = atl1_vlan_rx_add_vid;
2202 netdev->vlan_rx_kill_vid = atl1_vlan_rx_kill_vid; 2207 netdev->vlan_rx_kill_vid = atl1_vlan_rx_kill_vid;
@@ -2466,8 +2471,6 @@ static void __exit atl1_exit_module(void)
2466 */ 2471 */
2467static int __init atl1_init_module(void) 2472static int __init atl1_init_module(void)
2468{ 2473{
2469 printk(KERN_INFO "%s - version %s\n", atl1_driver_string, DRIVER_VERSION);
2470 printk(KERN_INFO "%s\n", atl1_copyright);
2471 return pci_register_driver(&atl1_driver); 2474 return pci_register_driver(&atl1_driver);
2472} 2475}
2473 2476
diff --git a/drivers/net/atl1/atl1_param.c b/drivers/net/atl1/atl1_param.c
index bcd0bd891722..4246bb9bd50e 100644
--- a/drivers/net/atl1/atl1_param.c
+++ b/drivers/net/atl1/atl1_param.c
@@ -23,6 +23,7 @@
23 23
24#include <linux/types.h> 24#include <linux/types.h>
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/pci.h>
26#include "atl1.h" 27#include "atl1.h"
27 28
28/* 29/*
@@ -93,7 +94,7 @@ struct atl1_option {
93 } arg; 94 } arg;
94}; 95};
95 96
96static int __devinit atl1_validate_option(int *value, struct atl1_option *opt) 97static int __devinit atl1_validate_option(int *value, struct atl1_option *opt, struct pci_dev *pdev)
97{ 98{
98 if (*value == OPTION_UNSET) { 99 if (*value == OPTION_UNSET) {
99 *value = opt->def; 100 *value = opt->def;
@@ -104,19 +105,17 @@ static int __devinit atl1_validate_option(int *value, struct atl1_option *opt)
104 case enable_option: 105 case enable_option:
105 switch (*value) { 106 switch (*value) {
106 case OPTION_ENABLED: 107 case OPTION_ENABLED:
107 printk(KERN_INFO "%s: %s Enabled\n", atl1_driver_name, 108 dev_info(&pdev->dev, "%s enabled\n", opt->name);
108 opt->name);
109 return 0; 109 return 0;
110 case OPTION_DISABLED: 110 case OPTION_DISABLED:
111 printk(KERN_INFO "%s: %s Disabled\n", atl1_driver_name, 111 dev_info(&pdev->dev, "%s disabled\n", opt->name);
112 opt->name);
113 return 0; 112 return 0;
114 } 113 }
115 break; 114 break;
116 case range_option: 115 case range_option:
117 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) { 116 if (*value >= opt->arg.r.min && *value <= opt->arg.r.max) {
118 printk(KERN_INFO "%s: %s set to %i\n", 117 dev_info(&pdev->dev, "%s set to %i\n", opt->name,
119 atl1_driver_name, opt->name, *value); 118 *value);
120 return 0; 119 return 0;
121 } 120 }
122 break; 121 break;
@@ -128,8 +127,8 @@ static int __devinit atl1_validate_option(int *value, struct atl1_option *opt)
128 ent = &opt->arg.l.p[i]; 127 ent = &opt->arg.l.p[i];
129 if (*value == ent->i) { 128 if (*value == ent->i) {
130 if (ent->str[0] != '\0') 129 if (ent->str[0] != '\0')
131 printk(KERN_INFO "%s: %s\n", 130 dev_info(&pdev->dev, "%s\n",
132 atl1_driver_name, ent->str); 131 ent->str);
133 return 0; 132 return 0;
134 } 133 }
135 } 134 }
@@ -140,8 +139,8 @@ static int __devinit atl1_validate_option(int *value, struct atl1_option *opt)
140 break; 139 break;
141 } 140 }
142 141
143 printk(KERN_INFO "%s: invalid %s specified (%i) %s\n", 142 dev_info(&pdev->dev, "invalid %s specified (%i) %s\n",
144 atl1_driver_name, opt->name, *value, opt->err); 143 opt->name, *value, opt->err);
145 *value = opt->def; 144 *value = opt->def;
146 return -1; 145 return -1;
147} 146}
@@ -157,12 +156,11 @@ static int __devinit atl1_validate_option(int *value, struct atl1_option *opt)
157 */ 156 */
158void __devinit atl1_check_options(struct atl1_adapter *adapter) 157void __devinit atl1_check_options(struct atl1_adapter *adapter)
159{ 158{
159 struct pci_dev *pdev = adapter->pdev;
160 int bd = adapter->bd_number; 160 int bd = adapter->bd_number;
161 if (bd >= ATL1_MAX_NIC) { 161 if (bd >= ATL1_MAX_NIC) {
162 printk(KERN_NOTICE "%s: warning: no configuration for board #%i\n", 162 dev_notice(&pdev->dev, "no configuration for board#%i\n", bd);
163 atl1_driver_name, bd); 163 dev_notice(&pdev->dev, "using defaults for all values\n");
164 printk(KERN_NOTICE "%s: using defaults for all values\n",
165 atl1_driver_name);
166 } 164 }
167 { /* Interrupt Moderate Timer */ 165 { /* Interrupt Moderate Timer */
168 struct atl1_option opt = { 166 struct atl1_option opt = {
@@ -177,7 +175,7 @@ void __devinit atl1_check_options(struct atl1_adapter *adapter)
177 int val; 175 int val;
178 if (num_int_mod_timer > bd) { 176 if (num_int_mod_timer > bd) {
179 val = int_mod_timer[bd]; 177 val = int_mod_timer[bd];
180 atl1_validate_option(&val, &opt); 178 atl1_validate_option(&val, &opt, pdev);
181 adapter->imt = (u16) val; 179 adapter->imt = (u16) val;
182 } else 180 } else
183 adapter->imt = (u16) (opt.def); 181 adapter->imt = (u16) (opt.def);
@@ -197,7 +195,7 @@ void __devinit atl1_check_options(struct atl1_adapter *adapter)
197 int val; 195 int val;
198 if (num_flash_vendor > bd) { 196 if (num_flash_vendor > bd) {
199 val = flash_vendor[bd]; 197 val = flash_vendor[bd];
200 atl1_validate_option(&val, &opt); 198 atl1_validate_option(&val, &opt, pdev);
201 adapter->hw.flash_vendor = (u8) val; 199 adapter->hw.flash_vendor = (u8) val;
202 } else 200 } else
203 adapter->hw.flash_vendor = (u8) (opt.def); 201 adapter->hw.flash_vendor = (u8) (opt.def);
diff --git a/drivers/net/atp.c b/drivers/net/atp.c
index 18aba838c1ff..82d78ff8399b 100644
--- a/drivers/net/atp.c
+++ b/drivers/net/atp.c
@@ -31,10 +31,8 @@
31 31
32*/ 32*/
33 33
34static const char versionA[] = 34static const char version[] =
35"atp.c:v1.09=ac 2002/10/01 Donald Becker <becker@scyld.com>\n"; 35"atp.c:v1.09=ac 2002/10/01 Donald Becker <becker@scyld.com>\n";
36static const char versionB[] =
37" http://www.scyld.com/network/atp.html\n";
38 36
39/* The user-configurable values. 37/* The user-configurable values.
40 These may be modified when a driver module is loaded.*/ 38 These may be modified when a driver module is loaded.*/
@@ -324,7 +322,7 @@ static int __init atp_probe1(long ioaddr)
324 322
325#ifndef MODULE 323#ifndef MODULE
326 if (net_debug) 324 if (net_debug)
327 printk(KERN_INFO "%s" KERN_INFO "%s", versionA, versionB); 325 printk(KERN_INFO "%s", version);
328#endif 326#endif
329 327
330 printk(KERN_NOTICE "%s: Pocket adapter found at %#3lx, IRQ %d, SAPROM " 328 printk(KERN_NOTICE "%s: Pocket adapter found at %#3lx, IRQ %d, SAPROM "
@@ -926,7 +924,7 @@ static void set_rx_mode_8012(struct net_device *dev)
926 924
927static int __init atp_init_module(void) { 925static int __init atp_init_module(void) {
928 if (debug) /* Emit version even if no cards detected. */ 926 if (debug) /* Emit version even if no cards detected. */
929 printk(KERN_INFO "%s" KERN_INFO "%s", versionA, versionB); 927 printk(KERN_INFO "%s", version);
930 return atp_init(); 928 return atp_init();
931} 929}
932 930
diff --git a/drivers/net/bmac.c b/drivers/net/bmac.c
index 4612725965df..9b8d7d9dbe86 100644
--- a/drivers/net/bmac.c
+++ b/drivers/net/bmac.c
@@ -1260,9 +1260,10 @@ static int __devinit bmac_probe(struct macio_dev *mdev, const struct of_device_i
1260 printk(KERN_ERR "BMAC: can't use, need 3 addrs and 3 intrs\n"); 1260 printk(KERN_ERR "BMAC: can't use, need 3 addrs and 3 intrs\n");
1261 return -ENODEV; 1261 return -ENODEV;
1262 } 1262 }
1263 prop_addr = get_property(macio_get_of_node(mdev), "mac-address", NULL); 1263 prop_addr = of_get_property(macio_get_of_node(mdev),
1264 "mac-address", NULL);
1264 if (prop_addr == NULL) { 1265 if (prop_addr == NULL) {
1265 prop_addr = get_property(macio_get_of_node(mdev), 1266 prop_addr = of_get_property(macio_get_of_node(mdev),
1266 "local-mac-address", NULL); 1267 "local-mac-address", NULL);
1267 if (prop_addr == NULL) { 1268 if (prop_addr == NULL) {
1268 printk(KERN_ERR "BMAC: Can't get mac-address\n"); 1269 printk(KERN_ERR "BMAC: Can't get mac-address\n");
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 724bce51f936..223517dcbcfd 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3461,7 +3461,7 @@ void bond_unregister_arp(struct bonding *bond)
3461/*---------------------------- Hashing Policies -----------------------------*/ 3461/*---------------------------- Hashing Policies -----------------------------*/
3462 3462
3463/* 3463/*
3464 * Hash for the the output device based upon layer 3 and layer 4 data. If 3464 * Hash for the output device based upon layer 3 and layer 4 data. If
3465 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is 3465 * the packet is a frag or not TCP or UDP, just use layer 3 data. If it is
3466 * altogether not IP, mimic bond_xmit_hash_policy_l2() 3466 * altogether not IP, mimic bond_xmit_hash_policy_l2()
3467 */ 3467 */
diff --git a/drivers/net/declance.c b/drivers/net/declance.c
index 95d854e2295c..b2577f40124e 100644
--- a/drivers/net/declance.c
+++ b/drivers/net/declance.c
@@ -932,8 +932,6 @@ static int lance_start_xmit(struct sk_buff *skb, struct net_device *dev)
932 /* Kick the lance: transmit now */ 932 /* Kick the lance: transmit now */
933 writereg(&ll->rdp, LE_C0_INEA | LE_C0_TDMD); 933 writereg(&ll->rdp, LE_C0_INEA | LE_C0_TDMD);
934 934
935 spin_unlock_irq(&lp->lock);
936
937 dev->trans_start = jiffies; 935 dev->trans_start = jiffies;
938 dev_kfree_skb(skb); 936 dev_kfree_skb(skb);
939 937
diff --git a/drivers/net/dm9000.c b/drivers/net/dm9000.c
index 8cc1174e7f64..264fa0e2e075 100644
--- a/drivers/net/dm9000.c
+++ b/drivers/net/dm9000.c
@@ -77,9 +77,6 @@
77 77
78#define DM9000_PHY 0x40 /* PHY address 0x01 */ 78#define DM9000_PHY 0x40 /* PHY address 0x01 */
79 79
80#define TRUE 1
81#define FALSE 0
82
83#define CARDNAME "dm9000" 80#define CARDNAME "dm9000"
84#define PFX CARDNAME ": " 81#define PFX CARDNAME ": "
85 82
@@ -601,7 +598,7 @@ dm9000_probe(struct platform_device *pdev)
601 printk("%s: not found (%d).\n", CARDNAME, ret); 598 printk("%s: not found (%d).\n", CARDNAME, ret);
602 599
603 dm9000_release_board(pdev, db); 600 dm9000_release_board(pdev, db);
604 kfree(ndev); 601 free_netdev(ndev);
605 602
606 return ret; 603 return ret;
607} 604}
@@ -896,7 +893,7 @@ dm9000_rx(struct net_device *dev)
896 struct dm9000_rxhdr rxhdr; 893 struct dm9000_rxhdr rxhdr;
897 struct sk_buff *skb; 894 struct sk_buff *skb;
898 u8 rxbyte, *rdptr; 895 u8 rxbyte, *rdptr;
899 int GoodPacket; 896 bool GoodPacket;
900 int RxLen; 897 int RxLen;
901 898
902 /* Check packet ready or not */ 899 /* Check packet ready or not */
@@ -918,7 +915,7 @@ dm9000_rx(struct net_device *dev)
918 return; 915 return;
919 916
920 /* A packet ready now & Get status/length */ 917 /* A packet ready now & Get status/length */
921 GoodPacket = TRUE; 918 GoodPacket = true;
922 writeb(DM9000_MRCMD, db->io_addr); 919 writeb(DM9000_MRCMD, db->io_addr);
923 920
924 (db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr)); 921 (db->inblk)(db->io_data, &rxhdr, sizeof(rxhdr));
@@ -927,7 +924,7 @@ dm9000_rx(struct net_device *dev)
927 924
928 /* Packet Status check */ 925 /* Packet Status check */
929 if (RxLen < 0x40) { 926 if (RxLen < 0x40) {
930 GoodPacket = FALSE; 927 GoodPacket = false;
931 PRINTK1("Bad Packet received (runt)\n"); 928 PRINTK1("Bad Packet received (runt)\n");
932 } 929 }
933 930
@@ -936,7 +933,7 @@ dm9000_rx(struct net_device *dev)
936 } 933 }
937 934
938 if (rxhdr.RxStatus & 0xbf00) { 935 if (rxhdr.RxStatus & 0xbf00) {
939 GoodPacket = FALSE; 936 GoodPacket = false;
940 if (rxhdr.RxStatus & 0x100) { 937 if (rxhdr.RxStatus & 0x100) {
941 PRINTK1("fifo error\n"); 938 PRINTK1("fifo error\n");
942 db->stats.rx_fifo_errors++; 939 db->stats.rx_fifo_errors++;
@@ -1193,7 +1190,7 @@ dm9000_drv_remove(struct platform_device *pdev)
1193 1190
1194 unregister_netdev(ndev); 1191 unregister_netdev(ndev);
1195 dm9000_release_board(pdev, (board_info_t *) ndev->priv); 1192 dm9000_release_board(pdev, (board_info_t *) ndev->priv);
1196 kfree(ndev); /* free device structure */ 1193 free_netdev(ndev); /* free device structure */
1197 1194
1198 PRINTK1("clean_module() exit\n"); 1195 PRINTK1("clean_module() exit\n");
1199 1196
diff --git a/drivers/net/e1000/e1000.h b/drivers/net/e1000/e1000.h
index a9ea67e75c1b..16a6edfeba41 100644
--- a/drivers/net/e1000/e1000.h
+++ b/drivers/net/e1000/e1000.h
@@ -333,11 +333,9 @@ struct e1000_adapter {
333 struct e1000_tx_ring test_tx_ring; 333 struct e1000_tx_ring test_tx_ring;
334 struct e1000_rx_ring test_rx_ring; 334 struct e1000_rx_ring test_rx_ring;
335 335
336
337 int msg_enable; 336 int msg_enable;
338#ifdef CONFIG_PCI_MSI
339 boolean_t have_msi; 337 boolean_t have_msi;
340#endif 338
341 /* to not mess up cache alignment, always add to the bottom */ 339 /* to not mess up cache alignment, always add to the bottom */
342 boolean_t tso_force; 340 boolean_t tso_force;
343 boolean_t smart_power_down; /* phy smart power down */ 341 boolean_t smart_power_down; /* phy smart power down */
diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
index 3a03a74c0609..cbc7febe9cdc 100644
--- a/drivers/net/e1000/e1000_main.c
+++ b/drivers/net/e1000/e1000_main.c
@@ -158,9 +158,7 @@ static struct net_device_stats * e1000_get_stats(struct net_device *netdev);
158static int e1000_change_mtu(struct net_device *netdev, int new_mtu); 158static int e1000_change_mtu(struct net_device *netdev, int new_mtu);
159static int e1000_set_mac(struct net_device *netdev, void *p); 159static int e1000_set_mac(struct net_device *netdev, void *p);
160static irqreturn_t e1000_intr(int irq, void *data); 160static irqreturn_t e1000_intr(int irq, void *data);
161#ifdef CONFIG_PCI_MSI
162static irqreturn_t e1000_intr_msi(int irq, void *data); 161static irqreturn_t e1000_intr_msi(int irq, void *data);
163#endif
164static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter, 162static boolean_t e1000_clean_tx_irq(struct e1000_adapter *adapter,
165 struct e1000_tx_ring *tx_ring); 163 struct e1000_tx_ring *tx_ring);
166#ifdef CONFIG_E1000_NAPI 164#ifdef CONFIG_E1000_NAPI
@@ -300,31 +298,26 @@ module_exit(e1000_exit_module);
300static int e1000_request_irq(struct e1000_adapter *adapter) 298static int e1000_request_irq(struct e1000_adapter *adapter)
301{ 299{
302 struct net_device *netdev = adapter->netdev; 300 struct net_device *netdev = adapter->netdev;
303 int flags, err = 0; 301 void (*handler) = &e1000_intr;
302 int irq_flags = IRQF_SHARED;
303 int err;
304 304
305 flags = IRQF_SHARED;
306#ifdef CONFIG_PCI_MSI
307 if (adapter->hw.mac_type >= e1000_82571) { 305 if (adapter->hw.mac_type >= e1000_82571) {
308 adapter->have_msi = TRUE; 306 adapter->have_msi = !pci_enable_msi(adapter->pdev);
309 if ((err = pci_enable_msi(adapter->pdev))) { 307 if (adapter->have_msi) {
310 DPRINTK(PROBE, ERR, 308 handler = &e1000_intr_msi;
311 "Unable to allocate MSI interrupt Error: %d\n", err); 309 irq_flags = 0;
312 adapter->have_msi = FALSE;
313 } 310 }
314 } 311 }
315 if (adapter->have_msi) { 312
316 flags &= ~IRQF_SHARED; 313 err = request_irq(adapter->pdev->irq, handler, irq_flags, netdev->name,
317 err = request_irq(adapter->pdev->irq, &e1000_intr_msi, flags, 314 netdev);
318 netdev->name, netdev); 315 if (err) {
319 if (err) 316 if (adapter->have_msi)
320 DPRINTK(PROBE, ERR, 317 pci_disable_msi(adapter->pdev);
321 "Unable to allocate interrupt Error: %d\n", err);
322 } else
323#endif
324 if ((err = request_irq(adapter->pdev->irq, &e1000_intr, flags,
325 netdev->name, netdev)))
326 DPRINTK(PROBE, ERR, 318 DPRINTK(PROBE, ERR,
327 "Unable to allocate interrupt Error: %d\n", err); 319 "Unable to allocate interrupt Error: %d\n", err);
320 }
328 321
329 return err; 322 return err;
330} 323}
@@ -335,10 +328,8 @@ static void e1000_free_irq(struct e1000_adapter *adapter)
335 328
336 free_irq(adapter->pdev->irq, netdev); 329 free_irq(adapter->pdev->irq, netdev);
337 330
338#ifdef CONFIG_PCI_MSI
339 if (adapter->have_msi) 331 if (adapter->have_msi)
340 pci_disable_msi(adapter->pdev); 332 pci_disable_msi(adapter->pdev);
341#endif
342} 333}
343 334
344/** 335/**
@@ -1214,7 +1205,7 @@ e1000_remove(struct pci_dev *pdev)
1214 int i; 1205 int i;
1215#endif 1206#endif
1216 1207
1217 flush_scheduled_work(); 1208 cancel_work_sync(&adapter->reset_task);
1218 1209
1219 e1000_release_manageability(adapter); 1210 e1000_release_manageability(adapter);
1220 1211
@@ -1440,10 +1431,6 @@ e1000_open(struct net_device *netdev)
1440 /* From here on the code is the same as e1000_up() */ 1431 /* From here on the code is the same as e1000_up() */
1441 clear_bit(__E1000_DOWN, &adapter->flags); 1432 clear_bit(__E1000_DOWN, &adapter->flags);
1442 1433
1443#ifdef CONFIG_E1000_NAPI
1444 netif_poll_enable(netdev);
1445#endif
1446
1447 e1000_irq_enable(adapter); 1434 e1000_irq_enable(adapter);
1448 1435
1449 /* fire a link status change interrupt to start the watchdog */ 1436 /* fire a link status change interrupt to start the watchdog */
@@ -3744,7 +3731,6 @@ e1000_update_stats(struct e1000_adapter *adapter)
3744 3731
3745 spin_unlock_irqrestore(&adapter->stats_lock, flags); 3732 spin_unlock_irqrestore(&adapter->stats_lock, flags);
3746} 3733}
3747#ifdef CONFIG_PCI_MSI
3748 3734
3749/** 3735/**
3750 * e1000_intr_msi - Interrupt Handler 3736 * e1000_intr_msi - Interrupt Handler
@@ -3810,7 +3796,6 @@ e1000_intr_msi(int irq, void *data)
3810 3796
3811 return IRQ_HANDLED; 3797 return IRQ_HANDLED;
3812} 3798}
3813#endif
3814 3799
3815/** 3800/**
3816 * e1000_intr - Interrupt Handler 3801 * e1000_intr - Interrupt Handler
diff --git a/drivers/net/eepro.c b/drivers/net/eepro.c
index 39654e1e2bed..47680237f783 100644
--- a/drivers/net/eepro.c
+++ b/drivers/net/eepro.c
@@ -1126,7 +1126,7 @@ static void eepro_tx_timeout (struct net_device *dev)
1126 printk (KERN_ERR "%s: transmit timed out, %s?\n", dev->name, 1126 printk (KERN_ERR "%s: transmit timed out, %s?\n", dev->name,
1127 "network cable problem"); 1127 "network cable problem");
1128 /* This is not a duplicate. One message for the console, 1128 /* This is not a duplicate. One message for the console,
1129 one for the the log file */ 1129 one for the log file */
1130 printk (KERN_DEBUG "%s: transmit timed out, %s?\n", dev->name, 1130 printk (KERN_DEBUG "%s: transmit timed out, %s?\n", dev->name,
1131 "network cable problem"); 1131 "network cable problem");
1132 eepro_complete_selreset(ioaddr); 1132 eepro_complete_selreset(ioaddr);
diff --git a/drivers/net/eepro100.c b/drivers/net/eepro100.c
index 6c267c38df97..9800341956a2 100644
--- a/drivers/net/eepro100.c
+++ b/drivers/net/eepro100.c
@@ -28,7 +28,7 @@
28*/ 28*/
29 29
30static const char * const version = 30static const char * const version =
31"eepro100.c:v1.09j-t 9/29/99 Donald Becker http://www.scyld.com/network/eepro100.html\n" 31"eepro100.c:v1.09j-t 9/29/99 Donald Becker\n"
32"eepro100.c: $Revision: 1.36 $ 2000/11/17 Modified by Andrey V. Savochkin <saw@saw.sw.com.sg> and others\n"; 32"eepro100.c: $Revision: 1.36 $ 2000/11/17 Modified by Andrey V. Savochkin <saw@saw.sw.com.sg> and others\n";
33 33
34/* A few user-configurable values that apply to all boards. 34/* A few user-configurable values that apply to all boards.
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index c7a5614e66c0..f6e0cb1ada1f 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -1803,10 +1803,10 @@ static inline int ehea_hash_skb(struct sk_buff *skb, int num_qps)
1803 u32 tmp; 1803 u32 tmp;
1804 1804
1805 if ((skb->protocol == htons(ETH_P_IP)) && 1805 if ((skb->protocol == htons(ETH_P_IP)) &&
1806 (skb->nh.iph->protocol == IPPROTO_TCP)) { 1806 (ip_hdr(skb)->protocol == IPPROTO_TCP)) {
1807 tcp = (struct tcphdr*)(skb->nh.raw + (skb->nh.iph->ihl * 4)); 1807 tcp = (struct tcphdr*)(skb_network_header(skb) + (ip_hdr(skb)->ihl * 4));
1808 tmp = (tcp->source + (tcp->dest << 16)) % 31; 1808 tmp = (tcp->source + (tcp->dest << 16)) % 31;
1809 tmp += skb->nh.iph->daddr % 31; 1809 tmp += ip_hdr(skb)->daddr % 31;
1810 return tmp % num_qps; 1810 return tmp % num_qps;
1811 } 1811 }
1812 else 1812 else
@@ -2603,14 +2603,13 @@ static int ehea_setup_ports(struct ehea_adapter *adapter)
2603{ 2603{
2604 struct device_node *lhea_dn; 2604 struct device_node *lhea_dn;
2605 struct device_node *eth_dn = NULL; 2605 struct device_node *eth_dn = NULL;
2606 2606 const u32 *dn_log_port_id;
2607 u32 *dn_log_port_id;
2608 int i = 0; 2607 int i = 0;
2609 2608
2610 lhea_dn = adapter->ebus_dev->ofdev.node; 2609 lhea_dn = adapter->ebus_dev->ofdev.node;
2611 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { 2610 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
2612 2611
2613 dn_log_port_id = (u32*)get_property(eth_dn, "ibm,hea-port-no", 2612 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
2614 NULL); 2613 NULL);
2615 if (!dn_log_port_id) { 2614 if (!dn_log_port_id) {
2616 ehea_error("bad device node: eth_dn name=%s", 2615 ehea_error("bad device node: eth_dn name=%s",
@@ -2645,12 +2644,12 @@ static struct device_node *ehea_get_eth_dn(struct ehea_adapter *adapter,
2645{ 2644{
2646 struct device_node *lhea_dn; 2645 struct device_node *lhea_dn;
2647 struct device_node *eth_dn = NULL; 2646 struct device_node *eth_dn = NULL;
2648 u32 *dn_log_port_id; 2647 const u32 *dn_log_port_id;
2649 2648
2650 lhea_dn = adapter->ebus_dev->ofdev.node; 2649 lhea_dn = adapter->ebus_dev->ofdev.node;
2651 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) { 2650 while ((eth_dn = of_get_next_child(lhea_dn, eth_dn))) {
2652 2651
2653 dn_log_port_id = (u32*)get_property(eth_dn, "ibm,hea-port-no", 2652 dn_log_port_id = of_get_property(eth_dn, "ibm,hea-port-no",
2654 NULL); 2653 NULL);
2655 if (dn_log_port_id) 2654 if (dn_log_port_id)
2656 if (*dn_log_port_id == logical_port_id) 2655 if (*dn_log_port_id == logical_port_id)
@@ -2774,7 +2773,7 @@ static int __devinit ehea_probe_adapter(struct ibmebus_dev *dev,
2774 const struct of_device_id *id) 2773 const struct of_device_id *id)
2775{ 2774{
2776 struct ehea_adapter *adapter; 2775 struct ehea_adapter *adapter;
2777 u64 *adapter_handle; 2776 const u64 *adapter_handle;
2778 int ret; 2777 int ret;
2779 2778
2780 if (!dev || !dev->ofdev.node) { 2779 if (!dev || !dev->ofdev.node) {
@@ -2791,7 +2790,7 @@ static int __devinit ehea_probe_adapter(struct ibmebus_dev *dev,
2791 2790
2792 adapter->ebus_dev = dev; 2791 adapter->ebus_dev = dev;
2793 2792
2794 adapter_handle = (u64*)get_property(dev->ofdev.node, "ibm,hea-handle", 2793 adapter_handle = of_get_property(dev->ofdev.node, "ibm,hea-handle",
2795 NULL); 2794 NULL);
2796 if (adapter_handle) 2795 if (adapter_handle)
2797 adapter->handle = *adapter_handle; 2796 adapter->handle = *adapter_handle;
diff --git a/drivers/net/epic100.c b/drivers/net/epic100.c
index 4e3f14c9c717..5e517946f46a 100644
--- a/drivers/net/epic100.c
+++ b/drivers/net/epic100.c
@@ -93,8 +93,6 @@ static int rx_copybreak;
93static char version[] __devinitdata = 93static char version[] __devinitdata =
94DRV_NAME ".c:v1.11 1/7/2001 Written by Donald Becker <becker@scyld.com>\n"; 94DRV_NAME ".c:v1.11 1/7/2001 Written by Donald Becker <becker@scyld.com>\n";
95static char version2[] __devinitdata = 95static char version2[] __devinitdata =
96" http://www.scyld.com/network/epic100.html\n";
97static char version3[] __devinitdata =
98" (unofficial 2.4.x kernel port, version " DRV_VERSION ", " DRV_RELDATE ")\n"; 96" (unofficial 2.4.x kernel port, version " DRV_VERSION ", " DRV_RELDATE ")\n";
99 97
100MODULE_AUTHOR("Donald Becker <becker@scyld.com>"); 98MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
@@ -323,8 +321,8 @@ static int __devinit epic_init_one (struct pci_dev *pdev,
323#ifndef MODULE 321#ifndef MODULE
324 static int printed_version; 322 static int printed_version;
325 if (!printed_version++) 323 if (!printed_version++)
326 printk (KERN_INFO "%s" KERN_INFO "%s" KERN_INFO "%s", 324 printk (KERN_INFO "%s" KERN_INFO "%s",
327 version, version2, version3); 325 version, version2);
328#endif 326#endif
329 327
330 card_idx++; 328 card_idx++;
@@ -1596,8 +1594,8 @@ static int __init epic_init (void)
1596{ 1594{
1597/* when a module, this is printed whether or not devices are found in probe */ 1595/* when a module, this is printed whether or not devices are found in probe */
1598#ifdef MODULE 1596#ifdef MODULE
1599 printk (KERN_INFO "%s" KERN_INFO "%s" KERN_INFO "%s", 1597 printk (KERN_INFO "%s" KERN_INFO "%s",
1600 version, version2, version3); 1598 version, version2);
1601#endif 1599#endif
1602 1600
1603 return pci_register_driver(&epic_driver); 1601 return pci_register_driver(&epic_driver);
diff --git a/drivers/net/fs_enet/mac-scc.c b/drivers/net/fs_enet/mac-scc.c
index d0f28981b55a..7540966687ec 100644
--- a/drivers/net/fs_enet/mac-scc.c
+++ b/drivers/net/fs_enet/mac-scc.c
@@ -167,7 +167,7 @@ static int allocate_bd(struct net_device *dev)
167 167
168 fep->ring_mem_addr = cpm_dpalloc((fpi->tx_ring + fpi->rx_ring) * 168 fep->ring_mem_addr = cpm_dpalloc((fpi->tx_ring + fpi->rx_ring) *
169 sizeof(cbd_t), 8); 169 sizeof(cbd_t), 8);
170 if (IS_DPERR(fep->ring_mem_addr)) 170 if (IS_ERR_VALUE(fep->ring_mem_addr))
171 return -ENOMEM; 171 return -ENOMEM;
172 172
173 fep->ring_base = cpm_dpram_addr(fep->ring_mem_addr); 173 fep->ring_base = cpm_dpram_addr(fep->ring_mem_addr);
diff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c
index b666a0cc0642..f5b3cba23fc5 100644
--- a/drivers/net/gianfar.c
+++ b/drivers/net/gianfar.c
@@ -1025,6 +1025,15 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
1025 1025
1026 dev->trans_start = jiffies; 1026 dev->trans_start = jiffies;
1027 1027
1028 /* The powerpc-specific eieio() is used, as wmb() has too strong
1029 * semantics (it requires synchronization between cacheable and
1030 * uncacheable mappings, which eieio doesn't provide and which we
1031 * don't need), thus requiring a more expensive sync instruction. At
1032 * some point, the set of architecture-independent barrier functions
1033 * should be expanded to include weaker barriers.
1034 */
1035
1036 eieio();
1028 txbdp->status = status; 1037 txbdp->status = status;
1029 1038
1030 /* If this was the last BD in the ring, the next one */ 1039 /* If this was the last BD in the ring, the next one */
@@ -1301,6 +1310,7 @@ struct sk_buff * gfar_new_skb(struct net_device *dev, struct rxbd8 *bdp)
1301 bdp->length = 0; 1310 bdp->length = 0;
1302 1311
1303 /* Mark the buffer empty */ 1312 /* Mark the buffer empty */
1313 eieio();
1304 bdp->status |= (RXBD_EMPTY | RXBD_INTERRUPT); 1314 bdp->status |= (RXBD_EMPTY | RXBD_INTERRUPT);
1305 1315
1306 return skb; 1316 return skb;
@@ -1484,6 +1494,7 @@ int gfar_clean_rx_ring(struct net_device *dev, int rx_work_limit)
1484 bdp = priv->cur_rx; 1494 bdp = priv->cur_rx;
1485 1495
1486 while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) { 1496 while (!((bdp->status & RXBD_EMPTY) || (--rx_work_limit < 0))) {
1497 rmb();
1487 skb = priv->rx_skbuff[priv->skb_currx]; 1498 skb = priv->rx_skbuff[priv->skb_currx];
1488 1499
1489 if (!(bdp->status & 1500 if (!(bdp->status &
diff --git a/drivers/net/hamradio/Kconfig b/drivers/net/hamradio/Kconfig
index 6e90619b3b41..36d2c7d4f4d0 100644
--- a/drivers/net/hamradio/Kconfig
+++ b/drivers/net/hamradio/Kconfig
@@ -140,7 +140,7 @@ config BAYCOM_SER_HDX
140 modems that connect to a serial interface. The driver supports the 140 modems that connect to a serial interface. The driver supports the
141 ser12 design in half-duplex mode. This is the old driver. It is 141 ser12 design in half-duplex mode. This is the old driver. It is
142 still provided in case your serial interface chip does not work with 142 still provided in case your serial interface chip does not work with
143 the full-duplex driver. This driver is depreciated. To configure 143 the full-duplex driver. This driver is deprecated. To configure
144 the driver, use the sethdlc utility available in the standard ax25 144 the driver, use the sethdlc utility available in the standard ax25
145 utilities package. For information on the modems, see 145 utilities package. For information on the modems, see
146 <http://www.baycom.de/> and 146 <http://www.baycom.de/> and
diff --git a/drivers/net/ibm_emac/ibm_emac_core.c b/drivers/net/ibm_emac/ibm_emac_core.c
index 50035ebd4f52..f752e5fc65ba 100644
--- a/drivers/net/ibm_emac/ibm_emac_core.c
+++ b/drivers/net/ibm_emac/ibm_emac_core.c
@@ -926,7 +926,7 @@ static int emac_link_differs(struct ocp_enet_private *dev)
926 int duplex = r & EMAC_MR1_FDE ? DUPLEX_FULL : DUPLEX_HALF; 926 int duplex = r & EMAC_MR1_FDE ? DUPLEX_FULL : DUPLEX_HALF;
927 int speed, pause, asym_pause; 927 int speed, pause, asym_pause;
928 928
929 if (r & (EMAC_MR1_MF_1000 | EMAC_MR1_MF_1000GPCS)) 929 if (r & EMAC_MR1_MF_1000)
930 speed = SPEED_1000; 930 speed = SPEED_1000;
931 else if (r & EMAC_MR1_MF_100) 931 else if (r & EMAC_MR1_MF_100)
932 speed = SPEED_100; 932 speed = SPEED_100;
diff --git a/drivers/net/ibm_emac/ibm_emac_mal.c b/drivers/net/ibm_emac/ibm_emac_mal.c
index 6c0f071e4052..cabd9846a5ee 100644
--- a/drivers/net/ibm_emac/ibm_emac_mal.c
+++ b/drivers/net/ibm_emac/ibm_emac_mal.c
@@ -59,8 +59,7 @@ int __init mal_register_commac(struct ibm_ocp_mal *mal,
59 return 0; 59 return 0;
60} 60}
61 61
62void __exit mal_unregister_commac(struct ibm_ocp_mal *mal, 62void mal_unregister_commac(struct ibm_ocp_mal *mal, struct mal_commac *commac)
63 struct mal_commac *commac)
64{ 63{
65 unsigned long flags; 64 unsigned long flags;
66 local_irq_save(flags); 65 local_irq_save(flags);
diff --git a/drivers/net/ibm_emac/ibm_emac_mal.h b/drivers/net/ibm_emac/ibm_emac_mal.h
index 407d2acbf7c7..64bc338acc6c 100644
--- a/drivers/net/ibm_emac/ibm_emac_mal.h
+++ b/drivers/net/ibm_emac/ibm_emac_mal.h
@@ -223,8 +223,7 @@ void mal_exit(void) __exit;
223 223
224int mal_register_commac(struct ibm_ocp_mal *mal, 224int mal_register_commac(struct ibm_ocp_mal *mal,
225 struct mal_commac *commac) __init; 225 struct mal_commac *commac) __init;
226void mal_unregister_commac(struct ibm_ocp_mal *mal, 226void mal_unregister_commac(struct ibm_ocp_mal *mal, struct mal_commac *commac);
227 struct mal_commac *commac) __exit;
228int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, unsigned long size); 227int mal_set_rcbs(struct ibm_ocp_mal *mal, int channel, unsigned long size);
229 228
230/* Returns BD ring offset for a particular channel 229/* Returns BD ring offset for a particular channel
diff --git a/drivers/net/ibm_emac/ibm_emac_phy.c b/drivers/net/ibm_emac/ibm_emac_phy.c
index 9074f76ee2bf..e57862b34cae 100644
--- a/drivers/net/ibm_emac/ibm_emac_phy.c
+++ b/drivers/net/ibm_emac/ibm_emac_phy.c
@@ -22,6 +22,7 @@
22 22
23#include <asm/ocp.h> 23#include <asm/ocp.h>
24 24
25#include "ibm_emac_core.h"
25#include "ibm_emac_phy.h" 26#include "ibm_emac_phy.h"
26 27
27static inline int phy_read(struct mii_phy *phy, int reg) 28static inline int phy_read(struct mii_phy *phy, int reg)
@@ -34,11 +35,39 @@ static inline void phy_write(struct mii_phy *phy, int reg, int val)
34 phy->mdio_write(phy->dev, phy->address, reg, val); 35 phy->mdio_write(phy->dev, phy->address, reg, val);
35} 36}
36 37
37int mii_reset_phy(struct mii_phy *phy) 38/*
39 * polls MII_BMCR until BMCR_RESET bit clears or operation times out.
40 *
41 * returns:
42 * >= 0 => success, value in BMCR returned to caller
43 * -EBUSY => failure, RESET bit never cleared
44 * otherwise => failure, lower level PHY read failed
45 */
46static int mii_spin_reset_complete(struct mii_phy *phy)
38{ 47{
39 int val; 48 int val;
40 int limit = 10000; 49 int limit = 10000;
41 50
51 while (limit--) {
52 val = phy_read(phy, MII_BMCR);
53 if (val >= 0 && !(val & BMCR_RESET))
54 return val; /* success */
55 udelay(10);
56 }
57 if (val & BMCR_RESET)
58 val = -EBUSY;
59
60 if (net_ratelimit())
61 printk(KERN_ERR "emac%d: PHY reset timeout (%d)\n",
62 ((struct ocp_enet_private *)phy->dev->priv)->def->index,
63 val);
64 return val;
65}
66
67int mii_reset_phy(struct mii_phy *phy)
68{
69 int val;
70
42 val = phy_read(phy, MII_BMCR); 71 val = phy_read(phy, MII_BMCR);
43 val &= ~BMCR_ISOLATE; 72 val &= ~BMCR_ISOLATE;
44 val |= BMCR_RESET; 73 val |= BMCR_RESET;
@@ -46,16 +75,11 @@ int mii_reset_phy(struct mii_phy *phy)
46 75
47 udelay(300); 76 udelay(300);
48 77
49 while (limit--) { 78 val = mii_spin_reset_complete(phy);
50 val = phy_read(phy, MII_BMCR); 79 if (val >= 0 && (val & BMCR_ISOLATE))
51 if (val >= 0 && (val & BMCR_RESET) == 0)
52 break;
53 udelay(10);
54 }
55 if ((val & BMCR_ISOLATE) && limit > 0)
56 phy_write(phy, MII_BMCR, val & ~BMCR_ISOLATE); 80 phy_write(phy, MII_BMCR, val & ~BMCR_ISOLATE);
57 81
58 return limit <= 0; 82 return val < 0;
59} 83}
60 84
61static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise) 85static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
@@ -102,8 +126,14 @@ static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
102 } 126 }
103 127
104 /* Start/Restart aneg */ 128 /* Start/Restart aneg */
105 ctl = phy_read(phy, MII_BMCR); 129 /* on some PHYs (e.g. National DP83843) a write to MII_ADVERTISE
106 ctl |= (BMCR_ANENABLE | BMCR_ANRESTART); 130 * causes BMCR_RESET to be set on the next read of MII_BMCR, which
131 * if not checked for causes the PHY to be reset below */
132 ctl = mii_spin_reset_complete(phy);
133 if (ctl < 0)
134 return ctl;
135
136 ctl |= BMCR_ANENABLE | BMCR_ANRESTART;
107 phy_write(phy, MII_BMCR, ctl); 137 phy_write(phy, MII_BMCR, ctl);
108 138
109 return 0; 139 return 0;
@@ -118,13 +148,13 @@ static int genmii_setup_forced(struct mii_phy *phy, int speed, int fd)
118 phy->duplex = fd; 148 phy->duplex = fd;
119 phy->pause = phy->asym_pause = 0; 149 phy->pause = phy->asym_pause = 0;
120 150
151 /* First reset the PHY */
152 mii_reset_phy(phy);
153
121 ctl = phy_read(phy, MII_BMCR); 154 ctl = phy_read(phy, MII_BMCR);
122 if (ctl < 0) 155 if (ctl < 0)
123 return ctl; 156 return ctl;
124 ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_ANENABLE); 157 ctl &= ~(BMCR_FULLDPLX | BMCR_SPEED100 | BMCR_ANENABLE | BMCR_SPEED1000);
125
126 /* First reset the PHY */
127 phy_write(phy, MII_BMCR, ctl | BMCR_RESET);
128 158
129 /* Select speed & duplex */ 159 /* Select speed & duplex */
130 switch (speed) { 160 switch (speed) {
diff --git a/drivers/net/ibm_emac/ibm_emac_rgmii.c b/drivers/net/ibm_emac/ibm_emac_rgmii.c
index 53d281cb9a16..9dbb5e5936c3 100644
--- a/drivers/net/ibm_emac/ibm_emac_rgmii.c
+++ b/drivers/net/ibm_emac/ibm_emac_rgmii.c
@@ -162,7 +162,7 @@ void rgmii_set_speed(struct ocp_device *ocpdev, int input, int speed)
162 out_be32(&dev->base->ssr, ssr); 162 out_be32(&dev->base->ssr, ssr);
163} 163}
164 164
165void __exit __rgmii_fini(struct ocp_device *ocpdev, int input) 165void __rgmii_fini(struct ocp_device *ocpdev, int input)
166{ 166{
167 struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev); 167 struct ibm_ocp_rgmii *dev = ocp_get_drvdata(ocpdev);
168 BUG_ON(!dev || dev->users == 0); 168 BUG_ON(!dev || dev->users == 0);
diff --git a/drivers/net/ibm_emac/ibm_emac_rgmii.h b/drivers/net/ibm_emac/ibm_emac_rgmii.h
index 117ea486c2ca..971e45815c6c 100644
--- a/drivers/net/ibm_emac/ibm_emac_rgmii.h
+++ b/drivers/net/ibm_emac/ibm_emac_rgmii.h
@@ -37,7 +37,7 @@ struct ibm_ocp_rgmii {
37#ifdef CONFIG_IBM_EMAC_RGMII 37#ifdef CONFIG_IBM_EMAC_RGMII
38int rgmii_attach(void *emac) __init; 38int rgmii_attach(void *emac) __init;
39 39
40void __rgmii_fini(struct ocp_device *ocpdev, int input) __exit; 40void __rgmii_fini(struct ocp_device *ocpdev, int input);
41static inline void rgmii_fini(struct ocp_device *ocpdev, int input) 41static inline void rgmii_fini(struct ocp_device *ocpdev, int input)
42{ 42{
43 if (ocpdev) 43 if (ocpdev)
diff --git a/drivers/net/ibm_emac/ibm_emac_tah.c b/drivers/net/ibm_emac/ibm_emac_tah.c
index e287b451bb44..3c2d5ba522a1 100644
--- a/drivers/net/ibm_emac/ibm_emac_tah.c
+++ b/drivers/net/ibm_emac/ibm_emac_tah.c
@@ -63,7 +63,7 @@ int __init tah_attach(void *emac)
63 return 0; 63 return 0;
64} 64}
65 65
66void __exit __tah_fini(struct ocp_device *ocpdev) 66void __tah_fini(struct ocp_device *ocpdev)
67{ 67{
68 struct tah_regs *p = ocp_get_drvdata(ocpdev); 68 struct tah_regs *p = ocp_get_drvdata(ocpdev);
69 BUG_ON(!p); 69 BUG_ON(!p);
diff --git a/drivers/net/ibm_emac/ibm_emac_tah.h b/drivers/net/ibm_emac/ibm_emac_tah.h
index 38153945a240..ccf64915e1e4 100644
--- a/drivers/net/ibm_emac/ibm_emac_tah.h
+++ b/drivers/net/ibm_emac/ibm_emac_tah.h
@@ -55,7 +55,7 @@ struct tah_regs {
55#ifdef CONFIG_IBM_EMAC_TAH 55#ifdef CONFIG_IBM_EMAC_TAH
56int tah_attach(void *emac) __init; 56int tah_attach(void *emac) __init;
57 57
58void __tah_fini(struct ocp_device *ocpdev) __exit; 58void __tah_fini(struct ocp_device *ocpdev);
59static inline void tah_fini(struct ocp_device *ocpdev) 59static inline void tah_fini(struct ocp_device *ocpdev)
60{ 60{
61 if (ocpdev) 61 if (ocpdev)
diff --git a/drivers/net/ibm_emac/ibm_emac_zmii.c b/drivers/net/ibm_emac/ibm_emac_zmii.c
index 37dc8f342868..2c0fdb0cabff 100644
--- a/drivers/net/ibm_emac/ibm_emac_zmii.c
+++ b/drivers/net/ibm_emac/ibm_emac_zmii.c
@@ -215,7 +215,7 @@ void __zmii_set_speed(struct ocp_device *ocpdev, int input, int speed)
215 out_be32(&dev->base->ssr, ssr); 215 out_be32(&dev->base->ssr, ssr);
216} 216}
217 217
218void __exit __zmii_fini(struct ocp_device *ocpdev, int input) 218void __zmii_fini(struct ocp_device *ocpdev, int input)
219{ 219{
220 struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev); 220 struct ibm_ocp_zmii *dev = ocp_get_drvdata(ocpdev);
221 BUG_ON(!dev || dev->users == 0); 221 BUG_ON(!dev || dev->users == 0);
diff --git a/drivers/net/ibm_emac/ibm_emac_zmii.h b/drivers/net/ibm_emac/ibm_emac_zmii.h
index 972e3a44a09f..fad6d8bf983a 100644
--- a/drivers/net/ibm_emac/ibm_emac_zmii.h
+++ b/drivers/net/ibm_emac/ibm_emac_zmii.h
@@ -40,7 +40,7 @@ struct ibm_ocp_zmii {
40#ifdef CONFIG_IBM_EMAC_ZMII 40#ifdef CONFIG_IBM_EMAC_ZMII
41int zmii_attach(void *emac) __init; 41int zmii_attach(void *emac) __init;
42 42
43void __zmii_fini(struct ocp_device *ocpdev, int input) __exit; 43void __zmii_fini(struct ocp_device *ocpdev, int input);
44static inline void zmii_fini(struct ocp_device *ocpdev, int input) 44static inline void zmii_fini(struct ocp_device *ocpdev, int input)
45{ 45{
46 if (ocpdev) 46 if (ocpdev)
diff --git a/drivers/net/irda/Kconfig b/drivers/net/irda/Kconfig
index 7c8ccc09b601..829da9a1d113 100644
--- a/drivers/net/irda/Kconfig
+++ b/drivers/net/irda/Kconfig
@@ -141,6 +141,20 @@ config ACT200L_DONGLE
141 To activate support for ACTiSYS IR-200L dongle you will have to 141 To activate support for ACTiSYS IR-200L dongle you will have to
142 start irattach like this: "irattach -d act200l". 142 start irattach like this: "irattach -d act200l".
143 143
144config KINGSUN_DONGLE
145 tristate "KingSun/DonShine DS-620 IrDA-USB dongle"
146 depends on IRDA && USB && EXPERIMENTAL
147 help
148 Say Y or M here if you want to build support for the KingSun/DonShine
149 DS-620 IrDA-USB bridge device driver.
150
151 This USB bridge does not conform to the IrDA-USB device class
152 specification, and therefore needs its own specific driver. This
153 dongle supports SIR speed only (9600 bps).
154
155 To compile it as a module, choose M here: the module will be called
156 kingsun-sir.
157
144comment "Old SIR device drivers" 158comment "Old SIR device drivers"
145 159
146config IRPORT_SIR 160config IRPORT_SIR
diff --git a/drivers/net/irda/Makefile b/drivers/net/irda/Makefile
index 5be09f1b9ee2..233a2f923730 100644
--- a/drivers/net/irda/Makefile
+++ b/drivers/net/irda/Makefile
@@ -45,6 +45,7 @@ obj-$(CONFIG_MCP2120_DONGLE) += mcp2120-sir.o
45obj-$(CONFIG_ACT200L_DONGLE) += act200l-sir.o 45obj-$(CONFIG_ACT200L_DONGLE) += act200l-sir.o
46obj-$(CONFIG_MA600_DONGLE) += ma600-sir.o 46obj-$(CONFIG_MA600_DONGLE) += ma600-sir.o
47obj-$(CONFIG_TOIM3232_DONGLE) += toim3232-sir.o 47obj-$(CONFIG_TOIM3232_DONGLE) += toim3232-sir.o
48obj-$(CONFIG_KINGSUN_DONGLE) += kingsun-sir.o
48 49
49# The SIR helper module 50# The SIR helper module
50sir-dev-objs := sir_dev.o sir_dongle.o 51sir-dev-objs := sir_dev.o sir_dongle.o
diff --git a/drivers/net/irda/donauboe.h b/drivers/net/irda/donauboe.h
index 2ab173d9a0e4..1e67720f1066 100644
--- a/drivers/net/irda/donauboe.h
+++ b/drivers/net/irda/donauboe.h
@@ -113,7 +113,7 @@
113/* RxOver overflow in Recv FIFO */ 113/* RxOver overflow in Recv FIFO */
114/* SipRcv received serial gap (or other condition you set) */ 114/* SipRcv received serial gap (or other condition you set) */
115/* Interrupts are enabled by writing a one to the IER register */ 115/* Interrupts are enabled by writing a one to the IER register */
116/* Interrupts are cleared by writting a one to the ISR register */ 116/* Interrupts are cleared by writing a one to the ISR register */
117/* */ 117/* */
118/* 6. The remaining registers: 0x6 and 0x3 appear to be */ 118/* 6. The remaining registers: 0x6 and 0x3 appear to be */
119/* reserved parts of 16 or 32 bit registersthe remainder */ 119/* reserved parts of 16 or 32 bit registersthe remainder */
diff --git a/drivers/net/irda/kingsun-sir.c b/drivers/net/irda/kingsun-sir.c
new file mode 100644
index 000000000000..217429122e79
--- /dev/null
+++ b/drivers/net/irda/kingsun-sir.c
@@ -0,0 +1,657 @@
1/*****************************************************************************
2*
3* Filename: kingsun-sir.c
4* Version: 0.1.1
5* Description: Irda KingSun/DonShine USB Dongle
6* Status: Experimental
7* Author: Alex Villac�s Lasso <a_villacis@palosanto.com>
8*
9* Based on stir4200 and mcs7780 drivers, with (strange?) differences
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.
14*
15* This program is distributed in the hope that it will be useful,
16* but WITHOUT ANY WARRANTY; without even the implied warranty of
17* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18* GNU General Public License for more details.
19*
20* You should have received a copy of the GNU General Public License
21* along with this program; if not, write to the Free Software
22* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23*
24*****************************************************************************/
25
26/*
27 * This is my current (2007-04-25) understanding of how this dongle is supposed
28 * to work. This is based on reverse-engineering and examination of the packet
29 * data sent and received by the WinXP driver using USBSnoopy. Feel free to
30 * update here as more of this dongle is known:
31 *
32 * General: Unlike the other USB IrDA dongles, this particular dongle exposes,
33 * not two bulk (in and out) endpoints, but two *interrupt* ones. This dongle,
34 * like the bulk based ones (stir4200.c and mcs7780.c), requires polling in
35 * order to receive data.
36 * Transmission: Just like stir4200, this dongle uses a raw stream of data,
37 * which needs to be wrapped and escaped in a similar way as in stir4200.c.
38 * Reception: Poll-based, as in stir4200. Each read returns the contents of a
39 * 8-byte buffer, of which the first byte (LSB) indicates the number of bytes
40 * (1-7) of valid data contained within the remaining 7 bytes. For example, if
41 * the buffer had the following contents:
42 * 06 ff ff ff c0 01 04 aa
43 * This means that (06) there are 6 bytes of valid data. The byte 0xaa at the
44 * end is garbage (left over from a previous reception) and is discarded.
45 * If a read returns an "impossible" value as the length of valid data (such as
46 * 0x36) in the first byte, then the buffer is uninitialized (as is the case of
47 * first plug-in) and its contents should be discarded. There is currently no
48 * evidence that the top 5 bits of the 1st byte of the buffer can have values
49 * other than 0 once reception begins.
50 * Once valid bytes are collected, the assembled stream is a sequence of
51 * wrapped IrDA frames that is unwrapped and unescaped as in stir4200.c.
52 * BIG FAT WARNING: the dongle does *not* reset the RX buffer in any way after
53 * a successful read from the host, which means that in absence of further
54 * reception, repeated reads from the dongle will return the exact same
55 * contents repeatedly. Attempts to be smart and cache a previous read seem
56 * to result in corrupted packets, so this driver depends on the unwrap logic
57 * to sort out any repeated reads.
58 * Speed change: no commands observed so far to change speed, assumed fixed
59 * 9600bps (SIR).
60 */
61
62#include <linux/module.h>
63#include <linux/moduleparam.h>
64#include <linux/kernel.h>
65#include <linux/types.h>
66#include <linux/errno.h>
67#include <linux/init.h>
68#include <linux/slab.h>
69#include <linux/module.h>
70#include <linux/kref.h>
71#include <linux/usb.h>
72#include <linux/device.h>
73#include <linux/crc32.h>
74
75#include <asm/unaligned.h>
76#include <asm/byteorder.h>
77#include <asm/uaccess.h>
78
79#include <net/irda/irda.h>
80#include <net/irda/wrapper.h>
81#include <net/irda/crc.h>
82
83/*
84 * According to lsusb, 0x07c0 is assigned to
85 * "Code Mercenaries Hard- und Software GmbH"
86 */
87#define KING_VENDOR_ID 0x07c0
88#define KING_PRODUCT_ID 0x4200
89
90/* These are the currently known USB ids */
91static struct usb_device_id dongles[] = {
92 /* KingSun Co,Ltd IrDA/USB Bridge */
93 { USB_DEVICE(KING_VENDOR_ID, KING_PRODUCT_ID) },
94 { }
95};
96
97MODULE_DEVICE_TABLE(usb, dongles);
98
99#define KINGSUN_MTT 0x07
100
101#define KINGSUN_FIFO_SIZE 4096
102#define KINGSUN_EP_IN 0
103#define KINGSUN_EP_OUT 1
104
105struct kingsun_cb {
106 struct usb_device *usbdev; /* init: probe_irda */
107 struct net_device *netdev; /* network layer */
108 struct irlap_cb *irlap; /* The link layer we are binded to */
109 struct net_device_stats stats; /* network statistics */
110 struct qos_info qos;
111
112 __u8 *in_buf; /* receive buffer */
113 __u8 *out_buf; /* transmit buffer */
114 __u8 max_rx; /* max. atomic read from dongle
115 (usually 8), also size of in_buf */
116 __u8 max_tx; /* max. atomic write to dongle
117 (usually 8) */
118
119 iobuff_t rx_buff; /* receive unwrap state machine */
120 struct timeval rx_time;
121 spinlock_t lock;
122 int receiving;
123
124 __u8 ep_in;
125 __u8 ep_out;
126
127 struct urb *tx_urb;
128 struct urb *rx_urb;
129};
130
131/* Callback transmission routine */
132static void kingsun_send_irq(struct urb *urb)
133{
134 struct kingsun_cb *kingsun = urb->context;
135 struct net_device *netdev = kingsun->netdev;
136
137 /* in process of stopping, just drop data */
138 if (!netif_running(kingsun->netdev)) {
139 err("kingsun_send_irq: Network not running!");
140 return;
141 }
142
143 /* unlink, shutdown, unplug, other nasties */
144 if (urb->status != 0) {
145 err("kingsun_send_irq: urb asynchronously failed - %d",
146 urb->status);
147 }
148 netif_wake_queue(netdev);
149}
150
151/*
152 * Called from net/core when new frame is available.
153 */
154static int kingsun_hard_xmit(struct sk_buff *skb, struct net_device *netdev)
155{
156 struct kingsun_cb *kingsun;
157 int wraplen;
158 int ret = 0;
159
160 if (skb == NULL || netdev == NULL)
161 return -EINVAL;
162
163 netif_stop_queue(netdev);
164
165 /* the IRDA wrapping routines don't deal with non linear skb */
166 SKB_LINEAR_ASSERT(skb);
167
168 kingsun = netdev_priv(netdev);
169
170 spin_lock(&kingsun->lock);
171
172 /* Append data to the end of whatever data remains to be transmitted */
173 wraplen = async_wrap_skb(skb,
174 kingsun->out_buf,
175 KINGSUN_FIFO_SIZE);
176
177 /* Calculate how much data can be transmitted in this urb */
178 usb_fill_int_urb(kingsun->tx_urb, kingsun->usbdev,
179 usb_sndintpipe(kingsun->usbdev, kingsun->ep_out),
180 kingsun->out_buf, wraplen, kingsun_send_irq,
181 kingsun, 1);
182
183 if ((ret = usb_submit_urb(kingsun->tx_urb, GFP_ATOMIC))) {
184 err("kingsun_hard_xmit: failed tx_urb submit: %d", ret);
185 switch (ret) {
186 case -ENODEV:
187 case -EPIPE:
188 break;
189 default:
190 kingsun->stats.tx_errors++;
191 netif_start_queue(netdev);
192 }
193 } else {
194 kingsun->stats.tx_packets++;
195 kingsun->stats.tx_bytes += skb->len;
196 }
197
198 dev_kfree_skb(skb);
199 spin_unlock(&kingsun->lock);
200
201 return ret;
202}
203
204/* Receive callback function */
205static void kingsun_rcv_irq(struct urb *urb)
206{
207 struct kingsun_cb *kingsun = urb->context;
208 int ret;
209
210 /* in process of stopping, just drop data */
211 if (!netif_running(kingsun->netdev)) {
212 kingsun->receiving = 0;
213 return;
214 }
215
216 /* unlink, shutdown, unplug, other nasties */
217 if (urb->status != 0) {
218 err("kingsun_rcv_irq: urb asynchronously failed - %d",
219 urb->status);
220 kingsun->receiving = 0;
221 return;
222 }
223
224 if (urb->actual_length == kingsun->max_rx) {
225 __u8 *bytes = urb->transfer_buffer;
226 int i;
227
228 /* The very first byte in the buffer indicates the length of
229 valid data in the read. This byte must be in the range
230 1..kingsun->max_rx -1 . Values outside this range indicate
231 an uninitialized Rx buffer when the dongle has just been
232 plugged in. */
233 if (bytes[0] >= 1 && bytes[0] < kingsun->max_rx) {
234 for (i = 1; i <= bytes[0]; i++) {
235 async_unwrap_char(kingsun->netdev,
236 &kingsun->stats,
237 &kingsun->rx_buff, bytes[i]);
238 }
239 kingsun->netdev->last_rx = jiffies;
240 do_gettimeofday(&kingsun->rx_time);
241 kingsun->receiving =
242 (kingsun->rx_buff.state != OUTSIDE_FRAME)
243 ? 1 : 0;
244 }
245 } else if (urb->actual_length > 0) {
246 err("%s(): Unexpected response length, expected %d got %d",
247 __FUNCTION__, kingsun->max_rx, urb->actual_length);
248 }
249 /* This urb has already been filled in kingsun_net_open */
250 ret = usb_submit_urb(urb, GFP_ATOMIC);
251}
252
253/*
254 * Function kingsun_net_open (dev)
255 *
256 * Network device is taken up. Usually this is done by "ifconfig irda0 up"
257 */
258static int kingsun_net_open(struct net_device *netdev)
259{
260 struct kingsun_cb *kingsun = netdev_priv(netdev);
261 int err = -ENOMEM;
262 char hwname[16];
263
264 /* At this point, urbs are NULL, and skb is NULL (see kingsun_probe) */
265 kingsun->receiving = 0;
266
267 /* Initialize for SIR to copy data directly into skb. */
268 kingsun->rx_buff.in_frame = FALSE;
269 kingsun->rx_buff.state = OUTSIDE_FRAME;
270 kingsun->rx_buff.truesize = IRDA_SKB_MAX_MTU;
271 kingsun->rx_buff.skb = dev_alloc_skb(IRDA_SKB_MAX_MTU);
272 if (!kingsun->rx_buff.skb)
273 goto free_mem;
274
275 skb_reserve(kingsun->rx_buff.skb, 1);
276 kingsun->rx_buff.head = kingsun->rx_buff.skb->data;
277 do_gettimeofday(&kingsun->rx_time);
278
279 kingsun->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
280 if (!kingsun->rx_urb)
281 goto free_mem;
282
283 kingsun->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
284 if (!kingsun->tx_urb)
285 goto free_mem;
286
287 /*
288 * Now that everything should be initialized properly,
289 * Open new IrLAP layer instance to take care of us...
290 */
291 sprintf(hwname, "usb#%d", kingsun->usbdev->devnum);
292 kingsun->irlap = irlap_open(netdev, &kingsun->qos, hwname);
293 if (!kingsun->irlap) {
294 err("kingsun-sir: irlap_open failed");
295 goto free_mem;
296 }
297
298 /* Start first reception */
299 usb_fill_int_urb(kingsun->rx_urb, kingsun->usbdev,
300 usb_rcvintpipe(kingsun->usbdev, kingsun->ep_in),
301 kingsun->in_buf, kingsun->max_rx,
302 kingsun_rcv_irq, kingsun, 1);
303 kingsun->rx_urb->status = 0;
304 err = usb_submit_urb(kingsun->rx_urb, GFP_KERNEL);
305 if (err) {
306 err("kingsun-sir: first urb-submit failed: %d", err);
307 goto close_irlap;
308 }
309
310 netif_start_queue(netdev);
311
312 /* Situation at this point:
313 - all work buffers allocated
314 - urbs allocated and ready to fill
315 - max rx packet known (in max_rx)
316 - unwrap state machine initialized, in state outside of any frame
317 - receive request in progress
318 - IrLAP layer started, about to hand over packets to send
319 */
320
321 return 0;
322
323 close_irlap:
324 irlap_close(kingsun->irlap);
325 free_mem:
326 if (kingsun->tx_urb) {
327 usb_free_urb(kingsun->tx_urb);
328 kingsun->tx_urb = NULL;
329 }
330 if (kingsun->rx_urb) {
331 usb_free_urb(kingsun->rx_urb);
332 kingsun->rx_urb = NULL;
333 }
334 if (kingsun->rx_buff.skb) {
335 kfree_skb(kingsun->rx_buff.skb);
336 kingsun->rx_buff.skb = NULL;
337 kingsun->rx_buff.head = NULL;
338 }
339 return err;
340}
341
342/*
343 * Function kingsun_net_close (kingsun)
344 *
345 * Network device is taken down. Usually this is done by
346 * "ifconfig irda0 down"
347 */
348static int kingsun_net_close(struct net_device *netdev)
349{
350 struct kingsun_cb *kingsun = netdev_priv(netdev);
351
352 /* Stop transmit processing */
353 netif_stop_queue(netdev);
354
355 /* Mop up receive && transmit urb's */
356 usb_kill_urb(kingsun->tx_urb);
357 usb_kill_urb(kingsun->rx_urb);
358
359 usb_free_urb(kingsun->tx_urb);
360 usb_free_urb(kingsun->rx_urb);
361
362 kingsun->tx_urb = NULL;
363 kingsun->rx_urb = NULL;
364
365 kfree_skb(kingsun->rx_buff.skb);
366 kingsun->rx_buff.skb = NULL;
367 kingsun->rx_buff.head = NULL;
368 kingsun->rx_buff.in_frame = FALSE;
369 kingsun->rx_buff.state = OUTSIDE_FRAME;
370 kingsun->receiving = 0;
371
372 /* Stop and remove instance of IrLAP */
373 if (kingsun->irlap)
374 irlap_close(kingsun->irlap);
375
376 kingsun->irlap = NULL;
377
378 return 0;
379}
380
381/*
382 * IOCTLs : Extra out-of-band network commands...
383 */
384static int kingsun_net_ioctl(struct net_device *netdev, struct ifreq *rq,
385 int cmd)
386{
387 struct if_irda_req *irq = (struct if_irda_req *) rq;
388 struct kingsun_cb *kingsun = netdev_priv(netdev);
389 int ret = 0;
390
391 switch (cmd) {
392 case SIOCSBANDWIDTH: /* Set bandwidth */
393 if (!capable(CAP_NET_ADMIN))
394 return -EPERM;
395
396 /* Check if the device is still there */
397 if (netif_device_present(kingsun->netdev))
398 /* No observed commands for speed change */
399 ret = -EOPNOTSUPP;
400 break;
401
402 case SIOCSMEDIABUSY: /* Set media busy */
403 if (!capable(CAP_NET_ADMIN))
404 return -EPERM;
405
406 /* Check if the IrDA stack is still there */
407 if (netif_running(kingsun->netdev))
408 irda_device_set_media_busy(kingsun->netdev, TRUE);
409 break;
410
411 case SIOCGRECEIVING:
412 /* Only approximately true */
413 irq->ifr_receiving = kingsun->receiving;
414 break;
415
416 default:
417 ret = -EOPNOTSUPP;
418 }
419
420 return ret;
421}
422
423/*
424 * Get device stats (for /proc/net/dev and ifconfig)
425 */
426static struct net_device_stats *
427kingsun_net_get_stats(struct net_device *netdev)
428{
429 struct kingsun_cb *kingsun = netdev_priv(netdev);
430 return &kingsun->stats;
431}
432
433/*
434 * This routine is called by the USB subsystem for each new device
435 * in the system. We need to check if the device is ours, and in
436 * this case start handling it.
437 */
438static int kingsun_probe(struct usb_interface *intf,
439 const struct usb_device_id *id)
440{
441 struct usb_host_interface *interface;
442 struct usb_endpoint_descriptor *endpoint;
443
444 struct usb_device *dev = interface_to_usbdev(intf);
445 struct kingsun_cb *kingsun = NULL;
446 struct net_device *net = NULL;
447 int ret = -ENOMEM;
448 int pipe, maxp_in, maxp_out;
449 __u8 ep_in;
450 __u8 ep_out;
451
452 /* Check that there really are two interrupt endpoints.
453 Check based on the one in drivers/usb/input/usbmouse.c
454 */
455 interface = intf->cur_altsetting;
456 if (interface->desc.bNumEndpoints != 2) {
457 err("kingsun-sir: expected 2 endpoints, found %d",
458 interface->desc.bNumEndpoints);
459 return -ENODEV;
460 }
461 endpoint = &interface->endpoint[KINGSUN_EP_IN].desc;
462 if (!usb_endpoint_is_int_in(endpoint)) {
463 err("kingsun-sir: endpoint 0 is not interrupt IN");
464 return -ENODEV;
465 }
466
467 ep_in = endpoint->bEndpointAddress;
468 pipe = usb_rcvintpipe(dev, ep_in);
469 maxp_in = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
470 if (maxp_in > 255 || maxp_in <= 1) {
471 err("%s: endpoint 0 has max packet size %d not in range",
472 __FILE__, maxp_in);
473 return -ENODEV;
474 }
475
476 endpoint = &interface->endpoint[KINGSUN_EP_OUT].desc;
477 if (!usb_endpoint_is_int_out(endpoint)) {
478 err("kingsun-sir: endpoint 1 is not interrupt OUT");
479 return -ENODEV;
480 }
481
482 ep_out = endpoint->bEndpointAddress;
483 pipe = usb_sndintpipe(dev, ep_out);
484 maxp_out = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
485
486 /* Allocate network device container. */
487 net = alloc_irdadev(sizeof(*kingsun));
488 if(!net)
489 goto err_out1;
490
491 SET_MODULE_OWNER(net);
492 SET_NETDEV_DEV(net, &intf->dev);
493 kingsun = netdev_priv(net);
494 kingsun->irlap = NULL;
495 kingsun->tx_urb = NULL;
496 kingsun->rx_urb = NULL;
497 kingsun->ep_in = ep_in;
498 kingsun->ep_out = ep_out;
499 kingsun->in_buf = NULL;
500 kingsun->out_buf = NULL;
501 kingsun->max_rx = (__u8)maxp_in;
502 kingsun->max_tx = (__u8)maxp_out;
503 kingsun->netdev = net;
504 kingsun->usbdev = dev;
505 kingsun->rx_buff.in_frame = FALSE;
506 kingsun->rx_buff.state = OUTSIDE_FRAME;
507 kingsun->rx_buff.skb = NULL;
508 kingsun->receiving = 0;
509 spin_lock_init(&kingsun->lock);
510
511 /* Allocate input buffer */
512 kingsun->in_buf = (__u8 *)kmalloc(kingsun->max_rx, GFP_KERNEL);
513 if (!kingsun->in_buf)
514 goto free_mem;
515
516 /* Allocate output buffer */
517 kingsun->out_buf = (__u8 *)kmalloc(KINGSUN_FIFO_SIZE, GFP_KERNEL);
518 if (!kingsun->out_buf)
519 goto free_mem;
520
521 printk(KERN_INFO "KingSun/DonShine IRDA/USB found at address %d, "
522 "Vendor: %x, Product: %x\n",
523 dev->devnum, le16_to_cpu(dev->descriptor.idVendor),
524 le16_to_cpu(dev->descriptor.idProduct));
525
526 /* Initialize QoS for this device */
527 irda_init_max_qos_capabilies(&kingsun->qos);
528
529 /* That's the Rx capability. */
530 kingsun->qos.baud_rate.bits &= IR_9600;
531 kingsun->qos.min_turn_time.bits &= KINGSUN_MTT;
532 irda_qos_bits_to_value(&kingsun->qos);
533
534 /* Override the network functions we need to use */
535 net->hard_start_xmit = kingsun_hard_xmit;
536 net->open = kingsun_net_open;
537 net->stop = kingsun_net_close;
538 net->get_stats = kingsun_net_get_stats;
539 net->do_ioctl = kingsun_net_ioctl;
540
541 ret = register_netdev(net);
542 if (ret != 0)
543 goto free_mem;
544
545 info("IrDA: Registered KingSun/DonShine device %s", net->name);
546
547 usb_set_intfdata(intf, kingsun);
548
549 /* Situation at this point:
550 - all work buffers allocated
551 - urbs not allocated, set to NULL
552 - max rx packet known (in max_rx)
553 - unwrap state machine (partially) initialized, but skb == NULL
554 */
555
556 return 0;
557
558free_mem:
559 if (kingsun->out_buf) kfree(kingsun->out_buf);
560 if (kingsun->in_buf) kfree(kingsun->in_buf);
561 free_netdev(net);
562err_out1:
563 return ret;
564}
565
566/*
567 * The current device is removed, the USB layer tell us to shut it down...
568 */
569static void kingsun_disconnect(struct usb_interface *intf)
570{
571 struct kingsun_cb *kingsun = usb_get_intfdata(intf);
572
573 if (!kingsun)
574 return;
575
576 unregister_netdev(kingsun->netdev);
577
578 /* Mop up receive && transmit urb's */
579 if (kingsun->tx_urb != NULL) {
580 usb_kill_urb(kingsun->tx_urb);
581 usb_free_urb(kingsun->tx_urb);
582 kingsun->tx_urb = NULL;
583 }
584 if (kingsun->rx_urb != NULL) {
585 usb_kill_urb(kingsun->rx_urb);
586 usb_free_urb(kingsun->rx_urb);
587 kingsun->rx_urb = NULL;
588 }
589
590 kfree(kingsun->out_buf);
591 kfree(kingsun->in_buf);
592 free_netdev(kingsun->netdev);
593
594 usb_set_intfdata(intf, NULL);
595}
596
597#ifdef CONFIG_PM
598/* USB suspend, so power off the transmitter/receiver */
599static int kingsun_suspend(struct usb_interface *intf, pm_message_t message)
600{
601 struct kingsun_cb *kingsun = usb_get_intfdata(intf);
602
603 netif_device_detach(kingsun->netdev);
604 if (kingsun->tx_urb != NULL) usb_kill_urb(kingsun->tx_urb);
605 if (kingsun->rx_urb != NULL) usb_kill_urb(kingsun->rx_urb);
606 return 0;
607}
608
609/* Coming out of suspend, so reset hardware */
610static int kingsun_resume(struct usb_interface *intf)
611{
612 struct kingsun_cb *kingsun = usb_get_intfdata(intf);
613
614 if (kingsun->rx_urb != NULL)
615 usb_submit_urb(kingsun->rx_urb, GFP_KERNEL);
616 netif_device_attach(kingsun->netdev);
617
618 return 0;
619}
620#endif
621
622/*
623 * USB device callbacks
624 */
625static struct usb_driver irda_driver = {
626 .name = "kingsun-sir",
627 .probe = kingsun_probe,
628 .disconnect = kingsun_disconnect,
629 .id_table = dongles,
630#ifdef CONFIG_PM
631 .suspend = kingsun_suspend,
632 .resume = kingsun_resume,
633#endif
634};
635
636/*
637 * Module insertion
638 */
639static int __init kingsun_init(void)
640{
641 return usb_register(&irda_driver);
642}
643module_init(kingsun_init);
644
645/*
646 * Module removal
647 */
648static void __exit kingsun_cleanup(void)
649{
650 /* Deregister the driver and remove all pending instances */
651 usb_deregister(&irda_driver);
652}
653module_exit(kingsun_cleanup);
654
655MODULE_AUTHOR("Alex Villac�s Lasso <a_villacis@palosanto.com>");
656MODULE_DESCRIPTION("IrDA-USB Dongle Driver for KingSun/DonShine");
657MODULE_LICENSE("GPL");
diff --git a/drivers/net/irda/sir_dev.c b/drivers/net/irda/sir_dev.c
index 17b0c3ab6201..9d6c8f391b2d 100644
--- a/drivers/net/irda/sir_dev.c
+++ b/drivers/net/irda/sir_dev.c
@@ -14,7 +14,6 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/smp_lock.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19 18
20#include <net/irda/irda.h> 19#include <net/irda/irda.h>
diff --git a/drivers/net/irda/sir_dongle.c b/drivers/net/irda/sir_dongle.c
index d7e32d9554fc..25d5b8a96bdc 100644
--- a/drivers/net/irda/sir_dongle.c
+++ b/drivers/net/irda/sir_dongle.c
@@ -14,7 +14,6 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/smp_lock.h>
18#include <linux/kmod.h> 17#include <linux/kmod.h>
19#include <linux/mutex.h> 18#include <linux/mutex.h>
20 19
diff --git a/drivers/net/irda/smsc-ircc2.c b/drivers/net/irda/smsc-ircc2.c
index 198bf3bfa70f..9043bf4aa49e 100644
--- a/drivers/net/irda/smsc-ircc2.c
+++ b/drivers/net/irda/smsc-ircc2.c
@@ -79,11 +79,17 @@ MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
79MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver"); 79MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
80MODULE_LICENSE("GPL"); 80MODULE_LICENSE("GPL");
81 81
82static int ircc_dma = 255; 82static int smsc_nopnp;
83module_param_named(nopnp, smsc_nopnp, bool, 0);
84MODULE_PARM_DESC(nopnp, "Do not use PNP to detect controller settings");
85
86#define DMA_INVAL 255
87static int ircc_dma = DMA_INVAL;
83module_param(ircc_dma, int, 0); 88module_param(ircc_dma, int, 0);
84MODULE_PARM_DESC(ircc_dma, "DMA channel"); 89MODULE_PARM_DESC(ircc_dma, "DMA channel");
85 90
86static int ircc_irq = 255; 91#define IRQ_INVAL 255
92static int ircc_irq = IRQ_INVAL;
87module_param(ircc_irq, int, 0); 93module_param(ircc_irq, int, 0);
88MODULE_PARM_DESC(ircc_irq, "IRQ line"); 94MODULE_PARM_DESC(ircc_irq, "IRQ line");
89 95
@@ -360,7 +366,6 @@ static inline void register_bank(int iobase, int bank)
360 iobase + IRCC_MASTER); 366 iobase + IRCC_MASTER);
361} 367}
362 368
363#ifdef CONFIG_PNP
364/* PNP hotplug support */ 369/* PNP hotplug support */
365static const struct pnp_device_id smsc_ircc_pnp_table[] = { 370static const struct pnp_device_id smsc_ircc_pnp_table[] = {
366 { .id = "SMCf010", .driver_data = 0 }, 371 { .id = "SMCf010", .driver_data = 0 },
@@ -368,7 +373,35 @@ static const struct pnp_device_id smsc_ircc_pnp_table[] = {
368 { } 373 { }
369}; 374};
370MODULE_DEVICE_TABLE(pnp, smsc_ircc_pnp_table); 375MODULE_DEVICE_TABLE(pnp, smsc_ircc_pnp_table);
371#endif 376
377static int pnp_driver_registered;
378
379static int __init smsc_ircc_pnp_probe(struct pnp_dev *dev,
380 const struct pnp_device_id *dev_id)
381{
382 unsigned int firbase, sirbase;
383 u8 dma, irq;
384
385 if (!(pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) &&
386 pnp_dma_valid(dev, 0) && pnp_irq_valid(dev, 0)))
387 return -EINVAL;
388
389 sirbase = pnp_port_start(dev, 0);
390 firbase = pnp_port_start(dev, 1);
391 dma = pnp_dma(dev, 0);
392 irq = pnp_irq(dev, 0);
393
394 if (smsc_ircc_open(firbase, sirbase, dma, irq))
395 return -ENODEV;
396
397 return 0;
398}
399
400static struct pnp_driver smsc_ircc_pnp_driver = {
401 .name = "smsc-ircc2",
402 .id_table = smsc_ircc_pnp_table,
403 .probe = smsc_ircc_pnp_probe,
404};
372 405
373 406
374/******************************************************************************* 407/*******************************************************************************
@@ -379,6 +412,35 @@ MODULE_DEVICE_TABLE(pnp, smsc_ircc_pnp_table);
379 * 412 *
380 *******************************************************************************/ 413 *******************************************************************************/
381 414
415static int __init smsc_ircc_legacy_probe(void)
416{
417 int ret = 0;
418
419 if (ircc_fir > 0 && ircc_sir > 0) {
420 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
421 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
422
423 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
424 ret = -ENODEV;
425 } else {
426 ret = -ENODEV;
427
428 /* try user provided configuration register base address */
429 if (ircc_cfg > 0) {
430 IRDA_MESSAGE(" Overriding configuration address "
431 "0x%04x\n", ircc_cfg);
432 if (!smsc_superio_fdc(ircc_cfg))
433 ret = 0;
434 if (!smsc_superio_lpc(ircc_cfg))
435 ret = 0;
436 }
437
438 if (smsc_ircc_look_for_chips() > 0)
439 ret = 0;
440 }
441 return ret;
442}
443
382/* 444/*
383 * Function smsc_ircc_init () 445 * Function smsc_ircc_init ()
384 * 446 *
@@ -406,31 +468,20 @@ static int __init smsc_ircc_init(void)
406 468
407 dev_count = 0; 469 dev_count = 0;
408 470
409 if (ircc_fir > 0 && ircc_sir > 0) { 471 if (smsc_nopnp || !pnp_platform_devices ||
410 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir); 472 ircc_cfg || ircc_fir || ircc_sir ||
411 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir); 473 ircc_dma != DMA_INVAL || ircc_irq != IRQ_INVAL) {
412 474 ret = smsc_ircc_legacy_probe();
413 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
414 ret = -ENODEV;
415 } else { 475 } else {
416 ret = -ENODEV; 476 if (pnp_register_driver(&smsc_ircc_pnp_driver) == 0)
417 477 pnp_driver_registered = 1;
418 /* try user provided configuration register base address */
419 if (ircc_cfg > 0) {
420 IRDA_MESSAGE(" Overriding configuration address "
421 "0x%04x\n", ircc_cfg);
422 if (!smsc_superio_fdc(ircc_cfg))
423 ret = 0;
424 if (!smsc_superio_lpc(ircc_cfg))
425 ret = 0;
426 }
427
428 if (smsc_ircc_look_for_chips() > 0)
429 ret = 0;
430 } 478 }
431 479
432 if (ret) 480 if (ret) {
481 if (pnp_driver_registered)
482 pnp_unregister_driver(&smsc_ircc_pnp_driver);
433 platform_driver_unregister(&smsc_ircc_driver); 483 platform_driver_unregister(&smsc_ircc_driver);
484 }
434 485
435 return ret; 486 return ret;
436} 487}
@@ -646,7 +697,7 @@ static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
646 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE; 697 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
647 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED; 698 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
648 699
649 if (irq < 255) { 700 if (irq != IRQ_INVAL) {
650 if (irq != chip_irq) 701 if (irq != chip_irq)
651 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n", 702 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
652 driver_name, chip_irq, irq); 703 driver_name, chip_irq, irq);
@@ -654,7 +705,7 @@ static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
654 } else 705 } else
655 self->io.irq = chip_irq; 706 self->io.irq = chip_irq;
656 707
657 if (dma < 255) { 708 if (dma != DMA_INVAL) {
658 if (dma != chip_dma) 709 if (dma != chip_dma)
659 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n", 710 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
660 driver_name, chip_dma, dma); 711 driver_name, chip_dma, dma);
@@ -1840,6 +1891,9 @@ static void __exit smsc_ircc_cleanup(void)
1840 smsc_ircc_close(dev_self[i]); 1891 smsc_ircc_close(dev_self[i]);
1841 } 1892 }
1842 1893
1894 if (pnp_driver_registered)
1895 pnp_unregister_driver(&smsc_ircc_pnp_driver);
1896
1843 platform_driver_unregister(&smsc_ircc_driver); 1897 platform_driver_unregister(&smsc_ircc_driver);
1844} 1898}
1845 1899
@@ -2836,9 +2890,9 @@ static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
2836 tmpconf.fir_io = ircc_fir; 2890 tmpconf.fir_io = ircc_fir;
2837 if (ircc_sir != 0) 2891 if (ircc_sir != 0)
2838 tmpconf.sir_io = ircc_sir; 2892 tmpconf.sir_io = ircc_sir;
2839 if (ircc_dma != 0xff) 2893 if (ircc_dma != DMA_INVAL)
2840 tmpconf.fir_dma = ircc_dma; 2894 tmpconf.fir_dma = ircc_dma;
2841 if (ircc_irq != 0xff) 2895 if (ircc_irq != IRQ_INVAL)
2842 tmpconf.fir_irq = ircc_irq; 2896 tmpconf.fir_irq = ircc_irq;
2843 2897
2844 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name); 2898 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index c4be973867a6..bf78ef1120ad 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -44,7 +44,6 @@ MODULE_LICENSE("GPL");
44#include <linux/time.h> 44#include <linux/time.h>
45#include <linux/proc_fs.h> 45#include <linux/proc_fs.h>
46#include <linux/seq_file.h> 46#include <linux/seq_file.h>
47#include <linux/smp_lock.h>
48#include <asm/uaccess.h> 47#include <asm/uaccess.h>
49#include <asm/byteorder.h> 48#include <asm/byteorder.h>
50 49
diff --git a/drivers/net/ixgb/ixgb.h b/drivers/net/ixgb/ixgb.h
index c8e90861f869..3569d5b03388 100644
--- a/drivers/net/ixgb/ixgb.h
+++ b/drivers/net/ixgb/ixgb.h
@@ -193,8 +193,6 @@ struct ixgb_adapter {
193 u16 msg_enable; 193 u16 msg_enable;
194 struct ixgb_hw_stats stats; 194 struct ixgb_hw_stats stats;
195 uint32_t alloc_rx_buff_failed; 195 uint32_t alloc_rx_buff_failed;
196#ifdef CONFIG_PCI_MSI
197 boolean_t have_msi; 196 boolean_t have_msi;
198#endif
199}; 197};
200#endif /* _IXGB_H_ */ 198#endif /* _IXGB_H_ */
diff --git a/drivers/net/ixgb/ixgb_ee.c b/drivers/net/ixgb/ixgb_ee.c
index f15aebde7b90..52c99d01d568 100644
--- a/drivers/net/ixgb/ixgb_ee.c
+++ b/drivers/net/ixgb/ixgb_ee.c
@@ -315,7 +315,7 @@ ixgb_wait_eeprom_command(struct ixgb_hw *hw)
315 * hw - Struct containing variables accessed by shared code 315 * hw - Struct containing variables accessed by shared code
316 * 316 *
317 * Reads the first 64 16 bit words of the EEPROM and sums the values read. 317 * Reads the first 64 16 bit words of the EEPROM and sums the values read.
318 * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is 318 * If the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
319 * valid. 319 * valid.
320 * 320 *
321 * Returns: 321 * Returns:
diff --git a/drivers/net/ixgb/ixgb_main.c b/drivers/net/ixgb/ixgb_main.c
index 6d2b059371f1..991c8833e23c 100644
--- a/drivers/net/ixgb/ixgb_main.c
+++ b/drivers/net/ixgb/ixgb_main.c
@@ -227,7 +227,7 @@ int
227ixgb_up(struct ixgb_adapter *adapter) 227ixgb_up(struct ixgb_adapter *adapter)
228{ 228{
229 struct net_device *netdev = adapter->netdev; 229 struct net_device *netdev = adapter->netdev;
230 int err; 230 int err, irq_flags = IRQF_SHARED;
231 int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH; 231 int max_frame = netdev->mtu + ENET_HEADER_SIZE + ENET_FCS_LENGTH;
232 struct ixgb_hw *hw = &adapter->hw; 232 struct ixgb_hw *hw = &adapter->hw;
233 233
@@ -246,26 +246,21 @@ ixgb_up(struct ixgb_adapter *adapter)
246 /* disable interrupts and get the hardware into a known state */ 246 /* disable interrupts and get the hardware into a known state */
247 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff); 247 IXGB_WRITE_REG(&adapter->hw, IMC, 0xffffffff);
248 248
249#ifdef CONFIG_PCI_MSI 249 /* only enable MSI if bus is in PCI-X mode */
250 { 250 if (IXGB_READ_REG(&adapter->hw, STATUS) & IXGB_STATUS_PCIX_MODE) {
251 boolean_t pcix = (IXGB_READ_REG(&adapter->hw, STATUS) & 251 err = pci_enable_msi(adapter->pdev);
252 IXGB_STATUS_PCIX_MODE) ? TRUE : FALSE; 252 if (!err) {
253 adapter->have_msi = TRUE; 253 adapter->have_msi = 1;
254 254 irq_flags = 0;
255 if (!pcix) 255 }
256 adapter->have_msi = FALSE;
257 else if((err = pci_enable_msi(adapter->pdev))) {
258 DPRINTK(PROBE, ERR,
259 "Unable to allocate MSI interrupt Error: %d\n", err);
260 adapter->have_msi = FALSE;
261 /* proceed to try to request regular interrupt */ 256 /* proceed to try to request regular interrupt */
262 } 257 }
263 }
264 258
265#endif 259 err = request_irq(adapter->pdev->irq, &ixgb_intr, irq_flags,
266 if((err = request_irq(adapter->pdev->irq, &ixgb_intr, 260 netdev->name, netdev);
267 IRQF_SHARED | IRQF_SAMPLE_RANDOM, 261 if (err) {
268 netdev->name, netdev))) { 262 if (adapter->have_msi)
263 pci_disable_msi(adapter->pdev);
269 DPRINTK(PROBE, ERR, 264 DPRINTK(PROBE, ERR,
270 "Unable to allocate interrupt Error: %d\n", err); 265 "Unable to allocate interrupt Error: %d\n", err);
271 return err; 266 return err;
@@ -307,11 +302,10 @@ ixgb_down(struct ixgb_adapter *adapter, boolean_t kill_watchdog)
307 302
308 ixgb_irq_disable(adapter); 303 ixgb_irq_disable(adapter);
309 free_irq(adapter->pdev->irq, netdev); 304 free_irq(adapter->pdev->irq, netdev);
310#ifdef CONFIG_PCI_MSI 305
311 if(adapter->have_msi == TRUE) 306 if (adapter->have_msi)
312 pci_disable_msi(adapter->pdev); 307 pci_disable_msi(adapter->pdev);
313 308
314#endif
315 if(kill_watchdog) 309 if(kill_watchdog)
316 del_timer_sync(&adapter->watchdog_timer); 310 del_timer_sync(&adapter->watchdog_timer);
317#ifdef CONFIG_IXGB_NAPI 311#ifdef CONFIG_IXGB_NAPI
diff --git a/drivers/net/mace.c b/drivers/net/mace.c
index b3bd62394958..52b9332810c5 100644
--- a/drivers/net/mace.c
+++ b/drivers/net/mace.c
@@ -110,9 +110,9 @@ static int __devinit mace_probe(struct macio_dev *mdev, const struct of_device_i
110 return -ENODEV; 110 return -ENODEV;
111 } 111 }
112 112
113 addr = get_property(mace, "mac-address", NULL); 113 addr = of_get_property(mace, "mac-address", NULL);
114 if (addr == NULL) { 114 if (addr == NULL) {
115 addr = get_property(mace, "local-mac-address", NULL); 115 addr = of_get_property(mace, "local-mac-address", NULL);
116 if (addr == NULL) { 116 if (addr == NULL) {
117 printk(KERN_ERR "Can't get mac-address for MACE %s\n", 117 printk(KERN_ERR "Can't get mac-address for MACE %s\n",
118 mace->full_name); 118 mace->full_name);
diff --git a/drivers/net/meth.h b/drivers/net/meth.h
index 84960dae2a22..ea3b8fc86d1e 100644
--- a/drivers/net/meth.h
+++ b/drivers/net/meth.h
@@ -126,7 +126,7 @@ typedef struct rx_packet {
126 /* Note: when loopback is set this bit becomes collision control. Setting this bit will */ 126 /* Note: when loopback is set this bit becomes collision control. Setting this bit will */
127 /* cause a collision to be reported. */ 127 /* cause a collision to be reported. */
128 128
129 /* Bits 5 and 6 are used to determine the the Destination address filter mode */ 129 /* Bits 5 and 6 are used to determine the Destination address filter mode */
130#define METH_ACCEPT_MY 0 /* 00: Accept PHY address only */ 130#define METH_ACCEPT_MY 0 /* 00: Accept PHY address only */
131#define METH_ACCEPT_MCAST 0x20 /* 01: Accept physical, broadcast, and multicast filter matches only */ 131#define METH_ACCEPT_MCAST 0x20 /* 01: Accept physical, broadcast, and multicast filter matches only */
132#define METH_ACCEPT_AMCAST 0x40 /* 10: Accept physical, broadcast, and all multicast packets */ 132#define METH_ACCEPT_AMCAST 0x40 /* 10: Accept physical, broadcast, and all multicast packets */
diff --git a/drivers/net/mlx4/Makefile b/drivers/net/mlx4/Makefile
new file mode 100644
index 000000000000..0952a6528f58
--- /dev/null
+++ b/drivers/net/mlx4/Makefile
@@ -0,0 +1,4 @@
1obj-$(CONFIG_MLX4_CORE) += mlx4_core.o
2
3mlx4_core-y := alloc.o catas.o cmd.o cq.o eq.o fw.o icm.o intf.o main.o mcg.o \
4 mr.o pd.o profile.o qp.o reset.o srq.o
diff --git a/drivers/net/mlx4/alloc.c b/drivers/net/mlx4/alloc.c
new file mode 100644
index 000000000000..dfbd5809d744
--- /dev/null
+++ b/drivers/net/mlx4/alloc.c
@@ -0,0 +1,180 @@
1/*
2 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/errno.h>
34#include <linux/slab.h>
35#include <linux/bitmap.h>
36#include <linux/dma-mapping.h>
37
38#include "mlx4.h"
39
40u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap)
41{
42 u32 obj;
43
44 spin_lock(&bitmap->lock);
45
46 obj = find_next_zero_bit(bitmap->table, bitmap->max, bitmap->last);
47 if (obj >= bitmap->max) {
48 bitmap->top = (bitmap->top + bitmap->max) & bitmap->mask;
49 obj = find_first_zero_bit(bitmap->table, bitmap->max);
50 }
51
52 if (obj < bitmap->max) {
53 set_bit(obj, bitmap->table);
54 obj |= bitmap->top;
55 bitmap->last = obj + 1;
56 } else
57 obj = -1;
58
59 spin_unlock(&bitmap->lock);
60
61 return obj;
62}
63
64void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj)
65{
66 obj &= bitmap->max - 1;
67
68 spin_lock(&bitmap->lock);
69 clear_bit(obj, bitmap->table);
70 bitmap->last = min(bitmap->last, obj);
71 bitmap->top = (bitmap->top + bitmap->max) & bitmap->mask;
72 spin_unlock(&bitmap->lock);
73}
74
75int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, u32 reserved)
76{
77 int i;
78
79 /* num must be a power of 2 */
80 if (num != roundup_pow_of_two(num))
81 return -EINVAL;
82
83 bitmap->last = 0;
84 bitmap->top = 0;
85 bitmap->max = num;
86 bitmap->mask = mask;
87 spin_lock_init(&bitmap->lock);
88 bitmap->table = kzalloc(BITS_TO_LONGS(num) * sizeof (long), GFP_KERNEL);
89 if (!bitmap->table)
90 return -ENOMEM;
91
92 for (i = 0; i < reserved; ++i)
93 set_bit(i, bitmap->table);
94
95 return 0;
96}
97
98void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap)
99{
100 kfree(bitmap->table);
101}
102
103/*
104 * Handling for queue buffers -- we allocate a bunch of memory and
105 * register it in a memory region at HCA virtual address 0. If the
106 * requested size is > max_direct, we split the allocation into
107 * multiple pages, so we don't require too much contiguous memory.
108 */
109
110int mlx4_buf_alloc(struct mlx4_dev *dev, int size, int max_direct,
111 struct mlx4_buf *buf)
112{
113 dma_addr_t t;
114
115 if (size <= max_direct) {
116 buf->nbufs = 1;
117 buf->npages = 1;
118 buf->page_shift = get_order(size) + PAGE_SHIFT;
119 buf->u.direct.buf = dma_alloc_coherent(&dev->pdev->dev,
120 size, &t, GFP_KERNEL);
121 if (!buf->u.direct.buf)
122 return -ENOMEM;
123
124 buf->u.direct.map = t;
125
126 while (t & ((1 << buf->page_shift) - 1)) {
127 --buf->page_shift;
128 buf->npages *= 2;
129 }
130
131 memset(buf->u.direct.buf, 0, size);
132 } else {
133 int i;
134
135 buf->nbufs = (size + PAGE_SIZE - 1) / PAGE_SIZE;
136 buf->npages = buf->nbufs;
137 buf->page_shift = PAGE_SHIFT;
138 buf->u.page_list = kzalloc(buf->nbufs * sizeof *buf->u.page_list,
139 GFP_KERNEL);
140 if (!buf->u.page_list)
141 return -ENOMEM;
142
143 for (i = 0; i < buf->nbufs; ++i) {
144 buf->u.page_list[i].buf =
145 dma_alloc_coherent(&dev->pdev->dev, PAGE_SIZE,
146 &t, GFP_KERNEL);
147 if (!buf->u.page_list[i].buf)
148 goto err_free;
149
150 buf->u.page_list[i].map = t;
151
152 memset(buf->u.page_list[i].buf, 0, PAGE_SIZE);
153 }
154 }
155
156 return 0;
157
158err_free:
159 mlx4_buf_free(dev, size, buf);
160
161 return -ENOMEM;
162}
163EXPORT_SYMBOL_GPL(mlx4_buf_alloc);
164
165void mlx4_buf_free(struct mlx4_dev *dev, int size, struct mlx4_buf *buf)
166{
167 int i;
168
169 if (buf->nbufs == 1)
170 dma_free_coherent(&dev->pdev->dev, size, buf->u.direct.buf,
171 buf->u.direct.map);
172 else {
173 for (i = 0; i < buf->nbufs; ++i)
174 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
175 buf->u.page_list[i].buf,
176 buf->u.page_list[i].map);
177 kfree(buf->u.page_list);
178 }
179}
180EXPORT_SYMBOL_GPL(mlx4_buf_free);
diff --git a/drivers/net/mlx4/catas.c b/drivers/net/mlx4/catas.c
new file mode 100644
index 000000000000..1bb088aeaf71
--- /dev/null
+++ b/drivers/net/mlx4/catas.c
@@ -0,0 +1,70 @@
1/*
2 * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include "mlx4.h"
34
35void mlx4_handle_catas_err(struct mlx4_dev *dev)
36{
37 struct mlx4_priv *priv = mlx4_priv(dev);
38
39 int i;
40
41 mlx4_err(dev, "Catastrophic error detected:\n");
42 for (i = 0; i < priv->fw.catas_size; ++i)
43 mlx4_err(dev, " buf[%02x]: %08x\n",
44 i, swab32(readl(priv->catas_err.map + i)));
45
46 mlx4_dispatch_event(dev, MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR, 0, 0);
47}
48
49void mlx4_map_catas_buf(struct mlx4_dev *dev)
50{
51 struct mlx4_priv *priv = mlx4_priv(dev);
52 unsigned long addr;
53
54 addr = pci_resource_start(dev->pdev, priv->fw.catas_bar) +
55 priv->fw.catas_offset;
56
57 priv->catas_err.map = ioremap(addr, priv->fw.catas_size * 4);
58 if (!priv->catas_err.map)
59 mlx4_warn(dev, "Failed to map catastrophic error buffer at 0x%lx\n",
60 addr);
61
62}
63
64void mlx4_unmap_catas_buf(struct mlx4_dev *dev)
65{
66 struct mlx4_priv *priv = mlx4_priv(dev);
67
68 if (priv->catas_err.map)
69 iounmap(priv->catas_err.map);
70}
diff --git a/drivers/net/mlx4/cmd.c b/drivers/net/mlx4/cmd.c
new file mode 100644
index 000000000000..c1f81a993f5d
--- /dev/null
+++ b/drivers/net/mlx4/cmd.c
@@ -0,0 +1,429 @@
1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#include <linux/sched.h>
36#include <linux/pci.h>
37#include <linux/errno.h>
38
39#include <linux/mlx4/cmd.h>
40
41#include <asm/io.h>
42
43#include "mlx4.h"
44
45#define CMD_POLL_TOKEN 0xffff
46
47enum {
48 /* command completed successfully: */
49 CMD_STAT_OK = 0x00,
50 /* Internal error (such as a bus error) occurred while processing command: */
51 CMD_STAT_INTERNAL_ERR = 0x01,
52 /* Operation/command not supported or opcode modifier not supported: */
53 CMD_STAT_BAD_OP = 0x02,
54 /* Parameter not supported or parameter out of range: */
55 CMD_STAT_BAD_PARAM = 0x03,
56 /* System not enabled or bad system state: */
57 CMD_STAT_BAD_SYS_STATE = 0x04,
58 /* Attempt to access reserved or unallocaterd resource: */
59 CMD_STAT_BAD_RESOURCE = 0x05,
60 /* Requested resource is currently executing a command, or is otherwise busy: */
61 CMD_STAT_RESOURCE_BUSY = 0x06,
62 /* Required capability exceeds device limits: */
63 CMD_STAT_EXCEED_LIM = 0x08,
64 /* Resource is not in the appropriate state or ownership: */
65 CMD_STAT_BAD_RES_STATE = 0x09,
66 /* Index out of range: */
67 CMD_STAT_BAD_INDEX = 0x0a,
68 /* FW image corrupted: */
69 CMD_STAT_BAD_NVMEM = 0x0b,
70 /* Attempt to modify a QP/EE which is not in the presumed state: */
71 CMD_STAT_BAD_QP_STATE = 0x10,
72 /* Bad segment parameters (Address/Size): */
73 CMD_STAT_BAD_SEG_PARAM = 0x20,
74 /* Memory Region has Memory Windows bound to: */
75 CMD_STAT_REG_BOUND = 0x21,
76 /* HCA local attached memory not present: */
77 CMD_STAT_LAM_NOT_PRE = 0x22,
78 /* Bad management packet (silently discarded): */
79 CMD_STAT_BAD_PKT = 0x30,
80 /* More outstanding CQEs in CQ than new CQ size: */
81 CMD_STAT_BAD_SIZE = 0x40
82};
83
84enum {
85 HCR_IN_PARAM_OFFSET = 0x00,
86 HCR_IN_MODIFIER_OFFSET = 0x08,
87 HCR_OUT_PARAM_OFFSET = 0x0c,
88 HCR_TOKEN_OFFSET = 0x14,
89 HCR_STATUS_OFFSET = 0x18,
90
91 HCR_OPMOD_SHIFT = 12,
92 HCR_T_BIT = 21,
93 HCR_E_BIT = 22,
94 HCR_GO_BIT = 23
95};
96
97enum {
98 GO_BIT_TIMEOUT = 10000
99};
100
101struct mlx4_cmd_context {
102 struct completion done;
103 int result;
104 int next;
105 u64 out_param;
106 u16 token;
107};
108
109static int mlx4_status_to_errno(u8 status) {
110 static const int trans_table[] = {
111 [CMD_STAT_INTERNAL_ERR] = -EIO,
112 [CMD_STAT_BAD_OP] = -EPERM,
113 [CMD_STAT_BAD_PARAM] = -EINVAL,
114 [CMD_STAT_BAD_SYS_STATE] = -ENXIO,
115 [CMD_STAT_BAD_RESOURCE] = -EBADF,
116 [CMD_STAT_RESOURCE_BUSY] = -EBUSY,
117 [CMD_STAT_EXCEED_LIM] = -ENOMEM,
118 [CMD_STAT_BAD_RES_STATE] = -EBADF,
119 [CMD_STAT_BAD_INDEX] = -EBADF,
120 [CMD_STAT_BAD_NVMEM] = -EFAULT,
121 [CMD_STAT_BAD_QP_STATE] = -EINVAL,
122 [CMD_STAT_BAD_SEG_PARAM] = -EFAULT,
123 [CMD_STAT_REG_BOUND] = -EBUSY,
124 [CMD_STAT_LAM_NOT_PRE] = -EAGAIN,
125 [CMD_STAT_BAD_PKT] = -EINVAL,
126 [CMD_STAT_BAD_SIZE] = -ENOMEM,
127 };
128
129 if (status >= ARRAY_SIZE(trans_table) ||
130 (status != CMD_STAT_OK && trans_table[status] == 0))
131 return -EIO;
132
133 return trans_table[status];
134}
135
136static int cmd_pending(struct mlx4_dev *dev)
137{
138 u32 status = readl(mlx4_priv(dev)->cmd.hcr + HCR_STATUS_OFFSET);
139
140 return (status & swab32(1 << HCR_GO_BIT)) ||
141 (mlx4_priv(dev)->cmd.toggle ==
142 !!(status & swab32(1 << HCR_T_BIT)));
143}
144
145static int mlx4_cmd_post(struct mlx4_dev *dev, u64 in_param, u64 out_param,
146 u32 in_modifier, u8 op_modifier, u16 op, u16 token,
147 int event)
148{
149 struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
150 u32 __iomem *hcr = cmd->hcr;
151 int ret = -EAGAIN;
152 unsigned long end;
153
154 mutex_lock(&cmd->hcr_mutex);
155
156 end = jiffies;
157 if (event)
158 end += HZ * 10;
159
160 while (cmd_pending(dev)) {
161 if (time_after_eq(jiffies, end))
162 goto out;
163 cond_resched();
164 }
165
166 /*
167 * We use writel (instead of something like memcpy_toio)
168 * because writes of less than 32 bits to the HCR don't work
169 * (and some architectures such as ia64 implement memcpy_toio
170 * in terms of writeb).
171 */
172 __raw_writel((__force u32) cpu_to_be32(in_param >> 32), hcr + 0);
173 __raw_writel((__force u32) cpu_to_be32(in_param & 0xfffffffful), hcr + 1);
174 __raw_writel((__force u32) cpu_to_be32(in_modifier), hcr + 2);
175 __raw_writel((__force u32) cpu_to_be32(out_param >> 32), hcr + 3);
176 __raw_writel((__force u32) cpu_to_be32(out_param & 0xfffffffful), hcr + 4);
177 __raw_writel((__force u32) cpu_to_be32(token << 16), hcr + 5);
178
179 /* __raw_writel may not order writes. */
180 wmb();
181
182 __raw_writel((__force u32) cpu_to_be32((1 << HCR_GO_BIT) |
183 (cmd->toggle << HCR_T_BIT) |
184 (event ? (1 << HCR_E_BIT) : 0) |
185 (op_modifier << HCR_OPMOD_SHIFT) |
186 op), hcr + 6);
187 cmd->toggle = cmd->toggle ^ 1;
188
189 ret = 0;
190
191out:
192 mutex_unlock(&cmd->hcr_mutex);
193 return ret;
194}
195
196static int mlx4_cmd_poll(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
197 int out_is_imm, u32 in_modifier, u8 op_modifier,
198 u16 op, unsigned long timeout)
199{
200 struct mlx4_priv *priv = mlx4_priv(dev);
201 void __iomem *hcr = priv->cmd.hcr;
202 int err = 0;
203 unsigned long end;
204
205 down(&priv->cmd.poll_sem);
206
207 err = mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0,
208 in_modifier, op_modifier, op, CMD_POLL_TOKEN, 0);
209 if (err)
210 goto out;
211
212 end = msecs_to_jiffies(timeout) + jiffies;
213 while (cmd_pending(dev) && time_before(jiffies, end))
214 cond_resched();
215
216 if (cmd_pending(dev)) {
217 err = -ETIMEDOUT;
218 goto out;
219 }
220
221 if (out_is_imm)
222 *out_param =
223 (u64) be32_to_cpu((__force __be32)
224 __raw_readl(hcr + HCR_OUT_PARAM_OFFSET)) << 32 |
225 (u64) be32_to_cpu((__force __be32)
226 __raw_readl(hcr + HCR_OUT_PARAM_OFFSET + 4));
227
228 err = mlx4_status_to_errno(be32_to_cpu((__force __be32)
229 __raw_readl(hcr + HCR_STATUS_OFFSET)) >> 24);
230
231out:
232 up(&priv->cmd.poll_sem);
233 return err;
234}
235
236void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param)
237{
238 struct mlx4_priv *priv = mlx4_priv(dev);
239 struct mlx4_cmd_context *context =
240 &priv->cmd.context[token & priv->cmd.token_mask];
241
242 /* previously timed out command completing at long last */
243 if (token != context->token)
244 return;
245
246 context->result = mlx4_status_to_errno(status);
247 context->out_param = out_param;
248
249 context->token += priv->cmd.token_mask + 1;
250
251 complete(&context->done);
252}
253
254static int mlx4_cmd_wait(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
255 int out_is_imm, u32 in_modifier, u8 op_modifier,
256 u16 op, unsigned long timeout)
257{
258 struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
259 struct mlx4_cmd_context *context;
260 int err = 0;
261
262 down(&cmd->event_sem);
263
264 spin_lock(&cmd->context_lock);
265 BUG_ON(cmd->free_head < 0);
266 context = &cmd->context[cmd->free_head];
267 cmd->free_head = context->next;
268 spin_unlock(&cmd->context_lock);
269
270 init_completion(&context->done);
271
272 mlx4_cmd_post(dev, in_param, out_param ? *out_param : 0,
273 in_modifier, op_modifier, op, context->token, 1);
274
275 if (!wait_for_completion_timeout(&context->done, msecs_to_jiffies(timeout))) {
276 err = -EBUSY;
277 goto out;
278 }
279
280 err = context->result;
281 if (err)
282 goto out;
283
284 if (out_is_imm)
285 *out_param = context->out_param;
286
287out:
288 spin_lock(&cmd->context_lock);
289 context->next = cmd->free_head;
290 cmd->free_head = context - cmd->context;
291 spin_unlock(&cmd->context_lock);
292
293 up(&cmd->event_sem);
294 return err;
295}
296
297int __mlx4_cmd(struct mlx4_dev *dev, u64 in_param, u64 *out_param,
298 int out_is_imm, u32 in_modifier, u8 op_modifier,
299 u16 op, unsigned long timeout)
300{
301 if (mlx4_priv(dev)->cmd.use_events)
302 return mlx4_cmd_wait(dev, in_param, out_param, out_is_imm,
303 in_modifier, op_modifier, op, timeout);
304 else
305 return mlx4_cmd_poll(dev, in_param, out_param, out_is_imm,
306 in_modifier, op_modifier, op, timeout);
307}
308EXPORT_SYMBOL_GPL(__mlx4_cmd);
309
310int mlx4_cmd_init(struct mlx4_dev *dev)
311{
312 struct mlx4_priv *priv = mlx4_priv(dev);
313
314 mutex_init(&priv->cmd.hcr_mutex);
315 sema_init(&priv->cmd.poll_sem, 1);
316 priv->cmd.use_events = 0;
317 priv->cmd.toggle = 1;
318
319 priv->cmd.hcr = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_HCR_BASE,
320 MLX4_HCR_SIZE);
321 if (!priv->cmd.hcr) {
322 mlx4_err(dev, "Couldn't map command register.");
323 return -ENOMEM;
324 }
325
326 priv->cmd.pool = pci_pool_create("mlx4_cmd", dev->pdev,
327 MLX4_MAILBOX_SIZE,
328 MLX4_MAILBOX_SIZE, 0);
329 if (!priv->cmd.pool) {
330 iounmap(priv->cmd.hcr);
331 return -ENOMEM;
332 }
333
334 return 0;
335}
336
337void mlx4_cmd_cleanup(struct mlx4_dev *dev)
338{
339 struct mlx4_priv *priv = mlx4_priv(dev);
340
341 pci_pool_destroy(priv->cmd.pool);
342 iounmap(priv->cmd.hcr);
343}
344
345/*
346 * Switch to using events to issue FW commands (can only be called
347 * after event queue for command events has been initialized).
348 */
349int mlx4_cmd_use_events(struct mlx4_dev *dev)
350{
351 struct mlx4_priv *priv = mlx4_priv(dev);
352 int i;
353
354 priv->cmd.context = kmalloc(priv->cmd.max_cmds *
355 sizeof (struct mlx4_cmd_context),
356 GFP_KERNEL);
357 if (!priv->cmd.context)
358 return -ENOMEM;
359
360 for (i = 0; i < priv->cmd.max_cmds; ++i) {
361 priv->cmd.context[i].token = i;
362 priv->cmd.context[i].next = i + 1;
363 }
364
365 priv->cmd.context[priv->cmd.max_cmds - 1].next = -1;
366 priv->cmd.free_head = 0;
367
368 sema_init(&priv->cmd.event_sem, priv->cmd.max_cmds);
369 spin_lock_init(&priv->cmd.context_lock);
370
371 for (priv->cmd.token_mask = 1;
372 priv->cmd.token_mask < priv->cmd.max_cmds;
373 priv->cmd.token_mask <<= 1)
374 ; /* nothing */
375 --priv->cmd.token_mask;
376
377 priv->cmd.use_events = 1;
378
379 down(&priv->cmd.poll_sem);
380
381 return 0;
382}
383
384/*
385 * Switch back to polling (used when shutting down the device)
386 */
387void mlx4_cmd_use_polling(struct mlx4_dev *dev)
388{
389 struct mlx4_priv *priv = mlx4_priv(dev);
390 int i;
391
392 priv->cmd.use_events = 0;
393
394 for (i = 0; i < priv->cmd.max_cmds; ++i)
395 down(&priv->cmd.event_sem);
396
397 kfree(priv->cmd.context);
398
399 up(&priv->cmd.poll_sem);
400}
401
402struct mlx4_cmd_mailbox *mlx4_alloc_cmd_mailbox(struct mlx4_dev *dev)
403{
404 struct mlx4_cmd_mailbox *mailbox;
405
406 mailbox = kmalloc(sizeof *mailbox, GFP_KERNEL);
407 if (!mailbox)
408 return ERR_PTR(-ENOMEM);
409
410 mailbox->buf = pci_pool_alloc(mlx4_priv(dev)->cmd.pool, GFP_KERNEL,
411 &mailbox->dma);
412 if (!mailbox->buf) {
413 kfree(mailbox);
414 return ERR_PTR(-ENOMEM);
415 }
416
417 return mailbox;
418}
419EXPORT_SYMBOL_GPL(mlx4_alloc_cmd_mailbox);
420
421void mlx4_free_cmd_mailbox(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox)
422{
423 if (!mailbox)
424 return;
425
426 pci_pool_free(mlx4_priv(dev)->cmd.pool, mailbox->buf, mailbox->dma);
427 kfree(mailbox);
428}
429EXPORT_SYMBOL_GPL(mlx4_free_cmd_mailbox);
diff --git a/drivers/net/mlx4/cq.c b/drivers/net/mlx4/cq.c
new file mode 100644
index 000000000000..437d78ad0912
--- /dev/null
+++ b/drivers/net/mlx4/cq.c
@@ -0,0 +1,254 @@
1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
7 *
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * OpenIB.org BSD license below:
13 *
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
16 * conditions are met:
17 *
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer.
21 *
22 * - Redistributions in binary form must reproduce the above
23 * copyright notice, this list of conditions and the following
24 * disclaimer in the documentation and/or other materials
25 * provided with the distribution.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE.
35 */
36
37#include <linux/init.h>
38#include <linux/hardirq.h>
39
40#include <linux/mlx4/cmd.h>
41
42#include "mlx4.h"
43#include "icm.h"
44
45struct mlx4_cq_context {
46 __be32 flags;
47 u16 reserved1[3];
48 __be16 page_offset;
49 __be32 logsize_usrpage;
50 u8 reserved2;
51 u8 cq_period;
52 u8 reserved3;
53 u8 cq_max_count;
54 u8 reserved4[3];
55 u8 comp_eqn;
56 u8 log_page_size;
57 u8 reserved5[2];
58 u8 mtt_base_addr_h;
59 __be32 mtt_base_addr_l;
60 __be32 last_notified_index;
61 __be32 solicit_producer_index;
62 __be32 consumer_index;
63 __be32 producer_index;
64 u8 reserved6[2];
65 __be64 db_rec_addr;
66};
67
68#define MLX4_CQ_STATUS_OK ( 0 << 28)
69#define MLX4_CQ_STATUS_OVERFLOW ( 9 << 28)
70#define MLX4_CQ_STATUS_WRITE_FAIL (10 << 28)
71#define MLX4_CQ_FLAG_CC ( 1 << 18)
72#define MLX4_CQ_FLAG_OI ( 1 << 17)
73#define MLX4_CQ_STATE_ARMED ( 9 << 8)
74#define MLX4_CQ_STATE_ARMED_SOL ( 6 << 8)
75#define MLX4_EQ_STATE_FIRED (10 << 8)
76
77void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn)
78{
79 struct mlx4_cq *cq;
80
81 cq = radix_tree_lookup(&mlx4_priv(dev)->cq_table.tree,
82 cqn & (dev->caps.num_cqs - 1));
83 if (!cq) {
84 mlx4_warn(dev, "Completion event for bogus CQ %08x\n", cqn);
85 return;
86 }
87
88 ++cq->arm_sn;
89
90 cq->comp(cq);
91}
92
93void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type)
94{
95 struct mlx4_cq_table *cq_table = &mlx4_priv(dev)->cq_table;
96 struct mlx4_cq *cq;
97
98 spin_lock(&cq_table->lock);
99
100 cq = radix_tree_lookup(&cq_table->tree, cqn & (dev->caps.num_cqs - 1));
101 if (cq)
102 atomic_inc(&cq->refcount);
103
104 spin_unlock(&cq_table->lock);
105
106 if (!cq) {
107 mlx4_warn(dev, "Async event for bogus CQ %08x\n", cqn);
108 return;
109 }
110
111 cq->event(cq, event_type);
112
113 if (atomic_dec_and_test(&cq->refcount))
114 complete(&cq->free);
115}
116
117static int mlx4_SW2HW_CQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
118 int cq_num)
119{
120 return mlx4_cmd(dev, mailbox->dma, cq_num, 0, MLX4_CMD_SW2HW_CQ,
121 MLX4_CMD_TIME_CLASS_A);
122}
123
124static int mlx4_HW2SW_CQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
125 int cq_num)
126{
127 return mlx4_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, cq_num,
128 mailbox ? 0 : 1, MLX4_CMD_HW2SW_CQ,
129 MLX4_CMD_TIME_CLASS_A);
130}
131
132int mlx4_cq_alloc(struct mlx4_dev *dev, int nent, struct mlx4_mtt *mtt,
133 struct mlx4_uar *uar, u64 db_rec, struct mlx4_cq *cq)
134{
135 struct mlx4_priv *priv = mlx4_priv(dev);
136 struct mlx4_cq_table *cq_table = &priv->cq_table;
137 struct mlx4_cmd_mailbox *mailbox;
138 struct mlx4_cq_context *cq_context;
139 u64 mtt_addr;
140 int err;
141
142 cq->cqn = mlx4_bitmap_alloc(&cq_table->bitmap);
143 if (cq->cqn == -1)
144 return -ENOMEM;
145
146 err = mlx4_table_get(dev, &cq_table->table, cq->cqn);
147 if (err)
148 goto err_out;
149
150 err = mlx4_table_get(dev, &cq_table->cmpt_table, cq->cqn);
151 if (err)
152 goto err_put;
153
154 spin_lock_irq(&cq_table->lock);
155 err = radix_tree_insert(&cq_table->tree, cq->cqn, cq);
156 spin_unlock_irq(&cq_table->lock);
157 if (err)
158 goto err_cmpt_put;
159
160 mailbox = mlx4_alloc_cmd_mailbox(dev);
161 if (IS_ERR(mailbox)) {
162 err = PTR_ERR(mailbox);
163 goto err_radix;
164 }
165
166 cq_context = mailbox->buf;
167 memset(cq_context, 0, sizeof *cq_context);
168
169 cq_context->logsize_usrpage = cpu_to_be32((ilog2(nent) << 24) | uar->index);
170 cq_context->comp_eqn = priv->eq_table.eq[MLX4_EQ_COMP].eqn;
171 cq_context->log_page_size = mtt->page_shift - MLX4_ICM_PAGE_SHIFT;
172
173 mtt_addr = mlx4_mtt_addr(dev, mtt);
174 cq_context->mtt_base_addr_h = mtt_addr >> 32;
175 cq_context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
176 cq_context->db_rec_addr = cpu_to_be64(db_rec);
177
178 err = mlx4_SW2HW_CQ(dev, mailbox, cq->cqn);
179 mlx4_free_cmd_mailbox(dev, mailbox);
180 if (err)
181 goto err_radix;
182
183 cq->cons_index = 0;
184 cq->arm_sn = 1;
185 cq->uar = uar;
186 atomic_set(&cq->refcount, 1);
187 init_completion(&cq->free);
188
189 return 0;
190
191err_radix:
192 spin_lock_irq(&cq_table->lock);
193 radix_tree_delete(&cq_table->tree, cq->cqn);
194 spin_unlock_irq(&cq_table->lock);
195
196err_cmpt_put:
197 mlx4_table_put(dev, &cq_table->cmpt_table, cq->cqn);
198
199err_put:
200 mlx4_table_put(dev, &cq_table->table, cq->cqn);
201
202err_out:
203 mlx4_bitmap_free(&cq_table->bitmap, cq->cqn);
204
205 return err;
206}
207EXPORT_SYMBOL_GPL(mlx4_cq_alloc);
208
209void mlx4_cq_free(struct mlx4_dev *dev, struct mlx4_cq *cq)
210{
211 struct mlx4_priv *priv = mlx4_priv(dev);
212 struct mlx4_cq_table *cq_table = &priv->cq_table;
213 int err;
214
215 err = mlx4_HW2SW_CQ(dev, NULL, cq->cqn);
216 if (err)
217 mlx4_warn(dev, "HW2SW_CQ failed (%d) for CQN %06x\n", err, cq->cqn);
218
219 synchronize_irq(priv->eq_table.eq[MLX4_EQ_COMP].irq);
220
221 spin_lock_irq(&cq_table->lock);
222 radix_tree_delete(&cq_table->tree, cq->cqn);
223 spin_unlock_irq(&cq_table->lock);
224
225 if (atomic_dec_and_test(&cq->refcount))
226 complete(&cq->free);
227 wait_for_completion(&cq->free);
228
229 mlx4_table_put(dev, &cq_table->table, cq->cqn);
230 mlx4_bitmap_free(&cq_table->bitmap, cq->cqn);
231}
232EXPORT_SYMBOL_GPL(mlx4_cq_free);
233
234int __devinit mlx4_init_cq_table(struct mlx4_dev *dev)
235{
236 struct mlx4_cq_table *cq_table = &mlx4_priv(dev)->cq_table;
237 int err;
238
239 spin_lock_init(&cq_table->lock);
240 INIT_RADIX_TREE(&cq_table->tree, GFP_ATOMIC);
241
242 err = mlx4_bitmap_init(&cq_table->bitmap, dev->caps.num_cqs,
243 dev->caps.num_cqs - 1, dev->caps.reserved_cqs);
244 if (err)
245 return err;
246
247 return 0;
248}
249
250void mlx4_cleanup_cq_table(struct mlx4_dev *dev)
251{
252 /* Nothing to do to clean up radix_tree */
253 mlx4_bitmap_cleanup(&mlx4_priv(dev)->cq_table.bitmap);
254}
diff --git a/drivers/net/mlx4/eq.c b/drivers/net/mlx4/eq.c
new file mode 100644
index 000000000000..0f11adb8eb4a
--- /dev/null
+++ b/drivers/net/mlx4/eq.c
@@ -0,0 +1,697 @@
1/*
2 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
3 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <linux/init.h>
35#include <linux/interrupt.h>
36#include <linux/dma-mapping.h>
37
38#include <linux/mlx4/cmd.h>
39
40#include "mlx4.h"
41#include "fw.h"
42
43enum {
44 MLX4_NUM_ASYNC_EQE = 0x100,
45 MLX4_NUM_SPARE_EQE = 0x80,
46 MLX4_EQ_ENTRY_SIZE = 0x20
47};
48
49/*
50 * Must be packed because start is 64 bits but only aligned to 32 bits.
51 */
52struct mlx4_eq_context {
53 __be32 flags;
54 u16 reserved1[3];
55 __be16 page_offset;
56 u8 log_eq_size;
57 u8 reserved2[4];
58 u8 eq_period;
59 u8 reserved3;
60 u8 eq_max_count;
61 u8 reserved4[3];
62 u8 intr;
63 u8 log_page_size;
64 u8 reserved5[2];
65 u8 mtt_base_addr_h;
66 __be32 mtt_base_addr_l;
67 u32 reserved6[2];
68 __be32 consumer_index;
69 __be32 producer_index;
70 u32 reserved7[4];
71};
72
73#define MLX4_EQ_STATUS_OK ( 0 << 28)
74#define MLX4_EQ_STATUS_WRITE_FAIL (10 << 28)
75#define MLX4_EQ_OWNER_SW ( 0 << 24)
76#define MLX4_EQ_OWNER_HW ( 1 << 24)
77#define MLX4_EQ_FLAG_EC ( 1 << 18)
78#define MLX4_EQ_FLAG_OI ( 1 << 17)
79#define MLX4_EQ_STATE_ARMED ( 9 << 8)
80#define MLX4_EQ_STATE_FIRED (10 << 8)
81#define MLX4_EQ_STATE_ALWAYS_ARMED (11 << 8)
82
83#define MLX4_ASYNC_EVENT_MASK ((1ull << MLX4_EVENT_TYPE_PATH_MIG) | \
84 (1ull << MLX4_EVENT_TYPE_COMM_EST) | \
85 (1ull << MLX4_EVENT_TYPE_SQ_DRAINED) | \
86 (1ull << MLX4_EVENT_TYPE_CQ_ERROR) | \
87 (1ull << MLX4_EVENT_TYPE_WQ_CATAS_ERROR) | \
88 (1ull << MLX4_EVENT_TYPE_EEC_CATAS_ERROR) | \
89 (1ull << MLX4_EVENT_TYPE_PATH_MIG_FAILED) | \
90 (1ull << MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR) | \
91 (1ull << MLX4_EVENT_TYPE_WQ_ACCESS_ERROR) | \
92 (1ull << MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR) | \
93 (1ull << MLX4_EVENT_TYPE_PORT_CHANGE) | \
94 (1ull << MLX4_EVENT_TYPE_ECC_DETECT) | \
95 (1ull << MLX4_EVENT_TYPE_SRQ_CATAS_ERROR) | \
96 (1ull << MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE) | \
97 (1ull << MLX4_EVENT_TYPE_SRQ_LIMIT) | \
98 (1ull << MLX4_EVENT_TYPE_CMD))
99#define MLX4_CATAS_EVENT_MASK (1ull << MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR)
100
101struct mlx4_eqe {
102 u8 reserved1;
103 u8 type;
104 u8 reserved2;
105 u8 subtype;
106 union {
107 u32 raw[6];
108 struct {
109 __be32 cqn;
110 } __attribute__((packed)) comp;
111 struct {
112 u16 reserved1;
113 __be16 token;
114 u32 reserved2;
115 u8 reserved3[3];
116 u8 status;
117 __be64 out_param;
118 } __attribute__((packed)) cmd;
119 struct {
120 __be32 qpn;
121 } __attribute__((packed)) qp;
122 struct {
123 __be32 srqn;
124 } __attribute__((packed)) srq;
125 struct {
126 __be32 cqn;
127 u32 reserved1;
128 u8 reserved2[3];
129 u8 syndrome;
130 } __attribute__((packed)) cq_err;
131 struct {
132 u32 reserved1[2];
133 __be32 port;
134 } __attribute__((packed)) port_change;
135 } event;
136 u8 reserved3[3];
137 u8 owner;
138} __attribute__((packed));
139
140static void eq_set_ci(struct mlx4_eq *eq, int req_not)
141{
142 __raw_writel((__force u32) cpu_to_be32((eq->cons_index & 0xffffff) |
143 req_not << 31),
144 eq->doorbell);
145 /* We still want ordering, just not swabbing, so add a barrier */
146 mb();
147}
148
149static struct mlx4_eqe *get_eqe(struct mlx4_eq *eq, u32 entry)
150{
151 unsigned long off = (entry & (eq->nent - 1)) * MLX4_EQ_ENTRY_SIZE;
152 return eq->page_list[off / PAGE_SIZE].buf + off % PAGE_SIZE;
153}
154
155static struct mlx4_eqe *next_eqe_sw(struct mlx4_eq *eq)
156{
157 struct mlx4_eqe *eqe = get_eqe(eq, eq->cons_index);
158 return !!(eqe->owner & 0x80) ^ !!(eq->cons_index & eq->nent) ? NULL : eqe;
159}
160
161static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
162{
163 struct mlx4_eqe *eqe;
164 int cqn;
165 int eqes_found = 0;
166 int set_ci = 0;
167
168 while ((eqe = next_eqe_sw(eq))) {
169 /*
170 * Make sure we read EQ entry contents after we've
171 * checked the ownership bit.
172 */
173 rmb();
174
175 switch (eqe->type) {
176 case MLX4_EVENT_TYPE_COMP:
177 cqn = be32_to_cpu(eqe->event.comp.cqn) & 0xffffff;
178 mlx4_cq_completion(dev, cqn);
179 break;
180
181 case MLX4_EVENT_TYPE_PATH_MIG:
182 case MLX4_EVENT_TYPE_COMM_EST:
183 case MLX4_EVENT_TYPE_SQ_DRAINED:
184 case MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE:
185 case MLX4_EVENT_TYPE_WQ_CATAS_ERROR:
186 case MLX4_EVENT_TYPE_PATH_MIG_FAILED:
187 case MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
188 case MLX4_EVENT_TYPE_WQ_ACCESS_ERROR:
189 mlx4_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
190 eqe->type);
191 break;
192
193 case MLX4_EVENT_TYPE_SRQ_LIMIT:
194 case MLX4_EVENT_TYPE_SRQ_CATAS_ERROR:
195 mlx4_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) & 0xffffff,
196 eqe->type);
197 break;
198
199 case MLX4_EVENT_TYPE_CMD:
200 mlx4_cmd_event(dev,
201 be16_to_cpu(eqe->event.cmd.token),
202 eqe->event.cmd.status,
203 be64_to_cpu(eqe->event.cmd.out_param));
204 break;
205
206 case MLX4_EVENT_TYPE_PORT_CHANGE:
207 mlx4_dispatch_event(dev, eqe->type, eqe->subtype,
208 be32_to_cpu(eqe->event.port_change.port) >> 28);
209 break;
210
211 case MLX4_EVENT_TYPE_CQ_ERROR:
212 mlx4_warn(dev, "CQ %s on CQN %06x\n",
213 eqe->event.cq_err.syndrome == 1 ?
214 "overrun" : "access violation",
215 be32_to_cpu(eqe->event.cq_err.cqn) & 0xffffff);
216 mlx4_cq_event(dev, be32_to_cpu(eqe->event.cq_err.cqn),
217 eqe->type);
218 break;
219
220 case MLX4_EVENT_TYPE_EQ_OVERFLOW:
221 mlx4_warn(dev, "EQ overrun on EQN %d\n", eq->eqn);
222 break;
223
224 case MLX4_EVENT_TYPE_EEC_CATAS_ERROR:
225 case MLX4_EVENT_TYPE_ECC_DETECT:
226 default:
227 mlx4_warn(dev, "Unhandled event %02x(%02x) on EQ %d at index %u\n",
228 eqe->type, eqe->subtype, eq->eqn, eq->cons_index);
229 break;
230 };
231
232 ++eq->cons_index;
233 eqes_found = 1;
234 ++set_ci;
235
236 /*
237 * The HCA will think the queue has overflowed if we
238 * don't tell it we've been processing events. We
239 * create our EQs with MLX4_NUM_SPARE_EQE extra
240 * entries, so we must update our consumer index at
241 * least that often.
242 */
243 if (unlikely(set_ci >= MLX4_NUM_SPARE_EQE)) {
244 /*
245 * Conditional on hca_type is OK here because
246 * this is a rare case, not the fast path.
247 */
248 eq_set_ci(eq, 0);
249 set_ci = 0;
250 }
251 }
252
253 eq_set_ci(eq, 1);
254
255 return eqes_found;
256}
257
258static irqreturn_t mlx4_interrupt(int irq, void *dev_ptr)
259{
260 struct mlx4_dev *dev = dev_ptr;
261 struct mlx4_priv *priv = mlx4_priv(dev);
262 int work = 0;
263 int i;
264
265 writel(priv->eq_table.clr_mask, priv->eq_table.clr_int);
266
267 for (i = 0; i < MLX4_EQ_CATAS; ++i)
268 work |= mlx4_eq_int(dev, &priv->eq_table.eq[i]);
269
270 return IRQ_RETVAL(work);
271}
272
273static irqreturn_t mlx4_msi_x_interrupt(int irq, void *eq_ptr)
274{
275 struct mlx4_eq *eq = eq_ptr;
276 struct mlx4_dev *dev = eq->dev;
277
278 mlx4_eq_int(dev, eq);
279
280 /* MSI-X vectors always belong to us */
281 return IRQ_HANDLED;
282}
283
284static irqreturn_t mlx4_catas_interrupt(int irq, void *dev_ptr)
285{
286 mlx4_handle_catas_err(dev_ptr);
287
288 /* MSI-X vectors always belong to us */
289 return IRQ_HANDLED;
290}
291
292static int mlx4_MAP_EQ(struct mlx4_dev *dev, u64 event_mask, int unmap,
293 int eq_num)
294{
295 return mlx4_cmd(dev, event_mask, (unmap << 31) | eq_num,
296 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B);
297}
298
299static int mlx4_SW2HW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
300 int eq_num)
301{
302 return mlx4_cmd(dev, mailbox->dma, eq_num, 0, MLX4_CMD_SW2HW_EQ,
303 MLX4_CMD_TIME_CLASS_A);
304}
305
306static int mlx4_HW2SW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
307 int eq_num)
308{
309 return mlx4_cmd_box(dev, 0, mailbox->dma, eq_num, 0, MLX4_CMD_HW2SW_EQ,
310 MLX4_CMD_TIME_CLASS_A);
311}
312
313static void __devinit __iomem *mlx4_get_eq_uar(struct mlx4_dev *dev,
314 struct mlx4_eq *eq)
315{
316 struct mlx4_priv *priv = mlx4_priv(dev);
317 int index;
318
319 index = eq->eqn / 4 - dev->caps.reserved_eqs / 4;
320
321 if (!priv->eq_table.uar_map[index]) {
322 priv->eq_table.uar_map[index] =
323 ioremap(pci_resource_start(dev->pdev, 2) +
324 ((eq->eqn / 4) << PAGE_SHIFT),
325 PAGE_SIZE);
326 if (!priv->eq_table.uar_map[index]) {
327 mlx4_err(dev, "Couldn't map EQ doorbell for EQN 0x%06x\n",
328 eq->eqn);
329 return NULL;
330 }
331 }
332
333 return priv->eq_table.uar_map[index] + 0x800 + 8 * (eq->eqn % 4);
334}
335
336static int __devinit mlx4_create_eq(struct mlx4_dev *dev, int nent,
337 u8 intr, struct mlx4_eq *eq)
338{
339 struct mlx4_priv *priv = mlx4_priv(dev);
340 struct mlx4_cmd_mailbox *mailbox;
341 struct mlx4_eq_context *eq_context;
342 int npages;
343 u64 *dma_list = NULL;
344 dma_addr_t t;
345 u64 mtt_addr;
346 int err = -ENOMEM;
347 int i;
348
349 eq->dev = dev;
350 eq->nent = roundup_pow_of_two(max(nent, 2));
351 npages = PAGE_ALIGN(eq->nent * MLX4_EQ_ENTRY_SIZE) / PAGE_SIZE;
352
353 eq->page_list = kmalloc(npages * sizeof *eq->page_list,
354 GFP_KERNEL);
355 if (!eq->page_list)
356 goto err_out;
357
358 for (i = 0; i < npages; ++i)
359 eq->page_list[i].buf = NULL;
360
361 dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
362 if (!dma_list)
363 goto err_out_free;
364
365 mailbox = mlx4_alloc_cmd_mailbox(dev);
366 if (IS_ERR(mailbox))
367 goto err_out_free;
368 eq_context = mailbox->buf;
369
370 for (i = 0; i < npages; ++i) {
371 eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev,
372 PAGE_SIZE, &t, GFP_KERNEL);
373 if (!eq->page_list[i].buf)
374 goto err_out_free_pages;
375
376 dma_list[i] = t;
377 eq->page_list[i].map = t;
378
379 memset(eq->page_list[i].buf, 0, PAGE_SIZE);
380 }
381
382 eq->eqn = mlx4_bitmap_alloc(&priv->eq_table.bitmap);
383 if (eq->eqn == -1)
384 goto err_out_free_pages;
385
386 eq->doorbell = mlx4_get_eq_uar(dev, eq);
387 if (!eq->doorbell) {
388 err = -ENOMEM;
389 goto err_out_free_eq;
390 }
391
392 err = mlx4_mtt_init(dev, npages, PAGE_SHIFT, &eq->mtt);
393 if (err)
394 goto err_out_free_eq;
395
396 err = mlx4_write_mtt(dev, &eq->mtt, 0, npages, dma_list);
397 if (err)
398 goto err_out_free_mtt;
399
400 memset(eq_context, 0, sizeof *eq_context);
401 eq_context->flags = cpu_to_be32(MLX4_EQ_STATUS_OK |
402 MLX4_EQ_STATE_ARMED);
403 eq_context->log_eq_size = ilog2(eq->nent);
404 eq_context->intr = intr;
405 eq_context->log_page_size = PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT;
406
407 mtt_addr = mlx4_mtt_addr(dev, &eq->mtt);
408 eq_context->mtt_base_addr_h = mtt_addr >> 32;
409 eq_context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
410
411 err = mlx4_SW2HW_EQ(dev, mailbox, eq->eqn);
412 if (err) {
413 mlx4_warn(dev, "SW2HW_EQ failed (%d)\n", err);
414 goto err_out_free_mtt;
415 }
416
417 kfree(dma_list);
418 mlx4_free_cmd_mailbox(dev, mailbox);
419
420 eq->cons_index = 0;
421
422 return err;
423
424err_out_free_mtt:
425 mlx4_mtt_cleanup(dev, &eq->mtt);
426
427err_out_free_eq:
428 mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn);
429
430err_out_free_pages:
431 for (i = 0; i < npages; ++i)
432 if (eq->page_list[i].buf)
433 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
434 eq->page_list[i].buf,
435 eq->page_list[i].map);
436
437 mlx4_free_cmd_mailbox(dev, mailbox);
438
439err_out_free:
440 kfree(eq->page_list);
441 kfree(dma_list);
442
443err_out:
444 return err;
445}
446
447static void mlx4_free_eq(struct mlx4_dev *dev,
448 struct mlx4_eq *eq)
449{
450 struct mlx4_priv *priv = mlx4_priv(dev);
451 struct mlx4_cmd_mailbox *mailbox;
452 int err;
453 int npages = PAGE_ALIGN(MLX4_EQ_ENTRY_SIZE * eq->nent) / PAGE_SIZE;
454 int i;
455
456 mailbox = mlx4_alloc_cmd_mailbox(dev);
457 if (IS_ERR(mailbox))
458 return;
459
460 err = mlx4_HW2SW_EQ(dev, mailbox, eq->eqn);
461 if (err)
462 mlx4_warn(dev, "HW2SW_EQ failed (%d)\n", err);
463
464 if (0) {
465 mlx4_dbg(dev, "Dumping EQ context %02x:\n", eq->eqn);
466 for (i = 0; i < sizeof (struct mlx4_eq_context) / 4; ++i) {
467 if (i % 4 == 0)
468 printk("[%02x] ", i * 4);
469 printk(" %08x", be32_to_cpup(mailbox->buf + i * 4));
470 if ((i + 1) % 4 == 0)
471 printk("\n");
472 }
473 }
474
475 mlx4_mtt_cleanup(dev, &eq->mtt);
476 for (i = 0; i < npages; ++i)
477 pci_free_consistent(dev->pdev, PAGE_SIZE,
478 eq->page_list[i].buf,
479 eq->page_list[i].map);
480
481 kfree(eq->page_list);
482 mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn);
483 mlx4_free_cmd_mailbox(dev, mailbox);
484}
485
486static void mlx4_free_irqs(struct mlx4_dev *dev)
487{
488 struct mlx4_eq_table *eq_table = &mlx4_priv(dev)->eq_table;
489 int i;
490
491 if (eq_table->have_irq)
492 free_irq(dev->pdev->irq, dev);
493 for (i = 0; i < MLX4_NUM_EQ; ++i)
494 if (eq_table->eq[i].have_irq)
495 free_irq(eq_table->eq[i].irq, eq_table->eq + i);
496}
497
498static int __devinit mlx4_map_clr_int(struct mlx4_dev *dev)
499{
500 struct mlx4_priv *priv = mlx4_priv(dev);
501
502 priv->clr_base = ioremap(pci_resource_start(dev->pdev, priv->fw.clr_int_bar) +
503 priv->fw.clr_int_base, MLX4_CLR_INT_SIZE);
504 if (!priv->clr_base) {
505 mlx4_err(dev, "Couldn't map interrupt clear register, aborting.\n");
506 return -ENOMEM;
507 }
508
509 return 0;
510}
511
512static void mlx4_unmap_clr_int(struct mlx4_dev *dev)
513{
514 struct mlx4_priv *priv = mlx4_priv(dev);
515
516 iounmap(priv->clr_base);
517}
518
519int __devinit mlx4_map_eq_icm(struct mlx4_dev *dev, u64 icm_virt)
520{
521 struct mlx4_priv *priv = mlx4_priv(dev);
522 int ret;
523
524 /*
525 * We assume that mapping one page is enough for the whole EQ
526 * context table. This is fine with all current HCAs, because
527 * we only use 32 EQs and each EQ uses 64 bytes of context
528 * memory, or 1 KB total.
529 */
530 priv->eq_table.icm_virt = icm_virt;
531 priv->eq_table.icm_page = alloc_page(GFP_HIGHUSER);
532 if (!priv->eq_table.icm_page)
533 return -ENOMEM;
534 priv->eq_table.icm_dma = pci_map_page(dev->pdev, priv->eq_table.icm_page, 0,
535 PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
536 if (pci_dma_mapping_error(priv->eq_table.icm_dma)) {
537 __free_page(priv->eq_table.icm_page);
538 return -ENOMEM;
539 }
540
541 ret = mlx4_MAP_ICM_page(dev, priv->eq_table.icm_dma, icm_virt);
542 if (ret) {
543 pci_unmap_page(dev->pdev, priv->eq_table.icm_dma, PAGE_SIZE,
544 PCI_DMA_BIDIRECTIONAL);
545 __free_page(priv->eq_table.icm_page);
546 }
547
548 return ret;
549}
550
551void mlx4_unmap_eq_icm(struct mlx4_dev *dev)
552{
553 struct mlx4_priv *priv = mlx4_priv(dev);
554
555 mlx4_UNMAP_ICM(dev, priv->eq_table.icm_virt, 1);
556 pci_unmap_page(dev->pdev, priv->eq_table.icm_dma, PAGE_SIZE,
557 PCI_DMA_BIDIRECTIONAL);
558 __free_page(priv->eq_table.icm_page);
559}
560
561int __devinit mlx4_init_eq_table(struct mlx4_dev *dev)
562{
563 struct mlx4_priv *priv = mlx4_priv(dev);
564 int err;
565 int i;
566
567 err = mlx4_bitmap_init(&priv->eq_table.bitmap, dev->caps.num_eqs,
568 dev->caps.num_eqs - 1, dev->caps.reserved_eqs);
569 if (err)
570 return err;
571
572 for (i = 0; i < ARRAY_SIZE(priv->eq_table.uar_map); ++i)
573 priv->eq_table.uar_map[i] = NULL;
574
575 err = mlx4_map_clr_int(dev);
576 if (err)
577 goto err_out_free;
578
579 priv->eq_table.clr_mask =
580 swab32(1 << (priv->eq_table.inta_pin & 31));
581 priv->eq_table.clr_int = priv->clr_base +
582 (priv->eq_table.inta_pin < 32 ? 4 : 0);
583
584 err = mlx4_create_eq(dev, dev->caps.num_cqs + MLX4_NUM_SPARE_EQE,
585 (dev->flags & MLX4_FLAG_MSI_X) ? MLX4_EQ_COMP : 0,
586 &priv->eq_table.eq[MLX4_EQ_COMP]);
587 if (err)
588 goto err_out_unmap;
589
590 err = mlx4_create_eq(dev, MLX4_NUM_ASYNC_EQE + MLX4_NUM_SPARE_EQE,
591 (dev->flags & MLX4_FLAG_MSI_X) ? MLX4_EQ_ASYNC : 0,
592 &priv->eq_table.eq[MLX4_EQ_ASYNC]);
593 if (err)
594 goto err_out_comp;
595
596 if (dev->flags & MLX4_FLAG_MSI_X) {
597 static const char *eq_name[] = {
598 [MLX4_EQ_COMP] = DRV_NAME " (comp)",
599 [MLX4_EQ_ASYNC] = DRV_NAME " (async)",
600 [MLX4_EQ_CATAS] = DRV_NAME " (catas)"
601 };
602
603 err = mlx4_create_eq(dev, 1, MLX4_EQ_CATAS,
604 &priv->eq_table.eq[MLX4_EQ_CATAS]);
605 if (err)
606 goto err_out_async;
607
608 for (i = 0; i < MLX4_EQ_CATAS; ++i) {
609 err = request_irq(priv->eq_table.eq[i].irq,
610 mlx4_msi_x_interrupt,
611 0, eq_name[i], priv->eq_table.eq + i);
612 if (err)
613 goto err_out_catas;
614
615 priv->eq_table.eq[i].have_irq = 1;
616 }
617
618 err = request_irq(priv->eq_table.eq[MLX4_EQ_CATAS].irq,
619 mlx4_catas_interrupt, 0,
620 eq_name[MLX4_EQ_CATAS], dev);
621 if (err)
622 goto err_out_catas;
623
624 priv->eq_table.eq[MLX4_EQ_CATAS].have_irq = 1;
625 } else {
626 err = request_irq(dev->pdev->irq, mlx4_interrupt,
627 IRQF_SHARED, DRV_NAME, dev);
628 if (err)
629 goto err_out_async;
630
631 priv->eq_table.have_irq = 1;
632 }
633
634 err = mlx4_MAP_EQ(dev, MLX4_ASYNC_EVENT_MASK, 0,
635 priv->eq_table.eq[MLX4_EQ_ASYNC].eqn);
636 if (err)
637 mlx4_warn(dev, "MAP_EQ for async EQ %d failed (%d)\n",
638 priv->eq_table.eq[MLX4_EQ_ASYNC].eqn, err);
639
640 for (i = 0; i < MLX4_EQ_CATAS; ++i)
641 eq_set_ci(&priv->eq_table.eq[i], 1);
642
643 if (dev->flags & MLX4_FLAG_MSI_X) {
644 err = mlx4_MAP_EQ(dev, MLX4_CATAS_EVENT_MASK, 0,
645 priv->eq_table.eq[MLX4_EQ_CATAS].eqn);
646 if (err)
647 mlx4_warn(dev, "MAP_EQ for catas EQ %d failed (%d)\n",
648 priv->eq_table.eq[MLX4_EQ_CATAS].eqn, err);
649 }
650
651 return 0;
652
653err_out_catas:
654 mlx4_free_eq(dev, &priv->eq_table.eq[MLX4_EQ_CATAS]);
655
656err_out_async:
657 mlx4_free_eq(dev, &priv->eq_table.eq[MLX4_EQ_ASYNC]);
658
659err_out_comp:
660 mlx4_free_eq(dev, &priv->eq_table.eq[MLX4_EQ_COMP]);
661
662err_out_unmap:
663 mlx4_unmap_clr_int(dev);
664 mlx4_free_irqs(dev);
665
666err_out_free:
667 mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
668 return err;
669}
670
671void mlx4_cleanup_eq_table(struct mlx4_dev *dev)
672{
673 struct mlx4_priv *priv = mlx4_priv(dev);
674 int i;
675
676 if (dev->flags & MLX4_FLAG_MSI_X)
677 mlx4_MAP_EQ(dev, MLX4_CATAS_EVENT_MASK, 1,
678 priv->eq_table.eq[MLX4_EQ_CATAS].eqn);
679
680 mlx4_MAP_EQ(dev, MLX4_ASYNC_EVENT_MASK, 1,
681 priv->eq_table.eq[MLX4_EQ_ASYNC].eqn);
682
683 mlx4_free_irqs(dev);
684
685 for (i = 0; i < MLX4_EQ_CATAS; ++i)
686 mlx4_free_eq(dev, &priv->eq_table.eq[i]);
687 if (dev->flags & MLX4_FLAG_MSI_X)
688 mlx4_free_eq(dev, &priv->eq_table.eq[MLX4_EQ_CATAS]);
689
690 mlx4_unmap_clr_int(dev);
691
692 for (i = 0; i < ARRAY_SIZE(priv->eq_table.uar_map); ++i)
693 if (priv->eq_table.uar_map[i])
694 iounmap(priv->eq_table.uar_map[i]);
695
696 mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
697}
diff --git a/drivers/net/mlx4/fw.c b/drivers/net/mlx4/fw.c
new file mode 100644
index 000000000000..cfa5cc072339
--- /dev/null
+++ b/drivers/net/mlx4/fw.c
@@ -0,0 +1,775 @@
1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#include <linux/mlx4/cmd.h>
36
37#include "fw.h"
38#include "icm.h"
39
40extern void __buggy_use_of_MLX4_GET(void);
41extern void __buggy_use_of_MLX4_PUT(void);
42
43#define MLX4_GET(dest, source, offset) \
44 do { \
45 void *__p = (char *) (source) + (offset); \
46 switch (sizeof (dest)) { \
47 case 1: (dest) = *(u8 *) __p; break; \
48 case 2: (dest) = be16_to_cpup(__p); break; \
49 case 4: (dest) = be32_to_cpup(__p); break; \
50 case 8: (dest) = be64_to_cpup(__p); break; \
51 default: __buggy_use_of_MLX4_GET(); \
52 } \
53 } while (0)
54
55#define MLX4_PUT(dest, source, offset) \
56 do { \
57 void *__d = ((char *) (dest) + (offset)); \
58 switch (sizeof(source)) { \
59 case 1: *(u8 *) __d = (source); break; \
60 case 2: *(__be16 *) __d = cpu_to_be16(source); break; \
61 case 4: *(__be32 *) __d = cpu_to_be32(source); break; \
62 case 8: *(__be64 *) __d = cpu_to_be64(source); break; \
63 default: __buggy_use_of_MLX4_PUT(); \
64 } \
65 } while (0)
66
67static void dump_dev_cap_flags(struct mlx4_dev *dev, u32 flags)
68{
69 static const char *fname[] = {
70 [ 0] = "RC transport",
71 [ 1] = "UC transport",
72 [ 2] = "UD transport",
73 [ 3] = "SRC transport",
74 [ 4] = "reliable multicast",
75 [ 5] = "FCoIB support",
76 [ 6] = "SRQ support",
77 [ 7] = "IPoIB checksum offload",
78 [ 8] = "P_Key violation counter",
79 [ 9] = "Q_Key violation counter",
80 [10] = "VMM",
81 [16] = "MW support",
82 [17] = "APM support",
83 [18] = "Atomic ops support",
84 [19] = "Raw multicast support",
85 [20] = "Address vector port checking support",
86 [21] = "UD multicast support",
87 [24] = "Demand paging support",
88 [25] = "Router support"
89 };
90 int i;
91
92 mlx4_dbg(dev, "DEV_CAP flags:\n");
93 for (i = 0; i < ARRAY_SIZE(fname); ++i)
94 if (fname[i] && (flags & (1 << i)))
95 mlx4_dbg(dev, " %s\n", fname[i]);
96}
97
98int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
99{
100 struct mlx4_cmd_mailbox *mailbox;
101 u32 *outbox;
102 u8 field;
103 u16 size;
104 u16 stat_rate;
105 int err;
106
107#define QUERY_DEV_CAP_OUT_SIZE 0x100
108#define QUERY_DEV_CAP_MAX_SRQ_SZ_OFFSET 0x10
109#define QUERY_DEV_CAP_MAX_QP_SZ_OFFSET 0x11
110#define QUERY_DEV_CAP_RSVD_QP_OFFSET 0x12
111#define QUERY_DEV_CAP_MAX_QP_OFFSET 0x13
112#define QUERY_DEV_CAP_RSVD_SRQ_OFFSET 0x14
113#define QUERY_DEV_CAP_MAX_SRQ_OFFSET 0x15
114#define QUERY_DEV_CAP_RSVD_EEC_OFFSET 0x16
115#define QUERY_DEV_CAP_MAX_EEC_OFFSET 0x17
116#define QUERY_DEV_CAP_MAX_CQ_SZ_OFFSET 0x19
117#define QUERY_DEV_CAP_RSVD_CQ_OFFSET 0x1a
118#define QUERY_DEV_CAP_MAX_CQ_OFFSET 0x1b
119#define QUERY_DEV_CAP_MAX_MPT_OFFSET 0x1d
120#define QUERY_DEV_CAP_RSVD_EQ_OFFSET 0x1e
121#define QUERY_DEV_CAP_MAX_EQ_OFFSET 0x1f
122#define QUERY_DEV_CAP_RSVD_MTT_OFFSET 0x20
123#define QUERY_DEV_CAP_MAX_MRW_SZ_OFFSET 0x21
124#define QUERY_DEV_CAP_RSVD_MRW_OFFSET 0x22
125#define QUERY_DEV_CAP_MAX_MTT_SEG_OFFSET 0x23
126#define QUERY_DEV_CAP_MAX_AV_OFFSET 0x27
127#define QUERY_DEV_CAP_MAX_REQ_QP_OFFSET 0x29
128#define QUERY_DEV_CAP_MAX_RES_QP_OFFSET 0x2b
129#define QUERY_DEV_CAP_MAX_RDMA_OFFSET 0x2f
130#define QUERY_DEV_CAP_RSZ_SRQ_OFFSET 0x33
131#define QUERY_DEV_CAP_ACK_DELAY_OFFSET 0x35
132#define QUERY_DEV_CAP_MTU_WIDTH_OFFSET 0x36
133#define QUERY_DEV_CAP_VL_PORT_OFFSET 0x37
134#define QUERY_DEV_CAP_MAX_GID_OFFSET 0x3b
135#define QUERY_DEV_CAP_RATE_SUPPORT_OFFSET 0x3c
136#define QUERY_DEV_CAP_MAX_PKEY_OFFSET 0x3f
137#define QUERY_DEV_CAP_FLAGS_OFFSET 0x44
138#define QUERY_DEV_CAP_RSVD_UAR_OFFSET 0x48
139#define QUERY_DEV_CAP_UAR_SZ_OFFSET 0x49
140#define QUERY_DEV_CAP_PAGE_SZ_OFFSET 0x4b
141#define QUERY_DEV_CAP_BF_OFFSET 0x4c
142#define QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET 0x4d
143#define QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET 0x4e
144#define QUERY_DEV_CAP_LOG_MAX_BF_PAGES_OFFSET 0x4f
145#define QUERY_DEV_CAP_MAX_SG_SQ_OFFSET 0x51
146#define QUERY_DEV_CAP_MAX_DESC_SZ_SQ_OFFSET 0x52
147#define QUERY_DEV_CAP_MAX_SG_RQ_OFFSET 0x55
148#define QUERY_DEV_CAP_MAX_DESC_SZ_RQ_OFFSET 0x56
149#define QUERY_DEV_CAP_MAX_QP_MCG_OFFSET 0x61
150#define QUERY_DEV_CAP_RSVD_MCG_OFFSET 0x62
151#define QUERY_DEV_CAP_MAX_MCG_OFFSET 0x63
152#define QUERY_DEV_CAP_RSVD_PD_OFFSET 0x64
153#define QUERY_DEV_CAP_MAX_PD_OFFSET 0x65
154#define QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET 0x80
155#define QUERY_DEV_CAP_QPC_ENTRY_SZ_OFFSET 0x82
156#define QUERY_DEV_CAP_AUX_ENTRY_SZ_OFFSET 0x84
157#define QUERY_DEV_CAP_ALTC_ENTRY_SZ_OFFSET 0x86
158#define QUERY_DEV_CAP_EQC_ENTRY_SZ_OFFSET 0x88
159#define QUERY_DEV_CAP_CQC_ENTRY_SZ_OFFSET 0x8a
160#define QUERY_DEV_CAP_SRQ_ENTRY_SZ_OFFSET 0x8c
161#define QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET 0x8e
162#define QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET 0x90
163#define QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET 0x92
164#define QUERY_DEV_CAP_BMME_FLAGS_OFFSET 0x97
165#define QUERY_DEV_CAP_RSVD_LKEY_OFFSET 0x98
166#define QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET 0xa0
167
168 mailbox = mlx4_alloc_cmd_mailbox(dev);
169 if (IS_ERR(mailbox))
170 return PTR_ERR(mailbox);
171 outbox = mailbox->buf;
172
173 err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_DEV_CAP,
174 MLX4_CMD_TIME_CLASS_A);
175
176 if (err)
177 goto out;
178
179 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_QP_OFFSET);
180 dev_cap->reserved_qps = 1 << (field & 0xf);
181 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_OFFSET);
182 dev_cap->max_qps = 1 << (field & 0x1f);
183 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_SRQ_OFFSET);
184 dev_cap->reserved_srqs = 1 << (field >> 4);
185 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SRQ_OFFSET);
186 dev_cap->max_srqs = 1 << (field & 0x1f);
187 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_CQ_SZ_OFFSET);
188 dev_cap->max_cq_sz = 1 << field;
189 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_CQ_OFFSET);
190 dev_cap->reserved_cqs = 1 << (field & 0xf);
191 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_CQ_OFFSET);
192 dev_cap->max_cqs = 1 << (field & 0x1f);
193 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MPT_OFFSET);
194 dev_cap->max_mpts = 1 << (field & 0x3f);
195 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_EQ_OFFSET);
196 dev_cap->reserved_eqs = 1 << (field & 0xf);
197 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_EQ_OFFSET);
198 dev_cap->max_eqs = 1 << (field & 0x7);
199 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MTT_OFFSET);
200 dev_cap->reserved_mtts = 1 << (field >> 4);
201 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MRW_SZ_OFFSET);
202 dev_cap->max_mrw_sz = 1 << field;
203 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MRW_OFFSET);
204 dev_cap->reserved_mrws = 1 << (field & 0xf);
205 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MTT_SEG_OFFSET);
206 dev_cap->max_mtt_seg = 1 << (field & 0x3f);
207 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_REQ_QP_OFFSET);
208 dev_cap->max_requester_per_qp = 1 << (field & 0x3f);
209 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_RES_QP_OFFSET);
210 dev_cap->max_responder_per_qp = 1 << (field & 0x3f);
211 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_RDMA_OFFSET);
212 dev_cap->max_rdma_global = 1 << (field & 0x3f);
213 MLX4_GET(field, outbox, QUERY_DEV_CAP_ACK_DELAY_OFFSET);
214 dev_cap->local_ca_ack_delay = field & 0x1f;
215 MLX4_GET(field, outbox, QUERY_DEV_CAP_MTU_WIDTH_OFFSET);
216 dev_cap->max_mtu = field >> 4;
217 dev_cap->max_port_width = field & 0xf;
218 MLX4_GET(field, outbox, QUERY_DEV_CAP_VL_PORT_OFFSET);
219 dev_cap->max_vl = field >> 4;
220 dev_cap->num_ports = field & 0xf;
221 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_GID_OFFSET);
222 dev_cap->max_gids = 1 << (field & 0xf);
223 MLX4_GET(stat_rate, outbox, QUERY_DEV_CAP_RATE_SUPPORT_OFFSET);
224 dev_cap->stat_rate_support = stat_rate;
225 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PKEY_OFFSET);
226 dev_cap->max_pkeys = 1 << (field & 0xf);
227 MLX4_GET(dev_cap->flags, outbox, QUERY_DEV_CAP_FLAGS_OFFSET);
228 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_UAR_OFFSET);
229 dev_cap->reserved_uars = field >> 4;
230 MLX4_GET(field, outbox, QUERY_DEV_CAP_UAR_SZ_OFFSET);
231 dev_cap->uar_size = 1 << ((field & 0x3f) + 20);
232 MLX4_GET(field, outbox, QUERY_DEV_CAP_PAGE_SZ_OFFSET);
233 dev_cap->min_page_sz = 1 << field;
234
235 MLX4_GET(field, outbox, QUERY_DEV_CAP_BF_OFFSET);
236 if (field & 0x80) {
237 MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_BF_REG_SZ_OFFSET);
238 dev_cap->bf_reg_size = 1 << (field & 0x1f);
239 MLX4_GET(field, outbox, QUERY_DEV_CAP_LOG_MAX_BF_REGS_PER_PAGE_OFFSET);
240 dev_cap->bf_regs_per_page = 1 << (field & 0x3f);
241 mlx4_dbg(dev, "BlueFlame available (reg size %d, regs/page %d)\n",
242 dev_cap->bf_reg_size, dev_cap->bf_regs_per_page);
243 } else {
244 dev_cap->bf_reg_size = 0;
245 mlx4_dbg(dev, "BlueFlame not available\n");
246 }
247
248 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SG_SQ_OFFSET);
249 dev_cap->max_sq_sg = field;
250 MLX4_GET(size, outbox, QUERY_DEV_CAP_MAX_DESC_SZ_SQ_OFFSET);
251 dev_cap->max_sq_desc_sz = size;
252
253 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_MCG_OFFSET);
254 dev_cap->max_qp_per_mcg = 1 << field;
255 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_MCG_OFFSET);
256 dev_cap->reserved_mgms = field & 0xf;
257 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_MCG_OFFSET);
258 dev_cap->max_mcgs = 1 << field;
259 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSVD_PD_OFFSET);
260 dev_cap->reserved_pds = field >> 4;
261 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_PD_OFFSET);
262 dev_cap->max_pds = 1 << (field & 0x3f);
263
264 MLX4_GET(size, outbox, QUERY_DEV_CAP_RDMARC_ENTRY_SZ_OFFSET);
265 dev_cap->rdmarc_entry_sz = size;
266 MLX4_GET(size, outbox, QUERY_DEV_CAP_QPC_ENTRY_SZ_OFFSET);
267 dev_cap->qpc_entry_sz = size;
268 MLX4_GET(size, outbox, QUERY_DEV_CAP_AUX_ENTRY_SZ_OFFSET);
269 dev_cap->aux_entry_sz = size;
270 MLX4_GET(size, outbox, QUERY_DEV_CAP_ALTC_ENTRY_SZ_OFFSET);
271 dev_cap->altc_entry_sz = size;
272 MLX4_GET(size, outbox, QUERY_DEV_CAP_EQC_ENTRY_SZ_OFFSET);
273 dev_cap->eqc_entry_sz = size;
274 MLX4_GET(size, outbox, QUERY_DEV_CAP_CQC_ENTRY_SZ_OFFSET);
275 dev_cap->cqc_entry_sz = size;
276 MLX4_GET(size, outbox, QUERY_DEV_CAP_SRQ_ENTRY_SZ_OFFSET);
277 dev_cap->srq_entry_sz = size;
278 MLX4_GET(size, outbox, QUERY_DEV_CAP_C_MPT_ENTRY_SZ_OFFSET);
279 dev_cap->cmpt_entry_sz = size;
280 MLX4_GET(size, outbox, QUERY_DEV_CAP_MTT_ENTRY_SZ_OFFSET);
281 dev_cap->mtt_entry_sz = size;
282 MLX4_GET(size, outbox, QUERY_DEV_CAP_D_MPT_ENTRY_SZ_OFFSET);
283 dev_cap->dmpt_entry_sz = size;
284
285 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SRQ_SZ_OFFSET);
286 dev_cap->max_srq_sz = 1 << field;
287 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_QP_SZ_OFFSET);
288 dev_cap->max_qp_sz = 1 << field;
289 MLX4_GET(field, outbox, QUERY_DEV_CAP_RSZ_SRQ_OFFSET);
290 dev_cap->resize_srq = field & 1;
291 MLX4_GET(field, outbox, QUERY_DEV_CAP_MAX_SG_RQ_OFFSET);
292 dev_cap->max_rq_sg = field;
293 MLX4_GET(size, outbox, QUERY_DEV_CAP_MAX_DESC_SZ_RQ_OFFSET);
294 dev_cap->max_rq_desc_sz = size;
295
296 MLX4_GET(dev_cap->bmme_flags, outbox,
297 QUERY_DEV_CAP_BMME_FLAGS_OFFSET);
298 MLX4_GET(dev_cap->reserved_lkey, outbox,
299 QUERY_DEV_CAP_RSVD_LKEY_OFFSET);
300 MLX4_GET(dev_cap->max_icm_sz, outbox,
301 QUERY_DEV_CAP_MAX_ICM_SZ_OFFSET);
302
303 if (dev_cap->bmme_flags & 1)
304 mlx4_dbg(dev, "Base MM extensions: yes "
305 "(flags %d, rsvd L_Key %08x)\n",
306 dev_cap->bmme_flags, dev_cap->reserved_lkey);
307 else
308 mlx4_dbg(dev, "Base MM extensions: no\n");
309
310 /*
311 * Each UAR has 4 EQ doorbells; so if a UAR is reserved, then
312 * we can't use any EQs whose doorbell falls on that page,
313 * even if the EQ itself isn't reserved.
314 */
315 dev_cap->reserved_eqs = max(dev_cap->reserved_uars * 4,
316 dev_cap->reserved_eqs);
317
318 mlx4_dbg(dev, "Max ICM size %lld MB\n",
319 (unsigned long long) dev_cap->max_icm_sz >> 20);
320 mlx4_dbg(dev, "Max QPs: %d, reserved QPs: %d, entry size: %d\n",
321 dev_cap->max_qps, dev_cap->reserved_qps, dev_cap->qpc_entry_sz);
322 mlx4_dbg(dev, "Max SRQs: %d, reserved SRQs: %d, entry size: %d\n",
323 dev_cap->max_srqs, dev_cap->reserved_srqs, dev_cap->srq_entry_sz);
324 mlx4_dbg(dev, "Max CQs: %d, reserved CQs: %d, entry size: %d\n",
325 dev_cap->max_cqs, dev_cap->reserved_cqs, dev_cap->cqc_entry_sz);
326 mlx4_dbg(dev, "Max EQs: %d, reserved EQs: %d, entry size: %d\n",
327 dev_cap->max_eqs, dev_cap->reserved_eqs, dev_cap->eqc_entry_sz);
328 mlx4_dbg(dev, "reserved MPTs: %d, reserved MTTs: %d\n",
329 dev_cap->reserved_mrws, dev_cap->reserved_mtts);
330 mlx4_dbg(dev, "Max PDs: %d, reserved PDs: %d, reserved UARs: %d\n",
331 dev_cap->max_pds, dev_cap->reserved_pds, dev_cap->reserved_uars);
332 mlx4_dbg(dev, "Max QP/MCG: %d, reserved MGMs: %d\n",
333 dev_cap->max_pds, dev_cap->reserved_mgms);
334 mlx4_dbg(dev, "Max CQEs: %d, max WQEs: %d, max SRQ WQEs: %d\n",
335 dev_cap->max_cq_sz, dev_cap->max_qp_sz, dev_cap->max_srq_sz);
336 mlx4_dbg(dev, "Local CA ACK delay: %d, max MTU: %d, port width cap: %d\n",
337 dev_cap->local_ca_ack_delay, 128 << dev_cap->max_mtu,
338 dev_cap->max_port_width);
339 mlx4_dbg(dev, "Max SQ desc size: %d, max SQ S/G: %d\n",
340 dev_cap->max_sq_desc_sz, dev_cap->max_sq_sg);
341 mlx4_dbg(dev, "Max RQ desc size: %d, max RQ S/G: %d\n",
342 dev_cap->max_rq_desc_sz, dev_cap->max_rq_sg);
343
344 dump_dev_cap_flags(dev, dev_cap->flags);
345
346out:
347 mlx4_free_cmd_mailbox(dev, mailbox);
348 return err;
349}
350
351int mlx4_map_cmd(struct mlx4_dev *dev, u16 op, struct mlx4_icm *icm, u64 virt)
352{
353 struct mlx4_cmd_mailbox *mailbox;
354 struct mlx4_icm_iter iter;
355 __be64 *pages;
356 int lg;
357 int nent = 0;
358 int i;
359 int err = 0;
360 int ts = 0, tc = 0;
361
362 mailbox = mlx4_alloc_cmd_mailbox(dev);
363 if (IS_ERR(mailbox))
364 return PTR_ERR(mailbox);
365 memset(mailbox->buf, 0, MLX4_MAILBOX_SIZE);
366 pages = mailbox->buf;
367
368 for (mlx4_icm_first(icm, &iter);
369 !mlx4_icm_last(&iter);
370 mlx4_icm_next(&iter)) {
371 /*
372 * We have to pass pages that are aligned to their
373 * size, so find the least significant 1 in the
374 * address or size and use that as our log2 size.
375 */
376 lg = ffs(mlx4_icm_addr(&iter) | mlx4_icm_size(&iter)) - 1;
377 if (lg < MLX4_ICM_PAGE_SHIFT) {
378 mlx4_warn(dev, "Got FW area not aligned to %d (%llx/%lx).\n",
379 MLX4_ICM_PAGE_SIZE,
380 (unsigned long long) mlx4_icm_addr(&iter),
381 mlx4_icm_size(&iter));
382 err = -EINVAL;
383 goto out;
384 }
385
386 for (i = 0; i < mlx4_icm_size(&iter) >> lg; ++i) {
387 if (virt != -1) {
388 pages[nent * 2] = cpu_to_be64(virt);
389 virt += 1 << lg;
390 }
391
392 pages[nent * 2 + 1] =
393 cpu_to_be64((mlx4_icm_addr(&iter) + (i << lg)) |
394 (lg - MLX4_ICM_PAGE_SHIFT));
395 ts += 1 << (lg - 10);
396 ++tc;
397
398 if (++nent == MLX4_MAILBOX_SIZE / 16) {
399 err = mlx4_cmd(dev, mailbox->dma, nent, 0, op,
400 MLX4_CMD_TIME_CLASS_B);
401 if (err)
402 goto out;
403 nent = 0;
404 }
405 }
406 }
407
408 if (nent)
409 err = mlx4_cmd(dev, mailbox->dma, nent, 0, op, MLX4_CMD_TIME_CLASS_B);
410 if (err)
411 goto out;
412
413 switch (op) {
414 case MLX4_CMD_MAP_FA:
415 mlx4_dbg(dev, "Mapped %d chunks/%d KB for FW.\n", tc, ts);
416 break;
417 case MLX4_CMD_MAP_ICM_AUX:
418 mlx4_dbg(dev, "Mapped %d chunks/%d KB for ICM aux.\n", tc, ts);
419 break;
420 case MLX4_CMD_MAP_ICM:
421 mlx4_dbg(dev, "Mapped %d chunks/%d KB at %llx for ICM.\n",
422 tc, ts, (unsigned long long) virt - (ts << 10));
423 break;
424 }
425
426out:
427 mlx4_free_cmd_mailbox(dev, mailbox);
428 return err;
429}
430
431int mlx4_MAP_FA(struct mlx4_dev *dev, struct mlx4_icm *icm)
432{
433 return mlx4_map_cmd(dev, MLX4_CMD_MAP_FA, icm, -1);
434}
435
436int mlx4_UNMAP_FA(struct mlx4_dev *dev)
437{
438 return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_UNMAP_FA, MLX4_CMD_TIME_CLASS_B);
439}
440
441
442int mlx4_RUN_FW(struct mlx4_dev *dev)
443{
444 return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_RUN_FW, MLX4_CMD_TIME_CLASS_A);
445}
446
447int mlx4_QUERY_FW(struct mlx4_dev *dev)
448{
449 struct mlx4_fw *fw = &mlx4_priv(dev)->fw;
450 struct mlx4_cmd *cmd = &mlx4_priv(dev)->cmd;
451 struct mlx4_cmd_mailbox *mailbox;
452 u32 *outbox;
453 int err = 0;
454 u64 fw_ver;
455 u8 lg;
456
457#define QUERY_FW_OUT_SIZE 0x100
458#define QUERY_FW_VER_OFFSET 0x00
459#define QUERY_FW_MAX_CMD_OFFSET 0x0f
460#define QUERY_FW_ERR_START_OFFSET 0x30
461#define QUERY_FW_ERR_SIZE_OFFSET 0x38
462#define QUERY_FW_ERR_BAR_OFFSET 0x3c
463
464#define QUERY_FW_SIZE_OFFSET 0x00
465#define QUERY_FW_CLR_INT_BASE_OFFSET 0x20
466#define QUERY_FW_CLR_INT_BAR_OFFSET 0x28
467
468 mailbox = mlx4_alloc_cmd_mailbox(dev);
469 if (IS_ERR(mailbox))
470 return PTR_ERR(mailbox);
471 outbox = mailbox->buf;
472
473 err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_FW,
474 MLX4_CMD_TIME_CLASS_A);
475 if (err)
476 goto out;
477
478 MLX4_GET(fw_ver, outbox, QUERY_FW_VER_OFFSET);
479 /*
480 * FW subminor version is at more signifant bits than minor
481 * version, so swap here.
482 */
483 dev->caps.fw_ver = (fw_ver & 0xffff00000000ull) |
484 ((fw_ver & 0xffff0000ull) >> 16) |
485 ((fw_ver & 0x0000ffffull) << 16);
486
487 MLX4_GET(lg, outbox, QUERY_FW_MAX_CMD_OFFSET);
488 cmd->max_cmds = 1 << lg;
489
490 mlx4_dbg(dev, "FW version %d.%d.%03d, max commands %d\n",
491 (int) (dev->caps.fw_ver >> 32),
492 (int) (dev->caps.fw_ver >> 16) & 0xffff,
493 (int) dev->caps.fw_ver & 0xffff,
494 cmd->max_cmds);
495
496 MLX4_GET(fw->catas_offset, outbox, QUERY_FW_ERR_START_OFFSET);
497 MLX4_GET(fw->catas_size, outbox, QUERY_FW_ERR_SIZE_OFFSET);
498 MLX4_GET(fw->catas_bar, outbox, QUERY_FW_ERR_BAR_OFFSET);
499 fw->catas_bar = (fw->catas_bar >> 6) * 2;
500
501 mlx4_dbg(dev, "Catastrophic error buffer at 0x%llx, size 0x%x, BAR %d\n",
502 (unsigned long long) fw->catas_offset, fw->catas_size, fw->catas_bar);
503
504 MLX4_GET(fw->fw_pages, outbox, QUERY_FW_SIZE_OFFSET);
505 MLX4_GET(fw->clr_int_base, outbox, QUERY_FW_CLR_INT_BASE_OFFSET);
506 MLX4_GET(fw->clr_int_bar, outbox, QUERY_FW_CLR_INT_BAR_OFFSET);
507 fw->clr_int_bar = (fw->clr_int_bar >> 6) * 2;
508
509 mlx4_dbg(dev, "FW size %d KB\n", fw->fw_pages >> 2);
510
511 /*
512 * Round up number of system pages needed in case
513 * MLX4_ICM_PAGE_SIZE < PAGE_SIZE.
514 */
515 fw->fw_pages =
516 ALIGN(fw->fw_pages, PAGE_SIZE / MLX4_ICM_PAGE_SIZE) >>
517 (PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT);
518
519 mlx4_dbg(dev, "Clear int @ %llx, BAR %d\n",
520 (unsigned long long) fw->clr_int_base, fw->clr_int_bar);
521
522out:
523 mlx4_free_cmd_mailbox(dev, mailbox);
524 return err;
525}
526
527static void get_board_id(void *vsd, char *board_id)
528{
529 int i;
530
531#define VSD_OFFSET_SIG1 0x00
532#define VSD_OFFSET_SIG2 0xde
533#define VSD_OFFSET_MLX_BOARD_ID 0xd0
534#define VSD_OFFSET_TS_BOARD_ID 0x20
535
536#define VSD_SIGNATURE_TOPSPIN 0x5ad
537
538 memset(board_id, 0, MLX4_BOARD_ID_LEN);
539
540 if (be16_to_cpup(vsd + VSD_OFFSET_SIG1) == VSD_SIGNATURE_TOPSPIN &&
541 be16_to_cpup(vsd + VSD_OFFSET_SIG2) == VSD_SIGNATURE_TOPSPIN) {
542 strlcpy(board_id, vsd + VSD_OFFSET_TS_BOARD_ID, MLX4_BOARD_ID_LEN);
543 } else {
544 /*
545 * The board ID is a string but the firmware byte
546 * swaps each 4-byte word before passing it back to
547 * us. Therefore we need to swab it before printing.
548 */
549 for (i = 0; i < 4; ++i)
550 ((u32 *) board_id)[i] =
551 swab32(*(u32 *) (vsd + VSD_OFFSET_MLX_BOARD_ID + i * 4));
552 }
553}
554
555int mlx4_QUERY_ADAPTER(struct mlx4_dev *dev, struct mlx4_adapter *adapter)
556{
557 struct mlx4_cmd_mailbox *mailbox;
558 u32 *outbox;
559 int err;
560
561#define QUERY_ADAPTER_OUT_SIZE 0x100
562#define QUERY_ADAPTER_VENDOR_ID_OFFSET 0x00
563#define QUERY_ADAPTER_DEVICE_ID_OFFSET 0x04
564#define QUERY_ADAPTER_REVISION_ID_OFFSET 0x08
565#define QUERY_ADAPTER_INTA_PIN_OFFSET 0x10
566#define QUERY_ADAPTER_VSD_OFFSET 0x20
567
568 mailbox = mlx4_alloc_cmd_mailbox(dev);
569 if (IS_ERR(mailbox))
570 return PTR_ERR(mailbox);
571 outbox = mailbox->buf;
572
573 err = mlx4_cmd_box(dev, 0, mailbox->dma, 0, 0, MLX4_CMD_QUERY_ADAPTER,
574 MLX4_CMD_TIME_CLASS_A);
575 if (err)
576 goto out;
577
578 MLX4_GET(adapter->vendor_id, outbox, QUERY_ADAPTER_VENDOR_ID_OFFSET);
579 MLX4_GET(adapter->device_id, outbox, QUERY_ADAPTER_DEVICE_ID_OFFSET);
580 MLX4_GET(adapter->revision_id, outbox, QUERY_ADAPTER_REVISION_ID_OFFSET);
581 MLX4_GET(adapter->inta_pin, outbox, QUERY_ADAPTER_INTA_PIN_OFFSET);
582
583 get_board_id(outbox + QUERY_ADAPTER_VSD_OFFSET / 4,
584 adapter->board_id);
585
586out:
587 mlx4_free_cmd_mailbox(dev, mailbox);
588 return err;
589}
590
591int mlx4_INIT_HCA(struct mlx4_dev *dev, struct mlx4_init_hca_param *param)
592{
593 struct mlx4_cmd_mailbox *mailbox;
594 __be32 *inbox;
595 int err;
596
597#define INIT_HCA_IN_SIZE 0x200
598#define INIT_HCA_VERSION_OFFSET 0x000
599#define INIT_HCA_VERSION 2
600#define INIT_HCA_FLAGS_OFFSET 0x014
601#define INIT_HCA_QPC_OFFSET 0x020
602#define INIT_HCA_QPC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x10)
603#define INIT_HCA_LOG_QP_OFFSET (INIT_HCA_QPC_OFFSET + 0x17)
604#define INIT_HCA_SRQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x28)
605#define INIT_HCA_LOG_SRQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x2f)
606#define INIT_HCA_CQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x30)
607#define INIT_HCA_LOG_CQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x37)
608#define INIT_HCA_ALTC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x40)
609#define INIT_HCA_AUXC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x50)
610#define INIT_HCA_EQC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x60)
611#define INIT_HCA_LOG_EQ_OFFSET (INIT_HCA_QPC_OFFSET + 0x67)
612#define INIT_HCA_RDMARC_BASE_OFFSET (INIT_HCA_QPC_OFFSET + 0x70)
613#define INIT_HCA_LOG_RD_OFFSET (INIT_HCA_QPC_OFFSET + 0x77)
614#define INIT_HCA_MCAST_OFFSET 0x0c0
615#define INIT_HCA_MC_BASE_OFFSET (INIT_HCA_MCAST_OFFSET + 0x00)
616#define INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x12)
617#define INIT_HCA_LOG_MC_HASH_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x16)
618#define INIT_HCA_LOG_MC_TABLE_SZ_OFFSET (INIT_HCA_MCAST_OFFSET + 0x1b)
619#define INIT_HCA_TPT_OFFSET 0x0f0
620#define INIT_HCA_DMPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x00)
621#define INIT_HCA_LOG_MPT_SZ_OFFSET (INIT_HCA_TPT_OFFSET + 0x0b)
622#define INIT_HCA_MTT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x10)
623#define INIT_HCA_CMPT_BASE_OFFSET (INIT_HCA_TPT_OFFSET + 0x18)
624#define INIT_HCA_UAR_OFFSET 0x120
625#define INIT_HCA_LOG_UAR_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0a)
626#define INIT_HCA_UAR_PAGE_SZ_OFFSET (INIT_HCA_UAR_OFFSET + 0x0b)
627
628 mailbox = mlx4_alloc_cmd_mailbox(dev);
629 if (IS_ERR(mailbox))
630 return PTR_ERR(mailbox);
631 inbox = mailbox->buf;
632
633 memset(inbox, 0, INIT_HCA_IN_SIZE);
634
635 *((u8 *) mailbox->buf + INIT_HCA_VERSION_OFFSET) = INIT_HCA_VERSION;
636
637#if defined(__LITTLE_ENDIAN)
638 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) &= ~cpu_to_be32(1 << 1);
639#elif defined(__BIG_ENDIAN)
640 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1 << 1);
641#else
642#error Host endianness not defined
643#endif
644 /* Check port for UD address vector: */
645 *(inbox + INIT_HCA_FLAGS_OFFSET / 4) |= cpu_to_be32(1);
646
647 /* QPC/EEC/CQC/EQC/RDMARC attributes */
648
649 MLX4_PUT(inbox, param->qpc_base, INIT_HCA_QPC_BASE_OFFSET);
650 MLX4_PUT(inbox, param->log_num_qps, INIT_HCA_LOG_QP_OFFSET);
651 MLX4_PUT(inbox, param->srqc_base, INIT_HCA_SRQC_BASE_OFFSET);
652 MLX4_PUT(inbox, param->log_num_srqs, INIT_HCA_LOG_SRQ_OFFSET);
653 MLX4_PUT(inbox, param->cqc_base, INIT_HCA_CQC_BASE_OFFSET);
654 MLX4_PUT(inbox, param->log_num_cqs, INIT_HCA_LOG_CQ_OFFSET);
655 MLX4_PUT(inbox, param->altc_base, INIT_HCA_ALTC_BASE_OFFSET);
656 MLX4_PUT(inbox, param->auxc_base, INIT_HCA_AUXC_BASE_OFFSET);
657 MLX4_PUT(inbox, param->eqc_base, INIT_HCA_EQC_BASE_OFFSET);
658 MLX4_PUT(inbox, param->log_num_eqs, INIT_HCA_LOG_EQ_OFFSET);
659 MLX4_PUT(inbox, param->rdmarc_base, INIT_HCA_RDMARC_BASE_OFFSET);
660 MLX4_PUT(inbox, param->log_rd_per_qp, INIT_HCA_LOG_RD_OFFSET);
661
662 /* multicast attributes */
663
664 MLX4_PUT(inbox, param->mc_base, INIT_HCA_MC_BASE_OFFSET);
665 MLX4_PUT(inbox, param->log_mc_entry_sz, INIT_HCA_LOG_MC_ENTRY_SZ_OFFSET);
666 MLX4_PUT(inbox, param->log_mc_hash_sz, INIT_HCA_LOG_MC_HASH_SZ_OFFSET);
667 MLX4_PUT(inbox, param->log_mc_table_sz, INIT_HCA_LOG_MC_TABLE_SZ_OFFSET);
668
669 /* TPT attributes */
670
671 MLX4_PUT(inbox, param->dmpt_base, INIT_HCA_DMPT_BASE_OFFSET);
672 MLX4_PUT(inbox, param->log_mpt_sz, INIT_HCA_LOG_MPT_SZ_OFFSET);
673 MLX4_PUT(inbox, param->mtt_base, INIT_HCA_MTT_BASE_OFFSET);
674 MLX4_PUT(inbox, param->cmpt_base, INIT_HCA_CMPT_BASE_OFFSET);
675
676 /* UAR attributes */
677
678 MLX4_PUT(inbox, (u8) (PAGE_SHIFT - 12), INIT_HCA_UAR_PAGE_SZ_OFFSET);
679 MLX4_PUT(inbox, param->log_uar_sz, INIT_HCA_LOG_UAR_SZ_OFFSET);
680
681 err = mlx4_cmd(dev, mailbox->dma, 0, 0, MLX4_CMD_INIT_HCA, 1000);
682
683 if (err)
684 mlx4_err(dev, "INIT_HCA returns %d\n", err);
685
686 mlx4_free_cmd_mailbox(dev, mailbox);
687 return err;
688}
689
690int mlx4_INIT_PORT(struct mlx4_dev *dev, struct mlx4_init_port_param *param, int port)
691{
692 struct mlx4_cmd_mailbox *mailbox;
693 u32 *inbox;
694 int err;
695 u32 flags;
696
697#define INIT_PORT_IN_SIZE 256
698#define INIT_PORT_FLAGS_OFFSET 0x00
699#define INIT_PORT_FLAG_SIG (1 << 18)
700#define INIT_PORT_FLAG_NG (1 << 17)
701#define INIT_PORT_FLAG_G0 (1 << 16)
702#define INIT_PORT_VL_SHIFT 4
703#define INIT_PORT_PORT_WIDTH_SHIFT 8
704#define INIT_PORT_MTU_OFFSET 0x04
705#define INIT_PORT_MAX_GID_OFFSET 0x06
706#define INIT_PORT_MAX_PKEY_OFFSET 0x0a
707#define INIT_PORT_GUID0_OFFSET 0x10
708#define INIT_PORT_NODE_GUID_OFFSET 0x18
709#define INIT_PORT_SI_GUID_OFFSET 0x20
710
711 mailbox = mlx4_alloc_cmd_mailbox(dev);
712 if (IS_ERR(mailbox))
713 return PTR_ERR(mailbox);
714 inbox = mailbox->buf;
715
716 memset(inbox, 0, INIT_PORT_IN_SIZE);
717
718 flags = 0;
719 flags |= param->set_guid0 ? INIT_PORT_FLAG_G0 : 0;
720 flags |= param->set_node_guid ? INIT_PORT_FLAG_NG : 0;
721 flags |= param->set_si_guid ? INIT_PORT_FLAG_SIG : 0;
722 flags |= (param->vl_cap & 0xf) << INIT_PORT_VL_SHIFT;
723 flags |= (param->port_width_cap & 0xf) << INIT_PORT_PORT_WIDTH_SHIFT;
724 MLX4_PUT(inbox, flags, INIT_PORT_FLAGS_OFFSET);
725
726 MLX4_PUT(inbox, param->mtu, INIT_PORT_MTU_OFFSET);
727 MLX4_PUT(inbox, param->max_gid, INIT_PORT_MAX_GID_OFFSET);
728 MLX4_PUT(inbox, param->max_pkey, INIT_PORT_MAX_PKEY_OFFSET);
729 MLX4_PUT(inbox, param->guid0, INIT_PORT_GUID0_OFFSET);
730 MLX4_PUT(inbox, param->node_guid, INIT_PORT_NODE_GUID_OFFSET);
731 MLX4_PUT(inbox, param->si_guid, INIT_PORT_SI_GUID_OFFSET);
732
733 err = mlx4_cmd(dev, mailbox->dma, port, 0, MLX4_CMD_INIT_PORT,
734 MLX4_CMD_TIME_CLASS_A);
735
736 mlx4_free_cmd_mailbox(dev, mailbox);
737
738 return err;
739}
740EXPORT_SYMBOL_GPL(mlx4_INIT_PORT);
741
742int mlx4_CLOSE_PORT(struct mlx4_dev *dev, int port)
743{
744 return mlx4_cmd(dev, 0, port, 0, MLX4_CMD_CLOSE_PORT, 1000);
745}
746EXPORT_SYMBOL_GPL(mlx4_CLOSE_PORT);
747
748int mlx4_CLOSE_HCA(struct mlx4_dev *dev, int panic)
749{
750 return mlx4_cmd(dev, 0, 0, panic, MLX4_CMD_CLOSE_HCA, 1000);
751}
752
753int mlx4_SET_ICM_SIZE(struct mlx4_dev *dev, u64 icm_size, u64 *aux_pages)
754{
755 int ret = mlx4_cmd_imm(dev, icm_size, aux_pages, 0, 0,
756 MLX4_CMD_SET_ICM_SIZE,
757 MLX4_CMD_TIME_CLASS_A);
758 if (ret)
759 return ret;
760
761 /*
762 * Round up number of system pages needed in case
763 * MLX4_ICM_PAGE_SIZE < PAGE_SIZE.
764 */
765 *aux_pages = ALIGN(*aux_pages, PAGE_SIZE / MLX4_ICM_PAGE_SIZE) >>
766 (PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT);
767
768 return 0;
769}
770
771int mlx4_NOP(struct mlx4_dev *dev)
772{
773 /* Input modifier of 0x1f means "finish as soon as possible." */
774 return mlx4_cmd(dev, 0, 0x1f, 0, MLX4_CMD_NOP, 100);
775}
diff --git a/drivers/net/mlx4/fw.h b/drivers/net/mlx4/fw.h
new file mode 100644
index 000000000000..2616fa53d4d0
--- /dev/null
+++ b/drivers/net/mlx4/fw.h
@@ -0,0 +1,167 @@
1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2006, 2007 Cisco Systems. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#ifndef MLX4_FW_H
36#define MLX4_FW_H
37
38#include "mlx4.h"
39#include "icm.h"
40
41struct mlx4_dev_cap {
42 int max_srq_sz;
43 int max_qp_sz;
44 int reserved_qps;
45 int max_qps;
46 int reserved_srqs;
47 int max_srqs;
48 int max_cq_sz;
49 int reserved_cqs;
50 int max_cqs;
51 int max_mpts;
52 int reserved_eqs;
53 int max_eqs;
54 int reserved_mtts;
55 int max_mrw_sz;
56 int reserved_mrws;
57 int max_mtt_seg;
58 int max_requester_per_qp;
59 int max_responder_per_qp;
60 int max_rdma_global;
61 int local_ca_ack_delay;
62 int max_mtu;
63 int max_port_width;
64 int max_vl;
65 int num_ports;
66 int max_gids;
67 u16 stat_rate_support;
68 int max_pkeys;
69 u32 flags;
70 int reserved_uars;
71 int uar_size;
72 int min_page_sz;
73 int bf_reg_size;
74 int bf_regs_per_page;
75 int max_sq_sg;
76 int max_sq_desc_sz;
77 int max_rq_sg;
78 int max_rq_desc_sz;
79 int max_qp_per_mcg;
80 int reserved_mgms;
81 int max_mcgs;
82 int reserved_pds;
83 int max_pds;
84 int qpc_entry_sz;
85 int rdmarc_entry_sz;
86 int altc_entry_sz;
87 int aux_entry_sz;
88 int srq_entry_sz;
89 int cqc_entry_sz;
90 int eqc_entry_sz;
91 int dmpt_entry_sz;
92 int cmpt_entry_sz;
93 int mtt_entry_sz;
94 int resize_srq;
95 u8 bmme_flags;
96 u32 reserved_lkey;
97 u64 max_icm_sz;
98};
99
100struct mlx4_adapter {
101 u32 vendor_id;
102 u32 device_id;
103 u32 revision_id;
104 char board_id[MLX4_BOARD_ID_LEN];
105 u8 inta_pin;
106};
107
108struct mlx4_init_hca_param {
109 u64 qpc_base;
110 u64 rdmarc_base;
111 u64 auxc_base;
112 u64 altc_base;
113 u64 srqc_base;
114 u64 cqc_base;
115 u64 eqc_base;
116 u64 mc_base;
117 u64 dmpt_base;
118 u64 cmpt_base;
119 u64 mtt_base;
120 u16 log_mc_entry_sz;
121 u16 log_mc_hash_sz;
122 u8 log_num_qps;
123 u8 log_num_srqs;
124 u8 log_num_cqs;
125 u8 log_num_eqs;
126 u8 log_rd_per_qp;
127 u8 log_mc_table_sz;
128 u8 log_mpt_sz;
129 u8 log_uar_sz;
130};
131
132struct mlx4_init_ib_param {
133 int port_width;
134 int vl_cap;
135 int mtu_cap;
136 u16 gid_cap;
137 u16 pkey_cap;
138 int set_guid0;
139 u64 guid0;
140 int set_node_guid;
141 u64 node_guid;
142 int set_si_guid;
143 u64 si_guid;
144};
145
146struct mlx4_set_ib_param {
147 int set_si_guid;
148 int reset_qkey_viol;
149 u64 si_guid;
150 u32 cap_mask;
151};
152
153int mlx4_QUERY_DEV_CAP(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap);
154int mlx4_MAP_FA(struct mlx4_dev *dev, struct mlx4_icm *icm);
155int mlx4_UNMAP_FA(struct mlx4_dev *dev);
156int mlx4_RUN_FW(struct mlx4_dev *dev);
157int mlx4_QUERY_FW(struct mlx4_dev *dev);
158int mlx4_QUERY_ADAPTER(struct mlx4_dev *dev, struct mlx4_adapter *adapter);
159int mlx4_INIT_HCA(struct mlx4_dev *dev, struct mlx4_init_hca_param *param);
160int mlx4_CLOSE_HCA(struct mlx4_dev *dev, int panic);
161int mlx4_map_cmd(struct mlx4_dev *dev, u16 op, struct mlx4_icm *icm, u64 virt);
162int mlx4_SET_ICM_SIZE(struct mlx4_dev *dev, u64 icm_size, u64 *aux_pages);
163int mlx4_MAP_ICM_AUX(struct mlx4_dev *dev, struct mlx4_icm *icm);
164int mlx4_UNMAP_ICM_AUX(struct mlx4_dev *dev);
165int mlx4_NOP(struct mlx4_dev *dev);
166
167#endif /* MLX4_FW_H */
diff --git a/drivers/net/mlx4/icm.c b/drivers/net/mlx4/icm.c
new file mode 100644
index 000000000000..b7a4aa8476fb
--- /dev/null
+++ b/drivers/net/mlx4/icm.c
@@ -0,0 +1,380 @@
1/*
2 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
3 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <linux/init.h>
35#include <linux/errno.h>
36#include <linux/mm.h>
37
38#include <linux/mlx4/cmd.h>
39
40#include "mlx4.h"
41#include "icm.h"
42#include "fw.h"
43
44/*
45 * We allocate in as big chunks as we can, up to a maximum of 256 KB
46 * per chunk.
47 */
48enum {
49 MLX4_ICM_ALLOC_SIZE = 1 << 18,
50 MLX4_TABLE_CHUNK_SIZE = 1 << 18
51};
52
53void mlx4_free_icm(struct mlx4_dev *dev, struct mlx4_icm *icm)
54{
55 struct mlx4_icm_chunk *chunk, *tmp;
56 int i;
57
58 list_for_each_entry_safe(chunk, tmp, &icm->chunk_list, list) {
59 if (chunk->nsg > 0)
60 pci_unmap_sg(dev->pdev, chunk->mem, chunk->npages,
61 PCI_DMA_BIDIRECTIONAL);
62
63 for (i = 0; i < chunk->npages; ++i)
64 __free_pages(chunk->mem[i].page,
65 get_order(chunk->mem[i].length));
66
67 kfree(chunk);
68 }
69
70 kfree(icm);
71}
72
73struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages,
74 gfp_t gfp_mask)
75{
76 struct mlx4_icm *icm;
77 struct mlx4_icm_chunk *chunk = NULL;
78 int cur_order;
79
80 icm = kmalloc(sizeof *icm, gfp_mask & ~(__GFP_HIGHMEM | __GFP_NOWARN));
81 if (!icm)
82 return icm;
83
84 icm->refcount = 0;
85 INIT_LIST_HEAD(&icm->chunk_list);
86
87 cur_order = get_order(MLX4_ICM_ALLOC_SIZE);
88
89 while (npages > 0) {
90 if (!chunk) {
91 chunk = kmalloc(sizeof *chunk,
92 gfp_mask & ~(__GFP_HIGHMEM | __GFP_NOWARN));
93 if (!chunk)
94 goto fail;
95
96 chunk->npages = 0;
97 chunk->nsg = 0;
98 list_add_tail(&chunk->list, &icm->chunk_list);
99 }
100
101 while (1 << cur_order > npages)
102 --cur_order;
103
104 chunk->mem[chunk->npages].page = alloc_pages(gfp_mask, cur_order);
105 if (chunk->mem[chunk->npages].page) {
106 chunk->mem[chunk->npages].length = PAGE_SIZE << cur_order;
107 chunk->mem[chunk->npages].offset = 0;
108
109 if (++chunk->npages == MLX4_ICM_CHUNK_LEN) {
110 chunk->nsg = pci_map_sg(dev->pdev, chunk->mem,
111 chunk->npages,
112 PCI_DMA_BIDIRECTIONAL);
113
114 if (chunk->nsg <= 0)
115 goto fail;
116
117 chunk = NULL;
118 }
119
120 npages -= 1 << cur_order;
121 } else {
122 --cur_order;
123 if (cur_order < 0)
124 goto fail;
125 }
126 }
127
128 if (chunk) {
129 chunk->nsg = pci_map_sg(dev->pdev, chunk->mem,
130 chunk->npages,
131 PCI_DMA_BIDIRECTIONAL);
132
133 if (chunk->nsg <= 0)
134 goto fail;
135 }
136
137 return icm;
138
139fail:
140 mlx4_free_icm(dev, icm);
141 return NULL;
142}
143
144static int mlx4_MAP_ICM(struct mlx4_dev *dev, struct mlx4_icm *icm, u64 virt)
145{
146 return mlx4_map_cmd(dev, MLX4_CMD_MAP_ICM, icm, virt);
147}
148
149int mlx4_UNMAP_ICM(struct mlx4_dev *dev, u64 virt, u32 page_count)
150{
151 return mlx4_cmd(dev, virt, page_count, 0, MLX4_CMD_UNMAP_ICM,
152 MLX4_CMD_TIME_CLASS_B);
153}
154
155int mlx4_MAP_ICM_page(struct mlx4_dev *dev, u64 dma_addr, u64 virt)
156{
157 struct mlx4_cmd_mailbox *mailbox;
158 __be64 *inbox;
159 int err;
160
161 mailbox = mlx4_alloc_cmd_mailbox(dev);
162 if (IS_ERR(mailbox))
163 return PTR_ERR(mailbox);
164 inbox = mailbox->buf;
165
166 inbox[0] = cpu_to_be64(virt);
167 inbox[1] = cpu_to_be64(dma_addr);
168
169 err = mlx4_cmd(dev, mailbox->dma, 1, 0, MLX4_CMD_MAP_ICM,
170 MLX4_CMD_TIME_CLASS_B);
171
172 mlx4_free_cmd_mailbox(dev, mailbox);
173
174 if (!err)
175 mlx4_dbg(dev, "Mapped page at %llx to %llx for ICM.\n",
176 (unsigned long long) dma_addr, (unsigned long long) virt);
177
178 return err;
179}
180
181int mlx4_MAP_ICM_AUX(struct mlx4_dev *dev, struct mlx4_icm *icm)
182{
183 return mlx4_map_cmd(dev, MLX4_CMD_MAP_ICM_AUX, icm, -1);
184}
185
186int mlx4_UNMAP_ICM_AUX(struct mlx4_dev *dev)
187{
188 return mlx4_cmd(dev, 0, 0, 0, MLX4_CMD_UNMAP_ICM_AUX, MLX4_CMD_TIME_CLASS_B);
189}
190
191int mlx4_table_get(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj)
192{
193 int i = (obj & (table->num_obj - 1)) / (MLX4_TABLE_CHUNK_SIZE / table->obj_size);
194 int ret = 0;
195
196 mutex_lock(&table->mutex);
197
198 if (table->icm[i]) {
199 ++table->icm[i]->refcount;
200 goto out;
201 }
202
203 table->icm[i] = mlx4_alloc_icm(dev, MLX4_TABLE_CHUNK_SIZE >> PAGE_SHIFT,
204 (table->lowmem ? GFP_KERNEL : GFP_HIGHUSER) |
205 __GFP_NOWARN);
206 if (!table->icm[i]) {
207 ret = -ENOMEM;
208 goto out;
209 }
210
211 if (mlx4_MAP_ICM(dev, table->icm[i], table->virt +
212 (u64) i * MLX4_TABLE_CHUNK_SIZE)) {
213 mlx4_free_icm(dev, table->icm[i]);
214 table->icm[i] = NULL;
215 ret = -ENOMEM;
216 goto out;
217 }
218
219 ++table->icm[i]->refcount;
220
221out:
222 mutex_unlock(&table->mutex);
223 return ret;
224}
225
226void mlx4_table_put(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj)
227{
228 int i;
229
230 i = (obj & (table->num_obj - 1)) / (MLX4_TABLE_CHUNK_SIZE / table->obj_size);
231
232 mutex_lock(&table->mutex);
233
234 if (--table->icm[i]->refcount == 0) {
235 mlx4_UNMAP_ICM(dev, table->virt + i * MLX4_TABLE_CHUNK_SIZE,
236 MLX4_TABLE_CHUNK_SIZE / MLX4_ICM_PAGE_SIZE);
237 mlx4_free_icm(dev, table->icm[i]);
238 table->icm[i] = NULL;
239 }
240
241 mutex_unlock(&table->mutex);
242}
243
244void *mlx4_table_find(struct mlx4_icm_table *table, int obj)
245{
246 int idx, offset, i;
247 struct mlx4_icm_chunk *chunk;
248 struct mlx4_icm *icm;
249 struct page *page = NULL;
250
251 if (!table->lowmem)
252 return NULL;
253
254 mutex_lock(&table->mutex);
255
256 idx = obj & (table->num_obj - 1);
257 icm = table->icm[idx / (MLX4_TABLE_CHUNK_SIZE / table->obj_size)];
258 offset = idx % (MLX4_TABLE_CHUNK_SIZE / table->obj_size);
259
260 if (!icm)
261 goto out;
262
263 list_for_each_entry(chunk, &icm->chunk_list, list) {
264 for (i = 0; i < chunk->npages; ++i) {
265 if (chunk->mem[i].length > offset) {
266 page = chunk->mem[i].page;
267 goto out;
268 }
269 offset -= chunk->mem[i].length;
270 }
271 }
272
273out:
274 mutex_unlock(&table->mutex);
275 return page ? lowmem_page_address(page) + offset : NULL;
276}
277
278int mlx4_table_get_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
279 int start, int end)
280{
281 int inc = MLX4_TABLE_CHUNK_SIZE / table->obj_size;
282 int i, err;
283
284 for (i = start; i <= end; i += inc) {
285 err = mlx4_table_get(dev, table, i);
286 if (err)
287 goto fail;
288 }
289
290 return 0;
291
292fail:
293 while (i > start) {
294 i -= inc;
295 mlx4_table_put(dev, table, i);
296 }
297
298 return err;
299}
300
301void mlx4_table_put_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
302 int start, int end)
303{
304 int i;
305
306 for (i = start; i <= end; i += MLX4_TABLE_CHUNK_SIZE / table->obj_size)
307 mlx4_table_put(dev, table, i);
308}
309
310int mlx4_init_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table,
311 u64 virt, int obj_size, int nobj, int reserved,
312 int use_lowmem)
313{
314 int obj_per_chunk;
315 int num_icm;
316 unsigned chunk_size;
317 int i;
318
319 obj_per_chunk = MLX4_TABLE_CHUNK_SIZE / obj_size;
320 num_icm = (nobj + obj_per_chunk - 1) / obj_per_chunk;
321
322 table->icm = kcalloc(num_icm, sizeof *table->icm, GFP_KERNEL);
323 if (!table->icm)
324 return -ENOMEM;
325 table->virt = virt;
326 table->num_icm = num_icm;
327 table->num_obj = nobj;
328 table->obj_size = obj_size;
329 table->lowmem = use_lowmem;
330 mutex_init(&table->mutex);
331
332 for (i = 0; i * MLX4_TABLE_CHUNK_SIZE < reserved * obj_size; ++i) {
333 chunk_size = MLX4_TABLE_CHUNK_SIZE;
334 if ((i + 1) * MLX4_TABLE_CHUNK_SIZE > nobj * obj_size)
335 chunk_size = PAGE_ALIGN(nobj * obj_size - i * MLX4_TABLE_CHUNK_SIZE);
336
337 table->icm[i] = mlx4_alloc_icm(dev, chunk_size >> PAGE_SHIFT,
338 (use_lowmem ? GFP_KERNEL : GFP_HIGHUSER) |
339 __GFP_NOWARN);
340 if (!table->icm[i])
341 goto err;
342 if (mlx4_MAP_ICM(dev, table->icm[i], virt + i * MLX4_TABLE_CHUNK_SIZE)) {
343 mlx4_free_icm(dev, table->icm[i]);
344 table->icm[i] = NULL;
345 goto err;
346 }
347
348 /*
349 * Add a reference to this ICM chunk so that it never
350 * gets freed (since it contains reserved firmware objects).
351 */
352 ++table->icm[i]->refcount;
353 }
354
355 return 0;
356
357err:
358 for (i = 0; i < num_icm; ++i)
359 if (table->icm[i]) {
360 mlx4_UNMAP_ICM(dev, virt + i * MLX4_TABLE_CHUNK_SIZE,
361 MLX4_TABLE_CHUNK_SIZE / MLX4_ICM_PAGE_SIZE);
362 mlx4_free_icm(dev, table->icm[i]);
363 }
364
365 return -ENOMEM;
366}
367
368void mlx4_cleanup_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table)
369{
370 int i;
371
372 for (i = 0; i < table->num_icm; ++i)
373 if (table->icm[i]) {
374 mlx4_UNMAP_ICM(dev, table->virt + i * MLX4_TABLE_CHUNK_SIZE,
375 MLX4_TABLE_CHUNK_SIZE / MLX4_ICM_PAGE_SIZE);
376 mlx4_free_icm(dev, table->icm[i]);
377 }
378
379 kfree(table->icm);
380}
diff --git a/drivers/net/mlx4/icm.h b/drivers/net/mlx4/icm.h
new file mode 100644
index 000000000000..bea223d879a5
--- /dev/null
+++ b/drivers/net/mlx4/icm.h
@@ -0,0 +1,135 @@
1/*
2 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
3 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#ifndef MLX4_ICM_H
35#define MLX4_ICM_H
36
37#include <linux/list.h>
38#include <linux/pci.h>
39#include <linux/mutex.h>
40
41#define MLX4_ICM_CHUNK_LEN \
42 ((256 - sizeof (struct list_head) - 2 * sizeof (int)) / \
43 (sizeof (struct scatterlist)))
44
45enum {
46 MLX4_ICM_PAGE_SHIFT = 12,
47 MLX4_ICM_PAGE_SIZE = 1 << MLX4_ICM_PAGE_SHIFT,
48};
49
50struct mlx4_icm_chunk {
51 struct list_head list;
52 int npages;
53 int nsg;
54 struct scatterlist mem[MLX4_ICM_CHUNK_LEN];
55};
56
57struct mlx4_icm {
58 struct list_head chunk_list;
59 int refcount;
60};
61
62struct mlx4_icm_iter {
63 struct mlx4_icm *icm;
64 struct mlx4_icm_chunk *chunk;
65 int page_idx;
66};
67
68struct mlx4_dev;
69
70struct mlx4_icm *mlx4_alloc_icm(struct mlx4_dev *dev, int npages, gfp_t gfp_mask);
71void mlx4_free_icm(struct mlx4_dev *dev, struct mlx4_icm *icm);
72
73int mlx4_table_get(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj);
74void mlx4_table_put(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj);
75int mlx4_table_get_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
76 int start, int end);
77void mlx4_table_put_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
78 int start, int end);
79int mlx4_init_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table,
80 u64 virt, int obj_size, int nobj, int reserved,
81 int use_lowmem);
82void mlx4_cleanup_icm_table(struct mlx4_dev *dev, struct mlx4_icm_table *table);
83int mlx4_table_get(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj);
84void mlx4_table_put(struct mlx4_dev *dev, struct mlx4_icm_table *table, int obj);
85void *mlx4_table_find(struct mlx4_icm_table *table, int obj);
86int mlx4_table_get_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
87 int start, int end);
88void mlx4_table_put_range(struct mlx4_dev *dev, struct mlx4_icm_table *table,
89 int start, int end);
90
91static inline void mlx4_icm_first(struct mlx4_icm *icm,
92 struct mlx4_icm_iter *iter)
93{
94 iter->icm = icm;
95 iter->chunk = list_empty(&icm->chunk_list) ?
96 NULL : list_entry(icm->chunk_list.next,
97 struct mlx4_icm_chunk, list);
98 iter->page_idx = 0;
99}
100
101static inline int mlx4_icm_last(struct mlx4_icm_iter *iter)
102{
103 return !iter->chunk;
104}
105
106static inline void mlx4_icm_next(struct mlx4_icm_iter *iter)
107{
108 if (++iter->page_idx >= iter->chunk->nsg) {
109 if (iter->chunk->list.next == &iter->icm->chunk_list) {
110 iter->chunk = NULL;
111 return;
112 }
113
114 iter->chunk = list_entry(iter->chunk->list.next,
115 struct mlx4_icm_chunk, list);
116 iter->page_idx = 0;
117 }
118}
119
120static inline dma_addr_t mlx4_icm_addr(struct mlx4_icm_iter *iter)
121{
122 return sg_dma_address(&iter->chunk->mem[iter->page_idx]);
123}
124
125static inline unsigned long mlx4_icm_size(struct mlx4_icm_iter *iter)
126{
127 return sg_dma_len(&iter->chunk->mem[iter->page_idx]);
128}
129
130int mlx4_UNMAP_ICM(struct mlx4_dev *dev, u64 virt, u32 page_count);
131int mlx4_MAP_ICM_page(struct mlx4_dev *dev, u64 dma_addr, u64 virt);
132int mlx4_MAP_ICM_AUX(struct mlx4_dev *dev, struct mlx4_icm *icm);
133int mlx4_UNMAP_ICM_AUX(struct mlx4_dev *dev);
134
135#endif /* MLX4_ICM_H */
diff --git a/drivers/net/mlx4/intf.c b/drivers/net/mlx4/intf.c
new file mode 100644
index 000000000000..65854f9e9c76
--- /dev/null
+++ b/drivers/net/mlx4/intf.c
@@ -0,0 +1,165 @@
1/*
2 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/mlx4/driver.h>
34
35#include "mlx4.h"
36
37struct mlx4_device_context {
38 struct list_head list;
39 struct mlx4_interface *intf;
40 void *context;
41};
42
43static LIST_HEAD(intf_list);
44static LIST_HEAD(dev_list);
45static DEFINE_MUTEX(intf_mutex);
46
47static void mlx4_add_device(struct mlx4_interface *intf, struct mlx4_priv *priv)
48{
49 struct mlx4_device_context *dev_ctx;
50
51 dev_ctx = kmalloc(sizeof *dev_ctx, GFP_KERNEL);
52 if (!dev_ctx)
53 return;
54
55 dev_ctx->intf = intf;
56 dev_ctx->context = intf->add(&priv->dev);
57
58 if (dev_ctx->context) {
59 spin_lock_irq(&priv->ctx_lock);
60 list_add_tail(&dev_ctx->list, &priv->ctx_list);
61 spin_unlock_irq(&priv->ctx_lock);
62 } else
63 kfree(dev_ctx);
64}
65
66static void mlx4_remove_device(struct mlx4_interface *intf, struct mlx4_priv *priv)
67{
68 struct mlx4_device_context *dev_ctx;
69
70 list_for_each_entry(dev_ctx, &priv->ctx_list, list)
71 if (dev_ctx->intf == intf) {
72 spin_lock_irq(&priv->ctx_lock);
73 list_del(&dev_ctx->list);
74 spin_unlock_irq(&priv->ctx_lock);
75
76 intf->remove(&priv->dev, dev_ctx->context);
77 kfree(dev_ctx);
78 return;
79 }
80}
81
82int mlx4_register_interface(struct mlx4_interface *intf)
83{
84 struct mlx4_priv *priv;
85
86 if (!intf->add || !intf->remove)
87 return -EINVAL;
88
89 mutex_lock(&intf_mutex);
90
91 list_add_tail(&intf->list, &intf_list);
92 list_for_each_entry(priv, &dev_list, dev_list)
93 mlx4_add_device(intf, priv);
94
95 mutex_unlock(&intf_mutex);
96
97 return 0;
98}
99EXPORT_SYMBOL_GPL(mlx4_register_interface);
100
101void mlx4_unregister_interface(struct mlx4_interface *intf)
102{
103 struct mlx4_priv *priv;
104
105 mutex_lock(&intf_mutex);
106
107 list_for_each_entry(priv, &dev_list, dev_list)
108 mlx4_remove_device(intf, priv);
109
110 list_del(&intf->list);
111
112 mutex_unlock(&intf_mutex);
113}
114EXPORT_SYMBOL_GPL(mlx4_unregister_interface);
115
116void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_event type,
117 int subtype, int port)
118{
119 struct mlx4_priv *priv = mlx4_priv(dev);
120 struct mlx4_device_context *dev_ctx;
121 unsigned long flags;
122
123 spin_lock_irqsave(&priv->ctx_lock, flags);
124
125 list_for_each_entry(dev_ctx, &priv->ctx_list, list)
126 if (dev_ctx->intf->event)
127 dev_ctx->intf->event(dev, dev_ctx->context, type,
128 subtype, port);
129
130 spin_unlock_irqrestore(&priv->ctx_lock, flags);
131}
132
133int mlx4_register_device(struct mlx4_dev *dev)
134{
135 struct mlx4_priv *priv = mlx4_priv(dev);
136 struct mlx4_interface *intf;
137
138 INIT_LIST_HEAD(&priv->ctx_list);
139 spin_lock_init(&priv->ctx_lock);
140
141 mutex_lock(&intf_mutex);
142
143 list_add_tail(&priv->dev_list, &dev_list);
144 list_for_each_entry(intf, &intf_list, list)
145 mlx4_add_device(intf, priv);
146
147 mutex_unlock(&intf_mutex);
148
149 return 0;
150}
151
152void mlx4_unregister_device(struct mlx4_dev *dev)
153{
154 struct mlx4_priv *priv = mlx4_priv(dev);
155 struct mlx4_interface *intf;
156
157 mutex_lock(&intf_mutex);
158
159 list_for_each_entry(intf, &intf_list, list)
160 mlx4_remove_device(intf, priv);
161
162 list_del(&priv->dev_list);
163
164 mutex_unlock(&intf_mutex);
165}
diff --git a/drivers/net/mlx4/main.c b/drivers/net/mlx4/main.c
new file mode 100644
index 000000000000..20b8c0d3ced4
--- /dev/null
+++ b/drivers/net/mlx4/main.c
@@ -0,0 +1,934 @@
1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
20 *
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * SOFTWARE.
34 */
35
36#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/errno.h>
39#include <linux/pci.h>
40#include <linux/dma-mapping.h>
41
42#include <linux/mlx4/device.h>
43#include <linux/mlx4/doorbell.h>
44
45#include "mlx4.h"
46#include "fw.h"
47#include "icm.h"
48
49MODULE_AUTHOR("Roland Dreier");
50MODULE_DESCRIPTION("Mellanox ConnectX HCA low-level driver");
51MODULE_LICENSE("Dual BSD/GPL");
52MODULE_VERSION(DRV_VERSION);
53
54#ifdef CONFIG_MLX4_DEBUG
55
56int mlx4_debug_level = 0;
57module_param_named(debug_level, mlx4_debug_level, int, 0644);
58MODULE_PARM_DESC(debug_level, "Enable debug tracing if > 0");
59
60#endif /* CONFIG_MLX4_DEBUG */
61
62#ifdef CONFIG_PCI_MSI
63
64static int msi_x;
65module_param(msi_x, int, 0444);
66MODULE_PARM_DESC(msi_x, "attempt to use MSI-X if nonzero");
67
68#else /* CONFIG_PCI_MSI */
69
70#define msi_x (0)
71
72#endif /* CONFIG_PCI_MSI */
73
74static const char mlx4_version[] __devinitdata =
75 DRV_NAME ": Mellanox ConnectX core driver v"
76 DRV_VERSION " (" DRV_RELDATE ")\n";
77
78static struct mlx4_profile default_profile = {
79 .num_qp = 1 << 16,
80 .num_srq = 1 << 16,
81 .rdmarc_per_qp = 4,
82 .num_cq = 1 << 16,
83 .num_mcg = 1 << 13,
84 .num_mpt = 1 << 17,
85 .num_mtt = 1 << 20,
86};
87
88static int __devinit mlx4_dev_cap(struct mlx4_dev *dev, struct mlx4_dev_cap *dev_cap)
89{
90 int err;
91
92 err = mlx4_QUERY_DEV_CAP(dev, dev_cap);
93 if (err) {
94 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
95 return err;
96 }
97
98 if (dev_cap->min_page_sz > PAGE_SIZE) {
99 mlx4_err(dev, "HCA minimum page size of %d bigger than "
100 "kernel PAGE_SIZE of %ld, aborting.\n",
101 dev_cap->min_page_sz, PAGE_SIZE);
102 return -ENODEV;
103 }
104 if (dev_cap->num_ports > MLX4_MAX_PORTS) {
105 mlx4_err(dev, "HCA has %d ports, but we only support %d, "
106 "aborting.\n",
107 dev_cap->num_ports, MLX4_MAX_PORTS);
108 return -ENODEV;
109 }
110
111 if (dev_cap->uar_size > pci_resource_len(dev->pdev, 2)) {
112 mlx4_err(dev, "HCA reported UAR size of 0x%x bigger than "
113 "PCI resource 2 size of 0x%llx, aborting.\n",
114 dev_cap->uar_size,
115 (unsigned long long) pci_resource_len(dev->pdev, 2));
116 return -ENODEV;
117 }
118
119 dev->caps.num_ports = dev_cap->num_ports;
120 dev->caps.num_uars = dev_cap->uar_size / PAGE_SIZE;
121 dev->caps.vl_cap = dev_cap->max_vl;
122 dev->caps.mtu_cap = dev_cap->max_mtu;
123 dev->caps.gid_table_len = dev_cap->max_gids;
124 dev->caps.pkey_table_len = dev_cap->max_pkeys;
125 dev->caps.local_ca_ack_delay = dev_cap->local_ca_ack_delay;
126 dev->caps.bf_reg_size = dev_cap->bf_reg_size;
127 dev->caps.bf_regs_per_page = dev_cap->bf_regs_per_page;
128 dev->caps.max_sq_sg = dev_cap->max_sq_sg;
129 dev->caps.max_rq_sg = dev_cap->max_rq_sg;
130 dev->caps.max_wqes = dev_cap->max_qp_sz;
131 dev->caps.max_qp_init_rdma = dev_cap->max_requester_per_qp;
132 dev->caps.reserved_qps = dev_cap->reserved_qps;
133 dev->caps.max_srq_wqes = dev_cap->max_srq_sz;
134 dev->caps.max_srq_sge = dev_cap->max_rq_sg - 1;
135 dev->caps.reserved_srqs = dev_cap->reserved_srqs;
136 dev->caps.max_sq_desc_sz = dev_cap->max_sq_desc_sz;
137 dev->caps.max_rq_desc_sz = dev_cap->max_rq_desc_sz;
138 dev->caps.num_qp_per_mgm = MLX4_QP_PER_MGM;
139 /*
140 * Subtract 1 from the limit because we need to allocate a
141 * spare CQE so the HCA HW can tell the difference between an
142 * empty CQ and a full CQ.
143 */
144 dev->caps.max_cqes = dev_cap->max_cq_sz - 1;
145 dev->caps.reserved_cqs = dev_cap->reserved_cqs;
146 dev->caps.reserved_eqs = dev_cap->reserved_eqs;
147 dev->caps.reserved_mtts = dev_cap->reserved_mtts;
148 dev->caps.reserved_mrws = dev_cap->reserved_mrws;
149 dev->caps.reserved_uars = dev_cap->reserved_uars;
150 dev->caps.reserved_pds = dev_cap->reserved_pds;
151 dev->caps.port_width_cap = dev_cap->max_port_width;
152 dev->caps.mtt_entry_sz = MLX4_MTT_ENTRY_PER_SEG * dev_cap->mtt_entry_sz;
153 dev->caps.page_size_cap = ~(u32) (dev_cap->min_page_sz - 1);
154 dev->caps.flags = dev_cap->flags;
155 dev->caps.stat_rate_support = dev_cap->stat_rate_support;
156
157 return 0;
158}
159
160static int __devinit mlx4_load_fw(struct mlx4_dev *dev)
161{
162 struct mlx4_priv *priv = mlx4_priv(dev);
163 int err;
164
165 priv->fw.fw_icm = mlx4_alloc_icm(dev, priv->fw.fw_pages,
166 GFP_HIGHUSER | __GFP_NOWARN);
167 if (!priv->fw.fw_icm) {
168 mlx4_err(dev, "Couldn't allocate FW area, aborting.\n");
169 return -ENOMEM;
170 }
171
172 err = mlx4_MAP_FA(dev, priv->fw.fw_icm);
173 if (err) {
174 mlx4_err(dev, "MAP_FA command failed, aborting.\n");
175 goto err_free;
176 }
177
178 err = mlx4_RUN_FW(dev);
179 if (err) {
180 mlx4_err(dev, "RUN_FW command failed, aborting.\n");
181 goto err_unmap_fa;
182 }
183
184 return 0;
185
186err_unmap_fa:
187 mlx4_UNMAP_FA(dev);
188
189err_free:
190 mlx4_free_icm(dev, priv->fw.fw_icm);
191 return err;
192}
193
194static int __devinit mlx4_init_cmpt_table(struct mlx4_dev *dev, u64 cmpt_base,
195 int cmpt_entry_sz)
196{
197 struct mlx4_priv *priv = mlx4_priv(dev);
198 int err;
199
200 err = mlx4_init_icm_table(dev, &priv->qp_table.cmpt_table,
201 cmpt_base +
202 ((u64) (MLX4_CMPT_TYPE_QP *
203 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
204 cmpt_entry_sz, dev->caps.num_qps,
205 dev->caps.reserved_qps, 0);
206 if (err)
207 goto err;
208
209 err = mlx4_init_icm_table(dev, &priv->srq_table.cmpt_table,
210 cmpt_base +
211 ((u64) (MLX4_CMPT_TYPE_SRQ *
212 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
213 cmpt_entry_sz, dev->caps.num_srqs,
214 dev->caps.reserved_srqs, 0);
215 if (err)
216 goto err_qp;
217
218 err = mlx4_init_icm_table(dev, &priv->cq_table.cmpt_table,
219 cmpt_base +
220 ((u64) (MLX4_CMPT_TYPE_CQ *
221 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
222 cmpt_entry_sz, dev->caps.num_cqs,
223 dev->caps.reserved_cqs, 0);
224 if (err)
225 goto err_srq;
226
227 err = mlx4_init_icm_table(dev, &priv->eq_table.cmpt_table,
228 cmpt_base +
229 ((u64) (MLX4_CMPT_TYPE_EQ *
230 cmpt_entry_sz) << MLX4_CMPT_SHIFT),
231 cmpt_entry_sz,
232 roundup_pow_of_two(MLX4_NUM_EQ +
233 dev->caps.reserved_eqs),
234 MLX4_NUM_EQ + dev->caps.reserved_eqs, 0);
235 if (err)
236 goto err_cq;
237
238 return 0;
239
240err_cq:
241 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
242
243err_srq:
244 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
245
246err_qp:
247 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
248
249err:
250 return err;
251}
252
253static int __devinit mlx4_init_icm(struct mlx4_dev *dev,
254 struct mlx4_dev_cap *dev_cap,
255 struct mlx4_init_hca_param *init_hca,
256 u64 icm_size)
257{
258 struct mlx4_priv *priv = mlx4_priv(dev);
259 u64 aux_pages;
260 int err;
261
262 err = mlx4_SET_ICM_SIZE(dev, icm_size, &aux_pages);
263 if (err) {
264 mlx4_err(dev, "SET_ICM_SIZE command failed, aborting.\n");
265 return err;
266 }
267
268 mlx4_dbg(dev, "%lld KB of HCA context requires %lld KB aux memory.\n",
269 (unsigned long long) icm_size >> 10,
270 (unsigned long long) aux_pages << 2);
271
272 priv->fw.aux_icm = mlx4_alloc_icm(dev, aux_pages,
273 GFP_HIGHUSER | __GFP_NOWARN);
274 if (!priv->fw.aux_icm) {
275 mlx4_err(dev, "Couldn't allocate aux memory, aborting.\n");
276 return -ENOMEM;
277 }
278
279 err = mlx4_MAP_ICM_AUX(dev, priv->fw.aux_icm);
280 if (err) {
281 mlx4_err(dev, "MAP_ICM_AUX command failed, aborting.\n");
282 goto err_free_aux;
283 }
284
285 err = mlx4_init_cmpt_table(dev, init_hca->cmpt_base, dev_cap->cmpt_entry_sz);
286 if (err) {
287 mlx4_err(dev, "Failed to map cMPT context memory, aborting.\n");
288 goto err_unmap_aux;
289 }
290
291 err = mlx4_map_eq_icm(dev, init_hca->eqc_base);
292 if (err) {
293 mlx4_err(dev, "Failed to map EQ context memory, aborting.\n");
294 goto err_unmap_cmpt;
295 }
296
297 err = mlx4_init_icm_table(dev, &priv->mr_table.mtt_table,
298 init_hca->mtt_base,
299 dev->caps.mtt_entry_sz,
300 dev->caps.num_mtt_segs,
301 dev->caps.reserved_mtts, 1);
302 if (err) {
303 mlx4_err(dev, "Failed to map MTT context memory, aborting.\n");
304 goto err_unmap_eq;
305 }
306
307 err = mlx4_init_icm_table(dev, &priv->mr_table.dmpt_table,
308 init_hca->dmpt_base,
309 dev_cap->dmpt_entry_sz,
310 dev->caps.num_mpts,
311 dev->caps.reserved_mrws, 1);
312 if (err) {
313 mlx4_err(dev, "Failed to map dMPT context memory, aborting.\n");
314 goto err_unmap_mtt;
315 }
316
317 err = mlx4_init_icm_table(dev, &priv->qp_table.qp_table,
318 init_hca->qpc_base,
319 dev_cap->qpc_entry_sz,
320 dev->caps.num_qps,
321 dev->caps.reserved_qps, 0);
322 if (err) {
323 mlx4_err(dev, "Failed to map QP context memory, aborting.\n");
324 goto err_unmap_dmpt;
325 }
326
327 err = mlx4_init_icm_table(dev, &priv->qp_table.auxc_table,
328 init_hca->auxc_base,
329 dev_cap->aux_entry_sz,
330 dev->caps.num_qps,
331 dev->caps.reserved_qps, 0);
332 if (err) {
333 mlx4_err(dev, "Failed to map AUXC context memory, aborting.\n");
334 goto err_unmap_qp;
335 }
336
337 err = mlx4_init_icm_table(dev, &priv->qp_table.altc_table,
338 init_hca->altc_base,
339 dev_cap->altc_entry_sz,
340 dev->caps.num_qps,
341 dev->caps.reserved_qps, 0);
342 if (err) {
343 mlx4_err(dev, "Failed to map ALTC context memory, aborting.\n");
344 goto err_unmap_auxc;
345 }
346
347 err = mlx4_init_icm_table(dev, &priv->qp_table.rdmarc_table,
348 init_hca->rdmarc_base,
349 dev_cap->rdmarc_entry_sz << priv->qp_table.rdmarc_shift,
350 dev->caps.num_qps,
351 dev->caps.reserved_qps, 0);
352 if (err) {
353 mlx4_err(dev, "Failed to map RDMARC context memory, aborting\n");
354 goto err_unmap_altc;
355 }
356
357 err = mlx4_init_icm_table(dev, &priv->cq_table.table,
358 init_hca->cqc_base,
359 dev_cap->cqc_entry_sz,
360 dev->caps.num_cqs,
361 dev->caps.reserved_cqs, 0);
362 if (err) {
363 mlx4_err(dev, "Failed to map CQ context memory, aborting.\n");
364 goto err_unmap_rdmarc;
365 }
366
367 err = mlx4_init_icm_table(dev, &priv->srq_table.table,
368 init_hca->srqc_base,
369 dev_cap->srq_entry_sz,
370 dev->caps.num_srqs,
371 dev->caps.reserved_srqs, 0);
372 if (err) {
373 mlx4_err(dev, "Failed to map SRQ context memory, aborting.\n");
374 goto err_unmap_cq;
375 }
376
377 /*
378 * It's not strictly required, but for simplicity just map the
379 * whole multicast group table now. The table isn't very big
380 * and it's a lot easier than trying to track ref counts.
381 */
382 err = mlx4_init_icm_table(dev, &priv->mcg_table.table,
383 init_hca->mc_base, MLX4_MGM_ENTRY_SIZE,
384 dev->caps.num_mgms + dev->caps.num_amgms,
385 dev->caps.num_mgms + dev->caps.num_amgms,
386 0);
387 if (err) {
388 mlx4_err(dev, "Failed to map MCG context memory, aborting.\n");
389 goto err_unmap_srq;
390 }
391
392 return 0;
393
394err_unmap_srq:
395 mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
396
397err_unmap_cq:
398 mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
399
400err_unmap_rdmarc:
401 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
402
403err_unmap_altc:
404 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
405
406err_unmap_auxc:
407 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
408
409err_unmap_qp:
410 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
411
412err_unmap_dmpt:
413 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
414
415err_unmap_mtt:
416 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
417
418err_unmap_eq:
419 mlx4_unmap_eq_icm(dev);
420
421err_unmap_cmpt:
422 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
423 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
424 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
425 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
426
427err_unmap_aux:
428 mlx4_UNMAP_ICM_AUX(dev);
429
430err_free_aux:
431 mlx4_free_icm(dev, priv->fw.aux_icm);
432
433 return err;
434}
435
436static void mlx4_free_icms(struct mlx4_dev *dev)
437{
438 struct mlx4_priv *priv = mlx4_priv(dev);
439
440 mlx4_cleanup_icm_table(dev, &priv->mcg_table.table);
441 mlx4_cleanup_icm_table(dev, &priv->srq_table.table);
442 mlx4_cleanup_icm_table(dev, &priv->cq_table.table);
443 mlx4_cleanup_icm_table(dev, &priv->qp_table.rdmarc_table);
444 mlx4_cleanup_icm_table(dev, &priv->qp_table.altc_table);
445 mlx4_cleanup_icm_table(dev, &priv->qp_table.auxc_table);
446 mlx4_cleanup_icm_table(dev, &priv->qp_table.qp_table);
447 mlx4_cleanup_icm_table(dev, &priv->mr_table.dmpt_table);
448 mlx4_cleanup_icm_table(dev, &priv->mr_table.mtt_table);
449 mlx4_cleanup_icm_table(dev, &priv->eq_table.cmpt_table);
450 mlx4_cleanup_icm_table(dev, &priv->cq_table.cmpt_table);
451 mlx4_cleanup_icm_table(dev, &priv->srq_table.cmpt_table);
452 mlx4_cleanup_icm_table(dev, &priv->qp_table.cmpt_table);
453 mlx4_unmap_eq_icm(dev);
454
455 mlx4_UNMAP_ICM_AUX(dev);
456 mlx4_free_icm(dev, priv->fw.aux_icm);
457}
458
459static void mlx4_close_hca(struct mlx4_dev *dev)
460{
461 mlx4_CLOSE_HCA(dev, 0);
462 mlx4_free_icms(dev);
463 mlx4_UNMAP_FA(dev);
464 mlx4_free_icm(dev, mlx4_priv(dev)->fw.fw_icm);
465}
466
467static int __devinit mlx4_init_hca(struct mlx4_dev *dev)
468{
469 struct mlx4_priv *priv = mlx4_priv(dev);
470 struct mlx4_adapter adapter;
471 struct mlx4_dev_cap dev_cap;
472 struct mlx4_profile profile;
473 struct mlx4_init_hca_param init_hca;
474 u64 icm_size;
475 int err;
476
477 err = mlx4_QUERY_FW(dev);
478 if (err) {
479 mlx4_err(dev, "QUERY_FW command failed, aborting.\n");
480 return err;
481 }
482
483 err = mlx4_load_fw(dev);
484 if (err) {
485 mlx4_err(dev, "Failed to start FW, aborting.\n");
486 return err;
487 }
488
489 err = mlx4_dev_cap(dev, &dev_cap);
490 if (err) {
491 mlx4_err(dev, "QUERY_DEV_CAP command failed, aborting.\n");
492 goto err_stop_fw;
493 }
494
495 profile = default_profile;
496
497 icm_size = mlx4_make_profile(dev, &profile, &dev_cap, &init_hca);
498 if ((long long) icm_size < 0) {
499 err = icm_size;
500 goto err_stop_fw;
501 }
502
503 init_hca.log_uar_sz = ilog2(dev->caps.num_uars);
504
505 err = mlx4_init_icm(dev, &dev_cap, &init_hca, icm_size);
506 if (err)
507 goto err_stop_fw;
508
509 err = mlx4_INIT_HCA(dev, &init_hca);
510 if (err) {
511 mlx4_err(dev, "INIT_HCA command failed, aborting.\n");
512 goto err_free_icm;
513 }
514
515 err = mlx4_QUERY_ADAPTER(dev, &adapter);
516 if (err) {
517 mlx4_err(dev, "QUERY_ADAPTER command failed, aborting.\n");
518 goto err_close;
519 }
520
521 priv->eq_table.inta_pin = adapter.inta_pin;
522 priv->rev_id = adapter.revision_id;
523 memcpy(priv->board_id, adapter.board_id, sizeof priv->board_id);
524
525 return 0;
526
527err_close:
528 mlx4_close_hca(dev);
529
530err_free_icm:
531 mlx4_free_icms(dev);
532
533err_stop_fw:
534 mlx4_UNMAP_FA(dev);
535 mlx4_free_icm(dev, priv->fw.fw_icm);
536
537 return err;
538}
539
540static int __devinit mlx4_setup_hca(struct mlx4_dev *dev)
541{
542 struct mlx4_priv *priv = mlx4_priv(dev);
543 int err;
544
545 err = mlx4_init_uar_table(dev);
546 if (err) {
547 mlx4_err(dev, "Failed to initialize "
548 "user access region table, aborting.\n");
549 return err;
550 }
551
552 err = mlx4_uar_alloc(dev, &priv->driver_uar);
553 if (err) {
554 mlx4_err(dev, "Failed to allocate driver access region, "
555 "aborting.\n");
556 goto err_uar_table_free;
557 }
558
559 priv->kar = ioremap(priv->driver_uar.pfn << PAGE_SHIFT, PAGE_SIZE);
560 if (!priv->kar) {
561 mlx4_err(dev, "Couldn't map kernel access region, "
562 "aborting.\n");
563 err = -ENOMEM;
564 goto err_uar_free;
565 }
566
567 err = mlx4_init_pd_table(dev);
568 if (err) {
569 mlx4_err(dev, "Failed to initialize "
570 "protection domain table, aborting.\n");
571 goto err_kar_unmap;
572 }
573
574 err = mlx4_init_mr_table(dev);
575 if (err) {
576 mlx4_err(dev, "Failed to initialize "
577 "memory region table, aborting.\n");
578 goto err_pd_table_free;
579 }
580
581 mlx4_map_catas_buf(dev);
582
583 err = mlx4_init_eq_table(dev);
584 if (err) {
585 mlx4_err(dev, "Failed to initialize "
586 "event queue table, aborting.\n");
587 goto err_catas_buf;
588 }
589
590 err = mlx4_cmd_use_events(dev);
591 if (err) {
592 mlx4_err(dev, "Failed to switch to event-driven "
593 "firmware commands, aborting.\n");
594 goto err_eq_table_free;
595 }
596
597 err = mlx4_NOP(dev);
598 if (err) {
599 mlx4_err(dev, "NOP command failed to generate interrupt "
600 "(IRQ %d), aborting.\n",
601 priv->eq_table.eq[MLX4_EQ_ASYNC].irq);
602 if (dev->flags & MLX4_FLAG_MSI_X)
603 mlx4_err(dev, "Try again with MSI-X disabled.\n");
604 else
605 mlx4_err(dev, "BIOS or ACPI interrupt routing problem?\n");
606
607 goto err_cmd_poll;
608 }
609
610 mlx4_dbg(dev, "NOP command IRQ test passed\n");
611
612 err = mlx4_init_cq_table(dev);
613 if (err) {
614 mlx4_err(dev, "Failed to initialize "
615 "completion queue table, aborting.\n");
616 goto err_cmd_poll;
617 }
618
619 err = mlx4_init_srq_table(dev);
620 if (err) {
621 mlx4_err(dev, "Failed to initialize "
622 "shared receive queue table, aborting.\n");
623 goto err_cq_table_free;
624 }
625
626 err = mlx4_init_qp_table(dev);
627 if (err) {
628 mlx4_err(dev, "Failed to initialize "
629 "queue pair table, aborting.\n");
630 goto err_srq_table_free;
631 }
632
633 err = mlx4_init_mcg_table(dev);
634 if (err) {
635 mlx4_err(dev, "Failed to initialize "
636 "multicast group table, aborting.\n");
637 goto err_qp_table_free;
638 }
639
640 return 0;
641
642err_qp_table_free:
643 mlx4_cleanup_qp_table(dev);
644
645err_srq_table_free:
646 mlx4_cleanup_srq_table(dev);
647
648err_cq_table_free:
649 mlx4_cleanup_cq_table(dev);
650
651err_cmd_poll:
652 mlx4_cmd_use_polling(dev);
653
654err_eq_table_free:
655 mlx4_cleanup_eq_table(dev);
656
657err_catas_buf:
658 mlx4_unmap_catas_buf(dev);
659 mlx4_cleanup_mr_table(dev);
660
661err_pd_table_free:
662 mlx4_cleanup_pd_table(dev);
663
664err_kar_unmap:
665 iounmap(priv->kar);
666
667err_uar_free:
668 mlx4_uar_free(dev, &priv->driver_uar);
669
670err_uar_table_free:
671 mlx4_cleanup_uar_table(dev);
672 return err;
673}
674
675static void __devinit mlx4_enable_msi_x(struct mlx4_dev *dev)
676{
677 struct mlx4_priv *priv = mlx4_priv(dev);
678 struct msix_entry entries[MLX4_NUM_EQ];
679 int err;
680 int i;
681
682 if (msi_x) {
683 for (i = 0; i < MLX4_NUM_EQ; ++i)
684 entries[i].entry = i;
685
686 err = pci_enable_msix(dev->pdev, entries, ARRAY_SIZE(entries));
687 if (err) {
688 if (err > 0)
689 mlx4_info(dev, "Only %d MSI-X vectors available, "
690 "not using MSI-X\n", err);
691 goto no_msi;
692 }
693
694 for (i = 0; i < MLX4_NUM_EQ; ++i)
695 priv->eq_table.eq[i].irq = entries[i].vector;
696
697 dev->flags |= MLX4_FLAG_MSI_X;
698 return;
699 }
700
701no_msi:
702 for (i = 0; i < MLX4_NUM_EQ; ++i)
703 priv->eq_table.eq[i].irq = dev->pdev->irq;
704}
705
706static int __devinit mlx4_init_one(struct pci_dev *pdev,
707 const struct pci_device_id *id)
708{
709 static int mlx4_version_printed;
710 struct mlx4_priv *priv;
711 struct mlx4_dev *dev;
712 int err;
713
714 if (!mlx4_version_printed) {
715 printk(KERN_INFO "%s", mlx4_version);
716 ++mlx4_version_printed;
717 }
718
719 printk(KERN_INFO PFX "Initializing %s\n",
720 pci_name(pdev));
721
722 err = pci_enable_device(pdev);
723 if (err) {
724 dev_err(&pdev->dev, "Cannot enable PCI device, "
725 "aborting.\n");
726 return err;
727 }
728
729 /*
730 * Check for BARs. We expect 0: 1MB, 2: 8MB, 4: DDR (may not
731 * be present)
732 */
733 if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM) ||
734 pci_resource_len(pdev, 0) != 1 << 20) {
735 dev_err(&pdev->dev, "Missing DCS, aborting.\n");
736 err = -ENODEV;
737 goto err_disable_pdev;
738 }
739 if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
740 dev_err(&pdev->dev, "Missing UAR, aborting.\n");
741 err = -ENODEV;
742 goto err_disable_pdev;
743 }
744
745 err = pci_request_region(pdev, 0, DRV_NAME);
746 if (err) {
747 dev_err(&pdev->dev, "Cannot request control region, aborting.\n");
748 goto err_disable_pdev;
749 }
750
751 err = pci_request_region(pdev, 2, DRV_NAME);
752 if (err) {
753 dev_err(&pdev->dev, "Cannot request UAR region, aborting.\n");
754 goto err_release_bar0;
755 }
756
757 pci_set_master(pdev);
758
759 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
760 if (err) {
761 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit PCI DMA mask.\n");
762 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
763 if (err) {
764 dev_err(&pdev->dev, "Can't set PCI DMA mask, aborting.\n");
765 goto err_release_bar2;
766 }
767 }
768 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
769 if (err) {
770 dev_warn(&pdev->dev, "Warning: couldn't set 64-bit "
771 "consistent PCI DMA mask.\n");
772 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
773 if (err) {
774 dev_err(&pdev->dev, "Can't set consistent PCI DMA mask, "
775 "aborting.\n");
776 goto err_release_bar2;
777 }
778 }
779
780 priv = kzalloc(sizeof *priv, GFP_KERNEL);
781 if (!priv) {
782 dev_err(&pdev->dev, "Device struct alloc failed, "
783 "aborting.\n");
784 err = -ENOMEM;
785 goto err_release_bar2;
786 }
787
788 dev = &priv->dev;
789 dev->pdev = pdev;
790
791 /*
792 * Now reset the HCA before we touch the PCI capabilities or
793 * attempt a firmware command, since a boot ROM may have left
794 * the HCA in an undefined state.
795 */
796 err = mlx4_reset(dev);
797 if (err) {
798 mlx4_err(dev, "Failed to reset HCA, aborting.\n");
799 goto err_free_dev;
800 }
801
802 mlx4_enable_msi_x(dev);
803
804 if (mlx4_cmd_init(dev)) {
805 mlx4_err(dev, "Failed to init command interface, aborting.\n");
806 goto err_free_dev;
807 }
808
809 err = mlx4_init_hca(dev);
810 if (err)
811 goto err_cmd;
812
813 err = mlx4_setup_hca(dev);
814 if (err)
815 goto err_close;
816
817 err = mlx4_register_device(dev);
818 if (err)
819 goto err_cleanup;
820
821 pci_set_drvdata(pdev, dev);
822
823 return 0;
824
825err_cleanup:
826 mlx4_cleanup_mcg_table(dev);
827 mlx4_cleanup_qp_table(dev);
828 mlx4_cleanup_srq_table(dev);
829 mlx4_cleanup_cq_table(dev);
830 mlx4_cmd_use_polling(dev);
831 mlx4_cleanup_eq_table(dev);
832
833 mlx4_unmap_catas_buf(dev);
834
835 mlx4_cleanup_mr_table(dev);
836 mlx4_cleanup_pd_table(dev);
837 mlx4_cleanup_uar_table(dev);
838
839err_close:
840 mlx4_close_hca(dev);
841
842err_cmd:
843 mlx4_cmd_cleanup(dev);
844
845err_free_dev:
846 if (dev->flags & MLX4_FLAG_MSI_X)
847 pci_disable_msix(pdev);
848
849 kfree(priv);
850
851err_release_bar2:
852 pci_release_region(pdev, 2);
853
854err_release_bar0:
855 pci_release_region(pdev, 0);
856
857err_disable_pdev:
858 pci_disable_device(pdev);
859 pci_set_drvdata(pdev, NULL);
860 return err;
861}
862
863static void __devexit mlx4_remove_one(struct pci_dev *pdev)
864{
865 struct mlx4_dev *dev = pci_get_drvdata(pdev);
866 struct mlx4_priv *priv = mlx4_priv(dev);
867 int p;
868
869 if (dev) {
870 mlx4_unregister_device(dev);
871
872 for (p = 1; p <= dev->caps.num_ports; ++p)
873 mlx4_CLOSE_PORT(dev, p);
874
875 mlx4_cleanup_mcg_table(dev);
876 mlx4_cleanup_qp_table(dev);
877 mlx4_cleanup_srq_table(dev);
878 mlx4_cleanup_cq_table(dev);
879 mlx4_cmd_use_polling(dev);
880 mlx4_cleanup_eq_table(dev);
881
882 mlx4_unmap_catas_buf(dev);
883
884 mlx4_cleanup_mr_table(dev);
885 mlx4_cleanup_pd_table(dev);
886
887 iounmap(priv->kar);
888 mlx4_uar_free(dev, &priv->driver_uar);
889 mlx4_cleanup_uar_table(dev);
890 mlx4_close_hca(dev);
891 mlx4_cmd_cleanup(dev);
892
893 if (dev->flags & MLX4_FLAG_MSI_X)
894 pci_disable_msix(pdev);
895
896 kfree(priv);
897 pci_release_region(pdev, 2);
898 pci_release_region(pdev, 0);
899 pci_disable_device(pdev);
900 pci_set_drvdata(pdev, NULL);
901 }
902}
903
904static struct pci_device_id mlx4_pci_table[] = {
905 { PCI_VDEVICE(MELLANOX, 0x6340) }, /* MT25408 "Hermon" SDR */
906 { PCI_VDEVICE(MELLANOX, 0x634a) }, /* MT25408 "Hermon" DDR */
907 { PCI_VDEVICE(MELLANOX, 0x6354) }, /* MT25408 "Hermon" QDR */
908 { 0, }
909};
910
911MODULE_DEVICE_TABLE(pci, mlx4_pci_table);
912
913static struct pci_driver mlx4_driver = {
914 .name = DRV_NAME,
915 .id_table = mlx4_pci_table,
916 .probe = mlx4_init_one,
917 .remove = __devexit_p(mlx4_remove_one)
918};
919
920static int __init mlx4_init(void)
921{
922 int ret;
923
924 ret = pci_register_driver(&mlx4_driver);
925 return ret < 0 ? ret : 0;
926}
927
928static void __exit mlx4_cleanup(void)
929{
930 pci_unregister_driver(&mlx4_driver);
931}
932
933module_init(mlx4_init);
934module_exit(mlx4_cleanup);
diff --git a/drivers/net/mlx4/mcg.c b/drivers/net/mlx4/mcg.c
new file mode 100644
index 000000000000..672024a0ee71
--- /dev/null
+++ b/drivers/net/mlx4/mcg.c
@@ -0,0 +1,380 @@
1/*
2 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/init.h>
34#include <linux/string.h>
35#include <linux/slab.h>
36
37#include <linux/mlx4/cmd.h>
38
39#include "mlx4.h"
40
41struct mlx4_mgm {
42 __be32 next_gid_index;
43 __be32 members_count;
44 u32 reserved[2];
45 u8 gid[16];
46 __be32 qp[MLX4_QP_PER_MGM];
47};
48
49static const u8 zero_gid[16]; /* automatically initialized to 0 */
50
51static int mlx4_READ_MCG(struct mlx4_dev *dev, int index,
52 struct mlx4_cmd_mailbox *mailbox)
53{
54 return mlx4_cmd_box(dev, 0, mailbox->dma, index, 0, MLX4_CMD_READ_MCG,
55 MLX4_CMD_TIME_CLASS_A);
56}
57
58static int mlx4_WRITE_MCG(struct mlx4_dev *dev, int index,
59 struct mlx4_cmd_mailbox *mailbox)
60{
61 return mlx4_cmd(dev, mailbox->dma, index, 0, MLX4_CMD_WRITE_MCG,
62 MLX4_CMD_TIME_CLASS_A);
63}
64
65static int mlx4_MGID_HASH(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
66 u16 *hash)
67{
68 u64 imm;
69 int err;
70
71 err = mlx4_cmd_imm(dev, mailbox->dma, &imm, 0, 0, MLX4_CMD_MGID_HASH,
72 MLX4_CMD_TIME_CLASS_A);
73
74 if (!err)
75 *hash = imm;
76
77 return err;
78}
79
80/*
81 * Caller must hold MCG table semaphore. gid and mgm parameters must
82 * be properly aligned for command interface.
83 *
84 * Returns 0 unless a firmware command error occurs.
85 *
86 * If GID is found in MGM or MGM is empty, *index = *hash, *prev = -1
87 * and *mgm holds MGM entry.
88 *
89 * if GID is found in AMGM, *index = index in AMGM, *prev = index of
90 * previous entry in hash chain and *mgm holds AMGM entry.
91 *
92 * If no AMGM exists for given gid, *index = -1, *prev = index of last
93 * entry in hash chain and *mgm holds end of hash chain.
94 */
95static int find_mgm(struct mlx4_dev *dev,
96 u8 *gid, struct mlx4_cmd_mailbox *mgm_mailbox,
97 u16 *hash, int *prev, int *index)
98{
99 struct mlx4_cmd_mailbox *mailbox;
100 struct mlx4_mgm *mgm = mgm_mailbox->buf;
101 u8 *mgid;
102 int err;
103
104 mailbox = mlx4_alloc_cmd_mailbox(dev);
105 if (IS_ERR(mailbox))
106 return -ENOMEM;
107 mgid = mailbox->buf;
108
109 memcpy(mgid, gid, 16);
110
111 err = mlx4_MGID_HASH(dev, mailbox, hash);
112 mlx4_free_cmd_mailbox(dev, mailbox);
113 if (err)
114 return err;
115
116 if (0)
117 mlx4_dbg(dev, "Hash for %04x:%04x:%04x:%04x:"
118 "%04x:%04x:%04x:%04x is %04x\n",
119 be16_to_cpu(((__be16 *) gid)[0]),
120 be16_to_cpu(((__be16 *) gid)[1]),
121 be16_to_cpu(((__be16 *) gid)[2]),
122 be16_to_cpu(((__be16 *) gid)[3]),
123 be16_to_cpu(((__be16 *) gid)[4]),
124 be16_to_cpu(((__be16 *) gid)[5]),
125 be16_to_cpu(((__be16 *) gid)[6]),
126 be16_to_cpu(((__be16 *) gid)[7]),
127 *hash);
128
129 *index = *hash;
130 *prev = -1;
131
132 do {
133 err = mlx4_READ_MCG(dev, *index, mgm_mailbox);
134 if (err)
135 return err;
136
137 if (!memcmp(mgm->gid, zero_gid, 16)) {
138 if (*index != *hash) {
139 mlx4_err(dev, "Found zero MGID in AMGM.\n");
140 err = -EINVAL;
141 }
142 return err;
143 }
144
145 if (!memcmp(mgm->gid, gid, 16))
146 return err;
147
148 *prev = *index;
149 *index = be32_to_cpu(mgm->next_gid_index) >> 6;
150 } while (*index);
151
152 *index = -1;
153 return err;
154}
155
156int mlx4_multicast_attach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16])
157{
158 struct mlx4_priv *priv = mlx4_priv(dev);
159 struct mlx4_cmd_mailbox *mailbox;
160 struct mlx4_mgm *mgm;
161 u32 members_count;
162 u16 hash;
163 int index, prev;
164 int link = 0;
165 int i;
166 int err;
167
168 mailbox = mlx4_alloc_cmd_mailbox(dev);
169 if (IS_ERR(mailbox))
170 return PTR_ERR(mailbox);
171 mgm = mailbox->buf;
172
173 mutex_lock(&priv->mcg_table.mutex);
174
175 err = find_mgm(dev, gid, mailbox, &hash, &prev, &index);
176 if (err)
177 goto out;
178
179 if (index != -1) {
180 if (!memcmp(mgm->gid, zero_gid, 16))
181 memcpy(mgm->gid, gid, 16);
182 } else {
183 link = 1;
184
185 index = mlx4_bitmap_alloc(&priv->mcg_table.bitmap);
186 if (index == -1) {
187 mlx4_err(dev, "No AMGM entries left\n");
188 err = -ENOMEM;
189 goto out;
190 }
191 index += dev->caps.num_mgms;
192
193 err = mlx4_READ_MCG(dev, index, mailbox);
194 if (err)
195 goto out;
196
197 memset(mgm, 0, sizeof *mgm);
198 memcpy(mgm->gid, gid, 16);
199 }
200
201 members_count = be32_to_cpu(mgm->members_count);
202 if (members_count == MLX4_QP_PER_MGM) {
203 mlx4_err(dev, "MGM at index %x is full.\n", index);
204 err = -ENOMEM;
205 goto out;
206 }
207
208 for (i = 0; i < members_count; ++i)
209 if (mgm->qp[i] == cpu_to_be32(qp->qpn)) {
210 mlx4_dbg(dev, "QP %06x already a member of MGM\n", qp->qpn);
211 err = 0;
212 goto out;
213 }
214
215 mgm->qp[members_count++] = cpu_to_be32(qp->qpn);
216 mgm->members_count = cpu_to_be32(members_count);
217
218 err = mlx4_WRITE_MCG(dev, index, mailbox);
219 if (err)
220 goto out;
221
222 if (!link)
223 goto out;
224
225 err = mlx4_READ_MCG(dev, prev, mailbox);
226 if (err)
227 goto out;
228
229 mgm->next_gid_index = cpu_to_be32(index << 6);
230
231 err = mlx4_WRITE_MCG(dev, prev, mailbox);
232 if (err)
233 goto out;
234
235out:
236 if (err && link && index != -1) {
237 if (index < dev->caps.num_mgms)
238 mlx4_warn(dev, "Got AMGM index %d < %d",
239 index, dev->caps.num_mgms);
240 else
241 mlx4_bitmap_free(&priv->mcg_table.bitmap,
242 index - dev->caps.num_mgms);
243 }
244 mutex_unlock(&priv->mcg_table.mutex);
245
246 mlx4_free_cmd_mailbox(dev, mailbox);
247 return err;
248}
249EXPORT_SYMBOL_GPL(mlx4_multicast_attach);
250
251int mlx4_multicast_detach(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16])
252{
253 struct mlx4_priv *priv = mlx4_priv(dev);
254 struct mlx4_cmd_mailbox *mailbox;
255 struct mlx4_mgm *mgm;
256 u32 members_count;
257 u16 hash;
258 int prev, index;
259 int i, loc;
260 int err;
261
262 mailbox = mlx4_alloc_cmd_mailbox(dev);
263 if (IS_ERR(mailbox))
264 return PTR_ERR(mailbox);
265 mgm = mailbox->buf;
266
267 mutex_lock(&priv->mcg_table.mutex);
268
269 err = find_mgm(dev, gid, mailbox, &hash, &prev, &index);
270 if (err)
271 goto out;
272
273 if (index == -1) {
274 mlx4_err(dev, "MGID %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x "
275 "not found\n",
276 be16_to_cpu(((__be16 *) gid)[0]),
277 be16_to_cpu(((__be16 *) gid)[1]),
278 be16_to_cpu(((__be16 *) gid)[2]),
279 be16_to_cpu(((__be16 *) gid)[3]),
280 be16_to_cpu(((__be16 *) gid)[4]),
281 be16_to_cpu(((__be16 *) gid)[5]),
282 be16_to_cpu(((__be16 *) gid)[6]),
283 be16_to_cpu(((__be16 *) gid)[7]));
284 err = -EINVAL;
285 goto out;
286 }
287
288 members_count = be32_to_cpu(mgm->members_count);
289 for (loc = -1, i = 0; i < members_count; ++i)
290 if (mgm->qp[i] == cpu_to_be32(qp->qpn))
291 loc = i;
292
293 if (loc == -1) {
294 mlx4_err(dev, "QP %06x not found in MGM\n", qp->qpn);
295 err = -EINVAL;
296 goto out;
297 }
298
299
300 mgm->members_count = cpu_to_be32(--members_count);
301 mgm->qp[loc] = mgm->qp[i - 1];
302 mgm->qp[i - 1] = 0;
303
304 err = mlx4_WRITE_MCG(dev, index, mailbox);
305 if (err)
306 goto out;
307
308 if (i != 1)
309 goto out;
310
311 if (prev == -1) {
312 /* Remove entry from MGM */
313 int amgm_index = be32_to_cpu(mgm->next_gid_index) >> 6;
314 if (amgm_index) {
315 err = mlx4_READ_MCG(dev, amgm_index, mailbox);
316 if (err)
317 goto out;
318 } else
319 memset(mgm->gid, 0, 16);
320
321 err = mlx4_WRITE_MCG(dev, index, mailbox);
322 if (err)
323 goto out;
324
325 if (amgm_index) {
326 if (amgm_index < dev->caps.num_mgms)
327 mlx4_warn(dev, "MGM entry %d had AMGM index %d < %d",
328 index, amgm_index, dev->caps.num_mgms);
329 else
330 mlx4_bitmap_free(&priv->mcg_table.bitmap,
331 amgm_index - dev->caps.num_mgms);
332 }
333 } else {
334 /* Remove entry from AMGM */
335 int cur_next_index = be32_to_cpu(mgm->next_gid_index) >> 6;
336 err = mlx4_READ_MCG(dev, prev, mailbox);
337 if (err)
338 goto out;
339
340 mgm->next_gid_index = cpu_to_be32(cur_next_index << 6);
341
342 err = mlx4_WRITE_MCG(dev, prev, mailbox);
343 if (err)
344 goto out;
345
346 if (index < dev->caps.num_mgms)
347 mlx4_warn(dev, "entry %d had next AMGM index %d < %d",
348 prev, index, dev->caps.num_mgms);
349 else
350 mlx4_bitmap_free(&priv->mcg_table.bitmap,
351 index - dev->caps.num_mgms);
352 }
353
354out:
355 mutex_unlock(&priv->mcg_table.mutex);
356
357 mlx4_free_cmd_mailbox(dev, mailbox);
358 return err;
359}
360EXPORT_SYMBOL_GPL(mlx4_multicast_detach);
361
362int __devinit mlx4_init_mcg_table(struct mlx4_dev *dev)
363{
364 struct mlx4_priv *priv = mlx4_priv(dev);
365 int err;
366
367 err = mlx4_bitmap_init(&priv->mcg_table.bitmap,
368 dev->caps.num_amgms, dev->caps.num_amgms - 1, 0);
369 if (err)
370 return err;
371
372 mutex_init(&priv->mcg_table.mutex);
373
374 return 0;
375}
376
377void mlx4_cleanup_mcg_table(struct mlx4_dev *dev)
378{
379 mlx4_bitmap_cleanup(&mlx4_priv(dev)->mcg_table.bitmap);
380}
diff --git a/drivers/net/mlx4/mlx4.h b/drivers/net/mlx4/mlx4.h
new file mode 100644
index 000000000000..3d3b6d24d8d3
--- /dev/null
+++ b/drivers/net/mlx4/mlx4.h
@@ -0,0 +1,347 @@
1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
4 * Copyright (c) 2005, 2006, 2007 Cisco Systems. All rights reserved.
5 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
6 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
7 *
8 * This software is available to you under a choice of one of two
9 * licenses. You may choose to be licensed under the terms of the GNU
10 * General Public License (GPL) Version 2, available from the file
11 * COPYING in the main directory of this source tree, or the
12 * OpenIB.org BSD license below:
13 *
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
16 * conditions are met:
17 *
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer.
21 *
22 * - Redistributions in binary form must reproduce the above
23 * copyright notice, this list of conditions and the following
24 * disclaimer in the documentation and/or other materials
25 * provided with the distribution.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 * SOFTWARE.
35 */
36
37#ifndef MLX4_H
38#define MLX4_H
39
40#include <linux/radix-tree.h>
41
42#include <linux/mlx4/device.h>
43#include <linux/mlx4/doorbell.h>
44
45#define DRV_NAME "mlx4_core"
46#define PFX DRV_NAME ": "
47#define DRV_VERSION "0.01"
48#define DRV_RELDATE "May 1, 2007"
49
50enum {
51 MLX4_HCR_BASE = 0x80680,
52 MLX4_HCR_SIZE = 0x0001c,
53 MLX4_CLR_INT_SIZE = 0x00008
54};
55
56enum {
57 MLX4_BOARD_ID_LEN = 64
58};
59
60enum {
61 MLX4_MGM_ENTRY_SIZE = 0x40,
62 MLX4_QP_PER_MGM = 4 * (MLX4_MGM_ENTRY_SIZE / 16 - 2),
63 MLX4_MTT_ENTRY_PER_SEG = 8
64};
65
66enum {
67 MLX4_EQ_ASYNC,
68 MLX4_EQ_COMP,
69 MLX4_EQ_CATAS,
70 MLX4_NUM_EQ
71};
72
73enum {
74 MLX4_NUM_PDS = 1 << 15
75};
76
77enum {
78 MLX4_CMPT_TYPE_QP = 0,
79 MLX4_CMPT_TYPE_SRQ = 1,
80 MLX4_CMPT_TYPE_CQ = 2,
81 MLX4_CMPT_TYPE_EQ = 3,
82 MLX4_CMPT_NUM_TYPE
83};
84
85enum {
86 MLX4_CMPT_SHIFT = 24,
87 MLX4_NUM_CMPTS = MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
88};
89
90#ifdef CONFIG_MLX4_DEBUG
91extern int mlx4_debug_level;
92
93#define mlx4_dbg(mdev, format, arg...) \
94 do { \
95 if (mlx4_debug_level) \
96 dev_printk(KERN_DEBUG, &mdev->pdev->dev, format, ## arg); \
97 } while (0)
98
99#else /* CONFIG_MLX4_DEBUG */
100
101#define mlx4_dbg(mdev, format, arg...) do { (void) mdev; } while (0)
102
103#endif /* CONFIG_MLX4_DEBUG */
104
105#define mlx4_err(mdev, format, arg...) \
106 dev_err(&mdev->pdev->dev, format, ## arg)
107#define mlx4_info(mdev, format, arg...) \
108 dev_info(&mdev->pdev->dev, format, ## arg)
109#define mlx4_warn(mdev, format, arg...) \
110 dev_warn(&mdev->pdev->dev, format, ## arg)
111
112struct mlx4_bitmap {
113 u32 last;
114 u32 top;
115 u32 max;
116 u32 mask;
117 spinlock_t lock;
118 unsigned long *table;
119};
120
121struct mlx4_buddy {
122 unsigned long **bits;
123 int max_order;
124 spinlock_t lock;
125};
126
127struct mlx4_icm;
128
129struct mlx4_icm_table {
130 u64 virt;
131 int num_icm;
132 int num_obj;
133 int obj_size;
134 int lowmem;
135 struct mutex mutex;
136 struct mlx4_icm **icm;
137};
138
139struct mlx4_eq {
140 struct mlx4_dev *dev;
141 void __iomem *doorbell;
142 int eqn;
143 u32 cons_index;
144 u16 irq;
145 u16 have_irq;
146 int nent;
147 struct mlx4_buf_list *page_list;
148 struct mlx4_mtt mtt;
149};
150
151struct mlx4_profile {
152 int num_qp;
153 int rdmarc_per_qp;
154 int num_srq;
155 int num_cq;
156 int num_mcg;
157 int num_mpt;
158 int num_mtt;
159};
160
161struct mlx4_fw {
162 u64 clr_int_base;
163 u64 catas_offset;
164 struct mlx4_icm *fw_icm;
165 struct mlx4_icm *aux_icm;
166 u32 catas_size;
167 u16 fw_pages;
168 u8 clr_int_bar;
169 u8 catas_bar;
170};
171
172struct mlx4_cmd {
173 struct pci_pool *pool;
174 void __iomem *hcr;
175 struct mutex hcr_mutex;
176 struct semaphore poll_sem;
177 struct semaphore event_sem;
178 int max_cmds;
179 spinlock_t context_lock;
180 int free_head;
181 struct mlx4_cmd_context *context;
182 u16 token_mask;
183 u8 use_events;
184 u8 toggle;
185};
186
187struct mlx4_uar_table {
188 struct mlx4_bitmap bitmap;
189};
190
191struct mlx4_mr_table {
192 struct mlx4_bitmap mpt_bitmap;
193 struct mlx4_buddy mtt_buddy;
194 u64 mtt_base;
195 u64 mpt_base;
196 struct mlx4_icm_table mtt_table;
197 struct mlx4_icm_table dmpt_table;
198};
199
200struct mlx4_cq_table {
201 struct mlx4_bitmap bitmap;
202 spinlock_t lock;
203 struct radix_tree_root tree;
204 struct mlx4_icm_table table;
205 struct mlx4_icm_table cmpt_table;
206};
207
208struct mlx4_eq_table {
209 struct mlx4_bitmap bitmap;
210 void __iomem *clr_int;
211 void __iomem *uar_map[(MLX4_NUM_EQ + 6) / 4];
212 u32 clr_mask;
213 struct mlx4_eq eq[MLX4_NUM_EQ];
214 u64 icm_virt;
215 struct page *icm_page;
216 dma_addr_t icm_dma;
217 struct mlx4_icm_table cmpt_table;
218 int have_irq;
219 u8 inta_pin;
220};
221
222struct mlx4_srq_table {
223 struct mlx4_bitmap bitmap;
224 spinlock_t lock;
225 struct radix_tree_root tree;
226 struct mlx4_icm_table table;
227 struct mlx4_icm_table cmpt_table;
228};
229
230struct mlx4_qp_table {
231 struct mlx4_bitmap bitmap;
232 u32 rdmarc_base;
233 int rdmarc_shift;
234 spinlock_t lock;
235 struct mlx4_icm_table qp_table;
236 struct mlx4_icm_table auxc_table;
237 struct mlx4_icm_table altc_table;
238 struct mlx4_icm_table rdmarc_table;
239 struct mlx4_icm_table cmpt_table;
240};
241
242struct mlx4_mcg_table {
243 struct mutex mutex;
244 struct mlx4_bitmap bitmap;
245 struct mlx4_icm_table table;
246};
247
248struct mlx4_catas_err {
249 u32 __iomem *map;
250 int size;
251};
252
253struct mlx4_priv {
254 struct mlx4_dev dev;
255
256 struct list_head dev_list;
257 struct list_head ctx_list;
258 spinlock_t ctx_lock;
259
260 struct mlx4_fw fw;
261 struct mlx4_cmd cmd;
262
263 struct mlx4_bitmap pd_bitmap;
264 struct mlx4_uar_table uar_table;
265 struct mlx4_mr_table mr_table;
266 struct mlx4_cq_table cq_table;
267 struct mlx4_eq_table eq_table;
268 struct mlx4_srq_table srq_table;
269 struct mlx4_qp_table qp_table;
270 struct mlx4_mcg_table mcg_table;
271
272 struct mlx4_catas_err catas_err;
273
274 void __iomem *clr_base;
275
276 struct mlx4_uar driver_uar;
277 void __iomem *kar;
278
279 u32 rev_id;
280 char board_id[MLX4_BOARD_ID_LEN];
281};
282
283static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
284{
285 return container_of(dev, struct mlx4_priv, dev);
286}
287
288u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
289void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj);
290int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask, u32 reserved);
291void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
292
293int mlx4_reset(struct mlx4_dev *dev);
294
295int mlx4_init_pd_table(struct mlx4_dev *dev);
296int mlx4_init_uar_table(struct mlx4_dev *dev);
297int mlx4_init_mr_table(struct mlx4_dev *dev);
298int mlx4_init_eq_table(struct mlx4_dev *dev);
299int mlx4_init_cq_table(struct mlx4_dev *dev);
300int mlx4_init_qp_table(struct mlx4_dev *dev);
301int mlx4_init_srq_table(struct mlx4_dev *dev);
302int mlx4_init_mcg_table(struct mlx4_dev *dev);
303
304void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
305void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
306void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
307void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
308void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
309void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
310void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
311void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
312
313void mlx4_map_catas_buf(struct mlx4_dev *dev);
314void mlx4_unmap_catas_buf(struct mlx4_dev *dev);
315
316int mlx4_register_device(struct mlx4_dev *dev);
317void mlx4_unregister_device(struct mlx4_dev *dev);
318void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_event type,
319 int subtype, int port);
320
321struct mlx4_dev_cap;
322struct mlx4_init_hca_param;
323
324u64 mlx4_make_profile(struct mlx4_dev *dev,
325 struct mlx4_profile *request,
326 struct mlx4_dev_cap *dev_cap,
327 struct mlx4_init_hca_param *init_hca);
328
329int mlx4_map_eq_icm(struct mlx4_dev *dev, u64 icm_virt);
330void mlx4_unmap_eq_icm(struct mlx4_dev *dev);
331
332int mlx4_cmd_init(struct mlx4_dev *dev);
333void mlx4_cmd_cleanup(struct mlx4_dev *dev);
334void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
335int mlx4_cmd_use_events(struct mlx4_dev *dev);
336void mlx4_cmd_use_polling(struct mlx4_dev *dev);
337
338void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
339void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
340
341void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
342
343void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
344
345void mlx4_handle_catas_err(struct mlx4_dev *dev);
346
347#endif /* MLX4_H */
diff --git a/drivers/net/mlx4/mr.c b/drivers/net/mlx4/mr.c
new file mode 100644
index 000000000000..b33864dab179
--- /dev/null
+++ b/drivers/net/mlx4/mr.c
@@ -0,0 +1,479 @@
1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#include <linux/init.h>
36#include <linux/errno.h>
37
38#include <linux/mlx4/cmd.h>
39
40#include "mlx4.h"
41#include "icm.h"
42
43/*
44 * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.
45 */
46struct mlx4_mpt_entry {
47 __be32 flags;
48 __be32 qpn;
49 __be32 key;
50 __be32 pd;
51 __be64 start;
52 __be64 length;
53 __be32 lkey;
54 __be32 win_cnt;
55 u8 reserved1[3];
56 u8 mtt_rep;
57 __be64 mtt_seg;
58 __be32 mtt_sz;
59 __be32 entity_size;
60 __be32 first_byte_offset;
61} __attribute__((packed));
62
63#define MLX4_MPT_FLAG_SW_OWNS (0xfUL << 28)
64#define MLX4_MPT_FLAG_MIO (1 << 17)
65#define MLX4_MPT_FLAG_BIND_ENABLE (1 << 15)
66#define MLX4_MPT_FLAG_PHYSICAL (1 << 9)
67#define MLX4_MPT_FLAG_REGION (1 << 8)
68
69#define MLX4_MTT_FLAG_PRESENT 1
70
71static u32 mlx4_buddy_alloc(struct mlx4_buddy *buddy, int order)
72{
73 int o;
74 int m;
75 u32 seg;
76
77 spin_lock(&buddy->lock);
78
79 for (o = order; o <= buddy->max_order; ++o) {
80 m = 1 << (buddy->max_order - o);
81 seg = find_first_bit(buddy->bits[o], m);
82 if (seg < m)
83 goto found;
84 }
85
86 spin_unlock(&buddy->lock);
87 return -1;
88
89 found:
90 clear_bit(seg, buddy->bits[o]);
91
92 while (o > order) {
93 --o;
94 seg <<= 1;
95 set_bit(seg ^ 1, buddy->bits[o]);
96 }
97
98 spin_unlock(&buddy->lock);
99
100 seg <<= order;
101
102 return seg;
103}
104
105static void mlx4_buddy_free(struct mlx4_buddy *buddy, u32 seg, int order)
106{
107 seg >>= order;
108
109 spin_lock(&buddy->lock);
110
111 while (test_bit(seg ^ 1, buddy->bits[order])) {
112 clear_bit(seg ^ 1, buddy->bits[order]);
113 seg >>= 1;
114 ++order;
115 }
116
117 set_bit(seg, buddy->bits[order]);
118
119 spin_unlock(&buddy->lock);
120}
121
122static int __devinit mlx4_buddy_init(struct mlx4_buddy *buddy, int max_order)
123{
124 int i, s;
125
126 buddy->max_order = max_order;
127 spin_lock_init(&buddy->lock);
128
129 buddy->bits = kzalloc((buddy->max_order + 1) * sizeof (long *),
130 GFP_KERNEL);
131 if (!buddy->bits)
132 goto err_out;
133
134 for (i = 0; i <= buddy->max_order; ++i) {
135 s = BITS_TO_LONGS(1 << (buddy->max_order - i));
136 buddy->bits[i] = kmalloc(s * sizeof (long), GFP_KERNEL);
137 if (!buddy->bits[i])
138 goto err_out_free;
139 bitmap_zero(buddy->bits[i], 1 << (buddy->max_order - i));
140 }
141
142 set_bit(0, buddy->bits[buddy->max_order]);
143
144 return 0;
145
146err_out_free:
147 for (i = 0; i <= buddy->max_order; ++i)
148 kfree(buddy->bits[i]);
149
150 kfree(buddy->bits);
151
152err_out:
153 return -ENOMEM;
154}
155
156static void mlx4_buddy_cleanup(struct mlx4_buddy *buddy)
157{
158 int i;
159
160 for (i = 0; i <= buddy->max_order; ++i)
161 kfree(buddy->bits[i]);
162
163 kfree(buddy->bits);
164}
165
166static u32 mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order)
167{
168 struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
169 u32 seg;
170
171 seg = mlx4_buddy_alloc(&mr_table->mtt_buddy, order);
172 if (seg == -1)
173 return -1;
174
175 if (mlx4_table_get_range(dev, &mr_table->mtt_table, seg,
176 seg + (1 << order) - 1)) {
177 mlx4_buddy_free(&mr_table->mtt_buddy, seg, order);
178 return -1;
179 }
180
181 return seg;
182}
183
184int mlx4_mtt_init(struct mlx4_dev *dev, int npages, int page_shift,
185 struct mlx4_mtt *mtt)
186{
187 int i;
188
189 if (!npages) {
190 mtt->order = -1;
191 mtt->page_shift = MLX4_ICM_PAGE_SHIFT;
192 return 0;
193 } else
194 mtt->page_shift = page_shift;
195
196 for (mtt->order = 0, i = MLX4_MTT_ENTRY_PER_SEG; i < npages; i <<= 1)
197 ++mtt->order;
198
199 mtt->first_seg = mlx4_alloc_mtt_range(dev, mtt->order);
200 if (mtt->first_seg == -1)
201 return -ENOMEM;
202
203 return 0;
204}
205EXPORT_SYMBOL_GPL(mlx4_mtt_init);
206
207void mlx4_mtt_cleanup(struct mlx4_dev *dev, struct mlx4_mtt *mtt)
208{
209 struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
210
211 if (mtt->order < 0)
212 return;
213
214 mlx4_buddy_free(&mr_table->mtt_buddy, mtt->first_seg, mtt->order);
215 mlx4_table_put_range(dev, &mr_table->mtt_table, mtt->first_seg,
216 mtt->first_seg + (1 << mtt->order) - 1);
217}
218EXPORT_SYMBOL_GPL(mlx4_mtt_cleanup);
219
220u64 mlx4_mtt_addr(struct mlx4_dev *dev, struct mlx4_mtt *mtt)
221{
222 return (u64) mtt->first_seg * dev->caps.mtt_entry_sz;
223}
224EXPORT_SYMBOL_GPL(mlx4_mtt_addr);
225
226static u32 hw_index_to_key(u32 ind)
227{
228 return (ind >> 24) | (ind << 8);
229}
230
231static u32 key_to_hw_index(u32 key)
232{
233 return (key << 24) | (key >> 8);
234}
235
236static int mlx4_SW2HW_MPT(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
237 int mpt_index)
238{
239 return mlx4_cmd(dev, mailbox->dma, mpt_index, 0, MLX4_CMD_SW2HW_MPT,
240 MLX4_CMD_TIME_CLASS_B);
241}
242
243static int mlx4_HW2SW_MPT(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
244 int mpt_index)
245{
246 return mlx4_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, mpt_index,
247 !mailbox, MLX4_CMD_HW2SW_MPT, MLX4_CMD_TIME_CLASS_B);
248}
249
250int mlx4_mr_alloc(struct mlx4_dev *dev, u32 pd, u64 iova, u64 size, u32 access,
251 int npages, int page_shift, struct mlx4_mr *mr)
252{
253 struct mlx4_priv *priv = mlx4_priv(dev);
254 u32 index;
255 int err;
256
257 index = mlx4_bitmap_alloc(&priv->mr_table.mpt_bitmap);
258 if (index == -1) {
259 err = -ENOMEM;
260 goto err;
261 }
262
263 mr->iova = iova;
264 mr->size = size;
265 mr->pd = pd;
266 mr->access = access;
267 mr->enabled = 0;
268 mr->key = hw_index_to_key(index);
269
270 err = mlx4_mtt_init(dev, npages, page_shift, &mr->mtt);
271 if (err)
272 goto err_index;
273
274 return 0;
275
276err_index:
277 mlx4_bitmap_free(&priv->mr_table.mpt_bitmap, index);
278
279err:
280 kfree(mr);
281 return err;
282}
283EXPORT_SYMBOL_GPL(mlx4_mr_alloc);
284
285void mlx4_mr_free(struct mlx4_dev *dev, struct mlx4_mr *mr)
286{
287 struct mlx4_priv *priv = mlx4_priv(dev);
288 int err;
289
290 if (mr->enabled) {
291 err = mlx4_HW2SW_MPT(dev, NULL,
292 key_to_hw_index(mr->key) &
293 (dev->caps.num_mpts - 1));
294 if (err)
295 mlx4_warn(dev, "HW2SW_MPT failed (%d)\n", err);
296 }
297
298 mlx4_mtt_cleanup(dev, &mr->mtt);
299 mlx4_bitmap_free(&priv->mr_table.mpt_bitmap, key_to_hw_index(mr->key));
300}
301EXPORT_SYMBOL_GPL(mlx4_mr_free);
302
303int mlx4_mr_enable(struct mlx4_dev *dev, struct mlx4_mr *mr)
304{
305 struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
306 struct mlx4_cmd_mailbox *mailbox;
307 struct mlx4_mpt_entry *mpt_entry;
308 int err;
309
310 err = mlx4_table_get(dev, &mr_table->dmpt_table, key_to_hw_index(mr->key));
311 if (err)
312 return err;
313
314 mailbox = mlx4_alloc_cmd_mailbox(dev);
315 if (IS_ERR(mailbox)) {
316 err = PTR_ERR(mailbox);
317 goto err_table;
318 }
319 mpt_entry = mailbox->buf;
320
321 memset(mpt_entry, 0, sizeof *mpt_entry);
322
323 mpt_entry->flags = cpu_to_be32(MLX4_MPT_FLAG_SW_OWNS |
324 MLX4_MPT_FLAG_MIO |
325 MLX4_MPT_FLAG_REGION |
326 mr->access);
327 if (mr->mtt.order < 0)
328 mpt_entry->flags |= cpu_to_be32(MLX4_MPT_FLAG_PHYSICAL);
329
330 mpt_entry->key = cpu_to_be32(key_to_hw_index(mr->key));
331 mpt_entry->pd = cpu_to_be32(mr->pd);
332 mpt_entry->start = cpu_to_be64(mr->iova);
333 mpt_entry->length = cpu_to_be64(mr->size);
334 mpt_entry->entity_size = cpu_to_be32(mr->mtt.page_shift);
335 mpt_entry->mtt_seg = cpu_to_be64(mlx4_mtt_addr(dev, &mr->mtt));
336
337 err = mlx4_SW2HW_MPT(dev, mailbox,
338 key_to_hw_index(mr->key) & (dev->caps.num_mpts - 1));
339 if (err) {
340 mlx4_warn(dev, "SW2HW_MPT failed (%d)\n", err);
341 goto err_cmd;
342 }
343
344 mr->enabled = 1;
345
346 mlx4_free_cmd_mailbox(dev, mailbox);
347
348 return 0;
349
350err_cmd:
351 mlx4_free_cmd_mailbox(dev, mailbox);
352
353err_table:
354 mlx4_table_put(dev, &mr_table->dmpt_table, key_to_hw_index(mr->key));
355 return err;
356}
357EXPORT_SYMBOL_GPL(mlx4_mr_enable);
358
359static int mlx4_WRITE_MTT(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
360 int num_mtt)
361{
362 return mlx4_cmd(dev, mailbox->dma, num_mtt, 0, MLX4_CMD_WRITE_MTT,
363 MLX4_CMD_TIME_CLASS_B);
364}
365
366int mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
367 int start_index, int npages, u64 *page_list)
368{
369 struct mlx4_cmd_mailbox *mailbox;
370 __be64 *mtt_entry;
371 int i;
372 int err = 0;
373
374 if (mtt->order < 0)
375 return -EINVAL;
376
377 mailbox = mlx4_alloc_cmd_mailbox(dev);
378 if (IS_ERR(mailbox))
379 return PTR_ERR(mailbox);
380
381 mtt_entry = mailbox->buf;
382
383 while (npages > 0) {
384 mtt_entry[0] = cpu_to_be64(mlx4_mtt_addr(dev, mtt) + start_index * 8);
385 mtt_entry[1] = 0;
386
387 for (i = 0; i < npages && i < MLX4_MAILBOX_SIZE / 8 - 2; ++i)
388 mtt_entry[i + 2] = cpu_to_be64(page_list[i] |
389 MLX4_MTT_FLAG_PRESENT);
390
391 /*
392 * If we have an odd number of entries to write, add
393 * one more dummy entry for firmware efficiency.
394 */
395 if (i & 1)
396 mtt_entry[i + 2] = 0;
397
398 err = mlx4_WRITE_MTT(dev, mailbox, (i + 1) & ~1);
399 if (err)
400 goto out;
401
402 npages -= i;
403 start_index += i;
404 page_list += i;
405 }
406
407out:
408 mlx4_free_cmd_mailbox(dev, mailbox);
409
410 return err;
411}
412EXPORT_SYMBOL_GPL(mlx4_write_mtt);
413
414int mlx4_buf_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
415 struct mlx4_buf *buf)
416{
417 u64 *page_list;
418 int err;
419 int i;
420
421 page_list = kmalloc(buf->npages * sizeof *page_list, GFP_KERNEL);
422 if (!page_list)
423 return -ENOMEM;
424
425 for (i = 0; i < buf->npages; ++i)
426 if (buf->nbufs == 1)
427 page_list[i] = buf->u.direct.map + (i << buf->page_shift);
428 else
429 page_list[i] = buf->u.page_list[i].map;
430
431 err = mlx4_write_mtt(dev, mtt, 0, buf->npages, page_list);
432
433 kfree(page_list);
434 return err;
435}
436EXPORT_SYMBOL_GPL(mlx4_buf_write_mtt);
437
438int __devinit mlx4_init_mr_table(struct mlx4_dev *dev)
439{
440 struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
441 int err;
442
443 err = mlx4_bitmap_init(&mr_table->mpt_bitmap, dev->caps.num_mpts,
444 ~0, dev->caps.reserved_mrws);
445 if (err)
446 return err;
447
448 err = mlx4_buddy_init(&mr_table->mtt_buddy,
449 ilog2(dev->caps.num_mtt_segs));
450 if (err)
451 goto err_buddy;
452
453 if (dev->caps.reserved_mtts) {
454 if (mlx4_alloc_mtt_range(dev, ilog2(dev->caps.reserved_mtts)) == -1) {
455 mlx4_warn(dev, "MTT table of order %d is too small.\n",
456 mr_table->mtt_buddy.max_order);
457 err = -ENOMEM;
458 goto err_reserve_mtts;
459 }
460 }
461
462 return 0;
463
464err_reserve_mtts:
465 mlx4_buddy_cleanup(&mr_table->mtt_buddy);
466
467err_buddy:
468 mlx4_bitmap_cleanup(&mr_table->mpt_bitmap);
469
470 return err;
471}
472
473void mlx4_cleanup_mr_table(struct mlx4_dev *dev)
474{
475 struct mlx4_mr_table *mr_table = &mlx4_priv(dev)->mr_table;
476
477 mlx4_buddy_cleanup(&mr_table->mtt_buddy);
478 mlx4_bitmap_cleanup(&mr_table->mpt_bitmap);
479}
diff --git a/drivers/net/mlx4/pd.c b/drivers/net/mlx4/pd.c
new file mode 100644
index 000000000000..23dea1ee7750
--- /dev/null
+++ b/drivers/net/mlx4/pd.c
@@ -0,0 +1,102 @@
1/*
2 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
34#include <linux/init.h>
35#include <linux/errno.h>
36
37#include <asm/page.h>
38
39#include "mlx4.h"
40#include "icm.h"
41
42int mlx4_pd_alloc(struct mlx4_dev *dev, u32 *pdn)
43{
44 struct mlx4_priv *priv = mlx4_priv(dev);
45
46 *pdn = mlx4_bitmap_alloc(&priv->pd_bitmap);
47 if (*pdn == -1)
48 return -ENOMEM;
49
50 return 0;
51}
52EXPORT_SYMBOL_GPL(mlx4_pd_alloc);
53
54void mlx4_pd_free(struct mlx4_dev *dev, u32 pdn)
55{
56 mlx4_bitmap_free(&mlx4_priv(dev)->pd_bitmap, pdn);
57}
58EXPORT_SYMBOL_GPL(mlx4_pd_free);
59
60int __devinit mlx4_init_pd_table(struct mlx4_dev *dev)
61{
62 struct mlx4_priv *priv = mlx4_priv(dev);
63
64 return mlx4_bitmap_init(&priv->pd_bitmap, dev->caps.num_pds,
65 (1 << 24) - 1, dev->caps.reserved_pds);
66}
67
68void mlx4_cleanup_pd_table(struct mlx4_dev *dev)
69{
70 mlx4_bitmap_cleanup(&mlx4_priv(dev)->pd_bitmap);
71}
72
73
74int mlx4_uar_alloc(struct mlx4_dev *dev, struct mlx4_uar *uar)
75{
76 uar->index = mlx4_bitmap_alloc(&mlx4_priv(dev)->uar_table.bitmap);
77 if (uar->index == -1)
78 return -ENOMEM;
79
80 uar->pfn = (pci_resource_start(dev->pdev, 2) >> PAGE_SHIFT) + uar->index;
81
82 return 0;
83}
84EXPORT_SYMBOL_GPL(mlx4_uar_alloc);
85
86void mlx4_uar_free(struct mlx4_dev *dev, struct mlx4_uar *uar)
87{
88 mlx4_bitmap_free(&mlx4_priv(dev)->uar_table.bitmap, uar->index);
89}
90EXPORT_SYMBOL_GPL(mlx4_uar_free);
91
92int mlx4_init_uar_table(struct mlx4_dev *dev)
93{
94 return mlx4_bitmap_init(&mlx4_priv(dev)->uar_table.bitmap,
95 dev->caps.num_uars, dev->caps.num_uars - 1,
96 max(128, dev->caps.reserved_uars));
97}
98
99void mlx4_cleanup_uar_table(struct mlx4_dev *dev)
100{
101 mlx4_bitmap_cleanup(&mlx4_priv(dev)->uar_table.bitmap);
102}
diff --git a/drivers/net/mlx4/profile.c b/drivers/net/mlx4/profile.c
new file mode 100644
index 000000000000..9ca42b213d54
--- /dev/null
+++ b/drivers/net/mlx4/profile.c
@@ -0,0 +1,238 @@
1/*
2 * Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
4 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#include <linux/init.h>
36
37#include "mlx4.h"
38#include "fw.h"
39
40enum {
41 MLX4_RES_QP,
42 MLX4_RES_RDMARC,
43 MLX4_RES_ALTC,
44 MLX4_RES_AUXC,
45 MLX4_RES_SRQ,
46 MLX4_RES_CQ,
47 MLX4_RES_EQ,
48 MLX4_RES_DMPT,
49 MLX4_RES_CMPT,
50 MLX4_RES_MTT,
51 MLX4_RES_MCG,
52 MLX4_RES_NUM
53};
54
55static const char *res_name[] = {
56 [MLX4_RES_QP] = "QP",
57 [MLX4_RES_RDMARC] = "RDMARC",
58 [MLX4_RES_ALTC] = "ALTC",
59 [MLX4_RES_AUXC] = "AUXC",
60 [MLX4_RES_SRQ] = "SRQ",
61 [MLX4_RES_CQ] = "CQ",
62 [MLX4_RES_EQ] = "EQ",
63 [MLX4_RES_DMPT] = "DMPT",
64 [MLX4_RES_CMPT] = "CMPT",
65 [MLX4_RES_MTT] = "MTT",
66 [MLX4_RES_MCG] = "MCG",
67};
68
69u64 mlx4_make_profile(struct mlx4_dev *dev,
70 struct mlx4_profile *request,
71 struct mlx4_dev_cap *dev_cap,
72 struct mlx4_init_hca_param *init_hca)
73{
74 struct mlx4_priv *priv = mlx4_priv(dev);
75 struct mlx4_resource {
76 u64 size;
77 u64 start;
78 int type;
79 int num;
80 int log_num;
81 };
82
83 u64 total_size = 0;
84 struct mlx4_resource *profile;
85 struct mlx4_resource tmp;
86 int i, j;
87
88 profile = kzalloc(MLX4_RES_NUM * sizeof *profile, GFP_KERNEL);
89 if (!profile)
90 return -ENOMEM;
91
92 profile[MLX4_RES_QP].size = dev_cap->qpc_entry_sz;
93 profile[MLX4_RES_RDMARC].size = dev_cap->rdmarc_entry_sz;
94 profile[MLX4_RES_ALTC].size = dev_cap->altc_entry_sz;
95 profile[MLX4_RES_AUXC].size = dev_cap->aux_entry_sz;
96 profile[MLX4_RES_SRQ].size = dev_cap->srq_entry_sz;
97 profile[MLX4_RES_CQ].size = dev_cap->cqc_entry_sz;
98 profile[MLX4_RES_EQ].size = dev_cap->eqc_entry_sz;
99 profile[MLX4_RES_DMPT].size = dev_cap->dmpt_entry_sz;
100 profile[MLX4_RES_CMPT].size = dev_cap->cmpt_entry_sz;
101 profile[MLX4_RES_MTT].size = MLX4_MTT_ENTRY_PER_SEG * dev_cap->mtt_entry_sz;
102 profile[MLX4_RES_MCG].size = MLX4_MGM_ENTRY_SIZE;
103
104 profile[MLX4_RES_QP].num = request->num_qp;
105 profile[MLX4_RES_RDMARC].num = request->num_qp * request->rdmarc_per_qp;
106 profile[MLX4_RES_ALTC].num = request->num_qp;
107 profile[MLX4_RES_AUXC].num = request->num_qp;
108 profile[MLX4_RES_SRQ].num = request->num_srq;
109 profile[MLX4_RES_CQ].num = request->num_cq;
110 profile[MLX4_RES_EQ].num = MLX4_NUM_EQ + dev_cap->reserved_eqs;
111 profile[MLX4_RES_DMPT].num = request->num_mpt;
112 profile[MLX4_RES_CMPT].num = MLX4_NUM_CMPTS;
113 profile[MLX4_RES_MTT].num = request->num_mtt;
114 profile[MLX4_RES_MCG].num = request->num_mcg;
115
116 for (i = 0; i < MLX4_RES_NUM; ++i) {
117 profile[i].type = i;
118 profile[i].num = roundup_pow_of_two(profile[i].num);
119 profile[i].log_num = ilog2(profile[i].num);
120 profile[i].size *= profile[i].num;
121 profile[i].size = max(profile[i].size, (u64) PAGE_SIZE);
122 }
123
124 /*
125 * Sort the resources in decreasing order of size. Since they
126 * all have sizes that are powers of 2, we'll be able to keep
127 * resources aligned to their size and pack them without gaps
128 * using the sorted order.
129 */
130 for (i = MLX4_RES_NUM; i > 0; --i)
131 for (j = 1; j < i; ++j) {
132 if (profile[j].size > profile[j - 1].size) {
133 tmp = profile[j];
134 profile[j] = profile[j - 1];
135 profile[j - 1] = tmp;
136 }
137 }
138
139 for (i = 0; i < MLX4_RES_NUM; ++i) {
140 if (profile[i].size) {
141 profile[i].start = total_size;
142 total_size += profile[i].size;
143 }
144
145 if (total_size > dev_cap->max_icm_sz) {
146 mlx4_err(dev, "Profile requires 0x%llx bytes; "
147 "won't fit in 0x%llx bytes of context memory.\n",
148 (unsigned long long) total_size,
149 (unsigned long long) dev_cap->max_icm_sz);
150 kfree(profile);
151 return -ENOMEM;
152 }
153
154 if (profile[i].size)
155 mlx4_dbg(dev, " profile[%2d] (%6s): 2^%02d entries @ 0x%10llx, "
156 "size 0x%10llx\n",
157 i, res_name[profile[i].type], profile[i].log_num,
158 (unsigned long long) profile[i].start,
159 (unsigned long long) profile[i].size);
160 }
161
162 mlx4_dbg(dev, "HCA context memory: reserving %d KB\n",
163 (int) (total_size >> 10));
164
165 for (i = 0; i < MLX4_RES_NUM; ++i) {
166 switch (profile[i].type) {
167 case MLX4_RES_QP:
168 dev->caps.num_qps = profile[i].num;
169 init_hca->qpc_base = profile[i].start;
170 init_hca->log_num_qps = profile[i].log_num;
171 break;
172 case MLX4_RES_RDMARC:
173 for (priv->qp_table.rdmarc_shift = 0;
174 request->num_qp << priv->qp_table.rdmarc_shift < profile[i].num;
175 ++priv->qp_table.rdmarc_shift)
176 ; /* nothing */
177 dev->caps.max_qp_dest_rdma = 1 << priv->qp_table.rdmarc_shift;
178 priv->qp_table.rdmarc_base = (u32) profile[i].start;
179 init_hca->rdmarc_base = profile[i].start;
180 init_hca->log_rd_per_qp = priv->qp_table.rdmarc_shift;
181 break;
182 case MLX4_RES_ALTC:
183 init_hca->altc_base = profile[i].start;
184 break;
185 case MLX4_RES_AUXC:
186 init_hca->auxc_base = profile[i].start;
187 break;
188 case MLX4_RES_SRQ:
189 dev->caps.num_srqs = profile[i].num;
190 init_hca->srqc_base = profile[i].start;
191 init_hca->log_num_srqs = profile[i].log_num;
192 break;
193 case MLX4_RES_CQ:
194 dev->caps.num_cqs = profile[i].num;
195 init_hca->cqc_base = profile[i].start;
196 init_hca->log_num_cqs = profile[i].log_num;
197 break;
198 case MLX4_RES_EQ:
199 dev->caps.num_eqs = profile[i].num;
200 init_hca->eqc_base = profile[i].start;
201 init_hca->log_num_eqs = profile[i].log_num;
202 break;
203 case MLX4_RES_DMPT:
204 dev->caps.num_mpts = profile[i].num;
205 priv->mr_table.mpt_base = profile[i].start;
206 init_hca->dmpt_base = profile[i].start;
207 init_hca->log_mpt_sz = profile[i].log_num;
208 break;
209 case MLX4_RES_CMPT:
210 init_hca->cmpt_base = profile[i].start;
211 break;
212 case MLX4_RES_MTT:
213 dev->caps.num_mtt_segs = profile[i].num;
214 priv->mr_table.mtt_base = profile[i].start;
215 init_hca->mtt_base = profile[i].start;
216 break;
217 case MLX4_RES_MCG:
218 dev->caps.num_mgms = profile[i].num >> 1;
219 dev->caps.num_amgms = profile[i].num >> 1;
220 init_hca->mc_base = profile[i].start;
221 init_hca->log_mc_entry_sz = ilog2(MLX4_MGM_ENTRY_SIZE);
222 init_hca->log_mc_table_sz = profile[i].log_num;
223 init_hca->log_mc_hash_sz = profile[i].log_num - 1;
224 break;
225 default:
226 break;
227 }
228 }
229
230 /*
231 * PDs don't take any HCA memory, but we assign them as part
232 * of the HCA profile anyway.
233 */
234 dev->caps.num_pds = MLX4_NUM_PDS;
235
236 kfree(profile);
237 return total_size;
238}
diff --git a/drivers/net/mlx4/qp.c b/drivers/net/mlx4/qp.c
new file mode 100644
index 000000000000..7f8b7d55b6e1
--- /dev/null
+++ b/drivers/net/mlx4/qp.c
@@ -0,0 +1,280 @@
1/*
2 * Copyright (c) 2004 Topspin Communications. All rights reserved.
3 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
4 * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
5 * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
6 *
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
11 * OpenIB.org BSD license below:
12 *
13 * Redistribution and use in source and binary forms, with or
14 * without modification, are permitted provided that the following
15 * conditions are met:
16 *
17 * - Redistributions of source code must retain the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer.
20 *
21 * - Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimer in the documentation and/or other materials
24 * provided with the distribution.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 * SOFTWARE.
34 */
35
36#include <linux/init.h>
37
38#include <linux/mlx4/cmd.h>
39#include <linux/mlx4/qp.h>
40
41#include "mlx4.h"
42#include "icm.h"
43
44void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type)
45{
46 struct mlx4_qp_table *qp_table = &mlx4_priv(dev)->qp_table;
47 struct mlx4_qp *qp;
48
49 spin_lock(&qp_table->lock);
50
51 qp = __mlx4_qp_lookup(dev, qpn);
52 if (qp)
53 atomic_inc(&qp->refcount);
54
55 spin_unlock(&qp_table->lock);
56
57 if (!qp) {
58 mlx4_warn(dev, "Async event for bogus QP %08x\n", qpn);
59 return;
60 }
61
62 qp->event(qp, event_type);
63
64 if (atomic_dec_and_test(&qp->refcount))
65 complete(&qp->free);
66}
67
68int mlx4_qp_modify(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
69 enum mlx4_qp_state cur_state, enum mlx4_qp_state new_state,
70 struct mlx4_qp_context *context, enum mlx4_qp_optpar optpar,
71 int sqd_event, struct mlx4_qp *qp)
72{
73 static const u16 op[MLX4_QP_NUM_STATE][MLX4_QP_NUM_STATE] = {
74 [MLX4_QP_STATE_RST] = {
75 [MLX4_QP_STATE_RST] = MLX4_CMD_2RST_QP,
76 [MLX4_QP_STATE_ERR] = MLX4_CMD_2ERR_QP,
77 [MLX4_QP_STATE_INIT] = MLX4_CMD_RST2INIT_QP,
78 },
79 [MLX4_QP_STATE_INIT] = {
80 [MLX4_QP_STATE_RST] = MLX4_CMD_2RST_QP,
81 [MLX4_QP_STATE_ERR] = MLX4_CMD_2ERR_QP,
82 [MLX4_QP_STATE_INIT] = MLX4_CMD_INIT2INIT_QP,
83 [MLX4_QP_STATE_RTR] = MLX4_CMD_INIT2RTR_QP,
84 },
85 [MLX4_QP_STATE_RTR] = {
86 [MLX4_QP_STATE_RST] = MLX4_CMD_2RST_QP,
87 [MLX4_QP_STATE_ERR] = MLX4_CMD_2ERR_QP,
88 [MLX4_QP_STATE_RTS] = MLX4_CMD_RTR2RTS_QP,
89 },
90 [MLX4_QP_STATE_RTS] = {
91 [MLX4_QP_STATE_RST] = MLX4_CMD_2RST_QP,
92 [MLX4_QP_STATE_ERR] = MLX4_CMD_2ERR_QP,
93 [MLX4_QP_STATE_RTS] = MLX4_CMD_RTS2RTS_QP,
94 [MLX4_QP_STATE_SQD] = MLX4_CMD_RTS2SQD_QP,
95 },
96 [MLX4_QP_STATE_SQD] = {
97 [MLX4_QP_STATE_RST] = MLX4_CMD_2RST_QP,
98 [MLX4_QP_STATE_ERR] = MLX4_CMD_2ERR_QP,
99 [MLX4_QP_STATE_RTS] = MLX4_CMD_SQD2RTS_QP,
100 [MLX4_QP_STATE_SQD] = MLX4_CMD_SQD2SQD_QP,
101 },
102 [MLX4_QP_STATE_SQER] = {
103 [MLX4_QP_STATE_RST] = MLX4_CMD_2RST_QP,
104 [MLX4_QP_STATE_ERR] = MLX4_CMD_2ERR_QP,
105 [MLX4_QP_STATE_RTS] = MLX4_CMD_SQERR2RTS_QP,
106 },
107 [MLX4_QP_STATE_ERR] = {
108 [MLX4_QP_STATE_RST] = MLX4_CMD_2RST_QP,
109 [MLX4_QP_STATE_ERR] = MLX4_CMD_2ERR_QP,
110 }
111 };
112
113 struct mlx4_cmd_mailbox *mailbox;
114 int ret = 0;
115
116 if (cur_state < 0 || cur_state >= MLX4_QP_NUM_STATE ||
117 new_state < 0 || cur_state >= MLX4_QP_NUM_STATE ||
118 !op[cur_state][new_state])
119 return -EINVAL;
120
121 if (op[cur_state][new_state] == MLX4_CMD_2RST_QP)
122 return mlx4_cmd(dev, 0, qp->qpn, 2,
123 MLX4_CMD_2RST_QP, MLX4_CMD_TIME_CLASS_A);
124
125 mailbox = mlx4_alloc_cmd_mailbox(dev);
126 if (IS_ERR(mailbox))
127 return PTR_ERR(mailbox);
128
129 if (cur_state == MLX4_QP_STATE_RST && new_state == MLX4_QP_STATE_INIT) {
130 u64 mtt_addr = mlx4_mtt_addr(dev, mtt);
131 context->mtt_base_addr_h = mtt_addr >> 32;
132 context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
133 context->log_page_size = mtt->page_shift - MLX4_ICM_PAGE_SHIFT;
134 }
135
136 *(__be32 *) mailbox->buf = cpu_to_be32(optpar);
137 memcpy(mailbox->buf + 8, context, sizeof *context);
138
139 ((struct mlx4_qp_context *) (mailbox->buf + 8))->local_qpn =
140 cpu_to_be32(qp->qpn);
141
142 ret = mlx4_cmd(dev, mailbox->dma, qp->qpn | (!!sqd_event << 31),
143 new_state == MLX4_QP_STATE_RST ? 2 : 0,
144 op[cur_state][new_state], MLX4_CMD_TIME_CLASS_C);
145
146 mlx4_free_cmd_mailbox(dev, mailbox);
147 return ret;
148}
149EXPORT_SYMBOL_GPL(mlx4_qp_modify);
150
151int mlx4_qp_alloc(struct mlx4_dev *dev, int sqpn, struct mlx4_qp *qp)
152{
153 struct mlx4_priv *priv = mlx4_priv(dev);
154 struct mlx4_qp_table *qp_table = &priv->qp_table;
155 int err;
156
157 if (sqpn)
158 qp->qpn = sqpn;
159 else {
160 qp->qpn = mlx4_bitmap_alloc(&qp_table->bitmap);
161 if (qp->qpn == -1)
162 return -ENOMEM;
163 }
164
165 err = mlx4_table_get(dev, &qp_table->qp_table, qp->qpn);
166 if (err)
167 goto err_out;
168
169 err = mlx4_table_get(dev, &qp_table->auxc_table, qp->qpn);
170 if (err)
171 goto err_put_qp;
172
173 err = mlx4_table_get(dev, &qp_table->altc_table, qp->qpn);
174 if (err)
175 goto err_put_auxc;
176
177 err = mlx4_table_get(dev, &qp_table->rdmarc_table, qp->qpn);
178 if (err)
179 goto err_put_altc;
180
181 err = mlx4_table_get(dev, &qp_table->cmpt_table, qp->qpn);
182 if (err)
183 goto err_put_rdmarc;
184
185 spin_lock_irq(&qp_table->lock);
186 err = radix_tree_insert(&dev->qp_table_tree, qp->qpn & (dev->caps.num_qps - 1), qp);
187 spin_unlock_irq(&qp_table->lock);
188 if (err)
189 goto err_put_cmpt;
190
191 atomic_set(&qp->refcount, 1);
192 init_completion(&qp->free);
193
194 return 0;
195
196err_put_cmpt:
197 mlx4_table_put(dev, &qp_table->cmpt_table, qp->qpn);
198
199err_put_rdmarc:
200 mlx4_table_put(dev, &qp_table->rdmarc_table, qp->qpn);
201
202err_put_altc:
203 mlx4_table_put(dev, &qp_table->altc_table, qp->qpn);
204
205err_put_auxc:
206 mlx4_table_put(dev, &qp_table->auxc_table, qp->qpn);
207
208err_put_qp:
209 mlx4_table_put(dev, &qp_table->qp_table, qp->qpn);
210
211err_out:
212 if (!sqpn)
213 mlx4_bitmap_free(&qp_table->bitmap, qp->qpn);
214
215 return err;
216}
217EXPORT_SYMBOL_GPL(mlx4_qp_alloc);
218
219void mlx4_qp_remove(struct mlx4_dev *dev, struct mlx4_qp *qp)
220{
221 struct mlx4_qp_table *qp_table = &mlx4_priv(dev)->qp_table;
222 unsigned long flags;
223
224 spin_lock_irqsave(&qp_table->lock, flags);
225 radix_tree_delete(&dev->qp_table_tree, qp->qpn & (dev->caps.num_qps - 1));
226 spin_unlock_irqrestore(&qp_table->lock, flags);
227}
228EXPORT_SYMBOL_GPL(mlx4_qp_remove);
229
230void mlx4_qp_free(struct mlx4_dev *dev, struct mlx4_qp *qp)
231{
232 struct mlx4_qp_table *qp_table = &mlx4_priv(dev)->qp_table;
233
234 if (atomic_dec_and_test(&qp->refcount))
235 complete(&qp->free);
236 wait_for_completion(&qp->free);
237
238 mlx4_table_put(dev, &qp_table->cmpt_table, qp->qpn);
239 mlx4_table_put(dev, &qp_table->rdmarc_table, qp->qpn);
240 mlx4_table_put(dev, &qp_table->altc_table, qp->qpn);
241 mlx4_table_put(dev, &qp_table->auxc_table, qp->qpn);
242 mlx4_table_put(dev, &qp_table->qp_table, qp->qpn);
243
244 mlx4_bitmap_free(&qp_table->bitmap, qp->qpn);
245}
246EXPORT_SYMBOL_GPL(mlx4_qp_free);
247
248static int mlx4_CONF_SPECIAL_QP(struct mlx4_dev *dev, u32 base_qpn)
249{
250 return mlx4_cmd(dev, 0, base_qpn, 0, MLX4_CMD_CONF_SPECIAL_QP,
251 MLX4_CMD_TIME_CLASS_B);
252}
253
254int __devinit mlx4_init_qp_table(struct mlx4_dev *dev)
255{
256 struct mlx4_qp_table *qp_table = &mlx4_priv(dev)->qp_table;
257 int err;
258
259 spin_lock_init(&qp_table->lock);
260 INIT_RADIX_TREE(&dev->qp_table_tree, GFP_ATOMIC);
261
262 /*
263 * We reserve 2 extra QPs per port for the special QPs. The
264 * block of special QPs must be aligned to a multiple of 8, so
265 * round up.
266 */
267 dev->caps.sqp_start = ALIGN(dev->caps.reserved_qps, 8);
268 err = mlx4_bitmap_init(&qp_table->bitmap, dev->caps.num_qps,
269 (1 << 24) - 1, dev->caps.sqp_start + 8);
270 if (err)
271 return err;
272
273 return mlx4_CONF_SPECIAL_QP(dev, dev->caps.sqp_start);
274}
275
276void mlx4_cleanup_qp_table(struct mlx4_dev *dev)
277{
278 mlx4_CONF_SPECIAL_QP(dev, 0);
279 mlx4_bitmap_cleanup(&mlx4_priv(dev)->qp_table.bitmap);
280}
diff --git a/drivers/net/mlx4/reset.c b/drivers/net/mlx4/reset.c
new file mode 100644
index 000000000000..e4dfd4b11a4a
--- /dev/null
+++ b/drivers/net/mlx4/reset.c
@@ -0,0 +1,182 @@
1/*
2 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/init.h>
34#include <linux/errno.h>
35#include <linux/pci.h>
36#include <linux/delay.h>
37#include <linux/slab.h>
38#include <linux/jiffies.h>
39
40#include "mlx4.h"
41
42int mlx4_reset(struct mlx4_dev *dev)
43{
44 void __iomem *reset;
45 u32 *hca_header = NULL;
46 int pcie_cap;
47 u16 devctl;
48 u16 linkctl;
49 u16 vendor;
50 unsigned long end;
51 u32 sem;
52 int i;
53 int err = 0;
54
55#define MLX4_RESET_BASE 0xf0000
56#define MLX4_RESET_SIZE 0x400
57#define MLX4_SEM_OFFSET 0x3fc
58#define MLX4_RESET_OFFSET 0x10
59#define MLX4_RESET_VALUE swab32(1)
60
61#define MLX4_SEM_TIMEOUT_JIFFIES (10 * HZ)
62#define MLX4_RESET_TIMEOUT_JIFFIES (2 * HZ)
63
64 /*
65 * Reset the chip. This is somewhat ugly because we have to
66 * save off the PCI header before reset and then restore it
67 * after the chip reboots. We skip config space offsets 22
68 * and 23 since those have a special meaning.
69 */
70
71 /* Do we need to save off the full 4K PCI Express header?? */
72 hca_header = kmalloc(256, GFP_KERNEL);
73 if (!hca_header) {
74 err = -ENOMEM;
75 mlx4_err(dev, "Couldn't allocate memory to save HCA "
76 "PCI header, aborting.\n");
77 goto out;
78 }
79
80 pcie_cap = pci_find_capability(dev->pdev, PCI_CAP_ID_EXP);
81
82 for (i = 0; i < 64; ++i) {
83 if (i == 22 || i == 23)
84 continue;
85 if (pci_read_config_dword(dev->pdev, i * 4, hca_header + i)) {
86 err = -ENODEV;
87 mlx4_err(dev, "Couldn't save HCA "
88 "PCI header, aborting.\n");
89 goto out;
90 }
91 }
92
93 reset = ioremap(pci_resource_start(dev->pdev, 0) + MLX4_RESET_BASE,
94 MLX4_RESET_SIZE);
95 if (!reset) {
96 err = -ENOMEM;
97 mlx4_err(dev, "Couldn't map HCA reset register, aborting.\n");
98 goto out;
99 }
100
101 /* grab HW semaphore to lock out flash updates */
102 end = jiffies + MLX4_SEM_TIMEOUT_JIFFIES;
103 do {
104 sem = readl(reset + MLX4_SEM_OFFSET);
105 if (!sem)
106 break;
107
108 msleep(1);
109 } while (time_before(jiffies, end));
110
111 if (sem) {
112 mlx4_err(dev, "Failed to obtain HW semaphore, aborting\n");
113 err = -EAGAIN;
114 iounmap(reset);
115 goto out;
116 }
117
118 /* actually hit reset */
119 writel(MLX4_RESET_VALUE, reset + MLX4_RESET_OFFSET);
120 iounmap(reset);
121
122 end = jiffies + MLX4_RESET_TIMEOUT_JIFFIES;
123 do {
124 if (!pci_read_config_word(dev->pdev, PCI_VENDOR_ID, &vendor) &&
125 vendor != 0xffff)
126 break;
127
128 msleep(1);
129 } while (time_before(jiffies, end));
130
131 if (vendor == 0xffff) {
132 err = -ENODEV;
133 mlx4_err(dev, "PCI device did not come back after reset, "
134 "aborting.\n");
135 goto out;
136 }
137
138 /* Now restore the PCI headers */
139 if (pcie_cap) {
140 devctl = hca_header[(pcie_cap + PCI_EXP_DEVCTL) / 4];
141 if (pci_write_config_word(dev->pdev, pcie_cap + PCI_EXP_DEVCTL,
142 devctl)) {
143 err = -ENODEV;
144 mlx4_err(dev, "Couldn't restore HCA PCI Express "
145 "Device Control register, aborting.\n");
146 goto out;
147 }
148 linkctl = hca_header[(pcie_cap + PCI_EXP_LNKCTL) / 4];
149 if (pci_write_config_word(dev->pdev, pcie_cap + PCI_EXP_LNKCTL,
150 linkctl)) {
151 err = -ENODEV;
152 mlx4_err(dev, "Couldn't restore HCA PCI Express "
153 "Link control register, aborting.\n");
154 goto out;
155 }
156 }
157
158 for (i = 0; i < 16; ++i) {
159 if (i * 4 == PCI_COMMAND)
160 continue;
161
162 if (pci_write_config_dword(dev->pdev, i * 4, hca_header[i])) {
163 err = -ENODEV;
164 mlx4_err(dev, "Couldn't restore HCA reg %x, "
165 "aborting.\n", i);
166 goto out;
167 }
168 }
169
170 if (pci_write_config_dword(dev->pdev, PCI_COMMAND,
171 hca_header[PCI_COMMAND / 4])) {
172 err = -ENODEV;
173 mlx4_err(dev, "Couldn't restore HCA COMMAND, "
174 "aborting.\n");
175 goto out;
176 }
177
178out:
179 kfree(hca_header);
180
181 return err;
182}
diff --git a/drivers/net/mlx4/srq.c b/drivers/net/mlx4/srq.c
new file mode 100644
index 000000000000..2134f83aed87
--- /dev/null
+++ b/drivers/net/mlx4/srq.c
@@ -0,0 +1,227 @@
1/*
2 * Copyright (c) 2006, 2007 Cisco Systems, Inc. All rights reserved.
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32
33#include <linux/init.h>
34
35#include <linux/mlx4/cmd.h>
36
37#include "mlx4.h"
38#include "icm.h"
39
40struct mlx4_srq_context {
41 __be32 state_logsize_srqn;
42 u8 logstride;
43 u8 reserved1[3];
44 u8 pg_offset;
45 u8 reserved2[3];
46 u32 reserved3;
47 u8 log_page_size;
48 u8 reserved4[2];
49 u8 mtt_base_addr_h;
50 __be32 mtt_base_addr_l;
51 __be32 pd;
52 __be16 limit_watermark;
53 __be16 wqe_cnt;
54 u16 reserved5;
55 __be16 wqe_counter;
56 u32 reserved6;
57 __be64 db_rec_addr;
58};
59
60void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type)
61{
62 struct mlx4_srq_table *srq_table = &mlx4_priv(dev)->srq_table;
63 struct mlx4_srq *srq;
64
65 spin_lock(&srq_table->lock);
66
67 srq = radix_tree_lookup(&srq_table->tree, srqn & (dev->caps.num_srqs - 1));
68 if (srq)
69 atomic_inc(&srq->refcount);
70
71 spin_unlock(&srq_table->lock);
72
73 if (!srq) {
74 mlx4_warn(dev, "Async event for bogus SRQ %08x\n", srqn);
75 return;
76 }
77
78 srq->event(srq, event_type);
79
80 if (atomic_dec_and_test(&srq->refcount))
81 complete(&srq->free);
82}
83
84static int mlx4_SW2HW_SRQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
85 int srq_num)
86{
87 return mlx4_cmd(dev, mailbox->dma, srq_num, 0, MLX4_CMD_SW2HW_SRQ,
88 MLX4_CMD_TIME_CLASS_A);
89}
90
91static int mlx4_HW2SW_SRQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
92 int srq_num)
93{
94 return mlx4_cmd_box(dev, 0, mailbox ? mailbox->dma : 0, srq_num,
95 mailbox ? 0 : 1, MLX4_CMD_HW2SW_SRQ,
96 MLX4_CMD_TIME_CLASS_A);
97}
98
99static int mlx4_ARM_SRQ(struct mlx4_dev *dev, int srq_num, int limit_watermark)
100{
101 return mlx4_cmd(dev, limit_watermark, srq_num, 0, MLX4_CMD_ARM_SRQ,
102 MLX4_CMD_TIME_CLASS_B);
103}
104
105int mlx4_srq_alloc(struct mlx4_dev *dev, u32 pdn, struct mlx4_mtt *mtt,
106 u64 db_rec, struct mlx4_srq *srq)
107{
108 struct mlx4_srq_table *srq_table = &mlx4_priv(dev)->srq_table;
109 struct mlx4_cmd_mailbox *mailbox;
110 struct mlx4_srq_context *srq_context;
111 u64 mtt_addr;
112 int err;
113
114 srq->srqn = mlx4_bitmap_alloc(&srq_table->bitmap);
115 if (srq->srqn == -1)
116 return -ENOMEM;
117
118 err = mlx4_table_get(dev, &srq_table->table, srq->srqn);
119 if (err)
120 goto err_out;
121
122 err = mlx4_table_get(dev, &srq_table->cmpt_table, srq->srqn);
123 if (err)
124 goto err_put;
125
126 spin_lock_irq(&srq_table->lock);
127 err = radix_tree_insert(&srq_table->tree, srq->srqn, srq);
128 spin_unlock_irq(&srq_table->lock);
129 if (err)
130 goto err_cmpt_put;
131
132 mailbox = mlx4_alloc_cmd_mailbox(dev);
133 if (IS_ERR(mailbox)) {
134 err = PTR_ERR(mailbox);
135 goto err_radix;
136 }
137
138 srq_context = mailbox->buf;
139 memset(srq_context, 0, sizeof *srq_context);
140
141 srq_context->state_logsize_srqn = cpu_to_be32((ilog2(srq->max) << 24) |
142 srq->srqn);
143 srq_context->logstride = srq->wqe_shift - 4;
144 srq_context->log_page_size = mtt->page_shift - MLX4_ICM_PAGE_SHIFT;
145
146 mtt_addr = mlx4_mtt_addr(dev, mtt);
147 srq_context->mtt_base_addr_h = mtt_addr >> 32;
148 srq_context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
149 srq_context->pd = cpu_to_be32(pdn);
150 srq_context->db_rec_addr = cpu_to_be64(db_rec);
151
152 err = mlx4_SW2HW_SRQ(dev, mailbox, srq->srqn);
153 mlx4_free_cmd_mailbox(dev, mailbox);
154 if (err)
155 goto err_radix;
156
157 atomic_set(&srq->refcount, 1);
158 init_completion(&srq->free);
159
160 return 0;
161
162err_radix:
163 spin_lock_irq(&srq_table->lock);
164 radix_tree_delete(&srq_table->tree, srq->srqn);
165 spin_unlock_irq(&srq_table->lock);
166
167err_cmpt_put:
168 mlx4_table_put(dev, &srq_table->cmpt_table, srq->srqn);
169
170err_put:
171 mlx4_table_put(dev, &srq_table->table, srq->srqn);
172
173err_out:
174 mlx4_bitmap_free(&srq_table->bitmap, srq->srqn);
175
176 return err;
177}
178EXPORT_SYMBOL_GPL(mlx4_srq_alloc);
179
180void mlx4_srq_free(struct mlx4_dev *dev, struct mlx4_srq *srq)
181{
182 struct mlx4_srq_table *srq_table = &mlx4_priv(dev)->srq_table;
183 int err;
184
185 err = mlx4_HW2SW_SRQ(dev, NULL, srq->srqn);
186 if (err)
187 mlx4_warn(dev, "HW2SW_SRQ failed (%d) for SRQN %06x\n", err, srq->srqn);
188
189 spin_lock_irq(&srq_table->lock);
190 radix_tree_delete(&srq_table->tree, srq->srqn);
191 spin_unlock_irq(&srq_table->lock);
192
193 if (atomic_dec_and_test(&srq->refcount))
194 complete(&srq->free);
195 wait_for_completion(&srq->free);
196
197 mlx4_table_put(dev, &srq_table->table, srq->srqn);
198 mlx4_bitmap_free(&srq_table->bitmap, srq->srqn);
199}
200EXPORT_SYMBOL_GPL(mlx4_srq_free);
201
202int mlx4_srq_arm(struct mlx4_dev *dev, struct mlx4_srq *srq, int limit_watermark)
203{
204 return mlx4_ARM_SRQ(dev, srq->srqn, limit_watermark);
205}
206EXPORT_SYMBOL_GPL(mlx4_srq_arm);
207
208int __devinit mlx4_init_srq_table(struct mlx4_dev *dev)
209{
210 struct mlx4_srq_table *srq_table = &mlx4_priv(dev)->srq_table;
211 int err;
212
213 spin_lock_init(&srq_table->lock);
214 INIT_RADIX_TREE(&srq_table->tree, GFP_ATOMIC);
215
216 err = mlx4_bitmap_init(&srq_table->bitmap, dev->caps.num_srqs,
217 dev->caps.num_srqs - 1, dev->caps.reserved_srqs);
218 if (err)
219 return err;
220
221 return 0;
222}
223
224void mlx4_cleanup_srq_table(struct mlx4_dev *dev)
225{
226 mlx4_bitmap_cleanup(&mlx4_priv(dev)->srq_table.bitmap);
227}
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 16e3c4315e82..5d14be7405a3 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -290,6 +290,8 @@ MODULE_PARM_DESC(myri10ge_wcfifo, "Enable WC Fifo when WC is enabled\n");
290 290
291#define myri10ge_pio_copy(to,from,size) __iowrite64_copy(to,from,size/8) 291#define myri10ge_pio_copy(to,from,size) __iowrite64_copy(to,from,size/8)
292 292
293static void myri10ge_set_multicast_list(struct net_device *dev);
294
293static inline void put_be32(__be32 val, __be32 __iomem * p) 295static inline void put_be32(__be32 val, __be32 __iomem * p)
294{ 296{
295 __raw_writel((__force __u32) val, (__force void __iomem *)p); 297 __raw_writel((__force __u32) val, (__force void __iomem *)p);
@@ -353,6 +355,8 @@ myri10ge_send_cmd(struct myri10ge_priv *mgp, u32 cmd,
353 return 0; 355 return 0;
354 } else if (result == MXGEFW_CMD_UNKNOWN) { 356 } else if (result == MXGEFW_CMD_UNKNOWN) {
355 return -ENOSYS; 357 return -ENOSYS;
358 } else if (result == MXGEFW_CMD_ERROR_UNALIGNED) {
359 return -E2BIG;
356 } else { 360 } else {
357 dev_err(&mgp->pdev->dev, 361 dev_err(&mgp->pdev->dev,
358 "command %d failed, result = %d\n", 362 "command %d failed, result = %d\n",
@@ -712,14 +716,78 @@ myri10ge_change_promisc(struct myri10ge_priv *mgp, int promisc, int atomic)
712 mgp->dev->name); 716 mgp->dev->name);
713} 717}
714 718
715static int myri10ge_reset(struct myri10ge_priv *mgp) 719static int myri10ge_dma_test(struct myri10ge_priv *mgp, int test_type)
716{ 720{
717 struct myri10ge_cmd cmd; 721 struct myri10ge_cmd cmd;
718 int status; 722 int status;
719 size_t bytes;
720 u32 len; 723 u32 len;
721 struct page *dmatest_page; 724 struct page *dmatest_page;
722 dma_addr_t dmatest_bus; 725 dma_addr_t dmatest_bus;
726 char *test = " ";
727
728 dmatest_page = alloc_page(GFP_KERNEL);
729 if (!dmatest_page)
730 return -ENOMEM;
731 dmatest_bus = pci_map_page(mgp->pdev, dmatest_page, 0, PAGE_SIZE,
732 DMA_BIDIRECTIONAL);
733
734 /* Run a small DMA test.
735 * The magic multipliers to the length tell the firmware
736 * to do DMA read, write, or read+write tests. The
737 * results are returned in cmd.data0. The upper 16
738 * bits or the return is the number of transfers completed.
739 * The lower 16 bits is the time in 0.5us ticks that the
740 * transfers took to complete.
741 */
742
743 len = mgp->tx.boundary;
744
745 cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
746 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
747 cmd.data2 = len * 0x10000;
748 status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
749 if (status != 0) {
750 test = "read";
751 goto abort;
752 }
753 mgp->read_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff);
754 cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
755 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
756 cmd.data2 = len * 0x1;
757 status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
758 if (status != 0) {
759 test = "write";
760 goto abort;
761 }
762 mgp->write_dma = ((cmd.data0 >> 16) * len * 2) / (cmd.data0 & 0xffff);
763
764 cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
765 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
766 cmd.data2 = len * 0x10001;
767 status = myri10ge_send_cmd(mgp, test_type, &cmd, 0);
768 if (status != 0) {
769 test = "read/write";
770 goto abort;
771 }
772 mgp->read_write_dma = ((cmd.data0 >> 16) * len * 2 * 2) /
773 (cmd.data0 & 0xffff);
774
775abort:
776 pci_unmap_page(mgp->pdev, dmatest_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
777 put_page(dmatest_page);
778
779 if (status != 0 && test_type != MXGEFW_CMD_UNALIGNED_TEST)
780 dev_warn(&mgp->pdev->dev, "DMA %s benchmark failed: %d\n",
781 test, status);
782
783 return status;
784}
785
786static int myri10ge_reset(struct myri10ge_priv *mgp)
787{
788 struct myri10ge_cmd cmd;
789 int status;
790 size_t bytes;
723 791
724 /* try to send a reset command to the card to see if it 792 /* try to send a reset command to the card to see if it
725 * is alive */ 793 * is alive */
@@ -729,11 +797,8 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
729 dev_err(&mgp->pdev->dev, "failed reset\n"); 797 dev_err(&mgp->pdev->dev, "failed reset\n");
730 return -ENXIO; 798 return -ENXIO;
731 } 799 }
732 dmatest_page = alloc_page(GFP_KERNEL); 800
733 if (!dmatest_page) 801 (void)myri10ge_dma_test(mgp, MXGEFW_DMA_TEST);
734 return -ENOMEM;
735 dmatest_bus = pci_map_page(mgp->pdev, dmatest_page, 0, PAGE_SIZE,
736 DMA_BIDIRECTIONAL);
737 802
738 /* Now exchange information about interrupts */ 803 /* Now exchange information about interrupts */
739 804
@@ -761,52 +826,6 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
761 } 826 }
762 put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr); 827 put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr);
763 828
764 /* Run a small DMA test.
765 * The magic multipliers to the length tell the firmware
766 * to do DMA read, write, or read+write tests. The
767 * results are returned in cmd.data0. The upper 16
768 * bits or the return is the number of transfers completed.
769 * The lower 16 bits is the time in 0.5us ticks that the
770 * transfers took to complete.
771 */
772
773 len = mgp->tx.boundary;
774
775 cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
776 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
777 cmd.data2 = len * 0x10000;
778 status = myri10ge_send_cmd(mgp, MXGEFW_DMA_TEST, &cmd, 0);
779 if (status == 0)
780 mgp->read_dma = ((cmd.data0 >> 16) * len * 2) /
781 (cmd.data0 & 0xffff);
782 else
783 dev_warn(&mgp->pdev->dev, "DMA read benchmark failed: %d\n",
784 status);
785 cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
786 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
787 cmd.data2 = len * 0x1;
788 status = myri10ge_send_cmd(mgp, MXGEFW_DMA_TEST, &cmd, 0);
789 if (status == 0)
790 mgp->write_dma = ((cmd.data0 >> 16) * len * 2) /
791 (cmd.data0 & 0xffff);
792 else
793 dev_warn(&mgp->pdev->dev, "DMA write benchmark failed: %d\n",
794 status);
795
796 cmd.data0 = MYRI10GE_LOWPART_TO_U32(dmatest_bus);
797 cmd.data1 = MYRI10GE_HIGHPART_TO_U32(dmatest_bus);
798 cmd.data2 = len * 0x10001;
799 status = myri10ge_send_cmd(mgp, MXGEFW_DMA_TEST, &cmd, 0);
800 if (status == 0)
801 mgp->read_write_dma = ((cmd.data0 >> 16) * len * 2 * 2) /
802 (cmd.data0 & 0xffff);
803 else
804 dev_warn(&mgp->pdev->dev,
805 "DMA read/write benchmark failed: %d\n", status);
806
807 pci_unmap_page(mgp->pdev, dmatest_bus, PAGE_SIZE, DMA_BIDIRECTIONAL);
808 put_page(dmatest_page);
809
810 memset(mgp->rx_done.entry, 0, bytes); 829 memset(mgp->rx_done.entry, 0, bytes);
811 830
812 /* reset mcp/driver shared state back to 0 */ 831 /* reset mcp/driver shared state back to 0 */
@@ -820,10 +839,8 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
820 mgp->rx_done.cnt = 0; 839 mgp->rx_done.cnt = 0;
821 mgp->link_changes = 0; 840 mgp->link_changes = 0;
822 status = myri10ge_update_mac_address(mgp, mgp->dev->dev_addr); 841 status = myri10ge_update_mac_address(mgp, mgp->dev->dev_addr);
823 myri10ge_change_promisc(mgp, 0, 0);
824 myri10ge_change_pause(mgp, mgp->pause); 842 myri10ge_change_pause(mgp, mgp->pause);
825 if (mgp->adopted_rx_filter_bug) 843 myri10ge_set_multicast_list(mgp->dev);
826 (void)myri10ge_send_cmd(mgp, MXGEFW_ENABLE_ALLMULTI, &cmd, 1);
827 return status; 844 return status;
828} 845}
829 846
@@ -1355,7 +1372,9 @@ static const char myri10ge_gstrings_stats[][ETH_GSTRING_LEN] = {
1355 "tx_req", "tx_done", "rx_small_cnt", "rx_big_cnt", 1372 "tx_req", "tx_done", "rx_small_cnt", "rx_big_cnt",
1356 "wake_queue", "stop_queue", "watchdog_resets", "tx_linearized", 1373 "wake_queue", "stop_queue", "watchdog_resets", "tx_linearized",
1357 "link_changes", "link_up", "dropped_link_overflow", 1374 "link_changes", "link_up", "dropped_link_overflow",
1358 "dropped_link_error_or_filtered", "dropped_multicast_filtered", 1375 "dropped_link_error_or_filtered",
1376 "dropped_pause", "dropped_bad_phy", "dropped_bad_crc32",
1377 "dropped_unicast_filtered", "dropped_multicast_filtered",
1359 "dropped_runt", "dropped_overrun", "dropped_no_small_buffer", 1378 "dropped_runt", "dropped_overrun", "dropped_no_small_buffer",
1360 "dropped_no_big_buffer" 1379 "dropped_no_big_buffer"
1361}; 1380};
@@ -1412,6 +1431,11 @@ myri10ge_get_ethtool_stats(struct net_device *netdev,
1412 data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_link_overflow); 1431 data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_link_overflow);
1413 data[i++] = 1432 data[i++] =
1414 (unsigned int)ntohl(mgp->fw_stats->dropped_link_error_or_filtered); 1433 (unsigned int)ntohl(mgp->fw_stats->dropped_link_error_or_filtered);
1434 data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_pause);
1435 data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_bad_phy);
1436 data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_bad_crc32);
1437 data[i++] =
1438 (unsigned int)ntohl(mgp->fw_stats->dropped_unicast_filtered);
1415 data[i++] = 1439 data[i++] =
1416 (unsigned int)ntohl(mgp->fw_stats->dropped_multicast_filtered); 1440 (unsigned int)ntohl(mgp->fw_stats->dropped_multicast_filtered);
1417 data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_runt); 1441 data[i++] = (unsigned int)ntohl(mgp->fw_stats->dropped_runt);
@@ -2276,7 +2300,7 @@ static void myri10ge_set_multicast_list(struct net_device *dev)
2276 myri10ge_change_promisc(mgp, dev->flags & IFF_PROMISC, 1); 2300 myri10ge_change_promisc(mgp, dev->flags & IFF_PROMISC, 1);
2277 2301
2278 /* This firmware is known to not support multicast */ 2302 /* This firmware is known to not support multicast */
2279 if (!mgp->fw_multicast_support || mgp->adopted_rx_filter_bug) 2303 if (!mgp->fw_multicast_support)
2280 return; 2304 return;
2281 2305
2282 /* Disable multicast filtering */ 2306 /* Disable multicast filtering */
@@ -2288,7 +2312,7 @@ static void myri10ge_set_multicast_list(struct net_device *dev)
2288 goto abort; 2312 goto abort;
2289 } 2313 }
2290 2314
2291 if (dev->flags & IFF_ALLMULTI) { 2315 if ((dev->flags & IFF_ALLMULTI) || mgp->adopted_rx_filter_bug) {
2292 /* request to disable multicast filtering, so quit here */ 2316 /* request to disable multicast filtering, so quit here */
2293 return; 2317 return;
2294 } 2318 }
@@ -2461,8 +2485,6 @@ static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
2461 err_cap |= PCI_ERR_CAP_ECRC_GENE; 2485 err_cap |= PCI_ERR_CAP_ECRC_GENE;
2462 pci_write_config_dword(bridge, cap + PCI_ERR_CAP, err_cap); 2486 pci_write_config_dword(bridge, cap + PCI_ERR_CAP, err_cap);
2463 dev_info(dev, "Enabled ECRC on upstream bridge %s\n", pci_name(bridge)); 2487 dev_info(dev, "Enabled ECRC on upstream bridge %s\n", pci_name(bridge));
2464 mgp->tx.boundary = 4096;
2465 mgp->fw_name = myri10ge_fw_aligned;
2466} 2488}
2467 2489
2468/* 2490/*
@@ -2484,22 +2506,70 @@ static void myri10ge_enable_ecrc(struct myri10ge_priv *mgp)
2484 * firmware image, and set tx.boundary to 4KB. 2506 * firmware image, and set tx.boundary to 4KB.
2485 */ 2507 */
2486 2508
2487#define PCI_DEVICE_ID_INTEL_E5000_PCIE23 0x25f7 2509static void myri10ge_firmware_probe(struct myri10ge_priv *mgp)
2488#define PCI_DEVICE_ID_INTEL_E5000_PCIE47 0x25fa
2489#define PCI_DEVICE_ID_INTEL_6300ESB_PCIEE1 0x3510
2490#define PCI_DEVICE_ID_INTEL_6300ESB_PCIEE4 0x351b
2491#define PCI_DEVICE_ID_INTEL_E3000_PCIE 0x2779
2492#define PCI_DEVICE_ID_INTEL_E3010_PCIE 0x277a
2493#define PCI_DEVICE_ID_SERVERWORKS_HT2100_PCIE_FIRST 0x140
2494#define PCI_DEVICE_ID_SERVERWORKS_HT2100_PCIE_LAST 0x142
2495
2496static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
2497{ 2510{
2498 struct pci_dev *bridge = mgp->pdev->bus->self; 2511 struct pci_dev *pdev = mgp->pdev;
2512 struct device *dev = &pdev->dev;
2513 int cap, status;
2514 u16 val;
2515
2516 mgp->tx.boundary = 4096;
2517 /*
2518 * Verify the max read request size was set to 4KB
2519 * before trying the test with 4KB.
2520 */
2521 cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
2522 if (cap < 64) {
2523 dev_err(dev, "Bad PCI_CAP_ID_EXP location %d\n", cap);
2524 goto abort;
2525 }
2526 status = pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &val);
2527 if (status != 0) {
2528 dev_err(dev, "Couldn't read max read req size: %d\n", status);
2529 goto abort;
2530 }
2531 if ((val & (5 << 12)) != (5 << 12)) {
2532 dev_warn(dev, "Max Read Request size != 4096 (0x%x)\n", val);
2533 mgp->tx.boundary = 2048;
2534 }
2535 /*
2536 * load the optimized firmware (which assumes aligned PCIe
2537 * completions) in order to see if it works on this host.
2538 */
2539 mgp->fw_name = myri10ge_fw_aligned;
2540 status = myri10ge_load_firmware(mgp);
2541 if (status != 0) {
2542 goto abort;
2543 }
2544
2545 /*
2546 * Enable ECRC if possible
2547 */
2548 myri10ge_enable_ecrc(mgp);
2549
2550 /*
2551 * Run a DMA test which watches for unaligned completions and
2552 * aborts on the first one seen.
2553 */
2499 2554
2555 status = myri10ge_dma_test(mgp, MXGEFW_CMD_UNALIGNED_TEST);
2556 if (status == 0)
2557 return; /* keep the aligned firmware */
2558
2559 if (status != -E2BIG)
2560 dev_warn(dev, "DMA test failed: %d\n", status);
2561 if (status == -ENOSYS)
2562 dev_warn(dev, "Falling back to ethp! "
2563 "Please install up to date fw\n");
2564abort:
2565 /* fall back to using the unaligned firmware */
2500 mgp->tx.boundary = 2048; 2566 mgp->tx.boundary = 2048;
2501 mgp->fw_name = myri10ge_fw_unaligned; 2567 mgp->fw_name = myri10ge_fw_unaligned;
2502 2568
2569}
2570
2571static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
2572{
2503 if (myri10ge_force_firmware == 0) { 2573 if (myri10ge_force_firmware == 0) {
2504 int link_width, exp_cap; 2574 int link_width, exp_cap;
2505 u16 lnk; 2575 u16 lnk;
@@ -2508,8 +2578,6 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
2508 pci_read_config_word(mgp->pdev, exp_cap + PCI_EXP_LNKSTA, &lnk); 2578 pci_read_config_word(mgp->pdev, exp_cap + PCI_EXP_LNKSTA, &lnk);
2509 link_width = (lnk >> 4) & 0x3f; 2579 link_width = (lnk >> 4) & 0x3f;
2510 2580
2511 myri10ge_enable_ecrc(mgp);
2512
2513 /* Check to see if Link is less than 8 or if the 2581 /* Check to see if Link is less than 8 or if the
2514 * upstream bridge is known to provide aligned 2582 * upstream bridge is known to provide aligned
2515 * completions */ 2583 * completions */
@@ -2518,46 +2586,8 @@ static void myri10ge_select_firmware(struct myri10ge_priv *mgp)
2518 link_width); 2586 link_width);
2519 mgp->tx.boundary = 4096; 2587 mgp->tx.boundary = 4096;
2520 mgp->fw_name = myri10ge_fw_aligned; 2588 mgp->fw_name = myri10ge_fw_aligned;
2521 } else if (bridge && 2589 } else {
2522 /* ServerWorks HT2000/HT1000 */ 2590 myri10ge_firmware_probe(mgp);
2523 ((bridge->vendor == PCI_VENDOR_ID_SERVERWORKS
2524 && bridge->device ==
2525 PCI_DEVICE_ID_SERVERWORKS_HT2000_PCIE)
2526 /* ServerWorks HT2100 */
2527 || (bridge->vendor == PCI_VENDOR_ID_SERVERWORKS
2528 && bridge->device >=
2529 PCI_DEVICE_ID_SERVERWORKS_HT2100_PCIE_FIRST
2530 && bridge->device <=
2531 PCI_DEVICE_ID_SERVERWORKS_HT2100_PCIE_LAST)
2532 /* All Intel E3000/E3010 PCIE ports */
2533 || (bridge->vendor == PCI_VENDOR_ID_INTEL
2534 && (bridge->device ==
2535 PCI_DEVICE_ID_INTEL_E3000_PCIE
2536 || bridge->device ==
2537 PCI_DEVICE_ID_INTEL_E3010_PCIE))
2538 /* All Intel 6310/6311/6321ESB PCIE ports */
2539 || (bridge->vendor == PCI_VENDOR_ID_INTEL
2540 && bridge->device >=
2541 PCI_DEVICE_ID_INTEL_6300ESB_PCIEE1
2542 && bridge->device <=
2543 PCI_DEVICE_ID_INTEL_6300ESB_PCIEE4)
2544 /* All Intel E5000 PCIE ports */
2545 || (bridge->vendor == PCI_VENDOR_ID_INTEL
2546 && bridge->device >=
2547 PCI_DEVICE_ID_INTEL_E5000_PCIE23
2548 && bridge->device <=
2549 PCI_DEVICE_ID_INTEL_E5000_PCIE47))) {
2550 dev_info(&mgp->pdev->dev,
2551 "Assuming aligned completions (0x%x:0x%x)\n",
2552 bridge->vendor, bridge->device);
2553 mgp->tx.boundary = 4096;
2554 mgp->fw_name = myri10ge_fw_aligned;
2555 } else if (bridge &&
2556 bridge->vendor == PCI_VENDOR_ID_SGI &&
2557 bridge->device == 0x4002 /* TIOCE pcie-port */ ) {
2558 /* this pcie bridge does not support 4K rdma request */
2559 mgp->tx.boundary = 2048;
2560 mgp->fw_name = myri10ge_fw_aligned;
2561 } 2591 }
2562 } else { 2592 } else {
2563 if (myri10ge_force_firmware == 1) { 2593 if (myri10ge_force_firmware == 1) {
@@ -2825,7 +2855,6 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2825 status = -ENODEV; 2855 status = -ENODEV;
2826 goto abort_with_netdev; 2856 goto abort_with_netdev;
2827 } 2857 }
2828 myri10ge_select_firmware(mgp);
2829 2858
2830 /* Find the vendor-specific cap so we can check 2859 /* Find the vendor-specific cap so we can check
2831 * the reboot register later on */ 2860 * the reboot register later on */
@@ -2919,6 +2948,8 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
2919 goto abort_with_ioremap; 2948 goto abort_with_ioremap;
2920 memset(mgp->rx_done.entry, 0, bytes); 2949 memset(mgp->rx_done.entry, 0, bytes);
2921 2950
2951 myri10ge_select_firmware(mgp);
2952
2922 status = myri10ge_load_firmware(mgp); 2953 status = myri10ge_load_firmware(mgp);
2923 if (status != 0) { 2954 if (status != 0) {
2924 dev_err(&pdev->dev, "failed to load firmware\n"); 2955 dev_err(&pdev->dev, "failed to load firmware\n");
diff --git a/drivers/net/myri10ge/myri10ge_mcp.h b/drivers/net/myri10ge/myri10ge_mcp.h
index 29463b301a84..a1d2a22296a9 100644
--- a/drivers/net/myri10ge/myri10ge_mcp.h
+++ b/drivers/net/myri10ge/myri10ge_mcp.h
@@ -200,6 +200,13 @@ enum myri10ge_mcp_cmd_type {
200 /* data0, data1 = bus addr, 200 /* data0, data1 = bus addr,
201 * data2 = sizeof(struct mcp_irq_data) from driver point of view, allows 201 * data2 = sizeof(struct mcp_irq_data) from driver point of view, allows
202 * adding new stuff to mcp_irq_data without changing the ABI */ 202 * adding new stuff to mcp_irq_data without changing the ABI */
203
204 MXGEFW_CMD_UNALIGNED_TEST,
205 /* same than DMA_TEST (same args) but abort with UNALIGNED on unaligned
206 * chipset */
207
208 MXGEFW_CMD_UNALIGNED_STATUS
209 /* return data = boolean, true if the chipset is known to be unaligned */
203}; 210};
204 211
205enum myri10ge_mcp_cmd_status { 212enum myri10ge_mcp_cmd_status {
@@ -212,18 +219,27 @@ enum myri10ge_mcp_cmd_status {
212 MXGEFW_CMD_ERROR_HASH_ERROR, 219 MXGEFW_CMD_ERROR_HASH_ERROR,
213 MXGEFW_CMD_ERROR_BAD_PORT, 220 MXGEFW_CMD_ERROR_BAD_PORT,
214 MXGEFW_CMD_ERROR_RESOURCES, 221 MXGEFW_CMD_ERROR_RESOURCES,
215 MXGEFW_CMD_ERROR_MULTICAST 222 MXGEFW_CMD_ERROR_MULTICAST,
223 MXGEFW_CMD_ERROR_UNALIGNED
216}; 224};
217 225
218#define MXGEFW_OLD_IRQ_DATA_LEN 40 226#define MXGEFW_OLD_IRQ_DATA_LEN 40
219 227
220struct mcp_irq_data { 228struct mcp_irq_data {
221 /* add new counters at the beginning */ 229 /* add new counters at the beginning */
222 __be32 future_use[5]; 230 __be32 future_use[1];
231 __be32 dropped_pause;
232 __be32 dropped_unicast_filtered;
233 __be32 dropped_bad_crc32;
234 __be32 dropped_bad_phy;
223 __be32 dropped_multicast_filtered; 235 __be32 dropped_multicast_filtered;
224 /* 40 Bytes */ 236 /* 40 Bytes */
225 __be32 send_done_count; 237 __be32 send_done_count;
226 238
239#define MXGEFW_LINK_DOWN 0
240#define MXGEFW_LINK_UP 1
241#define MXGEFW_LINK_MYRINET 2
242#define MXGEFW_LINK_UNKNOWN 3
227 __be32 link_up; 243 __be32 link_up;
228 __be32 dropped_link_overflow; 244 __be32 dropped_link_overflow;
229 __be32 dropped_link_error_or_filtered; 245 __be32 dropped_link_error_or_filtered;
diff --git a/drivers/net/natsemi.c b/drivers/net/natsemi.c
index a8d7ff2c96ac..4cf0d3fcb519 100644
--- a/drivers/net/natsemi.c
+++ b/drivers/net/natsemi.c
@@ -81,6 +81,8 @@ static const int multicast_filter_limit = 100;
81 Setting to > 1518 effectively disables this feature. */ 81 Setting to > 1518 effectively disables this feature. */
82static int rx_copybreak; 82static int rx_copybreak;
83 83
84static int dspcfg_workaround = 1;
85
84/* Used to pass the media type, etc. 86/* Used to pass the media type, etc.
85 Both 'options[]' and 'full_duplex[]' should exist for driver 87 Both 'options[]' and 'full_duplex[]' should exist for driver
86 interoperability. 88 interoperability.
@@ -129,7 +131,6 @@ static const char version[] __devinitdata =
129 KERN_INFO DRV_NAME " dp8381x driver, version " 131 KERN_INFO DRV_NAME " dp8381x driver, version "
130 DRV_VERSION ", " DRV_RELDATE "\n" 132 DRV_VERSION ", " DRV_RELDATE "\n"
131 KERN_INFO " originally by Donald Becker <becker@scyld.com>\n" 133 KERN_INFO " originally by Donald Becker <becker@scyld.com>\n"
132 KERN_INFO " http://www.scyld.com/network/natsemi.html\n"
133 KERN_INFO " 2.4.x kernel port by Jeff Garzik, Tjeerd Mulder\n"; 134 KERN_INFO " 2.4.x kernel port by Jeff Garzik, Tjeerd Mulder\n";
134 135
135MODULE_AUTHOR("Donald Becker <becker@scyld.com>"); 136MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
@@ -139,12 +140,14 @@ MODULE_LICENSE("GPL");
139module_param(mtu, int, 0); 140module_param(mtu, int, 0);
140module_param(debug, int, 0); 141module_param(debug, int, 0);
141module_param(rx_copybreak, int, 0); 142module_param(rx_copybreak, int, 0);
143module_param(dspcfg_workaround, int, 1);
142module_param_array(options, int, NULL, 0); 144module_param_array(options, int, NULL, 0);
143module_param_array(full_duplex, int, NULL, 0); 145module_param_array(full_duplex, int, NULL, 0);
144MODULE_PARM_DESC(mtu, "DP8381x MTU (all boards)"); 146MODULE_PARM_DESC(mtu, "DP8381x MTU (all boards)");
145MODULE_PARM_DESC(debug, "DP8381x default debug level"); 147MODULE_PARM_DESC(debug, "DP8381x default debug level");
146MODULE_PARM_DESC(rx_copybreak, 148MODULE_PARM_DESC(rx_copybreak,
147 "DP8381x copy breakpoint for copy-only-tiny-frames"); 149 "DP8381x copy breakpoint for copy-only-tiny-frames");
150MODULE_PARM_DESC(dspcfg_workaround, "DP8381x: control DspCfg workaround");
148MODULE_PARM_DESC(options, 151MODULE_PARM_DESC(options,
149 "DP8381x: Bits 0-3: media type, bit 17: full duplex"); 152 "DP8381x: Bits 0-3: media type, bit 17: full duplex");
150MODULE_PARM_DESC(full_duplex, "DP8381x full duplex setting(s) (1)"); 153MODULE_PARM_DESC(full_duplex, "DP8381x full duplex setting(s) (1)");
@@ -590,6 +593,7 @@ struct netdev_private {
590 u32 srr; 593 u32 srr;
591 /* expected DSPCFG value */ 594 /* expected DSPCFG value */
592 u16 dspcfg; 595 u16 dspcfg;
596 int dspcfg_workaround;
593 /* parms saved in ethtool format */ 597 /* parms saved in ethtool format */
594 u16 speed; /* The forced speed, 10Mb, 100Mb, gigabit */ 598 u16 speed; /* The forced speed, 10Mb, 100Mb, gigabit */
595 u8 duplex; /* Duplex, half or full */ 599 u8 duplex; /* Duplex, half or full */
@@ -656,6 +660,56 @@ static int netdev_get_regs(struct net_device *dev, u8 *buf);
656static int netdev_get_eeprom(struct net_device *dev, u8 *buf); 660static int netdev_get_eeprom(struct net_device *dev, u8 *buf);
657static const struct ethtool_ops ethtool_ops; 661static const struct ethtool_ops ethtool_ops;
658 662
663#define NATSEMI_ATTR(_name) \
664static ssize_t natsemi_show_##_name(struct device *dev, \
665 struct device_attribute *attr, char *buf); \
666 static ssize_t natsemi_set_##_name(struct device *dev, \
667 struct device_attribute *attr, \
668 const char *buf, size_t count); \
669 static DEVICE_ATTR(_name, 0644, natsemi_show_##_name, natsemi_set_##_name)
670
671#define NATSEMI_CREATE_FILE(_dev, _name) \
672 device_create_file(&_dev->dev, &dev_attr_##_name)
673#define NATSEMI_REMOVE_FILE(_dev, _name) \
674 device_create_file(&_dev->dev, &dev_attr_##_name)
675
676NATSEMI_ATTR(dspcfg_workaround);
677
678static ssize_t natsemi_show_dspcfg_workaround(struct device *dev,
679 struct device_attribute *attr,
680 char *buf)
681{
682 struct netdev_private *np = netdev_priv(to_net_dev(dev));
683
684 return sprintf(buf, "%s\n", np->dspcfg_workaround ? "on" : "off");
685}
686
687static ssize_t natsemi_set_dspcfg_workaround(struct device *dev,
688 struct device_attribute *attr,
689 const char *buf, size_t count)
690{
691 struct netdev_private *np = netdev_priv(to_net_dev(dev));
692 int new_setting;
693 u32 flags;
694
695 /* Find out the new setting */
696 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
697 new_setting = 1;
698 else if (!strncmp("off", buf, count - 1)
699 || !strncmp("0", buf, count - 1))
700 new_setting = 0;
701 else
702 return count;
703
704 spin_lock_irqsave(&np->lock, flags);
705
706 np->dspcfg_workaround = new_setting;
707
708 spin_unlock_irqrestore(&np->lock, flags);
709
710 return count;
711}
712
659static inline void __iomem *ns_ioaddr(struct net_device *dev) 713static inline void __iomem *ns_ioaddr(struct net_device *dev)
660{ 714{
661 return (void __iomem *) dev->base_addr; 715 return (void __iomem *) dev->base_addr;
@@ -820,6 +874,7 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
820 np->ignore_phy = 1; 874 np->ignore_phy = 1;
821 else 875 else
822 np->ignore_phy = 0; 876 np->ignore_phy = 0;
877 np->dspcfg_workaround = dspcfg_workaround;
823 878
824 /* Initial port: 879 /* Initial port:
825 * - If configured to ignore the PHY set up for external. 880 * - If configured to ignore the PHY set up for external.
@@ -899,6 +954,9 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
899 if (i) 954 if (i)
900 goto err_register_netdev; 955 goto err_register_netdev;
901 956
957 if (NATSEMI_CREATE_FILE(pdev, dspcfg_workaround))
958 goto err_create_file;
959
902 if (netif_msg_drv(np)) { 960 if (netif_msg_drv(np)) {
903 printk(KERN_INFO "natsemi %s: %s at %#08lx (%s), ", 961 printk(KERN_INFO "natsemi %s: %s at %#08lx (%s), ",
904 dev->name, natsemi_pci_info[chip_idx].name, iostart, 962 dev->name, natsemi_pci_info[chip_idx].name, iostart,
@@ -915,6 +973,9 @@ static int __devinit natsemi_probe1 (struct pci_dev *pdev,
915 } 973 }
916 return 0; 974 return 0;
917 975
976 err_create_file:
977 unregister_netdev(dev);
978
918 err_register_netdev: 979 err_register_netdev:
919 iounmap(ioaddr); 980 iounmap(ioaddr);
920 981
@@ -1727,7 +1788,8 @@ static void init_registers(struct net_device *dev)
1727 * It seems that a reference set for this chip went out with incorrect info, 1788 * It seems that a reference set for this chip went out with incorrect info,
1728 * and there exist boards that aren't quite right. An unexpected voltage 1789 * and there exist boards that aren't quite right. An unexpected voltage
1729 * drop can cause the PHY to get itself in a weird state (basically reset). 1790 * drop can cause the PHY to get itself in a weird state (basically reset).
1730 * NOTE: this only seems to affect revC chips. 1791 * NOTE: this only seems to affect revC chips. The user can disable
1792 * this check via dspcfg_workaround sysfs option.
1731 * 3) check of death of the RX path due to OOM 1793 * 3) check of death of the RX path due to OOM
1732 */ 1794 */
1733static void netdev_timer(unsigned long data) 1795static void netdev_timer(unsigned long data)
@@ -1753,10 +1815,10 @@ static void netdev_timer(unsigned long data)
1753 writew(1, ioaddr+PGSEL); 1815 writew(1, ioaddr+PGSEL);
1754 dspcfg = readw(ioaddr+DSPCFG); 1816 dspcfg = readw(ioaddr+DSPCFG);
1755 writew(0, ioaddr+PGSEL); 1817 writew(0, ioaddr+PGSEL);
1756 if (dspcfg != np->dspcfg) { 1818 if (np->dspcfg_workaround && dspcfg != np->dspcfg) {
1757 if (!netif_queue_stopped(dev)) { 1819 if (!netif_queue_stopped(dev)) {
1758 spin_unlock_irq(&np->lock); 1820 spin_unlock_irq(&np->lock);
1759 if (netif_msg_hw(np)) 1821 if (netif_msg_drv(np))
1760 printk(KERN_NOTICE "%s: possible phy reset: " 1822 printk(KERN_NOTICE "%s: possible phy reset: "
1761 "re-initializing\n", dev->name); 1823 "re-initializing\n", dev->name);
1762 disable_irq(dev->irq); 1824 disable_irq(dev->irq);
@@ -3157,6 +3219,7 @@ static void __devexit natsemi_remove1 (struct pci_dev *pdev)
3157 struct net_device *dev = pci_get_drvdata(pdev); 3219 struct net_device *dev = pci_get_drvdata(pdev);
3158 void __iomem * ioaddr = ns_ioaddr(dev); 3220 void __iomem * ioaddr = ns_ioaddr(dev);
3159 3221
3222 NATSEMI_REMOVE_FILE(pdev, dspcfg_workaround);
3160 unregister_netdev (dev); 3223 unregister_netdev (dev);
3161 pci_release_regions (pdev); 3224 pci_release_regions (pdev);
3162 iounmap(ioaddr); 3225 iounmap(ioaddr);
diff --git a/drivers/net/ne.c b/drivers/net/ne.c
index a5c4199e2754..c9f74bf5f491 100644
--- a/drivers/net/ne.c
+++ b/drivers/net/ne.c
@@ -51,14 +51,11 @@ static const char version2[] =
51#include <linux/netdevice.h> 51#include <linux/netdevice.h>
52#include <linux/etherdevice.h> 52#include <linux/etherdevice.h>
53#include <linux/jiffies.h> 53#include <linux/jiffies.h>
54#include <linux/platform_device.h>
54 55
55#include <asm/system.h> 56#include <asm/system.h>
56#include <asm/io.h> 57#include <asm/io.h>
57 58
58#if defined(CONFIG_TOSHIBA_RBTX4927) || defined(CONFIG_TOSHIBA_RBTX4938)
59#include <asm/tx4938/rbtx4938.h>
60#endif
61
62#include "8390.h" 59#include "8390.h"
63 60
64#define DRV_NAME "ne" 61#define DRV_NAME "ne"
@@ -77,8 +74,13 @@ static const char version2[] =
77/* Do we have a non std. amount of memory? (in units of 256 byte pages) */ 74/* Do we have a non std. amount of memory? (in units of 256 byte pages) */
78/* #define PACKETBUF_MEMSIZE 0x40 */ 75/* #define PACKETBUF_MEMSIZE 0x40 */
79 76
77#if !defined(MODULE) && (defined(CONFIG_ISA) || defined(CONFIG_M32R))
78/* Do we need a portlist for the ISA auto-probe ? */
79#define NEEDS_PORTLIST
80#endif
81
80/* A zero-terminated list of I/O addresses to be probed at boot. */ 82/* A zero-terminated list of I/O addresses to be probed at boot. */
81#ifndef MODULE 83#ifdef NEEDS_PORTLIST
82static unsigned int netcard_portlist[] __initdata = { 84static unsigned int netcard_portlist[] __initdata = {
83 0x300, 0x280, 0x320, 0x340, 0x360, 0x380, 0 85 0x300, 0x280, 0x320, 0x340, 0x360, 0x380, 0
84}; 86};
@@ -146,7 +148,7 @@ bad_clone_list[] __initdata = {
146# define DCR_VAL 0x49 148# define DCR_VAL 0x49
147#endif 149#endif
148 150
149static int ne_probe1(struct net_device *dev, int ioaddr); 151static int ne_probe1(struct net_device *dev, unsigned long ioaddr);
150static int ne_probe_isapnp(struct net_device *dev); 152static int ne_probe_isapnp(struct net_device *dev);
151 153
152static int ne_open(struct net_device *dev); 154static int ne_open(struct net_device *dev);
@@ -184,8 +186,8 @@ static void ne_block_output(struct net_device *dev, const int count,
184 186
185static int __init do_ne_probe(struct net_device *dev) 187static int __init do_ne_probe(struct net_device *dev)
186{ 188{
187 unsigned int base_addr = dev->base_addr; 189 unsigned long base_addr = dev->base_addr;
188#ifndef MODULE 190#ifdef NEEDS_PORTLIST
189 int orig_irq = dev->irq; 191 int orig_irq = dev->irq;
190#endif 192#endif
191 193
@@ -201,7 +203,7 @@ static int __init do_ne_probe(struct net_device *dev)
201 if (isapnp_present() && (ne_probe_isapnp(dev) == 0)) 203 if (isapnp_present() && (ne_probe_isapnp(dev) == 0))
202 return 0; 204 return 0;
203 205
204#ifndef MODULE 206#ifdef NEEDS_PORTLIST
205 /* Last resort. The semi-risky ISA auto-probe. */ 207 /* Last resort. The semi-risky ISA auto-probe. */
206 for (base_addr = 0; netcard_portlist[base_addr] != 0; base_addr++) { 208 for (base_addr = 0; netcard_portlist[base_addr] != 0; base_addr++) {
207 int ioaddr = netcard_portlist[base_addr]; 209 int ioaddr = netcard_portlist[base_addr];
@@ -226,10 +228,6 @@ struct net_device * __init ne_probe(int unit)
226 sprintf(dev->name, "eth%d", unit); 228 sprintf(dev->name, "eth%d", unit);
227 netdev_boot_setup_check(dev); 229 netdev_boot_setup_check(dev);
228 230
229#ifdef CONFIG_TOSHIBA_RBTX4938
230 dev->base_addr = RBTX4938_RTL_8019_BASE;
231 dev->irq = RBTX4938_RTL_8019_IRQ;
232#endif
233 err = do_ne_probe(dev); 231 err = do_ne_probe(dev);
234 if (err) 232 if (err)
235 goto out; 233 goto out;
@@ -285,7 +283,7 @@ static int __init ne_probe_isapnp(struct net_device *dev)
285 return -ENODEV; 283 return -ENODEV;
286} 284}
287 285
288static int __init ne_probe1(struct net_device *dev, int ioaddr) 286static int __init ne_probe1(struct net_device *dev, unsigned long ioaddr)
289{ 287{
290 int i; 288 int i;
291 unsigned char SA_prom[32]; 289 unsigned char SA_prom[32];
@@ -324,7 +322,7 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
324 if (ei_debug && version_printed++ == 0) 322 if (ei_debug && version_printed++ == 0)
325 printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2); 323 printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2);
326 324
327 printk(KERN_INFO "NE*000 ethercard probe at %#3x:", ioaddr); 325 printk(KERN_INFO "NE*000 ethercard probe at %#3lx:", ioaddr);
328 326
329 /* A user with a poor card that fails to ack the reset, or that 327 /* A user with a poor card that fails to ack the reset, or that
330 does not have a valid 0x57,0x57 signature can still use this 328 does not have a valid 0x57,0x57 signature can still use this
@@ -516,8 +514,7 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
516 } 514 }
517#endif 515#endif
518 516
519 printk("\n%s: %s found at %#x, using IRQ %d.\n", 517 printk("\n");
520 dev->name, name, ioaddr, dev->irq);
521 518
522 ei_status.name = name; 519 ei_status.name = name;
523 ei_status.tx_start_page = start_page; 520 ei_status.tx_start_page = start_page;
@@ -547,6 +544,8 @@ static int __init ne_probe1(struct net_device *dev, int ioaddr)
547 ret = register_netdev(dev); 544 ret = register_netdev(dev);
548 if (ret) 545 if (ret)
549 goto out_irq; 546 goto out_irq;
547 printk(KERN_INFO "%s: %s found at %#lx, using IRQ %d.\n",
548 dev->name, name, ioaddr, dev->irq);
550 return 0; 549 return 0;
551 550
552out_irq: 551out_irq:
@@ -807,6 +806,87 @@ retry:
807 return; 806 return;
808} 807}
809 808
809static int __init ne_drv_probe(struct platform_device *pdev)
810{
811 struct net_device *dev;
812 struct resource *res;
813 int err, irq;
814
815 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
816 irq = platform_get_irq(pdev, 0);
817 if (!res || irq < 0)
818 return -ENODEV;
819
820 dev = alloc_ei_netdev();
821 if (!dev)
822 return -ENOMEM;
823 dev->irq = irq;
824 dev->base_addr = res->start;
825 err = do_ne_probe(dev);
826 if (err) {
827 free_netdev(dev);
828 return err;
829 }
830 platform_set_drvdata(pdev, dev);
831 return 0;
832}
833
834static int __exit ne_drv_remove(struct platform_device *pdev)
835{
836 struct net_device *dev = platform_get_drvdata(pdev);
837
838 unregister_netdev(dev);
839 free_irq(dev->irq, dev);
840 release_region(dev->base_addr, NE_IO_EXTENT);
841 free_netdev(dev);
842 return 0;
843}
844
845#ifdef CONFIG_PM
846static int ne_drv_suspend(struct platform_device *pdev, pm_message_t state)
847{
848 struct net_device *dev = platform_get_drvdata(pdev);
849
850 if (netif_running(dev))
851 netif_device_detach(dev);
852 return 0;
853}
854
855static int ne_drv_resume(struct platform_device *pdev)
856{
857 struct net_device *dev = platform_get_drvdata(pdev);
858
859 if (netif_running(dev)) {
860 ne_reset_8390(dev);
861 NS8390_init(dev, 1);
862 netif_device_attach(dev);
863 }
864 return 0;
865}
866#else
867#define ne_drv_suspend NULL
868#define ne_drv_resume NULL
869#endif
870
871static struct platform_driver ne_driver = {
872 .remove = __exit_p(ne_drv_remove),
873 .suspend = ne_drv_suspend,
874 .resume = ne_drv_resume,
875 .driver = {
876 .name = DRV_NAME,
877 .owner = THIS_MODULE,
878 },
879};
880
881static int __init ne_init(void)
882{
883 return platform_driver_probe(&ne_driver, ne_drv_probe);
884}
885
886static void __exit ne_exit(void)
887{
888 platform_driver_unregister(&ne_driver);
889}
810 890
811#ifdef MODULE 891#ifdef MODULE
812#define MAX_NE_CARDS 4 /* Max number of NE cards per module */ 892#define MAX_NE_CARDS 4 /* Max number of NE cards per module */
@@ -832,6 +912,7 @@ ISA device autoprobes on a running machine are not recommended anyway. */
832int __init init_module(void) 912int __init init_module(void)
833{ 913{
834 int this_dev, found = 0; 914 int this_dev, found = 0;
915 int plat_found = !ne_init();
835 916
836 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { 917 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
837 struct net_device *dev = alloc_ei_netdev(); 918 struct net_device *dev = alloc_ei_netdev();
@@ -845,7 +926,7 @@ int __init init_module(void)
845 continue; 926 continue;
846 } 927 }
847 free_netdev(dev); 928 free_netdev(dev);
848 if (found) 929 if (found || plat_found)
849 break; 930 break;
850 if (io[this_dev] != 0) 931 if (io[this_dev] != 0)
851 printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", io[this_dev]); 932 printk(KERN_WARNING "ne.c: No NE*000 card found at i/o = %#x\n", io[this_dev]);
@@ -853,7 +934,7 @@ int __init init_module(void)
853 printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n"); 934 printk(KERN_NOTICE "ne.c: You must supply \"io=0xNNN\" value(s) for ISA cards.\n");
854 return -ENXIO; 935 return -ENXIO;
855 } 936 }
856 if (found) 937 if (found || plat_found)
857 return 0; 938 return 0;
858 return -ENODEV; 939 return -ENODEV;
859} 940}
@@ -871,6 +952,7 @@ void __exit cleanup_module(void)
871{ 952{
872 int this_dev; 953 int this_dev;
873 954
955 ne_exit();
874 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) { 956 for (this_dev = 0; this_dev < MAX_NE_CARDS; this_dev++) {
875 struct net_device *dev = dev_ne[this_dev]; 957 struct net_device *dev = dev_ne[this_dev];
876 if (dev) { 958 if (dev) {
@@ -880,4 +962,7 @@ void __exit cleanup_module(void)
880 } 962 }
881 } 963 }
882} 964}
965#else /* MODULE */
966module_init(ne_init);
967module_exit(ne_exit);
883#endif /* MODULE */ 968#endif /* MODULE */
diff --git a/drivers/net/ne2k-pci.c b/drivers/net/ne2k-pci.c
index 589785d1e762..995c0a5d4066 100644
--- a/drivers/net/ne2k-pci.c
+++ b/drivers/net/ne2k-pci.c
@@ -63,8 +63,7 @@ static int options[MAX_UNITS];
63 63
64/* These identify the driver base version and may not be removed. */ 64/* These identify the driver base version and may not be removed. */
65static char version[] __devinitdata = 65static char version[] __devinitdata =
66KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " D. Becker/P. Gortmaker\n" 66KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " D. Becker/P. Gortmaker\n";
67KERN_INFO " http://www.scyld.com/network/ne2k-pci.html\n";
68 67
69#if defined(__powerpc__) 68#if defined(__powerpc__)
70#define inl_le(addr) le32_to_cpu(inl(addr)) 69#define inl_le(addr) le32_to_cpu(inl(addr))
diff --git a/drivers/net/netxen/netxen_nic_init.c b/drivers/net/netxen/netxen_nic_init.c
index cf0e96adfe44..a36892457761 100644
--- a/drivers/net/netxen/netxen_nic_init.c
+++ b/drivers/net/netxen/netxen_nic_init.c
@@ -1216,7 +1216,7 @@ u32 netxen_process_rcv_ring(struct netxen_adapter *adapter, int ctxid, int max)
1216 /* Window = 1 */ 1216 /* Window = 1 */
1217 writel(consumer, 1217 writel(consumer,
1218 NETXEN_CRB_NORMALIZE(adapter, 1218 NETXEN_CRB_NORMALIZE(adapter,
1219 recv_crb_registers[ctxid]. 1219 recv_crb_registers[adapter->portnum].
1220 crb_rcv_status_consumer)); 1220 crb_rcv_status_consumer));
1221 } 1221 }
1222 1222
diff --git a/drivers/net/netxen/netxen_nic_main.c b/drivers/net/netxen/netxen_nic_main.c
index 4e32bb678ea9..2c5c6d20e6e9 100644
--- a/drivers/net/netxen/netxen_nic_main.c
+++ b/drivers/net/netxen/netxen_nic_main.c
@@ -735,7 +735,7 @@ static int netxen_nic_open(struct net_device *netdev)
735 } 735 }
736 adapter->irq = adapter->ahw.pdev->irq; 736 adapter->irq = adapter->ahw.pdev->irq;
737 err = request_irq(adapter->ahw.pdev->irq, netxen_intr, 737 err = request_irq(adapter->ahw.pdev->irq, netxen_intr,
738 SA_SHIRQ | SA_SAMPLE_RANDOM, netdev->name, 738 IRQF_SHARED|IRQF_SAMPLE_RANDOM, netdev->name,
739 adapter); 739 adapter);
740 if (err) { 740 if (err) {
741 printk(KERN_ERR "request_irq failed with: %d\n", err); 741 printk(KERN_ERR "request_irq failed with: %d\n", err);
diff --git a/drivers/net/ns83820.c b/drivers/net/ns83820.c
index 6a32338623f1..3439f8c649f9 100644
--- a/drivers/net/ns83820.c
+++ b/drivers/net/ns83820.c
@@ -104,7 +104,6 @@
104#include <linux/netdevice.h> 104#include <linux/netdevice.h>
105#include <linux/etherdevice.h> 105#include <linux/etherdevice.h>
106#include <linux/delay.h> 106#include <linux/delay.h>
107#include <linux/smp_lock.h>
108#include <linux/workqueue.h> 107#include <linux/workqueue.h>
109#include <linux/init.h> 108#include <linux/init.h>
110#include <linux/ip.h> /* for iph */ 109#include <linux/ip.h> /* for iph */
diff --git a/drivers/net/pasemi_mac.c b/drivers/net/pasemi_mac.c
index 76fe9dd8e841..8d38425e46c3 100644
--- a/drivers/net/pasemi_mac.c
+++ b/drivers/net/pasemi_mac.c
@@ -33,6 +33,8 @@
33#include <linux/tcp.h> 33#include <linux/tcp.h>
34#include <net/checksum.h> 34#include <net/checksum.h>
35 35
36#include <asm/irq.h>
37
36#include "pasemi_mac.h" 38#include "pasemi_mac.h"
37 39
38 40
@@ -51,6 +53,16 @@
51#define RX_RING_SIZE 512 53#define RX_RING_SIZE 512
52#define TX_RING_SIZE 512 54#define TX_RING_SIZE 512
53 55
56#define DEFAULT_MSG_ENABLE \
57 (NETIF_MSG_DRV | \
58 NETIF_MSG_PROBE | \
59 NETIF_MSG_LINK | \
60 NETIF_MSG_TIMER | \
61 NETIF_MSG_IFDOWN | \
62 NETIF_MSG_IFUP | \
63 NETIF_MSG_RX_ERR | \
64 NETIF_MSG_TX_ERR)
65
54#define TX_DESC(mac, num) ((mac)->tx->desc[(num) & (TX_RING_SIZE-1)]) 66#define TX_DESC(mac, num) ((mac)->tx->desc[(num) & (TX_RING_SIZE-1)])
55#define TX_DESC_INFO(mac, num) ((mac)->tx->desc_info[(num) & (TX_RING_SIZE-1)]) 67#define TX_DESC_INFO(mac, num) ((mac)->tx->desc_info[(num) & (TX_RING_SIZE-1)])
56#define RX_DESC(mac, num) ((mac)->rx->desc[(num) & (RX_RING_SIZE-1)]) 68#define RX_DESC(mac, num) ((mac)->rx->desc[(num) & (RX_RING_SIZE-1)])
@@ -59,11 +71,13 @@
59 71
60#define BUF_SIZE 1646 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */ 72#define BUF_SIZE 1646 /* 1500 MTU + ETH_HLEN + VLAN_HLEN + 2 64B cachelines */
61 73
62/* XXXOJN these should come out of the device tree some day */ 74MODULE_LICENSE("GPL");
63#define PAS_DMA_CAP_BASE 0xe00d0040 75MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
64#define PAS_DMA_CAP_SIZE 0x100 76MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
65#define PAS_DMA_COM_BASE 0xe00d0100 77
66#define PAS_DMA_COM_SIZE 0x100 78static int debug = -1; /* -1 == use DEFAULT_MSG_ENABLE as value */
79module_param(debug, int, 0);
80MODULE_PARM_DESC(debug, "PA Semi MAC bitmapped debugging message enable value");
67 81
68static struct pasdma_status *dma_status; 82static struct pasdma_status *dma_status;
69 83
@@ -71,6 +85,7 @@ static int pasemi_get_mac_addr(struct pasemi_mac *mac)
71{ 85{
72 struct pci_dev *pdev = mac->pdev; 86 struct pci_dev *pdev = mac->pdev;
73 struct device_node *dn = pci_device_to_OF_node(pdev); 87 struct device_node *dn = pci_device_to_OF_node(pdev);
88 int len;
74 const u8 *maddr; 89 const u8 *maddr;
75 u8 addr[6]; 90 u8 addr[6];
76 91
@@ -80,13 +95,27 @@ static int pasemi_get_mac_addr(struct pasemi_mac *mac)
80 return -ENOENT; 95 return -ENOENT;
81 } 96 }
82 97
83 maddr = get_property(dn, "mac-address", NULL); 98 maddr = of_get_property(dn, "local-mac-address", &len);
99
100 if (maddr && len == 6) {
101 memcpy(mac->mac_addr, maddr, 6);
102 return 0;
103 }
104
105 /* Some old versions of firmware mistakenly uses mac-address
106 * (and as a string) instead of a byte array in local-mac-address.
107 */
108
109 if (maddr == NULL)
110 maddr = of_get_property(dn, "mac-address", NULL);
111
84 if (maddr == NULL) { 112 if (maddr == NULL) {
85 dev_warn(&pdev->dev, 113 dev_warn(&pdev->dev,
86 "no mac address in device tree, not configuring\n"); 114 "no mac address in device tree, not configuring\n");
87 return -ENOENT; 115 return -ENOENT;
88 } 116 }
89 117
118
90 if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0], 119 if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0],
91 &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) { 120 &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) {
92 dev_warn(&pdev->dev, 121 dev_warn(&pdev->dev,
@@ -94,7 +123,8 @@ static int pasemi_get_mac_addr(struct pasemi_mac *mac)
94 return -EINVAL; 123 return -EINVAL;
95 } 124 }
96 125
97 memcpy(mac->mac_addr, addr, sizeof(addr)); 126 memcpy(mac->mac_addr, addr, 6);
127
98 return 0; 128 return 0;
99} 129}
100 130
@@ -277,8 +307,8 @@ static void pasemi_mac_free_rx_resources(struct net_device *dev)
277 for (i = 0; i < RX_RING_SIZE; i++) { 307 for (i = 0; i < RX_RING_SIZE; i++) {
278 info = &RX_DESC_INFO(mac, i); 308 info = &RX_DESC_INFO(mac, i);
279 dp = &RX_DESC(mac, i); 309 dp = &RX_DESC(mac, i);
280 if (info->dma) { 310 if (info->skb) {
281 if (info->skb) { 311 if (info->dma) {
282 pci_unmap_single(mac->dma_pdev, 312 pci_unmap_single(mac->dma_pdev,
283 info->dma, 313 info->dma,
284 info->skb->len, 314 info->skb->len,
@@ -309,82 +339,115 @@ static void pasemi_mac_replenish_rx_ring(struct net_device *dev)
309 struct pasemi_mac *mac = netdev_priv(dev); 339 struct pasemi_mac *mac = netdev_priv(dev);
310 unsigned int i; 340 unsigned int i;
311 int start = mac->rx->next_to_fill; 341 int start = mac->rx->next_to_fill;
312 unsigned int count; 342 unsigned int limit, count;
313 343
314 count = (mac->rx->next_to_clean + RX_RING_SIZE - 344 limit = (mac->rx->next_to_clean + RX_RING_SIZE -
315 mac->rx->next_to_fill) & (RX_RING_SIZE - 1); 345 mac->rx->next_to_fill) & (RX_RING_SIZE - 1);
316 346
317 /* Check to see if we're doing first-time setup */ 347 /* Check to see if we're doing first-time setup */
318 if (unlikely(mac->rx->next_to_clean == 0 && mac->rx->next_to_fill == 0)) 348 if (unlikely(mac->rx->next_to_clean == 0 && mac->rx->next_to_fill == 0))
319 count = RX_RING_SIZE; 349 limit = RX_RING_SIZE;
320 350
321 if (count <= 0) 351 if (limit <= 0)
322 return; 352 return;
323 353
324 for (i = start; i < start + count; i++) { 354 i = start;
355 for (count = limit; count; count--) {
325 struct pasemi_mac_buffer *info = &RX_DESC_INFO(mac, i); 356 struct pasemi_mac_buffer *info = &RX_DESC_INFO(mac, i);
326 u64 *buff = &RX_BUFF(mac, i); 357 u64 *buff = &RX_BUFF(mac, i);
327 struct sk_buff *skb; 358 struct sk_buff *skb;
328 dma_addr_t dma; 359 dma_addr_t dma;
329 360
330 skb = dev_alloc_skb(BUF_SIZE); 361 /* skb might still be in there for recycle on short receives */
362 if (info->skb)
363 skb = info->skb;
364 else
365 skb = dev_alloc_skb(BUF_SIZE);
331 366
332 if (!skb) { 367 if (unlikely(!skb))
333 count = i - start;
334 break; 368 break;
335 }
336 369
337 dma = pci_map_single(mac->dma_pdev, skb->data, skb->len, 370 dma = pci_map_single(mac->dma_pdev, skb->data, skb->len,
338 PCI_DMA_FROMDEVICE); 371 PCI_DMA_FROMDEVICE);
339 372
340 if (dma_mapping_error(dma)) { 373 if (unlikely(dma_mapping_error(dma))) {
341 dev_kfree_skb_irq(info->skb); 374 dev_kfree_skb_irq(info->skb);
342 count = i - start;
343 break; 375 break;
344 } 376 }
345 377
346 info->skb = skb; 378 info->skb = skb;
347 info->dma = dma; 379 info->dma = dma;
348 *buff = XCT_RXB_LEN(BUF_SIZE) | XCT_RXB_ADDR(dma); 380 *buff = XCT_RXB_LEN(BUF_SIZE) | XCT_RXB_ADDR(dma);
381 i++;
349 } 382 }
350 383
351 wmb(); 384 wmb();
352 385
353 pci_write_config_dword(mac->dma_pdev, 386 pci_write_config_dword(mac->dma_pdev,
354 PAS_DMA_RXCHAN_INCR(mac->dma_rxch), 387 PAS_DMA_RXCHAN_INCR(mac->dma_rxch),
355 count); 388 limit - count);
356 pci_write_config_dword(mac->dma_pdev, 389 pci_write_config_dword(mac->dma_pdev,
357 PAS_DMA_RXINT_INCR(mac->dma_if), 390 PAS_DMA_RXINT_INCR(mac->dma_if),
358 count); 391 limit - count);
392
393 mac->rx->next_to_fill += limit - count;
394}
359 395
360 mac->rx->next_to_fill += count; 396static void pasemi_mac_restart_rx_intr(struct pasemi_mac *mac)
397{
398 unsigned int reg, pcnt;
399 /* Re-enable packet count interrupts: finally
400 * ack the packet count interrupt we got in rx_intr.
401 */
402
403 pcnt = *mac->rx_status & PAS_STATUS_PCNT_M;
404
405 reg = PAS_IOB_DMA_RXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_RXCH_RESET_PINTC;
406
407 pci_write_config_dword(mac->iob_pdev,
408 PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch),
409 reg);
410}
411
412static void pasemi_mac_restart_tx_intr(struct pasemi_mac *mac)
413{
414 unsigned int reg, pcnt;
415
416 /* Re-enable packet count interrupts */
417 pcnt = *mac->tx_status & PAS_STATUS_PCNT_M;
418
419 reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
420
421 pci_write_config_dword(mac->iob_pdev,
422 PAS_IOB_DMA_TXCH_RESET(mac->dma_txch), reg);
361} 423}
362 424
425
363static int pasemi_mac_clean_rx(struct pasemi_mac *mac, int limit) 426static int pasemi_mac_clean_rx(struct pasemi_mac *mac, int limit)
364{ 427{
365 unsigned int i; 428 unsigned int n;
366 int start, count; 429 int count;
430 struct pas_dma_xct_descr *dp;
431 struct pasemi_mac_buffer *info;
432 struct sk_buff *skb;
433 unsigned int i, len;
434 u64 macrx;
435 dma_addr_t dma;
367 436
368 spin_lock(&mac->rx->lock); 437 spin_lock(&mac->rx->lock);
369 438
370 start = mac->rx->next_to_clean; 439 n = mac->rx->next_to_clean;
371 count = 0;
372 440
373 for (i = start; i < (start + RX_RING_SIZE) && count < limit; i++) { 441 for (count = limit; count; count--) {
374 struct pas_dma_xct_descr *dp;
375 struct pasemi_mac_buffer *info;
376 struct sk_buff *skb;
377 unsigned int j, len;
378 dma_addr_t dma;
379 442
380 rmb(); 443 rmb();
381 444
382 dp = &RX_DESC(mac, i); 445 dp = &RX_DESC(mac, n);
446 macrx = dp->macrx;
383 447
384 if (!(dp->macrx & XCT_MACRX_O)) 448 if (!(macrx & XCT_MACRX_O))
385 break; 449 break;
386 450
387 count++;
388 451
389 info = NULL; 452 info = NULL;
390 453
@@ -396,29 +459,42 @@ static int pasemi_mac_clean_rx(struct pasemi_mac *mac, int limit)
396 */ 459 */
397 460
398 dma = (dp->ptr & XCT_PTR_ADDR_M); 461 dma = (dp->ptr & XCT_PTR_ADDR_M);
399 for (j = start; j < (start + RX_RING_SIZE); j++) { 462 for (i = n; i < (n + RX_RING_SIZE); i++) {
400 info = &RX_DESC_INFO(mac, j); 463 info = &RX_DESC_INFO(mac, i);
401 if (info->dma == dma) 464 if (info->dma == dma)
402 break; 465 break;
403 } 466 }
404 467
405 BUG_ON(!info); 468 skb = info->skb;
406 BUG_ON(info->dma != dma); 469 info->dma = 0;
407 470
408 pci_unmap_single(mac->dma_pdev, info->dma, info->skb->len, 471 pci_unmap_single(mac->dma_pdev, dma, skb->len,
409 PCI_DMA_FROMDEVICE); 472 PCI_DMA_FROMDEVICE);
410 473
411 skb = info->skb; 474 len = (macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S;
412 475
413 len = (dp->macrx & XCT_MACRX_LLEN_M) >> XCT_MACRX_LLEN_S; 476 if (len < 256) {
477 struct sk_buff *new_skb =
478 netdev_alloc_skb(mac->netdev, len + NET_IP_ALIGN);
479 if (new_skb) {
480 skb_reserve(new_skb, NET_IP_ALIGN);
481 memcpy(new_skb->data - NET_IP_ALIGN,
482 skb->data - NET_IP_ALIGN,
483 len + NET_IP_ALIGN);
484 /* save the skb in buffer_info as good */
485 skb = new_skb;
486 }
487 /* else just continue with the old one */
488 } else
489 info->skb = NULL;
414 490
415 skb_put(skb, len); 491 skb_put(skb, len);
416 492
417 skb->protocol = eth_type_trans(skb, mac->netdev); 493 skb->protocol = eth_type_trans(skb, mac->netdev);
418 494
419 if ((dp->macrx & XCT_MACRX_HTY_M) == XCT_MACRX_HTY_IPV4_OK) { 495 if ((macrx & XCT_MACRX_HTY_M) == XCT_MACRX_HTY_IPV4_OK) {
420 skb->ip_summed = CHECKSUM_COMPLETE; 496 skb->ip_summed = CHECKSUM_COMPLETE;
421 skb->csum = (dp->macrx & XCT_MACRX_CSUM_M) >> 497 skb->csum = (macrx & XCT_MACRX_CSUM_M) >>
422 XCT_MACRX_CSUM_S; 498 XCT_MACRX_CSUM_S;
423 } else 499 } else
424 skb->ip_summed = CHECKSUM_NONE; 500 skb->ip_summed = CHECKSUM_NONE;
@@ -428,13 +504,13 @@ static int pasemi_mac_clean_rx(struct pasemi_mac *mac, int limit)
428 504
429 netif_receive_skb(skb); 505 netif_receive_skb(skb);
430 506
431 info->dma = 0;
432 info->skb = NULL;
433 dp->ptr = 0; 507 dp->ptr = 0;
434 dp->macrx = 0; 508 dp->macrx = 0;
509
510 n++;
435 } 511 }
436 512
437 mac->rx->next_to_clean += count; 513 mac->rx->next_to_clean += limit - count;
438 pasemi_mac_replenish_rx_ring(mac->netdev); 514 pasemi_mac_replenish_rx_ring(mac->netdev);
439 515
440 spin_unlock(&mac->rx->lock); 516 spin_unlock(&mac->rx->lock);
@@ -476,6 +552,8 @@ static int pasemi_mac_clean_tx(struct pasemi_mac *mac)
476 mac->tx->next_to_clean += count; 552 mac->tx->next_to_clean += count;
477 spin_unlock_irqrestore(&mac->tx->lock, flags); 553 spin_unlock_irqrestore(&mac->tx->lock, flags);
478 554
555 netif_wake_queue(mac->netdev);
556
479 return count; 557 return count;
480} 558}
481 559
@@ -486,18 +564,28 @@ static irqreturn_t pasemi_mac_rx_intr(int irq, void *data)
486 struct pasemi_mac *mac = netdev_priv(dev); 564 struct pasemi_mac *mac = netdev_priv(dev);
487 unsigned int reg; 565 unsigned int reg;
488 566
489 if (!(*mac->rx_status & PAS_STATUS_INT)) 567 if (!(*mac->rx_status & PAS_STATUS_CAUSE_M))
490 return IRQ_NONE; 568 return IRQ_NONE;
491 569
492 netif_rx_schedule(dev); 570 if (*mac->rx_status & PAS_STATUS_ERROR)
493 pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_COM_TIMEOUTCFG, 571 printk("rx_status reported error\n");
494 PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0)); 572
573 /* Don't reset packet count so it won't fire again but clear
574 * all others.
575 */
495 576
496 reg = PAS_IOB_DMA_RXCH_RESET_PINTC | PAS_IOB_DMA_RXCH_RESET_SINTC | 577 pci_read_config_dword(mac->dma_pdev, PAS_DMA_RXINT_RCMDSTA(mac->dma_if), &reg);
497 PAS_IOB_DMA_RXCH_RESET_DINTC; 578
579 reg = 0;
580 if (*mac->rx_status & PAS_STATUS_SOFT)
581 reg |= PAS_IOB_DMA_RXCH_RESET_SINTC;
582 if (*mac->rx_status & PAS_STATUS_ERROR)
583 reg |= PAS_IOB_DMA_RXCH_RESET_DINTC;
498 if (*mac->rx_status & PAS_STATUS_TIMER) 584 if (*mac->rx_status & PAS_STATUS_TIMER)
499 reg |= PAS_IOB_DMA_RXCH_RESET_TINTC; 585 reg |= PAS_IOB_DMA_RXCH_RESET_TINTC;
500 586
587 netif_rx_schedule(dev);
588
501 pci_write_config_dword(mac->iob_pdev, 589 pci_write_config_dword(mac->iob_pdev,
502 PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg); 590 PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch), reg);
503 591
@@ -509,32 +597,141 @@ static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
509{ 597{
510 struct net_device *dev = data; 598 struct net_device *dev = data;
511 struct pasemi_mac *mac = netdev_priv(dev); 599 struct pasemi_mac *mac = netdev_priv(dev);
512 unsigned int reg; 600 unsigned int reg, pcnt;
513 int was_full;
514 601
515 was_full = mac->tx->next_to_clean - mac->tx->next_to_use == TX_RING_SIZE; 602 if (!(*mac->tx_status & PAS_STATUS_CAUSE_M))
516
517 if (!(*mac->tx_status & PAS_STATUS_INT))
518 return IRQ_NONE; 603 return IRQ_NONE;
519 604
520 pasemi_mac_clean_tx(mac); 605 pasemi_mac_clean_tx(mac);
521 606
522 reg = PAS_IOB_DMA_TXCH_RESET_PINTC | PAS_IOB_DMA_TXCH_RESET_SINTC; 607 pcnt = *mac->tx_status & PAS_STATUS_PCNT_M;
523 if (*mac->tx_status & PAS_STATUS_TIMER)
524 reg |= PAS_IOB_DMA_TXCH_RESET_TINTC;
525 608
526 pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_TXCH_RESET(mac->dma_txch), 609 reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
527 reg);
528 610
529 if (was_full) 611 if (*mac->tx_status & PAS_STATUS_SOFT)
530 netif_wake_queue(dev); 612 reg |= PAS_IOB_DMA_TXCH_RESET_SINTC;
613 if (*mac->tx_status & PAS_STATUS_ERROR)
614 reg |= PAS_IOB_DMA_TXCH_RESET_DINTC;
615
616 pci_write_config_dword(mac->iob_pdev,
617 PAS_IOB_DMA_TXCH_RESET(mac->dma_txch),
618 reg);
531 619
532 return IRQ_HANDLED; 620 return IRQ_HANDLED;
533} 621}
534 622
623static void pasemi_adjust_link(struct net_device *dev)
624{
625 struct pasemi_mac *mac = netdev_priv(dev);
626 int msg;
627 unsigned int flags;
628 unsigned int new_flags;
629
630 if (!mac->phydev->link) {
631 /* If no link, MAC speed settings don't matter. Just report
632 * link down and return.
633 */
634 if (mac->link && netif_msg_link(mac))
635 printk(KERN_INFO "%s: Link is down.\n", dev->name);
636
637 netif_carrier_off(dev);
638 mac->link = 0;
639
640 return;
641 } else
642 netif_carrier_on(dev);
643
644 pci_read_config_dword(mac->pdev, PAS_MAC_CFG_PCFG, &flags);
645 new_flags = flags & ~(PAS_MAC_CFG_PCFG_HD | PAS_MAC_CFG_PCFG_SPD_M |
646 PAS_MAC_CFG_PCFG_TSR_M);
647
648 if (!mac->phydev->duplex)
649 new_flags |= PAS_MAC_CFG_PCFG_HD;
650
651 switch (mac->phydev->speed) {
652 case 1000:
653 new_flags |= PAS_MAC_CFG_PCFG_SPD_1G |
654 PAS_MAC_CFG_PCFG_TSR_1G;
655 break;
656 case 100:
657 new_flags |= PAS_MAC_CFG_PCFG_SPD_100M |
658 PAS_MAC_CFG_PCFG_TSR_100M;
659 break;
660 case 10:
661 new_flags |= PAS_MAC_CFG_PCFG_SPD_10M |
662 PAS_MAC_CFG_PCFG_TSR_10M;
663 break;
664 default:
665 printk("Unsupported speed %d\n", mac->phydev->speed);
666 }
667
668 /* Print on link or speed/duplex change */
669 msg = mac->link != mac->phydev->link || flags != new_flags;
670
671 mac->duplex = mac->phydev->duplex;
672 mac->speed = mac->phydev->speed;
673 mac->link = mac->phydev->link;
674
675 if (new_flags != flags)
676 pci_write_config_dword(mac->pdev, PAS_MAC_CFG_PCFG, new_flags);
677
678 if (msg && netif_msg_link(mac))
679 printk(KERN_INFO "%s: Link is up at %d Mbps, %s duplex.\n",
680 dev->name, mac->speed, mac->duplex ? "full" : "half");
681}
682
683static int pasemi_mac_phy_init(struct net_device *dev)
684{
685 struct pasemi_mac *mac = netdev_priv(dev);
686 struct device_node *dn, *phy_dn;
687 struct phy_device *phydev;
688 unsigned int phy_id;
689 const phandle *ph;
690 const unsigned int *prop;
691 struct resource r;
692 int ret;
693
694 dn = pci_device_to_OF_node(mac->pdev);
695 ph = of_get_property(dn, "phy-handle", NULL);
696 if (!ph)
697 return -ENODEV;
698 phy_dn = of_find_node_by_phandle(*ph);
699
700 prop = of_get_property(phy_dn, "reg", NULL);
701 ret = of_address_to_resource(phy_dn->parent, 0, &r);
702 if (ret)
703 goto err;
704
705 phy_id = *prop;
706 snprintf(mac->phy_id, BUS_ID_SIZE, PHY_ID_FMT, (int)r.start, phy_id);
707
708 of_node_put(phy_dn);
709
710 mac->link = 0;
711 mac->speed = 0;
712 mac->duplex = -1;
713
714 phydev = phy_connect(dev, mac->phy_id, &pasemi_adjust_link, 0, PHY_INTERFACE_MODE_SGMII);
715
716 if (IS_ERR(phydev)) {
717 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
718 return PTR_ERR(phydev);
719 }
720
721 mac->phydev = phydev;
722
723 return 0;
724
725err:
726 of_node_put(phy_dn);
727 return -ENODEV;
728}
729
730
535static int pasemi_mac_open(struct net_device *dev) 731static int pasemi_mac_open(struct net_device *dev)
536{ 732{
537 struct pasemi_mac *mac = netdev_priv(dev); 733 struct pasemi_mac *mac = netdev_priv(dev);
734 int base_irq;
538 unsigned int flags; 735 unsigned int flags;
539 int ret; 736 int ret;
540 737
@@ -558,10 +755,18 @@ static int pasemi_mac_open(struct net_device *dev)
558 flags |= PAS_MAC_CFG_PCFG_TSR_1G | PAS_MAC_CFG_PCFG_SPD_1G; 755 flags |= PAS_MAC_CFG_PCFG_TSR_1G | PAS_MAC_CFG_PCFG_SPD_1G;
559 756
560 pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_RXCH_CFG(mac->dma_rxch), 757 pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_RXCH_CFG(mac->dma_rxch),
561 PAS_IOB_DMA_RXCH_CFG_CNTTH(30)); 758 PAS_IOB_DMA_RXCH_CFG_CNTTH(1));
759
760 pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_TXCH_CFG(mac->dma_txch),
761 PAS_IOB_DMA_TXCH_CFG_CNTTH(32));
762
763 /* Clear out any residual packet count state from firmware */
764 pasemi_mac_restart_rx_intr(mac);
765 pasemi_mac_restart_tx_intr(mac);
562 766
767 /* 0xffffff is max value, about 16ms */
563 pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_COM_TIMEOUTCFG, 768 pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_COM_TIMEOUTCFG,
564 PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(1000000)); 769 PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(0xffffff));
565 770
566 pci_write_config_dword(mac->pdev, PAS_MAC_CFG_PCFG, flags); 771 pci_write_config_dword(mac->pdev, PAS_MAC_CFG_PCFG, flags);
567 772
@@ -595,31 +800,50 @@ static int pasemi_mac_open(struct net_device *dev)
595 800
596 pasemi_mac_replenish_rx_ring(dev); 801 pasemi_mac_replenish_rx_ring(dev);
597 802
803 ret = pasemi_mac_phy_init(dev);
804 /* Some configs don't have PHYs (XAUI etc), so don't complain about
805 * failed init due to -ENODEV.
806 */
807 if (ret && ret != -ENODEV)
808 dev_warn(&mac->pdev->dev, "phy init failed: %d\n", ret);
809
598 netif_start_queue(dev); 810 netif_start_queue(dev);
599 netif_poll_enable(dev); 811 netif_poll_enable(dev);
600 812
601 ret = request_irq(mac->dma_pdev->irq + mac->dma_txch, 813 /* Interrupts are a bit different for our DMA controller: While
602 &pasemi_mac_tx_intr, IRQF_DISABLED, 814 * it's got one a regular PCI device header, the interrupt there
815 * is really the base of the range it's using. Each tx and rx
816 * channel has it's own interrupt source.
817 */
818
819 base_irq = virq_to_hw(mac->dma_pdev->irq);
820
821 mac->tx_irq = irq_create_mapping(NULL, base_irq + mac->dma_txch);
822 mac->rx_irq = irq_create_mapping(NULL, base_irq + 20 + mac->dma_txch);
823
824 ret = request_irq(mac->tx_irq, &pasemi_mac_tx_intr, IRQF_DISABLED,
603 mac->tx->irq_name, dev); 825 mac->tx->irq_name, dev);
604 if (ret) { 826 if (ret) {
605 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n", 827 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
606 mac->dma_pdev->irq + mac->dma_txch, ret); 828 base_irq + mac->dma_txch, ret);
607 goto out_tx_int; 829 goto out_tx_int;
608 } 830 }
609 831
610 ret = request_irq(mac->dma_pdev->irq + 20 + mac->dma_rxch, 832 ret = request_irq(mac->rx_irq, &pasemi_mac_rx_intr, IRQF_DISABLED,
611 &pasemi_mac_rx_intr, IRQF_DISABLED,
612 mac->rx->irq_name, dev); 833 mac->rx->irq_name, dev);
613 if (ret) { 834 if (ret) {
614 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n", 835 dev_err(&mac->pdev->dev, "request_irq of irq %d failed: %d\n",
615 mac->dma_pdev->irq + 20 + mac->dma_rxch, ret); 836 base_irq + 20 + mac->dma_rxch, ret);
616 goto out_rx_int; 837 goto out_rx_int;
617 } 838 }
618 839
840 if (mac->phydev)
841 phy_start(mac->phydev);
842
619 return 0; 843 return 0;
620 844
621out_rx_int: 845out_rx_int:
622 free_irq(mac->dma_pdev->irq + mac->dma_txch, dev); 846 free_irq(mac->tx_irq, dev);
623out_tx_int: 847out_tx_int:
624 netif_poll_disable(dev); 848 netif_poll_disable(dev);
625 netif_stop_queue(dev); 849 netif_stop_queue(dev);
@@ -639,6 +863,11 @@ static int pasemi_mac_close(struct net_device *dev)
639 unsigned int stat; 863 unsigned int stat;
640 int retries; 864 int retries;
641 865
866 if (mac->phydev) {
867 phy_stop(mac->phydev);
868 phy_disconnect(mac->phydev);
869 }
870
642 netif_stop_queue(dev); 871 netif_stop_queue(dev);
643 872
644 /* Clean out any pending buffers */ 873 /* Clean out any pending buffers */
@@ -660,40 +889,37 @@ static int pasemi_mac_close(struct net_device *dev)
660 pci_read_config_dword(mac->dma_pdev, 889 pci_read_config_dword(mac->dma_pdev,
661 PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch), 890 PAS_DMA_TXCHAN_TCMDSTA(mac->dma_txch),
662 &stat); 891 &stat);
663 if (stat & PAS_DMA_TXCHAN_TCMDSTA_ACT) 892 if (!(stat & PAS_DMA_TXCHAN_TCMDSTA_ACT))
664 break; 893 break;
665 cond_resched(); 894 cond_resched();
666 } 895 }
667 896
668 if (!(stat & PAS_DMA_TXCHAN_TCMDSTA_ACT)) { 897 if (stat & PAS_DMA_TXCHAN_TCMDSTA_ACT)
669 dev_err(&mac->dma_pdev->dev, "Failed to stop tx channel\n"); 898 dev_err(&mac->dma_pdev->dev, "Failed to stop tx channel\n");
670 }
671 899
672 for (retries = 0; retries < MAX_RETRIES; retries++) { 900 for (retries = 0; retries < MAX_RETRIES; retries++) {
673 pci_read_config_dword(mac->dma_pdev, 901 pci_read_config_dword(mac->dma_pdev,
674 PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch), 902 PAS_DMA_RXCHAN_CCMDSTA(mac->dma_rxch),
675 &stat); 903 &stat);
676 if (stat & PAS_DMA_RXCHAN_CCMDSTA_ACT) 904 if (!(stat & PAS_DMA_RXCHAN_CCMDSTA_ACT))
677 break; 905 break;
678 cond_resched(); 906 cond_resched();
679 } 907 }
680 908
681 if (!(stat & PAS_DMA_RXCHAN_CCMDSTA_ACT)) { 909 if (stat & PAS_DMA_RXCHAN_CCMDSTA_ACT)
682 dev_err(&mac->dma_pdev->dev, "Failed to stop rx channel\n"); 910 dev_err(&mac->dma_pdev->dev, "Failed to stop rx channel\n");
683 }
684 911
685 for (retries = 0; retries < MAX_RETRIES; retries++) { 912 for (retries = 0; retries < MAX_RETRIES; retries++) {
686 pci_read_config_dword(mac->dma_pdev, 913 pci_read_config_dword(mac->dma_pdev,
687 PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 914 PAS_DMA_RXINT_RCMDSTA(mac->dma_if),
688 &stat); 915 &stat);
689 if (stat & PAS_DMA_RXINT_RCMDSTA_ACT) 916 if (!(stat & PAS_DMA_RXINT_RCMDSTA_ACT))
690 break; 917 break;
691 cond_resched(); 918 cond_resched();
692 } 919 }
693 920
694 if (!(stat & PAS_DMA_RXINT_RCMDSTA_ACT)) { 921 if (stat & PAS_DMA_RXINT_RCMDSTA_ACT)
695 dev_err(&mac->dma_pdev->dev, "Failed to stop rx interface\n"); 922 dev_err(&mac->dma_pdev->dev, "Failed to stop rx interface\n");
696 }
697 923
698 /* Then, disable the channel. This must be done separately from 924 /* Then, disable the channel. This must be done separately from
699 * stopping, since you can't disable when active. 925 * stopping, since you can't disable when active.
@@ -706,8 +932,8 @@ static int pasemi_mac_close(struct net_device *dev)
706 pci_write_config_dword(mac->dma_pdev, 932 pci_write_config_dword(mac->dma_pdev,
707 PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0); 933 PAS_DMA_RXINT_RCMDSTA(mac->dma_if), 0);
708 934
709 free_irq(mac->dma_pdev->irq + mac->dma_txch, dev); 935 free_irq(mac->tx_irq, dev);
710 free_irq(mac->dma_pdev->irq + 20 + mac->dma_rxch, dev); 936 free_irq(mac->rx_irq, dev);
711 937
712 /* Free resources */ 938 /* Free resources */
713 pasemi_mac_free_rx_resources(dev); 939 pasemi_mac_free_rx_resources(dev);
@@ -757,6 +983,7 @@ static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
757 if (txring->next_to_clean - txring->next_to_use == TX_RING_SIZE) { 983 if (txring->next_to_clean - txring->next_to_use == TX_RING_SIZE) {
758 spin_unlock_irqrestore(&txring->lock, flags); 984 spin_unlock_irqrestore(&txring->lock, flags);
759 pasemi_mac_clean_tx(mac); 985 pasemi_mac_clean_tx(mac);
986 pasemi_mac_restart_tx_intr(mac);
760 spin_lock_irqsave(&txring->lock, flags); 987 spin_lock_irqsave(&txring->lock, flags);
761 988
762 if (txring->next_to_clean - txring->next_to_use == 989 if (txring->next_to_clean - txring->next_to_use ==
@@ -802,6 +1029,7 @@ static struct net_device_stats *pasemi_mac_get_stats(struct net_device *dev)
802 return &mac->stats; 1029 return &mac->stats;
803} 1030}
804 1031
1032
805static void pasemi_mac_set_rx_mode(struct net_device *dev) 1033static void pasemi_mac_set_rx_mode(struct net_device *dev)
806{ 1034{
807 struct pasemi_mac *mac = netdev_priv(dev); 1035 struct pasemi_mac *mac = netdev_priv(dev);
@@ -826,18 +1054,17 @@ static int pasemi_mac_poll(struct net_device *dev, int *budget)
826 1054
827 pkts = pasemi_mac_clean_rx(mac, limit); 1055 pkts = pasemi_mac_clean_rx(mac, limit);
828 1056
1057 dev->quota -= pkts;
1058 *budget -= pkts;
1059
829 if (pkts < limit) { 1060 if (pkts < limit) {
830 /* all done, no more packets present */ 1061 /* all done, no more packets present */
831 netif_rx_complete(dev); 1062 netif_rx_complete(dev);
832 1063
833 /* re-enable receive interrupts */ 1064 pasemi_mac_restart_rx_intr(mac);
834 pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_COM_TIMEOUTCFG,
835 PAS_IOB_DMA_COM_TIMEOUTCFG_TCNT(1000000));
836 return 0; 1065 return 0;
837 } else { 1066 } else {
838 /* used up our quantum, so reschedule */ 1067 /* used up our quantum, so reschedule */
839 dev->quota -= pkts;
840 *budget -= pkts;
841 return 1; 1068 return 1;
842 } 1069 }
843} 1070}
@@ -937,6 +1164,11 @@ pasemi_mac_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
937 mac->rx_status = &dma_status->rx_sta[mac->dma_rxch]; 1164 mac->rx_status = &dma_status->rx_sta[mac->dma_rxch];
938 mac->tx_status = &dma_status->tx_sta[mac->dma_txch]; 1165 mac->tx_status = &dma_status->tx_sta[mac->dma_txch];
939 1166
1167 mac->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
1168
1169 /* Enable most messages by default */
1170 mac->msg_enable = (NETIF_MSG_IFUP << 1 ) - 1;
1171
940 err = register_netdev(dev); 1172 err = register_netdev(dev);
941 1173
942 if (err) { 1174 if (err) {
@@ -988,6 +1220,7 @@ static void __devexit pasemi_mac_remove(struct pci_dev *pdev)
988static struct pci_device_id pasemi_mac_pci_tbl[] = { 1220static struct pci_device_id pasemi_mac_pci_tbl[] = {
989 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) }, 1221 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) },
990 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) }, 1222 { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) },
1223 { },
991}; 1224};
992 1225
993MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl); 1226MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl);
@@ -1011,9 +1244,5 @@ int pasemi_mac_init_module(void)
1011 return pci_register_driver(&pasemi_mac_driver); 1244 return pci_register_driver(&pasemi_mac_driver);
1012} 1245}
1013 1246
1014MODULE_LICENSE("GPL");
1015MODULE_AUTHOR ("Olof Johansson <olof@lixom.net>");
1016MODULE_DESCRIPTION("PA Semi PWRficient Ethernet driver");
1017
1018module_init(pasemi_mac_init_module); 1247module_init(pasemi_mac_init_module);
1019module_exit(pasemi_mac_cleanup_module); 1248module_exit(pasemi_mac_cleanup_module);
diff --git a/drivers/net/pasemi_mac.h b/drivers/net/pasemi_mac.h
index c3e37e46a18a..c29ee159c33d 100644
--- a/drivers/net/pasemi_mac.h
+++ b/drivers/net/pasemi_mac.h
@@ -24,6 +24,7 @@
24#include <linux/ethtool.h> 24#include <linux/ethtool.h>
25#include <linux/netdevice.h> 25#include <linux/netdevice.h>
26#include <linux/spinlock.h> 26#include <linux/spinlock.h>
27#include <linux/phy.h>
27 28
28struct pasemi_mac_txring { 29struct pasemi_mac_txring {
29 spinlock_t lock; 30 spinlock_t lock;
@@ -54,6 +55,7 @@ struct pasemi_mac {
54 struct pci_dev *pdev; 55 struct pci_dev *pdev;
55 struct pci_dev *dma_pdev; 56 struct pci_dev *dma_pdev;
56 struct pci_dev *iob_pdev; 57 struct pci_dev *iob_pdev;
58 struct phy_device *phydev;
57 struct net_device_stats stats; 59 struct net_device_stats stats;
58 60
59 /* Pointer to the cacheable per-channel status registers */ 61 /* Pointer to the cacheable per-channel status registers */
@@ -73,6 +75,14 @@ struct pasemi_mac {
73 75
74 struct pasemi_mac_txring *tx; 76 struct pasemi_mac_txring *tx;
75 struct pasemi_mac_rxring *rx; 77 struct pasemi_mac_rxring *rx;
78 unsigned long tx_irq;
79 unsigned long rx_irq;
80 int link;
81 int speed;
82 int duplex;
83
84 unsigned int msg_enable;
85 char phy_id[BUS_ID_SIZE];
76}; 86};
77 87
78/* Software status descriptor (desc_info) */ 88/* Software status descriptor (desc_info) */
@@ -193,11 +203,15 @@ enum {
193#define PAS_DMA_RXINT_RCMDSTA(i) (0x200+(i)*_PAS_DMA_RXINT_STRIDE) 203#define PAS_DMA_RXINT_RCMDSTA(i) (0x200+(i)*_PAS_DMA_RXINT_STRIDE)
194#define PAS_DMA_RXINT_RCMDSTA_EN 0x00000001 204#define PAS_DMA_RXINT_RCMDSTA_EN 0x00000001
195#define PAS_DMA_RXINT_RCMDSTA_ST 0x00000002 205#define PAS_DMA_RXINT_RCMDSTA_ST 0x00000002
196#define PAS_DMA_RXINT_RCMDSTA_OO 0x00000100 206#define PAS_DMA_RXINT_RCMDSTA_MBT 0x00000008
197#define PAS_DMA_RXINT_RCMDSTA_BP 0x00000200 207#define PAS_DMA_RXINT_RCMDSTA_MDR 0x00000010
198#define PAS_DMA_RXINT_RCMDSTA_DR 0x00000400 208#define PAS_DMA_RXINT_RCMDSTA_MOO 0x00000020
209#define PAS_DMA_RXINT_RCMDSTA_MBP 0x00000040
199#define PAS_DMA_RXINT_RCMDSTA_BT 0x00000800 210#define PAS_DMA_RXINT_RCMDSTA_BT 0x00000800
200#define PAS_DMA_RXINT_RCMDSTA_TB 0x00001000 211#define PAS_DMA_RXINT_RCMDSTA_DR 0x00001000
212#define PAS_DMA_RXINT_RCMDSTA_OO 0x00002000
213#define PAS_DMA_RXINT_RCMDSTA_BP 0x00004000
214#define PAS_DMA_RXINT_RCMDSTA_TB 0x00008000
201#define PAS_DMA_RXINT_RCMDSTA_ACT 0x00010000 215#define PAS_DMA_RXINT_RCMDSTA_ACT 0x00010000
202#define PAS_DMA_RXINT_RCMDSTA_DROPS_M 0xfffe0000 216#define PAS_DMA_RXINT_RCMDSTA_DROPS_M 0xfffe0000
203#define PAS_DMA_RXINT_RCMDSTA_DROPS_S 17 217#define PAS_DMA_RXINT_RCMDSTA_DROPS_S 17
@@ -297,6 +311,7 @@ enum {
297#define PAS_STATUS_DCNT_S 16 311#define PAS_STATUS_DCNT_S 16
298#define PAS_STATUS_BPCNT_M 0x0000ffff00000000ull 312#define PAS_STATUS_BPCNT_M 0x0000ffff00000000ull
299#define PAS_STATUS_BPCNT_S 32 313#define PAS_STATUS_BPCNT_S 32
314#define PAS_STATUS_CAUSE_M 0xf000000000000000ull
300#define PAS_STATUS_TIMER 0x1000000000000000ull 315#define PAS_STATUS_TIMER 0x1000000000000000ull
301#define PAS_STATUS_ERROR 0x2000000000000000ull 316#define PAS_STATUS_ERROR 0x2000000000000000ull
302#define PAS_STATUS_SOFT 0x4000000000000000ull 317#define PAS_STATUS_SOFT 0x4000000000000000ull
@@ -326,7 +341,7 @@ enum {
326 PAS_IOB_DMA_TXCH_STAT_CNTDEL_M) 341 PAS_IOB_DMA_TXCH_STAT_CNTDEL_M)
327#define PAS_IOB_DMA_RXCH_RESET(i) (0x1500 + (i)*4) 342#define PAS_IOB_DMA_RXCH_RESET(i) (0x1500 + (i)*4)
328#define PAS_IOB_DMA_RXCH_RESET_PCNT_M 0xffff0000 343#define PAS_IOB_DMA_RXCH_RESET_PCNT_M 0xffff0000
329#define PAS_IOB_DMA_RXCH_RESET_PCNT_S 0 344#define PAS_IOB_DMA_RXCH_RESET_PCNT_S 16
330#define PAS_IOB_DMA_RXCH_RESET_PCNT(x) (((x) << PAS_IOB_DMA_RXCH_RESET_PCNT_S) & \ 345#define PAS_IOB_DMA_RXCH_RESET_PCNT(x) (((x) << PAS_IOB_DMA_RXCH_RESET_PCNT_S) & \
331 PAS_IOB_DMA_RXCH_RESET_PCNT_M) 346 PAS_IOB_DMA_RXCH_RESET_PCNT_M)
332#define PAS_IOB_DMA_RXCH_RESET_PCNTRST 0x00000020 347#define PAS_IOB_DMA_RXCH_RESET_PCNTRST 0x00000020
@@ -337,7 +352,7 @@ enum {
337#define PAS_IOB_DMA_RXCH_RESET_PINTC 0x00000001 352#define PAS_IOB_DMA_RXCH_RESET_PINTC 0x00000001
338#define PAS_IOB_DMA_TXCH_RESET(i) (0x1600 + (i)*4) 353#define PAS_IOB_DMA_TXCH_RESET(i) (0x1600 + (i)*4)
339#define PAS_IOB_DMA_TXCH_RESET_PCNT_M 0xffff0000 354#define PAS_IOB_DMA_TXCH_RESET_PCNT_M 0xffff0000
340#define PAS_IOB_DMA_TXCH_RESET_PCNT_S 0 355#define PAS_IOB_DMA_TXCH_RESET_PCNT_S 16
341#define PAS_IOB_DMA_TXCH_RESET_PCNT(x) (((x) << PAS_IOB_DMA_TXCH_RESET_PCNT_S) & \ 356#define PAS_IOB_DMA_TXCH_RESET_PCNT(x) (((x) << PAS_IOB_DMA_TXCH_RESET_PCNT_S) & \
342 PAS_IOB_DMA_TXCH_RESET_PCNT_M) 357 PAS_IOB_DMA_TXCH_RESET_PCNT_M)
343#define PAS_IOB_DMA_TXCH_RESET_PCNTRST 0x00000020 358#define PAS_IOB_DMA_TXCH_RESET_PCNTRST 0x00000020
diff --git a/drivers/net/pcmcia/Kconfig b/drivers/net/pcmcia/Kconfig
index 74f862001247..5d658bc9791c 100644
--- a/drivers/net/pcmcia/Kconfig
+++ b/drivers/net/pcmcia/Kconfig
@@ -2,11 +2,9 @@
2# PCMCIA Network device configuration 2# PCMCIA Network device configuration
3# 3#
4 4
5menu "PCMCIA network device support" 5menuconfig NET_PCMCIA
6 depends on NETDEVICES && PCMCIA!=n
7
8config NET_PCMCIA
9 bool "PCMCIA network device support" 6 bool "PCMCIA network device support"
7 depends on PCMCIA
10 ---help--- 8 ---help---
11 Say Y if you would like to include support for any PCMCIA or CardBus 9 Say Y if you would like to include support for any PCMCIA or CardBus
12 network adapters, then say Y to the driver for your particular card 10 network adapters, then say Y to the driver for your particular card
@@ -21,9 +19,10 @@ config NET_PCMCIA
21 19
22 If unsure, say N. 20 If unsure, say N.
23 21
22if NET_PCMCIA
23
24config PCMCIA_3C589 24config PCMCIA_3C589
25 tristate "3Com 3c589 PCMCIA support" 25 tristate "3Com 3c589 PCMCIA support"
26 depends on NET_PCMCIA && PCMCIA
27 help 26 help
28 Say Y here if you intend to attach a 3Com 3c589 or compatible PCMCIA 27 Say Y here if you intend to attach a 3Com 3c589 or compatible PCMCIA
29 (PC-card) Ethernet card to your computer. 28 (PC-card) Ethernet card to your computer.
@@ -33,7 +32,6 @@ config PCMCIA_3C589
33 32
34config PCMCIA_3C574 33config PCMCIA_3C574
35 tristate "3Com 3c574 PCMCIA support" 34 tristate "3Com 3c574 PCMCIA support"
36 depends on NET_PCMCIA && PCMCIA
37 help 35 help
38 Say Y here if you intend to attach a 3Com 3c574 or compatible PCMCIA 36 Say Y here if you intend to attach a 3Com 3c574 or compatible PCMCIA
39 (PC-card) Fast Ethernet card to your computer. 37 (PC-card) Fast Ethernet card to your computer.
@@ -43,7 +41,6 @@ config PCMCIA_3C574
43 41
44config PCMCIA_FMVJ18X 42config PCMCIA_FMVJ18X
45 tristate "Fujitsu FMV-J18x PCMCIA support" 43 tristate "Fujitsu FMV-J18x PCMCIA support"
46 depends on NET_PCMCIA && PCMCIA
47 select CRC32 44 select CRC32
48 help 45 help
49 Say Y here if you intend to attach a Fujitsu FMV-J18x or compatible 46 Say Y here if you intend to attach a Fujitsu FMV-J18x or compatible
@@ -54,7 +51,6 @@ config PCMCIA_FMVJ18X
54 51
55config PCMCIA_PCNET 52config PCMCIA_PCNET
56 tristate "NE2000 compatible PCMCIA support" 53 tristate "NE2000 compatible PCMCIA support"
57 depends on NET_PCMCIA && PCMCIA
58 select CRC32 54 select CRC32
59 help 55 help
60 Say Y here if you intend to attach an NE2000 compatible PCMCIA 56 Say Y here if you intend to attach an NE2000 compatible PCMCIA
@@ -65,7 +61,6 @@ config PCMCIA_PCNET
65 61
66config PCMCIA_NMCLAN 62config PCMCIA_NMCLAN
67 tristate "New Media PCMCIA support" 63 tristate "New Media PCMCIA support"
68 depends on NET_PCMCIA && PCMCIA
69 help 64 help
70 Say Y here if you intend to attach a New Media Ethernet or LiveWire 65 Say Y here if you intend to attach a New Media Ethernet or LiveWire
71 PCMCIA (PC-card) Ethernet card to your computer. 66 PCMCIA (PC-card) Ethernet card to your computer.
@@ -75,7 +70,6 @@ config PCMCIA_NMCLAN
75 70
76config PCMCIA_SMC91C92 71config PCMCIA_SMC91C92
77 tristate "SMC 91Cxx PCMCIA support" 72 tristate "SMC 91Cxx PCMCIA support"
78 depends on NET_PCMCIA && PCMCIA
79 select CRC32 73 select CRC32
80 select MII 74 select MII
81 help 75 help
@@ -87,7 +81,6 @@ config PCMCIA_SMC91C92
87 81
88config PCMCIA_XIRC2PS 82config PCMCIA_XIRC2PS
89 tristate "Xircom 16-bit PCMCIA support" 83 tristate "Xircom 16-bit PCMCIA support"
90 depends on NET_PCMCIA && PCMCIA
91 help 84 help
92 Say Y here if you intend to attach a Xircom 16-bit PCMCIA (PC-card) 85 Say Y here if you intend to attach a Xircom 16-bit PCMCIA (PC-card)
93 Ethernet or Fast Ethernet card to your computer. 86 Ethernet or Fast Ethernet card to your computer.
@@ -97,7 +90,6 @@ config PCMCIA_XIRC2PS
97 90
98config PCMCIA_AXNET 91config PCMCIA_AXNET
99 tristate "Asix AX88190 PCMCIA support" 92 tristate "Asix AX88190 PCMCIA support"
100 depends on NET_PCMCIA && PCMCIA
101 ---help--- 93 ---help---
102 Say Y here if you intend to attach an Asix AX88190-based PCMCIA 94 Say Y here if you intend to attach an Asix AX88190-based PCMCIA
103 (PC-card) Fast Ethernet card to your computer. These cards are 95 (PC-card) Fast Ethernet card to your computer. These cards are
@@ -109,7 +101,7 @@ config PCMCIA_AXNET
109 101
110config ARCNET_COM20020_CS 102config ARCNET_COM20020_CS
111 tristate "COM20020 ARCnet PCMCIA support" 103 tristate "COM20020 ARCnet PCMCIA support"
112 depends on NET_PCMCIA && ARCNET_COM20020 && PCMCIA 104 depends on ARCNET_COM20020
113 help 105 help
114 Say Y here if you intend to attach this type of ARCnet PCMCIA card 106 Say Y here if you intend to attach this type of ARCnet PCMCIA card
115 to your computer. 107 to your computer.
@@ -119,7 +111,7 @@ config ARCNET_COM20020_CS
119 111
120config PCMCIA_IBMTR 112config PCMCIA_IBMTR
121 tristate "IBM PCMCIA tokenring adapter support" 113 tristate "IBM PCMCIA tokenring adapter support"
122 depends on NET_PCMCIA && IBMTR!=y && TR && PCMCIA && !64BIT 114 depends on IBMTR!=y && TR && !64BIT
123 help 115 help
124 Say Y here if you intend to attach this type of Token Ring PCMCIA 116 Say Y here if you intend to attach this type of Token Ring PCMCIA
125 card to your computer. You then also need to say Y to "Token Ring 117 card to your computer. You then also need to say Y to "Token Ring
@@ -128,5 +120,4 @@ config PCMCIA_IBMTR
128 To compile this driver as a module, choose M here: the module will be 120 To compile this driver as a module, choose M here: the module will be
129 called ibmtr_cs. 121 called ibmtr_cs.
130 122
131endmenu 123endif # NET_PCMCIA
132
diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c
index 1060154ae750..4ecb8ca5a992 100644
--- a/drivers/net/pcmcia/ibmtr_cs.c
+++ b/drivers/net/pcmcia/ibmtr_cs.c
@@ -189,16 +189,20 @@ static void ibmtr_detach(struct pcmcia_device *link)
189{ 189{
190 struct ibmtr_dev_t *info = link->priv; 190 struct ibmtr_dev_t *info = link->priv;
191 struct net_device *dev = info->dev; 191 struct net_device *dev = info->dev;
192 struct tok_info *ti = netdev_priv(dev);
192 193
193 DEBUG(0, "ibmtr_detach(0x%p)\n", link); 194 DEBUG(0, "ibmtr_detach(0x%p)\n", link);
195
196 /*
197 * When the card removal interrupt hits tok_interrupt(),
198 * bail out early, so we don't crash the machine
199 */
200 ti->sram_phys |= 1;
194 201
195 if (link->dev_node) 202 if (link->dev_node)
196 unregister_netdev(dev); 203 unregister_netdev(dev);
197 204
198 { 205 del_timer_sync(&(ti->tr_timer));
199 struct tok_info *ti = netdev_priv(dev);
200 del_timer_sync(&(ti->tr_timer));
201 }
202 206
203 ibmtr_release(link); 207 ibmtr_release(link);
204 208
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index 809ec440b8eb..258d6f396186 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -1420,7 +1420,7 @@ set_addresses(struct net_device *dev)
1420 kio_addr_t ioaddr = dev->base_addr; 1420 kio_addr_t ioaddr = dev->base_addr;
1421 local_info_t *lp = netdev_priv(dev); 1421 local_info_t *lp = netdev_priv(dev);
1422 struct dev_mc_list *dmi = dev->mc_list; 1422 struct dev_mc_list *dmi = dev->mc_list;
1423 char *addr; 1423 unsigned char *addr;
1424 int i,j,k,n; 1424 int i,j,k,n;
1425 1425
1426 SelectPage(k=0x50); 1426 SelectPage(k=0x50);
@@ -1429,6 +1429,9 @@ set_addresses(struct net_device *dev)
1429 if (++n > 9) 1429 if (++n > 9)
1430 break; 1430 break;
1431 i = 0; 1431 i = 0;
1432 if (n > 1 && n <= dev->mc_count && dmi) {
1433 dmi = dmi->next;
1434 }
1432 } 1435 }
1433 if (j > 15) { 1436 if (j > 15) {
1434 j = 8; 1437 j = 8;
@@ -1436,10 +1439,9 @@ set_addresses(struct net_device *dev)
1436 SelectPage(k); 1439 SelectPage(k);
1437 } 1440 }
1438 1441
1439 if (n && n <= dev->mc_count && dmi) { 1442 if (n && n <= dev->mc_count && dmi)
1440 addr = dmi->dmi_addr; 1443 addr = dmi->dmi_addr;
1441 dmi = dmi->next; 1444 else
1442 } else
1443 addr = dev->dev_addr; 1445 addr = dev->dev_addr;
1444 1446
1445 if (lp->mohawk) 1447 if (lp->mohawk)
@@ -1465,10 +1467,10 @@ set_multicast_list(struct net_device *dev)
1465 if (dev->flags & IFF_PROMISC) { /* snoop */ 1467 if (dev->flags & IFF_PROMISC) { /* snoop */
1466 PutByte(XIRCREG42_SWC1, 0x06); /* set MPE and PME */ 1468 PutByte(XIRCREG42_SWC1, 0x06); /* set MPE and PME */
1467 } else if (dev->mc_count > 9 || (dev->flags & IFF_ALLMULTI)) { 1469 } else if (dev->mc_count > 9 || (dev->flags & IFF_ALLMULTI)) {
1468 PutByte(XIRCREG42_SWC1, 0x06); /* set MPE */ 1470 PutByte(XIRCREG42_SWC1, 0x02); /* set MPE */
1469 } else if (dev->mc_count) { 1471 } else if (dev->mc_count) {
1470 /* the chip can filter 9 addresses perfectly */ 1472 /* the chip can filter 9 addresses perfectly */
1471 PutByte(XIRCREG42_SWC1, 0x00); 1473 PutByte(XIRCREG42_SWC1, 0x01);
1472 SelectPage(0x40); 1474 SelectPage(0x40);
1473 PutByte(XIRCREG40_CMD0, Offline); 1475 PutByte(XIRCREG40_CMD0, Offline);
1474 set_addresses(dev); 1476 set_addresses(dev);
diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index f994f129f3d8..09b6f259eb92 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -2,69 +2,61 @@
2# PHY Layer Configuration 2# PHY Layer Configuration
3# 3#
4 4
5menu "PHY device support" 5menuconfig PHYLIB
6
7config PHYLIB
8 tristate "PHY Device support and infrastructure" 6 tristate "PHY Device support and infrastructure"
7 depends on !S390
9 depends on NET_ETHERNET && (BROKEN || !S390) 8 depends on NET_ETHERNET && (BROKEN || !S390)
10 help 9 help
11 Ethernet controllers are usually attached to PHY 10 Ethernet controllers are usually attached to PHY
12 devices. This option provides infrastructure for 11 devices. This option provides infrastructure for
13 managing PHY devices. 12 managing PHY devices.
14 13
14if PHYLIB
15
15comment "MII PHY device drivers" 16comment "MII PHY device drivers"
16 depends on PHYLIB
17 17
18config MARVELL_PHY 18config MARVELL_PHY
19 tristate "Drivers for Marvell PHYs" 19 tristate "Drivers for Marvell PHYs"
20 depends on PHYLIB
21 ---help--- 20 ---help---
22 Currently has a driver for the 88E1011S 21 Currently has a driver for the 88E1011S
23 22
24config DAVICOM_PHY 23config DAVICOM_PHY
25 tristate "Drivers for Davicom PHYs" 24 tristate "Drivers for Davicom PHYs"
26 depends on PHYLIB
27 ---help--- 25 ---help---
28 Currently supports dm9161e and dm9131 26 Currently supports dm9161e and dm9131
29 27
30config QSEMI_PHY 28config QSEMI_PHY
31 tristate "Drivers for Quality Semiconductor PHYs" 29 tristate "Drivers for Quality Semiconductor PHYs"
32 depends on PHYLIB
33 ---help--- 30 ---help---
34 Currently supports the qs6612 31 Currently supports the qs6612
35 32
36config LXT_PHY 33config LXT_PHY
37 tristate "Drivers for the Intel LXT PHYs" 34 tristate "Drivers for the Intel LXT PHYs"
38 depends on PHYLIB
39 ---help--- 35 ---help---
40 Currently supports the lxt970, lxt971 36 Currently supports the lxt970, lxt971
41 37
42config CICADA_PHY 38config CICADA_PHY
43 tristate "Drivers for the Cicada PHYs" 39 tristate "Drivers for the Cicada PHYs"
44 depends on PHYLIB
45 ---help--- 40 ---help---
46 Currently supports the cis8204 41 Currently supports the cis8204
42
47config VITESSE_PHY 43config VITESSE_PHY
48 tristate "Drivers for the Vitesse PHYs" 44 tristate "Drivers for the Vitesse PHYs"
49 depends on PHYLIB
50 ---help--- 45 ---help---
51 Currently supports the vsc8244 46 Currently supports the vsc8244
52 47
53config SMSC_PHY 48config SMSC_PHY
54 tristate "Drivers for SMSC PHYs" 49 tristate "Drivers for SMSC PHYs"
55 depends on PHYLIB
56 ---help--- 50 ---help---
57 Currently supports the LAN83C185 PHY 51 Currently supports the LAN83C185 PHY
58 52
59config BROADCOM_PHY 53config BROADCOM_PHY
60 tristate "Drivers for Broadcom PHYs" 54 tristate "Drivers for Broadcom PHYs"
61 depends on PHYLIB
62 ---help--- 55 ---help---
63 Currently supports the BCM5411, BCM5421 and BCM5461 PHYs. 56 Currently supports the BCM5411, BCM5421 and BCM5461 PHYs.
64 57
65config FIXED_PHY 58config FIXED_PHY
66 tristate "Drivers for PHY emulation on fixed speed/link" 59 tristate "Drivers for PHY emulation on fixed speed/link"
67 depends on PHYLIB
68 ---help--- 60 ---help---
69 Adds the driver to PHY layer to cover the boards that do not have any PHY bound, 61 Adds the driver to PHY layer to cover the boards that do not have any PHY bound,
70 but with the ability to manipulate the speed/link in software. The relevant MII 62 but with the ability to manipulate the speed/link in software. The relevant MII
@@ -79,5 +71,4 @@ config FIXED_MII_100_FDX
79 bool "Emulation for 100M Fdx fixed PHY behavior" 71 bool "Emulation for 100M Fdx fixed PHY behavior"
80 depends on FIXED_PHY 72 depends on FIXED_PHY
81 73
82endmenu 74endif # PHYLIB
83
diff --git a/drivers/net/phy/davicom.c b/drivers/net/phy/davicom.c
index 519baa38be8d..7ed632db00d7 100644
--- a/drivers/net/phy/davicom.c
+++ b/drivers/net/phy/davicom.c
@@ -139,7 +139,7 @@ static int dm9161_ack_interrupt(struct phy_device *phydev)
139 return (err < 0) ? err : 0; 139 return (err < 0) ? err : 0;
140} 140}
141 141
142static struct phy_driver dm9161_driver = { 142static struct phy_driver dm9161e_driver = {
143 .phy_id = 0x0181b880, 143 .phy_id = 0x0181b880,
144 .name = "Davicom DM9161E", 144 .name = "Davicom DM9161E",
145 .phy_id_mask = 0x0ffffff0, 145 .phy_id_mask = 0x0ffffff0,
@@ -147,7 +147,18 @@ static struct phy_driver dm9161_driver = {
147 .config_init = dm9161_config_init, 147 .config_init = dm9161_config_init,
148 .config_aneg = dm9161_config_aneg, 148 .config_aneg = dm9161_config_aneg,
149 .read_status = genphy_read_status, 149 .read_status = genphy_read_status,
150 .driver = { .owner = THIS_MODULE,}, 150 .driver = { .owner = THIS_MODULE,},
151};
152
153static struct phy_driver dm9161a_driver = {
154 .phy_id = 0x0181b8a0,
155 .name = "Davicom DM9161A",
156 .phy_id_mask = 0x0ffffff0,
157 .features = PHY_BASIC_FEATURES,
158 .config_init = dm9161_config_init,
159 .config_aneg = dm9161_config_aneg,
160 .read_status = genphy_read_status,
161 .driver = { .owner = THIS_MODULE,},
151}; 162};
152 163
153static struct phy_driver dm9131_driver = { 164static struct phy_driver dm9131_driver = {
@@ -160,31 +171,38 @@ static struct phy_driver dm9131_driver = {
160 .read_status = genphy_read_status, 171 .read_status = genphy_read_status,
161 .ack_interrupt = dm9161_ack_interrupt, 172 .ack_interrupt = dm9161_ack_interrupt,
162 .config_intr = dm9161_config_intr, 173 .config_intr = dm9161_config_intr,
163 .driver = { .owner = THIS_MODULE,}, 174 .driver = { .owner = THIS_MODULE,},
164}; 175};
165 176
166static int __init davicom_init(void) 177static int __init davicom_init(void)
167{ 178{
168 int ret; 179 int ret;
169 180
170 ret = phy_driver_register(&dm9161_driver); 181 ret = phy_driver_register(&dm9161e_driver);
171 if (ret) 182 if (ret)
172 goto err1; 183 goto err1;
173 184
174 ret = phy_driver_register(&dm9131_driver); 185 ret = phy_driver_register(&dm9161a_driver);
175 if (ret) 186 if (ret)
176 goto err2; 187 goto err2;
188
189 ret = phy_driver_register(&dm9131_driver);
190 if (ret)
191 goto err3;
177 return 0; 192 return 0;
178 193
179 err2: 194 err3:
180 phy_driver_unregister(&dm9161_driver); 195 phy_driver_unregister(&dm9161a_driver);
196 err2:
197 phy_driver_unregister(&dm9161e_driver);
181 err1: 198 err1:
182 return ret; 199 return ret;
183} 200}
184 201
185static void __exit davicom_exit(void) 202static void __exit davicom_exit(void)
186{ 203{
187 phy_driver_unregister(&dm9161_driver); 204 phy_driver_unregister(&dm9161e_driver);
205 phy_driver_unregister(&dm9161a_driver);
188 phy_driver_unregister(&dm9131_driver); 206 phy_driver_unregister(&dm9131_driver);
189} 207}
190 208
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index eed433d6056a..f71dab347667 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -662,10 +662,10 @@ int phy_stop_interrupts(struct phy_device *phydev)
662 phy_error(phydev); 662 phy_error(phydev);
663 663
664 /* 664 /*
665 * Finish any pending work; we might have been scheduled 665 * Finish any pending work; we might have been scheduled to be called
666 * to be called from keventd ourselves, though. 666 * from keventd ourselves, but cancel_work_sync() handles that.
667 */ 667 */
668 run_scheduled_work(&phydev->phy_queue); 668 cancel_work_sync(&phydev->phy_queue);
669 669
670 free_irq(phydev->irq, phydev); 670 free_irq(phydev->irq, phydev);
671 671
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 6d596ca50cfd..541168713f1f 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -40,7 +40,6 @@
40#include <linux/ip.h> 40#include <linux/ip.h>
41#include <linux/tcp.h> 41#include <linux/tcp.h>
42#include <linux/spinlock.h> 42#include <linux/spinlock.h>
43#include <linux/smp_lock.h>
44#include <linux/rwsem.h> 43#include <linux/rwsem.h>
45#include <linux/stddef.h> 44#include <linux/stddef.h>
46#include <linux/device.h> 45#include <linux/device.h>
diff --git a/drivers/net/s2io.c b/drivers/net/s2io.c
index 290e1c1f30c6..e3e6d410d72c 100644
--- a/drivers/net/s2io.c
+++ b/drivers/net/s2io.c
@@ -84,7 +84,7 @@
84#include "s2io.h" 84#include "s2io.h"
85#include "s2io-regs.h" 85#include "s2io-regs.h"
86 86
87#define DRV_VERSION "2.0.22.1" 87#define DRV_VERSION "2.0.23.1"
88 88
89/* S2io Driver name & version. */ 89/* S2io Driver name & version. */
90static char s2io_driver_name[] = "Neterion"; 90static char s2io_driver_name[] = "Neterion";
@@ -281,6 +281,28 @@ static char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = {
281 ("lro_out_of_sequence_pkts"), 281 ("lro_out_of_sequence_pkts"),
282 ("lro_flush_due_to_max_pkts"), 282 ("lro_flush_due_to_max_pkts"),
283 ("lro_avg_aggr_pkts"), 283 ("lro_avg_aggr_pkts"),
284 ("mem_alloc_fail_cnt"),
285 ("watchdog_timer_cnt"),
286 ("mem_allocated"),
287 ("mem_freed"),
288 ("link_up_cnt"),
289 ("link_down_cnt"),
290 ("link_up_time"),
291 ("link_down_time"),
292 ("tx_tcode_buf_abort_cnt"),
293 ("tx_tcode_desc_abort_cnt"),
294 ("tx_tcode_parity_err_cnt"),
295 ("tx_tcode_link_loss_cnt"),
296 ("tx_tcode_list_proc_err_cnt"),
297 ("rx_tcode_parity_err_cnt"),
298 ("rx_tcode_abort_cnt"),
299 ("rx_tcode_parity_abort_cnt"),
300 ("rx_tcode_rda_fail_cnt"),
301 ("rx_tcode_unkn_prot_cnt"),
302 ("rx_tcode_fcs_err_cnt"),
303 ("rx_tcode_buf_size_err_cnt"),
304 ("rx_tcode_rxd_corrupt_cnt"),
305 ("rx_tcode_unkn_err_cnt")
284}; 306};
285 307
286#define S2IO_XENA_STAT_LEN sizeof(ethtool_xena_stats_keys)/ ETH_GSTRING_LEN 308#define S2IO_XENA_STAT_LEN sizeof(ethtool_xena_stats_keys)/ ETH_GSTRING_LEN
@@ -490,6 +512,7 @@ static int init_shared_mem(struct s2io_nic *nic)
490 512
491 struct mac_info *mac_control; 513 struct mac_info *mac_control;
492 struct config_param *config; 514 struct config_param *config;
515 unsigned long long mem_allocated = 0;
493 516
494 mac_control = &nic->mac_control; 517 mac_control = &nic->mac_control;
495 config = &nic->config; 518 config = &nic->config;
@@ -519,6 +542,7 @@ static int init_shared_mem(struct s2io_nic *nic)
519 "Malloc failed for list_info\n"); 542 "Malloc failed for list_info\n");
520 return -ENOMEM; 543 return -ENOMEM;
521 } 544 }
545 mem_allocated += list_holder_size;
522 memset(mac_control->fifos[i].list_info, 0, list_holder_size); 546 memset(mac_control->fifos[i].list_info, 0, list_holder_size);
523 } 547 }
524 for (i = 0; i < config->tx_fifo_num; i++) { 548 for (i = 0; i < config->tx_fifo_num; i++) {
@@ -565,6 +589,7 @@ static int init_shared_mem(struct s2io_nic *nic)
565 DBG_PRINT(INFO_DBG, "failed for TxDL\n"); 589 DBG_PRINT(INFO_DBG, "failed for TxDL\n");
566 return -ENOMEM; 590 return -ENOMEM;
567 } 591 }
592 mem_allocated += PAGE_SIZE;
568 } 593 }
569 while (k < lst_per_page) { 594 while (k < lst_per_page) {
570 int l = (j * lst_per_page) + k; 595 int l = (j * lst_per_page) + k;
@@ -582,6 +607,7 @@ static int init_shared_mem(struct s2io_nic *nic)
582 nic->ufo_in_band_v = kcalloc(size, sizeof(u64), GFP_KERNEL); 607 nic->ufo_in_band_v = kcalloc(size, sizeof(u64), GFP_KERNEL);
583 if (!nic->ufo_in_band_v) 608 if (!nic->ufo_in_band_v)
584 return -ENOMEM; 609 return -ENOMEM;
610 mem_allocated += (size * sizeof(u64));
585 611
586 /* Allocation and initialization of RXDs in Rings */ 612 /* Allocation and initialization of RXDs in Rings */
587 size = 0; 613 size = 0;
@@ -639,6 +665,7 @@ static int init_shared_mem(struct s2io_nic *nic)
639 rx_blocks->block_virt_addr = tmp_v_addr; 665 rx_blocks->block_virt_addr = tmp_v_addr;
640 return -ENOMEM; 666 return -ENOMEM;
641 } 667 }
668 mem_allocated += size;
642 memset(tmp_v_addr, 0, size); 669 memset(tmp_v_addr, 0, size);
643 rx_blocks->block_virt_addr = tmp_v_addr; 670 rx_blocks->block_virt_addr = tmp_v_addr;
644 rx_blocks->block_dma_addr = tmp_p_addr; 671 rx_blocks->block_dma_addr = tmp_p_addr;
@@ -647,6 +674,8 @@ static int init_shared_mem(struct s2io_nic *nic)
647 GFP_KERNEL); 674 GFP_KERNEL);
648 if (!rx_blocks->rxds) 675 if (!rx_blocks->rxds)
649 return -ENOMEM; 676 return -ENOMEM;
677 mem_allocated +=
678 (sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
650 for (l=0; l<rxd_count[nic->rxd_mode];l++) { 679 for (l=0; l<rxd_count[nic->rxd_mode];l++) {
651 rx_blocks->rxds[l].virt_addr = 680 rx_blocks->rxds[l].virt_addr =
652 rx_blocks->block_virt_addr + 681 rx_blocks->block_virt_addr +
@@ -689,6 +718,7 @@ static int init_shared_mem(struct s2io_nic *nic)
689 GFP_KERNEL); 718 GFP_KERNEL);
690 if (!mac_control->rings[i].ba) 719 if (!mac_control->rings[i].ba)
691 return -ENOMEM; 720 return -ENOMEM;
721 mem_allocated +=(sizeof(struct buffAdd *) * blk_cnt);
692 for (j = 0; j < blk_cnt; j++) { 722 for (j = 0; j < blk_cnt; j++) {
693 int k = 0; 723 int k = 0;
694 mac_control->rings[i].ba[j] = 724 mac_control->rings[i].ba[j] =
@@ -697,6 +727,8 @@ static int init_shared_mem(struct s2io_nic *nic)
697 GFP_KERNEL); 727 GFP_KERNEL);
698 if (!mac_control->rings[i].ba[j]) 728 if (!mac_control->rings[i].ba[j])
699 return -ENOMEM; 729 return -ENOMEM;
730 mem_allocated += (sizeof(struct buffAdd) * \
731 (rxd_count[nic->rxd_mode] + 1));
700 while (k != rxd_count[nic->rxd_mode]) { 732 while (k != rxd_count[nic->rxd_mode]) {
701 ba = &mac_control->rings[i].ba[j][k]; 733 ba = &mac_control->rings[i].ba[j][k];
702 734
@@ -704,6 +736,8 @@ static int init_shared_mem(struct s2io_nic *nic)
704 (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL); 736 (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
705 if (!ba->ba_0_org) 737 if (!ba->ba_0_org)
706 return -ENOMEM; 738 return -ENOMEM;
739 mem_allocated +=
740 (BUF0_LEN + ALIGN_SIZE);
707 tmp = (unsigned long)ba->ba_0_org; 741 tmp = (unsigned long)ba->ba_0_org;
708 tmp += ALIGN_SIZE; 742 tmp += ALIGN_SIZE;
709 tmp &= ~((unsigned long) ALIGN_SIZE); 743 tmp &= ~((unsigned long) ALIGN_SIZE);
@@ -713,6 +747,8 @@ static int init_shared_mem(struct s2io_nic *nic)
713 (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL); 747 (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
714 if (!ba->ba_1_org) 748 if (!ba->ba_1_org)
715 return -ENOMEM; 749 return -ENOMEM;
750 mem_allocated
751 += (BUF1_LEN + ALIGN_SIZE);
716 tmp = (unsigned long) ba->ba_1_org; 752 tmp = (unsigned long) ba->ba_1_org;
717 tmp += ALIGN_SIZE; 753 tmp += ALIGN_SIZE;
718 tmp &= ~((unsigned long) ALIGN_SIZE); 754 tmp &= ~((unsigned long) ALIGN_SIZE);
@@ -736,6 +772,7 @@ static int init_shared_mem(struct s2io_nic *nic)
736 */ 772 */
737 return -ENOMEM; 773 return -ENOMEM;
738 } 774 }
775 mem_allocated += size;
739 mac_control->stats_mem_sz = size; 776 mac_control->stats_mem_sz = size;
740 777
741 tmp_v_addr = mac_control->stats_mem; 778 tmp_v_addr = mac_control->stats_mem;
@@ -743,7 +780,7 @@ static int init_shared_mem(struct s2io_nic *nic)
743 memset(tmp_v_addr, 0, size); 780 memset(tmp_v_addr, 0, size);
744 DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name, 781 DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name,
745 (unsigned long long) tmp_p_addr); 782 (unsigned long long) tmp_p_addr);
746 783 mac_control->stats_info->sw_stat.mem_allocated += mem_allocated;
747 return SUCCESS; 784 return SUCCESS;
748} 785}
749 786
@@ -757,12 +794,14 @@ static int init_shared_mem(struct s2io_nic *nic)
757static void free_shared_mem(struct s2io_nic *nic) 794static void free_shared_mem(struct s2io_nic *nic)
758{ 795{
759 int i, j, blk_cnt, size; 796 int i, j, blk_cnt, size;
797 u32 ufo_size = 0;
760 void *tmp_v_addr; 798 void *tmp_v_addr;
761 dma_addr_t tmp_p_addr; 799 dma_addr_t tmp_p_addr;
762 struct mac_info *mac_control; 800 struct mac_info *mac_control;
763 struct config_param *config; 801 struct config_param *config;
764 int lst_size, lst_per_page; 802 int lst_size, lst_per_page;
765 struct net_device *dev = nic->dev; 803 struct net_device *dev = nic->dev;
804 int page_num = 0;
766 805
767 if (!nic) 806 if (!nic)
768 return; 807 return;
@@ -774,8 +813,9 @@ static void free_shared_mem(struct s2io_nic *nic)
774 lst_per_page = PAGE_SIZE / lst_size; 813 lst_per_page = PAGE_SIZE / lst_size;
775 814
776 for (i = 0; i < config->tx_fifo_num; i++) { 815 for (i = 0; i < config->tx_fifo_num; i++) {
777 int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len, 816 ufo_size += config->tx_cfg[i].fifo_len;
778 lst_per_page); 817 page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
818 lst_per_page);
779 for (j = 0; j < page_num; j++) { 819 for (j = 0; j < page_num; j++) {
780 int mem_blks = (j * lst_per_page); 820 int mem_blks = (j * lst_per_page);
781 if (!mac_control->fifos[i].list_info) 821 if (!mac_control->fifos[i].list_info)
@@ -790,6 +830,8 @@ static void free_shared_mem(struct s2io_nic *nic)
790 mac_control->fifos[i]. 830 mac_control->fifos[i].
791 list_info[mem_blks]. 831 list_info[mem_blks].
792 list_phy_addr); 832 list_phy_addr);
833 nic->mac_control.stats_info->sw_stat.mem_freed
834 += PAGE_SIZE;
793 } 835 }
794 /* If we got a zero DMA address during allocation, 836 /* If we got a zero DMA address during allocation,
795 * free the page now 837 * free the page now
@@ -803,8 +845,12 @@ static void free_shared_mem(struct s2io_nic *nic)
803 dev->name); 845 dev->name);
804 DBG_PRINT(INIT_DBG, "Virtual address %p\n", 846 DBG_PRINT(INIT_DBG, "Virtual address %p\n",
805 mac_control->zerodma_virt_addr); 847 mac_control->zerodma_virt_addr);
848 nic->mac_control.stats_info->sw_stat.mem_freed
849 += PAGE_SIZE;
806 } 850 }
807 kfree(mac_control->fifos[i].list_info); 851 kfree(mac_control->fifos[i].list_info);
852 nic->mac_control.stats_info->sw_stat.mem_freed +=
853 (nic->config.tx_cfg[i].fifo_len *sizeof(struct list_info_hold));
808 } 854 }
809 855
810 size = SIZE_OF_BLOCK; 856 size = SIZE_OF_BLOCK;
@@ -819,7 +865,10 @@ static void free_shared_mem(struct s2io_nic *nic)
819 break; 865 break;
820 pci_free_consistent(nic->pdev, size, 866 pci_free_consistent(nic->pdev, size,
821 tmp_v_addr, tmp_p_addr); 867 tmp_v_addr, tmp_p_addr);
868 nic->mac_control.stats_info->sw_stat.mem_freed += size;
822 kfree(mac_control->rings[i].rx_blocks[j].rxds); 869 kfree(mac_control->rings[i].rx_blocks[j].rxds);
870 nic->mac_control.stats_info->sw_stat.mem_freed +=
871 ( sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
823 } 872 }
824 } 873 }
825 874
@@ -836,12 +885,20 @@ static void free_shared_mem(struct s2io_nic *nic)
836 struct buffAdd *ba = 885 struct buffAdd *ba =
837 &mac_control->rings[i].ba[j][k]; 886 &mac_control->rings[i].ba[j][k];
838 kfree(ba->ba_0_org); 887 kfree(ba->ba_0_org);
888 nic->mac_control.stats_info->sw_stat.\
889 mem_freed += (BUF0_LEN + ALIGN_SIZE);
839 kfree(ba->ba_1_org); 890 kfree(ba->ba_1_org);
891 nic->mac_control.stats_info->sw_stat.\
892 mem_freed += (BUF1_LEN + ALIGN_SIZE);
840 k++; 893 k++;
841 } 894 }
842 kfree(mac_control->rings[i].ba[j]); 895 kfree(mac_control->rings[i].ba[j]);
896 nic->mac_control.stats_info->sw_stat.mem_freed += (sizeof(struct buffAdd) *
897 (rxd_count[nic->rxd_mode] + 1));
843 } 898 }
844 kfree(mac_control->rings[i].ba); 899 kfree(mac_control->rings[i].ba);
900 nic->mac_control.stats_info->sw_stat.mem_freed +=
901 (sizeof(struct buffAdd *) * blk_cnt);
845 } 902 }
846 } 903 }
847 904
@@ -850,9 +907,14 @@ static void free_shared_mem(struct s2io_nic *nic)
850 mac_control->stats_mem_sz, 907 mac_control->stats_mem_sz,
851 mac_control->stats_mem, 908 mac_control->stats_mem,
852 mac_control->stats_mem_phy); 909 mac_control->stats_mem_phy);
910 nic->mac_control.stats_info->sw_stat.mem_freed +=
911 mac_control->stats_mem_sz;
853 } 912 }
854 if (nic->ufo_in_band_v) 913 if (nic->ufo_in_band_v) {
855 kfree(nic->ufo_in_band_v); 914 kfree(nic->ufo_in_band_v);
915 nic->mac_control.stats_info->sw_stat.mem_freed
916 += (ufo_size * sizeof(u64));
917 }
856} 918}
857 919
858/** 920/**
@@ -2122,10 +2184,12 @@ static void free_tx_buffers(struct s2io_nic *nic)
2122 2184
2123 for (i = 0; i < config->tx_fifo_num; i++) { 2185 for (i = 0; i < config->tx_fifo_num; i++) {
2124 for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) { 2186 for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) {
2125 txdp = (struct TxD *) mac_control->fifos[i].list_info[j]. 2187 txdp = (struct TxD *) \
2126 list_virt_addr; 2188 mac_control->fifos[i].list_info[j].list_virt_addr;
2127 skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j); 2189 skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
2128 if (skb) { 2190 if (skb) {
2191 nic->mac_control.stats_info->sw_stat.mem_freed
2192 += skb->truesize;
2129 dev_kfree_skb(skb); 2193 dev_kfree_skb(skb);
2130 cnt++; 2194 cnt++;
2131 } 2195 }
@@ -2186,11 +2250,14 @@ static int fill_rxd_3buf(struct s2io_nic *nic, struct RxD_t *rxdp, struct \
2186 /* skb_shinfo(skb)->frag_list will have L4 data payload */ 2250 /* skb_shinfo(skb)->frag_list will have L4 data payload */
2187 skb_shinfo(skb)->frag_list = dev_alloc_skb(dev->mtu + ALIGN_SIZE); 2251 skb_shinfo(skb)->frag_list = dev_alloc_skb(dev->mtu + ALIGN_SIZE);
2188 if (skb_shinfo(skb)->frag_list == NULL) { 2252 if (skb_shinfo(skb)->frag_list == NULL) {
2253 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
2189 DBG_PRINT(INFO_DBG, "%s: dev_alloc_skb failed\n ", dev->name); 2254 DBG_PRINT(INFO_DBG, "%s: dev_alloc_skb failed\n ", dev->name);
2190 return -ENOMEM ; 2255 return -ENOMEM ;
2191 } 2256 }
2192 frag_list = skb_shinfo(skb)->frag_list; 2257 frag_list = skb_shinfo(skb)->frag_list;
2193 skb->truesize += frag_list->truesize; 2258 skb->truesize += frag_list->truesize;
2259 nic->mac_control.stats_info->sw_stat.mem_allocated
2260 += frag_list->truesize;
2194 frag_list->next = NULL; 2261 frag_list->next = NULL;
2195 tmp = (void *)ALIGN((long)frag_list->data, ALIGN_SIZE + 1); 2262 tmp = (void *)ALIGN((long)frag_list->data, ALIGN_SIZE + 1);
2196 frag_list->data = tmp; 2263 frag_list->data = tmp;
@@ -2319,8 +2386,12 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2319 wmb(); 2386 wmb();
2320 first_rxdp->Control_1 |= RXD_OWN_XENA; 2387 first_rxdp->Control_1 |= RXD_OWN_XENA;
2321 } 2388 }
2389 nic->mac_control.stats_info->sw_stat. \
2390 mem_alloc_fail_cnt++;
2322 return -ENOMEM ; 2391 return -ENOMEM ;
2323 } 2392 }
2393 nic->mac_control.stats_info->sw_stat.mem_allocated
2394 += skb->truesize;
2324 if (nic->rxd_mode == RXD_MODE_1) { 2395 if (nic->rxd_mode == RXD_MODE_1) {
2325 /* 1 buffer mode - normal operation mode */ 2396 /* 1 buffer mode - normal operation mode */
2326 memset(rxdp, 0, sizeof(struct RxD1)); 2397 memset(rxdp, 0, sizeof(struct RxD1));
@@ -2328,7 +2399,8 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2328 ((struct RxD1*)rxdp)->Buffer0_ptr = pci_map_single 2399 ((struct RxD1*)rxdp)->Buffer0_ptr = pci_map_single
2329 (nic->pdev, skb->data, size - NET_IP_ALIGN, 2400 (nic->pdev, skb->data, size - NET_IP_ALIGN,
2330 PCI_DMA_FROMDEVICE); 2401 PCI_DMA_FROMDEVICE);
2331 rxdp->Control_2 = SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN); 2402 rxdp->Control_2 =
2403 SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
2332 2404
2333 } else if (nic->rxd_mode >= RXD_MODE_3A) { 2405 } else if (nic->rxd_mode >= RXD_MODE_3A) {
2334 /* 2406 /*
@@ -2342,7 +2414,7 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2342 * payload 2414 * payload
2343 */ 2415 */
2344 2416
2345 /* save the buffer pointers to avoid frequent dma mapping */ 2417 /* save buffer pointers to avoid frequent dma mapping */
2346 Buffer0_ptr = ((struct RxD3*)rxdp)->Buffer0_ptr; 2418 Buffer0_ptr = ((struct RxD3*)rxdp)->Buffer0_ptr;
2347 Buffer1_ptr = ((struct RxD3*)rxdp)->Buffer1_ptr; 2419 Buffer1_ptr = ((struct RxD3*)rxdp)->Buffer1_ptr;
2348 memset(rxdp, 0, sizeof(struct RxD3)); 2420 memset(rxdp, 0, sizeof(struct RxD3));
@@ -2364,7 +2436,7 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2364 PCI_DMA_FROMDEVICE); 2436 PCI_DMA_FROMDEVICE);
2365 else 2437 else
2366 pci_dma_sync_single_for_device(nic->pdev, 2438 pci_dma_sync_single_for_device(nic->pdev,
2367 (dma_addr_t) ((struct RxD3*)rxdp)->Buffer0_ptr, 2439 (dma_addr_t) ((struct RxD3*)rxdp)->Buffer0_ptr,
2368 BUF0_LEN, PCI_DMA_FROMDEVICE); 2440 BUF0_LEN, PCI_DMA_FROMDEVICE);
2369 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN); 2441 rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
2370 if (nic->rxd_mode == RXD_MODE_3B) { 2442 if (nic->rxd_mode == RXD_MODE_3B) {
@@ -2391,6 +2463,8 @@ static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
2391 } else { 2463 } else {
2392 /* 3 buffer mode */ 2464 /* 3 buffer mode */
2393 if (fill_rxd_3buf(nic, rxdp, skb) == -ENOMEM) { 2465 if (fill_rxd_3buf(nic, rxdp, skb) == -ENOMEM) {
2466 nic->mac_control.stats_info->sw_stat.\
2467 mem_freed += skb->truesize;
2394 dev_kfree_skb_irq(skb); 2468 dev_kfree_skb_irq(skb);
2395 if (first_rxdp) { 2469 if (first_rxdp) {
2396 wmb(); 2470 wmb();
@@ -2491,6 +2565,7 @@ static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
2491 PCI_DMA_FROMDEVICE); 2565 PCI_DMA_FROMDEVICE);
2492 memset(rxdp, 0, sizeof(struct RxD3)); 2566 memset(rxdp, 0, sizeof(struct RxD3));
2493 } 2567 }
2568 sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
2494 dev_kfree_skb(skb); 2569 dev_kfree_skb(skb);
2495 atomic_dec(&sp->rx_bufs_left[ring_no]); 2570 atomic_dec(&sp->rx_bufs_left[ring_no]);
2496 } 2571 }
@@ -2820,13 +2895,35 @@ static void tx_intr_handler(struct fifo_info *fifo_data)
2820 nic->mac_control.stats_info->sw_stat. 2895 nic->mac_control.stats_info->sw_stat.
2821 parity_err_cnt++; 2896 parity_err_cnt++;
2822 } 2897 }
2823 if ((err >> 48) == 0xA) { 2898
2824 DBG_PRINT(TX_DBG, "TxD returned due \ 2899 /* update t_code statistics */
2825 to loss of link\n"); 2900 err >>= 48;
2826 } 2901 switch(err) {
2827 else { 2902 case 2:
2828 DBG_PRINT(ERR_DBG, "***TxD error %llx\n", err); 2903 nic->mac_control.stats_info->sw_stat.
2829 } 2904 tx_buf_abort_cnt++;
2905 break;
2906
2907 case 3:
2908 nic->mac_control.stats_info->sw_stat.
2909 tx_desc_abort_cnt++;
2910 break;
2911
2912 case 7:
2913 nic->mac_control.stats_info->sw_stat.
2914 tx_parity_err_cnt++;
2915 break;
2916
2917 case 10:
2918 nic->mac_control.stats_info->sw_stat.
2919 tx_link_loss_cnt++;
2920 break;
2921
2922 case 15:
2923 nic->mac_control.stats_info->sw_stat.
2924 tx_list_proc_err_cnt++;
2925 break;
2926 }
2830 } 2927 }
2831 2928
2832 skb = s2io_txdl_getskb(fifo_data, txdlp, get_info.offset); 2929 skb = s2io_txdl_getskb(fifo_data, txdlp, get_info.offset);
@@ -2839,6 +2936,7 @@ static void tx_intr_handler(struct fifo_info *fifo_data)
2839 2936
2840 /* Updating the statistics block */ 2937 /* Updating the statistics block */
2841 nic->stats.tx_bytes += skb->len; 2938 nic->stats.tx_bytes += skb->len;
2939 nic->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
2842 dev_kfree_skb_irq(skb); 2940 dev_kfree_skb_irq(skb);
2843 2941
2844 get_info.offset++; 2942 get_info.offset++;
@@ -3314,7 +3412,9 @@ static void s2io_reset(struct s2io_nic * sp)
3314 u16 subid, pci_cmd; 3412 u16 subid, pci_cmd;
3315 int i; 3413 int i;
3316 u16 val16; 3414 u16 val16;
3317 unsigned long long reset_cnt = 0; 3415 unsigned long long up_cnt, down_cnt, up_time, down_time, reset_cnt;
3416 unsigned long long mem_alloc_cnt, mem_free_cnt, watchdog_cnt;
3417
3318 DBG_PRINT(INIT_DBG,"%s - Resetting XFrame card %s\n", 3418 DBG_PRINT(INIT_DBG,"%s - Resetting XFrame card %s\n",
3319 __FUNCTION__, sp->dev->name); 3419 __FUNCTION__, sp->dev->name);
3320 3420
@@ -3380,11 +3480,26 @@ new_way:
3380 3480
3381 /* Reset device statistics maintained by OS */ 3481 /* Reset device statistics maintained by OS */
3382 memset(&sp->stats, 0, sizeof (struct net_device_stats)); 3482 memset(&sp->stats, 0, sizeof (struct net_device_stats));
3383 /* save reset count */ 3483
3484 up_cnt = sp->mac_control.stats_info->sw_stat.link_up_cnt;
3485 down_cnt = sp->mac_control.stats_info->sw_stat.link_down_cnt;
3486 up_time = sp->mac_control.stats_info->sw_stat.link_up_time;
3487 down_time = sp->mac_control.stats_info->sw_stat.link_down_time;
3384 reset_cnt = sp->mac_control.stats_info->sw_stat.soft_reset_cnt; 3488 reset_cnt = sp->mac_control.stats_info->sw_stat.soft_reset_cnt;
3489 mem_alloc_cnt = sp->mac_control.stats_info->sw_stat.mem_allocated;
3490 mem_free_cnt = sp->mac_control.stats_info->sw_stat.mem_freed;
3491 watchdog_cnt = sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt;
3492 /* save link up/down time/cnt, reset/memory/watchdog cnt */
3385 memset(sp->mac_control.stats_info, 0, sizeof(struct stat_block)); 3493 memset(sp->mac_control.stats_info, 0, sizeof(struct stat_block));
3386 /* restore reset count */ 3494 /* restore link up/down time/cnt, reset/memory/watchdog cnt */
3495 sp->mac_control.stats_info->sw_stat.link_up_cnt = up_cnt;
3496 sp->mac_control.stats_info->sw_stat.link_down_cnt = down_cnt;
3497 sp->mac_control.stats_info->sw_stat.link_up_time = up_time;
3498 sp->mac_control.stats_info->sw_stat.link_down_time = down_time;
3387 sp->mac_control.stats_info->sw_stat.soft_reset_cnt = reset_cnt; 3499 sp->mac_control.stats_info->sw_stat.soft_reset_cnt = reset_cnt;
3500 sp->mac_control.stats_info->sw_stat.mem_allocated = mem_alloc_cnt;
3501 sp->mac_control.stats_info->sw_stat.mem_freed = mem_free_cnt;
3502 sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt = watchdog_cnt;
3388 3503
3389 /* SXE-002: Configure link and activity LED to turn it off */ 3504 /* SXE-002: Configure link and activity LED to turn it off */
3390 subid = sp->pdev->subsystem_device; 3505 subid = sp->pdev->subsystem_device;
@@ -3672,19 +3787,29 @@ static int s2io_enable_msi_x(struct s2io_nic *nic)
3672 nic->entries = kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct msix_entry), 3787 nic->entries = kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct msix_entry),
3673 GFP_KERNEL); 3788 GFP_KERNEL);
3674 if (nic->entries == NULL) { 3789 if (nic->entries == NULL) {
3675 DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", __FUNCTION__); 3790 DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", \
3791 __FUNCTION__);
3792 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
3676 return -ENOMEM; 3793 return -ENOMEM;
3677 } 3794 }
3678 memset(nic->entries, 0, MAX_REQUESTED_MSI_X * sizeof(struct msix_entry)); 3795 nic->mac_control.stats_info->sw_stat.mem_allocated
3796 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3797 memset(nic->entries, 0,MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3679 3798
3680 nic->s2io_entries = 3799 nic->s2io_entries =
3681 kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry), 3800 kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry),
3682 GFP_KERNEL); 3801 GFP_KERNEL);
3683 if (nic->s2io_entries == NULL) { 3802 if (nic->s2io_entries == NULL) {
3684 DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", __FUNCTION__); 3803 DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n",
3804 __FUNCTION__);
3805 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
3685 kfree(nic->entries); 3806 kfree(nic->entries);
3807 nic->mac_control.stats_info->sw_stat.mem_freed
3808 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3686 return -ENOMEM; 3809 return -ENOMEM;
3687 } 3810 }
3811 nic->mac_control.stats_info->sw_stat.mem_allocated
3812 += (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
3688 memset(nic->s2io_entries, 0, 3813 memset(nic->s2io_entries, 0,
3689 MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry)); 3814 MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
3690 3815
@@ -3708,7 +3833,8 @@ static int s2io_enable_msi_x(struct s2io_nic *nic)
3708 rx_mat = readq(&bar0->rx_mat); 3833 rx_mat = readq(&bar0->rx_mat);
3709 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) { 3834 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3710 rx_mat |= RX_MAT_SET(j, msix_indx); 3835 rx_mat |= RX_MAT_SET(j, msix_indx);
3711 nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j]; 3836 nic->s2io_entries[msix_indx].arg
3837 = &nic->mac_control.rings[j];
3712 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE; 3838 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3713 nic->s2io_entries[msix_indx].in_use = MSIX_FLG; 3839 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3714 } 3840 }
@@ -3717,7 +3843,8 @@ static int s2io_enable_msi_x(struct s2io_nic *nic)
3717 tx_mat = readq(&bar0->tx_mat0_n[7]); 3843 tx_mat = readq(&bar0->tx_mat0_n[7]);
3718 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) { 3844 for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
3719 tx_mat |= TX_MAT_SET(i, msix_indx); 3845 tx_mat |= TX_MAT_SET(i, msix_indx);
3720 nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j]; 3846 nic->s2io_entries[msix_indx].arg
3847 = &nic->mac_control.rings[j];
3721 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE; 3848 nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
3722 nic->s2io_entries[msix_indx].in_use = MSIX_FLG; 3849 nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
3723 } 3850 }
@@ -3734,7 +3861,11 @@ static int s2io_enable_msi_x(struct s2io_nic *nic)
3734 if (ret) { 3861 if (ret) {
3735 DBG_PRINT(ERR_DBG, "%s: Enabling MSIX failed\n", nic->dev->name); 3862 DBG_PRINT(ERR_DBG, "%s: Enabling MSIX failed\n", nic->dev->name);
3736 kfree(nic->entries); 3863 kfree(nic->entries);
3864 nic->mac_control.stats_info->sw_stat.mem_freed
3865 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3737 kfree(nic->s2io_entries); 3866 kfree(nic->s2io_entries);
3867 nic->mac_control.stats_info->sw_stat.mem_freed
3868 += (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
3738 nic->entries = NULL; 3869 nic->entries = NULL;
3739 nic->s2io_entries = NULL; 3870 nic->s2io_entries = NULL;
3740 nic->avail_msix_vectors = 0; 3871 nic->avail_msix_vectors = 0;
@@ -3802,10 +3933,16 @@ static int s2io_open(struct net_device *dev)
3802 3933
3803hw_init_failed: 3934hw_init_failed:
3804 if (sp->intr_type == MSI_X) { 3935 if (sp->intr_type == MSI_X) {
3805 if (sp->entries) 3936 if (sp->entries) {
3806 kfree(sp->entries); 3937 kfree(sp->entries);
3807 if (sp->s2io_entries) 3938 sp->mac_control.stats_info->sw_stat.mem_freed
3939 += (MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
3940 }
3941 if (sp->s2io_entries) {
3808 kfree(sp->s2io_entries); 3942 kfree(sp->s2io_entries);
3943 sp->mac_control.stats_info->sw_stat.mem_freed
3944 += (MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
3945 }
3809 } 3946 }
3810 return err; 3947 return err;
3811} 3948}
@@ -3866,6 +4003,13 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
3866 config = &sp->config; 4003 config = &sp->config;
3867 4004
3868 DBG_PRINT(TX_DBG, "%s: In Neterion Tx routine\n", dev->name); 4005 DBG_PRINT(TX_DBG, "%s: In Neterion Tx routine\n", dev->name);
4006
4007 if (unlikely(skb->len <= 0)) {
4008 DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name);
4009 dev_kfree_skb_any(skb);
4010 return 0;
4011}
4012
3869 spin_lock_irqsave(&sp->tx_lock, flags); 4013 spin_lock_irqsave(&sp->tx_lock, flags);
3870 if (atomic_read(&sp->card_state) == CARD_DOWN) { 4014 if (atomic_read(&sp->card_state) == CARD_DOWN) {
3871 DBG_PRINT(TX_DBG, "%s: Card going down for reset\n", 4015 DBG_PRINT(TX_DBG, "%s: Card going down for reset\n",
@@ -3876,7 +4020,6 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
3876 } 4020 }
3877 4021
3878 queue = 0; 4022 queue = 0;
3879
3880 /* Get Fifo number to Transmit based on vlan priority */ 4023 /* Get Fifo number to Transmit based on vlan priority */
3881 if (sp->vlgrp && vlan_tx_tag_present(skb)) { 4024 if (sp->vlgrp && vlan_tx_tag_present(skb)) {
3882 vlan_tag = vlan_tx_tag_get(skb); 4025 vlan_tag = vlan_tx_tag_get(skb);
@@ -3900,14 +4043,6 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
3900 return 0; 4043 return 0;
3901 } 4044 }
3902 4045
3903 /* A buffer with no data will be dropped */
3904 if (!skb->len) {
3905 DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name);
3906 dev_kfree_skb(skb);
3907 spin_unlock_irqrestore(&sp->tx_lock, flags);
3908 return 0;
3909 }
3910
3911 offload_type = s2io_offload_type(skb); 4046 offload_type = s2io_offload_type(skb);
3912 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) { 4047 if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
3913 txdp->Control_1 |= TXD_TCP_LSO_EN; 4048 txdp->Control_1 |= TXD_TCP_LSO_EN;
@@ -4003,7 +4138,7 @@ static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
4003 put_off, get_off); 4138 put_off, get_off);
4004 netif_stop_queue(dev); 4139 netif_stop_queue(dev);
4005 } 4140 }
4006 4141 mac_control->stats_info->sw_stat.mem_allocated += skb->truesize;
4007 dev->trans_start = jiffies; 4142 dev->trans_start = jiffies;
4008 spin_unlock_irqrestore(&sp->tx_lock, flags); 4143 spin_unlock_irqrestore(&sp->tx_lock, flags);
4009 4144
@@ -4775,6 +4910,40 @@ static int s2io_ethtool_idnic(struct net_device *dev, u32 data)
4775 return 0; 4910 return 0;
4776} 4911}
4777 4912
4913static void s2io_ethtool_gringparam(struct net_device *dev,
4914 struct ethtool_ringparam *ering)
4915{
4916 struct s2io_nic *sp = dev->priv;
4917 int i,tx_desc_count=0,rx_desc_count=0;
4918
4919 if (sp->rxd_mode == RXD_MODE_1)
4920 ering->rx_max_pending = MAX_RX_DESC_1;
4921 else if (sp->rxd_mode == RXD_MODE_3B)
4922 ering->rx_max_pending = MAX_RX_DESC_2;
4923 else if (sp->rxd_mode == RXD_MODE_3A)
4924 ering->rx_max_pending = MAX_RX_DESC_3;
4925
4926 ering->tx_max_pending = MAX_TX_DESC;
4927 for (i = 0 ; i < sp->config.tx_fifo_num ; i++) {
4928 tx_desc_count += sp->config.tx_cfg[i].fifo_len;
4929 }
4930 DBG_PRINT(INFO_DBG,"\nmax txds : %d\n",sp->config.max_txds);
4931 ering->tx_pending = tx_desc_count;
4932 rx_desc_count = 0;
4933 for (i = 0 ; i < sp->config.rx_ring_num ; i++) {
4934 rx_desc_count += sp->config.rx_cfg[i].num_rxd;
4935 }
4936 ering->rx_pending = rx_desc_count;
4937
4938 ering->rx_mini_max_pending = 0;
4939 ering->rx_mini_pending = 0;
4940 if(sp->rxd_mode == RXD_MODE_1)
4941 ering->rx_jumbo_max_pending = MAX_RX_DESC_1;
4942 else if (sp->rxd_mode == RXD_MODE_3B)
4943 ering->rx_jumbo_max_pending = MAX_RX_DESC_2;
4944 ering->rx_jumbo_pending = rx_desc_count;
4945}
4946
4778/** 4947/**
4779 * s2io_ethtool_getpause_data -Pause frame frame generation and reception. 4948 * s2io_ethtool_getpause_data -Pause frame frame generation and reception.
4780 * @sp : private member of the device structure, which is a pointer to the 4949 * @sp : private member of the device structure, which is a pointer to the
@@ -4981,8 +5150,11 @@ static void s2io_vpd_read(struct s2io_nic *nic)
4981 strcpy(nic->serial_num, "NOT AVAILABLE"); 5150 strcpy(nic->serial_num, "NOT AVAILABLE");
4982 5151
4983 vpd_data = kmalloc(256, GFP_KERNEL); 5152 vpd_data = kmalloc(256, GFP_KERNEL);
4984 if (!vpd_data) 5153 if (!vpd_data) {
5154 nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
4985 return; 5155 return;
5156 }
5157 nic->mac_control.stats_info->sw_stat.mem_allocated += 256;
4986 5158
4987 for (i = 0; i < 256; i +=4 ) { 5159 for (i = 0; i < 256; i +=4 ) {
4988 pci_write_config_byte(nic->pdev, (vpd_addr + 2), i); 5160 pci_write_config_byte(nic->pdev, (vpd_addr + 2), i);
@@ -5022,6 +5194,7 @@ static void s2io_vpd_read(struct s2io_nic *nic)
5022 memcpy(nic->product_name, &vpd_data[3], vpd_data[1]); 5194 memcpy(nic->product_name, &vpd_data[3], vpd_data[1]);
5023 } 5195 }
5024 kfree(vpd_data); 5196 kfree(vpd_data);
5197 nic->mac_control.stats_info->sw_stat.mem_freed += 256;
5025} 5198}
5026 5199
5027/** 5200/**
@@ -5742,6 +5915,30 @@ static void s2io_get_ethtool_stats(struct net_device *dev,
5742 } 5915 }
5743 else 5916 else
5744 tmp_stats[i++] = 0; 5917 tmp_stats[i++] = 0;
5918 tmp_stats[i++] = stat_info->sw_stat.mem_alloc_fail_cnt;
5919 tmp_stats[i++] = stat_info->sw_stat.watchdog_timer_cnt;
5920 tmp_stats[i++] = stat_info->sw_stat.mem_allocated;
5921 tmp_stats[i++] = stat_info->sw_stat.mem_freed;
5922 tmp_stats[i++] = stat_info->sw_stat.link_up_cnt;
5923 tmp_stats[i++] = stat_info->sw_stat.link_down_cnt;
5924 tmp_stats[i++] = stat_info->sw_stat.link_up_time;
5925 tmp_stats[i++] = stat_info->sw_stat.link_down_time;
5926
5927 tmp_stats[i++] = stat_info->sw_stat.tx_buf_abort_cnt;
5928 tmp_stats[i++] = stat_info->sw_stat.tx_desc_abort_cnt;
5929 tmp_stats[i++] = stat_info->sw_stat.tx_parity_err_cnt;
5930 tmp_stats[i++] = stat_info->sw_stat.tx_link_loss_cnt;
5931 tmp_stats[i++] = stat_info->sw_stat.tx_list_proc_err_cnt;
5932
5933 tmp_stats[i++] = stat_info->sw_stat.rx_parity_err_cnt;
5934 tmp_stats[i++] = stat_info->sw_stat.rx_abort_cnt;
5935 tmp_stats[i++] = stat_info->sw_stat.rx_parity_abort_cnt;
5936 tmp_stats[i++] = stat_info->sw_stat.rx_rda_fail_cnt;
5937 tmp_stats[i++] = stat_info->sw_stat.rx_unkn_prot_cnt;
5938 tmp_stats[i++] = stat_info->sw_stat.rx_fcs_err_cnt;
5939 tmp_stats[i++] = stat_info->sw_stat.rx_buf_size_err_cnt;
5940 tmp_stats[i++] = stat_info->sw_stat.rx_rxd_corrupt_cnt;
5941 tmp_stats[i++] = stat_info->sw_stat.rx_unkn_err_cnt;
5745} 5942}
5746 5943
5747static int s2io_ethtool_get_regs_len(struct net_device *dev) 5944static int s2io_ethtool_get_regs_len(struct net_device *dev)
@@ -5854,6 +6051,7 @@ static const struct ethtool_ops netdev_ethtool_ops = {
5854 .get_eeprom_len = s2io_get_eeprom_len, 6051 .get_eeprom_len = s2io_get_eeprom_len,
5855 .get_eeprom = s2io_ethtool_geeprom, 6052 .get_eeprom = s2io_ethtool_geeprom,
5856 .set_eeprom = s2io_ethtool_seeprom, 6053 .set_eeprom = s2io_ethtool_seeprom,
6054 .get_ringparam = s2io_ethtool_gringparam,
5857 .get_pauseparam = s2io_ethtool_getpause_data, 6055 .get_pauseparam = s2io_ethtool_getpause_data,
5858 .set_pauseparam = s2io_ethtool_setpause_data, 6056 .set_pauseparam = s2io_ethtool_setpause_data,
5859 .get_rx_csum = s2io_ethtool_get_rx_csum, 6057 .get_rx_csum = s2io_ethtool_get_rx_csum,
@@ -5962,7 +6160,7 @@ static void s2io_tasklet(unsigned long dev_addr)
5962 if (ret == -ENOMEM) { 6160 if (ret == -ENOMEM) {
5963 DBG_PRINT(INFO_DBG, "%s: Out of ", 6161 DBG_PRINT(INFO_DBG, "%s: Out of ",
5964 dev->name); 6162 dev->name);
5965 DBG_PRINT(ERR_DBG, "memory in tasklet\n"); 6163 DBG_PRINT(INFO_DBG, "memory in tasklet\n");
5966 break; 6164 break;
5967 } else if (ret == -EFILL) { 6165 } else if (ret == -EFILL) {
5968 DBG_PRINT(INFO_DBG, 6166 DBG_PRINT(INFO_DBG,
@@ -6077,9 +6275,14 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
6077 *skb = dev_alloc_skb(size); 6275 *skb = dev_alloc_skb(size);
6078 if (!(*skb)) { 6276 if (!(*skb)) {
6079 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name); 6277 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
6080 DBG_PRINT(INFO_DBG, "memory to allocate SKBs\n"); 6278 DBG_PRINT(INFO_DBG, "memory to allocate ");
6279 DBG_PRINT(INFO_DBG, "1 buf mode SKBs\n");
6280 sp->mac_control.stats_info->sw_stat. \
6281 mem_alloc_fail_cnt++;
6081 return -ENOMEM ; 6282 return -ENOMEM ;
6082 } 6283 }
6284 sp->mac_control.stats_info->sw_stat.mem_allocated
6285 += (*skb)->truesize;
6083 /* storing the mapped addr in a temp variable 6286 /* storing the mapped addr in a temp variable
6084 * such it will be used for next rxd whose 6287 * such it will be used for next rxd whose
6085 * Host Control is NULL 6288 * Host Control is NULL
@@ -6099,10 +6302,15 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
6099 } else { 6302 } else {
6100 *skb = dev_alloc_skb(size); 6303 *skb = dev_alloc_skb(size);
6101 if (!(*skb)) { 6304 if (!(*skb)) {
6102 DBG_PRINT(INFO_DBG, "%s: dev_alloc_skb failed\n", 6305 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
6103 dev->name); 6306 DBG_PRINT(INFO_DBG, "memory to allocate ");
6307 DBG_PRINT(INFO_DBG, "2 buf mode SKBs\n");
6308 sp->mac_control.stats_info->sw_stat. \
6309 mem_alloc_fail_cnt++;
6104 return -ENOMEM; 6310 return -ENOMEM;
6105 } 6311 }
6312 sp->mac_control.stats_info->sw_stat.mem_allocated
6313 += (*skb)->truesize;
6106 ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2 = 6314 ((struct RxD3*)rxdp)->Buffer2_ptr = *temp2 =
6107 pci_map_single(sp->pdev, (*skb)->data, 6315 pci_map_single(sp->pdev, (*skb)->data,
6108 dev->mtu + 4, 6316 dev->mtu + 4,
@@ -6126,10 +6334,15 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
6126 } else { 6334 } else {
6127 *skb = dev_alloc_skb(size); 6335 *skb = dev_alloc_skb(size);
6128 if (!(*skb)) { 6336 if (!(*skb)) {
6129 DBG_PRINT(INFO_DBG, "%s: dev_alloc_skb failed\n", 6337 DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
6130 dev->name); 6338 DBG_PRINT(INFO_DBG, "memory to allocate ");
6339 DBG_PRINT(INFO_DBG, "3 buf mode SKBs\n");
6340 sp->mac_control.stats_info->sw_stat. \
6341 mem_alloc_fail_cnt++;
6131 return -ENOMEM; 6342 return -ENOMEM;
6132 } 6343 }
6344 sp->mac_control.stats_info->sw_stat.mem_allocated
6345 += (*skb)->truesize;
6133 ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0 = 6346 ((struct RxD3*)rxdp)->Buffer0_ptr = *temp0 =
6134 pci_map_single(sp->pdev, ba->ba_0, BUF0_LEN, 6347 pci_map_single(sp->pdev, ba->ba_0, BUF0_LEN,
6135 PCI_DMA_FROMDEVICE); 6348 PCI_DMA_FROMDEVICE);
@@ -6147,10 +6360,14 @@ static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
6147 if (skb_shinfo(*skb)->frag_list == NULL) { 6360 if (skb_shinfo(*skb)->frag_list == NULL) {
6148 DBG_PRINT(ERR_DBG, "%s: dev_alloc_skb \ 6361 DBG_PRINT(ERR_DBG, "%s: dev_alloc_skb \
6149 failed\n ", dev->name); 6362 failed\n ", dev->name);
6363 sp->mac_control.stats_info->sw_stat. \
6364 mem_alloc_fail_cnt++;
6150 return -ENOMEM ; 6365 return -ENOMEM ;
6151 } 6366 }
6152 frag_list = skb_shinfo(*skb)->frag_list; 6367 frag_list = skb_shinfo(*skb)->frag_list;
6153 frag_list->next = NULL; 6368 frag_list->next = NULL;
6369 sp->mac_control.stats_info->sw_stat.mem_allocated
6370 += frag_list->truesize;
6154 /* 6371 /*
6155 * Buffer-2 receives L4 data payload 6372 * Buffer-2 receives L4 data payload
6156 */ 6373 */
@@ -6566,6 +6783,7 @@ static void s2io_tx_watchdog(struct net_device *dev)
6566 struct s2io_nic *sp = dev->priv; 6783 struct s2io_nic *sp = dev->priv;
6567 6784
6568 if (netif_carrier_ok(dev)) { 6785 if (netif_carrier_ok(dev)) {
6786 sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt++;
6569 schedule_work(&sp->rst_timer_task); 6787 schedule_work(&sp->rst_timer_task);
6570 sp->mac_control.stats_info->sw_stat.soft_reset_cnt++; 6788 sp->mac_control.stats_info->sw_stat.soft_reset_cnt++;
6571 } 6789 }
@@ -6606,7 +6824,53 @@ static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
6606 if (err & 0x1) { 6824 if (err & 0x1) {
6607 sp->mac_control.stats_info->sw_stat.parity_err_cnt++; 6825 sp->mac_control.stats_info->sw_stat.parity_err_cnt++;
6608 } 6826 }
6827 err >>= 48;
6828 switch(err) {
6829 case 1:
6830 sp->mac_control.stats_info->sw_stat.
6831 rx_parity_err_cnt++;
6832 break;
6609 6833
6834 case 2:
6835 sp->mac_control.stats_info->sw_stat.
6836 rx_abort_cnt++;
6837 break;
6838
6839 case 3:
6840 sp->mac_control.stats_info->sw_stat.
6841 rx_parity_abort_cnt++;
6842 break;
6843
6844 case 4:
6845 sp->mac_control.stats_info->sw_stat.
6846 rx_rda_fail_cnt++;
6847 break;
6848
6849 case 5:
6850 sp->mac_control.stats_info->sw_stat.
6851 rx_unkn_prot_cnt++;
6852 break;
6853
6854 case 6:
6855 sp->mac_control.stats_info->sw_stat.
6856 rx_fcs_err_cnt++;
6857 break;
6858
6859 case 7:
6860 sp->mac_control.stats_info->sw_stat.
6861 rx_buf_size_err_cnt++;
6862 break;
6863
6864 case 8:
6865 sp->mac_control.stats_info->sw_stat.
6866 rx_rxd_corrupt_cnt++;
6867 break;
6868
6869 case 15:
6870 sp->mac_control.stats_info->sw_stat.
6871 rx_unkn_err_cnt++;
6872 break;
6873 }
6610 /* 6874 /*
6611 * Drop the packet if bad transfer code. Exception being 6875 * Drop the packet if bad transfer code. Exception being
6612 * 0x5, which could be due to unsupported IPv6 extension header. 6876 * 0x5, which could be due to unsupported IPv6 extension header.
@@ -6614,10 +6878,12 @@ static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
6614 * Note that in this case, since checksum will be incorrect, 6878 * Note that in this case, since checksum will be incorrect,
6615 * stack will validate the same. 6879 * stack will validate the same.
6616 */ 6880 */
6617 if (err && ((err >> 48) != 0x5)) { 6881 if (err != 0x5) {
6618 DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%llx\n", 6882 DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%llx\n",
6619 dev->name, err); 6883 dev->name, err);
6620 sp->stats.rx_crc_errors++; 6884 sp->stats.rx_crc_errors++;
6885 sp->mac_control.stats_info->sw_stat.mem_freed
6886 += skb->truesize;
6621 dev_kfree_skb(skb); 6887 dev_kfree_skb(skb);
6622 atomic_dec(&sp->rx_bufs_left[ring_no]); 6888 atomic_dec(&sp->rx_bufs_left[ring_no]);
6623 rxdp->Host_Control = 0; 6889 rxdp->Host_Control = 0;
@@ -6627,7 +6893,6 @@ static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
6627 6893
6628 /* Updating statistics */ 6894 /* Updating statistics */
6629 rxdp->Host_Control = 0; 6895 rxdp->Host_Control = 0;
6630 sp->stats.rx_packets++;
6631 if (sp->rxd_mode == RXD_MODE_1) { 6896 if (sp->rxd_mode == RXD_MODE_1) {
6632 int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2); 6897 int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
6633 6898
@@ -6731,7 +6996,7 @@ static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
6731 } else { 6996 } else {
6732 skb->ip_summed = CHECKSUM_NONE; 6997 skb->ip_summed = CHECKSUM_NONE;
6733 } 6998 }
6734 6999 sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
6735 if (!sp->lro) { 7000 if (!sp->lro) {
6736 skb->protocol = eth_type_trans(skb, dev); 7001 skb->protocol = eth_type_trans(skb, dev);
6737 if ((sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2) && 7002 if ((sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2) &&
@@ -6780,12 +7045,21 @@ static void s2io_link(struct s2io_nic * sp, int link)
6780 if (link == LINK_DOWN) { 7045 if (link == LINK_DOWN) {
6781 DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name); 7046 DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
6782 netif_carrier_off(dev); 7047 netif_carrier_off(dev);
7048 if(sp->mac_control.stats_info->sw_stat.link_up_cnt)
7049 sp->mac_control.stats_info->sw_stat.link_up_time =
7050 jiffies - sp->start_time;
7051 sp->mac_control.stats_info->sw_stat.link_down_cnt++;
6783 } else { 7052 } else {
6784 DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name); 7053 DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name);
7054 if (sp->mac_control.stats_info->sw_stat.link_down_cnt)
7055 sp->mac_control.stats_info->sw_stat.link_down_time =
7056 jiffies - sp->start_time;
7057 sp->mac_control.stats_info->sw_stat.link_up_cnt++;
6785 netif_carrier_on(dev); 7058 netif_carrier_on(dev);
6786 } 7059 }
6787 } 7060 }
6788 sp->last_link_state = link; 7061 sp->last_link_state = link;
7062 sp->start_time = jiffies;
6789} 7063}
6790 7064
6791/** 7065/**
diff --git a/drivers/net/s2io.h b/drivers/net/s2io.h
index a656d18b33df..54baa0b8ec7c 100644
--- a/drivers/net/s2io.h
+++ b/drivers/net/s2io.h
@@ -95,6 +95,32 @@ struct swStat {
95 unsigned long long flush_max_pkts; 95 unsigned long long flush_max_pkts;
96 unsigned long long sum_avg_pkts_aggregated; 96 unsigned long long sum_avg_pkts_aggregated;
97 unsigned long long num_aggregations; 97 unsigned long long num_aggregations;
98 /* Other statistics */
99 unsigned long long mem_alloc_fail_cnt;
100 unsigned long long watchdog_timer_cnt;
101 unsigned long long mem_allocated;
102 unsigned long long mem_freed;
103 unsigned long long link_up_cnt;
104 unsigned long long link_down_cnt;
105 unsigned long long link_up_time;
106 unsigned long long link_down_time;
107
108 /* Transfer Code statistics */
109 unsigned long long tx_buf_abort_cnt;
110 unsigned long long tx_desc_abort_cnt;
111 unsigned long long tx_parity_err_cnt;
112 unsigned long long tx_link_loss_cnt;
113 unsigned long long tx_list_proc_err_cnt;
114
115 unsigned long long rx_parity_err_cnt;
116 unsigned long long rx_abort_cnt;
117 unsigned long long rx_parity_abort_cnt;
118 unsigned long long rx_rda_fail_cnt;
119 unsigned long long rx_unkn_prot_cnt;
120 unsigned long long rx_fcs_err_cnt;
121 unsigned long long rx_buf_size_err_cnt;
122 unsigned long long rx_rxd_corrupt_cnt;
123 unsigned long long rx_unkn_err_cnt;
98}; 124};
99 125
100/* Xpak releated alarm and warnings */ 126/* Xpak releated alarm and warnings */
@@ -308,6 +334,11 @@ struct stat_block {
308#define MAX_TX_FIFOS 8 334#define MAX_TX_FIFOS 8
309#define MAX_RX_RINGS 8 335#define MAX_RX_RINGS 8
310 336
337#define MAX_RX_DESC_1 (MAX_RX_RINGS * MAX_RX_BLOCKS_PER_RING * 127 )
338#define MAX_RX_DESC_2 (MAX_RX_RINGS * MAX_RX_BLOCKS_PER_RING * 85 )
339#define MAX_RX_DESC_3 (MAX_RX_RINGS * MAX_RX_BLOCKS_PER_RING * 85 )
340#define MAX_TX_DESC (MAX_AVAILABLE_TXDS)
341
311/* FIFO mappings for all possible number of fifos configured */ 342/* FIFO mappings for all possible number of fifos configured */
312static int fifo_map[][MAX_TX_FIFOS] = { 343static int fifo_map[][MAX_TX_FIFOS] = {
313 {0, 0, 0, 0, 0, 0, 0, 0}, 344 {0, 0, 0, 0, 0, 0, 0, 0},
@@ -819,6 +850,7 @@ struct s2io_nic {
819#define LINK_UP 2 850#define LINK_UP 2
820 851
821 int task_flag; 852 int task_flag;
853 unsigned long long start_time;
822#define CARD_DOWN 1 854#define CARD_DOWN 1
823#define CARD_UP 2 855#define CARD_UP 2
824 atomic_t card_state; 856 atomic_t card_state;
diff --git a/drivers/net/sgiseeq.c b/drivers/net/sgiseeq.c
index 1fc77300b055..2106becf6990 100644
--- a/drivers/net/sgiseeq.c
+++ b/drivers/net/sgiseeq.c
@@ -16,11 +16,13 @@
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/delay.h> 17#include <linux/delay.h>
18#include <linux/netdevice.h> 18#include <linux/netdevice.h>
19#include <linux/platform_device.h>
19#include <linux/etherdevice.h> 20#include <linux/etherdevice.h>
20#include <linux/skbuff.h> 21#include <linux/skbuff.h>
21 22
22#include <asm/sgi/hpc3.h> 23#include <asm/sgi/hpc3.h>
23#include <asm/sgi/ip22.h> 24#include <asm/sgi/ip22.h>
25#include <asm/sgi/seeq.h>
24 26
25#include "sgiseeq.h" 27#include "sgiseeq.h"
26 28
@@ -92,13 +94,9 @@ struct sgiseeq_private {
92 94
93 struct net_device_stats stats; 95 struct net_device_stats stats;
94 96
95 struct net_device *next_module;
96 spinlock_t tx_lock; 97 spinlock_t tx_lock;
97}; 98};
98 99
99/* A list of all installed seeq devices, for removing the driver module. */
100static struct net_device *root_sgiseeq_dev;
101
102static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs) 100static inline void hpc3_eth_reset(struct hpc3_ethregs *hregs)
103{ 101{
104 hregs->reset = HPC3_ERST_CRESET | HPC3_ERST_CLRIRQ; 102 hregs->reset = HPC3_ERST_CRESET | HPC3_ERST_CLRIRQ;
@@ -624,9 +622,12 @@ static inline void setup_rx_ring(struct sgiseeq_rx_desc *buf, int nbufs)
624 622
625#define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf)) 623#define ALIGNED(x) ((((unsigned long)(x)) + 0xf) & ~(0xf))
626 624
627static int sgiseeq_init(struct hpc3_regs* hpcregs, int irq, int has_eeprom) 625static int __init sgiseeq_probe(struct platform_device *pdev)
628{ 626{
627 struct sgiseeq_platform_data *pd = pdev->dev.platform_data;
628 struct hpc3_regs *hpcregs = pd->hpc;
629 struct sgiseeq_init_block *sr; 629 struct sgiseeq_init_block *sr;
630 unsigned int irq = pd->irq;
630 struct sgiseeq_private *sp; 631 struct sgiseeq_private *sp;
631 struct net_device *dev; 632 struct net_device *dev;
632 int err, i; 633 int err, i;
@@ -637,6 +638,8 @@ static int sgiseeq_init(struct hpc3_regs* hpcregs, int irq, int has_eeprom)
637 err = -ENOMEM; 638 err = -ENOMEM;
638 goto err_out; 639 goto err_out;
639 } 640 }
641
642 platform_set_drvdata(pdev, dev);
640 sp = netdev_priv(dev); 643 sp = netdev_priv(dev);
641 644
642 /* Make private data page aligned */ 645 /* Make private data page aligned */
@@ -648,15 +651,7 @@ static int sgiseeq_init(struct hpc3_regs* hpcregs, int irq, int has_eeprom)
648 } 651 }
649 sp->srings = sr; 652 sp->srings = sr;
650 653
651#define EADDR_NVOFS 250 654 memcpy(dev->dev_addr, pd->mac, ETH_ALEN);
652 for (i = 0; i < 3; i++) {
653 unsigned short tmp = has_eeprom ?
654 ip22_eeprom_read(&hpcregs->eeprom, EADDR_NVOFS / 2+i) :
655 ip22_nvram_read(EADDR_NVOFS / 2+i);
656
657 dev->dev_addr[2 * i] = tmp >> 8;
658 dev->dev_addr[2 * i + 1] = tmp & 0xff;
659 }
660 655
661#ifdef DEBUG 656#ifdef DEBUG
662 gpriv = sp; 657 gpriv = sp;
@@ -720,9 +715,6 @@ static int sgiseeq_init(struct hpc3_regs* hpcregs, int irq, int has_eeprom)
720 for (i = 0; i < 6; i++) 715 for (i = 0; i < 6; i++)
721 printk("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':'); 716 printk("%2.2x%c", dev->dev_addr[i], i == 5 ? '\n' : ':');
722 717
723 sp->next_module = root_sgiseeq_dev;
724 root_sgiseeq_dev = dev;
725
726 return 0; 718 return 0;
727 719
728err_out_free_page: 720err_out_free_page:
@@ -734,43 +726,42 @@ err_out:
734 return err; 726 return err;
735} 727}
736 728
737static int __init sgiseeq_probe(void) 729static void __exit sgiseeq_remove(struct platform_device *pdev)
738{ 730{
739 unsigned int tmp, ret1, ret2 = 0; 731 struct net_device *dev = platform_get_drvdata(pdev);
740 732 struct sgiseeq_private *sp = netdev_priv(dev);
741 /* On board adapter on 1st HPC is always present */
742 ret1 = sgiseeq_init(hpc3c0, SGI_ENET_IRQ, 0);
743 /* Let's see if second HPC is there */
744 if (!(ip22_is_fullhouse()) &&
745 get_dbe(tmp, (unsigned int *)&hpc3c1->pbdma[1]) == 0) {
746 sgimc->giopar |= SGIMC_GIOPAR_MASTEREXP1 |
747 SGIMC_GIOPAR_EXP164 |
748 SGIMC_GIOPAR_HPC264;
749 hpc3c1->pbus_piocfg[0][0] = 0x3ffff;
750 /* interrupt/config register on Challenge S Mezz board */
751 hpc3c1->pbus_extregs[0][0] = 0x30;
752 ret2 = sgiseeq_init(hpc3c1, SGI_GIO_0_IRQ, 1);
753 }
754 733
755 return (ret1 & ret2) ? ret1 : 0; 734 unregister_netdev(dev);
735 free_page((unsigned long) sp->srings);
736 free_netdev(dev);
737 platform_set_drvdata(pdev, NULL);
756} 738}
757 739
758static void __exit sgiseeq_exit(void) 740static struct platform_driver sgiseeq_driver = {
759{ 741 .probe = sgiseeq_probe,
760 struct net_device *next, *dev; 742 .remove = __devexit_p(sgiseeq_remove),
761 struct sgiseeq_private *sp; 743 .driver = {
744 .name = "sgiseeq"
745 }
746};
762 747
763 for (dev = root_sgiseeq_dev; dev; dev = next) { 748static int __init sgiseeq_module_init(void)
764 sp = (struct sgiseeq_private *) netdev_priv(dev); 749{
765 next = sp->next_module; 750 if (platform_driver_register(&sgiseeq_driver)) {
766 unregister_netdev(dev); 751 printk(KERN_ERR "Driver registration failed\n");
767 free_page((unsigned long) sp->srings); 752 return -ENODEV;
768 free_netdev(dev);
769 } 753 }
754
755 return 0;
756}
757
758static void __exit sgiseeq_module_exit(void)
759{
760 platform_driver_unregister(&sgiseeq_driver);
770} 761}
771 762
772module_init(sgiseeq_probe); 763module_init(sgiseeq_module_init);
773module_exit(sgiseeq_exit); 764module_exit(sgiseeq_module_exit);
774 765
775MODULE_DESCRIPTION("SGI Seeq 8003 driver"); 766MODULE_DESCRIPTION("SGI Seeq 8003 driver");
776MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>"); 767MODULE_AUTHOR("Linux/MIPS Mailing List <linux-mips@linux-mips.org>");
diff --git a/drivers/net/skge.c b/drivers/net/skge.c
index 21afe108d3cb..776692946562 100644
--- a/drivers/net/skge.c
+++ b/drivers/net/skge.c
@@ -135,10 +135,13 @@ static void skge_get_regs(struct net_device *dev, struct ethtool_regs *regs,
135/* Wake on Lan only supported on Yukon chips with rev 1 or above */ 135/* Wake on Lan only supported on Yukon chips with rev 1 or above */
136static u32 wol_supported(const struct skge_hw *hw) 136static u32 wol_supported(const struct skge_hw *hw)
137{ 137{
138 if (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev != 0) 138 if (hw->chip_id == CHIP_ID_GENESIS)
139 return WAKE_MAGIC | WAKE_PHY; 139 return 0;
140 else 140
141 if (hw->chip_id == CHIP_ID_YUKON && hw->chip_rev == 0)
141 return 0; 142 return 0;
143
144 return WAKE_MAGIC | WAKE_PHY;
142} 145}
143 146
144static u32 pci_wake_enabled(struct pci_dev *dev) 147static u32 pci_wake_enabled(struct pci_dev *dev)
@@ -3591,7 +3594,9 @@ static struct net_device *skge_devinit(struct skge_hw *hw, int port,
3591 skge->duplex = -1; 3594 skge->duplex = -1;
3592 skge->speed = -1; 3595 skge->speed = -1;
3593 skge->advertising = skge_supported_modes(hw); 3596 skge->advertising = skge_supported_modes(hw);
3594 skge->wol = pci_wake_enabled(hw->pdev) ? wol_supported(hw) : 0; 3597
3598 if (pci_wake_enabled(hw->pdev))
3599 skge->wol = wol_supported(hw) & WAKE_MAGIC;
3595 3600
3596 hw->dev[port] = dev; 3601 hw->dev[port] = dev;
3597 3602
@@ -3797,6 +3802,9 @@ static int skge_suspend(struct pci_dev *pdev, pm_message_t state)
3797 struct skge_hw *hw = pci_get_drvdata(pdev); 3802 struct skge_hw *hw = pci_get_drvdata(pdev);
3798 int i, err, wol = 0; 3803 int i, err, wol = 0;
3799 3804
3805 if (!hw)
3806 return 0;
3807
3800 err = pci_save_state(pdev); 3808 err = pci_save_state(pdev);
3801 if (err) 3809 if (err)
3802 return err; 3810 return err;
@@ -3825,6 +3833,9 @@ static int skge_resume(struct pci_dev *pdev)
3825 struct skge_hw *hw = pci_get_drvdata(pdev); 3833 struct skge_hw *hw = pci_get_drvdata(pdev);
3826 int i, err; 3834 int i, err;
3827 3835
3836 if (!hw)
3837 return 0;
3838
3828 err = pci_set_power_state(pdev, PCI_D0); 3839 err = pci_set_power_state(pdev, PCI_D0);
3829 if (err) 3840 if (err)
3830 goto out; 3841 goto out;
@@ -3863,6 +3874,9 @@ static void skge_shutdown(struct pci_dev *pdev)
3863 struct skge_hw *hw = pci_get_drvdata(pdev); 3874 struct skge_hw *hw = pci_get_drvdata(pdev);
3864 int i, wol = 0; 3875 int i, wol = 0;
3865 3876
3877 if (!hw)
3878 return;
3879
3866 for (i = 0; i < hw->ports; i++) { 3880 for (i = 0; i < hw->ports; i++) {
3867 struct net_device *dev = hw->dev[i]; 3881 struct net_device *dev = hw->dev[i];
3868 struct skge_port *skge = netdev_priv(dev); 3882 struct skge_port *skge = netdev_priv(dev);
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 238c2ca34da6..832fd69a0e59 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -124,16 +124,13 @@ static const struct pci_device_id sky2_id_table[] = {
124 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */ 124 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */
125 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) }, /* 88E8053 */ 125 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4362) }, /* 88E8053 */
126 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) }, /* 88E8055 */ 126 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4363) }, /* 88E8055 */
127#ifdef broken
128 /* This device causes data corruption problems that are not resolved */
129 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4364) }, /* 88E8056 */ 127 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4364) }, /* 88E8056 */
130#endif
131 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4366) }, /* 88EC036 */ 128 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4366) }, /* 88EC036 */
132 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4367) }, /* 88EC032 */ 129 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4367) }, /* 88EC032 */
133 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4368) }, /* 88EC034 */ 130 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4368) }, /* 88EC034 */
134 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */ 131 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */
135 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */ 132 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */
136 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */ 133// { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */
137 { 0 } 134 { 0 }
138}; 135};
139 136
@@ -307,10 +304,13 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
307 PHY_M_EC_MAC_S_MSK); 304 PHY_M_EC_MAC_S_MSK);
308 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ); 305 ectrl |= PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
309 306
307 /* on PHY 88E1040 Rev.D0 (and newer) downshift control changed */
310 if (hw->chip_id == CHIP_ID_YUKON_EC) 308 if (hw->chip_id == CHIP_ID_YUKON_EC)
309 /* set downshift counter to 3x and enable downshift */
311 ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA; 310 ectrl |= PHY_M_EC_DSC_2(2) | PHY_M_EC_DOWN_S_ENA;
312 else 311 else
313 ectrl |= PHY_M_EC_M_DSC(2) | PHY_M_EC_S_DSC(3); 312 /* set master & slave downshift counter to 1x */
313 ectrl |= PHY_M_EC_M_DSC(0) | PHY_M_EC_S_DSC(1);
314 314
315 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl); 315 gm_phy_write(hw, port, PHY_MARV_EXT_CTRL, ectrl);
316 } 316 }
@@ -327,10 +327,12 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
327 /* enable automatic crossover */ 327 /* enable automatic crossover */
328 ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO); 328 ctrl |= PHY_M_PC_MDI_XMODE(PHY_M_PC_ENA_AUTO);
329 329
330 /* downshift on PHY 88E1112 and 88E1149 is changed */
330 if (sky2->autoneg == AUTONEG_ENABLE 331 if (sky2->autoneg == AUTONEG_ENABLE
331 && (hw->chip_id == CHIP_ID_YUKON_XL 332 && (hw->chip_id == CHIP_ID_YUKON_XL
332 || hw->chip_id == CHIP_ID_YUKON_EC_U 333 || hw->chip_id == CHIP_ID_YUKON_EC_U
333 || hw->chip_id == CHIP_ID_YUKON_EX)) { 334 || hw->chip_id == CHIP_ID_YUKON_EX)) {
335 /* set downshift counter to 3x and enable downshift */
334 ctrl &= ~PHY_M_PC_DSC_MSK; 336 ctrl &= ~PHY_M_PC_DSC_MSK;
335 ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA; 337 ctrl |= PHY_M_PC_DSC(2) | PHY_M_PC_DOWN_S_ENA;
336 } 338 }
@@ -842,10 +844,12 @@ static inline struct tx_ring_info *tx_le_re(struct sky2_port *sky2,
842/* Update chip's next pointer */ 844/* Update chip's next pointer */
843static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx) 845static inline void sky2_put_idx(struct sky2_hw *hw, unsigned q, u16 idx)
844{ 846{
845 q = Y2_QADDR(q, PREF_UNIT_PUT_IDX); 847 /* Make sure write' to descriptors are complete before we tell hardware */
846 wmb(); 848 wmb();
847 sky2_write16(hw, q, idx); 849 sky2_write16(hw, Y2_QADDR(q, PREF_UNIT_PUT_IDX), idx);
848 sky2_read16(hw, q); 850
851 /* Synchronize I/O on since next processor may write to tail */
852 mmiowb();
849} 853}
850 854
851 855
@@ -977,6 +981,7 @@ stopped:
977 981
978 /* reset the Rx prefetch unit */ 982 /* reset the Rx prefetch unit */
979 sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET); 983 sky2_write32(hw, Y2_QADDR(rxq, PREF_UNIT_CTRL), PREF_UNIT_RST_SET);
984 mmiowb();
980} 985}
981 986
982/* Clean out receive buffer area, assumes receiver hardware stopped */ 987/* Clean out receive buffer area, assumes receiver hardware stopped */
@@ -1196,7 +1201,7 @@ static int sky2_rx_start(struct sky2_port *sky2)
1196 } 1201 }
1197 1202
1198 /* Tell chip about available buffers */ 1203 /* Tell chip about available buffers */
1199 sky2_write16(hw, Y2_QADDR(rxq, PREF_UNIT_PUT_IDX), sky2->rx_put); 1204 sky2_put_idx(hw, rxq, sky2->rx_put);
1200 return 0; 1205 return 0;
1201nomem: 1206nomem:
1202 sky2_rx_clean(sky2); 1207 sky2_rx_clean(sky2);
@@ -1538,6 +1543,8 @@ static void sky2_tx_complete(struct sky2_port *sky2, u16 done)
1538 } 1543 }
1539 1544
1540 sky2->tx_cons = idx; 1545 sky2->tx_cons = idx;
1546 smp_mb();
1547
1541 if (tx_avail(sky2) > MAX_SKB_TX_LE + 4) 1548 if (tx_avail(sky2) > MAX_SKB_TX_LE + 4)
1542 netif_wake_queue(dev); 1549 netif_wake_queue(dev);
1543} 1550}
@@ -1577,13 +1584,6 @@ static int sky2_down(struct net_device *dev)
1577 imask &= ~portirq_msk[port]; 1584 imask &= ~portirq_msk[port];
1578 sky2_write32(hw, B0_IMSK, imask); 1585 sky2_write32(hw, B0_IMSK, imask);
1579 1586
1580 /*
1581 * Both ports share the NAPI poll on port 0, so if necessary undo the
1582 * the disable that is done in dev_close.
1583 */
1584 if (sky2->port == 0 && hw->ports > 1)
1585 netif_poll_enable(dev);
1586
1587 sky2_gmac_reset(hw, port); 1587 sky2_gmac_reset(hw, port);
1588 1588
1589 /* Stop transmitter */ 1589 /* Stop transmitter */
@@ -2139,8 +2139,10 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do)
2139 switch (le->opcode & ~HW_OWNER) { 2139 switch (le->opcode & ~HW_OWNER) {
2140 case OP_RXSTAT: 2140 case OP_RXSTAT:
2141 skb = sky2_receive(dev, length, status); 2141 skb = sky2_receive(dev, length, status);
2142 if (!skb) 2142 if (unlikely(!skb)) {
2143 sky2->net_stats.rx_dropped++;
2143 goto force_update; 2144 goto force_update;
2145 }
2144 2146
2145 skb->protocol = eth_type_trans(skb, dev); 2147 skb->protocol = eth_type_trans(skb, dev);
2146 sky2->net_stats.rx_packets++; 2148 sky2->net_stats.rx_packets++;
@@ -2221,6 +2223,7 @@ force_update:
2221 2223
2222 /* Fully processed status ring so clear irq */ 2224 /* Fully processed status ring so clear irq */
2223 sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ); 2225 sky2_write32(hw, STAT_CTRL, SC_STAT_CLR_IRQ);
2226 mmiowb();
2224 2227
2225exit_loop: 2228exit_loop:
2226 if (buf_write[0]) { 2229 if (buf_write[0]) {
@@ -2341,6 +2344,12 @@ static void sky2_mac_intr(struct sky2_hw *hw, unsigned port)
2341 printk(KERN_INFO PFX "%s: mac interrupt status 0x%x\n", 2344 printk(KERN_INFO PFX "%s: mac interrupt status 0x%x\n",
2342 dev->name, status); 2345 dev->name, status);
2343 2346
2347 if (status & GM_IS_RX_CO_OV)
2348 gma_read16(hw, port, GM_RX_IRQ_SRC);
2349
2350 if (status & GM_IS_TX_CO_OV)
2351 gma_read16(hw, port, GM_TX_IRQ_SRC);
2352
2344 if (status & GM_IS_RX_FF_OR) { 2353 if (status & GM_IS_RX_FF_OR) {
2345 ++sky2->net_stats.rx_fifo_errors; 2354 ++sky2->net_stats.rx_fifo_errors;
2346 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO); 2355 sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_CLI_RX_FO);
@@ -2439,6 +2448,7 @@ static int sky2_poll(struct net_device *dev0, int *budget)
2439 if (work_done < work_limit) { 2448 if (work_done < work_limit) {
2440 netif_rx_complete(dev0); 2449 netif_rx_complete(dev0);
2441 2450
2451 /* end of interrupt, re-enables also acts as I/O synchronization */
2442 sky2_read32(hw, B0_Y2_SP_LISR); 2452 sky2_read32(hw, B0_Y2_SP_LISR);
2443 return 0; 2453 return 0;
2444 } else { 2454 } else {
@@ -3584,7 +3594,7 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
3584 err = pci_request_regions(pdev, DRV_NAME); 3594 err = pci_request_regions(pdev, DRV_NAME);
3585 if (err) { 3595 if (err) {
3586 dev_err(&pdev->dev, "cannot obtain PCI resources\n"); 3596 dev_err(&pdev->dev, "cannot obtain PCI resources\n");
3587 goto err_out; 3597 goto err_out_disable;
3588 } 3598 }
3589 3599
3590 pci_set_master(pdev); 3600 pci_set_master(pdev);
@@ -3721,8 +3731,10 @@ err_out_free_hw:
3721 kfree(hw); 3731 kfree(hw);
3722err_out_free_regions: 3732err_out_free_regions:
3723 pci_release_regions(pdev); 3733 pci_release_regions(pdev);
3734err_out_disable:
3724 pci_disable_device(pdev); 3735 pci_disable_device(pdev);
3725err_out: 3736err_out:
3737 pci_set_drvdata(pdev, NULL);
3726 return err; 3738 return err;
3727} 3739}
3728 3740
@@ -3775,6 +3787,9 @@ static int sky2_suspend(struct pci_dev *pdev, pm_message_t state)
3775 struct sky2_hw *hw = pci_get_drvdata(pdev); 3787 struct sky2_hw *hw = pci_get_drvdata(pdev);
3776 int i, wol = 0; 3788 int i, wol = 0;
3777 3789
3790 if (!hw)
3791 return 0;
3792
3778 del_timer_sync(&hw->idle_timer); 3793 del_timer_sync(&hw->idle_timer);
3779 netif_poll_disable(hw->dev[0]); 3794 netif_poll_disable(hw->dev[0]);
3780 3795
@@ -3806,6 +3821,9 @@ static int sky2_resume(struct pci_dev *pdev)
3806 struct sky2_hw *hw = pci_get_drvdata(pdev); 3821 struct sky2_hw *hw = pci_get_drvdata(pdev);
3807 int i, err; 3822 int i, err;
3808 3823
3824 if (!hw)
3825 return 0;
3826
3809 err = pci_set_power_state(pdev, PCI_D0); 3827 err = pci_set_power_state(pdev, PCI_D0);
3810 if (err) 3828 if (err)
3811 goto out; 3829 goto out;
@@ -3852,6 +3870,9 @@ static void sky2_shutdown(struct pci_dev *pdev)
3852 struct sky2_hw *hw = pci_get_drvdata(pdev); 3870 struct sky2_hw *hw = pci_get_drvdata(pdev);
3853 int i, wol = 0; 3871 int i, wol = 0;
3854 3872
3873 if (!hw)
3874 return;
3875
3855 del_timer_sync(&hw->idle_timer); 3876 del_timer_sync(&hw->idle_timer);
3856 netif_poll_disable(hw->dev[0]); 3877 netif_poll_disable(hw->dev[0]);
3857 3878
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 81f24847c963..db43e42bee35 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -77,7 +77,6 @@ static const char version[] =
77#include <linux/skbuff.h> 77#include <linux/skbuff.h>
78 78
79#include <asm/io.h> 79#include <asm/io.h>
80#include <asm/irq.h>
81 80
82#include "smc911x.h" 81#include "smc911x.h"
83 82
@@ -2084,12 +2083,11 @@ static int __init smc911x_probe(struct net_device *dev, unsigned long ioaddr)
2084 lp->ctl_rspeed = 100; 2083 lp->ctl_rspeed = 100;
2085 2084
2086 /* Grab the IRQ */ 2085 /* Grab the IRQ */
2087 retval = request_irq(dev->irq, &smc911x_interrupt, IRQF_SHARED, dev->name, dev); 2086 retval = request_irq(dev->irq, &smc911x_interrupt,
2087 IRQF_SHARED | IRQF_TRIGGER_FALLING, dev->name, dev);
2088 if (retval) 2088 if (retval)
2089 goto err_out; 2089 goto err_out;
2090 2090
2091 set_irq_type(dev->irq, IRQT_FALLING);
2092
2093#ifdef SMC_USE_DMA 2091#ifdef SMC_USE_DMA
2094 lp->rxdma = SMC_DMA_REQUEST(dev, smc911x_rx_dma_irq); 2092 lp->rxdma = SMC_DMA_REQUEST(dev, smc911x_rx_dma_irq);
2095 lp->txdma = SMC_DMA_REQUEST(dev, smc911x_tx_dma_irq); 2093 lp->txdma = SMC_DMA_REQUEST(dev, smc911x_tx_dma_irq);
diff --git a/drivers/net/smc91x.h b/drivers/net/smc91x.h
index 7053026d6c76..111f23d05764 100644
--- a/drivers/net/smc91x.h
+++ b/drivers/net/smc91x.h
@@ -279,6 +279,40 @@ SMC_outw(u16 val, void __iomem *ioaddr, int reg)
279#define SMC_insw(a, r, p, l) insw((a) + (r), p, l) 279#define SMC_insw(a, r, p, l) insw((a) + (r), p, l)
280#define SMC_outsw(a, r, p, l) outsw((a) + (r), p, l) 280#define SMC_outsw(a, r, p, l) outsw((a) + (r), p, l)
281 281
282#elif defined(CONFIG_SUPERH)
283
284#if defined(CONFIG_SH_7780_SOLUTION_ENGINE) || defined(CONFIG_SH_7722_SOLUTION_ENGINE)
285#define SMC_CAN_USE_8BIT 0
286#define SMC_CAN_USE_16BIT 1
287#define SMC_CAN_USE_32BIT 0
288#define SMC_IO_SHIFT 0
289#define SMC_NOWAIT 1
290
291#define SMC_inb(a, r) (inw((a) + ((r)&~1)) >> (8*(r%2)))&0xff
292#define SMC_inw(a, r) inw((a) + (r))
293#define SMC_outb(v, a, r) outw(((inw((a)+((r)&~1))*(0xff<<8*(r%2)))) | ((v)<<(8*(r&2)))), (a) + ((r)&~1))
294
295#define SMC_outw(v, a, r) outw(v, (a) + (r))
296#define SMC_insw(a, r, p, l) insw((a) + (r), p, l)
297#define SMC_outsw(a, r, p, l) outsw((a) + (r), p, l)
298
299#else /* BOARDS */
300
301#define SMC_CAN_USE_8BIT 1
302#define SMC_CAN_USE_16BIT 1
303#define SMC_CAN_USE_32BIT 1
304
305#define SMC_inb(a, r) inb((a) + (r))
306#define SMC_inw(a, r) inw((a) + (r))
307#define SMC_outb(v, a, r) outb(v, (a) + (r))
308#define SMC_outw(v, a, r) outw(v, (a) + (r))
309#define SMC_insw(a, r, p, l) insw((a) + (r), p, l)
310#define SMC_outsw(a, r, p, l) outsw((a) + (r), p, l)
311
312#endif /* BOARDS */
313
314#define set_irq_type(irq, type) do {} while (0)
315
282#elif defined(CONFIG_M32R) 316#elif defined(CONFIG_M32R)
283 317
284#define SMC_CAN_USE_8BIT 0 318#define SMC_CAN_USE_8BIT 0
diff --git a/drivers/net/spider_net.c b/drivers/net/spider_net.c
index 230da14b1b68..c3964c3d89d9 100644
--- a/drivers/net/spider_net.c
+++ b/drivers/net/spider_net.c
@@ -175,12 +175,10 @@ spider_net_setup_aneg(struct spider_net_card *card)
175{ 175{
176 struct mii_phy *phy = &card->phy; 176 struct mii_phy *phy = &card->phy;
177 u32 advertise = 0; 177 u32 advertise = 0;
178 u16 bmcr, bmsr, stat1000, estat; 178 u16 bmsr, estat;
179 179
180 bmcr = spider_net_read_phy(card->netdev, phy->mii_id, MII_BMCR); 180 bmsr = spider_net_read_phy(card->netdev, phy->mii_id, MII_BMSR);
181 bmsr = spider_net_read_phy(card->netdev, phy->mii_id, MII_BMSR); 181 estat = spider_net_read_phy(card->netdev, phy->mii_id, MII_ESTATUS);
182 stat1000 = spider_net_read_phy(card->netdev, phy->mii_id, MII_STAT1000);
183 estat = spider_net_read_phy(card->netdev, phy->mii_id, MII_ESTATUS);
184 182
185 if (bmsr & BMSR_10HALF) 183 if (bmsr & BMSR_10HALF)
186 advertise |= ADVERTISED_10baseT_Half; 184 advertise |= ADVERTISED_10baseT_Half;
@@ -432,7 +430,8 @@ spider_net_prepare_rx_descr(struct spider_net_card *card,
432 /* and we need to have it 128 byte aligned, therefore we allocate a 430 /* and we need to have it 128 byte aligned, therefore we allocate a
433 * bit more */ 431 * bit more */
434 /* allocate an skb */ 432 /* allocate an skb */
435 descr->skb = dev_alloc_skb(bufsize + SPIDER_NET_RXBUF_ALIGN - 1); 433 descr->skb = netdev_alloc_skb(card->netdev,
434 bufsize + SPIDER_NET_RXBUF_ALIGN - 1);
436 if (!descr->skb) { 435 if (!descr->skb) {
437 if (netif_msg_rx_err(card) && net_ratelimit()) 436 if (netif_msg_rx_err(card) && net_ratelimit())
438 pr_err("Not enough memory to allocate rx buffer\n"); 437 pr_err("Not enough memory to allocate rx buffer\n");
@@ -1830,7 +1829,7 @@ try_host_fw:
1830 if (!dn) 1829 if (!dn)
1831 goto out_err; 1830 goto out_err;
1832 1831
1833 fw_prop = get_property(dn, "firmware", &fw_size); 1832 fw_prop = of_get_property(dn, "firmware", &fw_size);
1834 if (!fw_prop) 1833 if (!fw_prop)
1835 goto out_err; 1834 goto out_err;
1836 1835
@@ -2236,7 +2235,7 @@ spider_net_setup_netdev(struct spider_net_card *card)
2236 if (!dn) 2235 if (!dn)
2237 return -EIO; 2236 return -EIO;
2238 2237
2239 mac = get_property(dn, "local-mac-address", NULL); 2238 mac = of_get_property(dn, "local-mac-address", NULL);
2240 if (!mac) 2239 if (!mac)
2241 return -EIO; 2240 return -EIO;
2242 memcpy(addr.sa_data, mac, ETH_ALEN); 2241 memcpy(addr.sa_data, mac, ETH_ALEN);
diff --git a/drivers/net/sundance.c b/drivers/net/sundance.c
index f51ba31970aa..e1f912d04043 100644
--- a/drivers/net/sundance.c
+++ b/drivers/net/sundance.c
@@ -110,8 +110,7 @@ static char *media[MAX_UNITS];
110 110
111/* These identify the driver base version and may not be removed. */ 111/* These identify the driver base version and may not be removed. */
112static char version[] = 112static char version[] =
113KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Written by Donald Becker\n" 113KERN_INFO DRV_NAME ".c:v" DRV_VERSION " " DRV_RELDATE " Written by Donald Becker\n";
114KERN_INFO " http://www.scyld.com/network/sundance.html\n";
115 114
116MODULE_AUTHOR("Donald Becker <becker@scyld.com>"); 115MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
117MODULE_DESCRIPTION("Sundance Alta Ethernet driver"); 116MODULE_DESCRIPTION("Sundance Alta Ethernet driver");
diff --git a/drivers/net/sungem.c b/drivers/net/sungem.c
index 5da73212ac91..432803855034 100644
--- a/drivers/net/sungem.c
+++ b/drivers/net/sungem.c
@@ -2903,7 +2903,7 @@ static int __devinit gem_get_device_address(struct gem *gp)
2903 struct net_device *dev = gp->dev; 2903 struct net_device *dev = gp->dev;
2904 const unsigned char *addr; 2904 const unsigned char *addr;
2905 2905
2906 addr = get_property(gp->of_node, "local-mac-address", NULL); 2906 addr = of_get_property(gp->of_node, "local-mac-address", NULL);
2907 if (addr == NULL) { 2907 if (addr == NULL) {
2908#ifdef CONFIG_SPARC 2908#ifdef CONFIG_SPARC
2909 addr = idprom->id_ethaddr; 2909 addr = idprom->id_ethaddr;
diff --git a/drivers/net/sungem_phy.c b/drivers/net/sungem_phy.c
index 56a110ca5e6f..61843fd57525 100644
--- a/drivers/net/sungem_phy.c
+++ b/drivers/net/sungem_phy.c
@@ -451,7 +451,7 @@ static int bcm5421_init(struct mii_phy* phy)
451 if (phy->platform_data) { 451 if (phy->platform_data) {
452 struct device_node *np = of_get_parent(phy->platform_data); 452 struct device_node *np = of_get_parent(phy->platform_data);
453 int can_low_power = 1; 453 int can_low_power = 1;
454 if (np == NULL || get_property(np, "no-autolowpower", NULL)) 454 if (np == NULL || of_get_property(np, "no-autolowpower", NULL))
455 can_low_power = 0; 455 can_low_power = 0;
456 if (can_low_power) { 456 if (can_low_power) {
457 /* Enable automatic low-power */ 457 /* Enable automatic low-power */
diff --git a/drivers/net/tc35815.c b/drivers/net/tc35815.c
index f1e2dfc795a2..463d600ed83d 100644
--- a/drivers/net/tc35815.c
+++ b/drivers/net/tc35815.c
@@ -540,7 +540,6 @@ static struct sk_buff *alloc_rxbuf_skb(struct net_device *dev,
540 skb = dev_alloc_skb(RX_BUF_SIZE); 540 skb = dev_alloc_skb(RX_BUF_SIZE);
541 if (!skb) 541 if (!skb)
542 return NULL; 542 return NULL;
543 skb->dev = dev;
544 *dma_handle = pci_map_single(hwdev, skb->data, RX_BUF_SIZE, 543 *dma_handle = pci_map_single(hwdev, skb->data, RX_BUF_SIZE,
545 PCI_DMA_FROMDEVICE); 544 PCI_DMA_FROMDEVICE);
546 if (pci_dma_mapping_error(*dma_handle)) { 545 if (pci_dma_mapping_error(*dma_handle)) {
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index e5e901ecd808..923b9c725cc3 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -3716,10 +3716,8 @@ static void tg3_reset_task(struct work_struct *work)
3716 unsigned int restart_timer; 3716 unsigned int restart_timer;
3717 3717
3718 tg3_full_lock(tp, 0); 3718 tg3_full_lock(tp, 0);
3719 tp->tg3_flags |= TG3_FLAG_IN_RESET_TASK;
3720 3719
3721 if (!netif_running(tp->dev)) { 3720 if (!netif_running(tp->dev)) {
3722 tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
3723 tg3_full_unlock(tp); 3721 tg3_full_unlock(tp);
3724 return; 3722 return;
3725 } 3723 }
@@ -3750,8 +3748,6 @@ static void tg3_reset_task(struct work_struct *work)
3750 mod_timer(&tp->timer, jiffies + 1); 3748 mod_timer(&tp->timer, jiffies + 1);
3751 3749
3752out: 3750out:
3753 tp->tg3_flags &= ~TG3_FLAG_IN_RESET_TASK;
3754
3755 tg3_full_unlock(tp); 3751 tg3_full_unlock(tp);
3756} 3752}
3757 3753
@@ -7390,12 +7386,7 @@ static int tg3_close(struct net_device *dev)
7390{ 7386{
7391 struct tg3 *tp = netdev_priv(dev); 7387 struct tg3 *tp = netdev_priv(dev);
7392 7388
7393 /* Calling flush_scheduled_work() may deadlock because 7389 cancel_work_sync(&tp->reset_task);
7394 * linkwatch_event() may be on the workqueue and it will try to get
7395 * the rtnl_lock which we are holding.
7396 */
7397 while (tp->tg3_flags & TG3_FLAG_IN_RESET_TASK)
7398 msleep(1);
7399 7390
7400 netif_stop_queue(dev); 7391 netif_stop_queue(dev);
7401 7392
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 4d334cf5a243..bd9f4f428e5b 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -2228,7 +2228,7 @@ struct tg3 {
2228#define TG3_FLAG_JUMBO_RING_ENABLE 0x00800000 2228#define TG3_FLAG_JUMBO_RING_ENABLE 0x00800000
2229#define TG3_FLAG_10_100_ONLY 0x01000000 2229#define TG3_FLAG_10_100_ONLY 0x01000000
2230#define TG3_FLAG_PAUSE_AUTONEG 0x02000000 2230#define TG3_FLAG_PAUSE_AUTONEG 0x02000000
2231#define TG3_FLAG_IN_RESET_TASK 0x04000000 2231
2232#define TG3_FLAG_40BIT_DMA_BUG 0x08000000 2232#define TG3_FLAG_40BIT_DMA_BUG 0x08000000
2233#define TG3_FLAG_BROKEN_CHECKSUMS 0x10000000 2233#define TG3_FLAG_BROKEN_CHECKSUMS 0x10000000
2234#define TG3_FLAG_SUPPORT_MSI 0x20000000 2234#define TG3_FLAG_SUPPORT_MSI 0x20000000
diff --git a/drivers/net/tsi108_eth.c b/drivers/net/tsi108_eth.c
index 0bfc2c9c1c08..1aabc91f6458 100644
--- a/drivers/net/tsi108_eth.c
+++ b/drivers/net/tsi108_eth.c
@@ -82,6 +82,7 @@ struct tsi108_prv_data {
82 unsigned int phy; /* Index of PHY for this interface */ 82 unsigned int phy; /* Index of PHY for this interface */
83 unsigned int irq_num; 83 unsigned int irq_num;
84 unsigned int id; 84 unsigned int id;
85 unsigned int phy_type;
85 86
86 struct timer_list timer;/* Timer that triggers the check phy function */ 87 struct timer_list timer;/* Timer that triggers the check phy function */
87 unsigned int rxtail; /* Next entry in rxring to read */ 88 unsigned int rxtail; /* Next entry in rxring to read */
@@ -1256,11 +1257,11 @@ static void tsi108_init_phy(struct net_device *dev)
1256 if (i == 0) 1257 if (i == 0)
1257 printk(KERN_ERR "%s function time out \n", __FUNCTION__); 1258 printk(KERN_ERR "%s function time out \n", __FUNCTION__);
1258 1259
1259#if (TSI108_PHY_TYPE == PHY_BCM54XX) /* Broadcom BCM54xx PHY */ 1260 if (data->phy_type == TSI108_PHY_BCM54XX) {
1260 tsi108_write_mii(data, 0x09, 0x0300); 1261 tsi108_write_mii(data, 0x09, 0x0300);
1261 tsi108_write_mii(data, 0x10, 0x1020); 1262 tsi108_write_mii(data, 0x10, 0x1020);
1262 tsi108_write_mii(data, 0x1c, 0x8c00); 1263 tsi108_write_mii(data, 0x1c, 0x8c00);
1263#endif 1264 }
1264 1265
1265 tsi108_write_mii(data, 1266 tsi108_write_mii(data,
1266 MII_BMCR, 1267 MII_BMCR,
@@ -1587,6 +1588,7 @@ tsi108_init_one(struct platform_device *pdev)
1587 data->mii_if.supports_gmii = mii_check_gmii_support(&data->mii_if); 1588 data->mii_if.supports_gmii = mii_check_gmii_support(&data->mii_if);
1588 1589
1589 data->phy = einfo->phy; 1590 data->phy = einfo->phy;
1591 data->phy_type = einfo->phy_type;
1590 data->irq_num = einfo->irq_num; 1592 data->irq_num = einfo->irq_num;
1591 data->id = pdev->id; 1593 data->id = pdev->id;
1592 dev->open = tsi108_open; 1594 dev->open = tsi108_open;
diff --git a/drivers/net/tsi108_eth.h b/drivers/net/tsi108_eth.h
index 77a769df228a..5a77ae6c5f36 100644
--- a/drivers/net/tsi108_eth.h
+++ b/drivers/net/tsi108_eth.h
@@ -43,15 +43,6 @@
43 in_be32((data->phyregs + (offset))) 43 in_be32((data->phyregs + (offset)))
44 44
45/* 45/*
46 * PHY Configuration Options
47 *
48 * NOTE: Enable set of definitions corresponding to your board type
49 */
50#define PHY_MV88E 1 /* Marvel 88Exxxx PHY */
51#define PHY_BCM54XX 2 /* Broardcom BCM54xx PHY */
52#define TSI108_PHY_TYPE PHY_MV88E
53
54/*
55 * TSI108 GIGE port registers 46 * TSI108 GIGE port registers
56 */ 47 */
57 48
diff --git a/drivers/net/tulip/interrupt.c b/drivers/net/tulip/interrupt.c
index 9b08afbd1f65..ea896777bcaf 100644
--- a/drivers/net/tulip/interrupt.c
+++ b/drivers/net/tulip/interrupt.c
@@ -269,7 +269,7 @@ done:
269 This would turn on IM for devices that is not contributing 269 This would turn on IM for devices that is not contributing
270 to backlog congestion with unnecessary latency. 270 to backlog congestion with unnecessary latency.
271 271
272 We monitor the the device RX-ring and have: 272 We monitor the device RX-ring and have:
273 273
274 HW Interrupt Mitigation either ON or OFF. 274 HW Interrupt Mitigation either ON or OFF.
275 275
diff --git a/drivers/net/tulip/winbond-840.c b/drivers/net/tulip/winbond-840.c
index fa440706fb4a..38f3b99716b8 100644
--- a/drivers/net/tulip/winbond-840.c
+++ b/drivers/net/tulip/winbond-840.c
@@ -1021,7 +1021,7 @@ static int start_tx(struct sk_buff *skb, struct net_device *dev)
1021 np->tx_ring[entry].length |= DescEndRing; 1021 np->tx_ring[entry].length |= DescEndRing;
1022 1022
1023 /* Now acquire the irq spinlock. 1023 /* Now acquire the irq spinlock.
1024 * The difficult race is the the ordering between 1024 * The difficult race is the ordering between
1025 * increasing np->cur_tx and setting DescOwned: 1025 * increasing np->cur_tx and setting DescOwned:
1026 * - if np->cur_tx is increased first the interrupt 1026 * - if np->cur_tx is increased first the interrupt
1027 * handler could consider the packet as transmitted 1027 * handler could consider the packet as transmitted
diff --git a/drivers/net/tulip/xircom_cb.c b/drivers/net/tulip/xircom_cb.c
index 985a1810ca59..2470b1ee33c0 100644
--- a/drivers/net/tulip/xircom_cb.c
+++ b/drivers/net/tulip/xircom_cb.c
@@ -1043,7 +1043,7 @@ static int enable_promisc(struct xircom_private *card)
1043 1043
1044 1044
1045/* 1045/*
1046link_status() checks the the links status and will return 0 for no link, 10 for 10mbit link and 100 for.. guess what. 1046link_status() checks the links status and will return 0 for no link, 10 for 10mbit link and 100 for.. guess what.
1047 1047
1048Must be called in locked state with interrupts disabled 1048Must be called in locked state with interrupts disabled
1049*/ 1049*/
diff --git a/drivers/net/typhoon.c b/drivers/net/typhoon.c
index f2dd7763cd0b..f72573594121 100644
--- a/drivers/net/typhoon.c
+++ b/drivers/net/typhoon.c
@@ -639,7 +639,7 @@ typhoon_issue_command(struct typhoon *tp, int num_cmd, struct cmd_desc *cmd,
639 639
640 typhoon_inc_cmd_index(&ring->lastWrite, num_cmd); 640 typhoon_inc_cmd_index(&ring->lastWrite, num_cmd);
641 641
642 /* "I feel a presence... another warrior is on the the mesa." 642 /* "I feel a presence... another warrior is on the mesa."
643 */ 643 */
644 wmb(); 644 wmb();
645 iowrite32(ring->lastWrite, tp->ioaddr + TYPHOON_REG_CMD_READY); 645 iowrite32(ring->lastWrite, tp->ioaddr + TYPHOON_REG_CMD_READY);
diff --git a/drivers/net/ucc_geth.c b/drivers/net/ucc_geth.c
index 16b9acdabbe8..c2ccbd098f53 100644
--- a/drivers/net/ucc_geth.c
+++ b/drivers/net/ucc_geth.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved. 2 * Copyright (C) 2006-2007 Freescale Semicondutor, Inc. All rights reserved.
3 * 3 *
4 * Author: Shlomi Gridish <gridish@freescale.com> 4 * Author: Shlomi Gridish <gridish@freescale.com>
5 * Li Yang <leoli@freescale.com> 5 * Li Yang <leoli@freescale.com>
@@ -293,7 +293,7 @@ static int fill_init_enet_entries(struct ucc_geth_private *ugeth,
293 else { 293 else {
294 init_enet_offset = 294 init_enet_offset =
295 qe_muram_alloc(thread_size, thread_alignment); 295 qe_muram_alloc(thread_size, thread_alignment);
296 if (IS_MURAM_ERR(init_enet_offset)) { 296 if (IS_ERR_VALUE(init_enet_offset)) {
297 ugeth_err 297 ugeth_err
298 ("fill_init_enet_entries: Can not allocate DPRAM memory."); 298 ("fill_init_enet_entries: Can not allocate DPRAM memory.");
299 qe_put_snum((u8) snum); 299 qe_put_snum((u8) snum);
@@ -2594,7 +2594,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2594 ugeth->tx_bd_ring_offset[j] = 2594 ugeth->tx_bd_ring_offset[j] =
2595 qe_muram_alloc(length, 2595 qe_muram_alloc(length,
2596 UCC_GETH_TX_BD_RING_ALIGNMENT); 2596 UCC_GETH_TX_BD_RING_ALIGNMENT);
2597 if (!IS_MURAM_ERR(ugeth->tx_bd_ring_offset[j])) 2597 if (!IS_ERR_VALUE(ugeth->tx_bd_ring_offset[j]))
2598 ugeth->p_tx_bd_ring[j] = 2598 ugeth->p_tx_bd_ring[j] =
2599 (u8 *) qe_muram_addr(ugeth-> 2599 (u8 *) qe_muram_addr(ugeth->
2600 tx_bd_ring_offset[j]); 2600 tx_bd_ring_offset[j]);
@@ -2629,7 +2629,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2629 ugeth->rx_bd_ring_offset[j] = 2629 ugeth->rx_bd_ring_offset[j] =
2630 qe_muram_alloc(length, 2630 qe_muram_alloc(length,
2631 UCC_GETH_RX_BD_RING_ALIGNMENT); 2631 UCC_GETH_RX_BD_RING_ALIGNMENT);
2632 if (!IS_MURAM_ERR(ugeth->rx_bd_ring_offset[j])) 2632 if (!IS_ERR_VALUE(ugeth->rx_bd_ring_offset[j]))
2633 ugeth->p_rx_bd_ring[j] = 2633 ugeth->p_rx_bd_ring[j] =
2634 (u8 *) qe_muram_addr(ugeth-> 2634 (u8 *) qe_muram_addr(ugeth->
2635 rx_bd_ring_offset[j]); 2635 rx_bd_ring_offset[j]);
@@ -2713,7 +2713,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2713 ugeth->tx_glbl_pram_offset = 2713 ugeth->tx_glbl_pram_offset =
2714 qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram), 2714 qe_muram_alloc(sizeof(struct ucc_geth_tx_global_pram),
2715 UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT); 2715 UCC_GETH_TX_GLOBAL_PRAM_ALIGNMENT);
2716 if (IS_MURAM_ERR(ugeth->tx_glbl_pram_offset)) { 2716 if (IS_ERR_VALUE(ugeth->tx_glbl_pram_offset)) {
2717 ugeth_err 2717 ugeth_err
2718 ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.", 2718 ("%s: Can not allocate DPRAM memory for p_tx_glbl_pram.",
2719 __FUNCTION__); 2719 __FUNCTION__);
@@ -2735,7 +2735,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2735 sizeof(struct ucc_geth_thread_data_tx) + 2735 sizeof(struct ucc_geth_thread_data_tx) +
2736 32 * (numThreadsTxNumerical == 1), 2736 32 * (numThreadsTxNumerical == 1),
2737 UCC_GETH_THREAD_DATA_ALIGNMENT); 2737 UCC_GETH_THREAD_DATA_ALIGNMENT);
2738 if (IS_MURAM_ERR(ugeth->thread_dat_tx_offset)) { 2738 if (IS_ERR_VALUE(ugeth->thread_dat_tx_offset)) {
2739 ugeth_err 2739 ugeth_err
2740 ("%s: Can not allocate DPRAM memory for p_thread_data_tx.", 2740 ("%s: Can not allocate DPRAM memory for p_thread_data_tx.",
2741 __FUNCTION__); 2741 __FUNCTION__);
@@ -2763,7 +2763,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2763 qe_muram_alloc(ug_info->numQueuesTx * 2763 qe_muram_alloc(ug_info->numQueuesTx *
2764 sizeof(struct ucc_geth_send_queue_qd), 2764 sizeof(struct ucc_geth_send_queue_qd),
2765 UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT); 2765 UCC_GETH_SEND_QUEUE_QUEUE_DESCRIPTOR_ALIGNMENT);
2766 if (IS_MURAM_ERR(ugeth->send_q_mem_reg_offset)) { 2766 if (IS_ERR_VALUE(ugeth->send_q_mem_reg_offset)) {
2767 ugeth_err 2767 ugeth_err
2768 ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.", 2768 ("%s: Can not allocate DPRAM memory for p_send_q_mem_reg.",
2769 __FUNCTION__); 2769 __FUNCTION__);
@@ -2806,7 +2806,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2806 ugeth->scheduler_offset = 2806 ugeth->scheduler_offset =
2807 qe_muram_alloc(sizeof(struct ucc_geth_scheduler), 2807 qe_muram_alloc(sizeof(struct ucc_geth_scheduler),
2808 UCC_GETH_SCHEDULER_ALIGNMENT); 2808 UCC_GETH_SCHEDULER_ALIGNMENT);
2809 if (IS_MURAM_ERR(ugeth->scheduler_offset)) { 2809 if (IS_ERR_VALUE(ugeth->scheduler_offset)) {
2810 ugeth_err 2810 ugeth_err
2811 ("%s: Can not allocate DPRAM memory for p_scheduler.", 2811 ("%s: Can not allocate DPRAM memory for p_scheduler.",
2812 __FUNCTION__); 2812 __FUNCTION__);
@@ -2854,7 +2854,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2854 qe_muram_alloc(sizeof 2854 qe_muram_alloc(sizeof
2855 (struct ucc_geth_tx_firmware_statistics_pram), 2855 (struct ucc_geth_tx_firmware_statistics_pram),
2856 UCC_GETH_TX_STATISTICS_ALIGNMENT); 2856 UCC_GETH_TX_STATISTICS_ALIGNMENT);
2857 if (IS_MURAM_ERR(ugeth->tx_fw_statistics_pram_offset)) { 2857 if (IS_ERR_VALUE(ugeth->tx_fw_statistics_pram_offset)) {
2858 ugeth_err 2858 ugeth_err
2859 ("%s: Can not allocate DPRAM memory for" 2859 ("%s: Can not allocate DPRAM memory for"
2860 " p_tx_fw_statistics_pram.", __FUNCTION__); 2860 " p_tx_fw_statistics_pram.", __FUNCTION__);
@@ -2893,7 +2893,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2893 ugeth->rx_glbl_pram_offset = 2893 ugeth->rx_glbl_pram_offset =
2894 qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram), 2894 qe_muram_alloc(sizeof(struct ucc_geth_rx_global_pram),
2895 UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT); 2895 UCC_GETH_RX_GLOBAL_PRAM_ALIGNMENT);
2896 if (IS_MURAM_ERR(ugeth->rx_glbl_pram_offset)) { 2896 if (IS_ERR_VALUE(ugeth->rx_glbl_pram_offset)) {
2897 ugeth_err 2897 ugeth_err
2898 ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.", 2898 ("%s: Can not allocate DPRAM memory for p_rx_glbl_pram.",
2899 __FUNCTION__); 2899 __FUNCTION__);
@@ -2914,7 +2914,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2914 qe_muram_alloc(numThreadsRxNumerical * 2914 qe_muram_alloc(numThreadsRxNumerical *
2915 sizeof(struct ucc_geth_thread_data_rx), 2915 sizeof(struct ucc_geth_thread_data_rx),
2916 UCC_GETH_THREAD_DATA_ALIGNMENT); 2916 UCC_GETH_THREAD_DATA_ALIGNMENT);
2917 if (IS_MURAM_ERR(ugeth->thread_dat_rx_offset)) { 2917 if (IS_ERR_VALUE(ugeth->thread_dat_rx_offset)) {
2918 ugeth_err 2918 ugeth_err
2919 ("%s: Can not allocate DPRAM memory for p_thread_data_rx.", 2919 ("%s: Can not allocate DPRAM memory for p_thread_data_rx.",
2920 __FUNCTION__); 2920 __FUNCTION__);
@@ -2937,7 +2937,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2937 qe_muram_alloc(sizeof 2937 qe_muram_alloc(sizeof
2938 (struct ucc_geth_rx_firmware_statistics_pram), 2938 (struct ucc_geth_rx_firmware_statistics_pram),
2939 UCC_GETH_RX_STATISTICS_ALIGNMENT); 2939 UCC_GETH_RX_STATISTICS_ALIGNMENT);
2940 if (IS_MURAM_ERR(ugeth->rx_fw_statistics_pram_offset)) { 2940 if (IS_ERR_VALUE(ugeth->rx_fw_statistics_pram_offset)) {
2941 ugeth_err 2941 ugeth_err
2942 ("%s: Can not allocate DPRAM memory for" 2942 ("%s: Can not allocate DPRAM memory for"
2943 " p_rx_fw_statistics_pram.", __FUNCTION__); 2943 " p_rx_fw_statistics_pram.", __FUNCTION__);
@@ -2959,7 +2959,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
2959 qe_muram_alloc(ug_info->numQueuesRx * 2959 qe_muram_alloc(ug_info->numQueuesRx *
2960 sizeof(struct ucc_geth_rx_interrupt_coalescing_entry) 2960 sizeof(struct ucc_geth_rx_interrupt_coalescing_entry)
2961 + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT); 2961 + 4, UCC_GETH_RX_INTERRUPT_COALESCING_ALIGNMENT);
2962 if (IS_MURAM_ERR(ugeth->rx_irq_coalescing_tbl_offset)) { 2962 if (IS_ERR_VALUE(ugeth->rx_irq_coalescing_tbl_offset)) {
2963 ugeth_err 2963 ugeth_err
2964 ("%s: Can not allocate DPRAM memory for" 2964 ("%s: Can not allocate DPRAM memory for"
2965 " p_rx_irq_coalescing_tbl.", __FUNCTION__); 2965 " p_rx_irq_coalescing_tbl.", __FUNCTION__);
@@ -3027,7 +3027,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3027 (sizeof(struct ucc_geth_rx_bd_queues_entry) + 3027 (sizeof(struct ucc_geth_rx_bd_queues_entry) +
3028 sizeof(struct ucc_geth_rx_prefetched_bds)), 3028 sizeof(struct ucc_geth_rx_prefetched_bds)),
3029 UCC_GETH_RX_BD_QUEUES_ALIGNMENT); 3029 UCC_GETH_RX_BD_QUEUES_ALIGNMENT);
3030 if (IS_MURAM_ERR(ugeth->rx_bd_qs_tbl_offset)) { 3030 if (IS_ERR_VALUE(ugeth->rx_bd_qs_tbl_offset)) {
3031 ugeth_err 3031 ugeth_err
3032 ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.", 3032 ("%s: Can not allocate DPRAM memory for p_rx_bd_qs_tbl.",
3033 __FUNCTION__); 3033 __FUNCTION__);
@@ -3116,7 +3116,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3116 ugeth->exf_glbl_param_offset = 3116 ugeth->exf_glbl_param_offset =
3117 qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram), 3117 qe_muram_alloc(sizeof(struct ucc_geth_exf_global_pram),
3118 UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT); 3118 UCC_GETH_RX_EXTENDED_FILTERING_GLOBAL_PARAMETERS_ALIGNMENT);
3119 if (IS_MURAM_ERR(ugeth->exf_glbl_param_offset)) { 3119 if (IS_ERR_VALUE(ugeth->exf_glbl_param_offset)) {
3120 ugeth_err 3120 ugeth_err
3121 ("%s: Can not allocate DPRAM memory for" 3121 ("%s: Can not allocate DPRAM memory for"
3122 " p_exf_glbl_param.", __FUNCTION__); 3122 " p_exf_glbl_param.", __FUNCTION__);
@@ -3258,7 +3258,7 @@ static int ucc_geth_startup(struct ucc_geth_private *ugeth)
3258 3258
3259 /* Allocate InitEnet command parameter structure */ 3259 /* Allocate InitEnet command parameter structure */
3260 init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4); 3260 init_enet_pram_offset = qe_muram_alloc(sizeof(struct ucc_geth_init_pram), 4);
3261 if (IS_MURAM_ERR(init_enet_pram_offset)) { 3261 if (IS_ERR_VALUE(init_enet_pram_offset)) {
3262 ugeth_err 3262 ugeth_err
3263 ("%s: Can not allocate DPRAM memory for p_init_enet_pram.", 3263 ("%s: Can not allocate DPRAM memory for p_init_enet_pram.",
3264 __FUNCTION__); 3264 __FUNCTION__);
@@ -3737,21 +3737,21 @@ static int ucc_geth_close(struct net_device *dev)
3737 3737
3738const struct ethtool_ops ucc_geth_ethtool_ops = { }; 3738const struct ethtool_ops ucc_geth_ethtool_ops = { };
3739 3739
3740static phy_interface_t to_phy_interface(const char *interface_type) 3740static phy_interface_t to_phy_interface(const char *phy_connection_type)
3741{ 3741{
3742 if (strcasecmp(interface_type, "mii") == 0) 3742 if (strcasecmp(phy_connection_type, "mii") == 0)
3743 return PHY_INTERFACE_MODE_MII; 3743 return PHY_INTERFACE_MODE_MII;
3744 if (strcasecmp(interface_type, "gmii") == 0) 3744 if (strcasecmp(phy_connection_type, "gmii") == 0)
3745 return PHY_INTERFACE_MODE_GMII; 3745 return PHY_INTERFACE_MODE_GMII;
3746 if (strcasecmp(interface_type, "tbi") == 0) 3746 if (strcasecmp(phy_connection_type, "tbi") == 0)
3747 return PHY_INTERFACE_MODE_TBI; 3747 return PHY_INTERFACE_MODE_TBI;
3748 if (strcasecmp(interface_type, "rmii") == 0) 3748 if (strcasecmp(phy_connection_type, "rmii") == 0)
3749 return PHY_INTERFACE_MODE_RMII; 3749 return PHY_INTERFACE_MODE_RMII;
3750 if (strcasecmp(interface_type, "rgmii") == 0) 3750 if (strcasecmp(phy_connection_type, "rgmii") == 0)
3751 return PHY_INTERFACE_MODE_RGMII; 3751 return PHY_INTERFACE_MODE_RGMII;
3752 if (strcasecmp(interface_type, "rgmii-id") == 0) 3752 if (strcasecmp(phy_connection_type, "rgmii-id") == 0)
3753 return PHY_INTERFACE_MODE_RGMII_ID; 3753 return PHY_INTERFACE_MODE_RGMII_ID;
3754 if (strcasecmp(interface_type, "rtbi") == 0) 3754 if (strcasecmp(phy_connection_type, "rtbi") == 0)
3755 return PHY_INTERFACE_MODE_RTBI; 3755 return PHY_INTERFACE_MODE_RTBI;
3756 3756
3757 return PHY_INTERFACE_MODE_MII; 3757 return PHY_INTERFACE_MODE_MII;
@@ -3787,7 +3787,7 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3787 3787
3788 ugeth_vdbg("%s: IN", __FUNCTION__); 3788 ugeth_vdbg("%s: IN", __FUNCTION__);
3789 3789
3790 prop = get_property(np, "device-id", NULL); 3790 prop = of_get_property(np, "device-id", NULL);
3791 ucc_num = *prop - 1; 3791 ucc_num = *prop - 1;
3792 if ((ucc_num < 0) || (ucc_num > 7)) 3792 if ((ucc_num < 0) || (ucc_num > 7))
3793 return -ENODEV; 3793 return -ENODEV;
@@ -3795,9 +3795,9 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3795 ug_info = &ugeth_info[ucc_num]; 3795 ug_info = &ugeth_info[ucc_num];
3796 ug_info->uf_info.ucc_num = ucc_num; 3796 ug_info->uf_info.ucc_num = ucc_num;
3797 3797
3798 prop = get_property(np, "rx-clock", NULL); 3798 prop = of_get_property(np, "rx-clock", NULL);
3799 ug_info->uf_info.rx_clock = *prop; 3799 ug_info->uf_info.rx_clock = *prop;
3800 prop = get_property(np, "tx-clock", NULL); 3800 prop = of_get_property(np, "tx-clock", NULL);
3801 ug_info->uf_info.tx_clock = *prop; 3801 ug_info->uf_info.tx_clock = *prop;
3802 err = of_address_to_resource(np, 0, &res); 3802 err = of_address_to_resource(np, 0, &res);
3803 if (err) 3803 if (err)
@@ -3806,42 +3806,34 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3806 ug_info->uf_info.regs = res.start; 3806 ug_info->uf_info.regs = res.start;
3807 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0); 3807 ug_info->uf_info.irq = irq_of_parse_and_map(np, 0);
3808 3808
3809 ph = get_property(np, "phy-handle", NULL); 3809 ph = of_get_property(np, "phy-handle", NULL);
3810 phy = of_find_node_by_phandle(*ph); 3810 phy = of_find_node_by_phandle(*ph);
3811 3811
3812 if (phy == NULL) 3812 if (phy == NULL)
3813 return -ENODEV; 3813 return -ENODEV;
3814 3814
3815 /* set the PHY address */ 3815 /* set the PHY address */
3816 prop = get_property(phy, "reg", NULL); 3816 prop = of_get_property(phy, "reg", NULL);
3817 if (prop == NULL) 3817 if (prop == NULL)
3818 return -1; 3818 return -1;
3819 ug_info->phy_address = *prop; 3819 ug_info->phy_address = *prop;
3820 3820
3821 /* get the phy interface type, or default to MII */ 3821 /* get the phy interface type, or default to MII */
3822 prop = get_property(np, "interface-type", NULL); 3822 prop = of_get_property(np, "phy-connection-type", NULL);
3823 if (!prop) { 3823 if (!prop) {
3824 /* handle interface property present in old trees */ 3824 /* handle interface property present in old trees */
3825 prop = get_property(phy, "interface", NULL); 3825 prop = of_get_property(phy, "interface", NULL);
3826 if (prop != NULL) 3826 if (prop != NULL) {
3827 phy_interface = enet_to_phy_interface[*prop]; 3827 phy_interface = enet_to_phy_interface[*prop];
3828 else 3828 max_speed = enet_to_speed[*prop];
3829 } else
3829 phy_interface = PHY_INTERFACE_MODE_MII; 3830 phy_interface = PHY_INTERFACE_MODE_MII;
3830 } else { 3831 } else {
3831 phy_interface = to_phy_interface((const char *)prop); 3832 phy_interface = to_phy_interface((const char *)prop);
3832 } 3833 }
3833 3834
3834 /* get speed, or derive from interface */ 3835 /* get speed, or derive from PHY interface */
3835 prop = get_property(np, "max-speed", NULL); 3836 if (max_speed == 0)
3836 if (!prop) {
3837 /* handle interface property present in old trees */
3838 prop = get_property(phy, "interface", NULL);
3839 if (prop != NULL)
3840 max_speed = enet_to_speed[*prop];
3841 } else {
3842 max_speed = *prop;
3843 }
3844 if (!max_speed) {
3845 switch (phy_interface) { 3837 switch (phy_interface) {
3846 case PHY_INTERFACE_MODE_GMII: 3838 case PHY_INTERFACE_MODE_GMII:
3847 case PHY_INTERFACE_MODE_RGMII: 3839 case PHY_INTERFACE_MODE_RGMII:
@@ -3854,9 +3846,9 @@ static int ucc_geth_probe(struct of_device* ofdev, const struct of_device_id *ma
3854 max_speed = SPEED_100; 3846 max_speed = SPEED_100;
3855 break; 3847 break;
3856 } 3848 }
3857 }
3858 3849
3859 if (max_speed == SPEED_1000) { 3850 if (max_speed == SPEED_1000) {
3851 /* configure muram FIFOs for gigabit operation */
3860 ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT; 3852 ug_info->uf_info.urfs = UCC_GETH_URFS_GIGA_INIT;
3861 ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT; 3853 ug_info->uf_info.urfet = UCC_GETH_URFET_GIGA_INIT;
3862 ug_info->uf_info.urfset = UCC_GETH_URFSET_GIGA_INIT; 3854 ug_info->uf_info.urfset = UCC_GETH_URFSET_GIGA_INIT;
diff --git a/drivers/net/ucc_geth_mii.c b/drivers/net/ucc_geth_mii.c
index 73b5a538e8f4..f96966d4bcc2 100644
--- a/drivers/net/ucc_geth_mii.c
+++ b/drivers/net/ucc_geth_mii.c
@@ -1,12 +1,13 @@
1/* 1/*
2 * drivers/net/ucc_geth_mii.c 2 * drivers/net/ucc_geth_mii.c
3 * 3 *
4 * Gianfar Ethernet Driver -- MIIM bus implementation 4 * QE UCC Gigabit Ethernet Driver -- MII Management Bus Implementation
5 * Provides Bus interface for MIIM regs 5 * Provides Bus interface for MII Management regs in the UCC register space
6 * 6 *
7 * Author: Li Yang 7 * Copyright (C) 2007 Freescale Semiconductor, Inc.
8 * 8 *
9 * Copyright (c) 2002-2004 Freescale Semiconductor, Inc. 9 * Authors: Li Yang <leoli@freescale.com>
10 * Kim Phillips <kim.phillips@freescale.com>
10 * 11 *
11 * This program is free software; you can redistribute it and/or modify it 12 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the 13 * under the terms of the GNU General Public License as published by the
@@ -172,7 +173,7 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
172 while ((child = of_get_next_child(np, child)) != NULL) { 173 while ((child = of_get_next_child(np, child)) != NULL) {
173 int irq = irq_of_parse_and_map(child, 0); 174 int irq = irq_of_parse_and_map(child, 0);
174 if (irq != NO_IRQ) { 175 if (irq != NO_IRQ) {
175 const u32 *id = get_property(child, "reg", NULL); 176 const u32 *id = of_get_property(child, "reg", NULL);
176 new_bus->irq[*id] = irq; 177 new_bus->irq[*id] = irq;
177 } 178 }
178 } 179 }
@@ -203,7 +204,7 @@ static int uec_mdio_probe(struct of_device *ofdev, const struct of_device_id *ma
203 if ((res.start >= tempres.start) && 204 if ((res.start >= tempres.start) &&
204 (res.end <= tempres.end)) { 205 (res.end <= tempres.end)) {
205 /* set this UCC to be the MII master */ 206 /* set this UCC to be the MII master */
206 const u32 *id = get_property(tempnp, "device-id", NULL); 207 const u32 *id = of_get_property(tempnp, "device-id", NULL);
207 if (id == NULL) 208 if (id == NULL)
208 goto bus_register_fail; 209 goto bus_register_fail;
209 210
diff --git a/drivers/net/ucc_geth_mii.h b/drivers/net/ucc_geth_mii.h
index 98430fe0bfc6..d83437039919 100644
--- a/drivers/net/ucc_geth_mii.h
+++ b/drivers/net/ucc_geth_mii.h
@@ -1,13 +1,13 @@
1/* 1/*
2 * drivers/net/ucc_geth_mii.h 2 * drivers/net/ucc_geth_mii.h
3 * 3 *
4 * Gianfar Ethernet Driver -- MII Management Bus Implementation 4 * QE UCC Gigabit Ethernet Driver -- MII Management Bus Implementation
5 * Driver for the MDIO bus controller in the Gianfar register space 5 * Provides Bus interface for MII Management regs in the UCC register space
6 * 6 *
7 * Author: Andy Fleming 7 * Copyright (C) 2007 Freescale Semiconductor, Inc.
8 * Maintainer: Kumar Gala
9 * 8 *
10 * Copyright (c) 2002-2004 Freescale Semiconductor, Inc. 9 * Authors: Li Yang <leoli@freescale.com>
10 * Kim Phillips <kim.phillips@freescale.com>
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify it 12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the 13 * under the terms of the GNU General Public License as published by the
diff --git a/drivers/usb/net/Kconfig b/drivers/net/usb/Kconfig
index 3de564b23147..3de564b23147 100644
--- a/drivers/usb/net/Kconfig
+++ b/drivers/net/usb/Kconfig
diff --git a/drivers/usb/net/Makefile b/drivers/net/usb/Makefile
index 595a539f8384..595a539f8384 100644
--- a/drivers/usb/net/Makefile
+++ b/drivers/net/usb/Makefile
diff --git a/drivers/usb/net/asix.c b/drivers/net/usb/asix.c
index d5ef97bc4d01..d5ef97bc4d01 100644
--- a/drivers/usb/net/asix.c
+++ b/drivers/net/usb/asix.c
diff --git a/drivers/usb/net/catc.c b/drivers/net/usb/catc.c
index 86e90c59d551..86e90c59d551 100644
--- a/drivers/usb/net/catc.c
+++ b/drivers/net/usb/catc.c
diff --git a/drivers/usb/net/cdc_ether.c b/drivers/net/usb/cdc_ether.c
index 5a21f06bf8a5..5a21f06bf8a5 100644
--- a/drivers/usb/net/cdc_ether.c
+++ b/drivers/net/usb/cdc_ether.c
diff --git a/drivers/usb/net/cdc_subset.c b/drivers/net/usb/cdc_subset.c
index bc62b012602b..bc62b012602b 100644
--- a/drivers/usb/net/cdc_subset.c
+++ b/drivers/net/usb/cdc_subset.c
diff --git a/drivers/usb/net/dm9601.c b/drivers/net/usb/dm9601.c
index a67638601477..a67638601477 100644
--- a/drivers/usb/net/dm9601.c
+++ b/drivers/net/usb/dm9601.c
diff --git a/drivers/usb/net/gl620a.c b/drivers/net/usb/gl620a.c
index 031cf5ca4dbb..031cf5ca4dbb 100644
--- a/drivers/usb/net/gl620a.c
+++ b/drivers/net/usb/gl620a.c
diff --git a/drivers/usb/net/kaweth.c b/drivers/net/usb/kaweth.c
index 60d29440f316..60d29440f316 100644
--- a/drivers/usb/net/kaweth.c
+++ b/drivers/net/usb/kaweth.c
diff --git a/drivers/usb/net/kawethfw.h b/drivers/net/usb/kawethfw.h
index cf85fcb0d1a6..cf85fcb0d1a6 100644
--- a/drivers/usb/net/kawethfw.h
+++ b/drivers/net/usb/kawethfw.h
diff --git a/drivers/usb/net/mcs7830.c b/drivers/net/usb/mcs7830.c
index 6240b978fe3d..6240b978fe3d 100644
--- a/drivers/usb/net/mcs7830.c
+++ b/drivers/net/usb/mcs7830.c
diff --git a/drivers/usb/net/net1080.c b/drivers/net/usb/net1080.c
index 19bf8dae70c9..19bf8dae70c9 100644
--- a/drivers/usb/net/net1080.c
+++ b/drivers/net/usb/net1080.c
diff --git a/drivers/usb/net/pegasus.c b/drivers/net/usb/pegasus.c
index a05fd97e5bc2..a05fd97e5bc2 100644
--- a/drivers/usb/net/pegasus.c
+++ b/drivers/net/usb/pegasus.c
diff --git a/drivers/usb/net/pegasus.h b/drivers/net/usb/pegasus.h
index c7467823cd1c..c7467823cd1c 100644
--- a/drivers/usb/net/pegasus.h
+++ b/drivers/net/usb/pegasus.h
diff --git a/drivers/usb/net/plusb.c b/drivers/net/usb/plusb.c
index 45300939d185..45300939d185 100644
--- a/drivers/usb/net/plusb.c
+++ b/drivers/net/usb/plusb.c
diff --git a/drivers/usb/net/rndis_host.c b/drivers/net/usb/rndis_host.c
index 980e4aaa97aa..980e4aaa97aa 100644
--- a/drivers/usb/net/rndis_host.c
+++ b/drivers/net/usb/rndis_host.c
diff --git a/drivers/usb/net/rtl8150.c b/drivers/net/usb/rtl8150.c
index fa598f0340cf..fa598f0340cf 100644
--- a/drivers/usb/net/rtl8150.c
+++ b/drivers/net/usb/rtl8150.c
diff --git a/drivers/usb/net/usbnet.c b/drivers/net/usb/usbnet.c
index f9cd42d058b0..f9cd42d058b0 100644
--- a/drivers/usb/net/usbnet.c
+++ b/drivers/net/usb/usbnet.c
diff --git a/drivers/usb/net/usbnet.h b/drivers/net/usb/usbnet.h
index cbb53e065d6c..82db5a8e528e 100644
--- a/drivers/usb/net/usbnet.h
+++ b/drivers/net/usb/usbnet.h
@@ -129,7 +129,7 @@ extern void usbnet_disconnect(struct usb_interface *);
129 129
130 130
131/* Drivers that reuse some of the standard USB CDC infrastructure 131/* Drivers that reuse some of the standard USB CDC infrastructure
132 * (notably, using multiple interfaces according to the the CDC 132 * (notably, using multiple interfaces according to the CDC
133 * union descriptor) get some helper code. 133 * union descriptor) get some helper code.
134 */ 134 */
135struct cdc_state { 135struct cdc_state {
diff --git a/drivers/usb/net/zaurus.c b/drivers/net/usb/zaurus.c
index 9f98e8ce487a..9f98e8ce487a 100644
--- a/drivers/usb/net/zaurus.c
+++ b/drivers/net/usb/zaurus.c
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index 8897f538a7c7..4fc8681bc110 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -2,10 +2,7 @@
2# wan devices configuration 2# wan devices configuration
3# 3#
4 4
5menu "Wan interfaces" 5menuconfig WAN
6 depends on NETDEVICES
7
8config WAN
9 bool "Wan interfaces support" 6 bool "Wan interfaces support"
10 ---help--- 7 ---help---
11 Wide Area Networks (WANs), such as X.25, Frame Relay and leased 8 Wide Area Networks (WANs), such as X.25, Frame Relay and leased
@@ -23,10 +20,12 @@ config WAN
23 20
24 If unsure, say N. 21 If unsure, say N.
25 22
23if WAN
24
26# There is no way to detect a comtrol sv11 - force it modular for now. 25# There is no way to detect a comtrol sv11 - force it modular for now.
27config HOSTESS_SV11 26config HOSTESS_SV11
28 tristate "Comtrol Hostess SV-11 support" 27 tristate "Comtrol Hostess SV-11 support"
29 depends on WAN && ISA && m && ISA_DMA_API && INET 28 depends on ISA && m && ISA_DMA_API && INET
30 help 29 help
31 Driver for Comtrol Hostess SV-11 network card which 30 Driver for Comtrol Hostess SV-11 network card which
32 operates on low speed synchronous serial links at up to 31 operates on low speed synchronous serial links at up to
@@ -38,7 +37,7 @@ config HOSTESS_SV11
38# The COSA/SRP driver has not been tested as non-modular yet. 37# The COSA/SRP driver has not been tested as non-modular yet.
39config COSA 38config COSA
40 tristate "COSA/SRP sync serial boards support" 39 tristate "COSA/SRP sync serial boards support"
41 depends on WAN && ISA && m && ISA_DMA_API 40 depends on ISA && m && ISA_DMA_API
42 ---help--- 41 ---help---
43 Driver for COSA and SRP synchronous serial boards. 42 Driver for COSA and SRP synchronous serial boards.
44 43
@@ -62,7 +61,7 @@ config COSA
62# 61#
63config LANMEDIA 62config LANMEDIA
64 tristate "LanMedia Corp. SSI/V.35, T1/E1, HSSI, T3 boards" 63 tristate "LanMedia Corp. SSI/V.35, T1/E1, HSSI, T3 boards"
65 depends on WAN && PCI 64 depends on PCI
66 ---help--- 65 ---help---
67 Driver for the following Lan Media family of serial boards: 66 Driver for the following Lan Media family of serial boards:
68 67
@@ -89,7 +88,7 @@ config LANMEDIA
89# There is no way to detect a Sealevel board. Force it modular 88# There is no way to detect a Sealevel board. Force it modular
90config SEALEVEL_4021 89config SEALEVEL_4021
91 tristate "Sealevel Systems 4021 support" 90 tristate "Sealevel Systems 4021 support"
92 depends on WAN && ISA && m && ISA_DMA_API && INET 91 depends on ISA && m && ISA_DMA_API && INET
93 help 92 help
94 This is a driver for the Sealevel Systems ACB 56 serial I/O adapter. 93 This is a driver for the Sealevel Systems ACB 56 serial I/O adapter.
95 94
@@ -99,7 +98,6 @@ config SEALEVEL_4021
99# Generic HDLC 98# Generic HDLC
100config HDLC 99config HDLC
101 tristate "Generic HDLC layer" 100 tristate "Generic HDLC layer"
102 depends on WAN
103 help 101 help
104 Say Y to this option if your Linux box contains a WAN (Wide Area 102 Say Y to this option if your Linux box contains a WAN (Wide Area
105 Network) card supported by this driver and you are planning to 103 Network) card supported by this driver and you are planning to
@@ -167,7 +165,7 @@ config HDLC_X25
167 If unsure, say N. 165 If unsure, say N.
168 166
169comment "X.25/LAPB support is disabled" 167comment "X.25/LAPB support is disabled"
170 depends on WAN && HDLC && (LAPB!=m || HDLC!=m) && LAPB!=y 168 depends on HDLC && (LAPB!=m || HDLC!=m) && LAPB!=y
171 169
172config PCI200SYN 170config PCI200SYN
173 tristate "Goramo PCI200SYN support" 171 tristate "Goramo PCI200SYN support"
@@ -230,10 +228,10 @@ config PC300_MLPPP
230 Multilink PPP over the PC300 synchronous communication boards. 228 Multilink PPP over the PC300 synchronous communication boards.
231 229
232comment "Cyclades-PC300 MLPPP support is disabled." 230comment "Cyclades-PC300 MLPPP support is disabled."
233 depends on WAN && HDLC && PC300 && (PPP=n || !PPP_MULTILINK || PPP_SYNC_TTY=n || !HDLC_PPP) 231 depends on HDLC && PC300 && (PPP=n || !PPP_MULTILINK || PPP_SYNC_TTY=n || !HDLC_PPP)
234 232
235comment "Refer to the file README.mlppp, provided by PC300 package." 233comment "Refer to the file README.mlppp, provided by PC300 package."
236 depends on WAN && HDLC && PC300 && (PPP=n || !PPP_MULTILINK || PPP_SYNC_TTY=n || !HDLC_PPP) 234 depends on HDLC && PC300 && (PPP=n || !PPP_MULTILINK || PPP_SYNC_TTY=n || !HDLC_PPP)
237 235
238config PC300TOO 236config PC300TOO
239 tristate "Cyclades PC300 RSV/X21 alternative support" 237 tristate "Cyclades PC300 RSV/X21 alternative support"
@@ -338,7 +336,6 @@ config DSCC4_PCI_RST
338 336
339config DLCI 337config DLCI
340 tristate "Frame Relay DLCI support" 338 tristate "Frame Relay DLCI support"
341 depends on WAN
342 ---help--- 339 ---help---
343 Support for the Frame Relay protocol. 340 Support for the Frame Relay protocol.
344 341
@@ -385,7 +382,7 @@ config SDLA
385# Wan router core. 382# Wan router core.
386config WAN_ROUTER_DRIVERS 383config WAN_ROUTER_DRIVERS
387 tristate "WAN router drivers" 384 tristate "WAN router drivers"
388 depends on WAN && WAN_ROUTER 385 depends on WAN_ROUTER
389 ---help--- 386 ---help---
390 Connect LAN to WAN via Linux box. 387 Connect LAN to WAN via Linux box.
391 388
@@ -440,7 +437,7 @@ config CYCLOMX_X25
440# X.25 network drivers 437# X.25 network drivers
441config LAPBETHER 438config LAPBETHER
442 tristate "LAPB over Ethernet driver (EXPERIMENTAL)" 439 tristate "LAPB over Ethernet driver (EXPERIMENTAL)"
443 depends on WAN && LAPB && X25 440 depends on LAPB && X25
444 ---help--- 441 ---help---
445 Driver for a pseudo device (typically called /dev/lapb0) which allows 442 Driver for a pseudo device (typically called /dev/lapb0) which allows
446 you to open an LAPB point-to-point connection to some other computer 443 you to open an LAPB point-to-point connection to some other computer
@@ -456,7 +453,7 @@ config LAPBETHER
456 453
457config X25_ASY 454config X25_ASY
458 tristate "X.25 async driver (EXPERIMENTAL)" 455 tristate "X.25 async driver (EXPERIMENTAL)"
459 depends on WAN && LAPB && X25 456 depends on LAPB && X25
460 ---help--- 457 ---help---
461 Send and receive X.25 frames over regular asynchronous serial 458 Send and receive X.25 frames over regular asynchronous serial
462 lines such as telephone lines equipped with ordinary modems. 459 lines such as telephone lines equipped with ordinary modems.
@@ -471,7 +468,7 @@ config X25_ASY
471 468
472config SBNI 469config SBNI
473 tristate "Granch SBNI12 Leased Line adapter support" 470 tristate "Granch SBNI12 Leased Line adapter support"
474 depends on WAN && X86 471 depends on X86
475 ---help--- 472 ---help---
476 Driver for ISA SBNI12-xx cards which are low cost alternatives to 473 Driver for ISA SBNI12-xx cards which are low cost alternatives to
477 leased line modems. 474 leased line modems.
@@ -497,5 +494,4 @@ config SBNI_MULTILINE
497 494
498 If unsure, say N. 495 If unsure, say N.
499 496
500endmenu 497endif # WAN
501
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index 23464735fa88..9ef49ce148b2 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -90,7 +90,6 @@
90#include <linux/ioport.h> 90#include <linux/ioport.h>
91#include <linux/netdevice.h> 91#include <linux/netdevice.h>
92#include <linux/spinlock.h> 92#include <linux/spinlock.h>
93#include <linux/smp_lock.h>
94#include <linux/device.h> 93#include <linux/device.h>
95 94
96#undef COSA_SLOW_IO /* for testing purposes only */ 95#undef COSA_SLOW_IO /* for testing purposes only */
diff --git a/drivers/net/wireless/Kconfig b/drivers/net/wireless/Kconfig
index 0184614517f9..e3f5bb0fe603 100644
--- a/drivers/net/wireless/Kconfig
+++ b/drivers/net/wireless/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "Wireless LAN" 5menu "Wireless LAN"
6 depends on !S390
6 7
7config WLAN_PRE80211 8config WLAN_PRE80211
8 bool "Wireless LAN (pre-802.11)" 9 bool "Wireless LAN (pre-802.11)"
@@ -267,7 +268,7 @@ config IPW2200_DEBUG
267 268
268config LIBERTAS_USB 269config LIBERTAS_USB
269 tristate "Marvell Libertas 8388 802.11a/b/g cards" 270 tristate "Marvell Libertas 8388 802.11a/b/g cards"
270 depends on NET_RADIO && USB 271 depends on USB && WLAN_80211
271 select FW_LOADER 272 select FW_LOADER
272 ---help--- 273 ---help---
273 A driver for Marvell Libertas 8388 USB devices. 274 A driver for Marvell Libertas 8388 USB devices.
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index f21bbafcb728..2d3a180dada0 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -25,7 +25,6 @@
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/proc_fs.h> 27#include <linux/proc_fs.h>
28#include <linux/smp_lock.h>
29 28
30#include <linux/sched.h> 29#include <linux/sched.h>
31#include <linux/ptrace.h> 30#include <linux/ptrace.h>
diff --git a/drivers/net/wireless/airport.c b/drivers/net/wireless/airport.c
index 38fac3bbcd82..7d5b8c2cc614 100644
--- a/drivers/net/wireless/airport.c
+++ b/drivers/net/wireless/airport.c
@@ -149,7 +149,7 @@ static int airport_hard_reset(struct orinoco_private *priv)
149 /* Vitally important. If we don't do this it seems we get an 149 /* Vitally important. If we don't do this it seems we get an
150 * interrupt somewhere during the power cycle, since 150 * interrupt somewhere during the power cycle, since
151 * hw_unavailable is already set it doesn't get ACKed, we get 151 * hw_unavailable is already set it doesn't get ACKed, we get
152 * into an interrupt loop and the the PMU decides to turn us 152 * into an interrupt loop and the PMU decides to turn us
153 * off. */ 153 * off. */
154 disable_irq(dev->irq); 154 disable_irq(dev->irq);
155 155
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx.h b/drivers/net/wireless/bcm43xx/bcm43xx.h
index f8483c179e4c..10e07e865426 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx.h
@@ -658,12 +658,6 @@ struct bcm43xx_pio {
658 658
659#define BCM43xx_MAX_80211_CORES 2 659#define BCM43xx_MAX_80211_CORES 2
660 660
661#ifdef CONFIG_BCM947XX
662#define core_offset(bcm) (bcm)->current_core_offset
663#else
664#define core_offset(bcm) 0
665#endif
666
667/* Generic information about a core. */ 661/* Generic information about a core. */
668struct bcm43xx_coreinfo { 662struct bcm43xx_coreinfo {
669 u8 available:1, 663 u8 available:1,
@@ -789,10 +783,6 @@ struct bcm43xx_private {
789 783
790 /* The currently active core. */ 784 /* The currently active core. */
791 struct bcm43xx_coreinfo *current_core; 785 struct bcm43xx_coreinfo *current_core;
792#ifdef CONFIG_BCM947XX
793 /** current core memory offset */
794 u32 current_core_offset;
795#endif
796 struct bcm43xx_coreinfo *active_80211_core; 786 struct bcm43xx_coreinfo *active_80211_core;
797 /* coreinfo structs for all possible cores follow. 787 /* coreinfo structs for all possible cores follow.
798 * Note that a core might not exist. 788 * Note that a core might not exist.
@@ -943,25 +933,25 @@ struct bcm43xx_lopair * bcm43xx_get_lopair(struct bcm43xx_phyinfo *phy,
943static inline 933static inline
944u16 bcm43xx_read16(struct bcm43xx_private *bcm, u16 offset) 934u16 bcm43xx_read16(struct bcm43xx_private *bcm, u16 offset)
945{ 935{
946 return ioread16(bcm->mmio_addr + core_offset(bcm) + offset); 936 return ioread16(bcm->mmio_addr + offset);
947} 937}
948 938
949static inline 939static inline
950void bcm43xx_write16(struct bcm43xx_private *bcm, u16 offset, u16 value) 940void bcm43xx_write16(struct bcm43xx_private *bcm, u16 offset, u16 value)
951{ 941{
952 iowrite16(value, bcm->mmio_addr + core_offset(bcm) + offset); 942 iowrite16(value, bcm->mmio_addr + offset);
953} 943}
954 944
955static inline 945static inline
956u32 bcm43xx_read32(struct bcm43xx_private *bcm, u16 offset) 946u32 bcm43xx_read32(struct bcm43xx_private *bcm, u16 offset)
957{ 947{
958 return ioread32(bcm->mmio_addr + core_offset(bcm) + offset); 948 return ioread32(bcm->mmio_addr + offset);
959} 949}
960 950
961static inline 951static inline
962void bcm43xx_write32(struct bcm43xx_private *bcm, u16 offset, u32 value) 952void bcm43xx_write32(struct bcm43xx_private *bcm, u16 offset, u32 value)
963{ 953{
964 iowrite32(value, bcm->mmio_addr + core_offset(bcm) + offset); 954 iowrite32(value, bcm->mmio_addr + offset);
965} 955}
966 956
967static inline 957static inline
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_dma.c b/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
index e3d2e61a31ee..1f7731fcfbd5 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_dma.c
@@ -660,10 +660,6 @@ struct bcm43xx_dmaring * bcm43xx_setup_dmaring(struct bcm43xx_private *bcm,
660 ring->routing = BCM43xx_DMA32_CLIENTTRANS; 660 ring->routing = BCM43xx_DMA32_CLIENTTRANS;
661 if (dma64) 661 if (dma64)
662 ring->routing = BCM43xx_DMA64_CLIENTTRANS; 662 ring->routing = BCM43xx_DMA64_CLIENTTRANS;
663#ifdef CONFIG_BCM947XX
664 if (bcm->pci_dev->bus->number == 0)
665 ring->routing = dma64 ? BCM43xx_DMA64_NOTRANS : BCM43xx_DMA32_NOTRANS;
666#endif
667 663
668 ring->bcm = bcm; 664 ring->bcm = bcm;
669 ring->nr_slots = nr_slots; 665 ring->nr_slots = nr_slots;
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.c b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
index 5e96bca6730a..ef6b253a92ce 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.c
@@ -61,10 +61,6 @@ MODULE_AUTHOR("Stefano Brivio");
61MODULE_AUTHOR("Michael Buesch"); 61MODULE_AUTHOR("Michael Buesch");
62MODULE_LICENSE("GPL"); 62MODULE_LICENSE("GPL");
63 63
64#ifdef CONFIG_BCM947XX
65extern char *nvram_get(char *name);
66#endif
67
68#if defined(CONFIG_BCM43XX_DMA) && defined(CONFIG_BCM43XX_PIO) 64#if defined(CONFIG_BCM43XX_DMA) && defined(CONFIG_BCM43XX_PIO)
69static int modparam_pio; 65static int modparam_pio;
70module_param_named(pio, modparam_pio, int, 0444); 66module_param_named(pio, modparam_pio, int, 0444);
@@ -142,10 +138,6 @@ MODULE_PARM_DESC(fwpostfix, "Postfix for .fw files. Useful for using multiple fi
142 { PCI_VENDOR_ID_BROADCOM, 0x4324, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 138 { PCI_VENDOR_ID_BROADCOM, 0x4324, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
143 /* Broadcom 43XG 802.11b/g */ 139 /* Broadcom 43XG 802.11b/g */
144 { PCI_VENDOR_ID_BROADCOM, 0x4325, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 140 { PCI_VENDOR_ID_BROADCOM, 0x4325, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
145#ifdef CONFIG_BCM947XX
146 /* SB bus on BCM947xx */
147 { PCI_VENDOR_ID_BROADCOM, 0x0800, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
148#endif
149 { 0 }, 141 { 0 },
150}; 142};
151MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl); 143MODULE_DEVICE_TABLE(pci, bcm43xx_pci_tbl);
@@ -786,9 +778,6 @@ static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
786{ 778{
787 u16 value; 779 u16 value;
788 u16 *sprom; 780 u16 *sprom;
789#ifdef CONFIG_BCM947XX
790 char *c;
791#endif
792 781
793 sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16), 782 sprom = kzalloc(BCM43xx_SPROM_SIZE * sizeof(u16),
794 GFP_KERNEL); 783 GFP_KERNEL);
@@ -796,28 +785,7 @@ static int bcm43xx_sprom_extract(struct bcm43xx_private *bcm)
796 printk(KERN_ERR PFX "sprom_extract OOM\n"); 785 printk(KERN_ERR PFX "sprom_extract OOM\n");
797 return -ENOMEM; 786 return -ENOMEM;
798 } 787 }
799#ifdef CONFIG_BCM947XX
800 sprom[BCM43xx_SPROM_BOARDFLAGS2] = atoi(nvram_get("boardflags2"));
801 sprom[BCM43xx_SPROM_BOARDFLAGS] = atoi(nvram_get("boardflags"));
802
803 if ((c = nvram_get("il0macaddr")) != NULL)
804 e_aton(c, (char *) &(sprom[BCM43xx_SPROM_IL0MACADDR]));
805
806 if ((c = nvram_get("et1macaddr")) != NULL)
807 e_aton(c, (char *) &(sprom[BCM43xx_SPROM_ET1MACADDR]));
808
809 sprom[BCM43xx_SPROM_PA0B0] = atoi(nvram_get("pa0b0"));
810 sprom[BCM43xx_SPROM_PA0B1] = atoi(nvram_get("pa0b1"));
811 sprom[BCM43xx_SPROM_PA0B2] = atoi(nvram_get("pa0b2"));
812
813 sprom[BCM43xx_SPROM_PA1B0] = atoi(nvram_get("pa1b0"));
814 sprom[BCM43xx_SPROM_PA1B1] = atoi(nvram_get("pa1b1"));
815 sprom[BCM43xx_SPROM_PA1B2] = atoi(nvram_get("pa1b2"));
816
817 sprom[BCM43xx_SPROM_BOARDREV] = atoi(nvram_get("boardrev"));
818#else
819 bcm43xx_sprom_read(bcm, sprom); 788 bcm43xx_sprom_read(bcm, sprom);
820#endif
821 789
822 /* boardflags2 */ 790 /* boardflags2 */
823 value = sprom[BCM43xx_SPROM_BOARDFLAGS2]; 791 value = sprom[BCM43xx_SPROM_BOARDFLAGS2];
@@ -1225,12 +1193,6 @@ static int _switch_core(struct bcm43xx_private *bcm, int core)
1225 goto error; 1193 goto error;
1226 udelay(10); 1194 udelay(10);
1227 } 1195 }
1228#ifdef CONFIG_BCM947XX
1229 if (bcm->pci_dev->bus->number == 0)
1230 bcm->current_core_offset = 0x1000 * core;
1231 else
1232 bcm->current_core_offset = 0;
1233#endif
1234 1196
1235 return 0; 1197 return 0;
1236error: 1198error:
@@ -1387,19 +1349,6 @@ void bcm43xx_wireless_core_reset(struct bcm43xx_private *bcm, int connect_phy)
1387 1349
1388 if ((bcm43xx_core_enabled(bcm)) && 1350 if ((bcm43xx_core_enabled(bcm)) &&
1389 !bcm43xx_using_pio(bcm)) { 1351 !bcm43xx_using_pio(bcm)) {
1390//FIXME: Do we _really_ want #ifndef CONFIG_BCM947XX here?
1391#if 0
1392#ifndef CONFIG_BCM947XX
1393 /* reset all used DMA controllers. */
1394 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
1395 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA2_BASE);
1396 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA3_BASE);
1397 bcm43xx_dmacontroller_tx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
1398 bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA1_BASE);
1399 if (bcm->current_core->rev < 5)
1400 bcm43xx_dmacontroller_rx_reset(bcm, BCM43xx_MMIO_DMA4_BASE);
1401#endif
1402#endif
1403 } 1352 }
1404 if (bcm43xx_status(bcm) == BCM43xx_STAT_SHUTTINGDOWN) { 1353 if (bcm43xx_status(bcm) == BCM43xx_STAT_SHUTTINGDOWN) {
1405 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD, 1354 bcm43xx_write32(bcm, BCM43xx_MMIO_STATUS_BITFIELD,
@@ -2140,32 +2089,11 @@ out:
2140 return err; 2089 return err;
2141} 2090}
2142 2091
2143#ifdef CONFIG_BCM947XX
2144static struct pci_device_id bcm43xx_47xx_ids[] = {
2145 { PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, 0x4324) },
2146 { 0 }
2147};
2148#endif
2149
2150static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm) 2092static int bcm43xx_initialize_irq(struct bcm43xx_private *bcm)
2151{ 2093{
2152 int err; 2094 int err;
2153 2095
2154 bcm->irq = bcm->pci_dev->irq; 2096 bcm->irq = bcm->pci_dev->irq;
2155#ifdef CONFIG_BCM947XX
2156 if (bcm->pci_dev->bus->number == 0) {
2157 struct pci_dev *d;
2158 struct pci_device_id *id;
2159 for (id = bcm43xx_47xx_ids; id->vendor; id++) {
2160 d = pci_get_device(id->vendor, id->device, NULL);
2161 if (d != NULL) {
2162 bcm->irq = d->irq;
2163 pci_dev_put(d);
2164 break;
2165 }
2166 }
2167 }
2168#endif
2169 err = request_irq(bcm->irq, bcm43xx_interrupt_handler, 2097 err = request_irq(bcm->irq, bcm43xx_interrupt_handler,
2170 IRQF_SHARED, KBUILD_MODNAME, bcm); 2098 IRQF_SHARED, KBUILD_MODNAME, bcm);
2171 if (err) 2099 if (err)
@@ -2645,10 +2573,6 @@ static int bcm43xx_probe_cores(struct bcm43xx_private *bcm)
2645 chip_id_16 = 0x4610; 2573 chip_id_16 = 0x4610;
2646 else if ((pci_device >= 0x4710) && (pci_device <= 0x4715)) 2574 else if ((pci_device >= 0x4710) && (pci_device <= 0x4715))
2647 chip_id_16 = 0x4710; 2575 chip_id_16 = 0x4710;
2648#ifdef CONFIG_BCM947XX
2649 else if ((pci_device >= 0x4320) && (pci_device <= 0x4325))
2650 chip_id_16 = 0x4309;
2651#endif
2652 else { 2576 else {
2653 printk(KERN_ERR PFX "Could not determine Chip ID\n"); 2577 printk(KERN_ERR PFX "Could not determine Chip ID\n");
2654 return -ENODEV; 2578 return -ENODEV;
@@ -4144,11 +4068,6 @@ static int __devinit bcm43xx_init_one(struct pci_dev *pdev,
4144 struct bcm43xx_private *bcm; 4068 struct bcm43xx_private *bcm;
4145 int err; 4069 int err;
4146 4070
4147#ifdef CONFIG_BCM947XX
4148 if ((pdev->bus->number == 0) && (pdev->device != 0x0800))
4149 return -ENODEV;
4150#endif
4151
4152#ifdef DEBUG_SINGLE_DEVICE_ONLY 4071#ifdef DEBUG_SINGLE_DEVICE_ONLY
4153 if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY)) 4072 if (strcmp(pci_name(pdev), DEBUG_SINGLE_DEVICE_ONLY))
4154 return -ENODEV; 4073 return -ENODEV;
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_main.h b/drivers/net/wireless/bcm43xx/bcm43xx_main.h
index f76357178e4d..c8f3c532bab5 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_main.h
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_main.h
@@ -33,25 +33,6 @@
33 33
34#include "bcm43xx.h" 34#include "bcm43xx.h"
35 35
36#ifdef CONFIG_BCM947XX
37#define atoi(str) simple_strtoul(((str != NULL) ? str : ""), NULL, 0)
38
39static inline void e_aton(char *str, char *dest)
40{
41 int i = 0;
42 u16 *d = (u16 *) dest;
43
44 for (;;) {
45 dest[i++] = (char) simple_strtoul(str, NULL, 16);
46 str += 2;
47 if (!*str++ || i == 6)
48 break;
49 }
50 for (i = 0; i < 3; i++)
51 d[i] = cpu_to_be16(d[i]);
52}
53#endif
54
55#define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes] 36#define P4D_BYT3S(magic, nr_bytes) u8 __p4dding##magic[nr_bytes]
56#define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes) 37#define P4D_BYTES(line, nr_bytes) P4D_BYT3S(line, nr_bytes)
57/* Magic helper macro to pad structures. Ignore those above. It's magic. */ 38/* Magic helper macro to pad structures. Ignore those above. It's magic. */
diff --git a/drivers/net/wireless/hostap/hostap_ioctl.c b/drivers/net/wireless/hostap/hostap_ioctl.c
index cb08bc5db2bd..cdea7f71b9eb 100644
--- a/drivers/net/wireless/hostap/hostap_ioctl.c
+++ b/drivers/net/wireless/hostap/hostap_ioctl.c
@@ -1,7 +1,6 @@
1/* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */ 1/* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
2 2
3#include <linux/types.h> 3#include <linux/types.h>
4#include <linux/smp_lock.h>
5#include <linux/ethtool.h> 4#include <linux/ethtool.h>
6#include <net/ieee80211_crypt.h> 5#include <net/ieee80211_crypt.h>
7 6
diff --git a/drivers/net/wireless/libertas/Makefile b/drivers/net/wireless/libertas/Makefile
index 19c935071d8e..56a8ea1fbf04 100644
--- a/drivers/net/wireless/libertas/Makefile
+++ b/drivers/net/wireless/libertas/Makefile
@@ -1,5 +1,3 @@
1# EXTRA_CFLAGS += -Wpacked
2
3usb8xxx-objs := main.o fw.o wext.o \ 1usb8xxx-objs := main.o fw.o wext.o \
4 rx.o tx.o cmd.o \ 2 rx.o tx.o cmd.o \
5 cmdresp.o scan.o \ 3 cmdresp.o scan.o \
@@ -7,13 +5,6 @@ usb8xxx-objs := main.o fw.o wext.o \
7 ioctl.o debugfs.o \ 5 ioctl.o debugfs.o \
8 ethtool.o assoc.o 6 ethtool.o assoc.o
9 7
10ifeq ($(CONFIG_LIBERTAS_USB_DEBUG), y)
11EXTRA_CFLAGS += -DDEBUG -DPROC_DEBUG
12endif
13
14
15# This is needed to support the newer boot2 bootloader (v >= 3104)
16EXTRA_CFLAGS += -DSUPPORT_BOOT_COMMAND
17usb8xxx-objs += if_bootcmd.o 8usb8xxx-objs += if_bootcmd.o
18usb8xxx-objs += if_usb.o 9usb8xxx-objs += if_usb.o
19 10
diff --git a/drivers/net/wireless/libertas/README b/drivers/net/wireless/libertas/README
index 688da4c784b1..378577200b56 100644
--- a/drivers/net/wireless/libertas/README
+++ b/drivers/net/wireless/libertas/README
@@ -40,64 +40,11 @@ NAME
40SYNOPSIS 40SYNOPSIS
41 iwpriv <ethX> <command> [sub-command] ... 41 iwpriv <ethX> <command> [sub-command] ...
42 42
43 iwpriv ethX version
44 iwpriv ethX scantype [sub-command]
45 iwpriv ethX getSNR <n>
46 iwpriv ethX getNF <n>
47 iwpriv ethX getRSSI <n>
48 iwpriv ethX setrxant <n>
49 iwpriv ethX getrxant
50 iwpriv ethX settxant <n>
51 iwpriv ethX gettxant
52 iwpriv ethX authalgs <n>
53 iwpriv ethX pre-TBTT <n>
54 iwpriv ethX 8021xauthalgs <n>
55 iwpriv ethX encryptionmode <n>
56 iwpriv ethX setregioncode <n> 43 iwpriv ethX setregioncode <n>
57 iwpriv ethX getregioncode 44 iwpriv ethX getregioncode
58 iwpriv ethX setbcnavg <n>
59 iwpriv ethX getbcnavg
60 iwpriv ethX setdataavg <n>
61 iwpriv ethX setlisteninter <n>
62 iwpriv ethX getlisteninter
63 iwpriv ethX setmultipledtim <n>
64 iwpriv ethX getmultipledtim
65 iwpriv ethX atimwindow <n>
66 iwpriv ethX deauth
67 iwpriv ethX adhocstop
68 iwpriv ethX radioon
69 iwpriv ethX radiooff
70 iwpriv ethX reasso-on
71 iwpriv ethX reasso-off
72 iwpriv ethX scanmode [sub-command]
73 iwpriv ethX setwpaie <n>
74 iwpriv ethX wlanidle-off
75 iwpriv ethX wlanidle-on
76 iwpriv ethX getcis
77 iwpriv ethX getlog
78 iwpriv ethX getadhocstatus
79 iwpriv ethX adhocgrate <n>
80
81Version 4 Command:
82 iwpriv ethX inactvityto <n>
83 iwpriv ethX sleeppd <n>
84 iwpriv ethX enable11d <n>
85 iwpriv ethX tpccfg <n>
86 iwpriv ethX powercfg <n>
87 iwpriv ethX setafc <n>
88 iwpriv ethX getafc
89 45
90Version 5 Command: 46Version 5 Command:
91 iwpriv ethX ledgpio <n> 47 iwpriv ethX ledgpio <n>
92 iwpriv ethX scanprobes <n>
93 iwpriv ethX lolisteninter <n>
94 iwpriv ethX rateadapt <n> <m>
95 iwpriv ethX txcontrol <n>
96 iwpriv ethX psnullinterval <n>
97 iwpriv ethX prescan <n>
98 iwpriv ethX getrxinfo
99 iwpriv ethX gettxrate
100 iwpriv ethX beaconinterval
101 48
102BT Commands: 49BT Commands:
103 The blinding table (BT) contains a list of mac addresses that should be 50 The blinding table (BT) contains a list of mac addresses that should be
@@ -150,114 +97,6 @@ DESCRIPTION
150 The ethX parameter specifies the network device that is to be used to 97 The ethX parameter specifies the network device that is to be used to
151 perform this command on. it could be eth0, eth1 etc. 98 perform this command on. it could be eth0, eth1 etc.
152 99
153version
154 This is used to get the current version of the driver and the firmware.
155
156scantype
157 This command is used to set the scan type to be used by the driver in
158 the scan command. This setting will not be used while performing a scan
159 for a specific SSID, as it is always done with scan type being active.
160
161 where the sub-commands are: -
162 active -- to set the scan type to active
163 passive -- to set the scan type to passive
164 get -- to get the scan type set in the driver
165
166getSNR
167 This command gets the average and non average value of Signal to Noise
168 Ratio of Beacon and Data.
169
170 where value is:-
171 0 -- Beacon non-average.
172 1 -- Beacon average.
173 2 -- Data non-average.
174 3 -- Data average.
175
176 If no value is given, all four values are returned in the order mentioned
177 above.
178
179 Note: This command is available only when STA is connected.
180
181getRSSI
182 This command gets the average and non average value os Receive Signal
183 Strength of Beacon and Data.
184
185 where value is:-
186 0 -- Beacon non-average.
187 1 -- Beacon average.
188 2 -- Data non-average.
189 3 -- Data average.
190
191 Note: This command is available only when STA is connected.
192
193getNF
194 This command gets the average and non average value of Noise Floor of
195 Beacon and Data.
196
197 where value is:-
198 0 -- Beacon non-average.
199 1 -- Beacon average.
200 2 -- Data non-average.
201 3 -- Data average.
202
203 Note: This command is available only when STA is connected.
204
205setrxant
206 This command is used to set the mode for Rx antenna.
207
208 The options that can be sent are:-
209 1 -- Antenna 1.
210 2 -- Antenna 2.
211 0xFFFF -- Diversity.
212
213 Usage:
214 iwpriv ethX setrxant 0x01: select Antenna 1.
215
216getrxant
217 This command is used to get the mode for Rx antenna.
218
219
220settxant
221 This command is used to set the mode for Tx antenna.
222 The options that can be sent are:-
223 1 -- Antenna 1.
224 2 -- Antenna 2.
225 0xFFFF -- Diversity.
226 Usage:
227 iwpriv ethX settxant 0x01: select Antenna 1.
228
229gettxant
230 This command is used to get the mode for Tx antenna.
231
232authalgs
233 This command is used by the WPA supplicant to set the authentication
234 algorithms in the station.
235
2368021xauthalgs
237 This command is used by the WPA supplicant to set the 8021.x authentication algorithm type
238 station.
239
240 where values can be:-
241 1 -- None
242 2 -- LEAP
243 4 -- TLS
244 8 -- TTLs
245 16 -- MD5
246
247
248encryptionmode
249 This command is used by the WPA supplicant to set the encryption algorithm.
250
251 where values can be:-
252 0 -- NONE
253 1 -- WEP40
254 2 -- TKIP
255 3 -- CCMP
256 4 -- WEP104
257
258pre-TBTT
259 This command is used to set pre-TBTT time period where value is in microseconds.
260
261setregioncode 100setregioncode
262 This command is used to set the region code in the station. 101 This command is used to set the region code in the station.
263 where value is 'region code' for various regions like 102 where value is 'region code' for various regions like
@@ -270,114 +109,6 @@ getregioncode
270 This command is used to get the region code information set in the 109 This command is used to get the region code information set in the
271 station. 110 station.
272 111
273setbcnavg
274 Set the weighting factor for calculating RSSI.
275
276getbcnavg
277 Get weighting factor for calculating RSSI.
278
279setdataavg
280 Set the weighting factor for calculating SNR.
281
282setlisteninter
283 This command is used to set the listen interval in the
284 station.
285
286 where the value ranges between 1 - 255
287
288getlisteninter
289 This command is used to get the listen interval value set in the
290 station.
291
292setmultipledtim
293 This command is used to set the multiple dtim value in the
294 station.
295 where the value is 1,2,3,4,5,0xfffe
296 0xfffe means the firmware will use listen interval in association
297 command for waking up
298
299getmultipledtim
300 This command is used to get the multiple dtim value set in the station.
301
302atimwindow
303 This command is used to set the atim value in the
304 station.
305
306 where the value ranges between 0 - 50
307
308deauth
309 This command is used to send the de-authentication to the AP with which
310 the station is associated. This command is valid only when
311 station is in Infrastructure mode.
312
313 Note: This command is available only when STA is connected.
314
315adhocstop
316 This command is used to stop beacon transmission from the station and
317 go into idle state in ad-hoc mode.
318
319 Note: This command is available only when STA is connected.
320
321radioon
322 This command is used to turn on the RF antenna.
323
324radiooff
325 This command is sued to turn off the RF antenna.
326
327scanmode
328 This command is used to set the station to scan for either IBSS
329 networks or BSS networks or both BSS and IBSS networks. This
330 command can be used with sub commands,
331
332 where the value for
333 bss -- Scan All the BSS networks.
334 ibss -- Scan All the IBSS networks.
335 any -- Scan both BSS and IBSS networks.
336
337
338
339setwpaie
340 This command is used by WPA supplicant to send the WPA-IE to the driver.
341
342wlanidle-off
343 This command is used to get into idle state.
344
345 Note: This command is available only when STA is connected.
346
347wlanidle-on
348 This command is used to get off the idle state.
349
350 Note: This command is available only when STA is connected.
351
352
353getlog
354 This command is used to get the 802.11 statistics available in the
355 station.
356
357 Note: This command is available only when STA is connected.
358
359getadhocstatus
360 This command is used to get the ad-hoc Network Status.
361
362 The various status codes are:
363 AdhocStarted
364 AdhocJoined
365 AdhocIdle
366 InfraMode
367 AutoUnknownMode
368
369 Note: This command is available only when STA is connected.
370
371adhocgrate
372 This command is used to enable(1) g_rate, Disable(0) g_rate
373 and request(2) the status which g_rate is disabled/enabled,
374 for Ad-hoc creator.
375
376 where value is:-
377 0 -- Disabled
378 1 -- Enabled
379 2 -- Get
380
381ledgpio 112ledgpio
382 This command is used to set/get LEDs. 113 This command is used to set/get LEDs.
383 114
@@ -400,253 +131,6 @@ ledgpio
400 Note: LED0 is invalid 131 Note: LED0 is invalid
401 Note: Maximum Number of LEDs are 16. 132 Note: Maximum Number of LEDs are 16.
402 133
403inactivityto
404 This command is used by the host to set/get the inactivity timeout value,
405 which specifies when WLAN device is put to sleep.
406
407 Usage:
408 iwpriv ethX inactivityto [<timeout>]
409
410 where the parameter are:
411 timeout: timeout value in milliseconds.
412
413 Example:
414 iwpriv eth1 inactivityto
415 "get the timeout value"
416
417 iwpriv eth1 inactivityto X
418 "set timeout value to X ms"
419
420
421sleeppd
422 This command is used to configure the sleep period of the WLAN device.
423
424 Usage:
425 iwpriv ethX sleeppd [<sleep period>]
426
427 where the parameter are:
428 Period: sleep period in milliseconds. Range 10~60.
429
430 Example:
431 iwpriv eth1 sleeppd 10
432 "set period as 10 ms"
433 iwpriv eth1 sleeppd
434 "get the sleep period configuration"
435
436enable11d
437 This command is used to control 11d
438 where value is:-
439 1 -- Enabled
440 0 -- Disabled
441 2 -- Get
442
443
444
445
446tpccfg
447 Enables or disables automatic transmit power control.
448
449 The first parameter turns this feature on (1) or off (0). When turning
450 on, the user must also supply four more parameters in the following
451 order:
452 -UseSNR (Use SNR (in addition to PER) for TPC algorithm),
453 -P0 (P0 power level for TPC),
454 -P1 (P1 power level for TPC),
455 -P2 (P2 power level for TPC).
456
457 Usage:
458 iwpriv ethX tpccfg: Get current configuration
459 iwpriv ethX tpccfg 0: disable auto TPC
460 iwpriv ethX tpccfg 0x01 0x00 0x05 0x0a 0x0d: enable auto TPC; do not use SNR;
461 P0=0x05; P1=0x0a; P2=0x0d;
462 iwpriv ethX tpccfg 0x01 0x01 0x05 0x0a 0x0d: enable auto TPC; use SNR;
463 P0=0x05; P1=0x0a; P2=0x0d.
464
465powercfg
466 Enables or disables power adaptation.
467
468 The first parameter turns this feature on (1) or off (0). When turning
469 on, the user must also supply three more parameters in the following
470 order:
471 -P0 (P0 power level for Power Adaptation),
472 -P1 (P1 power level for Power Adaptation),
473 -P2 (P2 power level for Power Adaptation).
474
475 Usage:
476 iwpriv ethX powercfg: Get current configuration
477 iwpriv ethX powercfg 0: disable power adaptation
478 iwpriv ethX powercfg 1 0x0d 0x0f 0x12: enable power adaptation;
479 P0=0x0d; P1=0x0f; P2=0x12.
480
481getafc
482 This command returns automatic frequency control parameters. It returns
483 three integers:
484 -P0: automatic is on (1), or off (0),
485 -P1: current timing offset in PPM (part per million), and
486 -P2: current frequency offset in PPM.
487
488setafc
489 Set automatic frequency control options.
490
491 The first parameter turns automatic on (1) or off (0).
492 The user must supply two more parameters in either case, in the following
493 order:
494
495 When auto is on:
496
497 -P0 (automatic adjustment frequency threshold in PPM),
498 -P1 (automatic adjustment period in beacon period),
499
500 When auto is off:
501
502 -P0 (manual adjustment timing offset in PPM), and
503 -P1 (manual adjustment frequency offset in PPM).
504
505 Usage:
506 iwpriv ethX setafc 0 10 10: manual adjustment, both timing and frequcncy
507 offset are 10 PPM.
508
509 iwpriv ethX setafc 1 10 10 enable afc, automatic adjustment,
510 frequency threshold 10 PPM, for every 10 beacon periods.
511
512
513
514scanprobes
515 This command sets number of probe requests per channel.
516
517 Usage:
518 iwpriv ethX scanprobes 3 (set scan probes to 3)
519 iwpriv ethX scanprobes (get scan probes)
520
521lolisteninter
522 This command sets the value of listen interval.
523
524 Usage:
525 iwpriv ethX lolisteninter 234 (set the lolisteninter to 234)
526 iwpriv ethX lolisteninter (get the lolisteninter value)
527
528rateadapt
529 This command sets the data rates bitmap.
530 Where <n>
531 0: Disable auto rate adapt
532 1: Enable auto rate adapt
533
534 <m>
535 data rate bitmap
536 Bit Data rate
537 0 1 Mbps
538 1 2 Mbps
539 2 5.5 Mbps
540 3 11 Mbps
541 4 Reserved
542 5 6 Mbps
543 6 9 Mbps
544 7 12 Mbps
545 8 18 Mbps
546 9 24 Mbps
547 10 36 Mbps
548 11 48 Mbps
549 12 54 Mbps
550 12-15 Reserved
551
552 Usage:
553 iwpriv ethX rateadapt
554 read the currect data rate setting
555 iwpriv ethX rateadapt 1 0x07
556 enable auto data rate adapt and
557 data rates are 1Mbps, 2Mbsp and 5.5Mbps
558
559
560txcontrol
561 This command is used to set the Tx rate, ack policy, and retry limit on a per packet basis.
562
563 Where value <n> is:
564 if bit[4] == 1:
565 bit[3:0] -- 0 1 2 3 4 5 6 7 8 9 10 11 12 13-16
566 Data Rate(Mbps) -- 1 2 5.5 11 Rsv 6 9 12 18 24 36 48 54 Rsv
567
568 bit[12:8]
569 if bit[12] == 1, bit[11:8] specifies the Tx retry limit.
570
571 bit[14:13] specifies per packet ack policy:
572 bit[14:13]
573 1 0 use immediate ack policy for this packet
574 1 1 use no ack policy for this packet
575 0 x use the per-packet ack policy setting
576
577 Usage:
578 iwpriv ethX txcontrol 0x7513
579 Use no-ack policy, 5 retires for Tx, 11Mbps rate
580
581
582
583psnullinterval
584 This command is used to set/request NULL package interval for Power Save
585 under infrastructure mode.
586
587 where value is:-
588 -1 -- Disabled
589 n>0 -- Set interval as n (seconds)
590
591prescan
592 This command is used to enable (1)/disable(0) auto prescan before assoicate to the ap
593
594 where value is:-
595 0 -- Disabled
596 1 -- Enabled
597 2 -- Get
598
599getrxinfo
600 This command gets non average value of Signal to Noise Ratio of Data and rate index.
601
602 The following table shows RateIndex and Rate
603
604 RateIndex Data rate
605 0 1 Mbps
606 1 2 Mbps
607 2 5.5 Mbps
608 3 11 Mbps
609 4 Reserved
610 5 6 Mbps
611 6 9 Mbps
612 7 12 Mbps
613 8 18 Mbps
614 9 24 Mbps
615 10 36 Mbps
616 11 48 Mbps
617 12 54 Mbps
618 13-15 Reserved
619
620gettxrate
621 This command gets current Tx rate index of the first packet associated with Rate Adaptation.
622
623 The following table shows RateIndex and Rate
624
625 RateIndex Data rate
626 0 1 Mbps
627 1 2 Mbps
628 2 5.5 Mbps
629 3 11 Mbps
630 4 Reserved
631 5 6 Mbps
632 6 9 Mbps
633 7 12 Mbps
634 8 18 Mbps
635 9 24 Mbps
636 10 36 Mbps
637 11 48 Mbps
638 12 54 Mbps
639 13-15 Reserved
640
641bcninterval
642 This command is used to sets beacon interval in adhoc mode when an argument is given, and gets current adhoc
643 beacon interval when no argument is given. The valid beacon interval is between 20 - 1000,
644 default beacon interval is 100.
645
646 Usage:
647 iwpriv ethX bcninterval 100 (set adhoc beacon interval to 100)
648 iwpriv ethX bcninterval (get adhoc beacon interval)
649
650fwt_add 134fwt_add
651 This command is used to insert an entry into the FWT table. The list of 135 This command is used to insert an entry into the FWT table. The list of
652 parameters must follow the following structure: 136 parameters must follow the following structure:
diff --git a/drivers/net/wireless/libertas/assoc.c b/drivers/net/wireless/libertas/assoc.c
index b55c7f57aca8..c260bd1b3d46 100644
--- a/drivers/net/wireless/libertas/assoc.c
+++ b/drivers/net/wireless/libertas/assoc.c
@@ -23,13 +23,13 @@ static int assoc_helper_essid(wlan_private *priv,
23 ENTER(); 23 ENTER();
24 24
25 lbs_pr_debug(1, "New SSID requested: %s\n", assoc_req->ssid.ssid); 25 lbs_pr_debug(1, "New SSID requested: %s\n", assoc_req->ssid.ssid);
26 if (assoc_req->mode == wlan802_11infrastructure) { 26 if (assoc_req->mode == IW_MODE_INFRA) {
27 if (adapter->prescan) { 27 if (adapter->prescan) {
28 libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1); 28 libertas_send_specific_SSID_scan(priv, &assoc_req->ssid, 1);
29 } 29 }
30 30
31 i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, 31 i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid,
32 NULL, wlan802_11infrastructure); 32 NULL, IW_MODE_INFRA);
33 if (i >= 0) { 33 if (i >= 0) {
34 lbs_pr_debug(1, 34 lbs_pr_debug(1,
35 "SSID found in scan list ... associating...\n"); 35 "SSID found in scan list ... associating...\n");
@@ -44,7 +44,7 @@ static int assoc_helper_essid(wlan_private *priv,
44 lbs_pr_debug(1, "SSID '%s' not found; cannot associate\n", 44 lbs_pr_debug(1, "SSID '%s' not found; cannot associate\n",
45 assoc_req->ssid.ssid); 45 assoc_req->ssid.ssid);
46 } 46 }
47 } else if (assoc_req->mode == wlan802_11ibss) { 47 } else if (assoc_req->mode == IW_MODE_ADHOC) {
48 /* Scan for the network, do not save previous results. Stale 48 /* Scan for the network, do not save previous results. Stale
49 * scan data will cause us to join a non-existant adhoc network 49 * scan data will cause us to join a non-existant adhoc network
50 */ 50 */
@@ -52,7 +52,7 @@ static int assoc_helper_essid(wlan_private *priv,
52 52
53 /* Search for the requested SSID in the scan table */ 53 /* Search for the requested SSID in the scan table */
54 i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL, 54 i = libertas_find_SSID_in_list(adapter, &assoc_req->ssid, NULL,
55 wlan802_11ibss); 55 IW_MODE_ADHOC);
56 if (i >= 0) { 56 if (i >= 0) {
57 lbs_pr_debug(1, "SSID found at %d in List, so join\n", ret); 57 lbs_pr_debug(1, "SSID found at %d in List, so join\n", ret);
58 libertas_join_adhoc_network(priv, &adapter->scantable[i]); 58 libertas_join_adhoc_network(priv, &adapter->scantable[i]);
@@ -90,10 +90,10 @@ static int assoc_helper_bssid(wlan_private *priv,
90 goto out; 90 goto out;
91 } 91 }
92 92
93 if (assoc_req->mode == wlan802_11infrastructure) { 93 if (assoc_req->mode == IW_MODE_INFRA) {
94 ret = wlan_associate(priv, &adapter->scantable[i]); 94 ret = wlan_associate(priv, &adapter->scantable[i]);
95 lbs_pr_debug(1, "ASSOC: return from wlan_associate(bssd) was %d\n", ret); 95 lbs_pr_debug(1, "ASSOC: return from wlan_associate(bssd) was %d\n", ret);
96 } else if (assoc_req->mode == wlan802_11ibss) { 96 } else if (assoc_req->mode == IW_MODE_ADHOC) {
97 libertas_join_adhoc_network(priv, &adapter->scantable[i]); 97 libertas_join_adhoc_network(priv, &adapter->scantable[i]);
98 } 98 }
99 memcpy(&assoc_req->ssid, &adapter->scantable[i].ssid, 99 memcpy(&assoc_req->ssid, &adapter->scantable[i].ssid,
@@ -142,23 +142,23 @@ static int assoc_helper_mode(wlan_private *priv,
142 142
143 ENTER(); 143 ENTER();
144 144
145 if (assoc_req->mode == adapter->inframode) { 145 if (assoc_req->mode == adapter->mode) {
146 LEAVE(); 146 LEAVE();
147 return 0; 147 return 0;
148 } 148 }
149 149
150 if (assoc_req->mode == wlan802_11infrastructure) { 150 if (assoc_req->mode == IW_MODE_INFRA) {
151 if (adapter->psstate != PS_STATE_FULL_POWER) 151 if (adapter->psstate != PS_STATE_FULL_POWER)
152 libertas_ps_wakeup(priv, cmd_option_waitforrsp); 152 libertas_ps_wakeup(priv, cmd_option_waitforrsp);
153 adapter->psmode = wlan802_11powermodecam; 153 adapter->psmode = wlan802_11powermodecam;
154 } 154 }
155 155
156 adapter->inframode = assoc_req->mode; 156 adapter->mode = assoc_req->mode;
157 ret = libertas_prepare_and_send_command(priv, 157 ret = libertas_prepare_and_send_command(priv,
158 cmd_802_11_snmp_mib, 158 cmd_802_11_snmp_mib,
159 0, cmd_option_waitforrsp, 159 0, cmd_option_waitforrsp,
160 OID_802_11_INFRASTRUCTURE_MODE, 160 OID_802_11_INFRASTRUCTURE_MODE,
161 (void *) assoc_req->mode); 161 (void *) (size_t) assoc_req->mode);
162 162
163 LEAVE(); 163 LEAVE();
164 return ret; 164 return ret;
@@ -196,7 +196,7 @@ static int assoc_helper_wep_keys(wlan_private *priv,
196 goto out; 196 goto out;
197 197
198 /* enable/disable the MAC's WEP packet filter */ 198 /* enable/disable the MAC's WEP packet filter */
199 if (assoc_req->secinfo.WEPstatus == wlan802_11WEPenabled) 199 if (assoc_req->secinfo.wep_enabled)
200 adapter->currentpacketfilter |= cmd_act_mac_wep_enable; 200 adapter->currentpacketfilter |= cmd_act_mac_wep_enable;
201 else 201 else
202 adapter->currentpacketfilter &= ~cmd_act_mac_wep_enable; 202 adapter->currentpacketfilter &= ~cmd_act_mac_wep_enable;
@@ -300,8 +300,7 @@ static int should_deauth_infrastructure(wlan_adapter *adapter,
300 } 300 }
301 301
302 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) { 302 if (test_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags)) {
303 if (adapter->secinfo.authmode != 303 if (adapter->secinfo.auth_mode != assoc_req->secinfo.auth_mode) {
304 assoc_req->secinfo.authmode) {
305 lbs_pr_debug(1, "Deauthenticating due to updated security " 304 lbs_pr_debug(1, "Deauthenticating due to updated security "
306 "info in configuration request.\n"); 305 "info in configuration request.\n");
307 return 1; 306 return 1;
@@ -316,7 +315,7 @@ static int should_deauth_infrastructure(wlan_adapter *adapter,
316 315
317 /* FIXME: deal with 'auto' mode somehow */ 316 /* FIXME: deal with 'auto' mode somehow */
318 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { 317 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
319 if (assoc_req->mode != wlan802_11infrastructure) 318 if (assoc_req->mode != IW_MODE_INFRA)
320 return 1; 319 return 1;
321 } 320 }
322 321
@@ -333,12 +332,12 @@ static int should_stop_adhoc(wlan_adapter *adapter,
333 if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength) 332 if (adapter->curbssparams.ssid.ssidlength != assoc_req->ssid.ssidlength)
334 return 1; 333 return 1;
335 if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid, 334 if (memcmp(adapter->curbssparams.ssid.ssid, assoc_req->ssid.ssid,
336 sizeof(struct WLAN_802_11_SSID))) 335 adapter->curbssparams.ssid.ssidlength))
337 return 1; 336 return 1;
338 337
339 /* FIXME: deal with 'auto' mode somehow */ 338 /* FIXME: deal with 'auto' mode somehow */
340 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) { 339 if (test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) {
341 if (assoc_req->mode != wlan802_11ibss) 340 if (assoc_req->mode != IW_MODE_ADHOC)
342 return 1; 341 return 1;
343 } 342 }
344 343
@@ -382,7 +381,7 @@ void wlan_association_worker(struct work_struct *work)
382 } 381 }
383 382
384 if (find_any_ssid) { 383 if (find_any_ssid) {
385 enum WLAN_802_11_NETWORK_INFRASTRUCTURE new_mode; 384 u8 new_mode;
386 385
387 ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid, 386 ret = libertas_find_best_network_SSID(priv, &assoc_req->ssid,
388 assoc_req->mode, &new_mode); 387 assoc_req->mode, &new_mode);
@@ -393,7 +392,7 @@ void wlan_association_worker(struct work_struct *work)
393 } 392 }
394 393
395 /* Ensure we switch to the mode of the AP */ 394 /* Ensure we switch to the mode of the AP */
396 if (assoc_req->mode == wlan802_11autounknown) { 395 if (assoc_req->mode == IW_MODE_AUTO) {
397 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); 396 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
398 assoc_req->mode = new_mode; 397 assoc_req->mode = new_mode;
399 } 398 }
@@ -403,7 +402,7 @@ void wlan_association_worker(struct work_struct *work)
403 * Check if the attributes being changing require deauthentication 402 * Check if the attributes being changing require deauthentication
404 * from the currently associated infrastructure access point. 403 * from the currently associated infrastructure access point.
405 */ 404 */
406 if (adapter->inframode == wlan802_11infrastructure) { 405 if (adapter->mode == IW_MODE_INFRA) {
407 if (should_deauth_infrastructure(adapter, assoc_req)) { 406 if (should_deauth_infrastructure(adapter, assoc_req)) {
408 ret = libertas_send_deauthentication(priv); 407 ret = libertas_send_deauthentication(priv);
409 if (ret) { 408 if (ret) {
@@ -412,7 +411,7 @@ void wlan_association_worker(struct work_struct *work)
412 ret); 411 ret);
413 } 412 }
414 } 413 }
415 } else if (adapter->inframode == wlan802_11ibss) { 414 } else if (adapter->mode == IW_MODE_ADHOC) {
416 if (should_stop_adhoc(adapter, assoc_req)) { 415 if (should_stop_adhoc(adapter, assoc_req)) {
417 ret = libertas_stop_adhoc_network(priv); 416 ret = libertas_stop_adhoc_network(priv);
418 if (ret) { 417 if (ret) {
@@ -543,7 +542,7 @@ struct assoc_request * wlan_get_association_request(wlan_adapter *adapter)
543 assoc_req->channel = adapter->curbssparams.channel; 542 assoc_req->channel = adapter->curbssparams.channel;
544 543
545 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags)) 544 if (!test_bit(ASSOC_FLAG_MODE, &assoc_req->flags))
546 assoc_req->mode = adapter->inframode; 545 assoc_req->mode = adapter->mode;
547 546
548 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) { 547 if (!test_bit(ASSOC_FLAG_BSSID, &assoc_req->flags)) {
549 memcpy(&assoc_req->bssid, adapter->curbssparams.bssid, 548 memcpy(&assoc_req->bssid, adapter->curbssparams.bssid,
diff --git a/drivers/net/wireless/libertas/cmd.c b/drivers/net/wireless/libertas/cmd.c
index bfdac58b5c06..de9cb46a70ff 100644
--- a/drivers/net/wireless/libertas/cmd.c
+++ b/drivers/net/wireless/libertas/cmd.c
@@ -381,15 +381,16 @@ static int wlan_cmd_802_11_snmp_mib(wlan_private * priv,
381 switch (cmd_oid) { 381 switch (cmd_oid) {
382 case OID_802_11_INFRASTRUCTURE_MODE: 382 case OID_802_11_INFRASTRUCTURE_MODE:
383 { 383 {
384 enum WLAN_802_11_NETWORK_INFRASTRUCTURE mode = 384 u8 mode = (u8) (size_t) pdata_buf;
385 (enum WLAN_802_11_NETWORK_INFRASTRUCTURE) pdata_buf;
386 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set); 385 pSNMPMIB->querytype = cpu_to_le16(cmd_act_set);
387 pSNMPMIB->oid = cpu_to_le16((u16) desired_bsstype_i); 386 pSNMPMIB->oid = cpu_to_le16((u16) desired_bsstype_i);
388 pSNMPMIB->bufsize = sizeof(u8); 387 pSNMPMIB->bufsize = sizeof(u8);
389 if (mode == wlan802_11infrastructure) 388 if (mode == IW_MODE_ADHOC) {
390 ucTemp = SNMP_MIB_VALUE_INFRA;
391 else
392 ucTemp = SNMP_MIB_VALUE_ADHOC; 389 ucTemp = SNMP_MIB_VALUE_ADHOC;
390 } else {
391 /* Infra and Auto modes */
392 ucTemp = SNMP_MIB_VALUE_INFRA;
393 }
393 394
394 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8)); 395 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
395 396
@@ -947,8 +948,8 @@ void libertas_queue_cmd(wlan_adapter * adapter, struct cmd_ctrl_node *cmdnode, u
947 948
948 spin_unlock_irqrestore(&adapter->driver_lock, flags); 949 spin_unlock_irqrestore(&adapter->driver_lock, flags);
949 950
950 lbs_pr_debug(1, "QUEUE_CMD: Inserted node=0x%x, cmd=0x%x in cmdpendingq\n", 951 lbs_pr_debug(1, "QUEUE_CMD: Inserted node=%p, cmd=0x%x in cmdpendingq\n",
951 (u32) cmdnode, 952 cmdnode,
952 ((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command); 953 ((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command);
953 954
954done: 955done:
@@ -976,8 +977,8 @@ static int DownloadcommandToStation(wlan_private * priv,
976 ENTER(); 977 ENTER();
977 978
978 if (!adapter || !cmdnode) { 979 if (!adapter || !cmdnode) {
979 lbs_pr_debug(1, "DNLD_CMD: adapter = %#x, cmdnode = %#x\n", 980 lbs_pr_debug(1, "DNLD_CMD: adapter = %p, cmdnode = %p\n",
980 (int)adapter, (int)cmdnode); 981 adapter, cmdnode);
981 if (cmdnode) { 982 if (cmdnode) {
982 spin_lock_irqsave(&adapter->driver_lock, flags); 983 spin_lock_irqsave(&adapter->driver_lock, flags);
983 __libertas_cleanup_and_insert_cmd(priv, cmdnode); 984 __libertas_cleanup_and_insert_cmd(priv, cmdnode);
@@ -1174,8 +1175,8 @@ int libertas_prepare_and_send_command(wlan_private * priv,
1174 1175
1175 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr; 1176 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1176 1177
1177 lbs_pr_debug(1, "PREP_CMD: Val of cmd ptr =0x%x, command=0x%X\n", 1178 lbs_pr_debug(1, "PREP_CMD: Val of cmd ptr=%p, command=0x%X\n",
1178 (u32) cmdptr, cmd_no); 1179 cmdptr, cmd_no);
1179 1180
1180 if (!cmdptr) { 1181 if (!cmdptr) {
1181 lbs_pr_debug(1, "PREP_CMD: bufvirtualaddr of cmdnode is NULL\n"); 1182 lbs_pr_debug(1, "PREP_CMD: bufvirtualaddr of cmdnode is NULL\n");
diff --git a/drivers/net/wireless/libertas/cmdresp.c b/drivers/net/wireless/libertas/cmdresp.c
index cdb012c7e9cf..c86454034b58 100644
--- a/drivers/net/wireless/libertas/cmdresp.c
+++ b/drivers/net/wireless/libertas/cmdresp.c
@@ -72,8 +72,6 @@ void libertas_mac_event_disconnected(wlan_private * priv)
72 adapter->secinfo.WPAenabled = 0; 72 adapter->secinfo.WPAenabled = 0;
73 adapter->secinfo.WPA2enabled = 0; 73 adapter->secinfo.WPA2enabled = 0;
74 adapter->wpa_ie_len = 0; 74 adapter->wpa_ie_len = 0;
75 adapter->secinfo.auth1xalg = WLAN_1X_AUTH_ALG_NONE;
76 adapter->secinfo.Encryptionmode = CIPHER_NONE;
77 75
78 adapter->connect_status = libertas_disconnected; 76 adapter->connect_status = libertas_disconnected;
79 77
@@ -811,7 +809,7 @@ int libertas_process_rx_command(wlan_private * priv)
811 if (result) { 809 if (result) {
812 lbs_pr_debug(1, "CMD_RESP: PS command failed- %#x \n", 810 lbs_pr_debug(1, "CMD_RESP: PS command failed- %#x \n",
813 resp->result); 811 resp->result);
814 if (adapter->inframode == wlan802_11ibss) { 812 if (adapter->mode == IW_MODE_ADHOC) {
815 /* 813 /*
816 * We should not re-try enter-ps command in 814 * We should not re-try enter-ps command in
817 * ad-hoc mode. It takes place in 815 * ad-hoc mode. It takes place in
diff --git a/drivers/net/wireless/libertas/debugfs.c b/drivers/net/wireless/libertas/debugfs.c
index 51dfd202f558..7d7bc5e86a56 100644
--- a/drivers/net/wireless/libertas/debugfs.c
+++ b/drivers/net/wireless/libertas/debugfs.c
@@ -7,6 +7,7 @@
7#include "dev.h" 7#include "dev.h"
8#include "decl.h" 8#include "decl.h"
9#include "host.h" 9#include "host.h"
10#include "debugfs.h"
10 11
11static struct dentry *libertas_dir = NULL; 12static struct dentry *libertas_dir = NULL;
12static char *szStates[] = { 13static char *szStates[] = {
@@ -276,7 +277,7 @@ static void libertas_parse_ssid(char *buf, size_t count,
276 if (!end) 277 if (!end)
277 end = buf + count - 1; 278 end = buf + count - 1;
278 279
279 size = min(IW_ESSID_MAX_SIZE, end - hold); 280 size = min((size_t)IW_ESSID_MAX_SIZE, (size_t) (end - hold));
280 strncpy(scan_cfg->specificSSID, hold, size); 281 strncpy(scan_cfg->specificSSID, hold, size);
281 282
282 return; 283 return;
@@ -1648,7 +1649,7 @@ struct libertas_debugfs_files {
1648 struct file_operations fops; 1649 struct file_operations fops;
1649}; 1650};
1650 1651
1651struct libertas_debugfs_files debugfs_files[] = { 1652static struct libertas_debugfs_files debugfs_files[] = {
1652 { "info", 0444, FOPS(libertas_dev_info, write_file_dummy), }, 1653 { "info", 0444, FOPS(libertas_dev_info, write_file_dummy), },
1653 { "getscantable", 0444, FOPS(libertas_getscantable, 1654 { "getscantable", 0444, FOPS(libertas_getscantable,
1654 write_file_dummy), }, 1655 write_file_dummy), },
@@ -1658,7 +1659,7 @@ struct libertas_debugfs_files debugfs_files[] = {
1658 { "setuserscan", 0600, FOPS(NULL, libertas_setuserscan), }, 1659 { "setuserscan", 0600, FOPS(NULL, libertas_setuserscan), },
1659}; 1660};
1660 1661
1661struct libertas_debugfs_files debugfs_events_files[] = { 1662static struct libertas_debugfs_files debugfs_events_files[] = {
1662 {"low_rssi", 0644, FOPS(libertas_lowrssi_read, 1663 {"low_rssi", 0644, FOPS(libertas_lowrssi_read,
1663 libertas_lowrssi_write), }, 1664 libertas_lowrssi_write), },
1664 {"low_snr", 0644, FOPS(libertas_lowsnr_read, 1665 {"low_snr", 0644, FOPS(libertas_lowsnr_read,
@@ -1673,7 +1674,7 @@ struct libertas_debugfs_files debugfs_events_files[] = {
1673 libertas_highsnr_write), }, 1674 libertas_highsnr_write), },
1674}; 1675};
1675 1676
1676struct libertas_debugfs_files debugfs_regs_files[] = { 1677static struct libertas_debugfs_files debugfs_regs_files[] = {
1677 {"rdmac", 0644, FOPS(libertas_rdmac_read, libertas_rdmac_write), }, 1678 {"rdmac", 0644, FOPS(libertas_rdmac_read, libertas_rdmac_write), },
1678 {"wrmac", 0600, FOPS(NULL, libertas_wrmac_write), }, 1679 {"wrmac", 0600, FOPS(NULL, libertas_wrmac_write), },
1679 {"rdbbp", 0644, FOPS(libertas_rdbbp_read, libertas_rdbbp_write), }, 1680 {"rdbbp", 0644, FOPS(libertas_rdbbp_read, libertas_rdbbp_write), },
@@ -1778,7 +1779,7 @@ void libertas_debugfs_remove_one(wlan_private *priv)
1778struct debug_data { 1779struct debug_data {
1779 char name[32]; 1780 char name[32];
1780 u32 size; 1781 u32 size;
1781 u32 addr; 1782 size_t addr;
1782}; 1783};
1783 1784
1784/* To debug any member of wlan_adapter, simply add one line here. 1785/* To debug any member of wlan_adapter, simply add one line here.
@@ -1825,6 +1826,8 @@ static ssize_t wlan_debugfs_read(struct file *file, char __user *userbuf,
1825 val = *((u16 *) d[i].addr); 1826 val = *((u16 *) d[i].addr);
1826 else if (d[i].size == 4) 1827 else if (d[i].size == 4)
1827 val = *((u32 *) d[i].addr); 1828 val = *((u32 *) d[i].addr);
1829 else if (d[i].size == 8)
1830 val = *((u64 *) d[i].addr);
1828 1831
1829 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val); 1832 pos += sprintf(p + pos, "%s=%d\n", d[i].name, val);
1830 } 1833 }
@@ -1844,7 +1847,7 @@ static ssize_t wlan_debugfs_read(struct file *file, char __user *userbuf,
1844 * @param data data to write 1847 * @param data data to write
1845 * @return number of data 1848 * @return number of data
1846 */ 1849 */
1847static int wlan_debugfs_write(struct file *f, const char __user *buf, 1850static ssize_t wlan_debugfs_write(struct file *f, const char __user *buf,
1848 size_t cnt, loff_t *ppos) 1851 size_t cnt, loff_t *ppos)
1849{ 1852{
1850 int r, i; 1853 int r, i;
@@ -1886,12 +1889,14 @@ static int wlan_debugfs_write(struct file *f, const char __user *buf,
1886 *((u16 *) d[i].addr) = (u16) r; 1889 *((u16 *) d[i].addr) = (u16) r;
1887 else if (d[i].size == 4) 1890 else if (d[i].size == 4)
1888 *((u32 *) d[i].addr) = (u32) r; 1891 *((u32 *) d[i].addr) = (u32) r;
1892 else if (d[i].size == 8)
1893 *((u64 *) d[i].addr) = (u64) r;
1889 break; 1894 break;
1890 } while (1); 1895 } while (1);
1891 } 1896 }
1892 kfree(pdata); 1897 kfree(pdata);
1893 1898
1894 return cnt; 1899 return (ssize_t)cnt;
1895} 1900}
1896 1901
1897static struct file_operations libertas_debug_fops = { 1902static struct file_operations libertas_debug_fops = {
@@ -1916,20 +1921,10 @@ void libertas_debug_init(wlan_private * priv, struct net_device *dev)
1916 return; 1921 return;
1917 1922
1918 for (i = 0; i < num_of_items; i++) 1923 for (i = 0; i < num_of_items; i++)
1919 items[i].addr += (u32) priv->adapter; 1924 items[i].addr += (size_t) priv->adapter;
1920 1925
1921 priv->debugfs_debug = debugfs_create_file("debug", 0644, 1926 priv->debugfs_debug = debugfs_create_file("debug", 0644,
1922 priv->debugfs_dir, &items[0], 1927 priv->debugfs_dir, &items[0],
1923 &libertas_debug_fops); 1928 &libertas_debug_fops);
1924} 1929}
1925 1930
1926/**
1927 * @brief remove proc file
1928 *
1929 * @param priv pointer wlan_private
1930 * @return N/A
1931 */
1932void libertas_debug_remove(wlan_private * priv)
1933{
1934 debugfs_remove(priv->debugfs_debug);
1935}
diff --git a/drivers/net/wireless/libertas/defs.h b/drivers/net/wireless/libertas/defs.h
index fb1478c1b87d..80dd9ea19c8e 100644
--- a/drivers/net/wireless/libertas/defs.h
+++ b/drivers/net/wireless/libertas/defs.h
@@ -9,6 +9,11 @@
9 9
10extern unsigned int libertas_debug; 10extern unsigned int libertas_debug;
11 11
12#ifdef CONFIG_LIBERTAS_DEBUG
13#define DEBUG
14#define PROC_DEBUG
15#endif
16
12#define DRV_NAME "usb8xxx" 17#define DRV_NAME "usb8xxx"
13 18
14#define lbs_pr_info(format, args...) \ 19#define lbs_pr_info(format, args...) \
@@ -223,31 +228,6 @@ enum SNRNF_DATA {
223 MAX_TYPE_AVG 228 MAX_TYPE_AVG
224}; 229};
225 230
226/** WLAN_802_11_AUTH_ALG*/
227enum WLAN_802_11_AUTH_ALG {
228 AUTH_ALG_OPEN_SYSTEM = 1,
229 AUTH_ALG_SHARED_KEY = 2,
230 AUTH_ALG_NETWORK_EAP = 8,
231};
232
233/** WLAN_802_1X_AUTH_ALG */
234enum WLAN_802_1X_AUTH_ALG {
235 WLAN_1X_AUTH_ALG_NONE = 1,
236 WLAN_1X_AUTH_ALG_LEAP = 2,
237 WLAN_1X_AUTH_ALG_TLS = 4,
238 WLAN_1X_AUTH_ALG_TTLS = 8,
239 WLAN_1X_AUTH_ALG_MD5 = 16,
240};
241
242/** WLAN_802_11_ENCRYPTION_MODE */
243enum WLAN_802_11_ENCRYPTION_MODE {
244 CIPHER_NONE,
245 CIPHER_WEP40,
246 CIPHER_TKIP,
247 CIPHER_CCMP,
248 CIPHER_WEP104,
249};
250
251/** WLAN_802_11_POWER_MODE */ 231/** WLAN_802_11_POWER_MODE */
252enum WLAN_802_11_POWER_MODE { 232enum WLAN_802_11_POWER_MODE {
253 wlan802_11powermodecam, 233 wlan802_11powermodecam,
@@ -292,28 +272,6 @@ enum mv_ms_type {
292 MVMS_EVENT 272 MVMS_EVENT
293}; 273};
294 274
295/** WLAN_802_11_NETWORK_INFRASTRUCTURE */
296enum WLAN_802_11_NETWORK_INFRASTRUCTURE {
297 wlan802_11ibss,
298 wlan802_11infrastructure,
299 wlan802_11autounknown,
300 /*defined as upper bound */
301 wlan802_11infrastructuremax
302};
303
304/** WLAN_802_11_AUTHENTICATION_MODE */
305enum WLAN_802_11_AUTHENTICATION_MODE {
306 wlan802_11authmodeopen = 0x00,
307 wlan802_11authmodeshared = 0x01,
308 wlan802_11authmodenetworkEAP = 0x80,
309};
310
311/** WLAN_802_11_WEP_STATUS */
312enum WLAN_802_11_WEP_STATUS {
313 wlan802_11WEPenabled,
314 wlan802_11WEPdisabled,
315};
316
317/** SNMP_MIB_INDEX_e */ 275/** SNMP_MIB_INDEX_e */
318enum SNMP_MIB_INDEX_e { 276enum SNMP_MIB_INDEX_e {
319 desired_bsstype_i = 0, 277 desired_bsstype_i = 0,
diff --git a/drivers/net/wireless/libertas/dev.h b/drivers/net/wireless/libertas/dev.h
index b1f876f9693b..e8b9020f9bd6 100644
--- a/drivers/net/wireless/libertas/dev.h
+++ b/drivers/net/wireless/libertas/dev.h
@@ -10,6 +10,7 @@
10#include <linux/wireless.h> 10#include <linux/wireless.h>
11#include <linux/ethtool.h> 11#include <linux/ethtool.h>
12#include <linux/debugfs.h> 12#include <linux/debugfs.h>
13#include <net/ieee80211.h>
13 14
14#include "defs.h" 15#include "defs.h"
15#include "scan.h" 16#include "scan.h"
@@ -56,10 +57,8 @@ struct region_channel {
56struct wlan_802_11_security { 57struct wlan_802_11_security {
57 u8 WPAenabled; 58 u8 WPAenabled;
58 u8 WPA2enabled; 59 u8 WPA2enabled;
59 enum WLAN_802_11_WEP_STATUS WEPstatus; 60 u8 wep_enabled;
60 enum WLAN_802_11_AUTHENTICATION_MODE authmode; 61 u8 auth_mode;
61 enum WLAN_802_1X_AUTH_ALG auth1xalg;
62 enum WLAN_802_11_ENCRYPTION_MODE Encryptionmode;
63}; 62};
64 63
65/** Current Basic Service Set State Structure */ 64/** Current Basic Service Set State Structure */
@@ -184,7 +183,7 @@ struct assoc_request {
184 183
185 struct WLAN_802_11_SSID ssid; 184 struct WLAN_802_11_SSID ssid;
186 u8 channel; 185 u8 channel;
187 enum WLAN_802_11_NETWORK_INFRASTRUCTURE mode; 186 u8 mode;
188 u8 bssid[ETH_ALEN]; 187 u8 bssid[ETH_ALEN];
189 188
190 /** WEP keys */ 189 /** WEP keys */
@@ -198,7 +197,6 @@ struct assoc_request {
198 struct wlan_802_11_security secinfo; 197 struct wlan_802_11_security secinfo;
199 198
200 /** WPA Information Elements*/ 199 /** WPA Information Elements*/
201#define MAX_WPA_IE_LEN 64
202 u8 wpa_ie[MAX_WPA_IE_LEN]; 200 u8 wpa_ie[MAX_WPA_IE_LEN];
203 u8 wpa_ie_len; 201 u8 wpa_ie_len;
204}; 202};
@@ -254,7 +252,8 @@ struct _wlan_adapter {
254 /** current ssid/bssid related parameters*/ 252 /** current ssid/bssid related parameters*/
255 struct current_bss_params curbssparams; 253 struct current_bss_params curbssparams;
256 254
257 enum WLAN_802_11_NETWORK_INFRASTRUCTURE inframode; 255 /* IW_MODE_* */
256 u8 mode;
258 257
259 struct bss_descriptor *pattemptedbssdesc; 258 struct bss_descriptor *pattemptedbssdesc;
260 259
@@ -339,7 +338,6 @@ struct _wlan_adapter {
339 struct WLAN_802_11_KEY wpa_unicast_key; 338 struct WLAN_802_11_KEY wpa_unicast_key;
340 339
341 /** WPA Information Elements*/ 340 /** WPA Information Elements*/
342#define MAX_WPA_IE_LEN 64
343 u8 wpa_ie[MAX_WPA_IE_LEN]; 341 u8 wpa_ie[MAX_WPA_IE_LEN];
344 u8 wpa_ie_len; 342 u8 wpa_ie_len;
345 343
diff --git a/drivers/net/wireless/libertas/fw.c b/drivers/net/wireless/libertas/fw.c
index b194a4570791..441123c85e62 100644
--- a/drivers/net/wireless/libertas/fw.c
+++ b/drivers/net/wireless/libertas/fw.c
@@ -194,16 +194,13 @@ static void wlan_init_adapter(wlan_private * priv)
194 adapter->scanmode = cmd_bss_type_any; 194 adapter->scanmode = cmd_bss_type_any;
195 195
196 /* 802.11 specific */ 196 /* 802.11 specific */
197 adapter->secinfo.WEPstatus = wlan802_11WEPdisabled; 197 adapter->secinfo.wep_enabled = 0;
198 for (i = 0; i < sizeof(adapter->wep_keys) / sizeof(adapter->wep_keys[0]); 198 for (i = 0; i < sizeof(adapter->wep_keys) / sizeof(adapter->wep_keys[0]);
199 i++) 199 i++)
200 memset(&adapter->wep_keys[i], 0, sizeof(struct WLAN_802_11_KEY)); 200 memset(&adapter->wep_keys[i], 0, sizeof(struct WLAN_802_11_KEY));
201 adapter->wep_tx_keyidx = 0; 201 adapter->wep_tx_keyidx = 0;
202 adapter->secinfo.WEPstatus = wlan802_11WEPdisabled; 202 adapter->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
203 adapter->secinfo.authmode = wlan802_11authmodeopen; 203 adapter->mode = IW_MODE_INFRA;
204 adapter->secinfo.auth1xalg = WLAN_1X_AUTH_ALG_NONE;
205 adapter->secinfo.Encryptionmode = CIPHER_NONE;
206 adapter->inframode = wlan802_11infrastructure;
207 204
208 adapter->assoc_req = NULL; 205 adapter->assoc_req = NULL;
209 206
diff --git a/drivers/net/wireless/libertas/if_usb.c b/drivers/net/wireless/libertas/if_usb.c
index 695fb6a66ffe..ae6f72a6cdf3 100644
--- a/drivers/net/wireless/libertas/if_usb.c
+++ b/drivers/net/wireless/libertas/if_usb.c
@@ -388,7 +388,7 @@ static int __if_usb_submit_rx_urb(wlan_private * priv,
388 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev, 388 usb_fill_bulk_urb(cardp->rx_urb, cardp->udev,
389 usb_rcvbulkpipe(cardp->udev, 389 usb_rcvbulkpipe(cardp->udev,
390 cardp->bulk_in_endpointAddr), 390 cardp->bulk_in_endpointAddr),
391 skb->tail + IPFIELD_ALIGN_OFFSET, 391 (void *) (skb->tail + (size_t) IPFIELD_ALIGN_OFFSET),
392 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn, 392 MRVDRV_ETH_RX_PACKET_BUFFER_SIZE, callbackfn,
393 rinfo); 393 rinfo);
394 394
@@ -626,6 +626,7 @@ static void if_usb_receive(struct urb *urb)
626 cardp->usb_event_cause); 626 cardp->usb_event_cause);
627 if (cardp->usb_event_cause & 0xffff0000) { 627 if (cardp->usb_event_cause & 0xffff0000) {
628 libertas_send_tx_feedback(priv); 628 libertas_send_tx_feedback(priv);
629 spin_unlock(&priv->adapter->driver_lock);
629 break; 630 break;
630 } 631 }
631 cardp->usb_event_cause = le32_to_cpu(cardp->usb_event_cause) << 3; 632 cardp->usb_event_cause = le32_to_cpu(cardp->usb_event_cause) << 3;
@@ -775,7 +776,6 @@ restart:
775 return -1; 776 return -1;
776 } 777 }
777 778
778#ifdef SUPPORT_BOOT_COMMAND
779 cardp->bootcmdresp = 0; 779 cardp->bootcmdresp = 0;
780 do { 780 do {
781 int j = 0; 781 int j = 0;
@@ -796,7 +796,6 @@ restart:
796 } 796 }
797 return -1; 797 return -1;
798 } 798 }
799#endif
800 799
801 i = 0; 800 i = 0;
802 priv->adapter->fw_ready = 0; 801 priv->adapter->fw_ready = 0;
diff --git a/drivers/net/wireless/libertas/if_usb.h b/drivers/net/wireless/libertas/if_usb.h
index 785116720bc6..170dfe6809f5 100644
--- a/drivers/net/wireless/libertas/if_usb.h
+++ b/drivers/net/wireless/libertas/if_usb.h
@@ -12,7 +12,6 @@
12#define USB8388_VID_2 0x05a3 12#define USB8388_VID_2 0x05a3
13#define USB8388_PID_2 0x8388 13#define USB8388_PID_2 0x8388
14 14
15#ifdef SUPPORT_BOOT_COMMAND
16#define BOOT_CMD_FW_BY_USB 0x01 15#define BOOT_CMD_FW_BY_USB 0x01
17#define BOOT_CMD_FW_IN_EEPROM 0x02 16#define BOOT_CMD_FW_IN_EEPROM 0x02
18#define BOOT_CMD_UPDATE_BOOT2 0x03 17#define BOOT_CMD_UPDATE_BOOT2 0x03
@@ -36,7 +35,6 @@ struct bootcmdrespStr
36 u8 u8result; 35 u8 u8result;
37 u8 au8dumy[2]; 36 u8 au8dumy[2];
38}; 37};
39#endif /* SUPPORT_BOOT_COMMAND */
40 38
41/* read callback private data */ 39/* read callback private data */
42struct read_cb_info { 40struct read_cb_info {
diff --git a/drivers/net/wireless/libertas/ioctl.c b/drivers/net/wireless/libertas/ioctl.c
index 82b39642423a..a8f76c358992 100644
--- a/drivers/net/wireless/libertas/ioctl.c
+++ b/drivers/net/wireless/libertas/ioctl.c
@@ -27,95 +27,6 @@
27 27
28#define WAIT_FOR_SCAN_RRESULT_MAX_TIME (10 * HZ) 28#define WAIT_FOR_SCAN_RRESULT_MAX_TIME (10 * HZ)
29 29
30static int setrxantenna(wlan_private * priv, int mode)
31{
32 int ret = 0;
33 wlan_adapter *adapter = priv->adapter;
34
35 if (mode != RF_ANTENNA_1 && mode != RF_ANTENNA_2
36 && mode != RF_ANTENNA_AUTO) {
37 return -EINVAL;
38 }
39
40 adapter->rxantennamode = mode;
41
42 lbs_pr_debug(1, "SET RX Antenna mode to 0x%04x\n", adapter->rxantennamode);
43
44 ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_antenna,
45 cmd_act_set_rx,
46 cmd_option_waitforrsp, 0,
47 &adapter->rxantennamode);
48 return ret;
49}
50
51static int settxantenna(wlan_private * priv, int mode)
52{
53 int ret = 0;
54 wlan_adapter *adapter = priv->adapter;
55
56 if ((mode != RF_ANTENNA_1) && (mode != RF_ANTENNA_2)
57 && (mode != RF_ANTENNA_AUTO)) {
58 return -EINVAL;
59 }
60
61 adapter->txantennamode = mode;
62
63 lbs_pr_debug(1, "SET TX Antenna mode to 0x%04x\n", adapter->txantennamode);
64
65 ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_antenna,
66 cmd_act_set_tx,
67 cmd_option_waitforrsp, 0,
68 &adapter->txantennamode);
69
70 return ret;
71}
72
73static int getrxantenna(wlan_private * priv, char *buf)
74{
75 int ret = 0;
76 wlan_adapter *adapter = priv->adapter;
77
78 // clear it, so we will know if the value
79 // returned below is correct or not.
80 adapter->rxantennamode = 0;
81
82 ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_antenna,
83 cmd_act_get_rx,
84 cmd_option_waitforrsp, 0, NULL);
85
86 if (ret) {
87 LEAVE();
88 return ret;
89 }
90
91 lbs_pr_debug(1, "Get Rx Antenna mode:0x%04x\n", adapter->rxantennamode);
92
93 return sprintf(buf, "0x%04x", adapter->rxantennamode) + 1;
94}
95
96static int gettxantenna(wlan_private * priv, char *buf)
97{
98 int ret = 0;
99 wlan_adapter *adapter = priv->adapter;
100
101 // clear it, so we will know if the value
102 // returned below is correct or not.
103 adapter->txantennamode = 0;
104
105 ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_antenna,
106 cmd_act_get_tx,
107 cmd_option_waitforrsp, 0, NULL);
108
109 if (ret) {
110 LEAVE();
111 return ret;
112 }
113
114 lbs_pr_debug(1, "Get Tx Antenna mode:0x%04x\n", adapter->txantennamode);
115
116 return sprintf(buf, "0x%04x", adapter->txantennamode) + 1;
117}
118
119static int wlan_set_region(wlan_private * priv, u16 region_code) 30static int wlan_set_region(wlan_private * priv, u16 region_code)
120{ 31{
121 int i; 32 int i;
@@ -144,998 +55,6 @@ static int wlan_set_region(wlan_private * priv, u16 region_code)
144 return 0; 55 return 0;
145} 56}
146 57
147/**
148 * @brief Get/Set Firmware wakeup method
149 *
150 * @param priv A pointer to wlan_private structure
151 * @param wrq A pointer to user data
152 * @return 0--success, otherwise fail
153 */
154static int wlan_txcontrol(wlan_private * priv, struct iwreq *wrq)
155{
156 wlan_adapter *adapter = priv->adapter;
157 int data;
158 ENTER();
159
160 if ((int)wrq->u.data.length == 0) {
161 if (copy_to_user
162 (wrq->u.data.pointer, &adapter->pkttxctrl, sizeof(u32))) {
163 lbs_pr_alert("copy_to_user failed!\n");
164 return -EFAULT;
165 }
166 } else {
167 if ((int)wrq->u.data.length > 1) {
168 lbs_pr_alert("ioctl too many args!\n");
169 return -EFAULT;
170 }
171 if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
172 lbs_pr_alert("Copy from user failed\n");
173 return -EFAULT;
174 }
175
176 adapter->pkttxctrl = (u32) data;
177 }
178
179 wrq->u.data.length = 1;
180
181 LEAVE();
182 return 0;
183}
184
185/**
186 * @brief Get/Set NULL Package generation interval
187 *
188 * @param priv A pointer to wlan_private structure
189 * @param wrq A pointer to user data
190 * @return 0--success, otherwise fail
191 */
192static int wlan_null_pkt_interval(wlan_private * priv, struct iwreq *wrq)
193{
194 wlan_adapter *adapter = priv->adapter;
195 int data;
196 ENTER();
197
198 if ((int)wrq->u.data.length == 0) {
199 data = adapter->nullpktinterval;
200
201 if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
202 lbs_pr_alert( "copy_to_user failed!\n");
203 return -EFAULT;
204 }
205 } else {
206 if ((int)wrq->u.data.length > 1) {
207 lbs_pr_alert( "ioctl too many args!\n");
208 return -EFAULT;
209 }
210 if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
211 lbs_pr_debug(1, "Copy from user failed\n");
212 return -EFAULT;
213 }
214
215 adapter->nullpktinterval = data;
216 }
217
218 wrq->u.data.length = 1;
219
220 LEAVE();
221 return 0;
222}
223
224static int wlan_get_rxinfo(wlan_private * priv, struct iwreq *wrq)
225{
226 wlan_adapter *adapter = priv->adapter;
227 int data[2];
228 ENTER();
229 data[0] = adapter->SNR[TYPE_RXPD][TYPE_NOAVG];
230 data[1] = adapter->rxpd_rate;
231 if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) * 2)) {
232 lbs_pr_debug(1, "Copy to user failed\n");
233 return -EFAULT;
234 }
235 wrq->u.data.length = 2;
236 LEAVE();
237 return 0;
238}
239
240static int wlan_get_snr(wlan_private * priv, struct iwreq *wrq)
241{
242 int ret = 0;
243 wlan_adapter *adapter = priv->adapter;
244 int data[4];
245
246 ENTER();
247 memset(data, 0, sizeof(data));
248 if (wrq->u.data.length) {
249 if (copy_from_user(data, wrq->u.data.pointer,
250 min_t(size_t, wrq->u.data.length, 4) * sizeof(int)))
251 return -EFAULT;
252 }
253 if ((wrq->u.data.length == 0) || (data[0] == 0) || (data[0] == 1)) {
254 if (adapter->connect_status == libertas_connected) {
255 ret = libertas_prepare_and_send_command(priv,
256 cmd_802_11_rssi,
257 0,
258 cmd_option_waitforrsp,
259 0, NULL);
260
261 if (ret) {
262 LEAVE();
263 return ret;
264 }
265 }
266 }
267
268 if (wrq->u.data.length == 0) {
269 data[0] = adapter->SNR[TYPE_BEACON][TYPE_NOAVG];
270 data[1] = adapter->SNR[TYPE_BEACON][TYPE_AVG];
271 data[2] = adapter->SNR[TYPE_RXPD][TYPE_NOAVG];
272 data[3] = adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
273 if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) * 4))
274 return -EFAULT;
275 wrq->u.data.length = 4;
276 } else if (data[0] == 0) {
277 data[0] = adapter->SNR[TYPE_BEACON][TYPE_NOAVG];
278 if (copy_to_user(wrq->u.data.pointer, data, sizeof(int)))
279 return -EFAULT;
280 wrq->u.data.length = 1;
281 } else if (data[0] == 1) {
282 data[0] = adapter->SNR[TYPE_BEACON][TYPE_AVG];
283 if (copy_to_user(wrq->u.data.pointer, data, sizeof(int)))
284 return -EFAULT;
285 wrq->u.data.length = 1;
286 } else if (data[0] == 2) {
287 data[0] = adapter->SNR[TYPE_RXPD][TYPE_NOAVG];
288 if (copy_to_user(wrq->u.data.pointer, data, sizeof(int)))
289 return -EFAULT;
290 wrq->u.data.length = 1;
291 } else if (data[0] == 3) {
292 data[0] = adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
293 if (copy_to_user(wrq->u.data.pointer, data, sizeof(int)))
294 return -EFAULT;
295 wrq->u.data.length = 1;
296 } else
297 return -ENOTSUPP;
298
299 LEAVE();
300 return 0;
301}
302
303static int wlan_beacon_interval(wlan_private * priv, struct iwreq *wrq)
304{
305 int data;
306 wlan_adapter *adapter = priv->adapter;
307
308 if (wrq->u.data.length > 0) {
309 if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int)))
310 return -EFAULT;
311
312 lbs_pr_debug(1, "WLAN SET BEACON INTERVAL: %d\n", data);
313 if ((data > MRVDRV_MAX_BEACON_INTERVAL)
314 || (data < MRVDRV_MIN_BEACON_INTERVAL))
315 return -ENOTSUPP;
316 adapter->beaconperiod = data;
317 }
318 data = adapter->beaconperiod;
319 if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int)))
320 return -EFAULT;
321
322 wrq->u.data.length = 1;
323
324 return 0;
325}
326
327static int wlan_get_rssi(wlan_private * priv, struct iwreq *wrq)
328{
329 int ret = 0;
330 wlan_adapter *adapter = priv->adapter;
331 int temp;
332 int data = 0;
333 int *val;
334
335 ENTER();
336 data = SUBCMD_DATA(wrq);
337 if ((data == 0) || (data == 1)) {
338 ret = libertas_prepare_and_send_command(priv,
339 cmd_802_11_rssi,
340 0, cmd_option_waitforrsp,
341 0, NULL);
342 if (ret) {
343 LEAVE();
344 return ret;
345 }
346 }
347
348 switch (data) {
349 case 0:
350
351 temp = CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
352 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
353 break;
354 case 1:
355 temp = CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_AVG],
356 adapter->NF[TYPE_BEACON][TYPE_AVG]);
357 break;
358 case 2:
359 temp = CAL_RSSI(adapter->SNR[TYPE_RXPD][TYPE_NOAVG],
360 adapter->NF[TYPE_RXPD][TYPE_NOAVG]);
361 break;
362 case 3:
363 temp = CAL_RSSI(adapter->SNR[TYPE_RXPD][TYPE_AVG] / AVG_SCALE,
364 adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE);
365 break;
366 default:
367 return -ENOTSUPP;
368 }
369 val = (int *)wrq->u.name;
370 *val = temp;
371
372 LEAVE();
373 return 0;
374}
375
376static int wlan_get_nf(wlan_private * priv, struct iwreq *wrq)
377{
378 int ret = 0;
379 wlan_adapter *adapter = priv->adapter;
380 int temp;
381 int data = 0;
382 int *val;
383
384 data = SUBCMD_DATA(wrq);
385 if ((data == 0) || (data == 1)) {
386 ret = libertas_prepare_and_send_command(priv,
387 cmd_802_11_rssi,
388 0, cmd_option_waitforrsp,
389 0, NULL);
390
391 if (ret) {
392 LEAVE();
393 return ret;
394 }
395 }
396
397 switch (data) {
398 case 0:
399 temp = adapter->NF[TYPE_BEACON][TYPE_NOAVG];
400 break;
401 case 1:
402 temp = adapter->NF[TYPE_BEACON][TYPE_AVG];
403 break;
404 case 2:
405 temp = adapter->NF[TYPE_RXPD][TYPE_NOAVG];
406 break;
407 case 3:
408 temp = adapter->NF[TYPE_RXPD][TYPE_AVG] / AVG_SCALE;
409 break;
410 default:
411 return -ENOTSUPP;
412 }
413
414 temp = CAL_NF(temp);
415
416 lbs_pr_debug(1, "%s: temp = %d\n", __FUNCTION__, temp);
417 val = (int *)wrq->u.name;
418 *val = temp;
419 return 0;
420}
421
422static int wlan_get_txrate_ioctl(wlan_private * priv, struct ifreq *req)
423{
424 wlan_adapter *adapter = priv->adapter;
425 int *pdata;
426 struct iwreq *wrq = (struct iwreq *)req;
427 int ret = 0;
428 adapter->txrate = 0;
429 lbs_pr_debug(1, "wlan_get_txrate_ioctl\n");
430 ret = libertas_prepare_and_send_command(priv, cmd_802_11_tx_rate_query,
431 cmd_act_get, cmd_option_waitforrsp,
432 0, NULL);
433 if (ret)
434 return ret;
435
436 pdata = (int *)wrq->u.name;
437 *pdata = (int)adapter->txrate;
438 return 0;
439}
440
441static int wlan_get_adhoc_status_ioctl(wlan_private * priv, struct iwreq *wrq)
442{
443 char status[64];
444 wlan_adapter *adapter = priv->adapter;
445
446 memset(status, 0, sizeof(status));
447
448 switch (adapter->inframode) {
449 case wlan802_11ibss:
450 if (adapter->connect_status == libertas_connected) {
451 if (adapter->adhoccreate)
452 memcpy(&status, "AdhocStarted", sizeof(status));
453 else
454 memcpy(&status, "AdhocJoined", sizeof(status));
455 } else {
456 memcpy(&status, "AdhocIdle", sizeof(status));
457 }
458 break;
459 case wlan802_11infrastructure:
460 memcpy(&status, "Inframode", sizeof(status));
461 break;
462 default:
463 memcpy(&status, "AutoUnknownmode", sizeof(status));
464 break;
465 }
466
467 lbs_pr_debug(1, "status = %s\n", status);
468 wrq->u.data.length = strlen(status) + 1;
469
470 if (wrq->u.data.pointer) {
471 if (copy_to_user(wrq->u.data.pointer,
472 &status, wrq->u.data.length))
473 return -EFAULT;
474 }
475
476 LEAVE();
477 return 0;
478}
479
480/**
481 * @brief Set/Get WPA IE
482 * @param priv A pointer to wlan_private structure
483 * @param req A pointer to ifreq structure
484 * @return 0 --success, otherwise fail
485 */
486static int wlan_setwpaie_ioctl(wlan_private * priv, struct ifreq *req)
487{
488 struct iwreq *wrq = (struct iwreq *)req;
489 wlan_adapter *adapter = priv->adapter;
490 int ret = 0;
491
492 ENTER();
493
494 if (wrq->u.data.length) {
495 if (wrq->u.data.length > sizeof(adapter->wpa_ie)) {
496 lbs_pr_debug(1, "failed to copy WPA IE, too big \n");
497 return -EFAULT;
498 }
499 if (copy_from_user(adapter->wpa_ie, wrq->u.data.pointer,
500 wrq->u.data.length)) {
501 lbs_pr_debug(1, "failed to copy WPA IE \n");
502 return -EFAULT;
503 }
504 adapter->wpa_ie_len = wrq->u.data.length;
505 lbs_pr_debug(1, "Set wpa_ie_len=%d IE=%#x\n", adapter->wpa_ie_len,
506 adapter->wpa_ie[0]);
507 lbs_dbg_hex("wpa_ie", adapter->wpa_ie, adapter->wpa_ie_len);
508 if (adapter->wpa_ie[0] == WPA_IE)
509 adapter->secinfo.WPAenabled = 1;
510 else if (adapter->wpa_ie[0] == WPA2_IE)
511 adapter->secinfo.WPA2enabled = 1;
512 else {
513 adapter->secinfo.WPAenabled = 0;
514 adapter->secinfo.WPA2enabled = 0;
515 }
516 } else {
517 memset(adapter->wpa_ie, 0, sizeof(adapter->wpa_ie));
518 adapter->wpa_ie_len = wrq->u.data.length;
519 lbs_pr_debug(1, "Reset wpa_ie_len=%d IE=%#x\n",
520 adapter->wpa_ie_len, adapter->wpa_ie[0]);
521 adapter->secinfo.WPAenabled = 0;
522 adapter->secinfo.WPA2enabled = 0;
523 }
524
525 // enable/disable RSN in firmware if WPA is enabled/disabled
526 // depending on variable adapter->secinfo.WPAenabled is set or not
527 ret = libertas_prepare_and_send_command(priv, cmd_802_11_enable_rsn,
528 cmd_act_set, cmd_option_waitforrsp,
529 0, NULL);
530
531 LEAVE();
532 return ret;
533}
534
535/**
536 * @brief Set Auto prescan
537 * @param priv A pointer to wlan_private structure
538 * @param wrq A pointer to iwreq structure
539 * @return 0 --success, otherwise fail
540 */
541static int wlan_subcmd_setprescan_ioctl(wlan_private * priv, struct iwreq *wrq)
542{
543 int data;
544 wlan_adapter *adapter = priv->adapter;
545 int *val;
546
547 data = SUBCMD_DATA(wrq);
548 lbs_pr_debug(1, "WLAN_SUBCMD_SET_PRESCAN %d\n", data);
549 adapter->prescan = data;
550
551 val = (int *)wrq->u.name;
552 *val = data;
553 return 0;
554}
555
556static int wlan_set_multiple_dtim_ioctl(wlan_private * priv, struct ifreq *req)
557{
558 struct iwreq *wrq = (struct iwreq *)req;
559 u32 mdtim;
560 int idata;
561 int ret = -EINVAL;
562
563 ENTER();
564
565 idata = SUBCMD_DATA(wrq);
566 mdtim = (u32) idata;
567 if (((mdtim >= MRVDRV_MIN_MULTIPLE_DTIM)
568 && (mdtim <= MRVDRV_MAX_MULTIPLE_DTIM))
569 || (mdtim == MRVDRV_IGNORE_MULTIPLE_DTIM)) {
570 priv->adapter->multipledtim = mdtim;
571 ret = 0;
572 }
573 if (ret)
574 lbs_pr_debug(1, "Invalid parameter, multipledtim not changed.\n");
575
576 LEAVE();
577 return ret;
578}
579
580/**
581 * @brief Set authentication mode
582 * @param priv A pointer to wlan_private structure
583 * @param req A pointer to ifreq structure
584 * @return 0 --success, otherwise fail
585 */
586static int wlan_setauthalg_ioctl(wlan_private * priv, struct ifreq *req)
587{
588 int alg;
589 struct iwreq *wrq = (struct iwreq *)req;
590 wlan_adapter *adapter = priv->adapter;
591
592 if (wrq->u.data.flags == 0) {
593 //from iwpriv subcmd
594 alg = SUBCMD_DATA(wrq);
595 } else {
596 //from wpa_supplicant subcmd
597 if (copy_from_user(&alg, wrq->u.data.pointer, sizeof(alg))) {
598 lbs_pr_debug(1, "Copy from user failed\n");
599 return -EFAULT;
600 }
601 }
602
603 lbs_pr_debug(1, "auth alg is %#x\n", alg);
604
605 switch (alg) {
606 case AUTH_ALG_SHARED_KEY:
607 adapter->secinfo.authmode = wlan802_11authmodeshared;
608 break;
609 case AUTH_ALG_NETWORK_EAP:
610 adapter->secinfo.authmode =
611 wlan802_11authmodenetworkEAP;
612 break;
613 case AUTH_ALG_OPEN_SYSTEM:
614 default:
615 adapter->secinfo.authmode = wlan802_11authmodeopen;
616 break;
617 }
618 return 0;
619}
620
621/**
622 * @brief Set 802.1x authentication mode
623 * @param priv A pointer to wlan_private structure
624 * @param req A pointer to ifreq structure
625 * @return 0 --success, otherwise fail
626 */
627static int wlan_set8021xauthalg_ioctl(wlan_private * priv, struct ifreq *req)
628{
629 int alg;
630 struct iwreq *wrq = (struct iwreq *)req;
631
632 if (wrq->u.data.flags == 0) {
633 //from iwpriv subcmd
634 alg = SUBCMD_DATA(wrq);
635 } else {
636 //from wpa_supplicant subcmd
637 if (copy_from_user(&alg, wrq->u.data.pointer, sizeof(int))) {
638 lbs_pr_debug(1, "Copy from user failed\n");
639 return -EFAULT;
640 }
641 }
642 lbs_pr_debug(1, "802.1x auth alg is %#x\n", alg);
643 priv->adapter->secinfo.auth1xalg = alg;
644 return 0;
645}
646
647static int wlan_setencryptionmode_ioctl(wlan_private * priv, struct ifreq *req)
648{
649 int mode;
650 struct iwreq *wrq = (struct iwreq *)req;
651
652 ENTER();
653
654 if (wrq->u.data.flags == 0) {
655 //from iwpriv subcmd
656 mode = SUBCMD_DATA(wrq);
657 } else {
658 //from wpa_supplicant subcmd
659 if (copy_from_user(&mode, wrq->u.data.pointer, sizeof(int))) {
660 lbs_pr_debug(1, "Copy from user failed\n");
661 return -EFAULT;
662 }
663 }
664 lbs_pr_debug(1, "encryption mode is %#x\n", mode);
665 priv->adapter->secinfo.Encryptionmode = mode;
666
667 LEAVE();
668 return 0;
669}
670
671static void adjust_mtu(wlan_private * priv)
672{
673 int mtu_increment = 0;
674
675 if (priv->adapter->linkmode == WLAN_LINKMODE_802_11)
676 mtu_increment += sizeof(struct ieee80211_hdr_4addr);
677
678 if (priv->adapter->radiomode == WLAN_RADIOMODE_RADIOTAP)
679 mtu_increment += max(sizeof(struct tx_radiotap_hdr),
680 sizeof(struct rx_radiotap_hdr));
681 priv->wlan_dev.netdev->mtu = ETH_FRAME_LEN
682 - sizeof(struct ethhdr)
683 + mtu_increment;
684}
685
686/**
687 * @brief Set Link-Layer Layer mode
688 * @param priv A pointer to wlan_private structure
689 * @param req A pointer to ifreq structure
690 * @return 0 --success, otherwise fail
691 */
692static int wlan_set_linkmode_ioctl(wlan_private * priv, struct ifreq *req)
693{
694 int mode;
695
696 mode = (int)((struct ifreq *)((u8 *) req + 4))->ifr_data;
697
698 switch (mode) {
699 case WLAN_LINKMODE_802_3:
700 priv->adapter->linkmode = mode;
701 break;
702 case WLAN_LINKMODE_802_11:
703 priv->adapter->linkmode = mode;
704 break;
705 default:
706 lbs_pr_info("usb8388-5: invalid link-layer mode (%#x)\n",
707 mode);
708 return -EINVAL;
709 break;
710 }
711 lbs_pr_debug(1, "usb8388-5: link-layer mode is %#x\n", mode);
712
713 adjust_mtu(priv);
714
715 return 0;
716}
717
718/**
719 * @brief Set Radio header mode
720 * @param priv A pointer to wlan_private structure
721 * @param req A pointer to ifreq structure
722 * @return 0 --success, otherwise fail
723 */
724static int wlan_set_radiomode_ioctl(wlan_private * priv, struct ifreq *req)
725{
726 int mode;
727
728 mode = (int)((struct ifreq *)((u8 *) req + 4))->ifr_data;
729
730 switch (mode) {
731 case WLAN_RADIOMODE_NONE:
732 priv->adapter->radiomode = mode;
733 break;
734 case WLAN_RADIOMODE_RADIOTAP:
735 priv->adapter->radiomode = mode;
736 break;
737 default:
738 lbs_pr_debug(1, "usb8388-5: invalid radio header mode (%#x)\n",
739 mode);
740 return -EINVAL;
741 }
742 lbs_pr_debug(1, "usb8388-5: radio-header mode is %#x\n", mode);
743
744 adjust_mtu(priv);
745 return 0;
746}
747
748/**
749 * @brief Set Debug header mode
750 * @param priv A pointer to wlan_private structure
751 * @param req A pointer to ifreq structure
752 * @return 0 --success, otherwise fail
753 */
754static int wlan_set_debugmode_ioctl(wlan_private * priv, struct ifreq *req)
755{
756 priv->adapter->debugmode = (int)((struct ifreq *)
757 ((u8 *) req + 4))->ifr_data;
758 return 0;
759}
760
761static int wlan_subcmd_getrxantenna_ioctl(wlan_private * priv,
762 struct ifreq *req)
763{
764 int len;
765 char buf[8];
766 struct iwreq *wrq = (struct iwreq *)req;
767
768 lbs_pr_debug(1, "WLAN_SUBCMD_GETRXANTENNA\n");
769 len = getrxantenna(priv, buf);
770
771 wrq->u.data.length = len;
772 if (wrq->u.data.pointer) {
773 if (copy_to_user(wrq->u.data.pointer, &buf, len)) {
774 lbs_pr_debug(1, "CopyToUser failed\n");
775 return -EFAULT;
776 }
777 }
778
779 return 0;
780}
781
782static int wlan_subcmd_gettxantenna_ioctl(wlan_private * priv,
783 struct ifreq *req)
784{
785 int len;
786 char buf[8];
787 struct iwreq *wrq = (struct iwreq *)req;
788
789 lbs_pr_debug(1, "WLAN_SUBCMD_GETTXANTENNA\n");
790 len = gettxantenna(priv, buf);
791
792 wrq->u.data.length = len;
793 if (wrq->u.data.pointer) {
794 if (copy_to_user(wrq->u.data.pointer, &buf, len)) {
795 lbs_pr_debug(1, "CopyToUser failed\n");
796 return -EFAULT;
797 }
798 }
799 return 0;
800}
801
802/**
803 * @brief Get the MAC TSF value from the firmware
804 *
805 * @param priv A pointer to wlan_private structure
806 * @param wrq A pointer to iwreq structure containing buffer
807 * space to store a TSF value retrieved from the firmware
808 *
809 * @return 0 if successful; IOCTL error code otherwise
810 */
811static int wlan_get_tsf_ioctl(wlan_private * priv, struct iwreq *wrq)
812{
813 u64 tsfval;
814 int ret;
815
816 ret = libertas_prepare_and_send_command(priv,
817 cmd_get_tsf,
818 0, cmd_option_waitforrsp, 0, &tsfval);
819
820 lbs_pr_debug(1, "IOCTL: Get TSF = 0x%016llx\n", tsfval);
821
822 if (ret != 0) {
823 lbs_pr_debug(1, "IOCTL: Get TSF; command exec failed\n");
824 ret = -EFAULT;
825 } else {
826 if (copy_to_user(wrq->u.data.pointer,
827 &tsfval,
828 min_t(size_t, wrq->u.data.length,
829 sizeof(tsfval))) != 0) {
830
831 lbs_pr_debug(1, "IOCTL: Get TSF; Copy to user failed\n");
832 ret = -EFAULT;
833 } else {
834 ret = 0;
835 }
836 }
837 return ret;
838}
839
840/**
841 * @brief Get/Set adapt rate
842 * @param priv A pointer to wlan_private structure
843 * @param wrq A pointer to iwreq structure
844 * @return 0 --success, otherwise fail
845 */
846static int wlan_adapt_rateset(wlan_private * priv, struct iwreq *wrq)
847{
848 int ret;
849 wlan_adapter *adapter = priv->adapter;
850 int data[2];
851
852 memset(data, 0, sizeof(data));
853 if (!wrq->u.data.length) {
854 lbs_pr_debug(1, "Get ADAPT RATE SET\n");
855 ret = libertas_prepare_and_send_command(priv,
856 cmd_802_11_rate_adapt_rateset,
857 cmd_act_get,
858 cmd_option_waitforrsp, 0, NULL);
859 data[0] = adapter->enablehwauto;
860 data[1] = adapter->ratebitmap;
861 if (copy_to_user(wrq->u.data.pointer, data, sizeof(int) * 2)) {
862 lbs_pr_debug(1, "Copy to user failed\n");
863 return -EFAULT;
864 }
865#define GET_TWO_INT 2
866 wrq->u.data.length = GET_TWO_INT;
867 } else {
868 lbs_pr_debug(1, "Set ADAPT RATE SET\n");
869 if (wrq->u.data.length > 2)
870 return -EINVAL;
871 if (copy_from_user
872 (data, wrq->u.data.pointer,
873 sizeof(int) * wrq->u.data.length)) {
874 lbs_pr_debug(1, "Copy from user failed\n");
875 return -EFAULT;
876 }
877
878 adapter->enablehwauto = data[0];
879 adapter->ratebitmap = data[1];
880 ret = libertas_prepare_and_send_command(priv,
881 cmd_802_11_rate_adapt_rateset,
882 cmd_act_set,
883 cmd_option_waitforrsp, 0, NULL);
884 }
885 return ret;
886}
887
888/**
889 * @brief Get/Set inactivity timeout
890 * @param priv A pointer to wlan_private structure
891 * @param wrq A pointer to iwreq structure
892 * @return 0 --success, otherwise fail
893 */
894static int wlan_inactivity_timeout(wlan_private * priv, struct iwreq *wrq)
895{
896 int ret;
897 int data = 0;
898 u16 timeout = 0;
899
900 ENTER();
901 if (wrq->u.data.length > 1)
902 return -ENOTSUPP;
903
904 if (wrq->u.data.length == 0) {
905 /* Get */
906 ret = libertas_prepare_and_send_command(priv,
907 cmd_802_11_inactivity_timeout,
908 cmd_act_get,
909 cmd_option_waitforrsp, 0,
910 &timeout);
911 data = timeout;
912 if (copy_to_user(wrq->u.data.pointer, &data, sizeof(int))) {
913 lbs_pr_debug(1, "Copy to user failed\n");
914 return -EFAULT;
915 }
916 } else {
917 /* Set */
918 if (copy_from_user(&data, wrq->u.data.pointer, sizeof(int))) {
919 lbs_pr_debug(1, "Copy from user failed\n");
920 return -EFAULT;
921 }
922
923 timeout = data;
924 ret = libertas_prepare_and_send_command(priv,
925 cmd_802_11_inactivity_timeout,
926 cmd_act_set,
927 cmd_option_waitforrsp, 0,
928 &timeout);
929 }
930
931 wrq->u.data.length = 1;
932
933 LEAVE();
934 return ret;
935}
936
937static int wlan_do_getlog_ioctl(wlan_private * priv, struct iwreq *wrq)
938{
939 int ret;
940 char buf[GETLOG_BUFSIZE - 1];
941 wlan_adapter *adapter = priv->adapter;
942
943 lbs_pr_debug(1, " GET STATS\n");
944
945 ret = libertas_prepare_and_send_command(priv, cmd_802_11_get_log,
946 0, cmd_option_waitforrsp, 0, NULL);
947
948 if (ret) {
949 return ret;
950 }
951
952 if (wrq->u.data.pointer) {
953 sprintf(buf, "\n mcasttxframe %u failed %u retry %u "
954 "multiretry %u framedup %u "
955 "rtssuccess %u rtsfailure %u ackfailure %u\n"
956 "rxfrag %u mcastrxframe %u fcserror %u "
957 "txframe %u wepundecryptable %u ",
958 adapter->logmsg.mcasttxframe,
959 adapter->logmsg.failed,
960 adapter->logmsg.retry,
961 adapter->logmsg.multiretry,
962 adapter->logmsg.framedup,
963 adapter->logmsg.rtssuccess,
964 adapter->logmsg.rtsfailure,
965 adapter->logmsg.ackfailure,
966 adapter->logmsg.rxfrag,
967 adapter->logmsg.mcastrxframe,
968 adapter->logmsg.fcserror,
969 adapter->logmsg.txframe,
970 adapter->logmsg.wepundecryptable);
971 wrq->u.data.length = strlen(buf) + 1;
972 if (copy_to_user(wrq->u.data.pointer, buf, wrq->u.data.length)) {
973 lbs_pr_debug(1, "Copy to user failed\n");
974 return -EFAULT;
975 }
976 }
977
978 return 0;
979}
980
981static int wlan_scan_type_ioctl(wlan_private * priv, struct iwreq *wrq)
982{
983 u8 buf[12];
984 u8 *option[] = { "active", "passive", "get", };
985 int i, max_options = (sizeof(option) / sizeof(option[0]));
986 int ret = 0;
987 wlan_adapter *adapter = priv->adapter;
988
989 if (priv->adapter->enable11d) {
990 lbs_pr_debug(1, "11D: Cannot set scantype when 11D enabled\n");
991 return -EFAULT;
992 }
993
994 memset(buf, 0, sizeof(buf));
995
996 if (copy_from_user(buf, wrq->u.data.pointer, min_t(size_t, sizeof(buf),
997 wrq->u.data.length)))
998 return -EFAULT;
999
1000 lbs_pr_debug(1, "Scan type Option = %s\n", buf);
1001
1002 buf[sizeof(buf) - 1] = '\0';
1003
1004 for (i = 0; i < max_options; i++) {
1005 if (!strcmp(buf, option[i]))
1006 break;
1007 }
1008
1009 switch (i) {
1010 case 0:
1011 adapter->scantype = cmd_scan_type_active;
1012 break;
1013 case 1:
1014 adapter->scantype = cmd_scan_type_passive;
1015 break;
1016 case 2:
1017 wrq->u.data.length = strlen(option[adapter->scantype]) + 1;
1018
1019 if (copy_to_user(wrq->u.data.pointer,
1020 option[adapter->scantype],
1021 wrq->u.data.length)) {
1022 lbs_pr_debug(1, "Copy to user failed\n");
1023 ret = -EFAULT;
1024 }
1025
1026 break;
1027 default:
1028 lbs_pr_debug(1, "Invalid Scan type Ioctl Option\n");
1029 ret = -EINVAL;
1030 break;
1031 }
1032
1033 return ret;
1034}
1035
1036static int wlan_scan_mode_ioctl(wlan_private * priv, struct iwreq *wrq)
1037{
1038 wlan_adapter *adapter = priv->adapter;
1039 u8 buf[12];
1040 u8 *option[] = { "bss", "ibss", "any", "get" };
1041 int i, max_options = (sizeof(option) / sizeof(option[0]));
1042 int ret = 0;
1043
1044 ENTER();
1045
1046 memset(buf, 0, sizeof(buf));
1047
1048 if (copy_from_user(buf, wrq->u.data.pointer, min_t(size_t, sizeof(buf),
1049 wrq->u.data.length))) {
1050 lbs_pr_debug(1, "Copy from user failed\n");
1051 return -EFAULT;
1052 }
1053
1054 lbs_pr_debug(1, "Scan mode Option = %s\n", buf);
1055
1056 buf[sizeof(buf) - 1] = '\0';
1057
1058 for (i = 0; i < max_options; i++) {
1059 if (!strcmp(buf, option[i]))
1060 break;
1061 }
1062
1063 switch (i) {
1064
1065 case 0:
1066 adapter->scanmode = cmd_bss_type_bss;
1067 break;
1068 case 1:
1069 adapter->scanmode = cmd_bss_type_ibss;
1070 break;
1071 case 2:
1072 adapter->scanmode = cmd_bss_type_any;
1073 break;
1074 case 3:
1075
1076 wrq->u.data.length = strlen(option[adapter->scanmode - 1]) + 1;
1077
1078 lbs_pr_debug(1, "Get Scan mode Option = %s\n",
1079 option[adapter->scanmode - 1]);
1080
1081 lbs_pr_debug(1, "Scan mode length %d\n", wrq->u.data.length);
1082
1083 if (copy_to_user(wrq->u.data.pointer,
1084 option[adapter->scanmode - 1],
1085 wrq->u.data.length)) {
1086 lbs_pr_debug(1, "Copy to user failed\n");
1087 ret = -EFAULT;
1088 }
1089 lbs_pr_debug(1, "GET Scan type Option after copy = %s\n",
1090 (char *)wrq->u.data.pointer);
1091
1092 break;
1093
1094 default:
1095 lbs_pr_debug(1, "Invalid Scan mode Ioctl Option\n");
1096 ret = -EINVAL;
1097 break;
1098 }
1099
1100 LEAVE();
1101 return ret;
1102}
1103
1104/**
1105 * @brief Get/Set Adhoc G Rate
1106 *
1107 * @param priv A pointer to wlan_private structure
1108 * @param wrq A pointer to user data
1109 * @return 0--success, otherwise fail
1110 */
1111static int wlan_do_set_grate_ioctl(wlan_private * priv, struct iwreq *wrq)
1112{
1113 wlan_adapter *adapter = priv->adapter;
1114 int data, data1;
1115 int *val;
1116
1117 ENTER();
1118
1119 data1 = SUBCMD_DATA(wrq);
1120 switch (data1) {
1121 case 0:
1122 adapter->adhoc_grate_enabled = 0;
1123 break;
1124 case 1:
1125 adapter->adhoc_grate_enabled = 1;
1126 break;
1127 case 2:
1128 break;
1129 default:
1130 return -EINVAL;
1131 }
1132 data = adapter->adhoc_grate_enabled;
1133 val = (int *)wrq->u.name;
1134 *val = data;
1135 LEAVE();
1136 return 0;
1137}
1138
1139static inline int hex2int(char c) 58static inline int hex2int(char c)
1140{ 59{
1141 if (c >= '0' && c <= '9') 60 if (c >= '0' && c <= '9')
@@ -1761,6 +680,7 @@ static int wlan_fwt_list_neighbor_ioctl(wlan_private * priv, struct ifreq *req)
1761 */ 680 */
1762static int wlan_fwt_cleanup_ioctl(wlan_private * priv, struct ifreq *req) 681static int wlan_fwt_cleanup_ioctl(wlan_private * priv, struct ifreq *req)
1763{ 682{
683 struct iwreq *wrq = (struct iwreq *)req;
1764 static struct cmd_ds_fwt_access fwt_access; 684 static struct cmd_ds_fwt_access fwt_access;
1765 int ret; 685 int ret;
1766 686
@@ -1776,7 +696,7 @@ static int wlan_fwt_cleanup_ioctl(wlan_private * priv, struct ifreq *req)
1776 (void *)&fwt_access); 696 (void *)&fwt_access);
1777 697
1778 if (ret == 0) 698 if (ret == 0)
1779 req->ifr_data = (char *)(le32_to_cpu(fwt_access.references)); 699 wrq->u.param.value = le32_to_cpu(fwt_access.references);
1780 else 700 else
1781 return -EFAULT; 701 return -EFAULT;
1782 702
@@ -1792,6 +712,7 @@ static int wlan_fwt_cleanup_ioctl(wlan_private * priv, struct ifreq *req)
1792 */ 712 */
1793static int wlan_fwt_time_ioctl(wlan_private * priv, struct ifreq *req) 713static int wlan_fwt_time_ioctl(wlan_private * priv, struct ifreq *req)
1794{ 714{
715 struct iwreq *wrq = (struct iwreq *)req;
1795 static struct cmd_ds_fwt_access fwt_access; 716 static struct cmd_ds_fwt_access fwt_access;
1796 int ret; 717 int ret;
1797 718
@@ -1807,7 +728,7 @@ static int wlan_fwt_time_ioctl(wlan_private * priv, struct ifreq *req)
1807 (void *)&fwt_access); 728 (void *)&fwt_access);
1808 729
1809 if (ret == 0) 730 if (ret == 0)
1810 req->ifr_data = (char *)(le32_to_cpu(fwt_access.references)); 731 wrq->u.param.value = le32_to_cpu(fwt_access.references);
1811 else 732 else
1812 return -EFAULT; 733 return -EFAULT;
1813 734
@@ -1823,6 +744,7 @@ static int wlan_fwt_time_ioctl(wlan_private * priv, struct ifreq *req)
1823 */ 744 */
1824static int wlan_mesh_get_ttl_ioctl(wlan_private * priv, struct ifreq *req) 745static int wlan_mesh_get_ttl_ioctl(wlan_private * priv, struct ifreq *req)
1825{ 746{
747 struct iwreq *wrq = (struct iwreq *)req;
1826 struct cmd_ds_mesh_access mesh_access; 748 struct cmd_ds_mesh_access mesh_access;
1827 int ret; 749 int ret;
1828 750
@@ -1835,9 +757,8 @@ static int wlan_mesh_get_ttl_ioctl(wlan_private * priv, struct ifreq *req)
1835 cmd_option_waitforrsp, 0, 757 cmd_option_waitforrsp, 0,
1836 (void *)&mesh_access); 758 (void *)&mesh_access);
1837 759
1838 if (ret == 0) { 760 if (ret == 0)
1839 req->ifr_data = (char *)(le32_to_cpu(mesh_access.data[0])); 761 wrq->u.param.value = le32_to_cpu(mesh_access.data[0]);
1840 }
1841 else 762 else
1842 return -EFAULT; 763 return -EFAULT;
1843 764
@@ -1898,36 +819,8 @@ int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
1898 819
1899 lbs_pr_debug(1, "libertas_do_ioctl: ioctl cmd = 0x%x\n", cmd); 820 lbs_pr_debug(1, "libertas_do_ioctl: ioctl cmd = 0x%x\n", cmd);
1900 switch (cmd) { 821 switch (cmd) {
1901 case WLANSCAN_TYPE:
1902 lbs_pr_debug(1, "Scan type Ioctl\n");
1903 ret = wlan_scan_type_ioctl(priv, wrq);
1904 break;
1905
1906 case WLAN_SETNONE_GETNONE: /* set WPA mode on/off ioctl #20 */ 822 case WLAN_SETNONE_GETNONE: /* set WPA mode on/off ioctl #20 */
1907 switch (wrq->u.data.flags) { 823 switch (wrq->u.data.flags) {
1908 case WLANDEAUTH:
1909 lbs_pr_debug(1, "Deauth\n");
1910 libertas_send_deauth(priv);
1911 break;
1912
1913 case WLANADHOCSTOP:
1914 lbs_pr_debug(1, "Adhoc stop\n");
1915 ret = libertas_do_adhocstop_ioctl(priv);
1916 break;
1917
1918 case WLANRADIOON:
1919 wlan_radio_ioctl(priv, 1);
1920 break;
1921
1922 case WLANRADIOOFF:
1923 wlan_radio_ioctl(priv, 0);
1924 break;
1925 case WLANWLANIDLEON:
1926 libertas_idle_on(priv);
1927 break;
1928 case WLANWLANIDLEOFF:
1929 libertas_idle_off(priv);
1930 break;
1931 case WLAN_SUBCMD_BT_RESET: /* bt_reset */ 824 case WLAN_SUBCMD_BT_RESET: /* bt_reset */
1932 wlan_bt_reset_ioctl(priv); 825 wlan_bt_reset_ioctl(priv);
1933 break; 826 break;
@@ -1937,162 +830,19 @@ int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
1937 } /* End of switch */ 830 } /* End of switch */
1938 break; 831 break;
1939 832
1940 case WLANSETWPAIE:
1941 ret = wlan_setwpaie_ioctl(priv, req);
1942 break;
1943 case WLAN_SETINT_GETINT:
1944 /* The first 4 bytes of req->ifr_data is sub-ioctl number
1945 * after 4 bytes sits the payload.
1946 */
1947 subcmd = (int)req->ifr_data; //from iwpriv subcmd
1948 switch (subcmd) {
1949 case WLANNF:
1950 ret = wlan_get_nf(priv, wrq);
1951 break;
1952 case WLANRSSI:
1953 ret = wlan_get_rssi(priv, wrq);
1954 break;
1955 case WLANENABLE11D:
1956 ret = libertas_cmd_enable_11d(priv, wrq);
1957 break;
1958 case WLANADHOCGRATE:
1959 ret = wlan_do_set_grate_ioctl(priv, wrq);
1960 break;
1961 case WLAN_SUBCMD_SET_PRESCAN:
1962 ret = wlan_subcmd_setprescan_ioctl(priv, wrq);
1963 break;
1964 }
1965 break;
1966
1967 case WLAN_SETONEINT_GETONEINT:
1968 switch (wrq->u.data.flags) {
1969 case WLAN_BEACON_INTERVAL:
1970 ret = wlan_beacon_interval(priv, wrq);
1971 break;
1972
1973 case WLAN_LISTENINTRVL:
1974 if (!wrq->u.data.length) {
1975 int data;
1976 lbs_pr_debug(1, "Get locallisteninterval value\n");
1977#define GET_ONE_INT 1
1978 data = adapter->locallisteninterval;
1979 if (copy_to_user(wrq->u.data.pointer,
1980 &data, sizeof(int))) {
1981 lbs_pr_debug(1, "Copy to user failed\n");
1982 return -EFAULT;
1983 }
1984
1985 wrq->u.data.length = GET_ONE_INT;
1986 } else {
1987 int data;
1988 if (copy_from_user
1989 (&data, wrq->u.data.pointer, sizeof(int))) {
1990 lbs_pr_debug(1, "Copy from user failed\n");
1991 return -EFAULT;
1992 }
1993
1994 lbs_pr_debug(1, "Set locallisteninterval = %d\n",
1995 data);
1996#define MAX_U16_VAL 65535
1997 if (data > MAX_U16_VAL) {
1998 lbs_pr_debug(1, "Exceeds U16 value\n");
1999 return -EINVAL;
2000 }
2001 adapter->locallisteninterval = data;
2002 }
2003 break;
2004 case WLAN_TXCONTROL:
2005 ret = wlan_txcontrol(priv, wrq); //adds for txcontrol ioctl
2006 break;
2007
2008 case WLAN_NULLPKTINTERVAL:
2009 ret = wlan_null_pkt_interval(priv, wrq);
2010 break;
2011
2012 default:
2013 ret = -EOPNOTSUPP;
2014 break;
2015 }
2016 break;
2017
2018 case WLAN_SETONEINT_GETNONE: 833 case WLAN_SETONEINT_GETNONE:
2019 /* The first 4 bytes of req->ifr_data is sub-ioctl number 834 /* The first 4 bytes of req->ifr_data is sub-ioctl number
2020 * after 4 bytes sits the payload. 835 * after 4 bytes sits the payload.
2021 */ 836 */
2022 subcmd = wrq->u.data.flags; //from wpa_supplicant subcmd 837 subcmd = wrq->u.data.flags;
2023
2024 if (!subcmd) 838 if (!subcmd)
2025 subcmd = (int)req->ifr_data; //from iwpriv subcmd 839 subcmd = (int)wrq->u.param.value;
2026 840
2027 switch (subcmd) { 841 switch (subcmd) {
2028 case WLAN_SUBCMD_SETRXANTENNA: /* SETRXANTENNA */
2029 idata = SUBCMD_DATA(wrq);
2030 ret = setrxantenna(priv, idata);
2031 break;
2032 case WLAN_SUBCMD_SETTXANTENNA: /* SETTXANTENNA */
2033 idata = SUBCMD_DATA(wrq);
2034 ret = settxantenna(priv, idata);
2035 break;
2036 case WLAN_SET_ATIM_WINDOW:
2037 adapter->atimwindow = SUBCMD_DATA(wrq);
2038 adapter->atimwindow = min_t(__u16, adapter->atimwindow, 50);
2039 break;
2040 case WLANSETBCNAVG:
2041 adapter->bcn_avg_factor = SUBCMD_DATA(wrq);
2042 if (adapter->bcn_avg_factor == 0)
2043 adapter->bcn_avg_factor =
2044 DEFAULT_BCN_AVG_FACTOR;
2045 if (adapter->bcn_avg_factor > DEFAULT_BCN_AVG_FACTOR)
2046 adapter->bcn_avg_factor =
2047 DEFAULT_BCN_AVG_FACTOR;
2048 break;
2049 case WLANSETDATAAVG:
2050 adapter->data_avg_factor = SUBCMD_DATA(wrq);
2051 if (adapter->data_avg_factor == 0)
2052 adapter->data_avg_factor =
2053 DEFAULT_DATA_AVG_FACTOR;
2054 if (adapter->data_avg_factor > DEFAULT_DATA_AVG_FACTOR)
2055 adapter->data_avg_factor =
2056 DEFAULT_DATA_AVG_FACTOR;
2057 break;
2058 case WLANSETREGION: 842 case WLANSETREGION:
2059 idata = SUBCMD_DATA(wrq); 843 idata = SUBCMD_DATA(wrq);
2060 ret = wlan_set_region(priv, (u16) idata); 844 ret = wlan_set_region(priv, (u16) idata);
2061 break; 845 break;
2062
2063 case WLAN_SET_LISTEN_INTERVAL:
2064 idata = SUBCMD_DATA(wrq);
2065 adapter->listeninterval = (u16) idata;
2066 break;
2067
2068 case WLAN_SET_MULTIPLE_DTIM:
2069 ret = wlan_set_multiple_dtim_ioctl(priv, req);
2070 break;
2071
2072 case WLANSETAUTHALG:
2073 ret = wlan_setauthalg_ioctl(priv, req);
2074 break;
2075
2076 case WLANSET8021XAUTHALG:
2077 ret = wlan_set8021xauthalg_ioctl(priv, req);
2078 break;
2079
2080 case WLANSETENCRYPTIONMODE:
2081 ret = wlan_setencryptionmode_ioctl(priv, req);
2082 break;
2083
2084 case WLAN_SET_LINKMODE:
2085 ret = wlan_set_linkmode_ioctl(priv, req);
2086 break;
2087
2088 case WLAN_SET_RADIOMODE:
2089 ret = wlan_set_radiomode_ioctl(priv, req);
2090 break;
2091
2092 case WLAN_SET_DEBUGMODE:
2093 ret = wlan_set_debugmode_ioctl(priv, req);
2094 break;
2095
2096 case WLAN_SUBCMD_MESH_SET_TTL: 846 case WLAN_SUBCMD_MESH_SET_TTL:
2097 idata = SUBCMD_DATA(wrq); 847 idata = SUBCMD_DATA(wrq);
2098 ret = wlan_mesh_set_ttl_ioctl(priv, idata); 848 ret = wlan_mesh_set_ttl_ioctl(priv, idata);
@@ -2105,38 +855,8 @@ int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
2105 855
2106 break; 856 break;
2107 857
2108 case WLAN_SETNONE_GETTWELVE_CHAR: /* Get Antenna settings */
2109 /*
2110 * We've not used IW_PRIV_TYPE_FIXED so sub-ioctl number is
2111 * in flags of iwreq structure, otherwise it will be in
2112 * mode member of iwreq structure.
2113 */
2114 switch ((int)wrq->u.data.flags) {
2115 case WLAN_SUBCMD_GETRXANTENNA: /* Get Rx Antenna */
2116 ret = wlan_subcmd_getrxantenna_ioctl(priv, req);
2117 break;
2118
2119 case WLAN_SUBCMD_GETTXANTENNA: /* Get Tx Antenna */
2120 ret = wlan_subcmd_gettxantenna_ioctl(priv, req);
2121 break;
2122
2123 case WLAN_GET_TSF:
2124 ret = wlan_get_tsf_ioctl(priv, wrq);
2125 break;
2126 }
2127 break;
2128
2129 case WLAN_SET128CHAR_GET128CHAR: 858 case WLAN_SET128CHAR_GET128CHAR:
2130 switch ((int)wrq->u.data.flags) { 859 switch ((int)wrq->u.data.flags) {
2131
2132 case WLANSCAN_MODE:
2133 lbs_pr_debug(1, "Scan mode Ioctl\n");
2134 ret = wlan_scan_mode_ioctl(priv, wrq);
2135 break;
2136
2137 case WLAN_GET_ADHOC_STATUS:
2138 ret = wlan_get_adhoc_status_ioctl(priv, wrq);
2139 break;
2140 case WLAN_SUBCMD_BT_ADD: 860 case WLAN_SUBCMD_BT_ADD:
2141 ret = wlan_bt_add_ioctl(priv, req); 861 ret = wlan_bt_add_ioctl(priv, req);
2142 break; 862 break;
@@ -2168,41 +888,11 @@ int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
2168 break; 888 break;
2169 889
2170 case WLAN_SETNONE_GETONEINT: 890 case WLAN_SETNONE_GETONEINT:
2171 switch ((int)req->ifr_data) { 891 switch (wrq->u.param.value) {
2172 case WLANGETBCNAVG:
2173 pdata = (int *)wrq->u.name;
2174 *pdata = (int)adapter->bcn_avg_factor;
2175 break;
2176
2177 case WLANGETREGION: 892 case WLANGETREGION:
2178 pdata = (int *)wrq->u.name; 893 pdata = (int *)wrq->u.name;
2179 *pdata = (int)adapter->regioncode; 894 *pdata = (int)adapter->regioncode;
2180 break; 895 break;
2181
2182 case WLAN_GET_LISTEN_INTERVAL:
2183 pdata = (int *)wrq->u.name;
2184 *pdata = (int)adapter->listeninterval;
2185 break;
2186
2187 case WLAN_GET_LINKMODE:
2188 req->ifr_data = (char *)((u32) adapter->linkmode);
2189 break;
2190
2191 case WLAN_GET_RADIOMODE:
2192 req->ifr_data = (char *)((u32) adapter->radiomode);
2193 break;
2194
2195 case WLAN_GET_DEBUGMODE:
2196 req->ifr_data = (char *)((u32) adapter->debugmode);
2197 break;
2198
2199 case WLAN_GET_MULTIPLE_DTIM:
2200 pdata = (int *)wrq->u.name;
2201 *pdata = (int)adapter->multipledtim;
2202 break;
2203 case WLAN_GET_TX_RATE:
2204 ret = wlan_get_txrate_ioctl(priv, req);
2205 break;
2206 case WLAN_SUBCMD_FWT_CLEANUP: /* fwt_cleanup */ 896 case WLAN_SUBCMD_FWT_CLEANUP: /* fwt_cleanup */
2207 ret = wlan_fwt_cleanup_ioctl(priv, req); 897 ret = wlan_fwt_cleanup_ioctl(priv, req);
2208 break; 898 break;
@@ -2222,196 +912,8 @@ int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
2222 912
2223 break; 913 break;
2224 914
2225 case WLANGETLOG:
2226 ret = wlan_do_getlog_ioctl(priv, wrq);
2227 break;
2228
2229 case WLAN_SET_GET_SIXTEEN_INT: 915 case WLAN_SET_GET_SIXTEEN_INT:
2230 switch ((int)wrq->u.data.flags) { 916 switch ((int)wrq->u.data.flags) {
2231 case WLAN_TPCCFG:
2232 {
2233 int data[5];
2234 struct cmd_ds_802_11_tpc_cfg cfg;
2235 memset(&cfg, 0, sizeof(cfg));
2236 if ((wrq->u.data.length > 1)
2237 && (wrq->u.data.length != 5))
2238 return -1;
2239
2240 if (wrq->u.data.length == 0) {
2241 cfg.action =
2242 cpu_to_le16
2243 (cmd_act_get);
2244 } else {
2245 if (copy_from_user
2246 (data, wrq->u.data.pointer,
2247 sizeof(int) * 5)) {
2248 lbs_pr_debug(1,
2249 "Copy from user failed\n");
2250 return -EFAULT;
2251 }
2252
2253 cfg.action =
2254 cpu_to_le16
2255 (cmd_act_set);
2256 cfg.enable = data[0];
2257 cfg.usesnr = data[1];
2258 cfg.P0 = data[2];
2259 cfg.P1 = data[3];
2260 cfg.P2 = data[4];
2261 }
2262
2263 ret =
2264 libertas_prepare_and_send_command(priv,
2265 cmd_802_11_tpc_cfg,
2266 0,
2267 cmd_option_waitforrsp,
2268 0, (void *)&cfg);
2269
2270 data[0] = cfg.enable;
2271 data[1] = cfg.usesnr;
2272 data[2] = cfg.P0;
2273 data[3] = cfg.P1;
2274 data[4] = cfg.P2;
2275 if (copy_to_user
2276 (wrq->u.data.pointer, data,
2277 sizeof(int) * 5)) {
2278 lbs_pr_debug(1, "Copy to user failed\n");
2279 return -EFAULT;
2280 }
2281
2282 wrq->u.data.length = 5;
2283 }
2284 break;
2285
2286 case WLAN_POWERCFG:
2287 {
2288 int data[4];
2289 struct cmd_ds_802_11_pwr_cfg cfg;
2290 memset(&cfg, 0, sizeof(cfg));
2291 if ((wrq->u.data.length > 1)
2292 && (wrq->u.data.length != 4))
2293 return -1;
2294 if (wrq->u.data.length == 0) {
2295 cfg.action =
2296 cpu_to_le16
2297 (cmd_act_get);
2298 } else {
2299 if (copy_from_user
2300 (data, wrq->u.data.pointer,
2301 sizeof(int) * 4)) {
2302 lbs_pr_debug(1,
2303 "Copy from user failed\n");
2304 return -EFAULT;
2305 }
2306
2307 cfg.action =
2308 cpu_to_le16
2309 (cmd_act_set);
2310 cfg.enable = data[0];
2311 cfg.PA_P0 = data[1];
2312 cfg.PA_P1 = data[2];
2313 cfg.PA_P2 = data[3];
2314 }
2315 ret =
2316 libertas_prepare_and_send_command(priv,
2317 cmd_802_11_pwr_cfg,
2318 0,
2319 cmd_option_waitforrsp,
2320 0, (void *)&cfg);
2321 data[0] = cfg.enable;
2322 data[1] = cfg.PA_P0;
2323 data[2] = cfg.PA_P1;
2324 data[3] = cfg.PA_P2;
2325 if (copy_to_user
2326 (wrq->u.data.pointer, data,
2327 sizeof(int) * 4)) {
2328 lbs_pr_debug(1, "Copy to user failed\n");
2329 return -EFAULT;
2330 }
2331
2332 wrq->u.data.length = 4;
2333 }
2334 break;
2335 case WLAN_AUTO_FREQ_SET:
2336 {
2337 int data[3];
2338 struct cmd_ds_802_11_afc afc;
2339 memset(&afc, 0, sizeof(afc));
2340 if (wrq->u.data.length != 3)
2341 return -1;
2342 if (copy_from_user
2343 (data, wrq->u.data.pointer,
2344 sizeof(int) * 3)) {
2345 lbs_pr_debug(1, "Copy from user failed\n");
2346 return -EFAULT;
2347 }
2348 afc.afc_auto = data[0];
2349
2350 if (afc.afc_auto != 0) {
2351 afc.threshold = data[1];
2352 afc.period = data[2];
2353 } else {
2354 afc.timing_offset = data[1];
2355 afc.carrier_offset = data[2];
2356 }
2357 ret =
2358 libertas_prepare_and_send_command(priv,
2359 cmd_802_11_set_afc,
2360 0,
2361 cmd_option_waitforrsp,
2362 0, (void *)&afc);
2363 }
2364 break;
2365 case WLAN_AUTO_FREQ_GET:
2366 {
2367 int data[3];
2368 struct cmd_ds_802_11_afc afc;
2369 memset(&afc, 0, sizeof(afc));
2370 ret =
2371 libertas_prepare_and_send_command(priv,
2372 cmd_802_11_get_afc,
2373 0,
2374 cmd_option_waitforrsp,
2375 0, (void *)&afc);
2376 data[0] = afc.afc_auto;
2377 data[1] = afc.timing_offset;
2378 data[2] = afc.carrier_offset;
2379 if (copy_to_user
2380 (wrq->u.data.pointer, data,
2381 sizeof(int) * 3)) {
2382 lbs_pr_debug(1, "Copy to user failed\n");
2383 return -EFAULT;
2384 }
2385
2386 wrq->u.data.length = 3;
2387 }
2388 break;
2389 case WLAN_SCANPROBES:
2390 {
2391 int data;
2392 if (wrq->u.data.length > 0) {
2393 if (copy_from_user
2394 (&data, wrq->u.data.pointer,
2395 sizeof(int))) {
2396 lbs_pr_debug(1,
2397 "Copy from user failed\n");
2398 return -EFAULT;
2399 }
2400
2401 adapter->scanprobes = data;
2402 } else {
2403 data = adapter->scanprobes;
2404 if (copy_to_user
2405 (wrq->u.data.pointer, &data,
2406 sizeof(int))) {
2407 lbs_pr_debug(1,
2408 "Copy to user failed\n");
2409 return -EFAULT;
2410 }
2411 }
2412 wrq->u.data.length = 1;
2413 }
2414 break;
2415 case WLAN_LED_GPIO_CTRL: 917 case WLAN_LED_GPIO_CTRL:
2416 { 918 {
2417 int i; 919 int i;
@@ -2475,17 +977,6 @@ int libertas_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
2475 wrq->u.data.length = gpio->header.len; 977 wrq->u.data.length = gpio->header.len;
2476 } 978 }
2477 break; 979 break;
2478 case WLAN_ADAPT_RATESET:
2479 ret = wlan_adapt_rateset(priv, wrq);
2480 break;
2481 case WLAN_INACTIVITY_TIMEOUT:
2482 ret = wlan_inactivity_timeout(priv, wrq);
2483 break;
2484 case WLANSNR:
2485 ret = wlan_get_snr(priv, wrq);
2486 break;
2487 case WLAN_GET_RXINFO:
2488 ret = wlan_get_rxinfo(priv, wrq);
2489 } 980 }
2490 break; 981 break;
2491 982
diff --git a/drivers/net/wireless/libertas/join.c b/drivers/net/wireless/libertas/join.c
index 11682cbe752b..d4926b83e145 100644
--- a/drivers/net/wireless/libertas/join.c
+++ b/drivers/net/wireless/libertas/join.c
@@ -15,6 +15,8 @@
15#include "join.h" 15#include "join.h"
16#include "dev.h" 16#include "dev.h"
17 17
18#define AD_HOC_CAP_PRIVACY_ON 1
19
18/** 20/**
19 * @brief This function finds out the common rates between rate1 and rate2. 21 * @brief This function finds out the common rates between rate1 and rate2.
20 * 22 *
@@ -85,7 +87,7 @@ int libertas_send_deauth(wlan_private * priv)
85 wlan_adapter *adapter = priv->adapter; 87 wlan_adapter *adapter = priv->adapter;
86 int ret = 0; 88 int ret = 0;
87 89
88 if (adapter->inframode == wlan802_11infrastructure && 90 if (adapter->mode == IW_MODE_INFRA &&
89 adapter->connect_status == libertas_connected) 91 adapter->connect_status == libertas_connected)
90 ret = libertas_send_deauthentication(priv); 92 ret = libertas_send_deauthentication(priv);
91 else 93 else
@@ -94,20 +96,6 @@ int libertas_send_deauth(wlan_private * priv)
94 return ret; 96 return ret;
95} 97}
96 98
97int libertas_do_adhocstop_ioctl(wlan_private * priv)
98{
99 wlan_adapter *adapter = priv->adapter;
100 int ret = 0;
101
102 if (adapter->inframode == wlan802_11ibss &&
103 adapter->connect_status == libertas_connected)
104 ret = libertas_stop_adhoc_network(priv);
105 else
106 ret = -ENOTSUPP;
107
108 return ret;
109}
110
111/** 99/**
112 * @brief Associate to a specific BSS discovered in a scan 100 * @brief Associate to a specific BSS discovered in a scan
113 * 101 *
@@ -207,8 +195,7 @@ int libertas_join_adhoc_network(wlan_private * priv, struct bss_descriptor * pbs
207 /* check if the requested SSID is already joined */ 195 /* check if the requested SSID is already joined */
208 if (adapter->curbssparams.ssid.ssidlength 196 if (adapter->curbssparams.ssid.ssidlength
209 && !libertas_SSID_cmp(&pbssdesc->ssid, &adapter->curbssparams.ssid) 197 && !libertas_SSID_cmp(&pbssdesc->ssid, &adapter->curbssparams.ssid)
210 && (adapter->curbssparams.bssdescriptor.inframode == 198 && (adapter->mode == IW_MODE_ADHOC)) {
211 wlan802_11ibss)) {
212 199
213 lbs_pr_debug(1, 200 lbs_pr_debug(1,
214 "ADHOC_J_CMD: New ad-hoc SSID is the same as current, " 201 "ADHOC_J_CMD: New ad-hoc SSID is the same as current, "
@@ -261,130 +248,6 @@ int libertas_send_deauthentication(wlan_private * priv)
261} 248}
262 249
263/** 250/**
264 * @brief Set Idle Off
265 *
266 * @param priv A pointer to wlan_private structure
267 * @return 0 --success, otherwise fail
268 */
269int libertas_idle_off(wlan_private * priv)
270{
271 wlan_adapter *adapter = priv->adapter;
272 int ret = 0;
273 const u8 zeromac[] = { 0, 0, 0, 0, 0, 0 };
274 int i;
275
276 ENTER();
277
278 if (adapter->connect_status == libertas_disconnected) {
279 if (adapter->inframode == wlan802_11infrastructure) {
280 if (memcmp(adapter->previousbssid, zeromac,
281 sizeof(zeromac)) != 0) {
282
283 lbs_pr_debug(1, "Previous SSID = %s\n",
284 adapter->previousssid.ssid);
285 lbs_pr_debug(1, "Previous BSSID = "
286 "%02x:%02x:%02x:%02x:%02x:%02x:\n",
287 adapter->previousbssid[0],
288 adapter->previousbssid[1],
289 adapter->previousbssid[2],
290 adapter->previousbssid[3],
291 adapter->previousbssid[4],
292 adapter->previousbssid[5]);
293
294 i = libertas_find_SSID_in_list(adapter,
295 &adapter->previousssid,
296 adapter->previousbssid,
297 adapter->inframode);
298
299 if (i < 0) {
300 libertas_send_specific_BSSID_scan(priv,
301 adapter->
302 previousbssid,
303 1);
304 i = libertas_find_SSID_in_list(adapter,
305 &adapter->
306 previousssid,
307 adapter->
308 previousbssid,
309 adapter->
310 inframode);
311 }
312
313 if (i < 0) {
314 /* If the BSSID could not be found, try just the SSID */
315 i = libertas_find_SSID_in_list(adapter,
316 &adapter->
317 previousssid, NULL,
318 adapter->
319 inframode);
320 }
321
322 if (i < 0) {
323 libertas_send_specific_SSID_scan(priv,
324 &adapter->
325 previousssid,
326 1);
327 i = libertas_find_SSID_in_list(adapter,
328 &adapter->
329 previousssid, NULL,
330 adapter->
331 inframode);
332 }
333
334 if (i >= 0) {
335 ret =
336 wlan_associate(priv,
337 &adapter->
338 scantable[i]);
339 }
340 }
341 } else if (adapter->inframode == wlan802_11ibss) {
342 ret = libertas_prepare_and_send_command(priv,
343 cmd_802_11_ad_hoc_start,
344 0,
345 cmd_option_waitforrsp,
346 0, &adapter->previousssid);
347 }
348 }
349 /* else it is connected */
350
351 lbs_pr_debug(1, "\nwlanidle is off");
352 LEAVE();
353 return ret;
354}
355
356/**
357 * @brief Set Idle On
358 *
359 * @param priv A pointer to wlan_private structure
360 * @return 0 --success, otherwise fail
361 */
362int libertas_idle_on(wlan_private * priv)
363{
364 wlan_adapter *adapter = priv->adapter;
365 int ret = 0;
366
367 if (adapter->connect_status == libertas_connected) {
368 if (adapter->inframode == wlan802_11infrastructure) {
369 lbs_pr_debug(1, "Previous SSID = %s\n",
370 adapter->previousssid.ssid);
371 memmove(&adapter->previousssid,
372 &adapter->curbssparams.ssid,
373 sizeof(struct WLAN_802_11_SSID));
374 libertas_send_deauth(priv);
375
376 } else if (adapter->inframode == wlan802_11ibss) {
377 ret = libertas_stop_adhoc_network(priv);
378 }
379
380 }
381
382 lbs_pr_debug(1, "\nwlanidle is on");
383
384 return ret;
385}
386
387/**
388 * @brief This function prepares command of authenticate. 251 * @brief This function prepares command of authenticate.
389 * 252 *
390 * @param priv A pointer to wlan_private structure 253 * @param priv A pointer to wlan_private structure
@@ -398,22 +261,39 @@ int libertas_cmd_80211_authenticate(wlan_private * priv,
398 void *pdata_buf) 261 void *pdata_buf)
399{ 262{
400 wlan_adapter *adapter = priv->adapter; 263 wlan_adapter *adapter = priv->adapter;
401 struct cmd_ds_802_11_authenticate *pauthenticate = 264 struct cmd_ds_802_11_authenticate *pauthenticate = &cmd->params.auth;
402 &cmd->params.auth; 265 int ret = -1;
403 u8 *bssid = pdata_buf; 266 u8 *bssid = pdata_buf;
404 267
405 cmd->command = cpu_to_le16(cmd_802_11_authenticate); 268 cmd->command = cpu_to_le16(cmd_802_11_authenticate);
406 cmd->size = 269 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate)
407 cpu_to_le16(sizeof(struct cmd_ds_802_11_authenticate) 270 + S_DS_GEN);
408 + S_DS_GEN); 271
272 /* translate auth mode to 802.11 defined wire value */
273 switch (adapter->secinfo.auth_mode) {
274 case IW_AUTH_ALG_OPEN_SYSTEM:
275 pauthenticate->authtype = 0x00;
276 break;
277 case IW_AUTH_ALG_SHARED_KEY:
278 pauthenticate->authtype = 0x01;
279 break;
280 case IW_AUTH_ALG_LEAP:
281 pauthenticate->authtype = 0x80;
282 break;
283 default:
284 lbs_pr_debug(1, "AUTH_CMD: invalid auth alg 0x%X\n",
285 adapter->secinfo.auth_mode);
286 goto out;
287 }
409 288
410 pauthenticate->authtype = adapter->secinfo.authmode;
411 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN); 289 memcpy(pauthenticate->macaddr, bssid, ETH_ALEN);
412 290
413 lbs_pr_debug(1, "AUTH_CMD: Bssid is : %x:%x:%x:%x:%x:%x\n", 291 lbs_pr_debug(1, "AUTH_CMD: Bssid is : %x:%x:%x:%x:%x:%x\n",
414 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]); 292 bssid[0], bssid[1], bssid[2], bssid[3], bssid[4], bssid[5]);
293 ret = 0;
415 294
416 return 0; 295out:
296 return ret;
417} 297}
418 298
419int libertas_cmd_80211_deauthenticate(wlan_private * priv, 299int libertas_cmd_80211_deauthenticate(wlan_private * priv,
@@ -550,7 +430,7 @@ int libertas_cmd_80211_associate(wlan_private * priv,
550 lbs_pr_debug(1, "ASSOC_CMD: rates->header.len = %d\n", rates->header.len); 430 lbs_pr_debug(1, "ASSOC_CMD: rates->header.len = %d\n", rates->header.len);
551 431
552 /* set IBSS field */ 432 /* set IBSS field */
553 if (pbssdesc->inframode == wlan802_11infrastructure) { 433 if (pbssdesc->mode == IW_MODE_INFRA) {
554#define CAPINFO_ESS_MODE 1 434#define CAPINFO_ESS_MODE 1
555 passo->capinfo.ess = CAPINFO_ESS_MODE; 435 passo->capinfo.ess = CAPINFO_ESS_MODE;
556 } 436 }
@@ -624,7 +504,7 @@ int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
624 504
625 /* set the BSS type */ 505 /* set the BSS type */
626 adhs->bsstype = cmd_bss_type_ibss; 506 adhs->bsstype = cmd_bss_type_ibss;
627 pbssdesc->inframode = wlan802_11ibss; 507 pbssdesc->mode = IW_MODE_ADHOC;
628 adhs->beaconperiod = adapter->beaconperiod; 508 adhs->beaconperiod = adapter->beaconperiod;
629 509
630 /* set Physical param set */ 510 /* set Physical param set */
@@ -666,15 +546,12 @@ int libertas_cmd_80211_ad_hoc_start(wlan_private * priv,
666 adhs->probedelay = cpu_to_le16(cmd_scan_probe_delay_time); 546 adhs->probedelay = cpu_to_le16(cmd_scan_probe_delay_time);
667 547
668 /* set up privacy in adapter->scantable[i] */ 548 /* set up privacy in adapter->scantable[i] */
669 if (adapter->secinfo.WEPstatus == wlan802_11WEPenabled) { 549 if (adapter->secinfo.wep_enabled) {
670 550 lbs_pr_debug(1, "ADHOC_S_CMD: WEP enabled, setting privacy on\n");
671#define AD_HOC_CAP_PRIVACY_ON 1
672 lbs_pr_debug(1, "ADHOC_S_CMD: WEPstatus set, privacy to WEP\n");
673 pbssdesc->privacy = wlan802_11privfilter8021xWEP; 551 pbssdesc->privacy = wlan802_11privfilter8021xWEP;
674 adhs->cap.privacy = AD_HOC_CAP_PRIVACY_ON; 552 adhs->cap.privacy = AD_HOC_CAP_PRIVACY_ON;
675 } else { 553 } else {
676 lbs_pr_debug(1, "ADHOC_S_CMD: WEPstatus NOT set, Setting " 554 lbs_pr_debug(1, "ADHOC_S_CMD: WEP disabled, setting privacy off\n");
677 "privacy to ACCEPT ALL\n");
678 pbssdesc->privacy = wlan802_11privfilteracceptall; 555 pbssdesc->privacy = wlan802_11privfilteracceptall;
679 } 556 }
680 557
@@ -786,9 +663,6 @@ int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
786 padhocjoin->bssdescriptor.BSSID[5], 663 padhocjoin->bssdescriptor.BSSID[5],
787 padhocjoin->bssdescriptor.SSID); 664 padhocjoin->bssdescriptor.SSID);
788 665
789 lbs_pr_debug(1, "ADHOC_J_CMD: Data Rate = %x\n",
790 (u32) padhocjoin->bssdescriptor.datarates);
791
792 /* failtimeout */ 666 /* failtimeout */
793 padhocjoin->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT); 667 padhocjoin->failtimeout = cpu_to_le16(MRVDRV_ASSOCIATION_TIME_OUT);
794 668
@@ -832,7 +706,7 @@ int libertas_cmd_80211_ad_hoc_join(wlan_private * priv,
832 padhocjoin->bssdescriptor.ssparamset.ibssparamset.atimwindow = 706 padhocjoin->bssdescriptor.ssparamset.ibssparamset.atimwindow =
833 cpu_to_le16(pbssdesc->atimwindow); 707 cpu_to_le16(pbssdesc->atimwindow);
834 708
835 if (adapter->secinfo.WEPstatus == wlan802_11WEPenabled) { 709 if (adapter->secinfo.wep_enabled) {
836 padhocjoin->bssdescriptor.cap.privacy = AD_HOC_CAP_PRIVACY_ON; 710 padhocjoin->bssdescriptor.cap.privacy = AD_HOC_CAP_PRIVACY_ON;
837 } 711 }
838 712
diff --git a/drivers/net/wireless/libertas/join.h b/drivers/net/wireless/libertas/join.h
index 8efa2455af9a..115f5a8ba346 100644
--- a/drivers/net/wireless/libertas/join.h
+++ b/drivers/net/wireless/libertas/join.h
@@ -1,6 +1,3 @@
1/* -*- mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
2/* vi: set expandtab shiftwidth=4 tabstop=4 textwidth=78: */
3
4/** 1/**
5 * Interface for the wlan infrastructure and adhoc join routines 2 * Interface for the wlan infrastructure and adhoc join routines
6 * 3 *
@@ -40,10 +37,6 @@ extern int libertas_ret_80211_disassociate(wlan_private * priv,
40extern int libertas_ret_80211_associate(wlan_private * priv, 37extern int libertas_ret_80211_associate(wlan_private * priv,
41 struct cmd_ds_command *resp); 38 struct cmd_ds_command *resp);
42 39
43extern int libertas_idle_on(wlan_private * priv);
44extern int libertas_idle_off(wlan_private * priv);
45
46extern int libertas_do_adhocstop_ioctl(wlan_private * priv);
47extern int libertas_reassociation_thread(void *data); 40extern int libertas_reassociation_thread(void *data);
48 41
49struct WLAN_802_11_SSID; 42struct WLAN_802_11_SSID;
diff --git a/drivers/net/wireless/libertas/main.c b/drivers/net/wireless/libertas/main.c
index dcbf102a057e..b9b25ce65919 100644
--- a/drivers/net/wireless/libertas/main.c
+++ b/drivers/net/wireless/libertas/main.c
@@ -21,6 +21,13 @@
21#include "debugfs.h" 21#include "debugfs.h"
22#include "assoc.h" 22#include "assoc.h"
23 23
24#define DRIVER_RELEASE_VERSION "320.p0"
25const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
26#ifdef DEBUG
27 "-dbg"
28#endif
29 "";
30
24#ifdef ENABLE_PM 31#ifdef ENABLE_PM
25static struct pm_dev *wlan_pm_dev = NULL; 32static struct pm_dev *wlan_pm_dev = NULL;
26#endif 33#endif
diff --git a/drivers/net/wireless/libertas/rx.c b/drivers/net/wireless/libertas/rx.c
index 7e3f78f092dc..d17924f764e5 100644
--- a/drivers/net/wireless/libertas/rx.c
+++ b/drivers/net/wireless/libertas/rx.c
@@ -210,7 +210,7 @@ int libertas_process_rxed_packet(wlan_private * priv, struct sk_buff *skb)
210 goto done; 210 goto done;
211 } 211 }
212 212
213 lbs_pr_debug(1, "RX Data: skb->len - sizeof(RxPd) = %d - %d = %d\n", 213 lbs_pr_debug(1, "RX Data: skb->len - sizeof(RxPd) = %d - %zd = %zd\n",
214 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd)); 214 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
215 215
216 lbs_dbg_hex("RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr, 216 lbs_dbg_hex("RX Data: Dest", p_rx_pkt->eth803_hdr.dest_addr,
@@ -364,7 +364,7 @@ static int process_rxed_802_11_packet(wlan_private * priv, struct sk_buff *skb)
364 priv->stats.rx_errors++; 364 priv->stats.rx_errors++;
365 } 365 }
366 366
367 lbs_pr_debug(1, "RX Data: skb->len - sizeof(RxPd) = %d - %d = %d\n", 367 lbs_pr_debug(1, "RX Data: skb->len - sizeof(RxPd) = %d - %zd = %zd\n",
368 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd)); 368 skb->len, sizeof(struct rxpd), skb->len - sizeof(struct rxpd));
369 369
370 /* create the exported radio header */ 370 /* create the exported radio header */
diff --git a/drivers/net/wireless/libertas/scan.c b/drivers/net/wireless/libertas/scan.c
index e18706238951..3c0b1a2a1727 100644
--- a/drivers/net/wireless/libertas/scan.c
+++ b/drivers/net/wireless/libertas/scan.c
@@ -1,6 +1,3 @@
1/* -*- mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
2/* vi: set expandtab shiftwidth=4 tabstop=4 textwidth=78: */
3
4/** 1/**
5 * Functions implementing wlan scan IOCTL and firmware command APIs 2 * Functions implementing wlan scan IOCTL and firmware command APIs
6 * 3 *
@@ -87,118 +84,95 @@
87 * 84 *
88 * @return Index in scantable, or error code if negative 85 * @return Index in scantable, or error code if negative
89 */ 86 */
90static int is_network_compatible(wlan_adapter * adapter, int index, int mode) 87static int is_network_compatible(wlan_adapter * adapter, int index, u8 mode)
91{ 88{
92 ENTER(); 89 ENTER();
93 90
94 if (adapter->scantable[index].inframode == mode) { 91 if (adapter->scantable[index].mode == mode) {
95 if (adapter->secinfo.WEPstatus == wlan802_11WEPdisabled 92 if ( !adapter->secinfo.wep_enabled
96 && !adapter->secinfo.WPAenabled 93 && !adapter->secinfo.WPAenabled
97 && !adapter->secinfo.WPA2enabled 94 && !adapter->secinfo.WPA2enabled
98 && adapter->scantable[index].wpa_supplicant.wpa_ie[0] != 95 && adapter->scantable[index].wpa_ie[0] != WPA_IE
99 WPA_IE 96 && adapter->scantable[index].rsn_ie[0] != WPA2_IE
100 && adapter->scantable[index].wpa2_supplicant.wpa_ie[0] !=
101 WPA2_IE && adapter->secinfo.Encryptionmode == CIPHER_NONE
102 && !adapter->scantable[index].privacy) { 97 && !adapter->scantable[index].privacy) {
103 /* no security */ 98 /* no security */
104 LEAVE(); 99 LEAVE();
105 return index; 100 return index;
106 } else if (adapter->secinfo.WEPstatus == wlan802_11WEPenabled 101 } else if ( adapter->secinfo.wep_enabled
107 && !adapter->secinfo.WPAenabled 102 && !adapter->secinfo.WPAenabled
108 && !adapter->secinfo.WPA2enabled 103 && !adapter->secinfo.WPA2enabled
109 && adapter->scantable[index].privacy) { 104 && adapter->scantable[index].privacy) {
110 /* static WEP enabled */ 105 /* static WEP enabled */
111 LEAVE(); 106 LEAVE();
112 return index; 107 return index;
113 } else if (adapter->secinfo.WEPstatus == wlan802_11WEPdisabled 108 } else if ( !adapter->secinfo.wep_enabled
114 && adapter->secinfo.WPAenabled 109 && adapter->secinfo.WPAenabled
115 && !adapter->secinfo.WPA2enabled 110 && !adapter->secinfo.WPA2enabled
116 && (adapter->scantable[index].wpa_supplicant. 111 && (adapter->scantable[index].wpa_ie[0] == WPA_IE)
117 wpa_ie[0]
118 == WPA_IE)
119 /* privacy bit may NOT be set in some APs like LinkSys WRT54G 112 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
120 && adapter->scantable[index].privacy */ 113 && adapter->scantable[index].privacy */
121 ) { 114 ) {
122 /* WPA enabled */ 115 /* WPA enabled */
123 lbs_pr_debug(1, 116 lbs_pr_debug(1,
124 "is_network_compatible() WPA: index=%d wpa_ie=%#x " 117 "is_network_compatible() WPA: index=%d wpa_ie=%#x "
125 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s Encmode=%#x " 118 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
126 "privacy=%#x\n", index, 119 "privacy=%#x\n", index,
127 adapter->scantable[index].wpa_supplicant. 120 adapter->scantable[index].wpa_ie[0],
128 wpa_ie[0], 121 adapter->scantable[index].rsn_ie[0],
129 adapter->scantable[index].wpa2_supplicant. 122 adapter->secinfo.wep_enabled ? "e" : "d",
130 wpa_ie[0], 123 adapter->secinfo.WPAenabled ? "e" : "d",
131 (adapter->secinfo.WEPstatus == 124 adapter->secinfo.WPA2enabled ? "e" : "d",
132 wlan802_11WEPenabled) ? "e" : "d",
133 (adapter->secinfo.WPAenabled) ? "e" : "d",
134 (adapter->secinfo.WPA2enabled) ? "e" : "d",
135 adapter->secinfo.Encryptionmode,
136 adapter->scantable[index].privacy); 125 adapter->scantable[index].privacy);
137 LEAVE(); 126 LEAVE();
138 return index; 127 return index;
139 } else if (adapter->secinfo.WEPstatus == wlan802_11WEPdisabled 128 } else if ( !adapter->secinfo.wep_enabled
140 && !adapter->secinfo.WPAenabled 129 && !adapter->secinfo.WPAenabled
141 && adapter->secinfo.WPA2enabled 130 && adapter->secinfo.WPA2enabled
142 && (adapter->scantable[index].wpa2_supplicant. 131 && (adapter->scantable[index].rsn_ie[0] == WPA2_IE)
143 wpa_ie[0]
144 == WPA2_IE)
145 /* privacy bit may NOT be set in some APs like LinkSys WRT54G 132 /* privacy bit may NOT be set in some APs like LinkSys WRT54G
146 && adapter->scantable[index].privacy */ 133 && adapter->scantable[index].privacy */
147 ) { 134 ) {
148 /* WPA2 enabled */ 135 /* WPA2 enabled */
149 lbs_pr_debug(1, 136 lbs_pr_debug(1,
150 "is_network_compatible() WPA2: index=%d wpa_ie=%#x " 137 "is_network_compatible() WPA2: index=%d wpa_ie=%#x "
151 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s Encmode=%#x " 138 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s "
152 "privacy=%#x\n", index, 139 "privacy=%#x\n", index,
153 adapter->scantable[index].wpa_supplicant. 140 adapter->scantable[index].wpa_ie[0],
154 wpa_ie[0], 141 adapter->scantable[index].rsn_ie[0],
155 adapter->scantable[index].wpa2_supplicant. 142 adapter->secinfo.wep_enabled ? "e" : "d",
156 wpa_ie[0], 143 adapter->secinfo.WPAenabled ? "e" : "d",
157 (adapter->secinfo.WEPstatus == 144 adapter->secinfo.WPA2enabled ? "e" : "d",
158 wlan802_11WEPenabled) ? "e" : "d",
159 (adapter->secinfo.WPAenabled) ? "e" : "d",
160 (adapter->secinfo.WPA2enabled) ? "e" : "d",
161 adapter->secinfo.Encryptionmode,
162 adapter->scantable[index].privacy); 145 adapter->scantable[index].privacy);
163 LEAVE(); 146 LEAVE();
164 return index; 147 return index;
165 } else if (adapter->secinfo.WEPstatus == wlan802_11WEPdisabled 148 } else if ( !adapter->secinfo.wep_enabled
166 && !adapter->secinfo.WPAenabled 149 && !adapter->secinfo.WPAenabled
167 && !adapter->secinfo.WPA2enabled 150 && !adapter->secinfo.WPA2enabled
168 && (adapter->scantable[index].wpa_supplicant. 151 && (adapter->scantable[index].wpa_ie[0] != WPA_IE)
169 wpa_ie[0] 152 && (adapter->scantable[index].rsn_ie[0] != WPA2_IE)
170 != WPA_IE)
171 && (adapter->scantable[index].wpa2_supplicant.
172 wpa_ie[0]
173 != WPA2_IE)
174 && adapter->secinfo.Encryptionmode != CIPHER_NONE
175 && adapter->scantable[index].privacy) { 153 && adapter->scantable[index].privacy) {
176 /* dynamic WEP enabled */ 154 /* dynamic WEP enabled */
177 lbs_pr_debug(1, 155 lbs_pr_debug(1,
178 "is_network_compatible() dynamic WEP: index=%d " 156 "is_network_compatible() dynamic WEP: index=%d "
179 "wpa_ie=%#x wpa2_ie=%#x Encmode=%#x privacy=%#x\n", 157 "wpa_ie=%#x wpa2_ie=%#x privacy=%#x\n",
180 index, 158 index,
181 adapter->scantable[index].wpa_supplicant. 159 adapter->scantable[index].wpa_ie[0],
182 wpa_ie[0], 160 adapter->scantable[index].rsn_ie[0],
183 adapter->scantable[index].wpa2_supplicant.
184 wpa_ie[0], adapter->secinfo.Encryptionmode,
185 adapter->scantable[index].privacy); 161 adapter->scantable[index].privacy);
186 LEAVE(); 162 LEAVE();
187 return index; 163 return index;
188 } 164 }
189 165
190 /* security doesn't match */ 166 /* security doesn't match */
191 lbs_pr_debug(1, 167 lbs_pr_debug(1,
192 "is_network_compatible() FAILED: index=%d wpa_ie=%#x " 168 "is_network_compatible() FAILED: index=%d wpa_ie=%#x "
193 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s Encmode=%#x privacy=%#x\n", 169 "wpa2_ie=%#x WEP=%s WPA=%s WPA2=%s privacy=%#x\n",
194 index, 170 index,
195 adapter->scantable[index].wpa_supplicant.wpa_ie[0], 171 adapter->scantable[index].wpa_ie[0],
196 adapter->scantable[index].wpa2_supplicant.wpa_ie[0], 172 adapter->scantable[index].rsn_ie[0],
197 (adapter->secinfo.WEPstatus == 173 adapter->secinfo.wep_enabled ? "e" : "d",
198 wlan802_11WEPenabled) ? "e" : "d", 174 adapter->secinfo.WPAenabled ? "e" : "d",
199 (adapter->secinfo.WPAenabled) ? "e" : "d", 175 adapter->secinfo.WPA2enabled ? "e" : "d",
200 (adapter->secinfo.WPA2enabled) ? "e" : "d",
201 adapter->secinfo.Encryptionmode,
202 adapter->scantable[index].privacy); 176 adapter->scantable[index].privacy);
203 LEAVE(); 177 LEAVE();
204 return -ECONNREFUSED; 178 return -ECONNREFUSED;
@@ -924,8 +898,6 @@ static int InterpretBSSDescriptionWithIE(struct bss_descriptor * pBSSEntry,
924 u8 founddatarateie; 898 u8 founddatarateie;
925 int bytesleftforcurrentbeacon; 899 int bytesleftforcurrentbeacon;
926 900
927 struct WPA_SUPPLICANT *pwpa_supplicant;
928 struct WPA_SUPPLICANT *pwpa2_supplicant;
929 struct IE_WPA *pIe; 901 struct IE_WPA *pIe;
930 const u8 oui01[4] = { 0x00, 0x50, 0xf2, 0x01 }; 902 const u8 oui01[4] = { 0x00, 0x50, 0xf2, 0x01 };
931 903
@@ -962,9 +934,6 @@ static int InterpretBSSDescriptionWithIE(struct bss_descriptor * pBSSEntry,
962 934
963 bytesleftforcurrentbeacon = beaconsize; 935 bytesleftforcurrentbeacon = beaconsize;
964 936
965 pwpa_supplicant = &pBSSEntry->wpa_supplicant;
966 pwpa2_supplicant = &pBSSEntry->wpa2_supplicant;
967
968 memcpy(pBSSEntry->macaddress, pcurrentptr, ETH_ALEN); 937 memcpy(pBSSEntry->macaddress, pcurrentptr, ETH_ALEN);
969 lbs_pr_debug(1, "InterpretIE: AP MAC Addr-%x:%x:%x:%x:%x:%x\n", 938 lbs_pr_debug(1, "InterpretIE: AP MAC Addr-%x:%x:%x:%x:%x:%x\n",
970 pBSSEntry->macaddress[0], pBSSEntry->macaddress[1], 939 pBSSEntry->macaddress[0], pBSSEntry->macaddress[1],
@@ -1027,9 +996,9 @@ static int InterpretBSSDescriptionWithIE(struct bss_descriptor * pBSSEntry,
1027 } 996 }
1028 997
1029 if (pcap->ibss == 1) { 998 if (pcap->ibss == 1) {
1030 pBSSEntry->inframode = wlan802_11ibss; 999 pBSSEntry->mode = IW_MODE_ADHOC;
1031 } else { 1000 } else {
1032 pBSSEntry->inframode = wlan802_11infrastructure; 1001 pBSSEntry->mode = IW_MODE_INFRA;
1033 } 1002 }
1034 1003
1035 /* process variable IE */ 1004 /* process variable IE */
@@ -1116,7 +1085,7 @@ static int InterpretBSSDescriptionWithIE(struct bss_descriptor * pBSSEntry,
1116 sizeof(pcountryinfo->countrycode) 1085 sizeof(pcountryinfo->countrycode)
1117 || pcountryinfo->len > 254) { 1086 || pcountryinfo->len > 254) {
1118 lbs_pr_debug(1, "InterpretIE: 11D- Err " 1087 lbs_pr_debug(1, "InterpretIE: 11D- Err "
1119 "CountryInfo len =%d min=%d max=254\n", 1088 "CountryInfo len =%d min=%zd max=254\n",
1120 pcountryinfo->len, 1089 pcountryinfo->len,
1121 sizeof(pcountryinfo->countrycode)); 1090 sizeof(pcountryinfo->countrycode));
1122 LEAVE(); 1091 LEAVE();
@@ -1160,27 +1129,27 @@ static int InterpretBSSDescriptionWithIE(struct bss_descriptor * pBSSEntry,
1160#define IE_ID_LEN_FIELDS_BYTES 2 1129#define IE_ID_LEN_FIELDS_BYTES 2
1161 pIe = (struct IE_WPA *)pcurrentptr; 1130 pIe = (struct IE_WPA *)pcurrentptr;
1162 1131
1163 if (!memcmp(pIe->oui, oui01, sizeof(oui01))) { 1132 if (memcmp(pIe->oui, oui01, sizeof(oui01)))
1164 pwpa_supplicant->wpa_ie_len 1133 break;
1165 = min_t(size_t, elemlen + IE_ID_LEN_FIELDS_BYTES, 1134
1166 sizeof(pwpa_supplicant->wpa_ie)); 1135 pBSSEntry->wpa_ie_len = min_t(size_t,
1167 memcpy(pwpa_supplicant->wpa_ie, 1136 elemlen + IE_ID_LEN_FIELDS_BYTES,
1168 pcurrentptr, 1137 sizeof(pBSSEntry->wpa_ie));
1169 pwpa_supplicant->wpa_ie_len); 1138 memcpy(pBSSEntry->wpa_ie, pcurrentptr,
1170 lbs_dbg_hex("InterpretIE: Resp WPA_IE", 1139 pBSSEntry->wpa_ie_len);
1171 pwpa_supplicant->wpa_ie, elemlen); 1140 lbs_dbg_hex("InterpretIE: Resp WPA_IE",
1172 } 1141 pBSSEntry->wpa_ie, elemlen);
1173 break; 1142 break;
1174 case WPA2_IE: 1143 case WPA2_IE:
1175 pIe = (struct IE_WPA *)pcurrentptr; 1144 pIe = (struct IE_WPA *)pcurrentptr;
1176 pwpa2_supplicant->wpa_ie_len
1177 = min_t(size_t, elemlen + IE_ID_LEN_FIELDS_BYTES,
1178 sizeof(pwpa2_supplicant->wpa_ie));
1179 memcpy(pwpa2_supplicant->wpa_ie,
1180 pcurrentptr, pwpa2_supplicant->wpa_ie_len);
1181 1145
1146 pBSSEntry->rsn_ie_len = min_t(size_t,
1147 elemlen + IE_ID_LEN_FIELDS_BYTES,
1148 sizeof(pBSSEntry->rsn_ie));
1149 memcpy(pBSSEntry->rsn_ie, pcurrentptr,
1150 pBSSEntry->rsn_ie_len);
1182 lbs_dbg_hex("InterpretIE: Resp WPA2_IE", 1151 lbs_dbg_hex("InterpretIE: Resp WPA2_IE",
1183 pwpa2_supplicant->wpa_ie, elemlen); 1152 pBSSEntry->rsn_ie, elemlen);
1184 break; 1153 break;
1185 case TIM: 1154 case TIM:
1186 break; 1155 break;
@@ -1227,7 +1196,7 @@ int libertas_SSID_cmp(struct WLAN_802_11_SSID *ssid1, struct WLAN_802_11_SSID *s
1227 * 1196 *
1228 * @return index in BSSID list, or error return code (< 0) 1197 * @return index in BSSID list, or error return code (< 0)
1229 */ 1198 */
1230int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, int mode) 1199int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, u8 mode)
1231{ 1200{
1232 int ret = -ENETUNREACH; 1201 int ret = -ENETUNREACH;
1233 int i; 1202 int i;
@@ -1247,8 +1216,8 @@ int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, int mode)
1247 for (i = 0; ret < 0 && i < adapter->numinscantable; i++) { 1216 for (i = 0; ret < 0 && i < adapter->numinscantable; i++) {
1248 if (!memcmp(adapter->scantable[i].macaddress, bssid, ETH_ALEN)) { 1217 if (!memcmp(adapter->scantable[i].macaddress, bssid, ETH_ALEN)) {
1249 switch (mode) { 1218 switch (mode) {
1250 case wlan802_11infrastructure: 1219 case IW_MODE_INFRA:
1251 case wlan802_11ibss: 1220 case IW_MODE_ADHOC:
1252 ret = is_network_compatible(adapter, i, mode); 1221 ret = is_network_compatible(adapter, i, mode);
1253 break; 1222 break;
1254 default: 1223 default:
@@ -1272,7 +1241,7 @@ int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, int mode)
1272 * @return index in BSSID list 1241 * @return index in BSSID list
1273 */ 1242 */
1274int libertas_find_SSID_in_list(wlan_adapter * adapter, 1243int libertas_find_SSID_in_list(wlan_adapter * adapter,
1275 struct WLAN_802_11_SSID *ssid, u8 * bssid, int mode) 1244 struct WLAN_802_11_SSID *ssid, u8 * bssid, u8 mode)
1276{ 1245{
1277 int net = -ENETUNREACH; 1246 int net = -ENETUNREACH;
1278 u8 bestrssi = 0; 1247 u8 bestrssi = 0;
@@ -1287,8 +1256,8 @@ int libertas_find_SSID_in_list(wlan_adapter * adapter,
1287 !memcmp(adapter->scantable[i]. 1256 !memcmp(adapter->scantable[i].
1288 macaddress, bssid, ETH_ALEN))) { 1257 macaddress, bssid, ETH_ALEN))) {
1289 switch (mode) { 1258 switch (mode) {
1290 case wlan802_11infrastructure: 1259 case IW_MODE_INFRA:
1291 case wlan802_11ibss: 1260 case IW_MODE_ADHOC:
1292 j = is_network_compatible(adapter, i, mode); 1261 j = is_network_compatible(adapter, i, mode);
1293 1262
1294 if (j >= 0) { 1263 if (j >= 0) {
@@ -1311,7 +1280,7 @@ int libertas_find_SSID_in_list(wlan_adapter * adapter,
1311 } 1280 }
1312 } 1281 }
1313 break; 1282 break;
1314 case wlan802_11autounknown: 1283 case IW_MODE_AUTO:
1315 default: 1284 default:
1316 if (SCAN_RSSI(adapter->scantable[i].rssi) 1285 if (SCAN_RSSI(adapter->scantable[i].rssi)
1317 > bestrssi) { 1286 > bestrssi) {
@@ -1338,8 +1307,7 @@ int libertas_find_SSID_in_list(wlan_adapter * adapter,
1338 * 1307 *
1339 * @return index in BSSID list 1308 * @return index in BSSID list
1340 */ 1309 */
1341int libertas_find_best_SSID_in_list(wlan_adapter * adapter, 1310int libertas_find_best_SSID_in_list(wlan_adapter * adapter, u8 mode)
1342 enum WLAN_802_11_NETWORK_INFRASTRUCTURE mode)
1343{ 1311{
1344 int bestnet = -ENETUNREACH; 1312 int bestnet = -ENETUNREACH;
1345 u8 bestrssi = 0; 1313 u8 bestrssi = 0;
@@ -1351,8 +1319,8 @@ int libertas_find_best_SSID_in_list(wlan_adapter * adapter,
1351 1319
1352 for (i = 0; i < adapter->numinscantable; i++) { 1320 for (i = 0; i < adapter->numinscantable; i++) {
1353 switch (mode) { 1321 switch (mode) {
1354 case wlan802_11infrastructure: 1322 case IW_MODE_INFRA:
1355 case wlan802_11ibss: 1323 case IW_MODE_ADHOC:
1356 if (is_network_compatible(adapter, i, mode) >= 0) { 1324 if (is_network_compatible(adapter, i, mode) >= 0) {
1357 if (SCAN_RSSI(adapter->scantable[i].rssi) > 1325 if (SCAN_RSSI(adapter->scantable[i].rssi) >
1358 bestrssi) { 1326 bestrssi) {
@@ -1363,7 +1331,7 @@ int libertas_find_best_SSID_in_list(wlan_adapter * adapter,
1363 } 1331 }
1364 } 1332 }
1365 break; 1333 break;
1366 case wlan802_11autounknown: 1334 case IW_MODE_AUTO:
1367 default: 1335 default:
1368 if (SCAN_RSSI(adapter->scantable[i].rssi) > bestrssi) { 1336 if (SCAN_RSSI(adapter->scantable[i].rssi) > bestrssi) {
1369 bestrssi = 1337 bestrssi =
@@ -1388,8 +1356,7 @@ int libertas_find_best_SSID_in_list(wlan_adapter * adapter,
1388 */ 1356 */
1389int libertas_find_best_network_SSID(wlan_private * priv, 1357int libertas_find_best_network_SSID(wlan_private * priv,
1390 struct WLAN_802_11_SSID *pSSID, 1358 struct WLAN_802_11_SSID *pSSID,
1391 enum WLAN_802_11_NETWORK_INFRASTRUCTURE preferred_mode, 1359 u8 preferred_mode, u8 *out_mode)
1392 enum WLAN_802_11_NETWORK_INFRASTRUCTURE *out_mode)
1393{ 1360{
1394 wlan_adapter *adapter = priv->adapter; 1361 wlan_adapter *adapter = priv->adapter;
1395 int ret = 0; 1362 int ret = 0;
@@ -1414,7 +1381,7 @@ int libertas_find_best_network_SSID(wlan_private * priv,
1414 preqbssid = &adapter->scantable[i]; 1381 preqbssid = &adapter->scantable[i];
1415 memcpy(pSSID, &preqbssid->ssid, 1382 memcpy(pSSID, &preqbssid->ssid,
1416 sizeof(struct WLAN_802_11_SSID)); 1383 sizeof(struct WLAN_802_11_SSID));
1417 *out_mode = preqbssid->inframode; 1384 *out_mode = preqbssid->mode;
1418 1385
1419 if (!pSSID->ssidlength) { 1386 if (!pSSID->ssidlength) {
1420 ret = -1; 1387 ret = -1;
@@ -1584,7 +1551,7 @@ int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
1584 for (i = 0; i < adapter->numinscantable; i++) { 1551 for (i = 0; i < adapter->numinscantable; i++) {
1585 if ((current_ev + MAX_SCAN_CELL_SIZE) >= end_buf) { 1552 if ((current_ev + MAX_SCAN_CELL_SIZE) >= end_buf) {
1586 lbs_pr_debug(1, "i=%d break out: current_ev=%p end_buf=%p " 1553 lbs_pr_debug(1, "i=%d break out: current_ev=%p end_buf=%p "
1587 "MAX_SCAN_CELL_SIZE=%d\n", 1554 "MAX_SCAN_CELL_SIZE=%zd\n",
1588 i, current_ev, end_buf, MAX_SCAN_CELL_SIZE); 1555 i, current_ev, end_buf, MAX_SCAN_CELL_SIZE);
1589 break; 1556 break;
1590 } 1557 }
@@ -1632,7 +1599,7 @@ int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
1632 1599
1633 //Add mode 1600 //Add mode
1634 iwe.cmd = SIOCGIWMODE; 1601 iwe.cmd = SIOCGIWMODE;
1635 iwe.u.mode = adapter->scantable[i].inframode + 1; 1602 iwe.u.mode = adapter->scantable[i].mode;
1636 iwe.len = IW_EV_UINT_LEN; 1603 iwe.len = IW_EV_UINT_LEN;
1637 current_ev = 1604 current_ev =
1638 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len); 1605 iwe_stream_add_event(current_ev, end_buf, &iwe, iwe.len);
@@ -1666,7 +1633,7 @@ int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
1666 iwe.u.qual.noise = 1633 iwe.u.qual.noise =
1667 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]); 1634 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1668 } 1635 }
1669 if ((adapter->inframode == wlan802_11ibss) && 1636 if ((adapter->mode == IW_MODE_ADHOC) &&
1670 !libertas_SSID_cmp(&adapter->curbssparams.ssid, 1637 !libertas_SSID_cmp(&adapter->curbssparams.ssid,
1671 &adapter->scantable[i].ssid) 1638 &adapter->scantable[i].ssid)
1672 && adapter->adhoccreate) { 1639 && adapter->adhoccreate) {
@@ -1731,7 +1698,7 @@ int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
1731 end_buf, &iwe, iwe.len); 1698 end_buf, &iwe, iwe.len);
1732 1699
1733 } 1700 }
1734 if ((adapter->scantable[i].inframode == wlan802_11ibss) 1701 if ((adapter->scantable[i].mode == IW_MODE_ADHOC)
1735 && !libertas_SSID_cmp(&adapter->curbssparams.ssid, 1702 && !libertas_SSID_cmp(&adapter->curbssparams.ssid,
1736 &adapter->scantable[i].ssid) 1703 &adapter->scantable[i].ssid)
1737 && adapter->adhoccreate) { 1704 && adapter->adhoccreate) {
@@ -1745,30 +1712,24 @@ int libertas_get_scan(struct net_device *dev, struct iw_request_info *info,
1745 /* Add new value to event */ 1712 /* Add new value to event */
1746 current_val = current_ev + IW_EV_LCP_LEN; 1713 current_val = current_ev + IW_EV_LCP_LEN;
1747 1714
1748 if (adapter->scantable[i].wpa2_supplicant.wpa_ie[0] == WPA2_IE) { 1715 if (adapter->scantable[i].rsn_ie[0] == WPA2_IE) {
1749 memset(&iwe, 0, sizeof(iwe)); 1716 memset(&iwe, 0, sizeof(iwe));
1750 memset(buf, 0, sizeof(buf)); 1717 memset(buf, 0, sizeof(buf));
1751 memcpy(buf, adapter->scantable[i]. 1718 memcpy(buf, adapter->scantable[i].rsn_ie,
1752 wpa2_supplicant.wpa_ie, 1719 adapter->scantable[i].rsn_ie_len);
1753 adapter->scantable[i].wpa2_supplicant.
1754 wpa_ie_len);
1755 iwe.cmd = IWEVGENIE; 1720 iwe.cmd = IWEVGENIE;
1756 iwe.u.data.length = adapter->scantable[i]. 1721 iwe.u.data.length = adapter->scantable[i].rsn_ie_len;
1757 wpa2_supplicant.wpa_ie_len;
1758 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length; 1722 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1759 current_ev = iwe_stream_add_point(current_ev, end_buf, 1723 current_ev = iwe_stream_add_point(current_ev, end_buf,
1760 &iwe, buf); 1724 &iwe, buf);
1761 } 1725 }
1762 if (adapter->scantable[i].wpa_supplicant.wpa_ie[0] == WPA_IE) { 1726 if (adapter->scantable[i].wpa_ie[0] == WPA_IE) {
1763 memset(&iwe, 0, sizeof(iwe)); 1727 memset(&iwe, 0, sizeof(iwe));
1764 memset(buf, 0, sizeof(buf)); 1728 memset(buf, 0, sizeof(buf));
1765 memcpy(buf, adapter->scantable[i]. 1729 memcpy(buf, adapter->scantable[i].wpa_ie,
1766 wpa_supplicant.wpa_ie, 1730 adapter->scantable[i].wpa_ie_len);
1767 adapter->scantable[i].wpa_supplicant.
1768 wpa_ie_len);
1769 iwe.cmd = IWEVGENIE; 1731 iwe.cmd = IWEVGENIE;
1770 iwe.u.data.length = adapter->scantable[i]. 1732 iwe.u.data.length = adapter->scantable[i].wpa_ie_len;
1771 wpa_supplicant.wpa_ie_len;
1772 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length; 1733 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1773 current_ev = iwe_stream_add_point(current_ev, end_buf, 1734 current_ev = iwe_stream_add_point(current_ev, end_buf,
1774 &iwe, buf); 1735 &iwe, buf);
diff --git a/drivers/net/wireless/libertas/scan.h b/drivers/net/wireless/libertas/scan.h
index d93aa7fa44fd..405f4f0fe575 100644
--- a/drivers/net/wireless/libertas/scan.h
+++ b/drivers/net/wireless/libertas/scan.h
@@ -1,6 +1,3 @@
1/* -*- mode: C; tab-width: 4; indent-tabs-mode: nil -*- */
2/* vi: set expandtab shiftwidth=4 tabstop=4 textwidth=78: */
3
4/** 1/**
5 * Interface for the wlan network scan routines 2 * Interface for the wlan network scan routines
6 * 3 *
@@ -10,6 +7,7 @@
10#ifndef _WLAN_SCAN_H 7#ifndef _WLAN_SCAN_H
11#define _WLAN_SCAN_H 8#define _WLAN_SCAN_H
12 9
10#include <net/ieee80211.h>
13#include "hostcmd.h" 11#include "hostcmd.h"
14 12
15/** 13/**
@@ -155,7 +153,7 @@ struct bss_descriptor {
155 153
156 u32 atimwindow; 154 u32 atimwindow;
157 155
158 enum WLAN_802_11_NETWORK_INFRASTRUCTURE inframode; 156 u8 mode;
159 u8 libertas_supported_rates[WLAN_SUPPORTED_RATES]; 157 u8 libertas_supported_rates[WLAN_SUPPORTED_RATES];
160 158
161 int extra_ie; 159 int extra_ie;
@@ -170,22 +168,22 @@ struct bss_descriptor {
170 168
171 struct ieeetypes_countryinfofullset countryinfo; 169 struct ieeetypes_countryinfofullset countryinfo;
172 170
173 struct WPA_SUPPLICANT wpa_supplicant; 171 u8 wpa_ie[MAX_WPA_IE_LEN];
174 struct WPA_SUPPLICANT wpa2_supplicant; 172 size_t wpa_ie_len;
175 173 u8 rsn_ie[MAX_WPA_IE_LEN];
174 size_t rsn_ie_len;
176}; 175};
177 176
178extern int libertas_SSID_cmp(struct WLAN_802_11_SSID *ssid1, 177extern int libertas_SSID_cmp(struct WLAN_802_11_SSID *ssid1,
179 struct WLAN_802_11_SSID *ssid2); 178 struct WLAN_802_11_SSID *ssid2);
180extern int libertas_find_SSID_in_list(wlan_adapter * adapter, struct WLAN_802_11_SSID *ssid, 179extern int libertas_find_SSID_in_list(wlan_adapter * adapter, struct WLAN_802_11_SSID *ssid,
181 u8 * bssid, int mode); 180 u8 * bssid, u8 mode);
182int libertas_find_best_SSID_in_list(wlan_adapter * adapter, enum WLAN_802_11_NETWORK_INFRASTRUCTURE mode); 181int libertas_find_best_SSID_in_list(wlan_adapter * adapter, u8 mode);
183extern int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, int mode); 182extern int libertas_find_BSSID_in_list(wlan_adapter * adapter, u8 * bssid, u8 mode);
184 183
185int libertas_find_best_network_SSID(wlan_private * priv, 184int libertas_find_best_network_SSID(wlan_private * priv,
186 struct WLAN_802_11_SSID *pSSID, 185 struct WLAN_802_11_SSID *pSSID,
187 enum WLAN_802_11_NETWORK_INFRASTRUCTURE preferred_mode, 186 u8 preferred_mode, u8 *out_mode);
188 enum WLAN_802_11_NETWORK_INFRASTRUCTURE *out_mode);
189 187
190extern int libertas_send_specific_SSID_scan(wlan_private * priv, 188extern int libertas_send_specific_SSID_scan(wlan_private * priv,
191 struct WLAN_802_11_SSID *prequestedssid, 189 struct WLAN_802_11_SSID *prequestedssid,
diff --git a/drivers/net/wireless/libertas/tx.c b/drivers/net/wireless/libertas/tx.c
index 82d06223043e..d4b13478c9a7 100644
--- a/drivers/net/wireless/libertas/tx.c
+++ b/drivers/net/wireless/libertas/tx.c
@@ -78,7 +78,7 @@ static int SendSinglePacket(wlan_private * priv, struct sk_buff *skb)
78 min_t(unsigned int, skb->len, 100)); 78 min_t(unsigned int, skb->len, 100));
79 79
80 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) { 80 if (!skb->len || (skb->len > MRVDRV_ETH_TX_PACKET_BUFFER_SIZE)) {
81 lbs_pr_debug(1, "Tx error: Bad skb length %d : %d\n", 81 lbs_pr_debug(1, "Tx error: Bad skb length %d : %zd\n",
82 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE); 82 skb->len, MRVDRV_ETH_TX_PACKET_BUFFER_SIZE);
83 ret = -1; 83 ret = -1;
84 goto done; 84 goto done;
diff --git a/drivers/net/wireless/libertas/version.h b/drivers/net/wireless/libertas/version.h
index e86f65ae79b8..8b137891791f 100644
--- a/drivers/net/wireless/libertas/version.h
+++ b/drivers/net/wireless/libertas/version.h
@@ -1,8 +1 @@
1#define DRIVER_RELEASE_VERSION "320.p0"
2const char libertas_driver_version[] = "COMM-USB8388-" DRIVER_RELEASE_VERSION
3#ifdef DEBUG
4 "-dbg"
5#endif
6 "";
7
8
diff --git a/drivers/net/wireless/libertas/wext.c b/drivers/net/wireless/libertas/wext.c
index 4a52336bc0f6..69f52b6e59c8 100644
--- a/drivers/net/wireless/libertas/wext.c
+++ b/drivers/net/wireless/libertas/wext.c
@@ -17,7 +17,6 @@
17#include "defs.h" 17#include "defs.h"
18#include "dev.h" 18#include "dev.h"
19#include "join.h" 19#include "join.h"
20#include "version.h"
21#include "wext.h" 20#include "wext.h"
22#include "assoc.h" 21#include "assoc.h"
23 22
@@ -233,7 +232,7 @@ static int changeadhocchannel(wlan_private * priv, int channel)
233 232
234 // find out the BSSID that matches the current SSID 233 // find out the BSSID that matches the current SSID
235 i = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL, 234 i = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL,
236 wlan802_11ibss); 235 IW_MODE_ADHOC);
237 236
238 if (i >= 0) { 237 if (i >= 0) {
239 lbs_pr_debug(1, "SSID found at %d in List," 238 lbs_pr_debug(1, "SSID found at %d in List,"
@@ -316,13 +315,11 @@ static int get_active_data_rates(wlan_adapter * adapter,
316 ENTER(); 315 ENTER();
317 316
318 if (adapter->connect_status != libertas_connected) { 317 if (adapter->connect_status != libertas_connected) {
319 if (adapter->inframode == wlan802_11infrastructure) { 318 if (adapter->mode == IW_MODE_INFRA) {
320 //Infra. mode
321 lbs_pr_debug(1, "Infra\n"); 319 lbs_pr_debug(1, "Infra\n");
322 k = copyrates(rates, k, libertas_supported_rates, 320 k = copyrates(rates, k, libertas_supported_rates,
323 sizeof(libertas_supported_rates)); 321 sizeof(libertas_supported_rates));
324 } else { 322 } else {
325 //ad-hoc mode
326 lbs_pr_debug(1, "Adhoc G\n"); 323 lbs_pr_debug(1, "Adhoc G\n");
327 k = copyrates(rates, k, libertas_adhoc_rates_g, 324 k = copyrates(rates, k, libertas_adhoc_rates_g,
328 sizeof(libertas_adhoc_rates_g)); 325 sizeof(libertas_adhoc_rates_g));
@@ -586,20 +583,7 @@ static int wlan_get_mode(struct net_device *dev,
586 583
587 ENTER(); 584 ENTER();
588 585
589 switch (adapter->inframode) { 586 *uwrq = adapter->mode;
590 case wlan802_11ibss:
591 *uwrq = IW_MODE_ADHOC;
592 break;
593
594 case wlan802_11infrastructure:
595 *uwrq = IW_MODE_INFRA;
596 break;
597
598 default:
599 case wlan802_11autounknown:
600 *uwrq = IW_MODE_AUTO;
601 break;
602 }
603 587
604 LEAVE(); 588 LEAVE();
605 return 0; 589 return 0;
@@ -1002,149 +986,18 @@ static const struct iw_priv_args wlan_private_args[] = {
1002 /* 986 /*
1003 * { cmd, set_args, get_args, name } 987 * { cmd, set_args, get_args, name }
1004 */ 988 */
1005 {
1006 WLANSCAN_TYPE,
1007 IW_PRIV_TYPE_CHAR | 8,
1008 IW_PRIV_TYPE_CHAR | 8,
1009 "scantype"},
1010
1011 {
1012 WLAN_SETINT_GETINT,
1013 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1014 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1015 ""},
1016 {
1017 WLANNF,
1018 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1019 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1020 "getNF"},
1021 {
1022 WLANRSSI,
1023 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1024 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1025 "getRSSI"},
1026 {
1027 WLANENABLE11D,
1028 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1029 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1030 "enable11d"},
1031 {
1032 WLANADHOCGRATE,
1033 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1034 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1035 "adhocgrate"},
1036
1037 {
1038 WLAN_SUBCMD_SET_PRESCAN,
1039 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1040 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1041 "prescan"},
1042 {
1043 WLAN_SETONEINT_GETONEINT,
1044 IW_PRIV_TYPE_INT | 1,
1045 IW_PRIV_TYPE_INT | 1,
1046 ""},
1047 {
1048 WLAN_BEACON_INTERVAL,
1049 IW_PRIV_TYPE_INT | 1,
1050 IW_PRIV_TYPE_INT | 1,
1051 "bcninterval"},
1052 {
1053 WLAN_LISTENINTRVL,
1054 IW_PRIV_TYPE_INT | 1,
1055 IW_PRIV_TYPE_INT | 1,
1056 "lolisteninter"},
1057 {
1058 WLAN_TXCONTROL,
1059 IW_PRIV_TYPE_INT | 1,
1060 IW_PRIV_TYPE_INT | 1,
1061 "txcontrol"},
1062 {
1063 WLAN_NULLPKTINTERVAL,
1064 IW_PRIV_TYPE_INT | 1,
1065 IW_PRIV_TYPE_INT | 1,
1066 "psnullinterval"},
1067 /* Using iwpriv sub-command feature */ 989 /* Using iwpriv sub-command feature */
1068 { 990 {
1069 WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */ 991 WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */
1070 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 992 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1071 IW_PRIV_TYPE_NONE, 993 IW_PRIV_TYPE_NONE,
1072 ""}, 994 ""},
1073
1074 {
1075 WLAN_SUBCMD_SETRXANTENNA,
1076 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1077 IW_PRIV_TYPE_NONE,
1078 "setrxant"},
1079 {
1080 WLAN_SUBCMD_SETTXANTENNA,
1081 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1082 IW_PRIV_TYPE_NONE,
1083 "settxant"},
1084 {
1085 WLANSETAUTHALG,
1086 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1087 IW_PRIV_TYPE_NONE,
1088 "authalgs",
1089 },
1090 {
1091 WLANSET8021XAUTHALG,
1092 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1093 IW_PRIV_TYPE_NONE,
1094 "8021xauthalgs",
1095 },
1096 {
1097 WLANSETENCRYPTIONMODE,
1098 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1099 IW_PRIV_TYPE_NONE,
1100 "encryptionmode",
1101 },
1102 { 995 {
1103 WLANSETREGION, 996 WLANSETREGION,
1104 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 997 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1105 IW_PRIV_TYPE_NONE, 998 IW_PRIV_TYPE_NONE,
1106 "setregioncode"}, 999 "setregioncode"},
1107 { 1000 {
1108 WLAN_SET_LISTEN_INTERVAL,
1109 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1110 IW_PRIV_TYPE_NONE,
1111 "setlisteninter"},
1112 {
1113 WLAN_SET_MULTIPLE_DTIM,
1114 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1115 IW_PRIV_TYPE_NONE,
1116 "setmultipledtim"},
1117 {
1118 WLAN_SET_ATIM_WINDOW,
1119 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1120 IW_PRIV_TYPE_NONE,
1121 "atimwindow"},
1122 {
1123 WLANSETBCNAVG,
1124 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1125 IW_PRIV_TYPE_NONE,
1126 "setbcnavg"},
1127 {
1128 WLANSETDATAAVG,
1129 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1130 IW_PRIV_TYPE_NONE,
1131 "setdataavg"},
1132 {
1133 WLAN_SET_LINKMODE,
1134 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1135 IW_PRIV_TYPE_NONE,
1136 "linkmode"},
1137 {
1138 WLAN_SET_RADIOMODE,
1139 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1140 IW_PRIV_TYPE_NONE,
1141 "radiomode"},
1142 {
1143 WLAN_SET_DEBUGMODE,
1144 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1145 IW_PRIV_TYPE_NONE,
1146 "debugmode"},
1147 {
1148 WLAN_SUBCMD_MESH_SET_TTL, 1001 WLAN_SUBCMD_MESH_SET_TTL,
1149 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 1002 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1150 IW_PRIV_TYPE_NONE, 1003 IW_PRIV_TYPE_NONE,
@@ -1160,41 +1013,6 @@ static const struct iw_priv_args wlan_private_args[] = {
1160 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 1013 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1161 "getregioncode"}, 1014 "getregioncode"},
1162 { 1015 {
1163 WLAN_GET_LISTEN_INTERVAL,
1164 IW_PRIV_TYPE_NONE,
1165 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1166 "getlisteninter"},
1167 {
1168 WLAN_GET_MULTIPLE_DTIM,
1169 IW_PRIV_TYPE_NONE,
1170 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1171 "getmultipledtim"},
1172 {
1173 WLAN_GET_TX_RATE,
1174 IW_PRIV_TYPE_NONE,
1175 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1176 "gettxrate"},
1177 {
1178 WLANGETBCNAVG,
1179 IW_PRIV_TYPE_NONE,
1180 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1181 "getbcnavg"},
1182 {
1183 WLAN_GET_LINKMODE,
1184 IW_PRIV_TYPE_NONE,
1185 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1186 "get_linkmode"},
1187 {
1188 WLAN_GET_RADIOMODE,
1189 IW_PRIV_TYPE_NONE,
1190 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1191 "get_radiomode"},
1192 {
1193 WLAN_GET_DEBUGMODE,
1194 IW_PRIV_TYPE_NONE,
1195 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1196 "get_debugmode"},
1197 {
1198 WLAN_SUBCMD_FWT_CLEANUP, 1016 WLAN_SUBCMD_FWT_CLEANUP,
1199 IW_PRIV_TYPE_NONE, 1017 IW_PRIV_TYPE_NONE,
1200 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 1018 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
@@ -1210,61 +1028,11 @@ static const struct iw_priv_args wlan_private_args[] = {
1210 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 1028 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1211 "mesh_get_ttl"}, 1029 "mesh_get_ttl"},
1212 { 1030 {
1213 WLAN_SETNONE_GETTWELVE_CHAR,
1214 IW_PRIV_TYPE_NONE,
1215 IW_PRIV_TYPE_CHAR | 12,
1216 ""},
1217 {
1218 WLAN_SUBCMD_GETRXANTENNA,
1219 IW_PRIV_TYPE_NONE,
1220 IW_PRIV_TYPE_CHAR | 12,
1221 "getrxant"},
1222 {
1223 WLAN_SUBCMD_GETTXANTENNA,
1224 IW_PRIV_TYPE_NONE,
1225 IW_PRIV_TYPE_CHAR | 12,
1226 "gettxant"},
1227 {
1228 WLAN_GET_TSF,
1229 IW_PRIV_TYPE_NONE,
1230 IW_PRIV_TYPE_CHAR | 12,
1231 "gettsf"},
1232 {
1233 WLAN_SETNONE_GETNONE, 1031 WLAN_SETNONE_GETNONE,
1234 IW_PRIV_TYPE_NONE, 1032 IW_PRIV_TYPE_NONE,
1235 IW_PRIV_TYPE_NONE, 1033 IW_PRIV_TYPE_NONE,
1236 ""}, 1034 ""},
1237 { 1035 {
1238 WLANDEAUTH,
1239 IW_PRIV_TYPE_NONE,
1240 IW_PRIV_TYPE_NONE,
1241 "deauth"},
1242 {
1243 WLANADHOCSTOP,
1244 IW_PRIV_TYPE_NONE,
1245 IW_PRIV_TYPE_NONE,
1246 "adhocstop"},
1247 {
1248 WLANRADIOON,
1249 IW_PRIV_TYPE_NONE,
1250 IW_PRIV_TYPE_NONE,
1251 "radioon"},
1252 {
1253 WLANRADIOOFF,
1254 IW_PRIV_TYPE_NONE,
1255 IW_PRIV_TYPE_NONE,
1256 "radiooff"},
1257 {
1258 WLANWLANIDLEON,
1259 IW_PRIV_TYPE_NONE,
1260 IW_PRIV_TYPE_NONE,
1261 "wlanidle-on"},
1262 {
1263 WLANWLANIDLEOFF,
1264 IW_PRIV_TYPE_NONE,
1265 IW_PRIV_TYPE_NONE,
1266 "wlanidle-off"},
1267 {
1268 WLAN_SUBCMD_FWT_RESET, 1036 WLAN_SUBCMD_FWT_RESET,
1269 IW_PRIV_TYPE_NONE, 1037 IW_PRIV_TYPE_NONE,
1270 IW_PRIV_TYPE_NONE, 1038 IW_PRIV_TYPE_NONE,
@@ -1327,90 +1095,15 @@ static const struct iw_priv_args wlan_private_args[] = {
1327 IW_PRIV_TYPE_CHAR | 128, 1095 IW_PRIV_TYPE_CHAR | 128,
1328 "fwt_list_route"}, 1096 "fwt_list_route"},
1329 { 1097 {
1330 WLANSCAN_MODE,
1331 IW_PRIV_TYPE_CHAR | 128,
1332 IW_PRIV_TYPE_CHAR | 128,
1333 "scanmode"},
1334 {
1335 WLAN_GET_ADHOC_STATUS,
1336 IW_PRIV_TYPE_CHAR | 128,
1337 IW_PRIV_TYPE_CHAR | 128,
1338 "getadhocstatus"},
1339 {
1340 WLAN_SETNONE_GETWORDCHAR,
1341 IW_PRIV_TYPE_NONE,
1342 IW_PRIV_TYPE_CHAR | 128,
1343 ""},
1344 {
1345 WLANSETWPAIE,
1346 IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 24,
1347 IW_PRIV_TYPE_NONE,
1348 "setwpaie"},
1349 {
1350 WLANGETLOG,
1351 IW_PRIV_TYPE_NONE,
1352 IW_PRIV_TYPE_CHAR | GETLOG_BUFSIZE,
1353 "getlog"},
1354 {
1355 WLAN_SET_GET_SIXTEEN_INT, 1098 WLAN_SET_GET_SIXTEEN_INT,
1356 IW_PRIV_TYPE_INT | 16, 1099 IW_PRIV_TYPE_INT | 16,
1357 IW_PRIV_TYPE_INT | 16, 1100 IW_PRIV_TYPE_INT | 16,
1358 ""}, 1101 ""},
1359 { 1102 {
1360 WLAN_TPCCFG,
1361 IW_PRIV_TYPE_INT | 16,
1362 IW_PRIV_TYPE_INT | 16,
1363 "tpccfg"},
1364 {
1365 WLAN_POWERCFG,
1366 IW_PRIV_TYPE_INT | 16,
1367 IW_PRIV_TYPE_INT | 16,
1368 "powercfg"},
1369 {
1370 WLAN_AUTO_FREQ_SET,
1371 IW_PRIV_TYPE_INT | 16,
1372 IW_PRIV_TYPE_INT | 16,
1373 "setafc"},
1374 {
1375 WLAN_AUTO_FREQ_GET,
1376 IW_PRIV_TYPE_INT | 16,
1377 IW_PRIV_TYPE_INT | 16,
1378 "getafc"},
1379 {
1380 WLAN_SCANPROBES,
1381 IW_PRIV_TYPE_INT | 16,
1382 IW_PRIV_TYPE_INT | 16,
1383 "scanprobes"},
1384 {
1385 WLAN_LED_GPIO_CTRL, 1103 WLAN_LED_GPIO_CTRL,
1386 IW_PRIV_TYPE_INT | 16, 1104 IW_PRIV_TYPE_INT | 16,
1387 IW_PRIV_TYPE_INT | 16, 1105 IW_PRIV_TYPE_INT | 16,
1388 "ledgpio"}, 1106 "ledgpio"},
1389 {
1390 WLAN_ADAPT_RATESET,
1391 IW_PRIV_TYPE_INT | 16,
1392 IW_PRIV_TYPE_INT | 16,
1393 "rateadapt"},
1394 {
1395 WLAN_INACTIVITY_TIMEOUT,
1396 IW_PRIV_TYPE_INT | 16,
1397 IW_PRIV_TYPE_INT | 16,
1398 "inactivityto"},
1399 {
1400 WLANSNR,
1401 IW_PRIV_TYPE_INT | 16,
1402 IW_PRIV_TYPE_INT | 16,
1403 "getSNR"},
1404 {
1405 WLAN_GET_RATE,
1406 IW_PRIV_TYPE_INT | 16,
1407 IW_PRIV_TYPE_INT | 16,
1408 "getrate"},
1409 {
1410 WLAN_GET_RXINFO,
1411 IW_PRIV_TYPE_INT | 16,
1412 IW_PRIV_TYPE_INT | 16,
1413 "getrxinfo"},
1414}; 1107};
1415 1108
1416static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev) 1109static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
@@ -1434,7 +1127,7 @@ static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
1434 1127
1435 ENTER(); 1128 ENTER();
1436 1129
1437 priv->wstats.status = adapter->inframode; 1130 priv->wstats.status = adapter->mode;
1438 1131
1439 /* If we're not associated, all quality values are meaningless */ 1132 /* If we're not associated, all quality values are meaningless */
1440 if (adapter->connect_status != libertas_connected) 1133 if (adapter->connect_status != libertas_connected)
@@ -1568,13 +1261,12 @@ static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
1568 if (!cfp) { 1261 if (!cfp) {
1569 rc = -EINVAL; 1262 rc = -EINVAL;
1570 } else { 1263 } else {
1571 if (adapter->inframode == wlan802_11ibss) { 1264 if (adapter->mode == IW_MODE_ADHOC) {
1572 rc = changeadhocchannel(priv, channel); 1265 rc = changeadhocchannel(priv, channel);
1573 /* If station is WEP enabled, send the 1266 /* If station is WEP enabled, send the
1574 * command to set WEP in firmware 1267 * command to set WEP in firmware
1575 */ 1268 */
1576 if (adapter->secinfo.WEPstatus == 1269 if (adapter->secinfo.wep_enabled) {
1577 wlan802_11WEPenabled) {
1578 lbs_pr_debug(1, "set_freq: WEP enabled\n"); 1270 lbs_pr_debug(1, "set_freq: WEP enabled\n");
1579 ret = libertas_prepare_and_send_command(priv, 1271 ret = libertas_prepare_and_send_command(priv,
1580 cmd_802_11_set_wep, 1272 cmd_802_11_set_wep,
@@ -1716,49 +1408,31 @@ static int wlan_set_mode(struct net_device *dev,
1716 wlan_private *priv = dev->priv; 1408 wlan_private *priv = dev->priv;
1717 wlan_adapter *adapter = priv->adapter; 1409 wlan_adapter *adapter = priv->adapter;
1718 struct assoc_request * assoc_req; 1410 struct assoc_request * assoc_req;
1719 enum WLAN_802_11_NETWORK_INFRASTRUCTURE new_mode;
1720 1411
1721 ENTER(); 1412 ENTER();
1722 1413
1723 switch (*uwrq) { 1414 if ( (*uwrq != IW_MODE_ADHOC)
1724 case IW_MODE_ADHOC: 1415 && (*uwrq != IW_MODE_INFRA)
1725 lbs_pr_debug(1, "Wanted mode is ad-hoc: current datarate=%#x\n", 1416 && (*uwrq != IW_MODE_AUTO)) {
1726 adapter->datarate); 1417 lbs_pr_debug(1, "Invalid mode: 0x%x\n", *uwrq);
1727 new_mode = wlan802_11ibss; 1418 ret = -EINVAL;
1728 adapter->adhocchannel = DEFAULT_AD_HOC_CHANNEL; 1419 goto out;
1729 break;
1730
1731 case IW_MODE_INFRA:
1732 lbs_pr_debug(1, "Wanted mode is Infrastructure\n");
1733 new_mode = wlan802_11infrastructure;
1734 break;
1735
1736 case IW_MODE_AUTO:
1737 lbs_pr_debug(1, "Wanted mode is Auto\n");
1738 new_mode = wlan802_11autounknown;
1739 break;
1740
1741 default:
1742 lbs_pr_debug(1, "Wanted mode is Unknown: 0x%x\n", *uwrq);
1743 return -EINVAL;
1744 } 1420 }
1745 1421
1746 mutex_lock(&adapter->lock); 1422 mutex_lock(&adapter->lock);
1747 assoc_req = wlan_get_association_request(adapter); 1423 assoc_req = wlan_get_association_request(adapter);
1748 if (!assoc_req) { 1424 if (!assoc_req) {
1749 ret = -ENOMEM; 1425 ret = -ENOMEM;
1426 wlan_cancel_association_work(priv);
1750 } else { 1427 } else {
1751 assoc_req->mode = new_mode; 1428 assoc_req->mode = *uwrq;
1752 }
1753
1754 if (ret == 0) {
1755 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags); 1429 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1756 wlan_postpone_association_work(priv); 1430 wlan_postpone_association_work(priv);
1757 } else { 1431 lbs_pr_debug(1, "Switching to mode: 0x%x\n", *uwrq);
1758 wlan_cancel_association_work(priv);
1759 } 1432 }
1760 mutex_unlock(&adapter->lock); 1433 mutex_unlock(&adapter->lock);
1761 1434
1435out:
1762 LEAVE(); 1436 LEAVE();
1763 return ret; 1437 return ret;
1764} 1438}
@@ -1789,13 +1463,13 @@ static int wlan_get_encode(struct net_device *dev,
1789 dwrq->flags = 0; 1463 dwrq->flags = 0;
1790 1464
1791 /* Authentication method */ 1465 /* Authentication method */
1792 switch (adapter->secinfo.authmode) { 1466 switch (adapter->secinfo.auth_mode) {
1793 case wlan802_11authmodeopen: 1467 case IW_AUTH_ALG_OPEN_SYSTEM:
1794 dwrq->flags = IW_ENCODE_OPEN; 1468 dwrq->flags = IW_ENCODE_OPEN;
1795 break; 1469 break;
1796 1470
1797 case wlan802_11authmodeshared: 1471 case IW_AUTH_ALG_SHARED_KEY:
1798 case wlan802_11authmodenetworkEAP: 1472 case IW_AUTH_ALG_LEAP:
1799 dwrq->flags = IW_ENCODE_RESTRICTED; 1473 dwrq->flags = IW_ENCODE_RESTRICTED;
1800 break; 1474 break;
1801 default: 1475 default:
@@ -1803,8 +1477,9 @@ static int wlan_get_encode(struct net_device *dev,
1803 break; 1477 break;
1804 } 1478 }
1805 1479
1806 if ((adapter->secinfo.WEPstatus == wlan802_11WEPenabled) 1480 if ( adapter->secinfo.wep_enabled
1807 || adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) { 1481 || adapter->secinfo.WPAenabled
1482 || adapter->secinfo.WPA2enabled) {
1808 dwrq->flags &= ~IW_ENCODE_DISABLED; 1483 dwrq->flags &= ~IW_ENCODE_DISABLED;
1809 } else { 1484 } else {
1810 dwrq->flags |= IW_ENCODE_DISABLED; 1485 dwrq->flags |= IW_ENCODE_DISABLED;
@@ -1818,8 +1493,7 @@ static int wlan_get_encode(struct net_device *dev,
1818 if (index < 0) 1493 if (index < 0)
1819 index = adapter->wep_tx_keyidx; 1494 index = adapter->wep_tx_keyidx;
1820 1495
1821 if ((adapter->wep_keys[index].len) && 1496 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
1822 (adapter->secinfo.WEPstatus == wlan802_11WEPenabled)) {
1823 memcpy(extra, adapter->wep_keys[index].key, 1497 memcpy(extra, adapter->wep_keys[index].key,
1824 adapter->wep_keys[index].len); 1498 adapter->wep_keys[index].len);
1825 dwrq->length = adapter->wep_keys[index].len; 1499 dwrq->length = adapter->wep_keys[index].len;
@@ -1903,7 +1577,7 @@ static int wlan_set_wep_key(struct assoc_request *assoc_req,
1903 assoc_req->wep_tx_keyidx = index; 1577 assoc_req->wep_tx_keyidx = index;
1904 } 1578 }
1905 1579
1906 assoc_req->secinfo.WEPstatus = wlan802_11WEPenabled; 1580 assoc_req->secinfo.wep_enabled = 1;
1907 1581
1908 LEAVE(); 1582 LEAVE();
1909 return 0; 1583 return 0;
@@ -1932,10 +1606,10 @@ static void disable_wep(struct assoc_request *assoc_req)
1932 int i; 1606 int i;
1933 1607
1934 /* Set Open System auth mode */ 1608 /* Set Open System auth mode */
1935 assoc_req->secinfo.authmode = wlan802_11authmodeopen; 1609 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1936 1610
1937 /* Clear WEP keys and mark WEP as disabled */ 1611 /* Clear WEP keys and mark WEP as disabled */
1938 assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled; 1612 assoc_req->secinfo.wep_enabled = 0;
1939 for (i = 0; i < 4; i++) 1613 for (i = 0; i < 4; i++)
1940 assoc_req->wep_keys[i].len = 0; 1614 assoc_req->wep_keys[i].len = 0;
1941 1615
@@ -1987,8 +1661,7 @@ static int wlan_set_encode(struct net_device *dev,
1987 /* If WEP isn't enabled, or if there is no key data but a valid 1661 /* If WEP isn't enabled, or if there is no key data but a valid
1988 * index, set the TX key. 1662 * index, set the TX key.
1989 */ 1663 */
1990 if ((assoc_req->secinfo.WEPstatus != wlan802_11WEPenabled) 1664 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1991 || (dwrq->length == 0 && !is_default))
1992 set_tx_key = 1; 1665 set_tx_key = 1;
1993 1666
1994 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key); 1667 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
@@ -2001,9 +1674,9 @@ static int wlan_set_encode(struct net_device *dev,
2001 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags); 1674 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
2002 1675
2003 if (dwrq->flags & IW_ENCODE_RESTRICTED) { 1676 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
2004 assoc_req->secinfo.authmode = wlan802_11authmodeshared; 1677 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
2005 } else if (dwrq->flags & IW_ENCODE_OPEN) { 1678 } else if (dwrq->flags & IW_ENCODE_OPEN) {
2006 assoc_req->secinfo.authmode = wlan802_11authmodeopen; 1679 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2007 } 1680 }
2008 1681
2009out: 1682out:
@@ -2056,30 +1729,31 @@ static int wlan_get_encodeext(struct net_device *dev,
2056 1729
2057 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY && 1730 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
2058 ext->alg != IW_ENCODE_ALG_WEP) { 1731 ext->alg != IW_ENCODE_ALG_WEP) {
2059 if (index != 0 || adapter->inframode != wlan802_11infrastructure) 1732 if (index != 0 || adapter->mode != IW_MODE_INFRA)
2060 goto out; 1733 goto out;
2061 } 1734 }
2062 1735
2063 dwrq->flags = index + 1; 1736 dwrq->flags = index + 1;
2064 memset(ext, 0, sizeof(*ext)); 1737 memset(ext, 0, sizeof(*ext));
2065 1738
2066 if ((adapter->secinfo.WEPstatus == wlan802_11WEPdisabled) 1739 if ( !adapter->secinfo.wep_enabled
2067 && !adapter->secinfo.WPAenabled && !adapter->secinfo.WPA2enabled) { 1740 && !adapter->secinfo.WPAenabled
1741 && !adapter->secinfo.WPA2enabled) {
2068 ext->alg = IW_ENCODE_ALG_NONE; 1742 ext->alg = IW_ENCODE_ALG_NONE;
2069 ext->key_len = 0; 1743 ext->key_len = 0;
2070 dwrq->flags |= IW_ENCODE_DISABLED; 1744 dwrq->flags |= IW_ENCODE_DISABLED;
2071 } else { 1745 } else {
2072 u8 *key = NULL; 1746 u8 *key = NULL;
2073 1747
2074 if ((adapter->secinfo.WEPstatus == wlan802_11WEPenabled) 1748 if ( adapter->secinfo.wep_enabled
2075 && !adapter->secinfo.WPAenabled 1749 && !adapter->secinfo.WPAenabled
2076 && !adapter->secinfo.WPA2enabled) { 1750 && !adapter->secinfo.WPA2enabled) {
2077 ext->alg = IW_ENCODE_ALG_WEP; 1751 ext->alg = IW_ENCODE_ALG_WEP;
2078 ext->key_len = adapter->wep_keys[index].len; 1752 ext->key_len = adapter->wep_keys[index].len;
2079 key = &adapter->wep_keys[index].key[0]; 1753 key = &adapter->wep_keys[index].key[0];
2080 } else if ((adapter->secinfo.WEPstatus == wlan802_11WEPdisabled) && 1754 } else if ( !adapter->secinfo.wep_enabled
2081 (adapter->secinfo.WPAenabled || 1755 && (adapter->secinfo.WPAenabled ||
2082 adapter->secinfo.WPA2enabled)) { 1756 adapter->secinfo.WPA2enabled)) {
2083 /* WPA */ 1757 /* WPA */
2084 ext->alg = IW_ENCODE_ALG_TKIP; 1758 ext->alg = IW_ENCODE_ALG_TKIP;
2085 ext->key_len = 0; 1759 ext->key_len = 0;
@@ -2149,7 +1823,7 @@ static int wlan_set_encodeext(struct net_device *dev,
2149 /* If WEP isn't enabled, or if there is no key data but a valid 1823 /* If WEP isn't enabled, or if there is no key data but a valid
2150 * index, or if the set-TX-key flag was passed, set the TX key. 1824 * index, or if the set-TX-key flag was passed, set the TX key.
2151 */ 1825 */
2152 if ((assoc_req->secinfo.WEPstatus != wlan802_11WEPenabled) 1826 if ( !assoc_req->secinfo.wep_enabled
2153 || (dwrq->length == 0 && !is_default) 1827 || (dwrq->length == 0 && !is_default)
2154 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY)) 1828 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
2155 set_tx_key = 1; 1829 set_tx_key = 1;
@@ -2161,11 +1835,9 @@ static int wlan_set_encodeext(struct net_device *dev,
2161 goto out; 1835 goto out;
2162 1836
2163 if (dwrq->flags & IW_ENCODE_RESTRICTED) { 1837 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
2164 assoc_req->secinfo.authmode = 1838 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
2165 wlan802_11authmodeshared;
2166 } else if (dwrq->flags & IW_ENCODE_OPEN) { 1839 } else if (dwrq->flags & IW_ENCODE_OPEN) {
2167 assoc_req->secinfo.authmode = 1840 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2168 wlan802_11authmodeopen;
2169 } 1841 }
2170 1842
2171 /* Mark the various WEP bits as modified */ 1843 /* Mark the various WEP bits as modified */
@@ -2350,15 +2022,13 @@ static int wlan_set_auth(struct net_device *dev,
2350 } 2022 }
2351 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) { 2023 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
2352 assoc_req->secinfo.WPAenabled = 1; 2024 assoc_req->secinfo.WPAenabled = 1;
2353 assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled; 2025 assoc_req->secinfo.wep_enabled = 0;
2354 assoc_req->secinfo.authmode = 2026 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2355 wlan802_11authmodeopen;
2356 } 2027 }
2357 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) { 2028 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
2358 assoc_req->secinfo.WPA2enabled = 1; 2029 assoc_req->secinfo.WPA2enabled = 1;
2359 assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled; 2030 assoc_req->secinfo.wep_enabled = 0;
2360 assoc_req->secinfo.authmode = 2031 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2361 wlan802_11authmodeopen;
2362 } 2032 }
2363 updated = 1; 2033 updated = 1;
2364 break; 2034 break;
@@ -2376,14 +2046,11 @@ static int wlan_set_auth(struct net_device *dev,
2376 2046
2377 case IW_AUTH_80211_AUTH_ALG: 2047 case IW_AUTH_80211_AUTH_ALG:
2378 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) { 2048 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
2379 assoc_req->secinfo.authmode = 2049 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
2380 wlan802_11authmodeshared;
2381 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) { 2050 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
2382 assoc_req->secinfo.authmode = 2051 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2383 wlan802_11authmodeopen;
2384 } else if (dwrq->value & IW_AUTH_ALG_LEAP) { 2052 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
2385 assoc_req->secinfo.authmode = 2053 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
2386 wlan802_11authmodenetworkEAP;
2387 } else { 2054 } else {
2388 ret = -EINVAL; 2055 ret = -EINVAL;
2389 } 2056 }
@@ -2396,9 +2063,8 @@ static int wlan_set_auth(struct net_device *dev,
2396 !assoc_req->secinfo.WPA2enabled) { 2063 !assoc_req->secinfo.WPA2enabled) {
2397 assoc_req->secinfo.WPAenabled = 1; 2064 assoc_req->secinfo.WPAenabled = 1;
2398 assoc_req->secinfo.WPA2enabled = 1; 2065 assoc_req->secinfo.WPA2enabled = 1;
2399 assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled; 2066 assoc_req->secinfo.wep_enabled = 0;
2400 assoc_req->secinfo.authmode = 2067 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2401 wlan802_11authmodeopen;
2402 } 2068 }
2403 } else { 2069 } else {
2404 assoc_req->secinfo.WPAenabled = 0; 2070 assoc_req->secinfo.WPAenabled = 0;
@@ -2455,19 +2121,7 @@ static int wlan_get_auth(struct net_device *dev,
2455 break; 2121 break;
2456 2122
2457 case IW_AUTH_80211_AUTH_ALG: 2123 case IW_AUTH_80211_AUTH_ALG:
2458 switch (adapter->secinfo.authmode) { 2124 dwrq->value = adapter->secinfo.auth_mode;
2459 case wlan802_11authmodeshared:
2460 dwrq->value = IW_AUTH_ALG_SHARED_KEY;
2461 break;
2462 case wlan802_11authmodeopen:
2463 dwrq->value = IW_AUTH_ALG_OPEN_SYSTEM;
2464 break;
2465 case wlan802_11authmodenetworkEAP:
2466 dwrq->value = IW_AUTH_ALG_LEAP;
2467 break;
2468 default:
2469 break;
2470 }
2471 break; 2125 break;
2472 2126
2473 case IW_AUTH_WPA_ENABLED: 2127 case IW_AUTH_WPA_ENABLED:
diff --git a/drivers/net/wireless/libertas/wext.h b/drivers/net/wireless/libertas/wext.h
index 39f367c38d90..15cfaaf0797f 100644
--- a/drivers/net/wireless/libertas/wext.h
+++ b/drivers/net/wireless/libertas/wext.h
@@ -10,88 +10,22 @@
10/** PRIVATE CMD ID */ 10/** PRIVATE CMD ID */
11#define WLANIOCTL SIOCIWFIRSTPRIV 11#define WLANIOCTL SIOCIWFIRSTPRIV
12 12
13#define WLANSETWPAIE (WLANIOCTL + 0)
14
15#define WLAN_SETINT_GETINT (WLANIOCTL + 7)
16#define WLANNF 1
17#define WLANRSSI 2
18#define WLANENABLE11D 5
19#define WLANADHOCGRATE 6
20#define WLAN_SUBCMD_SET_PRESCAN 11
21
22#define WLAN_SETNONE_GETNONE (WLANIOCTL + 8) 13#define WLAN_SETNONE_GETNONE (WLANIOCTL + 8)
23#define WLANDEAUTH 1
24#define WLANRADIOON 2
25#define WLANRADIOOFF 3
26#define WLANREMOVEADHOCAES 4
27#define WLANADHOCSTOP 5
28#define WLANCIPHERTEST 6
29#define WLANCRYPTOTEST 7
30
31#define WLANWLANIDLEON 10
32#define WLANWLANIDLEOFF 11
33#define WLAN_SUBCMD_BT_RESET 13 14#define WLAN_SUBCMD_BT_RESET 13
34#define WLAN_SUBCMD_FWT_RESET 14 15#define WLAN_SUBCMD_FWT_RESET 14
35 16
36#define WLANGETLOG (WLANIOCTL + 9)
37#define GETLOG_BUFSIZE 300
38
39#define WLANSCAN_TYPE (WLANIOCTL + 11)
40
41#define WLAN_SETNONE_GETONEINT (WLANIOCTL + 15) 17#define WLAN_SETNONE_GETONEINT (WLANIOCTL + 15)
42#define WLANGETREGION 1 18#define WLANGETREGION 1
43#define WLAN_GET_LISTEN_INTERVAL 2
44#define WLAN_GET_MULTIPLE_DTIM 3
45#define WLAN_GET_TX_RATE 4
46#define WLANGETBCNAVG 5
47 19
48#define WLAN_GET_LINKMODE 6
49#define WLAN_GET_RADIOMODE 7
50#define WLAN_GET_DEBUGMODE 8
51#define WLAN_SUBCMD_FWT_CLEANUP 15 20#define WLAN_SUBCMD_FWT_CLEANUP 15
52#define WLAN_SUBCMD_FWT_TIME 16 21#define WLAN_SUBCMD_FWT_TIME 16
53#define WLAN_SUBCMD_MESH_GET_TTL 17 22#define WLAN_SUBCMD_MESH_GET_TTL 17
54 23
55#define WLANREGCFRDWR (WLANIOCTL + 18)
56
57#define WLAN_SETNONE_GETTWELVE_CHAR (WLANIOCTL + 19)
58#define WLAN_SUBCMD_GETRXANTENNA 1
59#define WLAN_SUBCMD_GETTXANTENNA 2
60#define WLAN_GET_TSF 3
61
62#define WLAN_SETNONE_GETWORDCHAR (WLANIOCTL + 21)
63#define WLANGETADHOCAES 1
64
65#define WLAN_SETONEINT_GETONEINT (WLANIOCTL + 23)
66#define WLAN_BEACON_INTERVAL 1
67#define WLAN_LISTENINTRVL 4
68
69#define WLAN_TXCONTROL 6
70#define WLAN_NULLPKTINTERVAL 7
71
72#define WLAN_SETONEINT_GETNONE (WLANIOCTL + 24) 24#define WLAN_SETONEINT_GETNONE (WLANIOCTL + 24)
73#define WLAN_SUBCMD_SETRXANTENNA 1
74#define WLAN_SUBCMD_SETTXANTENNA 2
75#define WLANSETAUTHALG 5
76#define WLANSET8021XAUTHALG 6
77#define WLANSETENCRYPTIONMODE 7
78#define WLANSETREGION 8 25#define WLANSETREGION 8
79#define WLAN_SET_LISTEN_INTERVAL 9
80
81#define WLAN_SET_MULTIPLE_DTIM 10
82#define WLAN_SET_ATIM_WINDOW 11
83#define WLANSETBCNAVG 13
84#define WLANSETDATAAVG 14
85#define WLAN_SET_LINKMODE 15
86#define WLAN_SET_RADIOMODE 16
87#define WLAN_SET_DEBUGMODE 17
88#define WLAN_SUBCMD_MESH_SET_TTL 18 26#define WLAN_SUBCMD_MESH_SET_TTL 18
89 27
90#define WLAN_SET128CHAR_GET128CHAR (WLANIOCTL + 25) 28#define WLAN_SET128CHAR_GET128CHAR (WLANIOCTL + 25)
91#define WLANSCAN_MODE 6
92
93#define WLAN_GET_ADHOC_STATUS 9
94
95#define WLAN_SUBCMD_BT_ADD 18 29#define WLAN_SUBCMD_BT_ADD 18
96#define WLAN_SUBCMD_BT_DEL 19 30#define WLAN_SUBCMD_BT_DEL 19
97#define WLAN_SUBCMD_BT_LIST 20 31#define WLAN_SUBCMD_BT_LIST 20
@@ -103,27 +37,8 @@
103#define WLAN_SUBCMD_FWT_LIST_ROUTE 26 37#define WLAN_SUBCMD_FWT_LIST_ROUTE 26
104 38
105#define WLAN_SET_GET_SIXTEEN_INT (WLANIOCTL + 29) 39#define WLAN_SET_GET_SIXTEEN_INT (WLANIOCTL + 29)
106#define WLAN_TPCCFG 1
107#define WLAN_POWERCFG 2
108
109#define WLAN_AUTO_FREQ_SET 3
110#define WLAN_AUTO_FREQ_GET 4
111#define WLAN_LED_GPIO_CTRL 5 40#define WLAN_LED_GPIO_CTRL 5
112#define WLAN_SCANPROBES 6
113#define WLAN_ADAPT_RATESET 8
114#define WLAN_INACTIVITY_TIMEOUT 9
115#define WLANSNR 10
116#define WLAN_GET_RATE 11
117#define WLAN_GET_RXINFO 12
118
119#define WLANCMD52RDWR (WLANIOCTL + 30)
120#define WLANCMD53RDWR (WLANIOCTL + 31)
121#define CMD53BUFLEN 32
122 41
123#define REG_MAC 0x19
124#define REG_BBP 0x1a
125#define REG_RF 0x1b
126#define REG_EEPROM 0x59
127#define WLAN_LINKMODE_802_3 0 42#define WLAN_LINKMODE_802_3 0
128#define WLAN_LINKMODE_802_11 2 43#define WLAN_LINKMODE_802_11 2
129#define WLAN_RADIOMODE_NONE 0 44#define WLAN_RADIOMODE_NONE 0
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index 841b3c136ad9..283be4a70524 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -3054,7 +3054,7 @@ static const iw_handler prism54_handler[] = {
3054 (iw_handler) prism54_set_wap, /* SIOCSIWAP */ 3054 (iw_handler) prism54_set_wap, /* SIOCSIWAP */
3055 (iw_handler) prism54_get_wap, /* SIOCGIWAP */ 3055 (iw_handler) prism54_get_wap, /* SIOCGIWAP */
3056 (iw_handler) NULL, /* -- hole -- */ 3056 (iw_handler) NULL, /* -- hole -- */
3057 (iw_handler) NULL, /* SIOCGIWAPLIST depreciated */ 3057 (iw_handler) NULL, /* SIOCGIWAPLIST deprecated */
3058 (iw_handler) prism54_set_scan, /* SIOCSIWSCAN */ 3058 (iw_handler) prism54_set_scan, /* SIOCSIWSCAN */
3059 (iw_handler) prism54_get_scan, /* SIOCGIWSCAN */ 3059 (iw_handler) prism54_get_scan, /* SIOCGIWSCAN */
3060 (iw_handler) prism54_set_essid, /* SIOCSIWESSID */ 3060 (iw_handler) prism54_set_essid, /* SIOCSIWESSID */
diff --git a/drivers/net/wireless/prism54/islpci_dev.c b/drivers/net/wireless/prism54/islpci_dev.c
index a037b11dac9d..084795355b74 100644
--- a/drivers/net/wireless/prism54/islpci_dev.c
+++ b/drivers/net/wireless/prism54/islpci_dev.c
@@ -115,7 +115,7 @@ isl_upload_firmware(islpci_private *priv)
115 ISL38XX_MEMORY_WINDOW_SIZE : fw_len; 115 ISL38XX_MEMORY_WINDOW_SIZE : fw_len;
116 u32 __iomem *dev_fw_ptr = device_base + ISL38XX_DIRECT_MEM_WIN; 116 u32 __iomem *dev_fw_ptr = device_base + ISL38XX_DIRECT_MEM_WIN;
117 117
118 /* set the cards base address for writting the data */ 118 /* set the card's base address for writing the data */
119 isl38xx_w32_flush(device_base, reg, 119 isl38xx_w32_flush(device_base, reg,
120 ISL38XX_DIR_MEM_BASE_REG); 120 ISL38XX_DIR_MEM_BASE_REG);
121 wmb(); /* be paranoid */ 121 wmb(); /* be paranoid */
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index 67b867f837ca..5740d4d4267c 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -176,7 +176,7 @@ psa_write(struct net_device * dev,
176 volatile u_char __iomem *verify = lp->mem + PSA_ADDR + 176 volatile u_char __iomem *verify = lp->mem + PSA_ADDR +
177 (psaoff(0, psa_comp_number) << 1); 177 (psaoff(0, psa_comp_number) << 1);
178 178
179 /* Authorize writting to PSA */ 179 /* Authorize writing to PSA */
180 hacr_write(base, HACR_PWR_STAT | HACR_ROM_WEN); 180 hacr_write(base, HACR_PWR_STAT | HACR_ROM_WEN);
181 181
182 while(n-- > 0) 182 while(n-- > 0)
@@ -1676,7 +1676,7 @@ wv_set_frequency(u_long base, /* i/o port of the card */
1676 fee_write(base, 0x60, 1676 fee_write(base, 0x60,
1677 dac, 2); 1677 dac, 2);
1678 1678
1679 /* We now should verify here that the EEprom writting was ok */ 1679 /* We now should verify here that the EEprom writing was ok */
1680 1680
1681 /* ReRead the first area */ 1681 /* ReRead the first area */
1682 fee_read(base, 0x00, 1682 fee_read(base, 0x00,
diff --git a/drivers/net/wireless/wavelan_cs.p.h b/drivers/net/wireless/wavelan_cs.p.h
index 4d1c4905c749..4b9de0093a7b 100644
--- a/drivers/net/wireless/wavelan_cs.p.h
+++ b/drivers/net/wireless/wavelan_cs.p.h
@@ -120,7 +120,7 @@
120 * the Wavelan itself (NCR -> AT&T -> Lucent). 120 * the Wavelan itself (NCR -> AT&T -> Lucent).
121 * 121 *
122 * All started with Anders Klemets <klemets@paul.rutgers.edu>, 122 * All started with Anders Klemets <klemets@paul.rutgers.edu>,
123 * writting a Wavelan ISA driver for the MACH microkernel. Girish 123 * writing a Wavelan ISA driver for the MACH microkernel. Girish
124 * Welling <welling@paul.rutgers.edu> had also worked on it. 124 * Welling <welling@paul.rutgers.edu> had also worked on it.
125 * Keith Moore modify this for the Pcmcia hardware. 125 * Keith Moore modify this for the Pcmcia hardware.
126 * 126 *
diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
index e04cffc8adf3..8459549d0cee 100644
--- a/drivers/net/wireless/zd1211rw/zd_usb.c
+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
@@ -40,6 +40,7 @@ static struct usb_device_id usb_ids[] = {
40 { USB_DEVICE(0x126f, 0xa006), .driver_info = DEVICE_ZD1211 }, 40 { USB_DEVICE(0x126f, 0xa006), .driver_info = DEVICE_ZD1211 },
41 { USB_DEVICE(0x6891, 0xa727), .driver_info = DEVICE_ZD1211 }, 41 { USB_DEVICE(0x6891, 0xa727), .driver_info = DEVICE_ZD1211 },
42 { USB_DEVICE(0x0df6, 0x9071), .driver_info = DEVICE_ZD1211 }, 42 { USB_DEVICE(0x0df6, 0x9071), .driver_info = DEVICE_ZD1211 },
43 { USB_DEVICE(0x0df6, 0x9075), .driver_info = DEVICE_ZD1211 },
43 { USB_DEVICE(0x157e, 0x300b), .driver_info = DEVICE_ZD1211 }, 44 { USB_DEVICE(0x157e, 0x300b), .driver_info = DEVICE_ZD1211 },
44 { USB_DEVICE(0x079b, 0x004a), .driver_info = DEVICE_ZD1211 }, 45 { USB_DEVICE(0x079b, 0x004a), .driver_info = DEVICE_ZD1211 },
45 { USB_DEVICE(0x1740, 0x2000), .driver_info = DEVICE_ZD1211 }, 46 { USB_DEVICE(0x1740, 0x2000), .driver_info = DEVICE_ZD1211 },
@@ -67,8 +68,11 @@ static struct usb_device_id usb_ids[] = {
67 { USB_DEVICE(0x0586, 0x3410), .driver_info = DEVICE_ZD1211B }, 68 { USB_DEVICE(0x0586, 0x3410), .driver_info = DEVICE_ZD1211B },
68 { USB_DEVICE(0x0baf, 0x0121), .driver_info = DEVICE_ZD1211B }, 69 { USB_DEVICE(0x0baf, 0x0121), .driver_info = DEVICE_ZD1211B },
69 { USB_DEVICE(0x0586, 0x3412), .driver_info = DEVICE_ZD1211B }, 70 { USB_DEVICE(0x0586, 0x3412), .driver_info = DEVICE_ZD1211B },
71 { USB_DEVICE(0x0586, 0x3413), .driver_info = DEVICE_ZD1211B },
72 { USB_DEVICE(0x0053, 0x5301), .driver_info = DEVICE_ZD1211B },
70 /* "Driverless" devices that need ejecting */ 73 /* "Driverless" devices that need ejecting */
71 { USB_DEVICE(0x0ace, 0x2011), .driver_info = DEVICE_INSTALLER }, 74 { USB_DEVICE(0x0ace, 0x2011), .driver_info = DEVICE_INSTALLER },
75 { USB_DEVICE(0x0ace, 0x20ff), .driver_info = DEVICE_INSTALLER },
72 {} 76 {}
73}; 77};
74 78
diff --git a/drivers/net/yellowfin.c b/drivers/net/yellowfin.c
index 3f4a7cf9efea..f2a90a7fa2d6 100644
--- a/drivers/net/yellowfin.c
+++ b/drivers/net/yellowfin.c
@@ -109,7 +109,6 @@ static int gx_fix;
109/* These identify the driver base version and may not be removed. */ 109/* These identify the driver base version and may not be removed. */
110static char version[] __devinitdata = 110static char version[] __devinitdata =
111KERN_INFO DRV_NAME ".c:v1.05 1/09/2001 Written by Donald Becker <becker@scyld.com>\n" 111KERN_INFO DRV_NAME ".c:v1.05 1/09/2001 Written by Donald Becker <becker@scyld.com>\n"
112KERN_INFO " http://www.scyld.com/network/yellowfin.html\n"
113KERN_INFO " (unofficial 2.4.x port, " DRV_VERSION ", " DRV_RELDATE ")\n"; 112KERN_INFO " (unofficial 2.4.x port, " DRV_VERSION ", " DRV_RELDATE ")\n";
114 113
115MODULE_AUTHOR("Donald Becker <becker@scyld.com>"); 114MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
index 78c2e6e4b42e..edd6de995726 100644
--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -26,6 +26,7 @@
26#include <linux/profile.h> 26#include <linux/profile.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/fs.h> 28#include <linux/fs.h>
29#include <linux/sched.h>
29 30
30#include "oprofile_stats.h" 31#include "oprofile_stats.h"
31#include "event_buffer.h" 32#include "event_buffer.h"
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index 21c4c299b3d6..5b86ee5c1eeb 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -38,7 +38,6 @@
38#include <linux/pci.h> 38#include <linux/pci.h>
39#include <linux/ioport.h> 39#include <linux/ioport.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/smp_lock.h>
42 41
43#include <asm/byteorder.h> 42#include <asm/byteorder.h>
44#include <asm/pdc.h> 43#include <asm/pdc.h>
diff --git a/drivers/parport/Kconfig b/drivers/parport/Kconfig
index 36c6a1bfe558..f46c69e4ed82 100644
--- a/drivers/parport/Kconfig
+++ b/drivers/parport/Kconfig
@@ -6,6 +6,7 @@
6# 6#
7 7
8menu "Parallel port support" 8menu "Parallel port support"
9 depends on HAS_IOMEM
9 10
10config PARPORT 11config PARPORT
11 tristate "Parallel port support" 12 tristate "Parallel port support"
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index 316c06f4423c..8b7d84eca05d 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -201,7 +201,7 @@ static int parport_config(struct pcmcia_device *link)
201 201
202 p = parport_pc_probe_port(link->io.BasePort1, link->io.BasePort2, 202 p = parport_pc_probe_port(link->io.BasePort1, link->io.BasePort2,
203 link->irq.AssignedIRQ, PARPORT_DMA_NONE, 203 link->irq.AssignedIRQ, PARPORT_DMA_NONE,
204 NULL); 204 &link->dev);
205 if (p == NULL) { 205 if (p == NULL) {
206 printk(KERN_NOTICE "parport_cs: parport_pc_probe_port() at " 206 printk(KERN_NOTICE "parport_cs: parport_pc_probe_port() at "
207 "0x%3x, irq %u failed\n", link->io.BasePort1, 207 "0x%3x, irq %u failed\n", link->io.BasePort1,
diff --git a/drivers/parport/parport_mfc3.c b/drivers/parport/parport_mfc3.c
index e5b0a544de40..77726fc49766 100644
--- a/drivers/parport/parport_mfc3.c
+++ b/drivers/parport/parport_mfc3.c
@@ -356,6 +356,7 @@ static int __init parport_mfc3_init(void)
356 if (request_irq(IRQ_AMIGA_PORTS, mfc3_interrupt, IRQF_SHARED, p->name, &pp_mfc3_ops)) 356 if (request_irq(IRQ_AMIGA_PORTS, mfc3_interrupt, IRQF_SHARED, p->name, &pp_mfc3_ops))
357 goto out_irq; 357 goto out_irq;
358 } 358 }
359 p->dev = &z->dev;
359 360
360 this_port[pias++] = p; 361 this_port[pias++] = p;
361 printk(KERN_INFO "%s: Multiface III port using irq\n", p->name); 362 printk(KERN_INFO "%s: Multiface III port using irq\n", p->name);
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c
index 3de2623afa13..7bfbad57879d 100644
--- a/drivers/parport/parport_pc.c
+++ b/drivers/parport/parport_pc.c
@@ -51,8 +51,10 @@
51#include <linux/ioport.h> 51#include <linux/ioport.h>
52#include <linux/kernel.h> 52#include <linux/kernel.h>
53#include <linux/slab.h> 53#include <linux/slab.h>
54#include <linux/dma-mapping.h>
54#include <linux/pci.h> 55#include <linux/pci.h>
55#include <linux/pnp.h> 56#include <linux/pnp.h>
57#include <linux/platform_device.h>
56#include <linux/sysctl.h> 58#include <linux/sysctl.h>
57 59
58#include <asm/io.h> 60#include <asm/io.h>
@@ -620,6 +622,7 @@ static size_t parport_pc_fifo_write_block_dma (struct parport *port,
620 unsigned long dmaflag; 622 unsigned long dmaflag;
621 size_t left = length; 623 size_t left = length;
622 const struct parport_pc_private *priv = port->physport->private_data; 624 const struct parport_pc_private *priv = port->physport->private_data;
625 struct device *dev = port->physport->dev;
623 dma_addr_t dma_addr, dma_handle; 626 dma_addr_t dma_addr, dma_handle;
624 size_t maxlen = 0x10000; /* max 64k per DMA transfer */ 627 size_t maxlen = 0x10000; /* max 64k per DMA transfer */
625 unsigned long start = (unsigned long) buf; 628 unsigned long start = (unsigned long) buf;
@@ -631,8 +634,8 @@ dump_parport_state ("enter fifo_write_block_dma", port);
631 if ((start ^ end) & ~0xffffUL) 634 if ((start ^ end) & ~0xffffUL)
632 maxlen = 0x10000 - (start & 0xffff); 635 maxlen = 0x10000 - (start & 0xffff);
633 636
634 dma_addr = dma_handle = pci_map_single(priv->dev, (void *)buf, length, 637 dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length,
635 PCI_DMA_TODEVICE); 638 DMA_TO_DEVICE);
636 } else { 639 } else {
637 /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */ 640 /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */
638 maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */ 641 maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */
@@ -728,9 +731,9 @@ dump_parport_state ("enter fifo_write_block_dma", port);
728 731
729 /* Turn off DMA mode */ 732 /* Turn off DMA mode */
730 frob_econtrol (port, 1<<3, 0); 733 frob_econtrol (port, 1<<3, 0);
731 734
732 if (dma_handle) 735 if (dma_handle)
733 pci_unmap_single(priv->dev, dma_handle, length, PCI_DMA_TODEVICE); 736 dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
734 737
735dump_parport_state ("leave fifo_write_block_dma", port); 738dump_parport_state ("leave fifo_write_block_dma", port);
736 return length - left; 739 return length - left;
@@ -2146,7 +2149,7 @@ static DEFINE_SPINLOCK(ports_lock);
2146struct parport *parport_pc_probe_port (unsigned long int base, 2149struct parport *parport_pc_probe_port (unsigned long int base,
2147 unsigned long int base_hi, 2150 unsigned long int base_hi,
2148 int irq, int dma, 2151 int irq, int dma,
2149 struct pci_dev *dev) 2152 struct device *dev)
2150{ 2153{
2151 struct parport_pc_private *priv; 2154 struct parport_pc_private *priv;
2152 struct parport_operations *ops; 2155 struct parport_operations *ops;
@@ -2155,6 +2158,17 @@ struct parport *parport_pc_probe_port (unsigned long int base,
2155 struct resource *base_res; 2158 struct resource *base_res;
2156 struct resource *ECR_res = NULL; 2159 struct resource *ECR_res = NULL;
2157 struct resource *EPP_res = NULL; 2160 struct resource *EPP_res = NULL;
2161 struct platform_device *pdev = NULL;
2162
2163 if (!dev) {
2164 /* We need a physical device to attach to, but none was
2165 * provided. Create our own. */
2166 pdev = platform_device_register_simple("parport_pc",
2167 base, NULL, 0);
2168 if (IS_ERR(pdev))
2169 return NULL;
2170 dev = &pdev->dev;
2171 }
2158 2172
2159 ops = kmalloc(sizeof (struct parport_operations), GFP_KERNEL); 2173 ops = kmalloc(sizeof (struct parport_operations), GFP_KERNEL);
2160 if (!ops) 2174 if (!ops)
@@ -2180,9 +2194,10 @@ struct parport *parport_pc_probe_port (unsigned long int base,
2180 priv->fifo_depth = 0; 2194 priv->fifo_depth = 0;
2181 priv->dma_buf = NULL; 2195 priv->dma_buf = NULL;
2182 priv->dma_handle = 0; 2196 priv->dma_handle = 0;
2183 priv->dev = dev;
2184 INIT_LIST_HEAD(&priv->list); 2197 INIT_LIST_HEAD(&priv->list);
2185 priv->port = p; 2198 priv->port = p;
2199
2200 p->dev = dev;
2186 p->base_hi = base_hi; 2201 p->base_hi = base_hi;
2187 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT; 2202 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
2188 p->private_data = priv; 2203 p->private_data = priv;
@@ -2305,9 +2320,10 @@ struct parport *parport_pc_probe_port (unsigned long int base,
2305 p->dma = PARPORT_DMA_NONE; 2320 p->dma = PARPORT_DMA_NONE;
2306 } else { 2321 } else {
2307 priv->dma_buf = 2322 priv->dma_buf =
2308 pci_alloc_consistent(priv->dev, 2323 dma_alloc_coherent(dev,
2309 PAGE_SIZE, 2324 PAGE_SIZE,
2310 &priv->dma_handle); 2325 &priv->dma_handle,
2326 GFP_KERNEL);
2311 if (! priv->dma_buf) { 2327 if (! priv->dma_buf) {
2312 printk (KERN_WARNING "%s: " 2328 printk (KERN_WARNING "%s: "
2313 "cannot get buffer for DMA, " 2329 "cannot get buffer for DMA, "
@@ -2356,6 +2372,8 @@ out3:
2356out2: 2372out2:
2357 kfree (ops); 2373 kfree (ops);
2358out1: 2374out1:
2375 if (pdev)
2376 platform_device_unregister(pdev);
2359 return NULL; 2377 return NULL;
2360} 2378}
2361 2379
@@ -2383,7 +2401,7 @@ void parport_pc_unregister_port (struct parport *p)
2383 release_region(p->base_hi, 3); 2401 release_region(p->base_hi, 3);
2384#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA) 2402#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
2385 if (priv->dma_buf) 2403 if (priv->dma_buf)
2386 pci_free_consistent(priv->dev, PAGE_SIZE, 2404 dma_free_coherent(p->physport->dev, PAGE_SIZE,
2387 priv->dma_buf, 2405 priv->dma_buf,
2388 priv->dma_handle); 2406 priv->dma_handle);
2389#endif 2407#endif
@@ -2489,7 +2507,7 @@ static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
2489 */ 2507 */
2490 release_resource(base_res); 2508 release_resource(base_res);
2491 if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi, 2509 if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi,
2492 irq, PARPORT_DMA_NONE, NULL)) { 2510 irq, PARPORT_DMA_NONE, &pdev->dev)) {
2493 printk (KERN_INFO 2511 printk (KERN_INFO
2494 "parport_pc: ITE 8872 parallel port: io=0x%X", 2512 "parport_pc: ITE 8872 parallel port: io=0x%X",
2495 ite8872_lpt); 2513 ite8872_lpt);
@@ -2672,7 +2690,7 @@ static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
2672 } 2690 }
2673 2691
2674 /* finally, do the probe with values obtained */ 2692 /* finally, do the probe with values obtained */
2675 if (parport_pc_probe_port (port1, port2, irq, dma, NULL)) { 2693 if (parport_pc_probe_port (port1, port2, irq, dma, &pdev->dev)) {
2676 printk (KERN_INFO 2694 printk (KERN_INFO
2677 "parport_pc: VIA parallel port: io=0x%X", port1); 2695 "parport_pc: VIA parallel port: io=0x%X", port1);
2678 if (irq != PARPORT_IRQ_NONE) 2696 if (irq != PARPORT_IRQ_NONE)
@@ -2970,7 +2988,7 @@ static int parport_pc_pci_probe (struct pci_dev *dev,
2970 parport_pc_pci_tbl[i + last_sio].device, io_lo, io_hi); 2988 parport_pc_pci_tbl[i + last_sio].device, io_lo, io_hi);
2971 data->ports[count] = 2989 data->ports[count] =
2972 parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE, 2990 parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
2973 PARPORT_DMA_NONE, dev); 2991 PARPORT_DMA_NONE, &dev->dev);
2974 if (data->ports[count]) 2992 if (data->ports[count])
2975 count++; 2993 count++;
2976 } 2994 }
@@ -3077,8 +3095,8 @@ static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id
3077 } else 3095 } else
3078 dma = PARPORT_DMA_NONE; 3096 dma = PARPORT_DMA_NONE;
3079 3097
3080 printk(KERN_INFO "parport: PnPBIOS parport detected.\n"); 3098 dev_info(&dev->dev, "reported by %s\n", dev->protocol->name);
3081 if (!(pdata = parport_pc_probe_port (io_lo, io_hi, irq, dma, NULL))) 3099 if (!(pdata = parport_pc_probe_port (io_lo, io_hi, irq, dma, &dev->dev)))
3082 return -ENODEV; 3100 return -ENODEV;
3083 3101
3084 pnp_set_drvdata(dev,pdata); 3102 pnp_set_drvdata(dev,pdata);
@@ -3103,6 +3121,21 @@ static struct pnp_driver parport_pc_pnp_driver = {
3103}; 3121};
3104 3122
3105 3123
3124static int __devinit parport_pc_platform_probe(struct platform_device *pdev)
3125{
3126 /* Always succeed, the actual probing is done in
3127 * parport_pc_probe_port(). */
3128 return 0;
3129}
3130
3131static struct platform_driver parport_pc_platform_driver = {
3132 .driver = {
3133 .owner = THIS_MODULE,
3134 .name = "parport_pc",
3135 },
3136 .probe = parport_pc_platform_probe,
3137};
3138
3106/* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */ 3139/* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
3107static int __devinit __attribute__((unused)) 3140static int __devinit __attribute__((unused))
3108parport_pc_find_isa_ports (int autoirq, int autodma) 3141parport_pc_find_isa_ports (int autoirq, int autodma)
@@ -3378,9 +3411,15 @@ __setup("parport_init_mode=",parport_init_mode_setup);
3378 3411
3379static int __init parport_pc_init(void) 3412static int __init parport_pc_init(void)
3380{ 3413{
3414 int err;
3415
3381 if (parse_parport_params()) 3416 if (parse_parport_params())
3382 return -EINVAL; 3417 return -EINVAL;
3383 3418
3419 err = platform_driver_register(&parport_pc_platform_driver);
3420 if (err)
3421 return err;
3422
3384 if (io[0]) { 3423 if (io[0]) {
3385 int i; 3424 int i;
3386 /* Only probe the ports we were given. */ 3425 /* Only probe the ports we were given. */
@@ -3405,6 +3444,7 @@ static void __exit parport_pc_exit(void)
3405 pci_unregister_driver (&parport_pc_pci_driver); 3444 pci_unregister_driver (&parport_pc_pci_driver);
3406 if (pnp_registered_parport) 3445 if (pnp_registered_parport)
3407 pnp_unregister_driver (&parport_pc_pnp_driver); 3446 pnp_unregister_driver (&parport_pc_pnp_driver);
3447 platform_driver_unregister(&parport_pc_platform_driver);
3408 3448
3409 spin_lock(&ports_lock); 3449 spin_lock(&ports_lock);
3410 while (!list_empty(&ports_list)) { 3450 while (!list_empty(&ports_list)) {
@@ -3413,6 +3453,9 @@ static void __exit parport_pc_exit(void)
3413 priv = list_entry(ports_list.next, 3453 priv = list_entry(ports_list.next,
3414 struct parport_pc_private, list); 3454 struct parport_pc_private, list);
3415 port = priv->port; 3455 port = priv->port;
3456 if (port->dev && port->dev->bus == &platform_bus_type)
3457 platform_device_unregister(
3458 to_platform_device(port->dev));
3416 spin_unlock(&ports_lock); 3459 spin_unlock(&ports_lock);
3417 parport_pc_unregister_port(port); 3460 parport_pc_unregister_port(port);
3418 spin_lock(&ports_lock); 3461 spin_lock(&ports_lock);
diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c
index 78c0a269a2ba..90ea3b8b99b0 100644
--- a/drivers/parport/parport_serial.c
+++ b/drivers/parport/parport_serial.c
@@ -305,7 +305,7 @@ static int __devinit parport_register (struct pci_dev *dev,
305 dev_dbg(&dev->dev, "PCI parallel port detected: I/O at " 305 dev_dbg(&dev->dev, "PCI parallel port detected: I/O at "
306 "%#lx(%#lx)\n", io_lo, io_hi); 306 "%#lx(%#lx)\n", io_lo, io_hi);
307 port = parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE, 307 port = parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
308 PARPORT_DMA_NONE, dev); 308 PARPORT_DMA_NONE, &dev->dev);
309 if (port) { 309 if (port) {
310 priv->port[priv->num_par++] = port; 310 priv->port[priv->num_par++] = port;
311 success = 1; 311 success = 1;
@@ -392,6 +392,7 @@ static int parport_serial_pci_suspend(struct pci_dev *dev, pm_message_t state)
392static int parport_serial_pci_resume(struct pci_dev *dev) 392static int parport_serial_pci_resume(struct pci_dev *dev)
393{ 393{
394 struct parport_serial_private *priv = pci_get_drvdata(dev); 394 struct parport_serial_private *priv = pci_get_drvdata(dev);
395 int err;
395 396
396 pci_set_power_state(dev, PCI_D0); 397 pci_set_power_state(dev, PCI_D0);
397 pci_restore_state(dev); 398 pci_restore_state(dev);
@@ -399,7 +400,12 @@ static int parport_serial_pci_resume(struct pci_dev *dev)
399 /* 400 /*
400 * The device may have been disabled. Re-enable it. 401 * The device may have been disabled. Re-enable it.
401 */ 402 */
402 pci_enable_device(dev); 403 err = pci_enable_device(dev);
404 if (err) {
405 printk(KERN_ERR "parport_serial: %s: error enabling "
406 "device for resume (%d)\n", pci_name(dev), err);
407 return err;
408 }
403 409
404 if (priv->serial) 410 if (priv->serial)
405 pciserial_resume_ports(priv->serial); 411 pciserial_resume_ports(priv->serial);
diff --git a/drivers/parport/parport_sunbpp.c b/drivers/parport/parport_sunbpp.c
index 400bb90084cf..d27019c2f860 100644
--- a/drivers/parport/parport_sunbpp.c
+++ b/drivers/parport/parport_sunbpp.c
@@ -322,6 +322,7 @@ static int __devinit init_one_port(struct sbus_dev *sdev)
322 goto out_free_ops; 322 goto out_free_ops;
323 323
324 p->size = size; 324 p->size = size;
325 p->dev = &sdev->ofdev.dev;
325 326
326 if ((err = request_irq(p->irq, parport_sunbpp_interrupt, 327 if ((err = request_irq(p->irq, parport_sunbpp_interrupt,
327 IRQF_SHARED, p->name, p)) != 0) { 328 IRQF_SHARED, p->name, p)) != 0) {
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index fd9129e424f9..cd66442acfee 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -365,6 +365,11 @@ void parport_announce_port (struct parport *port)
365 parport_daisy_init(port); 365 parport_daisy_init(port);
366#endif 366#endif
367 367
368 if (!port->dev)
369 printk(KERN_WARNING "%s: fix this legacy "
370 "no-device port driver!\n",
371 port->name);
372
368 parport_proc_register(port); 373 parport_proc_register(port);
369 mutex_lock(&registration_lock); 374 mutex_lock(&registration_lock);
370 spin_lock_irq(&parportlist_lock); 375 spin_lock_irq(&parportlist_lock);
diff --git a/drivers/pci/hotplug/acpiphp_core.c b/drivers/pci/hotplug/acpiphp_core.c
index 40c79b03c7ef..fa5c0197d571 100644
--- a/drivers/pci/hotplug/acpiphp_core.c
+++ b/drivers/pci/hotplug/acpiphp_core.c
@@ -40,7 +40,6 @@
40#include <linux/pci_hotplug.h> 40#include <linux/pci_hotplug.h>
41#include <linux/slab.h> 41#include <linux/slab.h>
42#include <linux/smp.h> 42#include <linux/smp.h>
43#include <linux/smp_lock.h>
44#include "acpiphp.h" 43#include "acpiphp.h"
45 44
46#define MY_NAME "acpiphp" 45#define MY_NAME "acpiphp"
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index fca978fb158e..9ef4e989afc4 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -46,7 +46,6 @@
46#include <linux/kernel.h> 46#include <linux/kernel.h>
47#include <linux/pci.h> 47#include <linux/pci.h>
48#include <linux/pci_hotplug.h> 48#include <linux/pci_hotplug.h>
49#include <linux/smp_lock.h>
50#include <linux/mutex.h> 49#include <linux/mutex.h>
51 50
52#include "../pci.h" 51#include "../pci.h"
diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
index 59392946c2bd..0316eeaaeb29 100644
--- a/drivers/pci/hotplug/ibmphp_core.c
+++ b/drivers/pci/hotplug/ibmphp_core.c
@@ -34,7 +34,6 @@
34#include <linux/interrupt.h> 34#include <linux/interrupt.h>
35#include <linux/delay.h> 35#include <linux/delay.h>
36#include <linux/wait.h> 36#include <linux/wait.h>
37#include <linux/smp_lock.h>
38#include "../pci.h" 37#include "../pci.h"
39#include "../../../arch/i386/pci/pci.h" /* for struct irq_routing_table */ 38#include "../../../arch/i386/pci/pci.h" /* for struct irq_routing_table */
40#include "ibmphp.h" 39#include "ibmphp.h"
diff --git a/drivers/pci/hotplug/ibmphp_hpc.c b/drivers/pci/hotplug/ibmphp_hpc.c
index f55ac3885cb3..d06ccb69e411 100644
--- a/drivers/pci/hotplug/ibmphp_hpc.c
+++ b/drivers/pci/hotplug/ibmphp_hpc.c
@@ -32,9 +32,9 @@
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/pci.h> 34#include <linux/pci.h>
35#include <linux/smp_lock.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/sched.h>
38 38
39#include "ibmphp.h" 39#include "ibmphp.h"
40 40
diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 63f3bd1eecc4..bd433ef6bfc6 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -34,7 +34,6 @@
34#include <linux/sysfs.h> 34#include <linux/sysfs.h>
35#include <linux/pagemap.h> 35#include <linux/pagemap.h>
36#include <linux/slab.h> 36#include <linux/slab.h>
37#include <linux/smp_lock.h>
38#include <linux/init.h> 37#include <linux/init.h>
39#include <linux/mount.h> 38#include <linux/mount.h>
40#include <linux/namei.h> 39#include <linux/namei.h>
diff --git a/drivers/pci/hotplug/rpadlpar_sysfs.c b/drivers/pci/hotplug/rpadlpar_sysfs.c
index 6c5be3ff578c..df076064a3e0 100644
--- a/drivers/pci/hotplug/rpadlpar_sysfs.c
+++ b/drivers/pci/hotplug/rpadlpar_sysfs.c
@@ -129,8 +129,9 @@ struct kobj_type ktype_dlpar_io = {
129}; 129};
130 130
131struct kset dlpar_io_kset = { 131struct kset dlpar_io_kset = {
132 .subsys = &pci_hotplug_slots_subsys, 132 .kobj = {.name = DLPAR_KOBJ_NAME,
133 .kobj = {.name = DLPAR_KOBJ_NAME, .ktype=&ktype_dlpar_io,}, 133 .ktype = &ktype_dlpar_io,
134 .parent = &pci_hotplug_slots_subsys.kobj},
134 .ktype = &ktype_dlpar_io, 135 .ktype = &ktype_dlpar_io,
135}; 136};
136 137
diff --git a/drivers/pci/hotplug/rpaphp_core.c b/drivers/pci/hotplug/rpaphp_core.c
index 847936fe327e..458c08ef2654 100644
--- a/drivers/pci/hotplug/rpaphp_core.c
+++ b/drivers/pci/hotplug/rpaphp_core.c
@@ -29,7 +29,6 @@
29#include <linux/pci_hotplug.h> 29#include <linux/pci_hotplug.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/smp.h> 31#include <linux/smp.h>
32#include <linux/smp_lock.h>
33#include <linux/init.h> 32#include <linux/init.h>
34#include <asm/eeh.h> /* for eeh_add_device() */ 33#include <asm/eeh.h> /* for eeh_add_device() */
35#include <asm/rtas.h> /* rtas_call */ 34#include <asm/rtas.h> /* rtas_call */
@@ -170,10 +169,10 @@ static int get_children_props(struct device_node *dn, const int **drc_indexes,
170{ 169{
171 const int *indexes, *names, *types, *domains; 170 const int *indexes, *names, *types, *domains;
172 171
173 indexes = get_property(dn, "ibm,drc-indexes", NULL); 172 indexes = of_get_property(dn, "ibm,drc-indexes", NULL);
174 names = get_property(dn, "ibm,drc-names", NULL); 173 names = of_get_property(dn, "ibm,drc-names", NULL);
175 types = get_property(dn, "ibm,drc-types", NULL); 174 types = of_get_property(dn, "ibm,drc-types", NULL);
176 domains = get_property(dn, "ibm,drc-power-domains", NULL); 175 domains = of_get_property(dn, "ibm,drc-power-domains", NULL);
177 176
178 if (!indexes || !names || !types || !domains) { 177 if (!indexes || !names || !types || !domains) {
179 /* Slot does not have dynamically-removable children */ 178 /* Slot does not have dynamically-removable children */
@@ -206,7 +205,7 @@ int rpaphp_get_drc_props(struct device_node *dn, int *drc_index,
206 char *name_tmp, *type_tmp; 205 char *name_tmp, *type_tmp;
207 int i, rc; 206 int i, rc;
208 207
209 my_index = get_property(dn, "ibm,my-drc-index", NULL); 208 my_index = of_get_property(dn, "ibm,my-drc-index", NULL);
210 if (!my_index) { 209 if (!my_index) {
211 /* Node isn't DLPAR/hotplug capable */ 210 /* Node isn't DLPAR/hotplug capable */
212 return -EINVAL; 211 return -EINVAL;
diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c
index 78cf0711d1fa..ef07c36bccf7 100644
--- a/drivers/pci/hotplug/sgi_hotplug.c
+++ b/drivers/pci/hotplug/sgi_hotplug.c
@@ -249,19 +249,19 @@ static int sn_slot_enable(struct hotplug_slot *bss_hotplug_slot,
249 249
250 250
251 if (rc == PCI_SLOT_ALREADY_UP) { 251 if (rc == PCI_SLOT_ALREADY_UP) {
252 dev_dbg(slot->pci_bus->self, "is already active\n"); 252 dev_dbg(&slot->pci_bus->self->dev, "is already active\n");
253 return 1; /* return 1 to user */ 253 return 1; /* return 1 to user */
254 } 254 }
255 255
256 if (rc == PCI_L1_ERR) { 256 if (rc == PCI_L1_ERR) {
257 dev_dbg(slot->pci_bus->self, 257 dev_dbg(&slot->pci_bus->self->dev,
258 "L1 failure %d with message: %s", 258 "L1 failure %d with message: %s",
259 resp.resp_sub_errno, resp.resp_l1_msg); 259 resp.resp_sub_errno, resp.resp_l1_msg);
260 return -EPERM; 260 return -EPERM;
261 } 261 }
262 262
263 if (rc) { 263 if (rc) {
264 dev_dbg(slot->pci_bus->self, 264 dev_dbg(&slot->pci_bus->self->dev,
265 "insert failed with error %d sub-error %d\n", 265 "insert failed with error %d sub-error %d\n",
266 rc, resp.resp_sub_errno); 266 rc, resp.resp_sub_errno);
267 return -EIO; 267 return -EIO;
@@ -287,25 +287,25 @@ static int sn_slot_disable(struct hotplug_slot *bss_hotplug_slot,
287 287
288 if ((action == PCI_REQ_SLOT_ELIGIBLE) && 288 if ((action == PCI_REQ_SLOT_ELIGIBLE) &&
289 (rc == PCI_SLOT_ALREADY_DOWN)) { 289 (rc == PCI_SLOT_ALREADY_DOWN)) {
290 dev_dbg(slot->pci_bus->self, "Slot %s already inactive\n"); 290 dev_dbg(&slot->pci_bus->self->dev, "Slot %s already inactive\n", slot->physical_path);
291 return 1; /* return 1 to user */ 291 return 1; /* return 1 to user */
292 } 292 }
293 293
294 if ((action == PCI_REQ_SLOT_ELIGIBLE) && (rc == PCI_EMPTY_33MHZ)) { 294 if ((action == PCI_REQ_SLOT_ELIGIBLE) && (rc == PCI_EMPTY_33MHZ)) {
295 dev_dbg(slot->pci_bus->self, 295 dev_dbg(&slot->pci_bus->self->dev,
296 "Cannot remove last 33MHz card\n"); 296 "Cannot remove last 33MHz card\n");
297 return -EPERM; 297 return -EPERM;
298 } 298 }
299 299
300 if ((action == PCI_REQ_SLOT_ELIGIBLE) && (rc == PCI_L1_ERR)) { 300 if ((action == PCI_REQ_SLOT_ELIGIBLE) && (rc == PCI_L1_ERR)) {
301 dev_dbg(slot->pci_bus->self, 301 dev_dbg(&slot->pci_bus->self->dev,
302 "L1 failure %d with message \n%s\n", 302 "L1 failure %d with message \n%s\n",
303 resp.resp_sub_errno, resp.resp_l1_msg); 303 resp.resp_sub_errno, resp.resp_l1_msg);
304 return -EPERM; 304 return -EPERM;
305 } 305 }
306 306
307 if ((action == PCI_REQ_SLOT_ELIGIBLE) && rc) { 307 if ((action == PCI_REQ_SLOT_ELIGIBLE) && rc) {
308 dev_dbg(slot->pci_bus->self, 308 dev_dbg(&slot->pci_bus->self->dev,
309 "remove failed with error %d sub-error %d\n", 309 "remove failed with error %d sub-error %d\n",
310 rc, resp.resp_sub_errno); 310 rc, resp.resp_sub_errno);
311 return -EIO; 311 return -EIO;
@@ -317,12 +317,12 @@ static int sn_slot_disable(struct hotplug_slot *bss_hotplug_slot,
317 if ((action == PCI_REQ_SLOT_DISABLE) && !rc) { 317 if ((action == PCI_REQ_SLOT_DISABLE) && !rc) {
318 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus); 318 pcibus_info = SN_PCIBUS_BUSSOFT_INFO(slot->pci_bus);
319 pcibus_info->pbi_enabled_devices &= ~(1 << device_num); 319 pcibus_info->pbi_enabled_devices &= ~(1 << device_num);
320 dev_dbg(slot->pci_bus->self, "remove successful\n"); 320 dev_dbg(&slot->pci_bus->self->dev, "remove successful\n");
321 return 0; 321 return 0;
322 } 322 }
323 323
324 if ((action == PCI_REQ_SLOT_DISABLE) && rc) { 324 if ((action == PCI_REQ_SLOT_DISABLE) && rc) {
325 dev_dbg(slot->pci_bus->self,"remove failed rc = %d\n", rc); 325 dev_dbg(&slot->pci_bus->self->dev,"remove failed rc = %d\n", rc);
326 } 326 }
327 327
328 return rc; 328 return rc;
@@ -375,7 +375,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
375 num_funcs = pci_scan_slot(slot->pci_bus, 375 num_funcs = pci_scan_slot(slot->pci_bus,
376 PCI_DEVFN(slot->device_num + 1, 0)); 376 PCI_DEVFN(slot->device_num + 1, 0));
377 if (!num_funcs) { 377 if (!num_funcs) {
378 dev_dbg(slot->pci_bus->self, "no device in slot\n"); 378 dev_dbg(&slot->pci_bus->self->dev, "no device in slot\n");
379 mutex_unlock(&sn_hotplug_mutex); 379 mutex_unlock(&sn_hotplug_mutex);
380 return -ENODEV; 380 return -ENODEV;
381 } 381 }
@@ -427,7 +427,7 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
427 phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle; 427 phandle = PCI_CONTROLLER(slot->pci_bus)->acpi_handle;
428 428
429 if (acpi_bus_get_device(phandle, &pdevice)) { 429 if (acpi_bus_get_device(phandle, &pdevice)) {
430 dev_dbg(slot->pci_bus->self, 430 dev_dbg(&slot->pci_bus->self->dev,
431 "no parent device, assuming NULL\n"); 431 "no parent device, assuming NULL\n");
432 pdevice = NULL; 432 pdevice = NULL;
433 } 433 }
@@ -479,10 +479,10 @@ static int enable_slot(struct hotplug_slot *bss_hotplug_slot)
479 mutex_unlock(&sn_hotplug_mutex); 479 mutex_unlock(&sn_hotplug_mutex);
480 480
481 if (rc == 0) 481 if (rc == 0)
482 dev_dbg(slot->pci_bus->self, 482 dev_dbg(&slot->pci_bus->self->dev,
483 "insert operation successful\n"); 483 "insert operation successful\n");
484 else 484 else
485 dev_dbg(slot->pci_bus->self, 485 dev_dbg(&slot->pci_bus->self->dev,
486 "insert operation failed rc = %d\n", rc); 486 "insert operation failed rc = %d\n", rc);
487 487
488 return rc; 488 return rc;
@@ -659,16 +659,16 @@ static int sn_hotplug_slot_register(struct pci_bus *pci_bus)
659 if (rc) 659 if (rc)
660 goto register_err; 660 goto register_err;
661 } 661 }
662 dev_dbg(pci_bus->self, "Registered bus with hotplug\n"); 662 dev_dbg(&pci_bus->self->dev, "Registered bus with hotplug\n");
663 return rc; 663 return rc;
664 664
665register_err: 665register_err:
666 dev_dbg(pci_bus->self, "bus failed to register with err = %d\n", 666 dev_dbg(&pci_bus->self->dev, "bus failed to register with err = %d\n",
667 rc); 667 rc);
668 668
669alloc_err: 669alloc_err:
670 if (rc == -ENOMEM) 670 if (rc == -ENOMEM)
671 dev_dbg(pci_bus->self, "Memory allocation error\n"); 671 dev_dbg(&pci_bus->self->dev, "Memory allocation error\n");
672 672
673 /* destroy THIS element */ 673 /* destroy THIS element */
674 if (bss_hotplug_slot) 674 if (bss_hotplug_slot)
@@ -701,10 +701,10 @@ static int sn_pci_hotplug_init(void)
701 701
702 rc = sn_pci_bus_valid(pci_bus); 702 rc = sn_pci_bus_valid(pci_bus);
703 if (rc != 1) { 703 if (rc != 1) {
704 dev_dbg(pci_bus->self, "not a valid hotplug bus\n"); 704 dev_dbg(&pci_bus->self->dev, "not a valid hotplug bus\n");
705 continue; 705 continue;
706 } 706 }
707 dev_dbg(pci_bus->self, "valid hotplug bus\n"); 707 dev_dbg(&pci_bus->self->dev, "valid hotplug bus\n");
708 708
709 rc = sn_hotplug_slot_register(pci_bus); 709 rc = sn_hotplug_slot_register(pci_bus);
710 if (!rc) { 710 if (!rc) {
diff --git a/drivers/pci/hotplug/shpchp_ctrl.c b/drivers/pci/hotplug/shpchp_ctrl.c
index 2c94d44279a3..d2fc35598cdd 100644
--- a/drivers/pci/hotplug/shpchp_ctrl.c
+++ b/drivers/pci/hotplug/shpchp_ctrl.c
@@ -30,7 +30,6 @@
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/types.h> 32#include <linux/types.h>
33#include <linux/smp_lock.h>
34#include <linux/pci.h> 33#include <linux/pci.h>
35#include <linux/workqueue.h> 34#include <linux/workqueue.h>
36#include "../pci.h" 35#include "../pci.h"
diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
index 9e1321d0d5e6..d9cbd586ae4b 100644
--- a/drivers/pci/msi.c
+++ b/drivers/pci/msi.c
@@ -12,7 +12,6 @@
12#include <linux/interrupt.h> 12#include <linux/interrupt.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/ioport.h> 14#include <linux/ioport.h>
15#include <linux/smp_lock.h>
16#include <linux/pci.h> 15#include <linux/pci.h>
17#include <linux/proc_fs.h> 16#include <linux/proc_fs.h>
18#include <linux/msi.h> 17#include <linux/msi.h>
@@ -550,8 +549,10 @@ static int msi_free_irqs(struct pci_dev* dev)
550{ 549{
551 struct msi_desc *entry, *tmp; 550 struct msi_desc *entry, *tmp;
552 551
553 list_for_each_entry(entry, &dev->msi_list, list) 552 list_for_each_entry(entry, &dev->msi_list, list) {
554 BUG_ON(irq_has_action(entry->irq)); 553 if (entry->irq)
554 BUG_ON(irq_has_action(entry->irq));
555 }
555 556
556 arch_teardown_msi_irqs(dev); 557 arch_teardown_msi_irqs(dev);
557 558
diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 3bb7739d26a5..8e58ea3d95c0 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -119,7 +119,7 @@ static inline int pci_create_newid_file(struct pci_driver *drv)
119 * system is in its list of supported devices. Returns the matching 119 * system is in its list of supported devices. Returns the matching
120 * pci_device_id structure or %NULL if there is no match. 120 * pci_device_id structure or %NULL if there is no match.
121 * 121 *
122 * Depreciated, don't use this as it will not catch any dynamic ids 122 * Deprecated, don't use this as it will not catch any dynamic ids
123 * that a driver might want to check for. 123 * that a driver might want to check for.
124 */ 124 */
125const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, 125const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
diff --git a/drivers/pci/pcie/aer/aerdrv.h b/drivers/pci/pcie/aer/aerdrv.h
index bf655dbaf8e2..5cca394d5999 100644
--- a/drivers/pci/pcie/aer/aerdrv.h
+++ b/drivers/pci/pcie/aer/aerdrv.h
@@ -8,6 +8,7 @@
8#ifndef _AERDRV_H_ 8#ifndef _AERDRV_H_
9#define _AERDRV_H_ 9#define _AERDRV_H_
10 10
11#include <linux/workqueue.h>
11#include <linux/pcieport_if.h> 12#include <linux/pcieport_if.h>
12#include <linux/aer.h> 13#include <linux/aer.h>
13 14
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index ed87aa59f0b1..0425a7b7350d 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -11,7 +11,6 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/proc_fs.h> 12#include <linux/proc_fs.h>
13#include <linux/seq_file.h> 13#include <linux/seq_file.h>
14#include <linux/smp_lock.h>
15 14
16#include <asm/uaccess.h> 15#include <asm/uaccess.h>
17#include <asm/byteorder.h> 16#include <asm/byteorder.h>
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 147d86f8edbf..6ccc2e95930a 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -875,6 +875,7 @@ static void __devinit quirk_sb600_sata(struct pci_dev *pdev)
875 } 875 }
876} 876}
877DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_sb600_sata); 877DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_sb600_sata);
878DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_sb600_sata);
878 879
879/* 880/*
880 * Serverworks CSB5 IDE does not fully support native mode 881 * Serverworks CSB5 IDE does not fully support native mode
diff --git a/drivers/pcmcia/pxa2xx_mainstone.c b/drivers/pcmcia/pxa2xx_mainstone.c
index fda06941e730..383107ba4bd3 100644
--- a/drivers/pcmcia/pxa2xx_mainstone.c
+++ b/drivers/pcmcia/pxa2xx_mainstone.c
@@ -175,6 +175,7 @@ static int __init mst_pcmcia_init(void)
175 if (!mst_pcmcia_device) 175 if (!mst_pcmcia_device)
176 return -ENOMEM; 176 return -ENOMEM;
177 177
178 mst_pcmcia_device->dev.uevent_suppress = 0;
178 mst_pcmcia_device->dev.platform_data = &mst_pcmcia_ops; 179 mst_pcmcia_device->dev.platform_data = &mst_pcmcia_ops;
179 180
180 ret = platform_device_add(mst_pcmcia_device); 181 ret = platform_device_add(mst_pcmcia_device);
diff --git a/drivers/pcmcia/pxa2xx_sharpsl.c b/drivers/pcmcia/pxa2xx_sharpsl.c
index b7b9e149c5b9..a2daa3f531b2 100644
--- a/drivers/pcmcia/pxa2xx_sharpsl.c
+++ b/drivers/pcmcia/pxa2xx_sharpsl.c
@@ -261,6 +261,7 @@ static int __init sharpsl_pcmcia_init(void)
261 if (!sharpsl_pcmcia_device) 261 if (!sharpsl_pcmcia_device)
262 return -ENOMEM; 262 return -ENOMEM;
263 263
264 sharpsl_pcmcia_device->dev.uevent_suppress = 0;
264 sharpsl_pcmcia_device->dev.platform_data = &sharpsl_pcmcia_ops; 265 sharpsl_pcmcia_device->dev.platform_data = &sharpsl_pcmcia_ops;
265 sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev; 266 sharpsl_pcmcia_device->dev.parent = platform_scoop_config->devs[0].dev;
266 267
diff --git a/drivers/pnp/Kconfig b/drivers/pnp/Kconfig
index c5143201419a..1959cef8e9de 100644
--- a/drivers/pnp/Kconfig
+++ b/drivers/pnp/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "Plug and Play support" 5menu "Plug and Play support"
6 depends on HAS_IOMEM
6 7
7config PNP 8config PNP
8 bool "Plug and Play support" 9 bool "Plug and Play support"
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index aec83ec5ea23..3e20b1cc7778 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -14,6 +14,7 @@
14#include <linux/string.h> 14#include <linux/string.h>
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/errno.h> 16#include <linux/errno.h>
17#include <linux/dma-mapping.h>
17 18
18#include "base.h" 19#include "base.h"
19 20
@@ -22,6 +23,14 @@ static LIST_HEAD(pnp_protocols);
22LIST_HEAD(pnp_global); 23LIST_HEAD(pnp_global);
23DEFINE_SPINLOCK(pnp_lock); 24DEFINE_SPINLOCK(pnp_lock);
24 25
26/*
27 * ACPI or PNPBIOS should tell us about all platform devices, so we can
28 * skip some blind probes. ISAPNP typically enumerates only plug-in ISA
29 * devices, not built-in things like COM ports.
30 */
31int pnp_platform_devices;
32EXPORT_SYMBOL(pnp_platform_devices);
33
25void *pnp_alloc(long size) 34void *pnp_alloc(long size)
26{ 35{
27 void *result; 36 void *result;
@@ -114,6 +123,8 @@ int __pnp_add_device(struct pnp_dev *dev)
114 int ret; 123 int ret;
115 pnp_fixup_device(dev); 124 pnp_fixup_device(dev);
116 dev->dev.bus = &pnp_bus_type; 125 dev->dev.bus = &pnp_bus_type;
126 dev->dev.dma_mask = &dev->dma_mask;
127 dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK;
117 dev->dev.release = &pnp_release_device; 128 dev->dev.release = &pnp_release_device;
118 dev->status = PNP_READY; 129 dev->status = PNP_READY;
119 spin_lock(&pnp_lock); 130 spin_lock(&pnp_lock);
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index 62eda5d59024..a00548799e98 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr> 4 * Copyright (c) 2004 Matthieu Castet <castet.matthieu@free.fr>
5 * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com> 5 * Copyright (c) 2004 Li Shaohua <shaohua.li@intel.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify it 7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the 8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any 9 * Free Software Foundation; either version 2, or (at your option) any
@@ -18,7 +18,7 @@
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
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 <linux/acpi.h> 22#include <linux/acpi.h>
23#include <linux/pnp.h> 23#include <linux/pnp.h>
24#include <acpi/acpi_bus.h> 24#include <acpi/acpi_bus.h>
@@ -82,7 +82,7 @@ static void __init pnpidacpi_to_pnpid(char *id, char *str)
82static int pnpacpi_get_resources(struct pnp_dev * dev, struct pnp_resource_table * res) 82static int pnpacpi_get_resources(struct pnp_dev * dev, struct pnp_resource_table * res)
83{ 83{
84 acpi_status status; 84 acpi_status status;
85 status = pnpacpi_parse_allocated_resource((acpi_handle)dev->data, 85 status = pnpacpi_parse_allocated_resource((acpi_handle)dev->data,
86 &dev->res); 86 &dev->res);
87 return ACPI_FAILURE(status) ? -ENODEV : 0; 87 return ACPI_FAILURE(status) ? -ENODEV : 0;
88} 88}
@@ -112,9 +112,9 @@ static int pnpacpi_set_resources(struct pnp_dev * dev, struct pnp_resource_table
112static int pnpacpi_disable_resources(struct pnp_dev *dev) 112static int pnpacpi_disable_resources(struct pnp_dev *dev)
113{ 113{
114 acpi_status status; 114 acpi_status status;
115 115
116 /* acpi_unregister_gsi(pnp_irq(dev, 0)); */ 116 /* acpi_unregister_gsi(pnp_irq(dev, 0)); */
117 status = acpi_evaluate_object((acpi_handle)dev->data, 117 status = acpi_evaluate_object((acpi_handle)dev->data,
118 "_DIS", NULL, NULL); 118 "_DIS", NULL, NULL);
119 return ACPI_FAILURE(status) ? -ENODEV : 0; 119 return ACPI_FAILURE(status) ? -ENODEV : 0;
120} 120}
@@ -167,7 +167,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
167 strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name)); 167 strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
168 168
169 dev->number = num; 169 dev->number = num;
170 170
171 /* set the initial values for the PnP device */ 171 /* set the initial values for the PnP device */
172 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); 172 dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
173 if (!dev_id) 173 if (!dev_id)
@@ -185,14 +185,14 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
185 } 185 }
186 186
187 if(dev->capabilities & PNP_CONFIGURABLE) { 187 if(dev->capabilities & PNP_CONFIGURABLE) {
188 status = pnpacpi_parse_resource_option_data(device->handle, 188 status = pnpacpi_parse_resource_option_data(device->handle,
189 dev); 189 dev);
190 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) { 190 if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
191 pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s", dev_id->id); 191 pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s", dev_id->id);
192 goto err1; 192 goto err1;
193 } 193 }
194 } 194 }
195 195
196 /* parse compatible ids */ 196 /* parse compatible ids */
197 if (device->flags.compatible_ids) { 197 if (device->flags.compatible_ids) {
198 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list; 198 struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
@@ -236,6 +236,42 @@ static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
236 return AE_OK; 236 return AE_OK;
237} 237}
238 238
239static int __init acpi_pnp_match(struct device *dev, void *_pnp)
240{
241 struct acpi_device *acpi = to_acpi_device(dev);
242 struct pnp_dev *pnp = _pnp;
243
244 /* true means it matched */
245 return acpi->flags.hardware_id
246 && !acpi_get_physical_device(acpi->handle)
247 && compare_pnp_id(pnp->id, acpi->pnp.hardware_id);
248}
249
250static int __init acpi_pnp_find_device(struct device *dev, acpi_handle *handle)
251{
252 struct device *adev;
253 struct acpi_device *acpi;
254
255 adev = bus_find_device(&acpi_bus_type, NULL,
256 to_pnp_dev(dev),
257 acpi_pnp_match);
258 if (!adev)
259 return -ENODEV;
260
261 acpi = to_acpi_device(adev);
262 *handle = acpi->handle;
263 put_device(adev);
264 return 0;
265}
266
267/* complete initialization of a PNPACPI device includes having
268 * pnpdev->dev.archdata.acpi_handle point to its ACPI sibling.
269 */
270static struct acpi_bus_type __initdata acpi_pnp_bus = {
271 .bus = &pnp_bus_type,
272 .find_device = acpi_pnp_find_device,
273};
274
239int pnpacpi_disabled __initdata; 275int pnpacpi_disabled __initdata;
240static int __init pnpacpi_init(void) 276static int __init pnpacpi_init(void)
241{ 277{
@@ -245,8 +281,11 @@ static int __init pnpacpi_init(void)
245 } 281 }
246 pnp_info("PnP ACPI init"); 282 pnp_info("PnP ACPI init");
247 pnp_register_protocol(&pnpacpi_protocol); 283 pnp_register_protocol(&pnpacpi_protocol);
284 register_acpi_bus_type(&acpi_pnp_bus);
248 acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL); 285 acpi_get_devices(NULL, pnpacpi_add_device_handler, NULL, NULL);
249 pnp_info("PnP ACPI: found %d devices", num); 286 pnp_info("PnP ACPI: found %d devices", num);
287 unregister_acpi_bus_type(&acpi_pnp_bus);
288 pnp_platform_devices = 1;
250 return 0; 289 return 0;
251} 290}
252subsys_initcall(pnpacpi_init); 291subsys_initcall(pnpacpi_init);
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index 95738dbd5d45..3a201b77b963 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -62,6 +62,7 @@
62#include <linux/delay.h> 62#include <linux/delay.h>
63#include <linux/acpi.h> 63#include <linux/acpi.h>
64#include <linux/freezer.h> 64#include <linux/freezer.h>
65#include <linux/kthread.h>
65 66
66#include <asm/page.h> 67#include <asm/page.h>
67#include <asm/desc.h> 68#include <asm/desc.h>
@@ -159,9 +160,7 @@ static int pnp_dock_thread(void * unused)
159{ 160{
160 static struct pnp_docking_station_info now; 161 static struct pnp_docking_station_info now;
161 int docked = -1, d = 0; 162 int docked = -1, d = 0;
162 daemonize("kpnpbiosd"); 163 while (!unloading)
163 allow_signal(SIGKILL);
164 while(!unloading && !signal_pending(current))
165 { 164 {
166 int status; 165 int status;
167 166
@@ -170,11 +169,8 @@ static int pnp_dock_thread(void * unused)
170 */ 169 */
171 msleep_interruptible(2000); 170 msleep_interruptible(2000);
172 171
173 if(signal_pending(current)) { 172 if (try_to_freeze())
174 if (try_to_freeze()) 173 continue;
175 continue;
176 break;
177 }
178 174
179 status = pnp_bios_dock_station_info(&now); 175 status = pnp_bios_dock_station_info(&now);
180 176
@@ -574,6 +570,7 @@ static int __init pnpbios_init(void)
574 /* scan for pnpbios devices */ 570 /* scan for pnpbios devices */
575 build_devlist(); 571 build_devlist();
576 572
573 pnp_platform_devices = 1;
577 return 0; 574 return 0;
578} 575}
579 576
@@ -581,6 +578,7 @@ subsys_initcall(pnpbios_init);
581 578
582static int __init pnpbios_thread_init(void) 579static int __init pnpbios_thread_init(void)
583{ 580{
581 struct task_struct *task;
584#if defined(CONFIG_PPC_MERGE) 582#if defined(CONFIG_PPC_MERGE)
585 if (check_legacy_ioport(PNPBIOS_BASE)) 583 if (check_legacy_ioport(PNPBIOS_BASE))
586 return 0; 584 return 0;
@@ -589,7 +587,8 @@ static int __init pnpbios_thread_init(void)
589 return 0; 587 return 0;
590#ifdef CONFIG_HOTPLUG 588#ifdef CONFIG_HOTPLUG
591 init_completion(&unload_sem); 589 init_completion(&unload_sem);
592 if (kernel_thread(pnp_dock_thread, NULL, CLONE_KERNEL) > 0) 590 task = kthread_run(pnp_dock_thread, NULL, "kpnpbiosd");
591 if (!IS_ERR(task))
593 unloading = 0; 592 unloading = 0;
594#endif 593#endif
595 return 0; 594 return 0;
diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c
index e97ecefe8584..277df50c89ae 100644
--- a/drivers/pnp/quirks.c
+++ b/drivers/pnp/quirks.c
@@ -16,6 +16,7 @@
16#include <linux/string.h> 16#include <linux/string.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/pnp.h> 18#include <linux/pnp.h>
19#include <linux/io.h>
19#include "base.h" 20#include "base.h"
20 21
21 22
@@ -106,6 +107,34 @@ static void quirk_sb16audio_resources(struct pnp_dev *dev)
106 return; 107 return;
107} 108}
108 109
110static void quirk_smc_enable(struct pnp_dev *dev)
111{
112 unsigned int firbase;
113
114 if (!dev->active || !pnp_port_valid(dev, 1))
115 return;
116
117 /*
118 * On the HP/Compaq nw8240 (and probably other similar machines),
119 * there is an SMCF010 device with two I/O port regions:
120 *
121 * 0x3e8-0x3ef SIR
122 * 0x100-0x10f FIR
123 *
124 * _STA reports the device is enabled, but in fact, the BIOS
125 * neglects to enable the FIR range. Fortunately, it does fully
126 * enable the device if we call _SRS.
127 */
128 firbase = pnp_port_start(dev, 1);
129 if (inb(firbase + 0x7 /* IRCC_MASTER */) == 0xff) {
130 pnp_err("%s (%s) enabled but not responding, disabling and "
131 "re-enabling", dev->dev.bus_id, pnp_dev_name(dev));
132 pnp_disable_dev(dev);
133 pnp_activate_dev(dev);
134 }
135}
136
137
109/* 138/*
110 * PnP Quirks 139 * PnP Quirks
111 * Cards or devices that need some tweaking due to incomplete resource info 140 * Cards or devices that need some tweaking due to incomplete resource info
@@ -126,6 +155,7 @@ static struct pnp_fixup pnp_fixups[] = {
126 { "CTL0043", quirk_sb16audio_resources }, 155 { "CTL0043", quirk_sb16audio_resources },
127 { "CTL0044", quirk_sb16audio_resources }, 156 { "CTL0044", quirk_sb16audio_resources },
128 { "CTL0045", quirk_sb16audio_resources }, 157 { "CTL0045", quirk_sb16audio_resources },
158 { "SMCf010", quirk_smc_enable },
129 { "" } 159 { "" }
130}; 160};
131 161
diff --git a/drivers/ps3/vuart.c b/drivers/ps3/vuart.c
index 7d7cab1d91b4..ec2d36a1bc67 100644
--- a/drivers/ps3/vuart.c
+++ b/drivers/ps3/vuart.c
@@ -886,12 +886,12 @@ static int ps3_vuart_probe(struct device *_dev)
886 886
887 if (++vuart_bus_priv.use_count == 1) { 887 if (++vuart_bus_priv.use_count == 1) {
888 888
889 result = ps3_alloc_vuart_irq(PS3_BINDING_CPU_ANY, 889 result = ps3_vuart_irq_setup(PS3_BINDING_CPU_ANY,
890 (void*)&vuart_bus_priv.bmp.status, &vuart_bus_priv.virq); 890 (void*)&vuart_bus_priv.bmp.status, &vuart_bus_priv.virq);
891 891
892 if (result) { 892 if (result) {
893 dev_dbg(&dev->core, 893 dev_dbg(&dev->core,
894 "%s:%d: ps3_alloc_vuart_irq failed (%d)\n", 894 "%s:%d: ps3_vuart_irq_setup failed (%d)\n",
895 __func__, __LINE__, result); 895 __func__, __LINE__, result);
896 result = -EPERM; 896 result = -EPERM;
897 goto fail_alloc_irq; 897 goto fail_alloc_irq;
@@ -937,7 +937,7 @@ static int ps3_vuart_probe(struct device *_dev)
937fail_probe: 937fail_probe:
938 ps3_vuart_set_interrupt_mask(dev, 0); 938 ps3_vuart_set_interrupt_mask(dev, 0);
939fail_request_irq: 939fail_request_irq:
940 ps3_free_vuart_irq(vuart_bus_priv.virq); 940 ps3_vuart_irq_destroy(vuart_bus_priv.virq);
941 vuart_bus_priv.virq = NO_IRQ; 941 vuart_bus_priv.virq = NO_IRQ;
942fail_alloc_irq: 942fail_alloc_irq:
943 --vuart_bus_priv.use_count; 943 --vuart_bus_priv.use_count;
@@ -975,7 +975,7 @@ static int ps3_vuart_remove(struct device *_dev)
975 if (--vuart_bus_priv.use_count == 0) { 975 if (--vuart_bus_priv.use_count == 0) {
976 BUG(); 976 BUG();
977 free_irq(vuart_bus_priv.virq, &vuart_bus_priv); 977 free_irq(vuart_bus_priv.virq, &vuart_bus_priv);
978 ps3_free_vuart_irq(vuart_bus_priv.virq); 978 ps3_vuart_irq_destroy(vuart_bus_priv.virq);
979 vuart_bus_priv.virq = NO_IRQ; 979 vuart_bus_priv.virq = NO_IRQ;
980 } 980 }
981 981
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index ef1eae98ba44..4e4c10a7fd3a 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "Real Time Clock" 5menu "Real Time Clock"
6 depends on !S390
6 7
7config RTC_LIB 8config RTC_LIB
8 tristate 9 tristate
@@ -21,21 +22,31 @@ config RTC_CLASS
21 will be called rtc-class. 22 will be called rtc-class.
22 23
23config RTC_HCTOSYS 24config RTC_HCTOSYS
24 bool "Set system time from RTC on startup" 25 bool "Set system time from RTC on startup and resume"
25 depends on RTC_CLASS = y 26 depends on RTC_CLASS = y
26 default y 27 default y
27 help 28 help
28 If you say yes here, the system time will be set using 29 If you say yes here, the system time (wall clock) will be set using
29 the value read from the specified RTC device. This is useful 30 the value read from a specified RTC device. This is useful to avoid
30 in order to avoid unnecessary fsck runs. 31 unnecessary fsck runs at boot time, and to network better.
31 32
32config RTC_HCTOSYS_DEVICE 33config RTC_HCTOSYS_DEVICE
33 string "The RTC to read the time from" 34 string "RTC used to set the system time"
34 depends on RTC_HCTOSYS = y 35 depends on RTC_HCTOSYS = y
35 default "rtc0" 36 default "rtc0"
36 help 37 help
37 The RTC device that will be used as the source for 38 The RTC device that will be used to (re)initialize the system
38 the system time, usually rtc0. 39 clock, usually rtc0. Initialization is done when the system
40 starts up, and when it resumes from a low power state.
41
42 This clock should be battery-backed, so that it reads the correct
43 time when the system boots from a power-off state. Otherwise, your
44 system will need an external clock source (like an NTP server).
45
46 If the clock you specify here is not battery backed, it may still
47 be useful to reinitialize system time when resuming from system
48 sleep states. Do not specify an RTC here unless it stays powered
49 during all this system's supported sleep states.
39 50
40config RTC_DEBUG 51config RTC_DEBUG
41 bool "RTC debug support" 52 bool "RTC debug support"
@@ -48,7 +59,7 @@ comment "RTC interfaces"
48 depends on RTC_CLASS 59 depends on RTC_CLASS
49 60
50config RTC_INTF_SYSFS 61config RTC_INTF_SYSFS
51 tristate "sysfs" 62 boolean "/sys/class/rtc/rtcN (sysfs)"
52 depends on RTC_CLASS && SYSFS 63 depends on RTC_CLASS && SYSFS
53 default RTC_CLASS 64 default RTC_CLASS
54 help 65 help
@@ -59,7 +70,7 @@ config RTC_INTF_SYSFS
59 will be called rtc-sysfs. 70 will be called rtc-sysfs.
60 71
61config RTC_INTF_PROC 72config RTC_INTF_PROC
62 tristate "proc" 73 boolean "/proc/driver/rtc (procfs for rtc0)"
63 depends on RTC_CLASS && PROC_FS 74 depends on RTC_CLASS && PROC_FS
64 default RTC_CLASS 75 default RTC_CLASS
65 help 76 help
@@ -71,7 +82,7 @@ config RTC_INTF_PROC
71 will be called rtc-proc. 82 will be called rtc-proc.
72 83
73config RTC_INTF_DEV 84config RTC_INTF_DEV
74 tristate "dev" 85 boolean "/dev/rtcN (character devices)"
75 depends on RTC_CLASS 86 depends on RTC_CLASS
76 default RTC_CLASS 87 default RTC_CLASS
77 help 88 help
@@ -88,48 +99,30 @@ config RTC_INTF_DEV_UIE_EMUL
88 bool "RTC UIE emulation on dev interface" 99 bool "RTC UIE emulation on dev interface"
89 depends on RTC_INTF_DEV 100 depends on RTC_INTF_DEV
90 help 101 help
91 Provides an emulation for RTC_UIE if the underlaying rtc chip 102 Provides an emulation for RTC_UIE if the underlying rtc chip
92 driver does not expose RTC_UIE ioctls. Those requests generate 103 driver does not expose RTC_UIE ioctls. Those requests generate
93 once-per-second update interrupts, used for synchronization. 104 once-per-second update interrupts, used for synchronization.
94 105
95comment "RTC drivers" 106config RTC_DRV_TEST
107 tristate "Test driver/device"
96 depends on RTC_CLASS 108 depends on RTC_CLASS
97
98# this 'CMOS' RTC driver is arch dependent because <asm-generic/rtc.h>
99# requires <asm/mc146818rtc.h> defining CMOS_READ/CMOS_WRITE, and a
100# global rtc_lock ... it's not yet just another platform_device.
101
102config RTC_DRV_CMOS
103 tristate "PC-style 'CMOS' real time clock"
104 depends on RTC_CLASS && (X86 || ALPHA || ARM26 || ARM \
105 || M32R || ATARI || POWERPC)
106 help
107 Say "yes" here to get direct support for the real time clock
108 found in every PC or ACPI-based system, and some other boards.
109 Specifically the original MC146818, compatibles like those in
110 PC south bridges, the DS12887 or M48T86, some multifunction
111 or LPC bus chips, and so on.
112
113 Your system will need to define the platform device used by
114 this driver, otherwise it won't be accessible. This means
115 you can safely enable this driver if you don't know whether
116 or not your board has this kind of hardware.
117
118 This driver can also be built as a module. If so, the module
119 will be called rtc-cmos.
120
121config RTC_DRV_X1205
122 tristate "Xicor/Intersil X1205"
123 depends on RTC_CLASS && I2C
124 help 109 help
125 If you say yes here you get support for the 110 If you say yes here you get support for the
126 Xicor/Intersil X1205 RTC chip. 111 RTC test driver. It's a software RTC which can be
112 used to test the RTC subsystem APIs. It gets
113 the time from the system clock.
114 You want this driver only if you are doing development
115 on the RTC subsystem. Please read the source code
116 for further details.
127 117
128 This driver can also be built as a module. If so, the module 118 This driver can also be built as a module. If so, the module
129 will be called rtc-x1205. 119 will be called rtc-test.
120
121comment "I2C RTC drivers"
122 depends on RTC_CLASS
130 123
131config RTC_DRV_DS1307 124config RTC_DRV_DS1307
132 tristate "Dallas/Maxim DS1307 and similar I2C RTC chips" 125 tristate "Dallas/Maxim DS1307/37/38/39/40, ST M41T00"
133 depends on RTC_CLASS && I2C 126 depends on RTC_CLASS && I2C
134 help 127 help
135 If you say yes here you get support for various compatible RTC 128 If you say yes here you get support for various compatible RTC
@@ -146,53 +139,55 @@ config RTC_DRV_DS1307
146 This driver can also be built as a module. If so, the module 139 This driver can also be built as a module. If so, the module
147 will be called rtc-ds1307. 140 will be called rtc-ds1307.
148 141
149config RTC_DRV_DS1553 142config RTC_DRV_DS1672
150 tristate "Dallas DS1553" 143 tristate "Dallas/Maxim DS1672"
151 depends on RTC_CLASS 144 depends on RTC_CLASS && I2C
152 help 145 help
153 If you say yes here you get support for the 146 If you say yes here you get support for the
154 Dallas DS1553 timekeeping chip. 147 Dallas/Maxim DS1672 timekeeping chip.
155 148
156 This driver can also be built as a module. If so, the module 149 This driver can also be built as a module. If so, the module
157 will be called rtc-ds1553. 150 will be called rtc-ds1672.
158 151
159config RTC_DRV_ISL1208 152config RTC_DRV_MAX6900
160 tristate "Intersil 1208" 153 tristate "Maxim 6900"
161 depends on RTC_CLASS && I2C 154 depends on RTC_CLASS && I2C
162 help 155 help
163 If you say yes here you get support for the 156 If you say yes here you will get support for the
164 Intersil 1208 RTC chip. 157 Maxim MAX6900 I2C RTC chip.
165 158
166 This driver can also be built as a module. If so, the module 159 This driver can also be built as a module. If so, the module
167 will be called rtc-isl1208. 160 will be called rtc-max6900.
168 161
169config RTC_DRV_DS1672 162config RTC_DRV_RS5C372
170 tristate "Dallas/Maxim DS1672" 163 tristate "Ricoh RS5C372A/B"
171 depends on RTC_CLASS && I2C 164 depends on RTC_CLASS && I2C
172 help 165 help
173 If you say yes here you get support for the 166 If you say yes here you get support for the
174 Dallas/Maxim DS1672 timekeeping chip. 167 Ricoh RS5C372A and RS5C372B RTC chips.
175 168
176 This driver can also be built as a module. If so, the module 169 This driver can also be built as a module. If so, the module
177 will be called rtc-ds1672. 170 will be called rtc-rs5c372.
178 171
179config RTC_DRV_DS1742 172config RTC_DRV_ISL1208
180 tristate "Dallas DS1742/1743" 173 tristate "Intersil 1208"
181 depends on RTC_CLASS 174 depends on RTC_CLASS && I2C
182 help 175 help
183 If you say yes here you get support for the 176 If you say yes here you get support for the
184 Dallas DS1742/1743 timekeeping chip. 177 Intersil 1208 RTC chip.
185 178
186 This driver can also be built as a module. If so, the module 179 This driver can also be built as a module. If so, the module
187 will be called rtc-ds1742. 180 will be called rtc-isl1208.
188 181
189config RTC_DRV_OMAP 182config RTC_DRV_X1205
190 tristate "TI OMAP1" 183 tristate "Xicor/Intersil X1205"
191 depends on RTC_CLASS && ( \ 184 depends on RTC_CLASS && I2C
192 ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 )
193 help 185 help
194 Say "yes" here to support the real time clock on TI OMAP1 chips. 186 If you say yes here you get support for the
195 This driver can also be built as a module called rtc-omap. 187 Xicor/Intersil X1205 RTC chip.
188
189 This driver can also be built as a module. If so, the module
190 will be called rtc-x1205.
196 191
197config RTC_DRV_PCF8563 192config RTC_DRV_PCF8563
198 tristate "Philips PCF8563/Epson RTC8564" 193 tristate "Philips PCF8563/Epson RTC8564"
@@ -207,16 +202,20 @@ config RTC_DRV_PCF8563
207 202
208config RTC_DRV_PCF8583 203config RTC_DRV_PCF8583
209 tristate "Philips PCF8583" 204 tristate "Philips PCF8583"
210 depends on RTC_CLASS && I2C && ARCH_RPC 205 depends on RTC_CLASS && I2C
211 help 206 help
212 If you say yes here you get support for the Philips PCF8583 207 If you say yes here you get support for the Philips PCF8583
213 RTC chip found on Acorn RiscPCs. This driver supports the 208 RTC chip found on Acorn RiscPCs. This driver supports the
214 platform specific method of retrieving the current year from 209 platform specific method of retrieving the current year from
215 the RTC's SRAM. 210 the RTC's SRAM. It will work on other platforms with the same
211 chip, but the year will probably have to be tweaked.
216 212
217 This driver can also be built as a module. If so, the module 213 This driver can also be built as a module. If so, the module
218 will be called rtc-pcf8583. 214 will be called rtc-pcf8583.
219 215
216comment "SPI RTC drivers"
217 depends on RTC_CLASS
218
220config RTC_DRV_RS5C348 219config RTC_DRV_RS5C348
221 tristate "Ricoh RS5C348A/B" 220 tristate "Ricoh RS5C348A/B"
222 depends on RTC_CLASS && SPI 221 depends on RTC_CLASS && SPI
@@ -227,15 +226,92 @@ config RTC_DRV_RS5C348
227 This driver can also be built as a module. If so, the module 226 This driver can also be built as a module. If so, the module
228 will be called rtc-rs5c348. 227 will be called rtc-rs5c348.
229 228
230config RTC_DRV_RS5C372 229config RTC_DRV_MAX6902
231 tristate "Ricoh RS5C372A/B" 230 tristate "Maxim 6902"
232 depends on RTC_CLASS && I2C 231 depends on RTC_CLASS && SPI
232 help
233 If you say yes here you will get support for the
234 Maxim MAX6902 SPI RTC chip.
235
236 This driver can also be built as a module. If so, the module
237 will be called rtc-max6902.
238
239comment "Platform RTC drivers"
240 depends on RTC_CLASS
241
242# this 'CMOS' RTC driver is arch dependent because <asm-generic/rtc.h>
243# requires <asm/mc146818rtc.h> defining CMOS_READ/CMOS_WRITE, and a
244# global rtc_lock ... it's not yet just another platform_device.
245
246config RTC_DRV_CMOS
247 tristate "PC-style 'CMOS'"
248 depends on RTC_CLASS && (X86 || ALPHA || ARM26 || ARM \
249 || M32R || ATARI || POWERPC || MIPS)
250 help
251 Say "yes" here to get direct support for the real time clock
252 found in every PC or ACPI-based system, and some other boards.
253 Specifically the original MC146818, compatibles like those in
254 PC south bridges, the DS12887 or M48T86, some multifunction
255 or LPC bus chips, and so on.
256
257 Your system will need to define the platform device used by
258 this driver, otherwise it won't be accessible. This means
259 you can safely enable this driver if you don't know whether
260 or not your board has this kind of hardware.
261
262 This driver can also be built as a module. If so, the module
263 will be called rtc-cmos.
264
265config RTC_DRV_DS1553
266 tristate "Dallas DS1553"
267 depends on RTC_CLASS
233 help 268 help
234 If you say yes here you get support for the 269 If you say yes here you get support for the
235 Ricoh RS5C372A and RS5C372B RTC chips. 270 Dallas DS1553 timekeeping chip.
236 271
237 This driver can also be built as a module. If so, the module 272 This driver can also be built as a module. If so, the module
238 will be called rtc-rs5c372. 273 will be called rtc-ds1553.
274
275config RTC_DRV_DS1742
276 tristate "Dallas DS1742/1743"
277 depends on RTC_CLASS
278 help
279 If you say yes here you get support for the
280 Dallas DS1742/1743 timekeeping chip.
281
282 This driver can also be built as a module. If so, the module
283 will be called rtc-ds1742.
284
285config RTC_DRV_M48T86
286 tristate "ST M48T86/Dallas DS12887"
287 depends on RTC_CLASS
288 help
289 If you say Y here you will get support for the
290 ST M48T86 and Dallas DS12887 RTC chips.
291
292 This driver can also be built as a module. If so, the module
293 will be called rtc-m48t86.
294
295config RTC_DRV_V3020
296 tristate "EM Microelectronic V3020"
297 depends on RTC_CLASS
298 help
299 If you say yes here you will get support for the
300 EM Microelectronic v3020 RTC chip.
301
302 This driver can also be built as a module. If so, the module
303 will be called rtc-v3020.
304
305comment "on-CPU RTC drivers"
306 depends on RTC_CLASS
307
308config RTC_DRV_OMAP
309 tristate "TI OMAP1"
310 depends on RTC_CLASS && ( \
311 ARCH_OMAP15XX || ARCH_OMAP16XX || ARCH_OMAP730 )
312 help
313 Say "yes" here to support the real time clock on TI OMAP1 chips.
314 This driver can also be built as a module called rtc-omap.
239 315
240config RTC_DRV_S3C 316config RTC_DRV_S3C
241 tristate "Samsung S3C series SoC RTC" 317 tristate "Samsung S3C series SoC RTC"
@@ -253,16 +329,6 @@ config RTC_DRV_S3C
253 This driver can also be build as a module. If so, the module 329 This driver can also be build as a module. If so, the module
254 will be called rtc-s3c. 330 will be called rtc-s3c.
255 331
256config RTC_DRV_M48T86
257 tristate "ST M48T86/Dallas DS12887"
258 depends on RTC_CLASS
259 help
260 If you say Y here you will get support for the
261 ST M48T86 and Dallas DS12887 RTC chips.
262
263 This driver can also be built as a module. If so, the module
264 will be called rtc-m48t86.
265
266config RTC_DRV_EP93XX 332config RTC_DRV_EP93XX
267 tristate "Cirrus Logic EP93XX" 333 tristate "Cirrus Logic EP93XX"
268 depends on RTC_CLASS && ARCH_EP93XX 334 depends on RTC_CLASS && ARCH_EP93XX
@@ -308,7 +374,7 @@ config RTC_DRV_PL031
308 depends on RTC_CLASS && ARM_AMBA 374 depends on RTC_CLASS && ARM_AMBA
309 help 375 help
310 If you say Y here you will get access to ARM AMBA 376 If you say Y here you will get access to ARM AMBA
311 PrimeCell PL031 UART found on certain ARM SOCs. 377 PrimeCell PL031 RTC found on certain ARM SOCs.
312 378
313 To compile this driver as a module, choose M here: the 379 To compile this driver as a module, choose M here: the
314 module will be called rtc-pl031. 380 module will be called rtc-pl031.
@@ -319,41 +385,6 @@ config RTC_DRV_AT91RM9200
319 help 385 help
320 Driver for the Atmel AT91RM9200's internal RTC (Realtime Clock). 386 Driver for the Atmel AT91RM9200's internal RTC (Realtime Clock).
321 387
322config RTC_DRV_TEST
323 tristate "Test driver/device"
324 depends on RTC_CLASS
325 help
326 If you say yes here you get support for the
327 RTC test driver. It's a software RTC which can be
328 used to test the RTC subsystem APIs. It gets
329 the time from the system clock.
330 You want this driver only if you are doing development
331 on the RTC subsystem. Please read the source code
332 for further details.
333
334 This driver can also be built as a module. If so, the module
335 will be called rtc-test.
336
337config RTC_DRV_MAX6902
338 tristate "Maxim 6902"
339 depends on RTC_CLASS && SPI
340 help
341 If you say yes here you will get support for the
342 Maxim MAX6902 spi RTC chip.
343
344 This driver can also be built as a module. If so, the module
345 will be called rtc-max6902.
346
347config RTC_DRV_V3020
348 tristate "EM Microelectronic V3020"
349 depends on RTC_CLASS
350 help
351 If you say yes here you will get support for the
352 EM Microelectronic v3020 RTC chip.
353
354 This driver can also be built as a module. If so, the module
355 will be called rtc-v3020.
356
357config RTC_DRV_BFIN 388config RTC_DRV_BFIN
358 tristate "Blackfin On-Chip RTC" 389 tristate "Blackfin On-Chip RTC"
359 depends on RTC_CLASS && BFIN 390 depends on RTC_CLASS && BFIN
@@ -364,4 +395,10 @@ config RTC_DRV_BFIN
364 This driver can also be built as a module. If so, the module 395 This driver can also be built as a module. If so, the module
365 will be called rtc-bfin. 396 will be called rtc-bfin.
366 397
398config RTC_DRV_RS5C313
399 tristate "Ricoh RS5C313"
400 depends on RTC_CLASS && SH_LANDISK
401 help
402 If you say yes here you get support for the Ricoh RS5C313 RTC chips.
403
367endmenu 404endmenu
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 9218cf28d6ed..a1afbc236073 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -11,9 +11,9 @@ obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
11obj-$(CONFIG_RTC_CLASS) += rtc-core.o 11obj-$(CONFIG_RTC_CLASS) += rtc-core.o
12rtc-core-y := class.o interface.o 12rtc-core-y := class.o interface.o
13 13
14obj-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o 14rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
15obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o 15rtc-core-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
16obj-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o 16rtc-core-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
17 17
18obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o 18obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
19obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o 19obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
@@ -30,10 +30,12 @@ obj-$(CONFIG_RTC_DRV_S3C) += rtc-s3c.o
30obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o 30obj-$(CONFIG_RTC_DRV_RS5C348) += rtc-rs5c348.o
31obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o 31obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
32obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o 32obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o
33obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
33obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 34obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
34obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o 35obj-$(CONFIG_RTC_DRV_SA1100) += rtc-sa1100.o
35obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o 36obj-$(CONFIG_RTC_DRV_VR41XX) += rtc-vr41xx.o
36obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o 37obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
38obj-$(CONFIG_RTC_DRV_MAX6900) += rtc-max6900.o
37obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o 39obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
38obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o 40obj-$(CONFIG_RTC_DRV_V3020) += rtc-v3020.o
39obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o 41obj-$(CONFIG_RTC_DRV_AT91RM9200)+= rtc-at91rm9200.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 04aaa6347234..8b3cd31d6a61 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -16,19 +16,94 @@
16#include <linux/kdev_t.h> 16#include <linux/kdev_t.h>
17#include <linux/idr.h> 17#include <linux/idr.h>
18 18
19#include "rtc-core.h"
20
21
19static DEFINE_IDR(rtc_idr); 22static DEFINE_IDR(rtc_idr);
20static DEFINE_MUTEX(idr_lock); 23static DEFINE_MUTEX(idr_lock);
21struct class *rtc_class; 24struct class *rtc_class;
22 25
23static void rtc_device_release(struct class_device *class_dev) 26static void rtc_device_release(struct device *dev)
24{ 27{
25 struct rtc_device *rtc = to_rtc_device(class_dev); 28 struct rtc_device *rtc = to_rtc_device(dev);
26 mutex_lock(&idr_lock); 29 mutex_lock(&idr_lock);
27 idr_remove(&rtc_idr, rtc->id); 30 idr_remove(&rtc_idr, rtc->id);
28 mutex_unlock(&idr_lock); 31 mutex_unlock(&idr_lock);
29 kfree(rtc); 32 kfree(rtc);
30} 33}
31 34
35#if defined(CONFIG_PM) && defined(CONFIG_RTC_HCTOSYS_DEVICE)
36
37/*
38 * On suspend(), measure the delta between one RTC and the
39 * system's wall clock; restore it on resume().
40 */
41
42static struct timespec delta;
43static time_t oldtime;
44
45static int rtc_suspend(struct device *dev, pm_message_t mesg)
46{
47 struct rtc_device *rtc = to_rtc_device(dev);
48 struct rtc_time tm;
49
50 if (strncmp(rtc->dev.bus_id,
51 CONFIG_RTC_HCTOSYS_DEVICE,
52 BUS_ID_SIZE) != 0)
53 return 0;
54
55 rtc_read_time(rtc, &tm);
56 rtc_tm_to_time(&tm, &oldtime);
57
58 /* RTC precision is 1 second; adjust delta for avg 1/2 sec err */
59 set_normalized_timespec(&delta,
60 xtime.tv_sec - oldtime,
61 xtime.tv_nsec - (NSEC_PER_SEC >> 1));
62
63 return 0;
64}
65
66static int rtc_resume(struct device *dev)
67{
68 struct rtc_device *rtc = to_rtc_device(dev);
69 struct rtc_time tm;
70 time_t newtime;
71 struct timespec time;
72
73 if (strncmp(rtc->dev.bus_id,
74 CONFIG_RTC_HCTOSYS_DEVICE,
75 BUS_ID_SIZE) != 0)
76 return 0;
77
78 rtc_read_time(rtc, &tm);
79 if (rtc_valid_tm(&tm) != 0) {
80 pr_debug("%s: bogus resume time\n", rtc->dev.bus_id);
81 return 0;
82 }
83 rtc_tm_to_time(&tm, &newtime);
84 if (newtime <= oldtime) {
85 if (newtime < oldtime)
86 pr_debug("%s: time travel!\n", rtc->dev.bus_id);
87 return 0;
88 }
89
90 /* restore wall clock using delta against this RTC;
91 * adjust again for avg 1/2 second RTC sampling error
92 */
93 set_normalized_timespec(&time,
94 newtime + delta.tv_sec,
95 (NSEC_PER_SEC >> 1) + delta.tv_nsec);
96 do_settimeofday(&time);
97
98 return 0;
99}
100
101#else
102#define rtc_suspend NULL
103#define rtc_resume NULL
104#endif
105
106
32/** 107/**
33 * rtc_device_register - register w/ RTC class 108 * rtc_device_register - register w/ RTC class
34 * @dev: the device to register 109 * @dev: the device to register
@@ -70,23 +145,29 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
70 rtc->ops = ops; 145 rtc->ops = ops;
71 rtc->owner = owner; 146 rtc->owner = owner;
72 rtc->max_user_freq = 64; 147 rtc->max_user_freq = 64;
73 rtc->class_dev.dev = dev; 148 rtc->dev.parent = dev;
74 rtc->class_dev.class = rtc_class; 149 rtc->dev.class = rtc_class;
75 rtc->class_dev.release = rtc_device_release; 150 rtc->dev.release = rtc_device_release;
76 151
77 mutex_init(&rtc->ops_lock); 152 mutex_init(&rtc->ops_lock);
78 spin_lock_init(&rtc->irq_lock); 153 spin_lock_init(&rtc->irq_lock);
79 spin_lock_init(&rtc->irq_task_lock); 154 spin_lock_init(&rtc->irq_task_lock);
80 155
81 strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); 156 strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE);
82 snprintf(rtc->class_dev.class_id, BUS_ID_SIZE, "rtc%d", id); 157 snprintf(rtc->dev.bus_id, BUS_ID_SIZE, "rtc%d", id);
83 158
84 err = class_device_register(&rtc->class_dev); 159 rtc_dev_prepare(rtc);
160
161 err = device_register(&rtc->dev);
85 if (err) 162 if (err)
86 goto exit_kfree; 163 goto exit_kfree;
87 164
165 rtc_dev_add_device(rtc);
166 rtc_sysfs_add_device(rtc);
167 rtc_proc_add_device(rtc);
168
88 dev_info(dev, "rtc core: registered %s as %s\n", 169 dev_info(dev, "rtc core: registered %s as %s\n",
89 rtc->name, rtc->class_dev.class_id); 170 rtc->name, rtc->dev.bus_id);
90 171
91 return rtc; 172 return rtc;
92 173
@@ -113,26 +194,22 @@ EXPORT_SYMBOL_GPL(rtc_device_register);
113 */ 194 */
114void rtc_device_unregister(struct rtc_device *rtc) 195void rtc_device_unregister(struct rtc_device *rtc)
115{ 196{
116 if (class_device_get(&rtc->class_dev) != NULL) { 197 if (get_device(&rtc->dev) != NULL) {
117 mutex_lock(&rtc->ops_lock); 198 mutex_lock(&rtc->ops_lock);
118 /* remove innards of this RTC, then disable it, before 199 /* remove innards of this RTC, then disable it, before
119 * letting any rtc_class_open() users access it again 200 * letting any rtc_class_open() users access it again
120 */ 201 */
121 class_device_unregister(&rtc->class_dev); 202 rtc_sysfs_del_device(rtc);
203 rtc_dev_del_device(rtc);
204 rtc_proc_del_device(rtc);
205 device_unregister(&rtc->dev);
122 rtc->ops = NULL; 206 rtc->ops = NULL;
123 mutex_unlock(&rtc->ops_lock); 207 mutex_unlock(&rtc->ops_lock);
124 class_device_put(&rtc->class_dev); 208 put_device(&rtc->dev);
125 } 209 }
126} 210}
127EXPORT_SYMBOL_GPL(rtc_device_unregister); 211EXPORT_SYMBOL_GPL(rtc_device_unregister);
128 212
129int rtc_interface_register(struct class_interface *intf)
130{
131 intf->class = rtc_class;
132 return class_interface_register(intf);
133}
134EXPORT_SYMBOL_GPL(rtc_interface_register);
135
136static int __init rtc_init(void) 213static int __init rtc_init(void)
137{ 214{
138 rtc_class = class_create(THIS_MODULE, "rtc"); 215 rtc_class = class_create(THIS_MODULE, "rtc");
@@ -140,11 +217,16 @@ static int __init rtc_init(void)
140 printk(KERN_ERR "%s: couldn't create class\n", __FILE__); 217 printk(KERN_ERR "%s: couldn't create class\n", __FILE__);
141 return PTR_ERR(rtc_class); 218 return PTR_ERR(rtc_class);
142 } 219 }
220 rtc_class->suspend = rtc_suspend;
221 rtc_class->resume = rtc_resume;
222 rtc_dev_init();
223 rtc_sysfs_init(rtc_class);
143 return 0; 224 return 0;
144} 225}
145 226
146static void __exit rtc_exit(void) 227static void __exit rtc_exit(void)
147{ 228{
229 rtc_dev_exit();
148 class_destroy(rtc_class); 230 class_destroy(rtc_class);
149} 231}
150 232
diff --git a/drivers/rtc/hctosys.c b/drivers/rtc/hctosys.c
index d02fe9a0001f..178527252c6a 100644
--- a/drivers/rtc/hctosys.c
+++ b/drivers/rtc/hctosys.c
@@ -26,15 +26,15 @@ static int __init rtc_hctosys(void)
26{ 26{
27 int err; 27 int err;
28 struct rtc_time tm; 28 struct rtc_time tm;
29 struct class_device *class_dev = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE); 29 struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
30 30
31 if (class_dev == NULL) { 31 if (rtc == NULL) {
32 printk("%s: unable to open rtc device (%s)\n", 32 printk("%s: unable to open rtc device (%s)\n",
33 __FILE__, CONFIG_RTC_HCTOSYS_DEVICE); 33 __FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
34 return -ENODEV; 34 return -ENODEV;
35 } 35 }
36 36
37 err = rtc_read_time(class_dev, &tm); 37 err = rtc_read_time(rtc, &tm);
38 if (err == 0) { 38 if (err == 0) {
39 err = rtc_valid_tm(&tm); 39 err = rtc_valid_tm(&tm);
40 if (err == 0) { 40 if (err == 0) {
@@ -46,7 +46,7 @@ static int __init rtc_hctosys(void)
46 46
47 do_settimeofday(&tv); 47 do_settimeofday(&tv);
48 48
49 dev_info(class_dev->dev, 49 dev_info(rtc->dev.parent,
50 "setting the system clock to " 50 "setting the system clock to "
51 "%d-%02d-%02d %02d:%02d:%02d (%u)\n", 51 "%d-%02d-%02d %02d:%02d:%02d (%u)\n",
52 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, 52 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
@@ -54,14 +54,14 @@ static int __init rtc_hctosys(void)
54 (unsigned int) tv.tv_sec); 54 (unsigned int) tv.tv_sec);
55 } 55 }
56 else 56 else
57 dev_err(class_dev->dev, 57 dev_err(rtc->dev.parent,
58 "hctosys: invalid date/time\n"); 58 "hctosys: invalid date/time\n");
59 } 59 }
60 else 60 else
61 dev_err(class_dev->dev, 61 dev_err(rtc->dev.parent,
62 "hctosys: unable to read the hardware clock\n"); 62 "hctosys: unable to read the hardware clock\n");
63 63
64 rtc_class_close(class_dev); 64 rtc_class_close(rtc);
65 65
66 return 0; 66 return 0;
67} 67}
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index ef40df0f169d..ad66c6ecf365 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -13,10 +13,9 @@
13 13
14#include <linux/rtc.h> 14#include <linux/rtc.h>
15 15
16int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm) 16int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
17{ 17{
18 int err; 18 int err;
19 struct rtc_device *rtc = to_rtc_device(class_dev);
20 19
21 err = mutex_lock_interruptible(&rtc->ops_lock); 20 err = mutex_lock_interruptible(&rtc->ops_lock);
22 if (err) 21 if (err)
@@ -28,7 +27,7 @@ int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm)
28 err = -EINVAL; 27 err = -EINVAL;
29 else { 28 else {
30 memset(tm, 0, sizeof(struct rtc_time)); 29 memset(tm, 0, sizeof(struct rtc_time));
31 err = rtc->ops->read_time(class_dev->dev, tm); 30 err = rtc->ops->read_time(rtc->dev.parent, tm);
32 } 31 }
33 32
34 mutex_unlock(&rtc->ops_lock); 33 mutex_unlock(&rtc->ops_lock);
@@ -36,10 +35,9 @@ int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm)
36} 35}
37EXPORT_SYMBOL_GPL(rtc_read_time); 36EXPORT_SYMBOL_GPL(rtc_read_time);
38 37
39int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm) 38int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
40{ 39{
41 int err; 40 int err;
42 struct rtc_device *rtc = to_rtc_device(class_dev);
43 41
44 err = rtc_valid_tm(tm); 42 err = rtc_valid_tm(tm);
45 if (err != 0) 43 if (err != 0)
@@ -54,17 +52,16 @@ int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm)
54 else if (!rtc->ops->set_time) 52 else if (!rtc->ops->set_time)
55 err = -EINVAL; 53 err = -EINVAL;
56 else 54 else
57 err = rtc->ops->set_time(class_dev->dev, tm); 55 err = rtc->ops->set_time(rtc->dev.parent, tm);
58 56
59 mutex_unlock(&rtc->ops_lock); 57 mutex_unlock(&rtc->ops_lock);
60 return err; 58 return err;
61} 59}
62EXPORT_SYMBOL_GPL(rtc_set_time); 60EXPORT_SYMBOL_GPL(rtc_set_time);
63 61
64int rtc_set_mmss(struct class_device *class_dev, unsigned long secs) 62int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
65{ 63{
66 int err; 64 int err;
67 struct rtc_device *rtc = to_rtc_device(class_dev);
68 65
69 err = mutex_lock_interruptible(&rtc->ops_lock); 66 err = mutex_lock_interruptible(&rtc->ops_lock);
70 if (err) 67 if (err)
@@ -73,11 +70,11 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
73 if (!rtc->ops) 70 if (!rtc->ops)
74 err = -ENODEV; 71 err = -ENODEV;
75 else if (rtc->ops->set_mmss) 72 else if (rtc->ops->set_mmss)
76 err = rtc->ops->set_mmss(class_dev->dev, secs); 73 err = rtc->ops->set_mmss(rtc->dev.parent, secs);
77 else if (rtc->ops->read_time && rtc->ops->set_time) { 74 else if (rtc->ops->read_time && rtc->ops->set_time) {
78 struct rtc_time new, old; 75 struct rtc_time new, old;
79 76
80 err = rtc->ops->read_time(class_dev->dev, &old); 77 err = rtc->ops->read_time(rtc->dev.parent, &old);
81 if (err == 0) { 78 if (err == 0) {
82 rtc_time_to_tm(secs, &new); 79 rtc_time_to_tm(secs, &new);
83 80
@@ -89,7 +86,8 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
89 */ 86 */
90 if (!((old.tm_hour == 23 && old.tm_min == 59) || 87 if (!((old.tm_hour == 23 && old.tm_min == 59) ||
91 (new.tm_hour == 23 && new.tm_min == 59))) 88 (new.tm_hour == 23 && new.tm_min == 59)))
92 err = rtc->ops->set_time(class_dev->dev, &new); 89 err = rtc->ops->set_time(rtc->dev.parent,
90 &new);
93 } 91 }
94 } 92 }
95 else 93 else
@@ -101,10 +99,9 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
101} 99}
102EXPORT_SYMBOL_GPL(rtc_set_mmss); 100EXPORT_SYMBOL_GPL(rtc_set_mmss);
103 101
104int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm) 102int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
105{ 103{
106 int err; 104 int err;
107 struct rtc_device *rtc = to_rtc_device(class_dev);
108 105
109 err = mutex_lock_interruptible(&rtc->ops_lock); 106 err = mutex_lock_interruptible(&rtc->ops_lock);
110 if (err) 107 if (err)
@@ -116,7 +113,7 @@ int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
116 err = -EINVAL; 113 err = -EINVAL;
117 else { 114 else {
118 memset(alarm, 0, sizeof(struct rtc_wkalrm)); 115 memset(alarm, 0, sizeof(struct rtc_wkalrm));
119 err = rtc->ops->read_alarm(class_dev->dev, alarm); 116 err = rtc->ops->read_alarm(rtc->dev.parent, alarm);
120 } 117 }
121 118
122 mutex_unlock(&rtc->ops_lock); 119 mutex_unlock(&rtc->ops_lock);
@@ -124,10 +121,13 @@ int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
124} 121}
125EXPORT_SYMBOL_GPL(rtc_read_alarm); 122EXPORT_SYMBOL_GPL(rtc_read_alarm);
126 123
127int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm) 124int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
128{ 125{
129 int err; 126 int err;
130 struct rtc_device *rtc = to_rtc_device(class_dev); 127
128 err = rtc_valid_tm(&alarm->time);
129 if (err != 0)
130 return err;
131 131
132 err = mutex_lock_interruptible(&rtc->ops_lock); 132 err = mutex_lock_interruptible(&rtc->ops_lock);
133 if (err) 133 if (err)
@@ -138,7 +138,7 @@ int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
138 else if (!rtc->ops->set_alarm) 138 else if (!rtc->ops->set_alarm)
139 err = -EINVAL; 139 err = -EINVAL;
140 else 140 else
141 err = rtc->ops->set_alarm(class_dev->dev, alarm); 141 err = rtc->ops->set_alarm(rtc->dev.parent, alarm);
142 142
143 mutex_unlock(&rtc->ops_lock); 143 mutex_unlock(&rtc->ops_lock);
144 return err; 144 return err;
@@ -147,16 +147,14 @@ EXPORT_SYMBOL_GPL(rtc_set_alarm);
147 147
148/** 148/**
149 * rtc_update_irq - report RTC periodic, alarm, and/or update irqs 149 * rtc_update_irq - report RTC periodic, alarm, and/or update irqs
150 * @class_dev: the rtc's class device 150 * @rtc: the rtc device
151 * @num: how many irqs are being reported (usually one) 151 * @num: how many irqs are being reported (usually one)
152 * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF 152 * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF
153 * Context: in_interrupt(), irqs blocked 153 * Context: in_interrupt(), irqs blocked
154 */ 154 */
155void rtc_update_irq(struct class_device *class_dev, 155void rtc_update_irq(struct rtc_device *rtc,
156 unsigned long num, unsigned long events) 156 unsigned long num, unsigned long events)
157{ 157{
158 struct rtc_device *rtc = to_rtc_device(class_dev);
159
160 spin_lock(&rtc->irq_lock); 158 spin_lock(&rtc->irq_lock);
161 rtc->irq_data = (rtc->irq_data + (num << 8)) | events; 159 rtc->irq_data = (rtc->irq_data + (num << 8)) | events;
162 spin_unlock(&rtc->irq_lock); 160 spin_unlock(&rtc->irq_lock);
@@ -171,40 +169,43 @@ void rtc_update_irq(struct class_device *class_dev,
171} 169}
172EXPORT_SYMBOL_GPL(rtc_update_irq); 170EXPORT_SYMBOL_GPL(rtc_update_irq);
173 171
174struct class_device *rtc_class_open(char *name) 172struct rtc_device *rtc_class_open(char *name)
175{ 173{
176 struct class_device *class_dev = NULL, 174 struct device *dev;
177 *class_dev_tmp; 175 struct rtc_device *rtc = NULL;
178 176
179 down(&rtc_class->sem); 177 down(&rtc_class->sem);
180 list_for_each_entry(class_dev_tmp, &rtc_class->children, node) { 178 list_for_each_entry(dev, &rtc_class->devices, node) {
181 if (strncmp(class_dev_tmp->class_id, name, BUS_ID_SIZE) == 0) { 179 if (strncmp(dev->bus_id, name, BUS_ID_SIZE) == 0) {
182 class_dev = class_device_get(class_dev_tmp); 180 dev = get_device(dev);
181 if (dev)
182 rtc = to_rtc_device(dev);
183 break; 183 break;
184 } 184 }
185 } 185 }
186 186
187 if (class_dev) { 187 if (rtc) {
188 if (!try_module_get(to_rtc_device(class_dev)->owner)) 188 if (!try_module_get(rtc->owner)) {
189 class_dev = NULL; 189 put_device(dev);
190 rtc = NULL;
191 }
190 } 192 }
191 up(&rtc_class->sem); 193 up(&rtc_class->sem);
192 194
193 return class_dev; 195 return rtc;
194} 196}
195EXPORT_SYMBOL_GPL(rtc_class_open); 197EXPORT_SYMBOL_GPL(rtc_class_open);
196 198
197void rtc_class_close(struct class_device *class_dev) 199void rtc_class_close(struct rtc_device *rtc)
198{ 200{
199 module_put(to_rtc_device(class_dev)->owner); 201 module_put(rtc->owner);
200 class_device_put(class_dev); 202 put_device(&rtc->dev);
201} 203}
202EXPORT_SYMBOL_GPL(rtc_class_close); 204EXPORT_SYMBOL_GPL(rtc_class_close);
203 205
204int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task) 206int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task)
205{ 207{
206 int retval = -EBUSY; 208 int retval = -EBUSY;
207 struct rtc_device *rtc = to_rtc_device(class_dev);
208 209
209 if (task == NULL || task->func == NULL) 210 if (task == NULL || task->func == NULL)
210 return -EINVAL; 211 return -EINVAL;
@@ -220,9 +221,8 @@ int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task)
220} 221}
221EXPORT_SYMBOL_GPL(rtc_irq_register); 222EXPORT_SYMBOL_GPL(rtc_irq_register);
222 223
223void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task) 224void rtc_irq_unregister(struct rtc_device *rtc, struct rtc_task *task)
224{ 225{
225 struct rtc_device *rtc = to_rtc_device(class_dev);
226 226
227 spin_lock_irq(&rtc->irq_task_lock); 227 spin_lock_irq(&rtc->irq_task_lock);
228 if (rtc->irq_task == task) 228 if (rtc->irq_task == task)
@@ -231,11 +231,10 @@ void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task)
231} 231}
232EXPORT_SYMBOL_GPL(rtc_irq_unregister); 232EXPORT_SYMBOL_GPL(rtc_irq_unregister);
233 233
234int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int enabled) 234int rtc_irq_set_state(struct rtc_device *rtc, struct rtc_task *task, int enabled)
235{ 235{
236 int err = 0; 236 int err = 0;
237 unsigned long flags; 237 unsigned long flags;
238 struct rtc_device *rtc = to_rtc_device(class_dev);
239 238
240 if (rtc->ops->irq_set_state == NULL) 239 if (rtc->ops->irq_set_state == NULL)
241 return -ENXIO; 240 return -ENXIO;
@@ -246,17 +245,16 @@ int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int
246 spin_unlock_irqrestore(&rtc->irq_task_lock, flags); 245 spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
247 246
248 if (err == 0) 247 if (err == 0)
249 err = rtc->ops->irq_set_state(class_dev->dev, enabled); 248 err = rtc->ops->irq_set_state(rtc->dev.parent, enabled);
250 249
251 return err; 250 return err;
252} 251}
253EXPORT_SYMBOL_GPL(rtc_irq_set_state); 252EXPORT_SYMBOL_GPL(rtc_irq_set_state);
254 253
255int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int freq) 254int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
256{ 255{
257 int err = 0; 256 int err = 0;
258 unsigned long flags; 257 unsigned long flags;
259 struct rtc_device *rtc = to_rtc_device(class_dev);
260 258
261 if (rtc->ops->irq_set_freq == NULL) 259 if (rtc->ops->irq_set_freq == NULL)
262 return -ENXIO; 260 return -ENXIO;
@@ -267,7 +265,7 @@ int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int
267 spin_unlock_irqrestore(&rtc->irq_task_lock, flags); 265 spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
268 266
269 if (err == 0) { 267 if (err == 0) {
270 err = rtc->ops->irq_set_freq(class_dev->dev, freq); 268 err = rtc->ops->irq_set_freq(rtc->dev.parent, freq);
271 if (err == 0) 269 if (err == 0)
272 rtc->irq_freq = freq; 270 rtc->irq_freq = freq;
273 } 271 }
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index ac0e68e2f025..33795e5a5595 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -263,7 +263,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id)
263 263
264 at91_sys_write(AT91_RTC_SCCR, rtsr); /* clear status reg */ 264 at91_sys_write(AT91_RTC_SCCR, rtsr); /* clear status reg */
265 265
266 rtc_update_irq(&rtc->class_dev, 1, events); 266 rtc_update_irq(rtc, 1, events);
267 267
268 pr_debug("%s(): num=%ld, events=0x%02lx\n", __FUNCTION__, 268 pr_debug("%s(): num=%ld, events=0x%02lx\n", __FUNCTION__,
269 events >> 8, events & 0x000000FF); 269 events >> 8, events & 0x000000FF);
@@ -348,21 +348,10 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
348 348
349/* AT91RM9200 RTC Power management control */ 349/* AT91RM9200 RTC Power management control */
350 350
351static struct timespec at91_rtc_delta;
352static u32 at91_rtc_imr; 351static u32 at91_rtc_imr;
353 352
354static int at91_rtc_suspend(struct platform_device *pdev, pm_message_t state) 353static int at91_rtc_suspend(struct platform_device *pdev, pm_message_t state)
355{ 354{
356 struct rtc_time tm;
357 struct timespec time;
358
359 time.tv_nsec = 0;
360
361 /* calculate time delta for suspend */
362 at91_rtc_readtime(&pdev->dev, &tm);
363 rtc_tm_to_time(&tm, &time.tv_sec);
364 save_time_delta(&at91_rtc_delta, &time);
365
366 /* this IRQ is shared with DBGU and other hardware which isn't 355 /* this IRQ is shared with DBGU and other hardware which isn't
367 * necessarily doing PM like we are... 356 * necessarily doing PM like we are...
368 */ 357 */
@@ -374,36 +363,17 @@ static int at91_rtc_suspend(struct platform_device *pdev, pm_message_t state)
374 else 363 else
375 at91_sys_write(AT91_RTC_IDR, at91_rtc_imr); 364 at91_sys_write(AT91_RTC_IDR, at91_rtc_imr);
376 } 365 }
377
378 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
379 1900 + tm.tm_year, tm.tm_mon, tm.tm_mday,
380 tm.tm_hour, tm.tm_min, tm.tm_sec);
381
382 return 0; 366 return 0;
383} 367}
384 368
385static int at91_rtc_resume(struct platform_device *pdev) 369static int at91_rtc_resume(struct platform_device *pdev)
386{ 370{
387 struct rtc_time tm;
388 struct timespec time;
389
390 time.tv_nsec = 0;
391
392 at91_rtc_readtime(&pdev->dev, &tm);
393 rtc_tm_to_time(&tm, &time.tv_sec);
394 restore_time_delta(&at91_rtc_delta, &time);
395
396 if (at91_rtc_imr) { 371 if (at91_rtc_imr) {
397 if (device_may_wakeup(&pdev->dev)) 372 if (device_may_wakeup(&pdev->dev))
398 disable_irq_wake(AT91_ID_SYS); 373 disable_irq_wake(AT91_ID_SYS);
399 else 374 else
400 at91_sys_write(AT91_RTC_IER, at91_rtc_imr); 375 at91_sys_write(AT91_RTC_IER, at91_rtc_imr);
401 } 376 }
402
403 pr_debug("%s(): %4d-%02d-%02d %02d:%02d:%02d\n", __FUNCTION__,
404 1900 + tm.tm_year, tm.tm_mon, tm.tm_mday,
405 tm.tm_hour, tm.tm_min, tm.tm_sec);
406
407 return 0; 377 return 0;
408} 378}
409#else 379#else
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 7c0d60910077..6085261aa2c1 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -46,6 +46,10 @@ struct cmos_rtc {
46 int irq; 46 int irq;
47 struct resource *iomem; 47 struct resource *iomem;
48 48
49 void (*wake_on)(struct device *);
50 void (*wake_off)(struct device *);
51
52 u8 enabled_wake;
49 u8 suspend_ctrl; 53 u8 suspend_ctrl;
50 54
51 /* newer hardware extends the original register set */ 55 /* newer hardware extends the original register set */
@@ -203,7 +207,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
203 rtc_intr = CMOS_READ(RTC_INTR_FLAGS); 207 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
204 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; 208 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
205 if (is_intr(rtc_intr)) 209 if (is_intr(rtc_intr))
206 rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr); 210 rtc_update_irq(cmos->rtc, 1, rtc_intr);
207 211
208 /* update alarm */ 212 /* update alarm */
209 CMOS_WRITE(hrs, RTC_HOURS_ALARM); 213 CMOS_WRITE(hrs, RTC_HOURS_ALARM);
@@ -223,7 +227,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
223 rtc_intr = CMOS_READ(RTC_INTR_FLAGS); 227 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
224 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; 228 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
225 if (is_intr(rtc_intr)) 229 if (is_intr(rtc_intr))
226 rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr); 230 rtc_update_irq(cmos->rtc, 1, rtc_intr);
227 } 231 }
228 232
229 spin_unlock_irq(&rtc_lock); 233 spin_unlock_irq(&rtc_lock);
@@ -304,7 +308,7 @@ cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
304 rtc_intr = CMOS_READ(RTC_INTR_FLAGS); 308 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
305 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; 309 rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
306 if (is_intr(rtc_intr)) 310 if (is_intr(rtc_intr))
307 rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr); 311 rtc_update_irq(cmos->rtc, 1, rtc_intr);
308 spin_unlock_irqrestore(&rtc_lock, flags); 312 spin_unlock_irqrestore(&rtc_lock, flags);
309 return 0; 313 return 0;
310} 314}
@@ -379,12 +383,12 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
379 return IRQ_NONE; 383 return IRQ_NONE;
380} 384}
381 385
382#ifdef CONFIG_PNPACPI 386#ifdef CONFIG_PNP
383#define is_pnpacpi() 1 387#define is_pnp() 1
384#define INITSECTION 388#define INITSECTION
385 389
386#else 390#else
387#define is_pnpacpi() 0 391#define is_pnp() 0
388#define INITSECTION __init 392#define INITSECTION __init
389#endif 393#endif
390 394
@@ -405,13 +409,20 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
405 cmos_rtc.irq = rtc_irq; 409 cmos_rtc.irq = rtc_irq;
406 cmos_rtc.iomem = ports; 410 cmos_rtc.iomem = ports;
407 411
408 /* For ACPI systems the info comes from the FADT. On others, 412 /* For ACPI systems extension info comes from the FADT. On others,
409 * board specific setup provides it as appropriate. 413 * board specific setup provides it as appropriate. Systems where
414 * the alarm IRQ isn't automatically a wakeup IRQ (like ACPI, and
415 * some almost-clones) can provide hooks to make that behave.
410 */ 416 */
411 if (info) { 417 if (info) {
412 cmos_rtc.day_alrm = info->rtc_day_alarm; 418 cmos_rtc.day_alrm = info->rtc_day_alarm;
413 cmos_rtc.mon_alrm = info->rtc_mon_alarm; 419 cmos_rtc.mon_alrm = info->rtc_mon_alarm;
414 cmos_rtc.century = info->rtc_century; 420 cmos_rtc.century = info->rtc_century;
421
422 if (info->wake_on && info->wake_off) {
423 cmos_rtc.wake_on = info->wake_on;
424 cmos_rtc.wake_off = info->wake_off;
425 }
415 } 426 }
416 427
417 cmos_rtc.rtc = rtc_device_register(driver_name, dev, 428 cmos_rtc.rtc = rtc_device_register(driver_name, dev,
@@ -427,14 +438,14 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
427 * REVISIT for non-x86 systems we may need to handle io memory 438 * REVISIT for non-x86 systems we may need to handle io memory
428 * resources: ioremap them, and request_mem_region(). 439 * resources: ioremap them, and request_mem_region().
429 */ 440 */
430 if (is_pnpacpi()) { 441 if (is_pnp()) {
431 retval = request_resource(&ioport_resource, ports); 442 retval = request_resource(&ioport_resource, ports);
432 if (retval < 0) { 443 if (retval < 0) {
433 dev_dbg(dev, "i/o registers already in use\n"); 444 dev_dbg(dev, "i/o registers already in use\n");
434 goto cleanup0; 445 goto cleanup0;
435 } 446 }
436 } 447 }
437 rename_region(ports, cmos_rtc.rtc->class_dev.class_id); 448 rename_region(ports, cmos_rtc.rtc->dev.bus_id);
438 449
439 spin_lock_irq(&rtc_lock); 450 spin_lock_irq(&rtc_lock);
440 451
@@ -470,8 +481,8 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
470 481
471 if (is_valid_irq(rtc_irq)) 482 if (is_valid_irq(rtc_irq))
472 retval = request_irq(rtc_irq, cmos_interrupt, IRQF_DISABLED, 483 retval = request_irq(rtc_irq, cmos_interrupt, IRQF_DISABLED,
473 cmos_rtc.rtc->class_dev.class_id, 484 cmos_rtc.rtc->dev.bus_id,
474 &cmos_rtc.rtc->class_dev); 485 cmos_rtc.rtc);
475 if (retval < 0) { 486 if (retval < 0) {
476 dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq); 487 dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
477 goto cleanup1; 488 goto cleanup1;
@@ -483,7 +494,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
483 */ 494 */
484 495
485 pr_info("%s: alarms up to one %s%s\n", 496 pr_info("%s: alarms up to one %s%s\n",
486 cmos_rtc.rtc->class_dev.class_id, 497 cmos_rtc.rtc->dev.bus_id,
487 is_valid_irq(rtc_irq) 498 is_valid_irq(rtc_irq)
488 ? (cmos_rtc.mon_alrm 499 ? (cmos_rtc.mon_alrm
489 ? "year" 500 ? "year"
@@ -520,12 +531,12 @@ static void __exit cmos_do_remove(struct device *dev)
520 531
521 cmos_do_shutdown(); 532 cmos_do_shutdown();
522 533
523 if (is_pnpacpi()) 534 if (is_pnp())
524 release_resource(cmos->iomem); 535 release_resource(cmos->iomem);
525 rename_region(cmos->iomem, NULL); 536 rename_region(cmos->iomem, NULL);
526 537
527 if (is_valid_irq(cmos->irq)) 538 if (is_valid_irq(cmos->irq))
528 free_irq(cmos->irq, &cmos_rtc.rtc->class_dev); 539 free_irq(cmos->irq, cmos_rtc.rtc);
529 540
530 rtc_device_unregister(cmos_rtc.rtc); 541 rtc_device_unregister(cmos_rtc.rtc);
531 542
@@ -555,16 +566,20 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg)
555 irqstat = CMOS_READ(RTC_INTR_FLAGS); 566 irqstat = CMOS_READ(RTC_INTR_FLAGS);
556 irqstat &= (tmp & RTC_IRQMASK) | RTC_IRQF; 567 irqstat &= (tmp & RTC_IRQMASK) | RTC_IRQF;
557 if (is_intr(irqstat)) 568 if (is_intr(irqstat))
558 rtc_update_irq(&cmos->rtc->class_dev, 1, irqstat); 569 rtc_update_irq(cmos->rtc, 1, irqstat);
559 } 570 }
560 spin_unlock_irq(&rtc_lock); 571 spin_unlock_irq(&rtc_lock);
561 572
562 /* ACPI HOOK: enable ACPI_EVENT_RTC when (tmp & RTC_AIE) 573 if (tmp & RTC_AIE) {
563 * ... it'd be best if we could do that under rtc_lock. 574 cmos->enabled_wake = 1;
564 */ 575 if (cmos->wake_on)
576 cmos->wake_on(dev);
577 else
578 enable_irq_wake(cmos->irq);
579 }
565 580
566 pr_debug("%s: suspend%s, ctrl %02x\n", 581 pr_debug("%s: suspend%s, ctrl %02x\n",
567 cmos_rtc.rtc->class_dev.class_id, 582 cmos_rtc.rtc->dev.bus_id,
568 (tmp & RTC_AIE) ? ", alarm may wake" : "", 583 (tmp & RTC_AIE) ? ", alarm may wake" : "",
569 tmp); 584 tmp);
570 585
@@ -576,26 +591,28 @@ static int cmos_resume(struct device *dev)
576 struct cmos_rtc *cmos = dev_get_drvdata(dev); 591 struct cmos_rtc *cmos = dev_get_drvdata(dev);
577 unsigned char tmp = cmos->suspend_ctrl; 592 unsigned char tmp = cmos->suspend_ctrl;
578 593
579 /* REVISIT: a mechanism to resync the system clock (jiffies)
580 * on resume should be portable between platforms ...
581 */
582
583 /* re-enable any irqs previously active */ 594 /* re-enable any irqs previously active */
584 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) { 595 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) {
585 596
586 /* ACPI HOOK: disable ACPI_EVENT_RTC when (tmp & RTC_AIE) */ 597 if (cmos->enabled_wake) {
598 if (cmos->wake_off)
599 cmos->wake_off(dev);
600 else
601 disable_irq_wake(cmos->irq);
602 cmos->enabled_wake = 0;
603 }
587 604
588 spin_lock_irq(&rtc_lock); 605 spin_lock_irq(&rtc_lock);
589 CMOS_WRITE(tmp, RTC_CONTROL); 606 CMOS_WRITE(tmp, RTC_CONTROL);
590 tmp = CMOS_READ(RTC_INTR_FLAGS); 607 tmp = CMOS_READ(RTC_INTR_FLAGS);
591 tmp &= (cmos->suspend_ctrl & RTC_IRQMASK) | RTC_IRQF; 608 tmp &= (cmos->suspend_ctrl & RTC_IRQMASK) | RTC_IRQF;
592 if (is_intr(tmp)) 609 if (is_intr(tmp))
593 rtc_update_irq(&cmos->rtc->class_dev, 1, tmp); 610 rtc_update_irq(cmos->rtc, 1, tmp);
594 spin_unlock_irq(&rtc_lock); 611 spin_unlock_irq(&rtc_lock);
595 } 612 }
596 613
597 pr_debug("%s: resume, ctrl %02x\n", 614 pr_debug("%s: resume, ctrl %02x\n",
598 cmos_rtc.rtc->class_dev.class_id, 615 cmos_rtc.rtc->dev.bus_id,
599 cmos->suspend_ctrl); 616 cmos->suspend_ctrl);
600 617
601 618
@@ -613,7 +630,7 @@ static int cmos_resume(struct device *dev)
613 * the device node will always be created as a PNPACPI device. 630 * the device node will always be created as a PNPACPI device.
614 */ 631 */
615 632
616#ifdef CONFIG_PNPACPI 633#ifdef CONFIG_PNP
617 634
618#include <linux/pnp.h> 635#include <linux/pnp.h>
619 636
@@ -684,11 +701,11 @@ static void __exit cmos_exit(void)
684} 701}
685module_exit(cmos_exit); 702module_exit(cmos_exit);
686 703
687#else /* no PNPACPI */ 704#else /* no PNP */
688 705
689/*----------------------------------------------------------------*/ 706/*----------------------------------------------------------------*/
690 707
691/* Platform setup should have set up an RTC device, when PNPACPI is 708/* Platform setup should have set up an RTC device, when PNP is
692 * unavailable ... this could happen even on (older) PCs. 709 * unavailable ... this could happen even on (older) PCs.
693 */ 710 */
694 711
@@ -734,7 +751,7 @@ static void __exit cmos_exit(void)
734module_exit(cmos_exit); 751module_exit(cmos_exit);
735 752
736 753
737#endif /* !PNPACPI */ 754#endif /* !PNP */
738 755
739MODULE_AUTHOR("David Brownell"); 756MODULE_AUTHOR("David Brownell");
740MODULE_DESCRIPTION("Driver for PC-style 'CMOS' RTCs"); 757MODULE_DESCRIPTION("Driver for PC-style 'CMOS' RTCs");
diff --git a/drivers/rtc/rtc-core.h b/drivers/rtc/rtc-core.h
new file mode 100644
index 000000000000..5f9df7430a22
--- /dev/null
+++ b/drivers/rtc/rtc-core.h
@@ -0,0 +1,70 @@
1#ifdef CONFIG_RTC_INTF_DEV
2
3extern void __init rtc_dev_init(void);
4extern void __exit rtc_dev_exit(void);
5extern void rtc_dev_prepare(struct rtc_device *rtc);
6extern void rtc_dev_add_device(struct rtc_device *rtc);
7extern void rtc_dev_del_device(struct rtc_device *rtc);
8
9#else
10
11static inline void rtc_dev_init(void)
12{
13}
14
15static inline void rtc_dev_exit(void)
16{
17}
18
19static inline void rtc_dev_prepare(struct rtc_device *rtc)
20{
21}
22
23static inline void rtc_dev_add_device(struct rtc_device *rtc)
24{
25}
26
27static inline void rtc_dev_del_device(struct rtc_device *rtc)
28{
29}
30
31#endif
32
33#ifdef CONFIG_RTC_INTF_PROC
34
35extern void rtc_proc_add_device(struct rtc_device *rtc);
36extern void rtc_proc_del_device(struct rtc_device *rtc);
37
38#else
39
40static inline void rtc_proc_add_device(struct rtc_device *rtc)
41{
42}
43
44static inline void rtc_proc_del_device(struct rtc_device *rtc)
45{
46}
47
48#endif
49
50#ifdef CONFIG_RTC_INTF_SYSFS
51
52extern void __init rtc_sysfs_init(struct class *);
53extern void rtc_sysfs_add_device(struct rtc_device *rtc);
54extern void rtc_sysfs_del_device(struct rtc_device *rtc);
55
56#else
57
58static inline void rtc_sysfs_init(struct class *rtc)
59{
60}
61
62static inline void rtc_sysfs_add_device(struct rtc_device *rtc)
63{
64}
65
66static inline void rtc_sysfs_del_device(struct rtc_device *rtc)
67{
68}
69
70#endif
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 137330b8636b..f4e5f0040ff7 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -13,8 +13,8 @@
13 13
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/rtc.h> 15#include <linux/rtc.h>
16#include "rtc-core.h"
16 17
17static struct class *rtc_dev_class;
18static dev_t rtc_devt; 18static dev_t rtc_devt;
19 19
20#define RTC_DEV_MAX 16 /* 16 RTCs should be enough for everyone... */ 20#define RTC_DEV_MAX 16 /* 16 RTCs should be enough for everyone... */
@@ -32,9 +32,9 @@ static int rtc_dev_open(struct inode *inode, struct file *file)
32 if (!(mutex_trylock(&rtc->char_lock))) 32 if (!(mutex_trylock(&rtc->char_lock)))
33 return -EBUSY; 33 return -EBUSY;
34 34
35 file->private_data = &rtc->class_dev; 35 file->private_data = rtc;
36 36
37 err = ops->open ? ops->open(rtc->class_dev.dev) : 0; 37 err = ops->open ? ops->open(rtc->dev.parent) : 0;
38 if (err == 0) { 38 if (err == 0) {
39 spin_lock_irq(&rtc->irq_lock); 39 spin_lock_irq(&rtc->irq_lock);
40 rtc->irq_data = 0; 40 rtc->irq_data = 0;
@@ -61,7 +61,7 @@ static void rtc_uie_task(struct work_struct *work)
61 int num = 0; 61 int num = 0;
62 int err; 62 int err;
63 63
64 err = rtc_read_time(&rtc->class_dev, &tm); 64 err = rtc_read_time(rtc, &tm);
65 65
66 local_irq_disable(); 66 local_irq_disable();
67 spin_lock(&rtc->irq_lock); 67 spin_lock(&rtc->irq_lock);
@@ -79,7 +79,7 @@ static void rtc_uie_task(struct work_struct *work)
79 } 79 }
80 spin_unlock(&rtc->irq_lock); 80 spin_unlock(&rtc->irq_lock);
81 if (num) 81 if (num)
82 rtc_update_irq(&rtc->class_dev, num, RTC_UF | RTC_IRQF); 82 rtc_update_irq(rtc, num, RTC_UF | RTC_IRQF);
83 local_irq_enable(); 83 local_irq_enable();
84} 84}
85static void rtc_uie_timer(unsigned long data) 85static void rtc_uie_timer(unsigned long data)
@@ -121,7 +121,7 @@ static int set_uie(struct rtc_device *rtc)
121 struct rtc_time tm; 121 struct rtc_time tm;
122 int err; 122 int err;
123 123
124 err = rtc_read_time(&rtc->class_dev, &tm); 124 err = rtc_read_time(rtc, &tm);
125 if (err) 125 if (err)
126 return err; 126 return err;
127 spin_lock_irq(&rtc->irq_lock); 127 spin_lock_irq(&rtc->irq_lock);
@@ -180,7 +180,7 @@ rtc_dev_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
180 if (ret == 0) { 180 if (ret == 0) {
181 /* Check for any data updates */ 181 /* Check for any data updates */
182 if (rtc->ops->read_callback) 182 if (rtc->ops->read_callback)
183 data = rtc->ops->read_callback(rtc->class_dev.dev, 183 data = rtc->ops->read_callback(rtc->dev.parent,
184 data); 184 data);
185 185
186 if (sizeof(int) != sizeof(long) && 186 if (sizeof(int) != sizeof(long) &&
@@ -210,8 +210,7 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
210 unsigned int cmd, unsigned long arg) 210 unsigned int cmd, unsigned long arg)
211{ 211{
212 int err = 0; 212 int err = 0;
213 struct class_device *class_dev = file->private_data; 213 struct rtc_device *rtc = file->private_data;
214 struct rtc_device *rtc = to_rtc_device(class_dev);
215 const struct rtc_class_ops *ops = rtc->ops; 214 const struct rtc_class_ops *ops = rtc->ops;
216 struct rtc_time tm; 215 struct rtc_time tm;
217 struct rtc_wkalrm alarm; 216 struct rtc_wkalrm alarm;
@@ -252,7 +251,7 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
252 251
253 /* try the driver's ioctl interface */ 252 /* try the driver's ioctl interface */
254 if (ops->ioctl) { 253 if (ops->ioctl) {
255 err = ops->ioctl(class_dev->dev, cmd, arg); 254 err = ops->ioctl(rtc->dev.parent, cmd, arg);
256 if (err != -ENOIOCTLCMD) 255 if (err != -ENOIOCTLCMD)
257 return err; 256 return err;
258 } 257 }
@@ -264,7 +263,7 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
264 263
265 switch (cmd) { 264 switch (cmd) {
266 case RTC_ALM_READ: 265 case RTC_ALM_READ:
267 err = rtc_read_alarm(class_dev, &alarm); 266 err = rtc_read_alarm(rtc, &alarm);
268 if (err < 0) 267 if (err < 0)
269 return err; 268 return err;
270 269
@@ -278,17 +277,53 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
278 277
279 alarm.enabled = 0; 278 alarm.enabled = 0;
280 alarm.pending = 0; 279 alarm.pending = 0;
281 alarm.time.tm_mday = -1;
282 alarm.time.tm_mon = -1;
283 alarm.time.tm_year = -1;
284 alarm.time.tm_wday = -1; 280 alarm.time.tm_wday = -1;
285 alarm.time.tm_yday = -1; 281 alarm.time.tm_yday = -1;
286 alarm.time.tm_isdst = -1; 282 alarm.time.tm_isdst = -1;
287 err = rtc_set_alarm(class_dev, &alarm); 283
284 /* RTC_ALM_SET alarms may be up to 24 hours in the future.
285 * Rather than expecting every RTC to implement "don't care"
286 * for day/month/year fields, just force the alarm to have
287 * the right values for those fields.
288 *
289 * RTC_WKALM_SET should be used instead. Not only does it
290 * eliminate the need for a separate RTC_AIE_ON call, it
291 * doesn't have the "alarm 23:59:59 in the future" race.
292 *
293 * NOTE: some legacy code may have used invalid fields as
294 * wildcards, exposing hardware "periodic alarm" capabilities.
295 * Not supported here.
296 */
297 {
298 unsigned long now, then;
299
300 err = rtc_read_time(rtc, &tm);
301 if (err < 0)
302 return err;
303 rtc_tm_to_time(&tm, &now);
304
305 alarm.time.tm_mday = tm.tm_mday;
306 alarm.time.tm_mon = tm.tm_mon;
307 alarm.time.tm_year = tm.tm_year;
308 err = rtc_valid_tm(&alarm.time);
309 if (err < 0)
310 return err;
311 rtc_tm_to_time(&alarm.time, &then);
312
313 /* alarm may need to wrap into tomorrow */
314 if (then < now) {
315 rtc_time_to_tm(now + 24 * 60 * 60, &tm);
316 alarm.time.tm_mday = tm.tm_mday;
317 alarm.time.tm_mon = tm.tm_mon;
318 alarm.time.tm_year = tm.tm_year;
319 }
320 }
321
322 err = rtc_set_alarm(rtc, &alarm);
288 break; 323 break;
289 324
290 case RTC_RD_TIME: 325 case RTC_RD_TIME:
291 err = rtc_read_time(class_dev, &tm); 326 err = rtc_read_time(rtc, &tm);
292 if (err < 0) 327 if (err < 0)
293 return err; 328 return err;
294 329
@@ -300,7 +335,7 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
300 if (copy_from_user(&tm, uarg, sizeof(tm))) 335 if (copy_from_user(&tm, uarg, sizeof(tm)))
301 return -EFAULT; 336 return -EFAULT;
302 337
303 err = rtc_set_time(class_dev, &tm); 338 err = rtc_set_time(rtc, &tm);
304 break; 339 break;
305 340
306 case RTC_IRQP_READ: 341 case RTC_IRQP_READ:
@@ -310,7 +345,7 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
310 345
311 case RTC_IRQP_SET: 346 case RTC_IRQP_SET:
312 if (ops->irq_set_freq) 347 if (ops->irq_set_freq)
313 err = rtc_irq_set_freq(class_dev, rtc->irq_task, arg); 348 err = rtc_irq_set_freq(rtc, rtc->irq_task, arg);
314 break; 349 break;
315 350
316#if 0 351#if 0
@@ -336,11 +371,11 @@ static int rtc_dev_ioctl(struct inode *inode, struct file *file,
336 if (copy_from_user(&alarm, uarg, sizeof(alarm))) 371 if (copy_from_user(&alarm, uarg, sizeof(alarm)))
337 return -EFAULT; 372 return -EFAULT;
338 373
339 err = rtc_set_alarm(class_dev, &alarm); 374 err = rtc_set_alarm(rtc, &alarm);
340 break; 375 break;
341 376
342 case RTC_WKALM_RD: 377 case RTC_WKALM_RD:
343 err = rtc_read_alarm(class_dev, &alarm); 378 err = rtc_read_alarm(rtc, &alarm);
344 if (err < 0) 379 if (err < 0)
345 return err; 380 return err;
346 381
@@ -372,7 +407,7 @@ static int rtc_dev_release(struct inode *inode, struct file *file)
372 clear_uie(rtc); 407 clear_uie(rtc);
373#endif 408#endif
374 if (rtc->ops->release) 409 if (rtc->ops->release)
375 rtc->ops->release(rtc->class_dev.dev); 410 rtc->ops->release(rtc->dev.parent);
376 411
377 mutex_unlock(&rtc->char_lock); 412 mutex_unlock(&rtc->char_lock);
378 return 0; 413 return 0;
@@ -397,17 +432,18 @@ static const struct file_operations rtc_dev_fops = {
397 432
398/* insertion/removal hooks */ 433/* insertion/removal hooks */
399 434
400static int rtc_dev_add_device(struct class_device *class_dev, 435void rtc_dev_prepare(struct rtc_device *rtc)
401 struct class_interface *class_intf)
402{ 436{
403 int err = 0; 437 if (!rtc_devt)
404 struct rtc_device *rtc = to_rtc_device(class_dev); 438 return;
405 439
406 if (rtc->id >= RTC_DEV_MAX) { 440 if (rtc->id >= RTC_DEV_MAX) {
407 dev_err(class_dev->dev, "too many RTCs\n"); 441 pr_debug("%s: too many RTC devices\n", rtc->name);
408 return -EINVAL; 442 return;
409 } 443 }
410 444
445 rtc->dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);
446
411 mutex_init(&rtc->char_lock); 447 mutex_init(&rtc->char_lock);
412 spin_lock_init(&rtc->irq_lock); 448 spin_lock_init(&rtc->irq_lock);
413 init_waitqueue_head(&rtc->irq_queue); 449 init_waitqueue_head(&rtc->irq_queue);
@@ -418,100 +454,36 @@ static int rtc_dev_add_device(struct class_device *class_dev,
418 454
419 cdev_init(&rtc->char_dev, &rtc_dev_fops); 455 cdev_init(&rtc->char_dev, &rtc_dev_fops);
420 rtc->char_dev.owner = rtc->owner; 456 rtc->char_dev.owner = rtc->owner;
457}
421 458
422 if (cdev_add(&rtc->char_dev, MKDEV(MAJOR(rtc_devt), rtc->id), 1)) { 459void rtc_dev_add_device(struct rtc_device *rtc)
423 dev_err(class_dev->dev, 460{
424 "failed to add char device %d:%d\n", 461 if (cdev_add(&rtc->char_dev, rtc->dev.devt, 1))
462 printk(KERN_WARNING "%s: failed to add char device %d:%d\n",
463 rtc->name, MAJOR(rtc_devt), rtc->id);
464 else
465 pr_debug("%s: dev (%d:%d)\n", rtc->name,
425 MAJOR(rtc_devt), rtc->id); 466 MAJOR(rtc_devt), rtc->id);
426 return -ENODEV;
427 }
428
429 rtc->rtc_dev = class_device_create(rtc_dev_class, NULL,
430 MKDEV(MAJOR(rtc_devt), rtc->id),
431 class_dev->dev, "rtc%d", rtc->id);
432 if (IS_ERR(rtc->rtc_dev)) {
433 dev_err(class_dev->dev, "cannot create rtc_dev device\n");
434 err = PTR_ERR(rtc->rtc_dev);
435 goto err_cdev_del;
436 }
437
438 dev_dbg(class_dev->dev, "rtc intf: dev (%d:%d)\n",
439 MAJOR(rtc->rtc_dev->devt),
440 MINOR(rtc->rtc_dev->devt));
441
442 return 0;
443
444err_cdev_del:
445
446 cdev_del(&rtc->char_dev);
447 return err;
448} 467}
449 468
450static void rtc_dev_remove_device(struct class_device *class_dev, 469void rtc_dev_del_device(struct rtc_device *rtc)
451 struct class_interface *class_intf)
452{ 470{
453 struct rtc_device *rtc = to_rtc_device(class_dev); 471 if (rtc->dev.devt)
454
455 if (rtc->rtc_dev) {
456 dev_dbg(class_dev->dev, "removing char %d:%d\n",
457 MAJOR(rtc->rtc_dev->devt),
458 MINOR(rtc->rtc_dev->devt));
459
460 class_device_unregister(rtc->rtc_dev);
461 cdev_del(&rtc->char_dev); 472 cdev_del(&rtc->char_dev);
462 }
463} 473}
464 474
465/* interface registration */ 475void __init rtc_dev_init(void)
466
467static struct class_interface rtc_dev_interface = {
468 .add = &rtc_dev_add_device,
469 .remove = &rtc_dev_remove_device,
470};
471
472static int __init rtc_dev_init(void)
473{ 476{
474 int err; 477 int err;
475 478
476 rtc_dev_class = class_create(THIS_MODULE, "rtc-dev");
477 if (IS_ERR(rtc_dev_class))
478 return PTR_ERR(rtc_dev_class);
479
480 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc"); 479 err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc");
481 if (err < 0) { 480 if (err < 0)
482 printk(KERN_ERR "%s: failed to allocate char dev region\n", 481 printk(KERN_ERR "%s: failed to allocate char dev region\n",
483 __FILE__); 482 __FILE__);
484 goto err_destroy_class;
485 }
486
487 err = rtc_interface_register(&rtc_dev_interface);
488 if (err < 0) {
489 printk(KERN_ERR "%s: failed to register the interface\n",
490 __FILE__);
491 goto err_unregister_chrdev;
492 }
493
494 return 0;
495
496err_unregister_chrdev:
497 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
498
499err_destroy_class:
500 class_destroy(rtc_dev_class);
501
502 return err;
503} 483}
504 484
505static void __exit rtc_dev_exit(void) 485void __exit rtc_dev_exit(void)
506{ 486{
507 class_interface_unregister(&rtc_dev_interface); 487 if (rtc_devt)
508 class_destroy(rtc_dev_class); 488 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
509 unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
510} 489}
511
512subsys_initcall(rtc_dev_init);
513module_exit(rtc_dev_exit);
514
515MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
516MODULE_DESCRIPTION("RTC class dev interface");
517MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index e27176c0e18f..afa64c7fa2e2 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -203,7 +203,7 @@ static irqreturn_t ds1553_rtc_interrupt(int irq, void *dev_id)
203 events |= RTC_UF; 203 events |= RTC_UF;
204 else 204 else
205 events |= RTC_AF; 205 events |= RTC_AF;
206 rtc_update_irq(&pdata->rtc->class_dev, 1, events); 206 rtc_update_irq(pdata->rtc, 1, events);
207 return IRQ_HANDLED; 207 return IRQ_HANDLED;
208} 208}
209 209
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 7bbc26a34bd2..ba795a4db1e9 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -117,85 +117,4 @@ int rtc_tm_to_time(struct rtc_time *tm, unsigned long *time)
117} 117}
118EXPORT_SYMBOL(rtc_tm_to_time); 118EXPORT_SYMBOL(rtc_tm_to_time);
119 119
120
121/* Merge the valid (i.e. non-negative) fields of alarm into the current
122 * time. If the valid alarm fields are earlier than the equivalent
123 * fields in the time, carry one into the least significant invalid
124 * field, so that the alarm expiry is in the future. It assumes that the
125 * least significant invalid field is more significant than the most
126 * significant valid field, and that the seconds field is valid.
127 *
128 * This is used by alarms that take relative (rather than absolute)
129 * times, and/or have a simple binary second counter instead of
130 * day/hour/minute/sec registers.
131 */
132void rtc_merge_alarm(struct rtc_time *now, struct rtc_time *alarm)
133{
134 int *alarmp = &alarm->tm_sec;
135 int *timep = &now->tm_sec;
136 int carry_into, i;
137
138 /* Ignore everything past the 6th element (tm_year). */
139 for (i = 5; i > 0; i--) {
140 if (alarmp[i] < 0)
141 alarmp[i] = timep[i];
142 else
143 break;
144 }
145
146 /* No carry needed if all fields are valid. */
147 if (i == 5)
148 return;
149
150 for (carry_into = i + 1; i >= 0; i--) {
151 if (alarmp[i] < timep[i])
152 break;
153
154 if (alarmp[i] > timep[i])
155 return;
156 }
157
158 switch (carry_into) {
159 case 1:
160 alarm->tm_min++;
161
162 if (alarm->tm_min < 60)
163 return;
164
165 alarm->tm_min = 0;
166 /* fall-through */
167
168 case 2:
169 alarm->tm_hour++;
170
171 if (alarm->tm_hour < 60)
172 return;
173
174 alarm->tm_hour = 0;
175 /* fall-through */
176
177 case 3:
178 alarm->tm_mday++;
179
180 if (alarm->tm_mday <= rtc_days_in_month[alarm->tm_mon])
181 return;
182
183 alarm->tm_mday = 1;
184 /* fall-through */
185
186 case 4:
187 alarm->tm_mon++;
188
189 if (alarm->tm_mon <= 12)
190 return;
191
192 alarm->tm_mon = 1;
193 /* fall-through */
194
195 case 5:
196 alarm->tm_year++;
197 }
198}
199EXPORT_SYMBOL(rtc_merge_alarm);
200
201MODULE_LICENSE("GPL"); 120MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
new file mode 100644
index 000000000000..eee4ee5bb75a
--- /dev/null
+++ b/drivers/rtc/rtc-max6900.c
@@ -0,0 +1,311 @@
1/*
2 * rtc class driver for the Maxim MAX6900 chip
3 *
4 * Author: Dale Farnsworth <dale@farnsworth.org>
5 *
6 * based on previously existing rtc class drivers
7 *
8 * 2007 (c) MontaVista, Software, Inc. This file is licensed under
9 * the terms of the GNU General Public License version 2. This program
10 * is licensed "as is" without any warranty of any kind, whether express
11 * or implied.
12 */
13
14#include <linux/module.h>
15#include <linux/i2c.h>
16#include <linux/bcd.h>
17#include <linux/rtc.h>
18#include <linux/delay.h>
19
20#define DRV_NAME "max6900"
21#define DRV_VERSION "0.1"
22
23/*
24 * register indices
25 */
26#define MAX6900_REG_SC 0 /* seconds 00-59 */
27#define MAX6900_REG_MN 1 /* minutes 00-59 */
28#define MAX6900_REG_HR 2 /* hours 00-23 */
29#define MAX6900_REG_DT 3 /* day of month 00-31 */
30#define MAX6900_REG_MO 4 /* month 01-12 */
31#define MAX6900_REG_DW 5 /* day of week 1-7 */
32#define MAX6900_REG_YR 6 /* year 00-99 */
33#define MAX6900_REG_CT 7 /* control */
34#define MAX6900_REG_LEN 8
35
36#define MAX6900_REG_CT_WP (1 << 7) /* Write Protect */
37
38/*
39 * register read/write commands
40 */
41#define MAX6900_REG_CONTROL_WRITE 0x8e
42#define MAX6900_REG_BURST_READ 0xbf
43#define MAX6900_REG_BURST_WRITE 0xbe
44#define MAX6900_REG_RESERVED_READ 0x96
45
46#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */
47
48#define MAX6900_I2C_ADDR 0xa0
49
50static unsigned short normal_i2c[] = {
51 MAX6900_I2C_ADDR >> 1,
52 I2C_CLIENT_END
53};
54
55I2C_CLIENT_INSMOD; /* defines addr_data */
56
57static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind);
58
59static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
60{
61 u8 reg_addr[1] = { MAX6900_REG_BURST_READ };
62 struct i2c_msg msgs[2] = {
63 {
64 .addr = client->addr,
65 .flags = 0, /* write */
66 .len = sizeof(reg_addr),
67 .buf = reg_addr
68 },
69 {
70 .addr = client->addr,
71 .flags = I2C_M_RD,
72 .len = MAX6900_REG_LEN,
73 .buf = buf
74 }
75 };
76 int rc;
77
78 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
79 if (rc != ARRAY_SIZE(msgs)) {
80 dev_err(&client->dev, "%s: register read failed\n",
81 __FUNCTION__);
82 return -EIO;
83 }
84 return 0;
85}
86
87static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
88{
89 u8 i2c_buf[MAX6900_REG_LEN + 1] = { MAX6900_REG_BURST_WRITE };
90 struct i2c_msg msgs[1] = {
91 {
92 .addr = client->addr,
93 .flags = 0, /* write */
94 .len = MAX6900_REG_LEN + 1,
95 .buf = i2c_buf
96 }
97 };
98 int rc;
99
100 memcpy(&i2c_buf[1], buf, MAX6900_REG_LEN);
101
102 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
103 if (rc != ARRAY_SIZE(msgs)) {
104 dev_err(&client->dev, "%s: register write failed\n",
105 __FUNCTION__);
106 return -EIO;
107 }
108 msleep(MAX6900_IDLE_TIME_AFTER_WRITE);
109 return 0;
110}
111
112static int max6900_i2c_validate_client(struct i2c_client *client)
113{
114 u8 regs[MAX6900_REG_LEN];
115 u8 zero_mask[MAX6900_REG_LEN] = {
116 0x80, /* seconds */
117 0x80, /* minutes */
118 0x40, /* hours */
119 0xc0, /* day of month */
120 0xe0, /* month */
121 0xf8, /* day of week */
122 0x00, /* year */
123 0x7f, /* control */
124 };
125 int i;
126 int rc;
127 int reserved;
128
129 reserved = i2c_smbus_read_byte_data(client, MAX6900_REG_RESERVED_READ);
130 if (reserved != 0x07)
131 return -ENODEV;
132
133 rc = max6900_i2c_read_regs(client, regs);
134 if (rc < 0)
135 return rc;
136
137 for (i = 0; i < MAX6900_REG_LEN; ++i) {
138 if (regs[i] & zero_mask[i])
139 return -ENODEV;
140 }
141
142 return 0;
143}
144
145static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
146{
147 int rc;
148 u8 regs[MAX6900_REG_LEN];
149
150 rc = max6900_i2c_read_regs(client, regs);
151 if (rc < 0)
152 return rc;
153
154 tm->tm_sec = BCD2BIN(regs[MAX6900_REG_SC]);
155 tm->tm_min = BCD2BIN(regs[MAX6900_REG_MN]);
156 tm->tm_hour = BCD2BIN(regs[MAX6900_REG_HR] & 0x3f);
157 tm->tm_mday = BCD2BIN(regs[MAX6900_REG_DT]);
158 tm->tm_mon = BCD2BIN(regs[MAX6900_REG_MO]) - 1;
159 tm->tm_year = BCD2BIN(regs[MAX6900_REG_YR]) + 100;
160 tm->tm_wday = BCD2BIN(regs[MAX6900_REG_DW]);
161
162 return 0;
163}
164
165static int max6900_i2c_clear_write_protect(struct i2c_client *client)
166{
167 int rc;
168 rc = i2c_smbus_write_byte_data (client, MAX6900_REG_CONTROL_WRITE, 0);
169 if (rc < 0) {
170 dev_err(&client->dev, "%s: control register write failed\n",
171 __FUNCTION__);
172 return -EIO;
173 }
174 return 0;
175}
176
177static int max6900_i2c_set_time(struct i2c_client *client,
178 struct rtc_time const *tm)
179{
180 u8 regs[MAX6900_REG_LEN];
181 int rc;
182
183 rc = max6900_i2c_clear_write_protect(client);
184 if (rc < 0)
185 return rc;
186
187 regs[MAX6900_REG_SC] = BIN2BCD(tm->tm_sec);
188 regs[MAX6900_REG_MN] = BIN2BCD(tm->tm_min);
189 regs[MAX6900_REG_HR] = BIN2BCD(tm->tm_hour);
190 regs[MAX6900_REG_DT] = BIN2BCD(tm->tm_mday);
191 regs[MAX6900_REG_MO] = BIN2BCD(tm->tm_mon + 1);
192 regs[MAX6900_REG_YR] = BIN2BCD(tm->tm_year - 100);
193 regs[MAX6900_REG_DW] = BIN2BCD(tm->tm_wday);
194 regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP; /* set write protect */
195
196 rc = max6900_i2c_write_regs(client, regs);
197 if (rc < 0)
198 return rc;
199
200 return 0;
201}
202
203static int max6900_rtc_read_time(struct device *dev, struct rtc_time *tm)
204{
205 return max6900_i2c_read_time(to_i2c_client(dev), tm);
206}
207
208static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm)
209{
210 return max6900_i2c_set_time(to_i2c_client(dev), tm);
211}
212
213static int max6900_attach_adapter(struct i2c_adapter *adapter)
214{
215 return i2c_probe(adapter, &addr_data, max6900_probe);
216}
217
218static int max6900_detach_client(struct i2c_client *client)
219{
220 struct rtc_device *const rtc = i2c_get_clientdata(client);
221
222 if (rtc)
223 rtc_device_unregister(rtc);
224
225 return i2c_detach_client(client);
226}
227
228static struct i2c_driver max6900_driver = {
229 .driver = {
230 .name = DRV_NAME,
231 },
232 .id = I2C_DRIVERID_MAX6900,
233 .attach_adapter = max6900_attach_adapter,
234 .detach_client = max6900_detach_client,
235};
236
237static const struct rtc_class_ops max6900_rtc_ops = {
238 .read_time = max6900_rtc_read_time,
239 .set_time = max6900_rtc_set_time,
240};
241
242static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind)
243{
244 int rc = 0;
245 struct i2c_client *client = NULL;
246 struct rtc_device *rtc = NULL;
247
248 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
249 rc = -ENODEV;
250 goto failout;
251 }
252
253 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
254 if (client == NULL) {
255 rc = -ENOMEM;
256 goto failout;
257 }
258
259 client->addr = addr;
260 client->adapter = adapter;
261 client->driver = &max6900_driver;
262 strlcpy(client->name, DRV_NAME, I2C_NAME_SIZE);
263
264 if (kind < 0) {
265 rc = max6900_i2c_validate_client(client);
266 if (rc < 0)
267 goto failout;
268 }
269
270 rc = i2c_attach_client(client);
271 if (rc < 0)
272 goto failout;
273
274 dev_info(&client->dev,
275 "chip found, driver version " DRV_VERSION "\n");
276
277 rtc = rtc_device_register(max6900_driver.driver.name,
278 &client->dev,
279 &max6900_rtc_ops, THIS_MODULE);
280 if (IS_ERR(rtc)) {
281 rc = PTR_ERR(rtc);
282 goto failout_detach;
283 }
284
285 i2c_set_clientdata(client, rtc);
286
287 return 0;
288
289failout_detach:
290 i2c_detach_client(client);
291failout:
292 kfree(client);
293 return rc;
294}
295
296static int __init max6900_init(void)
297{
298 return i2c_add_driver(&max6900_driver);
299}
300
301static void __exit max6900_exit(void)
302{
303 i2c_del_driver(&max6900_driver);
304}
305
306MODULE_DESCRIPTION("Maxim MAX6900 RTC driver");
307MODULE_LICENSE("GPL");
308MODULE_VERSION(DRV_VERSION);
309
310module_init(max6900_init);
311module_exit(max6900_exit);
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 9de8d67f4f8d..a2f84f169588 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -124,7 +124,7 @@ static void rtc_wait_not_busy(void)
124 /* now we have ~15 usec to read/write various registers */ 124 /* now we have ~15 usec to read/write various registers */
125} 125}
126 126
127static irqreturn_t rtc_irq(int irq, void *class_dev) 127static irqreturn_t rtc_irq(int irq, void *rtc)
128{ 128{
129 unsigned long events = 0; 129 unsigned long events = 0;
130 u8 irq_data; 130 u8 irq_data;
@@ -141,7 +141,7 @@ static irqreturn_t rtc_irq(int irq, void *class_dev)
141 if (irq_data & OMAP_RTC_STATUS_1S_EVENT) 141 if (irq_data & OMAP_RTC_STATUS_1S_EVENT)
142 events |= RTC_IRQF | RTC_UF; 142 events |= RTC_IRQF | RTC_UF;
143 143
144 rtc_update_irq(class_dev, 1, events); 144 rtc_update_irq(rtc, 1, events);
145 145
146 return IRQ_HANDLED; 146 return IRQ_HANDLED;
147} 147}
@@ -289,34 +289,6 @@ static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
289{ 289{
290 u8 reg; 290 u8 reg;
291 291
292 /* Much userspace code uses RTC_ALM_SET, thus "don't care" for
293 * day/month/year specifies alarms up to 24 hours in the future.
294 * So we need to handle that ... but let's ignore the "don't care"
295 * values for hours/minutes/seconds.
296 */
297 if (alm->time.tm_mday <= 0
298 && alm->time.tm_mon < 0
299 && alm->time.tm_year < 0) {
300 struct rtc_time tm;
301 unsigned long now, then;
302
303 omap_rtc_read_time(dev, &tm);
304 rtc_tm_to_time(&tm, &now);
305
306 alm->time.tm_mday = tm.tm_mday;
307 alm->time.tm_mon = tm.tm_mon;
308 alm->time.tm_year = tm.tm_year;
309 rtc_tm_to_time(&alm->time, &then);
310
311 /* sometimes the alarm wraps into tomorrow */
312 if (then < now) {
313 rtc_time_to_tm(now + 24 * 60 * 60, &tm);
314 alm->time.tm_mday = tm.tm_mday;
315 alm->time.tm_mon = tm.tm_mon;
316 alm->time.tm_year = tm.tm_year;
317 }
318 }
319
320 if (tm2bcd(&alm->time) < 0) 292 if (tm2bcd(&alm->time) < 0)
321 return -EINVAL; 293 return -EINVAL;
322 294
@@ -399,7 +371,7 @@ static int __devinit omap_rtc_probe(struct platform_device *pdev)
399 goto fail; 371 goto fail;
400 } 372 }
401 platform_set_drvdata(pdev, rtc); 373 platform_set_drvdata(pdev, rtc);
402 class_set_devdata(&rtc->class_dev, mem); 374 dev_set_drvdata(&rtc->dev, mem);
403 375
404 /* clear pending irqs, and set 1/second periodic, 376 /* clear pending irqs, and set 1/second periodic,
405 * which we'll use instead of update irqs 377 * which we'll use instead of update irqs
@@ -418,13 +390,13 @@ static int __devinit omap_rtc_probe(struct platform_device *pdev)
418 390
419 /* handle periodic and alarm irqs */ 391 /* handle periodic and alarm irqs */
420 if (request_irq(omap_rtc_timer, rtc_irq, IRQF_DISABLED, 392 if (request_irq(omap_rtc_timer, rtc_irq, IRQF_DISABLED,
421 rtc->class_dev.class_id, &rtc->class_dev)) { 393 rtc->dev.bus_id, rtc)) {
422 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n", 394 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n",
423 pdev->name, omap_rtc_timer); 395 pdev->name, omap_rtc_timer);
424 goto fail0; 396 goto fail0;
425 } 397 }
426 if (request_irq(omap_rtc_alarm, rtc_irq, IRQF_DISABLED, 398 if (request_irq(omap_rtc_alarm, rtc_irq, IRQF_DISABLED,
427 rtc->class_dev.class_id, &rtc->class_dev)) { 399 rtc->dev.bus_id, rtc)) {
428 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n", 400 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n",
429 pdev->name, omap_rtc_alarm); 401 pdev->name, omap_rtc_alarm);
430 goto fail1; 402 goto fail1;
@@ -481,26 +453,17 @@ static int __devexit omap_rtc_remove(struct platform_device *pdev)
481 free_irq(omap_rtc_timer, rtc); 453 free_irq(omap_rtc_timer, rtc);
482 free_irq(omap_rtc_alarm, rtc); 454 free_irq(omap_rtc_alarm, rtc);
483 455
484 release_resource(class_get_devdata(&rtc->class_dev)); 456 release_resource(dev_get_drvdata(&rtc->dev));
485 rtc_device_unregister(rtc); 457 rtc_device_unregister(rtc);
486 return 0; 458 return 0;
487} 459}
488 460
489#ifdef CONFIG_PM 461#ifdef CONFIG_PM
490 462
491static struct timespec rtc_delta;
492static u8 irqstat; 463static u8 irqstat;
493 464
494static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state) 465static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state)
495{ 466{
496 struct rtc_time rtc_tm;
497 struct timespec time;
498
499 time.tv_nsec = 0;
500 omap_rtc_read_time(NULL, &rtc_tm);
501 rtc_tm_to_time(&rtc_tm, &time.tv_sec);
502
503 save_time_delta(&rtc_delta, &time);
504 irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG); 467 irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG);
505 468
506 /* FIXME the RTC alarm is not currently acting as a wakeup event 469 /* FIXME the RTC alarm is not currently acting as a wakeup event
@@ -517,14 +480,6 @@ static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state)
517 480
518static int omap_rtc_resume(struct platform_device *pdev) 481static int omap_rtc_resume(struct platform_device *pdev)
519{ 482{
520 struct rtc_time rtc_tm;
521 struct timespec time;
522
523 time.tv_nsec = 0;
524 omap_rtc_read_time(NULL, &rtc_tm);
525 rtc_tm_to_time(&rtc_tm, &time.tv_sec);
526
527 restore_time_delta(&rtc_delta, &time);
528 if (device_may_wakeup(&pdev->dev)) 483 if (device_may_wakeup(&pdev->dev))
529 disable_irq_wake(omap_rtc_alarm); 484 disable_irq_wake(omap_rtc_alarm);
530 else 485 else
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index f13daa9fecaa..e4bf68ca96f7 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -51,7 +51,7 @@ static irqreturn_t pl031_interrupt(int irq, void *dev_id)
51{ 51{
52 struct rtc_device *rtc = dev_id; 52 struct rtc_device *rtc = dev_id;
53 53
54 rtc_update_irq(&rtc->class_dev, 1, RTC_AF); 54 rtc_update_irq(rtc, 1, RTC_AF);
55 55
56 return IRQ_HANDLED; 56 return IRQ_HANDLED;
57} 57}
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
index 1bd624fc685c..8d300e6d0d9e 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/rtc-proc.c
@@ -16,18 +16,18 @@
16#include <linux/proc_fs.h> 16#include <linux/proc_fs.h>
17#include <linux/seq_file.h> 17#include <linux/seq_file.h>
18 18
19static struct class_device *rtc_dev = NULL; 19#include "rtc-core.h"
20static DEFINE_MUTEX(rtc_lock); 20
21 21
22static int rtc_proc_show(struct seq_file *seq, void *offset) 22static int rtc_proc_show(struct seq_file *seq, void *offset)
23{ 23{
24 int err; 24 int err;
25 struct class_device *class_dev = seq->private; 25 struct rtc_device *rtc = seq->private;
26 const struct rtc_class_ops *ops = to_rtc_device(class_dev)->ops; 26 const struct rtc_class_ops *ops = rtc->ops;
27 struct rtc_wkalrm alrm; 27 struct rtc_wkalrm alrm;
28 struct rtc_time tm; 28 struct rtc_time tm;
29 29
30 err = rtc_read_time(class_dev, &tm); 30 err = rtc_read_time(rtc, &tm);
31 if (err == 0) { 31 if (err == 0) {
32 seq_printf(seq, 32 seq_printf(seq,
33 "rtc_time\t: %02d:%02d:%02d\n" 33 "rtc_time\t: %02d:%02d:%02d\n"
@@ -36,7 +36,7 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
36 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); 36 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
37 } 37 }
38 38
39 err = rtc_read_alarm(class_dev, &alrm); 39 err = rtc_read_alarm(rtc, &alrm);
40 if (err == 0) { 40 if (err == 0) {
41 seq_printf(seq, "alrm_time\t: "); 41 seq_printf(seq, "alrm_time\t: ");
42 if ((unsigned int)alrm.time.tm_hour <= 24) 42 if ((unsigned int)alrm.time.tm_hour <= 24)
@@ -74,19 +74,19 @@ static int rtc_proc_show(struct seq_file *seq, void *offset)
74 seq_printf(seq, "24hr\t\t: yes\n"); 74 seq_printf(seq, "24hr\t\t: yes\n");
75 75
76 if (ops->proc) 76 if (ops->proc)
77 ops->proc(class_dev->dev, seq); 77 ops->proc(rtc->dev.parent, seq);
78 78
79 return 0; 79 return 0;
80} 80}
81 81
82static int rtc_proc_open(struct inode *inode, struct file *file) 82static int rtc_proc_open(struct inode *inode, struct file *file)
83{ 83{
84 struct class_device *class_dev = PDE(inode)->data; 84 struct rtc_device *rtc = PDE(inode)->data;
85 85
86 if (!try_module_get(THIS_MODULE)) 86 if (!try_module_get(THIS_MODULE))
87 return -ENODEV; 87 return -ENODEV;
88 88
89 return single_open(file, rtc_proc_show, class_dev); 89 return single_open(file, rtc_proc_show, rtc);
90} 90}
91 91
92static int rtc_proc_release(struct inode *inode, struct file *file) 92static int rtc_proc_release(struct inode *inode, struct file *file)
@@ -103,62 +103,22 @@ static const struct file_operations rtc_proc_fops = {
103 .release = rtc_proc_release, 103 .release = rtc_proc_release,
104}; 104};
105 105
106static int rtc_proc_add_device(struct class_device *class_dev, 106void rtc_proc_add_device(struct rtc_device *rtc)
107 struct class_interface *class_intf)
108{ 107{
109 mutex_lock(&rtc_lock); 108 if (rtc->id == 0) {
110 if (rtc_dev == NULL) {
111 struct proc_dir_entry *ent; 109 struct proc_dir_entry *ent;
112 110
113 rtc_dev = class_dev;
114
115 ent = create_proc_entry("driver/rtc", 0, NULL); 111 ent = create_proc_entry("driver/rtc", 0, NULL);
116 if (ent) { 112 if (ent) {
117 struct rtc_device *rtc = to_rtc_device(class_dev);
118
119 ent->proc_fops = &rtc_proc_fops; 113 ent->proc_fops = &rtc_proc_fops;
120 ent->owner = rtc->owner; 114 ent->owner = rtc->owner;
121 ent->data = class_dev; 115 ent->data = rtc;
122
123 dev_dbg(class_dev->dev, "rtc intf: proc\n");
124 } 116 }
125 else
126 rtc_dev = NULL;
127 } 117 }
128 mutex_unlock(&rtc_lock);
129
130 return 0;
131} 118}
132 119
133static void rtc_proc_remove_device(struct class_device *class_dev, 120void rtc_proc_del_device(struct rtc_device *rtc)
134 struct class_interface *class_intf)
135{ 121{
136 mutex_lock(&rtc_lock); 122 if (rtc->id == 0)
137 if (rtc_dev == class_dev) {
138 remove_proc_entry("driver/rtc", NULL); 123 remove_proc_entry("driver/rtc", NULL);
139 rtc_dev = NULL;
140 }
141 mutex_unlock(&rtc_lock);
142}
143
144static struct class_interface rtc_proc_interface = {
145 .add = &rtc_proc_add_device,
146 .remove = &rtc_proc_remove_device,
147};
148
149static int __init rtc_proc_init(void)
150{
151 return rtc_interface_register(&rtc_proc_interface);
152} 124}
153
154static void __exit rtc_proc_exit(void)
155{
156 class_interface_unregister(&rtc_proc_interface);
157}
158
159subsys_initcall(rtc_proc_init);
160module_exit(rtc_proc_exit);
161
162MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
163MODULE_DESCRIPTION("RTC class proc interface");
164MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
new file mode 100644
index 000000000000..66eb133bf5fd
--- /dev/null
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -0,0 +1,423 @@
1/*
2 * Ricoh RS5C313 RTC device/driver
3 * Copyright (C) 2007 Nobuhiro Iwamatsu
4 *
5 * 2005-09-19 modifed by kogiidena
6 *
7 * Based on the old drivers/char/rs5c313_rtc.c by:
8 * Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
9 * Copyright (C) 1999 Tetsuya Okada & Niibe Yutaka
10 *
11 * Based on code written by Paul Gortmaker.
12 * Copyright (C) 1996 Paul Gortmaker
13 *
14 * This file is subject to the terms and conditions of the GNU General Public
15 * License. See the file "COPYING" in the main directory of this archive
16 * for more details.
17 *
18 * Based on other minimal char device drivers, like Alan's
19 * watchdog, Ted's random, etc. etc.
20 *
21 * 1.07 Paul Gortmaker.
22 * 1.08 Miquel van Smoorenburg: disallow certain things on the
23 * DEC Alpha as the CMOS clock is also used for other things.
24 * 1.09 Nikita Schmidt: epoch support and some Alpha cleanup.
25 * 1.09a Pete Zaitcev: Sun SPARC
26 * 1.09b Jeff Garzik: Modularize, init cleanup
27 * 1.09c Jeff Garzik: SMP cleanup
28 * 1.10 Paul Barton-Davis: add support for async I/O
29 * 1.10a Andrea Arcangeli: Alpha updates
30 * 1.10b Andrew Morton: SMP lock fix
31 * 1.10c Cesar Barros: SMP locking fixes and cleanup
32 * 1.10d Paul Gortmaker: delete paranoia check in rtc_exit
33 * 1.10e Maciej W. Rozycki: Handle DECstation's year weirdness.
34 * 1.11 Takashi Iwai: Kernel access functions
35 * rtc_register/rtc_unregister/rtc_control
36 * 1.11a Daniele Bellucci: Audit create_proc_read_entry in rtc_init
37 * 1.12 Venkatesh Pallipadi: Hooks for emulating rtc on HPET base-timer
38 * CONFIG_HPET_EMULATE_RTC
39 * 1.13 Nobuhiro Iwamatsu: Updata driver.
40 */
41
42#include <linux/module.h>
43#include <linux/err.h>
44#include <linux/rtc.h>
45#include <linux/platform_device.h>
46#include <linux/bcd.h>
47#include <linux/delay.h>
48#include <asm/io.h>
49
50#define DRV_NAME "rs5c313"
51#define DRV_VERSION "1.13"
52
53#ifdef CONFIG_SH_LANDISK
54/*****************************************************/
55/* LANDISK dependence part of RS5C313 */
56/*****************************************************/
57
58#define SCSMR1 0xFFE00000
59#define SCSCR1 0xFFE00008
60#define SCSMR1_CA 0x80
61#define SCSCR1_CKE 0x03
62#define SCSPTR1 0xFFE0001C
63#define SCSPTR1_EIO 0x80
64#define SCSPTR1_SPB1IO 0x08
65#define SCSPTR1_SPB1DT 0x04
66#define SCSPTR1_SPB0IO 0x02
67#define SCSPTR1_SPB0DT 0x01
68
69#define SDA_OEN SCSPTR1_SPB1IO
70#define SDA SCSPTR1_SPB1DT
71#define SCL_OEN SCSPTR1_SPB0IO
72#define SCL SCSPTR1_SPB0DT
73
74/* RICOH RS5C313 CE port */
75#define RS5C313_CE 0xB0000003
76
77/* RICOH RS5C313 CE port bit */
78#define RS5C313_CE_RTCCE 0x02
79
80/* SCSPTR1 data */
81unsigned char scsptr1_data;
82
83#define RS5C313_CEENABLE ctrl_outb(RS5C313_CE_RTCCE, RS5C313_CE);
84#define RS5C313_CEDISABLE ctrl_outb(0x00, RS5C313_CE)
85#define RS5C313_MISCOP ctrl_outb(0x02, 0xB0000008)
86
87static void rs5c313_init_port(void)
88{
89 /* Set SCK as I/O port and Initialize SCSPTR1 data & I/O port. */
90 ctrl_outb(ctrl_inb(SCSMR1) & ~SCSMR1_CA, SCSMR1);
91 ctrl_outb(ctrl_inb(SCSCR1) & ~SCSCR1_CKE, SCSCR1);
92
93 /* And Initialize SCL for RS5C313 clock */
94 scsptr1_data = ctrl_inb(SCSPTR1) | SCL; /* SCL:H */
95 ctrl_outb(scsptr1_data, SCSPTR1);
96 scsptr1_data = ctrl_inb(SCSPTR1) | SCL_OEN; /* SCL output enable */
97 ctrl_outb(scsptr1_data, SCSPTR1);
98 RS5C313_CEDISABLE; /* CE:L */
99}
100
101static void rs5c313_write_data(unsigned char data)
102{
103 int i;
104
105 for (i = 0; i < 8; i++) {
106 /* SDA:Write Data */
107 scsptr1_data = (scsptr1_data & ~SDA) |
108 ((((0x80 >> i) & data) >> (7 - i)) << 2);
109 ctrl_outb(scsptr1_data, SCSPTR1);
110 if (i == 0) {
111 scsptr1_data |= SDA_OEN; /* SDA:output enable */
112 ctrl_outb(scsptr1_data, SCSPTR1);
113 }
114 ndelay(700);
115 scsptr1_data &= ~SCL; /* SCL:L */
116 ctrl_outb(scsptr1_data, SCSPTR1);
117 ndelay(700);
118 scsptr1_data |= SCL; /* SCL:H */
119 ctrl_outb(scsptr1_data, SCSPTR1);
120 }
121
122 scsptr1_data &= ~SDA_OEN; /* SDA:output disable */
123 ctrl_outb(scsptr1_data, SCSPTR1);
124}
125
126static unsigned char rs5c313_read_data(void)
127{
128 int i;
129 unsigned char data = 0;
130
131 for (i = 0; i < 8; i++) {
132 ndelay(700);
133 /* SDA:Read Data */
134 data |= ((ctrl_inb(SCSPTR1) & SDA) >> 2) << (7 - i);
135 scsptr1_data &= ~SCL; /* SCL:L */
136 ctrl_outb(scsptr1_data, SCSPTR1);
137 ndelay(700);
138 scsptr1_data |= SCL; /* SCL:H */
139 ctrl_outb(scsptr1_data, SCSPTR1);
140 }
141 return data & 0x0F;
142}
143
144#endif /* CONFIG_SH_LANDISK */
145
146/*****************************************************/
147/* machine independence part of RS5C313 */
148/*****************************************************/
149
150/* RICOH RS5C313 address */
151#define RS5C313_ADDR_SEC 0x00
152#define RS5C313_ADDR_SEC10 0x01
153#define RS5C313_ADDR_MIN 0x02
154#define RS5C313_ADDR_MIN10 0x03
155#define RS5C313_ADDR_HOUR 0x04
156#define RS5C313_ADDR_HOUR10 0x05
157#define RS5C313_ADDR_WEEK 0x06
158#define RS5C313_ADDR_INTINTVREG 0x07
159#define RS5C313_ADDR_DAY 0x08
160#define RS5C313_ADDR_DAY10 0x09
161#define RS5C313_ADDR_MON 0x0A
162#define RS5C313_ADDR_MON10 0x0B
163#define RS5C313_ADDR_YEAR 0x0C
164#define RS5C313_ADDR_YEAR10 0x0D
165#define RS5C313_ADDR_CNTREG 0x0E
166#define RS5C313_ADDR_TESTREG 0x0F
167
168/* RICOH RS5C313 control register */
169#define RS5C313_CNTREG_ADJ_BSY 0x01
170#define RS5C313_CNTREG_WTEN_XSTP 0x02
171#define RS5C313_CNTREG_12_24 0x04
172#define RS5C313_CNTREG_CTFG 0x08
173
174/* RICOH RS5C313 test register */
175#define RS5C313_TESTREG_TEST 0x01
176
177/* RICOH RS5C313 control bit */
178#define RS5C313_CNTBIT_READ 0x40
179#define RS5C313_CNTBIT_AD 0x20
180#define RS5C313_CNTBIT_DT 0x10
181
182static unsigned char rs5c313_read_reg(unsigned char addr)
183{
184
185 rs5c313_write_data(addr | RS5C313_CNTBIT_READ | RS5C313_CNTBIT_AD);
186 return rs5c313_read_data();
187}
188
189static void rs5c313_write_reg(unsigned char addr, unsigned char data)
190{
191 data &= 0x0f;
192 rs5c313_write_data(addr | RS5C313_CNTBIT_AD);
193 rs5c313_write_data(data | RS5C313_CNTBIT_DT);
194 return;
195}
196
197static inline unsigned char rs5c313_read_cntreg(void)
198{
199 return rs5c313_read_reg(RS5C313_ADDR_CNTREG);
200}
201
202static inline void rs5c313_write_cntreg(unsigned char data)
203{
204 rs5c313_write_reg(RS5C313_ADDR_CNTREG, data);
205}
206
207static inline void rs5c313_write_intintvreg(unsigned char data)
208{
209 rs5c313_write_reg(RS5C313_ADDR_INTINTVREG, data);
210}
211
212static int rs5c313_rtc_read_time(struct device *dev, struct rtc_time *tm)
213{
214 int data;
215 int cnt;
216
217 cnt = 0;
218 while (1) {
219 RS5C313_CEENABLE; /* CE:H */
220
221 /* Initialize control reg. 24 hour */
222 rs5c313_write_cntreg(0x04);
223
224 if (!(rs5c313_read_cntreg() & RS5C313_CNTREG_ADJ_BSY))
225 break;
226
227 RS5C313_CEDISABLE;
228 ndelay(700); /* CE:L */
229
230 if (cnt++ > 100) {
231 dev_err(dev, "%s: timeout error\n", __FUNCTION__);
232 return -EIO;
233 }
234 }
235
236 data = rs5c313_read_reg(RS5C313_ADDR_SEC);
237 data |= (rs5c313_read_reg(RS5C313_ADDR_SEC10) << 4);
238 tm->tm_sec = BCD2BIN(data);
239
240 data = rs5c313_read_reg(RS5C313_ADDR_MIN);
241 data |= (rs5c313_read_reg(RS5C313_ADDR_MIN10) << 4);
242 tm->tm_min = BCD2BIN(data);
243
244 data = rs5c313_read_reg(RS5C313_ADDR_HOUR);
245 data |= (rs5c313_read_reg(RS5C313_ADDR_HOUR10) << 4);
246 tm->tm_hour = BCD2BIN(data);
247
248 data = rs5c313_read_reg(RS5C313_ADDR_DAY);
249 data |= (rs5c313_read_reg(RS5C313_ADDR_DAY10) << 4);
250 tm->tm_mday = BCD2BIN(data);
251
252 data = rs5c313_read_reg(RS5C313_ADDR_MON);
253 data |= (rs5c313_read_reg(RS5C313_ADDR_MON10) << 4);
254 tm->tm_mon = BCD2BIN(data) - 1;
255
256 data = rs5c313_read_reg(RS5C313_ADDR_YEAR);
257 data |= (rs5c313_read_reg(RS5C313_ADDR_YEAR10) << 4);
258 tm->tm_year = BCD2BIN(data);
259
260 if (tm->tm_year < 70)
261 tm->tm_year += 100;
262
263 data = rs5c313_read_reg(RS5C313_ADDR_WEEK);
264 tm->tm_wday = BCD2BIN(data);
265
266 RS5C313_CEDISABLE;
267 ndelay(700); /* CE:L */
268
269 return 0;
270}
271
272static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm)
273{
274 int data;
275 int cnt;
276
277 cnt = 0;
278 /* busy check. */
279 while (1) {
280 RS5C313_CEENABLE; /* CE:H */
281
282 /* Initiatlize control reg. 24 hour */
283 rs5c313_write_cntreg(0x04);
284
285 if (!(rs5c313_read_cntreg() & RS5C313_CNTREG_ADJ_BSY))
286 break;
287 RS5C313_MISCOP;
288 RS5C313_CEDISABLE;
289 ndelay(700); /* CE:L */
290
291 if (cnt++ > 100) {
292 dev_err(dev, "%s: timeout error\n", __FUNCTION__);
293 return -EIO;
294 }
295 }
296
297 data = BIN2BCD(tm->tm_sec);
298 rs5c313_write_reg(RS5C313_ADDR_SEC, data);
299 rs5c313_write_reg(RS5C313_ADDR_SEC10, (data >> 4));
300
301 data = BIN2BCD(tm->tm_min);
302 rs5c313_write_reg(RS5C313_ADDR_MIN, data );
303 rs5c313_write_reg(RS5C313_ADDR_MIN10, (data >> 4));
304
305 data = BIN2BCD(tm->tm_hour);
306 rs5c313_write_reg(RS5C313_ADDR_HOUR, data);
307 rs5c313_write_reg(RS5C313_ADDR_HOUR10, (data >> 4));
308
309 data = BIN2BCD(tm->tm_mday);
310 rs5c313_write_reg(RS5C313_ADDR_DAY, data);
311 rs5c313_write_reg(RS5C313_ADDR_DAY10, (data>> 4));
312
313 data = BIN2BCD(tm->tm_mon + 1);
314 rs5c313_write_reg(RS5C313_ADDR_MON, data);
315 rs5c313_write_reg(RS5C313_ADDR_MON10, (data >> 4));
316
317 data = BIN2BCD(tm->tm_year % 100);
318 rs5c313_write_reg(RS5C313_ADDR_YEAR, data);
319 rs5c313_write_reg(RS5C313_ADDR_YEAR10, (data >> 4));
320
321 data = BIN2BCD(tm->tm_wday);
322 rs5c313_write_reg(RS5C313_ADDR_WEEK, data);
323
324 RS5C313_CEDISABLE; /* CE:H */
325 ndelay(700);
326
327 return 0;
328}
329
330static void rs5c313_check_xstp_bit(void)
331{
332 struct rtc_time tm;
333 int cnt;
334
335 RS5C313_CEENABLE; /* CE:H */
336 if (rs5c313_read_cntreg() & RS5C313_CNTREG_WTEN_XSTP) {
337 /* INT interval reg. OFF */
338 rs5c313_write_intintvreg(0x00);
339 /* Initialize control reg. 24 hour & adjust */
340 rs5c313_write_cntreg(0x07);
341
342 /* busy check. */
343 for (cnt = 0; cnt < 100; cnt++) {
344 if (!(rs5c313_read_cntreg() & RS5C313_CNTREG_ADJ_BSY))
345 break;
346 RS5C313_MISCOP;
347 }
348
349 memset(&tm, 0, sizeof(struct rtc_time));
350 tm.tm_mday = 1;
351 tm.tm_mon = 1 - 1;
352 tm.tm_year = 2000 - 1900;
353
354 rs5c313_rtc_set_time(NULL, &tm);
355 printk(KERN_ERR "RICHO RS5C313: invalid value, resetting to "
356 "1 Jan 2000\n");
357 }
358 RS5C313_CEDISABLE;
359 ndelay(700); /* CE:L */
360}
361
362static const struct rtc_class_ops rs5c313_rtc_ops = {
363 .read_time = rs5c313_rtc_read_time,
364 .set_time = rs5c313_rtc_set_time,
365};
366
367static int rs5c313_rtc_probe(struct platform_device *pdev)
368{
369 struct rtc_device *rtc = rtc_device_register("rs5c313", &pdev->dev,
370 &rs5c313_rtc_ops, THIS_MODULE);
371
372 if (IS_ERR(rtc))
373 return PTR_ERR(rtc);
374
375 platform_set_drvdata(pdev, rtc);
376
377 return 0;
378}
379
380static int __devexit rs5c313_rtc_remove(struct platform_device *pdev)
381{
382 struct rtc_device *rtc = platform_get_drvdata( pdev );
383
384 rtc_device_unregister(rtc);
385
386 return 0;
387}
388
389static struct platform_driver rs5c313_rtc_platform_driver = {
390 .driver = {
391 .name = DRV_NAME,
392 .owner = THIS_MODULE,
393 },
394 .probe = rs5c313_rtc_probe,
395 .remove = __devexit_p( rs5c313_rtc_remove ),
396};
397
398static int __init rs5c313_rtc_init(void)
399{
400 int err;
401
402 err = platform_driver_register(&rs5c313_rtc_platform_driver);
403 if (err)
404 return err;
405
406 rs5c313_init_port();
407 rs5c313_check_xstp_bit();
408
409 return 0;
410}
411
412static void __exit rs5c313_rtc_exit(void)
413{
414 platform_driver_unregister( &rs5c313_rtc_platform_driver );
415}
416
417module_init(rs5c313_rtc_init);
418module_exit(rs5c313_rtc_exit);
419
420MODULE_VERSION(DRV_VERSION);
421MODULE_AUTHOR("kogiidena , Nobuhiro Iwamatsu <iwamatsu@nigauri.org>");
422MODULE_DESCRIPTION("Ricoh RS5C313 RTC device driver");
423MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 9a79a24a7487..54b613053468 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -50,7 +50,7 @@ static irqreturn_t s3c_rtc_alarmirq(int irq, void *id)
50{ 50{
51 struct rtc_device *rdev = id; 51 struct rtc_device *rdev = id;
52 52
53 rtc_update_irq(&rdev->class_dev, 1, RTC_AF | RTC_IRQF); 53 rtc_update_irq(rdev, 1, RTC_AF | RTC_IRQF);
54 return IRQ_HANDLED; 54 return IRQ_HANDLED;
55} 55}
56 56
@@ -58,7 +58,7 @@ static irqreturn_t s3c_rtc_tickirq(int irq, void *id)
58{ 58{
59 struct rtc_device *rdev = id; 59 struct rtc_device *rdev = id;
60 60
61 rtc_update_irq(&rdev->class_dev, tick_count++, RTC_PF | RTC_IRQF); 61 rtc_update_irq(rdev, tick_count++, RTC_PF | RTC_IRQF);
62 return IRQ_HANDLED; 62 return IRQ_HANDLED;
63} 63}
64 64
@@ -548,37 +548,15 @@ static int ticnt_save;
548 548
549static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state) 549static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
550{ 550{
551 struct rtc_time tm;
552 struct timespec time;
553
554 time.tv_nsec = 0;
555
556 /* save TICNT for anyone using periodic interrupts */ 551 /* save TICNT for anyone using periodic interrupts */
557
558 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT); 552 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
559
560 /* calculate time delta for suspend */
561
562 s3c_rtc_gettime(&pdev->dev, &tm);
563 rtc_tm_to_time(&tm, &time.tv_sec);
564 save_time_delta(&s3c_rtc_delta, &time);
565 s3c_rtc_enable(pdev, 0); 553 s3c_rtc_enable(pdev, 0);
566
567 return 0; 554 return 0;
568} 555}
569 556
570static int s3c_rtc_resume(struct platform_device *pdev) 557static int s3c_rtc_resume(struct platform_device *pdev)
571{ 558{
572 struct rtc_time tm;
573 struct timespec time;
574
575 time.tv_nsec = 0;
576
577 s3c_rtc_enable(pdev, 1); 559 s3c_rtc_enable(pdev, 1);
578 s3c_rtc_gettime(&pdev->dev, &tm);
579 rtc_tm_to_time(&tm, &time.tv_sec);
580 restore_time_delta(&s3c_rtc_delta, &time);
581
582 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT); 560 writeb(ticnt_save, s3c_rtc_base + S3C2410_TICNT);
583 return 0; 561 return 0;
584} 562}
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 677bae820dc3..0918b787c4dd 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -93,7 +93,7 @@ static irqreturn_t sa1100_rtc_interrupt(int irq, void *dev_id)
93 if (rtsr & RTSR_HZ) 93 if (rtsr & RTSR_HZ)
94 events |= RTC_UF | RTC_IRQF; 94 events |= RTC_UF | RTC_IRQF;
95 95
96 rtc_update_irq(&rtc->class_dev, 1, events); 96 rtc_update_irq(rtc, 1, events);
97 97
98 if (rtsr & RTSR_AL && rtc_periodic_alarm(&rtc_alarm)) 98 if (rtsr & RTSR_AL && rtc_periodic_alarm(&rtc_alarm))
99 rtc_update_alarm(&rtc_alarm); 99 rtc_update_alarm(&rtc_alarm);
@@ -119,7 +119,7 @@ static irqreturn_t timer1_interrupt(int irq, void *dev_id)
119 */ 119 */
120 OSSR = OSSR_M1; /* clear match on timer1 */ 120 OSSR = OSSR_M1; /* clear match on timer1 */
121 121
122 rtc_update_irq(&rtc->class_dev, rtc_timer1_count, RTC_PF | RTC_IRQF); 122 rtc_update_irq(rtc, rtc_timer1_count, RTC_PF | RTC_IRQF);
123 123
124 if (rtc_timer1_count == 1) 124 if (rtc_timer1_count == 1)
125 rtc_timer1_count = (rtc_freq * ((1<<30)/(TIMER_FREQ>>2))); 125 rtc_timer1_count = (rtc_freq * ((1<<30)/(TIMER_FREQ>>2)));
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 198b9f22fbff..e0f91dfce0f5 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -104,7 +104,7 @@ static irqreturn_t sh_rtc_interrupt(int irq, void *dev_id)
104 104
105 writeb(tmp, rtc->regbase + RCR1); 105 writeb(tmp, rtc->regbase + RCR1);
106 106
107 rtc_update_irq(&rtc->rtc_dev->class_dev, 1, events); 107 rtc_update_irq(rtc->rtc_dev, 1, events);
108 108
109 spin_unlock(&rtc->lock); 109 spin_unlock(&rtc->lock);
110 110
@@ -139,7 +139,7 @@ static irqreturn_t sh_rtc_alarm(int irq, void *dev_id)
139 139
140 rtc->rearm_aie = 1; 140 rtc->rearm_aie = 1;
141 141
142 rtc_update_irq(&rtc->rtc_dev->class_dev, 1, events); 142 rtc_update_irq(rtc->rtc_dev, 1, events);
143 } 143 }
144 144
145 spin_unlock(&rtc->lock); 145 spin_unlock(&rtc->lock);
@@ -153,7 +153,7 @@ static irqreturn_t sh_rtc_periodic(int irq, void *dev_id)
153 153
154 spin_lock(&rtc->lock); 154 spin_lock(&rtc->lock);
155 155
156 rtc_update_irq(&rtc->rtc_dev->class_dev, 1, RTC_PF | RTC_IRQF); 156 rtc_update_irq(rtc->rtc_dev, 1, RTC_PF | RTC_IRQF);
157 157
158 spin_unlock(&rtc->lock); 158 spin_unlock(&rtc->lock);
159 159
@@ -341,7 +341,7 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
341 tm->tm_sec--; 341 tm->tm_sec--;
342#endif 342#endif
343 343
344 dev_dbg(&dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 344 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
345 "mday=%d, mon=%d, year=%d, wday=%d\n", 345 "mday=%d, mon=%d, year=%d, wday=%d\n",
346 __FUNCTION__, 346 __FUNCTION__,
347 tm->tm_sec, tm->tm_min, tm->tm_hour, 347 tm->tm_sec, tm->tm_min, tm->tm_hour,
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 899ab8c514fa..69df94b44841 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -12,20 +12,26 @@
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/rtc.h> 13#include <linux/rtc.h>
14 14
15#include "rtc-core.h"
16
17
15/* device attributes */ 18/* device attributes */
16 19
17static ssize_t rtc_sysfs_show_name(struct class_device *dev, char *buf) 20static ssize_t
21rtc_sysfs_show_name(struct device *dev, struct device_attribute *attr,
22 char *buf)
18{ 23{
19 return sprintf(buf, "%s\n", to_rtc_device(dev)->name); 24 return sprintf(buf, "%s\n", to_rtc_device(dev)->name);
20} 25}
21static CLASS_DEVICE_ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL);
22 26
23static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf) 27static ssize_t
28rtc_sysfs_show_date(struct device *dev, struct device_attribute *attr,
29 char *buf)
24{ 30{
25 ssize_t retval; 31 ssize_t retval;
26 struct rtc_time tm; 32 struct rtc_time tm;
27 33
28 retval = rtc_read_time(dev, &tm); 34 retval = rtc_read_time(to_rtc_device(dev), &tm);
29 if (retval == 0) { 35 if (retval == 0) {
30 retval = sprintf(buf, "%04d-%02d-%02d\n", 36 retval = sprintf(buf, "%04d-%02d-%02d\n",
31 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); 37 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
@@ -33,14 +39,15 @@ static ssize_t rtc_sysfs_show_date(struct class_device *dev, char *buf)
33 39
34 return retval; 40 return retval;
35} 41}
36static CLASS_DEVICE_ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL);
37 42
38static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf) 43static ssize_t
44rtc_sysfs_show_time(struct device *dev, struct device_attribute *attr,
45 char *buf)
39{ 46{
40 ssize_t retval; 47 ssize_t retval;
41 struct rtc_time tm; 48 struct rtc_time tm;
42 49
43 retval = rtc_read_time(dev, &tm); 50 retval = rtc_read_time(to_rtc_device(dev), &tm);
44 if (retval == 0) { 51 if (retval == 0) {
45 retval = sprintf(buf, "%02d:%02d:%02d\n", 52 retval = sprintf(buf, "%02d:%02d:%02d\n",
46 tm.tm_hour, tm.tm_min, tm.tm_sec); 53 tm.tm_hour, tm.tm_min, tm.tm_sec);
@@ -48,14 +55,15 @@ static ssize_t rtc_sysfs_show_time(struct class_device *dev, char *buf)
48 55
49 return retval; 56 return retval;
50} 57}
51static CLASS_DEVICE_ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL);
52 58
53static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf) 59static ssize_t
60rtc_sysfs_show_since_epoch(struct device *dev, struct device_attribute *attr,
61 char *buf)
54{ 62{
55 ssize_t retval; 63 ssize_t retval;
56 struct rtc_time tm; 64 struct rtc_time tm;
57 65
58 retval = rtc_read_time(dev, &tm); 66 retval = rtc_read_time(to_rtc_device(dev), &tm);
59 if (retval == 0) { 67 if (retval == 0) {
60 unsigned long time; 68 unsigned long time;
61 rtc_tm_to_time(&tm, &time); 69 rtc_tm_to_time(&tm, &time);
@@ -64,23 +72,18 @@ static ssize_t rtc_sysfs_show_since_epoch(struct class_device *dev, char *buf)
64 72
65 return retval; 73 return retval;
66} 74}
67static CLASS_DEVICE_ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL);
68
69static struct attribute *rtc_attrs[] = {
70 &class_device_attr_name.attr,
71 &class_device_attr_date.attr,
72 &class_device_attr_time.attr,
73 &class_device_attr_since_epoch.attr,
74 NULL,
75};
76 75
77static struct attribute_group rtc_attr_group = { 76static struct device_attribute rtc_attrs[] = {
78 .attrs = rtc_attrs, 77 __ATTR(name, S_IRUGO, rtc_sysfs_show_name, NULL),
78 __ATTR(date, S_IRUGO, rtc_sysfs_show_date, NULL),
79 __ATTR(time, S_IRUGO, rtc_sysfs_show_time, NULL),
80 __ATTR(since_epoch, S_IRUGO, rtc_sysfs_show_since_epoch, NULL),
81 { },
79}; 82};
80 83
81
82static ssize_t 84static ssize_t
83rtc_sysfs_show_wakealarm(struct class_device *dev, char *buf) 85rtc_sysfs_show_wakealarm(struct device *dev, struct device_attribute *attr,
86 char *buf)
84{ 87{
85 ssize_t retval; 88 ssize_t retval;
86 unsigned long alarm; 89 unsigned long alarm;
@@ -94,7 +97,7 @@ rtc_sysfs_show_wakealarm(struct class_device *dev, char *buf)
94 * REVISIT maybe we should require RTC implementations to 97 * REVISIT maybe we should require RTC implementations to
95 * disable the RTC alarm after it triggers, for uniformity. 98 * disable the RTC alarm after it triggers, for uniformity.
96 */ 99 */
97 retval = rtc_read_alarm(dev, &alm); 100 retval = rtc_read_alarm(to_rtc_device(dev), &alm);
98 if (retval == 0 && alm.enabled) { 101 if (retval == 0 && alm.enabled) {
99 rtc_tm_to_time(&alm.time, &alarm); 102 rtc_tm_to_time(&alm.time, &alarm);
100 retval = sprintf(buf, "%lu\n", alarm); 103 retval = sprintf(buf, "%lu\n", alarm);
@@ -104,16 +107,18 @@ rtc_sysfs_show_wakealarm(struct class_device *dev, char *buf)
104} 107}
105 108
106static ssize_t 109static ssize_t
107rtc_sysfs_set_wakealarm(struct class_device *dev, const char *buf, size_t n) 110rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
111 const char *buf, size_t n)
108{ 112{
109 ssize_t retval; 113 ssize_t retval;
110 unsigned long now, alarm; 114 unsigned long now, alarm;
111 struct rtc_wkalrm alm; 115 struct rtc_wkalrm alm;
116 struct rtc_device *rtc = to_rtc_device(dev);
112 117
113 /* Only request alarms that trigger in the future. Disable them 118 /* Only request alarms that trigger in the future. Disable them
114 * by writing another time, e.g. 0 meaning Jan 1 1970 UTC. 119 * by writing another time, e.g. 0 meaning Jan 1 1970 UTC.
115 */ 120 */
116 retval = rtc_read_time(dev, &alm.time); 121 retval = rtc_read_time(rtc, &alm.time);
117 if (retval < 0) 122 if (retval < 0)
118 return retval; 123 return retval;
119 rtc_tm_to_time(&alm.time, &now); 124 rtc_tm_to_time(&alm.time, &now);
@@ -124,7 +129,7 @@ rtc_sysfs_set_wakealarm(struct class_device *dev, const char *buf, size_t n)
124 * entirely prevent that here, without even the minimal 129 * entirely prevent that here, without even the minimal
125 * locking from the /dev/rtcN api. 130 * locking from the /dev/rtcN api.
126 */ 131 */
127 retval = rtc_read_alarm(dev, &alm); 132 retval = rtc_read_alarm(rtc, &alm);
128 if (retval < 0) 133 if (retval < 0)
129 return retval; 134 return retval;
130 if (alm.enabled) 135 if (alm.enabled)
@@ -141,10 +146,10 @@ rtc_sysfs_set_wakealarm(struct class_device *dev, const char *buf, size_t n)
141 } 146 }
142 rtc_time_to_tm(alarm, &alm.time); 147 rtc_time_to_tm(alarm, &alm.time);
143 148
144 retval = rtc_set_alarm(dev, &alm); 149 retval = rtc_set_alarm(rtc, &alm);
145 return (retval < 0) ? retval : n; 150 return (retval < 0) ? retval : n;
146} 151}
147static const CLASS_DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR, 152static DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR,
148 rtc_sysfs_show_wakealarm, rtc_sysfs_set_wakealarm); 153 rtc_sysfs_show_wakealarm, rtc_sysfs_set_wakealarm);
149 154
150 155
@@ -153,71 +158,37 @@ static const CLASS_DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR,
153 * suspend-to-disk. So: no attribute unless that side effect is possible. 158 * suspend-to-disk. So: no attribute unless that side effect is possible.
154 * (Userspace may disable that mechanism later.) 159 * (Userspace may disable that mechanism later.)
155 */ 160 */
156static inline int rtc_does_wakealarm(struct class_device *class_dev) 161static inline int rtc_does_wakealarm(struct rtc_device *rtc)
157{ 162{
158 struct rtc_device *rtc; 163 if (!device_can_wakeup(rtc->dev.parent))
159
160 if (!device_can_wakeup(class_dev->dev))
161 return 0; 164 return 0;
162 rtc = to_rtc_device(class_dev);
163 return rtc->ops->set_alarm != NULL; 165 return rtc->ops->set_alarm != NULL;
164} 166}
165 167
166 168
167static int rtc_sysfs_add_device(struct class_device *class_dev, 169void rtc_sysfs_add_device(struct rtc_device *rtc)
168 struct class_interface *class_intf)
169{ 170{
170 int err; 171 int err;
171 172
172 dev_dbg(class_dev->dev, "rtc intf: sysfs\n"); 173 /* not all RTCs support both alarms and wakeup */
174 if (!rtc_does_wakealarm(rtc))
175 return;
173 176
174 err = sysfs_create_group(&class_dev->kobj, &rtc_attr_group); 177 err = device_create_file(&rtc->dev, &dev_attr_wakealarm);
175 if (err) 178 if (err)
176 dev_err(class_dev->dev, "failed to create %s\n", 179 dev_err(rtc->dev.parent, "failed to create "
177 "sysfs attributes"); 180 "alarm attribute, %d",
178 else if (rtc_does_wakealarm(class_dev)) { 181 err);
179 /* not all RTCs support both alarms and wakeup */
180 err = class_device_create_file(class_dev,
181 &class_device_attr_wakealarm);
182 if (err) {
183 dev_err(class_dev->dev, "failed to create %s\n",
184 "alarm attribute");
185 sysfs_remove_group(&class_dev->kobj, &rtc_attr_group);
186 }
187 }
188
189 return err;
190} 182}
191 183
192static void rtc_sysfs_remove_device(struct class_device *class_dev, 184void rtc_sysfs_del_device(struct rtc_device *rtc)
193 struct class_interface *class_intf)
194{ 185{
195 if (rtc_does_wakealarm(class_dev)) 186 /* REVISIT did we add it successfully? */
196 class_device_remove_file(class_dev, 187 if (rtc_does_wakealarm(rtc))
197 &class_device_attr_wakealarm); 188 device_remove_file(&rtc->dev, &dev_attr_wakealarm);
198 sysfs_remove_group(&class_dev->kobj, &rtc_attr_group);
199} 189}
200 190
201/* interface registration */ 191void __init rtc_sysfs_init(struct class *rtc_class)
202
203static struct class_interface rtc_sysfs_interface = {
204 .add = &rtc_sysfs_add_device,
205 .remove = &rtc_sysfs_remove_device,
206};
207
208static int __init rtc_sysfs_init(void)
209{ 192{
210 return rtc_interface_register(&rtc_sysfs_interface); 193 rtc_class->dev_attrs = rtc_attrs;
211} 194}
212
213static void __exit rtc_sysfs_exit(void)
214{
215 class_interface_unregister(&rtc_sysfs_interface);
216}
217
218subsys_initcall(rtc_sysfs_init);
219module_exit(rtc_sysfs_exit);
220
221MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
222MODULE_DESCRIPTION("RTC class sysfs interface");
223MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index f50a1b8e1607..254c9fce27da 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -101,11 +101,11 @@ static ssize_t test_irq_store(struct device *dev,
101 retval = count; 101 retval = count;
102 local_irq_disable(); 102 local_irq_disable();
103 if (strncmp(buf, "tick", 4) == 0) 103 if (strncmp(buf, "tick", 4) == 0)
104 rtc_update_irq(&rtc->class_dev, 1, RTC_PF | RTC_IRQF); 104 rtc_update_irq(rtc, 1, RTC_PF | RTC_IRQF);
105 else if (strncmp(buf, "alarm", 5) == 0) 105 else if (strncmp(buf, "alarm", 5) == 0)
106 rtc_update_irq(&rtc->class_dev, 1, RTC_AF | RTC_IRQF); 106 rtc_update_irq(rtc, 1, RTC_AF | RTC_IRQF);
107 else if (strncmp(buf, "update", 6) == 0) 107 else if (strncmp(buf, "update", 6) == 0)
108 rtc_update_irq(&rtc->class_dev, 1, RTC_UF | RTC_IRQF); 108 rtc_update_irq(rtc, 1, RTC_UF | RTC_IRQF);
109 else 109 else
110 retval = -EINVAL; 110 retval = -EINVAL;
111 local_irq_enable(); 111 local_irq_enable();
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index e40322b71938..af7596ef29e2 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -97,6 +97,7 @@ static DEFINE_SPINLOCK(rtc_lock);
97static char rtc_name[] = "RTC"; 97static char rtc_name[] = "RTC";
98static unsigned long periodic_frequency; 98static unsigned long periodic_frequency;
99static unsigned long periodic_count; 99static unsigned long periodic_count;
100static unsigned int alarm_enabled;
100 101
101struct resource rtc_resource[2] = { 102struct resource rtc_resource[2] = {
102 { .name = rtc_name, 103 { .name = rtc_name,
@@ -188,6 +189,7 @@ static int vr41xx_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
188 low = rtc1_read(ECMPLREG); 189 low = rtc1_read(ECMPLREG);
189 mid = rtc1_read(ECMPMREG); 190 mid = rtc1_read(ECMPMREG);
190 high = rtc1_read(ECMPHREG); 191 high = rtc1_read(ECMPHREG);
192 wkalrm->enabled = alarm_enabled;
191 193
192 spin_unlock_irq(&rtc_lock); 194 spin_unlock_irq(&rtc_lock);
193 195
@@ -206,10 +208,18 @@ static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
206 208
207 spin_lock_irq(&rtc_lock); 209 spin_lock_irq(&rtc_lock);
208 210
211 if (alarm_enabled)
212 disable_irq(ELAPSEDTIME_IRQ);
213
209 rtc1_write(ECMPLREG, (uint16_t)(alarm_sec << 15)); 214 rtc1_write(ECMPLREG, (uint16_t)(alarm_sec << 15));
210 rtc1_write(ECMPMREG, (uint16_t)(alarm_sec >> 1)); 215 rtc1_write(ECMPMREG, (uint16_t)(alarm_sec >> 1));
211 rtc1_write(ECMPHREG, (uint16_t)(alarm_sec >> 17)); 216 rtc1_write(ECMPHREG, (uint16_t)(alarm_sec >> 17));
212 217
218 if (wkalrm->enabled)
219 enable_irq(ELAPSEDTIME_IRQ);
220
221 alarm_enabled = wkalrm->enabled;
222
213 spin_unlock_irq(&rtc_lock); 223 spin_unlock_irq(&rtc_lock);
214 224
215 return 0; 225 return 0;
@@ -221,10 +231,24 @@ static int vr41xx_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long
221 231
222 switch (cmd) { 232 switch (cmd) {
223 case RTC_AIE_ON: 233 case RTC_AIE_ON:
224 enable_irq(ELAPSEDTIME_IRQ); 234 spin_lock_irq(&rtc_lock);
235
236 if (!alarm_enabled) {
237 enable_irq(ELAPSEDTIME_IRQ);
238 alarm_enabled = 1;
239 }
240
241 spin_unlock_irq(&rtc_lock);
225 break; 242 break;
226 case RTC_AIE_OFF: 243 case RTC_AIE_OFF:
227 disable_irq(ELAPSEDTIME_IRQ); 244 spin_lock_irq(&rtc_lock);
245
246 if (alarm_enabled) {
247 disable_irq(ELAPSEDTIME_IRQ);
248 alarm_enabled = 0;
249 }
250
251 spin_unlock_irq(&rtc_lock);
228 break; 252 break;
229 case RTC_PIE_ON: 253 case RTC_PIE_ON:
230 enable_irq(RTCLONG1_IRQ); 254 enable_irq(RTCLONG1_IRQ);
@@ -275,7 +299,7 @@ static irqreturn_t elapsedtime_interrupt(int irq, void *dev_id)
275 299
276 rtc2_write(RTCINTREG, ELAPSEDTIME_INT); 300 rtc2_write(RTCINTREG, ELAPSEDTIME_INT);
277 301
278 rtc_update_irq(&rtc->class_dev, 1, RTC_AF); 302 rtc_update_irq(rtc, 1, RTC_AF);
279 303
280 return IRQ_HANDLED; 304 return IRQ_HANDLED;
281} 305}
@@ -291,7 +315,7 @@ static irqreturn_t rtclong1_interrupt(int irq, void *dev_id)
291 rtc1_write(RTCL1LREG, count); 315 rtc1_write(RTCL1LREG, count);
292 rtc1_write(RTCL1HREG, count >> 16); 316 rtc1_write(RTCL1HREG, count >> 16);
293 317
294 rtc_update_irq(&rtc->class_dev, 1, RTC_PF); 318 rtc_update_irq(rtc, 1, RTC_PF);
295 319
296 return IRQ_HANDLED; 320 return IRQ_HANDLED;
297} 321}
diff --git a/drivers/s390/block/Kconfig b/drivers/s390/block/Kconfig
index b250c5354503..e879b212cf43 100644
--- a/drivers/s390/block/Kconfig
+++ b/drivers/s390/block/Kconfig
@@ -1,11 +1,9 @@
1if S390 && BLOCK
2
3comment "S/390 block device drivers" 1comment "S/390 block device drivers"
4 depends on S390 2 depends on S390 && BLOCK
5 3
6config BLK_DEV_XPRAM 4config BLK_DEV_XPRAM
7 tristate "XPRAM disk support" 5 tristate "XPRAM disk support"
8 depends on S390 6 depends on S390 && BLOCK
9 help 7 help
10 Select this option if you want to use your expanded storage on S/390 8 Select this option if you want to use your expanded storage on S/390
11 or zSeries as a disk. This is useful as a _fast_ swap device if you 9 or zSeries as a disk. This is useful as a _fast_ swap device if you
@@ -15,12 +13,13 @@ config BLK_DEV_XPRAM
15 13
16config DCSSBLK 14config DCSSBLK
17 tristate "DCSSBLK support" 15 tristate "DCSSBLK support"
16 depends on S390 && BLOCK
18 help 17 help
19 Support for dcss block device 18 Support for dcss block device
20 19
21config DASD 20config DASD
22 tristate "Support for DASD devices" 21 tristate "Support for DASD devices"
23 depends on CCW 22 depends on CCW && BLOCK
24 help 23 help
25 Enable this option if you want to access DASDs directly utilizing 24 Enable this option if you want to access DASDs directly utilizing
26 S/390s channel subsystem commands. This is necessary for running 25 S/390s channel subsystem commands. This is necessary for running
@@ -62,5 +61,3 @@ config DASD_EER
62 This driver provides a character device interface to the 61 This driver provides a character device interface to the
63 DASD extended error reporting. This is only needed if you want to 62 DASD extended error reporting. This is only needed if you want to
64 use applications written for the EER facility. 63 use applications written for the EER facility.
65
66endif
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 977521013fe8..bfeca57098fa 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -2174,9 +2174,10 @@ dasd_generic_notify(struct ccw_device *cdev, int event)
2174 return ret; 2174 return ret;
2175} 2175}
2176 2176
2177struct dasd_ccw_req * dasd_generic_build_rdc(struct dasd_device *device, 2177static struct dasd_ccw_req *dasd_generic_build_rdc(struct dasd_device *device,
2178 void *rdc_buffer, 2178 void *rdc_buffer,
2179 int rdc_buffer_size, char *magic) 2179 int rdc_buffer_size,
2180 char *magic)
2180{ 2181{
2181 struct dasd_ccw_req *cqr; 2182 struct dasd_ccw_req *cqr;
2182 struct ccw1 *ccw; 2183 struct ccw1 *ccw;
@@ -2219,6 +2220,7 @@ int dasd_generic_read_dev_chars(struct dasd_device *device, char *magic,
2219 dasd_sfree_request(cqr, cqr->device); 2220 dasd_sfree_request(cqr, cqr->device);
2220 return ret; 2221 return ret;
2221} 2222}
2223EXPORT_SYMBOL_GPL(dasd_generic_read_dev_chars);
2222 2224
2223static int __init 2225static int __init
2224dasd_init(void) 2226dasd_init(void)
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c
index e810e4a44ed4..eccac1c3b71b 100644
--- a/drivers/s390/block/dasd_diag.c
+++ b/drivers/s390/block/dasd_diag.c
@@ -50,6 +50,7 @@ struct dasd_diag_private {
50 struct dasd_diag_rw_io iob; 50 struct dasd_diag_rw_io iob;
51 struct dasd_diag_init_io iib; 51 struct dasd_diag_init_io iib;
52 blocknum_t pt_block; 52 blocknum_t pt_block;
53 struct ccw_dev_id dev_id;
53}; 54};
54 55
55struct dasd_diag_req { 56struct dasd_diag_req {
@@ -102,7 +103,7 @@ mdsk_init_io(struct dasd_device *device, unsigned int blocksize,
102 iib = &private->iib; 103 iib = &private->iib;
103 memset(iib, 0, sizeof (struct dasd_diag_init_io)); 104 memset(iib, 0, sizeof (struct dasd_diag_init_io));
104 105
105 iib->dev_nr = _ccw_device_get_device_number(device->cdev); 106 iib->dev_nr = private->dev_id.devno;
106 iib->block_size = blocksize; 107 iib->block_size = blocksize;
107 iib->offset = offset; 108 iib->offset = offset;
108 iib->flaga = DASD_DIAG_FLAGA_DEFAULT; 109 iib->flaga = DASD_DIAG_FLAGA_DEFAULT;
@@ -127,7 +128,7 @@ mdsk_term_io(struct dasd_device * device)
127 private = (struct dasd_diag_private *) device->private; 128 private = (struct dasd_diag_private *) device->private;
128 iib = &private->iib; 129 iib = &private->iib;
129 memset(iib, 0, sizeof (struct dasd_diag_init_io)); 130 memset(iib, 0, sizeof (struct dasd_diag_init_io));
130 iib->dev_nr = _ccw_device_get_device_number(device->cdev); 131 iib->dev_nr = private->dev_id.devno;
131 rc = dia250(iib, TERM_BIO); 132 rc = dia250(iib, TERM_BIO);
132 return rc; 133 return rc;
133} 134}
@@ -166,7 +167,7 @@ dasd_start_diag(struct dasd_ccw_req * cqr)
166 private = (struct dasd_diag_private *) device->private; 167 private = (struct dasd_diag_private *) device->private;
167 dreq = (struct dasd_diag_req *) cqr->data; 168 dreq = (struct dasd_diag_req *) cqr->data;
168 169
169 private->iob.dev_nr = _ccw_device_get_device_number(device->cdev); 170 private->iob.dev_nr = private->dev_id.devno;
170 private->iob.key = 0; 171 private->iob.key = 0;
171 private->iob.flags = DASD_DIAG_RWFLAG_ASYNC; 172 private->iob.flags = DASD_DIAG_RWFLAG_ASYNC;
172 private->iob.block_count = dreq->block_count; 173 private->iob.block_count = dreq->block_count;
@@ -323,11 +324,12 @@ dasd_diag_check_device(struct dasd_device *device)
323 "memory allocation failed for private data"); 324 "memory allocation failed for private data");
324 return -ENOMEM; 325 return -ENOMEM;
325 } 326 }
327 ccw_device_get_id(device->cdev, &private->dev_id);
326 device->private = (void *) private; 328 device->private = (void *) private;
327 } 329 }
328 /* Read Device Characteristics */ 330 /* Read Device Characteristics */
329 rdc_data = (void *) &(private->rdc_data); 331 rdc_data = (void *) &(private->rdc_data);
330 rdc_data->dev_nr = _ccw_device_get_device_number(device->cdev); 332 rdc_data->dev_nr = private->dev_id.devno;
331 rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics); 333 rdc_data->rdc_len = sizeof (struct dasd_diag_characteristics);
332 334
333 rc = diag210((struct diag210 *) rdc_data); 335 rc = diag210((struct diag210 *) rdc_data);
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index c9583fbc2a7d..418b4e63a4fa 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -450,9 +450,9 @@ dasd_eckd_generate_uid(struct dasd_device *device, struct dasd_uid *uid)
450 return 0; 450 return 0;
451} 451}
452 452
453struct dasd_ccw_req * dasd_eckd_build_rcd_lpm(struct dasd_device *device, 453static struct dasd_ccw_req *dasd_eckd_build_rcd_lpm(struct dasd_device *device,
454 void *rcd_buffer, 454 void *rcd_buffer,
455 struct ciw *ciw, __u8 lpm) 455 struct ciw *ciw, __u8 lpm)
456{ 456{
457 struct dasd_ccw_req *cqr; 457 struct dasd_ccw_req *cqr;
458 struct ccw1 *ccw; 458 struct ccw1 *ccw;
diff --git a/drivers/s390/block/dasd_ioctl.c b/drivers/s390/block/dasd_ioctl.c
index 758cfb542865..672eb0a3dd0b 100644
--- a/drivers/s390/block/dasd_ioctl.c
+++ b/drivers/s390/block/dasd_ioctl.c
@@ -255,6 +255,7 @@ dasd_ioctl_information(struct dasd_device *device,
255 unsigned long flags; 255 unsigned long flags;
256 int rc; 256 int rc;
257 struct ccw_device *cdev; 257 struct ccw_device *cdev;
258 struct ccw_dev_id dev_id;
258 259
259 if (!device->discipline->fill_info) 260 if (!device->discipline->fill_info)
260 return -EINVAL; 261 return -EINVAL;
@@ -270,8 +271,9 @@ dasd_ioctl_information(struct dasd_device *device,
270 } 271 }
271 272
272 cdev = device->cdev; 273 cdev = device->cdev;
274 ccw_device_get_id(cdev, &dev_id);
273 275
274 dasd_info->devno = _ccw_device_get_device_number(device->cdev); 276 dasd_info->devno = dev_id.devno;
275 dasd_info->schid = _ccw_device_get_subchannel_number(device->cdev); 277 dasd_info->schid = _ccw_device_get_subchannel_number(device->cdev);
276 dasd_info->cu_type = cdev->id.cu_type; 278 dasd_info->cu_type = cdev->id.cu_type;
277 dasd_info->cu_model = cdev->id.cu_model; 279 dasd_info->cu_model = cdev->id.cu_model;
diff --git a/drivers/s390/Kconfig b/drivers/s390/char/Kconfig
index 165af398fdea..66102a184322 100644
--- a/drivers/s390/Kconfig
+++ b/drivers/s390/char/Kconfig
@@ -1,69 +1,9 @@
1config CCW
2 bool
3 default y
4
5source "drivers/block/Kconfig"
6
7source "drivers/md/Kconfig"
8
9
10menu "Character device drivers"
11
12config UNIX98_PTYS
13 bool "Unix98 PTY support"
14 ---help---
15 A pseudo terminal (PTY) is a software device consisting of two
16 halves: a master and a slave. The slave device behaves identical to
17 a physical terminal; the master device is used by a process to
18 read data from and write data to the slave, thereby emulating a
19 terminal. Typical programs for the master side are telnet servers
20 and xterms.
21
22 Linux has traditionally used the BSD-like names /dev/ptyxx for
23 masters and /dev/ttyxx for slaves of pseudo terminals. This scheme
24 has a number of problems. The GNU C library glibc 2.1 and later,
25 however, supports the Unix98 naming standard: in order to acquire a
26 pseudo terminal, a process opens /dev/ptmx; the number of the pseudo
27 terminal is then made available to the process and the pseudo
28 terminal slave can be accessed as /dev/pts/<number>. What was
29 traditionally /dev/ttyp2 will then be /dev/pts/2, for example.
30
31 The entries in /dev/pts/ are created on the fly by a virtual
32 file system; therefore, if you say Y here you should say Y to
33 "/dev/pts file system for Unix98 PTYs" as well.
34
35 If you want to say Y here, you need to have the C library glibc 2.1
36 or later (equal to libc-6.1, check with "ls -l /lib/libc.so.*").
37 Read the instructions in <file:Documentation/Changes> pertaining to
38 pseudo terminals. It's safe to say N.
39
40config UNIX98_PTY_COUNT
41 int "Maximum number of Unix98 PTYs in use (0-2048)"
42 depends on UNIX98_PTYS
43 default "256"
44 help
45 The maximum number of Unix98 PTYs that can be used at any one time.
46 The default is 256, and should be enough for desktop systems. Server
47 machines which support incoming telnet/rlogin/ssh connections and/or
48 serve several X terminals may want to increase this: every incoming
49 connection and every xterm uses up one PTY.
50
51 When not in use, each additional set of 256 PTYs occupy
52 approximately 8 KB of kernel memory on 32-bit architectures.
53
54config HANGCHECK_TIMER
55 tristate "Hangcheck timer"
56 help
57 The hangcheck-timer module detects when the system has gone
58 out to lunch past a certain margin. It can reboot the system
59 or merely print a warning.
60
61source "drivers/char/watchdog/Kconfig"
62
63comment "S/390 character device drivers" 1comment "S/390 character device drivers"
2 depends on S390
64 3
65config TN3270 4config TN3270
66 tristate "Support for locally attached 3270 terminals" 5 tristate "Support for locally attached 3270 terminals"
6 depends on CCW
67 help 7 help
68 Include support for IBM 3270 terminals. 8 Include support for IBM 3270 terminals.
69 9
@@ -88,6 +28,7 @@ config TN3270_CONSOLE
88 28
89config TN3215 29config TN3215
90 bool "Support for 3215 line mode terminal" 30 bool "Support for 3215 line mode terminal"
31 depends on CCW
91 help 32 help
92 Include support for IBM 3215 line-mode terminals. 33 Include support for IBM 3215 line-mode terminals.
93 34
@@ -99,12 +40,19 @@ config TN3215_CONSOLE
99 Linux system console. 40 Linux system console.
100 41
101config CCW_CONSOLE 42config CCW_CONSOLE
102 bool 43 bool
103 depends on TN3215_CONSOLE || TN3270_CONSOLE 44 depends on TN3215_CONSOLE || TN3270_CONSOLE
104 default y 45 default y
105 46
47config SCLP
48 bool "Support for SCLP"
49 depends on S390
50 help
51 Include support for the SCLP interface to the service element.
52
106config SCLP_TTY 53config SCLP_TTY
107 bool "Support for SCLP line mode terminal" 54 bool "Support for SCLP line mode terminal"
55 depends on SCLP
108 help 56 help
109 Include support for IBM SCLP line-mode terminals. 57 Include support for IBM SCLP line-mode terminals.
110 58
@@ -117,6 +65,7 @@ config SCLP_CONSOLE
117 65
118config SCLP_VT220_TTY 66config SCLP_VT220_TTY
119 bool "Support for SCLP VT220-compatible terminal" 67 bool "Support for SCLP VT220-compatible terminal"
68 depends on SCLP
120 help 69 help
121 Include support for an IBM SCLP VT220-compatible terminal. 70 Include support for an IBM SCLP VT220-compatible terminal.
122 71
@@ -129,6 +78,7 @@ config SCLP_VT220_CONSOLE
129 78
130config SCLP_CPI 79config SCLP_CPI
131 tristate "Control-Program Identification" 80 tristate "Control-Program Identification"
81 depends on SCLP
132 help 82 help
133 This option enables the hardware console interface for system 83 This option enables the hardware console interface for system
134 identification. This is commonly used for workload management and 84 identification. This is commonly used for workload management and
@@ -140,6 +90,7 @@ config SCLP_CPI
140 90
141config S390_TAPE 91config S390_TAPE
142 tristate "S/390 tape device support" 92 tristate "S/390 tape device support"
93 depends on CCW
143 help 94 help
144 Select this option if you want to access channel-attached tape 95 Select this option if you want to access channel-attached tape
145 devices on IBM S/390 or zSeries. 96 devices on IBM S/390 or zSeries.
@@ -194,6 +145,7 @@ config VMLOGRDR
194 145
195config VMCP 146config VMCP
196 tristate "Support for the z/VM CP interface (VM only)" 147 tristate "Support for the z/VM CP interface (VM only)"
148 depends on S390
197 help 149 help
198 Select this option if you want to be able to interact with the control 150 Select this option if you want to be able to interact with the control
199 program on z/VM 151 program on z/VM
@@ -207,33 +159,8 @@ config MONREADER
207 159
208config MONWRITER 160config MONWRITER
209 tristate "API for writing z/VM monitor service records" 161 tristate "API for writing z/VM monitor service records"
162 depends on S390
210 default "m" 163 default "m"
211 help 164 help
212 Character device driver for writing z/VM monitor service records 165 Character device driver for writing z/VM monitor service records
213 166
214endmenu
215
216menu "Cryptographic devices"
217
218config ZCRYPT
219 tristate "Support for PCI-attached cryptographic adapters"
220 select ZCRYPT_MONOLITHIC if ZCRYPT="y"
221 default "m"
222 help
223 Select this option if you want to use a PCI-attached cryptographic
224 adapter like:
225 + PCI Cryptographic Accelerator (PCICA)
226 + PCI Cryptographic Coprocessor (PCICC)
227 + PCI-X Cryptographic Coprocessor (PCIXCC)
228 + Crypto Express2 Coprocessor (CEX2C)
229 + Crypto Express2 Accelerator (CEX2A)
230
231config ZCRYPT_MONOLITHIC
232 bool "Monolithic zcrypt module"
233 depends on ZCRYPT="m"
234 help
235 Select this option if you want to have a single module z90crypt.ko
236 that contains all parts of the crypto device driver (ap bus,
237 request router and all the card drivers).
238
239endmenu
diff --git a/drivers/s390/char/monreader.c b/drivers/s390/char/monreader.c
index 8df7b1323c05..67009bfa093e 100644
--- a/drivers/s390/char/monreader.c
+++ b/drivers/s390/char/monreader.c
@@ -97,7 +97,7 @@ static u8 user_data_sever[16] = {
97 * Create the 8 bytes EBCDIC DCSS segment name from 97 * Create the 8 bytes EBCDIC DCSS segment name from
98 * an ASCII name, incl. padding 98 * an ASCII name, incl. padding
99 */ 99 */
100static inline void dcss_mkname(char *ascii_name, char *ebcdic_name) 100static void dcss_mkname(char *ascii_name, char *ebcdic_name)
101{ 101{
102 int i; 102 int i;
103 103
@@ -191,7 +191,7 @@ static inline u32 mon_rec_end(struct mon_msg *monmsg)
191 return *((u32 *) (mon_mca_start(monmsg) + monmsg->mca_offset + 8)); 191 return *((u32 *) (mon_mca_start(monmsg) + monmsg->mca_offset + 8));
192} 192}
193 193
194static inline int mon_check_mca(struct mon_msg *monmsg) 194static int mon_check_mca(struct mon_msg *monmsg)
195{ 195{
196 if ((mon_rec_end(monmsg) <= mon_rec_start(monmsg)) || 196 if ((mon_rec_end(monmsg) <= mon_rec_start(monmsg)) ||
197 (mon_rec_start(monmsg) < mon_dcss_start) || 197 (mon_rec_start(monmsg) < mon_dcss_start) ||
@@ -209,8 +209,8 @@ static inline int mon_check_mca(struct mon_msg *monmsg)
209 return 0; 209 return 0;
210} 210}
211 211
212static inline int mon_send_reply(struct mon_msg *monmsg, 212static int mon_send_reply(struct mon_msg *monmsg,
213 struct mon_private *monpriv) 213 struct mon_private *monpriv)
214{ 214{
215 int rc; 215 int rc;
216 216
@@ -236,7 +236,7 @@ static inline int mon_send_reply(struct mon_msg *monmsg,
236 return 0; 236 return 0;
237} 237}
238 238
239static inline void mon_free_mem(struct mon_private *monpriv) 239static void mon_free_mem(struct mon_private *monpriv)
240{ 240{
241 int i; 241 int i;
242 242
@@ -246,7 +246,7 @@ static inline void mon_free_mem(struct mon_private *monpriv)
246 kfree(monpriv); 246 kfree(monpriv);
247} 247}
248 248
249static inline struct mon_private *mon_alloc_mem(void) 249static struct mon_private *mon_alloc_mem(void)
250{ 250{
251 int i; 251 int i;
252 struct mon_private *monpriv; 252 struct mon_private *monpriv;
@@ -307,7 +307,7 @@ static inline void mon_next_mca(struct mon_msg *monmsg)
307 monmsg->pos = 0; 307 monmsg->pos = 0;
308} 308}
309 309
310static inline struct mon_msg *mon_next_message(struct mon_private *monpriv) 310static struct mon_msg *mon_next_message(struct mon_private *monpriv)
311{ 311{
312 struct mon_msg *monmsg; 312 struct mon_msg *monmsg;
313 313
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index 8facd14adb7c..f6ef90ee3e7d 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -589,9 +589,10 @@ static int
589__raw3270_size_device_vm(struct raw3270 *rp) 589__raw3270_size_device_vm(struct raw3270 *rp)
590{ 590{
591 int rc, model; 591 int rc, model;
592 struct ccw_dev_id dev_id;
592 593
593 raw3270_init_diag210.vrdcdvno = 594 ccw_device_get_id(rp->cdev, &dev_id);
594 _ccw_device_get_device_number(rp->cdev); 595 raw3270_init_diag210.vrdcdvno = dev_id.devno;
595 raw3270_init_diag210.vrdclen = sizeof(struct diag210); 596 raw3270_init_diag210.vrdclen = sizeof(struct diag210);
596 rc = diag210(&raw3270_init_diag210); 597 rc = diag210(&raw3270_init_diag210);
597 if (rc) 598 if (rc)
diff --git a/drivers/s390/char/sclp.h b/drivers/s390/char/sclp.h
index 87ac4a3ad49d..dbb99d1b6f57 100644
--- a/drivers/s390/char/sclp.h
+++ b/drivers/s390/char/sclp.h
@@ -132,6 +132,9 @@ int sclp_deactivate(void);
132int sclp_reactivate(void); 132int sclp_reactivate(void);
133int sclp_service_call(sclp_cmdw_t command, void *sccb); 133int sclp_service_call(sclp_cmdw_t command, void *sccb);
134 134
135int sclp_sdias_init(void);
136void sclp_sdias_exit(void);
137
135/* useful inlines */ 138/* useful inlines */
136 139
137/* VM uses EBCDIC 037, LPAR+native(SE+HMC) use EBCDIC 500 */ 140/* VM uses EBCDIC 037, LPAR+native(SE+HMC) use EBCDIC 500 */
diff --git a/drivers/s390/char/sclp_rw.c b/drivers/s390/char/sclp_rw.c
index bbd5b8b66f42..d6b06ab81188 100644
--- a/drivers/s390/char/sclp_rw.c
+++ b/drivers/s390/char/sclp_rw.c
@@ -23,7 +23,7 @@
23 23
24/* 24/*
25 * The room for the SCCB (only for writing) is not equal to a pages size 25 * The room for the SCCB (only for writing) is not equal to a pages size
26 * (as it is specified as the maximum size in the the SCLP documentation) 26 * (as it is specified as the maximum size in the SCLP documentation)
27 * because of the additional data structure described above. 27 * because of the additional data structure described above.
28 */ 28 */
29#define MAX_SCCB_ROOM (PAGE_SIZE - sizeof(struct sclp_buffer)) 29#define MAX_SCCB_ROOM (PAGE_SIZE - sizeof(struct sclp_buffer))
diff --git a/drivers/s390/char/sclp_sdias.c b/drivers/s390/char/sclp_sdias.c
index 52283daddaef..1c064976b32b 100644
--- a/drivers/s390/char/sclp_sdias.c
+++ b/drivers/s390/char/sclp_sdias.c
@@ -66,9 +66,9 @@ static DEFINE_MUTEX(sdias_mutex);
66 66
67static void sdias_callback(struct sclp_req *request, void *data) 67static void sdias_callback(struct sclp_req *request, void *data)
68{ 68{
69 struct sdias_sccb *sccb; 69 struct sdias_sccb *cbsccb;
70 70
71 sccb = (struct sdias_sccb *) request->sccb; 71 cbsccb = (struct sdias_sccb *) request->sccb;
72 sclp_req_done = 1; 72 sclp_req_done = 1;
73 wake_up(&sdias_wq); /* Inform caller, that request is complete */ 73 wake_up(&sdias_wq); /* Inform caller, that request is complete */
74 TRACE("callback done\n"); 74 TRACE("callback done\n");
@@ -229,7 +229,7 @@ out:
229 return rc; 229 return rc;
230} 230}
231 231
232int __init sdias_init(void) 232int __init sclp_sdias_init(void)
233{ 233{
234 int rc; 234 int rc;
235 235
@@ -248,7 +248,7 @@ int __init sdias_init(void)
248 return 0; 248 return 0;
249} 249}
250 250
251void __exit sdias_exit(void) 251void __exit sclp_sdias_exit(void)
252{ 252{
253 debug_unregister(sdias_dbf); 253 debug_unregister(sdias_dbf);
254 sclp_unregister(&sclp_sdias_register); 254 sclp_unregister(&sclp_sdias_register);
diff --git a/drivers/s390/char/zcore.c b/drivers/s390/char/zcore.c
index 89d439316a53..66eb0688d523 100644
--- a/drivers/s390/char/zcore.c
+++ b/drivers/s390/char/zcore.c
@@ -21,6 +21,7 @@
21#include <asm/debug.h> 21#include <asm/debug.h>
22#include <asm/processor.h> 22#include <asm/processor.h>
23#include <asm/irqflags.h> 23#include <asm/irqflags.h>
24#include "sclp.h"
24 25
25#define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x) 26#define TRACE(x...) debug_sprintf_event(zcore_dbf, 1, x)
26#define MSG(x...) printk( KERN_ALERT x ) 27#define MSG(x...) printk( KERN_ALERT x )
@@ -564,8 +565,6 @@ static void __init zcore_header_init(int arch, struct zcore_header *hdr)
564 get_cpu_id(&hdr->cpu_id); 565 get_cpu_id(&hdr->cpu_id);
565} 566}
566 567
567extern int sdias_init(void);
568
569static int __init zcore_init(void) 568static int __init zcore_init(void)
570{ 569{
571 unsigned char arch; 570 unsigned char arch;
@@ -582,7 +581,7 @@ static int __init zcore_init(void)
582 TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn); 581 TRACE("wwpn: %llx\n", (unsigned long long) ipl_info.data.fcp.wwpn);
583 TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun); 582 TRACE("lun: %llx\n", (unsigned long long) ipl_info.data.fcp.lun);
584 583
585 rc = sdias_init(); 584 rc = sclp_sdias_init();
586 if (rc) 585 if (rc)
587 goto fail; 586 goto fail;
588 587
@@ -634,12 +633,10 @@ fail:
634 return rc; 633 return rc;
635} 634}
636 635
637extern void sdias_exit(void);
638
639static void __exit zcore_exit(void) 636static void __exit zcore_exit(void)
640{ 637{
641 debug_unregister(zcore_dbf); 638 debug_unregister(zcore_dbf);
642 sdias_exit(); 639 sclp_sdias_exit();
643 diag308(DIAG308_REL_HSA, NULL); 640 diag308(DIAG308_REL_HSA, NULL);
644} 641}
645 642
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 27c6d9e55b23..dfca0ef139fd 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -191,8 +191,7 @@ static int css_register_subchannel(struct subchannel *sch)
191 return ret; 191 return ret;
192} 192}
193 193
194int 194static int css_probe_device(struct subchannel_id schid)
195css_probe_device(struct subchannel_id schid)
196{ 195{
197 int ret; 196 int ret;
198 struct subchannel *sch; 197 struct subchannel *sch;
diff --git a/drivers/s390/cio/css.h b/drivers/s390/cio/css.h
index 71fcfdc42800..ed7977531c3f 100644
--- a/drivers/s390/cio/css.h
+++ b/drivers/s390/cio/css.h
@@ -138,9 +138,7 @@ struct css_driver {
138 * all css_drivers have the css_bus_type 138 * all css_drivers have the css_bus_type
139 */ 139 */
140extern struct bus_type css_bus_type; 140extern struct bus_type css_bus_type;
141extern struct css_driver io_subchannel_driver;
142 141
143extern int css_probe_device(struct subchannel_id);
144extern int css_sch_device_register(struct subchannel *); 142extern int css_sch_device_register(struct subchannel *);
145extern void css_sch_device_unregister(struct subchannel *); 143extern void css_sch_device_unregister(struct subchannel *);
146extern struct subchannel * get_subchannel_by_schid(struct subchannel_id); 144extern struct subchannel * get_subchannel_by_schid(struct subchannel_id);
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index a23ff582db9d..a8b373f69cf0 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -129,7 +129,7 @@ static void io_subchannel_verify(struct device *);
129static void io_subchannel_ioterm(struct device *); 129static void io_subchannel_ioterm(struct device *);
130static void io_subchannel_shutdown(struct subchannel *); 130static void io_subchannel_shutdown(struct subchannel *);
131 131
132struct css_driver io_subchannel_driver = { 132static struct css_driver io_subchannel_driver = {
133 .subchannel_type = SUBCHANNEL_TYPE_IO, 133 .subchannel_type = SUBCHANNEL_TYPE_IO,
134 .drv = { 134 .drv = {
135 .name = "io_subchannel", 135 .name = "io_subchannel",
@@ -546,7 +546,7 @@ static struct attribute_group ccwdev_attr_group = {
546 .attrs = ccwdev_attrs, 546 .attrs = ccwdev_attrs,
547}; 547};
548 548
549struct attribute_group *ccwdev_attr_groups[] = { 549static struct attribute_group *ccwdev_attr_groups[] = {
550 &ccwdev_attr_group, 550 &ccwdev_attr_group,
551 NULL, 551 NULL,
552}; 552};
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index 16f59fcb66b1..a5d263fb55ae 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -616,6 +616,17 @@ ccw_device_get_chp_desc(struct ccw_device *cdev, int chp_no)
616 return chp_get_chp_desc(chpid); 616 return chp_get_chp_desc(chpid);
617} 617}
618 618
619/**
620 * ccw_device_get_id - obtain a ccw device id
621 * @cdev: device to obtain the id for
622 * @dev_id: where to fill in the values
623 */
624void ccw_device_get_id(struct ccw_device *cdev, struct ccw_dev_id *dev_id)
625{
626 *dev_id = cdev->private->dev_id;
627}
628EXPORT_SYMBOL(ccw_device_get_id);
629
619// FIXME: these have to go: 630// FIXME: these have to go:
620 631
621int 632int
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index cba64e4cfcd4..e70aeb7a3781 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -996,18 +996,25 @@ __qdio_outbound_processing(struct qdio_q *q)
996 if (qdio_has_outbound_q_moved(q)) 996 if (qdio_has_outbound_q_moved(q))
997 qdio_kick_outbound_handler(q); 997 qdio_kick_outbound_handler(q);
998 998
999 if (q->is_iqdio_q) { 999 if (q->queue_type == QDIO_ZFCP_QFMT) {
1000 if ((!q->hydra_gives_outbound_pcis) &&
1001 (!qdio_is_outbound_q_done(q)))
1002 qdio_mark_q(q);
1003 }
1004 else if (((!q->is_iqdio_q) && (!q->is_pci_out)) ||
1005 (q->queue_type == QDIO_IQDIO_QFMT_ASYNCH)) {
1000 /* 1006 /*
1001 * for asynchronous queues, we better check, if the sent 1007 * make sure buffer switch from PRIMED to EMPTY is noticed
1002 * buffer is already switched from PRIMED to EMPTY. 1008 * and outbound_handler is called
1003 */ 1009 */
1004 if ((q->queue_type == QDIO_IQDIO_QFMT_ASYNCH) && 1010 if (qdio_is_outbound_q_done(q)) {
1005 !qdio_is_outbound_q_done(q)) 1011 del_timer(&q->timer);
1006 qdio_mark_q(q); 1012 } else {
1007 1013 if (!timer_pending(&q->timer))
1008 } else if (!q->hydra_gives_outbound_pcis) 1014 mod_timer(&q->timer, jiffies +
1009 if (!qdio_is_outbound_q_done(q)) 1015 QDIO_FORCE_CHECK_TIMEOUT);
1010 qdio_mark_q(q); 1016 }
1017 }
1011 1018
1012 qdio_release_q(q); 1019 qdio_release_q(q);
1013} 1020}
@@ -1826,6 +1833,7 @@ qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev,
1826 q->queue_type = QDIO_IQDIO_QFMT_ASYNCH; 1833 q->queue_type = QDIO_IQDIO_QFMT_ASYNCH;
1827 q->int_parm=int_parm; 1834 q->int_parm=int_parm;
1828 q->is_input_q=0; 1835 q->is_input_q=0;
1836 q->is_pci_out = 0;
1829 q->schid = irq_ptr->schid; 1837 q->schid = irq_ptr->schid;
1830 q->cdev = cdev; 1838 q->cdev = cdev;
1831 q->irq_ptr = irq_ptr; 1839 q->irq_ptr = irq_ptr;
@@ -1838,6 +1846,10 @@ qdio_fill_qs(struct qdio_irq *irq_ptr, struct ccw_device *cdev,
1838 q->tasklet.data=(unsigned long)q; 1846 q->tasklet.data=(unsigned long)q;
1839 q->tasklet.func=(void(*)(unsigned long)) 1847 q->tasklet.func=(void(*)(unsigned long))
1840 &qdio_outbound_processing; 1848 &qdio_outbound_processing;
1849 q->timer.function=(void(*)(unsigned long))
1850 &qdio_outbound_processing;
1851 q->timer.data = (long)q;
1852 init_timer(&q->timer);
1841 1853
1842 atomic_set(&q->busy_siga_counter,0); 1854 atomic_set(&q->busy_siga_counter,0);
1843 q->timing.busy_start=0; 1855 q->timing.busy_start=0;
@@ -1971,6 +1983,7 @@ qdio_handle_pci(struct qdio_irq *irq_ptr)
1971 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT) 1983 if (q->is_input_q&QDIO_FLAG_NO_INPUT_INTERRUPT_CONTEXT)
1972 qdio_mark_q(q); 1984 qdio_mark_q(q);
1973 else { 1985 else {
1986 qdio_perf_stat_dec(&perf_stats.tl_runs);
1974 __qdio_inbound_processing(q); 1987 __qdio_inbound_processing(q);
1975 } 1988 }
1976 } 1989 }
@@ -2635,6 +2648,7 @@ qdio_shutdown(struct ccw_device *cdev, int how)
2635 2648
2636 for (i=0;i<irq_ptr->no_output_qs;i++) { 2649 for (i=0;i<irq_ptr->no_output_qs;i++) {
2637 tasklet_kill(&irq_ptr->output_qs[i]->tasklet); 2650 tasklet_kill(&irq_ptr->output_qs[i]->tasklet);
2651 del_timer(&irq_ptr->output_qs[i]->timer);
2638 wait_event_interruptible_timeout(cdev->private->wait_q, 2652 wait_event_interruptible_timeout(cdev->private->wait_q,
2639 !atomic_read(&irq_ptr-> 2653 !atomic_read(&irq_ptr->
2640 output_qs[i]-> 2654 output_qs[i]->
@@ -3458,6 +3472,10 @@ do_qdio_handle_outbound(struct qdio_q *q, unsigned int callflags,
3458 qdio_perf_stat_inc(&perf_stats.outbound_cnt); 3472 qdio_perf_stat_inc(&perf_stats.outbound_cnt);
3459 return; 3473 return;
3460 } 3474 }
3475 if (callflags & QDIO_FLAG_PCI_OUT)
3476 q->is_pci_out = 1;
3477 else
3478 q->is_pci_out = 0;
3461 if (q->is_iqdio_q) { 3479 if (q->is_iqdio_q) {
3462 /* one siga for every sbal */ 3480 /* one siga for every sbal */
3463 while (count--) 3481 while (count--)
diff --git a/drivers/s390/cio/qdio.h b/drivers/s390/cio/qdio.h
index 2895392eaae4..6d7aad18f6f0 100644
--- a/drivers/s390/cio/qdio.h
+++ b/drivers/s390/cio/qdio.h
@@ -60,6 +60,7 @@
60#define QDIO_ACTIVATE_TIMEOUT ((5*HZ)>>10) 60#define QDIO_ACTIVATE_TIMEOUT ((5*HZ)>>10)
61#define QDIO_CLEANUP_CLEAR_TIMEOUT (20*HZ) 61#define QDIO_CLEANUP_CLEAR_TIMEOUT (20*HZ)
62#define QDIO_CLEANUP_HALT_TIMEOUT (10*HZ) 62#define QDIO_CLEANUP_HALT_TIMEOUT (10*HZ)
63#define QDIO_FORCE_CHECK_TIMEOUT (10*HZ)
63 64
64enum qdio_irq_states { 65enum qdio_irq_states {
65 QDIO_IRQ_STATE_INACTIVE, 66 QDIO_IRQ_STATE_INACTIVE,
@@ -511,8 +512,8 @@ struct qdio_q {
511 512
512 void *irq_ptr; 513 void *irq_ptr;
513 514
514#ifdef QDIO_USE_TIMERS_FOR_POLLING
515 struct timer_list timer; 515 struct timer_list timer;
516#ifdef QDIO_USE_TIMERS_FOR_POLLING
516 atomic_t timer_already_set; 517 atomic_t timer_already_set;
517 spinlock_t timer_lock; 518 spinlock_t timer_lock;
518#else /* QDIO_USE_TIMERS_FOR_POLLING */ 519#else /* QDIO_USE_TIMERS_FOR_POLLING */
@@ -558,6 +559,7 @@ struct qdio_q {
558 } timing; 559 } timing;
559 atomic_t busy_siga_counter; 560 atomic_t busy_siga_counter;
560 unsigned int queue_type; 561 unsigned int queue_type;
562 unsigned int is_pci_out;
561 563
562 /* leave this member at the end. won't be cleared in qdio_fill_qs */ 564 /* leave this member at the end. won't be cleared in qdio_fill_qs */
563 struct slib *slib; /* a page is allocated under this pointer, 565 struct slib *slib; /* a page is allocated under this pointer,
diff --git a/drivers/s390/net/Kconfig b/drivers/s390/net/Kconfig
index f98fa465df0a..eada69dec4fe 100644
--- a/drivers/s390/net/Kconfig
+++ b/drivers/s390/net/Kconfig
@@ -3,7 +3,7 @@ menu "S/390 network device drivers"
3 3
4config LCS 4config LCS
5 tristate "Lan Channel Station Interface" 5 tristate "Lan Channel Station Interface"
6 depends on NETDEVICES && (NET_ETHERNET || TR || FDDI) 6 depends on CCW && NETDEVICES && (NET_ETHERNET || TR || FDDI)
7 help 7 help
8 Select this option if you want to use LCS networking on IBM S/390 8 Select this option if you want to use LCS networking on IBM S/390
9 or zSeries. This device driver supports Token Ring (IEEE 802.5), 9 or zSeries. This device driver supports Token Ring (IEEE 802.5),
@@ -13,7 +13,7 @@ config LCS
13 13
14config CTC 14config CTC
15 tristate "CTC device support" 15 tristate "CTC device support"
16 depends on NETDEVICES 16 depends on CCW && NETDEVICES
17 help 17 help
18 Select this option if you want to use channel-to-channel networking 18 Select this option if you want to use channel-to-channel networking
19 on IBM S/390 or zSeries. This device driver supports real CTC 19 on IBM S/390 or zSeries. This device driver supports real CTC
@@ -42,7 +42,7 @@ config SMSGIUCV
42 42
43config CLAW 43config CLAW
44 tristate "CLAW device support" 44 tristate "CLAW device support"
45 depends on NETDEVICES 45 depends on CCW && NETDEVICES
46 help 46 help
47 This driver supports channel attached CLAW devices. 47 This driver supports channel attached CLAW devices.
48 CLAW is Common Link Access for Workstation. Common devices 48 CLAW is Common Link Access for Workstation. Common devices
@@ -52,7 +52,7 @@ config CLAW
52 52
53config QETH 53config QETH
54 tristate "Gigabit Ethernet device support" 54 tristate "Gigabit Ethernet device support"
55 depends on NETDEVICES && IP_MULTICAST && QDIO 55 depends on CCW && NETDEVICES && IP_MULTICAST && QDIO
56 help 56 help
57 This driver supports the IBM S/390 and zSeries OSA Express adapters 57 This driver supports the IBM S/390 and zSeries OSA Express adapters
58 in QDIO mode (all media types), HiperSockets interfaces and VM GuestLAN 58 in QDIO mode (all media types), HiperSockets interfaces and VM GuestLAN
diff --git a/drivers/s390/net/netiucv.c b/drivers/s390/net/netiucv.c
index e10e85e85c84..c358764f3264 100644
--- a/drivers/s390/net/netiucv.c
+++ b/drivers/s390/net/netiucv.c
@@ -1862,12 +1862,14 @@ static void netiucv_remove_connection(struct iucv_connection *conn)
1862 write_lock_bh(&iucv_connection_rwlock); 1862 write_lock_bh(&iucv_connection_rwlock);
1863 list_del_init(&conn->list); 1863 list_del_init(&conn->list);
1864 write_unlock_bh(&iucv_connection_rwlock); 1864 write_unlock_bh(&iucv_connection_rwlock);
1865 fsm_deltimer(&conn->timer);
1866 netiucv_purge_skb_queue(&conn->collect_queue);
1865 if (conn->path) { 1867 if (conn->path) {
1866 iucv_path_sever(conn->path, iucvMagic); 1868 iucv_path_sever(conn->path, iucvMagic);
1867 kfree(conn->path); 1869 kfree(conn->path);
1868 conn->path = NULL; 1870 conn->path = NULL;
1869 } 1871 }
1870 fsm_deltimer(&conn->timer); 1872 netiucv_purge_skb_queue(&conn->commit_queue);
1871 kfree_fsm(conn->fsm); 1873 kfree_fsm(conn->fsm);
1872 kfree_skb(conn->rx_buff); 1874 kfree_skb(conn->rx_buff);
1873 kfree_skb(conn->tx_buff); 1875 kfree_skb(conn->tx_buff);
@@ -2115,7 +2117,6 @@ static void __exit netiucv_exit(void)
2115 while (!list_empty(&iucv_connection_list)) { 2117 while (!list_empty(&iucv_connection_list)) {
2116 cp = list_entry(iucv_connection_list.next, 2118 cp = list_entry(iucv_connection_list.next,
2117 struct iucv_connection, list); 2119 struct iucv_connection, list);
2118 list_del(&cp->list);
2119 ndev = cp->netdev; 2120 ndev = cp->netdev;
2120 priv = netdev_priv(ndev); 2121 priv = netdev_priv(ndev);
2121 dev = priv->dev; 2122 dev = priv->dev;
diff --git a/drivers/s390/net/qeth_eddp.c b/drivers/s390/net/qeth_eddp.c
index dd7034fbfff8..4640f32daae5 100644
--- a/drivers/s390/net/qeth_eddp.c
+++ b/drivers/s390/net/qeth_eddp.c
@@ -620,10 +620,10 @@ qeth_eddp_create_context_tcp(struct qeth_card *card, struct sk_buff *skb,
620 620
621struct qeth_eddp_context * 621struct qeth_eddp_context *
622qeth_eddp_create_context(struct qeth_card *card, struct sk_buff *skb, 622qeth_eddp_create_context(struct qeth_card *card, struct sk_buff *skb,
623 struct qeth_hdr *qhdr) 623 struct qeth_hdr *qhdr, unsigned char sk_protocol)
624{ 624{
625 QETH_DBF_TEXT(trace, 5, "creddpc"); 625 QETH_DBF_TEXT(trace, 5, "creddpc");
626 switch (skb->sk->sk_protocol){ 626 switch (sk_protocol) {
627 case IPPROTO_TCP: 627 case IPPROTO_TCP:
628 return qeth_eddp_create_context_tcp(card, skb, qhdr); 628 return qeth_eddp_create_context_tcp(card, skb, qhdr);
629 default: 629 default:
diff --git a/drivers/s390/net/qeth_eddp.h b/drivers/s390/net/qeth_eddp.h
index 103768d3bab2..52910c9252c0 100644
--- a/drivers/s390/net/qeth_eddp.h
+++ b/drivers/s390/net/qeth_eddp.h
@@ -34,7 +34,8 @@ struct qeth_eddp_context_reference {
34}; 34};
35 35
36extern struct qeth_eddp_context * 36extern struct qeth_eddp_context *
37qeth_eddp_create_context(struct qeth_card *,struct sk_buff *,struct qeth_hdr *); 37qeth_eddp_create_context(struct qeth_card *,struct sk_buff *,
38 struct qeth_hdr *, unsigned char);
38 39
39extern void 40extern void
40qeth_eddp_put_context(struct qeth_eddp_context *); 41qeth_eddp_put_context(struct qeth_eddp_context *);
diff --git a/drivers/s390/net/qeth_main.c b/drivers/s390/net/qeth_main.c
index 6fd8870551d3..0b96d49dd636 100644
--- a/drivers/s390/net/qeth_main.c
+++ b/drivers/s390/net/qeth_main.c
@@ -1682,6 +1682,21 @@ qeth_put_reply(struct qeth_reply *reply)
1682 kfree(reply); 1682 kfree(reply);
1683} 1683}
1684 1684
1685static void
1686qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, struct qeth_card *card)
1687{
1688 int rc;
1689 int com;
1690 char * ipa_name;
1691
1692 com = cmd->hdr.command;
1693 rc = cmd->hdr.return_code;
1694 ipa_name = qeth_get_ipa_cmd_name(com);
1695
1696 PRINT_ERR("%s(x%X) for %s returned x%X \"%s\"\n", ipa_name, com,
1697 QETH_CARD_IFNAME(card), rc, qeth_get_ipa_msg(rc));
1698}
1699
1685static struct qeth_ipa_cmd * 1700static struct qeth_ipa_cmd *
1686qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob) 1701qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1687{ 1702{
@@ -1690,8 +1705,11 @@ qeth_check_ipa_data(struct qeth_card *card, struct qeth_cmd_buffer *iob)
1690 QETH_DBF_TEXT(trace,5,"chkipad"); 1705 QETH_DBF_TEXT(trace,5,"chkipad");
1691 if (IS_IPA(iob->data)){ 1706 if (IS_IPA(iob->data)){
1692 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data); 1707 cmd = (struct qeth_ipa_cmd *) PDU_ENCAPSULATION(iob->data);
1693 if (IS_IPA_REPLY(cmd)) 1708 if (IS_IPA_REPLY(cmd)) {
1709 if (cmd->hdr.return_code)
1710 qeth_issue_ipa_msg(cmd, card);
1694 return cmd; 1711 return cmd;
1712 }
1695 else { 1713 else {
1696 switch (cmd->hdr.command) { 1714 switch (cmd->hdr.command) {
1697 case IPA_CMD_STOPLAN: 1715 case IPA_CMD_STOPLAN:
@@ -2816,6 +2834,7 @@ qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2816 struct qeth_qdio_out_buffer *buf; 2834 struct qeth_qdio_out_buffer *buf;
2817 int rc; 2835 int rc;
2818 int i; 2836 int i;
2837 unsigned int qdio_flags;
2819 2838
2820 QETH_DBF_TEXT(trace, 6, "flushbuf"); 2839 QETH_DBF_TEXT(trace, 6, "flushbuf");
2821 2840
@@ -2841,7 +2860,7 @@ qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2841 if (!atomic_read(&queue->set_pci_flags_count)){ 2860 if (!atomic_read(&queue->set_pci_flags_count)){
2842 /* 2861 /*
2843 * there's no outstanding PCI any more, so we 2862 * there's no outstanding PCI any more, so we
2844 * have to request a PCI to be sure the the PCI 2863 * have to request a PCI to be sure that the PCI
2845 * will wake at some time in the future then we 2864 * will wake at some time in the future then we
2846 * can flush packed buffers that might still be 2865 * can flush packed buffers that might still be
2847 * hanging around, which can happen if no 2866 * hanging around, which can happen if no
@@ -2859,13 +2878,13 @@ qeth_flush_buffers(struct qeth_qdio_out_q *queue, int under_int,
2859 queue->card->perf_stats.outbound_do_qdio_start_time = 2878 queue->card->perf_stats.outbound_do_qdio_start_time =
2860 qeth_get_micros(); 2879 qeth_get_micros();
2861 } 2880 }
2881 qdio_flags = QDIO_FLAG_SYNC_OUTPUT;
2862 if (under_int) 2882 if (under_int)
2863 rc = do_QDIO(CARD_DDEV(queue->card), 2883 qdio_flags |= QDIO_FLAG_UNDER_INTERRUPT;
2864 QDIO_FLAG_SYNC_OUTPUT | QDIO_FLAG_UNDER_INTERRUPT, 2884 if (atomic_read(&queue->set_pci_flags_count))
2865 queue->queue_no, index, count, NULL); 2885 qdio_flags |= QDIO_FLAG_PCI_OUT;
2866 else 2886 rc = do_QDIO(CARD_DDEV(queue->card), qdio_flags,
2867 rc = do_QDIO(CARD_DDEV(queue->card), QDIO_FLAG_SYNC_OUTPUT, 2887 queue->queue_no, index, count, NULL);
2868 queue->queue_no, index, count, NULL);
2869 if (queue->card->options.performance_stats) 2888 if (queue->card->options.performance_stats)
2870 queue->card->perf_stats.outbound_do_qdio_time += 2889 queue->card->perf_stats.outbound_do_qdio_time +=
2871 qeth_get_micros() - 2890 qeth_get_micros() -
@@ -4490,7 +4509,8 @@ qeth_send_packet(struct qeth_card *card, struct sk_buff *skb)
4490 qeth_fill_header(card, hdr, new_skb, ipv, cast_type); 4509 qeth_fill_header(card, hdr, new_skb, ipv, cast_type);
4491 } 4510 }
4492 if (large_send == QETH_LARGE_SEND_EDDP) { 4511 if (large_send == QETH_LARGE_SEND_EDDP) {
4493 ctx = qeth_eddp_create_context(card, new_skb, hdr); 4512 ctx = qeth_eddp_create_context(card, new_skb, hdr,
4513 skb->sk->sk_protocol);
4494 if (ctx == NULL) { 4514 if (ctx == NULL) {
4495 __qeth_free_new_skb(skb, new_skb); 4515 __qeth_free_new_skb(skb, new_skb);
4496 PRINT_WARN("could not create eddp context\n"); 4516 PRINT_WARN("could not create eddp context\n");
@@ -5948,9 +5968,6 @@ qeth_layer2_send_setmac_cb(struct qeth_card *card,
5948 cmd = (struct qeth_ipa_cmd *) data; 5968 cmd = (struct qeth_ipa_cmd *) data;
5949 if (cmd->hdr.return_code) { 5969 if (cmd->hdr.return_code) {
5950 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code); 5970 QETH_DBF_TEXT_(trace, 2, "L2er%x", cmd->hdr.return_code);
5951 PRINT_WARN("Error in registering MAC address on " \
5952 "device %s: x%x\n", CARD_BUS_ID(card),
5953 cmd->hdr.return_code);
5954 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED; 5971 card->info.mac_bits &= ~QETH_LAYER2_MAC_REGISTERED;
5955 cmd->hdr.return_code = -EIO; 5972 cmd->hdr.return_code = -EIO;
5956 } else { 5973 } else {
@@ -5985,9 +6002,6 @@ qeth_layer2_send_delmac_cb(struct qeth_card *card,
5985 QETH_DBF_TEXT(trace, 2, "L2Dmaccb"); 6002 QETH_DBF_TEXT(trace, 2, "L2Dmaccb");
5986 cmd = (struct qeth_ipa_cmd *) data; 6003 cmd = (struct qeth_ipa_cmd *) data;
5987 if (cmd->hdr.return_code) { 6004 if (cmd->hdr.return_code) {
5988 PRINT_WARN("Error in deregistering MAC address on " \
5989 "device %s: x%x\n", CARD_BUS_ID(card),
5990 cmd->hdr.return_code);
5991 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code); 6005 QETH_DBF_TEXT_(trace, 2, "err%d", cmd->hdr.return_code);
5992 cmd->hdr.return_code = -EIO; 6006 cmd->hdr.return_code = -EIO;
5993 return 0; 6007 return 0;
@@ -6651,7 +6665,7 @@ qeth_setadpparms_change_macaddr_cb(struct qeth_card *card,
6651 QETH_DBF_TEXT(trace,4,"chgmaccb"); 6665 QETH_DBF_TEXT(trace,4,"chgmaccb");
6652 6666
6653 cmd = (struct qeth_ipa_cmd *) data; 6667 cmd = (struct qeth_ipa_cmd *) data;
6654 if (!card->options.layer2 || card->info.guestlan || 6668 if (!card->options.layer2 ||
6655 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) { 6669 !(card->info.mac_bits & QETH_LAYER2_MAC_READ)) {
6656 memcpy(card->dev->dev_addr, 6670 memcpy(card->dev->dev_addr,
6657 &cmd->data.setadapterparms.data.change_addr.addr, 6671 &cmd->data.setadapterparms.data.change_addr.addr,
@@ -8497,6 +8511,7 @@ __qeth_reboot_event_card(struct device *dev, void *data)
8497 card = (struct qeth_card *) dev->driver_data; 8511 card = (struct qeth_card *) dev->driver_data;
8498 qeth_clear_ip_list(card, 0, 0); 8512 qeth_clear_ip_list(card, 0, 0);
8499 qeth_qdio_clear_card(card, 0); 8513 qeth_qdio_clear_card(card, 0);
8514 qeth_clear_qdio_buffers(card);
8500 return 0; 8515 return 0;
8501} 8516}
8502 8517
diff --git a/drivers/s390/net/qeth_mpc.c b/drivers/s390/net/qeth_mpc.c
index 77c83209d70e..f29a4bc4f6f2 100644
--- a/drivers/s390/net/qeth_mpc.c
+++ b/drivers/s390/net/qeth_mpc.c
@@ -157,12 +157,113 @@ unsigned char READ_CCW[]={
157}; 157};
158 158
159 159
160struct ipa_rc_msg {
161 enum qeth_ipa_return_codes rc;
162 char *msg;
163};
160 164
165static struct ipa_rc_msg qeth_ipa_rc_msg[] = {
166 {IPA_RC_SUCCESS, "success"},
167 {IPA_RC_NOTSUPP, "Command not supported"},
168 {IPA_RC_IP_TABLE_FULL, "Add Addr IP Table Full - ipv6"},
169 {IPA_RC_UNKNOWN_ERROR, "IPA command failed - reason unknown"},
170 {IPA_RC_UNSUPPORTED_COMMAND, "Command not supported"},
171 {IPA_RC_DUP_IPV6_REMOTE,"ipv6 address already registered remote"},
172 {IPA_RC_DUP_IPV6_HOME, "ipv6 address already registered"},
173 {IPA_RC_UNREGISTERED_ADDR, "Address not registered"},
174 {IPA_RC_NO_ID_AVAILABLE, "No identifiers available"},
175 {IPA_RC_ID_NOT_FOUND, "Identifier not found"},
176 {IPA_RC_INVALID_IP_VERSION, "IP version incorrect"},
177 {IPA_RC_LAN_FRAME_MISMATCH, "LAN and frame mismatch"},
178 {IPA_RC_L2_UNSUPPORTED_CMD, "Unsupported layer 2 command"},
179 {IPA_RC_L2_DUP_MAC, "Duplicate MAC address"},
180 {IPA_RC_L2_ADDR_TABLE_FULL, "Layer2 address table full"},
181 {IPA_RC_L2_DUP_LAYER3_MAC, "Duplicate with layer 3 MAC"},
182 {IPA_RC_L2_GMAC_NOT_FOUND, "GMAC not found"},
183 {IPA_RC_L2_MAC_NOT_FOUND, "L2 mac address not found"},
184 {IPA_RC_L2_INVALID_VLAN_ID, "L2 invalid vlan id"},
185 {IPA_RC_L2_DUP_VLAN_ID, "L2 duplicate vlan id"},
186 {IPA_RC_L2_VLAN_ID_NOT_FOUND, "L2 vlan id not found"},
187 {IPA_RC_DATA_MISMATCH, "Data field mismatch (v4/v6 mixed)"},
188 {IPA_RC_INVALID_MTU_SIZE, "Invalid MTU size"},
189 {IPA_RC_INVALID_LANTYPE, "Invalid LAN type"},
190 {IPA_RC_INVALID_LANNUM, "Invalid LAN num"},
191 {IPA_RC_DUPLICATE_IP_ADDRESS, "Address already registered"},
192 {IPA_RC_IP_ADDR_TABLE_FULL, "IP address table full"},
193 {IPA_RC_LAN_PORT_STATE_ERROR, "LAN port state error"},
194 {IPA_RC_SETIP_NO_STARTLAN, "Setip no startlan received"},
195 {IPA_RC_SETIP_ALREADY_RECEIVED, "Setip already received"},
196 {IPA_RC_IP_ADDR_ALREADY_USED, "IP address already in use on LAN"},
197 {IPA_RC_MULTICAST_FULL, "No task available, multicast full"},
198 {IPA_RC_SETIP_INVALID_VERSION, "SETIP invalid IP version"},
199 {IPA_RC_UNSUPPORTED_SUBCMD, "Unsupported assist subcommand"},
200 {IPA_RC_ARP_ASSIST_NO_ENABLE, "Only partial success, no enable"},
201 {IPA_RC_PRIMARY_ALREADY_DEFINED,"Primary already defined"},
202 {IPA_RC_SECOND_ALREADY_DEFINED, "Secondary already defined"},
203 {IPA_RC_INVALID_SETRTG_INDICATOR,"Invalid SETRTG indicator"},
204 {IPA_RC_MC_ADDR_ALREADY_DEFINED,"Multicast address already defined"},
205 {IPA_RC_LAN_OFFLINE, "STRTLAN_LAN_DISABLED - LAN offline"},
206 {IPA_RC_INVALID_IP_VERSION2, "Invalid IP version"},
207 {IPA_RC_FFFF, "Unknown Error"}
208};
161 209
162 210
163 211
212char *
213qeth_get_ipa_msg(enum qeth_ipa_return_codes rc)
214{
215 int x = 0;
216 qeth_ipa_rc_msg[sizeof(qeth_ipa_rc_msg) /
217 sizeof(struct ipa_rc_msg) - 1].rc = rc;
218 while(qeth_ipa_rc_msg[x].rc != rc)
219 x++;
220 return qeth_ipa_rc_msg[x].msg;
221}
164 222
165 223
224struct ipa_cmd_names {
225 enum qeth_ipa_cmds cmd;
226 char *name;
227};
228
229static struct ipa_cmd_names qeth_ipa_cmd_names[] = {
230 {IPA_CMD_STARTLAN, "startlan"},
231 {IPA_CMD_STOPLAN, "stoplan"},
232 {IPA_CMD_SETVMAC, "setvmac"},
233 {IPA_CMD_DELVMAC, "delvmca"},
234 {IPA_CMD_SETGMAC, "setgmac"},
235 {IPA_CMD_DELGMAC, "delgmac"},
236 {IPA_CMD_SETVLAN, "setvlan"},
237 {IPA_CMD_DELVLAN, "delvlan"},
238 {IPA_CMD_SETCCID, "setccid"},
239 {IPA_CMD_DELCCID, "delccid"},
240 {IPA_CMD_MODCCID, "setip"},
241 {IPA_CMD_SETIP, "setip"},
242 {IPA_CMD_QIPASSIST, "qipassist"},
243 {IPA_CMD_SETASSPARMS, "setassparms"},
244 {IPA_CMD_SETIPM, "setipm"},
245 {IPA_CMD_DELIPM, "delipm"},
246 {IPA_CMD_SETRTG, "setrtg"},
247 {IPA_CMD_DELIP, "delip"},
248 {IPA_CMD_SETADAPTERPARMS, "setadapterparms"},
249 {IPA_CMD_SET_DIAG_ASS, "set_diag_ass"},
250 {IPA_CMD_CREATE_ADDR, "create_addr"},
251 {IPA_CMD_DESTROY_ADDR, "destroy_addr"},
252 {IPA_CMD_REGISTER_LOCAL_ADDR, "register_local_addr"},
253 {IPA_CMD_UNREGISTER_LOCAL_ADDR, "unregister_local_addr"},
254 {IPA_CMD_UNKNOWN, "unknown"},
255};
166 256
257char *
258qeth_get_ipa_cmd_name(enum qeth_ipa_cmds cmd)
259{
260 int x = 0;
261 qeth_ipa_cmd_names[
262 sizeof(qeth_ipa_cmd_names)/
263 sizeof(struct ipa_cmd_names)-1].cmd = cmd;
264 while(qeth_ipa_cmd_names[x].cmd != cmd)
265 x++;
266 return qeth_ipa_cmd_names[x].name;
267}
167 268
168 269
diff --git a/drivers/s390/net/qeth_mpc.h b/drivers/s390/net/qeth_mpc.h
index d74bc43da72a..1d8083c91765 100644
--- a/drivers/s390/net/qeth_mpc.h
+++ b/drivers/s390/net/qeth_mpc.h
@@ -25,14 +25,14 @@ extern unsigned char IPA_PDU_HEADER[];
25 25
26#define IPA_CMD_LENGTH (IPA_PDU_HEADER_SIZE + sizeof(struct qeth_ipa_cmd)) 26#define IPA_CMD_LENGTH (IPA_PDU_HEADER_SIZE + sizeof(struct qeth_ipa_cmd))
27 27
28#define QETH_SEQ_NO_LENGTH 4 28#define QETH_SEQ_NO_LENGTH 4
29#define QETH_MPC_TOKEN_LENGTH 4 29#define QETH_MPC_TOKEN_LENGTH 4
30#define QETH_MCL_LENGTH 4 30#define QETH_MCL_LENGTH 4
31#define OSA_ADDR_LEN 6 31#define OSA_ADDR_LEN 6
32 32
33#define QETH_TIMEOUT (10 * HZ) 33#define QETH_TIMEOUT (10 * HZ)
34#define QETH_IPA_TIMEOUT (45 * HZ) 34#define QETH_IPA_TIMEOUT (45 * HZ)
35#define QETH_IDX_COMMAND_SEQNO 0xffff0000 35#define QETH_IDX_COMMAND_SEQNO 0xffff0000
36#define SR_INFO_LEN 16 36#define SR_INFO_LEN 16
37 37
38#define QETH_CLEAR_CHANNEL_PARM -10 38#define QETH_CLEAR_CHANNEL_PARM -10
@@ -93,79 +93,107 @@ enum qeth_checksum_types {
93 */ 93 */
94#define RESET_ROUTING_FLAG 0x10 /* indicate that routing type shall be set */ 94#define RESET_ROUTING_FLAG 0x10 /* indicate that routing type shall be set */
95enum qeth_routing_types { 95enum qeth_routing_types {
96 NO_ROUTER = 0, /* TODO: set to bit flag used in IPA Command */ 96 NO_ROUTER = 0, /* TODO: set to bit flag used in IPA Command */
97 PRIMARY_ROUTER = 1, 97 PRIMARY_ROUTER = 1,
98 SECONDARY_ROUTER = 2, 98 SECONDARY_ROUTER = 2,
99 MULTICAST_ROUTER = 3, 99 MULTICAST_ROUTER = 3,
100 PRIMARY_CONNECTOR = 4, 100 PRIMARY_CONNECTOR = 4,
101 SECONDARY_CONNECTOR = 5, 101 SECONDARY_CONNECTOR = 5,
102}; 102};
103 103
104
105/* IPA Commands */ 104/* IPA Commands */
106enum qeth_ipa_cmds { 105enum qeth_ipa_cmds {
107 IPA_CMD_STARTLAN = 0x01, 106 IPA_CMD_STARTLAN = 0x01,
108 IPA_CMD_STOPLAN = 0x02, 107 IPA_CMD_STOPLAN = 0x02,
109 IPA_CMD_SETVMAC = 0x21, 108 IPA_CMD_SETVMAC = 0x21,
110 IPA_CMD_DELVMAC = 0x22, 109 IPA_CMD_DELVMAC = 0x22,
111 IPA_CMD_SETGMAC = 0x23, 110 IPA_CMD_SETGMAC = 0x23,
112 IPA_CMD_DELGMAC = 0x24, 111 IPA_CMD_DELGMAC = 0x24,
113 IPA_CMD_SETVLAN = 0x25, 112 IPA_CMD_SETVLAN = 0x25,
114 IPA_CMD_DELVLAN = 0x26, 113 IPA_CMD_DELVLAN = 0x26,
115 IPA_CMD_SETCCID = 0x41, 114 IPA_CMD_SETCCID = 0x41,
116 IPA_CMD_DELCCID = 0x42, 115 IPA_CMD_DELCCID = 0x42,
117 IPA_CMD_MODCCID = 0x43, 116 IPA_CMD_MODCCID = 0x43,
118 IPA_CMD_SETIP = 0xb1, 117 IPA_CMD_SETIP = 0xb1,
119 IPA_CMD_DELIP = 0xb7, 118 IPA_CMD_QIPASSIST = 0xb2,
120 IPA_CMD_QIPASSIST = 0xb2, 119 IPA_CMD_SETASSPARMS = 0xb3,
121 IPA_CMD_SETASSPARMS = 0xb3, 120 IPA_CMD_SETIPM = 0xb4,
122 IPA_CMD_SETIPM = 0xb4, 121 IPA_CMD_DELIPM = 0xb5,
123 IPA_CMD_DELIPM = 0xb5, 122 IPA_CMD_SETRTG = 0xb6,
124 IPA_CMD_SETRTG = 0xb6, 123 IPA_CMD_DELIP = 0xb7,
125 IPA_CMD_SETADAPTERPARMS = 0xb8, 124 IPA_CMD_SETADAPTERPARMS = 0xb8,
126 IPA_CMD_IPFRAME = 0xb9, 125 IPA_CMD_SET_DIAG_ASS = 0xb9,
127 IPA_CMD_ADD_ADDR_ENTRY = 0xc1, 126 IPA_CMD_CREATE_ADDR = 0xc3,
128 IPA_CMD_DELETE_ADDR_ENTRY = 0xc2, 127 IPA_CMD_DESTROY_ADDR = 0xc4,
129 IPA_CMD_CREATE_ADDR = 0xc3, 128 IPA_CMD_REGISTER_LOCAL_ADDR = 0xd1,
130 IPA_CMD_DESTROY_ADDR = 0xc4, 129 IPA_CMD_UNREGISTER_LOCAL_ADDR = 0xd2,
131 IPA_CMD_REGISTER_LOCAL_ADDR = 0xd1, 130 IPA_CMD_UNKNOWN = 0x00
132 IPA_CMD_UNREGISTER_LOCAL_ADDR = 0xd2,
133}; 131};
134 132
135enum qeth_ip_ass_cmds { 133enum qeth_ip_ass_cmds {
136 IPA_CMD_ASS_START = 0x0001, 134 IPA_CMD_ASS_START = 0x0001,
137 IPA_CMD_ASS_STOP = 0x0002, 135 IPA_CMD_ASS_STOP = 0x0002,
138 IPA_CMD_ASS_CONFIGURE = 0x0003, 136 IPA_CMD_ASS_CONFIGURE = 0x0003,
139 IPA_CMD_ASS_ENABLE = 0x0004, 137 IPA_CMD_ASS_ENABLE = 0x0004,
140}; 138};
141 139
142enum qeth_arp_process_subcmds { 140enum qeth_arp_process_subcmds {
143 IPA_CMD_ASS_ARP_SET_NO_ENTRIES = 0x0003, 141 IPA_CMD_ASS_ARP_SET_NO_ENTRIES = 0x0003,
144 IPA_CMD_ASS_ARP_QUERY_CACHE = 0x0004, 142 IPA_CMD_ASS_ARP_QUERY_CACHE = 0x0004,
145 IPA_CMD_ASS_ARP_ADD_ENTRY = 0x0005, 143 IPA_CMD_ASS_ARP_ADD_ENTRY = 0x0005,
146 IPA_CMD_ASS_ARP_REMOVE_ENTRY = 0x0006, 144 IPA_CMD_ASS_ARP_REMOVE_ENTRY = 0x0006,
147 IPA_CMD_ASS_ARP_FLUSH_CACHE = 0x0007, 145 IPA_CMD_ASS_ARP_FLUSH_CACHE = 0x0007,
148 IPA_CMD_ASS_ARP_QUERY_INFO = 0x0104, 146 IPA_CMD_ASS_ARP_QUERY_INFO = 0x0104,
149 IPA_CMD_ASS_ARP_QUERY_STATS = 0x0204, 147 IPA_CMD_ASS_ARP_QUERY_STATS = 0x0204,
150}; 148};
151 149
152/* Return Codes for IPA Commands */ 150
151/* Return Codes for IPA Commands
152 * according to OSA card Specs */
153
153enum qeth_ipa_return_codes { 154enum qeth_ipa_return_codes {
154 IPA_RC_SUCCESS = 0x0000, 155 IPA_RC_SUCCESS = 0x0000,
155 IPA_RC_NOTSUPP = 0x0001, 156 IPA_RC_NOTSUPP = 0x0001,
156 IPA_RC_NO_ACCESS = 0x0002, 157 IPA_RC_IP_TABLE_FULL = 0x0002,
157 IPA_RC_FAILED = 0x0003, 158 IPA_RC_UNKNOWN_ERROR = 0x0003,
158 IPA_RC_DATA_MISMATCH = 0xe001, 159 IPA_RC_UNSUPPORTED_COMMAND = 0x0004,
159 IPA_RC_INVALID_LAN_TYPE = 0xe003, 160 IPA_RC_DUP_IPV6_REMOTE = 0x0008,
160 IPA_RC_INVALID_LAN_NO = 0xe004, 161 IPA_RC_DUP_IPV6_HOME = 0x0010,
161 IPA_RC_IPADDR_ALREADY_REG = 0xe005, 162 IPA_RC_UNREGISTERED_ADDR = 0x0011,
162 IPA_RC_IPADDR_TABLE_FULL = 0xe006, 163 IPA_RC_NO_ID_AVAILABLE = 0x0012,
163 IPA_RC_IPADDR_ALREADY_USED = 0xe00a, 164 IPA_RC_ID_NOT_FOUND = 0x0013,
164 IPA_RC_ASSNO_NOT_SUPP = 0xe00d, 165 IPA_RC_INVALID_IP_VERSION = 0x0020,
165 IPA_RC_ASSCMD_START_FAILED = 0xe00e, 166 IPA_RC_LAN_FRAME_MISMATCH = 0x0040,
166 IPA_RC_ASSCMD_PART_SUCCESS = 0xe00f, 167 IPA_RC_L2_UNSUPPORTED_CMD = 0x2003,
167 IPA_RC_IPADDR_NOT_DEFINED = 0xe010, 168 IPA_RC_L2_DUP_MAC = 0x2005,
168 IPA_RC_LAN_OFFLINE = 0xe080, 169 IPA_RC_L2_ADDR_TABLE_FULL = 0x2006,
170 IPA_RC_L2_DUP_LAYER3_MAC = 0x200a,
171 IPA_RC_L2_GMAC_NOT_FOUND = 0x200b,
172 IPA_RC_L2_MAC_NOT_FOUND = 0x2010,
173 IPA_RC_L2_INVALID_VLAN_ID = 0x2015,
174 IPA_RC_L2_DUP_VLAN_ID = 0x2016,
175 IPA_RC_L2_VLAN_ID_NOT_FOUND = 0x2017,
176 IPA_RC_DATA_MISMATCH = 0xe001,
177 IPA_RC_INVALID_MTU_SIZE = 0xe002,
178 IPA_RC_INVALID_LANTYPE = 0xe003,
179 IPA_RC_INVALID_LANNUM = 0xe004,
180 IPA_RC_DUPLICATE_IP_ADDRESS = 0xe005,
181 IPA_RC_IP_ADDR_TABLE_FULL = 0xe006,
182 IPA_RC_LAN_PORT_STATE_ERROR = 0xe007,
183 IPA_RC_SETIP_NO_STARTLAN = 0xe008,
184 IPA_RC_SETIP_ALREADY_RECEIVED = 0xe009,
185 IPA_RC_IP_ADDR_ALREADY_USED = 0xe00a,
186 IPA_RC_MULTICAST_FULL = 0xe00b,
187 IPA_RC_SETIP_INVALID_VERSION = 0xe00d,
188 IPA_RC_UNSUPPORTED_SUBCMD = 0xe00e,
189 IPA_RC_ARP_ASSIST_NO_ENABLE = 0xe00f,
190 IPA_RC_PRIMARY_ALREADY_DEFINED = 0xe010,
191 IPA_RC_SECOND_ALREADY_DEFINED = 0xe011,
192 IPA_RC_INVALID_SETRTG_INDICATOR = 0xe012,
193 IPA_RC_MC_ADDR_ALREADY_DEFINED = 0xe013,
194 IPA_RC_LAN_OFFLINE = 0xe080,
195 IPA_RC_INVALID_IP_VERSION2 = 0xf001,
196 IPA_RC_FFFF = 0xffff
169}; 197};
170 198
171/* IPA function flags; each flag marks availability of respective function */ 199/* IPA function flags; each flag marks availability of respective function */
@@ -183,7 +211,9 @@ enum qeth_ipa_funcs {
183 IPA_SETADAPTERPARMS = 0x00000400L, 211 IPA_SETADAPTERPARMS = 0x00000400L,
184 IPA_VLAN_PRIO = 0x00000800L, 212 IPA_VLAN_PRIO = 0x00000800L,
185 IPA_PASSTHRU = 0x00001000L, 213 IPA_PASSTHRU = 0x00001000L,
214 IPA_FLUSH_ARP_SUPPORT = 0x00002000L,
186 IPA_FULL_VLAN = 0x00004000L, 215 IPA_FULL_VLAN = 0x00004000L,
216 IPA_INBOUND_PASSTHRU = 0x00008000L,
187 IPA_SOURCE_MAC = 0x00010000L, 217 IPA_SOURCE_MAC = 0x00010000L,
188 IPA_OSA_MC_ROUTER = 0x00020000L, 218 IPA_OSA_MC_ROUTER = 0x00020000L,
189 IPA_QUERY_ARP_ASSIST = 0x00040000L, 219 IPA_QUERY_ARP_ASSIST = 0x00040000L,
@@ -204,31 +234,30 @@ enum qeth_ipa_setdelip_flags {
204/* SETADAPTER IPA Command: ****************************************************/ 234/* SETADAPTER IPA Command: ****************************************************/
205enum qeth_ipa_setadp_cmd { 235enum qeth_ipa_setadp_cmd {
206 IPA_SETADP_QUERY_COMMANDS_SUPPORTED = 0x01, 236 IPA_SETADP_QUERY_COMMANDS_SUPPORTED = 0x01,
207 IPA_SETADP_ALTER_MAC_ADDRESS = 0x02, 237 IPA_SETADP_ALTER_MAC_ADDRESS = 0x02,
208 IPA_SETADP_ADD_DELETE_GROUP_ADDRESS = 0x04, 238 IPA_SETADP_ADD_DELETE_GROUP_ADDRESS = 0x04,
209 IPA_SETADP_ADD_DELETE_FUNCTIONAL_ADDR = 0x08, 239 IPA_SETADP_ADD_DELETE_FUNCTIONAL_ADDR = 0x08,
210 IPA_SETADP_SET_ADDRESSING_MODE = 0x10, 240 IPA_SETADP_SET_ADDRESSING_MODE = 0x10,
211 IPA_SETADP_SET_CONFIG_PARMS = 0x20, 241 IPA_SETADP_SET_CONFIG_PARMS = 0x20,
212 IPA_SETADP_SET_CONFIG_PARMS_EXTENDED = 0x40, 242 IPA_SETADP_SET_CONFIG_PARMS_EXTENDED = 0x40,
213 IPA_SETADP_SET_BROADCAST_MODE = 0x80, 243 IPA_SETADP_SET_BROADCAST_MODE = 0x80,
214 IPA_SETADP_SEND_OSA_MESSAGE = 0x0100, 244 IPA_SETADP_SEND_OSA_MESSAGE = 0x0100,
215 IPA_SETADP_SET_SNMP_CONTROL = 0x0200, 245 IPA_SETADP_SET_SNMP_CONTROL = 0x0200,
216 IPA_SETADP_READ_SNMP_PARMS = 0x0400, 246 IPA_SETADP_QUERY_CARD_INFO = 0x0400,
217 IPA_SETADP_SET_PROMISC_MODE = 0x0800, 247 IPA_SETADP_SET_PROMISC_MODE = 0x0800,
218 IPA_SETADP_QUERY_CARD_INFO = 0x1000,
219}; 248};
220enum qeth_ipa_mac_ops { 249enum qeth_ipa_mac_ops {
221 CHANGE_ADDR_READ_MAC = 0, 250 CHANGE_ADDR_READ_MAC = 0,
222 CHANGE_ADDR_REPLACE_MAC = 1, 251 CHANGE_ADDR_REPLACE_MAC = 1,
223 CHANGE_ADDR_ADD_MAC = 2, 252 CHANGE_ADDR_ADD_MAC = 2,
224 CHANGE_ADDR_DEL_MAC = 4, 253 CHANGE_ADDR_DEL_MAC = 4,
225 CHANGE_ADDR_RESET_MAC = 8, 254 CHANGE_ADDR_RESET_MAC = 8,
226}; 255};
227enum qeth_ipa_addr_ops { 256enum qeth_ipa_addr_ops {
228 CHANGE_ADDR_READ_ADDR = 0, 257 CHANGE_ADDR_READ_ADDR = 0,
229 CHANGE_ADDR_ADD_ADDR = 1, 258 CHANGE_ADDR_ADD_ADDR = 1,
230 CHANGE_ADDR_DEL_ADDR = 2, 259 CHANGE_ADDR_DEL_ADDR = 2,
231 CHANGE_ADDR_FLUSH_ADDR_TABLE = 4, 260 CHANGE_ADDR_FLUSH_ADDR_TABLE = 4,
232}; 261};
233enum qeth_ipa_promisc_modes { 262enum qeth_ipa_promisc_modes {
234 SET_PROMISC_MODE_OFF = 0, 263 SET_PROMISC_MODE_OFF = 0,
@@ -407,15 +436,15 @@ struct qeth_ipacmd_hdr {
407struct qeth_ipa_cmd { 436struct qeth_ipa_cmd {
408 struct qeth_ipacmd_hdr hdr; 437 struct qeth_ipacmd_hdr hdr;
409 union { 438 union {
410 struct qeth_ipacmd_setdelip4 setdelip4; 439 struct qeth_ipacmd_setdelip4 setdelip4;
411 struct qeth_ipacmd_setdelip6 setdelip6; 440 struct qeth_ipacmd_setdelip6 setdelip6;
412 struct qeth_ipacmd_setdelipm setdelipm; 441 struct qeth_ipacmd_setdelipm setdelipm;
413 struct qeth_ipacmd_setassparms setassparms; 442 struct qeth_ipacmd_setassparms setassparms;
414 struct qeth_ipacmd_layer2setdelmac setdelmac; 443 struct qeth_ipacmd_layer2setdelmac setdelmac;
415 struct qeth_ipacmd_layer2setdelvlan setdelvlan; 444 struct qeth_ipacmd_layer2setdelvlan setdelvlan;
416 struct qeth_create_destroy_address create_destroy_addr; 445 struct qeth_create_destroy_address create_destroy_addr;
417 struct qeth_ipacmd_setadpparms setadapterparms; 446 struct qeth_ipacmd_setadpparms setadapterparms;
418 struct qeth_set_routing setrtg; 447 struct qeth_set_routing setrtg;
419 } data; 448 } data;
420} __attribute__ ((packed)); 449} __attribute__ ((packed));
421 450
@@ -433,6 +462,12 @@ enum qeth_ipa_arp_return_codes {
433 QETH_IPA_ARP_RC_Q_NO_DATA = 0x0008, 462 QETH_IPA_ARP_RC_Q_NO_DATA = 0x0008,
434}; 463};
435 464
465
466extern char *
467qeth_get_ipa_msg(enum qeth_ipa_return_codes rc);
468extern char *
469qeth_get_ipa_cmd_name(enum qeth_ipa_cmds cmd);
470
436#define QETH_SETASS_BASE_LEN (sizeof(struct qeth_ipacmd_hdr) + \ 471#define QETH_SETASS_BASE_LEN (sizeof(struct qeth_ipacmd_hdr) + \
437 sizeof(struct qeth_ipacmd_setassparms_hdr)) 472 sizeof(struct qeth_ipacmd_setassparms_hdr))
438#define QETH_IPA_ARP_DATA_POS(buffer) (buffer + IPA_PDU_HEADER_SIZE + \ 473#define QETH_IPA_ARP_DATA_POS(buffer) (buffer + IPA_PDU_HEADER_SIZE + \
@@ -521,7 +556,7 @@ extern unsigned char DM_ACT[];
521extern unsigned char IDX_ACTIVATE_READ[]; 556extern unsigned char IDX_ACTIVATE_READ[];
522extern unsigned char IDX_ACTIVATE_WRITE[]; 557extern unsigned char IDX_ACTIVATE_WRITE[];
523 558
524#define IDX_ACTIVATE_SIZE 0x22 559#define IDX_ACTIVATE_SIZE 0x22
525#define QETH_IDX_ACT_ISSUER_RM_TOKEN(buffer) (buffer+0x0c) 560#define QETH_IDX_ACT_ISSUER_RM_TOKEN(buffer) (buffer+0x0c)
526#define QETH_IDX_NO_PORTNAME_REQUIRED(buffer) ((buffer)[0x0b]&0x80) 561#define QETH_IDX_NO_PORTNAME_REQUIRED(buffer) ((buffer)[0x0b]&0x80)
527#define QETH_IDX_ACT_FUNC_LEVEL(buffer) (buffer+0x10) 562#define QETH_IDX_ACT_FUNC_LEVEL(buffer) (buffer+0x10)
diff --git a/drivers/s390/net/qeth_sys.c b/drivers/s390/net/qeth_sys.c
index d518419cd0c6..65ffc21afc37 100644
--- a/drivers/s390/net/qeth_sys.c
+++ b/drivers/s390/net/qeth_sys.c
@@ -384,8 +384,6 @@ qeth_dev_route_store(struct qeth_card *card, struct qeth_routing_info *route,
384 route->type = PRIMARY_CONNECTOR; 384 route->type = PRIMARY_CONNECTOR;
385 } else if (!strcmp(tmp, "secondary_connector")) { 385 } else if (!strcmp(tmp, "secondary_connector")) {
386 route->type = SECONDARY_CONNECTOR; 386 route->type = SECONDARY_CONNECTOR;
387 } else if (!strcmp(tmp, "multicast_router")) {
388 route->type = MULTICAST_ROUTER;
389 } else if (!strcmp(tmp, "primary_router")) { 387 } else if (!strcmp(tmp, "primary_router")) {
390 route->type = PRIMARY_ROUTER; 388 route->type = PRIMARY_ROUTER;
391 } else if (!strcmp(tmp, "secondary_router")) { 389 } else if (!strcmp(tmp, "secondary_router")) {
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 1f9554e08013..ddff40c4212c 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -118,97 +118,32 @@ _zfcp_hex_dump(char *addr, int count)
118 118
119#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF 119#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FSF
120 120
121static int zfcp_reqlist_init(struct zfcp_adapter *adapter) 121static int zfcp_reqlist_alloc(struct zfcp_adapter *adapter)
122{ 122{
123 int i; 123 int idx;
124 124
125 adapter->req_list = kcalloc(REQUEST_LIST_SIZE, sizeof(struct list_head), 125 adapter->req_list = kcalloc(REQUEST_LIST_SIZE, sizeof(struct list_head),
126 GFP_KERNEL); 126 GFP_KERNEL);
127
128 if (!adapter->req_list) 127 if (!adapter->req_list)
129 return -ENOMEM; 128 return -ENOMEM;
130 129
131 for (i=0; i<REQUEST_LIST_SIZE; i++) 130 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++)
132 INIT_LIST_HEAD(&adapter->req_list[i]); 131 INIT_LIST_HEAD(&adapter->req_list[idx]);
133
134 return 0; 132 return 0;
135} 133}
136 134
137static void zfcp_reqlist_free(struct zfcp_adapter *adapter) 135static void zfcp_reqlist_free(struct zfcp_adapter *adapter)
138{ 136{
139 struct zfcp_fsf_req *request, *tmp;
140 unsigned int i;
141
142 for (i=0; i<REQUEST_LIST_SIZE; i++) {
143 if (list_empty(&adapter->req_list[i]))
144 continue;
145
146 list_for_each_entry_safe(request, tmp,
147 &adapter->req_list[i], list)
148 list_del(&request->list);
149 }
150
151 kfree(adapter->req_list); 137 kfree(adapter->req_list);
152} 138}
153 139
154void zfcp_reqlist_add(struct zfcp_adapter *adapter,
155 struct zfcp_fsf_req *fsf_req)
156{
157 unsigned int i;
158
159 i = fsf_req->req_id % REQUEST_LIST_SIZE;
160 list_add_tail(&fsf_req->list, &adapter->req_list[i]);
161}
162
163void zfcp_reqlist_remove(struct zfcp_adapter *adapter, unsigned long req_id)
164{
165 struct zfcp_fsf_req *request, *tmp;
166 unsigned int i, counter;
167 u64 dbg_tmp[2];
168
169 i = req_id % REQUEST_LIST_SIZE;
170 BUG_ON(list_empty(&adapter->req_list[i]));
171
172 counter = 0;
173 list_for_each_entry_safe(request, tmp, &adapter->req_list[i], list) {
174 if (request->req_id == req_id) {
175 dbg_tmp[0] = (u64) atomic_read(&adapter->reqs_active);
176 dbg_tmp[1] = (u64) counter;
177 debug_event(adapter->erp_dbf, 4, (void *) dbg_tmp, 16);
178 list_del(&request->list);
179 break;
180 }
181 counter++;
182 }
183}
184
185struct zfcp_fsf_req *zfcp_reqlist_ismember(struct zfcp_adapter *adapter,
186 unsigned long req_id)
187{
188 struct zfcp_fsf_req *request, *tmp;
189 unsigned int i;
190
191 /* 0 is reserved as an invalid req_id */
192 if (req_id == 0)
193 return NULL;
194
195 i = req_id % REQUEST_LIST_SIZE;
196
197 list_for_each_entry_safe(request, tmp, &adapter->req_list[i], list)
198 if (request->req_id == req_id)
199 return request;
200
201 return NULL;
202}
203
204int zfcp_reqlist_isempty(struct zfcp_adapter *adapter) 140int zfcp_reqlist_isempty(struct zfcp_adapter *adapter)
205{ 141{
206 unsigned int i; 142 unsigned int idx;
207 143
208 for (i=0; i<REQUEST_LIST_SIZE; i++) 144 for (idx = 0; idx < REQUEST_LIST_SIZE; idx++)
209 if (!list_empty(&adapter->req_list[i])) 145 if (!list_empty(&adapter->req_list[idx]))
210 return 0; 146 return 0;
211
212 return 1; 147 return 1;
213} 148}
214 149
@@ -672,8 +607,7 @@ zfcp_sg_list_free(struct zfcp_sg_list *sg_list)
672 * @sg_count: elements in array 607 * @sg_count: elements in array
673 * Return: size of entire scatter-gather list 608 * Return: size of entire scatter-gather list
674 */ 609 */
675size_t 610static size_t zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count)
676zfcp_sg_size(struct scatterlist *sg, unsigned int sg_count)
677{ 611{
678 unsigned int i; 612 unsigned int i;
679 struct scatterlist *p; 613 struct scatterlist *p;
@@ -913,6 +847,8 @@ zfcp_unit_enqueue(struct zfcp_port *port, fcp_lun_t fcp_lun)
913 unit->sysfs_device.release = zfcp_sysfs_unit_release; 847 unit->sysfs_device.release = zfcp_sysfs_unit_release;
914 dev_set_drvdata(&unit->sysfs_device, unit); 848 dev_set_drvdata(&unit->sysfs_device, unit);
915 849
850 init_waitqueue_head(&unit->scsi_scan_wq);
851
916 /* mark unit unusable as long as sysfs registration is not complete */ 852 /* mark unit unusable as long as sysfs registration is not complete */
917 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status); 853 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
918 854
@@ -1038,8 +974,7 @@ zfcp_free_low_mem_buffers(struct zfcp_adapter *adapter)
1038 mempool_destroy(adapter->pool.data_gid_pn); 974 mempool_destroy(adapter->pool.data_gid_pn);
1039} 975}
1040 976
1041void 977static void zfcp_dummy_release(struct device *dev)
1042zfcp_dummy_release(struct device *dev)
1043{ 978{
1044 return; 979 return;
1045} 980}
@@ -1104,7 +1039,7 @@ zfcp_adapter_enqueue(struct ccw_device *ccw_device)
1104 1039
1105 /* initialize list of fsf requests */ 1040 /* initialize list of fsf requests */
1106 spin_lock_init(&adapter->req_list_lock); 1041 spin_lock_init(&adapter->req_list_lock);
1107 retval = zfcp_reqlist_init(adapter); 1042 retval = zfcp_reqlist_alloc(adapter);
1108 if (retval) { 1043 if (retval) {
1109 ZFCP_LOG_INFO("request list initialization failed\n"); 1044 ZFCP_LOG_INFO("request list initialization failed\n");
1110 goto failed_low_mem_buffers; 1045 goto failed_low_mem_buffers;
@@ -1165,6 +1100,7 @@ zfcp_adapter_enqueue(struct ccw_device *ccw_device)
1165 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev); 1100 zfcp_sysfs_adapter_remove_files(&adapter->ccw_device->dev);
1166 sysfs_failed: 1101 sysfs_failed:
1167 dev_set_drvdata(&ccw_device->dev, NULL); 1102 dev_set_drvdata(&ccw_device->dev, NULL);
1103 zfcp_reqlist_free(adapter);
1168 failed_low_mem_buffers: 1104 failed_low_mem_buffers:
1169 zfcp_free_low_mem_buffers(adapter); 1105 zfcp_free_low_mem_buffers(adapter);
1170 if (qdio_free(ccw_device) != 0) 1106 if (qdio_free(ccw_device) != 0)
@@ -1398,7 +1334,7 @@ zfcp_nameserver_enqueue(struct zfcp_adapter *adapter)
1398 1334
1399#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC 1335#define ZFCP_LOG_AREA ZFCP_LOG_AREA_FC
1400 1336
1401void 1337static void
1402zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter, 1338zfcp_fsf_incoming_els_rscn(struct zfcp_adapter *adapter,
1403 struct fsf_status_read_buffer *status_buffer) 1339 struct fsf_status_read_buffer *status_buffer)
1404{ 1340{
@@ -1497,7 +1433,7 @@ zfcp_fsf_incoming_els_plogi(struct zfcp_adapter *adapter,
1497 1433
1498 if (!port || (port->wwpn != (*(wwn_t *) &els_plogi->serv_param.wwpn))) { 1434 if (!port || (port->wwpn != (*(wwn_t *) &els_plogi->serv_param.wwpn))) {
1499 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port " 1435 ZFCP_LOG_DEBUG("ignored incoming PLOGI for nonexisting port "
1500 "with d_id 0x%08x on adapter %s\n", 1436 "with d_id 0x%06x on adapter %s\n",
1501 status_buffer->d_id, 1437 status_buffer->d_id,
1502 zfcp_get_busid_by_adapter(adapter)); 1438 zfcp_get_busid_by_adapter(adapter));
1503 } else { 1439 } else {
@@ -1522,7 +1458,7 @@ zfcp_fsf_incoming_els_logo(struct zfcp_adapter *adapter,
1522 1458
1523 if (!port || (port->wwpn != els_logo->nport_wwpn)) { 1459 if (!port || (port->wwpn != els_logo->nport_wwpn)) {
1524 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port " 1460 ZFCP_LOG_DEBUG("ignored incoming LOGO for nonexisting port "
1525 "with d_id 0x%08x on adapter %s\n", 1461 "with d_id 0x%06x on adapter %s\n",
1526 status_buffer->d_id, 1462 status_buffer->d_id,
1527 zfcp_get_busid_by_adapter(adapter)); 1463 zfcp_get_busid_by_adapter(adapter));
1528 } else { 1464 } else {
@@ -1704,7 +1640,7 @@ static void zfcp_ns_gid_pn_handler(unsigned long data)
1704 /* looks like a valid d_id */ 1640 /* looks like a valid d_id */
1705 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK; 1641 port->d_id = ct_iu_resp->d_id & ZFCP_DID_MASK;
1706 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status); 1642 atomic_set_mask(ZFCP_STATUS_PORT_DID_DID, &port->status);
1707 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%08x\n", 1643 ZFCP_LOG_DEBUG("adapter %s: wwpn=0x%016Lx ---> d_id=0x%06x\n",
1708 zfcp_get_busid_by_port(port), port->wwpn, port->d_id); 1644 zfcp_get_busid_by_port(port), port->wwpn, port->d_id);
1709 goto out; 1645 goto out;
1710 1646
diff --git a/drivers/s390/scsi/zfcp_dbf.c b/drivers/s390/scsi/zfcp_dbf.c
index d8191d115c14..5f3212440f68 100644
--- a/drivers/s390/scsi/zfcp_dbf.c
+++ b/drivers/s390/scsi/zfcp_dbf.c
@@ -478,7 +478,7 @@ static struct debug_view zfcp_hba_dbf_view = {
478 NULL 478 NULL
479}; 479};
480 480
481void 481static void
482_zfcp_san_dbf_event_common_ct(const char *tag, struct zfcp_fsf_req *fsf_req, 482_zfcp_san_dbf_event_common_ct(const char *tag, struct zfcp_fsf_req *fsf_req,
483 u32 s_id, u32 d_id, void *buffer, int buflen) 483 u32 s_id, u32 d_id, void *buffer, int buflen)
484{ 484{
diff --git a/drivers/s390/scsi/zfcp_def.h b/drivers/s390/scsi/zfcp_def.h
index 32933ed54b8a..22649639230b 100644
--- a/drivers/s390/scsi/zfcp_def.h
+++ b/drivers/s390/scsi/zfcp_def.h
@@ -637,6 +637,7 @@ do { \
637#define ZFCP_STATUS_UNIT_SHARED 0x00000004 637#define ZFCP_STATUS_UNIT_SHARED 0x00000004
638#define ZFCP_STATUS_UNIT_READONLY 0x00000008 638#define ZFCP_STATUS_UNIT_READONLY 0x00000008
639#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010 639#define ZFCP_STATUS_UNIT_REGISTERED 0x00000010
640#define ZFCP_STATUS_UNIT_SCSI_WORK_PENDING 0x00000020
640 641
641/* FSF request status (this does not have a common part) */ 642/* FSF request status (this does not have a common part) */
642#define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000 643#define ZFCP_STATUS_FSFREQ_NOT_INIT 0x00000000
@@ -980,6 +981,10 @@ struct zfcp_unit {
980 struct scsi_device *device; /* scsi device struct pointer */ 981 struct scsi_device *device; /* scsi device struct pointer */
981 struct zfcp_erp_action erp_action; /* pending error recovery */ 982 struct zfcp_erp_action erp_action; /* pending error recovery */
982 atomic_t erp_counter; 983 atomic_t erp_counter;
984 wait_queue_head_t scsi_scan_wq; /* can be used to wait until
985 all scsi_scan_target
986 requests have been
987 completed. */
983}; 988};
984 989
985/* FSF request */ 990/* FSF request */
@@ -1085,6 +1090,42 @@ extern void _zfcp_hex_dump(char *, int);
1085#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port)) 1090#define zfcp_get_busid_by_unit(unit) (zfcp_get_busid_by_port(unit->port))
1086 1091
1087/* 1092/*
1093 * Helper functions for request ID management.
1094 */
1095static inline int zfcp_reqlist_hash(unsigned long req_id)
1096{
1097 return req_id % REQUEST_LIST_SIZE;
1098}
1099
1100static inline void zfcp_reqlist_add(struct zfcp_adapter *adapter,
1101 struct zfcp_fsf_req *fsf_req)
1102{
1103 unsigned int idx;
1104
1105 idx = zfcp_reqlist_hash(fsf_req->req_id);
1106 list_add_tail(&fsf_req->list, &adapter->req_list[idx]);
1107}
1108
1109static inline void zfcp_reqlist_remove(struct zfcp_adapter *adapter,
1110 struct zfcp_fsf_req *fsf_req)
1111{
1112 list_del(&fsf_req->list);
1113}
1114
1115static inline struct zfcp_fsf_req *
1116zfcp_reqlist_find(struct zfcp_adapter *adapter, unsigned long req_id)
1117{
1118 struct zfcp_fsf_req *request;
1119 unsigned int idx;
1120
1121 idx = zfcp_reqlist_hash(req_id);
1122 list_for_each_entry(request, &adapter->req_list[idx], list)
1123 if (request->req_id == req_id)
1124 return request;
1125 return NULL;
1126}
1127
1128/*
1088 * functions needed for reference/usage counting 1129 * functions needed for reference/usage counting
1089 */ 1130 */
1090 1131
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index c1f2d4b14c2b..aef66bc2b6ca 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -179,7 +179,7 @@ static void zfcp_close_fsf(struct zfcp_adapter *adapter)
179static void zfcp_fsf_request_timeout_handler(unsigned long data) 179static void zfcp_fsf_request_timeout_handler(unsigned long data)
180{ 180{
181 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data; 181 struct zfcp_adapter *adapter = (struct zfcp_adapter *) data;
182 zfcp_erp_adapter_reopen(adapter, 0); 182 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED);
183} 183}
184 184
185void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout) 185void zfcp_fsf_start_timer(struct zfcp_fsf_req *fsf_req, unsigned long timeout)
@@ -342,9 +342,9 @@ zfcp_erp_adisc(struct zfcp_port *port)
342 adisc->wwpn = fc_host_port_name(adapter->scsi_host); 342 adisc->wwpn = fc_host_port_name(adapter->scsi_host);
343 adisc->wwnn = fc_host_node_name(adapter->scsi_host); 343 adisc->wwnn = fc_host_node_name(adapter->scsi_host);
344 adisc->nport_id = fc_host_port_id(adapter->scsi_host); 344 adisc->nport_id = fc_host_port_id(adapter->scsi_host);
345 ZFCP_LOG_INFO("ADISC request from s_id 0x%08x to d_id 0x%08x " 345 ZFCP_LOG_INFO("ADISC request from s_id 0x%06x to d_id 0x%06x "
346 "(wwpn=0x%016Lx, wwnn=0x%016Lx, " 346 "(wwpn=0x%016Lx, wwnn=0x%016Lx, "
347 "hard_nport_id=0x%08x, nport_id=0x%08x)\n", 347 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
348 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn, 348 adisc->nport_id, send_els->d_id, (wwn_t) adisc->wwpn,
349 (wwn_t) adisc->wwnn, adisc->hard_nport_id, 349 (wwn_t) adisc->wwnn, adisc->hard_nport_id,
350 adisc->nport_id); 350 adisc->nport_id);
@@ -352,7 +352,7 @@ zfcp_erp_adisc(struct zfcp_port *port)
352 retval = zfcp_fsf_send_els(send_els); 352 retval = zfcp_fsf_send_els(send_els);
353 if (retval != 0) { 353 if (retval != 0) {
354 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port " 354 ZFCP_LOG_NORMAL("error: initiation of Send ELS failed for port "
355 "0x%08x on adapter %s\n", send_els->d_id, 355 "0x%06x on adapter %s\n", send_els->d_id,
356 zfcp_get_busid_by_adapter(adapter)); 356 zfcp_get_busid_by_adapter(adapter));
357 goto freemem; 357 goto freemem;
358 } 358 }
@@ -398,7 +398,7 @@ zfcp_erp_adisc_handler(unsigned long data)
398 if (send_els->status != 0) { 398 if (send_els->status != 0) {
399 ZFCP_LOG_NORMAL("ELS request rejected/timed out, " 399 ZFCP_LOG_NORMAL("ELS request rejected/timed out, "
400 "force physical port reopen " 400 "force physical port reopen "
401 "(adapter %s, port d_id=0x%08x)\n", 401 "(adapter %s, port d_id=0x%06x)\n",
402 zfcp_get_busid_by_adapter(adapter), d_id); 402 zfcp_get_busid_by_adapter(adapter), d_id);
403 debug_text_event(adapter->erp_dbf, 3, "forcreop"); 403 debug_text_event(adapter->erp_dbf, 3, "forcreop");
404 if (zfcp_erp_port_forced_reopen(port, 0)) 404 if (zfcp_erp_port_forced_reopen(port, 0))
@@ -411,9 +411,9 @@ zfcp_erp_adisc_handler(unsigned long data)
411 411
412 adisc = zfcp_sg_to_address(send_els->resp); 412 adisc = zfcp_sg_to_address(send_els->resp);
413 413
414 ZFCP_LOG_INFO("ADISC response from d_id 0x%08x to s_id " 414 ZFCP_LOG_INFO("ADISC response from d_id 0x%06x to s_id "
415 "0x%08x (wwpn=0x%016Lx, wwnn=0x%016Lx, " 415 "0x%06x (wwpn=0x%016Lx, wwnn=0x%016Lx, "
416 "hard_nport_id=0x%08x, nport_id=0x%08x)\n", 416 "hard_nport_id=0x%06x, nport_id=0x%06x)\n",
417 d_id, fc_host_port_id(adapter->scsi_host), 417 d_id, fc_host_port_id(adapter->scsi_host),
418 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn, 418 (wwn_t) adisc->wwpn, (wwn_t) adisc->wwnn,
419 adisc->hard_nport_id, adisc->nport_id); 419 adisc->hard_nport_id, adisc->nport_id);
@@ -847,8 +847,7 @@ zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
847 if (erp_action->fsf_req) { 847 if (erp_action->fsf_req) {
848 /* take lock to ensure that request is not deleted meanwhile */ 848 /* take lock to ensure that request is not deleted meanwhile */
849 spin_lock(&adapter->req_list_lock); 849 spin_lock(&adapter->req_list_lock);
850 if (zfcp_reqlist_ismember(adapter, 850 if (zfcp_reqlist_find(adapter, erp_action->fsf_req->req_id)) {
851 erp_action->fsf_req->req_id)) {
852 /* fsf_req still exists */ 851 /* fsf_req still exists */
853 debug_text_event(adapter->erp_dbf, 3, "a_ca_req"); 852 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
854 debug_event(adapter->erp_dbf, 3, &erp_action->fsf_req, 853 debug_event(adapter->erp_dbf, 3, &erp_action->fsf_req,
@@ -1377,7 +1376,7 @@ zfcp_erp_port_failed(struct zfcp_port *port)
1377 1376
1378 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status)) 1377 if (atomic_test_mask(ZFCP_STATUS_PORT_WKA, &port->status))
1379 ZFCP_LOG_NORMAL("port erp failed (adapter %s, " 1378 ZFCP_LOG_NORMAL("port erp failed (adapter %s, "
1380 "port d_id=0x%08x)\n", 1379 "port d_id=0x%06x)\n",
1381 zfcp_get_busid_by_port(port), port->d_id); 1380 zfcp_get_busid_by_port(port), port->d_id);
1382 else 1381 else
1383 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n", 1382 ZFCP_LOG_NORMAL("port erp failed (adapter %s, wwpn=0x%016Lx)\n",
@@ -1591,6 +1590,62 @@ zfcp_erp_strategy_check_adapter(struct zfcp_adapter *adapter, int result)
1591 return result; 1590 return result;
1592} 1591}
1593 1592
1593struct zfcp_erp_add_work {
1594 struct zfcp_unit *unit;
1595 struct work_struct work;
1596};
1597
1598/**
1599 * zfcp_erp_scsi_scan
1600 * @data: pointer to a struct zfcp_erp_add_work
1601 *
1602 * Registers a logical unit with the SCSI stack.
1603 */
1604static void zfcp_erp_scsi_scan(struct work_struct *work)
1605{
1606 struct zfcp_erp_add_work *p =
1607 container_of(work, struct zfcp_erp_add_work, work);
1608 struct zfcp_unit *unit = p->unit;
1609 struct fc_rport *rport = unit->port->rport;
1610 scsi_scan_target(&rport->dev, 0, rport->scsi_target_id,
1611 unit->scsi_lun, 0);
1612 atomic_clear_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1613 wake_up(&unit->scsi_scan_wq);
1614 zfcp_unit_put(unit);
1615 kfree(p);
1616}
1617
1618/**
1619 * zfcp_erp_schedule_work
1620 * @unit: pointer to unit which should be registered with SCSI stack
1621 *
1622 * Schedules work which registers a unit with the SCSI stack
1623 */
1624static void
1625zfcp_erp_schedule_work(struct zfcp_unit *unit)
1626{
1627 struct zfcp_erp_add_work *p;
1628
1629 p = kmalloc(sizeof(*p), GFP_KERNEL);
1630 if (!p) {
1631 ZFCP_LOG_NORMAL("error: Out of resources. Could not register "
1632 "the FCP-LUN 0x%Lx connected to "
1633 "the port with WWPN 0x%Lx connected to "
1634 "the adapter %s with the SCSI stack.\n",
1635 unit->fcp_lun,
1636 unit->port->wwpn,
1637 zfcp_get_busid_by_unit(unit));
1638 return;
1639 }
1640
1641 zfcp_unit_get(unit);
1642 memset(p, 0, sizeof(*p));
1643 atomic_set_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING, &unit->status);
1644 INIT_WORK(&p->work, zfcp_erp_scsi_scan);
1645 p->unit = unit;
1646 schedule_work(&p->work);
1647}
1648
1594/* 1649/*
1595 * function: 1650 * function:
1596 * 1651 *
@@ -2401,7 +2456,7 @@ zfcp_erp_port_strategy_open_common(struct zfcp_erp_action *erp_action)
2401 retval = ZFCP_ERP_FAILED; 2456 retval = ZFCP_ERP_FAILED;
2402 } 2457 }
2403 } else { 2458 } else {
2404 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> " 2459 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> "
2405 "trying open\n", port->wwpn, port->d_id); 2460 "trying open\n", port->wwpn, port->d_id);
2406 retval = zfcp_erp_port_strategy_open_port(erp_action); 2461 retval = zfcp_erp_port_strategy_open_port(erp_action);
2407 } 2462 }
@@ -2441,7 +2496,7 @@ zfcp_erp_port_strategy_open_nameserver(struct zfcp_erp_action *erp_action)
2441 case ZFCP_ERP_STEP_UNINITIALIZED: 2496 case ZFCP_ERP_STEP_UNINITIALIZED:
2442 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING: 2497 case ZFCP_ERP_STEP_PHYS_PORT_CLOSING:
2443 case ZFCP_ERP_STEP_PORT_CLOSING: 2498 case ZFCP_ERP_STEP_PORT_CLOSING:
2444 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%08x -> trying open\n", 2499 ZFCP_LOG_DEBUG("port 0x%016Lx has d_id=0x%06x -> trying open\n",
2445 port->wwpn, port->d_id); 2500 port->wwpn, port->d_id);
2446 retval = zfcp_erp_port_strategy_open_port(erp_action); 2501 retval = zfcp_erp_port_strategy_open_port(erp_action);
2447 break; 2502 break;
@@ -3092,9 +3147,9 @@ zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3092 && port->rport) { 3147 && port->rport) {
3093 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED, 3148 atomic_set_mask(ZFCP_STATUS_UNIT_REGISTERED,
3094 &unit->status); 3149 &unit->status);
3095 scsi_scan_target(&port->rport->dev, 0, 3150 if (atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
3096 port->rport->scsi_target_id, 3151 &unit->status) == 0)
3097 unit->scsi_lun, 0); 3152 zfcp_erp_schedule_work(unit);
3098 } 3153 }
3099 zfcp_unit_put(unit); 3154 zfcp_unit_put(unit);
3100 break; 3155 break;
@@ -3121,7 +3176,7 @@ zfcp_erp_action_cleanup(int action, struct zfcp_adapter *adapter,
3121 zfcp_get_busid_by_port(port), 3176 zfcp_get_busid_by_port(port),
3122 port->wwpn); 3177 port->wwpn);
3123 else { 3178 else {
3124 scsi_flush_work(adapter->scsi_host); 3179 scsi_target_unblock(&port->rport->dev);
3125 port->rport->maxframe_size = port->maxframe_size; 3180 port->rport->maxframe_size = port->maxframe_size;
3126 port->rport->supported_classes = 3181 port->rport->supported_classes =
3127 port->supported_classes; 3182 port->supported_classes;
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index 01386ac688a2..991d45667a44 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -184,10 +184,6 @@ extern void zfcp_scsi_dbf_event_abort(const char *, struct zfcp_adapter *,
184 unsigned long); 184 unsigned long);
185extern void zfcp_scsi_dbf_event_devreset(const char *, u8, struct zfcp_unit *, 185extern void zfcp_scsi_dbf_event_devreset(const char *, u8, struct zfcp_unit *,
186 struct scsi_cmnd *); 186 struct scsi_cmnd *);
187extern void zfcp_reqlist_add(struct zfcp_adapter *, struct zfcp_fsf_req *);
188extern void zfcp_reqlist_remove(struct zfcp_adapter *, unsigned long);
189extern struct zfcp_fsf_req *zfcp_reqlist_ismember(struct zfcp_adapter *,
190 unsigned long);
191extern int zfcp_reqlist_isempty(struct zfcp_adapter *); 187extern int zfcp_reqlist_isempty(struct zfcp_adapter *);
192 188
193#endif /* ZFCP_EXT_H */ 189#endif /* ZFCP_EXT_H */
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index 4c0a59afd5c8..a8b02542ac2d 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -828,7 +828,7 @@ zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
828 828
829 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) { 829 if (!port || (port->d_id != (status_buffer->d_id & ZFCP_DID_MASK))) {
830 ZFCP_LOG_NORMAL("bug: Reopen port indication received for" 830 ZFCP_LOG_NORMAL("bug: Reopen port indication received for"
831 "nonexisting port with d_id 0x%08x on " 831 "nonexisting port with d_id 0x%06x on "
832 "adapter %s. Ignored.\n", 832 "adapter %s. Ignored.\n",
833 status_buffer->d_id & ZFCP_DID_MASK, 833 status_buffer->d_id & ZFCP_DID_MASK,
834 zfcp_get_busid_by_adapter(adapter)); 834 zfcp_get_busid_by_adapter(adapter));
@@ -853,7 +853,7 @@ zfcp_fsf_status_read_port_closed(struct zfcp_fsf_req *fsf_req)
853 &status_buffer->status_subtype, sizeof (u32)); 853 &status_buffer->status_subtype, sizeof (u32));
854 ZFCP_LOG_NORMAL("bug: Undefined status subtype received " 854 ZFCP_LOG_NORMAL("bug: Undefined status subtype received "
855 "for a reopen indication on port with " 855 "for a reopen indication on port with "
856 "d_id 0x%08x on the adapter %s. " 856 "d_id 0x%06x on the adapter %s. "
857 "Ignored. (debug info 0x%x)\n", 857 "Ignored. (debug info 0x%x)\n",
858 status_buffer->d_id, 858 status_buffer->d_id,
859 zfcp_get_busid_by_adapter(adapter), 859 zfcp_get_busid_by_adapter(adapter),
@@ -1156,7 +1156,7 @@ zfcp_fsf_abort_fcp_command(unsigned long old_req_id,
1156 } 1156 }
1157 1157
1158 ZFCP_LOG_DEBUG("Abort FCP Command request initiated " 1158 ZFCP_LOG_DEBUG("Abort FCP Command request initiated "
1159 "(adapter%s, port d_id=0x%08x, " 1159 "(adapter%s, port d_id=0x%06x, "
1160 "unit x%016Lx, old_req_id=0x%lx)\n", 1160 "unit x%016Lx, old_req_id=0x%lx)\n",
1161 zfcp_get_busid_by_adapter(adapter), 1161 zfcp_get_busid_by_adapter(adapter),
1162 unit->port->d_id, 1162 unit->port->d_id,
@@ -1554,7 +1554,7 @@ zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1554 1554
1555 case FSF_ACCESS_DENIED: 1555 case FSF_ACCESS_DENIED:
1556 ZFCP_LOG_NORMAL("access denied, cannot send generic service " 1556 ZFCP_LOG_NORMAL("access denied, cannot send generic service "
1557 "command (adapter %s, port d_id=0x%08x)\n", 1557 "command (adapter %s, port d_id=0x%06x)\n",
1558 zfcp_get_busid_by_port(port), port->d_id); 1558 zfcp_get_busid_by_port(port), port->d_id);
1559 for (counter = 0; counter < 2; counter++) { 1559 for (counter = 0; counter < 2; counter++) {
1560 subtable = header->fsf_status_qual.halfword[counter * 2]; 1560 subtable = header->fsf_status_qual.halfword[counter * 2];
@@ -1576,7 +1576,7 @@ zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1576 1576
1577 case FSF_GENERIC_COMMAND_REJECTED: 1577 case FSF_GENERIC_COMMAND_REJECTED:
1578 ZFCP_LOG_INFO("generic service command rejected " 1578 ZFCP_LOG_INFO("generic service command rejected "
1579 "(adapter %s, port d_id=0x%08x)\n", 1579 "(adapter %s, port d_id=0x%06x)\n",
1580 zfcp_get_busid_by_port(port), port->d_id); 1580 zfcp_get_busid_by_port(port), port->d_id);
1581 ZFCP_LOG_INFO("status qualifier:\n"); 1581 ZFCP_LOG_INFO("status qualifier:\n");
1582 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO, 1582 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_INFO,
@@ -1602,7 +1602,7 @@ zfcp_fsf_send_ct_handler(struct zfcp_fsf_req *fsf_req)
1602 1602
1603 case FSF_PORT_BOXED: 1603 case FSF_PORT_BOXED:
1604 ZFCP_LOG_INFO("port needs to be reopened " 1604 ZFCP_LOG_INFO("port needs to be reopened "
1605 "(adapter %s, port d_id=0x%08x)\n", 1605 "(adapter %s, port d_id=0x%06x)\n",
1606 zfcp_get_busid_by_port(port), port->d_id); 1606 zfcp_get_busid_by_port(port), port->d_id);
1607 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed"); 1607 debug_text_event(adapter->erp_dbf, 2, "fsf_s_pboxed");
1608 zfcp_erp_port_boxed(port); 1608 zfcp_erp_port_boxed(port);
@@ -1683,7 +1683,7 @@ zfcp_fsf_send_els(struct zfcp_send_els *els)
1683 NULL, &lock_flags, &fsf_req); 1683 NULL, &lock_flags, &fsf_req);
1684 if (ret < 0) { 1684 if (ret < 0) {
1685 ZFCP_LOG_INFO("error: creation of ELS request failed " 1685 ZFCP_LOG_INFO("error: creation of ELS request failed "
1686 "(adapter %s, port d_id: 0x%08x)\n", 1686 "(adapter %s, port d_id: 0x%06x)\n",
1687 zfcp_get_busid_by_adapter(adapter), d_id); 1687 zfcp_get_busid_by_adapter(adapter), d_id);
1688 goto failed_req; 1688 goto failed_req;
1689 } 1689 }
@@ -1708,7 +1708,7 @@ zfcp_fsf_send_els(struct zfcp_send_els *els)
1708 ZFCP_MAX_SBALS_PER_ELS_REQ); 1708 ZFCP_MAX_SBALS_PER_ELS_REQ);
1709 if (bytes <= 0) { 1709 if (bytes <= 0) {
1710 ZFCP_LOG_INFO("error: creation of ELS request failed " 1710 ZFCP_LOG_INFO("error: creation of ELS request failed "
1711 "(adapter %s, port d_id: 0x%08x)\n", 1711 "(adapter %s, port d_id: 0x%06x)\n",
1712 zfcp_get_busid_by_adapter(adapter), d_id); 1712 zfcp_get_busid_by_adapter(adapter), d_id);
1713 if (bytes == 0) { 1713 if (bytes == 0) {
1714 ret = -ENOMEM; 1714 ret = -ENOMEM;
@@ -1725,7 +1725,7 @@ zfcp_fsf_send_els(struct zfcp_send_els *els)
1725 ZFCP_MAX_SBALS_PER_ELS_REQ); 1725 ZFCP_MAX_SBALS_PER_ELS_REQ);
1726 if (bytes <= 0) { 1726 if (bytes <= 0) {
1727 ZFCP_LOG_INFO("error: creation of ELS request failed " 1727 ZFCP_LOG_INFO("error: creation of ELS request failed "
1728 "(adapter %s, port d_id: 0x%08x)\n", 1728 "(adapter %s, port d_id: 0x%06x)\n",
1729 zfcp_get_busid_by_adapter(adapter), d_id); 1729 zfcp_get_busid_by_adapter(adapter), d_id);
1730 if (bytes == 0) { 1730 if (bytes == 0) {
1731 ret = -ENOMEM; 1731 ret = -ENOMEM;
@@ -1739,7 +1739,7 @@ zfcp_fsf_send_els(struct zfcp_send_els *els)
1739 /* reject request */ 1739 /* reject request */
1740 ZFCP_LOG_INFO("error: microcode does not support chained SBALs" 1740 ZFCP_LOG_INFO("error: microcode does not support chained SBALs"
1741 ", ELS request too big (adapter %s, " 1741 ", ELS request too big (adapter %s, "
1742 "port d_id: 0x%08x)\n", 1742 "port d_id: 0x%06x)\n",
1743 zfcp_get_busid_by_adapter(adapter), d_id); 1743 zfcp_get_busid_by_adapter(adapter), d_id);
1744 ret = -EOPNOTSUPP; 1744 ret = -EOPNOTSUPP;
1745 goto failed_send; 1745 goto failed_send;
@@ -1760,13 +1760,13 @@ zfcp_fsf_send_els(struct zfcp_send_els *els)
1760 ret = zfcp_fsf_req_send(fsf_req); 1760 ret = zfcp_fsf_req_send(fsf_req);
1761 if (ret) { 1761 if (ret) {
1762 ZFCP_LOG_DEBUG("error: initiation of ELS request failed " 1762 ZFCP_LOG_DEBUG("error: initiation of ELS request failed "
1763 "(adapter %s, port d_id: 0x%08x)\n", 1763 "(adapter %s, port d_id: 0x%06x)\n",
1764 zfcp_get_busid_by_adapter(adapter), d_id); 1764 zfcp_get_busid_by_adapter(adapter), d_id);
1765 goto failed_send; 1765 goto failed_send;
1766 } 1766 }
1767 1767
1768 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: " 1768 ZFCP_LOG_DEBUG("ELS request initiated (adapter %s, port d_id: "
1769 "0x%08x)\n", zfcp_get_busid_by_adapter(adapter), d_id); 1769 "0x%06x)\n", zfcp_get_busid_by_adapter(adapter), d_id);
1770 goto out; 1770 goto out;
1771 1771
1772 failed_send: 1772 failed_send:
@@ -1859,7 +1859,7 @@ static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1859 case FSF_ELS_COMMAND_REJECTED: 1859 case FSF_ELS_COMMAND_REJECTED:
1860 ZFCP_LOG_INFO("ELS has been rejected because command filter " 1860 ZFCP_LOG_INFO("ELS has been rejected because command filter "
1861 "prohibited sending " 1861 "prohibited sending "
1862 "(adapter: %s, port d_id: 0x%08x)\n", 1862 "(adapter: %s, port d_id: 0x%06x)\n",
1863 zfcp_get_busid_by_adapter(adapter), d_id); 1863 zfcp_get_busid_by_adapter(adapter), d_id);
1864 1864
1865 break; 1865 break;
@@ -1907,7 +1907,7 @@ static int zfcp_fsf_send_els_handler(struct zfcp_fsf_req *fsf_req)
1907 1907
1908 case FSF_ACCESS_DENIED: 1908 case FSF_ACCESS_DENIED:
1909 ZFCP_LOG_NORMAL("access denied, cannot send ELS command " 1909 ZFCP_LOG_NORMAL("access denied, cannot send ELS command "
1910 "(adapter %s, port d_id=0x%08x)\n", 1910 "(adapter %s, port d_id=0x%06x)\n",
1911 zfcp_get_busid_by_adapter(adapter), d_id); 1911 zfcp_get_busid_by_adapter(adapter), d_id);
1912 for (counter = 0; counter < 2; counter++) { 1912 for (counter = 0; counter < 2; counter++) {
1913 subtable = header->fsf_status_qual.halfword[counter * 2]; 1913 subtable = header->fsf_status_qual.halfword[counter * 2];
@@ -2070,7 +2070,7 @@ zfcp_fsf_exchange_config_evaluate(struct zfcp_fsf_req *fsf_req, int xchg_ok)
2070 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n" 2070 ZFCP_LOG_NORMAL("The adapter %s reported the following characteristics:\n"
2071 "WWNN 0x%016Lx, " 2071 "WWNN 0x%016Lx, "
2072 "WWPN 0x%016Lx, " 2072 "WWPN 0x%016Lx, "
2073 "S_ID 0x%08x,\n" 2073 "S_ID 0x%06x,\n"
2074 "adapter version 0x%x, " 2074 "adapter version 0x%x, "
2075 "LIC version 0x%x, " 2075 "LIC version 0x%x, "
2076 "FC link speed %d Gb/s\n", 2076 "FC link speed %d Gb/s\n",
@@ -3043,6 +3043,7 @@ zfcp_fsf_open_unit_handler(struct zfcp_fsf_req *fsf_req)
3043 queue_designator = &header->fsf_status_qual.fsf_queue_designator; 3043 queue_designator = &header->fsf_status_qual.fsf_queue_designator;
3044 3044
3045 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED | 3045 atomic_clear_mask(ZFCP_STATUS_COMMON_ACCESS_DENIED |
3046 ZFCP_STATUS_COMMON_ACCESS_BOXED |
3046 ZFCP_STATUS_UNIT_SHARED | 3047 ZFCP_STATUS_UNIT_SHARED |
3047 ZFCP_STATUS_UNIT_READONLY, 3048 ZFCP_STATUS_UNIT_READONLY,
3048 &unit->status); 3049 &unit->status);
@@ -4645,23 +4646,22 @@ zfcp_fsf_req_create(struct zfcp_adapter *adapter, u32 fsf_cmd, int req_flags,
4645 fsf_req->adapter = adapter; 4646 fsf_req->adapter = adapter;
4646 fsf_req->fsf_command = fsf_cmd; 4647 fsf_req->fsf_command = fsf_cmd;
4647 INIT_LIST_HEAD(&fsf_req->list); 4648 INIT_LIST_HEAD(&fsf_req->list);
4648
4649 /* this is serialized (we are holding req_queue-lock of adapter */
4650 if (adapter->req_no == 0)
4651 adapter->req_no++;
4652 fsf_req->req_id = adapter->req_no++;
4653
4654 init_timer(&fsf_req->timer); 4649 init_timer(&fsf_req->timer);
4655 zfcp_fsf_req_qtcb_init(fsf_req);
4656 4650
4657 /* initialize waitqueue which may be used to wait on 4651 /* initialize waitqueue which may be used to wait on
4658 this request completion */ 4652 this request completion */
4659 init_waitqueue_head(&fsf_req->completion_wq); 4653 init_waitqueue_head(&fsf_req->completion_wq);
4660 4654
4661 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags); 4655 ret = zfcp_fsf_req_sbal_get(adapter, req_flags, lock_flags);
4662 if(ret < 0) { 4656 if (ret < 0)
4663 goto failed_sbals; 4657 goto failed_sbals;
4664 } 4658
4659 /* this is serialized (we are holding req_queue-lock of adapter) */
4660 if (adapter->req_no == 0)
4661 adapter->req_no++;
4662 fsf_req->req_id = adapter->req_no++;
4663
4664 zfcp_fsf_req_qtcb_init(fsf_req);
4665 4665
4666 /* 4666 /*
4667 * We hold queue_lock here. Check if QDIOUP is set and let request fail 4667 * We hold queue_lock here. Check if QDIOUP is set and let request fail
@@ -4788,7 +4788,7 @@ static int zfcp_fsf_req_send(struct zfcp_fsf_req *fsf_req)
4788 retval = -EIO; 4788 retval = -EIO;
4789 del_timer(&fsf_req->timer); 4789 del_timer(&fsf_req->timer);
4790 spin_lock(&adapter->req_list_lock); 4790 spin_lock(&adapter->req_list_lock);
4791 zfcp_reqlist_remove(adapter, fsf_req->req_id); 4791 zfcp_reqlist_remove(adapter, fsf_req);
4792 spin_unlock(&adapter->req_list_lock); 4792 spin_unlock(&adapter->req_list_lock);
4793 /* undo changes in request queue made for this request */ 4793 /* undo changes in request queue made for this request */
4794 zfcp_qdio_zero_sbals(req_queue->buffer, 4794 zfcp_qdio_zero_sbals(req_queue->buffer,
diff --git a/drivers/s390/scsi/zfcp_qdio.c b/drivers/s390/scsi/zfcp_qdio.c
index 1e12a78e8edd..bdf5782b8a7a 100644
--- a/drivers/s390/scsi/zfcp_qdio.c
+++ b/drivers/s390/scsi/zfcp_qdio.c
@@ -222,7 +222,7 @@ zfcp_qdio_handler_error_check(struct zfcp_adapter *adapter, unsigned int status,
222 * Since we have been using this adapter, it is save to assume 222 * Since we have been using this adapter, it is save to assume
223 * that it is not failed but recoverable. The card seems to 223 * that it is not failed but recoverable. The card seems to
224 * report link-up events by self-initiated queue shutdown. 224 * report link-up events by self-initiated queue shutdown.
225 * That is why we need to clear the the link-down flag 225 * That is why we need to clear the link-down flag
226 * which is set again in case we have missed by a mile. 226 * which is set again in case we have missed by a mile.
227 */ 227 */
228 zfcp_erp_adapter_reopen( 228 zfcp_erp_adapter_reopen(
@@ -283,10 +283,10 @@ zfcp_qdio_request_handler(struct ccw_device *ccw_device,
283} 283}
284 284
285/** 285/**
286 * zfcp_qdio_reqid_check - checks for valid reqids or unsolicited status 286 * zfcp_qdio_reqid_check - checks for valid reqids.
287 */ 287 */
288static int zfcp_qdio_reqid_check(struct zfcp_adapter *adapter, 288static void zfcp_qdio_reqid_check(struct zfcp_adapter *adapter,
289 unsigned long req_id) 289 unsigned long req_id)
290{ 290{
291 struct zfcp_fsf_req *fsf_req; 291 struct zfcp_fsf_req *fsf_req;
292 unsigned long flags; 292 unsigned long flags;
@@ -294,23 +294,22 @@ static int zfcp_qdio_reqid_check(struct zfcp_adapter *adapter,
294 debug_long_event(adapter->erp_dbf, 4, req_id); 294 debug_long_event(adapter->erp_dbf, 4, req_id);
295 295
296 spin_lock_irqsave(&adapter->req_list_lock, flags); 296 spin_lock_irqsave(&adapter->req_list_lock, flags);
297 fsf_req = zfcp_reqlist_ismember(adapter, req_id); 297 fsf_req = zfcp_reqlist_find(adapter, req_id);
298 298
299 if (!fsf_req) { 299 if (!fsf_req)
300 spin_unlock_irqrestore(&adapter->req_list_lock, flags); 300 /*
301 ZFCP_LOG_NORMAL("error: unknown request id (%ld).\n", req_id); 301 * Unknown request means that we have potentially memory
302 zfcp_erp_adapter_reopen(adapter, 0); 302 * corruption and must stop the machine immediatly.
303 return -EINVAL; 303 */
304 } 304 panic("error: unknown request id (%ld) on adapter %s.\n",
305 req_id, zfcp_get_busid_by_adapter(adapter));
305 306
306 zfcp_reqlist_remove(adapter, req_id); 307 zfcp_reqlist_remove(adapter, fsf_req);
307 atomic_dec(&adapter->reqs_active); 308 atomic_dec(&adapter->reqs_active);
308 spin_unlock_irqrestore(&adapter->req_list_lock, flags); 309 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
309 310
310 /* finish the FSF request */ 311 /* finish the FSF request */
311 zfcp_fsf_req_complete(fsf_req); 312 zfcp_fsf_req_complete(fsf_req);
312
313 return 0;
314} 313}
315 314
316/* 315/*
@@ -374,27 +373,9 @@ zfcp_qdio_response_handler(struct ccw_device *ccw_device,
374 373
375 /* look for QDIO request identifiers in SB */ 374 /* look for QDIO request identifiers in SB */
376 buffere = &buffer->element[buffere_index]; 375 buffere = &buffer->element[buffere_index];
377 retval = zfcp_qdio_reqid_check(adapter, 376 zfcp_qdio_reqid_check(adapter,
378 (unsigned long) buffere->addr); 377 (unsigned long) buffere->addr);
379 378
380 if (retval) {
381 ZFCP_LOG_NORMAL("bug: unexpected inbound "
382 "packet on adapter %s "
383 "(reqid=0x%lx, "
384 "first_element=%d, "
385 "elements_processed=%d)\n",
386 zfcp_get_busid_by_adapter(adapter),
387 (unsigned long) buffere->addr,
388 first_element,
389 elements_processed);
390 ZFCP_LOG_NORMAL("hex dump of inbound buffer "
391 "at address %p "
392 "(buffer_index=%d, "
393 "buffere_index=%d)\n", buffer,
394 buffer_index, buffere_index);
395 ZFCP_HEX_DUMP(ZFCP_LOG_LEVEL_NORMAL,
396 (char *) buffer, SBAL_SIZE);
397 }
398 /* 379 /*
399 * A single used SBALE per inbound SBALE has been 380 * A single used SBALE per inbound SBALE has been
400 * implemented by QDIO so far. Hope they will 381 * implemented by QDIO so far. Hope they will
diff --git a/drivers/s390/scsi/zfcp_scsi.c b/drivers/s390/scsi/zfcp_scsi.c
index 99db02062c3b..16e2d64658af 100644
--- a/drivers/s390/scsi/zfcp_scsi.c
+++ b/drivers/s390/scsi/zfcp_scsi.c
@@ -22,6 +22,7 @@
22#define ZFCP_LOG_AREA ZFCP_LOG_AREA_SCSI 22#define ZFCP_LOG_AREA ZFCP_LOG_AREA_SCSI
23 23
24#include "zfcp_ext.h" 24#include "zfcp_ext.h"
25#include <asm/atomic.h>
25 26
26static void zfcp_scsi_slave_destroy(struct scsi_device *sdp); 27static void zfcp_scsi_slave_destroy(struct scsi_device *sdp);
27static int zfcp_scsi_slave_alloc(struct scsi_device *sdp); 28static int zfcp_scsi_slave_alloc(struct scsi_device *sdp);
@@ -179,6 +180,10 @@ static void zfcp_scsi_slave_destroy(struct scsi_device *sdpnt)
179 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata; 180 struct zfcp_unit *unit = (struct zfcp_unit *) sdpnt->hostdata;
180 181
181 if (unit) { 182 if (unit) {
183 zfcp_erp_wait(unit->port->adapter);
184 wait_event(unit->scsi_scan_wq,
185 atomic_test_mask(ZFCP_STATUS_UNIT_SCSI_WORK_PENDING,
186 &unit->status) == 0);
182 atomic_clear_mask(ZFCP_STATUS_UNIT_REGISTERED, &unit->status); 187 atomic_clear_mask(ZFCP_STATUS_UNIT_REGISTERED, &unit->status);
183 sdpnt->hostdata = NULL; 188 sdpnt->hostdata = NULL;
184 unit->device = NULL; 189 unit->device = NULL;
@@ -402,8 +407,8 @@ static int zfcp_scsi_eh_abort_handler(struct scsi_cmnd *scpnt)
402 407
403 /* Check whether corresponding fsf_req is still pending */ 408 /* Check whether corresponding fsf_req is still pending */
404 spin_lock(&adapter->req_list_lock); 409 spin_lock(&adapter->req_list_lock);
405 fsf_req = zfcp_reqlist_ismember(adapter, (unsigned long) 410 fsf_req = zfcp_reqlist_find(adapter,
406 scpnt->host_scribble); 411 (unsigned long) scpnt->host_scribble);
407 spin_unlock(&adapter->req_list_lock); 412 spin_unlock(&adapter->req_list_lock);
408 if (!fsf_req) { 413 if (!fsf_req) {
409 write_unlock_irqrestore(&adapter->abort_lock, flags); 414 write_unlock_irqrestore(&adapter->abort_lock, flags);
diff --git a/drivers/sbus/char/bbc_i2c.c b/drivers/sbus/char/bbc_i2c.c
index 8410587348f1..178155bf9db6 100644
--- a/drivers/sbus/char/bbc_i2c.c
+++ b/drivers/sbus/char/bbc_i2c.c
@@ -18,6 +18,7 @@
18#include <asm/ebus.h> 18#include <asm/ebus.h>
19#include <asm/spitfire.h> 19#include <asm/spitfire.h>
20#include <asm/bbc.h> 20#include <asm/bbc.h>
21#include <asm/io.h>
21 22
22#include "bbc_i2c.h" 23#include "bbc_i2c.h"
23 24
diff --git a/drivers/sbus/char/bpp.c b/drivers/sbus/char/bpp.c
index a39ee80c9715..4fab0c23814c 100644
--- a/drivers/sbus/char/bpp.c
+++ b/drivers/sbus/char/bpp.c
@@ -15,7 +15,6 @@
15#include <linux/fs.h> 15#include <linux/fs.h>
16#include <linux/errno.h> 16#include <linux/errno.h>
17#include <linux/sched.h> 17#include <linux/sched.h>
18#include <linux/smp_lock.h>
19#include <linux/spinlock.h> 18#include <linux/spinlock.h>
20#include <linux/timer.h> 19#include <linux/timer.h>
21#include <linux/ioport.h> 20#include <linux/ioport.h>
@@ -157,7 +156,7 @@ static unsigned short get_pins(unsigned minor)
157#define BPP_ICR 0x18 156#define BPP_ICR 0x18
158#define BPP_SIZE 0x1A 157#define BPP_SIZE 0x1A
159 158
160/* BPP_CSR. Bits of type RW1 are cleared with writting '1'. */ 159/* BPP_CSR. Bits of type RW1 are cleared with writing '1'. */
161#define P_DEV_ID_MASK 0xf0000000 /* R */ 160#define P_DEV_ID_MASK 0xf0000000 /* R */
162#define P_DEV_ID_ZEBRA 0x40000000 161#define P_DEV_ID_ZEBRA 0x40000000
163#define P_DEV_ID_L64854 0xa0000000 /* == NCR 89C100+89C105. Pity. */ 162#define P_DEV_ID_L64854 0xa0000000 /* == NCR 89C100+89C105. Pity. */
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index 2d14a29effe4..3279a1b6501d 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -20,6 +20,7 @@
20#include <asm/ebus.h> /* EBus device */ 20#include <asm/ebus.h> /* EBus device */
21#include <asm/oplib.h> /* OpenProm Library */ 21#include <asm/oplib.h> /* OpenProm Library */
22#include <asm/uaccess.h> /* put_/get_user */ 22#include <asm/uaccess.h> /* put_/get_user */
23#include <asm/io.h>
23 24
24#include <asm/display7seg.h> 25#include <asm/display7seg.h>
25 26
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index f2be2ead8742..8328acab47fd 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -30,6 +30,7 @@
30#include <asm/ebus.h> 30#include <asm/ebus.h>
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32#include <asm/envctrl.h> 32#include <asm/envctrl.h>
33#include <asm/io.h>
33 34
34#define ENVCTRL_MINOR 162 35#define ENVCTRL_MINOR 162
35 36
diff --git a/drivers/sbus/char/rtc.c b/drivers/sbus/char/rtc.c
index 94d185829119..18d18f1a114e 100644
--- a/drivers/sbus/char/rtc.c
+++ b/drivers/sbus/char/rtc.c
@@ -19,7 +19,6 @@
19#include <linux/fcntl.h> 19#include <linux/fcntl.h>
20#include <linux/poll.h> 20#include <linux/poll.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/smp_lock.h>
23#include <asm/io.h> 22#include <asm/io.h>
24#include <asm/mostek.h> 23#include <asm/mostek.h>
25#include <asm/system.h> 24#include <asm/system.h>
diff --git a/drivers/sbus/char/vfc_dev.c b/drivers/sbus/char/vfc_dev.c
index c3135e2fbd5a..6afc7e5df0d4 100644
--- a/drivers/sbus/char/vfc_dev.c
+++ b/drivers/sbus/char/vfc_dev.c
@@ -20,7 +20,6 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/errno.h> 21#include <linux/errno.h>
22#include <linux/fs.h> 22#include <linux/fs.h>
23#include <linux/smp_lock.h>
24#include <linux/delay.h> 23#include <linux/delay.h>
25#include <linux/spinlock.h> 24#include <linux/spinlock.h>
26#include <linux/mm.h> 25#include <linux/mm.h>
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index e62d23f65180..d28c14e23c32 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1757,6 +1757,14 @@ config SCSI_ESP_CORE
1757 tristate "ESP Scsi Driver Core" 1757 tristate "ESP Scsi Driver Core"
1758 depends on SCSI 1758 depends on SCSI
1759 select SCSI_SPI_ATTRS 1759 select SCSI_SPI_ATTRS
1760 help
1761 This is a core driver for NCR53c9x based scsi chipsets,
1762 also known as "ESP" for Emulex Scsi Processor or
1763 Enhanced Scsi Processor. This driver does not exist by
1764 itself, there are front-end drivers which, when enabled,
1765 select and enable this driver. One example is SCSI_SUNESP.
1766 These front-end drivers provide probing, DMA, and register
1767 access support for the core driver.
1760 1768
1761config SCSI_SUNESP 1769config SCSI_SUNESP
1762 tristate "Sparc ESP Scsi Driver" 1770 tristate "Sparc ESP Scsi Driver"
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c
index 33682ce96a5d..3009ad8c4073 100644
--- a/drivers/scsi/aacraid/comminit.c
+++ b/drivers/scsi/aacraid/comminit.c
@@ -387,12 +387,11 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev)
387 * Ok now init the communication subsystem 387 * Ok now init the communication subsystem
388 */ 388 */
389 389
390 dev->queues = kmalloc(sizeof(struct aac_queue_block), GFP_KERNEL); 390 dev->queues = kzalloc(sizeof(struct aac_queue_block), GFP_KERNEL);
391 if (dev->queues == NULL) { 391 if (dev->queues == NULL) {
392 printk(KERN_ERR "Error could not allocate comm region.\n"); 392 printk(KERN_ERR "Error could not allocate comm region.\n");
393 return NULL; 393 return NULL;
394 } 394 }
395 memset(dev->queues, 0, sizeof(struct aac_queue_block));
396 395
397 if (aac_comm_init(dev)<0){ 396 if (aac_comm_init(dev)<0){
398 kfree(dev->queues); 397 kfree(dev->queues);
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 5824a757a753..9aca57eda943 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -1223,13 +1223,11 @@ int aac_check_health(struct aac_dev * aac)
1223 * Warning: no sleep allowed while 1223 * Warning: no sleep allowed while
1224 * holding spinlock 1224 * holding spinlock
1225 */ 1225 */
1226 hw_fib = kmalloc(sizeof(struct hw_fib), GFP_ATOMIC); 1226 hw_fib = kzalloc(sizeof(struct hw_fib), GFP_ATOMIC);
1227 fib = kmalloc(sizeof(struct fib), GFP_ATOMIC); 1227 fib = kzalloc(sizeof(struct fib), GFP_ATOMIC);
1228 if (fib && hw_fib) { 1228 if (fib && hw_fib) {
1229 struct aac_aifcmd * aif; 1229 struct aac_aifcmd * aif;
1230 1230
1231 memset(hw_fib, 0, sizeof(struct hw_fib));
1232 memset(fib, 0, sizeof(struct fib));
1233 fib->hw_fib_va = hw_fib; 1231 fib->hw_fib_va = hw_fib;
1234 fib->dev = aac; 1232 fib->dev = aac;
1235 aac_fib_init(fib); 1233 aac_fib_init(fib);
diff --git a/drivers/scsi/aacraid/dpcsup.c b/drivers/scsi/aacraid/dpcsup.c
index 42c7dcda6d9b..fcd25f7d0bc6 100644
--- a/drivers/scsi/aacraid/dpcsup.c
+++ b/drivers/scsi/aacraid/dpcsup.c
@@ -248,16 +248,14 @@ unsigned int aac_intr_normal(struct aac_dev * dev, u32 Index)
248 * manage the linked lists. 248 * manage the linked lists.
249 */ 249 */
250 if ((!dev->aif_thread) 250 if ((!dev->aif_thread)
251 || (!(fib = kmalloc(sizeof(struct fib),GFP_ATOMIC)))) 251 || (!(fib = kzalloc(sizeof(struct fib),GFP_ATOMIC))))
252 return 1; 252 return 1;
253 if (!(hw_fib = kmalloc(sizeof(struct hw_fib),GFP_ATOMIC))) { 253 if (!(hw_fib = kzalloc(sizeof(struct hw_fib),GFP_ATOMIC))) {
254 kfree (fib); 254 kfree (fib);
255 return 1; 255 return 1;
256 } 256 }
257 memset(hw_fib, 0, sizeof(struct hw_fib));
258 memcpy(hw_fib, (struct hw_fib *)(((ptrdiff_t)(dev->regs.sa)) + 257 memcpy(hw_fib, (struct hw_fib *)(((ptrdiff_t)(dev->regs.sa)) +
259 (index & ~0x00000002L)), sizeof(struct hw_fib)); 258 (index & ~0x00000002L)), sizeof(struct hw_fib));
260 memset(fib, 0, sizeof(struct fib));
261 INIT_LIST_HEAD(&fib->fiblink); 259 INIT_LIST_HEAD(&fib->fiblink);
262 fib->type = FSAFS_NTC_FIB_CONTEXT; 260 fib->type = FSAFS_NTC_FIB_CONTEXT;
263 fib->size = sizeof(struct fib); 261 fib->size = sizeof(struct fib);
diff --git a/drivers/scsi/aacraid/rx.c b/drivers/scsi/aacraid/rx.c
index 0c71315cbf1a..291cd14f4e98 100644
--- a/drivers/scsi/aacraid/rx.c
+++ b/drivers/scsi/aacraid/rx.c
@@ -539,8 +539,10 @@ int _aac_rx_init(struct aac_dev *dev)
539 } 539 }
540 540
541 /* Failure to reset here is an option ... */ 541 /* Failure to reset here is an option ... */
542 dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
543 dev->a_ops.adapter_enable_int = aac_rx_disable_interrupt;
542 dev->OIMR = status = rx_readb (dev, MUnit.OIMR); 544 dev->OIMR = status = rx_readb (dev, MUnit.OIMR);
543 if ((((status & 0xff) != 0xff) || reset_devices) && 545 if ((((status & 0x0c) != 0x0c) || reset_devices) &&
544 !aac_rx_restart_adapter(dev, 0)) 546 !aac_rx_restart_adapter(dev, 0))
545 ++restart; 547 ++restart;
546 /* 548 /*
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h
index 9218f29314fa..ad9761b237dc 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.h
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.h
@@ -47,7 +47,6 @@
47#include <linux/delay.h> 47#include <linux/delay.h>
48#include <linux/ioport.h> 48#include <linux/ioport.h>
49#include <linux/pci.h> 49#include <linux/pci.h>
50#include <linux/smp_lock.h>
51#include <linux/interrupt.h> 50#include <linux/interrupt.h>
52#include <linux/module.h> 51#include <linux/module.h>
53#include <linux/slab.h> 52#include <linux/slab.h>
diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
index 8d72bbae96ad..0bada0028aa0 100644
--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
@@ -966,7 +966,7 @@ ahd_aic790X_setup(struct ahd_softc *ahd)
966 | AHD_BUSFREEREV_BUG; 966 | AHD_BUSFREEREV_BUG;
967 ahd->bugs |= AHD_LQOOVERRUN_BUG|AHD_EARLY_REQ_BUG; 967 ahd->bugs |= AHD_LQOOVERRUN_BUG|AHD_EARLY_REQ_BUG;
968 968
969 /* If the user requested the the SLOWCRC bit to be set. */ 969 /* If the user requested that the SLOWCRC bit to be set. */
970 if (aic79xx_slowcrc) 970 if (aic79xx_slowcrc)
971 ahd->features |= AHD_AIC79XXB_SLOWCRC; 971 ahd->features |= AHD_AIC79XXB_SLOWCRC;
972 972
diff --git a/drivers/scsi/aic7xxx/aic7xxx_osm.h b/drivers/scsi/aic7xxx/aic7xxx_osm.h
index 85ae5d836fa4..8fee7edc6eb3 100644
--- a/drivers/scsi/aic7xxx/aic7xxx_osm.h
+++ b/drivers/scsi/aic7xxx/aic7xxx_osm.h
@@ -64,7 +64,6 @@
64#include <linux/delay.h> 64#include <linux/delay.h>
65#include <linux/ioport.h> 65#include <linux/ioport.h>
66#include <linux/pci.h> 66#include <linux/pci.h>
67#include <linux/smp_lock.h>
68#include <linux/interrupt.h> 67#include <linux/interrupt.h>
69#include <linux/module.h> 68#include <linux/module.h>
70#include <linux/slab.h> 69#include <linux/slab.h>
diff --git a/drivers/scsi/aic94xx/Makefile b/drivers/scsi/aic94xx/Makefile
index e6b70123940c..e78ce0fa44d2 100644
--- a/drivers/scsi/aic94xx/Makefile
+++ b/drivers/scsi/aic94xx/Makefile
@@ -6,7 +6,7 @@
6# 6#
7# This file is licensed under GPLv2. 7# This file is licensed under GPLv2.
8# 8#
9# This file is part of the the aic94xx driver. 9# This file is part of the aic94xx driver.
10# 10#
11# The aic94xx driver is free software; you can redistribute it and/or 11# The aic94xx driver 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
diff --git a/drivers/scsi/arm/arxescsi.c b/drivers/scsi/arm/arxescsi.c
index 7e132c5bacf8..2836fe248df9 100644
--- a/drivers/scsi/arm/arxescsi.c
+++ b/drivers/scsi/arm/arxescsi.c
@@ -281,7 +281,6 @@ arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
281{ 281{
282 struct Scsi_Host *host; 282 struct Scsi_Host *host;
283 struct arxescsi_info *info; 283 struct arxescsi_info *info;
284 unsigned long resbase, reslen;
285 void __iomem *base; 284 void __iomem *base;
286 int ret; 285 int ret;
287 286
@@ -289,9 +288,7 @@ arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
289 if (ret) 288 if (ret)
290 goto out; 289 goto out;
291 290
292 resbase = ecard_resource_start(ec, ECARD_RES_MEMC); 291 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
293 reslen = ecard_resource_len(ec, ECARD_RES_MEMC);
294 base = ioremap(resbase, reslen);
295 if (!base) { 292 if (!base) {
296 ret = -ENOMEM; 293 ret = -ENOMEM;
297 goto out_region; 294 goto out_region;
@@ -300,7 +297,7 @@ arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
300 host = scsi_host_alloc(&arxescsi_template, sizeof(struct arxescsi_info)); 297 host = scsi_host_alloc(&arxescsi_template, sizeof(struct arxescsi_info));
301 if (!host) { 298 if (!host) {
302 ret = -ENOMEM; 299 ret = -ENOMEM;
303 goto out_unmap; 300 goto out_region;
304 } 301 }
305 302
306 info = (struct arxescsi_info *)host->hostdata; 303 info = (struct arxescsi_info *)host->hostdata;
@@ -337,8 +334,6 @@ arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
337 fas216_release(host); 334 fas216_release(host);
338 out_unregister: 335 out_unregister:
339 scsi_host_put(host); 336 scsi_host_put(host);
340 out_unmap:
341 iounmap(base);
342 out_region: 337 out_region:
343 ecard_release_resources(ec); 338 ecard_release_resources(ec);
344 out: 339 out:
@@ -348,13 +343,10 @@ arxescsi_probe(struct expansion_card *ec, const struct ecard_id *id)
348static void __devexit arxescsi_remove(struct expansion_card *ec) 343static void __devexit arxescsi_remove(struct expansion_card *ec)
349{ 344{
350 struct Scsi_Host *host = ecard_get_drvdata(ec); 345 struct Scsi_Host *host = ecard_get_drvdata(ec);
351 struct arxescsi_info *info = (struct arxescsi_info *)host->hostdata;
352 346
353 ecard_set_drvdata(ec, NULL); 347 ecard_set_drvdata(ec, NULL);
354 fas216_remove(host); 348 fas216_remove(host);
355 349
356 iounmap(info->base);
357
358 fas216_release(host); 350 fas216_release(host);
359 scsi_host_put(host); 351 scsi_host_put(host);
360 ecard_release_resources(ec); 352 ecard_release_resources(ec);
diff --git a/drivers/scsi/arm/cumana_2.c b/drivers/scsi/arm/cumana_2.c
index 82add77ad131..68a64123af8f 100644
--- a/drivers/scsi/arm/cumana_2.c
+++ b/drivers/scsi/arm/cumana_2.c
@@ -401,7 +401,6 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id)
401{ 401{
402 struct Scsi_Host *host; 402 struct Scsi_Host *host;
403 struct cumanascsi2_info *info; 403 struct cumanascsi2_info *info;
404 unsigned long resbase, reslen;
405 void __iomem *base; 404 void __iomem *base;
406 int ret; 405 int ret;
407 406
@@ -409,9 +408,7 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id)
409 if (ret) 408 if (ret)
410 goto out; 409 goto out;
411 410
412 resbase = ecard_resource_start(ec, ECARD_RES_MEMC); 411 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
413 reslen = ecard_resource_len(ec, ECARD_RES_MEMC);
414 base = ioremap(resbase, reslen);
415 if (!base) { 412 if (!base) {
416 ret = -ENOMEM; 413 ret = -ENOMEM;
417 goto out_region; 414 goto out_region;
@@ -421,7 +418,7 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id)
421 sizeof(struct cumanascsi2_info)); 418 sizeof(struct cumanascsi2_info));
422 if (!host) { 419 if (!host) {
423 ret = -ENOMEM; 420 ret = -ENOMEM;
424 goto out_unmap; 421 goto out_region;
425 } 422 }
426 423
427 ecard_set_drvdata(ec, host); 424 ecard_set_drvdata(ec, host);
@@ -450,8 +447,8 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id)
450 447
451 ec->irqaddr = info->base + CUMANASCSI2_STATUS; 448 ec->irqaddr = info->base + CUMANASCSI2_STATUS;
452 ec->irqmask = STATUS_INT; 449 ec->irqmask = STATUS_INT;
453 ec->irq_data = info; 450
454 ec->ops = &cumanascsi_2_ops; 451 ecard_setirq(ec, &cumanascsi_2_ops, info);
455 452
456 ret = fas216_init(host); 453 ret = fas216_init(host);
457 if (ret) 454 if (ret)
@@ -490,9 +487,6 @@ cumanascsi2_probe(struct expansion_card *ec, const struct ecard_id *id)
490 out_free: 487 out_free:
491 scsi_host_put(host); 488 scsi_host_put(host);
492 489
493 out_unmap:
494 iounmap(base);
495
496 out_region: 490 out_region:
497 ecard_release_resources(ec); 491 ecard_release_resources(ec);
498 492
@@ -512,8 +506,6 @@ static void __devexit cumanascsi2_remove(struct expansion_card *ec)
512 free_dma(info->info.scsi.dma); 506 free_dma(info->info.scsi.dma);
513 free_irq(ec->irq, info); 507 free_irq(ec->irq, info);
514 508
515 iounmap(info->base);
516
517 fas216_release(host); 509 fas216_release(host);
518 scsi_host_put(host); 510 scsi_host_put(host);
519 ecard_release_resources(ec); 511 ecard_release_resources(ec);
diff --git a/drivers/scsi/arm/eesox.c b/drivers/scsi/arm/eesox.c
index ed06a8c19ad6..bb2477b3fb0b 100644
--- a/drivers/scsi/arm/eesox.c
+++ b/drivers/scsi/arm/eesox.c
@@ -519,7 +519,6 @@ eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
519{ 519{
520 struct Scsi_Host *host; 520 struct Scsi_Host *host;
521 struct eesoxscsi_info *info; 521 struct eesoxscsi_info *info;
522 unsigned long resbase, reslen;
523 void __iomem *base; 522 void __iomem *base;
524 int ret; 523 int ret;
525 524
@@ -527,9 +526,7 @@ eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
527 if (ret) 526 if (ret)
528 goto out; 527 goto out;
529 528
530 resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST); 529 base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
531 reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST);
532 base = ioremap(resbase, reslen);
533 if (!base) { 530 if (!base) {
534 ret = -ENOMEM; 531 ret = -ENOMEM;
535 goto out_region; 532 goto out_region;
@@ -539,7 +536,7 @@ eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
539 sizeof(struct eesoxscsi_info)); 536 sizeof(struct eesoxscsi_info));
540 if (!host) { 537 if (!host) {
541 ret = -ENOMEM; 538 ret = -ENOMEM;
542 goto out_unmap; 539 goto out_region;
543 } 540 }
544 541
545 ecard_set_drvdata(ec, host); 542 ecard_set_drvdata(ec, host);
@@ -569,8 +566,8 @@ eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
569 566
570 ec->irqaddr = base + EESOX_DMASTAT; 567 ec->irqaddr = base + EESOX_DMASTAT;
571 ec->irqmask = EESOX_STAT_INTR; 568 ec->irqmask = EESOX_STAT_INTR;
572 ec->irq_data = info; 569
573 ec->ops = &eesoxscsi_ops; 570 ecard_setirq(ec, &eesoxscsi_ops, info);
574 571
575 device_create_file(&ec->dev, &dev_attr_bus_term); 572 device_create_file(&ec->dev, &dev_attr_bus_term);
576 573
@@ -612,9 +609,6 @@ eesoxscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
612 device_remove_file(&ec->dev, &dev_attr_bus_term); 609 device_remove_file(&ec->dev, &dev_attr_bus_term);
613 scsi_host_put(host); 610 scsi_host_put(host);
614 611
615 out_unmap:
616 iounmap(base);
617
618 out_region: 612 out_region:
619 ecard_release_resources(ec); 613 ecard_release_resources(ec);
620 614
@@ -636,8 +630,6 @@ static void __devexit eesoxscsi_remove(struct expansion_card *ec)
636 630
637 device_remove_file(&ec->dev, &dev_attr_bus_term); 631 device_remove_file(&ec->dev, &dev_attr_bus_term);
638 632
639 iounmap(info->base);
640
641 fas216_release(host); 633 fas216_release(host);
642 scsi_host_put(host); 634 scsi_host_put(host);
643 ecard_release_resources(ec); 635 ecard_release_resources(ec);
diff --git a/drivers/scsi/arm/powertec.c b/drivers/scsi/arm/powertec.c
index 159047a34997..d9a546d1917c 100644
--- a/drivers/scsi/arm/powertec.c
+++ b/drivers/scsi/arm/powertec.c
@@ -313,7 +313,6 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
313{ 313{
314 struct Scsi_Host *host; 314 struct Scsi_Host *host;
315 struct powertec_info *info; 315 struct powertec_info *info;
316 unsigned long resbase, reslen;
317 void __iomem *base; 316 void __iomem *base;
318 int ret; 317 int ret;
319 318
@@ -321,9 +320,7 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
321 if (ret) 320 if (ret)
322 goto out; 321 goto out;
323 322
324 resbase = ecard_resource_start(ec, ECARD_RES_IOCFAST); 323 base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
325 reslen = ecard_resource_len(ec, ECARD_RES_IOCFAST);
326 base = ioremap(resbase, reslen);
327 if (!base) { 324 if (!base) {
328 ret = -ENOMEM; 325 ret = -ENOMEM;
329 goto out_region; 326 goto out_region;
@@ -333,7 +330,7 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
333 sizeof (struct powertec_info)); 330 sizeof (struct powertec_info));
334 if (!host) { 331 if (!host) {
335 ret = -ENOMEM; 332 ret = -ENOMEM;
336 goto out_unmap; 333 goto out_region;
337 } 334 }
338 335
339 ecard_set_drvdata(ec, host); 336 ecard_set_drvdata(ec, host);
@@ -361,8 +358,8 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
361 358
362 ec->irqaddr = base + POWERTEC_INTR_STATUS; 359 ec->irqaddr = base + POWERTEC_INTR_STATUS;
363 ec->irqmask = POWERTEC_INTR_BIT; 360 ec->irqmask = POWERTEC_INTR_BIT;
364 ec->irq_data = info; 361
365 ec->ops = &powertecscsi_ops; 362 ecard_setirq(ec, &powertecscsi_ops, info);
366 363
367 device_create_file(&ec->dev, &dev_attr_bus_term); 364 device_create_file(&ec->dev, &dev_attr_bus_term);
368 365
@@ -404,9 +401,6 @@ powertecscsi_probe(struct expansion_card *ec, const struct ecard_id *id)
404 device_remove_file(&ec->dev, &dev_attr_bus_term); 401 device_remove_file(&ec->dev, &dev_attr_bus_term);
405 scsi_host_put(host); 402 scsi_host_put(host);
406 403
407 out_unmap:
408 iounmap(base);
409
410 out_region: 404 out_region:
411 ecard_release_resources(ec); 405 ecard_release_resources(ec);
412 406
@@ -428,8 +422,6 @@ static void __devexit powertecscsi_remove(struct expansion_card *ec)
428 free_dma(info->info.scsi.dma); 422 free_dma(info->info.scsi.dma);
429 free_irq(ec->irq, info); 423 free_irq(ec->irq, info);
430 424
431 iounmap(info->base);
432
433 fas216_release(host); 425 fas216_release(host);
434 scsi_host_put(host); 426 scsi_host_put(host);
435 ecard_release_resources(ec); 427 ecard_release_resources(ec);
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 2a2cc6cf1182..2311019304c0 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -319,10 +319,9 @@ ch_readconfig(scsi_changer *ch)
319 int result,id,lun,i; 319 int result,id,lun,i;
320 u_int elem; 320 u_int elem;
321 321
322 buffer = kmalloc(512, GFP_KERNEL | GFP_DMA); 322 buffer = kzalloc(512, GFP_KERNEL | GFP_DMA);
323 if (!buffer) 323 if (!buffer)
324 return -ENOMEM; 324 return -ENOMEM;
325 memset(buffer,0,512);
326 325
327 memset(cmd,0,sizeof(cmd)); 326 memset(cmd,0,sizeof(cmd));
328 cmd[0] = MODE_SENSE; 327 cmd[0] = MODE_SENSE;
@@ -530,10 +529,9 @@ ch_set_voltag(scsi_changer *ch, u_int elem,
530 u_char *buffer; 529 u_char *buffer;
531 int result; 530 int result;
532 531
533 buffer = kmalloc(512, GFP_KERNEL); 532 buffer = kzalloc(512, GFP_KERNEL);
534 if (!buffer) 533 if (!buffer)
535 return -ENOMEM; 534 return -ENOMEM;
536 memset(buffer,0,512);
537 535
538 dprintk("%s %s voltag: 0x%x => \"%s\"\n", 536 dprintk("%s %s voltag: 0x%x => \"%s\"\n",
539 clear ? "clear" : "set", 537 clear ? "clear" : "set",
@@ -922,11 +920,10 @@ static int ch_probe(struct device *dev)
922 if (sd->type != TYPE_MEDIUM_CHANGER) 920 if (sd->type != TYPE_MEDIUM_CHANGER)
923 return -ENODEV; 921 return -ENODEV;
924 922
925 ch = kmalloc(sizeof(*ch), GFP_KERNEL); 923 ch = kzalloc(sizeof(*ch), GFP_KERNEL);
926 if (NULL == ch) 924 if (NULL == ch)
927 return -ENOMEM; 925 return -ENOMEM;
928 926
929 memset(ch,0,sizeof(*ch));
930 ch->minor = ch_devcount; 927 ch->minor = ch_devcount;
931 sprintf(ch->name,"ch%d",ch->minor); 928 sprintf(ch->name,"ch%d",ch->minor);
932 mutex_init(&ch->lock); 929 mutex_init(&ch->lock);
diff --git a/drivers/scsi/dc395x.c b/drivers/scsi/dc395x.c
index a965ed3548d5..564ea90ed3a0 100644
--- a/drivers/scsi/dc395x.c
+++ b/drivers/scsi/dc395x.c
@@ -541,7 +541,7 @@ static struct ParameterData __devinitdata cfg_data[] = {
541 541
542 542
543/* 543/*
544 * Safe settings. If set to zero the the BIOS/default values with 544 * Safe settings. If set to zero the BIOS/default values with
545 * command line overrides will be used. If set to 1 then safe and 545 * command line overrides will be used. If set to 1 then safe and
546 * slow settings will be used. 546 * slow settings will be used.
547 */ 547 */
@@ -617,7 +617,7 @@ static void __devinit fix_settings(void)
617 617
618/* 618/*
619 * Mapping from the eeprom delay index value (index into this array) 619 * Mapping from the eeprom delay index value (index into this array)
620 * to the the number of actual seconds that the delay should be for. 620 * to the number of actual seconds that the delay should be for.
621 */ 621 */
622static char __devinitdata eeprom_index_to_delay_map[] = 622static char __devinitdata eeprom_index_to_delay_map[] =
623 { 1, 3, 5, 10, 16, 30, 60, 120 }; 623 { 1, 3, 5, 10, 16, 30, 60, 120 };
@@ -4136,7 +4136,7 @@ static void __devinit trms1040_write_all(struct NvRamType *eeprom, unsigned long
4136 * @io_port: base I/O address 4136 * @io_port: base I/O address
4137 * @addr: offset into SEEPROM 4137 * @addr: offset into SEEPROM
4138 * 4138 *
4139 * Returns the the byte read. 4139 * Returns the byte read.
4140 **/ 4140 **/
4141static u8 __devinit trms1040_get_data(unsigned long io_port, u8 addr) 4141static u8 __devinit trms1040_get_data(unsigned long io_port, u8 addr)
4142{ 4142{
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index f7b9dbd64a96..8c7d2bbf9b1a 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -55,7 +55,6 @@ MODULE_DESCRIPTION("Adaptec I2O RAID Driver");
55#include <linux/sched.h> 55#include <linux/sched.h>
56#include <linux/reboot.h> 56#include <linux/reboot.h>
57#include <linux/spinlock.h> 57#include <linux/spinlock.h>
58#include <linux/smp_lock.h>
59#include <linux/dma-mapping.h> 58#include <linux/dma-mapping.h>
60 59
61#include <linux/timer.h> 60#include <linux/timer.h>
@@ -1309,13 +1308,12 @@ static s32 adpt_i2o_reset_hba(adpt_hba* pHba)
1309 schedule_timeout_uninterruptible(1); 1308 schedule_timeout_uninterruptible(1);
1310 } while (m == EMPTY_QUEUE); 1309 } while (m == EMPTY_QUEUE);
1311 1310
1312 status = kmalloc(4, GFP_KERNEL|ADDR32); 1311 status = kzalloc(4, GFP_KERNEL|ADDR32);
1313 if(status == NULL) { 1312 if(status == NULL) {
1314 adpt_send_nop(pHba, m); 1313 adpt_send_nop(pHba, m);
1315 printk(KERN_ERR"IOP reset failed - no free memory.\n"); 1314 printk(KERN_ERR"IOP reset failed - no free memory.\n");
1316 return -ENOMEM; 1315 return -ENOMEM;
1317 } 1316 }
1318 memset(status,0,4);
1319 1317
1320 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0; 1318 msg[0]=EIGHT_WORD_MSG_SIZE|SGL_OFFSET_0;
1321 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID; 1319 msg[1]=I2O_CMD_ADAPTER_RESET<<24|HOST_TID<<12|ADAPTER_TID;
@@ -1505,21 +1503,19 @@ static int adpt_i2o_parse_lct(adpt_hba* pHba)
1505 continue; 1503 continue;
1506 } 1504 }
1507 if( pHba->channel[bus_no].device[scsi_id] == NULL){ 1505 if( pHba->channel[bus_no].device[scsi_id] == NULL){
1508 pDev = kmalloc(sizeof(struct adpt_device),GFP_KERNEL); 1506 pDev = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1509 if(pDev == NULL) { 1507 if(pDev == NULL) {
1510 return -ENOMEM; 1508 return -ENOMEM;
1511 } 1509 }
1512 pHba->channel[bus_no].device[scsi_id] = pDev; 1510 pHba->channel[bus_no].device[scsi_id] = pDev;
1513 memset(pDev,0,sizeof(struct adpt_device));
1514 } else { 1511 } else {
1515 for( pDev = pHba->channel[bus_no].device[scsi_id]; 1512 for( pDev = pHba->channel[bus_no].device[scsi_id];
1516 pDev->next_lun; pDev = pDev->next_lun){ 1513 pDev->next_lun; pDev = pDev->next_lun){
1517 } 1514 }
1518 pDev->next_lun = kmalloc(sizeof(struct adpt_device),GFP_KERNEL); 1515 pDev->next_lun = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
1519 if(pDev->next_lun == NULL) { 1516 if(pDev->next_lun == NULL) {
1520 return -ENOMEM; 1517 return -ENOMEM;
1521 } 1518 }
1522 memset(pDev->next_lun,0,sizeof(struct adpt_device));
1523 pDev = pDev->next_lun; 1519 pDev = pDev->next_lun;
1524 } 1520 }
1525 pDev->tid = tid; 1521 pDev->tid = tid;
@@ -1668,12 +1664,11 @@ static int adpt_i2o_passthru(adpt_hba* pHba, u32 __user *arg)
1668 reply_size = REPLY_FRAME_SIZE; 1664 reply_size = REPLY_FRAME_SIZE;
1669 } 1665 }
1670 reply_size *= 4; 1666 reply_size *= 4;
1671 reply = kmalloc(REPLY_FRAME_SIZE*4, GFP_KERNEL); 1667 reply = kzalloc(REPLY_FRAME_SIZE*4, GFP_KERNEL);
1672 if(reply == NULL) { 1668 if(reply == NULL) {
1673 printk(KERN_WARNING"%s: Could not allocate reply buffer\n",pHba->name); 1669 printk(KERN_WARNING"%s: Could not allocate reply buffer\n",pHba->name);
1674 return -ENOMEM; 1670 return -ENOMEM;
1675 } 1671 }
1676 memset(reply,0,REPLY_FRAME_SIZE*4);
1677 sg_offset = (msg[0]>>4)&0xf; 1672 sg_offset = (msg[0]>>4)&0xf;
1678 msg[2] = 0x40000000; // IOCTL context 1673 msg[2] = 0x40000000; // IOCTL context
1679 msg[3] = (u32)reply; 1674 msg[3] = (u32)reply;
@@ -2445,7 +2440,7 @@ static s32 adpt_i2o_reparse_lct(adpt_hba* pHba)
2445 } 2440 }
2446 pDev = pHba->channel[bus_no].device[scsi_id]; 2441 pDev = pHba->channel[bus_no].device[scsi_id];
2447 if( pDev == NULL){ 2442 if( pDev == NULL){
2448 pDev = kmalloc(sizeof(struct adpt_device),GFP_KERNEL); 2443 pDev = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
2449 if(pDev == NULL) { 2444 if(pDev == NULL) {
2450 return -ENOMEM; 2445 return -ENOMEM;
2451 } 2446 }
@@ -2454,12 +2449,11 @@ static s32 adpt_i2o_reparse_lct(adpt_hba* pHba)
2454 while (pDev->next_lun) { 2449 while (pDev->next_lun) {
2455 pDev = pDev->next_lun; 2450 pDev = pDev->next_lun;
2456 } 2451 }
2457 pDev = pDev->next_lun = kmalloc(sizeof(struct adpt_device),GFP_KERNEL); 2452 pDev = pDev->next_lun = kzalloc(sizeof(struct adpt_device),GFP_KERNEL);
2458 if(pDev == NULL) { 2453 if(pDev == NULL) {
2459 return -ENOMEM; 2454 return -ENOMEM;
2460 } 2455 }
2461 } 2456 }
2462 memset(pDev,0,sizeof(struct adpt_device));
2463 pDev->tid = d->lct_data.tid; 2457 pDev->tid = d->lct_data.tid;
2464 pDev->scsi_channel = bus_no; 2458 pDev->scsi_channel = bus_no;
2465 pDev->scsi_id = scsi_id; 2459 pDev->scsi_id = scsi_id;
diff --git a/drivers/scsi/ibmvscsi/ibmvstgt.c b/drivers/scsi/ibmvscsi/ibmvstgt.c
index 6d223dd76440..8ba7dd09d01d 100644
--- a/drivers/scsi/ibmvscsi/ibmvstgt.c
+++ b/drivers/scsi/ibmvscsi/ibmvstgt.c
@@ -892,16 +892,16 @@ static int get_system_info(void)
892 if (!rootdn) 892 if (!rootdn)
893 return -ENOENT; 893 return -ENOENT;
894 894
895 model = get_property(rootdn, "model", NULL); 895 model = of_get_property(rootdn, "model", NULL);
896 id = get_property(rootdn, "system-id", NULL); 896 id = of_get_property(rootdn, "system-id", NULL);
897 if (model && id) 897 if (model && id)
898 snprintf(system_id, sizeof(system_id), "%s-%s", model, id); 898 snprintf(system_id, sizeof(system_id), "%s-%s", model, id);
899 899
900 name = get_property(rootdn, "ibm,partition-name", NULL); 900 name = of_get_property(rootdn, "ibm,partition-name", NULL);
901 if (name) 901 if (name)
902 strncpy(partition_name, name, sizeof(partition_name)); 902 strncpy(partition_name, name, sizeof(partition_name));
903 903
904 num = get_property(rootdn, "ibm,partition-no", NULL); 904 num = of_get_property(rootdn, "ibm,partition-no", NULL);
905 if (num) 905 if (num)
906 partition_number = *num; 906 partition_number = *num;
907 907
diff --git a/drivers/scsi/ibmvscsi/rpa_vscsi.c b/drivers/scsi/ibmvscsi/rpa_vscsi.c
index 0a533f398f52..d8700aaa6114 100644
--- a/drivers/scsi/ibmvscsi/rpa_vscsi.c
+++ b/drivers/scsi/ibmvscsi/rpa_vscsi.c
@@ -162,11 +162,11 @@ static void gather_partition_info(void)
162 return; 162 return;
163 } 163 }
164 164
165 ppartition_name = get_property(rootdn, "ibm,partition-name", NULL); 165 ppartition_name = of_get_property(rootdn, "ibm,partition-name", NULL);
166 if (ppartition_name) 166 if (ppartition_name)
167 strncpy(partition_name, ppartition_name, 167 strncpy(partition_name, ppartition_name,
168 sizeof(partition_name)); 168 sizeof(partition_name));
169 p_number_ptr = get_property(rootdn, "ibm,partition-no", NULL); 169 p_number_ptr = of_get_property(rootdn, "ibm,partition-no", NULL);
170 if (p_number_ptr) 170 if (p_number_ptr)
171 partition_number = *p_number_ptr; 171 partition_number = *p_number_ptr;
172 of_node_put(rootdn); 172 of_node_put(rootdn);
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 2b5b8a93bc10..8263f752809d 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -721,19 +721,23 @@ static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *r
721 return ide_stopped; 721 return ide_stopped;
722} 722}
723 723
724#ifdef CONFIG_IDE_PROC_FS
724static void idescsi_add_settings(ide_drive_t *drive) 725static void idescsi_add_settings(ide_drive_t *drive)
725{ 726{
726 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 727 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
727 728
728/* 729/*
729 * drive setting name read/write ioctl ioctl data type min max mul_factor div_factor data pointer set function 730 * drive setting name read/write data type min max mul_factor div_factor data pointer set function
730 */ 731 */
731 ide_add_setting(drive, "bios_cyl", SETTING_RW, -1, -1, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL); 732 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1, &drive->bios_cyl, NULL);
732 ide_add_setting(drive, "bios_head", SETTING_RW, -1, -1, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL); 733 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, &drive->bios_head, NULL);
733 ide_add_setting(drive, "bios_sect", SETTING_RW, -1, -1, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL); 734 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, &drive->bios_sect, NULL);
734 ide_add_setting(drive, "transform", SETTING_RW, -1, -1, TYPE_INT, 0, 3, 1, 1, &scsi->transform, NULL); 735 ide_add_setting(drive, "transform", SETTING_RW, TYPE_INT, 0, 3, 1, 1, &scsi->transform, NULL);
735 ide_add_setting(drive, "log", SETTING_RW, -1, -1, TYPE_INT, 0, 1, 1, 1, &scsi->log, NULL); 736 ide_add_setting(drive, "log", SETTING_RW, TYPE_INT, 0, 1, 1, 1, &scsi->log, NULL);
736} 737}
738#else
739static inline void idescsi_add_settings(ide_drive_t *drive) { ; }
740#endif
737 741
738/* 742/*
739 * Driver initialization. 743 * Driver initialization.
@@ -756,7 +760,7 @@ static void ide_scsi_remove(ide_drive_t *drive)
756 struct ide_scsi_obj *scsi = scsihost_to_idescsi(scsihost); 760 struct ide_scsi_obj *scsi = scsihost_to_idescsi(scsihost);
757 struct gendisk *g = scsi->disk; 761 struct gendisk *g = scsi->disk;
758 762
759 ide_unregister_subdriver(drive, scsi->driver); 763 ide_proc_unregister_driver(drive, scsi->driver);
760 764
761 ide_unregister_region(g); 765 ide_unregister_region(g);
762 766
@@ -770,13 +774,11 @@ static void ide_scsi_remove(ide_drive_t *drive)
770 774
771static int ide_scsi_probe(ide_drive_t *); 775static int ide_scsi_probe(ide_drive_t *);
772 776
773#ifdef CONFIG_PROC_FS 777#ifdef CONFIG_IDE_PROC_FS
774static ide_proc_entry_t idescsi_proc[] = { 778static ide_proc_entry_t idescsi_proc[] = {
775 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL }, 779 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
776 { NULL, 0, NULL, NULL } 780 { NULL, 0, NULL, NULL }
777}; 781};
778#else
779# define idescsi_proc NULL
780#endif 782#endif
781 783
782static ide_driver_t idescsi_driver = { 784static ide_driver_t idescsi_driver = {
@@ -790,11 +792,13 @@ static ide_driver_t idescsi_driver = {
790 .version = IDESCSI_VERSION, 792 .version = IDESCSI_VERSION,
791 .media = ide_scsi, 793 .media = ide_scsi,
792 .supports_dsc_overlap = 0, 794 .supports_dsc_overlap = 0,
793 .proc = idescsi_proc,
794 .do_request = idescsi_do_request, 795 .do_request = idescsi_do_request,
795 .end_request = idescsi_end_request, 796 .end_request = idescsi_end_request,
796 .error = idescsi_atapi_error, 797 .error = idescsi_atapi_error,
797 .abort = idescsi_atapi_abort, 798 .abort = idescsi_atapi_abort,
799#ifdef CONFIG_IDE_PROC_FS
800 .proc = idescsi_proc,
801#endif
798}; 802};
799 803
800static int idescsi_ide_open(struct inode *inode, struct file *filp) 804static int idescsi_ide_open(struct inode *inode, struct file *filp)
@@ -1153,7 +1157,7 @@ static int ide_scsi_probe(ide_drive_t *drive)
1153 idescsi->host = host; 1157 idescsi->host = host;
1154 idescsi->disk = g; 1158 idescsi->disk = g;
1155 g->private_data = &idescsi->driver; 1159 g->private_data = &idescsi->driver;
1156 ide_register_subdriver(drive, &idescsi_driver); 1160 ide_proc_register_driver(drive, &idescsi_driver);
1157 err = 0; 1161 err = 0;
1158 idescsi_setup(drive, idescsi); 1162 idescsi_setup(drive, idescsi);
1159 g->fops = &idescsi_ops; 1163 g->fops = &idescsi_ops;
@@ -1165,7 +1169,7 @@ static int ide_scsi_probe(ide_drive_t *drive)
1165 } 1169 }
1166 /* fall through on error */ 1170 /* fall through on error */
1167 ide_unregister_region(g); 1171 ide_unregister_region(g);
1168 ide_unregister_subdriver(drive, &idescsi_driver); 1172 ide_proc_unregister_driver(drive, &idescsi_driver);
1169 1173
1170 put_disk(g); 1174 put_disk(g);
1171out_host_put: 1175out_host_put:
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 2c7b77e833f9..4baa79e68679 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -92,6 +92,7 @@ static unsigned int ipr_fastfail = 0;
92static unsigned int ipr_transop_timeout = 0; 92static unsigned int ipr_transop_timeout = 0;
93static unsigned int ipr_enable_cache = 1; 93static unsigned int ipr_enable_cache = 1;
94static unsigned int ipr_debug = 0; 94static unsigned int ipr_debug = 0;
95static unsigned int ipr_dual_ioa_raid = 1;
95static DEFINE_SPINLOCK(ipr_driver_lock); 96static DEFINE_SPINLOCK(ipr_driver_lock);
96 97
97/* This table describes the differences between DMA controller chips */ 98/* This table describes the differences between DMA controller chips */
@@ -158,6 +159,8 @@ module_param_named(enable_cache, ipr_enable_cache, int, 0);
158MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)"); 159MODULE_PARM_DESC(enable_cache, "Enable adapter's non-volatile write cache (default: 1)");
159module_param_named(debug, ipr_debug, int, 0); 160module_param_named(debug, ipr_debug, int, 0);
160MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)"); 161MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
162module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
163MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
161MODULE_LICENSE("GPL"); 164MODULE_LICENSE("GPL");
162MODULE_VERSION(IPR_DRIVER_VERSION); 165MODULE_VERSION(IPR_DRIVER_VERSION);
163 166
@@ -206,6 +209,8 @@ struct ipr_error_table_t ipr_error_table[] = {
206 "8009: Impending cache battery pack failure"}, 209 "8009: Impending cache battery pack failure"},
207 {0x02040400, 0, 0, 210 {0x02040400, 0, 0,
208 "34FF: Disk device format in progress"}, 211 "34FF: Disk device format in progress"},
212 {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
213 "9070: IOA requested reset"},
209 {0x023F0000, 0, 0, 214 {0x023F0000, 0, 0,
210 "Synchronization required"}, 215 "Synchronization required"},
211 {0x024E0000, 0, 0, 216 {0x024E0000, 0, 0,
@@ -951,6 +956,53 @@ static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
951} 956}
952 957
953/** 958/**
959 * strip_and_pad_whitespace - Strip and pad trailing whitespace.
960 * @i: index into buffer
961 * @buf: string to modify
962 *
963 * This function will strip all trailing whitespace, pad the end
964 * of the string with a single space, and NULL terminate the string.
965 *
966 * Return value:
967 * new length of string
968 **/
969static int strip_and_pad_whitespace(int i, char *buf)
970{
971 while (i && buf[i] == ' ')
972 i--;
973 buf[i+1] = ' ';
974 buf[i+2] = '\0';
975 return i + 2;
976}
977
978/**
979 * ipr_log_vpd_compact - Log the passed extended VPD compactly.
980 * @prefix: string to print at start of printk
981 * @hostrcb: hostrcb pointer
982 * @vpd: vendor/product id/sn struct
983 *
984 * Return value:
985 * none
986 **/
987static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
988 struct ipr_vpd *vpd)
989{
990 char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
991 int i = 0;
992
993 memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
994 i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
995
996 memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
997 i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
998
999 memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
1000 buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
1001
1002 ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
1003}
1004
1005/**
954 * ipr_log_vpd - Log the passed VPD to the error log. 1006 * ipr_log_vpd - Log the passed VPD to the error log.
955 * @vpd: vendor/product id/sn struct 1007 * @vpd: vendor/product id/sn struct
956 * 1008 *
@@ -974,6 +1026,23 @@ static void ipr_log_vpd(struct ipr_vpd *vpd)
974} 1026}
975 1027
976/** 1028/**
1029 * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
1030 * @prefix: string to print at start of printk
1031 * @hostrcb: hostrcb pointer
1032 * @vpd: vendor/product id/sn/wwn struct
1033 *
1034 * Return value:
1035 * none
1036 **/
1037static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
1038 struct ipr_ext_vpd *vpd)
1039{
1040 ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
1041 ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
1042 be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
1043}
1044
1045/**
977 * ipr_log_ext_vpd - Log the passed extended VPD to the error log. 1046 * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
978 * @vpd: vendor/product id/sn/wwn struct 1047 * @vpd: vendor/product id/sn/wwn struct
979 * 1048 *
@@ -1287,10 +1356,11 @@ static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1287 1356
1288 error = &hostrcb->hcam.u.error.u.type_17_error; 1357 error = &hostrcb->hcam.u.error.u.type_17_error;
1289 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0'; 1358 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1359 strstrip(error->failure_reason);
1290 1360
1291 ipr_err("%s\n", error->failure_reason); 1361 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1292 ipr_err("Remote Adapter VPD:\n"); 1362 be32_to_cpu(hostrcb->hcam.u.error.prc));
1293 ipr_log_ext_vpd(&error->vpd); 1363 ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1294 ipr_log_hex_data(ioa_cfg, error->data, 1364 ipr_log_hex_data(ioa_cfg, error->data,
1295 be32_to_cpu(hostrcb->hcam.length) - 1365 be32_to_cpu(hostrcb->hcam.length) -
1296 (offsetof(struct ipr_hostrcb_error, u) + 1366 (offsetof(struct ipr_hostrcb_error, u) +
@@ -1312,10 +1382,11 @@ static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
1312 1382
1313 error = &hostrcb->hcam.u.error.u.type_07_error; 1383 error = &hostrcb->hcam.u.error.u.type_07_error;
1314 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0'; 1384 error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
1385 strstrip(error->failure_reason);
1315 1386
1316 ipr_err("%s\n", error->failure_reason); 1387 ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
1317 ipr_err("Remote Adapter VPD:\n"); 1388 be32_to_cpu(hostrcb->hcam.u.error.prc));
1318 ipr_log_vpd(&error->vpd); 1389 ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
1319 ipr_log_hex_data(ioa_cfg, error->data, 1390 ipr_log_hex_data(ioa_cfg, error->data,
1320 be32_to_cpu(hostrcb->hcam.length) - 1391 be32_to_cpu(hostrcb->hcam.length) -
1321 (offsetof(struct ipr_hostrcb_error, u) + 1392 (offsetof(struct ipr_hostrcb_error, u) +
@@ -1672,12 +1743,15 @@ static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
1672 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg; 1743 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
1673 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb; 1744 struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
1674 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc); 1745 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
1746 u32 fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
1675 1747
1676 list_del(&hostrcb->queue); 1748 list_del(&hostrcb->queue);
1677 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q); 1749 list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
1678 1750
1679 if (!ioasc) { 1751 if (!ioasc) {
1680 ipr_handle_log_data(ioa_cfg, hostrcb); 1752 ipr_handle_log_data(ioa_cfg, hostrcb);
1753 if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
1754 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
1681 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) { 1755 } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
1682 dev_err(&ioa_cfg->pdev->dev, 1756 dev_err(&ioa_cfg->pdev->dev,
1683 "Host RCB failed with IOASC: 0x%08X\n", ioasc); 1757 "Host RCB failed with IOASC: 0x%08X\n", ioasc);
@@ -2635,8 +2709,13 @@ static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
2635 if (!capable(CAP_SYS_ADMIN)) 2709 if (!capable(CAP_SYS_ADMIN))
2636 return -EACCES; 2710 return -EACCES;
2637 2711
2638 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2639 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 2712 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2713 while(ioa_cfg->in_reset_reload) {
2714 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
2715 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
2716 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
2717 }
2718
2640 ioa_cfg->errors_logged = 0; 2719 ioa_cfg->errors_logged = 0;
2641 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL); 2720 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
2642 2721
@@ -2958,6 +3037,11 @@ static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
2958 unsigned long lock_flags; 3037 unsigned long lock_flags;
2959 3038
2960 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 3039 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3040 while(ioa_cfg->in_reset_reload) {
3041 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
3042 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
3043 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
3044 }
2961 3045
2962 if (ioa_cfg->ucode_sglist) { 3046 if (ioa_cfg->ucode_sglist) {
2963 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 3047 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
@@ -4656,18 +4740,19 @@ static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
4656 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd; 4740 struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
4657 struct ipr_resource_entry *res = scsi_cmd->device->hostdata; 4741 struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
4658 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc); 4742 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
4743 u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
4659 4744
4660 if (!res) { 4745 if (!res) {
4661 ipr_scsi_eh_done(ipr_cmd); 4746 ipr_scsi_eh_done(ipr_cmd);
4662 return; 4747 return;
4663 } 4748 }
4664 4749
4665 if (!ipr_is_gscsi(res)) 4750 if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
4666 ipr_gen_sense(ipr_cmd); 4751 ipr_gen_sense(ipr_cmd);
4667 4752
4668 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res); 4753 ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
4669 4754
4670 switch (ioasc & IPR_IOASC_IOASC_MASK) { 4755 switch (masked_ioasc) {
4671 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST: 4756 case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
4672 if (ipr_is_naca_model(res)) 4757 if (ipr_is_naca_model(res))
4673 scsi_cmd->result |= (DID_ABORT << 16); 4758 scsi_cmd->result |= (DID_ABORT << 16);
@@ -5363,6 +5448,7 @@ static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
5363 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb); 5448 ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
5364 } 5449 }
5365 5450
5451 scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
5366 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n"); 5452 dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
5367 5453
5368 ioa_cfg->reset_retries = 0; 5454 ioa_cfg->reset_retries = 0;
@@ -5799,6 +5885,94 @@ static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
5799} 5885}
5800 5886
5801/** 5887/**
5888 * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
5889 * @ipr_cmd: ipr command struct
5890 *
5891 * This function enables dual IOA RAID support if possible.
5892 *
5893 * Return value:
5894 * IPR_RC_JOB_RETURN
5895 **/
5896static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
5897{
5898 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5899 struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
5900 struct ipr_mode_page24 *mode_page;
5901 int length;
5902
5903 ENTER;
5904 mode_page = ipr_get_mode_page(mode_pages, 0x24,
5905 sizeof(struct ipr_mode_page24));
5906
5907 if (mode_page)
5908 mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
5909
5910 length = mode_pages->hdr.length + 1;
5911 mode_pages->hdr.length = 0;
5912
5913 ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
5914 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
5915 length);
5916
5917 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
5918 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5919
5920 LEAVE;
5921 return IPR_RC_JOB_RETURN;
5922}
5923
5924/**
5925 * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
5926 * @ipr_cmd: ipr command struct
5927 *
5928 * This function handles the failure of a Mode Sense to the IOAFP.
5929 * Some adapters do not handle all mode pages.
5930 *
5931 * Return value:
5932 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
5933 **/
5934static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
5935{
5936 u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
5937
5938 if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
5939 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
5940 return IPR_RC_JOB_CONTINUE;
5941 }
5942
5943 return ipr_reset_cmd_failed(ipr_cmd);
5944}
5945
5946/**
5947 * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
5948 * @ipr_cmd: ipr command struct
5949 *
5950 * This function send a mode sense to the IOA to retrieve
5951 * the IOA Advanced Function Control mode page.
5952 *
5953 * Return value:
5954 * IPR_RC_JOB_RETURN
5955 **/
5956static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
5957{
5958 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
5959
5960 ENTER;
5961 ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
5962 0x24, ioa_cfg->vpd_cbs_dma +
5963 offsetof(struct ipr_misc_cbs, mode_pages),
5964 sizeof(struct ipr_mode_pages));
5965
5966 ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
5967 ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
5968
5969 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
5970
5971 LEAVE;
5972 return IPR_RC_JOB_RETURN;
5973}
5974
5975/**
5802 * ipr_init_res_table - Initialize the resource table 5976 * ipr_init_res_table - Initialize the resource table
5803 * @ipr_cmd: ipr command struct 5977 * @ipr_cmd: ipr command struct
5804 * 5978 *
@@ -5866,7 +6040,10 @@ static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
5866 } 6040 }
5867 } 6041 }
5868 6042
5869 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28; 6043 if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
6044 ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
6045 else
6046 ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
5870 6047
5871 LEAVE; 6048 LEAVE;
5872 return IPR_RC_JOB_CONTINUE; 6049 return IPR_RC_JOB_CONTINUE;
@@ -5888,8 +6065,11 @@ static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
5888 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb; 6065 struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
5889 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl; 6066 struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
5890 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data; 6067 struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
6068 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
5891 6069
5892 ENTER; 6070 ENTER;
6071 if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
6072 ioa_cfg->dual_raid = 1;
5893 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n", 6073 dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
5894 ucode_vpd->major_release, ucode_vpd->card_type, 6074 ucode_vpd->major_release, ucode_vpd->card_type,
5895 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]); 6075 ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
@@ -5973,6 +6153,37 @@ static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
5973} 6153}
5974 6154
5975/** 6155/**
6156 * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
6157 * @ipr_cmd: ipr command struct
6158 *
6159 * This function sends a Page 0xD0 inquiry to the adapter
6160 * to retrieve adapter capabilities.
6161 *
6162 * Return value:
6163 * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
6164 **/
6165static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
6166{
6167 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6168 struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
6169 struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
6170
6171 ENTER;
6172 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
6173 memset(cap, 0, sizeof(*cap));
6174
6175 if (ipr_inquiry_page_supported(page0, 0xD0)) {
6176 ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
6177 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
6178 sizeof(struct ipr_inquiry_cap));
6179 return IPR_RC_JOB_RETURN;
6180 }
6181
6182 LEAVE;
6183 return IPR_RC_JOB_CONTINUE;
6184}
6185
6186/**
5976 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter. 6187 * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
5977 * @ipr_cmd: ipr command struct 6188 * @ipr_cmd: ipr command struct
5978 * 6189 *
@@ -5992,7 +6203,7 @@ static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
5992 if (!ipr_inquiry_page_supported(page0, 1)) 6203 if (!ipr_inquiry_page_supported(page0, 1))
5993 ioa_cfg->cache_state = CACHE_NONE; 6204 ioa_cfg->cache_state = CACHE_NONE;
5994 6205
5995 ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg; 6206 ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
5996 6207
5997 ipr_ioafp_inquiry(ipr_cmd, 1, 3, 6208 ipr_ioafp_inquiry(ipr_cmd, 1, 3,
5998 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data), 6209 ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
@@ -6278,6 +6489,7 @@ static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
6278 struct ipr_hostrcb *hostrcb; 6489 struct ipr_hostrcb *hostrcb;
6279 struct ipr_uc_sdt sdt; 6490 struct ipr_uc_sdt sdt;
6280 int rc, length; 6491 int rc, length;
6492 u32 ioasc;
6281 6493
6282 mailbox = readl(ioa_cfg->ioa_mailbox); 6494 mailbox = readl(ioa_cfg->ioa_mailbox);
6283 6495
@@ -6310,9 +6522,13 @@ static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
6310 (__be32 *)&hostrcb->hcam, 6522 (__be32 *)&hostrcb->hcam,
6311 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32)); 6523 min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
6312 6524
6313 if (!rc) 6525 if (!rc) {
6314 ipr_handle_log_data(ioa_cfg, hostrcb); 6526 ipr_handle_log_data(ioa_cfg, hostrcb);
6315 else 6527 ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
6528 if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
6529 ioa_cfg->sdt_state == GET_DUMP)
6530 ioa_cfg->sdt_state = WAIT_FOR_DUMP;
6531 } else
6316 ipr_unit_check_no_data(ioa_cfg); 6532 ipr_unit_check_no_data(ioa_cfg);
6317 6533
6318 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q); 6534 list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
@@ -6425,6 +6641,48 @@ static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
6425} 6641}
6426 6642
6427/** 6643/**
6644 * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
6645 * @ipr_cmd: ipr command struct
6646 *
6647 * Description: This clears PCI reset to the adapter and delays two seconds.
6648 *
6649 * Return value:
6650 * IPR_RC_JOB_RETURN
6651 **/
6652static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
6653{
6654 ENTER;
6655 pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
6656 ipr_cmd->job_step = ipr_reset_bist_done;
6657 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
6658 LEAVE;
6659 return IPR_RC_JOB_RETURN;
6660}
6661
6662/**
6663 * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
6664 * @ipr_cmd: ipr command struct
6665 *
6666 * Description: This asserts PCI reset to the adapter.
6667 *
6668 * Return value:
6669 * IPR_RC_JOB_RETURN
6670 **/
6671static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
6672{
6673 struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
6674 struct pci_dev *pdev = ioa_cfg->pdev;
6675
6676 ENTER;
6677 pci_block_user_cfg_access(pdev);
6678 pci_set_pcie_reset_state(pdev, pcie_warm_reset);
6679 ipr_cmd->job_step = ipr_reset_slot_reset_done;
6680 ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
6681 LEAVE;
6682 return IPR_RC_JOB_RETURN;
6683}
6684
6685/**
6428 * ipr_reset_allowed - Query whether or not IOA can be reset 6686 * ipr_reset_allowed - Query whether or not IOA can be reset
6429 * @ioa_cfg: ioa config struct 6687 * @ioa_cfg: ioa config struct
6430 * 6688 *
@@ -6463,7 +6721,7 @@ static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
6463 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT; 6721 ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
6464 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT); 6722 ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
6465 } else { 6723 } else {
6466 ipr_cmd->job_step = ipr_reset_start_bist; 6724 ipr_cmd->job_step = ioa_cfg->reset;
6467 rc = IPR_RC_JOB_CONTINUE; 6725 rc = IPR_RC_JOB_CONTINUE;
6468 } 6726 }
6469 6727
@@ -6496,7 +6754,7 @@ static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
6496 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg); 6754 writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
6497 ipr_cmd->job_step = ipr_reset_wait_to_start_bist; 6755 ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
6498 } else { 6756 } else {
6499 ipr_cmd->job_step = ipr_reset_start_bist; 6757 ipr_cmd->job_step = ioa_cfg->reset;
6500 } 6758 }
6501 6759
6502 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT; 6760 ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
@@ -6591,12 +6849,14 @@ static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
6591 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN; 6849 ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
6592 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type; 6850 ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
6593 6851
6594 if (shutdown_type == IPR_SHUTDOWN_ABBREV) 6852 if (shutdown_type == IPR_SHUTDOWN_NORMAL)
6595 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT; 6853 timeout = IPR_SHUTDOWN_TIMEOUT;
6596 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL) 6854 else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
6597 timeout = IPR_INTERNAL_TIMEOUT; 6855 timeout = IPR_INTERNAL_TIMEOUT;
6856 else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
6857 timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
6598 else 6858 else
6599 timeout = IPR_SHUTDOWN_TIMEOUT; 6859 timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
6600 6860
6601 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout); 6861 ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
6602 6862
@@ -6776,8 +7036,11 @@ static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
6776 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev); 7036 struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
6777 7037
6778 spin_lock_irqsave(ioa_cfg->host->host_lock, flags); 7038 spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
6779 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space, 7039 if (ioa_cfg->needs_warm_reset)
6780 IPR_SHUTDOWN_NONE); 7040 ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
7041 else
7042 _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
7043 IPR_SHUTDOWN_NONE);
6781 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags); 7044 spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
6782 return PCI_ERS_RESULT_RECOVERED; 7045 return PCI_ERS_RESULT_RECOVERED;
6783} 7046}
@@ -7226,7 +7489,7 @@ static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
7226 unsigned long ipr_regs_pci; 7489 unsigned long ipr_regs_pci;
7227 void __iomem *ipr_regs; 7490 void __iomem *ipr_regs;
7228 int rc = PCIBIOS_SUCCESSFUL; 7491 int rc = PCIBIOS_SUCCESSFUL;
7229 volatile u32 mask, uproc; 7492 volatile u32 mask, uproc, interrupts;
7230 7493
7231 ENTER; 7494 ENTER;
7232 7495
@@ -7265,6 +7528,14 @@ static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
7265 else 7528 else
7266 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT; 7529 ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
7267 7530
7531 rc = pci_read_config_byte(pdev, PCI_REVISION_ID, &ioa_cfg->revid);
7532
7533 if (rc != PCIBIOS_SUCCESSFUL) {
7534 dev_err(&pdev->dev, "Failed to read PCI revision ID\n");
7535 rc = -EIO;
7536 goto out_scsi_host_put;
7537 }
7538
7268 ipr_regs_pci = pci_resource_start(pdev, 0); 7539 ipr_regs_pci = pci_resource_start(pdev, 0);
7269 7540
7270 rc = pci_request_regions(pdev, IPR_NAME); 7541 rc = pci_request_regions(pdev, IPR_NAME);
@@ -7333,9 +7604,14 @@ static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
7333 * the card is in an unknown state and needs a hard reset 7604 * the card is in an unknown state and needs a hard reset
7334 */ 7605 */
7335 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg); 7606 mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
7607 interrupts = readl(ioa_cfg->regs.sense_interrupt_reg);
7336 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg); 7608 uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
7337 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT)) 7609 if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
7338 ioa_cfg->needs_hard_reset = 1; 7610 ioa_cfg->needs_hard_reset = 1;
7611 if (interrupts & IPR_PCII_ERROR_INTERRUPTS)
7612 ioa_cfg->needs_hard_reset = 1;
7613 if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
7614 ioa_cfg->ioa_unit_checked = 1;
7339 7615
7340 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER); 7616 ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
7341 rc = request_irq(pdev->irq, ipr_isr, IRQF_SHARED, IPR_NAME, ioa_cfg); 7617 rc = request_irq(pdev->irq, ipr_isr, IRQF_SHARED, IPR_NAME, ioa_cfg);
@@ -7346,6 +7622,13 @@ static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
7346 goto cleanup_nolog; 7622 goto cleanup_nolog;
7347 } 7623 }
7348 7624
7625 if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
7626 (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
7627 ioa_cfg->needs_warm_reset = 1;
7628 ioa_cfg->reset = ipr_reset_slot_reset;
7629 } else
7630 ioa_cfg->reset = ipr_reset_start_bist;
7631
7349 spin_lock(&ipr_driver_lock); 7632 spin_lock(&ipr_driver_lock);
7350 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head); 7633 list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
7351 spin_unlock(&ipr_driver_lock); 7634 spin_unlock(&ipr_driver_lock);
@@ -7428,6 +7711,12 @@ static void __ipr_remove(struct pci_dev *pdev)
7428 ENTER; 7711 ENTER;
7429 7712
7430 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags); 7713 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7714 while(ioa_cfg->in_reset_reload) {
7715 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
7716 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7717 spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
7718 }
7719
7431 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL); 7720 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7432 7721
7433 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags); 7722 spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
@@ -7551,6 +7840,12 @@ static void ipr_shutdown(struct pci_dev *pdev)
7551 unsigned long lock_flags = 0; 7840 unsigned long lock_flags = 0;
7552 7841
7553 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags); 7842 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7843 while(ioa_cfg->in_reset_reload) {
7844 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7845 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
7846 spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
7847 }
7848
7554 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL); 7849 ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
7555 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags); 7850 spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
7556 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload); 7851 wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
@@ -7577,19 +7872,22 @@ static struct pci_device_id ipr_pci_table[] __devinitdata = {
7577 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, 7872 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7578 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 }, 7873 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7579 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, 7874 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7580 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0, 0 }, 7875 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
7876 IPR_USE_LONG_TRANSOP_TIMEOUT },
7581 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, 7877 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7582 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0, 7878 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
7583 IPR_USE_LONG_TRANSOP_TIMEOUT }, 7879 IPR_USE_LONG_TRANSOP_TIMEOUT },
7584 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, 7880 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7585 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 }, 7881 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7586 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, 7882 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7587 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0, 0 }, 7883 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
7884 IPR_USE_LONG_TRANSOP_TIMEOUT},
7588 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, 7885 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7589 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0, 7886 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
7590 IPR_USE_LONG_TRANSOP_TIMEOUT }, 7887 IPR_USE_LONG_TRANSOP_TIMEOUT },
7591 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, 7888 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7592 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0, 0 }, 7889 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
7890 IPR_USE_LONG_TRANSOP_TIMEOUT },
7593 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, 7891 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7594 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575D, 0, 0, 7892 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575D, 0, 0,
7595 IPR_USE_LONG_TRANSOP_TIMEOUT }, 7893 IPR_USE_LONG_TRANSOP_TIMEOUT },
@@ -7597,7 +7895,7 @@ static struct pci_device_id ipr_pci_table[] __devinitdata = {
7597 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 }, 7895 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
7598 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, 7896 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7599 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0, 7897 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
7600 IPR_USE_LONG_TRANSOP_TIMEOUT }, 7898 IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
7601 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, 7899 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
7602 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 }, 7900 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
7603 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, 7901 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
@@ -7627,6 +7925,7 @@ static struct pci_driver ipr_driver = {
7627 .remove = ipr_remove, 7925 .remove = ipr_remove,
7628 .shutdown = ipr_shutdown, 7926 .shutdown = ipr_shutdown,
7629 .err_handler = &ipr_err_handler, 7927 .err_handler = &ipr_err_handler,
7928 .dynids.use_driver_data = 1
7630}; 7929};
7631 7930
7632/** 7931/**
diff --git a/drivers/scsi/ipr.h b/drivers/scsi/ipr.h
index bc53d7cebe0a..d93156671e93 100644
--- a/drivers/scsi/ipr.h
+++ b/drivers/scsi/ipr.h
@@ -37,8 +37,8 @@
37/* 37/*
38 * Literals 38 * Literals
39 */ 39 */
40#define IPR_DRIVER_VERSION "2.3.2" 40#define IPR_DRIVER_VERSION "2.4.1"
41#define IPR_DRIVER_DATE "(March 23, 2007)" 41#define IPR_DRIVER_DATE "(April 24, 2007)"
42 42
43/* 43/*
44 * IPR_MAX_CMD_PER_LUN: This defines the maximum number of outstanding 44 * IPR_MAX_CMD_PER_LUN: This defines the maximum number of outstanding
@@ -91,6 +91,7 @@
91 * IOASCs 91 * IOASCs
92 */ 92 */
93#define IPR_IOASC_NR_INIT_CMD_REQUIRED 0x02040200 93#define IPR_IOASC_NR_INIT_CMD_REQUIRED 0x02040200
94#define IPR_IOASC_NR_IOA_RESET_REQUIRED 0x02048000
94#define IPR_IOASC_SYNC_REQUIRED 0x023f0000 95#define IPR_IOASC_SYNC_REQUIRED 0x023f0000
95#define IPR_IOASC_MED_DO_NOT_REALLOC 0x03110C00 96#define IPR_IOASC_MED_DO_NOT_REALLOC 0x03110C00
96#define IPR_IOASC_HW_SEL_TIMEOUT 0x04050000 97#define IPR_IOASC_HW_SEL_TIMEOUT 0x04050000
@@ -111,6 +112,7 @@
111 112
112/* Driver data flags */ 113/* Driver data flags */
113#define IPR_USE_LONG_TRANSOP_TIMEOUT 0x00000001 114#define IPR_USE_LONG_TRANSOP_TIMEOUT 0x00000001
115#define IPR_USE_PCI_WARM_RESET 0x00000002
114 116
115#define IPR_DEFAULT_MAX_ERROR_DUMP 984 117#define IPR_DEFAULT_MAX_ERROR_DUMP 984
116#define IPR_NUM_LOG_HCAMS 2 118#define IPR_NUM_LOG_HCAMS 2
@@ -179,6 +181,7 @@
179#define IPR_SHUTDOWN_TIMEOUT (ipr_fastfail ? 60 * HZ : 10 * 60 * HZ) 181#define IPR_SHUTDOWN_TIMEOUT (ipr_fastfail ? 60 * HZ : 10 * 60 * HZ)
180#define IPR_VSET_RW_TIMEOUT (ipr_fastfail ? 30 * HZ : 2 * 60 * HZ) 182#define IPR_VSET_RW_TIMEOUT (ipr_fastfail ? 30 * HZ : 2 * 60 * HZ)
181#define IPR_ABBREV_SHUTDOWN_TIMEOUT (10 * HZ) 183#define IPR_ABBREV_SHUTDOWN_TIMEOUT (10 * HZ)
184#define IPR_DUAL_IOA_ABBR_SHUTDOWN_TO (2 * 60 * HZ)
182#define IPR_DEVICE_RESET_TIMEOUT (ipr_fastfail ? 10 * HZ : 30 * HZ) 185#define IPR_DEVICE_RESET_TIMEOUT (ipr_fastfail ? 10 * HZ : 30 * HZ)
183#define IPR_CANCEL_ALL_TIMEOUT (ipr_fastfail ? 10 * HZ : 30 * HZ) 186#define IPR_CANCEL_ALL_TIMEOUT (ipr_fastfail ? 10 * HZ : 30 * HZ)
184#define IPR_ABORT_TASK_TIMEOUT (ipr_fastfail ? 10 * HZ : 30 * HZ) 187#define IPR_ABORT_TASK_TIMEOUT (ipr_fastfail ? 10 * HZ : 30 * HZ)
@@ -191,6 +194,7 @@
191#define IPR_WAIT_FOR_RESET_TIMEOUT (2 * HZ) 194#define IPR_WAIT_FOR_RESET_TIMEOUT (2 * HZ)
192#define IPR_CHECK_FOR_RESET_TIMEOUT (HZ / 10) 195#define IPR_CHECK_FOR_RESET_TIMEOUT (HZ / 10)
193#define IPR_WAIT_FOR_BIST_TIMEOUT (2 * HZ) 196#define IPR_WAIT_FOR_BIST_TIMEOUT (2 * HZ)
197#define IPR_PCI_RESET_TIMEOUT (HZ / 2)
194#define IPR_DUMP_TIMEOUT (15 * HZ) 198#define IPR_DUMP_TIMEOUT (15 * HZ)
195 199
196/* 200/*
@@ -602,6 +606,12 @@ struct ipr_mode_page28 {
602 struct ipr_dev_bus_entry bus[0]; 606 struct ipr_dev_bus_entry bus[0];
603}__attribute__((packed)); 607}__attribute__((packed));
604 608
609struct ipr_mode_page24 {
610 struct ipr_mode_page_hdr hdr;
611 u8 flags;
612#define IPR_ENABLE_DUAL_IOA_AF 0x80
613}__attribute__((packed));
614
605struct ipr_ioa_vpd { 615struct ipr_ioa_vpd {
606 struct ipr_std_inq_data std_inq_data; 616 struct ipr_std_inq_data std_inq_data;
607 u8 ascii_part_num[12]; 617 u8 ascii_part_num[12];
@@ -624,6 +634,19 @@ struct ipr_inquiry_page3 {
624 u8 patch_number[4]; 634 u8 patch_number[4];
625}__attribute__((packed)); 635}__attribute__((packed));
626 636
637struct ipr_inquiry_cap {
638 u8 peri_qual_dev_type;
639 u8 page_code;
640 u8 reserved1;
641 u8 page_length;
642 u8 ascii_len;
643 u8 reserved2;
644 u8 sis_version[2];
645 u8 cap;
646#define IPR_CAP_DUAL_IOA_RAID 0x80
647 u8 reserved3[15];
648}__attribute__((packed));
649
627#define IPR_INQUIRY_PAGE0_ENTRIES 20 650#define IPR_INQUIRY_PAGE0_ENTRIES 20
628struct ipr_inquiry_page0 { 651struct ipr_inquiry_page0 {
629 u8 peri_qual_dev_type; 652 u8 peri_qual_dev_type;
@@ -962,6 +985,7 @@ struct ipr_misc_cbs {
962 struct ipr_ioa_vpd ioa_vpd; 985 struct ipr_ioa_vpd ioa_vpd;
963 struct ipr_inquiry_page0 page0_data; 986 struct ipr_inquiry_page0 page0_data;
964 struct ipr_inquiry_page3 page3_data; 987 struct ipr_inquiry_page3 page3_data;
988 struct ipr_inquiry_cap cap;
965 struct ipr_mode_pages mode_pages; 989 struct ipr_mode_pages mode_pages;
966 struct ipr_supported_device supp_dev; 990 struct ipr_supported_device supp_dev;
967}; 991};
@@ -1068,6 +1092,10 @@ struct ipr_ioa_cfg {
1068 u8 allow_cmds:1; 1092 u8 allow_cmds:1;
1069 u8 allow_ml_add_del:1; 1093 u8 allow_ml_add_del:1;
1070 u8 needs_hard_reset:1; 1094 u8 needs_hard_reset:1;
1095 u8 dual_raid:1;
1096 u8 needs_warm_reset:1;
1097
1098 u8 revid;
1071 1099
1072 enum ipr_cache_state cache_state; 1100 enum ipr_cache_state cache_state;
1073 u16 type; /* CCIN of the card */ 1101 u16 type; /* CCIN of the card */
@@ -1161,6 +1189,7 @@ struct ipr_ioa_cfg {
1161 struct pci_pool *ipr_cmd_pool; 1189 struct pci_pool *ipr_cmd_pool;
1162 1190
1163 struct ipr_cmnd *reset_cmd; 1191 struct ipr_cmnd *reset_cmd;
1192 int (*reset) (struct ipr_cmnd *);
1164 1193
1165 struct ata_host ata_host; 1194 struct ata_host ata_host;
1166 char ipr_cmd_label[8]; 1195 char ipr_cmd_label[8];
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 897a5e2c55e4..b4b52694497c 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -23,6 +23,8 @@
23 * 23 *
24 */ 24 */
25 25
26#include <linux/kthread.h>
27
26#include "sas_internal.h" 28#include "sas_internal.h"
27 29
28#include <scsi/scsi_host.h> 30#include <scsi/scsi_host.h>
@@ -184,7 +186,7 @@ static int sas_queue_up(struct sas_task *task)
184 list_add_tail(&task->list, &core->task_queue); 186 list_add_tail(&task->list, &core->task_queue);
185 core->task_queue_size += 1; 187 core->task_queue_size += 1;
186 spin_unlock_irqrestore(&core->task_queue_lock, flags); 188 spin_unlock_irqrestore(&core->task_queue_lock, flags);
187 up(&core->queue_thread_sema); 189 wake_up_process(core->queue_thread);
188 190
189 return 0; 191 return 0;
190} 192}
@@ -819,7 +821,7 @@ static void sas_queue(struct sas_ha_struct *sas_ha)
819 struct sas_internal *i = to_sas_internal(core->shost->transportt); 821 struct sas_internal *i = to_sas_internal(core->shost->transportt);
820 822
821 spin_lock_irqsave(&core->task_queue_lock, flags); 823 spin_lock_irqsave(&core->task_queue_lock, flags);
822 while (!core->queue_thread_kill && 824 while (!kthread_should_stop() &&
823 !list_empty(&core->task_queue)) { 825 !list_empty(&core->task_queue)) {
824 826
825 can_queue = sas_ha->lldd_queue_size - core->task_queue_size; 827 can_queue = sas_ha->lldd_queue_size - core->task_queue_size;
@@ -858,8 +860,6 @@ static void sas_queue(struct sas_ha_struct *sas_ha)
858 spin_unlock_irqrestore(&core->task_queue_lock, flags); 860 spin_unlock_irqrestore(&core->task_queue_lock, flags);
859} 861}
860 862
861static DECLARE_COMPLETION(queue_th_comp);
862
863/** 863/**
864 * sas_queue_thread -- The Task Collector thread 864 * sas_queue_thread -- The Task Collector thread
865 * @_sas_ha: pointer to struct sas_ha 865 * @_sas_ha: pointer to struct sas_ha
@@ -867,40 +867,33 @@ static DECLARE_COMPLETION(queue_th_comp);
867static int sas_queue_thread(void *_sas_ha) 867static int sas_queue_thread(void *_sas_ha)
868{ 868{
869 struct sas_ha_struct *sas_ha = _sas_ha; 869 struct sas_ha_struct *sas_ha = _sas_ha;
870 struct scsi_core *core = &sas_ha->core;
871 870
872 daemonize("sas_queue_%d", core->shost->host_no);
873 current->flags |= PF_NOFREEZE; 871 current->flags |= PF_NOFREEZE;
874 872
875 complete(&queue_th_comp);
876
877 while (1) { 873 while (1) {
878 down_interruptible(&core->queue_thread_sema); 874 set_current_state(TASK_INTERRUPTIBLE);
875 schedule();
879 sas_queue(sas_ha); 876 sas_queue(sas_ha);
880 if (core->queue_thread_kill) 877 if (kthread_should_stop())
881 break; 878 break;
882 } 879 }
883 880
884 complete(&queue_th_comp);
885
886 return 0; 881 return 0;
887} 882}
888 883
889int sas_init_queue(struct sas_ha_struct *sas_ha) 884int sas_init_queue(struct sas_ha_struct *sas_ha)
890{ 885{
891 int res;
892 struct scsi_core *core = &sas_ha->core; 886 struct scsi_core *core = &sas_ha->core;
893 887
894 spin_lock_init(&core->task_queue_lock); 888 spin_lock_init(&core->task_queue_lock);
895 core->task_queue_size = 0; 889 core->task_queue_size = 0;
896 INIT_LIST_HEAD(&core->task_queue); 890 INIT_LIST_HEAD(&core->task_queue);
897 init_MUTEX_LOCKED(&core->queue_thread_sema);
898 891
899 res = kernel_thread(sas_queue_thread, sas_ha, 0); 892 core->queue_thread = kthread_run(sas_queue_thread, sas_ha,
900 if (res >= 0) 893 "sas_queue_%d", core->shost->host_no);
901 wait_for_completion(&queue_th_comp); 894 if (IS_ERR(core->queue_thread))
902 895 return PTR_ERR(core->queue_thread);
903 return res < 0 ? res : 0; 896 return 0;
904} 897}
905 898
906void sas_shutdown_queue(struct sas_ha_struct *sas_ha) 899void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
@@ -909,10 +902,7 @@ void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
909 struct scsi_core *core = &sas_ha->core; 902 struct scsi_core *core = &sas_ha->core;
910 struct sas_task *task, *n; 903 struct sas_task *task, *n;
911 904
912 init_completion(&queue_th_comp); 905 kthread_stop(core->queue_thread);
913 core->queue_thread_kill = 1;
914 up(&core->queue_thread_sema);
915 wait_for_completion(&queue_th_comp);
916 906
917 if (!list_empty(&core->task_queue)) 907 if (!list_empty(&core->task_queue))
918 SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n", 908 SAS_DPRINTK("HA: %llx: scsi core task queue is NOT empty!?\n",
diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
index a7de0bca5bdd..82e8f90c4617 100644
--- a/drivers/scsi/lpfc/lpfc.h
+++ b/drivers/scsi/lpfc/lpfc.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -27,10 +27,6 @@ struct lpfc_sli2_slim;
27 requests */ 27 requests */
28#define LPFC_MAX_NS_RETRY 3 /* Number of retry attempts to contact 28#define LPFC_MAX_NS_RETRY 3 /* Number of retry attempts to contact
29 the NameServer before giving up. */ 29 the NameServer before giving up. */
30#define LPFC_DFT_HBA_Q_DEPTH 2048 /* max cmds per hba */
31#define LPFC_LC_HBA_Q_DEPTH 1024 /* max cmds per low cost hba */
32#define LPFC_LP101_HBA_Q_DEPTH 128 /* max cmds per low cost hba */
33
34#define LPFC_CMD_PER_LUN 3 /* max outstanding cmds per lun */ 30#define LPFC_CMD_PER_LUN 3 /* max outstanding cmds per lun */
35#define LPFC_SG_SEG_CNT 64 /* sg element count per scsi cmnd */ 31#define LPFC_SG_SEG_CNT 64 /* sg element count per scsi cmnd */
36#define LPFC_IOCB_LIST_CNT 2250 /* list of IOCBs for fast-path usage. */ 32#define LPFC_IOCB_LIST_CNT 2250 /* list of IOCBs for fast-path usage. */
@@ -244,28 +240,23 @@ struct lpfc_hba {
244#define FC_FABRIC 0x100 /* We are fabric attached */ 240#define FC_FABRIC 0x100 /* We are fabric attached */
245#define FC_ESTABLISH_LINK 0x200 /* Reestablish Link */ 241#define FC_ESTABLISH_LINK 0x200 /* Reestablish Link */
246#define FC_RSCN_DISCOVERY 0x400 /* Authenticate all devices after RSCN*/ 242#define FC_RSCN_DISCOVERY 0x400 /* Authenticate all devices after RSCN*/
243#define FC_BLOCK_MGMT_IO 0x800 /* Don't allow mgmt mbx or iocb cmds */
247#define FC_LOADING 0x1000 /* HBA in process of loading drvr */ 244#define FC_LOADING 0x1000 /* HBA in process of loading drvr */
248#define FC_UNLOADING 0x2000 /* HBA in process of unloading drvr */ 245#define FC_UNLOADING 0x2000 /* HBA in process of unloading drvr */
249#define FC_SCSI_SCAN_TMO 0x4000 /* scsi scan timer running */ 246#define FC_SCSI_SCAN_TMO 0x4000 /* scsi scan timer running */
250#define FC_ABORT_DISCOVERY 0x8000 /* we want to abort discovery */ 247#define FC_ABORT_DISCOVERY 0x8000 /* we want to abort discovery */
251#define FC_NDISC_ACTIVE 0x10000 /* NPort discovery active */ 248#define FC_NDISC_ACTIVE 0x10000 /* NPort discovery active */
252#define FC_BYPASSED_MODE 0x20000 /* NPort is in bypassed mode */ 249#define FC_BYPASSED_MODE 0x20000 /* NPort is in bypassed mode */
250#define FC_LOOPBACK_MODE 0x40000 /* NPort is in Loopback mode */
251 /* This flag is set while issuing */
252 /* INIT_LINK mailbox command */
253#define FC_IGNORE_ERATT 0x80000 /* intr handler should ignore ERATT */
253 254
254 uint32_t fc_topology; /* link topology, from LINK INIT */ 255 uint32_t fc_topology; /* link topology, from LINK INIT */
255 256
256 struct lpfc_stats fc_stat; 257 struct lpfc_stats fc_stat;
257 258
258 /* These are the head/tail pointers for the bind, plogi, adisc, unmap, 259 struct list_head fc_nodes;
259 * and map lists. Their counters are immediately following.
260 */
261 struct list_head fc_plogi_list;
262 struct list_head fc_adisc_list;
263 struct list_head fc_reglogin_list;
264 struct list_head fc_prli_list;
265 struct list_head fc_nlpunmap_list;
266 struct list_head fc_nlpmap_list;
267 struct list_head fc_npr_list;
268 struct list_head fc_unused_list;
269 260
270 /* Keep counters for the number of entries in each list. */ 261 /* Keep counters for the number of entries in each list. */
271 uint16_t fc_plogi_cnt; 262 uint16_t fc_plogi_cnt;
@@ -387,13 +378,17 @@ struct lpfc_hba {
387 378
388 mempool_t *mbox_mem_pool; 379 mempool_t *mbox_mem_pool;
389 mempool_t *nlp_mem_pool; 380 mempool_t *nlp_mem_pool;
390 struct list_head freebufList;
391 struct list_head ctrspbuflist;
392 struct list_head rnidrspbuflist;
393 381
394 struct fc_host_statistics link_stats; 382 struct fc_host_statistics link_stats;
395}; 383};
396 384
385static inline void
386lpfc_set_loopback_flag(struct lpfc_hba *phba) {
387 if (phba->cfg_topology == FLAGS_LOCAL_LB)
388 phba->fc_flag |= FC_LOOPBACK_MODE;
389 else
390 phba->fc_flag &= ~FC_LOOPBACK_MODE;
391}
397 392
398struct rnidrsp { 393struct rnidrsp {
399 void *buf; 394 void *buf;
diff --git a/drivers/scsi/lpfc/lpfc_attr.c b/drivers/scsi/lpfc/lpfc_attr.c
index f247e786af99..95fe77e816f8 100644
--- a/drivers/scsi/lpfc/lpfc_attr.c
+++ b/drivers/scsi/lpfc/lpfc_attr.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -20,6 +20,7 @@
20 *******************************************************************/ 20 *******************************************************************/
21 21
22#include <linux/ctype.h> 22#include <linux/ctype.h>
23#include <linux/delay.h>
23#include <linux/pci.h> 24#include <linux/pci.h>
24#include <linux/interrupt.h> 25#include <linux/interrupt.h>
25 26
@@ -213,6 +214,7 @@ lpfc_issue_lip(struct Scsi_Host *host)
213 int mbxstatus = MBXERR_ERROR; 214 int mbxstatus = MBXERR_ERROR;
214 215
215 if ((phba->fc_flag & FC_OFFLINE_MODE) || 216 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
217 (phba->fc_flag & FC_BLOCK_MGMT_IO) ||
216 (phba->hba_state != LPFC_HBA_READY)) 218 (phba->hba_state != LPFC_HBA_READY))
217 return -EPERM; 219 return -EPERM;
218 220
@@ -235,6 +237,7 @@ lpfc_issue_lip(struct Scsi_Host *host)
235 phba->fc_ratov * 2); 237 phba->fc_ratov * 2);
236 } 238 }
237 239
240 lpfc_set_loopback_flag(phba);
238 if (mbxstatus == MBX_TIMEOUT) 241 if (mbxstatus == MBX_TIMEOUT)
239 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 242 pmboxq->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
240 else 243 else
@@ -247,19 +250,62 @@ lpfc_issue_lip(struct Scsi_Host *host)
247} 250}
248 251
249static int 252static int
250lpfc_selective_reset(struct lpfc_hba *phba) 253lpfc_do_offline(struct lpfc_hba *phba, uint32_t type)
251{ 254{
252 struct completion online_compl; 255 struct completion online_compl;
256 struct lpfc_sli_ring *pring;
257 struct lpfc_sli *psli;
253 int status = 0; 258 int status = 0;
259 int cnt = 0;
260 int i;
254 261
255 init_completion(&online_compl); 262 init_completion(&online_compl);
256 lpfc_workq_post_event(phba, &status, &online_compl, 263 lpfc_workq_post_event(phba, &status, &online_compl,
257 LPFC_EVT_OFFLINE); 264 LPFC_EVT_OFFLINE_PREP);
265 wait_for_completion(&online_compl);
266
267 if (status != 0)
268 return -EIO;
269
270 psli = &phba->sli;
271
272 for (i = 0; i < psli->num_rings; i++) {
273 pring = &psli->ring[i];
274 /* The linkdown event takes 30 seconds to timeout. */
275 while (pring->txcmplq_cnt) {
276 msleep(10);
277 if (cnt++ > 3000) {
278 lpfc_printf_log(phba,
279 KERN_WARNING, LOG_INIT,
280 "%d:0466 Outstanding IO when "
281 "bringing Adapter offline\n",
282 phba->brd_no);
283 break;
284 }
285 }
286 }
287
288 init_completion(&online_compl);
289 lpfc_workq_post_event(phba, &status, &online_compl, type);
258 wait_for_completion(&online_compl); 290 wait_for_completion(&online_compl);
259 291
260 if (status != 0) 292 if (status != 0)
261 return -EIO; 293 return -EIO;
262 294
295 return 0;
296}
297
298static int
299lpfc_selective_reset(struct lpfc_hba *phba)
300{
301 struct completion online_compl;
302 int status = 0;
303
304 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
305
306 if (status != 0)
307 return status;
308
263 init_completion(&online_compl); 309 init_completion(&online_compl);
264 lpfc_workq_post_event(phba, &status, &online_compl, 310 lpfc_workq_post_event(phba, &status, &online_compl,
265 LPFC_EVT_ONLINE); 311 LPFC_EVT_ONLINE);
@@ -324,23 +370,19 @@ lpfc_board_mode_store(struct class_device *cdev, const char *buf, size_t count)
324 370
325 init_completion(&online_compl); 371 init_completion(&online_compl);
326 372
327 if(strncmp(buf, "online", sizeof("online") - 1) == 0) 373 if(strncmp(buf, "online", sizeof("online") - 1) == 0) {
328 lpfc_workq_post_event(phba, &status, &online_compl, 374 lpfc_workq_post_event(phba, &status, &online_compl,
329 LPFC_EVT_ONLINE); 375 LPFC_EVT_ONLINE);
330 else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0) 376 wait_for_completion(&online_compl);
331 lpfc_workq_post_event(phba, &status, &online_compl, 377 } else if (strncmp(buf, "offline", sizeof("offline") - 1) == 0)
332 LPFC_EVT_OFFLINE); 378 status = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
333 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0) 379 else if (strncmp(buf, "warm", sizeof("warm") - 1) == 0)
334 lpfc_workq_post_event(phba, &status, &online_compl, 380 status = lpfc_do_offline(phba, LPFC_EVT_WARM_START);
335 LPFC_EVT_WARM_START); 381 else if (strncmp(buf, "error", sizeof("error") - 1) == 0)
336 else if (strncmp(buf, "error", sizeof("error") - 1) == 0) 382 status = lpfc_do_offline(phba, LPFC_EVT_KILL);
337 lpfc_workq_post_event(phba, &status, &online_compl,
338 LPFC_EVT_KILL);
339 else 383 else
340 return -EINVAL; 384 return -EINVAL;
341 385
342 wait_for_completion(&online_compl);
343
344 if (!status) 386 if (!status)
345 return strlen(buf); 387 return strlen(buf);
346 else 388 else
@@ -645,9 +687,7 @@ lpfc_soft_wwpn_store(struct class_device *cdev, const char *buf, size_t count)
645 dev_printk(KERN_NOTICE, &phba->pcidev->dev, 687 dev_printk(KERN_NOTICE, &phba->pcidev->dev,
646 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no); 688 "lpfc%d: Reinitializing to use soft_wwpn\n", phba->brd_no);
647 689
648 init_completion(&online_compl); 690 stat1 = lpfc_do_offline(phba, LPFC_EVT_OFFLINE);
649 lpfc_workq_post_event(phba, &stat1, &online_compl, LPFC_EVT_OFFLINE);
650 wait_for_completion(&online_compl);
651 if (stat1) 691 if (stat1)
652 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 692 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
653 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit " 693 "%d:0463 lpfc_soft_wwpn attribute set failed to reinit "
@@ -789,6 +829,18 @@ lpfc_nodev_tmo_init(struct lpfc_hba *phba, int val)
789 return -EINVAL; 829 return -EINVAL;
790} 830}
791 831
832static void
833lpfc_update_rport_devloss_tmo(struct lpfc_hba *phba)
834{
835 struct lpfc_nodelist *ndlp;
836
837 spin_lock_irq(phba->host->host_lock);
838 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp)
839 if (ndlp->rport)
840 ndlp->rport->dev_loss_tmo = phba->cfg_devloss_tmo;
841 spin_unlock_irq(phba->host->host_lock);
842}
843
792static int 844static int
793lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val) 845lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
794{ 846{
@@ -804,6 +856,7 @@ lpfc_nodev_tmo_set(struct lpfc_hba *phba, int val)
804 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) { 856 if (val >= LPFC_MIN_DEVLOSS_TMO && val <= LPFC_MAX_DEVLOSS_TMO) {
805 phba->cfg_nodev_tmo = val; 857 phba->cfg_nodev_tmo = val;
806 phba->cfg_devloss_tmo = val; 858 phba->cfg_devloss_tmo = val;
859 lpfc_update_rport_devloss_tmo(phba);
807 return 0; 860 return 0;
808 } 861 }
809 862
@@ -839,6 +892,7 @@ lpfc_devloss_tmo_set(struct lpfc_hba *phba, int val)
839 phba->cfg_nodev_tmo = val; 892 phba->cfg_nodev_tmo = val;
840 phba->cfg_devloss_tmo = val; 893 phba->cfg_devloss_tmo = val;
841 phba->dev_loss_tmo_changed = 1; 894 phba->dev_loss_tmo_changed = 1;
895 lpfc_update_rport_devloss_tmo(phba);
842 return 0; 896 return 0;
843 } 897 }
844 898
@@ -931,9 +985,10 @@ LPFC_ATTR_RW(topology, 0, 0, 6, "Select Fibre Channel topology");
931# 1 = 1 Gigabaud 985# 1 = 1 Gigabaud
932# 2 = 2 Gigabaud 986# 2 = 2 Gigabaud
933# 4 = 4 Gigabaud 987# 4 = 4 Gigabaud
934# Value range is [0,4]. Default value is 0. 988# 8 = 8 Gigabaud
989# Value range is [0,8]. Default value is 0.
935*/ 990*/
936LPFC_ATTR_R(link_speed, 0, 0, 4, "Select link speed"); 991LPFC_ATTR_R(link_speed, 0, 0, 8, "Select link speed");
937 992
938/* 993/*
939# lpfc_fcp_class: Determines FC class to use for the FCP protocol. 994# lpfc_fcp_class: Determines FC class to use for the FCP protocol.
@@ -958,7 +1013,7 @@ LPFC_ATTR_R(ack0, 0, 0, 1, "Enable ACK0 support");
958/* 1013/*
959# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing 1014# lpfc_cr_delay & lpfc_cr_count: Default values for I/O colaesing
960# cr_delay (msec) or cr_count outstanding commands. cr_delay can take 1015# cr_delay (msec) or cr_count outstanding commands. cr_delay can take
961# value [0,63]. cr_count can take value [0,255]. Default value of cr_delay 1016# value [0,63]. cr_count can take value [1,255]. Default value of cr_delay
962# is 0. Default value of cr_count is 1. The cr_count feature is disabled if 1017# is 0. Default value of cr_count is 1. The cr_count feature is disabled if
963# cr_delay is set to 0. 1018# cr_delay is set to 0.
964*/ 1019*/
@@ -1227,11 +1282,11 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1227 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata; 1282 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
1228 int rc; 1283 int rc;
1229 1284
1230 if (off > sizeof(MAILBOX_t)) 1285 if (off > MAILBOX_CMD_SIZE)
1231 return -ERANGE; 1286 return -ERANGE;
1232 1287
1233 if ((count + off) > sizeof(MAILBOX_t)) 1288 if ((count + off) > MAILBOX_CMD_SIZE)
1234 count = sizeof(MAILBOX_t) - off; 1289 count = MAILBOX_CMD_SIZE - off;
1235 1290
1236 if (off % 4 || count % 4 || (unsigned long)buf % 4) 1291 if (off % 4 || count % 4 || (unsigned long)buf % 4)
1237 return -EINVAL; 1292 return -EINVAL;
@@ -1307,6 +1362,12 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1307 return -EPERM; 1362 return -EPERM;
1308 } 1363 }
1309 1364
1365 if (phba->fc_flag & FC_BLOCK_MGMT_IO) {
1366 sysfs_mbox_idle(phba);
1367 spin_unlock_irq(host->host_lock);
1368 return -EAGAIN;
1369 }
1370
1310 if ((phba->fc_flag & FC_OFFLINE_MODE) || 1371 if ((phba->fc_flag & FC_OFFLINE_MODE) ||
1311 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){ 1372 (!(phba->sli.sli_flag & LPFC_SLI2_ACTIVE))){
1312 1373
@@ -1326,6 +1387,11 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1326 } 1387 }
1327 1388
1328 if (rc != MBX_SUCCESS) { 1389 if (rc != MBX_SUCCESS) {
1390 if (rc == MBX_TIMEOUT) {
1391 phba->sysfs_mbox.mbox->mbox_cmpl =
1392 lpfc_sli_def_mbox_cmpl;
1393 phba->sysfs_mbox.mbox = NULL;
1394 }
1329 sysfs_mbox_idle(phba); 1395 sysfs_mbox_idle(phba);
1330 spin_unlock_irq(host->host_lock); 1396 spin_unlock_irq(host->host_lock);
1331 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV; 1397 return (rc == MBX_TIMEOUT) ? -ETIME : -ENODEV;
@@ -1344,7 +1410,7 @@ sysfs_mbox_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
1344 1410
1345 phba->sysfs_mbox.offset = off + count; 1411 phba->sysfs_mbox.offset = off + count;
1346 1412
1347 if (phba->sysfs_mbox.offset == sizeof(MAILBOX_t)) 1413 if (phba->sysfs_mbox.offset == MAILBOX_CMD_SIZE)
1348 sysfs_mbox_idle(phba); 1414 sysfs_mbox_idle(phba);
1349 1415
1350 spin_unlock_irq(phba->host->host_lock); 1416 spin_unlock_irq(phba->host->host_lock);
@@ -1358,7 +1424,7 @@ static struct bin_attribute sysfs_mbox_attr = {
1358 .mode = S_IRUSR | S_IWUSR, 1424 .mode = S_IRUSR | S_IWUSR,
1359 .owner = THIS_MODULE, 1425 .owner = THIS_MODULE,
1360 }, 1426 },
1361 .size = sizeof(MAILBOX_t), 1427 .size = MAILBOX_CMD_SIZE,
1362 .read = sysfs_mbox_read, 1428 .read = sysfs_mbox_read,
1363 .write = sysfs_mbox_write, 1429 .write = sysfs_mbox_write,
1364}; 1430};
@@ -1494,6 +1560,9 @@ lpfc_get_host_speed(struct Scsi_Host *shost)
1494 case LA_4GHZ_LINK: 1560 case LA_4GHZ_LINK:
1495 fc_host_speed(shost) = FC_PORTSPEED_4GBIT; 1561 fc_host_speed(shost) = FC_PORTSPEED_4GBIT;
1496 break; 1562 break;
1563 case LA_8GHZ_LINK:
1564 fc_host_speed(shost) = FC_PORTSPEED_8GBIT;
1565 break;
1497 default: 1566 default:
1498 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN; 1567 fc_host_speed(shost) = FC_PORTSPEED_UNKNOWN;
1499 break; 1568 break;
@@ -1546,6 +1615,9 @@ lpfc_get_stats(struct Scsi_Host *shost)
1546 unsigned long seconds; 1615 unsigned long seconds;
1547 int rc = 0; 1616 int rc = 0;
1548 1617
1618 if (phba->fc_flag & FC_BLOCK_MGMT_IO)
1619 return NULL;
1620
1549 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1621 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1550 if (!pmboxq) 1622 if (!pmboxq)
1551 return NULL; 1623 return NULL;
@@ -1631,6 +1703,8 @@ lpfc_get_stats(struct Scsi_Host *shost)
1631 else 1703 else
1632 hs->seconds_since_last_reset = seconds - psli->stats_start; 1704 hs->seconds_since_last_reset = seconds - psli->stats_start;
1633 1705
1706 mempool_free(pmboxq, phba->mbox_mem_pool);
1707
1634 return hs; 1708 return hs;
1635} 1709}
1636 1710
@@ -1644,6 +1718,9 @@ lpfc_reset_stats(struct Scsi_Host *shost)
1644 MAILBOX_t *pmb; 1718 MAILBOX_t *pmb;
1645 int rc = 0; 1719 int rc = 0;
1646 1720
1721 if (phba->fc_flag & FC_BLOCK_MGMT_IO)
1722 return;
1723
1647 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 1724 pmboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1648 if (!pmboxq) 1725 if (!pmboxq)
1649 return; 1726 return;
@@ -1699,6 +1776,8 @@ lpfc_reset_stats(struct Scsi_Host *shost)
1699 1776
1700 psli->stats_start = get_seconds(); 1777 psli->stats_start = get_seconds();
1701 1778
1779 mempool_free(pmboxq, phba->mbox_mem_pool);
1780
1702 return; 1781 return;
1703} 1782}
1704 1783
@@ -1706,67 +1785,51 @@ lpfc_reset_stats(struct Scsi_Host *shost)
1706 * The LPFC driver treats linkdown handling as target loss events so there 1785 * The LPFC driver treats linkdown handling as target loss events so there
1707 * are no sysfs handlers for link_down_tmo. 1786 * are no sysfs handlers for link_down_tmo.
1708 */ 1787 */
1709static void 1788
1710lpfc_get_starget_port_id(struct scsi_target *starget) 1789static struct lpfc_nodelist *
1790lpfc_get_node_by_target(struct scsi_target *starget)
1711{ 1791{
1712 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 1792 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent);
1713 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata; 1793 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
1714 uint32_t did = -1; 1794 struct lpfc_nodelist *ndlp;
1715 struct lpfc_nodelist *ndlp = NULL;
1716 1795
1717 spin_lock_irq(shost->host_lock); 1796 spin_lock_irq(shost->host_lock);
1718 /* Search the mapped list for this target ID */ 1797 /* Search for this, mapped, target ID */
1719 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { 1798 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
1720 if (starget->id == ndlp->nlp_sid) { 1799 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1721 did = ndlp->nlp_DID; 1800 starget->id == ndlp->nlp_sid) {
1722 break; 1801 spin_unlock_irq(shost->host_lock);
1802 return ndlp;
1723 } 1803 }
1724 } 1804 }
1725 spin_unlock_irq(shost->host_lock); 1805 spin_unlock_irq(shost->host_lock);
1806 return NULL;
1807}
1808
1809static void
1810lpfc_get_starget_port_id(struct scsi_target *starget)
1811{
1812 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
1726 1813
1727 fc_starget_port_id(starget) = did; 1814 fc_starget_port_id(starget) = ndlp ? ndlp->nlp_DID : -1;
1728} 1815}
1729 1816
1730static void 1817static void
1731lpfc_get_starget_node_name(struct scsi_target *starget) 1818lpfc_get_starget_node_name(struct scsi_target *starget)
1732{ 1819{
1733 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 1820 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
1734 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
1735 u64 node_name = 0;
1736 struct lpfc_nodelist *ndlp = NULL;
1737
1738 spin_lock_irq(shost->host_lock);
1739 /* Search the mapped list for this target ID */
1740 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1741 if (starget->id == ndlp->nlp_sid) {
1742 node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1743 break;
1744 }
1745 }
1746 spin_unlock_irq(shost->host_lock);
1747 1821
1748 fc_starget_node_name(starget) = node_name; 1822 fc_starget_node_name(starget) =
1823 ndlp ? wwn_to_u64(ndlp->nlp_nodename.u.wwn) : 0;
1749} 1824}
1750 1825
1751static void 1826static void
1752lpfc_get_starget_port_name(struct scsi_target *starget) 1827lpfc_get_starget_port_name(struct scsi_target *starget)
1753{ 1828{
1754 struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); 1829 struct lpfc_nodelist *ndlp = lpfc_get_node_by_target(starget);
1755 struct lpfc_hba *phba = (struct lpfc_hba *) shost->hostdata;
1756 u64 port_name = 0;
1757 struct lpfc_nodelist *ndlp = NULL;
1758
1759 spin_lock_irq(shost->host_lock);
1760 /* Search the mapped list for this target ID */
1761 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) {
1762 if (starget->id == ndlp->nlp_sid) {
1763 port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
1764 break;
1765 }
1766 }
1767 spin_unlock_irq(shost->host_lock);
1768 1830
1769 fc_starget_port_name(starget) = port_name; 1831 fc_starget_port_name(starget) =
1832 ndlp ? wwn_to_u64(ndlp->nlp_portname.u.wwn) : 0;
1770} 1833}
1771 1834
1772static void 1835static void
@@ -1895,25 +1958,8 @@ lpfc_get_cfgparam(struct lpfc_hba *phba)
1895 sizeof(struct fcp_rsp) + 1958 sizeof(struct fcp_rsp) +
1896 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64)); 1959 (phba->cfg_sg_seg_cnt * sizeof(struct ulp_bde64));
1897 1960
1898 switch (phba->pcidev->device) {
1899 case PCI_DEVICE_ID_LP101:
1900 case PCI_DEVICE_ID_BSMB:
1901 case PCI_DEVICE_ID_ZSMB:
1902 phba->cfg_hba_queue_depth = LPFC_LP101_HBA_Q_DEPTH;
1903 break;
1904 case PCI_DEVICE_ID_RFLY:
1905 case PCI_DEVICE_ID_PFLY:
1906 case PCI_DEVICE_ID_BMID:
1907 case PCI_DEVICE_ID_ZMID:
1908 case PCI_DEVICE_ID_TFLY:
1909 phba->cfg_hba_queue_depth = LPFC_LC_HBA_Q_DEPTH;
1910 break;
1911 default:
1912 phba->cfg_hba_queue_depth = LPFC_DFT_HBA_Q_DEPTH;
1913 }
1914 1961
1915 if (phba->cfg_hba_queue_depth > lpfc_hba_queue_depth) 1962 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1916 lpfc_hba_queue_depth_init(phba, lpfc_hba_queue_depth);
1917 1963
1918 return; 1964 return;
1919} 1965}
diff --git a/drivers/scsi/lpfc/lpfc_crtn.h b/drivers/scsi/lpfc/lpfc_crtn.h
index 1251788ce2a3..b8c2a8862d8c 100644
--- a/drivers/scsi/lpfc/lpfc_crtn.h
+++ b/drivers/scsi/lpfc/lpfc_crtn.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -18,6 +18,8 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21typedef int (*node_filter)(struct lpfc_nodelist *ndlp, void *param);
22
21struct fc_rport; 23struct fc_rport;
22void lpfc_dump_mem(struct lpfc_hba *, LPFC_MBOXQ_t *, uint16_t); 24void lpfc_dump_mem(struct lpfc_hba *, LPFC_MBOXQ_t *, uint16_t);
23void lpfc_read_nv(struct lpfc_hba *, LPFC_MBOXQ_t *); 25void lpfc_read_nv(struct lpfc_hba *, LPFC_MBOXQ_t *);
@@ -43,20 +45,24 @@ void lpfc_mbx_cmpl_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
43void lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *); 45void lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
44void lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *); 46void lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
45void lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *); 47void lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *, LPFC_MBOXQ_t *);
46int lpfc_nlp_list(struct lpfc_hba *, struct lpfc_nodelist *, int); 48void lpfc_dequeue_node(struct lpfc_hba *, struct lpfc_nodelist *);
49void lpfc_nlp_set_state(struct lpfc_hba *, struct lpfc_nodelist *, int);
50void lpfc_drop_node(struct lpfc_hba *, struct lpfc_nodelist *);
47void lpfc_set_disctmo(struct lpfc_hba *); 51void lpfc_set_disctmo(struct lpfc_hba *);
48int lpfc_can_disctmo(struct lpfc_hba *); 52int lpfc_can_disctmo(struct lpfc_hba *);
49int lpfc_unreg_rpi(struct lpfc_hba *, struct lpfc_nodelist *); 53int lpfc_unreg_rpi(struct lpfc_hba *, struct lpfc_nodelist *);
50int lpfc_check_sli_ndlp(struct lpfc_hba *, struct lpfc_sli_ring *, 54int lpfc_check_sli_ndlp(struct lpfc_hba *, struct lpfc_sli_ring *,
51 struct lpfc_iocbq *, struct lpfc_nodelist *); 55 struct lpfc_iocbq *, struct lpfc_nodelist *);
52int lpfc_nlp_remove(struct lpfc_hba *, struct lpfc_nodelist *);
53void lpfc_nlp_init(struct lpfc_hba *, struct lpfc_nodelist *, uint32_t); 56void lpfc_nlp_init(struct lpfc_hba *, struct lpfc_nodelist *, uint32_t);
57struct lpfc_nodelist *lpfc_nlp_get(struct lpfc_nodelist *);
58int lpfc_nlp_put(struct lpfc_nodelist *);
54struct lpfc_nodelist *lpfc_setup_disc_node(struct lpfc_hba *, uint32_t); 59struct lpfc_nodelist *lpfc_setup_disc_node(struct lpfc_hba *, uint32_t);
55void lpfc_disc_list_loopmap(struct lpfc_hba *); 60void lpfc_disc_list_loopmap(struct lpfc_hba *);
56void lpfc_disc_start(struct lpfc_hba *); 61void lpfc_disc_start(struct lpfc_hba *);
57void lpfc_disc_flush_list(struct lpfc_hba *); 62void lpfc_disc_flush_list(struct lpfc_hba *);
58void lpfc_disc_timeout(unsigned long); 63void lpfc_disc_timeout(unsigned long);
59 64
65struct lpfc_nodelist *__lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi);
60struct lpfc_nodelist *lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi); 66struct lpfc_nodelist *lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi);
61 67
62int lpfc_workq_post_event(struct lpfc_hba *, void *, void *, uint32_t); 68int lpfc_workq_post_event(struct lpfc_hba *, void *, void *, uint32_t);
@@ -66,8 +72,7 @@ int lpfc_disc_state_machine(struct lpfc_hba *, struct lpfc_nodelist *, void *,
66 72
67int lpfc_check_sparm(struct lpfc_hba *, struct lpfc_nodelist *, 73int lpfc_check_sparm(struct lpfc_hba *, struct lpfc_nodelist *,
68 struct serv_parm *, uint32_t); 74 struct serv_parm *, uint32_t);
69int lpfc_els_abort(struct lpfc_hba *, struct lpfc_nodelist * ndlp, 75int lpfc_els_abort(struct lpfc_hba *, struct lpfc_nodelist * ndlp);
70 int);
71int lpfc_els_abort_flogi(struct lpfc_hba *); 76int lpfc_els_abort_flogi(struct lpfc_hba *);
72int lpfc_initial_flogi(struct lpfc_hba *); 77int lpfc_initial_flogi(struct lpfc_hba *);
73int lpfc_issue_els_plogi(struct lpfc_hba *, uint32_t, uint8_t); 78int lpfc_issue_els_plogi(struct lpfc_hba *, uint32_t, uint8_t);
@@ -113,7 +118,10 @@ void lpfc_hba_init(struct lpfc_hba *, uint32_t *);
113int lpfc_post_buffer(struct lpfc_hba *, struct lpfc_sli_ring *, int, int); 118int lpfc_post_buffer(struct lpfc_hba *, struct lpfc_sli_ring *, int, int);
114void lpfc_decode_firmware_rev(struct lpfc_hba *, char *, int); 119void lpfc_decode_firmware_rev(struct lpfc_hba *, char *, int);
115int lpfc_online(struct lpfc_hba *); 120int lpfc_online(struct lpfc_hba *);
116int lpfc_offline(struct lpfc_hba *); 121void lpfc_block_mgmt_io(struct lpfc_hba *);
122void lpfc_unblock_mgmt_io(struct lpfc_hba *);
123void lpfc_offline_prep(struct lpfc_hba *);
124void lpfc_offline(struct lpfc_hba *);
117 125
118int lpfc_sli_setup(struct lpfc_hba *); 126int lpfc_sli_setup(struct lpfc_hba *);
119int lpfc_sli_queue_setup(struct lpfc_hba *); 127int lpfc_sli_queue_setup(struct lpfc_hba *);
@@ -162,8 +170,8 @@ int lpfc_sli_ringpostbuf_put(struct lpfc_hba *, struct lpfc_sli_ring *,
162struct lpfc_dmabuf *lpfc_sli_ringpostbuf_get(struct lpfc_hba *, 170struct lpfc_dmabuf *lpfc_sli_ringpostbuf_get(struct lpfc_hba *,
163 struct lpfc_sli_ring *, 171 struct lpfc_sli_ring *,
164 dma_addr_t); 172 dma_addr_t);
165int lpfc_sli_issue_abort_iotag32(struct lpfc_hba *, struct lpfc_sli_ring *, 173int lpfc_sli_issue_abort_iotag(struct lpfc_hba *, struct lpfc_sli_ring *,
166 struct lpfc_iocbq *); 174 struct lpfc_iocbq *);
167int lpfc_sli_sum_iocb(struct lpfc_hba *, struct lpfc_sli_ring *, uint16_t, 175int lpfc_sli_sum_iocb(struct lpfc_hba *, struct lpfc_sli_ring *, uint16_t,
168 uint64_t, lpfc_ctx_cmd); 176 uint64_t, lpfc_ctx_cmd);
169int lpfc_sli_abort_iocb(struct lpfc_hba *, struct lpfc_sli_ring *, uint16_t, 177int lpfc_sli_abort_iocb(struct lpfc_hba *, struct lpfc_sli_ring *, uint16_t,
@@ -172,9 +180,8 @@ int lpfc_sli_abort_iocb(struct lpfc_hba *, struct lpfc_sli_ring *, uint16_t,
172void lpfc_mbox_timeout(unsigned long); 180void lpfc_mbox_timeout(unsigned long);
173void lpfc_mbox_timeout_handler(struct lpfc_hba *); 181void lpfc_mbox_timeout_handler(struct lpfc_hba *);
174 182
175struct lpfc_nodelist *lpfc_findnode_did(struct lpfc_hba *, uint32_t, uint32_t); 183struct lpfc_nodelist *lpfc_findnode_did(struct lpfc_hba *, uint32_t);
176struct lpfc_nodelist *lpfc_findnode_wwpn(struct lpfc_hba *, uint32_t, 184struct lpfc_nodelist *lpfc_findnode_wwpn(struct lpfc_hba *, struct lpfc_name *);
177 struct lpfc_name *);
178 185
179int lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq, 186int lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
180 uint32_t timeout); 187 uint32_t timeout);
@@ -193,6 +200,9 @@ void lpfc_mbuf_free(struct lpfc_hba *, void *, dma_addr_t);
193 200
194/* Function prototypes. */ 201/* Function prototypes. */
195const char* lpfc_info(struct Scsi_Host *); 202const char* lpfc_info(struct Scsi_Host *);
203void lpfc_scan_start(struct Scsi_Host *);
204int lpfc_scan_finished(struct Scsi_Host *, unsigned long);
205
196void lpfc_get_cfgparam(struct lpfc_hba *); 206void lpfc_get_cfgparam(struct lpfc_hba *);
197int lpfc_alloc_sysfs_attr(struct lpfc_hba *); 207int lpfc_alloc_sysfs_attr(struct lpfc_hba *);
198void lpfc_free_sysfs_attr(struct lpfc_hba *); 208void lpfc_free_sysfs_attr(struct lpfc_hba *);
diff --git a/drivers/scsi/lpfc/lpfc_ct.c b/drivers/scsi/lpfc/lpfc_ct.c
index a51a41b7f15d..34a9e3bb2614 100644
--- a/drivers/scsi/lpfc/lpfc_ct.c
+++ b/drivers/scsi/lpfc/lpfc_ct.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -334,21 +334,22 @@ lpfc_ns_rsp(struct lpfc_hba * phba, struct lpfc_dmabuf * mp, uint32_t Size)
334 334
335 lpfc_set_disctmo(phba); 335 lpfc_set_disctmo(phba);
336 336
337 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
338 337
339 list_add_tail(&head, &mp->list); 338 list_add_tail(&head, &mp->list);
340 list_for_each_entry_safe(mp, next_mp, &head, list) { 339 list_for_each_entry_safe(mp, next_mp, &head, list) {
341 mlast = mp; 340 mlast = mp;
342 341
342 Cnt = Size > FCELSSIZE ? FCELSSIZE : Size;
343
343 Size -= Cnt; 344 Size -= Cnt;
344 345
345 if (!ctptr) 346 if (!ctptr) {
346 ctptr = (uint32_t *) mlast->virt; 347 ctptr = (uint32_t *) mlast->virt;
347 else 348 } else
348 Cnt -= 16; /* subtract length of CT header */ 349 Cnt -= 16; /* subtract length of CT header */
349 350
350 /* Loop through entire NameServer list of DIDs */ 351 /* Loop through entire NameServer list of DIDs */
351 while (Cnt) { 352 while (Cnt >= sizeof (uint32_t)) {
352 353
353 /* Get next DID from NameServer List */ 354 /* Get next DID from NameServer List */
354 CTentry = *ctptr++; 355 CTentry = *ctptr++;
@@ -442,10 +443,8 @@ lpfc_cmpl_ct_cmd_gid_ft(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
442 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) { 443 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
443 phba->fc_ns_retry++; 444 phba->fc_ns_retry++;
444 /* CT command is being retried */ 445 /* CT command is being retried */
445 ndlp = 446 ndlp = lpfc_findnode_did(phba, NameServer_DID);
446 lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, 447 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
447 NameServer_DID);
448 if (ndlp) {
449 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 448 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) ==
450 0) { 449 0) {
451 goto out; 450 goto out;
@@ -729,7 +728,7 @@ lpfc_cmpl_ct_cmd_fdmi(struct lpfc_hba * phba,
729 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp; 728 uint16_t fdmi_cmd = CTcmd->CommandResponse.bits.CmdRsp;
730 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp; 729 uint16_t fdmi_rsp = CTrsp->CommandResponse.bits.CmdRsp;
731 730
732 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID); 731 ndlp = lpfc_findnode_did(phba, FDMI_DID);
733 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) { 732 if (fdmi_rsp == be16_to_cpu(SLI_CT_RESPONSE_FS_RJT)) {
734 /* FDMI rsp failed */ 733 /* FDMI rsp failed */
735 lpfc_printf_log(phba, 734 lpfc_printf_log(phba,
@@ -1039,6 +1038,9 @@ lpfc_fdmi_cmd(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, int cmdcode)
1039 case LA_4GHZ_LINK: 1038 case LA_4GHZ_LINK:
1040 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT; 1039 ae->un.PortSpeed = HBA_PORTSPEED_4GBIT;
1041 break; 1040 break;
1041 case LA_8GHZ_LINK:
1042 ae->un.PortSpeed = HBA_PORTSPEED_8GBIT;
1043 break;
1042 default: 1044 default:
1043 ae->un.PortSpeed = 1045 ae->un.PortSpeed =
1044 HBA_PORTSPEED_UNKNOWN; 1046 HBA_PORTSPEED_UNKNOWN;
@@ -1161,7 +1163,7 @@ lpfc_fdmi_tmo_handler(struct lpfc_hba *phba)
1161{ 1163{
1162 struct lpfc_nodelist *ndlp; 1164 struct lpfc_nodelist *ndlp;
1163 1165
1164 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID); 1166 ndlp = lpfc_findnode_did(phba, FDMI_DID);
1165 if (ndlp) { 1167 if (ndlp) {
1166 if (init_utsname()->nodename[0] != '\0') { 1168 if (init_utsname()->nodename[0] != '\0') {
1167 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA); 1169 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
diff --git a/drivers/scsi/lpfc/lpfc_disc.h b/drivers/scsi/lpfc/lpfc_disc.h
index 9766f909c9c6..498059f3f7f4 100644
--- a/drivers/scsi/lpfc/lpfc_disc.h
+++ b/drivers/scsi/lpfc/lpfc_disc.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -31,6 +31,7 @@
31/* worker thread events */ 31/* worker thread events */
32enum lpfc_work_type { 32enum lpfc_work_type {
33 LPFC_EVT_ONLINE, 33 LPFC_EVT_ONLINE,
34 LPFC_EVT_OFFLINE_PREP,
34 LPFC_EVT_OFFLINE, 35 LPFC_EVT_OFFLINE,
35 LPFC_EVT_WARM_START, 36 LPFC_EVT_WARM_START,
36 LPFC_EVT_KILL, 37 LPFC_EVT_KILL,
@@ -68,7 +69,6 @@ struct lpfc_nodelist {
68 uint16_t nlp_maxframe; /* Max RCV frame size */ 69 uint16_t nlp_maxframe; /* Max RCV frame size */
69 uint8_t nlp_class_sup; /* Supported Classes */ 70 uint8_t nlp_class_sup; /* Supported Classes */
70 uint8_t nlp_retry; /* used for ELS retries */ 71 uint8_t nlp_retry; /* used for ELS retries */
71 uint8_t nlp_disc_refcnt; /* used for DSM */
72 uint8_t nlp_fcp_info; /* class info, bits 0-3 */ 72 uint8_t nlp_fcp_info; /* class info, bits 0-3 */
73#define NLP_FCP_2_DEVICE 0x10 /* FCP-2 device */ 73#define NLP_FCP_2_DEVICE 0x10 /* FCP-2 device */
74 74
@@ -79,20 +79,10 @@ struct lpfc_nodelist {
79 struct lpfc_work_evt els_retry_evt; 79 struct lpfc_work_evt els_retry_evt;
80 unsigned long last_ramp_up_time; /* jiffy of last ramp up */ 80 unsigned long last_ramp_up_time; /* jiffy of last ramp up */
81 unsigned long last_q_full_time; /* jiffy of last queue full */ 81 unsigned long last_q_full_time; /* jiffy of last queue full */
82 struct kref kref;
82}; 83};
83 84
84/* Defines for nlp_flag (uint32) */ 85/* Defines for nlp_flag (uint32) */
85#define NLP_NO_LIST 0x0 /* Indicates immediately free node */
86#define NLP_UNUSED_LIST 0x1 /* Flg to indicate node will be freed */
87#define NLP_PLOGI_LIST 0x2 /* Flg to indicate sent PLOGI */
88#define NLP_ADISC_LIST 0x3 /* Flg to indicate sent ADISC */
89#define NLP_REGLOGIN_LIST 0x4 /* Flg to indicate sent REG_LOGIN */
90#define NLP_PRLI_LIST 0x5 /* Flg to indicate sent PRLI */
91#define NLP_UNMAPPED_LIST 0x6 /* Node is now unmapped */
92#define NLP_MAPPED_LIST 0x7 /* Node is now mapped */
93#define NLP_NPR_LIST 0x8 /* Node is in NPort Recovery state */
94#define NLP_JUST_DQ 0x9 /* just deque ndlp in lpfc_nlp_list */
95#define NLP_LIST_MASK 0xf /* mask to see what list node is on */
96#define NLP_PLOGI_SND 0x20 /* sent PLOGI request for this entry */ 86#define NLP_PLOGI_SND 0x20 /* sent PLOGI request for this entry */
97#define NLP_PRLI_SND 0x40 /* sent PRLI request for this entry */ 87#define NLP_PRLI_SND 0x40 /* sent PRLI request for this entry */
98#define NLP_ADISC_SND 0x80 /* sent ADISC request for this entry */ 88#define NLP_ADISC_SND 0x80 /* sent ADISC request for this entry */
@@ -108,20 +98,8 @@ struct lpfc_nodelist {
108 ACC */ 98 ACC */
109#define NLP_NPR_ADISC 0x2000000 /* Issue ADISC when dq'ed from 99#define NLP_NPR_ADISC 0x2000000 /* Issue ADISC when dq'ed from
110 NPR list */ 100 NPR list */
111#define NLP_DELAY_REMOVE 0x4000000 /* Defer removal till end of DSM */
112#define NLP_NODEV_REMOVE 0x8000000 /* Defer removal till discovery ends */ 101#define NLP_NODEV_REMOVE 0x8000000 /* Defer removal till discovery ends */
113 102
114/* Defines for list searchs */
115#define NLP_SEARCH_MAPPED 0x1 /* search mapped */
116#define NLP_SEARCH_UNMAPPED 0x2 /* search unmapped */
117#define NLP_SEARCH_PLOGI 0x4 /* search plogi */
118#define NLP_SEARCH_ADISC 0x8 /* search adisc */
119#define NLP_SEARCH_REGLOGIN 0x10 /* search reglogin */
120#define NLP_SEARCH_PRLI 0x20 /* search prli */
121#define NLP_SEARCH_NPR 0x40 /* search npr */
122#define NLP_SEARCH_UNUSED 0x80 /* search mapped */
123#define NLP_SEARCH_ALL 0xff /* search all lists */
124
125/* There are 4 different double linked lists nodelist entries can reside on. 103/* There are 4 different double linked lists nodelist entries can reside on.
126 * The Port Login (PLOGI) list and Address Discovery (ADISC) list are used 104 * The Port Login (PLOGI) list and Address Discovery (ADISC) list are used
127 * when Link Up discovery or Registered State Change Notification (RSCN) 105 * when Link Up discovery or Registered State Change Notification (RSCN)
diff --git a/drivers/scsi/lpfc/lpfc_els.c b/drivers/scsi/lpfc/lpfc_els.c
index a5f33a0dd4e7..638b3cd677bd 100644
--- a/drivers/scsi/lpfc/lpfc_els.c
+++ b/drivers/scsi/lpfc/lpfc_els.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -182,6 +182,7 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
182 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64)); 182 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
183 icmd->un.elsreq64.remoteID = did; /* DID */ 183 icmd->un.elsreq64.remoteID = did; /* DID */
184 icmd->ulpCommand = CMD_ELS_REQUEST64_CR; 184 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
185 icmd->ulpTimeout = phba->fc_ratov * 2;
185 } else { 186 } else {
186 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64); 187 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
187 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX; 188 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
@@ -208,9 +209,9 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
208 } 209 }
209 210
210 /* Save for completion so we can release these resources */ 211 /* Save for completion so we can release these resources */
211 elsiocb->context1 = (uint8_t *) ndlp; 212 elsiocb->context1 = lpfc_nlp_get(ndlp);
212 elsiocb->context2 = (uint8_t *) pcmd; 213 elsiocb->context2 = pcmd;
213 elsiocb->context3 = (uint8_t *) pbuflist; 214 elsiocb->context3 = pbuflist;
214 elsiocb->retry = retry; 215 elsiocb->retry = retry;
215 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT; 216 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
216 217
@@ -222,16 +223,16 @@ lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
222 /* Xmit ELS command <elsCmd> to remote NPORT <did> */ 223 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
223 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 224 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
224 "%d:0116 Xmit ELS command x%x to remote " 225 "%d:0116 Xmit ELS command x%x to remote "
225 "NPORT x%x Data: x%x x%x\n", 226 "NPORT x%x I/O tag: x%x, HBA state: x%x\n",
226 phba->brd_no, elscmd, 227 phba->brd_no, elscmd,
227 did, icmd->ulpIoTag, phba->hba_state); 228 did, elsiocb->iotag, phba->hba_state);
228 } else { 229 } else {
229 /* Xmit ELS response <elsCmd> to remote NPORT <did> */ 230 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
230 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 231 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
231 "%d:0117 Xmit ELS response x%x to remote " 232 "%d:0117 Xmit ELS response x%x to remote "
232 "NPORT x%x Data: x%x x%x\n", 233 "NPORT x%x I/O tag: x%x, size: x%x\n",
233 phba->brd_no, elscmd, 234 phba->brd_no, elscmd,
234 ndlp->nlp_DID, icmd->ulpIoTag, cmdSize); 235 ndlp->nlp_DID, elsiocb->iotag, cmdSize);
235 } 236 }
236 237
237 return elsiocb; 238 return elsiocb;
@@ -304,7 +305,7 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
304 goto fail_free_mbox; 305 goto fail_free_mbox;
305 306
306 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login; 307 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
307 mbox->context2 = ndlp; 308 mbox->context2 = lpfc_nlp_get(ndlp);
308 309
309 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB); 310 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
310 if (rc == MBX_NOT_FINISHED) 311 if (rc == MBX_NOT_FINISHED)
@@ -313,6 +314,7 @@ lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
313 return 0; 314 return 0;
314 315
315 fail_issue_reg_login: 316 fail_issue_reg_login:
317 lpfc_nlp_put(ndlp);
316 mp = (struct lpfc_dmabuf *) mbox->context1; 318 mp = (struct lpfc_dmabuf *) mbox->context1;
317 lpfc_mbuf_free(phba, mp->virt, mp->phys); 319 lpfc_mbuf_free(phba, mp->virt, mp->phys);
318 kfree(mp); 320 kfree(mp);
@@ -368,9 +370,9 @@ lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
368 mempool_free(mbox, phba->mbox_mem_pool); 370 mempool_free(mbox, phba->mbox_mem_pool);
369 goto fail; 371 goto fail;
370 } 372 }
371 mempool_free(ndlp, phba->nlp_mem_pool); 373 lpfc_nlp_put(ndlp);
372 374
373 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, PT2PT_RemoteID); 375 ndlp = lpfc_findnode_did(phba, PT2PT_RemoteID);
374 if (!ndlp) { 376 if (!ndlp) {
375 /* 377 /*
376 * Cannot find existing Fabric ndlp, so allocate a 378 * Cannot find existing Fabric ndlp, so allocate a
@@ -387,12 +389,11 @@ lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
387 sizeof(struct lpfc_name)); 389 sizeof(struct lpfc_name));
388 memcpy(&ndlp->nlp_nodename, &sp->nodeName, 390 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
389 sizeof(struct lpfc_name)); 391 sizeof(struct lpfc_name));
390 ndlp->nlp_state = NLP_STE_NPR_NODE; 392 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
391 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
392 ndlp->nlp_flag |= NLP_NPR_2B_DISC; 393 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
393 } else { 394 } else {
394 /* This side will wait for the PLOGI */ 395 /* This side will wait for the PLOGI */
395 mempool_free( ndlp, phba->nlp_mem_pool); 396 lpfc_nlp_put(ndlp);
396 } 397 }
397 398
398 spin_lock_irq(phba->host->host_lock); 399 spin_lock_irq(phba->host->host_lock);
@@ -407,8 +408,8 @@ lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
407} 408}
408 409
409static void 410static void
410lpfc_cmpl_els_flogi(struct lpfc_hba * phba, 411lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
411 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb) 412 struct lpfc_iocbq *rspiocb)
412{ 413{
413 IOCB_t *irsp = &rspiocb->iocb; 414 IOCB_t *irsp = &rspiocb->iocb;
414 struct lpfc_nodelist *ndlp = cmdiocb->context1; 415 struct lpfc_nodelist *ndlp = cmdiocb->context1;
@@ -418,7 +419,7 @@ lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
418 419
419 /* Check to see if link went down during discovery */ 420 /* Check to see if link went down during discovery */
420 if (lpfc_els_chk_latt(phba)) { 421 if (lpfc_els_chk_latt(phba)) {
421 lpfc_nlp_remove(phba, ndlp); 422 lpfc_nlp_put(ndlp);
422 goto out; 423 goto out;
423 } 424 }
424 425
@@ -433,13 +434,12 @@ lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
433 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP); 434 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
434 spin_unlock_irq(phba->host->host_lock); 435 spin_unlock_irq(phba->host->host_lock);
435 436
436 /* If private loop, then allow max outstandting els to be 437 /* If private loop, then allow max outstanding els to be
437 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no 438 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
438 * alpa map would take too long otherwise. 439 * alpa map would take too long otherwise.
439 */ 440 */
440 if (phba->alpa_map[0] == 0) { 441 if (phba->alpa_map[0] == 0) {
441 phba->cfg_discovery_threads = 442 phba->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
442 LPFC_MAX_DISC_THREADS;
443 } 443 }
444 444
445 /* FLOGI failure */ 445 /* FLOGI failure */
@@ -484,7 +484,7 @@ lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
484 } 484 }
485 485
486flogifail: 486flogifail:
487 lpfc_nlp_remove(phba, ndlp); 487 lpfc_nlp_put(ndlp);
488 488
489 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT || 489 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
490 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED && 490 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
@@ -582,24 +582,8 @@ lpfc_els_abort_flogi(struct lpfc_hba * phba)
582 icmd = &iocb->iocb; 582 icmd = &iocb->iocb;
583 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) { 583 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
584 ndlp = (struct lpfc_nodelist *)(iocb->context1); 584 ndlp = (struct lpfc_nodelist *)(iocb->context1);
585 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) { 585 if (ndlp && (ndlp->nlp_DID == Fabric_DID))
586 list_del(&iocb->list); 586 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
587 pring->txcmplq_cnt--;
588
589 if ((icmd->un.elsreq64.bdl.ulpIoTag32)) {
590 lpfc_sli_issue_abort_iotag32
591 (phba, pring, iocb);
592 }
593 if (iocb->iocb_cmpl) {
594 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
595 icmd->un.ulpWord[4] =
596 IOERR_SLI_ABORTED;
597 spin_unlock_irq(phba->host->host_lock);
598 (iocb->iocb_cmpl) (phba, iocb, iocb);
599 spin_lock_irq(phba->host->host_lock);
600 } else
601 lpfc_sli_release_iocbq(phba, iocb);
602 }
603 } 587 }
604 } 588 }
605 spin_unlock_irq(phba->host->host_lock); 589 spin_unlock_irq(phba->host->host_lock);
@@ -608,12 +592,12 @@ lpfc_els_abort_flogi(struct lpfc_hba * phba)
608} 592}
609 593
610int 594int
611lpfc_initial_flogi(struct lpfc_hba * phba) 595lpfc_initial_flogi(struct lpfc_hba *phba)
612{ 596{
613 struct lpfc_nodelist *ndlp; 597 struct lpfc_nodelist *ndlp;
614 598
615 /* First look for the Fabric ndlp */ 599 /* First look for the Fabric ndlp */
616 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, Fabric_DID); 600 ndlp = lpfc_findnode_did(phba, Fabric_DID);
617 if (!ndlp) { 601 if (!ndlp) {
618 /* Cannot find existing Fabric ndlp, so allocate a new one */ 602 /* Cannot find existing Fabric ndlp, so allocate a new one */
619 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); 603 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
@@ -621,10 +605,10 @@ lpfc_initial_flogi(struct lpfc_hba * phba)
621 return 0; 605 return 0;
622 lpfc_nlp_init(phba, ndlp, Fabric_DID); 606 lpfc_nlp_init(phba, ndlp, Fabric_DID);
623 } else { 607 } else {
624 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ); 608 lpfc_dequeue_node(phba, ndlp);
625 } 609 }
626 if (lpfc_issue_els_flogi(phba, ndlp, 0)) { 610 if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
627 mempool_free( ndlp, phba->nlp_mem_pool); 611 lpfc_nlp_put(ndlp);
628 } 612 }
629 return 1; 613 return 1;
630} 614}
@@ -653,7 +637,7 @@ lpfc_more_plogi(struct lpfc_hba * phba)
653} 637}
654 638
655static struct lpfc_nodelist * 639static struct lpfc_nodelist *
656lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_dmabuf *prsp, 640lpfc_plogi_confirm_nport(struct lpfc_hba *phba, struct lpfc_dmabuf *prsp,
657 struct lpfc_nodelist *ndlp) 641 struct lpfc_nodelist *ndlp)
658{ 642{
659 struct lpfc_nodelist *new_ndlp; 643 struct lpfc_nodelist *new_ndlp;
@@ -670,12 +654,12 @@ lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_dmabuf *prsp,
670 654
671 lp = (uint32_t *) prsp->virt; 655 lp = (uint32_t *) prsp->virt;
672 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t)); 656 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
673 memset(name, 0, sizeof (struct lpfc_name)); 657 memset(name, 0, sizeof(struct lpfc_name));
674 658
675 /* Now we to find out if the NPort we are logging into, matches the WWPN 659 /* Now we find out if the NPort we are logging into, matches the WWPN
676 * we have for that ndlp. If not, we have some work to do. 660 * we have for that ndlp. If not, we have some work to do.
677 */ 661 */
678 new_ndlp = lpfc_findnode_wwpn(phba, NLP_SEARCH_ALL, &sp->portName); 662 new_ndlp = lpfc_findnode_wwpn(phba, &sp->portName);
679 663
680 if (new_ndlp == ndlp) 664 if (new_ndlp == ndlp)
681 return ndlp; 665 return ndlp;
@@ -695,18 +679,15 @@ lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_dmabuf *prsp,
695 lpfc_unreg_rpi(phba, new_ndlp); 679 lpfc_unreg_rpi(phba, new_ndlp);
696 new_ndlp->nlp_DID = ndlp->nlp_DID; 680 new_ndlp->nlp_DID = ndlp->nlp_DID;
697 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state; 681 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
698 new_ndlp->nlp_state = ndlp->nlp_state; 682 lpfc_nlp_set_state(phba, new_ndlp, ndlp->nlp_state);
699 lpfc_nlp_list(phba, new_ndlp, ndlp->nlp_flag & NLP_LIST_MASK);
700 683
701 /* Move this back to NPR list */ 684 /* Move this back to NPR list */
702 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) { 685 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
703 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 686 lpfc_drop_node(phba, ndlp);
704 }
705 else { 687 else {
706 lpfc_unreg_rpi(phba, ndlp); 688 lpfc_unreg_rpi(phba, ndlp);
707 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */ 689 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
708 ndlp->nlp_state = NLP_STE_NPR_NODE; 690 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
709 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
710 } 691 }
711 return new_ndlp; 692 return new_ndlp;
712} 693}
@@ -720,13 +701,11 @@ lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
720 struct lpfc_dmabuf *prsp; 701 struct lpfc_dmabuf *prsp;
721 int disc, rc, did, type; 702 int disc, rc, did, type;
722 703
723
724 /* we pass cmdiocb to state machine which needs rspiocb as well */ 704 /* we pass cmdiocb to state machine which needs rspiocb as well */
725 cmdiocb->context_un.rsp_iocb = rspiocb; 705 cmdiocb->context_un.rsp_iocb = rspiocb;
726 706
727 irsp = &rspiocb->iocb; 707 irsp = &rspiocb->iocb;
728 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, 708 ndlp = lpfc_findnode_did(phba, irsp->un.elsreq64.remoteID);
729 irsp->un.elsreq64.remoteID);
730 if (!ndlp) 709 if (!ndlp)
731 goto out; 710 goto out;
732 711
@@ -1354,7 +1333,7 @@ lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1354 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, 1333 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1355 ndlp->nlp_DID, ELS_CMD_SCR); 1334 ndlp->nlp_DID, ELS_CMD_SCR);
1356 if (!elsiocb) { 1335 if (!elsiocb) {
1357 mempool_free( ndlp, phba->nlp_mem_pool); 1336 lpfc_nlp_put(ndlp);
1358 return 1; 1337 return 1;
1359 } 1338 }
1360 1339
@@ -1373,12 +1352,12 @@ lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1373 spin_lock_irq(phba->host->host_lock); 1352 spin_lock_irq(phba->host->host_lock);
1374 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 1353 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1375 spin_unlock_irq(phba->host->host_lock); 1354 spin_unlock_irq(phba->host->host_lock);
1376 mempool_free( ndlp, phba->nlp_mem_pool); 1355 lpfc_nlp_put(ndlp);
1377 lpfc_els_free_iocb(phba, elsiocb); 1356 lpfc_els_free_iocb(phba, elsiocb);
1378 return 1; 1357 return 1;
1379 } 1358 }
1380 spin_unlock_irq(phba->host->host_lock); 1359 spin_unlock_irq(phba->host->host_lock);
1381 mempool_free( ndlp, phba->nlp_mem_pool); 1360 lpfc_nlp_put(ndlp);
1382 return 0; 1361 return 0;
1383} 1362}
1384 1363
@@ -1407,7 +1386,7 @@ lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1407 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp, 1386 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1408 ndlp->nlp_DID, ELS_CMD_RNID); 1387 ndlp->nlp_DID, ELS_CMD_RNID);
1409 if (!elsiocb) { 1388 if (!elsiocb) {
1410 mempool_free( ndlp, phba->nlp_mem_pool); 1389 lpfc_nlp_put(ndlp);
1411 return 1; 1390 return 1;
1412 } 1391 }
1413 1392
@@ -1428,7 +1407,7 @@ lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1428 1407
1429 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name)); 1408 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
1430 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name)); 1409 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1431 if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) { 1410 if ((ondlp = lpfc_findnode_did(phba, nportid))) {
1432 memcpy(&fp->OportName, &ondlp->nlp_portname, 1411 memcpy(&fp->OportName, &ondlp->nlp_portname,
1433 sizeof (struct lpfc_name)); 1412 sizeof (struct lpfc_name));
1434 memcpy(&fp->OnodeName, &ondlp->nlp_nodename, 1413 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
@@ -1440,12 +1419,12 @@ lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1440 spin_lock_irq(phba->host->host_lock); 1419 spin_lock_irq(phba->host->host_lock);
1441 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 1420 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1442 spin_unlock_irq(phba->host->host_lock); 1421 spin_unlock_irq(phba->host->host_lock);
1443 mempool_free( ndlp, phba->nlp_mem_pool); 1422 lpfc_nlp_put(ndlp);
1444 lpfc_els_free_iocb(phba, elsiocb); 1423 lpfc_els_free_iocb(phba, elsiocb);
1445 return 1; 1424 return 1;
1446 } 1425 }
1447 spin_unlock_irq(phba->host->host_lock); 1426 spin_unlock_irq(phba->host->host_lock);
1448 mempool_free( ndlp, phba->nlp_mem_pool); 1427 lpfc_nlp_put(ndlp);
1449 return 0; 1428 return 0;
1450} 1429}
1451 1430
@@ -1554,29 +1533,25 @@ lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1554 case ELS_CMD_PLOGI: 1533 case ELS_CMD_PLOGI:
1555 if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) { 1534 if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) {
1556 ndlp->nlp_prev_state = ndlp->nlp_state; 1535 ndlp->nlp_prev_state = ndlp->nlp_state;
1557 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 1536 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
1558 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1559 } 1537 }
1560 break; 1538 break;
1561 case ELS_CMD_ADISC: 1539 case ELS_CMD_ADISC:
1562 if (!lpfc_issue_els_adisc(phba, ndlp, retry)) { 1540 if (!lpfc_issue_els_adisc(phba, ndlp, retry)) {
1563 ndlp->nlp_prev_state = ndlp->nlp_state; 1541 ndlp->nlp_prev_state = ndlp->nlp_state;
1564 ndlp->nlp_state = NLP_STE_ADISC_ISSUE; 1542 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
1565 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1566 } 1543 }
1567 break; 1544 break;
1568 case ELS_CMD_PRLI: 1545 case ELS_CMD_PRLI:
1569 if (!lpfc_issue_els_prli(phba, ndlp, retry)) { 1546 if (!lpfc_issue_els_prli(phba, ndlp, retry)) {
1570 ndlp->nlp_prev_state = ndlp->nlp_state; 1547 ndlp->nlp_prev_state = ndlp->nlp_state;
1571 ndlp->nlp_state = NLP_STE_PRLI_ISSUE; 1548 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE);
1572 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1573 } 1549 }
1574 break; 1550 break;
1575 case ELS_CMD_LOGO: 1551 case ELS_CMD_LOGO:
1576 if (!lpfc_issue_els_logo(phba, ndlp, retry)) { 1552 if (!lpfc_issue_els_logo(phba, ndlp, retry)) {
1577 ndlp->nlp_prev_state = ndlp->nlp_state; 1553 ndlp->nlp_prev_state = ndlp->nlp_state;
1578 ndlp->nlp_state = NLP_STE_NPR_NODE; 1554 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1579 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1580 } 1555 }
1581 break; 1556 break;
1582 } 1557 }
@@ -1614,12 +1589,12 @@ lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1614 cmd = *elscmd++; 1589 cmd = *elscmd++;
1615 } 1590 }
1616 1591
1617 if(ndlp) 1592 if (ndlp)
1618 did = ndlp->nlp_DID; 1593 did = ndlp->nlp_DID;
1619 else { 1594 else {
1620 /* We should only hit this case for retrying PLOGI */ 1595 /* We should only hit this case for retrying PLOGI */
1621 did = irsp->un.elsreq64.remoteID; 1596 did = irsp->un.elsreq64.remoteID;
1622 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did); 1597 ndlp = lpfc_findnode_did(phba, did);
1623 if (!ndlp && (cmd != ELS_CMD_PLOGI)) 1598 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1624 return 1; 1599 return 1;
1625 } 1600 }
@@ -1746,8 +1721,7 @@ lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1746 ndlp->nlp_flag |= NLP_DELAY_TMO; 1721 ndlp->nlp_flag |= NLP_DELAY_TMO;
1747 1722
1748 ndlp->nlp_prev_state = ndlp->nlp_state; 1723 ndlp->nlp_prev_state = ndlp->nlp_state;
1749 ndlp->nlp_state = NLP_STE_NPR_NODE; 1724 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1750 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1751 ndlp->nlp_last_elscmd = cmd; 1725 ndlp->nlp_last_elscmd = cmd;
1752 1726
1753 return 1; 1727 return 1;
@@ -1759,27 +1733,24 @@ lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1759 case ELS_CMD_PLOGI: 1733 case ELS_CMD_PLOGI:
1760 if (ndlp) { 1734 if (ndlp) {
1761 ndlp->nlp_prev_state = ndlp->nlp_state; 1735 ndlp->nlp_prev_state = ndlp->nlp_state;
1762 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 1736 lpfc_nlp_set_state(phba, ndlp,
1763 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST); 1737 NLP_STE_PLOGI_ISSUE);
1764 } 1738 }
1765 lpfc_issue_els_plogi(phba, did, cmdiocb->retry); 1739 lpfc_issue_els_plogi(phba, did, cmdiocb->retry);
1766 return 1; 1740 return 1;
1767 case ELS_CMD_ADISC: 1741 case ELS_CMD_ADISC:
1768 ndlp->nlp_prev_state = ndlp->nlp_state; 1742 ndlp->nlp_prev_state = ndlp->nlp_state;
1769 ndlp->nlp_state = NLP_STE_ADISC_ISSUE; 1743 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
1770 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1771 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry); 1744 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
1772 return 1; 1745 return 1;
1773 case ELS_CMD_PRLI: 1746 case ELS_CMD_PRLI:
1774 ndlp->nlp_prev_state = ndlp->nlp_state; 1747 ndlp->nlp_prev_state = ndlp->nlp_state;
1775 ndlp->nlp_state = NLP_STE_PRLI_ISSUE; 1748 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE);
1776 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1777 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry); 1749 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
1778 return 1; 1750 return 1;
1779 case ELS_CMD_LOGO: 1751 case ELS_CMD_LOGO:
1780 ndlp->nlp_prev_state = ndlp->nlp_state; 1752 ndlp->nlp_prev_state = ndlp->nlp_state;
1781 ndlp->nlp_state = NLP_STE_NPR_NODE; 1753 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1782 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1783 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry); 1754 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
1784 return 1; 1755 return 1;
1785 } 1756 }
@@ -1796,10 +1767,14 @@ lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1796} 1767}
1797 1768
1798int 1769int
1799lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb) 1770lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
1800{ 1771{
1801 struct lpfc_dmabuf *buf_ptr, *buf_ptr1; 1772 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1802 1773
1774 if (elsiocb->context1) {
1775 lpfc_nlp_put(elsiocb->context1);
1776 elsiocb->context1 = NULL;
1777 }
1803 /* context2 = cmd, context2->next = rsp, context3 = bpl */ 1778 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1804 if (elsiocb->context2) { 1779 if (elsiocb->context2) {
1805 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2; 1780 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
@@ -1843,7 +1818,7 @@ lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1843 1818
1844 switch (ndlp->nlp_state) { 1819 switch (ndlp->nlp_state) {
1845 case NLP_STE_UNUSED_NODE: /* node is just allocated */ 1820 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1846 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1821 lpfc_drop_node(phba, ndlp);
1847 break; 1822 break;
1848 case NLP_STE_NPR_NODE: /* NPort Recovery mode */ 1823 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1849 lpfc_unreg_rpi(phba, ndlp); 1824 lpfc_unreg_rpi(phba, ndlp);
@@ -1856,8 +1831,8 @@ lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1856} 1831}
1857 1832
1858static void 1833static void
1859lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 1834lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1860 struct lpfc_iocbq * rspiocb) 1835 struct lpfc_iocbq *rspiocb)
1861{ 1836{
1862 IOCB_t *irsp; 1837 IOCB_t *irsp;
1863 struct lpfc_nodelist *ndlp; 1838 struct lpfc_nodelist *ndlp;
@@ -1872,14 +1847,14 @@ lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1872 1847
1873 1848
1874 /* Check to see if link went down during discovery */ 1849 /* Check to see if link went down during discovery */
1875 if ((lpfc_els_chk_latt(phba)) || !ndlp) { 1850 if (lpfc_els_chk_latt(phba) || !ndlp) {
1876 if (mbox) { 1851 if (mbox) {
1877 mp = (struct lpfc_dmabuf *) mbox->context1; 1852 mp = (struct lpfc_dmabuf *) mbox->context1;
1878 if (mp) { 1853 if (mp) {
1879 lpfc_mbuf_free(phba, mp->virt, mp->phys); 1854 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1880 kfree(mp); 1855 kfree(mp);
1881 } 1856 }
1882 mempool_free( mbox, phba->mbox_mem_pool); 1857 mempool_free(mbox, phba->mbox_mem_pool);
1883 } 1858 }
1884 goto out; 1859 goto out;
1885 } 1860 }
@@ -1899,15 +1874,15 @@ lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1899 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) { 1874 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
1900 lpfc_unreg_rpi(phba, ndlp); 1875 lpfc_unreg_rpi(phba, ndlp);
1901 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; 1876 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1902 mbox->context2 = ndlp; 1877 mbox->context2 = lpfc_nlp_get(ndlp);
1903 ndlp->nlp_prev_state = ndlp->nlp_state; 1878 ndlp->nlp_prev_state = ndlp->nlp_state;
1904 ndlp->nlp_state = NLP_STE_REG_LOGIN_ISSUE; 1879 lpfc_nlp_set_state(phba, ndlp, NLP_STE_REG_LOGIN_ISSUE);
1905 lpfc_nlp_list(phba, ndlp, NLP_REGLOGIN_LIST);
1906 if (lpfc_sli_issue_mbox(phba, mbox, 1880 if (lpfc_sli_issue_mbox(phba, mbox,
1907 (MBX_NOWAIT | MBX_STOP_IOCB)) 1881 (MBX_NOWAIT | MBX_STOP_IOCB))
1908 != MBX_NOT_FINISHED) { 1882 != MBX_NOT_FINISHED) {
1909 goto out; 1883 goto out;
1910 } 1884 }
1885 lpfc_nlp_put(ndlp);
1911 /* NOTE: we should have messages for unsuccessful 1886 /* NOTE: we should have messages for unsuccessful
1912 reglogin */ 1887 reglogin */
1913 } else { 1888 } else {
@@ -1917,7 +1892,7 @@ lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1917 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) || 1892 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1918 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) { 1893 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) {
1919 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) { 1894 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1920 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1895 lpfc_drop_node(phba, ndlp);
1921 ndlp = NULL; 1896 ndlp = NULL;
1922 } 1897 }
1923 } 1898 }
@@ -2012,15 +1987,16 @@ lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
2012 return 1; 1987 return 1;
2013 } 1988 }
2014 1989
2015 if (newnode) 1990 if (newnode) {
1991 lpfc_nlp_put(ndlp);
2016 elsiocb->context1 = NULL; 1992 elsiocb->context1 = NULL;
1993 }
2017 1994
2018 /* Xmit ELS ACC response tag <ulpIoTag> */ 1995 /* Xmit ELS ACC response tag <ulpIoTag> */
2019 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 1996 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2020 "%d:0128 Xmit ELS ACC response tag x%x " 1997 "%d:0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2021 "Data: x%x x%x x%x x%x x%x\n", 1998 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2022 phba->brd_no, 1999 phba->brd_no, elsiocb->iotag,
2023 elsiocb->iocb.ulpIoTag,
2024 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2000 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2025 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2001 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2026 2002
@@ -2077,10 +2053,9 @@ lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
2077 2053
2078 /* Xmit ELS RJT <err> response tag <ulpIoTag> */ 2054 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2079 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2055 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2080 "%d:0129 Xmit ELS RJT x%x response tag x%x " 2056 "%d:0129 Xmit ELS RJT x%x response tag x%x xri x%x, "
2081 "Data: x%x x%x x%x x%x x%x\n", 2057 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2082 phba->brd_no, 2058 phba->brd_no, rejectError, elsiocb->iotag,
2083 rejectError, elsiocb->iocb.ulpIoTag,
2084 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2059 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2085 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2060 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2086 2061
@@ -2119,18 +2094,18 @@ lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
2119 if (!elsiocb) 2094 if (!elsiocb)
2120 return 1; 2095 return 1;
2121 2096
2097 icmd = &elsiocb->iocb;
2098 oldcmd = &oldiocb->iocb;
2099 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2100
2122 /* Xmit ADISC ACC response tag <ulpIoTag> */ 2101 /* Xmit ADISC ACC response tag <ulpIoTag> */
2123 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2102 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2124 "%d:0130 Xmit ADISC ACC response tag x%x " 2103 "%d:0130 Xmit ADISC ACC response iotag x%x xri: "
2125 "Data: x%x x%x x%x x%x x%x\n", 2104 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2126 phba->brd_no, 2105 phba->brd_no, elsiocb->iotag,
2127 elsiocb->iocb.ulpIoTag,
2128 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2106 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2129 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2107 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2130 2108
2131 icmd = &elsiocb->iocb;
2132 oldcmd = &oldiocb->iocb;
2133 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2134 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2109 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2135 2110
2136 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2111 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
@@ -2155,8 +2130,8 @@ lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
2155} 2130}
2156 2131
2157int 2132int
2158lpfc_els_rsp_prli_acc(struct lpfc_hba * phba, 2133lpfc_els_rsp_prli_acc(struct lpfc_hba *phba, struct lpfc_iocbq *oldiocb,
2159 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp) 2134 struct lpfc_nodelist *ndlp)
2160{ 2135{
2161 PRLI *npr; 2136 PRLI *npr;
2162 lpfc_vpd_t *vpd; 2137 lpfc_vpd_t *vpd;
@@ -2178,18 +2153,18 @@ lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
2178 if (!elsiocb) 2153 if (!elsiocb)
2179 return 1; 2154 return 1;
2180 2155
2156 icmd = &elsiocb->iocb;
2157 oldcmd = &oldiocb->iocb;
2158 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2159
2181 /* Xmit PRLI ACC response tag <ulpIoTag> */ 2160 /* Xmit PRLI ACC response tag <ulpIoTag> */
2182 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2161 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2183 "%d:0131 Xmit PRLI ACC response tag x%x " 2162 "%d:0131 Xmit PRLI ACC response tag x%x xri x%x, "
2184 "Data: x%x x%x x%x x%x x%x\n", 2163 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2185 phba->brd_no, 2164 phba->brd_no, elsiocb->iotag,
2186 elsiocb->iocb.ulpIoTag,
2187 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2165 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2188 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2166 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2189 2167
2190 icmd = &elsiocb->iocb;
2191 oldcmd = &oldiocb->iocb;
2192 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2193 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2168 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2194 2169
2195 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)); 2170 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
@@ -2232,9 +2207,8 @@ lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
2232} 2207}
2233 2208
2234static int 2209static int
2235lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba, 2210lpfc_els_rsp_rnid_acc(struct lpfc_hba *phba, uint8_t format,
2236 uint8_t format, 2211 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
2237 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2238{ 2212{
2239 RNID *rn; 2213 RNID *rn;
2240 IOCB_t *icmd; 2214 IOCB_t *icmd;
@@ -2259,17 +2233,17 @@ lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2259 if (!elsiocb) 2233 if (!elsiocb)
2260 return 1; 2234 return 1;
2261 2235
2236 icmd = &elsiocb->iocb;
2237 oldcmd = &oldiocb->iocb;
2238 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2239
2262 /* Xmit RNID ACC response tag <ulpIoTag> */ 2240 /* Xmit RNID ACC response tag <ulpIoTag> */
2263 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2241 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2264 "%d:0132 Xmit RNID ACC response tag x%x " 2242 "%d:0132 Xmit RNID ACC response tag x%x "
2265 "Data: x%x\n", 2243 "xri x%x\n",
2266 phba->brd_no, 2244 phba->brd_no, elsiocb->iotag,
2267 elsiocb->iocb.ulpIoTag,
2268 elsiocb->iocb.ulpContext); 2245 elsiocb->iocb.ulpContext);
2269 2246
2270 icmd = &elsiocb->iocb;
2271 oldcmd = &oldiocb->iocb;
2272 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2273 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt); 2247 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2274 2248
2275 *((uint32_t *) (pcmd)) = ELS_CMD_ACC; 2249 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
@@ -2301,6 +2275,7 @@ lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2301 2275
2302 phba->fc_stat.elsXmitACC++; 2276 phba->fc_stat.elsXmitACC++;
2303 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; 2277 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2278 lpfc_nlp_put(ndlp);
2304 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl, 2279 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2305 * it could be freed */ 2280 * it could be freed */
2306 2281
@@ -2315,32 +2290,31 @@ lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2315} 2290}
2316 2291
2317int 2292int
2318lpfc_els_disc_adisc(struct lpfc_hba * phba) 2293lpfc_els_disc_adisc(struct lpfc_hba *phba)
2319{ 2294{
2320 int sentadisc; 2295 int sentadisc;
2321 struct lpfc_nodelist *ndlp, *next_ndlp; 2296 struct lpfc_nodelist *ndlp, *next_ndlp;
2322 2297
2323 sentadisc = 0; 2298 sentadisc = 0;
2324 /* go thru NPR list and issue any remaining ELS ADISCs */ 2299 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2325 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list, 2300 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) {
2326 nlp_listp) { 2301 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2327 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { 2302 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2328 if (ndlp->nlp_flag & NLP_NPR_ADISC) { 2303 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
2329 ndlp->nlp_flag &= ~NLP_NPR_ADISC; 2304 spin_lock_irq(phba->host->host_lock);
2330 ndlp->nlp_prev_state = ndlp->nlp_state; 2305 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2331 ndlp->nlp_state = NLP_STE_ADISC_ISSUE; 2306 spin_unlock_irq(phba->host->host_lock);
2332 lpfc_nlp_list(phba, ndlp, 2307 ndlp->nlp_prev_state = ndlp->nlp_state;
2333 NLP_ADISC_LIST); 2308 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
2334 lpfc_issue_els_adisc(phba, ndlp, 0); 2309 lpfc_issue_els_adisc(phba, ndlp, 0);
2335 sentadisc++; 2310 sentadisc++;
2336 phba->num_disc_nodes++; 2311 phba->num_disc_nodes++;
2337 if (phba->num_disc_nodes >= 2312 if (phba->num_disc_nodes >=
2338 phba->cfg_discovery_threads) { 2313 phba->cfg_discovery_threads) {
2339 spin_lock_irq(phba->host->host_lock); 2314 spin_lock_irq(phba->host->host_lock);
2340 phba->fc_flag |= FC_NLP_MORE; 2315 phba->fc_flag |= FC_NLP_MORE;
2341 spin_unlock_irq(phba->host->host_lock); 2316 spin_unlock_irq(phba->host->host_lock);
2342 break; 2317 break;
2343 }
2344 } 2318 }
2345 } 2319 }
2346 } 2320 }
@@ -2360,24 +2334,22 @@ lpfc_els_disc_plogi(struct lpfc_hba * phba)
2360 2334
2361 sentplogi = 0; 2335 sentplogi = 0;
2362 /* go thru NPR list and issue any remaining ELS PLOGIs */ 2336 /* go thru NPR list and issue any remaining ELS PLOGIs */
2363 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list, 2337 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) {
2364 nlp_listp) { 2338 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2365 if ((ndlp->nlp_flag & NLP_NPR_2B_DISC) && 2339 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2366 (!(ndlp->nlp_flag & NLP_DELAY_TMO))) { 2340 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2367 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { 2341 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2368 ndlp->nlp_prev_state = ndlp->nlp_state; 2342 ndlp->nlp_prev_state = ndlp->nlp_state;
2369 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 2343 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
2370 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST); 2344 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
2371 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); 2345 sentplogi++;
2372 sentplogi++; 2346 phba->num_disc_nodes++;
2373 phba->num_disc_nodes++; 2347 if (phba->num_disc_nodes >=
2374 if (phba->num_disc_nodes >= 2348 phba->cfg_discovery_threads) {
2375 phba->cfg_discovery_threads) { 2349 spin_lock_irq(phba->host->host_lock);
2376 spin_lock_irq(phba->host->host_lock); 2350 phba->fc_flag |= FC_NLP_MORE;
2377 phba->fc_flag |= FC_NLP_MORE; 2351 spin_unlock_irq(phba->host->host_lock);
2378 spin_unlock_irq(phba->host->host_lock); 2352 break;
2379 break;
2380 }
2381 } 2353 }
2382 } 2354 }
2383 } 2355 }
@@ -2479,42 +2451,30 @@ lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
2479} 2451}
2480 2452
2481static int 2453static int
2482lpfc_rscn_recovery_check(struct lpfc_hba * phba) 2454lpfc_rscn_recovery_check(struct lpfc_hba *phba)
2483{ 2455{
2484 struct lpfc_nodelist *ndlp = NULL, *next_ndlp; 2456 struct lpfc_nodelist *ndlp = NULL;
2485 struct list_head *listp;
2486 struct list_head *node_list[7];
2487 int i;
2488 2457
2489 /* Look at all nodes effected by pending RSCNs and move 2458 /* Look at all nodes effected by pending RSCNs and move
2490 * them to NPR list. 2459 * them to NPR state.
2491 */ 2460 */
2492 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
2493 node_list[1] = &phba->fc_nlpmap_list;
2494 node_list[2] = &phba->fc_nlpunmap_list;
2495 node_list[3] = &phba->fc_prli_list;
2496 node_list[4] = &phba->fc_reglogin_list;
2497 node_list[5] = &phba->fc_adisc_list;
2498 node_list[6] = &phba->fc_plogi_list;
2499 for (i = 0; i < 7; i++) {
2500 listp = node_list[i];
2501 if (list_empty(listp))
2502 continue;
2503 2461
2504 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) { 2462 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
2505 if (!(lpfc_rscn_payload_check(phba, ndlp->nlp_DID))) 2463 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
2506 continue; 2464 lpfc_rscn_payload_check(phba, ndlp->nlp_DID) == 0)
2465 continue;
2507 2466
2508 lpfc_disc_state_machine(phba, ndlp, NULL, 2467 lpfc_disc_state_machine(phba, ndlp, NULL,
2509 NLP_EVT_DEVICE_RECOVERY); 2468 NLP_EVT_DEVICE_RECOVERY);
2510 2469
2511 /* Make sure NLP_DELAY_TMO is NOT running 2470 /*
2512 * after a device recovery event. 2471 * Make sure NLP_DELAY_TMO is NOT running after a device
2513 */ 2472 * recovery event.
2514 if (ndlp->nlp_flag & NLP_DELAY_TMO) 2473 */
2515 lpfc_cancel_retry_delay_tmo(phba, ndlp); 2474 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2516 } 2475 lpfc_cancel_retry_delay_tmo(phba, ndlp);
2517 } 2476 }
2477
2518 return 0; 2478 return 0;
2519} 2479}
2520 2480
@@ -2639,8 +2599,8 @@ lpfc_els_handle_rscn(struct lpfc_hba * phba)
2639 2599
2640 /* To process RSCN, first compare RSCN data with NameServer */ 2600 /* To process RSCN, first compare RSCN data with NameServer */
2641 phba->fc_ns_retry = 0; 2601 phba->fc_ns_retry = 0;
2642 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, NameServer_DID); 2602 ndlp = lpfc_findnode_did(phba, NameServer_DID);
2643 if (ndlp) { 2603 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
2644 /* Good ndlp, issue CT Request to NameServer */ 2604 /* Good ndlp, issue CT Request to NameServer */
2645 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) { 2605 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
2646 /* Wait for NameServer query cmpl before we can 2606 /* Wait for NameServer query cmpl before we can
@@ -2650,7 +2610,7 @@ lpfc_els_handle_rscn(struct lpfc_hba * phba)
2650 } else { 2610 } else {
2651 /* If login to NameServer does not exist, issue one */ 2611 /* If login to NameServer does not exist, issue one */
2652 /* Good status, issue PLOGI to NameServer */ 2612 /* Good status, issue PLOGI to NameServer */
2653 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID); 2613 ndlp = lpfc_findnode_did(phba, NameServer_DID);
2654 if (ndlp) { 2614 if (ndlp) {
2655 /* Wait for NameServer login cmpl before we can 2615 /* Wait for NameServer login cmpl before we can
2656 continue */ 2616 continue */
@@ -2664,8 +2624,7 @@ lpfc_els_handle_rscn(struct lpfc_hba * phba)
2664 lpfc_nlp_init(phba, ndlp, NameServer_DID); 2624 lpfc_nlp_init(phba, ndlp, NameServer_DID);
2665 ndlp->nlp_type |= NLP_FABRIC; 2625 ndlp->nlp_type |= NLP_FABRIC;
2666 ndlp->nlp_prev_state = ndlp->nlp_state; 2626 ndlp->nlp_prev_state = ndlp->nlp_state;
2667 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 2627 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
2668 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2669 lpfc_issue_els_plogi(phba, NameServer_DID, 0); 2628 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
2670 /* Wait for NameServer login cmpl before we can 2629 /* Wait for NameServer login cmpl before we can
2671 continue */ 2630 continue */
@@ -2734,8 +2693,9 @@ lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2734 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 2693 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2735 rc = lpfc_sli_issue_mbox 2694 rc = lpfc_sli_issue_mbox
2736 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB)); 2695 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2696 lpfc_set_loopback_flag(phba);
2737 if (rc == MBX_NOT_FINISHED) { 2697 if (rc == MBX_NOT_FINISHED) {
2738 mempool_free( mbox, phba->mbox_mem_pool); 2698 mempool_free(mbox, phba->mbox_mem_pool);
2739 } 2699 }
2740 return 1; 2700 return 1;
2741 } else if (rc > 0) { /* greater than */ 2701 } else if (rc > 0) { /* greater than */
@@ -2800,8 +2760,8 @@ lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2800} 2760}
2801 2761
2802static int 2762static int
2803lpfc_els_rcv_lirr(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 2763lpfc_els_rcv_lirr(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2804 struct lpfc_nodelist * ndlp) 2764 struct lpfc_nodelist *ndlp)
2805{ 2765{
2806 struct ls_rjt stat; 2766 struct ls_rjt stat;
2807 2767
@@ -2815,7 +2775,7 @@ lpfc_els_rcv_lirr(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2815} 2775}
2816 2776
2817static void 2777static void
2818lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 2778lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2819{ 2779{
2820 struct lpfc_sli *psli; 2780 struct lpfc_sli *psli;
2821 struct lpfc_sli_ring *pring; 2781 struct lpfc_sli_ring *pring;
@@ -2838,14 +2798,15 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2838 pmb->context2 = NULL; 2798 pmb->context2 = NULL;
2839 2799
2840 if (mb->mbxStatus) { 2800 if (mb->mbxStatus) {
2841 mempool_free( pmb, phba->mbox_mem_pool); 2801 mempool_free(pmb, phba->mbox_mem_pool);
2842 return; 2802 return;
2843 } 2803 }
2844 2804
2845 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t); 2805 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
2846 mempool_free( pmb, phba->mbox_mem_pool); 2806 mempool_free(pmb, phba->mbox_mem_pool);
2847 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp, 2807 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp,
2848 ndlp->nlp_DID, ELS_CMD_ACC); 2808 ndlp->nlp_DID, ELS_CMD_ACC);
2809 lpfc_nlp_put(ndlp);
2849 if (!elsiocb) 2810 if (!elsiocb)
2850 return; 2811 return;
2851 2812
@@ -2875,15 +2836,15 @@ lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2875 2836
2876 /* Xmit ELS RPS ACC response tag <ulpIoTag> */ 2837 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2877 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2838 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2878 "%d:0118 Xmit ELS RPS ACC response tag x%x " 2839 "%d:0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
2879 "Data: x%x x%x x%x x%x x%x\n", 2840 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2880 phba->brd_no, 2841 phba->brd_no, elsiocb->iotag,
2881 elsiocb->iocb.ulpIoTag,
2882 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2842 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2883 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2843 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2884 2844
2885 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc; 2845 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2886 phba->fc_stat.elsXmitACC++; 2846 phba->fc_stat.elsXmitACC++;
2847
2887 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) { 2848 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2888 lpfc_els_free_iocb(phba, elsiocb); 2849 lpfc_els_free_iocb(phba, elsiocb);
2889 } 2850 }
@@ -2923,13 +2884,14 @@ lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2923 lpfc_read_lnk_stat(phba, mbox); 2884 lpfc_read_lnk_stat(phba, mbox);
2924 mbox->context1 = 2885 mbox->context1 =
2925 (void *)((unsigned long)cmdiocb->iocb.ulpContext); 2886 (void *)((unsigned long)cmdiocb->iocb.ulpContext);
2926 mbox->context2 = ndlp; 2887 mbox->context2 = lpfc_nlp_get(ndlp);
2927 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc; 2888 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2928 if (lpfc_sli_issue_mbox (phba, mbox, 2889 if (lpfc_sli_issue_mbox (phba, mbox,
2929 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) { 2890 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) {
2930 /* Mbox completion will send ELS Response */ 2891 /* Mbox completion will send ELS Response */
2931 return 0; 2892 return 0;
2932 } 2893 }
2894 lpfc_nlp_put(ndlp);
2933 mempool_free(mbox, phba->mbox_mem_pool); 2895 mempool_free(mbox, phba->mbox_mem_pool);
2934 } 2896 }
2935 } 2897 }
@@ -2984,10 +2946,9 @@ lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2984 2946
2985 /* Xmit ELS RPL ACC response tag <ulpIoTag> */ 2947 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2986 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, 2948 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2987 "%d:0120 Xmit ELS RPL ACC response tag x%x " 2949 "%d:0120 Xmit ELS RPL ACC response tag x%x xri x%x, "
2988 "Data: x%x x%x x%x x%x x%x\n", 2950 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2989 phba->brd_no, 2951 phba->brd_no, elsiocb->iotag,
2990 elsiocb->iocb.ulpIoTag,
2991 elsiocb->iocb.ulpContext, ndlp->nlp_DID, 2952 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2992 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi); 2953 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2993 2954
@@ -3091,8 +3052,8 @@ lpfc_els_rcv_farp(struct lpfc_hba * phba,
3091 /* Log back into the node before sending the FARP. */ 3052 /* Log back into the node before sending the FARP. */
3092 if (fp->Rflags & FARP_REQUEST_PLOGI) { 3053 if (fp->Rflags & FARP_REQUEST_PLOGI) {
3093 ndlp->nlp_prev_state = ndlp->nlp_state; 3054 ndlp->nlp_prev_state = ndlp->nlp_state;
3094 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 3055 lpfc_nlp_set_state(phba, ndlp,
3095 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST); 3056 NLP_STE_PLOGI_ISSUE);
3096 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); 3057 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
3097 } 3058 }
3098 3059
@@ -3169,14 +3130,15 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3169 */ 3130 */
3170 3131
3171 list_for_each_entry_safe(ndlp, next_ndlp, 3132 list_for_each_entry_safe(ndlp, next_ndlp,
3172 &phba->fc_npr_list, nlp_listp) { 3133 &phba->fc_nodes, nlp_listp) {
3173 3134 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3135 continue;
3174 if (ndlp->nlp_type & NLP_FABRIC) { 3136 if (ndlp->nlp_type & NLP_FABRIC) {
3175 /* 3137 /*
3176 * Clean up old Fabric, Nameserver and 3138 * Clean up old Fabric, Nameserver and
3177 * other NLP_FABRIC logins 3139 * other NLP_FABRIC logins
3178 */ 3140 */
3179 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 3141 lpfc_drop_node(phba, ndlp);
3180 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { 3142 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
3181 /* Fail outstanding I/O now since this 3143 /* Fail outstanding I/O now since this
3182 * device is marked for PLOGI 3144 * device is marked for PLOGI
@@ -3193,20 +3155,22 @@ lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
3193 /* Discovery not needed, 3155 /* Discovery not needed,
3194 * move the nodes to their original state. 3156 * move the nodes to their original state.
3195 */ 3157 */
3196 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list, 3158 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes,
3197 nlp_listp) { 3159 nlp_listp) {
3160 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3161 continue;
3198 3162
3199 switch (ndlp->nlp_prev_state) { 3163 switch (ndlp->nlp_prev_state) {
3200 case NLP_STE_UNMAPPED_NODE: 3164 case NLP_STE_UNMAPPED_NODE:
3201 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 3165 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3202 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; 3166 lpfc_nlp_set_state(phba, ndlp,
3203 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST); 3167 NLP_STE_UNMAPPED_NODE);
3204 break; 3168 break;
3205 3169
3206 case NLP_STE_MAPPED_NODE: 3170 case NLP_STE_MAPPED_NODE:
3207 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 3171 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3208 ndlp->nlp_state = NLP_STE_MAPPED_NODE; 3172 lpfc_nlp_set_state(phba, ndlp,
3209 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST); 3173 NLP_STE_MAPPED_NODE);
3210 break; 3174 break;
3211 3175
3212 default: 3176 default:
@@ -3246,9 +3210,8 @@ lpfc_els_timeout_handler(struct lpfc_hba *phba)
3246 struct lpfc_iocbq *tmp_iocb, *piocb; 3210 struct lpfc_iocbq *tmp_iocb, *piocb;
3247 IOCB_t *cmd = NULL; 3211 IOCB_t *cmd = NULL;
3248 struct lpfc_dmabuf *pcmd; 3212 struct lpfc_dmabuf *pcmd;
3249 struct list_head *dlp;
3250 uint32_t *elscmd; 3213 uint32_t *elscmd;
3251 uint32_t els_command; 3214 uint32_t els_command=0;
3252 uint32_t timeout; 3215 uint32_t timeout;
3253 uint32_t remote_ID; 3216 uint32_t remote_ID;
3254 3217
@@ -3263,17 +3226,20 @@ lpfc_els_timeout_handler(struct lpfc_hba *phba)
3263 timeout = (uint32_t)(phba->fc_ratov << 1); 3226 timeout = (uint32_t)(phba->fc_ratov << 1);
3264 3227
3265 pring = &phba->sli.ring[LPFC_ELS_RING]; 3228 pring = &phba->sli.ring[LPFC_ELS_RING];
3266 dlp = &pring->txcmplq;
3267 3229
3268 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { 3230 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3269 cmd = &piocb->iocb; 3231 cmd = &piocb->iocb;
3270 3232
3271 if (piocb->iocb_flag & LPFC_IO_LIBDFC) { 3233 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) ||
3234 (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN) ||
3235 (piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)) {
3272 continue; 3236 continue;
3273 } 3237 }
3274 pcmd = (struct lpfc_dmabuf *) piocb->context2; 3238 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3275 elscmd = (uint32_t *) (pcmd->virt); 3239 if (pcmd) {
3276 els_command = *elscmd; 3240 elscmd = (uint32_t *) (pcmd->virt);
3241 els_command = *elscmd;
3242 }
3277 3243
3278 if ((els_command == ELS_CMD_FARP) 3244 if ((els_command == ELS_CMD_FARP)
3279 || (els_command == ELS_CMD_FARPR)) { 3245 || (els_command == ELS_CMD_FARPR)) {
@@ -3289,19 +3255,10 @@ lpfc_els_timeout_handler(struct lpfc_hba *phba)
3289 continue; 3255 continue;
3290 } 3256 }
3291 3257
3292 list_del(&piocb->list);
3293 pring->txcmplq_cnt--;
3294
3295 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) { 3258 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
3296 struct lpfc_nodelist *ndlp; 3259 struct lpfc_nodelist *ndlp;
3297 spin_unlock_irq(phba->host->host_lock); 3260 ndlp = __lpfc_findnode_rpi(phba, cmd->ulpContext);
3298 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
3299 spin_lock_irq(phba->host->host_lock);
3300 remote_ID = ndlp->nlp_DID; 3261 remote_ID = ndlp->nlp_DID;
3301 if (cmd->un.elsreq64.bdl.ulpIoTag32) {
3302 lpfc_sli_issue_abort_iotag32(phba,
3303 pring, piocb);
3304 }
3305 } else { 3262 } else {
3306 remote_ID = cmd->un.elsreq64.remoteID; 3263 remote_ID = cmd->un.elsreq64.remoteID;
3307 } 3264 }
@@ -3313,17 +3270,7 @@ lpfc_els_timeout_handler(struct lpfc_hba *phba)
3313 phba->brd_no, els_command, 3270 phba->brd_no, els_command,
3314 remote_ID, cmd->ulpCommand, cmd->ulpIoTag); 3271 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3315 3272
3316 /* 3273 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3317 * The iocb has timed out; abort it.
3318 */
3319 if (piocb->iocb_cmpl) {
3320 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3321 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3322 spin_unlock_irq(phba->host->host_lock);
3323 (piocb->iocb_cmpl) (phba, piocb, piocb);
3324 spin_lock_irq(phba->host->host_lock);
3325 } else
3326 lpfc_sli_release_iocbq(phba, piocb);
3327 } 3274 }
3328 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) 3275 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3329 mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout); 3276 mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout);
@@ -3332,16 +3279,13 @@ lpfc_els_timeout_handler(struct lpfc_hba *phba)
3332} 3279}
3333 3280
3334void 3281void
3335lpfc_els_flush_cmd(struct lpfc_hba * phba) 3282lpfc_els_flush_cmd(struct lpfc_hba *phba)
3336{ 3283{
3337 struct lpfc_sli_ring *pring; 3284 LIST_HEAD(completions);
3285 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3338 struct lpfc_iocbq *tmp_iocb, *piocb; 3286 struct lpfc_iocbq *tmp_iocb, *piocb;
3339 IOCB_t *cmd = NULL; 3287 IOCB_t *cmd = NULL;
3340 struct lpfc_dmabuf *pcmd;
3341 uint32_t *elscmd;
3342 uint32_t els_command;
3343 3288
3344 pring = &phba->sli.ring[LPFC_ELS_RING];
3345 spin_lock_irq(phba->host->host_lock); 3289 spin_lock_irq(phba->host->host_lock);
3346 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) { 3290 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3347 cmd = &piocb->iocb; 3291 cmd = &piocb->iocb;
@@ -3351,29 +3295,15 @@ lpfc_els_flush_cmd(struct lpfc_hba * phba)
3351 } 3295 }
3352 3296
3353 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */ 3297 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3354 if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) || 3298 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3355 (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) || 3299 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3356 (cmd->ulpCommand == CMD_CLOSE_XRI_CN) || 3300 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3357 (cmd->ulpCommand == CMD_ABORT_XRI_CN)) { 3301 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3358 continue; 3302 continue;
3359 }
3360 3303
3361 pcmd = (struct lpfc_dmabuf *) piocb->context2; 3304 list_move_tail(&piocb->list, &completions);
3362 elscmd = (uint32_t *) (pcmd->virt); 3305 pring->txq_cnt--;
3363 els_command = *elscmd;
3364 3306
3365 list_del(&piocb->list);
3366 pring->txcmplq_cnt--;
3367
3368 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3369 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3370
3371 if (piocb->iocb_cmpl) {
3372 spin_unlock_irq(phba->host->host_lock);
3373 (piocb->iocb_cmpl) (phba, piocb, piocb);
3374 spin_lock_irq(phba->host->host_lock);
3375 } else
3376 lpfc_sli_release_iocbq(phba, piocb);
3377 } 3307 }
3378 3308
3379 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) { 3309 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
@@ -3382,24 +3312,24 @@ lpfc_els_flush_cmd(struct lpfc_hba * phba)
3382 if (piocb->iocb_flag & LPFC_IO_LIBDFC) { 3312 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3383 continue; 3313 continue;
3384 } 3314 }
3385 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3386 elscmd = (uint32_t *) (pcmd->virt);
3387 els_command = *elscmd;
3388 3315
3389 list_del(&piocb->list); 3316 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3390 pring->txcmplq_cnt--; 3317 }
3318 spin_unlock_irq(phba->host->host_lock);
3391 3319
3392 cmd->ulpStatus = IOSTAT_LOCAL_REJECT; 3320 while(!list_empty(&completions)) {
3393 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; 3321 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3322 cmd = &piocb->iocb;
3323 list_del(&piocb->list);
3394 3324
3395 if (piocb->iocb_cmpl) { 3325 if (piocb->iocb_cmpl) {
3396 spin_unlock_irq(phba->host->host_lock); 3326 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3327 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3397 (piocb->iocb_cmpl) (phba, piocb, piocb); 3328 (piocb->iocb_cmpl) (phba, piocb, piocb);
3398 spin_lock_irq(phba->host->host_lock);
3399 } else 3329 } else
3400 lpfc_sli_release_iocbq(phba, piocb); 3330 lpfc_sli_release_iocbq(phba, piocb);
3401 } 3331 }
3402 spin_unlock_irq(phba->host->host_lock); 3332
3403 return; 3333 return;
3404} 3334}
3405 3335
@@ -3468,7 +3398,7 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3468 } 3398 }
3469 3399
3470 did = icmd->un.rcvels.remoteID; 3400 did = icmd->un.rcvels.remoteID;
3471 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did); 3401 ndlp = lpfc_findnode_did(phba, did);
3472 if (!ndlp) { 3402 if (!ndlp) {
3473 /* Cannot find existing Fabric ndlp, so allocate a new one */ 3403 /* Cannot find existing Fabric ndlp, so allocate a new one */
3474 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL); 3404 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
@@ -3484,12 +3414,13 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3484 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) { 3414 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3485 ndlp->nlp_type |= NLP_FABRIC; 3415 ndlp->nlp_type |= NLP_FABRIC;
3486 } 3416 }
3487 ndlp->nlp_state = NLP_STE_UNUSED_NODE; 3417 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
3488 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
3489 } 3418 }
3490 3419
3491 phba->fc_stat.elsRcvFrame++; 3420 phba->fc_stat.elsRcvFrame++;
3492 elsiocb->context1 = ndlp; 3421 if (elsiocb->context1)
3422 lpfc_nlp_put(elsiocb->context1);
3423 elsiocb->context1 = lpfc_nlp_get(ndlp);
3493 elsiocb->context2 = mp; 3424 elsiocb->context2 = mp;
3494 3425
3495 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) { 3426 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
@@ -3513,9 +3444,8 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3513 case ELS_CMD_FLOGI: 3444 case ELS_CMD_FLOGI:
3514 phba->fc_stat.elsRcvFLOGI++; 3445 phba->fc_stat.elsRcvFLOGI++;
3515 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode); 3446 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
3516 if (newnode) { 3447 if (newnode)
3517 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 3448 lpfc_drop_node(phba, ndlp);
3518 }
3519 break; 3449 break;
3520 case ELS_CMD_LOGO: 3450 case ELS_CMD_LOGO:
3521 phba->fc_stat.elsRcvLOGO++; 3451 phba->fc_stat.elsRcvLOGO++;
@@ -3536,9 +3466,8 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3536 case ELS_CMD_RSCN: 3466 case ELS_CMD_RSCN:
3537 phba->fc_stat.elsRcvRSCN++; 3467 phba->fc_stat.elsRcvRSCN++;
3538 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode); 3468 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
3539 if (newnode) { 3469 if (newnode)
3540 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 3470 lpfc_drop_node(phba, ndlp);
3541 }
3542 break; 3471 break;
3543 case ELS_CMD_ADISC: 3472 case ELS_CMD_ADISC:
3544 phba->fc_stat.elsRcvADISC++; 3473 phba->fc_stat.elsRcvADISC++;
@@ -3579,30 +3508,26 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3579 case ELS_CMD_LIRR: 3508 case ELS_CMD_LIRR:
3580 phba->fc_stat.elsRcvLIRR++; 3509 phba->fc_stat.elsRcvLIRR++;
3581 lpfc_els_rcv_lirr(phba, elsiocb, ndlp); 3510 lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
3582 if (newnode) { 3511 if (newnode)
3583 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 3512 lpfc_drop_node(phba, ndlp);
3584 }
3585 break; 3513 break;
3586 case ELS_CMD_RPS: 3514 case ELS_CMD_RPS:
3587 phba->fc_stat.elsRcvRPS++; 3515 phba->fc_stat.elsRcvRPS++;
3588 lpfc_els_rcv_rps(phba, elsiocb, ndlp); 3516 lpfc_els_rcv_rps(phba, elsiocb, ndlp);
3589 if (newnode) { 3517 if (newnode)
3590 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 3518 lpfc_drop_node(phba, ndlp);
3591 }
3592 break; 3519 break;
3593 case ELS_CMD_RPL: 3520 case ELS_CMD_RPL:
3594 phba->fc_stat.elsRcvRPL++; 3521 phba->fc_stat.elsRcvRPL++;
3595 lpfc_els_rcv_rpl(phba, elsiocb, ndlp); 3522 lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
3596 if (newnode) { 3523 if (newnode)
3597 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 3524 lpfc_drop_node(phba, ndlp);
3598 }
3599 break; 3525 break;
3600 case ELS_CMD_RNID: 3526 case ELS_CMD_RNID:
3601 phba->fc_stat.elsRcvRNID++; 3527 phba->fc_stat.elsRcvRNID++;
3602 lpfc_els_rcv_rnid(phba, elsiocb, ndlp); 3528 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
3603 if (newnode) { 3529 if (newnode)
3604 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 3530 lpfc_drop_node(phba, ndlp);
3605 }
3606 break; 3531 break;
3607 default: 3532 default:
3608 /* Unsupported ELS command, reject */ 3533 /* Unsupported ELS command, reject */
@@ -3612,9 +3537,8 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3612 lpfc_printf_log(phba, KERN_ERR, LOG_ELS, 3537 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3613 "%d:0115 Unknown ELS command x%x received from " 3538 "%d:0115 Unknown ELS command x%x received from "
3614 "NPORT x%x\n", phba->brd_no, cmd, did); 3539 "NPORT x%x\n", phba->brd_no, cmd, did);
3615 if (newnode) { 3540 if (newnode)
3616 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 3541 lpfc_drop_node(phba, ndlp);
3617 }
3618 break; 3542 break;
3619 } 3543 }
3620 3544
@@ -3627,6 +3551,8 @@ lpfc_els_unsol_event(struct lpfc_hba * phba,
3627 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp); 3551 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
3628 } 3552 }
3629 3553
3554 lpfc_nlp_put(elsiocb->context1);
3555 elsiocb->context1 = NULL;
3630 if (elsiocb->context2) { 3556 if (elsiocb->context2) {
3631 lpfc_mbuf_free(phba, mp->virt, mp->phys); 3557 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3632 kfree(mp); 3558 kfree(mp);
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index c39564e85e94..61caa8d379e2 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -109,6 +109,9 @@ lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
109 return; 109 return;
110 } 110 }
111 111
112 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
113 return;
114
112 name = (uint8_t *)&ndlp->nlp_portname; 115 name = (uint8_t *)&ndlp->nlp_portname;
113 phba = ndlp->nlp_phba; 116 phba = ndlp->nlp_phba;
114 117
@@ -147,11 +150,17 @@ lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
147 ndlp->nlp_state, ndlp->nlp_rpi); 150 ndlp->nlp_state, ndlp->nlp_rpi);
148 } 151 }
149 152
150 ndlp->rport = NULL; 153 if (!(phba->fc_flag & FC_UNLOADING) &&
151 rdata->pnode = NULL; 154 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
152 155 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
153 if (!(phba->fc_flag & FC_UNLOADING)) 156 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
154 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM); 157 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
158 else {
159 rdata->pnode = NULL;
160 ndlp->rport = NULL;
161 lpfc_nlp_put(ndlp);
162 put_device(&rport->dev);
163 }
155 164
156 return; 165 return;
157} 166}
@@ -182,29 +191,35 @@ lpfc_work_list_done(struct lpfc_hba * phba)
182 *(int *)(evtp->evt_arg1) = 0; 191 *(int *)(evtp->evt_arg1) = 0;
183 complete((struct completion *)(evtp->evt_arg2)); 192 complete((struct completion *)(evtp->evt_arg2));
184 break; 193 break;
185 case LPFC_EVT_OFFLINE: 194 case LPFC_EVT_OFFLINE_PREP:
186 if (phba->hba_state >= LPFC_LINK_DOWN) 195 if (phba->hba_state >= LPFC_LINK_DOWN)
187 lpfc_offline(phba); 196 lpfc_offline_prep(phba);
197 *(int *)(evtp->evt_arg1) = 0;
198 complete((struct completion *)(evtp->evt_arg2));
199 break;
200 case LPFC_EVT_OFFLINE:
201 lpfc_offline(phba);
188 lpfc_sli_brdrestart(phba); 202 lpfc_sli_brdrestart(phba);
189 *(int *)(evtp->evt_arg1) = 203 *(int *)(evtp->evt_arg1) =
190 lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY); 204 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
205 lpfc_unblock_mgmt_io(phba);
191 complete((struct completion *)(evtp->evt_arg2)); 206 complete((struct completion *)(evtp->evt_arg2));
192 break; 207 break;
193 case LPFC_EVT_WARM_START: 208 case LPFC_EVT_WARM_START:
194 if (phba->hba_state >= LPFC_LINK_DOWN) 209 lpfc_offline(phba);
195 lpfc_offline(phba);
196 lpfc_reset_barrier(phba); 210 lpfc_reset_barrier(phba);
197 lpfc_sli_brdreset(phba); 211 lpfc_sli_brdreset(phba);
198 lpfc_hba_down_post(phba); 212 lpfc_hba_down_post(phba);
199 *(int *)(evtp->evt_arg1) = 213 *(int *)(evtp->evt_arg1) =
200 lpfc_sli_brdready(phba, HS_MBRDY); 214 lpfc_sli_brdready(phba, HS_MBRDY);
215 lpfc_unblock_mgmt_io(phba);
201 complete((struct completion *)(evtp->evt_arg2)); 216 complete((struct completion *)(evtp->evt_arg2));
202 break; 217 break;
203 case LPFC_EVT_KILL: 218 case LPFC_EVT_KILL:
204 if (phba->hba_state >= LPFC_LINK_DOWN) 219 lpfc_offline(phba);
205 lpfc_offline(phba);
206 *(int *)(evtp->evt_arg1) 220 *(int *)(evtp->evt_arg1)
207 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba); 221 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba);
222 lpfc_unblock_mgmt_io(phba);
208 complete((struct completion *)(evtp->evt_arg2)); 223 complete((struct completion *)(evtp->evt_arg2));
209 break; 224 break;
210 } 225 }
@@ -359,13 +374,12 @@ lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
359} 374}
360 375
361int 376int
362lpfc_linkdown(struct lpfc_hba * phba) 377lpfc_linkdown(struct lpfc_hba *phba)
363{ 378{
364 struct lpfc_sli *psli; 379 struct lpfc_sli *psli;
365 struct lpfc_nodelist *ndlp, *next_ndlp; 380 struct lpfc_nodelist *ndlp, *next_ndlp;
366 struct list_head *listp, *node_list[7]; 381 LPFC_MBOXQ_t *mb;
367 LPFC_MBOXQ_t *mb; 382 int rc;
368 int rc, i;
369 383
370 psli = &phba->sli; 384 psli = &phba->sli;
371 /* sysfs or selective reset may call this routine to clean up */ 385 /* sysfs or selective reset may call this routine to clean up */
@@ -397,31 +411,16 @@ lpfc_linkdown(struct lpfc_hba * phba)
397 /* Cleanup any outstanding ELS commands */ 411 /* Cleanup any outstanding ELS commands */
398 lpfc_els_flush_cmd(phba); 412 lpfc_els_flush_cmd(phba);
399 413
400 /* Issue a LINK DOWN event to all nodes */ 414 /*
401 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */ 415 * Issue a LINK DOWN event to all nodes.
402 node_list[1] = &phba->fc_nlpmap_list; 416 */
403 node_list[2] = &phba->fc_nlpunmap_list; 417 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) {
404 node_list[3] = &phba->fc_prli_list; 418 /* free any ndlp's on unused list */
405 node_list[4] = &phba->fc_reglogin_list; 419 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
406 node_list[5] = &phba->fc_adisc_list; 420 lpfc_drop_node(phba, ndlp);
407 node_list[6] = &phba->fc_plogi_list; 421 else /* otherwise, force node recovery. */
408 for (i = 0; i < 7; i++) {
409 listp = node_list[i];
410 if (list_empty(listp))
411 continue;
412
413 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
414
415 rc = lpfc_disc_state_machine(phba, ndlp, NULL, 422 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
416 NLP_EVT_DEVICE_RECOVERY); 423 NLP_EVT_DEVICE_RECOVERY);
417
418 }
419 }
420
421 /* free any ndlp's on unused list */
422 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
423 nlp_listp) {
424 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
425 } 424 }
426 425
427 /* Setup myDID for link up if we are in pt2pt mode */ 426 /* Setup myDID for link up if we are in pt2pt mode */
@@ -452,11 +451,9 @@ lpfc_linkdown(struct lpfc_hba * phba)
452} 451}
453 452
454static int 453static int
455lpfc_linkup(struct lpfc_hba * phba) 454lpfc_linkup(struct lpfc_hba *phba)
456{ 455{
457 struct lpfc_nodelist *ndlp, *next_ndlp; 456 struct lpfc_nodelist *ndlp, *next_ndlp;
458 struct list_head *listp, *node_list[7];
459 int i;
460 457
461 fc_host_post_event(phba->host, fc_get_event_number(), 458 fc_host_post_event(phba->host, fc_get_event_number(),
462 FCH_EVT_LINKUP, 0); 459 FCH_EVT_LINKUP, 0);
@@ -470,29 +467,20 @@ lpfc_linkup(struct lpfc_hba * phba)
470 spin_unlock_irq(phba->host->host_lock); 467 spin_unlock_irq(phba->host->host_lock);
471 468
472 469
473 node_list[0] = &phba->fc_plogi_list; 470 if (phba->fc_flag & FC_LBIT) {
474 node_list[1] = &phba->fc_adisc_list; 471 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
475 node_list[2] = &phba->fc_reglogin_list; 472 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE) {
476 node_list[3] = &phba->fc_prli_list;
477 node_list[4] = &phba->fc_nlpunmap_list;
478 node_list[5] = &phba->fc_nlpmap_list;
479 node_list[6] = &phba->fc_npr_list;
480 for (i = 0; i < 7; i++) {
481 listp = node_list[i];
482 if (list_empty(listp))
483 continue;
484
485 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
486 if (phba->fc_flag & FC_LBIT) {
487 if (ndlp->nlp_type & NLP_FABRIC) { 473 if (ndlp->nlp_type & NLP_FABRIC) {
488 /* On Linkup its safe to clean up the 474 /*
475 * On Linkup its safe to clean up the
489 * ndlp from Fabric connections. 476 * ndlp from Fabric connections.
490 */ 477 */
491 lpfc_nlp_list(phba, ndlp, 478 lpfc_nlp_set_state(phba, ndlp,
492 NLP_UNUSED_LIST); 479 NLP_STE_UNUSED_NODE);
493 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { 480 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
494 /* Fail outstanding IO now since device 481 /*
495 * is marked for PLOGI. 482 * Fail outstanding IO now since
483 * device is marked for PLOGI.
496 */ 484 */
497 lpfc_unreg_rpi(phba, ndlp); 485 lpfc_unreg_rpi(phba, ndlp);
498 } 486 }
@@ -501,9 +489,10 @@ lpfc_linkup(struct lpfc_hba * phba)
501 } 489 }
502 490
503 /* free any ndlp's on unused list */ 491 /* free any ndlp's on unused list */
504 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list, 492 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes,
505 nlp_listp) { 493 nlp_listp) {
506 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 494 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
495 lpfc_drop_node(phba, ndlp);
507 } 496 }
508 497
509 return 0; 498 return 0;
@@ -734,6 +723,9 @@ lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
734 case LA_4GHZ_LINK: 723 case LA_4GHZ_LINK:
735 phba->fc_linkspeed = LA_4GHZ_LINK; 724 phba->fc_linkspeed = LA_4GHZ_LINK;
736 break; 725 break;
726 case LA_8GHZ_LINK:
727 phba->fc_linkspeed = LA_8GHZ_LINK;
728 break;
737 default: 729 default:
738 phba->fc_linkspeed = LA_UNKNW_LINK; 730 phba->fc_linkspeed = LA_UNKNW_LINK;
739 break; 731 break;
@@ -889,12 +881,21 @@ lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
889 881
890 if (la->attType == AT_LINK_UP) { 882 if (la->attType == AT_LINK_UP) {
891 phba->fc_stat.LinkUp++; 883 phba->fc_stat.LinkUp++;
892 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT, 884 if (phba->fc_flag & FC_LOOPBACK_MODE) {
885 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
886 "%d:1306 Link Up Event in loop back mode "
887 "x%x received Data: x%x x%x x%x x%x\n",
888 phba->brd_no, la->eventTag, phba->fc_eventTag,
889 la->granted_AL_PA, la->UlnkSpeed,
890 phba->alpa_map[0]);
891 } else {
892 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
893 "%d:1303 Link Up Event x%x received " 893 "%d:1303 Link Up Event x%x received "
894 "Data: x%x x%x x%x x%x\n", 894 "Data: x%x x%x x%x x%x\n",
895 phba->brd_no, la->eventTag, phba->fc_eventTag, 895 phba->brd_no, la->eventTag, phba->fc_eventTag,
896 la->granted_AL_PA, la->UlnkSpeed, 896 la->granted_AL_PA, la->UlnkSpeed,
897 phba->alpa_map[0]); 897 phba->alpa_map[0]);
898 }
898 lpfc_mbx_process_link_up(phba, la); 899 lpfc_mbx_process_link_up(phba, la);
899 } else { 900 } else {
900 phba->fc_stat.LinkDown++; 901 phba->fc_stat.LinkDown++;
@@ -940,6 +941,7 @@ lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
940 lpfc_mbuf_free(phba, mp->virt, mp->phys); 941 lpfc_mbuf_free(phba, mp->virt, mp->phys);
941 kfree(mp); 942 kfree(mp);
942 mempool_free( pmb, phba->mbox_mem_pool); 943 mempool_free( pmb, phba->mbox_mem_pool);
944 lpfc_nlp_put(ndlp);
943 945
944 return; 946 return;
945} 947}
@@ -966,11 +968,14 @@ lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
966 ndlp = (struct lpfc_nodelist *) pmb->context2; 968 ndlp = (struct lpfc_nodelist *) pmb->context2;
967 mp = (struct lpfc_dmabuf *) (pmb->context1); 969 mp = (struct lpfc_dmabuf *) (pmb->context1);
968 970
971 pmb->context1 = NULL;
972 pmb->context2 = NULL;
973
969 if (mb->mbxStatus) { 974 if (mb->mbxStatus) {
970 lpfc_mbuf_free(phba, mp->virt, mp->phys); 975 lpfc_mbuf_free(phba, mp->virt, mp->phys);
971 kfree(mp); 976 kfree(mp);
972 mempool_free( pmb, phba->mbox_mem_pool); 977 mempool_free(pmb, phba->mbox_mem_pool);
973 mempool_free( ndlp, phba->nlp_mem_pool); 978 lpfc_nlp_put(ndlp);
974 979
975 /* FLOGI failed, so just use loop map to make discovery list */ 980 /* FLOGI failed, so just use loop map to make discovery list */
976 lpfc_disc_list_loopmap(phba); 981 lpfc_disc_list_loopmap(phba);
@@ -980,12 +985,11 @@ lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
980 return; 985 return;
981 } 986 }
982 987
983 pmb->context1 = NULL;
984
985 ndlp->nlp_rpi = mb->un.varWords[0]; 988 ndlp->nlp_rpi = mb->un.varWords[0];
986 ndlp->nlp_type |= NLP_FABRIC; 989 ndlp->nlp_type |= NLP_FABRIC;
987 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; 990 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
988 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST); 991
992 lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
989 993
990 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) { 994 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
991 /* This NPort has been assigned an NPort_ID by the fabric as a 995 /* This NPort has been assigned an NPort_ID by the fabric as a
@@ -996,7 +1000,7 @@ lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
996 */ 1000 */
997 lpfc_issue_els_scr(phba, SCR_DID, 0); 1001 lpfc_issue_els_scr(phba, SCR_DID, 0);
998 1002
999 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID); 1003 ndlp = lpfc_findnode_did(phba, NameServer_DID);
1000 if (!ndlp) { 1004 if (!ndlp) {
1001 /* Allocate a new node instance. If the pool is empty, 1005 /* Allocate a new node instance. If the pool is empty,
1002 * start the discovery process and skip the Nameserver 1006 * start the discovery process and skip the Nameserver
@@ -1008,15 +1012,14 @@ lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1008 lpfc_disc_start(phba); 1012 lpfc_disc_start(phba);
1009 lpfc_mbuf_free(phba, mp->virt, mp->phys); 1013 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1010 kfree(mp); 1014 kfree(mp);
1011 mempool_free( pmb, phba->mbox_mem_pool); 1015 mempool_free(pmb, phba->mbox_mem_pool);
1012 return; 1016 return;
1013 } else { 1017 } else {
1014 lpfc_nlp_init(phba, ndlp, NameServer_DID); 1018 lpfc_nlp_init(phba, ndlp, NameServer_DID);
1015 ndlp->nlp_type |= NLP_FABRIC; 1019 ndlp->nlp_type |= NLP_FABRIC;
1016 } 1020 }
1017 } 1021 }
1018 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 1022 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
1019 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1020 lpfc_issue_els_plogi(phba, NameServer_DID, 0); 1023 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
1021 if (phba->cfg_fdmi_on) { 1024 if (phba->cfg_fdmi_on) {
1022 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool, 1025 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
@@ -1032,7 +1035,7 @@ lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1032 1035
1033 lpfc_mbuf_free(phba, mp->virt, mp->phys); 1036 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1034 kfree(mp); 1037 kfree(mp);
1035 mempool_free( pmb, phba->mbox_mem_pool); 1038 mempool_free(pmb, phba->mbox_mem_pool);
1036 return; 1039 return;
1037} 1040}
1038 1041
@@ -1057,10 +1060,11 @@ lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1057 mp = (struct lpfc_dmabuf *) (pmb->context1); 1060 mp = (struct lpfc_dmabuf *) (pmb->context1);
1058 1061
1059 if (mb->mbxStatus) { 1062 if (mb->mbxStatus) {
1063 lpfc_nlp_put(ndlp);
1060 lpfc_mbuf_free(phba, mp->virt, mp->phys); 1064 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1061 kfree(mp); 1065 kfree(mp);
1062 mempool_free( pmb, phba->mbox_mem_pool); 1066 mempool_free(pmb, phba->mbox_mem_pool);
1063 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1067 lpfc_drop_node(phba, ndlp);
1064 1068
1065 /* RegLogin failed, so just use loop map to make discovery 1069 /* RegLogin failed, so just use loop map to make discovery
1066 list */ 1070 list */
@@ -1075,8 +1079,7 @@ lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1075 1079
1076 ndlp->nlp_rpi = mb->un.varWords[0]; 1080 ndlp->nlp_rpi = mb->un.varWords[0];
1077 ndlp->nlp_type |= NLP_FABRIC; 1081 ndlp->nlp_type |= NLP_FABRIC;
1078 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; 1082 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1079 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1080 1083
1081 if (phba->hba_state < LPFC_HBA_READY) { 1084 if (phba->hba_state < LPFC_HBA_READY) {
1082 /* Link up discovery requires Fabrib registration. */ 1085 /* Link up discovery requires Fabrib registration. */
@@ -1093,6 +1096,7 @@ lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1093 lpfc_disc_start(phba); 1096 lpfc_disc_start(phba);
1094 } 1097 }
1095 1098
1099 lpfc_nlp_put(ndlp);
1096 lpfc_mbuf_free(phba, mp->virt, mp->phys); 1100 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1097 kfree(mp); 1101 kfree(mp);
1098 mempool_free( pmb, phba->mbox_mem_pool); 1102 mempool_free( pmb, phba->mbox_mem_pool);
@@ -1101,8 +1105,7 @@ lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1101} 1105}
1102 1106
1103static void 1107static void
1104lpfc_register_remote_port(struct lpfc_hba * phba, 1108lpfc_register_remote_port(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1105 struct lpfc_nodelist * ndlp)
1106{ 1109{
1107 struct fc_rport *rport; 1110 struct fc_rport *rport;
1108 struct lpfc_rport_data *rdata; 1111 struct lpfc_rport_data *rdata;
@@ -1114,8 +1117,19 @@ lpfc_register_remote_port(struct lpfc_hba * phba,
1114 rport_ids.port_id = ndlp->nlp_DID; 1117 rport_ids.port_id = ndlp->nlp_DID;
1115 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; 1118 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
1116 1119
1120 /*
1121 * We leave our node pointer in rport->dd_data when we unregister a
1122 * FCP target port. But fc_remote_port_add zeros the space to which
1123 * rport->dd_data points. So, if we're reusing a previously
1124 * registered port, drop the reference that we took the last time we
1125 * registered the port.
1126 */
1127 if (ndlp->rport && ndlp->rport->dd_data &&
1128 *(struct lpfc_rport_data **) ndlp->rport->dd_data) {
1129 lpfc_nlp_put(ndlp);
1130 }
1117 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids); 1131 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1118 if (!rport) { 1132 if (!rport || !get_device(&rport->dev)) {
1119 dev_printk(KERN_WARNING, &phba->pcidev->dev, 1133 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1120 "Warning: fc_remote_port_add failed\n"); 1134 "Warning: fc_remote_port_add failed\n");
1121 return; 1135 return;
@@ -1125,7 +1139,7 @@ lpfc_register_remote_port(struct lpfc_hba * phba,
1125 rport->maxframe_size = ndlp->nlp_maxframe; 1139 rport->maxframe_size = ndlp->nlp_maxframe;
1126 rport->supported_classes = ndlp->nlp_class_sup; 1140 rport->supported_classes = ndlp->nlp_class_sup;
1127 rdata = rport->dd_data; 1141 rdata = rport->dd_data;
1128 rdata->pnode = ndlp; 1142 rdata->pnode = lpfc_nlp_get(ndlp);
1129 1143
1130 if (ndlp->nlp_type & NLP_FCP_TARGET) 1144 if (ndlp->nlp_type & NLP_FCP_TARGET)
1131 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; 1145 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
@@ -1145,8 +1159,7 @@ lpfc_register_remote_port(struct lpfc_hba * phba,
1145} 1159}
1146 1160
1147static void 1161static void
1148lpfc_unregister_remote_port(struct lpfc_hba * phba, 1162lpfc_unregister_remote_port(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1149 struct lpfc_nodelist * ndlp)
1150{ 1163{
1151 struct fc_rport *rport = ndlp->rport; 1164 struct fc_rport *rport = ndlp->rport;
1152 struct lpfc_rport_data *rdata = rport->dd_data; 1165 struct lpfc_rport_data *rdata = rport->dd_data;
@@ -1154,6 +1167,8 @@ lpfc_unregister_remote_port(struct lpfc_hba * phba,
1154 if (rport->scsi_target_id == -1) { 1167 if (rport->scsi_target_id == -1) {
1155 ndlp->rport = NULL; 1168 ndlp->rport = NULL;
1156 rdata->pnode = NULL; 1169 rdata->pnode = NULL;
1170 lpfc_nlp_put(ndlp);
1171 put_device(&rport->dev);
1157 } 1172 }
1158 1173
1159 fc_remote_port_delete(rport); 1174 fc_remote_port_delete(rport);
@@ -1161,178 +1176,70 @@ lpfc_unregister_remote_port(struct lpfc_hba * phba,
1161 return; 1176 return;
1162} 1177}
1163 1178
1164int 1179static void
1165lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list) 1180lpfc_nlp_counters(struct lpfc_hba *phba, int state, int count)
1166{ 1181{
1167 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1168 struct lpfc_sli *psli;
1169
1170 psli = &phba->sli;
1171 /* Sanity check to ensure we are not moving to / from the same list */
1172 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
1173 if (list != NLP_NO_LIST)
1174 return 0;
1175
1176 spin_lock_irq(phba->host->host_lock); 1182 spin_lock_irq(phba->host->host_lock);
1177 switch (nlp->nlp_flag & NLP_LIST_MASK) { 1183 switch (state) {
1178 case NLP_NO_LIST: /* Not on any list */ 1184 case NLP_STE_UNUSED_NODE:
1185 phba->fc_unused_cnt += count;
1179 break; 1186 break;
1180 case NLP_UNUSED_LIST: 1187 case NLP_STE_PLOGI_ISSUE:
1181 phba->fc_unused_cnt--; 1188 phba->fc_plogi_cnt += count;
1182 list_del(&nlp->nlp_listp);
1183 break; 1189 break;
1184 case NLP_PLOGI_LIST: 1190 case NLP_STE_ADISC_ISSUE:
1185 phba->fc_plogi_cnt--; 1191 phba->fc_adisc_cnt += count;
1186 list_del(&nlp->nlp_listp);
1187 break; 1192 break;
1188 case NLP_ADISC_LIST: 1193 case NLP_STE_REG_LOGIN_ISSUE:
1189 phba->fc_adisc_cnt--; 1194 phba->fc_reglogin_cnt += count;
1190 list_del(&nlp->nlp_listp);
1191 break; 1195 break;
1192 case NLP_REGLOGIN_LIST: 1196 case NLP_STE_PRLI_ISSUE:
1193 phba->fc_reglogin_cnt--; 1197 phba->fc_prli_cnt += count;
1194 list_del(&nlp->nlp_listp);
1195 break; 1198 break;
1196 case NLP_PRLI_LIST: 1199 case NLP_STE_UNMAPPED_NODE:
1197 phba->fc_prli_cnt--; 1200 phba->fc_unmap_cnt += count;
1198 list_del(&nlp->nlp_listp);
1199 break; 1201 break;
1200 case NLP_UNMAPPED_LIST: 1202 case NLP_STE_MAPPED_NODE:
1201 phba->fc_unmap_cnt--; 1203 phba->fc_map_cnt += count;
1202 list_del(&nlp->nlp_listp);
1203 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1204 nlp->nlp_type &= ~NLP_FC_NODE;
1205 phba->nport_event_cnt++;
1206 if (nlp->rport)
1207 rport_del = unmapped;
1208 break; 1204 break;
1209 case NLP_MAPPED_LIST: 1205 case NLP_STE_NPR_NODE:
1210 phba->fc_map_cnt--; 1206 phba->fc_npr_cnt += count;
1211 list_del(&nlp->nlp_listp);
1212 phba->nport_event_cnt++;
1213 if (nlp->rport)
1214 rport_del = mapped;
1215 break;
1216 case NLP_NPR_LIST:
1217 phba->fc_npr_cnt--;
1218 list_del(&nlp->nlp_listp);
1219 /* Stop delay tmo if taking node off NPR list */
1220 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1221 (list != NLP_NPR_LIST)) {
1222 spin_unlock_irq(phba->host->host_lock);
1223 lpfc_cancel_retry_delay_tmo(phba, nlp);
1224 spin_lock_irq(phba->host->host_lock);
1225 }
1226 break; 1207 break;
1227 } 1208 }
1209 spin_unlock_irq(phba->host->host_lock);
1210}
1228 1211
1229 nlp->nlp_flag &= ~NLP_LIST_MASK; 1212static void
1230 1213lpfc_nlp_state_cleanup(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
1231 /* Add NPort <did> to <num> list */ 1214 int old_state, int new_state)
1232 lpfc_printf_log(phba, 1215{
1233 KERN_INFO, 1216 if (new_state == NLP_STE_UNMAPPED_NODE) {
1234 LOG_NODE, 1217 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1235 "%d:0904 Add NPort x%x to %d list Data: x%x\n", 1218 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1236 phba->brd_no, 1219 ndlp->nlp_type |= NLP_FC_NODE;
1237 nlp->nlp_DID, list, nlp->nlp_flag); 1220 }
1238 1221 if (new_state == NLP_STE_MAPPED_NODE)
1239 switch (list) { 1222 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1240 case NLP_NO_LIST: /* No list, just remove it */ 1223 if (new_state == NLP_STE_NPR_NODE)
1241 spin_unlock_irq(phba->host->host_lock); 1224 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
1242 lpfc_nlp_remove(phba, nlp); 1225
1243 spin_lock_irq(phba->host->host_lock); 1226 /* Transport interface */
1244 /* as node removed - stop further transport calls */ 1227 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1245 rport_del = none; 1228 old_state == NLP_STE_UNMAPPED_NODE)) {
1246 break;
1247 case NLP_UNUSED_LIST:
1248 nlp->nlp_flag |= list;
1249 /* Put it at the end of the unused list */
1250 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1251 phba->fc_unused_cnt++;
1252 break;
1253 case NLP_PLOGI_LIST:
1254 nlp->nlp_flag |= list;
1255 /* Put it at the end of the plogi list */
1256 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1257 phba->fc_plogi_cnt++;
1258 break;
1259 case NLP_ADISC_LIST:
1260 nlp->nlp_flag |= list;
1261 /* Put it at the end of the adisc list */
1262 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1263 phba->fc_adisc_cnt++;
1264 break;
1265 case NLP_REGLOGIN_LIST:
1266 nlp->nlp_flag |= list;
1267 /* Put it at the end of the reglogin list */
1268 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1269 phba->fc_reglogin_cnt++;
1270 break;
1271 case NLP_PRLI_LIST:
1272 nlp->nlp_flag |= list;
1273 /* Put it at the end of the prli list */
1274 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1275 phba->fc_prli_cnt++;
1276 break;
1277 case NLP_UNMAPPED_LIST:
1278 rport_add = unmapped;
1279 /* ensure all vestiges of "mapped" significance are gone */
1280 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1281 nlp->nlp_flag |= list;
1282 /* Put it at the end of the unmap list */
1283 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1284 phba->fc_unmap_cnt++;
1285 phba->nport_event_cnt++;
1286 nlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1287 nlp->nlp_type |= NLP_FC_NODE;
1288 break;
1289 case NLP_MAPPED_LIST:
1290 rport_add = mapped;
1291 nlp->nlp_flag |= list;
1292 /* Put it at the end of the map list */
1293 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1294 phba->fc_map_cnt++;
1295 phba->nport_event_cnt++; 1229 phba->nport_event_cnt++;
1296 nlp->nlp_flag &= ~NLP_NODEV_REMOVE; 1230 lpfc_unregister_remote_port(phba, ndlp);
1297 break;
1298 case NLP_NPR_LIST:
1299 nlp->nlp_flag |= list;
1300 /* Put it at the end of the npr list */
1301 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1302 phba->fc_npr_cnt++;
1303
1304 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
1305 break;
1306 case NLP_JUST_DQ:
1307 break;
1308 } 1231 }
1309 1232
1310 spin_unlock_irq(phba->host->host_lock); 1233 if (new_state == NLP_STE_MAPPED_NODE ||
1311 1234 new_state == NLP_STE_UNMAPPED_NODE) {
1312 /* 1235 phba->nport_event_cnt++;
1313 * We make all the calls into the transport after we have
1314 * moved the node between lists. This so that we don't
1315 * release the lock while in-between lists.
1316 */
1317
1318 /* Don't upcall midlayer if we're unloading */
1319 if (!(phba->fc_flag & FC_UNLOADING)) {
1320 /*
1321 * We revalidate the rport pointer as the "add" function
1322 * may have removed the remote port.
1323 */
1324 if ((rport_del != none) && nlp->rport)
1325 lpfc_unregister_remote_port(phba, nlp);
1326
1327 if (rport_add != none) {
1328 /* 1236 /*
1329 * Tell the fc transport about the port, if we haven't 1237 * Tell the fc transport about the port, if we haven't
1330 * already. If we have, and it's a scsi entity, be 1238 * already. If we have, and it's a scsi entity, be
1331 * sure to unblock any attached scsi devices 1239 * sure to unblock any attached scsi devices
1332 */ 1240 */
1333 if ((!nlp->rport) || (nlp->rport->port_state == 1241 lpfc_register_remote_port(phba, ndlp);
1334 FC_PORTSTATE_BLOCKED)) 1242 }
1335 lpfc_register_remote_port(phba, nlp);
1336 1243
1337 /* 1244 /*
1338 * if we added to Mapped list, but the remote port 1245 * if we added to Mapped list, but the remote port
@@ -1340,19 +1247,95 @@ lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1340 * our presentable range - move the node to the 1247 * our presentable range - move the node to the
1341 * Unmapped List 1248 * Unmapped List
1342 */ 1249 */
1343 if ((rport_add == mapped) && 1250 if (new_state == NLP_STE_MAPPED_NODE &&
1344 ((!nlp->rport) || 1251 (!ndlp->rport ||
1345 (nlp->rport->scsi_target_id == -1) || 1252 ndlp->rport->scsi_target_id == -1 ||
1346 (nlp->rport->scsi_target_id >= LPFC_MAX_TARGET))) { 1253 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
1347 nlp->nlp_state = NLP_STE_UNMAPPED_NODE; 1254 spin_lock_irq(phba->host->host_lock);
1348 spin_lock_irq(phba->host->host_lock); 1255 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1349 nlp->nlp_flag |= NLP_TGT_NO_SCSIID; 1256 spin_unlock_irq(phba->host->host_lock);
1350 spin_unlock_irq(phba->host->host_lock); 1257 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1351 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1352 }
1353 }
1354 } 1258 }
1355 return 0; 1259}
1260
1261static char *
1262lpfc_nlp_state_name(char *buffer, size_t size, int state)
1263{
1264 static char *states[] = {
1265 [NLP_STE_UNUSED_NODE] = "UNUSED",
1266 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
1267 [NLP_STE_ADISC_ISSUE] = "ADISC",
1268 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
1269 [NLP_STE_PRLI_ISSUE] = "PRLI",
1270 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
1271 [NLP_STE_MAPPED_NODE] = "MAPPED",
1272 [NLP_STE_NPR_NODE] = "NPR",
1273 };
1274
1275 if (state < ARRAY_SIZE(states) && states[state])
1276 strlcpy(buffer, states[state], size);
1277 else
1278 snprintf(buffer, size, "unknown (%d)", state);
1279 return buffer;
1280}
1281
1282void
1283lpfc_nlp_set_state(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, int state)
1284{
1285 int old_state = ndlp->nlp_state;
1286 char name1[16], name2[16];
1287
1288 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1289 "%d:0904 NPort state transition x%06x, %s -> %s\n",
1290 phba->brd_no,
1291 ndlp->nlp_DID,
1292 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
1293 lpfc_nlp_state_name(name2, sizeof(name2), state));
1294 if (old_state == NLP_STE_NPR_NODE &&
1295 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1296 state != NLP_STE_NPR_NODE)
1297 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1298 if (old_state == NLP_STE_UNMAPPED_NODE) {
1299 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1300 ndlp->nlp_type &= ~NLP_FC_NODE;
1301 }
1302
1303 if (list_empty(&ndlp->nlp_listp)) {
1304 spin_lock_irq(phba->host->host_lock);
1305 list_add_tail(&ndlp->nlp_listp, &phba->fc_nodes);
1306 spin_unlock_irq(phba->host->host_lock);
1307 } else if (old_state)
1308 lpfc_nlp_counters(phba, old_state, -1);
1309
1310 ndlp->nlp_state = state;
1311 lpfc_nlp_counters(phba, state, 1);
1312 lpfc_nlp_state_cleanup(phba, ndlp, old_state, state);
1313}
1314
1315void
1316lpfc_dequeue_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1317{
1318 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1319 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1320 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1321 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1322 spin_lock_irq(phba->host->host_lock);
1323 list_del_init(&ndlp->nlp_listp);
1324 spin_unlock_irq(phba->host->host_lock);
1325 lpfc_nlp_state_cleanup(phba, ndlp, ndlp->nlp_state, 0);
1326}
1327
1328void
1329lpfc_drop_node(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1330{
1331 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
1332 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1333 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1334 lpfc_nlp_counters(phba, ndlp->nlp_state, -1);
1335 spin_lock_irq(phba->host->host_lock);
1336 list_del_init(&ndlp->nlp_listp);
1337 spin_unlock_irq(phba->host->host_lock);
1338 lpfc_nlp_put(ndlp);
1356} 1339}
1357 1340
1358/* 1341/*
@@ -1464,6 +1447,7 @@ lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1464static int 1447static int
1465lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp) 1448lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1466{ 1449{
1450 LIST_HEAD(completions);
1467 struct lpfc_sli *psli; 1451 struct lpfc_sli *psli;
1468 struct lpfc_sli_ring *pring; 1452 struct lpfc_sli_ring *pring;
1469 struct lpfc_iocbq *iocb, *next_iocb; 1453 struct lpfc_iocbq *iocb, *next_iocb;
@@ -1492,29 +1476,29 @@ lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1492 (phba, pring, iocb, ndlp))) { 1476 (phba, pring, iocb, ndlp))) {
1493 /* It matches, so deque and call compl 1477 /* It matches, so deque and call compl
1494 with an error */ 1478 with an error */
1495 list_del(&iocb->list); 1479 list_move_tail(&iocb->list,
1480 &completions);
1496 pring->txq_cnt--; 1481 pring->txq_cnt--;
1497 if (iocb->iocb_cmpl) {
1498 icmd = &iocb->iocb;
1499 icmd->ulpStatus =
1500 IOSTAT_LOCAL_REJECT;
1501 icmd->un.ulpWord[4] =
1502 IOERR_SLI_ABORTED;
1503 spin_unlock_irq(phba->host->
1504 host_lock);
1505 (iocb->iocb_cmpl) (phba,
1506 iocb, iocb);
1507 spin_lock_irq(phba->host->
1508 host_lock);
1509 } else
1510 lpfc_sli_release_iocbq(phba,
1511 iocb);
1512 } 1482 }
1513 } 1483 }
1514 spin_unlock_irq(phba->host->host_lock); 1484 spin_unlock_irq(phba->host->host_lock);
1515 1485
1516 } 1486 }
1517 } 1487 }
1488
1489 while (!list_empty(&completions)) {
1490 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1491 list_del(&iocb->list);
1492
1493 if (iocb->iocb_cmpl) {
1494 icmd = &iocb->iocb;
1495 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1496 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1497 (iocb->iocb_cmpl) (phba, iocb, iocb);
1498 } else
1499 lpfc_sli_release_iocbq(phba, iocb);
1500 }
1501
1518 return 0; 1502 return 0;
1519} 1503}
1520 1504
@@ -1554,7 +1538,7 @@ lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1554 * so it can be freed. 1538 * so it can be freed.
1555 */ 1539 */
1556static int 1540static int
1557lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp) 1541lpfc_cleanup_node(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1558{ 1542{
1559 LPFC_MBOXQ_t *mb; 1543 LPFC_MBOXQ_t *mb;
1560 LPFC_MBOXQ_t *nextmb; 1544 LPFC_MBOXQ_t *nextmb;
@@ -1567,17 +1551,7 @@ lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1567 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag, 1551 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1568 ndlp->nlp_state, ndlp->nlp_rpi); 1552 ndlp->nlp_state, ndlp->nlp_rpi);
1569 1553
1570 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ); 1554 lpfc_dequeue_node(phba, ndlp);
1571
1572 /*
1573 * if unloading the driver - just leave the remote port in place.
1574 * The driver unload will force the attached devices to detach
1575 * and flush cache's w/o generating flush errors.
1576 */
1577 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1578 lpfc_unregister_remote_port(phba, ndlp);
1579 ndlp->nlp_sid = NLP_NO_SID;
1580 }
1581 1555
1582 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */ 1556 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1583 if ((mb = phba->sli.mbox_active)) { 1557 if ((mb = phba->sli.mbox_active)) {
@@ -1599,11 +1573,12 @@ lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1599 } 1573 }
1600 list_del(&mb->list); 1574 list_del(&mb->list);
1601 mempool_free(mb, phba->mbox_mem_pool); 1575 mempool_free(mb, phba->mbox_mem_pool);
1576 lpfc_nlp_put(ndlp);
1602 } 1577 }
1603 } 1578 }
1604 spin_unlock_irq(phba->host->host_lock); 1579 spin_unlock_irq(phba->host->host_lock);
1605 1580
1606 lpfc_els_abort(phba,ndlp,0); 1581 lpfc_els_abort(phba,ndlp);
1607 spin_lock_irq(phba->host->host_lock); 1582 spin_lock_irq(phba->host->host_lock);
1608 ndlp->nlp_flag &= ~NLP_DELAY_TMO; 1583 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1609 spin_unlock_irq(phba->host->host_lock); 1584 spin_unlock_irq(phba->host->host_lock);
@@ -1624,27 +1599,27 @@ lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1624 * If we are in the middle of using the nlp in the discovery state 1599 * If we are in the middle of using the nlp in the discovery state
1625 * machine, defer the free till we reach the end of the state machine. 1600 * machine, defer the free till we reach the end of the state machine.
1626 */ 1601 */
1627int 1602static void
1628lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp) 1603lpfc_nlp_remove(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
1629{ 1604{
1605 struct lpfc_rport_data *rdata;
1630 1606
1631 if (ndlp->nlp_flag & NLP_DELAY_TMO) { 1607 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1632 lpfc_cancel_retry_delay_tmo(phba, ndlp); 1608 lpfc_cancel_retry_delay_tmo(phba, ndlp);
1633 } 1609 }
1634 1610
1635 if (ndlp->nlp_disc_refcnt) { 1611 lpfc_cleanup_node(phba, ndlp);
1636 spin_lock_irq(phba->host->host_lock); 1612
1637 ndlp->nlp_flag |= NLP_DELAY_REMOVE; 1613 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
1638 spin_unlock_irq(phba->host->host_lock); 1614 put_device(&ndlp->rport->dev);
1639 } else { 1615 rdata = ndlp->rport->dd_data;
1640 lpfc_freenode(phba, ndlp); 1616 rdata->pnode = NULL;
1641 mempool_free( ndlp, phba->nlp_mem_pool); 1617 ndlp->rport = NULL;
1642 } 1618 }
1643 return 0;
1644} 1619}
1645 1620
1646static int 1621static int
1647lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did) 1622lpfc_matchdid(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, uint32_t did)
1648{ 1623{
1649 D_ID mydid; 1624 D_ID mydid;
1650 D_ID ndlpdid; 1625 D_ID ndlpdid;
@@ -1693,57 +1668,36 @@ lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1693 return 0; 1668 return 0;
1694} 1669}
1695 1670
1696/* Search for a nodelist entry on a specific list */ 1671/* Search for a nodelist entry */
1697struct lpfc_nodelist * 1672struct lpfc_nodelist *
1698lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did) 1673lpfc_findnode_did(struct lpfc_hba *phba, uint32_t did)
1699{ 1674{
1700 struct lpfc_nodelist *ndlp; 1675 struct lpfc_nodelist *ndlp;
1701 struct list_head *lists[]={&phba->fc_nlpunmap_list,
1702 &phba->fc_nlpmap_list,
1703 &phba->fc_plogi_list,
1704 &phba->fc_adisc_list,
1705 &phba->fc_reglogin_list,
1706 &phba->fc_prli_list,
1707 &phba->fc_npr_list,
1708 &phba->fc_unused_list};
1709 uint32_t search[]={NLP_SEARCH_UNMAPPED,
1710 NLP_SEARCH_MAPPED,
1711 NLP_SEARCH_PLOGI,
1712 NLP_SEARCH_ADISC,
1713 NLP_SEARCH_REGLOGIN,
1714 NLP_SEARCH_PRLI,
1715 NLP_SEARCH_NPR,
1716 NLP_SEARCH_UNUSED};
1717 int i;
1718 uint32_t data1; 1676 uint32_t data1;
1719 1677
1720 spin_lock_irq(phba->host->host_lock); 1678 spin_lock_irq(phba->host->host_lock);
1721 for (i = 0; i < ARRAY_SIZE(lists); i++ ) { 1679 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
1722 if (!(order & search[i])) 1680 if (lpfc_matchdid(phba, ndlp, did)) {
1723 continue; 1681 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1724 list_for_each_entry(ndlp, lists[i], nlp_listp) { 1682 ((uint32_t) ndlp->nlp_xri << 16) |
1725 if (lpfc_matchdid(phba, ndlp, did)) { 1683 ((uint32_t) ndlp->nlp_type << 8) |
1726 data1 = (((uint32_t) ndlp->nlp_state << 24) | 1684 ((uint32_t) ndlp->nlp_rpi & 0xff));
1727 ((uint32_t) ndlp->nlp_xri << 16) | 1685 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1728 ((uint32_t) ndlp->nlp_type << 8) | 1686 "%d:0929 FIND node DID "
1729 ((uint32_t) ndlp->nlp_rpi & 0xff)); 1687 " Data: x%p x%x x%x x%x\n",
1730 lpfc_printf_log(phba, KERN_INFO, LOG_NODE, 1688 phba->brd_no,
1731 "%d:0929 FIND node DID " 1689 ndlp, ndlp->nlp_DID,
1732 " Data: x%p x%x x%x x%x\n", 1690 ndlp->nlp_flag, data1);
1733 phba->brd_no, 1691 spin_unlock_irq(phba->host->host_lock);
1734 ndlp, ndlp->nlp_DID, 1692 return ndlp;
1735 ndlp->nlp_flag, data1);
1736 spin_unlock_irq(phba->host->host_lock);
1737 return ndlp;
1738 }
1739 } 1693 }
1740 } 1694 }
1741 spin_unlock_irq(phba->host->host_lock); 1695 spin_unlock_irq(phba->host->host_lock);
1742 1696
1743 /* FIND node did <did> NOT FOUND */ 1697 /* FIND node did <did> NOT FOUND */
1744 lpfc_printf_log(phba, KERN_INFO, LOG_NODE, 1698 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1745 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n", 1699 "%d:0932 FIND node did x%x NOT FOUND.\n",
1746 phba->brd_no, did, order); 1700 phba->brd_no, did);
1747 return NULL; 1701 return NULL;
1748} 1702}
1749 1703
@@ -1751,9 +1705,8 @@ struct lpfc_nodelist *
1751lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did) 1705lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1752{ 1706{
1753 struct lpfc_nodelist *ndlp; 1707 struct lpfc_nodelist *ndlp;
1754 uint32_t flg;
1755 1708
1756 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did); 1709 ndlp = lpfc_findnode_did(phba, did);
1757 if (!ndlp) { 1710 if (!ndlp) {
1758 if ((phba->fc_flag & FC_RSCN_MODE) && 1711 if ((phba->fc_flag & FC_RSCN_MODE) &&
1759 ((lpfc_rscn_payload_check(phba, did) == 0))) 1712 ((lpfc_rscn_payload_check(phba, did) == 0)))
@@ -1763,8 +1716,7 @@ lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1763 if (!ndlp) 1716 if (!ndlp)
1764 return NULL; 1717 return NULL;
1765 lpfc_nlp_init(phba, ndlp, did); 1718 lpfc_nlp_init(phba, ndlp, did);
1766 ndlp->nlp_state = NLP_STE_NPR_NODE; 1719 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1767 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1768 ndlp->nlp_flag |= NLP_NPR_2B_DISC; 1720 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1769 return ndlp; 1721 return ndlp;
1770 } 1722 }
@@ -1780,11 +1732,10 @@ lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1780 } else 1732 } else
1781 ndlp = NULL; 1733 ndlp = NULL;
1782 } else { 1734 } else {
1783 flg = ndlp->nlp_flag & NLP_LIST_MASK; 1735 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
1784 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST)) 1736 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE)
1785 return NULL; 1737 return NULL;
1786 ndlp->nlp_state = NLP_STE_NPR_NODE; 1738 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1787 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1788 ndlp->nlp_flag |= NLP_NPR_2B_DISC; 1739 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1789 } 1740 }
1790 return ndlp; 1741 return ndlp;
@@ -1842,8 +1793,9 @@ lpfc_disc_start(struct lpfc_hba * phba)
1842 struct lpfc_sli *psli; 1793 struct lpfc_sli *psli;
1843 LPFC_MBOXQ_t *mbox; 1794 LPFC_MBOXQ_t *mbox;
1844 struct lpfc_nodelist *ndlp, *next_ndlp; 1795 struct lpfc_nodelist *ndlp, *next_ndlp;
1845 uint32_t did_changed, num_sent; 1796 uint32_t num_sent;
1846 uint32_t clear_la_pending; 1797 uint32_t clear_la_pending;
1798 int did_changed;
1847 int rc; 1799 int rc;
1848 1800
1849 psli = &phba->sli; 1801 psli = &phba->sli;
@@ -1877,14 +1829,13 @@ lpfc_disc_start(struct lpfc_hba * phba)
1877 phba->fc_plogi_cnt, phba->fc_adisc_cnt); 1829 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1878 1830
1879 /* If our did changed, we MUST do PLOGI */ 1831 /* If our did changed, we MUST do PLOGI */
1880 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list, 1832 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) {
1881 nlp_listp) { 1833 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
1882 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) { 1834 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
1883 if (did_changed) { 1835 did_changed) {
1884 spin_lock_irq(phba->host->host_lock); 1836 spin_lock_irq(phba->host->host_lock);
1885 ndlp->nlp_flag &= ~NLP_NPR_ADISC; 1837 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1886 spin_unlock_irq(phba->host->host_lock); 1838 spin_unlock_irq(phba->host->host_lock);
1887 }
1888 } 1839 }
1889 } 1840 }
1890 1841
@@ -1944,11 +1895,11 @@ lpfc_disc_start(struct lpfc_hba * phba)
1944static void 1895static void
1945lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp) 1896lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1946{ 1897{
1898 LIST_HEAD(completions);
1947 struct lpfc_sli *psli; 1899 struct lpfc_sli *psli;
1948 IOCB_t *icmd; 1900 IOCB_t *icmd;
1949 struct lpfc_iocbq *iocb, *next_iocb; 1901 struct lpfc_iocbq *iocb, *next_iocb;
1950 struct lpfc_sli_ring *pring; 1902 struct lpfc_sli_ring *pring;
1951 struct lpfc_dmabuf *mp;
1952 1903
1953 psli = &phba->sli; 1904 psli = &phba->sli;
1954 pring = &psli->ring[LPFC_ELS_RING]; 1905 pring = &psli->ring[LPFC_ELS_RING];
@@ -1956,6 +1907,7 @@ lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1956 /* Error matching iocb on txq or txcmplq 1907 /* Error matching iocb on txq or txcmplq
1957 * First check the txq. 1908 * First check the txq.
1958 */ 1909 */
1910 spin_lock_irq(phba->host->host_lock);
1959 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { 1911 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
1960 if (iocb->context1 != ndlp) { 1912 if (iocb->context1 != ndlp) {
1961 continue; 1913 continue;
@@ -1964,9 +1916,8 @@ lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1964 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || 1916 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
1965 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { 1917 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
1966 1918
1967 list_del(&iocb->list); 1919 list_move_tail(&iocb->list, &completions);
1968 pring->txq_cnt--; 1920 pring->txq_cnt--;
1969 lpfc_els_free_iocb(phba, iocb);
1970 } 1921 }
1971 } 1922 }
1972 1923
@@ -1978,43 +1929,22 @@ lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1978 icmd = &iocb->iocb; 1929 icmd = &iocb->iocb;
1979 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) || 1930 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
1980 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) { 1931 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
1932 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1933 }
1934 }
1935 spin_unlock_irq(phba->host->host_lock);
1981 1936
1982 iocb->iocb_cmpl = NULL; 1937 while (!list_empty(&completions)) {
1983 /* context2 = cmd, context2->next = rsp, context3 = 1938 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1984 bpl */ 1939 list_del(&iocb->list);
1985 if (iocb->context2) {
1986 /* Free the response IOCB before handling the
1987 command. */
1988
1989 mp = (struct lpfc_dmabuf *) (iocb->context2);
1990 mp = list_get_first(&mp->list,
1991 struct lpfc_dmabuf,
1992 list);
1993 if (mp) {
1994 /* Delay before releasing rsp buffer to
1995 * give UNREG mbox a chance to take
1996 * effect.
1997 */
1998 list_add(&mp->list,
1999 &phba->freebufList);
2000 }
2001 lpfc_mbuf_free(phba,
2002 ((struct lpfc_dmabuf *)
2003 iocb->context2)->virt,
2004 ((struct lpfc_dmabuf *)
2005 iocb->context2)->phys);
2006 kfree(iocb->context2);
2007 }
2008 1940
2009 if (iocb->context3) { 1941 if (iocb->iocb_cmpl) {
2010 lpfc_mbuf_free(phba, 1942 icmd = &iocb->iocb;
2011 ((struct lpfc_dmabuf *) 1943 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2012 iocb->context3)->virt, 1944 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2013 ((struct lpfc_dmabuf *) 1945 (iocb->iocb_cmpl) (phba, iocb, iocb);
2014 iocb->context3)->phys); 1946 } else
2015 kfree(iocb->context3); 1947 lpfc_sli_release_iocbq(phba, iocb);
2016 }
2017 }
2018 } 1948 }
2019 1949
2020 return; 1950 return;
@@ -2025,21 +1955,16 @@ lpfc_disc_flush_list(struct lpfc_hba * phba)
2025{ 1955{
2026 struct lpfc_nodelist *ndlp, *next_ndlp; 1956 struct lpfc_nodelist *ndlp, *next_ndlp;
2027 1957
2028 if (phba->fc_plogi_cnt) { 1958 if (phba->fc_plogi_cnt || phba->fc_adisc_cnt) {
2029 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list, 1959 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes,
2030 nlp_listp) { 1960 nlp_listp) {
2031 lpfc_free_tx(phba, ndlp); 1961 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2032 lpfc_nlp_remove(phba, ndlp); 1962 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
2033 } 1963 lpfc_free_tx(phba, ndlp);
2034 } 1964 lpfc_nlp_put(ndlp);
2035 if (phba->fc_adisc_cnt) { 1965 }
2036 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2037 nlp_listp) {
2038 lpfc_free_tx(phba, ndlp);
2039 lpfc_nlp_remove(phba, ndlp);
2040 } 1966 }
2041 } 1967 }
2042 return;
2043} 1968}
2044 1969
2045/*****************************************************************************/ 1970/*****************************************************************************/
@@ -2108,11 +2033,13 @@ lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2108 phba->brd_no); 2033 phba->brd_no);
2109 2034
2110 /* Start discovery by sending FLOGI, clean up old rpis */ 2035 /* Start discovery by sending FLOGI, clean up old rpis */
2111 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list, 2036 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes,
2112 nlp_listp) { 2037 nlp_listp) {
2038 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
2039 continue;
2113 if (ndlp->nlp_type & NLP_FABRIC) { 2040 if (ndlp->nlp_type & NLP_FABRIC) {
2114 /* Clean up the ndlp on Fabric connections */ 2041 /* Clean up the ndlp on Fabric connections */
2115 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 2042 lpfc_drop_node(phba, ndlp);
2116 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) { 2043 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2117 /* Fail outstanding IO now since device 2044 /* Fail outstanding IO now since device
2118 * is marked for PLOGI. 2045 * is marked for PLOGI.
@@ -2153,9 +2080,9 @@ lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2153 "login\n", phba->brd_no); 2080 "login\n", phba->brd_no);
2154 2081
2155 /* Next look for NameServer ndlp */ 2082 /* Next look for NameServer ndlp */
2156 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID); 2083 ndlp = lpfc_findnode_did(phba, NameServer_DID);
2157 if (ndlp) 2084 if (ndlp)
2158 lpfc_nlp_remove(phba, ndlp); 2085 lpfc_nlp_put(ndlp);
2159 /* Start discovery */ 2086 /* Start discovery */
2160 lpfc_disc_start(phba); 2087 lpfc_disc_start(phba);
2161 break; 2088 break;
@@ -2168,9 +2095,8 @@ lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2168 phba->brd_no, 2095 phba->brd_no,
2169 phba->fc_ns_retry, LPFC_MAX_NS_RETRY); 2096 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2170 2097
2171 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, 2098 ndlp = lpfc_findnode_did(phba, NameServer_DID);
2172 NameServer_DID); 2099 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
2173 if (ndlp) {
2174 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) { 2100 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2175 /* Try it one more time */ 2101 /* Try it one more time */
2176 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT); 2102 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
@@ -2220,6 +2146,7 @@ lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2220 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0; 2146 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2221 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, 2147 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2222 (MBX_NOWAIT | MBX_STOP_IOCB)); 2148 (MBX_NOWAIT | MBX_STOP_IOCB));
2149 lpfc_set_loopback_flag(phba);
2223 if (rc == MBX_NOT_FINISHED) 2150 if (rc == MBX_NOT_FINISHED)
2224 mempool_free(initlinkmbox, phba->mbox_mem_pool); 2151 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2225 2152
@@ -2317,8 +2244,7 @@ lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2317 2244
2318 ndlp->nlp_rpi = mb->un.varWords[0]; 2245 ndlp->nlp_rpi = mb->un.varWords[0];
2319 ndlp->nlp_type |= NLP_FABRIC; 2246 ndlp->nlp_type |= NLP_FABRIC;
2320 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; 2247 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
2321 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2322 2248
2323 /* Start issuing Fabric-Device Management Interface (FDMI) 2249 /* Start issuing Fabric-Device Management Interface (FDMI)
2324 * command to 0xfffffa (FDMI well known port) 2250 * command to 0xfffffa (FDMI well known port)
@@ -2333,87 +2259,100 @@ lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2333 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60); 2259 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2334 } 2260 }
2335 2261
2262 /* Mailbox took a reference to the node */
2263 lpfc_nlp_put(ndlp);
2336 lpfc_mbuf_free(phba, mp->virt, mp->phys); 2264 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2337 kfree(mp); 2265 kfree(mp);
2338 mempool_free( pmb, phba->mbox_mem_pool); 2266 mempool_free(pmb, phba->mbox_mem_pool);
2339 2267
2340 return; 2268 return;
2341} 2269}
2342 2270
2271static int
2272lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
2273{
2274 uint16_t *rpi = param;
2275
2276 return ndlp->nlp_rpi == *rpi;
2277}
2278
2279static int
2280lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
2281{
2282 return memcmp(&ndlp->nlp_portname, param,
2283 sizeof(ndlp->nlp_portname)) == 0;
2284}
2285
2286/*
2287 * Search node lists for a remote port matching filter criteria
2288 * Caller needs to hold host_lock before calling this routine.
2289 */
2290struct lpfc_nodelist *
2291__lpfc_find_node(struct lpfc_hba *phba, node_filter filter, void *param)
2292{
2293 struct lpfc_nodelist *ndlp;
2294
2295 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
2296 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE &&
2297 filter(ndlp, param))
2298 return ndlp;
2299 }
2300 return NULL;
2301}
2302
2343/* 2303/*
2344 * This routine looks up the ndlp lists 2304 * Search node lists for a remote port matching filter criteria
2345 * for the given RPI. If rpi found 2305 * This routine is used when the caller does NOT have host_lock.
2346 * it return the node list pointer
2347 * else return NULL.
2348 */ 2306 */
2349struct lpfc_nodelist * 2307struct lpfc_nodelist *
2308lpfc_find_node(struct lpfc_hba *phba, node_filter filter, void *param)
2309{
2310 struct lpfc_nodelist *ndlp;
2311
2312 spin_lock_irq(phba->host->host_lock);
2313 ndlp = __lpfc_find_node(phba, filter, param);
2314 spin_unlock_irq(phba->host->host_lock);
2315 return ndlp;
2316}
2317
2318/*
2319 * This routine looks up the ndlp lists for the given RPI. If rpi found it
2320 * returns the node list pointer else return NULL.
2321 */
2322struct lpfc_nodelist *
2323__lpfc_findnode_rpi(struct lpfc_hba *phba, uint16_t rpi)
2324{
2325 return __lpfc_find_node(phba, lpfc_filter_by_rpi, &rpi);
2326}
2327
2328struct lpfc_nodelist *
2350lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi) 2329lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2351{ 2330{
2352 struct lpfc_nodelist *ndlp; 2331 struct lpfc_nodelist *ndlp;
2353 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2354 &phba->fc_nlpmap_list,
2355 &phba->fc_plogi_list,
2356 &phba->fc_adisc_list,
2357 &phba->fc_reglogin_list};
2358 int i;
2359 2332
2360 spin_lock_irq(phba->host->host_lock); 2333 spin_lock_irq(phba->host->host_lock);
2361 for (i = 0; i < ARRAY_SIZE(lists); i++ ) 2334 ndlp = __lpfc_findnode_rpi(phba, rpi);
2362 list_for_each_entry(ndlp, lists[i], nlp_listp)
2363 if (ndlp->nlp_rpi == rpi) {
2364 spin_unlock_irq(phba->host->host_lock);
2365 return ndlp;
2366 }
2367 spin_unlock_irq(phba->host->host_lock); 2335 spin_unlock_irq(phba->host->host_lock);
2368 return NULL; 2336 return ndlp;
2369} 2337}
2370 2338
2371/* 2339/*
2372 * This routine looks up the ndlp lists 2340 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
2373 * for the given WWPN. If WWPN found 2341 * returns the node list pointer else return NULL.
2374 * it return the node list pointer
2375 * else return NULL.
2376 */ 2342 */
2377struct lpfc_nodelist * 2343struct lpfc_nodelist *
2378lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order, 2344lpfc_findnode_wwpn(struct lpfc_hba *phba, struct lpfc_name *wwpn)
2379 struct lpfc_name * wwpn)
2380{ 2345{
2381 struct lpfc_nodelist *ndlp; 2346 struct lpfc_nodelist *ndlp;
2382 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2383 &phba->fc_nlpmap_list,
2384 &phba->fc_npr_list,
2385 &phba->fc_plogi_list,
2386 &phba->fc_adisc_list,
2387 &phba->fc_reglogin_list,
2388 &phba->fc_prli_list};
2389 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2390 NLP_SEARCH_MAPPED,
2391 NLP_SEARCH_NPR,
2392 NLP_SEARCH_PLOGI,
2393 NLP_SEARCH_ADISC,
2394 NLP_SEARCH_REGLOGIN,
2395 NLP_SEARCH_PRLI};
2396 int i;
2397 2347
2398 spin_lock_irq(phba->host->host_lock); 2348 spin_lock_irq(phba->host->host_lock);
2399 for (i = 0; i < ARRAY_SIZE(lists); i++ ) { 2349 ndlp = __lpfc_find_node(phba, lpfc_filter_by_wwpn, wwpn);
2400 if (!(order & search[i]))
2401 continue;
2402 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2403 if (memcmp(&ndlp->nlp_portname, wwpn,
2404 sizeof(struct lpfc_name)) == 0) {
2405 spin_unlock_irq(phba->host->host_lock);
2406 return ndlp;
2407 }
2408 }
2409 }
2410 spin_unlock_irq(phba->host->host_lock); 2350 spin_unlock_irq(phba->host->host_lock);
2411 return NULL; 2351 return NULL;
2412} 2352}
2413 2353
2414void 2354void
2415lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, 2355lpfc_nlp_init(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp, uint32_t did)
2416 uint32_t did)
2417{ 2356{
2418 memset(ndlp, 0, sizeof (struct lpfc_nodelist)); 2357 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2419 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp); 2358 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
@@ -2423,5 +2362,30 @@ lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2423 ndlp->nlp_DID = did; 2362 ndlp->nlp_DID = did;
2424 ndlp->nlp_phba = phba; 2363 ndlp->nlp_phba = phba;
2425 ndlp->nlp_sid = NLP_NO_SID; 2364 ndlp->nlp_sid = NLP_NO_SID;
2365 INIT_LIST_HEAD(&ndlp->nlp_listp);
2366 kref_init(&ndlp->kref);
2426 return; 2367 return;
2427} 2368}
2369
2370void
2371lpfc_nlp_release(struct kref *kref)
2372{
2373 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2374 kref);
2375 lpfc_nlp_remove(ndlp->nlp_phba, ndlp);
2376 mempool_free(ndlp, ndlp->nlp_phba->nlp_mem_pool);
2377}
2378
2379struct lpfc_nodelist *
2380lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2381{
2382 if (ndlp)
2383 kref_get(&ndlp->kref);
2384 return ndlp;
2385}
2386
2387int
2388lpfc_nlp_put(struct lpfc_nodelist *ndlp)
2389{
2390 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
2391}
diff --git a/drivers/scsi/lpfc/lpfc_hw.h b/drivers/scsi/lpfc/lpfc_hw.h
index f79cb6136906..2623a9bc7775 100644
--- a/drivers/scsi/lpfc/lpfc_hw.h
+++ b/drivers/scsi/lpfc/lpfc_hw.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -1078,6 +1078,8 @@ typedef struct {
1078/* Start FireFly Register definitions */ 1078/* Start FireFly Register definitions */
1079#define PCI_VENDOR_ID_EMULEX 0x10df 1079#define PCI_VENDOR_ID_EMULEX 0x10df
1080#define PCI_DEVICE_ID_FIREFLY 0x1ae5 1080#define PCI_DEVICE_ID_FIREFLY 0x1ae5
1081#define PCI_DEVICE_ID_SAT_SMB 0xf011
1082#define PCI_DEVICE_ID_SAT_MID 0xf015
1081#define PCI_DEVICE_ID_RFLY 0xf095 1083#define PCI_DEVICE_ID_RFLY 0xf095
1082#define PCI_DEVICE_ID_PFLY 0xf098 1084#define PCI_DEVICE_ID_PFLY 0xf098
1083#define PCI_DEVICE_ID_LP101 0xf0a1 1085#define PCI_DEVICE_ID_LP101 0xf0a1
@@ -1089,6 +1091,9 @@ typedef struct {
1089#define PCI_DEVICE_ID_NEPTUNE 0xf0f5 1091#define PCI_DEVICE_ID_NEPTUNE 0xf0f5
1090#define PCI_DEVICE_ID_NEPTUNE_SCSP 0xf0f6 1092#define PCI_DEVICE_ID_NEPTUNE_SCSP 0xf0f6
1091#define PCI_DEVICE_ID_NEPTUNE_DCSP 0xf0f7 1093#define PCI_DEVICE_ID_NEPTUNE_DCSP 0xf0f7
1094#define PCI_DEVICE_ID_SAT 0xf100
1095#define PCI_DEVICE_ID_SAT_SCSP 0xf111
1096#define PCI_DEVICE_ID_SAT_DCSP 0xf112
1092#define PCI_DEVICE_ID_SUPERFLY 0xf700 1097#define PCI_DEVICE_ID_SUPERFLY 0xf700
1093#define PCI_DEVICE_ID_DRAGONFLY 0xf800 1098#define PCI_DEVICE_ID_DRAGONFLY 0xf800
1094#define PCI_DEVICE_ID_CENTAUR 0xf900 1099#define PCI_DEVICE_ID_CENTAUR 0xf900
@@ -1098,6 +1103,7 @@ typedef struct {
1098#define PCI_DEVICE_ID_LP10000S 0xfc00 1103#define PCI_DEVICE_ID_LP10000S 0xfc00
1099#define PCI_DEVICE_ID_LP11000S 0xfc10 1104#define PCI_DEVICE_ID_LP11000S 0xfc10
1100#define PCI_DEVICE_ID_LPE11000S 0xfc20 1105#define PCI_DEVICE_ID_LPE11000S 0xfc20
1106#define PCI_DEVICE_ID_SAT_S 0xfc40
1101#define PCI_DEVICE_ID_HELIOS 0xfd00 1107#define PCI_DEVICE_ID_HELIOS 0xfd00
1102#define PCI_DEVICE_ID_HELIOS_SCSP 0xfd11 1108#define PCI_DEVICE_ID_HELIOS_SCSP 0xfd11
1103#define PCI_DEVICE_ID_HELIOS_DCSP 0xfd12 1109#define PCI_DEVICE_ID_HELIOS_DCSP 0xfd12
@@ -1118,6 +1124,7 @@ typedef struct {
1118#define HELIOS_JEDEC_ID 0x0364 1124#define HELIOS_JEDEC_ID 0x0364
1119#define ZEPHYR_JEDEC_ID 0x0577 1125#define ZEPHYR_JEDEC_ID 0x0577
1120#define VIPER_JEDEC_ID 0x4838 1126#define VIPER_JEDEC_ID 0x4838
1127#define SATURN_JEDEC_ID 0x1004
1121 1128
1122#define JEDEC_ID_MASK 0x0FFFF000 1129#define JEDEC_ID_MASK 0x0FFFF000
1123#define JEDEC_ID_SHIFT 12 1130#define JEDEC_ID_SHIFT 12
@@ -1565,7 +1572,7 @@ typedef struct {
1565#define LINK_SPEED_1G 1 /* 1 Gigabaud */ 1572#define LINK_SPEED_1G 1 /* 1 Gigabaud */
1566#define LINK_SPEED_2G 2 /* 2 Gigabaud */ 1573#define LINK_SPEED_2G 2 /* 2 Gigabaud */
1567#define LINK_SPEED_4G 4 /* 4 Gigabaud */ 1574#define LINK_SPEED_4G 4 /* 4 Gigabaud */
1568#define LINK_SPEED_8G 8 /* 4 Gigabaud */ 1575#define LINK_SPEED_8G 8 /* 8 Gigabaud */
1569#define LINK_SPEED_10G 16 /* 10 Gigabaud */ 1576#define LINK_SPEED_10G 16 /* 10 Gigabaud */
1570 1577
1571} INIT_LINK_VAR; 1578} INIT_LINK_VAR;
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index dcf6106f557a..dcb4ba0ecee1 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -386,12 +386,12 @@ lpfc_config_port_post(struct lpfc_hba * phba)
386 * Setup the ring 0 (els) timeout handler 386 * Setup the ring 0 (els) timeout handler
387 */ 387 */
388 timeout = phba->fc_ratov << 1; 388 timeout = phba->fc_ratov << 1;
389 phba->els_tmofunc.expires = jiffies + HZ * timeout; 389 mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout);
390 add_timer(&phba->els_tmofunc);
391 390
392 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed); 391 lpfc_init_link(phba, pmb, phba->cfg_topology, phba->cfg_link_speed);
393 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl; 392 pmb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
394 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT); 393 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
394 lpfc_set_loopback_flag(phba);
395 if (rc != MBX_SUCCESS) { 395 if (rc != MBX_SUCCESS) {
396 lpfc_printf_log(phba, 396 lpfc_printf_log(phba,
397 KERN_ERR, 397 KERN_ERR,
@@ -418,33 +418,6 @@ lpfc_config_port_post(struct lpfc_hba * phba)
418 return (0); 418 return (0);
419} 419}
420 420
421static int
422lpfc_discovery_wait(struct lpfc_hba *phba)
423{
424 int i = 0;
425
426 while ((phba->hba_state != LPFC_HBA_READY) ||
427 (phba->num_disc_nodes) || (phba->fc_prli_sent) ||
428 ((phba->fc_map_cnt == 0) && (i<2)) ||
429 (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE)) {
430 /* Check every second for 30 retries. */
431 i++;
432 if (i > 30) {
433 return -ETIMEDOUT;
434 }
435 if ((i >= 15) && (phba->hba_state <= LPFC_LINK_DOWN)) {
436 /* The link is down. Set linkdown timeout */
437 return -ETIMEDOUT;
438 }
439
440 /* Delay for 1 second to give discovery time to complete. */
441 msleep(1000);
442
443 }
444
445 return 0;
446}
447
448/************************************************************************/ 421/************************************************************************/
449/* */ 422/* */
450/* lpfc_hba_down_prep */ 423/* lpfc_hba_down_prep */
@@ -550,12 +523,15 @@ lpfc_handle_eratt(struct lpfc_hba * phba)
550 * There was a firmware error. Take the hba offline and then 523 * There was a firmware error. Take the hba offline and then
551 * attempt to restart it. 524 * attempt to restart it.
552 */ 525 */
526 lpfc_offline_prep(phba);
553 lpfc_offline(phba); 527 lpfc_offline(phba);
554 lpfc_sli_brdrestart(phba); 528 lpfc_sli_brdrestart(phba);
555 if (lpfc_online(phba) == 0) { /* Initialize the HBA */ 529 if (lpfc_online(phba) == 0) { /* Initialize the HBA */
556 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60); 530 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
531 lpfc_unblock_mgmt_io(phba);
557 return; 532 return;
558 } 533 }
534 lpfc_unblock_mgmt_io(phba);
559 } else { 535 } else {
560 /* The if clause above forces this code path when the status 536 /* The if clause above forces this code path when the status
561 * failure is a value other than FFER6. Do not call the offline 537 * failure is a value other than FFER6. Do not call the offline
@@ -573,7 +549,9 @@ lpfc_handle_eratt(struct lpfc_hba * phba)
573 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX); 549 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
574 550
575 psli->sli_flag &= ~LPFC_SLI2_ACTIVE; 551 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
552 lpfc_offline_prep(phba);
576 lpfc_offline(phba); 553 lpfc_offline(phba);
554 lpfc_unblock_mgmt_io(phba);
577 phba->hba_state = LPFC_HBA_ERROR; 555 phba->hba_state = LPFC_HBA_ERROR;
578 lpfc_hba_down_post(phba); 556 lpfc_hba_down_post(phba);
579 } 557 }
@@ -633,7 +611,7 @@ lpfc_handle_latt_free_mbuf:
633lpfc_handle_latt_free_mp: 611lpfc_handle_latt_free_mp:
634 kfree(mp); 612 kfree(mp);
635lpfc_handle_latt_free_pmb: 613lpfc_handle_latt_free_pmb:
636 kfree(pmb); 614 mempool_free(pmb, phba->mbox_mem_pool);
637lpfc_handle_latt_err_exit: 615lpfc_handle_latt_err_exit:
638 /* Enable Link attention interrupts */ 616 /* Enable Link attention interrupts */
639 spin_lock_irq(phba->host->host_lock); 617 spin_lock_irq(phba->host->host_lock);
@@ -925,6 +903,24 @@ lpfc_get_hba_model_desc(struct lpfc_hba * phba, uint8_t * mdp, uint8_t * descp)
925 m = (typeof(m)){"LPe11000-S", max_speed, 903 m = (typeof(m)){"LPe11000-S", max_speed,
926 "PCIe"}; 904 "PCIe"};
927 break; 905 break;
906 case PCI_DEVICE_ID_SAT:
907 m = (typeof(m)){"LPe12000", max_speed, "PCIe"};
908 break;
909 case PCI_DEVICE_ID_SAT_MID:
910 m = (typeof(m)){"LPe1250", max_speed, "PCIe"};
911 break;
912 case PCI_DEVICE_ID_SAT_SMB:
913 m = (typeof(m)){"LPe121", max_speed, "PCIe"};
914 break;
915 case PCI_DEVICE_ID_SAT_DCSP:
916 m = (typeof(m)){"LPe12002-SP", max_speed, "PCIe"};
917 break;
918 case PCI_DEVICE_ID_SAT_SCSP:
919 m = (typeof(m)){"LPe12000-SP", max_speed, "PCIe"};
920 break;
921 case PCI_DEVICE_ID_SAT_S:
922 m = (typeof(m)){"LPe12000-S", max_speed, "PCIe"};
923 break;
928 default: 924 default:
929 m = (typeof(m)){ NULL }; 925 m = (typeof(m)){ NULL };
930 break; 926 break;
@@ -1174,69 +1170,17 @@ lpfc_hba_init(struct lpfc_hba *phba, uint32_t *hbainit)
1174} 1170}
1175 1171
1176static void 1172static void
1177lpfc_cleanup(struct lpfc_hba * phba, uint32_t save_bind) 1173lpfc_cleanup(struct lpfc_hba * phba)
1178{ 1174{
1179 struct lpfc_nodelist *ndlp, *next_ndlp; 1175 struct lpfc_nodelist *ndlp, *next_ndlp;
1180 1176
1181 /* clean up phba - lpfc specific */ 1177 /* clean up phba - lpfc specific */
1182 lpfc_can_disctmo(phba); 1178 lpfc_can_disctmo(phba);
1183 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpunmap_list, 1179 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp)
1184 nlp_listp) { 1180 lpfc_nlp_put(ndlp);
1185 lpfc_nlp_remove(phba, ndlp);
1186 }
1187 1181
1188 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list, 1182 INIT_LIST_HEAD(&phba->fc_nodes);
1189 nlp_listp) {
1190 lpfc_nlp_remove(phba, ndlp);
1191 }
1192
1193 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
1194 nlp_listp) {
1195 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1196 }
1197
1198 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1199 nlp_listp) {
1200 lpfc_nlp_remove(phba, ndlp);
1201 }
1202
1203 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1204 nlp_listp) {
1205 lpfc_nlp_remove(phba, ndlp);
1206 }
1207
1208 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_reglogin_list,
1209 nlp_listp) {
1210 lpfc_nlp_remove(phba, ndlp);
1211 }
1212 1183
1213 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1214 nlp_listp) {
1215 lpfc_nlp_remove(phba, ndlp);
1216 }
1217
1218 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1219 nlp_listp) {
1220 lpfc_nlp_remove(phba, ndlp);
1221 }
1222
1223 INIT_LIST_HEAD(&phba->fc_nlpmap_list);
1224 INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
1225 INIT_LIST_HEAD(&phba->fc_unused_list);
1226 INIT_LIST_HEAD(&phba->fc_plogi_list);
1227 INIT_LIST_HEAD(&phba->fc_adisc_list);
1228 INIT_LIST_HEAD(&phba->fc_reglogin_list);
1229 INIT_LIST_HEAD(&phba->fc_prli_list);
1230 INIT_LIST_HEAD(&phba->fc_npr_list);
1231
1232 phba->fc_map_cnt = 0;
1233 phba->fc_unmap_cnt = 0;
1234 phba->fc_plogi_cnt = 0;
1235 phba->fc_adisc_cnt = 0;
1236 phba->fc_reglogin_cnt = 0;
1237 phba->fc_prli_cnt = 0;
1238 phba->fc_npr_cnt = 0;
1239 phba->fc_unused_cnt= 0;
1240 return; 1184 return;
1241} 1185}
1242 1186
@@ -1262,21 +1206,6 @@ lpfc_stop_timer(struct lpfc_hba * phba)
1262{ 1206{
1263 struct lpfc_sli *psli = &phba->sli; 1207 struct lpfc_sli *psli = &phba->sli;
1264 1208
1265 /* Instead of a timer, this has been converted to a
1266 * deferred procedding list.
1267 */
1268 while (!list_empty(&phba->freebufList)) {
1269
1270 struct lpfc_dmabuf *mp = NULL;
1271
1272 list_remove_head((&phba->freebufList), mp,
1273 struct lpfc_dmabuf, list);
1274 if (mp) {
1275 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1276 kfree(mp);
1277 }
1278 }
1279
1280 del_timer_sync(&phba->fcp_poll_timer); 1209 del_timer_sync(&phba->fcp_poll_timer);
1281 del_timer_sync(&phba->fc_estabtmo); 1210 del_timer_sync(&phba->fc_estabtmo);
1282 del_timer_sync(&phba->fc_disctmo); 1211 del_timer_sync(&phba->fc_disctmo);
@@ -1302,60 +1231,76 @@ lpfc_online(struct lpfc_hba * phba)
1302 "%d:0458 Bring Adapter online\n", 1231 "%d:0458 Bring Adapter online\n",
1303 phba->brd_no); 1232 phba->brd_no);
1304 1233
1305 if (!lpfc_sli_queue_setup(phba)) 1234 lpfc_block_mgmt_io(phba);
1235
1236 if (!lpfc_sli_queue_setup(phba)) {
1237 lpfc_unblock_mgmt_io(phba);
1306 return 1; 1238 return 1;
1239 }
1307 1240
1308 if (lpfc_sli_hba_setup(phba)) /* Initialize the HBA */ 1241 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */
1242 lpfc_unblock_mgmt_io(phba);
1309 return 1; 1243 return 1;
1244 }
1310 1245
1311 spin_lock_irq(phba->host->host_lock); 1246 spin_lock_irq(phba->host->host_lock);
1312 phba->fc_flag &= ~FC_OFFLINE_MODE; 1247 phba->fc_flag &= ~FC_OFFLINE_MODE;
1313 spin_unlock_irq(phba->host->host_lock); 1248 spin_unlock_irq(phba->host->host_lock);
1314 1249
1250 lpfc_unblock_mgmt_io(phba);
1315 return 0; 1251 return 0;
1316} 1252}
1317 1253
1318int 1254void
1319lpfc_offline(struct lpfc_hba * phba) 1255lpfc_block_mgmt_io(struct lpfc_hba * phba)
1320{ 1256{
1321 struct lpfc_sli_ring *pring;
1322 struct lpfc_sli *psli;
1323 unsigned long iflag; 1257 unsigned long iflag;
1324 int i;
1325 int cnt = 0;
1326 1258
1327 if (!phba) 1259 spin_lock_irqsave(phba->host->host_lock, iflag);
1328 return 0; 1260 phba->fc_flag |= FC_BLOCK_MGMT_IO;
1261 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1262}
1263
1264void
1265lpfc_unblock_mgmt_io(struct lpfc_hba * phba)
1266{
1267 unsigned long iflag;
1268
1269 spin_lock_irqsave(phba->host->host_lock, iflag);
1270 phba->fc_flag &= ~FC_BLOCK_MGMT_IO;
1271 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1272}
1273
1274void
1275lpfc_offline_prep(struct lpfc_hba * phba)
1276{
1277 struct lpfc_nodelist *ndlp, *next_ndlp;
1329 1278
1330 if (phba->fc_flag & FC_OFFLINE_MODE) 1279 if (phba->fc_flag & FC_OFFLINE_MODE)
1331 return 0; 1280 return;
1332 1281
1333 psli = &phba->sli; 1282 lpfc_block_mgmt_io(phba);
1334 1283
1335 lpfc_linkdown(phba); 1284 lpfc_linkdown(phba);
1285
1286 /* Issue an unreg_login to all nodes */
1287 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp)
1288 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE)
1289 lpfc_unreg_rpi(phba, ndlp);
1290
1336 lpfc_sli_flush_mbox_queue(phba); 1291 lpfc_sli_flush_mbox_queue(phba);
1292}
1337 1293
1338 for (i = 0; i < psli->num_rings; i++) { 1294void
1339 pring = &psli->ring[i]; 1295lpfc_offline(struct lpfc_hba * phba)
1340 /* The linkdown event takes 30 seconds to timeout. */ 1296{
1341 while (pring->txcmplq_cnt) { 1297 unsigned long iflag;
1342 mdelay(10);
1343 if (cnt++ > 3000) {
1344 lpfc_printf_log(phba,
1345 KERN_WARNING, LOG_INIT,
1346 "%d:0466 Outstanding IO when "
1347 "bringing Adapter offline\n",
1348 phba->brd_no);
1349 break;
1350 }
1351 }
1352 }
1353 1298
1299 if (phba->fc_flag & FC_OFFLINE_MODE)
1300 return;
1354 1301
1355 /* stop all timers associated with this hba */ 1302 /* stop all timers associated with this hba */
1356 lpfc_stop_timer(phba); 1303 lpfc_stop_timer(phba);
1357 phba->work_hba_events = 0;
1358 phba->work_ha = 0;
1359 1304
1360 lpfc_printf_log(phba, 1305 lpfc_printf_log(phba,
1361 KERN_WARNING, 1306 KERN_WARNING,
@@ -1366,11 +1311,12 @@ lpfc_offline(struct lpfc_hba * phba)
1366 /* Bring down the SLI Layer and cleanup. The HBA is offline 1311 /* Bring down the SLI Layer and cleanup. The HBA is offline
1367 now. */ 1312 now. */
1368 lpfc_sli_hba_down(phba); 1313 lpfc_sli_hba_down(phba);
1369 lpfc_cleanup(phba, 1); 1314 lpfc_cleanup(phba);
1370 spin_lock_irqsave(phba->host->host_lock, iflag); 1315 spin_lock_irqsave(phba->host->host_lock, iflag);
1316 phba->work_hba_events = 0;
1317 phba->work_ha = 0;
1371 phba->fc_flag |= FC_OFFLINE_MODE; 1318 phba->fc_flag |= FC_OFFLINE_MODE;
1372 spin_unlock_irqrestore(phba->host->host_lock, iflag); 1319 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1373 return 0;
1374} 1320}
1375 1321
1376/****************************************************************************** 1322/******************************************************************************
@@ -1407,6 +1353,156 @@ lpfc_scsi_free(struct lpfc_hba * phba)
1407 return 0; 1353 return 0;
1408} 1354}
1409 1355
1356void lpfc_remove_device(struct lpfc_hba *phba)
1357{
1358 unsigned long iflag;
1359
1360 lpfc_free_sysfs_attr(phba);
1361
1362 spin_lock_irqsave(phba->host->host_lock, iflag);
1363 phba->fc_flag |= FC_UNLOADING;
1364
1365 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1366
1367 fc_remove_host(phba->host);
1368 scsi_remove_host(phba->host);
1369
1370 kthread_stop(phba->worker_thread);
1371
1372 /*
1373 * Bring down the SLI Layer. This step disable all interrupts,
1374 * clears the rings, discards all mailbox commands, and resets
1375 * the HBA.
1376 */
1377 lpfc_sli_hba_down(phba);
1378 lpfc_sli_brdrestart(phba);
1379
1380 /* Release the irq reservation */
1381 free_irq(phba->pcidev->irq, phba);
1382 pci_disable_msi(phba->pcidev);
1383
1384 lpfc_cleanup(phba);
1385 lpfc_stop_timer(phba);
1386 phba->work_hba_events = 0;
1387
1388 /*
1389 * Call scsi_free before mem_free since scsi bufs are released to their
1390 * corresponding pools here.
1391 */
1392 lpfc_scsi_free(phba);
1393 lpfc_mem_free(phba);
1394
1395 /* Free resources associated with SLI2 interface */
1396 dma_free_coherent(&phba->pcidev->dev, SLI2_SLIM_SIZE,
1397 phba->slim2p, phba->slim2p_mapping);
1398
1399 /* unmap adapter SLIM and Control Registers */
1400 iounmap(phba->ctrl_regs_memmap_p);
1401 iounmap(phba->slim_memmap_p);
1402
1403 pci_release_regions(phba->pcidev);
1404 pci_disable_device(phba->pcidev);
1405
1406 idr_remove(&lpfc_hba_index, phba->brd_no);
1407 scsi_host_put(phba->host);
1408}
1409
1410void lpfc_scan_start(struct Scsi_Host *host)
1411{
1412 struct lpfc_hba *phba = (struct lpfc_hba*)host->hostdata;
1413
1414 if (lpfc_alloc_sysfs_attr(phba))
1415 goto error;
1416
1417 phba->MBslimaddr = phba->slim_memmap_p;
1418 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1419 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1420 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1421 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1422
1423 if (lpfc_sli_hba_setup(phba))
1424 goto error;
1425
1426 /*
1427 * hba setup may have changed the hba_queue_depth so we need to adjust
1428 * the value of can_queue.
1429 */
1430 host->can_queue = phba->cfg_hba_queue_depth - 10;
1431 return;
1432
1433error:
1434 lpfc_remove_device(phba);
1435}
1436
1437int lpfc_scan_finished(struct Scsi_Host *shost, unsigned long time)
1438{
1439 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
1440
1441 if (!phba->host)
1442 return 1;
1443 if (time >= 30 * HZ)
1444 goto finished;
1445
1446 if (phba->hba_state != LPFC_HBA_READY)
1447 return 0;
1448 if (phba->num_disc_nodes || phba->fc_prli_sent)
1449 return 0;
1450 if ((phba->fc_map_cnt == 0) && (time < 2 * HZ))
1451 return 0;
1452 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE)
1453 return 0;
1454 if ((phba->hba_state > LPFC_LINK_DOWN) || (time < 15 * HZ))
1455 return 0;
1456
1457finished:
1458 if (phba->cfg_poll & DISABLE_FCP_RING_INT) {
1459 spin_lock_irq(shost->host_lock);
1460 lpfc_poll_start_timer(phba);
1461 spin_unlock_irq(shost->host_lock);
1462 }
1463
1464 /*
1465 * set fixed host attributes
1466 * Must done after lpfc_sli_hba_setup()
1467 */
1468
1469 fc_host_node_name(shost) = wwn_to_u64(phba->fc_nodename.u.wwn);
1470 fc_host_port_name(shost) = wwn_to_u64(phba->fc_portname.u.wwn);
1471 fc_host_supported_classes(shost) = FC_COS_CLASS3;
1472
1473 memset(fc_host_supported_fc4s(shost), 0,
1474 sizeof(fc_host_supported_fc4s(shost)));
1475 fc_host_supported_fc4s(shost)[2] = 1;
1476 fc_host_supported_fc4s(shost)[7] = 1;
1477
1478 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(shost));
1479
1480 fc_host_supported_speeds(shost) = 0;
1481 if (phba->lmt & LMT_10Gb)
1482 fc_host_supported_speeds(shost) |= FC_PORTSPEED_10GBIT;
1483 if (phba->lmt & LMT_4Gb)
1484 fc_host_supported_speeds(shost) |= FC_PORTSPEED_4GBIT;
1485 if (phba->lmt & LMT_2Gb)
1486 fc_host_supported_speeds(shost) |= FC_PORTSPEED_2GBIT;
1487 if (phba->lmt & LMT_1Gb)
1488 fc_host_supported_speeds(shost) |= FC_PORTSPEED_1GBIT;
1489
1490 fc_host_maxframe_size(shost) =
1491 ((((uint32_t) phba->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1492 (uint32_t) phba->fc_sparam.cmn.bbRcvSizeLsb);
1493
1494 /* This value is also unchanging */
1495 memset(fc_host_active_fc4s(shost), 0,
1496 sizeof(fc_host_active_fc4s(shost)));
1497 fc_host_active_fc4s(shost)[2] = 1;
1498 fc_host_active_fc4s(shost)[7] = 1;
1499
1500 spin_lock_irq(shost->host_lock);
1501 phba->fc_flag &= ~FC_LOADING;
1502 spin_unlock_irq(shost->host_lock);
1503
1504 return 1;
1505}
1410 1506
1411static int __devinit 1507static int __devinit
1412lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid) 1508lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
@@ -1445,9 +1541,6 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1445 goto out_put_host; 1541 goto out_put_host;
1446 1542
1447 host->unique_id = phba->brd_no; 1543 host->unique_id = phba->brd_no;
1448 INIT_LIST_HEAD(&phba->ctrspbuflist);
1449 INIT_LIST_HEAD(&phba->rnidrspbuflist);
1450 INIT_LIST_HEAD(&phba->freebufList);
1451 1544
1452 /* Initialize timers used by driver */ 1545 /* Initialize timers used by driver */
1453 init_timer(&phba->fc_estabtmo); 1546 init_timer(&phba->fc_estabtmo);
@@ -1482,16 +1575,7 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1482 host->max_lun = phba->cfg_max_luns; 1575 host->max_lun = phba->cfg_max_luns;
1483 host->this_id = -1; 1576 host->this_id = -1;
1484 1577
1485 /* Initialize all internally managed lists. */ 1578 INIT_LIST_HEAD(&phba->fc_nodes);
1486 INIT_LIST_HEAD(&phba->fc_nlpmap_list);
1487 INIT_LIST_HEAD(&phba->fc_nlpunmap_list);
1488 INIT_LIST_HEAD(&phba->fc_unused_list);
1489 INIT_LIST_HEAD(&phba->fc_plogi_list);
1490 INIT_LIST_HEAD(&phba->fc_adisc_list);
1491 INIT_LIST_HEAD(&phba->fc_reglogin_list);
1492 INIT_LIST_HEAD(&phba->fc_prli_list);
1493 INIT_LIST_HEAD(&phba->fc_npr_list);
1494
1495 1579
1496 pci_set_master(pdev); 1580 pci_set_master(pdev);
1497 retval = pci_set_mwi(pdev); 1581 retval = pci_set_mwi(pdev);
@@ -1609,13 +1693,6 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1609 1693
1610 host->transportt = lpfc_transport_template; 1694 host->transportt = lpfc_transport_template;
1611 pci_set_drvdata(pdev, host); 1695 pci_set_drvdata(pdev, host);
1612 error = scsi_add_host(host, &pdev->dev);
1613 if (error)
1614 goto out_kthread_stop;
1615
1616 error = lpfc_alloc_sysfs_attr(phba);
1617 if (error)
1618 goto out_remove_host;
1619 1696
1620 if (phba->cfg_use_msi) { 1697 if (phba->cfg_use_msi) {
1621 error = pci_enable_msi(phba->pcidev); 1698 error = pci_enable_msi(phba->pcidev);
@@ -1631,73 +1708,15 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
1631 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 1708 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1632 "%d:0451 Enable interrupt handler failed\n", 1709 "%d:0451 Enable interrupt handler failed\n",
1633 phba->brd_no); 1710 phba->brd_no);
1634 goto out_free_sysfs_attr; 1711 goto out_kthread_stop;
1635 } 1712 }
1636 phba->MBslimaddr = phba->slim_memmap_p;
1637 phba->HAregaddr = phba->ctrl_regs_memmap_p + HA_REG_OFFSET;
1638 phba->CAregaddr = phba->ctrl_regs_memmap_p + CA_REG_OFFSET;
1639 phba->HSregaddr = phba->ctrl_regs_memmap_p + HS_REG_OFFSET;
1640 phba->HCregaddr = phba->ctrl_regs_memmap_p + HC_REG_OFFSET;
1641 1713
1642 error = lpfc_sli_hba_setup(phba); 1714 error = scsi_add_host(host, &pdev->dev);
1643 if (error) { 1715 if (error)
1644 error = -ENODEV;
1645 goto out_free_irq; 1716 goto out_free_irq;
1646 }
1647
1648 /*
1649 * hba setup may have changed the hba_queue_depth so we need to adjust
1650 * the value of can_queue.
1651 */
1652 host->can_queue = phba->cfg_hba_queue_depth - 10;
1653
1654 lpfc_discovery_wait(phba);
1655 1717
1656 if (phba->cfg_poll & DISABLE_FCP_RING_INT) { 1718 scsi_scan_host(host);
1657 spin_lock_irq(phba->host->host_lock);
1658 lpfc_poll_start_timer(phba);
1659 spin_unlock_irq(phba->host->host_lock);
1660 }
1661 1719
1662 /*
1663 * set fixed host attributes
1664 * Must done after lpfc_sli_hba_setup()
1665 */
1666
1667 fc_host_node_name(host) = wwn_to_u64(phba->fc_nodename.u.wwn);
1668 fc_host_port_name(host) = wwn_to_u64(phba->fc_portname.u.wwn);
1669 fc_host_supported_classes(host) = FC_COS_CLASS3;
1670
1671 memset(fc_host_supported_fc4s(host), 0,
1672 sizeof(fc_host_supported_fc4s(host)));
1673 fc_host_supported_fc4s(host)[2] = 1;
1674 fc_host_supported_fc4s(host)[7] = 1;
1675
1676 lpfc_get_hba_sym_node_name(phba, fc_host_symbolic_name(host));
1677
1678 fc_host_supported_speeds(host) = 0;
1679 if (phba->lmt & LMT_10Gb)
1680 fc_host_supported_speeds(host) |= FC_PORTSPEED_10GBIT;
1681 if (phba->lmt & LMT_4Gb)
1682 fc_host_supported_speeds(host) |= FC_PORTSPEED_4GBIT;
1683 if (phba->lmt & LMT_2Gb)
1684 fc_host_supported_speeds(host) |= FC_PORTSPEED_2GBIT;
1685 if (phba->lmt & LMT_1Gb)
1686 fc_host_supported_speeds(host) |= FC_PORTSPEED_1GBIT;
1687
1688 fc_host_maxframe_size(host) =
1689 ((((uint32_t) phba->fc_sparam.cmn.bbRcvSizeMsb & 0x0F) << 8) |
1690 (uint32_t) phba->fc_sparam.cmn.bbRcvSizeLsb);
1691
1692 /* This value is also unchanging */
1693 memset(fc_host_active_fc4s(host), 0,
1694 sizeof(fc_host_active_fc4s(host)));
1695 fc_host_active_fc4s(host)[2] = 1;
1696 fc_host_active_fc4s(host)[7] = 1;
1697
1698 spin_lock_irq(phba->host->host_lock);
1699 phba->fc_flag &= ~FC_LOADING;
1700 spin_unlock_irq(phba->host->host_lock);
1701 return 0; 1720 return 0;
1702 1721
1703out_free_irq: 1722out_free_irq:
@@ -1705,11 +1724,6 @@ out_free_irq:
1705 phba->work_hba_events = 0; 1724 phba->work_hba_events = 0;
1706 free_irq(phba->pcidev->irq, phba); 1725 free_irq(phba->pcidev->irq, phba);
1707 pci_disable_msi(phba->pcidev); 1726 pci_disable_msi(phba->pcidev);
1708out_free_sysfs_attr:
1709 lpfc_free_sysfs_attr(phba);
1710out_remove_host:
1711 fc_remove_host(phba->host);
1712 scsi_remove_host(phba->host);
1713out_kthread_stop: 1727out_kthread_stop:
1714 kthread_stop(phba->worker_thread); 1728 kthread_stop(phba->worker_thread);
1715out_free_iocbq: 1729out_free_iocbq:
@@ -1747,56 +1761,8 @@ lpfc_pci_remove_one(struct pci_dev *pdev)
1747{ 1761{
1748 struct Scsi_Host *host = pci_get_drvdata(pdev); 1762 struct Scsi_Host *host = pci_get_drvdata(pdev);
1749 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata; 1763 struct lpfc_hba *phba = (struct lpfc_hba *)host->hostdata;
1750 unsigned long iflag;
1751
1752 lpfc_free_sysfs_attr(phba);
1753
1754 spin_lock_irqsave(phba->host->host_lock, iflag);
1755 phba->fc_flag |= FC_UNLOADING;
1756
1757 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1758 1764
1759 fc_remove_host(phba->host); 1765 lpfc_remove_device(phba);
1760 scsi_remove_host(phba->host);
1761
1762 kthread_stop(phba->worker_thread);
1763
1764 /*
1765 * Bring down the SLI Layer. This step disable all interrupts,
1766 * clears the rings, discards all mailbox commands, and resets
1767 * the HBA.
1768 */
1769 lpfc_sli_hba_down(phba);
1770 lpfc_sli_brdrestart(phba);
1771
1772 /* Release the irq reservation */
1773 free_irq(phba->pcidev->irq, phba);
1774 pci_disable_msi(phba->pcidev);
1775
1776 lpfc_cleanup(phba, 0);
1777 lpfc_stop_timer(phba);
1778 phba->work_hba_events = 0;
1779
1780 /*
1781 * Call scsi_free before mem_free since scsi bufs are released to their
1782 * corresponding pools here.
1783 */
1784 lpfc_scsi_free(phba);
1785 lpfc_mem_free(phba);
1786
1787 /* Free resources associated with SLI2 interface */
1788 dma_free_coherent(&pdev->dev, SLI2_SLIM_SIZE,
1789 phba->slim2p, phba->slim2p_mapping);
1790
1791 /* unmap adapter SLIM and Control Registers */
1792 iounmap(phba->ctrl_regs_memmap_p);
1793 iounmap(phba->slim_memmap_p);
1794
1795 pci_release_regions(phba->pcidev);
1796 pci_disable_device(phba->pcidev);
1797
1798 idr_remove(&lpfc_hba_index, phba->brd_no);
1799 scsi_host_put(phba->host);
1800 1766
1801 pci_set_drvdata(pdev, NULL); 1767 pci_set_drvdata(pdev, NULL);
1802} 1768}
@@ -1941,6 +1907,18 @@ static struct pci_device_id lpfc_id_table[] = {
1941 PCI_ANY_ID, PCI_ANY_ID, }, 1907 PCI_ANY_ID, PCI_ANY_ID, },
1942 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S, 1908 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_LPE11000S,
1943 PCI_ANY_ID, PCI_ANY_ID, }, 1909 PCI_ANY_ID, PCI_ANY_ID, },
1910 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT,
1911 PCI_ANY_ID, PCI_ANY_ID, },
1912 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_MID,
1913 PCI_ANY_ID, PCI_ANY_ID, },
1914 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SMB,
1915 PCI_ANY_ID, PCI_ANY_ID, },
1916 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_DCSP,
1917 PCI_ANY_ID, PCI_ANY_ID, },
1918 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_SCSP,
1919 PCI_ANY_ID, PCI_ANY_ID, },
1920 {PCI_VENDOR_ID_EMULEX, PCI_DEVICE_ID_SAT_S,
1921 PCI_ANY_ID, PCI_ANY_ID, },
1944 { 0 } 1922 { 0 }
1945}; 1923};
1946 1924
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index 4d016c2a1b26..8041c3f06f7b 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -212,6 +212,7 @@ lpfc_init_link(struct lpfc_hba * phba,
212 case LINK_SPEED_1G: 212 case LINK_SPEED_1G:
213 case LINK_SPEED_2G: 213 case LINK_SPEED_2G:
214 case LINK_SPEED_4G: 214 case LINK_SPEED_4G:
215 case LINK_SPEED_8G:
215 mb->un.varInitLnk.link_flags |= 216 mb->un.varInitLnk.link_flags |=
216 FLAGS_LINK_SPEED; 217 FLAGS_LINK_SPEED;
217 mb->un.varInitLnk.link_speed = linkspeed; 218 mb->un.varInitLnk.link_speed = linkspeed;
diff --git a/drivers/scsi/lpfc/lpfc_nportdisc.c b/drivers/scsi/lpfc/lpfc_nportdisc.c
index 0c7e731dc45a..b309841e3846 100644
--- a/drivers/scsi/lpfc/lpfc_nportdisc.c
+++ b/drivers/scsi/lpfc/lpfc_nportdisc.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -168,14 +168,13 @@ lpfc_check_elscmpl_iocb(struct lpfc_hba * phba,
168 * routine effectively results in a "software abort". 168 * routine effectively results in a "software abort".
169 */ 169 */
170int 170int
171lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, 171lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
172 int send_abts)
173{ 172{
173 LIST_HEAD(completions);
174 struct lpfc_sli *psli; 174 struct lpfc_sli *psli;
175 struct lpfc_sli_ring *pring; 175 struct lpfc_sli_ring *pring;
176 struct lpfc_iocbq *iocb, *next_iocb; 176 struct lpfc_iocbq *iocb, *next_iocb;
177 IOCB_t *icmd; 177 IOCB_t *cmd;
178 int found = 0;
179 178
180 /* Abort outstanding I/O on NPort <nlp_DID> */ 179 /* Abort outstanding I/O on NPort <nlp_DID> */
181 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY, 180 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
@@ -188,75 +187,39 @@ lpfc_els_abort(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
188 pring = &psli->ring[LPFC_ELS_RING]; 187 pring = &psli->ring[LPFC_ELS_RING];
189 188
190 /* First check the txq */ 189 /* First check the txq */
191 do { 190 spin_lock_irq(phba->host->host_lock);
192 found = 0; 191 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
193 spin_lock_irq(phba->host->host_lock); 192 /* Check to see if iocb matches the nport we are looking
194 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { 193 for */
195 /* Check to see if iocb matches the nport we are looking 194 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
196 for */ 195 /* It matches, so deque and call compl with an
197 if ((lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))) { 196 error */
198 found = 1; 197 list_move_tail(&iocb->list, &completions);
199 /* It matches, so deque and call compl with an 198 pring->txq_cnt--;
200 error */
201 list_del(&iocb->list);
202 pring->txq_cnt--;
203 if (iocb->iocb_cmpl) {
204 icmd = &iocb->iocb;
205 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
206 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
207 spin_unlock_irq(phba->host->host_lock);
208 (iocb->iocb_cmpl) (phba, iocb, iocb);
209 spin_lock_irq(phba->host->host_lock);
210 } else
211 lpfc_sli_release_iocbq(phba, iocb);
212 break;
213 }
214 } 199 }
215 spin_unlock_irq(phba->host->host_lock); 200 }
216 } while (found);
217 201
218 /* Everything on txcmplq will be returned by firmware
219 * with a no rpi / linkdown / abort error. For ring 0,
220 * ELS discovery, we want to get rid of it right here.
221 */
222 /* Next check the txcmplq */ 202 /* Next check the txcmplq */
223 do { 203 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
224 found = 0; 204 /* Check to see if iocb matches the nport we are looking
225 spin_lock_irq(phba->host->host_lock); 205 for */
226 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, 206 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp))
227 list) { 207 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
228 /* Check to see if iocb matches the nport we are looking 208 }
229 for */ 209 spin_unlock_irq(phba->host->host_lock);
230 if ((lpfc_check_sli_ndlp (phba, pring, iocb, ndlp))) { 210
231 found = 1; 211 while (!list_empty(&completions)) {
232 /* It matches, so deque and call compl with an 212 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
233 error */ 213 cmd = &iocb->iocb;
234 list_del(&iocb->list); 214 list_del(&iocb->list);
235 pring->txcmplq_cnt--; 215
236 216 if (iocb->iocb_cmpl) {
237 icmd = &iocb->iocb; 217 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
238 /* If the driver is completing an ELS 218 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
239 * command early, flush it out of the firmware. 219 (iocb->iocb_cmpl) (phba, iocb, iocb);
240 */ 220 } else
241 if (send_abts && 221 lpfc_sli_release_iocbq(phba, iocb);
242 (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) && 222 }
243 (icmd->un.elsreq64.bdl.ulpIoTag32)) {
244 lpfc_sli_issue_abort_iotag32(phba,
245 pring, iocb);
246 }
247 if (iocb->iocb_cmpl) {
248 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
249 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
250 spin_unlock_irq(phba->host->host_lock);
251 (iocb->iocb_cmpl) (phba, iocb, iocb);
252 spin_lock_irq(phba->host->host_lock);
253 } else
254 lpfc_sli_release_iocbq(phba, iocb);
255 break;
256 }
257 }
258 spin_unlock_irq(phba->host->host_lock);
259 } while(found);
260 223
261 /* If we are delaying issuing an ELS command, cancel it */ 224 /* If we are delaying issuing an ELS command, cancel it */
262 if (ndlp->nlp_flag & NLP_DELAY_TMO) 225 if (ndlp->nlp_flag & NLP_DELAY_TMO)
@@ -390,7 +353,10 @@ lpfc_rcv_plogi(struct lpfc_hba * phba,
390 * queue this mbox command to be processed later. 353 * queue this mbox command to be processed later.
391 */ 354 */
392 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login; 355 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
393 mbox->context2 = ndlp; 356 /*
357 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
358 * command issued in lpfc_cmpl_els_acc().
359 */
394 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI); 360 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
395 361
396 /* 362 /*
@@ -404,7 +370,7 @@ lpfc_rcv_plogi(struct lpfc_hba * phba,
404 */ 370 */
405 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) { 371 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
406 /* software abort outstanding PLOGI */ 372 /* software abort outstanding PLOGI */
407 lpfc_els_abort(phba, ndlp, 1); 373 lpfc_els_abort(phba, ndlp);
408 } 374 }
409 375
410 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0); 376 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox, 0);
@@ -471,8 +437,7 @@ lpfc_rcv_padisc(struct lpfc_hba * phba,
471 spin_unlock_irq(phba->host->host_lock); 437 spin_unlock_irq(phba->host->host_lock);
472 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; 438 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
473 ndlp->nlp_prev_state = ndlp->nlp_state; 439 ndlp->nlp_prev_state = ndlp->nlp_state;
474 ndlp->nlp_state = NLP_STE_NPR_NODE; 440 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
475 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
476 return 0; 441 return 0;
477} 442}
478 443
@@ -502,12 +467,10 @@ lpfc_rcv_logo(struct lpfc_hba * phba,
502 467
503 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; 468 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
504 ndlp->nlp_prev_state = ndlp->nlp_state; 469 ndlp->nlp_prev_state = ndlp->nlp_state;
505 ndlp->nlp_state = NLP_STE_NPR_NODE; 470 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
506 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
507 } else { 471 } else {
508 ndlp->nlp_prev_state = ndlp->nlp_state; 472 ndlp->nlp_prev_state = ndlp->nlp_state;
509 ndlp->nlp_state = NLP_STE_UNUSED_NODE; 473 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
510 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
511 } 474 }
512 475
513 spin_lock_irq(phba->host->host_lock); 476 spin_lock_irq(phba->host->host_lock);
@@ -601,11 +564,10 @@ lpfc_rcv_plogi_unused_node(struct lpfc_hba * phba,
601 564
602 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) { 565 if (lpfc_rcv_plogi(phba, ndlp, cmdiocb)) {
603 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; 566 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
604 ndlp->nlp_state = NLP_STE_UNUSED_NODE; 567 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
605 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
606 return ndlp->nlp_state; 568 return ndlp->nlp_state;
607 } 569 }
608 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 570 lpfc_drop_node(phba, ndlp);
609 return NLP_STE_FREED_NODE; 571 return NLP_STE_FREED_NODE;
610} 572}
611 573
@@ -614,7 +576,7 @@ lpfc_rcv_els_unused_node(struct lpfc_hba * phba,
614 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt) 576 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
615{ 577{
616 lpfc_issue_els_logo(phba, ndlp, 0); 578 lpfc_issue_els_logo(phba, ndlp, 0);
617 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST); 579 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
618 return ndlp->nlp_state; 580 return ndlp->nlp_state;
619} 581}
620 582
@@ -630,7 +592,7 @@ lpfc_rcv_logo_unused_node(struct lpfc_hba * phba,
630 ndlp->nlp_flag |= NLP_LOGO_ACC; 592 ndlp->nlp_flag |= NLP_LOGO_ACC;
631 spin_unlock_irq(phba->host->host_lock); 593 spin_unlock_irq(phba->host->host_lock);
632 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0); 594 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
633 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST); 595 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
634 596
635 return ndlp->nlp_state; 597 return ndlp->nlp_state;
636} 598}
@@ -639,7 +601,7 @@ static uint32_t
639lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba, 601lpfc_cmpl_logo_unused_node(struct lpfc_hba * phba,
640 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt) 602 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
641{ 603{
642 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 604 lpfc_drop_node(phba, ndlp);
643 return NLP_STE_FREED_NODE; 605 return NLP_STE_FREED_NODE;
644} 606}
645 607
@@ -647,7 +609,7 @@ static uint32_t
647lpfc_device_rm_unused_node(struct lpfc_hba * phba, 609lpfc_device_rm_unused_node(struct lpfc_hba * phba,
648 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt) 610 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
649{ 611{
650 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 612 lpfc_drop_node(phba, ndlp);
651 return NLP_STE_FREED_NODE; 613 return NLP_STE_FREED_NODE;
652} 614}
653 615
@@ -697,7 +659,7 @@ lpfc_rcv_logo_plogi_issue(struct lpfc_hba * phba,
697 cmdiocb = (struct lpfc_iocbq *) arg; 659 cmdiocb = (struct lpfc_iocbq *) arg;
698 660
699 /* software abort outstanding PLOGI */ 661 /* software abort outstanding PLOGI */
700 lpfc_els_abort(phba, ndlp, 1); 662 lpfc_els_abort(phba, ndlp);
701 663
702 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO); 664 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
703 return ndlp->nlp_state; 665 return ndlp->nlp_state;
@@ -712,7 +674,7 @@ lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
712 cmdiocb = (struct lpfc_iocbq *) arg; 674 cmdiocb = (struct lpfc_iocbq *) arg;
713 675
714 /* software abort outstanding PLOGI */ 676 /* software abort outstanding PLOGI */
715 lpfc_els_abort(phba, ndlp, 1); 677 lpfc_els_abort(phba, ndlp);
716 678
717 if (evt == NLP_EVT_RCV_LOGO) { 679 if (evt == NLP_EVT_RCV_LOGO) {
718 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0); 680 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
@@ -727,8 +689,7 @@ lpfc_rcv_els_plogi_issue(struct lpfc_hba * phba,
727 spin_unlock_irq(phba->host->host_lock); 689 spin_unlock_irq(phba->host->host_lock);
728 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI; 690 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
729 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE; 691 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
730 ndlp->nlp_state = NLP_STE_NPR_NODE; 692 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
731 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
732 693
733 return ndlp->nlp_state; 694 return ndlp->nlp_state;
734} 695}
@@ -803,32 +764,26 @@ lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
803 goto out; 764 goto out;
804 765
805 lpfc_unreg_rpi(phba, ndlp); 766 lpfc_unreg_rpi(phba, ndlp);
806 if (lpfc_reg_login 767 if (lpfc_reg_login(phba, irsp->un.elsreq64.remoteID, (uint8_t *) sp,
807 (phba, irsp->un.elsreq64.remoteID, 768 mbox, 0) == 0) {
808 (uint8_t *) sp, mbox, 0) == 0) {
809 switch (ndlp->nlp_DID) { 769 switch (ndlp->nlp_DID) {
810 case NameServer_DID: 770 case NameServer_DID:
811 mbox->mbox_cmpl = 771 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
812 lpfc_mbx_cmpl_ns_reg_login;
813 break; 772 break;
814 case FDMI_DID: 773 case FDMI_DID:
815 mbox->mbox_cmpl = 774 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
816 lpfc_mbx_cmpl_fdmi_reg_login;
817 break; 775 break;
818 default: 776 default:
819 mbox->mbox_cmpl = 777 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
820 lpfc_mbx_cmpl_reg_login;
821 } 778 }
822 mbox->context2 = ndlp; 779 mbox->context2 = lpfc_nlp_get(ndlp);
823 if (lpfc_sli_issue_mbox(phba, mbox, 780 if (lpfc_sli_issue_mbox(phba, mbox,
824 (MBX_NOWAIT | MBX_STOP_IOCB)) 781 (MBX_NOWAIT | MBX_STOP_IOCB))
825 != MBX_NOT_FINISHED) { 782 != MBX_NOT_FINISHED) {
826 ndlp->nlp_state = 783 lpfc_nlp_set_state(phba, ndlp, NLP_STE_REG_LOGIN_ISSUE);
827 NLP_STE_REG_LOGIN_ISSUE;
828 lpfc_nlp_list(phba, ndlp,
829 NLP_REGLOGIN_LIST);
830 return ndlp->nlp_state; 784 return ndlp->nlp_state;
831 } 785 }
786 lpfc_nlp_put(ndlp);
832 mp = (struct lpfc_dmabuf *)mbox->context1; 787 mp = (struct lpfc_dmabuf *)mbox->context1;
833 lpfc_mbuf_free(phba, mp->virt, mp->phys); 788 lpfc_mbuf_free(phba, mp->virt, mp->phys);
834 kfree(mp); 789 kfree(mp);
@@ -841,7 +796,7 @@ lpfc_cmpl_plogi_plogi_issue(struct lpfc_hba * phba,
841 out: 796 out:
842 /* Free this node since the driver cannot login or has the wrong 797 /* Free this node since the driver cannot login or has the wrong
843 sparm */ 798 sparm */
844 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 799 lpfc_drop_node(phba, ndlp);
845 return NLP_STE_FREED_NODE; 800 return NLP_STE_FREED_NODE;
846} 801}
847 802
@@ -855,9 +810,9 @@ lpfc_device_rm_plogi_issue(struct lpfc_hba * phba,
855 } 810 }
856 else { 811 else {
857 /* software abort outstanding PLOGI */ 812 /* software abort outstanding PLOGI */
858 lpfc_els_abort(phba, ndlp, 1); 813 lpfc_els_abort(phba, ndlp);
859 814
860 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 815 lpfc_drop_node(phba, ndlp);
861 return NLP_STE_FREED_NODE; 816 return NLP_STE_FREED_NODE;
862 } 817 }
863} 818}
@@ -868,11 +823,10 @@ lpfc_device_recov_plogi_issue(struct lpfc_hba * phba,
868 uint32_t evt) 823 uint32_t evt)
869{ 824{
870 /* software abort outstanding PLOGI */ 825 /* software abort outstanding PLOGI */
871 lpfc_els_abort(phba, ndlp, 1); 826 lpfc_els_abort(phba, ndlp);
872 827
873 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE; 828 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
874 ndlp->nlp_state = NLP_STE_NPR_NODE; 829 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
875 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
876 spin_lock_irq(phba->host->host_lock); 830 spin_lock_irq(phba->host->host_lock);
877 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); 831 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
878 spin_unlock_irq(phba->host->host_lock); 832 spin_unlock_irq(phba->host->host_lock);
@@ -888,7 +842,7 @@ lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
888 struct lpfc_iocbq *cmdiocb; 842 struct lpfc_iocbq *cmdiocb;
889 843
890 /* software abort outstanding ADISC */ 844 /* software abort outstanding ADISC */
891 lpfc_els_abort(phba, ndlp, 1); 845 lpfc_els_abort(phba, ndlp);
892 846
893 cmdiocb = (struct lpfc_iocbq *) arg; 847 cmdiocb = (struct lpfc_iocbq *) arg;
894 848
@@ -896,8 +850,7 @@ lpfc_rcv_plogi_adisc_issue(struct lpfc_hba * phba,
896 return ndlp->nlp_state; 850 return ndlp->nlp_state;
897 } 851 }
898 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; 852 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
899 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 853 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
900 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
901 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); 854 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
902 855
903 return ndlp->nlp_state; 856 return ndlp->nlp_state;
@@ -926,7 +879,7 @@ lpfc_rcv_logo_adisc_issue(struct lpfc_hba * phba,
926 cmdiocb = (struct lpfc_iocbq *) arg; 879 cmdiocb = (struct lpfc_iocbq *) arg;
927 880
928 /* software abort outstanding ADISC */ 881 /* software abort outstanding ADISC */
929 lpfc_els_abort(phba, ndlp, 0); 882 lpfc_els_abort(phba, ndlp);
930 883
931 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO); 884 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
932 return ndlp->nlp_state; 885 return ndlp->nlp_state;
@@ -987,20 +940,17 @@ lpfc_cmpl_adisc_adisc_issue(struct lpfc_hba * phba,
987 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name)); 940 memset(&ndlp->nlp_portname, 0, sizeof (struct lpfc_name));
988 941
989 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; 942 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
990 ndlp->nlp_state = NLP_STE_NPR_NODE; 943 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
991 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
992 lpfc_unreg_rpi(phba, ndlp); 944 lpfc_unreg_rpi(phba, ndlp);
993 return ndlp->nlp_state; 945 return ndlp->nlp_state;
994 } 946 }
995 947
996 if (ndlp->nlp_type & NLP_FCP_TARGET) { 948 if (ndlp->nlp_type & NLP_FCP_TARGET) {
997 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; 949 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
998 ndlp->nlp_state = NLP_STE_MAPPED_NODE; 950 lpfc_nlp_set_state(phba, ndlp, NLP_STE_MAPPED_NODE);
999 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
1000 } else { 951 } else {
1001 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; 952 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1002 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; 953 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1003 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1004 } 954 }
1005 return ndlp->nlp_state; 955 return ndlp->nlp_state;
1006} 956}
@@ -1016,9 +966,9 @@ lpfc_device_rm_adisc_issue(struct lpfc_hba * phba,
1016 } 966 }
1017 else { 967 else {
1018 /* software abort outstanding ADISC */ 968 /* software abort outstanding ADISC */
1019 lpfc_els_abort(phba, ndlp, 1); 969 lpfc_els_abort(phba, ndlp);
1020 970
1021 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 971 lpfc_drop_node(phba, ndlp);
1022 return NLP_STE_FREED_NODE; 972 return NLP_STE_FREED_NODE;
1023 } 973 }
1024} 974}
@@ -1029,11 +979,10 @@ lpfc_device_recov_adisc_issue(struct lpfc_hba * phba,
1029 uint32_t evt) 979 uint32_t evt)
1030{ 980{
1031 /* software abort outstanding ADISC */ 981 /* software abort outstanding ADISC */
1032 lpfc_els_abort(phba, ndlp, 1); 982 lpfc_els_abort(phba, ndlp);
1033 983
1034 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE; 984 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1035 ndlp->nlp_state = NLP_STE_NPR_NODE; 985 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1036 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1037 spin_lock_irq(phba->host->host_lock); 986 spin_lock_irq(phba->host->host_lock);
1038 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); 987 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1039 ndlp->nlp_flag |= NLP_NPR_ADISC; 988 ndlp->nlp_flag |= NLP_NPR_ADISC;
@@ -1074,9 +1023,36 @@ lpfc_rcv_logo_reglogin_issue(struct lpfc_hba * phba,
1074 uint32_t evt) 1023 uint32_t evt)
1075{ 1024{
1076 struct lpfc_iocbq *cmdiocb; 1025 struct lpfc_iocbq *cmdiocb;
1026 LPFC_MBOXQ_t *mb;
1027 LPFC_MBOXQ_t *nextmb;
1028 struct lpfc_dmabuf *mp;
1077 1029
1078 cmdiocb = (struct lpfc_iocbq *) arg; 1030 cmdiocb = (struct lpfc_iocbq *) arg;
1079 1031
1032 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1033 if ((mb = phba->sli.mbox_active)) {
1034 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1035 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1036 mb->context2 = NULL;
1037 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1038 }
1039 }
1040
1041 spin_lock_irq(phba->host->host_lock);
1042 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1043 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1044 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1045 mp = (struct lpfc_dmabuf *) (mb->context1);
1046 if (mp) {
1047 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1048 kfree(mp);
1049 }
1050 list_del(&mb->list);
1051 mempool_free(mb, phba->mbox_mem_pool);
1052 }
1053 }
1054 spin_unlock_irq(phba->host->host_lock);
1055
1080 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO); 1056 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
1081 return ndlp->nlp_state; 1057 return ndlp->nlp_state;
1082} 1058}
@@ -1133,8 +1109,7 @@ lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1133 */ 1109 */
1134 if (mb->mbxStatus == MBXERR_RPI_FULL) { 1110 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1135 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE; 1111 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
1136 ndlp->nlp_state = NLP_STE_UNUSED_NODE; 1112 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
1137 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
1138 return ndlp->nlp_state; 1113 return ndlp->nlp_state;
1139 } 1114 }
1140 1115
@@ -1147,8 +1122,7 @@ lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1147 1122
1148 lpfc_issue_els_logo(phba, ndlp, 0); 1123 lpfc_issue_els_logo(phba, ndlp, 0);
1149 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; 1124 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1150 ndlp->nlp_state = NLP_STE_NPR_NODE; 1125 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1151 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1152 return ndlp->nlp_state; 1126 return ndlp->nlp_state;
1153 } 1127 }
1154 1128
@@ -1157,13 +1131,11 @@ lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_hba * phba,
1157 /* Only if we are not a fabric nport do we issue PRLI */ 1131 /* Only if we are not a fabric nport do we issue PRLI */
1158 if (!(ndlp->nlp_type & NLP_FABRIC)) { 1132 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1159 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; 1133 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1160 ndlp->nlp_state = NLP_STE_PRLI_ISSUE; 1134 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE);
1161 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1162 lpfc_issue_els_prli(phba, ndlp, 0); 1135 lpfc_issue_els_prli(phba, ndlp, 0);
1163 } else { 1136 } else {
1164 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; 1137 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1165 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; 1138 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1166 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1167 } 1139 }
1168 return ndlp->nlp_state; 1140 return ndlp->nlp_state;
1169} 1141}
@@ -1178,7 +1150,7 @@ lpfc_device_rm_reglogin_issue(struct lpfc_hba * phba,
1178 return ndlp->nlp_state; 1150 return ndlp->nlp_state;
1179 } 1151 }
1180 else { 1152 else {
1181 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1153 lpfc_drop_node(phba, ndlp);
1182 return NLP_STE_FREED_NODE; 1154 return NLP_STE_FREED_NODE;
1183 } 1155 }
1184} 1156}
@@ -1189,8 +1161,7 @@ lpfc_device_recov_reglogin_issue(struct lpfc_hba * phba,
1189 uint32_t evt) 1161 uint32_t evt)
1190{ 1162{
1191 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE; 1163 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1192 ndlp->nlp_state = NLP_STE_NPR_NODE; 1164 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1193 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1194 spin_lock_irq(phba->host->host_lock); 1165 spin_lock_irq(phba->host->host_lock);
1195 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); 1166 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1196 spin_unlock_irq(phba->host->host_lock); 1167 spin_unlock_irq(phba->host->host_lock);
@@ -1230,7 +1201,7 @@ lpfc_rcv_logo_prli_issue(struct lpfc_hba * phba,
1230 cmdiocb = (struct lpfc_iocbq *) arg; 1201 cmdiocb = (struct lpfc_iocbq *) arg;
1231 1202
1232 /* Software abort outstanding PRLI before sending acc */ 1203 /* Software abort outstanding PRLI before sending acc */
1233 lpfc_els_abort(phba, ndlp, 1); 1204 lpfc_els_abort(phba, ndlp);
1234 1205
1235 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO); 1206 lpfc_rcv_logo(phba, ndlp, cmdiocb, ELS_CMD_LOGO);
1236 return ndlp->nlp_state; 1207 return ndlp->nlp_state;
@@ -1279,8 +1250,7 @@ lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1279 irsp = &rspiocb->iocb; 1250 irsp = &rspiocb->iocb;
1280 if (irsp->ulpStatus) { 1251 if (irsp->ulpStatus) {
1281 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; 1252 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1282 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE; 1253 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNMAPPED_NODE);
1283 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1284 return ndlp->nlp_state; 1254 return ndlp->nlp_state;
1285 } 1255 }
1286 1256
@@ -1298,8 +1268,7 @@ lpfc_cmpl_prli_prli_issue(struct lpfc_hba * phba,
1298 } 1268 }
1299 1269
1300 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; 1270 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1301 ndlp->nlp_state = NLP_STE_MAPPED_NODE; 1271 lpfc_nlp_set_state(phba, ndlp, NLP_STE_MAPPED_NODE);
1302 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
1303 return ndlp->nlp_state; 1272 return ndlp->nlp_state;
1304} 1273}
1305 1274
@@ -1330,9 +1299,9 @@ lpfc_device_rm_prli_issue(struct lpfc_hba * phba,
1330 } 1299 }
1331 else { 1300 else {
1332 /* software abort outstanding PLOGI */ 1301 /* software abort outstanding PLOGI */
1333 lpfc_els_abort(phba, ndlp, 1); 1302 lpfc_els_abort(phba, ndlp);
1334 1303
1335 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1304 lpfc_drop_node(phba, ndlp);
1336 return NLP_STE_FREED_NODE; 1305 return NLP_STE_FREED_NODE;
1337 } 1306 }
1338} 1307}
@@ -1359,11 +1328,10 @@ lpfc_device_recov_prli_issue(struct lpfc_hba * phba,
1359 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt) 1328 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1360{ 1329{
1361 /* software abort outstanding PRLI */ 1330 /* software abort outstanding PRLI */
1362 lpfc_els_abort(phba, ndlp, 1); 1331 lpfc_els_abort(phba, ndlp);
1363 1332
1364 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE; 1333 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1365 ndlp->nlp_state = NLP_STE_NPR_NODE; 1334 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1366 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1367 spin_lock_irq(phba->host->host_lock); 1335 spin_lock_irq(phba->host->host_lock);
1368 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); 1336 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1369 spin_unlock_irq(phba->host->host_lock); 1337 spin_unlock_irq(phba->host->host_lock);
@@ -1436,8 +1404,7 @@ lpfc_device_recov_unmap_node(struct lpfc_hba * phba,
1436 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt) 1404 struct lpfc_nodelist * ndlp, void *arg, uint32_t evt)
1437{ 1405{
1438 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE; 1406 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1439 ndlp->nlp_state = NLP_STE_NPR_NODE; 1407 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1440 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1441 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); 1408 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1442 lpfc_disc_set_adisc(phba, ndlp); 1409 lpfc_disc_set_adisc(phba, ndlp);
1443 1410
@@ -1518,8 +1485,7 @@ lpfc_device_recov_mapped_node(struct lpfc_hba * phba,
1518 uint32_t evt) 1485 uint32_t evt)
1519{ 1486{
1520 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE; 1487 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1521 ndlp->nlp_state = NLP_STE_NPR_NODE; 1488 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
1522 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1523 spin_lock_irq(phba->host->host_lock); 1489 spin_lock_irq(phba->host->host_lock);
1524 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC); 1490 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1525 spin_unlock_irq(phba->host->host_lock); 1491 spin_unlock_irq(phba->host->host_lock);
@@ -1551,8 +1517,7 @@ lpfc_rcv_plogi_npr_node(struct lpfc_hba * phba,
1551 /* send PLOGI immediately, move to PLOGI issue state */ 1517 /* send PLOGI immediately, move to PLOGI issue state */
1552 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) { 1518 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1553 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 1519 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1554 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 1520 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
1555 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1556 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); 1521 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
1557 } 1522 }
1558 1523
@@ -1580,16 +1545,13 @@ lpfc_rcv_prli_npr_node(struct lpfc_hba * phba,
1580 ndlp->nlp_flag &= ~NLP_NPR_ADISC; 1545 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1581 spin_unlock_irq(phba->host->host_lock); 1546 spin_unlock_irq(phba->host->host_lock);
1582 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 1547 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1583 ndlp->nlp_state = NLP_STE_ADISC_ISSUE; 1548 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
1584 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1585 lpfc_issue_els_adisc(phba, ndlp, 0); 1549 lpfc_issue_els_adisc(phba, ndlp, 0);
1586 } else { 1550 } else {
1587 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 1551 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1588 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 1552 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
1589 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1590 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); 1553 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
1591 } 1554 }
1592
1593 } 1555 }
1594 return ndlp->nlp_state; 1556 return ndlp->nlp_state;
1595} 1557}
@@ -1627,13 +1589,11 @@ lpfc_rcv_padisc_npr_node(struct lpfc_hba * phba,
1627 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)){ 1589 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)){
1628 if (ndlp->nlp_flag & NLP_NPR_ADISC) { 1590 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1629 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 1591 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1630 ndlp->nlp_state = NLP_STE_ADISC_ISSUE; 1592 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
1631 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1632 lpfc_issue_els_adisc(phba, ndlp, 0); 1593 lpfc_issue_els_adisc(phba, ndlp, 0);
1633 } else { 1594 } else {
1634 ndlp->nlp_prev_state = NLP_STE_NPR_NODE; 1595 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1635 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE; 1596 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
1636 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1637 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0); 1597 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
1638 } 1598 }
1639 } 1599 }
@@ -1682,7 +1642,7 @@ lpfc_cmpl_plogi_npr_node(struct lpfc_hba * phba,
1682 1642
1683 irsp = &rspiocb->iocb; 1643 irsp = &rspiocb->iocb;
1684 if (irsp->ulpStatus) { 1644 if (irsp->ulpStatus) {
1685 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1645 lpfc_drop_node(phba, ndlp);
1686 return NLP_STE_FREED_NODE; 1646 return NLP_STE_FREED_NODE;
1687 } 1647 }
1688 return ndlp->nlp_state; 1648 return ndlp->nlp_state;
@@ -1700,7 +1660,7 @@ lpfc_cmpl_prli_npr_node(struct lpfc_hba * phba,
1700 1660
1701 irsp = &rspiocb->iocb; 1661 irsp = &rspiocb->iocb;
1702 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) { 1662 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1703 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1663 lpfc_drop_node(phba, ndlp);
1704 return NLP_STE_FREED_NODE; 1664 return NLP_STE_FREED_NODE;
1705 } 1665 }
1706 return ndlp->nlp_state; 1666 return ndlp->nlp_state;
@@ -1728,7 +1688,7 @@ lpfc_cmpl_adisc_npr_node(struct lpfc_hba * phba,
1728 1688
1729 irsp = &rspiocb->iocb; 1689 irsp = &rspiocb->iocb;
1730 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) { 1690 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1731 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1691 lpfc_drop_node(phba, ndlp);
1732 return NLP_STE_FREED_NODE; 1692 return NLP_STE_FREED_NODE;
1733 } 1693 }
1734 return ndlp->nlp_state; 1694 return ndlp->nlp_state;
@@ -1749,7 +1709,7 @@ lpfc_cmpl_reglogin_npr_node(struct lpfc_hba * phba,
1749 ndlp->nlp_rpi = mb->un.varWords[0]; 1709 ndlp->nlp_rpi = mb->un.varWords[0];
1750 else { 1710 else {
1751 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) { 1711 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
1752 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1712 lpfc_drop_node(phba, ndlp);
1753 return NLP_STE_FREED_NODE; 1713 return NLP_STE_FREED_NODE;
1754 } 1714 }
1755 } 1715 }
@@ -1765,7 +1725,7 @@ lpfc_device_rm_npr_node(struct lpfc_hba * phba,
1765 ndlp->nlp_flag |= NLP_NODEV_REMOVE; 1725 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1766 return ndlp->nlp_state; 1726 return ndlp->nlp_state;
1767 } 1727 }
1768 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST); 1728 lpfc_drop_node(phba, ndlp);
1769 return NLP_STE_FREED_NODE; 1729 return NLP_STE_FREED_NODE;
1770} 1730}
1771 1731
@@ -1964,7 +1924,7 @@ lpfc_disc_state_machine(struct lpfc_hba * phba,
1964 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *, 1924 uint32_t(*func) (struct lpfc_hba *, struct lpfc_nodelist *, void *,
1965 uint32_t); 1925 uint32_t);
1966 1926
1967 ndlp->nlp_disc_refcnt++; 1927 lpfc_nlp_get(ndlp);
1968 cur_state = ndlp->nlp_state; 1928 cur_state = ndlp->nlp_state;
1969 1929
1970 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */ 1930 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
@@ -1987,18 +1947,7 @@ lpfc_disc_state_machine(struct lpfc_hba * phba,
1987 phba->brd_no, 1947 phba->brd_no,
1988 rc, ndlp->nlp_DID, ndlp->nlp_flag); 1948 rc, ndlp->nlp_DID, ndlp->nlp_flag);
1989 1949
1990 ndlp->nlp_disc_refcnt--; 1950 lpfc_nlp_put(ndlp);
1991 1951
1992 /* Check to see if ndlp removal is deferred */
1993 if ((ndlp->nlp_disc_refcnt == 0)
1994 && (ndlp->nlp_flag & NLP_DELAY_REMOVE)) {
1995 spin_lock_irq(phba->host->host_lock);
1996 ndlp->nlp_flag &= ~NLP_DELAY_REMOVE;
1997 spin_unlock_irq(phba->host->host_lock);
1998 lpfc_nlp_remove(phba, ndlp);
1999 return NLP_STE_FREED_NODE;
2000 }
2001 if (rc == NLP_STE_FREED_NODE)
2002 return NLP_STE_FREED_NODE;
2003 return rc; 1952 return rc;
2004} 1953}
diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
index c3e68e0d8f74..9a12d05e99e4 100644
--- a/drivers/scsi/lpfc/lpfc_scsi.c
+++ b/drivers/scsi/lpfc/lpfc_scsi.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -146,6 +146,10 @@ lpfc_get_scsi_buf(struct lpfc_hba * phba)
146 146
147 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag); 147 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
148 list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list); 148 list_remove_head(scsi_buf_list, lpfc_cmd, struct lpfc_scsi_buf, list);
149 if (lpfc_cmd) {
150 lpfc_cmd->seg_cnt = 0;
151 lpfc_cmd->nonsg_phys = 0;
152 }
149 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag); 153 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
150 return lpfc_cmd; 154 return lpfc_cmd;
151} 155}
@@ -288,13 +292,13 @@ lpfc_scsi_unprep_dma_buf(struct lpfc_hba * phba, struct lpfc_scsi_buf * psb)
288} 292}
289 293
290static void 294static void
291lpfc_handle_fcp_err(struct lpfc_scsi_buf *lpfc_cmd) 295lpfc_handle_fcp_err(struct lpfc_scsi_buf *lpfc_cmd, struct lpfc_iocbq *rsp_iocb)
292{ 296{
293 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd; 297 struct scsi_cmnd *cmnd = lpfc_cmd->pCmd;
294 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd; 298 struct fcp_cmnd *fcpcmd = lpfc_cmd->fcp_cmnd;
295 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp; 299 struct fcp_rsp *fcprsp = lpfc_cmd->fcp_rsp;
296 struct lpfc_hba *phba = lpfc_cmd->scsi_hba; 300 struct lpfc_hba *phba = lpfc_cmd->scsi_hba;
297 uint32_t fcpi_parm = lpfc_cmd->cur_iocbq.iocb.un.fcpi.fcpi_parm; 301 uint32_t fcpi_parm = rsp_iocb->iocb.un.fcpi.fcpi_parm;
298 uint32_t resp_info = fcprsp->rspStatus2; 302 uint32_t resp_info = fcprsp->rspStatus2;
299 uint32_t scsi_status = fcprsp->rspStatus3; 303 uint32_t scsi_status = fcprsp->rspStatus3;
300 uint32_t *lp; 304 uint32_t *lp;
@@ -356,6 +360,24 @@ lpfc_handle_fcp_err(struct lpfc_scsi_buf *lpfc_cmd)
356 fcpi_parm, cmnd->cmnd[0], cmnd->underflow); 360 fcpi_parm, cmnd->cmnd[0], cmnd->underflow);
357 361
358 /* 362 /*
363 * If there is an under run check if under run reported by
364 * storage array is same as the under run reported by HBA.
365 * If this is not same, there is a dropped frame.
366 */
367 if ((cmnd->sc_data_direction == DMA_FROM_DEVICE) &&
368 fcpi_parm &&
369 (cmnd->resid != fcpi_parm)) {
370 lpfc_printf_log(phba, KERN_WARNING,
371 LOG_FCP | LOG_FCP_ERROR,
372 "%d:0735 FCP Read Check Error and Underrun "
373 "Data: x%x x%x x%x x%x\n", phba->brd_no,
374 be32_to_cpu(fcpcmd->fcpDl),
375 cmnd->resid,
376 fcpi_parm, cmnd->cmnd[0]);
377 cmnd->resid = cmnd->request_bufflen;
378 host_status = DID_ERROR;
379 }
380 /*
359 * The cmnd->underflow is the minimum number of bytes that must 381 * The cmnd->underflow is the minimum number of bytes that must
360 * be transfered for this command. Provided a sense condition 382 * be transfered for this command. Provided a sense condition
361 * is not present, make sure the actual amount transferred is at 383 * is not present, make sure the actual amount transferred is at
@@ -435,7 +457,7 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
435 switch (lpfc_cmd->status) { 457 switch (lpfc_cmd->status) {
436 case IOSTAT_FCP_RSP_ERROR: 458 case IOSTAT_FCP_RSP_ERROR:
437 /* Call FCP RSP handler to determine result */ 459 /* Call FCP RSP handler to determine result */
438 lpfc_handle_fcp_err(lpfc_cmd); 460 lpfc_handle_fcp_err(lpfc_cmd,pIocbOut);
439 break; 461 break;
440 case IOSTAT_NPORT_BSY: 462 case IOSTAT_NPORT_BSY:
441 case IOSTAT_FABRIC_BSY: 463 case IOSTAT_FABRIC_BSY:
@@ -466,10 +488,10 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
466 488
467 result = cmd->result; 489 result = cmd->result;
468 sdev = cmd->device; 490 sdev = cmd->device;
491 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
469 cmd->scsi_done(cmd); 492 cmd->scsi_done(cmd);
470 493
471 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) { 494 if (phba->cfg_poll & ENABLE_FCP_RING_POLLING) {
472 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
473 lpfc_release_scsi_buf(phba, lpfc_cmd); 495 lpfc_release_scsi_buf(phba, lpfc_cmd);
474 return; 496 return;
475 } 497 }
@@ -527,7 +549,6 @@ lpfc_scsi_cmd_iocb_cmpl(struct lpfc_hba *phba, struct lpfc_iocbq *pIocbIn,
527 } 549 }
528 } 550 }
529 551
530 lpfc_scsi_unprep_dma_buf(phba, lpfc_cmd);
531 lpfc_release_scsi_buf(phba, lpfc_cmd); 552 lpfc_release_scsi_buf(phba, lpfc_cmd);
532} 553}
533 554
@@ -670,6 +691,18 @@ lpfc_scsi_prep_task_mgmt_cmd(struct lpfc_hba *phba,
670 return (1); 691 return (1);
671} 692}
672 693
694static void
695lpfc_tskmgmt_def_cmpl(struct lpfc_hba *phba,
696 struct lpfc_iocbq *cmdiocbq,
697 struct lpfc_iocbq *rspiocbq)
698{
699 struct lpfc_scsi_buf *lpfc_cmd =
700 (struct lpfc_scsi_buf *) cmdiocbq->context1;
701 if (lpfc_cmd)
702 lpfc_release_scsi_buf(phba, lpfc_cmd);
703 return;
704}
705
673static int 706static int
674lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba, 707lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba,
675 unsigned tgt_id, unsigned int lun, 708 unsigned tgt_id, unsigned int lun,
@@ -706,8 +739,9 @@ lpfc_scsi_tgt_reset(struct lpfc_scsi_buf * lpfc_cmd, struct lpfc_hba * phba,
706 &phba->sli.ring[phba->sli.fcp_ring], 739 &phba->sli.ring[phba->sli.fcp_ring],
707 iocbq, iocbqrsp, lpfc_cmd->timeout); 740 iocbq, iocbqrsp, lpfc_cmd->timeout);
708 if (ret != IOCB_SUCCESS) { 741 if (ret != IOCB_SUCCESS) {
742 if (ret == IOCB_TIMEDOUT)
743 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
709 lpfc_cmd->status = IOSTAT_DRIVER_REJECT; 744 lpfc_cmd->status = IOSTAT_DRIVER_REJECT;
710 ret = FAILED;
711 } else { 745 } else {
712 ret = SUCCESS; 746 ret = SUCCESS;
713 lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4]; 747 lpfc_cmd->result = iocbqrsp->iocb.un.ulpWord[4];
@@ -974,7 +1008,7 @@ lpfc_abort_handler(struct scsi_cmnd *cmnd)
974} 1008}
975 1009
976static int 1010static int
977lpfc_reset_lun_handler(struct scsi_cmnd *cmnd) 1011lpfc_device_reset_handler(struct scsi_cmnd *cmnd)
978{ 1012{
979 struct Scsi_Host *shost = cmnd->device->host; 1013 struct Scsi_Host *shost = cmnd->device->host;
980 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1014 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
@@ -984,6 +1018,7 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
984 struct lpfc_nodelist *pnode = rdata->pnode; 1018 struct lpfc_nodelist *pnode = rdata->pnode;
985 uint32_t cmd_result = 0, cmd_status = 0; 1019 uint32_t cmd_result = 0, cmd_status = 0;
986 int ret = FAILED; 1020 int ret = FAILED;
1021 int iocb_status = IOCB_SUCCESS;
987 int cnt, loopcnt; 1022 int cnt, loopcnt;
988 1023
989 lpfc_block_error_handler(cmnd); 1024 lpfc_block_error_handler(cmnd);
@@ -995,7 +1030,7 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
995 */ 1030 */
996 while ( 1 ) { 1031 while ( 1 ) {
997 if (!pnode) 1032 if (!pnode)
998 return FAILED; 1033 goto out;
999 1034
1000 if (pnode->nlp_state != NLP_STE_MAPPED_NODE) { 1035 if (pnode->nlp_state != NLP_STE_MAPPED_NODE) {
1001 spin_unlock_irq(phba->host->host_lock); 1036 spin_unlock_irq(phba->host->host_lock);
@@ -1013,7 +1048,7 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
1013 } 1048 }
1014 pnode = rdata->pnode; 1049 pnode = rdata->pnode;
1015 if (!pnode) 1050 if (!pnode)
1016 return FAILED; 1051 goto out;
1017 } 1052 }
1018 if (pnode->nlp_state == NLP_STE_MAPPED_NODE) 1053 if (pnode->nlp_state == NLP_STE_MAPPED_NODE)
1019 break; 1054 break;
@@ -1028,7 +1063,7 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
1028 lpfc_cmd->rdata = rdata; 1063 lpfc_cmd->rdata = rdata;
1029 1064
1030 ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, cmnd->device->lun, 1065 ret = lpfc_scsi_prep_task_mgmt_cmd(phba, lpfc_cmd, cmnd->device->lun,
1031 FCP_LUN_RESET); 1066 FCP_TARGET_RESET);
1032 if (!ret) 1067 if (!ret)
1033 goto out_free_scsi_buf; 1068 goto out_free_scsi_buf;
1034 1069
@@ -1040,16 +1075,21 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
1040 goto out_free_scsi_buf; 1075 goto out_free_scsi_buf;
1041 1076
1042 lpfc_printf_log(phba, KERN_INFO, LOG_FCP, 1077 lpfc_printf_log(phba, KERN_INFO, LOG_FCP,
1043 "%d:0703 Issue LUN Reset to TGT %d LUN %d " 1078 "%d:0703 Issue target reset to TGT %d LUN %d rpi x%x "
1044 "Data: x%x x%x\n", phba->brd_no, cmnd->device->id, 1079 "nlp_flag x%x\n", phba->brd_no, cmnd->device->id,
1045 cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag); 1080 cmnd->device->lun, pnode->nlp_rpi, pnode->nlp_flag);
1046 1081
1047 ret = lpfc_sli_issue_iocb_wait(phba, 1082 iocb_status = lpfc_sli_issue_iocb_wait(phba,
1048 &phba->sli.ring[phba->sli.fcp_ring], 1083 &phba->sli.ring[phba->sli.fcp_ring],
1049 iocbq, iocbqrsp, lpfc_cmd->timeout); 1084 iocbq, iocbqrsp, lpfc_cmd->timeout);
1050 if (ret == IOCB_SUCCESS)
1051 ret = SUCCESS;
1052 1085
1086 if (iocb_status == IOCB_TIMEDOUT)
1087 iocbq->iocb_cmpl = lpfc_tskmgmt_def_cmpl;
1088
1089 if (iocb_status == IOCB_SUCCESS)
1090 ret = SUCCESS;
1091 else
1092 ret = iocb_status;
1053 1093
1054 cmd_result = iocbqrsp->iocb.un.ulpWord[4]; 1094 cmd_result = iocbqrsp->iocb.un.ulpWord[4];
1055 cmd_status = iocbqrsp->iocb.ulpStatus; 1095 cmd_status = iocbqrsp->iocb.ulpStatus;
@@ -1087,18 +1127,19 @@ lpfc_reset_lun_handler(struct scsi_cmnd *cmnd)
1087 1127
1088 if (cnt) { 1128 if (cnt) {
1089 lpfc_printf_log(phba, KERN_ERR, LOG_FCP, 1129 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1090 "%d:0719 LUN Reset I/O flush failure: cnt x%x\n", 1130 "%d:0719 device reset I/O flush failure: cnt x%x\n",
1091 phba->brd_no, cnt); 1131 phba->brd_no, cnt);
1092 ret = FAILED; 1132 ret = FAILED;
1093 } 1133 }
1094 1134
1095out_free_scsi_buf: 1135out_free_scsi_buf:
1096 lpfc_release_scsi_buf(phba, lpfc_cmd); 1136 if (iocb_status != IOCB_TIMEDOUT) {
1097 1137 lpfc_release_scsi_buf(phba, lpfc_cmd);
1138 }
1098 lpfc_printf_log(phba, KERN_ERR, LOG_FCP, 1139 lpfc_printf_log(phba, KERN_ERR, LOG_FCP,
1099 "%d:0713 SCSI layer issued LUN reset (%d, %d) " 1140 "%d:0713 SCSI layer issued device reset (%d, %d) "
1100 "Data: x%x x%x x%x\n", 1141 "return x%x status x%x result x%x\n",
1101 phba->brd_no, cmnd->device->id,cmnd->device->lun, 1142 phba->brd_no, cmnd->device->id, cmnd->device->lun,
1102 ret, cmd_status, cmd_result); 1143 ret, cmd_status, cmd_result);
1103 1144
1104out: 1145out:
@@ -1107,7 +1148,7 @@ out:
1107} 1148}
1108 1149
1109static int 1150static int
1110lpfc_reset_bus_handler(struct scsi_cmnd *cmnd) 1151lpfc_bus_reset_handler(struct scsi_cmnd *cmnd)
1111{ 1152{
1112 struct Scsi_Host *shost = cmnd->device->host; 1153 struct Scsi_Host *shost = cmnd->device->host;
1113 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata; 1154 struct lpfc_hba *phba = (struct lpfc_hba *)shost->hostdata;
@@ -1134,10 +1175,12 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
1134 * fail, this routine returns failure to the midlayer. 1175 * fail, this routine returns failure to the midlayer.
1135 */ 1176 */
1136 for (i = 0; i < LPFC_MAX_TARGET; i++) { 1177 for (i = 0; i < LPFC_MAX_TARGET; i++) {
1137 /* Search the mapped list for this target ID */ 1178 /* Search for mapped node by target ID */
1138 match = 0; 1179 match = 0;
1139 list_for_each_entry(ndlp, &phba->fc_nlpmap_list, nlp_listp) { 1180 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
1140 if ((i == ndlp->nlp_sid) && ndlp->rport) { 1181 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE &&
1182 i == ndlp->nlp_sid &&
1183 ndlp->rport) {
1141 match = 1; 1184 match = 1;
1142 break; 1185 break;
1143 } 1186 }
@@ -1152,13 +1195,17 @@ lpfc_reset_bus_handler(struct scsi_cmnd *cmnd)
1152 "%d:0700 Bus Reset on target %d failed\n", 1195 "%d:0700 Bus Reset on target %d failed\n",
1153 phba->brd_no, i); 1196 phba->brd_no, i);
1154 err_count++; 1197 err_count++;
1198 break;
1155 } 1199 }
1156 } 1200 }
1157 1201
1202 if (ret != IOCB_TIMEDOUT)
1203 lpfc_release_scsi_buf(phba, lpfc_cmd);
1204
1158 if (err_count == 0) 1205 if (err_count == 0)
1159 ret = SUCCESS; 1206 ret = SUCCESS;
1160 1207 else
1161 lpfc_release_scsi_buf(phba, lpfc_cmd); 1208 ret = FAILED;
1162 1209
1163 /* 1210 /*
1164 * All outstanding txcmplq I/Os should have been aborted by 1211 * All outstanding txcmplq I/Os should have been aborted by
@@ -1299,11 +1346,13 @@ struct scsi_host_template lpfc_template = {
1299 .info = lpfc_info, 1346 .info = lpfc_info,
1300 .queuecommand = lpfc_queuecommand, 1347 .queuecommand = lpfc_queuecommand,
1301 .eh_abort_handler = lpfc_abort_handler, 1348 .eh_abort_handler = lpfc_abort_handler,
1302 .eh_device_reset_handler= lpfc_reset_lun_handler, 1349 .eh_device_reset_handler= lpfc_device_reset_handler,
1303 .eh_bus_reset_handler = lpfc_reset_bus_handler, 1350 .eh_bus_reset_handler = lpfc_bus_reset_handler,
1304 .slave_alloc = lpfc_slave_alloc, 1351 .slave_alloc = lpfc_slave_alloc,
1305 .slave_configure = lpfc_slave_configure, 1352 .slave_configure = lpfc_slave_configure,
1306 .slave_destroy = lpfc_slave_destroy, 1353 .slave_destroy = lpfc_slave_destroy,
1354 .scan_finished = lpfc_scan_finished,
1355 .scan_start = lpfc_scan_start,
1307 .this_id = -1, 1356 .this_id = -1,
1308 .sg_tablesize = LPFC_SG_SEG_CNT, 1357 .sg_tablesize = LPFC_SG_SEG_CNT,
1309 .cmd_per_lun = LPFC_CMD_PER_LUN, 1358 .cmd_per_lun = LPFC_CMD_PER_LUN,
diff --git a/drivers/scsi/lpfc/lpfc_sli.c b/drivers/scsi/lpfc/lpfc_sli.c
index 9fb6960a8ada..a1e721459e2b 100644
--- a/drivers/scsi/lpfc/lpfc_sli.c
+++ b/drivers/scsi/lpfc/lpfc_sli.c
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig * 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
@@ -528,6 +528,7 @@ lpfc_sli_wake_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq)
528 * If pdone_q is empty, the driver thread gave up waiting and 528 * If pdone_q is empty, the driver thread gave up waiting and
529 * continued running. 529 * continued running.
530 */ 530 */
531 pmboxq->mbox_flag |= LPFC_MBX_WAKE;
531 pdone_q = (wait_queue_head_t *) pmboxq->context1; 532 pdone_q = (wait_queue_head_t *) pmboxq->context1;
532 if (pdone_q) 533 if (pdone_q)
533 wake_up_interruptible(pdone_q); 534 wake_up_interruptible(pdone_q);
@@ -538,11 +539,32 @@ void
538lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 539lpfc_sli_def_mbox_cmpl(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
539{ 540{
540 struct lpfc_dmabuf *mp; 541 struct lpfc_dmabuf *mp;
542 uint16_t rpi;
543 int rc;
544
541 mp = (struct lpfc_dmabuf *) (pmb->context1); 545 mp = (struct lpfc_dmabuf *) (pmb->context1);
546
542 if (mp) { 547 if (mp) {
543 lpfc_mbuf_free(phba, mp->virt, mp->phys); 548 lpfc_mbuf_free(phba, mp->virt, mp->phys);
544 kfree(mp); 549 kfree(mp);
545 } 550 }
551
552 /*
553 * If a REG_LOGIN succeeded after node is destroyed or node
554 * is in re-discovery driver need to cleanup the RPI.
555 */
556 if (!(phba->fc_flag & FC_UNLOADING) &&
557 (pmb->mb.mbxCommand == MBX_REG_LOGIN64) &&
558 (!pmb->mb.mbxStatus)) {
559
560 rpi = pmb->mb.un.varWords[0];
561 lpfc_unreg_login(phba, rpi, pmb);
562 pmb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
563 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_NOWAIT);
564 if (rc != MBX_NOT_FINISHED)
565 return;
566 }
567
546 mempool_free( pmb, phba->mbox_mem_pool); 568 mempool_free( pmb, phba->mbox_mem_pool);
547 return; 569 return;
548} 570}
@@ -693,25 +715,8 @@ lpfc_sli_handle_mb_event(struct lpfc_hba * phba)
693 } else { 715 } else {
694 spin_unlock_irq(phba->host->host_lock); 716 spin_unlock_irq(phba->host->host_lock);
695 /* Turn on IOCB processing */ 717 /* Turn on IOCB processing */
696 for (i = 0; i < phba->sli.num_rings; i++) { 718 for (i = 0; i < phba->sli.num_rings; i++)
697 lpfc_sli_turn_on_ring(phba, i); 719 lpfc_sli_turn_on_ring(phba, i);
698 }
699
700 /* Free any lpfc_dmabuf's waiting for mbox cmd cmpls */
701 while (!list_empty(&phba->freebufList)) {
702 struct lpfc_dmabuf *mp;
703
704 mp = NULL;
705 list_remove_head((&phba->freebufList),
706 mp,
707 struct lpfc_dmabuf,
708 list);
709 if (mp) {
710 lpfc_mbuf_free(phba, mp->virt,
711 mp->phys);
712 kfree(mp);
713 }
714 }
715 } 720 }
716 721
717 } while (process_next); 722 } while (process_next);
@@ -833,6 +838,14 @@ lpfc_sli_process_sol_iocb(struct lpfc_hba * phba, struct lpfc_sli_ring * pring,
833 * All other are passed to the completion callback. 838 * All other are passed to the completion callback.
834 */ 839 */
835 if (pring->ringno == LPFC_ELS_RING) { 840 if (pring->ringno == LPFC_ELS_RING) {
841 if (cmdiocbp->iocb_flag & LPFC_DRIVER_ABORTED) {
842 cmdiocbp->iocb_flag &=
843 ~LPFC_DRIVER_ABORTED;
844 saveq->iocb.ulpStatus =
845 IOSTAT_LOCAL_REJECT;
846 saveq->iocb.un.ulpWord[4] =
847 IOERR_SLI_ABORTED;
848 }
836 spin_unlock_irqrestore(phba->host->host_lock, 849 spin_unlock_irqrestore(phba->host->host_lock,
837 iflag); 850 iflag);
838 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq); 851 (cmdiocbp->iocb_cmpl) (phba, cmdiocbp, saveq);
@@ -1464,8 +1477,9 @@ lpfc_sli_handle_slow_ring_event(struct lpfc_hba * phba,
1464int 1477int
1465lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring) 1478lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1466{ 1479{
1480 LIST_HEAD(completions);
1467 struct lpfc_iocbq *iocb, *next_iocb; 1481 struct lpfc_iocbq *iocb, *next_iocb;
1468 IOCB_t *icmd = NULL, *cmd = NULL; 1482 IOCB_t *cmd = NULL;
1469 int errcnt; 1483 int errcnt;
1470 1484
1471 errcnt = 0; 1485 errcnt = 0;
@@ -1474,46 +1488,28 @@ lpfc_sli_abort_iocb_ring(struct lpfc_hba *phba, struct lpfc_sli_ring *pring)
1474 * First do the txq. 1488 * First do the txq.
1475 */ 1489 */
1476 spin_lock_irq(phba->host->host_lock); 1490 spin_lock_irq(phba->host->host_lock);
1477 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { 1491 list_splice_init(&pring->txq, &completions);
1478 list_del_init(&iocb->list);
1479 if (iocb->iocb_cmpl) {
1480 icmd = &iocb->iocb;
1481 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1482 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1483 spin_unlock_irq(phba->host->host_lock);
1484 (iocb->iocb_cmpl) (phba, iocb, iocb);
1485 spin_lock_irq(phba->host->host_lock);
1486 } else
1487 lpfc_sli_release_iocbq(phba, iocb);
1488 }
1489 pring->txq_cnt = 0; 1492 pring->txq_cnt = 0;
1490 INIT_LIST_HEAD(&(pring->txq));
1491 1493
1492 /* Next issue ABTS for everything on the txcmplq */ 1494 /* Next issue ABTS for everything on the txcmplq */
1493 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) { 1495 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list)
1494 cmd = &iocb->iocb; 1496 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1495 1497
1496 /* 1498 spin_unlock_irq(phba->host->host_lock);
1497 * Imediate abort of IOCB, deque and call compl
1498 */
1499 1499
1500 list_del_init(&iocb->list); 1500 while (!list_empty(&completions)) {
1501 pring->txcmplq_cnt--; 1501 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1502 cmd = &iocb->iocb;
1503 list_del(&iocb->list);
1502 1504
1503 if (iocb->iocb_cmpl) { 1505 if (iocb->iocb_cmpl) {
1504 cmd->ulpStatus = IOSTAT_LOCAL_REJECT; 1506 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1505 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED; 1507 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
1506 spin_unlock_irq(phba->host->host_lock);
1507 (iocb->iocb_cmpl) (phba, iocb, iocb); 1508 (iocb->iocb_cmpl) (phba, iocb, iocb);
1508 spin_lock_irq(phba->host->host_lock);
1509 } else 1509 } else
1510 lpfc_sli_release_iocbq(phba, iocb); 1510 lpfc_sli_release_iocbq(phba, iocb);
1511 } 1511 }
1512 1512
1513 INIT_LIST_HEAD(&pring->txcmplq);
1514 pring->txcmplq_cnt = 0;
1515 spin_unlock_irq(phba->host->host_lock);
1516
1517 return errcnt; 1513 return errcnt;
1518} 1514}
1519 1515
@@ -1588,6 +1584,7 @@ void lpfc_reset_barrier(struct lpfc_hba * phba)
1588 hc_copy = readl(phba->HCregaddr); 1584 hc_copy = readl(phba->HCregaddr);
1589 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr); 1585 writel((hc_copy & ~HC_ERINT_ENA), phba->HCregaddr);
1590 readl(phba->HCregaddr); /* flush */ 1586 readl(phba->HCregaddr); /* flush */
1587 phba->fc_flag |= FC_IGNORE_ERATT;
1591 1588
1592 if (readl(phba->HAregaddr) & HA_ERATT) { 1589 if (readl(phba->HAregaddr) & HA_ERATT) {
1593 /* Clear Chip error bit */ 1590 /* Clear Chip error bit */
@@ -1630,6 +1627,7 @@ clear_errat:
1630 } 1627 }
1631 1628
1632restore_hc: 1629restore_hc:
1630 phba->fc_flag &= ~FC_IGNORE_ERATT;
1633 writel(hc_copy, phba->HCregaddr); 1631 writel(hc_copy, phba->HCregaddr);
1634 readl(phba->HCregaddr); /* flush */ 1632 readl(phba->HCregaddr); /* flush */
1635} 1633}
@@ -1665,6 +1663,7 @@ lpfc_sli_brdkill(struct lpfc_hba * phba)
1665 status &= ~HC_ERINT_ENA; 1663 status &= ~HC_ERINT_ENA;
1666 writel(status, phba->HCregaddr); 1664 writel(status, phba->HCregaddr);
1667 readl(phba->HCregaddr); /* flush */ 1665 readl(phba->HCregaddr); /* flush */
1666 phba->fc_flag |= FC_IGNORE_ERATT;
1668 spin_unlock_irq(phba->host->host_lock); 1667 spin_unlock_irq(phba->host->host_lock);
1669 1668
1670 lpfc_kill_board(phba, pmb); 1669 lpfc_kill_board(phba, pmb);
@@ -1674,6 +1673,9 @@ lpfc_sli_brdkill(struct lpfc_hba * phba)
1674 if (retval != MBX_SUCCESS) { 1673 if (retval != MBX_SUCCESS) {
1675 if (retval != MBX_BUSY) 1674 if (retval != MBX_BUSY)
1676 mempool_free(pmb, phba->mbox_mem_pool); 1675 mempool_free(pmb, phba->mbox_mem_pool);
1676 spin_lock_irq(phba->host->host_lock);
1677 phba->fc_flag &= ~FC_IGNORE_ERATT;
1678 spin_unlock_irq(phba->host->host_lock);
1677 return 1; 1679 return 1;
1678 } 1680 }
1679 1681
@@ -1700,6 +1702,7 @@ lpfc_sli_brdkill(struct lpfc_hba * phba)
1700 } 1702 }
1701 spin_lock_irq(phba->host->host_lock); 1703 spin_lock_irq(phba->host->host_lock);
1702 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 1704 psli->sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
1705 phba->fc_flag &= ~FC_IGNORE_ERATT;
1703 spin_unlock_irq(phba->host->host_lock); 1706 spin_unlock_irq(phba->host->host_lock);
1704 1707
1705 psli->mbox_active = NULL; 1708 psli->mbox_active = NULL;
@@ -1985,42 +1988,6 @@ lpfc_sli_hba_setup_exit:
1985 return rc; 1988 return rc;
1986} 1989}
1987 1990
1988static void
1989lpfc_mbox_abort(struct lpfc_hba * phba)
1990{
1991 LPFC_MBOXQ_t *pmbox;
1992 MAILBOX_t *mb;
1993
1994 if (phba->sli.mbox_active) {
1995 del_timer_sync(&phba->sli.mbox_tmo);
1996 phba->work_hba_events &= ~WORKER_MBOX_TMO;
1997 pmbox = phba->sli.mbox_active;
1998 mb = &pmbox->mb;
1999 phba->sli.mbox_active = NULL;
2000 if (pmbox->mbox_cmpl) {
2001 mb->mbxStatus = MBX_NOT_FINISHED;
2002 (pmbox->mbox_cmpl) (phba, pmbox);
2003 }
2004 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2005 }
2006
2007 /* Abort all the non active mailbox commands. */
2008 spin_lock_irq(phba->host->host_lock);
2009 pmbox = lpfc_mbox_get(phba);
2010 while (pmbox) {
2011 mb = &pmbox->mb;
2012 if (pmbox->mbox_cmpl) {
2013 mb->mbxStatus = MBX_NOT_FINISHED;
2014 spin_unlock_irq(phba->host->host_lock);
2015 (pmbox->mbox_cmpl) (phba, pmbox);
2016 spin_lock_irq(phba->host->host_lock);
2017 }
2018 pmbox = lpfc_mbox_get(phba);
2019 }
2020 spin_unlock_irq(phba->host->host_lock);
2021 return;
2022}
2023
2024/*! lpfc_mbox_timeout 1991/*! lpfc_mbox_timeout
2025 * 1992 *
2026 * \pre 1993 * \pre
@@ -2055,6 +2022,8 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2055{ 2022{
2056 LPFC_MBOXQ_t *pmbox; 2023 LPFC_MBOXQ_t *pmbox;
2057 MAILBOX_t *mb; 2024 MAILBOX_t *mb;
2025 struct lpfc_sli *psli = &phba->sli;
2026 struct lpfc_sli_ring *pring;
2058 2027
2059 spin_lock_irq(phba->host->host_lock); 2028 spin_lock_irq(phba->host->host_lock);
2060 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) { 2029 if (!(phba->work_hba_events & WORKER_MBOX_TMO)) {
@@ -2062,8 +2031,6 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2062 return; 2031 return;
2063 } 2032 }
2064 2033
2065 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2066
2067 pmbox = phba->sli.mbox_active; 2034 pmbox = phba->sli.mbox_active;
2068 mb = &pmbox->mb; 2035 mb = &pmbox->mb;
2069 2036
@@ -2078,17 +2045,32 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)
2078 phba->sli.sli_flag, 2045 phba->sli.sli_flag,
2079 phba->sli.mbox_active); 2046 phba->sli.mbox_active);
2080 2047
2081 phba->sli.mbox_active = NULL; 2048 /* Setting state unknown so lpfc_sli_abort_iocb_ring
2082 if (pmbox->mbox_cmpl) { 2049 * would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing
2083 mb->mbxStatus = MBX_NOT_FINISHED; 2050 * it to fail all oustanding SCSI IO.
2084 spin_unlock_irq(phba->host->host_lock); 2051 */
2085 (pmbox->mbox_cmpl) (phba, pmbox); 2052 phba->hba_state = LPFC_STATE_UNKNOWN;
2086 spin_lock_irq(phba->host->host_lock); 2053 phba->work_hba_events &= ~WORKER_MBOX_TMO;
2087 } 2054 phba->fc_flag |= FC_ESTABLISH_LINK;
2088 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE; 2055 psli->sli_flag &= ~LPFC_SLI2_ACTIVE;
2089
2090 spin_unlock_irq(phba->host->host_lock); 2056 spin_unlock_irq(phba->host->host_lock);
2091 lpfc_mbox_abort(phba); 2057
2058 pring = &psli->ring[psli->fcp_ring];
2059 lpfc_sli_abort_iocb_ring(phba, pring);
2060
2061 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
2062 "%d:0316 Resetting board due to mailbox timeout\n",
2063 phba->brd_no);
2064 /*
2065 * lpfc_offline calls lpfc_sli_hba_down which will clean up
2066 * on oustanding mailbox commands.
2067 */
2068 lpfc_offline_prep(phba);
2069 lpfc_offline(phba);
2070 lpfc_sli_brdrestart(phba);
2071 if (lpfc_online(phba) == 0) /* Initialize the HBA */
2072 mod_timer(&phba->fc_estabtmo, jiffies + HZ * 60);
2073 lpfc_unblock_mgmt_io(phba);
2092 return; 2074 return;
2093} 2075}
2094 2076
@@ -2320,9 +2302,7 @@ lpfc_sli_issue_mbox(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmbox, uint32_t flag)
2320 spin_unlock_irqrestore(phba->host->host_lock, 2302 spin_unlock_irqrestore(phba->host->host_lock,
2321 drvr_flag); 2303 drvr_flag);
2322 2304
2323 /* Can be in interrupt context, do not sleep */ 2305 msleep(1);
2324 /* (or might be called with interrupts disabled) */
2325 mdelay(1);
2326 2306
2327 spin_lock_irqsave(phba->host->host_lock, drvr_flag); 2307 spin_lock_irqsave(phba->host->host_lock, drvr_flag);
2328 2308
@@ -2430,7 +2410,7 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2430 2410
2431 if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) { 2411 if (unlikely(phba->hba_state == LPFC_LINK_DOWN)) {
2432 /* 2412 /*
2433 * Only CREATE_XRI, CLOSE_XRI, ABORT_XRI, and QUE_RING_BUF 2413 * Only CREATE_XRI, CLOSE_XRI, and QUE_RING_BUF
2434 * can be issued if the link is not up. 2414 * can be issued if the link is not up.
2435 */ 2415 */
2436 switch (piocb->iocb.ulpCommand) { 2416 switch (piocb->iocb.ulpCommand) {
@@ -2444,6 +2424,8 @@ lpfc_sli_issue_iocb(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2444 piocb->iocb_cmpl = NULL; 2424 piocb->iocb_cmpl = NULL;
2445 /*FALLTHROUGH*/ 2425 /*FALLTHROUGH*/
2446 case CMD_CREATE_XRI_CR: 2426 case CMD_CREATE_XRI_CR:
2427 case CMD_CLOSE_XRI_CN:
2428 case CMD_CLOSE_XRI_CX:
2447 break; 2429 break;
2448 default: 2430 default:
2449 goto iocb_busy; 2431 goto iocb_busy;
@@ -2637,11 +2619,12 @@ lpfc_sli_queue_setup(struct lpfc_hba * phba)
2637int 2619int
2638lpfc_sli_hba_down(struct lpfc_hba * phba) 2620lpfc_sli_hba_down(struct lpfc_hba * phba)
2639{ 2621{
2622 LIST_HEAD(completions);
2640 struct lpfc_sli *psli; 2623 struct lpfc_sli *psli;
2641 struct lpfc_sli_ring *pring; 2624 struct lpfc_sli_ring *pring;
2642 LPFC_MBOXQ_t *pmb; 2625 LPFC_MBOXQ_t *pmb;
2643 struct lpfc_iocbq *iocb, *next_iocb; 2626 struct lpfc_iocbq *iocb;
2644 IOCB_t *icmd = NULL; 2627 IOCB_t *cmd = NULL;
2645 int i; 2628 int i;
2646 unsigned long flags = 0; 2629 unsigned long flags = 0;
2647 2630
@@ -2649,7 +2632,6 @@ lpfc_sli_hba_down(struct lpfc_hba * phba)
2649 lpfc_hba_down_prep(phba); 2632 lpfc_hba_down_prep(phba);
2650 2633
2651 spin_lock_irqsave(phba->host->host_lock, flags); 2634 spin_lock_irqsave(phba->host->host_lock, flags);
2652
2653 for (i = 0; i < psli->num_rings; i++) { 2635 for (i = 0; i < psli->num_rings; i++) {
2654 pring = &psli->ring[i]; 2636 pring = &psli->ring[i];
2655 pring->flag |= LPFC_DEFERRED_RING_EVENT; 2637 pring->flag |= LPFC_DEFERRED_RING_EVENT;
@@ -2658,28 +2640,25 @@ lpfc_sli_hba_down(struct lpfc_hba * phba)
2658 * Error everything on the txq since these iocbs have not been 2640 * Error everything on the txq since these iocbs have not been
2659 * given to the FW yet. 2641 * given to the FW yet.
2660 */ 2642 */
2643 list_splice_init(&pring->txq, &completions);
2661 pring->txq_cnt = 0; 2644 pring->txq_cnt = 0;
2662 2645
2663 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) { 2646 }
2664 list_del_init(&iocb->list); 2647 spin_unlock_irqrestore(phba->host->host_lock, flags);
2665 if (iocb->iocb_cmpl) {
2666 icmd = &iocb->iocb;
2667 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2668 icmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2669 spin_unlock_irqrestore(phba->host->host_lock,
2670 flags);
2671 (iocb->iocb_cmpl) (phba, iocb, iocb);
2672 spin_lock_irqsave(phba->host->host_lock, flags);
2673 } else
2674 lpfc_sli_release_iocbq(phba, iocb);
2675 }
2676 2648
2677 INIT_LIST_HEAD(&(pring->txq)); 2649 while (!list_empty(&completions)) {
2650 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2651 cmd = &iocb->iocb;
2652 list_del(&iocb->list);
2678 2653
2654 if (iocb->iocb_cmpl) {
2655 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2656 cmd->un.ulpWord[4] = IOERR_SLI_DOWN;
2657 (iocb->iocb_cmpl) (phba, iocb, iocb);
2658 } else
2659 lpfc_sli_release_iocbq(phba, iocb);
2679 } 2660 }
2680 2661
2681 spin_unlock_irqrestore(phba->host->host_lock, flags);
2682
2683 /* Return any active mbox cmds */ 2662 /* Return any active mbox cmds */
2684 del_timer_sync(&psli->mbox_tmo); 2663 del_timer_sync(&psli->mbox_tmo);
2685 spin_lock_irqsave(phba->host->host_lock, flags); 2664 spin_lock_irqsave(phba->host->host_lock, flags);
@@ -2768,85 +2747,138 @@ lpfc_sli_ringpostbuf_get(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
2768} 2747}
2769 2748
2770static void 2749static void
2771lpfc_sli_abort_elsreq_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 2750lpfc_sli_abort_els_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2772 struct lpfc_iocbq * rspiocb) 2751 struct lpfc_iocbq * rspiocb)
2773{ 2752{
2774 struct lpfc_dmabuf *buf_ptr, *buf_ptr1; 2753 IOCB_t *irsp;
2775 /* Free the resources associated with the ELS_REQUEST64 IOCB the driver 2754 uint16_t abort_iotag, abort_context;
2776 * just aborted. 2755 struct lpfc_iocbq *abort_iocb, *rsp_ab_iocb;
2777 * In this case, context2 = cmd, context2->next = rsp, context3 = bpl 2756 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
2778 */ 2757
2779 if (cmdiocb->context2) { 2758 abort_iocb = NULL;
2780 buf_ptr1 = (struct lpfc_dmabuf *) cmdiocb->context2; 2759 irsp = &rspiocb->iocb;
2781 2760
2782 /* Free the response IOCB before completing the abort 2761 spin_lock_irq(phba->host->host_lock);
2783 command. */
2784 buf_ptr = NULL;
2785 list_remove_head((&buf_ptr1->list), buf_ptr,
2786 struct lpfc_dmabuf, list);
2787 if (buf_ptr) {
2788 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2789 kfree(buf_ptr);
2790 }
2791 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2792 kfree(buf_ptr1);
2793 }
2794 2762
2795 if (cmdiocb->context3) { 2763 if (irsp->ulpStatus) {
2796 buf_ptr = (struct lpfc_dmabuf *) cmdiocb->context3; 2764 abort_context = cmdiocb->iocb.un.acxri.abortContextTag;
2797 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys); 2765 abort_iotag = cmdiocb->iocb.un.acxri.abortIoTag;
2798 kfree(buf_ptr); 2766
2767 if (abort_iotag != 0 && abort_iotag <= phba->sli.last_iotag)
2768 abort_iocb = phba->sli.iocbq_lookup[abort_iotag];
2769
2770 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2771 "%d:0327 Cannot abort els iocb %p"
2772 " with tag %x context %x\n",
2773 phba->brd_no, abort_iocb,
2774 abort_iotag, abort_context);
2775
2776 /*
2777 * make sure we have the right iocbq before taking it
2778 * off the txcmplq and try to call completion routine.
2779 */
2780 if (abort_iocb &&
2781 abort_iocb->iocb.ulpContext == abort_context &&
2782 abort_iocb->iocb_flag & LPFC_DRIVER_ABORTED) {
2783 list_del(&abort_iocb->list);
2784 pring->txcmplq_cnt--;
2785
2786 rsp_ab_iocb = lpfc_sli_get_iocbq(phba);
2787 if (rsp_ab_iocb == NULL)
2788 lpfc_sli_release_iocbq(phba, abort_iocb);
2789 else {
2790 abort_iocb->iocb_flag &=
2791 ~LPFC_DRIVER_ABORTED;
2792 rsp_ab_iocb->iocb.ulpStatus =
2793 IOSTAT_LOCAL_REJECT;
2794 rsp_ab_iocb->iocb.un.ulpWord[4] =
2795 IOERR_SLI_ABORTED;
2796 spin_unlock_irq(phba->host->host_lock);
2797 (abort_iocb->iocb_cmpl)
2798 (phba, abort_iocb, rsp_ab_iocb);
2799 spin_lock_irq(phba->host->host_lock);
2800 lpfc_sli_release_iocbq(phba, rsp_ab_iocb);
2801 }
2802 }
2799 } 2803 }
2800 2804
2801 lpfc_sli_release_iocbq(phba, cmdiocb); 2805 lpfc_sli_release_iocbq(phba, cmdiocb);
2806 spin_unlock_irq(phba->host->host_lock);
2802 return; 2807 return;
2803} 2808}
2804 2809
2805int 2810int
2806lpfc_sli_issue_abort_iotag32(struct lpfc_hba * phba, 2811lpfc_sli_issue_abort_iotag(struct lpfc_hba * phba,
2807 struct lpfc_sli_ring * pring, 2812 struct lpfc_sli_ring * pring,
2808 struct lpfc_iocbq * cmdiocb) 2813 struct lpfc_iocbq * cmdiocb)
2809{ 2814{
2810 struct lpfc_iocbq *abtsiocbp; 2815 struct lpfc_iocbq *abtsiocbp;
2811 IOCB_t *icmd = NULL; 2816 IOCB_t *icmd = NULL;
2812 IOCB_t *iabt = NULL; 2817 IOCB_t *iabt = NULL;
2818 int retval = IOCB_ERROR;
2819
2820 /* There are certain command types we don't want
2821 * to abort.
2822 */
2823 icmd = &cmdiocb->iocb;
2824 if ((icmd->ulpCommand == CMD_ABORT_XRI_CN) ||
2825 (icmd->ulpCommand == CMD_CLOSE_XRI_CN))
2826 return 0;
2827
2828 /* If we're unloading, interrupts are disabled so we
2829 * need to cleanup the iocb here.
2830 */
2831 if (phba->fc_flag & FC_UNLOADING)
2832 goto abort_iotag_exit;
2813 2833
2814 /* issue ABTS for this IOCB based on iotag */ 2834 /* issue ABTS for this IOCB based on iotag */
2815 abtsiocbp = lpfc_sli_get_iocbq(phba); 2835 abtsiocbp = lpfc_sli_get_iocbq(phba);
2816 if (abtsiocbp == NULL) 2836 if (abtsiocbp == NULL)
2817 return 0; 2837 return 0;
2818 2838
2839 /* This signals the response to set the correct status
2840 * before calling the completion handler.
2841 */
2842 cmdiocb->iocb_flag |= LPFC_DRIVER_ABORTED;
2843
2819 iabt = &abtsiocbp->iocb; 2844 iabt = &abtsiocbp->iocb;
2820 icmd = &cmdiocb->iocb; 2845 iabt->un.acxri.abortType = ABORT_TYPE_ABTS;
2821 switch (icmd->ulpCommand) { 2846 iabt->un.acxri.abortContextTag = icmd->ulpContext;
2822 case CMD_ELS_REQUEST64_CR: 2847 iabt->un.acxri.abortIoTag = icmd->ulpIoTag;
2823 /* Even though we abort the ELS command, the firmware may access 2848 iabt->ulpLe = 1;
2824 * the BPL or other resources before it processes our 2849 iabt->ulpClass = icmd->ulpClass;
2825 * ABORT_MXRI64. Thus we must delay reusing the cmdiocb
2826 * resources till the actual abort request completes.
2827 */
2828 abtsiocbp->context1 = (void *)((unsigned long)icmd->ulpCommand);
2829 abtsiocbp->context2 = cmdiocb->context2;
2830 abtsiocbp->context3 = cmdiocb->context3;
2831 cmdiocb->context2 = NULL;
2832 cmdiocb->context3 = NULL;
2833 abtsiocbp->iocb_cmpl = lpfc_sli_abort_elsreq_cmpl;
2834 break;
2835 default:
2836 lpfc_sli_release_iocbq(phba, abtsiocbp);
2837 return 0;
2838 }
2839 2850
2840 iabt->un.amxri.abortType = ABORT_TYPE_ABTS; 2851 if (phba->hba_state >= LPFC_LINK_UP)
2841 iabt->un.amxri.iotag32 = icmd->un.elsreq64.bdl.ulpIoTag32; 2852 iabt->ulpCommand = CMD_ABORT_XRI_CN;
2853 else
2854 iabt->ulpCommand = CMD_CLOSE_XRI_CN;
2842 2855
2843 iabt->ulpLe = 1; 2856 abtsiocbp->iocb_cmpl = lpfc_sli_abort_els_cmpl;
2844 iabt->ulpClass = CLASS3;
2845 iabt->ulpCommand = CMD_ABORT_MXRI64_CN;
2846 2857
2847 if (lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0) == IOCB_ERROR) { 2858 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
2848 lpfc_sli_release_iocbq(phba, abtsiocbp); 2859 "%d:0339 Abort xri x%x, original iotag x%x, abort "
2849 return 0; 2860 "cmd iotag x%x\n",
2861 phba->brd_no, iabt->un.acxri.abortContextTag,
2862 iabt->un.acxri.abortIoTag, abtsiocbp->iotag);
2863 retval = lpfc_sli_issue_iocb(phba, pring, abtsiocbp, 0);
2864
2865abort_iotag_exit:
2866
2867 /* If we could not issue an abort dequeue the iocb and handle
2868 * the completion here.
2869 */
2870 if (retval == IOCB_ERROR) {
2871 list_del(&cmdiocb->list);
2872 pring->txcmplq_cnt--;
2873
2874 if (cmdiocb->iocb_cmpl) {
2875 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2876 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2877 spin_unlock_irq(phba->host->host_lock);
2878 (cmdiocb->iocb_cmpl) (phba, cmdiocb, cmdiocb);
2879 spin_lock_irq(phba->host->host_lock);
2880 } else
2881 lpfc_sli_release_iocbq(phba, cmdiocb);
2850 } 2882 }
2851 2883
2852 return 1; 2884 return 1;
@@ -2918,9 +2950,11 @@ void
2918lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb, 2950lpfc_sli_abort_fcp_cmpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2919 struct lpfc_iocbq * rspiocb) 2951 struct lpfc_iocbq * rspiocb)
2920{ 2952{
2921 spin_lock_irq(phba->host->host_lock); 2953 unsigned long iflags;
2954
2955 spin_lock_irqsave(phba->host->host_lock, iflags);
2922 lpfc_sli_release_iocbq(phba, cmdiocb); 2956 lpfc_sli_release_iocbq(phba, cmdiocb);
2923 spin_unlock_irq(phba->host->host_lock); 2957 spin_unlock_irqrestore(phba->host->host_lock, iflags);
2924 return; 2958 return;
2925} 2959}
2926 2960
@@ -3043,22 +3077,22 @@ lpfc_sli_issue_iocb_wait(struct lpfc_hba * phba,
3043 timeout_req); 3077 timeout_req);
3044 spin_lock_irq(phba->host->host_lock); 3078 spin_lock_irq(phba->host->host_lock);
3045 3079
3046 if (timeleft == 0) { 3080 if (piocb->iocb_flag & LPFC_IO_WAKE) {
3081 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3082 "%d:0331 IOCB wake signaled\n",
3083 phba->brd_no);
3084 } else if (timeleft == 0) {
3047 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 3085 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3048 "%d:0338 IOCB wait timeout error - no " 3086 "%d:0338 IOCB wait timeout error - no "
3049 "wake response Data x%x\n", 3087 "wake response Data x%x\n",
3050 phba->brd_no, timeout); 3088 phba->brd_no, timeout);
3051 retval = IOCB_TIMEDOUT; 3089 retval = IOCB_TIMEDOUT;
3052 } else if (!(piocb->iocb_flag & LPFC_IO_WAKE)) { 3090 } else {
3053 lpfc_printf_log(phba, KERN_ERR, LOG_SLI, 3091 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3054 "%d:0330 IOCB wake NOT set, " 3092 "%d:0330 IOCB wake NOT set, "
3055 "Data x%x x%lx\n", phba->brd_no, 3093 "Data x%x x%lx\n", phba->brd_no,
3056 timeout, (timeleft / jiffies)); 3094 timeout, (timeleft / jiffies));
3057 retval = IOCB_TIMEDOUT; 3095 retval = IOCB_TIMEDOUT;
3058 } else {
3059 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3060 "%d:0331 IOCB wake signaled\n",
3061 phba->brd_no);
3062 } 3096 }
3063 } else { 3097 } else {
3064 lpfc_printf_log(phba, KERN_INFO, LOG_SLI, 3098 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
@@ -3087,8 +3121,6 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
3087 uint32_t timeout) 3121 uint32_t timeout)
3088{ 3122{
3089 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q); 3123 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(done_q);
3090 DECLARE_WAITQUEUE(wq_entry, current);
3091 uint32_t timeleft = 0;
3092 int retval; 3124 int retval;
3093 3125
3094 /* The caller must leave context1 empty. */ 3126 /* The caller must leave context1 empty. */
@@ -3101,27 +3133,25 @@ lpfc_sli_issue_mbox_wait(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmboxq,
3101 /* setup context field to pass wait_queue pointer to wake function */ 3133 /* setup context field to pass wait_queue pointer to wake function */
3102 pmboxq->context1 = &done_q; 3134 pmboxq->context1 = &done_q;
3103 3135
3104 /* start to sleep before we wait, to avoid races */
3105 set_current_state(TASK_INTERRUPTIBLE);
3106 add_wait_queue(&done_q, &wq_entry);
3107
3108 /* now issue the command */ 3136 /* now issue the command */
3109 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT); 3137 retval = lpfc_sli_issue_mbox(phba, pmboxq, MBX_NOWAIT);
3110 3138
3111 if (retval == MBX_BUSY || retval == MBX_SUCCESS) { 3139 if (retval == MBX_BUSY || retval == MBX_SUCCESS) {
3112 timeleft = schedule_timeout(timeout * HZ); 3140 wait_event_interruptible_timeout(done_q,
3141 pmboxq->mbox_flag & LPFC_MBX_WAKE,
3142 timeout * HZ);
3143
3113 pmboxq->context1 = NULL; 3144 pmboxq->context1 = NULL;
3114 /* if schedule_timeout returns 0, we timed out and were not 3145 /*
3115 woken up */ 3146 * if LPFC_MBX_WAKE flag is set the mailbox is completed
3116 if ((timeleft == 0) || signal_pending(current)) 3147 * else do not free the resources.
3117 retval = MBX_TIMEOUT; 3148 */
3118 else 3149 if (pmboxq->mbox_flag & LPFC_MBX_WAKE)
3119 retval = MBX_SUCCESS; 3150 retval = MBX_SUCCESS;
3151 else
3152 retval = MBX_TIMEOUT;
3120 } 3153 }
3121 3154
3122
3123 set_current_state(TASK_RUNNING);
3124 remove_wait_queue(&done_q, &wq_entry);
3125 return retval; 3155 return retval;
3126} 3156}
3127 3157
@@ -3184,6 +3214,11 @@ lpfc_intr_handler(int irq, void *dev_id)
3184 */ 3214 */
3185 spin_lock(phba->host->host_lock); 3215 spin_lock(phba->host->host_lock);
3186 ha_copy = readl(phba->HAregaddr); 3216 ha_copy = readl(phba->HAregaddr);
3217 /* If somebody is waiting to handle an eratt don't process it
3218 * here. The brdkill function will do this.
3219 */
3220 if (phba->fc_flag & FC_IGNORE_ERATT)
3221 ha_copy &= ~HA_ERATT;
3187 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr); 3222 writel((ha_copy & ~(HA_LATT | HA_ERATT)), phba->HAregaddr);
3188 readl(phba->HAregaddr); /* flush */ 3223 readl(phba->HAregaddr); /* flush */
3189 spin_unlock(phba->host->host_lock); 3224 spin_unlock(phba->host->host_lock);
diff --git a/drivers/scsi/lpfc/lpfc_sli.h b/drivers/scsi/lpfc/lpfc_sli.h
index a43549959dc7..41c38d324ab0 100644
--- a/drivers/scsi/lpfc/lpfc_sli.h
+++ b/drivers/scsi/lpfc/lpfc_sli.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -39,9 +39,10 @@ struct lpfc_iocbq {
39 IOCB_t iocb; /* IOCB cmd */ 39 IOCB_t iocb; /* IOCB cmd */
40 uint8_t retry; /* retry counter for IOCB cmd - if needed */ 40 uint8_t retry; /* retry counter for IOCB cmd - if needed */
41 uint8_t iocb_flag; 41 uint8_t iocb_flag;
42#define LPFC_IO_LIBDFC 1 /* libdfc iocb */ 42#define LPFC_IO_LIBDFC 1 /* libdfc iocb */
43#define LPFC_IO_WAKE 2 /* High Priority Queue signal flag */ 43#define LPFC_IO_WAKE 2 /* High Priority Queue signal flag */
44#define LPFC_IO_FCP 4 /* FCP command -- iocbq in scsi_buf */ 44#define LPFC_IO_FCP 4 /* FCP command -- iocbq in scsi_buf */
45#define LPFC_DRIVER_ABORTED 8 /* driver aborted this request */
45 46
46 uint8_t abort_count; 47 uint8_t abort_count;
47 uint8_t rsvd2; 48 uint8_t rsvd2;
@@ -67,6 +68,8 @@ struct lpfc_iocbq {
67#define IOCB_ERROR 2 68#define IOCB_ERROR 2
68#define IOCB_TIMEDOUT 3 69#define IOCB_TIMEDOUT 3
69 70
71#define LPFC_MBX_WAKE 1
72
70typedef struct lpfcMboxq { 73typedef struct lpfcMboxq {
71 /* MBOXQs are used in single linked lists */ 74 /* MBOXQs are used in single linked lists */
72 struct list_head list; /* ptr to next mailbox command */ 75 struct list_head list; /* ptr to next mailbox command */
@@ -75,6 +78,7 @@ typedef struct lpfcMboxq {
75 void *context2; /* caller context information */ 78 void *context2; /* caller context information */
76 79
77 void (*mbox_cmpl) (struct lpfc_hba *, struct lpfcMboxq *); 80 void (*mbox_cmpl) (struct lpfc_hba *, struct lpfcMboxq *);
81 uint8_t mbox_flag;
78 82
79} LPFC_MBOXQ_t; 83} LPFC_MBOXQ_t;
80 84
diff --git a/drivers/scsi/lpfc/lpfc_version.h b/drivers/scsi/lpfc/lpfc_version.h
index a61ef3d1e7f1..92a9107019d2 100644
--- a/drivers/scsi/lpfc/lpfc_version.h
+++ b/drivers/scsi/lpfc/lpfc_version.h
@@ -1,7 +1,7 @@
1/******************************************************************* 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for * 2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. * 3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2006 Emulex. All rights reserved. * 4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. * 5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com * 6 * www.emulex.com *
7 * * 7 * *
@@ -18,12 +18,12 @@
18 * included with this package. * 18 * included with this package. *
19 *******************************************************************/ 19 *******************************************************************/
20 20
21#define LPFC_DRIVER_VERSION "8.1.11" 21#define LPFC_DRIVER_VERSION "8.1.12"
22 22
23#define LPFC_DRIVER_NAME "lpfc" 23#define LPFC_DRIVER_NAME "lpfc"
24 24
25#define LPFC_MODULE_DESC "Emulex LightPulse Fibre Channel SCSI driver " \ 25#define LPFC_MODULE_DESC "Emulex LightPulse Fibre Channel SCSI driver " \
26 LPFC_DRIVER_VERSION 26 LPFC_DRIVER_VERSION
27#define LPFC_COPYRIGHT "Copyright(c) 2004-2006 Emulex. All rights reserved." 27#define LPFC_COPYRIGHT "Copyright(c) 2004-2007 Emulex. All rights reserved."
28 28
29#define DFC_API_VERSION "0.0.0" 29#define DFC_API_VERSION "0.0.0"
diff --git a/drivers/scsi/mac53c94.c b/drivers/scsi/mac53c94.c
index 753d88306cd1..5806ede120a4 100644
--- a/drivers/scsi/mac53c94.c
+++ b/drivers/scsi/mac53c94.c
@@ -471,7 +471,7 @@ static int mac53c94_probe(struct macio_dev *mdev, const struct of_device_id *mat
471 goto out_free; 471 goto out_free;
472 } 472 }
473 473
474 clkprop = get_property(node, "clock-frequency", &proplen); 474 clkprop = of_get_property(node, "clock-frequency", &proplen);
475 if (clkprop == NULL || proplen != sizeof(int)) { 475 if (clkprop == NULL || proplen != sizeof(int)) {
476 printk(KERN_ERR "%s: can't get clock frequency, " 476 printk(KERN_ERR "%s: can't get clock frequency, "
477 "assuming 25MHz\n", node->full_name); 477 "assuming 25MHz\n", node->full_name);
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 7fc6e06ea7e1..3cce75d70263 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -1754,7 +1754,8 @@ __mega_busywait_mbox (adapter_t *adapter)
1754 for (counter = 0; counter < 10000; counter++) { 1754 for (counter = 0; counter < 10000; counter++) {
1755 if (!mbox->m_in.busy) 1755 if (!mbox->m_in.busy)
1756 return 0; 1756 return 0;
1757 udelay(100); yield(); 1757 udelay(100);
1758 cond_resched();
1758 } 1759 }
1759 return -1; /* give up after 1 second */ 1760 return -1; /* give up after 1 second */
1760} 1761}
@@ -3177,7 +3178,10 @@ proc_rdrv(adapter_t *adapter, char *page, int start, int end )
3177 3178
3178 return len; 3179 return len;
3179} 3180}
3180 3181#else
3182static inline void mega_create_proc_entry(int index, struct proc_dir_entry *parent)
3183{
3184}
3181#endif 3185#endif
3182 3186
3183 3187
@@ -4342,7 +4346,7 @@ mega_support_cluster(adapter_t *adapter)
4342 return 0; 4346 return 0;
4343} 4347}
4344 4348
4345 4349#ifdef CONFIG_PROC_FS
4346/** 4350/**
4347 * mega_adapinq() 4351 * mega_adapinq()
4348 * @adapter - pointer to our soft state 4352 * @adapter - pointer to our soft state
@@ -4447,7 +4451,7 @@ mega_internal_dev_inquiry(adapter_t *adapter, u8 ch, u8 tgt,
4447 4451
4448 return rval; 4452 return rval;
4449} 4453}
4450 4454#endif
4451 4455
4452/** 4456/**
4453 * mega_internal_command() 4457 * mega_internal_command()
@@ -4965,7 +4969,6 @@ megaraid_remove_one(struct pci_dev *pdev)
4965{ 4969{
4966 struct Scsi_Host *host = pci_get_drvdata(pdev); 4970 struct Scsi_Host *host = pci_get_drvdata(pdev);
4967 adapter_t *adapter = (adapter_t *)host->hostdata; 4971 adapter_t *adapter = (adapter_t *)host->hostdata;
4968 char buf[12] = { 0 };
4969 4972
4970 scsi_remove_host(host); 4973 scsi_remove_host(host);
4971 4974
@@ -5011,8 +5014,11 @@ megaraid_remove_one(struct pci_dev *pdev)
5011 remove_proc_entry("raiddrives-30-39", 5014 remove_proc_entry("raiddrives-30-39",
5012 adapter->controller_proc_dir_entry); 5015 adapter->controller_proc_dir_entry);
5013#endif 5016#endif
5014 sprintf(buf, "hba%d", adapter->host->host_no); 5017 {
5015 remove_proc_entry(buf, mega_proc_dir_entry); 5018 char buf[12] = { 0 };
5019 sprintf(buf, "hba%d", adapter->host->host_no);
5020 remove_proc_entry(buf, mega_proc_dir_entry);
5021 }
5016 } 5022 }
5017#endif 5023#endif
5018 5024
diff --git a/drivers/scsi/megaraid.h b/drivers/scsi/megaraid.h
index c6e74643abe2..ee70bd4ae4ba 100644
--- a/drivers/scsi/megaraid.h
+++ b/drivers/scsi/megaraid.h
@@ -1002,7 +1002,6 @@ static int megaraid_reset(Scsi_Cmnd *);
1002static int megaraid_abort_and_reset(adapter_t *, Scsi_Cmnd *, int); 1002static int megaraid_abort_and_reset(adapter_t *, Scsi_Cmnd *, int);
1003static int megaraid_biosparam(struct scsi_device *, struct block_device *, 1003static int megaraid_biosparam(struct scsi_device *, struct block_device *,
1004 sector_t, int []); 1004 sector_t, int []);
1005static int mega_print_inquiry(char *, char *);
1006 1005
1007static int mega_build_sglist (adapter_t *adapter, scb_t *scb, 1006static int mega_build_sglist (adapter_t *adapter, scb_t *scb,
1008 u32 *buffer, u32 *length); 1007 u32 *buffer, u32 *length);
@@ -1024,6 +1023,7 @@ static int mega_init_scb (adapter_t *);
1024static int mega_is_bios_enabled (adapter_t *); 1023static int mega_is_bios_enabled (adapter_t *);
1025 1024
1026#ifdef CONFIG_PROC_FS 1025#ifdef CONFIG_PROC_FS
1026static int mega_print_inquiry(char *, char *);
1027static void mega_create_proc_entry(int, struct proc_dir_entry *); 1027static void mega_create_proc_entry(int, struct proc_dir_entry *);
1028static int proc_read_config(char *, char **, off_t, int, int *, void *); 1028static int proc_read_config(char *, char **, off_t, int, int *, void *);
1029static int proc_read_stat(char *, char **, off_t, int, int *, void *); 1029static int proc_read_stat(char *, char **, off_t, int, int *, void *);
@@ -1040,10 +1040,10 @@ static int proc_rdrv_20(char *, char **, off_t, int, int *, void *);
1040static int proc_rdrv_30(char *, char **, off_t, int, int *, void *); 1040static int proc_rdrv_30(char *, char **, off_t, int, int *, void *);
1041static int proc_rdrv_40(char *, char **, off_t, int, int *, void *); 1041static int proc_rdrv_40(char *, char **, off_t, int, int *, void *);
1042static int proc_rdrv(adapter_t *, char *, int, int); 1042static int proc_rdrv(adapter_t *, char *, int, int);
1043#endif
1044 1043
1045static int mega_adapinq(adapter_t *, dma_addr_t); 1044static int mega_adapinq(adapter_t *, dma_addr_t);
1046static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t); 1045static int mega_internal_dev_inquiry(adapter_t *, u8, u8, dma_addr_t);
1046#endif
1047 1047
1048static int mega_support_ext_cdb(adapter_t *); 1048static int mega_support_ext_cdb(adapter_t *);
1049static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *, 1049static mega_passthru* mega_prepare_passthru(adapter_t *, scb_t *,
diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index f33a678f0897..84d9c27133d4 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -14,7 +14,7 @@
14 * 14 *
15 * Common management module 15 * Common management module
16 */ 16 */
17 17#include <linux/sched.h>
18#include "megaraid_mm.h" 18#include "megaraid_mm.h"
19 19
20 20
@@ -60,7 +60,7 @@ EXPORT_SYMBOL(mraid_mm_unregister_adp);
60EXPORT_SYMBOL(mraid_mm_adapter_app_handle); 60EXPORT_SYMBOL(mraid_mm_adapter_app_handle);
61 61
62static int majorno; 62static int majorno;
63static uint32_t drvr_ver = 0x02200206; 63static uint32_t drvr_ver = 0x02200207;
64 64
65static int adapters_count_g; 65static int adapters_count_g;
66static struct list_head adapters_list_g; 66static struct list_head adapters_list_g;
diff --git a/drivers/scsi/mesh.c b/drivers/scsi/mesh.c
index 1fd3c7590d31..e64d1a19d8d7 100644
--- a/drivers/scsi/mesh.c
+++ b/drivers/scsi/mesh.c
@@ -185,7 +185,7 @@ struct mesh_state {
185 * Driver is too messy, we need a few prototypes... 185 * Driver is too messy, we need a few prototypes...
186 */ 186 */
187static void mesh_done(struct mesh_state *ms, int start_next); 187static void mesh_done(struct mesh_state *ms, int start_next);
188static void mesh_interrupt(int irq, void *dev_id); 188static void mesh_interrupt(struct mesh_state *ms);
189static void cmd_complete(struct mesh_state *ms); 189static void cmd_complete(struct mesh_state *ms);
190static void set_dma_cmds(struct mesh_state *ms, struct scsi_cmnd *cmd); 190static void set_dma_cmds(struct mesh_state *ms, struct scsi_cmnd *cmd);
191static void halt_dma(struct mesh_state *ms); 191static void halt_dma(struct mesh_state *ms);
@@ -466,7 +466,7 @@ static void mesh_start_cmd(struct mesh_state *ms, struct scsi_cmnd *cmd)
466 dlog(ms, "intr b4 arb, intr/exc/err/fc=%.8x", 466 dlog(ms, "intr b4 arb, intr/exc/err/fc=%.8x",
467 MKWORD(mr->interrupt, mr->exception, 467 MKWORD(mr->interrupt, mr->exception,
468 mr->error, mr->fifo_count)); 468 mr->error, mr->fifo_count));
469 mesh_interrupt(0, (void *)ms); 469 mesh_interrupt(ms);
470 if (ms->phase != arbitrating) 470 if (ms->phase != arbitrating)
471 return; 471 return;
472 } 472 }
@@ -504,7 +504,7 @@ static void mesh_start_cmd(struct mesh_state *ms, struct scsi_cmnd *cmd)
504 dlog(ms, "intr after disresel, intr/exc/err/fc=%.8x", 504 dlog(ms, "intr after disresel, intr/exc/err/fc=%.8x",
505 MKWORD(mr->interrupt, mr->exception, 505 MKWORD(mr->interrupt, mr->exception,
506 mr->error, mr->fifo_count)); 506 mr->error, mr->fifo_count));
507 mesh_interrupt(0, (void *)ms); 507 mesh_interrupt(ms);
508 if (ms->phase != arbitrating) 508 if (ms->phase != arbitrating)
509 return; 509 return;
510 dlog(ms, "after intr after disresel, intr/exc/err/fc=%.8x", 510 dlog(ms, "after intr after disresel, intr/exc/err/fc=%.8x",
@@ -1018,10 +1018,11 @@ static void handle_reset(struct mesh_state *ms)
1018static irqreturn_t do_mesh_interrupt(int irq, void *dev_id) 1018static irqreturn_t do_mesh_interrupt(int irq, void *dev_id)
1019{ 1019{
1020 unsigned long flags; 1020 unsigned long flags;
1021 struct Scsi_Host *dev = ((struct mesh_state *)dev_id)->host; 1021 struct mesh_state *ms = dev_id;
1022 struct Scsi_Host *dev = ms->host;
1022 1023
1023 spin_lock_irqsave(dev->host_lock, flags); 1024 spin_lock_irqsave(dev->host_lock, flags);
1024 mesh_interrupt(irq, dev_id); 1025 mesh_interrupt(ms);
1025 spin_unlock_irqrestore(dev->host_lock, flags); 1026 spin_unlock_irqrestore(dev->host_lock, flags);
1026 return IRQ_HANDLED; 1027 return IRQ_HANDLED;
1027} 1028}
@@ -1661,9 +1662,8 @@ static int mesh_queue(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
1661 * handler (do_mesh_interrupt) or by other functions in 1662 * handler (do_mesh_interrupt) or by other functions in
1662 * exceptional circumstances 1663 * exceptional circumstances
1663 */ 1664 */
1664static void mesh_interrupt(int irq, void *dev_id) 1665static void mesh_interrupt(struct mesh_state *ms)
1665{ 1666{
1666 struct mesh_state *ms = (struct mesh_state *) dev_id;
1667 volatile struct mesh_regs __iomem *mr = ms->mesh; 1667 volatile struct mesh_regs __iomem *mr = ms->mesh;
1668 int intr; 1668 int intr;
1669 1669
@@ -1947,7 +1947,7 @@ static int mesh_probe(struct macio_dev *mdev, const struct of_device_id *match)
1947 ms->tgts[tgt].current_req = NULL; 1947 ms->tgts[tgt].current_req = NULL;
1948 } 1948 }
1949 1949
1950 if ((cfp = get_property(mesh, "clock-frequency", NULL))) 1950 if ((cfp = of_get_property(mesh, "clock-frequency", NULL)))
1951 ms->clk_freq = *cfp; 1951 ms->clk_freq = *cfp;
1952 else { 1952 else {
1953 printk(KERN_INFO "mesh: assuming 50MHz clock frequency\n"); 1953 printk(KERN_INFO "mesh: assuming 50MHz clock frequency\n");
diff --git a/drivers/scsi/qla1280.c b/drivers/scsi/qla1280.c
index 6777e8a69153..54d8bdf86852 100644
--- a/drivers/scsi/qla1280.c
+++ b/drivers/scsi/qla1280.c
@@ -4293,7 +4293,7 @@ qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
4293 ha->devnum = devnum; /* specifies microcode load address */ 4293 ha->devnum = devnum; /* specifies microcode load address */
4294 4294
4295#ifdef QLA_64BIT_PTR 4295#ifdef QLA_64BIT_PTR
4296 if (pci_set_dma_mask(ha->pdev, (dma_addr_t) ~ 0ULL)) { 4296 if (pci_set_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
4297 if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK)) { 4297 if (pci_set_dma_mask(ha->pdev, DMA_32BIT_MASK)) {
4298 printk(KERN_WARNING "scsi(%li): Unable to set a " 4298 printk(KERN_WARNING "scsi(%li): Unable to set a "
4299 "suitable DMA mask - aborting\n", ha->host_no); 4299 "suitable DMA mask - aborting\n", ha->host_no);
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index 3e296ab845b6..2a45aec4ff29 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -13,7 +13,6 @@
13 13
14#ifdef CONFIG_SPARC 14#ifdef CONFIG_SPARC
15#include <asm/prom.h> 15#include <asm/prom.h>
16#include <asm/pbm.h>
17#endif 16#endif
18 17
19/* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */ 18/* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
@@ -130,18 +129,17 @@ qla2x00_initialize_adapter(scsi_qla_host_t *ha)
130int 129int
131qla2100_pci_config(scsi_qla_host_t *ha) 130qla2100_pci_config(scsi_qla_host_t *ha)
132{ 131{
133 uint16_t w, mwi; 132 int ret;
133 uint16_t w;
134 uint32_t d; 134 uint32_t d;
135 unsigned long flags; 135 unsigned long flags;
136 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 136 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
137 137
138 pci_set_master(ha->pdev); 138 pci_set_master(ha->pdev);
139 mwi = 0; 139 ret = pci_set_mwi(ha->pdev);
140 if (pci_set_mwi(ha->pdev))
141 mwi = PCI_COMMAND_INVALIDATE;
142 140
143 pci_read_config_word(ha->pdev, PCI_COMMAND, &w); 141 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
144 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); 142 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
145 pci_write_config_word(ha->pdev, PCI_COMMAND, w); 143 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
146 144
147 /* Reset expansion ROM address decode enable */ 145 /* Reset expansion ROM address decode enable */
@@ -166,22 +164,22 @@ qla2100_pci_config(scsi_qla_host_t *ha)
166int 164int
167qla2300_pci_config(scsi_qla_host_t *ha) 165qla2300_pci_config(scsi_qla_host_t *ha)
168{ 166{
169 uint16_t w, mwi; 167 int ret;
168 uint16_t w;
170 uint32_t d; 169 uint32_t d;
171 unsigned long flags = 0; 170 unsigned long flags = 0;
172 uint32_t cnt; 171 uint32_t cnt;
173 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 172 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
174 173
175 pci_set_master(ha->pdev); 174 pci_set_master(ha->pdev);
176 mwi = 0; 175 ret = pci_set_mwi(ha->pdev);
177 if (pci_set_mwi(ha->pdev))
178 mwi = PCI_COMMAND_INVALIDATE;
179 176
180 pci_read_config_word(ha->pdev, PCI_COMMAND, &w); 177 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
181 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); 178 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
182 179
183 if (IS_QLA2322(ha) || IS_QLA6322(ha)) 180 if (IS_QLA2322(ha) || IS_QLA6322(ha))
184 w &= ~PCI_COMMAND_INTX_DISABLE; 181 w &= ~PCI_COMMAND_INTX_DISABLE;
182 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
185 183
186 /* 184 /*
187 * If this is a 2300 card and not 2312, reset the 185 * If this is a 2300 card and not 2312, reset the
@@ -210,7 +208,7 @@ qla2300_pci_config(scsi_qla_host_t *ha)
210 ha->fb_rev = RD_FB_CMD_REG(ha, reg); 208 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
211 209
212 if (ha->fb_rev == FPM_2300) 210 if (ha->fb_rev == FPM_2300)
213 w &= ~PCI_COMMAND_INVALIDATE; 211 pci_clear_mwi(ha->pdev);
214 212
215 /* Deselect FPM registers. */ 213 /* Deselect FPM registers. */
216 WRT_REG_WORD(&reg->ctrl_status, 0x0); 214 WRT_REG_WORD(&reg->ctrl_status, 0x0);
@@ -227,7 +225,6 @@ qla2300_pci_config(scsi_qla_host_t *ha)
227 225
228 spin_unlock_irqrestore(&ha->hardware_lock, flags); 226 spin_unlock_irqrestore(&ha->hardware_lock, flags);
229 } 227 }
230 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
231 228
232 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); 229 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
233 230
@@ -253,19 +250,18 @@ qla2300_pci_config(scsi_qla_host_t *ha)
253int 250int
254qla24xx_pci_config(scsi_qla_host_t *ha) 251qla24xx_pci_config(scsi_qla_host_t *ha)
255{ 252{
256 uint16_t w, mwi; 253 int ret;
254 uint16_t w;
257 uint32_t d; 255 uint32_t d;
258 unsigned long flags = 0; 256 unsigned long flags = 0;
259 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; 257 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
260 int pcix_cmd_reg, pcie_dctl_reg; 258 int pcix_cmd_reg, pcie_dctl_reg;
261 259
262 pci_set_master(ha->pdev); 260 pci_set_master(ha->pdev);
263 mwi = 0; 261 ret = pci_set_mwi(ha->pdev);
264 if (pci_set_mwi(ha->pdev))
265 mwi = PCI_COMMAND_INVALIDATE;
266 262
267 pci_read_config_word(ha->pdev, PCI_COMMAND, &w); 263 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
268 w |= mwi | (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); 264 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
269 w &= ~PCI_COMMAND_INTX_DISABLE; 265 w &= ~PCI_COMMAND_INTX_DISABLE;
270 pci_write_config_word(ha->pdev, PCI_COMMAND, w); 266 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
271 267
@@ -1400,9 +1396,8 @@ static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1400{ 1396{
1401#ifdef CONFIG_SPARC 1397#ifdef CONFIG_SPARC
1402 struct pci_dev *pdev = ha->pdev; 1398 struct pci_dev *pdev = ha->pdev;
1403 struct pcidev_cookie *pcp = pdev->sysdata; 1399 struct device_node *dp = pci_device_to_OF_node(pdev);
1404 struct device_node *dp = pcp->prom_node; 1400 const u8 *val;
1405 u8 *val;
1406 int len; 1401 int len;
1407 1402
1408 val = of_get_property(dp, "port-wwn", &len); 1403 val = of_get_property(dp, "port-wwn", &len);
@@ -3373,9 +3368,8 @@ static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *n
3373{ 3368{
3374#ifdef CONFIG_SPARC 3369#ifdef CONFIG_SPARC
3375 struct pci_dev *pdev = ha->pdev; 3370 struct pci_dev *pdev = ha->pdev;
3376 struct pcidev_cookie *pcp = pdev->sysdata; 3371 struct device_node *dp = pci_device_to_OF_node(pdev);
3377 struct device_node *dp = pcp->prom_node; 3372 const u8 *val;
3378 u8 *val;
3379 int len; 3373 int len;
3380 3374
3381 val = of_get_property(dp, "port-wwn", &len); 3375 val = of_get_property(dp, "port-wwn", &len);
@@ -3931,6 +3925,8 @@ qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
3931 3925
3932 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)) 3926 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha))
3933 return; 3927 return;
3928 if (!ha->fw_major_version)
3929 return;
3934 3930
3935 ret = qla2x00_stop_firmware(ha); 3931 ret = qla2x00_stop_firmware(ha);
3936 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) { 3932 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index d4885616cd39..ca463469063d 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -1726,6 +1726,17 @@ qla2x00_request_irqs(scsi_qla_host_t *ha)
1726 qla_printk(KERN_WARNING, ha, 1726 qla_printk(KERN_WARNING, ha,
1727 "MSI-X: Falling back-to INTa mode -- %d.\n", ret); 1727 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1728skip_msix: 1728skip_msix:
1729
1730 if (!IS_QLA24XX(ha))
1731 goto skip_msi;
1732
1733 ret = pci_enable_msi(ha->pdev);
1734 if (!ret) {
1735 DEBUG2(qla_printk(KERN_INFO, ha, "MSI: Enabled.\n"));
1736 ha->flags.msi_enabled = 1;
1737 }
1738skip_msi:
1739
1729 ret = request_irq(ha->pdev->irq, ha->isp_ops.intr_handler, 1740 ret = request_irq(ha->pdev->irq, ha->isp_ops.intr_handler,
1730 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha); 1741 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
1731 if (!ret) { 1742 if (!ret) {
@@ -1746,6 +1757,8 @@ qla2x00_free_irqs(scsi_qla_host_t *ha)
1746 1757
1747 if (ha->flags.msix_enabled) 1758 if (ha->flags.msix_enabled)
1748 qla24xx_disable_msix(ha); 1759 qla24xx_disable_msix(ha);
1749 else if (ha->flags.inta_enabled) 1760 else if (ha->flags.inta_enabled) {
1750 free_irq(ha->host->irq, ha); 1761 free_irq(ha->host->irq, ha);
1762 pci_disable_msi(ha->pdev);
1763 }
1751} 1764}
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index b78919a318e2..dd076da86a46 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -36,7 +36,7 @@ module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
36MODULE_PARM_DESC(ql2xlogintimeout, 36MODULE_PARM_DESC(ql2xlogintimeout,
37 "Login timeout value in seconds."); 37 "Login timeout value in seconds.");
38 38
39int qlport_down_retry = 30; 39int qlport_down_retry;
40module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR); 40module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
41MODULE_PARM_DESC(qlport_down_retry, 41MODULE_PARM_DESC(qlport_down_retry,
42 "Maximum number of command retries to a port that returns " 42 "Maximum number of command retries to a port that returns "
@@ -1577,9 +1577,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1577 goto probe_failed; 1577 goto probe_failed;
1578 } 1578 }
1579 1579
1580 if (qla2x00_initialize_adapter(ha) && 1580 if (qla2x00_initialize_adapter(ha)) {
1581 !(ha->device_flags & DFLG_NO_CABLE)) {
1582
1583 qla_printk(KERN_WARNING, ha, 1581 qla_printk(KERN_WARNING, ha,
1584 "Failed to initialize adapter\n"); 1582 "Failed to initialize adapter\n");
1585 1583
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index dc85495c337f..c375a4efbc71 100644
--- a/drivers/scsi/qla2xxx/qla_version.h
+++ b/drivers/scsi/qla2xxx/qla_version.h
@@ -7,7 +7,7 @@
7/* 7/*
8 * Driver version 8 * Driver version
9 */ 9 */
10#define QLA2XXX_VERSION "8.01.07-k6" 10#define QLA2XXX_VERSION "8.01.07-k7"
11 11
12#define QLA_DRIVER_MAJOR_VER 8 12#define QLA_DRIVER_MAJOR_VER 8
13#define QLA_DRIVER_MINOR_VER 1 13#define QLA_DRIVER_MINOR_VER 1
diff --git a/drivers/scsi/qla4xxx/ql4_dbg.c b/drivers/scsi/qla4xxx/ql4_dbg.c
index 7b4e077a39c1..6437d024b0dd 100644
--- a/drivers/scsi/qla4xxx/ql4_dbg.c
+++ b/drivers/scsi/qla4xxx/ql4_dbg.c
@@ -8,6 +8,8 @@
8#include "ql4_def.h" 8#include "ql4_def.h"
9#include <scsi/scsi_dbg.h> 9#include <scsi/scsi_dbg.h>
10 10
11#if 0
12
11static void qla4xxx_print_srb_info(struct srb * srb) 13static void qla4xxx_print_srb_info(struct srb * srb)
12{ 14{
13 printk("%s: srb = 0x%p, flags=0x%02x\n", __func__, srb, srb->flags); 15 printk("%s: srb = 0x%p, flags=0x%02x\n", __func__, srb, srb->flags);
@@ -195,3 +197,5 @@ void qla4xxx_dump_buffer(void *b, uint32_t size)
195 if (cnt % 16) 197 if (cnt % 16)
196 printk(KERN_DEBUG "\n"); 198 printk(KERN_DEBUG "\n");
197} 199}
200
201#endif /* 0 */
diff --git a/drivers/scsi/qla4xxx/ql4_glbl.h b/drivers/scsi/qla4xxx/ql4_glbl.h
index e021eb5db2b2..5b00cb04e7c0 100644
--- a/drivers/scsi/qla4xxx/ql4_glbl.h
+++ b/drivers/scsi/qla4xxx/ql4_glbl.h
@@ -43,8 +43,6 @@ int qla4xxx_get_fwddb_entry(struct scsi_qla_host *ha,
43 uint16_t *tcp_source_port_num, 43 uint16_t *tcp_source_port_num,
44 uint16_t *connection_id); 44 uint16_t *connection_id);
45 45
46struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host * ha,
47 uint32_t fw_ddb_index);
48int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index, 46int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
49 dma_addr_t fw_ddb_entry_dma); 47 dma_addr_t fw_ddb_entry_dma);
50 48
@@ -55,18 +53,11 @@ void qla4xxx_get_crash_record(struct scsi_qla_host * ha);
55struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha); 53struct ddb_entry *qla4xxx_alloc_sess(struct scsi_qla_host *ha);
56int qla4xxx_add_sess(struct ddb_entry *); 54int qla4xxx_add_sess(struct ddb_entry *);
57void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry); 55void qla4xxx_destroy_sess(struct ddb_entry *ddb_entry);
58int qla4xxx_conn_close_sess_logout(struct scsi_qla_host * ha,
59 uint16_t fw_ddb_index,
60 uint16_t connection_id,
61 uint16_t option);
62int qla4xxx_clear_database_entry(struct scsi_qla_host * ha,
63 uint16_t fw_ddb_index);
64int qla4xxx_is_nvram_configuration_valid(struct scsi_qla_host * ha); 56int qla4xxx_is_nvram_configuration_valid(struct scsi_qla_host * ha);
65int qla4xxx_get_fw_version(struct scsi_qla_host * ha); 57int qla4xxx_get_fw_version(struct scsi_qla_host * ha);
66void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha, 58void qla4xxx_interrupt_service_routine(struct scsi_qla_host * ha,
67 uint32_t intr_status); 59 uint32_t intr_status);
68int qla4xxx_init_rings(struct scsi_qla_host * ha); 60int qla4xxx_init_rings(struct scsi_qla_host * ha);
69void qla4xxx_dump_buffer(void *b, uint32_t size);
70struct srb * qla4xxx_del_from_active_array(struct scsi_qla_host *ha, uint32_t index); 61struct srb * qla4xxx_del_from_active_array(struct scsi_qla_host *ha, uint32_t index);
71void qla4xxx_srb_compl(struct scsi_qla_host *ha, struct srb *srb); 62void qla4xxx_srb_compl(struct scsi_qla_host *ha, struct srb *srb);
72int qla4xxx_reinitialize_ddb_list(struct scsi_qla_host * ha); 63int qla4xxx_reinitialize_ddb_list(struct scsi_qla_host * ha);
diff --git a/drivers/scsi/qla4xxx/ql4_init.c b/drivers/scsi/qla4xxx/ql4_init.c
index b907b06d72ab..6365df268612 100644
--- a/drivers/scsi/qla4xxx/ql4_init.c
+++ b/drivers/scsi/qla4xxx/ql4_init.c
@@ -7,9 +7,8 @@
7 7
8#include "ql4_def.h" 8#include "ql4_def.h"
9 9
10/* 10static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
11 * QLogic ISP4xxx Hardware Support Function Prototypes. 11 uint32_t fw_ddb_index);
12 */
13 12
14static void ql4xxx_set_mac_number(struct scsi_qla_host *ha) 13static void ql4xxx_set_mac_number(struct scsi_qla_host *ha)
15{ 14{
@@ -48,7 +47,8 @@ static void ql4xxx_set_mac_number(struct scsi_qla_host *ha)
48 * This routine deallocates and unlinks the specified ddb_entry from the 47 * This routine deallocates and unlinks the specified ddb_entry from the
49 * adapter's 48 * adapter's
50 **/ 49 **/
51void qla4xxx_free_ddb(struct scsi_qla_host *ha, struct ddb_entry *ddb_entry) 50static void qla4xxx_free_ddb(struct scsi_qla_host *ha,
51 struct ddb_entry *ddb_entry)
52{ 52{
53 /* Remove device entry from list */ 53 /* Remove device entry from list */
54 list_del_init(&ddb_entry->list); 54 list_del_init(&ddb_entry->list);
@@ -370,9 +370,9 @@ static struct ddb_entry* qla4xxx_get_ddb_entry(struct scsi_qla_host *ha,
370 * must be initialized prior to calling this routine 370 * must be initialized prior to calling this routine
371 * 371 *
372 **/ 372 **/
373int qla4xxx_update_ddb_entry(struct scsi_qla_host *ha, 373static int qla4xxx_update_ddb_entry(struct scsi_qla_host *ha,
374 struct ddb_entry *ddb_entry, 374 struct ddb_entry *ddb_entry,
375 uint32_t fw_ddb_index) 375 uint32_t fw_ddb_index)
376{ 376{
377 struct dev_db_entry *fw_ddb_entry = NULL; 377 struct dev_db_entry *fw_ddb_entry = NULL;
378 dma_addr_t fw_ddb_entry_dma; 378 dma_addr_t fw_ddb_entry_dma;
@@ -450,8 +450,8 @@ int qla4xxx_update_ddb_entry(struct scsi_qla_host *ha,
450 * This routine allocates a ddb_entry, ititializes some values, and 450 * This routine allocates a ddb_entry, ititializes some values, and
451 * inserts it into the ddb list. 451 * inserts it into the ddb list.
452 **/ 452 **/
453struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha, 453static struct ddb_entry * qla4xxx_alloc_ddb(struct scsi_qla_host *ha,
454 uint32_t fw_ddb_index) 454 uint32_t fw_ddb_index)
455{ 455{
456 struct ddb_entry *ddb_entry; 456 struct ddb_entry *ddb_entry;
457 457
diff --git a/drivers/scsi/qla4xxx/ql4_iocb.c b/drivers/scsi/qla4xxx/ql4_iocb.c
index d41ce380eedc..a216a1781afb 100644
--- a/drivers/scsi/qla4xxx/ql4_iocb.c
+++ b/drivers/scsi/qla4xxx/ql4_iocb.c
@@ -19,8 +19,8 @@
19 * - advances the request_in pointer 19 * - advances the request_in pointer
20 * - checks for queue full 20 * - checks for queue full
21 **/ 21 **/
22int qla4xxx_get_req_pkt(struct scsi_qla_host *ha, 22static int qla4xxx_get_req_pkt(struct scsi_qla_host *ha,
23 struct queue_entry **queue_entry) 23 struct queue_entry **queue_entry)
24{ 24{
25 uint16_t request_in; 25 uint16_t request_in;
26 uint8_t status = QLA_SUCCESS; 26 uint8_t status = QLA_SUCCESS;
@@ -62,8 +62,8 @@ int qla4xxx_get_req_pkt(struct scsi_qla_host *ha,
62 * 62 *
63 * This routine issues a marker IOCB. 63 * This routine issues a marker IOCB.
64 **/ 64 **/
65int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha, 65static int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha,
66 struct ddb_entry *ddb_entry, int lun) 66 struct ddb_entry *ddb_entry, int lun)
67{ 67{
68 struct marker_entry *marker_entry; 68 struct marker_entry *marker_entry;
69 unsigned long flags = 0; 69 unsigned long flags = 0;
@@ -96,7 +96,7 @@ exit_send_marker:
96 return status; 96 return status;
97} 97}
98 98
99struct continuation_t1_entry* qla4xxx_alloc_cont_entry( 99static struct continuation_t1_entry* qla4xxx_alloc_cont_entry(
100 struct scsi_qla_host *ha) 100 struct scsi_qla_host *ha)
101{ 101{
102 struct continuation_t1_entry *cont_entry; 102 struct continuation_t1_entry *cont_entry;
@@ -120,7 +120,7 @@ struct continuation_t1_entry* qla4xxx_alloc_cont_entry(
120 return cont_entry; 120 return cont_entry;
121} 121}
122 122
123uint16_t qla4xxx_calc_request_entries(uint16_t dsds) 123static uint16_t qla4xxx_calc_request_entries(uint16_t dsds)
124{ 124{
125 uint16_t iocbs; 125 uint16_t iocbs;
126 126
@@ -133,9 +133,9 @@ uint16_t qla4xxx_calc_request_entries(uint16_t dsds)
133 return iocbs; 133 return iocbs;
134} 134}
135 135
136void qla4xxx_build_scsi_iocbs(struct srb *srb, 136static void qla4xxx_build_scsi_iocbs(struct srb *srb,
137 struct command_t3_entry *cmd_entry, 137 struct command_t3_entry *cmd_entry,
138 uint16_t tot_dsds) 138 uint16_t tot_dsds)
139{ 139{
140 struct scsi_qla_host *ha; 140 struct scsi_qla_host *ha;
141 uint16_t avail_dsds; 141 uint16_t avail_dsds;
diff --git a/drivers/scsi/qla4xxx/ql4_mbx.c b/drivers/scsi/qla4xxx/ql4_mbx.c
index 7f28657eef3f..f116ff917237 100644
--- a/drivers/scsi/qla4xxx/ql4_mbx.c
+++ b/drivers/scsi/qla4xxx/ql4_mbx.c
@@ -20,9 +20,9 @@
20 * If outCount is 0, this routine completes successfully WITHOUT waiting 20 * If outCount is 0, this routine completes successfully WITHOUT waiting
21 * for the mailbox command to complete. 21 * for the mailbox command to complete.
22 **/ 22 **/
23int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount, 23static int qla4xxx_mailbox_command(struct scsi_qla_host *ha, uint8_t inCount,
24 uint8_t outCount, uint32_t *mbx_cmd, 24 uint8_t outCount, uint32_t *mbx_cmd,
25 uint32_t *mbx_sts) 25 uint32_t *mbx_sts)
26{ 26{
27 int status = QLA_ERROR; 27 int status = QLA_ERROR;
28 uint8_t i; 28 uint8_t i;
@@ -170,6 +170,8 @@ mbox_exit:
170} 170}
171 171
172 172
173#if 0
174
173/** 175/**
174 * qla4xxx_issue_iocb - issue mailbox iocb command 176 * qla4xxx_issue_iocb - issue mailbox iocb command
175 * @ha: adapter state pointer. 177 * @ha: adapter state pointer.
@@ -243,6 +245,8 @@ int qla4xxx_clear_database_entry(struct scsi_qla_host * ha,
243 return QLA_SUCCESS; 245 return QLA_SUCCESS;
244} 246}
245 247
248#endif /* 0 */
249
246/** 250/**
247 * qla4xxx_initialize_fw_cb - initializes firmware control block. 251 * qla4xxx_initialize_fw_cb - initializes firmware control block.
248 * @ha: Pointer to host adapter structure. 252 * @ha: Pointer to host adapter structure.
@@ -570,6 +574,7 @@ int qla4xxx_set_ddb_entry(struct scsi_qla_host * ha, uint16_t fw_ddb_index,
570 return qla4xxx_mailbox_command(ha, 4, 1, &mbox_cmd[0], &mbox_sts[0]); 574 return qla4xxx_mailbox_command(ha, 4, 1, &mbox_cmd[0], &mbox_sts[0]);
571} 575}
572 576
577#if 0
573int qla4xxx_conn_open_session_login(struct scsi_qla_host * ha, 578int qla4xxx_conn_open_session_login(struct scsi_qla_host * ha,
574 uint16_t fw_ddb_index) 579 uint16_t fw_ddb_index)
575{ 580{
@@ -594,6 +599,7 @@ int qla4xxx_conn_open_session_login(struct scsi_qla_host * ha,
594 599
595 return status; 600 return status;
596} 601}
602#endif /* 0 */
597 603
598/** 604/**
599 * qla4xxx_get_crash_record - retrieves crash record. 605 * qla4xxx_get_crash_record - retrieves crash record.
@@ -649,6 +655,7 @@ exit_get_crash_record:
649 crash_record, crash_record_dma); 655 crash_record, crash_record_dma);
650} 656}
651 657
658#if 0
652/** 659/**
653 * qla4xxx_get_conn_event_log - retrieves connection event log 660 * qla4xxx_get_conn_event_log - retrieves connection event log
654 * @ha: Pointer to host adapter structure. 661 * @ha: Pointer to host adapter structure.
@@ -738,6 +745,7 @@ exit_get_event_log:
738 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log, 745 dma_free_coherent(&ha->pdev->dev, event_log_size, event_log,
739 event_log_dma); 746 event_log_dma);
740} 747}
748#endif /* 0 */
741 749
742/** 750/**
743 * qla4xxx_reset_lun - issues LUN Reset 751 * qla4xxx_reset_lun - issues LUN Reset
@@ -834,7 +842,8 @@ int qla4xxx_get_fw_version(struct scsi_qla_host * ha)
834 return QLA_SUCCESS; 842 return QLA_SUCCESS;
835} 843}
836 844
837int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, dma_addr_t dma_addr) 845static int qla4xxx_get_default_ddb(struct scsi_qla_host *ha,
846 dma_addr_t dma_addr)
838{ 847{
839 uint32_t mbox_cmd[MBOX_REG_COUNT]; 848 uint32_t mbox_cmd[MBOX_REG_COUNT];
840 uint32_t mbox_sts[MBOX_REG_COUNT]; 849 uint32_t mbox_sts[MBOX_REG_COUNT];
@@ -855,7 +864,7 @@ int qla4xxx_get_default_ddb(struct scsi_qla_host *ha, dma_addr_t dma_addr)
855 return QLA_SUCCESS; 864 return QLA_SUCCESS;
856} 865}
857 866
858int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index) 867static int qla4xxx_req_ddb_entry(struct scsi_qla_host *ha, uint32_t *ddb_index)
859{ 868{
860 uint32_t mbox_cmd[MBOX_REG_COUNT]; 869 uint32_t mbox_cmd[MBOX_REG_COUNT];
861 uint32_t mbox_sts[MBOX_REG_COUNT]; 870 uint32_t mbox_sts[MBOX_REG_COUNT];
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 0bfddf893ed0..da21f5fbbf87 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -14,7 +14,7 @@
14/* 14/*
15 * Driver version 15 * Driver version
16 */ 16 */
17char qla4xxx_version_str[40]; 17static char qla4xxx_version_str[40];
18 18
19/* 19/*
20 * SRB allocation cache 20 * SRB allocation cache
@@ -45,8 +45,7 @@ int ql4_mod_unload = 0;
45/* 45/*
46 * SCSI host template entry points 46 * SCSI host template entry points
47 */ 47 */
48 48static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
49void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha);
50 49
51/* 50/*
52 * iSCSI template entry points 51 * iSCSI template entry points
@@ -1352,7 +1351,7 @@ static void __devexit qla4xxx_remove_adapter(struct pci_dev *pdev)
1352 * At exit, the @ha's flags.enable_64bit_addressing set to indicated 1351 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1353 * supported addressing method. 1352 * supported addressing method.
1354 */ 1353 */
1355void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha) 1354static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
1356{ 1355{
1357 int retval; 1356 int retval;
1358 1357
@@ -1627,7 +1626,7 @@ static struct pci_device_id qla4xxx_pci_tbl[] = {
1627}; 1626};
1628MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl); 1627MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);
1629 1628
1630struct pci_driver qla4xxx_pci_driver = { 1629static struct pci_driver qla4xxx_pci_driver = {
1631 .name = DRIVER_NAME, 1630 .name = DRIVER_NAME,
1632 .id_table = qla4xxx_pci_tbl, 1631 .id_table = qla4xxx_pci_tbl,
1633 .probe = qla4xxx_probe_adapter, 1632 .probe = qla4xxx_probe_adapter,
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 3e2930b7ee23..06229f225ee9 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -36,7 +36,6 @@
36#include <linux/fs.h> 36#include <linux/fs.h>
37#include <linux/init.h> 37#include <linux/init.h>
38#include <linux/proc_fs.h> 38#include <linux/proc_fs.h>
39#include <linux/smp_lock.h>
40#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
41#include <linux/moduleparam.h> 40#include <linux/moduleparam.h>
42 41
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 3963e7013bd9..e8350c562d24 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -38,7 +38,6 @@
38#include "scsi_logging.h" 38#include "scsi_logging.h"
39 39
40#define SENSE_TIMEOUT (10*HZ) 40#define SENSE_TIMEOUT (10*HZ)
41#define START_UNIT_TIMEOUT (30*HZ)
42 41
43/* 42/*
44 * These should *probably* be handled by the host itself. 43 * These should *probably* be handled by the host itself.
@@ -936,7 +935,7 @@ static int scsi_eh_try_stu(struct scsi_cmnd *scmd)
936 935
937 for (i = 0; rtn == NEEDS_RETRY && i < 2; i++) 936 for (i = 0; rtn == NEEDS_RETRY && i < 2; i++)
938 rtn = scsi_send_eh_cmnd(scmd, stu_command, 6, 937 rtn = scsi_send_eh_cmnd(scmd, stu_command, 6,
939 START_UNIT_TIMEOUT, 0); 938 scmd->device->timeout, 0);
940 939
941 if (rtn == SUCCESS) 940 if (rtn == SUCCESS)
942 return 0; 941 return 0;
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 61fbcdcbb009..1f5a07bf2a75 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -173,7 +173,7 @@ int scsi_queue_insert(struct scsi_cmnd *cmd, int reason)
173 * @retries: number of times to retry request 173 * @retries: number of times to retry request
174 * @flags: or into request flags; 174 * @flags: or into request flags;
175 * 175 *
176 * returns the req->errors value which is the the scsi_cmnd result 176 * returns the req->errors value which is the scsi_cmnd result
177 * field. 177 * field.
178 **/ 178 **/
179int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd, 179int scsi_execute(struct scsi_device *sdev, const unsigned char *cmd,
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index 14c4f065b2b8..b4d1ece46f78 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -1718,31 +1718,12 @@ fc_starget_delete(struct work_struct *work)
1718 struct fc_rport *rport = 1718 struct fc_rport *rport =
1719 container_of(work, struct fc_rport, stgt_delete_work); 1719 container_of(work, struct fc_rport, stgt_delete_work);
1720 struct Scsi_Host *shost = rport_to_shost(rport); 1720 struct Scsi_Host *shost = rport_to_shost(rport);
1721 unsigned long flags;
1722 struct fc_internal *i = to_fc_internal(shost->transportt); 1721 struct fc_internal *i = to_fc_internal(shost->transportt);
1723 1722
1724 /* 1723 /* Involve the LLDD if possible to terminate all io on the rport. */
1725 * Involve the LLDD if possible. All io on the rport is to 1724 if (i->f->terminate_rport_io)
1726 * be terminated, either as part of the dev_loss_tmo callback
1727 * processing, or via the terminate_rport_io function.
1728 */
1729 if (i->f->dev_loss_tmo_callbk)
1730 i->f->dev_loss_tmo_callbk(rport);
1731 else if (i->f->terminate_rport_io)
1732 i->f->terminate_rport_io(rport); 1725 i->f->terminate_rport_io(rport);
1733 1726
1734 spin_lock_irqsave(shost->host_lock, flags);
1735 if (rport->flags & FC_RPORT_DEVLOSS_PENDING) {
1736 spin_unlock_irqrestore(shost->host_lock, flags);
1737 if (!cancel_delayed_work(&rport->fail_io_work))
1738 fc_flush_devloss(shost);
1739 if (!cancel_delayed_work(&rport->dev_loss_work))
1740 fc_flush_devloss(shost);
1741 spin_lock_irqsave(shost->host_lock, flags);
1742 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1743 }
1744 spin_unlock_irqrestore(shost->host_lock, flags);
1745
1746 scsi_remove_target(&rport->dev); 1727 scsi_remove_target(&rport->dev);
1747} 1728}
1748 1729
@@ -1760,6 +1741,7 @@ fc_rport_final_delete(struct work_struct *work)
1760 struct device *dev = &rport->dev; 1741 struct device *dev = &rport->dev;
1761 struct Scsi_Host *shost = rport_to_shost(rport); 1742 struct Scsi_Host *shost = rport_to_shost(rport);
1762 struct fc_internal *i = to_fc_internal(shost->transportt); 1743 struct fc_internal *i = to_fc_internal(shost->transportt);
1744 unsigned long flags;
1763 1745
1764 /* 1746 /*
1765 * if a scan is pending, flush the SCSI Host work_q so that 1747 * if a scan is pending, flush the SCSI Host work_q so that
@@ -1768,13 +1750,37 @@ fc_rport_final_delete(struct work_struct *work)
1768 if (rport->flags & FC_RPORT_SCAN_PENDING) 1750 if (rport->flags & FC_RPORT_SCAN_PENDING)
1769 scsi_flush_work(shost); 1751 scsi_flush_work(shost);
1770 1752
1753 /* involve the LLDD to terminate all pending i/o */
1754 if (i->f->terminate_rport_io)
1755 i->f->terminate_rport_io(rport);
1756
1757 /*
1758 * Cancel any outstanding timers. These should really exist
1759 * only when rmmod'ing the LLDD and we're asking for
1760 * immediate termination of the rports
1761 */
1762 spin_lock_irqsave(shost->host_lock, flags);
1763 if (rport->flags & FC_RPORT_DEVLOSS_PENDING) {
1764 spin_unlock_irqrestore(shost->host_lock, flags);
1765 if (!cancel_delayed_work(&rport->fail_io_work))
1766 fc_flush_devloss(shost);
1767 if (!cancel_delayed_work(&rport->dev_loss_work))
1768 fc_flush_devloss(shost);
1769 spin_lock_irqsave(shost->host_lock, flags);
1770 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
1771 }
1772 spin_unlock_irqrestore(shost->host_lock, flags);
1773
1771 /* Delete SCSI target and sdevs */ 1774 /* Delete SCSI target and sdevs */
1772 if (rport->scsi_target_id != -1) 1775 if (rport->scsi_target_id != -1)
1773 fc_starget_delete(&rport->stgt_delete_work); 1776 fc_starget_delete(&rport->stgt_delete_work);
1774 else if (i->f->dev_loss_tmo_callbk) 1777
1778 /*
1779 * Notify the driver that the rport is now dead. The LLDD will
1780 * also guarantee that any communication to the rport is terminated
1781 */
1782 if (i->f->dev_loss_tmo_callbk)
1775 i->f->dev_loss_tmo_callbk(rport); 1783 i->f->dev_loss_tmo_callbk(rport);
1776 else if (i->f->terminate_rport_io)
1777 i->f->terminate_rport_io(rport);
1778 1784
1779 transport_remove_device(dev); 1785 transport_remove_device(dev);
1780 device_del(dev); 1786 device_del(dev);
@@ -1963,8 +1969,6 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1963 } 1969 }
1964 1970
1965 if (match) { 1971 if (match) {
1966 struct delayed_work *work =
1967 &rport->dev_loss_work;
1968 1972
1969 memcpy(&rport->node_name, &ids->node_name, 1973 memcpy(&rport->node_name, &ids->node_name,
1970 sizeof(rport->node_name)); 1974 sizeof(rport->node_name));
@@ -1982,46 +1986,61 @@ fc_remote_port_add(struct Scsi_Host *shost, int channel,
1982 fci->f->dd_fcrport_size); 1986 fci->f->dd_fcrport_size);
1983 1987
1984 /* 1988 /*
1985 * If we were blocked, we were a target. 1989 * If we were not a target, cancel the
1986 * If no longer a target, we leave the timer 1990 * io terminate and rport timers, and
1987 * running in case the port changes roles 1991 * we're done.
1988 * prior to the timer expiring. If the timer 1992 *
1989 * fires, the target will be torn down. 1993 * If we were a target, but our new role
1994 * doesn't indicate a target, leave the
1995 * timers running expecting the role to
1996 * change as the target fully logs in. If
1997 * it doesn't, the target will be torn down.
1998 *
1999 * If we were a target, and our role shows
2000 * we're still a target, cancel the timers
2001 * and kick off a scan.
1990 */ 2002 */
1991 if (!(ids->roles & FC_RPORT_ROLE_FCP_TARGET))
1992 return rport;
1993 2003
1994 /* restart the target */ 2004 /* was a target, not in roles */
2005 if ((rport->scsi_target_id != -1) &&
2006 (!(ids->roles & FC_RPORT_ROLE_FCP_TARGET)))
2007 return rport;
1995 2008
1996 /* 2009 /*
1997 * Stop the target timers first. Take no action 2010 * Stop the fail io and dev_loss timers.
1998 * on the del_timer failure as the state 2011 * If they flush, the port_state will
1999 * machine state change will validate the 2012 * be checked and will NOOP the function.
2000 * transaction.
2001 */ 2013 */
2002 if (!cancel_delayed_work(&rport->fail_io_work)) 2014 if (!cancel_delayed_work(&rport->fail_io_work))
2003 fc_flush_devloss(shost); 2015 fc_flush_devloss(shost);
2004 if (!cancel_delayed_work(work)) 2016 if (!cancel_delayed_work(&rport->dev_loss_work))
2005 fc_flush_devloss(shost); 2017 fc_flush_devloss(shost);
2006 2018
2007 spin_lock_irqsave(shost->host_lock, flags); 2019 spin_lock_irqsave(shost->host_lock, flags);
2008 2020
2009 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; 2021 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
2010 2022
2011 /* initiate a scan of the target */ 2023 /* if target, initiate a scan */
2012 rport->flags |= FC_RPORT_SCAN_PENDING; 2024 if (rport->scsi_target_id != -1) {
2013 scsi_queue_work(shost, &rport->scan_work); 2025 rport->flags |= FC_RPORT_SCAN_PENDING;
2014 2026 scsi_queue_work(shost,
2015 spin_unlock_irqrestore(shost->host_lock, flags); 2027 &rport->scan_work);
2016 2028 spin_unlock_irqrestore(shost->host_lock,
2017 scsi_target_unblock(&rport->dev); 2029 flags);
2030 scsi_target_unblock(&rport->dev);
2031 } else
2032 spin_unlock_irqrestore(shost->host_lock,
2033 flags);
2018 2034
2019 return rport; 2035 return rport;
2020 } 2036 }
2021 } 2037 }
2022 } 2038 }
2023 2039
2024 /* Search the bindings array */ 2040 /*
2041 * Search the bindings array
2042 * Note: if never a FCP target, you won't be on this list
2043 */
2025 if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) { 2044 if (fc_host->tgtid_bind_type != FC_TGTID_BIND_NONE) {
2026 2045
2027 /* search for a matching consistent binding */ 2046 /* search for a matching consistent binding */
@@ -2158,15 +2177,24 @@ fc_remote_port_delete(struct fc_rport *rport)
2158 2177
2159 spin_lock_irqsave(shost->host_lock, flags); 2178 spin_lock_irqsave(shost->host_lock, flags);
2160 2179
2161 /* If no scsi target id mapping, delete it */ 2180 if (rport->port_state != FC_PORTSTATE_ONLINE) {
2162 if (rport->scsi_target_id == -1) {
2163 list_del(&rport->peers);
2164 rport->port_state = FC_PORTSTATE_DELETED;
2165 fc_queue_work(shost, &rport->rport_delete_work);
2166 spin_unlock_irqrestore(shost->host_lock, flags); 2181 spin_unlock_irqrestore(shost->host_lock, flags);
2167 return; 2182 return;
2168 } 2183 }
2169 2184
2185 /*
2186 * In the past, we if this was not an FCP-Target, we would
2187 * unconditionally just jump to deleting the rport.
2188 * However, rports can be used as node containers by the LLDD,
2189 * and its not appropriate to just terminate the rport at the
2190 * first sign of a loss in connectivity. The LLDD may want to
2191 * send ELS traffic to re-validate the login. If the rport is
2192 * immediately deleted, it makes it inappropriate for a node
2193 * container.
2194 * So... we now unconditionally wait dev_loss_tmo before
2195 * destroying an rport.
2196 */
2197
2170 rport->port_state = FC_PORTSTATE_BLOCKED; 2198 rport->port_state = FC_PORTSTATE_BLOCKED;
2171 2199
2172 rport->flags |= FC_RPORT_DEVLOSS_PENDING; 2200 rport->flags |= FC_RPORT_DEVLOSS_PENDING;
@@ -2263,11 +2291,11 @@ fc_remote_port_rolechg(struct fc_rport *rport, u32 roles)
2263EXPORT_SYMBOL(fc_remote_port_rolechg); 2291EXPORT_SYMBOL(fc_remote_port_rolechg);
2264 2292
2265/** 2293/**
2266 * fc_timeout_deleted_rport - Timeout handler for a deleted remote port that 2294 * fc_timeout_deleted_rport - Timeout handler for a deleted remote port,
2267 * was a SCSI target (thus was blocked), and failed 2295 * which we blocked, and has now failed to return
2268 * to return in the alloted time. 2296 * in the allotted time.
2269 * 2297 *
2270 * @work: rport target that failed to reappear in the alloted time. 2298 * @work: rport target that failed to reappear in the allotted time.
2271 **/ 2299 **/
2272static void 2300static void
2273fc_timeout_deleted_rport(struct work_struct *work) 2301fc_timeout_deleted_rport(struct work_struct *work)
@@ -2283,10 +2311,12 @@ fc_timeout_deleted_rport(struct work_struct *work)
2283 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING; 2311 rport->flags &= ~FC_RPORT_DEVLOSS_PENDING;
2284 2312
2285 /* 2313 /*
2286 * If the port is ONLINE, then it came back. Validate it's still an 2314 * If the port is ONLINE, then it came back. If it was a SCSI
2287 * FCP target. If not, tear down the scsi_target on it. 2315 * target, validate it still is. If not, tear down the
2316 * scsi_target on it.
2288 */ 2317 */
2289 if ((rport->port_state == FC_PORTSTATE_ONLINE) && 2318 if ((rport->port_state == FC_PORTSTATE_ONLINE) &&
2319 (rport->scsi_target_id != -1) &&
2290 !(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) { 2320 !(rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
2291 dev_printk(KERN_ERR, &rport->dev, 2321 dev_printk(KERN_ERR, &rport->dev,
2292 "blocked FC remote port time out: no longer" 2322 "blocked FC remote port time out: no longer"
@@ -2297,18 +2327,24 @@ fc_timeout_deleted_rport(struct work_struct *work)
2297 return; 2327 return;
2298 } 2328 }
2299 2329
2330 /* NOOP state - we're flushing workq's */
2300 if (rport->port_state != FC_PORTSTATE_BLOCKED) { 2331 if (rport->port_state != FC_PORTSTATE_BLOCKED) {
2301 spin_unlock_irqrestore(shost->host_lock, flags); 2332 spin_unlock_irqrestore(shost->host_lock, flags);
2302 dev_printk(KERN_ERR, &rport->dev, 2333 dev_printk(KERN_ERR, &rport->dev,
2303 "blocked FC remote port time out: leaving target alone\n"); 2334 "blocked FC remote port time out: leaving"
2335 " rport%s alone\n",
2336 (rport->scsi_target_id != -1) ? " and starget" : "");
2304 return; 2337 return;
2305 } 2338 }
2306 2339
2307 if (fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) { 2340 if ((fc_host->tgtid_bind_type == FC_TGTID_BIND_NONE) ||
2341 (rport->scsi_target_id == -1)) {
2308 list_del(&rport->peers); 2342 list_del(&rport->peers);
2309 rport->port_state = FC_PORTSTATE_DELETED; 2343 rport->port_state = FC_PORTSTATE_DELETED;
2310 dev_printk(KERN_ERR, &rport->dev, 2344 dev_printk(KERN_ERR, &rport->dev,
2311 "blocked FC remote port time out: removing target\n"); 2345 "blocked FC remote port time out: removing"
2346 " rport%s\n",
2347 (rport->scsi_target_id != -1) ? " and starget" : "");
2312 fc_queue_work(shost, &rport->rport_delete_work); 2348 fc_queue_work(shost, &rport->rport_delete_work);
2313 spin_unlock_irqrestore(shost->host_lock, flags); 2349 spin_unlock_irqrestore(shost->host_lock, flags);
2314 return; 2350 return;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 570977cf9efb..0c691a60a756 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -41,7 +41,6 @@ static int sg_version_num = 30534; /* 2 digits for each component */
41#include <linux/fcntl.h> 41#include <linux/fcntl.h>
42#include <linux/init.h> 42#include <linux/init.h>
43#include <linux/poll.h> 43#include <linux/poll.h>
44#include <linux/smp_lock.h>
45#include <linux/moduleparam.h> 44#include <linux/moduleparam.h>
46#include <linux/cdev.h> 45#include <linux/cdev.h>
47#include <linux/seq_file.h> 46#include <linux/seq_file.h>
diff --git a/drivers/scsi/sgiwd93.c b/drivers/scsi/sgiwd93.c
index a15752b37990..eef82758d047 100644
--- a/drivers/scsi/sgiwd93.c
+++ b/drivers/scsi/sgiwd93.c
@@ -6,87 +6,49 @@
6 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com) 6 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
7 * Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu) 7 * Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu)
8 * Copyright (C) 2001 Florian Lohoff (flo@rfc822.org) 8 * Copyright (C) 2001 Florian Lohoff (flo@rfc822.org)
9 * Copyright (C) 2003 Ralf Baechle (ralf@linux-mips.org) 9 * Copyright (C) 2003, 07 Ralf Baechle (ralf@linux-mips.org)
10 * 10 *
11 * (In all truth, Jed Schimmel wrote all this code.) 11 * (In all truth, Jed Schimmel wrote all this code.)
12 */ 12 */
13#include <linux/init.h> 13
14#include <linux/interrupt.h> 14#undef DEBUG
15#include <linux/types.h> 15
16#include <linux/mm.h>
17#include <linux/blkdev.h>
18#include <linux/delay.h> 16#include <linux/delay.h>
19#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
18#include <linux/gfp.h>
19#include <linux/interrupt.h>
20#include <linux/init.h>
21#include <linux/kernel.h>
22#include <linux/types.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
20#include <linux/spinlock.h> 25#include <linux/spinlock.h>
21 26
22#include <asm/page.h>
23#include <asm/pgtable.h>
24#include <asm/sgialib.h>
25#include <asm/sgi/sgi.h>
26#include <asm/sgi/mc.h>
27#include <asm/sgi/hpc3.h> 27#include <asm/sgi/hpc3.h>
28#include <asm/sgi/ip22.h> 28#include <asm/sgi/ip22.h>
29#include <asm/irq.h> 29#include <asm/sgi/wd.h>
30#include <asm/io.h>
31 30
32#include "scsi.h" 31#include "scsi.h"
33#include <scsi/scsi_host.h>
34#include "wd33c93.h" 32#include "wd33c93.h"
35 33
36#include <linux/stat.h>
37
38#if 0
39#define DPRINTK(args...) printk(args)
40#else
41#define DPRINTK(args...)
42#endif
43
44#define HDATA(ptr) ((struct ip22_hostdata *)((ptr)->hostdata))
45
46struct ip22_hostdata { 34struct ip22_hostdata {
47 struct WD33C93_hostdata wh; 35 struct WD33C93_hostdata wh;
48 struct hpc_data { 36 struct hpc_data {
49 dma_addr_t dma; 37 dma_addr_t dma;
50 void * cpu; 38 void *cpu;
51 } hd; 39 } hd;
52}; 40};
53 41
42#define host_to_hostdata(host) ((struct ip22_hostdata *)((host)->hostdata))
43
54struct hpc_chunk { 44struct hpc_chunk {
55 struct hpc_dma_desc desc; 45 struct hpc_dma_desc desc;
56 u32 _padding; /* align to quadword boundary */ 46 u32 _padding; /* align to quadword boundary */
57}; 47};
58 48
59struct Scsi_Host *sgiwd93_host;
60struct Scsi_Host *sgiwd93_host1;
61
62/* Wuff wuff, wuff, wd33c93.c, wuff wuff, object oriented, bow wow. */
63static inline void write_wd33c93_count(const wd33c93_regs regs,
64 unsigned long value)
65{
66 *regs.SASR = WD_TRANSFER_COUNT_MSB;
67 mb();
68 *regs.SCMD = ((value >> 16) & 0xff);
69 *regs.SCMD = ((value >> 8) & 0xff);
70 *regs.SCMD = ((value >> 0) & 0xff);
71 mb();
72}
73
74static inline unsigned long read_wd33c93_count(const wd33c93_regs regs)
75{
76 unsigned long value;
77
78 *regs.SASR = WD_TRANSFER_COUNT_MSB;
79 mb();
80 value = ((*regs.SCMD & 0xff) << 16);
81 value |= ((*regs.SCMD & 0xff) << 8);
82 value |= ((*regs.SCMD & 0xff) << 0);
83 mb();
84 return value;
85}
86
87static irqreturn_t sgiwd93_intr(int irq, void *dev_id) 49static irqreturn_t sgiwd93_intr(int irq, void *dev_id)
88{ 50{
89 struct Scsi_Host * host = (struct Scsi_Host *) dev_id; 51 struct Scsi_Host * host = dev_id;
90 unsigned long flags; 52 unsigned long flags;
91 53
92 spin_lock_irqsave(host->host_lock, flags); 54 spin_lock_irqsave(host->host_lock, flags);
@@ -131,12 +93,12 @@ void fill_hpc_entries(struct hpc_chunk *hcp, struct scsi_cmnd *cmd, int datainp)
131 93
132static int dma_setup(struct scsi_cmnd *cmd, int datainp) 94static int dma_setup(struct scsi_cmnd *cmd, int datainp)
133{ 95{
134 struct ip22_hostdata *hdata = HDATA(cmd->device->host); 96 struct ip22_hostdata *hdata = host_to_hostdata(cmd->device->host);
135 struct hpc3_scsiregs *hregs = 97 struct hpc3_scsiregs *hregs =
136 (struct hpc3_scsiregs *) cmd->device->host->base; 98 (struct hpc3_scsiregs *) cmd->device->host->base;
137 struct hpc_chunk *hcp = (struct hpc_chunk *) hdata->hd.cpu; 99 struct hpc_chunk *hcp = (struct hpc_chunk *) hdata->hd.cpu;
138 100
139 DPRINTK("dma_setup: datainp<%d> hcp<%p> ", datainp, hcp); 101 pr_debug("dma_setup: datainp<%d> hcp<%p> ", datainp, hcp);
140 102
141 hdata->wh.dma_dir = datainp; 103 hdata->wh.dma_dir = datainp;
142 104
@@ -151,7 +113,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int datainp)
151 113
152 fill_hpc_entries(hcp, cmd, datainp); 114 fill_hpc_entries(hcp, cmd, datainp);
153 115
154 DPRINTK(" HPCGO\n"); 116 pr_debug(" HPCGO\n");
155 117
156 /* Start up the HPC. */ 118 /* Start up the HPC. */
157 hregs->ndptr = hdata->hd.dma; 119 hregs->ndptr = hdata->hd.dma;
@@ -166,7 +128,7 @@ static int dma_setup(struct scsi_cmnd *cmd, int datainp)
166static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt, 128static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
167 int status) 129 int status)
168{ 130{
169 struct ip22_hostdata *hdata = HDATA(instance); 131 struct ip22_hostdata *hdata = host_to_hostdata(instance);
170 struct hpc3_scsiregs *hregs; 132 struct hpc3_scsiregs *hregs;
171 133
172 if (!SCpnt) 134 if (!SCpnt)
@@ -174,7 +136,7 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
174 136
175 hregs = (struct hpc3_scsiregs *) SCpnt->device->host->base; 137 hregs = (struct hpc3_scsiregs *) SCpnt->device->host->base;
176 138
177 DPRINTK("dma_stop: status<%d> ", status); 139 pr_debug("dma_stop: status<%d> ", status);
178 140
179 /* First stop the HPC and flush it's FIFO. */ 141 /* First stop the HPC and flush it's FIFO. */
180 if (hdata->wh.dma_dir) { 142 if (hdata->wh.dma_dir) {
@@ -186,7 +148,7 @@ static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
186 dma_unmap_single(NULL, SCpnt->SCp.dma_handle, SCpnt->SCp.this_residual, 148 dma_unmap_single(NULL, SCpnt->SCp.dma_handle, SCpnt->SCp.this_residual,
187 SCpnt->sc_data_direction); 149 SCpnt->sc_data_direction);
188 150
189 DPRINTK("\n"); 151 pr_debug("\n");
190} 152}
191 153
192void sgiwd93_reset(unsigned long base) 154void sgiwd93_reset(unsigned long base)
@@ -216,29 +178,71 @@ static inline void init_hpc_chain(struct hpc_data *hd)
216 hcp->desc.pnext = hd->dma; 178 hcp->desc.pnext = hd->dma;
217} 179}
218 180
219static struct Scsi_Host * __init sgiwd93_setup_scsi( 181static int sgiwd93_bus_reset(struct scsi_cmnd *cmd)
220 struct scsi_host_template *SGIblows, int unit, int irq, 182{
221 struct hpc3_scsiregs *hregs, unsigned char *wdregs) 183 /* FIXME perform bus-specific reset */
184
185 /* FIXME 2: kill this function, and let midlayer fallback
186 to the same result, calling wd33c93_host_reset() */
187
188 spin_lock_irq(cmd->device->host->host_lock);
189 wd33c93_host_reset(cmd);
190 spin_unlock_irq(cmd->device->host->host_lock);
191
192 return SUCCESS;
193}
194
195/*
196 * Kludge alert - the SCSI code calls the abort and reset method with int
197 * arguments not with pointers. So this is going to blow up beautyfully
198 * on 64-bit systems with memory outside the compat address spaces.
199 */
200static struct scsi_host_template sgiwd93_template = {
201 .module = THIS_MODULE,
202 .proc_name = "SGIWD93",
203 .name = "SGI WD93",
204 .queuecommand = wd33c93_queuecommand,
205 .eh_abort_handler = wd33c93_abort,
206 .eh_bus_reset_handler = sgiwd93_bus_reset,
207 .eh_host_reset_handler = wd33c93_host_reset,
208 .can_queue = 16,
209 .this_id = 7,
210 .sg_tablesize = SG_ALL,
211 .cmd_per_lun = 8,
212 .use_clustering = DISABLE_CLUSTERING,
213};
214
215static int __init sgiwd93_probe(struct platform_device *pdev)
222{ 216{
217 struct sgiwd93_platform_data *pd = pdev->dev.platform_data;
218 unsigned char *wdregs = pd->wdregs;
219 struct hpc3_scsiregs *hregs = pd->hregs;
223 struct ip22_hostdata *hdata; 220 struct ip22_hostdata *hdata;
224 struct Scsi_Host *host; 221 struct Scsi_Host *host;
225 wd33c93_regs regs; 222 wd33c93_regs regs;
226 223 unsigned int unit = pd->unit;
227 host = scsi_register(SGIblows, sizeof(struct ip22_hostdata)); 224 unsigned int irq = pd->irq;
228 if (!host) 225 int err;
229 return NULL; 226
227 host = scsi_host_alloc(&sgiwd93_template, sizeof(struct ip22_hostdata));
228 if (!host) {
229 err = -ENOMEM;
230 goto out;
231 }
230 232
231 host->base = (unsigned long) hregs; 233 host->base = (unsigned long) hregs;
232 host->irq = irq; 234 host->irq = irq;
233 235
234 hdata = HDATA(host); 236 hdata = host_to_hostdata(host);
235 hdata->hd.cpu = dma_alloc_coherent(NULL, PAGE_SIZE, &hdata->hd.dma, 237 hdata->hd.cpu = dma_alloc_coherent(&pdev->dev, PAGE_SIZE,
236 GFP_KERNEL); 238 &hdata->hd.dma, GFP_KERNEL);
237 if (!hdata->hd.cpu) { 239 if (!hdata->hd.cpu) {
238 printk(KERN_WARNING "sgiwd93: Could not allocate memory for " 240 printk(KERN_WARNING "sgiwd93: Could not allocate memory for "
239 "host %d buffer.\n", unit); 241 "host %d buffer.\n", unit);
240 goto out_unregister; 242 err = -ENOMEM;
243 goto out_put;
241 } 244 }
245
242 init_hpc_chain(&hdata->hd); 246 init_hpc_chain(&hdata->hd);
243 247
244 regs.SASR = wdregs + 3; 248 regs.SASR = wdregs + 3;
@@ -249,95 +253,67 @@ static struct Scsi_Host * __init sgiwd93_setup_scsi(
249 if (hdata->wh.no_sync == 0xff) 253 if (hdata->wh.no_sync == 0xff)
250 hdata->wh.no_sync = 0; 254 hdata->wh.no_sync = 0;
251 255
252 if (request_irq(irq, sgiwd93_intr, 0, "SGI WD93", (void *) host)) { 256 err = request_irq(irq, sgiwd93_intr, 0, "SGI WD93", host);
257 if (err) {
253 printk(KERN_WARNING "sgiwd93: Could not register irq %d " 258 printk(KERN_WARNING "sgiwd93: Could not register irq %d "
254 "for host %d.\n", irq, unit); 259 "for host %d.\n", irq, unit);
255 goto out_free; 260 goto out_free;
256 } 261 }
257 return host;
258 262
259out_free: 263 platform_set_drvdata(pdev, host);
260 dma_free_coherent(NULL, PAGE_SIZE, hdata->hd.cpu, hdata->hd.dma);
261 wd33c93_release();
262 264
263out_unregister: 265 err = scsi_add_host(host, NULL);
264 scsi_unregister(host); 266 if (err)
267 goto out_irq;
265 268
266 return NULL; 269 scsi_scan_host(host);
267}
268
269static int __init sgiwd93_detect(struct scsi_host_template *SGIblows)
270{
271 int found = 0;
272
273 SGIblows->proc_name = "SGIWD93";
274 sgiwd93_host = sgiwd93_setup_scsi(SGIblows, 0, SGI_WD93_0_IRQ,
275 &hpc3c0->scsi_chan0,
276 (unsigned char *)hpc3c0->scsi0_ext);
277 if (sgiwd93_host)
278 found++;
279
280 /* Set up second controller on the Indigo2 */
281 if (ip22_is_fullhouse()) {
282 sgiwd93_host1 = sgiwd93_setup_scsi(SGIblows, 1, SGI_WD93_1_IRQ,
283 &hpc3c0->scsi_chan1,
284 (unsigned char *)hpc3c0->scsi1_ext);
285 if (sgiwd93_host1)
286 found++;
287 }
288
289 return found;
290}
291 270
292static int sgiwd93_release(struct Scsi_Host *instance) 271 return 0;
293{
294 struct ip22_hostdata *hdata = HDATA(instance);
295 int irq = 0;
296
297 if (sgiwd93_host && sgiwd93_host == instance)
298 irq = SGI_WD93_0_IRQ;
299 else if (sgiwd93_host1 && sgiwd93_host1 == instance)
300 irq = SGI_WD93_1_IRQ;
301 272
302 free_irq(irq, sgiwd93_intr); 273out_irq:
274 free_irq(irq, host);
275out_free:
303 dma_free_coherent(NULL, PAGE_SIZE, hdata->hd.cpu, hdata->hd.dma); 276 dma_free_coherent(NULL, PAGE_SIZE, hdata->hd.cpu, hdata->hd.dma);
304 wd33c93_release(); 277out_put:
278 scsi_host_put(host);
279out:
305 280
306 return 1; 281 return err;
307} 282}
308 283
309static int sgiwd93_bus_reset(struct scsi_cmnd *cmd) 284static void __exit sgiwd93_remove(struct platform_device *pdev)
310{ 285{
311 /* FIXME perform bus-specific reset */ 286 struct Scsi_Host *host = platform_get_drvdata(pdev);
287 struct ip22_hostdata *hdata = (struct ip22_hostdata *) host->hostdata;
288 struct sgiwd93_platform_data *pd = pdev->dev.platform_data;
289
290 scsi_remove_host(host);
291 free_irq(pd->irq, host);
292 dma_free_coherent(&pdev->dev, PAGE_SIZE, hdata->hd.cpu, hdata->hd.dma);
293 scsi_host_put(host);
294}
312 295
313 /* FIXME 2: kill this function, and let midlayer fallback 296static struct platform_driver sgiwd93_driver = {
314 to the same result, calling wd33c93_host_reset() */ 297 .probe = sgiwd93_probe,
298 .remove = __devexit_p(sgiwd93_remove),
299 .driver = {
300 .name = "sgiwd93"
301 }
302};
315 303
316 spin_lock_irq(cmd->device->host->host_lock); 304static int __init sgiwd93_module_init(void)
317 wd33c93_host_reset(cmd); 305{
318 spin_unlock_irq(cmd->device->host->host_lock); 306 return platform_driver_register(&sgiwd93_driver);
307}
319 308
320 return SUCCESS; 309static void __exit sgiwd93_module_exit(void)
310{
311 return platform_driver_unregister(&sgiwd93_driver);
321} 312}
322 313
323/* 314module_init(sgiwd93_module_init);
324 * Kludge alert - the SCSI code calls the abort and reset method with int 315module_exit(sgiwd93_module_exit);
325 * arguments not with pointers. So this is going to blow up beautyfully 316
326 * on 64-bit systems with memory outside the compat address spaces. 317MODULE_DESCRIPTION("SGI WD33C93 driver");
327 */ 318MODULE_AUTHOR("Ralf Baechle <ralf@linux-mips.org>");
328static struct scsi_host_template driver_template = { 319MODULE_LICENSE("GPL");
329 .proc_name = "SGIWD93",
330 .name = "SGI WD93",
331 .detect = sgiwd93_detect,
332 .release = sgiwd93_release,
333 .queuecommand = wd33c93_queuecommand,
334 .eh_abort_handler = wd33c93_abort,
335 .eh_bus_reset_handler = sgiwd93_bus_reset,
336 .eh_host_reset_handler = wd33c93_host_reset,
337 .can_queue = 16,
338 .this_id = 7,
339 .sg_tablesize = SG_ALL,
340 .cmd_per_lun = 8,
341 .use_clustering = DISABLE_CLUSTERING,
342};
343#include "scsi_module.c"
diff --git a/drivers/scsi/sni_53c710.c b/drivers/scsi/sni_53c710.c
index 6bc505115841..a7dfb65fb842 100644
--- a/drivers/scsi/sni_53c710.c
+++ b/drivers/scsi/sni_53c710.c
@@ -98,7 +98,7 @@ static int __init snirm710_probe(struct platform_device *dev)
98 host->this_id = 7; 98 host->this_id = 7;
99 host->base = base; 99 host->base = base;
100 host->irq = platform_get_irq(dev, 0); 100 host->irq = platform_get_irq(dev, 0);
101 if(request_irq(host->irq, NCR_700_intr, SA_SHIRQ, "snirm710", host)) { 101 if(request_irq(host->irq, NCR_700_intr, IRQF_SHARED, "snirm710", host)) {
102 printk(KERN_ERR "snirm710: request_irq failed!\n"); 102 printk(KERN_ERR "snirm710: request_irq failed!\n");
103 goto out_put_host; 103 goto out_put_host;
104 } 104 }
diff --git a/drivers/scsi/tmscsim.c b/drivers/scsi/tmscsim.c
index 3158949ffa62..e7b85e832eb5 100644
--- a/drivers/scsi/tmscsim.c
+++ b/drivers/scsi/tmscsim.c
@@ -351,6 +351,27 @@ static u8 dc390_clock_speed[] = {100,80,67,57,50, 40, 31, 20};
351 * (DCBs, SRBs, Queueing) 351 * (DCBs, SRBs, Queueing)
352 * 352 *
353 **********************************************************************/ 353 **********************************************************************/
354static void inline dc390_start_segment(struct dc390_srb* pSRB)
355{
356 struct scatterlist *psgl = pSRB->pSegmentList;
357
358 /* start new sg segment */
359 pSRB->SGBusAddr = sg_dma_address(psgl);
360 pSRB->SGToBeXferLen = sg_dma_len(psgl);
361}
362
363static unsigned long inline dc390_advance_segment(struct dc390_srb* pSRB, u32 residue)
364{
365 unsigned long xfer = pSRB->SGToBeXferLen - residue;
366
367 /* xfer more bytes transferred */
368 pSRB->SGBusAddr += xfer;
369 pSRB->TotalXferredLen += xfer;
370 pSRB->SGToBeXferLen = residue;
371
372 return xfer;
373}
374
354static struct dc390_dcb __inline__ *dc390_findDCB ( struct dc390_acb* pACB, u8 id, u8 lun) 375static struct dc390_dcb __inline__ *dc390_findDCB ( struct dc390_acb* pACB, u8 id, u8 lun)
355{ 376{
356 struct dc390_dcb* pDCB = pACB->pLinkDCB; if (!pDCB) return NULL; 377 struct dc390_dcb* pDCB = pACB->pLinkDCB; if (!pDCB) return NULL;
@@ -625,70 +646,6 @@ dc390_StartSCSI( struct dc390_acb* pACB, struct dc390_dcb* pDCB, struct dc390_sr
625 return 0; 646 return 0;
626} 647}
627 648
628//#define DMA_INT EN_DMA_INT /*| EN_PAGE_INT*/
629#define DMA_INT 0
630
631#if DMA_INT
632/* This is similar to AM53C974.c ... */
633static u8
634dc390_dma_intr (struct dc390_acb* pACB)
635{
636 struct dc390_srb* pSRB;
637 u8 dstate;
638 DEBUG0(u16 pstate; struct pci_dev *pdev = pACB->pdev);
639
640 DEBUG0(pci_read_config_word(pdev, PCI_STATUS, &pstate));
641 DEBUG0(if (pstate & (PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY))\
642 { printk(KERN_WARNING "DC390: PCI state = %04x!\n", pstate); \
643 pci_write_config_word(pdev, PCI_STATUS, (PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY));});
644
645 dstate = DC390_read8 (DMA_Status);
646
647 if (! pACB->pActiveDCB || ! pACB->pActiveDCB->pActiveSRB) return dstate;
648 else pSRB = pACB->pActiveDCB->pActiveSRB;
649
650 if (dstate & (DMA_XFER_ABORT | DMA_XFER_ERROR | POWER_DOWN | PCI_MS_ABORT))
651 {
652 printk (KERN_ERR "DC390: DMA error (%02x)!\n", dstate);
653 return dstate;
654 }
655 if (dstate & DMA_XFER_DONE)
656 {
657 u32 residual, xferCnt; int ctr = 6000000;
658 if (! (DC390_read8 (DMA_Cmd) & READ_DIRECTION))
659 {
660 do
661 {
662 DEBUG1(printk (KERN_DEBUG "DC390: read residual bytes ... \n"));
663 dstate = DC390_read8 (DMA_Status);
664 residual = DC390_read8 (CtcReg_Low) | DC390_read8 (CtcReg_Mid) << 8 |
665 DC390_read8 (CtcReg_High) << 16;
666 residual += DC390_read8 (Current_Fifo) & 0x1f;
667 } while (residual && ! (dstate & SCSI_INTERRUPT) && --ctr);
668 if (!ctr) printk (KERN_CRIT "DC390: dma_intr: DMA aborted unfinished: %06x bytes remain!!\n", DC390_read32 (DMA_Wk_ByteCntr));
669 /* residual = ... */
670 }
671 else
672 residual = 0;
673
674 /* ??? */
675
676 xferCnt = pSRB->SGToBeXferLen - residual;
677 pSRB->SGBusAddr += xferCnt;
678 pSRB->TotalXferredLen += xferCnt;
679 pSRB->SGToBeXferLen = residual;
680# ifdef DC390_DEBUG0
681 printk (KERN_INFO "DC390: DMA: residual = %i, xfer = %i\n",
682 (unsigned int)residual, (unsigned int)xferCnt);
683# endif
684
685 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD);
686 }
687 dc390_laststatus &= ~0xff000000; dc390_laststatus |= dstate << 24;
688 return dstate;
689}
690#endif
691
692 649
693static void __inline__ 650static void __inline__
694dc390_InvalidCmd(struct dc390_acb* pACB) 651dc390_InvalidCmd(struct dc390_acb* pACB)
@@ -708,9 +665,6 @@ DC390_Interrupt(void *dev_id)
708 u8 phase; 665 u8 phase;
709 void (*stateV)( struct dc390_acb*, struct dc390_srb*, u8 *); 666 void (*stateV)( struct dc390_acb*, struct dc390_srb*, u8 *);
710 u8 istate, istatus; 667 u8 istate, istatus;
711#if DMA_INT
712 u8 dstatus;
713#endif
714 668
715 sstatus = DC390_read8 (Scsi_Status); 669 sstatus = DC390_read8 (Scsi_Status);
716 if( !(sstatus & INTERRUPT) ) 670 if( !(sstatus & INTERRUPT) )
@@ -718,22 +672,9 @@ DC390_Interrupt(void *dev_id)
718 672
719 DEBUG1(printk (KERN_DEBUG "sstatus=%02x,", sstatus)); 673 DEBUG1(printk (KERN_DEBUG "sstatus=%02x,", sstatus));
720 674
721#if DMA_INT
722 spin_lock_irq(pACB->pScsiHost->host_lock);
723 dstatus = dc390_dma_intr (pACB);
724 spin_unlock_irq(pACB->pScsiHost->host_lock);
725
726 DEBUG1(printk (KERN_DEBUG "dstatus=%02x,", dstatus));
727 if (! (dstatus & SCSI_INTERRUPT))
728 {
729 DEBUG0(printk (KERN_WARNING "DC390 Int w/o SCSI actions (only DMA?)\n"));
730 return IRQ_NONE;
731 }
732#else
733 //DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT); 675 //DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT);
734 //dstatus = DC390_read8 (DMA_Status); 676 //dstatus = DC390_read8 (DMA_Status);
735 //DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT); 677 //DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT);
736#endif
737 678
738 spin_lock_irq(pACB->pScsiHost->host_lock); 679 spin_lock_irq(pACB->pScsiHost->host_lock);
739 680
@@ -821,11 +762,10 @@ static irqreturn_t do_DC390_Interrupt(int irq, void *dev_id)
821} 762}
822 763
823static void 764static void
824dc390_DataOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) 765dc390_DataOut_0(struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
825{ 766{
826 u8 sstatus; 767 u8 sstatus;
827 struct scatterlist *psgl; 768 u32 ResidCnt;
828 u32 ResidCnt, xferCnt;
829 u8 dstate = 0; 769 u8 dstate = 0;
830 770
831 sstatus = *psstatus; 771 sstatus = *psstatus;
@@ -856,42 +796,35 @@ dc390_DataOut_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
856 if( pSRB->SGIndex < pSRB->SGcount ) 796 if( pSRB->SGIndex < pSRB->SGcount )
857 { 797 {
858 pSRB->pSegmentList++; 798 pSRB->pSegmentList++;
859 psgl = pSRB->pSegmentList;
860 799
861 pSRB->SGBusAddr = cpu_to_le32(pci_dma_lo32(sg_dma_address(psgl))); 800 dc390_start_segment(pSRB);
862 pSRB->SGToBeXferLen = cpu_to_le32(sg_dma_len(psgl));
863 } 801 }
864 else 802 else
865 pSRB->SGToBeXferLen = 0; 803 pSRB->SGToBeXferLen = 0;
866 } 804 }
867 else 805 else
868 { 806 {
869 ResidCnt = (u32) DC390_read8 (Current_Fifo) & 0x1f; 807 ResidCnt = ((u32) DC390_read8 (Current_Fifo) & 0x1f) +
870 ResidCnt |= (u32) DC390_read8 (CtcReg_High) << 16; 808 (((u32) DC390_read8 (CtcReg_High) << 16) |
871 ResidCnt |= (u32) DC390_read8 (CtcReg_Mid) << 8; 809 ((u32) DC390_read8 (CtcReg_Mid) << 8) |
872 ResidCnt += (u32) DC390_read8 (CtcReg_Low); 810 (u32) DC390_read8 (CtcReg_Low));
873 811
874 xferCnt = pSRB->SGToBeXferLen - ResidCnt; 812 dc390_advance_segment(pSRB, ResidCnt);
875 pSRB->SGBusAddr += xferCnt;
876 pSRB->TotalXferredLen += xferCnt;
877 pSRB->SGToBeXferLen = ResidCnt;
878 } 813 }
879 } 814 }
880 if ((*psstatus & 7) != SCSI_DATA_OUT) 815 if ((*psstatus & 7) != SCSI_DATA_OUT)
881 { 816 {
882 DC390_write8 (DMA_Cmd, WRITE_DIRECTION+DMA_IDLE_CMD); /* | DMA_INT */ 817 DC390_write8 (DMA_Cmd, WRITE_DIRECTION+DMA_IDLE_CMD);
883 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); 818 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
884 } 819 }
885} 820}
886 821
887static void 822static void
888dc390_DataIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus) 823dc390_DataIn_0(struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
889{ 824{
890 u8 sstatus, residual, bval; 825 u8 sstatus, residual, bval;
891 struct scatterlist *psgl; 826 u32 ResidCnt, i;
892 u32 ResidCnt, i;
893 unsigned long xferCnt; 827 unsigned long xferCnt;
894 u8 *ptr;
895 828
896 sstatus = *psstatus; 829 sstatus = *psstatus;
897 830
@@ -922,19 +855,17 @@ dc390_DataIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
922 DEBUG1(ResidCnt = ((unsigned long) DC390_read8 (CtcReg_High) << 16) \ 855 DEBUG1(ResidCnt = ((unsigned long) DC390_read8 (CtcReg_High) << 16) \
923 + ((unsigned long) DC390_read8 (CtcReg_Mid) << 8) \ 856 + ((unsigned long) DC390_read8 (CtcReg_Mid) << 8) \
924 + ((unsigned long) DC390_read8 (CtcReg_Low))); 857 + ((unsigned long) DC390_read8 (CtcReg_Low)));
925 DEBUG1(printk (KERN_DEBUG "Count_2_Zero (ResidCnt=%i,ToBeXfer=%li),", ResidCnt, pSRB->SGToBeXferLen)); 858 DEBUG1(printk (KERN_DEBUG "Count_2_Zero (ResidCnt=%u,ToBeXfer=%lu),", ResidCnt, pSRB->SGToBeXferLen));
926 859
927 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD); /* | DMA_INT */ 860 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD);
928 861
929 pSRB->TotalXferredLen += pSRB->SGToBeXferLen; 862 pSRB->TotalXferredLen += pSRB->SGToBeXferLen;
930 pSRB->SGIndex++; 863 pSRB->SGIndex++;
931 if( pSRB->SGIndex < pSRB->SGcount ) 864 if( pSRB->SGIndex < pSRB->SGcount )
932 { 865 {
933 pSRB->pSegmentList++; 866 pSRB->pSegmentList++;
934 psgl = pSRB->pSegmentList;
935 867
936 pSRB->SGBusAddr = cpu_to_le32(pci_dma_lo32(sg_dma_address(psgl))); 868 dc390_start_segment(pSRB);
937 pSRB->SGToBeXferLen = cpu_to_le32(sg_dma_len(psgl));
938 } 869 }
939 else 870 else
940 pSRB->SGToBeXferLen = 0; 871 pSRB->SGToBeXferLen = 0;
@@ -973,47 +904,45 @@ din_1:
973 } 904 }
974 /* It seems a DMA Blast abort isn't that bad ... */ 905 /* It seems a DMA Blast abort isn't that bad ... */
975 if (!i) printk (KERN_ERR "DC390: DMA Blast aborted unfinished!\n"); 906 if (!i) printk (KERN_ERR "DC390: DMA Blast aborted unfinished!\n");
976 //DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD); /* | DMA_INT */ 907 //DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD);
977 dc390_laststatus &= ~0xff000000; dc390_laststatus |= bval << 24; 908 dc390_laststatus &= ~0xff000000;
909 dc390_laststatus |= bval << 24;
978 910
979 DEBUG1(printk (KERN_DEBUG "Blast: Read %i times DMA_Status %02x", 0xa000-i, bval)); 911 DEBUG1(printk (KERN_DEBUG "Blast: Read %i times DMA_Status %02x", 0xa000-i, bval));
980 ResidCnt = (u32) DC390_read8 (CtcReg_High); 912 ResidCnt = (((u32) DC390_read8 (CtcReg_High) << 16) |
981 ResidCnt <<= 8; 913 ((u32) DC390_read8 (CtcReg_Mid) << 8)) |
982 ResidCnt |= (u32) DC390_read8 (CtcReg_Mid); 914 (u32) DC390_read8 (CtcReg_Low);
983 ResidCnt <<= 8; 915
984 ResidCnt |= (u32) DC390_read8 (CtcReg_Low); 916 xferCnt = dc390_advance_segment(pSRB, ResidCnt);
985 917
986 xferCnt = pSRB->SGToBeXferLen - ResidCnt; 918 if (residual) {
987 pSRB->SGBusAddr += xferCnt; 919 size_t count = 1;
988 pSRB->TotalXferredLen += xferCnt; 920 size_t offset = pSRB->SGBusAddr - sg_dma_address(pSRB->pSegmentList);
989 pSRB->SGToBeXferLen = ResidCnt; 921 unsigned long flags;
990 922 u8 *ptr;
991 if( residual ) 923
992 {
993 static int feedback_requested;
994 bval = DC390_read8 (ScsiFifo); /* get one residual byte */ 924 bval = DC390_read8 (ScsiFifo); /* get one residual byte */
995 925
996 if (!feedback_requested) { 926 local_irq_save(flags);
997 feedback_requested = 1; 927 ptr = scsi_kmap_atomic_sg(pSRB->pSegmentList, pSRB->SGcount, &offset, &count);
998 printk(KERN_WARNING "%s: Please, contact <linux-scsi@vger.kernel.org> " 928 if (likely(ptr)) {
999 "to help improve support for your system.\n", __FILE__); 929 *(ptr + offset) = bval;
930 scsi_kunmap_atomic_sg(ptr);
1000 } 931 }
932 local_irq_restore(flags);
933 WARN_ON(!ptr);
1001 934
1002 ptr = (u8 *) bus_to_virt( pSRB->SGBusAddr ); 935 /* 1 more byte read */
1003 *ptr = bval; 936 xferCnt += dc390_advance_segment(pSRB, pSRB->SGToBeXferLen - 1);
1004 pSRB->SGBusAddr++; xferCnt++;
1005 pSRB->TotalXferredLen++;
1006 pSRB->SGToBeXferLen--;
1007 } 937 }
1008 DEBUG1(printk (KERN_DEBUG "Xfered: %li, Total: %li, Remaining: %li\n", xferCnt,\ 938 DEBUG1(printk (KERN_DEBUG "Xfered: %lu, Total: %lu, Remaining: %lu\n", xferCnt,\
1009 pSRB->TotalXferredLen, pSRB->SGToBeXferLen)); 939 pSRB->TotalXferredLen, pSRB->SGToBeXferLen));
1010
1011 } 940 }
1012 } 941 }
1013 if ((*psstatus & 7) != SCSI_DATA_IN) 942 if ((*psstatus & 7) != SCSI_DATA_IN)
1014 { 943 {
1015 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD); 944 DC390_write8 (ScsiCmd, CLEAR_FIFO_CMD);
1016 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD); /* | DMA_INT */ 945 DC390_write8 (DMA_Cmd, READ_DIRECTION+DMA_IDLE_CMD);
1017 } 946 }
1018} 947}
1019 948
@@ -1216,7 +1145,7 @@ dc390_MsgIn_set_sync (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1216 1145
1217 1146
1218/* handle RESTORE_PTR */ 1147/* handle RESTORE_PTR */
1219/* I presume, this command is already mapped, so, have to remap. */ 1148/* This doesn't look very healthy... to-be-fixed */
1220static void 1149static void
1221dc390_restore_ptr (struct dc390_acb* pACB, struct dc390_srb* pSRB) 1150dc390_restore_ptr (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1222{ 1151{
@@ -1225,6 +1154,7 @@ dc390_restore_ptr (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1225 pSRB->TotalXferredLen = 0; 1154 pSRB->TotalXferredLen = 0;
1226 pSRB->SGIndex = 0; 1155 pSRB->SGIndex = 0;
1227 if (pcmd->use_sg) { 1156 if (pcmd->use_sg) {
1157 size_t saved;
1228 pSRB->pSegmentList = (struct scatterlist *)pcmd->request_buffer; 1158 pSRB->pSegmentList = (struct scatterlist *)pcmd->request_buffer;
1229 psgl = pSRB->pSegmentList; 1159 psgl = pSRB->pSegmentList;
1230 //dc390_pci_sync(pSRB); 1160 //dc390_pci_sync(pSRB);
@@ -1236,15 +1166,16 @@ dc390_restore_ptr (struct dc390_acb* pACB, struct dc390_srb* pSRB)
1236 if( pSRB->SGIndex < pSRB->SGcount ) 1166 if( pSRB->SGIndex < pSRB->SGcount )
1237 { 1167 {
1238 pSRB->pSegmentList++; 1168 pSRB->pSegmentList++;
1239 psgl = pSRB->pSegmentList; 1169
1240 pSRB->SGBusAddr = cpu_to_le32(pci_dma_lo32(sg_dma_address(psgl))); 1170 dc390_start_segment(pSRB);
1241 pSRB->SGToBeXferLen = cpu_to_le32(sg_dma_len(psgl));
1242 } 1171 }
1243 else 1172 else
1244 pSRB->SGToBeXferLen = 0; 1173 pSRB->SGToBeXferLen = 0;
1245 } 1174 }
1246 pSRB->SGToBeXferLen -= (pSRB->Saved_Ptr - pSRB->TotalXferredLen); 1175
1247 pSRB->SGBusAddr += (pSRB->Saved_Ptr - pSRB->TotalXferredLen); 1176 saved = pSRB->Saved_Ptr - pSRB->TotalXferredLen;
1177 pSRB->SGToBeXferLen -= saved;
1178 pSRB->SGBusAddr += saved;
1248 printk (KERN_INFO "DC390: Pointer restored. Segment %i, Total %li, Bus %08lx\n", 1179 printk (KERN_INFO "DC390: Pointer restored. Segment %i, Total %li, Bus %08lx\n",
1249 pSRB->SGIndex, pSRB->Saved_Ptr, pSRB->SGBusAddr); 1180 pSRB->SGIndex, pSRB->Saved_Ptr, pSRB->SGBusAddr);
1250 1181
@@ -1365,7 +1296,6 @@ dc390_MsgIn_0( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 *psstatus)
1365static void 1296static void
1366dc390_DataIO_Comm( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 ioDir) 1297dc390_DataIO_Comm( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 ioDir)
1367{ 1298{
1368 struct scatterlist *psgl;
1369 unsigned long lval; 1299 unsigned long lval;
1370 struct dc390_dcb* pDCB = pACB->pActiveDCB; 1300 struct dc390_dcb* pDCB = pACB->pActiveDCB;
1371 1301
@@ -1391,12 +1321,11 @@ dc390_DataIO_Comm( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 ioDir)
1391 1321
1392 if( pSRB->SGIndex < pSRB->SGcount ) 1322 if( pSRB->SGIndex < pSRB->SGcount )
1393 { 1323 {
1394 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir /* | DMA_INT */); 1324 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir);
1395 if( !pSRB->SGToBeXferLen ) 1325 if( !pSRB->SGToBeXferLen )
1396 { 1326 {
1397 psgl = pSRB->pSegmentList; 1327 dc390_start_segment(pSRB);
1398 pSRB->SGBusAddr = cpu_to_le32(pci_dma_lo32(sg_dma_address(psgl))); 1328
1399 pSRB->SGToBeXferLen = cpu_to_le32(sg_dma_len(psgl));
1400 DEBUG1(printk (KERN_DEBUG " DC390: Next SG segment.")); 1329 DEBUG1(printk (KERN_DEBUG " DC390: Next SG segment."));
1401 } 1330 }
1402 lval = pSRB->SGToBeXferLen; 1331 lval = pSRB->SGToBeXferLen;
@@ -1410,12 +1339,12 @@ dc390_DataIO_Comm( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 ioDir)
1410 DC390_write32 (DMA_XferCnt, pSRB->SGToBeXferLen); 1339 DC390_write32 (DMA_XferCnt, pSRB->SGToBeXferLen);
1411 DC390_write32 (DMA_XferAddr, pSRB->SGBusAddr); 1340 DC390_write32 (DMA_XferAddr, pSRB->SGBusAddr);
1412 1341
1413 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir); /* | DMA_INT; */ 1342 //DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir);
1414 pSRB->SRBState = SRB_DATA_XFER; 1343 pSRB->SRBState = SRB_DATA_XFER;
1415 1344
1416 DC390_write8 (ScsiCmd, DMA_COMMAND+INFO_XFER_CMD); 1345 DC390_write8 (ScsiCmd, DMA_COMMAND+INFO_XFER_CMD);
1417 1346
1418 DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir | DMA_INT); 1347 DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir);
1419 //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT)); 1348 //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, WRT_ERASE_DMA_STAT | EN_INT_ON_PCI_ABORT));
1420 //DEBUG1(printk (KERN_DEBUG "DC390: DMA_Status: %02x\n", DC390_read8 (DMA_Status))); 1349 //DEBUG1(printk (KERN_DEBUG "DC390: DMA_Status: %02x\n", DC390_read8 (DMA_Status)));
1421 //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT)); 1350 //DEBUG1(DC390_write32 (DMA_ScsiBusCtrl, EN_INT_ON_PCI_ABORT));
@@ -1436,8 +1365,8 @@ dc390_DataIO_Comm( struct dc390_acb* pACB, struct dc390_srb* pSRB, u8 ioDir)
1436 pSRB->SRBState |= SRB_XFERPAD; 1365 pSRB->SRBState |= SRB_XFERPAD;
1437 DC390_write8 (ScsiCmd, DMA_COMMAND+XFER_PAD_BYTE); 1366 DC390_write8 (ScsiCmd, DMA_COMMAND+XFER_PAD_BYTE);
1438/* 1367/*
1439 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir); // | DMA_INT; 1368 DC390_write8 (DMA_Cmd, DMA_IDLE_CMD | ioDir);
1440 DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir | DMA_INT); 1369 DC390_write8 (DMA_Cmd, DMA_START_CMD | ioDir);
1441*/ 1370*/
1442 } 1371 }
1443} 1372}
diff --git a/drivers/scsi/tmscsim.h b/drivers/scsi/tmscsim.h
index 9b66fa8d38d9..c3d8c80cfb38 100644
--- a/drivers/scsi/tmscsim.h
+++ b/drivers/scsi/tmscsim.h
@@ -19,14 +19,6 @@
19 19
20#define SEL_TIMEOUT 153 /* 250 ms selection timeout (@ 40 MHz) */ 20#define SEL_TIMEOUT 153 /* 250 ms selection timeout (@ 40 MHz) */
21 21
22#define pci_dma_lo32(a) (a & 0xffffffff)
23
24typedef u8 UCHAR; /* 8 bits */
25typedef u16 USHORT; /* 16 bits */
26typedef u32 UINT; /* 32 bits */
27typedef unsigned long ULONG; /* 32/64 bits */
28
29
30/* 22/*
31;----------------------------------------------------------------------- 23;-----------------------------------------------------------------------
32; SCSI Request Block 24; SCSI Request Block
@@ -43,7 +35,9 @@ struct scatterlist *pSegmentList;
43 35
44struct scatterlist Segmentx; /* make a one entry of S/G list table */ 36struct scatterlist Segmentx; /* make a one entry of S/G list table */
45 37
46unsigned long SGBusAddr; /*;a segment starting address as seen by AM53C974A*/ 38unsigned long SGBusAddr; /*;a segment starting address as seen by AM53C974A
39 in CPU endianness. We're only getting 32-bit bus
40 addresses by default */
47unsigned long SGToBeXferLen; /*; to be xfer length */ 41unsigned long SGToBeXferLen; /*; to be xfer length */
48unsigned long TotalXferredLen; 42unsigned long TotalXferredLen;
49unsigned long SavedTotXLen; 43unsigned long SavedTotXLen;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index c9832d963f1e..c84dab083a85 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -894,7 +894,7 @@ static void autoconfig_16550a(struct uart_8250_port *up)
894 quot = serial_dl_read(up); 894 quot = serial_dl_read(up);
895 quot <<= 3; 895 quot <<= 3;
896 896
897 status1 = serial_in(up, 0x04); /* EXCR1 */ 897 status1 = serial_in(up, 0x04); /* EXCR2 */
898 status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */ 898 status1 &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
899 status1 |= 0x10; /* 1.625 divisor for baud_base --> 921600 */ 899 status1 |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
900 serial_outp(up, 0x04, status1); 900 serial_outp(up, 0x04, status1);
@@ -994,7 +994,6 @@ static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
994 * be frobbing the chips IRQ enable register to see if it exists. 994 * be frobbing the chips IRQ enable register to see if it exists.
995 */ 995 */
996 spin_lock_irqsave(&up->port.lock, flags); 996 spin_lock_irqsave(&up->port.lock, flags);
997// save_flags(flags); cli();
998 997
999 up->capabilities = 0; 998 up->capabilities = 0;
1000 up->bugs = 0; 999 up->bugs = 0;
@@ -1151,7 +1150,6 @@ static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
1151 1150
1152 out: 1151 out:
1153 spin_unlock_irqrestore(&up->port.lock, flags); 1152 spin_unlock_irqrestore(&up->port.lock, flags);
1154// restore_flags(flags);
1155 DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name); 1153 DEBUG_AUTOCONF("type=%s\n", uart_config[up->port.type].name);
1156} 1154}
1157 1155
@@ -2619,7 +2617,22 @@ void serial8250_suspend_port(int line)
2619 */ 2617 */
2620void serial8250_resume_port(int line) 2618void serial8250_resume_port(int line)
2621{ 2619{
2622 uart_resume_port(&serial8250_reg, &serial8250_ports[line].port); 2620 struct uart_8250_port *up = &serial8250_ports[line];
2621
2622 if (up->capabilities & UART_NATSEMI) {
2623 unsigned char tmp;
2624
2625 /* Ensure it's still in high speed mode */
2626 serial_outp(up, UART_LCR, 0xE0);
2627
2628 tmp = serial_in(up, 0x04); /* EXCR2 */
2629 tmp &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
2630 tmp |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
2631 serial_outp(up, 0x04, tmp);
2632
2633 serial_outp(up, UART_LCR, 0);
2634 }
2635 uart_resume_port(&serial8250_reg, &up->port);
2623} 2636}
2624 2637
2625/* 2638/*
@@ -2696,7 +2709,7 @@ static int serial8250_resume(struct platform_device *dev)
2696 struct uart_8250_port *up = &serial8250_ports[i]; 2709 struct uart_8250_port *up = &serial8250_ports[i];
2697 2710
2698 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev) 2711 if (up->port.type != PORT_UNKNOWN && up->port.dev == &dev->dev)
2699 uart_resume_port(&serial8250_reg, &up->port); 2712 serial8250_resume_port(i);
2700 } 2713 }
2701 2714
2702 return 0; 2715 return 0;
diff --git a/drivers/serial/8250_acorn.c b/drivers/serial/8250_acorn.c
index 562ba745a044..b0ce8c56f1a4 100644
--- a/drivers/serial/8250_acorn.c
+++ b/drivers/serial/8250_acorn.c
@@ -54,7 +54,7 @@ serial_card_probe(struct expansion_card *ec, const struct ecard_id *id)
54 info->num_ports = type->num_ports; 54 info->num_ports = type->num_ports;
55 55
56 bus_addr = ecard_resource_start(ec, type->type); 56 bus_addr = ecard_resource_start(ec, type->type);
57 info->vaddr = ioremap(bus_addr, ecard_resource_len(ec, type->type)); 57 info->vaddr = ecardm_iomap(ec, type->type, 0, 0);
58 if (!info->vaddr) { 58 if (!info->vaddr) {
59 kfree(info); 59 kfree(info);
60 return -ENOMEM; 60 return -ENOMEM;
@@ -91,7 +91,6 @@ static void __devexit serial_card_remove(struct expansion_card *ec)
91 if (info->ports[i] > 0) 91 if (info->ports[i] > 0)
92 serial8250_unregister_port(info->ports[i]); 92 serial8250_unregister_port(info->ports[i]);
93 93
94 iounmap(info->vaddr);
95 kfree(info); 94 kfree(info);
96} 95}
97 96
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 924e9bd757f0..315ea9916456 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -5,6 +5,7 @@
5# 5#
6 6
7menu "Serial drivers" 7menu "Serial drivers"
8 depends on HAS_IOMEM
8 9
9# 10#
10# The new 8250/16550 serial drivers 11# The new 8250/16550 serial drivers
@@ -73,17 +74,21 @@ config SERIAL_8250_PCI
73 depends on SERIAL_8250 && PCI 74 depends on SERIAL_8250 && PCI
74 default SERIAL_8250 75 default SERIAL_8250
75 help 76 help
76 This builds standard PCI serial support. You may be able to 77 Say Y here if you have PCI serial ports.
77 disable this feature if you only need legacy serial support. 78
78 Saves about 9K. 79 To compile this driver as a module, choose M here: the module
80 will be called 8250_pci.
79 81
80config SERIAL_8250_PNP 82config SERIAL_8250_PNP
81 tristate "8250/16550 PNP device support" if EMBEDDED 83 tristate "8250/16550 PNP device support" if EMBEDDED
82 depends on SERIAL_8250 && PNP 84 depends on SERIAL_8250 && PNP
83 default SERIAL_8250 85 default SERIAL_8250
84 help 86 help
85 This builds standard PNP serial support. You may be able to 87 Say Y here if you have serial ports described by PNPBIOS or ACPI.
86 disable this feature if you only need legacy serial support. 88 These are typically ports built into the system board.
89
90 To compile this driver as a module, choose M here: the module
91 will be called 8250_pnp.
87 92
88config SERIAL_8250_HP300 93config SERIAL_8250_HP300
89 tristate 94 tristate
@@ -354,6 +359,23 @@ config SERIAL_ATMEL_TTYAT
354 359
355 Say Y if you have an external 8250/16C550 UART. If unsure, say N. 360 Say Y if you have an external 8250/16C550 UART. If unsure, say N.
356 361
362config SERIAL_KS8695
363 bool "Micrel KS8695 (Centaur) serial port support"
364 depends on ARCH_KS8695
365 select SERIAL_CORE
366 help
367 This selects the Micrel Centaur KS8695 UART. Say Y here.
368
369config SERIAL_KS8695_CONSOLE
370 bool "Support for console on KS8695 (Centaur) serial port"
371 depends on SERIAL_KS8695=y
372 select SERIAL_CORE_CONSOLE
373 help
374 Say Y here if you wish to use a KS8695 (Centaur) UART as the
375 system console (the system console is the device which
376 receives all kernel messages and warnings and which allows
377 logins in single user mode).
378
357config SERIAL_CLPS711X 379config SERIAL_CLPS711X
358 tristate "CLPS711X serial port support" 380 tristate "CLPS711X serial port support"
359 depends on ARM && ARCH_CLPS711X 381 depends on ARM && ARCH_CLPS711X
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 4959bcb8d1ef..08ad0d978183 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -61,3 +61,4 @@ obj-$(CONFIG_SERIAL_ATMEL) += atmel_serial.o
61obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o 61obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
62obj-$(CONFIG_SERIAL_NETX) += netx-serial.o 62obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
63obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o 63obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o
64obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 408390f93db9..787dc7168f3e 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -6,8 +6,6 @@
6 * Created: 6 * Created:
7 * Description: Driver for blackfin 5xx serial ports 7 * Description: Driver for blackfin 5xx serial ports
8 * 8 *
9 * Rev: $Id: bfin_5xx.c,v 1.19 2006/09/24 02:33:53 aubrey Exp $
10 *
11 * Modified: 9 * Modified:
12 * Copyright 2006 Analog Devices Inc. 10 * Copyright 2006 Analog Devices Inc.
13 * 11 *
@@ -152,7 +150,7 @@ static void local_put_char(struct bfin_serial_port *uart, char ch)
152 150
153static void bfin_serial_rx_chars(struct bfin_serial_port *uart) 151static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
154{ 152{
155 struct tty_struct *tty = uart->port.info?uart->port.info->tty:0; 153 struct tty_struct *tty = uart->port.info->tty;
156 unsigned int status, ch, flg; 154 unsigned int status, ch, flg;
157#ifdef BF533_FAMILY 155#ifdef BF533_FAMILY
158 static int in_break = 0; 156 static int in_break = 0;
@@ -173,8 +171,10 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
173 if (ch != 0) { 171 if (ch != 0) {
174 in_break = 0; 172 in_break = 0;
175 ch = UART_GET_CHAR(uart); 173 ch = UART_GET_CHAR(uart);
176 } 174 if (bfin_revid() < 5)
177 return; 175 return;
176 } else
177 return;
178 } 178 }
179#endif 179#endif
180 180
@@ -185,27 +185,32 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
185 uart->port.icount.brk++; 185 uart->port.icount.brk++;
186 if (uart_handle_break(&uart->port)) 186 if (uart_handle_break(&uart->port))
187 goto ignore_char; 187 goto ignore_char;
188 flg = TTY_BREAK; 188 }
189 } else if (status & PE) { 189 if (status & PE)
190 flg = TTY_PARITY;
191 uart->port.icount.parity++; 190 uart->port.icount.parity++;
192 } else if (status & OE) { 191 if (status & OE)
193 flg = TTY_OVERRUN;
194 uart->port.icount.overrun++; 192 uart->port.icount.overrun++;
195 } else if (status & FE) { 193 if (status & FE)
196 flg = TTY_FRAME;
197 uart->port.icount.frame++; 194 uart->port.icount.frame++;
198 } else 195
196 status &= uart->port.read_status_mask;
197
198 if (status & BI)
199 flg = TTY_BREAK;
200 else if (status & PE)
201 flg = TTY_PARITY;
202 else if (status & FE)
203 flg = TTY_FRAME;
204 else
199 flg = TTY_NORMAL; 205 flg = TTY_NORMAL;
200 206
201 if (uart_handle_sysrq_char(&uart->port, ch)) 207 if (uart_handle_sysrq_char(&uart->port, ch))
202 goto ignore_char; 208 goto ignore_char;
203 if (tty)
204 uart_insert_char(&uart->port, status, 2, ch, flg);
205 209
206ignore_char: 210 uart_insert_char(&uart->port, status, OE, ch, flg);
207 if (tty) 211
208 tty_flip_buffer_push(tty); 212 ignore_char:
213 tty_flip_buffer_push(tty);
209} 214}
210 215
211static void bfin_serial_tx_chars(struct bfin_serial_port *uart) 216static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
@@ -240,24 +245,29 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
240 bfin_serial_stop_tx(&uart->port); 245 bfin_serial_stop_tx(&uart->port);
241} 246}
242 247
243static irqreturn_t bfin_serial_int(int irq, void *dev_id) 248static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id)
244{ 249{
245 struct bfin_serial_port *uart = dev_id; 250 struct bfin_serial_port *uart = dev_id;
246 unsigned short status;
247 251
248 spin_lock(&uart->port.lock); 252 spin_lock(&uart->port.lock);
249 status = UART_GET_IIR(uart); 253 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_RX_READY)
250 do { 254 bfin_serial_rx_chars(uart);
251 if ((status & IIR_STATUS) == IIR_TX_READY)
252 bfin_serial_tx_chars(uart);
253 if ((status & IIR_STATUS) == IIR_RX_READY)
254 bfin_serial_rx_chars(uart);
255 status = UART_GET_IIR(uart);
256 } while (status & (IIR_TX_READY | IIR_RX_READY));
257 spin_unlock(&uart->port.lock); 255 spin_unlock(&uart->port.lock);
258 return IRQ_HANDLED; 256 return IRQ_HANDLED;
259} 257}
260 258
259static irqreturn_t bfin_serial_tx_int(int irq, void *dev_id)
260{
261 struct bfin_serial_port *uart = dev_id;
262
263 spin_lock(&uart->port.lock);
264 while ((UART_GET_IIR(uart) & IIR_STATUS) == IIR_TX_READY)
265 bfin_serial_tx_chars(uart);
266 spin_unlock(&uart->port.lock);
267 return IRQ_HANDLED;
268}
269
270
261static void bfin_serial_do_work(struct work_struct *work) 271static void bfin_serial_do_work(struct work_struct *work)
262{ 272{
263 struct bfin_serial_port *uart = container_of(work, struct bfin_serial_port, cts_workqueue); 273 struct bfin_serial_port *uart = container_of(work, struct bfin_serial_port, cts_workqueue);
@@ -319,7 +329,7 @@ static void bfin_serial_dma_tx_chars(struct bfin_serial_port *uart)
319 spin_unlock_irqrestore(&uart->port.lock, flags); 329 spin_unlock_irqrestore(&uart->port.lock, flags);
320} 330}
321 331
322static void bfin_serial_dma_rx_chars(struct bfin_serial_port * uart) 332static void bfin_serial_dma_rx_chars(struct bfin_serial_port *uart)
323{ 333{
324 struct tty_struct *tty = uart->port.info->tty; 334 struct tty_struct *tty = uart->port.info->tty;
325 int i, flg, status; 335 int i, flg, status;
@@ -331,25 +341,32 @@ static void bfin_serial_dma_rx_chars(struct bfin_serial_port * uart)
331 uart->port.icount.brk++; 341 uart->port.icount.brk++;
332 if (uart_handle_break(&uart->port)) 342 if (uart_handle_break(&uart->port))
333 goto dma_ignore_char; 343 goto dma_ignore_char;
334 flg = TTY_BREAK; 344 }
335 } else if (status & PE) { 345 if (status & PE)
336 flg = TTY_PARITY;
337 uart->port.icount.parity++; 346 uart->port.icount.parity++;
338 } else if (status & OE) { 347 if (status & OE)
339 flg = TTY_OVERRUN;
340 uart->port.icount.overrun++; 348 uart->port.icount.overrun++;
341 } else if (status & FE) { 349 if (status & FE)
342 flg = TTY_FRAME;
343 uart->port.icount.frame++; 350 uart->port.icount.frame++;
344 } else 351
352 status &= uart->port.read_status_mask;
353
354 if (status & BI)
355 flg = TTY_BREAK;
356 else if (status & PE)
357 flg = TTY_PARITY;
358 else if (status & FE)
359 flg = TTY_FRAME;
360 else
345 flg = TTY_NORMAL; 361 flg = TTY_NORMAL;
346 362
347 for (i = uart->rx_dma_buf.head; i < uart->rx_dma_buf.tail; i++) { 363 for (i = uart->rx_dma_buf.head; i < uart->rx_dma_buf.tail; i++) {
348 if (uart_handle_sysrq_char(&uart->port, uart->rx_dma_buf.buf[i])) 364 if (uart_handle_sysrq_char(&uart->port, uart->rx_dma_buf.buf[i]))
349 goto dma_ignore_char; 365 goto dma_ignore_char;
350 uart_insert_char(&uart->port, status, 2, uart->rx_dma_buf.buf[i], flg); 366 uart_insert_char(&uart->port, status, OE, uart->rx_dma_buf.buf[i], flg);
351 } 367 }
352dma_ignore_char: 368
369 dma_ignore_char:
353 tty_flip_buffer_push(tty); 370 tty_flip_buffer_push(tty);
354} 371}
355 372
@@ -545,14 +562,14 @@ static int bfin_serial_startup(struct uart_port *port)
545 add_timer(&(uart->rx_dma_timer)); 562 add_timer(&(uart->rx_dma_timer));
546#else 563#else
547 if (request_irq 564 if (request_irq
548 (uart->port.irq, bfin_serial_int, IRQF_DISABLED, 565 (uart->port.irq, bfin_serial_rx_int, IRQF_DISABLED,
549 "BFIN_UART_RX", uart)) { 566 "BFIN_UART_RX", uart)) {
550 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n"); 567 printk(KERN_NOTICE "Unable to attach BlackFin UART RX interrupt\n");
551 return -EBUSY; 568 return -EBUSY;
552 } 569 }
553 570
554 if (request_irq 571 if (request_irq
555 (uart->port.irq+1, bfin_serial_int, IRQF_DISABLED, 572 (uart->port.irq+1, bfin_serial_tx_int, IRQF_DISABLED,
556 "BFIN_UART_TX", uart)) { 573 "BFIN_UART_TX", uart)) {
557 printk(KERN_NOTICE "Unable to attach BlackFin UART TX interrupt\n"); 574 printk(KERN_NOTICE "Unable to attach BlackFin UART TX interrupt\n");
558 free_irq(uart->port.irq, uart); 575 free_irq(uart->port.irq, uart);
@@ -614,13 +631,27 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
614 lcr |= EPS; 631 lcr |= EPS;
615 } 632 }
616 633
617 /* These controls are not implemented for this port */ 634 port->read_status_mask = OE;
618 termios->c_iflag |= INPCK | BRKINT | PARMRK; 635 if (termios->c_iflag & INPCK)
619 termios->c_iflag &= ~(IGNPAR | IGNBRK); 636 port->read_status_mask |= (FE | PE);
637 if (termios->c_iflag & (BRKINT | PARMRK))
638 port->read_status_mask |= BI;
620 639
621 /* These controls are not implemented for this port */ 640 /*
622 termios->c_iflag |= INPCK | BRKINT | PARMRK; 641 * Characters to ignore
623 termios->c_iflag &= ~(IGNPAR | IGNBRK); 642 */
643 port->ignore_status_mask = 0;
644 if (termios->c_iflag & IGNPAR)
645 port->ignore_status_mask |= FE | PE;
646 if (termios->c_iflag & IGNBRK) {
647 port->ignore_status_mask |= BI;
648 /*
649 * If we're ignoring parity and break indicators,
650 * ignore overruns too (for real raw support).
651 */
652 if (termios->c_iflag & IGNPAR)
653 port->ignore_status_mask |= OE;
654 }
624 655
625 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16); 656 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
626 quot = uart_get_divisor(port, baud); 657 quot = uart_get_divisor(port, baud);
diff --git a/drivers/serial/cpm_uart/cpm_uart.h b/drivers/serial/cpm_uart/cpm_uart.h
index 69715e556506..a8f894c78194 100644
--- a/drivers/serial/cpm_uart/cpm_uart.h
+++ b/drivers/serial/cpm_uart/cpm_uart.h
@@ -88,7 +88,7 @@ extern struct uart_cpm_port cpm_uart_ports[UART_NR];
88 88
89/* these are located in their respective files */ 89/* these are located in their respective files */
90void cpm_line_cr_cmd(int line, int cmd); 90void cpm_line_cr_cmd(int line, int cmd);
91int __init cpm_uart_init_portdesc(void); 91int cpm_uart_init_portdesc(void);
92int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con); 92int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con);
93void cpm_uart_freebuf(struct uart_cpm_port *pinfo); 93void cpm_uart_freebuf(struct uart_cpm_port *pinfo);
94 94
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index 7a3b97fdf8d1..b63ff8dd7304 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -482,7 +482,8 @@ static void cpm_uart_shutdown(struct uart_port *port)
482} 482}
483 483
484static void cpm_uart_set_termios(struct uart_port *port, 484static void cpm_uart_set_termios(struct uart_port *port,
485 struct termios *termios, struct termios *old) 485 struct ktermios *termios,
486 struct ktermios *old)
486{ 487{
487 int baud; 488 int baud;
488 unsigned long flags; 489 unsigned long flags;
@@ -934,7 +935,7 @@ struct uart_cpm_port cpm_uart_ports[UART_NR] = {
934 .irq = SMC1_IRQ, 935 .irq = SMC1_IRQ,
935 .ops = &cpm_uart_pops, 936 .ops = &cpm_uart_pops,
936 .iotype = UPIO_MEM, 937 .iotype = UPIO_MEM,
937 .lock = SPIN_LOCK_UNLOCKED, 938 .lock = __SPIN_LOCK_UNLOCKED(cpm_uart_ports[UART_SMC1].port.lock),
938 }, 939 },
939 .flags = FLAG_SMC, 940 .flags = FLAG_SMC,
940 .tx_nrfifos = TX_NUM_FIFO, 941 .tx_nrfifos = TX_NUM_FIFO,
@@ -948,7 +949,7 @@ struct uart_cpm_port cpm_uart_ports[UART_NR] = {
948 .irq = SMC2_IRQ, 949 .irq = SMC2_IRQ,
949 .ops = &cpm_uart_pops, 950 .ops = &cpm_uart_pops,
950 .iotype = UPIO_MEM, 951 .iotype = UPIO_MEM,
951 .lock = SPIN_LOCK_UNLOCKED, 952 .lock = __SPIN_LOCK_UNLOCKED(cpm_uart_ports[UART_SMC2].port.lock),
952 }, 953 },
953 .flags = FLAG_SMC, 954 .flags = FLAG_SMC,
954 .tx_nrfifos = TX_NUM_FIFO, 955 .tx_nrfifos = TX_NUM_FIFO,
@@ -965,7 +966,7 @@ struct uart_cpm_port cpm_uart_ports[UART_NR] = {
965 .irq = SCC1_IRQ, 966 .irq = SCC1_IRQ,
966 .ops = &cpm_uart_pops, 967 .ops = &cpm_uart_pops,
967 .iotype = UPIO_MEM, 968 .iotype = UPIO_MEM,
968 .lock = SPIN_LOCK_UNLOCKED, 969 .lock = __SPIN_LOCK_UNLOCKED(cpm_uart_ports[UART_SCC1].port.lock),
969 }, 970 },
970 .tx_nrfifos = TX_NUM_FIFO, 971 .tx_nrfifos = TX_NUM_FIFO,
971 .tx_fifosize = TX_BUF_SIZE, 972 .tx_fifosize = TX_BUF_SIZE,
@@ -979,7 +980,7 @@ struct uart_cpm_port cpm_uart_ports[UART_NR] = {
979 .irq = SCC2_IRQ, 980 .irq = SCC2_IRQ,
980 .ops = &cpm_uart_pops, 981 .ops = &cpm_uart_pops,
981 .iotype = UPIO_MEM, 982 .iotype = UPIO_MEM,
982 .lock = SPIN_LOCK_UNLOCKED, 983 .lock = __SPIN_LOCK_UNLOCKED(cpm_uart_ports[UART_SCC2].port.lock),
983 }, 984 },
984 .tx_nrfifos = TX_NUM_FIFO, 985 .tx_nrfifos = TX_NUM_FIFO,
985 .tx_fifosize = TX_BUF_SIZE, 986 .tx_fifosize = TX_BUF_SIZE,
@@ -993,7 +994,7 @@ struct uart_cpm_port cpm_uart_ports[UART_NR] = {
993 .irq = SCC3_IRQ, 994 .irq = SCC3_IRQ,
994 .ops = &cpm_uart_pops, 995 .ops = &cpm_uart_pops,
995 .iotype = UPIO_MEM, 996 .iotype = UPIO_MEM,
996 .lock = SPIN_LOCK_UNLOCKED, 997 .lock = __SPIN_LOCK_UNLOCKED(cpm_uart_ports[UART_SCC3].port.lock),
997 }, 998 },
998 .tx_nrfifos = TX_NUM_FIFO, 999 .tx_nrfifos = TX_NUM_FIFO,
999 .tx_fifosize = TX_BUF_SIZE, 1000 .tx_fifosize = TX_BUF_SIZE,
@@ -1007,7 +1008,7 @@ struct uart_cpm_port cpm_uart_ports[UART_NR] = {
1007 .irq = SCC4_IRQ, 1008 .irq = SCC4_IRQ,
1008 .ops = &cpm_uart_pops, 1009 .ops = &cpm_uart_pops,
1009 .iotype = UPIO_MEM, 1010 .iotype = UPIO_MEM,
1010 .lock = SPIN_LOCK_UNLOCKED, 1011 .lock = __SPIN_LOCK_UNLOCKED(cpm_uart_ports[UART_SCC4].port.lock),
1011 }, 1012 },
1012 .tx_nrfifos = TX_NUM_FIFO, 1013 .tx_nrfifos = TX_NUM_FIFO,
1013 .tx_fifosize = TX_BUF_SIZE, 1014 .tx_fifosize = TX_BUF_SIZE,
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm1.c b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
index 925fb607d8c4..8c6324ed0202 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm1.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
@@ -125,7 +125,7 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
125{ 125{
126 int dpmemsz, memsz; 126 int dpmemsz, memsz;
127 u8 *dp_mem; 127 u8 *dp_mem;
128 uint dp_offset; 128 unsigned long dp_offset;
129 u8 *mem_addr; 129 u8 *mem_addr;
130 dma_addr_t dma_addr = 0; 130 dma_addr_t dma_addr = 0;
131 131
@@ -133,7 +133,7 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
133 133
134 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos); 134 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
135 dp_offset = cpm_dpalloc(dpmemsz, 8); 135 dp_offset = cpm_dpalloc(dpmemsz, 8);
136 if (IS_DPERR(dp_offset)) { 136 if (IS_ERR_VALUE(dp_offset)) {
137 printk(KERN_ERR 137 printk(KERN_ERR
138 "cpm_uart_cpm1.c: could not allocate buffer descriptors\n"); 138 "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
139 return -ENOMEM; 139 return -ENOMEM;
@@ -185,7 +185,7 @@ void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
185} 185}
186 186
187/* Setup any dynamic params in the uart desc */ 187/* Setup any dynamic params in the uart desc */
188int __init cpm_uart_init_portdesc(void) 188int cpm_uart_init_portdesc(void)
189{ 189{
190 pr_debug("CPM uart[-]:init portdesc\n"); 190 pr_debug("CPM uart[-]:init portdesc\n");
191 191
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.c b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
index fa455996ad8f..7b61d805ebe9 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm2.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
@@ -222,7 +222,7 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
222{ 222{
223 int dpmemsz, memsz; 223 int dpmemsz, memsz;
224 u8 *dp_mem; 224 u8 *dp_mem;
225 uint dp_offset; 225 unsigned long dp_offset;
226 u8 *mem_addr; 226 u8 *mem_addr;
227 dma_addr_t dma_addr = 0; 227 dma_addr_t dma_addr = 0;
228 228
@@ -230,7 +230,7 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
230 230
231 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos); 231 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
232 dp_offset = cpm_dpalloc(dpmemsz, 8); 232 dp_offset = cpm_dpalloc(dpmemsz, 8);
233 if (IS_DPERR(dp_offset)) { 233 if (IS_ERR_VALUE(dp_offset)) {
234 printk(KERN_ERR 234 printk(KERN_ERR
235 "cpm_uart_cpm.c: could not allocate buffer descriptors\n"); 235 "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
236 return -ENOMEM; 236 return -ENOMEM;
@@ -282,7 +282,7 @@ void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
282} 282}
283 283
284/* Setup any dynamic params in the uart desc */ 284/* Setup any dynamic params in the uart desc */
285int __init cpm_uart_init_portdesc(void) 285int cpm_uart_init_portdesc(void)
286{ 286{
287#if defined(CONFIG_SERIAL_CPM_SMC1) || defined(CONFIG_SERIAL_CPM_SMC2) 287#if defined(CONFIG_SERIAL_CPM_SMC1) || defined(CONFIG_SERIAL_CPM_SMC2)
288 u16 *addr; 288 u16 *addr;
diff --git a/drivers/serial/icom.c b/drivers/serial/icom.c
index 246c5572667b..9d3105b64a7a 100644
--- a/drivers/serial/icom.c
+++ b/drivers/serial/icom.c
@@ -47,7 +47,6 @@
47#include <linux/pci.h> 47#include <linux/pci.h>
48#include <linux/vmalloc.h> 48#include <linux/vmalloc.h>
49#include <linux/smp.h> 49#include <linux/smp.h>
50#include <linux/smp_lock.h>
51#include <linux/spinlock.h> 50#include <linux/spinlock.h>
52#include <linux/kobject.h> 51#include <linux/kobject.h>
53#include <linux/firmware.h> 52#include <linux/firmware.h>
@@ -70,33 +69,40 @@
70 69
71static const struct pci_device_id icom_pci_table[] = { 70static const struct pci_device_id icom_pci_table[] = {
72 { 71 {
73 .vendor = PCI_VENDOR_ID_IBM, 72 .vendor = PCI_VENDOR_ID_IBM,
74 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_1, 73 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_1,
75 .subvendor = PCI_ANY_ID, 74 .subvendor = PCI_ANY_ID,
76 .subdevice = PCI_ANY_ID, 75 .subdevice = PCI_ANY_ID,
77 .driver_data = ADAPTER_V1, 76 .driver_data = ADAPTER_V1,
78 }, 77 },
79 { 78 {
80 .vendor = PCI_VENDOR_ID_IBM, 79 .vendor = PCI_VENDOR_ID_IBM,
81 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2, 80 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
82 .subvendor = PCI_VENDOR_ID_IBM, 81 .subvendor = PCI_VENDOR_ID_IBM,
83 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_TWO_PORTS_RVX, 82 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_TWO_PORTS_RVX,
84 .driver_data = ADAPTER_V2, 83 .driver_data = ADAPTER_V2,
85 }, 84 },
86 { 85 {
87 .vendor = PCI_VENDOR_ID_IBM, 86 .vendor = PCI_VENDOR_ID_IBM,
88 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2, 87 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
89 .subvendor = PCI_VENDOR_ID_IBM, 88 .subvendor = PCI_VENDOR_ID_IBM,
90 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM, 89 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM,
91 .driver_data = ADAPTER_V2, 90 .driver_data = ADAPTER_V2,
92 }, 91 },
93 { 92 {
94 .vendor = PCI_VENDOR_ID_IBM, 93 .vendor = PCI_VENDOR_ID_IBM,
95 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2, 94 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
96 .subvendor = PCI_VENDOR_ID_IBM, 95 .subvendor = PCI_VENDOR_ID_IBM,
97 .subdevice = PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL, 96 .subdevice = PCI_DEVICE_ID_IBM_ICOM_FOUR_PORT_MODEL,
98 .driver_data = ADAPTER_V2, 97 .driver_data = ADAPTER_V2,
99 }, 98 },
99 {
100 .vendor = PCI_VENDOR_ID_IBM,
101 .device = PCI_DEVICE_ID_IBM_ICOM_DEV_ID_2,
102 .subvendor = PCI_VENDOR_ID_IBM,
103 .subdevice = PCI_DEVICE_ID_IBM_ICOM_V2_ONE_PORT_RVX_ONE_PORT_MDM_PCIE,
104 .driver_data = ADAPTER_V2,
105 },
100 {} 106 {}
101}; 107};
102 108
diff --git a/drivers/serial/jsm/jsm_neo.c b/drivers/serial/jsm/jsm_neo.c
index 8be8da37f629..b2d6f5b1a7c2 100644
--- a/drivers/serial/jsm/jsm_neo.c
+++ b/drivers/serial/jsm/jsm_neo.c
@@ -581,8 +581,13 @@ static void neo_parse_modem(struct jsm_channel *ch, u8 signals)
581 return; 581 return;
582 582
583 /* Scrub off lower bits. They signify delta's, which I don't care about */ 583 /* Scrub off lower bits. They signify delta's, which I don't care about */
584 msignals &= 0xf0; 584 /* Keep DDCD and DDSR though */
585 msignals &= 0xf8;
585 586
587 if (msignals & UART_MSR_DDCD)
588 uart_handle_dcd_change(&ch->uart_port, msignals & UART_MSR_DCD);
589 if (msignals & UART_MSR_DDSR)
590 uart_handle_cts_change(&ch->uart_port, msignals & UART_MSR_CTS);
586 if (msignals & UART_MSR_DCD) 591 if (msignals & UART_MSR_DCD)
587 ch->ch_mistat |= UART_MSR_DCD; 592 ch->ch_mistat |= UART_MSR_DCD;
588 else 593 else
diff --git a/drivers/serial/jsm/jsm_tty.c b/drivers/serial/jsm/jsm_tty.c
index be22bbdbc8e5..281f23a371b2 100644
--- a/drivers/serial/jsm/jsm_tty.c
+++ b/drivers/serial/jsm/jsm_tty.c
@@ -448,6 +448,7 @@ int jsm_uart_port_init(struct jsm_board *brd)
448 continue; 448 continue;
449 449
450 brd->channels[i]->uart_port.irq = brd->irq; 450 brd->channels[i]->uart_port.irq = brd->irq;
451 brd->channels[i]->uart_port.uartclk = 14745600;
451 brd->channels[i]->uart_port.type = PORT_JSM; 452 brd->channels[i]->uart_port.type = PORT_JSM;
452 brd->channels[i]->uart_port.iotype = UPIO_MEM; 453 brd->channels[i]->uart_port.iotype = UPIO_MEM;
453 brd->channels[i]->uart_port.membase = brd->re_map_membase; 454 brd->channels[i]->uart_port.membase = brd->re_map_membase;
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 8d24cd521056..35f8b86cc78f 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -257,9 +257,10 @@ mpc52xx_uart_shutdown(struct uart_port *port)
257{ 257{
258 struct mpc52xx_psc __iomem *psc = PSC(port); 258 struct mpc52xx_psc __iomem *psc = PSC(port);
259 259
260 /* Shut down the port, interrupt and all */ 260 /* Shut down the port. Leave TX active if on a console port */
261 out_8(&psc->command,MPC52xx_PSC_RST_RX); 261 out_8(&psc->command,MPC52xx_PSC_RST_RX);
262 out_8(&psc->command,MPC52xx_PSC_RST_TX); 262 if (!uart_console(port))
263 out_8(&psc->command,MPC52xx_PSC_RST_TX);
263 264
264 port->read_status_mask = 0; 265 port->read_status_mask = 0;
265 out_be16(&psc->mpc52xx_psc_imr,port->read_status_mask); 266 out_be16(&psc->mpc52xx_psc_imr,port->read_status_mask);
@@ -1069,7 +1070,7 @@ mpc52xx_uart_of_enumerate(void)
1069 continue; 1070 continue;
1070 1071
1071 /* Is a particular device number requested? */ 1072 /* Is a particular device number requested? */
1072 devno = get_property(np, "port-number", NULL); 1073 devno = of_get_property(np, "port-number", NULL);
1073 mpc52xx_uart_of_assign(of_node_get(np), devno ? *devno : -1); 1074 mpc52xx_uart_of_assign(of_node_get(np), devno ? *devno : -1);
1074 } 1075 }
1075 1076
diff --git a/drivers/serial/of_serial.c b/drivers/serial/of_serial.c
index 336d0f4580d9..7ffdaeaf0545 100644
--- a/drivers/serial/of_serial.c
+++ b/drivers/serial/of_serial.c
@@ -29,8 +29,8 @@ static int __devinit of_platform_serial_setup(struct of_device *ofdev,
29 int ret; 29 int ret;
30 30
31 memset(port, 0, sizeof *port); 31 memset(port, 0, sizeof *port);
32 spd = get_property(np, "current-speed", NULL); 32 spd = of_get_property(np, "current-speed", NULL);
33 clk = get_property(np, "clock-frequency", NULL); 33 clk = of_get_property(np, "clock-frequency", NULL);
34 if (!clk) { 34 if (!clk) {
35 dev_warn(&ofdev->dev, "no clock-frequency property set\n"); 35 dev_warn(&ofdev->dev, "no clock-frequency property set\n");
36 return -ENODEV; 36 return -ENODEV;
diff --git a/drivers/serial/pmac_zilog.c b/drivers/serial/pmac_zilog.c
index be8d75721a85..0fa9f6761763 100644
--- a/drivers/serial/pmac_zilog.c
+++ b/drivers/serial/pmac_zilog.c
@@ -1450,14 +1450,14 @@ no_dma:
1450 /* 1450 /*
1451 * Detect port type 1451 * Detect port type
1452 */ 1452 */
1453 if (device_is_compatible(np, "cobalt")) 1453 if (of_device_is_compatible(np, "cobalt"))
1454 uap->flags |= PMACZILOG_FLAG_IS_INTMODEM; 1454 uap->flags |= PMACZILOG_FLAG_IS_INTMODEM;
1455 conn = get_property(np, "AAPL,connector", &len); 1455 conn = of_get_property(np, "AAPL,connector", &len);
1456 if (conn && (strcmp(conn, "infrared") == 0)) 1456 if (conn && (strcmp(conn, "infrared") == 0))
1457 uap->flags |= PMACZILOG_FLAG_IS_IRDA; 1457 uap->flags |= PMACZILOG_FLAG_IS_IRDA;
1458 uap->port_type = PMAC_SCC_ASYNC; 1458 uap->port_type = PMAC_SCC_ASYNC;
1459 /* 1999 Powerbook G3 has slot-names property instead */ 1459 /* 1999 Powerbook G3 has slot-names property instead */
1460 slots = get_property(np, "slot-names", &len); 1460 slots = of_get_property(np, "slot-names", &len);
1461 if (slots && slots->count > 0) { 1461 if (slots && slots->count > 0) {
1462 if (strcmp(slots->name, "IrDA") == 0) 1462 if (strcmp(slots->name, "IrDA") == 0)
1463 uap->flags |= PMACZILOG_FLAG_IS_IRDA; 1463 uap->flags |= PMACZILOG_FLAG_IS_IRDA;
@@ -1471,7 +1471,7 @@ no_dma:
1471 of_find_node_by_name(NULL, "i2c-modem"); 1471 of_find_node_by_name(NULL, "i2c-modem");
1472 if (i2c_modem) { 1472 if (i2c_modem) {
1473 const char* mid = 1473 const char* mid =
1474 get_property(i2c_modem, "modem-id", NULL); 1474 of_get_property(i2c_modem, "modem-id", NULL);
1475 if (mid) switch(*mid) { 1475 if (mid) switch(*mid) {
1476 case 0x04 : 1476 case 0x04 :
1477 case 0x05 : 1477 case 0x05 :
diff --git a/drivers/serial/s3c2410.c b/drivers/serial/s3c2410.c
index 3ba9208ebd0c..10bc0209cd66 100644
--- a/drivers/serial/s3c2410.c
+++ b/drivers/serial/s3c2410.c
@@ -957,7 +957,7 @@ static struct uart_driver s3c24xx_uart_drv = {
957static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] = { 957static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] = {
958 [0] = { 958 [0] = {
959 .port = { 959 .port = {
960 .lock = SPIN_LOCK_UNLOCKED, 960 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[0].port.lock),
961 .iotype = UPIO_MEM, 961 .iotype = UPIO_MEM,
962 .irq = IRQ_S3CUART_RX0, 962 .irq = IRQ_S3CUART_RX0,
963 .uartclk = 0, 963 .uartclk = 0,
@@ -969,7 +969,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] = {
969 }, 969 },
970 [1] = { 970 [1] = {
971 .port = { 971 .port = {
972 .lock = SPIN_LOCK_UNLOCKED, 972 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[1].port.lock),
973 .iotype = UPIO_MEM, 973 .iotype = UPIO_MEM,
974 .irq = IRQ_S3CUART_RX1, 974 .irq = IRQ_S3CUART_RX1,
975 .uartclk = 0, 975 .uartclk = 0,
@@ -983,7 +983,7 @@ static struct s3c24xx_uart_port s3c24xx_serial_ports[NR_PORTS] = {
983 983
984 [2] = { 984 [2] = {
985 .port = { 985 .port = {
986 .lock = SPIN_LOCK_UNLOCKED, 986 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_serial_ports[2].port.lock),
987 .iotype = UPIO_MEM, 987 .iotype = UPIO_MEM,
988 .irq = IRQ_S3CUART_RX2, 988 .irq = IRQ_S3CUART_RX2,
989 .uartclk = 0, 989 .uartclk = 0,
diff --git a/drivers/serial/serial_ks8695.c b/drivers/serial/serial_ks8695.c
new file mode 100644
index 000000000000..698763b28ddd
--- /dev/null
+++ b/drivers/serial/serial_ks8695.c
@@ -0,0 +1,657 @@
1/*
2 * drivers/serial/serial_ks8695.c
3 *
4 * Driver for KS8695 serial ports
5 *
6 * Based on drivers/serial/serial_amba.c, by Kam Lee.
7 *
8 * Copyright 2002-2005 Micrel Inc.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 */
16#include <linux/module.h>
17#include <linux/tty.h>
18#include <linux/ioport.h>
19#include <linux/init.h>
20#include <linux/serial.h>
21#include <linux/console.h>
22#include <linux/sysrq.h>
23#include <linux/device.h>
24
25#include <asm/io.h>
26#include <asm/irq.h>
27#include <asm/mach/irq.h>
28
29#include <asm/arch/regs-uart.h>
30#include <asm/arch/regs-irq.h>
31
32#if defined(CONFIG_SERIAL_KS8695_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
33#define SUPPORT_SYSRQ
34#endif
35
36#include <linux/serial_core.h>
37
38
39#define SERIAL_KS8695_MAJOR 204
40#define SERIAL_KS8695_MINOR 16
41#define SERIAL_KS8695_DEVNAME "ttyAM"
42
43#define SERIAL_KS8695_NR 1
44
45/*
46 * Access macros for the KS8695 UART
47 */
48#define UART_GET_CHAR(p) (__raw_readl((p)->membase + KS8695_URRB) & 0xFF)
49#define UART_PUT_CHAR(p, c) __raw_writel((c), (p)->membase + KS8695_URTH)
50#define UART_GET_FCR(p) __raw_readl((p)->membase + KS8695_URFC)
51#define UART_PUT_FCR(p, c) __raw_writel((c), (p)->membase + KS8695_URFC)
52#define UART_GET_MSR(p) __raw_readl((p)->membase + KS8695_URMS)
53#define UART_GET_LSR(p) __raw_readl((p)->membase + KS8695_URLS)
54#define UART_GET_LCR(p) __raw_readl((p)->membase + KS8695_URLC)
55#define UART_PUT_LCR(p, c) __raw_writel((c), (p)->membase + KS8695_URLC)
56#define UART_GET_MCR(p) __raw_readl((p)->membase + KS8695_URMC)
57#define UART_PUT_MCR(p, c) __raw_writel((c), (p)->membase + KS8695_URMC)
58#define UART_GET_BRDR(p) __raw_readl((p)->membase + KS8695_URBD)
59#define UART_PUT_BRDR(p, c) __raw_writel((c), (p)->membase + KS8695_URBD)
60
61#define KS8695_CLR_TX_INT() __raw_writel(1 << KS8695_IRQ_UART_TX, KS8695_IRQ_VA + KS8695_INTST)
62
63#define UART_DUMMY_LSR_RX 0x100
64#define UART_PORT_SIZE (KS8695_USR - KS8695_URRB + 4)
65
66#define tx_enabled(port) ((port)->unused[0])
67#define rx_enabled(port) ((port)->unused[1])
68
69
70#ifdef SUPPORT_SYSRQ
71static struct console ks8695_console;
72#endif
73
74static void ks8695uart_stop_tx(struct uart_port *port)
75{
76 if (tx_enabled(port)) {
77 disable_irq(KS8695_IRQ_UART_TX);
78 tx_enabled(port) = 0;
79 }
80}
81
82static void ks8695uart_start_tx(struct uart_port *port)
83{
84 if (!tx_enabled(port)) {
85 enable_irq(KS8695_IRQ_UART_TX);
86 tx_enabled(port) = 1;
87 }
88}
89
90static void ks8695uart_stop_rx(struct uart_port *port)
91{
92 if (rx_enabled(port)) {
93 disable_irq(KS8695_IRQ_UART_RX);
94 rx_enabled(port) = 0;
95 }
96}
97
98static void ks8695uart_enable_ms(struct uart_port *port)
99{
100 enable_irq(KS8695_IRQ_UART_MODEM_STATUS);
101}
102
103static void ks8695uart_disable_ms(struct uart_port *port)
104{
105 disable_irq(KS8695_IRQ_UART_MODEM_STATUS);
106}
107
108static irqreturn_t ks8695uart_rx_chars(int irq, void *dev_id)
109{
110 struct uart_port *port = dev_id;
111 struct tty_struct *tty = port->info->tty;
112 unsigned int status, ch, lsr, flg, max_count = 256;
113
114 status = UART_GET_LSR(port); /* clears pending LSR interrupts */
115 while ((status & URLS_URDR) && max_count--) {
116 ch = UART_GET_CHAR(port);
117 flg = TTY_NORMAL;
118
119 port->icount.rx++;
120
121 /*
122 * Note that the error handling code is
123 * out of the main execution path
124 */
125 lsr = UART_GET_LSR(port) | UART_DUMMY_LSR_RX;
126 if (unlikely(lsr & (URLS_URBI | URLS_URPE | URLS_URFE | URLS_URROE))) {
127 if (lsr & URLS_URBI) {
128 lsr &= ~(URLS_URFE | URLS_URPE);
129 port->icount.brk++;
130 if (uart_handle_break(port))
131 goto ignore_char;
132 }
133 if (lsr & URLS_URPE)
134 port->icount.parity++;
135 if (lsr & URLS_URFE)
136 port->icount.frame++;
137 if (lsr & URLS_URROE)
138 port->icount.overrun++;
139
140 lsr &= port->read_status_mask;
141
142 if (lsr & URLS_URBI)
143 flg = TTY_BREAK;
144 else if (lsr & URLS_URPE)
145 flg = TTY_PARITY;
146 else if (lsr & URLS_URFE)
147 flg = TTY_FRAME;
148 }
149
150 if (uart_handle_sysrq_char(port, ch))
151 goto ignore_char;
152
153 uart_insert_char(port, lsr, URLS_URROE, ch, flg);
154
155ignore_char:
156 status = UART_GET_LSR(port);
157 }
158 tty_flip_buffer_push(tty);
159
160 return IRQ_HANDLED;
161}
162
163
164static irqreturn_t ks8695uart_tx_chars(int irq, void *dev_id)
165{
166 struct uart_port *port = dev_id;
167 struct circ_buf *xmit = &port->info->xmit;
168 unsigned int count;
169
170 if (port->x_char) {
171 KS8695_CLR_TX_INT();
172 UART_PUT_CHAR(port, port->x_char);
173 port->icount.tx++;
174 port->x_char = 0;
175 return IRQ_HANDLED;
176 }
177
178 if (uart_tx_stopped(port) || uart_circ_empty(xmit)) {
179 ks8695uart_stop_tx(port);
180 return IRQ_HANDLED;
181 }
182
183 count = 16; /* fifo size */
184 while (!uart_circ_empty(xmit) && (count-- > 0)) {
185 KS8695_CLR_TX_INT();
186 UART_PUT_CHAR(port, xmit->buf[xmit->tail]);
187
188 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
189 port->icount.tx++;
190 }
191
192 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
193 uart_write_wakeup(port);
194
195 if (uart_circ_empty(xmit))
196 ks8695uart_stop_tx(port);
197
198 return IRQ_HANDLED;
199}
200
201static irqreturn_t ks8695uart_modem_status(int irq, void *dev_id)
202{
203 struct uart_port *port = dev_id;
204 unsigned int status;
205
206 /*
207 * clear modem interrupt by reading MSR
208 */
209 status = UART_GET_MSR(port);
210
211 if (status & URMS_URDDCD)
212 uart_handle_dcd_change(port, status & URMS_URDDCD);
213
214 if (status & URMS_URDDST)
215 port->icount.dsr++;
216
217 if (status & URMS_URDCTS)
218 uart_handle_cts_change(port, status & URMS_URDCTS);
219
220 if (status & URMS_URTERI)
221 port->icount.rng++;
222
223 wake_up_interruptible(&port->info->delta_msr_wait);
224
225 return IRQ_HANDLED;
226}
227
228static unsigned int ks8695uart_tx_empty(struct uart_port *port)
229{
230 return (UART_GET_LSR(port) & URLS_URTE) ? TIOCSER_TEMT : 0;
231}
232
233static unsigned int ks8695uart_get_mctrl(struct uart_port *port)
234{
235 unsigned int result = 0;
236 unsigned int status;
237
238 status = UART_GET_MSR(port);
239 if (status & URMS_URDCD)
240 result |= TIOCM_CAR;
241 if (status & URMS_URDSR)
242 result |= TIOCM_DSR;
243 if (status & URMS_URCTS)
244 result |= TIOCM_CTS;
245 if (status & URMS_URRI)
246 result |= TIOCM_RI;
247
248 return result;
249}
250
251static void ks8695uart_set_mctrl(struct uart_port *port, u_int mctrl)
252{
253 unsigned int mcr;
254
255 mcr = UART_GET_MCR(port);
256 if (mctrl & TIOCM_RTS)
257 mcr |= URMC_URRTS;
258 else
259 mcr &= ~URMC_URRTS;
260
261 if (mctrl & TIOCM_DTR)
262 mcr |= URMC_URDTR;
263 else
264 mcr &= ~URMC_URDTR;
265
266 UART_PUT_MCR(port, mcr);
267}
268
269static void ks8695uart_break_ctl(struct uart_port *port, int break_state)
270{
271 unsigned int lcr;
272
273 lcr = UART_GET_LCR(port);
274
275 if (break_state == -1)
276 lcr |= URLC_URSBC;
277 else
278 lcr &= ~URLC_URSBC;
279
280 UART_PUT_LCR(port, lcr);
281}
282
283static int ks8695uart_startup(struct uart_port *port)
284{
285 int retval;
286
287 set_irq_flags(KS8695_IRQ_UART_TX, IRQF_VALID | IRQF_NOAUTOEN);
288 tx_enabled(port) = 0;
289 rx_enabled(port) = 1;
290
291 /*
292 * Allocate the IRQ
293 */
294 retval = request_irq(KS8695_IRQ_UART_TX, ks8695uart_tx_chars, IRQF_DISABLED, "UART TX", port);
295 if (retval)
296 goto err_tx;
297
298 retval = request_irq(KS8695_IRQ_UART_RX, ks8695uart_rx_chars, IRQF_DISABLED, "UART RX", port);
299 if (retval)
300 goto err_rx;
301
302 retval = request_irq(KS8695_IRQ_UART_LINE_STATUS, ks8695uart_rx_chars, IRQF_DISABLED, "UART LineStatus", port);
303 if (retval)
304 goto err_ls;
305
306 retval = request_irq(KS8695_IRQ_UART_MODEM_STATUS, ks8695uart_modem_status, IRQF_DISABLED, "UART ModemStatus", port);
307 if (retval)
308 goto err_ms;
309
310 return 0;
311
312err_ms:
313 free_irq(KS8695_IRQ_UART_LINE_STATUS, port);
314err_ls:
315 free_irq(KS8695_IRQ_UART_RX, port);
316err_rx:
317 free_irq(KS8695_IRQ_UART_TX, port);
318err_tx:
319 return retval;
320}
321
322static void ks8695uart_shutdown(struct uart_port *port)
323{
324 /*
325 * Free the interrupt
326 */
327 free_irq(KS8695_IRQ_UART_RX, port);
328 free_irq(KS8695_IRQ_UART_TX, port);
329 free_irq(KS8695_IRQ_UART_MODEM_STATUS, port);
330 free_irq(KS8695_IRQ_UART_LINE_STATUS, port);
331
332 /* disable break condition and fifos */
333 UART_PUT_LCR(port, UART_GET_LCR(port) & ~URLC_URSBC);
334 UART_PUT_FCR(port, UART_GET_FCR(port) & ~URFC_URFE);
335}
336
337static void ks8695uart_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old)
338{
339 unsigned int lcr, fcr = 0;
340 unsigned long flags;
341 unsigned int baud, quot;
342
343 /*
344 * Ask the core to calculate the divisor for us.
345 */
346 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
347 quot = uart_get_divisor(port, baud);
348
349 switch (termios->c_cflag & CSIZE) {
350 case CS5:
351 lcr = URCL_5;
352 break;
353 case CS6:
354 lcr = URCL_6;
355 break;
356 case CS7:
357 lcr = URCL_7;
358 break;
359 default:
360 lcr = URCL_8;
361 break;
362 }
363
364 /* stop bits */
365 if (termios->c_cflag & CSTOPB)
366 lcr |= URLC_URSB;
367
368 /* parity */
369 if (termios->c_cflag & PARENB) {
370 if (termios->c_cflag & CMSPAR) { /* Mark or Space parity */
371 if (termios->c_cflag & PARODD)
372 lcr |= URPE_MARK;
373 else
374 lcr |= URPE_SPACE;
375 }
376 else if (termios->c_cflag & PARODD)
377 lcr |= URPE_ODD;
378 else
379 lcr |= URPE_EVEN;
380 }
381
382 if (port->fifosize > 1)
383 fcr = URFC_URFRT_8 | URFC_URTFR | URFC_URRFR | URFC_URFE;
384
385 spin_lock_irqsave(&port->lock, flags);
386
387 /*
388 * Update the per-port timeout.
389 */
390 uart_update_timeout(port, termios->c_cflag, baud);
391
392 port->read_status_mask = URLS_URROE;
393 if (termios->c_iflag & INPCK)
394 port->read_status_mask |= (URLS_URFE | URLS_URPE);
395 if (termios->c_iflag & (BRKINT | PARMRK))
396 port->read_status_mask |= URLS_URBI;
397
398 /*
399 * Characters to ignore
400 */
401 port->ignore_status_mask = 0;
402 if (termios->c_iflag & IGNPAR)
403 port->ignore_status_mask |= (URLS_URFE | URLS_URPE);
404 if (termios->c_iflag & IGNBRK) {
405 port->ignore_status_mask |= URLS_URBI;
406 /*
407 * If we're ignoring parity and break indicators,
408 * ignore overruns too (for real raw support).
409 */
410 if (termios->c_iflag & IGNPAR)
411 port->ignore_status_mask |= URLS_URROE;
412 }
413
414 /*
415 * Ignore all characters if CREAD is not set.
416 */
417 if ((termios->c_cflag & CREAD) == 0)
418 port->ignore_status_mask |= UART_DUMMY_LSR_RX;
419
420 /* first, disable everything */
421 if (UART_ENABLE_MS(port, termios->c_cflag))
422 ks8695uart_enable_ms(port);
423 else
424 ks8695uart_disable_ms(port);
425
426 /* Set baud rate */
427 UART_PUT_BRDR(port, quot);
428
429 UART_PUT_LCR(port, lcr);
430 UART_PUT_FCR(port, fcr);
431
432 spin_unlock_irqrestore(&port->lock, flags);
433}
434
435static const char *ks8695uart_type(struct uart_port *port)
436{
437 return port->type == PORT_KS8695 ? "KS8695" : NULL;
438}
439
440/*
441 * Release the memory region(s) being used by 'port'
442 */
443static void ks8695uart_release_port(struct uart_port *port)
444{
445 release_mem_region(port->mapbase, UART_PORT_SIZE);
446}
447
448/*
449 * Request the memory region(s) being used by 'port'
450 */
451static int ks8695uart_request_port(struct uart_port *port)
452{
453 return request_mem_region(port->mapbase, UART_PORT_SIZE,
454 "serial_ks8695") != NULL ? 0 : -EBUSY;
455}
456
457/*
458 * Configure/autoconfigure the port.
459 */
460static void ks8695uart_config_port(struct uart_port *port, int flags)
461{
462 if (flags & UART_CONFIG_TYPE) {
463 port->type = PORT_KS8695;
464 ks8695uart_request_port(port);
465 }
466}
467
468/*
469 * verify the new serial_struct (for TIOCSSERIAL).
470 */
471static int ks8695uart_verify_port(struct uart_port *port, struct serial_struct *ser)
472{
473 int ret = 0;
474
475 if (ser->type != PORT_UNKNOWN && ser->type != PORT_KS8695)
476 ret = -EINVAL;
477 if (ser->irq != port->irq)
478 ret = -EINVAL;
479 if (ser->baud_base < 9600)
480 ret = -EINVAL;
481 return ret;
482}
483
484static struct uart_ops ks8695uart_pops = {
485 .tx_empty = ks8695uart_tx_empty,
486 .set_mctrl = ks8695uart_set_mctrl,
487 .get_mctrl = ks8695uart_get_mctrl,
488 .stop_tx = ks8695uart_stop_tx,
489 .start_tx = ks8695uart_start_tx,
490 .stop_rx = ks8695uart_stop_rx,
491 .enable_ms = ks8695uart_enable_ms,
492 .break_ctl = ks8695uart_break_ctl,
493 .startup = ks8695uart_startup,
494 .shutdown = ks8695uart_shutdown,
495 .set_termios = ks8695uart_set_termios,
496 .type = ks8695uart_type,
497 .release_port = ks8695uart_release_port,
498 .request_port = ks8695uart_request_port,
499 .config_port = ks8695uart_config_port,
500 .verify_port = ks8695uart_verify_port,
501};
502
503static struct uart_port ks8695uart_ports[SERIAL_KS8695_NR] = {
504 {
505 .membase = (void *) KS8695_UART_VA,
506 .mapbase = KS8695_UART_VA,
507 .iotype = SERIAL_IO_MEM,
508 .irq = KS8695_IRQ_UART_TX,
509 .uartclk = CLOCK_TICK_RATE * 16,
510 .fifosize = 16,
511 .ops = &ks8695uart_pops,
512 .flags = ASYNC_BOOT_AUTOCONF,
513 .line = 0,
514 }
515};
516
517#ifdef CONFIG_SERIAL_KS8695_CONSOLE
518static void ks8695_console_putchar(struct uart_port *port, int ch)
519{
520 while (!(UART_GET_LSR(port) & URLS_URTHRE))
521 barrier();
522
523 UART_PUT_CHAR(port, ch);
524}
525
526static void ks8695_console_write(struct console *co, const char *s, u_int count)
527{
528 struct uart_port *port = ks8695uart_ports + co->index;
529
530 uart_console_write(port, s, count, ks8695_console_putchar);
531}
532
533static void __init ks8695_console_get_options(struct uart_port *port, int *baud, int *parity, int *bits)
534{
535 unsigned int lcr;
536
537 lcr = UART_GET_LCR(port);
538
539 switch (lcr & URLC_PARITY) {
540 case URPE_ODD:
541 *parity = 'o';
542 break;
543 case URPE_EVEN:
544 *parity = 'e';
545 break;
546 default:
547 *parity = 'n';
548 }
549
550 switch (lcr & URLC_URCL) {
551 case URCL_5:
552 *bits = 5;
553 break;
554 case URCL_6:
555 *bits = 6;
556 break;
557 case URCL_7:
558 *bits = 7;
559 break;
560 default:
561 *bits = 8;
562 }
563
564 *baud = port->uartclk / (UART_GET_BRDR(port) & 0x0FFF);
565 *baud /= 16;
566 *baud &= 0xFFFFFFF0;
567}
568
569static int __init ks8695_console_setup(struct console *co, char *options)
570{
571 struct uart_port *port;
572 int baud = 115200;
573 int bits = 8;
574 int parity = 'n';
575 int flow = 'n';
576
577 /*
578 * Check whether an invalid uart number has been specified, and
579 * if so, search for the first available port that does have
580 * console support.
581 */
582 port = uart_get_console(ks8695uart_ports, SERIAL_KS8695_NR, co);
583
584 if (options)
585 uart_parse_options(options, &baud, &parity, &bits, &flow);
586 else
587 ks8695_console_get_options(port, &baud, &parity, &bits);
588
589 return uart_set_options(port, co, baud, parity, bits, flow);
590}
591
592extern struct uart_driver ks8695_reg;
593
594static struct console ks8695_console = {
595 .name = SERIAL_KS8695_DEVNAME,
596 .write = ks8695_console_write,
597 .device = uart_console_device,
598 .setup = ks8695_console_setup,
599 .flags = CON_PRINTBUFFER,
600 .index = -1,
601 .data = &ks8695_reg,
602};
603
604static int __init ks8695_console_init(void)
605{
606 register_console(&ks8695_console);
607 return 0;
608}
609
610console_initcall(ks8695_console_init);
611
612#define KS8695_CONSOLE &ks8695_console
613#else
614#define KS8695_CONSOLE NULL
615#endif
616
617static struct uart_driver ks8695_reg = {
618 .owner = THIS_MODULE,
619 .driver_name = "serial_ks8695",
620 .dev_name = SERIAL_KS8695_DEVNAME,
621 .major = SERIAL_KS8695_MAJOR,
622 .minor = SERIAL_KS8695_MINOR,
623 .nr = SERIAL_KS8695_NR,
624 .cons = KS8695_CONSOLE,
625};
626
627static int __init ks8695uart_init(void)
628{
629 int i, ret;
630
631 printk(KERN_INFO "Serial: Micrel KS8695 UART driver\n");
632
633 ret = uart_register_driver(&ks8695_reg);
634 if (ret)
635 return ret;
636
637 for (i = 0; i < SERIAL_KS8695_NR; i++)
638 uart_add_one_port(&ks8695_reg, &ks8695uart_ports[0]);
639
640 return 0;
641}
642
643static void __exit ks8695uart_exit(void)
644{
645 int i;
646
647 for (i = 0; i < SERIAL_KS8695_NR; i++)
648 uart_remove_one_port(&ks8695_reg, &ks8695uart_ports[0]);
649 uart_unregister_driver(&ks8695_reg);
650}
651
652module_init(ks8695uart_init);
653module_exit(ks8695uart_exit);
654
655MODULE_DESCRIPTION("KS8695 serial port driver");
656MODULE_AUTHOR("Micrel Inc.");
657MODULE_LICENSE("GPL");
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index 509ace7e6881..1deb5764326d 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -15,31 +15,6 @@
15 * published by the Free Software Foundation. 15 * published by the Free Software Foundation.
16 * 16 *
17 * Serial driver for TX3927/TX4927/TX4925/TX4938 internal SIO controller 17 * Serial driver for TX3927/TX4927/TX4925/TX4938 internal SIO controller
18 *
19 * Revision History:
20 * 0.30 Initial revision. (Renamed from serial_txx927.c)
21 * 0.31 Use save_flags instead of local_irq_save.
22 * 0.32 Support SCLK.
23 * 0.33 Switch TXX9_TTY_NAME by CONFIG_SERIAL_TXX9_STDSERIAL.
24 * Support TIOCSERGETLSR.
25 * 0.34 Support slow baudrate.
26 * 0.40 Merge codes from mainstream kernel (2.4.22).
27 * 0.41 Fix console checking in rs_shutdown_port().
28 * Disable flow-control in serial_console_write().
29 * 0.42 Fix minor compiler warning.
30 * 1.00 Kernel 2.6. Converted to new serial core (based on 8250.c).
31 * 1.01 Set fifosize to make tx_empry called properly.
32 * Use standard uart_get_divisor.
33 * 1.02 Cleanup. (import 8250.c changes)
34 * 1.03 Fix low-latency mode. (import 8250.c changes)
35 * 1.04 Remove usage of deprecated functions, cleanup.
36 * 1.05 More strict check in verify_port. Cleanup.
37 * 1.06 Do not insert a char caused previous overrun.
38 * Fix some spin_locks.
39 * Do not call uart_add_one_port for absent ports.
40 * 1.07 Use CONFIG_SERIAL_TXX9_NR_UARTS. Cleanup.
41 * 1.08 Use platform_device.
42 * Fix and cleanup suspend/resume/initialization codes.
43 */ 18 */
44 19
45#if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 20#if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
@@ -62,7 +37,7 @@
62 37
63#include <asm/io.h> 38#include <asm/io.h>
64 39
65static char *serial_version = "1.08"; 40static char *serial_version = "1.09";
66static char *serial_name = "TX39/49 Serial driver"; 41static char *serial_name = "TX39/49 Serial driver";
67 42
68#define PASS_LIMIT 256 43#define PASS_LIMIT 256
@@ -70,13 +45,14 @@ static char *serial_name = "TX39/49 Serial driver";
70#if !defined(CONFIG_SERIAL_TXX9_STDSERIAL) 45#if !defined(CONFIG_SERIAL_TXX9_STDSERIAL)
71/* "ttyS" is used for standard serial driver */ 46/* "ttyS" is used for standard serial driver */
72#define TXX9_TTY_NAME "ttyTX" 47#define TXX9_TTY_NAME "ttyTX"
73#define TXX9_TTY_MINOR_START (64 + 64) /* ttyTX0(128), ttyTX1(129) */ 48#define TXX9_TTY_MINOR_START 196
49#define TXX9_TTY_MAJOR 204
74#else 50#else
75/* acts like standard serial driver */ 51/* acts like standard serial driver */
76#define TXX9_TTY_NAME "ttyS" 52#define TXX9_TTY_NAME "ttyS"
77#define TXX9_TTY_MINOR_START 64 53#define TXX9_TTY_MINOR_START 64
78#endif
79#define TXX9_TTY_MAJOR TTY_MAJOR 54#define TXX9_TTY_MAJOR TTY_MAJOR
55#endif
80 56
81/* flag aliases */ 57/* flag aliases */
82#define UPF_TXX9_HAVE_CTS_LINE UPF_BUGGY_UART 58#define UPF_TXX9_HAVE_CTS_LINE UPF_BUGGY_UART
diff --git a/drivers/serial/sunhv.c b/drivers/serial/sunhv.c
index 40d48566215c..96557e6dba60 100644
--- a/drivers/serial/sunhv.c
+++ b/drivers/serial/sunhv.c
@@ -1,6 +1,6 @@
1/* sunhv.c: Serial driver for SUN4V hypervisor console. 1/* sunhv.c: Serial driver for SUN4V hypervisor console.
2 * 2 *
3 * Copyright (C) 2006 David S. Miller (davem@davemloft.net) 3 * Copyright (C) 2006, 2007 David S. Miller (davem@davemloft.net)
4 */ 4 */
5 5
6#include <linux/module.h> 6#include <linux/module.h>
@@ -35,57 +35,51 @@
35#define CON_BREAK ((long)-1) 35#define CON_BREAK ((long)-1)
36#define CON_HUP ((long)-2) 36#define CON_HUP ((long)-2)
37 37
38static inline long hypervisor_con_getchar(long *status) 38#define IGNORE_BREAK 0x1
39{ 39#define IGNORE_ALL 0x2
40 register unsigned long func asm("%o5");
41 register unsigned long arg0 asm("%o0");
42 register unsigned long arg1 asm("%o1");
43
44 func = HV_FAST_CONS_GETCHAR;
45 arg0 = 0;
46 arg1 = 0;
47 __asm__ __volatile__("ta %6"
48 : "=&r" (func), "=&r" (arg0), "=&r" (arg1)
49 : "0" (func), "1" (arg0), "2" (arg1),
50 "i" (HV_FAST_TRAP));
51 40
52 *status = arg0; 41static char *con_write_page;
42static char *con_read_page;
53 43
54 return (long) arg1; 44static int hung_up = 0;
55}
56 45
57static inline long hypervisor_con_putchar(long ch) 46static void transmit_chars_putchar(struct uart_port *port, struct circ_buf *xmit)
58{ 47{
59 register unsigned long func asm("%o5"); 48 while (!uart_circ_empty(xmit)) {
60 register unsigned long arg0 asm("%o0"); 49 long status = sun4v_con_putchar(xmit->buf[xmit->tail]);
61 50
62 func = HV_FAST_CONS_PUTCHAR; 51 if (status != HV_EOK)
63 arg0 = ch; 52 break;
64 __asm__ __volatile__("ta %4"
65 : "=&r" (func), "=&r" (arg0)
66 : "0" (func), "1" (arg0), "i" (HV_FAST_TRAP));
67 53
68 return (long) arg0; 54 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
55 port->icount.tx++;
56 }
69} 57}
70 58
71#define IGNORE_BREAK 0x1 59static void transmit_chars_write(struct uart_port *port, struct circ_buf *xmit)
72#define IGNORE_ALL 0x2 60{
61 while (!uart_circ_empty(xmit)) {
62 unsigned long ra = __pa(xmit->buf + xmit->tail);
63 unsigned long len, status, sent;
73 64
74static int hung_up = 0; 65 len = CIRC_CNT_TO_END(xmit->head, xmit->tail,
66 UART_XMIT_SIZE);
67 status = sun4v_con_write(ra, len, &sent);
68 if (status != HV_EOK)
69 break;
70 xmit->tail = (xmit->tail + sent) & (UART_XMIT_SIZE - 1);
71 port->icount.tx += sent;
72 }
73}
75 74
76static struct tty_struct *receive_chars(struct uart_port *port) 75static int receive_chars_getchar(struct uart_port *port, struct tty_struct *tty)
77{ 76{
78 struct tty_struct *tty = NULL;
79 int saw_console_brk = 0; 77 int saw_console_brk = 0;
80 int limit = 10000; 78 int limit = 10000;
81 79
82 if (port->info != NULL) /* Unopened serial console */
83 tty = port->info->tty;
84
85 while (limit-- > 0) { 80 while (limit-- > 0) {
86 long status; 81 long status;
87 long c = hypervisor_con_getchar(&status); 82 long c = sun4v_con_getchar(&status);
88 unsigned char flag;
89 83
90 if (status == HV_EWOULDBLOCK) 84 if (status == HV_EWOULDBLOCK)
91 break; 85 break;
@@ -110,27 +104,90 @@ static struct tty_struct *receive_chars(struct uart_port *port)
110 continue; 104 continue;
111 } 105 }
112 106
113 flag = TTY_NORMAL;
114 port->icount.rx++; 107 port->icount.rx++;
115 if (c == CON_BREAK) {
116 port->icount.brk++;
117 if (uart_handle_break(port))
118 continue;
119 flag = TTY_BREAK;
120 }
121 108
122 if (uart_handle_sysrq_char(port, c)) 109 if (uart_handle_sysrq_char(port, c))
123 continue; 110 continue;
124 111
125 if ((port->ignore_status_mask & IGNORE_ALL) || 112 tty_insert_flip_char(tty, c, TTY_NORMAL);
126 ((port->ignore_status_mask & IGNORE_BREAK) && 113 }
127 (c == CON_BREAK))) 114
115 return saw_console_brk;
116}
117
118static int receive_chars_read(struct uart_port *port, struct tty_struct *tty)
119{
120 int saw_console_brk = 0;
121 int limit = 10000;
122
123 while (limit-- > 0) {
124 unsigned long ra = __pa(con_read_page);
125 unsigned long bytes_read, i;
126 long stat = sun4v_con_read(ra, PAGE_SIZE, &bytes_read);
127
128 if (stat != HV_EOK) {
129 bytes_read = 0;
130
131 if (stat == CON_BREAK) {
132 if (uart_handle_break(port))
133 continue;
134 saw_console_brk = 1;
135 *con_read_page = 0;
136 bytes_read = 1;
137 } else if (stat == CON_HUP) {
138 hung_up = 1;
139 uart_handle_dcd_change(port, 0);
140 continue;
141 } else {
142 /* HV_EWOULDBLOCK, etc. */
143 break;
144 }
145 }
146
147 if (hung_up) {
148 hung_up = 0;
149 uart_handle_dcd_change(port, 1);
150 }
151
152 for (i = 0; i < bytes_read; i++)
153 uart_handle_sysrq_char(port, con_read_page[i]);
154
155 if (tty == NULL)
128 continue; 156 continue;
129 157
130 tty_insert_flip_char(tty, c, flag); 158 port->icount.rx += bytes_read;
159
160 tty_insert_flip_string(tty, con_read_page, bytes_read);
131 } 161 }
132 162
133 if (saw_console_brk) 163 return saw_console_brk;
164}
165
166struct sunhv_ops {
167 void (*transmit_chars)(struct uart_port *port, struct circ_buf *xmit);
168 int (*receive_chars)(struct uart_port *port, struct tty_struct *tty);
169};
170
171static struct sunhv_ops bychar_ops = {
172 .transmit_chars = transmit_chars_putchar,
173 .receive_chars = receive_chars_getchar,
174};
175
176static struct sunhv_ops bywrite_ops = {
177 .transmit_chars = transmit_chars_write,
178 .receive_chars = receive_chars_read,
179};
180
181static struct sunhv_ops *sunhv_ops = &bychar_ops;
182
183static struct tty_struct *receive_chars(struct uart_port *port)
184{
185 struct tty_struct *tty = NULL;
186
187 if (port->info != NULL) /* Unopened serial console */
188 tty = port->info->tty;
189
190 if (sunhv_ops->receive_chars(port, tty))
134 sun_do_break(); 191 sun_do_break();
135 192
136 return tty; 193 return tty;
@@ -147,15 +204,7 @@ static void transmit_chars(struct uart_port *port)
147 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) 204 if (uart_circ_empty(xmit) || uart_tx_stopped(port))
148 return; 205 return;
149 206
150 while (!uart_circ_empty(xmit)) { 207 sunhv_ops->transmit_chars(port, xmit);
151 long status = hypervisor_con_putchar(xmit->buf[xmit->tail]);
152
153 if (status != HV_EOK)
154 break;
155
156 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
157 port->icount.tx++;
158 }
159 208
160 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 209 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
161 uart_write_wakeup(port); 210 uart_write_wakeup(port);
@@ -212,7 +261,7 @@ static void sunhv_start_tx(struct uart_port *port)
212 struct circ_buf *xmit = &port->info->xmit; 261 struct circ_buf *xmit = &port->info->xmit;
213 262
214 while (!uart_circ_empty(xmit)) { 263 while (!uart_circ_empty(xmit)) {
215 long status = hypervisor_con_putchar(xmit->buf[xmit->tail]); 264 long status = sun4v_con_putchar(xmit->buf[xmit->tail]);
216 265
217 if (status != HV_EOK) 266 if (status != HV_EOK)
218 break; 267 break;
@@ -231,9 +280,10 @@ static void sunhv_send_xchar(struct uart_port *port, char ch)
231 spin_lock_irqsave(&port->lock, flags); 280 spin_lock_irqsave(&port->lock, flags);
232 281
233 while (limit-- > 0) { 282 while (limit-- > 0) {
234 long status = hypervisor_con_putchar(ch); 283 long status = sun4v_con_putchar(ch);
235 if (status == HV_EOK) 284 if (status == HV_EOK)
236 break; 285 break;
286 udelay(1);
237 } 287 }
238 288
239 spin_unlock_irqrestore(&port->lock, flags); 289 spin_unlock_irqrestore(&port->lock, flags);
@@ -254,15 +304,15 @@ static void sunhv_break_ctl(struct uart_port *port, int break_state)
254{ 304{
255 if (break_state) { 305 if (break_state) {
256 unsigned long flags; 306 unsigned long flags;
257 int limit = 1000000; 307 int limit = 10000;
258 308
259 spin_lock_irqsave(&port->lock, flags); 309 spin_lock_irqsave(&port->lock, flags);
260 310
261 while (limit-- > 0) { 311 while (limit-- > 0) {
262 long status = hypervisor_con_putchar(CON_BREAK); 312 long status = sun4v_con_putchar(CON_BREAK);
263 if (status == HV_EOK) 313 if (status == HV_EOK)
264 break; 314 break;
265 udelay(2); 315 udelay(1);
266 } 316 }
267 317
268 spin_unlock_irqrestore(&port->lock, flags); 318 spin_unlock_irqrestore(&port->lock, flags);
@@ -359,38 +409,99 @@ static struct uart_driver sunhv_reg = {
359 409
360static struct uart_port *sunhv_port; 410static struct uart_port *sunhv_port;
361 411
362static inline void sunhv_console_putchar(struct uart_port *port, char c) 412/* Copy 's' into the con_write_page, decoding "\n" into
413 * "\r\n" along the way. We have to return two lengths
414 * because the caller needs to know how much to advance
415 * 's' and also how many bytes to output via con_write_page.
416 */
417static int fill_con_write_page(const char *s, unsigned int n,
418 unsigned long *page_bytes)
363{ 419{
420 const char *orig_s = s;
421 char *p = con_write_page;
422 int left = PAGE_SIZE;
423
424 while (n--) {
425 if (*s == '\n') {
426 if (left < 2)
427 break;
428 *p++ = '\r';
429 left--;
430 } else if (left < 1)
431 break;
432 *p++ = *s++;
433 left--;
434 }
435 *page_bytes = p - con_write_page;
436 return s - orig_s;
437}
438
439static void sunhv_console_write_paged(struct console *con, const char *s, unsigned n)
440{
441 struct uart_port *port = sunhv_port;
364 unsigned long flags; 442 unsigned long flags;
365 int limit = 1000000;
366 443
367 spin_lock_irqsave(&port->lock, flags); 444 spin_lock_irqsave(&port->lock, flags);
445 while (n > 0) {
446 unsigned long ra = __pa(con_write_page);
447 unsigned long page_bytes;
448 unsigned int cpy = fill_con_write_page(s, n,
449 &page_bytes);
450
451 n -= cpy;
452 s += cpy;
453 while (page_bytes > 0) {
454 unsigned long written;
455 int limit = 1000000;
456
457 while (limit--) {
458 unsigned long stat;
459
460 stat = sun4v_con_write(ra, page_bytes,
461 &written);
462 if (stat == HV_EOK)
463 break;
464 udelay(1);
465 }
466 if (limit <= 0)
467 break;
468 page_bytes -= written;
469 ra += written;
470 }
471 }
472 spin_unlock_irqrestore(&port->lock, flags);
473}
474
475static inline void sunhv_console_putchar(struct uart_port *port, char c)
476{
477 int limit = 1000000;
368 478
369 while (limit-- > 0) { 479 while (limit-- > 0) {
370 long status = hypervisor_con_putchar(c); 480 long status = sun4v_con_putchar(c);
371 if (status == HV_EOK) 481 if (status == HV_EOK)
372 break; 482 break;
373 udelay(2); 483 udelay(1);
374 } 484 }
375
376 spin_unlock_irqrestore(&port->lock, flags);
377} 485}
378 486
379static void sunhv_console_write(struct console *con, const char *s, unsigned n) 487static void sunhv_console_write_bychar(struct console *con, const char *s, unsigned n)
380{ 488{
381 struct uart_port *port = sunhv_port; 489 struct uart_port *port = sunhv_port;
490 unsigned long flags;
382 int i; 491 int i;
383 492
493 spin_lock_irqsave(&port->lock, flags);
384 for (i = 0; i < n; i++) { 494 for (i = 0; i < n; i++) {
385 if (*s == '\n') 495 if (*s == '\n')
386 sunhv_console_putchar(port, '\r'); 496 sunhv_console_putchar(port, '\r');
387 sunhv_console_putchar(port, *s++); 497 sunhv_console_putchar(port, *s++);
388 } 498 }
499 spin_unlock_irqrestore(&port->lock, flags);
389} 500}
390 501
391static struct console sunhv_console = { 502static struct console sunhv_console = {
392 .name = "ttyHV", 503 .name = "ttyHV",
393 .write = sunhv_console_write, 504 .write = sunhv_console_write_bychar,
394 .device = uart_console_device, 505 .device = uart_console_device,
395 .flags = CON_PRINTBUFFER, 506 .flags = CON_PRINTBUFFER,
396 .index = -1, 507 .index = -1,
@@ -410,6 +521,7 @@ static inline struct console *SUNHV_CONSOLE(void)
410static int __devinit hv_probe(struct of_device *op, const struct of_device_id *match) 521static int __devinit hv_probe(struct of_device *op, const struct of_device_id *match)
411{ 522{
412 struct uart_port *port; 523 struct uart_port *port;
524 unsigned long minor;
413 int err; 525 int err;
414 526
415 if (op->irqs[0] == 0xffffffff) 527 if (op->irqs[0] == 0xffffffff)
@@ -419,6 +531,22 @@ static int __devinit hv_probe(struct of_device *op, const struct of_device_id *m
419 if (unlikely(!port)) 531 if (unlikely(!port))
420 return -ENOMEM; 532 return -ENOMEM;
421 533
534 minor = 1;
535 if (sun4v_hvapi_register(HV_GRP_CORE, 1, &minor) == 0 &&
536 minor >= 1) {
537 err = -ENOMEM;
538 con_write_page = kzalloc(PAGE_SIZE, GFP_KERNEL);
539 if (!con_write_page)
540 goto out_free_port;
541
542 con_read_page = kzalloc(PAGE_SIZE, GFP_KERNEL);
543 if (!con_read_page)
544 goto out_free_con_write_page;
545
546 sunhv_console.write = sunhv_console_write_paged;
547 sunhv_ops = &bywrite_ops;
548 }
549
422 sunhv_port = port; 550 sunhv_port = port;
423 551
424 port->line = 0; 552 port->line = 0;
@@ -437,7 +565,7 @@ static int __devinit hv_probe(struct of_device *op, const struct of_device_id *m
437 565
438 err = uart_register_driver(&sunhv_reg); 566 err = uart_register_driver(&sunhv_reg);
439 if (err) 567 if (err)
440 goto out_free_port; 568 goto out_free_con_read_page;
441 569
442 sunhv_reg.tty_driver->name_base = sunhv_reg.minor - 64; 570 sunhv_reg.tty_driver->name_base = sunhv_reg.minor - 64;
443 sunserial_current_minor += 1; 571 sunserial_current_minor += 1;
@@ -463,6 +591,12 @@ out_unregister_driver:
463 sunserial_current_minor -= 1; 591 sunserial_current_minor -= 1;
464 uart_unregister_driver(&sunhv_reg); 592 uart_unregister_driver(&sunhv_reg);
465 593
594out_free_con_read_page:
595 kfree(con_read_page);
596
597out_free_con_write_page:
598 kfree(con_write_page);
599
466out_free_port: 600out_free_port:
467 kfree(port); 601 kfree(port);
468 sunhv_port = NULL; 602 sunhv_port = NULL;
@@ -493,6 +627,10 @@ static struct of_device_id hv_match[] = {
493 .name = "console", 627 .name = "console",
494 .compatible = "qcn", 628 .compatible = "qcn",
495 }, 629 },
630 {
631 .name = "console",
632 .compatible = "SUNW,sun4v-console",
633 },
496 {}, 634 {},
497}; 635};
498MODULE_DEVICE_TABLE(of, hv_match); 636MODULE_DEVICE_TABLE(of, hv_match);
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index da73205e54cd..0985193dc57d 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -92,6 +92,8 @@ struct uart_sunzilog_port {
92#define SUNZILOG_FLAG_REGS_HELD 0x00000040 92#define SUNZILOG_FLAG_REGS_HELD 0x00000040
93#define SUNZILOG_FLAG_TX_STOPPED 0x00000080 93#define SUNZILOG_FLAG_TX_STOPPED 0x00000080
94#define SUNZILOG_FLAG_TX_ACTIVE 0x00000100 94#define SUNZILOG_FLAG_TX_ACTIVE 0x00000100
95#define SUNZILOG_FLAG_ESCC 0x00000200
96#define SUNZILOG_FLAG_ISR_HANDLER 0x00000400
95 97
96 unsigned int cflag; 98 unsigned int cflag;
97 99
@@ -174,9 +176,11 @@ static void sunzilog_clear_fifo(struct zilog_channel __iomem *channel)
174/* This function must only be called when the TX is not busy. The UART 176/* This function must only be called when the TX is not busy. The UART
175 * port lock must be held and local interrupts disabled. 177 * port lock must be held and local interrupts disabled.
176 */ 178 */
177static void __load_zsregs(struct zilog_channel __iomem *channel, unsigned char *regs) 179static int __load_zsregs(struct zilog_channel __iomem *channel, unsigned char *regs)
178{ 180{
179 int i; 181 int i;
182 int escc;
183 unsigned char r15;
180 184
181 /* Let pending transmits finish. */ 185 /* Let pending transmits finish. */
182 for (i = 0; i < 1000; i++) { 186 for (i = 0; i < 1000; i++) {
@@ -229,11 +233,25 @@ static void __load_zsregs(struct zilog_channel __iomem *channel, unsigned char *
229 write_zsreg(channel, R14, regs[R14]); 233 write_zsreg(channel, R14, regs[R14]);
230 234
231 /* External status interrupt control. */ 235 /* External status interrupt control. */
232 write_zsreg(channel, R15, regs[R15]); 236 write_zsreg(channel, R15, (regs[R15] | WR7pEN) & ~FIFOEN);
237
238 /* ESCC Extension Register */
239 r15 = read_zsreg(channel, R15);
240 if (r15 & 0x01) {
241 write_zsreg(channel, R7, regs[R7p]);
242
243 /* External status interrupt and FIFO control. */
244 write_zsreg(channel, R15, regs[R15] & ~WR7pEN);
245 escc = 1;
246 } else {
247 /* Clear FIFO bit case it is an issue */
248 regs[R15] &= ~FIFOEN;
249 escc = 0;
250 }
233 251
234 /* Reset external status interrupts. */ 252 /* Reset external status interrupts. */
235 write_zsreg(channel, R0, RES_EXT_INT); 253 write_zsreg(channel, R0, RES_EXT_INT); /* First Latch */
236 write_zsreg(channel, R0, RES_EXT_INT); 254 write_zsreg(channel, R0, RES_EXT_INT); /* Second Latch */
237 255
238 /* Rewrite R3/R5, this time without enables masked. */ 256 /* Rewrite R3/R5, this time without enables masked. */
239 write_zsreg(channel, R3, regs[R3]); 257 write_zsreg(channel, R3, regs[R3]);
@@ -241,6 +259,8 @@ static void __load_zsregs(struct zilog_channel __iomem *channel, unsigned char *
241 259
242 /* Rewrite R1, this time without IRQ enabled masked. */ 260 /* Rewrite R1, this time without IRQ enabled masked. */
243 write_zsreg(channel, R1, regs[R1]); 261 write_zsreg(channel, R1, regs[R1]);
262
263 return escc;
244} 264}
245 265
246/* Reprogram the Zilog channel HW registers with the copies found in the 266/* Reprogram the Zilog channel HW registers with the copies found in the
@@ -731,7 +751,7 @@ static void sunzilog_enable_ms(struct uart_port *port)
731 up->curregs[R15] = new_reg; 751 up->curregs[R15] = new_reg;
732 752
733 /* NOTE: Not subject to 'transmitter active' rule. */ 753 /* NOTE: Not subject to 'transmitter active' rule. */
734 write_zsreg(channel, R15, up->curregs[R15]); 754 write_zsreg(channel, R15, up->curregs[R15] & ~WR7pEN);
735 } 755 }
736} 756}
737 757
@@ -861,44 +881,44 @@ sunzilog_convert_to_zs(struct uart_sunzilog_port *up, unsigned int cflag,
861 up->curregs[R14] = BRSRC | BRENAB; 881 up->curregs[R14] = BRSRC | BRENAB;
862 882
863 /* Character size, stop bits, and parity. */ 883 /* Character size, stop bits, and parity. */
864 up->curregs[3] &= ~RxN_MASK; 884 up->curregs[R3] &= ~RxN_MASK;
865 up->curregs[5] &= ~TxN_MASK; 885 up->curregs[R5] &= ~TxN_MASK;
866 switch (cflag & CSIZE) { 886 switch (cflag & CSIZE) {
867 case CS5: 887 case CS5:
868 up->curregs[3] |= Rx5; 888 up->curregs[R3] |= Rx5;
869 up->curregs[5] |= Tx5; 889 up->curregs[R5] |= Tx5;
870 up->parity_mask = 0x1f; 890 up->parity_mask = 0x1f;
871 break; 891 break;
872 case CS6: 892 case CS6:
873 up->curregs[3] |= Rx6; 893 up->curregs[R3] |= Rx6;
874 up->curregs[5] |= Tx6; 894 up->curregs[R5] |= Tx6;
875 up->parity_mask = 0x3f; 895 up->parity_mask = 0x3f;
876 break; 896 break;
877 case CS7: 897 case CS7:
878 up->curregs[3] |= Rx7; 898 up->curregs[R3] |= Rx7;
879 up->curregs[5] |= Tx7; 899 up->curregs[R5] |= Tx7;
880 up->parity_mask = 0x7f; 900 up->parity_mask = 0x7f;
881 break; 901 break;
882 case CS8: 902 case CS8:
883 default: 903 default:
884 up->curregs[3] |= Rx8; 904 up->curregs[R3] |= Rx8;
885 up->curregs[5] |= Tx8; 905 up->curregs[R5] |= Tx8;
886 up->parity_mask = 0xff; 906 up->parity_mask = 0xff;
887 break; 907 break;
888 }; 908 };
889 up->curregs[4] &= ~0x0c; 909 up->curregs[R4] &= ~0x0c;
890 if (cflag & CSTOPB) 910 if (cflag & CSTOPB)
891 up->curregs[4] |= SB2; 911 up->curregs[R4] |= SB2;
892 else 912 else
893 up->curregs[4] |= SB1; 913 up->curregs[R4] |= SB1;
894 if (cflag & PARENB) 914 if (cflag & PARENB)
895 up->curregs[4] |= PAR_ENAB; 915 up->curregs[R4] |= PAR_ENAB;
896 else 916 else
897 up->curregs[4] &= ~PAR_ENAB; 917 up->curregs[R4] &= ~PAR_ENAB;
898 if (!(cflag & PARODD)) 918 if (!(cflag & PARODD))
899 up->curregs[4] |= PAR_EVEN; 919 up->curregs[R4] |= PAR_EVEN;
900 else 920 else
901 up->curregs[4] &= ~PAR_EVEN; 921 up->curregs[R4] &= ~PAR_EVEN;
902 922
903 up->port.read_status_mask = Rx_OVR; 923 up->port.read_status_mask = Rx_OVR;
904 if (iflag & INPCK) 924 if (iflag & INPCK)
@@ -952,7 +972,9 @@ sunzilog_set_termios(struct uart_port *port, struct ktermios *termios,
952 972
953static const char *sunzilog_type(struct uart_port *port) 973static const char *sunzilog_type(struct uart_port *port)
954{ 974{
955 return "zs"; 975 struct uart_sunzilog_port *up = UART_ZILOG(port);
976
977 return (up->flags & SUNZILOG_FLAG_ESCC) ? "zs (ESCC)" : "zs";
956} 978}
957 979
958/* We do not request/release mappings of the registers here, this 980/* We do not request/release mappings of the registers here, this
@@ -1170,7 +1192,7 @@ static int __init sunzilog_console_setup(struct console *con, char *options)
1170 1192
1171 spin_lock_irqsave(&up->port.lock, flags); 1193 spin_lock_irqsave(&up->port.lock, flags);
1172 1194
1173 up->curregs[R15] = BRKIE; 1195 up->curregs[R15] |= BRKIE;
1174 sunzilog_convert_to_zs(up, con->cflag, 0, brg); 1196 sunzilog_convert_to_zs(up, con->cflag, 0, brg);
1175 1197
1176 sunzilog_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS); 1198 sunzilog_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS);
@@ -1229,7 +1251,7 @@ static void __init sunzilog_init_kbdms(struct uart_sunzilog_port *up, int channe
1229 baud = 4800; 1251 baud = 4800;
1230 } 1252 }
1231 1253
1232 up->curregs[R15] = BRKIE; 1254 up->curregs[R15] |= BRKIE;
1233 brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR); 1255 brg = BPS_TO_BRG(baud, ZS_CLOCK / ZS_CLOCK_DIVISOR);
1234 sunzilog_convert_to_zs(up, up->cflag, 0, brg); 1256 sunzilog_convert_to_zs(up, up->cflag, 0, brg);
1235 sunzilog_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS); 1257 sunzilog_set_mctrl(&up->port, TIOCM_DTR | TIOCM_RTS);
@@ -1283,8 +1305,18 @@ static void __devinit sunzilog_init_hw(struct uart_sunzilog_port *up)
1283 1305
1284 if (up->flags & (SUNZILOG_FLAG_CONS_KEYB | 1306 if (up->flags & (SUNZILOG_FLAG_CONS_KEYB |
1285 SUNZILOG_FLAG_CONS_MOUSE)) { 1307 SUNZILOG_FLAG_CONS_MOUSE)) {
1308 up->curregs[R1] = EXT_INT_ENAB | INT_ALL_Rx | TxINT_ENAB;
1309 up->curregs[R4] = PAR_EVEN | X16CLK | SB1;
1310 up->curregs[R3] = RxENAB | Rx8;
1311 up->curregs[R5] = TxENAB | Tx8;
1312 up->curregs[R6] = 0x00; /* SDLC Address */
1313 up->curregs[R7] = 0x7E; /* SDLC Flag */
1314 up->curregs[R9] = NV;
1315 up->curregs[R7p] = 0x00;
1286 sunzilog_init_kbdms(up, up->port.line); 1316 sunzilog_init_kbdms(up, up->port.line);
1287 up->curregs[R9] |= (NV | MIE); 1317 /* Only enable interrupts if an ISR handler available */
1318 if (up->flags & SUNZILOG_FLAG_ISR_HANDLER)
1319 up->curregs[R9] |= MIE;
1288 write_zsreg(channel, R9, up->curregs[R9]); 1320 write_zsreg(channel, R9, up->curregs[R9]);
1289 } else { 1321 } else {
1290 /* Normal serial TTY. */ 1322 /* Normal serial TTY. */
@@ -1293,7 +1325,9 @@ static void __devinit sunzilog_init_hw(struct uart_sunzilog_port *up)
1293 up->curregs[R4] = PAR_EVEN | X16CLK | SB1; 1325 up->curregs[R4] = PAR_EVEN | X16CLK | SB1;
1294 up->curregs[R3] = RxENAB | Rx8; 1326 up->curregs[R3] = RxENAB | Rx8;
1295 up->curregs[R5] = TxENAB | Tx8; 1327 up->curregs[R5] = TxENAB | Tx8;
1296 up->curregs[R9] = NV | MIE; 1328 up->curregs[R6] = 0x00; /* SDLC Address */
1329 up->curregs[R7] = 0x7E; /* SDLC Flag */
1330 up->curregs[R9] = NV;
1297 up->curregs[R10] = NRZ; 1331 up->curregs[R10] = NRZ;
1298 up->curregs[R11] = TCBR | RCBR; 1332 up->curregs[R11] = TCBR | RCBR;
1299 baud = 9600; 1333 baud = 9600;
@@ -1301,7 +1335,14 @@ static void __devinit sunzilog_init_hw(struct uart_sunzilog_port *up)
1301 up->curregs[R12] = (brg & 0xff); 1335 up->curregs[R12] = (brg & 0xff);
1302 up->curregs[R13] = (brg >> 8) & 0xff; 1336 up->curregs[R13] = (brg >> 8) & 0xff;
1303 up->curregs[R14] = BRSRC | BRENAB; 1337 up->curregs[R14] = BRSRC | BRENAB;
1304 __load_zsregs(channel, up->curregs); 1338 up->curregs[R15] = FIFOEN; /* Use FIFO if on ESCC */
1339 up->curregs[R7p] = TxFIFO_LVL | RxFIFO_LVL;
1340 if (__load_zsregs(channel, up->curregs)) {
1341 up->flags |= SUNZILOG_FLAG_ESCC;
1342 }
1343 /* Only enable interrupts if an ISR handler available */
1344 if (up->flags & SUNZILOG_FLAG_ISR_HANDLER)
1345 up->curregs[R9] |= MIE;
1305 write_zsreg(channel, R9, up->curregs[R9]); 1346 write_zsreg(channel, R9, up->curregs[R9]);
1306 } 1347 }
1307 1348
@@ -1390,12 +1431,14 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1390 return err; 1431 return err;
1391 } 1432 }
1392 } else { 1433 } else {
1393 printk(KERN_INFO "%s: Keyboard at MMIO %lx (irq = %d) " 1434 printk(KERN_INFO "%s: Keyboard at MMIO 0x%lx (irq = %d) "
1394 "is a zs\n", 1435 "is a %s\n",
1395 op->dev.bus_id, up[0].port.mapbase, op->irqs[0]); 1436 op->dev.bus_id, up[0].port.mapbase, op->irqs[0],
1396 printk(KERN_INFO "%s: Mouse at MMIO %lx (irq = %d) " 1437 sunzilog_type (&up[0].port));
1397 "is a zs\n", 1438 printk(KERN_INFO "%s: Mouse at MMIO 0x%lx (irq = %d) "
1398 op->dev.bus_id, up[1].port.mapbase, op->irqs[0]); 1439 "is a %s\n",
1440 op->dev.bus_id, up[1].port.mapbase, op->irqs[0],
1441 sunzilog_type (&up[1].port));
1399 } 1442 }
1400 1443
1401 dev_set_drvdata(&op->dev, &up[0]); 1444 dev_set_drvdata(&op->dev, &up[0]);
@@ -1487,10 +1530,23 @@ static int __init sunzilog_init(void)
1487 goto out_unregister_uart; 1530 goto out_unregister_uart;
1488 1531
1489 if (zilog_irq != -1) { 1532 if (zilog_irq != -1) {
1533 struct uart_sunzilog_port *up = sunzilog_irq_chain;
1490 err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED, 1534 err = request_irq(zilog_irq, sunzilog_interrupt, IRQF_SHARED,
1491 "zs", sunzilog_irq_chain); 1535 "zs", sunzilog_irq_chain);
1492 if (err) 1536 if (err)
1493 goto out_unregister_driver; 1537 goto out_unregister_driver;
1538
1539 /* Enable Interrupts */
1540 while (up) {
1541 struct zilog_channel __iomem *channel;
1542
1543 /* printk (KERN_INFO "Enable IRQ for ZILOG Hardware %p\n", up); */
1544 channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
1545 up->flags |= SUNZILOG_FLAG_ISR_HANDLER;
1546 up->curregs[R9] |= MIE;
1547 write_zsreg(channel, R9, up->curregs[R9]);
1548 up = up->next;
1549 }
1494 } 1550 }
1495 1551
1496out: 1552out:
@@ -1515,6 +1571,20 @@ static void __exit sunzilog_exit(void)
1515 of_unregister_driver(&zs_driver); 1571 of_unregister_driver(&zs_driver);
1516 1572
1517 if (zilog_irq != -1) { 1573 if (zilog_irq != -1) {
1574 struct uart_sunzilog_port *up = sunzilog_irq_chain;
1575
1576 /* Disable Interrupts */
1577 while (up) {
1578 struct zilog_channel __iomem *channel;
1579
1580 /* printk (KERN_INFO "Disable IRQ for ZILOG Hardware %p\n", up); */
1581 channel = ZILOG_CHANNEL_FROM_PORT(&up->port);
1582 up->flags &= ~SUNZILOG_FLAG_ISR_HANDLER;
1583 up->curregs[R9] &= ~MIE;
1584 write_zsreg(channel, R9, up->curregs[R9]);
1585 up = up->next;
1586 }
1587
1518 free_irq(zilog_irq, sunzilog_irq_chain); 1588 free_irq(zilog_irq, sunzilog_irq_chain);
1519 zilog_irq = -1; 1589 zilog_irq = -1;
1520 } 1590 }
diff --git a/drivers/serial/sunzilog.h b/drivers/serial/sunzilog.h
index 7939b6d71270..5dec7b47cc38 100644
--- a/drivers/serial/sunzilog.h
+++ b/drivers/serial/sunzilog.h
@@ -13,7 +13,8 @@ struct zilog_layout {
13 struct zilog_channel channelA; 13 struct zilog_channel channelA;
14}; 14};
15 15
16#define NUM_ZSREGS 16 16#define NUM_ZSREGS 17
17#define R7p 16 /* Written as R7 with P15 bit 0 set */
17 18
18/* Conversion routines to/from brg time constants from/to bits 19/* Conversion routines to/from brg time constants from/to bits
19 * per second. 20 * per second.
@@ -127,6 +128,15 @@ struct zilog_layout {
127 128
128/* Write Register 7 (Sync bits 8-15/SDLC 01111110) */ 129/* Write Register 7 (Sync bits 8-15/SDLC 01111110) */
129 130
131/* Write Register 7' (ESCC Only) */
132#define AUTO_TxFLAG 1 /* Automatic Tx SDLC Flag */
133#define AUTO_EOM_RST 2 /* Automatic EOM Reset */
134#define AUTOnRTS 4 /* Automatic /RTS pin deactivation */
135#define RxFIFO_LVL 8 /* Receive FIFO interrupt level */
136#define nDTRnREQ 0x10 /* /DTR/REQ timing */
137#define TxFIFO_LVL 0x20 /* Transmit FIFO interrupt level */
138#define EXT_RD_EN 0x40 /* Extended read register enable */
139
130/* Write Register 8 (transmit buffer) */ 140/* Write Register 8 (transmit buffer) */
131 141
132/* Write Register 9 (Master interrupt control) */ 142/* Write Register 9 (Master interrupt control) */
@@ -135,6 +145,7 @@ struct zilog_layout {
135#define DLC 4 /* Disable Lower Chain */ 145#define DLC 4 /* Disable Lower Chain */
136#define MIE 8 /* Master Interrupt Enable */ 146#define MIE 8 /* Master Interrupt Enable */
137#define STATHI 0x10 /* Status high */ 147#define STATHI 0x10 /* Status high */
148#define SWIACK 0x20 /* Software Interrupt Ack (not on NMOS) */
138#define NORESET 0 /* No reset on write to R9 */ 149#define NORESET 0 /* No reset on write to R9 */
139#define CHRB 0x40 /* Reset channel B */ 150#define CHRB 0x40 /* Reset channel B */
140#define CHRA 0x80 /* Reset channel A */ 151#define CHRA 0x80 /* Reset channel A */
@@ -187,7 +198,9 @@ struct zilog_layout {
187#define SNRZI 0xe0 /* Set NRZI mode */ 198#define SNRZI 0xe0 /* Set NRZI mode */
188 199
189/* Write Register 15 (external/status interrupt control) */ 200/* Write Register 15 (external/status interrupt control) */
201#define WR7pEN 1 /* WR7' Enable (ESCC only) */
190#define ZCIE 2 /* Zero count IE */ 202#define ZCIE 2 /* Zero count IE */
203#define FIFOEN 4 /* FIFO Enable (ESCC only) */
191#define DCDIE 8 /* DCD IE */ 204#define DCDIE 8 /* DCD IE */
192#define SYNCIE 0x10 /* Sync/hunt IE */ 205#define SYNCIE 0x10 /* Sync/hunt IE */
193#define CTSIE 0x20 /* CTS IE */ 206#define CTSIE 0x20 /* CTS IE */
@@ -241,6 +254,10 @@ struct zilog_layout {
241#define CHATxIP 0x10 /* Channel A Tx IP */ 254#define CHATxIP 0x10 /* Channel A Tx IP */
242#define CHARxIP 0x20 /* Channel A Rx IP */ 255#define CHARxIP 0x20 /* Channel A Rx IP */
243 256
257/* Read Register 6 (LSB frame byte count [Not on NMOS]) */
258
259/* Read Register 7 (MSB frame byte count and FIFO status [Not on NMOS]) */
260
244/* Read Register 8 (receive data register) */ 261/* Read Register 8 (receive data register) */
245 262
246/* Read Register 10 (misc status bits) */ 263/* Read Register 10 (misc status bits) */
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index 4a012d9acbff..5e3f748f2693 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -6,6 +6,7 @@
6# fully appropriate there, so it'd need some thought to do well. 6# fully appropriate there, so it'd need some thought to do well.
7# 7#
8menu "SPI support" 8menu "SPI support"
9 depends on HAS_IOMEM
9 10
10config SPI 11config SPI
11 bool "SPI support" 12 bool "SPI support"
@@ -64,6 +65,17 @@ config SPI_BFIN
64 help 65 help
65 This is the SPI controller master driver for Blackfin 5xx processor. 66 This is the SPI controller master driver for Blackfin 5xx processor.
66 67
68config SPI_AU1550
69 tristate "Au1550/Au12x0 SPI Controller"
70 depends on SPI_MASTER && (SOC_AU1550 || SOC_AU1200) && EXPERIMENTAL
71 select SPI_BITBANG
72 help
73 If you say yes to this option, support will be included for the
74 Au1550 SPI controller (may also work with Au1200,Au1210,Au1250).
75
76 This driver can also be built as a module. If so, the module
77 will be called au1550_spi.
78
67config SPI_BITBANG 79config SPI_BITBANG
68 tristate "Bitbanging SPI master" 80 tristate "Bitbanging SPI master"
69 depends on SPI_MASTER && EXPERIMENTAL 81 depends on SPI_MASTER && EXPERIMENTAL
@@ -95,6 +107,13 @@ config SPI_IMX
95 This enables using the Freescale iMX SPI controller in master 107 This enables using the Freescale iMX SPI controller in master
96 mode. 108 mode.
97 109
110config SPI_MPC52xx_PSC
111 tristate "Freescale MPC52xx PSC SPI controller"
112 depends on SPI_MASTER && PPC_MPC52xx && EXPERIMENTAL
113 help
114 This enables using the Freescale MPC52xx Programmable Serial
115 Controller in master SPI mode.
116
98config SPI_MPC83xx 117config SPI_MPC83xx
99 tristate "Freescale MPC83xx SPI controller" 118 tristate "Freescale MPC83xx SPI controller"
100 depends on SPI_MASTER && PPC_83xx && EXPERIMENTAL 119 depends on SPI_MASTER && PPC_83xx && EXPERIMENTAL
@@ -159,6 +178,15 @@ config SPI_AT25
159 This driver can also be built as a module. If so, the module 178 This driver can also be built as a module. If so, the module
160 will be called at25. 179 will be called at25.
161 180
181config SPI_SPIDEV
182 tristate "User mode SPI device driver support"
183 depends on SPI_MASTER && EXPERIMENTAL
184 help
185 This supports user mode SPI protocol drivers.
186
187 Note that this application programming interface is EXPERIMENTAL
188 and hence SUBJECT TO CHANGE WITHOUT NOTICE while it stabilizes.
189
162# 190#
163# Add new SPI protocol masters in alphabetical order above this line 191# Add new SPI protocol masters in alphabetical order above this line
164# 192#
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index a95ade857a2f..5788d867de84 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -14,10 +14,12 @@ obj-$(CONFIG_SPI_MASTER) += spi.o
14obj-$(CONFIG_SPI_ATMEL) += atmel_spi.o 14obj-$(CONFIG_SPI_ATMEL) += atmel_spi.o
15obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.o 15obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.o
16obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o 16obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
17obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
17obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o 18obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
18obj-$(CONFIG_SPI_IMX) += spi_imx.o 19obj-$(CONFIG_SPI_IMX) += spi_imx.o
19obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o 20obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
20obj-$(CONFIG_SPI_OMAP_UWIRE) += omap_uwire.o 21obj-$(CONFIG_SPI_OMAP_UWIRE) += omap_uwire.o
22obj-$(CONFIG_SPI_MPC52xx_PSC) += mpc52xx_psc_spi.o
21obj-$(CONFIG_SPI_MPC83xx) += spi_mpc83xx.o 23obj-$(CONFIG_SPI_MPC83xx) += spi_mpc83xx.o
22obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o 24obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
23obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o 25obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o
@@ -25,6 +27,7 @@ obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o
25 27
26# SPI protocol drivers (device/link on bus) 28# SPI protocol drivers (device/link on bus)
27obj-$(CONFIG_SPI_AT25) += at25.o 29obj-$(CONFIG_SPI_AT25) += at25.o
30obj-$(CONFIG_SPI_SPIDEV) += spidev.o
28# ... add above this line ... 31# ... add above this line ...
29 32
30# SPI slave controller drivers (upstream link) 33# SPI slave controller drivers (upstream link)
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 66e7bc985797..1d8a2f6bb8eb 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -22,10 +22,7 @@
22#include <asm/io.h> 22#include <asm/io.h>
23#include <asm/arch/board.h> 23#include <asm/arch/board.h>
24#include <asm/arch/gpio.h> 24#include <asm/arch/gpio.h>
25
26#ifdef CONFIG_ARCH_AT91
27#include <asm/arch/cpu.h> 25#include <asm/arch/cpu.h>
28#endif
29 26
30#include "atmel_spi.h" 27#include "atmel_spi.h"
31 28
@@ -552,10 +549,8 @@ static int __init atmel_spi_probe(struct platform_device *pdev)
552 goto out_free_buffer; 549 goto out_free_buffer;
553 as->irq = irq; 550 as->irq = irq;
554 as->clk = clk; 551 as->clk = clk;
555#ifdef CONFIG_ARCH_AT91
556 if (!cpu_is_at91rm9200()) 552 if (!cpu_is_at91rm9200())
557 as->new_1 = 1; 553 as->new_1 = 1;
558#endif
559 554
560 ret = request_irq(irq, atmel_spi_interrupt, 0, 555 ret = request_irq(irq, atmel_spi_interrupt, 0,
561 pdev->dev.bus_id, master); 556 pdev->dev.bus_id, master);
diff --git a/drivers/spi/au1550_spi.c b/drivers/spi/au1550_spi.c
new file mode 100644
index 000000000000..ae2b1af0dba4
--- /dev/null
+++ b/drivers/spi/au1550_spi.c
@@ -0,0 +1,974 @@
1/*
2 * au1550_spi.c - au1550 psc spi controller driver
3 * may work also with au1200, au1210, au1250
4 * will not work on au1000, au1100 and au1500 (no full spi controller there)
5 *
6 * Copyright (c) 2006 ATRON electronic GmbH
7 * Author: Jan Nikitenko <jan.nikitenko@gmail.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 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include <linux/init.h>
25#include <linux/interrupt.h>
26#include <linux/errno.h>
27#include <linux/device.h>
28#include <linux/platform_device.h>
29#include <linux/spi/spi.h>
30#include <linux/spi/spi_bitbang.h>
31#include <linux/dma-mapping.h>
32#include <linux/completion.h>
33#include <asm/mach-au1x00/au1000.h>
34#include <asm/mach-au1x00/au1xxx_psc.h>
35#include <asm/mach-au1x00/au1xxx_dbdma.h>
36
37#include <asm/mach-au1x00/au1550_spi.h>
38
39static unsigned usedma = 1;
40module_param(usedma, uint, 0644);
41
42/*
43#define AU1550_SPI_DEBUG_LOOPBACK
44*/
45
46
47#define AU1550_SPI_DBDMA_DESCRIPTORS 1
48#define AU1550_SPI_DMA_RXTMP_MINSIZE 2048U
49
50struct au1550_spi {
51 struct spi_bitbang bitbang;
52
53 volatile psc_spi_t __iomem *regs;
54 int irq;
55 unsigned freq_max;
56 unsigned freq_min;
57
58 unsigned len;
59 unsigned tx_count;
60 unsigned rx_count;
61 const u8 *tx;
62 u8 *rx;
63
64 void (*rx_word)(struct au1550_spi *hw);
65 void (*tx_word)(struct au1550_spi *hw);
66 int (*txrx_bufs)(struct spi_device *spi, struct spi_transfer *t);
67 irqreturn_t (*irq_callback)(struct au1550_spi *hw);
68
69 struct completion master_done;
70
71 unsigned usedma;
72 u32 dma_tx_id;
73 u32 dma_rx_id;
74 u32 dma_tx_ch;
75 u32 dma_rx_ch;
76
77 u8 *dma_rx_tmpbuf;
78 unsigned dma_rx_tmpbuf_size;
79 u32 dma_rx_tmpbuf_addr;
80
81 struct spi_master *master;
82 struct device *dev;
83 struct au1550_spi_info *pdata;
84};
85
86
87/* we use an 8-bit memory device for dma transfers to/from spi fifo */
88static dbdev_tab_t au1550_spi_mem_dbdev =
89{
90 .dev_id = DBDMA_MEM_CHAN,
91 .dev_flags = DEV_FLAGS_ANYUSE|DEV_FLAGS_SYNC,
92 .dev_tsize = 0,
93 .dev_devwidth = 8,
94 .dev_physaddr = 0x00000000,
95 .dev_intlevel = 0,
96 .dev_intpolarity = 0
97};
98
99static void au1550_spi_bits_handlers_set(struct au1550_spi *hw, int bpw);
100
101
102/**
103 * compute BRG and DIV bits to setup spi clock based on main input clock rate
104 * that was specified in platform data structure
105 * according to au1550 datasheet:
106 * psc_tempclk = psc_mainclk / (2 << DIV)
107 * spiclk = psc_tempclk / (2 * (BRG + 1))
108 * BRG valid range is 4..63
109 * DIV valid range is 0..3
110 */
111static u32 au1550_spi_baudcfg(struct au1550_spi *hw, unsigned speed_hz)
112{
113 u32 mainclk_hz = hw->pdata->mainclk_hz;
114 u32 div, brg;
115
116 for (div = 0; div < 4; div++) {
117 brg = mainclk_hz / speed_hz / (4 << div);
118 /* now we have BRG+1 in brg, so count with that */
119 if (brg < (4 + 1)) {
120 brg = (4 + 1); /* speed_hz too big */
121 break; /* set lowest brg (div is == 0) */
122 }
123 if (brg <= (63 + 1))
124 break; /* we have valid brg and div */
125 }
126 if (div == 4) {
127 div = 3; /* speed_hz too small */
128 brg = (63 + 1); /* set highest brg and div */
129 }
130 brg--;
131 return PSC_SPICFG_SET_BAUD(brg) | PSC_SPICFG_SET_DIV(div);
132}
133
134static inline void au1550_spi_mask_ack_all(struct au1550_spi *hw)
135{
136 hw->regs->psc_spimsk =
137 PSC_SPIMSK_MM | PSC_SPIMSK_RR | PSC_SPIMSK_RO
138 | PSC_SPIMSK_RU | PSC_SPIMSK_TR | PSC_SPIMSK_TO
139 | PSC_SPIMSK_TU | PSC_SPIMSK_SD | PSC_SPIMSK_MD;
140 au_sync();
141
142 hw->regs->psc_spievent =
143 PSC_SPIEVNT_MM | PSC_SPIEVNT_RR | PSC_SPIEVNT_RO
144 | PSC_SPIEVNT_RU | PSC_SPIEVNT_TR | PSC_SPIEVNT_TO
145 | PSC_SPIEVNT_TU | PSC_SPIEVNT_SD | PSC_SPIEVNT_MD;
146 au_sync();
147}
148
149static void au1550_spi_reset_fifos(struct au1550_spi *hw)
150{
151 u32 pcr;
152
153 hw->regs->psc_spipcr = PSC_SPIPCR_RC | PSC_SPIPCR_TC;
154 au_sync();
155 do {
156 pcr = hw->regs->psc_spipcr;
157 au_sync();
158 } while (pcr != 0);
159}
160
161/*
162 * dma transfers are used for the most common spi word size of 8-bits
163 * we cannot easily change already set up dma channels' width, so if we wanted
164 * dma support for more than 8-bit words (up to 24 bits), we would need to
165 * setup dma channels from scratch on each spi transfer, based on bits_per_word
166 * instead we have pre set up 8 bit dma channels supporting spi 4 to 8 bits
167 * transfers, and 9 to 24 bits spi transfers will be done in pio irq based mode
168 * callbacks to handle dma or pio are set up in au1550_spi_bits_handlers_set()
169 */
170static void au1550_spi_chipsel(struct spi_device *spi, int value)
171{
172 struct au1550_spi *hw = spi_master_get_devdata(spi->master);
173 unsigned cspol = spi->mode & SPI_CS_HIGH ? 1 : 0;
174 u32 cfg, stat;
175
176 switch (value) {
177 case BITBANG_CS_INACTIVE:
178 if (hw->pdata->deactivate_cs)
179 hw->pdata->deactivate_cs(hw->pdata, spi->chip_select,
180 cspol);
181 break;
182
183 case BITBANG_CS_ACTIVE:
184 au1550_spi_bits_handlers_set(hw, spi->bits_per_word);
185
186 cfg = hw->regs->psc_spicfg;
187 au_sync();
188 hw->regs->psc_spicfg = cfg & ~PSC_SPICFG_DE_ENABLE;
189 au_sync();
190
191 if (spi->mode & SPI_CPOL)
192 cfg |= PSC_SPICFG_BI;
193 else
194 cfg &= ~PSC_SPICFG_BI;
195 if (spi->mode & SPI_CPHA)
196 cfg &= ~PSC_SPICFG_CDE;
197 else
198 cfg |= PSC_SPICFG_CDE;
199
200 if (spi->mode & SPI_LSB_FIRST)
201 cfg |= PSC_SPICFG_MLF;
202 else
203 cfg &= ~PSC_SPICFG_MLF;
204
205 if (hw->usedma && spi->bits_per_word <= 8)
206 cfg &= ~PSC_SPICFG_DD_DISABLE;
207 else
208 cfg |= PSC_SPICFG_DD_DISABLE;
209 cfg = PSC_SPICFG_CLR_LEN(cfg);
210 cfg |= PSC_SPICFG_SET_LEN(spi->bits_per_word);
211
212 cfg = PSC_SPICFG_CLR_BAUD(cfg);
213 cfg &= ~PSC_SPICFG_SET_DIV(3);
214 cfg |= au1550_spi_baudcfg(hw, spi->max_speed_hz);
215
216 hw->regs->psc_spicfg = cfg | PSC_SPICFG_DE_ENABLE;
217 au_sync();
218 do {
219 stat = hw->regs->psc_spistat;
220 au_sync();
221 } while ((stat & PSC_SPISTAT_DR) == 0);
222
223 if (hw->pdata->activate_cs)
224 hw->pdata->activate_cs(hw->pdata, spi->chip_select,
225 cspol);
226 break;
227 }
228}
229
230static int au1550_spi_setupxfer(struct spi_device *spi, struct spi_transfer *t)
231{
232 struct au1550_spi *hw = spi_master_get_devdata(spi->master);
233 unsigned bpw, hz;
234 u32 cfg, stat;
235
236 bpw = t ? t->bits_per_word : spi->bits_per_word;
237 hz = t ? t->speed_hz : spi->max_speed_hz;
238
239 if (bpw < 4 || bpw > 24) {
240 dev_err(&spi->dev, "setupxfer: invalid bits_per_word=%d\n",
241 bpw);
242 return -EINVAL;
243 }
244 if (hz > spi->max_speed_hz || hz > hw->freq_max || hz < hw->freq_min) {
245 dev_err(&spi->dev, "setupxfer: clock rate=%d out of range\n",
246 hz);
247 return -EINVAL;
248 }
249
250 au1550_spi_bits_handlers_set(hw, spi->bits_per_word);
251
252 cfg = hw->regs->psc_spicfg;
253 au_sync();
254 hw->regs->psc_spicfg = cfg & ~PSC_SPICFG_DE_ENABLE;
255 au_sync();
256
257 if (hw->usedma && bpw <= 8)
258 cfg &= ~PSC_SPICFG_DD_DISABLE;
259 else
260 cfg |= PSC_SPICFG_DD_DISABLE;
261 cfg = PSC_SPICFG_CLR_LEN(cfg);
262 cfg |= PSC_SPICFG_SET_LEN(bpw);
263
264 cfg = PSC_SPICFG_CLR_BAUD(cfg);
265 cfg &= ~PSC_SPICFG_SET_DIV(3);
266 cfg |= au1550_spi_baudcfg(hw, hz);
267
268 hw->regs->psc_spicfg = cfg;
269 au_sync();
270
271 if (cfg & PSC_SPICFG_DE_ENABLE) {
272 do {
273 stat = hw->regs->psc_spistat;
274 au_sync();
275 } while ((stat & PSC_SPISTAT_DR) == 0);
276 }
277
278 au1550_spi_reset_fifos(hw);
279 au1550_spi_mask_ack_all(hw);
280 return 0;
281}
282
283static int au1550_spi_setup(struct spi_device *spi)
284{
285 struct au1550_spi *hw = spi_master_get_devdata(spi->master);
286
287 if (spi->bits_per_word == 0)
288 spi->bits_per_word = 8;
289 if (spi->bits_per_word < 4 || spi->bits_per_word > 24) {
290 dev_err(&spi->dev, "setup: invalid bits_per_word=%d\n",
291 spi->bits_per_word);
292 return -EINVAL;
293 }
294
295 if (spi->max_speed_hz == 0)
296 spi->max_speed_hz = hw->freq_max;
297 if (spi->max_speed_hz > hw->freq_max
298 || spi->max_speed_hz < hw->freq_min)
299 return -EINVAL;
300 /*
301 * NOTE: cannot change speed and other hw settings immediately,
302 * otherwise sharing of spi bus is not possible,
303 * so do not call setupxfer(spi, NULL) here
304 */
305 return 0;
306}
307
308/*
309 * for dma spi transfers, we have to setup rx channel, otherwise there is
310 * no reliable way how to recognize that spi transfer is done
311 * dma complete callbacks are called before real spi transfer is finished
312 * and if only tx dma channel is set up (and rx fifo overflow event masked)
313 * spi master done event irq is not generated unless rx fifo is empty (emptied)
314 * so we need rx tmp buffer to use for rx dma if user does not provide one
315 */
316static int au1550_spi_dma_rxtmp_alloc(struct au1550_spi *hw, unsigned size)
317{
318 hw->dma_rx_tmpbuf = kmalloc(size, GFP_KERNEL);
319 if (!hw->dma_rx_tmpbuf)
320 return -ENOMEM;
321 hw->dma_rx_tmpbuf_size = size;
322 hw->dma_rx_tmpbuf_addr = dma_map_single(hw->dev, hw->dma_rx_tmpbuf,
323 size, DMA_FROM_DEVICE);
324 if (dma_mapping_error(hw->dma_rx_tmpbuf_addr)) {
325 kfree(hw->dma_rx_tmpbuf);
326 hw->dma_rx_tmpbuf = 0;
327 hw->dma_rx_tmpbuf_size = 0;
328 return -EFAULT;
329 }
330 return 0;
331}
332
333static void au1550_spi_dma_rxtmp_free(struct au1550_spi *hw)
334{
335 dma_unmap_single(hw->dev, hw->dma_rx_tmpbuf_addr,
336 hw->dma_rx_tmpbuf_size, DMA_FROM_DEVICE);
337 kfree(hw->dma_rx_tmpbuf);
338 hw->dma_rx_tmpbuf = 0;
339 hw->dma_rx_tmpbuf_size = 0;
340}
341
342static int au1550_spi_dma_txrxb(struct spi_device *spi, struct spi_transfer *t)
343{
344 struct au1550_spi *hw = spi_master_get_devdata(spi->master);
345 dma_addr_t dma_tx_addr;
346 dma_addr_t dma_rx_addr;
347 u32 res;
348
349 hw->len = t->len;
350 hw->tx_count = 0;
351 hw->rx_count = 0;
352
353 hw->tx = t->tx_buf;
354 hw->rx = t->rx_buf;
355 dma_tx_addr = t->tx_dma;
356 dma_rx_addr = t->rx_dma;
357
358 /*
359 * check if buffers are already dma mapped, map them otherwise
360 * use rx buffer in place of tx if tx buffer was not provided
361 * use temp rx buffer (preallocated or realloc to fit) for rx dma
362 */
363 if (t->rx_buf) {
364 if (t->rx_dma == 0) { /* if DMA_ADDR_INVALID, map it */
365 dma_rx_addr = dma_map_single(hw->dev,
366 (void *)t->rx_buf,
367 t->len, DMA_FROM_DEVICE);
368 if (dma_mapping_error(dma_rx_addr))
369 dev_err(hw->dev, "rx dma map error\n");
370 }
371 } else {
372 if (t->len > hw->dma_rx_tmpbuf_size) {
373 int ret;
374
375 au1550_spi_dma_rxtmp_free(hw);
376 ret = au1550_spi_dma_rxtmp_alloc(hw, max(t->len,
377 AU1550_SPI_DMA_RXTMP_MINSIZE));
378 if (ret < 0)
379 return ret;
380 }
381 hw->rx = hw->dma_rx_tmpbuf;
382 dma_rx_addr = hw->dma_rx_tmpbuf_addr;
383 dma_sync_single_for_device(hw->dev, dma_rx_addr,
384 t->len, DMA_FROM_DEVICE);
385 }
386 if (t->tx_buf) {
387 if (t->tx_dma == 0) { /* if DMA_ADDR_INVALID, map it */
388 dma_tx_addr = dma_map_single(hw->dev,
389 (void *)t->tx_buf,
390 t->len, DMA_TO_DEVICE);
391 if (dma_mapping_error(dma_tx_addr))
392 dev_err(hw->dev, "tx dma map error\n");
393 }
394 } else {
395 dma_sync_single_for_device(hw->dev, dma_rx_addr,
396 t->len, DMA_BIDIRECTIONAL);
397 hw->tx = hw->rx;
398 }
399
400 /* put buffers on the ring */
401 res = au1xxx_dbdma_put_dest(hw->dma_rx_ch, hw->rx, t->len);
402 if (!res)
403 dev_err(hw->dev, "rx dma put dest error\n");
404
405 res = au1xxx_dbdma_put_source(hw->dma_tx_ch, (void *)hw->tx, t->len);
406 if (!res)
407 dev_err(hw->dev, "tx dma put source error\n");
408
409 au1xxx_dbdma_start(hw->dma_rx_ch);
410 au1xxx_dbdma_start(hw->dma_tx_ch);
411
412 /* by default enable nearly all events interrupt */
413 hw->regs->psc_spimsk = PSC_SPIMSK_SD;
414 au_sync();
415
416 /* start the transfer */
417 hw->regs->psc_spipcr = PSC_SPIPCR_MS;
418 au_sync();
419
420 wait_for_completion(&hw->master_done);
421
422 au1xxx_dbdma_stop(hw->dma_tx_ch);
423 au1xxx_dbdma_stop(hw->dma_rx_ch);
424
425 if (!t->rx_buf) {
426 /* using the temporal preallocated and premapped buffer */
427 dma_sync_single_for_cpu(hw->dev, dma_rx_addr, t->len,
428 DMA_FROM_DEVICE);
429 }
430 /* unmap buffers if mapped above */
431 if (t->rx_buf && t->rx_dma == 0 )
432 dma_unmap_single(hw->dev, dma_rx_addr, t->len,
433 DMA_FROM_DEVICE);
434 if (t->tx_buf && t->tx_dma == 0 )
435 dma_unmap_single(hw->dev, dma_tx_addr, t->len,
436 DMA_TO_DEVICE);
437
438 return hw->rx_count < hw->tx_count ? hw->rx_count : hw->tx_count;
439}
440
441static irqreturn_t au1550_spi_dma_irq_callback(struct au1550_spi *hw)
442{
443 u32 stat, evnt;
444
445 stat = hw->regs->psc_spistat;
446 evnt = hw->regs->psc_spievent;
447 au_sync();
448 if ((stat & PSC_SPISTAT_DI) == 0) {
449 dev_err(hw->dev, "Unexpected IRQ!\n");
450 return IRQ_NONE;
451 }
452
453 if ((evnt & (PSC_SPIEVNT_MM | PSC_SPIEVNT_RO
454 | PSC_SPIEVNT_RU | PSC_SPIEVNT_TO
455 | PSC_SPIEVNT_TU | PSC_SPIEVNT_SD))
456 != 0) {
457 /*
458 * due to an spi error we consider transfer as done,
459 * so mask all events until before next transfer start
460 * and stop the possibly running dma immediatelly
461 */
462 au1550_spi_mask_ack_all(hw);
463 au1xxx_dbdma_stop(hw->dma_rx_ch);
464 au1xxx_dbdma_stop(hw->dma_tx_ch);
465
466 /* get number of transfered bytes */
467 hw->rx_count = hw->len - au1xxx_get_dma_residue(hw->dma_rx_ch);
468 hw->tx_count = hw->len - au1xxx_get_dma_residue(hw->dma_tx_ch);
469
470 au1xxx_dbdma_reset(hw->dma_rx_ch);
471 au1xxx_dbdma_reset(hw->dma_tx_ch);
472 au1550_spi_reset_fifos(hw);
473
474 dev_err(hw->dev,
475 "Unexpected SPI error: event=0x%x stat=0x%x!\n",
476 evnt, stat);
477
478 complete(&hw->master_done);
479 return IRQ_HANDLED;
480 }
481
482 if ((evnt & PSC_SPIEVNT_MD) != 0) {
483 /* transfer completed successfully */
484 au1550_spi_mask_ack_all(hw);
485 hw->rx_count = hw->len;
486 hw->tx_count = hw->len;
487 complete(&hw->master_done);
488 }
489 return IRQ_HANDLED;
490}
491
492
493/* routines to handle different word sizes in pio mode */
494#define AU1550_SPI_RX_WORD(size, mask) \
495static void au1550_spi_rx_word_##size(struct au1550_spi *hw) \
496{ \
497 u32 fifoword = hw->regs->psc_spitxrx & (u32)(mask); \
498 au_sync(); \
499 if (hw->rx) { \
500 *(u##size *)hw->rx = (u##size)fifoword; \
501 hw->rx += (size) / 8; \
502 } \
503 hw->rx_count += (size) / 8; \
504}
505
506#define AU1550_SPI_TX_WORD(size, mask) \
507static void au1550_spi_tx_word_##size(struct au1550_spi *hw) \
508{ \
509 u32 fifoword = 0; \
510 if (hw->tx) { \
511 fifoword = *(u##size *)hw->tx & (u32)(mask); \
512 hw->tx += (size) / 8; \
513 } \
514 hw->tx_count += (size) / 8; \
515 if (hw->tx_count >= hw->len) \
516 fifoword |= PSC_SPITXRX_LC; \
517 hw->regs->psc_spitxrx = fifoword; \
518 au_sync(); \
519}
520
521AU1550_SPI_RX_WORD(8,0xff)
522AU1550_SPI_RX_WORD(16,0xffff)
523AU1550_SPI_RX_WORD(32,0xffffff)
524AU1550_SPI_TX_WORD(8,0xff)
525AU1550_SPI_TX_WORD(16,0xffff)
526AU1550_SPI_TX_WORD(32,0xffffff)
527
528static int au1550_spi_pio_txrxb(struct spi_device *spi, struct spi_transfer *t)
529{
530 u32 stat, mask;
531 struct au1550_spi *hw = spi_master_get_devdata(spi->master);
532
533 hw->tx = t->tx_buf;
534 hw->rx = t->rx_buf;
535 hw->len = t->len;
536 hw->tx_count = 0;
537 hw->rx_count = 0;
538
539 /* by default enable nearly all events after filling tx fifo */
540 mask = PSC_SPIMSK_SD;
541
542 /* fill the transmit FIFO */
543 while (hw->tx_count < hw->len) {
544
545 hw->tx_word(hw);
546
547 if (hw->tx_count >= hw->len) {
548 /* mask tx fifo request interrupt as we are done */
549 mask |= PSC_SPIMSK_TR;
550 }
551
552 stat = hw->regs->psc_spistat;
553 au_sync();
554 if (stat & PSC_SPISTAT_TF)
555 break;
556 }
557
558 /* enable event interrupts */
559 hw->regs->psc_spimsk = mask;
560 au_sync();
561
562 /* start the transfer */
563 hw->regs->psc_spipcr = PSC_SPIPCR_MS;
564 au_sync();
565
566 wait_for_completion(&hw->master_done);
567
568 return hw->rx_count < hw->tx_count ? hw->rx_count : hw->tx_count;
569}
570
571static irqreturn_t au1550_spi_pio_irq_callback(struct au1550_spi *hw)
572{
573 int busy;
574 u32 stat, evnt;
575
576 stat = hw->regs->psc_spistat;
577 evnt = hw->regs->psc_spievent;
578 au_sync();
579 if ((stat & PSC_SPISTAT_DI) == 0) {
580 dev_err(hw->dev, "Unexpected IRQ!\n");
581 return IRQ_NONE;
582 }
583
584 if ((evnt & (PSC_SPIEVNT_MM | PSC_SPIEVNT_RO
585 | PSC_SPIEVNT_RU | PSC_SPIEVNT_TO
586 | PSC_SPIEVNT_TU | PSC_SPIEVNT_SD))
587 != 0) {
588 dev_err(hw->dev,
589 "Unexpected SPI error: event=0x%x stat=0x%x!\n",
590 evnt, stat);
591 /*
592 * due to an error we consider transfer as done,
593 * so mask all events until before next transfer start
594 */
595 au1550_spi_mask_ack_all(hw);
596 au1550_spi_reset_fifos(hw);
597 complete(&hw->master_done);
598 return IRQ_HANDLED;
599 }
600
601 /*
602 * while there is something to read from rx fifo
603 * or there is a space to write to tx fifo:
604 */
605 do {
606 busy = 0;
607 stat = hw->regs->psc_spistat;
608 au_sync();
609
610 if ((stat & PSC_SPISTAT_RE) == 0 && hw->rx_count < hw->len) {
611 hw->rx_word(hw);
612 /* ack the receive request event */
613 hw->regs->psc_spievent = PSC_SPIEVNT_RR;
614 au_sync();
615 busy = 1;
616 }
617
618 if ((stat & PSC_SPISTAT_TF) == 0 && hw->tx_count < hw->len) {
619 hw->tx_word(hw);
620 /* ack the transmit request event */
621 hw->regs->psc_spievent = PSC_SPIEVNT_TR;
622 au_sync();
623 busy = 1;
624 }
625 } while (busy);
626
627 evnt = hw->regs->psc_spievent;
628 au_sync();
629
630 if (hw->rx_count >= hw->len || (evnt & PSC_SPIEVNT_MD) != 0) {
631 /* transfer completed successfully */
632 au1550_spi_mask_ack_all(hw);
633 complete(&hw->master_done);
634 }
635 return IRQ_HANDLED;
636}
637
638static int au1550_spi_txrx_bufs(struct spi_device *spi, struct spi_transfer *t)
639{
640 struct au1550_spi *hw = spi_master_get_devdata(spi->master);
641 return hw->txrx_bufs(spi, t);
642}
643
644static irqreturn_t au1550_spi_irq(int irq, void *dev, struct pt_regs *regs)
645{
646 struct au1550_spi *hw = dev;
647 return hw->irq_callback(hw);
648}
649
650static void au1550_spi_bits_handlers_set(struct au1550_spi *hw, int bpw)
651{
652 if (bpw <= 8) {
653 if (hw->usedma) {
654 hw->txrx_bufs = &au1550_spi_dma_txrxb;
655 hw->irq_callback = &au1550_spi_dma_irq_callback;
656 } else {
657 hw->rx_word = &au1550_spi_rx_word_8;
658 hw->tx_word = &au1550_spi_tx_word_8;
659 hw->txrx_bufs = &au1550_spi_pio_txrxb;
660 hw->irq_callback = &au1550_spi_pio_irq_callback;
661 }
662 } else if (bpw <= 16) {
663 hw->rx_word = &au1550_spi_rx_word_16;
664 hw->tx_word = &au1550_spi_tx_word_16;
665 hw->txrx_bufs = &au1550_spi_pio_txrxb;
666 hw->irq_callback = &au1550_spi_pio_irq_callback;
667 } else {
668 hw->rx_word = &au1550_spi_rx_word_32;
669 hw->tx_word = &au1550_spi_tx_word_32;
670 hw->txrx_bufs = &au1550_spi_pio_txrxb;
671 hw->irq_callback = &au1550_spi_pio_irq_callback;
672 }
673}
674
675static void __init au1550_spi_setup_psc_as_spi(struct au1550_spi *hw)
676{
677 u32 stat, cfg;
678
679 /* set up the PSC for SPI mode */
680 hw->regs->psc_ctrl = PSC_CTRL_DISABLE;
681 au_sync();
682 hw->regs->psc_sel = PSC_SEL_PS_SPIMODE;
683 au_sync();
684
685 hw->regs->psc_spicfg = 0;
686 au_sync();
687
688 hw->regs->psc_ctrl = PSC_CTRL_ENABLE;
689 au_sync();
690
691 do {
692 stat = hw->regs->psc_spistat;
693 au_sync();
694 } while ((stat & PSC_SPISTAT_SR) == 0);
695
696
697 cfg = hw->usedma ? 0 : PSC_SPICFG_DD_DISABLE;
698 cfg |= PSC_SPICFG_SET_LEN(8);
699 cfg |= PSC_SPICFG_RT_FIFO8 | PSC_SPICFG_TT_FIFO8;
700 /* use minimal allowed brg and div values as initial setting: */
701 cfg |= PSC_SPICFG_SET_BAUD(4) | PSC_SPICFG_SET_DIV(0);
702
703#ifdef AU1550_SPI_DEBUG_LOOPBACK
704 cfg |= PSC_SPICFG_LB;
705#endif
706
707 hw->regs->psc_spicfg = cfg;
708 au_sync();
709
710 au1550_spi_mask_ack_all(hw);
711
712 hw->regs->psc_spicfg |= PSC_SPICFG_DE_ENABLE;
713 au_sync();
714
715 do {
716 stat = hw->regs->psc_spistat;
717 au_sync();
718 } while ((stat & PSC_SPISTAT_DR) == 0);
719}
720
721
722static int __init au1550_spi_probe(struct platform_device *pdev)
723{
724 struct au1550_spi *hw;
725 struct spi_master *master;
726 int err = 0;
727
728 master = spi_alloc_master(&pdev->dev, sizeof(struct au1550_spi));
729 if (master == NULL) {
730 dev_err(&pdev->dev, "No memory for spi_master\n");
731 err = -ENOMEM;
732 goto err_nomem;
733 }
734
735 hw = spi_master_get_devdata(master);
736
737 hw->master = spi_master_get(master);
738 hw->pdata = pdev->dev.platform_data;
739 hw->dev = &pdev->dev;
740
741 if (hw->pdata == NULL) {
742 dev_err(&pdev->dev, "No platform data supplied\n");
743 err = -ENOENT;
744 goto err_no_pdata;
745 }
746
747 platform_set_drvdata(pdev, hw);
748
749 init_completion(&hw->master_done);
750
751 hw->bitbang.master = hw->master;
752 hw->bitbang.setup_transfer = au1550_spi_setupxfer;
753 hw->bitbang.chipselect = au1550_spi_chipsel;
754 hw->bitbang.master->setup = au1550_spi_setup;
755 hw->bitbang.txrx_bufs = au1550_spi_txrx_bufs;
756
757 switch (hw->pdata->bus_num) {
758 case 0:
759 hw->irq = AU1550_PSC0_INT;
760 hw->regs = (volatile psc_spi_t *)PSC0_BASE_ADDR;
761 hw->dma_rx_id = DSCR_CMD0_PSC0_RX;
762 hw->dma_tx_id = DSCR_CMD0_PSC0_TX;
763 break;
764 case 1:
765 hw->irq = AU1550_PSC1_INT;
766 hw->regs = (volatile psc_spi_t *)PSC1_BASE_ADDR;
767 hw->dma_rx_id = DSCR_CMD0_PSC1_RX;
768 hw->dma_tx_id = DSCR_CMD0_PSC1_TX;
769 break;
770 case 2:
771 hw->irq = AU1550_PSC2_INT;
772 hw->regs = (volatile psc_spi_t *)PSC2_BASE_ADDR;
773 hw->dma_rx_id = DSCR_CMD0_PSC2_RX;
774 hw->dma_tx_id = DSCR_CMD0_PSC2_TX;
775 break;
776 case 3:
777 hw->irq = AU1550_PSC3_INT;
778 hw->regs = (volatile psc_spi_t *)PSC3_BASE_ADDR;
779 hw->dma_rx_id = DSCR_CMD0_PSC3_RX;
780 hw->dma_tx_id = DSCR_CMD0_PSC3_TX;
781 break;
782 default:
783 dev_err(&pdev->dev, "Wrong bus_num of SPI\n");
784 err = -ENOENT;
785 goto err_no_pdata;
786 }
787
788 if (request_mem_region((unsigned long)hw->regs, sizeof(psc_spi_t),
789 pdev->name) == NULL) {
790 dev_err(&pdev->dev, "Cannot reserve iomem region\n");
791 err = -ENXIO;
792 goto err_no_iores;
793 }
794
795
796 if (usedma) {
797 if (pdev->dev.dma_mask == NULL)
798 dev_warn(&pdev->dev, "no dma mask\n");
799 else
800 hw->usedma = 1;
801 }
802
803 if (hw->usedma) {
804 /*
805 * create memory device with 8 bits dev_devwidth
806 * needed for proper byte ordering to spi fifo
807 */
808 int memid = au1xxx_ddma_add_device(&au1550_spi_mem_dbdev);
809 if (!memid) {
810 dev_err(&pdev->dev,
811 "Cannot create dma 8 bit mem device\n");
812 err = -ENXIO;
813 goto err_dma_add_dev;
814 }
815
816 hw->dma_tx_ch = au1xxx_dbdma_chan_alloc(memid,
817 hw->dma_tx_id, NULL, (void *)hw);
818 if (hw->dma_tx_ch == 0) {
819 dev_err(&pdev->dev,
820 "Cannot allocate tx dma channel\n");
821 err = -ENXIO;
822 goto err_no_txdma;
823 }
824 au1xxx_dbdma_set_devwidth(hw->dma_tx_ch, 8);
825 if (au1xxx_dbdma_ring_alloc(hw->dma_tx_ch,
826 AU1550_SPI_DBDMA_DESCRIPTORS) == 0) {
827 dev_err(&pdev->dev,
828 "Cannot allocate tx dma descriptors\n");
829 err = -ENXIO;
830 goto err_no_txdma_descr;
831 }
832
833
834 hw->dma_rx_ch = au1xxx_dbdma_chan_alloc(hw->dma_rx_id,
835 memid, NULL, (void *)hw);
836 if (hw->dma_rx_ch == 0) {
837 dev_err(&pdev->dev,
838 "Cannot allocate rx dma channel\n");
839 err = -ENXIO;
840 goto err_no_rxdma;
841 }
842 au1xxx_dbdma_set_devwidth(hw->dma_rx_ch, 8);
843 if (au1xxx_dbdma_ring_alloc(hw->dma_rx_ch,
844 AU1550_SPI_DBDMA_DESCRIPTORS) == 0) {
845 dev_err(&pdev->dev,
846 "Cannot allocate rx dma descriptors\n");
847 err = -ENXIO;
848 goto err_no_rxdma_descr;
849 }
850
851 err = au1550_spi_dma_rxtmp_alloc(hw,
852 AU1550_SPI_DMA_RXTMP_MINSIZE);
853 if (err < 0) {
854 dev_err(&pdev->dev,
855 "Cannot allocate initial rx dma tmp buffer\n");
856 goto err_dma_rxtmp_alloc;
857 }
858 }
859
860 au1550_spi_bits_handlers_set(hw, 8);
861
862 err = request_irq(hw->irq, au1550_spi_irq, 0, pdev->name, hw);
863 if (err) {
864 dev_err(&pdev->dev, "Cannot claim IRQ\n");
865 goto err_no_irq;
866 }
867
868 master->bus_num = hw->pdata->bus_num;
869 master->num_chipselect = hw->pdata->num_chipselect;
870
871 /*
872 * precompute valid range for spi freq - from au1550 datasheet:
873 * psc_tempclk = psc_mainclk / (2 << DIV)
874 * spiclk = psc_tempclk / (2 * (BRG + 1))
875 * BRG valid range is 4..63
876 * DIV valid range is 0..3
877 * round the min and max frequencies to values that would still
878 * produce valid brg and div
879 */
880 {
881 int min_div = (2 << 0) * (2 * (4 + 1));
882 int max_div = (2 << 3) * (2 * (63 + 1));
883 hw->freq_max = hw->pdata->mainclk_hz / min_div;
884 hw->freq_min = hw->pdata->mainclk_hz / (max_div + 1) + 1;
885 }
886
887 au1550_spi_setup_psc_as_spi(hw);
888
889 err = spi_bitbang_start(&hw->bitbang);
890 if (err) {
891 dev_err(&pdev->dev, "Failed to register SPI master\n");
892 goto err_register;
893 }
894
895 dev_info(&pdev->dev,
896 "spi master registered: bus_num=%d num_chipselect=%d\n",
897 master->bus_num, master->num_chipselect);
898
899 return 0;
900
901err_register:
902 free_irq(hw->irq, hw);
903
904err_no_irq:
905 au1550_spi_dma_rxtmp_free(hw);
906
907err_dma_rxtmp_alloc:
908err_no_rxdma_descr:
909 if (hw->usedma)
910 au1xxx_dbdma_chan_free(hw->dma_rx_ch);
911
912err_no_rxdma:
913err_no_txdma_descr:
914 if (hw->usedma)
915 au1xxx_dbdma_chan_free(hw->dma_tx_ch);
916
917err_no_txdma:
918err_dma_add_dev:
919 release_mem_region((unsigned long)hw->regs, sizeof(psc_spi_t));
920
921err_no_iores:
922err_no_pdata:
923 spi_master_put(hw->master);
924
925err_nomem:
926 return err;
927}
928
929static int __exit au1550_spi_remove(struct platform_device *pdev)
930{
931 struct au1550_spi *hw = platform_get_drvdata(pdev);
932
933 dev_info(&pdev->dev, "spi master remove: bus_num=%d\n",
934 hw->master->bus_num);
935
936 spi_bitbang_stop(&hw->bitbang);
937 free_irq(hw->irq, hw);
938 release_mem_region((unsigned long)hw->regs, sizeof(psc_spi_t));
939
940 if (hw->usedma) {
941 au1550_spi_dma_rxtmp_free(hw);
942 au1xxx_dbdma_chan_free(hw->dma_rx_ch);
943 au1xxx_dbdma_chan_free(hw->dma_tx_ch);
944 }
945
946 platform_set_drvdata(pdev, NULL);
947
948 spi_master_put(hw->master);
949 return 0;
950}
951
952static struct platform_driver au1550_spi_drv = {
953 .remove = __exit_p(au1550_spi_remove),
954 .driver = {
955 .name = "au1550-spi",
956 .owner = THIS_MODULE,
957 },
958};
959
960static int __init au1550_spi_init(void)
961{
962 return platform_driver_probe(&au1550_spi_drv, au1550_spi_probe);
963}
964module_init(au1550_spi_init);
965
966static void __exit au1550_spi_exit(void)
967{
968 platform_driver_unregister(&au1550_spi_drv);
969}
970module_exit(au1550_spi_exit);
971
972MODULE_DESCRIPTION("Au1550 PSC SPI Driver");
973MODULE_AUTHOR("Jan Nikitenko <jan.nikitenko@gmail.com>");
974MODULE_LICENSE("GPL");
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
new file mode 100644
index 000000000000..052359fc41ee
--- /dev/null
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -0,0 +1,654 @@
1/*
2 * MPC52xx SPC in SPI mode driver.
3 *
4 * Maintainer: Dragos Carp
5 *
6 * Copyright (C) 2006 TOPTICA Photonics AG.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/errno.h>
17#include <linux/interrupt.h>
18
19#if defined(CONFIG_PPC_MERGE)
20#include <asm/of_platform.h>
21#else
22#include <linux/platform_device.h>
23#endif
24
25#include <linux/workqueue.h>
26#include <linux/completion.h>
27#include <linux/io.h>
28#include <linux/delay.h>
29#include <linux/spi/spi.h>
30#include <linux/fsl_devices.h>
31
32#include <asm/mpc52xx.h>
33#include <asm/mpc52xx_psc.h>
34
35#define MCLK 20000000 /* PSC port MClk in hz */
36
37struct mpc52xx_psc_spi {
38 /* fsl_spi_platform data */
39 void (*activate_cs)(u8, u8);
40 void (*deactivate_cs)(u8, u8);
41 u32 sysclk;
42
43 /* driver internal data */
44 struct mpc52xx_psc __iomem *psc;
45 unsigned int irq;
46 u8 bits_per_word;
47 u8 busy;
48
49 struct workqueue_struct *workqueue;
50 struct work_struct work;
51
52 struct list_head queue;
53 spinlock_t lock;
54
55 struct completion done;
56};
57
58/* controller state */
59struct mpc52xx_psc_spi_cs {
60 int bits_per_word;
61 int speed_hz;
62};
63
64/* set clock freq, clock ramp, bits per work
65 * if t is NULL then reset the values to the default values
66 */
67static int mpc52xx_psc_spi_transfer_setup(struct spi_device *spi,
68 struct spi_transfer *t)
69{
70 struct mpc52xx_psc_spi_cs *cs = spi->controller_state;
71
72 cs->speed_hz = (t && t->speed_hz)
73 ? t->speed_hz : spi->max_speed_hz;
74 cs->bits_per_word = (t && t->bits_per_word)
75 ? t->bits_per_word : spi->bits_per_word;
76 cs->bits_per_word = ((cs->bits_per_word + 7) / 8) * 8;
77 return 0;
78}
79
80static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
81{
82 struct mpc52xx_psc_spi_cs *cs = spi->controller_state;
83 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
84 struct mpc52xx_psc __iomem *psc = mps->psc;
85 u32 sicr;
86 u16 ccr;
87
88 sicr = in_be32(&psc->sicr);
89
90 /* Set clock phase and polarity */
91 if (spi->mode & SPI_CPHA)
92 sicr |= 0x00001000;
93 else
94 sicr &= ~0x00001000;
95 if (spi->mode & SPI_CPOL)
96 sicr |= 0x00002000;
97 else
98 sicr &= ~0x00002000;
99
100 if (spi->mode & SPI_LSB_FIRST)
101 sicr |= 0x10000000;
102 else
103 sicr &= ~0x10000000;
104 out_be32(&psc->sicr, sicr);
105
106 /* Set clock frequency and bits per word
107 * Because psc->ccr is defined as 16bit register instead of 32bit
108 * just set the lower byte of BitClkDiv
109 */
110 ccr = in_be16(&psc->ccr);
111 ccr &= 0xFF00;
112 if (cs->speed_hz)
113 ccr |= (MCLK / cs->speed_hz - 1) & 0xFF;
114 else /* by default SPI Clk 1MHz */
115 ccr |= (MCLK / 1000000 - 1) & 0xFF;
116 out_be16(&psc->ccr, ccr);
117 mps->bits_per_word = cs->bits_per_word;
118
119 if (mps->activate_cs)
120 mps->activate_cs(spi->chip_select,
121 (spi->mode & SPI_CS_HIGH) ? 1 : 0);
122}
123
124static void mpc52xx_psc_spi_deactivate_cs(struct spi_device *spi)
125{
126 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
127
128 if (mps->deactivate_cs)
129 mps->deactivate_cs(spi->chip_select,
130 (spi->mode & SPI_CS_HIGH) ? 1 : 0);
131}
132
133#define MPC52xx_PSC_BUFSIZE (MPC52xx_PSC_RFNUM_MASK + 1)
134/* wake up when 80% fifo full */
135#define MPC52xx_PSC_RFALARM (MPC52xx_PSC_BUFSIZE * 20 / 100)
136
137static int mpc52xx_psc_spi_transfer_rxtx(struct spi_device *spi,
138 struct spi_transfer *t)
139{
140 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
141 struct mpc52xx_psc __iomem *psc = mps->psc;
142 unsigned rb = 0; /* number of bytes receieved */
143 unsigned sb = 0; /* number of bytes sent */
144 unsigned char *rx_buf = (unsigned char *)t->rx_buf;
145 unsigned char *tx_buf = (unsigned char *)t->tx_buf;
146 unsigned rfalarm;
147 unsigned send_at_once = MPC52xx_PSC_BUFSIZE;
148 unsigned recv_at_once;
149 unsigned bpw = mps->bits_per_word / 8;
150
151 if (!t->tx_buf && !t->rx_buf && t->len)
152 return -EINVAL;
153
154 /* enable transmiter/receiver */
155 out_8(&psc->command, MPC52xx_PSC_TX_ENABLE | MPC52xx_PSC_RX_ENABLE);
156 while (rb < t->len) {
157 if (t->len - rb > MPC52xx_PSC_BUFSIZE) {
158 rfalarm = MPC52xx_PSC_RFALARM;
159 } else {
160 send_at_once = t->len - sb;
161 rfalarm = MPC52xx_PSC_BUFSIZE - (t->len - rb);
162 }
163
164 dev_dbg(&spi->dev, "send %d bytes...\n", send_at_once);
165 if (tx_buf) {
166 for (; send_at_once; sb++, send_at_once--) {
167 /* set EOF flag */
168 if (mps->bits_per_word
169 && (sb + 1) % bpw == 0)
170 out_8(&psc->ircr2, 0x01);
171 out_8(&psc->mpc52xx_psc_buffer_8, tx_buf[sb]);
172 }
173 } else {
174 for (; send_at_once; sb++, send_at_once--) {
175 /* set EOF flag */
176 if (mps->bits_per_word
177 && ((sb + 1) % bpw) == 0)
178 out_8(&psc->ircr2, 0x01);
179 out_8(&psc->mpc52xx_psc_buffer_8, 0);
180 }
181 }
182
183
184 /* enable interupts and wait for wake up
185 * if just one byte is expected the Rx FIFO genererates no
186 * FFULL interrupt, so activate the RxRDY interrupt
187 */
188 out_8(&psc->command, MPC52xx_PSC_SEL_MODE_REG_1);
189 if (t->len - rb == 1) {
190 out_8(&psc->mode, 0);
191 } else {
192 out_8(&psc->mode, MPC52xx_PSC_MODE_FFULL);
193 out_be16(&psc->rfalarm, rfalarm);
194 }
195 out_be16(&psc->mpc52xx_psc_imr, MPC52xx_PSC_IMR_RXRDY);
196 wait_for_completion(&mps->done);
197 recv_at_once = in_be16(&psc->rfnum);
198 dev_dbg(&spi->dev, "%d bytes received\n", recv_at_once);
199
200 send_at_once = recv_at_once;
201 if (rx_buf) {
202 for (; recv_at_once; rb++, recv_at_once--)
203 rx_buf[rb] = in_8(&psc->mpc52xx_psc_buffer_8);
204 } else {
205 for (; recv_at_once; rb++, recv_at_once--)
206 in_8(&psc->mpc52xx_psc_buffer_8);
207 }
208 }
209 /* disable transmiter/receiver */
210 out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE);
211
212 return 0;
213}
214
215static void mpc52xx_psc_spi_work(struct work_struct *work)
216{
217 struct mpc52xx_psc_spi *mps =
218 container_of(work, struct mpc52xx_psc_spi, work);
219
220 spin_lock_irq(&mps->lock);
221 mps->busy = 1;
222 while (!list_empty(&mps->queue)) {
223 struct spi_message *m;
224 struct spi_device *spi;
225 struct spi_transfer *t = NULL;
226 unsigned cs_change;
227 int status;
228
229 m = container_of(mps->queue.next, struct spi_message, queue);
230 list_del_init(&m->queue);
231 spin_unlock_irq(&mps->lock);
232
233 spi = m->spi;
234 cs_change = 1;
235 status = 0;
236 list_for_each_entry (t, &m->transfers, transfer_list) {
237 if (t->bits_per_word || t->speed_hz) {
238 status = mpc52xx_psc_spi_transfer_setup(spi, t);
239 if (status < 0)
240 break;
241 }
242
243 if (cs_change)
244 mpc52xx_psc_spi_activate_cs(spi);
245 cs_change = t->cs_change;
246
247 status = mpc52xx_psc_spi_transfer_rxtx(spi, t);
248 if (status)
249 break;
250 m->actual_length += t->len;
251
252 if (t->delay_usecs)
253 udelay(t->delay_usecs);
254
255 if (cs_change)
256 mpc52xx_psc_spi_deactivate_cs(spi);
257 }
258
259 m->status = status;
260 m->complete(m->context);
261
262 if (status || !cs_change)
263 mpc52xx_psc_spi_deactivate_cs(spi);
264
265 mpc52xx_psc_spi_transfer_setup(spi, NULL);
266
267 spin_lock_irq(&mps->lock);
268 }
269 mps->busy = 0;
270 spin_unlock_irq(&mps->lock);
271}
272
273static int mpc52xx_psc_spi_setup(struct spi_device *spi)
274{
275 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
276 struct mpc52xx_psc_spi_cs *cs = spi->controller_state;
277 unsigned long flags;
278
279 if (spi->bits_per_word%8)
280 return -EINVAL;
281
282 if (!cs) {
283 cs = kzalloc(sizeof *cs, GFP_KERNEL);
284 if (!cs)
285 return -ENOMEM;
286 spi->controller_state = cs;
287 }
288
289 cs->bits_per_word = spi->bits_per_word;
290 cs->speed_hz = spi->max_speed_hz;
291
292 spin_lock_irqsave(&mps->lock, flags);
293 if (!mps->busy)
294 mpc52xx_psc_spi_deactivate_cs(spi);
295 spin_unlock_irqrestore(&mps->lock, flags);
296
297 return 0;
298}
299
300static int mpc52xx_psc_spi_transfer(struct spi_device *spi,
301 struct spi_message *m)
302{
303 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(spi->master);
304 unsigned long flags;
305
306 m->actual_length = 0;
307 m->status = -EINPROGRESS;
308
309 spin_lock_irqsave(&mps->lock, flags);
310 list_add_tail(&m->queue, &mps->queue);
311 queue_work(mps->workqueue, &mps->work);
312 spin_unlock_irqrestore(&mps->lock, flags);
313
314 return 0;
315}
316
317static void mpc52xx_psc_spi_cleanup(struct spi_device *spi)
318{
319 kfree(spi->controller_state);
320}
321
322static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
323{
324 struct mpc52xx_cdm __iomem *cdm;
325 struct mpc52xx_gpio __iomem *gpio;
326 struct mpc52xx_psc __iomem *psc = mps->psc;
327 u32 ul;
328 u32 mclken_div;
329 int ret = 0;
330
331#if defined(CONFIG_PPC_MERGE)
332 cdm = mpc52xx_find_and_map("mpc52xx-cdm");
333 gpio = mpc52xx_find_and_map("mpc52xx-gpio");
334#else
335 cdm = ioremap(MPC52xx_PA(MPC52xx_CDM_OFFSET), MPC52xx_CDM_SIZE);
336 gpio = ioremap(MPC52xx_PA(MPC52xx_GPIO_OFFSET), MPC52xx_GPIO_SIZE);
337#endif
338 if (!cdm || !gpio) {
339 printk(KERN_ERR "Error mapping CDM/GPIO\n");
340 ret = -EFAULT;
341 goto unmap_regs;
342 }
343
344 /* default sysclk is 512MHz */
345 mclken_div = 0x8000 |
346 (((mps->sysclk ? mps->sysclk : 512000000) / MCLK) & 0x1FF);
347
348 switch (psc_id) {
349 case 1:
350 ul = in_be32(&gpio->port_config);
351 ul &= 0xFFFFFFF8;
352 ul |= 0x00000006;
353 out_be32(&gpio->port_config, ul);
354 out_be16(&cdm->mclken_div_psc1, mclken_div);
355 ul = in_be32(&cdm->clk_enables);
356 ul |= 0x00000020;
357 out_be32(&cdm->clk_enables, ul);
358 break;
359 case 2:
360 ul = in_be32(&gpio->port_config);
361 ul &= 0xFFFFFF8F;
362 ul |= 0x00000060;
363 out_be32(&gpio->port_config, ul);
364 out_be16(&cdm->mclken_div_psc2, mclken_div);
365 ul = in_be32(&cdm->clk_enables);
366 ul |= 0x00000040;
367 out_be32(&cdm->clk_enables, ul);
368 break;
369 case 3:
370 ul = in_be32(&gpio->port_config);
371 ul &= 0xFFFFF0FF;
372 ul |= 0x00000600;
373 out_be32(&gpio->port_config, ul);
374 out_be16(&cdm->mclken_div_psc3, mclken_div);
375 ul = in_be32(&cdm->clk_enables);
376 ul |= 0x00000080;
377 out_be32(&cdm->clk_enables, ul);
378 break;
379 case 6:
380 ul = in_be32(&gpio->port_config);
381 ul &= 0xFF8FFFFF;
382 ul |= 0x00700000;
383 out_be32(&gpio->port_config, ul);
384 out_be16(&cdm->mclken_div_psc6, mclken_div);
385 ul = in_be32(&cdm->clk_enables);
386 ul |= 0x00000010;
387 out_be32(&cdm->clk_enables, ul);
388 break;
389 default:
390 ret = -EINVAL;
391 goto unmap_regs;
392 }
393
394 /* Reset the PSC into a known state */
395 out_8(&psc->command, MPC52xx_PSC_RST_RX);
396 out_8(&psc->command, MPC52xx_PSC_RST_TX);
397 out_8(&psc->command, MPC52xx_PSC_TX_DISABLE | MPC52xx_PSC_RX_DISABLE);
398
399 /* Disable interrupts, interrupts are based on alarm level */
400 out_be16(&psc->mpc52xx_psc_imr, 0);
401 out_8(&psc->command, MPC52xx_PSC_SEL_MODE_REG_1);
402 out_8(&psc->rfcntl, 0);
403 out_8(&psc->mode, MPC52xx_PSC_MODE_FFULL);
404
405 /* Configure 8bit codec mode as a SPI master and use EOF flags */
406 /* SICR_SIM_CODEC8|SICR_GENCLK|SICR_SPI|SICR_MSTR|SICR_USEEOF */
407 out_be32(&psc->sicr, 0x0180C800);
408 out_be16(&psc->ccr, 0x070F); /* by default SPI Clk 1MHz */
409
410 /* Set 2ms DTL delay */
411 out_8(&psc->ctur, 0x00);
412 out_8(&psc->ctlr, 0x84);
413
414 mps->bits_per_word = 8;
415
416unmap_regs:
417 if (cdm)
418 iounmap(cdm);
419 if (gpio)
420 iounmap(gpio);
421
422 return ret;
423}
424
425static irqreturn_t mpc52xx_psc_spi_isr(int irq, void *dev_id)
426{
427 struct mpc52xx_psc_spi *mps = (struct mpc52xx_psc_spi *)dev_id;
428 struct mpc52xx_psc __iomem *psc = mps->psc;
429
430 /* disable interrupt and wake up the work queue */
431 if (in_be16(&psc->mpc52xx_psc_isr) & MPC52xx_PSC_IMR_RXRDY) {
432 out_be16(&psc->mpc52xx_psc_imr, 0);
433 complete(&mps->done);
434 return IRQ_HANDLED;
435 }
436 return IRQ_NONE;
437}
438
439/* bus_num is used only for the case dev->platform_data == NULL */
440static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
441 u32 size, unsigned int irq, s16 bus_num)
442{
443 struct fsl_spi_platform_data *pdata = dev->platform_data;
444 struct mpc52xx_psc_spi *mps;
445 struct spi_master *master;
446 int ret;
447
448 if (pdata == NULL)
449 return -ENODEV;
450
451 master = spi_alloc_master(dev, sizeof *mps);
452 if (master == NULL)
453 return -ENOMEM;
454
455 dev_set_drvdata(dev, master);
456 mps = spi_master_get_devdata(master);
457
458 mps->irq = irq;
459 if (pdata == NULL) {
460 dev_warn(dev, "probe called without platform data, no "
461 "(de)activate_cs function will be called\n");
462 mps->activate_cs = NULL;
463 mps->deactivate_cs = NULL;
464 mps->sysclk = 0;
465 master->bus_num = bus_num;
466 master->num_chipselect = 255;
467 } else {
468 mps->activate_cs = pdata->activate_cs;
469 mps->deactivate_cs = pdata->deactivate_cs;
470 mps->sysclk = pdata->sysclk;
471 master->bus_num = pdata->bus_num;
472 master->num_chipselect = pdata->max_chipselect;
473 }
474 master->setup = mpc52xx_psc_spi_setup;
475 master->transfer = mpc52xx_psc_spi_transfer;
476 master->cleanup = mpc52xx_psc_spi_cleanup;
477
478 mps->psc = ioremap(regaddr, size);
479 if (!mps->psc) {
480 dev_err(dev, "could not ioremap I/O port range\n");
481 ret = -EFAULT;
482 goto free_master;
483 }
484
485 ret = request_irq(mps->irq, mpc52xx_psc_spi_isr, 0, "mpc52xx-psc-spi",
486 mps);
487 if (ret)
488 goto free_master;
489
490 ret = mpc52xx_psc_spi_port_config(master->bus_num, mps);
491 if (ret < 0)
492 goto free_irq;
493
494 spin_lock_init(&mps->lock);
495 init_completion(&mps->done);
496 INIT_WORK(&mps->work, mpc52xx_psc_spi_work);
497 INIT_LIST_HEAD(&mps->queue);
498
499 mps->workqueue = create_singlethread_workqueue(
500 master->cdev.dev->bus_id);
501 if (mps->workqueue == NULL) {
502 ret = -EBUSY;
503 goto free_irq;
504 }
505
506 ret = spi_register_master(master);
507 if (ret < 0)
508 goto unreg_master;
509
510 return ret;
511
512unreg_master:
513 destroy_workqueue(mps->workqueue);
514free_irq:
515 free_irq(mps->irq, mps);
516free_master:
517 if (mps->psc)
518 iounmap(mps->psc);
519 spi_master_put(master);
520
521 return ret;
522}
523
524static int __exit mpc52xx_psc_spi_do_remove(struct device *dev)
525{
526 struct spi_master *master = dev_get_drvdata(dev);
527 struct mpc52xx_psc_spi *mps = spi_master_get_devdata(master);
528
529 flush_workqueue(mps->workqueue);
530 destroy_workqueue(mps->workqueue);
531 spi_unregister_master(master);
532 free_irq(mps->irq, mps);
533 if (mps->psc)
534 iounmap(mps->psc);
535
536 return 0;
537}
538
539#if !defined(CONFIG_PPC_MERGE)
540static int __init mpc52xx_psc_spi_probe(struct platform_device *dev)
541{
542 switch(dev->id) {
543 case 1:
544 case 2:
545 case 3:
546 case 6:
547 return mpc52xx_psc_spi_do_probe(&dev->dev,
548 MPC52xx_PA(MPC52xx_PSCx_OFFSET(dev->id)),
549 MPC52xx_PSC_SIZE, platform_get_irq(dev, 0), dev->id);
550 default:
551 return -EINVAL;
552 }
553}
554
555static int __exit mpc52xx_psc_spi_remove(struct platform_device *dev)
556{
557 return mpc52xx_psc_spi_do_remove(&dev->dev);
558}
559
560static struct platform_driver mpc52xx_psc_spi_platform_driver = {
561 .remove = __exit_p(mpc52xx_psc_spi_remove),
562 .driver = {
563 .name = "mpc52xx-psc-spi",
564 .owner = THIS_MODULE,
565 },
566};
567
568static int __init mpc52xx_psc_spi_init(void)
569{
570 return platform_driver_probe(&mpc52xx_psc_spi_platform_driver,
571 mpc52xx_psc_spi_probe);
572}
573module_init(mpc52xx_psc_spi_init);
574
575static void __exit mpc52xx_psc_spi_exit(void)
576{
577 platform_driver_unregister(&mpc52xx_psc_spi_platform_driver);
578}
579module_exit(mpc52xx_psc_spi_exit);
580
581#else /* defined(CONFIG_PPC_MERGE) */
582
583static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
584 const struct of_device_id *match)
585{
586 const u32 *regaddr_p;
587 u64 regaddr64, size64;
588 s16 id = -1;
589
590 regaddr_p = of_get_address(op->node, 0, &size64, NULL);
591 if (!regaddr_p) {
592 printk(KERN_ERR "Invalid PSC address\n");
593 return -EINVAL;
594 }
595 regaddr64 = of_translate_address(op->node, regaddr_p);
596
597 if (op->dev.platform_data == NULL) {
598 struct device_node *np;
599 int i = 0;
600
601 for_each_node_by_type(np, "spi") {
602 if (of_find_device_by_node(np) == op) {
603 id = i;
604 break;
605 }
606 i++;
607 }
608 }
609
610 return mpc52xx_psc_spi_do_probe(&op->dev, (u32)regaddr64, (u32)size64,
611 irq_of_parse_and_map(op->node, 0), id);
612}
613
614static int __exit mpc52xx_psc_spi_of_remove(struct of_device *op)
615{
616 return mpc52xx_psc_spi_do_remove(&op->dev);
617}
618
619static struct of_device_id mpc52xx_psc_spi_of_match[] = {
620 { .type = "spi", .compatible = "mpc52xx-psc-spi", },
621 {},
622};
623
624MODULE_DEVICE_TABLE(of, mpc52xx_psc_spi_of_match);
625
626static struct of_platform_driver mpc52xx_psc_spi_of_driver = {
627 .owner = THIS_MODULE,
628 .name = "mpc52xx-psc-spi",
629 .match_table = mpc52xx_psc_spi_of_match,
630 .probe = mpc52xx_psc_spi_of_probe,
631 .remove = __exit_p(mpc52xx_psc_spi_of_remove),
632 .driver = {
633 .name = "mpc52xx-psc-spi",
634 .owner = THIS_MODULE,
635 },
636};
637
638static int __init mpc52xx_psc_spi_init(void)
639{
640 return of_register_platform_driver(&mpc52xx_psc_spi_of_driver);
641}
642module_init(mpc52xx_psc_spi_init);
643
644static void __exit mpc52xx_psc_spi_exit(void)
645{
646 of_unregister_platform_driver(&mpc52xx_psc_spi_of_driver);
647}
648module_exit(mpc52xx_psc_spi_exit);
649
650#endif /* defined(CONFIG_PPC_MERGE) */
651
652MODULE_AUTHOR("Dragos Carp");
653MODULE_DESCRIPTION("MPC52xx PSC SPI Driver");
654MODULE_LICENSE("GPL");
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 6657331eed93..c3219b29b5ac 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -152,6 +152,11 @@ static void spi_drv_shutdown(struct device *dev)
152 sdrv->shutdown(to_spi_device(dev)); 152 sdrv->shutdown(to_spi_device(dev));
153} 153}
154 154
155/**
156 * spi_register_driver - register a SPI driver
157 * @sdrv: the driver to register
158 * Context: can sleep
159 */
155int spi_register_driver(struct spi_driver *sdrv) 160int spi_register_driver(struct spi_driver *sdrv)
156{ 161{
157 sdrv->driver.bus = &spi_bus_type; 162 sdrv->driver.bus = &spi_bus_type;
@@ -183,7 +188,13 @@ static LIST_HEAD(board_list);
183static DECLARE_MUTEX(board_lock); 188static DECLARE_MUTEX(board_lock);
184 189
185 190
186/* On typical mainboards, this is purely internal; and it's not needed 191/**
192 * spi_new_device - instantiate one new SPI device
193 * @master: Controller to which device is connected
194 * @chip: Describes the SPI device
195 * Context: can sleep
196 *
197 * On typical mainboards, this is purely internal; and it's not needed
187 * after board init creates the hard-wired devices. Some development 198 * after board init creates the hard-wired devices. Some development
188 * platforms may not be able to use spi_register_board_info though, and 199 * platforms may not be able to use spi_register_board_info though, and
189 * this is exported so that for example a USB or parport based adapter 200 * this is exported so that for example a USB or parport based adapter
@@ -251,7 +262,12 @@ fail:
251} 262}
252EXPORT_SYMBOL_GPL(spi_new_device); 263EXPORT_SYMBOL_GPL(spi_new_device);
253 264
254/* 265/**
266 * spi_register_board_info - register SPI devices for a given board
267 * @info: array of chip descriptors
268 * @n: how many descriptors are provided
269 * Context: can sleep
270 *
255 * Board-specific early init code calls this (probably during arch_initcall) 271 * Board-specific early init code calls this (probably during arch_initcall)
256 * with segments of the SPI device table. Any device nodes are created later, 272 * with segments of the SPI device table. Any device nodes are created later,
257 * after the relevant parent SPI controller (bus_num) is defined. We keep 273 * after the relevant parent SPI controller (bus_num) is defined. We keep
@@ -337,9 +353,10 @@ static struct class spi_master_class = {
337/** 353/**
338 * spi_alloc_master - allocate SPI master controller 354 * spi_alloc_master - allocate SPI master controller
339 * @dev: the controller, possibly using the platform_bus 355 * @dev: the controller, possibly using the platform_bus
340 * @size: how much driver-private data to preallocate; the pointer to this 356 * @size: how much zeroed driver-private data to allocate; the pointer to this
341 * memory is in the class_data field of the returned class_device, 357 * memory is in the class_data field of the returned class_device,
342 * accessible with spi_master_get_devdata(). 358 * accessible with spi_master_get_devdata().
359 * Context: can sleep
343 * 360 *
344 * This call is used only by SPI master controller drivers, which are the 361 * This call is used only by SPI master controller drivers, which are the
345 * only ones directly touching chip registers. It's how they allocate 362 * only ones directly touching chip registers. It's how they allocate
@@ -375,6 +392,7 @@ EXPORT_SYMBOL_GPL(spi_alloc_master);
375/** 392/**
376 * spi_register_master - register SPI master controller 393 * spi_register_master - register SPI master controller
377 * @master: initialized master, originally from spi_alloc_master() 394 * @master: initialized master, originally from spi_alloc_master()
395 * Context: can sleep
378 * 396 *
379 * SPI master controllers connect to their drivers using some non-SPI bus, 397 * SPI master controllers connect to their drivers using some non-SPI bus,
380 * such as the platform bus. The final stage of probe() in that code 398 * such as the platform bus. The final stage of probe() in that code
@@ -437,6 +455,7 @@ static int __unregister(struct device *dev, void *unused)
437/** 455/**
438 * spi_unregister_master - unregister SPI master controller 456 * spi_unregister_master - unregister SPI master controller
439 * @master: the master being unregistered 457 * @master: the master being unregistered
458 * Context: can sleep
440 * 459 *
441 * This call is used only by SPI master controller drivers, which are the 460 * This call is used only by SPI master controller drivers, which are the
442 * only ones directly touching chip registers. 461 * only ones directly touching chip registers.
@@ -455,6 +474,7 @@ EXPORT_SYMBOL_GPL(spi_unregister_master);
455/** 474/**
456 * spi_busnum_to_master - look up master associated with bus_num 475 * spi_busnum_to_master - look up master associated with bus_num
457 * @bus_num: the master's bus number 476 * @bus_num: the master's bus number
477 * Context: can sleep
458 * 478 *
459 * This call may be used with devices that are registered after 479 * This call may be used with devices that are registered after
460 * arch init time. It returns a refcounted pointer to the relevant 480 * arch init time. It returns a refcounted pointer to the relevant
@@ -492,6 +512,7 @@ static void spi_complete(void *arg)
492 * spi_sync - blocking/synchronous SPI data transfers 512 * spi_sync - blocking/synchronous SPI data transfers
493 * @spi: device with which data will be exchanged 513 * @spi: device with which data will be exchanged
494 * @message: describes the data transfers 514 * @message: describes the data transfers
515 * Context: can sleep
495 * 516 *
496 * This call may only be used from a context that may sleep. The sleep 517 * This call may only be used from a context that may sleep. The sleep
497 * is non-interruptible, and has no timeout. Low-overhead controller 518 * is non-interruptible, and has no timeout. Low-overhead controller
@@ -508,7 +529,7 @@ static void spi_complete(void *arg)
508 * 529 *
509 * The return value is a negative error code if the message could not be 530 * The return value is a negative error code if the message could not be
510 * submitted, else zero. When the value is zero, then message->status is 531 * submitted, else zero. When the value is zero, then message->status is
511 * also defined: it's the completion code for the transfer, either zero 532 * also defined; it's the completion code for the transfer, either zero
512 * or a negative error code from the controller driver. 533 * or a negative error code from the controller driver.
513 */ 534 */
514int spi_sync(struct spi_device *spi, struct spi_message *message) 535int spi_sync(struct spi_device *spi, struct spi_message *message)
@@ -538,6 +559,7 @@ static u8 *buf;
538 * @n_tx: size of txbuf, in bytes 559 * @n_tx: size of txbuf, in bytes
539 * @rxbuf: buffer into which data will be read 560 * @rxbuf: buffer into which data will be read
540 * @n_rx: size of rxbuf, in bytes (need not be dma-safe) 561 * @n_rx: size of rxbuf, in bytes (need not be dma-safe)
562 * Context: can sleep
541 * 563 *
542 * This performs a half duplex MicroWire style transaction with the 564 * This performs a half duplex MicroWire style transaction with the
543 * device, sending txbuf and then reading rxbuf. The return value 565 * device, sending txbuf and then reading rxbuf. The return value
@@ -545,7 +567,8 @@ static u8 *buf;
545 * This call may only be used from a context that may sleep. 567 * This call may only be used from a context that may sleep.
546 * 568 *
547 * Parameters to this routine are always copied using a small buffer; 569 * Parameters to this routine are always copied using a small buffer;
548 * performance-sensitive or bulk transfer code should instead use 570 * portable code should never use this for more than 32 bytes.
571 * Performance-sensitive or bulk transfer code should instead use
549 * spi_{async,sync}() calls with dma-safe buffers. 572 * spi_{async,sync}() calls with dma-safe buffers.
550 */ 573 */
551int spi_write_then_read(struct spi_device *spi, 574int spi_write_then_read(struct spi_device *spi,
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index ce3c0ce2316e..7d2d9ec6cac3 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -126,7 +126,7 @@ struct chip_data {
126 126
127 u8 chip_select_num; 127 u8 chip_select_num;
128 u8 n_bytes; 128 u8 n_bytes;
129 u32 width; /* 0 or 1 */ 129 u8 width; /* 0 or 1 */
130 u8 enable_dma; 130 u8 enable_dma;
131 u8 bits_per_word; /* 8 or 16 */ 131 u8 bits_per_word; /* 8 or 16 */
132 u8 cs_change_per_word; 132 u8 cs_change_per_word;
@@ -136,7 +136,7 @@ struct chip_data {
136 void (*duplex) (struct driver_data *); 136 void (*duplex) (struct driver_data *);
137}; 137};
138 138
139void bfin_spi_enable(struct driver_data *drv_data) 139static void bfin_spi_enable(struct driver_data *drv_data)
140{ 140{
141 u16 cr; 141 u16 cr;
142 142
@@ -145,7 +145,7 @@ void bfin_spi_enable(struct driver_data *drv_data)
145 SSYNC(); 145 SSYNC();
146} 146}
147 147
148void bfin_spi_disable(struct driver_data *drv_data) 148static void bfin_spi_disable(struct driver_data *drv_data)
149{ 149{
150 u16 cr; 150 u16 cr;
151 151
@@ -163,9 +163,6 @@ static u16 hz_to_spi_baud(u32 speed_hz)
163 if ((sclk % (2 * speed_hz)) > 0) 163 if ((sclk % (2 * speed_hz)) > 0)
164 spi_baud++; 164 spi_baud++;
165 165
166 pr_debug("sclk = %ld, speed_hz = %d, spi_baud = %d\n", sclk, speed_hz,
167 spi_baud);
168
169 return spi_baud; 166 return spi_baud;
170} 167}
171 168
@@ -190,11 +187,12 @@ static void restore_state(struct driver_data *drv_data)
190 /* Clear status and disable clock */ 187 /* Clear status and disable clock */
191 write_STAT(BIT_STAT_CLR); 188 write_STAT(BIT_STAT_CLR);
192 bfin_spi_disable(drv_data); 189 bfin_spi_disable(drv_data);
193 pr_debug("restoring spi ctl state\n"); 190 dev_dbg(&drv_data->pdev->dev, "restoring spi ctl state\n");
194 191
195#if defined(CONFIG_BF534) || defined(CONFIG_BF536) || defined(CONFIG_BF537) 192#if defined(CONFIG_BF534) || defined(CONFIG_BF536) || defined(CONFIG_BF537)
196 pr_debug("chip select number is %d\n", chip->chip_select_num); 193 dev_dbg(&drv_data->pdev->dev,
197 194 "chip select number is %d\n", chip->chip_select_num);
195
198 switch (chip->chip_select_num) { 196 switch (chip->chip_select_num) {
199 case 1: 197 case 1:
200 bfin_write_PORTF_FER(bfin_read_PORTF_FER() | 0x3c00); 198 bfin_write_PORTF_FER(bfin_read_PORTF_FER() | 0x3c00);
@@ -280,7 +278,8 @@ static void null_reader(struct driver_data *drv_data)
280 278
281static void u8_writer(struct driver_data *drv_data) 279static void u8_writer(struct driver_data *drv_data)
282{ 280{
283 pr_debug("cr8-s is 0x%x\n", read_STAT()); 281 dev_dbg(&drv_data->pdev->dev,
282 "cr8-s is 0x%x\n", read_STAT());
284 while (drv_data->tx < drv_data->tx_end) { 283 while (drv_data->tx < drv_data->tx_end) {
285 write_TDBR(*(u8 *) (drv_data->tx)); 284 write_TDBR(*(u8 *) (drv_data->tx));
286 while (read_STAT() & BIT_STAT_TXS) 285 while (read_STAT() & BIT_STAT_TXS)
@@ -318,7 +317,8 @@ static void u8_cs_chg_writer(struct driver_data *drv_data)
318 317
319static void u8_reader(struct driver_data *drv_data) 318static void u8_reader(struct driver_data *drv_data)
320{ 319{
321 pr_debug("cr-8 is 0x%x\n", read_STAT()); 320 dev_dbg(&drv_data->pdev->dev,
321 "cr-8 is 0x%x\n", read_STAT());
322 322
323 /* clear TDBR buffer before read(else it will be shifted out) */ 323 /* clear TDBR buffer before read(else it will be shifted out) */
324 write_TDBR(0xFFFF); 324 write_TDBR(0xFFFF);
@@ -404,7 +404,9 @@ static void u8_cs_chg_duplex(struct driver_data *drv_data)
404 404
405static void u16_writer(struct driver_data *drv_data) 405static void u16_writer(struct driver_data *drv_data)
406{ 406{
407 pr_debug("cr16 is 0x%x\n", read_STAT()); 407 dev_dbg(&drv_data->pdev->dev,
408 "cr16 is 0x%x\n", read_STAT());
409
408 while (drv_data->tx < drv_data->tx_end) { 410 while (drv_data->tx < drv_data->tx_end) {
409 write_TDBR(*(u16 *) (drv_data->tx)); 411 write_TDBR(*(u16 *) (drv_data->tx));
410 while ((read_STAT() & BIT_STAT_TXS)) 412 while ((read_STAT() & BIT_STAT_TXS))
@@ -442,7 +444,8 @@ static void u16_cs_chg_writer(struct driver_data *drv_data)
442 444
443static void u16_reader(struct driver_data *drv_data) 445static void u16_reader(struct driver_data *drv_data)
444{ 446{
445 pr_debug("cr-16 is 0x%x\n", read_STAT()); 447 dev_dbg(&drv_data->pdev->dev,
448 "cr-16 is 0x%x\n", read_STAT());
446 dummy_read(); 449 dummy_read();
447 450
448 while (drv_data->rx < (drv_data->rx_end - 2)) { 451 while (drv_data->rx < (drv_data->rx_end - 2)) {
@@ -571,12 +574,12 @@ static void giveback(struct driver_data *drv_data)
571 msg->complete(msg->context); 574 msg->complete(msg->context);
572} 575}
573 576
574static irqreturn_t dma_irq_handler(int irq, void *dev_id, struct pt_regs *regs) 577static irqreturn_t dma_irq_handler(int irq, void *dev_id)
575{ 578{
576 struct driver_data *drv_data = (struct driver_data *)dev_id; 579 struct driver_data *drv_data = (struct driver_data *)dev_id;
577 struct spi_message *msg = drv_data->cur_msg; 580 struct spi_message *msg = drv_data->cur_msg;
578 581
579 pr_debug("in dma_irq_handler\n"); 582 dev_dbg(&drv_data->pdev->dev, "in dma_irq_handler\n");
580 clear_dma_irqstat(CH_SPI); 583 clear_dma_irqstat(CH_SPI);
581 584
582 /* 585 /*
@@ -604,7 +607,9 @@ static irqreturn_t dma_irq_handler(int irq, void *dev_id, struct pt_regs *regs)
604 tasklet_schedule(&drv_data->pump_transfers); 607 tasklet_schedule(&drv_data->pump_transfers);
605 608
606 /* free the irq handler before next transfer */ 609 /* free the irq handler before next transfer */
607 pr_debug("disable dma channel irq%d\n", CH_SPI); 610 dev_dbg(&drv_data->pdev->dev,
611 "disable dma channel irq%d\n",
612 CH_SPI);
608 dma_disable_irq(CH_SPI); 613 dma_disable_irq(CH_SPI);
609 614
610 return IRQ_HANDLED; 615 return IRQ_HANDLED;
@@ -617,7 +622,8 @@ static void pump_transfers(unsigned long data)
617 struct spi_transfer *transfer = NULL; 622 struct spi_transfer *transfer = NULL;
618 struct spi_transfer *previous = NULL; 623 struct spi_transfer *previous = NULL;
619 struct chip_data *chip = NULL; 624 struct chip_data *chip = NULL;
620 u16 cr, width, dma_width, dma_config; 625 u8 width;
626 u16 cr, dma_width, dma_config;
621 u32 tranf_success = 1; 627 u32 tranf_success = 1;
622 628
623 /* Get current state information */ 629 /* Get current state information */
@@ -662,8 +668,8 @@ static void pump_transfers(unsigned long data)
662 if (transfer->tx_buf != NULL) { 668 if (transfer->tx_buf != NULL) {
663 drv_data->tx = (void *)transfer->tx_buf; 669 drv_data->tx = (void *)transfer->tx_buf;
664 drv_data->tx_end = drv_data->tx + transfer->len; 670 drv_data->tx_end = drv_data->tx + transfer->len;
665 pr_debug("tx_buf is %p, tx_end is %p\n", transfer->tx_buf, 671 dev_dbg(&drv_data->pdev->dev, "tx_buf is %p, tx_end is %p\n",
666 drv_data->tx_end); 672 transfer->tx_buf, drv_data->tx_end);
667 } else { 673 } else {
668 drv_data->tx = NULL; 674 drv_data->tx = NULL;
669 } 675 }
@@ -671,8 +677,8 @@ static void pump_transfers(unsigned long data)
671 if (transfer->rx_buf != NULL) { 677 if (transfer->rx_buf != NULL) {
672 drv_data->rx = transfer->rx_buf; 678 drv_data->rx = transfer->rx_buf;
673 drv_data->rx_end = drv_data->rx + transfer->len; 679 drv_data->rx_end = drv_data->rx + transfer->len;
674 pr_debug("rx_buf is %p, rx_end is %p\n", transfer->rx_buf, 680 dev_dbg(&drv_data->pdev->dev, "rx_buf is %p, rx_end is %p\n",
675 drv_data->rx_end); 681 transfer->rx_buf, drv_data->rx_end);
676 } else { 682 } else {
677 drv_data->rx = NULL; 683 drv_data->rx = NULL;
678 } 684 }
@@ -690,9 +696,9 @@ static void pump_transfers(unsigned long data)
690 drv_data->write = drv_data->tx ? chip->write : null_writer; 696 drv_data->write = drv_data->tx ? chip->write : null_writer;
691 drv_data->read = drv_data->rx ? chip->read : null_reader; 697 drv_data->read = drv_data->rx ? chip->read : null_reader;
692 drv_data->duplex = chip->duplex ? chip->duplex : null_writer; 698 drv_data->duplex = chip->duplex ? chip->duplex : null_writer;
693 pr_debug 699 dev_dbg(&drv_data->pdev->dev,
694 ("transfer: drv_data->write is %p, chip->write is %p, null_wr is %p\n", 700 "transfer: drv_data->write is %p, chip->write is %p, null_wr is %p\n",
695 drv_data->write, chip->write, null_writer); 701 drv_data->write, chip->write, null_writer);
696 702
697 /* speed and width has been set on per message */ 703 /* speed and width has been set on per message */
698 message->state = RUNNING_STATE; 704 message->state = RUNNING_STATE;
@@ -706,8 +712,9 @@ static void pump_transfers(unsigned long data)
706 } 712 }
707 write_FLAG(chip->flag); 713 write_FLAG(chip->flag);
708 714
709 pr_debug("now pumping a transfer: width is %d, len is %d\n", width, 715 dev_dbg(&drv_data->pdev->dev,
710 transfer->len); 716 "now pumping a transfer: width is %d, len is %d\n",
717 width, transfer->len);
711 718
712 /* 719 /*
713 * Try to map dma buffer and do a dma transfer if 720 * Try to map dma buffer and do a dma transfer if
@@ -722,7 +729,7 @@ static void pump_transfers(unsigned long data)
722 bfin_spi_disable(drv_data); 729 bfin_spi_disable(drv_data);
723 730
724 /* config dma channel */ 731 /* config dma channel */
725 pr_debug("doing dma transfer\n"); 732 dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n");
726 if (width == CFG_SPI_WORDSIZE16) { 733 if (width == CFG_SPI_WORDSIZE16) {
727 set_dma_x_count(CH_SPI, drv_data->len); 734 set_dma_x_count(CH_SPI, drv_data->len);
728 set_dma_x_modify(CH_SPI, 2); 735 set_dma_x_modify(CH_SPI, 2);
@@ -738,7 +745,8 @@ static void pump_transfers(unsigned long data)
738 745
739 /* dirty hack for autobuffer DMA mode */ 746 /* dirty hack for autobuffer DMA mode */
740 if (drv_data->tx_dma == 0xFFFF) { 747 if (drv_data->tx_dma == 0xFFFF) {
741 pr_debug("doing autobuffer DMA out.\n"); 748 dev_dbg(&drv_data->pdev->dev,
749 "doing autobuffer DMA out.\n");
742 750
743 /* no irq in autobuffer mode */ 751 /* no irq in autobuffer mode */
744 dma_config = 752 dma_config =
@@ -758,7 +766,7 @@ static void pump_transfers(unsigned long data)
758 /* In dma mode, rx or tx must be NULL in one transfer */ 766 /* In dma mode, rx or tx must be NULL in one transfer */
759 if (drv_data->rx != NULL) { 767 if (drv_data->rx != NULL) {
760 /* set transfer mode, and enable SPI */ 768 /* set transfer mode, and enable SPI */
761 pr_debug("doing DMA in.\n"); 769 dev_dbg(&drv_data->pdev->dev, "doing DMA in.\n");
762 770
763 /* disable SPI before write to TDBR */ 771 /* disable SPI before write to TDBR */
764 write_CTRL(cr & ~BIT_CTL_ENABLE); 772 write_CTRL(cr & ~BIT_CTL_ENABLE);
@@ -781,7 +789,7 @@ static void pump_transfers(unsigned long data)
781 /* set transfer mode, and enable SPI */ 789 /* set transfer mode, and enable SPI */
782 write_CTRL(cr); 790 write_CTRL(cr);
783 } else if (drv_data->tx != NULL) { 791 } else if (drv_data->tx != NULL) {
784 pr_debug("doing DMA out.\n"); 792 dev_dbg(&drv_data->pdev->dev, "doing DMA out.\n");
785 793
786 /* start dma */ 794 /* start dma */
787 dma_enable_irq(CH_SPI); 795 dma_enable_irq(CH_SPI);
@@ -796,7 +804,7 @@ static void pump_transfers(unsigned long data)
796 } 804 }
797 } else { 805 } else {
798 /* IO mode write then read */ 806 /* IO mode write then read */
799 pr_debug("doing IO transfer\n"); 807 dev_dbg(&drv_data->pdev->dev, "doing IO transfer\n");
800 808
801 write_STAT(BIT_STAT_CLR); 809 write_STAT(BIT_STAT_CLR);
802 810
@@ -804,11 +812,11 @@ static void pump_transfers(unsigned long data)
804 /* full duplex mode */ 812 /* full duplex mode */
805 BUG_ON((drv_data->tx_end - drv_data->tx) != 813 BUG_ON((drv_data->tx_end - drv_data->tx) !=
806 (drv_data->rx_end - drv_data->rx)); 814 (drv_data->rx_end - drv_data->rx));
807 cr = (read_CTRL() & (~BIT_CTL_TIMOD)); /* clear the TIMOD bits */ 815 cr = (read_CTRL() & (~BIT_CTL_TIMOD));
808 cr |= 816 cr |= CFG_SPI_WRITE | (width << 8) |
809 CFG_SPI_WRITE | (width << 8) | (CFG_SPI_ENABLE << 817 (CFG_SPI_ENABLE << 14);
810 14); 818 dev_dbg(&drv_data->pdev->dev,
811 pr_debug("IO duplex: cr is 0x%x\n", cr); 819 "IO duplex: cr is 0x%x\n", cr);
812 820
813 write_CTRL(cr); 821 write_CTRL(cr);
814 SSYNC(); 822 SSYNC();
@@ -819,11 +827,11 @@ static void pump_transfers(unsigned long data)
819 tranf_success = 0; 827 tranf_success = 0;
820 } else if (drv_data->tx != NULL) { 828 } else if (drv_data->tx != NULL) {
821 /* write only half duplex */ 829 /* write only half duplex */
822 cr = (read_CTRL() & (~BIT_CTL_TIMOD)); /* clear the TIMOD bits */ 830 cr = (read_CTRL() & (~BIT_CTL_TIMOD));
823 cr |= 831 cr |= CFG_SPI_WRITE | (width << 8) |
824 CFG_SPI_WRITE | (width << 8) | (CFG_SPI_ENABLE << 832 (CFG_SPI_ENABLE << 14);
825 14); 833 dev_dbg(&drv_data->pdev->dev,
826 pr_debug("IO write: cr is 0x%x\n", cr); 834 "IO write: cr is 0x%x\n", cr);
827 835
828 write_CTRL(cr); 836 write_CTRL(cr);
829 SSYNC(); 837 SSYNC();
@@ -834,11 +842,11 @@ static void pump_transfers(unsigned long data)
834 tranf_success = 0; 842 tranf_success = 0;
835 } else if (drv_data->rx != NULL) { 843 } else if (drv_data->rx != NULL) {
836 /* read only half duplex */ 844 /* read only half duplex */
837 cr = (read_CTRL() & (~BIT_CTL_TIMOD)); /* cleare the TIMOD bits */ 845 cr = (read_CTRL() & (~BIT_CTL_TIMOD));
838 cr |= 846 cr |= CFG_SPI_READ | (width << 8) |
839 CFG_SPI_READ | (width << 8) | (CFG_SPI_ENABLE << 847 (CFG_SPI_ENABLE << 14);
840 14); 848 dev_dbg(&drv_data->pdev->dev,
841 pr_debug("IO read: cr is 0x%x\n", cr); 849 "IO read: cr is 0x%x\n", cr);
842 850
843 write_CTRL(cr); 851 write_CTRL(cr);
844 SSYNC(); 852 SSYNC();
@@ -849,7 +857,8 @@ static void pump_transfers(unsigned long data)
849 } 857 }
850 858
851 if (!tranf_success) { 859 if (!tranf_success) {
852 pr_debug("IO write error!\n"); 860 dev_dbg(&drv_data->pdev->dev,
861 "IO write error!\n");
853 message->state = ERROR_STATE; 862 message->state = ERROR_STATE;
854 } else { 863 } else {
855 /* Update total byte transfered */ 864 /* Update total byte transfered */
@@ -899,11 +908,14 @@ static void pump_messages(struct work_struct *work)
899 /* Setup the SSP using the per chip configuration */ 908 /* Setup the SSP using the per chip configuration */
900 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi); 909 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
901 restore_state(drv_data); 910 restore_state(drv_data);
902 pr_debug 911 dev_dbg(&drv_data->pdev->dev,
903 ("got a message to pump, state is set to: baud %d, flag 0x%x, ctl 0x%x\n", 912 "got a message to pump, state is set to: baud %d, flag 0x%x, ctl 0x%x\n",
904 drv_data->cur_chip->baud, drv_data->cur_chip->flag, 913 drv_data->cur_chip->baud, drv_data->cur_chip->flag,
905 drv_data->cur_chip->ctl_reg); 914 drv_data->cur_chip->ctl_reg);
906 pr_debug("the first transfer len is %d\n", drv_data->cur_transfer->len); 915
916 dev_dbg(&drv_data->pdev->dev,
917 "the first transfer len is %d\n",
918 drv_data->cur_transfer->len);
907 919
908 /* Mark as busy and launch transfers */ 920 /* Mark as busy and launch transfers */
909 tasklet_schedule(&drv_data->pump_transfers); 921 tasklet_schedule(&drv_data->pump_transfers);
@@ -932,7 +944,7 @@ static int transfer(struct spi_device *spi, struct spi_message *msg)
932 msg->status = -EINPROGRESS; 944 msg->status = -EINPROGRESS;
933 msg->state = START_STATE; 945 msg->state = START_STATE;
934 946
935 pr_debug("adding an msg in transfer() \n"); 947 dev_dbg(&spi->dev, "adding an msg in transfer() \n");
936 list_add_tail(&msg->queue, &drv_data->queue); 948 list_add_tail(&msg->queue, &drv_data->queue);
937 949
938 if (drv_data->run == QUEUE_RUNNING && !drv_data->busy) 950 if (drv_data->run == QUEUE_RUNNING && !drv_data->busy)
@@ -1002,13 +1014,13 @@ static int setup(struct spi_device *spi)
1002 if (chip->enable_dma && !dma_requested) { 1014 if (chip->enable_dma && !dma_requested) {
1003 /* register dma irq handler */ 1015 /* register dma irq handler */
1004 if (request_dma(CH_SPI, "BF53x_SPI_DMA") < 0) { 1016 if (request_dma(CH_SPI, "BF53x_SPI_DMA") < 0) {
1005 pr_debug 1017 dev_dbg(&spi->dev,
1006 ("Unable to request BlackFin SPI DMA channel\n"); 1018 "Unable to request BlackFin SPI DMA channel\n");
1007 return -ENODEV; 1019 return -ENODEV;
1008 } 1020 }
1009 if (set_dma_callback(CH_SPI, (void *)dma_irq_handler, drv_data) 1021 if (set_dma_callback(CH_SPI, (void *)dma_irq_handler, drv_data)
1010 < 0) { 1022 < 0) {
1011 pr_debug("Unable to set dma callback\n"); 1023 dev_dbg(&spi->dev, "Unable to set dma callback\n");
1012 return -EPERM; 1024 return -EPERM;
1013 } 1025 }
1014 dma_disable_irq(CH_SPI); 1026 dma_disable_irq(CH_SPI);
@@ -1054,9 +1066,9 @@ static int setup(struct spi_device *spi)
1054 return -ENODEV; 1066 return -ENODEV;
1055 } 1067 }
1056 1068
1057 pr_debug("setup spi chip %s, width is %d, dma is %d,", 1069 dev_dbg(&spi->dev, "setup spi chip %s, width is %d, dma is %d,",
1058 spi->modalias, chip->width, chip->enable_dma); 1070 spi->modalias, chip->width, chip->enable_dma);
1059 pr_debug("ctl_reg is 0x%x, flag_reg is 0x%x\n", 1071 dev_dbg(&spi->dev, "ctl_reg is 0x%x, flag_reg is 0x%x\n",
1060 chip->ctl_reg, chip->flag); 1072 chip->ctl_reg, chip->flag);
1061 1073
1062 spi_set_ctldata(spi, chip); 1074 spi_set_ctldata(spi, chip);
@@ -1068,7 +1080,7 @@ static int setup(struct spi_device *spi)
1068 * callback for spi framework. 1080 * callback for spi framework.
1069 * clean driver specific data 1081 * clean driver specific data
1070 */ 1082 */
1071static void cleanup(const struct spi_device *spi) 1083static void cleanup(struct spi_device *spi)
1072{ 1084{
1073 struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi); 1085 struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi);
1074 1086
@@ -1207,7 +1219,7 @@ static int __init bfin5xx_spi_probe(struct platform_device *pdev)
1207 dev_err(&pdev->dev, "problem registering spi master\n"); 1219 dev_err(&pdev->dev, "problem registering spi master\n");
1208 goto out_error_queue_alloc; 1220 goto out_error_queue_alloc;
1209 } 1221 }
1210 pr_debug("controller probe successfully\n"); 1222 dev_dbg(&pdev->dev, "controller probe successfully\n");
1211 return status; 1223 return status;
1212 1224
1213 out_error_queue_alloc: 1225 out_error_queue_alloc:
@@ -1287,27 +1299,23 @@ static int bfin5xx_spi_resume(struct platform_device *pdev)
1287#endif /* CONFIG_PM */ 1299#endif /* CONFIG_PM */
1288 1300
1289static struct platform_driver bfin5xx_spi_driver = { 1301static struct platform_driver bfin5xx_spi_driver = {
1290 .driver = { 1302 .driver = {
1291 .name = "bfin-spi-master", 1303 .name = "bfin-spi-master",
1292 .bus = &platform_bus_type, 1304 .owner = THIS_MODULE,
1293 .owner = THIS_MODULE, 1305 },
1294 }, 1306 .suspend = bfin5xx_spi_suspend,
1295 .probe = bfin5xx_spi_probe, 1307 .resume = bfin5xx_spi_resume,
1296 .remove = __devexit_p(bfin5xx_spi_remove), 1308 .remove = __devexit_p(bfin5xx_spi_remove),
1297 .suspend = bfin5xx_spi_suspend,
1298 .resume = bfin5xx_spi_resume,
1299}; 1309};
1300 1310
1301static int __init bfin5xx_spi_init(void) 1311static int __init bfin5xx_spi_init(void)
1302{ 1312{
1303 return platform_driver_register(&bfin5xx_spi_driver); 1313 return platform_driver_probe(&bfin5xx_spi_driver, bfin5xx_spi_probe);
1304} 1314}
1305
1306module_init(bfin5xx_spi_init); 1315module_init(bfin5xx_spi_init);
1307 1316
1308static void __exit bfin5xx_spi_exit(void) 1317static void __exit bfin5xx_spi_exit(void)
1309{ 1318{
1310 platform_driver_unregister(&bfin5xx_spi_driver); 1319 platform_driver_unregister(&bfin5xx_spi_driver);
1311} 1320}
1312
1313module_exit(bfin5xx_spi_exit); 1321module_exit(bfin5xx_spi_exit);
diff --git a/drivers/spi/spi_butterfly.c b/drivers/spi/spi_butterfly.c
index 312987a03210..0ee2b2090252 100644
--- a/drivers/spi/spi_butterfly.c
+++ b/drivers/spi/spi_butterfly.c
@@ -20,7 +20,7 @@
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/platform_device.h> 23#include <linux/device.h>
24#include <linux/parport.h> 24#include <linux/parport.h>
25 25
26#include <linux/sched.h> 26#include <linux/sched.h>
@@ -40,8 +40,6 @@
40 * and use this custom parallel port cable. 40 * and use this custom parallel port cable.
41 */ 41 */
42 42
43#undef HAVE_USI /* nyet */
44
45 43
46/* DATA output bits (pins 2..9 == D0..D7) */ 44/* DATA output bits (pins 2..9 == D0..D7) */
47#define butterfly_nreset (1 << 1) /* pin 3 */ 45#define butterfly_nreset (1 << 1) /* pin 3 */
@@ -49,19 +47,13 @@
49#define spi_sck_bit (1 << 0) /* pin 2 */ 47#define spi_sck_bit (1 << 0) /* pin 2 */
50#define spi_mosi_bit (1 << 7) /* pin 9 */ 48#define spi_mosi_bit (1 << 7) /* pin 9 */
51 49
52#define usi_sck_bit (1 << 3) /* pin 5 */
53#define usi_mosi_bit (1 << 4) /* pin 6 */
54
55#define vcc_bits ((1 << 6) | (1 << 5)) /* pins 7, 8 */ 50#define vcc_bits ((1 << 6) | (1 << 5)) /* pins 7, 8 */
56 51
57/* STATUS input bits */ 52/* STATUS input bits */
58#define spi_miso_bit PARPORT_STATUS_BUSY /* pin 11 */ 53#define spi_miso_bit PARPORT_STATUS_BUSY /* pin 11 */
59 54
60#define usi_miso_bit PARPORT_STATUS_PAPEROUT /* pin 12 */
61
62/* CONTROL output bits */ 55/* CONTROL output bits */
63#define spi_cs_bit PARPORT_CONTROL_SELECT /* pin 17 */ 56#define spi_cs_bit PARPORT_CONTROL_SELECT /* pin 17 */
64/* USI uses no chipselect */
65 57
66 58
67 59
@@ -70,15 +62,6 @@ static inline struct butterfly *spidev_to_pp(struct spi_device *spi)
70 return spi->controller_data; 62 return spi->controller_data;
71} 63}
72 64
73static inline int is_usidev(struct spi_device *spi)
74{
75#ifdef HAVE_USI
76 return spi->chip_select != 1;
77#else
78 return 0;
79#endif
80}
81
82 65
83struct butterfly { 66struct butterfly {
84 /* REVISIT ... for now, this must be first */ 67 /* REVISIT ... for now, this must be first */
@@ -97,23 +80,13 @@ struct butterfly {
97 80
98/*----------------------------------------------------------------------*/ 81/*----------------------------------------------------------------------*/
99 82
100/*
101 * these routines may be slower than necessary because they're hiding
102 * the fact that there are two different SPI busses on this cable: one
103 * to the DataFlash chip (or AVR SPI controller), the other to the
104 * AVR USI controller.
105 */
106
107static inline void 83static inline void
108setsck(struct spi_device *spi, int is_on) 84setsck(struct spi_device *spi, int is_on)
109{ 85{
110 struct butterfly *pp = spidev_to_pp(spi); 86 struct butterfly *pp = spidev_to_pp(spi);
111 u8 bit, byte = pp->lastbyte; 87 u8 bit, byte = pp->lastbyte;
112 88
113 if (is_usidev(spi)) 89 bit = spi_sck_bit;
114 bit = usi_sck_bit;
115 else
116 bit = spi_sck_bit;
117 90
118 if (is_on) 91 if (is_on)
119 byte |= bit; 92 byte |= bit;
@@ -129,10 +102,7 @@ setmosi(struct spi_device *spi, int is_on)
129 struct butterfly *pp = spidev_to_pp(spi); 102 struct butterfly *pp = spidev_to_pp(spi);
130 u8 bit, byte = pp->lastbyte; 103 u8 bit, byte = pp->lastbyte;
131 104
132 if (is_usidev(spi)) 105 bit = spi_mosi_bit;
133 bit = usi_mosi_bit;
134 else
135 bit = spi_mosi_bit;
136 106
137 if (is_on) 107 if (is_on)
138 byte |= bit; 108 byte |= bit;
@@ -148,10 +118,7 @@ static inline int getmiso(struct spi_device *spi)
148 int value; 118 int value;
149 u8 bit; 119 u8 bit;
150 120
151 if (is_usidev(spi)) 121 bit = spi_miso_bit;
152 bit = usi_miso_bit;
153 else
154 bit = spi_miso_bit;
155 122
156 /* only STATUS_BUSY is NOT negated */ 123 /* only STATUS_BUSY is NOT negated */
157 value = !(parport_read_status(pp->port) & bit); 124 value = !(parport_read_status(pp->port) & bit);
@@ -166,10 +133,6 @@ static void butterfly_chipselect(struct spi_device *spi, int value)
166 if (value != BITBANG_CS_INACTIVE) 133 if (value != BITBANG_CS_INACTIVE)
167 setsck(spi, spi->mode & SPI_CPOL); 134 setsck(spi, spi->mode & SPI_CPOL);
168 135
169 /* no chipselect on this USI link config */
170 if (is_usidev(spi))
171 return;
172
173 /* here, value == "activate or not"; 136 /* here, value == "activate or not";
174 * most PARPORT_CONTROL_* bits are negated, so we must 137 * most PARPORT_CONTROL_* bits are negated, so we must
175 * morph it to value == "bit value to write in control register" 138 * morph it to value == "bit value to write in control register"
@@ -237,24 +200,16 @@ static void butterfly_attach(struct parport *p)
237 int status; 200 int status;
238 struct butterfly *pp; 201 struct butterfly *pp;
239 struct spi_master *master; 202 struct spi_master *master;
240 struct platform_device *pdev; 203 struct device *dev = p->physport->dev;
241 204
242 if (butterfly) 205 if (butterfly || !dev)
243 return; 206 return;
244 207
245 /* REVISIT: this just _assumes_ a butterfly is there ... no probe, 208 /* REVISIT: this just _assumes_ a butterfly is there ... no probe,
246 * and no way to be selective about what it binds to. 209 * and no way to be selective about what it binds to.
247 */ 210 */
248 211
249 /* FIXME where should master->cdev.dev come from? 212 master = spi_alloc_master(dev, sizeof *pp);
250 * e.g. /sys/bus/pnp0/00:0b, some PCI thing, etc
251 * setting up a platform device like this is an ugly kluge...
252 */
253 pdev = platform_device_register_simple("butterfly", -1, NULL, 0);
254 if (IS_ERR(pdev))
255 return;
256
257 master = spi_alloc_master(&pdev->dev, sizeof *pp);
258 if (!master) { 213 if (!master) {
259 status = -ENOMEM; 214 status = -ENOMEM;
260 goto done; 215 goto done;
@@ -300,7 +255,7 @@ static void butterfly_attach(struct parport *p)
300 parport_frob_control(pp->port, spi_cs_bit, 0); 255 parport_frob_control(pp->port, spi_cs_bit, 0);
301 256
302 /* stabilize power with chip in reset (nRESET), and 257 /* stabilize power with chip in reset (nRESET), and
303 * both spi_sck_bit and usi_sck_bit clear (CPOL=0) 258 * spi_sck_bit clear (CPOL=0)
304 */ 259 */
305 pp->lastbyte |= vcc_bits; 260 pp->lastbyte |= vcc_bits;
306 parport_write_data(pp->port, pp->lastbyte); 261 parport_write_data(pp->port, pp->lastbyte);
@@ -334,23 +289,6 @@ static void butterfly_attach(struct parport *p)
334 pr_debug("%s: dataflash at %s\n", p->name, 289 pr_debug("%s: dataflash at %s\n", p->name,
335 pp->dataflash->dev.bus_id); 290 pp->dataflash->dev.bus_id);
336 291
337#ifdef HAVE_USI
338 /* Bus 2 is only for talking to the AVR, and it can work no
339 * matter who masters bus 1; needs appropriate AVR firmware.
340 */
341 pp->info[1].max_speed_hz = 10 /* ?? */ * 1000 * 1000;
342 strcpy(pp->info[1].modalias, "butterfly");
343 // pp->info[1].platform_data = ... TBD ... ;
344 pp->info[1].chip_select = 2,
345 pp->info[1].controller_data = pp;
346 pp->butterfly = spi_new_device(pp->bitbang.master, &pp->info[1]);
347 if (pp->butterfly)
348 pr_debug("%s: butterfly at %s\n", p->name,
349 pp->butterfly->dev.bus_id);
350
351 /* FIXME setup ACK for the IRQ line ... */
352#endif
353
354 // dev_info(_what?_, ...) 292 // dev_info(_what?_, ...)
355 pr_info("%s: AVR Butterfly\n", p->name); 293 pr_info("%s: AVR Butterfly\n", p->name);
356 butterfly = pp; 294 butterfly = pp;
@@ -366,14 +304,12 @@ clean1:
366clean0: 304clean0:
367 (void) spi_master_put(pp->bitbang.master); 305 (void) spi_master_put(pp->bitbang.master);
368done: 306done:
369 platform_device_unregister(pdev);
370 pr_debug("%s: butterfly probe, fail %d\n", p->name, status); 307 pr_debug("%s: butterfly probe, fail %d\n", p->name, status);
371} 308}
372 309
373static void butterfly_detach(struct parport *p) 310static void butterfly_detach(struct parport *p)
374{ 311{
375 struct butterfly *pp; 312 struct butterfly *pp;
376 struct platform_device *pdev;
377 int status; 313 int status;
378 314
379 /* FIXME this global is ugly ... but, how to quickly get from 315 /* FIXME this global is ugly ... but, how to quickly get from
@@ -386,7 +322,6 @@ static void butterfly_detach(struct parport *p)
386 butterfly = NULL; 322 butterfly = NULL;
387 323
388 /* stop() unregisters child devices too */ 324 /* stop() unregisters child devices too */
389 pdev = to_platform_device(pp->bitbang.master->cdev.dev);
390 status = spi_bitbang_stop(&pp->bitbang); 325 status = spi_bitbang_stop(&pp->bitbang);
391 326
392 /* turn off VCC */ 327 /* turn off VCC */
@@ -397,8 +332,6 @@ static void butterfly_detach(struct parport *p)
397 parport_unregister_device(pp->pd); 332 parport_unregister_device(pp->pd);
398 333
399 (void) spi_master_put(pp->bitbang.master); 334 (void) spi_master_put(pp->bitbang.master);
400
401 platform_device_unregister(pdev);
402} 335}
403 336
404static struct parport_driver butterfly_driver = { 337static struct parport_driver butterfly_driver = {
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
new file mode 100644
index 000000000000..225d6b2f82dd
--- /dev/null
+++ b/drivers/spi/spidev.c
@@ -0,0 +1,584 @@
1/*
2 * spidev.c -- simple synchronous userspace interface to SPI devices
3 *
4 * Copyright (C) 2006 SWAPP
5 * Andrea Paterniani <a.paterniani@swapp-eng.it>
6 * Copyright (C) 2007 David Brownell (simplification, cleanup)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/ioctl.h>
26#include <linux/fs.h>
27#include <linux/device.h>
28#include <linux/list.h>
29#include <linux/errno.h>
30#include <linux/mutex.h>
31#include <linux/slab.h>
32
33#include <linux/spi/spi.h>
34#include <linux/spi/spidev.h>
35
36#include <asm/uaccess.h>
37
38
39/*
40 * This supports acccess to SPI devices using normal userspace I/O calls.
41 * Note that while traditional UNIX/POSIX I/O semantics are half duplex,
42 * and often mask message boundaries, full SPI support requires full duplex
43 * transfers. There are several kinds of of internal message boundaries to
44 * handle chipselect management and other protocol options.
45 *
46 * SPI has a character major number assigned. We allocate minor numbers
47 * dynamically using a bitmask. You must use hotplug tools, such as udev
48 * (or mdev with busybox) to create and destroy the /dev/spidevB.C device
49 * nodes, since there is no fixed association of minor numbers with any
50 * particular SPI bus or device.
51 */
52#define SPIDEV_MAJOR 153 /* assigned */
53#define N_SPI_MINORS 32 /* ... up to 256 */
54
55static unsigned long minors[N_SPI_MINORS / BITS_PER_LONG];
56
57
58/* Bit masks for spi_device.mode management */
59#define SPI_MODE_MASK (SPI_CPHA | SPI_CPOL)
60
61
62struct spidev_data {
63 struct device dev;
64 struct spi_device *spi;
65 struct list_head device_entry;
66
67 struct mutex buf_lock;
68 unsigned users;
69 u8 *buffer;
70};
71
72static LIST_HEAD(device_list);
73static DEFINE_MUTEX(device_list_lock);
74
75static unsigned bufsiz = 4096;
76module_param(bufsiz, uint, S_IRUGO);
77MODULE_PARM_DESC(bufsiz, "data bytes in biggest supported SPI message");
78
79/*-------------------------------------------------------------------------*/
80
81/* Read-only message with current device setup */
82static ssize_t
83spidev_read(struct file *filp, char __user *buf, size_t count, loff_t *f_pos)
84{
85 struct spidev_data *spidev;
86 struct spi_device *spi;
87 ssize_t status = 0;
88
89 /* chipselect only toggles at start or end of operation */
90 if (count > bufsiz)
91 return -EMSGSIZE;
92
93 spidev = filp->private_data;
94 spi = spidev->spi;
95
96 mutex_lock(&spidev->buf_lock);
97 status = spi_read(spi, spidev->buffer, count);
98 if (status == 0) {
99 unsigned long missing;
100
101 missing = copy_to_user(buf, spidev->buffer, count);
102 if (count && missing == count)
103 status = -EFAULT;
104 else
105 status = count - missing;
106 }
107 mutex_unlock(&spidev->buf_lock);
108
109 return status;
110}
111
112/* Write-only message with current device setup */
113static ssize_t
114spidev_write(struct file *filp, const char __user *buf,
115 size_t count, loff_t *f_pos)
116{
117 struct spidev_data *spidev;
118 struct spi_device *spi;
119 ssize_t status = 0;
120 unsigned long missing;
121
122 /* chipselect only toggles at start or end of operation */
123 if (count > bufsiz)
124 return -EMSGSIZE;
125
126 spidev = filp->private_data;
127 spi = spidev->spi;
128
129 mutex_lock(&spidev->buf_lock);
130 missing = copy_from_user(spidev->buffer, buf, count);
131 if (missing == 0) {
132 status = spi_write(spi, spidev->buffer, count);
133 if (status == 0)
134 status = count;
135 } else
136 status = -EFAULT;
137 mutex_unlock(&spidev->buf_lock);
138
139 return status;
140}
141
142static int spidev_message(struct spidev_data *spidev,
143 struct spi_ioc_transfer *u_xfers, unsigned n_xfers)
144{
145 struct spi_message msg;
146 struct spi_transfer *k_xfers;
147 struct spi_transfer *k_tmp;
148 struct spi_ioc_transfer *u_tmp;
149 struct spi_device *spi = spidev->spi;
150 unsigned n, total;
151 u8 *buf;
152 int status = -EFAULT;
153
154 spi_message_init(&msg);
155 k_xfers = kcalloc(n_xfers, sizeof(*k_tmp), GFP_KERNEL);
156 if (k_xfers == NULL)
157 return -ENOMEM;
158
159 /* Construct spi_message, copying any tx data to bounce buffer.
160 * We walk the array of user-provided transfers, using each one
161 * to initialize a kernel version of the same transfer.
162 */
163 mutex_lock(&spidev->buf_lock);
164 buf = spidev->buffer;
165 total = 0;
166 for (n = n_xfers, k_tmp = k_xfers, u_tmp = u_xfers;
167 n;
168 n--, k_tmp++, u_tmp++) {
169 k_tmp->len = u_tmp->len;
170
171 if (u_tmp->rx_buf) {
172 k_tmp->rx_buf = buf;
173 if (!access_ok(VERIFY_WRITE, u_tmp->rx_buf, u_tmp->len))
174 goto done;
175 }
176 if (u_tmp->tx_buf) {
177 k_tmp->tx_buf = buf;
178 if (copy_from_user(buf, (const u8 __user *)u_tmp->tx_buf,
179 u_tmp->len))
180 goto done;
181 }
182
183 total += k_tmp->len;
184 if (total > bufsiz) {
185 status = -EMSGSIZE;
186 goto done;
187 }
188 buf += k_tmp->len;
189
190 k_tmp->cs_change = !!u_tmp->cs_change;
191 k_tmp->bits_per_word = u_tmp->bits_per_word;
192 k_tmp->delay_usecs = u_tmp->delay_usecs;
193 k_tmp->speed_hz = u_tmp->speed_hz;
194#ifdef VERBOSE
195 dev_dbg(&spi->dev,
196 " xfer len %zd %s%s%s%dbits %u usec %uHz\n",
197 u_tmp->len,
198 u_tmp->rx_buf ? "rx " : "",
199 u_tmp->tx_buf ? "tx " : "",
200 u_tmp->cs_change ? "cs " : "",
201 u_tmp->bits_per_word ? : spi->bits_per_word,
202 u_tmp->delay_usecs,
203 u_tmp->speed_hz ? : spi->max_speed_hz);
204#endif
205 spi_message_add_tail(k_tmp, &msg);
206 }
207
208 status = spi_sync(spi, &msg);
209 if (status < 0)
210 goto done;
211
212 /* copy any rx data out of bounce buffer */
213 buf = spidev->buffer;
214 for (n = n_xfers, u_tmp = u_xfers; n; n--, u_tmp++) {
215 if (u_tmp->rx_buf) {
216 if (__copy_to_user((u8 __user *)u_tmp->rx_buf, buf,
217 u_tmp->len)) {
218 status = -EFAULT;
219 goto done;
220 }
221 }
222 buf += u_tmp->len;
223 }
224 status = total;
225
226done:
227 mutex_unlock(&spidev->buf_lock);
228 kfree(k_xfers);
229 return status;
230}
231
232static int
233spidev_ioctl(struct inode *inode, struct file *filp,
234 unsigned int cmd, unsigned long arg)
235{
236 int err = 0;
237 int retval = 0;
238 struct spidev_data *spidev;
239 struct spi_device *spi;
240 u32 tmp;
241 unsigned n_ioc;
242 struct spi_ioc_transfer *ioc;
243
244 /* Check type and command number */
245 if (_IOC_TYPE(cmd) != SPI_IOC_MAGIC)
246 return -ENOTTY;
247
248 /* Check access direction once here; don't repeat below.
249 * IOC_DIR is from the user perspective, while access_ok is
250 * from the kernel perspective; so they look reversed.
251 */
252 if (_IOC_DIR(cmd) & _IOC_READ)
253 err = !access_ok(VERIFY_WRITE,
254 (void __user *)arg, _IOC_SIZE(cmd));
255 if (err == 0 && _IOC_DIR(cmd) & _IOC_WRITE)
256 err = !access_ok(VERIFY_READ,
257 (void __user *)arg, _IOC_SIZE(cmd));
258 if (err)
259 return -EFAULT;
260
261 spidev = filp->private_data;
262 spi = spidev->spi;
263
264 switch (cmd) {
265 /* read requests */
266 case SPI_IOC_RD_MODE:
267 retval = __put_user(spi->mode & SPI_MODE_MASK,
268 (__u8 __user *)arg);
269 break;
270 case SPI_IOC_RD_LSB_FIRST:
271 retval = __put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0,
272 (__u8 __user *)arg);
273 break;
274 case SPI_IOC_RD_BITS_PER_WORD:
275 retval = __put_user(spi->bits_per_word, (__u8 __user *)arg);
276 break;
277 case SPI_IOC_RD_MAX_SPEED_HZ:
278 retval = __put_user(spi->max_speed_hz, (__u32 __user *)arg);
279 break;
280
281 /* write requests */
282 case SPI_IOC_WR_MODE:
283 retval = __get_user(tmp, (u8 __user *)arg);
284 if (retval == 0) {
285 u8 save = spi->mode;
286
287 if (tmp & ~SPI_MODE_MASK) {
288 retval = -EINVAL;
289 break;
290 }
291
292 tmp |= spi->mode & ~SPI_MODE_MASK;
293 spi->mode = (u8)tmp;
294 retval = spi_setup(spi);
295 if (retval < 0)
296 spi->mode = save;
297 else
298 dev_dbg(&spi->dev, "spi mode %02x\n", tmp);
299 }
300 break;
301 case SPI_IOC_WR_LSB_FIRST:
302 retval = __get_user(tmp, (__u8 __user *)arg);
303 if (retval == 0) {
304 u8 save = spi->mode;
305
306 if (tmp)
307 spi->mode |= SPI_LSB_FIRST;
308 else
309 spi->mode &= ~SPI_LSB_FIRST;
310 retval = spi_setup(spi);
311 if (retval < 0)
312 spi->mode = save;
313 else
314 dev_dbg(&spi->dev, "%csb first\n",
315 tmp ? 'l' : 'm');
316 }
317 break;
318 case SPI_IOC_WR_BITS_PER_WORD:
319 retval = __get_user(tmp, (__u8 __user *)arg);
320 if (retval == 0) {
321 u8 save = spi->bits_per_word;
322
323 spi->bits_per_word = tmp;
324 retval = spi_setup(spi);
325 if (retval < 0)
326 spi->bits_per_word = save;
327 else
328 dev_dbg(&spi->dev, "%d bits per word\n", tmp);
329 }
330 break;
331 case SPI_IOC_WR_MAX_SPEED_HZ:
332 retval = __get_user(tmp, (__u32 __user *)arg);
333 if (retval == 0) {
334 u32 save = spi->max_speed_hz;
335
336 spi->max_speed_hz = tmp;
337 retval = spi_setup(spi);
338 if (retval < 0)
339 spi->max_speed_hz = save;
340 else
341 dev_dbg(&spi->dev, "%d Hz (max)\n", tmp);
342 }
343 break;
344
345 default:
346 /* segmented and/or full-duplex I/O request */
347 if (_IOC_NR(cmd) != _IOC_NR(SPI_IOC_MESSAGE(0))
348 || _IOC_DIR(cmd) != _IOC_WRITE)
349 return -ENOTTY;
350
351 tmp = _IOC_SIZE(cmd);
352 if ((tmp % sizeof(struct spi_ioc_transfer)) != 0) {
353 retval = -EINVAL;
354 break;
355 }
356 n_ioc = tmp / sizeof(struct spi_ioc_transfer);
357 if (n_ioc == 0)
358 break;
359
360 /* copy into scratch area */
361 ioc = kmalloc(tmp, GFP_KERNEL);
362 if (!ioc) {
363 retval = -ENOMEM;
364 break;
365 }
366 if (__copy_from_user(ioc, (void __user *)arg, tmp)) {
367 retval = -EFAULT;
368 break;
369 }
370
371 /* translate to spi_message, execute */
372 retval = spidev_message(spidev, ioc, n_ioc);
373 kfree(ioc);
374 break;
375 }
376 return retval;
377}
378
379static int spidev_open(struct inode *inode, struct file *filp)
380{
381 struct spidev_data *spidev;
382 int status = -ENXIO;
383
384 mutex_lock(&device_list_lock);
385
386 list_for_each_entry(spidev, &device_list, device_entry) {
387 if (spidev->dev.devt == inode->i_rdev) {
388 status = 0;
389 break;
390 }
391 }
392 if (status == 0) {
393 if (!spidev->buffer) {
394 spidev->buffer = kmalloc(bufsiz, GFP_KERNEL);
395 if (!spidev->buffer) {
396 dev_dbg(&spidev->spi->dev, "open/ENOMEM\n");
397 status = -ENOMEM;
398 }
399 }
400 if (status == 0) {
401 spidev->users++;
402 filp->private_data = spidev;
403 nonseekable_open(inode, filp);
404 }
405 } else
406 pr_debug("spidev: nothing for minor %d\n", iminor(inode));
407
408 mutex_unlock(&device_list_lock);
409 return status;
410}
411
412static int spidev_release(struct inode *inode, struct file *filp)
413{
414 struct spidev_data *spidev;
415 int status = 0;
416
417 mutex_lock(&device_list_lock);
418 spidev = filp->private_data;
419 filp->private_data = NULL;
420 spidev->users--;
421 if (!spidev->users) {
422 kfree(spidev->buffer);
423 spidev->buffer = NULL;
424 }
425 mutex_unlock(&device_list_lock);
426
427 return status;
428}
429
430static struct file_operations spidev_fops = {
431 .owner = THIS_MODULE,
432 /* REVISIT switch to aio primitives, so that userspace
433 * gets more complete API coverage. It'll simplify things
434 * too, except for the locking.
435 */
436 .write = spidev_write,
437 .read = spidev_read,
438 .ioctl = spidev_ioctl,
439 .open = spidev_open,
440 .release = spidev_release,
441};
442
443/*-------------------------------------------------------------------------*/
444
445/* The main reason to have this class is to make mdev/udev create the
446 * /dev/spidevB.C character device nodes exposing our userspace API.
447 * It also simplifies memory management.
448 */
449
450static void spidev_classdev_release(struct device *dev)
451{
452 struct spidev_data *spidev;
453
454 spidev = container_of(dev, struct spidev_data, dev);
455 kfree(spidev);
456}
457
458static struct class spidev_class = {
459 .name = "spidev",
460 .owner = THIS_MODULE,
461 .dev_release = spidev_classdev_release,
462};
463
464/*-------------------------------------------------------------------------*/
465
466static int spidev_probe(struct spi_device *spi)
467{
468 struct spidev_data *spidev;
469 int status;
470 unsigned long minor;
471
472 /* Allocate driver data */
473 spidev = kzalloc(sizeof(*spidev), GFP_KERNEL);
474 if (!spidev)
475 return -ENOMEM;
476
477 /* Initialize the driver data */
478 spidev->spi = spi;
479 mutex_init(&spidev->buf_lock);
480
481 INIT_LIST_HEAD(&spidev->device_entry);
482
483 /* If we can allocate a minor number, hook up this device.
484 * Reusing minors is fine so long as udev or mdev is working.
485 */
486 mutex_lock(&device_list_lock);
487 minor = find_first_zero_bit(minors, N_SPI_MINORS);
488 if (minor < N_SPI_MINORS) {
489 spidev->dev.parent = &spi->dev;
490 spidev->dev.class = &spidev_class;
491 spidev->dev.devt = MKDEV(SPIDEV_MAJOR, minor);
492 snprintf(spidev->dev.bus_id, sizeof spidev->dev.bus_id,
493 "spidev%d.%d",
494 spi->master->bus_num, spi->chip_select);
495 status = device_register(&spidev->dev);
496 } else {
497 dev_dbg(&spi->dev, "no minor number available!\n");
498 status = -ENODEV;
499 }
500 if (status == 0) {
501 set_bit(minor, minors);
502 dev_set_drvdata(&spi->dev, spidev);
503 list_add(&spidev->device_entry, &device_list);
504 }
505 mutex_unlock(&device_list_lock);
506
507 if (status != 0)
508 kfree(spidev);
509
510 return status;
511}
512
513static int spidev_remove(struct spi_device *spi)
514{
515 struct spidev_data *spidev = dev_get_drvdata(&spi->dev);
516
517 mutex_lock(&device_list_lock);
518
519 list_del(&spidev->device_entry);
520 dev_set_drvdata(&spi->dev, NULL);
521 clear_bit(MINOR(spidev->dev.devt), minors);
522 device_unregister(&spidev->dev);
523
524 mutex_unlock(&device_list_lock);
525
526 return 0;
527}
528
529static struct spi_driver spidev_spi = {
530 .driver = {
531 .name = "spidev",
532 .owner = THIS_MODULE,
533 },
534 .probe = spidev_probe,
535 .remove = __devexit_p(spidev_remove),
536
537 /* NOTE: suspend/resume methods are not necessary here.
538 * We don't do anything except pass the requests to/from
539 * the underlying controller. The refrigerator handles
540 * most issues; the controller driver handles the rest.
541 */
542};
543
544/*-------------------------------------------------------------------------*/
545
546static int __init spidev_init(void)
547{
548 int status;
549
550 /* Claim our 256 reserved device numbers. Then register a class
551 * that will key udev/mdev to add/remove /dev nodes. Last, register
552 * the driver which manages those device numbers.
553 */
554 BUILD_BUG_ON(N_SPI_MINORS > 256);
555 status = register_chrdev(SPIDEV_MAJOR, "spi", &spidev_fops);
556 if (status < 0)
557 return status;
558
559 status = class_register(&spidev_class);
560 if (status < 0) {
561 unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
562 return status;
563 }
564
565 status = spi_register_driver(&spidev_spi);
566 if (status < 0) {
567 class_unregister(&spidev_class);
568 unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
569 }
570 return status;
571}
572module_init(spidev_init);
573
574static void __exit spidev_exit(void)
575{
576 spi_unregister_driver(&spidev_spi);
577 class_unregister(&spidev_class);
578 unregister_chrdev(SPIDEV_MAJOR, spidev_spi.driver.name);
579}
580module_exit(spidev_exit);
581
582MODULE_AUTHOR("Andrea Paterniani, <a.paterniani@swapp-eng.it>");
583MODULE_DESCRIPTION("User mode SPI device interface");
584MODULE_LICENSE("GPL");
diff --git a/drivers/telephony/Kconfig b/drivers/telephony/Kconfig
index 7625b1816baf..dd1d6a53f3c0 100644
--- a/drivers/telephony/Kconfig
+++ b/drivers/telephony/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "Telephony Support" 5menu "Telephony Support"
6 depends on HAS_IOMEM
6 7
7config PHONE 8config PHONE
8 tristate "Linux telephony support" 9 tristate "Linux telephony support"
diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
index 71cb64e41a1b..c7b0a357b04a 100644
--- a/drivers/telephony/ixj.c
+++ b/drivers/telephony/ixj.c
@@ -7692,7 +7692,7 @@ static int __init ixj_probe_pci(int *cnt)
7692 IXJ *j = NULL; 7692 IXJ *j = NULL;
7693 7693
7694 for (i = 0; i < IXJMAX - *cnt; i++) { 7694 for (i = 0; i < IXJMAX - *cnt; i++) {
7695 pci = pci_find_device(PCI_VENDOR_ID_QUICKNET, 7695 pci = pci_get_device(PCI_VENDOR_ID_QUICKNET,
7696 PCI_DEVICE_ID_QUICKNET_XJ, pci); 7696 PCI_DEVICE_ID_QUICKNET_XJ, pci);
7697 if (!pci) 7697 if (!pci)
7698 break; 7698 break;
@@ -7712,6 +7712,7 @@ static int __init ixj_probe_pci(int *cnt)
7712 printk(KERN_INFO "ixj: found Internet PhoneJACK PCI at 0x%x\n", j->DSPbase); 7712 printk(KERN_INFO "ixj: found Internet PhoneJACK PCI at 0x%x\n", j->DSPbase);
7713 ++*cnt; 7713 ++*cnt;
7714 } 7714 }
7715 pci_dev_put(pci);
7715 return probe; 7716 return probe;
7716} 7717}
7717 7718
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index b847bbc8b0e1..15499b7e33f4 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -3,6 +3,7 @@
3# 3#
4 4
5menu "USB support" 5menu "USB support"
6 depends on HAS_IOMEM
6 7
7# Host-side USB depends on having a host controller 8# Host-side USB depends on having a host controller
8# NOTE: dummy_hcd is always an option, but it's ignored here ... 9# NOTE: dummy_hcd is always an option, but it's ignored here ...
@@ -87,8 +88,6 @@ source "drivers/usb/storage/Kconfig"
87 88
88source "drivers/usb/image/Kconfig" 89source "drivers/usb/image/Kconfig"
89 90
90source "drivers/usb/net/Kconfig"
91
92source "drivers/usb/mon/Kconfig" 91source "drivers/usb/mon/Kconfig"
93 92
94comment "USB port drivers" 93comment "USB port drivers"
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 0ef090b1b37c..72464b586990 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -23,13 +23,6 @@ obj-$(CONFIG_USB_PRINTER) += class/
23obj-$(CONFIG_USB_STORAGE) += storage/ 23obj-$(CONFIG_USB_STORAGE) += storage/
24obj-$(CONFIG_USB) += storage/ 24obj-$(CONFIG_USB) += storage/
25 25
26obj-$(CONFIG_USB_CATC) += net/
27obj-$(CONFIG_USB_KAWETH) += net/
28obj-$(CONFIG_USB_PEGASUS) += net/
29obj-$(CONFIG_USB_RTL8150) += net/
30obj-$(CONFIG_USB_USBNET) += net/
31obj-$(CONFIG_USB_ZD1201) += net/
32
33obj-$(CONFIG_USB_MDC800) += image/ 26obj-$(CONFIG_USB_MDC800) += image/
34obj-$(CONFIG_USB_MICROTEK) += image/ 27obj-$(CONFIG_USB_MICROTEK) += image/
35 28
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index b3f779f5933a..11e9b15ca45a 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -77,7 +77,6 @@
77#include <linux/sched.h> 77#include <linux/sched.h>
78#include <linux/signal.h> 78#include <linux/signal.h>
79#include <linux/slab.h> 79#include <linux/slab.h>
80#include <linux/smp_lock.h>
81#include <linux/stat.h> 80#include <linux/stat.h>
82#include <linux/timer.h> 81#include <linux/timer.h>
83#include <linux/wait.h> 82#include <linux/wait.h>
@@ -1034,7 +1033,7 @@ static int usbatm_do_heavy_init(void *arg)
1034 1033
1035static int usbatm_heavy_init(struct usbatm_data *instance) 1034static int usbatm_heavy_init(struct usbatm_data *instance)
1036{ 1035{
1037 int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_KERNEL); 1036 int ret = kernel_thread(usbatm_do_heavy_init, instance, CLONE_FS | CLONE_FILES);
1038 1037
1039 if (ret < 0) { 1038 if (ret < 0) {
1040 usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret); 1039 usb_err(instance, "%s: failed to create kernel_thread (%d)!\n", __func__, ret);
diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 14de3b1b6a20..0081c1d12687 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -59,7 +59,6 @@
59#include <linux/tty_driver.h> 59#include <linux/tty_driver.h>
60#include <linux/tty_flip.h> 60#include <linux/tty_flip.h>
61#include <linux/module.h> 61#include <linux/module.h>
62#include <linux/smp_lock.h>
63#include <linux/mutex.h> 62#include <linux/mutex.h>
64#include <asm/uaccess.h> 63#include <asm/uaccess.h>
65#include <linux/usb.h> 64#include <linux/usb.h>
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 6584cf00f7f3..15e740e3a5c4 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -49,7 +49,6 @@
49#include <linux/module.h> 49#include <linux/module.h>
50#include <linux/kernel.h> 50#include <linux/kernel.h>
51#include <linux/sched.h> 51#include <linux/sched.h>
52#include <linux/smp_lock.h>
53#include <linux/signal.h> 52#include <linux/signal.h>
54#include <linux/poll.h> 53#include <linux/poll.h>
55#include <linux/init.h> 54#include <linux/init.h>
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index bde29ab2b504..f6b74a678de5 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -16,7 +16,6 @@
16#include <linux/sched.h> 16#include <linux/sched.h>
17#include <linux/list.h> 17#include <linux/list.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/smp_lock.h>
20#include <linux/ioctl.h> 19#include <linux/ioctl.h>
21#include <linux/usb.h> 20#include <linux/usb.h>
22#include <linux/usbdevice_fs.h> 21#include <linux/usbdevice_fs.h>
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index cddfc62c4611..cd4f11157280 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -36,7 +36,6 @@
36#include <linux/usb.h> 36#include <linux/usb.h>
37#include <linux/namei.h> 37#include <linux/namei.h>
38#include <linux/usbdevice_fs.h> 38#include <linux/usbdevice_fs.h>
39#include <linux/smp_lock.h>
40#include <linux/parser.h> 39#include <linux/parser.h>
41#include <linux/notifier.h> 40#include <linux/notifier.h>
42#include <asm/byteorder.h> 41#include <asm/byteorder.h>
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index dfd1b5c87ca3..18ddc5e67e39 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -31,7 +31,6 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/spinlock.h> 32#include <linux/spinlock.h>
33#include <linux/errno.h> 33#include <linux/errno.h>
34#include <linux/smp_lock.h>
35#include <linux/usb.h> 34#include <linux/usb.h>
36#include <linux/mutex.h> 35#include <linux/mutex.h>
37#include <linux/workqueue.h> 36#include <linux/workqueue.h>
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index 8065f2b53701..f771a7cae9ec 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -210,7 +210,7 @@ config USB_OTG
210 210
211config USB_GADGET_AT91 211config USB_GADGET_AT91
212 boolean "AT91 USB Device Port" 212 boolean "AT91 USB Device Port"
213 depends on ARCH_AT91 213 depends on ARCH_AT91 && !ARCH_AT91SAM9RL
214 select USB_GADGET_SELECTED 214 select USB_GADGET_SELECTED
215 help 215 help
216 Many Atmel AT91 processors (such as the AT91RM2000) have a 216 Many Atmel AT91 processors (such as the AT91RM2000) have a
diff --git a/drivers/usb/gadget/at91_udc.c b/drivers/usb/gadget/at91_udc.c
index 2a6e3163d944..ba163f35bf21 100644
--- a/drivers/usb/gadget/at91_udc.c
+++ b/drivers/usb/gadget/at91_udc.c
@@ -31,7 +31,6 @@
31#include <linux/delay.h> 31#include <linux/delay.h>
32#include <linux/ioport.h> 32#include <linux/ioport.h>
33#include <linux/slab.h> 33#include <linux/slab.h>
34#include <linux/smp_lock.h>
35#include <linux/errno.h> 34#include <linux/errno.h>
36#include <linux/init.h> 35#include <linux/init.h>
37#include <linux/list.h> 36#include <linux/list.h>
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 7d7909cf2558..fcb5526cb085 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -41,7 +41,6 @@
41#include <linux/delay.h> 41#include <linux/delay.h>
42#include <linux/ioport.h> 42#include <linux/ioport.h>
43#include <linux/slab.h> 43#include <linux/slab.h>
44#include <linux/smp_lock.h>
45#include <linux/errno.h> 44#include <linux/errno.h>
46#include <linux/init.h> 45#include <linux/init.h>
47#include <linux/timer.h> 46#include <linux/timer.h>
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 1dd8b57f4420..325bf7cfb83f 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -28,7 +28,6 @@
28#include <linux/delay.h> 28#include <linux/delay.h>
29#include <linux/ioport.h> 29#include <linux/ioport.h>
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/smp_lock.h>
32#include <linux/errno.h> 31#include <linux/errno.h>
33#include <linux/init.h> 32#include <linux/init.h>
34#include <linux/timer.h> 33#include <linux/timer.h>
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 65c91d3735de..ae931af05cef 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -30,7 +30,6 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/ioport.h> 31#include <linux/ioport.h>
32#include <linux/slab.h> 32#include <linux/slab.h>
33#include <linux/smp_lock.h>
34#include <linux/errno.h> 33#include <linux/errno.h>
35#include <linux/init.h> 34#include <linux/init.h>
36#include <linux/timer.h> 35#include <linux/timer.h>
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 49d737725f70..52779c52b56d 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -54,7 +54,6 @@
54#include <linux/delay.h> 54#include <linux/delay.h>
55#include <linux/ioport.h> 55#include <linux/ioport.h>
56#include <linux/slab.h> 56#include <linux/slab.h>
57#include <linux/smp_lock.h>
58#include <linux/errno.h> 57#include <linux/errno.h>
59#include <linux/init.h> 58#include <linux/init.h>
60#include <linux/timer.h> 59#include <linux/timer.h>
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index e552668d36b3..f847c3414be3 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -22,7 +22,6 @@
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/ioport.h> 23#include <linux/ioport.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/smp_lock.h>
26#include <linux/errno.h> 25#include <linux/errno.h>
27#include <linux/init.h> 26#include <linux/init.h>
28#include <linux/timer.h> 27#include <linux/timer.h>
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 8c85e33f74a4..7078374d0b79 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -67,7 +67,6 @@
67#include <linux/delay.h> 67#include <linux/delay.h>
68#include <linux/ioport.h> 68#include <linux/ioport.h>
69#include <linux/slab.h> 69#include <linux/slab.h>
70#include <linux/smp_lock.h>
71#include <linux/errno.h> 70#include <linux/errno.h>
72#include <linux/init.h> 71#include <linux/init.h>
73#include <linux/timer.h> 72#include <linux/timer.h>
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index c7458f7e56cc..099aff64f536 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -24,7 +24,6 @@
24#include <linux/ioport.h> 24#include <linux/ioport.h>
25#include <linux/sched.h> 25#include <linux/sched.h>
26#include <linux/slab.h> 26#include <linux/slab.h>
27#include <linux/smp_lock.h>
28#include <linux/errno.h> 27#include <linux/errno.h>
29#include <linux/init.h> 28#include <linux/init.h>
30#include <linux/timer.h> 29#include <linux/timer.h>
diff --git a/drivers/usb/host/ehci-ps3.c b/drivers/usb/host/ehci-ps3.c
index 93107453f124..37b83ba09969 100644
--- a/drivers/usb/host/ehci-ps3.c
+++ b/drivers/usb/host/ehci-ps3.c
@@ -97,7 +97,7 @@ static int ps3_ehci_sb_probe(struct ps3_system_bus_device *dev)
97 dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__, 97 dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
98 __LINE__, dev->m_region->lpar_addr); 98 __LINE__, dev->m_region->lpar_addr);
99 99
100 result = ps3_alloc_io_irq(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq); 100 result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
101 101
102 if (result) { 102 if (result) {
103 dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n", 103 dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
@@ -155,7 +155,7 @@ fail_add_hcd:
155fail_ioremap: 155fail_ioremap:
156 usb_put_hcd(hcd); 156 usb_put_hcd(hcd);
157fail_create_hcd: 157fail_create_hcd:
158 ps3_free_io_irq(virq); 158 ps3_io_irq_destroy(virq);
159fail_irq: 159fail_irq:
160 ps3_free_mmio_region(dev->m_region); 160 ps3_free_mmio_region(dev->m_region);
161fail_mmio: 161fail_mmio:
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index e8bbe8bc2598..a66637e725f3 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -26,7 +26,6 @@
26#include <linux/ioport.h> 26#include <linux/ioport.h>
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/smp_lock.h>
30#include <linux/errno.h> 29#include <linux/errno.h>
31#include <linux/init.h> 30#include <linux/init.h>
32#include <linux/timer.h> 31#include <linux/timer.h>
diff --git a/drivers/usb/host/ohci-ppc-of.c b/drivers/usb/host/ohci-ppc-of.c
index 08e237c7bc43..c43b66acd4d5 100644
--- a/drivers/usb/host/ohci-ppc-of.c
+++ b/drivers/usb/host/ohci-ppc-of.c
@@ -97,8 +97,8 @@ ohci_hcd_ppc_of_probe(struct of_device *op, const struct of_device_id *match)
97 return -ENODEV; 97 return -ENODEV;
98 98
99 is_bigendian = 99 is_bigendian =
100 device_is_compatible(dn, "ohci-bigendian") || 100 of_device_is_compatible(dn, "ohci-bigendian") ||
101 device_is_compatible(dn, "ohci-be"); 101 of_device_is_compatible(dn, "ohci-be");
102 102
103 dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n"); 103 dev_dbg(&op->dev, "initializing PPC-OF USB Controller\n");
104 104
diff --git a/drivers/usb/host/ohci-ps3.c b/drivers/usb/host/ohci-ps3.c
index c849f72b508a..d7cf07288b0b 100644
--- a/drivers/usb/host/ohci-ps3.c
+++ b/drivers/usb/host/ohci-ps3.c
@@ -99,7 +99,7 @@ static int ps3_ohci_sb_probe(struct ps3_system_bus_device *dev)
99 dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__, 99 dev_dbg(&dev->core, "%s:%d: mmio mapped_addr %lxh\n", __func__,
100 __LINE__, dev->m_region->lpar_addr); 100 __LINE__, dev->m_region->lpar_addr);
101 101
102 result = ps3_alloc_io_irq(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq); 102 result = ps3_io_irq_setup(PS3_BINDING_CPU_ANY, dev->interrupt_id, &virq);
103 103
104 if (result) { 104 if (result) {
105 dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n", 105 dev_dbg(&dev->core, "%s:%d: ps3_construct_io_irq(%d) failed.\n",
@@ -157,7 +157,7 @@ fail_add_hcd:
157fail_ioremap: 157fail_ioremap:
158 usb_put_hcd(hcd); 158 usb_put_hcd(hcd);
159fail_create_hcd: 159fail_create_hcd:
160 ps3_free_io_irq(virq); 160 ps3_io_irq_destroy(virq);
161fail_irq: 161fail_irq:
162 ps3_free_mmio_region(dev->m_region); 162 ps3_free_mmio_region(dev->m_region);
163fail_mmio: 163fail_mmio:
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 5fa5647ea095..4cfa3ff2c993 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -38,7 +38,6 @@
38#include <linux/ioport.h> 38#include <linux/ioport.h>
39#include <linux/sched.h> 39#include <linux/sched.h>
40#include <linux/slab.h> 40#include <linux/slab.h>
41#include <linux/smp_lock.h>
42#include <linux/errno.h> 41#include <linux/errno.h>
43#include <linux/init.h> 42#include <linux/init.h>
44#include <linux/timer.h> 43#include <linux/timer.h>
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index a7fa0d75567d..ff0dba01f1c7 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -43,7 +43,6 @@
43#include <linux/pci_ids.h> 43#include <linux/pci_ids.h>
44#include <linux/sched.h> 44#include <linux/sched.h>
45#include <linux/slab.h> 45#include <linux/slab.h>
46#include <linux/smp_lock.h>
47#include <linux/errno.h> 46#include <linux/errno.h>
48#include <linux/init.h> 47#include <linux/init.h>
49#include <linux/timer.h> 48#include <linux/timer.h>
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index d308afd06935..36502a06f73a 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -94,7 +94,6 @@
94#include <linux/init.h> 94#include <linux/init.h>
95#include <linux/slab.h> 95#include <linux/slab.h>
96#include <linux/module.h> 96#include <linux/module.h>
97#include <linux/smp_lock.h>
98#include <linux/wait.h> 97#include <linux/wait.h>
99#include <linux/mutex.h> 98#include <linux/mutex.h>
100 99
diff --git a/drivers/usb/image/microtek.c b/drivers/usb/image/microtek.c
index 896cb2b71020..51bd80d2b8cc 100644
--- a/drivers/usb/image/microtek.c
+++ b/drivers/usb/image/microtek.c
@@ -128,7 +128,6 @@
128#include <linux/init.h> 128#include <linux/init.h>
129#include <linux/slab.h> 129#include <linux/slab.h>
130#include <linux/spinlock.h> 130#include <linux/spinlock.h>
131#include <linux/smp_lock.h>
132#include <linux/usb.h> 131#include <linux/usb.h>
133#include <linux/proc_fs.h> 132#include <linux/proc_fs.h>
134 133
diff --git a/drivers/usb/misc/auerswald.c b/drivers/usb/misc/auerswald.c
index b5332e679c46..88fb56d5db8f 100644
--- a/drivers/usb/misc/auerswald.c
+++ b/drivers/usb/misc/auerswald.c
@@ -1307,7 +1307,7 @@ static int auerswald_addservice (pauerswald_t cp, pauerscon_t scp)
1307} 1307}
1308 1308
1309 1309
1310/* remove a service from the the device 1310/* remove a service from the device
1311 scp->id must be set! */ 1311 scp->id must be set! */
1312static void auerswald_removeservice (pauerswald_t cp, pauerscon_t scp) 1312static void auerswald_removeservice (pauerswald_t cp, pauerscon_t scp)
1313{ 1313{
diff --git a/drivers/usb/misc/idmouse.c b/drivers/usb/misc/idmouse.c
index 15c70bd048c4..8d0e360636e6 100644
--- a/drivers/usb/misc/idmouse.c
+++ b/drivers/usb/misc/idmouse.c
@@ -22,7 +22,6 @@
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/slab.h> 23#include <linux/slab.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/smp_lock.h>
26#include <linux/completion.h> 25#include <linux/completion.h>
27#include <linux/mutex.h> 26#include <linux/mutex.h>
28#include <asm/uaccess.h> 27#include <asm/uaccess.h>
diff --git a/drivers/usb/misc/legousbtower.c b/drivers/usb/misc/legousbtower.c
index 5dce797bddb7..1713e19a7899 100644
--- a/drivers/usb/misc/legousbtower.c
+++ b/drivers/usb/misc/legousbtower.c
@@ -80,7 +80,6 @@
80#include <linux/init.h> 80#include <linux/init.h>
81#include <linux/slab.h> 81#include <linux/slab.h>
82#include <linux/module.h> 82#include <linux/module.h>
83#include <linux/smp_lock.h>
84#include <linux/completion.h> 83#include <linux/completion.h>
85#include <linux/mutex.h> 84#include <linux/mutex.h>
86#include <asm/uaccess.h> 85#include <asm/uaccess.h>
diff --git a/drivers/usb/misc/rio500.c b/drivers/usb/misc/rio500.c
index fdf68479a166..88f6abe73624 100644
--- a/drivers/usb/misc/rio500.c
+++ b/drivers/usb/misc/rio500.c
@@ -39,7 +39,6 @@
39#include <linux/slab.h> 39#include <linux/slab.h>
40#include <linux/spinlock.h> 40#include <linux/spinlock.h>
41#include <linux/usb.h> 41#include <linux/usb.h>
42#include <linux/smp_lock.h>
43#include <linux/wait.h> 42#include <linux/wait.h>
44 43
45#include "rio500_usb.h" 44#include "rio500_usb.h"
diff --git a/drivers/usb/misc/sisusbvga/sisusb_con.c b/drivers/usb/misc/sisusbvga/sisusb_con.c
index 1730d8642a47..5947afb0017e 100644
--- a/drivers/usb/misc/sisusbvga/sisusb_con.c
+++ b/drivers/usb/misc/sisusbvga/sisusb_con.c
@@ -62,7 +62,6 @@
62#include <linux/selection.h> 62#include <linux/selection.h>
63#include <linux/spinlock.h> 63#include <linux/spinlock.h>
64#include <linux/kref.h> 64#include <linux/kref.h>
65#include <linux/smp_lock.h>
66#include <linux/ioport.h> 65#include <linux/ioport.h>
67#include <linux/interrupt.h> 66#include <linux/interrupt.h>
68#include <linux/vmalloc.h> 67#include <linux/vmalloc.h>
@@ -322,7 +321,7 @@ sisusbcon_deinit(struct vc_data *c)
322/* interface routine */ 321/* interface routine */
323static u8 322static u8
324sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity, 323sisusbcon_build_attr(struct vc_data *c, u8 color, u8 intensity,
325 u8 blink, u8 underline, u8 reverse) 324 u8 blink, u8 underline, u8 reverse, u8 unused)
326{ 325{
327 u8 attr = color; 326 u8 attr = color;
328 327
diff --git a/drivers/usb/mon/mon_main.c b/drivers/usb/mon/mon_main.c
index 8a1df2c9c73e..8977ec0d0f99 100644
--- a/drivers/usb/mon/mon_main.c
+++ b/drivers/usb/mon/mon_main.c
@@ -9,7 +9,6 @@
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/usb.h> 11#include <linux/usb.h>
12#include <linux/smp_lock.h>
13#include <linux/notifier.h> 12#include <linux/notifier.h>
14#include <linux/mutex.h> 13#include <linux/mutex.h>
15 14
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index ba5d1dc03036..3efe67092f15 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -558,7 +558,7 @@ config USB_SERIAL_DEBUG
558 tristate "USB Debugging Device" 558 tristate "USB Debugging Device"
559 depends on USB_SERIAL 559 depends on USB_SERIAL
560 help 560 help
561 Say Y here if you have a USB debugging device used to recieve 561 Say Y here if you have a USB debugging device used to receive
562 debugging data from another machine. The most common of these 562 debugging data from another machine. The most common of these
563 devices is the NetChip TurboCONNECT device. 563 devices is the NetChip TurboCONNECT device.
564 564
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index b675735bfbee..fbc8c27d5d99 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -9,7 +9,7 @@
9 * The device works as an standard CDC device, it has 2 interfaces, the first 9 * The device works as an standard CDC device, it has 2 interfaces, the first
10 * one is for firmware access and the second is the serial one. 10 * one is for firmware access and the second is the serial one.
11 * The protocol is very simply, there are two posibilities reading or writing. 11 * The protocol is very simply, there are two posibilities reading or writing.
12 * When writting the first urb must have a Header that starts with 0x20 0x29 the 12 * When writing the first urb must have a Header that starts with 0x20 0x29 the
13 * next two bytes must say how much data will be sended. 13 * next two bytes must say how much data will be sended.
14 * When reading the process is almost equal except that the header starts with 14 * When reading the process is almost equal except that the header starts with
15 * 0x00 0x20. 15 * 0x00 0x20.
@@ -18,7 +18,7 @@
18 * buffer: The First and Second byte is used for a Header, the Third and Fourth 18 * buffer: The First and Second byte is used for a Header, the Third and Fourth
19 * tells the device the amount of information the package holds. 19 * tells the device the amount of information the package holds.
20 * Packages are 60 bytes long Header Stuff. 20 * Packages are 60 bytes long Header Stuff.
21 * When writting to the device the first two bytes of the header are 0x20 0x29 21 * When writing to the device the first two bytes of the header are 0x20 0x29
22 * When reading the bytes are 0x00 0x20, or 0x00 0x10, there is an strange 22 * When reading the bytes are 0x00 0x20, or 0x00 0x10, there is an strange
23 * situation, when too much data arrives to the device because it sends the data 23 * situation, when too much data arrives to the device because it sends the data
24 * but with out the header. I will use a simply hack to override this situation, 24 * but with out the header. I will use a simply hack to override this situation,
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index 18f74ac76565..4807f960150b 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -2465,7 +2465,7 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r
2465 ((edge_serial->is_epic) && 2465 ((edge_serial->is_epic) &&
2466 (!edge_serial->epic_descriptor.Supports.IOSPWriteMCR) && 2466 (!edge_serial->epic_descriptor.Supports.IOSPWriteMCR) &&
2467 (regNum == MCR))) { 2467 (regNum == MCR))) {
2468 dbg("SendCmdWriteUartReg - Not writting to MCR Register"); 2468 dbg("SendCmdWriteUartReg - Not writing to MCR Register");
2469 return 0; 2469 return 0;
2470 } 2470 }
2471 2471
@@ -2473,7 +2473,7 @@ static int send_cmd_write_uart_register (struct edgeport_port *edge_port, __u8 r
2473 ((edge_serial->is_epic) && 2473 ((edge_serial->is_epic) &&
2474 (!edge_serial->epic_descriptor.Supports.IOSPWriteLCR) && 2474 (!edge_serial->epic_descriptor.Supports.IOSPWriteLCR) &&
2475 (regNum == LCR))) { 2475 (regNum == LCR))) {
2476 dbg ("SendCmdWriteUartReg - Not writting to LCR Register"); 2476 dbg ("SendCmdWriteUartReg - Not writing to LCR Register");
2477 return 0; 2477 return 0;
2478 } 2478 }
2479 2479
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 7639022cdf84..87f378806db6 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -28,7 +28,6 @@
28#include <linux/spinlock.h> 28#include <linux/spinlock.h>
29#include <linux/mutex.h> 29#include <linux/mutex.h>
30#include <linux/list.h> 30#include <linux/list.h>
31#include <linux/smp_lock.h>
32#include <asm/uaccess.h> 31#include <asm/uaccess.h>
33#include <linux/usb.h> 32#include <linux/usb.h>
34#include <linux/usb/serial.h> 33#include <linux/usb/serial.h>
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 21f3ddbc9080..6dac1ffdde86 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -47,7 +47,6 @@
47#include <linux/usb.h> 47#include <linux/usb.h>
48#include <linux/usb_usual.h> 48#include <linux/usb_usual.h>
49#include <linux/blkdev.h> 49#include <linux/blkdev.h>
50#include <linux/smp_lock.h>
51#include <linux/completion.h> 50#include <linux/completion.h>
52#include <linux/mutex.h> 51#include <linux/mutex.h>
53#include <scsi/scsi_host.h> 52#include <scsi/scsi_host.h>
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 344c37595305..4d7485fa553f 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -3,8 +3,14 @@
3# 3#
4 4
5menu "Graphics support" 5menu "Graphics support"
6 depends on HAS_IOMEM
6 7
7source "drivers/video/backlight/Kconfig" 8source "drivers/video/backlight/Kconfig"
9source "drivers/video/display/Kconfig"
10
11config VGASTATE
12 tristate
13 default n
8 14
9config FB 15config FB
10 tristate "Support for frame buffer devices" 16 tristate "Support for frame buffer devices"
@@ -90,6 +96,43 @@ config FB_CFB_IMAGEBLIT
90 blitting. This is used by drivers that don't provide their own 96 blitting. This is used by drivers that don't provide their own
91 (accelerated) version. 97 (accelerated) version.
92 98
99config FB_SYS_FILLRECT
100 tristate
101 depends on FB
102 default n
103 ---help---
104 Include the sys_fillrect function for generic software rectangle
105 filling. This is used by drivers that don't provide their own
106 (accelerated) version and the framebuffer is in system RAM.
107
108config FB_SYS_COPYAREA
109 tristate
110 depends on FB
111 default n
112 ---help---
113 Include the sys_copyarea function for generic software area copying.
114 This is used by drivers that don't provide their own (accelerated)
115 version and the framebuffer is in system RAM.
116
117config FB_SYS_IMAGEBLIT
118 tristate
119 depends on FB
120 default n
121 ---help---
122 Include the sys_imageblit function for generic software image
123 blitting. This is used by drivers that don't provide their own
124 (accelerated) version and the framebuffer is in system RAM.
125
126config FB_SYS_FOPS
127 tristate
128 depends on FB
129 default n
130
131config FB_DEFERRED_IO
132 bool
133 depends on FB
134 default y
135
93config FB_SVGALIB 136config FB_SVGALIB
94 tristate 137 tristate
95 depends on FB 138 depends on FB
@@ -375,9 +418,10 @@ config FB_FM2
375config FB_ARC 418config FB_ARC
376 tristate "Arc Monochrome LCD board support" 419 tristate "Arc Monochrome LCD board support"
377 depends on FB && X86 420 depends on FB && X86
378 select FB_CFB_FILLRECT 421 select FB_SYS_FILLRECT
379 select FB_CFB_COPYAREA 422 select FB_SYS_COPYAREA
380 select FB_CFB_IMAGEBLIT 423 select FB_SYS_IMAGEBLIT
424 select FB_SYS_FOPS
381 help 425 help
382 This enables support for the Arc Monochrome LCD board. The board 426 This enables support for the Arc Monochrome LCD board. The board
383 is based on the KS-108 lcd controller and is typically a matrix 427 is based on the KS-108 lcd controller and is typically a matrix
@@ -475,6 +519,8 @@ config FB_VGA16
475 select FB_CFB_FILLRECT 519 select FB_CFB_FILLRECT
476 select FB_CFB_COPYAREA 520 select FB_CFB_COPYAREA
477 select FB_CFB_IMAGEBLIT 521 select FB_CFB_IMAGEBLIT
522 select VGASTATE
523 select FONT_8x16 if FRAMEBUFFER_CONSOLE
478 help 524 help
479 This is the frame buffer device driver for VGA 16 color graphic 525 This is the frame buffer device driver for VGA 16 color graphic
480 cards. Say Y if you have such a card. 526 cards. Say Y if you have such a card.
@@ -519,15 +565,25 @@ config FB_HP300
519 default y 565 default y
520 566
521config FB_TGA 567config FB_TGA
522 tristate "TGA framebuffer support" 568 tristate "TGA/SFB+ framebuffer support"
523 depends on FB && ALPHA 569 depends on FB && (ALPHA || TC)
524 select FB_CFB_FILLRECT 570 select FB_CFB_FILLRECT
525 select FB_CFB_COPYAREA 571 select FB_CFB_COPYAREA
526 select FB_CFB_IMAGEBLIT 572 select FB_CFB_IMAGEBLIT
527 select BITREVERSE 573 select BITREVERSE
528 help 574 ---help---
529 This is the frame buffer device driver for generic TGA graphic 575 This is the frame buffer device driver for generic TGA and SFB+
530 cards. Say Y if you have one of those. 576 graphic cards. These include DEC ZLXp-E1, -E2 and -E3 PCI cards,
577 also known as PBXGA-A, -B and -C, and DEC ZLX-E1, -E2 and -E3
578 TURBOchannel cards, also known as PMAGD-A, -B and -C.
579
580 Due to hardware limitations ZLX-E2 and E3 cards are not supported
581 for DECstation 5000/200 systems. Additionally due to firmware
582 limitations these cards may cause troubles with booting DECstation
583 5000/240 and /260 systems, but are fully supported under Linux if
584 you manage to get it going. ;-)
585
586 Say Y if you have one of those.
531 587
532config FB_VESA 588config FB_VESA
533 bool "VESA VGA graphics support" 589 bool "VESA VGA graphics support"
@@ -551,6 +607,21 @@ config FB_IMAC
551 help 607 help
552 This is the frame buffer device driver for the Intel-based Macintosh 608 This is the frame buffer device driver for the Intel-based Macintosh
553 609
610config FB_HECUBA
611 tristate "Hecuba board support"
612 depends on FB && X86 && MMU
613 select FB_SYS_FILLRECT
614 select FB_SYS_COPYAREA
615 select FB_SYS_IMAGEBLIT
616 select FB_SYS_FOPS
617 select FB_DEFERRED_IO
618 help
619 This enables support for the Hecuba board. This driver was tested
620 with an E-Ink 800x600 display and x86 SBCs through a 16 bit GPIO
621 interface (8 bit data, 4 bit control). If you anticpate using
622 this driver, say Y or M; otherwise say N. You must specify the
623 GPIO IO address to be used for setting control and data.
624
554config FB_HGA 625config FB_HGA
555 tristate "Hercules mono graphics support" 626 tristate "Hercules mono graphics support"
556 depends on FB && X86 627 depends on FB && X86
@@ -677,6 +748,22 @@ config FB_S1D13XXX
677 working with S1D13806). Product specs at 748 working with S1D13806). Product specs at
678 <http://www.erd.epson.com/vdc/html/legacy_13xxx.htm> 749 <http://www.erd.epson.com/vdc/html/legacy_13xxx.htm>
679 750
751config FB_ATMEL
752 tristate "AT91/AT32 LCD Controller support"
753 depends on FB && (ARCH_AT91SAM9261 || ARCH_AT91SAM9263 || AVR32)
754 select FB_CFB_FILLRECT
755 select FB_CFB_COPYAREA
756 select FB_CFB_IMAGEBLIT
757 help
758 This enables support for the AT91/AT32 LCD Controller.
759
760config FB_INTSRAM
761 bool "Frame Buffer in internal SRAM"
762 depends on FB_ATMEL && ARCH_AT91SAM9261
763 help
764 Say Y if you want to map Frame Buffer in internal SRAM. Say N if you want
765 to let frame buffer in external SDRAM.
766
680config FB_NVIDIA 767config FB_NVIDIA
681 tristate "nVidia Framebuffer Support" 768 tristate "nVidia Framebuffer Support"
682 depends on FB && PCI 769 depends on FB && PCI
@@ -686,6 +773,7 @@ config FB_NVIDIA
686 select FB_CFB_COPYAREA 773 select FB_CFB_COPYAREA
687 select FB_CFB_IMAGEBLIT 774 select FB_CFB_IMAGEBLIT
688 select BITREVERSE 775 select BITREVERSE
776 select VGASTATE
689 help 777 help
690 This driver supports graphics boards with the nVidia chips, TNT 778 This driver supports graphics boards with the nVidia chips, TNT
691 and newer. For very old chipsets, such as the RIVA128, then use 779 and newer. For very old chipsets, such as the RIVA128, then use
@@ -708,6 +796,15 @@ config FB_NVIDIA_I2C
708 independently validate video mode parameters, you should say Y 796 independently validate video mode parameters, you should say Y
709 here. 797 here.
710 798
799config FB_NVIDIA_DEBUG
800 bool "Lots of debug output"
801 depends on FB_NVIDIA
802 default n
803 help
804 Say Y here if you want the nVidia driver to output all sorts
805 of debugging information to provide to the maintainer when
806 something goes wrong.
807
711config FB_NVIDIA_BACKLIGHT 808config FB_NVIDIA_BACKLIGHT
712 bool "Support for backlight control" 809 bool "Support for backlight control"
713 depends on FB_NVIDIA 810 depends on FB_NVIDIA
@@ -724,6 +821,7 @@ config FB_RIVA
724 select FB_CFB_COPYAREA 821 select FB_CFB_COPYAREA
725 select FB_CFB_IMAGEBLIT 822 select FB_CFB_IMAGEBLIT
726 select BITREVERSE 823 select BITREVERSE
824 select VGASTATE
727 help 825 help
728 This driver supports graphics boards with the nVidia Riva/Geforce 826 This driver supports graphics boards with the nVidia Riva/Geforce
729 chips. 827 chips.
@@ -746,7 +844,7 @@ config FB_RIVA_I2C
746 here. 844 here.
747 845
748config FB_RIVA_DEBUG 846config FB_RIVA_DEBUG
749 bool "Lots of debug output from Riva(nVidia) driver" 847 bool "Lots of debug output"
750 depends on FB_RIVA 848 depends on FB_RIVA
751 default n 849 default n
752 help 850 help
@@ -770,6 +868,7 @@ config FB_I810
770 select FB_CFB_FILLRECT 868 select FB_CFB_FILLRECT
771 select FB_CFB_COPYAREA 869 select FB_CFB_COPYAREA
772 select FB_CFB_IMAGEBLIT 870 select FB_CFB_IMAGEBLIT
871 select VGASTATE
773 help 872 help
774 This driver supports the on-board graphics built in to the Intel 810 873 This driver supports the on-board graphics built in to the Intel 810
775 and 815 chipsets. Say Y if you have and plan to use such a board. 874 and 815 chipsets. Say Y if you have and plan to use such a board.
@@ -809,6 +908,22 @@ config FB_I810_I2C
809 select FB_DDC 908 select FB_DDC
810 help 909 help
811 910
911config FB_LE80578
912 tristate "Intel LE80578 (Vermilion) support"
913 depends on FB && PCI && X86
914 select FB_MODE_HELPERS
915 select FB_CFB_FILLRECT
916 select FB_CFB_COPYAREA
917 select FB_CFB_IMAGEBLIT
918 help
919 This driver supports the LE80578 (Vermilion Range) chipset
920
921config FB_CARILLO_RANCH
922 tristate "Intel Carillo Ranch support"
923 depends on FB_LE80578 && FB && PCI && X86
924 help
925 This driver supports the LE80578 (Carillo Ranch) board
926
812config FB_INTEL 927config FB_INTEL
813 tristate "Intel 830M/845G/852GM/855GM/865G/915G/945G support (EXPERIMENTAL)" 928 tristate "Intel 830M/845G/852GM/855GM/865G/915G/945G support (EXPERIMENTAL)"
814 depends on FB && EXPERIMENTAL && PCI && X86 929 depends on FB && EXPERIMENTAL && PCI && X86
@@ -1120,6 +1235,8 @@ config FB_S3
1120 select FB_CFB_IMAGEBLIT 1235 select FB_CFB_IMAGEBLIT
1121 select FB_TILEBLITTING 1236 select FB_TILEBLITTING
1122 select FB_SVGALIB 1237 select FB_SVGALIB
1238 select VGASTATE
1239 select FONT_8x16 if FRAMEBUFFER_CONSOLE
1123 ---help--- 1240 ---help---
1124 Driver for graphics boards with S3 Trio / S3 Virge chip. 1241 Driver for graphics boards with S3 Trio / S3 Virge chip.
1125 1242
@@ -1130,6 +1247,7 @@ config FB_SAVAGE
1130 select FB_CFB_FILLRECT 1247 select FB_CFB_FILLRECT
1131 select FB_CFB_COPYAREA 1248 select FB_CFB_COPYAREA
1132 select FB_CFB_IMAGEBLIT 1249 select FB_CFB_IMAGEBLIT
1250 select VGASTATE
1133 help 1251 help
1134 This driver supports notebooks and computers with S3 Savage PCI/AGP 1252 This driver supports notebooks and computers with S3 Savage PCI/AGP
1135 chips. 1253 chips.
@@ -1196,6 +1314,7 @@ config FB_NEOMAGIC
1196 select FB_CFB_FILLRECT 1314 select FB_CFB_FILLRECT
1197 select FB_CFB_COPYAREA 1315 select FB_CFB_COPYAREA
1198 select FB_CFB_IMAGEBLIT 1316 select FB_CFB_IMAGEBLIT
1317 select VGASTATE
1199 help 1318 help
1200 This driver supports notebooks with NeoMagic PCI chips. 1319 This driver supports notebooks with NeoMagic PCI chips.
1201 Say Y if you have such a graphics card. 1320 Say Y if you have such a graphics card.
@@ -1255,6 +1374,20 @@ config FB_VOODOO1
1255 Please read the <file:Documentation/fb/README-sstfb.txt> for supported 1374 Please read the <file:Documentation/fb/README-sstfb.txt> for supported
1256 options and other important info support. 1375 options and other important info support.
1257 1376
1377config FB_VT8623
1378 tristate "VIA VT8623 support"
1379 depends on FB && PCI
1380 select FB_CFB_FILLRECT
1381 select FB_CFB_COPYAREA
1382 select FB_CFB_IMAGEBLIT
1383 select FB_TILEBLITTING
1384 select FB_SVGALIB
1385 select VGASTATE
1386 select FONT_8x16 if FRAMEBUFFER_CONSOLE
1387 ---help---
1388 Driver for CastleRock integrated graphics core in the
1389 VIA VT8623 [Apollo CLE266] chipset.
1390
1258config FB_CYBLA 1391config FB_CYBLA
1259 tristate "Cyberblade/i1 support" 1392 tristate "Cyberblade/i1 support"
1260 depends on FB && PCI && X86_32 && !64BIT 1393 depends on FB && PCI && X86_32 && !64BIT
@@ -1308,9 +1441,26 @@ config FB_TRIDENT_ACCEL
1308 This will compile the Trident frame buffer device with 1441 This will compile the Trident frame buffer device with
1309 acceleration functions. 1442 acceleration functions.
1310 1443
1444config FB_ARK
1445 tristate "ARK 2000PV support"
1446 depends on FB && PCI
1447 select FB_CFB_FILLRECT
1448 select FB_CFB_COPYAREA
1449 select FB_CFB_IMAGEBLIT
1450 select FB_TILEBLITTING
1451 select FB_SVGALIB
1452 select VGASTATE
1453 select FONT_8x16 if FRAMEBUFFER_CONSOLE
1454 ---help---
1455 Driver for PCI graphics boards with ARK 2000PV chip
1456 and ICS 5342 RAMDAC.
1457
1311config FB_PM3 1458config FB_PM3
1312 tristate "Permedia3 support" 1459 tristate "Permedia3 support (EXPERIMENTAL)"
1313 depends on FB && PCI && BROKEN 1460 depends on FB && PCI && EXPERIMENTAL
1461 select FB_CFB_FILLRECT
1462 select FB_CFB_COPYAREA
1463 select FB_CFB_IMAGEBLIT
1314 help 1464 help
1315 This is the frame buffer device driver for the 3DLabs Permedia3 1465 This is the frame buffer device driver for the 3DLabs Permedia3
1316 chipset, used in Formac ProFormance III, 3DLabs Oxygen VX1 & 1466 chipset, used in Formac ProFormance III, 3DLabs Oxygen VX1 &
@@ -1385,7 +1535,7 @@ config FB_LEO
1385 1535
1386config FB_XVR500 1536config FB_XVR500
1387 bool "Sun XVR-500 3DLABS Wildcat support" 1537 bool "Sun XVR-500 3DLABS Wildcat support"
1388 depends on FB && PCI && SPARC64 1538 depends on (FB = y) && PCI && SPARC64
1389 select FB_CFB_FILLRECT 1539 select FB_CFB_FILLRECT
1390 select FB_CFB_COPYAREA 1540 select FB_CFB_COPYAREA
1391 select FB_CFB_IMAGEBLIT 1541 select FB_CFB_IMAGEBLIT
@@ -1398,7 +1548,7 @@ config FB_XVR500
1398 1548
1399config FB_XVR2500 1549config FB_XVR2500
1400 bool "Sun XVR-2500 3DLABS Wildcat support" 1550 bool "Sun XVR-2500 3DLABS Wildcat support"
1401 depends on FB && PCI && SPARC64 1551 depends on (FB = y) && PCI && SPARC64
1402 select FB_CFB_FILLRECT 1552 select FB_CFB_FILLRECT
1403 select FB_CFB_COPYAREA 1553 select FB_CFB_COPYAREA
1404 select FB_CFB_IMAGEBLIT 1554 select FB_CFB_IMAGEBLIT
@@ -1662,13 +1812,25 @@ config FB_PS3_DEFAULT_SIZE_M
1662 The default value can be overridden on the kernel command line 1812 The default value can be overridden on the kernel command line
1663 using the "ps3fb" option (e.g. "ps3fb=9M"); 1813 using the "ps3fb" option (e.g. "ps3fb=9M");
1664 1814
1665config FB_VIRTUAL 1815config FB_XILINX
1666 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)" 1816 tristate "Xilinx frame buffer support"
1667 depends on FB 1817 depends on FB && XILINX_VIRTEX
1668 select FB_CFB_FILLRECT 1818 select FB_CFB_FILLRECT
1669 select FB_CFB_COPYAREA 1819 select FB_CFB_COPYAREA
1670 select FB_CFB_IMAGEBLIT 1820 select FB_CFB_IMAGEBLIT
1671 ---help--- 1821 ---help---
1822 Include support for the Xilinx ML300/ML403 reference design
1823 framebuffer. ML300 carries a 640*480 LCD display on the board,
1824 ML403 uses a standard DB15 VGA connector.
1825
1826config FB_VIRTUAL
1827 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)"
1828 depends on FB
1829 select FB_SYS_FILLRECT
1830 select FB_SYS_COPYAREA
1831 select FB_SYS_IMAGEBLIT
1832 select FB_SYS_FOPS
1833 ---help---
1672 This is a `virtual' frame buffer device. It operates on a chunk of 1834 This is a `virtual' frame buffer device. It operates on a chunk of
1673 unswappable kernel memory instead of on the memory of a graphics 1835 unswappable kernel memory instead of on the memory of a graphics
1674 board. This means you cannot see any output sent to this frame 1836 board. This means you cannot see any output sent to this frame
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 558473d040d6..bd8b05229500 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -4,6 +4,7 @@
4 4
5# Each configuration option enables a list of files. 5# Each configuration option enables a list of files.
6 6
7obj-$(CONFIG_VGASTATE) += vgastate.o
7obj-y += fb_notify.o 8obj-y += fb_notify.o
8obj-$(CONFIG_FB) += fb.o 9obj-$(CONFIG_FB) += fb.o
9fb-y := fbmem.o fbmon.o fbcmap.o fbsysfs.o \ 10fb-y := fbmem.o fbmon.o fbcmap.o fbsysfs.o \
@@ -12,14 +13,19 @@ fb-objs := $(fb-y)
12 13
13obj-$(CONFIG_VT) += console/ 14obj-$(CONFIG_VT) += console/
14obj-$(CONFIG_LOGO) += logo/ 15obj-$(CONFIG_LOGO) += logo/
15obj-y += backlight/ 16obj-y += backlight/ display/
16 17
17obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o 18obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o
18obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o 19obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o
19obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o 20obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o
21obj-$(CONFIG_FB_SYS_FILLRECT) += sysfillrect.o
22obj-$(CONFIG_FB_SYS_COPYAREA) += syscopyarea.o
23obj-$(CONFIG_FB_SYS_IMAGEBLIT) += sysimgblt.o
24obj-$(CONFIG_FB_SYS_FOPS) += fb_sys_fops.o
20obj-$(CONFIG_FB_SVGALIB) += svgalib.o 25obj-$(CONFIG_FB_SVGALIB) += svgalib.o
21obj-$(CONFIG_FB_MACMODES) += macmodes.o 26obj-$(CONFIG_FB_MACMODES) += macmodes.o
22obj-$(CONFIG_FB_DDC) += fb_ddc.o 27obj-$(CONFIG_FB_DDC) += fb_ddc.o
28obj-$(CONFIG_FB_DEFERRED_IO) += fb_defio.o
23 29
24# Hardware specific drivers go first 30# Hardware specific drivers go first
25obj-$(CONFIG_FB_AMIGA) += amifb.o c2p.o 31obj-$(CONFIG_FB_AMIGA) += amifb.o c2p.o
@@ -30,7 +36,7 @@ obj-$(CONFIG_FB_PM2) += pm2fb.o
30obj-$(CONFIG_FB_PM3) += pm3fb.o 36obj-$(CONFIG_FB_PM3) += pm3fb.o
31 37
32obj-$(CONFIG_FB_MATROX) += matrox/ 38obj-$(CONFIG_FB_MATROX) += matrox/
33obj-$(CONFIG_FB_RIVA) += riva/ vgastate.o 39obj-$(CONFIG_FB_RIVA) += riva/
34obj-$(CONFIG_FB_NVIDIA) += nvidia/ 40obj-$(CONFIG_FB_NVIDIA) += nvidia/
35obj-$(CONFIG_FB_ATY) += aty/ macmodes.o 41obj-$(CONFIG_FB_ATY) += aty/ macmodes.o
36obj-$(CONFIG_FB_ATY128) += aty/ macmodes.o 42obj-$(CONFIG_FB_ATY128) += aty/ macmodes.o
@@ -40,8 +46,7 @@ obj-$(CONFIG_FB_KYRO) += kyro/
40obj-$(CONFIG_FB_SAVAGE) += savage/ 46obj-$(CONFIG_FB_SAVAGE) += savage/
41obj-$(CONFIG_FB_GEODE) += geode/ 47obj-$(CONFIG_FB_GEODE) += geode/
42obj-$(CONFIG_FB_MBX) += mbx/ 48obj-$(CONFIG_FB_MBX) += mbx/
43obj-$(CONFIG_FB_I810) += vgastate.o 49obj-$(CONFIG_FB_NEOMAGIC) += neofb.o
44obj-$(CONFIG_FB_NEOMAGIC) += neofb.o vgastate.o
45obj-$(CONFIG_FB_3DFX) += tdfxfb.o 50obj-$(CONFIG_FB_3DFX) += tdfxfb.o
46obj-$(CONFIG_FB_CONTROL) += controlfb.o 51obj-$(CONFIG_FB_CONTROL) += controlfb.o
47obj-$(CONFIG_FB_PLATINUM) += platinumfb.o 52obj-$(CONFIG_FB_PLATINUM) += platinumfb.o
@@ -49,9 +54,12 @@ obj-$(CONFIG_FB_VALKYRIE) += valkyriefb.o
49obj-$(CONFIG_FB_CT65550) += chipsfb.o 54obj-$(CONFIG_FB_CT65550) += chipsfb.o
50obj-$(CONFIG_FB_IMSTT) += imsttfb.o 55obj-$(CONFIG_FB_IMSTT) += imsttfb.o
51obj-$(CONFIG_FB_FM2) += fm2fb.o 56obj-$(CONFIG_FB_FM2) += fm2fb.o
57obj-$(CONFIG_FB_VT8623) += vt8623fb.o
52obj-$(CONFIG_FB_CYBLA) += cyblafb.o 58obj-$(CONFIG_FB_CYBLA) += cyblafb.o
53obj-$(CONFIG_FB_TRIDENT) += tridentfb.o 59obj-$(CONFIG_FB_TRIDENT) += tridentfb.o
54obj-$(CONFIG_FB_S3) += s3fb.o vgastate.o 60obj-$(CONFIG_FB_LE80578) += vermilion/
61obj-$(CONFIG_FB_S3) += s3fb.o
62obj-$(CONFIG_FB_ARK) += arkfb.o
55obj-$(CONFIG_FB_STI) += stifb.o 63obj-$(CONFIG_FB_STI) += stifb.o
56obj-$(CONFIG_FB_FFB) += ffb.o sbuslib.o 64obj-$(CONFIG_FB_FFB) += ffb.o sbuslib.o
57obj-$(CONFIG_FB_CG6) += cg6.o sbuslib.o 65obj-$(CONFIG_FB_CG6) += cg6.o sbuslib.o
@@ -66,6 +74,7 @@ obj-$(CONFIG_FB_ACORN) += acornfb.o
66obj-$(CONFIG_FB_ATARI) += atafb.o c2p.o atafb_mfb.o \ 74obj-$(CONFIG_FB_ATARI) += atafb.o c2p.o atafb_mfb.o \
67 atafb_iplan2p2.o atafb_iplan2p4.o atafb_iplan2p8.o 75 atafb_iplan2p2.o atafb_iplan2p4.o atafb_iplan2p8.o
68obj-$(CONFIG_FB_MAC) += macfb.o 76obj-$(CONFIG_FB_MAC) += macfb.o
77obj-$(CONFIG_FB_HECUBA) += hecubafb.o
69obj-$(CONFIG_FB_HGA) += hgafb.o 78obj-$(CONFIG_FB_HGA) += hgafb.o
70obj-$(CONFIG_FB_XVR500) += sunxvr500.o 79obj-$(CONFIG_FB_XVR500) += sunxvr500.o
71obj-$(CONFIG_FB_XVR2500) += sunxvr2500.o 80obj-$(CONFIG_FB_XVR2500) += sunxvr2500.o
@@ -78,6 +87,7 @@ obj-$(CONFIG_FB_G364) += g364fb.o
78obj-$(CONFIG_FB_SA1100) += sa1100fb.o 87obj-$(CONFIG_FB_SA1100) += sa1100fb.o
79obj-$(CONFIG_FB_HIT) += hitfb.o 88obj-$(CONFIG_FB_HIT) += hitfb.o
80obj-$(CONFIG_FB_EPSON1355) += epson1355fb.o 89obj-$(CONFIG_FB_EPSON1355) += epson1355fb.o
90obj-$(CONFIG_FB_ATMEL) += atmel_lcdfb.o
81obj-$(CONFIG_FB_PVR2) += pvr2fb.o 91obj-$(CONFIG_FB_PVR2) += pvr2fb.o
82obj-$(CONFIG_FB_VOODOO1) += sstfb.o 92obj-$(CONFIG_FB_VOODOO1) += sstfb.o
83obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o 93obj-$(CONFIG_FB_ARMCLCD) += amba-clcd.o
@@ -102,11 +112,12 @@ obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/
102obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o 112obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o
103obj-$(CONFIG_FB_PS3) += ps3fb.o 113obj-$(CONFIG_FB_PS3) += ps3fb.o
104obj-$(CONFIG_FB_SM501) += sm501fb.o 114obj-$(CONFIG_FB_SM501) += sm501fb.o
115obj-$(CONFIG_FB_XILINX) += xilinxfb.o
105 116
106# Platform or fallback drivers go here 117# Platform or fallback drivers go here
107obj-$(CONFIG_FB_VESA) += vesafb.o 118obj-$(CONFIG_FB_VESA) += vesafb.o
108obj-$(CONFIG_FB_IMAC) += imacfb.o 119obj-$(CONFIG_FB_IMAC) += imacfb.o
109obj-$(CONFIG_FB_VGA16) += vga16fb.o vgastate.o 120obj-$(CONFIG_FB_VGA16) += vga16fb.o
110obj-$(CONFIG_FB_OF) += offb.o 121obj-$(CONFIG_FB_OF) += offb.o
111 122
112# the test framebuffer is last 123# the test framebuffer is last
diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
index 30a8369757e7..db15baca3f7b 100644
--- a/drivers/video/arcfb.c
+++ b/drivers/video/arcfb.c
@@ -262,7 +262,8 @@ static void arcfb_lcd_update_page(struct arcfb_par *par, unsigned int upper,
262 ks108_set_yaddr(par, chipindex, upper/8); 262 ks108_set_yaddr(par, chipindex, upper/8);
263 263
264 linesize = par->info->var.xres/8; 264 linesize = par->info->var.xres/8;
265 src = par->info->screen_base + (left/8) + (upper * linesize); 265 src = (unsigned char __force *) par->info->screen_base + (left/8) +
266 (upper * linesize);
266 ks108_set_xaddr(par, chipindex, left); 267 ks108_set_xaddr(par, chipindex, left);
267 268
268 bitmask=1; 269 bitmask=1;
@@ -368,7 +369,7 @@ static void arcfb_fillrect(struct fb_info *info,
368{ 369{
369 struct arcfb_par *par = info->par; 370 struct arcfb_par *par = info->par;
370 371
371 cfb_fillrect(info, rect); 372 sys_fillrect(info, rect);
372 373
373 /* update the physical lcd */ 374 /* update the physical lcd */
374 arcfb_lcd_update(par, rect->dx, rect->dy, rect->width, rect->height); 375 arcfb_lcd_update(par, rect->dx, rect->dy, rect->width, rect->height);
@@ -379,7 +380,7 @@ static void arcfb_copyarea(struct fb_info *info,
379{ 380{
380 struct arcfb_par *par = info->par; 381 struct arcfb_par *par = info->par;
381 382
382 cfb_copyarea(info, area); 383 sys_copyarea(info, area);
383 384
384 /* update the physical lcd */ 385 /* update the physical lcd */
385 arcfb_lcd_update(par, area->dx, area->dy, area->width, area->height); 386 arcfb_lcd_update(par, area->dx, area->dy, area->width, area->height);
@@ -389,7 +390,7 @@ static void arcfb_imageblit(struct fb_info *info, const struct fb_image *image)
389{ 390{
390 struct arcfb_par *par = info->par; 391 struct arcfb_par *par = info->par;
391 392
392 cfb_imageblit(info, image); 393 sys_imageblit(info, image);
393 394
394 /* update the physical lcd */ 395 /* update the physical lcd */
395 arcfb_lcd_update(par, image->dx, image->dy, image->width, 396 arcfb_lcd_update(par, image->dx, image->dy, image->width,
@@ -439,14 +440,11 @@ static int arcfb_ioctl(struct fb_info *info,
439 * the fb. it's inefficient for them to do anything less than 64*8 440 * the fb. it's inefficient for them to do anything less than 64*8
440 * writes since we update the lcd in each write() anyway. 441 * writes since we update the lcd in each write() anyway.
441 */ 442 */
442static ssize_t arcfb_write(struct file *file, const char __user *buf, size_t count, 443static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
443 loff_t *ppos) 444 size_t count, loff_t *ppos)
444{ 445{
445 /* modded from epson 1355 */ 446 /* modded from epson 1355 */
446 447
447 struct inode *inode;
448 int fbidx;
449 struct fb_info *info;
450 unsigned long p; 448 unsigned long p;
451 int err=-EINVAL; 449 int err=-EINVAL;
452 unsigned int fbmemlength,x,y,w,h, bitppos, startpos, endpos, bitcount; 450 unsigned int fbmemlength,x,y,w,h, bitppos, startpos, endpos, bitcount;
@@ -454,13 +452,6 @@ static ssize_t arcfb_write(struct file *file, const char __user *buf, size_t cou
454 unsigned int xres; 452 unsigned int xres;
455 453
456 p = *ppos; 454 p = *ppos;
457 inode = file->f_path.dentry->d_inode;
458 fbidx = iminor(inode);
459 info = registered_fb[fbidx];
460
461 if (!info || !info->screen_base)
462 return -ENODEV;
463
464 par = info->par; 455 par = info->par;
465 xres = info->var.xres; 456 xres = info->var.xres;
466 fbmemlength = (xres * info->var.yres)/8; 457 fbmemlength = (xres * info->var.yres)/8;
@@ -477,7 +468,7 @@ static ssize_t arcfb_write(struct file *file, const char __user *buf, size_t cou
477 if (count) { 468 if (count) {
478 char *base_addr; 469 char *base_addr;
479 470
480 base_addr = info->screen_base; 471 base_addr = (char __force *)info->screen_base;
481 count -= copy_from_user(base_addr + p, buf, count); 472 count -= copy_from_user(base_addr + p, buf, count);
482 *ppos += count; 473 *ppos += count;
483 err = -EFAULT; 474 err = -EFAULT;
@@ -503,6 +494,7 @@ static ssize_t arcfb_write(struct file *file, const char __user *buf, size_t cou
503static struct fb_ops arcfb_ops = { 494static struct fb_ops arcfb_ops = {
504 .owner = THIS_MODULE, 495 .owner = THIS_MODULE,
505 .fb_open = arcfb_open, 496 .fb_open = arcfb_open,
497 .fb_read = fb_sys_read,
506 .fb_write = arcfb_write, 498 .fb_write = arcfb_write,
507 .fb_release = arcfb_release, 499 .fb_release = arcfb_release,
508 .fb_pan_display = arcfb_pan_display, 500 .fb_pan_display = arcfb_pan_display,
@@ -603,7 +595,7 @@ static int arcfb_remove(struct platform_device *dev)
603 595
604 if (info) { 596 if (info) {
605 unregister_framebuffer(info); 597 unregister_framebuffer(info);
606 vfree(info->screen_base); 598 vfree((void __force *)info->screen_base);
607 framebuffer_release(info); 599 framebuffer_release(info);
608 } 600 }
609 return 0; 601 return 0;
diff --git a/drivers/video/arkfb.c b/drivers/video/arkfb.c
new file mode 100644
index 000000000000..ba6fede5c466
--- /dev/null
+++ b/drivers/video/arkfb.c
@@ -0,0 +1,1200 @@
1/*
2 * linux/drivers/video/arkfb.c -- Frame buffer device driver for ARK 2000PV
3 * with ICS 5342 dac (it is easy to add support for different dacs).
4 *
5 * Copyright (c) 2007 Ondrej Zajicek <santiago@crfreenet.org>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
10 *
11 * Code is based on s3fb
12 */
13
14#include <linux/version.h>
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/errno.h>
18#include <linux/string.h>
19#include <linux/mm.h>
20#include <linux/tty.h>
21#include <linux/slab.h>
22#include <linux/delay.h>
23#include <linux/fb.h>
24#include <linux/svga.h>
25#include <linux/init.h>
26#include <linux/pci.h>
27#include <linux/console.h> /* Why should fb driver call console functions? because acquire_console_sem() */
28#include <video/vga.h>
29
30#ifdef CONFIG_MTRR
31#include <asm/mtrr.h>
32#endif
33
34struct arkfb_info {
35 int mclk_freq;
36 int mtrr_reg;
37
38 struct dac_info *dac;
39 struct vgastate state;
40 struct mutex open_lock;
41 unsigned int ref_count;
42 u32 pseudo_palette[16];
43};
44
45
46/* ------------------------------------------------------------------------- */
47
48
49static const struct svga_fb_format arkfb_formats[] = {
50 { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
51 FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 8},
52 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
53 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16},
54 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
55 FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16},
56 { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
57 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 8},
58 {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
59 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4},
60 {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
61 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4},
62 {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
63 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 8, 8},
64 {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
65 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 2},
66 SVGA_FORMAT_END
67};
68
69
70/* CRT timing register sets */
71
72static const struct vga_regset ark_h_total_regs[] = {{0x00, 0, 7}, {0x41, 7, 7}, VGA_REGSET_END};
73static const struct vga_regset ark_h_display_regs[] = {{0x01, 0, 7}, {0x41, 6, 6}, VGA_REGSET_END};
74static const struct vga_regset ark_h_blank_start_regs[] = {{0x02, 0, 7}, {0x41, 5, 5}, VGA_REGSET_END};
75static const struct vga_regset ark_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7 }, VGA_REGSET_END};
76static const struct vga_regset ark_h_sync_start_regs[] = {{0x04, 0, 7}, {0x41, 4, 4}, VGA_REGSET_END};
77static const struct vga_regset ark_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
78
79static const struct vga_regset ark_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x40, 7, 7}, VGA_REGSET_END};
80static const struct vga_regset ark_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x40, 6, 6}, VGA_REGSET_END};
81static const struct vga_regset ark_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x40, 5, 5}, VGA_REGSET_END};
82// const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 6}, VGA_REGSET_END};
83static const struct vga_regset ark_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
84static const struct vga_regset ark_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x40, 4, 4}, VGA_REGSET_END};
85static const struct vga_regset ark_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
86
87static const struct vga_regset ark_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, VGA_REGSET_END};
88static const struct vga_regset ark_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x40, 0, 2}, VGA_REGSET_END};
89static const struct vga_regset ark_offset_regs[] = {{0x13, 0, 7}, {0x41, 3, 3}, VGA_REGSET_END};
90
91static const struct svga_timing_regs ark_timing_regs = {
92 ark_h_total_regs, ark_h_display_regs, ark_h_blank_start_regs,
93 ark_h_blank_end_regs, ark_h_sync_start_regs, ark_h_sync_end_regs,
94 ark_v_total_regs, ark_v_display_regs, ark_v_blank_start_regs,
95 ark_v_blank_end_regs, ark_v_sync_start_regs, ark_v_sync_end_regs,
96};
97
98
99/* ------------------------------------------------------------------------- */
100
101
102/* Module parameters */
103
104static char *mode = "640x480-8@60";
105
106#ifdef CONFIG_MTRR
107static int mtrr = 1;
108#endif
109
110MODULE_AUTHOR("(c) 2007 Ondrej Zajicek <santiago@crfreenet.org>");
111MODULE_LICENSE("GPL");
112MODULE_DESCRIPTION("fbdev driver for ARK 2000PV");
113
114module_param(mode, charp, 0444);
115MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc)");
116
117#ifdef CONFIG_MTRR
118module_param(mtrr, int, 0444);
119MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
120#endif
121
122static int threshold = 4;
123
124module_param(threshold, int, 0644);
125MODULE_PARM_DESC(threshold, "FIFO threshold");
126
127
128/* ------------------------------------------------------------------------- */
129
130
131static void arkfb_settile(struct fb_info *info, struct fb_tilemap *map)
132{
133 const u8 *font = map->data;
134 u8 __iomem *fb = (u8 __iomem *)info->screen_base;
135 int i, c;
136
137 if ((map->width != 8) || (map->height != 16) ||
138 (map->depth != 1) || (map->length != 256)) {
139 printk(KERN_ERR "fb%d: unsupported font parameters: width %d, "
140 "height %d, depth %d, length %d\n", info->node,
141 map->width, map->height, map->depth, map->length);
142 return;
143 }
144
145 fb += 2;
146 for (c = 0; c < map->length; c++) {
147 for (i = 0; i < map->height; i++) {
148 fb_writeb(font[i], &fb[i * 4]);
149 fb_writeb(font[i], &fb[i * 4 + (128 * 8)]);
150 }
151 fb += 128;
152
153 if ((c % 8) == 7)
154 fb += 128*8;
155
156 font += map->height;
157 }
158}
159
160static struct fb_tile_ops arkfb_tile_ops = {
161 .fb_settile = arkfb_settile,
162 .fb_tilecopy = svga_tilecopy,
163 .fb_tilefill = svga_tilefill,
164 .fb_tileblit = svga_tileblit,
165 .fb_tilecursor = svga_tilecursor,
166 .fb_get_tilemax = svga_get_tilemax,
167};
168
169
170/* ------------------------------------------------------------------------- */
171
172
173/* image data is MSB-first, fb structure is MSB-first too */
174static inline u32 expand_color(u32 c)
175{
176 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
177}
178
179/* arkfb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
180static void arkfb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
181{
182 u32 fg = expand_color(image->fg_color);
183 u32 bg = expand_color(image->bg_color);
184 const u8 *src1, *src;
185 u8 __iomem *dst1;
186 u32 __iomem *dst;
187 u32 val;
188 int x, y;
189
190 src1 = image->data;
191 dst1 = info->screen_base + (image->dy * info->fix.line_length)
192 + ((image->dx / 8) * 4);
193
194 for (y = 0; y < image->height; y++) {
195 src = src1;
196 dst = (u32 __iomem *) dst1;
197 for (x = 0; x < image->width; x += 8) {
198 val = *(src++) * 0x01010101;
199 val = (val & fg) | (~val & bg);
200 fb_writel(val, dst++);
201 }
202 src1 += image->width / 8;
203 dst1 += info->fix.line_length;
204 }
205
206}
207
208/* arkfb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
209static void arkfb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
210{
211 u32 fg = expand_color(rect->color);
212 u8 __iomem *dst1;
213 u32 __iomem *dst;
214 int x, y;
215
216 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
217 + ((rect->dx / 8) * 4);
218
219 for (y = 0; y < rect->height; y++) {
220 dst = (u32 __iomem *) dst1;
221 for (x = 0; x < rect->width; x += 8) {
222 fb_writel(fg, dst++);
223 }
224 dst1 += info->fix.line_length;
225 }
226
227}
228
229
230/* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
231static inline u32 expand_pixel(u32 c)
232{
233 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
234 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
235}
236
237/* arkfb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
238static void arkfb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
239{
240 u32 fg = image->fg_color * 0x11111111;
241 u32 bg = image->bg_color * 0x11111111;
242 const u8 *src1, *src;
243 u8 __iomem *dst1;
244 u32 __iomem *dst;
245 u32 val;
246 int x, y;
247
248 src1 = image->data;
249 dst1 = info->screen_base + (image->dy * info->fix.line_length)
250 + ((image->dx / 8) * 4);
251
252 for (y = 0; y < image->height; y++) {
253 src = src1;
254 dst = (u32 __iomem *) dst1;
255 for (x = 0; x < image->width; x += 8) {
256 val = expand_pixel(*(src++));
257 val = (val & fg) | (~val & bg);
258 fb_writel(val, dst++);
259 }
260 src1 += image->width / 8;
261 dst1 += info->fix.line_length;
262 }
263
264}
265
266static void arkfb_imageblit(struct fb_info *info, const struct fb_image *image)
267{
268 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
269 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
270 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
271 arkfb_iplan_imageblit(info, image);
272 else
273 arkfb_cfb4_imageblit(info, image);
274 } else
275 cfb_imageblit(info, image);
276}
277
278static void arkfb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
279{
280 if ((info->var.bits_per_pixel == 4)
281 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
282 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
283 arkfb_iplan_fillrect(info, rect);
284 else
285 cfb_fillrect(info, rect);
286}
287
288
289/* ------------------------------------------------------------------------- */
290
291
292enum
293{
294 DAC_PSEUDO8_8,
295 DAC_RGB1555_8,
296 DAC_RGB0565_8,
297 DAC_RGB0888_8,
298 DAC_RGB8888_8,
299 DAC_PSEUDO8_16,
300 DAC_RGB1555_16,
301 DAC_RGB0565_16,
302 DAC_RGB0888_16,
303 DAC_RGB8888_16,
304 DAC_MAX
305};
306
307struct dac_ops {
308 int (*dac_get_mode)(struct dac_info *info);
309 int (*dac_set_mode)(struct dac_info *info, int mode);
310 int (*dac_get_freq)(struct dac_info *info, int channel);
311 int (*dac_set_freq)(struct dac_info *info, int channel, u32 freq);
312 void (*dac_release)(struct dac_info *info);
313};
314
315typedef void (*dac_read_regs_t)(void *data, u8 *code, int count);
316typedef void (*dac_write_regs_t)(void *data, u8 *code, int count);
317
318struct dac_info
319{
320 struct dac_ops *dacops;
321 dac_read_regs_t dac_read_regs;
322 dac_write_regs_t dac_write_regs;
323 void *data;
324};
325
326
327static inline u8 dac_read_reg(struct dac_info *info, u8 reg)
328{
329 u8 code[2] = {reg, 0};
330 info->dac_read_regs(info->data, code, 1);
331 return code[1];
332}
333
334static inline void dac_read_regs(struct dac_info *info, u8 *code, int count)
335{
336 info->dac_read_regs(info->data, code, count);
337}
338
339static inline void dac_write_reg(struct dac_info *info, u8 reg, u8 val)
340{
341 u8 code[2] = {reg, val};
342 info->dac_write_regs(info->data, code, 1);
343}
344
345static inline void dac_write_regs(struct dac_info *info, u8 *code, int count)
346{
347 info->dac_write_regs(info->data, code, count);
348}
349
350static inline int dac_set_mode(struct dac_info *info, int mode)
351{
352 return info->dacops->dac_set_mode(info, mode);
353}
354
355static inline int dac_set_freq(struct dac_info *info, int channel, u32 freq)
356{
357 return info->dacops->dac_set_freq(info, channel, freq);
358}
359
360static inline void dac_release(struct dac_info *info)
361{
362 info->dacops->dac_release(info);
363}
364
365
366/* ------------------------------------------------------------------------- */
367
368
369/* ICS5342 DAC */
370
371struct ics5342_info
372{
373 struct dac_info dac;
374 u8 mode;
375};
376
377#define DAC_PAR(info) ((struct ics5342_info *) info)
378
379/* LSB is set to distinguish unused slots */
380static const u8 ics5342_mode_table[DAC_MAX] = {
381 [DAC_PSEUDO8_8] = 0x01, [DAC_RGB1555_8] = 0x21, [DAC_RGB0565_8] = 0x61,
382 [DAC_RGB0888_8] = 0x41, [DAC_PSEUDO8_16] = 0x11, [DAC_RGB1555_16] = 0x31,
383 [DAC_RGB0565_16] = 0x51, [DAC_RGB0888_16] = 0x91, [DAC_RGB8888_16] = 0x71
384};
385
386static int ics5342_set_mode(struct dac_info *info, int mode)
387{
388 u8 code;
389
390 if (mode >= DAC_MAX)
391 return -EINVAL;
392
393 code = ics5342_mode_table[mode];
394
395 if (! code)
396 return -EINVAL;
397
398 dac_write_reg(info, 6, code & 0xF0);
399 DAC_PAR(info)->mode = mode;
400
401 return 0;
402}
403
404static const struct svga_pll ics5342_pll = {3, 129, 3, 33, 0, 3,
405 60000, 250000, 14318};
406
407/* pd4 - allow only posdivider 4 (r=2) */
408static const struct svga_pll ics5342_pll_pd4 = {3, 129, 3, 33, 2, 2,
409 60000, 335000, 14318};
410
411/* 270 MHz should be upper bound for VCO clock according to specs,
412 but that is too restrictive in pd4 case */
413
414static int ics5342_set_freq(struct dac_info *info, int channel, u32 freq)
415{
416 u16 m, n, r;
417
418 /* only postdivider 4 (r=2) is valid in mode DAC_PSEUDO8_16 */
419 int rv = svga_compute_pll((DAC_PAR(info)->mode == DAC_PSEUDO8_16)
420 ? &ics5342_pll_pd4 : &ics5342_pll,
421 freq, &m, &n, &r, 0);
422
423 if (rv < 0) {
424 return -EINVAL;
425 } else {
426 u8 code[6] = {4, 3, 5, m-2, 5, (n-2) | (r << 5)};
427 dac_write_regs(info, code, 3);
428 return 0;
429 }
430}
431
432static void ics5342_release(struct dac_info *info)
433{
434 ics5342_set_mode(info, DAC_PSEUDO8_8);
435 kfree(info);
436}
437
438static struct dac_ops ics5342_ops = {
439 .dac_set_mode = ics5342_set_mode,
440 .dac_set_freq = ics5342_set_freq,
441 .dac_release = ics5342_release
442};
443
444
445static struct dac_info * ics5342_init(dac_read_regs_t drr, dac_write_regs_t dwr, void *data)
446{
447 struct dac_info *info = kzalloc(sizeof(struct ics5342_info), GFP_KERNEL);
448
449 if (! info)
450 return NULL;
451
452 info->dacops = &ics5342_ops;
453 info->dac_read_regs = drr;
454 info->dac_write_regs = dwr;
455 info->data = data;
456 DAC_PAR(info)->mode = DAC_PSEUDO8_8; /* estimation */
457 return info;
458}
459
460
461/* ------------------------------------------------------------------------- */
462
463
464static unsigned short dac_regs[4] = {0x3c8, 0x3c9, 0x3c6, 0x3c7};
465
466static void ark_dac_read_regs(void *data, u8 *code, int count)
467{
468 u8 regval = vga_rseq(NULL, 0x1C);
469
470 while (count != 0)
471 {
472 vga_wseq(NULL, 0x1C, regval | (code[0] & 4) ? 0x80 : 0);
473 code[1] = vga_r(NULL, dac_regs[code[0] & 3]);
474 count--;
475 code += 2;
476 }
477
478 vga_wseq(NULL, 0x1C, regval);
479}
480
481static void ark_dac_write_regs(void *data, u8 *code, int count)
482{
483 u8 regval = vga_rseq(NULL, 0x1C);
484
485 while (count != 0)
486 {
487 vga_wseq(NULL, 0x1C, regval | (code[0] & 4) ? 0x80 : 0);
488 vga_w(NULL, dac_regs[code[0] & 3], code[1]);
489 count--;
490 code += 2;
491 }
492
493 vga_wseq(NULL, 0x1C, regval);
494}
495
496
497static void ark_set_pixclock(struct fb_info *info, u32 pixclock)
498{
499 struct arkfb_info *par = info->par;
500 u8 regval;
501
502 int rv = dac_set_freq(par->dac, 0, 1000000000 / pixclock);
503 if (rv < 0) {
504 printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
505 return;
506 }
507
508 /* Set VGA misc register */
509 regval = vga_r(NULL, VGA_MIS_R);
510 vga_w(NULL, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
511}
512
513
514/* Open framebuffer */
515
516static int arkfb_open(struct fb_info *info, int user)
517{
518 struct arkfb_info *par = info->par;
519
520 mutex_lock(&(par->open_lock));
521 if (par->ref_count == 0) {
522 memset(&(par->state), 0, sizeof(struct vgastate));
523 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
524 par->state.num_crtc = 0x60;
525 par->state.num_seq = 0x30;
526 save_vga(&(par->state));
527 }
528
529 par->ref_count++;
530 mutex_unlock(&(par->open_lock));
531
532 return 0;
533}
534
535/* Close framebuffer */
536
537static int arkfb_release(struct fb_info *info, int user)
538{
539 struct arkfb_info *par = info->par;
540
541 mutex_lock(&(par->open_lock));
542 if (par->ref_count == 0) {
543 mutex_unlock(&(par->open_lock));
544 return -EINVAL;
545 }
546
547 if (par->ref_count == 1) {
548 restore_vga(&(par->state));
549 dac_set_mode(par->dac, DAC_PSEUDO8_8);
550 }
551
552 par->ref_count--;
553 mutex_unlock(&(par->open_lock));
554
555 return 0;
556}
557
558/* Validate passed in var */
559
560static int arkfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
561{
562 int rv, mem, step;
563
564 /* Find appropriate format */
565 rv = svga_match_format (arkfb_formats, var, NULL);
566 if (rv < 0)
567 {
568 printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
569 return rv;
570 }
571
572 /* Do not allow to have real resoulution larger than virtual */
573 if (var->xres > var->xres_virtual)
574 var->xres_virtual = var->xres;
575
576 if (var->yres > var->yres_virtual)
577 var->yres_virtual = var->yres;
578
579 /* Round up xres_virtual to have proper alignment of lines */
580 step = arkfb_formats[rv].xresstep - 1;
581 var->xres_virtual = (var->xres_virtual+step) & ~step;
582
583
584 /* Check whether have enough memory */
585 mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
586 if (mem > info->screen_size)
587 {
588 printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n", info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
589 return -EINVAL;
590 }
591
592 rv = svga_check_timings (&ark_timing_regs, var, info->node);
593 if (rv < 0)
594 {
595 printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
596 return rv;
597 }
598
599 /* Interlaced mode is broken */
600 if (var->vmode & FB_VMODE_INTERLACED)
601 return -EINVAL;
602
603 return 0;
604}
605
606/* Set video mode from par */
607
608static int arkfb_set_par(struct fb_info *info)
609{
610 struct arkfb_info *par = info->par;
611 u32 value, mode, hmul, hdiv, offset_value, screen_size;
612 u32 bpp = info->var.bits_per_pixel;
613 u8 regval;
614
615 if (bpp != 0) {
616 info->fix.ypanstep = 1;
617 info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
618
619 info->flags &= ~FBINFO_MISC_TILEBLITTING;
620 info->tileops = NULL;
621
622 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
623 info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
624 info->pixmap.blit_y = ~(u32)0;
625
626 offset_value = (info->var.xres_virtual * bpp) / 64;
627 screen_size = info->var.yres_virtual * info->fix.line_length;
628 } else {
629 info->fix.ypanstep = 16;
630 info->fix.line_length = 0;
631
632 info->flags |= FBINFO_MISC_TILEBLITTING;
633 info->tileops = &arkfb_tile_ops;
634
635 /* supports 8x16 tiles only */
636 info->pixmap.blit_x = 1 << (8 - 1);
637 info->pixmap.blit_y = 1 << (16 - 1);
638
639 offset_value = info->var.xres_virtual / 16;
640 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
641 }
642
643 info->var.xoffset = 0;
644 info->var.yoffset = 0;
645 info->var.activate = FB_ACTIVATE_NOW;
646
647 /* Unlock registers */
648 svga_wcrt_mask(0x11, 0x00, 0x80);
649
650 /* Blank screen and turn off sync */
651 svga_wseq_mask(0x01, 0x20, 0x20);
652 svga_wcrt_mask(0x17, 0x00, 0x80);
653
654 /* Set default values */
655 svga_set_default_gfx_regs();
656 svga_set_default_atc_regs();
657 svga_set_default_seq_regs();
658 svga_set_default_crt_regs();
659 svga_wcrt_multi(ark_line_compare_regs, 0xFFFFFFFF);
660 svga_wcrt_multi(ark_start_address_regs, 0);
661
662 /* ARK specific initialization */
663 svga_wseq_mask(0x10, 0x1F, 0x1F); /* enable linear framebuffer and full memory access */
664 svga_wseq_mask(0x12, 0x03, 0x03); /* 4 MB linear framebuffer size */
665
666 vga_wseq(NULL, 0x13, info->fix.smem_start >> 16);
667 vga_wseq(NULL, 0x14, info->fix.smem_start >> 24);
668 vga_wseq(NULL, 0x15, 0);
669 vga_wseq(NULL, 0x16, 0);
670
671 /* Set the FIFO threshold register */
672 /* It is fascinating way to store 5-bit value in 8-bit register */
673 regval = 0x10 | ((threshold & 0x0E) >> 1) | (threshold & 0x01) << 7 | (threshold & 0x10) << 1;
674 vga_wseq(NULL, 0x18, regval);
675
676 /* Set the offset register */
677 pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
678 svga_wcrt_multi(ark_offset_regs, offset_value);
679
680 /* fix for hi-res textmode */
681 svga_wcrt_mask(0x40, 0x08, 0x08);
682
683 if (info->var.vmode & FB_VMODE_DOUBLE)
684 svga_wcrt_mask(0x09, 0x80, 0x80);
685 else
686 svga_wcrt_mask(0x09, 0x00, 0x80);
687
688 if (info->var.vmode & FB_VMODE_INTERLACED)
689 svga_wcrt_mask(0x44, 0x04, 0x04);
690 else
691 svga_wcrt_mask(0x44, 0x00, 0x04);
692
693 hmul = 1;
694 hdiv = 1;
695 mode = svga_match_format(arkfb_formats, &(info->var), &(info->fix));
696
697 /* Set mode-specific register values */
698 switch (mode) {
699 case 0:
700 pr_debug("fb%d: text mode\n", info->node);
701 svga_set_textmode_vga_regs();
702
703 vga_wseq(NULL, 0x11, 0x10); /* basic VGA mode */
704 svga_wcrt_mask(0x46, 0x00, 0x04); /* 8bit pixel path */
705 dac_set_mode(par->dac, DAC_PSEUDO8_8);
706
707 break;
708 case 1:
709 pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
710 vga_wgfx(NULL, VGA_GFX_MODE, 0x40);
711
712 vga_wseq(NULL, 0x11, 0x10); /* basic VGA mode */
713 svga_wcrt_mask(0x46, 0x00, 0x04); /* 8bit pixel path */
714 dac_set_mode(par->dac, DAC_PSEUDO8_8);
715 break;
716 case 2:
717 pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
718
719 vga_wseq(NULL, 0x11, 0x10); /* basic VGA mode */
720 svga_wcrt_mask(0x46, 0x00, 0x04); /* 8bit pixel path */
721 dac_set_mode(par->dac, DAC_PSEUDO8_8);
722 break;
723 case 3:
724 pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
725
726 vga_wseq(NULL, 0x11, 0x16); /* 8bpp accel mode */
727
728 if (info->var.pixclock > 20000) {
729 pr_debug("fb%d: not using multiplex\n", info->node);
730 svga_wcrt_mask(0x46, 0x00, 0x04); /* 8bit pixel path */
731 dac_set_mode(par->dac, DAC_PSEUDO8_8);
732 } else {
733 pr_debug("fb%d: using multiplex\n", info->node);
734 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
735 dac_set_mode(par->dac, DAC_PSEUDO8_16);
736 hdiv = 2;
737 }
738 break;
739 case 4:
740 pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
741
742 vga_wseq(NULL, 0x11, 0x1A); /* 16bpp accel mode */
743 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
744 dac_set_mode(par->dac, DAC_RGB1555_16);
745 break;
746 case 5:
747 pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
748
749 vga_wseq(NULL, 0x11, 0x1A); /* 16bpp accel mode */
750 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
751 dac_set_mode(par->dac, DAC_RGB0565_16);
752 break;
753 case 6:
754 pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
755
756 vga_wseq(NULL, 0x11, 0x16); /* 8bpp accel mode ??? */
757 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
758 dac_set_mode(par->dac, DAC_RGB0888_16);
759 hmul = 3;
760 hdiv = 2;
761 break;
762 case 7:
763 pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
764
765 vga_wseq(NULL, 0x11, 0x1E); /* 32bpp accel mode */
766 svga_wcrt_mask(0x46, 0x04, 0x04); /* 16bit pixel path */
767 dac_set_mode(par->dac, DAC_RGB8888_16);
768 hmul = 2;
769 break;
770 default:
771 printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
772 return -EINVAL;
773 }
774
775 ark_set_pixclock(info, (hdiv * info->var.pixclock) / hmul);
776 svga_set_timings(&ark_timing_regs, &(info->var), hmul, hdiv,
777 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
778 (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
779 hmul, info->node);
780
781 /* Set interlaced mode start/end register */
782 value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
783 value = ((value * hmul / hdiv) / 8) - 5;
784 vga_wcrt(NULL, 0x42, (value + 1) / 2);
785
786 memset_io(info->screen_base, 0x00, screen_size);
787 /* Device and screen back on */
788 svga_wcrt_mask(0x17, 0x80, 0x80);
789 svga_wseq_mask(0x01, 0x00, 0x20);
790
791 return 0;
792}
793
794/* Set a colour register */
795
796static int arkfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
797 u_int transp, struct fb_info *fb)
798{
799 switch (fb->var.bits_per_pixel) {
800 case 0:
801 case 4:
802 if (regno >= 16)
803 return -EINVAL;
804
805 if ((fb->var.bits_per_pixel == 4) &&
806 (fb->var.nonstd == 0)) {
807 outb(0xF0, VGA_PEL_MSK);
808 outb(regno*16, VGA_PEL_IW);
809 } else {
810 outb(0x0F, VGA_PEL_MSK);
811 outb(regno, VGA_PEL_IW);
812 }
813 outb(red >> 10, VGA_PEL_D);
814 outb(green >> 10, VGA_PEL_D);
815 outb(blue >> 10, VGA_PEL_D);
816 break;
817 case 8:
818 if (regno >= 256)
819 return -EINVAL;
820
821 outb(0xFF, VGA_PEL_MSK);
822 outb(regno, VGA_PEL_IW);
823 outb(red >> 10, VGA_PEL_D);
824 outb(green >> 10, VGA_PEL_D);
825 outb(blue >> 10, VGA_PEL_D);
826 break;
827 case 16:
828 if (regno >= 16)
829 return 0;
830
831 if (fb->var.green.length == 5)
832 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
833 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
834 else if (fb->var.green.length == 6)
835 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
836 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
837 else
838 return -EINVAL;
839 break;
840 case 24:
841 case 32:
842 if (regno >= 16)
843 return 0;
844
845 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
846 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
847 break;
848 default:
849 return -EINVAL;
850 }
851
852 return 0;
853}
854
855/* Set the display blanking state */
856
857static int arkfb_blank(int blank_mode, struct fb_info *info)
858{
859 switch (blank_mode) {
860 case FB_BLANK_UNBLANK:
861 pr_debug("fb%d: unblank\n", info->node);
862 svga_wseq_mask(0x01, 0x00, 0x20);
863 svga_wcrt_mask(0x17, 0x80, 0x80);
864 break;
865 case FB_BLANK_NORMAL:
866 pr_debug("fb%d: blank\n", info->node);
867 svga_wseq_mask(0x01, 0x20, 0x20);
868 svga_wcrt_mask(0x17, 0x80, 0x80);
869 break;
870 case FB_BLANK_POWERDOWN:
871 case FB_BLANK_HSYNC_SUSPEND:
872 case FB_BLANK_VSYNC_SUSPEND:
873 pr_debug("fb%d: sync down\n", info->node);
874 svga_wseq_mask(0x01, 0x20, 0x20);
875 svga_wcrt_mask(0x17, 0x00, 0x80);
876 break;
877 }
878 return 0;
879}
880
881
882/* Pan the display */
883
884static int arkfb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
885{
886 unsigned int offset;
887
888 /* Calculate the offset */
889 if (var->bits_per_pixel == 0) {
890 offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
891 offset = offset >> 2;
892 } else {
893 offset = (var->yoffset * info->fix.line_length) +
894 (var->xoffset * var->bits_per_pixel / 8);
895 offset = offset >> ((var->bits_per_pixel == 4) ? 2 : 3);
896 }
897
898 /* Set the offset */
899 svga_wcrt_multi(ark_start_address_regs, offset);
900
901 return 0;
902}
903
904
905/* ------------------------------------------------------------------------- */
906
907
908/* Frame buffer operations */
909
910static struct fb_ops arkfb_ops = {
911 .owner = THIS_MODULE,
912 .fb_open = arkfb_open,
913 .fb_release = arkfb_release,
914 .fb_check_var = arkfb_check_var,
915 .fb_set_par = arkfb_set_par,
916 .fb_setcolreg = arkfb_setcolreg,
917 .fb_blank = arkfb_blank,
918 .fb_pan_display = arkfb_pan_display,
919 .fb_fillrect = arkfb_fillrect,
920 .fb_copyarea = cfb_copyarea,
921 .fb_imageblit = arkfb_imageblit,
922 .fb_get_caps = svga_get_caps,
923};
924
925
926/* ------------------------------------------------------------------------- */
927
928
929/* PCI probe */
930static int __devinit ark_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
931{
932 struct fb_info *info;
933 struct arkfb_info *par;
934 int rc;
935 u8 regval;
936
937 /* Ignore secondary VGA device because there is no VGA arbitration */
938 if (! svga_primary_device(dev)) {
939 dev_info(&(dev->dev), "ignoring secondary device\n");
940 return -ENODEV;
941 }
942
943 /* Allocate and fill driver data structure */
944 info = framebuffer_alloc(sizeof(struct arkfb_info), NULL);
945 if (! info) {
946 dev_err(&(dev->dev), "cannot allocate memory\n");
947 return -ENOMEM;
948 }
949
950 par = info->par;
951 mutex_init(&par->open_lock);
952
953 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
954 info->fbops = &arkfb_ops;
955
956 /* Prepare PCI device */
957 rc = pci_enable_device(dev);
958 if (rc < 0) {
959 dev_err(&(dev->dev), "cannot enable PCI device\n");
960 goto err_enable_device;
961 }
962
963 rc = pci_request_regions(dev, "arkfb");
964 if (rc < 0) {
965 dev_err(&(dev->dev), "cannot reserve framebuffer region\n");
966 goto err_request_regions;
967 }
968
969 par->dac = ics5342_init(ark_dac_read_regs, ark_dac_write_regs, info);
970 if (! par->dac) {
971 rc = -ENOMEM;
972 dev_err(&(dev->dev), "RAMDAC initialization failed\n");
973 goto err_dac;
974 }
975
976 info->fix.smem_start = pci_resource_start(dev, 0);
977 info->fix.smem_len = pci_resource_len(dev, 0);
978
979 /* Map physical IO memory address into kernel space */
980 info->screen_base = pci_iomap(dev, 0, 0);
981 if (! info->screen_base) {
982 rc = -ENOMEM;
983 dev_err(&(dev->dev), "iomap for framebuffer failed\n");
984 goto err_iomap;
985 }
986
987 /* FIXME get memsize */
988 regval = vga_rseq(NULL, 0x10);
989 info->screen_size = (1 << (regval >> 6)) << 20;
990 info->fix.smem_len = info->screen_size;
991
992 strcpy(info->fix.id, "ARK 2000PV");
993 info->fix.mmio_start = 0;
994 info->fix.mmio_len = 0;
995 info->fix.type = FB_TYPE_PACKED_PIXELS;
996 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
997 info->fix.ypanstep = 0;
998 info->fix.accel = FB_ACCEL_NONE;
999 info->pseudo_palette = (void*) (par->pseudo_palette);
1000
1001 /* Prepare startup mode */
1002 rc = fb_find_mode(&(info->var), info, mode, NULL, 0, NULL, 8);
1003 if (! ((rc == 1) || (rc == 2))) {
1004 rc = -EINVAL;
1005 dev_err(&(dev->dev), "mode %s not found\n", mode);
1006 goto err_find_mode;
1007 }
1008
1009 rc = fb_alloc_cmap(&info->cmap, 256, 0);
1010 if (rc < 0) {
1011 dev_err(&(dev->dev), "cannot allocate colormap\n");
1012 goto err_alloc_cmap;
1013 }
1014
1015 rc = register_framebuffer(info);
1016 if (rc < 0) {
1017 dev_err(&(dev->dev), "cannot register framebugger\n");
1018 goto err_reg_fb;
1019 }
1020
1021 printk(KERN_INFO "fb%d: %s on %s, %d MB RAM\n", info->node, info->fix.id,
1022 pci_name(dev), info->fix.smem_len >> 20);
1023
1024 /* Record a reference to the driver data */
1025 pci_set_drvdata(dev, info);
1026
1027#ifdef CONFIG_MTRR
1028 if (mtrr) {
1029 par->mtrr_reg = -1;
1030 par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
1031 }
1032#endif
1033
1034 return 0;
1035
1036 /* Error handling */
1037err_reg_fb:
1038 fb_dealloc_cmap(&info->cmap);
1039err_alloc_cmap:
1040err_find_mode:
1041 pci_iounmap(dev, info->screen_base);
1042err_iomap:
1043 dac_release(par->dac);
1044err_dac:
1045 pci_release_regions(dev);
1046err_request_regions:
1047/* pci_disable_device(dev); */
1048err_enable_device:
1049 framebuffer_release(info);
1050 return rc;
1051}
1052
1053/* PCI remove */
1054
1055static void __devexit ark_pci_remove(struct pci_dev *dev)
1056{
1057 struct fb_info *info = pci_get_drvdata(dev);
1058 struct arkfb_info *par = info->par;
1059
1060 if (info) {
1061#ifdef CONFIG_MTRR
1062 if (par->mtrr_reg >= 0) {
1063 mtrr_del(par->mtrr_reg, 0, 0);
1064 par->mtrr_reg = -1;
1065 }
1066#endif
1067
1068 dac_release(par->dac);
1069 unregister_framebuffer(info);
1070 fb_dealloc_cmap(&info->cmap);
1071
1072 pci_iounmap(dev, info->screen_base);
1073 pci_release_regions(dev);
1074/* pci_disable_device(dev); */
1075
1076 pci_set_drvdata(dev, NULL);
1077 framebuffer_release(info);
1078 }
1079}
1080
1081
1082#ifdef CONFIG_PM
1083/* PCI suspend */
1084
1085static int ark_pci_suspend (struct pci_dev* dev, pm_message_t state)
1086{
1087 struct fb_info *info = pci_get_drvdata(dev);
1088 struct arkfb_info *par = info->par;
1089
1090 dev_info(&(dev->dev), "suspend\n");
1091
1092 acquire_console_sem();
1093 mutex_lock(&(par->open_lock));
1094
1095 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
1096 mutex_unlock(&(par->open_lock));
1097 release_console_sem();
1098 return 0;
1099 }
1100
1101 fb_set_suspend(info, 1);
1102
1103 pci_save_state(dev);
1104 pci_disable_device(dev);
1105 pci_set_power_state(dev, pci_choose_state(dev, state));
1106
1107 mutex_unlock(&(par->open_lock));
1108 release_console_sem();
1109
1110 return 0;
1111}
1112
1113
1114/* PCI resume */
1115
1116static int ark_pci_resume (struct pci_dev* dev)
1117{
1118 struct fb_info *info = pci_get_drvdata(dev);
1119 struct arkfb_info *par = info->par;
1120
1121 dev_info(&(dev->dev), "resume\n");
1122
1123 acquire_console_sem();
1124 mutex_lock(&(par->open_lock));
1125
1126 if (par->ref_count == 0) {
1127 mutex_unlock(&(par->open_lock));
1128 release_console_sem();
1129 return 0;
1130 }
1131
1132 pci_set_power_state(dev, PCI_D0);
1133 pci_restore_state(dev);
1134
1135 if (pci_enable_device(dev))
1136 goto fail;
1137
1138 pci_set_master(dev);
1139
1140 arkfb_set_par(info);
1141 fb_set_suspend(info, 0);
1142
1143 mutex_unlock(&(par->open_lock));
1144fail:
1145 release_console_sem();
1146 return 0;
1147}
1148#else
1149#define ark_pci_suspend NULL
1150#define ark_pci_resume NULL
1151#endif /* CONFIG_PM */
1152
1153/* List of boards that we are trying to support */
1154
1155static struct pci_device_id ark_devices[] __devinitdata = {
1156 {PCI_DEVICE(0xEDD8, 0xA099)},
1157 {0, 0, 0, 0, 0, 0, 0}
1158};
1159
1160
1161MODULE_DEVICE_TABLE(pci, ark_devices);
1162
1163static struct pci_driver arkfb_pci_driver = {
1164 .name = "arkfb",
1165 .id_table = ark_devices,
1166 .probe = ark_pci_probe,
1167 .remove = __devexit_p(ark_pci_remove),
1168 .suspend = ark_pci_suspend,
1169 .resume = ark_pci_resume,
1170};
1171
1172/* Cleanup */
1173
1174static void __exit arkfb_cleanup(void)
1175{
1176 pr_debug("arkfb: cleaning up\n");
1177 pci_unregister_driver(&arkfb_pci_driver);
1178}
1179
1180/* Driver Initialisation */
1181
1182static int __init arkfb_init(void)
1183{
1184
1185#ifndef MODULE
1186 char *option = NULL;
1187
1188 if (fb_get_options("arkfb", &option))
1189 return -ENODEV;
1190
1191 if (option && *option)
1192 mode = option;
1193#endif
1194
1195 pr_debug("arkfb: initializing\n");
1196 return pci_register_driver(&arkfb_pci_driver);
1197}
1198
1199module_init(arkfb_init);
1200module_exit(arkfb_cleanup);
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
new file mode 100644
index 000000000000..e1d5bd0c98c4
--- /dev/null
+++ b/drivers/video/atmel_lcdfb.c
@@ -0,0 +1,752 @@
1/*
2 * Driver for AT91/AT32 LCD Controller
3 *
4 * Copyright (C) 2007 Atmel Corporation
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive for
8 * more details.
9 */
10
11#include <linux/kernel.h>
12#include <linux/platform_device.h>
13#include <linux/dma-mapping.h>
14#include <linux/interrupt.h>
15#include <linux/clk.h>
16#include <linux/fb.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19
20#include <asm/arch/board.h>
21#include <asm/arch/cpu.h>
22#include <asm/arch/gpio.h>
23
24#include <video/atmel_lcdc.h>
25
26#define lcdc_readl(sinfo, reg) __raw_readl((sinfo)->mmio+(reg))
27#define lcdc_writel(sinfo, reg, val) __raw_writel((val), (sinfo)->mmio+(reg))
28
29/* configurable parameters */
30#define ATMEL_LCDC_CVAL_DEFAULT 0xc8
31#define ATMEL_LCDC_DMA_BURST_LEN 8
32
33#if defined(CONFIG_ARCH_AT91SAM9263)
34#define ATMEL_LCDC_FIFO_SIZE 2048
35#else
36#define ATMEL_LCDC_FIFO_SIZE 512
37#endif
38
39#if defined(CONFIG_ARCH_AT91)
40#define ATMEL_LCDFB_FBINFO_DEFAULT FBINFO_DEFAULT
41
42static inline void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
43 struct fb_var_screeninfo *var)
44{
45
46}
47#elif defined(CONFIG_AVR32)
48#define ATMEL_LCDFB_FBINFO_DEFAULT (FBINFO_DEFAULT \
49 | FBINFO_PARTIAL_PAN_OK \
50 | FBINFO_HWACCEL_XPAN \
51 | FBINFO_HWACCEL_YPAN)
52
53static void atmel_lcdfb_update_dma2d(struct atmel_lcdfb_info *sinfo,
54 struct fb_var_screeninfo *var)
55{
56 u32 dma2dcfg;
57 u32 pixeloff;
58
59 pixeloff = (var->xoffset * var->bits_per_pixel) & 0x1f;
60
61 dma2dcfg = ((var->xres_virtual - var->xres) * var->bits_per_pixel) / 8;
62 dma2dcfg |= pixeloff << ATMEL_LCDC_PIXELOFF_OFFSET;
63 lcdc_writel(sinfo, ATMEL_LCDC_DMA2DCFG, dma2dcfg);
64
65 /* Update configuration */
66 lcdc_writel(sinfo, ATMEL_LCDC_DMACON,
67 lcdc_readl(sinfo, ATMEL_LCDC_DMACON)
68 | ATMEL_LCDC_DMAUPDT);
69}
70#endif
71
72
73static struct fb_fix_screeninfo atmel_lcdfb_fix __initdata = {
74 .type = FB_TYPE_PACKED_PIXELS,
75 .visual = FB_VISUAL_TRUECOLOR,
76 .xpanstep = 0,
77 .ypanstep = 0,
78 .ywrapstep = 0,
79 .accel = FB_ACCEL_NONE,
80};
81
82
83static void atmel_lcdfb_update_dma(struct fb_info *info,
84 struct fb_var_screeninfo *var)
85{
86 struct atmel_lcdfb_info *sinfo = info->par;
87 struct fb_fix_screeninfo *fix = &info->fix;
88 unsigned long dma_addr;
89
90 dma_addr = (fix->smem_start + var->yoffset * fix->line_length
91 + var->xoffset * var->bits_per_pixel / 8);
92
93 dma_addr &= ~3UL;
94
95 /* Set framebuffer DMA base address and pixel offset */
96 lcdc_writel(sinfo, ATMEL_LCDC_DMABADDR1, dma_addr);
97
98 atmel_lcdfb_update_dma2d(sinfo, var);
99}
100
101static inline void atmel_lcdfb_free_video_memory(struct atmel_lcdfb_info *sinfo)
102{
103 struct fb_info *info = sinfo->info;
104
105 dma_free_writecombine(info->device, info->fix.smem_len,
106 info->screen_base, info->fix.smem_start);
107}
108
109/**
110 * atmel_lcdfb_alloc_video_memory - Allocate framebuffer memory
111 * @sinfo: the frame buffer to allocate memory for
112 */
113static int atmel_lcdfb_alloc_video_memory(struct atmel_lcdfb_info *sinfo)
114{
115 struct fb_info *info = sinfo->info;
116 struct fb_var_screeninfo *var = &info->var;
117
118 info->fix.smem_len = (var->xres_virtual * var->yres_virtual
119 * ((var->bits_per_pixel + 7) / 8));
120
121 info->screen_base = dma_alloc_writecombine(info->device, info->fix.smem_len,
122 (dma_addr_t *)&info->fix.smem_start, GFP_KERNEL);
123
124 if (!info->screen_base) {
125 return -ENOMEM;
126 }
127
128 return 0;
129}
130
131/**
132 * atmel_lcdfb_check_var - Validates a var passed in.
133 * @var: frame buffer variable screen structure
134 * @info: frame buffer structure that represents a single frame buffer
135 *
136 * Checks to see if the hardware supports the state requested by
137 * var passed in. This function does not alter the hardware
138 * state!!! This means the data stored in struct fb_info and
139 * struct atmel_lcdfb_info do not change. This includes the var
140 * inside of struct fb_info. Do NOT change these. This function
141 * can be called on its own if we intent to only test a mode and
142 * not actually set it. The stuff in modedb.c is a example of
143 * this. If the var passed in is slightly off by what the
144 * hardware can support then we alter the var PASSED in to what
145 * we can do. If the hardware doesn't support mode change a
146 * -EINVAL will be returned by the upper layers. You don't need
147 * to implement this function then. If you hardware doesn't
148 * support changing the resolution then this function is not
149 * needed. In this case the driver would just provide a var that
150 * represents the static state the screen is in.
151 *
152 * Returns negative errno on error, or zero on success.
153 */
154static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
155 struct fb_info *info)
156{
157 struct device *dev = info->device;
158 struct atmel_lcdfb_info *sinfo = info->par;
159 unsigned long clk_value_khz;
160
161 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
162
163 dev_dbg(dev, "%s:\n", __func__);
164 dev_dbg(dev, " resolution: %ux%u\n", var->xres, var->yres);
165 dev_dbg(dev, " pixclk: %lu KHz\n", PICOS2KHZ(var->pixclock));
166 dev_dbg(dev, " bpp: %u\n", var->bits_per_pixel);
167 dev_dbg(dev, " clk: %lu KHz\n", clk_value_khz);
168
169 if ((PICOS2KHZ(var->pixclock) * var->bits_per_pixel / 8) > clk_value_khz) {
170 dev_err(dev, "%lu KHz pixel clock is too fast\n", PICOS2KHZ(var->pixclock));
171 return -EINVAL;
172 }
173
174 /* Force same alignment for each line */
175 var->xres = (var->xres + 3) & ~3UL;
176 var->xres_virtual = (var->xres_virtual + 3) & ~3UL;
177
178 var->red.msb_right = var->green.msb_right = var->blue.msb_right = 0;
179 var->transp.msb_right = 0;
180 var->transp.offset = var->transp.length = 0;
181 var->xoffset = var->yoffset = 0;
182
183 switch (var->bits_per_pixel) {
184 case 2:
185 case 4:
186 case 8:
187 var->red.offset = var->green.offset = var->blue.offset = 0;
188 var->red.length = var->green.length = var->blue.length
189 = var->bits_per_pixel;
190 break;
191 case 15:
192 case 16:
193 var->red.offset = 0;
194 var->green.offset = 5;
195 var->blue.offset = 10;
196 var->red.length = var->green.length = var->blue.length = 5;
197 break;
198 case 24:
199 case 32:
200 var->red.offset = 0;
201 var->green.offset = 8;
202 var->blue.offset = 16;
203 var->red.length = var->green.length = var->blue.length = 8;
204 break;
205 default:
206 dev_err(dev, "color depth %d not supported\n",
207 var->bits_per_pixel);
208 return -EINVAL;
209 }
210
211 return 0;
212}
213
214/**
215 * atmel_lcdfb_set_par - Alters the hardware state.
216 * @info: frame buffer structure that represents a single frame buffer
217 *
218 * Using the fb_var_screeninfo in fb_info we set the resolution
219 * of the this particular framebuffer. This function alters the
220 * par AND the fb_fix_screeninfo stored in fb_info. It doesn't
221 * not alter var in fb_info since we are using that data. This
222 * means we depend on the data in var inside fb_info to be
223 * supported by the hardware. atmel_lcdfb_check_var is always called
224 * before atmel_lcdfb_set_par to ensure this. Again if you can't
225 * change the resolution you don't need this function.
226 *
227 */
228static int atmel_lcdfb_set_par(struct fb_info *info)
229{
230 struct atmel_lcdfb_info *sinfo = info->par;
231 unsigned long value;
232 unsigned long clk_value_khz;
233
234 dev_dbg(info->device, "%s:\n", __func__);
235 dev_dbg(info->device, " * resolution: %ux%u (%ux%u virtual)\n",
236 info->var.xres, info->var.yres,
237 info->var.xres_virtual, info->var.yres_virtual);
238
239 /* Turn off the LCD controller and the DMA controller */
240 lcdc_writel(sinfo, ATMEL_LCDC_PWRCON, sinfo->guard_time << ATMEL_LCDC_GUARDT_OFFSET);
241
242 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, 0);
243
244 if (info->var.bits_per_pixel <= 8)
245 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
246 else
247 info->fix.visual = FB_VISUAL_TRUECOLOR;
248
249 info->fix.line_length = info->var.xres_virtual * (info->var.bits_per_pixel / 8);
250
251 /* Re-initialize the DMA engine... */
252 dev_dbg(info->device, " * update DMA engine\n");
253 atmel_lcdfb_update_dma(info, &info->var);
254
255 /* ...set frame size and burst length = 8 words (?) */
256 value = (info->var.yres * info->var.xres * info->var.bits_per_pixel) / 32;
257 value |= ((ATMEL_LCDC_DMA_BURST_LEN - 1) << ATMEL_LCDC_BLENGTH_OFFSET);
258 lcdc_writel(sinfo, ATMEL_LCDC_DMAFRMCFG, value);
259
260 /* Now, the LCDC core... */
261
262 /* Set pixel clock */
263 clk_value_khz = clk_get_rate(sinfo->lcdc_clk) / 1000;
264
265 value = clk_value_khz / PICOS2KHZ(info->var.pixclock);
266
267 if (clk_value_khz % PICOS2KHZ(info->var.pixclock))
268 value++;
269
270 value = (value / 2) - 1;
271
272 if (value <= 0) {
273 dev_notice(info->device, "Bypassing pixel clock divider\n");
274 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, ATMEL_LCDC_BYPASS);
275 } else
276 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON1, value << ATMEL_LCDC_CLKVAL_OFFSET);
277
278 /* Initialize control register 2 */
279 value = sinfo->default_lcdcon2;
280
281 if (!(info->var.sync & FB_SYNC_HOR_HIGH_ACT))
282 value |= ATMEL_LCDC_INVLINE_INVERTED;
283 if (!(info->var.sync & FB_SYNC_VERT_HIGH_ACT))
284 value |= ATMEL_LCDC_INVFRAME_INVERTED;
285
286 switch (info->var.bits_per_pixel) {
287 case 1: value |= ATMEL_LCDC_PIXELSIZE_1; break;
288 case 2: value |= ATMEL_LCDC_PIXELSIZE_2; break;
289 case 4: value |= ATMEL_LCDC_PIXELSIZE_4; break;
290 case 8: value |= ATMEL_LCDC_PIXELSIZE_8; break;
291 case 15: /* fall through */
292 case 16: value |= ATMEL_LCDC_PIXELSIZE_16; break;
293 case 24: value |= ATMEL_LCDC_PIXELSIZE_24; break;
294 case 32: value |= ATMEL_LCDC_PIXELSIZE_32; break;
295 default: BUG(); break;
296 }
297 dev_dbg(info->device, " * LCDCON2 = %08lx\n", value);
298 lcdc_writel(sinfo, ATMEL_LCDC_LCDCON2, value);
299
300 /* Vertical timing */
301 value = (info->var.vsync_len - 1) << ATMEL_LCDC_VPW_OFFSET;
302 value |= info->var.upper_margin << ATMEL_LCDC_VBP_OFFSET;
303 value |= info->var.lower_margin;
304 dev_dbg(info->device, " * LCDTIM1 = %08lx\n", value);
305 lcdc_writel(sinfo, ATMEL_LCDC_TIM1, value);
306
307 /* Horizontal timing */
308 value = (info->var.right_margin - 1) << ATMEL_LCDC_HFP_OFFSET;
309 value |= (info->var.hsync_len - 1) << ATMEL_LCDC_HPW_OFFSET;
310 value |= (info->var.left_margin - 1);
311 dev_dbg(info->device, " * LCDTIM2 = %08lx\n", value);
312 lcdc_writel(sinfo, ATMEL_LCDC_TIM2, value);
313
314 /* Display size */
315 value = (info->var.xres - 1) << ATMEL_LCDC_HOZVAL_OFFSET;
316 value |= info->var.yres - 1;
317 lcdc_writel(sinfo, ATMEL_LCDC_LCDFRMCFG, value);
318
319 /* FIFO Threshold: Use formula from data sheet */
320 value = ATMEL_LCDC_FIFO_SIZE - (2 * ATMEL_LCDC_DMA_BURST_LEN + 3);
321 lcdc_writel(sinfo, ATMEL_LCDC_FIFO, value);
322
323 /* Toggle LCD_MODE every frame */
324 lcdc_writel(sinfo, ATMEL_LCDC_MVAL, 0);
325
326 /* Disable all interrupts */
327 lcdc_writel(sinfo, ATMEL_LCDC_IDR, ~0UL);
328
329 /* Set contrast */
330 value = ATMEL_LCDC_PS_DIV8 | ATMEL_LCDC_POL_POSITIVE | ATMEL_LCDC_ENA_PWMENABLE;
331 lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_CTR, value);
332 lcdc_writel(sinfo, ATMEL_LCDC_CONTRAST_VAL, ATMEL_LCDC_CVAL_DEFAULT);
333 /* ...wait for DMA engine to become idle... */
334 while (lcdc_readl(sinfo, ATMEL_LCDC_DMACON) & ATMEL_LCDC_DMABUSY)
335 msleep(10);
336
337 dev_dbg(info->device, " * re-enable DMA engine\n");
338 /* ...and enable it with updated configuration */
339 lcdc_writel(sinfo, ATMEL_LCDC_DMACON, sinfo->default_dmacon);
340
341 dev_dbg(info->device, " * re-enable LCDC core\n");
342 lcdc_writel(sinfo, ATMEL_LCDC_PWRCON,
343 (sinfo->guard_time << ATMEL_LCDC_GUARDT_OFFSET) | ATMEL_LCDC_PWR);
344
345 dev_dbg(info->device, " * DONE\n");
346
347 return 0;
348}
349
350static inline unsigned int chan_to_field(unsigned int chan, const struct fb_bitfield *bf)
351{
352 chan &= 0xffff;
353 chan >>= 16 - bf->length;
354 return chan << bf->offset;
355}
356
357/**
358 * atmel_lcdfb_setcolreg - Optional function. Sets a color register.
359 * @regno: Which register in the CLUT we are programming
360 * @red: The red value which can be up to 16 bits wide
361 * @green: The green value which can be up to 16 bits wide
362 * @blue: The blue value which can be up to 16 bits wide.
363 * @transp: If supported the alpha value which can be up to 16 bits wide.
364 * @info: frame buffer info structure
365 *
366 * Set a single color register. The values supplied have a 16 bit
367 * magnitude which needs to be scaled in this function for the hardware.
368 * Things to take into consideration are how many color registers, if
369 * any, are supported with the current color visual. With truecolor mode
370 * no color palettes are supported. Here a psuedo palette is created
371 * which we store the value in pseudo_palette in struct fb_info. For
372 * pseudocolor mode we have a limited color palette. To deal with this
373 * we can program what color is displayed for a particular pixel value.
374 * DirectColor is similar in that we can program each color field. If
375 * we have a static colormap we don't need to implement this function.
376 *
377 * Returns negative errno on error, or zero on success. In an
378 * ideal world, this would have been the case, but as it turns
379 * out, the other drivers return 1 on failure, so that's what
380 * we're going to do.
381 */
382static int atmel_lcdfb_setcolreg(unsigned int regno, unsigned int red,
383 unsigned int green, unsigned int blue,
384 unsigned int transp, struct fb_info *info)
385{
386 struct atmel_lcdfb_info *sinfo = info->par;
387 unsigned int val;
388 u32 *pal;
389 int ret = 1;
390
391 if (info->var.grayscale)
392 red = green = blue = (19595 * red + 38470 * green
393 + 7471 * blue) >> 16;
394
395 switch (info->fix.visual) {
396 case FB_VISUAL_TRUECOLOR:
397 if (regno < 16) {
398 pal = info->pseudo_palette;
399
400 val = chan_to_field(red, &info->var.red);
401 val |= chan_to_field(green, &info->var.green);
402 val |= chan_to_field(blue, &info->var.blue);
403
404 pal[regno] = val;
405 ret = 0;
406 }
407 break;
408
409 case FB_VISUAL_PSEUDOCOLOR:
410 if (regno < 256) {
411 val = ((red >> 11) & 0x001f);
412 val |= ((green >> 6) & 0x03e0);
413 val |= ((blue >> 1) & 0x7c00);
414
415 /*
416 * TODO: intensity bit. Maybe something like
417 * ~(red[10] ^ green[10] ^ blue[10]) & 1
418 */
419
420 lcdc_writel(sinfo, ATMEL_LCDC_LUT(regno), val);
421 ret = 0;
422 }
423 break;
424 }
425
426 return ret;
427}
428
429static int atmel_lcdfb_pan_display(struct fb_var_screeninfo *var,
430 struct fb_info *info)
431{
432 dev_dbg(info->device, "%s\n", __func__);
433
434 atmel_lcdfb_update_dma(info, var);
435
436 return 0;
437}
438
439static struct fb_ops atmel_lcdfb_ops = {
440 .owner = THIS_MODULE,
441 .fb_check_var = atmel_lcdfb_check_var,
442 .fb_set_par = atmel_lcdfb_set_par,
443 .fb_setcolreg = atmel_lcdfb_setcolreg,
444 .fb_pan_display = atmel_lcdfb_pan_display,
445 .fb_fillrect = cfb_fillrect,
446 .fb_copyarea = cfb_copyarea,
447 .fb_imageblit = cfb_imageblit,
448};
449
450static irqreturn_t atmel_lcdfb_interrupt(int irq, void *dev_id)
451{
452 struct fb_info *info = dev_id;
453 struct atmel_lcdfb_info *sinfo = info->par;
454 u32 status;
455
456 status = lcdc_readl(sinfo, ATMEL_LCDC_ISR);
457 lcdc_writel(sinfo, ATMEL_LCDC_IDR, status);
458 return IRQ_HANDLED;
459}
460
461static int __init atmel_lcdfb_init_fbinfo(struct atmel_lcdfb_info *sinfo)
462{
463 struct fb_info *info = sinfo->info;
464 int ret = 0;
465
466 memset_io(info->screen_base, 0, info->fix.smem_len);
467 info->var.activate |= FB_ACTIVATE_FORCE | FB_ACTIVATE_NOW;
468
469 dev_info(info->device,
470 "%luKiB frame buffer at %08lx (mapped at %p)\n",
471 (unsigned long)info->fix.smem_len / 1024,
472 (unsigned long)info->fix.smem_start,
473 info->screen_base);
474
475 /* Allocate colormap */
476 ret = fb_alloc_cmap(&info->cmap, 256, 0);
477 if (ret < 0)
478 dev_err(info->device, "Alloc color map failed\n");
479
480 return ret;
481}
482
483static void atmel_lcdfb_start_clock(struct atmel_lcdfb_info *sinfo)
484{
485 if (sinfo->bus_clk)
486 clk_enable(sinfo->bus_clk);
487 clk_enable(sinfo->lcdc_clk);
488}
489
490static void atmel_lcdfb_stop_clock(struct atmel_lcdfb_info *sinfo)
491{
492 if (sinfo->bus_clk)
493 clk_disable(sinfo->bus_clk);
494 clk_disable(sinfo->lcdc_clk);
495}
496
497
498static int __init atmel_lcdfb_probe(struct platform_device *pdev)
499{
500 struct device *dev = &pdev->dev;
501 struct fb_info *info;
502 struct atmel_lcdfb_info *sinfo;
503 struct atmel_lcdfb_info *pdata_sinfo;
504 struct resource *regs = NULL;
505 struct resource *map = NULL;
506 int ret;
507
508 dev_dbg(dev, "%s BEGIN\n", __func__);
509
510 ret = -ENOMEM;
511 info = framebuffer_alloc(sizeof(struct atmel_lcdfb_info), dev);
512 if (!info) {
513 dev_err(dev, "cannot allocate memory\n");
514 goto out;
515 }
516
517 sinfo = info->par;
518
519 if (dev->platform_data) {
520 pdata_sinfo = (struct atmel_lcdfb_info *)dev->platform_data;
521 sinfo->default_bpp = pdata_sinfo->default_bpp;
522 sinfo->default_dmacon = pdata_sinfo->default_dmacon;
523 sinfo->default_lcdcon2 = pdata_sinfo->default_lcdcon2;
524 sinfo->default_monspecs = pdata_sinfo->default_monspecs;
525 sinfo->atmel_lcdfb_power_control = pdata_sinfo->atmel_lcdfb_power_control;
526 sinfo->guard_time = pdata_sinfo->guard_time;
527 } else {
528 dev_err(dev, "cannot get default configuration\n");
529 goto free_info;
530 }
531 sinfo->info = info;
532 sinfo->pdev = pdev;
533
534 strcpy(info->fix.id, sinfo->pdev->name);
535 info->flags = ATMEL_LCDFB_FBINFO_DEFAULT;
536 info->pseudo_palette = sinfo->pseudo_palette;
537 info->fbops = &atmel_lcdfb_ops;
538
539 memcpy(&info->monspecs, sinfo->default_monspecs, sizeof(info->monspecs));
540 info->fix = atmel_lcdfb_fix;
541
542 /* Enable LCDC Clocks */
543 if (cpu_is_at91sam9261() || cpu_is_at32ap7000()) {
544 sinfo->bus_clk = clk_get(dev, "hck1");
545 if (IS_ERR(sinfo->bus_clk)) {
546 ret = PTR_ERR(sinfo->bus_clk);
547 goto free_info;
548 }
549 }
550 sinfo->lcdc_clk = clk_get(dev, "lcdc_clk");
551 if (IS_ERR(sinfo->lcdc_clk)) {
552 ret = PTR_ERR(sinfo->lcdc_clk);
553 goto put_bus_clk;
554 }
555 atmel_lcdfb_start_clock(sinfo);
556
557 ret = fb_find_mode(&info->var, info, NULL, info->monspecs.modedb,
558 info->monspecs.modedb_len, info->monspecs.modedb,
559 sinfo->default_bpp);
560 if (!ret) {
561 dev_err(dev, "no suitable video mode found\n");
562 goto stop_clk;
563 }
564
565
566 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
567 if (!regs) {
568 dev_err(dev, "resources unusable\n");
569 ret = -ENXIO;
570 goto stop_clk;
571 }
572
573 sinfo->irq_base = platform_get_irq(pdev, 0);
574 if (sinfo->irq_base < 0) {
575 dev_err(dev, "unable to get irq\n");
576 ret = sinfo->irq_base;
577 goto stop_clk;
578 }
579
580 /* Initialize video memory */
581 map = platform_get_resource(pdev, IORESOURCE_MEM, 1);
582 if (map) {
583 /* use a pre-allocated memory buffer */
584 info->fix.smem_start = map->start;
585 info->fix.smem_len = map->end - map->start + 1;
586 if (!request_mem_region(info->fix.smem_start,
587 info->fix.smem_len, pdev->name)) {
588 ret = -EBUSY;
589 goto stop_clk;
590 }
591
592 info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
593 if (!info->screen_base)
594 goto release_intmem;
595 } else {
596 /* alocate memory buffer */
597 ret = atmel_lcdfb_alloc_video_memory(sinfo);
598 if (ret < 0) {
599 dev_err(dev, "cannot allocate framebuffer: %d\n", ret);
600 goto stop_clk;
601 }
602 }
603
604 /* LCDC registers */
605 info->fix.mmio_start = regs->start;
606 info->fix.mmio_len = regs->end - regs->start + 1;
607
608 if (!request_mem_region(info->fix.mmio_start,
609 info->fix.mmio_len, pdev->name)) {
610 ret = -EBUSY;
611 goto free_fb;
612 }
613
614 sinfo->mmio = ioremap(info->fix.mmio_start, info->fix.mmio_len);
615 if (!sinfo->mmio) {
616 dev_err(dev, "cannot map LCDC registers\n");
617 goto release_mem;
618 }
619
620 /* interrupt */
621 ret = request_irq(sinfo->irq_base, atmel_lcdfb_interrupt, 0, pdev->name, info);
622 if (ret) {
623 dev_err(dev, "request_irq failed: %d\n", ret);
624 goto unmap_mmio;
625 }
626
627 ret = atmel_lcdfb_init_fbinfo(sinfo);
628 if (ret < 0) {
629 dev_err(dev, "init fbinfo failed: %d\n", ret);
630 goto unregister_irqs;
631 }
632
633 /*
634 * This makes sure that our colour bitfield
635 * descriptors are correctly initialised.
636 */
637 atmel_lcdfb_check_var(&info->var, info);
638
639 ret = fb_set_var(info, &info->var);
640 if (ret) {
641 dev_warn(dev, "unable to set display parameters\n");
642 goto free_cmap;
643 }
644
645 dev_set_drvdata(dev, info);
646
647 /*
648 * Tell the world that we're ready to go
649 */
650 ret = register_framebuffer(info);
651 if (ret < 0) {
652 dev_err(dev, "failed to register framebuffer device: %d\n", ret);
653 goto free_cmap;
654 }
655
656 /* Power up the LCDC screen */
657 if (sinfo->atmel_lcdfb_power_control)
658 sinfo->atmel_lcdfb_power_control(1);
659
660 dev_info(dev, "fb%d: Atmel LCDC at 0x%08lx (mapped at %p), irq %lu\n",
661 info->node, info->fix.mmio_start, sinfo->mmio, sinfo->irq_base);
662
663 return 0;
664
665
666free_cmap:
667 fb_dealloc_cmap(&info->cmap);
668unregister_irqs:
669 free_irq(sinfo->irq_base, info);
670unmap_mmio:
671 iounmap(sinfo->mmio);
672release_mem:
673 release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
674free_fb:
675 if (map)
676 iounmap(info->screen_base);
677 else
678 atmel_lcdfb_free_video_memory(sinfo);
679
680release_intmem:
681 if (map)
682 release_mem_region(info->fix.smem_start, info->fix.smem_len);
683stop_clk:
684 atmel_lcdfb_stop_clock(sinfo);
685 clk_put(sinfo->lcdc_clk);
686put_bus_clk:
687 if (sinfo->bus_clk)
688 clk_put(sinfo->bus_clk);
689free_info:
690 framebuffer_release(info);
691out:
692 dev_dbg(dev, "%s FAILED\n", __func__);
693 return ret;
694}
695
696static int __exit atmel_lcdfb_remove(struct platform_device *pdev)
697{
698 struct device *dev = &pdev->dev;
699 struct fb_info *info = dev_get_drvdata(dev);
700 struct atmel_lcdfb_info *sinfo = info->par;
701
702 if (!sinfo)
703 return 0;
704
705 if (sinfo->atmel_lcdfb_power_control)
706 sinfo->atmel_lcdfb_power_control(0);
707 unregister_framebuffer(info);
708 atmel_lcdfb_stop_clock(sinfo);
709 clk_put(sinfo->lcdc_clk);
710 if (sinfo->bus_clk)
711 clk_put(sinfo->bus_clk);
712 fb_dealloc_cmap(&info->cmap);
713 free_irq(sinfo->irq_base, info);
714 iounmap(sinfo->mmio);
715 release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
716 if (platform_get_resource(pdev, IORESOURCE_MEM, 1)) {
717 iounmap(info->screen_base);
718 release_mem_region(info->fix.smem_start, info->fix.smem_len);
719 } else {
720 atmel_lcdfb_free_video_memory(sinfo);
721 }
722
723 dev_set_drvdata(dev, NULL);
724 framebuffer_release(info);
725
726 return 0;
727}
728
729static struct platform_driver atmel_lcdfb_driver = {
730 .remove = __exit_p(atmel_lcdfb_remove),
731 .driver = {
732 .name = "atmel_lcdfb",
733 .owner = THIS_MODULE,
734 },
735};
736
737static int __init atmel_lcdfb_init(void)
738{
739 return platform_driver_probe(&atmel_lcdfb_driver, atmel_lcdfb_probe);
740}
741
742static void __exit atmel_lcdfb_exit(void)
743{
744 platform_driver_unregister(&atmel_lcdfb_driver);
745}
746
747module_init(atmel_lcdfb_init);
748module_exit(atmel_lcdfb_exit);
749
750MODULE_DESCRIPTION("AT91/AT32 LCD Controller framebuffer driver");
751MODULE_AUTHOR("Nicolas Ferre <nicolas.ferre@rfo.atmel.com>");
752MODULE_LICENSE("GPL");
diff --git a/drivers/video/aty/ati_ids.h b/drivers/video/aty/ati_ids.h
index 39ab483fc250..90e7df22f508 100644
--- a/drivers/video/aty/ati_ids.h
+++ b/drivers/video/aty/ati_ids.h
@@ -209,4 +209,4 @@
209#define PCI_CHIP_R423_5D57 0x5D57 209#define PCI_CHIP_R423_5D57 0x5D57
210#define PCI_CHIP_RS350_7834 0x7834 210#define PCI_CHIP_RS350_7834 0x7834
211#define PCI_CHIP_RS350_7835 0x7835 211#define PCI_CHIP_RS350_7835 0x7835
212 212#define PCI_CHIP_RS480_5955 0x5955
diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
index e86d7e0c9825..7fea4d8ae8e2 100644
--- a/drivers/video/aty/aty128fb.c
+++ b/drivers/video/aty/aty128fb.c
@@ -2165,18 +2165,29 @@ static void __devexit aty128_remove(struct pci_dev *pdev)
2165static int aty128fb_blank(int blank, struct fb_info *fb) 2165static int aty128fb_blank(int blank, struct fb_info *fb)
2166{ 2166{
2167 struct aty128fb_par *par = fb->par; 2167 struct aty128fb_par *par = fb->par;
2168 u8 state = 0; 2168 u8 state;
2169 2169
2170 if (par->lock_blank || par->asleep) 2170 if (par->lock_blank || par->asleep)
2171 return 0; 2171 return 0;
2172 2172
2173 if (blank & FB_BLANK_VSYNC_SUSPEND) 2173 switch (blank) {
2174 state |= 2; 2174 case FB_BLANK_NORMAL:
2175 if (blank & FB_BLANK_HSYNC_SUSPEND) 2175 state = 4;
2176 state |= 1; 2176 break;
2177 if (blank & FB_BLANK_POWERDOWN) 2177 case FB_BLANK_VSYNC_SUSPEND:
2178 state |= 4; 2178 state = 6;
2179 2179 break;
2180 case FB_BLANK_HSYNC_SUSPEND:
2181 state = 5;
2182 break;
2183 case FB_BLANK_POWERDOWN:
2184 state = 7;
2185 break;
2186 case FB_BLANK_UNBLANK:
2187 default:
2188 state = 0;
2189 break;
2190 }
2180 aty_st_8(CRTC_EXT_CNTL+1, state); 2191 aty_st_8(CRTC_EXT_CNTL+1, state);
2181 2192
2182 if (par->chip_gen == rage_M3) { 2193 if (par->chip_gen == rage_M3) {
@@ -2430,7 +2441,7 @@ static int aty128_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2430 wait_for_idle(par); 2441 wait_for_idle(par);
2431 2442
2432 /* Blank display and LCD */ 2443 /* Blank display and LCD */
2433 aty128fb_blank(VESA_POWERDOWN, info); 2444 aty128fb_blank(FB_BLANK_POWERDOWN, info);
2434 2445
2435 /* Sleep */ 2446 /* Sleep */
2436 par->asleep = 1; 2447 par->asleep = 1;
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index 8514f2a6f060..8d3455da663a 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -80,8 +80,9 @@
80#include "../macmodes.h" 80#include "../macmodes.h"
81#endif 81#endif
82#ifdef __sparc__ 82#ifdef __sparc__
83#include <asm/pbm.h>
84#include <asm/fbio.h> 83#include <asm/fbio.h>
84#include <asm/oplib.h>
85#include <asm/prom.h>
85#endif 86#endif
86 87
87#ifdef CONFIG_ADB_PMU 88#ifdef CONFIG_ADB_PMU
@@ -2297,20 +2298,6 @@ static int __devinit aty_init(struct fb_info *info)
2297 par->pll_limits.xclk = 53; 2298 par->pll_limits.xclk = 53;
2298 } 2299 }
2299#endif 2300#endif
2300 if (pll)
2301 par->pll_limits.pll_max = pll;
2302 if (mclk)
2303 par->pll_limits.mclk = mclk;
2304 if (xclk)
2305 par->pll_limits.xclk = xclk;
2306
2307 aty_calc_mem_refresh(par, par->pll_limits.xclk);
2308 par->pll_per = 1000000/par->pll_limits.pll_max;
2309 par->mclk_per = 1000000/par->pll_limits.mclk;
2310 par->xclk_per = 1000000/par->pll_limits.xclk;
2311
2312 par->ref_clk_per = 1000000000000ULL / 14318180;
2313 xtal = "14.31818";
2314 2301
2315#ifdef CONFIG_FB_ATY_GX 2302#ifdef CONFIG_FB_ATY_GX
2316 if (!M64_HAS(INTEGRATED)) { 2303 if (!M64_HAS(INTEGRATED)) {
@@ -2338,6 +2325,7 @@ static int __devinit aty_init(struct fb_info *info)
2338 case DAC_IBMRGB514: 2325 case DAC_IBMRGB514:
2339 par->dac_ops = &aty_dac_ibm514; 2326 par->dac_ops = &aty_dac_ibm514;
2340 break; 2327 break;
2328#ifdef CONFIG_ATARI
2341 case DAC_ATI68860_B: 2329 case DAC_ATI68860_B:
2342 case DAC_ATI68860_C: 2330 case DAC_ATI68860_C:
2343 par->dac_ops = &aty_dac_ati68860b; 2331 par->dac_ops = &aty_dac_ati68860b;
@@ -2346,6 +2334,7 @@ static int __devinit aty_init(struct fb_info *info)
2346 case DAC_ATT21C498: 2334 case DAC_ATT21C498:
2347 par->dac_ops = &aty_dac_att21c498; 2335 par->dac_ops = &aty_dac_att21c498;
2348 break; 2336 break;
2337#endif
2349 default: 2338 default:
2350 PRINTKI("aty_init: DAC type not implemented yet!\n"); 2339 PRINTKI("aty_init: DAC type not implemented yet!\n");
2351 par->dac_ops = &aty_dac_unsupported; 2340 par->dac_ops = &aty_dac_unsupported;
@@ -2389,8 +2378,29 @@ static int __devinit aty_init(struct fb_info *info)
2389 /* for many chips, the mclk is 67 MHz for SDRAM, 63 MHz otherwise */ 2378 /* for many chips, the mclk is 67 MHz for SDRAM, 63 MHz otherwise */
2390 if (par->pll_limits.mclk == 67 && par->ram_type < SDRAM) 2379 if (par->pll_limits.mclk == 67 && par->ram_type < SDRAM)
2391 par->pll_limits.mclk = 63; 2380 par->pll_limits.mclk = 63;
2381 /* Mobility + 32bit memory interface need halved XCLK. */
2382 if (M64_HAS(MOBIL_BUS) && par->ram_type == SDRAM32)
2383 par->pll_limits.xclk = (par->pll_limits.xclk + 1) >> 1;
2392 } 2384 }
2385#endif
2393 2386
2387 /* Allow command line to override clocks. */
2388 if (pll)
2389 par->pll_limits.pll_max = pll;
2390 if (mclk)
2391 par->pll_limits.mclk = mclk;
2392 if (xclk)
2393 par->pll_limits.xclk = xclk;
2394
2395 aty_calc_mem_refresh(par, par->pll_limits.xclk);
2396 par->pll_per = 1000000/par->pll_limits.pll_max;
2397 par->mclk_per = 1000000/par->pll_limits.mclk;
2398 par->xclk_per = 1000000/par->pll_limits.xclk;
2399
2400 par->ref_clk_per = 1000000000000ULL / 14318180;
2401 xtal = "14.31818";
2402
2403#ifdef CONFIG_FB_ATY_CT
2394 if (M64_HAS(GTB_DSP)) { 2404 if (M64_HAS(GTB_DSP)) {
2395 u8 pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par); 2405 u8 pll_ref_div = aty_ld_pll_ct(PLL_REF_DIV, par);
2396 2406
diff --git a/drivers/video/aty/mach64_ct.c b/drivers/video/aty/mach64_ct.c
index 1fdcfdbf669b..cc9e9779b75f 100644
--- a/drivers/video/aty/mach64_ct.c
+++ b/drivers/video/aty/mach64_ct.c
@@ -608,12 +608,10 @@ static void aty_resume_pll_ct(const struct fb_info *info,
608 aty_st_pll_ct(SCLK_FB_DIV, pll->ct.sclk_fb_div, par); 608 aty_st_pll_ct(SCLK_FB_DIV, pll->ct.sclk_fb_div, par);
609 aty_st_pll_ct(SPLL_CNTL2, pll->ct.spll_cntl2, par); 609 aty_st_pll_ct(SPLL_CNTL2, pll->ct.spll_cntl2, par);
610 /* 610 /*
611 * The sclk has been started. However, I believe the first clock 611 * SCLK has been started. Wait for the PLL to lock. 5 ms
612 * ticks it generates are not very stable. Hope this primitive loop 612 * should be enough according to mach64 programmer's guide.
613 * helps for Rage Mobilities that sometimes crash when
614 * we switch to sclk. (Daniel Mantione, 13-05-2003)
615 */ 613 */
616 udelay(500); 614 mdelay(5);
617 } 615 }
618 616
619 aty_st_pll_ct(PLL_REF_DIV, pll->ct.pll_ref_div, par); 617 aty_st_pll_ct(PLL_REF_DIV, pll->ct.pll_ref_div, par);
diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
index 2a7f381c330f..fe2c6ad01a8d 100644
--- a/drivers/video/aty/mach64_cursor.c
+++ b/drivers/video/aty/mach64_cursor.c
@@ -11,7 +11,6 @@
11#include <asm/uaccess.h> 11#include <asm/uaccess.h>
12 12
13#ifdef __sparc__ 13#ifdef __sparc__
14#include <asm/pbm.h>
15#include <asm/fbio.h> 14#include <asm/fbio.h>
16#endif 15#endif
17 16
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index a4b3fd185de7..2ce050193018 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -100,6 +100,8 @@
100 { PCI_VENDOR_ID_ATI, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (flags) | (CHIP_FAMILY_##family) } 100 { PCI_VENDOR_ID_ATI, id, PCI_ANY_ID, PCI_ANY_ID, 0, 0, (flags) | (CHIP_FAMILY_##family) }
101 101
102static struct pci_device_id radeonfb_pci_table[] = { 102static struct pci_device_id radeonfb_pci_table[] = {
103 /* Radeon Xpress 200m */
104 CHIP_DEF(PCI_CHIP_RS480_5955, RS480, CHIP_HAS_CRTC2 | CHIP_IS_IGP | CHIP_IS_MOBILITY),
103 /* Mobility M6 */ 105 /* Mobility M6 */
104 CHIP_DEF(PCI_CHIP_RADEON_LY, RV100, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY), 106 CHIP_DEF(PCI_CHIP_RADEON_LY, RV100, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
105 CHIP_DEF(PCI_CHIP_RADEON_LZ, RV100, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY), 107 CHIP_DEF(PCI_CHIP_RADEON_LZ, RV100, CHIP_HAS_CRTC2 | CHIP_IS_MOBILITY),
@@ -422,7 +424,7 @@ static int __devinit radeon_read_xtal_OF (struct radeonfb_info *rinfo)
422 424
423 if (dp == NULL) 425 if (dp == NULL)
424 return -ENODEV; 426 return -ENODEV;
425 val = get_property(dp, "ATY,RefCLK", NULL); 427 val = of_get_property(dp, "ATY,RefCLK", NULL);
426 if (!val || !*val) { 428 if (!val || !*val) {
427 printk(KERN_WARNING "radeonfb: No ATY,RefCLK property !\n"); 429 printk(KERN_WARNING "radeonfb: No ATY,RefCLK property !\n");
428 return -EINVAL; 430 return -EINVAL;
@@ -430,11 +432,11 @@ static int __devinit radeon_read_xtal_OF (struct radeonfb_info *rinfo)
430 432
431 rinfo->pll.ref_clk = (*val) / 10; 433 rinfo->pll.ref_clk = (*val) / 10;
432 434
433 val = get_property(dp, "ATY,SCLK", NULL); 435 val = of_get_property(dp, "ATY,SCLK", NULL);
434 if (val && *val) 436 if (val && *val)
435 rinfo->pll.sclk = (*val) / 10; 437 rinfo->pll.sclk = (*val) / 10;
436 438
437 val = get_property(dp, "ATY,MCLK", NULL); 439 val = of_get_property(dp, "ATY,MCLK", NULL);
438 if (val && *val) 440 if (val && *val)
439 rinfo->pll.mclk = (*val) / 10; 441 rinfo->pll.mclk = (*val) / 10;
440 442
@@ -1994,7 +1996,8 @@ static void radeon_identify_vram(struct radeonfb_info *rinfo)
1994 /* framebuffer size */ 1996 /* framebuffer size */
1995 if ((rinfo->family == CHIP_FAMILY_RS100) || 1997 if ((rinfo->family == CHIP_FAMILY_RS100) ||
1996 (rinfo->family == CHIP_FAMILY_RS200) || 1998 (rinfo->family == CHIP_FAMILY_RS200) ||
1997 (rinfo->family == CHIP_FAMILY_RS300)) { 1999 (rinfo->family == CHIP_FAMILY_RS300) ||
2000 (rinfo->family == CHIP_FAMILY_RS480) ) {
1998 u32 tom = INREG(NB_TOM); 2001 u32 tom = INREG(NB_TOM);
1999 tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024); 2002 tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024);
2000 2003
diff --git a/drivers/video/aty/radeon_monitor.c b/drivers/video/aty/radeon_monitor.c
index 737b5c09dbdb..2030ed813429 100644
--- a/drivers/video/aty/radeon_monitor.c
+++ b/drivers/video/aty/radeon_monitor.c
@@ -70,7 +70,7 @@ static int __devinit radeon_parse_montype_prop(struct device_node *dp, u8 **out_
70 int i, mt = MT_NONE; 70 int i, mt = MT_NONE;
71 71
72 RTRACE("analyzing OF properties...\n"); 72 RTRACE("analyzing OF properties...\n");
73 pmt = get_property(dp, "display-type", NULL); 73 pmt = of_get_property(dp, "display-type", NULL);
74 if (!pmt) 74 if (!pmt)
75 return MT_NONE; 75 return MT_NONE;
76 RTRACE("display-type: %s\n", pmt); 76 RTRACE("display-type: %s\n", pmt);
@@ -89,7 +89,7 @@ static int __devinit radeon_parse_montype_prop(struct device_node *dp, u8 **out_
89 } 89 }
90 90
91 for (i = 0; propnames[i] != NULL; ++i) { 91 for (i = 0; propnames[i] != NULL; ++i) {
92 pedid = get_property(dp, propnames[i], NULL); 92 pedid = of_get_property(dp, propnames[i], NULL);
93 if (pedid != NULL) 93 if (pedid != NULL)
94 break; 94 break;
95 } 95 }
@@ -98,9 +98,10 @@ static int __devinit radeon_parse_montype_prop(struct device_node *dp, u8 **out_
98 * single-head cards have hdno == -1 and skip this step 98 * single-head cards have hdno == -1 and skip this step
99 */ 99 */
100 if (pedid == NULL && dp->parent && (hdno != -1)) 100 if (pedid == NULL && dp->parent && (hdno != -1))
101 pedid = get_property(dp->parent, (hdno == 0) ? "EDID1" : "EDID2", NULL); 101 pedid = of_get_property(dp->parent,
102 (hdno == 0) ? "EDID1" : "EDID2", NULL);
102 if (pedid == NULL && dp->parent && (hdno == 0)) 103 if (pedid == NULL && dp->parent && (hdno == 0))
103 pedid = get_property(dp->parent, "EDID", NULL); 104 pedid = of_get_property(dp->parent, "EDID", NULL);
104 if (pedid == NULL) 105 if (pedid == NULL)
105 return mt; 106 return mt;
106 107
@@ -130,7 +131,7 @@ static int __devinit radeon_probe_OF_head(struct radeonfb_info *rinfo, int head_
130 do { 131 do {
131 if (!dp) 132 if (!dp)
132 return MT_NONE; 133 return MT_NONE;
133 pname = get_property(dp, "name", NULL); 134 pname = of_get_property(dp, "name", NULL);
134 if (!pname) 135 if (!pname)
135 return MT_NONE; 136 return MT_NONE;
136 len = strlen(pname); 137 len = strlen(pname);
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c
index c411293cefc8..be1d57bf9dc8 100644
--- a/drivers/video/aty/radeon_pm.c
+++ b/drivers/video/aty/radeon_pm.c
@@ -1290,7 +1290,7 @@ static void radeon_pm_full_reset_sdram(struct radeonfb_info *rinfo)
1290 if (rinfo->of_node != NULL) { 1290 if (rinfo->of_node != NULL) {
1291 int size; 1291 int size;
1292 1292
1293 mrtable = get_property(rinfo->of_node, "ATY,MRT", &size); 1293 mrtable = of_get_property(rinfo->of_node, "ATY,MRT", &size);
1294 if (mrtable) 1294 if (mrtable)
1295 mrtable_size = size >> 2; 1295 mrtable_size = size >> 2;
1296 else 1296 else
@@ -2826,11 +2826,15 @@ void radeonfb_pm_init(struct radeonfb_info *rinfo, int dynclk, int ignore_devlis
2826 rinfo->pm_reg = pci_find_capability(rinfo->pdev, PCI_CAP_ID_PM); 2826 rinfo->pm_reg = pci_find_capability(rinfo->pdev, PCI_CAP_ID_PM);
2827 2827
2828 /* Enable/Disable dynamic clocks: TODO add sysfs access */ 2828 /* Enable/Disable dynamic clocks: TODO add sysfs access */
2829 rinfo->dynclk = dynclk; 2829 if (rinfo->family == CHIP_FAMILY_RS480)
2830 if (dynclk == 1) { 2830 rinfo->dynclk = -1;
2831 else
2832 rinfo->dynclk = dynclk;
2833
2834 if (rinfo->dynclk == 1) {
2831 radeon_pm_enable_dynamic_mode(rinfo); 2835 radeon_pm_enable_dynamic_mode(rinfo);
2832 printk("radeonfb: Dynamic Clock Power Management enabled\n"); 2836 printk("radeonfb: Dynamic Clock Power Management enabled\n");
2833 } else if (dynclk == 0) { 2837 } else if (rinfo->dynclk == 0) {
2834 radeon_pm_disable_dynamic_mode(rinfo); 2838 radeon_pm_disable_dynamic_mode(rinfo);
2835 printk("radeonfb: Dynamic Clock Power Management disabled\n"); 2839 printk("radeonfb: Dynamic Clock Power Management disabled\n");
2836 } 2840 }
diff --git a/drivers/video/aty/radeonfb.h b/drivers/video/aty/radeonfb.h
index 319000360285..7ebffcdfd1e3 100644
--- a/drivers/video/aty/radeonfb.h
+++ b/drivers/video/aty/radeonfb.h
@@ -48,6 +48,7 @@ enum radeon_family {
48 CHIP_FAMILY_RV350, 48 CHIP_FAMILY_RV350,
49 CHIP_FAMILY_RV380, /* RV370/RV380/M22/M24 */ 49 CHIP_FAMILY_RV380, /* RV370/RV380/M22/M24 */
50 CHIP_FAMILY_R420, /* R420/R423/M18 */ 50 CHIP_FAMILY_R420, /* R420/R423/M18 */
51 CHIP_FAMILY_RS480,
51 CHIP_FAMILY_LAST, 52 CHIP_FAMILY_LAST,
52}; 53};
53 54
@@ -64,7 +65,8 @@ enum radeon_family {
64 ((rinfo)->family == CHIP_FAMILY_RV350) || \ 65 ((rinfo)->family == CHIP_FAMILY_RV350) || \
65 ((rinfo)->family == CHIP_FAMILY_R350) || \ 66 ((rinfo)->family == CHIP_FAMILY_R350) || \
66 ((rinfo)->family == CHIP_FAMILY_RV380) || \ 67 ((rinfo)->family == CHIP_FAMILY_RV380) || \
67 ((rinfo)->family == CHIP_FAMILY_R420)) 68 ((rinfo)->family == CHIP_FAMILY_R420) || \
69 ((rinfo)->family == CHIP_FAMILY_RS480) )
68 70
69/* 71/*
70 * Chip flags 72 * Chip flags
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 47d15b5d985a..fbef663fc057 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -63,3 +63,11 @@ config BACKLIGHT_PROGEAR
63 help 63 help
64 If you have a Frontpath ProGear say Y to enable the 64 If you have a Frontpath ProGear say Y to enable the
65 backlight driver. 65 backlight driver.
66
67config BACKLIGHT_CARILLO_RANCH
68 tristate "Intel Carillo Ranch Backlight Driver"
69 depends on BACKLIGHT_CLASS_DEVICE && LCD_CLASS_DEVICE && PCI && X86 && FB_LE80578
70 default n
71 help
72 If you have a Intel LE80578 (Carillo Ranch) say Y to enable the
73 backlight driver.
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 0c3ce46f5094..c6e2266f63e2 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o
6obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o 6obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
7obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o 7obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
8obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o 8obj-$(CONFIG_BACKLIGHT_PROGEAR) += progear_bl.o
9obj-$(CONFIG_BACKLIGHT_CARILLO_RANCH) += cr_bllcd.o
diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c
new file mode 100644
index 000000000000..e9bbc3455c94
--- /dev/null
+++ b/drivers/video/backlight/cr_bllcd.c
@@ -0,0 +1,287 @@
1/*
2 * Copyright (c) Intel Corp. 2007.
3 * All Rights Reserved.
4 *
5 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
6 * develop this driver.
7 *
8 * This file is part of the Carillo Ranch video subsystem driver.
9 * The Carillo Ranch video subsystem driver is free software;
10 * you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The Carillo Ranch video subsystem driver is distributed
16 * in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this driver; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 * Authors:
26 * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
27 * Alan Hourihane <alanh-at-tungstengraphics-dot-com>
28 */
29
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/init.h>
33#include <linux/platform_device.h>
34#include <linux/mutex.h>
35#include <linux/fb.h>
36#include <linux/backlight.h>
37#include <linux/lcd.h>
38#include <linux/pci.h>
39#include <asm/uaccess.h>
40
41/* The LVDS- and panel power controls sits on the
42 * GPIO port of the ISA bridge.
43 */
44
45#define CRVML_DEVICE_LPC 0x27B8
46#define CRVML_REG_GPIOBAR 0x48
47#define CRVML_REG_GPIOEN 0x4C
48#define CRVML_GPIOEN_BIT (1 << 4)
49#define CRVML_PANEL_PORT 0x38
50#define CRVML_LVDS_ON 0x00000001
51#define CRVML_PANEL_ON 0x00000002
52#define CRVML_BACKLIGHT_OFF 0x00000004
53
54/* The PLL Clock register sits on Host bridge */
55#define CRVML_DEVICE_MCH 0x5001
56#define CRVML_REG_MCHBAR 0x44
57#define CRVML_REG_MCHEN 0x54
58#define CRVML_MCHEN_BIT (1 << 28)
59#define CRVML_MCHMAP_SIZE 4096
60#define CRVML_REG_CLOCK 0xc3c
61#define CRVML_CLOCK_SHIFT 8
62#define CRVML_CLOCK_MASK 0x00000f00
63
64static struct pci_dev *lpc_dev;
65static u32 gpio_bar;
66
67struct cr_panel {
68 struct backlight_device *cr_backlight_device;
69 struct lcd_device *cr_lcd_device;
70};
71
72static int cr_backlight_set_intensity(struct backlight_device *bd)
73{
74 int intensity = bd->props.brightness;
75 u32 addr = gpio_bar + CRVML_PANEL_PORT;
76 u32 cur = inl(addr);
77
78 if (bd->props.power == FB_BLANK_UNBLANK)
79 intensity = FB_BLANK_UNBLANK;
80 if (bd->props.fb_blank == FB_BLANK_UNBLANK)
81 intensity = FB_BLANK_UNBLANK;
82 if (bd->props.power == FB_BLANK_POWERDOWN)
83 intensity = FB_BLANK_POWERDOWN;
84 if (bd->props.fb_blank == FB_BLANK_POWERDOWN)
85 intensity = FB_BLANK_POWERDOWN;
86
87 if (intensity == FB_BLANK_UNBLANK) { /* FULL ON */
88 cur &= ~CRVML_BACKLIGHT_OFF;
89 outl(cur, addr);
90 } else if (intensity == FB_BLANK_POWERDOWN) { /* OFF */
91 cur |= CRVML_BACKLIGHT_OFF;
92 outl(cur, addr);
93 } /* anything else, don't bother */
94
95 return 0;
96}
97
98static int cr_backlight_get_intensity(struct backlight_device *bd)
99{
100 u32 addr = gpio_bar + CRVML_PANEL_PORT;
101 u32 cur = inl(addr);
102 u8 intensity;
103
104 if (cur & CRVML_BACKLIGHT_OFF)
105 intensity = FB_BLANK_POWERDOWN;
106 else
107 intensity = FB_BLANK_UNBLANK;
108
109 return intensity;
110}
111
112static struct backlight_ops cr_backlight_ops = {
113 .get_brightness = cr_backlight_get_intensity,
114 .update_status = cr_backlight_set_intensity,
115};
116
117static void cr_panel_on(void)
118{
119 u32 addr = gpio_bar + CRVML_PANEL_PORT;
120 u32 cur = inl(addr);
121
122 if (!(cur & CRVML_PANEL_ON)) {
123 /* Make sure LVDS controller is down. */
124 if (cur & 0x00000001) {
125 cur &= ~CRVML_LVDS_ON;
126 outl(cur, addr);
127 }
128 /* Power up Panel */
129 schedule_timeout(HZ / 10);
130 cur |= CRVML_PANEL_ON;
131 outl(cur, addr);
132 }
133
134 /* Power up LVDS controller */
135
136 if (!(cur & CRVML_LVDS_ON)) {
137 schedule_timeout(HZ / 10);
138 outl(cur | CRVML_LVDS_ON, addr);
139 }
140}
141
142static void cr_panel_off(void)
143{
144 u32 addr = gpio_bar + CRVML_PANEL_PORT;
145 u32 cur = inl(addr);
146
147 /* Power down LVDS controller first to avoid high currents */
148 if (cur & CRVML_LVDS_ON) {
149 cur &= ~CRVML_LVDS_ON;
150 outl(cur, addr);
151 }
152 if (cur & CRVML_PANEL_ON) {
153 schedule_timeout(HZ / 10);
154 outl(cur & ~CRVML_PANEL_ON, addr);
155 }
156}
157
158static int cr_lcd_set_power(struct lcd_device *ld, int power)
159{
160 if (power == FB_BLANK_UNBLANK)
161 cr_panel_on();
162 if (power == FB_BLANK_POWERDOWN)
163 cr_panel_off();
164
165 return 0;
166}
167
168static struct lcd_ops cr_lcd_ops = {
169 .set_power = cr_lcd_set_power,
170};
171
172static int cr_backlight_probe(struct platform_device *pdev)
173{
174 struct cr_panel *crp;
175 u8 dev_en;
176
177 crp = kzalloc(sizeof(crp), GFP_KERNEL);
178 if (crp == NULL)
179 return -ENOMEM;
180
181 lpc_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
182 CRVML_DEVICE_LPC, NULL);
183 if (!lpc_dev) {
184 printk("INTEL CARILLO RANCH LPC not found.\n");
185 return -ENODEV;
186 }
187
188 pci_read_config_byte(lpc_dev, CRVML_REG_GPIOEN, &dev_en);
189 if (!(dev_en & CRVML_GPIOEN_BIT)) {
190 printk(KERN_ERR
191 "Carillo Ranch GPIO device was not enabled.\n");
192 pci_dev_put(lpc_dev);
193 return -ENODEV;
194 }
195
196 crp->cr_backlight_device = backlight_device_register("cr-backlight",
197 &pdev->dev, NULL,
198 &cr_backlight_ops);
199 if (IS_ERR(crp->cr_backlight_device)) {
200 pci_dev_put(lpc_dev);
201 return PTR_ERR(crp->cr_backlight_device);
202 }
203
204 crp->cr_lcd_device = lcd_device_register("cr-lcd",
205 &pdev->dev,
206 &cr_lcd_ops);
207
208 if (IS_ERR(crp->cr_lcd_device)) {
209 pci_dev_put(lpc_dev);
210 return PTR_ERR(crp->cr_backlight_device);
211 }
212
213 pci_read_config_dword(lpc_dev, CRVML_REG_GPIOBAR,
214 &gpio_bar);
215 gpio_bar &= ~0x3F;
216
217 crp->cr_backlight_device->props.power = FB_BLANK_UNBLANK;
218 crp->cr_backlight_device->props.brightness = 0;
219 crp->cr_backlight_device->props.max_brightness = 0;
220 cr_backlight_set_intensity(crp->cr_backlight_device);
221
222 cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_UNBLANK);
223
224 platform_set_drvdata(pdev, crp);
225
226 return 0;
227}
228
229static int cr_backlight_remove(struct platform_device *pdev)
230{
231 struct cr_panel *crp = platform_get_drvdata(pdev);
232 crp->cr_backlight_device->props.power = FB_BLANK_POWERDOWN;
233 crp->cr_backlight_device->props.brightness = 0;
234 crp->cr_backlight_device->props.max_brightness = 0;
235 cr_backlight_set_intensity(crp->cr_backlight_device);
236 cr_lcd_set_power(crp->cr_lcd_device, FB_BLANK_POWERDOWN);
237 backlight_device_unregister(crp->cr_backlight_device);
238 lcd_device_unregister(crp->cr_lcd_device);
239 pci_dev_put(lpc_dev);
240
241 return 0;
242}
243
244static struct platform_driver cr_backlight_driver = {
245 .probe = cr_backlight_probe,
246 .remove = cr_backlight_remove,
247 .driver = {
248 .name = "cr_backlight",
249 },
250};
251
252static struct platform_device *crp;
253
254static int __init cr_backlight_init(void)
255{
256 int ret = platform_driver_register(&cr_backlight_driver);
257
258 if (!ret) {
259 crp = platform_device_alloc("cr_backlight", -1);
260 if (!crp)
261 return -ENOMEM;
262
263 ret = platform_device_add(crp);
264
265 if (ret) {
266 platform_device_put(crp);
267 platform_driver_unregister(&cr_backlight_driver);
268 }
269 }
270
271 printk("Carillo Ranch Backlight Driver Initialized.\n");
272
273 return ret;
274}
275
276static void __exit cr_backlight_exit(void)
277{
278 platform_device_unregister(crp);
279 platform_driver_unregister(&cr_backlight_driver);
280}
281
282module_init(cr_backlight_init);
283module_exit(cr_backlight_exit);
284
285MODULE_AUTHOR("Tungsten Graphics Inc.");
286MODULE_DESCRIPTION("Carillo Ranch Backlight Driver");
287MODULE_LICENSE("GPL");
diff --git a/drivers/video/cfbcopyarea.c b/drivers/video/cfbcopyarea.c
index 6faea4034e3d..032210f45be3 100644
--- a/drivers/video/cfbcopyarea.c
+++ b/drivers/video/cfbcopyarea.c
@@ -22,8 +22,6 @@
22 * help moving some redundant computations and branches out of the loop, too. 22 * help moving some redundant computations and branches out of the loop, too.
23 */ 23 */
24 24
25
26
27#include <linux/module.h> 25#include <linux/module.h>
28#include <linux/kernel.h> 26#include <linux/kernel.h>
29#include <linux/string.h> 27#include <linux/string.h>
@@ -31,6 +29,7 @@
31#include <linux/slab.h> 29#include <linux/slab.h>
32#include <asm/types.h> 30#include <asm/types.h>
33#include <asm/io.h> 31#include <asm/io.h>
32#include "fb_draw.h"
34 33
35#if BITS_PER_LONG == 32 34#if BITS_PER_LONG == 32
36# define FB_WRITEL fb_writel 35# define FB_WRITEL fb_writel
@@ -41,17 +40,6 @@
41#endif 40#endif
42 41
43 /* 42 /*
44 * Compose two values, using a bitmask as decision value
45 * This is equivalent to (a & mask) | (b & ~mask)
46 */
47
48static inline unsigned long
49comp(unsigned long a, unsigned long b, unsigned long mask)
50{
51 return ((a ^ b) & mask) ^ b;
52}
53
54 /*
55 * Generic bitwise copy algorithm 43 * Generic bitwise copy algorithm
56 */ 44 */
57 45
diff --git a/drivers/video/cfbfillrect.c b/drivers/video/cfbfillrect.c
index f00b50aab606..71623b4f8ca2 100644
--- a/drivers/video/cfbfillrect.c
+++ b/drivers/video/cfbfillrect.c
@@ -21,6 +21,7 @@
21#include <linux/string.h> 21#include <linux/string.h>
22#include <linux/fb.h> 22#include <linux/fb.h>
23#include <asm/types.h> 23#include <asm/types.h>
24#include "fb_draw.h"
24 25
25#if BITS_PER_LONG == 32 26#if BITS_PER_LONG == 32
26# define FB_WRITEL fb_writel 27# define FB_WRITEL fb_writel
@@ -31,73 +32,6 @@
31#endif 32#endif
32 33
33 /* 34 /*
34 * Compose two values, using a bitmask as decision value
35 * This is equivalent to (a & mask) | (b & ~mask)
36 */
37
38static inline unsigned long
39comp(unsigned long a, unsigned long b, unsigned long mask)
40{
41 return ((a ^ b) & mask) ^ b;
42}
43
44 /*
45 * Create a pattern with the given pixel's color
46 */
47
48#if BITS_PER_LONG == 64
49static inline unsigned long
50pixel_to_pat( u32 bpp, u32 pixel)
51{
52 switch (bpp) {
53 case 1:
54 return 0xfffffffffffffffful*pixel;
55 case 2:
56 return 0x5555555555555555ul*pixel;
57 case 4:
58 return 0x1111111111111111ul*pixel;
59 case 8:
60 return 0x0101010101010101ul*pixel;
61 case 12:
62 return 0x0001001001001001ul*pixel;
63 case 16:
64 return 0x0001000100010001ul*pixel;
65 case 24:
66 return 0x0000000001000001ul*pixel;
67 case 32:
68 return 0x0000000100000001ul*pixel;
69 default:
70 panic("pixel_to_pat(): unsupported pixelformat\n");
71 }
72}
73#else
74static inline unsigned long
75pixel_to_pat( u32 bpp, u32 pixel)
76{
77 switch (bpp) {
78 case 1:
79 return 0xfffffffful*pixel;
80 case 2:
81 return 0x55555555ul*pixel;
82 case 4:
83 return 0x11111111ul*pixel;
84 case 8:
85 return 0x01010101ul*pixel;
86 case 12:
87 return 0x00001001ul*pixel;
88 case 16:
89 return 0x00010001ul*pixel;
90 case 24:
91 return 0x00000001ul*pixel;
92 case 32:
93 return 0x00000001ul*pixel;
94 default:
95 panic("pixel_to_pat(): unsupported pixelformat\n");
96 }
97}
98#endif
99
100 /*
101 * Aligned pattern fill using 32/64-bit memory accesses 35 * Aligned pattern fill using 32/64-bit memory accesses
102 */ 36 */
103 37
diff --git a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c
index 2c4bc6205738..8269d704ab2a 100644
--- a/drivers/video/cirrusfb.c
+++ b/drivers/video/cirrusfb.c
@@ -98,15 +98,6 @@
98#define assert(expr) 98#define assert(expr)
99#endif 99#endif
100 100
101#ifdef TRUE
102#undef TRUE
103#endif
104#ifdef FALSE
105#undef FALSE
106#endif
107#define TRUE 1
108#define FALSE 0
109
110#define MB_ (1024*1024) 101#define MB_ (1024*1024)
111#define KB_ (1024) 102#define KB_ (1024)
112 103
@@ -146,9 +137,9 @@ static const struct cirrusfb_board_info_rec {
146 char *name; /* ASCII name of chipset */ 137 char *name; /* ASCII name of chipset */
147 long maxclock[5]; /* maximum video clock */ 138 long maxclock[5]; /* maximum video clock */
148 /* for 1/4bpp, 8bpp 15/16bpp, 24bpp, 32bpp - numbers from xorg code */ 139 /* for 1/4bpp, 8bpp 15/16bpp, 24bpp, 32bpp - numbers from xorg code */
149 unsigned init_sr07 : 1; /* init SR07 during init_vgachip() */ 140 bool init_sr07 : 1; /* init SR07 during init_vgachip() */
150 unsigned init_sr1f : 1; /* write SR1F during init_vgachip() */ 141 bool init_sr1f : 1; /* write SR1F during init_vgachip() */
151 unsigned scrn_start_bit19 : 1; /* construct bit 19 of screen start address */ 142 bool scrn_start_bit19 : 1; /* construct bit 19 of screen start address */
152 143
153 /* initial SR07 value, then for each mode */ 144 /* initial SR07 value, then for each mode */
154 unsigned char sr07; 145 unsigned char sr07;
@@ -166,9 +157,9 @@ static const struct cirrusfb_board_info_rec {
166 /* the SD64/P4 have a higher max. videoclock */ 157 /* the SD64/P4 have a higher max. videoclock */
167 140000, 140000, 140000, 140000, 140000, 158 140000, 140000, 140000, 140000, 140000,
168 }, 159 },
169 .init_sr07 = TRUE, 160 .init_sr07 = true,
170 .init_sr1f = TRUE, 161 .init_sr1f = true,
171 .scrn_start_bit19 = TRUE, 162 .scrn_start_bit19 = true,
172 .sr07 = 0xF0, 163 .sr07 = 0xF0,
173 .sr07_1bpp = 0xF0, 164 .sr07_1bpp = 0xF0,
174 .sr07_8bpp = 0xF1, 165 .sr07_8bpp = 0xF1,
@@ -180,9 +171,9 @@ static const struct cirrusfb_board_info_rec {
180 /* guess */ 171 /* guess */
181 90000, 90000, 90000, 90000, 90000 172 90000, 90000, 90000, 90000, 90000
182 }, 173 },
183 .init_sr07 = TRUE, 174 .init_sr07 = true,
184 .init_sr1f = TRUE, 175 .init_sr1f = true,
185 .scrn_start_bit19 = FALSE, 176 .scrn_start_bit19 = false,
186 .sr07 = 0x80, 177 .sr07 = 0x80,
187 .sr07_1bpp = 0x80, 178 .sr07_1bpp = 0x80,
188 .sr07_8bpp = 0x81, 179 .sr07_8bpp = 0x81,
@@ -194,9 +185,9 @@ static const struct cirrusfb_board_info_rec {
194 /* guess */ 185 /* guess */
195 90000, 90000, 90000, 90000, 90000 186 90000, 90000, 90000, 90000, 90000
196 }, 187 },
197 .init_sr07 = TRUE, 188 .init_sr07 = true,
198 .init_sr1f = TRUE, 189 .init_sr1f = true,
199 .scrn_start_bit19 = FALSE, 190 .scrn_start_bit19 = false,
200 .sr07 = 0x20, 191 .sr07 = 0x20,
201 .sr07_1bpp = 0x20, 192 .sr07_1bpp = 0x20,
202 .sr07_8bpp = 0x21, 193 .sr07_8bpp = 0x21,
@@ -208,9 +199,9 @@ static const struct cirrusfb_board_info_rec {
208 /* guess */ 199 /* guess */
209 90000, 90000, 90000, 90000, 90000 200 90000, 90000, 90000, 90000, 90000
210 }, 201 },
211 .init_sr07 = TRUE, 202 .init_sr07 = true,
212 .init_sr1f = TRUE, 203 .init_sr1f = true,
213 .scrn_start_bit19 = FALSE, 204 .scrn_start_bit19 = false,
214 .sr07 = 0x80, 205 .sr07 = 0x80,
215 .sr07_1bpp = 0x80, 206 .sr07_1bpp = 0x80,
216 .sr07_8bpp = 0x81, 207 .sr07_8bpp = 0x81,
@@ -221,9 +212,9 @@ static const struct cirrusfb_board_info_rec {
221 .maxclock = { 212 .maxclock = {
222 135100, 135100, 85500, 85500, 0 213 135100, 135100, 85500, 85500, 0
223 }, 214 },
224 .init_sr07 = TRUE, 215 .init_sr07 = true,
225 .init_sr1f = FALSE, 216 .init_sr1f = false,
226 .scrn_start_bit19 = TRUE, 217 .scrn_start_bit19 = true,
227 .sr07 = 0x20, 218 .sr07 = 0x20,
228 .sr07_1bpp = 0x20, 219 .sr07_1bpp = 0x20,
229 .sr07_8bpp = 0x21, 220 .sr07_8bpp = 0x21,
@@ -235,9 +226,9 @@ static const struct cirrusfb_board_info_rec {
235 /* for the GD5430. GD5446 can do more... */ 226 /* for the GD5430. GD5446 can do more... */
236 85500, 85500, 50000, 28500, 0 227 85500, 85500, 50000, 28500, 0
237 }, 228 },
238 .init_sr07 = TRUE, 229 .init_sr07 = true,
239 .init_sr1f = TRUE, 230 .init_sr1f = true,
240 .scrn_start_bit19 = TRUE, 231 .scrn_start_bit19 = true,
241 .sr07 = 0xA0, 232 .sr07 = 0xA0,
242 .sr07_1bpp = 0xA1, 233 .sr07_1bpp = 0xA1,
243 .sr07_1bpp_mux = 0xA7, 234 .sr07_1bpp_mux = 0xA7,
@@ -250,9 +241,9 @@ static const struct cirrusfb_board_info_rec {
250 .maxclock = { 241 .maxclock = {
251 135100, 200000, 200000, 135100, 135100 242 135100, 200000, 200000, 135100, 135100
252 }, 243 },
253 .init_sr07 = TRUE, 244 .init_sr07 = true,
254 .init_sr1f = TRUE, 245 .init_sr1f = true,
255 .scrn_start_bit19 = TRUE, 246 .scrn_start_bit19 = true,
256 .sr07 = 0x10, 247 .sr07 = 0x10,
257 .sr07_1bpp = 0x11, 248 .sr07_1bpp = 0x11,
258 .sr07_8bpp = 0x11, 249 .sr07_8bpp = 0x11,
@@ -264,9 +255,9 @@ static const struct cirrusfb_board_info_rec {
264 /* guess */ 255 /* guess */
265 135100, 135100, 135100, 135100, 135100, 256 135100, 135100, 135100, 135100, 135100,
266 }, 257 },
267 .init_sr07 = FALSE, 258 .init_sr07 = false,
268 .init_sr1f = FALSE, 259 .init_sr1f = false,
269 .scrn_start_bit19 = TRUE, 260 .scrn_start_bit19 = true,
270 } 261 }
271}; 262};
272 263
@@ -815,7 +806,7 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
815 806
816 default: 807 default:
817 DPRINTK("Unsupported bpp size: %d\n", var->bits_per_pixel); 808 DPRINTK("Unsupported bpp size: %d\n", var->bits_per_pixel);
818 assert (FALSE); 809 assert(false);
819 /* should never occur */ 810 /* should never occur */
820 break; 811 break;
821 } 812 }
@@ -886,7 +877,7 @@ static int cirrusfb_decode_var (const struct fb_var_screeninfo *var,
886 877
887 default: 878 default:
888 DPRINTK("Unsupported bpp size: %d\n", var->bits_per_pixel); 879 DPRINTK("Unsupported bpp size: %d\n", var->bits_per_pixel);
889 assert (FALSE); 880 assert(false);
890 /* should never occur */ 881 /* should never occur */
891 break; 882 break;
892 } 883 }
@@ -3203,7 +3194,7 @@ void cirrusfb_dbg_print_regs (caddr_t regbase, cirrusfb_dbg_reg_class_t reg_clas
3203 break; 3194 break;
3204 default: 3195 default:
3205 /* should never occur */ 3196 /* should never occur */
3206 assert (FALSE); 3197 assert(false);
3207 break; 3198 break;
3208 } 3199 }
3209 3200
diff --git a/drivers/video/console/Kconfig b/drivers/video/console/Kconfig
index aa3935df852a..63b85bf81a65 100644
--- a/drivers/video/console/Kconfig
+++ b/drivers/video/console/Kconfig
@@ -19,13 +19,6 @@ config VGA_CONSOLE
19 19
20 Say Y. 20 Say Y.
21 21
22# if [ "$CONFIG_PCI" = "y" -a "$CONFIG_VGA_CONSOLE" = "y" ]; then
23# bool ' Allow VGA on any bus?' CONFIG_VGA_HOSE
24# if [ "$CONFIG_VGA_HOSE" = "y" ]; then
25# define_bool CONFIG_DUMMY_CONSOLE y
26# fi
27# fi
28
29config VGACON_SOFT_SCROLLBACK 22config VGACON_SOFT_SCROLLBACK
30 bool "Enable Scrollback Buffer in System RAM" 23 bool "Enable Scrollback Buffer in System RAM"
31 depends on VGA_CONSOLE 24 depends on VGA_CONSOLE
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 0429fd2cece0..73813c60d03a 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -107,7 +107,9 @@ static struct display fb_display[MAX_NR_CONSOLES];
107 107
108static signed char con2fb_map[MAX_NR_CONSOLES]; 108static signed char con2fb_map[MAX_NR_CONSOLES];
109static signed char con2fb_map_boot[MAX_NR_CONSOLES]; 109static signed char con2fb_map_boot[MAX_NR_CONSOLES];
110#ifndef MODULE
110static int logo_height; 111static int logo_height;
112#endif
111static int logo_lines; 113static int logo_lines;
112/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO 114/* logo_shown is an index to vc_cons when >= 0; otherwise follows FBCON_LOGO
113 enums. */ 115 enums. */
@@ -576,6 +578,13 @@ static int fbcon_takeover(int show_logo)
576 return err; 578 return err;
577} 579}
578 580
581#ifdef MODULE
582static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
583 int cols, int rows, int new_cols, int new_rows)
584{
585 logo_shown = FBCON_LOGO_DONTSHOW;
586}
587#else
579static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info, 588static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
580 int cols, int rows, int new_cols, int new_rows) 589 int cols, int rows, int new_cols, int new_rows)
581{ 590{
@@ -584,6 +593,11 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
584 int cnt, erase = vc->vc_video_erase_char, step; 593 int cnt, erase = vc->vc_video_erase_char, step;
585 unsigned short *save = NULL, *r, *q; 594 unsigned short *save = NULL, *r, *q;
586 595
596 if (info->flags & FBINFO_MODULE) {
597 logo_shown = FBCON_LOGO_DONTSHOW;
598 return;
599 }
600
587 /* 601 /*
588 * remove underline attribute from erase character 602 * remove underline attribute from erase character
589 * if black and white framebuffer. 603 * if black and white framebuffer.
@@ -618,8 +632,13 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
618 r -= cols; 632 r -= cols;
619 } 633 }
620 if (!save) { 634 if (!save) {
621 vc->vc_y += logo_lines; 635 int lines;
622 vc->vc_pos += logo_lines * vc->vc_size_row; 636 if (vc->vc_y + logo_lines >= rows)
637 lines = rows - vc->vc_y - 1;
638 else
639 lines = logo_lines;
640 vc->vc_y += lines;
641 vc->vc_pos += lines * vc->vc_size_row;
623 } 642 }
624 } 643 }
625 scr_memsetw((unsigned short *) vc->vc_origin, 644 scr_memsetw((unsigned short *) vc->vc_origin,
@@ -650,6 +669,7 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info,
650 vc->vc_top = logo_lines; 669 vc->vc_top = logo_lines;
651 } 670 }
652} 671}
672#endif /* MODULE */
653 673
654#ifdef CONFIG_FB_TILEBLITTING 674#ifdef CONFIG_FB_TILEBLITTING
655static void set_blitting_type(struct vc_data *vc, struct fb_info *info) 675static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
@@ -665,6 +685,17 @@ static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
665 fbcon_set_bitops(ops); 685 fbcon_set_bitops(ops);
666 } 686 }
667} 687}
688
689static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
690{
691 int err = 0;
692
693 if (info->flags & FBINFO_MISC_TILEBLITTING &&
694 info->tileops->fb_get_tilemax(info) < charcount)
695 err = 1;
696
697 return err;
698}
668#else 699#else
669static void set_blitting_type(struct vc_data *vc, struct fb_info *info) 700static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
670{ 701{
@@ -675,6 +706,12 @@ static void set_blitting_type(struct vc_data *vc, struct fb_info *info)
675 fbcon_set_rotation(info); 706 fbcon_set_rotation(info);
676 fbcon_set_bitops(ops); 707 fbcon_set_bitops(ops);
677} 708}
709
710static int fbcon_invalid_charcount(struct fb_info *info, unsigned charcount)
711{
712 return 0;
713}
714
678#endif /* CONFIG_MISC_TILEBLITTING */ 715#endif /* CONFIG_MISC_TILEBLITTING */
679 716
680 717
@@ -968,7 +1005,9 @@ static const char *fbcon_startup(void)
968 if (!p->fontdata) { 1005 if (!p->fontdata) {
969 if (!fontname[0] || !(font = find_font(fontname))) 1006 if (!fontname[0] || !(font = find_font(fontname)))
970 font = get_default_font(info->var.xres, 1007 font = get_default_font(info->var.xres,
971 info->var.yres); 1008 info->var.yres,
1009 info->pixmap.blit_x,
1010 info->pixmap.blit_y);
972 vc->vc_font.width = font->width; 1011 vc->vc_font.width = font->width;
973 vc->vc_font.height = font->height; 1012 vc->vc_font.height = font->height;
974 vc->vc_font.data = (void *)(p->fontdata = font->data); 1013 vc->vc_font.data = (void *)(p->fontdata = font->data);
@@ -1088,7 +1127,9 @@ static void fbcon_init(struct vc_data *vc, int init)
1088 1127
1089 if (!fontname[0] || !(font = find_font(fontname))) 1128 if (!fontname[0] || !(font = find_font(fontname)))
1090 font = get_default_font(info->var.xres, 1129 font = get_default_font(info->var.xres,
1091 info->var.yres); 1130 info->var.yres,
1131 info->pixmap.blit_x,
1132 info->pixmap.blit_y);
1092 vc->vc_font.width = font->width; 1133 vc->vc_font.width = font->width;
1093 vc->vc_font.height = font->height; 1134 vc->vc_font.height = font->height;
1094 vc->vc_font.data = (void *)(p->fontdata = font->data); 1135 vc->vc_font.data = (void *)(p->fontdata = font->data);
@@ -1305,7 +1346,7 @@ static void fbcon_cursor(struct vc_data *vc, int mode)
1305 int y; 1346 int y;
1306 int c = scr_readw((u16 *) vc->vc_pos); 1347 int c = scr_readw((u16 *) vc->vc_pos);
1307 1348
1308 if (fbcon_is_inactive(vc, info)) 1349 if (fbcon_is_inactive(vc, info) || vc->vc_deccm != 1)
1309 return; 1350 return;
1310 1351
1311 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1; 1352 ops->cursor_flash = (mode == CM_ERASE) ? 0 : 1;
@@ -2475,6 +2516,7 @@ static int fbcon_copy_font(struct vc_data *vc, int con)
2475 2516
2476static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags) 2517static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigned flags)
2477{ 2518{
2519 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
2478 unsigned charcount = font->charcount; 2520 unsigned charcount = font->charcount;
2479 int w = font->width; 2521 int w = font->width;
2480 int h = font->height; 2522 int h = font->height;
@@ -2488,6 +2530,15 @@ static int fbcon_set_font(struct vc_data *vc, struct console_font *font, unsigne
2488 if (charcount != 256 && charcount != 512) 2530 if (charcount != 256 && charcount != 512)
2489 return -EINVAL; 2531 return -EINVAL;
2490 2532
2533 /* Make sure drawing engine can handle the font */
2534 if (!(info->pixmap.blit_x & (1 << (font->width - 1))) ||
2535 !(info->pixmap.blit_y & (1 << (font->height - 1))))
2536 return -EINVAL;
2537
2538 /* Make sure driver can handle the font length */
2539 if (fbcon_invalid_charcount(info, charcount))
2540 return -EINVAL;
2541
2491 size = h * pitch * charcount; 2542 size = h * pitch * charcount;
2492 2543
2493 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER); 2544 new_data = kmalloc(FONT_EXTRA_WORDS * sizeof(int) + size, GFP_USER);
@@ -2532,7 +2583,8 @@ static int fbcon_set_def_font(struct vc_data *vc, struct console_font *font, cha
2532 const struct font_desc *f; 2583 const struct font_desc *f;
2533 2584
2534 if (!name) 2585 if (!name)
2535 f = get_default_font(info->var.xres, info->var.yres); 2586 f = get_default_font(info->var.xres, info->var.yres,
2587 info->pixmap.blit_x, info->pixmap.blit_y);
2536 else if (!(f = find_font(name))) 2588 else if (!(f = find_font(name)))
2537 return -ENOENT; 2589 return -ENOENT;
2538 2590
@@ -2829,7 +2881,7 @@ static void fbcon_set_all_vcs(struct fb_info *info)
2829 struct fbcon_ops *ops = info->fbcon_par; 2881 struct fbcon_ops *ops = info->fbcon_par;
2830 struct vc_data *vc; 2882 struct vc_data *vc;
2831 struct display *p; 2883 struct display *p;
2832 int i, rows, cols; 2884 int i, rows, cols, fg = -1;
2833 2885
2834 if (!ops || ops->currcon < 0) 2886 if (!ops || ops->currcon < 0)
2835 return; 2887 return;
@@ -2840,34 +2892,23 @@ static void fbcon_set_all_vcs(struct fb_info *info)
2840 registered_fb[con2fb_map[i]] != info) 2892 registered_fb[con2fb_map[i]] != info)
2841 continue; 2893 continue;
2842 2894
2895 if (CON_IS_VISIBLE(vc)) {
2896 fg = i;
2897 continue;
2898 }
2899
2843 p = &fb_display[vc->vc_num]; 2900 p = &fb_display[vc->vc_num];
2844 set_blitting_type(vc, info); 2901 set_blitting_type(vc, info);
2845 var_to_display(p, &info->var, info); 2902 var_to_display(p, &info->var, info);
2846 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres); 2903 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres);
2847 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres); 2904 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres);
2848 cols /= vc->vc_font.width; 2905 cols /= vc->vc_font.width;
2849 rows /= vc->vc_font.height; 2906 rows /= vc->vc_font.height;
2850 vc_resize(vc, cols, rows); 2907 vc_resize(vc, cols, rows);
2851
2852 if (CON_IS_VISIBLE(vc)) {
2853 updatescrollmode(p, info, vc);
2854 scrollback_max = 0;
2855 scrollback_current = 0;
2856
2857 if (!fbcon_is_inactive(vc, info)) {
2858 ops->var.xoffset = ops->var.yoffset =
2859 p->yscroll = 0;
2860 ops->update_start(info);
2861 }
2862
2863 fbcon_set_palette(vc, color_table);
2864 update_screen(vc);
2865 if (softback_buf)
2866 fbcon_update_softback(vc);
2867 }
2868 } 2908 }
2869 2909
2870 ops->p = &fb_display[ops->currcon]; 2910 if (fg != -1)
2911 fbcon_modechanged(info);
2871} 2912}
2872 2913
2873static int fbcon_mode_deleted(struct fb_info *info, 2914static int fbcon_mode_deleted(struct fb_info *info,
@@ -3002,6 +3043,42 @@ static void fbcon_new_modelist(struct fb_info *info)
3002 } 3043 }
3003} 3044}
3004 3045
3046static void fbcon_get_requirement(struct fb_info *info,
3047 struct fb_blit_caps *caps)
3048{
3049 struct vc_data *vc;
3050 struct display *p;
3051
3052 if (caps->flags) {
3053 int i, charcnt;
3054
3055 for (i = first_fb_vc; i <= last_fb_vc; i++) {
3056 vc = vc_cons[i].d;
3057 if (vc && vc->vc_mode == KD_TEXT &&
3058 info->node == con2fb_map[i]) {
3059 p = &fb_display[i];
3060 caps->x |= 1 << (vc->vc_font.width - 1);
3061 caps->y |= 1 << (vc->vc_font.height - 1);
3062 charcnt = (p->userfont) ?
3063 FNTCHARCNT(p->fontdata) : 256;
3064 if (caps->len < charcnt)
3065 caps->len = charcnt;
3066 }
3067 }
3068 } else {
3069 vc = vc_cons[fg_console].d;
3070
3071 if (vc && vc->vc_mode == KD_TEXT &&
3072 info->node == con2fb_map[fg_console]) {
3073 p = &fb_display[fg_console];
3074 caps->x = 1 << (vc->vc_font.width - 1);
3075 caps->y = 1 << (vc->vc_font.height - 1);
3076 caps->len = (p->userfont) ?
3077 FNTCHARCNT(p->fontdata) : 256;
3078 }
3079 }
3080}
3081
3005static int fbcon_event_notify(struct notifier_block *self, 3082static int fbcon_event_notify(struct notifier_block *self,
3006 unsigned long action, void *data) 3083 unsigned long action, void *data)
3007{ 3084{
@@ -3009,6 +3086,7 @@ static int fbcon_event_notify(struct notifier_block *self,
3009 struct fb_info *info = event->info; 3086 struct fb_info *info = event->info;
3010 struct fb_videomode *mode; 3087 struct fb_videomode *mode;
3011 struct fb_con2fbmap *con2fb; 3088 struct fb_con2fbmap *con2fb;
3089 struct fb_blit_caps *caps;
3012 int ret = 0; 3090 int ret = 0;
3013 3091
3014 /* 3092 /*
@@ -3057,6 +3135,10 @@ static int fbcon_event_notify(struct notifier_block *self,
3057 case FB_EVENT_NEW_MODELIST: 3135 case FB_EVENT_NEW_MODELIST:
3058 fbcon_new_modelist(info); 3136 fbcon_new_modelist(info);
3059 break; 3137 break;
3138 case FB_EVENT_GET_REQ:
3139 caps = event->data;
3140 fbcon_get_requirement(info, caps);
3141 break;
3060 } 3142 }
3061 3143
3062done: 3144done:
diff --git a/drivers/video/console/fonts.c b/drivers/video/console/fonts.c
index c960728b7e82..a6828d0a4c56 100644
--- a/drivers/video/console/fonts.c
+++ b/drivers/video/console/fonts.c
@@ -98,6 +98,8 @@ const struct font_desc *find_font(const char *name)
98 * get_default_font - get default font 98 * get_default_font - get default font
99 * @xres: screen size of X 99 * @xres: screen size of X
100 * @yres: screen size of Y 100 * @yres: screen size of Y
101 * @font_w: bit array of supported widths (1 - 32)
102 * @font_h: bit array of supported heights (1 - 32)
101 * 103 *
102 * Get the default font for a specified screen size. 104 * Get the default font for a specified screen size.
103 * Dimensions are in pixels. 105 * Dimensions are in pixels.
@@ -107,7 +109,8 @@ const struct font_desc *find_font(const char *name)
107 * 109 *
108 */ 110 */
109 111
110const struct font_desc *get_default_font(int xres, int yres) 112const struct font_desc *get_default_font(int xres, int yres, u32 font_w,
113 u32 font_h)
111{ 114{
112 int i, c, cc; 115 int i, c, cc;
113 const struct font_desc *f, *g; 116 const struct font_desc *f, *g;
@@ -129,6 +132,11 @@ const struct font_desc *get_default_font(int xres, int yres)
129#endif 132#endif
130 if ((yres < 400) == (f->height <= 8)) 133 if ((yres < 400) == (f->height <= 8))
131 c += 1000; 134 c += 1000;
135
136 if (!(font_w & (1 << (f->width - 1))) ||
137 !(font_w & (1 << (f->height - 1))))
138 c += 1000;
139
132 if (c > cc) { 140 if (c > cc) {
133 cc = c; 141 cc = c;
134 g = f; 142 g = f;
diff --git a/drivers/video/console/mdacon.c b/drivers/video/console/mdacon.c
index 124ecbe6f88c..bd8d995fe25d 100644
--- a/drivers/video/console/mdacon.c
+++ b/drivers/video/console/mdacon.c
@@ -384,7 +384,7 @@ static inline u16 mda_convert_attr(u16 ch)
384} 384}
385 385
386static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity, 386static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
387 u8 blink, u8 underline, u8 reverse) 387 u8 blink, u8 underline, u8 reverse, u8 italic)
388{ 388{
389 /* The attribute is just a bit vector: 389 /* The attribute is just a bit vector:
390 * 390 *
@@ -397,6 +397,7 @@ static u8 mdacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
397 return (intensity & 3) | 397 return (intensity & 3) |
398 ((underline & 1) << 2) | 398 ((underline & 1) << 2) |
399 ((reverse & 1) << 3) | 399 ((reverse & 1) << 3) |
400 (!!italic << 4) |
400 ((blink & 1) << 7); 401 ((blink & 1) << 7);
401} 402}
402 403
diff --git a/drivers/video/console/promcon.c b/drivers/video/console/promcon.c
index b78eac63459f..ae02e4eb18e7 100644
--- a/drivers/video/console/promcon.c
+++ b/drivers/video/console/promcon.c
@@ -548,7 +548,8 @@ promcon_scroll(struct vc_data *conp, int t, int b, int dir, int count)
548} 548}
549 549
550#if !(PROMCON_COLOR) 550#if !(PROMCON_COLOR)
551static u8 promcon_build_attr(struct vc_data *conp, u8 _color, u8 _intensity, u8 _blink, u8 _underline, u8 _reverse) 551static u8 promcon_build_attr(struct vc_data *conp, u8 _color, u8 _intensity,
552 u8 _blink, u8 _underline, u8 _reverse, u8 _italic)
552{ 553{
553 return (_reverse) ? 0xf : 0x7; 554 return (_reverse) ? 0xf : 0x7;
554} 555}
diff --git a/drivers/video/console/softcursor.c b/drivers/video/console/softcursor.c
index f577bd80e020..03cfb7ac5733 100644
--- a/drivers/video/console/softcursor.c
+++ b/drivers/video/console/softcursor.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * linux/drivers/video/softcursor.c 2 * linux/drivers/video/console/softcursor.c
3 * 3 *
4 * Generic software cursor for frame buffer devices 4 * Generic software cursor for frame buffer devices
5 * 5 *
diff --git a/drivers/video/console/sticon.c b/drivers/video/console/sticon.c
index 57b21e533036..67a682d6cc7b 100644
--- a/drivers/video/console/sticon.c
+++ b/drivers/video/console/sticon.c
@@ -314,7 +314,7 @@ static unsigned long sticon_getxy(struct vc_data *conp, unsigned long pos,
314} 314}
315 315
316static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens, 316static u8 sticon_build_attr(struct vc_data *conp, u8 color, u8 intens,
317 u8 blink, u8 underline, u8 reverse) 317 u8 blink, u8 underline, u8 reverse, u8 italic)
318{ 318{
319 u8 attr = ((color & 0x70) >> 1) | ((color & 7)); 319 u8 attr = ((color & 0x70) >> 1) | ((color & 7));
320 320
diff --git a/drivers/video/console/sticore.c b/drivers/video/console/sticore.c
index 88e7038eab88..717b360d0415 100644
--- a/drivers/video/console/sticore.c
+++ b/drivers/video/console/sticore.c
@@ -495,7 +495,7 @@ sti_select_fbfont(struct sti_cooked_rom *cooked_rom, const char *fbfont_name)
495 return NULL; 495 return NULL;
496 fbfont = find_font(fbfont_name); 496 fbfont = find_font(fbfont_name);
497 if (!fbfont) 497 if (!fbfont)
498 fbfont = get_default_font(1024,768); 498 fbfont = get_default_font(1024,768, ~(u32)0, ~(u32)0);
499 if (!fbfont) 499 if (!fbfont)
500 return NULL; 500 return NULL;
501 501
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index 3e67c34df9a5..f46fe95f69fb 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -86,8 +86,6 @@ static int vgacon_set_origin(struct vc_data *c);
86static void vgacon_save_screen(struct vc_data *c); 86static void vgacon_save_screen(struct vc_data *c);
87static int vgacon_scroll(struct vc_data *c, int t, int b, int dir, 87static int vgacon_scroll(struct vc_data *c, int t, int b, int dir,
88 int lines); 88 int lines);
89static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
90 u8 blink, u8 underline, u8 reverse);
91static void vgacon_invert_region(struct vc_data *c, u16 * p, int count); 89static void vgacon_invert_region(struct vc_data *c, u16 * p, int count);
92static unsigned long vgacon_uni_pagedir[2]; 90static unsigned long vgacon_uni_pagedir[2];
93 91
@@ -370,9 +368,14 @@ static const char *vgacon_startup(void)
370#endif 368#endif
371 } 369 }
372 370
371 /* SCREEN_INFO initialized? */
372 if ((ORIG_VIDEO_MODE == 0) &&
373 (ORIG_VIDEO_LINES == 0) &&
374 (ORIG_VIDEO_COLS == 0))
375 goto no_vga;
376
373 /* VGA16 modes are not handled by VGACON */ 377 /* VGA16 modes are not handled by VGACON */
374 if ((ORIG_VIDEO_MODE == 0x00) || /* SCREEN_INFO not initialized */ 378 if ((ORIG_VIDEO_MODE == 0x0D) || /* 320x200/4 */
375 (ORIG_VIDEO_MODE == 0x0D) || /* 320x200/4 */
376 (ORIG_VIDEO_MODE == 0x0E) || /* 640x200/4 */ 379 (ORIG_VIDEO_MODE == 0x0E) || /* 640x200/4 */
377 (ORIG_VIDEO_MODE == 0x10) || /* 640x350/4 */ 380 (ORIG_VIDEO_MODE == 0x10) || /* 640x350/4 */
378 (ORIG_VIDEO_MODE == 0x12) || /* 640x480/4 */ 381 (ORIG_VIDEO_MODE == 0x12) || /* 640x480/4 */
@@ -578,12 +581,14 @@ static void vgacon_deinit(struct vc_data *c)
578} 581}
579 582
580static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity, 583static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
581 u8 blink, u8 underline, u8 reverse) 584 u8 blink, u8 underline, u8 reverse, u8 italic)
582{ 585{
583 u8 attr = color; 586 u8 attr = color;
584 587
585 if (vga_can_do_color) { 588 if (vga_can_do_color) {
586 if (underline) 589 if (italic)
590 attr = (attr & 0xF0) | c->vc_itcolor;
591 else if (underline)
587 attr = (attr & 0xf0) | c->vc_ulcolor; 592 attr = (attr & 0xf0) | c->vc_ulcolor;
588 else if (intensity == 0) 593 else if (intensity == 0)
589 attr = (attr & 0xf0) | c->vc_halfcolor; 594 attr = (attr & 0xf0) | c->vc_halfcolor;
@@ -597,7 +602,9 @@ static u8 vgacon_build_attr(struct vc_data *c, u8 color, u8 intensity,
597 if (intensity == 2) 602 if (intensity == 2)
598 attr ^= 0x08; 603 attr ^= 0x08;
599 if (!vga_can_do_color) { 604 if (!vga_can_do_color) {
600 if (underline) 605 if (italic)
606 attr = (attr & 0xF8) | 0x02;
607 else if (underline)
601 attr = (attr & 0xf8) | 0x01; 608 attr = (attr & 0xf8) | 0x01;
602 else if (intensity == 0) 609 else if (intensity == 0)
603 attr = (attr & 0xf0) | 0x08; 610 attr = (attr & 0xf0) | 0x08;
@@ -658,6 +665,9 @@ static void vgacon_set_cursor_size(int xpos, int from, int to)
658 665
659static void vgacon_cursor(struct vc_data *c, int mode) 666static void vgacon_cursor(struct vc_data *c, int mode)
660{ 667{
668 if (c->vc_mode != KD_TEXT)
669 return;
670
661 vgacon_restore_screen(c); 671 vgacon_restore_screen(c);
662 672
663 switch (mode) { 673 switch (mode) {
@@ -1316,7 +1326,7 @@ static int vgacon_scroll(struct vc_data *c, int t, int b, int dir,
1316 unsigned long oldo; 1326 unsigned long oldo;
1317 unsigned int delta; 1327 unsigned int delta;
1318 1328
1319 if (t || b != c->vc_rows || vga_is_gfx) 1329 if (t || b != c->vc_rows || vga_is_gfx || c->vc_mode != KD_TEXT)
1320 return 0; 1330 return 0;
1321 1331
1322 if (!vga_hardscroll_enabled || lines >= c->vc_rows / 2) 1332 if (!vga_hardscroll_enabled || lines >= c->vc_rows / 2)
diff --git a/drivers/video/display/Kconfig b/drivers/video/display/Kconfig
new file mode 100644
index 000000000000..f99af931d4f8
--- /dev/null
+++ b/drivers/video/display/Kconfig
@@ -0,0 +1,24 @@
1#
2# Display drivers configuration
3#
4
5menu "Display device support"
6
7config DISPLAY_SUPPORT
8 tristate "Display panel/monitor support"
9 ---help---
10 This framework adds support for low-level control of a display.
11 This includes support for power.
12
13 Enable this to be able to choose the drivers for controlling the
14 physical display panel/monitor on some platforms. This not only
15 covers LCD displays for PDAs but also other types of displays
16 such as CRT, TVout etc.
17
18 To have support for your specific display panel you will have to
19 select the proper drivers which depend on this option.
20
21comment "Display hardware drivers"
22 depends on DISPLAY_SUPPORT
23
24endmenu
diff --git a/drivers/video/display/Makefile b/drivers/video/display/Makefile
new file mode 100644
index 000000000000..c0ea832bf171
--- /dev/null
+++ b/drivers/video/display/Makefile
@@ -0,0 +1,6 @@
1# Display drivers
2
3display-objs := display-sysfs.o
4
5obj-$(CONFIG_DISPLAY_SUPPORT) += display.o
6
diff --git a/drivers/video/display/display-sysfs.c b/drivers/video/display/display-sysfs.c
new file mode 100644
index 000000000000..35477177bef4
--- /dev/null
+++ b/drivers/video/display/display-sysfs.c
@@ -0,0 +1,217 @@
1/*
2 * display-sysfs.c - Display output driver sysfs interface
3 *
4 * Copyright (C) 2007 James Simmons <jsimmons@infradead.org>
5 *
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or (at
11 * your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 *
22 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
23 */
24#include <linux/module.h>
25#include <linux/display.h>
26#include <linux/ctype.h>
27#include <linux/idr.h>
28#include <linux/err.h>
29
30static ssize_t display_show_name(struct device *dev,
31 struct device_attribute *attr, char *buf)
32{
33 struct display_device *dsp = dev_get_drvdata(dev);
34 return snprintf(buf, PAGE_SIZE, "%s\n", dsp->name);
35}
36
37static ssize_t display_show_type(struct device *dev,
38 struct device_attribute *attr, char *buf)
39{
40 struct display_device *dsp = dev_get_drvdata(dev);
41 return snprintf(buf, PAGE_SIZE, "%s\n", dsp->type);
42}
43
44static ssize_t display_show_contrast(struct device *dev,
45 struct device_attribute *attr, char *buf)
46{
47 struct display_device *dsp = dev_get_drvdata(dev);
48 ssize_t rc = -ENXIO;
49
50 mutex_lock(&dsp->lock);
51 if (likely(dsp->driver) && dsp->driver->get_contrast)
52 rc = sprintf(buf, "%d\n", dsp->driver->get_contrast(dsp));
53 mutex_unlock(&dsp->lock);
54 return rc;
55}
56
57static ssize_t display_store_contrast(struct device *dev,
58 struct device_attribute *attr,
59 const char *buf, size_t count)
60{
61 struct display_device *dsp = dev_get_drvdata(dev);
62 ssize_t ret = -EINVAL, size;
63 int contrast;
64 char *endp;
65
66 contrast = simple_strtoul(buf, &endp, 0);
67 size = endp - buf;
68
69 if (*endp && isspace(*endp))
70 size++;
71
72 if (size != count)
73 return ret;
74
75 mutex_lock(&dsp->lock);
76 if (likely(dsp->driver && dsp->driver->set_contrast)) {
77 pr_debug("display: set contrast to %d\n", contrast);
78 dsp->driver->set_contrast(dsp, contrast);
79 ret = count;
80 }
81 mutex_unlock(&dsp->lock);
82 return ret;
83}
84
85static ssize_t display_show_max_contrast(struct device *dev,
86 struct device_attribute *attr,
87 char *buf)
88{
89 struct display_device *dsp = dev_get_drvdata(dev);
90 ssize_t rc = -ENXIO;
91
92 mutex_lock(&dsp->lock);
93 if (likely(dsp->driver))
94 rc = sprintf(buf, "%d\n", dsp->driver->max_contrast);
95 mutex_unlock(&dsp->lock);
96 return rc;
97}
98
99static struct device_attribute display_attrs[] = {
100 __ATTR(name, S_IRUGO, display_show_name, NULL),
101 __ATTR(type, S_IRUGO, display_show_type, NULL),
102 __ATTR(contrast, S_IRUGO | S_IWUSR, display_show_contrast, display_store_contrast),
103 __ATTR(max_contrast, S_IRUGO, display_show_max_contrast, NULL),
104};
105
106static int display_suspend(struct device *dev, pm_message_t state)
107{
108 struct display_device *dsp = dev_get_drvdata(dev);
109
110 mutex_lock(&dsp->lock);
111 if (likely(dsp->driver->suspend))
112 dsp->driver->suspend(dsp, state);
113 mutex_unlock(&dsp->lock);
114 return 0;
115};
116
117static int display_resume(struct device *dev)
118{
119 struct display_device *dsp = dev_get_drvdata(dev);
120
121 mutex_lock(&dsp->lock);
122 if (likely(dsp->driver->resume))
123 dsp->driver->resume(dsp);
124 mutex_unlock(&dsp->lock);
125 return 0;
126};
127
128static struct mutex allocated_dsp_lock;
129static DEFINE_IDR(allocated_dsp);
130static struct class *display_class;
131
132struct display_device *display_device_register(struct display_driver *driver,
133 struct device *parent, void *devdata)
134{
135 struct display_device *new_dev = NULL;
136 int ret = -EINVAL;
137
138 if (unlikely(!driver))
139 return ERR_PTR(ret);
140
141 mutex_lock(&allocated_dsp_lock);
142 ret = idr_pre_get(&allocated_dsp, GFP_KERNEL);
143 mutex_unlock(&allocated_dsp_lock);
144 if (!ret)
145 return ERR_PTR(ret);
146
147 new_dev = kzalloc(sizeof(struct display_device), GFP_KERNEL);
148 if (likely(new_dev) && unlikely(driver->probe(new_dev, devdata))) {
149 // Reserve the index for this display
150 mutex_lock(&allocated_dsp_lock);
151 ret = idr_get_new(&allocated_dsp, new_dev, &new_dev->idx);
152 mutex_unlock(&allocated_dsp_lock);
153
154 if (!ret) {
155 new_dev->dev = device_create(display_class, parent, 0,
156 "display%d", new_dev->idx);
157 if (!IS_ERR(new_dev->dev)) {
158 dev_set_drvdata(new_dev->dev, new_dev);
159 new_dev->parent = parent;
160 new_dev->driver = driver;
161 mutex_init(&new_dev->lock);
162 return new_dev;
163 }
164 mutex_lock(&allocated_dsp_lock);
165 idr_remove(&allocated_dsp, new_dev->idx);
166 mutex_unlock(&allocated_dsp_lock);
167 ret = -EINVAL;
168 }
169 }
170 kfree(new_dev);
171 return ERR_PTR(ret);
172}
173EXPORT_SYMBOL(display_device_register);
174
175void display_device_unregister(struct display_device *ddev)
176{
177 if (!ddev)
178 return;
179 // Free device
180 mutex_lock(&ddev->lock);
181 device_unregister(ddev->dev);
182 mutex_unlock(&ddev->lock);
183 // Mark device index as avaliable
184 mutex_lock(&allocated_dsp_lock);
185 idr_remove(&allocated_dsp, ddev->idx);
186 mutex_unlock(&allocated_dsp_lock);
187 kfree(ddev);
188}
189EXPORT_SYMBOL(display_device_unregister);
190
191static int __init display_class_init(void)
192{
193 display_class = class_create(THIS_MODULE, "display");
194 if (IS_ERR(display_class)) {
195 printk(KERN_ERR "Failed to create display class\n");
196 display_class = NULL;
197 return -EINVAL;
198 }
199 display_class->dev_attrs = display_attrs;
200 display_class->suspend = display_suspend;
201 display_class->resume = display_resume;
202 mutex_init(&allocated_dsp_lock);
203 return 0;
204}
205
206static void __exit display_class_exit(void)
207{
208 class_destroy(display_class);
209}
210
211module_init(display_class_init);
212module_exit(display_class_exit);
213
214MODULE_DESCRIPTION("Display Hardware handling");
215MODULE_AUTHOR("James Simmons <jsimmons@infradead.org>");
216MODULE_LICENSE("GPL");
217
diff --git a/drivers/video/epson1355fb.c b/drivers/video/epson1355fb.c
index 29e07c109887..ca2c54ce508e 100644
--- a/drivers/video/epson1355fb.c
+++ b/drivers/video/epson1355fb.c
@@ -403,17 +403,10 @@ static inline unsigned long copy_to_user16(void *to, const void *from,
403 403
404 404
405static ssize_t 405static ssize_t
406epson1355fb_read(struct file *file, char *buf, size_t count, loff_t * ppos) 406epson1355fb_read(struct fb_info *info, char *buf, size_t count, loff_t * ppos)
407{ 407{
408 struct inode *inode = file->f_path.dentry->d_inode;
409 int fbidx = iminor(inode);
410 struct fb_info *info = registered_fb[fbidx];
411 unsigned long p = *ppos; 408 unsigned long p = *ppos;
412 409
413 /* from fbmem.c except for our own copy_*_user */
414 if (!info || !info->screen_base)
415 return -ENODEV;
416
417 if (p >= info->fix.smem_len) 410 if (p >= info->fix.smem_len)
418 return 0; 411 return 0;
419 if (count >= info->fix.smem_len) 412 if (count >= info->fix.smem_len)
@@ -434,20 +427,13 @@ epson1355fb_read(struct file *file, char *buf, size_t count, loff_t * ppos)
434} 427}
435 428
436static ssize_t 429static ssize_t
437epson1355fb_write(struct file *file, const char *buf, 430epson1355fb_write(struct fb_info *info, const char *buf,
438 size_t count, loff_t * ppos) 431 size_t count, loff_t * ppos)
439{ 432{
440 struct inode *inode = file->f_path.dentry->d_inode;
441 int fbidx = iminor(inode);
442 struct fb_info *info = registered_fb[fbidx];
443 unsigned long p = *ppos; 433 unsigned long p = *ppos;
444 int err; 434 int err;
445 435
446 /* from fbmem.c except for our own copy_*_user */ 436 /* from fbmem.c except for our own copy_*_user */
447 if (!info || !info->screen_base)
448 return -ENODEV;
449
450 /* from fbmem.c except for our own copy_*_user */
451 if (p > info->fix.smem_len) 437 if (p > info->fix.smem_len)
452 return -ENOSPC; 438 return -ENOSPC;
453 if (count >= info->fix.smem_len) 439 if (count >= info->fix.smem_len)
@@ -650,9 +636,10 @@ int __init epson1355fb_probe(struct platform_device *dev)
650 } 636 }
651 637
652 info = framebuffer_alloc(sizeof(struct epson1355_par) + sizeof(u32) * 256, &dev->dev); 638 info = framebuffer_alloc(sizeof(struct epson1355_par) + sizeof(u32) * 256, &dev->dev);
653 if (!info) 639 if (!info) {
654 rc = -ENOMEM; 640 rc = -ENOMEM;
655 goto bail; 641 goto bail;
642 }
656 643
657 default_par = info->par; 644 default_par = info->par;
658 default_par->reg_addr = (unsigned long) ioremap(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN); 645 default_par->reg_addr = (unsigned long) ioremap(EPSON1355FB_REGS_PHYS, EPSON1355FB_REGS_LEN);
diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
new file mode 100644
index 000000000000..1a8643f053d8
--- /dev/null
+++ b/drivers/video/fb_defio.c
@@ -0,0 +1,151 @@
1/*
2 * linux/drivers/video/fb_defio.c
3 *
4 * Copyright (C) 2006 Jaya Kumar
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/string.h>
15#include <linux/mm.h>
16#include <linux/slab.h>
17#include <linux/vmalloc.h>
18#include <linux/delay.h>
19#include <linux/interrupt.h>
20#include <linux/fb.h>
21#include <linux/list.h>
22#include <asm/uaccess.h>
23
24/* to support deferred IO */
25#include <linux/rmap.h>
26#include <linux/pagemap.h>
27
28/* this is to find and return the vmalloc-ed fb pages */
29static struct page* fb_deferred_io_nopage(struct vm_area_struct *vma,
30 unsigned long vaddr, int *type)
31{
32 unsigned long offset;
33 struct page *page;
34 struct fb_info *info = vma->vm_private_data;
35 /* info->screen_base is in System RAM */
36 void *screen_base = (void __force *) info->screen_base;
37
38 offset = (vaddr - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
39 if (offset >= info->fix.smem_len)
40 return NOPAGE_SIGBUS;
41
42 page = vmalloc_to_page(screen_base + offset);
43 if (!page)
44 return NOPAGE_OOM;
45
46 get_page(page);
47 if (type)
48 *type = VM_FAULT_MINOR;
49 return page;
50}
51
52int fb_deferred_io_fsync(struct file *file, struct dentry *dentry, int datasync)
53{
54 struct fb_info *info = file->private_data;
55
56 /* Kill off the delayed work */
57 cancel_rearming_delayed_work(&info->deferred_work);
58
59 /* Run it immediately */
60 return schedule_delayed_work(&info->deferred_work, 0);
61}
62EXPORT_SYMBOL_GPL(fb_deferred_io_fsync);
63
64/* vm_ops->page_mkwrite handler */
65static int fb_deferred_io_mkwrite(struct vm_area_struct *vma,
66 struct page *page)
67{
68 struct fb_info *info = vma->vm_private_data;
69 struct fb_deferred_io *fbdefio = info->fbdefio;
70
71 /* this is a callback we get when userspace first tries to
72 write to the page. we schedule a workqueue. that workqueue
73 will eventually mkclean the touched pages and execute the
74 deferred framebuffer IO. then if userspace touches a page
75 again, we repeat the same scheme */
76
77 /* protect against the workqueue changing the page list */
78 mutex_lock(&fbdefio->lock);
79 list_add(&page->lru, &fbdefio->pagelist);
80 mutex_unlock(&fbdefio->lock);
81
82 /* come back after delay to process the deferred IO */
83 schedule_delayed_work(&info->deferred_work, fbdefio->delay);
84 return 0;
85}
86
87static struct vm_operations_struct fb_deferred_io_vm_ops = {
88 .nopage = fb_deferred_io_nopage,
89 .page_mkwrite = fb_deferred_io_mkwrite,
90};
91
92static int fb_deferred_io_mmap(struct fb_info *info, struct vm_area_struct *vma)
93{
94 vma->vm_ops = &fb_deferred_io_vm_ops;
95 vma->vm_flags |= ( VM_IO | VM_RESERVED | VM_DONTEXPAND );
96 vma->vm_private_data = info;
97 return 0;
98}
99
100/* workqueue callback */
101static void fb_deferred_io_work(struct work_struct *work)
102{
103 struct fb_info *info = container_of(work, struct fb_info,
104 deferred_work.work);
105 struct list_head *node, *next;
106 struct page *cur;
107 struct fb_deferred_io *fbdefio = info->fbdefio;
108
109 /* here we mkclean the pages, then do all deferred IO */
110 mutex_lock(&fbdefio->lock);
111 list_for_each_entry(cur, &fbdefio->pagelist, lru) {
112 lock_page(cur);
113 page_mkclean(cur);
114 unlock_page(cur);
115 }
116
117 /* driver's callback with pagelist */
118 fbdefio->deferred_io(info, &fbdefio->pagelist);
119
120 /* clear the list */
121 list_for_each_safe(node, next, &fbdefio->pagelist) {
122 list_del(node);
123 }
124 mutex_unlock(&fbdefio->lock);
125}
126
127void fb_deferred_io_init(struct fb_info *info)
128{
129 struct fb_deferred_io *fbdefio = info->fbdefio;
130
131 BUG_ON(!fbdefio);
132 mutex_init(&fbdefio->lock);
133 info->fbops->fb_mmap = fb_deferred_io_mmap;
134 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
135 INIT_LIST_HEAD(&fbdefio->pagelist);
136 if (fbdefio->delay == 0) /* set a default of 1 s */
137 fbdefio->delay = HZ;
138}
139EXPORT_SYMBOL_GPL(fb_deferred_io_init);
140
141void fb_deferred_io_cleanup(struct fb_info *info)
142{
143 struct fb_deferred_io *fbdefio = info->fbdefio;
144
145 BUG_ON(!fbdefio);
146 cancel_delayed_work(&info->deferred_work);
147 flush_scheduled_work();
148}
149EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
150
151MODULE_LICENSE("GPL");
diff --git a/drivers/video/fb_draw.h b/drivers/video/fb_draw.h
new file mode 100644
index 000000000000..c5c45203833b
--- /dev/null
+++ b/drivers/video/fb_draw.h
@@ -0,0 +1,72 @@
1#ifndef _FB_DRAW_H
2#define _FB_DRAW_H
3
4#include <asm/types.h>
5
6 /*
7 * Compose two values, using a bitmask as decision value
8 * This is equivalent to (a & mask) | (b & ~mask)
9 */
10
11static inline unsigned long
12comp(unsigned long a, unsigned long b, unsigned long mask)
13{
14 return ((a ^ b) & mask) ^ b;
15}
16
17 /*
18 * Create a pattern with the given pixel's color
19 */
20
21#if BITS_PER_LONG == 64
22static inline unsigned long
23pixel_to_pat( u32 bpp, u32 pixel)
24{
25 switch (bpp) {
26 case 1:
27 return 0xfffffffffffffffful*pixel;
28 case 2:
29 return 0x5555555555555555ul*pixel;
30 case 4:
31 return 0x1111111111111111ul*pixel;
32 case 8:
33 return 0x0101010101010101ul*pixel;
34 case 12:
35 return 0x0001001001001001ul*pixel;
36 case 16:
37 return 0x0001000100010001ul*pixel;
38 case 24:
39 return 0x0000000001000001ul*pixel;
40 case 32:
41 return 0x0000000100000001ul*pixel;
42 default:
43 panic("pixel_to_pat(): unsupported pixelformat\n");
44 }
45}
46#else
47static inline unsigned long
48pixel_to_pat( u32 bpp, u32 pixel)
49{
50 switch (bpp) {
51 case 1:
52 return 0xfffffffful*pixel;
53 case 2:
54 return 0x55555555ul*pixel;
55 case 4:
56 return 0x11111111ul*pixel;
57 case 8:
58 return 0x01010101ul*pixel;
59 case 12:
60 return 0x00001001ul*pixel;
61 case 16:
62 return 0x00010001ul*pixel;
63 case 24:
64 return 0x00000001ul*pixel;
65 case 32:
66 return 0x00000001ul*pixel;
67 default:
68 panic("pixel_to_pat(): unsupported pixelformat\n");
69 }
70}
71#endif
72#endif /* FB_DRAW_H */
diff --git a/drivers/video/fb_sys_fops.c b/drivers/video/fb_sys_fops.c
new file mode 100644
index 000000000000..cf2538d669cd
--- /dev/null
+++ b/drivers/video/fb_sys_fops.c
@@ -0,0 +1,104 @@
1/*
2 * linux/drivers/video/fb_sys_read.c - Generic file operations where
3 * framebuffer is in system RAM
4 *
5 * Copyright (C) 2007 Antonino Daplas <adaplas@pol.net>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive
9 * for more details.
10 *
11 */
12#include <linux/fb.h>
13#include <linux/module.h>
14#include <asm/uaccess.h>
15
16ssize_t fb_sys_read(struct fb_info *info, char __user *buf, size_t count,
17 loff_t *ppos)
18{
19 unsigned long p = *ppos;
20 void *src;
21 int err = 0;
22 unsigned long total_size;
23
24 if (info->state != FBINFO_STATE_RUNNING)
25 return -EPERM;
26
27 total_size = info->screen_size;
28
29 if (total_size == 0)
30 total_size = info->fix.smem_len;
31
32 if (p >= total_size)
33 return 0;
34
35 if (count >= total_size)
36 count = total_size;
37
38 if (count + p > total_size)
39 count = total_size - p;
40
41 src = (void __force *)(info->screen_base + p);
42
43 if (info->fbops->fb_sync)
44 info->fbops->fb_sync(info);
45
46 if (copy_to_user(buf, src, count))
47 err = -EFAULT;
48
49 if (!err)
50 *ppos += count;
51
52 return (err) ? err : count;
53}
54EXPORT_SYMBOL_GPL(fb_sys_read);
55
56ssize_t fb_sys_write(struct fb_info *info, const char __user *buf,
57 size_t count, loff_t *ppos)
58{
59 unsigned long p = *ppos;
60 void *dst;
61 int err = 0;
62 unsigned long total_size;
63
64 if (info->state != FBINFO_STATE_RUNNING)
65 return -EPERM;
66
67 total_size = info->screen_size;
68
69 if (total_size == 0)
70 total_size = info->fix.smem_len;
71
72 if (p > total_size)
73 return -EFBIG;
74
75 if (count > total_size) {
76 err = -EFBIG;
77 count = total_size;
78 }
79
80 if (count + p > total_size) {
81 if (!err)
82 err = -ENOSPC;
83
84 count = total_size - p;
85 }
86
87 dst = (void __force *) (info->screen_base + p);
88
89 if (info->fbops->fb_sync)
90 info->fbops->fb_sync(info);
91
92 if (copy_from_user(dst, buf, count))
93 err = -EFAULT;
94
95 if (!err)
96 *ppos += count;
97
98 return (err) ? err : count;
99}
100EXPORT_SYMBOL_GPL(fb_sys_write);
101
102MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
103MODULE_DESCRIPTION("Generic file read (fb in system RAM)");
104MODULE_LICENSE("GPL");
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 28225265159a..38c2e2558f5e 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -354,59 +354,59 @@ static void fb_rotate_logo(struct fb_info *info, u8 *dst,
354 if (rotate == FB_ROTATE_UD) { 354 if (rotate == FB_ROTATE_UD) {
355 fb_rotate_logo_ud(image->data, dst, image->width, 355 fb_rotate_logo_ud(image->data, dst, image->width,
356 image->height); 356 image->height);
357 image->dx = info->var.xres - image->width; 357 image->dx = info->var.xres - image->width - image->dx;
358 image->dy = info->var.yres - image->height; 358 image->dy = info->var.yres - image->height - image->dy;
359 } else if (rotate == FB_ROTATE_CW) { 359 } else if (rotate == FB_ROTATE_CW) {
360 fb_rotate_logo_cw(image->data, dst, image->width, 360 fb_rotate_logo_cw(image->data, dst, image->width,
361 image->height); 361 image->height);
362 tmp = image->width; 362 tmp = image->width;
363 image->width = image->height; 363 image->width = image->height;
364 image->height = tmp; 364 image->height = tmp;
365 image->dx = info->var.xres - image->width; 365 tmp = image->dy;
366 image->dy = image->dx;
367 image->dx = info->var.xres - image->width - tmp;
366 } else if (rotate == FB_ROTATE_CCW) { 368 } else if (rotate == FB_ROTATE_CCW) {
367 fb_rotate_logo_ccw(image->data, dst, image->width, 369 fb_rotate_logo_ccw(image->data, dst, image->width,
368 image->height); 370 image->height);
369 tmp = image->width; 371 tmp = image->width;
370 image->width = image->height; 372 image->width = image->height;
371 image->height = tmp; 373 image->height = tmp;
372 image->dy = info->var.yres - image->height; 374 tmp = image->dx;
375 image->dx = image->dy;
376 image->dy = info->var.yres - image->height - tmp;
373 } 377 }
374 378
375 image->data = dst; 379 image->data = dst;
376} 380}
377 381
378static void fb_do_show_logo(struct fb_info *info, struct fb_image *image, 382static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
379 int rotate) 383 int rotate, unsigned int num)
380{ 384{
381 int x; 385 unsigned int x;
382 386
383 if (rotate == FB_ROTATE_UR) { 387 if (rotate == FB_ROTATE_UR) {
384 for (x = 0; x < num_online_cpus() && 388 for (x = 0;
385 x * (fb_logo.logo->width + 8) <= 389 x < num && image->dx + image->width <= info->var.xres;
386 info->var.xres - fb_logo.logo->width; x++) { 390 x++) {
387 info->fbops->fb_imageblit(info, image); 391 info->fbops->fb_imageblit(info, image);
388 image->dx += fb_logo.logo->width + 8; 392 image->dx += image->width + 8;
389 } 393 }
390 } else if (rotate == FB_ROTATE_UD) { 394 } else if (rotate == FB_ROTATE_UD) {
391 for (x = 0; x < num_online_cpus() && 395 for (x = 0; x < num && image->dx >= 0; x++) {
392 x * (fb_logo.logo->width + 8) <=
393 info->var.xres - fb_logo.logo->width; x++) {
394 info->fbops->fb_imageblit(info, image); 396 info->fbops->fb_imageblit(info, image);
395 image->dx -= fb_logo.logo->width + 8; 397 image->dx -= image->width + 8;
396 } 398 }
397 } else if (rotate == FB_ROTATE_CW) { 399 } else if (rotate == FB_ROTATE_CW) {
398 for (x = 0; x < num_online_cpus() && 400 for (x = 0;
399 x * (fb_logo.logo->width + 8) <= 401 x < num && image->dy + image->height <= info->var.yres;
400 info->var.yres - fb_logo.logo->width; x++) { 402 x++) {
401 info->fbops->fb_imageblit(info, image); 403 info->fbops->fb_imageblit(info, image);
402 image->dy += fb_logo.logo->width + 8; 404 image->dy += image->height + 8;
403 } 405 }
404 } else if (rotate == FB_ROTATE_CCW) { 406 } else if (rotate == FB_ROTATE_CCW) {
405 for (x = 0; x < num_online_cpus() && 407 for (x = 0; x < num && image->dy >= 0; x++) {
406 x * (fb_logo.logo->width + 8) <=
407 info->var.yres - fb_logo.logo->width; x++) {
408 info->fbops->fb_imageblit(info, image); 408 info->fbops->fb_imageblit(info, image);
409 image->dy -= fb_logo.logo->width + 8; 409 image->dy -= image->height + 8;
410 } 410 }
411 } 411 }
412} 412}
@@ -418,7 +418,8 @@ int fb_prepare_logo(struct fb_info *info, int rotate)
418 418
419 memset(&fb_logo, 0, sizeof(struct logo_data)); 419 memset(&fb_logo, 0, sizeof(struct logo_data));
420 420
421 if (info->flags & FBINFO_MISC_TILEBLITTING) 421 if (info->flags & FBINFO_MISC_TILEBLITTING ||
422 info->flags & FBINFO_MODULE)
422 return 0; 423 return 0;
423 424
424 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) { 425 if (info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
@@ -483,7 +484,8 @@ int fb_show_logo(struct fb_info *info, int rotate)
483 struct fb_image image; 484 struct fb_image image;
484 485
485 /* Return if the frame buffer is not mapped or suspended */ 486 /* Return if the frame buffer is not mapped or suspended */
486 if (fb_logo.logo == NULL || info->state != FBINFO_STATE_RUNNING) 487 if (fb_logo.logo == NULL || info->state != FBINFO_STATE_RUNNING ||
488 info->flags & FBINFO_MODULE)
487 return 0; 489 return 0;
488 490
489 image.depth = 8; 491 image.depth = 8;
@@ -532,7 +534,7 @@ int fb_show_logo(struct fb_info *info, int rotate)
532 fb_rotate_logo(info, logo_rotate, &image, rotate); 534 fb_rotate_logo(info, logo_rotate, &image, rotate);
533 } 535 }
534 536
535 fb_do_show_logo(info, &image, rotate); 537 fb_do_show_logo(info, &image, rotate, num_online_cpus());
536 538
537 kfree(palette); 539 kfree(palette);
538 if (saved_pseudo_palette != NULL) 540 if (saved_pseudo_palette != NULL)
@@ -586,7 +588,7 @@ fb_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
586 return -EPERM; 588 return -EPERM;
587 589
588 if (info->fbops->fb_read) 590 if (info->fbops->fb_read)
589 return info->fbops->fb_read(file, buf, count, ppos); 591 return info->fbops->fb_read(info, buf, count, ppos);
590 592
591 total_size = info->screen_size; 593 total_size = info->screen_size;
592 594
@@ -661,7 +663,7 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
661 return -EPERM; 663 return -EPERM;
662 664
663 if (info->fbops->fb_write) 665 if (info->fbops->fb_write)
664 return info->fbops->fb_write(file, buf, count, ppos); 666 return info->fbops->fb_write(info, buf, count, ppos);
665 667
666 total_size = info->screen_size; 668 total_size = info->screen_size;
667 669
@@ -771,14 +773,37 @@ fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
771 return 0; 773 return 0;
772} 774}
773 775
776static int fb_check_caps(struct fb_info *info, struct fb_var_screeninfo *var,
777 u32 activate)
778{
779 struct fb_event event;
780 struct fb_blit_caps caps, fbcaps;
781 int err = 0;
782
783 memset(&caps, 0, sizeof(caps));
784 memset(&fbcaps, 0, sizeof(fbcaps));
785 caps.flags = (activate & FB_ACTIVATE_ALL) ? 1 : 0;
786 event.info = info;
787 event.data = &caps;
788 fb_notifier_call_chain(FB_EVENT_GET_REQ, &event);
789 info->fbops->fb_get_caps(info, &fbcaps, var);
790
791 if (((fbcaps.x ^ caps.x) & caps.x) ||
792 ((fbcaps.y ^ caps.y) & caps.y) ||
793 (fbcaps.len < caps.len))
794 err = -EINVAL;
795
796 return err;
797}
798
774int 799int
775fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) 800fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
776{ 801{
777 int err, flags = info->flags; 802 int flags = info->flags;
803 int ret = 0;
778 804
779 if (var->activate & FB_ACTIVATE_INV_MODE) { 805 if (var->activate & FB_ACTIVATE_INV_MODE) {
780 struct fb_videomode mode1, mode2; 806 struct fb_videomode mode1, mode2;
781 int ret = 0;
782 807
783 fb_var_to_videomode(&mode1, var); 808 fb_var_to_videomode(&mode1, var);
784 fb_var_to_videomode(&mode2, &info->var); 809 fb_var_to_videomode(&mode2, &info->var);
@@ -796,40 +821,51 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
796 if (!ret) 821 if (!ret)
797 fb_delete_videomode(&mode1, &info->modelist); 822 fb_delete_videomode(&mode1, &info->modelist);
798 823
799 return ret; 824
825 ret = (ret) ? -EINVAL : 0;
826 goto done;
800 } 827 }
801 828
802 if ((var->activate & FB_ACTIVATE_FORCE) || 829 if ((var->activate & FB_ACTIVATE_FORCE) ||
803 memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) { 830 memcmp(&info->var, var, sizeof(struct fb_var_screeninfo))) {
831 u32 activate = var->activate;
832
804 if (!info->fbops->fb_check_var) { 833 if (!info->fbops->fb_check_var) {
805 *var = info->var; 834 *var = info->var;
806 return 0; 835 goto done;
807 } 836 }
808 837
809 if ((err = info->fbops->fb_check_var(var, info))) 838 ret = info->fbops->fb_check_var(var, info);
810 return err; 839
840 if (ret)
841 goto done;
811 842
812 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) { 843 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
813 struct fb_videomode mode; 844 struct fb_videomode mode;
814 int err = 0; 845
846 if (info->fbops->fb_get_caps) {
847 ret = fb_check_caps(info, var, activate);
848
849 if (ret)
850 goto done;
851 }
815 852
816 info->var = *var; 853 info->var = *var;
854
817 if (info->fbops->fb_set_par) 855 if (info->fbops->fb_set_par)
818 info->fbops->fb_set_par(info); 856 info->fbops->fb_set_par(info);
819 857
820 fb_pan_display(info, &info->var); 858 fb_pan_display(info, &info->var);
821
822 fb_set_cmap(&info->cmap, info); 859 fb_set_cmap(&info->cmap, info);
823
824 fb_var_to_videomode(&mode, &info->var); 860 fb_var_to_videomode(&mode, &info->var);
825 861
826 if (info->modelist.prev && info->modelist.next && 862 if (info->modelist.prev && info->modelist.next &&
827 !list_empty(&info->modelist)) 863 !list_empty(&info->modelist))
828 err = fb_add_videomode(&mode, &info->modelist); 864 ret = fb_add_videomode(&mode, &info->modelist);
829 865
830 if (!err && (flags & FBINFO_MISC_USEREVENT)) { 866 if (!ret && (flags & FBINFO_MISC_USEREVENT)) {
831 struct fb_event event; 867 struct fb_event event;
832 int evnt = (var->activate & FB_ACTIVATE_ALL) ? 868 int evnt = (activate & FB_ACTIVATE_ALL) ?
833 FB_EVENT_MODE_CHANGE_ALL : 869 FB_EVENT_MODE_CHANGE_ALL :
834 FB_EVENT_MODE_CHANGE; 870 FB_EVENT_MODE_CHANGE;
835 871
@@ -839,7 +875,9 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
839 } 875 }
840 } 876 }
841 } 877 }
842 return 0; 878
879 done:
880 return ret;
843} 881}
844 882
845int 883int
@@ -1198,6 +1236,10 @@ fb_mmap(struct file *file, struct vm_area_struct * vma)
1198 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE; 1236 pgprot_val(vma->vm_page_prot) |= _PAGE_NO_CACHE;
1199#elif defined(__arm__) || defined(__sh__) || defined(__m32r__) 1237#elif defined(__arm__) || defined(__sh__) || defined(__m32r__)
1200 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); 1238 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
1239#elif defined(__avr32__)
1240 vma->vm_page_prot = __pgprot((pgprot_val(vma->vm_page_prot)
1241 & ~_PAGE_CACHABLE)
1242 | (_PAGE_BUFFER | _PAGE_DIRTY));
1201#elif defined(__ia64__) 1243#elif defined(__ia64__)
1202 if (efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start)) 1244 if (efi_range_is_wc(vma->vm_start, vma->vm_end - vma->vm_start))
1203 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot); 1245 vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
@@ -1266,6 +1308,9 @@ static const struct file_operations fb_fops = {
1266#ifdef HAVE_ARCH_FB_UNMAPPED_AREA 1308#ifdef HAVE_ARCH_FB_UNMAPPED_AREA
1267 .get_unmapped_area = get_fb_unmapped_area, 1309 .get_unmapped_area = get_fb_unmapped_area,
1268#endif 1310#endif
1311#ifdef CONFIG_FB_DEFERRED_IO
1312 .fsync = fb_deferred_io_fsync,
1313#endif
1269}; 1314};
1270 1315
1271struct class *fb_class; 1316struct class *fb_class;
@@ -1316,6 +1361,12 @@ register_framebuffer(struct fb_info *fb_info)
1316 } 1361 }
1317 fb_info->pixmap.offset = 0; 1362 fb_info->pixmap.offset = 0;
1318 1363
1364 if (!fb_info->pixmap.blit_x)
1365 fb_info->pixmap.blit_x = ~(u32)0;
1366
1367 if (!fb_info->pixmap.blit_y)
1368 fb_info->pixmap.blit_y = ~(u32)0;
1369
1319 if (!fb_info->modelist.prev || !fb_info->modelist.next) 1370 if (!fb_info->modelist.prev || !fb_info->modelist.next)
1320 INIT_LIST_HEAD(&fb_info->modelist); 1371 INIT_LIST_HEAD(&fb_info->modelist);
1321 1372
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 6b385c39b8b5..438b9411905c 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -48,8 +48,9 @@
48#define DPRINTK(fmt, args...) 48#define DPRINTK(fmt, args...)
49#endif 49#endif
50 50
51#define FBMON_FIX_HEADER 1 51#define FBMON_FIX_HEADER 1
52#define FBMON_FIX_INPUT 2 52#define FBMON_FIX_INPUT 2
53#define FBMON_FIX_TIMINGS 3
53 54
54#ifdef CONFIG_FB_MODE_HELPERS 55#ifdef CONFIG_FB_MODE_HELPERS
55struct broken_edid { 56struct broken_edid {
@@ -71,6 +72,12 @@ static const struct broken_edid brokendb[] = {
71 .model = 0x5a44, 72 .model = 0x5a44,
72 .fix = FBMON_FIX_INPUT, 73 .fix = FBMON_FIX_INPUT,
73 }, 74 },
75 /* Sharp UXGA? */
76 {
77 .manufacturer = "SHP",
78 .model = 0x138e,
79 .fix = FBMON_FIX_TIMINGS,
80 },
74}; 81};
75 82
76static const unsigned char edid_v1_header[] = { 0x00, 0xff, 0xff, 0xff, 83static const unsigned char edid_v1_header[] = { 0x00, 0xff, 0xff, 0xff,
@@ -87,6 +94,55 @@ static void copy_string(unsigned char *c, unsigned char *s)
87 while (i-- && (*--s == 0x20)) *s = 0; 94 while (i-- && (*--s == 0x20)) *s = 0;
88} 95}
89 96
97static int edid_is_serial_block(unsigned char *block)
98{
99 if ((block[0] == 0x00) && (block[1] == 0x00) &&
100 (block[2] == 0x00) && (block[3] == 0xff) &&
101 (block[4] == 0x00))
102 return 1;
103 else
104 return 0;
105}
106
107static int edid_is_ascii_block(unsigned char *block)
108{
109 if ((block[0] == 0x00) && (block[1] == 0x00) &&
110 (block[2] == 0x00) && (block[3] == 0xfe) &&
111 (block[4] == 0x00))
112 return 1;
113 else
114 return 0;
115}
116
117static int edid_is_limits_block(unsigned char *block)
118{
119 if ((block[0] == 0x00) && (block[1] == 0x00) &&
120 (block[2] == 0x00) && (block[3] == 0xfd) &&
121 (block[4] == 0x00))
122 return 1;
123 else
124 return 0;
125}
126
127static int edid_is_monitor_block(unsigned char *block)
128{
129 if ((block[0] == 0x00) && (block[1] == 0x00) &&
130 (block[2] == 0x00) && (block[3] == 0xfc) &&
131 (block[4] == 0x00))
132 return 1;
133 else
134 return 0;
135}
136
137static int edid_is_timing_block(unsigned char *block)
138{
139 if ((block[0] != 0x00) || (block[1] != 0x00) ||
140 (block[2] != 0x00) || (block[4] != 0x00))
141 return 1;
142 else
143 return 0;
144}
145
90static int check_edid(unsigned char *edid) 146static int check_edid(unsigned char *edid)
91{ 147{
92 unsigned char *block = edid + ID_MANUFACTURER_NAME, manufacturer[4]; 148 unsigned char *block = edid + ID_MANUFACTURER_NAME, manufacturer[4];
@@ -104,9 +160,6 @@ static int check_edid(unsigned char *edid)
104 for (i = 0; i < ARRAY_SIZE(brokendb); i++) { 160 for (i = 0; i < ARRAY_SIZE(brokendb); i++) {
105 if (!strncmp(manufacturer, brokendb[i].manufacturer, 4) && 161 if (!strncmp(manufacturer, brokendb[i].manufacturer, 4) &&
106 brokendb[i].model == model) { 162 brokendb[i].model == model) {
107 printk("fbmon: The EDID Block of "
108 "Manufacturer: %s Model: 0x%x is known to "
109 "be broken,\n", manufacturer, model);
110 fix = brokendb[i].fix; 163 fix = brokendb[i].fix;
111 break; 164 break;
112 } 165 }
@@ -115,8 +168,10 @@ static int check_edid(unsigned char *edid)
115 switch (fix) { 168 switch (fix) {
116 case FBMON_FIX_HEADER: 169 case FBMON_FIX_HEADER:
117 for (i = 0; i < 8; i++) { 170 for (i = 0; i < 8; i++) {
118 if (edid[i] != edid_v1_header[i]) 171 if (edid[i] != edid_v1_header[i]) {
119 ret = fix; 172 ret = fix;
173 break;
174 }
120 } 175 }
121 break; 176 break;
122 case FBMON_FIX_INPUT: 177 case FBMON_FIX_INPUT:
@@ -126,14 +181,34 @@ static int check_edid(unsigned char *edid)
126 if (b[4] & 0x01 && b[0] & 0x80) 181 if (b[4] & 0x01 && b[0] & 0x80)
127 ret = fix; 182 ret = fix;
128 break; 183 break;
184 case FBMON_FIX_TIMINGS:
185 b = edid + DETAILED_TIMING_DESCRIPTIONS_START;
186 ret = fix;
187
188 for (i = 0; i < 4; i++) {
189 if (edid_is_limits_block(b)) {
190 ret = 0;
191 break;
192 }
193
194 b += DETAILED_TIMING_DESCRIPTION_SIZE;
195 }
196
197 break;
129 } 198 }
130 199
200 if (ret)
201 printk("fbmon: The EDID Block of "
202 "Manufacturer: %s Model: 0x%x is known to "
203 "be broken,\n", manufacturer, model);
204
131 return ret; 205 return ret;
132} 206}
133 207
134static void fix_edid(unsigned char *edid, int fix) 208static void fix_edid(unsigned char *edid, int fix)
135{ 209{
136 unsigned char *b; 210 int i;
211 unsigned char *b, csum = 0;
137 212
138 switch (fix) { 213 switch (fix) {
139 case FBMON_FIX_HEADER: 214 case FBMON_FIX_HEADER:
@@ -145,6 +220,37 @@ static void fix_edid(unsigned char *edid, int fix)
145 b = edid + EDID_STRUCT_DISPLAY; 220 b = edid + EDID_STRUCT_DISPLAY;
146 b[0] &= ~0x80; 221 b[0] &= ~0x80;
147 edid[127] += 0x80; 222 edid[127] += 0x80;
223 break;
224 case FBMON_FIX_TIMINGS:
225 printk("fbmon: trying to fix monitor timings\n");
226 b = edid + DETAILED_TIMING_DESCRIPTIONS_START;
227 for (i = 0; i < 4; i++) {
228 if (!(edid_is_serial_block(b) ||
229 edid_is_ascii_block(b) ||
230 edid_is_monitor_block(b) ||
231 edid_is_timing_block(b))) {
232 b[0] = 0x00;
233 b[1] = 0x00;
234 b[2] = 0x00;
235 b[3] = 0xfd;
236 b[4] = 0x00;
237 b[5] = 60; /* vfmin */
238 b[6] = 60; /* vfmax */
239 b[7] = 30; /* hfmin */
240 b[8] = 75; /* hfmax */
241 b[9] = 17; /* pixclock - 170 MHz*/
242 b[10] = 0; /* GTF */
243 break;
244 }
245
246 b += DETAILED_TIMING_DESCRIPTION_SIZE;
247 }
248
249 for (i = 0; i < EDID_LENGTH - 1; i++)
250 csum += edid[i];
251
252 edid[127] = 256 - csum;
253 break;
148 } 254 }
149} 255}
150 256
@@ -273,46 +379,6 @@ static void get_chroma(unsigned char *block, struct fb_monspecs *specs)
273 DPRINTK("WhiteY: 0.%03d\n", specs->chroma.whitey); 379 DPRINTK("WhiteY: 0.%03d\n", specs->chroma.whitey);
274} 380}
275 381
276static int edid_is_serial_block(unsigned char *block)
277{
278 if ((block[0] == 0x00) && (block[1] == 0x00) &&
279 (block[2] == 0x00) && (block[3] == 0xff) &&
280 (block[4] == 0x00))
281 return 1;
282 else
283 return 0;
284}
285
286static int edid_is_ascii_block(unsigned char *block)
287{
288 if ((block[0] == 0x00) && (block[1] == 0x00) &&
289 (block[2] == 0x00) && (block[3] == 0xfe) &&
290 (block[4] == 0x00))
291 return 1;
292 else
293 return 0;
294}
295
296static int edid_is_limits_block(unsigned char *block)
297{
298 if ((block[0] == 0x00) && (block[1] == 0x00) &&
299 (block[2] == 0x00) && (block[3] == 0xfd) &&
300 (block[4] == 0x00))
301 return 1;
302 else
303 return 0;
304}
305
306static int edid_is_monitor_block(unsigned char *block)
307{
308 if ((block[0] == 0x00) && (block[1] == 0x00) &&
309 (block[2] == 0x00) && (block[3] == 0xfc) &&
310 (block[4] == 0x00))
311 return 1;
312 else
313 return 0;
314}
315
316static void calc_mode_timings(int xres, int yres, int refresh, 382static void calc_mode_timings(int xres, int yres, int refresh,
317 struct fb_videomode *mode) 383 struct fb_videomode *mode)
318{ 384{
@@ -795,15 +861,6 @@ static void get_monspecs(unsigned char *edid, struct fb_monspecs *specs)
795 } 861 }
796} 862}
797 863
798static int edid_is_timing_block(unsigned char *block)
799{
800 if ((block[0] != 0x00) || (block[1] != 0x00) ||
801 (block[2] != 0x00) || (block[4] != 0x00))
802 return 1;
803 else
804 return 0;
805}
806
807int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var) 864int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
808{ 865{
809 int i; 866 int i;
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index 40c80c8190e2..d4a2c11d9809 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -376,7 +376,7 @@ static ssize_t show_pan(struct device *device,
376{ 376{
377 struct fb_info *fb_info = dev_get_drvdata(device); 377 struct fb_info *fb_info = dev_get_drvdata(device);
378 return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xoffset, 378 return snprintf(buf, PAGE_SIZE, "%d,%d\n", fb_info->var.xoffset,
379 fb_info->var.xoffset); 379 fb_info->var.yoffset);
380} 380}
381 381
382static ssize_t show_name(struct device *device, 382static ssize_t show_name(struct device *device,
diff --git a/drivers/video/hecubafb.c b/drivers/video/hecubafb.c
new file mode 100644
index 000000000000..abfcb50364c8
--- /dev/null
+++ b/drivers/video/hecubafb.c
@@ -0,0 +1,471 @@
1/*
2 * linux/drivers/video/hecubafb.c -- FB driver for Hecuba controller
3 *
4 * Copyright (C) 2006, Jaya Kumar
5 * This work was sponsored by CIS(M) Sdn Bhd
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
10 *
11 * Layout is based on skeletonfb.c by James Simmons and Geert Uytterhoeven.
12 * This work was possible because of apollo display code from E-Ink's website
13 * http://support.eink.com/community
14 * All information used to write this code is from public material made
15 * available by E-Ink on its support site. Some commands such as 0xA4
16 * were found by looping through cmd=0x00 thru 0xFF and supplying random
17 * values. There are other commands that the display is capable of,
18 * beyond the 5 used here but they are more complex.
19 *
20 * This driver is written to be used with the Hecuba display controller
21 * board, and tested with the EInk 800x600 display in 1 bit mode.
22 * The interface between Hecuba and the host is TTL based GPIO. The
23 * GPIO requirements are 8 writable data lines and 6 lines for control.
24 * Only 4 of the controls are actually used here but 6 for future use.
25 * The driver requires the IO addresses for data and control GPIO at
26 * load time. It is also possible to use this display with a standard
27 * PC parallel port.
28 *
29 * General notes:
30 * - User must set hecubafb_enable=1 to enable it
31 * - User must set dio_addr=0xIOADDR cio_addr=0xIOADDR c2io_addr=0xIOADDR
32 *
33 */
34
35#include <linux/module.h>
36#include <linux/kernel.h>
37#include <linux/errno.h>
38#include <linux/string.h>
39#include <linux/mm.h>
40#include <linux/slab.h>
41#include <linux/vmalloc.h>
42#include <linux/delay.h>
43#include <linux/interrupt.h>
44#include <linux/fb.h>
45#include <linux/init.h>
46#include <linux/platform_device.h>
47#include <linux/list.h>
48#include <asm/uaccess.h>
49
50/* Apollo controller specific defines */
51#define APOLLO_START_NEW_IMG 0xA0
52#define APOLLO_STOP_IMG_DATA 0xA1
53#define APOLLO_DISPLAY_IMG 0xA2
54#define APOLLO_ERASE_DISPLAY 0xA3
55#define APOLLO_INIT_DISPLAY 0xA4
56
57/* Hecuba interface specific defines */
58/* WUP is inverted, CD is inverted, DS is inverted */
59#define HCB_NWUP_BIT 0x01
60#define HCB_NDS_BIT 0x02
61#define HCB_RW_BIT 0x04
62#define HCB_NCD_BIT 0x08
63#define HCB_ACK_BIT 0x80
64
65/* Display specific information */
66#define DPY_W 600
67#define DPY_H 800
68
69struct hecubafb_par {
70 unsigned long dio_addr;
71 unsigned long cio_addr;
72 unsigned long c2io_addr;
73 unsigned char ctl;
74 struct fb_info *info;
75 unsigned int irq;
76};
77
78static struct fb_fix_screeninfo hecubafb_fix __devinitdata = {
79 .id = "hecubafb",
80 .type = FB_TYPE_PACKED_PIXELS,
81 .visual = FB_VISUAL_MONO01,
82 .xpanstep = 0,
83 .ypanstep = 0,
84 .ywrapstep = 0,
85 .accel = FB_ACCEL_NONE,
86};
87
88static struct fb_var_screeninfo hecubafb_var __devinitdata = {
89 .xres = DPY_W,
90 .yres = DPY_H,
91 .xres_virtual = DPY_W,
92 .yres_virtual = DPY_H,
93 .bits_per_pixel = 1,
94 .nonstd = 1,
95};
96
97static unsigned long dio_addr;
98static unsigned long cio_addr;
99static unsigned long c2io_addr;
100static unsigned long splashval;
101static unsigned int nosplash;
102static unsigned int hecubafb_enable;
103static unsigned int irq;
104
105static DECLARE_WAIT_QUEUE_HEAD(hecubafb_waitq);
106
107static void hcb_set_ctl(struct hecubafb_par *par)
108{
109 outb(par->ctl, par->cio_addr);
110}
111
112static unsigned char hcb_get_ctl(struct hecubafb_par *par)
113{
114 return inb(par->c2io_addr);
115}
116
117static void hcb_set_data(struct hecubafb_par *par, unsigned char value)
118{
119 outb(value, par->dio_addr);
120}
121
122static int __devinit apollo_init_control(struct hecubafb_par *par)
123{
124 unsigned char ctl;
125 /* for init, we want the following setup to be set:
126 WUP = lo
127 ACK = hi
128 DS = hi
129 RW = hi
130 CD = lo
131 */
132
133 /* write WUP to lo, DS to hi, RW to hi, CD to lo */
134 par->ctl = HCB_NWUP_BIT | HCB_RW_BIT | HCB_NCD_BIT ;
135 par->ctl &= ~HCB_NDS_BIT;
136 hcb_set_ctl(par);
137
138 /* check ACK is not lo */
139 ctl = hcb_get_ctl(par);
140 if ((ctl & HCB_ACK_BIT)) {
141 printk(KERN_ERR "Fail because ACK is already low\n");
142 return -ENXIO;
143 }
144
145 return 0;
146}
147
148static void hcb_wait_for_ack(struct hecubafb_par *par)
149{
150
151 int timeout;
152 unsigned char ctl;
153
154 timeout=500;
155 do {
156 ctl = hcb_get_ctl(par);
157 if ((ctl & HCB_ACK_BIT))
158 return;
159 udelay(1);
160 } while (timeout--);
161 printk(KERN_ERR "timed out waiting for ack\n");
162}
163
164static void hcb_wait_for_ack_clear(struct hecubafb_par *par)
165{
166
167 int timeout;
168 unsigned char ctl;
169
170 timeout=500;
171 do {
172 ctl = hcb_get_ctl(par);
173 if (!(ctl & HCB_ACK_BIT))
174 return;
175 udelay(1);
176 } while (timeout--);
177 printk(KERN_ERR "timed out waiting for clear\n");
178}
179
180static void apollo_send_data(struct hecubafb_par *par, unsigned char data)
181{
182 /* set data */
183 hcb_set_data(par, data);
184
185 /* set DS low */
186 par->ctl |= HCB_NDS_BIT;
187 hcb_set_ctl(par);
188
189 hcb_wait_for_ack(par);
190
191 /* set DS hi */
192 par->ctl &= ~(HCB_NDS_BIT);
193 hcb_set_ctl(par);
194
195 hcb_wait_for_ack_clear(par);
196}
197
198static void apollo_send_command(struct hecubafb_par *par, unsigned char data)
199{
200 /* command so set CD to high */
201 par->ctl &= ~(HCB_NCD_BIT);
202 hcb_set_ctl(par);
203
204 /* actually strobe with command */
205 apollo_send_data(par, data);
206
207 /* clear CD back to low */
208 par->ctl |= (HCB_NCD_BIT);
209 hcb_set_ctl(par);
210}
211
212/* main hecubafb functions */
213
214static void hecubafb_dpy_update(struct hecubafb_par *par)
215{
216 int i;
217 unsigned char *buf = (unsigned char __force *)par->info->screen_base;
218
219 apollo_send_command(par, 0xA0);
220
221 for (i=0; i < (DPY_W*DPY_H/8); i++) {
222 apollo_send_data(par, *(buf++));
223 }
224
225 apollo_send_command(par, 0xA1);
226 apollo_send_command(par, 0xA2);
227}
228
229/* this is called back from the deferred io workqueue */
230static void hecubafb_dpy_deferred_io(struct fb_info *info,
231 struct list_head *pagelist)
232{
233 hecubafb_dpy_update(info->par);
234}
235
236static void hecubafb_fillrect(struct fb_info *info,
237 const struct fb_fillrect *rect)
238{
239 struct hecubafb_par *par = info->par;
240
241 sys_fillrect(info, rect);
242
243 hecubafb_dpy_update(par);
244}
245
246static void hecubafb_copyarea(struct fb_info *info,
247 const struct fb_copyarea *area)
248{
249 struct hecubafb_par *par = info->par;
250
251 sys_copyarea(info, area);
252
253 hecubafb_dpy_update(par);
254}
255
256static void hecubafb_imageblit(struct fb_info *info,
257 const struct fb_image *image)
258{
259 struct hecubafb_par *par = info->par;
260
261 sys_imageblit(info, image);
262
263 hecubafb_dpy_update(par);
264}
265
266/*
267 * this is the slow path from userspace. they can seek and write to
268 * the fb. it's inefficient to do anything less than a full screen draw
269 */
270static ssize_t hecubafb_write(struct fb_info *info, const char __user *buf,
271 size_t count, loff_t *ppos)
272{
273 unsigned long p;
274 int err=-EINVAL;
275 struct hecubafb_par *par;
276 unsigned int xres;
277 unsigned int fbmemlength;
278
279 p = *ppos;
280 par = info->par;
281 xres = info->var.xres;
282 fbmemlength = (xres * info->var.yres)/8;
283
284 if (p > fbmemlength)
285 return -ENOSPC;
286
287 err = 0;
288 if ((count + p) > fbmemlength) {
289 count = fbmemlength - p;
290 err = -ENOSPC;
291 }
292
293 if (count) {
294 char *base_addr;
295
296 base_addr = (char __force *)info->screen_base;
297 count -= copy_from_user(base_addr + p, buf, count);
298 *ppos += count;
299 err = -EFAULT;
300 }
301
302 hecubafb_dpy_update(par);
303
304 if (count)
305 return count;
306
307 return err;
308}
309
310static struct fb_ops hecubafb_ops = {
311 .owner = THIS_MODULE,
312 .fb_read = fb_sys_read,
313 .fb_write = hecubafb_write,
314 .fb_fillrect = hecubafb_fillrect,
315 .fb_copyarea = hecubafb_copyarea,
316 .fb_imageblit = hecubafb_imageblit,
317};
318
319static struct fb_deferred_io hecubafb_defio = {
320 .delay = HZ,
321 .deferred_io = hecubafb_dpy_deferred_io,
322};
323
324static int __devinit hecubafb_probe(struct platform_device *dev)
325{
326 struct fb_info *info;
327 int retval = -ENOMEM;
328 int videomemorysize;
329 unsigned char *videomemory;
330 struct hecubafb_par *par;
331
332 videomemorysize = (DPY_W*DPY_H)/8;
333
334 if (!(videomemory = vmalloc(videomemorysize)))
335 return retval;
336
337 memset(videomemory, 0, videomemorysize);
338
339 info = framebuffer_alloc(sizeof(struct hecubafb_par), &dev->dev);
340 if (!info)
341 goto err;
342
343 info->screen_base = (char __iomem *) videomemory;
344 info->fbops = &hecubafb_ops;
345
346 info->var = hecubafb_var;
347 info->fix = hecubafb_fix;
348 info->fix.smem_len = videomemorysize;
349 par = info->par;
350 par->info = info;
351
352 if (!dio_addr || !cio_addr || !c2io_addr) {
353 printk(KERN_WARNING "no IO addresses supplied\n");
354 goto err1;
355 }
356 par->dio_addr = dio_addr;
357 par->cio_addr = cio_addr;
358 par->c2io_addr = c2io_addr;
359 info->flags = FBINFO_FLAG_DEFAULT;
360
361 info->fbdefio = &hecubafb_defio;
362 fb_deferred_io_init(info);
363
364 retval = register_framebuffer(info);
365 if (retval < 0)
366 goto err1;
367 platform_set_drvdata(dev, info);
368
369 printk(KERN_INFO
370 "fb%d: Hecuba frame buffer device, using %dK of video memory\n",
371 info->node, videomemorysize >> 10);
372
373 /* this inits the dpy */
374 apollo_init_control(par);
375
376 apollo_send_command(par, APOLLO_INIT_DISPLAY);
377 apollo_send_data(par, 0x81);
378
379 /* have to wait while display resets */
380 udelay(1000);
381
382 /* if we were told to splash the screen, we just clear it */
383 if (!nosplash) {
384 apollo_send_command(par, APOLLO_ERASE_DISPLAY);
385 apollo_send_data(par, splashval);
386 }
387
388 return 0;
389err1:
390 framebuffer_release(info);
391err:
392 vfree(videomemory);
393 return retval;
394}
395
396static int __devexit hecubafb_remove(struct platform_device *dev)
397{
398 struct fb_info *info = platform_get_drvdata(dev);
399
400 if (info) {
401 fb_deferred_io_cleanup(info);
402 unregister_framebuffer(info);
403 vfree((void __force *)info->screen_base);
404 framebuffer_release(info);
405 }
406 return 0;
407}
408
409static struct platform_driver hecubafb_driver = {
410 .probe = hecubafb_probe,
411 .remove = hecubafb_remove,
412 .driver = {
413 .name = "hecubafb",
414 },
415};
416
417static struct platform_device *hecubafb_device;
418
419static int __init hecubafb_init(void)
420{
421 int ret;
422
423 if (!hecubafb_enable) {
424 printk(KERN_ERR "Use hecubafb_enable to enable the device\n");
425 return -ENXIO;
426 }
427
428 ret = platform_driver_register(&hecubafb_driver);
429 if (!ret) {
430 hecubafb_device = platform_device_alloc("hecubafb", 0);
431 if (hecubafb_device)
432 ret = platform_device_add(hecubafb_device);
433 else
434 ret = -ENOMEM;
435
436 if (ret) {
437 platform_device_put(hecubafb_device);
438 platform_driver_unregister(&hecubafb_driver);
439 }
440 }
441 return ret;
442
443}
444
445static void __exit hecubafb_exit(void)
446{
447 platform_device_unregister(hecubafb_device);
448 platform_driver_unregister(&hecubafb_driver);
449}
450
451module_param(nosplash, uint, 0);
452MODULE_PARM_DESC(nosplash, "Disable doing the splash screen");
453module_param(hecubafb_enable, uint, 0);
454MODULE_PARM_DESC(hecubafb_enable, "Enable communication with Hecuba board");
455module_param(dio_addr, ulong, 0);
456MODULE_PARM_DESC(dio_addr, "IO address for data, eg: 0x480");
457module_param(cio_addr, ulong, 0);
458MODULE_PARM_DESC(cio_addr, "IO address for control, eg: 0x400");
459module_param(c2io_addr, ulong, 0);
460MODULE_PARM_DESC(c2io_addr, "IO address for secondary control, eg: 0x408");
461module_param(splashval, ulong, 0);
462MODULE_PARM_DESC(splashval, "Splash pattern: 0x00 is black, 0x01 is white");
463module_param(irq, uint, 0);
464MODULE_PARM_DESC(irq, "IRQ for the Hecuba board");
465
466module_init(hecubafb_init);
467module_exit(hecubafb_exit);
468
469MODULE_DESCRIPTION("fbdev driver for Hecuba board");
470MODULE_AUTHOR("Jaya Kumar");
471MODULE_LICENSE("GPL");
diff --git a/drivers/video/i810/i810.h b/drivers/video/i810/i810.h
index aa65ffce915b..889e4ea5edc1 100644
--- a/drivers/video/i810/i810.h
+++ b/drivers/video/i810/i810.h
@@ -133,7 +133,7 @@
133/* Masks (AND ops) and OR's */ 133/* Masks (AND ops) and OR's */
134#define FB_START_MASK (0x3f << (32 - 6)) 134#define FB_START_MASK (0x3f << (32 - 6))
135#define MMIO_ADDR_MASK (0x1FFF << (32 - 13)) 135#define MMIO_ADDR_MASK (0x1FFF << (32 - 13))
136#define FREQ_MASK 0x1EF 136#define FREQ_MASK (1 << 4)
137#define SCR_OFF 0x20 137#define SCR_OFF 0x20
138#define DRAM_ON 0x08 138#define DRAM_ON 0x08
139#define DRAM_OFF 0xE7 139#define DRAM_OFF 0xE7
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index 7e760197cf29..1a7d7789d877 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -1717,7 +1717,7 @@ static int __devinit i810_alloc_agp_mem(struct fb_info *info)
1717 * @info: pointer to device specific info structure 1717 * @info: pointer to device specific info structure
1718 * 1718 *
1719 * DESCRIPTION: 1719 * DESCRIPTION:
1720 * Sets the the user monitor's horizontal and vertical 1720 * Sets the user monitor's horizontal and vertical
1721 * frequency limits 1721 * frequency limits
1722 */ 1722 */
1723static void __devinit i810_init_monspecs(struct fb_info *info) 1723static void __devinit i810_init_monspecs(struct fb_info *info)
diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c
index c1eb18bf0883..16bc8d75e36e 100644
--- a/drivers/video/intelfb/intelfbhw.c
+++ b/drivers/video/intelfb/intelfbhw.c
@@ -1428,6 +1428,24 @@ static void refresh_ring(struct intelfb_info *dinfo);
1428static void reset_state(struct intelfb_info *dinfo); 1428static void reset_state(struct intelfb_info *dinfo);
1429static void do_flush(struct intelfb_info *dinfo); 1429static void do_flush(struct intelfb_info *dinfo);
1430 1430
1431static u32 get_ring_space(struct intelfb_info *dinfo)
1432{
1433 u32 ring_space;
1434
1435 if (dinfo->ring_tail >= dinfo->ring_head)
1436 ring_space = dinfo->ring.size -
1437 (dinfo->ring_tail - dinfo->ring_head);
1438 else
1439 ring_space = dinfo->ring_head - dinfo->ring_tail;
1440
1441 if (ring_space > RING_MIN_FREE)
1442 ring_space -= RING_MIN_FREE;
1443 else
1444 ring_space = 0;
1445
1446 return ring_space;
1447}
1448
1431static int 1449static int
1432wait_ring(struct intelfb_info *dinfo, int n) 1450wait_ring(struct intelfb_info *dinfo, int n)
1433{ 1451{
@@ -1442,13 +1460,8 @@ wait_ring(struct intelfb_info *dinfo, int n)
1442 end = jiffies + (HZ * 3); 1460 end = jiffies + (HZ * 3);
1443 while (dinfo->ring_space < n) { 1461 while (dinfo->ring_space < n) {
1444 dinfo->ring_head = INREG(PRI_RING_HEAD) & RING_HEAD_MASK; 1462 dinfo->ring_head = INREG(PRI_RING_HEAD) & RING_HEAD_MASK;
1445 if (dinfo->ring_tail + RING_MIN_FREE < dinfo->ring_head) 1463 dinfo->ring_space = get_ring_space(dinfo);
1446 dinfo->ring_space = dinfo->ring_head 1464
1447 - (dinfo->ring_tail + RING_MIN_FREE);
1448 else
1449 dinfo->ring_space = (dinfo->ring.size +
1450 dinfo->ring_head)
1451 - (dinfo->ring_tail + RING_MIN_FREE);
1452 if (dinfo->ring_head != last_head) { 1465 if (dinfo->ring_head != last_head) {
1453 end = jiffies + (HZ * 3); 1466 end = jiffies + (HZ * 3);
1454 last_head = dinfo->ring_head; 1467 last_head = dinfo->ring_head;
@@ -1513,12 +1526,7 @@ refresh_ring(struct intelfb_info *dinfo)
1513 1526
1514 dinfo->ring_head = INREG(PRI_RING_HEAD) & RING_HEAD_MASK; 1527 dinfo->ring_head = INREG(PRI_RING_HEAD) & RING_HEAD_MASK;
1515 dinfo->ring_tail = INREG(PRI_RING_TAIL) & RING_TAIL_MASK; 1528 dinfo->ring_tail = INREG(PRI_RING_TAIL) & RING_TAIL_MASK;
1516 if (dinfo->ring_tail + RING_MIN_FREE < dinfo->ring_head) 1529 dinfo->ring_space = get_ring_space(dinfo);
1517 dinfo->ring_space = dinfo->ring_head
1518 - (dinfo->ring_tail + RING_MIN_FREE);
1519 else
1520 dinfo->ring_space = (dinfo->ring.size + dinfo->ring_head)
1521 - (dinfo->ring_tail + RING_MIN_FREE);
1522} 1530}
1523 1531
1524static void 1532static void
diff --git a/drivers/video/logo/Kconfig b/drivers/video/logo/Kconfig
index f0e6512c87ff..9397bcef3018 100644
--- a/drivers/video/logo/Kconfig
+++ b/drivers/video/logo/Kconfig
@@ -2,73 +2,69 @@
2# Logo configuration 2# Logo configuration
3# 3#
4 4
5menu "Logo configuration" 5menuconfig LOGO
6
7config LOGO
8 bool "Bootup logo" 6 bool "Bootup logo"
9 depends on FB || SGI_NEWPORT_CONSOLE 7 depends on FB || SGI_NEWPORT_CONSOLE
10 help 8 help
11 Enable and select frame buffer bootup logos. 9 Enable and select frame buffer bootup logos.
12 10
11if LOGO
12
13config LOGO_LINUX_MONO 13config LOGO_LINUX_MONO
14 bool "Standard black and white Linux logo" 14 bool "Standard black and white Linux logo"
15 depends on LOGO
16 default y 15 default y
17 16
18config LOGO_LINUX_VGA16 17config LOGO_LINUX_VGA16
19 bool "Standard 16-color Linux logo" 18 bool "Standard 16-color Linux logo"
20 depends on LOGO
21 default y 19 default y
22 20
23config LOGO_LINUX_CLUT224 21config LOGO_LINUX_CLUT224
24 bool "Standard 224-color Linux logo" 22 bool "Standard 224-color Linux logo"
25 depends on LOGO
26 default y 23 default y
27 24
28config LOGO_DEC_CLUT224 25config LOGO_DEC_CLUT224
29 bool "224-color Digital Equipment Corporation Linux logo" 26 bool "224-color Digital Equipment Corporation Linux logo"
30 depends on LOGO && (MACH_DECSTATION || ALPHA) 27 depends on MACH_DECSTATION || ALPHA
31 default y 28 default y
32 29
33config LOGO_MAC_CLUT224 30config LOGO_MAC_CLUT224
34 bool "224-color Macintosh Linux logo" 31 bool "224-color Macintosh Linux logo"
35 depends on LOGO && MAC 32 depends on MAC
36 default y 33 default y
37 34
38config LOGO_PARISC_CLUT224 35config LOGO_PARISC_CLUT224
39 bool "224-color PA-RISC Linux logo" 36 bool "224-color PA-RISC Linux logo"
40 depends on LOGO && PARISC 37 depends on PARISC
41 default y 38 default y
42 39
43config LOGO_SGI_CLUT224 40config LOGO_SGI_CLUT224
44 bool "224-color SGI Linux logo" 41 bool "224-color SGI Linux logo"
45 depends on LOGO && (SGI_IP22 || SGI_IP27 || SGI_IP32 || X86_VISWS) 42 depends on SGI_IP22 || SGI_IP27 || SGI_IP32 || X86_VISWS
46 default y 43 default y
47 44
48config LOGO_SUN_CLUT224 45config LOGO_SUN_CLUT224
49 bool "224-color Sun Linux logo" 46 bool "224-color Sun Linux logo"
50 depends on LOGO && SPARC 47 depends on SPARC
51 default y 48 default y
52 49
53config LOGO_SUPERH_MONO 50config LOGO_SUPERH_MONO
54 bool "Black and white SuperH Linux logo" 51 bool "Black and white SuperH Linux logo"
55 depends on LOGO && SUPERH 52 depends on SUPERH
56 default y 53 default y
57 54
58config LOGO_SUPERH_VGA16 55config LOGO_SUPERH_VGA16
59 bool "16-color SuperH Linux logo" 56 bool "16-color SuperH Linux logo"
60 depends on LOGO && SUPERH 57 depends on SUPERH
61 default y 58 default y
62 59
63config LOGO_SUPERH_CLUT224 60config LOGO_SUPERH_CLUT224
64 bool "224-color SuperH Linux logo" 61 bool "224-color SuperH Linux logo"
65 depends on LOGO && SUPERH 62 depends on SUPERH
66 default y 63 default y
67 64
68config LOGO_M32R_CLUT224 65config LOGO_M32R_CLUT224
69 bool "224-color M32R Linux logo" 66 bool "224-color M32R Linux logo"
70 depends on LOGO && M32R 67 depends on M32R
71 default y 68 default y
72 69
73endmenu 70endif # LOGO
74
diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
index a5690a5f29d5..9445cdb759b1 100644
--- a/drivers/video/matrox/matroxfb_Ti3026.c
+++ b/drivers/video/matrox/matroxfb_Ti3026.c
@@ -72,7 +72,7 @@
72 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> 72 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
73 * 73 *
74 * (following author is not in any relation with this code, but his ideas 74 * (following author is not in any relation with this code, but his ideas
75 * were used when writting this driver) 75 * were used when writing this driver)
76 * 76 *
77 * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk> 77 * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk>
78 * 78 *
diff --git a/drivers/video/matrox/matroxfb_accel.c b/drivers/video/matrox/matroxfb_accel.c
index a5c825d99466..c57aaadf410c 100644
--- a/drivers/video/matrox/matroxfb_accel.c
+++ b/drivers/video/matrox/matroxfb_accel.c
@@ -70,7 +70,7 @@
70 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> 70 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
71 * 71 *
72 * (following author is not in any relation with this code, but his ideas 72 * (following author is not in any relation with this code, but his ideas
73 * were used when writting this driver) 73 * were used when writing this driver)
74 * 74 *
75 * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk> 75 * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk>
76 * 76 *
diff --git a/drivers/video/matrox/matroxfb_base.c b/drivers/video/matrox/matroxfb_base.c
index cb2aa402ddfd..c8559a756b75 100644
--- a/drivers/video/matrox/matroxfb_base.c
+++ b/drivers/video/matrox/matroxfb_base.c
@@ -93,7 +93,7 @@
93 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> 93 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
94 * 94 *
95 * (following author is not in any relation with this code, but his ideas 95 * (following author is not in any relation with this code, but his ideas
96 * were used when writting this driver) 96 * were used when writing this driver)
97 * 97 *
98 * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk> 98 * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk>
99 * 99 *
diff --git a/drivers/video/matrox/matroxfb_misc.c b/drivers/video/matrox/matroxfb_misc.c
index 18886b629cb1..5948e54b9ef9 100644
--- a/drivers/video/matrox/matroxfb_misc.c
+++ b/drivers/video/matrox/matroxfb_misc.c
@@ -78,7 +78,7 @@
78 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de> 78 * (c) 1998 Gerd Knorr <kraxel@cs.tu-berlin.de>
79 * 79 *
80 * (following author is not in any relation with this code, but his ideas 80 * (following author is not in any relation with this code, but his ideas
81 * were used when writting this driver) 81 * were used when writing this driver)
82 * 82 *
83 * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk> 83 * FreeVBE/AF (Matrox), "Shawn Hargreaves" <shawn@talula.demon.co.uk>
84 * 84 *
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 3e517940c5a5..3741ad729401 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -395,7 +395,7 @@ static int my_atoi(const char *name)
395 395
396 for (;; name++) { 396 for (;; name++) {
397 switch (*name) { 397 switch (*name) {
398 case '0'...'9': 398 case '0' ... '9':
399 val = 10*val+(*name-'0'); 399 val = 10*val+(*name-'0');
400 break; 400 break;
401 default: 401 default:
@@ -548,7 +548,7 @@ int fb_find_mode(struct fb_var_screeninfo *var,
548 } else 548 } else
549 goto done; 549 goto done;
550 break; 550 break;
551 case '0'...'9': 551 case '0' ... '9':
552 break; 552 break;
553 case 'M': 553 case 'M':
554 if (!yres_specified) 554 if (!yres_specified)
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index 395ccedde9a6..bd30aba242d0 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -665,6 +665,7 @@ neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
665 var->red.msb_right = 0; 665 var->red.msb_right = 0;
666 var->green.msb_right = 0; 666 var->green.msb_right = 0;
667 var->blue.msb_right = 0; 667 var->blue.msb_right = 0;
668 var->transp.msb_right = 0;
668 669
669 switch (var->bits_per_pixel) { 670 switch (var->bits_per_pixel) {
670 case 8: /* PSEUDOCOLOUR, 256 */ 671 case 8: /* PSEUDOCOLOUR, 256 */
diff --git a/drivers/video/nvidia/nv_accel.c b/drivers/video/nvidia/nv_accel.c
index 9efb8a3854e2..fa4821c5572b 100644
--- a/drivers/video/nvidia/nv_accel.c
+++ b/drivers/video/nvidia/nv_accel.c
@@ -69,27 +69,38 @@ static const int NVCopyROP_PM[16] = {
69 0x5A, /* invert */ 69 0x5A, /* invert */
70}; 70};
71 71
72static inline void NVFlush(struct nvidia_par *par) 72static inline void nvidiafb_safe_mode(struct fb_info *info)
73{ 73{
74 struct nvidia_par *par = info->par;
75
76 touch_softlockup_watchdog();
77 info->pixmap.scan_align = 1;
78 par->lockup = 1;
79}
80
81static inline void NVFlush(struct fb_info *info)
82{
83 struct nvidia_par *par = info->par;
74 int count = 1000000000; 84 int count = 1000000000;
75 85
76 while (--count && READ_GET(par) != par->dmaPut) ; 86 while (--count && READ_GET(par) != par->dmaPut) ;
77 87
78 if (!count) { 88 if (!count) {
79 printk("nvidiafb: DMA Flush lockup\n"); 89 printk("nvidiafb: DMA Flush lockup\n");
80 par->lockup = 1; 90 nvidiafb_safe_mode(info);
81 } 91 }
82} 92}
83 93
84static inline void NVSync(struct nvidia_par *par) 94static inline void NVSync(struct fb_info *info)
85{ 95{
96 struct nvidia_par *par = info->par;
86 int count = 1000000000; 97 int count = 1000000000;
87 98
88 while (--count && NV_RD32(par->PGRAPH, 0x0700)) ; 99 while (--count && NV_RD32(par->PGRAPH, 0x0700)) ;
89 100
90 if (!count) { 101 if (!count) {
91 printk("nvidiafb: DMA Sync lockup\n"); 102 printk("nvidiafb: DMA Sync lockup\n");
92 par->lockup = 1; 103 nvidiafb_safe_mode(info);
93 } 104 }
94} 105}
95 106
@@ -101,8 +112,9 @@ static void NVDmaKickoff(struct nvidia_par *par)
101 } 112 }
102} 113}
103 114
104static void NVDmaWait(struct nvidia_par *par, int size) 115static void NVDmaWait(struct fb_info *info, int size)
105{ 116{
117 struct nvidia_par *par = info->par;
106 int dmaGet; 118 int dmaGet;
107 int count = 1000000000, cnt; 119 int count = 1000000000, cnt;
108 size++; 120 size++;
@@ -135,34 +147,38 @@ static void NVDmaWait(struct nvidia_par *par, int size)
135 } 147 }
136 148
137 if (!count) { 149 if (!count) {
138 printk("DMA Wait Lockup\n"); 150 printk("nvidiafb: DMA Wait Lockup\n");
139 par->lockup = 1; 151 nvidiafb_safe_mode(info);
140 } 152 }
141} 153}
142 154
143static void NVSetPattern(struct nvidia_par *par, u32 clr0, u32 clr1, 155static void NVSetPattern(struct fb_info *info, u32 clr0, u32 clr1,
144 u32 pat0, u32 pat1) 156 u32 pat0, u32 pat1)
145{ 157{
146 NVDmaStart(par, PATTERN_COLOR_0, 4); 158 struct nvidia_par *par = info->par;
159
160 NVDmaStart(info, par, PATTERN_COLOR_0, 4);
147 NVDmaNext(par, clr0); 161 NVDmaNext(par, clr0);
148 NVDmaNext(par, clr1); 162 NVDmaNext(par, clr1);
149 NVDmaNext(par, pat0); 163 NVDmaNext(par, pat0);
150 NVDmaNext(par, pat1); 164 NVDmaNext(par, pat1);
151} 165}
152 166
153static void NVSetRopSolid(struct nvidia_par *par, u32 rop, u32 planemask) 167static void NVSetRopSolid(struct fb_info *info, u32 rop, u32 planemask)
154{ 168{
169 struct nvidia_par *par = info->par;
170
155 if (planemask != ~0) { 171 if (planemask != ~0) {
156 NVSetPattern(par, 0, planemask, ~0, ~0); 172 NVSetPattern(info, 0, planemask, ~0, ~0);
157 if (par->currentRop != (rop + 32)) { 173 if (par->currentRop != (rop + 32)) {
158 NVDmaStart(par, ROP_SET, 1); 174 NVDmaStart(info, par, ROP_SET, 1);
159 NVDmaNext(par, NVCopyROP_PM[rop]); 175 NVDmaNext(par, NVCopyROP_PM[rop]);
160 par->currentRop = rop + 32; 176 par->currentRop = rop + 32;
161 } 177 }
162 } else if (par->currentRop != rop) { 178 } else if (par->currentRop != rop) {
163 if (par->currentRop >= 16) 179 if (par->currentRop >= 16)
164 NVSetPattern(par, ~0, ~0, ~0, ~0); 180 NVSetPattern(info, ~0, ~0, ~0, ~0);
165 NVDmaStart(par, ROP_SET, 1); 181 NVDmaStart(info, par, ROP_SET, 1);
166 NVDmaNext(par, NVCopyROP[rop]); 182 NVDmaNext(par, NVCopyROP[rop]);
167 par->currentRop = rop; 183 par->currentRop = rop;
168 } 184 }
@@ -175,7 +191,7 @@ static void NVSetClippingRectangle(struct fb_info *info, int x1, int y1,
175 int h = y2 - y1 + 1; 191 int h = y2 - y1 + 1;
176 int w = x2 - x1 + 1; 192 int w = x2 - x1 + 1;
177 193
178 NVDmaStart(par, CLIP_POINT, 2); 194 NVDmaStart(info, par, CLIP_POINT, 2);
179 NVDmaNext(par, (y1 << 16) | x1); 195 NVDmaNext(par, (y1 << 16) | x1);
180 NVDmaNext(par, (h << 16) | w); 196 NVDmaNext(par, (h << 16) | w);
181} 197}
@@ -237,23 +253,23 @@ void NVResetGraphics(struct fb_info *info)
237 break; 253 break;
238 } 254 }
239 255
240 NVDmaStart(par, SURFACE_FORMAT, 4); 256 NVDmaStart(info, par, SURFACE_FORMAT, 4);
241 NVDmaNext(par, surfaceFormat); 257 NVDmaNext(par, surfaceFormat);
242 NVDmaNext(par, pitch | (pitch << 16)); 258 NVDmaNext(par, pitch | (pitch << 16));
243 NVDmaNext(par, 0); 259 NVDmaNext(par, 0);
244 NVDmaNext(par, 0); 260 NVDmaNext(par, 0);
245 261
246 NVDmaStart(par, PATTERN_FORMAT, 1); 262 NVDmaStart(info, par, PATTERN_FORMAT, 1);
247 NVDmaNext(par, patternFormat); 263 NVDmaNext(par, patternFormat);
248 264
249 NVDmaStart(par, RECT_FORMAT, 1); 265 NVDmaStart(info, par, RECT_FORMAT, 1);
250 NVDmaNext(par, rectFormat); 266 NVDmaNext(par, rectFormat);
251 267
252 NVDmaStart(par, LINE_FORMAT, 1); 268 NVDmaStart(info, par, LINE_FORMAT, 1);
253 NVDmaNext(par, lineFormat); 269 NVDmaNext(par, lineFormat);
254 270
255 par->currentRop = ~0; /* set to something invalid */ 271 par->currentRop = ~0; /* set to something invalid */
256 NVSetRopSolid(par, ROP_COPY, ~0); 272 NVSetRopSolid(info, ROP_COPY, ~0);
257 273
258 NVSetClippingRectangle(info, 0, 0, info->var.xres_virtual, 274 NVSetClippingRectangle(info, 0, 0, info->var.xres_virtual,
259 info->var.yres_virtual); 275 info->var.yres_virtual);
@@ -269,10 +285,10 @@ int nvidiafb_sync(struct fb_info *info)
269 return 0; 285 return 0;
270 286
271 if (!par->lockup) 287 if (!par->lockup)
272 NVFlush(par); 288 NVFlush(info);
273 289
274 if (!par->lockup) 290 if (!par->lockup)
275 NVSync(par); 291 NVSync(info);
276 292
277 return 0; 293 return 0;
278} 294}
@@ -287,7 +303,7 @@ void nvidiafb_copyarea(struct fb_info *info, const struct fb_copyarea *region)
287 if (par->lockup) 303 if (par->lockup)
288 return cfb_copyarea(info, region); 304 return cfb_copyarea(info, region);
289 305
290 NVDmaStart(par, BLIT_POINT_SRC, 3); 306 NVDmaStart(info, par, BLIT_POINT_SRC, 3);
291 NVDmaNext(par, (region->sy << 16) | region->sx); 307 NVDmaNext(par, (region->sy << 16) | region->sx);
292 NVDmaNext(par, (region->dy << 16) | region->dx); 308 NVDmaNext(par, (region->dy << 16) | region->dx);
293 NVDmaNext(par, (region->height << 16) | region->width); 309 NVDmaNext(par, (region->height << 16) | region->width);
@@ -312,19 +328,19 @@ void nvidiafb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
312 color = ((u32 *) info->pseudo_palette)[rect->color]; 328 color = ((u32 *) info->pseudo_palette)[rect->color];
313 329
314 if (rect->rop != ROP_COPY) 330 if (rect->rop != ROP_COPY)
315 NVSetRopSolid(par, rect->rop, ~0); 331 NVSetRopSolid(info, rect->rop, ~0);
316 332
317 NVDmaStart(par, RECT_SOLID_COLOR, 1); 333 NVDmaStart(info, par, RECT_SOLID_COLOR, 1);
318 NVDmaNext(par, color); 334 NVDmaNext(par, color);
319 335
320 NVDmaStart(par, RECT_SOLID_RECTS(0), 2); 336 NVDmaStart(info, par, RECT_SOLID_RECTS(0), 2);
321 NVDmaNext(par, (rect->dx << 16) | rect->dy); 337 NVDmaNext(par, (rect->dx << 16) | rect->dy);
322 NVDmaNext(par, (rect->width << 16) | rect->height); 338 NVDmaNext(par, (rect->width << 16) | rect->height);
323 339
324 NVDmaKickoff(par); 340 NVDmaKickoff(par);
325 341
326 if (rect->rop != ROP_COPY) 342 if (rect->rop != ROP_COPY)
327 NVSetRopSolid(par, ROP_COPY, ~0); 343 NVSetRopSolid(info, ROP_COPY, ~0);
328} 344}
329 345
330static void nvidiafb_mono_color_expand(struct fb_info *info, 346static void nvidiafb_mono_color_expand(struct fb_info *info,
@@ -346,7 +362,7 @@ static void nvidiafb_mono_color_expand(struct fb_info *info,
346 bg = ((u32 *) info->pseudo_palette)[image->bg_color] | mask; 362 bg = ((u32 *) info->pseudo_palette)[image->bg_color] | mask;
347 } 363 }
348 364
349 NVDmaStart(par, RECT_EXPAND_TWO_COLOR_CLIP, 7); 365 NVDmaStart(info, par, RECT_EXPAND_TWO_COLOR_CLIP, 7);
350 NVDmaNext(par, (image->dy << 16) | (image->dx & 0xffff)); 366 NVDmaNext(par, (image->dy << 16) | (image->dx & 0xffff));
351 NVDmaNext(par, ((image->dy + image->height) << 16) | 367 NVDmaNext(par, ((image->dy + image->height) << 16) |
352 ((image->dx + image->width) & 0xffff)); 368 ((image->dx + image->width) & 0xffff));
@@ -357,7 +373,7 @@ static void nvidiafb_mono_color_expand(struct fb_info *info,
357 NVDmaNext(par, (image->dy << 16) | (image->dx & 0xffff)); 373 NVDmaNext(par, (image->dy << 16) | (image->dx & 0xffff));
358 374
359 while (dsize >= RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS) { 375 while (dsize >= RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS) {
360 NVDmaStart(par, RECT_EXPAND_TWO_COLOR_DATA(0), 376 NVDmaStart(info, par, RECT_EXPAND_TWO_COLOR_DATA(0),
361 RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS); 377 RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS);
362 378
363 for (j = RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS; j--;) { 379 for (j = RECT_EXPAND_TWO_COLOR_DATA_MAX_DWORDS; j--;) {
@@ -370,7 +386,7 @@ static void nvidiafb_mono_color_expand(struct fb_info *info,
370 } 386 }
371 387
372 if (dsize) { 388 if (dsize) {
373 NVDmaStart(par, RECT_EXPAND_TWO_COLOR_DATA(0), dsize); 389 NVDmaStart(info, par, RECT_EXPAND_TWO_COLOR_DATA(0), dsize);
374 390
375 for (j = dsize; j--;) { 391 for (j = dsize; j--;) {
376 tmp = data[k++]; 392 tmp = data[k++];
diff --git a/drivers/video/nvidia/nv_hw.c b/drivers/video/nvidia/nv_hw.c
index ea426115c6f9..aff11bbf59a7 100644
--- a/drivers/video/nvidia/nv_hw.c
+++ b/drivers/video/nvidia/nv_hw.c
@@ -150,7 +150,8 @@ static void nvGetClocks(struct nvidia_par *par, unsigned int *MClk,
150 M = pll & 0xFF; 150 M = pll & 0xFF;
151 N = (pll >> 8) & 0xFF; 151 N = (pll >> 8) & 0xFF;
152 if (((par->Chipset & 0xfff0) == 0x0290) || 152 if (((par->Chipset & 0xfff0) == 0x0290) ||
153 ((par->Chipset & 0xfff0) == 0x0390)) { 153 ((par->Chipset & 0xfff0) == 0x0390) ||
154 ((par->Chipset & 0xfff0) == 0x02E0)) {
154 MB = 1; 155 MB = 1;
155 NB = 1; 156 NB = 1;
156 } else { 157 } else {
@@ -686,7 +687,7 @@ static void nForceUpdateArbitrationSettings(unsigned VClk,
686 687
687 if ((par->Chipset & 0x0FF0) == 0x01A0) { 688 if ((par->Chipset & 0x0FF0) == 0x01A0) {
688 unsigned int uMClkPostDiv; 689 unsigned int uMClkPostDiv;
689 dev = pci_find_slot(0, 3); 690 dev = pci_get_bus_and_slot(0, 3);
690 pci_read_config_dword(dev, 0x6C, &uMClkPostDiv); 691 pci_read_config_dword(dev, 0x6C, &uMClkPostDiv);
691 uMClkPostDiv = (uMClkPostDiv >> 8) & 0xf; 692 uMClkPostDiv = (uMClkPostDiv >> 8) & 0xf;
692 693
@@ -694,11 +695,11 @@ static void nForceUpdateArbitrationSettings(unsigned VClk,
694 uMClkPostDiv = 4; 695 uMClkPostDiv = 4;
695 MClk = 400000 / uMClkPostDiv; 696 MClk = 400000 / uMClkPostDiv;
696 } else { 697 } else {
697 dev = pci_find_slot(0, 5); 698 dev = pci_get_bus_and_slot(0, 5);
698 pci_read_config_dword(dev, 0x4c, &MClk); 699 pci_read_config_dword(dev, 0x4c, &MClk);
699 MClk /= 1000; 700 MClk /= 1000;
700 } 701 }
701 702 pci_dev_put(dev);
702 pll = NV_RD32(par->PRAMDAC0, 0x0500); 703 pll = NV_RD32(par->PRAMDAC0, 0x0500);
703 M = (pll >> 0) & 0xFF; 704 M = (pll >> 0) & 0xFF;
704 N = (pll >> 8) & 0xFF; 705 N = (pll >> 8) & 0xFF;
@@ -707,19 +708,21 @@ static void nForceUpdateArbitrationSettings(unsigned VClk,
707 sim_data.pix_bpp = (char)pixelDepth; 708 sim_data.pix_bpp = (char)pixelDepth;
708 sim_data.enable_video = 0; 709 sim_data.enable_video = 0;
709 sim_data.enable_mp = 0; 710 sim_data.enable_mp = 0;
710 pci_find_slot(0, 1); 711 dev = pci_get_bus_and_slot(0, 1);
711 pci_read_config_dword(dev, 0x7C, &sim_data.memory_type); 712 pci_read_config_dword(dev, 0x7C, &sim_data.memory_type);
713 pci_dev_put(dev);
712 sim_data.memory_type = (sim_data.memory_type >> 12) & 1; 714 sim_data.memory_type = (sim_data.memory_type >> 12) & 1;
713 sim_data.memory_width = 64; 715 sim_data.memory_width = 64;
714 716
715 dev = pci_find_slot(0, 3); 717 dev = pci_get_bus_and_slot(0, 3);
716 pci_read_config_dword(dev, 0, &memctrl); 718 pci_read_config_dword(dev, 0, &memctrl);
719 pci_dev_put(dev);
717 memctrl >>= 16; 720 memctrl >>= 16;
718 721
719 if ((memctrl == 0x1A9) || (memctrl == 0x1AB) || (memctrl == 0x1ED)) { 722 if ((memctrl == 0x1A9) || (memctrl == 0x1AB) || (memctrl == 0x1ED)) {
720 int dimm[3]; 723 int dimm[3];
721 724
722 pci_find_slot(0, 2); 725 dev = pci_get_bus_and_slot(0, 2);
723 pci_read_config_dword(dev, 0x40, &dimm[0]); 726 pci_read_config_dword(dev, 0x40, &dimm[0]);
724 dimm[0] = (dimm[0] >> 8) & 0x4f; 727 dimm[0] = (dimm[0] >> 8) & 0x4f;
725 pci_read_config_dword(dev, 0x44, &dimm[1]); 728 pci_read_config_dword(dev, 0x44, &dimm[1]);
@@ -731,6 +734,7 @@ static void nForceUpdateArbitrationSettings(unsigned VClk,
731 printk("nvidiafb: your nForce DIMMs are not arranged " 734 printk("nvidiafb: your nForce DIMMs are not arranged "
732 "in optimal banks!\n"); 735 "in optimal banks!\n");
733 } 736 }
737 pci_dev_put(dev);
734 } 738 }
735 739
736 sim_data.mem_latency = 3; 740 sim_data.mem_latency = 3;
@@ -960,6 +964,7 @@ void NVLoadStateExt(struct nvidia_par *par, RIVA_HW_STATE * state)
960 964
961 if (((par->Chipset & 0xfff0) == 0x0090) || 965 if (((par->Chipset & 0xfff0) == 0x0090) ||
962 ((par->Chipset & 0xfff0) == 0x01D0) || 966 ((par->Chipset & 0xfff0) == 0x01D0) ||
967 ((par->Chipset & 0xfff0) == 0x02E0) ||
963 ((par->Chipset & 0xfff0) == 0x0290)) 968 ((par->Chipset & 0xfff0) == 0x0290))
964 regions = 15; 969 regions = 15;
965 for(i = 0; i < regions; i++) { 970 for(i = 0; i < regions; i++) {
@@ -1272,6 +1277,7 @@ void NVLoadStateExt(struct nvidia_par *par, RIVA_HW_STATE * state)
1272 0x00100000); 1277 0x00100000);
1273 break; 1278 break;
1274 case 0x0090: 1279 case 0x0090:
1280 case 0x02E0:
1275 case 0x0290: 1281 case 0x0290:
1276 NV_WR32(par->PRAMDAC, 0x0608, 1282 NV_WR32(par->PRAMDAC, 0x0608,
1277 NV_RD32(par->PRAMDAC, 0x0608) | 1283 NV_RD32(par->PRAMDAC, 0x0608) |
@@ -1349,6 +1355,7 @@ void NVLoadStateExt(struct nvidia_par *par, RIVA_HW_STATE * state)
1349 } else { 1355 } else {
1350 if (((par->Chipset & 0xfff0) == 0x0090) || 1356 if (((par->Chipset & 0xfff0) == 0x0090) ||
1351 ((par->Chipset & 0xfff0) == 0x01D0) || 1357 ((par->Chipset & 0xfff0) == 0x01D0) ||
1358 ((par->Chipset & 0xfff0) == 0x02E0) ||
1352 ((par->Chipset & 0xfff0) == 0x0290)) { 1359 ((par->Chipset & 0xfff0) == 0x0290)) {
1353 for (i = 0; i < 60; i++) { 1360 for (i = 0; i < 60; i++) {
1354 NV_WR32(par->PGRAPH, 1361 NV_WR32(par->PGRAPH,
@@ -1400,6 +1407,7 @@ void NVLoadStateExt(struct nvidia_par *par, RIVA_HW_STATE * state)
1400 } else { 1407 } else {
1401 if ((par->Chipset & 0xfff0) == 0x0090 || 1408 if ((par->Chipset & 0xfff0) == 0x0090 ||
1402 (par->Chipset & 0xfff0) == 0x01D0 || 1409 (par->Chipset & 0xfff0) == 0x01D0 ||
1410 (par->Chipset & 0xfff0) == 0x02E0 ||
1403 (par->Chipset & 0xfff0) == 0x0290) { 1411 (par->Chipset & 0xfff0) == 0x0290) {
1404 NV_WR32(par->PGRAPH, 0x0DF0, 1412 NV_WR32(par->PGRAPH, 0x0DF0,
1405 NV_RD32(par->PFB, 0x0200)); 1413 NV_RD32(par->PFB, 0x0200));
diff --git a/drivers/video/nvidia/nv_i2c.c b/drivers/video/nvidia/nv_i2c.c
index b8588973e400..afe4567e1ff4 100644
--- a/drivers/video/nvidia/nv_i2c.c
+++ b/drivers/video/nvidia/nv_i2c.c
@@ -30,16 +30,14 @@ static void nvidia_gpio_setscl(void *data, int state)
30 struct nvidia_par *par = chan->par; 30 struct nvidia_par *par = chan->par;
31 u32 val; 31 u32 val;
32 32
33 VGA_WR08(par->PCIO, 0x3d4, chan->ddc_base + 1); 33 val = NVReadCrtc(par, chan->ddc_base + 1) & 0xf0;
34 val = VGA_RD08(par->PCIO, 0x3d5) & 0xf0;
35 34
36 if (state) 35 if (state)
37 val |= 0x20; 36 val |= 0x20;
38 else 37 else
39 val &= ~0x20; 38 val &= ~0x20;
40 39
41 VGA_WR08(par->PCIO, 0x3d4, chan->ddc_base + 1); 40 NVWriteCrtc(par, chan->ddc_base + 1, val | 0x01);
42 VGA_WR08(par->PCIO, 0x3d5, val | 0x1);
43} 41}
44 42
45static void nvidia_gpio_setsda(void *data, int state) 43static void nvidia_gpio_setsda(void *data, int state)
@@ -48,16 +46,14 @@ static void nvidia_gpio_setsda(void *data, int state)
48 struct nvidia_par *par = chan->par; 46 struct nvidia_par *par = chan->par;
49 u32 val; 47 u32 val;
50 48
51 VGA_WR08(par->PCIO, 0x3d4, chan->ddc_base + 1); 49 val = NVReadCrtc(par, chan->ddc_base + 1) & 0xf0;
52 val = VGA_RD08(par->PCIO, 0x3d5) & 0xf0;
53 50
54 if (state) 51 if (state)
55 val |= 0x10; 52 val |= 0x10;
56 else 53 else
57 val &= ~0x10; 54 val &= ~0x10;
58 55
59 VGA_WR08(par->PCIO, 0x3d4, chan->ddc_base + 1); 56 NVWriteCrtc(par, chan->ddc_base + 1, val | 0x01);
60 VGA_WR08(par->PCIO, 0x3d5, val | 0x1);
61} 57}
62 58
63static int nvidia_gpio_getscl(void *data) 59static int nvidia_gpio_getscl(void *data)
@@ -66,12 +62,9 @@ static int nvidia_gpio_getscl(void *data)
66 struct nvidia_par *par = chan->par; 62 struct nvidia_par *par = chan->par;
67 u32 val = 0; 63 u32 val = 0;
68 64
69 VGA_WR08(par->PCIO, 0x3d4, chan->ddc_base); 65 if (NVReadCrtc(par, chan->ddc_base) & 0x04)
70 if (VGA_RD08(par->PCIO, 0x3d5) & 0x04)
71 val = 1; 66 val = 1;
72 67
73 val = VGA_RD08(par->PCIO, 0x3d5);
74
75 return val; 68 return val;
76} 69}
77 70
@@ -81,20 +74,21 @@ static int nvidia_gpio_getsda(void *data)
81 struct nvidia_par *par = chan->par; 74 struct nvidia_par *par = chan->par;
82 u32 val = 0; 75 u32 val = 0;
83 76
84 VGA_WR08(par->PCIO, 0x3d4, chan->ddc_base); 77 if (NVReadCrtc(par, chan->ddc_base) & 0x08)
85 if (VGA_RD08(par->PCIO, 0x3d5) & 0x08)
86 val = 1; 78 val = 1;
87 79
88 return val; 80 return val;
89} 81}
90 82
91static int nvidia_setup_i2c_bus(struct nvidia_i2c_chan *chan, const char *name) 83static int nvidia_setup_i2c_bus(struct nvidia_i2c_chan *chan, const char *name,
84 unsigned int i2c_class)
92{ 85{
93 int rc; 86 int rc;
94 87
95 strcpy(chan->adapter.name, name); 88 strcpy(chan->adapter.name, name);
96 chan->adapter.owner = THIS_MODULE; 89 chan->adapter.owner = THIS_MODULE;
97 chan->adapter.id = I2C_HW_B_NVIDIA; 90 chan->adapter.id = I2C_HW_B_NVIDIA;
91 chan->adapter.class = i2c_class;
98 chan->adapter.algo_data = &chan->algo; 92 chan->adapter.algo_data = &chan->algo;
99 chan->adapter.dev.parent = &chan->par->pci_dev->dev; 93 chan->adapter.dev.parent = &chan->par->pci_dev->dev;
100 chan->algo.setsda = nvidia_gpio_setsda; 94 chan->algo.setsda = nvidia_gpio_setsda;
@@ -127,83 +121,39 @@ static int nvidia_setup_i2c_bus(struct nvidia_i2c_chan *chan, const char *name)
127 121
128void nvidia_create_i2c_busses(struct nvidia_par *par) 122void nvidia_create_i2c_busses(struct nvidia_par *par)
129{ 123{
130 par->bus = 3;
131
132 par->chan[0].par = par; 124 par->chan[0].par = par;
133 par->chan[1].par = par; 125 par->chan[1].par = par;
134 par->chan[2].par = par; 126 par->chan[2].par = par;
135 127
136 par->chan[0].ddc_base = 0x3e; 128 par->chan[0].ddc_base = 0x36;
137 nvidia_setup_i2c_bus(&par->chan[0], "nvidia #0"); 129 nvidia_setup_i2c_bus(&par->chan[0], "nvidia #0", I2C_CLASS_HWMON);
138 130
139 par->chan[1].ddc_base = 0x36; 131 par->chan[1].ddc_base = 0x3e;
140 nvidia_setup_i2c_bus(&par->chan[1], "nvidia #1"); 132 nvidia_setup_i2c_bus(&par->chan[1], "nvidia #1", 0);
141 133
142 par->chan[2].ddc_base = 0x50; 134 par->chan[2].ddc_base = 0x50;
143 nvidia_setup_i2c_bus(&par->chan[2], "nvidia #2"); 135 nvidia_setup_i2c_bus(&par->chan[2], "nvidia #2", 0);
144} 136}
145 137
146void nvidia_delete_i2c_busses(struct nvidia_par *par) 138void nvidia_delete_i2c_busses(struct nvidia_par *par)
147{ 139{
148 if (par->chan[0].par) 140 int i;
149 i2c_del_adapter(&par->chan[0].adapter);
150 par->chan[0].par = NULL;
151
152 if (par->chan[1].par)
153 i2c_del_adapter(&par->chan[1].adapter);
154 par->chan[1].par = NULL;
155
156 if (par->chan[2].par)
157 i2c_del_adapter(&par->chan[2].adapter);
158 par->chan[2].par = NULL;
159
160}
161 141
162static u8 *nvidia_do_probe_i2c_edid(struct nvidia_i2c_chan *chan) 142 for (i = 0; i < 3; i++) {
163{ 143 if (!par->chan[i].par)
164 u8 start = 0x0; 144 continue;
165 struct i2c_msg msgs[] = { 145 i2c_del_adapter(&par->chan[i].adapter);
166 { 146 par->chan[i].par = NULL;
167 .addr = 0x50,
168 .len = 1,
169 .buf = &start,
170 }, {
171 .addr = 0x50,
172 .flags = I2C_M_RD,
173 .len = EDID_LENGTH,
174 },
175 };
176 u8 *buf;
177
178 if (!chan->par)
179 return NULL;
180
181 buf = kmalloc(EDID_LENGTH, GFP_KERNEL);
182 if (!buf) {
183 dev_warn(&chan->par->pci_dev->dev, "Out of memory!\n");
184 return NULL;
185 } 147 }
186 msgs[1].buf = buf;
187
188 if (i2c_transfer(&chan->adapter, msgs, 2) == 2)
189 return buf;
190 dev_dbg(&chan->par->pci_dev->dev, "Unable to read EDID block.\n");
191 kfree(buf);
192 return NULL;
193} 148}
194 149
195int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid) 150int nvidia_probe_i2c_connector(struct fb_info *info, int conn, u8 **out_edid)
196{ 151{
197 struct nvidia_par *par = info->par; 152 struct nvidia_par *par = info->par;
198 u8 *edid = NULL; 153 u8 *edid = NULL;
199 int i;
200 154
201 for (i = 0; i < 3; i++) { 155 if (par->chan[conn - 1].par)
202 /* Do the real work */ 156 edid = fb_ddc_read(&par->chan[conn - 1].adapter);
203 edid = nvidia_do_probe_i2c_edid(&par->chan[conn - 1]);
204 if (edid)
205 break;
206 }
207 157
208 if (!edid && conn == 1) { 158 if (!edid && conn == 1) {
209 /* try to get from firmware */ 159 /* try to get from firmware */
diff --git a/drivers/video/nvidia/nv_local.h b/drivers/video/nvidia/nv_local.h
index e009d242ea10..68e508daa417 100644
--- a/drivers/video/nvidia/nv_local.h
+++ b/drivers/video/nvidia/nv_local.h
@@ -73,9 +73,9 @@
73#define NVDmaNext(par, data) \ 73#define NVDmaNext(par, data) \
74 NV_WR32(&(par)->dmaBase[(par)->dmaCurrent++], 0, (data)) 74 NV_WR32(&(par)->dmaBase[(par)->dmaCurrent++], 0, (data))
75 75
76#define NVDmaStart(par, tag, size) { \ 76#define NVDmaStart(info, par, tag, size) { \
77 if((par)->dmaFree <= (size)) \ 77 if((par)->dmaFree <= (size)) \
78 NVDmaWait(par, size); \ 78 NVDmaWait(info, size); \
79 NVDmaNext(par, ((size) << 18) | (tag)); \ 79 NVDmaNext(par, ((size) << 18) | (tag)); \
80 (par)->dmaFree -= ((size) + 1); \ 80 (par)->dmaFree -= ((size) + 1); \
81} 81}
diff --git a/drivers/video/nvidia/nv_of.c b/drivers/video/nvidia/nv_of.c
index 163a774a1b30..73afd7eb9977 100644
--- a/drivers/video/nvidia/nv_of.c
+++ b/drivers/video/nvidia/nv_of.c
@@ -46,15 +46,15 @@ int nvidia_probe_of_connector(struct fb_info *info, int conn, u8 **out_edid)
46 46
47 for (dp = NULL; 47 for (dp = NULL;
48 (dp = of_get_next_child(parent, dp)) != NULL;) { 48 (dp = of_get_next_child(parent, dp)) != NULL;) {
49 pname = get_property(dp, "name", NULL); 49 pname = of_get_property(dp, "name", NULL);
50 if (!pname) 50 if (!pname)
51 continue; 51 continue;
52 len = strlen(pname); 52 len = strlen(pname);
53 if ((pname[len-1] == 'A' && conn == 1) || 53 if ((pname[len-1] == 'A' && conn == 1) ||
54 (pname[len-1] == 'B' && conn == 2)) { 54 (pname[len-1] == 'B' && conn == 2)) {
55 for (i = 0; propnames[i] != NULL; ++i) { 55 for (i = 0; propnames[i] != NULL; ++i) {
56 pedid = get_property(dp, propnames[i], 56 pedid = of_get_property(dp,
57 NULL); 57 propnames[i], NULL);
58 if (pedid != NULL) 58 if (pedid != NULL)
59 break; 59 break;
60 } 60 }
@@ -65,7 +65,7 @@ int nvidia_probe_of_connector(struct fb_info *info, int conn, u8 **out_edid)
65 } 65 }
66 if (pedid == NULL) { 66 if (pedid == NULL) {
67 for (i = 0; propnames[i] != NULL; ++i) { 67 for (i = 0; propnames[i] != NULL; ++i) {
68 pedid = get_property(parent, propnames[i], NULL); 68 pedid = of_get_property(parent, propnames[i], NULL);
69 if (pedid != NULL) 69 if (pedid != NULL)
70 break; 70 break;
71 } 71 }
diff --git a/drivers/video/nvidia/nv_setup.c b/drivers/video/nvidia/nv_setup.c
index eab3e282a4de..707e2c8a13ed 100644
--- a/drivers/video/nvidia/nv_setup.c
+++ b/drivers/video/nvidia/nv_setup.c
@@ -261,7 +261,7 @@ static void nv10GetConfig(struct nvidia_par *par)
261 } 261 }
262#endif 262#endif
263 263
264 dev = pci_find_slot(0, 1); 264 dev = pci_get_bus_and_slot(0, 1);
265 if ((par->Chipset & 0xffff) == 0x01a0) { 265 if ((par->Chipset & 0xffff) == 0x01a0) {
266 int amt = 0; 266 int amt = 0;
267 267
@@ -276,6 +276,7 @@ static void nv10GetConfig(struct nvidia_par *par)
276 par->RamAmountKBytes = 276 par->RamAmountKBytes =
277 (NV_RD32(par->PFB, 0x020C) & 0xFFF00000) >> 10; 277 (NV_RD32(par->PFB, 0x020C) & 0xFFF00000) >> 10;
278 } 278 }
279 pci_dev_put(dev);
279 280
280 par->CrystalFreqKHz = (NV_RD32(par->PEXTDEV, 0x0000) & (1 << 6)) ? 281 par->CrystalFreqKHz = (NV_RD32(par->PEXTDEV, 0x0000) & (1 << 6)) ?
281 14318 : 13500; 282 14318 : 13500;
@@ -656,7 +657,7 @@ int NVCommonSetup(struct fb_info *info)
656 par->LVDS = 0; 657 par->LVDS = 0;
657 if (par->FlatPanel && par->twoHeads) { 658 if (par->FlatPanel && par->twoHeads) {
658 NV_WR32(par->PRAMDAC0, 0x08B0, 0x00010004); 659 NV_WR32(par->PRAMDAC0, 0x08B0, 0x00010004);
659 if (par->PRAMDAC0[0x08b4] & 1) 660 if (NV_RD32(par->PRAMDAC0, 0x08b4) & 1)
660 par->LVDS = 1; 661 par->LVDS = 1;
661 printk("nvidiafb: Panel is %s\n", par->LVDS ? "LVDS" : "TMDS"); 662 printk("nvidiafb: Panel is %s\n", par->LVDS ? "LVDS" : "TMDS");
662 } 663 }
diff --git a/drivers/video/nvidia/nv_type.h b/drivers/video/nvidia/nv_type.h
index 86e65dea60d3..38f7cc0a2331 100644
--- a/drivers/video/nvidia/nv_type.h
+++ b/drivers/video/nvidia/nv_type.h
@@ -4,8 +4,9 @@
4#include <linux/fb.h> 4#include <linux/fb.h>
5#include <linux/types.h> 5#include <linux/types.h>
6#include <linux/i2c.h> 6#include <linux/i2c.h>
7#include <linux/i2c-id.h>
8#include <linux/i2c-algo-bit.h> 7#include <linux/i2c-algo-bit.h>
8#include <linux/mutex.h>
9#include <video/vga.h>
9 10
10#define NV_ARCH_04 0x04 11#define NV_ARCH_04 0x04
11#define NV_ARCH_10 0x10 12#define NV_ARCH_10 0x10
@@ -94,13 +95,15 @@ struct riva_regs {
94struct nvidia_par { 95struct nvidia_par {
95 RIVA_HW_STATE SavedReg; 96 RIVA_HW_STATE SavedReg;
96 RIVA_HW_STATE ModeReg; 97 RIVA_HW_STATE ModeReg;
98 RIVA_HW_STATE initial_state;
97 RIVA_HW_STATE *CurrentState; 99 RIVA_HW_STATE *CurrentState;
100 struct vgastate vgastate;
101 struct mutex open_lock;
98 u32 pseudo_palette[16]; 102 u32 pseudo_palette[16];
99 struct pci_dev *pci_dev; 103 struct pci_dev *pci_dev;
100 u32 Architecture; 104 u32 Architecture;
101 u32 CursorStart; 105 u32 CursorStart;
102 int Chipset; 106 int Chipset;
103 int bus;
104 unsigned long FbAddress; 107 unsigned long FbAddress;
105 u8 __iomem *FbStart; 108 u8 __iomem *FbStart;
106 u32 FbMapSize; 109 u32 FbMapSize;
@@ -143,6 +146,7 @@ struct nvidia_par {
143 int BlendingPossible; 146 int BlendingPossible;
144 u32 paletteEnabled; 147 u32 paletteEnabled;
145 u32 forceCRTC; 148 u32 forceCRTC;
149 u32 open_count;
146 u8 DDCBase; 150 u8 DDCBase;
147#ifdef CONFIG_MTRR 151#ifdef CONFIG_MTRR
148 struct { 152 struct {
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index b97ec6901263..41f63658572f 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -37,7 +37,6 @@
37#include "nv_proto.h" 37#include "nv_proto.h"
38#include "nv_dma.h" 38#include "nv_dma.h"
39 39
40#undef CONFIG_FB_NVIDIA_DEBUG
41#ifdef CONFIG_FB_NVIDIA_DEBUG 40#ifdef CONFIG_FB_NVIDIA_DEBUG
42#define NVTRACE printk 41#define NVTRACE printk
43#else 42#else
@@ -200,7 +199,7 @@ static int nvidia_panel_tweak(struct nvidia_par *par,
200 return tweak; 199 return tweak;
201} 200}
202 201
203static void nvidia_vga_protect(struct nvidia_par *par, int on) 202static void nvidia_screen_off(struct nvidia_par *par, int on)
204{ 203{
205 unsigned char tmp; 204 unsigned char tmp;
206 205
@@ -649,7 +648,7 @@ static int nvidiafb_set_par(struct fb_info *info)
649 NVLockUnlock(par, 0); 648 NVLockUnlock(par, 0);
650 } 649 }
651 650
652 nvidia_vga_protect(par, 1); 651 nvidia_screen_off(par, 1);
653 652
654 nvidia_write_regs(par, &par->ModeReg); 653 nvidia_write_regs(par, &par->ModeReg);
655 NVSetStartAddress(par, 0); 654 NVSetStartAddress(par, 0);
@@ -687,7 +686,7 @@ static int nvidiafb_set_par(struct fb_info *info)
687 686
688 par->cursor_reset = 1; 687 par->cursor_reset = 1;
689 688
690 nvidia_vga_protect(par, 0); 689 nvidia_screen_off(par, 0);
691 690
692#ifdef CONFIG_BOOTX_TEXT 691#ifdef CONFIG_BOOTX_TEXT
693 /* Update debug text engine */ 692 /* Update debug text engine */
@@ -696,6 +695,7 @@ static int nvidiafb_set_par(struct fb_info *info)
696 info->var.bits_per_pixel, info->fix.line_length); 695 info->var.bits_per_pixel, info->fix.line_length);
697#endif 696#endif
698 697
698 NVLockUnlock(par, 0);
699 NVTRACE_LEAVE(); 699 NVTRACE_LEAVE();
700 return 0; 700 return 0;
701} 701}
@@ -948,8 +948,80 @@ static int nvidiafb_blank(int blank, struct fb_info *info)
948 return 0; 948 return 0;
949} 949}
950 950
951/*
952 * Because the VGA registers are not mapped linearly in its MMIO space,
953 * restrict VGA register saving and restore to x86 only, where legacy VGA IO
954 * access is legal. Consequently, we must also check if the device is the
955 * primary display.
956 */
957#ifdef CONFIG_X86
958static void save_vga_x86(struct nvidia_par *par)
959{
960 struct resource *res= &par->pci_dev->resource[PCI_ROM_RESOURCE];
961
962 if (res && res->flags & IORESOURCE_ROM_SHADOW) {
963 memset(&par->vgastate, 0, sizeof(par->vgastate));
964 par->vgastate.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS |
965 VGA_SAVE_CMAP;
966 save_vga(&par->vgastate);
967 }
968}
969
970static void restore_vga_x86(struct nvidia_par *par)
971{
972 struct resource *res= &par->pci_dev->resource[PCI_ROM_RESOURCE];
973
974 if (res && res->flags & IORESOURCE_ROM_SHADOW)
975 restore_vga(&par->vgastate);
976}
977#else
978#define save_vga_x86(x) do {} while (0)
979#define restore_vga_x86(x) do {} while (0)
980#endif /* X86 */
981
982static int nvidiafb_open(struct fb_info *info, int user)
983{
984 struct nvidia_par *par = info->par;
985
986 mutex_lock(&par->open_lock);
987
988 if (!par->open_count) {
989 save_vga_x86(par);
990 nvidia_save_vga(par, &par->initial_state);
991 }
992
993 par->open_count++;
994 mutex_unlock(&par->open_lock);
995 return 0;
996}
997
998static int nvidiafb_release(struct fb_info *info, int user)
999{
1000 struct nvidia_par *par = info->par;
1001 int err = 0;
1002
1003 mutex_lock(&par->open_lock);
1004
1005 if (!par->open_count) {
1006 err = -EINVAL;
1007 goto done;
1008 }
1009
1010 if (par->open_count == 1) {
1011 nvidia_write_regs(par, &par->initial_state);
1012 restore_vga_x86(par);
1013 }
1014
1015 par->open_count--;
1016done:
1017 mutex_unlock(&par->open_lock);
1018 return err;
1019}
1020
951static struct fb_ops nvidia_fb_ops = { 1021static struct fb_ops nvidia_fb_ops = {
952 .owner = THIS_MODULE, 1022 .owner = THIS_MODULE,
1023 .fb_open = nvidiafb_open,
1024 .fb_release = nvidiafb_release,
953 .fb_check_var = nvidiafb_check_var, 1025 .fb_check_var = nvidiafb_check_var,
954 .fb_set_par = nvidiafb_set_par, 1026 .fb_set_par = nvidiafb_set_par,
955 .fb_setcolreg = nvidiafb_setcolreg, 1027 .fb_setcolreg = nvidiafb_setcolreg,
@@ -1170,6 +1242,7 @@ static u32 __devinit nvidia_get_arch(struct fb_info *info)
1170 case 0x0140: /* GeForce 6600 */ 1242 case 0x0140: /* GeForce 6600 */
1171 case 0x0160: /* GeForce 6200 */ 1243 case 0x0160: /* GeForce 6200 */
1172 case 0x01D0: /* GeForce 7200, 7300, 7400 */ 1244 case 0x01D0: /* GeForce 7200, 7300, 7400 */
1245 case 0x02E0: /* GeForce 7300 GT */
1173 case 0x0090: /* GeForce 7800 */ 1246 case 0x0090: /* GeForce 7800 */
1174 case 0x0210: /* GeForce 6800 */ 1247 case 0x0210: /* GeForce 6800 */
1175 case 0x0220: /* GeForce 6200 */ 1248 case 0x0220: /* GeForce 6200 */
@@ -1207,7 +1280,7 @@ static int __devinit nvidiafb_probe(struct pci_dev *pd,
1207 1280
1208 par = info->par; 1281 par = info->par;
1209 par->pci_dev = pd; 1282 par->pci_dev = pd;
1210 1283 mutex_init(&par->open_lock);
1211 info->pixmap.addr = kzalloc(8 * 1024, GFP_KERNEL); 1284 info->pixmap.addr = kzalloc(8 * 1024, GFP_KERNEL);
1212 1285
1213 if (info->pixmap.addr == NULL) 1286 if (info->pixmap.addr == NULL)
diff --git a/drivers/video/offb.c b/drivers/video/offb.c
index 9576a55eaf16..885b42836cbb 100644
--- a/drivers/video/offb.c
+++ b/drivers/video/offb.c
@@ -322,8 +322,8 @@ static void __init offb_init_fb(const char *name, const char *full_name,
322 ioremap(base + 0x7ff000, 0x1000) + 0xcc0; 322 ioremap(base + 0x7ff000, 0x1000) + 0xcc0;
323 par->cmap_data = par->cmap_adr + 1; 323 par->cmap_data = par->cmap_adr + 1;
324 par->cmap_type = cmap_m64; 324 par->cmap_type = cmap_m64;
325 } else if (dp && (device_is_compatible(dp, "pci1014,b7") || 325 } else if (dp && (of_device_is_compatible(dp, "pci1014,b7") ||
326 device_is_compatible(dp, "pci1014,21c"))) { 326 of_device_is_compatible(dp, "pci1014,21c"))) {
327 par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000); 327 par->cmap_adr = offb_map_reg(dp, 0, 0x6000, 0x1000);
328 if (par->cmap_adr) 328 if (par->cmap_adr)
329 par->cmap_type = cmap_gxt2000; 329 par->cmap_type = cmap_gxt2000;
@@ -425,27 +425,27 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
425 const u32 *pp, *addrp, *up; 425 const u32 *pp, *addrp, *up;
426 u64 asize; 426 u64 asize;
427 427
428 pp = get_property(dp, "linux,bootx-depth", &len); 428 pp = of_get_property(dp, "linux,bootx-depth", &len);
429 if (pp == NULL) 429 if (pp == NULL)
430 pp = get_property(dp, "depth", &len); 430 pp = of_get_property(dp, "depth", &len);
431 if (pp && len == sizeof(u32)) 431 if (pp && len == sizeof(u32))
432 depth = *pp; 432 depth = *pp;
433 433
434 pp = get_property(dp, "linux,bootx-width", &len); 434 pp = of_get_property(dp, "linux,bootx-width", &len);
435 if (pp == NULL) 435 if (pp == NULL)
436 pp = get_property(dp, "width", &len); 436 pp = of_get_property(dp, "width", &len);
437 if (pp && len == sizeof(u32)) 437 if (pp && len == sizeof(u32))
438 width = *pp; 438 width = *pp;
439 439
440 pp = get_property(dp, "linux,bootx-height", &len); 440 pp = of_get_property(dp, "linux,bootx-height", &len);
441 if (pp == NULL) 441 if (pp == NULL)
442 pp = get_property(dp, "height", &len); 442 pp = of_get_property(dp, "height", &len);
443 if (pp && len == sizeof(u32)) 443 if (pp && len == sizeof(u32))
444 height = *pp; 444 height = *pp;
445 445
446 pp = get_property(dp, "linux,bootx-linebytes", &len); 446 pp = of_get_property(dp, "linux,bootx-linebytes", &len);
447 if (pp == NULL) 447 if (pp == NULL)
448 pp = get_property(dp, "linebytes", &len); 448 pp = of_get_property(dp, "linebytes", &len);
449 if (pp && len == sizeof(u32) && (*pp != 0xffffffffu)) 449 if (pp && len == sizeof(u32) && (*pp != 0xffffffffu))
450 pitch = *pp; 450 pitch = *pp;
451 else 451 else
@@ -463,9 +463,9 @@ static void __init offb_init_nodriver(struct device_node *dp, int no_real_node)
463 * ranges and pick one that is both big enough and if possible encloses 463 * ranges and pick one that is both big enough and if possible encloses
464 * the "address" property. If none match, we pick the biggest 464 * the "address" property. If none match, we pick the biggest
465 */ 465 */
466 up = get_property(dp, "linux,bootx-addr", &len); 466 up = of_get_property(dp, "linux,bootx-addr", &len);
467 if (up == NULL) 467 if (up == NULL)
468 up = get_property(dp, "address", &len); 468 up = of_get_property(dp, "address", &len);
469 if (up && len == sizeof(u32)) 469 if (up && len == sizeof(u32))
470 addr_prop = *up; 470 addr_prop = *up;
471 471
@@ -521,7 +521,7 @@ static int __init offb_init(void)
521 return -ENODEV; 521 return -ENODEV;
522 522
523 /* Check if we have a MacOS display without a node spec */ 523 /* Check if we have a MacOS display without a node spec */
524 if (get_property(of_chosen, "linux,bootx-noscreen", NULL) != NULL) { 524 if (of_get_property(of_chosen, "linux,bootx-noscreen", NULL) != NULL) {
525 /* The old code tried to work out which node was the MacOS 525 /* The old code tried to work out which node was the MacOS
526 * display based on the address. I'm dropping that since the 526 * display based on the address. I'm dropping that since the
527 * lack of a node spec only happens with old BootX versions 527 * lack of a node spec only happens with old BootX versions
@@ -532,14 +532,14 @@ static int __init offb_init(void)
532 } 532 }
533 533
534 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) { 534 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
535 if (get_property(dp, "linux,opened", NULL) && 535 if (of_get_property(dp, "linux,opened", NULL) &&
536 get_property(dp, "linux,boot-display", NULL)) { 536 of_get_property(dp, "linux,boot-display", NULL)) {
537 boot_disp = dp; 537 boot_disp = dp;
538 offb_init_nodriver(dp, 0); 538 offb_init_nodriver(dp, 0);
539 } 539 }
540 } 540 }
541 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) { 541 for (dp = NULL; (dp = of_find_node_by_type(dp, "display"));) {
542 if (get_property(dp, "linux,opened", NULL) && 542 if (of_get_property(dp, "linux,opened", NULL) &&
543 dp != boot_disp) 543 dp != boot_disp)
544 offb_init_nodriver(dp, 0); 544 offb_init_nodriver(dp, 0);
545 } 545 }
diff --git a/drivers/video/pm2fb.c b/drivers/video/pm2fb.c
index a560a2223825..ab5e66890e4e 100644
--- a/drivers/video/pm2fb.c
+++ b/drivers/video/pm2fb.c
@@ -81,8 +81,6 @@ static int lowvsync;
81struct pm2fb_par 81struct pm2fb_par
82{ 82{
83 pm2type_t type; /* Board type */ 83 pm2type_t type; /* Board type */
84 u32 fb_size; /* framebuffer memory size */
85 unsigned char __iomem *v_fb; /* virtual address of frame buffer */
86 unsigned char __iomem *v_regs;/* virtual address of p_regs */ 84 unsigned char __iomem *v_regs;/* virtual address of p_regs */
87 u32 memclock; /* memclock */ 85 u32 memclock; /* memclock */
88 u32 video; /* video flags before blanking */ 86 u32 video; /* video flags before blanking */
@@ -103,7 +101,7 @@ static struct fb_fix_screeninfo pm2fb_fix __devinitdata = {
103 .xpanstep = 1, 101 .xpanstep = 1,
104 .ypanstep = 1, 102 .ypanstep = 1,
105 .ywrapstep = 0, 103 .ywrapstep = 0,
106 .accel = FB_ACCEL_NONE, 104 .accel = FB_ACCEL_3DLABS_PERMEDIA2,
107}; 105};
108 106
109/* 107/*
@@ -302,10 +300,10 @@ static void pm2v_mnp(u32 clk, unsigned char* mm, unsigned char* nn,
302 s32 delta = 1000; 300 s32 delta = 1000;
303 301
304 *mm = *nn = *pp = 0; 302 *mm = *nn = *pp = 0;
305 for (n = 1; n; n++) { 303 for ( m = 1; m < 128; m++) {
306 for ( m = 1; m; m++) { 304 for (n = 2 * m + 1; n; n++) {
307 for ( p = 0; p < 2; p++) { 305 for ( p = 0; p < 2; p++) {
308 f = PM2_REFERENCE_CLOCK * n / (m * (1 << (p + 1))); 306 f = ( PM2_REFERENCE_CLOCK >> ( p + 1 )) * n / m;
309 if ( clk > f - delta && clk < f + delta ) { 307 if ( clk > f - delta && clk < f + delta ) {
310 delta = ( clk > f ) ? clk - f : f - clk; 308 delta = ( clk > f ) ? clk - f : f - clk;
311 *mm=m; 309 *mm=m;
@@ -462,21 +460,43 @@ static void set_memclock(struct pm2fb_par* par, u32 clk)
462 int i; 460 int i;
463 unsigned char m, n, p; 461 unsigned char m, n, p;
464 462
465 pm2_mnp(clk, &m, &n, &p); 463 switch (par->type) {
466 WAIT_FIFO(par, 10); 464 case PM2_TYPE_PERMEDIA2V:
467 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6); 465 pm2v_mnp(clk/2, &m, &n, &p);
468 wmb(); 466 WAIT_FIFO(par, 8);
469 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m); 467 pm2_WR(par, PM2VR_RD_INDEX_HIGH, PM2VI_RD_MCLK_CONTROL >> 8);
470 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n); 468 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 0);
471 wmb(); 469 wmb();
472 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p); 470 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_PRESCALE, m);
473 wmb(); 471 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_FEEDBACK, n);
474 pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS); 472 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_POSTSCALE, p);
475 rmb(); 473 wmb();
476 for (i = 256; 474 pm2v_RDAC_WR(par, PM2VI_RD_MCLK_CONTROL, 1);
477 i && !(pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED); 475 rmb();
478 i--) 476 for (i = 256;
479 ; 477 i && !(pm2_RDAC_RD(par, PM2VI_RD_MCLK_CONTROL) & 2);
478 i--)
479 ;
480 pm2_WR(par, PM2VR_RD_INDEX_HIGH, 0);
481 break;
482 case PM2_TYPE_PERMEDIA2:
483 pm2_mnp(clk, &m, &n, &p);
484 WAIT_FIFO(par, 10);
485 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 6);
486 wmb();
487 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_1, m);
488 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_2, n);
489 wmb();
490 pm2_RDAC_WR(par, PM2I_RD_MEMORY_CLOCK_3, 8|p);
491 wmb();
492 pm2_RDAC_RD(par, PM2I_RD_MEMORY_CLOCK_STATUS);
493 rmb();
494 for (i = 256;
495 i && !(pm2_RD(par, PM2R_RD_INDEXED_DATA) & PM2F_PLL_LOCKED);
496 i--)
497 ;
498 break;
499 }
480} 500}
481 501
482static void set_pixclock(struct pm2fb_par* par, u32 clk) 502static void set_pixclock(struct pm2fb_par* par, u32 clk)
@@ -623,6 +643,8 @@ static int pm2fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
623 return -EINVAL; 643 return -EINVAL;
624 } 644 }
625 645
646 var->transp.offset = 0;
647 var->transp.length = 0;
626 switch(var->bits_per_pixel) { 648 switch(var->bits_per_pixel) {
627 case 8: 649 case 8:
628 var->red.length = var->green.length = var->blue.length = 8; 650 var->red.length = var->green.length = var->blue.length = 8;
@@ -1017,6 +1039,131 @@ static int pm2fb_blank(int blank_mode, struct fb_info *info)
1017 return 0; 1039 return 0;
1018} 1040}
1019 1041
1042static int pm2fb_sync(struct fb_info *info)
1043{
1044 struct pm2fb_par *par = info->par;
1045
1046 WAIT_FIFO(par, 1);
1047 pm2_WR(par, PM2R_SYNC, 0);
1048 mb();
1049 do {
1050 while (pm2_RD(par, PM2R_OUT_FIFO_WORDS) == 0)
1051 udelay(10);
1052 rmb();
1053 } while (pm2_RD(par, PM2R_OUT_FIFO) != PM2TAG(PM2R_SYNC));
1054
1055 return 0;
1056}
1057
1058/*
1059 * block operation. copy=0: rectangle fill, copy=1: rectangle copy.
1060 */
1061static void pm2fb_block_op(struct fb_info* info, int copy,
1062 s32 xsrc, s32 ysrc,
1063 s32 x, s32 y, s32 w, s32 h,
1064 u32 color) {
1065 struct pm2fb_par *par = info->par;
1066
1067 if (!w || !h)
1068 return;
1069 WAIT_FIFO(par, 6);
1070 pm2_WR(par, PM2R_CONFIG, PM2F_CONFIG_FB_WRITE_ENABLE |
1071 PM2F_CONFIG_FB_READ_SOURCE_ENABLE);
1072 pm2_WR(par, PM2R_FB_PIXEL_OFFSET, 0);
1073 if (copy)
1074 pm2_WR(par, PM2R_FB_SOURCE_DELTA,
1075 ((ysrc-y) & 0xfff) << 16 | ((xsrc-x) & 0xfff));
1076 else
1077 pm2_WR(par, PM2R_FB_BLOCK_COLOR, color);
1078 pm2_WR(par, PM2R_RECTANGLE_ORIGIN, (y << 16) | x);
1079 pm2_WR(par, PM2R_RECTANGLE_SIZE, (h << 16) | w);
1080 wmb();
1081 pm2_WR(par, PM2R_RENDER,PM2F_RENDER_RECTANGLE |
1082 (x<xsrc ? PM2F_INCREASE_X : 0) |
1083 (y<ysrc ? PM2F_INCREASE_Y : 0) |
1084 (copy ? 0 : PM2F_RENDER_FASTFILL));
1085}
1086
1087static void pm2fb_fillrect (struct fb_info *info,
1088 const struct fb_fillrect *region)
1089{
1090 struct fb_fillrect modded;
1091 int vxres, vyres;
1092 u32 color = (info->fix.visual == FB_VISUAL_TRUECOLOR) ?
1093 ((u32*)info->pseudo_palette)[region->color] : region->color;
1094
1095 if (info->state != FBINFO_STATE_RUNNING)
1096 return;
1097 if ((info->flags & FBINFO_HWACCEL_DISABLED) ||
1098 region->rop != ROP_COPY ) {
1099 cfb_fillrect(info, region);
1100 return;
1101 }
1102
1103 vxres = info->var.xres_virtual;
1104 vyres = info->var.yres_virtual;
1105
1106 memcpy(&modded, region, sizeof(struct fb_fillrect));
1107
1108 if(!modded.width || !modded.height ||
1109 modded.dx >= vxres || modded.dy >= vyres)
1110 return;
1111
1112 if(modded.dx + modded.width > vxres)
1113 modded.width = vxres - modded.dx;
1114 if(modded.dy + modded.height > vyres)
1115 modded.height = vyres - modded.dy;
1116
1117 if(info->var.bits_per_pixel == 8)
1118 color |= color << 8;
1119 if(info->var.bits_per_pixel <= 16)
1120 color |= color << 16;
1121
1122 if(info->var.bits_per_pixel != 24)
1123 pm2fb_block_op(info, 0, 0, 0,
1124 modded.dx, modded.dy,
1125 modded.width, modded.height, color);
1126 else
1127 cfb_fillrect(info, region);
1128}
1129
1130static void pm2fb_copyarea(struct fb_info *info,
1131 const struct fb_copyarea *area)
1132{
1133 struct fb_copyarea modded;
1134 u32 vxres, vyres;
1135
1136 if (info->state != FBINFO_STATE_RUNNING)
1137 return;
1138 if (info->flags & FBINFO_HWACCEL_DISABLED) {
1139 cfb_copyarea(info, area);
1140 return;
1141 }
1142
1143 memcpy(&modded, area, sizeof(struct fb_copyarea));
1144
1145 vxres = info->var.xres_virtual;
1146 vyres = info->var.yres_virtual;
1147
1148 if(!modded.width || !modded.height ||
1149 modded.sx >= vxres || modded.sy >= vyres ||
1150 modded.dx >= vxres || modded.dy >= vyres)
1151 return;
1152
1153 if(modded.sx + modded.width > vxres)
1154 modded.width = vxres - modded.sx;
1155 if(modded.dx + modded.width > vxres)
1156 modded.width = vxres - modded.dx;
1157 if(modded.sy + modded.height > vyres)
1158 modded.height = vyres - modded.sy;
1159 if(modded.dy + modded.height > vyres)
1160 modded.height = vyres - modded.dy;
1161
1162 pm2fb_block_op(info, 1, modded.sx, modded.sy,
1163 modded.dx, modded.dy,
1164 modded.width, modded.height, 0);
1165}
1166
1020/* ------------ Hardware Independent Functions ------------ */ 1167/* ------------ Hardware Independent Functions ------------ */
1021 1168
1022/* 1169/*
@@ -1030,9 +1177,10 @@ static struct fb_ops pm2fb_ops = {
1030 .fb_setcolreg = pm2fb_setcolreg, 1177 .fb_setcolreg = pm2fb_setcolreg,
1031 .fb_blank = pm2fb_blank, 1178 .fb_blank = pm2fb_blank,
1032 .fb_pan_display = pm2fb_pan_display, 1179 .fb_pan_display = pm2fb_pan_display,
1033 .fb_fillrect = cfb_fillrect, 1180 .fb_fillrect = pm2fb_fillrect,
1034 .fb_copyarea = cfb_copyarea, 1181 .fb_copyarea = pm2fb_copyarea,
1035 .fb_imageblit = cfb_imageblit, 1182 .fb_imageblit = cfb_imageblit,
1183 .fb_sync = pm2fb_sync,
1036}; 1184};
1037 1185
1038/* 1186/*
@@ -1119,38 +1267,47 @@ static int __devinit pm2fb_probe(struct pci_dev *pdev,
1119 1267
1120 if(default_par->mem_control == 0 && 1268 if(default_par->mem_control == 0 &&
1121 default_par->boot_address == 0x31 && 1269 default_par->boot_address == 0x31 &&
1122 default_par->mem_config == 0x259fffff && 1270 default_par->mem_config == 0x259fffff) {
1123 pdev->subsystem_vendor == 0x1048 && 1271 default_par->memclock = CVPPC_MEMCLOCK;
1124 pdev->subsystem_device == 0x0a31) {
1125 DPRINTK("subsystem_vendor: %04x, subsystem_device: %04x\n",
1126 pdev->subsystem_vendor, pdev->subsystem_device);
1127 DPRINTK("We have not been initialized by VGA BIOS "
1128 "and are running on an Elsa Winner 2000 Office\n");
1129 DPRINTK("Initializing card timings manually...\n");
1130 default_par->mem_control=0; 1272 default_par->mem_control=0;
1131 default_par->boot_address=0x20; 1273 default_par->boot_address=0x20;
1132 default_par->mem_config=0xe6002021; 1274 default_par->mem_config=0xe6002021;
1133 default_par->memclock=100000; 1275 if (pdev->subsystem_vendor == 0x1048 &&
1276 pdev->subsystem_device == 0x0a31) {
1277 DPRINTK("subsystem_vendor: %04x, subsystem_device: %04x\n",
1278 pdev->subsystem_vendor, pdev->subsystem_device);
1279 DPRINTK("We have not been initialized by VGA BIOS "
1280 "and are running on an Elsa Winner 2000 Office\n");
1281 DPRINTK("Initializing card timings manually...\n");
1282 default_par->memclock=70000;
1283 }
1284 if (pdev->subsystem_vendor == 0x3d3d &&
1285 pdev->subsystem_device == 0x0100) {
1286 DPRINTK("subsystem_vendor: %04x, subsystem_device: %04x\n",
1287 pdev->subsystem_vendor, pdev->subsystem_device);
1288 DPRINTK("We have not been initialized by VGA BIOS "
1289 "and are running on an 3dlabs reference board\n");
1290 DPRINTK("Initializing card timings manually...\n");
1291 default_par->memclock=74894;
1292 }
1134 } 1293 }
1135 1294
1136 /* Now work out how big lfb is going to be. */ 1295 /* Now work out how big lfb is going to be. */
1137 switch(default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) { 1296 switch(default_par->mem_config & PM2F_MEM_CONFIG_RAM_MASK) {
1138 case PM2F_MEM_BANKS_1: 1297 case PM2F_MEM_BANKS_1:
1139 default_par->fb_size=0x200000; 1298 pm2fb_fix.smem_len=0x200000;
1140 break; 1299 break;
1141 case PM2F_MEM_BANKS_2: 1300 case PM2F_MEM_BANKS_2:
1142 default_par->fb_size=0x400000; 1301 pm2fb_fix.smem_len=0x400000;
1143 break; 1302 break;
1144 case PM2F_MEM_BANKS_3: 1303 case PM2F_MEM_BANKS_3:
1145 default_par->fb_size=0x600000; 1304 pm2fb_fix.smem_len=0x600000;
1146 break; 1305 break;
1147 case PM2F_MEM_BANKS_4: 1306 case PM2F_MEM_BANKS_4:
1148 default_par->fb_size=0x800000; 1307 pm2fb_fix.smem_len=0x800000;
1149 break; 1308 break;
1150 } 1309 }
1151 default_par->memclock = CVPPC_MEMCLOCK;
1152 pm2fb_fix.smem_start = pci_resource_start(pdev, 1); 1310 pm2fb_fix.smem_start = pci_resource_start(pdev, 1);
1153 pm2fb_fix.smem_len = default_par->fb_size;
1154 1311
1155 /* Linear frame buffer - request region and map it. */ 1312 /* Linear frame buffer - request region and map it. */
1156 if ( !request_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len, 1313 if ( !request_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len,
@@ -1158,9 +1315,9 @@ static int __devinit pm2fb_probe(struct pci_dev *pdev,
1158 printk(KERN_WARNING "pm2fb: Can't reserve smem.\n"); 1315 printk(KERN_WARNING "pm2fb: Can't reserve smem.\n");
1159 goto err_exit_mmio; 1316 goto err_exit_mmio;
1160 } 1317 }
1161 info->screen_base = default_par->v_fb = 1318 info->screen_base =
1162 ioremap_nocache(pm2fb_fix.smem_start, pm2fb_fix.smem_len); 1319 ioremap_nocache(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1163 if ( !default_par->v_fb ) { 1320 if ( !info->screen_base ) {
1164 printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n"); 1321 printk(KERN_WARNING "pm2fb: Can't ioremap smem area.\n");
1165 release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len); 1322 release_mem_region(pm2fb_fix.smem_start, pm2fb_fix.smem_len);
1166 goto err_exit_mmio; 1323 goto err_exit_mmio;
@@ -1170,7 +1327,9 @@ static int __devinit pm2fb_probe(struct pci_dev *pdev,
1170 info->fix = pm2fb_fix; 1327 info->fix = pm2fb_fix;
1171 info->pseudo_palette = default_par->palette; 1328 info->pseudo_palette = default_par->palette;
1172 info->flags = FBINFO_DEFAULT | 1329 info->flags = FBINFO_DEFAULT |
1173 FBINFO_HWACCEL_YPAN; 1330 FBINFO_HWACCEL_YPAN |
1331 FBINFO_HWACCEL_COPYAREA |
1332 FBINFO_HWACCEL_FILLRECT;
1174 1333
1175 if (!mode) 1334 if (!mode)
1176 mode = "640x480@60"; 1335 mode = "640x480@60";
@@ -1180,13 +1339,13 @@ static int __devinit pm2fb_probe(struct pci_dev *pdev,
1180 info->var = pm2fb_var; 1339 info->var = pm2fb_var;
1181 1340
1182 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) 1341 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0)
1183 goto err_exit_all; 1342 goto err_exit_both;
1184 1343
1185 if (register_framebuffer(info) < 0) 1344 if (register_framebuffer(info) < 0)
1186 goto err_exit_both; 1345 goto err_exit_all;
1187 1346
1188 printk(KERN_INFO "fb%d: %s frame buffer device, memory = %dK.\n", 1347 printk(KERN_INFO "fb%d: %s frame buffer device, memory = %dK.\n",
1189 info->node, info->fix.id, default_par->fb_size / 1024); 1348 info->node, info->fix.id, pm2fb_fix.smem_len / 1024);
1190 1349
1191 /* 1350 /*
1192 * Our driver data 1351 * Our driver data
@@ -1242,6 +1401,9 @@ static struct pci_device_id pm2fb_id_table[] = {
1242 { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V, 1401 { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V,
1243 PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, 1402 PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
1244 0xff0000, 0 }, 1403 0xff0000, 0 },
1404 { PCI_VENDOR_ID_3DLABS, PCI_DEVICE_ID_3DLABS_PERMEDIA2V,
1405 PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_NOT_DEFINED_VGA << 8,
1406 0xff00, 0 },
1245 { 0, } 1407 { 0, }
1246}; 1408};
1247 1409
diff --git a/drivers/video/pm3fb.c b/drivers/video/pm3fb.c
index bd787e80177d..c77a1a1fd46b 100644
--- a/drivers/video/pm3fb.c
+++ b/drivers/video/pm3fb.c
@@ -1,55 +1,25 @@
1/* 1/*
2 * linux/drivers/video/pm3fb.c -- 3DLabs Permedia3 frame buffer device 2 * linux/drivers/video/pm3fb.c -- 3DLabs Permedia3 frame buffer device
3 * 3 *
4 * Copyright (C) 2001 Romain Dolbeau <dolbeau@irisa.fr> 4 * Copyright (C) 2001 Romain Dolbeau <romain@dolbeau.org>.
5 *
6 * Ported to 2.6 kernel on 1 May 2007 by Krzysztof Helt <krzysztof.h1@wp.pl>
7 * based on pm2fb.c
8 *
5 * Based on code written by: 9 * Based on code written by:
6 * Sven Luther, <luther@dpt-info.u-strasbg.fr> 10 * Sven Luther, <luther@dpt-info.u-strasbg.fr>
7 * Alan Hourihane, <alanh@fairlite.demon.co.uk> 11 * Alan Hourihane, <alanh@fairlite.demon.co.uk>
8 * Russell King, <rmk@arm.linux.org.uk> 12 * Russell King, <rmk@arm.linux.org.uk>
9 * Based on linux/drivers/video/skeletonfb.c: 13 * Based on linux/drivers/video/skeletonfb.c:
10 * Copyright (C) 1997 Geert Uytterhoeven 14 * Copyright (C) 1997 Geert Uytterhoeven
11 * Based on linux/driver/video/pm2fb.c: 15 * Based on linux/driver/video/pm2fb.c:
12 * Copyright (C) 1998-1999 Ilario Nardinocchi (nardinoc@CS.UniBO.IT) 16 * Copyright (C) 1998-1999 Ilario Nardinocchi (nardinoc@CS.UniBO.IT)
13 * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com) 17 * Copyright (C) 1999 Jakub Jelinek (jakub@redhat.com)
14 * 18 *
15 * This file is subject to the terms and conditions of the GNU General Public 19 * This file is subject to the terms and conditions of the GNU General Public
16 * License. See the file COPYING in the main directory of this archive for 20 * License. See the file COPYING in the main directory of this archive for
17 * more details. 21 * more details.
18 * 22 *
19 * $Header: /cvsroot/linux/drivers/video/pm3fb.c,v 1.1 2002/02/25 19:11:06 marcelo Exp $
20 *
21 * CHANGELOG:
22 * Mon Feb 11 10:35:48 MET 2002, v 1.4.11B: Cosmetic update.
23 * Wed Jan 23 14:16:59 MET 2002, v 1.4.11: Preliminary 2.5.x support, patch for 2.5.2.
24 * Wed Nov 28 11:08:29 MET 2001, v 1.4.10: potential bug fix for SDRAM-based board, patch for 2.4.16.
25 * Thu Sep 20 10:24:42 MET DST 2001, v 1.4.9: sync bug fix, preliminary flatpanel support, better timings.
26 * Tue Aug 28 10:13:01 MET DST 2001, v 1.4.8: memory timings check, minor bug fixes.
27 * Wed Jul 18 19:06:14 CEST 2001, v 1.4.7: Mode fix (800x600-100, 1024x768-100 changed), using HW panning + accel bug fix.
28 * Mon Jun 25 10:33:56 MET DST 2001, v 1.4.6: Depth 12 fix, chip reset ioctl, moved memory erase ioctl to DEBUG.
29 * Wed Jun 20 11:13:08 MET DST 2001, v 1.4.5: Fixed missing blinking cursor in 8bpp, code cleaning, memory erase IOCTL.
30 * Mon Jun 18 16:00:27 CEST 2001, v 1.4.4: Depth 12 (RGBA 4444) support, code cleaning.
31 * Fri Jun 15 13:53:01 CEST 2001, v 1.4.3: Removed warnings, depth 15 support, add 'depth' option.
32 * Thu Jun 14 10:13:52 MET DST 2001, v 1.4.2: Fixed depth switching bug, preliminary 15bpp (RGB5551) support.
33 * Thu Apr 12 11:16:45 MET DST 2001, v 1.4.1B: Doc updates.
34 * Fri Apr 6 11:12:53 MET DST 2001, v 1.4.1: Configure.help, minor cleanup
35 * Thu Mar 29 10:56:50 MET DST 2001, v 1.4.0: Module & module options support (note: linux patch changed, 2.2.19 added).
36 * Thu Mar 15 15:30:31 MET 2001, v 1.3.2: Fixed mirroring bug on little-endian.
37 * Wed Mar 14 21:25:54 CET 2001, v 1.3.1: Fixed bug in BlockMove (_bmov).
38 * Tue Mar 13 10:53:19 MET 2001, v 1.3.0: Character drawing hardware support (in all width between 1 and 16), fixes.
39 * Thu Mar 8 10:20:16 MET 2001, v 1.2.2: Better J2000 support, "font:" option.
40 * Tue Mar 6 21:25:04 CET 2001, v 1.2.1: Better acceleration support.
41 * Mon Mar 5 21:54:17 CET 2001, v 1.2.0: Partial acceleration support (clear & bmove)
42 * Mon Mar 5 12:52:15 CET 2001, v 1.1.3: Big pan_display fix.
43 * Sun Mar 4 22:21:50 CET 2001, v 1.1.2: (numerous) bug fixes.
44 * Fri Mar 2 15:54:07 CET 2001, v 1.1.1: Might have Appian J2000 support, resource mangement in 2.4
45 * Wed Feb 28 18:21:35 CET 2001, v 1.1.0: Might have multiple boards support (added, but not yest tested)
46 * Tue Feb 27 17:31:12 CET 2001, v 1.0.6: fixes boot-time mode select, add more default mode
47 * Tue Feb 27 14:01:36 CET 2001, v 1.0.5: fixes (1.0.4 was broken for 2.2), cleaning up
48 * Mon Feb 26 23:17:36 CET 2001, v 1.0.4: preliminary 2.4.x support, dropped (useless on pm3) partial product, more OF fix
49 * Mon Feb 26 20:59:05 CET 2001, v 1.0.3: No more shadow register (and wasted memory), endianess fix, use OF-preset resolution by default
50 * Wed Feb 21 22:09:30 CET 2001, v 1.0.2: Code cleaning for future multiboard support, better OF support, bugs fix
51 * Wed Feb 21 19:58:56 CET 2001, v 1.0.1: OpenFirmware support, fixed memory detection, better debug support, code cleaning
52 * Wed Feb 21 14:47:06 CET 2001, v 1.0.0: First working version
53 */ 23 */
54 24
55#include <linux/module.h> 25#include <linux/module.h>
@@ -58,856 +28,155 @@
58#include <linux/string.h> 28#include <linux/string.h>
59#include <linux/mm.h> 29#include <linux/mm.h>
60#include <linux/slab.h> 30#include <linux/slab.h>
61#include <linux/vmalloc.h>
62#include <linux/delay.h> 31#include <linux/delay.h>
63#include <linux/interrupt.h>
64#include <linux/fb.h> 32#include <linux/fb.h>
65#include <linux/init.h> 33#include <linux/init.h>
66#include <linux/pci.h> 34#include <linux/pci.h>
67#include <linux/ioport.h>
68#include <linux/ctype.h>
69
70#include <video/fbcon.h>
71#include <video/fbcon-mfb.h>
72#include <video/fbcon-cfb2.h>
73#include <video/fbcon-cfb4.h>
74#include <video/fbcon-cfb8.h>
75#include <video/fbcon-cfb16.h>
76#include <video/fbcon-cfb24.h>
77#include <video/fbcon-cfb32.h>
78#include <video/pm3fb.h>
79 35
80#include <asm/io.h> 36#include <video/pm3fb.h>
81#include <asm/uaccess.h>
82 37
83#ifdef CONFIG_FB_OF 38#if !defined(CONFIG_PCI)
84#include <asm/prom.h> 39#error "Only generic PCI cards supported."
85#endif 40#endif
86 41
87/* ************************************* */ 42#undef PM3FB_MASTER_DEBUG
88/* ***** The various "global" data ***** */ 43#ifdef PM3FB_MASTER_DEBUG
89/* ************************************* */ 44#define DPRINTK(a,b...) printk(KERN_DEBUG "pm3fb: %s: " a, __FUNCTION__ , ## b)
90 45#else
91/* those will need a rework for multiple board support */ 46#define DPRINTK(a,b...)
92/* Driver name */
93static const char permedia3_name[16] = "Permedia3";
94
95/* the fb_par struct, mandatory */
96struct pm3fb_par {
97 u32 pixclock; /* pixclock in KHz */
98
99 u32 width; /* width of virtual screen */
100 u32 height; /* height of virtual screen */
101
102 u32 hsstart; /* horiz. sync start */
103 u32 hsend; /* horiz. sync end */
104 u32 hbend; /* horiz. blank end (also gate end) */
105 u32 htotal; /* total width (w/ sync & blank) */
106
107 u32 vsstart; /* vert. sync start */
108 u32 vsend; /* vert. sync end */
109 u32 vbend; /* vert. blank end */
110 u32 vtotal; /* total height (w/ sync & blank) */
111
112 u32 stride; /* screen stride */
113 u32 base; /* screen base (xoffset+yoffset) in 128 bits unit */
114 /* NOTE : unlike other pm3 stuff above, stored *after* shiftbpp. don't ask */
115 u32 depth; /* screen depth (8, 12, 15, 16 or 32) */
116 u32 video; /* video control (hsync,vsync) */
117};
118
119/* memory timings */
120struct pm3fb_timings
121{
122 unsigned long caps;
123 unsigned long timings;
124 unsigned long control;
125 unsigned long refresh;
126 unsigned long powerdown;
127};
128typedef enum pm3fb_timing_result { pm3fb_timing_ok, pm3fb_timing_problem, pm3fb_timing_retry } pm3fb_timing_result;
129#define PM3FB_UNKNOWN_TIMING_VALUE ((unsigned long)-1)
130#define PM3FB_UNKNOWN_TIMINGS { PM3FB_UNKNOWN_TIMING_VALUE, PM3FB_UNKNOWN_TIMING_VALUE, PM3FB_UNKNOWN_TIMING_VALUE, PM3FB_UNKNOWN_TIMING_VALUE, PM3FB_UNKNOWN_TIMING_VALUE }
131
132/* the fb_info struct, mandatory */
133struct pm3fb_info {
134 struct fb_info_gen gen;
135 unsigned long board_num; /* internal board number */
136 unsigned long use_current;
137 struct pm3fb_par *current_par;
138 struct pci_dev *dev; /* PCI device */
139 unsigned long board_type; /* index in the cardbase */
140 unsigned char *fb_base; /* framebuffer memory base */
141 u32 fb_size; /* framebuffer memory size */
142 unsigned char *p_fb; /* physical address of frame buffer */
143 unsigned char *v_fb; /* virtual address of frame buffer */
144 unsigned char *pIOBase; /* physical address of registers region, must be rg_base or rg_base+PM2_REGS_SIZE depending on the host endianness */
145 unsigned char *vIOBase; /* address of registers after ioremap() */
146 struct {
147 u8 transp;
148 u8 red;
149 u8 green;
150 u8 blue;
151 } palette[256];
152 union {
153#ifdef FBCON_HAS_CFB16
154 u16 cmap12[16]; /* RGBA 4444 */
155 u16 cmap15[16]; /* RGBA 5551 */
156 u16 cmap16[16]; /* RGBA 5650 */
157#endif
158#ifdef FBCON_HAS_CFB32
159 u32 cmap32[16];
160#endif 47#endif
161 } cmap;
162 struct pm3fb_timings memt;
163};
164 48
165/* regular resolution database*/ 49/*
166static struct { 50 * Driver data
167 char name[16]; 51 */
168 struct pm3fb_par user_mode; 52static char *mode_option __devinitdata;
169} mode_base[] __initdata = {
170 {
171 "default-800x600", {
172 49500, 800, 600, 16, 96, 256, 1056, 1, 4, 25, 625,
173 800, 0, 8,
174 PM3VideoControl_ENABLE |
175 PM3VideoControl_HSYNC_ACTIVE_HIGH
176 |
177 PM3VideoControl_VSYNC_ACTIVE_HIGH
178 | PM3VideoControl_PIXELSIZE_8BIT}}, {
179 "1024x768-74", {
180 78752, 1024, 768, 32, 128, 304, 1328, 1, 4, 38,
181 806, 1024, 0, 8,
182 PM3VideoControl_ENABLE |
183 PM3VideoControl_HSYNC_ACTIVE_HIGH
184 |
185 PM3VideoControl_VSYNC_ACTIVE_HIGH
186 | PM3VideoControl_PIXELSIZE_8BIT}}, {
187 "1024x768-74-32", {
188 78752, 1024, 768, 32, 128, 304, 1328, 1, 4, 38,
189 806, 1024, 0, 32,
190 PM3VideoControl_ENABLE |
191 PM3VideoControl_HSYNC_ACTIVE_HIGH
192 |
193 PM3VideoControl_VSYNC_ACTIVE_HIGH
194 | PM3VideoControl_PIXELSIZE_32BIT}},
195/* Generated mode : "1600x1024", for the SGI 1600SW flat panel*/
196 {
197 "SGI1600SW", {
198 108000, 1600, 1024, 16, 56, 104, 1704, 3, 6, 32,
199 1056, 1600, 0, 8,
200 PM3VideoControl_ENABLE|
201 PM3VideoControl_HSYNC_ACTIVE_LOW|PM3VideoControl_VSYNC_ACTIVE_LOW|
202 PM3VideoControl_PIXELSIZE_32BIT}},
203/* ##### auto-generated mode, by fbtimings2pm3 */
204/* Generated mode : "640x480-60" */
205 {
206 "640x480-60", {
207 25174, 640, 480, 16, 112, 160, 800, 10, 12, 45,
208 525, 640, 0, 8,
209 PM3VideoControl_ENABLE |
210 PM3VideoControl_HSYNC_ACTIVE_LOW
211 |
212 PM3VideoControl_VSYNC_ACTIVE_LOW
213 | PM3VideoControl_PIXELSIZE_8BIT}},
214/* Generated mode : "640x480-72" */
215 {
216 "640x480-72", {
217 31199, 640, 480, 24, 64, 192, 832, 9, 12, 40, 520,
218 640, 0, 8,
219 PM3VideoControl_ENABLE |
220 PM3VideoControl_HSYNC_ACTIVE_LOW
221 |
222 PM3VideoControl_VSYNC_ACTIVE_LOW
223 | PM3VideoControl_PIXELSIZE_8BIT}},
224/* Generated mode : "640x480-75" */
225 {
226 "640x480-75", {
227 31499, 640, 480, 16, 80, 200, 840, 1, 4, 20, 500,
228 640, 0, 8,
229 PM3VideoControl_ENABLE |
230 PM3VideoControl_HSYNC_ACTIVE_LOW
231 |
232 PM3VideoControl_VSYNC_ACTIVE_LOW
233 | PM3VideoControl_PIXELSIZE_8BIT}},
234/* Generated mode : "640x480-90" */
235 {
236 "640x480-90", {
237 39909, 640, 480, 32, 72, 192, 832, 25, 39, 53, 533,
238 640, 0, 8,
239 PM3VideoControl_ENABLE |
240 PM3VideoControl_HSYNC_ACTIVE_LOW
241 |
242 PM3VideoControl_VSYNC_ACTIVE_LOW
243 | PM3VideoControl_PIXELSIZE_8BIT}},
244/* Generated mode : "640x480-100" */
245 {
246 "640x480-100", {
247 44899, 640, 480, 32, 160, 208, 848, 22, 34, 51,
248 531, 640, 0, 8,
249 PM3VideoControl_ENABLE |
250 PM3VideoControl_HSYNC_ACTIVE_LOW
251 |
252 PM3VideoControl_VSYNC_ACTIVE_LOW
253 | PM3VideoControl_PIXELSIZE_8BIT}},
254/* Generated mode : "800x600-48-lace" */
255/* INTERLACED NOT SUPPORTED
256 {"800x600-48-lace", {35999, 800, 600, 80, 208, 264, 1064, 11, 23, 102, 702, 800, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}},
257 INTERLACED NOT SUPPORTED */
258/* Generated mode : "800x600-56" */
259 {
260 "800x600-56", {
261 35999, 800, 600, 24, 96, 224, 1024, 1, 3, 25, 625,
262 800, 0, 8,
263 PM3VideoControl_ENABLE |
264 PM3VideoControl_HSYNC_ACTIVE_HIGH
265 |
266 PM3VideoControl_VSYNC_ACTIVE_HIGH
267 | PM3VideoControl_PIXELSIZE_8BIT}},
268/* Generated mode : "800x600-60" */
269 {
270 "800x600-60", {
271 40000, 800, 600, 40, 168, 256, 1056, 1, 5, 28, 628,
272 800, 0, 8,
273 PM3VideoControl_ENABLE |
274 PM3VideoControl_HSYNC_ACTIVE_HIGH
275 |
276 PM3VideoControl_VSYNC_ACTIVE_HIGH
277 | PM3VideoControl_PIXELSIZE_8BIT}},
278/* Generated mode : "800x600-70" */
279 {
280 "800x600-70", {
281 44899, 800, 600, 24, 168, 208, 1008, 9, 21, 36,
282 636, 800, 0, 8,
283 PM3VideoControl_ENABLE |
284 PM3VideoControl_HSYNC_ACTIVE_HIGH
285 |
286 PM3VideoControl_VSYNC_ACTIVE_LOW
287 | PM3VideoControl_PIXELSIZE_8BIT}},
288/* Generated mode : "800x600-72" */
289 {
290 "800x600-72", {
291 50000, 800, 600, 56, 176, 240, 1040, 37, 43, 66,
292 666, 800, 0, 8,
293 PM3VideoControl_ENABLE |
294 PM3VideoControl_HSYNC_ACTIVE_HIGH
295 |
296 PM3VideoControl_VSYNC_ACTIVE_HIGH
297 | PM3VideoControl_PIXELSIZE_8BIT}},
298/* Generated mode : "800x600-75" */
299 {
300 "800x600-75", {
301 49497, 800, 600, 16, 96, 256, 1056, 1, 4, 25, 625,
302 800, 0, 8,
303 PM3VideoControl_ENABLE |
304 PM3VideoControl_HSYNC_ACTIVE_HIGH
305 |
306 PM3VideoControl_VSYNC_ACTIVE_HIGH
307 | PM3VideoControl_PIXELSIZE_8BIT}},
308/* Generated mode : "800x600-90" */
309 {
310 "800x600-90", {
311 56637, 800, 600, 8, 72, 192, 992, 8, 19, 35, 635,
312 800, 0, 8,
313 PM3VideoControl_ENABLE |
314 PM3VideoControl_HSYNC_ACTIVE_HIGH
315 |
316 PM3VideoControl_VSYNC_ACTIVE_HIGH
317 | PM3VideoControl_PIXELSIZE_8BIT}},
318/* Generated mode : "800x600-100", from /etc/fb.modes */
319/* DISABLED, hsstart == 0
320 {
321 "800x600-100", {
322 67499, 800, 600, 0, 64, 280, 1080, 7, 11, 25, 625,
323 800, 0, 8,
324 PM3VideoControl_ENABLE |
325 PM3VideoControl_HSYNC_ACTIVE_HIGH
326 |
327 PM3VideoControl_VSYNC_ACTIVE_HIGH
328 | PM3VideoControl_PIXELSIZE_8BIT}},
329*/
330/* Generated mode : "800x600-100", from ??? */
331 {
332 "800x600-100", {
333 69650, 800, 600, 64, 128, 288, 1088, 4, 10, 40, 640, 800, 0, 8,
334 PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_LOW|
335 PM3VideoControl_VSYNC_ACTIVE_LOW|PM3VideoControl_PIXELSIZE_8BIT}},
336/* Generated mode : "1024x768-43-lace" */
337/* INTERLACED NOT SUPPORTED
338 {"1024x768-43-lace", {44899, 1024, 768, 8, 184, 240, 1264, 1, 9, 49, 817, 1024, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}},
339 INTERLACED NOT SUPPORTED */
340/* Generated mode : "1024x768-60" */
341 {
342 "1024x768-60", {
343 64998, 1024, 768, 24, 160, 320, 1344, 3, 9, 38,
344 806, 1024, 0, 8,
345 PM3VideoControl_ENABLE |
346 PM3VideoControl_HSYNC_ACTIVE_LOW
347 |
348 PM3VideoControl_VSYNC_ACTIVE_LOW
349 | PM3VideoControl_PIXELSIZE_8BIT}},
350/* Generated mode : "1024x768-70" */
351 {
352 "1024x768-70", {
353 74996, 1024, 768, 24, 160, 304, 1328, 3, 9, 38,
354 806, 1024, 0, 8,
355 PM3VideoControl_ENABLE |
356 PM3VideoControl_HSYNC_ACTIVE_LOW
357 |
358 PM3VideoControl_VSYNC_ACTIVE_LOW
359 | PM3VideoControl_PIXELSIZE_8BIT}},
360/* Generated mode : "1024x768-72" */
361 {
362 "1024x768-72", {
363 74996, 10224, 768, 24, 160, 264, 10488, 3, 9, 38,
364 806, 10224, 0, 8,
365 PM3VideoControl_ENABLE |
366 PM3VideoControl_HSYNC_ACTIVE_LOW
367 |
368 PM3VideoControl_VSYNC_ACTIVE_LOW
369 | PM3VideoControl_PIXELSIZE_8BIT}},
370/* Generated mode : "1024x768-75" */
371 {
372 "1024x768-75", {
373 78746, 1024, 768, 16, 112, 288, 1312, 1, 4, 32,
374 800, 1024, 0, 8,
375 PM3VideoControl_ENABLE |
376 PM3VideoControl_HSYNC_ACTIVE_HIGH
377 |
378 PM3VideoControl_VSYNC_ACTIVE_HIGH
379 | PM3VideoControl_PIXELSIZE_8BIT}},
380/* Generated mode : "1024x768-90" */
381 {
382 "1024x768-90", {
383 100000, 1024, 768, 0, 96, 288, 1312, 21, 36, 77,
384 845, 1024, 0, 8,
385 PM3VideoControl_ENABLE |
386 PM3VideoControl_HSYNC_ACTIVE_LOW
387 |
388 PM3VideoControl_VSYNC_ACTIVE_LOW
389 | PM3VideoControl_PIXELSIZE_8BIT}},
390/* Generated mode : "1024x768-100", from /etc/fb.modes */
391/* DISABLED, vsstart == 0
392 {
393 "1024x768-100", {
394 109998, 1024, 768, 0, 88, 368, 1392, 0, 8, 24, 792,
395 1024, 0, 8,
396 PM3VideoControl_ENABLE |
397 PM3VideoControl_HSYNC_ACTIVE_LOW
398 |
399 PM3VideoControl_VSYNC_ACTIVE_LOW
400 | PM3VideoControl_PIXELSIZE_8BIT}},
401*/
402/* Generated mode : "1024x768-100", from ??? */
403 {
404 "1024x768-100", {
405 115500, 1024, 768, 32, 224, 416, 1440, 3, 13, 34, 802, 1024, 0, 8,
406 PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_LOW|
407 PM3VideoControl_VSYNC_ACTIVE_LOW|PM3VideoControl_PIXELSIZE_8BIT}},
408/* Generated mode : "1152x864-43-lace" */
409/* INTERLACED NOT SUPPORTED
410 {"1152x864-43-lace", {64998, 1152, 864, 72, 200, 264, 1416, 78, 87, 191, 1055, 1152, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}},
411 INTERLACED NOT SUPPORTED */
412/* Generated mode : "1152x864-47-lace" */
413/* INTERLACED NOT SUPPORTED
414 {"1152x864-47-lace", {64998, 1152, 864, 88, 216, 296, 1448, 30, 39, 83, 947, 1152, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}},
415 INTERLACED NOT SUPPORTED */
416/* Generated mode : "1152x864-60" */
417 {
418 "1152x864-60", {
419 80000, 1152, 864, 64, 176, 304, 1456, 6, 11, 52,
420 916, 1152, 0, 8,
421 PM3VideoControl_ENABLE |
422 PM3VideoControl_HSYNC_ACTIVE_HIGH
423 |
424 PM3VideoControl_VSYNC_ACTIVE_HIGH
425 | PM3VideoControl_PIXELSIZE_8BIT}},
426/* Generated mode : "1152x864-70" */
427 {
428 "1152x864-70", {
429 100000, 1152, 864, 40, 192, 360, 1512, 13, 24, 81,
430 945, 1152, 0, 8,
431 PM3VideoControl_ENABLE |
432 PM3VideoControl_HSYNC_ACTIVE_HIGH
433 |
434 PM3VideoControl_VSYNC_ACTIVE_HIGH
435 | PM3VideoControl_PIXELSIZE_8BIT}},
436/* Generated mode : "1152x864-75" */
437 {
438 "1152x864-75", {
439 109998, 1152, 864, 24, 168, 312, 1464, 45, 53, 138,
440 1002, 1152, 0, 8,
441 PM3VideoControl_ENABLE |
442 PM3VideoControl_HSYNC_ACTIVE_HIGH
443 |
444 PM3VideoControl_VSYNC_ACTIVE_HIGH
445 | PM3VideoControl_PIXELSIZE_8BIT}},
446/* Generated mode : "1152x864-80" */
447 {
448 "1152x864-80", {
449 109998, 1152, 864, 16, 128, 288, 1440, 30, 37, 94,
450 958, 1152, 0, 8,
451 PM3VideoControl_ENABLE |
452 PM3VideoControl_HSYNC_ACTIVE_HIGH
453 |
454 PM3VideoControl_VSYNC_ACTIVE_HIGH
455 | PM3VideoControl_PIXELSIZE_8BIT}},
456/* Generated mode : "1280x1024-43-lace" */
457/* INTERLACED NOT SUPPORTED
458 {"1280x1024-43-lace", {80000, 1024, 1024, 80, 160, 320, 1344, 50, 60, 125, 1149, 1024, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}},
459 INTERLACED NOT SUPPORTED */
460/* Generated mode : "1280x1024-47-lace" */
461/* INTERLACED NOT SUPPORTED
462 {"1280x1024-47-lace", {80000, 1280, 1024, 80, 160, 320, 1600, 1, 11, 29, 1053, 1280, 0, 8, PM3VideoControl_ENABLE|PM3VideoControl_HSYNC_ACTIVE_HIGH|PM3VideoControl_VSYNC_ACTIVE_HIGH|PM3VideoControl_PIXELSIZE_8BIT}},
463 INTERLACED NOT SUPPORTED */
464/* Generated mode : "1280x1024-60" */
465 {
466 "1280x1024-60", {
467 107991, 1280, 1024, 48, 160, 408, 1688, 1, 4, 42,
468 1066, 1280, 0, 8,
469 PM3VideoControl_ENABLE |
470 PM3VideoControl_HSYNC_ACTIVE_HIGH
471 |
472 PM3VideoControl_VSYNC_ACTIVE_HIGH
473 | PM3VideoControl_PIXELSIZE_8BIT}},
474/* Generated mode : "1280x1024-70" */
475 {
476 "1280x1024-70", {
477 125992, 1280, 1024, 80, 192, 408, 1688, 1, 6, 42,
478 1066, 1280, 0, 8,
479 PM3VideoControl_ENABLE |
480 PM3VideoControl_HSYNC_ACTIVE_HIGH
481 |
482 PM3VideoControl_VSYNC_ACTIVE_HIGH
483 | PM3VideoControl_PIXELSIZE_8BIT}},
484/* Generated mode : "1280x1024-74" */
485 {
486 "1280x1024-74", {
487 134989, 1280, 1024, 32, 176, 432, 1712, 0, 30, 40,
488 1064, 1280, 0, 8,
489 PM3VideoControl_ENABLE |
490 PM3VideoControl_HSYNC_ACTIVE_HIGH
491 |
492 PM3VideoControl_VSYNC_ACTIVE_HIGH
493 | PM3VideoControl_PIXELSIZE_8BIT}},
494/* Generated mode : "1280x1024-75" */
495 {
496 "1280x1024-75", {
497 134989, 1280, 1024, 16, 160, 408, 1688, 1, 4, 42,
498 1066, 1280, 0, 8,
499 PM3VideoControl_ENABLE |
500 PM3VideoControl_HSYNC_ACTIVE_HIGH
501 |
502 PM3VideoControl_VSYNC_ACTIVE_HIGH
503 | PM3VideoControl_PIXELSIZE_8BIT}},
504/* Generated mode : "1600x1200-60" */
505 {
506 "1600x1200-60", {
507 155981, 1600, 1200, 32, 192, 448, 2048, 10, 18, 70,
508 1270, 1600, 0, 8,
509 PM3VideoControl_ENABLE |
510 PM3VideoControl_HSYNC_ACTIVE_LOW
511 |
512 PM3VideoControl_VSYNC_ACTIVE_LOW
513 | PM3VideoControl_PIXELSIZE_8BIT}},
514/* Generated mode : "1600x1200-66" */
515 {
516 "1600x1200-66", {
517 171998, 1600, 1200, 40, 176, 480, 2080, 3, 6, 53,
518 1253, 1600, 0, 8,
519 PM3VideoControl_ENABLE |
520 PM3VideoControl_HSYNC_ACTIVE_LOW
521 |
522 PM3VideoControl_VSYNC_ACTIVE_LOW
523 | PM3VideoControl_PIXELSIZE_8BIT}},
524/* Generated mode : "1600x1200-76" */
525 {
526 "1600x1200-76", {
527 197980, 1600, 1200, 40, 176, 480, 2080, 3, 8, 50,
528 1250, 1600, 0, 8,
529 PM3VideoControl_ENABLE |
530 PM3VideoControl_HSYNC_ACTIVE_LOW
531 |
532 PM3VideoControl_VSYNC_ACTIVE_LOW
533 | PM3VideoControl_PIXELSIZE_8BIT}},
534/* ##### end of auto-generated mode */
535 {
536 "\0",}
537};
538
539/* more mandatory stuff (see skeletonfb.c + framebuffer driver HOWTO */
540static struct pm3fb_info fb_info[PM3_MAX_BOARD];
541static struct pm3fb_par current_par[PM3_MAX_BOARD];
542static int current_par_valid[PM3_MAX_BOARD];
543/* to allow explicit filtering of board */
544short bus[PM3_MAX_BOARD];
545short slot[PM3_MAX_BOARD];
546short func[PM3_MAX_BOARD];
547short disable[PM3_MAX_BOARD];
548short noaccel[PM3_MAX_BOARD];
549char fontn[PM3_MAX_BOARD][PM3_FONTNAME_SIZE];
550short depth[PM3_MAX_BOARD];
551short flatpanel[PM3_MAX_BOARD];
552static struct display disp[PM3_MAX_BOARD];
553static char g_options[PM3_OPTIONS_SIZE] __initdata = "pm3fb,dummy";
554short printtimings = 0;
555short forcesize[PM3_MAX_BOARD];
556
557/* ********************* */
558/* ***** prototype ***** */
559/* ********************* */
560/* card-specific */
561static void pm3fb_j2000_setup(struct pm3fb_info *l_fb_info);
562/* permedia3-specific */
563static pm3fb_timing_result pm3fb_preserve_memory_timings(struct pm3fb_info *l_fb_info);
564static pm3fb_timing_result pm3fb_try_memory_timings(struct pm3fb_info *l_fb_info);
565static void pm3fb_write_memory_timings(struct pm3fb_info *l_fb_info);
566static unsigned long pm3fb_read_dac_reg(struct pm3fb_info *l_fb_info,
567 unsigned long r);
568static unsigned long pm3fb_CalculateClock(struct pm3fb_info *l_fb_info, unsigned long reqclock, /* In kHz units */
569 unsigned long refclock, /* In kHz units */
570 unsigned char *prescale, /* ClkPreScale */
571 unsigned char *feedback, /* ClkFeedBackScale */
572 unsigned char *postscale
573 /* ClkPostScale */ );
574static void pm3fb_clear_memory(struct pm3fb_info *l_fb_info, u32 cc);
575static void pm3fb_clear_colormap(struct pm3fb_info *l_fb_info, unsigned char r, unsigned char g, unsigned char b);
576static void pm3fb_common_init(struct pm3fb_info *l_fb_info);
577static int pm3fb_Shiftbpp(struct pm3fb_info *l_fb_info,
578 unsigned long depth, int v);
579static int pm3fb_Unshiftbpp(struct pm3fb_info *l_fb_info,
580 unsigned long depth, int v);
581static void pm3fb_mapIO(struct pm3fb_info *l_fb_info);
582static void pm3fb_unmapIO(struct pm3fb_info *l_fb_info);
583#if defined(PM3FB_MASTER_DEBUG) && (PM3FB_MASTER_DEBUG >= 2)
584static void pm3fb_show_cur_mode(struct pm3fb_info *l_fb_info);
585#endif
586static void pm3fb_show_cur_timing(struct pm3fb_info *l_fb_info);
587static void pm3fb_write_mode(struct pm3fb_info *l_fb_info);
588static void pm3fb_read_mode(struct pm3fb_info *l_fb_info,
589 struct pm3fb_par *curpar);
590static unsigned long pm3fb_size_memory(struct pm3fb_info *l_fb_info);
591/* accelerated permedia3-specific */
592#ifdef PM3FB_USE_ACCEL
593static void pm3fb_wait_pm3(struct pm3fb_info *l_fb_info);
594static void pm3fb_init_engine(struct pm3fb_info *l_fb_info);
595#ifdef FBCON_HAS_CFB32
596static void pm3fb_cfb32_clear(struct vc_data *conp,
597 struct display *p,
598 int sy, int sx, int height, int width);
599static void pm3fb_cfb32_clear_margins(struct vc_data *conp,
600 struct display *p, int bottom_only);
601#endif /* FBCON_HAS_CFB32 */
602#ifdef FBCON_HAS_CFB16
603static void pm3fb_cfb16_clear(struct vc_data *conp,
604 struct display *p,
605 int sy, int sx, int height, int width);
606static void pm3fb_cfb16_clear_margins(struct vc_data *conp,
607 struct display *p, int bottom_only);
608#endif /* FBCON_HAS_CFB16 */
609#ifdef FBCON_HAS_CFB8
610static void pm3fb_cfb8_clear(struct vc_data *conp,
611 struct display *p,
612 int sy, int sx, int height, int width);
613static void pm3fb_cfb8_clear_margins(struct vc_data *conp,
614 struct display *p, int bottom_only);
615#endif /* FBCON_HAS_CFB8 */
616#if defined(FBCON_HAS_CFB8) || defined(FBCON_HAS_CFB16) || defined(FBCON_HAS_CFB32)
617static void pm3fb_cfbX_bmove(struct display *p,
618 int sy, int sx,
619 int dy, int dx, int height, int width);
620static void pm3fb_cfbX_putc(struct vc_data *conp, struct display *p,
621 int c, int yy, int xx);
622static void pm3fb_cfbX_putcs(struct vc_data *conp, struct display *p,
623 const unsigned short *s, int count, int yy,
624 int xx);
625static void pm3fb_cfbX_revc(struct display *p, int xx, int yy);
626#endif /* FBCON_HAS_CFB8 || FBCON_HAS_CFB16 || FBCON_HAS_CFB32 */
627#endif /* PM3FB_USE_ACCEL */
628/* pre-init */
629static void pm3fb_mode_setup(char *mode, unsigned long board_num);
630static void pm3fb_pciid_setup(char *pciid, unsigned long board_num);
631static char *pm3fb_boardnum_setup(char *options, unsigned long *bn);
632static void pm3fb_real_setup(char *options);
633/* fbdev */
634static int pm3fb_encode_fix(struct fb_fix_screeninfo *fix,
635 const void *par, struct fb_info_gen *info);
636static int pm3fb_decode_var(const struct fb_var_screeninfo *var,
637 void *par, struct fb_info_gen *info);
638static void pm3fb_encode_depth(struct fb_var_screeninfo *var, long d);
639static int pm3fb_encode_var(struct fb_var_screeninfo *var,
640 const void *par, struct fb_info_gen *info);
641static void pm3fb_get_par(void *par, struct fb_info_gen *info);
642static void pm3fb_set_par(const void *par, struct fb_info_gen *info);
643static void pm3fb_set_color(struct pm3fb_info *l_fb_info,
644 unsigned char regno, unsigned char r,
645 unsigned char g, unsigned char b);
646static int pm3fb_getcolreg(unsigned regno, unsigned *red, unsigned *green,
647 unsigned *blue, unsigned *transp,
648 struct fb_info *info);
649static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green,
650 unsigned blue, unsigned transp,
651 struct fb_info *info);
652static int pm3fb_blank(int blank_mode, struct fb_info_gen *info);
653static void pm3fb_set_disp(const void *par, struct display *disp,
654 struct fb_info_gen *info);
655static void pm3fb_detect(void);
656static int pm3fb_pan_display(const struct fb_var_screeninfo *var,
657 struct fb_info_gen *info);
658static int pm3fb_ioctl(struct fb_info *info, u_int cmd, u_long arg);
659
660
661/* the struct that hold them together */
662struct fbgen_hwswitch pm3fb_switch = {
663 pm3fb_detect, pm3fb_encode_fix, pm3fb_decode_var, pm3fb_encode_var,
664 pm3fb_get_par, pm3fb_set_par, pm3fb_getcolreg,
665 pm3fb_pan_display, pm3fb_blank, pm3fb_set_disp
666};
667 53
668static struct fb_ops pm3fb_ops = { 54/*
669 .owner = THIS_MODULE, 55 * If your driver supports multiple boards, you should make the
670 .fb_get_fix = fbgen_get_fix, 56 * below data types arrays, or allocate them dynamically (using kmalloc()).
671 .fb_get_var = fbgen_get_var, 57 */
672 .fb_set_var = fbgen_set_var,
673 .fb_get_cmap = fbgen_get_cmap,
674 .fb_set_cmap = fbgen_set_cmap,
675 .fb_setcolreg = pm3fb_setcolreg,
676 .fb_pan_display =fbgen_pan_display,
677 .fb_blank = fbgen_blank,
678 .fb_ioctl = pm3fb_ioctl,
679};
680 58
681#ifdef PM3FB_USE_ACCEL 59/*
682#ifdef FBCON_HAS_CFB32 60 * This structure defines the hardware state of the graphics card. Normally
683static struct display_switch pm3fb_cfb32 = { 61 * you place this in a header file in linux/include/video. This file usually
684 fbcon_cfb32_setup, pm3fb_cfbX_bmove, pm3fb_cfb32_clear, 62 * also includes register information. That allows other driver subsystems
685 pm3fb_cfbX_putc, pm3fb_cfbX_putcs, pm3fb_cfbX_revc, 63 * and userland applications the ability to use the same header file to
686 NULL /* cursor() */ , NULL /* set_font() */ , 64 * avoid duplicate work and easy porting of software.
687 pm3fb_cfb32_clear_margins, 65 */
688 FONTWIDTHRANGE(1, 16) /* true only if accelerated... */ 66struct pm3_par {
689}; 67 unsigned char __iomem *v_regs;/* virtual address of p_regs */
690#endif /* FBCON_HAS_CFB32 */ 68 u32 video; /* video flags before blanking */
691#ifdef FBCON_HAS_CFB16 69 u32 base; /* screen base (xoffset+yoffset) in 128 bits unit */
692static struct display_switch pm3fb_cfb16 = { 70 u32 palette[16];
693 fbcon_cfb16_setup, pm3fb_cfbX_bmove, pm3fb_cfb16_clear,
694 pm3fb_cfbX_putc, pm3fb_cfbX_putcs, pm3fb_cfbX_revc,
695 NULL /* cursor() */ , NULL /* set_font() */ ,
696 pm3fb_cfb16_clear_margins,
697 FONTWIDTHRANGE(1, 16) /* true only if accelerated... */
698};
699#endif /* FBCON_HAS_CFB16 */
700#ifdef FBCON_HAS_CFB8
701static struct display_switch pm3fb_cfb8 = {
702 fbcon_cfb8_setup, pm3fb_cfbX_bmove, pm3fb_cfb8_clear,
703 pm3fb_cfbX_putc, pm3fb_cfbX_putcs, pm3fb_cfbX_revc,
704 NULL /* cursor() */ , NULL /* set_font() */ ,
705 pm3fb_cfb8_clear_margins,
706 FONTWIDTHRANGE(1, 16) /* true only if accelerated... */
707};
708#endif /* FBCON_HAS_CFB8 */
709#endif /* PM3FB_USE_ACCEL */
710
711/* ****************************** */
712/* ***** card-specific data ***** */
713/* ****************************** */
714struct pm3fb_card_timings {
715 unsigned long memsize; /* 0 for last value (i.e. default) */
716 struct pm3fb_timings memt;
717}; 71};
718 72
719static struct pm3fb_card_timings t_FormacProFormance3[] = { 73/*
720 { 16, { 0x02e311b8, 0x06100205, 0x08000002, 0x00000079, 0x00000000} }, 74 * Here we define the default structs fb_fix_screeninfo and fb_var_screeninfo
721 { 0, { 0x02e311b8, 0x06100205, 0x08000002, 0x00000079, 0x00000000} } /* from 16 MB PF3 */ 75 * if we don't use modedb. If we do use modedb see pm3fb_init how to use it
76 * to get a fb_var_screeninfo. Otherwise define a default var as well.
77 */
78static struct fb_fix_screeninfo pm3fb_fix __devinitdata = {
79 .id = "Permedia3",
80 .type = FB_TYPE_PACKED_PIXELS,
81 .visual = FB_VISUAL_PSEUDOCOLOR,
82 .xpanstep = 1,
83 .ypanstep = 1,
84 .ywrapstep = 0,
85 .accel = FB_ACCEL_NONE,
722}; 86};
723 87
724static struct pm3fb_card_timings t_AppianJeronimo2000[] = { 88/*
725 { 32, { 0x02e311B8, 0x07424905, 0x0c000003, 0x00000061, 0x00000000} }, 89 * Utility functions
726 { 0, { 0x02e311B8, 0x07424905, 0x0c000003, 0x00000061, 0x00000000} } /* from 32MB J2000 */ 90 */
727};
728 91
729static struct pm3fb_card_timings t_3DLabsOxygenVX1[] = { 92static inline u32 PM3_READ_REG(struct pm3_par *par, s32 off)
730 { 32, { 0x30e311b8, 0x08501204, 0x08000002, 0x0000006b, 0x00000000} }, 93{
731 { 0, { 0x30e311b8, 0x08501204, 0x08000002, 0x0000006b, 0x00000000} } /* from 32MB VX1 */ 94 return fb_readl(par->v_regs + off);
732}; 95}
733 96
734static struct { 97static inline void PM3_WRITE_REG(struct pm3_par *par, s32 off, u32 v)
735 char cardname[32]; /* recognized card name */ 98{
736 u16 subvendor; /* subvendor of the card */ 99 fb_writel(v, par->v_regs + off);
737 u16 subdevice; /* subdevice of the card */ 100}
738 u8 func; /* function of the card to which the extra init apply */
739 void (*specific_setup)(struct pm3fb_info *l_fb_info); /* card/func specific setup, done before _any_ FB access */
740 struct pm3fb_card_timings *c_memt; /* defauls timings for the boards */
741} cardbase[] = {
742 { "Unknown Permedia3 board", 0xFFFF, 0xFFFF, 0xFF, NULL, NULL },
743 { "Appian Jeronimo 2000 head 1", 0x1097, 0x3d32, 1, NULL,
744 t_AppianJeronimo2000
745 },
746 { "Appian Jeronimo 2000 head 2", 0x1097, 0x3d32, 2, pm3fb_j2000_setup,
747 t_AppianJeronimo2000
748 },
749 { "Formac ProFormance 3", PCI_VENDOR_ID_3DLABS, 0x000a, 0, NULL, /* Formac use 3DLabs ID ?!? */
750 t_FormacProFormance3
751 },
752 { "3DLabs Permedia3 Create!", PCI_VENDOR_ID_3DLABS, 0x0127, 0, NULL, NULL },
753 { "3DLabs Oxygen VX1 PCI", PCI_VENDOR_ID_3DLABS, 0x0121, 0, NULL,
754 t_3DLabsOxygenVX1
755 },
756 { "3DLabs Oxygen VX1 AGP", PCI_VENDOR_ID_3DLABS, 0x0125, 0, NULL, NULL },
757 { "3DLabs Oxygen VX1-16 AGP", PCI_VENDOR_ID_3DLABS, 0x0140, 0, NULL, NULL },
758 { "3DLabs Oxygen VX1-1600SW PCI", PCI_VENDOR_ID_3DLABS, 0x0800, 0, NULL, NULL },
759 { "\0", 0x0, 0x0, 0, NULL, NULL }
760};
761 101
762/* ********************************** */ 102static inline void PM3_WAIT(struct pm3_par *par, u32 n)
763/* ***** card-specific function ***** */ 103{
764/* ********************************** */ 104 while (PM3_READ_REG(par, PM3InFIFOSpace) < n);
765static void pm3fb_j2000_setup(struct pm3fb_info *l_fb_info)
766{ /* the appian j2000 require more initialization of the second head */
767 /* l_fb_info must point to the _second_ head of the J2000 */
768
769 DTRACE;
770
771 l_fb_info->memt = t_AppianJeronimo2000[0].memt; /* 32 MB, first and only j2000 ? */
772
773 pm3fb_write_memory_timings(l_fb_info);
774} 105}
775 106
776/* *************************************** */ 107static inline void PM3_SLOW_WRITE_REG(struct pm3_par *par, s32 off, u32 v)
777/* ***** permedia3-specific function ***** */
778/* *************************************** */
779static pm3fb_timing_result pm3fb_preserve_memory_timings(struct pm3fb_info *l_fb_info)
780{ 108{
781 l_fb_info->memt.caps = PM3_READ_REG(PM3LocalMemCaps); 109 if (par->v_regs) {
782 l_fb_info->memt.timings = PM3_READ_REG(PM3LocalMemTimings); 110 mb();
783 l_fb_info->memt.control = PM3_READ_REG(PM3LocalMemControl); 111 PM3_WAIT(par, 1);
784 l_fb_info->memt.refresh = PM3_READ_REG(PM3LocalMemRefresh); 112 wmb();
785 l_fb_info->memt.powerdown = PM3_READ_REG(PM3LocalMemPowerDown); 113 PM3_WRITE_REG(par, off, v);
786
787 if ((l_fb_info->memt.caps == PM3FB_UNKNOWN_TIMING_VALUE) ||
788 (l_fb_info->memt.timings == PM3FB_UNKNOWN_TIMING_VALUE) ||
789 (l_fb_info->memt.control == PM3FB_UNKNOWN_TIMING_VALUE) ||
790 (l_fb_info->memt.refresh == PM3FB_UNKNOWN_TIMING_VALUE) ||
791 (l_fb_info->memt.powerdown == PM3FB_UNKNOWN_TIMING_VALUE))
792 {
793 printk(KERN_ERR "pm3fb: invalid memory timings in permedia3 board #%ld\n", l_fb_info->board_num);
794 return(pm3fb_try_memory_timings(l_fb_info));
795 } 114 }
796 return(pm3fb_timing_ok);
797} 115}
798 116
799static pm3fb_timing_result pm3fb_try_memory_timings(struct pm3fb_info *l_fb_info) 117static inline void PM3_SET_INDEX(struct pm3_par *par, unsigned index)
800{ 118{
801 if (cardbase[l_fb_info->board_type].c_memt) 119 PM3_SLOW_WRITE_REG(par, PM3RD_IndexHigh, (index >> 8) & 0xff);
802 { 120 PM3_SLOW_WRITE_REG(par, PM3RD_IndexLow, index & 0xff);
803 int i = 0, done = 0; 121}
804 while (!done) 122
805 { 123static inline void PM3_WRITE_DAC_REG(struct pm3_par *par, unsigned r, u8 v)
806 if ((cardbase[l_fb_info->board_type].c_memt[i].memsize == l_fb_info->fb_size) 124{
807 || !(cardbase[l_fb_info->board_type].c_memt[i].memsize)) 125 PM3_SET_INDEX(par, r);
808 { /* will use the 0-sized timings by default */ 126 wmb();
809 done = 1; 127 PM3_WRITE_REG(par, PM3RD_IndexedData, v);
810 l_fb_info->memt = cardbase[l_fb_info->board_type].c_memt[i].memt;
811 printk(KERN_WARNING "pm3fb: trying to use predefined memory timings for permedia3 board #%ld (%s, %ld MB)\n",
812 l_fb_info->board_num,
813 cardbase[l_fb_info->board_type].cardname,
814 cardbase[l_fb_info->board_type].c_memt[i].memsize);
815 pm3fb_write_memory_timings(l_fb_info);
816 return(pm3fb_timing_retry);
817 }
818 i++;
819 }
820 } else
821 return(pm3fb_timing_problem);
822 return(pm3fb_timing_ok);
823} 128}
824 129
825static void pm3fb_write_memory_timings(struct pm3fb_info *l_fb_info) 130static inline void pm3fb_set_color(struct pm3_par *par, unsigned char regno,
131 unsigned char r, unsigned char g, unsigned char b)
826{ 132{
827 unsigned char m, n, p; 133 PM3_SLOW_WRITE_REG(par, PM3RD_PaletteWriteAddress, regno);
828 unsigned long clockused; 134 PM3_SLOW_WRITE_REG(par, PM3RD_PaletteData, r);
829 135 PM3_SLOW_WRITE_REG(par, PM3RD_PaletteData, g);
830 PM3_SLOW_WRITE_REG(PM3LocalMemCaps, l_fb_info->memt.caps); 136 PM3_SLOW_WRITE_REG(par, PM3RD_PaletteData, b);
831 PM3_SLOW_WRITE_REG(PM3LocalMemTimings, l_fb_info->memt.timings);
832 PM3_SLOW_WRITE_REG(PM3LocalMemControl, l_fb_info->memt.control);
833 PM3_SLOW_WRITE_REG(PM3LocalMemRefresh, l_fb_info->memt.refresh);
834 PM3_SLOW_WRITE_REG(PM3LocalMemPowerDown, l_fb_info->memt.powerdown);
835
836 clockused =
837 pm3fb_CalculateClock(l_fb_info, 2 * 105000, PM3_REF_CLOCK, &m,
838 &n, &p);
839
840 PM3_WRITE_DAC_REG(PM3RD_KClkPreScale, m);
841 PM3_WRITE_DAC_REG(PM3RD_KClkFeedbackScale, n);
842 PM3_WRITE_DAC_REG(PM3RD_KClkPostScale, p);
843 PM3_WRITE_DAC_REG(PM3RD_KClkControl,
844 PM3RD_KClkControl_STATE_RUN |
845 PM3RD_KClkControl_SOURCE_PLL |
846 PM3RD_KClkControl_ENABLE);
847 PM3_WRITE_DAC_REG(PM3RD_MClkControl,
848 PM3RD_MClkControl_STATE_RUN |
849 PM3RD_MClkControl_SOURCE_KCLK |
850 PM3RD_MClkControl_ENABLE);
851 PM3_WRITE_DAC_REG(PM3RD_SClkControl,
852 PM3RD_SClkControl_STATE_RUN |
853 PM3RD_SClkControl_SOURCE_PCLK |
854 PM3RD_SClkControl_ENABLE);
855} 137}
856 138
857static unsigned long pm3fb_read_dac_reg(struct pm3fb_info *l_fb_info, 139static void pm3fb_clear_colormap(struct pm3_par *par,
858 unsigned long r) 140 unsigned char r, unsigned char g, unsigned char b)
859{ 141{
860 DASSERT((l_fb_info->vIOBase != (unsigned char *) (-1)), 142 int i;
861 "l_fb_info->vIOBase mapped in read dac reg\n"); 143
862 PM3_SET_INDEX(r); 144 for (i = 0; i < 256 ; i++) /* fill color map with white */
863 mb(); 145 pm3fb_set_color(par, i, r, g, b);
864 return (PM3_READ_REG(PM3RD_IndexedData)); 146
865} 147}
866 148
867/* Calculating various clock parameter */ 149/* Calculating various clock parameter */
868static unsigned long pm3fb_CalculateClock(struct pm3fb_info *l_fb_info, unsigned long reqclock, /* In kHz units */ 150static void pm3fb_calculate_clock(unsigned long reqclock,
869 unsigned long refclock, /* In kHz units */ 151 unsigned char *prescale,
870 unsigned char *prescale, /* ClkPreScale */ 152 unsigned char *feedback,
871 unsigned char *feedback, /* ClkFeedBackScale */ 153 unsigned char *postscale)
872 unsigned char *postscale
873 /* ClkPostScale */ )
874{ 154{
875 int f, pre, post; 155 int f, pre, post;
876 unsigned long freq; 156 unsigned long freq;
877 long freqerr = 1000; 157 long freqerr = 1000;
878 unsigned long actualclock = 0; 158 long currerr;
879
880 DTRACE;
881 159
882 for (f = 1; f < 256; f++) { 160 for (f = 1; f < 256; f++) {
883 for (pre = 1; pre < 256; pre++) { 161 for (pre = 1; pre < 256; pre++) {
884 for (post = 0; post < 5; post++) { 162 for (post = 0; post < 5; post++) {
885 freq = 163 freq = ((2*PM3_REF_CLOCK * f) >> post) / pre;
886 ((2 * refclock * f) / 164 currerr = (reqclock > freq)
887 (pre * (1 << post))); 165 ? reqclock - freq
888 if ((reqclock > freq - freqerr) 166 : freq - reqclock;
889 && (reqclock < freq + freqerr)) { 167 if (currerr < freqerr) {
890 freqerr = 168 freqerr = currerr;
891 (reqclock >
892 freq) ? reqclock -
893 freq : freq - reqclock;
894 *feedback = f; 169 *feedback = f;
895 *prescale = pre; 170 *prescale = pre;
896 *postscale = post; 171 *postscale = post;
897 actualclock = freq;
898 } 172 }
899 } 173 }
900 } 174 }
901 } 175 }
902
903 return (actualclock);
904} 176}
905 177
906static int pm3fb_Shiftbpp(struct pm3fb_info *l_fb_info, 178static inline int pm3fb_shift_bpp(unsigned long depth, int v)
907 unsigned long depth, int v)
908{ 179{
909 DTRACE;
910
911 switch (depth) { 180 switch (depth) {
912 case 8: 181 case 8:
913 return (v >> 4); 182 return (v >> 4);
@@ -918,181 +187,59 @@ static int pm3fb_Shiftbpp(struct pm3fb_info *l_fb_info,
918 case 32: 187 case 32:
919 return (v >> 2); 188 return (v >> 2);
920 } 189 }
921 DPRINTK(1, "Unsupported depth %ld\n", depth); 190 DPRINTK("Unsupported depth %ld\n", depth);
922 return (0); 191 return 0;
923}
924
925static int pm3fb_Unshiftbpp(struct pm3fb_info *l_fb_info,
926 unsigned long depth, int v)
927{
928 DTRACE;
929
930 switch (depth) {
931 case 8:
932 return (v << 4);
933 case 12:
934 case 15:
935 case 16:
936 return (v << 3);
937 case 32:
938 return (v << 2);
939 }
940 DPRINTK(1, "Unsupported depth %ld\n", depth);
941 return (0);
942}
943
944static void pm3fb_mapIO(struct pm3fb_info *l_fb_info)
945{
946 DTRACE;
947
948 l_fb_info->vIOBase =
949 ioremap((unsigned long) l_fb_info->pIOBase, PM3_REGS_SIZE);
950 l_fb_info->v_fb =
951 ioremap((unsigned long) l_fb_info->p_fb, l_fb_info->fb_size);
952 DPRINTK(2, "IO mapping : IOBase %lx / %lx, fb %lx / %lx\n",
953 (unsigned long) l_fb_info->pIOBase,
954 (unsigned long) l_fb_info->vIOBase,
955 (unsigned long) l_fb_info->p_fb,
956 (unsigned long) l_fb_info->v_fb);
957}
958
959static void pm3fb_unmapIO(struct pm3fb_info *l_fb_info)
960{
961 DTRACE;
962
963 iounmap(l_fb_info->vIOBase);
964 iounmap(l_fb_info->v_fb);
965 l_fb_info->vIOBase = (unsigned char *) -1;
966 l_fb_info->v_fb = (unsigned char *) -1;
967}
968
969#if defined(PM3FB_MASTER_DEBUG) && (PM3FB_MASTER_DEBUG >= 2)
970static void pm3fb_show_cur_mode(struct pm3fb_info *l_fb_info)
971{
972 DPRINTK(2, "PM3Aperture0: 0x%08x\n", PM3_READ_REG(PM3Aperture0));
973 DPRINTK(2, "PM3Aperture1: 0x%08x\n", PM3_READ_REG(PM3Aperture1));
974 DPRINTK(2, "PM3ByAperture1Mode: 0x%08x\n",
975 PM3_READ_REG(PM3ByAperture1Mode));
976 DPRINTK(2, "PM3ByAperture2Mode: 0x%08x\n",
977 PM3_READ_REG(PM3ByAperture2Mode));
978 DPRINTK(2, "PM3ChipConfig: 0x%08x\n", PM3_READ_REG(PM3ChipConfig));
979 DPRINTK(2, "PM3FIFODis: 0x%08x\n", PM3_READ_REG(PM3FIFODis));
980 DPRINTK(2, "PM3HTotal: 0x%08x\n", PM3_READ_REG(PM3HTotal));
981 DPRINTK(2, "PM3HbEnd: 0x%08x\n", PM3_READ_REG(PM3HbEnd));
982 DPRINTK(2, "PM3HgEnd: 0x%08x\n", PM3_READ_REG(PM3HgEnd));
983 DPRINTK(2, "PM3HsEnd: 0x%08x\n", PM3_READ_REG(PM3HsEnd));
984 DPRINTK(2, "PM3HsStart: 0x%08x\n", PM3_READ_REG(PM3HsStart));
985 DPRINTK(2, "PM3MemBypassWriteMask: 0x%08x\n",
986 PM3_READ_REG(PM3MemBypassWriteMask));
987 DPRINTK(2, "PM3RD_IndexControl: 0x%08x\n",
988 PM3_READ_REG(PM3RD_IndexControl));
989 DPRINTK(2, "PM3ScreenBase: 0x%08x\n", PM3_READ_REG(PM3ScreenBase));
990 DPRINTK(2, "PM3ScreenStride: 0x%08x\n",
991 PM3_READ_REG(PM3ScreenStride));
992 DPRINTK(2, "PM3VClkCtl: 0x%08x\n", PM3_READ_REG(PM3VClkCtl));
993 DPRINTK(2, "PM3VTotal: 0x%08x\n", PM3_READ_REG(PM3VTotal));
994 DPRINTK(2, "PM3VbEnd: 0x%08x\n", PM3_READ_REG(PM3VbEnd));
995 DPRINTK(2, "PM3VideoControl: 0x%08x\n",
996 PM3_READ_REG(PM3VideoControl));
997 DPRINTK(2, "PM3VsEnd: 0x%08x\n", PM3_READ_REG(PM3VsEnd));
998 DPRINTK(2, "PM3VsStart: 0x%08x\n", PM3_READ_REG(PM3VsStart));
999
1000 DPRINTK(2, "PM3RD_ColorFormat: %ld\n",
1001 PM3_READ_DAC_REG(PM3RD_ColorFormat));
1002 DPRINTK(2, "PM3RD_DACControl: %ld\n",
1003 PM3_READ_DAC_REG(PM3RD_DACControl));
1004 DPRINTK(2, "PM3RD_DClk0FeedbackScale: %ld\n",
1005 PM3_READ_DAC_REG(PM3RD_DClk0FeedbackScale));
1006 DPRINTK(2, "PM3RD_DClk0PostScale: %ld\n",
1007 PM3_READ_DAC_REG(PM3RD_DClk0PostScale));
1008 DPRINTK(2, "PM3RD_DClk0PreScale: %ld\n",
1009 PM3_READ_DAC_REG(PM3RD_DClk0PreScale));
1010 DPRINTK(2, "[not set] PM3RD_IndexControl: %ld\n",
1011 PM3_READ_DAC_REG(PM3RD_IndexControl));
1012 DPRINTK(2, "PM3RD_MiscControl: %ld\n",
1013 PM3_READ_DAC_REG(PM3RD_MiscControl));
1014 DPRINTK(2, "PM3RD_PixelSize: %ld\n",
1015 PM3_READ_DAC_REG(PM3RD_PixelSize));
1016 DPRINTK(2, "PM3RD_SyncControl: %ld\n",
1017 PM3_READ_DAC_REG(PM3RD_SyncControl));
1018}
1019
1020#endif /* defined(PM3FB_MASTER_DEBUG) && (PM3FB_MASTER_DEBUG >= 2) */
1021static void pm3fb_show_cur_timing(struct pm3fb_info *l_fb_info)
1022{
1023 u16 subvendor, subdevice;
1024
1025 if ((!pci_read_config_word
1026 (l_fb_info->dev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor))
1027 &&
1028 (!pci_read_config_word
1029 (l_fb_info->dev, PCI_SUBSYSTEM_ID, &subdevice))) {
1030 /* well, nothing... */
1031 } else {
1032 subvendor = subdevice = (u16)-1;
1033 }
1034
1035 printk(KERN_INFO "pm3fb: memory timings for board #%ld (subvendor: 0x%hx, subdevice: 0x%hx)\n", l_fb_info->board_num, subvendor, subdevice);
1036 printk(KERN_INFO " PM3LocalMemCaps: 0x%08x\n",
1037 PM3_READ_REG(PM3LocalMemCaps));
1038 printk(KERN_INFO " PM3LocalMemTimings: 0x%08x\n",
1039 PM3_READ_REG(PM3LocalMemTimings));
1040 printk(KERN_INFO " PM3LocalMemControl: 0x%08x\n",
1041 PM3_READ_REG(PM3LocalMemControl));
1042 printk(KERN_INFO " PM3LocalMemRefresh: 0x%08x\n",
1043 PM3_READ_REG(PM3LocalMemRefresh));
1044 printk(KERN_INFO " PM3LocalMemPowerDown: 0x%08x\n",
1045 PM3_READ_REG(PM3LocalMemPowerDown));
1046} 192}
1047 193
1048/* write the mode to registers */ 194/* write the mode to registers */
1049static void pm3fb_write_mode(struct pm3fb_info *l_fb_info) 195static void pm3fb_write_mode(struct fb_info *info)
1050{ 196{
197 struct pm3_par *par = info->par;
1051 char tempsync = 0x00, tempmisc = 0x00; 198 char tempsync = 0x00, tempmisc = 0x00;
1052 DTRACE; 199 const u32 hsstart = info->var.right_margin;
1053 200 const u32 hsend = hsstart + info->var.hsync_len;
1054 PM3_SLOW_WRITE_REG(PM3MemBypassWriteMask, 0xffffffff); 201 const u32 hbend = hsend + info->var.left_margin;
1055 PM3_SLOW_WRITE_REG(PM3Aperture0, 0x00000000); 202 const u32 xres = (info->var.xres + 31) & ~31;
1056 PM3_SLOW_WRITE_REG(PM3Aperture1, 0x00000000); 203 const u32 htotal = xres + hbend;
1057 PM3_SLOW_WRITE_REG(PM3FIFODis, 0x00000007); 204 const u32 vsstart = info->var.lower_margin;
1058 205 const u32 vsend = vsstart + info->var.vsync_len;
1059 PM3_SLOW_WRITE_REG(PM3HTotal, 206 const u32 vbend = vsend + info->var.upper_margin;
1060 pm3fb_Shiftbpp(l_fb_info, 207 const u32 vtotal = info->var.yres + vbend;
1061 l_fb_info->current_par->depth, 208 const u32 width = (info->var.xres_virtual + 7) & ~7;
1062 l_fb_info->current_par->htotal - 209
1063 1)); 210 PM3_SLOW_WRITE_REG(par, PM3MemBypassWriteMask, 0xffffffff);
1064 PM3_SLOW_WRITE_REG(PM3HsEnd, 211 PM3_SLOW_WRITE_REG(par, PM3Aperture0, 0x00000000);
1065 pm3fb_Shiftbpp(l_fb_info, 212 PM3_SLOW_WRITE_REG(par, PM3Aperture1, 0x00000000);
1066 l_fb_info->current_par->depth, 213 PM3_SLOW_WRITE_REG(par, PM3FIFODis, 0x00000007);
1067 l_fb_info->current_par->hsend)); 214
1068 PM3_SLOW_WRITE_REG(PM3HsStart, 215 PM3_SLOW_WRITE_REG(par, PM3HTotal,
1069 pm3fb_Shiftbpp(l_fb_info, 216 pm3fb_shift_bpp(info->var.bits_per_pixel,
1070 l_fb_info->current_par->depth, 217 htotal - 1));
1071 l_fb_info->current_par-> 218 PM3_SLOW_WRITE_REG(par, PM3HsEnd,
219 pm3fb_shift_bpp(info->var.bits_per_pixel,
220 hsend));
221 PM3_SLOW_WRITE_REG(par, PM3HsStart,
222 pm3fb_shift_bpp(info->var.bits_per_pixel,
1072 hsstart)); 223 hsstart));
1073 PM3_SLOW_WRITE_REG(PM3HbEnd, 224 PM3_SLOW_WRITE_REG(par, PM3HbEnd,
1074 pm3fb_Shiftbpp(l_fb_info, 225 pm3fb_shift_bpp(info->var.bits_per_pixel,
1075 l_fb_info->current_par->depth, 226 hbend));
1076 l_fb_info->current_par->hbend)); 227 PM3_SLOW_WRITE_REG(par, PM3HgEnd,
1077 PM3_SLOW_WRITE_REG(PM3HgEnd, 228 pm3fb_shift_bpp(info->var.bits_per_pixel,
1078 pm3fb_Shiftbpp(l_fb_info, 229 hbend));
1079 l_fb_info->current_par->depth, 230 PM3_SLOW_WRITE_REG(par, PM3ScreenStride,
1080 l_fb_info->current_par->hbend)); 231 pm3fb_shift_bpp(info->var.bits_per_pixel,
1081 PM3_SLOW_WRITE_REG(PM3ScreenStride, 232 width));
1082 pm3fb_Shiftbpp(l_fb_info, 233 PM3_SLOW_WRITE_REG(par, PM3VTotal, vtotal - 1);
1083 l_fb_info->current_par->depth, 234 PM3_SLOW_WRITE_REG(par, PM3VsEnd, vsend - 1);
1084 l_fb_info->current_par->stride)); 235 PM3_SLOW_WRITE_REG(par, PM3VsStart, vsstart - 1);
1085 PM3_SLOW_WRITE_REG(PM3VTotal, l_fb_info->current_par->vtotal - 1); 236 PM3_SLOW_WRITE_REG(par, PM3VbEnd, vbend);
1086 PM3_SLOW_WRITE_REG(PM3VsEnd, l_fb_info->current_par->vsend - 1); 237
1087 PM3_SLOW_WRITE_REG(PM3VsStart, 238 switch (info->var.bits_per_pixel) {
1088 l_fb_info->current_par->vsstart - 1);
1089 PM3_SLOW_WRITE_REG(PM3VbEnd, l_fb_info->current_par->vbend);
1090
1091 switch (l_fb_info->current_par->depth) {
1092 case 8: 239 case 8:
1093 PM3_SLOW_WRITE_REG(PM3ByAperture1Mode, 240 PM3_SLOW_WRITE_REG(par, PM3ByAperture1Mode,
1094 PM3ByApertureMode_PIXELSIZE_8BIT); 241 PM3ByApertureMode_PIXELSIZE_8BIT);
1095 PM3_SLOW_WRITE_REG(PM3ByAperture2Mode, 242 PM3_SLOW_WRITE_REG(par, PM3ByAperture2Mode,
1096 PM3ByApertureMode_PIXELSIZE_8BIT); 243 PM3ByApertureMode_PIXELSIZE_8BIT);
1097 break; 244 break;
1098 245
@@ -1100,15 +247,15 @@ static void pm3fb_write_mode(struct pm3fb_info *l_fb_info)
1100 case 15: 247 case 15:
1101 case 16: 248 case 16:
1102#ifndef __BIG_ENDIAN 249#ifndef __BIG_ENDIAN
1103 PM3_SLOW_WRITE_REG(PM3ByAperture1Mode, 250 PM3_SLOW_WRITE_REG(par, PM3ByAperture1Mode,
1104 PM3ByApertureMode_PIXELSIZE_16BIT); 251 PM3ByApertureMode_PIXELSIZE_16BIT);
1105 PM3_SLOW_WRITE_REG(PM3ByAperture2Mode, 252 PM3_SLOW_WRITE_REG(par, PM3ByAperture2Mode,
1106 PM3ByApertureMode_PIXELSIZE_16BIT); 253 PM3ByApertureMode_PIXELSIZE_16BIT);
1107#else 254#else
1108 PM3_SLOW_WRITE_REG(PM3ByAperture1Mode, 255 PM3_SLOW_WRITE_REG(par, PM3ByAperture1Mode,
1109 PM3ByApertureMode_PIXELSIZE_16BIT | 256 PM3ByApertureMode_PIXELSIZE_16BIT |
1110 PM3ByApertureMode_BYTESWAP_BADC); 257 PM3ByApertureMode_BYTESWAP_BADC);
1111 PM3_SLOW_WRITE_REG(PM3ByAperture2Mode, 258 PM3_SLOW_WRITE_REG(par, PM3ByAperture2Mode,
1112 PM3ByApertureMode_PIXELSIZE_16BIT | 259 PM3ByApertureMode_PIXELSIZE_16BIT |
1113 PM3ByApertureMode_BYTESWAP_BADC); 260 PM3ByApertureMode_BYTESWAP_BADC);
1114#endif /* ! __BIG_ENDIAN */ 261#endif /* ! __BIG_ENDIAN */
@@ -1116,23 +263,23 @@ static void pm3fb_write_mode(struct pm3fb_info *l_fb_info)
1116 263
1117 case 32: 264 case 32:
1118#ifndef __BIG_ENDIAN 265#ifndef __BIG_ENDIAN
1119 PM3_SLOW_WRITE_REG(PM3ByAperture1Mode, 266 PM3_SLOW_WRITE_REG(par, PM3ByAperture1Mode,
1120 PM3ByApertureMode_PIXELSIZE_32BIT); 267 PM3ByApertureMode_PIXELSIZE_32BIT);
1121 PM3_SLOW_WRITE_REG(PM3ByAperture2Mode, 268 PM3_SLOW_WRITE_REG(par, PM3ByAperture2Mode,
1122 PM3ByApertureMode_PIXELSIZE_32BIT); 269 PM3ByApertureMode_PIXELSIZE_32BIT);
1123#else 270#else
1124 PM3_SLOW_WRITE_REG(PM3ByAperture1Mode, 271 PM3_SLOW_WRITE_REG(par, PM3ByAperture1Mode,
1125 PM3ByApertureMode_PIXELSIZE_32BIT | 272 PM3ByApertureMode_PIXELSIZE_32BIT |
1126 PM3ByApertureMode_BYTESWAP_DCBA); 273 PM3ByApertureMode_BYTESWAP_DCBA);
1127 PM3_SLOW_WRITE_REG(PM3ByAperture2Mode, 274 PM3_SLOW_WRITE_REG(par, PM3ByAperture2Mode,
1128 PM3ByApertureMode_PIXELSIZE_32BIT | 275 PM3ByApertureMode_PIXELSIZE_32BIT |
1129 PM3ByApertureMode_BYTESWAP_DCBA); 276 PM3ByApertureMode_BYTESWAP_DCBA);
1130#endif /* ! __BIG_ENDIAN */ 277#endif /* ! __BIG_ENDIAN */
1131 break; 278 break;
1132 279
1133 default: 280 default:
1134 DPRINTK(1, "Unsupported depth %d\n", 281 DPRINTK("Unsupported depth %d\n",
1135 l_fb_info->current_par->depth); 282 info->var.bits_per_pixel);
1136 break; 283 break;
1137 } 284 }
1138 285
@@ -1143,95 +290,86 @@ static void pm3fb_write_mode(struct pm3fb_info *l_fb_info)
1143 * sync options in PM3RD_SyncControl. --rmk 290 * sync options in PM3RD_SyncControl. --rmk
1144 */ 291 */
1145 { 292 {
1146 unsigned int video = l_fb_info->current_par->video; 293 unsigned int video = par->video;
1147 294
1148 video &= ~(PM3VideoControl_HSYNC_MASK | 295 video &= ~(PM3VideoControl_HSYNC_MASK |
1149 PM3VideoControl_VSYNC_MASK); 296 PM3VideoControl_VSYNC_MASK);
1150 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH | 297 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
1151 PM3VideoControl_VSYNC_ACTIVE_HIGH; 298 PM3VideoControl_VSYNC_ACTIVE_HIGH;
1152 PM3_SLOW_WRITE_REG(PM3VideoControl, video); 299 PM3_SLOW_WRITE_REG(par, PM3VideoControl, video);
1153 } 300 }
1154 PM3_SLOW_WRITE_REG(PM3VClkCtl, 301 PM3_SLOW_WRITE_REG(par, PM3VClkCtl,
1155 (PM3_READ_REG(PM3VClkCtl) & 0xFFFFFFFC)); 302 (PM3_READ_REG(par, PM3VClkCtl) & 0xFFFFFFFC));
1156 PM3_SLOW_WRITE_REG(PM3ScreenBase, l_fb_info->current_par->base); 303 PM3_SLOW_WRITE_REG(par, PM3ScreenBase, par->base);
1157 PM3_SLOW_WRITE_REG(PM3ChipConfig, 304 PM3_SLOW_WRITE_REG(par, PM3ChipConfig,
1158 (PM3_READ_REG(PM3ChipConfig) & 0xFFFFFFFD)); 305 (PM3_READ_REG(par, PM3ChipConfig) & 0xFFFFFFFD));
1159 306
1160 { 307 {
1161 unsigned char m; /* ClkPreScale */ 308 unsigned char uninitialized_var(m); /* ClkPreScale */
1162 unsigned char n; /* ClkFeedBackScale */ 309 unsigned char uninitialized_var(n); /* ClkFeedBackScale */
1163 unsigned char p; /* ClkPostScale */ 310 unsigned char uninitialized_var(p); /* ClkPostScale */
1164 (void)pm3fb_CalculateClock(l_fb_info, l_fb_info->current_par->pixclock, PM3_REF_CLOCK, &m, &n, &p); 311 unsigned long pixclock = PICOS2KHZ(info->var.pixclock);
1165 312
1166 DPRINTK(2, 313 (void)pm3fb_calculate_clock(pixclock, &m, &n, &p);
1167 "Pixclock: %d, Pre: %d, Feedback: %d, Post: %d\n", 314
1168 l_fb_info->current_par->pixclock, (int) m, (int) n, 315 DPRINTK("Pixclock: %ld, Pre: %d, Feedback: %d, Post: %d\n",
1169 (int) p); 316 pixclock, (int) m, (int) n, (int) p);
1170 317
1171 PM3_WRITE_DAC_REG(PM3RD_DClk0PreScale, m); 318 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PreScale, m);
1172 PM3_WRITE_DAC_REG(PM3RD_DClk0FeedbackScale, n); 319 PM3_WRITE_DAC_REG(par, PM3RD_DClk0FeedbackScale, n);
1173 PM3_WRITE_DAC_REG(PM3RD_DClk0PostScale, p); 320 PM3_WRITE_DAC_REG(par, PM3RD_DClk0PostScale, p);
1174 } 321 }
1175 /* 322 /*
1176 PM3_WRITE_DAC_REG(PM3RD_IndexControl, 0x00); 323 PM3_WRITE_DAC_REG(par, PM3RD_IndexControl, 0x00);
1177 */ 324 */
1178 /* 325 /*
1179 PM3_SLOW_WRITE_REG(PM3RD_IndexControl, 0x00); 326 PM3_SLOW_WRITE_REG(par, PM3RD_IndexControl, 0x00);
1180 */ 327 */
1181 if ((l_fb_info->current_par->video & PM3VideoControl_HSYNC_MASK) == 328 if ((par->video & PM3VideoControl_HSYNC_MASK) ==
1182 PM3VideoControl_HSYNC_ACTIVE_HIGH) 329 PM3VideoControl_HSYNC_ACTIVE_HIGH)
1183 tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH; 330 tempsync |= PM3RD_SyncControl_HSYNC_ACTIVE_HIGH;
1184 if ((l_fb_info->current_par->video & PM3VideoControl_VSYNC_MASK) == 331 if ((par->video & PM3VideoControl_VSYNC_MASK) ==
1185 PM3VideoControl_VSYNC_ACTIVE_HIGH) 332 PM3VideoControl_VSYNC_ACTIVE_HIGH)
1186 tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH; 333 tempsync |= PM3RD_SyncControl_VSYNC_ACTIVE_HIGH;
1187
1188 PM3_WRITE_DAC_REG(PM3RD_SyncControl, tempsync);
1189 DPRINTK(2, "PM3RD_SyncControl: %d\n", tempsync);
1190
1191 if (flatpanel[l_fb_info->board_num])
1192 {
1193 PM3_WRITE_DAC_REG(PM3RD_DACControl, PM3RD_DACControl_BLANK_PEDESTAL_ENABLE);
1194 PM3_WAIT(2);
1195 PM3_WRITE_REG(PM3VSConfiguration, 0x06);
1196 PM3_WRITE_REG(0x5a00, 1 << 14); /* black magic... */
1197 tempmisc = PM3RD_MiscControl_VSB_OUTPUT_ENABLE;
1198 }
1199 else
1200 PM3_WRITE_DAC_REG(PM3RD_DACControl, 0x00);
1201 334
1202 switch (l_fb_info->current_par->depth) { 335 PM3_WRITE_DAC_REG(par, PM3RD_SyncControl, tempsync);
336 DPRINTK("PM3RD_SyncControl: %d\n", tempsync);
337
338 PM3_WRITE_DAC_REG(par, PM3RD_DACControl, 0x00);
339
340 switch (info->var.bits_per_pixel) {
1203 case 8: 341 case 8:
1204 PM3_WRITE_DAC_REG(PM3RD_PixelSize, 342 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
1205 PM3RD_PixelSize_8_BIT_PIXELS); 343 PM3RD_PixelSize_8_BIT_PIXELS);
1206 PM3_WRITE_DAC_REG(PM3RD_ColorFormat, 344 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
1207 PM3RD_ColorFormat_CI8_COLOR | 345 PM3RD_ColorFormat_CI8_COLOR |
1208 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW); 346 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
1209 tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; 347 tempmisc |= PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
1210 break; 348 break;
1211 case 12: 349 case 12:
1212 PM3_WRITE_DAC_REG(PM3RD_PixelSize, 350 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
1213 PM3RD_PixelSize_16_BIT_PIXELS); 351 PM3RD_PixelSize_16_BIT_PIXELS);
1214 PM3_WRITE_DAC_REG(PM3RD_ColorFormat, 352 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
1215 PM3RD_ColorFormat_4444_COLOR | 353 PM3RD_ColorFormat_4444_COLOR |
1216 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW | 354 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
1217 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE); 355 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
1218 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | 356 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
1219 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; 357 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
1220 break; 358 break;
1221 case 15: 359 case 15:
1222 PM3_WRITE_DAC_REG(PM3RD_PixelSize, 360 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
1223 PM3RD_PixelSize_16_BIT_PIXELS); 361 PM3RD_PixelSize_16_BIT_PIXELS);
1224 PM3_WRITE_DAC_REG(PM3RD_ColorFormat, 362 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
1225 PM3RD_ColorFormat_5551_FRONT_COLOR | 363 PM3RD_ColorFormat_5551_FRONT_COLOR |
1226 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW | 364 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
1227 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE); 365 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
1228 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | 366 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
1229 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; 367 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
1230 break; 368 break;
1231 case 16: 369 case 16:
1232 PM3_WRITE_DAC_REG(PM3RD_PixelSize, 370 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
1233 PM3RD_PixelSize_16_BIT_PIXELS); 371 PM3RD_PixelSize_16_BIT_PIXELS);
1234 PM3_WRITE_DAC_REG(PM3RD_ColorFormat, 372 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
1235 PM3RD_ColorFormat_565_FRONT_COLOR | 373 PM3RD_ColorFormat_565_FRONT_COLOR |
1236 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW | 374 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW |
1237 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE); 375 PM3RD_ColorFormat_LINEAR_COLOR_EXT_ENABLE);
@@ -1239,1936 +377,280 @@ static void pm3fb_write_mode(struct pm3fb_info *l_fb_info)
1239 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; 377 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
1240 break; 378 break;
1241 case 32: 379 case 32:
1242 PM3_WRITE_DAC_REG(PM3RD_PixelSize, 380 PM3_WRITE_DAC_REG(par, PM3RD_PixelSize,
1243 PM3RD_PixelSize_32_BIT_PIXELS); 381 PM3RD_PixelSize_32_BIT_PIXELS);
1244 PM3_WRITE_DAC_REG(PM3RD_ColorFormat, 382 PM3_WRITE_DAC_REG(par, PM3RD_ColorFormat,
1245 PM3RD_ColorFormat_8888_COLOR | 383 PM3RD_ColorFormat_8888_COLOR |
1246 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW); 384 PM3RD_ColorFormat_COLOR_ORDER_BLUE_LOW);
1247 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE | 385 tempmisc |= PM3RD_MiscControl_DIRECTCOLOR_ENABLE |
1248 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE; 386 PM3RD_MiscControl_HIGHCOLOR_RES_ENABLE;
1249 break; 387 break;
1250 } 388 }
1251 PM3_WRITE_DAC_REG(PM3RD_MiscControl, tempmisc); 389 PM3_WRITE_DAC_REG(par, PM3RD_MiscControl, tempmisc);
1252
1253 PM3_SHOW_CUR_MODE;
1254} 390}
1255 391
1256static void pm3fb_read_mode(struct pm3fb_info *l_fb_info, 392/*
1257 struct pm3fb_par *curpar) 393 * hardware independent functions
1258{ 394 */
1259 unsigned long pixsize1, pixsize2, clockused; 395int pm3fb_init(void);
1260 unsigned long pre, feedback, post; 396int pm3fb_setup(char*);
1261
1262 DTRACE;
1263
1264 clockused = PM3_READ_REG(PM3VClkCtl);
1265 397
1266 switch (clockused) { 398static int pm3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1267 case 3: 399{
1268 pre = PM3_READ_DAC_REG(PM3RD_DClk3PreScale); 400 u32 lpitch;
1269 feedback = PM3_READ_DAC_REG(PM3RD_DClk3FeedbackScale);
1270 post = PM3_READ_DAC_REG(PM3RD_DClk3PostScale);
1271 401
1272 DPRINTK(2, 402 var->transp.offset = 0;
1273 "DClk3 parameter: Pre: %ld, Feedback: %ld, Post: %ld ; giving pixclock: %ld\n", 403 var->transp.length = 0;
1274 pre, feedback, post, PM3_SCALE_TO_CLOCK(pre, 404 switch(var->bits_per_pixel) {
1275 feedback, 405 case 8:
1276 post)); 406 var->red.length = var->green.length = var->blue.length = 8;
407 var->red.offset = var->green.offset = var->blue.offset = 0;
1277 break; 408 break;
1278 case 2: 409 case 12:
1279 pre = PM3_READ_DAC_REG(PM3RD_DClk2PreScale); 410 var->red.offset = 8;
1280 feedback = PM3_READ_DAC_REG(PM3RD_DClk2FeedbackScale); 411 var->red.length = 4;
1281 post = PM3_READ_DAC_REG(PM3RD_DClk2PostScale); 412 var->green.offset = 4;
1282 413 var->green.length = 4;
1283 DPRINTK(2, 414 var->blue.offset = 0;
1284 "DClk2 parameter: Pre: %ld, Feedback: %ld, Post: %ld ; giving pixclock: %ld\n", 415 var->blue.length = 4;
1285 pre, feedback, post, PM3_SCALE_TO_CLOCK(pre, 416 var->transp.offset = 12;
1286 feedback, 417 var->transp.length = 4;
1287 post)); 418 case 15:
419 var->red.offset = 10;
420 var->red.length = 5;
421 var->green.offset = 5;
422 var->green.length = 5;
423 var->blue.offset = 0;
424 var->blue.length = 5;
425 var->transp.offset = 15;
426 var->transp.length = 1;
1288 break; 427 break;
1289 case 1: 428 case 16:
1290 pre = PM3_READ_DAC_REG(PM3RD_DClk1PreScale); 429 var->red.offset = 11;
1291 feedback = PM3_READ_DAC_REG(PM3RD_DClk1FeedbackScale); 430 var->red.length = 5;
1292 post = PM3_READ_DAC_REG(PM3RD_DClk1PostScale); 431 var->green.offset = 5;
1293 432 var->green.length = 6;
1294 DPRINTK(2, 433 var->blue.offset = 0;
1295 "DClk1 parameter: Pre: %ld, Feedback: %ld, Post: %ld ; giving pixclock: %ld\n", 434 var->blue.length = 5;
1296 pre, feedback, post, PM3_SCALE_TO_CLOCK(pre,
1297 feedback,
1298 post));
1299 break; 435 break;
1300 case 0: 436 case 32:
1301 pre = PM3_READ_DAC_REG(PM3RD_DClk0PreScale); 437 var->transp.offset = 24;
1302 feedback = PM3_READ_DAC_REG(PM3RD_DClk0FeedbackScale); 438 var->transp.length = 8;
1303 post = PM3_READ_DAC_REG(PM3RD_DClk0PostScale); 439 var->red.offset = 16;
1304 440 var->green.offset = 8;
1305 DPRINTK(2, 441 var->blue.offset = 0;
1306 "DClk0 parameter: Pre: %ld, Feedback: %ld, Post: %ld ; giving pixclock: %ld\n", 442 var->red.length = var->green.length = var->blue.length = 8;
1307 pre, feedback, post, PM3_SCALE_TO_CLOCK(pre,
1308 feedback,
1309 post));
1310 break; 443 break;
1311 default: 444 default:
1312 pre = feedback = post = 0; 445 DPRINTK("depth not supported: %u\n", var->bits_per_pixel);
1313 DPRINTK(1, "Unknowk D clock used : %ld\n", clockused); 446 return -EINVAL;
1314 break;
1315 }
1316
1317 curpar->pixclock = PM3_SCALE_TO_CLOCK(pre, feedback, post);
1318
1319 pixsize1 =
1320 PM3ByApertureMode_PIXELSIZE_MASK &
1321 (PM3_READ_REG(PM3ByAperture1Mode));
1322 pixsize2 =
1323 PM3ByApertureMode_PIXELSIZE_MASK &
1324 (PM3_READ_REG(PM3ByAperture2Mode));
1325
1326 DASSERT((pixsize1 == pixsize2),
1327 "pixsize the same in both aperture\n");
1328
1329 if (pixsize1 & PM3ByApertureMode_PIXELSIZE_32BIT)
1330 curpar->depth = 32;
1331 else if (pixsize1 & PM3ByApertureMode_PIXELSIZE_16BIT)
1332 {
1333 curpar->depth = 16;
1334 }
1335 else
1336 curpar->depth = 8;
1337
1338 /* not sure if I need to add one on the next ; it give better result with */
1339 curpar->htotal =
1340 pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
1341 1 + PM3_READ_REG(PM3HTotal));
1342 curpar->hsend =
1343 pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
1344 PM3_READ_REG(PM3HsEnd));
1345 curpar->hsstart =
1346 pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
1347 PM3_READ_REG(PM3HsStart));
1348 curpar->hbend =
1349 pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
1350 PM3_READ_REG(PM3HbEnd));
1351
1352 curpar->stride =
1353 pm3fb_Unshiftbpp(l_fb_info, curpar->depth,
1354 PM3_READ_REG(PM3ScreenStride));
1355
1356 curpar->vtotal = 1 + PM3_READ_REG(PM3VTotal);
1357 curpar->vsend = 1 + PM3_READ_REG(PM3VsEnd);
1358 curpar->vsstart = 1 + PM3_READ_REG(PM3VsStart);
1359 curpar->vbend = PM3_READ_REG(PM3VbEnd);
1360
1361 curpar->video = PM3_READ_REG(PM3VideoControl);
1362
1363 curpar->base = PM3_READ_REG(PM3ScreenBase);
1364 curpar->width = curpar->htotal - curpar->hbend; /* make virtual == displayed resolution */
1365 curpar->height = curpar->vtotal - curpar->vbend;
1366
1367 DPRINTK(2, "Found : %d * %d, %d Khz, stride is %08x\n",
1368 curpar->width, curpar->height, curpar->pixclock,
1369 curpar->stride);
1370}
1371
1372static unsigned long pm3fb_size_memory(struct pm3fb_info *l_fb_info)
1373{
1374 unsigned long memsize = 0, tempBypass, i, temp1, temp2;
1375 u16 subvendor, subdevice;
1376 pm3fb_timing_result ptr;
1377
1378 DTRACE;
1379
1380 l_fb_info->fb_size = 64 * 1024 * 1024; /* pm3 aperture always 64 MB */
1381 pm3fb_mapIO(l_fb_info); /* temporary map IO */
1382
1383 DASSERT((l_fb_info->vIOBase != NULL),
1384 "IO successfully mapped before mem detect\n");
1385 DASSERT((l_fb_info->v_fb != NULL),
1386 "FB successfully mapped before mem detect\n");
1387
1388 /* card-specific stuff, *before* accessing *any* FB memory */
1389 if ((!pci_read_config_word
1390 (l_fb_info->dev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor))
1391 &&
1392 (!pci_read_config_word
1393 (l_fb_info->dev, PCI_SUBSYSTEM_ID, &subdevice))) {
1394 i = 0; l_fb_info->board_type = 0;
1395 while ((cardbase[i].cardname[0]) && !(l_fb_info->board_type)) {
1396 if ((cardbase[i].subvendor == subvendor) &&
1397 (cardbase[i].subdevice == subdevice) &&
1398 (cardbase[i].func == PCI_FUNC(l_fb_info->dev->devfn))) {
1399 DPRINTK(2, "Card #%ld is an %s\n",
1400 l_fb_info->board_num,
1401 cardbase[i].cardname);
1402 if (cardbase[i].specific_setup)
1403 cardbase[i].specific_setup(l_fb_info);
1404 l_fb_info->board_type = i;
1405 }
1406 i++;
1407 }
1408 if (!l_fb_info->board_type) {
1409 DPRINTK(1, "Card #%ld is an unknown 0x%04x / 0x%04x\n",
1410 l_fb_info->board_num, subvendor, subdevice);
1411 }
1412 } else {
1413 printk(KERN_ERR "pm3fb: Error: pci_read_config_word failed, board #%ld\n",
1414 l_fb_info->board_num);
1415 }
1416
1417 if (printtimings)
1418 pm3fb_show_cur_timing(l_fb_info);
1419
1420 /* card-specific setup is done, we preserve the final
1421 memory timing for future reference */
1422 if ((ptr = pm3fb_preserve_memory_timings(l_fb_info)) == pm3fb_timing_problem) { /* memory timings were wrong ! oops.... */
1423 return(0);
1424 }
1425
1426 tempBypass = PM3_READ_REG(PM3MemBypassWriteMask);
1427
1428 DPRINTK(2, "PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass);
1429
1430 PM3_SLOW_WRITE_REG(PM3MemBypassWriteMask, 0xFFFFFFFF);
1431
1432 /* pm3 split up memory, replicates, and do a lot of nasty stuff IMHO ;-) */
1433 for (i = 0; i < 32; i++) {
1434 fb_writel(i * 0x00345678,
1435 (l_fb_info->v_fb + (i * 1048576)));
1436 mb();
1437 temp1 = fb_readl((l_fb_info->v_fb + (i * 1048576)));
1438
1439 /* Let's check for wrapover, write will fail at 16MB boundary */
1440 if (temp1 == (i * 0x00345678))
1441 memsize = i;
1442 else
1443 break;
1444 }
1445
1446 DPRINTK(2, "First detect pass already got %ld MB\n", memsize + 1);
1447
1448 if (memsize == i) {
1449 for (i = 0; i < 32; i++) {
1450 /* Clear first 32MB ; 0 is 0, no need to byteswap */
1451 writel(0x0000000,
1452 (l_fb_info->v_fb + (i * 1048576)));
1453 mb();
1454 }
1455
1456 for (i = 32; i < 64; i++) {
1457 fb_writel(i * 0x00345678,
1458 (l_fb_info->v_fb + (i * 1048576)));
1459 mb();
1460 temp1 =
1461 fb_readl((l_fb_info->v_fb + (i * 1048576)));
1462 temp2 =
1463 fb_readl((l_fb_info->v_fb +
1464 ((i - 32) * 1048576)));
1465 if ((temp1 == (i * 0x00345678)) && (temp2 == 0)) /* different value, different RAM... */
1466 memsize = i;
1467 else
1468 break;
1469 }
1470 }
1471
1472 DPRINTK(2, "Second detect pass got %ld MB\n", memsize + 1);
1473
1474 PM3_SLOW_WRITE_REG(PM3MemBypassWriteMask, tempBypass);
1475
1476 pm3fb_unmapIO(l_fb_info);
1477 memsize = 1048576 * (memsize + 1);
1478
1479 DPRINTK(2, "Returning 0x%08lx bytes\n", memsize);
1480
1481 if (forcesize[l_fb_info->board_num] && ((forcesize[l_fb_info->board_num] * 1048576) != memsize))
1482 {
1483 printk(KERN_WARNING "pm3fb: mismatch between probed (%ld MB) and specified (%hd MB) memory size, using SPECIFIED !\n", memsize, forcesize[l_fb_info->board_num]);
1484 memsize = 1048576 * forcesize[l_fb_info->board_num];
1485 }
1486
1487 l_fb_info->fb_size = memsize;
1488
1489 if (ptr == pm3fb_timing_retry)
1490 {
1491 printk(KERN_WARNING "pm3fb: retrying memory timings check");
1492 if (pm3fb_try_memory_timings(l_fb_info) == pm3fb_timing_problem)
1493 return(0);
1494 }
1495
1496 return (memsize);
1497}
1498
1499static void pm3fb_clear_memory(struct pm3fb_info *l_fb_info, u32 cc)
1500{
1501 int i;
1502
1503 DTRACE;
1504
1505 for (i = 0; i < (l_fb_info->fb_size / sizeof(u32)) ; i++) /* clear entire FB memory to black */
1506 {
1507 fb_writel(cc, (l_fb_info->v_fb + (i * sizeof(u32))));
1508 } 447 }
1509} 448 var->height = var->width = -1;
1510
1511static void pm3fb_clear_colormap(struct pm3fb_info *l_fb_info, unsigned char r, unsigned char g, unsigned char b)
1512{
1513 int i;
1514
1515 DTRACE;
1516
1517 for (i = 0; i < 256 ; i++) /* fill color map with white */
1518 pm3fb_set_color(l_fb_info, i, r, g, b);
1519
1520}
1521
1522/* common initialisation */
1523static void pm3fb_common_init(struct pm3fb_info *l_fb_info)
1524{
1525 DTRACE;
1526
1527 DPRINTK(2, "Initializing board #%ld @ %lx\n", l_fb_info->board_num,
1528 (unsigned long) l_fb_info);
1529
1530 strcpy(l_fb_info->gen.info.modename, permedia3_name);
1531 disp[l_fb_info->board_num].scrollmode = 0; /* SCROLL_YNOMOVE; *//* 0 means "let fbcon choose" */
1532 l_fb_info->gen.parsize = sizeof(struct pm3fb_par);
1533 l_fb_info->gen.info.changevar = NULL;
1534 l_fb_info->gen.info.fbops = &pm3fb_ops;
1535 l_fb_info->gen.info.disp = &(disp[l_fb_info->board_num]);
1536 if (fontn[l_fb_info->board_num][0])
1537 strcpy(l_fb_info->gen.info.fontname,
1538 fontn[l_fb_info->board_num]);
1539 l_fb_info->gen.info.switch_con = &fbgen_switch;
1540 l_fb_info->gen.info.updatevar = &fbgen_update_var; /* */
1541 l_fb_info->gen.info.flags = FBINFO_FLAG_DEFAULT;
1542
1543 pm3fb_mapIO(l_fb_info);
1544
1545 pm3fb_clear_memory(l_fb_info, 0);
1546 pm3fb_clear_colormap(l_fb_info, 0, 0, 0);
1547
1548 (void) fbgen_get_var(&(disp[l_fb_info->board_num]).var, -1,
1549 &l_fb_info->gen.info);
1550 449
1551 if (depth[l_fb_info->board_num]) /* override mode-defined depth */ 450 if (var->xres != var->xres_virtual) {
1552 { 451 DPRINTK("virtual x resolution != physical x resolution not supported\n");
1553 pm3fb_encode_depth(&(disp[l_fb_info->board_num]).var, depth[l_fb_info->board_num]); 452 return -EINVAL;
1554 (disp[l_fb_info->board_num]).var.bits_per_pixel = depth2bpp(depth[l_fb_info->board_num]);
1555 } 453 }
1556 454
1557 (void) fbgen_do_set_var(&(disp[l_fb_info->board_num]).var, 1, 455 if (var->yres > var->yres_virtual) {
1558 &l_fb_info->gen); 456 DPRINTK("virtual y resolution < physical y resolution not possible\n");
1559 457 return -EINVAL;
1560 fbgen_set_disp(-1, &l_fb_info->gen);
1561
1562 do_install_cmap(0, &l_fb_info->gen.info);
1563
1564 if (register_framebuffer(&l_fb_info->gen.info) < 0) {
1565 DPRINTK(1, "Couldn't register framebuffer\n");
1566 return;
1567 } 458 }
1568 459
1569 PM3_WRITE_DAC_REG(PM3RD_CursorMode, 460 if (var->xoffset) {
1570 PM3RD_CursorMode_CURSOR_DISABLE); 461 DPRINTK("xoffset not supported\n");
1571 462 return -EINVAL;
1572 PM3_SHOW_CUR_MODE;
1573
1574 pm3fb_write_mode(l_fb_info);
1575
1576 printk("fb%d: %s, using %uK of video memory (%s)\n",
1577 l_fb_info->gen.info.node,
1578 permedia3_name, (u32) (l_fb_info->fb_size >> 10),
1579 cardbase[l_fb_info->board_type].cardname);
1580}
1581
1582/* **************************************************** */
1583/* ***** accelerated permedia3-specific functions ***** */
1584/* **************************************************** */
1585#ifdef PM3FB_USE_ACCEL
1586static void pm3fb_wait_pm3(struct pm3fb_info *l_fb_info)
1587{
1588 DTRACE;
1589
1590 PM3_SLOW_WRITE_REG(PM3FilterMode, PM3FilterModeSync);
1591 PM3_SLOW_WRITE_REG(PM3Sync, 0);
1592 mb();
1593 do {
1594 while ((PM3_READ_REG(PM3OutFIFOWords)) == 0);
1595 rmb();
1596 } while ((PM3_READ_REG(PM3OutputFifo)) != PM3Sync_Tag);
1597}
1598
1599static void pm3fb_init_engine(struct pm3fb_info *l_fb_info)
1600{
1601 PM3_SLOW_WRITE_REG(PM3FilterMode, PM3FilterModeSync);
1602 PM3_SLOW_WRITE_REG(PM3StatisticMode, 0x0);
1603 PM3_SLOW_WRITE_REG(PM3DeltaMode, 0x0);
1604 PM3_SLOW_WRITE_REG(PM3RasterizerMode, 0x0);
1605 PM3_SLOW_WRITE_REG(PM3ScissorMode, 0x0);
1606 PM3_SLOW_WRITE_REG(PM3LineStippleMode, 0x0);
1607 PM3_SLOW_WRITE_REG(PM3AreaStippleMode, 0x0);
1608 PM3_SLOW_WRITE_REG(PM3GIDMode, 0x0);
1609 PM3_SLOW_WRITE_REG(PM3DepthMode, 0x0);
1610 PM3_SLOW_WRITE_REG(PM3StencilMode, 0x0);
1611 PM3_SLOW_WRITE_REG(PM3StencilData, 0x0);
1612 PM3_SLOW_WRITE_REG(PM3ColorDDAMode, 0x0);
1613 PM3_SLOW_WRITE_REG(PM3TextureCoordMode, 0x0);
1614 PM3_SLOW_WRITE_REG(PM3TextureIndexMode0, 0x0);
1615 PM3_SLOW_WRITE_REG(PM3TextureIndexMode1, 0x0);
1616 PM3_SLOW_WRITE_REG(PM3TextureReadMode, 0x0);
1617 PM3_SLOW_WRITE_REG(PM3LUTMode, 0x0);
1618 PM3_SLOW_WRITE_REG(PM3TextureFilterMode, 0x0);
1619 PM3_SLOW_WRITE_REG(PM3TextureCompositeMode, 0x0);
1620 PM3_SLOW_WRITE_REG(PM3TextureApplicationMode, 0x0);
1621 PM3_SLOW_WRITE_REG(PM3TextureCompositeColorMode1, 0x0);
1622 PM3_SLOW_WRITE_REG(PM3TextureCompositeAlphaMode1, 0x0);
1623 PM3_SLOW_WRITE_REG(PM3TextureCompositeColorMode0, 0x0);
1624 PM3_SLOW_WRITE_REG(PM3TextureCompositeAlphaMode0, 0x0);
1625 PM3_SLOW_WRITE_REG(PM3FogMode, 0x0);
1626 PM3_SLOW_WRITE_REG(PM3ChromaTestMode, 0x0);
1627 PM3_SLOW_WRITE_REG(PM3AlphaTestMode, 0x0);
1628 PM3_SLOW_WRITE_REG(PM3AntialiasMode, 0x0);
1629 PM3_SLOW_WRITE_REG(PM3YUVMode, 0x0);
1630 PM3_SLOW_WRITE_REG(PM3AlphaBlendColorMode, 0x0);
1631 PM3_SLOW_WRITE_REG(PM3AlphaBlendAlphaMode, 0x0);
1632 PM3_SLOW_WRITE_REG(PM3DitherMode, 0x0);
1633 PM3_SLOW_WRITE_REG(PM3LogicalOpMode, 0x0);
1634 PM3_SLOW_WRITE_REG(PM3RouterMode, 0x0);
1635 PM3_SLOW_WRITE_REG(PM3Window, 0x0);
1636
1637 PM3_SLOW_WRITE_REG(PM3Config2D, 0x0);
1638
1639 PM3_SLOW_WRITE_REG(PM3SpanColorMask, 0xffffffff);
1640
1641 PM3_SLOW_WRITE_REG(PM3XBias, 0x0);
1642 PM3_SLOW_WRITE_REG(PM3YBias, 0x0);
1643 PM3_SLOW_WRITE_REG(PM3DeltaControl, 0x0);
1644
1645 PM3_SLOW_WRITE_REG(PM3BitMaskPattern, 0xffffffff);
1646
1647 PM3_SLOW_WRITE_REG(PM3FBDestReadEnables,
1648 PM3FBDestReadEnables_E(0xff) |
1649 PM3FBDestReadEnables_R(0xff) |
1650 PM3FBDestReadEnables_ReferenceAlpha(0xff));
1651 PM3_SLOW_WRITE_REG(PM3FBDestReadBufferAddr0, 0x0);
1652 PM3_SLOW_WRITE_REG(PM3FBDestReadBufferOffset0, 0x0);
1653 PM3_SLOW_WRITE_REG(PM3FBDestReadBufferWidth0,
1654 PM3FBDestReadBufferWidth_Width(l_fb_info->
1655 current_par->
1656 width));
1657
1658 PM3_SLOW_WRITE_REG(PM3FBDestReadMode,
1659 PM3FBDestReadMode_ReadEnable |
1660 PM3FBDestReadMode_Enable0);
1661 PM3_SLOW_WRITE_REG(PM3FBSourceReadBufferAddr, 0x0);
1662 PM3_SLOW_WRITE_REG(PM3FBSourceReadBufferOffset, 0x0);
1663 PM3_SLOW_WRITE_REG(PM3FBSourceReadBufferWidth,
1664 PM3FBSourceReadBufferWidth_Width(l_fb_info->
1665 current_par->
1666 width));
1667 PM3_SLOW_WRITE_REG(PM3FBSourceReadMode,
1668 PM3FBSourceReadMode_Blocking |
1669 PM3FBSourceReadMode_ReadEnable);
1670
1671 {
1672 unsigned long rm = 1;
1673 switch (l_fb_info->current_par->depth) {
1674 case 8:
1675 PM3_SLOW_WRITE_REG(PM3PixelSize,
1676 PM3PixelSize_GLOBAL_8BIT);
1677 break;
1678 case 12:
1679 case 15:
1680 case 16:
1681 PM3_SLOW_WRITE_REG(PM3PixelSize,
1682 PM3PixelSize_GLOBAL_16BIT);
1683 break;
1684 case 32:
1685 PM3_SLOW_WRITE_REG(PM3PixelSize,
1686 PM3PixelSize_GLOBAL_32BIT);
1687 break;
1688 default:
1689 DPRINTK(1, "Unsupported depth %d\n",
1690 l_fb_info->current_par->depth);
1691 break;
1692 }
1693 PM3_SLOW_WRITE_REG(PM3RasterizerMode, rm);
1694 } 463 }
1695 464
1696 PM3_SLOW_WRITE_REG(PM3FBSoftwareWriteMask, 0xffffffff); 465 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
1697 PM3_SLOW_WRITE_REG(PM3FBHardwareWriteMask, 0xffffffff); 466 DPRINTK("interlace not supported\n");
1698 PM3_SLOW_WRITE_REG(PM3FBWriteMode, 467 return -EINVAL;
1699 PM3FBWriteMode_WriteEnable |
1700 PM3FBWriteMode_OpaqueSpan |
1701 PM3FBWriteMode_Enable0);
1702 PM3_SLOW_WRITE_REG(PM3FBWriteBufferAddr0, 0x0);
1703 PM3_SLOW_WRITE_REG(PM3FBWriteBufferOffset0, 0x0);
1704 PM3_SLOW_WRITE_REG(PM3FBWriteBufferWidth0,
1705 PM3FBWriteBufferWidth_Width(l_fb_info->
1706 current_par->
1707 width));
1708
1709 PM3_SLOW_WRITE_REG(PM3SizeOfFramebuffer, 0x0);
1710 {
1711 unsigned long sofb = (8UL * l_fb_info->fb_size) /
1712 ((depth2bpp(l_fb_info->current_par->depth))
1713 * l_fb_info->current_par->width); /* size in lines of FB */
1714 if (sofb > 4095)
1715 PM3_SLOW_WRITE_REG(PM3SizeOfFramebuffer, 4095);
1716 else
1717 PM3_SLOW_WRITE_REG(PM3SizeOfFramebuffer, sofb);
1718
1719 switch (l_fb_info->current_par->depth) {
1720 case 8:
1721 PM3_SLOW_WRITE_REG(PM3DitherMode,
1722 (1 << 10) | (2 << 3));
1723 break;
1724 case 12:
1725 case 15:
1726 case 16:
1727 PM3_SLOW_WRITE_REG(PM3DitherMode,
1728 (1 << 10) | (1 << 3));
1729 break;
1730 case 32:
1731 PM3_SLOW_WRITE_REG(PM3DitherMode,
1732 (1 << 10) | (0 << 3));
1733 break;
1734 default:
1735 DPRINTK(1, "Unsupported depth %d\n",
1736 l_fb_info->current_par->depth);
1737 break;
1738 }
1739 } 468 }
1740 469
1741 PM3_SLOW_WRITE_REG(PM3dXDom, 0x0); 470 var->xres = (var->xres + 31) & ~31; /* could sometimes be 8 */
1742 PM3_SLOW_WRITE_REG(PM3dXSub, 0x0); 471 lpitch = var->xres * ((var->bits_per_pixel + 7)>>3);
1743 PM3_SLOW_WRITE_REG(PM3dY, (1 << 16));
1744 PM3_SLOW_WRITE_REG(PM3StartXDom, 0x0);
1745 PM3_SLOW_WRITE_REG(PM3StartXSub, 0x0);
1746 PM3_SLOW_WRITE_REG(PM3StartY, 0x0);
1747 PM3_SLOW_WRITE_REG(PM3Count, 0x0);
1748
1749/* Disable LocalBuffer. better safe than sorry */
1750 PM3_SLOW_WRITE_REG(PM3LBDestReadMode, 0x0);
1751 PM3_SLOW_WRITE_REG(PM3LBDestReadEnables, 0x0);
1752 PM3_SLOW_WRITE_REG(PM3LBSourceReadMode, 0x0);
1753 PM3_SLOW_WRITE_REG(PM3LBWriteMode, 0x0);
1754
1755 pm3fb_wait_pm3(l_fb_info);
1756}
1757 472
1758#ifdef FBCON_HAS_CFB32 473 if (var->xres < 200 || var->xres > 2048) {
1759static void pm3fb_cfb32_clear(struct vc_data *conp, 474 DPRINTK("width not supported: %u\n", var->xres);
1760 struct display *p, 475 return -EINVAL;
1761 int sy, int sx, int height, int width)
1762{
1763 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
1764 u32 c;
1765
1766 DTRACE;
1767
1768 sx = sx * fontwidth(p);
1769 width = width * fontwidth(p);
1770 sy = sy * fontheight(p);
1771 height = height * fontheight(p);
1772 c = ((u32 *) p->dispsw_data)[attr_bgcol_ec(p, conp)];
1773
1774 /* block fills in 32bpp are hard, but in low res (width <= 1600 :-)
1775 we can use 16bpp operations, but not if NoWriteMask is on (SDRAM) */
1776 if ((l_fb_info->current_par->width > 1600) ||
1777 (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)) {
1778 PM3_WAIT(4);
1779
1780 PM3_WRITE_REG(PM3Config2D,
1781 PM3Config2D_UseConstantSource |
1782 PM3Config2D_ForegroundROPEnable |
1783 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
1784 PM3Config2D_FBWriteEnable);
1785
1786 PM3_WRITE_REG(PM3ForegroundColor, c);
1787
1788 PM3_WRITE_REG(PM3RectanglePosition,
1789 (PM3RectanglePosition_XOffset(sx)) |
1790 (PM3RectanglePosition_YOffset(sy)));
1791
1792 PM3_WRITE_REG(PM3Render2D,
1793 PM3Render2D_XPositive |
1794 PM3Render2D_YPositive |
1795 PM3Render2D_Operation_Normal |
1796 PM3Render2D_SpanOperation |
1797 (PM3Render2D_Width(width)) |
1798 (PM3Render2D_Height(height)));
1799 } else {
1800 PM3_WAIT(8);
1801
1802 PM3_WRITE_REG(PM3FBBlockColor, c);
1803
1804 PM3_WRITE_REG(PM3PixelSize, PM3PixelSize_GLOBAL_16BIT);
1805
1806 PM3_WRITE_REG(PM3FBWriteBufferWidth0,
1807 PM3FBWriteBufferWidth_Width(l_fb_info->
1808 current_par->
1809 width << 1));
1810
1811 PM3_WRITE_REG(PM3Config2D,
1812 PM3Config2D_UseConstantSource |
1813 PM3Config2D_ForegroundROPEnable |
1814 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
1815 PM3Config2D_FBWriteEnable);
1816
1817 PM3_WRITE_REG(PM3RectanglePosition,
1818 (PM3RectanglePosition_XOffset(sx << 1)) |
1819 (PM3RectanglePosition_YOffset(sy)));
1820
1821 PM3_WRITE_REG(PM3Render2D,
1822 PM3Render2D_XPositive |
1823 PM3Render2D_YPositive |
1824 PM3Render2D_Operation_Normal |
1825 (PM3Render2D_Width(width << 1)) |
1826 (PM3Render2D_Height(height)));
1827
1828 PM3_WRITE_REG(PM3FBWriteBufferWidth0,
1829 PM3FBWriteBufferWidth_Width(l_fb_info->
1830 current_par->
1831 width));
1832
1833 PM3_WRITE_REG(PM3PixelSize, PM3PixelSize_GLOBAL_32BIT);
1834 } 476 }
1835 477
1836 pm3fb_wait_pm3(l_fb_info); 478 if (var->yres < 200 || var->yres > 4095) {
1837} 479 DPRINTK("height not supported: %u\n", var->yres);
1838 480 return -EINVAL;
1839static void pm3fb_cfb32_clear_margins(struct vc_data *conp,
1840 struct display *p, int bottom_only)
1841{
1842 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
1843 int sx, sy;
1844 u32 c;
1845
1846 DTRACE;
1847
1848 sx = conp->vc_cols * fontwidth(p); /* right margin */
1849 sy = conp->vc_rows * fontheight(p); /* bottom margin */
1850 c = ((u32 *) p->dispsw_data)[attr_bgcol_ec(p, conp)];
1851
1852 if (!bottom_only) { /* right margin top->bottom */
1853 PM3_WAIT(4);
1854
1855 PM3_WRITE_REG(PM3Config2D,
1856 PM3Config2D_UseConstantSource |
1857 PM3Config2D_ForegroundROPEnable |
1858 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
1859 PM3Config2D_FBWriteEnable);
1860
1861 PM3_WRITE_REG(PM3ForegroundColor, c);
1862
1863 PM3_WRITE_REG(PM3RectanglePosition,
1864 (PM3RectanglePosition_XOffset
1865 (p->var.xoffset +
1866 sx)) | (PM3RectanglePosition_YOffset(p->
1867 var.
1868 yoffset)));
1869
1870 PM3_WRITE_REG(PM3Render2D,
1871 PM3Render2D_XPositive |
1872 PM3Render2D_YPositive |
1873 PM3Render2D_Operation_Normal |
1874 PM3Render2D_SpanOperation |
1875 (PM3Render2D_Width(p->var.xres - sx)) |
1876 (PM3Render2D_Height(p->var.yres)));
1877 } 481 }
1878 482
1879 /* bottom margin left -> right */ 483 if (lpitch * var->yres_virtual > info->fix.smem_len) {
1880 PM3_WAIT(4); 484 DPRINTK("no memory for screen (%ux%ux%u)\n",
1881 485 var->xres, var->yres_virtual, var->bits_per_pixel);
1882 PM3_WRITE_REG(PM3Config2D, 486 return -EINVAL;
1883 PM3Config2D_UseConstantSource |
1884 PM3Config2D_ForegroundROPEnable |
1885 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
1886 PM3Config2D_FBWriteEnable);
1887
1888 PM3_WRITE_REG(PM3ForegroundColor, c);
1889
1890 PM3_WRITE_REG(PM3RectanglePosition,
1891 (PM3RectanglePosition_XOffset(p->var.xoffset)) |
1892 (PM3RectanglePosition_YOffset(p->var.yoffset + sy)));
1893
1894 PM3_WRITE_REG(PM3Render2D,
1895 PM3Render2D_XPositive |
1896 PM3Render2D_YPositive |
1897 PM3Render2D_Operation_Normal |
1898 PM3Render2D_SpanOperation |
1899 (PM3Render2D_Width(p->var.xres)) |
1900 (PM3Render2D_Height(p->var.yres - sy)));
1901
1902 pm3fb_wait_pm3(l_fb_info);
1903}
1904#endif /* FBCON_HAS_CFB32 */
1905#ifdef FBCON_HAS_CFB16
1906static void pm3fb_cfb16_clear(struct vc_data *conp,
1907 struct display *p,
1908 int sy, int sx, int height, int width)
1909{
1910 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
1911 u32 c;
1912
1913 DTRACE;
1914
1915 sx = sx * fontwidth(p);
1916 width = width * fontwidth(p);
1917 sy = sy * fontheight(p);
1918 height = height * fontheight(p);
1919 c = ((u16 *) p->dispsw_data)[attr_bgcol_ec(p, conp)];
1920 c = c | (c << 16);
1921
1922 PM3_WAIT(4);
1923
1924 if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
1925 PM3_WRITE_REG(PM3ForegroundColor, c);
1926 else
1927 PM3_WRITE_REG(PM3FBBlockColor, c);
1928
1929 PM3_WRITE_REG(PM3Config2D,
1930 PM3Config2D_UseConstantSource |
1931 PM3Config2D_ForegroundROPEnable |
1932 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
1933 PM3Config2D_FBWriteEnable);
1934
1935 PM3_WRITE_REG(PM3RectanglePosition,
1936 (PM3RectanglePosition_XOffset(sx)) |
1937 (PM3RectanglePosition_YOffset(sy)));
1938
1939 if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
1940 PM3_WRITE_REG(PM3Render2D,
1941 PM3Render2D_XPositive |
1942 PM3Render2D_YPositive |
1943 PM3Render2D_Operation_Normal |
1944 PM3Render2D_SpanOperation |
1945 (PM3Render2D_Width(width)) |
1946 (PM3Render2D_Height(height)));
1947 else
1948 PM3_WRITE_REG(PM3Render2D,
1949 PM3Render2D_XPositive |
1950 PM3Render2D_YPositive |
1951 PM3Render2D_Operation_Normal |
1952 (PM3Render2D_Width(width)) |
1953 (PM3Render2D_Height(height)));
1954
1955 pm3fb_wait_pm3(l_fb_info);
1956}
1957
1958static void pm3fb_cfb16_clear_margins(struct vc_data *conp,
1959 struct display *p, int bottom_only)
1960{
1961 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
1962 int sx, sy;
1963 u32 c;
1964
1965 DTRACE;
1966
1967 sx = conp->vc_cols * fontwidth(p); /* right margin */
1968 sy = conp->vc_rows * fontheight(p); /* bottom margin */
1969 c = ((u16 *) p->dispsw_data)[attr_bgcol_ec(p, conp)];
1970 c = c | (c << 16);
1971
1972 if (!bottom_only) { /* right margin top->bottom */
1973 PM3_WAIT(4);
1974
1975 PM3_WRITE_REG(PM3Config2D,
1976 PM3Config2D_UseConstantSource |
1977 PM3Config2D_ForegroundROPEnable |
1978 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
1979 PM3Config2D_FBWriteEnable);
1980
1981 if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
1982 PM3_WRITE_REG(PM3ForegroundColor, c);
1983 else
1984 PM3_WRITE_REG(PM3FBBlockColor, c);
1985
1986 PM3_WRITE_REG(PM3RectanglePosition,
1987 (PM3RectanglePosition_XOffset
1988 (p->var.xoffset +
1989 sx)) | (PM3RectanglePosition_YOffset(p->
1990 var.
1991 yoffset)));
1992 if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
1993 PM3_WRITE_REG(PM3Render2D,
1994 PM3Render2D_XPositive |
1995 PM3Render2D_YPositive |
1996 PM3Render2D_Operation_Normal |
1997 PM3Render2D_SpanOperation |
1998 (PM3Render2D_Width(p->var.xres - sx)) |
1999 (PM3Render2D_Height(p->var.yres)));
2000 else
2001 PM3_WRITE_REG(PM3Render2D,
2002 PM3Render2D_XPositive |
2003 PM3Render2D_YPositive |
2004 PM3Render2D_Operation_Normal |
2005 (PM3Render2D_Width(p->var.xres - sx)) |
2006 (PM3Render2D_Height(p->var.yres)));
2007 } 487 }
2008
2009 /* bottom margin left -> right */
2010 PM3_WAIT(4);
2011
2012 PM3_WRITE_REG(PM3Config2D,
2013 PM3Config2D_UseConstantSource |
2014 PM3Config2D_ForegroundROPEnable |
2015 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
2016 PM3Config2D_FBWriteEnable);
2017
2018 if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
2019 PM3_WRITE_REG(PM3ForegroundColor, c);
2020 else
2021 PM3_WRITE_REG(PM3FBBlockColor, c);
2022
2023
2024 PM3_WRITE_REG(PM3RectanglePosition,
2025 (PM3RectanglePosition_XOffset(p->var.xoffset)) |
2026 (PM3RectanglePosition_YOffset(p->var.yoffset + sy)));
2027
2028 if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
2029 PM3_WRITE_REG(PM3Render2D,
2030 PM3Render2D_XPositive |
2031 PM3Render2D_YPositive |
2032 PM3Render2D_Operation_Normal |
2033 PM3Render2D_SpanOperation |
2034 (PM3Render2D_Width(p->var.xres)) |
2035 (PM3Render2D_Height(p->var.yres - sy)));
2036 else
2037 PM3_WRITE_REG(PM3Render2D,
2038 PM3Render2D_XPositive |
2039 PM3Render2D_YPositive |
2040 PM3Render2D_Operation_Normal |
2041 (PM3Render2D_Width(p->var.xres)) |
2042 (PM3Render2D_Height(p->var.yres - sy)));
2043
2044 pm3fb_wait_pm3(l_fb_info);
2045}
2046#endif /* FBCON_HAS_CFB16 */
2047#ifdef FBCON_HAS_CFB8
2048static void pm3fb_cfb8_clear(struct vc_data *conp,
2049 struct display *p,
2050 int sy, int sx, int height, int width)
2051{
2052 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
2053 u32 c;
2054
2055 DTRACE;
2056
2057 sx = sx * fontwidth(p);
2058 width = width * fontwidth(p);
2059 sy = sy * fontheight(p);
2060 height = height * fontheight(p);
2061
2062 c = attr_bgcol_ec(p, conp);
2063 c |= c << 8;
2064 c |= c << 16;
2065 488
2066 PM3_WAIT(4); 489 if (PICOS2KHZ(var->pixclock) > PM3_MAX_PIXCLOCK) {
2067 490 DPRINTK("pixclock too high (%ldKHz)\n", PICOS2KHZ(var->pixclock));
2068 PM3_WRITE_REG(PM3Config2D, 491 return -EINVAL;
2069 PM3Config2D_UseConstantSource |
2070 PM3Config2D_ForegroundROPEnable |
2071 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
2072 PM3Config2D_FBWriteEnable);
2073
2074 PM3_WRITE_REG(PM3ForegroundColor, c);
2075
2076 PM3_WRITE_REG(PM3RectanglePosition,
2077 (PM3RectanglePosition_XOffset(sx)) |
2078 (PM3RectanglePosition_YOffset(sy)));
2079
2080 PM3_WRITE_REG(PM3Render2D,
2081 PM3Render2D_XPositive |
2082 PM3Render2D_YPositive |
2083 PM3Render2D_Operation_Normal |
2084 PM3Render2D_SpanOperation |
2085 (PM3Render2D_Width(width)) |
2086 (PM3Render2D_Height(height)));
2087
2088 pm3fb_wait_pm3(l_fb_info);
2089}
2090
2091static void pm3fb_cfb8_clear_margins(struct vc_data *conp,
2092 struct display *p, int bottom_only)
2093{
2094 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
2095 int sx, sy;
2096 u32 c;
2097
2098 DTRACE;
2099
2100 sx = conp->vc_cols * fontwidth(p); /* right margin */
2101 sy = conp->vc_rows * fontheight(p); /* bottom margin */
2102 c = attr_bgcol_ec(p, conp);
2103 c |= c << 8;
2104 c |= c << 16;
2105
2106 if (!bottom_only) { /* right margin top->bottom */
2107 PM3_WAIT(4);
2108
2109 PM3_WRITE_REG(PM3Config2D,
2110 PM3Config2D_UseConstantSource |
2111 PM3Config2D_ForegroundROPEnable |
2112 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
2113 PM3Config2D_FBWriteEnable);
2114
2115 PM3_WRITE_REG(PM3ForegroundColor, c);
2116
2117 PM3_WRITE_REG(PM3RectanglePosition,
2118 (PM3RectanglePosition_XOffset
2119 (p->var.xoffset +
2120 sx)) | (PM3RectanglePosition_YOffset(p->
2121 var.
2122 yoffset)));
2123
2124 PM3_WRITE_REG(PM3Render2D,
2125 PM3Render2D_XPositive |
2126 PM3Render2D_YPositive |
2127 PM3Render2D_Operation_Normal |
2128 PM3Render2D_SpanOperation |
2129 (PM3Render2D_Width(p->var.xres - sx)) |
2130 (PM3Render2D_Height(p->var.yres)));
2131 } 492 }
2132 493
2133 /* bottom margin left -> right */ 494 var->accel_flags = 0; /* Can't mmap if this is on */
2134 PM3_WAIT(4);
2135
2136 PM3_WRITE_REG(PM3Config2D,
2137 PM3Config2D_UseConstantSource |
2138 PM3Config2D_ForegroundROPEnable |
2139 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
2140 PM3Config2D_FBWriteEnable);
2141
2142 PM3_WRITE_REG(PM3ForegroundColor, c);
2143 495
2144 PM3_WRITE_REG(PM3RectanglePosition, 496 DPRINTK("Checking graphics mode at %dx%d depth %d\n",
2145 (PM3RectanglePosition_XOffset(p->var.xoffset)) | 497 var->xres, var->yres, var->bits_per_pixel);
2146 (PM3RectanglePosition_YOffset(p->var.yoffset + sy))); 498 return 0;
2147
2148 PM3_WRITE_REG(PM3Render2D,
2149 PM3Render2D_XPositive |
2150 PM3Render2D_YPositive |
2151 PM3Render2D_Operation_Normal |
2152 PM3Render2D_SpanOperation |
2153 (PM3Render2D_Width(p->var.xres)) |
2154 (PM3Render2D_Height(p->var.yres - sy)));
2155
2156 pm3fb_wait_pm3(l_fb_info);
2157}
2158#endif /* FBCON_HAS_CFB8 */
2159#if defined(FBCON_HAS_CFB8) || defined(FBCON_HAS_CFB16) || defined(FBCON_HAS_CFB32)
2160static void pm3fb_cfbX_bmove(struct display *p,
2161 int sy, int sx,
2162 int dy, int dx, int height, int width)
2163{
2164 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
2165 int x_align, o_x, o_y;
2166
2167 DTRACE;
2168
2169 sx = sx * fontwidth(p);
2170 dx = dx * fontwidth(p);
2171 width = width * fontwidth(p);
2172 sy = sy * fontheight(p);
2173 dy = dy * fontheight(p);
2174 height = height * fontheight(p);
2175
2176 o_x = sx - dx; /*(sx > dx ) ? (sx - dx) : (dx - sx); */
2177 o_y = sy - dy; /*(sy > dy ) ? (sy - dy) : (dy - sy); */
2178
2179 x_align = (sx & 0x1f);
2180
2181 PM3_WAIT(6);
2182
2183 PM3_WRITE_REG(PM3Config2D,
2184 PM3Config2D_UserScissorEnable |
2185 PM3Config2D_ForegroundROPEnable |
2186 PM3Config2D_Blocking |
2187 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
2188 PM3Config2D_FBWriteEnable);
2189
2190 PM3_WRITE_REG(PM3ScissorMinXY,
2191 ((dy & 0x0fff) << 16) | (dx & 0x0fff));
2192 PM3_WRITE_REG(PM3ScissorMaxXY,
2193 (((dy + height) & 0x0fff) << 16) |
2194 ((dx + width) & 0x0fff));
2195
2196 PM3_WRITE_REG(PM3FBSourceReadBufferOffset,
2197 PM3FBSourceReadBufferOffset_XOffset(o_x) |
2198 PM3FBSourceReadBufferOffset_YOffset(o_y));
2199
2200 PM3_WRITE_REG(PM3RectanglePosition,
2201 (PM3RectanglePosition_XOffset(dx - x_align)) |
2202 (PM3RectanglePosition_YOffset(dy)));
2203
2204 PM3_WRITE_REG(PM3Render2D,
2205 ((sx > dx) ? PM3Render2D_XPositive : 0) |
2206 ((sy > dy) ? PM3Render2D_YPositive : 0) |
2207 PM3Render2D_Operation_Normal |
2208 PM3Render2D_SpanOperation |
2209 PM3Render2D_FBSourceReadEnable |
2210 (PM3Render2D_Width(width + x_align)) |
2211 (PM3Render2D_Height(height)));
2212
2213 pm3fb_wait_pm3(l_fb_info);
2214} 499}
2215 500
2216static void pm3fb_cfbX_putc(struct vc_data *conp, struct display *p, 501static int pm3fb_set_par(struct fb_info *info)
2217 int c, int yy, int xx)
2218{ 502{
2219 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info; 503 struct pm3_par *par = info->par;
2220 u8 *cdat, asx = 0, asy = 0, o_x = 0, o_y = 0; 504 const u32 xres = (info->var.xres + 31) & ~31;
2221 u32 fgx, bgx, ldat; 505 const int depth = (info->var.bits_per_pixel + 7) & ~7;
2222 int sx, sy, i;
2223
2224 DTRACE;
2225
2226 if (l_fb_info->current_par->depth == 8)
2227 fgx = attr_fgcol(p, c);
2228 else if (depth2bpp(l_fb_info->current_par->depth) == 16)
2229 fgx = ((u16 *) p->dispsw_data)[attr_fgcol(p, c)];
2230 else
2231 fgx = ((u32 *) p->dispsw_data)[attr_fgcol(p, c)];
2232
2233 PM3_COLOR(fgx);
2234
2235 if (l_fb_info->current_par->depth == 8)
2236 bgx = attr_bgcol(p, c);
2237 else if (depth2bpp(l_fb_info->current_par->depth) == 16)
2238 bgx = ((u16 *) p->dispsw_data)[attr_bgcol(p, c)];
2239 else
2240 bgx = ((u32 *) p->dispsw_data)[attr_bgcol(p, c)];
2241
2242 PM3_COLOR(bgx);
2243
2244 PM3_WAIT(4);
2245
2246 PM3_WRITE_REG(PM3Config2D,
2247 PM3Config2D_UseConstantSource |
2248 PM3Config2D_ForegroundROPEnable |
2249 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
2250 PM3Config2D_FBWriteEnable | PM3Config2D_OpaqueSpan);
2251
2252 PM3_WRITE_REG(PM3ForegroundColor, fgx);
2253 PM3_WRITE_REG(PM3FillBackgroundColor, bgx);
2254
2255 /* WARNING : address select X need to specify 8 bits for fontwidth <= 8 */
2256 /* and 16 bits for fontwidth <= 16 */
2257 /* same in _putcs, same for Y and fontheight */
2258 if (fontwidth(p) <= 8)
2259 asx = 2;
2260 else if (fontwidth(p) <= 16)
2261 asx = 3; /* look OK */
2262 if (fontheight(p) <= 8)
2263 asy = 2;
2264 else if (fontheight(p) <= 16)
2265 asy = 3; /* look OK */
2266 else if (fontheight(p) <= 32)
2267 asy = 4; /* look OK */
2268
2269 sx = xx * fontwidth(p);
2270 sy = yy * fontheight(p);
2271
2272 if (fontwidth(p) <= 8)
2273 o_x = (8 - (sx & 0x7)) & 0x7;
2274 else if (fontwidth(p) <= 16)
2275 o_x = (16 - (sx & 0xF)) & 0xF;
2276 if (fontheight(p) <= 8)
2277 o_y = (8 - (sy & 0x7)) & 0x7;
2278 else if (fontheight(p) <= 16)
2279 o_y = (16 - (sy & 0xF)) & 0xF;
2280 else if (fontheight(p) <= 32)
2281 o_y = (32 - (sy & 0x1F)) & 0x1F;
2282
2283 PM3_WRITE_REG(PM3AreaStippleMode, (o_x << 7) | (o_y << 12) | /* x_offset, y_offset in pattern */
2284 (1 << 18) | /* BE */
2285 1 | (asx << 1) | (asy << 4) | /* address select x/y */
2286 (1 << 20)); /* OpaqueSpan */
2287
2288 if (fontwidth(p) <= 8) {
2289 cdat = p->fontdata + (c & p->charmask) * fontheight(p);
2290 } else {
2291 cdat =
2292 p->fontdata +
2293 ((c & p->charmask) * (fontheight(p) << 1));
2294 }
2295
2296 PM3_WAIT(2 + fontheight(p));
2297
2298 for (i = 0; i < fontheight(p); i++) { /* assume fontheight <= 32 */
2299 if (fontwidth(p) <= 8) {
2300 ldat = *cdat++;
2301 } else { /* assume fontwidth <= 16 ATM */
2302
2303 ldat = ((*cdat++) << 8);
2304 ldat |= *cdat++;
2305 }
2306 PM3_WRITE_REG(AreaStipplePattern_indexed(i), ldat);
2307 }
2308 506
2309 PM3_WRITE_REG(PM3RectanglePosition, 507 par->base = pm3fb_shift_bpp(info->var.bits_per_pixel,
2310 (PM3RectanglePosition_XOffset(sx)) | 508 (info->var.yoffset * xres)
2311 (PM3RectanglePosition_YOffset(sy))); 509 + info->var.xoffset);
510 par->video = 0;
2312 511
2313 PM3_WRITE_REG(PM3Render2D, 512 if (info->var.sync & FB_SYNC_HOR_HIGH_ACT)
2314 PM3Render2D_AreaStippleEnable | 513 par->video |= PM3VideoControl_HSYNC_ACTIVE_HIGH;
2315 PM3Render2D_XPositive |
2316 PM3Render2D_YPositive |
2317 PM3Render2D_Operation_Normal |
2318 PM3Render2D_SpanOperation |
2319 (PM3Render2D_Width(fontwidth(p))) |
2320 (PM3Render2D_Height(fontheight(p))));
2321
2322 pm3fb_wait_pm3(l_fb_info);
2323}
2324
2325static void pm3fb_cfbX_putcs(struct vc_data *conp, struct display *p,
2326 const unsigned short *s, int count, int yy,
2327 int xx)
2328{
2329 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
2330 u8 *cdat, asx = 0, asy = 0, o_x = 0, o_y = 0;
2331 u32 fgx, bgx, ldat;
2332 int sx, sy, i, j;
2333 u16 sc;
2334
2335 DTRACE;
2336
2337 sc = scr_readw(s);
2338 if (l_fb_info->current_par->depth == 8)
2339 fgx = attr_fgcol(p, sc);
2340 else if (depth2bpp(l_fb_info->current_par->depth) == 16)
2341 fgx = ((u16 *) p->dispsw_data)[attr_fgcol(p, sc)];
2342 else
2343 fgx = ((u32 *) p->dispsw_data)[attr_fgcol(p, sc)];
2344
2345 PM3_COLOR(fgx);
2346
2347 if (l_fb_info->current_par->depth == 8)
2348 bgx = attr_bgcol(p, sc);
2349 else if (depth2bpp(l_fb_info->current_par->depth) == 16)
2350 bgx = ((u16 *) p->dispsw_data)[attr_bgcol(p, sc)];
2351 else 514 else
2352 bgx = ((u32 *) p->dispsw_data)[attr_bgcol(p, sc)]; 515 par->video |= PM3VideoControl_HSYNC_ACTIVE_LOW;
2353
2354 PM3_COLOR(bgx);
2355
2356 PM3_WAIT(4);
2357
2358 PM3_WRITE_REG(PM3Config2D,
2359 PM3Config2D_UseConstantSource |
2360 PM3Config2D_ForegroundROPEnable |
2361 (PM3Config2D_ForegroundROP(0x3)) | /* Ox3 is GXcopy */
2362 PM3Config2D_FBWriteEnable |
2363 PM3Config2D_OpaqueSpan);
2364
2365 PM3_WRITE_REG(PM3ForegroundColor, fgx);
2366 PM3_WRITE_REG(PM3FillBackgroundColor, bgx);
2367
2368 /* WARNING : address select X need to specify 8 bits for fontwidth <= 8 */
2369 /* and 16 bits for fontwidth <= 16 */
2370 /* same in _putc, same for Y and fontheight */
2371 if (fontwidth(p) <= 8)
2372 asx = 2;
2373 else if (fontwidth(p) <= 16)
2374 asx = 3; /* look OK */
2375 if (fontheight(p) <= 8)
2376 asy = 2;
2377 else if (fontheight(p) <= 16)
2378 asy = 3; /* look OK */
2379 else if (fontheight(p) <= 32)
2380 asy = 4; /* look OK */
2381
2382 sy = yy * fontheight(p);
2383
2384 if (fontheight(p) <= 8)
2385 o_y = (8 - (sy & 0x7)) & 0x7;
2386 else if (fontheight(p) <= 16)
2387 o_y = (16 - (sy & 0xF)) & 0xF;
2388 else if (fontheight(p) <= 32)
2389 o_y = (32 - (sy & 0x1F)) & 0x1F;
2390
2391 for (j = 0; j < count; j++) {
2392 sc = scr_readw(s + j);
2393 if (fontwidth(p) <= 8)
2394 cdat = p->fontdata +
2395 (sc & p->charmask) * fontheight(p);
2396 else
2397 cdat = p->fontdata +
2398 ((sc & p->charmask) * fontheight(p) << 1);
2399
2400 sx = (xx + j) * fontwidth(p);
2401
2402 if (fontwidth(p) <= 8)
2403 o_x = (8 - (sx & 0x7)) & 0x7;
2404 else if (fontwidth(p) <= 16)
2405 o_x = (16 - (sx & 0xF)) & 0xF;
2406
2407 PM3_WAIT(3 + fontheight(p));
2408
2409 PM3_WRITE_REG(PM3AreaStippleMode, (o_x << 7) | (o_y << 12) | /* x_offset, y_offset in pattern */
2410 (1 << 18) | /* BE */
2411 1 | (asx << 1) | (asy << 4) | /* address select x/y */
2412 (1 << 20)); /* OpaqueSpan */
2413
2414 for (i = 0; i < fontheight(p); i++) { /* assume fontheight <= 32 */
2415 if (fontwidth(p) <= 8) {
2416 ldat = *cdat++;
2417 } else { /* assume fontwidth <= 16 ATM */
2418 ldat = ((*cdat++) << 8);
2419 ldat |= *cdat++;
2420 }
2421 PM3_WRITE_REG(AreaStipplePattern_indexed(i), ldat);
2422 }
2423
2424 PM3_WRITE_REG(PM3RectanglePosition,
2425 (PM3RectanglePosition_XOffset(sx)) |
2426 (PM3RectanglePosition_YOffset(sy)));
2427
2428 PM3_WRITE_REG(PM3Render2D,
2429 PM3Render2D_AreaStippleEnable |
2430 PM3Render2D_XPositive |
2431 PM3Render2D_YPositive |
2432 PM3Render2D_Operation_Normal |
2433 PM3Render2D_SpanOperation |
2434 (PM3Render2D_Width(fontwidth(p))) |
2435 (PM3Render2D_Height(fontheight(p))));
2436 }
2437 pm3fb_wait_pm3(l_fb_info);
2438}
2439
2440static void pm3fb_cfbX_revc(struct display *p, int xx, int yy)
2441{
2442 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) p->fb_info;
2443
2444 xx = xx * fontwidth(p);
2445 yy = yy * fontheight(p);
2446
2447 if (l_fb_info->current_par->depth == 8)
2448 {
2449 if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
2450 PM3_SLOW_WRITE_REG(PM3FBSoftwareWriteMask, 0x0F0F0F0F);
2451 else
2452 PM3_SLOW_WRITE_REG(PM3FBHardwareWriteMask, 0x0F0F0F0F);
2453 }
2454
2455 PM3_WAIT(3);
2456
2457 PM3_WRITE_REG(PM3Config2D,
2458 PM3Config2D_UseConstantSource |
2459 PM3Config2D_ForegroundROPEnable |
2460 (PM3Config2D_ForegroundROP(0xa)) | /* Oxa is GXinvert */
2461 PM3Config2D_FBDestReadEnable |
2462 PM3Config2D_FBWriteEnable);
2463
2464 PM3_WRITE_REG(PM3RectanglePosition,
2465 (PM3RectanglePosition_XOffset(xx)) |
2466 (PM3RectanglePosition_YOffset(yy)));
2467
2468 PM3_WRITE_REG(PM3Render2D,
2469 PM3Render2D_XPositive |
2470 PM3Render2D_YPositive |
2471 PM3Render2D_Operation_Normal |
2472 PM3Render2D_SpanOperation |
2473 (PM3Render2D_Width(fontwidth(p))) |
2474 (PM3Render2D_Height(fontheight(p))));
2475
2476 pm3fb_wait_pm3(l_fb_info);
2477
2478 if (l_fb_info->current_par->depth == 8)
2479 {
2480 if (l_fb_info->memt.caps & PM3LocalMemCaps_NoWriteMask)
2481 PM3_SLOW_WRITE_REG(PM3FBSoftwareWriteMask, 0xFFFFFFFF);
2482 else
2483 PM3_SLOW_WRITE_REG(PM3FBHardwareWriteMask, 0xFFFFFFFF);
2484 }
2485}
2486
2487#endif /* FBCON_HAS_CFB8 || FBCON_HAS_CFB16 || FBCON_HAS_CFB32 */
2488#endif /* PM3FB_USE_ACCEL */
2489/* *********************************** */
2490/* ***** pre-init board(s) setup ***** */
2491/* *********************************** */
2492
2493static void pm3fb_mode_setup(char *mode, unsigned long board_num)
2494{
2495 struct pm3fb_info *l_fb_info = &(fb_info[board_num]);
2496 struct pm3fb_par *l_fb_par = &(current_par[board_num]);
2497 unsigned long i = 0;
2498
2499 current_par_valid[board_num] = 0;
2500
2501 if (!strncmp(mode, "current", 7)) {
2502 l_fb_info->use_current = 1; /* default w/ OpenFirmware */
2503 } else {
2504 while ((mode_base[i].name[0])
2505 && (!current_par_valid[board_num])) {
2506 if (!
2507 (strncmp
2508 (mode, mode_base[i].name,
2509 strlen(mode_base[i].name)))) {
2510 memcpy(l_fb_par, &(mode_base[i].user_mode),
2511 sizeof(struct pm3fb_par));
2512 current_par_valid[board_num] = 1;
2513 DPRINTK(2, "Mode set to %s\n",
2514 mode_base[i].name);
2515 }
2516 i++;
2517 }
2518 DASSERT(current_par_valid[board_num],
2519 "Valid mode on command line\n");
2520 }
2521}
2522
2523static void pm3fb_pciid_setup(char *pciid, unsigned long board_num)
2524{
2525 short l_bus = -1, l_slot = -1, l_func = -1;
2526 char *next;
2527
2528 if (pciid) {
2529 l_bus = simple_strtoul(pciid, &next, 10);
2530 if (next && (next[0] == ':')) {
2531 pciid = next + 1;
2532 l_slot = simple_strtoul(pciid, &next, 10);
2533 if (next && (next[0] == ':')) {
2534 pciid = next + 1;
2535 l_func =
2536 simple_strtoul(pciid, (char **) NULL,
2537 10);
2538 }
2539 }
2540 } else
2541 return;
2542
2543 if ((l_bus >= 0) && (l_slot >= 0) && (l_func >= 0)) {
2544 bus[board_num] = l_bus;
2545 slot[board_num] = l_slot;
2546 func[board_num] = l_func;
2547 DPRINTK(2, "Board #%ld will be PciId: %hd:%hd:%hd\n",
2548 board_num, l_bus, l_slot, l_func);
2549 } else {
2550 DPRINTK(1, "Invalid PciId: %hd:%hd:%hd for board #%ld\n",
2551 l_bus, l_slot, l_func, board_num);
2552 }
2553}
2554
2555static void pm3fb_font_setup(char *lf, unsigned long board_num)
2556{
2557 unsigned long lfs = strlen(lf);
2558
2559 if (lfs > (PM3_FONTNAME_SIZE - 1)) {
2560 DPRINTK(1, "Fontname %s too long\n", lf);
2561 return;
2562 }
2563 strlcpy(fontn[board_num], lf, lfs + 1);
2564}
2565
2566static void pm3fb_bootdepth_setup(char *bds, unsigned long board_num)
2567{
2568 unsigned long bd = simple_strtoul(bds, (char **) NULL, 10);
2569
2570 if (!(depth_supported(bd))) {
2571 printk(KERN_WARNING "pm3fb: ignoring invalid depth %s for board #%ld\n",
2572 bds, board_num);
2573 return;
2574 }
2575 depth[board_num] = bd;
2576}
2577
2578static void pm3fb_forcesize_setup(char *bds, unsigned long board_num)
2579{
2580 unsigned long bd = simple_strtoul(bds, (char **) NULL, 10);
2581
2582 if (bd > 64) {
2583 printk(KERN_WARNING "pm3fb: ignoring invalid memory size %s for board #%ld\n",
2584 bds, board_num);
2585 return;
2586 }
2587 forcesize[board_num] = bd;
2588}
2589
2590static char *pm3fb_boardnum_setup(char *options, unsigned long *bn)
2591{
2592 char *next;
2593
2594 if (!(isdigit(options[0]))) {
2595 (*bn) = 0;
2596 return (options);
2597 }
2598
2599 (*bn) = simple_strtoul(options, &next, 10);
2600 516
2601 if (next && (next[0] == ':') && ((*bn) >= 0) 517 if (info->var.sync & FB_SYNC_VERT_HIGH_ACT)
2602 && ((*bn) <= PM3_MAX_BOARD)) { 518 par->video |= PM3VideoControl_VSYNC_ACTIVE_HIGH;
2603 DPRINTK(2, "Board_num seen as %ld\n", (*bn));
2604 return (next + 1);
2605 } else {
2606 (*bn) = 0;
2607 DPRINTK(2, "Board_num default to %ld\n", (*bn));
2608 return (options);
2609 }
2610}
2611
2612static void pm3fb_real_setup(char *options)
2613{
2614 char *next;
2615 unsigned long i, bn;
2616 struct pm3fb_info *l_fb_info;
2617
2618 DTRACE;
2619
2620 DPRINTK(2, "Options : %s\n", options);
2621
2622 for (i = 0; i < PM3_MAX_BOARD; i++) {
2623 l_fb_info = &(fb_info[i]);
2624 memset(l_fb_info, 0, sizeof(struct pm3fb_info));
2625 l_fb_info->gen.fbhw = &pm3fb_switch;
2626 l_fb_info->board_num = i;
2627 current_par_valid[i] = 0;
2628 slot[i] = -1;
2629 func[i] = -1;
2630 bus[i] = -1;
2631 disable[i] = 0;
2632 noaccel[i] = 0;
2633 fontn[i][0] = '\0';
2634 depth[i] = 0;
2635 l_fb_info->current_par = &(current_par[i]);
2636 }
2637
2638 /* eat up prefix pm3fb and whatever is used as separator i.e. :,= */
2639 if (!strncmp(options, "pm3fb", 5)) {
2640 options += 5;
2641 while (((*options) == ',') || ((*options) == ':')
2642 || ((*options) == '='))
2643 options++;
2644 }
2645
2646 while (options) {
2647 bn = 0;
2648 if ((next = strchr(options, ','))) {
2649 (*next) = '\0';
2650 next++;
2651 }
2652
2653 if (!strncmp(options, "mode:", 5)) {
2654 options = pm3fb_boardnum_setup(options + 5, &bn);
2655 DPRINTK(2, "Setting mode for board #%ld\n", bn);
2656 pm3fb_mode_setup(options, bn);
2657 } else if (!strncmp(options, "off:", 4)) {
2658 options = pm3fb_boardnum_setup(options + 4, &bn);
2659 DPRINTK(2, "Disabling board #%ld\n", bn);
2660 disable[bn] = 1;
2661 } else if (!strncmp(options, "off", 3)) { /* disable everything */
2662 for (i = 0; i < PM3_MAX_BOARD; i++)
2663 disable[i] = 1;
2664 } else if (!strncmp(options, "disable:", 8)) {
2665 options = pm3fb_boardnum_setup(options + 8, &bn);
2666 DPRINTK(2, "Disabling board #%ld\n", bn);
2667 disable[bn] = 1;
2668 } else if (!strncmp(options, "pciid:", 6)) {
2669 options = pm3fb_boardnum_setup(options + 6, &bn);
2670 DPRINTK(2, "Setting PciID for board #%ld\n", bn);
2671 pm3fb_pciid_setup(options, bn);
2672 } else if (!strncmp(options, "noaccel:", 8)) {
2673 options = pm3fb_boardnum_setup(options + 8, &bn);
2674 noaccel[bn] = 1;
2675 } else if (!strncmp(options, "font:", 5)) {
2676 options = pm3fb_boardnum_setup(options + 5, &bn);
2677 pm3fb_font_setup(options, bn);
2678 } else if (!strncmp(options, "depth:", 6)) {
2679 options = pm3fb_boardnum_setup(options + 6, &bn);
2680 pm3fb_bootdepth_setup(options, bn);
2681 } else if (!strncmp(options, "printtimings", 12)) {
2682 printtimings = 1;
2683 } else if (!strncmp(options, "flatpanel:", 10)) {
2684 options = pm3fb_boardnum_setup(options + 10, &bn);
2685 flatpanel[bn] = 1;
2686 } else if (!strncmp(options, "forcesize:", 10)) {
2687 options = pm3fb_boardnum_setup(options + 10, &bn);
2688 pm3fb_forcesize_setup(options, bn);
2689 }
2690 options = next;
2691 }
2692}
2693
2694/* ********************************************** */
2695/* ***** framebuffer API standard functions ***** */
2696/* ********************************************** */
2697
2698static int pm3fb_encode_fix(struct fb_fix_screeninfo *fix,
2699 const void *par, struct fb_info_gen *info)
2700{
2701 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
2702 struct pm3fb_par *p = (struct pm3fb_par *) par;
2703
2704 DTRACE;
2705
2706 strcpy(fix->id, permedia3_name);
2707 fix->smem_start = (unsigned long)l_fb_info->p_fb;
2708 fix->smem_len = l_fb_info->fb_size;
2709 fix->mmio_start = (unsigned long)l_fb_info->pIOBase;
2710 fix->mmio_len = PM3_REGS_SIZE;
2711#ifdef PM3FB_USE_ACCEL
2712 if (!(noaccel[l_fb_info->board_num]))
2713 fix->accel = FB_ACCEL_3DLABS_PERMEDIA3;
2714 else
2715#endif /* PM3FB_USE_ACCEL */
2716 fix->accel = FB_ACCEL_NONE;
2717 fix->type = FB_TYPE_PACKED_PIXELS;
2718 fix->visual =
2719 (p->depth == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
2720 if (current_par_valid[l_fb_info->board_num])
2721 fix->line_length =
2722 l_fb_info->current_par->width *
2723 depth2ByPP(l_fb_info->current_par->depth);
2724 else 519 else
2725 fix->line_length = 0; 520 par->video |= PM3VideoControl_VSYNC_ACTIVE_LOW;
2726 fix->xpanstep = 64 / depth2bpp(p->depth);
2727 fix->ypanstep = 1;
2728 fix->ywrapstep = 0;
2729 return (0);
2730}
2731
2732static int pm3fb_decode_var(const struct fb_var_screeninfo *var,
2733 void *par, struct fb_info_gen *info)
2734{
2735 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
2736 struct pm3fb_par *p = (struct pm3fb_par *) par;
2737 struct pm3fb_par temp_p;
2738 u32 xres;
2739
2740 DTRACE;
2741
2742 DASSERT((var != NULL), "fb_var_screeninfo* not NULL");
2743 DASSERT((p != NULL), "pm3fb_par* not NULL");
2744 DASSERT((l_fb_info != NULL), "pm3fb_info* not NULL");
2745 521
2746 memset(&temp_p, 0, sizeof(struct pm3fb_par)); 522 if ((info->var.vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
2747 temp_p.width = (var->xres_virtual + 7) & ~7; 523 par->video |= PM3VideoControl_LINE_DOUBLE_ON;
2748 temp_p.height = var->yres_virtual;
2749
2750 if (!(depth_supported(var->bits_per_pixel))) /* round unsupported up to a multiple of 8 */
2751 temp_p.depth = depth2bpp(var->bits_per_pixel);
2752 else 524 else
2753 temp_p.depth = var->bits_per_pixel; 525 par->video |= PM3VideoControl_LINE_DOUBLE_OFF;
2754
2755 temp_p.depth = (temp_p.depth > 32) ? 32 : temp_p.depth; /* max 32 */
2756 temp_p.depth = (temp_p.depth == 24) ? 32 : temp_p.depth; /* 24 unsupported, round-up to 32 */
2757
2758 if ((temp_p.depth == 16) && (var->red.length == 5) && (var->green.length == 5) && (var->blue.length == 5))
2759 temp_p.depth = 15; /* RGBA 5551 is stored as depth 15 */
2760
2761 if ((temp_p.depth == 16) && (var->red.length == 4) && (var->green.length == 4) && (var->blue.length == 4))
2762 temp_p.depth = 12; /* RGBA 4444 is stored as depth 12 */
2763
2764
2765 DPRINTK(2,
2766 "xres: %d, yres: %d, vxres: %d, vyres: %d ; xoffset:%d, yoffset: %d\n",
2767 var->xres, var->yres, var->xres_virtual, var->yres_virtual,
2768 var->xoffset, var->yoffset);
2769
2770 xres = (var->xres + 31) & ~31;
2771 if (temp_p.width < xres + var->xoffset)
2772 temp_p.width = xres + var->xoffset;
2773 if (temp_p.height < var->yres + var->yoffset)
2774 temp_p.height = var->yres + var->yoffset;
2775
2776 if (temp_p.width > 2048) {
2777 DPRINTK(1, "virtual width not supported: %u\n",
2778 temp_p.width);
2779 return (-EINVAL);
2780 }
2781 if (var->yres < 200) {
2782 DPRINTK(1, "height not supported: %u\n", (u32) var->yres);
2783 return (-EINVAL);
2784 }
2785 if (temp_p.height < 200 || temp_p.height > 4095) {
2786 DPRINTK(1, "virtual height not supported: %u\n",
2787 temp_p.height);
2788 return (-EINVAL);
2789 }
2790 if (!(depth_supported(temp_p.depth))) {
2791 DPRINTK(1, "depth not supported: %u\n", temp_p.depth);
2792 return (-EINVAL);
2793 }
2794 if ((temp_p.width * temp_p.height * depth2ByPP(temp_p.depth)) >
2795 l_fb_info->fb_size) {
2796 DPRINTK(1, "no memory for screen (%ux%ux%u)\n",
2797 temp_p.width, temp_p.height, temp_p.depth);
2798 return (-EINVAL);
2799 }
2800
2801 if ((!var->pixclock) ||
2802 (!var->right_margin) ||
2803 (!var->hsync_len) ||
2804 (!var->left_margin) ||
2805 (!var->lower_margin) ||
2806 (!var->vsync_len) || (!var->upper_margin)
2807 ) {
2808 unsigned long i = 0, done = 0;
2809 printk(KERN_WARNING "pm3fb: refusing to use a likely wrong timing\n");
2810
2811 while ((mode_base[i].user_mode.width) && !done) {
2812 if ((mode_base[i].user_mode.width == temp_p.width)
2813 && (mode_base[i].user_mode.height ==
2814 temp_p.height)) {
2815 printk(KERN_NOTICE "pm3fb: using close match %s\n",
2816 mode_base[i].name);
2817 temp_p = mode_base[i].user_mode;
2818 done = 1;
2819 }
2820 i++;
2821 }
2822 if (!done)
2823 return (-EINVAL);
2824 } else {
2825 temp_p.pixclock = PICOS2KHZ(var->pixclock);
2826 if (temp_p.pixclock > PM3_MAX_PIXCLOCK) {
2827 DPRINTK(1, "pixclock too high (%uKHz)\n",
2828 temp_p.pixclock);
2829 return (-EINVAL);
2830 }
2831
2832 temp_p.hsstart = var->right_margin;
2833 temp_p.hsend = var->right_margin + var->hsync_len;
2834 temp_p.hbend =
2835 var->right_margin + var->hsync_len + var->left_margin;
2836 temp_p.htotal = xres + temp_p.hbend;
2837
2838 temp_p.vsstart = var->lower_margin;
2839 temp_p.vsend = var->lower_margin + var->vsync_len;
2840 temp_p.vbend =
2841 var->lower_margin + var->vsync_len + var->upper_margin;
2842 temp_p.vtotal = var->yres + temp_p.vbend;
2843
2844 temp_p.stride = temp_p.width;
2845
2846 DPRINTK(2, "Using %d * %d, %d Khz, stride is %08x\n",
2847 temp_p.width, temp_p.height, temp_p.pixclock,
2848 temp_p.stride);
2849
2850 temp_p.base =
2851 pm3fb_Shiftbpp(l_fb_info, temp_p.depth,
2852 (var->yoffset * xres) + var->xoffset);
2853 526
2854 temp_p.video = 0; 527 if (info->var.activate == FB_ACTIVATE_NOW)
2855 528 par->video |= PM3VideoControl_ENABLE;
2856 if (var->sync & FB_SYNC_HOR_HIGH_ACT) 529 else {
2857 temp_p.video |= PM3VideoControl_HSYNC_ACTIVE_HIGH; 530 par->video |= PM3VideoControl_DISABLE;
2858 else 531 DPRINTK("PM3Video disabled\n");
2859 temp_p.video |= PM3VideoControl_HSYNC_ACTIVE_LOW;
2860
2861 if (var->sync & FB_SYNC_VERT_HIGH_ACT)
2862 temp_p.video |= PM3VideoControl_VSYNC_ACTIVE_HIGH;
2863 else
2864 temp_p.video |= PM3VideoControl_VSYNC_ACTIVE_LOW;
2865
2866 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_INTERLACED) {
2867 DPRINTK(1, "Interlaced mode not supported\n\n");
2868 return (-EINVAL);
2869 }
2870
2871 if ((var->vmode & FB_VMODE_MASK) == FB_VMODE_DOUBLE)
2872 temp_p.video |= PM3VideoControl_LINE_DOUBLE_ON;
2873 else
2874 temp_p.video |= PM3VideoControl_LINE_DOUBLE_OFF;
2875
2876 if (var->activate == FB_ACTIVATE_NOW)
2877 temp_p.video |= PM3VideoControl_ENABLE;
2878 else {
2879 temp_p.video |= PM3VideoControl_DISABLE;
2880 DPRINTK(2, "PM3Video disabled\n");
2881 }
2882
2883 switch (temp_p.depth) {
2884 case 8:
2885 temp_p.video |= PM3VideoControl_PIXELSIZE_8BIT;
2886 break;
2887 case 12:
2888 case 15:
2889 case 16:
2890 temp_p.video |= PM3VideoControl_PIXELSIZE_16BIT;
2891 break;
2892 case 32:
2893 temp_p.video |= PM3VideoControl_PIXELSIZE_32BIT;
2894 break;
2895 default:
2896 DPRINTK(1, "Unsupported depth\n");
2897 break;
2898 }
2899 } 532 }
2900 (*p) = temp_p; 533 switch (depth) {
2901
2902#ifdef PM3FB_USE_ACCEL
2903 if (var->accel_flags & FB_ACCELF_TEXT)
2904 noaccel[l_fb_info->board_num] = 0;
2905 else
2906 noaccel[l_fb_info->board_num] = 1;
2907#endif /* PM3FB_USE_ACCEL */
2908
2909 return (0);
2910}
2911
2912static void pm3fb_encode_depth(struct fb_var_screeninfo *var, long d)
2913{
2914 switch (d) {
2915 case 8: 534 case 8:
2916 var->red.length = var->green.length = var->blue.length = 8; 535 par->video |= PM3VideoControl_PIXELSIZE_8BIT;
2917 var->red.offset = var->green.offset = var->blue.offset = 0;
2918 var->transp.offset = var->transp.length = 0;
2919 break; 536 break;
2920
2921 case 12: 537 case 12:
2922 var->red.offset = 8;
2923 var->red.length = 4;
2924 var->green.offset = 4;
2925 var->green.length = 4;
2926 var->blue.offset = 0;
2927 var->blue.length = 4;
2928 var->transp.offset = 12;
2929 var->transp.length = 4;
2930 break;
2931
2932 case 15: 538 case 15:
2933 var->red.offset = 10;
2934 var->red.length = 5;
2935 var->green.offset = 5;
2936 var->green.length = 5;
2937 var->blue.offset = 0;
2938 var->blue.length = 5;
2939 var->transp.offset = 15;
2940 var->transp.length = 1;
2941 break;
2942
2943 case 16: 539 case 16:
2944 var->red.offset = 11; 540 par->video |= PM3VideoControl_PIXELSIZE_16BIT;
2945 var->red.length = 5;
2946 var->green.offset = 5;
2947 var->green.length = 6;
2948 var->blue.offset = 0;
2949 var->blue.length = 5;
2950 var->transp.offset = var->transp.length = 0;
2951 break; 541 break;
2952
2953 case 32: 542 case 32:
2954 var->transp.offset = 24; 543 par->video |= PM3VideoControl_PIXELSIZE_32BIT;
2955 var->red.offset = 16;
2956 var->green.offset = 8;
2957 var->blue.offset = 0;
2958 var->red.length = var->green.length =
2959 var->blue.length = var->transp.length = 8;
2960 break; 544 break;
2961
2962 default: 545 default:
2963 DPRINTK(1, "Unsupported depth %ld\n", d); 546 DPRINTK("Unsupported depth\n");
2964 break; 547 break;
2965 } 548 }
2966}
2967
2968static int pm3fb_encode_var(struct fb_var_screeninfo *var,
2969 const void *par, struct fb_info_gen *info)
2970{
2971 struct pm3fb_par *p = (struct pm3fb_par *) par;
2972 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
2973
2974 u32 base;
2975
2976 DTRACE;
2977
2978 DASSERT((var != NULL), "fb_var_screeninfo* not NULL");
2979 DASSERT((p != NULL), "pm3fb_par* not NULL");
2980 DASSERT((info != NULL), "fb_info_gen* not NULL");
2981
2982 memset(var, 0, sizeof(struct fb_var_screeninfo));
2983
2984#ifdef PM3FB_USE_ACCEL
2985 if (!(noaccel[l_fb_info->board_num]))
2986 var->accel_flags |= FB_ACCELF_TEXT;
2987#endif /* PM3FB_USE_ACCEL */
2988
2989 var->xres_virtual = p->width;
2990 var->yres_virtual = p->height;
2991 var->xres = p->htotal - p->hbend;
2992 var->yres = p->vtotal - p->vbend;
2993
2994 DPRINTK(2, "xres = %d, yres : %d\n", var->xres, var->yres);
2995
2996 var->right_margin = p->hsstart;
2997 var->hsync_len = p->hsend - p->hsstart;
2998 var->left_margin = p->hbend - p->hsend;
2999 var->lower_margin = p->vsstart;
3000 var->vsync_len = p->vsend - p->vsstart;
3001 var->upper_margin = p->vbend - p->vsend;
3002 var->bits_per_pixel = depth2bpp(p->depth);
3003
3004 pm3fb_encode_depth(var, p->depth);
3005
3006 base = pm3fb_Unshiftbpp(l_fb_info, p->depth, p->base);
3007
3008 var->xoffset = base % var->xres;
3009 var->yoffset = base / var->xres;
3010
3011 var->height = var->width = -1;
3012
3013 var->pixclock = KHZ2PICOS(p->pixclock);
3014
3015 if ((p->video & PM3VideoControl_HSYNC_MASK) ==
3016 PM3VideoControl_HSYNC_ACTIVE_HIGH)
3017 var->sync |= FB_SYNC_HOR_HIGH_ACT;
3018 if ((p->video & PM3VideoControl_VSYNC_MASK) ==
3019 PM3VideoControl_VSYNC_ACTIVE_HIGH)
3020 var->sync |= FB_SYNC_VERT_HIGH_ACT;
3021 if (p->video & PM3VideoControl_LINE_DOUBLE_ON)
3022 var->vmode = FB_VMODE_DOUBLE;
3023
3024 return (0);
3025}
3026
3027static void pm3fb_get_par(void *par, struct fb_info_gen *info)
3028{
3029 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
3030
3031 DTRACE;
3032
3033 if (!current_par_valid[l_fb_info->board_num]) {
3034 if (l_fb_info->use_current)
3035 pm3fb_read_mode(l_fb_info, l_fb_info->current_par);
3036 else
3037 memcpy(l_fb_info->current_par,
3038 &(mode_base[0].user_mode),
3039 sizeof(struct pm3fb_par));
3040 current_par_valid[l_fb_info->board_num] = 1;
3041 }
3042 *((struct pm3fb_par *) par) = *(l_fb_info->current_par);
3043}
3044
3045static void pm3fb_set_par(const void *par, struct fb_info_gen *info)
3046{
3047 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
3048
3049 DTRACE;
3050 549
3051 *(l_fb_info->current_par) = *((struct pm3fb_par *) par); 550 info->fix.visual =
3052 current_par_valid[l_fb_info->board_num] = 1; 551 (depth == 8) ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
552 info->fix.line_length = ((info->var.xres_virtual + 7) & ~7)
553 * depth / 8;
3053 554
3054 pm3fb_write_mode(l_fb_info); 555/* pm3fb_clear_memory(info, 0);*/
3055 556 pm3fb_clear_colormap(par, 0, 0, 0);
3056#ifdef PM3FB_USE_ACCEL 557 PM3_WRITE_DAC_REG(par, PM3RD_CursorMode,
3057 pm3fb_init_engine(l_fb_info); 558 PM3RD_CursorMode_CURSOR_DISABLE);
3058#endif /* PM3FB_USE_ACCEL */ 559 pm3fb_write_mode(info);
3059} 560 return 0;
3060
3061static void pm3fb_set_color(struct pm3fb_info *l_fb_info,
3062 unsigned char regno, unsigned char r,
3063 unsigned char g, unsigned char b)
3064{
3065 DTRACE;
3066
3067 PM3_SLOW_WRITE_REG(PM3RD_PaletteWriteAddress, regno);
3068 PM3_SLOW_WRITE_REG(PM3RD_PaletteData, r);
3069 PM3_SLOW_WRITE_REG(PM3RD_PaletteData, g);
3070 PM3_SLOW_WRITE_REG(PM3RD_PaletteData, b);
3071}
3072
3073static int pm3fb_getcolreg(unsigned regno, unsigned *red, unsigned *green,
3074 unsigned *blue, unsigned *transp,
3075 struct fb_info *info)
3076{
3077 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
3078
3079 DTRACE;
3080
3081 if (regno < 256) {
3082 *red =
3083 l_fb_info->palette[regno].red << 8 | l_fb_info->
3084 palette[regno].red;
3085 *green =
3086 l_fb_info->palette[regno].green << 8 | l_fb_info->
3087 palette[regno].green;
3088 *blue =
3089 l_fb_info->palette[regno].blue << 8 | l_fb_info->
3090 palette[regno].blue;
3091 *transp =
3092 l_fb_info->palette[regno].transp << 8 | l_fb_info->
3093 palette[regno].transp;
3094 }
3095 return (regno > 255);
3096} 561}
3097 562
3098static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green, 563static int pm3fb_setcolreg(unsigned regno, unsigned red, unsigned green,
3099 unsigned blue, unsigned transp, 564 unsigned blue, unsigned transp,
3100 struct fb_info *info) 565 struct fb_info *info)
3101{ 566{
3102 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info; 567 struct pm3_par *par = info->par;
3103 568
3104 DTRACE; 569 if (regno >= 256) /* no. of hw registers */
570 return -EINVAL;
571
572 /* grayscale works only partially under directcolor */
573 if (info->var.grayscale) {
574 /* grayscale = 0.30*R + 0.59*G + 0.11*B */
575 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
576 }
577
578 /* Directcolor:
579 * var->{color}.offset contains start of bitfield
580 * var->{color}.length contains length of bitfield
581 * {hardwarespecific} contains width of DAC
582 * pseudo_palette[X] is programmed to (X << red.offset) |
583 * (X << green.offset) |
584 * (X << blue.offset)
585 * RAMDAC[X] is programmed to (red, green, blue)
586 * color depth = SUM(var->{color}.length)
587 *
588 * Pseudocolor:
589 * var->{color}.offset is 0
590 * var->{color}.length contains width of DAC or the number of unique
591 * colors available (color depth)
592 * pseudo_palette is not used
593 * RAMDAC[X] is programmed to (red, green, blue)
594 * color depth = var->{color}.length
595 */
3105 596
3106 if (regno < 16) { 597 /*
3107 switch (l_fb_info->current_par->depth) { 598 * This is the point where the color is converted to something that
3108#ifdef FBCON_HAS_CFB8 599 * is acceptable by the hardware.
600 */
601#define CNVT_TOHW(val,width) ((((val)<<(width))+0x7FFF-(val))>>16)
602 red = CNVT_TOHW(red, info->var.red.length);
603 green = CNVT_TOHW(green, info->var.green.length);
604 blue = CNVT_TOHW(blue, info->var.blue.length);
605 transp = CNVT_TOHW(transp, info->var.transp.length);
606#undef CNVT_TOHW
607
608 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
609 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
610 u32 v;
611
612 if (regno >= 16)
613 return -EINVAL;
614
615 v = (red << info->var.red.offset) |
616 (green << info->var.green.offset) |
617 (blue << info->var.blue.offset) |
618 (transp << info->var.transp.offset);
619
620 switch (info->var.bits_per_pixel) {
3109 case 8: 621 case 8:
3110 break; 622 break;
3111#endif
3112#ifdef FBCON_HAS_CFB16
3113 case 12:
3114 l_fb_info->cmap.cmap12[regno] =
3115 (((u32) red & 0xf000) >> 4) |
3116 (((u32) green & 0xf000) >> 8) |
3117 (((u32) blue & 0xf000) >> 12);
3118 break;
3119
3120 case 15:
3121 l_fb_info->cmap.cmap15[regno] =
3122 (((u32) red & 0xf800) >> 1) |
3123 (((u32) green & 0xf800) >> 6) |
3124 (((u32) blue & 0xf800) >> 11);
3125 break;
3126
3127 case 16: 623 case 16:
3128 l_fb_info->cmap.cmap16[regno] = 624 case 24:
3129 ((u32) red & 0xf800) |
3130 (((u32) green & 0xfc00) >> 5) |
3131 (((u32) blue & 0xf800) >> 11);
3132 break;
3133#endif
3134#ifdef FBCON_HAS_CFB32
3135 case 32: 625 case 32:
3136 l_fb_info->cmap.cmap32[regno] = 626 ((u32*)(info->pseudo_palette))[regno] = v;
3137 (((u32) transp & 0xff00) << 16) |
3138 (((u32) red & 0xff00) << 8) |
3139 (((u32) green & 0xff00)) |
3140 (((u32) blue & 0xff00) >> 8);
3141 break;
3142#endif
3143 default:
3144 DPRINTK(1, "bad depth %u\n",
3145 l_fb_info->current_par->depth);
3146 break; 627 break;
3147 } 628 }
629 return 0;
3148 } 630 }
3149 if (regno < 256) { 631 else if (info->fix.visual == FB_VISUAL_PSEUDOCOLOR)
3150 l_fb_info->palette[regno].red = red >> 8; 632 pm3fb_set_color(par, regno, red, green, blue);
3151 l_fb_info->palette[regno].green = green >> 8; 633
3152 l_fb_info->palette[regno].blue = blue >> 8; 634 return 0;
3153 l_fb_info->palette[regno].transp = transp >> 8;
3154 if (l_fb_info->current_par->depth == 8)
3155 pm3fb_set_color(l_fb_info, regno, red >> 8,
3156 green >> 8, blue >> 8);
3157 }
3158 return (regno > 255);
3159} 635}
3160 636
3161static int pm3fb_blank(int blank_mode, struct fb_info_gen *info) 637static int pm3fb_pan_display(struct fb_var_screeninfo *var,
638 struct fb_info *info)
3162{ 639{
3163 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info; 640 struct pm3_par *par = info->par;
3164 u32 video; 641 const u32 xres = (var->xres + 31) & ~31;
3165
3166 DTRACE;
3167 642
3168 if (!current_par_valid[l_fb_info->board_num]) 643 par->base = pm3fb_shift_bpp(var->bits_per_pixel,
3169 return (1); 644 (var->yoffset * xres)
645 + var->xoffset);
646 PM3_SLOW_WRITE_REG(par, PM3ScreenBase, par->base);
647 return 0;
648}
3170 649
3171 video = l_fb_info->current_par->video; 650static int pm3fb_blank(int blank_mode, struct fb_info *info)
651{
652 struct pm3_par *par = info->par;
653 u32 video = par->video;
3172 654
3173 /* 655 /*
3174 * Oxygen VX1 - it appears that setting PM3VideoControl and 656 * Oxygen VX1 - it appears that setting PM3VideoControl and
@@ -3181,454 +663,345 @@ static int pm3fb_blank(int blank_mode, struct fb_info_gen *info)
3181 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH | 663 video |= PM3VideoControl_HSYNC_ACTIVE_HIGH |
3182 PM3VideoControl_VSYNC_ACTIVE_HIGH; 664 PM3VideoControl_VSYNC_ACTIVE_HIGH;
3183 665
3184 if (blank_mode > 0) { 666 switch (blank_mode) {
3185 switch (blank_mode - 1) { 667 case FB_BLANK_UNBLANK:
3186 668 video = video | PM3VideoControl_ENABLE;
3187 case VESA_NO_BLANKING: /* FIXME */
3188 video = video & ~(PM3VideoControl_ENABLE);
3189 break;
3190
3191 case VESA_HSYNC_SUSPEND:
3192 video = video & ~(PM3VideoControl_HSYNC_MASK |
3193 PM3VideoControl_BLANK_ACTIVE_LOW);
3194 break;
3195 case VESA_VSYNC_SUSPEND:
3196 video = video & ~(PM3VideoControl_VSYNC_MASK |
3197 PM3VideoControl_BLANK_ACTIVE_LOW);
3198 break;
3199 case VESA_POWERDOWN:
3200 video = video & ~(PM3VideoControl_HSYNC_MASK |
3201 PM3VideoControl_VSYNC_MASK |
3202 PM3VideoControl_BLANK_ACTIVE_LOW);
3203 break;
3204 default:
3205 DPRINTK(1, "Unsupported blanking %d\n",
3206 blank_mode);
3207 return (1);
3208 break;
3209 }
3210 }
3211
3212 PM3_SLOW_WRITE_REG(PM3VideoControl, video);
3213
3214 return (0);
3215}
3216
3217static void pm3fb_set_disp(const void *par, struct display *disp,
3218 struct fb_info_gen *info)
3219{
3220 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
3221 struct pm3fb_par *p = (struct pm3fb_par *) par;
3222 u32 flags;
3223
3224 DTRACE;
3225
3226 local_irq_save(flags);
3227 info->info.screen_base = l_fb_info->v_fb;
3228 switch (p->depth) {
3229#ifdef FBCON_HAS_CFB8
3230 case 8:
3231#ifdef PM3FB_USE_ACCEL
3232 if (!(noaccel[l_fb_info->board_num]))
3233 disp->dispsw = &pm3fb_cfb8;
3234 else
3235#endif /* PM3FB_USE_ACCEL */
3236 disp->dispsw = &fbcon_cfb8;
3237 break; 669 break;
3238#endif 670 case FB_BLANK_NORMAL: /* FIXME */
3239#ifdef FBCON_HAS_CFB16 671 video = video & ~(PM3VideoControl_ENABLE);
3240 case 12:
3241#ifdef PM3FB_USE_ACCEL
3242 if (!(noaccel[l_fb_info->board_num]))
3243 disp->dispsw = &pm3fb_cfb16;
3244 else
3245#endif /* PM3FB_USE_ACCEL */
3246 disp->dispsw = &fbcon_cfb16;
3247 disp->dispsw_data = l_fb_info->cmap.cmap12;
3248 break; 672 break;
3249 case 15: 673 case FB_BLANK_HSYNC_SUSPEND:
3250#ifdef PM3FB_USE_ACCEL 674 video = video & ~(PM3VideoControl_HSYNC_MASK |
3251 if (!(noaccel[l_fb_info->board_num])) 675 PM3VideoControl_BLANK_ACTIVE_LOW);
3252 disp->dispsw = &pm3fb_cfb16;
3253 else
3254#endif /* PM3FB_USE_ACCEL */
3255 disp->dispsw = &fbcon_cfb16;
3256 disp->dispsw_data = l_fb_info->cmap.cmap15;
3257 break; 676 break;
3258 case 16: 677 case FB_BLANK_VSYNC_SUSPEND:
3259#ifdef PM3FB_USE_ACCEL 678 video = video & ~(PM3VideoControl_VSYNC_MASK |
3260 if (!(noaccel[l_fb_info->board_num])) 679 PM3VideoControl_BLANK_ACTIVE_LOW);
3261 disp->dispsw = &pm3fb_cfb16;
3262 else
3263#endif /* PM3FB_USE_ACCEL */
3264 disp->dispsw = &fbcon_cfb16;
3265 disp->dispsw_data = l_fb_info->cmap.cmap16;
3266 break; 680 break;
3267#endif 681 case FB_BLANK_POWERDOWN:
3268#ifdef FBCON_HAS_CFB32 682 video = video & ~(PM3VideoControl_HSYNC_MASK |
3269 case 32: 683 PM3VideoControl_VSYNC_MASK |
3270#ifdef PM3FB_USE_ACCEL 684 PM3VideoControl_BLANK_ACTIVE_LOW);
3271 if (!(noaccel[l_fb_info->board_num]))
3272 disp->dispsw = &pm3fb_cfb32;
3273 else
3274#endif /* PM3FB_USE_ACCEL */
3275 disp->dispsw = &fbcon_cfb32;
3276 disp->dispsw_data = l_fb_info->cmap.cmap32;
3277 break; 685 break;
3278#endif /* FBCON_HAS_CFB32 */
3279 default: 686 default:
3280 disp->dispsw = &fbcon_dummy; 687 DPRINTK("Unsupported blanking %d\n", blank_mode);
3281 DPRINTK(1, "Invalid depth, using fbcon_dummy\n"); 688 return 1;
3282 break;
3283 } 689 }
3284 local_irq_restore(flags); 690
691 PM3_SLOW_WRITE_REG(par,PM3VideoControl, video);
692
693 return 0;
3285} 694}
3286 695
3287/* */ 696 /*
3288static void pm3fb_detect(void) 697 * Frame buffer operations
3289{ 698 */
3290 struct pci_dev *dev_array[PM3_MAX_BOARD];
3291 struct pci_dev *dev = NULL;
3292 struct pm3fb_info *l_fb_info = &(fb_info[0]);
3293 unsigned long i, j, done;
3294 699
3295 DTRACE; 700static struct fb_ops pm3fb_ops = {
701 .owner = THIS_MODULE,
702 .fb_check_var = pm3fb_check_var,
703 .fb_set_par = pm3fb_set_par,
704 .fb_setcolreg = pm3fb_setcolreg,
705 .fb_pan_display = pm3fb_pan_display,
706 .fb_fillrect = cfb_fillrect, /* Needed !!! */
707 .fb_copyarea = cfb_copyarea, /* Needed !!! */
708 .fb_imageblit = cfb_imageblit, /* Needed !!! */
709 .fb_blank = pm3fb_blank,
710};
3296 711
3297 for (i = 0; i < PM3_MAX_BOARD; i++) { 712/* ------------------------------------------------------------------------- */
3298 dev_array[i] = NULL;
3299 fb_info[i].dev = NULL;
3300 }
3301 713
3302 dev = pci_get_device(PCI_VENDOR_ID_3DLABS, 714 /*
3303 PCI_DEVICE_ID_3DLABS_PERMEDIA3, dev); 715 * Initialization
716 */
3304 717
3305 for (i = 0; ((i < PM3_MAX_BOARD) && dev); i++) { 718/* mmio register are already mapped when this function is called */
3306 dev_array[i] = dev; 719/* the pm3fb_fix.smem_start is also set */
3307 dev = pci_get_device(PCI_VENDOR_ID_3DLABS, 720static unsigned long pm3fb_size_memory(struct pm3_par *par)
3308 PCI_DEVICE_ID_3DLABS_PERMEDIA3, dev); 721{
3309 } 722 unsigned long memsize = 0, tempBypass, i, temp1, temp2;
723 unsigned char __iomem *screen_mem;
3310 724
3311 if (dev) { /* more than PM3_MAX_BOARD */ 725 pm3fb_fix.smem_len = 64 * 1024 * 1024; /* request full aperture size */
3312 printk(KERN_WARNING "pm3fb: Warning: more than %d boards found\n", 726 /* Linear frame buffer - request region and map it. */
3313 PM3_MAX_BOARD); 727 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
728 "pm3fb smem")) {
729 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
730 return 0;
3314 } 731 }
3315 732 screen_mem =
3316 if (!dev_array[0]) { /* not a single board, abort */ 733 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
3317 return; 734 if (!screen_mem) {
735 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
736 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
737 return 0;
3318 } 738 }
3319 739
3320 /* allocate user-defined boards */ 740 /* TODO: card-specific stuff, *before* accessing *any* FB memory */
3321 for (i = 0; i < PM3_MAX_BOARD; i++) { 741 /* For Appian Jeronimo 2000 board second head */
3322 if ((bus[i] >= 0) && (slot[i] >= 0) && (func[i] >= 0)) { 742
3323 for (j = 0; j < PM3_MAX_BOARD; j++) { 743 tempBypass = PM3_READ_REG(par, PM3MemBypassWriteMask);
3324 if ((dev_array[j] != NULL) && 744
3325 (dev_array[j]->bus->number == bus[i]) 745 DPRINTK("PM3MemBypassWriteMask was: 0x%08lx\n", tempBypass);
3326 && (PCI_SLOT(dev_array[j]->devfn) == 746
3327 slot[i]) 747 PM3_SLOW_WRITE_REG(par, PM3MemBypassWriteMask, 0xFFFFFFFF);
3328 && (PCI_FUNC(dev_array[j]->devfn) == 748
3329 func[i])) { 749 /* pm3 split up memory, replicates, and do a lot of nasty stuff IMHO ;-) */
3330 fb_info[i].dev = dev_array[j]; 750 for (i = 0; i < 32; i++) {
3331 dev_array[j] = NULL; 751 fb_writel(i * 0x00345678,
3332 } 752 (screen_mem + (i * 1048576)));
3333 } 753 mb();
3334 } 754 temp1 = fb_readl((screen_mem + (i * 1048576)));
755
756 /* Let's check for wrapover, write will fail at 16MB boundary */
757 if (temp1 == (i * 0x00345678))
758 memsize = i;
759 else
760 break;
3335 } 761 }
3336 /* allocate remaining boards */ 762
3337 for (i = 0; i < PM3_MAX_BOARD; i++) { 763 DPRINTK("First detect pass already got %ld MB\n", memsize + 1);
3338 if (fb_info[i].dev == NULL) { 764
3339 done = 0; 765 if (memsize + 1 == i) {
3340 for (j = 0; ((j < PM3_MAX_BOARD) && (!done)); j++) { 766 for (i = 0; i < 32; i++) {
3341 if (dev_array[j] != NULL) { 767 /* Clear first 32MB ; 0 is 0, no need to byteswap */
3342 fb_info[i].dev = dev_array[j]; 768 writel(0x0000000,
3343 dev_array[j] = NULL; 769 (screen_mem + (i * 1048576)));
3344 done = 1; 770 mb();
3345 }
3346 }
3347 } 771 }
3348 }
3349 772
3350 /* at that point, all PCI Permedia3 are detected and allocated */ 773 for (i = 32; i < 64; i++) {
3351 /* now, initialize... or not */ 774 fb_writel(i * 0x00345678,
3352 for (i = 0; i < PM3_MAX_BOARD; i++) { 775 (screen_mem + (i * 1048576)));
3353 l_fb_info = &(fb_info[i]); 776 mb();
3354 if (l_fb_info->dev && !disable[i]) { /* PCI device was found and not disabled by user */ 777 temp1 =
3355 DPRINTK(2, 778 fb_readl((screen_mem + (i * 1048576)));
3356 "found @%lx Vendor %lx Device %lx ; base @ : %lx - %lx - %lx - %lx - %lx - %lx, irq %ld\n", 779 temp2 =
3357 (unsigned long) l_fb_info->dev, 780 fb_readl((screen_mem + ((i - 32) * 1048576)));
3358 (unsigned long) l_fb_info->dev->vendor, 781 /* different value, different RAM... */
3359 (unsigned long) l_fb_info->dev->device, 782 if ((temp1 == (i * 0x00345678)) && (temp2 == 0))
3360 (unsigned long) 783 memsize = i;
3361 pci_resource_start(l_fb_info->dev, 0), 784 else
3362 (unsigned long) 785 break;
3363 pci_resource_start(l_fb_info->dev, 1),
3364 (unsigned long)
3365 pci_resource_start(l_fb_info->dev, 2),
3366 (unsigned long)
3367 pci_resource_start(l_fb_info->dev, 3),
3368 (unsigned long)
3369 pci_resource_start(l_fb_info->dev, 4),
3370 (unsigned long)
3371 pci_resource_start(l_fb_info->dev, 5),
3372 (unsigned long) l_fb_info->dev->irq);
3373
3374 l_fb_info->pIOBase =
3375 (unsigned char *)
3376 pci_resource_start(l_fb_info->dev, 0);
3377#ifdef __BIG_ENDIAN
3378 l_fb_info->pIOBase += PM3_REGS_SIZE;
3379#endif
3380 l_fb_info->vIOBase = (unsigned char *) -1;
3381 l_fb_info->p_fb =
3382 (unsigned char *)
3383 pci_resource_start(l_fb_info->dev, 1);
3384 l_fb_info->v_fb = (unsigned char *) -1;
3385
3386 if (!request_mem_region
3387 ((unsigned long)l_fb_info->p_fb, 64 * 1024 * 1024, /* request full aperture size */
3388 "pm3fb")) {
3389 printk
3390 (KERN_ERR "pm3fb: Error: couldn't request framebuffer memory, board #%ld\n",
3391 l_fb_info->board_num);
3392 continue;
3393 }
3394 if (!request_mem_region
3395 ((unsigned long)l_fb_info->pIOBase, PM3_REGS_SIZE,
3396 "pm3fb I/O regs")) {
3397 printk
3398 (KERN_ERR "pm3fb: Error: couldn't request IObase memory, board #%ld\n",
3399 l_fb_info->board_num);
3400 continue;
3401 }
3402 if (forcesize[l_fb_info->board_num])
3403 l_fb_info->fb_size = forcesize[l_fb_info->board_num];
3404
3405 l_fb_info->fb_size =
3406 pm3fb_size_memory(l_fb_info);
3407 if (l_fb_info->fb_size) {
3408 (void) pci_enable_device(l_fb_info->dev);
3409 pm3fb_common_init(l_fb_info);
3410 } else
3411 printk(KERN_ERR "pm3fb: memory problem, not enabling board #%ld\n", l_fb_info->board_num);
3412 } 786 }
3413 } 787 }
3414} 788 DPRINTK("Second detect pass got %ld MB\n", memsize + 1);
3415 789
3416static int pm3fb_pan_display(const struct fb_var_screeninfo *var, 790 PM3_SLOW_WRITE_REG(par, PM3MemBypassWriteMask, tempBypass);
3417 struct fb_info_gen *info)
3418{
3419 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info;
3420 791
3421 DTRACE; 792 iounmap(screen_mem);
793 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
794 memsize = 1048576 * (memsize + 1);
3422 795
3423 if (!current_par_valid[l_fb_info->board_num]) 796 DPRINTK("Returning 0x%08lx bytes\n", memsize);
3424 return -EINVAL;
3425 797
3426 l_fb_info->current_par->base = /* in 128 bits chunk - i.e. AFTER Shiftbpp */ 798 return memsize;
3427 pm3fb_Shiftbpp(l_fb_info,
3428 l_fb_info->current_par->depth,
3429 (var->yoffset * l_fb_info->current_par->width) +
3430 var->xoffset);
3431 PM3_SLOW_WRITE_REG(PM3ScreenBase, l_fb_info->current_par->base);
3432 return 0;
3433} 799}
3434 800
3435static int pm3fb_ioctl(struct fb_info *info, u_int cmd, u_long arg) 801static int __devinit pm3fb_probe(struct pci_dev *dev,
802 const struct pci_device_id *ent)
3436{ 803{
3437 struct pm3fb_info *l_fb_info = (struct pm3fb_info *) info; 804 struct fb_info *info;
3438 u32 cm, i; 805 struct pm3_par *par;
3439#ifdef PM3FB_MASTER_DEBUG 806 struct device* device = &dev->dev; /* for pci drivers */
3440 char cc[3]; 807 int err, retval = -ENXIO;
3441#endif /* PM3FB_MASTER_DEBUG */
3442 808
3443 switch(cmd) 809 err = pci_enable_device(dev);
3444 { 810 if (err) {
3445#ifdef PM3FB_MASTER_DEBUG 811 printk(KERN_WARNING "pm3fb: Can't enable PCI dev: %d\n", err);
3446 case PM3FBIO_CLEARMEMORY: 812 return err;
3447 if (copy_from_user(&cm, (void *)arg, sizeof(u32))) 813 }
3448 return(-EFAULT); 814 /*
3449 pm3fb_clear_memory(l_fb_info, cm); 815 * Dynamically allocate info and par
3450 return(0); 816 */
3451 break; 817 info = framebuffer_alloc(sizeof(struct pm3_par), device);
3452 818
3453 case PM3FBIO_CLEARCMAP: 819 if (!info)
3454 if (copy_from_user(cc, (void*)arg, 3 * sizeof(char))) 820 return -ENOMEM;
3455 return(-EFAULT); 821 par = info->par;
3456 pm3fb_clear_colormap(l_fb_info, cc[0], cc[1], cc[2]);
3457 return(0);
3458 break;
3459#endif /* PM3FB_MASTER_DEBUG */
3460
3461 case PM3FBIO_RESETCHIP:
3462 cm = 1;
3463 PM3_SLOW_WRITE_REG(PM3ResetStatus, 1);
3464 for (i = 0 ; (i < 10000) && cm ; i++)
3465 {
3466 PM3_DELAY(10);
3467 cm = PM3_READ_REG(PM3ResetStatus);
3468 }
3469 if (cm)
3470 {
3471 printk(KERN_ERR "pm3fb: chip reset failed with status 0x%x\n", cm);
3472 return(-EIO);
3473 }
3474 /* first thing first, reload memory timings */
3475 pm3fb_write_memory_timings(l_fb_info);
3476#ifdef PM3FB_USE_ACCEL
3477 pm3fb_init_engine(l_fb_info);
3478#endif /* PM3FB_USE_ACCEL */
3479 pm3fb_write_mode(l_fb_info);
3480 return(0);
3481 break;
3482 822
3483 default: 823 /*
3484 DPRINTK(2, "unknown ioctl: %d (%x)\n", cmd, cmd); 824 * Here we set the screen_base to the virtual memory address
3485 return(-EINVAL); 825 * for the framebuffer.
826 */
827 pm3fb_fix.mmio_start = pci_resource_start(dev, 0);
828 pm3fb_fix.mmio_len = PM3_REGS_SIZE;
829
830 /* Registers - request region and map it. */
831 if (!request_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len,
832 "pm3fb regbase")) {
833 printk(KERN_WARNING "pm3fb: Can't reserve regbase.\n");
834 goto err_exit_neither;
835 }
836 par->v_regs =
837 ioremap_nocache(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
838 if (!par->v_regs) {
839 printk(KERN_WARNING "pm3fb: Can't remap %s register area.\n",
840 pm3fb_fix.id);
841 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
842 goto err_exit_neither;
843 }
844
845#if defined(__BIG_ENDIAN)
846 pm3fb_fix.mmio_start += PM3_REGS_SIZE;
847 DPRINTK("Adjusting register base for big-endian.\n");
848#endif
849 /* Linear frame buffer - request region and map it. */
850 pm3fb_fix.smem_start = pci_resource_start(dev, 1);
851 pm3fb_fix.smem_len = pm3fb_size_memory(par);
852 if (!pm3fb_fix.smem_len)
853 {
854 printk(KERN_WARNING "pm3fb: Can't find memory on board.\n");
855 goto err_exit_mmio;
3486 } 856 }
3487} 857 if (!request_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len,
858 "pm3fb smem")) {
859 printk(KERN_WARNING "pm3fb: Can't reserve smem.\n");
860 goto err_exit_mmio;
861 }
862 info->screen_base =
863 ioremap_nocache(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
864 if (!info->screen_base) {
865 printk(KERN_WARNING "pm3fb: Can't ioremap smem area.\n");
866 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
867 goto err_exit_mmio;
868 }
869 info->screen_size = pm3fb_fix.smem_len;
3488 870
3489/* ****************************************** */ 871 info->fbops = &pm3fb_ops;
3490/* ***** standard FB API init functions ***** */
3491/* ****************************************** */
3492 872
3493int __init pm3fb_setup(char *options) 873 par->video = PM3_READ_REG(par, PM3VideoControl);
3494{
3495 long opsi = strlen(options);
3496 874
3497 DTRACE; 875 info->fix = pm3fb_fix;
876 info->pseudo_palette = par->palette;
877 info->flags = FBINFO_DEFAULT;/* | FBINFO_HWACCEL_YPAN;*/
3498 878
3499 memcpy(g_options, options, 879 /*
3500 ((opsi + 1) > 880 * This should give a reasonable default video mode. The following is
3501 PM3_OPTIONS_SIZE) ? PM3_OPTIONS_SIZE : (opsi + 1)); 881 * done when we can set a video mode.
3502 g_options[PM3_OPTIONS_SIZE - 1] = 0; 882 */
883 if (!mode_option)
884 mode_option = "640x480@60";
885
886 retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
887
888 if (!retval || retval == 4) {
889 retval = -EINVAL;
890 goto err_exit_both;
891 }
892
893 /* This has to been done !!! */
894 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
895 retval = -ENOMEM;
896 goto err_exit_both;
897 }
3503 898
3504 return (0); 899 /*
900 * For drivers that can...
901 */
902 pm3fb_check_var(&info->var, info);
903
904 if (register_framebuffer(info) < 0) {
905 retval = -EINVAL;
906 goto err_exit_all;
907 }
908 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
909 info->fix.id);
910 pci_set_drvdata(dev, info); /* or dev_set_drvdata(device, info) */
911 return 0;
912
913 err_exit_all:
914 fb_dealloc_cmap(&info->cmap);
915 err_exit_both:
916 iounmap(info->screen_base);
917 release_mem_region(pm3fb_fix.smem_start, pm3fb_fix.smem_len);
918 err_exit_mmio:
919 iounmap(par->v_regs);
920 release_mem_region(pm3fb_fix.mmio_start, pm3fb_fix.mmio_len);
921 err_exit_neither:
922 framebuffer_release(info);
923 return retval;
3505} 924}
3506 925
3507int __init pm3fb_init(void) 926 /*
927 * Cleanup
928 */
929static void __devexit pm3fb_remove(struct pci_dev *dev)
3508{ 930{
3509 DTRACE; 931 struct fb_info *info = pci_get_drvdata(dev);
3510 932
3511 DPRINTK(2, "This is pm3fb.c, CVS version: $Header: /cvsroot/linux/drivers/video/pm3fb.c,v 1.1 2002/02/25 19:11:06 marcelo Exp $"); 933 if (info) {
934 struct fb_fix_screeninfo *fix = &info->fix;
935 struct pm3_par *par = info->par;
3512 936
3513 pm3fb_real_setup(g_options); 937 unregister_framebuffer(info);
938 fb_dealloc_cmap(&info->cmap);
3514 939
3515 pm3fb_detect(); 940 iounmap(info->screen_base);
941 release_mem_region(fix->smem_start, fix->smem_len);
942 iounmap(par->v_regs);
943 release_mem_region(fix->mmio_start, fix->mmio_len);
3516 944
3517 if (!fb_info[0].dev) { /* not even one board ??? */ 945 pci_set_drvdata(dev, NULL);
3518 DPRINTK(1, "No PCI Permedia3 board detected\n"); 946 framebuffer_release(info);
3519 } 947 }
3520 return (0);
3521} 948}
3522 949
3523/* ************************* */ 950static struct pci_device_id pm3fb_id_table[] = {
3524/* **** Module support ***** */ 951 { PCI_VENDOR_ID_3DLABS, 0x0a,
3525/* ************************* */ 952 PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
3526 953 0xff0000, 0 },
3527#ifdef MODULE 954 { 0, }
3528MODULE_AUTHOR("Romain Dolbeau"); 955};
3529MODULE_DESCRIPTION("Permedia3 framebuffer device driver");
3530static char *mode[PM3_MAX_BOARD];
3531module_param_array(mode, charp, NULL, 0);
3532MODULE_PARM_DESC(mode,"video mode");
3533module_param_array(disable, short, NULL, 0);
3534MODULE_PARM_DESC(disable,"disable board");
3535static short off[PM3_MAX_BOARD];
3536module_param_array(off, short, NULL, 0);
3537MODULE_PARM_DESC(off,"disable board");
3538static char *pciid[PM3_MAX_BOARD];
3539module_param_array(pciid, charp, NULL, 0);
3540MODULE_PARM_DESC(pciid,"board PCI Id");
3541module_param_array(noaccel, short, NULL, 0);
3542MODULE_PARM_DESC(noaccel,"disable accel");
3543static char *font[PM3_MAX_BOARD];
3544module_param_array(font, charp, NULL, 0);
3545MODULE_PARM_DESC(font,"choose font");
3546module_param(depth, short, NULL, 0);
3547MODULE_PARM_DESC(depth,"boot-time depth");
3548module_param(printtimings, short, NULL, 0);
3549MODULE_PARM_DESC(printtimings, "print the memory timings of the card(s)");
3550module_param(forcesize, short, NULL, 0);
3551MODULE_PARM_DESC(forcesize, "force specified memory size");
3552/*
3553MODULE_SUPPORTED_DEVICE("Permedia3 PCI boards")
3554MODULE_GENERIC_TABLE(gtype,name)
3555MODULE_DEVICE_TABLE(type,name)
3556*/
3557 956
3558void pm3fb_build_options(void) 957/* For PCI drivers */
3559{ 958static struct pci_driver pm3fb_driver = {
3560 int i; 959 .name = "pm3fb",
3561 char ts[128]; 960 .id_table = pm3fb_id_table,
961 .probe = pm3fb_probe,
962 .remove = __devexit_p(pm3fb_remove),
963};
3562 964
3563 strcpy(g_options, "pm3fb"); 965MODULE_DEVICE_TABLE(pci, pm3fb_id_table);
3564 for (i = 0; i < PM3_MAX_BOARD ; i++)
3565 {
3566 if (mode[i])
3567 {
3568 sprintf(ts, ",mode:%d:%s", i, mode[i]);
3569 strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
3570 }
3571 if (disable[i] || off[i])
3572 {
3573 sprintf(ts, ",disable:%d:", i);
3574 strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
3575 }
3576 if (pciid[i])
3577 {
3578 sprintf(ts, ",pciid:%d:%s", i, pciid[i]);
3579 strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
3580 }
3581 if (noaccel[i])
3582 {
3583 sprintf(ts, ",noaccel:%d:", i);
3584 strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
3585 }
3586 if (font[i])
3587 {
3588 sprintf(ts, ",font:%d:%s", i, font[i]);
3589 strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
3590 }
3591 if (depth[i])
3592 {
3593 sprintf(ts, ",depth:%d:%d", i, depth[i]);
3594 strncat(g_options, ts, PM3_OPTIONS_SIZE - strlen(g_options));
3595 }
3596 }
3597 g_options[PM3_OPTIONS_SIZE - 1] = '\0';
3598 DPRINTK(1, "pm3fb use options: %s\n", g_options);
3599}
3600 966
3601int init_module(void) 967int __init pm3fb_init(void)
3602{ 968{
3603 DTRACE; 969 /*
970 * For kernel boot options (in 'video=pm3fb:<options>' format)
971 */
972#ifndef MODULE
973 char *option = NULL;
3604 974
3605 pm3fb_build_options(); 975 if (fb_get_options("pm3fb", &option))
976 return -ENODEV;
977 pm3fb_setup(option);
978#endif
3606 979
3607 pm3fb_init(); 980 return pci_register_driver(&pm3fb_driver);
981}
3608 982
3609 return 0; 983static void __exit pm3fb_exit(void)
984{
985 pci_unregister_driver(&pm3fb_driver);
3610} 986}
3611 987
3612void cleanup_module(void) 988#ifndef MODULE
989 /*
990 * Setup
991 */
992
993/*
994 * Only necessary if your driver takes special options,
995 * otherwise we fall back on the generic fb_setup().
996 */
997int __init pm3fb_setup(char *options)
3613{ 998{
3614 DTRACE; 999 /* Parse user speficied options (`video=pm3fb:') */
3615 { 1000 return 0;
3616 unsigned long i;
3617 struct pm3fb_info *l_fb_info;
3618 for (i = 0; i < PM3_MAX_BOARD; i++) {
3619 l_fb_info = &(fb_info[i]);
3620 pci_dev_put(l_fb_info->dev);
3621 if (l_fb_info->dev != NULL && !(disable[l_fb_info->board_num])) {
3622 if (l_fb_info->vIOBase != (unsigned char *) -1) {
3623 pm3fb_unmapIO(l_fb_info);
3624 release_mem_region(l_fb_info->p_fb,
3625 l_fb_info->fb_size);
3626 release_mem_region(l_fb_info->pIOBase,
3627 PM3_REGS_SIZE);
3628 }
3629 unregister_framebuffer(&l_fb_info->gen.info);
3630 }
3631 }
3632 }
3633} 1001}
3634#endif /* MODULE */ 1002#endif /* MODULE */
1003
1004module_init(pm3fb_init);
1005module_exit(pm3fb_exit);
1006
1007MODULE_LICENSE("GPL");
diff --git a/drivers/video/ps3fb.c b/drivers/video/ps3fb.c
index 07d1979bc23e..9756a728b74f 100644
--- a/drivers/video/ps3fb.c
+++ b/drivers/video/ps3fb.c
@@ -898,8 +898,8 @@ static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo, void *dev)
898 } 898 }
899 899
900 ps3fb.dev = dev; 900 ps3fb.dev = dev;
901 error = ps3_alloc_irq(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet, 901 error = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
902 &ps3fb.irq_no); 902 &ps3fb.irq_no);
903 if (error) { 903 if (error) {
904 printk(KERN_ERR "%s: ps3_alloc_irq failed %d\n", __func__, 904 printk(KERN_ERR "%s: ps3_alloc_irq failed %d\n", __func__,
905 error); 905 error);
@@ -911,7 +911,7 @@ static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo, void *dev)
911 if (error) { 911 if (error) {
912 printk(KERN_ERR "%s: request_irq failed %d\n", __func__, 912 printk(KERN_ERR "%s: request_irq failed %d\n", __func__,
913 error); 913 error);
914 ps3_free_irq(ps3fb.irq_no); 914 ps3_irq_plug_destroy(ps3fb.irq_no);
915 return error; 915 return error;
916 } 916 }
917 917
@@ -1083,7 +1083,7 @@ err_framebuffer_release:
1083 framebuffer_release(info); 1083 framebuffer_release(info);
1084err_free_irq: 1084err_free_irq:
1085 free_irq(ps3fb.irq_no, ps3fb.dev); 1085 free_irq(ps3fb.irq_no, ps3fb.dev);
1086 ps3_free_irq(ps3fb.irq_no); 1086 ps3_irq_plug_destroy(ps3fb.irq_no);
1087err_iounmap_dinfo: 1087err_iounmap_dinfo:
1088 iounmap((u8 __iomem *)ps3fb.dinfo); 1088 iounmap((u8 __iomem *)ps3fb.dinfo);
1089err_gpu_context_free: 1089err_gpu_context_free:
@@ -1099,7 +1099,7 @@ static void ps3fb_shutdown(struct platform_device *dev)
1099 ps3fb_flip_ctl(0); /* flip off */ 1099 ps3fb_flip_ctl(0); /* flip off */
1100 ps3fb.dinfo->irq.mask = 0; 1100 ps3fb.dinfo->irq.mask = 0;
1101 free_irq(ps3fb.irq_no, ps3fb.dev); 1101 free_irq(ps3fb.irq_no, ps3fb.dev);
1102 ps3_free_irq(ps3fb.irq_no); 1102 ps3_irq_plug_destroy(ps3fb.irq_no);
1103 iounmap((u8 __iomem *)ps3fb.dinfo); 1103 iounmap((u8 __iomem *)ps3fb.dinfo);
1104} 1104}
1105 1105
@@ -1114,7 +1114,7 @@ void ps3fb_cleanup(void)
1114 } 1114 }
1115 if (ps3fb.irq_no) { 1115 if (ps3fb.irq_no) {
1116 free_irq(ps3fb.irq_no, ps3fb.dev); 1116 free_irq(ps3fb.irq_no, ps3fb.dev);
1117 ps3_free_irq(ps3fb.irq_no); 1117 ps3_irq_plug_destroy(ps3fb.irq_no);
1118 } 1118 }
1119 iounmap((u8 __iomem *)ps3fb.dinfo); 1119 iounmap((u8 __iomem *)ps3fb.dinfo);
1120 1120
diff --git a/drivers/video/pvr2fb.c b/drivers/video/pvr2fb.c
index a93618bc9d27..df2909ae704c 100644
--- a/drivers/video/pvr2fb.c
+++ b/drivers/video/pvr2fb.c
@@ -214,7 +214,7 @@ static int pvr2_init_cable(void);
214static int pvr2_get_param(const struct pvr2_params *p, const char *s, 214static int pvr2_get_param(const struct pvr2_params *p, const char *s,
215 int val, int size); 215 int val, int size);
216#ifdef CONFIG_SH_DMA 216#ifdef CONFIG_SH_DMA
217static ssize_t pvr2fb_write(struct file *file, const char *buf, 217static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
218 size_t count, loff_t *ppos); 218 size_t count, loff_t *ppos);
219#endif 219#endif
220 220
@@ -674,7 +674,7 @@ static int pvr2_init_cable(void)
674} 674}
675 675
676#ifdef CONFIG_SH_DMA 676#ifdef CONFIG_SH_DMA
677static ssize_t pvr2fb_write(struct file *file, const char *buf, 677static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
678 size_t count, loff_t *ppos) 678 size_t count, loff_t *ppos)
679{ 679{
680 unsigned long dst, start, end, len; 680 unsigned long dst, start, end, len;
diff --git a/drivers/video/pxafb.c b/drivers/video/pxafb.c
index 0b195f33f84f..81e571d59b50 100644
--- a/drivers/video/pxafb.c
+++ b/drivers/video/pxafb.c
@@ -1203,7 +1203,7 @@ static int __init pxafb_parse_options(struct device *dev, char *options)
1203 } else 1203 } else
1204 goto done; 1204 goto done;
1205 break; 1205 break;
1206 case '0'...'9': 1206 case '0' ... '9':
1207 break; 1207 break;
1208 default: 1208 default:
1209 goto done; 1209 goto done;
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index d7ece8d17a2c..0fe547842c64 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -317,15 +317,15 @@ static int riva_bl_update_status(struct backlight_device *bd)
317 else 317 else
318 level = bd->props.brightness; 318 level = bd->props.brightness;
319 319
320 tmp_pmc = par->riva.PMC[0x10F0/4] & 0x0000FFFF; 320 tmp_pmc = NV_RD32(par->riva.PMC, 0x10F0) & 0x0000FFFF;
321 tmp_pcrt = par->riva.PCRTC0[0x081C/4] & 0xFFFFFFFC; 321 tmp_pcrt = NV_RD32(par->riva.PCRTC0, 0x081C) & 0xFFFFFFFC;
322 if(level > 0) { 322 if(level > 0) {
323 tmp_pcrt |= 0x1; 323 tmp_pcrt |= 0x1;
324 tmp_pmc |= (1 << 31); /* backlight bit */ 324 tmp_pmc |= (1 << 31); /* backlight bit */
325 tmp_pmc |= riva_bl_get_level_brightness(par, level) << 16; /* level */ 325 tmp_pmc |= riva_bl_get_level_brightness(par, level) << 16; /* level */
326 } 326 }
327 par->riva.PCRTC0[0x081C/4] = tmp_pcrt; 327 NV_WR32(par->riva.PCRTC0, 0x081C, tmp_pcrt);
328 par->riva.PMC[0x10F0/4] = tmp_pmc; 328 NV_WR32(par->riva.PMC, 0x10F0, tmp_pmc);
329 329
330 return 0; 330 return 0;
331} 331}
@@ -1760,13 +1760,13 @@ static int __devinit riva_get_EDID_OF(struct fb_info *info, struct pci_dev *pd)
1760 NVTRACE_ENTER(); 1760 NVTRACE_ENTER();
1761 dp = pci_device_to_OF_node(pd); 1761 dp = pci_device_to_OF_node(pd);
1762 for (; dp != NULL; dp = dp->child) { 1762 for (; dp != NULL; dp = dp->child) {
1763 disptype = get_property(dp, "display-type", NULL); 1763 disptype = of_get_property(dp, "display-type", NULL);
1764 if (disptype == NULL) 1764 if (disptype == NULL)
1765 continue; 1765 continue;
1766 if (strncmp(disptype, "LCD", 3) != 0) 1766 if (strncmp(disptype, "LCD", 3) != 0)
1767 continue; 1767 continue;
1768 for (i = 0; propnames[i] != NULL; ++i) { 1768 for (i = 0; propnames[i] != NULL; ++i) {
1769 pedid = get_property(dp, propnames[i], NULL); 1769 pedid = of_get_property(dp, propnames[i], NULL);
1770 if (pedid != NULL) { 1770 if (pedid != NULL) {
1771 par->EDID = (unsigned char *)pedid; 1771 par->EDID = (unsigned char *)pedid;
1772 NVTRACE("LCD found.\n"); 1772 NVTRACE("LCD found.\n");
@@ -1788,8 +1788,10 @@ static int __devinit riva_get_EDID_i2c(struct fb_info *info)
1788 1788
1789 NVTRACE_ENTER(); 1789 NVTRACE_ENTER();
1790 riva_create_i2c_busses(par); 1790 riva_create_i2c_busses(par);
1791 for (i = 0; i < par->bus; i++) { 1791 for (i = 0; i < 3; i++) {
1792 riva_probe_i2c_connector(par, i+1, &par->EDID); 1792 if (!par->chan[i].par)
1793 continue;
1794 riva_probe_i2c_connector(par, i, &par->EDID);
1793 if (par->EDID && !fb_parse_edid(par->EDID, &var)) { 1795 if (par->EDID && !fb_parse_edid(par->EDID, &var)) {
1794 printk(PFX "Found EDID Block from BUS %i\n", i); 1796 printk(PFX "Found EDID Block from BUS %i\n", i);
1795 break; 1797 break;
@@ -2104,7 +2106,7 @@ err_ret:
2104 return ret; 2106 return ret;
2105} 2107}
2106 2108
2107static void __exit rivafb_remove(struct pci_dev *pd) 2109static void __devexit rivafb_remove(struct pci_dev *pd)
2108{ 2110{
2109 struct fb_info *info = pci_get_drvdata(pd); 2111 struct fb_info *info = pci_get_drvdata(pd);
2110 struct riva_par *par = info->par; 2112 struct riva_par *par = info->par;
@@ -2185,7 +2187,7 @@ static struct pci_driver rivafb_driver = {
2185 .name = "rivafb", 2187 .name = "rivafb",
2186 .id_table = rivafb_pci_tbl, 2188 .id_table = rivafb_pci_tbl,
2187 .probe = rivafb_probe, 2189 .probe = rivafb_probe,
2188 .remove = __exit_p(rivafb_remove), 2190 .remove = __devexit_p(rivafb_remove),
2189}; 2191};
2190 2192
2191 2193
diff --git a/drivers/video/riva/nv4ref.h b/drivers/video/riva/nv4ref.h
deleted file mode 100644
index 3b5f9117c37d..000000000000
--- a/drivers/video/riva/nv4ref.h
+++ /dev/null
@@ -1,2445 +0,0 @@
1 /***************************************************************************\
2|* *|
3|* Copyright 1993-1998 NVIDIA, Corporation. All rights reserved. *|
4|* *|
5|* NOTICE TO USER: The source code is copyrighted under U.S. and *|
6|* international laws. Users and possessors of this source code are *|
7|* hereby granted a nonexclusive, royalty-free copyright license to *|
8|* use this code in individual and commercial software. *|
9|* *|
10|* Any use of this source code must include, in the user documenta- *|
11|* tion and internal comments to the code, notices to the end user *|
12|* as follows: *|
13|* *|
14|* Copyright 1993-1998 NVIDIA, Corporation. All rights reserved. *|
15|* *|
16|* NVIDIA, CORPORATION MAKES NO REPRESENTATION ABOUT THE SUITABILITY *|
17|* OF THIS SOURCE CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" *|
18|* WITHOUT EXPRESS OR IMPLIED WARRANTY OF ANY KIND. NVIDIA, CORPOR- *|
19|* ATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOURCE CODE, *|
20|* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGE- *|
21|* MENT, AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL *|
22|* NVIDIA, CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT, INCI- *|
23|* DENTAL, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RE- *|
24|* SULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION *|
25|* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *|
26|* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOURCE CODE. *|
27|* *|
28|* U.S. Government End Users. This source code is a "commercial *|
29|* item," as that term is defined at 48 C.F.R. 2.101 (OCT 1995), *|
30|* consisting of "commercial computer software" and "commercial *|
31|* computer software documentation," as such terms are used in *|
32|* 48 C.F.R. 12.212 (SEPT 1995) and is provided to the U.S. Govern- *|
33|* ment only as a commercial end item. Consistent with 48 C.F.R. *|
34|* 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), *|
35|* all U.S. Government End Users acquire the source code with only *|
36|* those rights set forth herein. *|
37|* *|
38 \***************************************************************************/
39
40/*
41 * GPL licensing note -- nVidia is allowing a liberal interpretation of
42 * the documentation restriction above, to merely say that this nVidia's
43 * copyright and disclaimer should be included with all code derived
44 * from this source. -- Jeff Garzik <jgarzik@pobox.com>, 01/Nov/99
45 */
46
47 /***************************************************************************\
48|* Modified 1999 by Fredrik Reite (fredrik@reite.com) *|
49 \***************************************************************************/
50
51
52#ifndef __NV4REF_H__
53#define __NV4REF_H__
54
55/* Magic values to lock/unlock extended regs */
56#define NV_CIO_SR_LOCK_INDEX 0x0000001F /* */
57#define NV_CIO_SR_UNLOCK_RW_VALUE 0x00000057 /* */
58#define NV_CIO_SR_UNLOCK_RO_VALUE 0x00000075 /* */
59#define NV_CIO_SR_LOCK_VALUE 0x00000099 /* */
60
61#define UNLOCK_EXT_MAGIC 0x57
62#define LOCK_EXT_MAGIC 0x99 /* Any value other than 0x57 will do */
63
64#define LOCK_EXT_INDEX 0x6
65
66#define NV_PCRTC_HORIZ_TOTAL 0x00
67#define NV_PCRTC_HORIZ_DISPLAY_END 0x01
68#define NV_PCRTC_HORIZ_BLANK_START 0x02
69
70#define NV_PCRTC_HORIZ_BLANK_END 0x03
71#define NV_PCRTC_HORIZ_BLANK_END_EVRA 7:7
72#define NV_PCRTC_HORIZ_BLANK_END_DISPLAY_END_SKEW 6:5
73#define NV_PCRTC_HORIZ_BLANK_END_HORIZ_BLANK_END 4:0
74
75#define NV_PCRTC_HORIZ_RETRACE_START 0x04
76
77#define NV_PCRTC_HORIZ_RETRACE_END 0x05
78#define NV_PCRTC_HORIZ_RETRACE_END_HORIZ_BLANK_END_5 7:7
79#define NV_PCRTC_HORIZ_RETRACE_END_HORIZ_RETRACE_SKEW 6:5
80#define NV_PCRTC_HORIZ_RETRACE_END_HORIZ_RETRACE_END 4:0
81
82#define NV_PCRTC_VERT_TOTAL 0x06
83
84#define NV_PCRTC_OVERFLOW 0x07
85#define NV_PCRTC_OVERFLOW_VERT_RETRACE_START_9 7:7
86#define NV_PCRTC_OVERFLOW_VERT_DISPLAY_END_9 6:6
87#define NV_PCRTC_OVERFLOW_VERT_TOTAL_9 5:5
88#define NV_PCRTC_OVERFLOW_LINE_COMPARE_8 4:4
89#define NV_PCRTC_OVERFLOW_VERT_BLANK_START_8 3:3
90#define NV_PCRTC_OVERFLOW_VERT_RETRACE_START_8 2:2
91#define NV_PCRTC_OVERFLOW_VERT_DISPLAY_END_8 1:1
92#define NV_PCRTC_OVERFLOW_VERT_TOTAL_8 0:0
93
94#define NV_PCRTC_PRESET_ROW_SCAN 0x08
95
96#define NV_PCRTC_MAX_SCAN_LINE 0x09
97#define NV_PCRTC_MAX_SCAN_LINE_DOUBLE_SCAN 7:7
98#define NV_PCRTC_MAX_SCAN_LINE_LINE_COMPARE_9 6:6
99#define NV_PCRTC_MAX_SCAN_LINE_VERT_BLANK_START_9 5:5
100#define NV_PCRTC_MAX_SCAN_LINE_MAX_SCAN_LINE 4:0
101
102#define NV_PCRTC_CURSOR_START 0x0A
103#define NV_PCRTC_CURSOR_END 0x0B
104#define NV_PCRTC_START_ADDR_HIGH 0x0C
105#define NV_PCRTC_START_ADDR_LOW 0x0D
106#define NV_PCRTC_CURSOR_LOCATION_HIGH 0x0E
107#define NV_PCRTC_CURSOR_LOCATION_LOW 0x0F
108
109#define NV_PCRTC_VERT_RETRACE_START 0x10
110#define NV_PCRTC_VERT_RETRACE_END 0x11
111#define NV_PCRTC_VERT_DISPLAY_END 0x12
112#define NV_PCRTC_OFFSET 0x13
113#define NV_PCRTC_UNDERLINE_LOCATION 0x14
114#define NV_PCRTC_VERT_BLANK_START 0x15
115#define NV_PCRTC_VERT_BLANK_END 0x16
116#define NV_PCRTC_MODE_CONTROL 0x17
117#define NV_PCRTC_LINE_COMPARE 0x18
118
119/* Extended offset and start address */
120#define NV_PCRTC_REPAINT0 0x19
121#define NV_PCRTC_REPAINT0_OFFSET_10_8 7:5
122#define NV_PCRTC_REPAINT0_START_ADDR_20_16 4:0
123
124/* Horizonal extended bits */
125#define NV_PCRTC_HORIZ_EXTRA 0x2d
126#define NV_PCRTC_HORIZ_EXTRA_INTER_HALF_START_8 4:4
127#define NV_PCRTC_HORIZ_EXTRA_HORIZ_RETRACE_START_8 3:3
128#define NV_PCRTC_HORIZ_EXTRA_HORIZ_BLANK_START_8 2:2
129#define NV_PCRTC_HORIZ_EXTRA_DISPLAY_END_8 1:1
130#define NV_PCRTC_HORIZ_EXTRA_DISPLAY_TOTAL_8 0:0
131
132/* Assorted extra bits */
133#define NV_PCRTC_EXTRA 0x25
134#define NV_PCRTC_EXTRA_OFFSET_11 5:5
135#define NV_PCRTC_EXTRA_HORIZ_BLANK_END_6 4:4
136#define NV_PCRTC_EXTRA_VERT_BLANK_START_10 3:3
137#define NV_PCRTC_EXTRA_VERT_RETRACE_START_10 2:2
138#define NV_PCRTC_EXTRA_VERT_DISPLAY_END_10 1:1
139#define NV_PCRTC_EXTRA_VERT_TOTAL_10 0:0
140
141/* Controls how much data the refresh fifo requests */
142#define NV_PCRTC_FIFO_CONTROL 0x1b
143#define NV_PCRTC_FIFO_CONTROL_UNDERFLOW_WARN 7:7
144#define NV_PCRTC_FIFO_CONTROL_BURST_LENGTH 2:0
145#define NV_PCRTC_FIFO_CONTROL_BURST_LENGTH_8 0x0
146#define NV_PCRTC_FIFO_CONTROL_BURST_LENGTH_32 0x1
147#define NV_PCRTC_FIFO_CONTROL_BURST_LENGTH_64 0x2
148#define NV_PCRTC_FIFO_CONTROL_BURST_LENGTH_128 0x3
149#define NV_PCRTC_FIFO_CONTROL_BURST_LENGTH_256 0x4
150
151/* When the fifo occupancy falls below *twice* the watermark,
152 * the refresh fifo will start to be refilled. If this value is
153 * too low, you will get junk on the screen. Too high, and performance
154 * will suffer. Watermark in units of 8 bytes
155 */
156#define NV_PCRTC_FIFO 0x20
157#define NV_PCRTC_FIFO_RESET 7:7
158#define NV_PCRTC_FIFO_WATERMARK 5:0
159
160/* Various flags */
161#define NV_PCRTC_REPAINT1 0x1a
162#define NV_PCRTC_REPAINT1_HSYNC 7:7
163#define NV_PCRTC_REPAINT1_HYSNC_DISABLE 0x01
164#define NV_PCRTC_REPAINT1_HYSNC_ENABLE 0x00
165#define NV_PCRTC_REPAINT1_VSYNC 6:6
166#define NV_PCRTC_REPAINT1_VYSNC_DISABLE 0x01
167#define NV_PCRTC_REPAINT1_VYSNC_ENABLE 0x00
168#define NV_PCRTC_REPAINT1_COMPATIBLE_TEXT 4:4
169#define NV_PCRTC_REPAINT1_COMPATIBLE_TEXT_ENABLE 0x01
170#define NV_PCRTC_REPAINT1_COMPATIBLE_TEXT_DISABLE 0x00
171#define NV_PCRTC_REPAINT1_LARGE_SCREEN 2:2
172#define NV_PCRTC_REPAINT1_LARGE_SCREEN_DISABLE 0x01
173#define NV_PCRTC_REPAINT1_LARGE_SCREEN_ENABLE 0x00 /* >=1280 */
174#define NV_PCRTC_REPAINT1_PALETTE_WIDTH 1:1
175#define NV_PCRTC_REPAINT1_PALETTE_WIDTH_8BITS 0x00
176#define NV_PCRTC_REPAINT1_PALETTE_WIDTH_6BITS 0x01
177
178#define NV_PCRTC_GRCURSOR0 0x30
179#define NV_PCRTC_GRCURSOR0_START_ADDR_21_16 5:0
180
181#define NV_PCRTC_GRCURSOR1 0x31
182#define NV_PCRTC_GRCURSOR1_START_ADDR_15_11 7:3
183#define NV_PCRTC_GRCURSOR1_SCAN_DBL 1:1
184#define NV_PCRTC_GRCURSOR1_SCAN_DBL_DISABLE 0
185#define NV_PCRTC_GRCURSOR1_SCAN_DBL_ENABLE 1
186#define NV_PCRTC_GRCURSOR1_CURSOR 0:0
187#define NV_PCRTC_GRCURSOR1_CURSOR_DISABLE 0
188#define NV_PCRTC_GRCURSOR1_CURSOR_ENABLE 1
189
190/* Controls what the format of the framebuffer is */
191#define NV_PCRTC_PIXEL 0x28
192#define NV_PCRTC_PIXEL_MODE 7:7
193#define NV_PCRTC_PIXEL_MODE_TV 0x01
194#define NV_PCRTC_PIXEL_MODE_VGA 0x00
195#define NV_PCRTC_PIXEL_TV_MODE 6:6
196#define NV_PCRTC_PIXEL_TV_MODE_NTSC 0x00
197#define NV_PCRTC_PIXEL_TV_MODE_PAL 0x01
198#define NV_PCRTC_PIXEL_TV_HORIZ_ADJUST 5:3
199#define NV_PCRTC_PIXEL_FORMAT 1:0
200#define NV_PCRTC_PIXEL_FORMAT_VGA 0x00
201#define NV_PCRTC_PIXEL_FORMAT_8BPP 0x01
202#define NV_PCRTC_PIXEL_FORMAT_16BPP 0x02
203#define NV_PCRTC_PIXEL_FORMAT_32BPP 0x03
204
205/* RAMDAC registers and fields */
206#define NV_PRAMDAC 0x00680FFF:0x00680000 /* RW--D */
207#define NV_PRAMDAC_GRCURSOR_START_POS 0x00680300 /* RW-4R */
208#define NV_PRAMDAC_GRCURSOR_START_POS_X 11:0 /* RWXSF */
209#define NV_PRAMDAC_GRCURSOR_START_POS_Y 27:16 /* RWXSF */
210#define NV_PRAMDAC_NVPLL_COEFF 0x00680500 /* RW-4R */
211#define NV_PRAMDAC_NVPLL_COEFF_MDIV 7:0 /* RWIUF */
212#define NV_PRAMDAC_NVPLL_COEFF_NDIV 15:8 /* RWIUF */
213#define NV_PRAMDAC_NVPLL_COEFF_PDIV 18:16 /* RWIVF */
214#define NV_PRAMDAC_MPLL_COEFF 0x00680504 /* RW-4R */
215#define NV_PRAMDAC_MPLL_COEFF_MDIV 7:0 /* RWIUF */
216#define NV_PRAMDAC_MPLL_COEFF_NDIV 15:8 /* RWIUF */
217#define NV_PRAMDAC_MPLL_COEFF_PDIV 18:16 /* RWIVF */
218#define NV_PRAMDAC_VPLL_COEFF 0x00680508 /* RW-4R */
219#define NV_PRAMDAC_VPLL_COEFF_MDIV 7:0 /* RWIUF */
220#define NV_PRAMDAC_VPLL_COEFF_NDIV 15:8 /* RWIUF */
221#define NV_PRAMDAC_VPLL_COEFF_PDIV 18:16 /* RWIVF */
222#define NV_PRAMDAC_PLL_COEFF_SELECT 0x0068050C /* RW-4R */
223#define NV_PRAMDAC_PLL_COEFF_SELECT_DLL_BYPASS 4:4 /* RWIVF */
224#define NV_PRAMDAC_PLL_COEFF_SELECT_DLL_BYPASS_FALSE 0x00000000 /* RWI-V */
225#define NV_PRAMDAC_PLL_COEFF_SELECT_DLL_BYPASS_TRUE 0x00000001 /* RW--V */
226#define NV_PRAMDAC_PLL_COEFF_SELECT_MPLL_SOURCE 8:8 /* RWIVF */
227#define NV_PRAMDAC_PLL_COEFF_SELECT_MPLL_SOURCE_DEFAULT 0x00000000 /* RWI-V */
228#define NV_PRAMDAC_PLL_COEFF_SELECT_MPLL_SOURCE_PROG 0x00000001 /* RW--V */
229#define NV_PRAMDAC_PLL_COEFF_SELECT_MPLL_BYPASS 12:12 /* RWIVF */
230#define NV_PRAMDAC_PLL_COEFF_SELECT_MPLL_BYPASS_FALSE 0x00000000 /* RWI-V */
231#define NV_PRAMDAC_PLL_COEFF_SELECT_MPLL_BYPASS_TRUE 0x00000001 /* RW--V */
232#define NV_PRAMDAC_PLL_COEFF_SELECT_VPLL_SOURCE 16:16 /* RWIVF */
233#define NV_PRAMDAC_PLL_COEFF_SELECT_VPLL_SOURCE_DEFAULT 0x00000000 /* RWI-V */
234#define NV_PRAMDAC_PLL_COEFF_SELECT_VPLL_SOURCE_PROG 0x00000001 /* RW--V */
235#define NV_PRAMDAC_PLL_COEFF_SELECT_VPLL_BYPASS 20:20 /* RWIVF */
236#define NV_PRAMDAC_PLL_COEFF_SELECT_VPLL_BYPASS_FALSE 0x00000000 /* RWI-V */
237#define NV_PRAMDAC_PLL_COEFF_SELECT_VPLL_BYPASS_TRUE 0x00000001 /* RW--V */
238#define NV_PRAMDAC_PLL_COEFF_SELECT_PCLK_SOURCE 25:24 /* RWIVF */
239#define NV_PRAMDAC_PLL_COEFF_SELECT_PCLK_SOURCE_VPLL 0x00000000 /* RWI-V */
240#define NV_PRAMDAC_PLL_COEFF_SELECT_PCLK_SOURCE_VIP 0x00000001 /* RW--V */
241#define NV_PRAMDAC_PLL_COEFF_SELECT_PCLK_SOURCE_XTALOSC 0x00000002 /* RW--V */
242#define NV_PRAMDAC_PLL_COEFF_SELECT_VCLK_RATIO 28:28 /* RWIVF */
243#define NV_PRAMDAC_PLL_COEFF_SELECT_VCLK_RATIO_DB1 0x00000000 /* RWI-V */
244#define NV_PRAMDAC_PLL_COEFF_SELECT_VCLK_RATIO_DB2 0x00000001 /* RW--V */
245#define NV_PRAMDAC_GENERAL_CONTROL 0x00680600 /* RW-4R */
246#define NV_PRAMDAC_GENERAL_CONTROL_FF_COEFF 1:0 /* RWIVF */
247#define NV_PRAMDAC_GENERAL_CONTROL_FF_COEFF_DEF 0x00000000 /* RWI-V */
248#define NV_PRAMDAC_GENERAL_CONTROL_IDC_MODE 4:4 /* RWIVF */
249#define NV_PRAMDAC_GENERAL_CONTROL_IDC_MODE_GAMMA 0x00000000 /* RWI-V */
250#define NV_PRAMDAC_GENERAL_CONTROL_IDC_MODE_INDEX 0x00000001 /* RW--V */
251#define NV_PRAMDAC_GENERAL_CONTROL_VGA_STATE 8:8 /* RWIVF */
252#define NV_PRAMDAC_GENERAL_CONTROL_VGA_STATE_NOTSE 0x00000000 /* RWI-V */
253#define NV_PRAMDAC_GENERAL_CONTROL_VGA_STATE_SEL 0x00000001 /* RW--V */
254#define NV_PRAMDAC_GENERAL_CONTROL_565_MODE 12:12 /* RWIVF */
255#define NV_PRAMDAC_GENERAL_CONTROL_565_MODE_NOTSEL 0x00000000 /* RWI-V */
256#define NV_PRAMDAC_GENERAL_CONTROL_565_MODE_SEL 0x00000001 /* RW--V */
257#define NV_PRAMDAC_GENERAL_CONTROL_BLK_PEDSTL 16:16 /* RWIVF */
258#define NV_PRAMDAC_GENERAL_CONTROL_BLK_PEDSTL_OFF 0x00000000 /* RWI-V */
259#define NV_PRAMDAC_GENERAL_CONTROL_BLK_PEDSTL_ON 0x00000001 /* RW--V */
260#define NV_PRAMDAC_GENERAL_CONTROL_TERMINATION 17:17 /* RWIVF */
261#define NV_PRAMDAC_GENERAL_CONTROL_TERMINATION_37OHM 0x00000000 /* RWI-V */
262#define NV_PRAMDAC_GENERAL_CONTROL_TERMINATION_75OHM 0x00000001 /* RW--V */
263#define NV_PRAMDAC_GENERAL_CONTROL_BPC 20:20 /* RWIVF */
264#define NV_PRAMDAC_GENERAL_CONTROL_BPC_6BITS 0x00000000 /* RWI-V */
265#define NV_PRAMDAC_GENERAL_CONTROL_BPC_8BITS 0x00000001 /* RW--V */
266#define NV_PRAMDAC_GENERAL_CONTROL_DAC_SLEEP 24:24 /* RWIVF */
267#define NV_PRAMDAC_GENERAL_CONTROL_DAC_SLEEP_DIS 0x00000000 /* RWI-V */
268#define NV_PRAMDAC_GENERAL_CONTROL_DAC_SLEEP_EN 0x00000001 /* RW--V */
269#define NV_PRAMDAC_GENERAL_CONTROL_PALETTE_CLK 28:28 /* RWIVF */
270#define NV_PRAMDAC_GENERAL_CONTROL_PALETTE_CLK_EN 0x00000000 /* RWI-V */
271#define NV_PRAMDAC_GENERAL_CONTROL_PALETTE_CLK_DIS 0x00000001 /* RW--V */
272
273/* Master Control */
274#define NV_PMC 0x00000FFF:0x00000000 /* RW--D */
275#define NV_PMC_BOOT_0 0x00000000 /* R--4R */
276#define NV_PMC_BOOT_0_MINOR_REVISION 3:0 /* C--VF */
277#define NV_PMC_BOOT_0_MINOR_REVISION_0 0x00000000 /* C---V */
278#define NV_PMC_BOOT_0_MAJOR_REVISION 7:4 /* C--VF */
279#define NV_PMC_BOOT_0_MAJOR_REVISION_A 0x00000000 /* C---V */
280#define NV_PMC_BOOT_0_MAJOR_REVISION_B 0x00000001 /* ----V */
281#define NV_PMC_BOOT_0_IMPLEMENTATION 11:8 /* C--VF */
282#define NV_PMC_BOOT_0_IMPLEMENTATION_NV4_0 0x00000000 /* C---V */
283#define NV_PMC_BOOT_0_ARCHITECTURE 15:12 /* C--VF */
284#define NV_PMC_BOOT_0_ARCHITECTURE_NV0 0x00000000 /* ----V */
285#define NV_PMC_BOOT_0_ARCHITECTURE_NV1 0x00000001 /* ----V */
286#define NV_PMC_BOOT_0_ARCHITECTURE_NV2 0x00000002 /* ----V */
287#define NV_PMC_BOOT_0_ARCHITECTURE_NV3 0x00000003 /* ----V */
288#define NV_PMC_BOOT_0_ARCHITECTURE_NV4 0x00000004 /* C---V */
289#define NV_PMC_BOOT_0_FIB_REVISION 19:16 /* C--VF */
290#define NV_PMC_BOOT_0_FIB_REVISION_0 0x00000000 /* C---V */
291#define NV_PMC_BOOT_0_MASK_REVISION 23:20 /* C--VF */
292#define NV_PMC_BOOT_0_MASK_REVISION_A 0x00000000 /* C---V */
293#define NV_PMC_BOOT_0_MASK_REVISION_B 0x00000001 /* ----V */
294#define NV_PMC_BOOT_0_MANUFACTURER 27:24 /* C--UF */
295#define NV_PMC_BOOT_0_MANUFACTURER_NVIDIA 0x00000000 /* C---V */
296#define NV_PMC_BOOT_0_FOUNDRY 31:28 /* C--VF */
297#define NV_PMC_BOOT_0_FOUNDRY_SGS 0x00000000 /* ----V */
298#define NV_PMC_BOOT_0_FOUNDRY_HELIOS 0x00000001 /* ----V */
299#define NV_PMC_BOOT_0_FOUNDRY_TSMC 0x00000002 /* C---V */
300#define NV_PMC_INTR_0 0x00000100 /* RW-4R */
301#define NV_PMC_INTR_0_PMEDIA 4:4 /* R--VF */
302#define NV_PMC_INTR_0_PMEDIA_NOT_PENDING 0x00000000 /* R---V */
303#define NV_PMC_INTR_0_PMEDIA_PENDING 0x00000001 /* R---V */
304#define NV_PMC_INTR_0_PFIFO 8:8 /* R--VF */
305#define NV_PMC_INTR_0_PFIFO_NOT_PENDING 0x00000000 /* R---V */
306#define NV_PMC_INTR_0_PFIFO_PENDING 0x00000001 /* R---V */
307#define NV_PMC_INTR_0_PGRAPH 12:12 /* R--VF */
308#define NV_PMC_INTR_0_PGRAPH_NOT_PENDING 0x00000000 /* R---V */
309#define NV_PMC_INTR_0_PGRAPH_PENDING 0x00000001 /* R---V */
310#define NV_PMC_INTR_0_PVIDEO 16:16 /* R--VF */
311#define NV_PMC_INTR_0_PVIDEO_NOT_PENDING 0x00000000 /* R---V */
312#define NV_PMC_INTR_0_PVIDEO_PENDING 0x00000001 /* R---V */
313#define NV_PMC_INTR_0_PTIMER 20:20 /* R--VF */
314#define NV_PMC_INTR_0_PTIMER_NOT_PENDING 0x00000000 /* R---V */
315#define NV_PMC_INTR_0_PTIMER_PENDING 0x00000001 /* R---V */
316#define NV_PMC_INTR_0_PCRTC 24:24 /* R--VF */
317#define NV_PMC_INTR_0_PCRTC_NOT_PENDING 0x00000000 /* R---V */
318#define NV_PMC_INTR_0_PCRTC_PENDING 0x00000001 /* R---V */
319#define NV_PMC_INTR_0_PBUS 28:28 /* R--VF */
320#define NV_PMC_INTR_0_PBUS_NOT_PENDING 0x00000000 /* R---V */
321#define NV_PMC_INTR_0_PBUS_PENDING 0x00000001 /* R---V */
322#define NV_PMC_INTR_0_SOFTWARE 31:31 /* RWIVF */
323#define NV_PMC_INTR_0_SOFTWARE_NOT_PENDING 0x00000000 /* RWI-V */
324#define NV_PMC_INTR_0_SOFTWARE_PENDING 0x00000001 /* RW--V */
325#define NV_PMC_INTR_EN_0 0x00000140 /* RW-4R */
326#define NV_PMC_INTR_EN_0_INTA 1:0 /* RWIVF */
327#define NV_PMC_INTR_EN_0_INTA_DISABLED 0x00000000 /* RWI-V */
328#define NV_PMC_INTR_EN_0_INTA_HARDWARE 0x00000001 /* RW--V */
329#define NV_PMC_INTR_EN_0_INTA_SOFTWARE 0x00000002 /* RW--V */
330#define NV_PMC_INTR_READ_0 0x00000160 /* R--4R */
331#define NV_PMC_INTR_READ_0_INTA 0:0 /* R--VF */
332#define NV_PMC_INTR_READ_0_INTA_LOW 0x00000000 /* R---V */
333#define NV_PMC_INTR_READ_0_INTA_HIGH 0x00000001 /* R---V */
334#define NV_PMC_ENABLE 0x00000200 /* RW-4R */
335#define NV_PMC_ENABLE_PMEDIA 4:4 /* RWIVF */
336#define NV_PMC_ENABLE_PMEDIA_DISABLED 0x00000000 /* RWI-V */
337#define NV_PMC_ENABLE_PMEDIA_ENABLED 0x00000001 /* RW--V */
338#define NV_PMC_ENABLE_PFIFO 8:8 /* RWIVF */
339#define NV_PMC_ENABLE_PFIFO_DISABLED 0x00000000 /* RWI-V */
340#define NV_PMC_ENABLE_PFIFO_ENABLED 0x00000001 /* RW--V */
341#define NV_PMC_ENABLE_PGRAPH 12:12 /* RWIVF */
342#define NV_PMC_ENABLE_PGRAPH_DISABLED 0x00000000 /* RWI-V */
343#define NV_PMC_ENABLE_PGRAPH_ENABLED 0x00000001 /* RW--V */
344#define NV_PMC_ENABLE_PPMI 16:16 /* RWIVF */
345#define NV_PMC_ENABLE_PPMI_DISABLED 0x00000000 /* RWI-V */
346#define NV_PMC_ENABLE_PPMI_ENABLED 0x00000001 /* RW--V */
347#define NV_PMC_ENABLE_PFB 20:20 /* RWIVF */
348#define NV_PMC_ENABLE_PFB_DISABLED 0x00000000 /* RW--V */
349#define NV_PMC_ENABLE_PFB_ENABLED 0x00000001 /* RWI-V */
350#define NV_PMC_ENABLE_PCRTC 24:24 /* RWIVF */
351#define NV_PMC_ENABLE_PCRTC_DISABLED 0x00000000 /* RW--V */
352#define NV_PMC_ENABLE_PCRTC_ENABLED 0x00000001 /* RWI-V */
353#define NV_PMC_ENABLE_PVIDEO 28:28 /* RWIVF */
354#define NV_PMC_ENABLE_PVIDEO_DISABLED 0x00000000 /* RWI-V */
355#define NV_PMC_ENABLE_PVIDEO_ENABLED 0x00000001 /* RW--V */
356
357/* dev_timer.ref */
358#define NV_PTIMER 0x00009FFF:0x00009000 /* RW--D */
359#define NV_PTIMER_INTR_0 0x00009100 /* RW-4R */
360#define NV_PTIMER_INTR_0_ALARM 0:0 /* RWXVF */
361#define NV_PTIMER_INTR_0_ALARM_NOT_PENDING 0x00000000 /* R---V */
362#define NV_PTIMER_INTR_0_ALARM_PENDING 0x00000001 /* R---V */
363#define NV_PTIMER_INTR_0_ALARM_RESET 0x00000001 /* -W--V */
364#define NV_PTIMER_INTR_EN_0 0x00009140 /* RW-4R */
365#define NV_PTIMER_INTR_EN_0_ALARM 0:0 /* RWIVF */
366#define NV_PTIMER_INTR_EN_0_ALARM_DISABLED 0x00000000 /* RWI-V */
367#define NV_PTIMER_INTR_EN_0_ALARM_ENABLED 0x00000001 /* RW--V */
368#define NV_PTIMER_NUMERATOR 0x00009200 /* RW-4R */
369#define NV_PTIMER_NUMERATOR_VALUE 15:0 /* RWIUF */
370#define NV_PTIMER_NUMERATOR_VALUE_0 0x00000000 /* RWI-V */
371#define NV_PTIMER_DENOMINATOR 0x00009210 /* RW-4R */
372#define NV_PTIMER_DENOMINATOR_VALUE 15:0 /* RWIUF */
373#define NV_PTIMER_DENOMINATOR_VALUE_0 0x00000000 /* RWI-V */
374#define NV_PTIMER_TIME_0 0x00009400 /* RW-4R */
375#define NV_PTIMER_TIME_0_NSEC 31:5 /* RWXUF */
376#define NV_PTIMER_TIME_1 0x00009410 /* RW-4R */
377#define NV_PTIMER_TIME_1_NSEC 28:0 /* RWXUF */
378#define NV_PTIMER_ALARM_0 0x00009420 /* RW-4R */
379#define NV_PTIMER_ALARM_0_NSEC 31:5 /* RWXUF */
380
381/* dev_fifo.ref */
382#define NV_PFIFO 0x00003FFF:0x00002000 /* RW--D */
383#define NV_PFIFO_DELAY_0 0x00002040 /* RW-4R */
384#define NV_PFIFO_DELAY_0_WAIT_RETRY 9:0 /* RWIUF */
385#define NV_PFIFO_DELAY_0_WAIT_RETRY_0 0x00000000 /* RWI-V */
386#define NV_PFIFO_DMA_TIMESLICE 0x00002044 /* RW-4R */
387#define NV_PFIFO_DMA_TIMESLICE_SELECT 16:0 /* RWIUF */
388#define NV_PFIFO_DMA_TIMESLICE_SELECT_1 0x00000000 /* RWI-V */
389#define NV_PFIFO_DMA_TIMESLICE_SELECT_16K 0x00003fff /* RW--V */
390#define NV_PFIFO_DMA_TIMESLICE_SELECT_32K 0x00007fff /* RW--V */
391#define NV_PFIFO_DMA_TIMESLICE_SELECT_64K 0x0000ffff /* RW--V */
392#define NV_PFIFO_DMA_TIMESLICE_SELECT_128K 0x0001ffff /* RW--V */
393#define NV_PFIFO_DMA_TIMESLICE_TIMEOUT 24:24 /* RWIUF */
394#define NV_PFIFO_DMA_TIMESLICE_TIMEOUT_DISABLED 0x00000000 /* RW--V */
395#define NV_PFIFO_DMA_TIMESLICE_TIMEOUT_ENABLED 0x00000001 /* RWI-V */
396#define NV_PFIFO_PIO_TIMESLICE 0x00002048 /* RW-4R */
397#define NV_PFIFO_PIO_TIMESLICE_SELECT 16:0 /* RWIUF */
398#define NV_PFIFO_PIO_TIMESLICE_SELECT_1 0x00000000 /* RWI-V */
399#define NV_PFIFO_PIO_TIMESLICE_SELECT_16K 0x00003fff /* RW--V */
400#define NV_PFIFO_PIO_TIMESLICE_SELECT_32K 0x00007fff /* RW--V */
401#define NV_PFIFO_PIO_TIMESLICE_SELECT_64K 0x0000ffff /* RW--V */
402#define NV_PFIFO_PIO_TIMESLICE_SELECT_128K 0x0001ffff /* RW--V */
403#define NV_PFIFO_PIO_TIMESLICE_TIMEOUT 24:24 /* RWIUF */
404#define NV_PFIFO_PIO_TIMESLICE_TIMEOUT_DISABLED 0x00000000 /* RW--V */
405#define NV_PFIFO_PIO_TIMESLICE_TIMEOUT_ENABLED 0x00000001 /* RWI-V */
406#define NV_PFIFO_TIMESLICE 0x0000204C /* RW-4R */
407#define NV_PFIFO_TIMESLICE_TIMER 17:0 /* RWIUF */
408#define NV_PFIFO_TIMESLICE_TIMER_EXPIRED 0x0003FFFF /* RWI-V */
409#define NV_PFIFO_NEXT_CHANNEL 0x00002050 /* RW-4R */
410#define NV_PFIFO_NEXT_CHANNEL_CHID 3:0 /* RWXUF */
411#define NV_PFIFO_NEXT_CHANNEL_MODE 8:8 /* RWXVF */
412#define NV_PFIFO_NEXT_CHANNEL_MODE_PIO 0x00000000 /* RW--V */
413#define NV_PFIFO_NEXT_CHANNEL_MODE_DMA 0x00000001 /* RW--V */
414#define NV_PFIFO_NEXT_CHANNEL_SWITCH 12:12 /* RWIVF */
415#define NV_PFIFO_NEXT_CHANNEL_SWITCH_NOT_PENDING 0x00000000 /* RWI-V */
416#define NV_PFIFO_NEXT_CHANNEL_SWITCH_PENDING 0x00000001 /* RW--V */
417#define NV_PFIFO_DEBUG_0 0x00002080 /* R--4R */
418#define NV_PFIFO_DEBUG_0_CACHE_ERROR0 0:0 /* R-XVF */
419#define NV_PFIFO_DEBUG_0_CACHE_ERROR0_NOT_PENDING 0x00000000 /* R---V */
420#define NV_PFIFO_DEBUG_0_CACHE_ERROR0_PENDING 0x00000001 /* R---V */
421#define NV_PFIFO_DEBUG_0_CACHE_ERROR1 4:4 /* R-XVF */
422#define NV_PFIFO_DEBUG_0_CACHE_ERROR1_NOT_PENDING 0x00000000 /* R---V */
423#define NV_PFIFO_DEBUG_0_CACHE_ERROR1_PENDING 0x00000001 /* R---V */
424#define NV_PFIFO_INTR_0 0x00002100 /* RW-4R */
425#define NV_PFIFO_INTR_0_CACHE_ERROR 0:0 /* RWXVF */
426#define NV_PFIFO_INTR_0_CACHE_ERROR_NOT_PENDING 0x00000000 /* R---V */
427#define NV_PFIFO_INTR_0_CACHE_ERROR_PENDING 0x00000001 /* R---V */
428#define NV_PFIFO_INTR_0_CACHE_ERROR_RESET 0x00000001 /* -W--V */
429#define NV_PFIFO_INTR_0_RUNOUT 4:4 /* RWXVF */
430#define NV_PFIFO_INTR_0_RUNOUT_NOT_PENDING 0x00000000 /* R---V */
431#define NV_PFIFO_INTR_0_RUNOUT_PENDING 0x00000001 /* R---V */
432#define NV_PFIFO_INTR_0_RUNOUT_RESET 0x00000001 /* -W--V */
433#define NV_PFIFO_INTR_0_RUNOUT_OVERFLOW 8:8 /* RWXVF */
434#define NV_PFIFO_INTR_0_RUNOUT_OVERFLOW_NOT_PENDING 0x00000000 /* R---V */
435#define NV_PFIFO_INTR_0_RUNOUT_OVERFLOW_PENDING 0x00000001 /* R---V */
436#define NV_PFIFO_INTR_0_RUNOUT_OVERFLOW_RESET 0x00000001 /* -W--V */
437#define NV_PFIFO_INTR_0_DMA_PUSHER 12:12 /* RWXVF */
438#define NV_PFIFO_INTR_0_DMA_PUSHER_NOT_PENDING 0x00000000 /* R---V */
439#define NV_PFIFO_INTR_0_DMA_PUSHER_PENDING 0x00000001 /* R---V */
440#define NV_PFIFO_INTR_0_DMA_PUSHER_RESET 0x00000001 /* -W--V */
441#define NV_PFIFO_INTR_0_DMA_PT 16:16 /* RWXVF */
442#define NV_PFIFO_INTR_0_DMA_PT_NOT_PENDING 0x00000000 /* R---V */
443#define NV_PFIFO_INTR_0_DMA_PT_PENDING 0x00000001 /* R---V */
444#define NV_PFIFO_INTR_0_DMA_PT_RESET 0x00000001 /* -W--V */
445#define NV_PFIFO_INTR_EN_0 0x00002140 /* RW-4R */
446#define NV_PFIFO_INTR_EN_0_CACHE_ERROR 0:0 /* RWIVF */
447#define NV_PFIFO_INTR_EN_0_CACHE_ERROR_DISABLED 0x00000000 /* RWI-V */
448#define NV_PFIFO_INTR_EN_0_CACHE_ERROR_ENABLED 0x00000001 /* RW--V */
449#define NV_PFIFO_INTR_EN_0_RUNOUT 4:4 /* RWIVF */
450#define NV_PFIFO_INTR_EN_0_RUNOUT_DISABLED 0x00000000 /* RWI-V */
451#define NV_PFIFO_INTR_EN_0_RUNOUT_ENABLED 0x00000001 /* RW--V */
452#define NV_PFIFO_INTR_EN_0_RUNOUT_OVERFLOW 8:8 /* RWIVF */
453#define NV_PFIFO_INTR_EN_0_RUNOUT_OVERFLOW_DISABLED 0x00000000 /* RWI-V */
454#define NV_PFIFO_INTR_EN_0_RUNOUT_OVERFLOW_ENABLED 0x00000001 /* RW--V */
455#define NV_PFIFO_INTR_EN_0_DMA_PUSHER 12:12 /* RWIVF */
456#define NV_PFIFO_INTR_EN_0_DMA_PUSHER_DISABLED 0x00000000 /* RWI-V */
457#define NV_PFIFO_INTR_EN_0_DMA_PUSHER_ENABLED 0x00000001 /* RW--V */
458#define NV_PFIFO_INTR_EN_0_DMA_PT 16:16 /* RWIVF */
459#define NV_PFIFO_INTR_EN_0_DMA_PT_DISABLED 0x00000000 /* RWI-V */
460#define NV_PFIFO_INTR_EN_0_DMA_PT_ENABLED 0x00000001 /* RW--V */
461#define NV_PFIFO_RAMHT 0x00002210 /* RW-4R */
462#define NV_PFIFO_RAMHT_BASE_ADDRESS 8:4 /* RWIUF */
463#define NV_PFIFO_RAMHT_BASE_ADDRESS_10000 0x00000010 /* RWI-V */
464#define NV_PFIFO_RAMHT_SIZE 17:16 /* RWIUF */
465#define NV_PFIFO_RAMHT_SIZE_4K 0x00000000 /* RWI-V */
466#define NV_PFIFO_RAMHT_SIZE_8K 0x00000001 /* RW--V */
467#define NV_PFIFO_RAMHT_SIZE_16K 0x00000002 /* RW--V */
468#define NV_PFIFO_RAMHT_SIZE_32K 0x00000003 /* RW--V */
469#define NV_PFIFO_RAMHT_SEARCH 25:24 /* RWIUF */
470#define NV_PFIFO_RAMHT_SEARCH_16 0x00000000 /* RWI-V */
471#define NV_PFIFO_RAMHT_SEARCH_32 0x00000001 /* RW--V */
472#define NV_PFIFO_RAMHT_SEARCH_64 0x00000002 /* RW--V */
473#define NV_PFIFO_RAMHT_SEARCH_128 0x00000003 /* RW--V */
474#define NV_PFIFO_RAMFC 0x00002214 /* RW-4R */
475#define NV_PFIFO_RAMFC_BASE_ADDRESS 8:1 /* RWIUF */
476#define NV_PFIFO_RAMFC_BASE_ADDRESS_11000 0x00000088 /* RWI-V */
477#define NV_PFIFO_RAMRO 0x00002218 /* RW-4R */
478#define NV_PFIFO_RAMRO_BASE_ADDRESS 8:1 /* RWIUF */
479#define NV_PFIFO_RAMRO_BASE_ADDRESS_11200 0x00000089 /* RWI-V */
480#define NV_PFIFO_RAMRO_BASE_ADDRESS_12000 0x00000090 /* RW--V */
481#define NV_PFIFO_RAMRO_SIZE 16:16 /* RWIVF */
482#define NV_PFIFO_RAMRO_SIZE_512 0x00000000 /* RWI-V */
483#define NV_PFIFO_RAMRO_SIZE_8K 0x00000001 /* RW--V */
484#define NV_PFIFO_CACHES 0x00002500 /* RW-4R */
485#define NV_PFIFO_CACHES_REASSIGN 0:0 /* RWIVF */
486#define NV_PFIFO_CACHES_REASSIGN_DISABLED 0x00000000 /* RWI-V */
487#define NV_PFIFO_CACHES_REASSIGN_ENABLED 0x00000001 /* RW--V */
488#define NV_PFIFO_CACHES_DMA_SUSPEND 4:4 /* R--VF */
489#define NV_PFIFO_CACHES_DMA_SUSPEND_IDLE 0x00000000 /* R---V */
490#define NV_PFIFO_CACHES_DMA_SUSPEND_BUSY 0x00000001 /* R---V */
491#define NV_PFIFO_MODE 0x00002504 /* RW-4R */
492#define NV_PFIFO_MODE_CHANNEL_0 0:0 /* RWIVF */
493#define NV_PFIFO_MODE_CHANNEL_0_PIO 0x00000000 /* RWI-V */
494#define NV_PFIFO_MODE_CHANNEL_0_DMA 0x00000001 /* RW--V */
495#define NV_PFIFO_MODE_CHANNEL_1 1:1 /* RWIVF */
496#define NV_PFIFO_MODE_CHANNEL_1_PIO 0x00000000 /* RWI-V */
497#define NV_PFIFO_MODE_CHANNEL_1_DMA 0x00000001 /* RW--V */
498#define NV_PFIFO_MODE_CHANNEL_2 2:2 /* RWIVF */
499#define NV_PFIFO_MODE_CHANNEL_2_PIO 0x00000000 /* RWI-V */
500#define NV_PFIFO_MODE_CHANNEL_2_DMA 0x00000001 /* RW--V */
501#define NV_PFIFO_MODE_CHANNEL_3 3:3 /* RWIVF */
502#define NV_PFIFO_MODE_CHANNEL_3_PIO 0x00000000 /* RWI-V */
503#define NV_PFIFO_MODE_CHANNEL_3_DMA 0x00000001 /* RW--V */
504#define NV_PFIFO_MODE_CHANNEL_4 4:4 /* RWIVF */
505#define NV_PFIFO_MODE_CHANNEL_4_PIO 0x00000000 /* RWI-V */
506#define NV_PFIFO_MODE_CHANNEL_4_DMA 0x00000001 /* RW--V */
507#define NV_PFIFO_MODE_CHANNEL_5 5:5 /* RWIVF */
508#define NV_PFIFO_MODE_CHANNEL_5_PIO 0x00000000 /* RWI-V */
509#define NV_PFIFO_MODE_CHANNEL_5_DMA 0x00000001 /* RW--V */
510#define NV_PFIFO_MODE_CHANNEL_6 6:6 /* RWIVF */
511#define NV_PFIFO_MODE_CHANNEL_6_PIO 0x00000000 /* RWI-V */
512#define NV_PFIFO_MODE_CHANNEL_6_DMA 0x00000001 /* RW--V */
513#define NV_PFIFO_MODE_CHANNEL_7 7:7 /* RWIVF */
514#define NV_PFIFO_MODE_CHANNEL_7_PIO 0x00000000 /* RWI-V */
515#define NV_PFIFO_MODE_CHANNEL_7_DMA 0x00000001 /* RW--V */
516#define NV_PFIFO_MODE_CHANNEL_8 8:8 /* RWIVF */
517#define NV_PFIFO_MODE_CHANNEL_8_PIO 0x00000000 /* RWI-V */
518#define NV_PFIFO_MODE_CHANNEL_8_DMA 0x00000001 /* RW--V */
519#define NV_PFIFO_MODE_CHANNEL_9 9:9 /* RWIVF */
520#define NV_PFIFO_MODE_CHANNEL_9_PIO 0x00000000 /* RWI-V */
521#define NV_PFIFO_MODE_CHANNEL_9_DMA 0x00000001 /* RW--V */
522#define NV_PFIFO_MODE_CHANNEL_10 10:10 /* RWIVF */
523#define NV_PFIFO_MODE_CHANNEL_10_PIO 0x00000000 /* RWI-V */
524#define NV_PFIFO_MODE_CHANNEL_10_DMA 0x00000001 /* RW--V */
525#define NV_PFIFO_MODE_CHANNEL_11 11:11 /* RWIVF */
526#define NV_PFIFO_MODE_CHANNEL_11_PIO 0x00000000 /* RWI-V */
527#define NV_PFIFO_MODE_CHANNEL_11_DMA 0x00000001 /* RW--V */
528#define NV_PFIFO_MODE_CHANNEL_12 12:12 /* RWIVF */
529#define NV_PFIFO_MODE_CHANNEL_12_PIO 0x00000000 /* RWI-V */
530#define NV_PFIFO_MODE_CHANNEL_12_DMA 0x00000001 /* RW--V */
531#define NV_PFIFO_MODE_CHANNEL_13 13:13 /* RWIVF */
532#define NV_PFIFO_MODE_CHANNEL_13_PIO 0x00000000 /* RWI-V */
533#define NV_PFIFO_MODE_CHANNEL_13_DMA 0x00000001 /* RW--V */
534#define NV_PFIFO_MODE_CHANNEL_14 14:14 /* RWIVF */
535#define NV_PFIFO_MODE_CHANNEL_14_PIO 0x00000000 /* RWI-V */
536#define NV_PFIFO_MODE_CHANNEL_14_DMA 0x00000001 /* RW--V */
537#define NV_PFIFO_MODE_CHANNEL_15 15:15 /* RWIVF */
538#define NV_PFIFO_MODE_CHANNEL_15_PIO 0x00000000 /* RWI-V */
539#define NV_PFIFO_MODE_CHANNEL_15_DMA 0x00000001 /* RW--V */
540#define NV_PFIFO_DMA 0x00002508 /* RW-4R */
541#define NV_PFIFO_DMA_CHANNEL_0 0:0 /* RWIVF */
542#define NV_PFIFO_DMA_CHANNEL_0_NOT_PENDING 0x00000000 /* RWI-V */
543#define NV_PFIFO_DMA_CHANNEL_0_PENDING 0x00000001 /* RW--V */
544#define NV_PFIFO_DMA_CHANNEL_1 1:1 /* RWIVF */
545#define NV_PFIFO_DMA_CHANNEL_1_NOT_PENDING 0x00000000 /* RWI-V */
546#define NV_PFIFO_DMA_CHANNEL_1_PENDING 0x00000001 /* RW--V */
547#define NV_PFIFO_DMA_CHANNEL_2 2:2 /* RWIVF */
548#define NV_PFIFO_DMA_CHANNEL_2_NOT_PENDING 0x00000000 /* RWI-V */
549#define NV_PFIFO_DMA_CHANNEL_2_PENDING 0x00000001 /* RW--V */
550#define NV_PFIFO_DMA_CHANNEL_3 3:3 /* RWIVF */
551#define NV_PFIFO_DMA_CHANNEL_3_NOT_PENDING 0x00000000 /* RWI-V */
552#define NV_PFIFO_DMA_CHANNEL_3_PENDING 0x00000001 /* RW--V */
553#define NV_PFIFO_DMA_CHANNEL_4 4:4 /* RWIVF */
554#define NV_PFIFO_DMA_CHANNEL_4_NOT_PENDING 0x00000000 /* RWI-V */
555#define NV_PFIFO_DMA_CHANNEL_4_PENDING 0x00000001 /* RW--V */
556#define NV_PFIFO_DMA_CHANNEL_5 5:5 /* RWIVF */
557#define NV_PFIFO_DMA_CHANNEL_5_NOT_PENDING 0x00000000 /* RWI-V */
558#define NV_PFIFO_DMA_CHANNEL_5_PENDING 0x00000001 /* RW--V */
559#define NV_PFIFO_DMA_CHANNEL_6 6:6 /* RWIVF */
560#define NV_PFIFO_DMA_CHANNEL_6_NOT_PENDING 0x00000000 /* RWI-V */
561#define NV_PFIFO_DMA_CHANNEL_6_PENDING 0x00000001 /* RW--V */
562#define NV_PFIFO_DMA_CHANNEL_7 7:7 /* RWIVF */
563#define NV_PFIFO_DMA_CHANNEL_7_NOT_PENDING 0x00000000 /* RWI-V */
564#define NV_PFIFO_DMA_CHANNEL_7_PENDING 0x00000001 /* RW--V */
565#define NV_PFIFO_DMA_CHANNEL_8 8:8 /* RWIVF */
566#define NV_PFIFO_DMA_CHANNEL_8_NOT_PENDING 0x00000000 /* RWI-V */
567#define NV_PFIFO_DMA_CHANNEL_8_PENDING 0x00000001 /* RW--V */
568#define NV_PFIFO_DMA_CHANNEL_9 9:9 /* RWIVF */
569#define NV_PFIFO_DMA_CHANNEL_9_NOT_PENDING 0x00000000 /* RWI-V */
570#define NV_PFIFO_DMA_CHANNEL_9_PENDING 0x00000001 /* RW--V */
571#define NV_PFIFO_DMA_CHANNEL_10 10:10 /* RWIVF */
572#define NV_PFIFO_DMA_CHANNEL_10_NOT_PENDING 0x00000000 /* RWI-V */
573#define NV_PFIFO_DMA_CHANNEL_10_PENDING 0x00000001 /* RW--V */
574#define NV_PFIFO_DMA_CHANNEL_11 11:11 /* RWIVF */
575#define NV_PFIFO_DMA_CHANNEL_11_NOT_PENDING 0x00000000 /* RWI-V */
576#define NV_PFIFO_DMA_CHANNEL_11_PENDING 0x00000001 /* RW--V */
577#define NV_PFIFO_DMA_CHANNEL_12 12:12 /* RWIVF */
578#define NV_PFIFO_DMA_CHANNEL_12_NOT_PENDING 0x00000000 /* RWI-V */
579#define NV_PFIFO_DMA_CHANNEL_12_PENDING 0x00000001 /* RW--V */
580#define NV_PFIFO_DMA_CHANNEL_13 13:13 /* RWIVF */
581#define NV_PFIFO_DMA_CHANNEL_13_NOT_PENDING 0x00000000 /* RWI-V */
582#define NV_PFIFO_DMA_CHANNEL_13_PENDING 0x00000001 /* RW--V */
583#define NV_PFIFO_DMA_CHANNEL_14 14:14 /* RWIVF */
584#define NV_PFIFO_DMA_CHANNEL_14_NOT_PENDING 0x00000000 /* RWI-V */
585#define NV_PFIFO_DMA_CHANNEL_14_PENDING 0x00000001 /* RW--V */
586#define NV_PFIFO_DMA_CHANNEL_15 15:15 /* RWIVF */
587#define NV_PFIFO_DMA_CHANNEL_15_NOT_PENDING 0x00000000 /* RWI-V */
588#define NV_PFIFO_DMA_CHANNEL_15_PENDING 0x00000001 /* RW--V */
589#define NV_PFIFO_SIZE 0x0000250C /* RW-4R */
590#define NV_PFIFO_SIZE_CHANNEL_0 0:0 /* RWIVF */
591#define NV_PFIFO_SIZE_CHANNEL_0_124_BYTES 0x00000000 /* RWI-V */
592#define NV_PFIFO_SIZE_CHANNEL_0_512_BYTES 0x00000001 /* RW--V */
593#define NV_PFIFO_SIZE_CHANNEL_1 1:1 /* RWIVF */
594#define NV_PFIFO_SIZE_CHANNEL_1_124_BYTES 0x00000000 /* RWI-V */
595#define NV_PFIFO_SIZE_CHANNEL_1_512_BYTES 0x00000001 /* RW--V */
596#define NV_PFIFO_SIZE_CHANNEL_2 2:2 /* RWIVF */
597#define NV_PFIFO_SIZE_CHANNEL_2_124_BYTES 0x00000000 /* RWI-V */
598#define NV_PFIFO_SIZE_CHANNEL_2_512_BYTES 0x00000001 /* RW--V */
599#define NV_PFIFO_SIZE_CHANNEL_3 3:3 /* RWIVF */
600#define NV_PFIFO_SIZE_CHANNEL_3_124_BYTES 0x00000000 /* RWI-V */
601#define NV_PFIFO_SIZE_CHANNEL_3_512_BYTES 0x00000001 /* RW--V */
602#define NV_PFIFO_SIZE_CHANNEL_4 4:4 /* RWIVF */
603#define NV_PFIFO_SIZE_CHANNEL_4_124_BYTES 0x00000000 /* RWI-V */
604#define NV_PFIFO_SIZE_CHANNEL_4_512_BYTES 0x00000001 /* RW--V */
605#define NV_PFIFO_SIZE_CHANNEL_5 5:5 /* RWIVF */
606#define NV_PFIFO_SIZE_CHANNEL_5_124_BYTES 0x00000000 /* RWI-V */
607#define NV_PFIFO_SIZE_CHANNEL_5_512_BYTES 0x00000001 /* RW--V */
608#define NV_PFIFO_SIZE_CHANNEL_6 6:6 /* RWIVF */
609#define NV_PFIFO_SIZE_CHANNEL_6_124_BYTES 0x00000000 /* RWI-V */
610#define NV_PFIFO_SIZE_CHANNEL_6_512_BYTES 0x00000001 /* RW--V */
611#define NV_PFIFO_SIZE_CHANNEL_7 7:7 /* RWIVF */
612#define NV_PFIFO_SIZE_CHANNEL_7_124_BYTES 0x00000000 /* RWI-V */
613#define NV_PFIFO_SIZE_CHANNEL_7_512_BYTES 0x00000001 /* RW--V */
614#define NV_PFIFO_SIZE_CHANNEL_8 8:8 /* RWIVF */
615#define NV_PFIFO_SIZE_CHANNEL_8_124_BYTES 0x00000000 /* RWI-V */
616#define NV_PFIFO_SIZE_CHANNEL_8_512_BYTES 0x00000001 /* RW--V */
617#define NV_PFIFO_SIZE_CHANNEL_9 9:9 /* RWIVF */
618#define NV_PFIFO_SIZE_CHANNEL_9_124_BYTES 0x00000000 /* RWI-V */
619#define NV_PFIFO_SIZE_CHANNEL_9_512_BYTES 0x00000001 /* RW--V */
620#define NV_PFIFO_SIZE_CHANNEL_10 10:10 /* RWIVF */
621#define NV_PFIFO_SIZE_CHANNEL_10_124_BYTES 0x00000000 /* RWI-V */
622#define NV_PFIFO_SIZE_CHANNEL_10_512_BYTES 0x00000001 /* RW--V */
623#define NV_PFIFO_SIZE_CHANNEL_11 11:11 /* RWIVF */
624#define NV_PFIFO_SIZE_CHANNEL_11_124_BYTES 0x00000000 /* RWI-V */
625#define NV_PFIFO_SIZE_CHANNEL_11_512_BYTES 0x00000001 /* RW--V */
626#define NV_PFIFO_SIZE_CHANNEL_12 12:12 /* RWIVF */
627#define NV_PFIFO_SIZE_CHANNEL_12_124_BYTES 0x00000000 /* RWI-V */
628#define NV_PFIFO_SIZE_CHANNEL_12_512_BYTES 0x00000001 /* RW--V */
629#define NV_PFIFO_SIZE_CHANNEL_13 13:13 /* RWIVF */
630#define NV_PFIFO_SIZE_CHANNEL_13_124_BYTES 0x00000000 /* RWI-V */
631#define NV_PFIFO_SIZE_CHANNEL_13_512_BYTES 0x00000001 /* RW--V */
632#define NV_PFIFO_SIZE_CHANNEL_14 14:14 /* RWIVF */
633#define NV_PFIFO_SIZE_CHANNEL_14_124_BYTES 0x00000000 /* RWI-V */
634#define NV_PFIFO_SIZE_CHANNEL_14_512_BYTES 0x00000001 /* RW--V */
635#define NV_PFIFO_SIZE_CHANNEL_15 15:15 /* RWIVF */
636#define NV_PFIFO_SIZE_CHANNEL_15_124_BYTES 0x00000000 /* RWI-V */
637#define NV_PFIFO_SIZE_CHANNEL_15_512_BYTES 0x00000001 /* RW--V */
638#define NV_PFIFO_CACHE0_PUSH0 0x00003000 /* RW-4R */
639#define NV_PFIFO_CACHE0_PUSH0_ACCESS 0:0 /* RWIVF */
640#define NV_PFIFO_CACHE0_PUSH0_ACCESS_DISABLED 0x00000000 /* RWI-V */
641#define NV_PFIFO_CACHE0_PUSH0_ACCESS_ENABLED 0x00000001 /* RW--V */
642#define NV_PFIFO_CACHE1_PUSH0 0x00003200 /* RW-4R */
643#define NV_PFIFO_CACHE1_PUSH0_ACCESS 0:0 /* RWIVF */
644#define NV_PFIFO_CACHE1_PUSH0_ACCESS_DISABLED 0x00000000 /* RWI-V */
645#define NV_PFIFO_CACHE1_PUSH0_ACCESS_ENABLED 0x00000001 /* RW--V */
646#define NV_PFIFO_CACHE0_PUSH1 0x00003004 /* RW-4R */
647#define NV_PFIFO_CACHE0_PUSH1_CHID 3:0 /* RWXUF */
648#define NV_PFIFO_CACHE1_PUSH1 0x00003204 /* RW-4R */
649#define NV_PFIFO_CACHE1_PUSH1_CHID 3:0 /* RWXUF */
650#define NV_PFIFO_CACHE1_PUSH1_MODE 8:8 /* RWIVF */
651#define NV_PFIFO_CACHE1_PUSH1_MODE_PIO 0x00000000 /* RWI-V */
652#define NV_PFIFO_CACHE1_PUSH1_MODE_DMA 0x00000001 /* RW--V */
653#define NV_PFIFO_CACHE1_DMA_PUSH 0x00003220 /* RW-4R */
654#define NV_PFIFO_CACHE1_DMA_PUSH_ACCESS 0:0 /* RWIVF */
655#define NV_PFIFO_CACHE1_DMA_PUSH_ACCESS_DISABLED 0x00000000 /* RWI-V */
656#define NV_PFIFO_CACHE1_DMA_PUSH_ACCESS_ENABLED 0x00000001 /* RW--V */
657#define NV_PFIFO_CACHE1_DMA_PUSH_STATE 4:4 /* R--VF */
658#define NV_PFIFO_CACHE1_DMA_PUSH_STATE_IDLE 0x00000000 /* R---V */
659#define NV_PFIFO_CACHE1_DMA_PUSH_STATE_BUSY 0x00000001 /* R---V */
660#define NV_PFIFO_CACHE1_DMA_PUSH_BUFFER 8:8 /* R--VF */
661#define NV_PFIFO_CACHE1_DMA_PUSH_BUFFER_NOT_EMPTY 0x00000000 /* R---V */
662#define NV_PFIFO_CACHE1_DMA_PUSH_BUFFER_EMPTY 0x00000001 /* R---V */
663#define NV_PFIFO_CACHE1_DMA_PUSH_STATUS 12:12 /* RWIVF */
664#define NV_PFIFO_CACHE1_DMA_PUSH_STATUS_RUNNING 0x00000000 /* RWI-V */
665#define NV_PFIFO_CACHE1_DMA_PUSH_STATUS_SUSPENDED 0x00000001 /* RW--V */
666#define NV_PFIFO_CACHE1_DMA_FETCH 0x00003224 /* RW-4R */
667#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG 7:3 /* RWIUF */
668#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_8_BYTES 0x00000000 /* RW--V */
669#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_16_BYTES 0x00000001 /* RW--V */
670#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_24_BYTES 0x00000002 /* RW--V */
671#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_32_BYTES 0x00000003 /* RW--V */
672#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_40_BYTES 0x00000004 /* RW--V */
673#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_48_BYTES 0x00000005 /* RW--V */
674#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_56_BYTES 0x00000006 /* RW--V */
675#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_64_BYTES 0x00000007 /* RW--V */
676#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_72_BYTES 0x00000008 /* RW--V */
677#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_80_BYTES 0x00000009 /* RW--V */
678#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_88_BYTES 0x0000000A /* RW--V */
679#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_96_BYTES 0x0000000B /* RW--V */
680#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_104_BYTES 0x0000000C /* RW--V */
681#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_112_BYTES 0x0000000D /* RW--V */
682#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_120_BYTES 0x0000000E /* RW--V */
683#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_128_BYTES 0x0000000F /* RWI-V */
684#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_136_BYTES 0x00000010 /* RW--V */
685#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_144_BYTES 0x00000011 /* RW--V */
686#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_152_BYTES 0x00000012 /* RW--V */
687#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_160_BYTES 0x00000013 /* RW--V */
688#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_168_BYTES 0x00000014 /* RW--V */
689#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_176_BYTES 0x00000015 /* RW--V */
690#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_184_BYTES 0x00000016 /* RW--V */
691#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_192_BYTES 0x00000017 /* RW--V */
692#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_200_BYTES 0x00000018 /* RW--V */
693#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_208_BYTES 0x00000019 /* RW--V */
694#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_216_BYTES 0x0000001A /* RW--V */
695#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_224_BYTES 0x0000001B /* RW--V */
696#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_232_BYTES 0x0000001C /* RW--V */
697#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_240_BYTES 0x0000001D /* RW--V */
698#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_248_BYTES 0x0000001E /* RW--V */
699#define NV_PFIFO_CACHE1_DMA_FETCH_TRIG_256_BYTES 0x0000001F /* RW--V */
700#define NV_PFIFO_CACHE1_DMA_FETCH_SIZE 15:13 /* RWIUF */
701#define NV_PFIFO_CACHE1_DMA_FETCH_SIZE_32_BYTES 0x00000000 /* RW--V */
702#define NV_PFIFO_CACHE1_DMA_FETCH_SIZE_64_BYTES 0x00000001 /* RW--V */
703#define NV_PFIFO_CACHE1_DMA_FETCH_SIZE_96_BYTES 0x00000002 /* RW--V */
704#define NV_PFIFO_CACHE1_DMA_FETCH_SIZE_128_BYTES 0x00000003 /* RWI-V */
705#define NV_PFIFO_CACHE1_DMA_FETCH_SIZE_160_BYTES 0x00000004 /* RW--V */
706#define NV_PFIFO_CACHE1_DMA_FETCH_SIZE_192_BYTES 0x00000005 /* RW--V */
707#define NV_PFIFO_CACHE1_DMA_FETCH_SIZE_224_BYTES 0x00000006 /* RW--V */
708#define NV_PFIFO_CACHE1_DMA_FETCH_SIZE_256_BYTES 0x00000007 /* RW--V */
709#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS 19:16 /* RWIUF */
710#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_0 0x00000000 /* RWI-V */
711#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_1 0x00000001 /* RW--V */
712#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_2 0x00000002 /* RW--V */
713#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_3 0x00000003 /* RW--V */
714#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_4 0x00000004 /* RW--V */
715#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_5 0x00000005 /* RW--V */
716#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_6 0x00000006 /* RW--V */
717#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_7 0x00000007 /* RW--V */
718#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_8 0x00000008 /* RW--V */
719#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_9 0x00000009 /* RW--V */
720#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_10 0x0000000A /* RW--V */
721#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_11 0x0000000B /* RW--V */
722#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_12 0x0000000C /* RW--V */
723#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_13 0x0000000D /* RW--V */
724#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_14 0x0000000E /* RW--V */
725#define NV_PFIFO_CACHE1_DMA_FETCH_MAX_REQS_15 0x0000000F /* RW--V */
726#define NV_PFIFO_CACHE1_DMA_PUT 0x00003240 /* RW-4R */
727#define NV_PFIFO_CACHE1_DMA_PUT_OFFSET 28:2 /* RWXUF */
728#define NV_PFIFO_CACHE1_DMA_GET 0x00003244 /* RW-4R */
729#define NV_PFIFO_CACHE1_DMA_GET_OFFSET 28:2 /* RWXUF */
730#define NV_PFIFO_CACHE1_DMA_STATE 0x00003228 /* RW-4R */
731#define NV_PFIFO_CACHE1_DMA_STATE_METHOD 12:2 /* RWXUF */
732#define NV_PFIFO_CACHE1_DMA_STATE_SUBCHANNEL 15:13 /* RWXUF */
733#define NV_PFIFO_CACHE1_DMA_STATE_METHOD_COUNT 28:18 /* RWIUF */
734#define NV_PFIFO_CACHE1_DMA_STATE_METHOD_COUNT_0 0x00000000 /* RWI-V */
735#define NV_PFIFO_CACHE1_DMA_STATE_ERROR 31:30 /* RWXUF */
736#define NV_PFIFO_CACHE1_DMA_STATE_ERROR_NONE 0x00000000 /* RW--V */
737#define NV_PFIFO_CACHE1_DMA_STATE_ERROR_NON_CACHE 0x00000001 /* RW--V */
738#define NV_PFIFO_CACHE1_DMA_STATE_ERROR_RESERVED_CMD 0x00000002 /* RW--V */
739#define NV_PFIFO_CACHE1_DMA_STATE_ERROR_PROTECTION 0x00000003 /* RW--V */
740#define NV_PFIFO_CACHE1_DMA_INSTANCE 0x0000322C /* RW-4R */
741#define NV_PFIFO_CACHE1_DMA_INSTANCE_ADDRESS 15:0 /* RWXUF */
742#define NV_PFIFO_CACHE1_DMA_CTL 0x00003230 /* RW-4R */
743#define NV_PFIFO_CACHE1_DMA_CTL_ADJUST 11:2 /* RWXUF */
744#define NV_PFIFO_CACHE1_DMA_CTL_PAGE_TABLE 12:12 /* RWXUF */
745#define NV_PFIFO_CACHE1_DMA_CTL_PAGE_TABLE_NOT_PRESENT 0x00000000 /* RW--V */
746#define NV_PFIFO_CACHE1_DMA_CTL_PAGE_TABLE_PRESENT 0x00000001 /* RW--V */
747#define NV_PFIFO_CACHE1_DMA_CTL_PAGE_ENTRY 13:13 /* RWXUF */
748#define NV_PFIFO_CACHE1_DMA_CTL_PAGE_ENTRY_NOT_LINEAR 0x00000000 /* RW--V */
749#define NV_PFIFO_CACHE1_DMA_CTL_PAGE_ENTRY_LINEAR 0x00000001 /* RW--V */
750#define NV_PFIFO_CACHE1_DMA_CTL_TARGET_NODE 17:16 /* RWXUF */
751#define NV_PFIFO_CACHE1_DMA_CTL_TARGET_NODE_PCI 0x00000002 /* RW--V */
752#define NV_PFIFO_CACHE1_DMA_CTL_TARGET_NODE_AGP 0x00000003 /* RW--V */
753#define NV_PFIFO_CACHE1_DMA_CTL_AT_INFO 31:31 /* RWIUF */
754#define NV_PFIFO_CACHE1_DMA_CTL_AT_INFO_INVALID 0x00000000 /* RW--V */
755#define NV_PFIFO_CACHE1_DMA_CTL_AT_INFO_VALID 0x00000001 /* RWI-V */
756#define NV_PFIFO_CACHE1_DMA_LIMIT 0x00003234 /* RW-4R */
757#define NV_PFIFO_CACHE1_DMA_LIMIT_OFFSET 28:2 /* RWXUF */
758#define NV_PFIFO_CACHE1_DMA_TLB_TAG 0x00003238 /* RW-4R */
759#define NV_PFIFO_CACHE1_DMA_TLB_TAG_ADDRESS 28:12 /* RWXUF */
760#define NV_PFIFO_CACHE1_DMA_TLB_TAG_STATE 0:0 /* RWIUF */
761#define NV_PFIFO_CACHE1_DMA_TLB_TAG_STATE_INVALID 0x00000000 /* RWI-V */
762#define NV_PFIFO_CACHE1_DMA_TLB_TAG_STATE_VALID 0x00000001 /* RW--V */
763#define NV_PFIFO_CACHE1_DMA_TLB_PTE 0x0000323C /* RW-4R */
764#define NV_PFIFO_CACHE1_DMA_TLB_PTE_FRAME_ADDRESS 31:12 /* RWXUF */
765#define NV_PFIFO_CACHE0_PULL0 0x00003050 /* RW-4R */
766#define NV_PFIFO_CACHE0_PULL0_ACCESS 0:0 /* RWIVF */
767#define NV_PFIFO_CACHE0_PULL0_ACCESS_DISABLED 0x00000000 /* RWI-V */
768#define NV_PFIFO_CACHE0_PULL0_ACCESS_ENABLED 0x00000001 /* RW--V */
769#define NV_PFIFO_CACHE0_PULL0_HASH 4:4 /* R-XVF */
770#define NV_PFIFO_CACHE0_PULL0_HASH_SUCCEEDED 0x00000000 /* R---V */
771#define NV_PFIFO_CACHE0_PULL0_HASH_FAILED 0x00000001 /* R---V */
772#define NV_PFIFO_CACHE0_PULL0_DEVICE 8:8 /* R-XVF */
773#define NV_PFIFO_CACHE0_PULL0_DEVICE_HARDWARE 0x00000000 /* R---V */
774#define NV_PFIFO_CACHE0_PULL0_DEVICE_SOFTWARE 0x00000001 /* R---V */
775#define NV_PFIFO_CACHE0_PULL0_HASH_STATE 12:12 /* R-XVF */
776#define NV_PFIFO_CACHE0_PULL0_HASH_STATE_IDLE 0x00000000 /* R---V */
777#define NV_PFIFO_CACHE0_PULL0_HASH_STATE_BUSY 0x00000001 /* R---V */
778#define NV_PFIFO_CACHE1_PULL0 0x00003250 /* RW-4R */
779#define NV_PFIFO_CACHE1_PULL0_ACCESS 0:0 /* RWIVF */
780#define NV_PFIFO_CACHE1_PULL0_ACCESS_DISABLED 0x00000000 /* RWI-V */
781#define NV_PFIFO_CACHE1_PULL0_ACCESS_ENABLED 0x00000001 /* RW--V */
782#define NV_PFIFO_CACHE1_PULL0_HASH 4:4 /* R-XVF */
783#define NV_PFIFO_CACHE1_PULL0_HASH_SUCCEEDED 0x00000000 /* R---V */
784#define NV_PFIFO_CACHE1_PULL0_HASH_FAILED 0x00000001 /* R---V */
785#define NV_PFIFO_CACHE1_PULL0_DEVICE 8:8 /* R-XVF */
786#define NV_PFIFO_CACHE1_PULL0_DEVICE_HARDWARE 0x00000000 /* R---V */
787#define NV_PFIFO_CACHE1_PULL0_DEVICE_SOFTWARE 0x00000001 /* R---V */
788#define NV_PFIFO_CACHE1_PULL0_HASH_STATE 12:12 /* R-XVF */
789#define NV_PFIFO_CACHE1_PULL0_HASH_STATE_IDLE 0x00000000 /* R---V */
790#define NV_PFIFO_CACHE1_PULL0_HASH_STATE_BUSY 0x00000001 /* R---V */
791#define NV_PFIFO_CACHE0_PULL1 0x00003054 /* RW-4R */
792#define NV_PFIFO_CACHE0_PULL1_ENGINE 1:0 /* RWXUF */
793#define NV_PFIFO_CACHE0_PULL1_ENGINE_SW 0x00000000 /* RW--V */
794#define NV_PFIFO_CACHE0_PULL1_ENGINE_GRAPHICS 0x00000001 /* RW--V */
795#define NV_PFIFO_CACHE0_PULL1_ENGINE_DVD 0x00000002 /* RW--V */
796#define NV_PFIFO_CACHE1_PULL1 0x00003254 /* RW-4R */
797#define NV_PFIFO_CACHE1_PULL1_ENGINE 1:0 /* RWXUF */
798#define NV_PFIFO_CACHE1_PULL1_ENGINE_SW 0x00000000 /* RW--V */
799#define NV_PFIFO_CACHE1_PULL1_ENGINE_GRAPHICS 0x00000001 /* RW--V */
800#define NV_PFIFO_CACHE1_PULL1_ENGINE_DVD 0x00000002 /* RW--V */
801#define NV_PFIFO_CACHE0_HASH 0x00003058 /* RW-4R */
802#define NV_PFIFO_CACHE0_HASH_INSTANCE 15:0 /* RWXUF */
803#define NV_PFIFO_CACHE0_HASH_VALID 16:16 /* RWXVF */
804#define NV_PFIFO_CACHE1_HASH 0x00003258 /* RW-4R */
805#define NV_PFIFO_CACHE1_HASH_INSTANCE 15:0 /* RWXUF */
806#define NV_PFIFO_CACHE1_HASH_VALID 16:16 /* RWXVF */
807#define NV_PFIFO_CACHE0_STATUS 0x00003014 /* R--4R */
808#define NV_PFIFO_CACHE0_STATUS_LOW_MARK 4:4 /* R--VF */
809#define NV_PFIFO_CACHE0_STATUS_LOW_MARK_NOT_EMPTY 0x00000000 /* R---V */
810#define NV_PFIFO_CACHE0_STATUS_LOW_MARK_EMPTY 0x00000001 /* R---V */
811#define NV_PFIFO_CACHE0_STATUS_HIGH_MARK 8:8 /* R--VF */
812#define NV_PFIFO_CACHE0_STATUS_HIGH_MARK_NOT_FULL 0x00000000 /* R---V */
813#define NV_PFIFO_CACHE0_STATUS_HIGH_MARK_FULL 0x00000001 /* R---V */
814#define NV_PFIFO_CACHE1_STATUS 0x00003214 /* R--4R */
815#define NV_PFIFO_CACHE1_STATUS_LOW_MARK 4:4 /* R--VF */
816#define NV_PFIFO_CACHE1_STATUS_LOW_MARK_NOT_EMPTY 0x00000000 /* R---V */
817#define NV_PFIFO_CACHE1_STATUS_LOW_MARK_EMPTY 0x00000001 /* R---V */
818#define NV_PFIFO_CACHE1_STATUS_HIGH_MARK 8:8 /* R--VF */
819#define NV_PFIFO_CACHE1_STATUS_HIGH_MARK_NOT_FULL 0x00000000 /* R---V */
820#define NV_PFIFO_CACHE1_STATUS_HIGH_MARK_FULL 0x00000001 /* R---V */
821#define NV_PFIFO_CACHE1_STATUS1 0x00003218 /* R--4R */
822#define NV_PFIFO_CACHE1_STATUS1_RANOUT 0:0 /* R-XVF */
823#define NV_PFIFO_CACHE1_STATUS1_RANOUT_FALSE 0x00000000 /* R---V */
824#define NV_PFIFO_CACHE1_STATUS1_RANOUT_TRUE 0x00000001 /* R---V */
825#define NV_PFIFO_CACHE0_PUT 0x00003010 /* RW-4R */
826#define NV_PFIFO_CACHE0_PUT_ADDRESS 2:2 /* RWXUF */
827#define NV_PFIFO_CACHE1_PUT 0x00003210 /* RW-4R */
828#define NV_PFIFO_CACHE1_PUT_ADDRESS 9:2 /* RWXUF */
829#define NV_PFIFO_CACHE0_GET 0x00003070 /* RW-4R */
830#define NV_PFIFO_CACHE0_GET_ADDRESS 2:2 /* RWXUF */
831#define NV_PFIFO_CACHE1_GET 0x00003270 /* RW-4R */
832#define NV_PFIFO_CACHE1_GET_ADDRESS 9:2 /* RWXUF */
833#define NV_PFIFO_CACHE0_ENGINE 0x00003080 /* RW-4R */
834#define NV_PFIFO_CACHE0_ENGINE_0 1:0 /* RWXUF */
835#define NV_PFIFO_CACHE0_ENGINE_0_SW 0x00000000 /* RW--V */
836#define NV_PFIFO_CACHE0_ENGINE_0_GRAPHICS 0x00000001 /* RW--V */
837#define NV_PFIFO_CACHE0_ENGINE_0_DVD 0x00000002 /* RW--V */
838#define NV_PFIFO_CACHE0_ENGINE_1 5:4 /* RWXUF */
839#define NV_PFIFO_CACHE0_ENGINE_1_SW 0x00000000 /* RW--V */
840#define NV_PFIFO_CACHE0_ENGINE_1_GRAPHICS 0x00000001 /* RW--V */
841#define NV_PFIFO_CACHE0_ENGINE_1_DVD 0x00000002 /* RW--V */
842#define NV_PFIFO_CACHE0_ENGINE_2 9:8 /* RWXUF */
843#define NV_PFIFO_CACHE0_ENGINE_2_SW 0x00000000 /* RW--V */
844#define NV_PFIFO_CACHE0_ENGINE_2_GRAPHICS 0x00000001 /* RW--V */
845#define NV_PFIFO_CACHE0_ENGINE_2_DVD 0x00000002 /* RW--V */
846#define NV_PFIFO_CACHE0_ENGINE_3 13:12 /* RWXUF */
847#define NV_PFIFO_CACHE0_ENGINE_3_SW 0x00000000 /* RW--V */
848#define NV_PFIFO_CACHE0_ENGINE_3_GRAPHICS 0x00000001 /* RW--V */
849#define NV_PFIFO_CACHE0_ENGINE_3_DVD 0x00000002 /* RW--V */
850#define NV_PFIFO_CACHE0_ENGINE_4 17:16 /* RWXUF */
851#define NV_PFIFO_CACHE0_ENGINE_4_SW 0x00000000 /* RW--V */
852#define NV_PFIFO_CACHE0_ENGINE_4_GRAPHICS 0x00000001 /* RW--V */
853#define NV_PFIFO_CACHE0_ENGINE_4_DVD 0x00000002 /* RW--V */
854#define NV_PFIFO_CACHE0_ENGINE_5 21:20 /* RWXUF */
855#define NV_PFIFO_CACHE0_ENGINE_5_SW 0x00000000 /* RW--V */
856#define NV_PFIFO_CACHE0_ENGINE_5_GRAPHICS 0x00000001 /* RW--V */
857#define NV_PFIFO_CACHE0_ENGINE_5_DVD 0x00000002 /* RW--V */
858#define NV_PFIFO_CACHE0_ENGINE_6 25:24 /* RWXUF */
859#define NV_PFIFO_CACHE0_ENGINE_6_SW 0x00000000 /* RW--V */
860#define NV_PFIFO_CACHE0_ENGINE_6_GRAPHICS 0x00000001 /* RW--V */
861#define NV_PFIFO_CACHE0_ENGINE_6_DVD 0x00000002 /* RW--V */
862#define NV_PFIFO_CACHE0_ENGINE_7 29:28 /* RWXUF */
863#define NV_PFIFO_CACHE0_ENGINE_7_SW 0x00000000 /* RW--V */
864#define NV_PFIFO_CACHE0_ENGINE_7_GRAPHICS 0x00000001 /* RW--V */
865#define NV_PFIFO_CACHE0_ENGINE_7_DVD 0x00000002 /* RW--V */
866#define NV_PFIFO_CACHE1_ENGINE 0x00003280 /* RW-4R */
867#define NV_PFIFO_CACHE1_ENGINE_0 1:0 /* RWXUF */
868#define NV_PFIFO_CACHE1_ENGINE_0_SW 0x00000000 /* RW--V */
869#define NV_PFIFO_CACHE1_ENGINE_0_GRAPHICS 0x00000001 /* RW--V */
870#define NV_PFIFO_CACHE1_ENGINE_0_DVD 0x00000002 /* RW--V */
871#define NV_PFIFO_CACHE1_ENGINE_1 5:4 /* RWXUF */
872#define NV_PFIFO_CACHE1_ENGINE_1_SW 0x00000000 /* RW--V */
873#define NV_PFIFO_CACHE1_ENGINE_1_GRAPHICS 0x00000001 /* RW--V */
874#define NV_PFIFO_CACHE1_ENGINE_1_DVD 0x00000002 /* RW--V */
875#define NV_PFIFO_CACHE1_ENGINE_2 9:8 /* RWXUF */
876#define NV_PFIFO_CACHE1_ENGINE_2_SW 0x00000000 /* RW--V */
877#define NV_PFIFO_CACHE1_ENGINE_2_GRAPHICS 0x00000001 /* RW--V */
878#define NV_PFIFO_CACHE1_ENGINE_2_DVD 0x00000002 /* RW--V */
879#define NV_PFIFO_CACHE1_ENGINE_3 13:12 /* RWXUF */
880#define NV_PFIFO_CACHE1_ENGINE_3_SW 0x00000000 /* RW--V */
881#define NV_PFIFO_CACHE1_ENGINE_3_GRAPHICS 0x00000001 /* RW--V */
882#define NV_PFIFO_CACHE1_ENGINE_3_DVD 0x00000002 /* RW--V */
883#define NV_PFIFO_CACHE1_ENGINE_4 17:16 /* RWXUF */
884#define NV_PFIFO_CACHE1_ENGINE_4_SW 0x00000000 /* RW--V */
885#define NV_PFIFO_CACHE1_ENGINE_4_GRAPHICS 0x00000001 /* RW--V */
886#define NV_PFIFO_CACHE1_ENGINE_4_DVD 0x00000002 /* RW--V */
887#define NV_PFIFO_CACHE1_ENGINE_5 21:20 /* RWXUF */
888#define NV_PFIFO_CACHE1_ENGINE_5_SW 0x00000000 /* RW--V */
889#define NV_PFIFO_CACHE1_ENGINE_5_GRAPHICS 0x00000001 /* RW--V */
890#define NV_PFIFO_CACHE1_ENGINE_5_DVD 0x00000002 /* RW--V */
891#define NV_PFIFO_CACHE1_ENGINE_6 25:24 /* RWXUF */
892#define NV_PFIFO_CACHE1_ENGINE_6_SW 0x00000000 /* RW--V */
893#define NV_PFIFO_CACHE1_ENGINE_6_GRAPHICS 0x00000001 /* RW--V */
894#define NV_PFIFO_CACHE1_ENGINE_6_DVD 0x00000002 /* RW--V */
895#define NV_PFIFO_CACHE1_ENGINE_7 29:28 /* RWXUF */
896#define NV_PFIFO_CACHE1_ENGINE_7_SW 0x00000000 /* RW--V */
897#define NV_PFIFO_CACHE1_ENGINE_7_GRAPHICS 0x00000001 /* RW--V */
898#define NV_PFIFO_CACHE1_ENGINE_7_DVD 0x00000002 /* RW--V */
899#define NV_PFIFO_CACHE0_METHOD(i) (0x00003100+(i)*8) /* RW-4A */
900#define NV_PFIFO_CACHE0_METHOD__SIZE_1 1 /* */
901#define NV_PFIFO_CACHE0_METHOD_ADDRESS 12:2 /* RWXUF */
902#define NV_PFIFO_CACHE0_METHOD_SUBCHANNEL 15:13 /* RWXUF */
903#define NV_PFIFO_CACHE1_METHOD(i) (0x00003800+(i)*8) /* RW-4A */
904#define NV_PFIFO_CACHE1_METHOD__SIZE_1 128 /* */
905#define NV_PFIFO_CACHE1_METHOD_ADDRESS 12:2 /* RWXUF */
906#define NV_PFIFO_CACHE1_METHOD_SUBCHANNEL 15:13 /* RWXUF */
907#define NV_PFIFO_CACHE1_METHOD_ALIAS(i) (0x00003C00+(i)*8) /* RW-4A */
908#define NV_PFIFO_CACHE1_METHOD_ALIAS__SIZE_1 128 /* */
909#define NV_PFIFO_CACHE0_DATA(i) (0x00003104+(i)*8) /* RW-4A */
910#define NV_PFIFO_CACHE0_DATA__SIZE_1 1 /* */
911#define NV_PFIFO_CACHE0_DATA_VALUE 31:0 /* RWXVF */
912#define NV_PFIFO_CACHE1_DATA(i) (0x00003804+(i)*8) /* RW-4A */
913#define NV_PFIFO_CACHE1_DATA__SIZE_1 128 /* */
914#define NV_PFIFO_CACHE1_DATA_VALUE 31:0 /* RWXVF */
915#define NV_PFIFO_CACHE1_DATA_ALIAS(i) (0x00003C04+(i)*8) /* RW-4A */
916#define NV_PFIFO_CACHE1_DATA_ALIAS__SIZE_1 128 /* */
917#define NV_PFIFO_DEVICE(i) (0x00002800+(i)*4) /* R--4A */
918#define NV_PFIFO_DEVICE__SIZE_1 128 /* */
919#define NV_PFIFO_DEVICE_CHID 3:0 /* R--UF */
920#define NV_PFIFO_DEVICE_SWITCH 24:24 /* R--VF */
921#define NV_PFIFO_DEVICE_SWITCH_UNAVAILABLE 0x00000000 /* R---V */
922#define NV_PFIFO_DEVICE_SWITCH_AVAILABLE 0x00000001 /* R---V */
923#define NV_PFIFO_RUNOUT_STATUS 0x00002400 /* R--4R */
924#define NV_PFIFO_RUNOUT_STATUS_RANOUT 0:0 /* R--VF */
925#define NV_PFIFO_RUNOUT_STATUS_RANOUT_FALSE 0x00000000 /* R---V */
926#define NV_PFIFO_RUNOUT_STATUS_RANOUT_TRUE 0x00000001 /* R---V */
927#define NV_PFIFO_RUNOUT_STATUS_LOW_MARK 4:4 /* R--VF */
928#define NV_PFIFO_RUNOUT_STATUS_LOW_MARK_NOT_EMPTY 0x00000000 /* R---V */
929#define NV_PFIFO_RUNOUT_STATUS_LOW_MARK_EMPTY 0x00000001 /* R---V */
930#define NV_PFIFO_RUNOUT_STATUS_HIGH_MARK 8:8 /* R--VF */
931#define NV_PFIFO_RUNOUT_STATUS_HIGH_MARK_NOT_FULL 0x00000000 /* R---V */
932#define NV_PFIFO_RUNOUT_STATUS_HIGH_MARK_FULL 0x00000001 /* R---V */
933#define NV_PFIFO_RUNOUT_PUT 0x00002410 /* RW-4R */
934#define NV_PFIFO_RUNOUT_PUT_ADDRESS 12:3 /* RWXUF */
935#define NV_PFIFO_RUNOUT_PUT_ADDRESS__SIZE_0 8:3 /* RWXUF */
936#define NV_PFIFO_RUNOUT_PUT_ADDRESS__SIZE_1 12:3 /* RWXUF */
937#define NV_PFIFO_RUNOUT_GET 0x00002420 /* RW-4R */
938#define NV_PFIFO_RUNOUT_GET_ADDRESS 13:3 /* RWXUF */
939/* dev_graphics.ref */
940#define NV_PGRAPH 0x00401FFF:0x00400000 /* RW--D */
941#define NV_PGRAPH_DEBUG_0 0x00400080 /* RW-4R */
942#define NV_PGRAPH_DEBUG_1 0x00400084 /* RW-4R */
943#define NV_PGRAPH_DEBUG_2 0x00400088 /* RW-4R */
944#define NV_PGRAPH_DEBUG_3 0x0040008C /* RW-4R */
945#define NV_PGRAPH_INTR 0x00400100 /* RW-4R */
946#define NV_PGRAPH_INTR_NOTIFY 0:0 /* RWIVF */
947#define NV_PGRAPH_INTR_NOTIFY_NOT_PENDING 0x00000000 /* R-I-V */
948#define NV_PGRAPH_INTR_NOTIFY_PENDING 0x00000001 /* R---V */
949#define NV_PGRAPH_INTR_NOTIFY_RESET 0x00000001 /* -W--C */
950#define NV_PGRAPH_INTR_MISSING_HW 4:4 /* RWIVF */
951#define NV_PGRAPH_INTR_MISSING_HW_NOT_PENDING 0x00000000 /* R-I-V */
952#define NV_PGRAPH_INTR_MISSING_HW_PENDING 0x00000001 /* R---V */
953#define NV_PGRAPH_INTR_MISSING_HW_RESET 0x00000001 /* -W--C */
954#define NV_PGRAPH_INTR_TLB_PRESENT_A 8:8 /* RWIVF */
955#define NV_PGRAPH_INTR_TLB_PRESENT_A_NOT_PENDING 0x00000000 /* R-I-V */
956#define NV_PGRAPH_INTR_TLB_PRESENT_A_PENDING 0x00000001 /* R---V */
957#define NV_PGRAPH_INTR_TLB_PRESENT_A_RESET 0x00000001 /* -W--C */
958#define NV_PGRAPH_INTR_TLB_PRESENT_B 9:9 /* RWIVF */
959#define NV_PGRAPH_INTR_TLB_PRESENT_B_NOT_PENDING 0x00000000 /* R-I-V */
960#define NV_PGRAPH_INTR_TLB_PRESENT_B_PENDING 0x00000001 /* R---V */
961#define NV_PGRAPH_INTR_TLB_PRESENT_B_RESET 0x00000001 /* -W--C */
962#define NV_PGRAPH_INTR_CONTEXT_SWITCH 12:12 /* RWIVF */
963#define NV_PGRAPH_INTR_CONTEXT_SWITCH_NOT_PENDING 0x00000000 /* R-I-V */
964#define NV_PGRAPH_INTR_CONTEXT_SWITCH_PENDING 0x00000001 /* R---V */
965#define NV_PGRAPH_INTR_CONTEXT_SWITCH_RESET 0x00000001 /* -W--C */
966#define NV_PGRAPH_INTR_BUFFER_NOTIFY 16:16 /* RWIVF */
967#define NV_PGRAPH_INTR_BUFFER_NOTIFY_NOT_PENDING 0x00000000 /* R-I-V */
968#define NV_PGRAPH_INTR_BUFFER_NOTIFY_PENDING 0x00000001 /* R---V */
969#define NV_PGRAPH_INTR_BUFFER_NOTIFY_RESET 0x00000001 /* -W--C */
970#define NV_PGRAPH_NSTATUS 0x00400104 /* RW-4R */
971#define NV_PGRAPH_NSTATUS_STATE_IN_USE 11:11 /* RWIVF */
972#define NV_PGRAPH_NSTATUS_STATE_IN_USE_NOT_PENDING 0x00000000 /* RWI-V */
973#define NV_PGRAPH_NSTATUS_STATE_IN_USE_PENDING 0x00000001 /* RW--V */
974#define NV_PGRAPH_NSTATUS_INVALID_STATE 12:12 /* RWIVF */
975#define NV_PGRAPH_NSTATUS_INVALID_STATE_NOT_PENDING 0x00000000 /* RWI-V */
976#define NV_PGRAPH_NSTATUS_INVALID_STATE_PENDING 0x00000001 /* RW--V */
977#define NV_PGRAPH_NSTATUS_BAD_ARGUMENT 13:13 /* RWIVF */
978#define NV_PGRAPH_NSTATUS_BAD_ARGUMENT_NOT_PENDING 0x00000000 /* RWI-V */
979#define NV_PGRAPH_NSTATUS_BAD_ARGUMENT_PENDING 0x00000001 /* RW--V */
980#define NV_PGRAPH_NSTATUS_PROTECTION_FAULT 14:14 /* RWIVF */
981#define NV_PGRAPH_NSTATUS_PROTECTION_FAULT_NOT_PENDING 0x00000000 /* RWI-V */
982#define NV_PGRAPH_NSTATUS_PROTECTION_FAULT_PENDING 0x00000001 /* RW--V */
983#define NV_PGRAPH_NSOURCE 0x00400108 /* R--4R */
984#define NV_PGRAPH_NSOURCE_NOTIFICATION 0:0 /* R-IVF */
985#define NV_PGRAPH_NSOURCE_NOTIFICATION_NOT_PENDING 0x00000000 /* R-I-V */
986#define NV_PGRAPH_NSOURCE_NOTIFICATION_PENDING 0x00000001 /* R---V */
987#define NV_PGRAPH_NSOURCE_DATA_ERROR 1:1 /* R-IVF */
988#define NV_PGRAPH_NSOURCE_DATA_ERROR_NOT_PENDING 0x00000000 /* R-I-V */
989#define NV_PGRAPH_NSOURCE_DATA_ERROR_PENDING 0x00000001 /* R---V */
990#define NV_PGRAPH_NSOURCE_PROTECTION_ERROR 2:2 /* R-IVF */
991#define NV_PGRAPH_NSOURCE_PROTECTION_ERROR_NOT_PENDING 0x00000000 /* R-I-V */
992#define NV_PGRAPH_NSOURCE_PROTECTION_ERROR_PENDING 0x00000001 /* R---V */
993#define NV_PGRAPH_NSOURCE_RANGE_EXCEPTION 3:3 /* R-IVF */
994#define NV_PGRAPH_NSOURCE_RANGE_EXCEPTION_NOT_PENDING 0x00000000 /* R-I-V */
995#define NV_PGRAPH_NSOURCE_RANGE_EXCEPTION_PENDING 0x00000001 /* R---V */
996#define NV_PGRAPH_NSOURCE_LIMIT_COLOR 4:4 /* R-IVF */
997#define NV_PGRAPH_NSOURCE_LIMIT_COLOR_NOT_PENDING 0x00000000 /* R-I-V */
998#define NV_PGRAPH_NSOURCE_LIMIT_COLOR_PENDING 0x00000001 /* R---V */
999#define NV_PGRAPH_NSOURCE_LIMIT_ZETA_ 5:5 /* R-IVF */
1000#define NV_PGRAPH_NSOURCE_LIMIT_ZETA_NOT_PENDING 0x00000000 /* R-I-V */
1001#define NV_PGRAPH_NSOURCE_LIMIT_ZETA_PENDING 0x00000001 /* R---V */
1002#define NV_PGRAPH_NSOURCE_ILLEGAL_MTHD 6:6 /* R-IVF */
1003#define NV_PGRAPH_NSOURCE_ILLEGAL_MTHD_NOT_PENDING 0x00000000 /* R-I-V */
1004#define NV_PGRAPH_NSOURCE_ILLEGAL_MTHD_PENDING 0x00000001 /* R---V */
1005#define NV_PGRAPH_NSOURCE_DMA_R_PROTECTION 7:7 /* R-IVF */
1006#define NV_PGRAPH_NSOURCE_DMA_R_PROTECTION_NOT_PENDING 0x00000000 /* R-I-V */
1007#define NV_PGRAPH_NSOURCE_DMA_R_PROTECTION_PENDING 0x00000001 /* R---V */
1008#define NV_PGRAPH_NSOURCE_DMA_W_PROTECTION 8:8 /* R-IVF */
1009#define NV_PGRAPH_NSOURCE_DMA_W_PROTECTION_NOT_PENDING 0x00000000 /* R-I-V */
1010#define NV_PGRAPH_NSOURCE_DMA_W_PROTECTION_PENDING 0x00000001 /* R---V */
1011#define NV_PGRAPH_NSOURCE_FORMAT_EXCEPTION 9:9 /* R-IVF */
1012#define NV_PGRAPH_NSOURCE_FORMAT_EXCEPTION_NOT_PENDING 0x00000000 /* R-I-V */
1013#define NV_PGRAPH_NSOURCE_FORMAT_EXCEPTION_PENDING 0x00000001 /* R---V */
1014#define NV_PGRAPH_NSOURCE_PATCH_EXCEPTION 10:10 /* R-IVF */
1015#define NV_PGRAPH_NSOURCE_PATCH_EXCEPTION_NOT_PENDING 0x00000000 /* R-I-V */
1016#define NV_PGRAPH_NSOURCE_PATCH_EXCEPTION_PENDING 0x00000001 /* R---V */
1017#define NV_PGRAPH_NSOURCE_STATE_INVALID 11:11 /* R-IVF */
1018#define NV_PGRAPH_NSOURCE_STATE_INVALID_NOT_PENDING 0x00000000 /* R-I-V */
1019#define NV_PGRAPH_NSOURCE_STATE_INVALID_PENDING 0x00000001 /* R---V */
1020#define NV_PGRAPH_NSOURCE_DOUBLE_NOTIFY 12:12 /* R-IVF */
1021#define NV_PGRAPH_NSOURCE_DOUBLE_NOTIFY_NOT_PENDING 0x00000000 /* R-I-V */
1022#define NV_PGRAPH_NSOURCE_DOUBLE_NOTIFY_PENDING 0x00000001 /* R---V */
1023#define NV_PGRAPH_NSOURCE_NOTIFY_IN_USE 13:13 /* R-IVF */
1024#define NV_PGRAPH_NSOURCE_NOTIFY_IN_USE_NOT_PENDING 0x00000000 /* R-I-V */
1025#define NV_PGRAPH_NSOURCE_NOTIFY_IN_USE_PENDING 0x00000001 /* R---V */
1026#define NV_PGRAPH_NSOURCE_METHOD_CNT 14:14 /* R-IVF */
1027#define NV_PGRAPH_NSOURCE_METHOD_CNT_NOT_PENDING 0x00000000 /* R-I-V */
1028#define NV_PGRAPH_NSOURCE_METHOD_CNT_PENDING 0x00000001 /* R---V */
1029#define NV_PGRAPH_NSOURCE_BFR_NOTIFICATION 15:15 /* R-IVF */
1030#define NV_PGRAPH_NSOURCE_BFR_NOTIFICATION_NOT_PENDING 0x00000000 /* R-I-V */
1031#define NV_PGRAPH_NSOURCE_BFR_NOTIFICATION_PENDING 0x00000001 /* R---V */
1032#define NV_PGRAPH_INTR_EN 0x00400140 /* RW-4R */
1033#define NV_PGRAPH_INTR_EN_NOTIFY 0:0 /* RWIVF */
1034#define NV_PGRAPH_INTR_EN_NOTIFY_DISABLED 0x00000000 /* RWI-V */
1035#define NV_PGRAPH_INTR_EN_NOTIFY_ENABLED 0x00000001 /* RW--V */
1036#define NV_PGRAPH_INTR_EN_MISSING_HW 4:4 /* RWIVF */
1037#define NV_PGRAPH_INTR_EN_MISSING_HW_DISABLED 0x00000000 /* RWI-V */
1038#define NV_PGRAPH_INTR_EN_MISSING_HW_ENABLED 0x00000001 /* RW--V */
1039#define NV_PGRAPH_INTR_EN_TLB_PRESENT_A 8:8 /* RWIVF */
1040#define NV_PGRAPH_INTR_EN_TLB_PRESENT_A_DISABLED 0x00000000 /* RWI-V */
1041#define NV_PGRAPH_INTR_EN_TLB_PRESENT_A_ENABLED 0x00000001 /* RW--V */
1042#define NV_PGRAPH_INTR_EN_TLB_PRESENT_B 9:9 /* RWIVF */
1043#define NV_PGRAPH_INTR_EN_TLB_PRESENT_B_DISABLED 0x00000000 /* RWI-V */
1044#define NV_PGRAPH_INTR_EN_TLB_PRESENT_B_ENABLED 0x00000001 /* RW--V */
1045#define NV_PGRAPH_INTR_EN_CONTEXT_SWITCH 12:12 /* RWIVF */
1046#define NV_PGRAPH_INTR_EN_CONTEXT_SWITCH_DISABLED 0x00000000 /* RWI-V */
1047#define NV_PGRAPH_INTR_EN_CONTEXT_SWITCH_ENABLED 0x00000001 /* RW--V */
1048#define NV_PGRAPH_INTR_EN_BUFFER_NOTIFY 16:16 /* RWIVF */
1049#define NV_PGRAPH_INTR_EN_BUFFER_NOTIFY_DISABLED 0x00000000 /* RWI-V */
1050#define NV_PGRAPH_INTR_EN_BUFFER_NOTIFY_ENABLED 0x00000001 /* RW--V */
1051#define NV_PGRAPH_CTX_SWITCH1 0x00400160 /* RW-4R */
1052#define NV_PGRAPH_CTX_SWITCH1_GRCLASS 7:0 /* RWXVF */
1053#define NV_PGRAPH_CTX_SWITCH1_CHROMA_KEY 12:12 /* RWXUF */
1054#define NV_PGRAPH_CTX_SWITCH1_CHROMA_KEY_DISABLE 0x00000000 /* RW--V */
1055#define NV_PGRAPH_CTX_SWITCH1_CHROMA_KEY_ENABLE 0x00000001 /* RW--V */
1056#define NV_PGRAPH_CTX_SWITCH1_USER_CLIP 13:13 /* RWXUF */
1057#define NV_PGRAPH_CTX_SWITCH1_USER_CLIP_DISABLE 0x00000000 /* RW--V */
1058#define NV_PGRAPH_CTX_SWITCH1_USER_CLIP_ENABLE 0x00000001 /* RW--V */
1059#define NV_PGRAPH_CTX_SWITCH1_SWIZZLE 14:14 /* RWXUF */
1060#define NV_PGRAPH_CTX_SWITCH1_SWIZZLE_DISABLE 0x00000000 /* RW--V */
1061#define NV_PGRAPH_CTX_SWITCH1_SWIZZLE_ENABLE 0x00000001 /* RW--V */
1062#define NV_PGRAPH_CTX_SWITCH1_PATCH_CONFIG 17:15 /* RWXUF */
1063#define NV_PGRAPH_CTX_SWITCH1_PATCH_CONFIG_SRCCOPY_AND 0x00000000 /* RW--V */
1064#define NV_PGRAPH_CTX_SWITCH1_PATCH_CONFIG_ROP_AND 0x00000001 /* RW--V */
1065#define NV_PGRAPH_CTX_SWITCH1_PATCH_CONFIG_BLEND_AND 0x00000002 /* RW--V */
1066#define NV_PGRAPH_CTX_SWITCH1_PATCH_CONFIG_SRCCOPY 0x00000003 /* RW--V */
1067#define NV_PGRAPH_CTX_SWITCH1_PATCH_CONFIG_SRCCOPY_PRE 0x00000004 /* RW--V */
1068#define NV_PGRAPH_CTX_SWITCH1_PATCH_CONFIG_BLEND_PRE 0x00000005 /* RW--V */
1069#define NV_PGRAPH_CTX_SWITCH1_PATCH_STATUS 24:24 /* RWXUF */
1070#define NV_PGRAPH_CTX_SWITCH1_PATCH_STATUS_INVALID 0x00000000 /* RW--V */
1071#define NV_PGRAPH_CTX_SWITCH1_PATCH_STATUS_VALID 0x00000001 /* RW--V */
1072#define NV_PGRAPH_CTX_SWITCH1_CONTEXT_SURFACE 25:25 /* RWXUF */
1073#define NV_PGRAPH_CTX_SWITCH1_CONTEXT_SURFACE_INVALID 0x00000000 /* RW--V */
1074#define NV_PGRAPH_CTX_SWITCH1_CONTEXT_SURFACE_VALID 0x00000001 /* RW--V */
1075#define NV_PGRAPH_CTX_SWITCH1_VOLATILE_RESET 31:31 /* CWIVF */
1076#define NV_PGRAPH_CTX_SWITCH1_VOLATILE_RESET_IGNORE 0x00000000 /* CWI-V */
1077#define NV_PGRAPH_CTX_SWITCH1_VOLATILE_RESET_ENABLED 0x00000001 /* -W--T */
1078#define NV_PGRAPH_CTX_SWITCH2 0x00400164 /* RW-4R */
1079#define NV_PGRAPH_CTX_SWITCH2_MONO_FORMAT 1:0 /* RWXUF */
1080#define NV_PGRAPH_CTX_SWITCH2_MONO_FORMAT_INVALID 0x00 /* RW--V */
1081#define NV_PGRAPH_CTX_SWITCH2_MONO_FORMAT_CGA6_M1 0x01 /* RW--V */
1082#define NV_PGRAPH_CTX_SWITCH2_MONO_FORMAT_LE_M1 0x02 /* RW--V */
1083#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT 13:8 /* RWXUF */
1084#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_INVALID 0x00 /* RW--V */
1085#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_Y8 0x01 /* RW--V */
1086#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_X16A8Y8 0x02 /* RW--V */
1087#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_X24Y8 0x03 /* RW--V */
1088#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_A1R5G5B5 0x06 /* RW--V */
1089#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_X1R5G5B5 0x07 /* RW--V */
1090#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_X16A1R5G5B5 0x08 /* RW--V */
1091#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_X17R5G5B5 0x09 /* RW--V */
1092#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_R5G6B5 0x0A /* RW--V */
1093#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_A16R5G6B5 0x0B /* RW--V */
1094#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_X16R5G6B5 0x0C /* RW--V */
1095#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_A8R8G8B8 0x0D /* RW--V */
1096#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_X8R8G8B8 0x0E /* RW--V */
1097#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_Y16 0x0F /* RW--V */
1098#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_A16Y16 0x10 /* RW--V */
1099#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_X16Y16 0x11 /* RW--V */
1100#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_V8YB8U8YA8 0x12 /* RW--V */
1101#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_YB8V8YA8U8 0x13 /* RW--V */
1102#define NV_PGRAPH_CTX_SWITCH2_COLOR_FORMAT_LE_Y32 0x14 /* RW--V */
1103#define NV_PGRAPH_CTX_SWITCH2_NOTIFY_INSTANCE 31:16 /* RWXUF */
1104#define NV_PGRAPH_CTX_SWITCH2_NOTIFY_INSTANCE_INVALID 0x0000 /* RW--V */
1105#define NV_PGRAPH_CTX_SWITCH3 0x00400168 /* RW-4R */
1106#define NV_PGRAPH_CTX_SWITCH3_DMA_INSTANCE_0 15:0 /* RWXUF */
1107#define NV_PGRAPH_CTX_SWITCH3_DMA_INSTANCE_0_INVALID 0x0000 /* RW--V */
1108#define NV_PGRAPH_CTX_SWITCH3_DMA_INSTANCE_1 31:16 /* RWXUF */
1109#define NV_PGRAPH_CTX_SWITCH3_DMA_INSTANCE_1_INVALID 0x0000 /* RW--V */
1110#define NV_PGRAPH_CTX_SWITCH4 0x0040016C /* RW-4R */
1111#define NV_PGRAPH_CTX_SWITCH4_USER_INSTANCE 15:0 /* RWXUF */
1112#define NV_PGRAPH_CTX_SWITCH4_USER_INSTANCE_INVALID 0x0000 /* RW--V */
1113#define NV_PGRAPH_CTX_CACHE1(i) (0x00400180+(i)*4) /* RW-4A */
1114#define NV_PGRAPH_CTX_CACHE1__SIZE_1 8 /* */
1115#define NV_PGRAPH_CTX_CACHE1_GRCLASS 7:0 /* RWXVF */
1116#define NV_PGRAPH_CTX_CACHE1_CHROMA_KEY 12:12 /* RWXVF */
1117#define NV_PGRAPH_CTX_CACHE1_USER_CLIP 13:13 /* RWXVF */
1118#define NV_PGRAPH_CTX_CACHE1_SWIZZLE 14:14 /* RWXVF */
1119#define NV_PGRAPH_CTX_CACHE1_PATCH_CONFIG 19:15 /* RWXVF */
1120#define NV_PGRAPH_CTX_CACHE1_SPARE1 20:20 /* RWXVF */
1121#define NV_PGRAPH_CTX_CACHE1_PATCH_STATUS 24:24 /* RWXVF */
1122#define NV_PGRAPH_CTX_CACHE1_CONTEXT_SURFACE 25:25 /* RWXVF */
1123#define NV_PGRAPH_CTX_CACHE2(i) (0x004001a0+(i)*4) /* RW-4A */
1124#define NV_PGRAPH_CTX_CACHE2__SIZE_1 8 /* */
1125#define NV_PGRAPH_CTX_CACHE2_MONO_FORMAT 1:0 /* RWXVF */
1126#define NV_PGRAPH_CTX_CACHE2_COLOR_FORMAT 13:8 /* RWXVF */
1127#define NV_PGRAPH_CTX_CACHE2_NOTIFY_INSTANCE 31:16 /* RWXVF */
1128#define NV_PGRAPH_CTX_CACHE3(i) (0x004001c0+(i)*4) /* RW-4A */
1129#define NV_PGRAPH_CTX_CACHE3__SIZE_1 8 /* */
1130#define NV_PGRAPH_CTX_CACHE3_DMA_INSTANCE_0 15:0 /* RWXVF */
1131#define NV_PGRAPH_CTX_CACHE3_DMA_INSTANCE_1 31:16 /* RWXVF */
1132#define NV_PGRAPH_CTX_CACHE4(i) (0x004001e0+(i)*4) /* RW-4A */
1133#define NV_PGRAPH_CTX_CACHE4__SIZE_1 8 /* */
1134#define NV_PGRAPH_CTX_CACHE4_USER_INSTANCE 15:0 /* RWXVF */
1135#define NV_PGRAPH_CTX_CONTROL 0x00400170 /* RW-4R */
1136#define NV_PGRAPH_CTX_CONTROL_MINIMUM_TIME 1:0 /* RWIVF */
1137#define NV_PGRAPH_CTX_CONTROL_MINIMUM_TIME_33US 0x00000000 /* RWI-V */
1138#define NV_PGRAPH_CTX_CONTROL_MINIMUM_TIME_262US 0x00000001 /* RW--V */
1139#define NV_PGRAPH_CTX_CONTROL_MINIMUM_TIME_2MS 0x00000002 /* RW--V */
1140#define NV_PGRAPH_CTX_CONTROL_MINIMUM_TIME_17MS 0x00000003 /* RW--V */
1141#define NV_PGRAPH_CTX_CONTROL_TIME 8:8 /* RWIVF */
1142#define NV_PGRAPH_CTX_CONTROL_TIME_EXPIRED 0x00000000 /* RWI-V */
1143#define NV_PGRAPH_CTX_CONTROL_TIME_NOT_EXPIRED 0x00000001 /* RW--V */
1144#define NV_PGRAPH_CTX_CONTROL_CHID 16:16 /* RWIVF */
1145#define NV_PGRAPH_CTX_CONTROL_CHID_INVALID 0x00000000 /* RWI-V */
1146#define NV_PGRAPH_CTX_CONTROL_CHID_VALID 0x00000001 /* RW--V */
1147#define NV_PGRAPH_CTX_CONTROL_CHANGE 20:20 /* R--VF */
1148#define NV_PGRAPH_CTX_CONTROL_CHANGE_UNAVAILABLE 0x00000000 /* R---V */
1149#define NV_PGRAPH_CTX_CONTROL_CHANGE_AVAILABLE 0x00000001 /* R---V */
1150#define NV_PGRAPH_CTX_CONTROL_SWITCHING 24:24 /* RWIVF */
1151#define NV_PGRAPH_CTX_CONTROL_SWITCHING_IDLE 0x00000000 /* RWI-V */
1152#define NV_PGRAPH_CTX_CONTROL_SWITCHING_BUSY 0x00000001 /* RW--V */
1153#define NV_PGRAPH_CTX_CONTROL_DEVICE 28:28 /* RWIVF */
1154#define NV_PGRAPH_CTX_CONTROL_DEVICE_DISABLED 0x00000000 /* RWI-V */
1155#define NV_PGRAPH_CTX_CONTROL_DEVICE_ENABLED 0x00000001 /* RW--V */
1156#define NV_PGRAPH_CTX_USER 0x00400174 /* RW-4R */
1157#define NV_PGRAPH_CTX_USER_SUBCH 15:13 /* RWIVF */
1158#define NV_PGRAPH_CTX_USER_SUBCH_0 0x00000000 /* RWI-V */
1159#define NV_PGRAPH_CTX_USER_CHID 27:24 /* RWIVF */
1160#define NV_PGRAPH_CTX_USER_CHID_0 0x00000000 /* RWI-V */
1161#define NV_PGRAPH_FIFO 0x00400720 /* RW-4R */
1162#define NV_PGRAPH_FIFO_ACCESS 0:0 /* RWIVF */
1163#define NV_PGRAPH_FIFO_ACCESS_DISABLED 0x00000000 /* RW--V */
1164#define NV_PGRAPH_FIFO_ACCESS_ENABLED 0x00000001 /* RWI-V */
1165#define NV_PGRAPH_FFINTFC_FIFO_0(i) (0x00400730+(i)*4) /* RW-4A */
1166#define NV_PGRAPH_FFINTFC_FIFO_0__SIZE_1 4 /* */
1167#define NV_PGRAPH_FFINTFC_FIFO_0_TAG 0:0 /* RWXVF */
1168#define NV_PGRAPH_FFINTFC_FIFO_0_TAG_MTHD 0x00000000 /* RW--V */
1169#define NV_PGRAPH_FFINTFC_FIFO_0_TAG_CHSW 0x00000001 /* RW--V */
1170#define NV_PGRAPH_FFINTFC_FIFO_0_SUBCH 3:1 /* RWXVF */
1171#define NV_PGRAPH_FFINTFC_FIFO_0_SUBCH_0 0x00000000 /* RW--V */
1172#define NV_PGRAPH_FFINTFC_FIFO_0_SUBCH_1 0x00000001 /* RW--V */
1173#define NV_PGRAPH_FFINTFC_FIFO_0_SUBCH_2 0x00000002 /* RW--V */
1174#define NV_PGRAPH_FFINTFC_FIFO_0_SUBCH_3 0x00000003 /* RW--V */
1175#define NV_PGRAPH_FFINTFC_FIFO_0_SUBCH_4 0x00000004 /* RW--V */
1176#define NV_PGRAPH_FFINTFC_FIFO_0_SUBCH_5 0x00000005 /* RW--V */
1177#define NV_PGRAPH_FFINTFC_FIFO_0_SUBCH_6 0x00000006 /* RW--V */
1178#define NV_PGRAPH_FFINTFC_FIFO_0_SUBCH_7 0x00000007 /* RW--V */
1179#define NV_PGRAPH_FFINTFC_FIFO_0_MTHD 14:4 /* RWXVF */
1180#define NV_PGRAPH_FFINTFC_FIFO_0_MTHD_CTX_SWITCH 0x00000000 /* RW--V */
1181#define NV_PGRAPH_FFINTFC_FIFO_1(i) (0x00400740+(i)*4) /* RW-4A */
1182#define NV_PGRAPH_FFINTFC_FIFO_1__SIZE_1 4 /* */
1183#define NV_PGRAPH_FFINTFC_FIFO_1_ARGUMENT 31:0 /* RWXVF */
1184#define NV_PGRAPH_FFINTFC_FIFO_PTR 0x00400750 /* RW-4R */
1185#define NV_PGRAPH_FFINTFC_FIFO_PTR_WRITE 2:0 /* RWIVF */
1186#define NV_PGRAPH_FFINTFC_FIFO_PTR_WRITE_0 0x00000000 /* RWI-V */
1187#define NV_PGRAPH_FFINTFC_FIFO_PTR_READ 6:4 /* RWIVF */
1188#define NV_PGRAPH_FFINTFC_FIFO_PTR_READ_0 0x00000000 /* RWI-V */
1189#define NV_PGRAPH_FFINTFC_ST2 0x00400754 /* RW-4R */
1190#define NV_PGRAPH_FFINTFC_ST2_STATUS 0:0 /* RWIVF */
1191#define NV_PGRAPH_FFINTFC_ST2_STATUS_INVALID 0x00000000 /* RWI-V */
1192#define NV_PGRAPH_FFINTFC_ST2_STATUS_VALID 0x00000001 /* RW--V */
1193#define NV_PGRAPH_FFINTFC_ST2_MTHD 11:1 /* RWIVF */
1194#define NV_PGRAPH_FFINTFC_ST2_MTHD_CTX_SWITCH 0x00000000 /* RWI-V */
1195#define NV_PGRAPH_FFINTFC_ST2_SUBCH 14:12 /* RWIVF */
1196#define NV_PGRAPH_FFINTFC_ST2_SUBCH_0 0x00000000 /* RWI-V */
1197#define NV_PGRAPH_FFINTFC_ST2_SUBCH_1 0x00000001 /* RW--V */
1198#define NV_PGRAPH_FFINTFC_ST2_SUBCH_2 0x00000002 /* RW--V */
1199#define NV_PGRAPH_FFINTFC_ST2_SUBCH_3 0x00000003 /* RW--V */
1200#define NV_PGRAPH_FFINTFC_ST2_SUBCH_4 0x00000004 /* RW--V */
1201#define NV_PGRAPH_FFINTFC_ST2_SUBCH_5 0x00000005 /* RW--V */
1202#define NV_PGRAPH_FFINTFC_ST2_SUBCH_6 0x00000006 /* RW--V */
1203#define NV_PGRAPH_FFINTFC_ST2_SUBCH_7 0x00000007 /* RW--V */
1204#define NV_PGRAPH_FFINTFC_ST2_CHID 18:15 /* RWIVF */
1205#define NV_PGRAPH_FFINTFC_ST2_CHID_0 0x00000000 /* RWI-V */
1206#define NV_PGRAPH_FFINTFC_ST2_CHID_1 0x00000001 /* RW--V */
1207#define NV_PGRAPH_FFINTFC_ST2_CHID_2 0x00000002 /* RW--V */
1208#define NV_PGRAPH_FFINTFC_ST2_CHID_3 0x00000003 /* RW--V */
1209#define NV_PGRAPH_FFINTFC_ST2_CHID_4 0x00000004 /* RW--V */
1210#define NV_PGRAPH_FFINTFC_ST2_CHID_5 0x00000005 /* RW--V */
1211#define NV_PGRAPH_FFINTFC_ST2_CHID_6 0x00000006 /* RW--V */
1212#define NV_PGRAPH_FFINTFC_ST2_CHID_7 0x00000007 /* RW--V */
1213#define NV_PGRAPH_FFINTFC_ST2_CHID_8 0x00000008 /* RW--V */
1214#define NV_PGRAPH_FFINTFC_ST2_CHID_9 0x00000009 /* RW--V */
1215#define NV_PGRAPH_FFINTFC_ST2_CHID_10 0x0000000A /* RW--V */
1216#define NV_PGRAPH_FFINTFC_ST2_CHID_11 0x0000000B /* RW--V */
1217#define NV_PGRAPH_FFINTFC_ST2_CHID_12 0x0000000C /* RW--V */
1218#define NV_PGRAPH_FFINTFC_ST2_CHID_13 0x0000000D /* RW--V */
1219#define NV_PGRAPH_FFINTFC_ST2_CHID_14 0x0000000E /* RW--V */
1220#define NV_PGRAPH_FFINTFC_ST2_CHID_15 0x0000000F /* RW--V */
1221#define NV_PGRAPH_FFINTFC_ST2_CHID_STATUS 19:19 /* RWIVF */
1222#define NV_PGRAPH_FFINTFC_ST2_CHID_STATUS_INVALID 0x00000000 /* RWI-V */
1223#define NV_PGRAPH_FFINTFC_ST2_CHID_STATUS_VALID 0x00000001 /* RW--V */
1224#define NV_PGRAPH_FFINTFC_ST2_D 0x00400758 /* RW-4R */
1225#define NV_PGRAPH_FFINTFC_ST2_D_ARGUMENT 31:0 /* RWIVF */
1226#define NV_PGRAPH_FFINTFC_ST2_D_ARGUMENT_0 0x00000000 /* RWI-V */
1227#define NV_PGRAPH_STATUS 0x00400700 /* R--4R */
1228#define NV_PGRAPH_STATUS_STATE 0:0 /* R-IVF */
1229#define NV_PGRAPH_STATUS_STATE_IDLE 0x00000000 /* R-I-V */
1230#define NV_PGRAPH_STATUS_STATE_BUSY 0x00000001 /* R---V */
1231#define NV_PGRAPH_STATUS_XY_LOGIC 4:4 /* R-IVF */
1232#define NV_PGRAPH_STATUS_XY_LOGIC_IDLE 0x00000000 /* R-I-V */
1233#define NV_PGRAPH_STATUS_XY_LOGIC_BUSY 0x00000001 /* R---V */
1234#define NV_PGRAPH_STATUS_FE 5:5 /* R-IVF */
1235#define NV_PGRAPH_STATUS_FE_IDLE 0x00000000 /* R-I-V */
1236#define NV_PGRAPH_STATUS_FE_BUSY 0x00000001 /* R---V */
1237#define NV_PGRAPH_STATUS_RASTERIZER 6:6 /* R-IVF */
1238#define NV_PGRAPH_STATUS_RASTERIZER_IDLE 0x00000000 /* R-I-V */
1239#define NV_PGRAPH_STATUS_RASTERIZER_BUSY 0x00000001 /* R---V */
1240#define NV_PGRAPH_STATUS_PORT_NOTIFY 8:8 /* R-IVF */
1241#define NV_PGRAPH_STATUS_PORT_NOTIFY_IDLE 0x00000000 /* R-I-V */
1242#define NV_PGRAPH_STATUS_PORT_NOTIFY_BUSY 0x00000001 /* R---V */
1243#define NV_PGRAPH_STATUS_PORT_REGISTER 12:12 /* R-IVF */
1244#define NV_PGRAPH_STATUS_PORT_REGISTER_IDLE 0x00000000 /* R-I-V */
1245#define NV_PGRAPH_STATUS_PORT_REGISTER_BUSY 0x00000001 /* R---V */
1246#define NV_PGRAPH_STATUS_PORT_DMA 16:16 /* R-IVF */
1247#define NV_PGRAPH_STATUS_PORT_DMA_IDLE 0x00000000 /* R-I-V */
1248#define NV_PGRAPH_STATUS_PORT_DMA_BUSY 0x00000001 /* R---V */
1249#define NV_PGRAPH_STATUS_DMA_ENGINE 17:17 /* R-IVF */
1250#define NV_PGRAPH_STATUS_DMA_ENGINE_IDLE 0x00000000 /* R-I-V */
1251#define NV_PGRAPH_STATUS_DMA_ENGINE_BUSY 0x00000001 /* R---V */
1252#define NV_PGRAPH_STATUS_DMA_NOTIFY 20:20 /* R-IVF */
1253#define NV_PGRAPH_STATUS_DMA_NOTIFY_IDLE 0x00000000 /* R-I-V */
1254#define NV_PGRAPH_STATUS_DMA_NOTIFY_BUSY 0x00000001 /* R---V */
1255#define NV_PGRAPH_STATUS_DMA_BUFFER_NOTIFY 21:21 /* R-IVF */
1256#define NV_PGRAPH_STATUS_DMA_BUFFER_NOTIFY_IDLE 0x00000000 /* R-I-V */
1257#define NV_PGRAPH_STATUS_DMA_BUFFER_NOTIFY_BUSY 0x00000001 /* R---V */
1258#define NV_PGRAPH_STATUS_D3D 24:24 /* R-IVF */
1259#define NV_PGRAPH_STATUS_D3D_IDLE 0x00000000 /* R-I-V */
1260#define NV_PGRAPH_STATUS_D3D_BUSY 0x00000001 /* R---V */
1261#define NV_PGRAPH_STATUS_CACHE 25:25 /* R-IVF */
1262#define NV_PGRAPH_STATUS_CACHE_IDLE 0x00000000 /* R-I-V */
1263#define NV_PGRAPH_STATUS_CACHE_BUSY 0x00000001 /* R---V */
1264#define NV_PGRAPH_STATUS_LIGHTING 26:26 /* R-IVF */
1265#define NV_PGRAPH_STATUS_LIGHTING_IDLE 0x00000000 /* R-I-V */
1266#define NV_PGRAPH_STATUS_LIGHTING_BUSY 0x00000001 /* R---V */
1267#define NV_PGRAPH_STATUS_PREROP 27:27 /* R-IVF */
1268#define NV_PGRAPH_STATUS_PREROP_IDLE 0x00000000 /* R-I-V */
1269#define NV_PGRAPH_STATUS_PREROP_BUSY 0x00000001 /* R---V */
1270#define NV_PGRAPH_STATUS_ROP 28:28 /* R-IVF */
1271#define NV_PGRAPH_STATUS_ROP_IDLE 0x00000000 /* R-I-V */
1272#define NV_PGRAPH_STATUS_ROP_BUSY 0x00000001 /* R---V */
1273#define NV_PGRAPH_STATUS_PORT_USER 29:29 /* R-IVF */
1274#define NV_PGRAPH_STATUS_PORT_USER_IDLE 0x00000000 /* R-I-V */
1275#define NV_PGRAPH_STATUS_PORT_USER_BUSY 0x00000001 /* R---V */
1276#define NV_PGRAPH_TRAPPED_ADDR 0x00400704 /* R--4R */
1277#define NV_PGRAPH_TRAPPED_ADDR_MTHD 12:2 /* R-XUF */
1278#define NV_PGRAPH_TRAPPED_ADDR_SUBCH 15:13 /* R-XUF */
1279#define NV_PGRAPH_TRAPPED_ADDR_CHID 27:24 /* R-XUF */
1280#define NV_PGRAPH_TRAPPED_DATA 0x00400708 /* R--4R */
1281#define NV_PGRAPH_TRAPPED_DATA_VALUE 31:0 /* R-XVF */
1282#define NV_PGRAPH_SURFACE 0x0040070C /* RW-4R */
1283#define NV_PGRAPH_SURFACE_TYPE 1:0 /* RWIVF */
1284#define NV_PGRAPH_SURFACE_TYPE_INVALID 0x00000000 /* RWI-V */
1285#define NV_PGRAPH_SURFACE_TYPE_NON_SWIZZLE 0x00000001 /* RW--V */
1286#define NV_PGRAPH_SURFACE_TYPE_SWIZZLE 0x00000002 /* RW--V */
1287#define NV_PGRAPH_NOTIFY 0x00400714 /* RW-4R */
1288#define NV_PGRAPH_NOTIFY_BUFFER_REQ 0:0 /* RWIVF */
1289#define NV_PGRAPH_NOTIFY_BUFFER_REQ_NOT_PENDING 0x00000000 /* RWI-V */
1290#define NV_PGRAPH_NOTIFY_BUFFER_REQ_PENDING 0x00000001 /* RW--V */
1291#define NV_PGRAPH_NOTIFY_BUFFER_STYLE 8:8 /* RWIVF */
1292#define NV_PGRAPH_NOTIFY_BUFFER_STYLE_WRITE_ONLY 0x00000000 /* RWI-V */
1293#define NV_PGRAPH_NOTIFY_BUFFER_STYLE_WRITE_THEN_AWAKEN 0x00000001 /* RW--V */
1294#define NV_PGRAPH_NOTIFY_REQ 16:16 /* RWIVF */
1295#define NV_PGRAPH_NOTIFY_REQ_NOT_PENDING 0x00000000 /* RWI-V */
1296#define NV_PGRAPH_NOTIFY_REQ_PENDING 0x00000001 /* RW--V */
1297#define NV_PGRAPH_NOTIFY_STYLE 20:20 /* RWIVF */
1298#define NV_PGRAPH_NOTIFY_STYLE_WRITE_ONLY 0x00000000 /* RWI-V */
1299#define NV_PGRAPH_NOTIFY_STYLE_WRITE_THEN_AWAKEN 0x00000001 /* RW--V */
1300#define NV_PGRAPH_BOFFSET(i) (0x00400640+(i)*4) /* RW-4A */
1301#define NV_PGRAPH_BOFFSET__SIZE_1 6 /* */
1302#define NV_PGRAPH_BOFFSET_LINADRS 23:0 /* RWIUF */
1303#define NV_PGRAPH_BOFFSET_LINADRS_0 0x00000000 /* RWI-V */
1304#define NV_PGRAPH_BOFFSET0 0x00400640 /* RW-4R */
1305#define NV_PGRAPH_BOFFSET0__ALIAS_1 NV_PGRAPH_BOFFSET(0) /* */
1306#define NV_PGRAPH_BOFFSET0_LINADRS 23:0 /* RWIUF */
1307#define NV_PGRAPH_BOFFSET0_LINADRS_0 0x00000000 /* RWI-V */
1308#define NV_PGRAPH_BOFFSET1 0x00400644 /* RW-4R */
1309#define NV_PGRAPH_BOFFSET1__ALIAS_1 NV_PGRAPH_BOFFSET(1) /* */
1310#define NV_PGRAPH_BOFFSET1_LINADRS 23:0 /* RWIUF */
1311#define NV_PGRAPH_BOFFSET1_LINADRS_0 0x00000000 /* RWI-V */
1312#define NV_PGRAPH_BOFFSET2 0x00400648 /* RW-4R */
1313#define NV_PGRAPH_BOFFSET2__ALIAS_1 NV_PGRAPH_BOFFSET(2) /* */
1314#define NV_PGRAPH_BOFFSET2_LINADRS 23:0 /* RWIUF */
1315#define NV_PGRAPH_BOFFSET2_LINADRS_0 0x00000000 /* RWI-V */
1316#define NV_PGRAPH_BOFFSET3 0x0040064C /* RW-4R */
1317#define NV_PGRAPH_BOFFSET3__ALIAS_1 NV_PGRAPH_BOFFSET(3) /* */
1318#define NV_PGRAPH_BOFFSET3_LINADRS 23:0 /* RWIUF */
1319#define NV_PGRAPH_BOFFSET3_LINADRS_0 0x00000000 /* RWI-V */
1320#define NV_PGRAPH_BOFFSET4 0x00400650 /* RW-4R */
1321#define NV_PGRAPH_BOFFSET4__ALIAS_1 NV_PGRAPH_BOFFSET(4) /* */
1322#define NV_PGRAPH_BOFFSET4_LINADRS 23:0 /* RWIUF */
1323#define NV_PGRAPH_BOFFSET4_LINADRS_0 0x00000000 /* RWI-V */
1324#define NV_PGRAPH_BOFFSET5 0x00400654 /* RW-4R */
1325#define NV_PGRAPH_BOFFSET5__ALIAS_1 NV_PGRAPH_BOFFSET(5) /* */
1326#define NV_PGRAPH_BOFFSET5_LINADRS 23:0 /* RWIUF */
1327#define NV_PGRAPH_BOFFSET5_LINADRS_0 0x00000000 /* RWI-V */
1328#define NV_PGRAPH_BBASE(i) (0x00400658+(i)*4) /* RW-4A */
1329#define NV_PGRAPH_BBASE__SIZE_1 6 /* */
1330#define NV_PGRAPH_BBASE_LINADRS 23:0 /* RWIUF */
1331#define NV_PGRAPH_BBASE_LINADRS_0 0x00000000 /* RWI-V */
1332#define NV_PGRAPH_BBASE0 0x00400658 /* RW-4R */
1333#define NV_PGRAPH_BBASE0__ALIAS_1 NV_PGRAPH_BBASE(0) /* */
1334#define NV_PGRAPH_BBASE0_LINADRS 23:0 /* RWIUF */
1335#define NV_PGRAPH_BBASE0_LINADRS_0 0x00000000 /* RWI-V */
1336#define NV_PGRAPH_BBASE1 0x0040065c /* RW-4R */
1337#define NV_PGRAPH_BBASE1__ALIAS_1 NV_PGRAPH_BBASE(1) /* */
1338#define NV_PGRAPH_BBASE1_LINADRS 23:0 /* RWIUF */
1339#define NV_PGRAPH_BBASE1_LINADRS_0 0x00000000 /* RWI-V */
1340#define NV_PGRAPH_BBASE2 0x00400660 /* RW-4R */
1341#define NV_PGRAPH_BBASE2__ALIAS_1 NV_PGRAPH_BBASE(2) /* */
1342#define NV_PGRAPH_BBASE2_LINADRS 23:0 /* RWIUF */
1343#define NV_PGRAPH_BBASE2_LINADRS_0 0x00000000 /* RWI-V */
1344#define NV_PGRAPH_BBASE3 0x00400664 /* RW-4R */
1345#define NV_PGRAPH_BBASE3__ALIAS_1 NV_PGRAPH_BBASE(3) /* */
1346#define NV_PGRAPH_BBASE3_LINADRS 23:0 /* RWIUF */
1347#define NV_PGRAPH_BBASE3_LINADRS_0 0x00000000 /* RWI-V */
1348#define NV_PGRAPH_BBASE4 0x00400668 /* RW-4R */
1349#define NV_PGRAPH_BBASE4__ALIAS_1 NV_PGRAPH_BBASE(4) /* */
1350#define NV_PGRAPH_BBASE4_LINADRS 23:0 /* RWIUF */
1351#define NV_PGRAPH_BBASE4_LINADRS_0 0x00000000 /* RWI-V */
1352#define NV_PGRAPH_BBASE5 0x0040066C /* RW-4R */
1353#define NV_PGRAPH_BBASE5__ALIAS_1 NV_PGRAPH_BBASE(5) /* */
1354#define NV_PGRAPH_BBASE5_LINADRS 23:0 /* RWIUF */
1355#define NV_PGRAPH_BBASE5_LINADRS_0 0x00000000 /* RWI-V */
1356#define NV_PGRAPH_BPITCH(i) (0x00400670+(i)*4) /* RW-4A */
1357#define NV_PGRAPH_BPITCH__SIZE_1 5 /* */
1358#define NV_PGRAPH_BPITCH_VALUE 12:0 /* RWIUF */
1359#define NV_PGRAPH_BPITCH_VALUE_0 0x00000000 /* RWI-V */
1360#define NV_PGRAPH_BPITCH0 0x00400670 /* RW-4R */
1361#define NV_PGRAPH_BPITCH0__ALIAS_1 NV_PGRAPH_BPITCH(0) /* */
1362#define NV_PGRAPH_BPITCH0_VALUE 12:0 /* RWIUF */
1363#define NV_PGRAPH_BPITCH0_VALUE_0 0x00000000 /* RWI-V */
1364#define NV_PGRAPH_BPITCH1 0x00400674 /* RW-4R */
1365#define NV_PGRAPH_BPITCH1__ALIAS_1 NV_PGRAPH_BPITCH(1) /* */
1366#define NV_PGRAPH_BPITCH1_VALUE 12:0 /* RWIUF */
1367#define NV_PGRAPH_BPITCH1_VALUE_0 0x00000000 /* RWI-V */
1368#define NV_PGRAPH_BPITCH2 0x00400678 /* RW-4R */
1369#define NV_PGRAPH_BPITCH2__ALIAS_1 NV_PGRAPH_BPITCH(2) /* */
1370#define NV_PGRAPH_BPITCH2_VALUE 12:0 /* RWIUF */
1371#define NV_PGRAPH_BPITCH2_VALUE_0 0x00000000 /* RWI-V */
1372#define NV_PGRAPH_BPITCH3 0x0040067C /* RW-4R */
1373#define NV_PGRAPH_BPITCH3__ALIAS_1 NV_PGRAPH_BPITCH(3) /* */
1374#define NV_PGRAPH_BPITCH3_VALUE 12:0 /* RWIUF */
1375#define NV_PGRAPH_BPITCH3_VALUE_0 0x00000000 /* RWI-V */
1376#define NV_PGRAPH_BPITCH4 0x00400680 /* RW-4R */
1377#define NV_PGRAPH_BPITCH4__ALIAS_1 NV_PGRAPH_BPITCH(4) /* */
1378#define NV_PGRAPH_BPITCH4_VALUE 12:0 /* RWIUF */
1379#define NV_PGRAPH_BPITCH4_VALUE_0 0x00000000 /* RWI-V */
1380#define NV_PGRAPH_BLIMIT(i) (0x00400684+(i)*4) /* RW-4A */
1381#define NV_PGRAPH_BLIMIT__SIZE_1 6 /* */
1382#define NV_PGRAPH_BLIMIT_VALUE 23:0 /* RWXUF */
1383#define NV_PGRAPH_BLIMIT_TYPE 31:31 /* RWIVF */
1384#define NV_PGRAPH_BLIMIT_TYPE_IN_MEMORY 0x00000000 /* RW--V */
1385#define NV_PGRAPH_BLIMIT_TYPE_NULL 0x00000001 /* RWI-V */
1386#define NV_PGRAPH_BLIMIT0 0x00400684 /* RW-4R */
1387#define NV_PGRAPH_BLIMIT0__ALIAS_1 NV_PGRAPH_BLIMIT(0) /* */
1388#define NV_PGRAPH_BLIMIT0_VALUE 23:0 /* RWXUF */
1389#define NV_PGRAPH_BLIMIT0_TYPE 31:31 /* RWIVF */
1390#define NV_PGRAPH_BLIMIT0_TYPE_IN_MEMORY 0x00000000 /* RW--V */
1391#define NV_PGRAPH_BLIMIT0_TYPE_NULL 0x00000001 /* RWI-V */
1392#define NV_PGRAPH_BLIMIT1 0x00400688 /* RW-4R */
1393#define NV_PGRAPH_BLIMIT1__ALIAS_1 NV_PGRAPH_BLIMIT(1) /* */
1394#define NV_PGRAPH_BLIMIT1_VALUE 23:0 /* RWXUF */
1395#define NV_PGRAPH_BLIMIT1_TYPE 31:31 /* RWIVF */
1396#define NV_PGRAPH_BLIMIT1_TYPE_IN_MEMORY 0x00000000 /* RW--V */
1397#define NV_PGRAPH_BLIMIT1_TYPE_NULL 0x00000001 /* RWI-V */
1398#define NV_PGRAPH_BLIMIT2 0x0040068c /* RW-4R */
1399#define NV_PGRAPH_BLIMIT2__ALIAS_1 NV_PGRAPH_BLIMIT(2) /* */
1400#define NV_PGRAPH_BLIMIT2_VALUE 23:0 /* RWXUF */
1401#define NV_PGRAPH_BLIMIT2_TYPE 31:31 /* RWIVF */
1402#define NV_PGRAPH_BLIMIT2_TYPE_IN_MEMORY 0x00000000 /* RW--V */
1403#define NV_PGRAPH_BLIMIT2_TYPE_NULL 0x00000001 /* RWI-V */
1404#define NV_PGRAPH_BLIMIT3 0x00400690 /* RW-4R */
1405#define NV_PGRAPH_BLIMIT3__ALIAS_1 NV_PGRAPH_BLIMIT(3) /* */
1406#define NV_PGRAPH_BLIMIT3_VALUE 23:0 /* RWXUF */
1407#define NV_PGRAPH_BLIMIT3_TYPE 31:31 /* RWIVF */
1408#define NV_PGRAPH_BLIMIT3_TYPE_IN_MEMORY 0x00000000 /* RW--V */
1409#define NV_PGRAPH_BLIMIT3_TYPE_NULL 0x00000001 /* RWI-V */
1410#define NV_PGRAPH_BLIMIT4 0x00400694 /* RW-4R */
1411#define NV_PGRAPH_BLIMIT4__ALIAS_1 NV_PGRAPH_BLIMIT(4) /* */
1412#define NV_PGRAPH_BLIMIT4_VALUE 23:0 /* RWXUF */
1413#define NV_PGRAPH_BLIMIT4_TYPE 31:31 /* RWIVF */
1414#define NV_PGRAPH_BLIMIT4_TYPE_IN_MEMORY 0x00000000 /* RW--V */
1415#define NV_PGRAPH_BLIMIT4_TYPE_NULL 0x00000001 /* RWI-V */
1416#define NV_PGRAPH_BLIMIT5 0x00400698 /* RW-4R */
1417#define NV_PGRAPH_BLIMIT5__ALIAS_1 NV_PGRAPH_BLIMIT(5) /* */
1418#define NV_PGRAPH_BLIMIT5_VALUE 23:0 /* RWXUF */
1419#define NV_PGRAPH_BLIMIT5_TYPE 31:31 /* RWIVF */
1420#define NV_PGRAPH_BLIMIT5_TYPE_IN_MEMORY 0x00000000 /* RW--V */
1421#define NV_PGRAPH_BLIMIT5_TYPE_NULL 0x00000001 /* RWI-V */
1422#define NV_PGRAPH_BSWIZZLE2 0x0040069c /* RW-4R */
1423#define NV_PGRAPH_BSWIZZLE2_WIDTH 19:16 /* RWIUF */
1424#define NV_PGRAPH_BSWIZZLE2_WIDTH_0 0x00000000 /* RWI-V */
1425#define NV_PGRAPH_BSWIZZLE2_HEIGHT 27:24 /* RWIUF */
1426#define NV_PGRAPH_BSWIZZLE2_HEIGHT_0 0x00000000 /* RWI-V */
1427#define NV_PGRAPH_BSWIZZLE5 0x004006a0 /* RW-4R */
1428#define NV_PGRAPH_BSWIZZLE5_WIDTH 19:16 /* RWIUF */
1429#define NV_PGRAPH_BSWIZZLE5_WIDTH_0 0x00000000 /* RWI-V */
1430#define NV_PGRAPH_BSWIZZLE5_HEIGHT 27:24 /* RWIUF */
1431#define NV_PGRAPH_BSWIZZLE5_HEIGHT_0 0x00000000 /* RWI-V */
1432#define NV_PGRAPH_BPIXEL 0x00400724 /* RW-4R */
1433#define NV_PGRAPH_BPIXEL_DEPTH0 3:0 /* RWIVF */
1434#define NV_PGRAPH_BPIXEL_DEPTH0_INVALID 0x00000000 /* RWI-V */
1435#define NV_PGRAPH_BPIXEL_DEPTH0_Y8 0x00000001 /* RW--V */
1436#define NV_PGRAPH_BPIXEL_DEPTH0_X1R5G5B5_Z1R5G5B5 0x00000002 /* RW--V */
1437#define NV_PGRAPH_BPIXEL_DEPTH0_X1R5G5B5_O1R5G5B5 0x00000003 /* RW--V */
1438#define NV_PGRAPH_BPIXEL_DEPTH0_A1R5G5B5 0x00000004 /* RW--V */
1439#define NV_PGRAPH_BPIXEL_DEPTH0_R5G6B5 0x00000005 /* RW--V */
1440#define NV_PGRAPH_BPIXEL_DEPTH0_Y16 0x00000006 /* RW--V */
1441#define NV_PGRAPH_BPIXEL_DEPTH0_X8R8G8B8_Z8R8G8B8 0x00000007 /* RW--V */
1442#define NV_PGRAPH_BPIXEL_DEPTH0_X8R8G8B8_O1Z7R8G8B8 0x00000008 /* RW--V */
1443#define NV_PGRAPH_BPIXEL_DEPTH0_X1A7R8G8B8_Z1A7R8G8B8 0x00000009 /* RW--V */
1444#define NV_PGRAPH_BPIXEL_DEPTH0_X1A7R8G8B8_O1A7R8G8B8 0x0000000a /* RW--V */
1445#define NV_PGRAPH_BPIXEL_DEPTH0_X8R8G8B8_O8R8G8B8 0x0000000b /* RW--V */
1446#define NV_PGRAPH_BPIXEL_DEPTH0_A8R8G8B8 0x0000000c /* RW--V */
1447#define NV_PGRAPH_BPIXEL_DEPTH0_Y32 0x0000000d /* RW--V */
1448#define NV_PGRAPH_BPIXEL_DEPTH0_V8YB8U8YA8 0x0000000e /* RW--V */
1449#define NV_PGRAPH_BPIXEL_DEPTH0_YB8V8YA8U8 0x0000000f /* RW--V */
1450#define NV_PGRAPH_BPIXEL_DEPTH1 7:4 /* RWIVF */
1451#define NV_PGRAPH_BPIXEL_DEPTH1_INVALID 0x00000000 /* RWI-V */
1452#define NV_PGRAPH_BPIXEL_DEPTH1_Y8 0x00000001 /* RW--V */
1453#define NV_PGRAPH_BPIXEL_DEPTH1_X1R5G5B5_Z1R5G5B5 0x00000002 /* RW--V */
1454#define NV_PGRAPH_BPIXEL_DEPTH1_X1R5G5B5_O1R5G5B5 0x00000003 /* RW--V */
1455#define NV_PGRAPH_BPIXEL_DEPTH1_A1R5G5B5 0x00000004 /* RW--V */
1456#define NV_PGRAPH_BPIXEL_DEPTH1_R5G6B5 0x00000005 /* RW--V */
1457#define NV_PGRAPH_BPIXEL_DEPTH1_Y16 0x00000006 /* RW--V */
1458#define NV_PGRAPH_BPIXEL_DEPTH1_X8R8G8B8_Z8R8G8B8 0x00000007 /* RW--V */
1459#define NV_PGRAPH_BPIXEL_DEPTH1_X8R8G8B8_O1Z7R8G8B8 0x00000008 /* RW--V */
1460#define NV_PGRAPH_BPIXEL_DEPTH1_X1A7R8G8B8_Z1A7R8G8B8 0x00000009 /* RW--V */
1461#define NV_PGRAPH_BPIXEL_DEPTH1_X1A7R8G8B8_O1A7R8G8B8 0x0000000a /* RW--V */
1462#define NV_PGRAPH_BPIXEL_DEPTH1_X8R8G8B8_O8R8G8B8 0x0000000b /* RW--V */
1463#define NV_PGRAPH_BPIXEL_DEPTH1_A8R8G8B8 0x0000000c /* RW--V */
1464#define NV_PGRAPH_BPIXEL_DEPTH1_Y32 0x0000000d /* RW--V */
1465#define NV_PGRAPH_BPIXEL_DEPTH1_V8YB8U8YA8 0x0000000e /* RW--V */
1466#define NV_PGRAPH_BPIXEL_DEPTH1_YB8V8YA8U8 0x0000000f /* RW--V */
1467#define NV_PGRAPH_BPIXEL_DEPTH2 11:8 /* RWIVF */
1468#define NV_PGRAPH_BPIXEL_DEPTH2_INVALID 0x00000000 /* RWI-V */
1469#define NV_PGRAPH_BPIXEL_DEPTH2_Y8 0x00000001 /* RW--V */
1470#define NV_PGRAPH_BPIXEL_DEPTH2_X1R5G5B5_Z1R5G5B5 0x00000002 /* RW--V */
1471#define NV_PGRAPH_BPIXEL_DEPTH2_X1R5G5B5_O1R5G5B5 0x00000003 /* RW--V */
1472#define NV_PGRAPH_BPIXEL_DEPTH2_A1R5G5B5 0x00000004 /* RW--V */
1473#define NV_PGRAPH_BPIXEL_DEPTH2_R5G6B5 0x00000005 /* RW--V */
1474#define NV_PGRAPH_BPIXEL_DEPTH2_Y16 0x00000006 /* RW--V */
1475#define NV_PGRAPH_BPIXEL_DEPTH2_X8R8G8B8_Z8R8G8B8 0x00000007 /* RW--V */
1476#define NV_PGRAPH_BPIXEL_DEPTH2_X8R8G8B8_O1Z7R8G8B8 0x00000008 /* RW--V */
1477#define NV_PGRAPH_BPIXEL_DEPTH2_X1A7R8G8B8_Z1A7R8G8B8 0x00000009 /* RW--V */
1478#define NV_PGRAPH_BPIXEL_DEPTH2_X1A7R8G8B8_O1A7R8G8B8 0x0000000a /* RW--V */
1479#define NV_PGRAPH_BPIXEL_DEPTH2_X8R8G8B8_O8R8G8B8 0x0000000b /* RW--V */
1480#define NV_PGRAPH_BPIXEL_DEPTH2_A8R8G8B8 0x0000000c /* RW--V */
1481#define NV_PGRAPH_BPIXEL_DEPTH2_Y32 0x0000000d /* RW--V */
1482#define NV_PGRAPH_BPIXEL_DEPTH2_V8YB8U8YA8 0x0000000e /* RW--V */
1483#define NV_PGRAPH_BPIXEL_DEPTH2_YB8V8YA8U8 0x0000000f /* RW--V */
1484#define NV_PGRAPH_BPIXEL_DEPTH3 15:12 /* RWIVF */
1485#define NV_PGRAPH_BPIXEL_DEPTH3_INVALID 0x00000000 /* RWI-V */
1486#define NV_PGRAPH_BPIXEL_DEPTH3_Y8 0x00000001 /* RW--V */
1487#define NV_PGRAPH_BPIXEL_DEPTH3_X1R5G5B5_Z1R5G5B5 0x00000002 /* RW--V */
1488#define NV_PGRAPH_BPIXEL_DEPTH3_X1R5G5B5_O1R5G5B5 0x00000003 /* RW--V */
1489#define NV_PGRAPH_BPIXEL_DEPTH3_A1R5G5B5 0x00000004 /* RW--V */
1490#define NV_PGRAPH_BPIXEL_DEPTH3_R5G6B5 0x00000005 /* RW--V */
1491#define NV_PGRAPH_BPIXEL_DEPTH3_Y16 0x00000006 /* RW--V */
1492#define NV_PGRAPH_BPIXEL_DEPTH3_X8R8G8B8_Z8R8G8B8 0x00000007 /* RW--V */
1493#define NV_PGRAPH_BPIXEL_DEPTH3_X8R8G8B8_O1Z7R8G8B8 0x00000008 /* RW--V */
1494#define NV_PGRAPH_BPIXEL_DEPTH3_X1A7R8G8B8_Z1A7R8G8B8 0x00000009 /* RW--V */
1495#define NV_PGRAPH_BPIXEL_DEPTH3_X1A7R8G8B8_O1A7R8G8B8 0x0000000a /* RW--V */
1496#define NV_PGRAPH_BPIXEL_DEPTH3_X8R8G8B8_O8R8G8B8 0x0000000b /* RW--V */
1497#define NV_PGRAPH_BPIXEL_DEPTH3_A8R8G8B8 0x0000000c /* RW--V */
1498#define NV_PGRAPH_BPIXEL_DEPTH3_Y32 0x0000000d /* RW--V */
1499#define NV_PGRAPH_BPIXEL_DEPTH3_V8YB8U8YA8 0x0000000e /* RW--V */
1500#define NV_PGRAPH_BPIXEL_DEPTH3_YB8V8YA8U8 0x0000000f /* RW--V */
1501#define NV_PGRAPH_BPIXEL_DEPTH4 19:16 /* RWIVF */
1502#define NV_PGRAPH_BPIXEL_DEPTH4_INVALID 0x00000000 /* RWI-V */
1503#define NV_PGRAPH_BPIXEL_DEPTH4_Y8 0x00000001 /* RW--V */
1504#define NV_PGRAPH_BPIXEL_DEPTH4_X1R5G5B5_Z1R5G5B5 0x00000002 /* RW--V */
1505#define NV_PGRAPH_BPIXEL_DEPTH4_X1R5G5B5_O1R5G5B5 0x00000003 /* RW--V */
1506#define NV_PGRAPH_BPIXEL_DEPTH4_A1R5G5B5 0x00000004 /* RW--V */
1507#define NV_PGRAPH_BPIXEL_DEPTH4_R5G6B5 0x00000005 /* RW--V */
1508#define NV_PGRAPH_BPIXEL_DEPTH4_Y16 0x00000006 /* RW--V */
1509#define NV_PGRAPH_BPIXEL_DEPTH4_X8R8G8B8_Z8R8G8B8 0x00000007 /* RW--V */
1510#define NV_PGRAPH_BPIXEL_DEPTH4_X8R8G8B8_O1Z7R8G8B8 0x00000008 /* RW--V */
1511#define NV_PGRAPH_BPIXEL_DEPTH4_X1A7R8G8B8_Z1A7R8G8B8 0x00000009 /* RW--V */
1512#define NV_PGRAPH_BPIXEL_DEPTH4_X1A7R8G8B8_O1A7R8G8B8 0x0000000a /* RW--V */
1513#define NV_PGRAPH_BPIXEL_DEPTH4_X8R8G8B8_O8R8G8B8 0x0000000b /* RW--V */
1514#define NV_PGRAPH_BPIXEL_DEPTH4_A8R8G8B8 0x0000000c /* RW--V */
1515#define NV_PGRAPH_BPIXEL_DEPTH4_Y32 0x0000000d /* RW--V */
1516#define NV_PGRAPH_BPIXEL_DEPTH4_V8YB8U8YA8 0x0000000e /* RW--V */
1517#define NV_PGRAPH_BPIXEL_DEPTH4_YB8V8YA8U8 0x0000000f /* RW--V */
1518#define NV_PGRAPH_BPIXEL_DEPTH5 23:20 /* RWIVF */
1519#define NV_PGRAPH_BPIXEL_DEPTH5_INVALID 0x00000000 /* RWI-V */
1520#define NV_PGRAPH_BPIXEL_DEPTH5_Y8 0x00000001 /* RW--V */
1521#define NV_PGRAPH_BPIXEL_DEPTH5_X1R5G5B5_Z1R5G5B5 0x00000002 /* RW--V */
1522#define NV_PGRAPH_BPIXEL_DEPTH5_X1R5G5B5_O1R5G5B5 0x00000003 /* RW--V */
1523#define NV_PGRAPH_BPIXEL_DEPTH5_A1R5G5B5 0x00000004 /* RW--V */
1524#define NV_PGRAPH_BPIXEL_DEPTH5_R5G6B5 0x00000005 /* RW--V */
1525#define NV_PGRAPH_BPIXEL_DEPTH5_Y16 0x00000006 /* RW--V */
1526#define NV_PGRAPH_BPIXEL_DEPTH5_X8R8G8B8_Z8R8G8B8 0x00000007 /* RW--V */
1527#define NV_PGRAPH_BPIXEL_DEPTH5_X8R8G8B8_O1Z7R8G8B8 0x00000008 /* RW--V */
1528#define NV_PGRAPH_BPIXEL_DEPTH5_X1A7R8G8B8_Z1A7R8G8B8 0x00000009 /* RW--V */
1529#define NV_PGRAPH_BPIXEL_DEPTH5_X1A7R8G8B8_O1A7R8G8B8 0x0000000a /* RW--V */
1530#define NV_PGRAPH_BPIXEL_DEPTH5_X8R8G8B8_O8R8G8B8 0x0000000b /* RW--V */
1531#define NV_PGRAPH_BPIXEL_DEPTH5_A8R8G8B8 0x0000000c /* RW--V */
1532#define NV_PGRAPH_BPIXEL_DEPTH5_Y32 0x0000000d /* RW--V */
1533#define NV_PGRAPH_BPIXEL_DEPTH5_V8YB8U8YA8 0x0000000e /* RW--V */
1534#define NV_PGRAPH_BPIXEL_DEPTH5_YB8V8YA8U8 0x0000000f /* RW--V */
1535#define NV_PGRAPH_LIMIT_VIOL_PIX 0x00400610 /* RW-4R */
1536#define NV_PGRAPH_LIMIT_VIOL_PIX_ADRS 23:0 /* RWIVF */
1537#define NV_PGRAPH_LIMIT_VIOL_PIX_ADRS_0 0x00000000 /* RWI-V */
1538#define NV_PGRAPH_LIMIT_VIOL_PIX_BLIT 29:29 /* RWIVF */
1539#define NV_PGRAPH_LIMIT_VIOL_PIX_BLIT_NO_VIOL 0x00000000 /* RWI-V */
1540#define NV_PGRAPH_LIMIT_VIOL_PIX_BLIT_VIOL 0x00000001 /* RW--V */
1541#define NV_PGRAPH_LIMIT_VIOL_PIX_LIMIT 30:30 /* RWIVF */
1542#define NV_PGRAPH_LIMIT_VIOL_PIX_LIMIT_NO_VIOL 0x00000000 /* RWI-V */
1543#define NV_PGRAPH_LIMIT_VIOL_PIX_LIMIT_VIOL 0x00000001 /* RW--V */
1544#define NV_PGRAPH_LIMIT_VIOL_PIX_OVRFLW 31:31 /* RWIVF */
1545#define NV_PGRAPH_LIMIT_VIOL_PIX_OVRFLW_NO_VIOL 0x00000000 /* RWI-V */
1546#define NV_PGRAPH_LIMIT_VIOL_PIX_OVRFLW_VIOL 0x00000001 /* RW--V */
1547#define NV_PGRAPH_LIMIT_VIOL_Z 0x00400614 /* RW-4R */
1548#define NV_PGRAPH_LIMIT_VIOL_Z_ADRS 23:0 /* RWIVF */
1549#define NV_PGRAPH_LIMIT_VIOL_Z_ADRS_0 0x00000000 /* RWI-V */
1550#define NV_PGRAPH_LIMIT_VIOL_Z_LIMIT 30:30 /* RWIVF */
1551#define NV_PGRAPH_LIMIT_VIOL_Z_LIMIT_NO_VIOL 0x00000000 /* RWI-V */
1552#define NV_PGRAPH_LIMIT_VIOL_Z_LIMIT_VIOL 0x00000001 /* RW--V */
1553#define NV_PGRAPH_LIMIT_VIOL_Z_OVRFLW 31:31 /* RWIVF */
1554#define NV_PGRAPH_LIMIT_VIOL_Z_OVRFLW_NO_VIOL 0x00000000 /* RWI-V */
1555#define NV_PGRAPH_LIMIT_VIOL_Z_OVRFLW_VIOL 0x00000001 /* RW--V */
1556#define NV_PGRAPH_STATE 0x00400710 /* RW-4R */
1557#define NV_PGRAPH_STATE_BUFFER_0 0:0 /* RWIVF */
1558#define NV_PGRAPH_STATE_BUFFER_0_INVALID 0x00000000 /* RWI-V */
1559#define NV_PGRAPH_STATE_BUFFER_0_VALID 0x00000001 /* RW--V */
1560#define NV_PGRAPH_STATE_BUFFER_1 1:1 /* RWIVF */
1561#define NV_PGRAPH_STATE_BUFFER_1_INVALID 0x00000000 /* RWI-V */
1562#define NV_PGRAPH_STATE_BUFFER_1_VALID 0x00000001 /* RW--V */
1563#define NV_PGRAPH_STATE_BUFFER_2 2:2 /* RWIVF */
1564#define NV_PGRAPH_STATE_BUFFER_2_INVALID 0x00000000 /* RWI-V */
1565#define NV_PGRAPH_STATE_BUFFER_2_VALID 0x00000001 /* RW--V */
1566#define NV_PGRAPH_STATE_BUFFER_3 3:3 /* RWIVF */
1567#define NV_PGRAPH_STATE_BUFFER_3_INVALID 0x00000000 /* RWI-V */
1568#define NV_PGRAPH_STATE_BUFFER_3_VALID 0x00000001 /* RW--V */
1569#define NV_PGRAPH_STATE_BUFFER_4 4:4 /* RWIVF */
1570#define NV_PGRAPH_STATE_BUFFER_4_INVALID 0x00000000 /* RWI-V */
1571#define NV_PGRAPH_STATE_BUFFER_4_VALID 0x00000001 /* RW--V */
1572#define NV_PGRAPH_STATE_BUFFER_5 5:5 /* RWIVF */
1573#define NV_PGRAPH_STATE_BUFFER_5_INVALID 0x00000000 /* RWI-V */
1574#define NV_PGRAPH_STATE_BUFFER_5_VALID 0x00000001 /* RW--V */
1575#define NV_PGRAPH_STATE_PITCH_0 8:8 /* RWIVF */
1576#define NV_PGRAPH_STATE_PITCH_0_INVALID 0x00000000 /* RWI-V */
1577#define NV_PGRAPH_STATE_PITCH_0_VALID 0x00000001 /* RW--V */
1578#define NV_PGRAPH_STATE_PITCH_1 9:9 /* RWIVF */
1579#define NV_PGRAPH_STATE_PITCH_1_INVALID 0x00000000 /* RWI-V */
1580#define NV_PGRAPH_STATE_PITCH_1_VALID 0x00000001 /* RW--V */
1581#define NV_PGRAPH_STATE_PITCH_2 10:10 /* RWIVF */
1582#define NV_PGRAPH_STATE_PITCH_2_INVALID 0x00000000 /* RWI-V */
1583#define NV_PGRAPH_STATE_PITCH_2_VALID 0x00000001 /* RW--V */
1584#define NV_PGRAPH_STATE_PITCH_3 11:11 /* RWIVF */
1585#define NV_PGRAPH_STATE_PITCH_3_INVALID 0x00000000 /* RWI-V */
1586#define NV_PGRAPH_STATE_PITCH_3_VALID 0x00000001 /* RW--V */
1587#define NV_PGRAPH_STATE_PITCH_4 12:12 /* RWIVF */
1588#define NV_PGRAPH_STATE_PITCH_4_INVALID 0x00000000 /* RWI-V */
1589#define NV_PGRAPH_STATE_PITCH_4_VALID 0x00000001 /* RW--V */
1590#define NV_PGRAPH_STATE_CHROMA_COLOR 16:16 /* RWIVF */
1591#define NV_PGRAPH_STATE_CHROMA_COLOR_INVALID 0x00000000 /* RWI-V */
1592#define NV_PGRAPH_STATE_CHROMA_COLOR_VALID 0x00000001 /* RW--V */
1593#define NV_PGRAPH_STATE_CHROMA_COLORFMT 17:17 /* RWIVF */
1594#define NV_PGRAPH_STATE_CHROMA_COLORFMT_INVALID 0x00000000 /* RWI-V */
1595#define NV_PGRAPH_STATE_CHROMA_COLORFMT_VALID 0x00000001 /* RW--V */
1596#define NV_PGRAPH_STATE_CPATTERN_COLORFMT 20:20 /* RWIVF */
1597#define NV_PGRAPH_STATE_CPATTERN_COLORFMT_INVALID 0x00000000 /* RWI-V */
1598#define NV_PGRAPH_STATE_CPATTERN_COLORFMT_VALID 0x00000001 /* RW--V */
1599#define NV_PGRAPH_STATE_CPATTERN_MONOFMT 21:21 /* RWIVF */
1600#define NV_PGRAPH_STATE_CPATTERN_MONOFMT_INVALID 0x00000000 /* RWI-V */
1601#define NV_PGRAPH_STATE_CPATTERN_MONOFMT_VALID 0x00000001 /* RW--V */
1602#define NV_PGRAPH_STATE_CPATTERN_SELECT 22:22 /* RWIVF */
1603#define NV_PGRAPH_STATE_CPATTERN_SELECT_INVALID 0x00000000 /* RWI-V */
1604#define NV_PGRAPH_STATE_CPATTERN_SELECT_VALID 0x00000001 /* RW--V */
1605#define NV_PGRAPH_STATE_PATTERN_COLOR0 24:24 /* RWIVF */
1606#define NV_PGRAPH_STATE_PATTERN_COLOR0_INVALID 0x00000000 /* RWI-V */
1607#define NV_PGRAPH_STATE_PATTERN_COLOR0_VALID 0x00000001 /* RW--V */
1608#define NV_PGRAPH_STATE_PATTERN_COLOR1 25:25 /* RWIVF */
1609#define NV_PGRAPH_STATE_PATTERN_COLOR1_INVALID 0x00000000 /* RWI-V */
1610#define NV_PGRAPH_STATE_PATTERN_COLOR1_VALID 0x00000001 /* RW--V */
1611#define NV_PGRAPH_STATE_PATTERN_PATT0 26:26 /* RWIVF */
1612#define NV_PGRAPH_STATE_PATTERN_PATT0_INVALID 0x00000000 /* RWI-V */
1613#define NV_PGRAPH_STATE_PATTERN_PATT0_VALID 0x00000001 /* RW--V */
1614#define NV_PGRAPH_STATE_PATTERN_PATT1 27:27 /* RWIVF */
1615#define NV_PGRAPH_STATE_PATTERN_PATT1_INVALID 0x00000000 /* RWI-V */
1616#define NV_PGRAPH_STATE_PATTERN_PATT1_VALID 0x00000001 /* RW--V */
1617#define NV_PGRAPH_CACHE_INDEX 0x00400728 /* RW-4R */
1618#define NV_PGRAPH_CACHE_INDEX_BANK 2:2 /* RWXVF */
1619#define NV_PGRAPH_CACHE_INDEX_BANK_10 0x00000000 /* RW--V */
1620#define NV_PGRAPH_CACHE_INDEX_BANK_32 0x00000001 /* RW--V */
1621#define NV_PGRAPH_CACHE_INDEX_ADRS 12:3 /* RWXVF */
1622#define NV_PGRAPH_CACHE_INDEX_ADRS_0 0x00000000 /* RW--V */
1623#define NV_PGRAPH_CACHE_INDEX_ADRS_1024 0x00000400 /* RW--V */
1624#define NV_PGRAPH_CACHE_INDEX_OP 14:13 /* RWXVF */
1625#define NV_PGRAPH_CACHE_INDEX_OP_WR_CACHE 0x00000000 /* RW--V */
1626#define NV_PGRAPH_CACHE_INDEX_OP_RD_CACHE 0x00000001 /* RW--V */
1627#define NV_PGRAPH_CACHE_INDEX_OP_RD_INDEX 0x00000002 /* RW--V */
1628#define NV_PGRAPH_CACHE_RAM 0x0040072c /* RW-4R */
1629#define NV_PGRAPH_CACHE_RAM_VALUE 31:0 /* RWXVF */
1630#define NV_PGRAPH_DMA_PITCH 0x00400760 /* RW-4R */
1631#define NV_PGRAPH_DMA_PITCH_S0 15:0 /* RWXSF */
1632#define NV_PGRAPH_DMA_PITCH_S1 31:16 /* RWXSF */
1633#define NV_PGRAPH_DVD_COLORFMT 0x00400764 /* RW-4R */
1634#define NV_PGRAPH_DVD_COLORFMT_IMAGE 5:0 /* RWNVF */
1635#define NV_PGRAPH_DVD_COLORFMT_IMAGE_FORMAT_INVALID 0x00 /* RWN-V */
1636#define NV_PGRAPH_DVD_COLORFMT_IMAGE_FORMAT_LE_V8YB8U8YA8 0x12 /* RW--V */
1637#define NV_PGRAPH_DVD_COLORFMT_IMAGE_FORMAT_LE_YB8V8YA8U8 0x13 /* RW--V */
1638#define NV_PGRAPH_DVD_COLORFMT_OVLY 9:8 /* RWNVF */
1639#define NV_PGRAPH_DVD_COLORFMT_OVLY_FORMAT_INVALID 0x00 /* RWN-V */
1640#define NV_PGRAPH_DVD_COLORFMT_OVLY_FORMAT_LE_A8Y8U8V8 0x01 /* RW--V */
1641#define NV_PGRAPH_DVD_COLORFMT_OVLY_FORMAT_LE_A4V6YB6A4U6YA6 0x02 /* RW--V */
1642#define NV_PGRAPH_DVD_COLORFMT_OVLY_FORMAT_TRANSPARENT 0x03 /* RW--V */
1643#define NV_PGRAPH_SCALED_FORMAT 0x00400768 /* RW-4R */
1644#define NV_PGRAPH_SCALED_FORMAT_ORIGIN 17:16 /* RWIVF */
1645#define NV_PGRAPH_SCALED_FORMAT_ORIGIN_INVALID 0x00000000 /* RWI-V */
1646#define NV_PGRAPH_SCALED_FORMAT_ORIGIN_CENTER 0x00000001 /* RW--V */
1647#define NV_PGRAPH_SCALED_FORMAT_ORIGIN_CORNER 0x00000002 /* RW--V */
1648#define NV_PGRAPH_SCALED_FORMAT_INTERPOLATOR 24:24 /* RWIVF */
1649#define NV_PGRAPH_SCALED_FORMAT_INTERPOLATOR_ZOH 0x00000000 /* RWI-V */
1650#define NV_PGRAPH_SCALED_FORMAT_INTERPOLATOR_FOH 0x00000001 /* RW--V */
1651#define NV_PGRAPH_PATT_COLOR0 0x00400800 /* RW-4R */
1652#define NV_PGRAPH_PATT_COLOR0_VALUE 31:0 /* RWXUF */
1653#define NV_PGRAPH_PATT_COLOR1 0x00400804 /* RW-4R */
1654#define NV_PGRAPH_PATT_COLOR1_VALUE 31:0 /* RWXUF */
1655#define NV_PGRAPH_PATT_COLORRAM(i) (0x00400900+(i)*4) /* R--4A */
1656#define NV_PGRAPH_PATT_COLORRAM__SIZE_1 64 /* */
1657#define NV_PGRAPH_PATT_COLORRAM_VALUE 23:0 /* R--UF */
1658#define NV_PGRAPH_PATTERN(i) (0x00400808+(i)*4) /* RW-4A */
1659#define NV_PGRAPH_PATTERN__SIZE_1 2 /* */
1660#define NV_PGRAPH_PATTERN_BITMAP 31:0 /* RWXVF */
1661#define NV_PGRAPH_PATTERN_SHAPE 0x00400810 /* RW-4R */
1662#define NV_PGRAPH_PATTERN_SHAPE_VALUE 1:0 /* RWXVF */
1663#define NV_PGRAPH_PATTERN_SHAPE_VALUE_8X_8Y 0x00000000 /* RW--V */
1664#define NV_PGRAPH_PATTERN_SHAPE_VALUE_64X_1Y 0x00000001 /* RW--V */
1665#define NV_PGRAPH_PATTERN_SHAPE_VALUE_1X_64Y 0x00000002 /* RW--V */
1666#define NV_PGRAPH_PATTERN_SHAPE_SELECT 4:4 /* RWXVF */
1667#define NV_PGRAPH_PATTERN_SHAPE_SELECT_2COLOR 0x00000000 /* RW--V */
1668#define NV_PGRAPH_PATTERN_SHAPE_SELECT_FULLCOLOR 0x00000001 /* RW--V */
1669#define NV_PGRAPH_MONO_COLOR0 0x00400600 /* RW-4R */
1670#define NV_PGRAPH_MONO_COLOR0_VALUE 31:0 /* RWXUF */
1671#define NV_PGRAPH_ROP3 0x00400604 /* RW-4R */
1672#define NV_PGRAPH_ROP3_VALUE 7:0 /* RWXVF */
1673#define NV_PGRAPH_CHROMA 0x00400814 /* RW-4R */
1674#define NV_PGRAPH_CHROMA_VALUE 31:0 /* RWXUF */
1675#define NV_PGRAPH_BETA_AND 0x00400608 /* RW-4R */
1676#define NV_PGRAPH_BETA_AND_VALUE_FRACTION 30:23 /* RWXUF */
1677#define NV_PGRAPH_BETA_PREMULT 0x0040060c /* RW-4R */
1678#define NV_PGRAPH_BETA_PREMULT_VALUE 31:0 /* RWXUF */
1679#define NV_PGRAPH_CONTROL0 0x00400818 /* RW-4R */
1680#define NV_PGRAPH_CONTROL1 0x0040081c /* RW-4R */
1681#define NV_PGRAPH_CONTROL2 0x00400820 /* RW-4R */
1682#define NV_PGRAPH_BLEND 0x00400824 /* RW-4R */
1683#define NV_PGRAPH_DPRAM_INDEX 0x00400828 /* RW-4R */
1684#define NV_PGRAPH_DPRAM_INDEX_ADRS 6:0 /* RWIVF */
1685#define NV_PGRAPH_DPRAM_INDEX_ADRS_0 0x00000000 /* RWI-V */
1686#define NV_PGRAPH_DPRAM_INDEX_SELECT 10:8 /* RWIVF */
1687#define NV_PGRAPH_DPRAM_INDEX_SELECT_ADRS_0 0x00000000 /* RWI-V */
1688#define NV_PGRAPH_DPRAM_INDEX_SELECT_ADRS_1 0x00000001 /* RW--V */
1689#define NV_PGRAPH_DPRAM_INDEX_SELECT_DATA_0 0x00000002 /* RW--V */
1690#define NV_PGRAPH_DPRAM_INDEX_SELECT_DATA_1 0x00000003 /* RW--V */
1691#define NV_PGRAPH_DPRAM_INDEX_SELECT_WE_0 0x00000004 /* RW--V */
1692#define NV_PGRAPH_DPRAM_INDEX_SELECT_WE_1 0x00000005 /* RW--V */
1693#define NV_PGRAPH_DPRAM_INDEX_SELECT_ALPHA_0 0x00000006 /* RW--V */
1694#define NV_PGRAPH_DPRAM_INDEX_SELECT_ALPHA_1 0x00000007 /* RW--V */
1695#define NV_PGRAPH_DPRAM_DATA 0x0040082c /* RW-4R */
1696#define NV_PGRAPH_DPRAM_DATA_VALUE 31:0 /* RWXVF */
1697#define NV_PGRAPH_DPRAM_ADRS_0 0x0040082c /* RW-4R */
1698#define NV_PGRAPH_DPRAM_ADRS_0__ALIAS_1 NV_PGRAPH_DPRAM_DATA /* */
1699#define NV_PGRAPH_DPRAM_ADRS_0_VALUE 19:0 /* RWXVF */
1700#define NV_PGRAPH_DPRAM_ADRS_1 0x0040082c /* RW-4R */
1701#define NV_PGRAPH_DPRAM_ADRS_1__ALIAS_1 NV_PGRAPH_DPRAM_DATA /* */
1702#define NV_PGRAPH_DPRAM_ADRS_1_VALUE 19:0 /* RWXVF */
1703#define NV_PGRAPH_DPRAM_DATA_0 0x0040082c /* RW-4R */
1704#define NV_PGRAPH_DPRAM_DATA_0__ALIAS_1 NV_PGRAPH_DPRAM_DATA /* */
1705#define NV_PGRAPH_DPRAM_DATA_0_VALUE 31:0 /* RWXVF */
1706#define NV_PGRAPH_DPRAM_DATA_1 0x0040082c /* RW-4R */
1707#define NV_PGRAPH_DPRAM_DATA_1__ALIAS_1 NV_PGRAPH_DPRAM_DATA /* */
1708#define NV_PGRAPH_DPRAM_DATA_1_VALUE 31:0 /* RWXVF */
1709#define NV_PGRAPH_DPRAM_WE_0 0x0040082c /* RW-4R */
1710#define NV_PGRAPH_DPRAM_WE_0__ALIAS_1 NV_PGRAPH_DPRAM_DATA /* */
1711#define NV_PGRAPH_DPRAM_WE_0_VALUE 23:0 /* RWXVF */
1712#define NV_PGRAPH_DPRAM_WE_1 0x0040082c /* RW-4R */
1713#define NV_PGRAPH_DPRAM_WE_1__ALIAS_1 NV_PGRAPH_DPRAM_DATA /* */
1714#define NV_PGRAPH_DPRAM_WE_1_VALUE 23:0 /* RWXVF */
1715#define NV_PGRAPH_DPRAM_ALPHA_0 0x0040082c /* RW-4R */
1716#define NV_PGRAPH_DPRAM_ALPHA_0__ALIAS_1 NV_PGRAPH_DPRAM_DATA /* */
1717#define NV_PGRAPH_DPRAM_ALPHA_0_VALUE 31:0 /* RWXVF */
1718#define NV_PGRAPH_DPRAM_ALPHA_1 0x0040082c /* RW-4R */
1719#define NV_PGRAPH_DPRAM_ALPHA_1__ALIAS_1 NV_PGRAPH_DPRAM_DATA /* */
1720#define NV_PGRAPH_DPRAM_ALPHA_1_VALUE 31:0 /* RWXVF */
1721#define NV_PGRAPH_STORED_FMT 0x00400830 /* RW-4R */
1722#define NV_PGRAPH_STORED_FMT_MONO0 5:0 /* RWXVF */
1723#define NV_PGRAPH_STORED_FMT_PATT0 13:8 /* RWXVF */
1724#define NV_PGRAPH_STORED_FMT_PATT1 21:16 /* RWXVF */
1725#define NV_PGRAPH_STORED_FMT_CHROMA 29:24 /* RWXVF */
1726#define NV_PGRAPH_FORMATS 0x00400618 /* RW-4R */
1727#define NV_PGRAPH_FORMATS_ROP 2:0 /* R-XVF */
1728#define NV_PGRAPH_FORMATS_ROP_Y8 0x00000000 /* -W--V */
1729#define NV_PGRAPH_FORMATS_ROP_RGB15 0x00000001 /* -W--V */
1730#define NV_PGRAPH_FORMATS_ROP_RGB16 0x00000002 /* -W--V */
1731#define NV_PGRAPH_FORMATS_ROP_Y16 0x00000003 /* -W--V */
1732#define NV_PGRAPH_FORMATS_ROP_INVALID 0x00000004 /* -W--V */
1733#define NV_PGRAPH_FORMATS_ROP_RGB24 0x00000005 /* -W--V */
1734#define NV_PGRAPH_FORMATS_ROP_RGB30 0x00000006 /* -W--V */
1735#define NV_PGRAPH_FORMATS_ROP_Y32 0x00000007 /* -W--V */
1736#define NV_PGRAPH_FORMATS_SRC 9:4 /* R-XVF */
1737#define NV_PGRAPH_FORMATS_SRC_INVALID 0x00000000 /* RW--V */
1738#define NV_PGRAPH_FORMATS_SRC_LE_Y8 0x00000001 /* RW--V */
1739#define NV_PGRAPH_FORMATS_SRC_LE_X16A8Y8 0x00000002 /* RW--V */
1740#define NV_PGRAPH_FORMATS_SRC_LE_X24Y8 0x00000003 /* RW--V */
1741#define NV_PGRAPH_FORMATS_SRC_LE_A1R5G5B5 0x00000006 /* RW--V */
1742#define NV_PGRAPH_FORMATS_SRC_LE_X1R5G5B5 0x00000007 /* RW--V */
1743#define NV_PGRAPH_FORMATS_SRC_LE_X16A1R5G5B5 0x00000008 /* RW--V */
1744#define NV_PGRAPH_FORMATS_SRC_LE_X17R5G5B5 0x00000009 /* RW--V */
1745#define NV_PGRAPH_FORMATS_SRC_LE_R5G6B5 0x0000000A /* RW--V */
1746#define NV_PGRAPH_FORMATS_SRC_LE_A16R5G6B5 0x0000000B /* RW--V */
1747#define NV_PGRAPH_FORMATS_SRC_LE_X16R5G6B5 0x0000000C /* RW--V */
1748#define NV_PGRAPH_FORMATS_SRC_LE_A8R8G8B8 0x0000000D /* RW--V */
1749#define NV_PGRAPH_FORMATS_SRC_LE_X8R8G8B8 0x0000000E /* RW--V */
1750#define NV_PGRAPH_FORMATS_SRC_LE_Y16 0x0000000F /* RW--V */
1751#define NV_PGRAPH_FORMATS_SRC_LE_A16Y16 0x00000010 /* RW--V */
1752#define NV_PGRAPH_FORMATS_SRC_LE_X16Y16 0x00000011 /* RW--V */
1753#define NV_PGRAPH_FORMATS_SRC_LE_V8YB8U8YA8 0x00000012 /* RW--V */
1754#define NV_PGRAPH_FORMATS_SRC_LE_YB8V8YA8U8 0x00000013 /* RW--V */
1755#define NV_PGRAPH_FORMATS_SRC_LE_Y32 0x00000014 /* RW--V */
1756#define NV_PGRAPH_FORMATS_FB 15:12 /* R-XVF */
1757#define NV_PGRAPH_FORMATS_FB_INVALID 0x00000000 /* RWI-V */
1758#define NV_PGRAPH_FORMATS_FB_Y8 0x00000001 /* RW--V */
1759#define NV_PGRAPH_FORMATS_FB_X1R5G5B5_Z1R5G5B5 0x00000002 /* RW--V */
1760#define NV_PGRAPH_FORMATS_FB_X1R5G5B5_O1R5G5B5 0x00000003 /* RW--V */
1761#define NV_PGRAPH_FORMATS_FB_A1R5G5B5 0x00000004 /* RW--V */
1762#define NV_PGRAPH_FORMATS_FB_R5G6B5 0x00000005 /* RW--V */
1763#define NV_PGRAPH_FORMATS_FB_Y16 0x00000006 /* RW--V */
1764#define NV_PGRAPH_FORMATS_FB_X8R8G8B8_Z8R8G8B8 0x00000007 /* RW--V */
1765#define NV_PGRAPH_FORMATS_FB_X8R8G8B8_O1Z7R8G8B8 0x00000008 /* RW--V */
1766#define NV_PGRAPH_FORMATS_FB_X1A7R8G8B8_Z1A7R8G8B8 0x00000009 /* RW--V */
1767#define NV_PGRAPH_FORMATS_FB_X1A7R8G8B8_O1A7R8G8B8 0x0000000a /* RW--V */
1768#define NV_PGRAPH_FORMATS_FB_X8R8G8B8_O8R8G8B8 0x0000000b /* RW--V */
1769#define NV_PGRAPH_FORMATS_FB_A8R8G8B8 0x0000000c /* RW--V */
1770#define NV_PGRAPH_FORMATS_FB_Y32 0x0000000d /* RW--V */
1771#define NV_PGRAPH_FORMATS_FB_V8YB8U8YA8 0x0000000e /* RW--V */
1772#define NV_PGRAPH_FORMATS_FB_YB8V8YA8U8 0x0000000f /* RW--V */
1773#define NV_PGRAPH_ABS_X_RAM(i) (0x00400400+(i)*4) /* RW-4A */
1774#define NV_PGRAPH_ABS_X_RAM__SIZE_1 32 /* */
1775#define NV_PGRAPH_ABS_X_RAM_VALUE 31:0 /* RWXUF */
1776#define NV_PGRAPH_X_RAM_BPORT(i) (0x00400c00+(i)*4) /* R--4A */
1777#define NV_PGRAPH_X_RAM_BPORT__SIZE_1 32 /* */
1778#define NV_PGRAPH_X_RAM_BPORT_VALUE 31:0 /* R--UF */
1779#define NV_PGRAPH_ABS_Y_RAM(i) (0x00400480+(i)*4) /* RW-4A */
1780#define NV_PGRAPH_ABS_Y_RAM__SIZE_1 32 /* */
1781#define NV_PGRAPH_ABS_Y_RAM_VALUE 31:0 /* RWXUF */
1782#define NV_PGRAPH_Y_RAM_BPORT(i) (0x00400c80+(i)*4) /* R--4A */
1783#define NV_PGRAPH_Y_RAM_BPORT__SIZE_1 32 /* */
1784#define NV_PGRAPH_Y_RAM_BPORT_VALUE 31:0 /* R--UF */
1785#define NV_PGRAPH_XY_LOGIC_MISC0 0x00400514 /* RW-4R */
1786#define NV_PGRAPH_XY_LOGIC_MISC0_COUNTER 17:0 /* RWBUF */
1787#define NV_PGRAPH_XY_LOGIC_MISC0_COUNTER_0 0x00000000 /* RWB-V */
1788#define NV_PGRAPH_XY_LOGIC_MISC0_DIMENSION 20:20 /* RWVVF */
1789#define NV_PGRAPH_XY_LOGIC_MISC0_DIMENSION_NONZERO 0x00000000 /* RWV-V */
1790#define NV_PGRAPH_XY_LOGIC_MISC0_DIMENSION_ZERO 0x00000001 /* RW--V */
1791#define NV_PGRAPH_XY_LOGIC_MISC0_INDEX 31:28 /* RWBUF */
1792#define NV_PGRAPH_XY_LOGIC_MISC0_INDEX_0 0x00000000 /* RWB-V */
1793#define NV_PGRAPH_XY_LOGIC_MISC1 0x00400518 /* RW-4R */
1794#define NV_PGRAPH_XY_LOGIC_MISC1_INITIAL 0:0 /* RWNVF */
1795#define NV_PGRAPH_XY_LOGIC_MISC1_INITIAL_NEEDED 0x00000000 /* RWN-V */
1796#define NV_PGRAPH_XY_LOGIC_MISC1_INITIAL_DONE 0x00000001 /* RW--V */
1797#define NV_PGRAPH_XY_LOGIC_MISC1_XTRACLIPX 4:4 /* RWIVF */
1798#define NV_PGRAPH_XY_LOGIC_MISC1_XTRACLIPX_NOTNULL 0x00000000 /* RWI-V */
1799#define NV_PGRAPH_XY_LOGIC_MISC1_XTRACLIPX_NULL 0x00000001 /* RW--V */
1800#define NV_PGRAPH_XY_LOGIC_MISC1_XTRACLIPY 5:5 /* RWIVF */
1801#define NV_PGRAPH_XY_LOGIC_MISC1_XTRACLIPY_NOTNULL 0x00000000 /* RWI-V */
1802#define NV_PGRAPH_XY_LOGIC_MISC1_XTRACLIPY_NULL 0x00000001 /* RW--V */
1803#define NV_PGRAPH_XY_LOGIC_MISC1_SEL_XIMAX 12:12 /* RWIVF */
1804#define NV_PGRAPH_XY_LOGIC_MISC1_SEL_XIMAX_UUMAX 0x00000000 /* RWI-V */
1805#define NV_PGRAPH_XY_LOGIC_MISC1_SEL_XIMAX_IMAGEMAX 0x00000001 /* RW--V */
1806#define NV_PGRAPH_XY_LOGIC_MISC1_SEL_YIMAX 16:16 /* RWIVF */
1807#define NV_PGRAPH_XY_LOGIC_MISC1_SEL_YIMAX_UUMAX 0x00000000 /* RWI-V */
1808#define NV_PGRAPH_XY_LOGIC_MISC1_SEL_YIMAX_IMAGEMAX 0x00000001 /* RW--V */
1809#define NV_PGRAPH_XY_LOGIC_MISC1_SEL_XXTRA 20:20 /* RWIVF */
1810#define NV_PGRAPH_XY_LOGIC_MISC1_SEL_XXTRA_CLIPMAX 0x00000000 /* RWI-V */
1811#define NV_PGRAPH_XY_LOGIC_MISC1_SEL_XXTRA_IMAGEMAX 0x00000001 /* RW--V */
1812#define NV_PGRAPH_XY_LOGIC_MISC2 0x0040051C /* RW-4R */
1813#define NV_PGRAPH_XY_LOGIC_MISC2_HANDOFF 0:0 /* RWIVF */
1814#define NV_PGRAPH_XY_LOGIC_MISC2_HANDOFF_DISABLE 0x00000000 /* RWI-V */
1815#define NV_PGRAPH_XY_LOGIC_MISC2_HANDOFF_ENABLE 0x00000001 /* RW--V */
1816#define NV_PGRAPH_XY_LOGIC_MISC2_XTRACLIPX 4:4 /* RWIVF */
1817#define NV_PGRAPH_XY_LOGIC_MISC2_XTRACLIPX_NOTNULL 0x00000000 /* RWI-V */
1818#define NV_PGRAPH_XY_LOGIC_MISC2_XTRACLIPX_NULL 0x00000001 /* RW--V */
1819#define NV_PGRAPH_XY_LOGIC_MISC2_XTRACLIPY 5:5 /* RWIVF */
1820#define NV_PGRAPH_XY_LOGIC_MISC2_XTRACLIPY_NOTNULL 0x00000000 /* RWI-V */
1821#define NV_PGRAPH_XY_LOGIC_MISC2_XTRACLIPY_NULL 0x00000001 /* RW--V */
1822#define NV_PGRAPH_XY_LOGIC_MISC2_SEL_XIMAX 12:12 /* RWIVF */
1823#define NV_PGRAPH_XY_LOGIC_MISC2_SEL_XIMAX_UCMAX 0x00000000 /* RWI-V */
1824#define NV_PGRAPH_XY_LOGIC_MISC2_SEL_XIMAX_IMAGEMAX 0x00000001 /* RW--V */
1825#define NV_PGRAPH_XY_LOGIC_MISC2_SEL_YIMAX 16:16 /* RWIVF */
1826#define NV_PGRAPH_XY_LOGIC_MISC2_SEL_YIMAX_UCMAX 0x00000000 /* RWI-V */
1827#define NV_PGRAPH_XY_LOGIC_MISC2_SEL_YIMAX_IMAGEMAX 0x00000001 /* RW--V */
1828#define NV_PGRAPH_XY_LOGIC_MISC2_SEL_XXTRA 20:20 /* RWIVF */
1829#define NV_PGRAPH_XY_LOGIC_MISC2_SEL_XXTRA_CLIPMAX 0x00000000 /* RWI-V */
1830#define NV_PGRAPH_XY_LOGIC_MISC2_SEL_XXTRA_IMAGEMAX 0x00000001 /* RW--V */
1831#define NV_PGRAPH_XY_LOGIC_MISC3 0x00400520 /* RW-4R */
1832#define NV_PGRAPH_XY_LOGIC_MISC3_WDIMY_EQ_0 0:0 /* RWXVF */
1833#define NV_PGRAPH_XY_LOGIC_MISC3_WDIMY_EQ_0_NULL 0x00000000 /* RW--V */
1834#define NV_PGRAPH_XY_LOGIC_MISC3_WDIMY_EQ_0_TRUE 0x00000001 /* RW--V */
1835#define NV_PGRAPH_XY_LOGIC_MISC3_RELOAD_WDIMY 4:4 /* RWXVF */
1836#define NV_PGRAPH_XY_LOGIC_MISC3_RELOAD_WDIMY_NULL 0x00000000 /* RW--V */
1837#define NV_PGRAPH_XY_LOGIC_MISC3_RELOAD_WDIMY_TRUE 0x00000001 /* RW--V */
1838#define NV_PGRAPH_XY_LOGIC_MISC3_RELOAD_WX 8:8 /* RWIVF */
1839#define NV_PGRAPH_XY_LOGIC_MISC3_RELOAD_WX_NULL 0x00000000 /* RWI-V */
1840#define NV_PGRAPH_XY_LOGIC_MISC3_RELOAD_WX_TRUE 0x00000001 /* RW--V */
1841#define NV_PGRAPH_XY_LOGIC_MISC3_TEXT_ALG 12:12 /* RWIVF */
1842#define NV_PGRAPH_XY_LOGIC_MISC3_TEXT_ALG_NULL 0x00000000 /* RWI-V */
1843#define NV_PGRAPH_XY_LOGIC_MISC3_TEXT_ALG_TRUE 0x00000001 /* RW--V */
1844#define NV_PGRAPH_XY_LOGIC_MISC3_TEXT_DIMX 22:16 /* RWXUF */
1845#define NV_PGRAPH_XY_LOGIC_MISC3_TEXT_DIMX_0 0x00000000 /* RW--V */
1846#define NV_PGRAPH_XY_LOGIC_MISC3_TEXT_WDIMX 30:24 /* RWXUF */
1847#define NV_PGRAPH_XY_LOGIC_MISC3_TEXT_WDIMX_0 0x00000000 /* RW--V */
1848#define NV_PGRAPH_X_MISC 0x00400500 /* RW-4R */
1849#define NV_PGRAPH_X_MISC_BIT33_0 0:0 /* RWNVF */
1850#define NV_PGRAPH_X_MISC_BIT33_0_0 0x00000000 /* RWN-V */
1851#define NV_PGRAPH_X_MISC_BIT33_1 1:1 /* RWNVF */
1852#define NV_PGRAPH_X_MISC_BIT33_1_0 0x00000000 /* RWN-V */
1853#define NV_PGRAPH_X_MISC_BIT33_2 2:2 /* RWNVF */
1854#define NV_PGRAPH_X_MISC_BIT33_2_0 0x00000000 /* RWN-V */
1855#define NV_PGRAPH_X_MISC_BIT33_3 3:3 /* RWNVF */
1856#define NV_PGRAPH_X_MISC_BIT33_3_0 0x00000000 /* RWN-V */
1857#define NV_PGRAPH_X_MISC_RANGE_0 4:4 /* RWNVF */
1858#define NV_PGRAPH_X_MISC_RANGE_0_0 0x00000000 /* RWN-V */
1859#define NV_PGRAPH_X_MISC_RANGE_1 5:5 /* RWNVF */
1860#define NV_PGRAPH_X_MISC_RANGE_1_0 0x00000000 /* RWN-V */
1861#define NV_PGRAPH_X_MISC_RANGE_2 6:6 /* RWNVF */
1862#define NV_PGRAPH_X_MISC_RANGE_2_0 0x00000000 /* RWN-V */
1863#define NV_PGRAPH_X_MISC_RANGE_3 7:7 /* RWNVF */
1864#define NV_PGRAPH_X_MISC_RANGE_3_0 0x00000000 /* RWN-V */
1865#define NV_PGRAPH_X_MISC_ADDER_OUTPUT 29:28 /* RWXVF */
1866#define NV_PGRAPH_X_MISC_ADDER_OUTPUT_EQ_0 0x00000000 /* RW--V */
1867#define NV_PGRAPH_X_MISC_ADDER_OUTPUT_LT_0 0x00000001 /* RW--V */
1868#define NV_PGRAPH_X_MISC_ADDER_OUTPUT_GT_0 0x00000002 /* RW--V */
1869#define NV_PGRAPH_Y_MISC 0x00400504 /* RW-4R */
1870#define NV_PGRAPH_Y_MISC_BIT33_0 0:0 /* RWNVF */
1871#define NV_PGRAPH_Y_MISC_BIT33_0_0 0x00000000 /* RWN-V */
1872#define NV_PGRAPH_Y_MISC_BIT33_1 1:1 /* RWNVF */
1873#define NV_PGRAPH_Y_MISC_BIT33_1_0 0x00000000 /* RWN-V */
1874#define NV_PGRAPH_Y_MISC_BIT33_2 2:2 /* RWNVF */
1875#define NV_PGRAPH_Y_MISC_BIT33_2_0 0x00000000 /* RWN-V */
1876#define NV_PGRAPH_Y_MISC_BIT33_3 3:3 /* RWNVF */
1877#define NV_PGRAPH_Y_MISC_BIT33_3_0 0x00000000 /* RWN-V */
1878#define NV_PGRAPH_Y_MISC_RANGE_0 4:4 /* RWNVF */
1879#define NV_PGRAPH_Y_MISC_RANGE_0_0 0x00000000 /* RWN-V */
1880#define NV_PGRAPH_Y_MISC_RANGE_1 5:5 /* RWNVF */
1881#define NV_PGRAPH_Y_MISC_RANGE_1_0 0x00000000 /* RWN-V */
1882#define NV_PGRAPH_Y_MISC_RANGE_2 6:6 /* RWNVF */
1883#define NV_PGRAPH_Y_MISC_RANGE_2_0 0x00000000 /* RWN-V */
1884#define NV_PGRAPH_Y_MISC_RANGE_3 7:7 /* RWNVF */
1885#define NV_PGRAPH_Y_MISC_RANGE_3_0 0x00000000 /* RWN-V */
1886#define NV_PGRAPH_Y_MISC_ADDER_OUTPUT 29:28 /* RWXVF */
1887#define NV_PGRAPH_Y_MISC_ADDER_OUTPUT_EQ_0 0x00000000 /* RW--V */
1888#define NV_PGRAPH_Y_MISC_ADDER_OUTPUT_LT_0 0x00000001 /* RW--V */
1889#define NV_PGRAPH_Y_MISC_ADDER_OUTPUT_GT_0 0x00000002 /* RW--V */
1890#define NV_PGRAPH_ABS_UCLIP_XMIN 0x0040053C /* RW-4R */
1891#define NV_PGRAPH_ABS_UCLIP_XMIN_VALUE 15:0 /* RWXSF */
1892#define NV_PGRAPH_ABS_UCLIP_XMAX 0x00400544 /* RW-4R */
1893#define NV_PGRAPH_ABS_UCLIP_XMAX_VALUE 17:0 /* RWXSF */
1894#define NV_PGRAPH_ABS_UCLIP_YMIN 0x00400540 /* RW-4R */
1895#define NV_PGRAPH_ABS_UCLIP_YMIN_VALUE 15:0 /* RWXSF */
1896#define NV_PGRAPH_ABS_UCLIP_YMAX 0x00400548 /* RW-4R */
1897#define NV_PGRAPH_ABS_UCLIP_YMAX_VALUE 17:0 /* RWXSF */
1898#define NV_PGRAPH_ABS_UCLIPA_XMIN 0x00400560 /* RW-4R */
1899#define NV_PGRAPH_ABS_UCLIPA_XMIN_VALUE 15:0 /* RWXSF */
1900#define NV_PGRAPH_ABS_UCLIPA_XMAX 0x00400568 /* RW-4R */
1901#define NV_PGRAPH_ABS_UCLIPA_XMAX_VALUE 17:0 /* RWXSF */
1902#define NV_PGRAPH_ABS_UCLIPA_YMIN 0x00400564 /* RW-4R */
1903#define NV_PGRAPH_ABS_UCLIPA_YMIN_VALUE 15:0 /* RWXSF */
1904#define NV_PGRAPH_ABS_UCLIPA_YMAX 0x0040056C /* RW-4R */
1905#define NV_PGRAPH_ABS_UCLIPA_YMAX_VALUE 17:0 /* RWXSF */
1906#define NV_PGRAPH_SOURCE_COLOR 0x0040050C /* RW-4R */
1907#define NV_PGRAPH_SOURCE_COLOR_VALUE 31:0 /* RWNVF */
1908#define NV_PGRAPH_SOURCE_COLOR_VALUE_0 0x00000000 /* RWN-V */
1909#define NV_PGRAPH_VALID1 0x00400508 /* RW-4R */
1910#define NV_PGRAPH_VALID1_VLD 22:0 /* RWNVF */
1911#define NV_PGRAPH_VALID1_VLD_0 0x00000000 /* RWN-V */
1912#define NV_PGRAPH_VALID1_CLIP_MIN 28:28 /* RWIVF */
1913#define NV_PGRAPH_VALID1_CLIP_MIN_NO_ERROR 0x00000000 /* RWI-V */
1914#define NV_PGRAPH_VALID1_CLIP_MIN_ONLY 0x00000001 /* RW--V */
1915#define NV_PGRAPH_VALID1_CLIPA_MIN 29:29 /* RWIVF */
1916#define NV_PGRAPH_VALID1_CLIPA_MIN_NO_ERROR 0x00000000 /* RWI-V */
1917#define NV_PGRAPH_VALID1_CLIPA_MIN_ONLY 0x00000001 /* RW--V */
1918#define NV_PGRAPH_VALID1_CLIP_MAX 30:30 /* RWIVF */
1919#define NV_PGRAPH_VALID1_CLIP_MAX_NO_ERROR 0x00000000 /* RWI-V */
1920#define NV_PGRAPH_VALID1_CLIP_MAX_ONLY 0x00000001 /* RW--V */
1921#define NV_PGRAPH_VALID1_CLIPA_MAX 31:31 /* RWIVF */
1922#define NV_PGRAPH_VALID1_CLIPA_MAX_NO_ERROR 0x00000000 /* RWI-V */
1923#define NV_PGRAPH_VALID1_CLIPA_MAX_ONLY 0x00000001 /* RW--V */
1924#define NV_PGRAPH_VALID2 0x00400578 /* RW-4R */
1925#define NV_PGRAPH_VALID2_VLD2 28:0 /* RWNVF */
1926#define NV_PGRAPH_VALID2_VLD2_0 0x00000000 /* RWN-V */
1927#define NV_PGRAPH_ABS_ICLIP_XMAX 0x00400534 /* RW-4R */
1928#define NV_PGRAPH_ABS_ICLIP_XMAX_VALUE 17:0 /* RWXSF */
1929#define NV_PGRAPH_ABS_ICLIP_YMAX 0x00400538 /* RW-4R */
1930#define NV_PGRAPH_ABS_ICLIP_YMAX_VALUE 17:0 /* RWXSF */
1931#define NV_PGRAPH_CLIPX_0 0x00400524 /* RW-4R */
1932#define NV_PGRAPH_CLIPX_0_CLIP0_MIN 1:0 /* RWNVF */
1933#define NV_PGRAPH_CLIPX_0_CLIP0_MIN_GT 0x00000000 /* RW--V */
1934#define NV_PGRAPH_CLIPX_0_CLIP0_MIN_LT 0x00000001 /* RWN-V */
1935#define NV_PGRAPH_CLIPX_0_CLIP0_MIN_EQ 0x00000002 /* RW--V */
1936#define NV_PGRAPH_CLIPX_0_CLIP0_MAX 3:2 /* RWNVF */
1937#define NV_PGRAPH_CLIPX_0_CLIP0_MAX_LT 0x00000000 /* RW--V */
1938#define NV_PGRAPH_CLIPX_0_CLIP0_MAX_GT 0x00000001 /* RWN-V */
1939#define NV_PGRAPH_CLIPX_0_CLIP0_MAX_EQ 0x00000002 /* RW--V */
1940#define NV_PGRAPH_CLIPX_0_CLIP1_MIN 5:4 /* RWNVF */
1941#define NV_PGRAPH_CLIPX_0_CLIP1_MIN_GT 0x00000000 /* RW--V */
1942#define NV_PGRAPH_CLIPX_0_CLIP1_MIN_LT 0x00000001 /* RWN-V */
1943#define NV_PGRAPH_CLIPX_0_CLIP1_MIN_EQ 0x00000002 /* RW--V */
1944#define NV_PGRAPH_CLIPX_0_CLIP1_MAX 7:6 /* RWNVF */
1945#define NV_PGRAPH_CLIPX_0_CLIP1_MAX_LT 0x00000000 /* RW--V */
1946#define NV_PGRAPH_CLIPX_0_CLIP1_MAX_GT 0x00000001 /* RWN-V */
1947#define NV_PGRAPH_CLIPX_0_CLIP1_MAX_EQ 0x00000002 /* RW--V */
1948#define NV_PGRAPH_CLIPX_0_CLIP2_MIN 9:8 /* RWNVF */
1949#define NV_PGRAPH_CLIPX_0_CLIP2_MIN_GT 0x00000000 /* RW--V */
1950#define NV_PGRAPH_CLIPX_0_CLIP2_MIN_LT 0x00000001 /* RWN-V */
1951#define NV_PGRAPH_CLIPX_0_CLIP2_MIN_EQ 0x00000002 /* RW--V */
1952#define NV_PGRAPH_CLIPX_0_CLIP2_MAX 11:10 /* RWNVF */
1953#define NV_PGRAPH_CLIPX_0_CLIP2_MAX_LT 0x00000000 /* RW--V */
1954#define NV_PGRAPH_CLIPX_0_CLIP2_MAX_GT 0x00000001 /* RWN-V */
1955#define NV_PGRAPH_CLIPX_0_CLIP2_MAX_EQ 0x00000002 /* RW--V */
1956#define NV_PGRAPH_CLIPX_0_CLIP3_MIN 13:12 /* RWNVF */
1957#define NV_PGRAPH_CLIPX_0_CLIP3_MIN_GT 0x00000000 /* RW--V */
1958#define NV_PGRAPH_CLIPX_0_CLIP3_MIN_LT 0x00000001 /* RWN-V */
1959#define NV_PGRAPH_CLIPX_0_CLIP3_MIN_EQ 0x00000002 /* RW--V */
1960#define NV_PGRAPH_CLIPX_0_CLIP3_MAX 15:14 /* RWNVF */
1961#define NV_PGRAPH_CLIPX_0_CLIP3_MAX_LT 0x00000000 /* RW--V */
1962#define NV_PGRAPH_CLIPX_0_CLIP3_MAX_GT 0x00000001 /* RWN-V */
1963#define NV_PGRAPH_CLIPX_0_CLIP3_MAX_EQ 0x00000002 /* RW--V */
1964#define NV_PGRAPH_CLIPX_0_CLIP4_MIN 17:16 /* RWNVF */
1965#define NV_PGRAPH_CLIPX_0_CLIP4_MIN_GT 0x00000000 /* RW--V */
1966#define NV_PGRAPH_CLIPX_0_CLIP4_MIN_LT 0x00000001 /* RWN-V */
1967#define NV_PGRAPH_CLIPX_0_CLIP4_MIN_EQ 0x00000002 /* RW--V */
1968#define NV_PGRAPH_CLIPX_0_CLIP4_MAX 19:18 /* RWNVF */
1969#define NV_PGRAPH_CLIPX_0_CLIP4_MAX_LT 0x00000000 /* RW--V */
1970#define NV_PGRAPH_CLIPX_0_CLIP4_MAX_GT 0x00000001 /* RWN-V */
1971#define NV_PGRAPH_CLIPX_0_CLIP4_MAX_EQ 0x00000002 /* RW--V */
1972#define NV_PGRAPH_CLIPX_0_CLIP5_MIN 21:20 /* RWNVF */
1973#define NV_PGRAPH_CLIPX_0_CLIP5_MIN_GT 0x00000000 /* RW--V */
1974#define NV_PGRAPH_CLIPX_0_CLIP5_MIN_LT 0x00000001 /* RWN-V */
1975#define NV_PGRAPH_CLIPX_0_CLIP5_MIN_EQ 0x00000002 /* RW--V */
1976#define NV_PGRAPH_CLIPX_0_CLIP5_MAX 23:22 /* RWNVF */
1977#define NV_PGRAPH_CLIPX_0_CLIP5_MAX_LT 0x00000000 /* RW--V */
1978#define NV_PGRAPH_CLIPX_0_CLIP5_MAX_GT 0x00000001 /* RWN-V */
1979#define NV_PGRAPH_CLIPX_0_CLIP5_MAX_EQ 0x00000002 /* RW--V */
1980#define NV_PGRAPH_CLIPX_0_CLIP6_MIN 25:24 /* RWNVF */
1981#define NV_PGRAPH_CLIPX_0_CLIP6_MIN_GT 0x00000000 /* RW--V */
1982#define NV_PGRAPH_CLIPX_0_CLIP6_MIN_LT 0x00000001 /* RWN-V */
1983#define NV_PGRAPH_CLIPX_0_CLIP6_MIN_EQ 0x00000002 /* RW--V */
1984#define NV_PGRAPH_CLIPX_0_CLIP6_MAX 27:26 /* RWNVF */
1985#define NV_PGRAPH_CLIPX_0_CLIP6_MAX_LT 0x00000000 /* RW--V */
1986#define NV_PGRAPH_CLIPX_0_CLIP6_MAX_GT 0x00000001 /* RWN-V */
1987#define NV_PGRAPH_CLIPX_0_CLIP6_MAX_EQ 0x00000002 /* RW--V */
1988#define NV_PGRAPH_CLIPX_0_CLIP7_MIN 29:28 /* RWNVF */
1989#define NV_PGRAPH_CLIPX_0_CLIP7_MIN_GT 0x00000000 /* RW--V */
1990#define NV_PGRAPH_CLIPX_0_CLIP7_MIN_LT 0x00000001 /* RWN-V */
1991#define NV_PGRAPH_CLIPX_0_CLIP7_MIN_EQ 0x00000002 /* RW--V */
1992#define NV_PGRAPH_CLIPX_0_CLIP7_MAX 31:30 /* RWNVF */
1993#define NV_PGRAPH_CLIPX_0_CLIP7_MAX_LT 0x00000000 /* RW--V */
1994#define NV_PGRAPH_CLIPX_0_CLIP7_MAX_GT 0x00000001 /* RWN-V */
1995#define NV_PGRAPH_CLIPX_0_CLIP7_MAX_EQ 0x00000002 /* RW--V */
1996#define NV_PGRAPH_CLIPX_1 0x00400528 /* RW-4R */
1997#define NV_PGRAPH_CLIPX_1_CLIP8_MIN 1:0 /* RWNVF */
1998#define NV_PGRAPH_CLIPX_1_CLIP8_MIN_GT 0x00000000 /* RW--V */
1999#define NV_PGRAPH_CLIPX_1_CLIP8_MIN_LT 0x00000001 /* RWN-V */
2000#define NV_PGRAPH_CLIPX_1_CLIP8_MIN_EQ 0x00000002 /* RW--V */
2001#define NV_PGRAPH_CLIPX_1_CLIP8_MAX 3:2 /* RWNVF */
2002#define NV_PGRAPH_CLIPX_1_CLIP8_MAX_LT 0x00000000 /* RW--V */
2003#define NV_PGRAPH_CLIPX_1_CLIP8_MAX_GT 0x00000001 /* RWN-V */
2004#define NV_PGRAPH_CLIPX_1_CLIP8_MAX_EQ 0x00000002 /* RW--V */
2005#define NV_PGRAPH_CLIPX_1_CLIP9_MIN 5:4 /* RWNVF */
2006#define NV_PGRAPH_CLIPX_1_CLIP9_MIN_GT 0x00000000 /* RW--V */
2007#define NV_PGRAPH_CLIPX_1_CLIP9_MIN_LT 0x00000001 /* RWN-V */
2008#define NV_PGRAPH_CLIPX_1_CLIP9_MIN_EQ 0x00000002 /* RW--V */
2009#define NV_PGRAPH_CLIPX_1_CLIP9_MAX 7:6 /* RWNVF */
2010#define NV_PGRAPH_CLIPX_1_CLIP9_MAX_LT 0x00000000 /* RW--V */
2011#define NV_PGRAPH_CLIPX_1_CLIP9_MAX_GT 0x00000001 /* RWN-V */
2012#define NV_PGRAPH_CLIPX_1_CLIP9_MAX_EQ 0x00000002 /* RW--V */
2013#define NV_PGRAPH_CLIPX_1_CLIP10_MIN 9:8 /* RWNVF */
2014#define NV_PGRAPH_CLIPX_1_CLIP10_MIN_GT 0x00000000 /* RW--V */
2015#define NV_PGRAPH_CLIPX_1_CLIP10_MIN_LT 0x00000001 /* RWN-V */
2016#define NV_PGRAPH_CLIPX_1_CLIP10_MIN_EQ 0x00000002 /* RW--V */
2017#define NV_PGRAPH_CLIPX_1_CLIP10_MAX 11:10 /* RWNVF */
2018#define NV_PGRAPH_CLIPX_1_CLIP10_MAX_LT 0x00000000 /* RW--V */
2019#define NV_PGRAPH_CLIPX_1_CLIP10_MAX_GT 0x00000001 /* RWN-V */
2020#define NV_PGRAPH_CLIPX_1_CLIP10_MAX_EQ 0x00000002 /* RW--V */
2021#define NV_PGRAPH_CLIPX_1_CLIP11_MIN 13:12 /* RWNVF */
2022#define NV_PGRAPH_CLIPX_1_CLIP11_MIN_GT 0x00000000 /* RW--V */
2023#define NV_PGRAPH_CLIPX_1_CLIP11_MIN_LT 0x00000001 /* RWN-V */
2024#define NV_PGRAPH_CLIPX_1_CLIP11MIN_EQ 0x00000002 /* RW--V */
2025#define NV_PGRAPH_CLIPX_1_CLIP11_MAX 15:14 /* RWNVF */
2026#define NV_PGRAPH_CLIPX_1_CLIP11_MAX_LT 0x00000000 /* RW--V */
2027#define NV_PGRAPH_CLIPX_1_CLIP11_MAX_GT 0x00000001 /* RWN-V */
2028#define NV_PGRAPH_CLIPX_1_CLIP11_MAX_EQ 0x00000002 /* RW--V */
2029#define NV_PGRAPH_CLIPX_1_CLIP12_MIN 17:16 /* RWNVF */
2030#define NV_PGRAPH_CLIPX_1_CLIP12_MIN_GT 0x00000000 /* RW--V */
2031#define NV_PGRAPH_CLIPX_1_CLIP12_MIN_LT 0x00000001 /* RWN-V */
2032#define NV_PGRAPH_CLIPX_1_CLIP12_MIN_EQ 0x00000002 /* RW--V */
2033#define NV_PGRAPH_CLIPX_1_CLIP12_MAX 19:18 /* RWNVF */
2034#define NV_PGRAPH_CLIPX_1_CLIP12_MAX_LT 0x00000000 /* RW--V */
2035#define NV_PGRAPH_CLIPX_1_CLIP12_MAX_GT 0x00000001 /* RWN-V */
2036#define NV_PGRAPH_CLIPX_1_CLIP12_MAX_EQ 0x00000002 /* RW--V */
2037#define NV_PGRAPH_CLIPX_1_CLIP13_MIN 21:20 /* RWNVF */
2038#define NV_PGRAPH_CLIPX_1_CLIP13_MIN_GT 0x00000000 /* RW--V */
2039#define NV_PGRAPH_CLIPX_1_CLIP13_MIN_LT 0x00000001 /* RWN-V */
2040#define NV_PGRAPH_CLIPX_1_CLIP13_MIN_EQ 0x00000002 /* RW--V */
2041#define NV_PGRAPH_CLIPX_1_CLIP13_MAX 23:22 /* RWNVF */
2042#define NV_PGRAPH_CLIPX_1_CLIP13_MAX_LT 0x00000000 /* RW--V */
2043#define NV_PGRAPH_CLIPX_1_CLIP13_MAX_GT 0x00000001 /* RWN-V */
2044#define NV_PGRAPH_CLIPX_1_CLIP13_MAX_EQ 0x00000002 /* RW--V */
2045#define NV_PGRAPH_CLIPX_1_CLIP14_MIN 25:24 /* RWNVF */
2046#define NV_PGRAPH_CLIPX_1_CLIP14_MIN_GT 0x00000000 /* RW--V */
2047#define NV_PGRAPH_CLIPX_1_CLIP14_MIN_LT 0x00000001 /* RWN-V */
2048#define NV_PGRAPH_CLIPX_1_CLIP14_MIN_EQ 0x00000002 /* RW--V */
2049#define NV_PGRAPH_CLIPX_1_CLIP14_MAX 27:26 /* RWNVF */
2050#define NV_PGRAPH_CLIPX_1_CLIP14_MAX_LT 0x00000000 /* RW--V */
2051#define NV_PGRAPH_CLIPX_1_CLIP14_MAX_GT 0x00000001 /* RWN-V */
2052#define NV_PGRAPH_CLIPX_1_CLIP14_MAX_EQ 0x00000002 /* RW--V */
2053#define NV_PGRAPH_CLIPX_1_CLIP15_MIN 29:28 /* RWNVF */
2054#define NV_PGRAPH_CLIPX_1_CLIP15_MIN_GT 0x00000000 /* RW--V */
2055#define NV_PGRAPH_CLIPX_1_CLIP15_MIN_LT 0x00000001 /* RWN-V */
2056#define NV_PGRAPH_CLIPX_1_CLIP15_MIN_EQ 0x00000002 /* RW--V */
2057#define NV_PGRAPH_CLIPX_1_CLIP15_MAX 31:30 /* RWNVF */
2058#define NV_PGRAPH_CLIPX_1_CLIP15_MAX_LT 0x00000000 /* RW--V */
2059#define NV_PGRAPH_CLIPX_1_CLIP15_MAX_GT 0x00000001 /* RWN-V */
2060#define NV_PGRAPH_CLIPX_1_CLIP15_MAX_EQ 0x00000002 /* RW--V */
2061#define NV_PGRAPH_CLIPY_0 0x0040052c /* RW-4R */
2062#define NV_PGRAPH_CLIPY_0_CLIP0_MIN 1:0 /* RWNVF */
2063#define NV_PGRAPH_CLIPY_0_CLIP0_MIN_GT 0x00000000 /* RW--V */
2064#define NV_PGRAPH_CLIPY_0_CLIP0_MIN_LT 0x00000001 /* RWN-V */
2065#define NV_PGRAPH_CLIPY_0_CLIP0_MIN_EQ 0x00000002 /* RW--V */
2066#define NV_PGRAPH_CLIPY_0_CLIP0_MAX 3:2 /* RWNVF */
2067#define NV_PGRAPH_CLIPY_0_CLIP0_MAX_LT 0x00000000 /* RW--V */
2068#define NV_PGRAPH_CLIPY_0_CLIP0_MAX_GT 0x00000001 /* RWN-V */
2069#define NV_PGRAPH_CLIPY_0_CLIP0_MAX_EQ 0x00000002 /* RW--V */
2070#define NV_PGRAPH_CLIPY_0_CLIP1_MIN 5:4 /* RWNVF */
2071#define NV_PGRAPH_CLIPY_0_CLIP1_MIN_GT 0x00000000 /* RW--V */
2072#define NV_PGRAPH_CLIPY_0_CLIP1_MIN_LT 0x00000001 /* RWN-V */
2073#define NV_PGRAPH_CLIPY_0_CLIP1_MIN_EQ 0x00000002 /* RW--V */
2074#define NV_PGRAPH_CLIPY_0_CLIP1_MAX 7:6 /* RWNVF */
2075#define NV_PGRAPH_CLIPY_0_CLIP1_MAX_LT 0x00000000 /* RW--V */
2076#define NV_PGRAPH_CLIPY_0_CLIP1_MAX_GT 0x00000001 /* RWN-V */
2077#define NV_PGRAPH_CLIPY_0_CLIP1_MAX_EQ 0x00000002 /* RW--V */
2078#define NV_PGRAPH_CLIPY_0_CLIP2_MIN 9:8 /* RWNVF */
2079#define NV_PGRAPH_CLIPY_0_CLIP2_MIN_GT 0x00000000 /* RW--V */
2080#define NV_PGRAPH_CLIPY_0_CLIP2_MIN_LT 0x00000001 /* RWN-V */
2081#define NV_PGRAPH_CLIPY_0_CLIP2_MIN_EQ 0x00000002 /* RW--V */
2082#define NV_PGRAPH_CLIPY_0_CLIP2_MAX 11:10 /* RWNVF */
2083#define NV_PGRAPH_CLIPY_0_CLIP2_MAX_LT 0x00000000 /* RW--V */
2084#define NV_PGRAPH_CLIPY_0_CLIP2_MAX_GT 0x00000001 /* RWN-V */
2085#define NV_PGRAPH_CLIPY_0_CLIP2_MAX_EQ 0x00000002 /* RW--V */
2086#define NV_PGRAPH_CLIPY_0_CLIP3_MIN 13:12 /* RWNVF */
2087#define NV_PGRAPH_CLIPY_0_CLIP3_MIN_GT 0x00000000 /* RW--V */
2088#define NV_PGRAPH_CLIPY_0_CLIP3_MIN_LT 0x00000001 /* RWN-V */
2089#define NV_PGRAPH_CLIPY_0_CLIP3_MIN_EQ 0x00000002 /* RW--V */
2090#define NV_PGRAPH_CLIPY_0_CLIP3_MAX 15:14 /* RWNVF */
2091#define NV_PGRAPH_CLIPY_0_CLIP3_MAX_LT 0x00000000 /* RW--V */
2092#define NV_PGRAPH_CLIPY_0_CLIP3_MAX_GT 0x00000001 /* RWN-V */
2093#define NV_PGRAPH_CLIPY_0_CLIP3_MAX_EQ 0x00000002 /* RW--V */
2094#define NV_PGRAPH_CLIPY_0_CLIP4_MIN 17:16 /* RWNVF */
2095#define NV_PGRAPH_CLIPY_0_CLIP4_MIN_GT 0x00000000 /* RW--V */
2096#define NV_PGRAPH_CLIPY_0_CLIP4_MIN_LT 0x00000001 /* RWN-V */
2097#define NV_PGRAPH_CLIPY_0_CLIP4_MIN_EQ 0x00000002 /* RW--V */
2098#define NV_PGRAPH_CLIPY_0_CLIP4_MAX 19:18 /* RWNVF */
2099#define NV_PGRAPH_CLIPY_0_CLIP4_MAX_LT 0x00000000 /* RW--V */
2100#define NV_PGRAPH_CLIPY_0_CLIP4_MAX_GT 0x00000001 /* RWN-V */
2101#define NV_PGRAPH_CLIPY_0_CLIP4_MAX_EQ 0x00000002 /* RW--V */
2102#define NV_PGRAPH_CLIPY_0_CLIP5_MIN 21:20 /* RWNVF */
2103#define NV_PGRAPH_CLIPY_0_CLIP5_MIN_GT 0x00000000 /* RW--V */
2104#define NV_PGRAPH_CLIPY_0_CLIP5_MIN_LT 0x00000001 /* RWN-V */
2105#define NV_PGRAPH_CLIPY_0_CLIP5_MIN_EQ 0x00000002 /* RW--V */
2106#define NV_PGRAPH_CLIPY_0_CLIP5_MAX 23:22 /* RWNVF */
2107#define NV_PGRAPH_CLIPY_0_CLIP5_MAX_LT 0x00000000 /* RW--V */
2108#define NV_PGRAPH_CLIPY_0_CLIP5_MAX_GT 0x00000001 /* RWN-V */
2109#define NV_PGRAPH_CLIPY_0_CLIP5_MAX_EQ 0x00000002 /* RW--V */
2110#define NV_PGRAPH_CLIPY_0_CLIP6_MIN 25:24 /* RWNVF */
2111#define NV_PGRAPH_CLIPY_0_CLIP6_MIN_GT 0x00000000 /* RW--V */
2112#define NV_PGRAPH_CLIPY_0_CLIP6_MIN_LT 0x00000001 /* RWN-V */
2113#define NV_PGRAPH_CLIPY_0_CLIP6_MIN_EQ 0x00000002 /* RW--V */
2114#define NV_PGRAPH_CLIPY_0_CLIP6_MAX 27:26 /* RWNVF */
2115#define NV_PGRAPH_CLIPY_0_CLIP6_MAX_LT 0x00000000 /* RW--V */
2116#define NV_PGRAPH_CLIPY_0_CLIP6_MAX_GT 0x00000001 /* RWN-V */
2117#define NV_PGRAPH_CLIPY_0_CLIP6_MAX_EQ 0x00000002 /* RW--V */
2118#define NV_PGRAPH_CLIPY_0_CLIP7_MIN 29:28 /* RWNVF */
2119#define NV_PGRAPH_CLIPY_0_CLIP7_MIN_GT 0x00000000 /* RW--V */
2120#define NV_PGRAPH_CLIPY_0_CLIP7_MIN_LT 0x00000001 /* RWN-V */
2121#define NV_PGRAPH_CLIPY_0_CLIP7_MIN_EQ 0x00000002 /* RW--V */
2122#define NV_PGRAPH_CLIPY_0_CLIP7_MAX 31:30 /* RWNVF */
2123#define NV_PGRAPH_CLIPY_0_CLIP7_MAX_LT 0x00000000 /* RW--V */
2124#define NV_PGRAPH_CLIPY_0_CLIP7_MAX_GT 0x00000001 /* RWN-V */
2125#define NV_PGRAPH_CLIPY_0_CLIP7_MAX_EQ 0x00000002 /* RW--V */
2126#define NV_PGRAPH_CLIPY_1 0x00400530 /* RW-4R */
2127#define NV_PGRAPH_CLIPY_1_CLIP8_MIN 1:0 /* RWNVF */
2128#define NV_PGRAPH_CLIPY_1_CLIP8_MIN_GT 0x00000000 /* RW--V */
2129#define NV_PGRAPH_CLIPY_1_CLIP8_MIN_LT 0x00000001 /* RWN-V */
2130#define NV_PGRAPH_CLIPY_1_CLIP8_MIN_EQ 0x00000002 /* RW--V */
2131#define NV_PGRAPH_CLIPY_1_CLIP8_MAX 3:2 /* RWNVF */
2132#define NV_PGRAPH_CLIPY_1_CLIP8_MAX_LT 0x00000000 /* RW--V */
2133#define NV_PGRAPH_CLIPY_1_CLIP8_MAX_GT 0x00000001 /* RWN-V */
2134#define NV_PGRAPH_CLIPY_1_CLIP8_MAX_EQ 0x00000002 /* RW--V */
2135#define NV_PGRAPH_CLIPY_1_CLIP9_MIN 5:4 /* RWNVF */
2136#define NV_PGRAPH_CLIPY_1_CLIP9_MIN_GT 0x00000000 /* RW--V */
2137#define NV_PGRAPH_CLIPY_1_CLIP9_MIN_LT 0x00000001 /* RWN-V */
2138#define NV_PGRAPH_CLIPY_1_CLIP9_MIN_EQ 0x00000002 /* RW--V */
2139#define NV_PGRAPH_CLIPY_1_CLIP9_MAX 7:6 /* RWNVF */
2140#define NV_PGRAPH_CLIPY_1_CLIP9_MAX_LT 0x00000000 /* RW--V */
2141#define NV_PGRAPH_CLIPY_1_CLIP9_MAX_GT 0x00000001 /* RWN-V */
2142#define NV_PGRAPH_CLIPY_1_CLIP9_MAX_EQ 0x00000002 /* RW--V */
2143#define NV_PGRAPH_CLIPY_1_CLIP10_MIN 9:8 /* RWNVF */
2144#define NV_PGRAPH_CLIPY_1_CLIP10_MIN_GT 0x00000000 /* RW--V */
2145#define NV_PGRAPH_CLIPY_1_CLIP10_MIN_LT 0x00000001 /* RWN-V */
2146#define NV_PGRAPH_CLIPY_1_CLIP10_MIN_EQ 0x00000002 /* RW--V */
2147#define NV_PGRAPH_CLIPY_1_CLIP10_MAX 11:10 /* RWNVF */
2148#define NV_PGRAPH_CLIPY_1_CLIP10_MAX_LT 0x00000000 /* RW--V */
2149#define NV_PGRAPH_CLIPY_1_CLIP10_MAX_GT 0x00000001 /* RWN-V */
2150#define NV_PGRAPH_CLIPY_1_CLIP10_MAX_EQ 0x00000002 /* RW--V */
2151#define NV_PGRAPH_CLIPY_1_CLIP11_MIN 13:12 /* RWNVF */
2152#define NV_PGRAPH_CLIPY_1_CLIP11_MIN_GT 0x00000000 /* RW--V */
2153#define NV_PGRAPH_CLIPY_1_CLIP11_MIN_LT 0x00000001 /* RWN-V */
2154#define NV_PGRAPH_CLIPY_1_CLIP11MIN_EQ 0x00000002 /* RW--V */
2155#define NV_PGRAPH_CLIPY_1_CLIP11_MAX 15:14 /* RWNVF */
2156#define NV_PGRAPH_CLIPY_1_CLIP11_MAX_LT 0x00000000 /* RW--V */
2157#define NV_PGRAPH_CLIPY_1_CLIP11_MAX_GT 0x00000001 /* RWN-V */
2158#define NV_PGRAPH_CLIPY_1_CLIP11_MAX_EQ 0x00000002 /* RW--V */
2159#define NV_PGRAPH_CLIPY_1_CLIP12_MIN 17:16 /* RWNVF */
2160#define NV_PGRAPH_CLIPY_1_CLIP12_MIN_GT 0x00000000 /* RW--V */
2161#define NV_PGRAPH_CLIPY_1_CLIP12_MIN_LT 0x00000001 /* RWN-V */
2162#define NV_PGRAPH_CLIPY_1_CLIP12_MIN_EQ 0x00000002 /* RW--V */
2163#define NV_PGRAPH_CLIPY_1_CLIP12_MAX 19:18 /* RWNVF */
2164#define NV_PGRAPH_CLIPY_1_CLIP12_MAX_LT 0x00000000 /* RW--V */
2165#define NV_PGRAPH_CLIPY_1_CLIP12_MAX_GT 0x00000001 /* RWN-V */
2166#define NV_PGRAPH_CLIPY_1_CLIP12_MAX_EQ 0x00000002 /* RW--V */
2167#define NV_PGRAPH_CLIPY_1_CLIP13_MIN 21:20 /* RWNVF */
2168#define NV_PGRAPH_CLIPY_1_CLIP13_MIN_GT 0x00000000 /* RW--V */
2169#define NV_PGRAPH_CLIPY_1_CLIP13_MIN_LT 0x00000001 /* RWN-V */
2170#define NV_PGRAPH_CLIPY_1_CLIP13_MIN_EQ 0x00000002 /* RW--V */
2171#define NV_PGRAPH_CLIPY_1_CLIP13_MAX 23:22 /* RWNVF */
2172#define NV_PGRAPH_CLIPY_1_CLIP13_MAX_LT 0x00000000 /* RW--V */
2173#define NV_PGRAPH_CLIPY_1_CLIP13_MAX_GT 0x00000001 /* RWN-V */
2174#define NV_PGRAPH_CLIPY_1_CLIP13_MAX_EQ 0x00000002 /* RW--V */
2175#define NV_PGRAPH_CLIPY_1_CLIP14_MIN 25:24 /* RWNVF */
2176#define NV_PGRAPH_CLIPY_1_CLIP14_MIN_GT 0x00000000 /* RW--V */
2177#define NV_PGRAPH_CLIPY_1_CLIP14_MIN_LT 0x00000001 /* RWN-V */
2178#define NV_PGRAPH_CLIPY_1_CLIP14_MIN_EQ 0x00000002 /* RW--V */
2179#define NV_PGRAPH_CLIPY_1_CLIP14_MAX 27:26 /* RWNVF */
2180#define NV_PGRAPH_CLIPY_1_CLIP14_MAX_LT 0x00000000 /* RW--V */
2181#define NV_PGRAPH_CLIPY_1_CLIP14_MAX_GT 0x00000001 /* RWN-V */
2182#define NV_PGRAPH_CLIPY_1_CLIP14_MAX_EQ 0x00000002 /* RW--V */
2183#define NV_PGRAPH_CLIPY_1_CLIP15_MIN 29:28 /* RWNVF */
2184#define NV_PGRAPH_CLIPY_1_CLIP15_MIN_GT 0x00000000 /* RW--V */
2185#define NV_PGRAPH_CLIPY_1_CLIP15_MIN_LT 0x00000001 /* RWN-V */
2186#define NV_PGRAPH_CLIPY_1_CLIP15_MIN_EQ 0x00000002 /* RW--V */
2187#define NV_PGRAPH_CLIPY_1_CLIP15_MAX 31:30 /* RWNVF */
2188#define NV_PGRAPH_CLIPY_1_CLIP15_MAX_LT 0x00000000 /* RW--V */
2189#define NV_PGRAPH_CLIPY_1_CLIP15_MAX_GT 0x00000001 /* RWN-V */
2190#define NV_PGRAPH_CLIPY_1_CLIP15_MAX_EQ 0x00000002 /* RW--V */
2191#define NV_PGRAPH_MISC24_0 0x00400510 /* RW-4R */
2192#define NV_PGRAPH_MISC24_0_VALUE 23:0 /* RWXUF */
2193#define NV_PGRAPH_MISC24_1 0x00400570 /* RW-4R */
2194#define NV_PGRAPH_MISC24_1_VALUE 23:0 /* RWXUF */
2195#define NV_PGRAPH_MISC24_2 0x00400574 /* RW-4R */
2196#define NV_PGRAPH_MISC24_2_VALUE 23:0 /* RWXUF */
2197#define NV_PGRAPH_PASSTHRU_0 0x0040057C /* RW-4R */
2198#define NV_PGRAPH_PASSTHRU_0_VALUE 31:0 /* RWXUF */
2199#define NV_PGRAPH_PASSTHRU_1 0x00400580 /* RW-4R */
2200#define NV_PGRAPH_PASSTHRU_1_VALUE 31:0 /* RWXUF */
2201#define NV_PGRAPH_PASSTHRU_2 0x00400584 /* RW-4R */
2202#define NV_PGRAPH_PASSTHRU_2_VALUE 31:0 /* RWXUF */
2203#define NV_PGRAPH_U_RAM(i) (0x00400d00+(i)*4) /* RW-4A */
2204#define NV_PGRAPH_U_RAM__SIZE_1 16 /* */
2205#define NV_PGRAPH_U_RAM_VALUE 31:6 /* RWXFF */
2206#define NV_PGRAPH_V_RAM(i) (0x00400d40+(i)*4) /* RW-4A */
2207#define NV_PGRAPH_V_RAM__SIZE_1 16 /* */
2208#define NV_PGRAPH_V_RAM_VALUE 31:6 /* RWXFF */
2209#define NV_PGRAPH_M_RAM(i) (0x00400d80+(i)*4) /* RW-4A */
2210#define NV_PGRAPH_M_RAM__SIZE_1 16 /* */
2211#define NV_PGRAPH_M_RAM_VALUE 31:6 /* RWXFF */
2212#define NV_PGRAPH_DMA_START_0 0x00401000 /* RW-4R */
2213#define NV_PGRAPH_DMA_START_0_VALUE 31:0 /* RWXUF */
2214#define NV_PGRAPH_DMA_START_1 0x00401004 /* RW-4R */
2215#define NV_PGRAPH_DMA_START_1_VALUE 31:0 /* RWXUF */
2216#define NV_PGRAPH_DMA_LENGTH 0x00401008 /* RW-4R */
2217#define NV_PGRAPH_DMA_LENGTH_VALUE 21:0 /* RWXUF */
2218#define NV_PGRAPH_DMA_MISC 0x0040100C /* RW-4R */
2219#define NV_PGRAPH_DMA_MISC_COUNT 15:0 /* RWXUF */
2220#define NV_PGRAPH_DMA_MISC_FMT_SRC 18:16 /* RWXVF */
2221#define NV_PGRAPH_DMA_MISC_FMT_DST 22:20 /* RWXVF */
2222#define NV_PGRAPH_DMA_DATA_0 0x00401020 /* RW-4R */
2223#define NV_PGRAPH_DMA_DATA_0_VALUE 31:0 /* RWXUF */
2224#define NV_PGRAPH_DMA_DATA_1 0x00401024 /* RW-4R */
2225#define NV_PGRAPH_DMA_DATA_1_VALUE 31:0 /* RWXUF */
2226#define NV_PGRAPH_DMA_RM 0x00401030 /* RW-4R */
2227#define NV_PGRAPH_DMA_RM_ASSIST_A 0:0 /* RWIVF */
2228#define NV_PGRAPH_DMA_RM_ASSIST_A_NOT_PENDING 0x00000000 /* R-I-V */
2229#define NV_PGRAPH_DMA_RM_ASSIST_A_PENDING 0x00000001 /* R---V */
2230#define NV_PGRAPH_DMA_RM_ASSIST_A_RESET 0x00000001 /* -W--C */
2231#define NV_PGRAPH_DMA_RM_ASSIST_B 1:1 /* RWIVF */
2232#define NV_PGRAPH_DMA_RM_ASSIST_B_NOT_PENDING 0x00000000 /* R-I-V */
2233#define NV_PGRAPH_DMA_RM_ASSIST_B_PENDING 0x00000001 /* R---V */
2234#define NV_PGRAPH_DMA_RM_ASSIST_B_RESET 0x00000001 /* -W--C */
2235#define NV_PGRAPH_DMA_RM_WRITE_REQ 4:4 /* CWIVF */
2236#define NV_PGRAPH_DMA_RM_WRITE_REQ_NOT_PENDING 0x00000000 /* CWI-V */
2237#define NV_PGRAPH_DMA_RM_WRITE_REQ_PENDING 0x00000001 /* -W--T */
2238#define NV_PGRAPH_DMA_A_XLATE_INST 0x00401040 /* RW-4R */
2239#define NV_PGRAPH_DMA_A_XLATE_INST_VALUE 15:0 /* RWXUF */
2240#define NV_PGRAPH_DMA_A_CONTROL 0x00401044 /* RW-4R */
2241#define NV_PGRAPH_DMA_A_CONTROL_PAGE_TABLE 12:12 /* RWIVF */
2242#define NV_PGRAPH_DMA_A_CONTROL_PAGE_TABLE_NOT_PRESENT 0x00000000 /* RWI-V */
2243#define NV_PGRAPH_DMA_A_CONTROL_PAGE_TABLE_PRESENT 0x00000001 /* RW--V */
2244#define NV_PGRAPH_DMA_A_CONTROL_PAGE_ENTRY 13:13 /* RWXVF */
2245#define NV_PGRAPH_DMA_A_CONTROL_PAGE_ENTRY_NOT_LINEAR 0x00000000 /* RW--V */
2246#define NV_PGRAPH_DMA_A_CONTROL_PAGE_ENTRY_LINEAR 0x00000001 /* RW--V */
2247#define NV_PGRAPH_DMA_A_CONTROL_TARGET_NODE 17:16 /* RWXUF */
2248#define NV_PGRAPH_DMA_A_CONTROL_TARGET_NODE_NVM 0x00000000 /* RW--V */
2249#define NV_PGRAPH_DMA_A_CONTROL_TARGET_NODE_PCI 0x00000002 /* RW--V */
2250#define NV_PGRAPH_DMA_A_CONTROL_TARGET_NODE_AGP 0x00000003 /* RW--V */
2251#define NV_PGRAPH_DMA_A_CONTROL_ADJUST 31:20 /* RWXUF */
2252#define NV_PGRAPH_DMA_A_LIMIT 0x00401048 /* RW-4R */
2253#define NV_PGRAPH_DMA_A_LIMIT_OFFSET 31:0 /* RWXUF */
2254#define NV_PGRAPH_DMA_A_TLB_PTE 0x0040104C /* RW-4R */
2255#define NV_PGRAPH_DMA_A_TLB_PTE_ACCESS 1:1 /* RWXVF */
2256#define NV_PGRAPH_DMA_A_TLB_PTE_ACCESS_READ_ONLY 0x00000000 /* RW--V */
2257#define NV_PGRAPH_DMA_A_TLB_PTE_ACCESS_READ_WRITE 0x00000001 /* RW--V */
2258#define NV_PGRAPH_DMA_A_TLB_PTE_FRAME_ADDRESS 31:12 /* RWXUF */
2259#define NV_PGRAPH_DMA_A_TLB_TAG 0x00401050 /* RW-4R */
2260#define NV_PGRAPH_DMA_A_TLB_TAG_ADDRESS 31:12 /* RWXUF */
2261#define NV_PGRAPH_DMA_A_ADJ_OFFSET 0x00401054 /* RW-4R */
2262#define NV_PGRAPH_DMA_A_ADJ_OFFSET_VALUE 31:0 /* RWXUF */
2263#define NV_PGRAPH_DMA_A_OFFSET 0x00401058 /* RW-4R */
2264#define NV_PGRAPH_DMA_A_OFFSET_VALUE 31:0 /* RWXUF */
2265#define NV_PGRAPH_DMA_A_SIZE 0x0040105C /* RW-4R */
2266#define NV_PGRAPH_DMA_A_SIZE_VALUE 24:0 /* RWXUF */
2267#define NV_PGRAPH_DMA_A_Y_SIZE 0x00401060 /* RW-4R */
2268#define NV_PGRAPH_DMA_A_Y_SIZE_VALUE 10:0 /* RWXUF */
2269#define NV_PGRAPH_DMA_B_XLATE_INST 0x00401080 /* RW-4R */
2270#define NV_PGRAPH_DMA_B_XLATE_INST_VALUE 15:0 /* RWXUF */
2271#define NV_PGRAPH_DMA_B_CONTROL 0x00401084 /* RW-4R */
2272#define NV_PGRAPH_DMA_B_CONTROL_PAGE_TABLE 12:12 /* RWIVF */
2273#define NV_PGRAPH_DMA_B_CONTROL_PAGE_TABLE_NOT_PRESENT 0x00000000 /* RWI-V */
2274#define NV_PGRAPH_DMA_B_CONTROL_PAGE_TABLE_PRESENT 0x00000001 /* RW--V */
2275#define NV_PGRAPH_DMA_B_CONTROL_PAGE_ENTRY 13:13 /* RWXVF */
2276#define NV_PGRAPH_DMA_B_CONTROL_PAGE_ENTRY_NOT_LINEAR 0x00000000 /* RW--V */
2277#define NV_PGRAPH_DMA_B_CONTROL_PAGE_ENTRY_LINEAR 0x00000001 /* RW--V */
2278#define NV_PGRAPH_DMA_B_CONTROL_TARGET_NODE 17:16 /* RWXUF */
2279#define NV_PGRAPH_DMA_B_CONTROL_TARGET_NODE_NVM 0x00000000 /* RW--V */
2280#define NV_PGRAPH_DMA_B_CONTROL_TARGET_NODE_PCI 0x00000002 /* RW--V */
2281#define NV_PGRAPH_DMA_B_CONTROL_TARGET_NODE_AGP 0x00000003 /* RW--V */
2282#define NV_PGRAPH_DMA_B_CONTROL_ADJUST 31:20 /* RWXUF */
2283#define NV_PGRAPH_DMA_B_LIMIT 0x00401088 /* RW-4R */
2284#define NV_PGRAPH_DMA_B_LIMIT_OFFSET 31:0 /* RWXUF */
2285#define NV_PGRAPH_DMA_B_TLB_PTE 0x0040108C /* RW-4R */
2286#define NV_PGRAPH_DMA_B_TLB_PTE_ACCESS 1:1 /* RWXVF */
2287#define NV_PGRAPH_DMA_B_TLB_PTE_ACCESS_READ_ONLY 0x00000000 /* RW--V */
2288#define NV_PGRAPH_DMA_B_TLB_PTE_ACCESS_READ_WRITE 0x00000001 /* RW--V */
2289#define NV_PGRAPH_DMA_B_TLB_PTE_FRAME_ADDRESS 31:12 /* RWXUF */
2290#define NV_PGRAPH_DMA_B_TLB_TAG 0x00401090 /* RW-4R */
2291#define NV_PGRAPH_DMA_B_TLB_TAG_ADDRESS 31:12 /* RWXUF */
2292#define NV_PGRAPH_DMA_B_ADJ_OFFSET 0x00401094 /* RW-4R */
2293#define NV_PGRAPH_DMA_B_ADJ_OFFSET_VALUE 31:0 /* RWXUF */
2294#define NV_PGRAPH_DMA_B_OFFSET 0x00401098 /* RW-4R */
2295#define NV_PGRAPH_DMA_B_OFFSET_VALUE 31:0 /* RWXUF */
2296#define NV_PGRAPH_DMA_B_SIZE 0x0040109C /* RW-4R */
2297#define NV_PGRAPH_DMA_B_SIZE_VALUE 24:0 /* RWXUF */
2298#define NV_PGRAPH_DMA_B_Y_SIZE 0x004010A0 /* RW-4R */
2299#define NV_PGRAPH_DMA_B_Y_SIZE_VALUE 10:0 /* RWXUF */
2300
2301/* Framebuffer registers */
2302#define NV_PFB 0x00100FFF:0x00100000 /* RW--D */
2303#define NV_PFB_BOOT_0 0x00100000 /* RW-4R */
2304#define NV_PFB_BOOT_0_RAM_AMOUNT 1:0 /* RW-VF */
2305#define NV_PFB_BOOT_0_RAM_AMOUNT_32MB 0x00000000 /* RW--V */
2306#define NV_PFB_BOOT_0_RAM_AMOUNT_4MB 0x00000001 /* RW--V */
2307#define NV_PFB_BOOT_0_RAM_AMOUNT_8MB 0x00000002 /* RW--V */
2308#define NV_PFB_BOOT_0_RAM_AMOUNT_16MB 0x00000003 /* RW--V */
2309#define NV_PFB_BOOT_0_RAM_WIDTH_128 2:2 /* RW-VF */
2310#define NV_PFB_BOOT_0_RAM_WIDTH_128_OFF 0x00000000 /* RW--V */
2311#define NV_PFB_BOOT_0_RAM_WIDTH_128_ON 0x00000001 /* RW--V */
2312#define NV_PFB_BOOT_0_RAM_TYPE 4:3 /* RW-VF */
2313#define NV_PFB_BOOT_0_RAM_TYPE_256K 0x00000000 /* RW--V */
2314#define NV_PFB_BOOT_0_RAM_TYPE_512K_2BANK 0x00000001 /* RW--V */
2315#define NV_PFB_BOOT_0_RAM_TYPE_512K_4BANK 0x00000002 /* RW--V */
2316#define NV_PFB_BOOT_0_RAM_TYPE_1024K_2BANK 0x00000003 /* RW--V */
2317#define NV_PFB_CONFIG_0 0x00100200 /* RW-4R */
2318#define NV_PFB_CONFIG_0_TYPE 14:0 /* RWIVF */
2319#define NV_PFB_CONFIG_0_TYPE_OLD1024_FIXED_8BPP 0x00000120 /* RW--V */
2320#define NV_PFB_CONFIG_0_TYPE_OLD1024_FIXED_16BPP 0x00000220 /* RW--V */
2321#define NV_PFB_CONFIG_0_TYPE_OLD1024_FIXED_32BPP 0x00000320 /* RW--V */
2322#define NV_PFB_CONFIG_0_TYPE_OLD1024_VAR_8BPP 0x00004120 /* RW--V */
2323#define NV_PFB_CONFIG_0_TYPE_OLD1024_VAR_16BPP 0x00004220 /* RW--V */
2324#define NV_PFB_CONFIG_0_TYPE_OLD1024_VAR_32BPP 0x00004320 /* RW--V */
2325#define NV_PFB_CONFIG_0_TYPE_TETRIS 0x00002000 /* RW--V */
2326#define NV_PFB_CONFIG_0_TYPE_NOTILING 0x00001114 /* RWI-V */
2327#define NV_PFB_CONFIG_0_TETRIS_MODE 17:15 /* RWI-F */
2328#define NV_PFB_CONFIG_0_TETRIS_MODE_PASS 0x00000000 /* RWI-V */
2329#define NV_PFB_CONFIG_0_TETRIS_MODE_1 0x00000001 /* RW--V */
2330#define NV_PFB_CONFIG_0_TETRIS_MODE_2 0x00000002 /* RW--V */
2331#define NV_PFB_CONFIG_0_TETRIS_MODE_3 0x00000003 /* RW--V */
2332#define NV_PFB_CONFIG_0_TETRIS_MODE_4 0x00000004 /* RW--V */
2333#define NV_PFB_CONFIG_0_TETRIS_MODE_5 0x00000005 /* RW--V */
2334#define NV_PFB_CONFIG_0_TETRIS_MODE_6 0x00000006 /* RW--V */
2335#define NV_PFB_CONFIG_0_TETRIS_MODE_7 0x00000007 /* RW--V */
2336#define NV_PFB_CONFIG_0_TETRIS_SHIFT 19:18 /* RWI-F */
2337#define NV_PFB_CONFIG_0_TETRIS_SHIFT_0 0x00000000 /* RWI-V */
2338#define NV_PFB_CONFIG_0_TETRIS_SHIFT_1 0x00000001 /* RW--V */
2339#define NV_PFB_CONFIG_0_TETRIS_SHIFT_2 0x00000002 /* RW--V */
2340#define NV_PFB_CONFIG_0_BANK_SWAP 22:20 /* RWI-F */
2341#define NV_PFB_CONFIG_0_BANK_SWAP_OFF 0x00000000 /* RWI-V */
2342#define NV_PFB_CONFIG_0_BANK_SWAP_1M 0x00000001 /* RW--V */
2343#define NV_PFB_CONFIG_0_BANK_SWAP_2M 0x00000005 /* RW--V */
2344#define NV_PFB_CONFIG_0_BANK_SWAP_4M 0x00000007 /* RW--V */
2345#define NV_PFB_CONFIG_0_UNUSED 23:23 /* RW-VF */
2346#define NV_PFB_CONFIG_0_SCRAMBLE_EN 29:29 /* RWIVF */
2347#define NV_PFB_CONFIG_0_SCRAMBLE_EN_INIT 0x00000000 /* RW--V */
2348#define NV_PFB_CONFIG_0_SCRAMBLE_ACTIVE 0x00000001 /* RW--V */
2349#define NV_PFB_CONFIG_0_PRAMIN_WR 28:28 /* RWIVF */
2350#define NV_PFB_CONFIG_0_PRAMIN_WR_INIT 0x00000000 /* RW--V */
2351#define NV_PFB_CONFIG_0_PRAMIN_WR_DISABLED 0x00000001 /* RW--V */
2352#define NV_PFB_CONFIG_0_PRAMIN_WR_MASK 27:24 /* RWIVF */
2353#define NV_PFB_CONFIG_0_PRAMIN_WR_MASK_INIT 0x00000000 /* RWI-V */
2354#define NV_PFB_CONFIG_0_PRAMIN_WR_MASK_CLEAR 0x0000000f /* RWI-V */
2355#define NV_PFB_CONFIG_1 0x00100204 /* RW-4R */
2356#define NV_PFB_RTL 0x00100300 /* RW-4R */
2357#define NV_PFB_RTL_H 0:0 /* RWIUF */
2358#define NV_PFB_RTL_H_DEFAULT 0x00000000 /* RWI-V */
2359#define NV_PFB_RTL_MC 1:1 /* RWIUF */
2360#define NV_PFB_RTL_MC_DEFAULT 0x00000000 /* RWI-V */
2361#define NV_PFB_RTL_V 2:2 /* RWIUF */
2362#define NV_PFB_RTL_V_DEFAULT 0x00000000 /* RWI-V */
2363#define NV_PFB_RTL_G 3:3 /* RWIUF */
2364#define NV_PFB_RTL_G_DEFAULT 0x00000000 /* RWI-V */
2365#define NV_PFB_RTL_GB 4:4 /* RWIUF */
2366#define NV_PFB_RTL_GB_DEFAULT 0x00000000 /* RWI-V */
2367#define NV_PFB_CONFIG_0_RESOLUTION 5:0 /* RWIVF */
2368#define NV_PFB_CONFIG_0_RESOLUTION_320_PIXELS 0x0000000a /* RW--V */
2369#define NV_PFB_CONFIG_0_RESOLUTION_400_PIXELS 0x0000000d /* RW--V */
2370#define NV_PFB_CONFIG_0_RESOLUTION_480_PIXELS 0x0000000f /* RW--V */
2371#define NV_PFB_CONFIG_0_RESOLUTION_512_PIXELS 0x00000010 /* RW--V */
2372#define NV_PFB_CONFIG_0_RESOLUTION_640_PIXELS 0x00000014 /* RW--V */
2373#define NV_PFB_CONFIG_0_RESOLUTION_800_PIXELS 0x00000019 /* RW--V */
2374#define NV_PFB_CONFIG_0_RESOLUTION_960_PIXELS 0x0000001e /* RW--V */
2375#define NV_PFB_CONFIG_0_RESOLUTION_1024_PIXELS 0x00000020 /* RW--V */
2376#define NV_PFB_CONFIG_0_RESOLUTION_1152_PIXELS 0x00000024 /* RW--V */
2377#define NV_PFB_CONFIG_0_RESOLUTION_1280_PIXELS 0x00000028 /* RW--V */
2378#define NV_PFB_CONFIG_0_RESOLUTION_1600_PIXELS 0x00000032 /* RW--V */
2379#define NV_PFB_CONFIG_0_RESOLUTION_DEFAULT 0x00000014 /* RWI-V */
2380#define NV_PFB_CONFIG_0_PIXEL_DEPTH 9:8 /* RWIVF */
2381#define NV_PFB_CONFIG_0_PIXEL_DEPTH_8_BITS 0x00000001 /* RW--V */
2382#define NV_PFB_CONFIG_0_PIXEL_DEPTH_16_BITS 0x00000002 /* RW--V */
2383#define NV_PFB_CONFIG_0_PIXEL_DEPTH_32_BITS 0x00000003 /* RW--V */
2384#define NV_PFB_CONFIG_0_PIXEL_DEPTH_DEFAULT 0x00000001 /* RWI-V */
2385#define NV_PFB_CONFIG_0_TILING 12:12 /* RWIVF */
2386#define NV_PFB_CONFIG_0_TILING_ENABLED 0x00000000 /* RW--V */
2387#define NV_PFB_CONFIG_0_TILING_DISABLED 0x00000001 /* RWI-V */
2388#define NV_PFB_CONFIG_1_SGRAM100 3:3 /* RWIVF */
2389#define NV_PFB_CONFIG_1_SGRAM100_ENABLED 0x00000000 /* RWI-V */
2390#define NV_PFB_CONFIG_1_SGRAM100_DISABLED 0x00000001 /* RW--V */
2391#define NV_PFB_DEBUG_0_CKE_ALWAYSON 29:29 /* RWIVF */
2392#define NV_PFB_DEBUG_0_CKE_ALWAYSON_OFF 0x00000000 /* RW--V */
2393#define NV_PFB_DEBUG_0_CKE_ALWAYSON_ON 0x00000001 /* RWI-V */
2394
2395#define NV_PEXTDEV 0x00101FFF:0x00101000 /* RW--D */
2396#define NV_PEXTDEV_BOOT_0 0x00101000 /* R--4R */
2397#define NV_PEXTDEV_BOOT_0_STRAP_BUS_SPEED 0:0 /* R-XVF */
2398#define NV_PEXTDEV_BOOT_0_STRAP_BUS_SPEED_33MHZ 0x00000000 /* R---V */
2399#define NV_PEXTDEV_BOOT_0_STRAP_BUS_SPEED_66MHZ 0x00000001 /* R---V */
2400#define NV_PEXTDEV_BOOT_0_STRAP_SUB_VENDOR 1:1 /* R-XVF */
2401#define NV_PEXTDEV_BOOT_0_STRAP_SUB_VENDOR_NO_BIOS 0x00000000 /* R---V */
2402#define NV_PEXTDEV_BOOT_0_STRAP_SUB_VENDOR_BIOS 0x00000001 /* R---V */
2403#define NV_PEXTDEV_BOOT_0_STRAP_RAM_TYPE 3:2 /* R-XVF */
2404#define NV_PEXTDEV_BOOT_0_STRAP_RAM_TYPE_SGRAM_256K 0x00000000 /* R---V */
2405#define NV_PEXTDEV_BOOT_0_STRAP_RAM_TYPE_SGRAM_512K_2BANK 0x00000001 /* R---V */
2406#define NV_PEXTDEV_BOOT_0_STRAP_RAM_TYPE_SGRAM_512K_4BANK 0x00000002 /* R---V */
2407#define NV_PEXTDEV_BOOT_0_STRAP_RAM_TYPE_1024K_2BANK 0x00000003 /* R---V */
2408#define NV_PEXTDEV_BOOT_0_STRAP_RAM_WIDTH 4:4 /* R-XVF */
2409#define NV_PEXTDEV_BOOT_0_STRAP_RAM_WIDTH_64 0x00000000 /* R---V */
2410#define NV_PEXTDEV_BOOT_0_STRAP_RAM_WIDTH_128 0x00000001 /* R---V */
2411#define NV_PEXTDEV_BOOT_0_STRAP_BUS_TYPE 5:5 /* R-XVF */
2412#define NV_PEXTDEV_BOOT_0_STRAP_BUS_TYPE_PCI 0x00000000 /* R---V */
2413#define NV_PEXTDEV_BOOT_0_STRAP_BUS_TYPE_AGP 0x00000001 /* R---V */
2414#define NV_PEXTDEV_BOOT_0_STRAP_CRYSTAL 6:6 /* R-XVF */
2415#define NV_PEXTDEV_BOOT_0_STRAP_CRYSTAL_13500K 0x00000000 /* R---V */
2416#define NV_PEXTDEV_BOOT_0_STRAP_CRYSTAL_14318180 0x00000001 /* R---V */
2417#define NV_PEXTDEV_BOOT_0_STRAP_TVMODE 8:7 /* R-XVF */
2418#define NV_PEXTDEV_BOOT_0_STRAP_TVMODE_SECAM 0x00000000 /* R---V */
2419#define NV_PEXTDEV_BOOT_0_STRAP_TVMODE_NTSC 0x00000001 /* R---V */
2420#define NV_PEXTDEV_BOOT_0_STRAP_TVMODE_PAL 0x00000002 /* R---V */
2421#define NV_PEXTDEV_BOOT_0_STRAP_TVMODE_DISABLED 0x00000003 /* R---V */
2422#define NV_PEXTDEV_BOOT_0_STRAP_OVERWRITE 11:11 /* RWIVF */
2423#define NV_PEXTDEV_BOOT_0_STRAP_OVERWRITE_DISABLED 0x00000000 /* RWI-V */
2424#define NV_PEXTDEV_BOOT_0_STRAP_OVERWRITE_ENABLED 0x00000001 /* RW--V */
2425
2426/* Extras */
2427#define NV_PRAMIN 0x007FFFFF:0x00700000 /* RW--M */
2428/*#define NV_PRAMIN 0x00FFFFFF:0x00C00000*/
2429#define NV_PNVM 0x01FFFFFF:0x01000000 /* RW--M */
2430/*#define NV_PNVM 0x00BFFFFF:0x00800000*/
2431#define NV_CHAN0 0x0080ffff:0x00800000
2432
2433/* FIFO subchannels */
2434#define NV_UROP 0x43
2435#define NV_UCHROMA 0x57
2436#define NV_UCLIP 0x19
2437#define NV_UPATT 0x18
2438#define NV_ULIN 0x5C
2439#define NV_UTRI 0x5D
2440#define NV_URECT 0x5E
2441#define NV_UBLIT 0x5F
2442#define NV_UGLYPH 0x4B
2443
2444#endif /*__NV4REF_H__*/
2445
diff --git a/drivers/video/riva/nv_driver.c b/drivers/video/riva/nv_driver.c
index be630a0ccfd4..a11026812d1b 100644
--- a/drivers/video/riva/nv_driver.c
+++ b/drivers/video/riva/nv_driver.c
@@ -231,12 +231,14 @@ unsigned long riva_get_memlen(struct riva_par *par)
231 case NV_ARCH_30: 231 case NV_ARCH_30:
232 if(chipset == NV_CHIP_IGEFORCE2) { 232 if(chipset == NV_CHIP_IGEFORCE2) {
233 233
234 dev = pci_find_slot(0, 1); 234 dev = pci_get_bus_and_slot(0, 1);
235 pci_read_config_dword(dev, 0x7C, &amt); 235 pci_read_config_dword(dev, 0x7C, &amt);
236 pci_dev_put(dev);
236 memlen = (((amt >> 6) & 31) + 1) * 1024; 237 memlen = (((amt >> 6) & 31) + 1) * 1024;
237 } else if (chipset == NV_CHIP_0x01F0) { 238 } else if (chipset == NV_CHIP_0x01F0) {
238 dev = pci_find_slot(0, 1); 239 dev = pci_get_bus_and_slot(0, 1);
239 pci_read_config_dword(dev, 0x84, &amt); 240 pci_read_config_dword(dev, 0x84, &amt);
241 pci_dev_put(dev);
240 memlen = (((amt >> 4) & 127) + 1) * 1024; 242 memlen = (((amt >> 4) & 127) + 1) * 1024;
241 } else { 243 } else {
242 switch ((NV_RD32(chip->PFB, 0x0000020C) >> 20) & 244 switch ((NV_RD32(chip->PFB, 0x0000020C) >> 20) &
diff --git a/drivers/video/riva/riva_hw.c b/drivers/video/riva/riva_hw.c
index e0b8c521cc9c..70bfd78eca81 100644
--- a/drivers/video/riva/riva_hw.c
+++ b/drivers/video/riva/riva_hw.c
@@ -1118,8 +1118,9 @@ static void nForceUpdateArbitrationSettings
1118 unsigned int uMClkPostDiv; 1118 unsigned int uMClkPostDiv;
1119 struct pci_dev *dev; 1119 struct pci_dev *dev;
1120 1120
1121 dev = pci_find_slot(0, 3); 1121 dev = pci_get_bus_and_slot(0, 3);
1122 pci_read_config_dword(dev, 0x6C, &uMClkPostDiv); 1122 pci_read_config_dword(dev, 0x6C, &uMClkPostDiv);
1123 pci_dev_put(dev);
1123 uMClkPostDiv = (uMClkPostDiv >> 8) & 0xf; 1124 uMClkPostDiv = (uMClkPostDiv >> 8) & 0xf;
1124 1125
1125 if(!uMClkPostDiv) uMClkPostDiv = 4; 1126 if(!uMClkPostDiv) uMClkPostDiv = 4;
@@ -1132,8 +1133,9 @@ static void nForceUpdateArbitrationSettings
1132 sim_data.enable_video = 0; 1133 sim_data.enable_video = 0;
1133 sim_data.enable_mp = 0; 1134 sim_data.enable_mp = 0;
1134 1135
1135 dev = pci_find_slot(0, 1); 1136 dev = pci_get_bus_and_slot(0, 1);
1136 pci_read_config_dword(dev, 0x7C, &sim_data.memory_type); 1137 pci_read_config_dword(dev, 0x7C, &sim_data.memory_type);
1138 pci_dev_put(dev);
1137 sim_data.memory_type = (sim_data.memory_type >> 12) & 1; 1139 sim_data.memory_type = (sim_data.memory_type >> 12) & 1;
1138 1140
1139 sim_data.memory_width = 64; 1141 sim_data.memory_width = 64;
@@ -2112,12 +2114,14 @@ static void nv10GetConfig
2112 * Fill in chip configuration. 2114 * Fill in chip configuration.
2113 */ 2115 */
2114 if(chipset == NV_CHIP_IGEFORCE2) { 2116 if(chipset == NV_CHIP_IGEFORCE2) {
2115 dev = pci_find_slot(0, 1); 2117 dev = pci_get_bus_and_slot(0, 1);
2116 pci_read_config_dword(dev, 0x7C, &amt); 2118 pci_read_config_dword(dev, 0x7C, &amt);
2119 pci_dev_put(dev);
2117 chip->RamAmountKBytes = (((amt >> 6) & 31) + 1) * 1024; 2120 chip->RamAmountKBytes = (((amt >> 6) & 31) + 1) * 1024;
2118 } else if(chipset == NV_CHIP_0x01F0) { 2121 } else if(chipset == NV_CHIP_0x01F0) {
2119 dev = pci_find_slot(0, 1); 2122 dev = pci_get_bus_and_slot(0, 1);
2120 pci_read_config_dword(dev, 0x84, &amt); 2123 pci_read_config_dword(dev, 0x84, &amt);
2124 pci_dev_put(dev);
2121 chip->RamAmountKBytes = (((amt >> 4) & 127) + 1) * 1024; 2125 chip->RamAmountKBytes = (((amt >> 4) & 127) + 1) * 1024;
2122 } else { 2126 } else {
2123 switch ((NV_RD32(chip->PFB, 0x0000020C) >> 20) & 0x000000FF) 2127 switch ((NV_RD32(chip->PFB, 0x0000020C) >> 20) & 0x000000FF)
diff --git a/drivers/video/riva/rivafb-i2c.c b/drivers/video/riva/rivafb-i2c.c
index 0405e839ff93..a0e22ac483a3 100644
--- a/drivers/video/riva/rivafb-i2c.c
+++ b/drivers/video/riva/rivafb-i2c.c
@@ -70,8 +70,6 @@ static int riva_gpio_getscl(void* data)
70 if (VGA_RD08(par->riva.PCIO, 0x3d5) & 0x04) 70 if (VGA_RD08(par->riva.PCIO, 0x3d5) & 0x04)
71 val = 1; 71 val = 1;
72 72
73 val = VGA_RD08(par->riva.PCIO, 0x3d5);
74
75 return val; 73 return val;
76} 74}
77 75
@@ -88,13 +86,16 @@ static int riva_gpio_getsda(void* data)
88 return val; 86 return val;
89} 87}
90 88
91static int riva_setup_i2c_bus(struct riva_i2c_chan *chan, const char *name) 89static int __devinit riva_setup_i2c_bus(struct riva_i2c_chan *chan,
90 const char *name,
91 unsigned int i2c_class)
92{ 92{
93 int rc; 93 int rc;
94 94
95 strcpy(chan->adapter.name, name); 95 strcpy(chan->adapter.name, name);
96 chan->adapter.owner = THIS_MODULE; 96 chan->adapter.owner = THIS_MODULE;
97 chan->adapter.id = I2C_HW_B_RIVA; 97 chan->adapter.id = I2C_HW_B_RIVA;
98 chan->adapter.class = i2c_class;
98 chan->adapter.algo_data = &chan->algo; 99 chan->adapter.algo_data = &chan->algo;
99 chan->adapter.dev.parent = &chan->par->pdev->dev; 100 chan->adapter.dev.parent = &chan->par->pdev->dev;
100 chan->algo.setsda = riva_gpio_setsda; 101 chan->algo.setsda = riva_gpio_setsda;
@@ -124,42 +125,38 @@ static int riva_setup_i2c_bus(struct riva_i2c_chan *chan, const char *name)
124 return rc; 125 return rc;
125} 126}
126 127
127void riva_create_i2c_busses(struct riva_par *par) 128void __devinit riva_create_i2c_busses(struct riva_par *par)
128{ 129{
129 par->bus = 3;
130
131 par->chan[0].par = par; 130 par->chan[0].par = par;
132 par->chan[1].par = par; 131 par->chan[1].par = par;
133 par->chan[2].par = par; 132 par->chan[2].par = par;
134 133
135 par->chan[0].ddc_base = 0x3e; 134 par->chan[0].ddc_base = 0x36;
136 par->chan[1].ddc_base = 0x36; 135 par->chan[1].ddc_base = 0x3e;
137 par->chan[2].ddc_base = 0x50; 136 par->chan[2].ddc_base = 0x50;
138 riva_setup_i2c_bus(&par->chan[0], "BUS1"); 137 riva_setup_i2c_bus(&par->chan[0], "BUS1", I2C_CLASS_HWMON);
139 riva_setup_i2c_bus(&par->chan[1], "BUS2"); 138 riva_setup_i2c_bus(&par->chan[1], "BUS2", 0);
140 riva_setup_i2c_bus(&par->chan[2], "BUS3"); 139 riva_setup_i2c_bus(&par->chan[2], "BUS3", 0);
141} 140}
142 141
143void riva_delete_i2c_busses(struct riva_par *par) 142void riva_delete_i2c_busses(struct riva_par *par)
144{ 143{
145 if (par->chan[0].par) 144 int i;
146 i2c_del_adapter(&par->chan[0].adapter);
147 par->chan[0].par = NULL;
148 145
149 if (par->chan[1].par) 146 for (i = 0; i < 3; i++) {
150 i2c_del_adapter(&par->chan[1].adapter); 147 if (!par->chan[i].par)
151 par->chan[1].par = NULL; 148 continue;
152 149 i2c_del_adapter(&par->chan[i].adapter);
153 if (par->chan[2].par) 150 par->chan[i].par = NULL;
154 i2c_del_adapter(&par->chan[2].adapter); 151 }
155 par->chan[2].par = NULL;
156} 152}
157 153
158int riva_probe_i2c_connector(struct riva_par *par, int conn, u8 **out_edid) 154int __devinit riva_probe_i2c_connector(struct riva_par *par, int conn, u8 **out_edid)
159{ 155{
160 u8 *edid = NULL; 156 u8 *edid = NULL;
161 157
162 edid = fb_ddc_read(&par->chan[conn-1].adapter); 158 if (par->chan[conn].par)
159 edid = fb_ddc_read(&par->chan[conn].adapter);
163 160
164 if (out_edid) 161 if (out_edid)
165 *out_edid = edid; 162 *out_edid = edid;
diff --git a/drivers/video/riva/rivafb.h b/drivers/video/riva/rivafb.h
index 48ead6d72f24..d9f107b704c6 100644
--- a/drivers/video/riva/rivafb.h
+++ b/drivers/video/riva/rivafb.h
@@ -4,7 +4,6 @@
4#include <linux/fb.h> 4#include <linux/fb.h>
5#include <video/vga.h> 5#include <video/vga.h>
6#include <linux/i2c.h> 6#include <linux/i2c.h>
7#include <linux/i2c-id.h>
8#include <linux/i2c-algo-bit.h> 7#include <linux/i2c-algo-bit.h>
9 8
10#include "riva_hw.h" 9#include "riva_hw.h"
@@ -61,7 +60,6 @@ struct riva_par {
61 Bool SecondCRTC; 60 Bool SecondCRTC;
62 int FlatPanel; 61 int FlatPanel;
63 struct pci_dev *pdev; 62 struct pci_dev *pdev;
64 int bus;
65 int cursor_reset; 63 int cursor_reset;
66#ifdef CONFIG_MTRR 64#ifdef CONFIG_MTRR
67 struct { int vram; int vram_valid; } mtrr; 65 struct { int vram; int vram_valid; } mtrr;
diff --git a/drivers/video/s3fb.c b/drivers/video/s3fb.c
index 3091b20124b4..d11735895a01 100644
--- a/drivers/video/s3fb.c
+++ b/drivers/video/s3fb.c
@@ -65,7 +65,7 @@ static const struct svga_fb_format s3fb_formats[] = {
65 65
66 66
67static const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3, 67static const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3,
68 60000, 240000, 14318}; 68 35000, 240000, 14318};
69 69
70static const int s3_memsizes[] = {4096, 0, 3072, 8192, 2048, 6144, 1024, 512}; 70static const int s3_memsizes[] = {4096, 0, 3072, 8192, 2048, 6144, 1024, 512};
71 71
@@ -164,7 +164,7 @@ MODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, defau
164static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map) 164static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map)
165{ 165{
166 const u8 *font = map->data; 166 const u8 *font = map->data;
167 u8* fb = (u8 *) info->screen_base; 167 u8 __iomem *fb = (u8 __iomem *) info->screen_base;
168 int i, c; 168 int i, c;
169 169
170 if ((map->width != 8) || (map->height != 16) || 170 if ((map->width != 8) || (map->height != 16) ||
@@ -177,20 +177,19 @@ static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map)
177 fb += 2; 177 fb += 2;
178 for (i = 0; i < map->height; i++) { 178 for (i = 0; i < map->height; i++) {
179 for (c = 0; c < map->length; c++) { 179 for (c = 0; c < map->length; c++) {
180 fb[c * 4] = font[c * map->height + i]; 180 fb_writeb(font[c * map->height + i], fb + c * 4);
181 } 181 }
182 fb += 1024; 182 fb += 1024;
183 } 183 }
184} 184}
185 185
186
187
188static struct fb_tile_ops s3fb_tile_ops = { 186static struct fb_tile_ops s3fb_tile_ops = {
189 .fb_settile = svga_settile, 187 .fb_settile = svga_settile,
190 .fb_tilecopy = svga_tilecopy, 188 .fb_tilecopy = svga_tilecopy,
191 .fb_tilefill = svga_tilefill, 189 .fb_tilefill = svga_tilefill,
192 .fb_tileblit = svga_tileblit, 190 .fb_tileblit = svga_tileblit,
193 .fb_tilecursor = svga_tilecursor, 191 .fb_tilecursor = svga_tilecursor,
192 .fb_get_tilemax = svga_get_tilemax,
194}; 193};
195 194
196static struct fb_tile_ops s3fb_fast_tile_ops = { 195static struct fb_tile_ops s3fb_fast_tile_ops = {
@@ -199,6 +198,7 @@ static struct fb_tile_ops s3fb_fast_tile_ops = {
199 .fb_tilefill = svga_tilefill, 198 .fb_tilefill = svga_tilefill,
200 .fb_tileblit = svga_tileblit, 199 .fb_tileblit = svga_tileblit,
201 .fb_tilecursor = svga_tilecursor, 200 .fb_tilecursor = svga_tilecursor,
201 .fb_get_tilemax = svga_get_tilemax,
202}; 202};
203 203
204 204
@@ -326,8 +326,13 @@ static void s3_set_pixclock(struct fb_info *info, u32 pixclock)
326{ 326{
327 u16 m, n, r; 327 u16 m, n, r;
328 u8 regval; 328 u8 regval;
329 int rv;
329 330
330 svga_compute_pll(&s3_pll, 1000000000 / pixclock, &m, &n, &r, info->node); 331 rv = svga_compute_pll(&s3_pll, 1000000000 / pixclock, &m, &n, &r, info->node);
332 if (rv < 0) {
333 printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
334 return;
335 }
331 336
332 /* Set VGA misc register */ 337 /* Set VGA misc register */
333 regval = vga_r(NULL, VGA_MIS_R); 338 regval = vga_r(NULL, VGA_MIS_R);
@@ -449,6 +454,10 @@ static int s3fb_set_par(struct fb_info *info)
449 info->flags &= ~FBINFO_MISC_TILEBLITTING; 454 info->flags &= ~FBINFO_MISC_TILEBLITTING;
450 info->tileops = NULL; 455 info->tileops = NULL;
451 456
457 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
458 info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
459 info->pixmap.blit_y = ~(u32)0;
460
452 offset_value = (info->var.xres_virtual * bpp) / 64; 461 offset_value = (info->var.xres_virtual * bpp) / 64;
453 screen_size = info->var.yres_virtual * info->fix.line_length; 462 screen_size = info->var.yres_virtual * info->fix.line_length;
454 } else { 463 } else {
@@ -458,6 +467,10 @@ static int s3fb_set_par(struct fb_info *info)
458 info->flags |= FBINFO_MISC_TILEBLITTING; 467 info->flags |= FBINFO_MISC_TILEBLITTING;
459 info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops; 468 info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
460 469
470 /* supports 8x16 tiles only */
471 info->pixmap.blit_x = 1 << (8 - 1);
472 info->pixmap.blit_y = 1 << (16 - 1);
473
461 offset_value = info->var.xres_virtual / 16; 474 offset_value = info->var.xres_virtual / 16;
462 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64; 475 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
463 } 476 }
@@ -656,7 +669,7 @@ static int s3fb_set_par(struct fb_info *info)
656 value = ((value * hmul) / 8) - 5; 669 value = ((value * hmul) / 8) - 5;
657 vga_wcrt(NULL, 0x3C, (value + 1) / 2); 670 vga_wcrt(NULL, 0x3C, (value + 1) / 2);
658 671
659 memset((u8*)info->screen_base, 0x00, screen_size); 672 memset_io(info->screen_base, 0x00, screen_size);
660 /* Device and screen back on */ 673 /* Device and screen back on */
661 svga_wcrt_mask(0x17, 0x80, 0x80); 674 svga_wcrt_mask(0x17, 0x80, 0x80);
662 svga_wseq_mask(0x01, 0x00, 0x20); 675 svga_wseq_mask(0x01, 0x00, 0x20);
@@ -699,7 +712,7 @@ static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
699 break; 712 break;
700 case 16: 713 case 16:
701 if (regno >= 16) 714 if (regno >= 16)
702 return -EINVAL; 715 return 0;
703 716
704 if (fb->var.green.length == 5) 717 if (fb->var.green.length == 5)
705 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) | 718 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
@@ -712,9 +725,9 @@ static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
712 case 24: 725 case 24:
713 case 32: 726 case 32:
714 if (regno >= 16) 727 if (regno >= 16)
715 return -EINVAL; 728 return 0;
716 729
717 ((u32*)fb->pseudo_palette)[regno] = ((transp & 0xFF00) << 16) | ((red & 0xFF00) << 8) | 730 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
718 (green & 0xFF00) | ((blue & 0xFF00) >> 8); 731 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
719 break; 732 break;
720 default: 733 default:
@@ -767,12 +780,6 @@ static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
767 780
768 unsigned int offset; 781 unsigned int offset;
769 782
770 /* Validate the offsets */
771 if ((var->xoffset + var->xres) > var->xres_virtual)
772 return -EINVAL;
773 if ((var->yoffset + var->yres) > var->yres_virtual)
774 return -EINVAL;
775
776 /* Calculate the offset */ 783 /* Calculate the offset */
777 if (var->bits_per_pixel == 0) { 784 if (var->bits_per_pixel == 0) {
778 offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2); 785 offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
@@ -805,6 +812,7 @@ static struct fb_ops s3fb_ops = {
805 .fb_fillrect = s3fb_fillrect, 812 .fb_fillrect = s3fb_fillrect,
806 .fb_copyarea = cfb_copyarea, 813 .fb_copyarea = cfb_copyarea,
807 .fb_imageblit = s3fb_imageblit, 814 .fb_imageblit = s3fb_imageblit,
815 .fb_get_caps = svga_get_caps,
808}; 816};
809 817
810/* ------------------------------------------------------------------------- */ 818/* ------------------------------------------------------------------------- */
@@ -1061,6 +1069,7 @@ static int s3_pci_resume(struct pci_dev* dev)
1061{ 1069{
1062 struct fb_info *info = pci_get_drvdata(dev); 1070 struct fb_info *info = pci_get_drvdata(dev);
1063 struct s3fb_info *par = info->par; 1071 struct s3fb_info *par = info->par;
1072 int err;
1064 1073
1065 dev_info(&(dev->dev), "resume\n"); 1074 dev_info(&(dev->dev), "resume\n");
1066 1075
@@ -1075,7 +1084,13 @@ static int s3_pci_resume(struct pci_dev* dev)
1075 1084
1076 pci_set_power_state(dev, PCI_D0); 1085 pci_set_power_state(dev, PCI_D0);
1077 pci_restore_state(dev); 1086 pci_restore_state(dev);
1078 pci_enable_device(dev); 1087 err = pci_enable_device(dev);
1088 if (err) {
1089 mutex_unlock(&(par->open_lock));
1090 release_console_sem();
1091 dev_err(&(dev->dev), "error %d enabling device for resume\n", err);
1092 return err;
1093 }
1079 pci_set_master(dev); 1094 pci_set_master(dev);
1080 1095
1081 s3fb_set_par(info); 1096 s3fb_set_par(info);
diff --git a/drivers/video/savage/savagefb-i2c.c b/drivers/video/savage/savagefb-i2c.c
index 8db066ccca6b..35c1ce62b216 100644
--- a/drivers/video/savage/savagefb-i2c.c
+++ b/drivers/video/savage/savagefb-i2c.c
@@ -41,10 +41,6 @@
41#define SAVAGE4_I2C_SCL_IN 0x00000008 41#define SAVAGE4_I2C_SCL_IN 0x00000008
42#define SAVAGE4_I2C_SDA_IN 0x00000010 42#define SAVAGE4_I2C_SDA_IN 0x00000010
43 43
44#define SET_CR_IX(base, val) writeb((val), base + 0x8000 + VGA_CR_IX)
45#define SET_CR_DATA(base, val) writeb((val), base + 0x8000 + VGA_CR_DATA)
46#define GET_CR_DATA(base) readb(base + 0x8000 + VGA_CR_DATA)
47
48static void savage4_gpio_setscl(void *data, int val) 44static void savage4_gpio_setscl(void *data, int val)
49{ 45{
50 struct savagefb_i2c_chan *chan = data; 46 struct savagefb_i2c_chan *chan = data;
@@ -92,15 +88,15 @@ static void prosavage_gpio_setscl(void* data, int val)
92 struct savagefb_i2c_chan *chan = data; 88 struct savagefb_i2c_chan *chan = data;
93 u32 r; 89 u32 r;
94 90
95 SET_CR_IX(chan->ioaddr, chan->reg); 91 r = VGArCR(chan->reg, chan->par);
96 r = GET_CR_DATA(chan->ioaddr);
97 r |= PROSAVAGE_I2C_ENAB; 92 r |= PROSAVAGE_I2C_ENAB;
98 if (val) { 93 if (val) {
99 r |= PROSAVAGE_I2C_SCL_OUT; 94 r |= PROSAVAGE_I2C_SCL_OUT;
100 } else { 95 } else {
101 r &= ~PROSAVAGE_I2C_SCL_OUT; 96 r &= ~PROSAVAGE_I2C_SCL_OUT;
102 } 97 }
103 SET_CR_DATA(chan->ioaddr, r); 98
99 VGAwCR(chan->reg, r, chan->par);
104} 100}
105 101
106static void prosavage_gpio_setsda(void* data, int val) 102static void prosavage_gpio_setsda(void* data, int val)
@@ -108,31 +104,29 @@ static void prosavage_gpio_setsda(void* data, int val)
108 struct savagefb_i2c_chan *chan = data; 104 struct savagefb_i2c_chan *chan = data;
109 unsigned int r; 105 unsigned int r;
110 106
111 SET_CR_IX(chan->ioaddr, chan->reg); 107 r = VGArCR(chan->reg, chan->par);
112 r = GET_CR_DATA(chan->ioaddr);
113 r |= PROSAVAGE_I2C_ENAB; 108 r |= PROSAVAGE_I2C_ENAB;
114 if (val) { 109 if (val) {
115 r |= PROSAVAGE_I2C_SDA_OUT; 110 r |= PROSAVAGE_I2C_SDA_OUT;
116 } else { 111 } else {
117 r &= ~PROSAVAGE_I2C_SDA_OUT; 112 r &= ~PROSAVAGE_I2C_SDA_OUT;
118 } 113 }
119 SET_CR_DATA(chan->ioaddr, r); 114
115 VGAwCR(chan->reg, r, chan->par);
120} 116}
121 117
122static int prosavage_gpio_getscl(void* data) 118static int prosavage_gpio_getscl(void* data)
123{ 119{
124 struct savagefb_i2c_chan *chan = data; 120 struct savagefb_i2c_chan *chan = data;
125 121
126 SET_CR_IX(chan->ioaddr, chan->reg); 122 return (VGArCR(chan->reg, chan->par) & PROSAVAGE_I2C_SCL_IN) ? 1 : 0;
127 return (0 != (GET_CR_DATA(chan->ioaddr) & PROSAVAGE_I2C_SCL_IN));
128} 123}
129 124
130static int prosavage_gpio_getsda(void* data) 125static int prosavage_gpio_getsda(void* data)
131{ 126{
132 struct savagefb_i2c_chan *chan = data; 127 struct savagefb_i2c_chan *chan = data;
133 128
134 SET_CR_IX(chan->ioaddr, chan->reg); 129 return (VGArCR(chan->reg, chan->par) & PROSAVAGE_I2C_SDA_IN) ? 1 : 0;
135 return (0 != (GET_CR_DATA(chan->ioaddr) & PROSAVAGE_I2C_SDA_IN));
136} 130}
137 131
138static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan, 132static int savage_setup_i2c_bus(struct savagefb_i2c_chan *chan,
diff --git a/drivers/video/savage/savagefb.h b/drivers/video/savage/savagefb.h
index e648a6c0f6d9..8bfdfc3c5234 100644
--- a/drivers/video/savage/savagefb.h
+++ b/drivers/video/savage/savagefb.h
@@ -15,6 +15,8 @@
15#include <linux/i2c.h> 15#include <linux/i2c.h>
16#include <linux/i2c-id.h> 16#include <linux/i2c-id.h>
17#include <linux/i2c-algo-bit.h> 17#include <linux/i2c-algo-bit.h>
18#include <linux/mutex.h>
19#include <video/vga.h>
18#include "../edid.h" 20#include "../edid.h"
19 21
20#ifdef SAVAGEFB_DEBUG 22#ifdef SAVAGEFB_DEBUG
@@ -189,8 +191,12 @@ struct savagefb_par {
189 struct savagefb_i2c_chan chan; 191 struct savagefb_i2c_chan chan;
190 struct savage_reg state; 192 struct savage_reg state;
191 struct savage_reg save; 193 struct savage_reg save;
194 struct savage_reg initial;
195 struct vgastate vgastate;
196 struct mutex open_lock;
192 unsigned char *edid; 197 unsigned char *edid;
193 u32 pseudo_palette[16]; 198 u32 pseudo_palette[16];
199 u32 open_count;
194 int paletteEnabled; 200 int paletteEnabled;
195 int pm_state; 201 int pm_state;
196 int display_type; 202 int display_type;
@@ -203,7 +209,7 @@ struct savagefb_par {
203 int clock[4]; 209 int clock[4];
204 int MCLK, REFCLK, LCDclk; 210 int MCLK, REFCLK, LCDclk;
205 struct { 211 struct {
206 u8 __iomem *vbase; 212 void __iomem *vbase;
207 u32 pbase; 213 u32 pbase;
208 u32 len; 214 u32 len;
209#ifdef CONFIG_MTRR 215#ifdef CONFIG_MTRR
@@ -212,7 +218,7 @@ struct savagefb_par {
212 } video; 218 } video;
213 219
214 struct { 220 struct {
215 volatile u8 __iomem *vbase; 221 void __iomem *vbase;
216 u32 pbase; 222 u32 pbase;
217 u32 len; 223 u32 len;
218 } mmio; 224 } mmio;
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index 0166ec2ccf32..3d7507ad55f6 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -1623,8 +1623,46 @@ static void savagefb_restore_state(struct fb_info *info)
1623 savagefb_blank(FB_BLANK_UNBLANK, info); 1623 savagefb_blank(FB_BLANK_UNBLANK, info);
1624} 1624}
1625 1625
1626static int savagefb_open(struct fb_info *info, int user)
1627{
1628 struct savagefb_par *par = info->par;
1629
1630 mutex_lock(&par->open_lock);
1631
1632 if (!par->open_count) {
1633 memset(&par->vgastate, 0, sizeof(par->vgastate));
1634 par->vgastate.flags = VGA_SAVE_CMAP | VGA_SAVE_FONTS |
1635 VGA_SAVE_MODE;
1636 par->vgastate.vgabase = par->mmio.vbase + 0x8000;
1637 save_vga(&par->vgastate);
1638 savage_get_default_par(par, &par->initial);
1639 }
1640
1641 par->open_count++;
1642 mutex_unlock(&par->open_lock);
1643 return 0;
1644}
1645
1646static int savagefb_release(struct fb_info *info, int user)
1647{
1648 struct savagefb_par *par = info->par;
1649
1650 mutex_lock(&par->open_lock);
1651
1652 if (par->open_count == 1) {
1653 savage_set_default_par(par, &par->initial);
1654 restore_vga(&par->vgastate);
1655 }
1656
1657 par->open_count--;
1658 mutex_unlock(&par->open_lock);
1659 return 0;
1660}
1661
1626static struct fb_ops savagefb_ops = { 1662static struct fb_ops savagefb_ops = {
1627 .owner = THIS_MODULE, 1663 .owner = THIS_MODULE,
1664 .fb_open = savagefb_open,
1665 .fb_release = savagefb_release,
1628 .fb_check_var = savagefb_check_var, 1666 .fb_check_var = savagefb_check_var,
1629 .fb_set_par = savagefb_set_par, 1667 .fb_set_par = savagefb_set_par,
1630 .fb_setcolreg = savagefb_setcolreg, 1668 .fb_setcolreg = savagefb_setcolreg,
@@ -2173,6 +2211,7 @@ static int __devinit savagefb_probe(struct pci_dev* dev,
2173 if (!info) 2211 if (!info)
2174 return -ENOMEM; 2212 return -ENOMEM;
2175 par = info->par; 2213 par = info->par;
2214 mutex_init(&par->open_lock);
2176 err = pci_enable_device(dev); 2215 err = pci_enable_device(dev);
2177 if (err) 2216 if (err)
2178 goto failed_enable; 2217 goto failed_enable;
diff --git a/drivers/video/sis/osdef.h b/drivers/video/sis/osdef.h
index d048bd39961b..c1492782cb18 100644
--- a/drivers/video/sis/osdef.h
+++ b/drivers/video/sis/osdef.h
@@ -58,9 +58,6 @@
58#define SIS_LINUX_KERNEL /* Linux kernel framebuffer */ 58#define SIS_LINUX_KERNEL /* Linux kernel framebuffer */
59#undef SIS_XORG_XF86 /* XFree86/X.org */ 59#undef SIS_XORG_XF86 /* XFree86/X.org */
60 60
61#undef SIS_LINUX_KERNEL_24
62#undef SIS_LINUX_KERNEL_26
63
64#ifdef OutPortByte 61#ifdef OutPortByte
65#undef OutPortByte 62#undef OutPortByte
66#endif 63#endif
@@ -100,8 +97,6 @@
100#define SIS315H 97#define SIS315H
101#endif 98#endif
102 99
103#define SIS_LINUX_KERNEL_26
104
105#if !defined(SIS300) && !defined(SIS315H) 100#if !defined(SIS300) && !defined(SIS315H)
106#warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set 101#warning Neither CONFIG_FB_SIS_300 nor CONFIG_FB_SIS_315 is set
107#warning sisfb will not work! 102#warning sisfb will not work!
diff --git a/drivers/video/sis/sis.h b/drivers/video/sis/sis.h
index 7d5ee2145e21..d5e2d9c27847 100644
--- a/drivers/video/sis/sis.h
+++ b/drivers/video/sis/sis.h
@@ -27,11 +27,7 @@
27#include <linux/version.h> 27#include <linux/version.h>
28 28
29#include "osdef.h" 29#include "osdef.h"
30#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
31#include <video/sisfb.h> 30#include <video/sisfb.h>
32#else
33#include <linux/sisfb.h>
34#endif
35 31
36#include "vgatypes.h" 32#include "vgatypes.h"
37#include "vstruct.h" 33#include "vstruct.h"
@@ -40,33 +36,17 @@
40#define VER_MINOR 8 36#define VER_MINOR 8
41#define VER_LEVEL 9 37#define VER_LEVEL 9
42 38
43#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
44#include <linux/spinlock.h> 39#include <linux/spinlock.h>
45#define SIS_PCI_GET_CLASS(a, b) pci_get_class(a, b) 40
46#define SIS_PCI_GET_DEVICE(a,b,c) pci_get_device(a,b,c)
47#define SIS_PCI_GET_SLOT(a,b) pci_get_slot(a,b)
48#define SIS_PCI_PUT_DEVICE(a) pci_dev_put(a)
49#ifdef CONFIG_COMPAT 41#ifdef CONFIG_COMPAT
50#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10) 42#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10)
51#include <linux/ioctl32.h> 43#include <linux/ioctl32.h>
52#define SIS_OLD_CONFIG_COMPAT 44#define SIS_OLD_CONFIG_COMPAT
53#else 45#else
54#include <linux/smp_lock.h>
55#define SIS_NEW_CONFIG_COMPAT 46#define SIS_NEW_CONFIG_COMPAT
56#endif 47#endif
57#endif /* CONFIG_COMPAT */ 48#endif /* CONFIG_COMPAT */
58#else /* 2.4 */ 49
59#define SIS_PCI_GET_CLASS(a, b) pci_find_class(a, b)
60#define SIS_PCI_GET_DEVICE(a,b,c) pci_find_device(a,b,c)
61#define SIS_PCI_GET_SLOT(a,b) pci_find_slot(a,b)
62#define SIS_PCI_PUT_DEVICE(a)
63#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,19)
64#ifdef __x86_64__ /* Shouldn't we check for CONFIG_IA32_EMULATION here? */
65#include <asm/ioctl32.h>
66#define SIS_OLD_CONFIG_COMPAT
67#endif
68#endif
69#endif /* 2.4 */
70#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8) 50#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,8)
71#define SIS_IOTYPE1 void __iomem 51#define SIS_IOTYPE1 void __iomem
72#define SIS_IOTYPE2 __iomem 52#define SIS_IOTYPE2 __iomem
@@ -498,26 +478,8 @@ struct sis_video_info {
498 478
499 struct fb_var_screeninfo default_var; 479 struct fb_var_screeninfo default_var;
500 480
501#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
502 struct fb_fix_screeninfo sisfb_fix; 481 struct fb_fix_screeninfo sisfb_fix;
503 u32 pseudo_palette[17]; 482 u32 pseudo_palette[17];
504#endif
505
506#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
507 struct display sis_disp;
508 struct display_switch sisfb_sw;
509 struct {
510 u16 red, green, blue, pad;
511 } sis_palette[256];
512 union {
513#ifdef FBCON_HAS_CFB16
514 u16 cfb16[16];
515#endif
516#ifdef FBCON_HAS_CFB32
517 u32 cfb32[16];
518#endif
519 } sis_fbcon_cmap;
520#endif
521 483
522 struct sisfb_monitor { 484 struct sisfb_monitor {
523 u16 hmin; 485 u16 hmin;
@@ -538,10 +500,6 @@ struct sis_video_info {
538 500
539 int mni; /* Mode number index */ 501 int mni; /* Mode number index */
540 502
541#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
542 int currcon;
543#endif
544
545 unsigned long video_size; 503 unsigned long video_size;
546 unsigned long video_base; 504 unsigned long video_base;
547 unsigned long mmio_size; 505 unsigned long mmio_size;
@@ -578,9 +536,6 @@ struct sis_video_info {
578 int sisfb_tvplug; 536 int sisfb_tvplug;
579 int sisfb_tvstd; 537 int sisfb_tvstd;
580 int sisfb_nocrt2rate; 538 int sisfb_nocrt2rate;
581#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
582 int sisfb_inverse;
583#endif
584 539
585 u32 heapstart; /* offset */ 540 u32 heapstart; /* offset */
586 SIS_IOTYPE1 *sisfb_heap_start; /* address */ 541 SIS_IOTYPE1 *sisfb_heap_start; /* address */
@@ -646,9 +601,7 @@ struct sis_video_info {
646 int modechanged; 601 int modechanged;
647 unsigned char modeprechange; 602 unsigned char modeprechange;
648 603
649#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
650 u8 sisfb_lastrates[128]; 604 u8 sisfb_lastrates[128];
651#endif
652 605
653 int newrom; 606 int newrom;
654 int haveXGIROM; 607 int haveXGIROM;
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index 01197d740217..a30e1e13d8be 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -37,7 +37,6 @@
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
39#include <linux/kernel.h> 39#include <linux/kernel.h>
40#include <linux/smp_lock.h>
41#include <linux/spinlock.h> 40#include <linux/spinlock.h>
42#include <linux/errno.h> 41#include <linux/errno.h>
43#include <linux/string.h> 42#include <linux/string.h>
@@ -1948,7 +1947,7 @@ sisfb_get_northbridge(int basechipid)
1948 default: return NULL; 1947 default: return NULL;
1949 } 1948 }
1950 for(i = 0; i < nbridgenum; i++) { 1949 for(i = 0; i < nbridgenum; i++) {
1951 if((pdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 1950 if((pdev = pci_get_device(PCI_VENDOR_ID_SI,
1952 nbridgeids[nbridgeidx+i], NULL))) 1951 nbridgeids[nbridgeidx+i], NULL)))
1953 break; 1952 break;
1954 } 1953 }
@@ -4613,9 +4612,9 @@ sisfb_find_host_bridge(struct sis_video_info *ivideo, struct pci_dev *mypdev,
4613 unsigned short temp; 4612 unsigned short temp;
4614 int ret = 0; 4613 int ret = 0;
4615 4614
4616 while((pdev = SIS_PCI_GET_CLASS(PCI_CLASS_BRIDGE_HOST, pdev))) { 4615 while((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST, pdev))) {
4617 temp = pdev->vendor; 4616 temp = pdev->vendor;
4618 SIS_PCI_PUT_DEVICE(pdev); 4617 pci_dev_put(pdev);
4619 if(temp == pcivendor) { 4618 if(temp == pcivendor) {
4620 ret = 1; 4619 ret = 1;
4621 break; 4620 break;
@@ -5154,24 +5153,24 @@ sisfb_post_xgi(struct pci_dev *pdev)
5154 if(reg & 0x80) v2 |= 0x80; 5153 if(reg & 0x80) v2 |= 0x80;
5155 v2 |= 0x01; 5154 v2 |= 0x01;
5156 5155
5157 if((mypdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0730, NULL))) { 5156 if((mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0730, NULL))) {
5158 SIS_PCI_PUT_DEVICE(mypdev); 5157 pci_dev_put(mypdev);
5159 if(((v2 & 0x06) == 2) || ((v2 & 0x06) == 4)) 5158 if(((v2 & 0x06) == 2) || ((v2 & 0x06) == 4))
5160 v2 &= 0xf9; 5159 v2 &= 0xf9;
5161 v2 |= 0x08; 5160 v2 |= 0x08;
5162 v1 &= 0xfe; 5161 v1 &= 0xfe;
5163 } else { 5162 } else {
5164 mypdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0735, NULL); 5163 mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0735, NULL);
5165 if(!mypdev) 5164 if(!mypdev)
5166 mypdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0645, NULL); 5165 mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0645, NULL);
5167 if(!mypdev) 5166 if(!mypdev)
5168 mypdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0650, NULL); 5167 mypdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0650, NULL);
5169 if(mypdev) { 5168 if(mypdev) {
5170 pci_read_config_dword(mypdev, 0x94, &regd); 5169 pci_read_config_dword(mypdev, 0x94, &regd);
5171 regd &= 0xfffffeff; 5170 regd &= 0xfffffeff;
5172 pci_write_config_dword(mypdev, 0x94, regd); 5171 pci_write_config_dword(mypdev, 0x94, regd);
5173 v1 &= 0xfe; 5172 v1 &= 0xfe;
5174 SIS_PCI_PUT_DEVICE(mypdev); 5173 pci_dev_put(mypdev);
5175 } else if(sisfb_find_host_bridge(ivideo, pdev, PCI_VENDOR_ID_SI)) { 5174 } else if(sisfb_find_host_bridge(ivideo, pdev, PCI_VENDOR_ID_SI)) {
5176 v1 &= 0xfe; 5175 v1 &= 0xfe;
5177 } else if(sisfb_find_host_bridge(ivideo, pdev, 0x1106) || 5176 } else if(sisfb_find_host_bridge(ivideo, pdev, 0x1106) ||
@@ -5194,13 +5193,13 @@ sisfb_post_xgi(struct pci_dev *pdev)
5194 if( (!(v1 & 0x02)) && (v2 & 0x30) && (regd < 0xcf) ) 5193 if( (!(v1 & 0x02)) && (v2 & 0x30) && (regd < 0xcf) )
5195 setSISIDXREG(SISCR, 0x5f, 0xf1, 0x01); 5194 setSISIDXREG(SISCR, 0x5f, 0xf1, 0x01);
5196 5195
5197 if((mypdev = SIS_PCI_GET_DEVICE(0x10de, 0x01e0, NULL))) { 5196 if((mypdev = pci_get_device(0x10de, 0x01e0, NULL))) {
5198 /* TODO: set CR5f &0xf1 | 0x01 for version 6570 5197 /* TODO: set CR5f &0xf1 | 0x01 for version 6570
5199 * of nforce 2 ROM 5198 * of nforce 2 ROM
5200 */ 5199 */
5201 if(0) 5200 if(0)
5202 setSISIDXREG(SISCR, 0x5f, 0xf1, 0x01); 5201 setSISIDXREG(SISCR, 0x5f, 0xf1, 0x01);
5203 SIS_PCI_PUT_DEVICE(mypdev); 5202 pci_dev_put(mypdev);
5204 } 5203 }
5205 } 5204 }
5206 5205
@@ -5236,9 +5235,9 @@ sisfb_post_xgi(struct pci_dev *pdev)
5236 setSISIDXREG(SISCR, 0x75, 0xe0, bios[0x4ff] & 0x1f); 5235 setSISIDXREG(SISCR, 0x75, 0xe0, bios[0x4ff] & 0x1f);
5237 setSISIDXREG(SISCR, 0x76, 0xe0, bios[0x500] & 0x1f); 5236 setSISIDXREG(SISCR, 0x76, 0xe0, bios[0x500] & 0x1f);
5238 v1 = bios[0x501]; 5237 v1 = bios[0x501];
5239 if((mypdev = SIS_PCI_GET_DEVICE(0x8086, 0x2530, NULL))) { 5238 if((mypdev = pci_get_device(0x8086, 0x2530, NULL))) {
5240 v1 = 0xf0; 5239 v1 = 0xf0;
5241 SIS_PCI_PUT_DEVICE(mypdev); 5240 pci_dev_put(mypdev);
5242 } 5241 }
5243 outSISIDXREG(SISCR, 0x77, v1); 5242 outSISIDXREG(SISCR, 0x77, v1);
5244 } 5243 }
@@ -5947,7 +5946,7 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5947 5946
5948 if(!ivideo->sisvga_enabled) { 5947 if(!ivideo->sisvga_enabled) {
5949 if(pci_enable_device(pdev)) { 5948 if(pci_enable_device(pdev)) {
5950 if(ivideo->nbridge) SIS_PCI_PUT_DEVICE(ivideo->nbridge); 5949 if(ivideo->nbridge) pci_dev_put(ivideo->nbridge);
5951 pci_set_drvdata(pdev, NULL); 5950 pci_set_drvdata(pdev, NULL);
5952 kfree(sis_fb_info); 5951 kfree(sis_fb_info);
5953 return -EIO; 5952 return -EIO;
@@ -5974,7 +5973,7 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5974 "requiring Chrontel/GPIO setup\n", 5973 "requiring Chrontel/GPIO setup\n",
5975 mychswtable[i].vendorName, 5974 mychswtable[i].vendorName,
5976 mychswtable[i].cardName); 5975 mychswtable[i].cardName);
5977 ivideo->lpcdev = SIS_PCI_GET_DEVICE(PCI_VENDOR_ID_SI, 0x0008, NULL); 5976 ivideo->lpcdev = pci_get_device(PCI_VENDOR_ID_SI, 0x0008, NULL);
5978 break; 5977 break;
5979 } 5978 }
5980 i++; 5979 i++;
@@ -5984,7 +5983,7 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5984 5983
5985#ifdef CONFIG_FB_SIS_315 5984#ifdef CONFIG_FB_SIS_315
5986 if((ivideo->chip == SIS_760) && (ivideo->nbridge)) { 5985 if((ivideo->chip == SIS_760) && (ivideo->nbridge)) {
5987 ivideo->lpcdev = SIS_PCI_GET_SLOT(ivideo->nbridge->bus, (2 << 3)); 5986 ivideo->lpcdev = pci_get_slot(ivideo->nbridge->bus, (2 << 3));
5988 } 5987 }
5989#endif 5988#endif
5990 5989
@@ -6149,9 +6148,9 @@ error_1: release_mem_region(ivideo->video_base, ivideo->video_size);
6149error_2: release_mem_region(ivideo->mmio_base, ivideo->mmio_size); 6148error_2: release_mem_region(ivideo->mmio_base, ivideo->mmio_size);
6150error_3: vfree(ivideo->bios_abase); 6149error_3: vfree(ivideo->bios_abase);
6151 if(ivideo->lpcdev) 6150 if(ivideo->lpcdev)
6152 SIS_PCI_PUT_DEVICE(ivideo->lpcdev); 6151 pci_dev_put(ivideo->lpcdev);
6153 if(ivideo->nbridge) 6152 if(ivideo->nbridge)
6154 SIS_PCI_PUT_DEVICE(ivideo->nbridge); 6153 pci_dev_put(ivideo->nbridge);
6155 pci_set_drvdata(pdev, NULL); 6154 pci_set_drvdata(pdev, NULL);
6156 if(!ivideo->sisvga_enabled) 6155 if(!ivideo->sisvga_enabled)
6157 pci_disable_device(pdev); 6156 pci_disable_device(pdev);
@@ -6331,70 +6330,6 @@ error_3: vfree(ivideo->bios_abase);
6331 6330
6332 sisfb_set_vparms(ivideo); 6331 sisfb_set_vparms(ivideo);
6333 6332
6334#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6335
6336 /* ---------------- For 2.4: Now switch the mode ------------------ */
6337
6338 printk(KERN_INFO "sisfb: Setting mode %dx%dx%d (%dHz)\n",
6339 ivideo->video_width, ivideo->video_height, ivideo->video_bpp,
6340 ivideo->refresh_rate);
6341
6342 /* Determine whether or not acceleration is to be
6343 * used. Need to know before pre/post_set_mode()
6344 */
6345 ivideo->accel = 0;
6346 ivideo->default_var.accel_flags &= ~FB_ACCELF_TEXT;
6347 if(ivideo->sisfb_accel) {
6348 ivideo->accel = -1;
6349 ivideo->default_var.accel_flags |= FB_ACCELF_TEXT;
6350 }
6351
6352 /* Now switch the mode */
6353 sisfb_pre_setmode(ivideo);
6354
6355 if(SiSSetMode(&ivideo->SiS_Pr, ivideo->mode_no) == 0) {
6356 printk(KERN_ERR "sisfb: Fatal error: Setting mode[0x%x] failed\n",
6357 ivideo->mode_no);
6358 ret = -EINVAL;
6359 iounmap(ivideo->mmio_vbase);
6360 goto error_0;
6361 }
6362
6363 outSISIDXREG(SISSR, IND_SIS_PASSWORD, SIS_PASSWORD);
6364
6365 sisfb_post_setmode(ivideo);
6366
6367 /* Maximize regardless of sisfb_max at startup */
6368 ivideo->default_var.yres_virtual = 32767;
6369
6370 /* Force reset of x virtual in crtc_to_var */
6371 ivideo->default_var.xres_virtual = 0;
6372
6373 /* Copy mode timing to var */
6374 sisfb_crtc_to_var(ivideo, &ivideo->default_var);
6375
6376 /* Find out about screen pitch */
6377 sisfb_calc_pitch(ivideo, &ivideo->default_var);
6378 sisfb_set_pitch(ivideo);
6379
6380 /* Init the accelerator (does nothing currently) */
6381 sisfb_initaccel(ivideo);
6382
6383 /* Init some fbinfo entries */
6384 sis_fb_info->node = -1;
6385 sis_fb_info->flags = FBINFO_FLAG_DEFAULT;
6386 sis_fb_info->fbops = &sisfb_ops;
6387 sis_fb_info->disp = &ivideo->sis_disp;
6388 sis_fb_info->blank = &sisfb_blank;
6389 sis_fb_info->switch_con = &sisfb_switch;
6390 sis_fb_info->updatevar = &sisfb_update_var;
6391 sis_fb_info->changevar = NULL;
6392 strcpy(sis_fb_info->fontname, sisfb_fontname);
6393
6394 sisfb_set_disp(-1, &ivideo->default_var, sis_fb_info);
6395
6396#else /* --------- For 2.6: Setup a somewhat sane default var ------------ */
6397
6398 printk(KERN_INFO "sisfb: Default mode is %dx%dx%d (%dHz)\n", 6333 printk(KERN_INFO "sisfb: Default mode is %dx%dx%d (%dHz)\n",
6399 ivideo->video_width, ivideo->video_height, ivideo->video_bpp, 6334 ivideo->video_width, ivideo->video_height, ivideo->video_bpp,
6400 ivideo->refresh_rate); 6335 ivideo->refresh_rate);
@@ -6454,7 +6389,6 @@ error_3: vfree(ivideo->bios_abase);
6454 sis_fb_info->pseudo_palette = ivideo->pseudo_palette; 6389 sis_fb_info->pseudo_palette = ivideo->pseudo_palette;
6455 6390
6456 fb_alloc_cmap(&sis_fb_info->cmap, 256 , 0); 6391 fb_alloc_cmap(&sis_fb_info->cmap, 256 , 0);
6457#endif /* 2.6 */
6458 6392
6459 printk(KERN_DEBUG "sisfb: Initial vbflags 0x%x\n", (int)ivideo->vbflags); 6393 printk(KERN_DEBUG "sisfb: Initial vbflags 0x%x\n", (int)ivideo->vbflags);
6460 6394
@@ -6564,10 +6498,10 @@ static void __devexit sisfb_remove(struct pci_dev *pdev)
6564 vfree(ivideo->bios_abase); 6498 vfree(ivideo->bios_abase);
6565 6499
6566 if(ivideo->lpcdev) 6500 if(ivideo->lpcdev)
6567 SIS_PCI_PUT_DEVICE(ivideo->lpcdev); 6501 pci_dev_put(ivideo->lpcdev);
6568 6502
6569 if(ivideo->nbridge) 6503 if(ivideo->nbridge)
6570 SIS_PCI_PUT_DEVICE(ivideo->nbridge); 6504 pci_dev_put(ivideo->nbridge);
6571 6505
6572#ifdef CONFIG_MTRR 6506#ifdef CONFIG_MTRR
6573 /* Release MTRR region */ 6507 /* Release MTRR region */
diff --git a/drivers/video/skeletonfb.c b/drivers/video/skeletonfb.c
index bb96cb65fdaa..836a612af977 100644
--- a/drivers/video/skeletonfb.c
+++ b/drivers/video/skeletonfb.c
@@ -14,7 +14,7 @@
14 * of it. 14 * of it.
15 * 15 *
16 * First the roles of struct fb_info and struct display have changed. Struct 16 * First the roles of struct fb_info and struct display have changed. Struct
17 * display will go away. The way the the new framebuffer console code will 17 * display will go away. The way the new framebuffer console code will
18 * work is that it will act to translate data about the tty/console in 18 * work is that it will act to translate data about the tty/console in
19 * struct vc_data to data in a device independent way in struct fb_info. Then 19 * struct vc_data to data in a device independent way in struct fb_info. Then
20 * various functions in struct fb_ops will be called to store the device 20 * various functions in struct fb_ops will be called to store the device
@@ -51,6 +51,7 @@
51#include <linux/delay.h> 51#include <linux/delay.h>
52#include <linux/fb.h> 52#include <linux/fb.h>
53#include <linux/init.h> 53#include <linux/init.h>
54#include <linux/pci.h>
54 55
55 /* 56 /*
56 * This is just simple sample code. 57 * This is just simple sample code.
@@ -60,6 +61,11 @@
60 */ 61 */
61 62
62/* 63/*
64 * Driver data
65 */
66static char *mode_option __devinitdata;
67
68/*
63 * If your driver supports multiple boards, you should make the 69 * If your driver supports multiple boards, you should make the
64 * below data types arrays, or allocate them dynamically (using kmalloc()). 70 * below data types arrays, or allocate them dynamically (using kmalloc()).
65 */ 71 */
@@ -78,7 +84,7 @@ struct xxx_par;
78 * if we don't use modedb. If we do use modedb see xxxfb_init how to use it 84 * if we don't use modedb. If we do use modedb see xxxfb_init how to use it
79 * to get a fb_var_screeninfo. Otherwise define a default var as well. 85 * to get a fb_var_screeninfo. Otherwise define a default var as well.
80 */ 86 */
81static struct fb_fix_screeninfo xxxfb_fix __initdata = { 87static struct fb_fix_screeninfo xxxfb_fix __devinitdata = {
82 .id = "FB's name", 88 .id = "FB's name",
83 .type = FB_TYPE_PACKED_PIXELS, 89 .type = FB_TYPE_PACKED_PIXELS,
84 .visual = FB_VISUAL_PSEUDOCOLOR, 90 .visual = FB_VISUAL_PSEUDOCOLOR,
@@ -142,7 +148,7 @@ int xxxfb_setup(char*);
142 * 148 *
143 * Returns negative errno on error, or zero on success. 149 * Returns negative errno on error, or zero on success.
144 */ 150 */
145static int xxxfb_open(const struct fb_info *info, int user) 151static int xxxfb_open(struct fb_info *info, int user)
146{ 152{
147 return 0; 153 return 0;
148} 154}
@@ -161,7 +167,7 @@ static int xxxfb_open(const struct fb_info *info, int user)
161 * 167 *
162 * Returns negative errno on error, or zero on success. 168 * Returns negative errno on error, or zero on success.
163 */ 169 */
164static int xxxfb_release(const struct fb_info *info, int user) 170static int xxxfb_release(struct fb_info *info, int user)
165{ 171{
166 return 0; 172 return 0;
167} 173}
@@ -278,7 +284,7 @@ static int xxxfb_set_par(struct fb_info *info)
278 */ 284 */
279static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green, 285static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
280 unsigned blue, unsigned transp, 286 unsigned blue, unsigned transp,
281 const struct fb_info *info) 287 struct fb_info *info)
282{ 288{
283 if (regno >= 256) /* no. of hw registers */ 289 if (regno >= 256) /* no. of hw registers */
284 return -EINVAL; 290 return -EINVAL;
@@ -416,7 +422,7 @@ static int xxxfb_setcolreg(unsigned regno, unsigned red, unsigned green,
416 * Returns negative errno on error, or zero on success. 422 * Returns negative errno on error, or zero on success.
417 */ 423 */
418static int xxxfb_pan_display(struct fb_var_screeninfo *var, 424static int xxxfb_pan_display(struct fb_var_screeninfo *var,
419 const struct fb_info *info) 425 struct fb_info *info)
420{ 426{
421 /* 427 /*
422 * If your hardware does not support panning, _do_ _not_ implement this 428 * If your hardware does not support panning, _do_ _not_ implement this
@@ -454,7 +460,7 @@ static int xxxfb_pan_display(struct fb_var_screeninfo *var,
454 * Return !0 for any modes that are unimplemented. 460 * Return !0 for any modes that are unimplemented.
455 * 461 *
456 */ 462 */
457static int xxxfb_blank(int blank_mode, const struct fb_info *info) 463static int xxxfb_blank(int blank_mode, struct fb_info *info)
458{ 464{
459 /* ... */ 465 /* ... */
460 return 0; 466 return 0;
@@ -483,7 +489,7 @@ static int xxxfb_blank(int blank_mode, const struct fb_info *info)
483 * depending on the rastering operation with the value of color which 489 * depending on the rastering operation with the value of color which
484 * is in the current color depth format. 490 * is in the current color depth format.
485 */ 491 */
486void xxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region) 492void xxxfb_fillrect(struct fb_info *p, const struct fb_fillrect *region)
487{ 493{
488/* Meaning of struct fb_fillrect 494/* Meaning of struct fb_fillrect
489 * 495 *
@@ -623,19 +629,6 @@ void xxxfb_rotate(struct fb_info *info, int angle)
623} 629}
624 630
625/** 631/**
626 * xxxfb_poll - NOT a required function. The purpose of this
627 * function is to provide a way for some process
628 * to wait until a specific hardware event occurs
629 * for the framebuffer device.
630 *
631 * @info: frame buffer structure that represents a single frame buffer
632 * @wait: poll table where we store process that await a event.
633 */
634void xxxfb_poll(struct fb_info *info, poll_table *wait)
635{
636}
637
638/**
639 * xxxfb_sync - NOT a required function. Normally the accel engine 632 * xxxfb_sync - NOT a required function. Normally the accel engine
640 * for a graphics card take a specific amount of time. 633 * for a graphics card take a specific amount of time.
641 * Often we have to wait for the accelerator to finish 634 * Often we have to wait for the accelerator to finish
@@ -647,21 +640,49 @@ void xxxfb_poll(struct fb_info *info, poll_table *wait)
647 * If the driver has implemented its own hardware-based drawing function, 640 * If the driver has implemented its own hardware-based drawing function,
648 * implementing this function is highly recommended. 641 * implementing this function is highly recommended.
649 */ 642 */
650void xxxfb_sync(struct fb_info *info) 643int xxxfb_sync(struct fb_info *info)
651{ 644{
645 return 0;
652} 646}
653 647
654 /* 648 /*
649 * Frame buffer operations
650 */
651
652static struct fb_ops xxxfb_ops = {
653 .owner = THIS_MODULE,
654 .fb_open = xxxfb_open,
655 .fb_read = xxxfb_read,
656 .fb_write = xxxfb_write,
657 .fb_release = xxxfb_release,
658 .fb_check_var = xxxfb_check_var,
659 .fb_set_par = xxxfb_set_par,
660 .fb_setcolreg = xxxfb_setcolreg,
661 .fb_blank = xxxfb_blank,
662 .fb_pan_display = xxxfb_pan_display,
663 .fb_fillrect = xxxfb_fillrect, /* Needed !!! */
664 .fb_copyarea = xxxfb_copyarea, /* Needed !!! */
665 .fb_imageblit = xxxfb_imageblit, /* Needed !!! */
666 .fb_cursor = xxxfb_cursor, /* Optional !!! */
667 .fb_rotate = xxxfb_rotate,
668 .fb_sync = xxxfb_sync,
669 .fb_ioctl = xxxfb_ioctl,
670 .fb_mmap = xxxfb_mmap,
671};
672
673/* ------------------------------------------------------------------------- */
674
675 /*
655 * Initialization 676 * Initialization
656 */ 677 */
657 678
658/* static int __init xxfb_probe (struct device *device) -- for platform devs */ 679/* static int __init xxfb_probe (struct device *device) -- for platform devs */
659static int __init xxxfb_probe(struct pci_dev *dev, 680static int __devinit xxxfb_probe(struct pci_dev *dev,
660 const_struct pci_device_id *ent) 681 const struct pci_device_id *ent)
661{ 682{
662 struct fb_info *info; 683 struct fb_info *info;
663 struct xxx_par *par; 684 struct xxx_par *par;
664 struct device = &dev->dev; /* for pci drivers */ 685 struct device* device = &dev->dev; /* for pci drivers */
665 int cmap_len, retval; 686 int cmap_len, retval;
666 687
667 /* 688 /*
@@ -684,7 +705,7 @@ static int __init xxxfb_probe(struct pci_dev *dev,
684 info->screen_base = framebuffer_virtual_memory; 705 info->screen_base = framebuffer_virtual_memory;
685 info->fbops = &xxxfb_ops; 706 info->fbops = &xxxfb_ops;
686 info->fix = xxxfb_fix; /* this will be the only time xxxfb_fix will be 707 info->fix = xxxfb_fix; /* this will be the only time xxxfb_fix will be
687 * used, so mark it as __initdata 708 * used, so mark it as __devinitdata
688 */ 709 */
689 info->pseudo_palette = pseudo_palette; /* The pseudopalette is an 710 info->pseudo_palette = pseudo_palette; /* The pseudopalette is an
690 * 16-member array 711 * 16-member array
@@ -760,7 +781,7 @@ static int __init xxxfb_probe(struct pci_dev *dev,
760 * 781 *
761 * NOTE: This field is currently unused. 782 * NOTE: This field is currently unused.
762 */ 783 */
763 info->pixmap.scan_align = 32 784 info->pixmap.scan_align = 32;
764/***************************** End optional stage ***************************/ 785/***************************** End optional stage ***************************/
765 786
766 /* 787 /*
@@ -770,13 +791,13 @@ static int __init xxxfb_probe(struct pci_dev *dev,
770 if (!mode_option) 791 if (!mode_option)
771 mode_option = "640x480@60"; 792 mode_option = "640x480@60";
772 793
773 retval = fb_find_mode(info->var, info, mode_option, NULL, 0, NULL, 8); 794 retval = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
774 795
775 if (!retval || retval == 4) 796 if (!retval || retval == 4)
776 return -EINVAL; 797 return -EINVAL;
777 798
778 /* This has to been done !!! */ 799 /* This has to been done !!! */
779 fb_alloc_cmap(info->cmap, cmap_len, 0); 800 fb_alloc_cmap(&info->cmap, cmap_len, 0);
780 801
781 /* 802 /*
782 * The following is done in the case of having hardware with a static 803 * The following is done in the case of having hardware with a static
@@ -811,34 +832,77 @@ static int __init xxxfb_probe(struct pci_dev *dev,
811 /* 832 /*
812 * Cleanup 833 * Cleanup
813 */ 834 */
814/* static void __exit xxxfb_remove(struct device *device) */ 835/* static void __devexit xxxfb_remove(struct device *device) */
815static void __exit xxxfb_remove(struct pci_dev *dev) 836static void __devexit xxxfb_remove(struct pci_dev *dev)
816{ 837{
817 struct fb_info *info = pci_get_drv_data(dev); 838 struct fb_info *info = pci_get_drvdata(dev);
818 /* or dev_get_drv_data(device); */ 839 /* or dev_get_drvdata(device); */
819 840
820 if (info) { 841 if (info) {
821 unregister_framebuffer(info); 842 unregister_framebuffer(info);
822 fb_dealloc_cmap(&info.cmap); 843 fb_dealloc_cmap(&info->cmap);
823 /* ... */ 844 /* ... */
824 framebuffer_release(info); 845 framebuffer_release(info);
825 } 846 }
847}
848
849#ifdef CONFIG_PCI
850#ifdef CONFIG_PM
851/**
852 * xxxfb_suspend - Optional but recommended function. Suspend the device.
853 * @dev: PCI device
854 * @msg: the suspend event code.
855 *
856 * See Documentation/power/devices.txt for more information
857 */
858static int xxxfb_suspend(struct pci_dev *dev, pm_message_t msg)
859{
860 struct fb_info *info = pci_get_drvdata(dev);
861 struct xxxfb_par *par = info->par;
862
863 /* suspend here */
864 return 0;
865}
866
867/**
868 * xxxfb_resume - Optional but recommended function. Resume the device.
869 * @dev: PCI device
870 *
871 * See Documentation/power/devices.txt for more information
872 */
873static int xxxfb_resume(struct pci_dev *dev)
874{
875 struct fb_info *info = pci_get_drvdata(dev);
876 struct xxxfb_par *par = info->par;
826 877
878 /* resume here */
827 return 0; 879 return 0;
828} 880}
881#else
882#define xxxfb_suspend NULL
883#define xxxfb_resume NULL
884#endif /* CONFIG_PM */
885
886static struct pci_device_id xxxfb_id_table[] = {
887 { PCI_VENDOR_ID_XXX, PCI_DEVICE_ID_XXX,
888 PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
889 PCI_CLASS_MASK, 0 },
890 { 0, }
891};
829 892
830#if CONFIG_PCI
831/* For PCI drivers */ 893/* For PCI drivers */
832static struct pci_driver xxxfb_driver = { 894static struct pci_driver xxxfb_driver = {
833 .name = "xxxfb", 895 .name = "xxxfb",
834 .id_table = xxxfb_devices, 896 .id_table = xxxfb_id_table,
835 .probe = xxxfb_probe, 897 .probe = xxxfb_probe,
836 .remove = __devexit_p(xxxfb_remove), 898 .remove = __devexit_p(xxxfb_remove),
837 .suspend = xxxfb_suspend, /* optional */ 899 .suspend = xxxfb_suspend, /* optional but recommended */
838 .resume = xxxfb_resume, /* optional */ 900 .resume = xxxfb_resume, /* optional but recommended */
839}; 901};
840 902
841static int __init xxxfb_init(void) 903MODULE_DEVICE_TABLE(pci, xxxfb_id_table);
904
905int __init xxxfb_init(void)
842{ 906{
843 /* 907 /*
844 * For kernel boot options (in 'video=xxxfb:<options>' format) 908 * For kernel boot options (in 'video=xxxfb:<options>' format)
@@ -858,16 +922,53 @@ static void __exit xxxfb_exit(void)
858{ 922{
859 pci_unregister_driver(&xxxfb_driver); 923 pci_unregister_driver(&xxxfb_driver);
860} 924}
861#else 925#else /* non PCI, platform drivers */
862#include <linux/platform_device.h> 926#include <linux/platform_device.h>
863/* for platform devices */ 927/* for platform devices */
928
929#ifdef CONFIG_PM
930/**
931 * xxxfb_suspend - Optional but recommended function. Suspend the device.
932 * @dev: platform device
933 * @msg: the suspend event code.
934 *
935 * See Documentation/power/devices.txt for more information
936 */
937static int xxxfb_suspend(struct platform_device *dev, pm_message_t msg)
938{
939 struct fb_info *info = platform_get_drvdata(dev);
940 struct xxxfb_par *par = info->par;
941
942 /* suspend here */
943 return 0;
944}
945
946/**
947 * xxxfb_resume - Optional but recommended function. Resume the device.
948 * @dev: platform device
949 *
950 * See Documentation/power/devices.txt for more information
951 */
952static int xxxfb_resume(struct platform_dev *dev)
953{
954 struct fb_info *info = platform_get_drvdata(dev);
955 struct xxxfb_par *par = info->par;
956
957 /* resume here */
958 return 0;
959}
960#else
961#define xxxfb_suspend NULL
962#define xxxfb_resume NULL
963#endif /* CONFIG_PM */
964
864static struct device_driver xxxfb_driver = { 965static struct device_driver xxxfb_driver = {
865 .name = "xxxfb", 966 .name = "xxxfb",
866 .bus = &platform_bus_type, 967 .bus = &platform_bus_type,
867 .probe = xxxfb_probe, 968 .probe = xxxfb_probe,
868 .remove = xxxfb_remove, 969 .remove = xxxfb_remove,
869 .suspend = xxxfb_suspend, /* optional */ 970 .suspend = xxxfb_suspend, /* optional but recommended */
870 .resume = xxxfb_resume, /* optional */ 971 .resume = xxxfb_resume, /* optional but recommended */
871}; 972};
872 973
873static struct platform_device xxxfb_device = { 974static struct platform_device xxxfb_device = {
@@ -903,8 +1004,9 @@ static void __exit xxxfb_exit(void)
903 platform_device_unregister(&xxxfb_device); 1004 platform_device_unregister(&xxxfb_device);
904 driver_unregister(&xxxfb_driver); 1005 driver_unregister(&xxxfb_driver);
905} 1006}
906#endif 1007#endif /* CONFIG_PCI */
907 1008
1009#ifdef MODULE
908 /* 1010 /*
909 * Setup 1011 * Setup
910 */ 1012 */
@@ -917,34 +1019,7 @@ int __init xxxfb_setup(char *options)
917{ 1019{
918 /* Parse user speficied options (`video=xxxfb:') */ 1020 /* Parse user speficied options (`video=xxxfb:') */
919} 1021}
920 1022#endif /* MODULE */
921/* ------------------------------------------------------------------------- */
922
923 /*
924 * Frame buffer operations
925 */
926
927static struct fb_ops xxxfb_ops = {
928 .owner = THIS_MODULE,
929 .fb_open = xxxfb_open,
930 .fb_read = xxxfb_read,
931 .fb_write = xxxfb_write,
932 .fb_release = xxxfb_release,
933 .fb_check_var = xxxfb_check_var,
934 .fb_set_par = xxxfb_set_par,
935 .fb_setcolreg = xxxfb_setcolreg,
936 .fb_blank = xxxfb_blank,
937 .fb_pan_display = xxxfb_pan_display,
938 .fb_fillrect = xxxfb_fillrect, /* Needed !!! */
939 .fb_copyarea = xxxfb_copyarea, /* Needed !!! */
940 .fb_imageblit = xxxfb_imageblit, /* Needed !!! */
941 .fb_cursor = xxxfb_cursor, /* Optional !!! */
942 .fb_rotate = xxxfb_rotate,
943 .fb_poll = xxxfb_poll,
944 .fb_sync = xxxfb_sync,
945 .fb_ioctl = xxxfb_ioctl,
946 .fb_mmap = xxxfb_mmap,
947};
948 1023
949/* ------------------------------------------------------------------------- */ 1024/* ------------------------------------------------------------------------- */
950 1025
@@ -954,6 +1029,6 @@ static struct fb_ops xxxfb_ops = {
954 */ 1029 */
955 1030
956module_init(xxxfb_init); 1031module_init(xxxfb_init);
957module_exit(xxxfb_cleanup); 1032module_exit(xxxfb_remove);
958 1033
959MODULE_LICENSE("GPL"); 1034MODULE_LICENSE("GPL");
diff --git a/drivers/video/sm501fb.c b/drivers/video/sm501fb.c
index 0a44c44672c8..c86df126f93a 100644
--- a/drivers/video/sm501fb.c
+++ b/drivers/video/sm501fb.c
@@ -989,7 +989,7 @@ static int sm501fb_cursor(struct fb_info *info, struct fb_cursor *cursor)
989 ((info->cmap.green[fg_col] & 0xFC) << 3) | 989 ((info->cmap.green[fg_col] & 0xFC) << 3) |
990 ((info->cmap.blue[fg_col] & 0xF8) >> 3); 990 ((info->cmap.blue[fg_col] & 0xF8) >> 3);
991 991
992 dev_dbg(fbi->dev, "fgcol %08x, bgcol %08x\n", fg, bg); 992 dev_dbg(fbi->dev, "fgcol %08lx, bgcol %08lx\n", fg, bg);
993 993
994 writel(bg, base + SM501_OFF_HWC_COLOR_1_2); 994 writel(bg, base + SM501_OFF_HWC_COLOR_1_2);
995 writel(fg, base + SM501_OFF_HWC_COLOR_3); 995 writel(fg, base + SM501_OFF_HWC_COLOR_3);
diff --git a/drivers/video/svgalib.c b/drivers/video/svgalib.c
index 68b30d9eac58..25df928d37d8 100644
--- a/drivers/video/svgalib.c
+++ b/drivers/video/svgalib.c
@@ -194,7 +194,7 @@ void svga_dump_var(struct fb_var_screeninfo *var, int node)
194void svga_settile(struct fb_info *info, struct fb_tilemap *map) 194void svga_settile(struct fb_info *info, struct fb_tilemap *map)
195{ 195{
196 const u8 *font = map->data; 196 const u8 *font = map->data;
197 u8* fb = (u8 *) info->screen_base; 197 u8 __iomem *fb = (u8 __iomem *)info->screen_base;
198 int i, c; 198 int i, c;
199 199
200 if ((map->width != 8) || (map->height != 16) || 200 if ((map->width != 8) || (map->height != 16) ||
@@ -207,7 +207,8 @@ void svga_settile(struct fb_info *info, struct fb_tilemap *map)
207 fb += 2; 207 fb += 2;
208 for (c = 0; c < map->length; c++) { 208 for (c = 0; c < map->length; c++) {
209 for (i = 0; i < map->height; i++) { 209 for (i = 0; i < map->height; i++) {
210 fb[i * 4] = font[i]; 210 fb_writeb(font[i], fb + i * 4);
211// fb[i * 4] = font[i];
211 } 212 }
212 fb += 128; 213 fb += 128;
213 font += map->height; 214 font += map->height;
@@ -221,8 +222,8 @@ void svga_tilecopy(struct fb_info *info, struct fb_tilearea *area)
221 /* colstride is halved in this function because u16 are used */ 222 /* colstride is halved in this function because u16 are used */
222 int colstride = 1 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK); 223 int colstride = 1 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK);
223 int rowstride = colstride * (info->var.xres_virtual / 8); 224 int rowstride = colstride * (info->var.xres_virtual / 8);
224 u16 *fb = (u16 *) info->screen_base; 225 u16 __iomem *fb = (u16 __iomem *) info->screen_base;
225 u16 *src, *dst; 226 u16 __iomem *src, *dst;
226 227
227 if ((area->sy > area->dy) || 228 if ((area->sy > area->dy) ||
228 ((area->sy == area->dy) && (area->sx > area->dx))) { 229 ((area->sy == area->dy) && (area->sx > area->dx))) {
@@ -239,10 +240,11 @@ void svga_tilecopy(struct fb_info *info, struct fb_tilearea *area)
239 } 240 }
240 241
241 for (dy = 0; dy < area->height; dy++) { 242 for (dy = 0; dy < area->height; dy++) {
242 u16* src2 = src; 243 u16 __iomem *src2 = src;
243 u16* dst2 = dst; 244 u16 __iomem *dst2 = dst;
244 for (dx = 0; dx < area->width; dx++) { 245 for (dx = 0; dx < area->width; dx++) {
245 *dst2 = *src2; 246 fb_writew(fb_readw(src2), dst2);
247// *dst2 = *src2;
246 src2 += colstride; 248 src2 += colstride;
247 dst2 += colstride; 249 dst2 += colstride;
248 } 250 }
@@ -258,14 +260,14 @@ void svga_tilefill(struct fb_info *info, struct fb_tilerect *rect)
258 int colstride = 2 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK); 260 int colstride = 2 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK);
259 int rowstride = colstride * (info->var.xres_virtual / 8); 261 int rowstride = colstride * (info->var.xres_virtual / 8);
260 int attr = (0x0F & rect->bg) << 4 | (0x0F & rect->fg); 262 int attr = (0x0F & rect->bg) << 4 | (0x0F & rect->fg);
261 u8 *fb = (u8 *) info->screen_base; 263 u8 __iomem *fb = (u8 __iomem *)info->screen_base;
262 fb += rect->sx * colstride + rect->sy * rowstride; 264 fb += rect->sx * colstride + rect->sy * rowstride;
263 265
264 for (dy = 0; dy < rect->height; dy++) { 266 for (dy = 0; dy < rect->height; dy++) {
265 u8* fb2 = fb; 267 u8 __iomem *fb2 = fb;
266 for (dx = 0; dx < rect->width; dx++) { 268 for (dx = 0; dx < rect->width; dx++) {
267 fb2[0] = rect->index; 269 fb_writeb(rect->index, fb2);
268 fb2[1] = attr; 270 fb_writeb(attr, fb2 + 1);
269 fb2 += colstride; 271 fb2 += colstride;
270 } 272 }
271 fb += rowstride; 273 fb += rowstride;
@@ -279,15 +281,15 @@ void svga_tileblit(struct fb_info *info, struct fb_tileblit *blit)
279 int colstride = 2 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK); 281 int colstride = 2 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK);
280 int rowstride = colstride * (info->var.xres_virtual / 8); 282 int rowstride = colstride * (info->var.xres_virtual / 8);
281 int attr = (0x0F & blit->bg) << 4 | (0x0F & blit->fg); 283 int attr = (0x0F & blit->bg) << 4 | (0x0F & blit->fg);
282 u8* fb = (u8 *) info->screen_base; 284 u8 __iomem *fb = (u8 __iomem *)info->screen_base;
283 fb += blit->sx * colstride + blit->sy * rowstride; 285 fb += blit->sx * colstride + blit->sy * rowstride;
284 286
285 i=0; 287 i=0;
286 for (dy=0; dy < blit->height; dy ++) { 288 for (dy=0; dy < blit->height; dy ++) {
287 u8* fb2 = fb; 289 u8 __iomem *fb2 = fb;
288 for (dx = 0; dx < blit->width; dx ++) { 290 for (dx = 0; dx < blit->width; dx ++) {
289 fb2[0] = blit->indices[i]; 291 fb_writeb(blit->indices[i], fb2);
290 fb2[1] = attr; 292 fb_writeb(attr, fb2 + 1);
291 fb2 += colstride; 293 fb2 += colstride;
292 i ++; 294 i ++;
293 if (i == blit->length) return; 295 if (i == blit->length) return;
@@ -340,6 +342,28 @@ void svga_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
340 vga_wcrt(NULL, 0x0A, cs); /* set cursor start and enable it */ 342 vga_wcrt(NULL, 0x0A, cs); /* set cursor start and enable it */
341} 343}
342 344
345int svga_get_tilemax(struct fb_info *info)
346{
347 return 256;
348}
349
350/* Get capabilities of accelerator based on the mode */
351
352void svga_get_caps(struct fb_info *info, struct fb_blit_caps *caps,
353 struct fb_var_screeninfo *var)
354{
355 if (var->bits_per_pixel == 0) {
356 /* can only support 256 8x16 bitmap */
357 caps->x = 1 << (8 - 1);
358 caps->y = 1 << (16 - 1);
359 caps->len = 256;
360 } else {
361 caps->x = (var->bits_per_pixel == 4) ? 1 << (8 - 1) : ~(u32)0;
362 caps->y = ~(u32)0;
363 caps->len = ~(u32)0;
364 }
365}
366EXPORT_SYMBOL(svga_get_caps);
343 367
344/* ------------------------------------------------------------------------- */ 368/* ------------------------------------------------------------------------- */
345 369
@@ -621,6 +645,7 @@ EXPORT_SYMBOL(svga_tilecopy);
621EXPORT_SYMBOL(svga_tilefill); 645EXPORT_SYMBOL(svga_tilefill);
622EXPORT_SYMBOL(svga_tileblit); 646EXPORT_SYMBOL(svga_tileblit);
623EXPORT_SYMBOL(svga_tilecursor); 647EXPORT_SYMBOL(svga_tilecursor);
648EXPORT_SYMBOL(svga_get_tilemax);
624 649
625EXPORT_SYMBOL(svga_compute_pll); 650EXPORT_SYMBOL(svga_compute_pll);
626EXPORT_SYMBOL(svga_check_timings); 651EXPORT_SYMBOL(svga_check_timings);
diff --git a/drivers/video/syscopyarea.c b/drivers/video/syscopyarea.c
new file mode 100644
index 000000000000..37af10ab8f52
--- /dev/null
+++ b/drivers/video/syscopyarea.c
@@ -0,0 +1,378 @@
1/*
2 * Generic Bit Block Transfer for frame buffers located in system RAM with
3 * packed pixels of any depth.
4 *
5 * Based almost entirely from cfbcopyarea.c (which is based almost entirely
6 * on Geert Uytterhoeven's copyarea routine)
7 *
8 * Copyright (C) 2007 Antonino Daplas <adaplas@pol.net>
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive for
12 * more details.
13 *
14 */
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/string.h>
18#include <linux/fb.h>
19#include <linux/slab.h>
20#include <asm/types.h>
21#include <asm/io.h>
22#include "fb_draw.h"
23
24 /*
25 * Generic bitwise copy algorithm
26 */
27
28static void
29bitcpy(unsigned long *dst, int dst_idx, const unsigned long *src,
30 int src_idx, int bits, unsigned n)
31{
32 unsigned long first, last;
33 int const shift = dst_idx-src_idx;
34 int left, right;
35
36 first = FB_SHIFT_HIGH(~0UL, dst_idx);
37 last = ~(FB_SHIFT_HIGH(~0UL, (dst_idx+n) % bits));
38
39 if (!shift) {
40 /* Same alignment for source and dest */
41 if (dst_idx+n <= bits) {
42 /* Single word */
43 if (last)
44 first &= last;
45 *dst = comp(*src, *dst, first);
46 } else {
47 /* Multiple destination words */
48 /* Leading bits */
49 if (first != ~0UL) {
50 *dst = comp(*src, *dst, first);
51 dst++;
52 src++;
53 n -= bits - dst_idx;
54 }
55
56 /* Main chunk */
57 n /= bits;
58 while (n >= 8) {
59 *dst++ = *src++;
60 *dst++ = *src++;
61 *dst++ = *src++;
62 *dst++ = *src++;
63 *dst++ = *src++;
64 *dst++ = *src++;
65 *dst++ = *src++;
66 *dst++ = *src++;
67 n -= 8;
68 }
69 while (n--)
70 *dst++ = *src++;
71
72 /* Trailing bits */
73 if (last)
74 *dst = comp(*src, *dst, last);
75 }
76 } else {
77 unsigned long d0, d1;
78 int m;
79
80 /* Different alignment for source and dest */
81 right = shift & (bits - 1);
82 left = -shift & (bits - 1);
83
84 if (dst_idx+n <= bits) {
85 /* Single destination word */
86 if (last)
87 first &= last;
88 if (shift > 0) {
89 /* Single source word */
90 *dst = comp(*src >> right, *dst, first);
91 } else if (src_idx+n <= bits) {
92 /* Single source word */
93 *dst = comp(*src << left, *dst, first);
94 } else {
95 /* 2 source words */
96 d0 = *src++;
97 d1 = *src;
98 *dst = comp(d0 << left | d1 >> right, *dst,
99 first);
100 }
101 } else {
102 /* Multiple destination words */
103 /** We must always remember the last value read,
104 because in case SRC and DST overlap bitwise (e.g.
105 when moving just one pixel in 1bpp), we always
106 collect one full long for DST and that might
107 overlap with the current long from SRC. We store
108 this value in 'd0'. */
109 d0 = *src++;
110 /* Leading bits */
111 if (shift > 0) {
112 /* Single source word */
113 *dst = comp(d0 >> right, *dst, first);
114 dst++;
115 n -= bits - dst_idx;
116 } else {
117 /* 2 source words */
118 d1 = *src++;
119 *dst = comp(d0 << left | *dst >> right, *dst, first);
120 d0 = d1;
121 dst++;
122 n -= bits - dst_idx;
123 }
124
125 /* Main chunk */
126 m = n % bits;
127 n /= bits;
128 while (n >= 4) {
129 d1 = *src++;
130 *dst++ = d0 << left | d1 >> right;
131 d0 = d1;
132 d1 = *src++;
133 *dst++ = d0 << left | d1 >> right;
134 d0 = d1;
135 d1 = *src++;
136 *dst++ = d0 << left | d1 >> right;
137 d0 = d1;
138 d1 = *src++;
139 *dst++ = d0 << left | d1 >> right;
140 d0 = d1;
141 n -= 4;
142 }
143 while (n--) {
144 d1 = *src++;
145 *dst++ = d0 << left | d1 >> right;
146 d0 = d1;
147 }
148
149 /* Trailing bits */
150 if (last) {
151 if (m <= right) {
152 /* Single source word */
153 *dst = comp(d0 << left, *dst, last);
154 } else {
155 /* 2 source words */
156 d1 = *src;
157 *dst = comp(d0 << left | d1 >> right,
158 *dst, last);
159 }
160 }
161 }
162 }
163}
164
165 /*
166 * Generic bitwise copy algorithm, operating backward
167 */
168
169static void
170bitcpy_rev(unsigned long *dst, int dst_idx, const unsigned long *src,
171 int src_idx, int bits, unsigned n)
172{
173 unsigned long first, last;
174 int shift;
175
176 dst += (n-1)/bits;
177 src += (n-1)/bits;
178 if ((n-1) % bits) {
179 dst_idx += (n-1) % bits;
180 dst += dst_idx >> (ffs(bits) - 1);
181 dst_idx &= bits - 1;
182 src_idx += (n-1) % bits;
183 src += src_idx >> (ffs(bits) - 1);
184 src_idx &= bits - 1;
185 }
186
187 shift = dst_idx-src_idx;
188
189 first = FB_SHIFT_LOW(~0UL, bits - 1 - dst_idx);
190 last = ~(FB_SHIFT_LOW(~0UL, bits - 1 - ((dst_idx-n) % bits)));
191
192 if (!shift) {
193 /* Same alignment for source and dest */
194 if ((unsigned long)dst_idx+1 >= n) {
195 /* Single word */
196 if (last)
197 first &= last;
198 *dst = comp(*src, *dst, first);
199 } else {
200 /* Multiple destination words */
201
202 /* Leading bits */
203 if (first != ~0UL) {
204 *dst = comp(*src, *dst, first);
205 dst--;
206 src--;
207 n -= dst_idx+1;
208 }
209
210 /* Main chunk */
211 n /= bits;
212 while (n >= 8) {
213 *dst-- = *src--;
214 *dst-- = *src--;
215 *dst-- = *src--;
216 *dst-- = *src--;
217 *dst-- = *src--;
218 *dst-- = *src--;
219 *dst-- = *src--;
220 *dst-- = *src--;
221 n -= 8;
222 }
223 while (n--)
224 *dst-- = *src--;
225 /* Trailing bits */
226 if (last)
227 *dst = comp(*src, *dst, last);
228 }
229 } else {
230 /* Different alignment for source and dest */
231
232 int const left = -shift & (bits-1);
233 int const right = shift & (bits-1);
234
235 if ((unsigned long)dst_idx+1 >= n) {
236 /* Single destination word */
237 if (last)
238 first &= last;
239 if (shift < 0) {
240 /* Single source word */
241 *dst = comp(*src << left, *dst, first);
242 } else if (1+(unsigned long)src_idx >= n) {
243 /* Single source word */
244 *dst = comp(*src >> right, *dst, first);
245 } else {
246 /* 2 source words */
247 *dst = comp(*src >> right | *(src-1) << left,
248 *dst, first);
249 }
250 } else {
251 /* Multiple destination words */
252 /** We must always remember the last value read,
253 because in case SRC and DST overlap bitwise (e.g.
254 when moving just one pixel in 1bpp), we always
255 collect one full long for DST and that might
256 overlap with the current long from SRC. We store
257 this value in 'd0'. */
258 unsigned long d0, d1;
259 int m;
260
261 d0 = *src--;
262 /* Leading bits */
263 if (shift < 0) {
264 /* Single source word */
265 *dst = comp(d0 << left, *dst, first);
266 } else {
267 /* 2 source words */
268 d1 = *src--;
269 *dst = comp(d0 >> right | d1 << left, *dst,
270 first);
271 d0 = d1;
272 }
273 dst--;
274 n -= dst_idx+1;
275
276 /* Main chunk */
277 m = n % bits;
278 n /= bits;
279 while (n >= 4) {
280 d1 = *src--;
281 *dst-- = d0 >> right | d1 << left;
282 d0 = d1;
283 d1 = *src--;
284 *dst-- = d0 >> right | d1 << left;
285 d0 = d1;
286 d1 = *src--;
287 *dst-- = d0 >> right | d1 << left;
288 d0 = d1;
289 d1 = *src--;
290 *dst-- = d0 >> right | d1 << left;
291 d0 = d1;
292 n -= 4;
293 }
294 while (n--) {
295 d1 = *src--;
296 *dst-- = d0 >> right | d1 << left;
297 d0 = d1;
298 }
299
300 /* Trailing bits */
301 if (last) {
302 if (m <= left) {
303 /* Single source word */
304 *dst = comp(d0 >> right, *dst, last);
305 } else {
306 /* 2 source words */
307 d1 = *src;
308 *dst = comp(d0 >> right | d1 << left,
309 *dst, last);
310 }
311 }
312 }
313 }
314}
315
316void sys_copyarea(struct fb_info *p, const struct fb_copyarea *area)
317{
318 u32 dx = area->dx, dy = area->dy, sx = area->sx, sy = area->sy;
319 u32 height = area->height, width = area->width;
320 unsigned long const bits_per_line = p->fix.line_length*8u;
321 unsigned long *dst = NULL, *src = NULL;
322 int bits = BITS_PER_LONG, bytes = bits >> 3;
323 int dst_idx = 0, src_idx = 0, rev_copy = 0;
324
325 if (p->state != FBINFO_STATE_RUNNING)
326 return;
327
328 /* if the beginning of the target area might overlap with the end of
329 the source area, be have to copy the area reverse. */
330 if ((dy == sy && dx > sx) || (dy > sy)) {
331 dy += height;
332 sy += height;
333 rev_copy = 1;
334 }
335
336 /* split the base of the framebuffer into a long-aligned address and
337 the index of the first bit */
338 dst = src = (unsigned long *)((unsigned long)p->screen_base &
339 ~(bytes-1));
340 dst_idx = src_idx = 8*((unsigned long)p->screen_base & (bytes-1));
341 /* add offset of source and target area */
342 dst_idx += dy*bits_per_line + dx*p->var.bits_per_pixel;
343 src_idx += sy*bits_per_line + sx*p->var.bits_per_pixel;
344
345 if (p->fbops->fb_sync)
346 p->fbops->fb_sync(p);
347
348 if (rev_copy) {
349 while (height--) {
350 dst_idx -= bits_per_line;
351 src_idx -= bits_per_line;
352 dst += dst_idx >> (ffs(bits) - 1);
353 dst_idx &= (bytes - 1);
354 src += src_idx >> (ffs(bits) - 1);
355 src_idx &= (bytes - 1);
356 bitcpy_rev(dst, dst_idx, src, src_idx, bits,
357 width*p->var.bits_per_pixel);
358 }
359 } else {
360 while (height--) {
361 dst += dst_idx >> (ffs(bits) - 1);
362 dst_idx &= (bytes - 1);
363 src += src_idx >> (ffs(bits) - 1);
364 src_idx &= (bytes - 1);
365 bitcpy(dst, dst_idx, src, src_idx, bits,
366 width*p->var.bits_per_pixel);
367 dst_idx += bits_per_line;
368 src_idx += bits_per_line;
369 }
370 }
371}
372
373EXPORT_SYMBOL(sys_copyarea);
374
375MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
376MODULE_DESCRIPTION("Generic copyarea (sys-to-sys)");
377MODULE_LICENSE("GPL");
378
diff --git a/drivers/video/sysfillrect.c b/drivers/video/sysfillrect.c
new file mode 100644
index 000000000000..a261e9e6a675
--- /dev/null
+++ b/drivers/video/sysfillrect.c
@@ -0,0 +1,334 @@
1/*
2 * Generic fillrect for frame buffers in system RAM with packed pixels of
3 * any depth.
4 *
5 * Based almost entirely from cfbfillrect.c (which is based almost entirely
6 * on Geert Uytterhoeven's fillrect routine)
7 *
8 * Copyright (C) 2007 Antonino Daplas <adaplas@pol.net>
9 *
10 * This file is subject to the terms and conditions of the GNU General Public
11 * License. See the file COPYING in the main directory of this archive for
12 * more details.
13 */
14#include <linux/module.h>
15#include <linux/string.h>
16#include <linux/fb.h>
17#include <asm/types.h>
18#include "fb_draw.h"
19
20 /*
21 * Aligned pattern fill using 32/64-bit memory accesses
22 */
23
24static void
25bitfill_aligned(unsigned long *dst, int dst_idx, unsigned long pat,
26 unsigned n, int bits)
27{
28 unsigned long first, last;
29
30 if (!n)
31 return;
32
33 first = FB_SHIFT_HIGH(~0UL, dst_idx);
34 last = ~(FB_SHIFT_HIGH(~0UL, (dst_idx+n) % bits));
35
36 if (dst_idx+n <= bits) {
37 /* Single word */
38 if (last)
39 first &= last;
40 *dst = comp(pat, *dst, first);
41 } else {
42 /* Multiple destination words */
43
44 /* Leading bits */
45 if (first!= ~0UL) {
46 *dst = comp(pat, *dst, first);
47 dst++;
48 n -= bits - dst_idx;
49 }
50
51 /* Main chunk */
52 n /= bits;
53 while (n >= 8) {
54 *dst++ = pat;
55 *dst++ = pat;
56 *dst++ = pat;
57 *dst++ = pat;
58 *dst++ = pat;
59 *dst++ = pat;
60 *dst++ = pat;
61 *dst++ = pat;
62 n -= 8;
63 }
64 while (n--)
65 *dst++ = pat;
66 /* Trailing bits */
67 if (last)
68 *dst = comp(pat, *dst, last);
69 }
70}
71
72
73 /*
74 * Unaligned generic pattern fill using 32/64-bit memory accesses
75 * The pattern must have been expanded to a full 32/64-bit value
76 * Left/right are the appropriate shifts to convert to the pattern to be
77 * used for the next 32/64-bit word
78 */
79
80static void
81bitfill_unaligned(unsigned long *dst, int dst_idx, unsigned long pat,
82 int left, int right, unsigned n, int bits)
83{
84 unsigned long first, last;
85
86 if (!n)
87 return;
88
89 first = FB_SHIFT_HIGH(~0UL, dst_idx);
90 last = ~(FB_SHIFT_HIGH(~0UL, (dst_idx+n) % bits));
91
92 if (dst_idx+n <= bits) {
93 /* Single word */
94 if (last)
95 first &= last;
96 *dst = comp(pat, *dst, first);
97 } else {
98 /* Multiple destination words */
99 /* Leading bits */
100 if (first) {
101 *dst = comp(pat, *dst, first);
102 dst++;
103 pat = pat << left | pat >> right;
104 n -= bits - dst_idx;
105 }
106
107 /* Main chunk */
108 n /= bits;
109 while (n >= 4) {
110 *dst++ = pat;
111 pat = pat << left | pat >> right;
112 *dst++ = pat;
113 pat = pat << left | pat >> right;
114 *dst++ = pat;
115 pat = pat << left | pat >> right;
116 *dst++ = pat;
117 pat = pat << left | pat >> right;
118 n -= 4;
119 }
120 while (n--) {
121 *dst++ = pat;
122 pat = pat << left | pat >> right;
123 }
124
125 /* Trailing bits */
126 if (last)
127 *dst = comp(pat, *dst, first);
128 }
129}
130
131 /*
132 * Aligned pattern invert using 32/64-bit memory accesses
133 */
134static void
135bitfill_aligned_rev(unsigned long *dst, int dst_idx, unsigned long pat,
136 unsigned n, int bits)
137{
138 unsigned long val = pat;
139 unsigned long first, last;
140
141 if (!n)
142 return;
143
144 first = FB_SHIFT_HIGH(~0UL, dst_idx);
145 last = ~(FB_SHIFT_HIGH(~0UL, (dst_idx+n) % bits));
146
147 if (dst_idx+n <= bits) {
148 /* Single word */
149 if (last)
150 first &= last;
151 *dst = comp(*dst ^ val, *dst, first);
152 } else {
153 /* Multiple destination words */
154 /* Leading bits */
155 if (first!=0UL) {
156 *dst = comp(*dst ^ val, *dst, first);
157 dst++;
158 n -= bits - dst_idx;
159 }
160
161 /* Main chunk */
162 n /= bits;
163 while (n >= 8) {
164 *dst++ ^= val;
165 *dst++ ^= val;
166 *dst++ ^= val;
167 *dst++ ^= val;
168 *dst++ ^= val;
169 *dst++ ^= val;
170 *dst++ ^= val;
171 *dst++ ^= val;
172 n -= 8;
173 }
174 while (n--)
175 *dst++ ^= val;
176 /* Trailing bits */
177 if (last)
178 *dst = comp(*dst ^ val, *dst, last);
179 }
180}
181
182
183 /*
184 * Unaligned generic pattern invert using 32/64-bit memory accesses
185 * The pattern must have been expanded to a full 32/64-bit value
186 * Left/right are the appropriate shifts to convert to the pattern to be
187 * used for the next 32/64-bit word
188 */
189
190static void
191bitfill_unaligned_rev(unsigned long *dst, int dst_idx, unsigned long pat,
192 int left, int right, unsigned n, int bits)
193{
194 unsigned long first, last;
195
196 if (!n)
197 return;
198
199 first = FB_SHIFT_HIGH(~0UL, dst_idx);
200 last = ~(FB_SHIFT_HIGH(~0UL, (dst_idx+n) % bits));
201
202 if (dst_idx+n <= bits) {
203 /* Single word */
204 if (last)
205 first &= last;
206 *dst = comp(*dst ^ pat, *dst, first);
207 } else {
208 /* Multiple destination words */
209
210 /* Leading bits */
211 if (first != 0UL) {
212 *dst = comp(*dst ^ pat, *dst, first);
213 dst++;
214 pat = pat << left | pat >> right;
215 n -= bits - dst_idx;
216 }
217
218 /* Main chunk */
219 n /= bits;
220 while (n >= 4) {
221 *dst++ ^= pat;
222 pat = pat << left | pat >> right;
223 *dst++ ^= pat;
224 pat = pat << left | pat >> right;
225 *dst++ ^= pat;
226 pat = pat << left | pat >> right;
227 *dst++ ^= pat;
228 pat = pat << left | pat >> right;
229 n -= 4;
230 }
231 while (n--) {
232 *dst ^= pat;
233 pat = pat << left | pat >> right;
234 }
235
236 /* Trailing bits */
237 if (last)
238 *dst = comp(*dst ^ pat, *dst, last);
239 }
240}
241
242void sys_fillrect(struct fb_info *p, const struct fb_fillrect *rect)
243{
244 unsigned long pat, fg;
245 unsigned long width = rect->width, height = rect->height;
246 int bits = BITS_PER_LONG, bytes = bits >> 3;
247 u32 bpp = p->var.bits_per_pixel;
248 unsigned long *dst;
249 int dst_idx, left;
250
251 if (p->state != FBINFO_STATE_RUNNING)
252 return;
253
254 if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
255 p->fix.visual == FB_VISUAL_DIRECTCOLOR )
256 fg = ((u32 *) (p->pseudo_palette))[rect->color];
257 else
258 fg = rect->color;
259
260 pat = pixel_to_pat( bpp, fg);
261
262 dst = (unsigned long *)((unsigned long)p->screen_base & ~(bytes-1));
263 dst_idx = ((unsigned long)p->screen_base & (bytes - 1))*8;
264 dst_idx += rect->dy*p->fix.line_length*8+rect->dx*bpp;
265 /* FIXME For now we support 1-32 bpp only */
266 left = bits % bpp;
267 if (p->fbops->fb_sync)
268 p->fbops->fb_sync(p);
269 if (!left) {
270 void (*fill_op32)(unsigned long *dst, int dst_idx,
271 unsigned long pat, unsigned n, int bits) =
272 NULL;
273
274 switch (rect->rop) {
275 case ROP_XOR:
276 fill_op32 = bitfill_aligned_rev;
277 break;
278 case ROP_COPY:
279 fill_op32 = bitfill_aligned;
280 break;
281 default:
282 printk( KERN_ERR "cfb_fillrect(): unknown rop, "
283 "defaulting to ROP_COPY\n");
284 fill_op32 = bitfill_aligned;
285 break;
286 }
287 while (height--) {
288 dst += dst_idx >> (ffs(bits) - 1);
289 dst_idx &= (bits - 1);
290 fill_op32(dst, dst_idx, pat, width*bpp, bits);
291 dst_idx += p->fix.line_length*8;
292 }
293 } else {
294 int right;
295 int r;
296 int rot = (left-dst_idx) % bpp;
297 void (*fill_op)(unsigned long *dst, int dst_idx,
298 unsigned long pat, int left, int right,
299 unsigned n, int bits) = NULL;
300
301 /* rotate pattern to correct start position */
302 pat = pat << rot | pat >> (bpp-rot);
303
304 right = bpp-left;
305 switch (rect->rop) {
306 case ROP_XOR:
307 fill_op = bitfill_unaligned_rev;
308 break;
309 case ROP_COPY:
310 fill_op = bitfill_unaligned;
311 break;
312 default:
313 printk(KERN_ERR "cfb_fillrect(): unknown rop, "
314 "defaulting to ROP_COPY\n");
315 fill_op = bitfill_unaligned;
316 break;
317 }
318 while (height--) {
319 dst += dst_idx >> (ffs(bits) - 1);
320 dst_idx &= (bits - 1);
321 fill_op(dst, dst_idx, pat, left, right,
322 width*bpp, bits);
323 r = (p->fix.line_length*8) % bpp;
324 pat = pat << (bpp-r) | pat >> r;
325 dst_idx += p->fix.line_length*8;
326 }
327 }
328}
329
330EXPORT_SYMBOL(sys_fillrect);
331
332MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
333MODULE_DESCRIPTION("Generic fill rectangle (sys-to-sys)");
334MODULE_LICENSE("GPL");
diff --git a/drivers/video/sysimgblt.c b/drivers/video/sysimgblt.c
new file mode 100644
index 000000000000..bd7e7e9d155f
--- /dev/null
+++ b/drivers/video/sysimgblt.c
@@ -0,0 +1,291 @@
1/*
2 * Generic 1-bit or 8-bit source to 1-32 bit destination expansion
3 * for frame buffer located in system RAM with packed pixels of any depth.
4 *
5 * Based almost entirely on cfbimgblt.c
6 *
7 * Copyright (C) April 2007 Antonino Daplas <adaplas@pol.net>
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for
11 * more details.
12 */
13#include <linux/module.h>
14#include <linux/string.h>
15#include <linux/fb.h>
16#include <asm/types.h>
17
18#define DEBUG
19
20#ifdef DEBUG
21#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt,__FUNCTION__,## args)
22#else
23#define DPRINTK(fmt, args...)
24#endif
25
26static const u32 cfb_tab8[] = {
27#if defined(__BIG_ENDIAN)
28 0x00000000,0x000000ff,0x0000ff00,0x0000ffff,
29 0x00ff0000,0x00ff00ff,0x00ffff00,0x00ffffff,
30 0xff000000,0xff0000ff,0xff00ff00,0xff00ffff,
31 0xffff0000,0xffff00ff,0xffffff00,0xffffffff
32#elif defined(__LITTLE_ENDIAN)
33 0x00000000,0xff000000,0x00ff0000,0xffff0000,
34 0x0000ff00,0xff00ff00,0x00ffff00,0xffffff00,
35 0x000000ff,0xff0000ff,0x00ff00ff,0xffff00ff,
36 0x0000ffff,0xff00ffff,0x00ffffff,0xffffffff
37#else
38#error FIXME: No endianness??
39#endif
40};
41
42static const u32 cfb_tab16[] = {
43#if defined(__BIG_ENDIAN)
44 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
45#elif defined(__LITTLE_ENDIAN)
46 0x00000000, 0xffff0000, 0x0000ffff, 0xffffffff
47#else
48#error FIXME: No endianness??
49#endif
50};
51
52static const u32 cfb_tab32[] = {
53 0x00000000, 0xffffffff
54};
55
56static void color_imageblit(const struct fb_image *image, struct fb_info *p,
57 void *dst1, u32 start_index, u32 pitch_index)
58{
59 /* Draw the penguin */
60 u32 *dst, *dst2;
61 u32 color = 0, val, shift;
62 int i, n, bpp = p->var.bits_per_pixel;
63 u32 null_bits = 32 - bpp;
64 u32 *palette = (u32 *) p->pseudo_palette;
65 const u8 *src = image->data;
66
67 dst2 = dst1;
68 for (i = image->height; i--; ) {
69 n = image->width;
70 dst = dst1;
71 shift = 0;
72 val = 0;
73
74 if (start_index) {
75 u32 start_mask = ~(FB_SHIFT_HIGH(~(u32)0,
76 start_index));
77 val = *dst & start_mask;
78 shift = start_index;
79 }
80 while (n--) {
81 if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
82 p->fix.visual == FB_VISUAL_DIRECTCOLOR )
83 color = palette[*src];
84 else
85 color = *src;
86 color <<= FB_LEFT_POS(bpp);
87 val |= FB_SHIFT_HIGH(color, shift);
88 if (shift >= null_bits) {
89 *dst++ = val;
90
91 val = (shift == null_bits) ? 0 :
92 FB_SHIFT_LOW(color, 32 - shift);
93 }
94 shift += bpp;
95 shift &= (32 - 1);
96 src++;
97 }
98 if (shift) {
99 u32 end_mask = FB_SHIFT_HIGH(~(u32)0, shift);
100
101 *dst &= end_mask;
102 *dst |= val;
103 }
104 dst1 += p->fix.line_length;
105 if (pitch_index) {
106 dst2 += p->fix.line_length;
107 dst1 = (u8 *)((long)dst2 & ~(sizeof(u32) - 1));
108
109 start_index += pitch_index;
110 start_index &= 32 - 1;
111 }
112 }
113}
114
115static void slow_imageblit(const struct fb_image *image, struct fb_info *p,
116 void *dst1, u32 fgcolor, u32 bgcolor,
117 u32 start_index, u32 pitch_index)
118{
119 u32 shift, color = 0, bpp = p->var.bits_per_pixel;
120 u32 *dst, *dst2;
121 u32 val, pitch = p->fix.line_length;
122 u32 null_bits = 32 - bpp;
123 u32 spitch = (image->width+7)/8;
124 const u8 *src = image->data, *s;
125 u32 i, j, l;
126
127 dst2 = dst1;
128 fgcolor <<= FB_LEFT_POS(bpp);
129 bgcolor <<= FB_LEFT_POS(bpp);
130
131 for (i = image->height; i--; ) {
132 shift = val = 0;
133 l = 8;
134 j = image->width;
135 dst = dst1;
136 s = src;
137
138 /* write leading bits */
139 if (start_index) {
140 u32 start_mask = ~(FB_SHIFT_HIGH(~(u32)0,start_index));
141 val = *dst & start_mask;
142 shift = start_index;
143 }
144
145 while (j--) {
146 l--;
147 color = (*s & (1 << l)) ? fgcolor : bgcolor;
148 val |= FB_SHIFT_HIGH(color, shift);
149
150 /* Did the bitshift spill bits to the next long? */
151 if (shift >= null_bits) {
152 *dst++ = val;
153 val = (shift == null_bits) ? 0 :
154 FB_SHIFT_LOW(color,32 - shift);
155 }
156 shift += bpp;
157 shift &= (32 - 1);
158 if (!l) { l = 8; s++; };
159 }
160
161 /* write trailing bits */
162 if (shift) {
163 u32 end_mask = FB_SHIFT_HIGH(~(u32)0, shift);
164
165 *dst &= end_mask;
166 *dst |= val;
167 }
168
169 dst1 += pitch;
170 src += spitch;
171 if (pitch_index) {
172 dst2 += pitch;
173 dst1 = (u8 *)((long)dst2 & ~(sizeof(u32) - 1));
174 start_index += pitch_index;
175 start_index &= 32 - 1;
176 }
177
178 }
179}
180
181/*
182 * fast_imageblit - optimized monochrome color expansion
183 *
184 * Only if: bits_per_pixel == 8, 16, or 32
185 * image->width is divisible by pixel/dword (ppw);
186 * fix->line_legth is divisible by 4;
187 * beginning and end of a scanline is dword aligned
188 */
189static void fast_imageblit(const struct fb_image *image, struct fb_info *p,
190 void *dst1, u32 fgcolor, u32 bgcolor)
191{
192 u32 fgx = fgcolor, bgx = bgcolor, bpp = p->var.bits_per_pixel;
193 u32 ppw = 32/bpp, spitch = (image->width + 7)/8;
194 u32 bit_mask, end_mask, eorx, shift;
195 const char *s = image->data, *src;
196 u32 *dst;
197 const u32 *tab = NULL;
198 int i, j, k;
199
200 switch (bpp) {
201 case 8:
202 tab = cfb_tab8;
203 break;
204 case 16:
205 tab = cfb_tab16;
206 break;
207 case 32:
208 default:
209 tab = cfb_tab32;
210 break;
211 }
212
213 for (i = ppw-1; i--; ) {
214 fgx <<= bpp;
215 bgx <<= bpp;
216 fgx |= fgcolor;
217 bgx |= bgcolor;
218 }
219
220 bit_mask = (1 << ppw) - 1;
221 eorx = fgx ^ bgx;
222 k = image->width/ppw;
223
224 for (i = image->height; i--; ) {
225 dst = dst1;
226 shift = 8;
227 src = s;
228
229 for (j = k; j--; ) {
230 shift -= ppw;
231 end_mask = tab[(*src >> shift) & bit_mask];
232 *dst++ = (end_mask & eorx) ^ bgx;
233 if (!shift) {
234 shift = 8;
235 src++;
236 }
237 }
238 dst1 += p->fix.line_length;
239 s += spitch;
240 }
241}
242
243void sys_imageblit(struct fb_info *p, const struct fb_image *image)
244{
245 u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
246 u32 bpl = sizeof(u32), bpp = p->var.bits_per_pixel;
247 u32 width = image->width;
248 u32 dx = image->dx, dy = image->dy;
249 void *dst1;
250
251 if (p->state != FBINFO_STATE_RUNNING)
252 return;
253
254 bitstart = (dy * p->fix.line_length * 8) + (dx * bpp);
255 start_index = bitstart & (32 - 1);
256 pitch_index = (p->fix.line_length & (bpl - 1)) * 8;
257
258 bitstart /= 8;
259 bitstart &= ~(bpl - 1);
260 dst1 = (void __force *)p->screen_base + bitstart;
261
262 if (p->fbops->fb_sync)
263 p->fbops->fb_sync(p);
264
265 if (image->depth == 1) {
266 if (p->fix.visual == FB_VISUAL_TRUECOLOR ||
267 p->fix.visual == FB_VISUAL_DIRECTCOLOR) {
268 fgcolor = ((u32*)(p->pseudo_palette))[image->fg_color];
269 bgcolor = ((u32*)(p->pseudo_palette))[image->bg_color];
270 } else {
271 fgcolor = image->fg_color;
272 bgcolor = image->bg_color;
273 }
274
275 if (32 % bpp == 0 && !start_index && !pitch_index &&
276 ((width & (32/bpp-1)) == 0) &&
277 bpp >= 8 && bpp <= 32)
278 fast_imageblit(image, p, dst1, fgcolor, bgcolor);
279 else
280 slow_imageblit(image, p, dst1, fgcolor, bgcolor,
281 start_index, pitch_index);
282 } else
283 color_imageblit(image, p, dst1, start_index, pitch_index);
284}
285
286EXPORT_SYMBOL(sys_imageblit);
287
288MODULE_AUTHOR("Antonino Daplas <adaplas@pol.net>");
289MODULE_DESCRIPTION("1-bit/8-bit to 1-32 bit color expansion (sys-to-sys)");
290MODULE_LICENSE("GPL");
291
diff --git a/drivers/video/tgafb.c b/drivers/video/tgafb.c
index 7478d0e3e211..f0fde6ea7c36 100644
--- a/drivers/video/tgafb.c
+++ b/drivers/video/tgafb.c
@@ -5,27 +5,45 @@
5 * Copyright (C) 1997 Geert Uytterhoeven 5 * Copyright (C) 1997 Geert Uytterhoeven
6 * Copyright (C) 1999,2000 Martin Lucina, Tom Zerucha 6 * Copyright (C) 1999,2000 Martin Lucina, Tom Zerucha
7 * Copyright (C) 2002 Richard Henderson 7 * Copyright (C) 2002 Richard Henderson
8 * Copyright (C) 2006 Maciej W. Rozycki
8 * 9 *
9 * This file is subject to the terms and conditions of the GNU General Public 10 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file COPYING in the main directory of this archive for 11 * License. See the file COPYING in the main directory of this archive for
11 * more details. 12 * more details.
12 */ 13 */
13 14
14#include <linux/module.h> 15#include <linux/bitrev.h>
15#include <linux/kernel.h>
16#include <linux/errno.h>
17#include <linux/string.h>
18#include <linux/mm.h>
19#include <linux/slab.h>
20#include <linux/delay.h> 16#include <linux/delay.h>
21#include <linux/init.h> 17#include <linux/device.h>
18#include <linux/errno.h>
22#include <linux/fb.h> 19#include <linux/fb.h>
20#include <linux/init.h>
21#include <linux/ioport.h>
22#include <linux/kernel.h>
23#include <linux/mm.h>
24#include <linux/module.h>
23#include <linux/pci.h> 25#include <linux/pci.h>
24#include <linux/selection.h> 26#include <linux/selection.h>
25#include <linux/bitrev.h> 27#include <linux/slab.h>
28#include <linux/string.h>
29#include <linux/tc.h>
30
26#include <asm/io.h> 31#include <asm/io.h>
32
27#include <video/tgafb.h> 33#include <video/tgafb.h>
28 34
35#ifdef CONFIG_PCI
36#define TGA_BUS_PCI(dev) (dev->bus == &pci_bus_type)
37#else
38#define TGA_BUS_PCI(dev) 0
39#endif
40
41#ifdef CONFIG_TC
42#define TGA_BUS_TC(dev) (dev->bus == &tc_bus_type)
43#else
44#define TGA_BUS_TC(dev) 0
45#endif
46
29/* 47/*
30 * Local functions. 48 * Local functions.
31 */ 49 */
@@ -41,14 +59,19 @@ static void tgafb_init_fix(struct fb_info *);
41static void tgafb_imageblit(struct fb_info *, const struct fb_image *); 59static void tgafb_imageblit(struct fb_info *, const struct fb_image *);
42static void tgafb_fillrect(struct fb_info *, const struct fb_fillrect *); 60static void tgafb_fillrect(struct fb_info *, const struct fb_fillrect *);
43static void tgafb_copyarea(struct fb_info *, const struct fb_copyarea *); 61static void tgafb_copyarea(struct fb_info *, const struct fb_copyarea *);
62static int tgafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info);
44 63
45static int __devinit tgafb_pci_register(struct pci_dev *, 64static int __devinit tgafb_register(struct device *dev);
46 const struct pci_device_id *); 65static void __devexit tgafb_unregister(struct device *dev);
47static void __devexit tgafb_pci_unregister(struct pci_dev *);
48 66
49static const char *mode_option = "640x480@60"; 67static const char *mode_option;
68static const char *mode_option_pci = "640x480@60";
69static const char *mode_option_tc = "1280x1024@72";
50 70
51 71
72static struct pci_driver tgafb_pci_driver;
73static struct tc_driver tgafb_tc_driver;
74
52/* 75/*
53 * Frame buffer operations 76 * Frame buffer operations
54 */ 77 */
@@ -59,15 +82,20 @@ static struct fb_ops tgafb_ops = {
59 .fb_set_par = tgafb_set_par, 82 .fb_set_par = tgafb_set_par,
60 .fb_setcolreg = tgafb_setcolreg, 83 .fb_setcolreg = tgafb_setcolreg,
61 .fb_blank = tgafb_blank, 84 .fb_blank = tgafb_blank,
85 .fb_pan_display = tgafb_pan_display,
62 .fb_fillrect = tgafb_fillrect, 86 .fb_fillrect = tgafb_fillrect,
63 .fb_copyarea = tgafb_copyarea, 87 .fb_copyarea = tgafb_copyarea,
64 .fb_imageblit = tgafb_imageblit, 88 .fb_imageblit = tgafb_imageblit,
65}; 89};
66 90
67 91
92#ifdef CONFIG_PCI
68/* 93/*
69 * PCI registration operations 94 * PCI registration operations
70 */ 95 */
96static int __devinit tgafb_pci_register(struct pci_dev *,
97 const struct pci_device_id *);
98static void __devexit tgafb_pci_unregister(struct pci_dev *);
71 99
72static struct pci_device_id const tgafb_pci_table[] = { 100static struct pci_device_id const tgafb_pci_table[] = {
73 { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TGA) }, 101 { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TGA) },
@@ -75,13 +103,68 @@ static struct pci_device_id const tgafb_pci_table[] = {
75}; 103};
76MODULE_DEVICE_TABLE(pci, tgafb_pci_table); 104MODULE_DEVICE_TABLE(pci, tgafb_pci_table);
77 105
78static struct pci_driver tgafb_driver = { 106static struct pci_driver tgafb_pci_driver = {
79 .name = "tgafb", 107 .name = "tgafb",
80 .id_table = tgafb_pci_table, 108 .id_table = tgafb_pci_table,
81 .probe = tgafb_pci_register, 109 .probe = tgafb_pci_register,
82 .remove = __devexit_p(tgafb_pci_unregister), 110 .remove = __devexit_p(tgafb_pci_unregister),
83}; 111};
84 112
113static int __devinit
114tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
115{
116 return tgafb_register(&pdev->dev);
117}
118
119static void __devexit
120tgafb_pci_unregister(struct pci_dev *pdev)
121{
122 tgafb_unregister(&pdev->dev);
123}
124#endif /* CONFIG_PCI */
125
126#ifdef CONFIG_TC
127/*
128 * TC registration operations
129 */
130static int __devinit tgafb_tc_register(struct device *);
131static int __devexit tgafb_tc_unregister(struct device *);
132
133static struct tc_device_id const tgafb_tc_table[] = {
134 { "DEC ", "PMAGD-AA" },
135 { "DEC ", "PMAGD " },
136 { }
137};
138MODULE_DEVICE_TABLE(tc, tgafb_tc_table);
139
140static struct tc_driver tgafb_tc_driver = {
141 .id_table = tgafb_tc_table,
142 .driver = {
143 .name = "tgafb",
144 .bus = &tc_bus_type,
145 .probe = tgafb_tc_register,
146 .remove = __devexit_p(tgafb_tc_unregister),
147 },
148};
149
150static int __devinit
151tgafb_tc_register(struct device *dev)
152{
153 int status = tgafb_register(dev);
154 if (!status)
155 get_device(dev);
156 return status;
157}
158
159static int __devexit
160tgafb_tc_unregister(struct device *dev)
161{
162 put_device(dev);
163 tgafb_unregister(dev);
164 return 0;
165}
166#endif /* CONFIG_TC */
167
85 168
86/** 169/**
87 * tgafb_check_var - Optional function. Validates a var passed in. 170 * tgafb_check_var - Optional function. Validates a var passed in.
@@ -132,10 +215,10 @@ static int
132tgafb_set_par(struct fb_info *info) 215tgafb_set_par(struct fb_info *info)
133{ 216{
134 static unsigned int const deep_presets[4] = { 217 static unsigned int const deep_presets[4] = {
135 0x00014000, 218 0x00004000,
136 0x0001440d, 219 0x0000440d,
137 0xffffffff, 220 0xffffffff,
138 0x0001441d 221 0x0000441d
139 }; 222 };
140 static unsigned int const rasterop_presets[4] = { 223 static unsigned int const rasterop_presets[4] = {
141 0x00000003, 224 0x00000003,
@@ -157,6 +240,8 @@ tgafb_set_par(struct fb_info *info)
157 }; 240 };
158 241
159 struct tga_par *par = (struct tga_par *) info->par; 242 struct tga_par *par = (struct tga_par *) info->par;
243 int tga_bus_pci = TGA_BUS_PCI(par->dev);
244 int tga_bus_tc = TGA_BUS_TC(par->dev);
160 u32 htimings, vtimings, pll_freq; 245 u32 htimings, vtimings, pll_freq;
161 u8 tga_type; 246 u8 tga_type;
162 int i; 247 int i;
@@ -221,7 +306,7 @@ tgafb_set_par(struct fb_info *info)
221 TGA_WRITE_REG(par, vtimings, TGA_VERT_REG); 306 TGA_WRITE_REG(par, vtimings, TGA_VERT_REG);
222 307
223 /* Initalise RAMDAC. */ 308 /* Initalise RAMDAC. */
224 if (tga_type == TGA_TYPE_8PLANE) { 309 if (tga_type == TGA_TYPE_8PLANE && tga_bus_pci) {
225 310
226 /* Init BT485 RAMDAC registers. */ 311 /* Init BT485 RAMDAC registers. */
227 BT485_WRITE(par, 0xa2 | (par->sync_on_green ? 0x8 : 0x0), 312 BT485_WRITE(par, 0xa2 | (par->sync_on_green ? 0x8 : 0x0),
@@ -236,21 +321,7 @@ tgafb_set_par(struct fb_info *info)
236 BT485_WRITE(par, 0x00, BT485_ADDR_PAL_WRITE); 321 BT485_WRITE(par, 0x00, BT485_ADDR_PAL_WRITE);
237 TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG); 322 TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG);
238 323
239#ifdef CONFIG_HW_CONSOLE
240 for (i = 0; i < 16; i++) {
241 int j = color_table[i];
242
243 TGA_WRITE_REG(par, default_red[j]|(BT485_DATA_PAL<<8),
244 TGA_RAMDAC_REG);
245 TGA_WRITE_REG(par, default_grn[j]|(BT485_DATA_PAL<<8),
246 TGA_RAMDAC_REG);
247 TGA_WRITE_REG(par, default_blu[j]|(BT485_DATA_PAL<<8),
248 TGA_RAMDAC_REG);
249 }
250 for (i = 0; i < 240 * 3; i += 4) {
251#else
252 for (i = 0; i < 256 * 3; i += 4) { 324 for (i = 0; i < 256 * 3; i += 4) {
253#endif
254 TGA_WRITE_REG(par, 0x55 | (BT485_DATA_PAL << 8), 325 TGA_WRITE_REG(par, 0x55 | (BT485_DATA_PAL << 8),
255 TGA_RAMDAC_REG); 326 TGA_RAMDAC_REG);
256 TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8), 327 TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
@@ -261,6 +332,27 @@ tgafb_set_par(struct fb_info *info)
261 TGA_RAMDAC_REG); 332 TGA_RAMDAC_REG);
262 } 333 }
263 334
335 } else if (tga_type == TGA_TYPE_8PLANE && tga_bus_tc) {
336
337 /* Init BT459 RAMDAC registers. */
338 BT459_WRITE(par, BT459_REG_ACC, BT459_CMD_REG_0, 0x40);
339 BT459_WRITE(par, BT459_REG_ACC, BT459_CMD_REG_1, 0x00);
340 BT459_WRITE(par, BT459_REG_ACC, BT459_CMD_REG_2,
341 (par->sync_on_green ? 0xc0 : 0x40));
342
343 BT459_WRITE(par, BT459_REG_ACC, BT459_CUR_CMD_REG, 0x00);
344
345 /* Fill the palette. */
346 BT459_LOAD_ADDR(par, 0x0000);
347 TGA_WRITE_REG(par, BT459_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
348
349 for (i = 0; i < 256 * 3; i += 4) {
350 TGA_WRITE_REG(par, 0x55, TGA_RAMDAC_REG);
351 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
352 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
353 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
354 }
355
264 } else { /* 24-plane or 24plusZ */ 356 } else { /* 24-plane or 24plusZ */
265 357
266 /* Init BT463 RAMDAC registers. */ 358 /* Init BT463 RAMDAC registers. */
@@ -431,6 +523,8 @@ tgafb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
431 unsigned transp, struct fb_info *info) 523 unsigned transp, struct fb_info *info)
432{ 524{
433 struct tga_par *par = (struct tga_par *) info->par; 525 struct tga_par *par = (struct tga_par *) info->par;
526 int tga_bus_pci = TGA_BUS_PCI(par->dev);
527 int tga_bus_tc = TGA_BUS_TC(par->dev);
434 528
435 if (regno > 255) 529 if (regno > 255)
436 return 1; 530 return 1;
@@ -438,12 +532,18 @@ tgafb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
438 green >>= 8; 532 green >>= 8;
439 blue >>= 8; 533 blue >>= 8;
440 534
441 if (par->tga_type == TGA_TYPE_8PLANE) { 535 if (par->tga_type == TGA_TYPE_8PLANE && tga_bus_pci) {
442 BT485_WRITE(par, regno, BT485_ADDR_PAL_WRITE); 536 BT485_WRITE(par, regno, BT485_ADDR_PAL_WRITE);
443 TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG); 537 TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG);
444 TGA_WRITE_REG(par, red|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG); 538 TGA_WRITE_REG(par, red|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
445 TGA_WRITE_REG(par, green|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG); 539 TGA_WRITE_REG(par, green|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
446 TGA_WRITE_REG(par, blue|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG); 540 TGA_WRITE_REG(par, blue|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
541 } else if (par->tga_type == TGA_TYPE_8PLANE && tga_bus_tc) {
542 BT459_LOAD_ADDR(par, regno);
543 TGA_WRITE_REG(par, BT459_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
544 TGA_WRITE_REG(par, red, TGA_RAMDAC_REG);
545 TGA_WRITE_REG(par, green, TGA_RAMDAC_REG);
546 TGA_WRITE_REG(par, blue, TGA_RAMDAC_REG);
447 } else { 547 } else {
448 if (regno < 16) { 548 if (regno < 16) {
449 u32 value = (regno << 16) | (regno << 8) | regno; 549 u32 value = (regno << 16) | (regno << 8) | regno;
@@ -523,16 +623,8 @@ tgafb_blank(int blank, struct fb_info *info)
523 * Acceleration. 623 * Acceleration.
524 */ 624 */
525 625
526/**
527 * tgafb_imageblit - REQUIRED function. Can use generic routines if
528 * non acclerated hardware and packed pixel based.
529 * Copies a image from system memory to the screen.
530 *
531 * @info: frame buffer structure that represents a single frame buffer
532 * @image: structure defining the image.
533 */
534static void 626static void
535tgafb_imageblit(struct fb_info *info, const struct fb_image *image) 627tgafb_mono_imageblit(struct fb_info *info, const struct fb_image *image)
536{ 628{
537 struct tga_par *par = (struct tga_par *) info->par; 629 struct tga_par *par = (struct tga_par *) info->par;
538 u32 fgcolor, bgcolor, dx, dy, width, height, vxres, vyres, pixelmask; 630 u32 fgcolor, bgcolor, dx, dy, width, height, vxres, vyres, pixelmask;
@@ -542,6 +634,17 @@ tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
542 void __iomem *regs_base; 634 void __iomem *regs_base;
543 void __iomem *fb_base; 635 void __iomem *fb_base;
544 636
637 is8bpp = info->var.bits_per_pixel == 8;
638
639 /* For copies that aren't pixel expansion, there's little we
640 can do better than the generic code. */
641 /* ??? There is a DMA write mode; I wonder if that could be
642 made to pull the data from the image buffer... */
643 if (image->depth > 1) {
644 cfb_imageblit(info, image);
645 return;
646 }
647
545 dx = image->dx; 648 dx = image->dx;
546 dy = image->dy; 649 dy = image->dy;
547 width = image->width; 650 width = image->width;
@@ -559,18 +662,8 @@ tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
559 if (dy + height > vyres) 662 if (dy + height > vyres)
560 height = vyres - dy; 663 height = vyres - dy;
561 664
562 /* For copies that aren't pixel expansion, there's little we
563 can do better than the generic code. */
564 /* ??? There is a DMA write mode; I wonder if that could be
565 made to pull the data from the image buffer... */
566 if (image->depth > 1) {
567 cfb_imageblit(info, image);
568 return;
569 }
570
571 regs_base = par->tga_regs_base; 665 regs_base = par->tga_regs_base;
572 fb_base = par->tga_fb_base; 666 fb_base = par->tga_fb_base;
573 is8bpp = info->var.bits_per_pixel == 8;
574 667
575 /* Expand the color values to fill 32-bits. */ 668 /* Expand the color values to fill 32-bits. */
576 /* ??? Would be nice to notice colour changes elsewhere, so 669 /* ??? Would be nice to notice colour changes elsewhere, so
@@ -748,6 +841,85 @@ tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
748 regs_base + TGA_MODE_REG); 841 regs_base + TGA_MODE_REG);
749} 842}
750 843
844static void
845tgafb_clut_imageblit(struct fb_info *info, const struct fb_image *image)
846{
847 struct tga_par *par = (struct tga_par *) info->par;
848 u32 color, dx, dy, width, height, vxres, vyres;
849 u32 *palette = ((u32 *)info->pseudo_palette);
850 unsigned long pos, line_length, i, j;
851 const unsigned char *data;
852 void *regs_base, *fb_base;
853
854 dx = image->dx;
855 dy = image->dy;
856 width = image->width;
857 height = image->height;
858 vxres = info->var.xres_virtual;
859 vyres = info->var.yres_virtual;
860 line_length = info->fix.line_length;
861
862 /* Crop the image to the screen. */
863 if (dx > vxres || dy > vyres)
864 return;
865 if (dx + width > vxres)
866 width = vxres - dx;
867 if (dy + height > vyres)
868 height = vyres - dy;
869
870 regs_base = par->tga_regs_base;
871 fb_base = par->tga_fb_base;
872
873 pos = dy * line_length + (dx * 4);
874 data = image->data;
875
876 /* Now copy the image, color_expanding via the palette. */
877 for (i = 0; i < height; i++) {
878 for (j = 0; j < width; j++) {
879 color = palette[*data++];
880 __raw_writel(color, fb_base + pos + j*4);
881 }
882 pos += line_length;
883 }
884}
885
886/**
887 * tgafb_imageblit - REQUIRED function. Can use generic routines if
888 * non acclerated hardware and packed pixel based.
889 * Copies a image from system memory to the screen.
890 *
891 * @info: frame buffer structure that represents a single frame buffer
892 * @image: structure defining the image.
893 */
894static void
895tgafb_imageblit(struct fb_info *info, const struct fb_image *image)
896{
897 unsigned int is8bpp = info->var.bits_per_pixel == 8;
898
899 /* If a mono image, regardless of FB depth, go do it. */
900 if (image->depth == 1) {
901 tgafb_mono_imageblit(info, image);
902 return;
903 }
904
905 /* For copies that aren't pixel expansion, there's little we
906 can do better than the generic code. */
907 /* ??? There is a DMA write mode; I wonder if that could be
908 made to pull the data from the image buffer... */
909 if (image->depth == info->var.bits_per_pixel) {
910 cfb_imageblit(info, image);
911 return;
912 }
913
914 /* If 24-plane FB and the image is 8-plane with CLUT, we can do it. */
915 if (!is8bpp && image->depth == 8) {
916 tgafb_clut_imageblit(info, image);
917 return;
918 }
919
920 /* Silently return... */
921}
922
751/** 923/**
752 * tgafb_fillrect - REQUIRED function. Can use generic routines if 924 * tgafb_fillrect - REQUIRED function. Can use generic routines if
753 * non acclerated hardware and packed pixel based. 925 * non acclerated hardware and packed pixel based.
@@ -1309,18 +1481,29 @@ static void
1309tgafb_init_fix(struct fb_info *info) 1481tgafb_init_fix(struct fb_info *info)
1310{ 1482{
1311 struct tga_par *par = (struct tga_par *)info->par; 1483 struct tga_par *par = (struct tga_par *)info->par;
1484 int tga_bus_pci = TGA_BUS_PCI(par->dev);
1485 int tga_bus_tc = TGA_BUS_TC(par->dev);
1312 u8 tga_type = par->tga_type; 1486 u8 tga_type = par->tga_type;
1313 const char *tga_type_name; 1487 const char *tga_type_name = NULL;
1314 1488
1315 switch (tga_type) { 1489 switch (tga_type) {
1316 case TGA_TYPE_8PLANE: 1490 case TGA_TYPE_8PLANE:
1317 tga_type_name = "Digital ZLXp-E1"; 1491 if (tga_bus_pci)
1492 tga_type_name = "Digital ZLXp-E1";
1493 if (tga_bus_tc)
1494 tga_type_name = "Digital ZLX-E1";
1318 break; 1495 break;
1319 case TGA_TYPE_24PLANE: 1496 case TGA_TYPE_24PLANE:
1320 tga_type_name = "Digital ZLXp-E2"; 1497 if (tga_bus_pci)
1498 tga_type_name = "Digital ZLXp-E2";
1499 if (tga_bus_tc)
1500 tga_type_name = "Digital ZLX-E2";
1321 break; 1501 break;
1322 case TGA_TYPE_24PLUSZ: 1502 case TGA_TYPE_24PLUSZ:
1323 tga_type_name = "Digital ZLXp-E3"; 1503 if (tga_bus_pci)
1504 tga_type_name = "Digital ZLXp-E3";
1505 if (tga_bus_tc)
1506 tga_type_name = "Digital ZLX-E3";
1324 break; 1507 break;
1325 default: 1508 default:
1326 tga_type_name = "Unknown"; 1509 tga_type_name = "Unknown";
@@ -1346,11 +1529,37 @@ tgafb_init_fix(struct fb_info *info)
1346 info->fix.ywrapstep = 0; 1529 info->fix.ywrapstep = 0;
1347 1530
1348 info->fix.accel = FB_ACCEL_DEC_TGA; 1531 info->fix.accel = FB_ACCEL_DEC_TGA;
1532
1533 /*
1534 * These are needed by fb_set_logo_truepalette(), so we
1535 * set them here for 24-plane cards.
1536 */
1537 if (tga_type != TGA_TYPE_8PLANE) {
1538 info->var.red.length = 8;
1539 info->var.green.length = 8;
1540 info->var.blue.length = 8;
1541 info->var.red.offset = 16;
1542 info->var.green.offset = 8;
1543 info->var.blue.offset = 0;
1544 }
1349} 1545}
1350 1546
1351static __devinit int 1547static int tgafb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
1352tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent) 1548{
1549 /* We just use this to catch switches out of graphics mode. */
1550 tgafb_set_par(info); /* A bit of overkill for BASE_ADDR reset. */
1551 return 0;
1552}
1553
1554static int __devinit
1555tgafb_register(struct device *dev)
1353{ 1556{
1557 static const struct fb_videomode modedb_tc = {
1558 /* 1280x1024 @ 72 Hz, 76.8 kHz hsync */
1559 "1280x1024@72", 0, 1280, 1024, 7645, 224, 28, 33, 3, 160, 3,
1560 FB_SYNC_ON_GREEN, FB_VMODE_NONINTERLACED
1561 };
1562
1354 static unsigned int const fb_offset_presets[4] = { 1563 static unsigned int const fb_offset_presets[4] = {
1355 TGA_8PLANE_FB_OFFSET, 1564 TGA_8PLANE_FB_OFFSET,
1356 TGA_24PLANE_FB_OFFSET, 1565 TGA_24PLANE_FB_OFFSET,
@@ -1358,40 +1567,51 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1358 TGA_24PLUSZ_FB_OFFSET 1567 TGA_24PLUSZ_FB_OFFSET
1359 }; 1568 };
1360 1569
1570 const struct fb_videomode *modedb_tga = NULL;
1571 resource_size_t bar0_start = 0, bar0_len = 0;
1572 const char *mode_option_tga = NULL;
1573 int tga_bus_pci = TGA_BUS_PCI(dev);
1574 int tga_bus_tc = TGA_BUS_TC(dev);
1575 unsigned int modedbsize_tga = 0;
1361 void __iomem *mem_base; 1576 void __iomem *mem_base;
1362 unsigned long bar0_start, bar0_len;
1363 struct fb_info *info; 1577 struct fb_info *info;
1364 struct tga_par *par; 1578 struct tga_par *par;
1365 u8 tga_type; 1579 u8 tga_type;
1366 int ret; 1580 int ret = 0;
1367 1581
1368 /* Enable device in PCI config. */ 1582 /* Enable device in PCI config. */
1369 if (pci_enable_device(pdev)) { 1583 if (tga_bus_pci && pci_enable_device(to_pci_dev(dev))) {
1370 printk(KERN_ERR "tgafb: Cannot enable PCI device\n"); 1584 printk(KERN_ERR "tgafb: Cannot enable PCI device\n");
1371 return -ENODEV; 1585 return -ENODEV;
1372 } 1586 }
1373 1587
1374 /* Allocate the fb and par structures. */ 1588 /* Allocate the fb and par structures. */
1375 info = framebuffer_alloc(sizeof(struct tga_par), &pdev->dev); 1589 info = framebuffer_alloc(sizeof(struct tga_par), dev);
1376 if (!info) { 1590 if (!info) {
1377 printk(KERN_ERR "tgafb: Cannot allocate memory\n"); 1591 printk(KERN_ERR "tgafb: Cannot allocate memory\n");
1378 return -ENOMEM; 1592 return -ENOMEM;
1379 } 1593 }
1380 1594
1381 par = info->par; 1595 par = info->par;
1382 pci_set_drvdata(pdev, info); 1596 dev_set_drvdata(dev, info);
1383 1597
1384 /* Request the mem regions. */ 1598 /* Request the mem regions. */
1385 bar0_start = pci_resource_start(pdev, 0);
1386 bar0_len = pci_resource_len(pdev, 0);
1387 ret = -ENODEV; 1599 ret = -ENODEV;
1600 if (tga_bus_pci) {
1601 bar0_start = pci_resource_start(to_pci_dev(dev), 0);
1602 bar0_len = pci_resource_len(to_pci_dev(dev), 0);
1603 }
1604 if (tga_bus_tc) {
1605 bar0_start = to_tc_dev(dev)->resource.start;
1606 bar0_len = to_tc_dev(dev)->resource.end - bar0_start + 1;
1607 }
1388 if (!request_mem_region (bar0_start, bar0_len, "tgafb")) { 1608 if (!request_mem_region (bar0_start, bar0_len, "tgafb")) {
1389 printk(KERN_ERR "tgafb: cannot reserve FB region\n"); 1609 printk(KERN_ERR "tgafb: cannot reserve FB region\n");
1390 goto err0; 1610 goto err0;
1391 } 1611 }
1392 1612
1393 /* Map the framebuffer. */ 1613 /* Map the framebuffer. */
1394 mem_base = ioremap(bar0_start, bar0_len); 1614 mem_base = ioremap_nocache(bar0_start, bar0_len);
1395 if (!mem_base) { 1615 if (!mem_base) {
1396 printk(KERN_ERR "tgafb: Cannot map MMIO\n"); 1616 printk(KERN_ERR "tgafb: Cannot map MMIO\n");
1397 goto err1; 1617 goto err1;
@@ -1399,12 +1619,16 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1399 1619
1400 /* Grab info about the card. */ 1620 /* Grab info about the card. */
1401 tga_type = (readl(mem_base) >> 12) & 0x0f; 1621 tga_type = (readl(mem_base) >> 12) & 0x0f;
1402 par->pdev = pdev; 1622 par->dev = dev;
1403 par->tga_mem_base = mem_base; 1623 par->tga_mem_base = mem_base;
1404 par->tga_fb_base = mem_base + fb_offset_presets[tga_type]; 1624 par->tga_fb_base = mem_base + fb_offset_presets[tga_type];
1405 par->tga_regs_base = mem_base + TGA_REGS_OFFSET; 1625 par->tga_regs_base = mem_base + TGA_REGS_OFFSET;
1406 par->tga_type = tga_type; 1626 par->tga_type = tga_type;
1407 pci_read_config_byte(pdev, PCI_REVISION_ID, &par->tga_chip_rev); 1627 if (tga_bus_pci)
1628 pci_read_config_byte(to_pci_dev(dev), PCI_REVISION_ID,
1629 &par->tga_chip_rev);
1630 if (tga_bus_tc)
1631 par->tga_chip_rev = TGA_READ_REG(par, TGA_START_REG) & 0xff;
1408 1632
1409 /* Setup framebuffer. */ 1633 /* Setup framebuffer. */
1410 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA | 1634 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA |
@@ -1414,8 +1638,17 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1414 info->pseudo_palette = (void *)(par + 1); 1638 info->pseudo_palette = (void *)(par + 1);
1415 1639
1416 /* This should give a reasonable default video mode. */ 1640 /* This should give a reasonable default video mode. */
1417 1641 if (tga_bus_pci) {
1418 ret = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 1642 mode_option_tga = mode_option_pci;
1643 }
1644 if (tga_bus_tc) {
1645 mode_option_tga = mode_option_tc;
1646 modedb_tga = &modedb_tc;
1647 modedbsize_tga = 1;
1648 }
1649 ret = fb_find_mode(&info->var, info,
1650 mode_option ? mode_option : mode_option_tga,
1651 modedb_tga, modedbsize_tga, NULL,
1419 tga_type == TGA_TYPE_8PLANE ? 8 : 32); 1652 tga_type == TGA_TYPE_8PLANE ? 8 : 32);
1420 if (ret == 0 || ret == 4) { 1653 if (ret == 0 || ret == 4) {
1421 printk(KERN_ERR "tgafb: Could not find valid video mode\n"); 1654 printk(KERN_ERR "tgafb: Could not find valid video mode\n");
@@ -1438,13 +1671,19 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1438 goto err1; 1671 goto err1;
1439 } 1672 }
1440 1673
1441 printk(KERN_INFO "tgafb: DC21030 [TGA] detected, rev=0x%02x\n", 1674 if (tga_bus_pci) {
1442 par->tga_chip_rev); 1675 pr_info("tgafb: DC21030 [TGA] detected, rev=0x%02x\n",
1443 printk(KERN_INFO "tgafb: at PCI bus %d, device %d, function %d\n", 1676 par->tga_chip_rev);
1444 pdev->bus->number, PCI_SLOT(pdev->devfn), 1677 pr_info("tgafb: at PCI bus %d, device %d, function %d\n",
1445 PCI_FUNC(pdev->devfn)); 1678 to_pci_dev(dev)->bus->number,
1446 printk(KERN_INFO "fb%d: %s frame buffer device at 0x%lx\n", 1679 PCI_SLOT(to_pci_dev(dev)->devfn),
1447 info->node, info->fix.id, bar0_start); 1680 PCI_FUNC(to_pci_dev(dev)->devfn));
1681 }
1682 if (tga_bus_tc)
1683 pr_info("tgafb: SFB+ detected, rev=0x%02x\n",
1684 par->tga_chip_rev);
1685 pr_info("fb%d: %s frame buffer device at 0x%lx\n",
1686 info->node, info->fix.id, (long)bar0_start);
1448 1687
1449 return 0; 1688 return 0;
1450 1689
@@ -1458,25 +1697,39 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1458} 1697}
1459 1698
1460static void __devexit 1699static void __devexit
1461tgafb_pci_unregister(struct pci_dev *pdev) 1700tgafb_unregister(struct device *dev)
1462{ 1701{
1463 struct fb_info *info = pci_get_drvdata(pdev); 1702 resource_size_t bar0_start = 0, bar0_len = 0;
1464 struct tga_par *par = info->par; 1703 int tga_bus_pci = TGA_BUS_PCI(dev);
1704 int tga_bus_tc = TGA_BUS_TC(dev);
1705 struct fb_info *info = NULL;
1706 struct tga_par *par;
1465 1707
1708 info = dev_get_drvdata(dev);
1466 if (!info) 1709 if (!info)
1467 return; 1710 return;
1711
1712 par = info->par;
1468 unregister_framebuffer(info); 1713 unregister_framebuffer(info);
1469 fb_dealloc_cmap(&info->cmap); 1714 fb_dealloc_cmap(&info->cmap);
1470 iounmap(par->tga_mem_base); 1715 iounmap(par->tga_mem_base);
1471 release_mem_region(pci_resource_start(pdev, 0), 1716 if (tga_bus_pci) {
1472 pci_resource_len(pdev, 0)); 1717 bar0_start = pci_resource_start(to_pci_dev(dev), 0);
1718 bar0_len = pci_resource_len(to_pci_dev(dev), 0);
1719 }
1720 if (tga_bus_tc) {
1721 bar0_start = to_tc_dev(dev)->resource.start;
1722 bar0_len = to_tc_dev(dev)->resource.end - bar0_start + 1;
1723 }
1724 release_mem_region(bar0_start, bar0_len);
1473 framebuffer_release(info); 1725 framebuffer_release(info);
1474} 1726}
1475 1727
1476static void __devexit 1728static void __devexit
1477tgafb_exit(void) 1729tgafb_exit(void)
1478{ 1730{
1479 pci_unregister_driver(&tgafb_driver); 1731 tc_unregister_driver(&tgafb_tc_driver);
1732 pci_unregister_driver(&tgafb_pci_driver);
1480} 1733}
1481 1734
1482#ifndef MODULE 1735#ifndef MODULE
@@ -1505,6 +1758,7 @@ tgafb_setup(char *arg)
1505static int __devinit 1758static int __devinit
1506tgafb_init(void) 1759tgafb_init(void)
1507{ 1760{
1761 int status;
1508#ifndef MODULE 1762#ifndef MODULE
1509 char *option = NULL; 1763 char *option = NULL;
1510 1764
@@ -1512,7 +1766,10 @@ tgafb_init(void)
1512 return -ENODEV; 1766 return -ENODEV;
1513 tgafb_setup(option); 1767 tgafb_setup(option);
1514#endif 1768#endif
1515 return pci_register_driver(&tgafb_driver); 1769 status = pci_register_driver(&tgafb_pci_driver);
1770 if (!status)
1771 status = tc_register_driver(&tgafb_tc_driver);
1772 return status;
1516} 1773}
1517 1774
1518/* 1775/*
@@ -1522,5 +1779,5 @@ tgafb_init(void)
1522module_init(tgafb_init); 1779module_init(tgafb_init);
1523module_exit(tgafb_exit); 1780module_exit(tgafb_exit);
1524 1781
1525MODULE_DESCRIPTION("framebuffer driver for TGA chipset"); 1782MODULE_DESCRIPTION("Framebuffer driver for TGA/SFB+ chipset");
1526MODULE_LICENSE("GPL"); 1783MODULE_LICENSE("GPL");
diff --git a/drivers/video/vermilion/Makefile b/drivers/video/vermilion/Makefile
new file mode 100644
index 000000000000..cc21a656153d
--- /dev/null
+++ b/drivers/video/vermilion/Makefile
@@ -0,0 +1,5 @@
1obj-$(CONFIG_FB_LE80578) += vmlfb.o
2obj-$(CONFIG_FB_CARILLO_RANCH) += crvml.o
3
4vmlfb-objs := vermilion.o
5crvml-objs := cr_pll.o
diff --git a/drivers/video/vermilion/cr_pll.c b/drivers/video/vermilion/cr_pll.c
new file mode 100644
index 000000000000..ebc6e6e0dd0f
--- /dev/null
+++ b/drivers/video/vermilion/cr_pll.c
@@ -0,0 +1,208 @@
1/*
2 * Copyright (c) Intel Corp. 2007.
3 * All Rights Reserved.
4 *
5 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
6 * develop this driver.
7 *
8 * This file is part of the Carillo Ranch video subsystem driver.
9 * The Carillo Ranch video subsystem driver is free software;
10 * you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The Carillo Ranch video subsystem driver is distributed
16 * in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this driver; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 * Authors:
26 * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com>
27 * Alan Hourihane <alanh-at-tungstengraphics-dot-com>
28 */
29
30#include <linux/module.h>
31#include <linux/kernel.h>
32#include <linux/pci.h>
33#include <linux/errno.h>
34#include <linux/fb.h>
35#include "vermilion.h"
36
37/* The PLL Clock register sits on Host bridge */
38#define CRVML_DEVICE_MCH 0x5001
39#define CRVML_REG_MCHBAR 0x44
40#define CRVML_REG_MCHEN 0x54
41#define CRVML_MCHEN_BIT (1 << 28)
42#define CRVML_MCHMAP_SIZE 4096
43#define CRVML_REG_CLOCK 0xc3c
44#define CRVML_CLOCK_SHIFT 8
45#define CRVML_CLOCK_MASK 0x00000f00
46
47static struct pci_dev *mch_dev;
48static u32 mch_bar;
49static void __iomem *mch_regs_base;
50static u32 saved_clock;
51
52static const unsigned crvml_clocks[] = {
53 6750,
54 13500,
55 27000,
56 29700,
57 37125,
58 54000,
59 59400,
60 74250,
61 120000
62 /*
63 * There are more clocks, but they are disabled on the CR board.
64 */
65};
66
67static const u32 crvml_clock_bits[] = {
68 0x0a,
69 0x09,
70 0x08,
71 0x07,
72 0x06,
73 0x05,
74 0x04,
75 0x03,
76 0x0b
77};
78
79static const unsigned crvml_num_clocks = ARRAY_SIZE(crvml_clocks);
80
81static int crvml_sys_restore(struct vml_sys *sys)
82{
83 void __iomem *clock_reg = mch_regs_base + CRVML_REG_CLOCK;
84
85 iowrite32(saved_clock, clock_reg);
86 ioread32(clock_reg);
87
88 return 0;
89}
90
91static int crvml_sys_save(struct vml_sys *sys)
92{
93 void __iomem *clock_reg = mch_regs_base + CRVML_REG_CLOCK;
94
95 saved_clock = ioread32(clock_reg);
96
97 return 0;
98}
99
100static int crvml_nearest_index(const struct vml_sys *sys, int clock)
101{
102 int i;
103 int cur_index = 0;
104 int cur_diff;
105 int diff;
106
107 cur_diff = clock - crvml_clocks[0];
108 cur_diff = (cur_diff < 0) ? -cur_diff : cur_diff;
109 for (i = 1; i < crvml_num_clocks; ++i) {
110 diff = clock - crvml_clocks[i];
111 diff = (diff < 0) ? -diff : diff;
112 if (diff < cur_diff) {
113 cur_index = i;
114 cur_diff = diff;
115 }
116 }
117 return cur_index;
118}
119
120static int crvml_nearest_clock(const struct vml_sys *sys, int clock)
121{
122 return crvml_clocks[crvml_nearest_index(sys, clock)];
123}
124
125static int crvml_set_clock(struct vml_sys *sys, int clock)
126{
127 void __iomem *clock_reg = mch_regs_base + CRVML_REG_CLOCK;
128 int index;
129 u32 clock_val;
130
131 index = crvml_nearest_index(sys, clock);
132
133 if (crvml_clocks[index] != clock)
134 return -EINVAL;
135
136 clock_val = ioread32(clock_reg) & ~CRVML_CLOCK_MASK;
137 clock_val = crvml_clock_bits[index] << CRVML_CLOCK_SHIFT;
138 iowrite32(clock_val, clock_reg);
139 ioread32(clock_reg);
140
141 return 0;
142}
143
144static struct vml_sys cr_pll_ops = {
145 .name = "Carillo Ranch",
146 .save = crvml_sys_save,
147 .restore = crvml_sys_restore,
148 .set_clock = crvml_set_clock,
149 .nearest_clock = crvml_nearest_clock,
150};
151
152static int __init cr_pll_init(void)
153{
154 int err;
155 u32 dev_en;
156
157 mch_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
158 CRVML_DEVICE_MCH, NULL);
159 if (!mch_dev) {
160 printk(KERN_ERR
161 "Could not find Carillo Ranch MCH device.\n");
162 return -ENODEV;
163 }
164
165 pci_read_config_dword(mch_dev, CRVML_REG_MCHEN, &dev_en);
166 if (!(dev_en & CRVML_MCHEN_BIT)) {
167 printk(KERN_ERR
168 "Carillo Ranch MCH device was not enabled.\n");
169 pci_dev_put(mch_dev);
170 return -ENODEV;
171 }
172
173 pci_read_config_dword(mch_dev, CRVML_REG_MCHBAR,
174 &mch_bar);
175 mch_regs_base =
176 ioremap_nocache(mch_bar, CRVML_MCHMAP_SIZE);
177 if (!mch_regs_base) {
178 printk(KERN_ERR
179 "Carillo Ranch MCH device was not enabled.\n");
180 pci_dev_put(mch_dev);
181 return -ENODEV;
182 }
183
184 err = vmlfb_register_subsys(&cr_pll_ops);
185 if (err) {
186 printk(KERN_ERR
187 "Carillo Ranch failed to initialize vml_sys.\n");
188 pci_dev_put(mch_dev);
189 return err;
190 }
191
192 return 0;
193}
194
195static void __exit cr_pll_exit(void)
196{
197 vmlfb_unregister_subsys(&cr_pll_ops);
198
199 iounmap(mch_regs_base);
200 pci_dev_put(mch_dev);
201}
202
203module_init(cr_pll_init);
204module_exit(cr_pll_exit);
205
206MODULE_AUTHOR("Tungsten Graphics Inc.");
207MODULE_DESCRIPTION("Carillo Ranch PLL Driver");
208MODULE_LICENSE("GPL");
diff --git a/drivers/video/vermilion/vermilion.c b/drivers/video/vermilion/vermilion.c
new file mode 100644
index 000000000000..de531c907718
--- /dev/null
+++ b/drivers/video/vermilion/vermilion.c
@@ -0,0 +1,1195 @@
1/*
2 * Copyright (c) Intel Corp. 2007.
3 * All Rights Reserved.
4 *
5 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
6 * develop this driver.
7 *
8 * This file is part of the Vermilion Range fb driver.
9 * The Vermilion Range fb driver is free software;
10 * you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The Vermilion Range fb driver is distributed
16 * in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this driver; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 * Authors:
26 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
27 * Michel Dänzer <michel-at-tungstengraphics-dot-com>
28 * Alan Hourihane <alanh-at-tungstengraphics-dot-com>
29 */
30
31#include <linux/module.h>
32#include <linux/kernel.h>
33#include <linux/errno.h>
34#include <linux/string.h>
35#include <linux/delay.h>
36#include <linux/mm.h>
37#include <linux/fb.h>
38#include <linux/pci.h>
39#include <asm/cacheflush.h>
40#include <asm/tlbflush.h>
41#include <linux/mmzone.h>
42#include <asm/uaccess.h>
43
44/* #define VERMILION_DEBUG */
45
46#include "vermilion.h"
47
48#define MODULE_NAME "vmlfb"
49
50#define VML_TOHW(_val, _width) ((((_val) << (_width)) + 0x7FFF - (_val)) >> 16)
51
52static struct mutex vml_mutex;
53static struct list_head global_no_mode;
54static struct list_head global_has_mode;
55static struct fb_ops vmlfb_ops;
56static struct vml_sys *subsys = NULL;
57static char *vml_default_mode = "1024x768@60";
58static struct fb_videomode defaultmode = {
59 NULL, 60, 1024, 768, 12896, 144, 24, 29, 3, 136, 6,
60 0, FB_VMODE_NONINTERLACED
61};
62
63static u32 vml_mem_requested = (10 * 1024 * 1024);
64static u32 vml_mem_contig = (4 * 1024 * 1024);
65static u32 vml_mem_min = (4 * 1024 * 1024);
66
67static u32 vml_clocks[] = {
68 6750,
69 13500,
70 27000,
71 29700,
72 37125,
73 54000,
74 59400,
75 74250,
76 120000,
77 148500
78};
79
80static u32 vml_num_clocks = ARRAY_SIZE(vml_clocks);
81
82/*
83 * Allocate a contiguous vram area and make its linear kernel map
84 * uncached.
85 */
86
87static int vmlfb_alloc_vram_area(struct vram_area *va, unsigned max_order,
88 unsigned min_order)
89{
90 gfp_t flags;
91 unsigned long i;
92 pgprot_t wc_pageprot;
93
94 wc_pageprot = PAGE_KERNEL_NOCACHE;
95 max_order++;
96 do {
97 /*
98 * Really try hard to get the needed memory.
99 * We need memory below the first 32MB, so we
100 * add the __GFP_DMA flag that guarantees that we are
101 * below the first 16MB.
102 */
103
104 flags = __GFP_DMA | __GFP_HIGH;
105 va->logical =
106 __get_free_pages(flags, --max_order);
107 } while (va->logical == 0 && max_order > min_order);
108
109 if (!va->logical)
110 return -ENOMEM;
111
112 va->phys = virt_to_phys((void *)va->logical);
113 va->size = PAGE_SIZE << max_order;
114 va->order = max_order;
115
116 /*
117 * It seems like __get_free_pages only ups the usage count
118 * of the first page. This doesn't work with nopage mapping, so
119 * up the usage count once more.
120 */
121
122 memset((void *)va->logical, 0x00, va->size);
123 for (i = va->logical; i < va->logical + va->size; i += PAGE_SIZE) {
124 get_page(virt_to_page(i));
125 }
126
127 /*
128 * Change caching policy of the linear kernel map to avoid
129 * mapping type conflicts with user-space mappings.
130 * The first global_flush_tlb() is really only there to do a global
131 * wbinvd().
132 */
133
134 global_flush_tlb();
135 change_page_attr(virt_to_page(va->logical), va->size >> PAGE_SHIFT,
136 wc_pageprot);
137 global_flush_tlb();
138
139 printk(KERN_DEBUG MODULE_NAME
140 ": Allocated %ld bytes vram area at 0x%08lx\n",
141 va->size, va->phys);
142
143 return 0;
144}
145
146/*
147 * Free a contiguous vram area and reset its linear kernel map
148 * mapping type.
149 */
150
151static void vmlfb_free_vram_area(struct vram_area *va)
152{
153 unsigned long j;
154
155 if (va->logical) {
156
157 /*
158 * Reset the linear kernel map caching policy.
159 */
160
161 change_page_attr(virt_to_page(va->logical),
162 va->size >> PAGE_SHIFT, PAGE_KERNEL);
163 global_flush_tlb();
164
165 /*
166 * Decrease the usage count on the pages we've used
167 * to compensate for upping when allocating.
168 */
169
170 for (j = va->logical; j < va->logical + va->size;
171 j += PAGE_SIZE) {
172 (void)put_page_testzero(virt_to_page(j));
173 }
174
175 printk(KERN_DEBUG MODULE_NAME
176 ": Freeing %ld bytes vram area at 0x%08lx\n",
177 va->size, va->phys);
178 free_pages(va->logical, va->order);
179
180 va->logical = 0;
181 }
182}
183
184/*
185 * Free allocated vram.
186 */
187
188static void vmlfb_free_vram(struct vml_info *vinfo)
189{
190 int i;
191
192 for (i = 0; i < vinfo->num_areas; ++i) {
193 vmlfb_free_vram_area(&vinfo->vram[i]);
194 }
195 vinfo->num_areas = 0;
196}
197
198/*
199 * Allocate vram. Currently we try to allocate contiguous areas from the
200 * __GFP_DMA zone and puzzle them together. A better approach would be to
201 * allocate one contiguous area for scanout and use one-page allocations for
202 * offscreen areas. This requires user-space and GPU virtual mappings.
203 */
204
205static int vmlfb_alloc_vram(struct vml_info *vinfo,
206 size_t requested,
207 size_t min_total, size_t min_contig)
208{
209 int i, j;
210 int order;
211 int contiguous;
212 int err;
213 struct vram_area *va;
214 struct vram_area *va2;
215
216 vinfo->num_areas = 0;
217 for (i = 0; i < VML_VRAM_AREAS; ++i) {
218 va = &vinfo->vram[i];
219 order = 0;
220
221 while (requested > (PAGE_SIZE << order) && order < MAX_ORDER)
222 order++;
223
224 err = vmlfb_alloc_vram_area(va, order, 0);
225
226 if (err)
227 break;
228
229 if (i == 0) {
230 vinfo->vram_start = va->phys;
231 vinfo->vram_logical = (void __iomem *) va->logical;
232 vinfo->vram_contig_size = va->size;
233 vinfo->num_areas = 1;
234 } else {
235 contiguous = 0;
236
237 for (j = 0; j < i; ++j) {
238 va2 = &vinfo->vram[j];
239 if (va->phys + va->size == va2->phys ||
240 va2->phys + va2->size == va->phys) {
241 contiguous = 1;
242 break;
243 }
244 }
245
246 if (contiguous) {
247 vinfo->num_areas++;
248 if (va->phys < vinfo->vram_start) {
249 vinfo->vram_start = va->phys;
250 vinfo->vram_logical =
251 (void __iomem *)va->logical;
252 }
253 vinfo->vram_contig_size += va->size;
254 } else {
255 vmlfb_free_vram_area(va);
256 break;
257 }
258 }
259
260 if (requested < va->size)
261 break;
262 else
263 requested -= va->size;
264 }
265
266 if (vinfo->vram_contig_size > min_total &&
267 vinfo->vram_contig_size > min_contig) {
268
269 printk(KERN_DEBUG MODULE_NAME
270 ": Contiguous vram: %ld bytes at physical 0x%08lx.\n",
271 (unsigned long)vinfo->vram_contig_size,
272 (unsigned long)vinfo->vram_start);
273
274 return 0;
275 }
276
277 printk(KERN_ERR MODULE_NAME
278 ": Could not allocate requested minimal amount of vram.\n");
279
280 vmlfb_free_vram(vinfo);
281
282 return -ENOMEM;
283}
284
285/*
286 * Find the GPU to use with our display controller.
287 */
288
289static int vmlfb_get_gpu(struct vml_par *par)
290{
291 mutex_lock(&vml_mutex);
292
293 par->gpu = pci_get_device(PCI_VENDOR_ID_INTEL, VML_DEVICE_GPU, NULL);
294
295 if (!par->gpu) {
296 mutex_unlock(&vml_mutex);
297 return -ENODEV;
298 }
299
300 mutex_unlock(&vml_mutex);
301
302 if (pci_enable_device(par->gpu) < 0)
303 return -ENODEV;
304
305 return 0;
306}
307
308/*
309 * Find a contiguous vram area that contains a given offset from vram start.
310 */
311static int vmlfb_vram_offset(struct vml_info *vinfo, unsigned long offset)
312{
313 unsigned long aoffset;
314 unsigned i;
315
316 for (i = 0; i < vinfo->num_areas; ++i) {
317 aoffset = offset - (vinfo->vram[i].phys - vinfo->vram_start);
318
319 if (aoffset < vinfo->vram[i].size) {
320 return 0;
321 }
322 }
323
324 return -EINVAL;
325}
326
327/*
328 * Remap the MMIO register spaces of the VDC and the GPU.
329 */
330
331static int vmlfb_enable_mmio(struct vml_par *par)
332{
333 int err;
334
335 par->vdc_mem_base = pci_resource_start(par->vdc, 0);
336 par->vdc_mem_size = pci_resource_len(par->vdc, 0);
337 if (!request_mem_region(par->vdc_mem_base, par->vdc_mem_size, "vmlfb")) {
338 printk(KERN_ERR MODULE_NAME
339 ": Could not claim display controller MMIO.\n");
340 return -EBUSY;
341 }
342 par->vdc_mem = ioremap_nocache(par->vdc_mem_base, par->vdc_mem_size);
343 if (par->vdc_mem == NULL) {
344 printk(KERN_ERR MODULE_NAME
345 ": Could not map display controller MMIO.\n");
346 err = -ENOMEM;
347 goto out_err_0;
348 }
349
350 par->gpu_mem_base = pci_resource_start(par->gpu, 0);
351 par->gpu_mem_size = pci_resource_len(par->gpu, 0);
352 if (!request_mem_region(par->gpu_mem_base, par->gpu_mem_size, "vmlfb")) {
353 printk(KERN_ERR MODULE_NAME ": Could not claim GPU MMIO.\n");
354 err = -EBUSY;
355 goto out_err_1;
356 }
357 par->gpu_mem = ioremap_nocache(par->gpu_mem_base, par->gpu_mem_size);
358 if (par->gpu_mem == NULL) {
359 printk(KERN_ERR MODULE_NAME ": Could not map GPU MMIO.\n");
360 err = -ENOMEM;
361 goto out_err_2;
362 }
363
364 return 0;
365
366out_err_2:
367 release_mem_region(par->gpu_mem_base, par->gpu_mem_size);
368out_err_1:
369 iounmap(par->vdc_mem);
370out_err_0:
371 release_mem_region(par->vdc_mem_base, par->vdc_mem_size);
372 return err;
373}
374
375/*
376 * Unmap the VDC and GPU register spaces.
377 */
378
379static void vmlfb_disable_mmio(struct vml_par *par)
380{
381 iounmap(par->gpu_mem);
382 release_mem_region(par->gpu_mem_base, par->gpu_mem_size);
383 iounmap(par->vdc_mem);
384 release_mem_region(par->vdc_mem_base, par->vdc_mem_size);
385}
386
387/*
388 * Release and uninit the VDC and GPU.
389 */
390
391static void vmlfb_release_devices(struct vml_par *par)
392{
393 if (atomic_dec_and_test(&par->refcount)) {
394 pci_set_drvdata(par->vdc, NULL);
395 pci_disable_device(par->gpu);
396 pci_disable_device(par->vdc);
397 }
398}
399
400/*
401 * Free up allocated resources for a device.
402 */
403
404static void __devexit vml_pci_remove(struct pci_dev *dev)
405{
406 struct fb_info *info;
407 struct vml_info *vinfo;
408 struct vml_par *par;
409
410 info = pci_get_drvdata(dev);
411 if (info) {
412 vinfo = container_of(info, struct vml_info, info);
413 par = vinfo->par;
414 mutex_lock(&vml_mutex);
415 unregister_framebuffer(info);
416 fb_dealloc_cmap(&info->cmap);
417 vmlfb_free_vram(vinfo);
418 vmlfb_disable_mmio(par);
419 vmlfb_release_devices(par);
420 kfree(vinfo);
421 kfree(par);
422 mutex_unlock(&vml_mutex);
423 }
424}
425
426static void vmlfb_set_pref_pixel_format(struct fb_var_screeninfo *var)
427{
428 switch (var->bits_per_pixel) {
429 case 16:
430 var->blue.offset = 0;
431 var->blue.length = 5;
432 var->green.offset = 5;
433 var->green.length = 5;
434 var->red.offset = 10;
435 var->red.length = 5;
436 var->transp.offset = 15;
437 var->transp.length = 1;
438 break;
439 case 32:
440 var->blue.offset = 0;
441 var->blue.length = 8;
442 var->green.offset = 8;
443 var->green.length = 8;
444 var->red.offset = 16;
445 var->red.length = 8;
446 var->transp.offset = 24;
447 var->transp.length = 0;
448 break;
449 default:
450 break;
451 }
452
453 var->blue.msb_right = var->green.msb_right =
454 var->red.msb_right = var->transp.msb_right = 0;
455}
456
457/*
458 * Device initialization.
459 * We initialize one vml_par struct per device and one vml_info
460 * struct per pipe. Currently we have only one pipe.
461 */
462
463static int __devinit vml_pci_probe(struct pci_dev *dev,
464 const struct pci_device_id *id)
465{
466 struct vml_info *vinfo;
467 struct fb_info *info;
468 struct vml_par *par;
469 int err = 0;
470
471 par = kzalloc(sizeof(*par), GFP_KERNEL);
472 if (par == NULL)
473 return -ENOMEM;
474
475 vinfo = kzalloc(sizeof(*vinfo), GFP_KERNEL);
476 if (vinfo == NULL) {
477 err = -ENOMEM;
478 goto out_err_0;
479 }
480
481 vinfo->par = par;
482 par->vdc = dev;
483 atomic_set(&par->refcount, 1);
484
485 switch (id->device) {
486 case VML_DEVICE_VDC:
487 if ((err = vmlfb_get_gpu(par)))
488 goto out_err_1;
489 pci_set_drvdata(dev, &vinfo->info);
490 break;
491 default:
492 err = -ENODEV;
493 goto out_err_1;
494 break;
495 }
496
497 info = &vinfo->info;
498 info->flags = FBINFO_DEFAULT | FBINFO_PARTIAL_PAN_OK;
499
500 err = vmlfb_enable_mmio(par);
501 if (err)
502 goto out_err_2;
503
504 err = vmlfb_alloc_vram(vinfo, vml_mem_requested,
505 vml_mem_contig, vml_mem_min);
506 if (err)
507 goto out_err_3;
508
509 strcpy(info->fix.id, "Vermilion Range");
510 info->fix.mmio_start = 0;
511 info->fix.mmio_len = 0;
512 info->fix.smem_start = vinfo->vram_start;
513 info->fix.smem_len = vinfo->vram_contig_size;
514 info->fix.type = FB_TYPE_PACKED_PIXELS;
515 info->fix.visual = FB_VISUAL_TRUECOLOR;
516 info->fix.ypanstep = 1;
517 info->fix.xpanstep = 1;
518 info->fix.ywrapstep = 0;
519 info->fix.accel = FB_ACCEL_NONE;
520 info->screen_base = vinfo->vram_logical;
521 info->pseudo_palette = vinfo->pseudo_palette;
522 info->par = par;
523 info->fbops = &vmlfb_ops;
524 info->device = &dev->dev;
525
526 INIT_LIST_HEAD(&vinfo->head);
527 vinfo->pipe_disabled = 1;
528 vinfo->cur_blank_mode = FB_BLANK_UNBLANK;
529
530 info->var.grayscale = 0;
531 info->var.bits_per_pixel = 16;
532 vmlfb_set_pref_pixel_format(&info->var);
533
534 if (!fb_find_mode
535 (&info->var, info, vml_default_mode, NULL, 0, &defaultmode, 16)) {
536 printk(KERN_ERR MODULE_NAME ": Could not find initial mode\n");
537 }
538
539 if (fb_alloc_cmap(&info->cmap, 256, 1) < 0) {
540 err = -ENOMEM;
541 goto out_err_4;
542 }
543
544 err = register_framebuffer(info);
545 if (err) {
546 printk(KERN_ERR MODULE_NAME ": Register framebuffer error.\n");
547 goto out_err_5;
548 }
549
550 printk("Initialized vmlfb\n");
551
552 return 0;
553
554out_err_5:
555 fb_dealloc_cmap(&info->cmap);
556out_err_4:
557 vmlfb_free_vram(vinfo);
558out_err_3:
559 vmlfb_disable_mmio(par);
560out_err_2:
561 vmlfb_release_devices(par);
562out_err_1:
563 kfree(vinfo);
564out_err_0:
565 kfree(par);
566 return err;
567}
568
569static int vmlfb_open(struct fb_info *info, int user)
570{
571 /*
572 * Save registers here?
573 */
574 return 0;
575}
576
577static int vmlfb_release(struct fb_info *info, int user)
578{
579 /*
580 * Restore registers here.
581 */
582
583 return 0;
584}
585
586static int vml_nearest_clock(int clock)
587{
588
589 int i;
590 int cur_index;
591 int cur_diff;
592 int diff;
593
594 cur_index = 0;
595 cur_diff = clock - vml_clocks[0];
596 cur_diff = (cur_diff < 0) ? -cur_diff : cur_diff;
597 for (i = 1; i < vml_num_clocks; ++i) {
598 diff = clock - vml_clocks[i];
599 diff = (diff < 0) ? -diff : diff;
600 if (diff < cur_diff) {
601 cur_index = i;
602 cur_diff = diff;
603 }
604 }
605 return vml_clocks[cur_index];
606}
607
608static int vmlfb_check_var_locked(struct fb_var_screeninfo *var,
609 struct vml_info *vinfo)
610{
611 u32 pitch;
612 u64 mem;
613 int nearest_clock;
614 int clock;
615 int clock_diff;
616 struct fb_var_screeninfo v;
617
618 v = *var;
619 clock = PICOS2KHZ(var->pixclock);
620
621 if (subsys && subsys->nearest_clock) {
622 nearest_clock = subsys->nearest_clock(subsys, clock);
623 } else {
624 nearest_clock = vml_nearest_clock(clock);
625 }
626
627 /*
628 * Accept a 20% diff.
629 */
630
631 clock_diff = nearest_clock - clock;
632 clock_diff = (clock_diff < 0) ? -clock_diff : clock_diff;
633 if (clock_diff > clock / 5) {
634#if 0
635 printk(KERN_DEBUG MODULE_NAME ": Diff failure. %d %d\n",clock_diff,clock);
636#endif
637 return -EINVAL;
638 }
639
640 v.pixclock = KHZ2PICOS(nearest_clock);
641
642 if (var->xres > VML_MAX_XRES || var->yres > VML_MAX_YRES) {
643 printk(KERN_DEBUG MODULE_NAME ": Resolution failure.\n");
644 return -EINVAL;
645 }
646 if (var->xres_virtual > VML_MAX_XRES_VIRTUAL) {
647 printk(KERN_DEBUG MODULE_NAME
648 ": Virtual resolution failure.\n");
649 return -EINVAL;
650 }
651 switch (v.bits_per_pixel) {
652 case 0 ... 16:
653 v.bits_per_pixel = 16;
654 break;
655 case 17 ... 32:
656 v.bits_per_pixel = 32;
657 break;
658 default:
659 printk(KERN_DEBUG MODULE_NAME ": Invalid bpp: %d.\n",
660 var->bits_per_pixel);
661 return -EINVAL;
662 }
663
664 pitch = __ALIGN_MASK((var->xres * var->bits_per_pixel) >> 3, 0x3F);
665 mem = pitch * var->yres_virtual;
666 if (mem > vinfo->vram_contig_size) {
667 return -ENOMEM;
668 }
669
670 switch (v.bits_per_pixel) {
671 case 16:
672 if (var->blue.offset != 0 ||
673 var->blue.length != 5 ||
674 var->green.offset != 5 ||
675 var->green.length != 5 ||
676 var->red.offset != 10 ||
677 var->red.length != 5 ||
678 var->transp.offset != 15 || var->transp.length != 1) {
679 vmlfb_set_pref_pixel_format(&v);
680 }
681 break;
682 case 32:
683 if (var->blue.offset != 0 ||
684 var->blue.length != 8 ||
685 var->green.offset != 8 ||
686 var->green.length != 8 ||
687 var->red.offset != 16 ||
688 var->red.length != 8 ||
689 (var->transp.length != 0 && var->transp.length != 8) ||
690 (var->transp.length == 8 && var->transp.offset != 24)) {
691 vmlfb_set_pref_pixel_format(&v);
692 }
693 break;
694 default:
695 return -EINVAL;
696 }
697
698 *var = v;
699
700 return 0;
701}
702
703static int vmlfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
704{
705 struct vml_info *vinfo = container_of(info, struct vml_info, info);
706 int ret;
707
708 mutex_lock(&vml_mutex);
709 ret = vmlfb_check_var_locked(var, vinfo);
710 mutex_unlock(&vml_mutex);
711
712 return ret;
713}
714
715static void vml_wait_vblank(struct vml_info *vinfo)
716{
717 /* Wait for vblank. For now, just wait for a 50Hz cycle (20ms)) */
718 mdelay(20);
719}
720
721static void vmlfb_disable_pipe(struct vml_info *vinfo)
722{
723 struct vml_par *par = vinfo->par;
724
725 /* Disable the MDVO pad */
726 VML_WRITE32(par, VML_RCOMPSTAT, 0);
727 while (!(VML_READ32(par, VML_RCOMPSTAT) & VML_MDVO_VDC_I_RCOMP)) ;
728
729 /* Disable display planes */
730 VML_WRITE32(par, VML_DSPCCNTR,
731 VML_READ32(par, VML_DSPCCNTR) & ~VML_GFX_ENABLE);
732 (void)VML_READ32(par, VML_DSPCCNTR);
733 /* Wait for vblank for the disable to take effect */
734 vml_wait_vblank(vinfo);
735
736 /* Next, disable display pipes */
737 VML_WRITE32(par, VML_PIPEACONF, 0);
738 (void)VML_READ32(par, VML_PIPEACONF);
739
740 vinfo->pipe_disabled = 1;
741}
742
743#ifdef VERMILION_DEBUG
744static void vml_dump_regs(struct vml_info *vinfo)
745{
746 struct vml_par *par = vinfo->par;
747
748 printk(KERN_DEBUG MODULE_NAME ": Modesetting register dump:\n");
749 printk(KERN_DEBUG MODULE_NAME ": \tHTOTAL_A : 0x%08x\n",
750 (unsigned)VML_READ32(par, VML_HTOTAL_A));
751 printk(KERN_DEBUG MODULE_NAME ": \tHBLANK_A : 0x%08x\n",
752 (unsigned)VML_READ32(par, VML_HBLANK_A));
753 printk(KERN_DEBUG MODULE_NAME ": \tHSYNC_A : 0x%08x\n",
754 (unsigned)VML_READ32(par, VML_HSYNC_A));
755 printk(KERN_DEBUG MODULE_NAME ": \tVTOTAL_A : 0x%08x\n",
756 (unsigned)VML_READ32(par, VML_VTOTAL_A));
757 printk(KERN_DEBUG MODULE_NAME ": \tVBLANK_A : 0x%08x\n",
758 (unsigned)VML_READ32(par, VML_VBLANK_A));
759 printk(KERN_DEBUG MODULE_NAME ": \tVSYNC_A : 0x%08x\n",
760 (unsigned)VML_READ32(par, VML_VSYNC_A));
761 printk(KERN_DEBUG MODULE_NAME ": \tDSPCSTRIDE : 0x%08x\n",
762 (unsigned)VML_READ32(par, VML_DSPCSTRIDE));
763 printk(KERN_DEBUG MODULE_NAME ": \tDSPCSIZE : 0x%08x\n",
764 (unsigned)VML_READ32(par, VML_DSPCSIZE));
765 printk(KERN_DEBUG MODULE_NAME ": \tDSPCPOS : 0x%08x\n",
766 (unsigned)VML_READ32(par, VML_DSPCPOS));
767 printk(KERN_DEBUG MODULE_NAME ": \tDSPARB : 0x%08x\n",
768 (unsigned)VML_READ32(par, VML_DSPARB));
769 printk(KERN_DEBUG MODULE_NAME ": \tDSPCADDR : 0x%08x\n",
770 (unsigned)VML_READ32(par, VML_DSPCADDR));
771 printk(KERN_DEBUG MODULE_NAME ": \tBCLRPAT_A : 0x%08x\n",
772 (unsigned)VML_READ32(par, VML_BCLRPAT_A));
773 printk(KERN_DEBUG MODULE_NAME ": \tCANVSCLR_A : 0x%08x\n",
774 (unsigned)VML_READ32(par, VML_CANVSCLR_A));
775 printk(KERN_DEBUG MODULE_NAME ": \tPIPEASRC : 0x%08x\n",
776 (unsigned)VML_READ32(par, VML_PIPEASRC));
777 printk(KERN_DEBUG MODULE_NAME ": \tPIPEACONF : 0x%08x\n",
778 (unsigned)VML_READ32(par, VML_PIPEACONF));
779 printk(KERN_DEBUG MODULE_NAME ": \tDSPCCNTR : 0x%08x\n",
780 (unsigned)VML_READ32(par, VML_DSPCCNTR));
781 printk(KERN_DEBUG MODULE_NAME ": \tRCOMPSTAT : 0x%08x\n",
782 (unsigned)VML_READ32(par, VML_RCOMPSTAT));
783 printk(KERN_DEBUG MODULE_NAME ": End of modesetting register dump.\n");
784}
785#endif
786
787static int vmlfb_set_par_locked(struct vml_info *vinfo)
788{
789 struct vml_par *par = vinfo->par;
790 struct fb_info *info = &vinfo->info;
791 struct fb_var_screeninfo *var = &info->var;
792 u32 htotal, hactive, hblank_start, hblank_end, hsync_start, hsync_end;
793 u32 vtotal, vactive, vblank_start, vblank_end, vsync_start, vsync_end;
794 u32 dspcntr;
795 int clock;
796
797 vinfo->bytes_per_pixel = var->bits_per_pixel >> 3;
798 vinfo->stride =
799 __ALIGN_MASK(var->xres_virtual * vinfo->bytes_per_pixel, 0x3F);
800 info->fix.line_length = vinfo->stride;
801
802 if (!subsys)
803 return 0;
804
805 htotal =
806 var->xres + var->right_margin + var->hsync_len + var->left_margin;
807 hactive = var->xres;
808 hblank_start = var->xres;
809 hblank_end = htotal;
810 hsync_start = hactive + var->right_margin;
811 hsync_end = hsync_start + var->hsync_len;
812
813 vtotal =
814 var->yres + var->lower_margin + var->vsync_len + var->upper_margin;
815 vactive = var->yres;
816 vblank_start = var->yres;
817 vblank_end = vtotal;
818 vsync_start = vactive + var->lower_margin;
819 vsync_end = vsync_start + var->vsync_len;
820
821 dspcntr = VML_GFX_ENABLE | VML_GFX_GAMMABYPASS;
822 clock = PICOS2KHZ(var->pixclock);
823
824 if (subsys->nearest_clock) {
825 clock = subsys->nearest_clock(subsys, clock);
826 } else {
827 clock = vml_nearest_clock(clock);
828 }
829 printk(KERN_DEBUG MODULE_NAME
830 ": Set mode Hfreq : %d kHz, Vfreq : %d Hz.\n", clock / htotal,
831 ((clock / htotal) * 1000) / vtotal);
832
833 switch (var->bits_per_pixel) {
834 case 16:
835 dspcntr |= VML_GFX_ARGB1555;
836 break;
837 case 32:
838 if (var->transp.length == 8)
839 dspcntr |= VML_GFX_ARGB8888 | VML_GFX_ALPHAMULT;
840 else
841 dspcntr |= VML_GFX_RGB0888;
842 break;
843 default:
844 return -EINVAL;
845 }
846
847 vmlfb_disable_pipe(vinfo);
848 mb();
849
850 if (subsys->set_clock)
851 subsys->set_clock(subsys, clock);
852 else
853 return -EINVAL;
854
855 VML_WRITE32(par, VML_HTOTAL_A, ((htotal - 1) << 16) | (hactive - 1));
856 VML_WRITE32(par, VML_HBLANK_A,
857 ((hblank_end - 1) << 16) | (hblank_start - 1));
858 VML_WRITE32(par, VML_HSYNC_A,
859 ((hsync_end - 1) << 16) | (hsync_start - 1));
860 VML_WRITE32(par, VML_VTOTAL_A, ((vtotal - 1) << 16) | (vactive - 1));
861 VML_WRITE32(par, VML_VBLANK_A,
862 ((vblank_end - 1) << 16) | (vblank_start - 1));
863 VML_WRITE32(par, VML_VSYNC_A,
864 ((vsync_end - 1) << 16) | (vsync_start - 1));
865 VML_WRITE32(par, VML_DSPCSTRIDE, vinfo->stride);
866 VML_WRITE32(par, VML_DSPCSIZE,
867 ((var->yres - 1) << 16) | (var->xres - 1));
868 VML_WRITE32(par, VML_DSPCPOS, 0x00000000);
869 VML_WRITE32(par, VML_DSPARB, VML_FIFO_DEFAULT);
870 VML_WRITE32(par, VML_BCLRPAT_A, 0x00000000);
871 VML_WRITE32(par, VML_CANVSCLR_A, 0x00000000);
872 VML_WRITE32(par, VML_PIPEASRC,
873 ((var->xres - 1) << 16) | (var->yres - 1));
874
875 wmb();
876 VML_WRITE32(par, VML_PIPEACONF, VML_PIPE_ENABLE);
877 wmb();
878 VML_WRITE32(par, VML_DSPCCNTR, dspcntr);
879 wmb();
880 VML_WRITE32(par, VML_DSPCADDR, (u32) vinfo->vram_start +
881 var->yoffset * vinfo->stride +
882 var->xoffset * vinfo->bytes_per_pixel);
883
884 VML_WRITE32(par, VML_RCOMPSTAT, VML_MDVO_PAD_ENABLE);
885
886 while (!(VML_READ32(par, VML_RCOMPSTAT) &
887 (VML_MDVO_VDC_I_RCOMP | VML_MDVO_PAD_ENABLE))) ;
888
889 vinfo->pipe_disabled = 0;
890#ifdef VERMILION_DEBUG
891 vml_dump_regs(vinfo);
892#endif
893
894 return 0;
895}
896
897static int vmlfb_set_par(struct fb_info *info)
898{
899 struct vml_info *vinfo = container_of(info, struct vml_info, info);
900 int ret;
901
902 mutex_lock(&vml_mutex);
903 list_del(&vinfo->head);
904 list_add(&vinfo->head, (subsys) ? &global_has_mode : &global_no_mode);
905 ret = vmlfb_set_par_locked(vinfo);
906
907 mutex_unlock(&vml_mutex);
908 return ret;
909}
910
911static int vmlfb_blank_locked(struct vml_info *vinfo)
912{
913 struct vml_par *par = vinfo->par;
914 u32 cur = VML_READ32(par, VML_PIPEACONF);
915
916 switch (vinfo->cur_blank_mode) {
917 case FB_BLANK_UNBLANK:
918 if (vinfo->pipe_disabled) {
919 vmlfb_set_par_locked(vinfo);
920 }
921 VML_WRITE32(par, VML_PIPEACONF, cur & ~VML_PIPE_FORCE_BORDER);
922 (void)VML_READ32(par, VML_PIPEACONF);
923 break;
924 case FB_BLANK_NORMAL:
925 if (vinfo->pipe_disabled) {
926 vmlfb_set_par_locked(vinfo);
927 }
928 VML_WRITE32(par, VML_PIPEACONF, cur | VML_PIPE_FORCE_BORDER);
929 (void)VML_READ32(par, VML_PIPEACONF);
930 break;
931 case FB_BLANK_VSYNC_SUSPEND:
932 case FB_BLANK_HSYNC_SUSPEND:
933 if (!vinfo->pipe_disabled) {
934 vmlfb_disable_pipe(vinfo);
935 }
936 break;
937 case FB_BLANK_POWERDOWN:
938 if (!vinfo->pipe_disabled) {
939 vmlfb_disable_pipe(vinfo);
940 }
941 break;
942 default:
943 return -EINVAL;
944 }
945
946 return 0;
947}
948
949static int vmlfb_blank(int blank_mode, struct fb_info *info)
950{
951 struct vml_info *vinfo = container_of(info, struct vml_info, info);
952 int ret;
953
954 mutex_lock(&vml_mutex);
955 vinfo->cur_blank_mode = blank_mode;
956 ret = vmlfb_blank_locked(vinfo);
957 mutex_unlock(&vml_mutex);
958 return ret;
959}
960
961static int vmlfb_pan_display(struct fb_var_screeninfo *var,
962 struct fb_info *info)
963{
964 struct vml_info *vinfo = container_of(info, struct vml_info, info);
965 struct vml_par *par = vinfo->par;
966
967 mutex_lock(&vml_mutex);
968 VML_WRITE32(par, VML_DSPCADDR, (u32) vinfo->vram_start +
969 var->yoffset * vinfo->stride +
970 var->xoffset * vinfo->bytes_per_pixel);
971 (void)VML_READ32(par, VML_DSPCADDR);
972 mutex_unlock(&vml_mutex);
973
974 return 0;
975}
976
977static int vmlfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
978 u_int transp, struct fb_info *info)
979{
980 u32 v;
981
982 if (regno >= 16)
983 return -EINVAL;
984
985 if (info->var.grayscale) {
986 red = green = blue = (red * 77 + green * 151 + blue * 28) >> 8;
987 }
988
989 if (info->fix.visual != FB_VISUAL_TRUECOLOR)
990 return -EINVAL;
991
992 red = VML_TOHW(red, info->var.red.length);
993 blue = VML_TOHW(blue, info->var.blue.length);
994 green = VML_TOHW(green, info->var.green.length);
995 transp = VML_TOHW(transp, info->var.transp.length);
996
997 v = (red << info->var.red.offset) |
998 (green << info->var.green.offset) |
999 (blue << info->var.blue.offset) |
1000 (transp << info->var.transp.offset);
1001
1002 switch (info->var.bits_per_pixel) {
1003 case 16:
1004 ((u32 *) info->pseudo_palette)[regno] = v;
1005 break;
1006 case 24:
1007 case 32:
1008 ((u32 *) info->pseudo_palette)[regno] = v;
1009 break;
1010 }
1011 return 0;
1012}
1013
1014static int vmlfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
1015{
1016 struct vml_info *vinfo = container_of(info, struct vml_info, info);
1017 unsigned long size = vma->vm_end - vma->vm_start;
1018 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
1019 int ret;
1020
1021 if (vma->vm_pgoff > (~0UL >> PAGE_SHIFT))
1022 return -EINVAL;
1023 if (offset + size > vinfo->vram_contig_size)
1024 return -EINVAL;
1025 ret = vmlfb_vram_offset(vinfo, offset);
1026 if (ret)
1027 return -EINVAL;
1028 offset += vinfo->vram_start;
1029 pgprot_val(vma->vm_page_prot) |= _PAGE_PCD;
1030 pgprot_val(vma->vm_page_prot) &= ~_PAGE_PWT;
1031 vma->vm_flags |= VM_RESERVED | VM_IO;
1032 if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT,
1033 size, vma->vm_page_prot))
1034 return -EAGAIN;
1035 return 0;
1036}
1037
1038static int vmlfb_sync(struct fb_info *info)
1039{
1040 return 0;
1041}
1042
1043static int vmlfb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1044{
1045 return -EINVAL; /* just to force soft_cursor() call */
1046}
1047
1048static struct fb_ops vmlfb_ops = {
1049 .owner = THIS_MODULE,
1050 .fb_open = vmlfb_open,
1051 .fb_release = vmlfb_release,
1052 .fb_check_var = vmlfb_check_var,
1053 .fb_set_par = vmlfb_set_par,
1054 .fb_blank = vmlfb_blank,
1055 .fb_pan_display = vmlfb_pan_display,
1056 .fb_fillrect = cfb_fillrect,
1057 .fb_copyarea = cfb_copyarea,
1058 .fb_imageblit = cfb_imageblit,
1059 .fb_cursor = vmlfb_cursor,
1060 .fb_sync = vmlfb_sync,
1061 .fb_mmap = vmlfb_mmap,
1062 .fb_setcolreg = vmlfb_setcolreg
1063};
1064
1065static struct pci_device_id vml_ids[] = {
1066 {PCI_DEVICE(PCI_VENDOR_ID_INTEL, VML_DEVICE_VDC)},
1067 {0}
1068};
1069
1070static struct pci_driver vmlfb_pci_driver = {
1071 .name = "vmlfb",
1072 .id_table = vml_ids,
1073 .probe = vml_pci_probe,
1074 .remove = __devexit_p(vml_pci_remove)
1075};
1076
1077static void __exit vmlfb_cleanup(void)
1078{
1079 pci_unregister_driver(&vmlfb_pci_driver);
1080}
1081
1082static int __init vmlfb_init(void)
1083{
1084
1085#ifndef MODULE
1086 char *option = NULL;
1087
1088 if (fb_get_options(MODULE_NAME, &option))
1089 return -ENODEV;
1090#endif
1091
1092 printk(KERN_DEBUG MODULE_NAME ": initializing\n");
1093 mutex_init(&vml_mutex);
1094 INIT_LIST_HEAD(&global_no_mode);
1095 INIT_LIST_HEAD(&global_has_mode);
1096
1097 return pci_register_driver(&vmlfb_pci_driver);
1098}
1099
1100int vmlfb_register_subsys(struct vml_sys *sys)
1101{
1102 struct vml_info *entry;
1103 struct list_head *list;
1104 u32 save_activate;
1105
1106 mutex_lock(&vml_mutex);
1107 if (subsys != NULL) {
1108 subsys->restore(subsys);
1109 }
1110 subsys = sys;
1111 subsys->save(subsys);
1112
1113 /*
1114 * We need to restart list traversal for each item, since we
1115 * release the list mutex in the loop.
1116 */
1117
1118 list = global_no_mode.next;
1119 while (list != &global_no_mode) {
1120 list_del_init(list);
1121 entry = list_entry(list, struct vml_info, head);
1122
1123 /*
1124 * First, try the current mode which might not be
1125 * completely validated with respect to the pixel clock.
1126 */
1127
1128 if (!vmlfb_check_var_locked(&entry->info.var, entry)) {
1129 vmlfb_set_par_locked(entry);
1130 list_add_tail(list, &global_has_mode);
1131 } else {
1132
1133 /*
1134 * Didn't work. Try to find another mode,
1135 * that matches this subsys.
1136 */
1137
1138 mutex_unlock(&vml_mutex);
1139 save_activate = entry->info.var.activate;
1140 entry->info.var.bits_per_pixel = 16;
1141 vmlfb_set_pref_pixel_format(&entry->info.var);
1142 if (fb_find_mode(&entry->info.var,
1143 &entry->info,
1144 vml_default_mode, NULL, 0, NULL, 16)) {
1145 entry->info.var.activate |=
1146 FB_ACTIVATE_FORCE | FB_ACTIVATE_NOW;
1147 fb_set_var(&entry->info, &entry->info.var);
1148 } else {
1149 printk(KERN_ERR MODULE_NAME
1150 ": Sorry. no mode found for this subsys.\n");
1151 }
1152 entry->info.var.activate = save_activate;
1153 mutex_lock(&vml_mutex);
1154 }
1155 vmlfb_blank_locked(entry);
1156 list = global_no_mode.next;
1157 }
1158 mutex_unlock(&vml_mutex);
1159
1160 printk(KERN_DEBUG MODULE_NAME ": Registered %s subsystem.\n",
1161 subsys->name ? subsys->name : "unknown");
1162 return 0;
1163}
1164
1165EXPORT_SYMBOL_GPL(vmlfb_register_subsys);
1166
1167void vmlfb_unregister_subsys(struct vml_sys *sys)
1168{
1169 struct vml_info *entry, *next;
1170
1171 mutex_lock(&vml_mutex);
1172 if (subsys != sys) {
1173 mutex_unlock(&vml_mutex);
1174 return;
1175 }
1176 subsys->restore(subsys);
1177 subsys = NULL;
1178 list_for_each_entry_safe(entry, next, &global_has_mode, head) {
1179 printk(KERN_DEBUG MODULE_NAME ": subsys disable pipe\n");
1180 vmlfb_disable_pipe(entry);
1181 list_del(&entry->head);
1182 list_add_tail(&entry->head, &global_no_mode);
1183 }
1184 mutex_unlock(&vml_mutex);
1185}
1186
1187EXPORT_SYMBOL_GPL(vmlfb_unregister_subsys);
1188
1189module_init(vmlfb_init);
1190module_exit(vmlfb_cleanup);
1191
1192MODULE_AUTHOR("Tungsten Graphics");
1193MODULE_DESCRIPTION("Initialization of the Vermilion display devices");
1194MODULE_VERSION("1.0.0");
1195MODULE_LICENSE("GPL");
diff --git a/drivers/video/vermilion/vermilion.h b/drivers/video/vermilion/vermilion.h
new file mode 100644
index 000000000000..1fc6695a49d2
--- /dev/null
+++ b/drivers/video/vermilion/vermilion.h
@@ -0,0 +1,260 @@
1/*
2 * Copyright (c) Intel Corp. 2007.
3 * All Rights Reserved.
4 *
5 * Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
6 * develop this driver.
7 *
8 * This file is part of the Vermilion Range fb driver.
9 * The Vermilion Range fb driver is free software;
10 * you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The Vermilion Range fb driver is distributed
16 * in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this driver; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 *
25 * Authors:
26 * Thomas Hellström <thomas-at-tungstengraphics-dot-com>
27 */
28
29#ifndef _VERMILION_H_
30#define _VERMILION_H_
31
32#include <linux/kernel.h>
33#include <linux/version.h>
34#include <linux/pci.h>
35#include <asm/atomic.h>
36#include <linux/mutex.h>
37
38#define VML_DEVICE_GPU 0x5002
39#define VML_DEVICE_VDC 0x5009
40
41#define VML_VRAM_AREAS 3
42#define VML_MAX_XRES 1024
43#define VML_MAX_YRES 768
44#define VML_MAX_XRES_VIRTUAL 1040
45
46/*
47 * Display controller registers:
48 */
49
50/* Display controller 10-bit color representation */
51
52#define VML_R_MASK 0x3FF00000
53#define VML_R_SHIFT 20
54#define VML_G_MASK 0x000FFC00
55#define VML_G_SHIFT 10
56#define VML_B_MASK 0x000003FF
57#define VML_B_SHIFT 0
58
59/* Graphics plane control */
60#define VML_DSPCCNTR 0x00072180
61#define VML_GFX_ENABLE 0x80000000
62#define VML_GFX_GAMMABYPASS 0x40000000
63#define VML_GFX_ARGB1555 0x0C000000
64#define VML_GFX_RGB0888 0x18000000
65#define VML_GFX_ARGB8888 0x1C000000
66#define VML_GFX_ALPHACONST 0x02000000
67#define VML_GFX_ALPHAMULT 0x01000000
68#define VML_GFX_CONST_ALPHA 0x000000FF
69
70/* Graphics plane start address. Pixel aligned. */
71#define VML_DSPCADDR 0x00072184
72
73/* Graphics plane stride register. */
74#define VML_DSPCSTRIDE 0x00072188
75
76/* Graphics plane position register. */
77#define VML_DSPCPOS 0x0007218C
78#define VML_POS_YMASK 0x0FFF0000
79#define VML_POS_YSHIFT 16
80#define VML_POS_XMASK 0x00000FFF
81#define VML_POS_XSHIFT 0
82
83/* Graphics plane height and width */
84#define VML_DSPCSIZE 0x00072190
85#define VML_SIZE_HMASK 0x0FFF0000
86#define VML_SIZE_HSHIFT 16
87#define VML_SISE_WMASK 0x00000FFF
88#define VML_SIZE_WSHIFT 0
89
90/* Graphics plane gamma correction lookup table registers (129 * 32 bits) */
91#define VML_DSPCGAMLUT 0x00072200
92
93/* Pixel video output configuration register */
94#define VML_PVOCONFIG 0x00061140
95#define VML_CONFIG_BASE 0x80000000
96#define VML_CONFIG_PIXEL_SWAP 0x04000000
97#define VML_CONFIG_DE_INV 0x01000000
98#define VML_CONFIG_HREF_INV 0x00400000
99#define VML_CONFIG_VREF_INV 0x00100000
100#define VML_CONFIG_CLK_INV 0x00040000
101#define VML_CONFIG_CLK_DIV2 0x00010000
102#define VML_CONFIG_ESTRB_INV 0x00008000
103
104/* Pipe A Horizontal total register */
105#define VML_HTOTAL_A 0x00060000
106#define VML_HTOTAL_MASK 0x1FFF0000
107#define VML_HTOTAL_SHIFT 16
108#define VML_HTOTAL_VAL 8192
109#define VML_HACTIVE_MASK 0x000007FF
110#define VML_HACTIVE_SHIFT 0
111#define VML_HACTIVE_VAL 4096
112
113/* Pipe A Horizontal Blank register */
114#define VML_HBLANK_A 0x00060004
115#define VML_HBLANK_END_MASK 0x1FFF0000
116#define VML_HBLANK_END_SHIFT 16
117#define VML_HBLANK_END_VAL 8192
118#define VML_HBLANK_START_MASK 0x00001FFF
119#define VML_HBLANK_START_SHIFT 0
120#define VML_HBLANK_START_VAL 8192
121
122/* Pipe A Horizontal Sync register */
123#define VML_HSYNC_A 0x00060008
124#define VML_HSYNC_END_MASK 0x1FFF0000
125#define VML_HSYNC_END_SHIFT 16
126#define VML_HSYNC_END_VAL 8192
127#define VML_HSYNC_START_MASK 0x00001FFF
128#define VML_HSYNC_START_SHIFT 0
129#define VML_HSYNC_START_VAL 8192
130
131/* Pipe A Vertical total register */
132#define VML_VTOTAL_A 0x0006000C
133#define VML_VTOTAL_MASK 0x1FFF0000
134#define VML_VTOTAL_SHIFT 16
135#define VML_VTOTAL_VAL 8192
136#define VML_VACTIVE_MASK 0x000007FF
137#define VML_VACTIVE_SHIFT 0
138#define VML_VACTIVE_VAL 4096
139
140/* Pipe A Vertical Blank register */
141#define VML_VBLANK_A 0x00060010
142#define VML_VBLANK_END_MASK 0x1FFF0000
143#define VML_VBLANK_END_SHIFT 16
144#define VML_VBLANK_END_VAL 8192
145#define VML_VBLANK_START_MASK 0x00001FFF
146#define VML_VBLANK_START_SHIFT 0
147#define VML_VBLANK_START_VAL 8192
148
149/* Pipe A Vertical Sync register */
150#define VML_VSYNC_A 0x00060014
151#define VML_VSYNC_END_MASK 0x1FFF0000
152#define VML_VSYNC_END_SHIFT 16
153#define VML_VSYNC_END_VAL 8192
154#define VML_VSYNC_START_MASK 0x00001FFF
155#define VML_VSYNC_START_SHIFT 0
156#define VML_VSYNC_START_VAL 8192
157
158/* Pipe A Source Image size (minus one - equal to active size)
159 * Programmable while pipe is enabled.
160 */
161#define VML_PIPEASRC 0x0006001C
162#define VML_PIPEASRC_HMASK 0x0FFF0000
163#define VML_PIPEASRC_HSHIFT 16
164#define VML_PIPEASRC_VMASK 0x00000FFF
165#define VML_PIPEASRC_VSHIFT 0
166
167/* Pipe A Border Color Pattern register (10 bit color) */
168#define VML_BCLRPAT_A 0x00060020
169
170/* Pipe A Canvas Color register (10 bit color) */
171#define VML_CANVSCLR_A 0x00060024
172
173/* Pipe A Configuration register */
174#define VML_PIPEACONF 0x00070008
175#define VML_PIPE_BASE 0x00000000
176#define VML_PIPE_ENABLE 0x80000000
177#define VML_PIPE_FORCE_BORDER 0x02000000
178#define VML_PIPE_PLANES_OFF 0x00080000
179#define VML_PIPE_ARGB_OUTPUT_MODE 0x00040000
180
181/* Pipe A FIFO setting */
182#define VML_DSPARB 0x00070030
183#define VML_FIFO_DEFAULT 0x00001D9C
184
185/* MDVO rcomp status & pads control register */
186#define VML_RCOMPSTAT 0x00070048
187#define VML_MDVO_VDC_I_RCOMP 0x80000000
188#define VML_MDVO_POWERSAVE_OFF 0x00000008
189#define VML_MDVO_PAD_ENABLE 0x00000004
190#define VML_MDVO_PULLDOWN_ENABLE 0x00000001
191
192struct vml_par {
193 struct pci_dev *vdc;
194 u64 vdc_mem_base;
195 u64 vdc_mem_size;
196 char __iomem *vdc_mem;
197
198 struct pci_dev *gpu;
199 u64 gpu_mem_base;
200 u64 gpu_mem_size;
201 char __iomem *gpu_mem;
202
203 atomic_t refcount;
204};
205
206struct vram_area {
207 unsigned long logical;
208 unsigned long phys;
209 unsigned long size;
210 unsigned order;
211};
212
213struct vml_info {
214 struct fb_info info;
215 struct vml_par *par;
216 struct list_head head;
217 struct vram_area vram[VML_VRAM_AREAS];
218 u64 vram_start;
219 u64 vram_contig_size;
220 u32 num_areas;
221 void __iomem *vram_logical;
222 u32 pseudo_palette[16];
223 u32 stride;
224 u32 bytes_per_pixel;
225 atomic_t vmas;
226 int cur_blank_mode;
227 int pipe_disabled;
228};
229
230/*
231 * Subsystem
232 */
233
234struct vml_sys {
235 char *name;
236
237 /*
238 * Save / Restore;
239 */
240
241 int (*save) (struct vml_sys * sys);
242 int (*restore) (struct vml_sys * sys);
243
244 /*
245 * PLL programming;
246 */
247
248 int (*set_clock) (struct vml_sys * sys, int clock);
249 int (*nearest_clock) (const struct vml_sys * sys, int clock);
250};
251
252extern int vmlfb_register_subsys(struct vml_sys *sys);
253extern void vmlfb_unregister_subsys(struct vml_sys *sys);
254
255#define VML_READ32(_par, _offset) \
256 (ioread32((_par)->vdc_mem + (_offset)))
257#define VML_WRITE32(_par, _offset, _value) \
258 iowrite32(_value, (_par)->vdc_mem + (_offset))
259
260#endif
diff --git a/drivers/video/vfb.c b/drivers/video/vfb.c
index a9b99b01bd8e..64ee78c3c12b 100644
--- a/drivers/video/vfb.c
+++ b/drivers/video/vfb.c
@@ -84,13 +84,15 @@ static int vfb_mmap(struct fb_info *info,
84 struct vm_area_struct *vma); 84 struct vm_area_struct *vma);
85 85
86static struct fb_ops vfb_ops = { 86static struct fb_ops vfb_ops = {
87 .fb_read = fb_sys_read,
88 .fb_write = fb_sys_write,
87 .fb_check_var = vfb_check_var, 89 .fb_check_var = vfb_check_var,
88 .fb_set_par = vfb_set_par, 90 .fb_set_par = vfb_set_par,
89 .fb_setcolreg = vfb_setcolreg, 91 .fb_setcolreg = vfb_setcolreg,
90 .fb_pan_display = vfb_pan_display, 92 .fb_pan_display = vfb_pan_display,
91 .fb_fillrect = cfb_fillrect, 93 .fb_fillrect = sys_fillrect,
92 .fb_copyarea = cfb_copyarea, 94 .fb_copyarea = sys_copyarea,
93 .fb_imageblit = cfb_imageblit, 95 .fb_imageblit = sys_imageblit,
94 .fb_mmap = vfb_mmap, 96 .fb_mmap = vfb_mmap,
95}; 97};
96 98
diff --git a/drivers/video/vga16fb.c b/drivers/video/vga16fb.c
index ec4c7dc54a66..2a14d28c4163 100644
--- a/drivers/video/vga16fb.c
+++ b/drivers/video/vga16fb.c
@@ -1378,6 +1378,8 @@ static int __init vga16fb_probe(struct platform_device *dev)
1378 info->fbops = &vga16fb_ops; 1378 info->fbops = &vga16fb_ops;
1379 info->var = vga16fb_defined; 1379 info->var = vga16fb_defined;
1380 info->fix = vga16fb_fix; 1380 info->fix = vga16fb_fix;
1381 /* supports rectangles with widths of multiples of 8 */
1382 info->pixmap.blit_x = 1 << 7 | 1 << 15 | 1 << 23 | 1 << 31;
1381 info->flags = FBINFO_FLAG_DEFAULT | 1383 info->flags = FBINFO_FLAG_DEFAULT |
1382 FBINFO_HWACCEL_YPAN; 1384 FBINFO_HWACCEL_YPAN;
1383 1385
diff --git a/drivers/video/vgastate.c b/drivers/video/vgastate.c
index d94efafc77b5..b91c466225b9 100644
--- a/drivers/video/vgastate.c
+++ b/drivers/video/vgastate.c
@@ -50,23 +50,28 @@ static void save_vga_text(struct vgastate *state, void __iomem *fbbase)
50 struct regstate *saved = (struct regstate *) state->vidstate; 50 struct regstate *saved = (struct regstate *) state->vidstate;
51 int i; 51 int i;
52 u8 misc, attr10, gr4, gr5, gr6, seq1, seq2, seq4; 52 u8 misc, attr10, gr4, gr5, gr6, seq1, seq2, seq4;
53 unsigned short iobase;
53 54
54 /* if in graphics mode, no need to save */ 55 /* if in graphics mode, no need to save */
56 misc = vga_r(state->vgabase, VGA_MIS_R);
57 iobase = (misc & 1) ? 0x3d0 : 0x3b0;
58
59 vga_r(state->vgabase, iobase + 0xa);
60 vga_w(state->vgabase, VGA_ATT_W, 0x00);
55 attr10 = vga_rattr(state->vgabase, 0x10); 61 attr10 = vga_rattr(state->vgabase, 0x10);
62 vga_r(state->vgabase, iobase + 0xa);
63 vga_w(state->vgabase, VGA_ATT_W, 0x20);
64
56 if (attr10 & 1) 65 if (attr10 & 1)
57 return; 66 return;
58 67
59 /* save regs */ 68 /* save regs */
60 misc = vga_r(state->vgabase, VGA_MIS_R);
61 gr4 = vga_rgfx(state->vgabase, VGA_GFX_PLANE_READ); 69 gr4 = vga_rgfx(state->vgabase, VGA_GFX_PLANE_READ);
62 gr5 = vga_rgfx(state->vgabase, VGA_GFX_MODE); 70 gr5 = vga_rgfx(state->vgabase, VGA_GFX_MODE);
63 gr6 = vga_rgfx(state->vgabase, VGA_GFX_MISC); 71 gr6 = vga_rgfx(state->vgabase, VGA_GFX_MISC);
64 seq2 = vga_rseq(state->vgabase, VGA_SEQ_PLANE_WRITE); 72 seq2 = vga_rseq(state->vgabase, VGA_SEQ_PLANE_WRITE);
65 seq4 = vga_rseq(state->vgabase, VGA_SEQ_MEMORY_MODE); 73 seq4 = vga_rseq(state->vgabase, VGA_SEQ_MEMORY_MODE);
66 74
67 /* force graphics mode */
68 vga_w(state->vgabase, VGA_MIS_W, misc | 1);
69
70 /* blank screen */ 75 /* blank screen */
71 seq1 = vga_rseq(state->vgabase, VGA_SEQ_CLOCK_MODE); 76 seq1 = vga_rseq(state->vgabase, VGA_SEQ_CLOCK_MODE);
72 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1); 77 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1);
@@ -115,15 +120,12 @@ static void save_vga_text(struct vgastate *state, void __iomem *fbbase)
115 } 120 }
116 121
117 /* restore regs */ 122 /* restore regs */
118 vga_wattr(state->vgabase, 0x10, attr10);
119
120 vga_wseq(state->vgabase, VGA_SEQ_PLANE_WRITE, seq2); 123 vga_wseq(state->vgabase, VGA_SEQ_PLANE_WRITE, seq2);
121 vga_wseq(state->vgabase, VGA_SEQ_MEMORY_MODE, seq4); 124 vga_wseq(state->vgabase, VGA_SEQ_MEMORY_MODE, seq4);
122 125
123 vga_wgfx(state->vgabase, VGA_GFX_PLANE_READ, gr4); 126 vga_wgfx(state->vgabase, VGA_GFX_PLANE_READ, gr4);
124 vga_wgfx(state->vgabase, VGA_GFX_MODE, gr5); 127 vga_wgfx(state->vgabase, VGA_GFX_MODE, gr5);
125 vga_wgfx(state->vgabase, VGA_GFX_MISC, gr6); 128 vga_wgfx(state->vgabase, VGA_GFX_MISC, gr6);
126 vga_w(state->vgabase, VGA_MIS_W, misc);
127 129
128 /* unblank screen */ 130 /* unblank screen */
129 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1); 131 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1);
@@ -137,11 +139,10 @@ static void restore_vga_text(struct vgastate *state, void __iomem *fbbase)
137{ 139{
138 struct regstate *saved = (struct regstate *) state->vidstate; 140 struct regstate *saved = (struct regstate *) state->vidstate;
139 int i; 141 int i;
140 u8 misc, gr1, gr3, gr4, gr5, gr6, gr8; 142 u8 gr1, gr3, gr4, gr5, gr6, gr8;
141 u8 seq1, seq2, seq4; 143 u8 seq1, seq2, seq4;
142 144
143 /* save regs */ 145 /* save regs */
144 misc = vga_r(state->vgabase, VGA_MIS_R);
145 gr1 = vga_rgfx(state->vgabase, VGA_GFX_SR_ENABLE); 146 gr1 = vga_rgfx(state->vgabase, VGA_GFX_SR_ENABLE);
146 gr3 = vga_rgfx(state->vgabase, VGA_GFX_DATA_ROTATE); 147 gr3 = vga_rgfx(state->vgabase, VGA_GFX_DATA_ROTATE);
147 gr4 = vga_rgfx(state->vgabase, VGA_GFX_PLANE_READ); 148 gr4 = vga_rgfx(state->vgabase, VGA_GFX_PLANE_READ);
@@ -151,9 +152,6 @@ static void restore_vga_text(struct vgastate *state, void __iomem *fbbase)
151 seq2 = vga_rseq(state->vgabase, VGA_SEQ_PLANE_WRITE); 152 seq2 = vga_rseq(state->vgabase, VGA_SEQ_PLANE_WRITE);
152 seq4 = vga_rseq(state->vgabase, VGA_SEQ_MEMORY_MODE); 153 seq4 = vga_rseq(state->vgabase, VGA_SEQ_MEMORY_MODE);
153 154
154 /* force graphics mode */
155 vga_w(state->vgabase, VGA_MIS_W, misc | 1);
156
157 /* blank screen */ 155 /* blank screen */
158 seq1 = vga_rseq(state->vgabase, VGA_SEQ_CLOCK_MODE); 156 seq1 = vga_rseq(state->vgabase, VGA_SEQ_CLOCK_MODE);
159 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1); 157 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x1);
@@ -213,8 +211,6 @@ static void restore_vga_text(struct vgastate *state, void __iomem *fbbase)
213 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x3); 211 vga_wseq(state->vgabase, VGA_SEQ_RESET, 0x3);
214 212
215 /* restore regs */ 213 /* restore regs */
216 vga_w(state->vgabase, VGA_MIS_W, misc);
217
218 vga_wgfx(state->vgabase, VGA_GFX_SR_ENABLE, gr1); 214 vga_wgfx(state->vgabase, VGA_GFX_SR_ENABLE, gr1);
219 vga_wgfx(state->vgabase, VGA_GFX_DATA_ROTATE, gr3); 215 vga_wgfx(state->vgabase, VGA_GFX_DATA_ROTATE, gr3);
220 vga_wgfx(state->vgabase, VGA_GFX_PLANE_READ, gr4); 216 vga_wgfx(state->vgabase, VGA_GFX_PLANE_READ, gr4);
diff --git a/drivers/video/vt8623fb.c b/drivers/video/vt8623fb.c
new file mode 100644
index 000000000000..5e9755e464a1
--- /dev/null
+++ b/drivers/video/vt8623fb.c
@@ -0,0 +1,927 @@
1/*
2 * linux/drivers/video/vt8623fb.c - fbdev driver for
3 * integrated graphic core in VIA VT8623 [CLE266] chipset
4 *
5 * Copyright (c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file COPYING in the main directory of this archive for
9 * more details.
10 *
11 * Code is based on s3fb, some parts are from David Boucher's viafb
12 * (http://davesdomain.org.uk/viafb/)
13 */
14
15#include <linux/version.h>
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/errno.h>
19#include <linux/string.h>
20#include <linux/mm.h>
21#include <linux/tty.h>
22#include <linux/slab.h>
23#include <linux/delay.h>
24#include <linux/fb.h>
25#include <linux/svga.h>
26#include <linux/init.h>
27#include <linux/pci.h>
28#include <linux/console.h> /* Why should fb driver call console functions? because acquire_console_sem() */
29#include <video/vga.h>
30
31#ifdef CONFIG_MTRR
32#include <asm/mtrr.h>
33#endif
34
35struct vt8623fb_info {
36 char __iomem *mmio_base;
37 int mtrr_reg;
38 struct vgastate state;
39 struct mutex open_lock;
40 unsigned int ref_count;
41 u32 pseudo_palette[16];
42};
43
44
45
46/* ------------------------------------------------------------------------- */
47
48static const struct svga_fb_format vt8623fb_formats[] = {
49 { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
50 FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP8, FB_VISUAL_PSEUDOCOLOR, 16, 16},
51 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
52 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 16, 16},
53 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
54 FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 16, 16},
55 { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
56 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 8},
57/* {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
58 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4}, */
59 {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
60 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 4, 4},
61 {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
62 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 2},
63 SVGA_FORMAT_END
64};
65
66static const struct svga_pll vt8623_pll = {2, 127, 2, 7, 0, 3,
67 60000, 300000, 14318};
68
69/* CRT timing register sets */
70
71struct vga_regset vt8623_h_total_regs[] = {{0x00, 0, 7}, {0x36, 3, 3}, VGA_REGSET_END};
72struct vga_regset vt8623_h_display_regs[] = {{0x01, 0, 7}, VGA_REGSET_END};
73struct vga_regset vt8623_h_blank_start_regs[] = {{0x02, 0, 7}, VGA_REGSET_END};
74struct vga_regset vt8623_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, {0x33, 5, 5}, VGA_REGSET_END};
75struct vga_regset vt8623_h_sync_start_regs[] = {{0x04, 0, 7}, {0x33, 4, 4}, VGA_REGSET_END};
76struct vga_regset vt8623_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
77
78struct vga_regset vt8623_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x35, 0, 0}, VGA_REGSET_END};
79struct vga_regset vt8623_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x35, 2, 2}, VGA_REGSET_END};
80struct vga_regset vt8623_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x35, 3, 3}, VGA_REGSET_END};
81struct vga_regset vt8623_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
82struct vga_regset vt8623_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x35, 1, 1}, VGA_REGSET_END};
83struct vga_regset vt8623_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
84
85struct vga_regset vt8623_offset_regs[] = {{0x13, 0, 7}, {0x35, 5, 7}, VGA_REGSET_END};
86struct vga_regset vt8623_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x33, 0, 2}, {0x35, 4, 4}, VGA_REGSET_END};
87struct vga_regset vt8623_fetch_count_regs[] = {{0x1C, 0, 7}, {0x1D, 0, 1}, VGA_REGSET_END};
88struct vga_regset vt8623_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x34, 0, 7}, {0x48, 0, 1}, VGA_REGSET_END};
89
90struct svga_timing_regs vt8623_timing_regs = {
91 vt8623_h_total_regs, vt8623_h_display_regs, vt8623_h_blank_start_regs,
92 vt8623_h_blank_end_regs, vt8623_h_sync_start_regs, vt8623_h_sync_end_regs,
93 vt8623_v_total_regs, vt8623_v_display_regs, vt8623_v_blank_start_regs,
94 vt8623_v_blank_end_regs, vt8623_v_sync_start_regs, vt8623_v_sync_end_regs,
95};
96
97
98/* ------------------------------------------------------------------------- */
99
100
101/* Module parameters */
102
103static char *mode = "640x480-8@60";
104
105#ifdef CONFIG_MTRR
106static int mtrr = 1;
107#endif
108
109MODULE_AUTHOR("(c) 2006 Ondrej Zajicek <santiago@crfreenet.org>");
110MODULE_LICENSE("GPL");
111MODULE_DESCRIPTION("fbdev driver for integrated graphics core in VIA VT8623 [CLE266]");
112
113module_param(mode, charp, 0644);
114MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc)");
115
116#ifdef CONFIG_MTRR
117module_param(mtrr, int, 0444);
118MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
119#endif
120
121
122/* ------------------------------------------------------------------------- */
123
124
125static struct fb_tile_ops vt8623fb_tile_ops = {
126 .fb_settile = svga_settile,
127 .fb_tilecopy = svga_tilecopy,
128 .fb_tilefill = svga_tilefill,
129 .fb_tileblit = svga_tileblit,
130 .fb_tilecursor = svga_tilecursor,
131 .fb_get_tilemax = svga_get_tilemax,
132};
133
134
135/* ------------------------------------------------------------------------- */
136
137
138/* image data is MSB-first, fb structure is MSB-first too */
139static inline u32 expand_color(u32 c)
140{
141 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
142}
143
144/* vt8623fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
145static void vt8623fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
146{
147 u32 fg = expand_color(image->fg_color);
148 u32 bg = expand_color(image->bg_color);
149 const u8 *src1, *src;
150 u8 __iomem *dst1;
151 u32 __iomem *dst;
152 u32 val;
153 int x, y;
154
155 src1 = image->data;
156 dst1 = info->screen_base + (image->dy * info->fix.line_length)
157 + ((image->dx / 8) * 4);
158
159 for (y = 0; y < image->height; y++) {
160 src = src1;
161 dst = (u32 __iomem *) dst1;
162 for (x = 0; x < image->width; x += 8) {
163 val = *(src++) * 0x01010101;
164 val = (val & fg) | (~val & bg);
165 fb_writel(val, dst++);
166 }
167 src1 += image->width / 8;
168 dst1 += info->fix.line_length;
169 }
170}
171
172/* vt8623fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
173static void vt8623fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
174{
175 u32 fg = expand_color(rect->color);
176 u8 __iomem *dst1;
177 u32 __iomem *dst;
178 int x, y;
179
180 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
181 + ((rect->dx / 8) * 4);
182
183 for (y = 0; y < rect->height; y++) {
184 dst = (u32 __iomem *) dst1;
185 for (x = 0; x < rect->width; x += 8) {
186 fb_writel(fg, dst++);
187 }
188 dst1 += info->fix.line_length;
189 }
190}
191
192
193/* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
194static inline u32 expand_pixel(u32 c)
195{
196 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
197 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
198}
199
200/* vt8623fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
201static void vt8623fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
202{
203 u32 fg = image->fg_color * 0x11111111;
204 u32 bg = image->bg_color * 0x11111111;
205 const u8 *src1, *src;
206 u8 __iomem *dst1;
207 u32 __iomem *dst;
208 u32 val;
209 int x, y;
210
211 src1 = image->data;
212 dst1 = info->screen_base + (image->dy * info->fix.line_length)
213 + ((image->dx / 8) * 4);
214
215 for (y = 0; y < image->height; y++) {
216 src = src1;
217 dst = (u32 __iomem *) dst1;
218 for (x = 0; x < image->width; x += 8) {
219 val = expand_pixel(*(src++));
220 val = (val & fg) | (~val & bg);
221 fb_writel(val, dst++);
222 }
223 src1 += image->width / 8;
224 dst1 += info->fix.line_length;
225 }
226}
227
228static void vt8623fb_imageblit(struct fb_info *info, const struct fb_image *image)
229{
230 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
231 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
232 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
233 vt8623fb_iplan_imageblit(info, image);
234 else
235 vt8623fb_cfb4_imageblit(info, image);
236 } else
237 cfb_imageblit(info, image);
238}
239
240static void vt8623fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
241{
242 if ((info->var.bits_per_pixel == 4)
243 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
244 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
245 vt8623fb_iplan_fillrect(info, rect);
246 else
247 cfb_fillrect(info, rect);
248}
249
250
251/* ------------------------------------------------------------------------- */
252
253
254static void vt8623_set_pixclock(struct fb_info *info, u32 pixclock)
255{
256 u16 m, n, r;
257 u8 regval;
258 int rv;
259
260 rv = svga_compute_pll(&vt8623_pll, 1000000000 / pixclock, &m, &n, &r, info->node);
261 if (rv < 0) {
262 printk(KERN_ERR "fb%d: cannot set requested pixclock, keeping old value\n", info->node);
263 return;
264 }
265
266 /* Set VGA misc register */
267 regval = vga_r(NULL, VGA_MIS_R);
268 vga_w(NULL, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
269
270 /* Set clock registers */
271 vga_wseq(NULL, 0x46, (n | (r << 6)));
272 vga_wseq(NULL, 0x47, m);
273
274 udelay(1000);
275
276 /* PLL reset */
277 svga_wseq_mask(0x40, 0x02, 0x02);
278 svga_wseq_mask(0x40, 0x00, 0x02);
279}
280
281
282static int vt8623fb_open(struct fb_info *info, int user)
283{
284 struct vt8623fb_info *par = info->par;
285
286 mutex_lock(&(par->open_lock));
287 if (par->ref_count == 0) {
288 memset(&(par->state), 0, sizeof(struct vgastate));
289 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
290 par->state.num_crtc = 0xA2;
291 par->state.num_seq = 0x50;
292 save_vga(&(par->state));
293 }
294
295 par->ref_count++;
296 mutex_unlock(&(par->open_lock));
297
298 return 0;
299}
300
301static int vt8623fb_release(struct fb_info *info, int user)
302{
303 struct vt8623fb_info *par = info->par;
304
305 mutex_lock(&(par->open_lock));
306 if (par->ref_count == 0) {
307 mutex_unlock(&(par->open_lock));
308 return -EINVAL;
309 }
310
311 if (par->ref_count == 1)
312 restore_vga(&(par->state));
313
314 par->ref_count--;
315 mutex_unlock(&(par->open_lock));
316
317 return 0;
318}
319
320static int vt8623fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
321{
322 int rv, mem, step;
323
324 /* Find appropriate format */
325 rv = svga_match_format (vt8623fb_formats, var, NULL);
326 if (rv < 0)
327 {
328 printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
329 return rv;
330 }
331
332 /* Do not allow to have real resoulution larger than virtual */
333 if (var->xres > var->xres_virtual)
334 var->xres_virtual = var->xres;
335
336 if (var->yres > var->yres_virtual)
337 var->yres_virtual = var->yres;
338
339 /* Round up xres_virtual to have proper alignment of lines */
340 step = vt8623fb_formats[rv].xresstep - 1;
341 var->xres_virtual = (var->xres_virtual+step) & ~step;
342
343 /* Check whether have enough memory */
344 mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
345 if (mem > info->screen_size)
346 {
347 printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n", info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
348 return -EINVAL;
349 }
350
351 /* Text mode is limited to 256 kB of memory */
352 if ((var->bits_per_pixel == 0) && (mem > (256*1024)))
353 {
354 printk(KERN_ERR "fb%d: text framebuffer size too large (%d kB requested, 256 kB possible)\n", info->node, mem >> 10);
355 return -EINVAL;
356 }
357
358 rv = svga_check_timings (&vt8623_timing_regs, var, info->node);
359 if (rv < 0)
360 {
361 printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
362 return rv;
363 }
364
365 /* Interlaced mode not supported */
366 if (var->vmode & FB_VMODE_INTERLACED)
367 return -EINVAL;
368
369 return 0;
370}
371
372
373static int vt8623fb_set_par(struct fb_info *info)
374{
375 u32 mode, offset_value, fetch_value, screen_size;
376 u32 bpp = info->var.bits_per_pixel;
377
378 if (bpp != 0) {
379 info->fix.ypanstep = 1;
380 info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
381
382 info->flags &= ~FBINFO_MISC_TILEBLITTING;
383 info->tileops = NULL;
384
385 /* in 4bpp supports 8p wide tiles only, any tiles otherwise */
386 info->pixmap.blit_x = (bpp == 4) ? (1 << (8 - 1)) : (~(u32)0);
387 info->pixmap.blit_y = ~(u32)0;
388
389 offset_value = (info->var.xres_virtual * bpp) / 64;
390 fetch_value = ((info->var.xres * bpp) / 128) + 4;
391
392 if (bpp == 4)
393 fetch_value = (info->var.xres / 8) + 8; /* + 0 is OK */
394
395 screen_size = info->var.yres_virtual * info->fix.line_length;
396 } else {
397 info->fix.ypanstep = 16;
398 info->fix.line_length = 0;
399
400 info->flags |= FBINFO_MISC_TILEBLITTING;
401 info->tileops = &vt8623fb_tile_ops;
402
403 /* supports 8x16 tiles only */
404 info->pixmap.blit_x = 1 << (8 - 1);
405 info->pixmap.blit_y = 1 << (16 - 1);
406
407 offset_value = info->var.xres_virtual / 16;
408 fetch_value = (info->var.xres / 8) + 8;
409 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
410 }
411
412 info->var.xoffset = 0;
413 info->var.yoffset = 0;
414 info->var.activate = FB_ACTIVATE_NOW;
415
416 /* Unlock registers */
417 svga_wseq_mask(0x10, 0x01, 0x01);
418 svga_wcrt_mask(0x11, 0x00, 0x80);
419 svga_wcrt_mask(0x47, 0x00, 0x01);
420
421 /* Device, screen and sync off */
422 svga_wseq_mask(0x01, 0x20, 0x20);
423 svga_wcrt_mask(0x36, 0x30, 0x30);
424 svga_wcrt_mask(0x17, 0x00, 0x80);
425
426 /* Set default values */
427 svga_set_default_gfx_regs();
428 svga_set_default_atc_regs();
429 svga_set_default_seq_regs();
430 svga_set_default_crt_regs();
431 svga_wcrt_multi(vt8623_line_compare_regs, 0xFFFFFFFF);
432 svga_wcrt_multi(vt8623_start_address_regs, 0);
433
434 svga_wcrt_multi(vt8623_offset_regs, offset_value);
435 svga_wseq_multi(vt8623_fetch_count_regs, fetch_value);
436
437 if (info->var.vmode & FB_VMODE_DOUBLE)
438 svga_wcrt_mask(0x09, 0x80, 0x80);
439 else
440 svga_wcrt_mask(0x09, 0x00, 0x80);
441
442 svga_wseq_mask(0x1E, 0xF0, 0xF0); // DI/DVP bus
443 svga_wseq_mask(0x2A, 0x0F, 0x0F); // DI/DVP bus
444 svga_wseq_mask(0x16, 0x08, 0xBF); // FIFO read treshold
445 vga_wseq(NULL, 0x17, 0x1F); // FIFO depth
446 vga_wseq(NULL, 0x18, 0x4E);
447 svga_wseq_mask(0x1A, 0x08, 0x08); // enable MMIO ?
448
449 vga_wcrt(NULL, 0x32, 0x00);
450 vga_wcrt(NULL, 0x34, 0x00);
451 vga_wcrt(NULL, 0x6A, 0x80);
452 vga_wcrt(NULL, 0x6A, 0xC0);
453
454 vga_wgfx(NULL, 0x20, 0x00);
455 vga_wgfx(NULL, 0x21, 0x00);
456 vga_wgfx(NULL, 0x22, 0x00);
457
458 /* Set SR15 according to number of bits per pixel */
459 mode = svga_match_format(vt8623fb_formats, &(info->var), &(info->fix));
460 switch (mode) {
461 case 0:
462 pr_debug("fb%d: text mode\n", info->node);
463 svga_set_textmode_vga_regs();
464 svga_wseq_mask(0x15, 0x00, 0xFE);
465 svga_wcrt_mask(0x11, 0x60, 0x70);
466 break;
467 case 1:
468 pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
469 vga_wgfx(NULL, VGA_GFX_MODE, 0x40);
470 svga_wseq_mask(0x15, 0x20, 0xFE);
471 svga_wcrt_mask(0x11, 0x00, 0x70);
472 break;
473 case 2:
474 pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
475 svga_wseq_mask(0x15, 0x00, 0xFE);
476 svga_wcrt_mask(0x11, 0x00, 0x70);
477 break;
478 case 3:
479 pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
480 svga_wseq_mask(0x15, 0x22, 0xFE);
481 break;
482 case 4:
483 pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
484 svga_wseq_mask(0x15, 0xB6, 0xFE);
485 break;
486 case 5:
487 pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
488 svga_wseq_mask(0x15, 0xAE, 0xFE);
489 break;
490 default:
491 printk(KERN_ERR "vt8623fb: unsupported mode - bug\n");
492 return (-EINVAL);
493 }
494
495 vt8623_set_pixclock(info, info->var.pixclock);
496 svga_set_timings(&vt8623_timing_regs, &(info->var), 1, 1,
497 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1, 1,
498 1, info->node);
499
500 memset_io(info->screen_base, 0x00, screen_size);
501
502 /* Device and screen back on */
503 svga_wcrt_mask(0x17, 0x80, 0x80);
504 svga_wcrt_mask(0x36, 0x00, 0x30);
505 svga_wseq_mask(0x01, 0x00, 0x20);
506
507 return 0;
508}
509
510
511static int vt8623fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
512 u_int transp, struct fb_info *fb)
513{
514 switch (fb->var.bits_per_pixel) {
515 case 0:
516 case 4:
517 if (regno >= 16)
518 return -EINVAL;
519
520 outb(0x0F, VGA_PEL_MSK);
521 outb(regno, VGA_PEL_IW);
522 outb(red >> 10, VGA_PEL_D);
523 outb(green >> 10, VGA_PEL_D);
524 outb(blue >> 10, VGA_PEL_D);
525 break;
526 case 8:
527 if (regno >= 256)
528 return -EINVAL;
529
530 outb(0xFF, VGA_PEL_MSK);
531 outb(regno, VGA_PEL_IW);
532 outb(red >> 10, VGA_PEL_D);
533 outb(green >> 10, VGA_PEL_D);
534 outb(blue >> 10, VGA_PEL_D);
535 break;
536 case 16:
537 if (regno >= 16)
538 return 0;
539
540 if (fb->var.green.length == 5)
541 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
542 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
543 else if (fb->var.green.length == 6)
544 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
545 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
546 else
547 return -EINVAL;
548 break;
549 case 24:
550 case 32:
551 if (regno >= 16)
552 return 0;
553
554 /* ((transp & 0xFF00) << 16) */
555 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xFF00) << 8) |
556 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
557 break;
558 default:
559 return -EINVAL;
560 }
561
562 return 0;
563}
564
565
566static int vt8623fb_blank(int blank_mode, struct fb_info *info)
567{
568 switch (blank_mode) {
569 case FB_BLANK_UNBLANK:
570 pr_debug("fb%d: unblank\n", info->node);
571 svga_wcrt_mask(0x36, 0x00, 0x30);
572 svga_wseq_mask(0x01, 0x00, 0x20);
573 break;
574 case FB_BLANK_NORMAL:
575 pr_debug("fb%d: blank\n", info->node);
576 svga_wcrt_mask(0x36, 0x00, 0x30);
577 svga_wseq_mask(0x01, 0x20, 0x20);
578 break;
579 case FB_BLANK_HSYNC_SUSPEND:
580 pr_debug("fb%d: DPMS standby (hsync off)\n", info->node);
581 svga_wcrt_mask(0x36, 0x10, 0x30);
582 svga_wseq_mask(0x01, 0x20, 0x20);
583 break;
584 case FB_BLANK_VSYNC_SUSPEND:
585 pr_debug("fb%d: DPMS suspend (vsync off)\n", info->node);
586 svga_wcrt_mask(0x36, 0x20, 0x30);
587 svga_wseq_mask(0x01, 0x20, 0x20);
588 break;
589 case FB_BLANK_POWERDOWN:
590 pr_debug("fb%d: DPMS off (no sync)\n", info->node);
591 svga_wcrt_mask(0x36, 0x30, 0x30);
592 svga_wseq_mask(0x01, 0x20, 0x20);
593 break;
594 }
595
596 return 0;
597}
598
599
600static int vt8623fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
601{
602 unsigned int offset;
603
604 /* Calculate the offset */
605 if (var->bits_per_pixel == 0) {
606 offset = (var->yoffset / 16) * var->xres_virtual + var->xoffset;
607 offset = offset >> 3;
608 } else {
609 offset = (var->yoffset * info->fix.line_length) +
610 (var->xoffset * var->bits_per_pixel / 8);
611 offset = offset >> ((var->bits_per_pixel == 4) ? 2 : 1);
612 }
613
614 /* Set the offset */
615 svga_wcrt_multi(vt8623_start_address_regs, offset);
616
617 return 0;
618}
619
620
621/* ------------------------------------------------------------------------- */
622
623
624/* Frame buffer operations */
625
626static struct fb_ops vt8623fb_ops = {
627 .owner = THIS_MODULE,
628 .fb_open = vt8623fb_open,
629 .fb_release = vt8623fb_release,
630 .fb_check_var = vt8623fb_check_var,
631 .fb_set_par = vt8623fb_set_par,
632 .fb_setcolreg = vt8623fb_setcolreg,
633 .fb_blank = vt8623fb_blank,
634 .fb_pan_display = vt8623fb_pan_display,
635 .fb_fillrect = vt8623fb_fillrect,
636 .fb_copyarea = cfb_copyarea,
637 .fb_imageblit = vt8623fb_imageblit,
638 .fb_get_caps = svga_get_caps,
639};
640
641
642/* PCI probe */
643
644static int __devinit vt8623_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
645{
646 struct fb_info *info;
647 struct vt8623fb_info *par;
648 unsigned int memsize1, memsize2;
649 int rc;
650
651 /* Ignore secondary VGA device because there is no VGA arbitration */
652 if (! svga_primary_device(dev)) {
653 dev_info(&(dev->dev), "ignoring secondary device\n");
654 return -ENODEV;
655 }
656
657 /* Allocate and fill driver data structure */
658 info = framebuffer_alloc(sizeof(struct vt8623fb_info), NULL);
659 if (! info) {
660 dev_err(&(dev->dev), "cannot allocate memory\n");
661 return -ENOMEM;
662 }
663
664 par = info->par;
665 mutex_init(&par->open_lock);
666
667 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
668 info->fbops = &vt8623fb_ops;
669
670 /* Prepare PCI device */
671
672 rc = pci_enable_device(dev);
673 if (rc < 0) {
674 dev_err(&(dev->dev), "cannot enable PCI device\n");
675 goto err_enable_device;
676 }
677
678 rc = pci_request_regions(dev, "vt8623fb");
679 if (rc < 0) {
680 dev_err(&(dev->dev), "cannot reserve framebuffer region\n");
681 goto err_request_regions;
682 }
683
684 info->fix.smem_start = pci_resource_start(dev, 0);
685 info->fix.smem_len = pci_resource_len(dev, 0);
686 info->fix.mmio_start = pci_resource_start(dev, 1);
687 info->fix.mmio_len = pci_resource_len(dev, 1);
688
689 /* Map physical IO memory address into kernel space */
690 info->screen_base = pci_iomap(dev, 0, 0);
691 if (! info->screen_base) {
692 rc = -ENOMEM;
693 dev_err(&(dev->dev), "iomap for framebuffer failed\n");
694 goto err_iomap_1;
695 }
696
697 par->mmio_base = pci_iomap(dev, 1, 0);
698 if (! par->mmio_base) {
699 rc = -ENOMEM;
700 dev_err(&(dev->dev), "iomap for MMIO failed\n");
701 goto err_iomap_2;
702 }
703
704 /* Find how many physical memory there is on card */
705 memsize1 = (vga_rseq(NULL, 0x34) + 1) >> 1;
706 memsize2 = vga_rseq(NULL, 0x39) << 2;
707
708 if ((16 <= memsize1) && (memsize1 <= 64) && (memsize1 == memsize2))
709 info->screen_size = memsize1 << 20;
710 else {
711 dev_err(&(dev->dev), "memory size detection failed (%x %x), suppose 16 MB\n", memsize1, memsize2);
712 info->screen_size = 16 << 20;
713 }
714
715 info->fix.smem_len = info->screen_size;
716 strcpy(info->fix.id, "VIA VT8623");
717 info->fix.type = FB_TYPE_PACKED_PIXELS;
718 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
719 info->fix.ypanstep = 0;
720 info->fix.accel = FB_ACCEL_NONE;
721 info->pseudo_palette = (void*)par->pseudo_palette;
722
723 /* Prepare startup mode */
724
725 rc = fb_find_mode(&(info->var), info, mode, NULL, 0, NULL, 8);
726 if (! ((rc == 1) || (rc == 2))) {
727 rc = -EINVAL;
728 dev_err(&(dev->dev), "mode %s not found\n", mode);
729 goto err_find_mode;
730 }
731
732 rc = fb_alloc_cmap(&info->cmap, 256, 0);
733 if (rc < 0) {
734 dev_err(&(dev->dev), "cannot allocate colormap\n");
735 goto err_alloc_cmap;
736 }
737
738 rc = register_framebuffer(info);
739 if (rc < 0) {
740 dev_err(&(dev->dev), "cannot register framebugger\n");
741 goto err_reg_fb;
742 }
743
744 printk(KERN_INFO "fb%d: %s on %s, %d MB RAM\n", info->node, info->fix.id,
745 pci_name(dev), info->fix.smem_len >> 20);
746
747 /* Record a reference to the driver data */
748 pci_set_drvdata(dev, info);
749
750#ifdef CONFIG_MTRR
751 if (mtrr) {
752 par->mtrr_reg = -1;
753 par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
754 }
755#endif
756
757 return 0;
758
759 /* Error handling */
760err_reg_fb:
761 fb_dealloc_cmap(&info->cmap);
762err_alloc_cmap:
763err_find_mode:
764 pci_iounmap(dev, par->mmio_base);
765err_iomap_2:
766 pci_iounmap(dev, info->screen_base);
767err_iomap_1:
768 pci_release_regions(dev);
769err_request_regions:
770/* pci_disable_device(dev); */
771err_enable_device:
772 framebuffer_release(info);
773 return rc;
774}
775
776/* PCI remove */
777
778static void __devexit vt8623_pci_remove(struct pci_dev *dev)
779{
780 struct fb_info *info = pci_get_drvdata(dev);
781 struct vt8623fb_info *par = info->par;
782
783 if (info) {
784#ifdef CONFIG_MTRR
785 if (par->mtrr_reg >= 0) {
786 mtrr_del(par->mtrr_reg, 0, 0);
787 par->mtrr_reg = -1;
788 }
789#endif
790
791 unregister_framebuffer(info);
792 fb_dealloc_cmap(&info->cmap);
793
794 pci_iounmap(dev, info->screen_base);
795 pci_iounmap(dev, par->mmio_base);
796 pci_release_regions(dev);
797/* pci_disable_device(dev); */
798
799 pci_set_drvdata(dev, NULL);
800 framebuffer_release(info);
801 }
802}
803
804
805#ifdef CONFIG_PM
806/* PCI suspend */
807
808static int vt8623_pci_suspend(struct pci_dev* dev, pm_message_t state)
809{
810 struct fb_info *info = pci_get_drvdata(dev);
811 struct vt8623fb_info *par = info->par;
812
813 dev_info(&(dev->dev), "suspend\n");
814
815 acquire_console_sem();
816 mutex_lock(&(par->open_lock));
817
818 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
819 mutex_unlock(&(par->open_lock));
820 release_console_sem();
821 return 0;
822 }
823
824 fb_set_suspend(info, 1);
825
826 pci_save_state(dev);
827 pci_disable_device(dev);
828 pci_set_power_state(dev, pci_choose_state(dev, state));
829
830 mutex_unlock(&(par->open_lock));
831 release_console_sem();
832
833 return 0;
834}
835
836
837/* PCI resume */
838
839static int vt8623_pci_resume(struct pci_dev* dev)
840{
841 struct fb_info *info = pci_get_drvdata(dev);
842 struct vt8623fb_info *par = info->par;
843
844 dev_info(&(dev->dev), "resume\n");
845
846 acquire_console_sem();
847 mutex_lock(&(par->open_lock));
848
849 if (par->ref_count == 0) {
850 mutex_unlock(&(par->open_lock));
851 release_console_sem();
852 return 0;
853 }
854
855 pci_set_power_state(dev, PCI_D0);
856 pci_restore_state(dev);
857
858 if (pci_enable_device(dev))
859 goto fail;
860
861 pci_set_master(dev);
862
863 vt8623fb_set_par(info);
864 fb_set_suspend(info, 0);
865
866 mutex_unlock(&(par->open_lock));
867fail:
868 release_console_sem();
869
870 return 0;
871}
872#else
873#define vt8623_pci_suspend NULL
874#define vt8623_pci_resume NULL
875#endif /* CONFIG_PM */
876
877/* List of boards that we are trying to support */
878
879static struct pci_device_id vt8623_devices[] __devinitdata = {
880 {PCI_DEVICE(PCI_VENDOR_ID_VIA, 0x3122)},
881 {0, 0, 0, 0, 0, 0, 0}
882};
883
884MODULE_DEVICE_TABLE(pci, vt8623_devices);
885
886static struct pci_driver vt8623fb_pci_driver = {
887 .name = "vt8623fb",
888 .id_table = vt8623_devices,
889 .probe = vt8623_pci_probe,
890 .remove = __devexit_p(vt8623_pci_remove),
891 .suspend = vt8623_pci_suspend,
892 .resume = vt8623_pci_resume,
893};
894
895/* Cleanup */
896
897static void __exit vt8623fb_cleanup(void)
898{
899 pr_debug("vt8623fb: cleaning up\n");
900 pci_unregister_driver(&vt8623fb_pci_driver);
901}
902
903/* Driver Initialisation */
904
905int __init vt8623fb_init(void)
906{
907
908#ifndef MODULE
909 char *option = NULL;
910
911 if (fb_get_options("vt8623fb", &option))
912 return -ENODEV;
913
914 if (option && *option)
915 mode = option;
916#endif
917
918 pr_debug("vt8623fb: initializing\n");
919 return pci_register_driver(&vt8623fb_pci_driver);
920}
921
922/* ------------------------------------------------------------------------- */
923
924/* Modularization */
925
926module_init(vt8623fb_init);
927module_exit(vt8623fb_cleanup);
diff --git a/drivers/video/xilinxfb.c b/drivers/video/xilinxfb.c
new file mode 100644
index 000000000000..1d29a89a86b4
--- /dev/null
+++ b/drivers/video/xilinxfb.c
@@ -0,0 +1,381 @@
1/*
2 * xilinxfb.c
3 *
4 * Xilinx TFT LCD frame buffer driver
5 *
6 * Author: MontaVista Software, Inc.
7 * source@mvista.com
8 *
9 * 2002-2007 (c) MontaVista Software, Inc. This file is licensed under the
10 * terms of the GNU General Public License version 2. This program is licensed
11 * "as is" without any warranty of any kind, whether express or implied.
12 */
13
14/*
15 * This driver was based on au1100fb.c by MontaVista rewritten for 2.6
16 * by Embedded Alley Solutions <source@embeddedalley.com>, which in turn
17 * was based on skeletonfb.c, Skeleton for a frame buffer device by
18 * Geert Uytterhoeven.
19 */
20
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/version.h>
24#include <linux/errno.h>
25#include <linux/string.h>
26#include <linux/mm.h>
27#include <linux/fb.h>
28#include <linux/init.h>
29#include <linux/dma-mapping.h>
30#include <linux/platform_device.h>
31
32#include <asm/io.h>
33#include <syslib/virtex_devices.h>
34
35#define DRIVER_NAME "xilinxfb"
36#define DRIVER_DESCRIPTION "Xilinx TFT LCD frame buffer driver"
37
38/*
39 * Xilinx calls it "PLB TFT LCD Controller" though it can also be used for
40 * the VGA port on the Xilinx ML40x board. This is a hardware display controller
41 * for a 640x480 resolution TFT or VGA screen.
42 *
43 * The interface to the framebuffer is nice and simple. There are two
44 * control registers. The first tells the LCD interface where in memory
45 * the frame buffer is (only the 11 most significant bits are used, so
46 * don't start thinking about scrolling). The second allows the LCD to
47 * be turned on or off as well as rotated 180 degrees.
48 */
49#define NUM_REGS 2
50#define REG_FB_ADDR 0
51#define REG_CTRL 1
52#define REG_CTRL_ENABLE 0x0001
53#define REG_CTRL_ROTATE 0x0002
54
55/*
56 * The hardware only handles a single mode: 640x480 24 bit true
57 * color. Each pixel gets a word (32 bits) of memory. Within each word,
58 * the 8 most significant bits are ignored, the next 8 bits are the red
59 * level, the next 8 bits are the green level and the 8 least
60 * significant bits are the blue level. Each row of the LCD uses 1024
61 * words, but only the first 640 pixels are displayed with the other 384
62 * words being ignored. There are 480 rows.
63 */
64#define BYTES_PER_PIXEL 4
65#define BITS_PER_PIXEL (BYTES_PER_PIXEL * 8)
66#define XRES 640
67#define YRES 480
68#define XRES_VIRTUAL 1024
69#define YRES_VIRTUAL YRES
70#define LINE_LENGTH (XRES_VIRTUAL * BYTES_PER_PIXEL)
71#define FB_SIZE (YRES_VIRTUAL * LINE_LENGTH)
72
73#define RED_SHIFT 16
74#define GREEN_SHIFT 8
75#define BLUE_SHIFT 0
76
77#define PALETTE_ENTRIES_NO 16 /* passed to fb_alloc_cmap() */
78
79/*
80 * Here are the default fb_fix_screeninfo and fb_var_screeninfo structures
81 */
82static struct fb_fix_screeninfo xilinx_fb_fix __initdata = {
83 .id = "Xilinx",
84 .type = FB_TYPE_PACKED_PIXELS,
85 .visual = FB_VISUAL_TRUECOLOR,
86 .smem_len = FB_SIZE,
87 .line_length = LINE_LENGTH,
88 .accel = FB_ACCEL_NONE
89};
90
91static struct fb_var_screeninfo xilinx_fb_var __initdata = {
92 .xres = XRES,
93 .yres = YRES,
94 .xres_virtual = XRES_VIRTUAL,
95 .yres_virtual = YRES_VIRTUAL,
96
97 .bits_per_pixel = BITS_PER_PIXEL,
98
99 .red = { RED_SHIFT, 8, 0 },
100 .green = { GREEN_SHIFT, 8, 0 },
101 .blue = { BLUE_SHIFT, 8, 0 },
102 .transp = { 0, 0, 0 },
103
104 .activate = FB_ACTIVATE_NOW
105};
106
107struct xilinxfb_drvdata {
108
109 struct fb_info info; /* FB driver info record */
110
111 u32 regs_phys; /* phys. address of the control registers */
112 u32 __iomem *regs; /* virt. address of the control registers */
113
114 unsigned char __iomem *fb_virt; /* virt. address of the frame buffer */
115 dma_addr_t fb_phys; /* phys. address of the frame buffer */
116
117 u32 reg_ctrl_default;
118
119 u32 pseudo_palette[PALETTE_ENTRIES_NO];
120 /* Fake palette of 16 colors */
121};
122
123#define to_xilinxfb_drvdata(_info) \
124 container_of(_info, struct xilinxfb_drvdata, info)
125
126/*
127 * The LCD controller has DCR interface to its registers, but all
128 * the boards and configurations the driver has been tested with
129 * use opb2dcr bridge. So the registers are seen as memory mapped.
130 * This macro is to make it simple to add the direct DCR access
131 * when it's needed.
132 */
133#define xilinx_fb_out_be32(driverdata, offset, val) \
134 out_be32(driverdata->regs + offset, val)
135
136static int
137xilinx_fb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
138 unsigned transp, struct fb_info *fbi)
139{
140 u32 *palette = fbi->pseudo_palette;
141
142 if (regno >= PALETTE_ENTRIES_NO)
143 return -EINVAL;
144
145 if (fbi->var.grayscale) {
146 /* Convert color to grayscale.
147 * grayscale = 0.30*R + 0.59*G + 0.11*B */
148 red = green = blue =
149 (red * 77 + green * 151 + blue * 28 + 127) >> 8;
150 }
151
152 /* fbi->fix.visual is always FB_VISUAL_TRUECOLOR */
153
154 /* We only handle 8 bits of each color. */
155 red >>= 8;
156 green >>= 8;
157 blue >>= 8;
158 palette[regno] = (red << RED_SHIFT) | (green << GREEN_SHIFT) |
159 (blue << BLUE_SHIFT);
160
161 return 0;
162}
163
164static int
165xilinx_fb_blank(int blank_mode, struct fb_info *fbi)
166{
167 struct xilinxfb_drvdata *drvdata = to_xilinxfb_drvdata(fbi);
168
169 switch (blank_mode) {
170 case FB_BLANK_UNBLANK:
171 /* turn on panel */
172 xilinx_fb_out_be32(drvdata, REG_CTRL, drvdata->reg_ctrl_default);
173 break;
174
175 case FB_BLANK_NORMAL:
176 case FB_BLANK_VSYNC_SUSPEND:
177 case FB_BLANK_HSYNC_SUSPEND:
178 case FB_BLANK_POWERDOWN:
179 /* turn off panel */
180 xilinx_fb_out_be32(drvdata, REG_CTRL, 0);
181 default:
182 break;
183
184 }
185 return 0; /* success */
186}
187
188static struct fb_ops xilinxfb_ops =
189{
190 .owner = THIS_MODULE,
191 .fb_setcolreg = xilinx_fb_setcolreg,
192 .fb_blank = xilinx_fb_blank,
193 .fb_fillrect = cfb_fillrect,
194 .fb_copyarea = cfb_copyarea,
195 .fb_imageblit = cfb_imageblit,
196};
197
198/* === The device driver === */
199
200static int
201xilinxfb_drv_probe(struct device *dev)
202{
203 struct platform_device *pdev;
204 struct xilinxfb_platform_data *pdata;
205 struct xilinxfb_drvdata *drvdata;
206 struct resource *regs_res;
207 int retval;
208
209 if (!dev)
210 return -EINVAL;
211
212 pdev = to_platform_device(dev);
213 pdata = pdev->dev.platform_data;
214
215 if (pdata == NULL) {
216 printk(KERN_ERR "Couldn't find platform data.\n");
217 return -EFAULT;
218 }
219
220 drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL);
221 if (!drvdata) {
222 printk(KERN_ERR "Couldn't allocate device private record\n");
223 return -ENOMEM;
224 }
225 dev_set_drvdata(dev, drvdata);
226
227 /* Map the control registers in */
228 regs_res = platform_get_resource(pdev, IORESOURCE_IO, 0);
229 if (!regs_res || (regs_res->end - regs_res->start + 1 < 8)) {
230 printk(KERN_ERR "Couldn't get registers resource\n");
231 retval = -EFAULT;
232 goto failed1;
233 }
234
235 if (!request_mem_region(regs_res->start, 8, DRIVER_NAME)) {
236 printk(KERN_ERR
237 "Couldn't lock memory region at 0x%08X\n",
238 regs_res->start);
239 retval = -EBUSY;
240 goto failed1;
241 }
242 drvdata->regs = (u32 __iomem*) ioremap(regs_res->start, 8);
243 drvdata->regs_phys = regs_res->start;
244
245 /* Allocate the framebuffer memory */
246 drvdata->fb_virt = dma_alloc_coherent(dev, PAGE_ALIGN(FB_SIZE),
247 &drvdata->fb_phys, GFP_KERNEL);
248 if (!drvdata->fb_virt) {
249 printk(KERN_ERR "Could not allocate frame buffer memory\n");
250 retval = -ENOMEM;
251 goto failed2;
252 }
253
254 /* Clear (turn to black) the framebuffer */
255 memset_io((void *) drvdata->fb_virt, 0, FB_SIZE);
256
257 /* Tell the hardware where the frame buffer is */
258 xilinx_fb_out_be32(drvdata, REG_FB_ADDR, drvdata->fb_phys);
259
260 /* Turn on the display */
261 if (pdata->rotate_screen) {
262 drvdata->reg_ctrl_default = REG_CTRL_ENABLE | REG_CTRL_ROTATE;
263 } else {
264 drvdata->reg_ctrl_default = REG_CTRL_ENABLE;
265 }
266 xilinx_fb_out_be32(drvdata, REG_CTRL, drvdata->reg_ctrl_default);
267
268 /* Fill struct fb_info */
269 drvdata->info.device = dev;
270 drvdata->info.screen_base = drvdata->fb_virt;
271 drvdata->info.fbops = &xilinxfb_ops;
272 drvdata->info.fix = xilinx_fb_fix;
273 drvdata->info.fix.smem_start = drvdata->fb_phys;
274 drvdata->info.pseudo_palette = drvdata->pseudo_palette;
275
276 if (fb_alloc_cmap(&drvdata->info.cmap, PALETTE_ENTRIES_NO, 0) < 0) {
277 printk(KERN_ERR "Fail to allocate colormap (%d entries)\n",
278 PALETTE_ENTRIES_NO);
279 retval = -EFAULT;
280 goto failed3;
281 }
282
283 drvdata->info.flags = FBINFO_DEFAULT;
284 xilinx_fb_var.height = pdata->screen_height_mm;
285 xilinx_fb_var.width = pdata->screen_width_mm;
286 drvdata->info.var = xilinx_fb_var;
287
288 /* Register new frame buffer */
289 if (register_framebuffer(&drvdata->info) < 0) {
290 printk(KERN_ERR "Could not register frame buffer\n");
291 retval = -EINVAL;
292 goto failed4;
293 }
294
295 return 0; /* success */
296
297failed4:
298 fb_dealloc_cmap(&drvdata->info.cmap);
299
300failed3:
301 dma_free_coherent(dev, PAGE_ALIGN(FB_SIZE), drvdata->fb_virt,
302 drvdata->fb_phys);
303
304 /* Turn off the display */
305 xilinx_fb_out_be32(drvdata, REG_CTRL, 0);
306 iounmap(drvdata->regs);
307
308failed2:
309 release_mem_region(regs_res->start, 8);
310
311failed1:
312 kfree(drvdata);
313 dev_set_drvdata(dev, NULL);
314
315 return retval;
316}
317
318static int
319xilinxfb_drv_remove(struct device *dev)
320{
321 struct xilinxfb_drvdata *drvdata;
322
323 if (!dev)
324 return -ENODEV;
325
326 drvdata = (struct xilinxfb_drvdata *) dev_get_drvdata(dev);
327
328#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
329 xilinx_fb_blank(VESA_POWERDOWN, &drvdata->info);
330#endif
331
332 unregister_framebuffer(&drvdata->info);
333
334 fb_dealloc_cmap(&drvdata->info.cmap);
335
336 dma_free_coherent(dev, PAGE_ALIGN(FB_SIZE), drvdata->fb_virt,
337 drvdata->fb_phys);
338
339 /* Turn off the display */
340 xilinx_fb_out_be32(drvdata, REG_CTRL, 0);
341 iounmap(drvdata->regs);
342
343 release_mem_region(drvdata->regs_phys, 8);
344
345 kfree(drvdata);
346 dev_set_drvdata(dev, NULL);
347
348 return 0;
349}
350
351
352static struct device_driver xilinxfb_driver = {
353 .name = DRIVER_NAME,
354 .bus = &platform_bus_type,
355
356 .probe = xilinxfb_drv_probe,
357 .remove = xilinxfb_drv_remove
358};
359
360static int __init
361xilinxfb_init(void)
362{
363 /*
364 * No kernel boot options used,
365 * so we just need to register the driver
366 */
367 return driver_register(&xilinxfb_driver);
368}
369
370static void __exit
371xilinxfb_cleanup(void)
372{
373 driver_unregister(&xilinxfb_driver);
374}
375
376module_init(xilinxfb_init);
377module_exit(xilinxfb_cleanup);
378
379MODULE_AUTHOR("MontaVista Software, Inc. <source@mvista.com>");
380MODULE_DESCRIPTION(DRIVER_DESCRIPTION);
381MODULE_LICENSE("GPL");
diff --git a/drivers/w1/Kconfig b/drivers/w1/Kconfig
index c287a9ae4fdd..ca75b3ad3a2e 100644
--- a/drivers/w1/Kconfig
+++ b/drivers/w1/Kconfig
@@ -1,4 +1,5 @@
1menu "Dallas's 1-wire bus" 1menu "Dallas's 1-wire bus"
2 depends on HAS_IOMEM
2 3
3config W1 4config W1
4 tristate "Dallas's 1-wire support" 5 tristate "Dallas's 1-wire support"
diff --git a/drivers/w1/masters/Kconfig b/drivers/w1/masters/Kconfig
index 2fb425536eae..8f779338f744 100644
--- a/drivers/w1/masters/Kconfig
+++ b/drivers/w1/masters/Kconfig
@@ -35,5 +35,13 @@ config W1_MASTER_DS2482
35 This driver can also be built as a module. If so, the module 35 This driver can also be built as a module. If so, the module
36 will be called ds2482. 36 will be called ds2482.
37 37
38config W1_MASTER_DS1WM
39 tristate "Maxim DS1WM 1-wire busmaster"
40 depends on W1 && ARM
41 help
42 Say Y here to enable the DS1WM 1-wire driver, such as that
43 in HP iPAQ devices like h5xxx, h2200, and ASIC3-based like
44 hx4700.
45
38endmenu 46endmenu
39 47
diff --git a/drivers/w1/masters/Makefile b/drivers/w1/masters/Makefile
index 4cee256a8134..11551b328186 100644
--- a/drivers/w1/masters/Makefile
+++ b/drivers/w1/masters/Makefile
@@ -5,4 +5,4 @@
5obj-$(CONFIG_W1_MASTER_MATROX) += matrox_w1.o 5obj-$(CONFIG_W1_MASTER_MATROX) += matrox_w1.o
6obj-$(CONFIG_W1_MASTER_DS2490) += ds2490.o 6obj-$(CONFIG_W1_MASTER_DS2490) += ds2490.o
7obj-$(CONFIG_W1_MASTER_DS2482) += ds2482.o 7obj-$(CONFIG_W1_MASTER_DS2482) += ds2482.o
8 8obj-$(CONFIG_W1_MASTER_DS1WM) += ds1wm.o
diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c
new file mode 100644
index 000000000000..763bc73e5070
--- /dev/null
+++ b/drivers/w1/masters/ds1wm.c
@@ -0,0 +1,468 @@
1/*
2 * 1-wire busmaster driver for DS1WM and ASICs with embedded DS1WMs
3 * such as HP iPAQs (including h5xxx, h2200, and devices with ASIC3
4 * like hx4700).
5 *
6 * Copyright (c) 2004-2005, Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>
7 * Copyright (c) 2004-2007, Matt Reimer <mreimer@vpop.net>
8 *
9 * Use consistent with the GNU GPL is permitted,
10 * provided that this copyright notice is
11 * preserved in its entirety in all copies and derived works.
12 */
13
14#include <linux/module.h>
15#include <linux/interrupt.h>
16#include <linux/irq.h>
17#include <linux/pm.h>
18#include <linux/platform_device.h>
19#include <linux/clk.h>
20#include <linux/delay.h>
21#include <linux/ds1wm.h>
22
23#include <asm/io.h>
24
25#include "../w1.h"
26#include "../w1_int.h"
27
28
29#define DS1WM_CMD 0x00 /* R/W 4 bits command */
30#define DS1WM_DATA 0x01 /* R/W 8 bits, transmit/receive buffer */
31#define DS1WM_INT 0x02 /* R/W interrupt status */
32#define DS1WM_INT_EN 0x03 /* R/W interrupt enable */
33#define DS1WM_CLKDIV 0x04 /* R/W 5 bits of divisor and pre-scale */
34
35#define DS1WM_CMD_1W_RESET (1 << 0) /* force reset on 1-wire bus */
36#define DS1WM_CMD_SRA (1 << 1) /* enable Search ROM accelerator mode */
37#define DS1WM_CMD_DQ_OUTPUT (1 << 2) /* write only - forces bus low */
38#define DS1WM_CMD_DQ_INPUT (1 << 3) /* read only - reflects state of bus */
39#define DS1WM_CMD_RST (1 << 5) /* software reset */
40#define DS1WM_CMD_OD (1 << 7) /* overdrive */
41
42#define DS1WM_INT_PD (1 << 0) /* presence detect */
43#define DS1WM_INT_PDR (1 << 1) /* presence detect result */
44#define DS1WM_INT_TBE (1 << 2) /* tx buffer empty */
45#define DS1WM_INT_TSRE (1 << 3) /* tx shift register empty */
46#define DS1WM_INT_RBF (1 << 4) /* rx buffer full */
47#define DS1WM_INT_RSRF (1 << 5) /* rx shift register full */
48
49#define DS1WM_INTEN_EPD (1 << 0) /* enable presence detect int */
50#define DS1WM_INTEN_IAS (1 << 1) /* INTR active state */
51#define DS1WM_INTEN_ETBE (1 << 2) /* enable tx buffer empty int */
52#define DS1WM_INTEN_ETMT (1 << 3) /* enable tx shift register empty int */
53#define DS1WM_INTEN_ERBF (1 << 4) /* enable rx buffer full int */
54#define DS1WM_INTEN_ERSRF (1 << 5) /* enable rx shift register full int */
55#define DS1WM_INTEN_DQO (1 << 6) /* enable direct bus driving ops */
56
57
58#define DS1WM_TIMEOUT (HZ * 5)
59
60static struct {
61 unsigned long freq;
62 unsigned long divisor;
63} freq[] = {
64 { 4000000, 0x8 },
65 { 5000000, 0x2 },
66 { 6000000, 0x5 },
67 { 7000000, 0x3 },
68 { 8000000, 0xc },
69 { 10000000, 0x6 },
70 { 12000000, 0x9 },
71 { 14000000, 0x7 },
72 { 16000000, 0x10 },
73 { 20000000, 0xa },
74 { 24000000, 0xd },
75 { 28000000, 0xb },
76 { 32000000, 0x14 },
77 { 40000000, 0xe },
78 { 48000000, 0x11 },
79 { 56000000, 0xf },
80 { 64000000, 0x18 },
81 { 80000000, 0x12 },
82 { 96000000, 0x15 },
83 { 112000000, 0x13 },
84 { 128000000, 0x1c },
85};
86
87struct ds1wm_data {
88 void *map;
89 int bus_shift; /* # of shifts to calc register offsets */
90 struct platform_device *pdev;
91 struct ds1wm_platform_data *pdata;
92 int irq;
93 int active_high;
94 struct clk *clk;
95 int slave_present;
96 void *reset_complete;
97 void *read_complete;
98 void *write_complete;
99 u8 read_byte; /* last byte received */
100};
101
102static inline void ds1wm_write_register(struct ds1wm_data *ds1wm_data, u32 reg,
103 u8 val)
104{
105 __raw_writeb(val, ds1wm_data->map + (reg << ds1wm_data->bus_shift));
106}
107
108static inline u8 ds1wm_read_register(struct ds1wm_data *ds1wm_data, u32 reg)
109{
110 return __raw_readb(ds1wm_data->map + (reg << ds1wm_data->bus_shift));
111}
112
113
114static irqreturn_t ds1wm_isr(int isr, void *data)
115{
116 struct ds1wm_data *ds1wm_data = data;
117 u8 intr = ds1wm_read_register(ds1wm_data, DS1WM_INT);
118
119 ds1wm_data->slave_present = (intr & DS1WM_INT_PDR) ? 0 : 1;
120
121 if ((intr & DS1WM_INT_PD) && ds1wm_data->reset_complete)
122 complete(ds1wm_data->reset_complete);
123
124 if ((intr & DS1WM_INT_TSRE) && ds1wm_data->write_complete)
125 complete(ds1wm_data->write_complete);
126
127 if (intr & DS1WM_INT_RBF) {
128 ds1wm_data->read_byte = ds1wm_read_register(ds1wm_data,
129 DS1WM_DATA);
130 if (ds1wm_data->read_complete)
131 complete(ds1wm_data->read_complete);
132 }
133
134 return IRQ_HANDLED;
135}
136
137static int ds1wm_reset(struct ds1wm_data *ds1wm_data)
138{
139 unsigned long timeleft;
140 DECLARE_COMPLETION_ONSTACK(reset_done);
141
142 ds1wm_data->reset_complete = &reset_done;
143
144 ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, DS1WM_INTEN_EPD |
145 (ds1wm_data->active_high ? DS1WM_INTEN_IAS : 0));
146
147 ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_1W_RESET);
148
149 timeleft = wait_for_completion_timeout(&reset_done, DS1WM_TIMEOUT);
150 ds1wm_data->reset_complete = NULL;
151 if (!timeleft) {
152 dev_dbg(&ds1wm_data->pdev->dev, "reset failed\n");
153 return 1;
154 }
155
156 /* Wait for the end of the reset. According to the specs, the time
157 * from when the interrupt is asserted to the end of the reset is:
158 * tRSTH - tPDH - tPDL - tPDI
159 * 625 us - 60 us - 240 us - 100 ns = 324.9 us
160 *
161 * We'll wait a bit longer just to be sure.
162 */
163 udelay(500);
164
165 ds1wm_write_register(ds1wm_data, DS1WM_INT_EN,
166 DS1WM_INTEN_ERBF | DS1WM_INTEN_ETMT | DS1WM_INTEN_EPD |
167 (ds1wm_data->active_high ? DS1WM_INTEN_IAS : 0));
168
169 if (!ds1wm_data->slave_present) {
170 dev_dbg(&ds1wm_data->pdev->dev, "reset: no devices found\n");
171 return 1;
172 }
173
174 return 0;
175}
176
177static int ds1wm_write(struct ds1wm_data *ds1wm_data, u8 data)
178{
179 DECLARE_COMPLETION_ONSTACK(write_done);
180 ds1wm_data->write_complete = &write_done;
181
182 ds1wm_write_register(ds1wm_data, DS1WM_DATA, data);
183
184 wait_for_completion_timeout(&write_done, DS1WM_TIMEOUT);
185 ds1wm_data->write_complete = NULL;
186
187 return 0;
188}
189
190static int ds1wm_read(struct ds1wm_data *ds1wm_data, unsigned char write_data)
191{
192 DECLARE_COMPLETION_ONSTACK(read_done);
193 ds1wm_data->read_complete = &read_done;
194
195 ds1wm_write(ds1wm_data, write_data);
196 wait_for_completion_timeout(&read_done, DS1WM_TIMEOUT);
197 ds1wm_data->read_complete = NULL;
198
199 return ds1wm_data->read_byte;
200}
201
202static int ds1wm_find_divisor(int gclk)
203{
204 int i;
205
206 for (i = 0; i < ARRAY_SIZE(freq); i++)
207 if (gclk <= freq[i].freq)
208 return freq[i].divisor;
209
210 return 0;
211}
212
213static void ds1wm_up(struct ds1wm_data *ds1wm_data)
214{
215 int gclk, divisor;
216
217 if (ds1wm_data->pdata->enable)
218 ds1wm_data->pdata->enable(ds1wm_data->pdev);
219
220 gclk = clk_get_rate(ds1wm_data->clk);
221 clk_enable(ds1wm_data->clk);
222 divisor = ds1wm_find_divisor(gclk);
223 if (divisor == 0) {
224 dev_err(&ds1wm_data->pdev->dev,
225 "no suitable divisor for %dHz clock\n", gclk);
226 return;
227 }
228 ds1wm_write_register(ds1wm_data, DS1WM_CLKDIV, divisor);
229
230 /* Let the w1 clock stabilize. */
231 msleep(1);
232
233 ds1wm_reset(ds1wm_data);
234}
235
236static void ds1wm_down(struct ds1wm_data *ds1wm_data)
237{
238 ds1wm_reset(ds1wm_data);
239
240 /* Disable interrupts. */
241 ds1wm_write_register(ds1wm_data, DS1WM_INT_EN,
242 ds1wm_data->active_high ? DS1WM_INTEN_IAS : 0);
243
244 if (ds1wm_data->pdata->disable)
245 ds1wm_data->pdata->disable(ds1wm_data->pdev);
246
247 clk_disable(ds1wm_data->clk);
248}
249
250/* --------------------------------------------------------------------- */
251/* w1 methods */
252
253static u8 ds1wm_read_byte(void *data)
254{
255 struct ds1wm_data *ds1wm_data = data;
256
257 return ds1wm_read(ds1wm_data, 0xff);
258}
259
260static void ds1wm_write_byte(void *data, u8 byte)
261{
262 struct ds1wm_data *ds1wm_data = data;
263
264 ds1wm_write(ds1wm_data, byte);
265}
266
267static u8 ds1wm_reset_bus(void *data)
268{
269 struct ds1wm_data *ds1wm_data = data;
270
271 ds1wm_reset(ds1wm_data);
272
273 return 0;
274}
275
276static void ds1wm_search(void *data, u8 search_type,
277 w1_slave_found_callback slave_found)
278{
279 struct ds1wm_data *ds1wm_data = data;
280 int i;
281 unsigned long long rom_id;
282
283 /* XXX We need to iterate for multiple devices per the DS1WM docs.
284 * See http://www.maxim-ic.com/appnotes.cfm/appnote_number/120. */
285 if (ds1wm_reset(ds1wm_data))
286 return;
287
288 ds1wm_write(ds1wm_data, search_type);
289 ds1wm_write_register(ds1wm_data, DS1WM_CMD, DS1WM_CMD_SRA);
290
291 for (rom_id = 0, i = 0; i < 16; i++) {
292
293 unsigned char resp, r, d;
294
295 resp = ds1wm_read(ds1wm_data, 0x00);
296
297 r = ((resp & 0x02) >> 1) |
298 ((resp & 0x08) >> 2) |
299 ((resp & 0x20) >> 3) |
300 ((resp & 0x80) >> 4);
301
302 d = ((resp & 0x01) >> 0) |
303 ((resp & 0x04) >> 1) |
304 ((resp & 0x10) >> 2) |
305 ((resp & 0x40) >> 3);
306
307 rom_id |= (unsigned long long) r << (i * 4);
308
309 }
310 dev_dbg(&ds1wm_data->pdev->dev, "found 0x%08llX", rom_id);
311
312 ds1wm_write_register(ds1wm_data, DS1WM_CMD, ~DS1WM_CMD_SRA);
313 ds1wm_reset(ds1wm_data);
314
315 slave_found(ds1wm_data, rom_id);
316}
317
318/* --------------------------------------------------------------------- */
319
320static struct w1_bus_master ds1wm_master = {
321 .read_byte = ds1wm_read_byte,
322 .write_byte = ds1wm_write_byte,
323 .reset_bus = ds1wm_reset_bus,
324 .search = ds1wm_search,
325};
326
327static int ds1wm_probe(struct platform_device *pdev)
328{
329 struct ds1wm_data *ds1wm_data;
330 struct ds1wm_platform_data *plat;
331 struct resource *res;
332 int ret;
333
334 if (!pdev)
335 return -ENODEV;
336
337 ds1wm_data = kzalloc(sizeof (*ds1wm_data), GFP_KERNEL);
338 if (!ds1wm_data)
339 return -ENOMEM;
340
341 platform_set_drvdata(pdev, ds1wm_data);
342
343 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
344 if (!res) {
345 ret = -ENXIO;
346 goto err0;
347 }
348 ds1wm_data->map = ioremap(res->start, res->end - res->start + 1);
349 if (!ds1wm_data->map) {
350 ret = -ENOMEM;
351 goto err0;
352 }
353 plat = pdev->dev.platform_data;
354 ds1wm_data->bus_shift = plat->bus_shift;
355 ds1wm_data->pdev = pdev;
356 ds1wm_data->pdata = plat;
357
358 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
359 if (!res) {
360 ret = -ENXIO;
361 goto err1;
362 }
363 ds1wm_data->irq = res->start;
364 ds1wm_data->active_high = (res->flags & IORESOURCE_IRQ_HIGHEDGE) ?
365 1 : 0;
366
367 set_irq_type(ds1wm_data->irq, ds1wm_data->active_high ?
368 IRQ_TYPE_EDGE_RISING : IRQ_TYPE_EDGE_FALLING);
369
370 ret = request_irq(ds1wm_data->irq, ds1wm_isr, IRQF_DISABLED,
371 "ds1wm", ds1wm_data);
372 if (ret)
373 goto err1;
374
375 ds1wm_data->clk = clk_get(&pdev->dev, "ds1wm");
376 if (!ds1wm_data->clk) {
377 ret = -ENOENT;
378 goto err2;
379 }
380
381 ds1wm_up(ds1wm_data);
382
383 ds1wm_master.data = (void *)ds1wm_data;
384
385 ret = w1_add_master_device(&ds1wm_master);
386 if (ret)
387 goto err3;
388
389 return 0;
390
391err3:
392 ds1wm_down(ds1wm_data);
393 clk_put(ds1wm_data->clk);
394err2:
395 free_irq(ds1wm_data->irq, ds1wm_data);
396err1:
397 iounmap(ds1wm_data->map);
398err0:
399 kfree(ds1wm_data);
400
401 return ret;
402}
403
404#ifdef CONFIG_PM
405static int ds1wm_suspend(struct platform_device *pdev, pm_message_t state)
406{
407 struct ds1wm_data *ds1wm_data = platform_get_drvdata(pdev);
408
409 ds1wm_down(ds1wm_data);
410
411 return 0;
412}
413
414static int ds1wm_resume(struct platform_device *pdev)
415{
416 struct ds1wm_data *ds1wm_data = platform_get_drvdata(pdev);
417
418 ds1wm_up(ds1wm_data);
419
420 return 0;
421}
422#else
423#define ds1wm_suspend NULL
424#define ds1wm_resume NULL
425#endif
426
427static int ds1wm_remove(struct platform_device *pdev)
428{
429 struct ds1wm_data *ds1wm_data = platform_get_drvdata(pdev);
430
431 w1_remove_master_device(&ds1wm_master);
432 ds1wm_down(ds1wm_data);
433 clk_put(ds1wm_data->clk);
434 free_irq(ds1wm_data->irq, ds1wm_data);
435 iounmap(ds1wm_data->map);
436 kfree(ds1wm_data);
437
438 return 0;
439}
440
441static struct platform_driver ds1wm_driver = {
442 .driver = {
443 .name = "ds1wm",
444 },
445 .probe = ds1wm_probe,
446 .remove = ds1wm_remove,
447 .suspend = ds1wm_suspend,
448 .resume = ds1wm_resume
449};
450
451static int __init ds1wm_init(void)
452{
453 printk("DS1WM w1 busmaster driver - (c) 2004 Szabolcs Gyurko\n");
454 return platform_driver_register(&ds1wm_driver);
455}
456
457static void __exit ds1wm_exit(void)
458{
459 platform_driver_unregister(&ds1wm_driver);
460}
461
462module_init(ds1wm_init);
463module_exit(ds1wm_exit);
464
465MODULE_LICENSE("GPL");
466MODULE_AUTHOR("Szabolcs Gyurko <szabolcs.gyurko@tlt.hu>, "
467 "Matt Reimer <mreimer@vpop.net>");
468MODULE_DESCRIPTION("DS1WM w1 busmaster driver");
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 63c07243993c..7d6876dbcc96 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -459,7 +459,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
459 (unsigned long long) sl->reg_num.id); 459 (unsigned long long) sl->reg_num.id);
460 460
461 dev_dbg(&sl->dev, "%s: registering %s as %p.\n", __func__, 461 dev_dbg(&sl->dev, "%s: registering %s as %p.\n", __func__,
462 &sl->dev.bus_id[0]); 462 &sl->dev.bus_id[0], sl);
463 463
464 err = device_register(&sl->dev); 464 err = device_register(&sl->dev);
465 if (err < 0) { 465 if (err < 0) {
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 357a2e0f637a..258defdb2efd 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -100,7 +100,8 @@ int w1_add_master_device(struct w1_bus_master *master)
100 100
101 /* validate minimum functionality */ 101 /* validate minimum functionality */
102 if (!(master->touch_bit && master->reset_bus) && 102 if (!(master->touch_bit && master->reset_bus) &&
103 !(master->write_bit && master->read_bit)) { 103 !(master->write_bit && master->read_bit) &&
104 !(master->write_byte && master->read_byte && master->reset_bus)) {
104 printk(KERN_ERR "w1_add_master_device: invalid function set\n"); 105 printk(KERN_ERR "w1_add_master_device: invalid function set\n");
105 return(-EINVAL); 106 return(-EINVAL);
106 } 107 }