aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2007-02-17 15:09:59 -0500
committerJeff Garzik <jeff@garzik.org>2007-02-17 15:09:59 -0500
commit48c871c1f6a7c7044dd76774fb469e65c7e2e4e8 (patch)
treeda3aa535c98cc0957851354ceb0fbff7482d7a9d /drivers
parent1a1689344add3333d28d1b5495d8043a3877d01c (diff)
parent4409d28140d9a6e6e3f4f1fdaf7234c4b965d954 (diff)
Merge branch 'gfar' of master.kernel.org:/pub/scm/linux/kernel/git/galak/powerpc into upstream
Diffstat (limited to 'drivers')
-rw-r--r--drivers/Kconfig2
-rw-r--r--drivers/Makefile1
-rw-r--r--drivers/acorn/char/i2c.c2
-rw-r--r--drivers/ata/Kconfig41
-rw-r--r--drivers/ata/Makefile3
-rw-r--r--drivers/ata/ahci.c236
-rw-r--r--drivers/ata/ata_generic.c8
-rw-r--r--drivers/ata/ata_piix.c56
-rw-r--r--drivers/ata/libata-core.c591
-rw-r--r--drivers/ata/libata-eh.c7
-rw-r--r--drivers/ata/libata-scsi.c98
-rw-r--r--drivers/ata/libata-sff.c641
-rw-r--r--drivers/ata/libata.h4
-rw-r--r--drivers/ata/pata_ali.c32
-rw-r--r--drivers/ata/pata_amd.c36
-rw-r--r--drivers/ata/pata_artop.c12
-rw-r--r--drivers/ata/pata_atiixp.c6
-rw-r--r--drivers/ata/pata_cmd64x.c18
-rw-r--r--drivers/ata/pata_cs5520.c41
-rw-r--r--drivers/ata/pata_cs5530.c41
-rw-r--r--drivers/ata/pata_cs5535.c6
-rw-r--r--drivers/ata/pata_cypress.c6
-rw-r--r--drivers/ata/pata_efar.c6
-rw-r--r--drivers/ata/pata_hpt366.c26
-rw-r--r--drivers/ata/pata_hpt37x.c61
-rw-r--r--drivers/ata/pata_hpt3x2n.c26
-rw-r--r--drivers/ata/pata_hpt3x3.c8
-rw-r--r--drivers/ata/pata_isapnp.c21
-rw-r--r--drivers/ata/pata_it8213.c354
-rw-r--r--drivers/ata/pata_it821x.c58
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c50
-rw-r--r--drivers/ata/pata_jmicron.c8
-rw-r--r--drivers/ata/pata_legacy.c166
-rw-r--r--drivers/ata/pata_marvell.c12
-rw-r--r--drivers/ata/pata_mpc52xx.c538
-rw-r--r--drivers/ata/pata_mpiix.c113
-rw-r--r--drivers/ata/pata_netcell.c6
-rw-r--r--drivers/ata/pata_ns87410.c6
-rw-r--r--drivers/ata/pata_oldpiix.c24
-rw-r--r--drivers/ata/pata_opti.c24
-rw-r--r--drivers/ata/pata_optidma.c40
-rw-r--r--drivers/ata/pata_pcmcia.c27
-rw-r--r--drivers/ata/pata_pdc2027x.c122
-rw-r--r--drivers/ata/pata_pdc202xx_old.c41
-rw-r--r--drivers/ata/pata_platform.c67
-rw-r--r--drivers/ata/pata_qdi.c50
-rw-r--r--drivers/ata/pata_radisys.c6
-rw-r--r--drivers/ata/pata_rz1000.c6
-rw-r--r--drivers/ata/pata_sc1200.c6
-rw-r--r--drivers/ata/pata_serverworks.c31
-rw-r--r--drivers/ata/pata_sil680.c8
-rw-r--r--drivers/ata/pata_sis.c70
-rw-r--r--drivers/ata/pata_sl82c105.c10
-rw-r--r--drivers/ata/pata_triflex.c6
-rw-r--r--drivers/ata/pata_via.c22
-rw-r--r--drivers/ata/pata_winbond.c49
-rw-r--r--drivers/ata/pdc_adma.c120
-rw-r--r--drivers/ata/sata_inic162x.c781
-rw-r--r--drivers/ata/sata_mv.c200
-rw-r--r--drivers/ata/sata_nv.c629
-rw-r--r--drivers/ata/sata_promise.c379
-rw-r--r--drivers/ata/sata_qstor.c138
-rw-r--r--drivers/ata/sata_sil.c99
-rw-r--r--drivers/ata/sata_sil24.c178
-rw-r--r--drivers/ata/sata_sis.c161
-rw-r--r--drivers/ata/sata_svw.c127
-rw-r--r--drivers/ata/sata_sx4.c207
-rw-r--r--drivers/ata/sata_uli.c66
-rw-r--r--drivers/ata/sata_via.c193
-rw-r--r--drivers/ata/sata_vsc.c134
-rw-r--r--drivers/atm/eni.c1
-rw-r--r--drivers/auxdisplay/Kconfig109
-rw-r--r--drivers/auxdisplay/Makefile6
-rw-r--r--drivers/auxdisplay/cfag12864b.c383
-rw-r--r--drivers/auxdisplay/cfag12864bfb.c180
-rw-r--r--drivers/auxdisplay/ks0108.c166
-rw-r--r--drivers/base/Kconfig12
-rw-r--r--drivers/base/Makefile1
-rw-r--r--drivers/base/base.h1
-rw-r--r--drivers/base/core.c2
-rw-r--r--drivers/base/dd.c3
-rw-r--r--drivers/base/devres.c644
-rw-r--r--drivers/base/dma-mapping.c218
-rw-r--r--drivers/base/dmapool.c59
-rw-r--r--drivers/base/node.c9
-rw-r--r--drivers/block/DAC960.c101
-rw-r--r--drivers/block/DAC960.h495
-rw-r--r--drivers/block/Kconfig4
-rw-r--r--drivers/block/acsi_slm.c2
-rw-r--r--drivers/block/aoe/aoechr.c2
-rw-r--r--drivers/block/paride/Kconfig8
-rw-r--r--drivers/block/paride/pg.c2
-rw-r--r--drivers/block/paride/pt.c2
-rw-r--r--drivers/block/pktcdvd.c32
-rw-r--r--drivers/bluetooth/hci_vhci.c2
-rw-r--r--drivers/cdrom/viocd.c2
-rw-r--r--drivers/char/Kconfig4
-rw-r--r--drivers/char/amiserial.c8
-rw-r--r--drivers/char/briq_panel.c2
-rw-r--r--drivers/char/cyclades.c24
-rw-r--r--drivers/char/drm/drm_drv.c2
-rw-r--r--drivers/char/drm/i810_dma.c2
-rw-r--r--drivers/char/drm/i830_dma.c2
-rw-r--r--drivers/char/drm/via_dmablit.c14
-rw-r--r--drivers/char/ds1302.c2
-rw-r--r--drivers/char/dtlk.c8
-rw-r--r--drivers/char/epca.c3
-rw-r--r--drivers/char/generic_nvram.c2
-rw-r--r--drivers/char/generic_serial.c1
-rw-r--r--drivers/char/hw_random/intel-rng.c76
-rw-r--r--drivers/char/ip2/i2lib.c40
-rw-r--r--drivers/char/ip2/ip2main.c4
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c30
-rw-r--r--drivers/char/isicom.c108
-rw-r--r--drivers/char/istallion.c1
-rw-r--r--drivers/char/keyboard.c12
-rw-r--r--drivers/char/mbcs.c2
-rw-r--r--drivers/char/moxa.c927
-rw-r--r--drivers/char/mspec.c6
-rw-r--r--drivers/char/mxser.c11
-rw-r--r--drivers/char/mxser.h8
-rw-r--r--drivers/char/mxser_new.c236
-rw-r--r--drivers/char/mxser_new.h477
-rw-r--r--drivers/char/n_r3964.c2095
-rw-r--r--drivers/char/n_tty.c14
-rw-r--r--drivers/char/nwbutton.c13
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c10
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c3
-rw-r--r--drivers/char/pcmcia/synclink_cs.c14
-rw-r--r--drivers/char/random.c4
-rw-r--r--drivers/char/raw.c2
-rw-r--r--drivers/char/rio/rio_linux.c12
-rw-r--r--drivers/char/rio/riointr.c9
-rw-r--r--drivers/char/riscom8.c5
-rw-r--r--drivers/char/rocket.c13
-rw-r--r--drivers/char/rtc.c12
-rw-r--r--drivers/char/scan_keyb.c149
-rw-r--r--drivers/char/scan_keyb.h15
-rw-r--r--drivers/char/serial167.c3322
-rw-r--r--drivers/char/specialix.c18
-rw-r--r--drivers/char/synclink.c15
-rw-r--r--drivers/char/synclink_gt.c24
-rw-r--r--drivers/char/synclinkmp.c27
-rw-r--r--drivers/char/sysrq.c6
-rw-r--r--drivers/char/toshiba.c35
-rw-r--r--drivers/char/tpm/tpm.c5
-rw-r--r--drivers/char/tpm/tpm_bios.c4
-rw-r--r--drivers/char/tty_io.c246
-rw-r--r--drivers/char/tty_ioctl.c45
-rw-r--r--drivers/char/viotape.c2
-rw-r--r--drivers/char/vt.c11
-rw-r--r--drivers/char/vt_ioctl.c28
-rw-r--r--drivers/char/watchdog/alim7101_wdt.c6
-rw-r--r--drivers/char/watchdog/iTCO_wdt.c2
-rw-r--r--drivers/char/watchdog/omap_wdt.c2
-rw-r--r--drivers/char/watchdog/pc87413_wdt.c2
-rw-r--r--drivers/char/watchdog/pnx4008_wdt.c2
-rw-r--r--drivers/char/watchdog/rm9k_wdt.c2
-rw-r--r--drivers/char/watchdog/smsc37b787_wdt.c2
-rw-r--r--drivers/char/watchdog/w83697hf_wdt.c2
-rw-r--r--drivers/edac/e752x_edac.c40
-rw-r--r--drivers/edac/edac_mc.c175
-rw-r--r--drivers/edac/edac_mc.h28
-rw-r--r--drivers/firmware/edd.c8
-rw-r--r--drivers/i2c/chips/tps65010.c2
-rw-r--r--drivers/i2c/i2c-dev.c2
-rw-r--r--drivers/ide/ide-proc.c3
-rw-r--r--drivers/ide/ide-tape.c2
-rw-r--r--drivers/ieee1394/dv1394.c2
-rw-r--r--drivers/ieee1394/raw1394.c2
-rw-r--r--drivers/ieee1394/video1394.c2
-rw-r--r--drivers/infiniband/core/ucm.c2
-rw-r--r--drivers/infiniband/core/ucma.c2
-rw-r--r--drivers/infiniband/core/user_mad.c4
-rw-r--r--drivers/infiniband/core/uverbs_main.c6
-rw-r--r--drivers/infiniband/hw/ehca/ehca_cq.c3
-rw-r--r--drivers/infiniband/hw/ehca/ehca_mrmw.c6
-rw-r--r--drivers/infiniband/hw/ehca/ehca_pd.c3
-rw-r--r--drivers/infiniband/hw/ehca/ehca_qp.c3
-rw-r--r--drivers/infiniband/hw/ipath/ipath_diag.c4
-rw-r--r--drivers/infiniband/hw/ipath/ipath_file_ops.c6
-rw-r--r--drivers/infiniband/hw/ipath/ipath_fs.c14
-rw-r--r--drivers/infiniband/hw/ipath/ipath_kernel.h2
-rw-r--r--drivers/infiniband/ulp/ipoib/ipoib_fs.c4
-rw-r--r--drivers/input/gameport/ns558.c1
-rw-r--r--drivers/input/input.c6
-rw-r--r--drivers/input/keyboard/Kconfig19
-rw-r--r--drivers/input/keyboard/Makefile5
-rw-r--r--drivers/input/keyboard/gpio_keys.c147
-rw-r--r--drivers/input/keyboard/hilkbd.c114
-rw-r--r--drivers/input/misc/Kconfig10
-rw-r--r--drivers/input/misc/Makefile1
-rw-r--r--drivers/input/misc/atlas_btns.c170
-rw-r--r--drivers/input/misc/hp_sdc_rtc.c2
-rw-r--r--drivers/input/misc/uinput.c2
-rw-r--r--drivers/input/misc/wistron_btns.c20
-rw-r--r--drivers/input/mouse/inport.c2
-rw-r--r--drivers/input/mouse/pc110pad.c2
-rw-r--r--drivers/input/serio/i8042.c12
-rw-r--r--drivers/input/serio/serio_raw.c2
-rw-r--r--drivers/input/touchscreen/Kconfig9
-rw-r--r--drivers/input/touchscreen/ads7846.c581
-rw-r--r--drivers/input/tsdev.c4
-rw-r--r--drivers/isdn/capi/capi.c41
-rw-r--r--drivers/isdn/capi/capidrv.c4
-rw-r--r--drivers/isdn/capi/kcapi_proc.c10
-rw-r--r--drivers/isdn/divert/divert_procfs.c2
-rw-r--r--drivers/isdn/gigaset/Kconfig25
-rw-r--r--drivers/isdn/gigaset/Makefile2
-rw-r--r--drivers/isdn/gigaset/asyncdata.c5
-rw-r--r--drivers/isdn/gigaset/bas-gigaset.c4
-rw-r--r--drivers/isdn/gigaset/common.c24
-rw-r--r--drivers/isdn/gigaset/ev-layer.c2
-rw-r--r--drivers/isdn/gigaset/interface.c17
-rw-r--r--drivers/isdn/gigaset/isocdata.c4
-rw-r--r--drivers/isdn/gigaset/ser-gigaset.c837
-rw-r--r--drivers/isdn/hardware/avm/b1dma.c14
-rw-r--r--drivers/isdn/hardware/avm/c4.c16
-rw-r--r--drivers/isdn/hardware/eicon/capifunc.c4
-rw-r--r--drivers/isdn/hardware/eicon/debug.c30
-rw-r--r--drivers/isdn/hardware/eicon/di.c16
-rw-r--r--drivers/isdn/hardware/eicon/divamnt.c2
-rw-r--r--drivers/isdn/hardware/eicon/divasi.c2
-rw-r--r--drivers/isdn/hardware/eicon/divasmain.c2
-rw-r--r--drivers/isdn/hardware/eicon/divasproc.c2
-rw-r--r--drivers/isdn/hardware/eicon/message.c383
-rw-r--r--drivers/isdn/hardware/eicon/os_pri.c4
-rw-r--r--drivers/isdn/hardware/eicon/platform.h12
-rw-r--r--drivers/isdn/hisax/Kconfig2
-rw-r--r--drivers/isdn/hisax/Makefile1
-rw-r--r--drivers/isdn/hisax/config.c11
-rw-r--r--drivers/isdn/hisax/elsa_ser.c8
-rw-r--r--drivers/isdn/hisax/hfc4s8s_l1.c48
-rw-r--r--drivers/isdn/hisax/hfc_usb.c40
-rw-r--r--drivers/isdn/hisax/hfc_usb.h3
-rw-r--r--drivers/isdn/hisax/hisax.h25
-rw-r--r--drivers/isdn/hisax/isar.c1
-rw-r--r--drivers/isdn/hisax/isdnl1.h17
-rw-r--r--drivers/isdn/hisax/isdnl3.c12
-rw-r--r--drivers/isdn/hisax/isdnl3.h26
-rw-r--r--drivers/isdn/hysdn/hysdn_procconf.c2
-rw-r--r--drivers/isdn/hysdn/hysdn_proclog.c2
-rw-r--r--drivers/isdn/i4l/isdn_common.c2
-rw-r--r--drivers/isdn/i4l/isdn_tty.c1
-rw-r--r--drivers/isdn/pcbit/drv.c4
-rw-r--r--drivers/isdn/pcbit/edss1.c6
-rw-r--r--drivers/isdn/pcbit/edss1.h7
-rw-r--r--drivers/isdn/pcbit/layer2.c16
-rw-r--r--drivers/isdn/pcbit/module.c3
-rw-r--r--drivers/isdn/pcbit/pcbit.h8
-rw-r--r--drivers/isdn/sc/card.h30
-rw-r--r--drivers/isdn/sc/command.c17
-rw-r--r--drivers/isdn/sc/event.c3
-rw-r--r--drivers/isdn/sc/init.c6
-rw-r--r--drivers/isdn/sc/interrupt.c10
-rw-r--r--drivers/isdn/sc/ioctl.c10
-rw-r--r--drivers/isdn/sc/message.c10
-rw-r--r--drivers/isdn/sc/packet.c10
-rw-r--r--drivers/isdn/sc/scioc.h6
-rw-r--r--drivers/isdn/sc/shmem.c6
-rw-r--r--drivers/isdn/sc/timer.c8
-rw-r--r--drivers/kvm/kvm.h4
-rw-r--r--drivers/kvm/kvm_main.c123
-rw-r--r--drivers/kvm/paging_tmpl.h28
-rw-r--r--drivers/kvm/svm.c15
-rw-r--r--drivers/kvm/vmx.c43
-rw-r--r--drivers/kvm/vmx.h1
-rw-r--r--drivers/macintosh/adb.c2
-rw-r--r--drivers/macintosh/ans-lcd.c2
-rw-r--r--drivers/macintosh/apm_emu.c2
-rw-r--r--drivers/macintosh/nvram.c2
-rw-r--r--drivers/macintosh/smu.c2
-rw-r--r--drivers/macintosh/via-pmu.c3
-rw-r--r--drivers/macintosh/via-pmu68k.c2
-rw-r--r--drivers/md/bitmap.c2
-rw-r--r--drivers/md/dm-ioctl.c2
-rw-r--r--drivers/md/md.c2
-rw-r--r--drivers/media/common/saa7146_fops.c2
-rw-r--r--drivers/media/radio/dsbr100.c2
-rw-r--r--drivers/media/radio/miropcm20-radio.c2
-rw-r--r--drivers/media/radio/miropcm20-rds.c2
-rw-r--r--drivers/media/radio/radio-aimslab.c2
-rw-r--r--drivers/media/radio/radio-aztech.c2
-rw-r--r--drivers/media/radio/radio-cadet.c2
-rw-r--r--drivers/media/radio/radio-gemtek-pci.c2
-rw-r--r--drivers/media/radio/radio-gemtek.c2
-rw-r--r--drivers/media/radio/radio-maestro.c2
-rw-r--r--drivers/media/radio/radio-maxiradio.c2
-rw-r--r--drivers/media/radio/radio-rtrack2.c2
-rw-r--r--drivers/media/radio/radio-sf16fmi.c2
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c2
-rw-r--r--drivers/media/radio/radio-terratec.c2
-rw-r--r--drivers/media/radio/radio-trust.c2
-rw-r--r--drivers/media/radio/radio-typhoon.c2
-rw-r--r--drivers/media/radio/radio-zoltrix.c2
-rw-r--r--drivers/media/video/arv.c2
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c4
-rw-r--r--drivers/media/video/bw-qcam.c2
-rw-r--r--drivers/media/video/c-qcam.c2
-rw-r--r--drivers/media/video/cafe_ccic.c6
-rw-r--r--drivers/media/video/cpia.c2
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c2
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c2
-rw-r--r--drivers/media/video/cx88/cx88-video.c4
-rw-r--r--drivers/media/video/dabusb.c2
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c2
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c2
-rw-r--r--drivers/media/video/meye.c2
-rw-r--r--drivers/media/video/ov511.c2
-rw-r--r--drivers/media/video/pms.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c2
-rw-r--r--drivers/media/video/pwc/pwc-if.c2
-rw-r--r--drivers/media/video/saa5246a.c2
-rw-r--r--drivers/media/video/saa5249.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-oss.c4
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c4
-rw-r--r--drivers/media/video/saa7134/saa7134.h4
-rw-r--r--drivers/media/video/se401.c2
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c2
-rw-r--r--drivers/media/video/stradis.c2
-rw-r--r--drivers/media/video/stv680.c2
-rw-r--r--drivers/media/video/tvmixer.c2
-rw-r--r--drivers/media/video/usbvideo/usbvideo.c2
-rw-r--r--drivers/media/video/usbvideo/vicam.c2
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c6
-rw-r--r--drivers/media/video/videodev.c4
-rw-r--r--drivers/media/video/vino.c2
-rw-r--r--drivers/media/video/vivi.c2
-rw-r--r--drivers/media/video/w9966.c2
-rw-r--r--drivers/media/video/w9968cf.c4
-rw-r--r--drivers/media/video/zc0301/zc0301_core.c2
-rw-r--r--drivers/media/video/zoran_driver.c3
-rw-r--r--drivers/media/video/zoran_procfs.c2
-rw-r--r--drivers/message/fusion/Kconfig2
-rw-r--r--drivers/message/fusion/Makefile7
-rw-r--r--drivers/message/fusion/lsi/mpi.h7
-rw-r--r--drivers/message/fusion/lsi/mpi_cnfg.h131
-rw-r--r--drivers/message/fusion/lsi/mpi_history.txt77
-rw-r--r--drivers/message/fusion/lsi/mpi_init.h7
-rw-r--r--drivers/message/fusion/lsi/mpi_ioc.h75
-rw-r--r--drivers/message/fusion/lsi/mpi_log_sas.h284
-rw-r--r--drivers/message/fusion/lsi/mpi_sas.h9
-rw-r--r--drivers/message/fusion/mptbase.c875
-rw-r--r--drivers/message/fusion/mptbase.h47
-rw-r--r--drivers/message/fusion/mptctl.c165
-rw-r--r--drivers/message/fusion/mptctl.h2
-rw-r--r--drivers/message/fusion/mptfc.c53
-rw-r--r--drivers/message/fusion/mptlan.c1
-rw-r--r--drivers/message/fusion/mptlan.h1
-rw-r--r--drivers/message/fusion/mptsas.c718
-rw-r--r--drivers/message/fusion/mptscsih.c997
-rw-r--r--drivers/message/fusion/mptscsih.h44
-rw-r--r--drivers/message/fusion/mptspi.c527
-rw-r--r--drivers/message/i2o/i2o_config.c2
-rw-r--r--drivers/message/i2o/i2o_proc.c38
-rw-r--r--drivers/misc/hdpuftrs/hdpu_cpustate.c2
-rw-r--r--drivers/misc/hdpuftrs/hdpu_nexus.c2
-rw-r--r--drivers/misc/ibmasm/ibmasmfs.c10
-rw-r--r--drivers/misc/ioc4.c6
-rw-r--r--drivers/mmc/sdhci.c40
-rw-r--r--drivers/mmc/tifm_sd.c11
-rw-r--r--drivers/mmc/wbsd.c6
-rw-r--r--drivers/mtd/devices/block2mtd.c3
-rw-r--r--drivers/mtd/mtdchar.c2
-rw-r--r--drivers/net/arcnet/com20020.c3
-rw-r--r--drivers/net/bonding/bond_main.c2
-rw-r--r--drivers/net/gianfar_sysfs.c108
-rw-r--r--drivers/net/hamradio/bpqether.c2
-rw-r--r--drivers/net/hamradio/scc.c2
-rw-r--r--drivers/net/hamradio/yam.c2
-rw-r--r--drivers/net/ibmveth.c2
-rw-r--r--drivers/net/irda/vlsi_ir.c2
-rw-r--r--drivers/net/ppp_generic.c4
-rw-r--r--drivers/net/pppoe.c2
-rw-r--r--drivers/net/tun.c2
-rw-r--r--drivers/net/wan/cosa.c2
-rw-r--r--drivers/net/wireless/airo.c16
-rw-r--r--drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c12
-rw-r--r--drivers/net/wireless/strip.c2
-rw-r--r--drivers/oprofile/event_buffer.c2
-rw-r--r--drivers/oprofile/event_buffer.h2
-rw-r--r--drivers/oprofile/oprofile_files.c10
-rw-r--r--drivers/oprofile/oprofilefs.c6
-rw-r--r--drivers/parisc/ccio-dma.c4
-rw-r--r--drivers/parisc/eisa_eeprom.c2
-rw-r--r--drivers/parisc/led.c2
-rw-r--r--drivers/parisc/sba_iommu.c4
-rw-r--r--drivers/pci/Kconfig2
-rw-r--r--drivers/pci/hotplug/cpqphp_sysfs.c2
-rw-r--r--drivers/pci/pci.c127
-rw-r--r--drivers/pci/proc.c4
-rw-r--r--drivers/pci/quirks.c2
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c2
-rw-r--r--drivers/pnp/base.h1
-rw-r--r--drivers/pnp/isapnp/proc.c2
-rw-r--r--drivers/pnp/pnpbios/rsparser.c1
-rw-r--r--drivers/ps3/Makefile1
-rw-r--r--drivers/ps3/ps3av.c974
-rw-r--r--drivers/ps3/ps3av_cmd.c1020
-rw-r--r--drivers/ps3/vuart.c17
-rw-r--r--drivers/ps3/vuart.h1
-rw-r--r--drivers/rapidio/rio-scan.c118
-rw-r--r--drivers/rtc/Kconfig25
-rw-r--r--drivers/rtc/Makefile1
-rw-r--r--drivers/rtc/rtc-cmos.c725
-rw-r--r--drivers/rtc/rtc-dev.c2
-rw-r--r--drivers/rtc/rtc-ds1553.c2
-rw-r--r--drivers/rtc/rtc-ds1742.c2
-rw-r--r--drivers/rtc/rtc-proc.c2
-rw-r--r--drivers/rtc/rtc-sysfs.c103
-rw-r--r--drivers/s390/block/dasd_eer.c2
-rw-r--r--drivers/s390/block/dasd_proc.c2
-rw-r--r--drivers/s390/char/fs3270.c2
-rw-r--r--drivers/s390/char/monreader.c2
-rw-r--r--drivers/s390/char/monwriter.c2
-rw-r--r--drivers/s390/char/tape_char.c2
-rw-r--r--drivers/s390/char/tape_class.c2
-rw-r--r--drivers/s390/char/tape_class.h2
-rw-r--r--drivers/s390/char/tape_proc.c2
-rw-r--r--drivers/s390/char/vmcp.c2
-rw-r--r--drivers/s390/char/vmlogrdr.c2
-rw-r--r--drivers/s390/char/vmwatchdog.c2
-rw-r--r--drivers/s390/cio/blacklist.c2
-rw-r--r--drivers/s390/cio/device_id.c3
-rw-r--r--drivers/s390/cio/device_ops.c32
-rw-r--r--drivers/s390/cio/qdio.c2
-rw-r--r--drivers/s390/crypto/zcrypt_api.c3
-rw-r--r--drivers/s390/net/lcs.c6
-rw-r--r--drivers/s390/net/qeth_proc.c4
-rw-r--r--drivers/s390/scsi/zfcp_aux.c2
-rw-r--r--drivers/s390/scsi/zfcp_erp.c22
-rw-r--r--drivers/s390/scsi/zfcp_ext.h2
-rw-r--r--drivers/s390/scsi/zfcp_fsf.c23
-rw-r--r--drivers/sbus/char/bpp.c2
-rw-r--r--drivers/sbus/char/cpwatchdog.c2
-rw-r--r--drivers/sbus/char/display7seg.c2
-rw-r--r--drivers/sbus/char/envctrl.c2
-rw-r--r--drivers/sbus/char/flash.c2
-rw-r--r--drivers/sbus/char/jsflash.c2
-rw-r--r--drivers/sbus/char/openprom.c2
-rw-r--r--drivers/sbus/char/riowatchdog.c2
-rw-r--r--drivers/sbus/char/rtc.c2
-rw-r--r--drivers/sbus/char/uctrl.c2
-rw-r--r--drivers/sbus/char/vfc_dev.c4
-rw-r--r--drivers/sbus/sbus.c18
-rw-r--r--drivers/scsi/3w-9xxx.c2
-rw-r--r--drivers/scsi/3w-xxxx.c2
-rw-r--r--drivers/scsi/53c700.c24
-rw-r--r--drivers/scsi/53c700.h2
-rw-r--r--drivers/scsi/53c7xx.c5
-rw-r--r--drivers/scsi/BusLogic.c46
-rw-r--r--drivers/scsi/BusLogic.h300
-rw-r--r--drivers/scsi/FlashPoint.c4
-rw-r--r--drivers/scsi/Kconfig9
-rw-r--r--drivers/scsi/Makefile1
-rw-r--r--drivers/scsi/NCR_D700.c1
-rw-r--r--drivers/scsi/aacraid/Makefile2
-rw-r--r--drivers/scsi/aacraid/aachba.c602
-rw-r--r--drivers/scsi/aacraid/aacraid.h46
-rw-r--r--drivers/scsi/aacraid/comminit.c14
-rw-r--r--drivers/scsi/aacraid/commsup.c40
-rw-r--r--drivers/scsi/aacraid/linit.c19
-rw-r--r--drivers/scsi/aacraid/nark.c87
-rw-r--r--drivers/scsi/aacraid/rkt.c64
-rw-r--r--drivers/scsi/aacraid/rx.c263
-rw-r--r--drivers/scsi/aacraid/sa.c33
-rw-r--r--drivers/scsi/advansys.c7
-rw-r--r--drivers/scsi/aic7xxx/aic79xx.h3
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_core.c5
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.c9
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm.h2
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_osm_pci.c19
-rw-r--r--drivers/scsi/aic7xxx/aic79xx_pci.c2
-rw-r--r--drivers/scsi/aic94xx/aic94xx_dev.c16
-rw-r--r--drivers/scsi/aic94xx/aic94xx_dump.c2
-rw-r--r--drivers/scsi/aic94xx/aic94xx_hwi.c3
-rw-r--r--drivers/scsi/aic94xx/aic94xx_init.c49
-rw-r--r--drivers/scsi/aic94xx/aic94xx_reg_def.h5
-rw-r--r--drivers/scsi/aic94xx/aic94xx_sas.h1
-rw-r--r--drivers/scsi/aic94xx/aic94xx_scb.c122
-rw-r--r--drivers/scsi/aic94xx/aic94xx_sds.c10
-rw-r--r--drivers/scsi/aic94xx/aic94xx_seq.c45
-rw-r--r--drivers/scsi/aic94xx/aic94xx_seq.h1
-rw-r--r--drivers/scsi/aic94xx/aic94xx_task.c9
-rw-r--r--drivers/scsi/aic94xx/aic94xx_tmf.c4
-rw-r--r--drivers/scsi/ch.c2
-rw-r--r--drivers/scsi/dpt_i2o.c2
-rw-r--r--drivers/scsi/gdth.c2
-rw-r--r--drivers/scsi/ipr.c91
-rw-r--r--drivers/scsi/ipr.h4
-rw-r--r--drivers/scsi/lasi700.c1
-rw-r--r--drivers/scsi/libsas/sas_discover.c62
-rw-r--r--drivers/scsi/libsas/sas_event.c6
-rw-r--r--drivers/scsi/libsas/sas_expander.c48
-rw-r--r--drivers/scsi/libsas/sas_init.c52
-rw-r--r--drivers/scsi/libsas/sas_internal.h9
-rw-r--r--drivers/scsi/libsas/sas_port.c14
-rw-r--r--drivers/scsi/libsas/sas_scsi_host.c290
-rw-r--r--drivers/scsi/megaraid.c2
-rw-r--r--drivers/scsi/megaraid/mbox_defs.h2
-rw-r--r--drivers/scsi/megaraid/mega_common.h122
-rw-r--r--drivers/scsi/megaraid/megaraid_ioctl.h36
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.c421
-rw-r--r--drivers/scsi/megaraid/megaraid_mbox.h46
-rw-r--r--drivers/scsi/megaraid/megaraid_mm.c67
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.c2
-rw-r--r--drivers/scsi/megaraid/megaraid_sas.h14
-rw-r--r--drivers/scsi/osst.c2
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.h66
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c68
-rw-r--r--drivers/scsi/qla2xxx/qla_def.h38
-rw-r--r--drivers/scsi/qla2xxx/qla_gbl.h6
-rw-r--r--drivers/scsi/qla2xxx/qla_init.c218
-rw-r--r--drivers/scsi/qla2xxx/qla_isr.c245
-rw-r--r--drivers/scsi/qla2xxx/qla_mbx.c18
-rw-r--r--drivers/scsi/qla2xxx/qla_os.c24
-rw-r--r--drivers/scsi/qla2xxx/qla_sup.c348
-rw-r--r--drivers/scsi/qla2xxx/qla_version.h2
-rw-r--r--drivers/scsi/scsi.c21
-rw-r--r--drivers/scsi/scsi_debug.c42
-rw-r--r--drivers/scsi/scsi_error.c256
-rw-r--r--drivers/scsi/scsi_lib.c7
-rw-r--r--drivers/scsi/scsi_priv.h6
-rw-r--r--drivers/scsi/scsi_proc.c2
-rw-r--r--drivers/scsi/scsi_scan.c2
-rw-r--r--drivers/scsi/scsi_tgt_if.c2
-rw-r--r--drivers/scsi/scsi_transport_sas.c118
-rw-r--r--drivers/scsi/scsi_transport_spi.c1
-rw-r--r--drivers/scsi/sim710.c1
-rw-r--r--drivers/scsi/sni_53c710.c159
-rw-r--r--drivers/scsi/st.c25
-rw-r--r--drivers/scsi/st.h3
-rw-r--r--drivers/serial/8250.c8
-rw-r--r--drivers/serial/8250_pci.c27
-rw-r--r--drivers/serial/Kconfig5
-rw-r--r--drivers/serial/atmel_serial.c54
-rw-r--r--drivers/serial/crisv10.c14
-rw-r--r--drivers/serial/ioc4_serial.c6
-rw-r--r--drivers/serial/serial_txx9.c23
-rw-r--r--drivers/sn/ioc3.c6
-rw-r--r--drivers/spi/Kconfig38
-rw-r--r--drivers/spi/Makefile3
-rw-r--r--drivers/spi/at25.c381
-rw-r--r--drivers/spi/omap_uwire.c572
-rw-r--r--drivers/spi/pxa2xx_spi.c4
-rw-r--r--drivers/spi/spi.c2
-rw-r--r--drivers/spi/spi_bitbang.c11
-rw-r--r--drivers/spi/spi_imx.c1769
-rw-r--r--drivers/tc/zs.c4
-rw-r--r--drivers/telephony/ixj.c41
-rw-r--r--drivers/telephony/ixj.h4
-rw-r--r--drivers/telephony/phonedev.c2
-rw-r--r--drivers/usb/gadget/file_storage.c2
-rw-r--r--drivers/usb/gadget/rndis.c1
-rw-r--r--drivers/usb/host/hc_crisv10.c3
-rw-r--r--drivers/usb/host/uhci-q.c4
-rw-r--r--drivers/usb/input/hid-ff.c1
-rw-r--r--drivers/usb/input/hid-lgff.c1
-rw-r--r--drivers/usb/misc/adutux.c2
-rw-r--r--drivers/usb/misc/appledisplay.c4
-rw-r--r--drivers/usb/misc/ftdi-elan.c2
-rw-r--r--drivers/usb/serial/digi_acceleport.c10
-rw-r--r--drivers/usb/serial/keyspan_pda.c7
-rw-r--r--drivers/usb/serial/mos7720.c14
-rw-r--r--drivers/usb/serial/mos7840.c14
-rw-r--r--drivers/video/Kconfig89
-rw-r--r--drivers/video/Makefile8
-rw-r--r--drivers/video/S3triofb.c790
-rw-r--r--drivers/video/aty/atyfb_base.c4
-rw-r--r--drivers/video/au1100fb.c6
-rw-r--r--drivers/video/console/fbcon.c4
-rw-r--r--drivers/video/console/fbcon.h2
-rw-r--r--drivers/video/controlfb.c3
-rw-r--r--drivers/video/cyber2000fb.c19
-rw-r--r--drivers/video/cyberfb.c2295
-rw-r--r--drivers/video/cyberfb.h415
-rw-r--r--drivers/video/fbsysfs.c2
-rw-r--r--drivers/video/geode/gx1fb_core.c29
-rw-r--r--drivers/video/i810/i810.h3
-rw-r--r--drivers/video/i810/i810_main.c32
-rw-r--r--drivers/video/igafb.c8
-rw-r--r--drivers/video/intelfb/intelfbdrv.c3
-rw-r--r--drivers/video/matrox/i2c-matroxfb.c4
-rw-r--r--drivers/video/matrox/matroxfb_crtc2.c3
-rw-r--r--drivers/video/mbx/mbxdebugfs.c12
-rw-r--r--drivers/video/modedb.c47
-rw-r--r--drivers/video/neofb.c22
-rw-r--r--drivers/video/nvidia/nvidia.c16
-rw-r--r--drivers/video/pm3fb.c29
-rw-r--r--drivers/video/ps3fb.c1229
-rw-r--r--drivers/video/retz3fb.c1588
-rw-r--r--drivers/video/retz3fb.h286
-rw-r--r--drivers/video/riva/fbdev.c27
-rw-r--r--drivers/video/riva/rivafb.h3
-rw-r--r--drivers/video/s3fb.c1180
-rw-r--r--drivers/video/sa1100fb.h4
-rw-r--r--drivers/video/savage/savagefb_driver.c12
-rw-r--r--drivers/video/sis/init.c140
-rw-r--r--drivers/video/sis/init.h36
-rw-r--r--drivers/video/sis/init301.c260
-rw-r--r--drivers/video/sis/init301.h14
-rw-r--r--drivers/video/sis/initextlfb.c18
-rw-r--r--drivers/video/sis/sis.h2
-rw-r--r--drivers/video/sis/sis_main.c214
-rw-r--r--drivers/video/sis/sis_main.h112
-rw-r--r--drivers/video/sis/vgatypes.h12
-rw-r--r--drivers/video/sis/vstruct.h44
-rw-r--r--drivers/video/sun3fb.c702
-rw-r--r--drivers/video/svgalib.c632
-rw-r--r--drivers/video/tgafb.c185
-rw-r--r--drivers/video/vga16fb.c23
-rw-r--r--drivers/video/virgefb.c2526
-rw-r--r--drivers/video/virgefb.h288
-rw-r--r--drivers/w1/slaves/w1_therm.c6
-rw-r--r--drivers/zorro/proc.c2
616 files changed, 28479 insertions, 22089 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig
index e7da9fa724e..050323fd79e 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -80,6 +80,8 @@ source "drivers/rtc/Kconfig"
80 80
81source "drivers/dma/Kconfig" 81source "drivers/dma/Kconfig"
82 82
83source "drivers/auxdisplay/Kconfig"
84
83source "drivers/kvm/Kconfig" 85source "drivers/kvm/Kconfig"
84 86
85endmenu 87endmenu
diff --git a/drivers/Makefile b/drivers/Makefile
index f28dcb4ec8b..3a718f51350 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_ATA) += ata/
38obj-$(CONFIG_FUSION) += message/ 38obj-$(CONFIG_FUSION) += message/
39obj-$(CONFIG_IEEE1394) += ieee1394/ 39obj-$(CONFIG_IEEE1394) += ieee1394/
40obj-y += cdrom/ 40obj-y += cdrom/
41obj-y += auxdisplay/
41obj-$(CONFIG_MTD) += mtd/ 42obj-$(CONFIG_MTD) += mtd/
42obj-$(CONFIG_SPI) += spi/ 43obj-$(CONFIG_SPI) += spi/
43obj-$(CONFIG_PCCARD) += pcmcia/ 44obj-$(CONFIG_PCCARD) += pcmcia/
diff --git a/drivers/acorn/char/i2c.c b/drivers/acorn/char/i2c.c
index 9e584a7af43..157d8b73bb6 100644
--- a/drivers/acorn/char/i2c.c
+++ b/drivers/acorn/char/i2c.c
@@ -238,7 +238,7 @@ static int rtc_ioctl(struct inode *inode, struct file *file,
238 return -EINVAL; 238 return -EINVAL;
239} 239}
240 240
241static struct file_operations rtc_fops = { 241static const struct file_operations rtc_fops = {
242 .ioctl = rtc_ioctl, 242 .ioctl = rtc_ioctl,
243}; 243};
244 244
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig
index 1c94b43d2c9..3747457fee7 100644
--- a/drivers/ata/Kconfig
+++ b/drivers/ata/Kconfig
@@ -41,12 +41,12 @@ config SATA_SVW
41 If unsure, say N. 41 If unsure, say N.
42 42
43config ATA_PIIX 43config ATA_PIIX
44 tristate "Intel PIIX/ICH SATA support" 44 tristate "Intel ESB, ICH, PIIX3, PIIX4 PATA/SATA support"
45 depends on PCI 45 depends on PCI
46 help 46 help
47 This option enables support for ICH5/6/7/8 Serial ATA 47 This option enables support for ICH5/6/7/8 Serial ATA
48 and support for PATA on the Intel PIIX3/PIIX4/ICH series 48 and support for PATA on the Intel ESB/ICH/PIIX3/PIIX4 series
49 PATA host controllers. 49 host controllers.
50 50
51 If unsure, say N. 51 If unsure, say N.
52 52
@@ -116,11 +116,14 @@ config SATA_SIL24
116 If unsure, say N. 116 If unsure, say N.
117 117
118config SATA_SIS 118config SATA_SIS
119 tristate "SiS 964/180 SATA support" 119 tristate "SiS 964/965/966/180 SATA support"
120 depends on PCI 120 depends on PCI
121 select PATA_SIS
121 help 122 help
122 This option enables support for SiS Serial ATA 964/180. 123 This option enables support for SiS Serial ATA on
123 124 SiS 964/965/966/180 and Parallel ATA on SiS 180.
125 The PATA support for SiS 180 requires additionally to
126 enable the PATA_SIS driver in the config.
124 If unsure, say N. 127 If unsure, say N.
125 128
126config SATA_ULI 129config SATA_ULI
@@ -147,6 +150,12 @@ config SATA_VITESSE
147 150
148 If unsure, say N. 151 If unsure, say N.
149 152
153config SATA_INIC162X
154 tristate "Initio 162x SATA support (HIGHLY EXPERIMENTAL)"
155 depends on PCI && EXPERIMENTAL
156 help
157 This option enables support for Initio 162x Serial ATA.
158
150config SATA_INTEL_COMBINED 159config SATA_INTEL_COMBINED
151 bool 160 bool
152 depends on IDE=y && !BLK_DEV_IDE_SATA && (SATA_AHCI || ATA_PIIX) 161 depends on IDE=y && !BLK_DEV_IDE_SATA && (SATA_AHCI || ATA_PIIX)
@@ -296,7 +305,7 @@ config PATA_ISAPNP
296 If unsure, say N. 305 If unsure, say N.
297 306
298config PATA_IT821X 307config PATA_IT821X
299 tristate "IT821x PATA support (Experimental)" 308 tristate "IT8211/2 PATA support (Experimental)"
300 depends on PCI && EXPERIMENTAL 309 depends on PCI && EXPERIMENTAL
301 help 310 help
302 This option enables support for the ITE 8211 and 8212 311 This option enables support for the ITE 8211 and 8212
@@ -305,6 +314,15 @@ config PATA_IT821X
305 314
306 If unsure, say N. 315 If unsure, say N.
307 316
317config PATA_IT8213
318 tristate "IT8213 PATA support (Experimental)"
319 depends on PCI && EXPERIMENTAL
320 help
321 This option enables support for the ITE 821 PATA
322 controllers via the new ATA layer.
323
324 If unsure, say N.
325
308config PATA_JMICRON 326config PATA_JMICRON
309 tristate "JMicron PATA support" 327 tristate "JMicron PATA support"
310 depends on PCI 328 depends on PCI
@@ -341,6 +359,15 @@ config PATA_MARVELL
341 359
342 If unsure, say N. 360 If unsure, say N.
343 361
362config PATA_MPC52xx
363 tristate "Freescale MPC52xx SoC internal IDE"
364 depends on PPC_MPC52xx
365 help
366 This option enables support for integrated IDE controller
367 of the Freescale MPC52xx SoC.
368
369 If unsure, say N.
370
344config PATA_MPIIX 371config PATA_MPIIX
345 tristate "Intel PATA MPIIX support" 372 tristate "Intel PATA MPIIX support"
346 depends on PCI 373 depends on PCI
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile
index bc3d81ae757..cd096f0c78a 100644
--- a/drivers/ata/Makefile
+++ b/drivers/ata/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_SATA_SX4) += sata_sx4.o
15obj-$(CONFIG_SATA_NV) += sata_nv.o 15obj-$(CONFIG_SATA_NV) += sata_nv.o
16obj-$(CONFIG_SATA_ULI) += sata_uli.o 16obj-$(CONFIG_SATA_ULI) += sata_uli.o
17obj-$(CONFIG_SATA_MV) += sata_mv.o 17obj-$(CONFIG_SATA_MV) += sata_mv.o
18obj-$(CONFIG_SATA_INIC162X) += sata_inic162x.o
18obj-$(CONFIG_PDC_ADMA) += pdc_adma.o 19obj-$(CONFIG_PDC_ADMA) += pdc_adma.o
19 20
20obj-$(CONFIG_PATA_ALI) += pata_ali.o 21obj-$(CONFIG_PATA_ALI) += pata_ali.o
@@ -33,11 +34,13 @@ obj-$(CONFIG_PATA_HPT3X2N) += pata_hpt3x2n.o
33obj-$(CONFIG_PATA_HPT3X3) += pata_hpt3x3.o 34obj-$(CONFIG_PATA_HPT3X3) += pata_hpt3x3.o
34obj-$(CONFIG_PATA_ISAPNP) += pata_isapnp.o 35obj-$(CONFIG_PATA_ISAPNP) += pata_isapnp.o
35obj-$(CONFIG_PATA_IT821X) += pata_it821x.o 36obj-$(CONFIG_PATA_IT821X) += pata_it821x.o
37obj-$(CONFIG_PATA_IT8213) += pata_it8213.o
36obj-$(CONFIG_PATA_JMICRON) += pata_jmicron.o 38obj-$(CONFIG_PATA_JMICRON) += pata_jmicron.o
37obj-$(CONFIG_PATA_NETCELL) += pata_netcell.o 39obj-$(CONFIG_PATA_NETCELL) += pata_netcell.o
38obj-$(CONFIG_PATA_NS87410) += pata_ns87410.o 40obj-$(CONFIG_PATA_NS87410) += pata_ns87410.o
39obj-$(CONFIG_PATA_OPTI) += pata_opti.o 41obj-$(CONFIG_PATA_OPTI) += pata_opti.o
40obj-$(CONFIG_PATA_OPTIDMA) += pata_optidma.o 42obj-$(CONFIG_PATA_OPTIDMA) += pata_optidma.o
43obj-$(CONFIG_PATA_MPC52xx) += pata_mpc52xx.o
41obj-$(CONFIG_PATA_MARVELL) += pata_marvell.o 44obj-$(CONFIG_PATA_MARVELL) += pata_marvell.o
42obj-$(CONFIG_PATA_MPIIX) += pata_mpiix.o 45obj-$(CONFIG_PATA_MPIIX) += pata_mpiix.o
43obj-$(CONFIG_PATA_OLDPIIX) += pata_oldpiix.o 46obj-$(CONFIG_PATA_OLDPIIX) += pata_oldpiix.o
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index e2796fb40eb..92cdb0c5171 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -45,7 +45,6 @@
45#include <scsi/scsi_host.h> 45#include <scsi/scsi_host.h>
46#include <scsi/scsi_cmnd.h> 46#include <scsi/scsi_cmnd.h>
47#include <linux/libata.h> 47#include <linux/libata.h>
48#include <asm/io.h>
49 48
50#define DRV_NAME "ahci" 49#define DRV_NAME "ahci"
51#define DRV_VERSION "2.0" 50#define DRV_VERSION "2.0"
@@ -166,9 +165,6 @@ enum {
166 PORT_CMD_ICC_PARTIAL = (0x2 << 28), /* Put i/f in partial state */ 165 PORT_CMD_ICC_PARTIAL = (0x2 << 28), /* Put i/f in partial state */
167 PORT_CMD_ICC_SLUMBER = (0x6 << 28), /* Put i/f in slumber state */ 166 PORT_CMD_ICC_SLUMBER = (0x6 << 28), /* Put i/f in slumber state */
168 167
169 /* hpriv->flags bits */
170 AHCI_FLAG_MSI = (1 << 0),
171
172 /* ap->flags bits */ 168 /* ap->flags bits */
173 AHCI_FLAG_NO_NCQ = (1 << 24), 169 AHCI_FLAG_NO_NCQ = (1 << 24),
174 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 */
@@ -191,7 +187,6 @@ struct ahci_sg {
191}; 187};
192 188
193struct ahci_host_priv { 189struct ahci_host_priv {
194 unsigned long flags;
195 u32 cap; /* cache of HOST_CAP register */ 190 u32 cap; /* cache of HOST_CAP register */
196 u32 port_map; /* cache of HOST_PORTS_IMPL reg */ 191 u32 port_map; /* cache of HOST_PORTS_IMPL reg */
197}; 192};
@@ -229,7 +224,6 @@ static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg);
229static int ahci_port_resume(struct ata_port *ap); 224static int ahci_port_resume(struct ata_port *ap);
230static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg); 225static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
231static int ahci_pci_device_resume(struct pci_dev *pdev); 226static int ahci_pci_device_resume(struct pci_dev *pdev);
232static void ahci_remove_one (struct pci_dev *pdev);
233 227
234static struct scsi_host_template ahci_sht = { 228static struct scsi_host_template ahci_sht = {
235 .module = THIS_MODULE, 229 .module = THIS_MODULE,
@@ -266,6 +260,8 @@ static const struct ata_port_operations ahci_ops = {
266 260
267 .irq_handler = ahci_interrupt, 261 .irq_handler = ahci_interrupt,
268 .irq_clear = ahci_irq_clear, 262 .irq_clear = ahci_irq_clear,
263 .irq_on = ata_dummy_irq_on,
264 .irq_ack = ata_dummy_irq_ack,
269 265
270 .scr_read = ahci_scr_read, 266 .scr_read = ahci_scr_read,
271 .scr_write = ahci_scr_write, 267 .scr_write = ahci_scr_write,
@@ -297,6 +293,8 @@ static const struct ata_port_operations ahci_vt8251_ops = {
297 293
298 .irq_handler = ahci_interrupt, 294 .irq_handler = ahci_interrupt,
299 .irq_clear = ahci_irq_clear, 295 .irq_clear = ahci_irq_clear,
296 .irq_on = ata_dummy_irq_on,
297 .irq_ack = ata_dummy_irq_ack,
300 298
301 .scr_read = ahci_scr_read, 299 .scr_read = ahci_scr_read,
302 .scr_write = ahci_scr_write, 300 .scr_write = ahci_scr_write,
@@ -431,7 +429,7 @@ static const struct pci_device_id ahci_pci_tbl[] = {
431 429
432 /* Generic, PCI class code for AHCI */ 430 /* Generic, PCI class code for AHCI */
433 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, 431 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
434 0x010601, 0xffffff, board_ahci }, 432 PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
435 433
436 { } /* terminate list */ 434 { } /* terminate list */
437}; 435};
@@ -441,9 +439,9 @@ static struct pci_driver ahci_pci_driver = {
441 .name = DRV_NAME, 439 .name = DRV_NAME,
442 .id_table = ahci_pci_tbl, 440 .id_table = ahci_pci_tbl,
443 .probe = ahci_init_one, 441 .probe = ahci_init_one,
442 .remove = ata_pci_remove_one,
444 .suspend = ahci_pci_device_suspend, 443 .suspend = ahci_pci_device_suspend,
445 .resume = ahci_pci_device_resume, 444 .resume = ahci_pci_device_resume,
446 .remove = ahci_remove_one,
447}; 445};
448 446
449 447
@@ -452,16 +450,12 @@ static inline int ahci_nr_ports(u32 cap)
452 return (cap & 0x1f) + 1; 450 return (cap & 0x1f) + 1;
453} 451}
454 452
455static inline unsigned long ahci_port_base_ul (unsigned long base, unsigned int port) 453static inline void __iomem *ahci_port_base(void __iomem *base,
454 unsigned int port)
456{ 455{
457 return base + 0x100 + (port * 0x80); 456 return base + 0x100 + (port * 0x80);
458} 457}
459 458
460static inline void __iomem *ahci_port_base (void __iomem *base, unsigned int port)
461{
462 return (void __iomem *) ahci_port_base_ul((unsigned long)base, port);
463}
464
465static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in) 459static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in)
466{ 460{
467 unsigned int sc_reg; 461 unsigned int sc_reg;
@@ -475,7 +469,7 @@ static u32 ahci_scr_read (struct ata_port *ap, unsigned int sc_reg_in)
475 return 0xffffffffU; 469 return 0xffffffffU;
476 } 470 }
477 471
478 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 472 return readl(ap->ioaddr.scr_addr + (sc_reg * 4));
479} 473}
480 474
481 475
@@ -493,7 +487,7 @@ static void ahci_scr_write (struct ata_port *ap, unsigned int sc_reg_in,
493 return; 487 return;
494 } 488 }
495 489
496 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 490 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
497} 491}
498 492
499static void ahci_start_engine(void __iomem *port_mmio) 493static void ahci_start_engine(void __iomem *port_mmio)
@@ -735,7 +729,7 @@ static void ahci_init_controller(void __iomem *mmio, struct pci_dev *pdev,
735 729
736static unsigned int ahci_dev_classify(struct ata_port *ap) 730static unsigned int ahci_dev_classify(struct ata_port *ap)
737{ 731{
738 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 732 void __iomem *port_mmio = ap->ioaddr.cmd_addr;
739 struct ata_taskfile tf; 733 struct ata_taskfile tf;
740 u32 tmp; 734 u32 tmp;
741 735
@@ -763,7 +757,7 @@ static void ahci_fill_cmd_slot(struct ahci_port_priv *pp, unsigned int tag,
763 757
764static int ahci_clo(struct ata_port *ap) 758static int ahci_clo(struct ata_port *ap)
765{ 759{
766 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 760 void __iomem *port_mmio = ap->ioaddr.cmd_addr;
767 struct ahci_host_priv *hpriv = ap->host->private_data; 761 struct ahci_host_priv *hpriv = ap->host->private_data;
768 u32 tmp; 762 u32 tmp;
769 763
@@ -785,7 +779,7 @@ static int ahci_clo(struct ata_port *ap)
785static int ahci_softreset(struct ata_port *ap, unsigned int *class) 779static int ahci_softreset(struct ata_port *ap, unsigned int *class)
786{ 780{
787 struct ahci_port_priv *pp = ap->private_data; 781 struct ahci_port_priv *pp = ap->private_data;
788 void __iomem *mmio = ap->host->mmio_base; 782 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
789 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 783 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
790 const u32 cmd_fis_len = 5; /* five dwords */ 784 const u32 cmd_fis_len = 5; /* five dwords */
791 const char *reason = NULL; 785 const char *reason = NULL;
@@ -893,7 +887,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
893 struct ahci_port_priv *pp = ap->private_data; 887 struct ahci_port_priv *pp = ap->private_data;
894 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG; 888 u8 *d2h_fis = pp->rx_fis + RX_FIS_D2H_REG;
895 struct ata_taskfile tf; 889 struct ata_taskfile tf;
896 void __iomem *mmio = ap->host->mmio_base; 890 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
897 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 891 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
898 int rc; 892 int rc;
899 893
@@ -921,7 +915,7 @@ static int ahci_hardreset(struct ata_port *ap, unsigned int *class)
921 915
922static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class) 916static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class)
923{ 917{
924 void __iomem *mmio = ap->host->mmio_base; 918 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
925 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 919 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
926 int rc; 920 int rc;
927 921
@@ -946,7 +940,7 @@ static int ahci_vt8251_hardreset(struct ata_port *ap, unsigned int *class)
946 940
947static void ahci_postreset(struct ata_port *ap, unsigned int *class) 941static void ahci_postreset(struct ata_port *ap, unsigned int *class)
948{ 942{
949 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 943 void __iomem *port_mmio = ap->ioaddr.cmd_addr;
950 u32 new_tmp, tmp; 944 u32 new_tmp, tmp;
951 945
952 ata_std_postreset(ap, class); 946 ata_std_postreset(ap, class);
@@ -965,7 +959,7 @@ static void ahci_postreset(struct ata_port *ap, unsigned int *class)
965 959
966static u8 ahci_check_status(struct ata_port *ap) 960static u8 ahci_check_status(struct ata_port *ap)
967{ 961{
968 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr; 962 void __iomem *mmio = ap->ioaddr.cmd_addr;
969 963
970 return readl(mmio + PORT_TFDATA) & 0xFF; 964 return readl(mmio + PORT_TFDATA) & 0xFF;
971} 965}
@@ -1111,7 +1105,7 @@ static void ahci_error_intr(struct ata_port *ap, u32 irq_stat)
1111 1105
1112static void ahci_host_intr(struct ata_port *ap) 1106static void ahci_host_intr(struct ata_port *ap)
1113{ 1107{
1114 void __iomem *mmio = ap->host->mmio_base; 1108 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1115 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1109 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1116 struct ata_eh_info *ehi = &ap->eh_info; 1110 struct ata_eh_info *ehi = &ap->eh_info;
1117 struct ahci_port_priv *pp = ap->private_data; 1111 struct ahci_port_priv *pp = ap->private_data;
@@ -1209,7 +1203,7 @@ static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
1209 VPRINTK("ENTER\n"); 1203 VPRINTK("ENTER\n");
1210 1204
1211 hpriv = host->private_data; 1205 hpriv = host->private_data;
1212 mmio = host->mmio_base; 1206 mmio = host->iomap[AHCI_PCI_BAR];
1213 1207
1214 /* sigh. 0xffffffff is a valid return from h/w */ 1208 /* sigh. 0xffffffff is a valid return from h/w */
1215 irq_stat = readl(mmio + HOST_IRQ_STAT); 1209 irq_stat = readl(mmio + HOST_IRQ_STAT);
@@ -1254,7 +1248,7 @@ static irqreturn_t ahci_interrupt(int irq, void *dev_instance)
1254static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc) 1248static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
1255{ 1249{
1256 struct ata_port *ap = qc->ap; 1250 struct ata_port *ap = qc->ap;
1257 void __iomem *port_mmio = (void __iomem *) ap->ioaddr.cmd_addr; 1251 void __iomem *port_mmio = ap->ioaddr.cmd_addr;
1258 1252
1259 if (qc->tf.protocol == ATA_PROT_NCQ) 1253 if (qc->tf.protocol == ATA_PROT_NCQ)
1260 writel(1 << qc->tag, port_mmio + PORT_SCR_ACT); 1254 writel(1 << qc->tag, port_mmio + PORT_SCR_ACT);
@@ -1266,7 +1260,7 @@ static unsigned int ahci_qc_issue(struct ata_queued_cmd *qc)
1266 1260
1267static void ahci_freeze(struct ata_port *ap) 1261static void ahci_freeze(struct ata_port *ap)
1268{ 1262{
1269 void __iomem *mmio = ap->host->mmio_base; 1263 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1270 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1264 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1271 1265
1272 /* turn IRQ off */ 1266 /* turn IRQ off */
@@ -1275,7 +1269,7 @@ static void ahci_freeze(struct ata_port *ap)
1275 1269
1276static void ahci_thaw(struct ata_port *ap) 1270static void ahci_thaw(struct ata_port *ap)
1277{ 1271{
1278 void __iomem *mmio = ap->host->mmio_base; 1272 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1279 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1273 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1280 u32 tmp; 1274 u32 tmp;
1281 1275
@@ -1290,7 +1284,7 @@ static void ahci_thaw(struct ata_port *ap)
1290 1284
1291static void ahci_error_handler(struct ata_port *ap) 1285static void ahci_error_handler(struct ata_port *ap)
1292{ 1286{
1293 void __iomem *mmio = ap->host->mmio_base; 1287 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1294 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1288 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1295 1289
1296 if (!(ap->pflags & ATA_PFLAG_FROZEN)) { 1290 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
@@ -1306,7 +1300,7 @@ static void ahci_error_handler(struct ata_port *ap)
1306 1300
1307static void ahci_vt8251_error_handler(struct ata_port *ap) 1301static void ahci_vt8251_error_handler(struct ata_port *ap)
1308{ 1302{
1309 void __iomem *mmio = ap->host->mmio_base; 1303 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1310 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1304 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1311 1305
1312 if (!(ap->pflags & ATA_PFLAG_FROZEN)) { 1306 if (!(ap->pflags & ATA_PFLAG_FROZEN)) {
@@ -1323,7 +1317,7 @@ static void ahci_vt8251_error_handler(struct ata_port *ap)
1323static void ahci_post_internal_cmd(struct ata_queued_cmd *qc) 1317static void ahci_post_internal_cmd(struct ata_queued_cmd *qc)
1324{ 1318{
1325 struct ata_port *ap = qc->ap; 1319 struct ata_port *ap = qc->ap;
1326 void __iomem *mmio = ap->host->mmio_base; 1320 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1327 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1321 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1328 1322
1329 if (qc->flags & ATA_QCFLAG_FAILED) 1323 if (qc->flags & ATA_QCFLAG_FAILED)
@@ -1340,7 +1334,7 @@ static int ahci_port_suspend(struct ata_port *ap, pm_message_t mesg)
1340{ 1334{
1341 struct ahci_host_priv *hpriv = ap->host->private_data; 1335 struct ahci_host_priv *hpriv = ap->host->private_data;
1342 struct ahci_port_priv *pp = ap->private_data; 1336 struct ahci_port_priv *pp = ap->private_data;
1343 void __iomem *mmio = ap->host->mmio_base; 1337 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1344 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1338 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1345 const char *emsg = NULL; 1339 const char *emsg = NULL;
1346 int rc; 1340 int rc;
@@ -1361,7 +1355,7 @@ static int ahci_port_resume(struct ata_port *ap)
1361{ 1355{
1362 struct ahci_port_priv *pp = ap->private_data; 1356 struct ahci_port_priv *pp = ap->private_data;
1363 struct ahci_host_priv *hpriv = ap->host->private_data; 1357 struct ahci_host_priv *hpriv = ap->host->private_data;
1364 void __iomem *mmio = ap->host->mmio_base; 1358 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1365 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1359 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1366 1360
1367 ahci_power_up(port_mmio, hpriv->cap); 1361 ahci_power_up(port_mmio, hpriv->cap);
@@ -1373,7 +1367,7 @@ static int ahci_port_resume(struct ata_port *ap)
1373static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) 1367static int ahci_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
1374{ 1368{
1375 struct ata_host *host = dev_get_drvdata(&pdev->dev); 1369 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1376 void __iomem *mmio = host->mmio_base; 1370 void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
1377 u32 ctl; 1371 u32 ctl;
1378 1372
1379 if (mesg.event == PM_EVENT_SUSPEND) { 1373 if (mesg.event == PM_EVENT_SUSPEND) {
@@ -1394,10 +1388,12 @@ static int ahci_pci_device_resume(struct pci_dev *pdev)
1394{ 1388{
1395 struct ata_host *host = dev_get_drvdata(&pdev->dev); 1389 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1396 struct ahci_host_priv *hpriv = host->private_data; 1390 struct ahci_host_priv *hpriv = host->private_data;
1397 void __iomem *mmio = host->mmio_base; 1391 void __iomem *mmio = host->iomap[AHCI_PCI_BAR];
1398 int rc; 1392 int rc;
1399 1393
1400 ata_pci_device_do_resume(pdev); 1394 rc = ata_pci_device_do_resume(pdev);
1395 if (rc)
1396 return rc;
1401 1397
1402 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) { 1398 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
1403 rc = ahci_reset_controller(mmio, pdev); 1399 rc = ahci_reset_controller(mmio, pdev);
@@ -1418,29 +1414,24 @@ static int ahci_port_start(struct ata_port *ap)
1418 struct device *dev = ap->host->dev; 1414 struct device *dev = ap->host->dev;
1419 struct ahci_host_priv *hpriv = ap->host->private_data; 1415 struct ahci_host_priv *hpriv = ap->host->private_data;
1420 struct ahci_port_priv *pp; 1416 struct ahci_port_priv *pp;
1421 void __iomem *mmio = ap->host->mmio_base; 1417 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1422 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1418 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1423 void *mem; 1419 void *mem;
1424 dma_addr_t mem_dma; 1420 dma_addr_t mem_dma;
1425 int rc; 1421 int rc;
1426 1422
1427 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 1423 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
1428 if (!pp) 1424 if (!pp)
1429 return -ENOMEM; 1425 return -ENOMEM;
1430 memset(pp, 0, sizeof(*pp));
1431 1426
1432 rc = ata_pad_alloc(ap, dev); 1427 rc = ata_pad_alloc(ap, dev);
1433 if (rc) { 1428 if (rc)
1434 kfree(pp);
1435 return rc; 1429 return rc;
1436 }
1437 1430
1438 mem = dma_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma, GFP_KERNEL); 1431 mem = dmam_alloc_coherent(dev, AHCI_PORT_PRIV_DMA_SZ, &mem_dma,
1439 if (!mem) { 1432 GFP_KERNEL);
1440 ata_pad_free(ap, dev); 1433 if (!mem)
1441 kfree(pp);
1442 return -ENOMEM; 1434 return -ENOMEM;
1443 }
1444 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ); 1435 memset(mem, 0, AHCI_PORT_PRIV_DMA_SZ);
1445 1436
1446 /* 1437 /*
@@ -1482,10 +1473,8 @@ static int ahci_port_start(struct ata_port *ap)
1482 1473
1483static void ahci_port_stop(struct ata_port *ap) 1474static void ahci_port_stop(struct ata_port *ap)
1484{ 1475{
1485 struct device *dev = ap->host->dev;
1486 struct ahci_host_priv *hpriv = ap->host->private_data; 1476 struct ahci_host_priv *hpriv = ap->host->private_data;
1487 struct ahci_port_priv *pp = ap->private_data; 1477 void __iomem *mmio = ap->host->iomap[AHCI_PCI_BAR];
1488 void __iomem *mmio = ap->host->mmio_base;
1489 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no); 1478 void __iomem *port_mmio = ahci_port_base(mmio, ap->port_no);
1490 const char *emsg = NULL; 1479 const char *emsg = NULL;
1491 int rc; 1480 int rc;
@@ -1494,19 +1483,13 @@ static void ahci_port_stop(struct ata_port *ap)
1494 rc = ahci_deinit_port(port_mmio, hpriv->cap, &emsg); 1483 rc = ahci_deinit_port(port_mmio, hpriv->cap, &emsg);
1495 if (rc) 1484 if (rc)
1496 ata_port_printk(ap, KERN_WARNING, "%s (%d)\n", emsg, rc); 1485 ata_port_printk(ap, KERN_WARNING, "%s (%d)\n", emsg, rc);
1497
1498 ap->private_data = NULL;
1499 dma_free_coherent(dev, AHCI_PORT_PRIV_DMA_SZ,
1500 pp->cmd_slot, pp->cmd_slot_dma);
1501 ata_pad_free(ap, dev);
1502 kfree(pp);
1503} 1486}
1504 1487
1505static void ahci_setup_port(struct ata_ioports *port, unsigned long base, 1488static void ahci_setup_port(struct ata_ioports *port, void __iomem *base,
1506 unsigned int port_idx) 1489 unsigned int port_idx)
1507{ 1490{
1508 VPRINTK("ENTER, base==0x%lx, port_idx %u\n", base, port_idx); 1491 VPRINTK("ENTER, base==0x%lx, port_idx %u\n", base, port_idx);
1509 base = ahci_port_base_ul(base, port_idx); 1492 base = ahci_port_base(base, port_idx);
1510 VPRINTK("base now==0x%lx\n", base); 1493 VPRINTK("base now==0x%lx\n", base);
1511 1494
1512 port->cmd_addr = base; 1495 port->cmd_addr = base;
@@ -1519,7 +1502,7 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
1519{ 1502{
1520 struct ahci_host_priv *hpriv = probe_ent->private_data; 1503 struct ahci_host_priv *hpriv = probe_ent->private_data;
1521 struct pci_dev *pdev = to_pci_dev(probe_ent->dev); 1504 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
1522 void __iomem *mmio = probe_ent->mmio_base; 1505 void __iomem *mmio = probe_ent->iomap[AHCI_PCI_BAR];
1523 unsigned int i, cap_n_ports, using_dac; 1506 unsigned int i, cap_n_ports, using_dac;
1524 int rc; 1507 int rc;
1525 1508
@@ -1586,7 +1569,7 @@ static int ahci_host_init(struct ata_probe_ent *probe_ent)
1586 } 1569 }
1587 1570
1588 for (i = 0; i < probe_ent->n_ports; i++) 1571 for (i = 0; i < probe_ent->n_ports; i++)
1589 ahci_setup_port(&probe_ent->port[i], (unsigned long) mmio, i); 1572 ahci_setup_port(&probe_ent->port[i], mmio, i);
1590 1573
1591 ahci_init_controller(mmio, pdev, probe_ent->n_ports, 1574 ahci_init_controller(mmio, pdev, probe_ent->n_ports,
1592 probe_ent->port_flags, hpriv); 1575 probe_ent->port_flags, hpriv);
@@ -1600,7 +1583,7 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
1600{ 1583{
1601 struct ahci_host_priv *hpriv = probe_ent->private_data; 1584 struct ahci_host_priv *hpriv = probe_ent->private_data;
1602 struct pci_dev *pdev = to_pci_dev(probe_ent->dev); 1585 struct pci_dev *pdev = to_pci_dev(probe_ent->dev);
1603 void __iomem *mmio = probe_ent->mmio_base; 1586 void __iomem *mmio = probe_ent->iomap[AHCI_PCI_BAR];
1604 u32 vers, cap, impl, speed; 1587 u32 vers, cap, impl, speed;
1605 const char *speed_s; 1588 const char *speed_s;
1606 u16 cc; 1589 u16 cc;
@@ -1619,11 +1602,11 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
1619 speed_s = "?"; 1602 speed_s = "?";
1620 1603
1621 pci_read_config_word(pdev, 0x0a, &cc); 1604 pci_read_config_word(pdev, 0x0a, &cc);
1622 if (cc == 0x0101) 1605 if (cc == PCI_CLASS_STORAGE_IDE)
1623 scc_s = "IDE"; 1606 scc_s = "IDE";
1624 else if (cc == 0x0106) 1607 else if (cc == PCI_CLASS_STORAGE_SATA)
1625 scc_s = "SATA"; 1608 scc_s = "SATA";
1626 else if (cc == 0x0104) 1609 else if (cc == PCI_CLASS_STORAGE_RAID)
1627 scc_s = "RAID"; 1610 scc_s = "RAID";
1628 else 1611 else
1629 scc_s = "unknown"; 1612 scc_s = "unknown";
@@ -1667,15 +1650,13 @@ static void ahci_print_info(struct ata_probe_ent *probe_ent)
1667 ); 1650 );
1668} 1651}
1669 1652
1670static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 1653static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1671{ 1654{
1672 static int printed_version; 1655 static int printed_version;
1673 struct ata_probe_ent *probe_ent = NULL;
1674 struct ahci_host_priv *hpriv;
1675 unsigned long base;
1676 void __iomem *mmio_base;
1677 unsigned int board_idx = (unsigned int) ent->driver_data; 1656 unsigned int board_idx = (unsigned int) ent->driver_data;
1678 int have_msi, pci_dev_busy = 0; 1657 struct device *dev = &pdev->dev;
1658 struct ata_probe_ent *probe_ent;
1659 struct ahci_host_priv *hpriv;
1679 int rc; 1660 int rc;
1680 1661
1681 VPRINTK("ENTER\n"); 1662 VPRINTK("ENTER\n");
@@ -1685,57 +1666,36 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1685 if (!printed_version++) 1666 if (!printed_version++)
1686 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1667 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1687 1668
1688 /* JMicron-specific fixup: make sure we're in AHCI mode */
1689 /* This is protected from races with ata_jmicron by the pci probe
1690 locking */
1691 if (pdev->vendor == PCI_VENDOR_ID_JMICRON) { 1669 if (pdev->vendor == PCI_VENDOR_ID_JMICRON) {
1692 /* AHCI enable, AHCI on function 0 */ 1670 /* Function 1 is the PATA controller except on the 368, where
1693 pci_write_config_byte(pdev, 0x41, 0xa1); 1671 we are not AHCI anyway */
1694 /* Function 1 is the PATA controller */
1695 if (PCI_FUNC(pdev->devfn)) 1672 if (PCI_FUNC(pdev->devfn))
1696 return -ENODEV; 1673 return -ENODEV;
1697 } 1674 }
1698 1675
1699 rc = pci_enable_device(pdev); 1676 rc = pcim_enable_device(pdev);
1700 if (rc) 1677 if (rc)
1701 return rc; 1678 return rc;
1702 1679
1703 rc = pci_request_regions(pdev, DRV_NAME); 1680 rc = pcim_iomap_regions(pdev, 1 << AHCI_PCI_BAR, DRV_NAME);
1704 if (rc) { 1681 if (rc == -EBUSY)
1705 pci_dev_busy = 1; 1682 pcim_pin_device(pdev);
1706 goto err_out; 1683 if (rc)
1707 } 1684 return rc;
1708 1685
1709 if (pci_enable_msi(pdev) == 0) 1686 if (pci_enable_msi(pdev))
1710 have_msi = 1;
1711 else {
1712 pci_intx(pdev, 1); 1687 pci_intx(pdev, 1);
1713 have_msi = 0;
1714 }
1715 1688
1716 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 1689 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
1717 if (probe_ent == NULL) { 1690 if (probe_ent == NULL)
1718 rc = -ENOMEM; 1691 return -ENOMEM;
1719 goto err_out_msi;
1720 }
1721 1692
1722 memset(probe_ent, 0, sizeof(*probe_ent));
1723 probe_ent->dev = pci_dev_to_dev(pdev); 1693 probe_ent->dev = pci_dev_to_dev(pdev);
1724 INIT_LIST_HEAD(&probe_ent->node); 1694 INIT_LIST_HEAD(&probe_ent->node);
1725 1695
1726 mmio_base = pci_iomap(pdev, AHCI_PCI_BAR, 0); 1696 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
1727 if (mmio_base == NULL) { 1697 if (!hpriv)
1728 rc = -ENOMEM; 1698 return -ENOMEM;
1729 goto err_out_free_ent;
1730 }
1731 base = (unsigned long) mmio_base;
1732
1733 hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL);
1734 if (!hpriv) {
1735 rc = -ENOMEM;
1736 goto err_out_iounmap;
1737 }
1738 memset(hpriv, 0, sizeof(*hpriv));
1739 1699
1740 probe_ent->sht = ahci_port_info[board_idx].sht; 1700 probe_ent->sht = ahci_port_info[board_idx].sht;
1741 probe_ent->port_flags = ahci_port_info[board_idx].flags; 1701 probe_ent->port_flags = ahci_port_info[board_idx].flags;
@@ -1745,16 +1705,13 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1745 1705
1746 probe_ent->irq = pdev->irq; 1706 probe_ent->irq = pdev->irq;
1747 probe_ent->irq_flags = IRQF_SHARED; 1707 probe_ent->irq_flags = IRQF_SHARED;
1748 probe_ent->mmio_base = mmio_base; 1708 probe_ent->iomap = pcim_iomap_table(pdev);
1749 probe_ent->private_data = hpriv; 1709 probe_ent->private_data = hpriv;
1750 1710
1751 if (have_msi)
1752 hpriv->flags |= AHCI_FLAG_MSI;
1753
1754 /* initialize adapter */ 1711 /* initialize adapter */
1755 rc = ahci_host_init(probe_ent); 1712 rc = ahci_host_init(probe_ent);
1756 if (rc) 1713 if (rc)
1757 goto err_out_hpriv; 1714 return rc;
1758 1715
1759 if (!(probe_ent->port_flags & AHCI_FLAG_NO_NCQ) && 1716 if (!(probe_ent->port_flags & AHCI_FLAG_NO_NCQ) &&
1760 (hpriv->cap & HOST_CAP_NCQ)) 1717 (hpriv->cap & HOST_CAP_NCQ))
@@ -1762,62 +1719,11 @@ static int ahci_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1762 1719
1763 ahci_print_info(probe_ent); 1720 ahci_print_info(probe_ent);
1764 1721
1765 /* FIXME: check ata_device_add return value */ 1722 if (!ata_device_add(probe_ent))
1766 ata_device_add(probe_ent); 1723 return -ENODEV;
1767 kfree(probe_ent);
1768 1724
1725 devm_kfree(dev, probe_ent);
1769 return 0; 1726 return 0;
1770
1771err_out_hpriv:
1772 kfree(hpriv);
1773err_out_iounmap:
1774 pci_iounmap(pdev, mmio_base);
1775err_out_free_ent:
1776 kfree(probe_ent);
1777err_out_msi:
1778 if (have_msi)
1779 pci_disable_msi(pdev);
1780 else
1781 pci_intx(pdev, 0);
1782 pci_release_regions(pdev);
1783err_out:
1784 if (!pci_dev_busy)
1785 pci_disable_device(pdev);
1786 return rc;
1787}
1788
1789static void ahci_remove_one (struct pci_dev *pdev)
1790{
1791 struct device *dev = pci_dev_to_dev(pdev);
1792 struct ata_host *host = dev_get_drvdata(dev);
1793 struct ahci_host_priv *hpriv = host->private_data;
1794 unsigned int i;
1795 int have_msi;
1796
1797 for (i = 0; i < host->n_ports; i++)
1798 ata_port_detach(host->ports[i]);
1799
1800 have_msi = hpriv->flags & AHCI_FLAG_MSI;
1801 free_irq(host->irq, host);
1802
1803 for (i = 0; i < host->n_ports; i++) {
1804 struct ata_port *ap = host->ports[i];
1805
1806 ata_scsi_release(ap->scsi_host);
1807 scsi_host_put(ap->scsi_host);
1808 }
1809
1810 kfree(hpriv);
1811 pci_iounmap(pdev, host->mmio_base);
1812 kfree(host);
1813
1814 if (have_msi)
1815 pci_disable_msi(pdev);
1816 else
1817 pci_intx(pdev, 0);
1818 pci_release_regions(pdev);
1819 pci_disable_device(pdev);
1820 dev_set_drvdata(dev, NULL);
1821} 1727}
1822 1728
1823static int __init ahci_init(void) 1729static int __init ahci_init(void)
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index 24af56081b5..be66ea08da5 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -79,7 +79,7 @@ static int generic_set_mode(struct ata_port *ap, struct ata_device **unused)
79 79
80 /* Bits 5 and 6 indicate if DMA is active on master/slave */ 80 /* Bits 5 and 6 indicate if DMA is active on master/slave */
81 if (ap->ioaddr.bmdma_addr) 81 if (ap->ioaddr.bmdma_addr)
82 dma_enabled = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 82 dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
83 83
84 for (i = 0; i < ATA_MAX_DEVICES; i++) { 84 for (i = 0; i < ATA_MAX_DEVICES; i++) {
85 struct ata_device *dev = &ap->device[i]; 85 struct ata_device *dev = &ap->device[i];
@@ -138,7 +138,7 @@ static struct ata_port_operations generic_port_ops = {
138 .bmdma_stop = ata_bmdma_stop, 138 .bmdma_stop = ata_bmdma_stop,
139 .bmdma_status = ata_bmdma_status, 139 .bmdma_status = ata_bmdma_status,
140 140
141 .data_xfer = ata_pio_data_xfer, 141 .data_xfer = ata_data_xfer,
142 142
143 .freeze = ata_bmdma_freeze, 143 .freeze = ata_bmdma_freeze,
144 .thaw = ata_bmdma_thaw, 144 .thaw = ata_bmdma_thaw,
@@ -150,10 +150,10 @@ static struct ata_port_operations generic_port_ops = {
150 150
151 .irq_handler = ata_interrupt, 151 .irq_handler = ata_interrupt,
152 .irq_clear = ata_bmdma_irq_clear, 152 .irq_clear = ata_bmdma_irq_clear,
153 .irq_on = ata_irq_on,
154 .irq_ack = ata_irq_ack,
153 155
154 .port_start = ata_port_start, 156 .port_start = ata_port_start,
155 .port_stop = ata_port_stop,
156 .host_stop = ata_host_stop
157}; 157};
158 158
159static int all_generic_ide; /* Set to claim all devices */ 159static int all_generic_ide; /* Set to claim all devices */
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index 47701b286f8..4d716c7347e 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -118,7 +118,7 @@ enum {
118 PIIX_80C_SEC = (1 << 7) | (1 << 6), 118 PIIX_80C_SEC = (1 << 7) | (1 << 6),
119 119
120 /* controller IDs */ 120 /* controller IDs */
121 piix_pata_33 = 0, /* PIIX3 or 4 at 33Mhz */ 121 piix_pata_33 = 0, /* PIIX4 at 33Mhz */
122 ich_pata_33 = 1, /* ICH up to UDMA 33 only */ 122 ich_pata_33 = 1, /* ICH up to UDMA 33 only */
123 ich_pata_66 = 2, /* ICH up to 66 Mhz */ 123 ich_pata_66 = 2, /* ICH up to 66 Mhz */
124 ich_pata_100 = 3, /* ICH up to UDMA 100 */ 124 ich_pata_100 = 3, /* ICH up to UDMA 100 */
@@ -128,6 +128,7 @@ enum {
128 ich6_sata_ahci = 7, 128 ich6_sata_ahci = 7,
129 ich6m_sata_ahci = 8, 129 ich6m_sata_ahci = 8,
130 ich8_sata_ahci = 9, 130 ich8_sata_ahci = 9,
131 piix_pata_mwdma = 10, /* PIIX3 MWDMA only */
131 132
132 /* constants for mapping table */ 133 /* constants for mapping table */
133 P0 = 0, /* port 0 */ 134 P0 = 0, /* port 0 */
@@ -153,7 +154,6 @@ struct piix_host_priv {
153 154
154static int piix_init_one (struct pci_dev *pdev, 155static int piix_init_one (struct pci_dev *pdev,
155 const struct pci_device_id *ent); 156 const struct pci_device_id *ent);
156static void piix_host_stop(struct ata_host *host);
157static void piix_pata_error_handler(struct ata_port *ap); 157static void piix_pata_error_handler(struct ata_port *ap);
158static void ich_pata_error_handler(struct ata_port *ap); 158static void ich_pata_error_handler(struct ata_port *ap);
159static void piix_sata_error_handler(struct ata_port *ap); 159static void piix_sata_error_handler(struct ata_port *ap);
@@ -164,7 +164,8 @@ static void ich_set_dmamode (struct ata_port *ap, struct ata_device *adev);
164static unsigned int in_module_init = 1; 164static unsigned int in_module_init = 1;
165 165
166static const struct pci_device_id piix_pci_tbl[] = { 166static const struct pci_device_id piix_pci_tbl[] = {
167#ifdef ATA_ENABLE_PATA 167 /* Intel PIIX3 for the 430HX etc */
168 { 0x8086, 0x7010, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_mwdma },
168 /* Intel PIIX4 for the 430TX/440BX/MX chipset: UDMA 33 */ 169 /* Intel PIIX4 for the 430TX/440BX/MX chipset: UDMA 33 */
169 /* Also PIIX4E (fn3 rev 2) and PIIX4M (fn3 rev 3) */ 170 /* Also PIIX4E (fn3 rev 2) and PIIX4M (fn3 rev 3) */
170 { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 }, 171 { 0x8086, 0x7111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, piix_pata_33 },
@@ -202,7 +203,6 @@ static const struct pci_device_id piix_pci_tbl[] = {
202 /* ICH7/7-R (i945, i975) UDMA 100*/ 203 /* ICH7/7-R (i945, i975) UDMA 100*/
203 { 0x8086, 0x27DF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_133 }, 204 { 0x8086, 0x27DF, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_133 },
204 { 0x8086, 0x269E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 }, 205 { 0x8086, 0x269E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich_pata_100 },
205#endif
206 206
207 /* NOTE: The following PCI ids must be kept in sync with the 207 /* NOTE: The following PCI ids must be kept in sync with the
208 * list in drivers/pci/quirks.c. 208 * list in drivers/pci/quirks.c.
@@ -297,7 +297,7 @@ static const struct ata_port_operations piix_pata_ops = {
297 .bmdma_status = ata_bmdma_status, 297 .bmdma_status = ata_bmdma_status,
298 .qc_prep = ata_qc_prep, 298 .qc_prep = ata_qc_prep,
299 .qc_issue = ata_qc_issue_prot, 299 .qc_issue = ata_qc_issue_prot,
300 .data_xfer = ata_pio_data_xfer, 300 .data_xfer = ata_data_xfer,
301 301
302 .freeze = ata_bmdma_freeze, 302 .freeze = ata_bmdma_freeze,
303 .thaw = ata_bmdma_thaw, 303 .thaw = ata_bmdma_thaw,
@@ -306,10 +306,10 @@ static const struct ata_port_operations piix_pata_ops = {
306 306
307 .irq_handler = ata_interrupt, 307 .irq_handler = ata_interrupt,
308 .irq_clear = ata_bmdma_irq_clear, 308 .irq_clear = ata_bmdma_irq_clear,
309 .irq_on = ata_irq_on,
310 .irq_ack = ata_irq_ack,
309 311
310 .port_start = ata_port_start, 312 .port_start = ata_port_start,
311 .port_stop = ata_port_stop,
312 .host_stop = piix_host_stop,
313}; 313};
314 314
315static const struct ata_port_operations ich_pata_ops = { 315static const struct ata_port_operations ich_pata_ops = {
@@ -330,7 +330,7 @@ static const struct ata_port_operations ich_pata_ops = {
330 .bmdma_status = ata_bmdma_status, 330 .bmdma_status = ata_bmdma_status,
331 .qc_prep = ata_qc_prep, 331 .qc_prep = ata_qc_prep,
332 .qc_issue = ata_qc_issue_prot, 332 .qc_issue = ata_qc_issue_prot,
333 .data_xfer = ata_pio_data_xfer, 333 .data_xfer = ata_data_xfer,
334 334
335 .freeze = ata_bmdma_freeze, 335 .freeze = ata_bmdma_freeze,
336 .thaw = ata_bmdma_thaw, 336 .thaw = ata_bmdma_thaw,
@@ -339,10 +339,10 @@ static const struct ata_port_operations ich_pata_ops = {
339 339
340 .irq_handler = ata_interrupt, 340 .irq_handler = ata_interrupt,
341 .irq_clear = ata_bmdma_irq_clear, 341 .irq_clear = ata_bmdma_irq_clear,
342 .irq_on = ata_irq_on,
343 .irq_ack = ata_irq_ack,
342 344
343 .port_start = ata_port_start, 345 .port_start = ata_port_start,
344 .port_stop = ata_port_stop,
345 .host_stop = piix_host_stop,
346}; 346};
347 347
348static const struct ata_port_operations piix_sata_ops = { 348static const struct ata_port_operations piix_sata_ops = {
@@ -360,7 +360,7 @@ static const struct ata_port_operations piix_sata_ops = {
360 .bmdma_status = ata_bmdma_status, 360 .bmdma_status = ata_bmdma_status,
361 .qc_prep = ata_qc_prep, 361 .qc_prep = ata_qc_prep,
362 .qc_issue = ata_qc_issue_prot, 362 .qc_issue = ata_qc_issue_prot,
363 .data_xfer = ata_pio_data_xfer, 363 .data_xfer = ata_data_xfer,
364 364
365 .freeze = ata_bmdma_freeze, 365 .freeze = ata_bmdma_freeze,
366 .thaw = ata_bmdma_thaw, 366 .thaw = ata_bmdma_thaw,
@@ -369,10 +369,10 @@ static const struct ata_port_operations piix_sata_ops = {
369 369
370 .irq_handler = ata_interrupt, 370 .irq_handler = ata_interrupt,
371 .irq_clear = ata_bmdma_irq_clear, 371 .irq_clear = ata_bmdma_irq_clear,
372 .irq_on = ata_irq_on,
373 .irq_ack = ata_irq_ack,
372 374
373 .port_start = ata_port_start, 375 .port_start = ata_port_start,
374 .port_stop = ata_port_stop,
375 .host_stop = piix_host_stop,
376}; 376};
377 377
378static const struct piix_map_db ich5_map_db = { 378static const struct piix_map_db ich5_map_db = {
@@ -441,7 +441,7 @@ static const struct piix_map_db *piix_map_db_table[] = {
441}; 441};
442 442
443static struct ata_port_info piix_port_info[] = { 443static struct ata_port_info piix_port_info[] = {
444 /* piix_pata_33: 0: PIIX3 or 4 at 33MHz */ 444 /* piix_pata_33: 0: PIIX4 at 33MHz */
445 { 445 {
446 .sht = &piix_sht, 446 .sht = &piix_sht,
447 .flags = PIIX_PATA_FLAGS, 447 .flags = PIIX_PATA_FLAGS,
@@ -543,6 +543,14 @@ static struct ata_port_info piix_port_info[] = {
543 .port_ops = &piix_sata_ops, 543 .port_ops = &piix_sata_ops,
544 }, 544 },
545 545
546 /* piix_pata_mwdma: 10: PIIX3 MWDMA only */
547 {
548 .sht = &piix_sht,
549 .flags = PIIX_PATA_FLAGS,
550 .pio_mask = 0x1f, /* pio0-4 */
551 .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
552 .port_ops = &piix_pata_ops,
553 },
546}; 554};
547 555
548static struct pci_bits piix_enable_bits[] = { 556static struct pci_bits piix_enable_bits[] = {
@@ -569,6 +577,7 @@ struct ich_laptop {
569static const struct ich_laptop ich_laptop[] = { 577static const struct ich_laptop ich_laptop[] = {
570 /* devid, subvendor, subdev */ 578 /* devid, subvendor, subdev */
571 { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */ 579 { 0x27DF, 0x0005, 0x0280 }, /* ICH7 on Acer 5602WLMi */
580 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
572 /* end marker */ 581 /* end marker */
573 { 0, } 582 { 0, }
574}; 583};
@@ -632,7 +641,7 @@ static int piix_pata_prereset(struct ata_port *ap)
632 641
633 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no])) 642 if (!pci_test_config_bits(pdev, &piix_enable_bits[ap->port_no]))
634 return -ENOENT; 643 return -ENOENT;
635 644
636 ap->cbl = ATA_CBL_PATA40; 645 ap->cbl = ATA_CBL_PATA40;
637 return ata_std_prereset(ap); 646 return ata_std_prereset(ap);
638} 647}
@@ -776,7 +785,7 @@ static void do_pata_set_dmamode (struct ata_port *ap, struct ata_device *adev, i
776 u16 master_data; 785 u16 master_data;
777 u8 speed = adev->dma_mode; 786 u8 speed = adev->dma_mode;
778 int devid = adev->devno + 2 * ap->port_no; 787 int devid = adev->devno + 2 * ap->port_no;
779 u8 udma_enable; 788 u8 udma_enable = 0;
780 789
781 static const /* ISP RTC */ 790 static const /* ISP RTC */
782 u8 timings[][2] = { { 0, 0 }, 791 u8 timings[][2] = { { 0, 0 },
@@ -786,7 +795,8 @@ static void do_pata_set_dmamode (struct ata_port *ap, struct ata_device *adev, i
786 { 2, 3 }, }; 795 { 2, 3 }, };
787 796
788 pci_read_config_word(dev, master_port, &master_data); 797 pci_read_config_word(dev, master_port, &master_data);
789 pci_read_config_byte(dev, 0x48, &udma_enable); 798 if (ap->udma_mask)
799 pci_read_config_byte(dev, 0x48, &udma_enable);
790 800
791 if (speed >= XFER_UDMA_0) { 801 if (speed >= XFER_UDMA_0) {
792 unsigned int udma = adev->dma_mode - XFER_UDMA_0; 802 unsigned int udma = adev->dma_mode - XFER_UDMA_0;
@@ -1059,6 +1069,7 @@ static void __devinit piix_init_sata_map(struct pci_dev *pdev,
1059static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 1069static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1060{ 1070{
1061 static int printed_version; 1071 static int printed_version;
1072 struct device *dev = &pdev->dev;
1062 struct ata_port_info port_info[2]; 1073 struct ata_port_info port_info[2];
1063 struct ata_port_info *ppinfo[2] = { &port_info[0], &port_info[1] }; 1074 struct ata_port_info *ppinfo[2] = { &port_info[0], &port_info[1] };
1064 struct piix_host_priv *hpriv; 1075 struct piix_host_priv *hpriv;
@@ -1072,7 +1083,7 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1072 if (!in_module_init) 1083 if (!in_module_init)
1073 return -ENODEV; 1084 return -ENODEV;
1074 1085
1075 hpriv = kzalloc(sizeof(*hpriv), GFP_KERNEL); 1086 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
1076 if (!hpriv) 1087 if (!hpriv)
1077 return -ENOMEM; 1088 return -ENOMEM;
1078 1089
@@ -1122,15 +1133,6 @@ static int piix_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1122 return ata_pci_init_one(pdev, ppinfo, 2); 1133 return ata_pci_init_one(pdev, ppinfo, 2);
1123} 1134}
1124 1135
1125static void piix_host_stop(struct ata_host *host)
1126{
1127 struct piix_host_priv *hpriv = host->private_data;
1128
1129 ata_host_stop(host);
1130
1131 kfree(hpriv);
1132}
1133
1134static int __init piix_init(void) 1136static int __init piix_init(void)
1135{ 1137{
1136 int rc; 1138 int rc;
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 667acd28336..25d8d3f778a 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -59,6 +59,9 @@
59 59
60#include "libata.h" 60#include "libata.h"
61 61
62#define DRV_VERSION "2.10" /* must be exactly four chars */
63
64
62/* debounce timing parameters in msecs { interval, duration, timeout } */ 65/* debounce timing parameters in msecs { interval, duration, timeout } */
63const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 }; 66const unsigned long sata_deb_timing_normal[] = { 5, 100, 2000 };
64const unsigned long sata_deb_timing_hotplug[] = { 25, 500, 2000 }; 67const unsigned long sata_deb_timing_hotplug[] = { 25, 500, 2000 };
@@ -598,51 +601,7 @@ void ata_dev_disable(struct ata_device *dev)
598} 601}
599 602
600/** 603/**
601 * ata_pio_devchk - PATA device presence detection 604 * ata_devchk - PATA device presence detection
602 * @ap: ATA channel to examine
603 * @device: Device to examine (starting at zero)
604 *
605 * This technique was originally described in
606 * Hale Landis's ATADRVR (www.ata-atapi.com), and
607 * later found its way into the ATA/ATAPI spec.
608 *
609 * Write a pattern to the ATA shadow registers,
610 * and if a device is present, it will respond by
611 * correctly storing and echoing back the
612 * ATA shadow register contents.
613 *
614 * LOCKING:
615 * caller.
616 */
617
618static unsigned int ata_pio_devchk(struct ata_port *ap,
619 unsigned int device)
620{
621 struct ata_ioports *ioaddr = &ap->ioaddr;
622 u8 nsect, lbal;
623
624 ap->ops->dev_select(ap, device);
625
626 outb(0x55, ioaddr->nsect_addr);
627 outb(0xaa, ioaddr->lbal_addr);
628
629 outb(0xaa, ioaddr->nsect_addr);
630 outb(0x55, ioaddr->lbal_addr);
631
632 outb(0x55, ioaddr->nsect_addr);
633 outb(0xaa, ioaddr->lbal_addr);
634
635 nsect = inb(ioaddr->nsect_addr);
636 lbal = inb(ioaddr->lbal_addr);
637
638 if ((nsect == 0x55) && (lbal == 0xaa))
639 return 1; /* we found a device */
640
641 return 0; /* nothing found */
642}
643
644/**
645 * ata_mmio_devchk - PATA device presence detection
646 * @ap: ATA channel to examine 605 * @ap: ATA channel to examine
647 * @device: Device to examine (starting at zero) 606 * @device: Device to examine (starting at zero)
648 * 607 *
@@ -659,25 +618,24 @@ static unsigned int ata_pio_devchk(struct ata_port *ap,
659 * caller. 618 * caller.
660 */ 619 */
661 620
662static unsigned int ata_mmio_devchk(struct ata_port *ap, 621static unsigned int ata_devchk(struct ata_port *ap, unsigned int device)
663 unsigned int device)
664{ 622{
665 struct ata_ioports *ioaddr = &ap->ioaddr; 623 struct ata_ioports *ioaddr = &ap->ioaddr;
666 u8 nsect, lbal; 624 u8 nsect, lbal;
667 625
668 ap->ops->dev_select(ap, device); 626 ap->ops->dev_select(ap, device);
669 627
670 writeb(0x55, (void __iomem *) ioaddr->nsect_addr); 628 iowrite8(0x55, ioaddr->nsect_addr);
671 writeb(0xaa, (void __iomem *) ioaddr->lbal_addr); 629 iowrite8(0xaa, ioaddr->lbal_addr);
672 630
673 writeb(0xaa, (void __iomem *) ioaddr->nsect_addr); 631 iowrite8(0xaa, ioaddr->nsect_addr);
674 writeb(0x55, (void __iomem *) ioaddr->lbal_addr); 632 iowrite8(0x55, ioaddr->lbal_addr);
675 633
676 writeb(0x55, (void __iomem *) ioaddr->nsect_addr); 634 iowrite8(0x55, ioaddr->nsect_addr);
677 writeb(0xaa, (void __iomem *) ioaddr->lbal_addr); 635 iowrite8(0xaa, ioaddr->lbal_addr);
678 636
679 nsect = readb((void __iomem *) ioaddr->nsect_addr); 637 nsect = ioread8(ioaddr->nsect_addr);
680 lbal = readb((void __iomem *) ioaddr->lbal_addr); 638 lbal = ioread8(ioaddr->lbal_addr);
681 639
682 if ((nsect == 0x55) && (lbal == 0xaa)) 640 if ((nsect == 0x55) && (lbal == 0xaa))
683 return 1; /* we found a device */ 641 return 1; /* we found a device */
@@ -686,27 +644,6 @@ static unsigned int ata_mmio_devchk(struct ata_port *ap,
686} 644}
687 645
688/** 646/**
689 * ata_devchk - PATA device presence detection
690 * @ap: ATA channel to examine
691 * @device: Device to examine (starting at zero)
692 *
693 * Dispatch ATA device presence detection, depending
694 * on whether we are using PIO or MMIO to talk to the
695 * ATA shadow registers.
696 *
697 * LOCKING:
698 * caller.
699 */
700
701static unsigned int ata_devchk(struct ata_port *ap,
702 unsigned int device)
703{
704 if (ap->flags & ATA_FLAG_MMIO)
705 return ata_mmio_devchk(ap, device);
706 return ata_pio_devchk(ap, device);
707}
708
709/**
710 * ata_dev_classify - determine device type based on ATA-spec signature 647 * ata_dev_classify - determine device type based on ATA-spec signature
711 * @tf: ATA taskfile register set for device to be identified 648 * @tf: ATA taskfile register set for device to be identified
712 * 649 *
@@ -923,11 +860,7 @@ void ata_std_dev_select (struct ata_port *ap, unsigned int device)
923 else 860 else
924 tmp = ATA_DEVICE_OBS | ATA_DEV1; 861 tmp = ATA_DEVICE_OBS | ATA_DEV1;
925 862
926 if (ap->flags & ATA_FLAG_MMIO) { 863 iowrite8(tmp, ap->ioaddr.device_addr);
927 writeb(tmp, (void __iomem *) ap->ioaddr.device_addr);
928 } else {
929 outb(tmp, ap->ioaddr.device_addr);
930 }
931 ata_pause(ap); /* needed; also flushes, for mmio */ 864 ata_pause(ap); /* needed; also flushes, for mmio */
932} 865}
933 866
@@ -1156,7 +1089,7 @@ void ata_port_flush_task(struct ata_port *ap)
1156 ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __FUNCTION__); 1089 ata_port_printk(ap, KERN_DEBUG, "%s: EXIT\n", __FUNCTION__);
1157} 1090}
1158 1091
1159void ata_qc_complete_internal(struct ata_queued_cmd *qc) 1092static void ata_qc_complete_internal(struct ata_queued_cmd *qc)
1160{ 1093{
1161 struct completion *waiting = qc->private_data; 1094 struct completion *waiting = qc->private_data;
1162 1095
@@ -1249,7 +1182,6 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1249 buflen += sg[i].length; 1182 buflen += sg[i].length;
1250 1183
1251 ata_sg_init(qc, sg, n_elem); 1184 ata_sg_init(qc, sg, n_elem);
1252 qc->nsect = buflen / ATA_SECT_SIZE;
1253 qc->nbytes = buflen; 1185 qc->nbytes = buflen;
1254 } 1186 }
1255 1187
@@ -1292,7 +1224,7 @@ unsigned ata_exec_internal_sg(struct ata_device *dev,
1292 if (ap->ops->post_internal_cmd) 1224 if (ap->ops->post_internal_cmd)
1293 ap->ops->post_internal_cmd(qc); 1225 ap->ops->post_internal_cmd(qc);
1294 1226
1295 if (qc->flags & ATA_QCFLAG_FAILED && !qc->err_mask) { 1227 if ((qc->flags & ATA_QCFLAG_FAILED) && !qc->err_mask) {
1296 if (ata_msg_warn(ap)) 1228 if (ata_msg_warn(ap))
1297 ata_dev_printk(dev, KERN_WARNING, 1229 ata_dev_printk(dev, KERN_WARNING,
1298 "zero err_mask for failed " 1230 "zero err_mask for failed "
@@ -1608,6 +1540,8 @@ int ata_dev_configure(struct ata_device *dev)
1608 const u16 *id = dev->id; 1540 const u16 *id = dev->id;
1609 unsigned int xfer_mask; 1541 unsigned int xfer_mask;
1610 char revbuf[7]; /* XYZ-99\0 */ 1542 char revbuf[7]; /* XYZ-99\0 */
1543 char fwrevbuf[ATA_ID_FW_REV_LEN+1];
1544 char modelbuf[ATA_ID_PROD_LEN+1];
1611 int rc; 1545 int rc;
1612 1546
1613 if (!ata_dev_enabled(dev) && ata_msg_info(ap)) { 1547 if (!ata_dev_enabled(dev) && ata_msg_info(ap)) {
@@ -1662,6 +1596,16 @@ int ata_dev_configure(struct ata_device *dev)
1662 1596
1663 dev->n_sectors = ata_id_n_sectors(id); 1597 dev->n_sectors = ata_id_n_sectors(id);
1664 1598
1599 /* SCSI only uses 4-char revisions, dump full 8 chars from ATA */
1600 ata_id_c_string(dev->id, fwrevbuf, ATA_ID_FW_REV,
1601 sizeof(fwrevbuf));
1602
1603 ata_id_c_string(dev->id, modelbuf, ATA_ID_PROD,
1604 sizeof(modelbuf));
1605
1606 if (dev->id[59] & 0x100)
1607 dev->multi_count = dev->id[59] & 0xff;
1608
1665 if (ata_id_has_lba(id)) { 1609 if (ata_id_has_lba(id)) {
1666 const char *lba_desc; 1610 const char *lba_desc;
1667 char ncq_desc[20]; 1611 char ncq_desc[20];
@@ -1681,13 +1625,16 @@ int ata_dev_configure(struct ata_device *dev)
1681 ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc)); 1625 ata_dev_config_ncq(dev, ncq_desc, sizeof(ncq_desc));
1682 1626
1683 /* print device info to dmesg */ 1627 /* print device info to dmesg */
1684 if (ata_msg_drv(ap) && print_info) 1628 if (ata_msg_drv(ap) && print_info) {
1685 ata_dev_printk(dev, KERN_INFO, "%s, " 1629 ata_dev_printk(dev, KERN_INFO,
1686 "max %s, %Lu sectors: %s %s\n", 1630 "%s: %s, %s, max %s\n",
1687 revbuf, 1631 revbuf, modelbuf, fwrevbuf,
1688 ata_mode_string(xfer_mask), 1632 ata_mode_string(xfer_mask));
1633 ata_dev_printk(dev, KERN_INFO,
1634 "%Lu sectors, multi %u: %s %s\n",
1689 (unsigned long long)dev->n_sectors, 1635 (unsigned long long)dev->n_sectors,
1690 lba_desc, ncq_desc); 1636 dev->multi_count, lba_desc, ncq_desc);
1637 }
1691 } else { 1638 } else {
1692 /* CHS */ 1639 /* CHS */
1693 1640
@@ -1704,22 +1651,17 @@ int ata_dev_configure(struct ata_device *dev)
1704 } 1651 }
1705 1652
1706 /* print device info to dmesg */ 1653 /* print device info to dmesg */
1707 if (ata_msg_drv(ap) && print_info) 1654 if (ata_msg_drv(ap) && print_info) {
1708 ata_dev_printk(dev, KERN_INFO, "%s, "
1709 "max %s, %Lu sectors: CHS %u/%u/%u\n",
1710 revbuf,
1711 ata_mode_string(xfer_mask),
1712 (unsigned long long)dev->n_sectors,
1713 dev->cylinders, dev->heads,
1714 dev->sectors);
1715 }
1716
1717 if (dev->id[59] & 0x100) {
1718 dev->multi_count = dev->id[59] & 0xff;
1719 if (ata_msg_drv(ap) && print_info)
1720 ata_dev_printk(dev, KERN_INFO, 1655 ata_dev_printk(dev, KERN_INFO,
1721 "ata%u: dev %u multi count %u\n", 1656 "%s: %s, %s, max %s\n",
1722 ap->id, dev->devno, dev->multi_count); 1657 revbuf, modelbuf, fwrevbuf,
1658 ata_mode_string(xfer_mask));
1659 ata_dev_printk(dev, KERN_INFO,
1660 "%Lu sectors, multi %u, CHS %u/%u/%u\n",
1661 (unsigned long long)dev->n_sectors,
1662 dev->multi_count, dev->cylinders,
1663 dev->heads, dev->sectors);
1664 }
1723 } 1665 }
1724 1666
1725 dev->cdb_len = 16; 1667 dev->cdb_len = 16;
@@ -2391,6 +2333,10 @@ static int ata_dev_set_mode(struct ata_device *dev)
2391 dev->flags |= ATA_DFLAG_PIO; 2333 dev->flags |= ATA_DFLAG_PIO;
2392 2334
2393 err_mask = ata_dev_set_xfermode(dev); 2335 err_mask = ata_dev_set_xfermode(dev);
2336 /* Old CFA may refuse this command, which is just fine */
2337 if (dev->xfer_shift == ATA_SHIFT_PIO && ata_id_is_cfa(dev->id))
2338 err_mask &= ~AC_ERR_DEV;
2339
2394 if (err_mask) { 2340 if (err_mask) {
2395 ata_dev_printk(dev, KERN_ERR, "failed to set xfermode " 2341 ata_dev_printk(dev, KERN_ERR, "failed to set xfermode "
2396 "(err_mask=0x%x)\n", err_mask); 2342 "(err_mask=0x%x)\n", err_mask);
@@ -2493,7 +2439,7 @@ int ata_set_mode(struct ata_port *ap, struct ata_device **r_failed_dev)
2493 for (i = 0; i < ATA_MAX_DEVICES; i++) { 2439 for (i = 0; i < ATA_MAX_DEVICES; i++) {
2494 dev = &ap->device[i]; 2440 dev = &ap->device[i];
2495 2441
2496 /* don't udpate suspended devices' xfer mode */ 2442 /* don't update suspended devices' xfer mode */
2497 if (!ata_dev_ready(dev)) 2443 if (!ata_dev_ready(dev))
2498 continue; 2444 continue;
2499 2445
@@ -2614,13 +2560,8 @@ static void ata_bus_post_reset(struct ata_port *ap, unsigned int devmask)
2614 u8 nsect, lbal; 2560 u8 nsect, lbal;
2615 2561
2616 ap->ops->dev_select(ap, 1); 2562 ap->ops->dev_select(ap, 1);
2617 if (ap->flags & ATA_FLAG_MMIO) { 2563 nsect = ioread8(ioaddr->nsect_addr);
2618 nsect = readb((void __iomem *) ioaddr->nsect_addr); 2564 lbal = ioread8(ioaddr->lbal_addr);
2619 lbal = readb((void __iomem *) ioaddr->lbal_addr);
2620 } else {
2621 nsect = inb(ioaddr->nsect_addr);
2622 lbal = inb(ioaddr->lbal_addr);
2623 }
2624 if ((nsect == 1) && (lbal == 1)) 2565 if ((nsect == 1) && (lbal == 1))
2625 break; 2566 break;
2626 if (time_after(jiffies, timeout)) { 2567 if (time_after(jiffies, timeout)) {
@@ -2648,19 +2589,11 @@ static unsigned int ata_bus_softreset(struct ata_port *ap,
2648 DPRINTK("ata%u: bus reset via SRST\n", ap->id); 2589 DPRINTK("ata%u: bus reset via SRST\n", ap->id);
2649 2590
2650 /* software reset. causes dev0 to be selected */ 2591 /* software reset. causes dev0 to be selected */
2651 if (ap->flags & ATA_FLAG_MMIO) { 2592 iowrite8(ap->ctl, ioaddr->ctl_addr);
2652 writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr); 2593 udelay(20); /* FIXME: flush */
2653 udelay(20); /* FIXME: flush */ 2594 iowrite8(ap->ctl | ATA_SRST, ioaddr->ctl_addr);
2654 writeb(ap->ctl | ATA_SRST, (void __iomem *) ioaddr->ctl_addr); 2595 udelay(20); /* FIXME: flush */
2655 udelay(20); /* FIXME: flush */ 2596 iowrite8(ap->ctl, ioaddr->ctl_addr);
2656 writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
2657 } else {
2658 outb(ap->ctl, ioaddr->ctl_addr);
2659 udelay(10);
2660 outb(ap->ctl | ATA_SRST, ioaddr->ctl_addr);
2661 udelay(10);
2662 outb(ap->ctl, ioaddr->ctl_addr);
2663 }
2664 2597
2665 /* spec mandates ">= 2ms" before checking status. 2598 /* spec mandates ">= 2ms" before checking status.
2666 * We wait 150ms, because that was the magic delay used for 2599 * We wait 150ms, because that was the magic delay used for
@@ -2745,8 +2678,7 @@ void ata_bus_reset(struct ata_port *ap)
2745 ap->device[1].class = ata_dev_try_classify(ap, 1, &err); 2678 ap->device[1].class = ata_dev_try_classify(ap, 1, &err);
2746 2679
2747 /* re-enable interrupts */ 2680 /* re-enable interrupts */
2748 if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */ 2681 ap->ops->irq_on(ap);
2749 ata_irq_on(ap);
2750 2682
2751 /* is double-select really necessary? */ 2683 /* is double-select really necessary? */
2752 if (ap->device[1].class != ATA_DEV_NONE) 2684 if (ap->device[1].class != ATA_DEV_NONE)
@@ -2761,10 +2693,7 @@ void ata_bus_reset(struct ata_port *ap)
2761 2693
2762 if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) { 2694 if (ap->flags & (ATA_FLAG_SATA_RESET | ATA_FLAG_SRST)) {
2763 /* set up device control for ATA_FLAG_SATA_RESET */ 2695 /* set up device control for ATA_FLAG_SATA_RESET */
2764 if (ap->flags & ATA_FLAG_MMIO) 2696 iowrite8(ap->ctl, ioaddr->ctl_addr);
2765 writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
2766 else
2767 outb(ap->ctl, ioaddr->ctl_addr);
2768 } 2697 }
2769 2698
2770 DPRINTK("EXIT\n"); 2699 DPRINTK("EXIT\n");
@@ -3098,6 +3027,9 @@ int sata_std_hardreset(struct ata_port *ap, unsigned int *class)
3098 return 0; 3027 return 0;
3099 } 3028 }
3100 3029
3030 /* wait a while before checking status, see SRST for more info */
3031 msleep(150);
3032
3101 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) { 3033 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
3102 ata_port_printk(ap, KERN_ERR, 3034 ata_port_printk(ap, KERN_ERR,
3103 "COMRESET failed (device not ready)\n"); 3035 "COMRESET failed (device not ready)\n");
@@ -3138,11 +3070,8 @@ void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
3138 sata_scr_write(ap, SCR_ERROR, serror); 3070 sata_scr_write(ap, SCR_ERROR, serror);
3139 3071
3140 /* re-enable interrupts */ 3072 /* re-enable interrupts */
3141 if (!ap->ops->error_handler) { 3073 if (!ap->ops->error_handler)
3142 /* FIXME: hack. create a hook instead */ 3074 ap->ops->irq_on(ap);
3143 if (ap->ioaddr.ctl_addr)
3144 ata_irq_on(ap);
3145 }
3146 3075
3147 /* is double-select really necessary? */ 3076 /* is double-select really necessary? */
3148 if (classes[0] != ATA_DEV_NONE) 3077 if (classes[0] != ATA_DEV_NONE)
@@ -3157,12 +3086,8 @@ void ata_std_postreset(struct ata_port *ap, unsigned int *classes)
3157 } 3086 }
3158 3087
3159 /* set up device control */ 3088 /* set up device control */
3160 if (ap->ioaddr.ctl_addr) { 3089 if (ap->ioaddr.ctl_addr)
3161 if (ap->flags & ATA_FLAG_MMIO) 3090 iowrite8(ap->ctl, ap->ioaddr.ctl_addr);
3162 writeb(ap->ctl, (void __iomem *) ap->ioaddr.ctl_addr);
3163 else
3164 outb(ap->ctl, ap->ioaddr.ctl_addr);
3165 }
3166 3091
3167 DPRINTK("EXIT\n"); 3092 DPRINTK("EXIT\n");
3168} 3093}
@@ -3187,7 +3112,8 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
3187 const u16 *new_id) 3112 const u16 *new_id)
3188{ 3113{
3189 const u16 *old_id = dev->id; 3114 const u16 *old_id = dev->id;
3190 unsigned char model[2][41], serial[2][21]; 3115 unsigned char model[2][ATA_ID_PROD_LEN + 1];
3116 unsigned char serial[2][ATA_ID_SERNO_LEN + 1];
3191 u64 new_n_sectors; 3117 u64 new_n_sectors;
3192 3118
3193 if (dev->class != new_class) { 3119 if (dev->class != new_class) {
@@ -3196,10 +3122,10 @@ static int ata_dev_same_device(struct ata_device *dev, unsigned int new_class,
3196 return 0; 3122 return 0;
3197 } 3123 }
3198 3124
3199 ata_id_c_string(old_id, model[0], ATA_ID_PROD_OFS, sizeof(model[0])); 3125 ata_id_c_string(old_id, model[0], ATA_ID_PROD, sizeof(model[0]));
3200 ata_id_c_string(new_id, model[1], ATA_ID_PROD_OFS, sizeof(model[1])); 3126 ata_id_c_string(new_id, model[1], ATA_ID_PROD, sizeof(model[1]));
3201 ata_id_c_string(old_id, serial[0], ATA_ID_SERNO_OFS, sizeof(serial[0])); 3127 ata_id_c_string(old_id, serial[0], ATA_ID_SERNO, sizeof(serial[0]));
3202 ata_id_c_string(new_id, serial[1], ATA_ID_SERNO_OFS, sizeof(serial[1])); 3128 ata_id_c_string(new_id, serial[1], ATA_ID_SERNO, sizeof(serial[1]));
3203 new_n_sectors = ata_id_n_sectors(new_id); 3129 new_n_sectors = ata_id_n_sectors(new_id);
3204 3130
3205 if (strcmp(model[0], model[1])) { 3131 if (strcmp(model[0], model[1])) {
@@ -3324,37 +3250,20 @@ static const struct ata_blacklist_entry ata_device_blacklist [] = {
3324 { } 3250 { }
3325}; 3251};
3326 3252
3327static int ata_strim(char *s, size_t len)
3328{
3329 len = strnlen(s, len);
3330
3331 /* ATAPI specifies that empty space is blank-filled; remove blanks */
3332 while ((len > 0) && (s[len - 1] == ' ')) {
3333 len--;
3334 s[len] = 0;
3335 }
3336 return len;
3337}
3338
3339unsigned long ata_device_blacklisted(const struct ata_device *dev) 3253unsigned long ata_device_blacklisted(const struct ata_device *dev)
3340{ 3254{
3341 unsigned char model_num[40]; 3255 unsigned char model_num[ATA_ID_PROD_LEN + 1];
3342 unsigned char model_rev[16]; 3256 unsigned char model_rev[ATA_ID_FW_REV_LEN + 1];
3343 unsigned int nlen, rlen;
3344 const struct ata_blacklist_entry *ad = ata_device_blacklist; 3257 const struct ata_blacklist_entry *ad = ata_device_blacklist;
3345 3258
3346 ata_id_string(dev->id, model_num, ATA_ID_PROD_OFS, 3259 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
3347 sizeof(model_num)); 3260 ata_id_c_string(dev->id, model_rev, ATA_ID_FW_REV, sizeof(model_rev));
3348 ata_id_string(dev->id, model_rev, ATA_ID_FW_REV_OFS,
3349 sizeof(model_rev));
3350 nlen = ata_strim(model_num, sizeof(model_num));
3351 rlen = ata_strim(model_rev, sizeof(model_rev));
3352 3261
3353 while (ad->model_num) { 3262 while (ad->model_num) {
3354 if (!strncmp(ad->model_num, model_num, nlen)) { 3263 if (!strcmp(ad->model_num, model_num)) {
3355 if (ad->model_rev == NULL) 3264 if (ad->model_rev == NULL)
3356 return ad->horkage; 3265 return ad->horkage;
3357 if (!strncmp(ad->model_rev, model_rev, rlen)) 3266 if (!strcmp(ad->model_rev, model_rev))
3358 return ad->horkage; 3267 return ad->horkage;
3359 } 3268 }
3360 ad++; 3269 ad++;
@@ -3894,53 +3803,7 @@ void swap_buf_le16(u16 *buf, unsigned int buf_words)
3894} 3803}
3895 3804
3896/** 3805/**
3897 * ata_mmio_data_xfer - Transfer data by MMIO 3806 * ata_data_xfer - Transfer data by PIO
3898 * @adev: device for this I/O
3899 * @buf: data buffer
3900 * @buflen: buffer length
3901 * @write_data: read/write
3902 *
3903 * Transfer data from/to the device data register by MMIO.
3904 *
3905 * LOCKING:
3906 * Inherited from caller.
3907 */
3908
3909void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
3910 unsigned int buflen, int write_data)
3911{
3912 struct ata_port *ap = adev->ap;
3913 unsigned int i;
3914 unsigned int words = buflen >> 1;
3915 u16 *buf16 = (u16 *) buf;
3916 void __iomem *mmio = (void __iomem *)ap->ioaddr.data_addr;
3917
3918 /* Transfer multiple of 2 bytes */
3919 if (write_data) {
3920 for (i = 0; i < words; i++)
3921 writew(le16_to_cpu(buf16[i]), mmio);
3922 } else {
3923 for (i = 0; i < words; i++)
3924 buf16[i] = cpu_to_le16(readw(mmio));
3925 }
3926
3927 /* Transfer trailing 1 byte, if any. */
3928 if (unlikely(buflen & 0x01)) {
3929 u16 align_buf[1] = { 0 };
3930 unsigned char *trailing_buf = buf + buflen - 1;
3931
3932 if (write_data) {
3933 memcpy(align_buf, trailing_buf, 1);
3934 writew(le16_to_cpu(align_buf[0]), mmio);
3935 } else {
3936 align_buf[0] = cpu_to_le16(readw(mmio));
3937 memcpy(trailing_buf, align_buf, 1);
3938 }
3939 }
3940}
3941
3942/**
3943 * ata_pio_data_xfer - Transfer data by PIO
3944 * @adev: device to target 3807 * @adev: device to target
3945 * @buf: data buffer 3808 * @buf: data buffer
3946 * @buflen: buffer length 3809 * @buflen: buffer length
@@ -3951,18 +3814,17 @@ void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf,
3951 * LOCKING: 3814 * LOCKING:
3952 * Inherited from caller. 3815 * Inherited from caller.
3953 */ 3816 */
3954 3817void ata_data_xfer(struct ata_device *adev, unsigned char *buf,
3955void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf, 3818 unsigned int buflen, int write_data)
3956 unsigned int buflen, int write_data)
3957{ 3819{
3958 struct ata_port *ap = adev->ap; 3820 struct ata_port *ap = adev->ap;
3959 unsigned int words = buflen >> 1; 3821 unsigned int words = buflen >> 1;
3960 3822
3961 /* Transfer multiple of 2 bytes */ 3823 /* Transfer multiple of 2 bytes */
3962 if (write_data) 3824 if (write_data)
3963 outsw(ap->ioaddr.data_addr, buf, words); 3825 iowrite16_rep(ap->ioaddr.data_addr, buf, words);
3964 else 3826 else
3965 insw(ap->ioaddr.data_addr, buf, words); 3827 ioread16_rep(ap->ioaddr.data_addr, buf, words);
3966 3828
3967 /* Transfer trailing 1 byte, if any. */ 3829 /* Transfer trailing 1 byte, if any. */
3968 if (unlikely(buflen & 0x01)) { 3830 if (unlikely(buflen & 0x01)) {
@@ -3971,16 +3833,16 @@ void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf,
3971 3833
3972 if (write_data) { 3834 if (write_data) {
3973 memcpy(align_buf, trailing_buf, 1); 3835 memcpy(align_buf, trailing_buf, 1);
3974 outw(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr); 3836 iowrite16(le16_to_cpu(align_buf[0]), ap->ioaddr.data_addr);
3975 } else { 3837 } else {
3976 align_buf[0] = cpu_to_le16(inw(ap->ioaddr.data_addr)); 3838 align_buf[0] = cpu_to_le16(ioread16(ap->ioaddr.data_addr));
3977 memcpy(trailing_buf, align_buf, 1); 3839 memcpy(trailing_buf, align_buf, 1);
3978 } 3840 }
3979 } 3841 }
3980} 3842}
3981 3843
3982/** 3844/**
3983 * ata_pio_data_xfer_noirq - Transfer data by PIO 3845 * ata_data_xfer_noirq - Transfer data by PIO
3984 * @adev: device to target 3846 * @adev: device to target
3985 * @buf: data buffer 3847 * @buf: data buffer
3986 * @buflen: buffer length 3848 * @buflen: buffer length
@@ -3992,13 +3854,12 @@ void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf,
3992 * LOCKING: 3854 * LOCKING:
3993 * Inherited from caller. 3855 * Inherited from caller.
3994 */ 3856 */
3995 3857void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
3996void ata_pio_data_xfer_noirq(struct ata_device *adev, unsigned char *buf, 3858 unsigned int buflen, int write_data)
3997 unsigned int buflen, int write_data)
3998{ 3859{
3999 unsigned long flags; 3860 unsigned long flags;
4000 local_irq_save(flags); 3861 local_irq_save(flags);
4001 ata_pio_data_xfer(adev, buf, buflen, write_data); 3862 ata_data_xfer(adev, buf, buflen, write_data);
4002 local_irq_restore(flags); 3863 local_irq_restore(flags);
4003} 3864}
4004 3865
@@ -4022,11 +3883,11 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
4022 unsigned int offset; 3883 unsigned int offset;
4023 unsigned char *buf; 3884 unsigned char *buf;
4024 3885
4025 if (qc->cursect == (qc->nsect - 1)) 3886 if (qc->curbytes == qc->nbytes - ATA_SECT_SIZE)
4026 ap->hsm_task_state = HSM_ST_LAST; 3887 ap->hsm_task_state = HSM_ST_LAST;
4027 3888
4028 page = sg[qc->cursg].page; 3889 page = sg[qc->cursg].page;
4029 offset = sg[qc->cursg].offset + qc->cursg_ofs * ATA_SECT_SIZE; 3890 offset = sg[qc->cursg].offset + qc->cursg_ofs;
4030 3891
4031 /* get the current page and offset */ 3892 /* get the current page and offset */
4032 page = nth_page(page, (offset >> PAGE_SHIFT)); 3893 page = nth_page(page, (offset >> PAGE_SHIFT));
@@ -4051,10 +3912,10 @@ static void ata_pio_sector(struct ata_queued_cmd *qc)
4051 ap->ops->data_xfer(qc->dev, buf + offset, ATA_SECT_SIZE, do_write); 3912 ap->ops->data_xfer(qc->dev, buf + offset, ATA_SECT_SIZE, do_write);
4052 } 3913 }
4053 3914
4054 qc->cursect++; 3915 qc->curbytes += ATA_SECT_SIZE;
4055 qc->cursg_ofs++; 3916 qc->cursg_ofs += ATA_SECT_SIZE;
4056 3917
4057 if ((qc->cursg_ofs * ATA_SECT_SIZE) == (&sg[qc->cursg])->length) { 3918 if (qc->cursg_ofs == (&sg[qc->cursg])->length) {
4058 qc->cursg++; 3919 qc->cursg++;
4059 qc->cursg_ofs = 0; 3920 qc->cursg_ofs = 0;
4060 } 3921 }
@@ -4079,7 +3940,8 @@ static void ata_pio_sectors(struct ata_queued_cmd *qc)
4079 3940
4080 WARN_ON(qc->dev->multi_count == 0); 3941 WARN_ON(qc->dev->multi_count == 0);
4081 3942
4082 nsect = min(qc->nsect - qc->cursect, qc->dev->multi_count); 3943 nsect = min((qc->nbytes - qc->curbytes) / ATA_SECT_SIZE,
3944 qc->dev->multi_count);
4083 while (nsect--) 3945 while (nsect--)
4084 ata_pio_sector(qc); 3946 ata_pio_sector(qc);
4085 } else 3947 } else
@@ -4320,7 +4182,7 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
4320 qc = ata_qc_from_tag(ap, qc->tag); 4182 qc = ata_qc_from_tag(ap, qc->tag);
4321 if (qc) { 4183 if (qc) {
4322 if (likely(!(qc->err_mask & AC_ERR_HSM))) { 4184 if (likely(!(qc->err_mask & AC_ERR_HSM))) {
4323 ata_irq_on(ap); 4185 ap->ops->irq_on(ap);
4324 ata_qc_complete(qc); 4186 ata_qc_complete(qc);
4325 } else 4187 } else
4326 ata_port_freeze(ap); 4188 ata_port_freeze(ap);
@@ -4336,7 +4198,7 @@ static void ata_hsm_qc_complete(struct ata_queued_cmd *qc, int in_wq)
4336 } else { 4198 } else {
4337 if (in_wq) { 4199 if (in_wq) {
4338 spin_lock_irqsave(ap->lock, flags); 4200 spin_lock_irqsave(ap->lock, flags);
4339 ata_irq_on(ap); 4201 ap->ops->irq_on(ap);
4340 ata_qc_complete(qc); 4202 ata_qc_complete(qc);
4341 spin_unlock_irqrestore(ap->lock, flags); 4203 spin_unlock_irqrestore(ap->lock, flags);
4342 } else 4204 } else
@@ -5161,7 +5023,7 @@ idle_irq:
5161 5023
5162#ifdef ATA_IRQ_TRAP 5024#ifdef ATA_IRQ_TRAP
5163 if ((ap->stats.idle_irq % 1000) == 0) { 5025 if ((ap->stats.idle_irq % 1000) == 0) {
5164 ata_irq_ack(ap, 0); /* debug trap */ 5026 ap->ops->irq_ack(ap, 0); /* debug trap */
5165 ata_port_printk(ap, KERN_WARNING, "irq trap\n"); 5027 ata_port_printk(ap, KERN_WARNING, "irq trap\n");
5166 return 1; 5028 return 1;
5167 } 5029 }
@@ -5502,54 +5364,25 @@ void ata_host_resume(struct ata_host *host)
5502 * LOCKING: 5364 * LOCKING:
5503 * Inherited from caller. 5365 * Inherited from caller.
5504 */ 5366 */
5505 5367int ata_port_start(struct ata_port *ap)
5506int ata_port_start (struct ata_port *ap)
5507{ 5368{
5508 struct device *dev = ap->dev; 5369 struct device *dev = ap->dev;
5509 int rc; 5370 int rc;
5510 5371
5511 ap->prd = dma_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma, GFP_KERNEL); 5372 ap->prd = dmam_alloc_coherent(dev, ATA_PRD_TBL_SZ, &ap->prd_dma,
5373 GFP_KERNEL);
5512 if (!ap->prd) 5374 if (!ap->prd)
5513 return -ENOMEM; 5375 return -ENOMEM;
5514 5376
5515 rc = ata_pad_alloc(ap, dev); 5377 rc = ata_pad_alloc(ap, dev);
5516 if (rc) { 5378 if (rc)
5517 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma);
5518 return rc; 5379 return rc;
5519 }
5520
5521 DPRINTK("prd alloc, virt %p, dma %llx\n", ap->prd, (unsigned long long) ap->prd_dma);
5522 5380
5381 DPRINTK("prd alloc, virt %p, dma %llx\n", ap->prd,
5382 (unsigned long long)ap->prd_dma);
5523 return 0; 5383 return 0;
5524} 5384}
5525 5385
5526
5527/**
5528 * ata_port_stop - Undo ata_port_start()
5529 * @ap: Port to shut down
5530 *
5531 * Frees the PRD table.
5532 *
5533 * May be used as the port_stop() entry in ata_port_operations.
5534 *
5535 * LOCKING:
5536 * Inherited from caller.
5537 */
5538
5539void ata_port_stop (struct ata_port *ap)
5540{
5541 struct device *dev = ap->dev;
5542
5543 dma_free_coherent(dev, ATA_PRD_TBL_SZ, ap->prd, ap->prd_dma);
5544 ata_pad_free(ap, dev);
5545}
5546
5547void ata_host_stop (struct ata_host *host)
5548{
5549 if (host->mmio_base)
5550 iounmap(host->mmio_base);
5551}
5552
5553/** 5386/**
5554 * ata_dev_init - Initialize an ata_device structure 5387 * ata_dev_init - Initialize an ata_device structure
5555 * @dev: Device structure to initialize 5388 * @dev: Device structure to initialize
@@ -5723,6 +5556,27 @@ static struct ata_port * ata_port_add(const struct ata_probe_ent *ent,
5723 return ap; 5556 return ap;
5724} 5557}
5725 5558
5559static void ata_host_release(struct device *gendev, void *res)
5560{
5561 struct ata_host *host = dev_get_drvdata(gendev);
5562 int i;
5563
5564 for (i = 0; i < host->n_ports; i++) {
5565 struct ata_port *ap = host->ports[i];
5566
5567 if (!ap)
5568 continue;
5569
5570 if (ap->ops->port_stop)
5571 ap->ops->port_stop(ap);
5572
5573 scsi_host_put(ap->scsi_host);
5574 }
5575
5576 if (host->ops->host_stop)
5577 host->ops->host_stop(host);
5578}
5579
5726/** 5580/**
5727 * ata_sas_host_init - Initialize a host struct 5581 * ata_sas_host_init - Initialize a host struct
5728 * @host: host to initialize 5582 * @host: host to initialize
@@ -5770,22 +5624,28 @@ int ata_device_add(const struct ata_probe_ent *ent)
5770 int rc; 5624 int rc;
5771 5625
5772 DPRINTK("ENTER\n"); 5626 DPRINTK("ENTER\n");
5773 5627
5774 if (ent->irq == 0) { 5628 if (ent->irq == 0) {
5775 dev_printk(KERN_ERR, dev, "is not available: No interrupt assigned.\n"); 5629 dev_printk(KERN_ERR, dev, "is not available: No interrupt assigned.\n");
5776 return 0; 5630 return 0;
5777 } 5631 }
5632
5633 if (!devres_open_group(dev, ata_device_add, GFP_KERNEL))
5634 return 0;
5635
5778 /* alloc a container for our list of ATA ports (buses) */ 5636 /* alloc a container for our list of ATA ports (buses) */
5779 host = kzalloc(sizeof(struct ata_host) + 5637 host = devres_alloc(ata_host_release, sizeof(struct ata_host) +
5780 (ent->n_ports * sizeof(void *)), GFP_KERNEL); 5638 (ent->n_ports * sizeof(void *)), GFP_KERNEL);
5781 if (!host) 5639 if (!host)
5782 return 0; 5640 goto err_out;
5641 devres_add(dev, host);
5642 dev_set_drvdata(dev, host);
5783 5643
5784 ata_host_init(host, dev, ent->_host_flags, ent->port_ops); 5644 ata_host_init(host, dev, ent->_host_flags, ent->port_ops);
5785 host->n_ports = ent->n_ports; 5645 host->n_ports = ent->n_ports;
5786 host->irq = ent->irq; 5646 host->irq = ent->irq;
5787 host->irq2 = ent->irq2; 5647 host->irq2 = ent->irq2;
5788 host->mmio_base = ent->mmio_base; 5648 host->iomap = ent->iomap;
5789 host->private_data = ent->private_data; 5649 host->private_data = ent->private_data;
5790 5650
5791 /* register each port bound to this device */ 5651 /* register each port bound to this device */
@@ -5823,8 +5683,8 @@ int ata_device_add(const struct ata_probe_ent *ent)
5823 (ap->pio_mask << ATA_SHIFT_PIO); 5683 (ap->pio_mask << ATA_SHIFT_PIO);
5824 5684
5825 /* print per-port info to dmesg */ 5685 /* print per-port info to dmesg */
5826 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%lX " 5686 ata_port_printk(ap, KERN_INFO, "%cATA max %s cmd 0x%p "
5827 "ctl 0x%lX bmdma 0x%lX irq %d\n", 5687 "ctl 0x%p bmdma 0x%p irq %d\n",
5828 ap->flags & ATA_FLAG_SATA ? 'S' : 'P', 5688 ap->flags & ATA_FLAG_SATA ? 'S' : 'P',
5829 ata_mode_string(xfer_mode_mask), 5689 ata_mode_string(xfer_mode_mask),
5830 ap->ioaddr.cmd_addr, 5690 ap->ioaddr.cmd_addr,
@@ -5837,8 +5697,8 @@ int ata_device_add(const struct ata_probe_ent *ent)
5837 } 5697 }
5838 5698
5839 /* obtain irq, that may be shared between channels */ 5699 /* obtain irq, that may be shared between channels */
5840 rc = request_irq(ent->irq, ent->port_ops->irq_handler, ent->irq_flags, 5700 rc = devm_request_irq(dev, ent->irq, ent->port_ops->irq_handler,
5841 DRV_NAME, host); 5701 ent->irq_flags, DRV_NAME, host);
5842 if (rc) { 5702 if (rc) {
5843 dev_printk(KERN_ERR, dev, "irq %lu request failed: %d\n", 5703 dev_printk(KERN_ERR, dev, "irq %lu request failed: %d\n",
5844 ent->irq, rc); 5704 ent->irq, rc);
@@ -5851,15 +5711,19 @@ int ata_device_add(const struct ata_probe_ent *ent)
5851 so trap it now */ 5711 so trap it now */
5852 BUG_ON(ent->irq == ent->irq2); 5712 BUG_ON(ent->irq == ent->irq2);
5853 5713
5854 rc = request_irq(ent->irq2, ent->port_ops->irq_handler, ent->irq_flags, 5714 rc = devm_request_irq(dev, ent->irq2,
5855 DRV_NAME, host); 5715 ent->port_ops->irq_handler, ent->irq_flags,
5716 DRV_NAME, host);
5856 if (rc) { 5717 if (rc) {
5857 dev_printk(KERN_ERR, dev, "irq %lu request failed: %d\n", 5718 dev_printk(KERN_ERR, dev, "irq %lu request failed: %d\n",
5858 ent->irq2, rc); 5719 ent->irq2, rc);
5859 goto err_out_free_irq; 5720 goto err_out;
5860 } 5721 }
5861 } 5722 }
5862 5723
5724 /* resource acquisition complete */
5725 devres_remove_group(dev, ata_device_add);
5726
5863 /* perform each probe synchronously */ 5727 /* perform each probe synchronously */
5864 DPRINTK("probe begin\n"); 5728 DPRINTK("probe begin\n");
5865 for (i = 0; i < host->n_ports; i++) { 5729 for (i = 0; i < host->n_ports; i++) {
@@ -5928,24 +5792,13 @@ int ata_device_add(const struct ata_probe_ent *ent)
5928 ata_scsi_scan_host(ap); 5792 ata_scsi_scan_host(ap);
5929 } 5793 }
5930 5794
5931 dev_set_drvdata(dev, host);
5932
5933 VPRINTK("EXIT, returning %u\n", ent->n_ports); 5795 VPRINTK("EXIT, returning %u\n", ent->n_ports);
5934 return ent->n_ports; /* success */ 5796 return ent->n_ports; /* success */
5935 5797
5936err_out_free_irq: 5798 err_out:
5937 free_irq(ent->irq, host); 5799 devres_release_group(dev, ata_device_add);
5938err_out: 5800 dev_set_drvdata(dev, NULL);
5939 for (i = 0; i < host->n_ports; i++) { 5801 VPRINTK("EXIT, returning %d\n", rc);
5940 struct ata_port *ap = host->ports[i];
5941 if (ap) {
5942 ap->ops->port_stop(ap);
5943 scsi_host_put(ap->scsi_host);
5944 }
5945 }
5946
5947 kfree(host);
5948 VPRINTK("EXIT, returning 0\n");
5949 return 0; 5802 return 0;
5950} 5803}
5951 5804
@@ -6008,76 +5861,20 @@ void ata_port_detach(struct ata_port *ap)
6008} 5861}
6009 5862
6010/** 5863/**
6011 * ata_host_remove - PCI layer callback for device removal 5864 * ata_host_detach - Detach all ports of an ATA host
6012 * @host: ATA host set that was removed 5865 * @host: Host to detach
6013 * 5866 *
6014 * Unregister all objects associated with this host set. Free those 5867 * Detach all ports of @host.
6015 * objects.
6016 * 5868 *
6017 * LOCKING: 5869 * LOCKING:
6018 * Inherited from calling layer (may sleep). 5870 * Kernel thread context (may sleep).
6019 */ 5871 */
6020 5872void ata_host_detach(struct ata_host *host)
6021void ata_host_remove(struct ata_host *host)
6022{ 5873{
6023 unsigned int i; 5874 int i;
6024 5875
6025 for (i = 0; i < host->n_ports; i++) 5876 for (i = 0; i < host->n_ports; i++)
6026 ata_port_detach(host->ports[i]); 5877 ata_port_detach(host->ports[i]);
6027
6028 free_irq(host->irq, host);
6029 if (host->irq2)
6030 free_irq(host->irq2, host);
6031
6032 for (i = 0; i < host->n_ports; i++) {
6033 struct ata_port *ap = host->ports[i];
6034
6035 ata_scsi_release(ap->scsi_host);
6036
6037 if ((ap->flags & ATA_FLAG_NO_LEGACY) == 0) {
6038 struct ata_ioports *ioaddr = &ap->ioaddr;
6039
6040 /* FIXME: Add -ac IDE pci mods to remove these special cases */
6041 if (ioaddr->cmd_addr == ATA_PRIMARY_CMD)
6042 release_region(ATA_PRIMARY_CMD, 8);
6043 else if (ioaddr->cmd_addr == ATA_SECONDARY_CMD)
6044 release_region(ATA_SECONDARY_CMD, 8);
6045 }
6046
6047 scsi_host_put(ap->scsi_host);
6048 }
6049
6050 if (host->ops->host_stop)
6051 host->ops->host_stop(host);
6052
6053 kfree(host);
6054}
6055
6056/**
6057 * ata_scsi_release - SCSI layer callback hook for host unload
6058 * @shost: libata host to be unloaded
6059 *
6060 * Performs all duties necessary to shut down a libata port...
6061 * Kill port kthread, disable port, and release resources.
6062 *
6063 * LOCKING:
6064 * Inherited from SCSI layer.
6065 *
6066 * RETURNS:
6067 * One.
6068 */
6069
6070int ata_scsi_release(struct Scsi_Host *shost)
6071{
6072 struct ata_port *ap = ata_shost_to_port(shost);
6073
6074 DPRINTK("ENTER\n");
6075
6076 ap->ops->port_disable(ap);
6077 ap->ops->port_stop(ap);
6078
6079 DPRINTK("EXIT\n");
6080 return 1;
6081} 5878}
6082 5879
6083struct ata_probe_ent * 5880struct ata_probe_ent *
@@ -6085,7 +5882,11 @@ ata_probe_ent_alloc(struct device *dev, const struct ata_port_info *port)
6085{ 5882{
6086 struct ata_probe_ent *probe_ent; 5883 struct ata_probe_ent *probe_ent;
6087 5884
6088 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); 5885 /* XXX - the following if can go away once all LLDs are managed */
5886 if (!list_empty(&dev->devres_head))
5887 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
5888 else
5889 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
6089 if (!probe_ent) { 5890 if (!probe_ent) {
6090 printk(KERN_ERR DRV_NAME "(%s): out of memory\n", 5891 printk(KERN_ERR DRV_NAME "(%s): out of memory\n",
6091 kobject_name(&(dev->kobj))); 5892 kobject_name(&(dev->kobj)));
@@ -6135,37 +5936,23 @@ void ata_std_ports(struct ata_ioports *ioaddr)
6135 5936
6136#ifdef CONFIG_PCI 5937#ifdef CONFIG_PCI
6137 5938
6138void ata_pci_host_stop (struct ata_host *host)
6139{
6140 struct pci_dev *pdev = to_pci_dev(host->dev);
6141
6142 pci_iounmap(pdev, host->mmio_base);
6143}
6144
6145/** 5939/**
6146 * ata_pci_remove_one - PCI layer callback for device removal 5940 * ata_pci_remove_one - PCI layer callback for device removal
6147 * @pdev: PCI device that was removed 5941 * @pdev: PCI device that was removed
6148 * 5942 *
6149 * PCI layer indicates to libata via this hook that 5943 * PCI layer indicates to libata via this hook that hot-unplug or
6150 * hot-unplug or module unload event has occurred. 5944 * module unload event has occurred. Detach all ports. Resource
6151 * Handle this by unregistering all objects associated 5945 * release is handled via devres.
6152 * with this PCI device. Free those objects. Then finally
6153 * release PCI resources and disable device.
6154 * 5946 *
6155 * LOCKING: 5947 * LOCKING:
6156 * Inherited from PCI layer (may sleep). 5948 * Inherited from PCI layer (may sleep).
6157 */ 5949 */
6158 5950void ata_pci_remove_one(struct pci_dev *pdev)
6159void ata_pci_remove_one (struct pci_dev *pdev)
6160{ 5951{
6161 struct device *dev = pci_dev_to_dev(pdev); 5952 struct device *dev = pci_dev_to_dev(pdev);
6162 struct ata_host *host = dev_get_drvdata(dev); 5953 struct ata_host *host = dev_get_drvdata(dev);
6163 5954
6164 ata_host_remove(host); 5955 ata_host_detach(host);
6165
6166 pci_release_regions(pdev);
6167 pci_disable_device(pdev);
6168 dev_set_drvdata(dev, NULL);
6169} 5956}
6170 5957
6171/* move to PCI subsystem */ 5958/* move to PCI subsystem */
@@ -6212,12 +5999,22 @@ void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg)
6212 } 5999 }
6213} 6000}
6214 6001
6215void ata_pci_device_do_resume(struct pci_dev *pdev) 6002int ata_pci_device_do_resume(struct pci_dev *pdev)
6216{ 6003{
6004 int rc;
6005
6217 pci_set_power_state(pdev, PCI_D0); 6006 pci_set_power_state(pdev, PCI_D0);
6218 pci_restore_state(pdev); 6007 pci_restore_state(pdev);
6219 pci_enable_device(pdev); 6008
6009 rc = pcim_enable_device(pdev);
6010 if (rc) {
6011 dev_printk(KERN_ERR, &pdev->dev,
6012 "failed to enable device after resume (%d)\n", rc);
6013 return rc;
6014 }
6015
6220 pci_set_master(pdev); 6016 pci_set_master(pdev);
6017 return 0;
6221} 6018}
6222 6019
6223int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg) 6020int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
@@ -6237,10 +6034,12 @@ int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg)
6237int ata_pci_device_resume(struct pci_dev *pdev) 6034int ata_pci_device_resume(struct pci_dev *pdev)
6238{ 6035{
6239 struct ata_host *host = dev_get_drvdata(&pdev->dev); 6036 struct ata_host *host = dev_get_drvdata(&pdev->dev);
6037 int rc;
6240 6038
6241 ata_pci_device_do_resume(pdev); 6039 rc = ata_pci_device_do_resume(pdev);
6242 ata_host_resume(host); 6040 if (rc == 0)
6243 return 0; 6041 ata_host_resume(host);
6042 return rc;
6244} 6043}
6245#endif /* CONFIG_PCI */ 6044#endif /* CONFIG_PCI */
6246 6045
@@ -6386,8 +6185,7 @@ EXPORT_SYMBOL_GPL(ata_std_bios_param);
6386EXPORT_SYMBOL_GPL(ata_std_ports); 6185EXPORT_SYMBOL_GPL(ata_std_ports);
6387EXPORT_SYMBOL_GPL(ata_host_init); 6186EXPORT_SYMBOL_GPL(ata_host_init);
6388EXPORT_SYMBOL_GPL(ata_device_add); 6187EXPORT_SYMBOL_GPL(ata_device_add);
6389EXPORT_SYMBOL_GPL(ata_port_detach); 6188EXPORT_SYMBOL_GPL(ata_host_detach);
6390EXPORT_SYMBOL_GPL(ata_host_remove);
6391EXPORT_SYMBOL_GPL(ata_sg_init); 6189EXPORT_SYMBOL_GPL(ata_sg_init);
6392EXPORT_SYMBOL_GPL(ata_sg_init_one); 6190EXPORT_SYMBOL_GPL(ata_sg_init_one);
6393EXPORT_SYMBOL_GPL(ata_hsm_move); 6191EXPORT_SYMBOL_GPL(ata_hsm_move);
@@ -6404,12 +6202,9 @@ EXPORT_SYMBOL_GPL(ata_check_status);
6404EXPORT_SYMBOL_GPL(ata_altstatus); 6202EXPORT_SYMBOL_GPL(ata_altstatus);
6405EXPORT_SYMBOL_GPL(ata_exec_command); 6203EXPORT_SYMBOL_GPL(ata_exec_command);
6406EXPORT_SYMBOL_GPL(ata_port_start); 6204EXPORT_SYMBOL_GPL(ata_port_start);
6407EXPORT_SYMBOL_GPL(ata_port_stop);
6408EXPORT_SYMBOL_GPL(ata_host_stop);
6409EXPORT_SYMBOL_GPL(ata_interrupt); 6205EXPORT_SYMBOL_GPL(ata_interrupt);
6410EXPORT_SYMBOL_GPL(ata_mmio_data_xfer); 6206EXPORT_SYMBOL_GPL(ata_data_xfer);
6411EXPORT_SYMBOL_GPL(ata_pio_data_xfer); 6207EXPORT_SYMBOL_GPL(ata_data_xfer_noirq);
6412EXPORT_SYMBOL_GPL(ata_pio_data_xfer_noirq);
6413EXPORT_SYMBOL_GPL(ata_qc_prep); 6208EXPORT_SYMBOL_GPL(ata_qc_prep);
6414EXPORT_SYMBOL_GPL(ata_noop_qc_prep); 6209EXPORT_SYMBOL_GPL(ata_noop_qc_prep);
6415EXPORT_SYMBOL_GPL(ata_bmdma_setup); 6210EXPORT_SYMBOL_GPL(ata_bmdma_setup);
@@ -6446,7 +6241,6 @@ EXPORT_SYMBOL_GPL(ata_scsi_queuecmd);
6446EXPORT_SYMBOL_GPL(ata_scsi_slave_config); 6241EXPORT_SYMBOL_GPL(ata_scsi_slave_config);
6447EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy); 6242EXPORT_SYMBOL_GPL(ata_scsi_slave_destroy);
6448EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth); 6243EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth);
6449EXPORT_SYMBOL_GPL(ata_scsi_release);
6450EXPORT_SYMBOL_GPL(ata_host_intr); 6244EXPORT_SYMBOL_GPL(ata_host_intr);
6451EXPORT_SYMBOL_GPL(sata_scr_valid); 6245EXPORT_SYMBOL_GPL(sata_scr_valid);
6452EXPORT_SYMBOL_GPL(sata_scr_read); 6246EXPORT_SYMBOL_GPL(sata_scr_read);
@@ -6467,7 +6261,6 @@ EXPORT_SYMBOL_GPL(ata_timing_merge);
6467 6261
6468#ifdef CONFIG_PCI 6262#ifdef CONFIG_PCI
6469EXPORT_SYMBOL_GPL(pci_test_config_bits); 6263EXPORT_SYMBOL_GPL(pci_test_config_bits);
6470EXPORT_SYMBOL_GPL(ata_pci_host_stop);
6471EXPORT_SYMBOL_GPL(ata_pci_init_native_mode); 6264EXPORT_SYMBOL_GPL(ata_pci_init_native_mode);
6472EXPORT_SYMBOL_GPL(ata_pci_init_one); 6265EXPORT_SYMBOL_GPL(ata_pci_init_one);
6473EXPORT_SYMBOL_GPL(ata_pci_remove_one); 6266EXPORT_SYMBOL_GPL(ata_pci_remove_one);
@@ -6491,3 +6284,7 @@ EXPORT_SYMBOL_GPL(ata_eh_thaw_port);
6491EXPORT_SYMBOL_GPL(ata_eh_qc_complete); 6284EXPORT_SYMBOL_GPL(ata_eh_qc_complete);
6492EXPORT_SYMBOL_GPL(ata_eh_qc_retry); 6285EXPORT_SYMBOL_GPL(ata_eh_qc_retry);
6493EXPORT_SYMBOL_GPL(ata_do_eh); 6286EXPORT_SYMBOL_GPL(ata_do_eh);
6287EXPORT_SYMBOL_GPL(ata_irq_on);
6288EXPORT_SYMBOL_GPL(ata_dummy_irq_on);
6289EXPORT_SYMBOL_GPL(ata_irq_ack);
6290EXPORT_SYMBOL_GPL(ata_dummy_irq_ack);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index 748435807d6..52c85af7fe9 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -1443,15 +1443,10 @@ static void ata_eh_report(struct ata_port *ap)
1443 }; 1443 };
1444 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag); 1444 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
1445 struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf; 1445 struct ata_taskfile *cmd = &qc->tf, *res = &qc->result_tf;
1446 unsigned int nbytes;
1447 1446
1448 if (!(qc->flags & ATA_QCFLAG_FAILED) || !qc->err_mask) 1447 if (!(qc->flags & ATA_QCFLAG_FAILED) || !qc->err_mask)
1449 continue; 1448 continue;
1450 1449
1451 nbytes = qc->nbytes;
1452 if (!nbytes)
1453 nbytes = qc->nsect << 9;
1454
1455 ata_dev_printk(qc->dev, KERN_ERR, 1450 ata_dev_printk(qc->dev, KERN_ERR,
1456 "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x " 1451 "cmd %02x/%02x:%02x:%02x:%02x:%02x/%02x:%02x:%02x:%02x:%02x/%02x "
1457 "tag %d cdb 0x%x data %u %s\n " 1452 "tag %d cdb 0x%x data %u %s\n "
@@ -1461,7 +1456,7 @@ static void ata_eh_report(struct ata_port *ap)
1461 cmd->lbal, cmd->lbam, cmd->lbah, 1456 cmd->lbal, cmd->lbam, cmd->lbah,
1462 cmd->hob_feature, cmd->hob_nsect, 1457 cmd->hob_feature, cmd->hob_nsect,
1463 cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah, 1458 cmd->hob_lbal, cmd->hob_lbam, cmd->hob_lbah,
1464 cmd->device, qc->tag, qc->cdb[0], nbytes, 1459 cmd->device, qc->tag, qc->cdb[0], qc->nbytes,
1465 dma_str[qc->dma_dir], 1460 dma_str[qc->dma_dir],
1466 res->command, res->feature, res->nsect, 1461 res->command, res->feature, res->nsect,
1467 res->lbal, res->lbam, res->lbah, 1462 res->lbal, res->lbam, res->lbah,
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 73902d33576..0009818a430 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -149,6 +149,45 @@ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev,
149} 149}
150 150
151/** 151/**
152 * ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl
153 * @sdev: SCSI device to get identify data for
154 * @arg: User buffer area for identify data
155 *
156 * LOCKING:
157 * Defined by the SCSI layer. We don't really care.
158 *
159 * RETURNS:
160 * Zero on success, negative errno on error.
161 */
162static int ata_get_identity(struct scsi_device *sdev, void __user *arg)
163{
164 struct ata_port *ap = ata_shost_to_port(sdev->host);
165 struct ata_device *dev = ata_scsi_find_dev(ap, sdev);
166 u16 __user *dst = arg;
167 char buf[40];
168
169 if (!dev)
170 return -ENOMSG;
171
172 if (copy_to_user(dst, dev->id, ATA_ID_WORDS * sizeof(u16)))
173 return -EFAULT;
174
175 ata_id_string(dev->id, buf, ATA_ID_PROD, ATA_ID_PROD_LEN);
176 if (copy_to_user(dst + ATA_ID_PROD, buf, ATA_ID_PROD_LEN))
177 return -EFAULT;
178
179 ata_id_string(dev->id, buf, ATA_ID_FW_REV, ATA_ID_FW_REV_LEN);
180 if (copy_to_user(dst + ATA_ID_FW_REV, buf, ATA_ID_FW_REV_LEN))
181 return -EFAULT;
182
183 ata_id_string(dev->id, buf, ATA_ID_SERNO, ATA_ID_SERNO_LEN);
184 if (copy_to_user(dst + ATA_ID_SERNO, buf, ATA_ID_SERNO_LEN))
185 return -EFAULT;
186
187 return 0;
188}
189
190/**
152 * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl 191 * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl
153 * @scsidev: Device to which we are issuing command 192 * @scsidev: Device to which we are issuing command
154 * @arg: User provided data for issuing command 193 * @arg: User provided data for issuing command
@@ -159,7 +198,6 @@ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev,
159 * RETURNS: 198 * RETURNS:
160 * Zero on success, negative errno on error. 199 * Zero on success, negative errno on error.
161 */ 200 */
162
163int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) 201int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg)
164{ 202{
165 int rc = 0; 203 int rc = 0;
@@ -359,6 +397,9 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
359 return -EINVAL; 397 return -EINVAL;
360 return 0; 398 return 0;
361 399
400 case HDIO_GET_IDENTITY:
401 return ata_get_identity(scsidev, arg);
402
362 case HDIO_DRIVE_CMD: 403 case HDIO_DRIVE_CMD:
363 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO)) 404 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
364 return -EACCES; 405 return -EACCES;
@@ -397,9 +438,9 @@ int ata_scsi_ioctl(struct scsi_device *scsidev, int cmd, void __user *arg)
397 * RETURNS: 438 * RETURNS:
398 * Command allocated, or %NULL if none available. 439 * Command allocated, or %NULL if none available.
399 */ 440 */
400struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev, 441static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev,
401 struct scsi_cmnd *cmd, 442 struct scsi_cmnd *cmd,
402 void (*done)(struct scsi_cmnd *)) 443 void (*done)(struct scsi_cmnd *))
403{ 444{
404 struct ata_queued_cmd *qc; 445 struct ata_queued_cmd *qc;
405 446
@@ -435,7 +476,7 @@ struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev,
435 * LOCKING: 476 * LOCKING:
436 * inherited from caller 477 * inherited from caller
437 */ 478 */
438void ata_dump_status(unsigned id, struct ata_taskfile *tf) 479static void ata_dump_status(unsigned id, struct ata_taskfile *tf)
439{ 480{
440 u8 stat = tf->command, err = tf->feature; 481 u8 stat = tf->command, err = tf->feature;
441 482
@@ -610,8 +651,8 @@ int ata_scsi_device_resume(struct scsi_device *sdev)
610 * LOCKING: 651 * LOCKING:
611 * spin_lock_irqsave(host lock) 652 * spin_lock_irqsave(host lock)
612 */ 653 */
613void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, 654static void ata_to_sense_error(unsigned id, u8 drv_stat, u8 drv_err, u8 *sk,
614 u8 *ascq, int verbose) 655 u8 *asc, u8 *ascq, int verbose)
615{ 656{
616 int i; 657 int i;
617 658
@@ -1359,7 +1400,7 @@ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc)
1359 goto nothing_to_do; 1400 goto nothing_to_do;
1360 1401
1361 qc->flags |= ATA_QCFLAG_IO; 1402 qc->flags |= ATA_QCFLAG_IO;
1362 qc->nsect = n_block; 1403 qc->nbytes = n_block * ATA_SECT_SIZE;
1363 1404
1364 rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags, 1405 rc = ata_build_rw_tf(&qc->tf, qc->dev, block, n_block, tf_flags,
1365 qc->tag); 1406 qc->tag);
@@ -1698,8 +1739,8 @@ unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf,
1698 1739
1699 if (buflen > 35) { 1740 if (buflen > 35) {
1700 memcpy(&rbuf[8], "ATA ", 8); 1741 memcpy(&rbuf[8], "ATA ", 8);
1701 ata_id_string(args->id, &rbuf[16], ATA_ID_PROD_OFS, 16); 1742 ata_id_string(args->id, &rbuf[16], ATA_ID_PROD, 16);
1702 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV_OFS, 4); 1743 ata_id_string(args->id, &rbuf[32], ATA_ID_FW_REV, 4);
1703 if (rbuf[32] == 0 || rbuf[32] == ' ') 1744 if (rbuf[32] == 0 || rbuf[32] == ' ')
1704 memcpy(&rbuf[32], "n/a ", 4); 1745 memcpy(&rbuf[32], "n/a ", 4);
1705 } 1746 }
@@ -1768,13 +1809,13 @@ unsigned int ata_scsiop_inq_80(struct ata_scsi_args *args, u8 *rbuf,
1768 0, 1809 0,
1769 0x80, /* this page code */ 1810 0x80, /* this page code */
1770 0, 1811 0,
1771 ATA_SERNO_LEN, /* page len */ 1812 ATA_ID_SERNO_LEN, /* page len */
1772 }; 1813 };
1773 memcpy(rbuf, hdr, sizeof(hdr)); 1814 memcpy(rbuf, hdr, sizeof(hdr));
1774 1815
1775 if (buflen > (ATA_SERNO_LEN + 4 - 1)) 1816 if (buflen > (ATA_ID_SERNO_LEN + 4 - 1))
1776 ata_id_string(args->id, (unsigned char *) &rbuf[4], 1817 ata_id_string(args->id, (unsigned char *) &rbuf[4],
1777 ATA_ID_SERNO_OFS, ATA_SERNO_LEN); 1818 ATA_ID_SERNO, ATA_ID_SERNO_LEN);
1778 1819
1779 return 0; 1820 return 0;
1780} 1821}
@@ -1799,19 +1840,18 @@ unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf,
1799{ 1840{
1800 int num; 1841 int num;
1801 const int sat_model_serial_desc_len = 68; 1842 const int sat_model_serial_desc_len = 68;
1802 const int ata_model_byte_len = 40;
1803 1843
1804 rbuf[1] = 0x83; /* this page code */ 1844 rbuf[1] = 0x83; /* this page code */
1805 num = 4; 1845 num = 4;
1806 1846
1807 if (buflen > (ATA_SERNO_LEN + num + 3)) { 1847 if (buflen > (ATA_ID_SERNO_LEN + num + 3)) {
1808 /* piv=0, assoc=lu, code_set=ACSII, designator=vendor */ 1848 /* piv=0, assoc=lu, code_set=ACSII, designator=vendor */
1809 rbuf[num + 0] = 2; 1849 rbuf[num + 0] = 2;
1810 rbuf[num + 3] = ATA_SERNO_LEN; 1850 rbuf[num + 3] = ATA_ID_SERNO_LEN;
1811 num += 4; 1851 num += 4;
1812 ata_id_string(args->id, (unsigned char *) rbuf + num, 1852 ata_id_string(args->id, (unsigned char *) rbuf + num,
1813 ATA_ID_SERNO_OFS, ATA_SERNO_LEN); 1853 ATA_ID_SERNO, ATA_ID_SERNO_LEN);
1814 num += ATA_SERNO_LEN; 1854 num += ATA_ID_SERNO_LEN;
1815 } 1855 }
1816 if (buflen > (sat_model_serial_desc_len + num + 3)) { 1856 if (buflen > (sat_model_serial_desc_len + num + 3)) {
1817 /* SAT defined lu model and serial numbers descriptor */ 1857 /* SAT defined lu model and serial numbers descriptor */
@@ -1823,11 +1863,11 @@ unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf,
1823 memcpy(rbuf + num, "ATA ", 8); 1863 memcpy(rbuf + num, "ATA ", 8);
1824 num += 8; 1864 num += 8;
1825 ata_id_string(args->id, (unsigned char *) rbuf + num, 1865 ata_id_string(args->id, (unsigned char *) rbuf + num,
1826 ATA_ID_PROD_OFS, ata_model_byte_len); 1866 ATA_ID_PROD, ATA_ID_PROD_LEN);
1827 num += ata_model_byte_len; 1867 num += ATA_ID_PROD_LEN;
1828 ata_id_string(args->id, (unsigned char *) rbuf + num, 1868 ata_id_string(args->id, (unsigned char *) rbuf + num,
1829 ATA_ID_SERNO_OFS, ATA_SERNO_LEN); 1869 ATA_ID_SERNO, ATA_ID_SERNO_LEN);
1830 num += ATA_SERNO_LEN; 1870 num += ATA_ID_SERNO_LEN;
1831 } 1871 }
1832 rbuf[3] = num - 4; /* page len (assume less than 256 bytes) */ 1872 rbuf[3] = num - 4; /* page len (assume less than 256 bytes) */
1833 return 0; 1873 return 0;
@@ -1955,15 +1995,15 @@ static unsigned int ata_msense_rw_recovery(u8 **ptr_io, const u8 *last)
1955 */ 1995 */
1956static int ata_dev_supports_fua(u16 *id) 1996static int ata_dev_supports_fua(u16 *id)
1957{ 1997{
1958 unsigned char model[41], fw[9]; 1998 unsigned char model[ATA_ID_PROD_LEN + 1], fw[ATA_ID_FW_REV_LEN + 1];
1959 1999
1960 if (!libata_fua) 2000 if (!libata_fua)
1961 return 0; 2001 return 0;
1962 if (!ata_id_has_fua(id)) 2002 if (!ata_id_has_fua(id))
1963 return 0; 2003 return 0;
1964 2004
1965 ata_id_c_string(id, model, ATA_ID_PROD_OFS, sizeof(model)); 2005 ata_id_c_string(id, model, ATA_ID_PROD, sizeof(model));
1966 ata_id_c_string(id, fw, ATA_ID_FW_REV_OFS, sizeof(fw)); 2006 ata_id_c_string(id, fw, ATA_ID_FW_REV, sizeof(fw));
1967 2007
1968 if (strcmp(model, "Maxtor")) 2008 if (strcmp(model, "Maxtor"))
1969 return 1; 2009 return 1;
@@ -2661,7 +2701,7 @@ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc)
2661 * TODO: find out if we need to do more here to 2701 * TODO: find out if we need to do more here to
2662 * cover scatter/gather case. 2702 * cover scatter/gather case.
2663 */ 2703 */
2664 qc->nsect = scmd->request_bufflen / ATA_SECT_SIZE; 2704 qc->nbytes = scmd->request_bufflen;
2665 2705
2666 /* request result TF */ 2706 /* request result TF */
2667 qc->flags |= ATA_QCFLAG_RESULT_TF; 2707 qc->flags |= ATA_QCFLAG_RESULT_TF;
@@ -3059,7 +3099,8 @@ void ata_scsi_hotplug(struct work_struct *work)
3059 for (i = 0; i < ATA_MAX_DEVICES; i++) { 3099 for (i = 0; i < ATA_MAX_DEVICES; i++) {
3060 struct ata_device *dev = &ap->device[i]; 3100 struct ata_device *dev = &ap->device[i];
3061 if (ata_dev_enabled(dev) && !dev->sdev) { 3101 if (ata_dev_enabled(dev) && !dev->sdev) {
3062 queue_delayed_work(ata_aux_wq, &ap->hotplug_task, HZ); 3102 queue_delayed_work(ata_aux_wq, &ap->hotplug_task,
3103 round_jiffies_relative(HZ));
3063 break; 3104 break;
3064 } 3105 }
3065 } 3106 }
@@ -3264,7 +3305,8 @@ EXPORT_SYMBOL_GPL(ata_sas_port_init);
3264 3305
3265void ata_sas_port_destroy(struct ata_port *ap) 3306void ata_sas_port_destroy(struct ata_port *ap)
3266{ 3307{
3267 ap->ops->port_stop(ap); 3308 if (ap->ops->port_stop)
3309 ap->ops->port_stop(ap);
3268 kfree(ap); 3310 kfree(ap);
3269} 3311}
3270EXPORT_SYMBOL_GPL(ata_sas_port_destroy); 3312EXPORT_SYMBOL_GPL(ata_sas_port_destroy);
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index 12c88c58803..16bc3e35bdd 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -56,10 +56,7 @@ u8 ata_irq_on(struct ata_port *ap)
56 ap->ctl &= ~ATA_NIEN; 56 ap->ctl &= ~ATA_NIEN;
57 ap->last_ctl = ap->ctl; 57 ap->last_ctl = ap->ctl;
58 58
59 if (ap->flags & ATA_FLAG_MMIO) 59 iowrite8(ap->ctl, ioaddr->ctl_addr);
60 writeb(ap->ctl, (void __iomem *) ioaddr->ctl_addr);
61 else
62 outb(ap->ctl, ioaddr->ctl_addr);
63 tmp = ata_wait_idle(ap); 60 tmp = ata_wait_idle(ap);
64 61
65 ap->ops->irq_clear(ap); 62 ap->ops->irq_clear(ap);
@@ -67,92 +64,74 @@ u8 ata_irq_on(struct ata_port *ap)
67 return tmp; 64 return tmp;
68} 65}
69 66
67u8 ata_dummy_irq_on (struct ata_port *ap) { return 0; }
68
70/** 69/**
71 * ata_tf_load_pio - send taskfile registers to host controller 70 * ata_irq_ack - Acknowledge a device interrupt.
72 * @ap: Port to which output is sent 71 * @ap: Port on which interrupts are enabled.
73 * @tf: ATA taskfile register set
74 * 72 *
75 * Outputs ATA taskfile to standard ATA host controller. 73 * Wait up to 10 ms for legacy IDE device to become idle (BUSY
74 * or BUSY+DRQ clear). Obtain dma status and port status from
75 * device. Clear the interrupt. Return port status.
76 * 76 *
77 * LOCKING: 77 * LOCKING:
78 * Inherited from caller.
79 */ 78 */
80 79
81static void ata_tf_load_pio(struct ata_port *ap, const struct ata_taskfile *tf) 80u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq)
82{ 81{
83 struct ata_ioports *ioaddr = &ap->ioaddr; 82 unsigned int bits = chk_drq ? ATA_BUSY | ATA_DRQ : ATA_BUSY;
84 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; 83 u8 host_stat, post_stat, status;
85 84
86 if (tf->ctl != ap->last_ctl) { 85 status = ata_busy_wait(ap, bits, 1000);
87 outb(tf->ctl, ioaddr->ctl_addr); 86 if (status & bits)
88 ap->last_ctl = tf->ctl; 87 if (ata_msg_err(ap))
89 ata_wait_idle(ap); 88 printk(KERN_ERR "abnormal status 0x%X\n", status);
90 }
91 89
92 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { 90 /* get controller status; clear intr, err bits */
93 outb(tf->hob_feature, ioaddr->feature_addr); 91 host_stat = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
94 outb(tf->hob_nsect, ioaddr->nsect_addr); 92 iowrite8(host_stat | ATA_DMA_INTR | ATA_DMA_ERR,
95 outb(tf->hob_lbal, ioaddr->lbal_addr); 93 ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
96 outb(tf->hob_lbam, ioaddr->lbam_addr);
97 outb(tf->hob_lbah, ioaddr->lbah_addr);
98 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
99 tf->hob_feature,
100 tf->hob_nsect,
101 tf->hob_lbal,
102 tf->hob_lbam,
103 tf->hob_lbah);
104 }
105 94
106 if (is_addr) { 95 post_stat = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
107 outb(tf->feature, ioaddr->feature_addr);
108 outb(tf->nsect, ioaddr->nsect_addr);
109 outb(tf->lbal, ioaddr->lbal_addr);
110 outb(tf->lbam, ioaddr->lbam_addr);
111 outb(tf->lbah, ioaddr->lbah_addr);
112 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
113 tf->feature,
114 tf->nsect,
115 tf->lbal,
116 tf->lbam,
117 tf->lbah);
118 }
119 96
120 if (tf->flags & ATA_TFLAG_DEVICE) { 97 if (ata_msg_intr(ap))
121 outb(tf->device, ioaddr->device_addr); 98 printk(KERN_INFO "%s: irq ack: host_stat 0x%X, new host_stat 0x%X, drv_stat 0x%X\n",
122 VPRINTK("device 0x%X\n", tf->device); 99 __FUNCTION__,
123 } 100 host_stat, post_stat, status);
124 101
125 ata_wait_idle(ap); 102 return status;
126} 103}
127 104
105u8 ata_dummy_irq_ack(struct ata_port *ap, unsigned int chk_drq) { return 0; }
106
128/** 107/**
129 * ata_tf_load_mmio - send taskfile registers to host controller 108 * ata_tf_load - send taskfile registers to host controller
130 * @ap: Port to which output is sent 109 * @ap: Port to which output is sent
131 * @tf: ATA taskfile register set 110 * @tf: ATA taskfile register set
132 * 111 *
133 * Outputs ATA taskfile to standard ATA host controller using MMIO. 112 * Outputs ATA taskfile to standard ATA host controller.
134 * 113 *
135 * LOCKING: 114 * LOCKING:
136 * Inherited from caller. 115 * Inherited from caller.
137 */ 116 */
138 117
139static void ata_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf) 118void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
140{ 119{
141 struct ata_ioports *ioaddr = &ap->ioaddr; 120 struct ata_ioports *ioaddr = &ap->ioaddr;
142 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; 121 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
143 122
144 if (tf->ctl != ap->last_ctl) { 123 if (tf->ctl != ap->last_ctl) {
145 writeb(tf->ctl, (void __iomem *) ap->ioaddr.ctl_addr); 124 iowrite8(tf->ctl, ioaddr->ctl_addr);
146 ap->last_ctl = tf->ctl; 125 ap->last_ctl = tf->ctl;
147 ata_wait_idle(ap); 126 ata_wait_idle(ap);
148 } 127 }
149 128
150 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { 129 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
151 writeb(tf->hob_feature, (void __iomem *) ioaddr->feature_addr); 130 iowrite8(tf->hob_feature, ioaddr->feature_addr);
152 writeb(tf->hob_nsect, (void __iomem *) ioaddr->nsect_addr); 131 iowrite8(tf->hob_nsect, ioaddr->nsect_addr);
153 writeb(tf->hob_lbal, (void __iomem *) ioaddr->lbal_addr); 132 iowrite8(tf->hob_lbal, ioaddr->lbal_addr);
154 writeb(tf->hob_lbam, (void __iomem *) ioaddr->lbam_addr); 133 iowrite8(tf->hob_lbam, ioaddr->lbam_addr);
155 writeb(tf->hob_lbah, (void __iomem *) ioaddr->lbah_addr); 134 iowrite8(tf->hob_lbah, ioaddr->lbah_addr);
156 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n", 135 VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
157 tf->hob_feature, 136 tf->hob_feature,
158 tf->hob_nsect, 137 tf->hob_nsect,
@@ -162,11 +141,11 @@ static void ata_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
162 } 141 }
163 142
164 if (is_addr) { 143 if (is_addr) {
165 writeb(tf->feature, (void __iomem *) ioaddr->feature_addr); 144 iowrite8(tf->feature, ioaddr->feature_addr);
166 writeb(tf->nsect, (void __iomem *) ioaddr->nsect_addr); 145 iowrite8(tf->nsect, ioaddr->nsect_addr);
167 writeb(tf->lbal, (void __iomem *) ioaddr->lbal_addr); 146 iowrite8(tf->lbal, ioaddr->lbal_addr);
168 writeb(tf->lbam, (void __iomem *) ioaddr->lbam_addr); 147 iowrite8(tf->lbam, ioaddr->lbam_addr);
169 writeb(tf->lbah, (void __iomem *) ioaddr->lbah_addr); 148 iowrite8(tf->lbah, ioaddr->lbah_addr);
170 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n", 149 VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
171 tf->feature, 150 tf->feature,
172 tf->nsect, 151 tf->nsect,
@@ -176,108 +155,34 @@ static void ata_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
176 } 155 }
177 156
178 if (tf->flags & ATA_TFLAG_DEVICE) { 157 if (tf->flags & ATA_TFLAG_DEVICE) {
179 writeb(tf->device, (void __iomem *) ioaddr->device_addr); 158 iowrite8(tf->device, ioaddr->device_addr);
180 VPRINTK("device 0x%X\n", tf->device); 159 VPRINTK("device 0x%X\n", tf->device);
181 } 160 }
182 161
183 ata_wait_idle(ap); 162 ata_wait_idle(ap);
184} 163}
185 164
186
187/**
188 * ata_tf_load - send taskfile registers to host controller
189 * @ap: Port to which output is sent
190 * @tf: ATA taskfile register set
191 *
192 * Outputs ATA taskfile to standard ATA host controller using MMIO
193 * or PIO as indicated by the ATA_FLAG_MMIO flag.
194 * Writes the control, feature, nsect, lbal, lbam, and lbah registers.
195 * Optionally (ATA_TFLAG_LBA48) writes hob_feature, hob_nsect,
196 * hob_lbal, hob_lbam, and hob_lbah.
197 *
198 * This function waits for idle (!BUSY and !DRQ) after writing
199 * registers. If the control register has a new value, this
200 * function also waits for idle after writing control and before
201 * writing the remaining registers.
202 *
203 * May be used as the tf_load() entry in ata_port_operations.
204 *
205 * LOCKING:
206 * Inherited from caller.
207 */
208void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
209{
210 if (ap->flags & ATA_FLAG_MMIO)
211 ata_tf_load_mmio(ap, tf);
212 else
213 ata_tf_load_pio(ap, tf);
214}
215
216/** 165/**
217 * ata_exec_command_pio - issue ATA command to host controller 166 * ata_exec_command - issue ATA command to host controller
218 * @ap: port to which command is being issued
219 * @tf: ATA taskfile register set
220 *
221 * Issues PIO write to ATA command register, with proper
222 * synchronization with interrupt handler / other threads.
223 *
224 * LOCKING:
225 * spin_lock_irqsave(host lock)
226 */
227
228static void ata_exec_command_pio(struct ata_port *ap, const struct ata_taskfile *tf)
229{
230 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command);
231
232 outb(tf->command, ap->ioaddr.command_addr);
233 ata_pause(ap);
234}
235
236
237/**
238 * ata_exec_command_mmio - issue ATA command to host controller
239 * @ap: port to which command is being issued 167 * @ap: port to which command is being issued
240 * @tf: ATA taskfile register set 168 * @tf: ATA taskfile register set
241 * 169 *
242 * Issues MMIO write to ATA command register, with proper 170 * Issues ATA command, with proper synchronization with interrupt
243 * synchronization with interrupt handler / other threads. 171 * handler / other threads.
244 *
245 * FIXME: missing write posting for 400nS delay enforcement
246 * 172 *
247 * LOCKING: 173 * LOCKING:
248 * spin_lock_irqsave(host lock) 174 * spin_lock_irqsave(host lock)
249 */ 175 */
250 176void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
251static void ata_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf)
252{ 177{
253 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command); 178 DPRINTK("ata%u: cmd 0x%X\n", ap->id, tf->command);
254 179
255 writeb(tf->command, (void __iomem *) ap->ioaddr.command_addr); 180 iowrite8(tf->command, ap->ioaddr.command_addr);
256 ata_pause(ap); 181 ata_pause(ap);
257} 182}
258 183
259
260/**
261 * ata_exec_command - issue ATA command to host controller
262 * @ap: port to which command is being issued
263 * @tf: ATA taskfile register set
264 *
265 * Issues PIO/MMIO write to ATA command register, with proper
266 * synchronization with interrupt handler / other threads.
267 *
268 * LOCKING:
269 * spin_lock_irqsave(host lock)
270 */
271void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
272{
273 if (ap->flags & ATA_FLAG_MMIO)
274 ata_exec_command_mmio(ap, tf);
275 else
276 ata_exec_command_pio(ap, tf);
277}
278
279/** 184/**
280 * ata_tf_read_pio - input device's ATA taskfile shadow registers 185 * ata_tf_read - input device's ATA taskfile shadow registers
281 * @ap: Port from which input is read 186 * @ap: Port from which input is read
282 * @tf: ATA taskfile register set for storing input 187 * @tf: ATA taskfile register set for storing input
283 * 188 *
@@ -287,121 +192,28 @@ void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf)
287 * LOCKING: 192 * LOCKING:
288 * Inherited from caller. 193 * Inherited from caller.
289 */ 194 */
290 195void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
291static void ata_tf_read_pio(struct ata_port *ap, struct ata_taskfile *tf)
292{
293 struct ata_ioports *ioaddr = &ap->ioaddr;
294
295 tf->command = ata_check_status(ap);
296 tf->feature = inb(ioaddr->error_addr);
297 tf->nsect = inb(ioaddr->nsect_addr);
298 tf->lbal = inb(ioaddr->lbal_addr);
299 tf->lbam = inb(ioaddr->lbam_addr);
300 tf->lbah = inb(ioaddr->lbah_addr);
301 tf->device = inb(ioaddr->device_addr);
302
303 if (tf->flags & ATA_TFLAG_LBA48) {
304 outb(tf->ctl | ATA_HOB, ioaddr->ctl_addr);
305 tf->hob_feature = inb(ioaddr->error_addr);
306 tf->hob_nsect = inb(ioaddr->nsect_addr);
307 tf->hob_lbal = inb(ioaddr->lbal_addr);
308 tf->hob_lbam = inb(ioaddr->lbam_addr);
309 tf->hob_lbah = inb(ioaddr->lbah_addr);
310 }
311}
312
313/**
314 * ata_tf_read_mmio - input device's ATA taskfile shadow registers
315 * @ap: Port from which input is read
316 * @tf: ATA taskfile register set for storing input
317 *
318 * Reads ATA taskfile registers for currently-selected device
319 * into @tf via MMIO.
320 *
321 * LOCKING:
322 * Inherited from caller.
323 */
324
325static void ata_tf_read_mmio(struct ata_port *ap, struct ata_taskfile *tf)
326{ 196{
327 struct ata_ioports *ioaddr = &ap->ioaddr; 197 struct ata_ioports *ioaddr = &ap->ioaddr;
328 198
329 tf->command = ata_check_status(ap); 199 tf->command = ata_check_status(ap);
330 tf->feature = readb((void __iomem *)ioaddr->error_addr); 200 tf->feature = ioread8(ioaddr->error_addr);
331 tf->nsect = readb((void __iomem *)ioaddr->nsect_addr); 201 tf->nsect = ioread8(ioaddr->nsect_addr);
332 tf->lbal = readb((void __iomem *)ioaddr->lbal_addr); 202 tf->lbal = ioread8(ioaddr->lbal_addr);
333 tf->lbam = readb((void __iomem *)ioaddr->lbam_addr); 203 tf->lbam = ioread8(ioaddr->lbam_addr);
334 tf->lbah = readb((void __iomem *)ioaddr->lbah_addr); 204 tf->lbah = ioread8(ioaddr->lbah_addr);
335 tf->device = readb((void __iomem *)ioaddr->device_addr); 205 tf->device = ioread8(ioaddr->device_addr);
336 206
337 if (tf->flags & ATA_TFLAG_LBA48) { 207 if (tf->flags & ATA_TFLAG_LBA48) {
338 writeb(tf->ctl | ATA_HOB, (void __iomem *) ap->ioaddr.ctl_addr); 208 iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr);
339 tf->hob_feature = readb((void __iomem *)ioaddr->error_addr); 209 tf->hob_feature = ioread8(ioaddr->error_addr);
340 tf->hob_nsect = readb((void __iomem *)ioaddr->nsect_addr); 210 tf->hob_nsect = ioread8(ioaddr->nsect_addr);
341 tf->hob_lbal = readb((void __iomem *)ioaddr->lbal_addr); 211 tf->hob_lbal = ioread8(ioaddr->lbal_addr);
342 tf->hob_lbam = readb((void __iomem *)ioaddr->lbam_addr); 212 tf->hob_lbam = ioread8(ioaddr->lbam_addr);
343 tf->hob_lbah = readb((void __iomem *)ioaddr->lbah_addr); 213 tf->hob_lbah = ioread8(ioaddr->lbah_addr);
344 } 214 }
345} 215}
346 216
347
348/**
349 * ata_tf_read - input device's ATA taskfile shadow registers
350 * @ap: Port from which input is read
351 * @tf: ATA taskfile register set for storing input
352 *
353 * Reads ATA taskfile registers for currently-selected device
354 * into @tf.
355 *
356 * Reads nsect, lbal, lbam, lbah, and device. If ATA_TFLAG_LBA48
357 * is set, also reads the hob registers.
358 *
359 * May be used as the tf_read() entry in ata_port_operations.
360 *
361 * LOCKING:
362 * Inherited from caller.
363 */
364void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
365{
366 if (ap->flags & ATA_FLAG_MMIO)
367 ata_tf_read_mmio(ap, tf);
368 else
369 ata_tf_read_pio(ap, tf);
370}
371
372/**
373 * ata_check_status_pio - Read device status reg & clear interrupt
374 * @ap: port where the device is
375 *
376 * Reads ATA taskfile status register for currently-selected device
377 * and return its value. This also clears pending interrupts
378 * from this device
379 *
380 * LOCKING:
381 * Inherited from caller.
382 */
383static u8 ata_check_status_pio(struct ata_port *ap)
384{
385 return inb(ap->ioaddr.status_addr);
386}
387
388/**
389 * ata_check_status_mmio - Read device status reg & clear interrupt
390 * @ap: port where the device is
391 *
392 * Reads ATA taskfile status register for currently-selected device
393 * via MMIO and return its value. This also clears pending interrupts
394 * from this device
395 *
396 * LOCKING:
397 * Inherited from caller.
398 */
399static u8 ata_check_status_mmio(struct ata_port *ap)
400{
401 return readb((void __iomem *) ap->ioaddr.status_addr);
402}
403
404
405/** 217/**
406 * ata_check_status - Read device status reg & clear interrupt 218 * ata_check_status - Read device status reg & clear interrupt
407 * @ap: port where the device is 219 * @ap: port where the device is
@@ -410,19 +222,14 @@ static u8 ata_check_status_mmio(struct ata_port *ap)
410 * and return its value. This also clears pending interrupts 222 * and return its value. This also clears pending interrupts
411 * from this device 223 * from this device
412 * 224 *
413 * May be used as the check_status() entry in ata_port_operations.
414 *
415 * LOCKING: 225 * LOCKING:
416 * Inherited from caller. 226 * Inherited from caller.
417 */ 227 */
418u8 ata_check_status(struct ata_port *ap) 228u8 ata_check_status(struct ata_port *ap)
419{ 229{
420 if (ap->flags & ATA_FLAG_MMIO) 230 return ioread8(ap->ioaddr.status_addr);
421 return ata_check_status_mmio(ap);
422 return ata_check_status_pio(ap);
423} 231}
424 232
425
426/** 233/**
427 * ata_altstatus - Read device alternate status reg 234 * ata_altstatus - Read device alternate status reg
428 * @ap: port where the device is 235 * @ap: port where the device is
@@ -441,58 +248,52 @@ u8 ata_altstatus(struct ata_port *ap)
441 if (ap->ops->check_altstatus) 248 if (ap->ops->check_altstatus)
442 return ap->ops->check_altstatus(ap); 249 return ap->ops->check_altstatus(ap);
443 250
444 if (ap->flags & ATA_FLAG_MMIO) 251 return ioread8(ap->ioaddr.altstatus_addr);
445 return readb((void __iomem *)ap->ioaddr.altstatus_addr);
446 return inb(ap->ioaddr.altstatus_addr);
447} 252}
448 253
449/** 254/**
450 * ata_bmdma_setup_mmio - Set up PCI IDE BMDMA transaction 255 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
451 * @qc: Info associated with this ATA transaction. 256 * @qc: Info associated with this ATA transaction.
452 * 257 *
453 * LOCKING: 258 * LOCKING:
454 * spin_lock_irqsave(host lock) 259 * spin_lock_irqsave(host lock)
455 */ 260 */
456 261void ata_bmdma_setup(struct ata_queued_cmd *qc)
457static void ata_bmdma_setup_mmio (struct ata_queued_cmd *qc)
458{ 262{
459 struct ata_port *ap = qc->ap; 263 struct ata_port *ap = qc->ap;
460 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); 264 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
461 u8 dmactl; 265 u8 dmactl;
462 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
463 266
464 /* load PRD table addr. */ 267 /* load PRD table addr. */
465 mb(); /* make sure PRD table writes are visible to controller */ 268 mb(); /* make sure PRD table writes are visible to controller */
466 writel(ap->prd_dma, mmio + ATA_DMA_TABLE_OFS); 269 iowrite32(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
467 270
468 /* specify data direction, triple-check start bit is clear */ 271 /* specify data direction, triple-check start bit is clear */
469 dmactl = readb(mmio + ATA_DMA_CMD); 272 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
470 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START); 273 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
471 if (!rw) 274 if (!rw)
472 dmactl |= ATA_DMA_WR; 275 dmactl |= ATA_DMA_WR;
473 writeb(dmactl, mmio + ATA_DMA_CMD); 276 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
474 277
475 /* issue r/w command */ 278 /* issue r/w command */
476 ap->ops->exec_command(ap, &qc->tf); 279 ap->ops->exec_command(ap, &qc->tf);
477} 280}
478 281
479/** 282/**
480 * ata_bmdma_start_mmio - Start a PCI IDE BMDMA transaction 283 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
481 * @qc: Info associated with this ATA transaction. 284 * @qc: Info associated with this ATA transaction.
482 * 285 *
483 * LOCKING: 286 * LOCKING:
484 * spin_lock_irqsave(host lock) 287 * spin_lock_irqsave(host lock)
485 */ 288 */
486 289void ata_bmdma_start (struct ata_queued_cmd *qc)
487static void ata_bmdma_start_mmio (struct ata_queued_cmd *qc)
488{ 290{
489 struct ata_port *ap = qc->ap; 291 struct ata_port *ap = qc->ap;
490 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
491 u8 dmactl; 292 u8 dmactl;
492 293
493 /* start host DMA transaction */ 294 /* start host DMA transaction */
494 dmactl = readb(mmio + ATA_DMA_CMD); 295 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
495 writeb(dmactl | ATA_DMA_START, mmio + ATA_DMA_CMD); 296 iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
496 297
497 /* Strictly, one may wish to issue a readb() here, to 298 /* Strictly, one may wish to issue a readb() here, to
498 * flush the mmio write. However, control also passes 299 * flush the mmio write. However, control also passes
@@ -508,96 +309,6 @@ static void ata_bmdma_start_mmio (struct ata_queued_cmd *qc)
508} 309}
509 310
510/** 311/**
511 * ata_bmdma_setup_pio - Set up PCI IDE BMDMA transaction (PIO)
512 * @qc: Info associated with this ATA transaction.
513 *
514 * LOCKING:
515 * spin_lock_irqsave(host lock)
516 */
517
518static void ata_bmdma_setup_pio (struct ata_queued_cmd *qc)
519{
520 struct ata_port *ap = qc->ap;
521 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
522 u8 dmactl;
523
524 /* load PRD table addr. */
525 outl(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
526
527 /* specify data direction, triple-check start bit is clear */
528 dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
529 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
530 if (!rw)
531 dmactl |= ATA_DMA_WR;
532 outb(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
533
534 /* issue r/w command */
535 ap->ops->exec_command(ap, &qc->tf);
536}
537
538/**
539 * ata_bmdma_start_pio - Start a PCI IDE BMDMA transaction (PIO)
540 * @qc: Info associated with this ATA transaction.
541 *
542 * LOCKING:
543 * spin_lock_irqsave(host lock)
544 */
545
546static void ata_bmdma_start_pio (struct ata_queued_cmd *qc)
547{
548 struct ata_port *ap = qc->ap;
549 u8 dmactl;
550
551 /* start host DMA transaction */
552 dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
553 outb(dmactl | ATA_DMA_START,
554 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
555}
556
557
558/**
559 * ata_bmdma_start - Start a PCI IDE BMDMA transaction
560 * @qc: Info associated with this ATA transaction.
561 *
562 * Writes the ATA_DMA_START flag to the DMA command register.
563 *
564 * May be used as the bmdma_start() entry in ata_port_operations.
565 *
566 * LOCKING:
567 * spin_lock_irqsave(host lock)
568 */
569void ata_bmdma_start(struct ata_queued_cmd *qc)
570{
571 if (qc->ap->flags & ATA_FLAG_MMIO)
572 ata_bmdma_start_mmio(qc);
573 else
574 ata_bmdma_start_pio(qc);
575}
576
577
578/**
579 * ata_bmdma_setup - Set up PCI IDE BMDMA transaction
580 * @qc: Info associated with this ATA transaction.
581 *
582 * Writes address of PRD table to device's PRD Table Address
583 * register, sets the DMA control register, and calls
584 * ops->exec_command() to start the transfer.
585 *
586 * May be used as the bmdma_setup() entry in ata_port_operations.
587 *
588 * LOCKING:
589 * spin_lock_irqsave(host lock)
590 */
591void ata_bmdma_setup(struct ata_queued_cmd *qc)
592{
593 if (qc->ap->flags & ATA_FLAG_MMIO)
594 ata_bmdma_setup_mmio(qc);
595 else
596 ata_bmdma_setup_pio(qc);
597}
598
599
600/**
601 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt. 312 * ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt.
602 * @ap: Port associated with this ATA transaction. 313 * @ap: Port associated with this ATA transaction.
603 * 314 *
@@ -608,23 +319,16 @@ void ata_bmdma_setup(struct ata_queued_cmd *qc)
608 * LOCKING: 319 * LOCKING:
609 * spin_lock_irqsave(host lock) 320 * spin_lock_irqsave(host lock)
610 */ 321 */
611
612void ata_bmdma_irq_clear(struct ata_port *ap) 322void ata_bmdma_irq_clear(struct ata_port *ap)
613{ 323{
614 if (!ap->ioaddr.bmdma_addr) 324 void __iomem *mmio = ap->ioaddr.bmdma_addr;
325
326 if (!mmio)
615 return; 327 return;
616 328
617 if (ap->flags & ATA_FLAG_MMIO) { 329 iowrite8(ioread8(mmio + ATA_DMA_STATUS), mmio + ATA_DMA_STATUS);
618 void __iomem *mmio =
619 ((void __iomem *) ap->ioaddr.bmdma_addr) + ATA_DMA_STATUS;
620 writeb(readb(mmio), mmio);
621 } else {
622 unsigned long addr = ap->ioaddr.bmdma_addr + ATA_DMA_STATUS;
623 outb(inb(addr), addr);
624 }
625} 330}
626 331
627
628/** 332/**
629 * ata_bmdma_status - Read PCI IDE BMDMA status 333 * ata_bmdma_status - Read PCI IDE BMDMA status
630 * @ap: Port associated with this ATA transaction. 334 * @ap: Port associated with this ATA transaction.
@@ -636,19 +340,11 @@ void ata_bmdma_irq_clear(struct ata_port *ap)
636 * LOCKING: 340 * LOCKING:
637 * spin_lock_irqsave(host lock) 341 * spin_lock_irqsave(host lock)
638 */ 342 */
639
640u8 ata_bmdma_status(struct ata_port *ap) 343u8 ata_bmdma_status(struct ata_port *ap)
641{ 344{
642 u8 host_stat; 345 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
643 if (ap->flags & ATA_FLAG_MMIO) {
644 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
645 host_stat = readb(mmio + ATA_DMA_STATUS);
646 } else
647 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
648 return host_stat;
649} 346}
650 347
651
652/** 348/**
653 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer 349 * ata_bmdma_stop - Stop PCI IDE BMDMA transfer
654 * @qc: Command we are ending DMA for 350 * @qc: Command we are ending DMA for
@@ -660,21 +356,14 @@ u8 ata_bmdma_status(struct ata_port *ap)
660 * LOCKING: 356 * LOCKING:
661 * spin_lock_irqsave(host lock) 357 * spin_lock_irqsave(host lock)
662 */ 358 */
663
664void ata_bmdma_stop(struct ata_queued_cmd *qc) 359void ata_bmdma_stop(struct ata_queued_cmd *qc)
665{ 360{
666 struct ata_port *ap = qc->ap; 361 struct ata_port *ap = qc->ap;
667 if (ap->flags & ATA_FLAG_MMIO) { 362 void __iomem *mmio = ap->ioaddr.bmdma_addr;
668 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
669 363
670 /* clear start/stop bit */ 364 /* clear start/stop bit */
671 writeb(readb(mmio + ATA_DMA_CMD) & ~ATA_DMA_START, 365 iowrite8(ioread8(mmio + ATA_DMA_CMD) & ~ATA_DMA_START,
672 mmio + ATA_DMA_CMD); 366 mmio + ATA_DMA_CMD);
673 } else {
674 /* clear start/stop bit */
675 outb(inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD) & ~ATA_DMA_START,
676 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
677 }
678 367
679 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ 368 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
680 ata_altstatus(ap); /* dummy read */ 369 ata_altstatus(ap); /* dummy read */
@@ -696,10 +385,7 @@ void ata_bmdma_freeze(struct ata_port *ap)
696 ap->ctl |= ATA_NIEN; 385 ap->ctl |= ATA_NIEN;
697 ap->last_ctl = ap->ctl; 386 ap->last_ctl = ap->ctl;
698 387
699 if (ap->flags & ATA_FLAG_MMIO) 388 iowrite8(ap->ctl, ioaddr->ctl_addr);
700 writeb(ap->ctl, (void __iomem *)ioaddr->ctl_addr);
701 else
702 outb(ap->ctl, ioaddr->ctl_addr);
703 389
704 /* Under certain circumstances, some controllers raise IRQ on 390 /* Under certain circumstances, some controllers raise IRQ on
705 * ATA_NIEN manipulation. Also, many controllers fail to mask 391 * ATA_NIEN manipulation. Also, many controllers fail to mask
@@ -724,8 +410,7 @@ void ata_bmdma_thaw(struct ata_port *ap)
724 /* clear & re-enable interrupts */ 410 /* clear & re-enable interrupts */
725 ata_chk_status(ap); 411 ata_chk_status(ap);
726 ap->ops->irq_clear(ap); 412 ap->ops->irq_clear(ap);
727 if (ap->ioaddr.ctl_addr) /* FIXME: hack. create a hook instead */ 413 ap->ops->irq_on(ap);
728 ata_irq_on(ap);
729} 414}
730 415
731/** 416/**
@@ -775,7 +460,7 @@ void ata_bmdma_drive_eh(struct ata_port *ap, ata_prereset_fn_t prereset,
775 * really a timeout event, adjust error mask and 460 * really a timeout event, adjust error mask and
776 * cancel frozen state. 461 * cancel frozen state.
777 */ 462 */
778 if (qc->err_mask == AC_ERR_TIMEOUT && host_stat & ATA_DMA_ERR) { 463 if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) {
779 qc->err_mask = AC_ERR_HOST_BUS; 464 qc->err_mask = AC_ERR_HOST_BUS;
780 thaw = 1; 465 thaw = 1;
781 } 466 }
@@ -832,6 +517,21 @@ void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc)
832} 517}
833 518
834#ifdef CONFIG_PCI 519#ifdef CONFIG_PCI
520
521static int ata_resources_present(struct pci_dev *pdev, int port)
522{
523 int i;
524
525 /* Check the PCI resources for this channel are enabled */
526 port = port * 2;
527 for (i = 0; i < 2; i ++) {
528 if (pci_resource_start(pdev, port + i) == 0 ||
529 pci_resource_len(pdev, port + i) == 0)
530 return 0;
531 }
532 return 1;
533}
534
835/** 535/**
836 * ata_pci_init_native_mode - Initialize native-mode driver 536 * ata_pci_init_native_mode - Initialize native-mode driver
837 * @pdev: pci device to be initialized 537 * @pdev: pci device to be initialized
@@ -853,45 +553,62 @@ void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc)
853struct ata_probe_ent * 553struct ata_probe_ent *
854ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ports) 554ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int ports)
855{ 555{
856 struct ata_probe_ent *probe_ent = 556 struct ata_probe_ent *probe_ent;
857 ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); 557 int i, p = 0;
858 int p = 0; 558 void __iomem * const *iomap;
859 unsigned long bmdma; 559
560 /* iomap BARs */
561 for (i = 0; i < 4; i++) {
562 if (pcim_iomap(pdev, i, 0) == NULL) {
563 dev_printk(KERN_ERR, &pdev->dev,
564 "failed to iomap PCI BAR %d\n", i);
565 return NULL;
566 }
567 }
860 568
569 pcim_iomap(pdev, 4, 0); /* may fail */
570 iomap = pcim_iomap_table(pdev);
571
572 /* alloc and init probe_ent */
573 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
861 if (!probe_ent) 574 if (!probe_ent)
862 return NULL; 575 return NULL;
863 576
864 probe_ent->irq = pdev->irq; 577 probe_ent->irq = pdev->irq;
865 probe_ent->irq_flags = IRQF_SHARED; 578 probe_ent->irq_flags = IRQF_SHARED;
579
580 /* Discard disabled ports. Some controllers show their
581 unused channels this way */
582 if (ata_resources_present(pdev, 0) == 0)
583 ports &= ~ATA_PORT_PRIMARY;
584 if (ata_resources_present(pdev, 1) == 0)
585 ports &= ~ATA_PORT_SECONDARY;
866 586
867 if (ports & ATA_PORT_PRIMARY) { 587 if (ports & ATA_PORT_PRIMARY) {
868 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 0); 588 probe_ent->port[p].cmd_addr = iomap[0];
869 probe_ent->port[p].altstatus_addr = 589 probe_ent->port[p].altstatus_addr =
870 probe_ent->port[p].ctl_addr = 590 probe_ent->port[p].ctl_addr = (void __iomem *)
871 pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS; 591 ((unsigned long)iomap[1] | ATA_PCI_CTL_OFS);
872 bmdma = pci_resource_start(pdev, 4); 592 if (iomap[4]) {
873 if (bmdma) {
874 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) && 593 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
875 (inb(bmdma + 2) & 0x80)) 594 (ioread8(iomap[4] + 2) & 0x80))
876 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 595 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
877 probe_ent->port[p].bmdma_addr = bmdma; 596 probe_ent->port[p].bmdma_addr = iomap[4];
878 } 597 }
879 ata_std_ports(&probe_ent->port[p]); 598 ata_std_ports(&probe_ent->port[p]);
880 p++; 599 p++;
881 } 600 }
882 601
883 if (ports & ATA_PORT_SECONDARY) { 602 if (ports & ATA_PORT_SECONDARY) {
884 probe_ent->port[p].cmd_addr = pci_resource_start(pdev, 2); 603 probe_ent->port[p].cmd_addr = iomap[2];
885 probe_ent->port[p].altstatus_addr = 604 probe_ent->port[p].altstatus_addr =
886 probe_ent->port[p].ctl_addr = 605 probe_ent->port[p].ctl_addr = (void __iomem *)
887 pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS; 606 ((unsigned long)iomap[3] | ATA_PCI_CTL_OFS);
888 bmdma = pci_resource_start(pdev, 4); 607 if (iomap[4]) {
889 if (bmdma) {
890 bmdma += 8;
891 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) && 608 if ((!(port[p]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
892 (inb(bmdma + 2) & 0x80)) 609 (ioread8(iomap[4] + 10) & 0x80))
893 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 610 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
894 probe_ent->port[p].bmdma_addr = bmdma; 611 probe_ent->port[p].bmdma_addr = iomap[4] + 8;
895 } 612 }
896 ata_std_ports(&probe_ent->port[p]); 613 ata_std_ports(&probe_ent->port[p]);
897 probe_ent->pinfo2 = port[1]; 614 probe_ent->pinfo2 = port[1];
@@ -902,13 +619,29 @@ ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int
902 return probe_ent; 619 return probe_ent;
903} 620}
904 621
905
906static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev, 622static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
907 struct ata_port_info **port, int port_mask) 623 struct ata_port_info **port, int port_mask)
908{ 624{
909 struct ata_probe_ent *probe_ent; 625 struct ata_probe_ent *probe_ent;
910 unsigned long bmdma = pci_resource_start(pdev, 4); 626 void __iomem *iomap[5] = { }, *bmdma;
627
628 if (port_mask & ATA_PORT_PRIMARY) {
629 iomap[0] = devm_ioport_map(&pdev->dev, ATA_PRIMARY_CMD, 8);
630 iomap[1] = devm_ioport_map(&pdev->dev, ATA_PRIMARY_CTL, 1);
631 if (!iomap[0] || !iomap[1])
632 return NULL;
633 }
634
635 if (port_mask & ATA_PORT_SECONDARY) {
636 iomap[2] = devm_ioport_map(&pdev->dev, ATA_SECONDARY_CMD, 8);
637 iomap[3] = devm_ioport_map(&pdev->dev, ATA_SECONDARY_CTL, 1);
638 if (!iomap[2] || !iomap[3])
639 return NULL;
640 }
911 641
642 bmdma = pcim_iomap(pdev, 4, 16); /* may fail */
643
644 /* alloc and init probe_ent */
912 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]); 645 probe_ent = ata_probe_ent_alloc(pci_dev_to_dev(pdev), port[0]);
913 if (!probe_ent) 646 if (!probe_ent)
914 return NULL; 647 return NULL;
@@ -918,13 +651,13 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
918 651
919 if (port_mask & ATA_PORT_PRIMARY) { 652 if (port_mask & ATA_PORT_PRIMARY) {
920 probe_ent->irq = ATA_PRIMARY_IRQ(pdev); 653 probe_ent->irq = ATA_PRIMARY_IRQ(pdev);
921 probe_ent->port[0].cmd_addr = ATA_PRIMARY_CMD; 654 probe_ent->port[0].cmd_addr = iomap[0];
922 probe_ent->port[0].altstatus_addr = 655 probe_ent->port[0].altstatus_addr =
923 probe_ent->port[0].ctl_addr = ATA_PRIMARY_CTL; 656 probe_ent->port[0].ctl_addr = iomap[1];
924 if (bmdma) { 657 if (bmdma) {
925 probe_ent->port[0].bmdma_addr = bmdma; 658 probe_ent->port[0].bmdma_addr = bmdma;
926 if ((!(port[0]->flags & ATA_FLAG_IGN_SIMPLEX)) && 659 if ((!(port[0]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
927 (inb(bmdma + 2) & 0x80)) 660 (ioread8(bmdma + 2) & 0x80))
928 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 661 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
929 } 662 }
930 ata_std_ports(&probe_ent->port[0]); 663 ata_std_ports(&probe_ent->port[0]);
@@ -936,13 +669,13 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
936 probe_ent->irq2 = ATA_SECONDARY_IRQ(pdev); 669 probe_ent->irq2 = ATA_SECONDARY_IRQ(pdev);
937 else 670 else
938 probe_ent->irq = ATA_SECONDARY_IRQ(pdev); 671 probe_ent->irq = ATA_SECONDARY_IRQ(pdev);
939 probe_ent->port[1].cmd_addr = ATA_SECONDARY_CMD; 672 probe_ent->port[1].cmd_addr = iomap[2];
940 probe_ent->port[1].altstatus_addr = 673 probe_ent->port[1].altstatus_addr =
941 probe_ent->port[1].ctl_addr = ATA_SECONDARY_CTL; 674 probe_ent->port[1].ctl_addr = iomap[3];
942 if (bmdma) { 675 if (bmdma) {
943 probe_ent->port[1].bmdma_addr = bmdma + 8; 676 probe_ent->port[1].bmdma_addr = bmdma + 8;
944 if ((!(port[1]->flags & ATA_FLAG_IGN_SIMPLEX)) && 677 if ((!(port[1]->flags & ATA_FLAG_IGN_SIMPLEX)) &&
945 (inb(bmdma + 10) & 0x80)) 678 (ioread8(bmdma + 10) & 0x80))
946 probe_ent->_host_flags |= ATA_HOST_SIMPLEX; 679 probe_ent->_host_flags |= ATA_HOST_SIMPLEX;
947 } 680 }
948 ata_std_ports(&probe_ent->port[1]); 681 ata_std_ports(&probe_ent->port[1]);
@@ -984,15 +717,18 @@ static struct ata_probe_ent *ata_pci_init_legacy_port(struct pci_dev *pdev,
984int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info, 717int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
985 unsigned int n_ports) 718 unsigned int n_ports)
986{ 719{
720 struct device *dev = &pdev->dev;
987 struct ata_probe_ent *probe_ent = NULL; 721 struct ata_probe_ent *probe_ent = NULL;
988 struct ata_port_info *port[2]; 722 struct ata_port_info *port[2];
989 u8 mask; 723 u8 mask;
990 unsigned int legacy_mode = 0; 724 unsigned int legacy_mode = 0;
991 int disable_dev_on_err = 1;
992 int rc; 725 int rc;
993 726
994 DPRINTK("ENTER\n"); 727 DPRINTK("ENTER\n");
995 728
729 if (!devres_open_group(dev, NULL, GFP_KERNEL))
730 return -ENOMEM;
731
996 BUG_ON(n_ports < 1 || n_ports > 2); 732 BUG_ON(n_ports < 1 || n_ports > 2);
997 733
998 port[0] = port_info[0]; 734 port[0] = port_info[0];
@@ -1009,9 +745,9 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1009 boot for the primary video which is BIOS enabled 745 boot for the primary video which is BIOS enabled
1010 */ 746 */
1011 747
1012 rc = pci_enable_device(pdev); 748 rc = pcim_enable_device(pdev);
1013 if (rc) 749 if (rc)
1014 return rc; 750 goto err_out;
1015 751
1016 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) { 752 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE) {
1017 u8 tmp8; 753 u8 tmp8;
@@ -1027,7 +763,8 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1027 left a device in compatibility mode */ 763 left a device in compatibility mode */
1028 if (legacy_mode) { 764 if (legacy_mode) {
1029 printk(KERN_ERR "ata: Compatibility mode ATA is not supported on this platform, skipping.\n"); 765 printk(KERN_ERR "ata: Compatibility mode ATA is not supported on this platform, skipping.\n");
1030 return -EOPNOTSUPP; 766 rc = -EOPNOTSUPP;
767 goto err_out;
1031 } 768 }
1032#endif 769#endif
1033 } 770 }
@@ -1035,13 +772,13 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1035 if (!legacy_mode) { 772 if (!legacy_mode) {
1036 rc = pci_request_regions(pdev, DRV_NAME); 773 rc = pci_request_regions(pdev, DRV_NAME);
1037 if (rc) { 774 if (rc) {
1038 disable_dev_on_err = 0; 775 pcim_pin_device(pdev);
1039 goto err_out; 776 goto err_out;
1040 } 777 }
1041 } else { 778 } else {
1042 /* Deal with combined mode hack. This side of the logic all 779 /* Deal with combined mode hack. This side of the logic all
1043 goes away once the combined mode hack is killed in 2.6.21 */ 780 goes away once the combined mode hack is killed in 2.6.21 */
1044 if (!request_region(ATA_PRIMARY_CMD, 8, "libata")) { 781 if (!devm_request_region(dev, ATA_PRIMARY_CMD, 8, "libata")) {
1045 struct resource *conflict, res; 782 struct resource *conflict, res;
1046 res.start = ATA_PRIMARY_CMD; 783 res.start = ATA_PRIMARY_CMD;
1047 res.end = ATA_PRIMARY_CMD + 8 - 1; 784 res.end = ATA_PRIMARY_CMD + 8 - 1;
@@ -1051,7 +788,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1051 if (!strcmp(conflict->name, "libata")) 788 if (!strcmp(conflict->name, "libata"))
1052 legacy_mode |= ATA_PORT_PRIMARY; 789 legacy_mode |= ATA_PORT_PRIMARY;
1053 else { 790 else {
1054 disable_dev_on_err = 0; 791 pcim_pin_device(pdev);
1055 printk(KERN_WARNING "ata: 0x%0X IDE port busy\n" \ 792 printk(KERN_WARNING "ata: 0x%0X IDE port busy\n" \
1056 "ata: conflict with %s\n", 793 "ata: conflict with %s\n",
1057 ATA_PRIMARY_CMD, 794 ATA_PRIMARY_CMD,
@@ -1060,7 +797,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1060 } else 797 } else
1061 legacy_mode |= ATA_PORT_PRIMARY; 798 legacy_mode |= ATA_PORT_PRIMARY;
1062 799
1063 if (!request_region(ATA_SECONDARY_CMD, 8, "libata")) { 800 if (!devm_request_region(dev, ATA_SECONDARY_CMD, 8, "libata")) {
1064 struct resource *conflict, res; 801 struct resource *conflict, res;
1065 res.start = ATA_SECONDARY_CMD; 802 res.start = ATA_SECONDARY_CMD;
1066 res.end = ATA_SECONDARY_CMD + 8 - 1; 803 res.end = ATA_SECONDARY_CMD + 8 - 1;
@@ -1070,7 +807,7 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1070 if (!strcmp(conflict->name, "libata")) 807 if (!strcmp(conflict->name, "libata"))
1071 legacy_mode |= ATA_PORT_SECONDARY; 808 legacy_mode |= ATA_PORT_SECONDARY;
1072 else { 809 else {
1073 disable_dev_on_err = 0; 810 pcim_pin_device(pdev);
1074 printk(KERN_WARNING "ata: 0x%X IDE port busy\n" \ 811 printk(KERN_WARNING "ata: 0x%X IDE port busy\n" \
1075 "ata: conflict with %s\n", 812 "ata: conflict with %s\n",
1076 ATA_SECONDARY_CMD, 813 ATA_SECONDARY_CMD,
@@ -1090,16 +827,16 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1090 /* we have legacy mode, but all ports are unavailable */ 827 /* we have legacy mode, but all ports are unavailable */
1091 if (legacy_mode == (1 << 3)) { 828 if (legacy_mode == (1 << 3)) {
1092 rc = -EBUSY; 829 rc = -EBUSY;
1093 goto err_out_regions; 830 goto err_out;
1094 } 831 }
1095 832
1096 /* TODO: If we get no DMA mask we should fall back to PIO */ 833 /* TODO: If we get no DMA mask we should fall back to PIO */
1097 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 834 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
1098 if (rc) 835 if (rc)
1099 goto err_out_regions; 836 goto err_out;
1100 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 837 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
1101 if (rc) 838 if (rc)
1102 goto err_out_regions; 839 goto err_out;
1103 840
1104 if (legacy_mode) { 841 if (legacy_mode) {
1105 probe_ent = ata_pci_init_legacy_port(pdev, port, legacy_mode); 842 probe_ent = ata_pci_init_legacy_port(pdev, port, legacy_mode);
@@ -1111,40 +848,22 @@ int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_info,
1111 } 848 }
1112 if (!probe_ent) { 849 if (!probe_ent) {
1113 rc = -ENOMEM; 850 rc = -ENOMEM;
1114 goto err_out_regions; 851 goto err_out;
1115 } 852 }
1116 853
1117 pci_set_master(pdev); 854 pci_set_master(pdev);
1118 855
1119 if (!ata_device_add(probe_ent)) { 856 if (!ata_device_add(probe_ent)) {
1120 rc = -ENODEV; 857 rc = -ENODEV;
1121 goto err_out_ent; 858 goto err_out;
1122 } 859 }
1123 860
1124 kfree(probe_ent); 861 devm_kfree(dev, probe_ent);
1125 862 devres_remove_group(dev, NULL);
1126 return 0; 863 return 0;
1127 864
1128err_out_ent:
1129 kfree(probe_ent);
1130err_out_regions:
1131 /* All this conditional stuff is needed for the combined mode hack
1132 until 2.6.21 when it can go */
1133 if (legacy_mode) {
1134 pci_release_region(pdev, 4);
1135 if (legacy_mode & ATA_PORT_PRIMARY) {
1136 release_region(ATA_PRIMARY_CMD, 8);
1137 pci_release_region(pdev, 1);
1138 }
1139 if (legacy_mode & ATA_PORT_SECONDARY) {
1140 release_region(ATA_SECONDARY_CMD, 8);
1141 pci_release_region(pdev, 3);
1142 }
1143 } else
1144 pci_release_regions(pdev);
1145err_out: 865err_out:
1146 if (disable_dev_on_err) 866 devres_release_group(dev, NULL);
1147 pci_disable_device(pdev);
1148 return rc; 867 return rc;
1149} 868}
1150 869
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index 81ae41d5f23..06ccf230e3c 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -29,7 +29,6 @@
29#define __LIBATA_H__ 29#define __LIBATA_H__
30 30
31#define DRV_NAME "libata" 31#define DRV_NAME "libata"
32#define DRV_VERSION "2.00" /* must be exactly four chars */
33 32
34struct ata_scsi_args { 33struct ata_scsi_args {
35 struct ata_device *dev; 34 struct ata_device *dev;
@@ -136,4 +135,7 @@ extern void ata_qc_schedule_eh(struct ata_queued_cmd *qc);
136/* libata-sff.c */ 135/* libata-sff.c */
137extern u8 ata_irq_on(struct ata_port *ap); 136extern u8 ata_irq_on(struct ata_port *ap);
138 137
138/* pata_sis.c */
139extern struct ata_port_info sis_info133;
140
139#endif /* __LIBATA_H__ */ 141#endif /* __LIBATA_H__ */
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index c5d61d1911a..ab44d18850f 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -153,11 +153,11 @@ static void ali_early_error_handler(struct ata_port *ap)
153 153
154static unsigned long ali_20_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 154static unsigned long ali_20_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask)
155{ 155{
156 char model_num[40]; 156 char model_num[ATA_ID_PROD_LEN + 1];
157 /* No DMA on anything but a disk for now */ 157 /* No DMA on anything but a disk for now */
158 if (adev->class != ATA_DEV_ATA) 158 if (adev->class != ATA_DEV_ATA)
159 mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA); 159 mask &= ~(ATA_MASK_MWDMA | ATA_MASK_UDMA);
160 ata_id_string(adev->id, model_num, ATA_ID_PROD_OFS, sizeof(model_num)); 160 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
161 if (strstr(model_num, "WDC")) 161 if (strstr(model_num, "WDC"))
162 return mask &= ~ATA_MASK_UDMA; 162 return mask &= ~ATA_MASK_UDMA;
163 return ata_pci_default_filter(ap, adev, mask); 163 return ata_pci_default_filter(ap, adev, mask);
@@ -370,14 +370,14 @@ static struct ata_port_operations ali_early_port_ops = {
370 .qc_prep = ata_qc_prep, 370 .qc_prep = ata_qc_prep,
371 .qc_issue = ata_qc_issue_prot, 371 .qc_issue = ata_qc_issue_prot,
372 372
373 .data_xfer = ata_pio_data_xfer, 373 .data_xfer = ata_data_xfer,
374 374
375 .irq_handler = ata_interrupt, 375 .irq_handler = ata_interrupt,
376 .irq_clear = ata_bmdma_irq_clear, 376 .irq_clear = ata_bmdma_irq_clear,
377 .irq_on = ata_irq_on,
378 .irq_ack = ata_irq_ack,
377 379
378 .port_start = ata_port_start, 380 .port_start = ata_port_start,
379 .port_stop = ata_port_stop,
380 .host_stop = ata_host_stop
381}; 381};
382 382
383/* 383/*
@@ -411,14 +411,14 @@ static struct ata_port_operations ali_20_port_ops = {
411 .qc_prep = ata_qc_prep, 411 .qc_prep = ata_qc_prep,
412 .qc_issue = ata_qc_issue_prot, 412 .qc_issue = ata_qc_issue_prot,
413 413
414 .data_xfer = ata_pio_data_xfer, 414 .data_xfer = ata_data_xfer,
415 415
416 .irq_handler = ata_interrupt, 416 .irq_handler = ata_interrupt,
417 .irq_clear = ata_bmdma_irq_clear, 417 .irq_clear = ata_bmdma_irq_clear,
418 .irq_on = ata_irq_on,
419 .irq_ack = ata_irq_ack,
418 420
419 .port_start = ata_port_start, 421 .port_start = ata_port_start,
420 .port_stop = ata_port_stop,
421 .host_stop = ata_host_stop
422}; 422};
423 423
424/* 424/*
@@ -449,14 +449,14 @@ static struct ata_port_operations ali_c2_port_ops = {
449 .qc_prep = ata_qc_prep, 449 .qc_prep = ata_qc_prep,
450 .qc_issue = ata_qc_issue_prot, 450 .qc_issue = ata_qc_issue_prot,
451 451
452 .data_xfer = ata_pio_data_xfer, 452 .data_xfer = ata_data_xfer,
453 453
454 .irq_handler = ata_interrupt, 454 .irq_handler = ata_interrupt,
455 .irq_clear = ata_bmdma_irq_clear, 455 .irq_clear = ata_bmdma_irq_clear,
456 .irq_on = ata_irq_on,
457 .irq_ack = ata_irq_ack,
456 458
457 .port_start = ata_port_start, 459 .port_start = ata_port_start,
458 .port_stop = ata_port_stop,
459 .host_stop = ata_host_stop
460}; 460};
461 461
462/* 462/*
@@ -486,14 +486,14 @@ static struct ata_port_operations ali_c5_port_ops = {
486 .qc_prep = ata_qc_prep, 486 .qc_prep = ata_qc_prep,
487 .qc_issue = ata_qc_issue_prot, 487 .qc_issue = ata_qc_issue_prot,
488 488
489 .data_xfer = ata_pio_data_xfer, 489 .data_xfer = ata_data_xfer,
490 490
491 .irq_handler = ata_interrupt, 491 .irq_handler = ata_interrupt,
492 .irq_clear = ata_bmdma_irq_clear, 492 .irq_clear = ata_bmdma_irq_clear,
493 .irq_on = ata_irq_on,
494 .irq_ack = ata_irq_ack,
493 495
494 .port_start = ata_port_start, 496 .port_start = ata_port_start,
495 .port_stop = ata_port_stop,
496 .host_stop = ata_host_stop
497}; 497};
498 498
499 499
@@ -504,7 +504,7 @@ static struct ata_port_operations ali_c5_port_ops = {
504 * Perform the setup on the device that must be done both at boot 504 * Perform the setup on the device that must be done both at boot
505 * and at resume time. 505 * and at resume time.
506 */ 506 */
507 507
508static void ali_init_chipset(struct pci_dev *pdev) 508static void ali_init_chipset(struct pci_dev *pdev)
509{ 509{
510 u8 rev, tmp; 510 u8 rev, tmp;
@@ -655,7 +655,7 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
655 port_info[0] = port_info[1] = &info_c5; 655 port_info[0] = port_info[1] = &info_c5;
656 656
657 ali_init_chipset(pdev); 657 ali_init_chipset(pdev);
658 658
659 isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL); 659 isa_bridge = pci_get_device(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, NULL);
660 if (isa_bridge && rev >= 0x20 && rev < 0xC2) { 660 if (isa_bridge && rev >= 0x20 && rev < 0xC2) {
661 /* Are we paired with a UDMA capable chip */ 661 /* Are we paired with a UDMA capable chip */
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index a6b330089f2..619e44b0403 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -362,14 +362,14 @@ static struct ata_port_operations amd33_port_ops = {
362 .qc_prep = ata_qc_prep, 362 .qc_prep = ata_qc_prep,
363 .qc_issue = ata_qc_issue_prot, 363 .qc_issue = ata_qc_issue_prot,
364 364
365 .data_xfer = ata_pio_data_xfer, 365 .data_xfer = ata_data_xfer,
366 366
367 .irq_handler = ata_interrupt, 367 .irq_handler = ata_interrupt,
368 .irq_clear = ata_bmdma_irq_clear, 368 .irq_clear = ata_bmdma_irq_clear,
369 .irq_on = ata_irq_on,
370 .irq_ack = ata_irq_ack,
369 371
370 .port_start = ata_port_start, 372 .port_start = ata_port_start,
371 .port_stop = ata_port_stop,
372 .host_stop = ata_host_stop
373}; 373};
374 374
375static struct ata_port_operations amd66_port_ops = { 375static struct ata_port_operations amd66_port_ops = {
@@ -396,14 +396,14 @@ static struct ata_port_operations amd66_port_ops = {
396 .qc_prep = ata_qc_prep, 396 .qc_prep = ata_qc_prep,
397 .qc_issue = ata_qc_issue_prot, 397 .qc_issue = ata_qc_issue_prot,
398 398
399 .data_xfer = ata_pio_data_xfer, 399 .data_xfer = ata_data_xfer,
400 400
401 .irq_handler = ata_interrupt, 401 .irq_handler = ata_interrupt,
402 .irq_clear = ata_bmdma_irq_clear, 402 .irq_clear = ata_bmdma_irq_clear,
403 .irq_on = ata_irq_on,
404 .irq_ack = ata_irq_ack,
403 405
404 .port_start = ata_port_start, 406 .port_start = ata_port_start,
405 .port_stop = ata_port_stop,
406 .host_stop = ata_host_stop
407}; 407};
408 408
409static struct ata_port_operations amd100_port_ops = { 409static struct ata_port_operations amd100_port_ops = {
@@ -430,14 +430,14 @@ static struct ata_port_operations amd100_port_ops = {
430 .qc_prep = ata_qc_prep, 430 .qc_prep = ata_qc_prep,
431 .qc_issue = ata_qc_issue_prot, 431 .qc_issue = ata_qc_issue_prot,
432 432
433 .data_xfer = ata_pio_data_xfer, 433 .data_xfer = ata_data_xfer,
434 434
435 .irq_handler = ata_interrupt, 435 .irq_handler = ata_interrupt,
436 .irq_clear = ata_bmdma_irq_clear, 436 .irq_clear = ata_bmdma_irq_clear,
437 .irq_on = ata_irq_on,
438 .irq_ack = ata_irq_ack,
437 439
438 .port_start = ata_port_start, 440 .port_start = ata_port_start,
439 .port_stop = ata_port_stop,
440 .host_stop = ata_host_stop
441}; 441};
442 442
443static struct ata_port_operations amd133_port_ops = { 443static struct ata_port_operations amd133_port_ops = {
@@ -464,14 +464,14 @@ static struct ata_port_operations amd133_port_ops = {
464 .qc_prep = ata_qc_prep, 464 .qc_prep = ata_qc_prep,
465 .qc_issue = ata_qc_issue_prot, 465 .qc_issue = ata_qc_issue_prot,
466 466
467 .data_xfer = ata_pio_data_xfer, 467 .data_xfer = ata_data_xfer,
468 468
469 .irq_handler = ata_interrupt, 469 .irq_handler = ata_interrupt,
470 .irq_clear = ata_bmdma_irq_clear, 470 .irq_clear = ata_bmdma_irq_clear,
471 .irq_on = ata_irq_on,
472 .irq_ack = ata_irq_ack,
471 473
472 .port_start = ata_port_start, 474 .port_start = ata_port_start,
473 .port_stop = ata_port_stop,
474 .host_stop = ata_host_stop
475}; 475};
476 476
477static struct ata_port_operations nv100_port_ops = { 477static struct ata_port_operations nv100_port_ops = {
@@ -498,14 +498,14 @@ static struct ata_port_operations nv100_port_ops = {
498 .qc_prep = ata_qc_prep, 498 .qc_prep = ata_qc_prep,
499 .qc_issue = ata_qc_issue_prot, 499 .qc_issue = ata_qc_issue_prot,
500 500
501 .data_xfer = ata_pio_data_xfer, 501 .data_xfer = ata_data_xfer,
502 502
503 .irq_handler = ata_interrupt, 503 .irq_handler = ata_interrupt,
504 .irq_clear = ata_bmdma_irq_clear, 504 .irq_clear = ata_bmdma_irq_clear,
505 .irq_on = ata_irq_on,
506 .irq_ack = ata_irq_ack,
505 507
506 .port_start = ata_port_start, 508 .port_start = ata_port_start,
507 .port_stop = ata_port_stop,
508 .host_stop = ata_host_stop
509}; 509};
510 510
511static struct ata_port_operations nv133_port_ops = { 511static struct ata_port_operations nv133_port_ops = {
@@ -532,14 +532,14 @@ static struct ata_port_operations nv133_port_ops = {
532 .qc_prep = ata_qc_prep, 532 .qc_prep = ata_qc_prep,
533 .qc_issue = ata_qc_issue_prot, 533 .qc_issue = ata_qc_issue_prot,
534 534
535 .data_xfer = ata_pio_data_xfer, 535 .data_xfer = ata_data_xfer,
536 536
537 .irq_handler = ata_interrupt, 537 .irq_handler = ata_interrupt,
538 .irq_clear = ata_bmdma_irq_clear, 538 .irq_clear = ata_bmdma_irq_clear,
539 .irq_on = ata_irq_on,
540 .irq_ack = ata_irq_ack,
539 541
540 .port_start = ata_port_start, 542 .port_start = ata_port_start,
541 .port_stop = ata_port_stop,
542 .host_stop = ata_host_stop
543}; 543};
544 544
545static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 545static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
index 37bc1323bda..21c30282717 100644
--- a/drivers/ata/pata_artop.c
+++ b/drivers/ata/pata_artop.c
@@ -341,14 +341,14 @@ static const struct ata_port_operations artop6210_ops = {
341 .qc_prep = ata_qc_prep, 341 .qc_prep = ata_qc_prep,
342 .qc_issue = ata_qc_issue_prot, 342 .qc_issue = ata_qc_issue_prot,
343 343
344 .data_xfer = ata_pio_data_xfer, 344 .data_xfer = ata_data_xfer,
345 345
346 .irq_handler = ata_interrupt, 346 .irq_handler = ata_interrupt,
347 .irq_clear = ata_bmdma_irq_clear, 347 .irq_clear = ata_bmdma_irq_clear,
348 .irq_on = ata_irq_on,
349 .irq_ack = ata_irq_ack,
348 350
349 .port_start = ata_port_start, 351 .port_start = ata_port_start,
350 .port_stop = ata_port_stop,
351 .host_stop = ata_host_stop,
352}; 352};
353 353
354static const struct ata_port_operations artop6260_ops = { 354static const struct ata_port_operations artop6260_ops = {
@@ -373,14 +373,14 @@ static const struct ata_port_operations artop6260_ops = {
373 .bmdma_status = ata_bmdma_status, 373 .bmdma_status = ata_bmdma_status,
374 .qc_prep = ata_qc_prep, 374 .qc_prep = ata_qc_prep,
375 .qc_issue = ata_qc_issue_prot, 375 .qc_issue = ata_qc_issue_prot,
376 .data_xfer = ata_pio_data_xfer, 376 .data_xfer = ata_data_xfer,
377 377
378 .irq_handler = ata_interrupt, 378 .irq_handler = ata_interrupt,
379 .irq_clear = ata_bmdma_irq_clear, 379 .irq_clear = ata_bmdma_irq_clear,
380 .irq_on = ata_irq_on,
381 .irq_ack = ata_irq_ack,
380 382
381 .port_start = ata_port_start, 383 .port_start = ata_port_start,
382 .port_stop = ata_port_stop,
383 .host_stop = ata_host_stop,
384}; 384};
385 385
386 386
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index 504e1dbfffd..c3eb40c91c8 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -252,14 +252,14 @@ static struct ata_port_operations atiixp_port_ops = {
252 .qc_prep = ata_qc_prep, 252 .qc_prep = ata_qc_prep,
253 .qc_issue = ata_qc_issue_prot, 253 .qc_issue = ata_qc_issue_prot,
254 254
255 .data_xfer = ata_pio_data_xfer, 255 .data_xfer = ata_data_xfer,
256 256
257 .irq_handler = ata_interrupt, 257 .irq_handler = ata_interrupt,
258 .irq_clear = ata_bmdma_irq_clear, 258 .irq_clear = ata_bmdma_irq_clear,
259 .irq_on = ata_irq_on,
260 .irq_ack = ata_irq_ack,
259 261
260 .port_start = ata_port_start, 262 .port_start = ata_port_start,
261 .port_stop = ata_port_stop,
262 .host_stop = ata_host_stop
263}; 263};
264 264
265static int atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id) 265static int atiixp_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index 449162cbf93..da098282b5f 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -313,14 +313,14 @@ static struct ata_port_operations cmd64x_port_ops = {
313 .qc_prep = ata_qc_prep, 313 .qc_prep = ata_qc_prep,
314 .qc_issue = ata_qc_issue_prot, 314 .qc_issue = ata_qc_issue_prot,
315 315
316 .data_xfer = ata_pio_data_xfer, 316 .data_xfer = ata_data_xfer,
317 317
318 .irq_handler = ata_interrupt, 318 .irq_handler = ata_interrupt,
319 .irq_clear = ata_bmdma_irq_clear, 319 .irq_clear = ata_bmdma_irq_clear,
320 .irq_on = ata_irq_on,
321 .irq_ack = ata_irq_ack,
320 322
321 .port_start = ata_port_start, 323 .port_start = ata_port_start,
322 .port_stop = ata_port_stop,
323 .host_stop = ata_host_stop
324}; 324};
325 325
326static struct ata_port_operations cmd646r1_port_ops = { 326static struct ata_port_operations cmd646r1_port_ops = {
@@ -347,14 +347,14 @@ static struct ata_port_operations cmd646r1_port_ops = {
347 .qc_prep = ata_qc_prep, 347 .qc_prep = ata_qc_prep,
348 .qc_issue = ata_qc_issue_prot, 348 .qc_issue = ata_qc_issue_prot,
349 349
350 .data_xfer = ata_pio_data_xfer, 350 .data_xfer = ata_data_xfer,
351 351
352 .irq_handler = ata_interrupt, 352 .irq_handler = ata_interrupt,
353 .irq_clear = ata_bmdma_irq_clear, 353 .irq_clear = ata_bmdma_irq_clear,
354 .irq_on = ata_irq_on,
355 .irq_ack = ata_irq_ack,
354 356
355 .port_start = ata_port_start, 357 .port_start = ata_port_start,
356 .port_stop = ata_port_stop,
357 .host_stop = ata_host_stop
358}; 358};
359 359
360static struct ata_port_operations cmd648_port_ops = { 360static struct ata_port_operations cmd648_port_ops = {
@@ -381,14 +381,14 @@ static struct ata_port_operations cmd648_port_ops = {
381 .qc_prep = ata_qc_prep, 381 .qc_prep = ata_qc_prep,
382 .qc_issue = ata_qc_issue_prot, 382 .qc_issue = ata_qc_issue_prot,
383 383
384 .data_xfer = ata_pio_data_xfer, 384 .data_xfer = ata_data_xfer,
385 385
386 .irq_handler = ata_interrupt, 386 .irq_handler = ata_interrupt,
387 .irq_clear = ata_bmdma_irq_clear, 387 .irq_clear = ata_bmdma_irq_clear,
388 .irq_on = ata_irq_on,
389 .irq_ack = ata_irq_ack,
388 390
389 .port_start = ata_port_start, 391 .port_start = ata_port_start,
390 .port_stop = ata_port_stop,
391 .host_stop = ata_host_stop
392}; 392};
393 393
394static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 394static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index 9f165a8e032..1ce8fcfd782 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -99,9 +99,9 @@ static void cs5520_set_timings(struct ata_port *ap, struct ata_device *adev, int
99static void cs5520_enable_dma(struct ata_port *ap, struct ata_device *adev) 99static void cs5520_enable_dma(struct ata_port *ap, struct ata_device *adev)
100{ 100{
101 /* Set the DMA enable/disable flag */ 101 /* Set the DMA enable/disable flag */
102 u8 reg = inb(ap->ioaddr.bmdma_addr + 0x02); 102 u8 reg = ioread8(ap->ioaddr.bmdma_addr + 0x02);
103 reg |= 1<<(adev->devno + 5); 103 reg |= 1<<(adev->devno + 5);
104 outb(reg, ap->ioaddr.bmdma_addr + 0x02); 104 iowrite8(reg, ap->ioaddr.bmdma_addr + 0x02);
105} 105}
106 106
107/** 107/**
@@ -193,19 +193,20 @@ static struct ata_port_operations cs5520_port_ops = {
193 .bmdma_status = ata_bmdma_status, 193 .bmdma_status = ata_bmdma_status,
194 .qc_prep = ata_qc_prep, 194 .qc_prep = ata_qc_prep,
195 .qc_issue = ata_qc_issue_prot, 195 .qc_issue = ata_qc_issue_prot,
196 .data_xfer = ata_pio_data_xfer, 196 .data_xfer = ata_data_xfer,
197 197
198 .irq_handler = ata_interrupt, 198 .irq_handler = ata_interrupt,
199 .irq_clear = ata_bmdma_irq_clear, 199 .irq_clear = ata_bmdma_irq_clear,
200 .irq_on = ata_irq_on,
201 .irq_ack = ata_irq_ack,
200 202
201 .port_start = ata_port_start, 203 .port_start = ata_port_start,
202 .port_stop = ata_port_stop,
203 .host_stop = ata_host_stop,
204}; 204};
205 205
206static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id) 206static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_device_id *id)
207{ 207{
208 u8 pcicfg; 208 u8 pcicfg;
209 void *iomap[5];
209 static struct ata_probe_ent probe[2]; 210 static struct ata_probe_ent probe[2];
210 int ports = 0; 211 int ports = 0;
211 212
@@ -236,6 +237,16 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
236 return -ENODEV; 237 return -ENODEV;
237 } 238 }
238 239
240 /* Map IO ports */
241 iomap[0] = devm_ioport_map(&dev->dev, 0x1F0, 8);
242 iomap[1] = devm_ioport_map(&dev->dev, 0x3F6, 1);
243 iomap[2] = devm_ioport_map(&dev->dev, 0x170, 8);
244 iomap[3] = devm_ioport_map(&dev->dev, 0x376, 1);
245 iomap[4] = pcim_iomap(dev, 2, 0);
246
247 if (!iomap[0] || !iomap[1] || !iomap[2] || !iomap[3] || !iomap[4])
248 return -ENOMEM;
249
239 /* We have to do our own plumbing as the PCI setup for this 250 /* We have to do our own plumbing as the PCI setup for this
240 chipset is non-standard so we can't punt to the libata code */ 251 chipset is non-standard so we can't punt to the libata code */
241 252
@@ -249,10 +260,10 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
249 probe[0].irq_flags = 0; 260 probe[0].irq_flags = 0;
250 probe[0].port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST; 261 probe[0].port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST;
251 probe[0].n_ports = 1; 262 probe[0].n_ports = 1;
252 probe[0].port[0].cmd_addr = 0x1F0; 263 probe[0].port[0].cmd_addr = iomap[0];
253 probe[0].port[0].ctl_addr = 0x3F6; 264 probe[0].port[0].ctl_addr = iomap[1];
254 probe[0].port[0].altstatus_addr = 0x3F6; 265 probe[0].port[0].altstatus_addr = iomap[1];
255 probe[0].port[0].bmdma_addr = pci_resource_start(dev, 2); 266 probe[0].port[0].bmdma_addr = iomap[4];
256 267
257 /* The secondary lurks at different addresses but is otherwise 268 /* The secondary lurks at different addresses but is otherwise
258 the same beastie */ 269 the same beastie */
@@ -260,10 +271,10 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
260 probe[1] = probe[0]; 271 probe[1] = probe[0];
261 INIT_LIST_HEAD(&probe[1].node); 272 INIT_LIST_HEAD(&probe[1].node);
262 probe[1].irq = 15; 273 probe[1].irq = 15;
263 probe[1].port[0].cmd_addr = 0x170; 274 probe[1].port[0].cmd_addr = iomap[2];
264 probe[1].port[0].ctl_addr = 0x376; 275 probe[1].port[0].ctl_addr = iomap[3];
265 probe[1].port[0].altstatus_addr = 0x376; 276 probe[1].port[0].altstatus_addr = iomap[3];
266 probe[1].port[0].bmdma_addr = pci_resource_start(dev, 2) + 8; 277 probe[1].port[0].bmdma_addr = iomap[4] + 8;
267 278
268 /* Let libata fill in the port details */ 279 /* Let libata fill in the port details */
269 ata_std_ports(&probe[0].port[0]); 280 ata_std_ports(&probe[0].port[0]);
@@ -294,7 +305,7 @@ static void __devexit cs5520_remove_one(struct pci_dev *pdev)
294 struct device *dev = pci_dev_to_dev(pdev); 305 struct device *dev = pci_dev_to_dev(pdev);
295 struct ata_host *host = dev_get_drvdata(dev); 306 struct ata_host *host = dev_get_drvdata(dev);
296 307
297 ata_host_remove(host); 308 ata_host_detach(host);
298 dev_set_drvdata(dev, NULL); 309 dev_set_drvdata(dev, NULL);
299} 310}
300 311
@@ -305,7 +316,7 @@ static void __devexit cs5520_remove_one(struct pci_dev *pdev)
305 * Do any reconfiguration work needed by a resume from RAM. We need 316 * Do any reconfiguration work needed by a resume from RAM. We need
306 * to restore DMA mode support on BIOSen which disabled it 317 * to restore DMA mode support on BIOSen which disabled it
307 */ 318 */
308 319
309static int cs5520_reinit_one(struct pci_dev *pdev) 320static int cs5520_reinit_one(struct pci_dev *pdev)
310{ 321{
311 u8 pcicfg; 322 u8 pcicfg;
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index b1ca207e354..3d7b7d87ec6 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -37,6 +37,13 @@
37#define DRV_NAME "pata_cs5530" 37#define DRV_NAME "pata_cs5530"
38#define DRV_VERSION "0.7.1" 38#define DRV_VERSION "0.7.1"
39 39
40static void __iomem *cs5530_port_base(struct ata_port *ap)
41{
42 unsigned long bmdma = (unsigned long)ap->ioaddr.bmdma_addr;
43
44 return (void __iomem *)((bmdma & ~0x0F) + 0x20 + 0x10 * ap->port_no);
45}
46
40/** 47/**
41 * cs5530_set_piomode - PIO setup 48 * cs5530_set_piomode - PIO setup
42 * @ap: ATA interface 49 * @ap: ATA interface
@@ -52,19 +59,19 @@ static void cs5530_set_piomode(struct ata_port *ap, struct ata_device *adev)
52 {0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010}, 59 {0x00009172, 0x00012171, 0x00020080, 0x00032010, 0x00040010},
53 {0xd1329172, 0x71212171, 0x30200080, 0x20102010, 0x00100010} 60 {0xd1329172, 0x71212171, 0x30200080, 0x20102010, 0x00100010}
54 }; 61 };
55 unsigned long base = ( ap->ioaddr.bmdma_addr & ~0x0F) + 0x20 + 0x10 * ap->port_no; 62 void __iomem *base = cs5530_port_base(ap);
56 u32 tuning; 63 u32 tuning;
57 int format; 64 int format;
58 65
59 /* Find out which table to use */ 66 /* Find out which table to use */
60 tuning = inl(base + 0x04); 67 tuning = ioread32(base + 0x04);
61 format = (tuning & 0x80000000UL) ? 1 : 0; 68 format = (tuning & 0x80000000UL) ? 1 : 0;
62 69
63 /* Now load the right timing register */ 70 /* Now load the right timing register */
64 if (adev->devno) 71 if (adev->devno)
65 base += 0x08; 72 base += 0x08;
66 73
67 outl(cs5530_pio_timings[format][adev->pio_mode - XFER_PIO_0], base); 74 iowrite32(cs5530_pio_timings[format][adev->pio_mode - XFER_PIO_0], base);
68} 75}
69 76
70/** 77/**
@@ -79,12 +86,12 @@ static void cs5530_set_piomode(struct ata_port *ap, struct ata_device *adev)
79 86
80static void cs5530_set_dmamode(struct ata_port *ap, struct ata_device *adev) 87static void cs5530_set_dmamode(struct ata_port *ap, struct ata_device *adev)
81{ 88{
82 unsigned long base = ( ap->ioaddr.bmdma_addr & ~0x0F) + 0x20 + 0x10 * ap->port_no; 89 void __iomem *base = cs5530_port_base(ap);
83 u32 tuning, timing = 0; 90 u32 tuning, timing = 0;
84 u8 reg; 91 u8 reg;
85 92
86 /* Find out which table to use */ 93 /* Find out which table to use */
87 tuning = inl(base + 0x04); 94 tuning = ioread32(base + 0x04);
88 95
89 switch(adev->dma_mode) { 96 switch(adev->dma_mode) {
90 case XFER_UDMA_0: 97 case XFER_UDMA_0:
@@ -105,20 +112,20 @@ static void cs5530_set_dmamode(struct ata_port *ap, struct ata_device *adev)
105 /* Merge in the PIO format bit */ 112 /* Merge in the PIO format bit */
106 timing |= (tuning & 0x80000000UL); 113 timing |= (tuning & 0x80000000UL);
107 if (adev->devno == 0) /* Master */ 114 if (adev->devno == 0) /* Master */
108 outl(timing, base + 0x04); 115 iowrite32(timing, base + 0x04);
109 else { 116 else {
110 if (timing & 0x00100000) 117 if (timing & 0x00100000)
111 tuning |= 0x00100000; /* UDMA for both */ 118 tuning |= 0x00100000; /* UDMA for both */
112 else 119 else
113 tuning &= ~0x00100000; /* MWDMA for both */ 120 tuning &= ~0x00100000; /* MWDMA for both */
114 outl(tuning, base + 0x04); 121 iowrite32(tuning, base + 0x04);
115 outl(timing, base + 0x0C); 122 iowrite32(timing, base + 0x0C);
116 } 123 }
117 124
118 /* Set the DMA capable bit in the BMDMA area */ 125 /* Set the DMA capable bit in the BMDMA area */
119 reg = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); 126 reg = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
120 reg |= (1 << (5 + adev->devno)); 127 reg |= (1 << (5 + adev->devno));
121 outb(reg, ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); 128 iowrite8(reg, ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
122 129
123 /* Remember the last DMA setup we did */ 130 /* Remember the last DMA setup we did */
124 131
@@ -210,14 +217,14 @@ static struct ata_port_operations cs5530_port_ops = {
210 .qc_prep = ata_qc_prep, 217 .qc_prep = ata_qc_prep,
211 .qc_issue = cs5530_qc_issue_prot, 218 .qc_issue = cs5530_qc_issue_prot,
212 219
213 .data_xfer = ata_pio_data_xfer, 220 .data_xfer = ata_data_xfer,
214 221
215 .irq_handler = ata_interrupt, 222 .irq_handler = ata_interrupt,
216 .irq_clear = ata_bmdma_irq_clear, 223 .irq_clear = ata_bmdma_irq_clear,
224 .irq_on = ata_irq_on,
225 .irq_ack = ata_irq_ack,
217 226
218 .port_start = ata_port_start, 227 .port_start = ata_port_start,
219 .port_stop = ata_port_stop,
220 .host_stop = ata_host_stop
221}; 228};
222 229
223static struct dmi_system_id palmax_dmi_table[] = { 230static struct dmi_system_id palmax_dmi_table[] = {
@@ -247,7 +254,7 @@ static int cs5530_is_palmax(void)
247 * Perform the chip initialisation work that is shared between both 254 * Perform the chip initialisation work that is shared between both
248 * setup and resume paths 255 * setup and resume paths
249 */ 256 */
250 257
251static int cs5530_init_chip(void) 258static int cs5530_init_chip(void)
252{ 259{
253 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL, *dev = NULL; 260 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL, *dev = NULL;
@@ -357,11 +364,11 @@ static int cs5530_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
357 .port_ops = &cs5530_port_ops 364 .port_ops = &cs5530_port_ops
358 }; 365 };
359 static struct ata_port_info *port_info[2] = { &info, &info }; 366 static struct ata_port_info *port_info[2] = { &info, &info };
360 367
361 /* Chip initialisation */ 368 /* Chip initialisation */
362 if (cs5530_init_chip()) 369 if (cs5530_init_chip())
363 return -ENODEV; 370 return -ENODEV;
364 371
365 if (cs5530_is_palmax()) 372 if (cs5530_is_palmax())
366 port_info[1] = &info_palmax_secondary; 373 port_info[1] = &info_palmax_secondary;
367 374
@@ -376,7 +383,7 @@ static int cs5530_reinit_one(struct pci_dev *pdev)
376 BUG(); 383 BUG();
377 return ata_pci_device_resume(pdev); 384 return ata_pci_device_resume(pdev);
378} 385}
379 386
380static const struct pci_device_id cs5530[] = { 387static const struct pci_device_id cs5530[] = {
381 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_IDE), }, 388 { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_IDE), },
382 389
diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
index e3efec4ffc7..17bc693cc51 100644
--- a/drivers/ata/pata_cs5535.c
+++ b/drivers/ata/pata_cs5535.c
@@ -214,14 +214,14 @@ static struct ata_port_operations cs5535_port_ops = {
214 .qc_prep = ata_qc_prep, 214 .qc_prep = ata_qc_prep,
215 .qc_issue = ata_qc_issue_prot, 215 .qc_issue = ata_qc_issue_prot,
216 216
217 .data_xfer = ata_pio_data_xfer, 217 .data_xfer = ata_data_xfer,
218 218
219 .irq_handler = ata_interrupt, 219 .irq_handler = ata_interrupt,
220 .irq_clear = ata_bmdma_irq_clear, 220 .irq_clear = ata_bmdma_irq_clear,
221 .irq_on = ata_irq_on,
222 .irq_ack = ata_irq_ack,
221 223
222 .port_start = ata_port_start, 224 .port_start = ata_port_start,
223 .port_stop = ata_port_stop,
224 .host_stop = ata_host_stop
225}; 225};
226 226
227/** 227/**
diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
index e2a95699bae..63f48f08763 100644
--- a/drivers/ata/pata_cypress.c
+++ b/drivers/ata/pata_cypress.c
@@ -165,14 +165,14 @@ static struct ata_port_operations cy82c693_port_ops = {
165 .qc_prep = ata_qc_prep, 165 .qc_prep = ata_qc_prep,
166 .qc_issue = ata_qc_issue_prot, 166 .qc_issue = ata_qc_issue_prot,
167 167
168 .data_xfer = ata_pio_data_xfer, 168 .data_xfer = ata_data_xfer,
169 169
170 .irq_handler = ata_interrupt, 170 .irq_handler = ata_interrupt,
171 .irq_clear = ata_bmdma_irq_clear, 171 .irq_clear = ata_bmdma_irq_clear,
172 .irq_on = ata_irq_on,
173 .irq_ack = ata_irq_ack,
172 174
173 .port_start = ata_port_start, 175 .port_start = ata_port_start,
174 .port_stop = ata_port_stop,
175 .host_stop = ata_host_stop
176}; 176};
177 177
178static int cy82c693_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 178static int cy82c693_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
index edf8a63f50a..c19b6a8a7dc 100644
--- a/drivers/ata/pata_efar.c
+++ b/drivers/ata/pata_efar.c
@@ -261,14 +261,14 @@ static const struct ata_port_operations efar_ops = {
261 .bmdma_status = ata_bmdma_status, 261 .bmdma_status = ata_bmdma_status,
262 .qc_prep = ata_qc_prep, 262 .qc_prep = ata_qc_prep,
263 .qc_issue = ata_qc_issue_prot, 263 .qc_issue = ata_qc_issue_prot,
264 .data_xfer = ata_pio_data_xfer, 264 .data_xfer = ata_data_xfer,
265 265
266 .irq_handler = ata_interrupt, 266 .irq_handler = ata_interrupt,
267 .irq_clear = ata_bmdma_irq_clear, 267 .irq_clear = ata_bmdma_irq_clear,
268 .irq_on = ata_irq_on,
269 .irq_ack = ata_irq_ack,
268 270
269 .port_start = ata_port_start, 271 .port_start = ata_port_start,
270 .port_stop = ata_port_stop,
271 .host_stop = ata_host_stop,
272}; 272};
273 273
274 274
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 2663599a7c0..27d724b5eea 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -151,23 +151,13 @@ static const char *bad_ata66_3[] = {
151 151
152static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[]) 152static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[])
153{ 153{
154 unsigned char model_num[40]; 154 unsigned char model_num[ATA_ID_PROD_LEN + 1];
155 char *s;
156 unsigned int len;
157 int i = 0; 155 int i = 0;
158 156
159 ata_id_string(dev->id, model_num, ATA_ID_PROD_OFS, sizeof(model_num)); 157 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
160 s = &model_num[0];
161 len = strnlen(s, sizeof(model_num));
162 158
163 /* ATAPI specifies that empty space is blank-filled; remove blanks */ 159 while (list[i] != NULL) {
164 while ((len > 0) && (s[len - 1] == ' ')) { 160 if (!strcmp(list[i], model_num)) {
165 len--;
166 s[len] = 0;
167 }
168
169 while(list[i] != NULL) {
170 if (!strncmp(list[i], s, len)) {
171 printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n", 161 printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n",
172 modestr, list[i]); 162 modestr, list[i]);
173 return 1; 163 return 1;
@@ -232,7 +222,7 @@ static int hpt36x_pre_reset(struct ata_port *ap)
232 222
233 if (!pci_test_config_bits(pdev, &hpt36x_enable_bits[ap->port_no])) 223 if (!pci_test_config_bits(pdev, &hpt36x_enable_bits[ap->port_no]))
234 return -ENOENT; 224 return -ENOENT;
235 225
236 pci_read_config_byte(pdev, 0x5A, &ata66); 226 pci_read_config_byte(pdev, 0x5A, &ata66);
237 if (ata66 & (1 << ap->port_no)) 227 if (ata66 & (1 << ap->port_no))
238 ap->cbl = ATA_CBL_PATA40; 228 ap->cbl = ATA_CBL_PATA40;
@@ -371,14 +361,14 @@ static struct ata_port_operations hpt366_port_ops = {
371 .qc_prep = ata_qc_prep, 361 .qc_prep = ata_qc_prep,
372 .qc_issue = ata_qc_issue_prot, 362 .qc_issue = ata_qc_issue_prot,
373 363
374 .data_xfer = ata_pio_data_xfer, 364 .data_xfer = ata_data_xfer,
375 365
376 .irq_handler = ata_interrupt, 366 .irq_handler = ata_interrupt,
377 .irq_clear = ata_bmdma_irq_clear, 367 .irq_clear = ata_bmdma_irq_clear,
368 .irq_on = ata_irq_on,
369 .irq_ack = ata_irq_ack,
378 370
379 .port_start = ata_port_start, 371 .port_start = ata_port_start,
380 .port_stop = ata_port_stop,
381 .host_stop = ata_host_stop
382}; 372};
383 373
384/** 374/**
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index dfb306057cf..4ffc392052c 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -349,24 +349,13 @@ static u32 hpt37x_find_mode(struct ata_port *ap, int speed)
349 349
350static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[]) 350static int hpt_dma_blacklisted(const struct ata_device *dev, char *modestr, const char *list[])
351{ 351{
352 unsigned char model_num[40]; 352 unsigned char model_num[ATA_ID_PROD_LEN + 1];
353 char *s;
354 unsigned int len;
355 int i = 0; 353 int i = 0;
356 354
357 ata_id_string(dev->id, model_num, ATA_ID_PROD_OFS, 355 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
358 sizeof(model_num));
359 s = &model_num[0];
360 len = strnlen(s, sizeof(model_num));
361 356
362 /* ATAPI specifies that empty space is blank-filled; remove blanks */ 357 while (list[i] != NULL) {
363 while ((len > 0) && (s[len - 1] == ' ')) { 358 if (!strcmp(list[i], model_num)) {
364 len--;
365 s[len] = 0;
366 }
367
368 while(list[i] != NULL) {
369 if (!strncmp(list[i], s, len)) {
370 printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n", 359 printk(KERN_WARNING DRV_NAME ": %s is not supported for %s.\n",
371 modestr, list[i]); 360 modestr, list[i]);
372 return 1; 361 return 1;
@@ -459,7 +448,7 @@ static int hpt37x_pre_reset(struct ata_port *ap)
459 }; 448 };
460 if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no])) 449 if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no]))
461 return -ENOENT; 450 return -ENOENT;
462 451
463 pci_read_config_byte(pdev, 0x5B, &scr2); 452 pci_read_config_byte(pdev, 0x5B, &scr2);
464 pci_write_config_byte(pdev, 0x5B, scr2 & ~0x01); 453 pci_write_config_byte(pdev, 0x5B, scr2 & ~0x01);
465 /* Cable register now active */ 454 /* Cable register now active */
@@ -504,7 +493,7 @@ static int hpt374_pre_reset(struct ata_port *ap)
504 493
505 if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no])) 494 if (!pci_test_config_bits(pdev, &hpt37x_enable_bits[ap->port_no]))
506 return -ENOENT; 495 return -ENOENT;
507 496
508 /* Do the extra channel work */ 497 /* Do the extra channel work */
509 pci_read_config_word(pdev, 0x52, &mcr3); 498 pci_read_config_word(pdev, 0x52, &mcr3);
510 pci_read_config_word(pdev, 0x56, &mcr6); 499 pci_read_config_word(pdev, 0x56, &mcr6);
@@ -645,24 +634,24 @@ static void hpt370_bmdma_stop(struct ata_queued_cmd *qc)
645{ 634{
646 struct ata_port *ap = qc->ap; 635 struct ata_port *ap = qc->ap;
647 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 636 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
648 u8 dma_stat = inb(ap->ioaddr.bmdma_addr + 2); 637 u8 dma_stat = ioread8(ap->ioaddr.bmdma_addr + 2);
649 u8 dma_cmd; 638 u8 dma_cmd;
650 unsigned long bmdma = ap->ioaddr.bmdma_addr; 639 void __iomem *bmdma = ap->ioaddr.bmdma_addr;
651 640
652 if (dma_stat & 0x01) { 641 if (dma_stat & 0x01) {
653 udelay(20); 642 udelay(20);
654 dma_stat = inb(bmdma + 2); 643 dma_stat = ioread8(bmdma + 2);
655 } 644 }
656 if (dma_stat & 0x01) { 645 if (dma_stat & 0x01) {
657 /* Clear the engine */ 646 /* Clear the engine */
658 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37); 647 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
659 udelay(10); 648 udelay(10);
660 /* Stop DMA */ 649 /* Stop DMA */
661 dma_cmd = inb(bmdma ); 650 dma_cmd = ioread8(bmdma );
662 outb(dma_cmd & 0xFE, bmdma); 651 iowrite8(dma_cmd & 0xFE, bmdma);
663 /* Clear Error */ 652 /* Clear Error */
664 dma_stat = inb(bmdma + 2); 653 dma_stat = ioread8(bmdma + 2);
665 outb(dma_stat | 0x06 , bmdma + 2); 654 iowrite8(dma_stat | 0x06 , bmdma + 2);
666 /* Clear the engine */ 655 /* Clear the engine */
667 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37); 656 pci_write_config_byte(pdev, 0x50 + 4 * ap->port_no, 0x37);
668 udelay(10); 657 udelay(10);
@@ -807,14 +796,14 @@ static struct ata_port_operations hpt370_port_ops = {
807 .qc_prep = ata_qc_prep, 796 .qc_prep = ata_qc_prep,
808 .qc_issue = ata_qc_issue_prot, 797 .qc_issue = ata_qc_issue_prot,
809 798
810 .data_xfer = ata_pio_data_xfer, 799 .data_xfer = ata_data_xfer,
811 800
812 .irq_handler = ata_interrupt, 801 .irq_handler = ata_interrupt,
813 .irq_clear = ata_bmdma_irq_clear, 802 .irq_clear = ata_bmdma_irq_clear,
803 .irq_on = ata_irq_on,
804 .irq_ack = ata_irq_ack,
814 805
815 .port_start = ata_port_start, 806 .port_start = ata_port_start,
816 .port_stop = ata_port_stop,
817 .host_stop = ata_host_stop
818}; 807};
819 808
820/* 809/*
@@ -846,14 +835,14 @@ static struct ata_port_operations hpt370a_port_ops = {
846 .qc_prep = ata_qc_prep, 835 .qc_prep = ata_qc_prep,
847 .qc_issue = ata_qc_issue_prot, 836 .qc_issue = ata_qc_issue_prot,
848 837
849 .data_xfer = ata_pio_data_xfer, 838 .data_xfer = ata_data_xfer,
850 839
851 .irq_handler = ata_interrupt, 840 .irq_handler = ata_interrupt,
852 .irq_clear = ata_bmdma_irq_clear, 841 .irq_clear = ata_bmdma_irq_clear,
842 .irq_on = ata_irq_on,
843 .irq_ack = ata_irq_ack,
853 844
854 .port_start = ata_port_start, 845 .port_start = ata_port_start,
855 .port_stop = ata_port_stop,
856 .host_stop = ata_host_stop
857}; 846};
858 847
859/* 848/*
@@ -886,14 +875,14 @@ static struct ata_port_operations hpt372_port_ops = {
886 .qc_prep = ata_qc_prep, 875 .qc_prep = ata_qc_prep,
887 .qc_issue = ata_qc_issue_prot, 876 .qc_issue = ata_qc_issue_prot,
888 877
889 .data_xfer = ata_pio_data_xfer, 878 .data_xfer = ata_data_xfer,
890 879
891 .irq_handler = ata_interrupt, 880 .irq_handler = ata_interrupt,
892 .irq_clear = ata_bmdma_irq_clear, 881 .irq_clear = ata_bmdma_irq_clear,
882 .irq_on = ata_irq_on,
883 .irq_ack = ata_irq_ack,
893 884
894 .port_start = ata_port_start, 885 .port_start = ata_port_start,
895 .port_stop = ata_port_stop,
896 .host_stop = ata_host_stop
897}; 886};
898 887
899/* 888/*
@@ -926,14 +915,14 @@ static struct ata_port_operations hpt374_port_ops = {
926 .qc_prep = ata_qc_prep, 915 .qc_prep = ata_qc_prep,
927 .qc_issue = ata_qc_issue_prot, 916 .qc_issue = ata_qc_issue_prot,
928 917
929 .data_xfer = ata_pio_data_xfer, 918 .data_xfer = ata_data_xfer,
930 919
931 .irq_handler = ata_interrupt, 920 .irq_handler = ata_interrupt,
932 .irq_clear = ata_bmdma_irq_clear, 921 .irq_clear = ata_bmdma_irq_clear,
922 .irq_on = ata_irq_on,
923 .irq_ack = ata_irq_ack,
933 924
934 .port_start = ata_port_start, 925 .port_start = ata_port_start,
935 .port_stop = ata_port_stop,
936 .host_stop = ata_host_stop
937}; 926};
938 927
939/** 928/**
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index 886fab9aa62..65f2e180e7f 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -263,26 +263,26 @@ static void hpt3x2n_bmdma_stop(struct ata_queued_cmd *qc)
263 263
264static void hpt3x2n_set_clock(struct ata_port *ap, int source) 264static void hpt3x2n_set_clock(struct ata_port *ap, int source)
265{ 265{
266 unsigned long bmdma = ap->ioaddr.bmdma_addr; 266 void __iomem *bmdma = ap->ioaddr.bmdma_addr;
267 267
268 /* Tristate the bus */ 268 /* Tristate the bus */
269 outb(0x80, bmdma+0x73); 269 iowrite8(0x80, bmdma+0x73);
270 outb(0x80, bmdma+0x77); 270 iowrite8(0x80, bmdma+0x77);
271 271
272 /* Switch clock and reset channels */ 272 /* Switch clock and reset channels */
273 outb(source, bmdma+0x7B); 273 iowrite8(source, bmdma+0x7B);
274 outb(0xC0, bmdma+0x79); 274 iowrite8(0xC0, bmdma+0x79);
275 275
276 /* Reset state machines */ 276 /* Reset state machines */
277 outb(0x37, bmdma+0x70); 277 iowrite8(0x37, bmdma+0x70);
278 outb(0x37, bmdma+0x74); 278 iowrite8(0x37, bmdma+0x74);
279 279
280 /* Complete reset */ 280 /* Complete reset */
281 outb(0x00, bmdma+0x79); 281 iowrite8(0x00, bmdma+0x79);
282 282
283 /* Reconnect channels to bus */ 283 /* Reconnect channels to bus */
284 outb(0x00, bmdma+0x73); 284 iowrite8(0x00, bmdma+0x73);
285 outb(0x00, bmdma+0x77); 285 iowrite8(0x00, bmdma+0x77);
286} 286}
287 287
288/* Check if our partner interface is busy */ 288/* Check if our partner interface is busy */
@@ -373,14 +373,14 @@ static struct ata_port_operations hpt3x2n_port_ops = {
373 .qc_prep = ata_qc_prep, 373 .qc_prep = ata_qc_prep,
374 .qc_issue = hpt3x2n_qc_issue_prot, 374 .qc_issue = hpt3x2n_qc_issue_prot,
375 375
376 .data_xfer = ata_pio_data_xfer, 376 .data_xfer = ata_data_xfer,
377 377
378 .irq_handler = ata_interrupt, 378 .irq_handler = ata_interrupt,
379 .irq_clear = ata_bmdma_irq_clear, 379 .irq_clear = ata_bmdma_irq_clear,
380 .irq_on = ata_irq_on,
381 .irq_ack = ata_irq_ack,
380 382
381 .port_start = ata_port_start, 383 .port_start = ata_port_start,
382 .port_stop = ata_port_stop,
383 .host_stop = ata_host_stop
384}; 384};
385 385
386/** 386/**
diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
index 5f1d385eb59..483ce7c12c9 100644
--- a/drivers/ata/pata_hpt3x3.c
+++ b/drivers/ata/pata_hpt3x3.c
@@ -148,14 +148,14 @@ static struct ata_port_operations hpt3x3_port_ops = {
148 .qc_prep = ata_qc_prep, 148 .qc_prep = ata_qc_prep,
149 .qc_issue = ata_qc_issue_prot, 149 .qc_issue = ata_qc_issue_prot,
150 150
151 .data_xfer = ata_pio_data_xfer, 151 .data_xfer = ata_data_xfer,
152 152
153 .irq_handler = ata_interrupt, 153 .irq_handler = ata_interrupt,
154 .irq_clear = ata_bmdma_irq_clear, 154 .irq_clear = ata_bmdma_irq_clear,
155 .irq_on = ata_irq_on,
156 .irq_ack = ata_irq_ack,
155 157
156 .port_start = ata_port_start, 158 .port_start = ata_port_start,
157 .port_stop = ata_port_stop,
158 .host_stop = ata_host_stop
159}; 159};
160 160
161/** 161/**
@@ -164,7 +164,7 @@ static struct ata_port_operations hpt3x3_port_ops = {
164 * 164 *
165 * Perform the setup required at boot and on resume. 165 * Perform the setup required at boot and on resume.
166 */ 166 */
167 167
168static void hpt3x3_init_chipset(struct pci_dev *dev) 168static void hpt3x3_init_chipset(struct pci_dev *dev)
169{ 169{
170 u16 cmd; 170 u16 cmd;
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index a97d55ae95c..1bf5ec18b2e 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -53,14 +53,14 @@ static struct ata_port_operations isapnp_port_ops = {
53 .qc_prep = ata_qc_prep, 53 .qc_prep = ata_qc_prep,
54 .qc_issue = ata_qc_issue_prot, 54 .qc_issue = ata_qc_issue_prot,
55 55
56 .data_xfer = ata_pio_data_xfer, 56 .data_xfer = ata_data_xfer,
57 57
58 .irq_handler = ata_interrupt, 58 .irq_handler = ata_interrupt,
59 .irq_clear = ata_bmdma_irq_clear, 59 .irq_clear = ata_bmdma_irq_clear,
60 .irq_on = ata_irq_on,
61 .irq_ack = ata_irq_ack,
60 62
61 .port_start = ata_port_start, 63 .port_start = ata_port_start,
62 .port_stop = ata_port_stop,
63 .host_stop = ata_host_stop
64}; 64};
65 65
66/** 66/**
@@ -75,6 +75,7 @@ static struct ata_port_operations isapnp_port_ops = {
75static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id) 75static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev_id)
76{ 76{
77 struct ata_probe_ent ae; 77 struct ata_probe_ent ae;
78 void __iomem *cmd_addr, *ctl_addr;
78 79
79 if (pnp_port_valid(idev, 0) == 0) 80 if (pnp_port_valid(idev, 0) == 0)
80 return -ENODEV; 81 return -ENODEV;
@@ -83,6 +84,10 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
83 if (pnp_irq_valid(idev, 0) == 0) 84 if (pnp_irq_valid(idev, 0) == 0)
84 return -ENODEV; 85 return -ENODEV;
85 86
87 cmd_addr = devm_ioport_map(&idev->dev, pnp_port_start(idev, 0), 8);
88 if (!cmd_addr)
89 return -ENOMEM;
90
86 memset(&ae, 0, sizeof(struct ata_probe_ent)); 91 memset(&ae, 0, sizeof(struct ata_probe_ent));
87 INIT_LIST_HEAD(&ae.node); 92 INIT_LIST_HEAD(&ae.node);
88 ae.dev = &idev->dev; 93 ae.dev = &idev->dev;
@@ -93,11 +98,13 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
93 ae.irq = pnp_irq(idev, 0); 98 ae.irq = pnp_irq(idev, 0);
94 ae.irq_flags = 0; 99 ae.irq_flags = 0;
95 ae.port_flags = ATA_FLAG_SLAVE_POSS; 100 ae.port_flags = ATA_FLAG_SLAVE_POSS;
96 ae.port[0].cmd_addr = pnp_port_start(idev, 0); 101 ae.port[0].cmd_addr = cmd_addr;
97 102
98 if (pnp_port_valid(idev, 1) == 0) { 103 if (pnp_port_valid(idev, 1) == 0) {
99 ae.port[0].altstatus_addr = pnp_port_start(idev, 1); 104 ctl_addr = devm_ioport_map(&idev->dev,
100 ae.port[0].ctl_addr = pnp_port_start(idev, 1); 105 pnp_port_start(idev, 1), 1);
106 ae.port[0].altstatus_addr = ctl_addr;
107 ae.port[0].ctl_addr = ctl_addr;
101 ae.port_flags |= ATA_FLAG_SRST; 108 ae.port_flags |= ATA_FLAG_SRST;
102 } 109 }
103 ata_std_ports(&ae.port[0]); 110 ata_std_ports(&ae.port[0]);
@@ -120,7 +127,7 @@ static void isapnp_remove_one(struct pnp_dev *idev)
120 struct device *dev = &idev->dev; 127 struct device *dev = &idev->dev;
121 struct ata_host *host = dev_get_drvdata(dev); 128 struct ata_host *host = dev_get_drvdata(dev);
122 129
123 ata_host_remove(host); 130 ata_host_detach(host);
124 dev_set_drvdata(dev, NULL); 131 dev_set_drvdata(dev, NULL);
125} 132}
126 133
diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
new file mode 100644
index 00000000000..7eac869dfcd
--- /dev/null
+++ b/drivers/ata/pata_it8213.c
@@ -0,0 +1,354 @@
1/*
2 * pata_it8213.c - iTE Tech. Inc. IT8213 PATA driver
3 *
4 * The IT8213 is a very Intel ICH like device for timing purposes, having
5 * a similar register layout and the same split clock arrangement. Cable
6 * detection is different, and it does not have slave channels or all the
7 * clutter of later ICH/SATA setups.
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/pci.h>
13#include <linux/init.h>
14#include <linux/blkdev.h>
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <scsi/scsi_host.h>
18#include <linux/libata.h>
19#include <linux/ata.h>
20
21#define DRV_NAME "pata_it8213"
22#define DRV_VERSION "0.0.2"
23
24/**
25 * it8213_pre_reset - check for 40/80 pin
26 * @ap: Port
27 *
28 * Perform cable detection for the 8213 ATA interface. This is
29 * different to the PIIX arrangement
30 */
31
32static int it8213_pre_reset(struct ata_port *ap)
33{
34 static const struct pci_bits it8213_enable_bits[] = {
35 { 0x41U, 1U, 0x80UL, 0x80UL }, /* port 0 */
36 };
37
38 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
39 u8 tmp;
40
41 if (!pci_test_config_bits(pdev, &it8213_enable_bits[ap->port_no]))
42 return -ENOENT;
43
44 pci_read_config_byte(pdev, 0x42, &tmp);
45 if (tmp & 2) /* The initial docs are incorrect */
46 ap->cbl = ATA_CBL_PATA40;
47 else
48 ap->cbl = ATA_CBL_PATA80;
49 return ata_std_prereset(ap);
50}
51
52/**
53 * it8213_probe_reset - Probe specified port on PATA host controller
54 * @ap: Port to probe
55 *
56 * LOCKING:
57 * None (inherited from caller).
58 */
59
60static void it8213_error_handler(struct ata_port *ap)
61{
62 ata_bmdma_drive_eh(ap, it8213_pre_reset, ata_std_softreset, NULL, ata_std_postreset);
63}
64
65/**
66 * it8213_set_piomode - Initialize host controller PATA PIO timings
67 * @ap: Port whose timings we are configuring
68 * @adev: um
69 *
70 * Set PIO mode for device, in host controller PCI config space.
71 *
72 * LOCKING:
73 * None (inherited from caller).
74 */
75
76static void it8213_set_piomode (struct ata_port *ap, struct ata_device *adev)
77{
78 unsigned int pio = adev->pio_mode - XFER_PIO_0;
79 struct pci_dev *dev = to_pci_dev(ap->host->dev);
80 unsigned int idetm_port= ap->port_no ? 0x42 : 0x40;
81 u16 idetm_data;
82 int control = 0;
83
84 /*
85 * See Intel Document 298600-004 for the timing programing rules
86 * for PIIX/ICH. The 8213 is a clone so very similar
87 */
88
89 static const /* ISP RTC */
90 u8 timings[][2] = { { 0, 0 },
91 { 0, 0 },
92 { 1, 0 },
93 { 2, 1 },
94 { 2, 3 }, };
95
96 if (pio > 2)
97 control |= 1; /* TIME1 enable */
98 if (ata_pio_need_iordy(adev)) /* PIO 3/4 require IORDY */
99 control |= 2; /* IORDY enable */
100 /* Bit 2 is set for ATAPI on the IT8213 - reverse of ICH/PIIX */
101 if (adev->class != ATA_DEV_ATA)
102 control |= 4;
103
104 pci_read_config_word(dev, idetm_port, &idetm_data);
105
106 /* Enable PPE, IE and TIME as appropriate */
107
108 if (adev->devno == 0) {
109 idetm_data &= 0xCCF0;
110 idetm_data |= control;
111 idetm_data |= (timings[pio][0] << 12) |
112 (timings[pio][1] << 8);
113 } else {
114 u8 slave_data;
115
116 idetm_data &= 0xCC0F;
117 idetm_data |= (control << 4);
118
119 /* Slave timing in seperate register */
120 pci_read_config_byte(dev, 0x44, &slave_data);
121 slave_data &= 0xF0;
122 slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << 4;
123 pci_write_config_byte(dev, 0x44, slave_data);
124 }
125
126 idetm_data |= 0x4000; /* Ensure SITRE is enabled */
127 pci_write_config_word(dev, idetm_port, idetm_data);
128}
129
130/**
131 * it8213_set_dmamode - Initialize host controller PATA DMA timings
132 * @ap: Port whose timings we are configuring
133 * @adev: Device to program
134 *
135 * Set UDMA/MWDMA mode for device, in host controller PCI config space.
136 * This device is basically an ICH alike.
137 *
138 * LOCKING:
139 * None (inherited from caller).
140 */
141
142static void it8213_set_dmamode (struct ata_port *ap, struct ata_device *adev)
143{
144 struct pci_dev *dev = to_pci_dev(ap->host->dev);
145 u16 master_data;
146 u8 speed = adev->dma_mode;
147 int devid = adev->devno;
148 u8 udma_enable;
149
150 static const /* ISP RTC */
151 u8 timings[][2] = { { 0, 0 },
152 { 0, 0 },
153 { 1, 0 },
154 { 2, 1 },
155 { 2, 3 }, };
156
157 pci_read_config_word(dev, 0x40, &master_data);
158 pci_read_config_byte(dev, 0x48, &udma_enable);
159
160 if (speed >= XFER_UDMA_0) {
161 unsigned int udma = adev->dma_mode - XFER_UDMA_0;
162 u16 udma_timing;
163 u16 ideconf;
164 int u_clock, u_speed;
165
166 /* Clocks follow the PIIX style */
167 u_speed = min(2 - (udma & 1), udma);
168 if (udma == 5)
169 u_clock = 0x1000; /* 100Mhz */
170 else if (udma > 2)
171 u_clock = 1; /* 66Mhz */
172 else
173 u_clock = 0; /* 33Mhz */
174
175 udma_enable |= (1 << devid);
176
177 /* Load the UDMA mode number */
178 pci_read_config_word(dev, 0x4A, &udma_timing);
179 udma_timing &= ~(3 << (4 * devid));
180 udma_timing |= (udma & 3) << (4 * devid);
181 pci_write_config_word(dev, 0x4A, udma_timing);
182
183 /* Load the clock selection */
184 pci_read_config_word(dev, 0x54, &ideconf);
185 ideconf &= ~(0x1001 << devid);
186 ideconf |= u_clock << devid;
187 pci_write_config_word(dev, 0x54, ideconf);
188 } else {
189 /*
190 * MWDMA is driven by the PIO timings. We must also enable
191 * IORDY unconditionally along with TIME1. PPE has already
192 * been set when the PIO timing was set.
193 */
194 unsigned int mwdma = adev->dma_mode - XFER_MW_DMA_0;
195 unsigned int control;
196 u8 slave_data;
197 static const unsigned int needed_pio[3] = {
198 XFER_PIO_0, XFER_PIO_3, XFER_PIO_4
199 };
200 int pio = needed_pio[mwdma] - XFER_PIO_0;
201
202 control = 3; /* IORDY|TIME1 */
203
204 /* If the drive MWDMA is faster than it can do PIO then
205 we must force PIO into PIO0 */
206
207 if (adev->pio_mode < needed_pio[mwdma])
208 /* Enable DMA timing only */
209 control |= 8; /* PIO cycles in PIO0 */
210
211 if (devid) { /* Slave */
212 master_data &= 0xFF4F; /* Mask out IORDY|TIME1|DMAONLY */
213 master_data |= control << 4;
214 pci_read_config_byte(dev, 0x44, &slave_data);
215 slave_data &= (0x0F + 0xE1 * ap->port_no);
216 /* Load the matching timing */
217 slave_data |= ((timings[pio][0] << 2) | timings[pio][1]) << (ap->port_no ? 4 : 0);
218 pci_write_config_byte(dev, 0x44, slave_data);
219 } else { /* Master */
220 master_data &= 0xCCF4; /* Mask out IORDY|TIME1|DMAONLY
221 and master timing bits */
222 master_data |= control;
223 master_data |=
224 (timings[pio][0] << 12) |
225 (timings[pio][1] << 8);
226 }
227 udma_enable &= ~(1 << devid);
228 pci_write_config_word(dev, 0x40, master_data);
229 }
230 pci_write_config_byte(dev, 0x48, udma_enable);
231}
232
233static struct scsi_host_template it8213_sht = {
234 .module = THIS_MODULE,
235 .name = DRV_NAME,
236 .ioctl = ata_scsi_ioctl,
237 .queuecommand = ata_scsi_queuecmd,
238 .can_queue = ATA_DEF_QUEUE,
239 .this_id = ATA_SHT_THIS_ID,
240 .sg_tablesize = LIBATA_MAX_PRD,
241 .max_sectors = ATA_MAX_SECTORS,
242 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
243 .emulated = ATA_SHT_EMULATED,
244 .use_clustering = ATA_SHT_USE_CLUSTERING,
245 .proc_name = DRV_NAME,
246 .dma_boundary = ATA_DMA_BOUNDARY,
247 .slave_configure = ata_scsi_slave_config,
248 .bios_param = ata_std_bios_param,
249 .resume = ata_scsi_device_resume,
250 .suspend = ata_scsi_device_suspend,
251};
252
253static const struct ata_port_operations it8213_ops = {
254 .port_disable = ata_port_disable,
255 .set_piomode = it8213_set_piomode,
256 .set_dmamode = it8213_set_dmamode,
257 .mode_filter = ata_pci_default_filter,
258
259 .tf_load = ata_tf_load,
260 .tf_read = ata_tf_read,
261 .check_status = ata_check_status,
262 .exec_command = ata_exec_command,
263 .dev_select = ata_std_dev_select,
264
265 .freeze = ata_bmdma_freeze,
266 .thaw = ata_bmdma_thaw,
267 .error_handler = it8213_error_handler,
268 .post_internal_cmd = ata_bmdma_post_internal_cmd,
269
270 .bmdma_setup = ata_bmdma_setup,
271 .bmdma_start = ata_bmdma_start,
272 .bmdma_stop = ata_bmdma_stop,
273 .bmdma_status = ata_bmdma_status,
274 .qc_prep = ata_qc_prep,
275 .qc_issue = ata_qc_issue_prot,
276 .data_xfer = ata_data_xfer,
277
278 .irq_handler = ata_interrupt,
279 .irq_clear = ata_bmdma_irq_clear,
280 .irq_on = ata_irq_on,
281 .irq_ack = ata_irq_ack,
282
283 .port_start = ata_port_start,
284};
285
286
287/**
288 * it8213_init_one - Register 8213 ATA PCI device with kernel services
289 * @pdev: PCI device to register
290 * @ent: Entry in it8213_pci_tbl matching with @pdev
291 *
292 * Called from kernel PCI layer.
293 *
294 * LOCKING:
295 * Inherited from PCI layer (may sleep).
296 *
297 * RETURNS:
298 * Zero on success, or -ERRNO value.
299 */
300
301static int it8213_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
302{
303 static int printed_version;
304 static struct ata_port_info info = {
305 .sht = &it8213_sht,
306 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
307 .pio_mask = 0x1f, /* pio0-4 */
308 .mwdma_mask = 0x07, /* mwdma0-2 */
309 .udma_mask = 0x1f, /* UDMA 100 */
310 .port_ops = &it8213_ops,
311 };
312 static struct ata_port_info *port_info[2] = { &info, &info };
313
314 if (!printed_version++)
315 dev_printk(KERN_DEBUG, &pdev->dev,
316 "version " DRV_VERSION "\n");
317
318 /* Current IT8213 stuff is single port */
319 return ata_pci_init_one(pdev, port_info, 1);
320}
321
322static const struct pci_device_id it8213_pci_tbl[] = {
323 { PCI_VDEVICE(ITE, PCI_DEVICE_ID_ITE_8213), },
324
325 { } /* terminate list */
326};
327
328static struct pci_driver it8213_pci_driver = {
329 .name = DRV_NAME,
330 .id_table = it8213_pci_tbl,
331 .probe = it8213_init_one,
332 .remove = ata_pci_remove_one,
333 .suspend = ata_pci_device_suspend,
334 .resume = ata_pci_device_resume,
335};
336
337static int __init it8213_init(void)
338{
339 return pci_register_driver(&it8213_pci_driver);
340}
341
342static void __exit it8213_exit(void)
343{
344 pci_unregister_driver(&it8213_pci_driver);
345}
346
347module_init(it8213_init);
348module_exit(it8213_exit);
349
350MODULE_AUTHOR("Alan Cox");
351MODULE_DESCRIPTION("SCSI low-level driver for the ITE 8213");
352MODULE_LICENSE("GPL");
353MODULE_DEVICE_TABLE(pci, it8213_pci_tbl);
354MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index e8afd486434..73394c75be4 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -492,7 +492,7 @@ static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused
492 /* Bits 5 and 6 indicate if DMA is active on master/slave */ 492 /* Bits 5 and 6 indicate if DMA is active on master/slave */
493 /* It is possible that BMDMA isn't allocated */ 493 /* It is possible that BMDMA isn't allocated */
494 if (ap->ioaddr.bmdma_addr) 494 if (ap->ioaddr.bmdma_addr)
495 dma_enabled = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 495 dma_enabled = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
496 496
497 for (i = 0; i < ATA_MAX_DEVICES; i++) { 497 for (i = 0; i < ATA_MAX_DEVICES; i++) {
498 struct ata_device *dev = &ap->device[i]; 498 struct ata_device *dev = &ap->device[i];
@@ -531,23 +531,9 @@ static int it821x_smart_set_mode(struct ata_port *ap, struct ata_device **unused
531 531
532static void it821x_dev_config(struct ata_port *ap, struct ata_device *adev) 532static void it821x_dev_config(struct ata_port *ap, struct ata_device *adev)
533{ 533{
534 unsigned char model_num[40]; 534 unsigned char model_num[ATA_ID_PROD_LEN + 1];
535 char *s; 535
536 unsigned int len; 536 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
537
538 /* This block ought to be a library routine as it is in several
539 drivers now */
540
541 ata_id_string(adev->id, model_num, ATA_ID_PROD_OFS,
542 sizeof(model_num));
543 s = &model_num[0];
544 len = strnlen(s, sizeof(model_num));
545
546 /* ATAPI specifies that empty space is blank-filled; remove blanks */
547 while ((len > 0) && (s[len - 1] == ' ')) {
548 len--;
549 s[len] = 0;
550 }
551 537
552 if (adev->max_sectors > 255) 538 if (adev->max_sectors > 255)
553 adev->max_sectors = 255; 539 adev->max_sectors = 255;
@@ -608,14 +594,10 @@ static int it821x_port_start(struct ata_port *ap)
608 if (ret < 0) 594 if (ret < 0)
609 return ret; 595 return ret;
610 596
611 ap->private_data = kmalloc(sizeof(struct it821x_dev), GFP_KERNEL); 597 itdev = devm_kzalloc(&pdev->dev, sizeof(struct it821x_dev), GFP_KERNEL);
612 if (ap->private_data == NULL) { 598 if (itdev == NULL)
613 ata_port_stop(ap);
614 return -ENOMEM; 599 return -ENOMEM;
615 } 600 ap->private_data = itdev;
616
617 itdev = ap->private_data;
618 memset(itdev, 0, sizeof(struct it821x_dev));
619 601
620 pci_read_config_byte(pdev, 0x50, &conf); 602 pci_read_config_byte(pdev, 0x50, &conf);
621 603
@@ -646,20 +628,6 @@ static int it821x_port_start(struct ata_port *ap)
646 return 0; 628 return 0;
647} 629}
648 630
649/**
650 * it821x_port_stop - port shutdown
651 * @ap: ATA port being removed
652 *
653 * Release the private objects we added in it821x_port_start
654 */
655
656static void it821x_port_stop(struct ata_port *ap) {
657 kfree(ap->private_data);
658 ap->private_data = NULL; /* We want an OOPS if we reuse this
659 too late! */
660 ata_port_stop(ap);
661}
662
663static struct scsi_host_template it821x_sht = { 631static struct scsi_host_template it821x_sht = {
664 .module = THIS_MODULE, 632 .module = THIS_MODULE,
665 .name = DRV_NAME, 633 .name = DRV_NAME,
@@ -706,14 +674,14 @@ static struct ata_port_operations it821x_smart_port_ops = {
706 .qc_prep = ata_qc_prep, 674 .qc_prep = ata_qc_prep,
707 .qc_issue = it821x_smart_qc_issue_prot, 675 .qc_issue = it821x_smart_qc_issue_prot,
708 676
709 .data_xfer = ata_pio_data_xfer, 677 .data_xfer = ata_data_xfer,
710 678
711 .irq_handler = ata_interrupt, 679 .irq_handler = ata_interrupt,
712 .irq_clear = ata_bmdma_irq_clear, 680 .irq_clear = ata_bmdma_irq_clear,
681 .irq_on = ata_irq_on,
682 .irq_ack = ata_irq_ack,
713 683
714 .port_start = it821x_port_start, 684 .port_start = it821x_port_start,
715 .port_stop = it821x_port_stop,
716 .host_stop = ata_host_stop
717}; 685};
718 686
719static struct ata_port_operations it821x_passthru_port_ops = { 687static struct ata_port_operations it821x_passthru_port_ops = {
@@ -742,14 +710,14 @@ static struct ata_port_operations it821x_passthru_port_ops = {
742 .qc_prep = ata_qc_prep, 710 .qc_prep = ata_qc_prep,
743 .qc_issue = it821x_passthru_qc_issue_prot, 711 .qc_issue = it821x_passthru_qc_issue_prot,
744 712
745 .data_xfer = ata_pio_data_xfer, 713 .data_xfer = ata_data_xfer,
746 714
747 .irq_clear = ata_bmdma_irq_clear, 715 .irq_clear = ata_bmdma_irq_clear,
748 .irq_handler = ata_interrupt, 716 .irq_handler = ata_interrupt,
717 .irq_on = ata_irq_on,
718 .irq_ack = ata_irq_ack,
749 719
750 .port_start = it821x_port_start, 720 .port_start = it821x_port_start,
751 .port_stop = it821x_port_stop,
752 .host_stop = ata_host_stop
753}; 721};
754 722
755static void __devinit it821x_disable_raid(struct pci_dev *pdev) 723static void __devinit it821x_disable_raid(struct pci_dev *pdev)
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index 23b8aab3ebd..3222ac7b945 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -95,14 +95,6 @@ static void ixp4xx_irq_clear(struct ata_port *ap)
95{ 95{
96} 96}
97 97
98static void ixp4xx_host_stop (struct ata_host *host)
99{
100 struct ixp4xx_pata_data *data = host->dev->platform_data;
101
102 iounmap(data->cs0);
103 iounmap(data->cs1);
104}
105
106static struct scsi_host_template ixp4xx_sht = { 98static struct scsi_host_template ixp4xx_sht = {
107 .module = THIS_MODULE, 99 .module = THIS_MODULE,
108 .name = DRV_NAME, 100 .name = DRV_NAME,
@@ -139,10 +131,10 @@ static struct ata_port_operations ixp4xx_port_ops = {
139 131
140 .irq_handler = ata_interrupt, 132 .irq_handler = ata_interrupt,
141 .irq_clear = ixp4xx_irq_clear, 133 .irq_clear = ixp4xx_irq_clear,
134 .irq_on = ata_irq_on,
135 .irq_ack = ata_irq_ack,
142 136
143 .port_start = ata_port_start, 137 .port_start = ata_port_start,
144 .port_stop = ata_port_stop,
145 .host_stop = ixp4xx_host_stop,
146 138
147 .phy_reset = ixp4xx_phy_reset, 139 .phy_reset = ixp4xx_phy_reset,
148}; 140};
@@ -150,9 +142,9 @@ static struct ata_port_operations ixp4xx_port_ops = {
150static void ixp4xx_setup_port(struct ata_ioports *ioaddr, 142static void ixp4xx_setup_port(struct ata_ioports *ioaddr,
151 struct ixp4xx_pata_data *data) 143 struct ixp4xx_pata_data *data)
152{ 144{
153 ioaddr->cmd_addr = (unsigned long) data->cs0; 145 ioaddr->cmd_addr = data->cs0;
154 ioaddr->altstatus_addr = (unsigned long) data->cs1 + 0x06; 146 ioaddr->altstatus_addr = data->cs1 + 0x06;
155 ioaddr->ctl_addr = (unsigned long) data->cs1 + 0x06; 147 ioaddr->ctl_addr = data->cs1 + 0x06;
156 148
157 ata_std_ports(ioaddr); 149 ata_std_ports(ioaddr);
158 150
@@ -162,19 +154,19 @@ static void ixp4xx_setup_port(struct ata_ioports *ioaddr,
162 * ixp4xx in little endian mode. 154 * ixp4xx in little endian mode.
163 */ 155 */
164 156
165 ioaddr->data_addr ^= 0x02; 157 *(unsigned long *)&ioaddr->data_addr ^= 0x02;
166 ioaddr->cmd_addr ^= 0x03; 158 *(unsigned long *)&ioaddr->cmd_addr ^= 0x03;
167 ioaddr->altstatus_addr ^= 0x03; 159 *(unsigned long *)&ioaddr->altstatus_addr ^= 0x03;
168 ioaddr->ctl_addr ^= 0x03; 160 *(unsigned long *)&ioaddr->ctl_addr ^= 0x03;
169 ioaddr->error_addr ^= 0x03; 161 *(unsigned long *)&ioaddr->error_addr ^= 0x03;
170 ioaddr->feature_addr ^= 0x03; 162 *(unsigned long *)&ioaddr->feature_addr ^= 0x03;
171 ioaddr->nsect_addr ^= 0x03; 163 *(unsigned long *)&ioaddr->nsect_addr ^= 0x03;
172 ioaddr->lbal_addr ^= 0x03; 164 *(unsigned long *)&ioaddr->lbal_addr ^= 0x03;
173 ioaddr->lbam_addr ^= 0x03; 165 *(unsigned long *)&ioaddr->lbam_addr ^= 0x03;
174 ioaddr->lbah_addr ^= 0x03; 166 *(unsigned long *)&ioaddr->lbah_addr ^= 0x03;
175 ioaddr->device_addr ^= 0x03; 167 *(unsigned long *)&ioaddr->device_addr ^= 0x03;
176 ioaddr->status_addr ^= 0x03; 168 *(unsigned long *)&ioaddr->status_addr ^= 0x03;
177 ioaddr->command_addr ^= 0x03; 169 *(unsigned long *)&ioaddr->command_addr ^= 0x03;
178#endif 170#endif
179} 171}
180 172
@@ -195,8 +187,8 @@ static __devinit int ixp4xx_pata_probe(struct platform_device *pdev)
195 187
196 pdev->dev.coherent_dma_mask = DMA_32BIT_MASK; 188 pdev->dev.coherent_dma_mask = DMA_32BIT_MASK;
197 189
198 data->cs0 = ioremap(cs0->start, 0x1000); 190 data->cs0 = devm_ioremap(&pdev->dev, cs0->start, 0x1000);
199 data->cs1 = ioremap(cs1->start, 0x1000); 191 data->cs1 = devm_ioremap(&pdev->dev, cs1->start, 0x1000);
200 192
201 irq = platform_get_irq(pdev, 0); 193 irq = platform_get_irq(pdev, 0);
202 if (irq) 194 if (irq)
@@ -238,7 +230,7 @@ static __devexit int ixp4xx_pata_remove(struct platform_device *dev)
238{ 230{
239 struct ata_host *host = platform_get_drvdata(dev); 231 struct ata_host *host = platform_get_drvdata(dev);
240 232
241 ata_host_remove(host); 233 ata_host_detach(host);
242 platform_set_drvdata(dev, NULL); 234 platform_set_drvdata(dev, NULL);
243 235
244 return 0; 236 return 0;
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index d50264af284..7a635dd326f 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -161,16 +161,16 @@ static const struct ata_port_operations jmicron_ops = {
161 .bmdma_status = ata_bmdma_status, 161 .bmdma_status = ata_bmdma_status,
162 .qc_prep = ata_qc_prep, 162 .qc_prep = ata_qc_prep,
163 .qc_issue = ata_qc_issue_prot, 163 .qc_issue = ata_qc_issue_prot,
164 .data_xfer = ata_pio_data_xfer, 164 .data_xfer = ata_data_xfer,
165 165
166 /* IRQ-related hooks */ 166 /* IRQ-related hooks */
167 .irq_handler = ata_interrupt, 167 .irq_handler = ata_interrupt,
168 .irq_clear = ata_bmdma_irq_clear, 168 .irq_clear = ata_bmdma_irq_clear,
169 .irq_on = ata_irq_on,
170 .irq_ack = ata_irq_ack,
169 171
170 /* Generic PATA PCI ATA helpers */ 172 /* Generic PATA PCI ATA helpers */
171 .port_start = ata_port_start, 173 .port_start = ata_port_start,
172 .port_stop = ata_port_stop,
173 .host_stop = ata_host_stop,
174}; 174};
175 175
176 176
@@ -221,7 +221,7 @@ static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *i
221static int jmicron_reinit_one(struct pci_dev *pdev) 221static int jmicron_reinit_one(struct pci_dev *pdev)
222{ 222{
223 u32 reg; 223 u32 reg;
224 224
225 switch(pdev->device) { 225 switch(pdev->device) {
226 case PCI_DEVICE_ID_JMICRON_JMB368: 226 case PCI_DEVICE_ID_JMICRON_JMB368:
227 break; 227 break;
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index 581cb33c6f4..4223e10de6a 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -164,14 +164,14 @@ static struct ata_port_operations simple_port_ops = {
164 .qc_prep = ata_qc_prep, 164 .qc_prep = ata_qc_prep,
165 .qc_issue = ata_qc_issue_prot, 165 .qc_issue = ata_qc_issue_prot,
166 166
167 .data_xfer = ata_pio_data_xfer_noirq, 167 .data_xfer = ata_data_xfer_noirq,
168 168
169 .irq_handler = ata_interrupt, 169 .irq_handler = ata_interrupt,
170 .irq_clear = ata_bmdma_irq_clear, 170 .irq_clear = ata_bmdma_irq_clear,
171 .irq_on = ata_irq_on,
172 .irq_ack = ata_irq_ack,
171 173
172 .port_start = ata_port_start, 174 .port_start = ata_port_start,
173 .port_stop = ata_port_stop,
174 .host_stop = ata_host_stop
175}; 175};
176 176
177static struct ata_port_operations legacy_port_ops = { 177static struct ata_port_operations legacy_port_ops = {
@@ -189,14 +189,14 @@ static struct ata_port_operations legacy_port_ops = {
189 .qc_prep = ata_qc_prep, 189 .qc_prep = ata_qc_prep,
190 .qc_issue = ata_qc_issue_prot, 190 .qc_issue = ata_qc_issue_prot,
191 191
192 .data_xfer = ata_pio_data_xfer_noirq, 192 .data_xfer = ata_data_xfer_noirq,
193 193
194 .irq_handler = ata_interrupt, 194 .irq_handler = ata_interrupt,
195 .irq_clear = ata_bmdma_irq_clear, 195 .irq_clear = ata_bmdma_irq_clear,
196 .irq_on = ata_irq_on,
197 .irq_ack = ata_irq_ack,
196 198
197 .port_start = ata_port_start, 199 .port_start = ata_port_start,
198 .port_stop = ata_port_stop,
199 .host_stop = ata_host_stop
200}; 200};
201 201
202/* 202/*
@@ -257,31 +257,33 @@ static void pdc_data_xfer_vlb(struct ata_device *adev, unsigned char *buf, unsig
257 local_irq_save(flags); 257 local_irq_save(flags);
258 258
259 /* Perform the 32bit I/O synchronization sequence */ 259 /* Perform the 32bit I/O synchronization sequence */
260 inb(ap->ioaddr.nsect_addr); 260 ioread8(ap->ioaddr.nsect_addr);
261 inb(ap->ioaddr.nsect_addr); 261 ioread8(ap->ioaddr.nsect_addr);
262 inb(ap->ioaddr.nsect_addr); 262 ioread8(ap->ioaddr.nsect_addr);
263 263
264 /* Now the data */ 264 /* Now the data */
265 265
266 if (write_data) 266 if (write_data)
267 outsl(ap->ioaddr.data_addr, buf, buflen >> 2); 267 iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
268 else 268 else
269 insl(ap->ioaddr.data_addr, buf, buflen >> 2); 269 ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
270 270
271 if (unlikely(slop)) { 271 if (unlikely(slop)) {
272 u32 pad; 272 u32 pad;
273 if (write_data) { 273 if (write_data) {
274 memcpy(&pad, buf + buflen - slop, slop); 274 memcpy(&pad, buf + buflen - slop, slop);
275 outl(le32_to_cpu(pad), ap->ioaddr.data_addr); 275 pad = le32_to_cpu(pad);
276 iowrite32(pad, ap->ioaddr.data_addr);
276 } else { 277 } else {
277 pad = cpu_to_le16(inl(ap->ioaddr.data_addr)); 278 pad = ioread32(ap->ioaddr.data_addr);
279 pad = cpu_to_le16(pad);
278 memcpy(buf + buflen - slop, &pad, slop); 280 memcpy(buf + buflen - slop, &pad, slop);
279 } 281 }
280 } 282 }
281 local_irq_restore(flags); 283 local_irq_restore(flags);
282 } 284 }
283 else 285 else
284 ata_pio_data_xfer_noirq(adev, buf, buflen, write_data); 286 ata_data_xfer_noirq(adev, buf, buflen, write_data);
285} 287}
286 288
287static struct ata_port_operations pdc20230_port_ops = { 289static struct ata_port_operations pdc20230_port_ops = {
@@ -303,10 +305,10 @@ static struct ata_port_operations pdc20230_port_ops = {
303 305
304 .irq_handler = ata_interrupt, 306 .irq_handler = ata_interrupt,
305 .irq_clear = ata_bmdma_irq_clear, 307 .irq_clear = ata_bmdma_irq_clear,
308 .irq_on = ata_irq_on,
309 .irq_ack = ata_irq_ack,
306 310
307 .port_start = ata_port_start, 311 .port_start = ata_port_start,
308 .port_stop = ata_port_stop,
309 .host_stop = ata_host_stop
310}; 312};
311 313
312/* 314/*
@@ -332,8 +334,8 @@ static void ht6560a_set_piomode(struct ata_port *ap, struct ata_device *adev)
332 inb(0x3E6); 334 inb(0x3E6);
333 inb(0x3E6); 335 inb(0x3E6);
334 336
335 outb(recover << 4 | active, ap->ioaddr.device_addr); 337 iowrite8(recover << 4 | active, ap->ioaddr.device_addr);
336 inb(ap->ioaddr.status_addr); 338 ioread8(ap->ioaddr.status_addr);
337} 339}
338 340
339static struct ata_port_operations ht6560a_port_ops = { 341static struct ata_port_operations ht6560a_port_ops = {
@@ -351,14 +353,14 @@ static struct ata_port_operations ht6560a_port_ops = {
351 .qc_prep = ata_qc_prep, 353 .qc_prep = ata_qc_prep,
352 .qc_issue = ata_qc_issue_prot, 354 .qc_issue = ata_qc_issue_prot,
353 355
354 .data_xfer = ata_pio_data_xfer, /* Check vlb/noirq */ 356 .data_xfer = ata_data_xfer, /* Check vlb/noirq */
355 357
356 .irq_handler = ata_interrupt, 358 .irq_handler = ata_interrupt,
357 .irq_clear = ata_bmdma_irq_clear, 359 .irq_clear = ata_bmdma_irq_clear,
360 .irq_on = ata_irq_on,
361 .irq_ack = ata_irq_ack,
358 362
359 .port_start = ata_port_start, 363 .port_start = ata_port_start,
360 .port_stop = ata_port_stop,
361 .host_stop = ata_host_stop
362}; 364};
363 365
364/* 366/*
@@ -387,7 +389,7 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
387 inb(0x3E6); 389 inb(0x3E6);
388 inb(0x3E6); 390 inb(0x3E6);
389 391
390 outb(recover << 4 | active, ap->ioaddr.device_addr); 392 iowrite8(recover << 4 | active, ap->ioaddr.device_addr);
391 393
392 if (adev->class != ATA_DEV_ATA) { 394 if (adev->class != ATA_DEV_ATA) {
393 u8 rconf = inb(0x3E6); 395 u8 rconf = inb(0x3E6);
@@ -396,7 +398,7 @@ static void ht6560b_set_piomode(struct ata_port *ap, struct ata_device *adev)
396 outb(rconf, 0x3E6); 398 outb(rconf, 0x3E6);
397 } 399 }
398 } 400 }
399 inb(ap->ioaddr.status_addr); 401 ioread8(ap->ioaddr.status_addr);
400} 402}
401 403
402static struct ata_port_operations ht6560b_port_ops = { 404static struct ata_port_operations ht6560b_port_ops = {
@@ -414,14 +416,14 @@ static struct ata_port_operations ht6560b_port_ops = {
414 .qc_prep = ata_qc_prep, 416 .qc_prep = ata_qc_prep,
415 .qc_issue = ata_qc_issue_prot, 417 .qc_issue = ata_qc_issue_prot,
416 418
417 .data_xfer = ata_pio_data_xfer, /* FIXME: Check 32bit and noirq */ 419 .data_xfer = ata_data_xfer, /* FIXME: Check 32bit and noirq */
418 420
419 .irq_handler = ata_interrupt, 421 .irq_handler = ata_interrupt,
420 .irq_clear = ata_bmdma_irq_clear, 422 .irq_clear = ata_bmdma_irq_clear,
423 .irq_on = ata_irq_on,
424 .irq_ack = ata_irq_ack,
421 425
422 .port_start = ata_port_start, 426 .port_start = ata_port_start,
423 .port_stop = ata_port_stop,
424 .host_stop = ata_host_stop
425}; 427};
426 428
427/* 429/*
@@ -464,12 +466,12 @@ static void opti82c611a_set_piomode(struct ata_port *ap, struct ata_device *adev
464 u8 rc; 466 u8 rc;
465 467
466 /* Enter configuration mode */ 468 /* Enter configuration mode */
467 inw(ap->ioaddr.error_addr); 469 ioread16(ap->ioaddr.error_addr);
468 inw(ap->ioaddr.error_addr); 470 ioread16(ap->ioaddr.error_addr);
469 outb(3, ap->ioaddr.nsect_addr); 471 iowrite8(3, ap->ioaddr.nsect_addr);
470 472
471 /* Read VLB clock strapping */ 473 /* Read VLB clock strapping */
472 clock = 1000000000 / khz[inb(ap->ioaddr.lbah_addr) & 0x03]; 474 clock = 1000000000 / khz[ioread8(ap->ioaddr.lbah_addr) & 0x03];
473 475
474 /* Get the timing data in cycles */ 476 /* Get the timing data in cycles */
475 ata_timing_compute(adev, adev->pio_mode, &t, clock, 1000); 477 ata_timing_compute(adev, adev->pio_mode, &t, clock, 1000);
@@ -487,33 +489,33 @@ static void opti82c611a_set_piomode(struct ata_port *ap, struct ata_device *adev
487 setup = FIT(t.setup, 1, 4) - 1; 489 setup = FIT(t.setup, 1, 4) - 1;
488 490
489 /* Select the right timing bank for write timing */ 491 /* Select the right timing bank for write timing */
490 rc = inb(ap->ioaddr.lbal_addr); 492 rc = ioread8(ap->ioaddr.lbal_addr);
491 rc &= 0x7F; 493 rc &= 0x7F;
492 rc |= (adev->devno << 7); 494 rc |= (adev->devno << 7);
493 outb(rc, ap->ioaddr.lbal_addr); 495 iowrite8(rc, ap->ioaddr.lbal_addr);
494 496
495 /* Write the timings */ 497 /* Write the timings */
496 outb(active << 4 | recover, ap->ioaddr.error_addr); 498 iowrite8(active << 4 | recover, ap->ioaddr.error_addr);
497 499
498 /* Select the right bank for read timings, also 500 /* Select the right bank for read timings, also
499 load the shared timings for address */ 501 load the shared timings for address */
500 rc = inb(ap->ioaddr.device_addr); 502 rc = ioread8(ap->ioaddr.device_addr);
501 rc &= 0xC0; 503 rc &= 0xC0;
502 rc |= adev->devno; /* Index select */ 504 rc |= adev->devno; /* Index select */
503 rc |= (setup << 4) | 0x04; 505 rc |= (setup << 4) | 0x04;
504 outb(rc, ap->ioaddr.device_addr); 506 iowrite8(rc, ap->ioaddr.device_addr);
505 507
506 /* Load the read timings */ 508 /* Load the read timings */
507 outb(active << 4 | recover, ap->ioaddr.data_addr); 509 iowrite8(active << 4 | recover, ap->ioaddr.data_addr);
508 510
509 /* Ensure the timing register mode is right */ 511 /* Ensure the timing register mode is right */
510 rc = inb (ap->ioaddr.lbal_addr); 512 rc = ioread8(ap->ioaddr.lbal_addr);
511 rc &= 0x73; 513 rc &= 0x73;
512 rc |= 0x84; 514 rc |= 0x84;
513 outb(rc, ap->ioaddr.lbal_addr); 515 iowrite8(rc, ap->ioaddr.lbal_addr);
514 516
515 /* Exit command mode */ 517 /* Exit command mode */
516 outb(0x83, ap->ioaddr.nsect_addr); 518 iowrite8(0x83, ap->ioaddr.nsect_addr);
517} 519}
518 520
519 521
@@ -532,14 +534,14 @@ static struct ata_port_operations opti82c611a_port_ops = {
532 .qc_prep = ata_qc_prep, 534 .qc_prep = ata_qc_prep,
533 .qc_issue = ata_qc_issue_prot, 535 .qc_issue = ata_qc_issue_prot,
534 536
535 .data_xfer = ata_pio_data_xfer, 537 .data_xfer = ata_data_xfer,
536 538
537 .irq_handler = ata_interrupt, 539 .irq_handler = ata_interrupt,
538 .irq_clear = ata_bmdma_irq_clear, 540 .irq_clear = ata_bmdma_irq_clear,
541 .irq_on = ata_irq_on,
542 .irq_ack = ata_irq_ack,
539 543
540 .port_start = ata_port_start, 544 .port_start = ata_port_start,
541 .port_stop = ata_port_stop,
542 .host_stop = ata_host_stop
543}; 545};
544 546
545/* 547/*
@@ -563,9 +565,9 @@ static void opti82c46x_set_piomode(struct ata_port *ap, struct ata_device *adev)
563 sysclk = opti_syscfg(0xAC) & 0xC0; /* BIOS set */ 565 sysclk = opti_syscfg(0xAC) & 0xC0; /* BIOS set */
564 566
565 /* Enter configuration mode */ 567 /* Enter configuration mode */
566 inw(ap->ioaddr.error_addr); 568 ioread16(ap->ioaddr.error_addr);
567 inw(ap->ioaddr.error_addr); 569 ioread16(ap->ioaddr.error_addr);
568 outb(3, ap->ioaddr.nsect_addr); 570 iowrite8(3, ap->ioaddr.nsect_addr);
569 571
570 /* Read VLB clock strapping */ 572 /* Read VLB clock strapping */
571 clock = 1000000000 / khz[sysclk]; 573 clock = 1000000000 / khz[sysclk];
@@ -586,33 +588,33 @@ static void opti82c46x_set_piomode(struct ata_port *ap, struct ata_device *adev)
586 setup = FIT(t.setup, 1, 4) - 1; 588 setup = FIT(t.setup, 1, 4) - 1;
587 589
588 /* Select the right timing bank for write timing */ 590 /* Select the right timing bank for write timing */
589 rc = inb(ap->ioaddr.lbal_addr); 591 rc = ioread8(ap->ioaddr.lbal_addr);
590 rc &= 0x7F; 592 rc &= 0x7F;
591 rc |= (adev->devno << 7); 593 rc |= (adev->devno << 7);
592 outb(rc, ap->ioaddr.lbal_addr); 594 iowrite8(rc, ap->ioaddr.lbal_addr);
593 595
594 /* Write the timings */ 596 /* Write the timings */
595 outb(active << 4 | recover, ap->ioaddr.error_addr); 597 iowrite8(active << 4 | recover, ap->ioaddr.error_addr);
596 598
597 /* Select the right bank for read timings, also 599 /* Select the right bank for read timings, also
598 load the shared timings for address */ 600 load the shared timings for address */
599 rc = inb(ap->ioaddr.device_addr); 601 rc = ioread8(ap->ioaddr.device_addr);
600 rc &= 0xC0; 602 rc &= 0xC0;
601 rc |= adev->devno; /* Index select */ 603 rc |= adev->devno; /* Index select */
602 rc |= (setup << 4) | 0x04; 604 rc |= (setup << 4) | 0x04;
603 outb(rc, ap->ioaddr.device_addr); 605 iowrite8(rc, ap->ioaddr.device_addr);
604 606
605 /* Load the read timings */ 607 /* Load the read timings */
606 outb(active << 4 | recover, ap->ioaddr.data_addr); 608 iowrite8(active << 4 | recover, ap->ioaddr.data_addr);
607 609
608 /* Ensure the timing register mode is right */ 610 /* Ensure the timing register mode is right */
609 rc = inb (ap->ioaddr.lbal_addr); 611 rc = ioread8(ap->ioaddr.lbal_addr);
610 rc &= 0x73; 612 rc &= 0x73;
611 rc |= 0x84; 613 rc |= 0x84;
612 outb(rc, ap->ioaddr.lbal_addr); 614 iowrite8(rc, ap->ioaddr.lbal_addr);
613 615
614 /* Exit command mode */ 616 /* Exit command mode */
615 outb(0x83, ap->ioaddr.nsect_addr); 617 iowrite8(0x83, ap->ioaddr.nsect_addr);
616 618
617 /* We need to know this for quad device on the MVB */ 619 /* We need to know this for quad device on the MVB */
618 ap->host->private_data = ap; 620 ap->host->private_data = ap;
@@ -662,14 +664,14 @@ static struct ata_port_operations opti82c46x_port_ops = {
662 .qc_prep = ata_qc_prep, 664 .qc_prep = ata_qc_prep,
663 .qc_issue = opti82c46x_qc_issue_prot, 665 .qc_issue = opti82c46x_qc_issue_prot,
664 666
665 .data_xfer = ata_pio_data_xfer, 667 .data_xfer = ata_data_xfer,
666 668
667 .irq_handler = ata_interrupt, 669 .irq_handler = ata_interrupt,
668 .irq_clear = ata_bmdma_irq_clear, 670 .irq_clear = ata_bmdma_irq_clear,
671 .irq_on = ata_irq_on,
672 .irq_ack = ata_irq_ack,
669 673
670 .port_start = ata_port_start, 674 .port_start = ata_port_start,
671 .port_stop = ata_port_stop,
672 .host_stop = ata_host_stop
673}; 675};
674 676
675 677
@@ -689,21 +691,26 @@ static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl
689 struct legacy_data *ld = &legacy_data[nr_legacy_host]; 691 struct legacy_data *ld = &legacy_data[nr_legacy_host];
690 struct ata_probe_ent ae; 692 struct ata_probe_ent ae;
691 struct platform_device *pdev; 693 struct platform_device *pdev;
692 int ret = -EBUSY;
693 struct ata_port_operations *ops = &legacy_port_ops; 694 struct ata_port_operations *ops = &legacy_port_ops;
695 void __iomem *io_addr, *ctrl_addr;
694 int pio_modes = pio_mask; 696 int pio_modes = pio_mask;
695 u32 mask = (1 << port); 697 u32 mask = (1 << port);
696 698 int ret;
697 if (request_region(io, 8, "pata_legacy") == NULL)
698 return -EBUSY;
699 if (request_region(ctrl, 1, "pata_legacy") == NULL)
700 goto fail_io;
701 699
702 pdev = platform_device_register_simple(DRV_NAME, nr_legacy_host, NULL, 0); 700 pdev = platform_device_register_simple(DRV_NAME, nr_legacy_host, NULL, 0);
703 if (IS_ERR(pdev)) { 701 if (IS_ERR(pdev))
704 ret = PTR_ERR(pdev); 702 return PTR_ERR(pdev);
705 goto fail_dev; 703
706 } 704 ret = -EBUSY;
705 if (devm_request_region(&pdev->dev, io, 8, "pata_legacy") == NULL ||
706 devm_request_region(&pdev->dev, ctrl, 1, "pata_legacy") == NULL)
707 goto fail;
708
709 ret = -ENOMEM;
710 io_addr = devm_ioport_map(&pdev->dev, io, 8);
711 ctrl_addr = devm_ioport_map(&pdev->dev, ctrl, 1);
712 if (!io_addr || !ctrl_addr)
713 goto fail;
707 714
708 if (ht6560a & mask) { 715 if (ht6560a & mask) {
709 ops = &ht6560a_port_ops; 716 ops = &ht6560a_port_ops;
@@ -770,27 +777,22 @@ static __init int legacy_init_one(int port, unsigned long io, unsigned long ctrl
770 ae.irq = irq; 777 ae.irq = irq;
771 ae.irq_flags = 0; 778 ae.irq_flags = 0;
772 ae.port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST; 779 ae.port_flags = ATA_FLAG_SLAVE_POSS|ATA_FLAG_SRST;
773 ae.port[0].cmd_addr = io; 780 ae.port[0].cmd_addr = io_addr;
774 ae.port[0].altstatus_addr = ctrl; 781 ae.port[0].altstatus_addr = ctrl_addr;
775 ae.port[0].ctl_addr = ctrl; 782 ae.port[0].ctl_addr = ctrl_addr;
776 ata_std_ports(&ae.port[0]); 783 ata_std_ports(&ae.port[0]);
777 ae.private_data = ld; 784 ae.private_data = ld;
778 785
779 ret = ata_device_add(&ae); 786 ret = -ENODEV;
780 if (ret == 0) { 787 if (!ata_device_add(&ae))
781 ret = -ENODEV;
782 goto fail; 788 goto fail;
783 } 789
784 legacy_host[nr_legacy_host++] = dev_get_drvdata(&pdev->dev); 790 legacy_host[nr_legacy_host++] = dev_get_drvdata(&pdev->dev);
785 ld->platform_dev = pdev; 791 ld->platform_dev = pdev;
786 return 0; 792 return 0;
787 793
788fail: 794fail:
789 platform_device_unregister(pdev); 795 platform_device_unregister(pdev);
790fail_dev:
791 release_region(ctrl, 1);
792fail_io:
793 release_region(io, 8);
794 return ret; 796 return ret;
795} 797}
796 798
@@ -923,15 +925,11 @@ static __exit void legacy_exit(void)
923 925
924 for (i = 0; i < nr_legacy_host; i++) { 926 for (i = 0; i < nr_legacy_host; i++) {
925 struct legacy_data *ld = &legacy_data[i]; 927 struct legacy_data *ld = &legacy_data[i];
926 struct ata_port *ap =legacy_host[i]->ports[0]; 928
927 unsigned long io = ap->ioaddr.cmd_addr; 929 ata_host_detach(legacy_host[i]);
928 unsigned long ctrl = ap->ioaddr.ctl_addr;
929 ata_host_remove(legacy_host[i]);
930 platform_device_unregister(ld->platform_dev); 930 platform_device_unregister(ld->platform_dev);
931 if (ld->timing) 931 if (ld->timing)
932 release_region(ld->timing, 2); 932 release_region(ld->timing, 2);
933 release_region(io, 8);
934 release_region(ctrl, 1);
935 } 933 }
936} 934}
937 935
diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
index 1c810ea0025..13a70ac6f1d 100644
--- a/drivers/ata/pata_marvell.c
+++ b/drivers/ata/pata_marvell.c
@@ -45,10 +45,10 @@ static int marvell_pre_reset(struct ata_port *ap)
45 for(i = 0; i <= 0x0F; i++) 45 for(i = 0; i <= 0x0F; i++)
46 printk("%02X:%02X ", i, readb(barp + i)); 46 printk("%02X:%02X ", i, readb(barp + i));
47 printk("\n"); 47 printk("\n");
48 48
49 devices = readl(barp + 0x0C); 49 devices = readl(barp + 0x0C);
50 pci_iounmap(pdev, barp); 50 pci_iounmap(pdev, barp);
51 51
52 if ((pdev->device == 0x6145) && (ap->port_no == 0) && 52 if ((pdev->device == 0x6145) && (ap->port_no == 0) &&
53 (!(devices & 0x10))) /* PATA enable ? */ 53 (!(devices & 0x10))) /* PATA enable ? */
54 return -ENOENT; 54 return -ENOENT;
@@ -57,7 +57,7 @@ static int marvell_pre_reset(struct ata_port *ap)
57 switch(ap->port_no) 57 switch(ap->port_no)
58 { 58 {
59 case 0: 59 case 0:
60 if (inb(ap->ioaddr.bmdma_addr + 1) & 1) 60 if (ioread8(ap->ioaddr.bmdma_addr + 1) & 1)
61 ap->cbl = ATA_CBL_PATA40; 61 ap->cbl = ATA_CBL_PATA40;
62 else 62 else
63 ap->cbl = ATA_CBL_PATA80; 63 ap->cbl = ATA_CBL_PATA80;
@@ -129,16 +129,16 @@ static const struct ata_port_operations marvell_ops = {
129 .bmdma_status = ata_bmdma_status, 129 .bmdma_status = ata_bmdma_status,
130 .qc_prep = ata_qc_prep, 130 .qc_prep = ata_qc_prep,
131 .qc_issue = ata_qc_issue_prot, 131 .qc_issue = ata_qc_issue_prot,
132 .data_xfer = ata_pio_data_xfer, 132 .data_xfer = ata_data_xfer,
133 133
134 /* Timeout handling */ 134 /* Timeout handling */
135 .irq_handler = ata_interrupt, 135 .irq_handler = ata_interrupt,
136 .irq_clear = ata_bmdma_irq_clear, 136 .irq_clear = ata_bmdma_irq_clear,
137 .irq_on = ata_irq_on,
138 .irq_ack = ata_irq_ack,
137 139
138 /* Generic PATA PCI ATA helpers */ 140 /* Generic PATA PCI ATA helpers */
139 .port_start = ata_port_start, 141 .port_start = ata_port_start,
140 .port_stop = ata_port_stop,
141 .host_stop = ata_host_stop,
142}; 142};
143 143
144 144
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
new file mode 100644
index 00000000000..d7378df4497
--- /dev/null
+++ b/drivers/ata/pata_mpc52xx.c
@@ -0,0 +1,538 @@
1/*
2 * drivers/ata/pata_mpc52xx.c
3 *
4 * libata driver for the Freescale MPC52xx on-chip IDE interface
5 *
6 * Copyright (C) 2006 Sylvain Munaut <tnt@246tNt.com>
7 * Copyright (C) 2003 Mipsys - Benjamin Herrenschmidt
8 *
9 * This file is licensed under the terms of the GNU General Public License
10 * version 2. This program is licensed "as is" without any warranty of any
11 * kind, whether express or implied.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/slab.h>
17#include <linux/delay.h>
18#include <linux/libata.h>
19
20#include <asm/types.h>
21#include <asm/prom.h>
22#include <asm/of_platform.h>
23#include <asm/mpc52xx.h>
24
25
26#define DRV_NAME "mpc52xx_ata"
27#define DRV_VERSION "0.1.0"
28
29
30/* Private structures used by the driver */
31struct mpc52xx_ata_timings {
32 u32 pio1;
33 u32 pio2;
34};
35
36struct mpc52xx_ata_priv {
37 unsigned int ipb_period;
38 struct mpc52xx_ata __iomem * ata_regs;
39 int ata_irq;
40 struct mpc52xx_ata_timings timings[2];
41 int csel;
42};
43
44
45/* ATAPI-4 PIO specs (in ns) */
46static const int ataspec_t0[5] = {600, 383, 240, 180, 120};
47static const int ataspec_t1[5] = { 70, 50, 30, 30, 25};
48static const int ataspec_t2_8[5] = {290, 290, 290, 80, 70};
49static const int ataspec_t2_16[5] = {165, 125, 100, 80, 70};
50static const int ataspec_t2i[5] = { 0, 0, 0, 70, 25};
51static const int ataspec_t4[5] = { 30, 20, 15, 10, 10};
52static const int ataspec_ta[5] = { 35, 35, 35, 35, 35};
53
54#define CALC_CLKCYC(c,v) ((((v)+(c)-1)/(c)))
55
56
57/* Bit definitions inside the registers */
58#define MPC52xx_ATA_HOSTCONF_SMR 0x80000000UL /* State machine reset */
59#define MPC52xx_ATA_HOSTCONF_FR 0x40000000UL /* FIFO Reset */
60#define MPC52xx_ATA_HOSTCONF_IE 0x02000000UL /* Enable interrupt in PIO */
61#define MPC52xx_ATA_HOSTCONF_IORDY 0x01000000UL /* Drive supports IORDY protocol */
62
63#define MPC52xx_ATA_HOSTSTAT_TIP 0x80000000UL /* Transaction in progress */
64#define MPC52xx_ATA_HOSTSTAT_UREP 0x40000000UL /* UDMA Read Extended Pause */
65#define MPC52xx_ATA_HOSTSTAT_RERR 0x02000000UL /* Read Error */
66#define MPC52xx_ATA_HOSTSTAT_WERR 0x01000000UL /* Write Error */
67
68#define MPC52xx_ATA_FIFOSTAT_EMPTY 0x01 /* FIFO Empty */
69
70#define MPC52xx_ATA_DMAMODE_WRITE 0x01 /* Write DMA */
71#define MPC52xx_ATA_DMAMODE_READ 0x02 /* Read DMA */
72#define MPC52xx_ATA_DMAMODE_UDMA 0x04 /* UDMA enabled */
73#define MPC52xx_ATA_DMAMODE_IE 0x08 /* Enable drive interrupt to CPU in DMA mode */
74#define MPC52xx_ATA_DMAMODE_FE 0x10 /* FIFO Flush enable in Rx mode */
75#define MPC52xx_ATA_DMAMODE_FR 0x20 /* FIFO Reset */
76#define MPC52xx_ATA_DMAMODE_HUT 0x40 /* Host UDMA burst terminate */
77
78
79/* Structure of the hardware registers */
80struct mpc52xx_ata {
81
82 /* Host interface registers */
83 u32 config; /* ATA + 0x00 Host configuration */
84 u32 host_status; /* ATA + 0x04 Host controller status */
85 u32 pio1; /* ATA + 0x08 PIO Timing 1 */
86 u32 pio2; /* ATA + 0x0c PIO Timing 2 */
87 u32 mdma1; /* ATA + 0x10 MDMA Timing 1 */
88 u32 mdma2; /* ATA + 0x14 MDMA Timing 2 */
89 u32 udma1; /* ATA + 0x18 UDMA Timing 1 */
90 u32 udma2; /* ATA + 0x1c UDMA Timing 2 */
91 u32 udma3; /* ATA + 0x20 UDMA Timing 3 */
92 u32 udma4; /* ATA + 0x24 UDMA Timing 4 */
93 u32 udma5; /* ATA + 0x28 UDMA Timing 5 */
94 u32 share_cnt; /* ATA + 0x2c ATA share counter */
95 u32 reserved0[3];
96
97 /* FIFO registers */
98 u32 fifo_data; /* ATA + 0x3c */
99 u8 fifo_status_frame; /* ATA + 0x40 */
100 u8 fifo_status; /* ATA + 0x41 */
101 u16 reserved7[1];
102 u8 fifo_control; /* ATA + 0x44 */
103 u8 reserved8[5];
104 u16 fifo_alarm; /* ATA + 0x4a */
105 u16 reserved9;
106 u16 fifo_rdp; /* ATA + 0x4e */
107 u16 reserved10;
108 u16 fifo_wrp; /* ATA + 0x52 */
109 u16 reserved11;
110 u16 fifo_lfrdp; /* ATA + 0x56 */
111 u16 reserved12;
112 u16 fifo_lfwrp; /* ATA + 0x5a */
113
114 /* Drive TaskFile registers */
115 u8 tf_control; /* ATA + 0x5c TASKFILE Control/Alt Status */
116 u8 reserved13[3];
117 u16 tf_data; /* ATA + 0x60 TASKFILE Data */
118 u16 reserved14;
119 u8 tf_features; /* ATA + 0x64 TASKFILE Features/Error */
120 u8 reserved15[3];
121 u8 tf_sec_count; /* ATA + 0x68 TASKFILE Sector Count */
122 u8 reserved16[3];
123 u8 tf_sec_num; /* ATA + 0x6c TASKFILE Sector Number */
124 u8 reserved17[3];
125 u8 tf_cyl_low; /* ATA + 0x70 TASKFILE Cylinder Low */
126 u8 reserved18[3];
127 u8 tf_cyl_high; /* ATA + 0x74 TASKFILE Cylinder High */
128 u8 reserved19[3];
129 u8 tf_dev_head; /* ATA + 0x78 TASKFILE Device/Head */
130 u8 reserved20[3];
131 u8 tf_command; /* ATA + 0x7c TASKFILE Command/Status */
132 u8 dma_mode; /* ATA + 0x7d ATA Host DMA Mode configuration */
133 u8 reserved21[2];
134};
135
136
137/* ======================================================================== */
138/* Aux fns */
139/* ======================================================================== */
140
141
142/* MPC52xx low level hw control */
143
144static int
145mpc52xx_ata_compute_pio_timings(struct mpc52xx_ata_priv *priv, int dev, int pio)
146{
147 struct mpc52xx_ata_timings *timing = &priv->timings[dev];
148 unsigned int ipb_period = priv->ipb_period;
149 unsigned int t0, t1, t2_8, t2_16, t2i, t4, ta;
150
151 if ((pio<0) || (pio>4))
152 return -EINVAL;
153
154 t0 = CALC_CLKCYC(ipb_period, 1000 * ataspec_t0[pio]);
155 t1 = CALC_CLKCYC(ipb_period, 1000 * ataspec_t1[pio]);
156 t2_8 = CALC_CLKCYC(ipb_period, 1000 * ataspec_t2_8[pio]);
157 t2_16 = CALC_CLKCYC(ipb_period, 1000 * ataspec_t2_16[pio]);
158 t2i = CALC_CLKCYC(ipb_period, 1000 * ataspec_t2i[pio]);
159 t4 = CALC_CLKCYC(ipb_period, 1000 * ataspec_t4[pio]);
160 ta = CALC_CLKCYC(ipb_period, 1000 * ataspec_ta[pio]);
161
162 timing->pio1 = (t0 << 24) | (t2_8 << 16) | (t2_16 << 8) | (t2i);
163 timing->pio2 = (t4 << 24) | (t1 << 16) | (ta << 8);
164
165 return 0;
166}
167
168static void
169mpc52xx_ata_apply_timings(struct mpc52xx_ata_priv *priv, int device)
170{
171 struct mpc52xx_ata __iomem *regs = priv->ata_regs;
172 struct mpc52xx_ata_timings *timing = &priv->timings[device];
173
174 out_be32(&regs->pio1, timing->pio1);
175 out_be32(&regs->pio2, timing->pio2);
176 out_be32(&regs->mdma1, 0);
177 out_be32(&regs->mdma2, 0);
178 out_be32(&regs->udma1, 0);
179 out_be32(&regs->udma2, 0);
180 out_be32(&regs->udma3, 0);
181 out_be32(&regs->udma4, 0);
182 out_be32(&regs->udma5, 0);
183
184 priv->csel = device;
185}
186
187static int
188mpc52xx_ata_hw_init(struct mpc52xx_ata_priv *priv)
189{
190 struct mpc52xx_ata __iomem *regs = priv->ata_regs;
191 int tslot;
192
193 /* Clear share_cnt (all sample code do this ...) */
194 out_be32(&regs->share_cnt, 0);
195
196 /* Configure and reset host */
197 out_be32(&regs->config,
198 MPC52xx_ATA_HOSTCONF_IE |
199 MPC52xx_ATA_HOSTCONF_IORDY |
200 MPC52xx_ATA_HOSTCONF_SMR |
201 MPC52xx_ATA_HOSTCONF_FR);
202
203 udelay(10);
204
205 out_be32(&regs->config,
206 MPC52xx_ATA_HOSTCONF_IE |
207 MPC52xx_ATA_HOSTCONF_IORDY);
208
209 /* Set the time slot to 1us */
210 tslot = CALC_CLKCYC(priv->ipb_period, 1000000);
211 out_be32(&regs->share_cnt, tslot << 16 );
212
213 /* Init timings to PIO0 */
214 memset(priv->timings, 0x00, 2*sizeof(struct mpc52xx_ata_timings));
215
216 mpc52xx_ata_compute_pio_timings(priv, 0, 0);
217 mpc52xx_ata_compute_pio_timings(priv, 1, 0);
218
219 mpc52xx_ata_apply_timings(priv, 0);
220
221 return 0;
222}
223
224
225/* ======================================================================== */
226/* libata driver */
227/* ======================================================================== */
228
229static void
230mpc52xx_ata_set_piomode(struct ata_port *ap, struct ata_device *adev)
231{
232 struct mpc52xx_ata_priv *priv = ap->host->private_data;
233 int pio, rv;
234
235 pio = adev->pio_mode - XFER_PIO_0;
236
237 rv = mpc52xx_ata_compute_pio_timings(priv, adev->devno, pio);
238
239 if (rv) {
240 printk(KERN_ERR DRV_NAME
241 ": Trying to select invalid PIO mode %d\n", pio);
242 return;
243 }
244
245 mpc52xx_ata_apply_timings(priv, adev->devno);
246}
247static void
248mpc52xx_ata_dev_select(struct ata_port *ap, unsigned int device)
249{
250 struct mpc52xx_ata_priv *priv = ap->host->private_data;
251
252 if (device != priv->csel)
253 mpc52xx_ata_apply_timings(priv, device);
254
255 ata_std_dev_select(ap,device);
256}
257
258static void
259mpc52xx_ata_error_handler(struct ata_port *ap)
260{
261 ata_bmdma_drive_eh(ap, ata_std_prereset, ata_std_softreset, NULL,
262 ata_std_postreset);
263}
264
265
266
267static struct scsi_host_template mpc52xx_ata_sht = {
268 .module = THIS_MODULE,
269 .name = DRV_NAME,
270 .ioctl = ata_scsi_ioctl,
271 .queuecommand = ata_scsi_queuecmd,
272 .can_queue = ATA_DEF_QUEUE,
273 .this_id = ATA_SHT_THIS_ID,
274 .sg_tablesize = LIBATA_MAX_PRD,
275 .max_sectors = ATA_MAX_SECTORS,
276 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
277 .emulated = ATA_SHT_EMULATED,
278 .use_clustering = ATA_SHT_USE_CLUSTERING,
279 .proc_name = DRV_NAME,
280 .dma_boundary = ATA_DMA_BOUNDARY,
281 .slave_configure = ata_scsi_slave_config,
282 .bios_param = ata_std_bios_param,
283};
284
285static struct ata_port_operations mpc52xx_ata_port_ops = {
286 .port_disable = ata_port_disable,
287 .set_piomode = mpc52xx_ata_set_piomode,
288 .dev_select = mpc52xx_ata_dev_select,
289 .tf_load = ata_tf_load,
290 .tf_read = ata_tf_read,
291 .check_status = ata_check_status,
292 .exec_command = ata_exec_command,
293 .freeze = ata_bmdma_freeze,
294 .thaw = ata_bmdma_thaw,
295 .error_handler = mpc52xx_ata_error_handler,
296 .qc_prep = ata_qc_prep,
297 .qc_issue = ata_qc_issue_prot,
298 .data_xfer = ata_data_xfer,
299 .irq_handler = ata_interrupt,
300 .irq_clear = ata_bmdma_irq_clear,
301 .irq_on = ata_irq_on,
302 .irq_ack = ata_irq_ack,
303 .port_start = ata_port_start,
304};
305
306static struct ata_probe_ent mpc52xx_ata_probe_ent = {
307 .port_ops = &mpc52xx_ata_port_ops,
308 .sht = &mpc52xx_ata_sht,
309 .n_ports = 1,
310 .pio_mask = 0x1f, /* Up to PIO4 */
311 .mwdma_mask = 0x00, /* No MWDMA */
312 .udma_mask = 0x00, /* No UDMA */
313 .port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
314 .irq_flags = 0,
315};
316
317static int __devinit
318mpc52xx_ata_init_one(struct device *dev, struct mpc52xx_ata_priv *priv)
319{
320 struct ata_probe_ent *ae = &mpc52xx_ata_probe_ent;
321 struct ata_ioports *aio = &ae->port[0];
322 int rv;
323
324 INIT_LIST_HEAD(&ae->node);
325 ae->dev = dev;
326 ae->irq = priv->ata_irq;
327
328 aio->cmd_addr = 0; /* Don't have a classic reg block */
329 aio->altstatus_addr = &priv->ata_regs->tf_control;
330 aio->ctl_addr = &priv->ata_regs->tf_control;
331 aio->data_addr = &priv->ata_regs->tf_data;
332 aio->error_addr = &priv->ata_regs->tf_features;
333 aio->feature_addr = &priv->ata_regs->tf_features;
334 aio->nsect_addr = &priv->ata_regs->tf_sec_count;
335 aio->lbal_addr = &priv->ata_regs->tf_sec_num;
336 aio->lbam_addr = &priv->ata_regs->tf_cyl_low;
337 aio->lbah_addr = &priv->ata_regs->tf_cyl_high;
338 aio->device_addr = &priv->ata_regs->tf_dev_head;
339 aio->status_addr = &priv->ata_regs->tf_command;
340 aio->command_addr = &priv->ata_regs->tf_command;
341
342 ae->private_data = priv;
343
344 rv = ata_device_add(ae);
345
346 return rv ? 0 : -EINVAL;
347}
348
349static struct mpc52xx_ata_priv *
350mpc52xx_ata_remove_one(struct device *dev)
351{
352 struct ata_host *host = dev_get_drvdata(dev);
353 struct mpc52xx_ata_priv *priv = host->private_data;
354
355 ata_host_detach(host);
356
357 return priv;
358}
359
360
361/* ======================================================================== */
362/* OF Platform driver */
363/* ======================================================================== */
364
365static int __devinit
366mpc52xx_ata_probe(struct of_device *op, const struct of_device_id *match)
367{
368 unsigned int ipb_freq;
369 struct resource res_mem;
370 int ata_irq = NO_IRQ;
371 struct mpc52xx_ata __iomem *ata_regs;
372 struct mpc52xx_ata_priv *priv;
373 int rv;
374
375 /* Get ipb frequency */
376 ipb_freq = mpc52xx_find_ipb_freq(op->node);
377 if (!ipb_freq) {
378 printk(KERN_ERR DRV_NAME ": "
379 "Unable to find IPB Bus frequency\n" );
380 return -ENODEV;
381 }
382
383 /* Get IRQ and register */
384 rv = of_address_to_resource(op->node, 0, &res_mem);
385 if (rv) {
386 printk(KERN_ERR DRV_NAME ": "
387 "Error while parsing device node resource\n" );
388 return rv;
389 }
390
391 ata_irq = irq_of_parse_and_map(op->node, 0);
392 if (ata_irq == NO_IRQ) {
393 printk(KERN_ERR DRV_NAME ": "
394 "Error while mapping the irq\n");
395 return -EINVAL;
396 }
397
398 /* Request mem region */
399 if (!devm_request_mem_region(&op->dev, res_mem.start,
400 sizeof(struct mpc52xx_ata), DRV_NAME)) {
401 printk(KERN_ERR DRV_NAME ": "
402 "Error while requesting mem region\n");
403 rv = -EBUSY;
404 goto err;
405 }
406
407 /* Remap registers */
408 ata_regs = devm_ioremap(&op->dev, res_mem.start,
409 sizeof(struct mpc52xx_ata));
410 if (!ata_regs) {
411 printk(KERN_ERR DRV_NAME ": "
412 "Error while mapping register set\n");
413 rv = -ENOMEM;
414 goto err;
415 }
416
417 /* Prepare our private structure */
418 priv = devm_kzalloc(&op->dev, sizeof(struct mpc52xx_ata_priv),
419 GFP_ATOMIC);
420 if (!priv) {
421 printk(KERN_ERR DRV_NAME ": "
422 "Error while allocating private structure\n");
423 rv = -ENOMEM;
424 goto err;
425 }
426
427 priv->ipb_period = 1000000000 / (ipb_freq / 1000);
428 priv->ata_regs = ata_regs;
429 priv->ata_irq = ata_irq;
430 priv->csel = -1;
431
432 /* Init the hw */
433 rv = mpc52xx_ata_hw_init(priv);
434 if (rv) {
435 printk(KERN_ERR DRV_NAME ": Error during HW init\n");
436 goto err;
437 }
438
439 /* Register ourselves to libata */
440 rv = mpc52xx_ata_init_one(&op->dev, priv);
441 if (rv) {
442 printk(KERN_ERR DRV_NAME ": "
443 "Error while registering to ATA layer\n");
444 return rv;
445 }
446
447 /* Done */
448 return 0;
449
450 /* Error path */
451err:
452 irq_dispose_mapping(ata_irq);
453 return rv;
454}
455
456static int
457mpc52xx_ata_remove(struct of_device *op)
458{
459 struct mpc52xx_ata_priv *priv;
460
461 priv = mpc52xx_ata_remove_one(&op->dev);
462 irq_dispose_mapping(priv->ata_irq);
463
464 return 0;
465}
466
467
468#ifdef CONFIG_PM
469
470static int
471mpc52xx_ata_suspend(struct of_device *op, pm_message_t state)
472{
473 return 0; /* FIXME : What to do here ? */
474}
475
476static int
477mpc52xx_ata_resume(struct of_device *op)
478{
479 return 0; /* FIXME : What to do here ? */
480}
481
482#endif
483
484
485static struct of_device_id mpc52xx_ata_of_match[] = {
486 {
487 .compatible = "mpc5200-ata",
488 },
489 {
490 .compatible = "mpc52xx-ata",
491 },
492 {},
493};
494
495
496static struct of_platform_driver mpc52xx_ata_of_platform_driver = {
497 .owner = THIS_MODULE,
498 .name = DRV_NAME,
499 .match_table = mpc52xx_ata_of_match,
500 .probe = mpc52xx_ata_probe,
501 .remove = mpc52xx_ata_remove,
502#ifdef CONFIG_PM
503 .suspend = mpc52xx_ata_suspend,
504 .resume = mpc52xx_ata_resume,
505#endif
506 .driver = {
507 .name = DRV_NAME,
508 .owner = THIS_MODULE,
509 },
510};
511
512
513/* ======================================================================== */
514/* Module */
515/* ======================================================================== */
516
517static int __init
518mpc52xx_ata_init(void)
519{
520 printk(KERN_INFO "ata: MPC52xx IDE/ATA libata driver\n");
521 return of_register_platform_driver(&mpc52xx_ata_of_platform_driver);
522}
523
524static void __exit
525mpc52xx_ata_exit(void)
526{
527 of_unregister_platform_driver(&mpc52xx_ata_of_platform_driver);
528}
529
530module_init(mpc52xx_ata_init);
531module_exit(mpc52xx_ata_exit);
532
533MODULE_AUTHOR("Sylvain Munaut <tnt@246tNt.com>");
534MODULE_DESCRIPTION("Freescale MPC52xx IDE/ATA libata driver");
535MODULE_LICENSE("GPL");
536MODULE_DEVICE_TABLE(of, mpc52xx_ata_of_match);
537MODULE_VERSION(DRV_VERSION);
538
diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
index 4ccca938675..ca8c965179b 100644
--- a/drivers/ata/pata_mpiix.c
+++ b/drivers/ata/pata_mpiix.c
@@ -35,7 +35,7 @@
35#include <linux/libata.h> 35#include <linux/libata.h>
36 36
37#define DRV_NAME "pata_mpiix" 37#define DRV_NAME "pata_mpiix"
38#define DRV_VERSION "0.7.3" 38#define DRV_VERSION "0.7.5"
39 39
40enum { 40enum {
41 IDETIM = 0x6C, /* IDE control register */ 41 IDETIM = 0x6C, /* IDE control register */
@@ -49,12 +49,9 @@ enum {
49static int mpiix_pre_reset(struct ata_port *ap) 49static int mpiix_pre_reset(struct ata_port *ap)
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[] = { 52 static const struct pci_bits mpiix_enable_bits = { 0x6D, 1, 0x80, 0x80 };
53 { 0x6D, 1, 0x80, 0x80 },
54 { 0x6F, 1, 0x80, 0x80 }
55 };
56 53
57 if (!pci_test_config_bits(pdev, &mpiix_enable_bits[ap->port_no])) 54 if (!pci_test_config_bits(pdev, &mpiix_enable_bits))
58 return -ENOENT; 55 return -ENOENT;
59 ap->cbl = ATA_CBL_PATA40; 56 ap->cbl = ATA_CBL_PATA40;
60 return ata_std_prereset(ap); 57 return ata_std_prereset(ap);
@@ -80,8 +77,8 @@ static void mpiix_error_handler(struct ata_port *ap)
80 * @adev: ATA device 77 * @adev: ATA device
81 * 78 *
82 * Called to do the PIO mode setup. The MPIIX allows us to program the 79 * Called to do the PIO mode setup. The MPIIX allows us to program the
83 * IORDY sample point (2-5 clocks), recovery 1-4 clocks and whether 80 * IORDY sample point (2-5 clocks), recovery (1-4 clocks) and whether
84 * prefetching or iordy are used. 81 * prefetching or IORDY are used.
85 * 82 *
86 * This would get very ugly because we can only program timing for one 83 * This would get very ugly because we can only program timing for one
87 * device at a time, the other gets PIO0. Fortunately libata calls 84 * device at a time, the other gets PIO0. Fortunately libata calls
@@ -103,18 +100,19 @@ static void mpiix_set_piomode(struct ata_port *ap, struct ata_device *adev)
103 { 2, 3 }, }; 100 { 2, 3 }, };
104 101
105 pci_read_config_word(pdev, IDETIM, &idetim); 102 pci_read_config_word(pdev, IDETIM, &idetim);
106 /* Mask the IORDY/TIME/PPE0 bank for this device */ 103
104 /* Mask the IORDY/TIME/PPE for this device */
107 if (adev->class == ATA_DEV_ATA) 105 if (adev->class == ATA_DEV_ATA)
108 control |= PPE; /* PPE enable for disk */ 106 control |= PPE; /* Enable prefetch/posting for disk */
109 if (ata_pio_need_iordy(adev)) 107 if (ata_pio_need_iordy(adev))
110 control |= IORDY; /* IORDY */ 108 control |= IORDY;
111 if (pio > 0) 109 if (pio > 1)
112 control |= FTIM; /* This drive is on the fast timing bank */ 110 control |= FTIM; /* This drive is on the fast timing bank */
113 111
114 /* Mask out timing and clear both TIME bank selects */ 112 /* Mask out timing and clear both TIME bank selects */
115 idetim &= 0xCCEE; 113 idetim &= 0xCCEE;
116 idetim &= ~(0x07 << (2 * adev->devno)); 114 idetim &= ~(0x07 << (4 * adev->devno));
117 idetim |= (control << (2 * adev->devno)); 115 idetim |= control << (4 * adev->devno);
118 116
119 idetim |= (timings[pio][0] << 12) | (timings[pio][1] << 8); 117 idetim |= (timings[pio][0] << 12) | (timings[pio][1] << 8);
120 pci_write_config_word(pdev, IDETIM, idetim); 118 pci_write_config_word(pdev, IDETIM, idetim);
@@ -188,23 +186,24 @@ static struct ata_port_operations mpiix_port_ops = {
188 186
189 .qc_prep = ata_qc_prep, 187 .qc_prep = ata_qc_prep,
190 .qc_issue = mpiix_qc_issue_prot, 188 .qc_issue = mpiix_qc_issue_prot,
191 .data_xfer = ata_pio_data_xfer, 189 .data_xfer = ata_data_xfer,
192 190
193 .irq_handler = ata_interrupt, 191 .irq_handler = ata_interrupt,
194 .irq_clear = ata_bmdma_irq_clear, 192 .irq_clear = ata_bmdma_irq_clear,
193 .irq_on = ata_irq_on,
194 .irq_ack = ata_irq_ack,
195 195
196 .port_start = ata_port_start, 196 .port_start = ata_port_start,
197 .port_stop = ata_port_stop,
198 .host_stop = ata_host_stop
199}; 197};
200 198
201static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id) 199static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id)
202{ 200{
203 /* Single threaded by the PCI probe logic */ 201 /* Single threaded by the PCI probe logic */
204 static struct ata_probe_ent probe[2]; 202 static struct ata_probe_ent probe;
205 static int printed_version; 203 static int printed_version;
204 void __iomem *cmd_addr, *ctl_addr;
206 u16 idetim; 205 u16 idetim;
207 int enabled; 206 int irq;
208 207
209 if (!printed_version++) 208 if (!printed_version++)
210 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n"); 209 dev_printk(KERN_DEBUG, &dev->dev, "version " DRV_VERSION "\n");
@@ -217,65 +216,49 @@ static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id)
217 if (!(idetim & ENABLED)) 216 if (!(idetim & ENABLED))
218 return -ENODEV; 217 return -ENODEV;
219 218
219 /* See if it's primary or secondary channel... */
220 if (!(idetim & SECONDARY)) {
221 irq = 14;
222 cmd_addr = devm_ioport_map(&dev->dev, 0x1F0, 8);
223 ctl_addr = devm_ioport_map(&dev->dev, 0x3F6, 1);
224 } else {
225 irq = 15;
226 cmd_addr = devm_ioport_map(&dev->dev, 0x170, 8);
227 ctl_addr = devm_ioport_map(&dev->dev, 0x376, 1);
228 }
229
230 if (!cmd_addr || !ctl_addr)
231 return -ENOMEM;
232
220 /* We do our own plumbing to avoid leaking special cases for whacko 233 /* We do our own plumbing to avoid leaking special cases for whacko
221 ancient hardware into the core code. There are two issues to 234 ancient hardware into the core code. There are two issues to
222 worry about. #1 The chip is a bridge so if in legacy mode and 235 worry about. #1 The chip is a bridge so if in legacy mode and
223 without BARs set fools the setup. #2 If you pci_disable_device 236 without BARs set fools the setup. #2 If you pci_disable_device
224 the MPIIX your box goes castors up */ 237 the MPIIX your box goes castors up */
225 238
226 INIT_LIST_HEAD(&probe[0].node); 239 INIT_LIST_HEAD(&probe.node);
227 probe[0].dev = pci_dev_to_dev(dev); 240 probe.dev = pci_dev_to_dev(dev);
228 probe[0].port_ops = &mpiix_port_ops; 241 probe.port_ops = &mpiix_port_ops;
229 probe[0].sht = &mpiix_sht; 242 probe.sht = &mpiix_sht;
230 probe[0].pio_mask = 0x1F; 243 probe.pio_mask = 0x1F;
231 probe[0].irq = 14; 244 probe.irq_flags = SA_SHIRQ;
232 probe[0].irq_flags = SA_SHIRQ; 245 probe.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
233 probe[0].port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST; 246 probe.n_ports = 1;
234 probe[0].n_ports = 1; 247
235 probe[0].port[0].cmd_addr = 0x1F0; 248 probe.irq = irq;
236 probe[0].port[0].ctl_addr = 0x3F6; 249 probe.port[0].cmd_addr = cmd_addr;
237 probe[0].port[0].altstatus_addr = 0x3F6; 250 probe.port[0].ctl_addr = ctl_addr;
238 251 probe.port[0].altstatus_addr = ctl_addr;
239 /* The secondary lurks at different addresses but is otherwise
240 the same beastie */
241
242 INIT_LIST_HEAD(&probe[1].node);
243 probe[1] = probe[0];
244 probe[1].irq = 15;
245 probe[1].port[0].cmd_addr = 0x170;
246 probe[1].port[0].ctl_addr = 0x376;
247 probe[1].port[0].altstatus_addr = 0x376;
248 252
249 /* Let libata fill in the port details */ 253 /* Let libata fill in the port details */
250 ata_std_ports(&probe[0].port[0]); 254 ata_std_ports(&probe.port[0]);
251 ata_std_ports(&probe[1].port[0]);
252 255
253 /* Now add the port that is active */ 256 /* Now add the port that is active */
254 enabled = (idetim & SECONDARY) ? 1 : 0; 257 if (ata_device_add(&probe))
255
256 if (ata_device_add(&probe[enabled]))
257 return 0; 258 return 0;
258 return -ENODEV; 259 return -ENODEV;
259} 260}
260 261
261/**
262 * mpiix_remove_one - device unload
263 * @pdev: PCI device being removed
264 *
265 * Handle an unplug/unload event for a PCI device. Unload the
266 * PCI driver but do not use the default handler as we *MUST NOT*
267 * disable the device as it has other functions.
268 */
269
270static void __devexit mpiix_remove_one(struct pci_dev *pdev)
271{
272 struct device *dev = pci_dev_to_dev(pdev);
273 struct ata_host *host = dev_get_drvdata(dev);
274
275 ata_host_remove(host);
276 dev_set_drvdata(dev, NULL);
277}
278
279static const struct pci_device_id mpiix[] = { 262static const struct pci_device_id mpiix[] = {
280 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371MX), }, 263 { PCI_VDEVICE(INTEL, PCI_DEVICE_ID_INTEL_82371MX), },
281 264
@@ -286,7 +269,7 @@ static struct pci_driver mpiix_pci_driver = {
286 .name = DRV_NAME, 269 .name = DRV_NAME,
287 .id_table = mpiix, 270 .id_table = mpiix,
288 .probe = mpiix_init_one, 271 .probe = mpiix_init_one,
289 .remove = mpiix_remove_one, 272 .remove = ata_pci_remove_one,
290 .suspend = ata_pci_device_suspend, 273 .suspend = ata_pci_device_suspend,
291 .resume = ata_pci_device_resume, 274 .resume = ata_pci_device_resume,
292}; 275};
diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
index cf7fe037471..e8393e19be4 100644
--- a/drivers/ata/pata_netcell.c
+++ b/drivers/ata/pata_netcell.c
@@ -89,16 +89,16 @@ static const struct ata_port_operations netcell_ops = {
89 .bmdma_status = ata_bmdma_status, 89 .bmdma_status = ata_bmdma_status,
90 .qc_prep = ata_qc_prep, 90 .qc_prep = ata_qc_prep,
91 .qc_issue = ata_qc_issue_prot, 91 .qc_issue = ata_qc_issue_prot,
92 .data_xfer = ata_pio_data_xfer, 92 .data_xfer = ata_data_xfer,
93 93
94 /* IRQ-related hooks */ 94 /* IRQ-related hooks */
95 .irq_handler = ata_interrupt, 95 .irq_handler = ata_interrupt,
96 .irq_clear = ata_bmdma_irq_clear, 96 .irq_clear = ata_bmdma_irq_clear,
97 .irq_on = ata_irq_on,
98 .irq_ack = ata_irq_ack,
97 99
98 /* Generic PATA PCI ATA helpers */ 100 /* Generic PATA PCI ATA helpers */
99 .port_start = ata_port_start, 101 .port_start = ata_port_start,
100 .port_stop = ata_port_stop,
101 .host_stop = ata_host_stop,
102}; 102};
103 103
104 104
diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
index c3032eb9010..3d1fa487c48 100644
--- a/drivers/ata/pata_ns87410.c
+++ b/drivers/ata/pata_ns87410.c
@@ -179,14 +179,14 @@ static struct ata_port_operations ns87410_port_ops = {
179 .qc_prep = ata_qc_prep, 179 .qc_prep = ata_qc_prep,
180 .qc_issue = ns87410_qc_issue_prot, 180 .qc_issue = ns87410_qc_issue_prot,
181 181
182 .data_xfer = ata_pio_data_xfer, 182 .data_xfer = ata_data_xfer,
183 183
184 .irq_handler = ata_interrupt, 184 .irq_handler = ata_interrupt,
185 .irq_clear = ata_bmdma_irq_clear, 185 .irq_clear = ata_bmdma_irq_clear,
186 .irq_on = ata_irq_on,
187 .irq_ack = ata_irq_ack,
186 188
187 .port_start = ata_port_start, 189 .port_start = ata_port_start,
188 .port_stop = ata_port_stop,
189 .host_stop = ata_host_stop
190}; 190};
191 191
192static 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)
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index 10ac3cc1018..45215aa05e7 100644
--- a/drivers/ata/pata_oldpiix.c
+++ b/drivers/ata/pata_oldpiix.c
@@ -25,7 +25,7 @@
25#include <linux/ata.h> 25#include <linux/ata.h>
26 26
27#define DRV_NAME "pata_oldpiix" 27#define DRV_NAME "pata_oldpiix"
28#define DRV_VERSION "0.5.2" 28#define DRV_VERSION "0.5.3"
29 29
30/** 30/**
31 * oldpiix_pre_reset - probe begin 31 * oldpiix_pre_reset - probe begin
@@ -94,19 +94,21 @@ static void oldpiix_set_piomode (struct ata_port *ap, struct ata_device *adev)
94 { 2, 1 }, 94 { 2, 1 },
95 { 2, 3 }, }; 95 { 2, 3 }, };
96 96
97 if (pio > 2) 97 if (pio > 1)
98 control |= 1; /* TIME1 enable */ 98 control |= 1; /* TIME */
99 if (ata_pio_need_iordy(adev)) 99 if (ata_pio_need_iordy(adev))
100 control |= 2; /* IE IORDY */ 100 control |= 2; /* IE */
101 101
102 /* Intel specifies that the PPE functionality is for disk only */ 102 /* Intel specifies that the prefetch/posting is for disk only */
103 if (adev->class == ATA_DEV_ATA) 103 if (adev->class == ATA_DEV_ATA)
104 control |= 4; /* PPE enable */ 104 control |= 4; /* PPE */
105 105
106 pci_read_config_word(dev, idetm_port, &idetm_data); 106 pci_read_config_word(dev, idetm_port, &idetm_data);
107 107
108 /* Enable PPE, IE and TIME as appropriate. Clear the other 108 /*
109 drive timing bits */ 109 * Set PPE, IE and TIME as appropriate.
110 * Clear the other drive's timing bits.
111 */
110 if (adev->devno == 0) { 112 if (adev->devno == 0) {
111 idetm_data &= 0xCCE0; 113 idetm_data &= 0xCCE0;
112 idetm_data |= control; 114 idetm_data |= control;
@@ -259,14 +261,14 @@ static const struct ata_port_operations oldpiix_pata_ops = {
259 .bmdma_status = ata_bmdma_status, 261 .bmdma_status = ata_bmdma_status,
260 .qc_prep = ata_qc_prep, 262 .qc_prep = ata_qc_prep,
261 .qc_issue = oldpiix_qc_issue_prot, 263 .qc_issue = oldpiix_qc_issue_prot,
262 .data_xfer = ata_pio_data_xfer, 264 .data_xfer = ata_data_xfer,
263 265
264 .irq_handler = ata_interrupt, 266 .irq_handler = ata_interrupt,
265 .irq_clear = ata_bmdma_irq_clear, 267 .irq_clear = ata_bmdma_irq_clear,
268 .irq_on = ata_irq_on,
269 .irq_ack = ata_irq_ack,
266 270
267 .port_start = ata_port_start, 271 .port_start = ata_port_start,
268 .port_stop = ata_port_stop,
269 .host_stop = ata_host_stop,
270}; 272};
271 273
272 274
diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
index c2988b0aa8e..da1aa148b37 100644
--- a/drivers/ata/pata_opti.c
+++ b/drivers/ata/pata_opti.c
@@ -95,18 +95,18 @@ static void opti_error_handler(struct ata_port *ap)
95 95
96static void opti_write_reg(struct ata_port *ap, u8 val, int reg) 96static void opti_write_reg(struct ata_port *ap, u8 val, int reg)
97{ 97{
98 unsigned long regio = ap->ioaddr.cmd_addr; 98 void __iomem *regio = ap->ioaddr.cmd_addr;
99 99
100 /* These 3 unlock the control register access */ 100 /* These 3 unlock the control register access */
101 inw(regio + 1); 101 ioread16(regio + 1);
102 inw(regio + 1); 102 ioread16(regio + 1);
103 outb(3, regio + 2); 103 iowrite8(3, regio + 2);
104 104
105 /* Do the I/O */ 105 /* Do the I/O */
106 outb(val, regio + reg); 106 iowrite8(val, regio + reg);
107 107
108 /* Relock */ 108 /* Relock */
109 outb(0x83, regio + 2); 109 iowrite8(0x83, regio + 2);
110} 110}
111 111
112/** 112/**
@@ -124,7 +124,7 @@ static void opti_set_piomode(struct ata_port *ap, struct ata_device *adev)
124 struct ata_device *pair = ata_dev_pair(adev); 124 struct ata_device *pair = ata_dev_pair(adev);
125 int clock; 125 int clock;
126 int pio = adev->pio_mode - XFER_PIO_0; 126 int pio = adev->pio_mode - XFER_PIO_0;
127 unsigned long regio = ap->ioaddr.cmd_addr; 127 void __iomem *regio = ap->ioaddr.cmd_addr;
128 u8 addr; 128 u8 addr;
129 129
130 /* Address table precomputed with prefetch off and a DCLK of 2 */ 130 /* Address table precomputed with prefetch off and a DCLK of 2 */
@@ -137,8 +137,8 @@ static void opti_set_piomode(struct ata_port *ap, struct ata_device *adev)
137 { 0x58, 0x44, 0x32, 0x22, 0x21 } 137 { 0x58, 0x44, 0x32, 0x22, 0x21 }
138 }; 138 };
139 139
140 outb(0xff, regio + 5); 140 iowrite8(0xff, regio + 5);
141 clock = inw(regio + 5) & 1; 141 clock = ioread16(regio + 5) & 1;
142 142
143 /* 143 /*
144 * As with many controllers the address setup time is shared 144 * As with many controllers the address setup time is shared
@@ -205,14 +205,14 @@ static struct ata_port_operations opti_port_ops = {
205 .qc_prep = ata_qc_prep, 205 .qc_prep = ata_qc_prep,
206 .qc_issue = ata_qc_issue_prot, 206 .qc_issue = ata_qc_issue_prot,
207 207
208 .data_xfer = ata_pio_data_xfer, 208 .data_xfer = ata_data_xfer,
209 209
210 .irq_handler = ata_interrupt, 210 .irq_handler = ata_interrupt,
211 .irq_clear = ata_bmdma_irq_clear, 211 .irq_clear = ata_bmdma_irq_clear,
212 .irq_on = ata_irq_on,
213 .irq_ack = ata_irq_ack,
212 214
213 .port_start = ata_port_start, 215 .port_start = ata_port_start,
214 .port_stop = ata_port_stop,
215 .host_stop = ata_host_stop
216}; 216};
217 217
218static int opti_init_one(struct pci_dev *dev, const struct pci_device_id *id) 218static int opti_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
index 80d111c569d..d80b36e209c 100644
--- a/drivers/ata/pata_optidma.c
+++ b/drivers/ata/pata_optidma.c
@@ -91,12 +91,12 @@ static void optidma_error_handler(struct ata_port *ap)
91 91
92static void optidma_unlock(struct ata_port *ap) 92static void optidma_unlock(struct ata_port *ap)
93{ 93{
94 unsigned long regio = ap->ioaddr.cmd_addr; 94 void __iomem *regio = ap->ioaddr.cmd_addr;
95 95
96 /* These 3 unlock the control register access */ 96 /* These 3 unlock the control register access */
97 inw(regio + 1); 97 ioread16(regio + 1);
98 inw(regio + 1); 98 ioread16(regio + 1);
99 outb(3, regio + 2); 99 iowrite8(3, regio + 2);
100} 100}
101 101
102/** 102/**
@@ -108,10 +108,10 @@ static void optidma_unlock(struct ata_port *ap)
108 108
109static void optidma_lock(struct ata_port *ap) 109static void optidma_lock(struct ata_port *ap)
110{ 110{
111 unsigned long regio = ap->ioaddr.cmd_addr; 111 void __iomem *regio = ap->ioaddr.cmd_addr;
112 112
113 /* Relock */ 113 /* Relock */
114 outb(0x83, regio + 2); 114 iowrite8(0x83, regio + 2);
115} 115}
116 116
117/** 117/**
@@ -133,7 +133,7 @@ static void optidma_set_mode(struct ata_port *ap, struct ata_device *adev, u8 mo
133 struct ata_device *pair = ata_dev_pair(adev); 133 struct ata_device *pair = ata_dev_pair(adev);
134 int pio = adev->pio_mode - XFER_PIO_0; 134 int pio = adev->pio_mode - XFER_PIO_0;
135 int dma = adev->dma_mode - XFER_MW_DMA_0; 135 int dma = adev->dma_mode - XFER_MW_DMA_0;
136 unsigned long regio = ap->ioaddr.cmd_addr; 136 void __iomem *regio = ap->ioaddr.cmd_addr;
137 u8 addr; 137 u8 addr;
138 138
139 /* Address table precomputed with a DCLK of 2 */ 139 /* Address table precomputed with a DCLK of 2 */
@@ -178,20 +178,20 @@ static void optidma_set_mode(struct ata_port *ap, struct ata_device *adev, u8 mo
178 178
179 /* Commence primary programming sequence */ 179 /* Commence primary programming sequence */
180 /* First we load the device number into the timing select */ 180 /* First we load the device number into the timing select */
181 outb(adev->devno, regio + MISC_REG); 181 iowrite8(adev->devno, regio + MISC_REG);
182 /* Now we load the data timings into read data/write data */ 182 /* Now we load the data timings into read data/write data */
183 if (mode < XFER_MW_DMA_0) { 183 if (mode < XFER_MW_DMA_0) {
184 outb(data_rec_timing[pci_clock][pio], regio + READ_REG); 184 iowrite8(data_rec_timing[pci_clock][pio], regio + READ_REG);
185 outb(data_rec_timing[pci_clock][pio], regio + WRITE_REG); 185 iowrite8(data_rec_timing[pci_clock][pio], regio + WRITE_REG);
186 } else if (mode < XFER_UDMA_0) { 186 } else if (mode < XFER_UDMA_0) {
187 outb(dma_data_rec_timing[pci_clock][dma], regio + READ_REG); 187 iowrite8(dma_data_rec_timing[pci_clock][dma], regio + READ_REG);
188 outb(dma_data_rec_timing[pci_clock][dma], regio + WRITE_REG); 188 iowrite8(dma_data_rec_timing[pci_clock][dma], regio + WRITE_REG);
189 } 189 }
190 /* Finally we load the address setup into the misc register */ 190 /* Finally we load the address setup into the misc register */
191 outb(addr | adev->devno, regio + MISC_REG); 191 iowrite8(addr | adev->devno, regio + MISC_REG);
192 192
193 /* Programming sequence complete, timing 0 dev 0, timing 1 dev 1 */ 193 /* Programming sequence complete, timing 0 dev 0, timing 1 dev 1 */
194 outb(0x85, regio + CNTRL_REG); 194 iowrite8(0x85, regio + CNTRL_REG);
195 195
196 /* Switch back to IDE mode */ 196 /* Switch back to IDE mode */
197 optidma_lock(ap); 197 optidma_lock(ap);
@@ -389,14 +389,14 @@ static struct ata_port_operations optidma_port_ops = {
389 .qc_prep = ata_qc_prep, 389 .qc_prep = ata_qc_prep,
390 .qc_issue = ata_qc_issue_prot, 390 .qc_issue = ata_qc_issue_prot,
391 391
392 .data_xfer = ata_pio_data_xfer, 392 .data_xfer = ata_data_xfer,
393 393
394 .irq_handler = ata_interrupt, 394 .irq_handler = ata_interrupt,
395 .irq_clear = ata_bmdma_irq_clear, 395 .irq_clear = ata_bmdma_irq_clear,
396 .irq_on = ata_irq_on,
397 .irq_ack = ata_irq_ack,
396 398
397 .port_start = ata_port_start, 399 .port_start = ata_port_start,
398 .port_stop = ata_port_stop,
399 .host_stop = ata_host_stop
400}; 400};
401 401
402static struct ata_port_operations optiplus_port_ops = { 402static struct ata_port_operations optiplus_port_ops = {
@@ -424,14 +424,14 @@ static struct ata_port_operations optiplus_port_ops = {
424 .qc_prep = ata_qc_prep, 424 .qc_prep = ata_qc_prep,
425 .qc_issue = ata_qc_issue_prot, 425 .qc_issue = ata_qc_issue_prot,
426 426
427 .data_xfer = ata_pio_data_xfer, 427 .data_xfer = ata_data_xfer,
428 428
429 .irq_handler = ata_interrupt, 429 .irq_handler = ata_interrupt,
430 .irq_clear = ata_bmdma_irq_clear, 430 .irq_clear = ata_bmdma_irq_clear,
431 .irq_on = ata_irq_on,
432 .irq_ack = ata_irq_ack,
431 433
432 .port_start = ata_port_start, 434 .port_start = ata_port_start,
433 .port_stop = ata_port_stop,
434 .host_stop = ata_host_stop
435}; 435};
436 436
437/** 437/**
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index 9ed7f58424a..acfc09f9abd 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -88,14 +88,14 @@ static struct ata_port_operations pcmcia_port_ops = {
88 .qc_prep = ata_qc_prep, 88 .qc_prep = ata_qc_prep,
89 .qc_issue = ata_qc_issue_prot, 89 .qc_issue = ata_qc_issue_prot,
90 90
91 .data_xfer = ata_pio_data_xfer_noirq, 91 .data_xfer = ata_data_xfer_noirq,
92 92
93 .irq_handler = ata_interrupt, 93 .irq_handler = ata_interrupt,
94 .irq_clear = ata_bmdma_irq_clear, 94 .irq_clear = ata_bmdma_irq_clear,
95 .irq_on = ata_irq_on,
96 .irq_ack = ata_irq_ack,
95 97
96 .port_start = ata_port_start, 98 .port_start = ata_port_start,
97 .port_stop = ata_port_stop,
98 .host_stop = ata_host_stop
99}; 99};
100 100
101#define CS_CHECK(fn, ret) \ 101#define CS_CHECK(fn, ret) \
@@ -123,6 +123,7 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
123 cistpl_cftable_entry_t *cfg; 123 cistpl_cftable_entry_t *cfg;
124 int pass, last_ret = 0, last_fn = 0, is_kme = 0, ret = -ENOMEM; 124 int pass, last_ret = 0, last_fn = 0, is_kme = 0, ret = -ENOMEM;
125 unsigned long io_base, ctl_base; 125 unsigned long io_base, ctl_base;
126 void __iomem *io_addr, *ctl_addr;
126 127
127 info = kzalloc(sizeof(*info), GFP_KERNEL); 128 info = kzalloc(sizeof(*info), GFP_KERNEL);
128 if (info == NULL) 129 if (info == NULL)
@@ -233,10 +234,17 @@ next_entry:
233 CS_CHECK(RequestIRQ, pcmcia_request_irq(pdev, &pdev->irq)); 234 CS_CHECK(RequestIRQ, pcmcia_request_irq(pdev, &pdev->irq));
234 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(pdev, &pdev->conf)); 235 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(pdev, &pdev->conf));
235 236
237 /* iomap */
238 ret = -ENOMEM;
239 io_addr = devm_ioport_map(&pdev->dev, io_base, 8);
240 ctl_addr = devm_ioport_map(&pdev->dev, ctl_base, 1);
241 if (!io_addr || !ctl_addr)
242 goto failed;
243
236 /* Success. Disable the IRQ nIEN line, do quirks */ 244 /* Success. Disable the IRQ nIEN line, do quirks */
237 outb(0x02, ctl_base); 245 iowrite8(0x02, ctl_addr);
238 if (is_kme) 246 if (is_kme)
239 outb(0x81, ctl_base + 0x01); 247 iowrite8(0x81, ctl_addr + 0x01);
240 248
241 /* FIXME: Could be more ports at base + 0x10 but we only deal with 249 /* FIXME: Could be more ports at base + 0x10 but we only deal with
242 one right now */ 250 one right now */
@@ -258,11 +266,12 @@ next_entry:
258 ae.irq = pdev->irq.AssignedIRQ; 266 ae.irq = pdev->irq.AssignedIRQ;
259 ae.irq_flags = SA_SHIRQ; 267 ae.irq_flags = SA_SHIRQ;
260 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST; 268 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
261 ae.port[0].cmd_addr = io_base; 269 ae.port[0].cmd_addr = io_addr;
262 ae.port[0].altstatus_addr = ctl_base; 270 ae.port[0].altstatus_addr = ctl_addr;
263 ae.port[0].ctl_addr = ctl_base; 271 ae.port[0].ctl_addr = ctl_addr;
264 ata_std_ports(&ae.port[0]); 272 ata_std_ports(&ae.port[0]);
265 273
274 ret = -ENODEV;
266 if (ata_device_add(&ae) == 0) 275 if (ata_device_add(&ae) == 0)
267 goto failed; 276 goto failed;
268 277
@@ -298,7 +307,7 @@ static void pcmcia_remove_one(struct pcmcia_device *pdev)
298 /* If we have attached the device to the ATA layer, detach it */ 307 /* If we have attached the device to the ATA layer, detach it */
299 if (info->ndev) { 308 if (info->ndev) {
300 struct ata_host *host = dev_get_drvdata(dev); 309 struct ata_host *host = dev_get_drvdata(dev);
301 ata_host_remove(host); 310 ata_host_detach(host);
302 dev_set_drvdata(dev, NULL); 311 dev_set_drvdata(dev, NULL);
303 } 312 }
304 info->ndev = 0; 313 info->ndev = 0;
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index 76dd1c935db..ffa7f47fbb2 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -33,7 +33,6 @@
33#include <scsi/scsi_host.h> 33#include <scsi/scsi_host.h>
34#include <scsi/scsi_cmnd.h> 34#include <scsi/scsi_cmnd.h>
35#include <linux/libata.h> 35#include <linux/libata.h>
36#include <asm/io.h>
37 36
38#define DRV_NAME "pata_pdc2027x" 37#define DRV_NAME "pata_pdc2027x"
39#define DRV_VERSION "0.74-ac5" 38#define DRV_VERSION "0.74-ac5"
@@ -46,6 +45,8 @@
46#endif 45#endif
47 46
48enum { 47enum {
48 PDC_MMIO_BAR = 5,
49
49 PDC_UDMA_100 = 0, 50 PDC_UDMA_100 = 0,
50 PDC_UDMA_133 = 1, 51 PDC_UDMA_133 = 1,
51 52
@@ -62,7 +63,6 @@ enum {
62}; 63};
63 64
64static int pdc2027x_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 65static int pdc2027x_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
65static void pdc2027x_remove_one(struct pci_dev *pdev);
66static void pdc2027x_error_handler(struct ata_port *ap); 66static void pdc2027x_error_handler(struct ata_port *ap);
67static void pdc2027x_set_piomode(struct ata_port *ap, struct ata_device *adev); 67static void pdc2027x_set_piomode(struct ata_port *ap, struct ata_device *adev);
68static void pdc2027x_set_dmamode(struct ata_port *ap, struct ata_device *adev); 68static void pdc2027x_set_dmamode(struct ata_port *ap, struct ata_device *adev);
@@ -123,7 +123,7 @@ static struct pci_driver pdc2027x_pci_driver = {
123 .name = DRV_NAME, 123 .name = DRV_NAME,
124 .id_table = pdc2027x_pci_tbl, 124 .id_table = pdc2027x_pci_tbl,
125 .probe = pdc2027x_init_one, 125 .probe = pdc2027x_init_one,
126 .remove = __devexit_p(pdc2027x_remove_one), 126 .remove = ata_pci_remove_one,
127}; 127};
128 128
129static struct scsi_host_template pdc2027x_sht = { 129static struct scsi_host_template pdc2027x_sht = {
@@ -160,7 +160,7 @@ static struct ata_port_operations pdc2027x_pata100_ops = {
160 .bmdma_status = ata_bmdma_status, 160 .bmdma_status = ata_bmdma_status,
161 .qc_prep = ata_qc_prep, 161 .qc_prep = ata_qc_prep,
162 .qc_issue = ata_qc_issue_prot, 162 .qc_issue = ata_qc_issue_prot,
163 .data_xfer = ata_mmio_data_xfer, 163 .data_xfer = ata_data_xfer,
164 164
165 .freeze = ata_bmdma_freeze, 165 .freeze = ata_bmdma_freeze,
166 .thaw = ata_bmdma_thaw, 166 .thaw = ata_bmdma_thaw,
@@ -169,10 +169,10 @@ static struct ata_port_operations pdc2027x_pata100_ops = {
169 169
170 .irq_handler = ata_interrupt, 170 .irq_handler = ata_interrupt,
171 .irq_clear = ata_bmdma_irq_clear, 171 .irq_clear = ata_bmdma_irq_clear,
172 .irq_on = ata_irq_on,
173 .irq_ack = ata_irq_ack,
172 174
173 .port_start = ata_port_start, 175 .port_start = ata_port_start,
174 .port_stop = ata_port_stop,
175 .host_stop = ata_pci_host_stop,
176}; 176};
177 177
178static struct ata_port_operations pdc2027x_pata133_ops = { 178static struct ata_port_operations pdc2027x_pata133_ops = {
@@ -194,7 +194,7 @@ static struct ata_port_operations pdc2027x_pata133_ops = {
194 .bmdma_status = ata_bmdma_status, 194 .bmdma_status = ata_bmdma_status,
195 .qc_prep = ata_qc_prep, 195 .qc_prep = ata_qc_prep,
196 .qc_issue = ata_qc_issue_prot, 196 .qc_issue = ata_qc_issue_prot,
197 .data_xfer = ata_mmio_data_xfer, 197 .data_xfer = ata_data_xfer,
198 198
199 .freeze = ata_bmdma_freeze, 199 .freeze = ata_bmdma_freeze,
200 .thaw = ata_bmdma_thaw, 200 .thaw = ata_bmdma_thaw,
@@ -203,10 +203,10 @@ static struct ata_port_operations pdc2027x_pata133_ops = {
203 203
204 .irq_handler = ata_interrupt, 204 .irq_handler = ata_interrupt,
205 .irq_clear = ata_bmdma_irq_clear, 205 .irq_clear = ata_bmdma_irq_clear,
206 .irq_on = ata_irq_on,
207 .irq_ack = ata_irq_ack,
206 208
207 .port_start = ata_port_start, 209 .port_start = ata_port_start,
208 .port_stop = ata_port_stop,
209 .host_stop = ata_pci_host_stop,
210}; 210};
211 211
212static struct ata_port_info pdc2027x_port_info[] = { 212static struct ata_port_info pdc2027x_port_info[] = {
@@ -245,7 +245,7 @@ MODULE_DEVICE_TABLE(pci, pdc2027x_pci_tbl);
245 */ 245 */
246static inline void __iomem *port_mmio(struct ata_port *ap, unsigned int offset) 246static inline void __iomem *port_mmio(struct ata_port *ap, unsigned int offset)
247{ 247{
248 return ap->host->mmio_base + ap->port_no * 0x100 + offset; 248 return ap->host->iomap[PDC_MMIO_BAR] + ap->port_no * 0x100 + offset;
249} 249}
250 250
251/** 251/**
@@ -526,18 +526,19 @@ static int pdc2027x_check_atapi_dma(struct ata_queued_cmd *qc)
526 526
527static long pdc_read_counter(struct ata_probe_ent *probe_ent) 527static long pdc_read_counter(struct ata_probe_ent *probe_ent)
528{ 528{
529 void __iomem *mmio_base = probe_ent->iomap[PDC_MMIO_BAR];
529 long counter; 530 long counter;
530 int retry = 1; 531 int retry = 1;
531 u32 bccrl, bccrh, bccrlv, bccrhv; 532 u32 bccrl, bccrh, bccrlv, bccrhv;
532 533
533retry: 534retry:
534 bccrl = readl(probe_ent->mmio_base + PDC_BYTE_COUNT) & 0xffff; 535 bccrl = readl(mmio_base + PDC_BYTE_COUNT) & 0xffff;
535 bccrh = readl(probe_ent->mmio_base + PDC_BYTE_COUNT + 0x100) & 0xffff; 536 bccrh = readl(mmio_base + PDC_BYTE_COUNT + 0x100) & 0xffff;
536 rmb(); 537 rmb();
537 538
538 /* Read the counter values again for verification */ 539 /* Read the counter values again for verification */
539 bccrlv = readl(probe_ent->mmio_base + PDC_BYTE_COUNT) & 0xffff; 540 bccrlv = readl(mmio_base + PDC_BYTE_COUNT) & 0xffff;
540 bccrhv = readl(probe_ent->mmio_base + PDC_BYTE_COUNT + 0x100) & 0xffff; 541 bccrhv = readl(mmio_base + PDC_BYTE_COUNT + 0x100) & 0xffff;
541 rmb(); 542 rmb();
542 543
543 counter = (bccrh << 15) | bccrl; 544 counter = (bccrh << 15) | bccrl;
@@ -568,7 +569,7 @@ retry:
568 */ 569 */
569static void pdc_adjust_pll(struct ata_probe_ent *probe_ent, long pll_clock, unsigned int board_idx) 570static void pdc_adjust_pll(struct ata_probe_ent *probe_ent, long pll_clock, unsigned int board_idx)
570{ 571{
571 572 void __iomem *mmio_base = probe_ent->iomap[PDC_MMIO_BAR];
572 u16 pll_ctl; 573 u16 pll_ctl;
573 long pll_clock_khz = pll_clock / 1000; 574 long pll_clock_khz = pll_clock / 1000;
574 long pout_required = board_idx? PDC_133_MHZ:PDC_100_MHZ; 575 long pout_required = board_idx? PDC_133_MHZ:PDC_100_MHZ;
@@ -587,7 +588,7 @@ static void pdc_adjust_pll(struct ata_probe_ent *probe_ent, long pll_clock, unsi
587 /* Show the current clock value of PLL control register 588 /* Show the current clock value of PLL control register
588 * (maybe already configured by the firmware) 589 * (maybe already configured by the firmware)
589 */ 590 */
590 pll_ctl = readw(probe_ent->mmio_base + PDC_PLL_CTL); 591 pll_ctl = readw(mmio_base + PDC_PLL_CTL);
591 592
592 PDPRINTK("pll_ctl[%X]\n", pll_ctl); 593 PDPRINTK("pll_ctl[%X]\n", pll_ctl);
593#endif 594#endif
@@ -627,8 +628,8 @@ static void pdc_adjust_pll(struct ata_probe_ent *probe_ent, long pll_clock, unsi
627 628
628 PDPRINTK("Writing pll_ctl[%X]\n", pll_ctl); 629 PDPRINTK("Writing pll_ctl[%X]\n", pll_ctl);
629 630
630 writew(pll_ctl, probe_ent->mmio_base + PDC_PLL_CTL); 631 writew(pll_ctl, mmio_base + PDC_PLL_CTL);
631 readw(probe_ent->mmio_base + PDC_PLL_CTL); /* flush */ 632 readw(mmio_base + PDC_PLL_CTL); /* flush */
632 633
633 /* Wait the PLL circuit to be stable */ 634 /* Wait the PLL circuit to be stable */
634 mdelay(30); 635 mdelay(30);
@@ -638,7 +639,7 @@ static void pdc_adjust_pll(struct ata_probe_ent *probe_ent, long pll_clock, unsi
638 * Show the current clock value of PLL control register 639 * Show the current clock value of PLL control register
639 * (maybe configured by the firmware) 640 * (maybe configured by the firmware)
640 */ 641 */
641 pll_ctl = readw(probe_ent->mmio_base + PDC_PLL_CTL); 642 pll_ctl = readw(mmio_base + PDC_PLL_CTL);
642 643
643 PDPRINTK("pll_ctl[%X]\n", pll_ctl); 644 PDPRINTK("pll_ctl[%X]\n", pll_ctl);
644#endif 645#endif
@@ -654,6 +655,7 @@ static void pdc_adjust_pll(struct ata_probe_ent *probe_ent, long pll_clock, unsi
654 */ 655 */
655static long pdc_detect_pll_input_clock(struct ata_probe_ent *probe_ent) 656static long pdc_detect_pll_input_clock(struct ata_probe_ent *probe_ent)
656{ 657{
658 void __iomem *mmio_base = probe_ent->iomap[PDC_MMIO_BAR];
657 u32 scr; 659 u32 scr;
658 long start_count, end_count; 660 long start_count, end_count;
659 long pll_clock; 661 long pll_clock;
@@ -662,10 +664,10 @@ static long pdc_detect_pll_input_clock(struct ata_probe_ent *probe_ent)
662 start_count = pdc_read_counter(probe_ent); 664 start_count = pdc_read_counter(probe_ent);
663 665
664 /* Start the test mode */ 666 /* Start the test mode */
665 scr = readl(probe_ent->mmio_base + PDC_SYS_CTL); 667 scr = readl(mmio_base + PDC_SYS_CTL);
666 PDPRINTK("scr[%X]\n", scr); 668 PDPRINTK("scr[%X]\n", scr);
667 writel(scr | (0x01 << 14), probe_ent->mmio_base + PDC_SYS_CTL); 669 writel(scr | (0x01 << 14), mmio_base + PDC_SYS_CTL);
668 readl(probe_ent->mmio_base + PDC_SYS_CTL); /* flush */ 670 readl(mmio_base + PDC_SYS_CTL); /* flush */
669 671
670 /* Let the counter run for 100 ms. */ 672 /* Let the counter run for 100 ms. */
671 mdelay(100); 673 mdelay(100);
@@ -674,10 +676,10 @@ static long pdc_detect_pll_input_clock(struct ata_probe_ent *probe_ent)
674 end_count = pdc_read_counter(probe_ent); 676 end_count = pdc_read_counter(probe_ent);
675 677
676 /* Stop the test mode */ 678 /* Stop the test mode */
677 scr = readl(probe_ent->mmio_base + PDC_SYS_CTL); 679 scr = readl(mmio_base + PDC_SYS_CTL);
678 PDPRINTK("scr[%X]\n", scr); 680 PDPRINTK("scr[%X]\n", scr);
679 writel(scr & ~(0x01 << 14), probe_ent->mmio_base + PDC_SYS_CTL); 681 writel(scr & ~(0x01 << 14), mmio_base + PDC_SYS_CTL);
680 readl(probe_ent->mmio_base + PDC_SYS_CTL); /* flush */ 682 readl(mmio_base + PDC_SYS_CTL); /* flush */
681 683
682 /* calculate the input clock in Hz */ 684 /* calculate the input clock in Hz */
683 pll_clock = (start_count - end_count) * 10; 685 pll_clock = (start_count - end_count) * 10;
@@ -722,7 +724,7 @@ static int pdc_hardware_init(struct pci_dev *pdev, struct ata_probe_ent *pe, uns
722 * @port: ata ioports to setup 724 * @port: ata ioports to setup
723 * @base: base address 725 * @base: base address
724 */ 726 */
725static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base) 727static void pdc_ata_setup_port(struct ata_ioports *port, void __iomem *base)
726{ 728{
727 port->cmd_addr = 729 port->cmd_addr =
728 port->data_addr = base; 730 port->data_addr = base;
@@ -755,48 +757,37 @@ static int __devinit pdc2027x_init_one(struct pci_dev *pdev, const struct pci_de
755 static int printed_version; 757 static int printed_version;
756 unsigned int board_idx = (unsigned int) ent->driver_data; 758 unsigned int board_idx = (unsigned int) ent->driver_data;
757 759
758 struct ata_probe_ent *probe_ent = NULL; 760 struct ata_probe_ent *probe_ent;
759 unsigned long base;
760 void __iomem *mmio_base; 761 void __iomem *mmio_base;
761 int rc; 762 int rc;
762 763
763 if (!printed_version++) 764 if (!printed_version++)
764 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 765 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
765 766
766 rc = pci_enable_device(pdev); 767 rc = pcim_enable_device(pdev);
767 if (rc) 768 if (rc)
768 return rc; 769 return rc;
769 770
770 rc = pci_request_regions(pdev, DRV_NAME); 771 rc = pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME);
771 if (rc) 772 if (rc)
772 goto err_out; 773 return rc;
773 774
774 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 775 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
775 if (rc) 776 if (rc)
776 goto err_out_regions; 777 return rc;
777 778
778 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 779 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
779 if (rc) 780 if (rc)
780 goto err_out_regions; 781 return rc;
781 782
782 /* Prepare the probe entry */ 783 /* Prepare the probe entry */
783 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); 784 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
784 if (probe_ent == NULL) { 785 if (probe_ent == NULL)
785 rc = -ENOMEM; 786 return -ENOMEM;
786 goto err_out_regions;
787 }
788 787
789 probe_ent->dev = pci_dev_to_dev(pdev); 788 probe_ent->dev = pci_dev_to_dev(pdev);
790 INIT_LIST_HEAD(&probe_ent->node); 789 INIT_LIST_HEAD(&probe_ent->node);
791 790
792 mmio_base = pci_iomap(pdev, 5, 0);
793 if (!mmio_base) {
794 rc = -ENOMEM;
795 goto err_out_free_ent;
796 }
797
798 base = (unsigned long) mmio_base;
799
800 probe_ent->sht = pdc2027x_port_info[board_idx].sht; 791 probe_ent->sht = pdc2027x_port_info[board_idx].sht;
801 probe_ent->port_flags = pdc2027x_port_info[board_idx].flags; 792 probe_ent->port_flags = pdc2027x_port_info[board_idx].flags;
802 probe_ent->pio_mask = pdc2027x_port_info[board_idx].pio_mask; 793 probe_ent->pio_mask = pdc2027x_port_info[board_idx].pio_mask;
@@ -806,12 +797,14 @@ static int __devinit pdc2027x_init_one(struct pci_dev *pdev, const struct pci_de
806 797
807 probe_ent->irq = pdev->irq; 798 probe_ent->irq = pdev->irq;
808 probe_ent->irq_flags = SA_SHIRQ; 799 probe_ent->irq_flags = SA_SHIRQ;
809 probe_ent->mmio_base = mmio_base; 800 probe_ent->iomap = pcim_iomap_table(pdev);
810 801
811 pdc_ata_setup_port(&probe_ent->port[0], base + 0x17c0); 802 mmio_base = probe_ent->iomap[PDC_MMIO_BAR];
812 probe_ent->port[0].bmdma_addr = base + 0x1000; 803
813 pdc_ata_setup_port(&probe_ent->port[1], base + 0x15c0); 804 pdc_ata_setup_port(&probe_ent->port[0], mmio_base + 0x17c0);
814 probe_ent->port[1].bmdma_addr = base + 0x1008; 805 probe_ent->port[0].bmdma_addr = mmio_base + 0x1000;
806 pdc_ata_setup_port(&probe_ent->port[1], mmio_base + 0x15c0);
807 probe_ent->port[1].bmdma_addr = mmio_base + 0x1008;
815 808
816 probe_ent->n_ports = 2; 809 probe_ent->n_ports = 2;
817 810
@@ -820,32 +813,13 @@ static int __devinit pdc2027x_init_one(struct pci_dev *pdev, const struct pci_de
820 813
821 /* initialize adapter */ 814 /* initialize adapter */
822 if (pdc_hardware_init(pdev, probe_ent, board_idx) != 0) 815 if (pdc_hardware_init(pdev, probe_ent, board_idx) != 0)
823 goto err_out_free_ent; 816 return -EIO;
824 817
825 ata_device_add(probe_ent); 818 if (!ata_device_add(probe_ent))
826 kfree(probe_ent); 819 return -ENODEV;
827 820
821 devm_kfree(&pdev->dev, probe_ent);
828 return 0; 822 return 0;
829
830err_out_free_ent:
831 kfree(probe_ent);
832err_out_regions:
833 pci_release_regions(pdev);
834err_out:
835 pci_disable_device(pdev);
836 return rc;
837}
838
839/**
840 * pdc2027x_remove_one - Called to remove a single instance of the
841 * adapter.
842 *
843 * @dev: The PCI device to remove.
844 * FIXME: module load/unload not working yet
845 */
846static void __devexit pdc2027x_remove_one(struct pci_dev *pdev)
847{
848 ata_pci_remove_one(pdev);
849} 823}
850 824
851/** 825/**
diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
index ad691b9e774..6dd63413a52 100644
--- a/drivers/ata/pata_pdc202xx_old.c
+++ b/drivers/ata/pata_pdc202xx_old.c
@@ -170,17 +170,17 @@ static void pdc2026x_bmdma_start(struct ata_queued_cmd *qc)
170 struct ata_taskfile *tf = &qc->tf; 170 struct ata_taskfile *tf = &qc->tf;
171 int sel66 = ap->port_no ? 0x08: 0x02; 171 int sel66 = ap->port_no ? 0x08: 0x02;
172 172
173 unsigned long master = ap->host->ports[0]->ioaddr.bmdma_addr; 173 void __iomem *master = ap->host->ports[0]->ioaddr.bmdma_addr;
174 unsigned long clock = master + 0x11; 174 void __iomem *clock = master + 0x11;
175 unsigned long atapi_reg = master + 0x20 + (4 * ap->port_no); 175 void __iomem *atapi_reg = master + 0x20 + (4 * ap->port_no);
176 176
177 u32 len; 177 u32 len;
178 178
179 /* Check we keep host level locking here */ 179 /* Check we keep host level locking here */
180 if (adev->dma_mode >= XFER_UDMA_2) 180 if (adev->dma_mode >= XFER_UDMA_2)
181 outb(inb(clock) | sel66, clock); 181 iowrite8(ioread8(clock) | sel66, clock);
182 else 182 else
183 outb(inb(clock) & ~sel66, clock); 183 iowrite8(ioread8(clock) & ~sel66, clock);
184 184
185 /* The DMA clocks may have been trashed by a reset. FIXME: make conditional 185 /* The DMA clocks may have been trashed by a reset. FIXME: make conditional
186 and move to qc_issue ? */ 186 and move to qc_issue ? */
@@ -189,17 +189,14 @@ static void pdc2026x_bmdma_start(struct ata_queued_cmd *qc)
189 /* Cases the state machine will not complete correctly without help */ 189 /* Cases the state machine will not complete correctly without help */
190 if ((tf->flags & ATA_TFLAG_LBA48) || tf->protocol == ATA_PROT_ATAPI_DMA) 190 if ((tf->flags & ATA_TFLAG_LBA48) || tf->protocol == ATA_PROT_ATAPI_DMA)
191 { 191 {
192 if (tf->flags & ATA_TFLAG_LBA48) 192 len = qc->nbytes;
193 len = qc->nsect * 512;
194 else
195 len = qc->nbytes;
196 193
197 if (tf->flags & ATA_TFLAG_WRITE) 194 if (tf->flags & ATA_TFLAG_WRITE)
198 len |= 0x06000000; 195 len |= 0x06000000;
199 else 196 else
200 len |= 0x05000000; 197 len |= 0x05000000;
201 198
202 outl(len, atapi_reg); 199 iowrite32(len, atapi_reg);
203 } 200 }
204 201
205 /* Activate DMA */ 202 /* Activate DMA */
@@ -222,19 +219,19 @@ static void pdc2026x_bmdma_stop(struct ata_queued_cmd *qc)
222 219
223 int sel66 = ap->port_no ? 0x08: 0x02; 220 int sel66 = ap->port_no ? 0x08: 0x02;
224 /* The clock bits are in the same register for both channels */ 221 /* The clock bits are in the same register for both channels */
225 unsigned long master = ap->host->ports[0]->ioaddr.bmdma_addr; 222 void __iomem *master = ap->host->ports[0]->ioaddr.bmdma_addr;
226 unsigned long clock = master + 0x11; 223 void __iomem *clock = master + 0x11;
227 unsigned long atapi_reg = master + 0x20 + (4 * ap->port_no); 224 void __iomem *atapi_reg = master + 0x20 + (4 * ap->port_no);
228 225
229 /* Cases the state machine will not complete correctly */ 226 /* Cases the state machine will not complete correctly */
230 if (tf->protocol == ATA_PROT_ATAPI_DMA || ( tf->flags & ATA_TFLAG_LBA48)) { 227 if (tf->protocol == ATA_PROT_ATAPI_DMA || ( tf->flags & ATA_TFLAG_LBA48)) {
231 outl(0, atapi_reg); 228 iowrite32(0, atapi_reg);
232 outb(inb(clock) & ~sel66, clock); 229 iowrite8(ioread8(clock) & ~sel66, clock);
233 } 230 }
234 /* Check we keep host level locking here */ 231 /* Check we keep host level locking here */
235 /* Flip back to 33Mhz for PIO */ 232 /* Flip back to 33Mhz for PIO */
236 if (adev->dma_mode >= XFER_UDMA_2) 233 if (adev->dma_mode >= XFER_UDMA_2)
237 outb(inb(clock) & ~sel66, clock); 234 iowrite8(ioread8(clock) & ~sel66, clock);
238 235
239 ata_bmdma_stop(qc); 236 ata_bmdma_stop(qc);
240} 237}
@@ -297,14 +294,14 @@ static struct ata_port_operations pdc2024x_port_ops = {
297 294
298 .qc_prep = ata_qc_prep, 295 .qc_prep = ata_qc_prep,
299 .qc_issue = ata_qc_issue_prot, 296 .qc_issue = ata_qc_issue_prot,
300 .data_xfer = ata_pio_data_xfer, 297 .data_xfer = ata_data_xfer,
301 298
302 .irq_handler = ata_interrupt, 299 .irq_handler = ata_interrupt,
303 .irq_clear = ata_bmdma_irq_clear, 300 .irq_clear = ata_bmdma_irq_clear,
301 .irq_on = ata_irq_on,
302 .irq_ack = ata_irq_ack,
304 303
305 .port_start = ata_port_start, 304 .port_start = ata_port_start,
306 .port_stop = ata_port_stop,
307 .host_stop = ata_host_stop
308}; 305};
309 306
310static struct ata_port_operations pdc2026x_port_ops = { 307static struct ata_port_operations pdc2026x_port_ops = {
@@ -331,14 +328,14 @@ static struct ata_port_operations pdc2026x_port_ops = {
331 328
332 .qc_prep = ata_qc_prep, 329 .qc_prep = ata_qc_prep,
333 .qc_issue = ata_qc_issue_prot, 330 .qc_issue = ata_qc_issue_prot,
334 .data_xfer = ata_pio_data_xfer, 331 .data_xfer = ata_data_xfer,
335 332
336 .irq_handler = ata_interrupt, 333 .irq_handler = ata_interrupt,
337 .irq_clear = ata_bmdma_irq_clear, 334 .irq_clear = ata_bmdma_irq_clear,
335 .irq_on = ata_irq_on,
336 .irq_ack = ata_irq_ack,
338 337
339 .port_start = ata_port_start, 338 .port_start = ata_port_start,
340 .port_stop = ata_port_stop,
341 .host_stop = ata_host_stop
342}; 339};
343 340
344static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id) 341static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id)
diff --git a/drivers/ata/pata_platform.c b/drivers/ata/pata_platform.c
index 40ae11cbfda..479a326114e 100644
--- a/drivers/ata/pata_platform.c
+++ b/drivers/ata/pata_platform.c
@@ -47,23 +47,6 @@ static int pata_platform_set_mode(struct ata_port *ap, struct ata_device **unuse
47 return 0; 47 return 0;
48} 48}
49 49
50static void pata_platform_host_stop(struct ata_host *host)
51{
52 int i;
53
54 /*
55 * Unmap the bases for MMIO
56 */
57 for (i = 0; i < host->n_ports; i++) {
58 struct ata_port *ap = host->ports[i];
59
60 if (ap->flags & ATA_FLAG_MMIO) {
61 iounmap((void __iomem *)ap->ioaddr.ctl_addr);
62 iounmap((void __iomem *)ap->ioaddr.cmd_addr);
63 }
64 }
65}
66
67static struct scsi_host_template pata_platform_sht = { 50static struct scsi_host_template pata_platform_sht = {
68 .module = THIS_MODULE, 51 .module = THIS_MODULE,
69 .name = DRV_NAME, 52 .name = DRV_NAME,
@@ -100,14 +83,14 @@ static struct ata_port_operations pata_platform_port_ops = {
100 .qc_prep = ata_qc_prep, 83 .qc_prep = ata_qc_prep,
101 .qc_issue = ata_qc_issue_prot, 84 .qc_issue = ata_qc_issue_prot,
102 85
103 .data_xfer = ata_pio_data_xfer_noirq, 86 .data_xfer = ata_data_xfer_noirq,
104 87
105 .irq_handler = ata_interrupt, 88 .irq_handler = ata_interrupt,
106 .irq_clear = ata_bmdma_irq_clear, 89 .irq_clear = ata_bmdma_irq_clear,
90 .irq_on = ata_irq_on,
91 .irq_ack = ata_irq_ack,
107 92
108 .port_start = ata_port_start, 93 .port_start = ata_port_start,
109 .port_stop = ata_port_stop,
110 .host_stop = pata_platform_host_stop
111}; 94};
112 95
113static void pata_platform_setup_port(struct ata_ioports *ioaddr, 96static void pata_platform_setup_port(struct ata_ioports *ioaddr,
@@ -153,7 +136,6 @@ static int __devinit pata_platform_probe(struct platform_device *pdev)
153 struct resource *io_res, *ctl_res; 136 struct resource *io_res, *ctl_res;
154 struct ata_probe_ent ae; 137 struct ata_probe_ent ae;
155 unsigned int mmio; 138 unsigned int mmio;
156 int ret;
157 139
158 /* 140 /*
159 * Simple resource validation .. 141 * Simple resource validation ..
@@ -207,46 +189,29 @@ static int __devinit pata_platform_probe(struct platform_device *pdev)
207 * Handle the MMIO case 189 * Handle the MMIO case
208 */ 190 */
209 if (mmio) { 191 if (mmio) {
210 ae.port_flags |= ATA_FLAG_MMIO; 192 ae.port[0].cmd_addr = devm_ioremap(&pdev->dev, io_res->start,
211
212 ae.port[0].cmd_addr = (unsigned long)ioremap(io_res->start,
213 io_res->end - io_res->start + 1); 193 io_res->end - io_res->start + 1);
214 if (unlikely(!ae.port[0].cmd_addr)) { 194 ae.port[0].ctl_addr = devm_ioremap(&pdev->dev, ctl_res->start,
215 dev_err(&pdev->dev, "failed to remap IO base\n");
216 return -ENXIO;
217 }
218
219 ae.port[0].ctl_addr = (unsigned long)ioremap(ctl_res->start,
220 ctl_res->end - ctl_res->start + 1); 195 ctl_res->end - ctl_res->start + 1);
221 if (unlikely(!ae.port[0].ctl_addr)) {
222 dev_err(&pdev->dev, "failed to remap CTL base\n");
223 ret = -ENXIO;
224 goto bad_remap;
225 }
226 } else { 196 } else {
227 ae.port[0].cmd_addr = io_res->start; 197 ae.port[0].cmd_addr = devm_ioport_map(&pdev->dev, io_res->start,
228 ae.port[0].ctl_addr = ctl_res->start; 198 io_res->end - io_res->start + 1);
199 ae.port[0].ctl_addr = devm_ioport_map(&pdev->dev, ctl_res->start,
200 ctl_res->end - ctl_res->start + 1);
201 }
202 if (!ae.port[0].cmd_addr || !ae.port[0].ctl_addr) {
203 dev_err(&pdev->dev, "failed to map IO/CTL base\n");
204 return -ENOMEM;
229 } 205 }
230 206
231 ae.port[0].altstatus_addr = ae.port[0].ctl_addr; 207 ae.port[0].altstatus_addr = ae.port[0].ctl_addr;
232 208
233 pata_platform_setup_port(&ae.port[0], pdev->dev.platform_data); 209 pata_platform_setup_port(&ae.port[0], pdev->dev.platform_data);
234 210
235 if (unlikely(ata_device_add(&ae) == 0)) { 211 if (unlikely(ata_device_add(&ae) == 0))
236 ret = -ENODEV; 212 return -ENODEV;
237 goto add_failed;
238 }
239 213
240 return 0; 214 return 0;
241
242add_failed:
243 if (ae.port[0].ctl_addr && mmio)
244 iounmap((void __iomem *)ae.port[0].ctl_addr);
245bad_remap:
246 if (ae.port[0].cmd_addr && mmio)
247 iounmap((void __iomem *)ae.port[0].cmd_addr);
248
249 return ret;
250} 215}
251 216
252/** 217/**
@@ -261,7 +226,7 @@ static int __devexit pata_platform_remove(struct platform_device *pdev)
261 struct device *dev = &pdev->dev; 226 struct device *dev = &pdev->dev;
262 struct ata_host *host = dev_get_drvdata(dev); 227 struct ata_host *host = dev_get_drvdata(dev);
263 228
264 ata_host_remove(host); 229 ata_host_detach(host);
265 dev_set_drvdata(dev, NULL); 230 dev_set_drvdata(dev, NULL);
266 231
267 return 0; 232 return 0;
diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
index afc0d990e7d..1b3b4ed8eb1 100644
--- a/drivers/ata/pata_qdi.c
+++ b/drivers/ata/pata_qdi.c
@@ -131,22 +131,24 @@ static void qdi_data_xfer(struct ata_device *adev, unsigned char *buf, unsigned
131 131
132 if (ata_id_has_dword_io(adev->id)) { 132 if (ata_id_has_dword_io(adev->id)) {
133 if (write_data) 133 if (write_data)
134 outsl(ap->ioaddr.data_addr, buf, buflen >> 2); 134 iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
135 else 135 else
136 insl(ap->ioaddr.data_addr, buf, buflen >> 2); 136 ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
137 137
138 if (unlikely(slop)) { 138 if (unlikely(slop)) {
139 u32 pad; 139 u32 pad;
140 if (write_data) { 140 if (write_data) {
141 memcpy(&pad, buf + buflen - slop, slop); 141 memcpy(&pad, buf + buflen - slop, slop);
142 outl(le32_to_cpu(pad), ap->ioaddr.data_addr); 142 pad = le32_to_cpu(pad);
143 iowrite32(pad, ap->ioaddr.data_addr);
143 } else { 144 } else {
144 pad = cpu_to_le32(inl(ap->ioaddr.data_addr)); 145 pad = ioread32(ap->ioaddr.data_addr);
146 pad = cpu_to_le32(pad);
145 memcpy(buf + buflen - slop, &pad, slop); 147 memcpy(buf + buflen - slop, &pad, slop);
146 } 148 }
147 } 149 }
148 } else 150 } else
149 ata_pio_data_xfer(adev, buf, buflen, write_data); 151 ata_data_xfer(adev, buf, buflen, write_data);
150} 152}
151 153
152static struct scsi_host_template qdi_sht = { 154static struct scsi_host_template qdi_sht = {
@@ -189,10 +191,10 @@ static struct ata_port_operations qdi6500_port_ops = {
189 191
190 .irq_handler = ata_interrupt, 192 .irq_handler = ata_interrupt,
191 .irq_clear = ata_bmdma_irq_clear, 193 .irq_clear = ata_bmdma_irq_clear,
194 .irq_on = ata_irq_on,
195 .irq_ack = ata_irq_ack,
192 196
193 .port_start = ata_port_start, 197 .port_start = ata_port_start,
194 .port_stop = ata_port_stop,
195 .host_stop = ata_host_stop
196}; 198};
197 199
198static struct ata_port_operations qdi6580_port_ops = { 200static struct ata_port_operations qdi6580_port_ops = {
@@ -217,10 +219,10 @@ static struct ata_port_operations qdi6580_port_ops = {
217 219
218 .irq_handler = ata_interrupt, 220 .irq_handler = ata_interrupt,
219 .irq_clear = ata_bmdma_irq_clear, 221 .irq_clear = ata_bmdma_irq_clear,
222 .irq_on = ata_irq_on,
223 .irq_ack = ata_irq_ack,
220 224
221 .port_start = ata_port_start, 225 .port_start = ata_port_start,
222 .port_stop = ata_port_stop,
223 .host_stop = ata_host_stop
224}; 226};
225 227
226/** 228/**
@@ -238,10 +240,9 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
238{ 240{
239 struct ata_probe_ent ae; 241 struct ata_probe_ent ae;
240 struct platform_device *pdev; 242 struct platform_device *pdev;
243 void __iomem *io_addr, *ctl_addr;
241 int ret; 244 int ret;
242 245
243 unsigned long ctrl = io + 0x206;
244
245 /* 246 /*
246 * Fill in a probe structure first of all 247 * Fill in a probe structure first of all
247 */ 248 */
@@ -250,6 +251,12 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
250 if (IS_ERR(pdev)) 251 if (IS_ERR(pdev))
251 return PTR_ERR(pdev); 252 return PTR_ERR(pdev);
252 253
254 ret = -ENOMEM;
255 io_addr = devm_ioport_map(&pdev->dev, io, 8);
256 ctl_addr = devm_ioport_map(&pdev->dev, io + 0x206, 1);
257 if (!io_addr || !ctl_addr)
258 goto fail;
259
253 memset(&ae, 0, sizeof(struct ata_probe_ent)); 260 memset(&ae, 0, sizeof(struct ata_probe_ent));
254 INIT_LIST_HEAD(&ae.node); 261 INIT_LIST_HEAD(&ae.node);
255 ae.dev = &pdev->dev; 262 ae.dev = &pdev->dev;
@@ -267,9 +274,9 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
267 ae.irq = irq; 274 ae.irq = irq;
268 ae.irq_flags = 0; 275 ae.irq_flags = 0;
269 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST; 276 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
270 ae.port[0].cmd_addr = io; 277 ae.port[0].cmd_addr = io_addr;
271 ae.port[0].altstatus_addr = ctrl; 278 ae.port[0].altstatus_addr = ctl_addr;
272 ae.port[0].ctl_addr = ctrl; 279 ae.port[0].ctl_addr = ctl_addr;
273 ata_std_ports(&ae.port[0]); 280 ata_std_ports(&ae.port[0]);
274 281
275 /* 282 /*
@@ -282,14 +289,17 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
282 qdi_data[nr_qdi_host].platform_dev = pdev; 289 qdi_data[nr_qdi_host].platform_dev = pdev;
283 290
284 printk(KERN_INFO DRV_NAME": qd%d at 0x%lx.\n", type, io); 291 printk(KERN_INFO DRV_NAME": qd%d at 0x%lx.\n", type, io);
285 ret = ata_device_add(&ae); 292
286 if (ret == 0) { 293 ret = -ENODEV;
287 platform_device_unregister(pdev); 294 if (!ata_device_add(&ae))
288 return -ENODEV; 295 goto fail;
289 }
290 296
291 qdi_host[nr_qdi_host++] = dev_get_drvdata(&pdev->dev); 297 qdi_host[nr_qdi_host++] = dev_get_drvdata(&pdev->dev);
292 return 0; 298 return 0;
299
300 fail:
301 platform_device_unregister(pdev);
302 return ret;
293} 303}
294 304
295/** 305/**
@@ -382,7 +392,7 @@ static __exit void qdi_exit(void)
382 int i; 392 int i;
383 393
384 for (i = 0; i < nr_qdi_host; i++) { 394 for (i = 0; i < nr_qdi_host; i++) {
385 ata_host_remove(qdi_host[i]); 395 ata_host_detach(qdi_host[i]);
386 /* Free the control resource. The 6580 dual channel has the resources 396 /* Free the control resource. The 6580 dual channel has the resources
387 * claimed as a pair of 2 byte resources so we need no special cases... 397 * claimed as a pair of 2 byte resources so we need no special cases...
388 */ 398 */
diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
index 065541d034a..0d1e571ef63 100644
--- a/drivers/ata/pata_radisys.c
+++ b/drivers/ata/pata_radisys.c
@@ -255,14 +255,14 @@ static const struct ata_port_operations radisys_pata_ops = {
255 .bmdma_status = ata_bmdma_status, 255 .bmdma_status = ata_bmdma_status,
256 .qc_prep = ata_qc_prep, 256 .qc_prep = ata_qc_prep,
257 .qc_issue = radisys_qc_issue_prot, 257 .qc_issue = radisys_qc_issue_prot,
258 .data_xfer = ata_pio_data_xfer, 258 .data_xfer = ata_data_xfer,
259 259
260 .irq_handler = ata_interrupt, 260 .irq_handler = ata_interrupt,
261 .irq_clear = ata_bmdma_irq_clear, 261 .irq_clear = ata_bmdma_irq_clear,
262 .irq_on = ata_irq_on,
263 .irq_ack = ata_irq_ack,
262 264
263 .port_start = ata_port_start, 265 .port_start = ata_port_start,
264 .port_stop = ata_port_stop,
265 .host_stop = ata_host_stop,
266}; 266};
267 267
268 268
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index cec0729225e..71a2bac09e0 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -115,7 +115,7 @@ static struct ata_port_operations rz1000_port_ops = {
115 .qc_prep = ata_qc_prep, 115 .qc_prep = ata_qc_prep,
116 .qc_issue = ata_qc_issue_prot, 116 .qc_issue = ata_qc_issue_prot,
117 117
118 .data_xfer = ata_pio_data_xfer, 118 .data_xfer = ata_data_xfer,
119 119
120 .freeze = ata_bmdma_freeze, 120 .freeze = ata_bmdma_freeze,
121 .thaw = ata_bmdma_thaw, 121 .thaw = ata_bmdma_thaw,
@@ -124,10 +124,10 @@ static struct ata_port_operations rz1000_port_ops = {
124 124
125 .irq_handler = ata_interrupt, 125 .irq_handler = ata_interrupt,
126 .irq_clear = ata_bmdma_irq_clear, 126 .irq_clear = ata_bmdma_irq_clear,
127 .irq_on = ata_irq_on,
128 .irq_ack = ata_irq_ack,
127 129
128 .port_start = ata_port_start, 130 .port_start = ata_port_start,
129 .port_stop = ata_port_stop,
130 .host_stop = ata_host_stop
131}; 131};
132 132
133static int rz1000_fifo_disable(struct pci_dev *pdev) 133static int rz1000_fifo_disable(struct pci_dev *pdev)
diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
index a3b35bc5039..58e42fbd14f 100644
--- a/drivers/ata/pata_sc1200.c
+++ b/drivers/ata/pata_sc1200.c
@@ -220,14 +220,14 @@ static struct ata_port_operations sc1200_port_ops = {
220 .qc_prep = ata_qc_prep, 220 .qc_prep = ata_qc_prep,
221 .qc_issue = sc1200_qc_issue_prot, 221 .qc_issue = sc1200_qc_issue_prot,
222 222
223 .data_xfer = ata_pio_data_xfer, 223 .data_xfer = ata_data_xfer,
224 224
225 .irq_handler = ata_interrupt, 225 .irq_handler = ata_interrupt,
226 .irq_clear = ata_bmdma_irq_clear, 226 .irq_clear = ata_bmdma_irq_clear,
227 .irq_on = ata_irq_on,
228 .irq_ack = ata_irq_ack,
227 229
228 .port_start = ata_port_start, 230 .port_start = ata_port_start,
229 .port_stop = ata_port_stop,
230 .host_stop = ata_host_stop
231}; 231};
232 232
233/** 233/**
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index f02b6a3b0f1..ad5b43fef3d 100644
--- a/drivers/ata/pata_serverworks.c
+++ b/drivers/ata/pata_serverworks.c
@@ -218,25 +218,18 @@ static unsigned long serverworks_osb4_filter(const struct ata_port *ap, struct a
218static unsigned long serverworks_csb_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask) 218static unsigned long serverworks_csb_filter(const struct ata_port *ap, struct ata_device *adev, unsigned long mask)
219{ 219{
220 const char *p; 220 const char *p;
221 char model_num[40]; 221 char model_num[ATA_ID_PROD_LEN + 1];
222 int len, i; 222 int i;
223 223
224 /* Disk, UDMA */ 224 /* Disk, UDMA */
225 if (adev->class != ATA_DEV_ATA) 225 if (adev->class != ATA_DEV_ATA)
226 return ata_pci_default_filter(ap, adev, mask); 226 return ata_pci_default_filter(ap, adev, mask);
227 227
228 /* Actually do need to check */ 228 /* Actually do need to check */
229 ata_id_string(adev->id, model_num, ATA_ID_PROD_OFS, sizeof(model_num)); 229 ata_id_c_string(adev->id, model_num, ATA_ID_PROD, sizeof(model_num));
230 /* Precuationary - why not do this in the libata core ?? */
231 230
232 len = strlen(model_num); 231 for (i = 0; (p = csb_bad_ata100[i]) != NULL; i++) {
233 while ((len > 0) && (model_num[len - 1] == ' ')) { 232 if (!strcmp(p, model_num))
234 len--;
235 model_num[len] = 0;
236 }
237
238 for(i = 0; (p = csb_bad_ata100[i]) != NULL; i++) {
239 if (!strncmp(p, model_num, len))
240 mask &= ~(0x1F << ATA_SHIFT_UDMA); 233 mask &= ~(0x1F << ATA_SHIFT_UDMA);
241 } 234 }
242 return ata_pci_default_filter(ap, adev, mask); 235 return ata_pci_default_filter(ap, adev, mask);
@@ -355,14 +348,14 @@ static struct ata_port_operations serverworks_osb4_port_ops = {
355 .qc_prep = ata_qc_prep, 348 .qc_prep = ata_qc_prep,
356 .qc_issue = ata_qc_issue_prot, 349 .qc_issue = ata_qc_issue_prot,
357 350
358 .data_xfer = ata_pio_data_xfer, 351 .data_xfer = ata_data_xfer,
359 352
360 .irq_handler = ata_interrupt, 353 .irq_handler = ata_interrupt,
361 .irq_clear = ata_bmdma_irq_clear, 354 .irq_clear = ata_bmdma_irq_clear,
355 .irq_on = ata_irq_on,
356 .irq_ack = ata_irq_ack,
362 357
363 .port_start = ata_port_start, 358 .port_start = ata_port_start,
364 .port_stop = ata_port_stop,
365 .host_stop = ata_host_stop
366}; 359};
367 360
368static struct ata_port_operations serverworks_csb_port_ops = { 361static struct ata_port_operations serverworks_csb_port_ops = {
@@ -390,14 +383,14 @@ static struct ata_port_operations serverworks_csb_port_ops = {
390 .qc_prep = ata_qc_prep, 383 .qc_prep = ata_qc_prep,
391 .qc_issue = ata_qc_issue_prot, 384 .qc_issue = ata_qc_issue_prot,
392 385
393 .data_xfer = ata_pio_data_xfer, 386 .data_xfer = ata_data_xfer,
394 387
395 .irq_handler = ata_interrupt, 388 .irq_handler = ata_interrupt,
396 .irq_clear = ata_bmdma_irq_clear, 389 .irq_clear = ata_bmdma_irq_clear,
390 .irq_on = ata_irq_on,
391 .irq_ack = ata_irq_ack,
397 392
398 .port_start = ata_port_start, 393 .port_start = ata_port_start,
399 .port_stop = ata_port_stop,
400 .host_stop = ata_host_stop
401}; 394};
402 395
403static int serverworks_fixup_osb4(struct pci_dev *pdev) 396static int serverworks_fixup_osb4(struct pci_dev *pdev)
@@ -559,7 +552,7 @@ static int serverworks_reinit_one(struct pci_dev *pdev)
559{ 552{
560 /* Force master latency timer to 64 PCI clocks */ 553 /* Force master latency timer to 64 PCI clocks */
561 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40); 554 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0x40);
562 555
563 switch (pdev->device) 556 switch (pdev->device)
564 { 557 {
565 case PCI_DEVICE_ID_SERVERWORKS_OSB4IDE: 558 case PCI_DEVICE_ID_SERVERWORKS_OSB4IDE:
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index e8dfd8fc3ff..ed79fabe025 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -252,14 +252,14 @@ static struct ata_port_operations sil680_port_ops = {
252 .qc_prep = ata_qc_prep, 252 .qc_prep = ata_qc_prep,
253 .qc_issue = ata_qc_issue_prot, 253 .qc_issue = ata_qc_issue_prot,
254 254
255 .data_xfer = ata_pio_data_xfer, 255 .data_xfer = ata_data_xfer,
256 256
257 .irq_handler = ata_interrupt, 257 .irq_handler = ata_interrupt,
258 .irq_clear = ata_bmdma_irq_clear, 258 .irq_clear = ata_bmdma_irq_clear,
259 .irq_on = ata_irq_on,
260 .irq_ack = ata_irq_ack,
259 261
260 .port_start = ata_port_start, 262 .port_start = ata_port_start,
261 .port_stop = ata_port_stop,
262 .host_stop = ata_host_stop
263}; 263};
264 264
265/** 265/**
@@ -270,7 +270,7 @@ static struct ata_port_operations sil680_port_ops = {
270 * is powered up on boot and when we resume in case we resumed from RAM. 270 * is powered up on boot and when we resume in case we resumed from RAM.
271 * Returns the final clock settings. 271 * Returns the final clock settings.
272 */ 272 */
273 273
274static u8 sil680_init_chip(struct pci_dev *pdev) 274static u8 sil680_init_chip(struct pci_dev *pdev)
275{ 275{
276 u32 class_rev = 0; 276 u32 class_rev = 0;
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index 916cedb3d75..560103d55b2 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -32,7 +32,9 @@
32#include <scsi/scsi_host.h> 32#include <scsi/scsi_host.h>
33#include <linux/libata.h> 33#include <linux/libata.h>
34#include <linux/ata.h> 34#include <linux/ata.h>
35#include "libata.h"
35 36
37#undef DRV_NAME /* already defined in libata.h, for libata-core */
36#define DRV_NAME "pata_sis" 38#define DRV_NAME "pata_sis"
37#define DRV_VERSION "0.4.5" 39#define DRV_VERSION "0.4.5"
38 40
@@ -43,6 +45,34 @@ struct sis_chipset {
43 up code later */ 45 up code later */
44}; 46};
45 47
48struct sis_laptop {
49 u16 device;
50 u16 subvendor;
51 u16 subdevice;
52};
53
54static const struct sis_laptop sis_laptop[] = {
55 /* devid, subvendor, subdev */
56 { 0x5513, 0x1043, 0x1107 }, /* ASUS A6K */
57 /* end marker */
58 { 0, }
59};
60
61static int sis_short_ata40(struct pci_dev *dev)
62{
63 const struct sis_laptop *lap = &sis_laptop[0];
64
65 while (lap->device) {
66 if (lap->device == dev->device &&
67 lap->subvendor == dev->subsystem_vendor &&
68 lap->subdevice == dev->subsystem_device)
69 return 1;
70 lap++;
71 }
72
73 return 0;
74}
75
46/** 76/**
47 * sis_port_base - return PCI configuration base for dev 77 * sis_port_base - return PCI configuration base for dev
48 * @adev: device 78 * @adev: device
@@ -79,7 +109,7 @@ static int sis_133_pre_reset(struct ata_port *ap)
79 109
80 /* The top bit of this register is the cable detect bit */ 110 /* The top bit of this register is the cable detect bit */
81 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp); 111 pci_read_config_word(pdev, 0x50 + 2 * ap->port_no, &tmp);
82 if (tmp & 0x8000) 112 if ((tmp & 0x8000) && !sis_short_ata40(pdev))
83 ap->cbl = ATA_CBL_PATA40; 113 ap->cbl = ATA_CBL_PATA40;
84 else 114 else
85 ap->cbl = ATA_CBL_PATA80; 115 ap->cbl = ATA_CBL_PATA80;
@@ -127,7 +157,7 @@ static int sis_66_pre_reset(struct ata_port *ap)
127 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */ 157 /* Older chips keep cable detect in bits 4/5 of reg 0x48 */
128 pci_read_config_byte(pdev, 0x48, &tmp); 158 pci_read_config_byte(pdev, 0x48, &tmp);
129 tmp >>= ap->port_no; 159 tmp >>= ap->port_no;
130 if (tmp & 0x10) 160 if ((tmp & 0x10) && !sis_short_ata40(pdev))
131 ap->cbl = ATA_CBL_PATA40; 161 ap->cbl = ATA_CBL_PATA40;
132 else 162 else
133 ap->cbl = ATA_CBL_PATA80; 163 ap->cbl = ATA_CBL_PATA80;
@@ -573,14 +603,14 @@ static const struct ata_port_operations sis_133_ops = {
573 .bmdma_status = ata_bmdma_status, 603 .bmdma_status = ata_bmdma_status,
574 .qc_prep = ata_qc_prep, 604 .qc_prep = ata_qc_prep,
575 .qc_issue = ata_qc_issue_prot, 605 .qc_issue = ata_qc_issue_prot,
576 .data_xfer = ata_pio_data_xfer, 606 .data_xfer = ata_data_xfer,
577 607
578 .irq_handler = ata_interrupt, 608 .irq_handler = ata_interrupt,
579 .irq_clear = ata_bmdma_irq_clear, 609 .irq_clear = ata_bmdma_irq_clear,
610 .irq_on = ata_irq_on,
611 .irq_ack = ata_irq_ack,
580 612
581 .port_start = ata_port_start, 613 .port_start = ata_port_start,
582 .port_stop = ata_port_stop,
583 .host_stop = ata_host_stop,
584}; 614};
585 615
586static const struct ata_port_operations sis_133_early_ops = { 616static const struct ata_port_operations sis_133_early_ops = {
@@ -606,14 +636,14 @@ static const struct ata_port_operations sis_133_early_ops = {
606 .bmdma_status = ata_bmdma_status, 636 .bmdma_status = ata_bmdma_status,
607 .qc_prep = ata_qc_prep, 637 .qc_prep = ata_qc_prep,
608 .qc_issue = ata_qc_issue_prot, 638 .qc_issue = ata_qc_issue_prot,
609 .data_xfer = ata_pio_data_xfer, 639 .data_xfer = ata_data_xfer,
610 640
611 .irq_handler = ata_interrupt, 641 .irq_handler = ata_interrupt,
612 .irq_clear = ata_bmdma_irq_clear, 642 .irq_clear = ata_bmdma_irq_clear,
643 .irq_on = ata_irq_on,
644 .irq_ack = ata_irq_ack,
613 645
614 .port_start = ata_port_start, 646 .port_start = ata_port_start,
615 .port_stop = ata_port_stop,
616 .host_stop = ata_host_stop,
617}; 647};
618 648
619static const struct ata_port_operations sis_100_ops = { 649static const struct ata_port_operations sis_100_ops = {
@@ -640,14 +670,14 @@ static const struct ata_port_operations sis_100_ops = {
640 .bmdma_status = ata_bmdma_status, 670 .bmdma_status = ata_bmdma_status,
641 .qc_prep = ata_qc_prep, 671 .qc_prep = ata_qc_prep,
642 .qc_issue = ata_qc_issue_prot, 672 .qc_issue = ata_qc_issue_prot,
643 .data_xfer = ata_pio_data_xfer, 673 .data_xfer = ata_data_xfer,
644 674
645 .irq_handler = ata_interrupt, 675 .irq_handler = ata_interrupt,
646 .irq_clear = ata_bmdma_irq_clear, 676 .irq_clear = ata_bmdma_irq_clear,
677 .irq_on = ata_irq_on,
678 .irq_ack = ata_irq_ack,
647 679
648 .port_start = ata_port_start, 680 .port_start = ata_port_start,
649 .port_stop = ata_port_stop,
650 .host_stop = ata_host_stop,
651}; 681};
652 682
653static const struct ata_port_operations sis_66_ops = { 683static const struct ata_port_operations sis_66_ops = {
@@ -673,14 +703,14 @@ static const struct ata_port_operations sis_66_ops = {
673 .bmdma_status = ata_bmdma_status, 703 .bmdma_status = ata_bmdma_status,
674 .qc_prep = ata_qc_prep, 704 .qc_prep = ata_qc_prep,
675 .qc_issue = ata_qc_issue_prot, 705 .qc_issue = ata_qc_issue_prot,
676 .data_xfer = ata_pio_data_xfer, 706 .data_xfer = ata_data_xfer,
677 707
678 .irq_handler = ata_interrupt, 708 .irq_handler = ata_interrupt,
679 .irq_clear = ata_bmdma_irq_clear, 709 .irq_clear = ata_bmdma_irq_clear,
710 .irq_on = ata_irq_on,
711 .irq_ack = ata_irq_ack,
680 712
681 .port_start = ata_port_start, 713 .port_start = ata_port_start,
682 .port_stop = ata_port_stop,
683 .host_stop = ata_host_stop,
684}; 714};
685 715
686static const struct ata_port_operations sis_old_ops = { 716static const struct ata_port_operations sis_old_ops = {
@@ -706,14 +736,14 @@ static const struct ata_port_operations sis_old_ops = {
706 .bmdma_status = ata_bmdma_status, 736 .bmdma_status = ata_bmdma_status,
707 .qc_prep = ata_qc_prep, 737 .qc_prep = ata_qc_prep,
708 .qc_issue = ata_qc_issue_prot, 738 .qc_issue = ata_qc_issue_prot,
709 .data_xfer = ata_pio_data_xfer, 739 .data_xfer = ata_data_xfer,
710 740
711 .irq_handler = ata_interrupt, 741 .irq_handler = ata_interrupt,
712 .irq_clear = ata_bmdma_irq_clear, 742 .irq_clear = ata_bmdma_irq_clear,
743 .irq_on = ata_irq_on,
744 .irq_ack = ata_irq_ack,
713 745
714 .port_start = ata_port_start, 746 .port_start = ata_port_start,
715 .port_stop = ata_port_stop,
716 .host_stop = ata_host_stop,
717}; 747};
718 748
719static struct ata_port_info sis_info = { 749static struct ata_port_info sis_info = {
@@ -753,7 +783,7 @@ static struct ata_port_info sis_info100_early = {
753 .pio_mask = 0x1f, /* pio0-4 */ 783 .pio_mask = 0x1f, /* pio0-4 */
754 .port_ops = &sis_66_ops, 784 .port_ops = &sis_66_ops,
755}; 785};
756static struct ata_port_info sis_info133 = { 786struct ata_port_info sis_info133 = {
757 .sht = &sis_sht, 787 .sht = &sis_sht,
758 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 788 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
759 .pio_mask = 0x1f, /* pio0-4 */ 789 .pio_mask = 0x1f, /* pio0-4 */
@@ -768,6 +798,8 @@ static struct ata_port_info sis_info133_early = {
768 .port_ops = &sis_133_early_ops, 798 .port_ops = &sis_133_early_ops,
769}; 799};
770 800
801/* Privately shared with the SiS180 SATA driver, not for use elsewhere */
802EXPORT_SYMBOL_GPL(sis_info133);
771 803
772static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis) 804static void sis_fixup(struct pci_dev *pdev, struct sis_chipset *sis)
773{ 805{
@@ -847,7 +879,7 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
847 struct sis_chipset *chipset = NULL; 879 struct sis_chipset *chipset = NULL;
848 880
849 static struct sis_chipset sis_chipsets[] = { 881 static struct sis_chipset sis_chipsets[] = {
850 882
851 { 0x0968, &sis_info133 }, 883 { 0x0968, &sis_info133 },
852 { 0x0966, &sis_info133 }, 884 { 0x0966, &sis_info133 },
853 { 0x0965, &sis_info133 }, 885 { 0x0965, &sis_info133 },
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
index e94f515ef54..f2fa158d07c 100644
--- a/drivers/ata/pata_sl82c105.c
+++ b/drivers/ata/pata_sl82c105.c
@@ -139,13 +139,13 @@ static void sl82c105_set_dmamode(struct ata_port *ap, struct ata_device *adev)
139{ 139{
140 switch(adev->dma_mode) { 140 switch(adev->dma_mode) {
141 case XFER_MW_DMA_0: 141 case XFER_MW_DMA_0:
142 sl82c105_configure_piomode(ap, adev, 1); 142 sl82c105_configure_piomode(ap, adev, 0);
143 break; 143 break;
144 case XFER_MW_DMA_1: 144 case XFER_MW_DMA_1:
145 sl82c105_configure_piomode(ap, adev, 3); 145 sl82c105_configure_piomode(ap, adev, 3);
146 break; 146 break;
147 case XFER_MW_DMA_2: 147 case XFER_MW_DMA_2:
148 sl82c105_configure_piomode(ap, adev, 3); 148 sl82c105_configure_piomode(ap, adev, 4);
149 break; 149 break;
150 default: 150 default:
151 BUG(); 151 BUG();
@@ -262,14 +262,14 @@ static struct ata_port_operations sl82c105_port_ops = {
262 .qc_prep = ata_qc_prep, 262 .qc_prep = ata_qc_prep,
263 .qc_issue = ata_qc_issue_prot, 263 .qc_issue = ata_qc_issue_prot,
264 264
265 .data_xfer = ata_pio_data_xfer, 265 .data_xfer = ata_data_xfer,
266 266
267 .irq_handler = ata_interrupt, 267 .irq_handler = ata_interrupt,
268 .irq_clear = ata_bmdma_irq_clear, 268 .irq_clear = ata_bmdma_irq_clear,
269 .irq_on = ata_irq_on,
270 .irq_ack = ata_irq_ack,
269 271
270 .port_start = ata_port_start, 272 .port_start = ata_port_start,
271 .port_stop = ata_port_stop,
272 .host_stop = ata_host_stop
273}; 273};
274 274
275/** 275/**
diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
index a142971f130..453ab90b721 100644
--- a/drivers/ata/pata_triflex.c
+++ b/drivers/ata/pata_triflex.c
@@ -221,14 +221,14 @@ static struct ata_port_operations triflex_port_ops = {
221 .qc_prep = ata_qc_prep, 221 .qc_prep = ata_qc_prep,
222 .qc_issue = ata_qc_issue_prot, 222 .qc_issue = ata_qc_issue_prot,
223 223
224 .data_xfer = ata_pio_data_xfer, 224 .data_xfer = ata_data_xfer,
225 225
226 .irq_handler = ata_interrupt, 226 .irq_handler = ata_interrupt,
227 .irq_clear = ata_bmdma_irq_clear, 227 .irq_clear = ata_bmdma_irq_clear,
228 .irq_on = ata_irq_on,
229 .irq_ack = ata_irq_ack,
228 230
229 .port_start = ata_port_start, 231 .port_start = ata_port_start,
230 .port_stop = ata_port_stop,
231 .host_stop = ata_host_stop
232}; 232};
233 233
234static 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)
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index f0b6c3b7142..220fcd6c549 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -334,14 +334,14 @@ static struct ata_port_operations via_port_ops = {
334 .qc_prep = ata_qc_prep, 334 .qc_prep = ata_qc_prep,
335 .qc_issue = ata_qc_issue_prot, 335 .qc_issue = ata_qc_issue_prot,
336 336
337 .data_xfer = ata_pio_data_xfer, 337 .data_xfer = ata_data_xfer,
338 338
339 .irq_handler = ata_interrupt, 339 .irq_handler = ata_interrupt,
340 .irq_clear = ata_bmdma_irq_clear, 340 .irq_clear = ata_bmdma_irq_clear,
341 .irq_on = ata_irq_on,
342 .irq_ack = ata_irq_ack,
341 343
342 .port_start = ata_port_start, 344 .port_start = ata_port_start,
343 .port_stop = ata_port_stop,
344 .host_stop = ata_host_stop
345}; 345};
346 346
347static struct ata_port_operations via_port_ops_noirq = { 347static struct ata_port_operations via_port_ops_noirq = {
@@ -369,14 +369,14 @@ static struct ata_port_operations via_port_ops_noirq = {
369 .qc_prep = ata_qc_prep, 369 .qc_prep = ata_qc_prep,
370 .qc_issue = ata_qc_issue_prot, 370 .qc_issue = ata_qc_issue_prot,
371 371
372 .data_xfer = ata_pio_data_xfer_noirq, 372 .data_xfer = ata_data_xfer_noirq,
373 373
374 .irq_handler = ata_interrupt, 374 .irq_handler = ata_interrupt,
375 .irq_clear = ata_bmdma_irq_clear, 375 .irq_clear = ata_bmdma_irq_clear,
376 .irq_on = ata_irq_on,
377 .irq_ack = ata_irq_ack,
376 378
377 .port_start = ata_port_start, 379 .port_start = ata_port_start,
378 .port_stop = ata_port_stop,
379 .host_stop = ata_host_stop
380}; 380};
381 381
382/** 382/**
@@ -391,11 +391,11 @@ static struct ata_port_operations via_port_ops_noirq = {
391static void via_config_fifo(struct pci_dev *pdev, unsigned int flags) 391static void via_config_fifo(struct pci_dev *pdev, unsigned int flags)
392{ 392{
393 u8 enable; 393 u8 enable;
394 394
395 /* 0x40 low bits indicate enabled channels */ 395 /* 0x40 low bits indicate enabled channels */
396 pci_read_config_byte(pdev, 0x40 , &enable); 396 pci_read_config_byte(pdev, 0x40 , &enable);
397 enable &= 3; 397 enable &= 3;
398 398
399 if (flags & VIA_SET_FIFO) { 399 if (flags & VIA_SET_FIFO) {
400 static const u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20}; 400 static const u8 fifo_setting[4] = {0x00, 0x60, 0x00, 0x20};
401 u8 fifo; 401 u8 fifo;
@@ -516,7 +516,7 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
516 516
517 /* Initialise the FIFO for the enabled channels. */ 517 /* Initialise the FIFO for the enabled channels. */
518 via_config_fifo(pdev, config->flags); 518 via_config_fifo(pdev, config->flags);
519 519
520 /* Clock set up */ 520 /* Clock set up */
521 switch(config->flags & VIA_UDMA) { 521 switch(config->flags & VIA_UDMA) {
522 case VIA_UDMA_NONE: 522 case VIA_UDMA_NONE:
@@ -575,7 +575,7 @@ static int via_reinit_one(struct pci_dev *pdev)
575 u32 timing; 575 u32 timing;
576 struct ata_host *host = dev_get_drvdata(&pdev->dev); 576 struct ata_host *host = dev_get_drvdata(&pdev->dev);
577 const struct via_isa_bridge *config = host->private_data; 577 const struct via_isa_bridge *config = host->private_data;
578 578
579 via_config_fifo(pdev, config->flags); 579 via_config_fifo(pdev, config->flags);
580 580
581 if ((config->flags & VIA_UDMA) == VIA_UDMA_66) { 581 if ((config->flags & VIA_UDMA) == VIA_UDMA_66) {
@@ -590,7 +590,7 @@ static int via_reinit_one(struct pci_dev *pdev)
590 timing &= ~0x80008; 590 timing &= ~0x80008;
591 pci_write_config_dword(pdev, 0x50, timing); 591 pci_write_config_dword(pdev, 0x50, timing);
592 } 592 }
593 return ata_pci_device_resume(pdev); 593 return ata_pci_device_resume(pdev);
594} 594}
595 595
596static const struct pci_device_id via[] = { 596static const struct pci_device_id via[] = {
diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
index 5d1f518e1cc..0888b4f19f4 100644
--- a/drivers/ata/pata_winbond.c
+++ b/drivers/ata/pata_winbond.c
@@ -5,7 +5,7 @@
5 * Support for the Winbond 83759A when operating in advanced mode. 5 * Support for the Winbond 83759A when operating in advanced mode.
6 * Multichip mode is not currently supported. 6 * Multichip mode is not currently supported.
7 */ 7 */
8 8
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/module.h> 10#include <linux/module.h>
11#include <linux/pci.h> 11#include <linux/pci.h>
@@ -69,7 +69,7 @@ static void winbond_set_piomode(struct ata_port *ap, struct ata_device *adev)
69 int timing = 0x88 + (ap->port_no * 4) + (adev->devno * 2); 69 int timing = 0x88 + (ap->port_no * 4) + (adev->devno * 2);
70 70
71 reg = winbond_readcfg(winbond->config, 0x81); 71 reg = winbond_readcfg(winbond->config, 0x81);
72 72
73 /* Get the timing data in cycles */ 73 /* Get the timing data in cycles */
74 if (reg & 0x40) /* Fast VLB bus, assume 50MHz */ 74 if (reg & 0x40) /* Fast VLB bus, assume 50MHz */
75 ata_timing_compute(adev, adev->pio_mode, &t, 20000, 1000); 75 ata_timing_compute(adev, adev->pio_mode, &t, 20000, 1000);
@@ -80,9 +80,9 @@ static void winbond_set_piomode(struct ata_port *ap, struct ata_device *adev)
80 recovery = (FIT(t.recover, 1, 15) + 1) & 0x0F; 80 recovery = (FIT(t.recover, 1, 15) + 1) & 0x0F;
81 timing = (active << 4) | recovery; 81 timing = (active << 4) | recovery;
82 winbond_writecfg(winbond->config, timing, reg); 82 winbond_writecfg(winbond->config, timing, reg);
83 83
84 /* Load the setup timing */ 84 /* Load the setup timing */
85 85
86 reg = 0x35; 86 reg = 0x35;
87 if (adev->class != ATA_DEV_ATA) 87 if (adev->class != ATA_DEV_ATA)
88 reg |= 0x08; /* FIFO off */ 88 reg |= 0x08; /* FIFO off */
@@ -100,22 +100,24 @@ static void winbond_data_xfer(struct ata_device *adev, unsigned char *buf, unsig
100 100
101 if (ata_id_has_dword_io(adev->id)) { 101 if (ata_id_has_dword_io(adev->id)) {
102 if (write_data) 102 if (write_data)
103 outsl(ap->ioaddr.data_addr, buf, buflen >> 2); 103 iowrite32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
104 else 104 else
105 insl(ap->ioaddr.data_addr, buf, buflen >> 2); 105 ioread32_rep(ap->ioaddr.data_addr, buf, buflen >> 2);
106 106
107 if (unlikely(slop)) { 107 if (unlikely(slop)) {
108 u32 pad; 108 u32 pad;
109 if (write_data) { 109 if (write_data) {
110 memcpy(&pad, buf + buflen - slop, slop); 110 memcpy(&pad, buf + buflen - slop, slop);
111 outl(le32_to_cpu(pad), ap->ioaddr.data_addr); 111 pad = le32_to_cpu(pad);
112 iowrite32(pad, ap->ioaddr.data_addr);
112 } else { 113 } else {
113 pad = cpu_to_le16(inl(ap->ioaddr.data_addr)); 114 pad = ioread32(ap->ioaddr.data_addr);
115 pad = cpu_to_le16(pad);
114 memcpy(buf + buflen - slop, &pad, slop); 116 memcpy(buf + buflen - slop, &pad, slop);
115 } 117 }
116 } 118 }
117 } else 119 } else
118 ata_pio_data_xfer(adev, buf, buflen, write_data); 120 ata_data_xfer(adev, buf, buflen, write_data);
119} 121}
120 122
121static struct scsi_host_template winbond_sht = { 123static struct scsi_host_template winbond_sht = {
@@ -158,10 +160,10 @@ static struct ata_port_operations winbond_port_ops = {
158 160
159 .irq_handler = ata_interrupt, 161 .irq_handler = ata_interrupt,
160 .irq_clear = ata_bmdma_irq_clear, 162 .irq_clear = ata_bmdma_irq_clear,
163 .irq_on = ata_irq_on,
164 .irq_ack = ata_irq_ack,
161 165
162 .port_start = ata_port_start, 166 .port_start = ata_port_start,
163 .port_stop = ata_port_stop,
164 .host_stop = ata_host_stop
165}; 167};
166 168
167/** 169/**
@@ -194,13 +196,15 @@ static __init int winbond_init_one(unsigned long port)
194 winbond_writecfg(port, 0x85, reg); 196 winbond_writecfg(port, 0x85, reg);
195 197
196 reg = winbond_readcfg(port, 0x81); 198 reg = winbond_readcfg(port, 0x81);
197 199
198 if (!(reg & 0x03)) /* Disabled */ 200 if (!(reg & 0x03)) /* Disabled */
199 return 0; 201 return 0;
200 202
201 for (i = 0; i < 2 ; i ++) { 203 for (i = 0; i < 2 ; i ++) {
204 unsigned long cmd_port = 0x1F0 - (0x80 * i);
205 void __iomem *cmd_addr, *ctl_addr;
202 206
203 if (reg & (1 << i)) { 207 if (reg & (1 << i)) {
204 /* 208 /*
205 * Fill in a probe structure first of all 209 * Fill in a probe structure first of all
206 */ 210 */
@@ -209,6 +213,13 @@ static __init int winbond_init_one(unsigned long port)
209 if (IS_ERR(pdev)) 213 if (IS_ERR(pdev))
210 return PTR_ERR(pdev); 214 return PTR_ERR(pdev);
211 215
216 cmd_addr = devm_ioport_map(&pdev->dev, cmd_port, 8);
217 ctl_addr = devm_ioport_map(&pdev->dev, cmd_port + 0x0206, 1);
218 if (!cmd_addr || !ctl_addr) {
219 platform_device_unregister(pdev);
220 return -ENOMEM;
221 }
222
212 memset(&ae, 0, sizeof(struct ata_probe_ent)); 223 memset(&ae, 0, sizeof(struct ata_probe_ent));
213 INIT_LIST_HEAD(&ae.node); 224 INIT_LIST_HEAD(&ae.node);
214 ae.dev = &pdev->dev; 225 ae.dev = &pdev->dev;
@@ -217,14 +228,14 @@ static __init int winbond_init_one(unsigned long port)
217 ae.pio_mask = 0x1F; 228 ae.pio_mask = 0x1F;
218 229
219 ae.sht = &winbond_sht; 230 ae.sht = &winbond_sht;
220 231
221 ae.n_ports = 1; 232 ae.n_ports = 1;
222 ae.irq = 14 + i; 233 ae.irq = 14 + i;
223 ae.irq_flags = 0; 234 ae.irq_flags = 0;
224 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST; 235 ae.port_flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST;
225 ae.port[0].cmd_addr = 0x1F0 - (0x80 * i); 236 ae.port[0].cmd_addr = cmd_addr;
226 ae.port[0].altstatus_addr = ae.port[0].cmd_addr + 0x0206; 237 ae.port[0].altstatus_addr = ctl_addr;
227 ae.port[0].ctl_addr = ae.port[0].altstatus_addr; 238 ae.port[0].ctl_addr = ctl_addr;
228 ata_std_ports(&ae.port[0]); 239 ata_std_ports(&ae.port[0]);
229 /* 240 /*
230 * Hook in a private data structure per channel 241 * Hook in a private data structure per channel
@@ -257,7 +268,7 @@ static __init int winbond_init(void)
257 268
258 int ct = 0; 269 int ct = 0;
259 int i; 270 int i;
260 271
261 if (probe_winbond == 0) 272 if (probe_winbond == 0)
262 return -ENODEV; 273 return -ENODEV;
263 274
@@ -288,7 +299,7 @@ static __exit void winbond_exit(void)
288 int i; 299 int i;
289 300
290 for (i = 0; i < nr_winbond_host; i++) { 301 for (i = 0; i < nr_winbond_host; i++) {
291 ata_host_remove(winbond_host[i]); 302 ata_host_detach(winbond_host[i]);
292 release_region(winbond_data[i].config, 2); 303 release_region(winbond_data[i].config, 2);
293 platform_device_unregister(winbond_data[i].platform_dev); 304 platform_device_unregister(winbond_data[i].platform_dev);
294 } 305 }
diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
index 90786d7a20b..b4ed8ce553e 100644
--- a/drivers/ata/pdc_adma.c
+++ b/drivers/ata/pdc_adma.c
@@ -42,7 +42,6 @@
42#include <linux/sched.h> 42#include <linux/sched.h>
43#include <linux/device.h> 43#include <linux/device.h>
44#include <scsi/scsi_host.h> 44#include <scsi/scsi_host.h>
45#include <asm/io.h>
46#include <linux/libata.h> 45#include <linux/libata.h>
47 46
48#define DRV_NAME "pdc_adma" 47#define DRV_NAME "pdc_adma"
@@ -52,9 +51,15 @@
52#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40)) 51#define ADMA_ATA_REGS(base,port_no) ((base) + ((port_no) * 0x40))
53 52
54/* macro to calculate base address for ADMA regs */ 53/* macro to calculate base address for ADMA regs */
55#define ADMA_REGS(base,port_no) ((base) + 0x80 + ((port_no) * 0x20)) 54#define ADMA_REGS(base,port_no) ((base) + 0x80 + ((port_no) * 0x20))
55
56/* macro to obtain addresses from ata_host */
57#define ADMA_HOST_REGS(host,port_no) \
58 ADMA_REGS((host)->iomap[ADMA_MMIO_BAR], port_no)
56 59
57enum { 60enum {
61 ADMA_MMIO_BAR = 4,
62
58 ADMA_PORTS = 2, 63 ADMA_PORTS = 2,
59 ADMA_CPB_BYTES = 40, 64 ADMA_CPB_BYTES = 40,
60 ADMA_PRD_BYTES = LIBATA_MAX_PRD * 16, 65 ADMA_PRD_BYTES = LIBATA_MAX_PRD * 16,
@@ -167,9 +172,11 @@ static const struct ata_port_operations adma_ata_ops = {
167 .qc_prep = adma_qc_prep, 172 .qc_prep = adma_qc_prep,
168 .qc_issue = adma_qc_issue, 173 .qc_issue = adma_qc_issue,
169 .eng_timeout = adma_eng_timeout, 174 .eng_timeout = adma_eng_timeout,
170 .data_xfer = ata_mmio_data_xfer, 175 .data_xfer = ata_data_xfer,
171 .irq_handler = adma_intr, 176 .irq_handler = adma_intr,
172 .irq_clear = adma_irq_clear, 177 .irq_clear = adma_irq_clear,
178 .irq_on = ata_irq_on,
179 .irq_ack = ata_irq_ack,
173 .port_start = adma_port_start, 180 .port_start = adma_port_start,
174 .port_stop = adma_port_stop, 181 .port_stop = adma_port_stop,
175 .host_stop = adma_host_stop, 182 .host_stop = adma_host_stop,
@@ -235,11 +242,10 @@ static void adma_reset_engine(void __iomem *chan)
235static void adma_reinit_engine(struct ata_port *ap) 242static void adma_reinit_engine(struct ata_port *ap)
236{ 243{
237 struct adma_port_priv *pp = ap->private_data; 244 struct adma_port_priv *pp = ap->private_data;
238 void __iomem *mmio_base = ap->host->mmio_base; 245 void __iomem *chan = ADMA_HOST_REGS(ap->host, ap->port_no);
239 void __iomem *chan = ADMA_REGS(mmio_base, ap->port_no);
240 246
241 /* mask/clear ATA interrupts */ 247 /* mask/clear ATA interrupts */
242 writeb(ATA_NIEN, (void __iomem *)ap->ioaddr.ctl_addr); 248 writeb(ATA_NIEN, ap->ioaddr.ctl_addr);
243 ata_check_status(ap); 249 ata_check_status(ap);
244 250
245 /* reset the ADMA engine */ 251 /* reset the ADMA engine */
@@ -263,7 +269,7 @@ static void adma_reinit_engine(struct ata_port *ap)
263 269
264static inline void adma_enter_reg_mode(struct ata_port *ap) 270static inline void adma_enter_reg_mode(struct ata_port *ap)
265{ 271{
266 void __iomem *chan = ADMA_REGS(ap->host->mmio_base, ap->port_no); 272 void __iomem *chan = ADMA_HOST_REGS(ap->host, ap->port_no);
267 273
268 writew(aPIOMD4, chan + ADMA_CONTROL); 274 writew(aPIOMD4, chan + ADMA_CONTROL);
269 readb(chan + ADMA_STATUS); /* flush */ 275 readb(chan + ADMA_STATUS); /* flush */
@@ -410,7 +416,7 @@ static void adma_qc_prep(struct ata_queued_cmd *qc)
410static inline void adma_packet_start(struct ata_queued_cmd *qc) 416static inline void adma_packet_start(struct ata_queued_cmd *qc)
411{ 417{
412 struct ata_port *ap = qc->ap; 418 struct ata_port *ap = qc->ap;
413 void __iomem *chan = ADMA_REGS(ap->host->mmio_base, ap->port_no); 419 void __iomem *chan = ADMA_HOST_REGS(ap->host, ap->port_no);
414 420
415 VPRINTK("ENTER, ap %p\n", ap); 421 VPRINTK("ENTER, ap %p\n", ap);
416 422
@@ -443,13 +449,12 @@ static unsigned int adma_qc_issue(struct ata_queued_cmd *qc)
443static inline unsigned int adma_intr_pkt(struct ata_host *host) 449static inline unsigned int adma_intr_pkt(struct ata_host *host)
444{ 450{
445 unsigned int handled = 0, port_no; 451 unsigned int handled = 0, port_no;
446 u8 __iomem *mmio_base = host->mmio_base;
447 452
448 for (port_no = 0; port_no < host->n_ports; ++port_no) { 453 for (port_no = 0; port_no < host->n_ports; ++port_no) {
449 struct ata_port *ap = host->ports[port_no]; 454 struct ata_port *ap = host->ports[port_no];
450 struct adma_port_priv *pp; 455 struct adma_port_priv *pp;
451 struct ata_queued_cmd *qc; 456 struct ata_queued_cmd *qc;
452 void __iomem *chan = ADMA_REGS(mmio_base, port_no); 457 void __iomem *chan = ADMA_HOST_REGS(host, port_no);
453 u8 status = readb(chan + ADMA_STATUS); 458 u8 status = readb(chan + ADMA_STATUS);
454 459
455 if (status == 0) 460 if (status == 0)
@@ -523,7 +528,7 @@ static irqreturn_t adma_intr(int irq, void *dev_instance)
523 return IRQ_RETVAL(handled); 528 return IRQ_RETVAL(handled);
524} 529}
525 530
526static void adma_ata_setup_port(struct ata_ioports *port, unsigned long base) 531static void adma_ata_setup_port(struct ata_ioports *port, void __iomem *base)
527{ 532{
528 port->cmd_addr = 533 port->cmd_addr =
529 port->data_addr = base + 0x000; 534 port->data_addr = base + 0x000;
@@ -550,48 +555,28 @@ static int adma_port_start(struct ata_port *ap)
550 if (rc) 555 if (rc)
551 return rc; 556 return rc;
552 adma_enter_reg_mode(ap); 557 adma_enter_reg_mode(ap);
553 rc = -ENOMEM; 558 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
554 pp = kzalloc(sizeof(*pp), GFP_KERNEL);
555 if (!pp) 559 if (!pp)
556 goto err_out; 560 return -ENOMEM;
557 pp->pkt = dma_alloc_coherent(dev, ADMA_PKT_BYTES, &pp->pkt_dma, 561 pp->pkt = dmam_alloc_coherent(dev, ADMA_PKT_BYTES, &pp->pkt_dma,
558 GFP_KERNEL); 562 GFP_KERNEL);
559 if (!pp->pkt) 563 if (!pp->pkt)
560 goto err_out_kfree; 564 return -ENOMEM;
561 /* paranoia? */ 565 /* paranoia? */
562 if ((pp->pkt_dma & 7) != 0) { 566 if ((pp->pkt_dma & 7) != 0) {
563 printk("bad alignment for pp->pkt_dma: %08x\n", 567 printk("bad alignment for pp->pkt_dma: %08x\n",
564 (u32)pp->pkt_dma); 568 (u32)pp->pkt_dma);
565 dma_free_coherent(dev, ADMA_PKT_BYTES, 569 return -ENOMEM;
566 pp->pkt, pp->pkt_dma);
567 goto err_out_kfree;
568 } 570 }
569 memset(pp->pkt, 0, ADMA_PKT_BYTES); 571 memset(pp->pkt, 0, ADMA_PKT_BYTES);
570 ap->private_data = pp; 572 ap->private_data = pp;
571 adma_reinit_engine(ap); 573 adma_reinit_engine(ap);
572 return 0; 574 return 0;
573
574err_out_kfree:
575 kfree(pp);
576err_out:
577 ata_port_stop(ap);
578 return rc;
579} 575}
580 576
581static void adma_port_stop(struct ata_port *ap) 577static void adma_port_stop(struct ata_port *ap)
582{ 578{
583 struct device *dev = ap->host->dev; 579 adma_reset_engine(ADMA_HOST_REGS(ap->host, ap->port_no));
584 struct adma_port_priv *pp = ap->private_data;
585
586 adma_reset_engine(ADMA_REGS(ap->host->mmio_base, ap->port_no));
587 if (pp != NULL) {
588 ap->private_data = NULL;
589 if (pp->pkt != NULL)
590 dma_free_coherent(dev, ADMA_PKT_BYTES,
591 pp->pkt, pp->pkt_dma);
592 kfree(pp);
593 }
594 ata_port_stop(ap);
595} 580}
596 581
597static void adma_host_stop(struct ata_host *host) 582static void adma_host_stop(struct ata_host *host)
@@ -599,16 +584,14 @@ static void adma_host_stop(struct ata_host *host)
599 unsigned int port_no; 584 unsigned int port_no;
600 585
601 for (port_no = 0; port_no < ADMA_PORTS; ++port_no) 586 for (port_no = 0; port_no < ADMA_PORTS; ++port_no)
602 adma_reset_engine(ADMA_REGS(host->mmio_base, port_no)); 587 adma_reset_engine(ADMA_HOST_REGS(host, port_no));
603
604 ata_pci_host_stop(host);
605} 588}
606 589
607static void adma_host_init(unsigned int chip_id, 590static void adma_host_init(unsigned int chip_id,
608 struct ata_probe_ent *probe_ent) 591 struct ata_probe_ent *probe_ent)
609{ 592{
610 unsigned int port_no; 593 unsigned int port_no;
611 void __iomem *mmio_base = probe_ent->mmio_base; 594 void __iomem *mmio_base = probe_ent->iomap[ADMA_MMIO_BAR];
612 595
613 /* enable/lock aGO operation */ 596 /* enable/lock aGO operation */
614 writeb(7, mmio_base + ADMA_MODE_LOCK); 597 writeb(7, mmio_base + ADMA_MODE_LOCK);
@@ -638,7 +621,7 @@ static int adma_set_dma_masks(struct pci_dev *pdev, void __iomem *mmio_base)
638} 621}
639 622
640static int adma_ata_init_one(struct pci_dev *pdev, 623static int adma_ata_init_one(struct pci_dev *pdev,
641 const struct pci_device_id *ent) 624 const struct pci_device_id *ent)
642{ 625{
643 static int printed_version; 626 static int printed_version;
644 struct ata_probe_ent *probe_ent = NULL; 627 struct ata_probe_ent *probe_ent = NULL;
@@ -649,34 +632,25 @@ static int adma_ata_init_one(struct pci_dev *pdev,
649 if (!printed_version++) 632 if (!printed_version++)
650 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 633 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
651 634
652 rc = pci_enable_device(pdev); 635 rc = pcim_enable_device(pdev);
653 if (rc) 636 if (rc)
654 return rc; 637 return rc;
655 638
656 rc = pci_request_regions(pdev, DRV_NAME); 639 if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0)
657 if (rc) 640 return -ENODEV;
658 goto err_out;
659
660 if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0) {
661 rc = -ENODEV;
662 goto err_out_regions;
663 }
664 641
665 mmio_base = pci_iomap(pdev, 4, 0); 642 rc = pcim_iomap_regions(pdev, 1 << ADMA_MMIO_BAR, DRV_NAME);
666 if (mmio_base == NULL) { 643 if (rc)
667 rc = -ENOMEM; 644 return rc;
668 goto err_out_regions; 645 mmio_base = pcim_iomap_table(pdev)[ADMA_MMIO_BAR];
669 }
670 646
671 rc = adma_set_dma_masks(pdev, mmio_base); 647 rc = adma_set_dma_masks(pdev, mmio_base);
672 if (rc) 648 if (rc)
673 goto err_out_iounmap; 649 return rc;
674 650
675 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); 651 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
676 if (probe_ent == NULL) { 652 if (probe_ent == NULL)
677 rc = -ENOMEM; 653 return -ENOMEM;
678 goto err_out_iounmap;
679 }
680 654
681 probe_ent->dev = pci_dev_to_dev(pdev); 655 probe_ent->dev = pci_dev_to_dev(pdev);
682 INIT_LIST_HEAD(&probe_ent->node); 656 INIT_LIST_HEAD(&probe_ent->node);
@@ -690,12 +664,12 @@ static int adma_ata_init_one(struct pci_dev *pdev,
690 664
691 probe_ent->irq = pdev->irq; 665 probe_ent->irq = pdev->irq;
692 probe_ent->irq_flags = IRQF_SHARED; 666 probe_ent->irq_flags = IRQF_SHARED;
693 probe_ent->mmio_base = mmio_base;
694 probe_ent->n_ports = ADMA_PORTS; 667 probe_ent->n_ports = ADMA_PORTS;
668 probe_ent->iomap = pcim_iomap_table(pdev);
695 669
696 for (port_no = 0; port_no < probe_ent->n_ports; ++port_no) { 670 for (port_no = 0; port_no < probe_ent->n_ports; ++port_no) {
697 adma_ata_setup_port(&probe_ent->port[port_no], 671 adma_ata_setup_port(&probe_ent->port[port_no],
698 ADMA_ATA_REGS((unsigned long)mmio_base, port_no)); 672 ADMA_ATA_REGS(mmio_base, port_no));
699 } 673 }
700 674
701 pci_set_master(pdev); 675 pci_set_master(pdev);
@@ -703,19 +677,11 @@ static int adma_ata_init_one(struct pci_dev *pdev,
703 /* initialize adapter */ 677 /* initialize adapter */
704 adma_host_init(board_idx, probe_ent); 678 adma_host_init(board_idx, probe_ent);
705 679
706 rc = ata_device_add(probe_ent); 680 if (!ata_device_add(probe_ent))
707 kfree(probe_ent); 681 return -ENODEV;
708 if (rc != ADMA_PORTS)
709 goto err_out_iounmap;
710 return 0;
711 682
712err_out_iounmap: 683 devm_kfree(&pdev->dev, probe_ent);
713 pci_iounmap(pdev, mmio_base); 684 return 0;
714err_out_regions:
715 pci_release_regions(pdev);
716err_out:
717 pci_disable_device(pdev);
718 return rc;
719} 685}
720 686
721static int __init adma_ata_init(void) 687static int __init adma_ata_init(void)
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
new file mode 100644
index 00000000000..c5335f42280
--- /dev/null
+++ b/drivers/ata/sata_inic162x.c
@@ -0,0 +1,781 @@
1/*
2 * sata_inic162x.c - Driver for Initio 162x SATA controllers
3 *
4 * Copyright 2006 SUSE Linux Products GmbH
5 * Copyright 2006 Tejun Heo <teheo@novell.com>
6 *
7 * This file is released under GPL v2.
8 *
9 * This controller is eccentric and easily locks up if something isn't
10 * right. Documentation is available at initio's website but it only
11 * documents registers (not programming model).
12 *
13 * - ATA disks work.
14 * - Hotplug works.
15 * - ATAPI read works but burning doesn't. This thing is really
16 * peculiar about ATAPI and I couldn't figure out how ATAPI PIO and
17 * ATAPI DMA WRITE should be programmed. If you've got a clue, be
18 * my guest.
19 * - Both STR and STD work.
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/pci.h>
25#include <scsi/scsi_host.h>
26#include <linux/libata.h>
27#include <linux/blkdev.h>
28#include <scsi/scsi_device.h>
29
30#define DRV_NAME "sata_inic162x"
31#define DRV_VERSION "0.1"
32
33enum {
34 MMIO_BAR = 5,
35
36 NR_PORTS = 2,
37
38 HOST_CTL = 0x7c,
39 HOST_STAT = 0x7e,
40 HOST_IRQ_STAT = 0xbc,
41 HOST_IRQ_MASK = 0xbe,
42
43 PORT_SIZE = 0x40,
44
45 /* registers for ATA TF operation */
46 PORT_TF = 0x00,
47 PORT_ALT_STAT = 0x08,
48 PORT_IRQ_STAT = 0x09,
49 PORT_IRQ_MASK = 0x0a,
50 PORT_PRD_CTL = 0x0b,
51 PORT_PRD_ADDR = 0x0c,
52 PORT_PRD_XFERLEN = 0x10,
53
54 /* IDMA register */
55 PORT_IDMA_CTL = 0x14,
56
57 PORT_SCR = 0x20,
58
59 /* HOST_CTL bits */
60 HCTL_IRQOFF = (1 << 8), /* global IRQ off */
61 HCTL_PWRDWN = (1 << 13), /* power down PHYs */
62 HCTL_SOFTRST = (1 << 13), /* global reset (no phy reset) */
63 HCTL_RPGSEL = (1 << 15), /* register page select */
64
65 HCTL_KNOWN_BITS = HCTL_IRQOFF | HCTL_PWRDWN | HCTL_SOFTRST |
66 HCTL_RPGSEL,
67
68 /* HOST_IRQ_(STAT|MASK) bits */
69 HIRQ_PORT0 = (1 << 0),
70 HIRQ_PORT1 = (1 << 1),
71 HIRQ_SOFT = (1 << 14),
72 HIRQ_GLOBAL = (1 << 15), /* STAT only */
73
74 /* PORT_IRQ_(STAT|MASK) bits */
75 PIRQ_OFFLINE = (1 << 0), /* device unplugged */
76 PIRQ_ONLINE = (1 << 1), /* device plugged */
77 PIRQ_COMPLETE = (1 << 2), /* completion interrupt */
78 PIRQ_FATAL = (1 << 3), /* fatal error */
79 PIRQ_ATA = (1 << 4), /* ATA interrupt */
80 PIRQ_REPLY = (1 << 5), /* reply FIFO not empty */
81 PIRQ_PENDING = (1 << 7), /* port IRQ pending (STAT only) */
82
83 PIRQ_ERR = PIRQ_OFFLINE | PIRQ_ONLINE | PIRQ_FATAL,
84
85 PIRQ_MASK_DMA_READ = PIRQ_REPLY | PIRQ_ATA,
86 PIRQ_MASK_OTHER = PIRQ_REPLY | PIRQ_COMPLETE,
87 PIRQ_MASK_FREEZE = 0xff,
88
89 /* PORT_PRD_CTL bits */
90 PRD_CTL_START = (1 << 0),
91 PRD_CTL_WR = (1 << 3),
92 PRD_CTL_DMAEN = (1 << 7), /* DMA enable */
93
94 /* PORT_IDMA_CTL bits */
95 IDMA_CTL_RST_ATA = (1 << 2), /* hardreset ATA bus */
96 IDMA_CTL_RST_IDMA = (1 << 5), /* reset IDMA machinary */
97 IDMA_CTL_GO = (1 << 7), /* IDMA mode go */
98 IDMA_CTL_ATA_NIEN = (1 << 8), /* ATA IRQ disable */
99};
100
101struct inic_host_priv {
102 u16 cached_hctl;
103};
104
105struct inic_port_priv {
106 u8 dfl_prdctl;
107 u8 cached_prdctl;
108 u8 cached_pirq_mask;
109};
110
111static int inic_slave_config(struct scsi_device *sdev)
112{
113 /* This controller is braindamaged. dma_boundary is 0xffff
114 * like others but it will lock up the whole machine HARD if
115 * 65536 byte PRD entry is fed. Reduce maximum segment size.
116 */
117 blk_queue_max_segment_size(sdev->request_queue, 65536 - 512);
118
119 return ata_scsi_slave_config(sdev);
120}
121
122static struct scsi_host_template inic_sht = {
123 .module = THIS_MODULE,
124 .name = DRV_NAME,
125 .ioctl = ata_scsi_ioctl,
126 .queuecommand = ata_scsi_queuecmd,
127 .can_queue = ATA_DEF_QUEUE,
128 .this_id = ATA_SHT_THIS_ID,
129 .sg_tablesize = LIBATA_MAX_PRD,
130 .cmd_per_lun = ATA_SHT_CMD_PER_LUN,
131 .emulated = ATA_SHT_EMULATED,
132 .use_clustering = ATA_SHT_USE_CLUSTERING,
133 .proc_name = DRV_NAME,
134 .dma_boundary = ATA_DMA_BOUNDARY,
135 .slave_configure = inic_slave_config,
136 .slave_destroy = ata_scsi_slave_destroy,
137 .bios_param = ata_std_bios_param,
138 .suspend = ata_scsi_device_suspend,
139 .resume = ata_scsi_device_resume,
140};
141
142static const int scr_map[] = {
143 [SCR_STATUS] = 0,
144 [SCR_ERROR] = 1,
145 [SCR_CONTROL] = 2,
146};
147
148static void __iomem * inic_port_base(struct ata_port *ap)
149{
150 return ap->host->iomap[MMIO_BAR] + ap->port_no * PORT_SIZE;
151}
152
153static void __inic_set_pirq_mask(struct ata_port *ap, u8 mask)
154{
155 void __iomem *port_base = inic_port_base(ap);
156 struct inic_port_priv *pp = ap->private_data;
157
158 writeb(mask, port_base + PORT_IRQ_MASK);
159 pp->cached_pirq_mask = mask;
160}
161
162static void inic_set_pirq_mask(struct ata_port *ap, u8 mask)
163{
164 struct inic_port_priv *pp = ap->private_data;
165
166 if (pp->cached_pirq_mask != mask)
167 __inic_set_pirq_mask(ap, mask);
168}
169
170static void inic_reset_port(void __iomem *port_base)
171{
172 void __iomem *idma_ctl = port_base + PORT_IDMA_CTL;
173 u16 ctl;
174
175 ctl = readw(idma_ctl);
176 ctl &= ~(IDMA_CTL_RST_IDMA | IDMA_CTL_ATA_NIEN | IDMA_CTL_GO);
177
178 /* mask IRQ and assert reset */
179 writew(ctl | IDMA_CTL_RST_IDMA | IDMA_CTL_ATA_NIEN, idma_ctl);
180 readw(idma_ctl); /* flush */
181
182 /* give it some time */
183 msleep(1);
184
185 /* release reset */
186 writew(ctl | IDMA_CTL_ATA_NIEN, idma_ctl);
187
188 /* clear irq */
189 writeb(0xff, port_base + PORT_IRQ_STAT);
190
191 /* reenable ATA IRQ, turn off IDMA mode */
192 writew(ctl, idma_ctl);
193}
194
195static u32 inic_scr_read(struct ata_port *ap, unsigned sc_reg)
196{
197 void __iomem *scr_addr = (void __iomem *)ap->ioaddr.scr_addr;
198 void __iomem *addr;
199 u32 val;
200
201 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map)))
202 return 0xffffffffU;
203
204 addr = scr_addr + scr_map[sc_reg] * 4;
205 val = readl(scr_addr + scr_map[sc_reg] * 4);
206
207 /* this controller has stuck DIAG.N, ignore it */
208 if (sc_reg == SCR_ERROR)
209 val &= ~SERR_PHYRDY_CHG;
210 return val;
211}
212
213static void inic_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val)
214{
215 void __iomem *scr_addr = (void __iomem *)ap->ioaddr.scr_addr;
216 void __iomem *addr;
217
218 if (unlikely(sc_reg >= ARRAY_SIZE(scr_map)))
219 return;
220
221 addr = scr_addr + scr_map[sc_reg] * 4;
222 writel(val, scr_addr + scr_map[sc_reg] * 4);
223}
224
225/*
226 * In TF mode, inic162x is very similar to SFF device. TF registers
227 * function the same. DMA engine behaves similary using the same PRD
228 * format as BMDMA but different command register, interrupt and event
229 * notification methods are used. The following inic_bmdma_*()
230 * functions do the impedance matching.
231 */
232static void inic_bmdma_setup(struct ata_queued_cmd *qc)
233{
234 struct ata_port *ap = qc->ap;
235 struct inic_port_priv *pp = ap->private_data;
236 void __iomem *port_base = inic_port_base(ap);
237 int rw = qc->tf.flags & ATA_TFLAG_WRITE;
238
239 /* make sure device sees PRD table writes */
240 wmb();
241
242 /* load transfer length */
243 writel(qc->nbytes, port_base + PORT_PRD_XFERLEN);
244
245 /* turn on DMA and specify data direction */
246 pp->cached_prdctl = pp->dfl_prdctl | PRD_CTL_DMAEN;
247 if (!rw)
248 pp->cached_prdctl |= PRD_CTL_WR;
249 writeb(pp->cached_prdctl, port_base + PORT_PRD_CTL);
250
251 /* issue r/w command */
252 ap->ops->exec_command(ap, &qc->tf);
253}
254
255static void inic_bmdma_start(struct ata_queued_cmd *qc)
256{
257 struct ata_port *ap = qc->ap;
258 struct inic_port_priv *pp = ap->private_data;
259 void __iomem *port_base = inic_port_base(ap);
260
261 /* start host DMA transaction */
262 pp->cached_prdctl |= PRD_CTL_START;
263 writeb(pp->cached_prdctl, port_base + PORT_PRD_CTL);
264}
265
266static void inic_bmdma_stop(struct ata_queued_cmd *qc)
267{
268 struct ata_port *ap = qc->ap;
269 struct inic_port_priv *pp = ap->private_data;
270 void __iomem *port_base = inic_port_base(ap);
271
272 /* stop DMA engine */
273 writeb(pp->dfl_prdctl, port_base + PORT_PRD_CTL);
274}
275
276static u8 inic_bmdma_status(struct ata_port *ap)
277{
278 /* event is already verified by the interrupt handler */
279 return ATA_DMA_INTR;
280}
281
282static void inic_irq_clear(struct ata_port *ap)
283{
284 /* noop */
285}
286
287static void inic_host_intr(struct ata_port *ap)
288{
289 void __iomem *port_base = inic_port_base(ap);
290 struct ata_eh_info *ehi = &ap->eh_info;
291 u8 irq_stat;
292
293 /* fetch and clear irq */
294 irq_stat = readb(port_base + PORT_IRQ_STAT);
295 writeb(irq_stat, port_base + PORT_IRQ_STAT);
296
297 if (likely(!(irq_stat & PIRQ_ERR))) {
298 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, ap->active_tag);
299
300 if (unlikely(!qc || (qc->tf.flags & ATA_TFLAG_POLLING))) {
301 ata_chk_status(ap); /* clear ATA interrupt */
302 return;
303 }
304
305 if (likely(ata_host_intr(ap, qc)))
306 return;
307
308 ata_chk_status(ap); /* clear ATA interrupt */
309 ata_port_printk(ap, KERN_WARNING, "unhandled "
310 "interrupt, irq_stat=%x\n", irq_stat);
311 return;
312 }
313
314 /* error */
315 ata_ehi_push_desc(ehi, "irq_stat=0x%x", irq_stat);
316
317 if (irq_stat & (PIRQ_OFFLINE | PIRQ_ONLINE)) {
318 ata_ehi_hotplugged(ehi);
319 ata_port_freeze(ap);
320 } else
321 ata_port_abort(ap);
322}
323
324static irqreturn_t inic_interrupt(int irq, void *dev_instance)
325{
326 struct ata_host *host = dev_instance;
327 void __iomem *mmio_base = host->iomap[MMIO_BAR];
328 u16 host_irq_stat;
329 int i, handled = 0;;
330
331 host_irq_stat = readw(mmio_base + HOST_IRQ_STAT);
332
333 if (unlikely(!(host_irq_stat & HIRQ_GLOBAL)))
334 goto out;
335
336 spin_lock(&host->lock);
337
338 for (i = 0; i < NR_PORTS; i++) {
339 struct ata_port *ap = host->ports[i];
340
341 if (!(host_irq_stat & (HIRQ_PORT0 << i)))
342 continue;
343
344 if (likely(ap && !(ap->flags & ATA_FLAG_DISABLED))) {
345 inic_host_intr(ap);
346 handled++;
347 } else {
348 if (ata_ratelimit())
349 dev_printk(KERN_ERR, host->dev, "interrupt "
350 "from disabled port %d (0x%x)\n",
351 i, host_irq_stat);
352 }
353 }
354
355 spin_unlock(&host->lock);
356
357 out:
358 return IRQ_RETVAL(handled);
359}
360
361static unsigned int inic_qc_issue(struct ata_queued_cmd *qc)
362{
363 struct ata_port *ap = qc->ap;
364
365 /* ATA IRQ doesn't wait for DMA transfer completion and vice
366 * versa. Mask IRQ selectively to detect command completion.
367 * Without it, ATA DMA read command can cause data corruption.
368 *
369 * Something similar might be needed for ATAPI writes. I
370 * tried a lot of combinations but couldn't find the solution.
371 */
372 if (qc->tf.protocol == ATA_PROT_DMA &&
373 !(qc->tf.flags & ATA_TFLAG_WRITE))
374 inic_set_pirq_mask(ap, PIRQ_MASK_DMA_READ);
375 else
376 inic_set_pirq_mask(ap, PIRQ_MASK_OTHER);
377
378 /* Issuing a command to yet uninitialized port locks up the
379 * controller. Most of the time, this happens for the first
380 * command after reset which are ATA and ATAPI IDENTIFYs.
381 * Fast fail if stat is 0x7f or 0xff for those commands.
382 */
383 if (unlikely(qc->tf.command == ATA_CMD_ID_ATA ||
384 qc->tf.command == ATA_CMD_ID_ATAPI)) {
385 u8 stat = ata_chk_status(ap);
386 if (stat == 0x7f || stat == 0xff)
387 return AC_ERR_HSM;
388 }
389
390 return ata_qc_issue_prot(qc);
391}
392
393static void inic_freeze(struct ata_port *ap)
394{
395 void __iomem *port_base = inic_port_base(ap);
396
397 __inic_set_pirq_mask(ap, PIRQ_MASK_FREEZE);
398
399 ata_chk_status(ap);
400 writeb(0xff, port_base + PORT_IRQ_STAT);
401
402 readb(port_base + PORT_IRQ_STAT); /* flush */
403}
404
405static void inic_thaw(struct ata_port *ap)
406{
407 void __iomem *port_base = inic_port_base(ap);
408
409 ata_chk_status(ap);
410 writeb(0xff, port_base + PORT_IRQ_STAT);
411
412 __inic_set_pirq_mask(ap, PIRQ_MASK_OTHER);
413
414 readb(port_base + PORT_IRQ_STAT); /* flush */
415}
416
417/*
418 * SRST and SControl hardreset don't give valid signature on this
419 * controller. Only controller specific hardreset mechanism works.
420 */
421static int inic_hardreset(struct ata_port *ap, unsigned int *class)
422{
423 void __iomem *port_base = inic_port_base(ap);
424 void __iomem *idma_ctl = port_base + PORT_IDMA_CTL;
425 const unsigned long *timing = sata_ehc_deb_timing(&ap->eh_context);
426 u16 val;
427 int rc;
428
429 /* hammer it into sane state */
430 inic_reset_port(port_base);
431
432 val = readw(idma_ctl);
433 writew(val | IDMA_CTL_RST_ATA, idma_ctl);
434 readw(idma_ctl); /* flush */
435 msleep(1);
436 writew(val & ~IDMA_CTL_RST_ATA, idma_ctl);
437
438 rc = sata_phy_resume(ap, timing);
439 if (rc) {
440 ata_port_printk(ap, KERN_WARNING, "failed to resume "
441 "link after reset (errno=%d)\n", rc);
442 return rc;
443 }
444
445 *class = ATA_DEV_NONE;
446 if (ata_port_online(ap)) {
447 struct ata_taskfile tf;
448
449 /* wait a while before checking status */
450 msleep(150);
451
452 if (ata_busy_sleep(ap, ATA_TMOUT_BOOT_QUICK, ATA_TMOUT_BOOT)) {
453 ata_port_printk(ap, KERN_WARNING,
454 "device busy after hardreset\n");
455 return -EIO;
456 }
457
458 ata_tf_read(ap, &tf);
459 *class = ata_dev_classify(&tf);
460 if (*class == ATA_DEV_UNKNOWN)
461 *class = ATA_DEV_NONE;
462 }
463
464 return 0;
465}
466
467static void inic_error_handler(struct ata_port *ap)
468{
469 void __iomem *port_base = inic_port_base(ap);
470 struct inic_port_priv *pp = ap->private_data;
471 unsigned long flags;
472
473 /* reset PIO HSM and stop DMA engine */
474 inic_reset_port(port_base);
475
476 spin_lock_irqsave(ap->lock, flags);
477 ap->hsm_task_state = HSM_ST_IDLE;
478 writeb(pp->dfl_prdctl, port_base + PORT_PRD_CTL);
479 spin_unlock_irqrestore(ap->lock, flags);
480
481 /* PIO and DMA engines have been stopped, perform recovery */
482 ata_do_eh(ap, ata_std_prereset, NULL, inic_hardreset,
483 ata_std_postreset);
484}
485
486static void inic_post_internal_cmd(struct ata_queued_cmd *qc)
487{
488 /* make DMA engine forget about the failed command */
489 if (qc->err_mask)
490 inic_reset_port(inic_port_base(qc->ap));
491}
492
493static void inic_dev_config(struct ata_port *ap, struct ata_device *dev)
494{
495 /* inic can only handle upto LBA28 max sectors */
496 if (dev->max_sectors > ATA_MAX_SECTORS)
497 dev->max_sectors = ATA_MAX_SECTORS;
498}
499
500static void init_port(struct ata_port *ap)
501{
502 void __iomem *port_base = inic_port_base(ap);
503
504 /* Setup PRD address */
505 writel(ap->prd_dma, port_base + PORT_PRD_ADDR);
506}
507
508static int inic_port_resume(struct ata_port *ap)
509{
510 init_port(ap);
511 return 0;
512}
513
514static int inic_port_start(struct ata_port *ap)
515{
516 void __iomem *port_base = inic_port_base(ap);
517 struct inic_port_priv *pp;
518 u8 tmp;
519 int rc;
520
521 /* alloc and initialize private data */
522 pp = devm_kzalloc(ap->host->dev, sizeof(*pp), GFP_KERNEL);
523 if (!pp)
524 return -ENOMEM;
525 ap->private_data = pp;
526
527 /* default PRD_CTL value, DMAEN, WR and START off */
528 tmp = readb(port_base + PORT_PRD_CTL);
529 tmp &= ~(PRD_CTL_DMAEN | PRD_CTL_WR | PRD_CTL_START);
530 pp->dfl_prdctl = tmp;
531
532 /* Alloc resources */
533 rc = ata_port_start(ap);
534 if (rc) {
535 kfree(pp);
536 return rc;
537 }
538
539 init_port(ap);
540
541 return 0;
542}
543
544static struct ata_port_operations inic_port_ops = {
545 .port_disable = ata_port_disable,
546 .tf_load = ata_tf_load,
547 .tf_read = ata_tf_read,
548 .check_status = ata_check_status,
549 .exec_command = ata_exec_command,
550 .dev_select = ata_std_dev_select,
551
552 .scr_read = inic_scr_read,
553 .scr_write = inic_scr_write,
554
555 .bmdma_setup = inic_bmdma_setup,
556 .bmdma_start = inic_bmdma_start,
557 .bmdma_stop = inic_bmdma_stop,
558 .bmdma_status = inic_bmdma_status,
559
560 .irq_handler = inic_interrupt,
561 .irq_clear = inic_irq_clear,
562 .irq_on = ata_irq_on,
563 .irq_ack = ata_irq_ack,
564
565 .qc_prep = ata_qc_prep,
566 .qc_issue = inic_qc_issue,
567 .data_xfer = ata_data_xfer,
568
569 .freeze = inic_freeze,
570 .thaw = inic_thaw,
571 .error_handler = inic_error_handler,
572 .post_internal_cmd = inic_post_internal_cmd,
573 .dev_config = inic_dev_config,
574
575 .port_resume = inic_port_resume,
576
577 .port_start = inic_port_start,
578};
579
580static struct ata_port_info inic_port_info = {
581 .sht = &inic_sht,
582 /* For some reason, ATA_PROT_ATAPI is broken on this
583 * controller, and no, PIO_POLLING does't fix it. It somehow
584 * manages to report the wrong ireason and ignoring ireason
585 * results in machine lock up. Tell libata to always prefer
586 * DMA.
587 */
588 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
589 .pio_mask = 0x1f, /* pio0-4 */
590 .mwdma_mask = 0x07, /* mwdma0-2 */
591 .udma_mask = 0x7f, /* udma0-6 */
592 .port_ops = &inic_port_ops
593};
594
595static int init_controller(void __iomem *mmio_base, u16 hctl)
596{
597 int i;
598 u16 val;
599
600 hctl &= ~HCTL_KNOWN_BITS;
601
602 /* Soft reset whole controller. Spec says reset duration is 3
603 * PCI clocks, be generous and give it 10ms.
604 */
605 writew(hctl | HCTL_SOFTRST, mmio_base + HOST_CTL);
606 readw(mmio_base + HOST_CTL); /* flush */
607
608 for (i = 0; i < 10; i++) {
609 msleep(1);
610 val = readw(mmio_base + HOST_CTL);
611 if (!(val & HCTL_SOFTRST))
612 break;
613 }
614
615 if (val & HCTL_SOFTRST)
616 return -EIO;
617
618 /* mask all interrupts and reset ports */
619 for (i = 0; i < NR_PORTS; i++) {
620 void __iomem *port_base = mmio_base + i * PORT_SIZE;
621
622 writeb(0xff, port_base + PORT_IRQ_MASK);
623 inic_reset_port(port_base);
624 }
625
626 /* port IRQ is masked now, unmask global IRQ */
627 writew(hctl & ~HCTL_IRQOFF, mmio_base + HOST_CTL);
628 val = readw(mmio_base + HOST_IRQ_MASK);
629 val &= ~(HIRQ_PORT0 | HIRQ_PORT1);
630 writew(val, mmio_base + HOST_IRQ_MASK);
631
632 return 0;
633}
634
635static int inic_pci_device_resume(struct pci_dev *pdev)
636{
637 struct ata_host *host = dev_get_drvdata(&pdev->dev);
638 struct inic_host_priv *hpriv = host->private_data;
639 void __iomem *mmio_base = host->iomap[MMIO_BAR];
640 int rc;
641
642 ata_pci_device_do_resume(pdev);
643
644 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
645 printk("XXX\n");
646 rc = init_controller(mmio_base, hpriv->cached_hctl);
647 if (rc)
648 return rc;
649 }
650
651 ata_host_resume(host);
652
653 return 0;
654}
655
656static int inic_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
657{
658 static int printed_version;
659 struct ata_port_info *pinfo = &inic_port_info;
660 struct ata_probe_ent *probe_ent;
661 struct inic_host_priv *hpriv;
662 void __iomem * const *iomap;
663 int i, rc;
664
665 if (!printed_version++)
666 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
667
668 rc = pcim_enable_device(pdev);
669 if (rc)
670 return rc;
671
672 rc = pci_request_regions(pdev, DRV_NAME);
673 if (rc)
674 return rc;
675
676 rc = pcim_iomap_regions(pdev, 0x3f, DRV_NAME);
677 if (rc)
678 return rc;
679 iomap = pcim_iomap_table(pdev);
680
681 /* Set dma_mask. This devices doesn't support 64bit addressing. */
682 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
683 if (rc) {
684 dev_printk(KERN_ERR, &pdev->dev,
685 "32-bit DMA enable failed\n");
686 return rc;
687 }
688
689 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
690 if (rc) {
691 dev_printk(KERN_ERR, &pdev->dev,
692 "32-bit consistent DMA enable failed\n");
693 return rc;
694 }
695
696 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
697 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
698 if (!probe_ent || !hpriv)
699 return -ENOMEM;
700
701 probe_ent->dev = &pdev->dev;
702 INIT_LIST_HEAD(&probe_ent->node);
703
704 probe_ent->sht = pinfo->sht;
705 probe_ent->port_flags = pinfo->flags;
706 probe_ent->pio_mask = pinfo->pio_mask;
707 probe_ent->mwdma_mask = pinfo->mwdma_mask;
708 probe_ent->udma_mask = pinfo->udma_mask;
709 probe_ent->port_ops = pinfo->port_ops;
710 probe_ent->n_ports = NR_PORTS;
711
712 probe_ent->irq = pdev->irq;
713 probe_ent->irq_flags = SA_SHIRQ;
714
715 probe_ent->iomap = iomap;
716
717 for (i = 0; i < NR_PORTS; i++) {
718 struct ata_ioports *port = &probe_ent->port[i];
719 void __iomem *port_base = iomap[MMIO_BAR] + i * PORT_SIZE;
720
721 port->cmd_addr = iomap[2 * i];
722 port->altstatus_addr =
723 port->ctl_addr = (void __iomem *)
724 ((unsigned long)iomap[2 * i + 1] | ATA_PCI_CTL_OFS);
725 port->scr_addr = port_base + PORT_SCR;
726
727 ata_std_ports(port);
728 }
729
730 probe_ent->private_data = hpriv;
731 hpriv->cached_hctl = readw(iomap[MMIO_BAR] + HOST_CTL);
732
733 rc = init_controller(iomap[MMIO_BAR], hpriv->cached_hctl);
734 if (rc) {
735 dev_printk(KERN_ERR, &pdev->dev,
736 "failed to initialize controller\n");
737 return rc;
738 }
739
740 pci_set_master(pdev);
741
742 if (!ata_device_add(probe_ent))
743 return -ENODEV;
744
745 devm_kfree(&pdev->dev, probe_ent);
746
747 return 0;
748}
749
750static const struct pci_device_id inic_pci_tbl[] = {
751 { PCI_VDEVICE(INIT, 0x1622), },
752 { },
753};
754
755static struct pci_driver inic_pci_driver = {
756 .name = DRV_NAME,
757 .id_table = inic_pci_tbl,
758 .suspend = ata_pci_device_suspend,
759 .resume = inic_pci_device_resume,
760 .probe = inic_init_one,
761 .remove = ata_pci_remove_one,
762};
763
764static int __init inic_init(void)
765{
766 return pci_register_driver(&inic_pci_driver);
767}
768
769static void __exit inic_exit(void)
770{
771 pci_unregister_driver(&inic_pci_driver);
772}
773
774MODULE_AUTHOR("Tejun Heo");
775MODULE_DESCRIPTION("low-level driver for Initio 162x SATA");
776MODULE_LICENSE("GPL v2");
777MODULE_DEVICE_TABLE(pci, inic_pci_tbl);
778MODULE_VERSION(DRV_VERSION);
779
780module_init(inic_init);
781module_exit(inic_exit);
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index aae0b5201c1..769eca52442 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -34,7 +34,6 @@
34#include <scsi/scsi_host.h> 34#include <scsi/scsi_host.h>
35#include <scsi/scsi_cmnd.h> 35#include <scsi/scsi_cmnd.h>
36#include <linux/libata.h> 36#include <linux/libata.h>
37#include <asm/io.h>
38 37
39#define DRV_NAME "sata_mv" 38#define DRV_NAME "sata_mv"
40#define DRV_VERSION "0.7" 39#define DRV_VERSION "0.7"
@@ -342,7 +341,6 @@ static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in);
342static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val); 341static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val);
343static void mv_phy_reset(struct ata_port *ap); 342static void mv_phy_reset(struct ata_port *ap);
344static void __mv_phy_reset(struct ata_port *ap, int can_sleep); 343static void __mv_phy_reset(struct ata_port *ap, int can_sleep);
345static void mv_host_stop(struct ata_host *host);
346static int mv_port_start(struct ata_port *ap); 344static int mv_port_start(struct ata_port *ap);
347static void mv_port_stop(struct ata_port *ap); 345static void mv_port_stop(struct ata_port *ap);
348static void mv_qc_prep(struct ata_queued_cmd *qc); 346static void mv_qc_prep(struct ata_queued_cmd *qc);
@@ -406,19 +404,20 @@ static const struct ata_port_operations mv5_ops = {
406 404
407 .qc_prep = mv_qc_prep, 405 .qc_prep = mv_qc_prep,
408 .qc_issue = mv_qc_issue, 406 .qc_issue = mv_qc_issue,
409 .data_xfer = ata_mmio_data_xfer, 407 .data_xfer = ata_data_xfer,
410 408
411 .eng_timeout = mv_eng_timeout, 409 .eng_timeout = mv_eng_timeout,
412 410
413 .irq_handler = mv_interrupt, 411 .irq_handler = mv_interrupt,
414 .irq_clear = mv_irq_clear, 412 .irq_clear = mv_irq_clear,
413 .irq_on = ata_irq_on,
414 .irq_ack = ata_irq_ack,
415 415
416 .scr_read = mv5_scr_read, 416 .scr_read = mv5_scr_read,
417 .scr_write = mv5_scr_write, 417 .scr_write = mv5_scr_write,
418 418
419 .port_start = mv_port_start, 419 .port_start = mv_port_start,
420 .port_stop = mv_port_stop, 420 .port_stop = mv_port_stop,
421 .host_stop = mv_host_stop,
422}; 421};
423 422
424static const struct ata_port_operations mv6_ops = { 423static const struct ata_port_operations mv6_ops = {
@@ -434,19 +433,20 @@ static const struct ata_port_operations mv6_ops = {
434 433
435 .qc_prep = mv_qc_prep, 434 .qc_prep = mv_qc_prep,
436 .qc_issue = mv_qc_issue, 435 .qc_issue = mv_qc_issue,
437 .data_xfer = ata_mmio_data_xfer, 436 .data_xfer = ata_data_xfer,
438 437
439 .eng_timeout = mv_eng_timeout, 438 .eng_timeout = mv_eng_timeout,
440 439
441 .irq_handler = mv_interrupt, 440 .irq_handler = mv_interrupt,
442 .irq_clear = mv_irq_clear, 441 .irq_clear = mv_irq_clear,
442 .irq_on = ata_irq_on,
443 .irq_ack = ata_irq_ack,
443 444
444 .scr_read = mv_scr_read, 445 .scr_read = mv_scr_read,
445 .scr_write = mv_scr_write, 446 .scr_write = mv_scr_write,
446 447
447 .port_start = mv_port_start, 448 .port_start = mv_port_start,
448 .port_stop = mv_port_stop, 449 .port_stop = mv_port_stop,
449 .host_stop = mv_host_stop,
450}; 450};
451 451
452static const struct ata_port_operations mv_iie_ops = { 452static const struct ata_port_operations mv_iie_ops = {
@@ -462,19 +462,20 @@ static const struct ata_port_operations mv_iie_ops = {
462 462
463 .qc_prep = mv_qc_prep_iie, 463 .qc_prep = mv_qc_prep_iie,
464 .qc_issue = mv_qc_issue, 464 .qc_issue = mv_qc_issue,
465 .data_xfer = ata_mmio_data_xfer, 465 .data_xfer = ata_data_xfer,
466 466
467 .eng_timeout = mv_eng_timeout, 467 .eng_timeout = mv_eng_timeout,
468 468
469 .irq_handler = mv_interrupt, 469 .irq_handler = mv_interrupt,
470 .irq_clear = mv_irq_clear, 470 .irq_clear = mv_irq_clear,
471 .irq_on = ata_irq_on,
472 .irq_ack = ata_irq_ack,
471 473
472 .scr_read = mv_scr_read, 474 .scr_read = mv_scr_read,
473 .scr_write = mv_scr_write, 475 .scr_write = mv_scr_write,
474 476
475 .port_start = mv_port_start, 477 .port_start = mv_port_start,
476 .port_stop = mv_port_stop, 478 .port_stop = mv_port_stop,
477 .host_stop = mv_host_stop,
478}; 479};
479 480
480static const struct ata_port_info mv_port_info[] = { 481static const struct ata_port_info mv_port_info[] = {
@@ -620,7 +621,7 @@ static inline void __iomem *mv_port_base(void __iomem *base, unsigned int port)
620 621
621static inline void __iomem *mv_ap_base(struct ata_port *ap) 622static inline void __iomem *mv_ap_base(struct ata_port *ap)
622{ 623{
623 return mv_port_base(ap->host->mmio_base, ap->port_no); 624 return mv_port_base(ap->host->iomap[MV_PRIMARY_BAR], ap->port_no);
624} 625}
625 626
626static inline int mv_get_hc_count(unsigned long port_flags) 627static inline int mv_get_hc_count(unsigned long port_flags)
@@ -809,35 +810,6 @@ static void mv_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
809 } 810 }
810} 811}
811 812
812/**
813 * mv_host_stop - Host specific cleanup/stop routine.
814 * @host: host data structure
815 *
816 * Disable ints, cleanup host memory, call general purpose
817 * host_stop.
818 *
819 * LOCKING:
820 * Inherited from caller.
821 */
822static void mv_host_stop(struct ata_host *host)
823{
824 struct mv_host_priv *hpriv = host->private_data;
825 struct pci_dev *pdev = to_pci_dev(host->dev);
826
827 if (hpriv->hp_flags & MV_HP_FLAG_MSI) {
828 pci_disable_msi(pdev);
829 } else {
830 pci_intx(pdev, 0);
831 }
832 kfree(hpriv);
833 ata_host_stop(host);
834}
835
836static inline void mv_priv_free(struct mv_port_priv *pp, struct device *dev)
837{
838 dma_free_coherent(dev, MV_PORT_PRIV_DMA_SZ, pp->crpb, pp->crpb_dma);
839}
840
841static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio) 813static void mv_edma_cfg(struct mv_host_priv *hpriv, void __iomem *port_mmio)
842{ 814{
843 u32 cfg = readl(port_mmio + EDMA_CFG_OFS); 815 u32 cfg = readl(port_mmio + EDMA_CFG_OFS);
@@ -883,22 +855,21 @@ static int mv_port_start(struct ata_port *ap)
883 void __iomem *port_mmio = mv_ap_base(ap); 855 void __iomem *port_mmio = mv_ap_base(ap);
884 void *mem; 856 void *mem;
885 dma_addr_t mem_dma; 857 dma_addr_t mem_dma;
886 int rc = -ENOMEM; 858 int rc;
887 859
888 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 860 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
889 if (!pp) 861 if (!pp)
890 goto err_out; 862 return -ENOMEM;
891 memset(pp, 0, sizeof(*pp));
892 863
893 mem = dma_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma, 864 mem = dmam_alloc_coherent(dev, MV_PORT_PRIV_DMA_SZ, &mem_dma,
894 GFP_KERNEL); 865 GFP_KERNEL);
895 if (!mem) 866 if (!mem)
896 goto err_out_pp; 867 return -ENOMEM;
897 memset(mem, 0, MV_PORT_PRIV_DMA_SZ); 868 memset(mem, 0, MV_PORT_PRIV_DMA_SZ);
898 869
899 rc = ata_pad_alloc(ap, dev); 870 rc = ata_pad_alloc(ap, dev);
900 if (rc) 871 if (rc)
901 goto err_out_priv; 872 return rc;
902 873
903 /* First item in chunk of DMA memory: 874 /* First item in chunk of DMA memory:
904 * 32-slot command request table (CRQB), 32 bytes each in size 875 * 32-slot command request table (CRQB), 32 bytes each in size
@@ -951,13 +922,6 @@ static int mv_port_start(struct ata_port *ap)
951 */ 922 */
952 ap->private_data = pp; 923 ap->private_data = pp;
953 return 0; 924 return 0;
954
955err_out_priv:
956 mv_priv_free(pp, dev);
957err_out_pp:
958 kfree(pp);
959err_out:
960 return rc;
961} 925}
962 926
963/** 927/**
@@ -971,18 +935,11 @@ err_out:
971 */ 935 */
972static void mv_port_stop(struct ata_port *ap) 936static void mv_port_stop(struct ata_port *ap)
973{ 937{
974 struct device *dev = ap->host->dev;
975 struct mv_port_priv *pp = ap->private_data;
976 unsigned long flags; 938 unsigned long flags;
977 939
978 spin_lock_irqsave(&ap->host->lock, flags); 940 spin_lock_irqsave(&ap->host->lock, flags);
979 mv_stop_dma(ap); 941 mv_stop_dma(ap);
980 spin_unlock_irqrestore(&ap->host->lock, flags); 942 spin_unlock_irqrestore(&ap->host->lock, flags);
981
982 ap->private_data = NULL;
983 ata_pad_free(ap, dev);
984 mv_priv_free(pp, dev);
985 kfree(pp);
986} 943}
987 944
988/** 945/**
@@ -1348,7 +1305,7 @@ static void mv_err_intr(struct ata_port *ap, int reset_allowed)
1348 */ 1305 */
1349static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc) 1306static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
1350{ 1307{
1351 void __iomem *mmio = host->mmio_base; 1308 void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
1352 void __iomem *hc_mmio = mv_hc_base(mmio, hc); 1309 void __iomem *hc_mmio = mv_hc_base(mmio, hc);
1353 struct ata_queued_cmd *qc; 1310 struct ata_queued_cmd *qc;
1354 u32 hc_irq_cause; 1311 u32 hc_irq_cause;
@@ -1391,8 +1348,7 @@ static void mv_host_intr(struct ata_host *host, u32 relevant, unsigned int hc)
1391 } else { 1348 } else {
1392 /* PIO: check for device (drive) interrupt */ 1349 /* PIO: check for device (drive) interrupt */
1393 if ((DEV_IRQ << hard_port) & hc_irq_cause) { 1350 if ((DEV_IRQ << hard_port) & hc_irq_cause) {
1394 ata_status = readb((void __iomem *) 1351 ata_status = readb(ap->ioaddr.status_addr);
1395 ap->ioaddr.status_addr);
1396 handled = 1; 1352 handled = 1;
1397 /* ignore spurious intr if drive still BUSY */ 1353 /* ignore spurious intr if drive still BUSY */
1398 if (ata_status & ATA_BUSY) { 1354 if (ata_status & ATA_BUSY) {
@@ -1452,7 +1408,7 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance)
1452{ 1408{
1453 struct ata_host *host = dev_instance; 1409 struct ata_host *host = dev_instance;
1454 unsigned int hc, handled = 0, n_hcs; 1410 unsigned int hc, handled = 0, n_hcs;
1455 void __iomem *mmio = host->mmio_base; 1411 void __iomem *mmio = host->iomap[MV_PRIMARY_BAR];
1456 struct mv_host_priv *hpriv; 1412 struct mv_host_priv *hpriv;
1457 u32 irq_stat; 1413 u32 irq_stat;
1458 1414
@@ -1528,22 +1484,24 @@ static unsigned int mv5_scr_offset(unsigned int sc_reg_in)
1528 1484
1529static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in) 1485static u32 mv5_scr_read(struct ata_port *ap, unsigned int sc_reg_in)
1530{ 1486{
1531 void __iomem *mmio = mv5_phy_base(ap->host->mmio_base, ap->port_no); 1487 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
1488 void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
1532 unsigned int ofs = mv5_scr_offset(sc_reg_in); 1489 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1533 1490
1534 if (ofs != 0xffffffffU) 1491 if (ofs != 0xffffffffU)
1535 return readl(mmio + ofs); 1492 return readl(addr + ofs);
1536 else 1493 else
1537 return (u32) ofs; 1494 return (u32) ofs;
1538} 1495}
1539 1496
1540static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val) 1497static void mv5_scr_write(struct ata_port *ap, unsigned int sc_reg_in, u32 val)
1541{ 1498{
1542 void __iomem *mmio = mv5_phy_base(ap->host->mmio_base, ap->port_no); 1499 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
1500 void __iomem *addr = mv5_phy_base(mmio, ap->port_no);
1543 unsigned int ofs = mv5_scr_offset(sc_reg_in); 1501 unsigned int ofs = mv5_scr_offset(sc_reg_in);
1544 1502
1545 if (ofs != 0xffffffffU) 1503 if (ofs != 0xffffffffU)
1546 writelfl(val, mmio + ofs); 1504 writelfl(val, addr + ofs);
1547} 1505}
1548 1506
1549static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio) 1507static void mv5_reset_bus(struct pci_dev *pdev, void __iomem *mmio)
@@ -1905,7 +1863,7 @@ static void mv_channel_reset(struct mv_host_priv *hpriv, void __iomem *mmio,
1905static void mv_stop_and_reset(struct ata_port *ap) 1863static void mv_stop_and_reset(struct ata_port *ap)
1906{ 1864{
1907 struct mv_host_priv *hpriv = ap->host->private_data; 1865 struct mv_host_priv *hpriv = ap->host->private_data;
1908 void __iomem *mmio = ap->host->mmio_base; 1866 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
1909 1867
1910 mv_stop_dma(ap); 1868 mv_stop_dma(ap);
1911 1869
@@ -2003,10 +1961,10 @@ comreset_retry:
2003 break; 1961 break;
2004 } 1962 }
2005 1963
2006 tf.lbah = readb((void __iomem *) ap->ioaddr.lbah_addr); 1964 tf.lbah = readb(ap->ioaddr.lbah_addr);
2007 tf.lbam = readb((void __iomem *) ap->ioaddr.lbam_addr); 1965 tf.lbam = readb(ap->ioaddr.lbam_addr);
2008 tf.lbal = readb((void __iomem *) ap->ioaddr.lbal_addr); 1966 tf.lbal = readb(ap->ioaddr.lbal_addr);
2009 tf.nsect = readb((void __iomem *) ap->ioaddr.nsect_addr); 1967 tf.nsect = readb(ap->ioaddr.nsect_addr);
2010 1968
2011 dev->class = ata_dev_classify(&tf); 1969 dev->class = ata_dev_classify(&tf);
2012 if (!ata_dev_enabled(dev)) { 1970 if (!ata_dev_enabled(dev)) {
@@ -2038,17 +1996,17 @@ static void mv_phy_reset(struct ata_port *ap)
2038 */ 1996 */
2039static void mv_eng_timeout(struct ata_port *ap) 1997static void mv_eng_timeout(struct ata_port *ap)
2040{ 1998{
1999 void __iomem *mmio = ap->host->iomap[MV_PRIMARY_BAR];
2041 struct ata_queued_cmd *qc; 2000 struct ata_queued_cmd *qc;
2042 unsigned long flags; 2001 unsigned long flags;
2043 2002
2044 ata_port_printk(ap, KERN_ERR, "Entering mv_eng_timeout\n"); 2003 ata_port_printk(ap, KERN_ERR, "Entering mv_eng_timeout\n");
2045 DPRINTK("All regs @ start of eng_timeout\n"); 2004 DPRINTK("All regs @ start of eng_timeout\n");
2046 mv_dump_all_regs(ap->host->mmio_base, ap->port_no, 2005 mv_dump_all_regs(mmio, ap->port_no, to_pci_dev(ap->host->dev));
2047 to_pci_dev(ap->host->dev));
2048 2006
2049 qc = ata_qc_from_tag(ap, ap->active_tag); 2007 qc = ata_qc_from_tag(ap, ap->active_tag);
2050 printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n", 2008 printk(KERN_ERR "mmio_base %p ap %p qc %p scsi_cmnd %p &cmnd %p\n",
2051 ap->host->mmio_base, ap, qc, qc->scsicmd, &qc->scsicmd->cmnd); 2009 mmio, ap, qc, qc->scsicmd, &qc->scsicmd->cmnd);
2052 2010
2053 spin_lock_irqsave(&ap->host->lock, flags); 2011 spin_lock_irqsave(&ap->host->lock, flags);
2054 mv_err_intr(ap, 0); 2012 mv_err_intr(ap, 0);
@@ -2076,7 +2034,7 @@ static void mv_eng_timeout(struct ata_port *ap)
2076 */ 2034 */
2077static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio) 2035static void mv_port_init(struct ata_ioports *port, void __iomem *port_mmio)
2078{ 2036{
2079 unsigned long shd_base = (unsigned long) port_mmio + SHD_BLK_OFS; 2037 void __iomem *shd_base = port_mmio + SHD_BLK_OFS;
2080 unsigned serr_ofs; 2038 unsigned serr_ofs;
2081 2039
2082 /* PIO related setup 2040 /* PIO related setup
@@ -2224,7 +2182,7 @@ static int mv_init_host(struct pci_dev *pdev, struct ata_probe_ent *probe_ent,
2224 unsigned int board_idx) 2182 unsigned int board_idx)
2225{ 2183{
2226 int rc = 0, n_hc, port, hc; 2184 int rc = 0, n_hc, port, hc;
2227 void __iomem *mmio = probe_ent->mmio_base; 2185 void __iomem *mmio = probe_ent->iomap[MV_PRIMARY_BAR];
2228 struct mv_host_priv *hpriv = probe_ent->private_data; 2186 struct mv_host_priv *hpriv = probe_ent->private_data;
2229 2187
2230 /* global interrupt mask */ 2188 /* global interrupt mask */
@@ -2342,49 +2300,36 @@ static void mv_print_info(struct ata_probe_ent *probe_ent)
2342static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 2300static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2343{ 2301{
2344 static int printed_version = 0; 2302 static int printed_version = 0;
2345 struct ata_probe_ent *probe_ent = NULL; 2303 struct device *dev = &pdev->dev;
2304 struct ata_probe_ent *probe_ent;
2346 struct mv_host_priv *hpriv; 2305 struct mv_host_priv *hpriv;
2347 unsigned int board_idx = (unsigned int)ent->driver_data; 2306 unsigned int board_idx = (unsigned int)ent->driver_data;
2348 void __iomem *mmio_base; 2307 int rc;
2349 int pci_dev_busy = 0, rc;
2350 2308
2351 if (!printed_version++) 2309 if (!printed_version++)
2352 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 2310 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
2353 2311
2354 rc = pci_enable_device(pdev); 2312 rc = pcim_enable_device(pdev);
2355 if (rc) { 2313 if (rc)
2356 return rc; 2314 return rc;
2357 }
2358 pci_set_master(pdev); 2315 pci_set_master(pdev);
2359 2316
2360 rc = pci_request_regions(pdev, DRV_NAME); 2317 rc = pcim_iomap_regions(pdev, 1 << MV_PRIMARY_BAR, DRV_NAME);
2361 if (rc) { 2318 if (rc == -EBUSY)
2362 pci_dev_busy = 1; 2319 pcim_pin_device(pdev);
2363 goto err_out; 2320 if (rc)
2364 } 2321 return rc;
2365 2322
2366 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 2323 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
2367 if (probe_ent == NULL) { 2324 if (probe_ent == NULL)
2368 rc = -ENOMEM; 2325 return -ENOMEM;
2369 goto err_out_regions;
2370 }
2371 2326
2372 memset(probe_ent, 0, sizeof(*probe_ent));
2373 probe_ent->dev = pci_dev_to_dev(pdev); 2327 probe_ent->dev = pci_dev_to_dev(pdev);
2374 INIT_LIST_HEAD(&probe_ent->node); 2328 INIT_LIST_HEAD(&probe_ent->node);
2375 2329
2376 mmio_base = pci_iomap(pdev, MV_PRIMARY_BAR, 0); 2330 hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL);
2377 if (mmio_base == NULL) { 2331 if (!hpriv)
2378 rc = -ENOMEM; 2332 return -ENOMEM;
2379 goto err_out_free_ent;
2380 }
2381
2382 hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL);
2383 if (!hpriv) {
2384 rc = -ENOMEM;
2385 goto err_out_iounmap;
2386 }
2387 memset(hpriv, 0, sizeof(*hpriv));
2388 2333
2389 probe_ent->sht = mv_port_info[board_idx].sht; 2334 probe_ent->sht = mv_port_info[board_idx].sht;
2390 probe_ent->port_flags = mv_port_info[board_idx].flags; 2335 probe_ent->port_flags = mv_port_info[board_idx].flags;
@@ -2394,53 +2339,26 @@ static int mv_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2394 2339
2395 probe_ent->irq = pdev->irq; 2340 probe_ent->irq = pdev->irq;
2396 probe_ent->irq_flags = IRQF_SHARED; 2341 probe_ent->irq_flags = IRQF_SHARED;
2397 probe_ent->mmio_base = mmio_base; 2342 probe_ent->iomap = pcim_iomap_table(pdev);
2398 probe_ent->private_data = hpriv; 2343 probe_ent->private_data = hpriv;
2399 2344
2400 /* initialize adapter */ 2345 /* initialize adapter */
2401 rc = mv_init_host(pdev, probe_ent, board_idx); 2346 rc = mv_init_host(pdev, probe_ent, board_idx);
2402 if (rc) { 2347 if (rc)
2403 goto err_out_hpriv; 2348 return rc;
2404 }
2405 2349
2406 /* Enable interrupts */ 2350 /* Enable interrupts */
2407 if (msi && pci_enable_msi(pdev) == 0) { 2351 if (msi && !pci_enable_msi(pdev))
2408 hpriv->hp_flags |= MV_HP_FLAG_MSI;
2409 } else {
2410 pci_intx(pdev, 1); 2352 pci_intx(pdev, 1);
2411 }
2412 2353
2413 mv_dump_pci_cfg(pdev, 0x68); 2354 mv_dump_pci_cfg(pdev, 0x68);
2414 mv_print_info(probe_ent); 2355 mv_print_info(probe_ent);
2415 2356
2416 if (ata_device_add(probe_ent) == 0) { 2357 if (ata_device_add(probe_ent) == 0)
2417 rc = -ENODEV; /* No devices discovered */ 2358 return -ENODEV;
2418 goto err_out_dev_add;
2419 }
2420 2359
2421 kfree(probe_ent); 2360 devm_kfree(dev, probe_ent);
2422 return 0; 2361 return 0;
2423
2424err_out_dev_add:
2425 if (MV_HP_FLAG_MSI & hpriv->hp_flags) {
2426 pci_disable_msi(pdev);
2427 } else {
2428 pci_intx(pdev, 0);
2429 }
2430err_out_hpriv:
2431 kfree(hpriv);
2432err_out_iounmap:
2433 pci_iounmap(pdev, mmio_base);
2434err_out_free_ent:
2435 kfree(probe_ent);
2436err_out_regions:
2437 pci_release_regions(pdev);
2438err_out:
2439 if (!pci_dev_busy) {
2440 pci_disable_device(pdev);
2441 }
2442
2443 return rc;
2444} 2362}
2445 2363
2446static int __init mv_init(void) 2364static int __init mv_init(void)
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index f7a963eb1f0..095ef1b2cd0 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -49,11 +49,13 @@
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.2" 52#define DRV_VERSION "3.3"
53 53
54#define NV_ADMA_DMA_BOUNDARY 0xffffffffUL 54#define NV_ADMA_DMA_BOUNDARY 0xffffffffUL
55 55
56enum { 56enum {
57 NV_MMIO_BAR = 5,
58
57 NV_PORTS = 2, 59 NV_PORTS = 2,
58 NV_PIO_MASK = 0x1f, 60 NV_PIO_MASK = 0x1f,
59 NV_MWDMA_MASK = 0x07, 61 NV_MWDMA_MASK = 0x07,
@@ -213,12 +215,21 @@ struct nv_adma_port_priv {
213 dma_addr_t cpb_dma; 215 dma_addr_t cpb_dma;
214 struct nv_adma_prd *aprd; 216 struct nv_adma_prd *aprd;
215 dma_addr_t aprd_dma; 217 dma_addr_t aprd_dma;
218 void __iomem * ctl_block;
219 void __iomem * gen_block;
220 void __iomem * notifier_clear_block;
216 u8 flags; 221 u8 flags;
217}; 222};
218 223
224struct nv_host_priv {
225 unsigned long type;
226};
227
219#define NV_ADMA_CHECK_INTR(GCTL, PORT) ((GCTL) & ( 1 << (19 + (12 * (PORT))))) 228#define NV_ADMA_CHECK_INTR(GCTL, PORT) ((GCTL) & ( 1 << (19 + (12 * (PORT)))))
220 229
221static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent); 230static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent);
231static void nv_remove_one (struct pci_dev *pdev);
232static int nv_pci_device_resume(struct pci_dev *pdev);
222static void nv_ck804_host_stop(struct ata_host *host); 233static void nv_ck804_host_stop(struct ata_host *host);
223static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance); 234static irqreturn_t nv_generic_interrupt(int irq, void *dev_instance);
224static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance); 235static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance);
@@ -239,6 +250,8 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance);
239static void nv_adma_irq_clear(struct ata_port *ap); 250static void nv_adma_irq_clear(struct ata_port *ap);
240static int nv_adma_port_start(struct ata_port *ap); 251static int nv_adma_port_start(struct ata_port *ap);
241static void nv_adma_port_stop(struct ata_port *ap); 252static void nv_adma_port_stop(struct ata_port *ap);
253static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg);
254static int nv_adma_port_resume(struct ata_port *ap);
242static void nv_adma_error_handler(struct ata_port *ap); 255static void nv_adma_error_handler(struct ata_port *ap);
243static void nv_adma_host_stop(struct ata_host *host); 256static void nv_adma_host_stop(struct ata_host *host);
244static void nv_adma_bmdma_setup(struct ata_queued_cmd *qc); 257static void nv_adma_bmdma_setup(struct ata_queued_cmd *qc);
@@ -284,7 +297,9 @@ static struct pci_driver nv_pci_driver = {
284 .name = DRV_NAME, 297 .name = DRV_NAME,
285 .id_table = nv_pci_tbl, 298 .id_table = nv_pci_tbl,
286 .probe = nv_init_one, 299 .probe = nv_init_one,
287 .remove = ata_pci_remove_one, 300 .suspend = ata_pci_device_suspend,
301 .resume = nv_pci_device_resume,
302 .remove = nv_remove_one,
288}; 303};
289 304
290static struct scsi_host_template nv_sht = { 305static struct scsi_host_template nv_sht = {
@@ -303,6 +318,8 @@ static struct scsi_host_template nv_sht = {
303 .slave_configure = ata_scsi_slave_config, 318 .slave_configure = ata_scsi_slave_config,
304 .slave_destroy = ata_scsi_slave_destroy, 319 .slave_destroy = ata_scsi_slave_destroy,
305 .bios_param = ata_std_bios_param, 320 .bios_param = ata_std_bios_param,
321 .suspend = ata_scsi_device_suspend,
322 .resume = ata_scsi_device_resume,
306}; 323};
307 324
308static struct scsi_host_template nv_adma_sht = { 325static struct scsi_host_template nv_adma_sht = {
@@ -321,6 +338,8 @@ static struct scsi_host_template nv_adma_sht = {
321 .slave_configure = nv_adma_slave_config, 338 .slave_configure = nv_adma_slave_config,
322 .slave_destroy = ata_scsi_slave_destroy, 339 .slave_destroy = ata_scsi_slave_destroy,
323 .bios_param = ata_std_bios_param, 340 .bios_param = ata_std_bios_param,
341 .suspend = ata_scsi_device_suspend,
342 .resume = ata_scsi_device_resume,
324}; 343};
325 344
326static const struct ata_port_operations nv_generic_ops = { 345static const struct ata_port_operations nv_generic_ops = {
@@ -340,14 +359,14 @@ static const struct ata_port_operations nv_generic_ops = {
340 .thaw = ata_bmdma_thaw, 359 .thaw = ata_bmdma_thaw,
341 .error_handler = nv_error_handler, 360 .error_handler = nv_error_handler,
342 .post_internal_cmd = ata_bmdma_post_internal_cmd, 361 .post_internal_cmd = ata_bmdma_post_internal_cmd,
343 .data_xfer = ata_pio_data_xfer, 362 .data_xfer = ata_data_xfer,
344 .irq_handler = nv_generic_interrupt, 363 .irq_handler = nv_generic_interrupt,
345 .irq_clear = ata_bmdma_irq_clear, 364 .irq_clear = ata_bmdma_irq_clear,
365 .irq_on = ata_irq_on,
366 .irq_ack = ata_irq_ack,
346 .scr_read = nv_scr_read, 367 .scr_read = nv_scr_read,
347 .scr_write = nv_scr_write, 368 .scr_write = nv_scr_write,
348 .port_start = ata_port_start, 369 .port_start = ata_port_start,
349 .port_stop = ata_port_stop,
350 .host_stop = ata_pci_host_stop,
351}; 370};
352 371
353static const struct ata_port_operations nv_nf2_ops = { 372static const struct ata_port_operations nv_nf2_ops = {
@@ -367,14 +386,14 @@ static const struct ata_port_operations nv_nf2_ops = {
367 .thaw = nv_nf2_thaw, 386 .thaw = nv_nf2_thaw,
368 .error_handler = nv_error_handler, 387 .error_handler = nv_error_handler,
369 .post_internal_cmd = ata_bmdma_post_internal_cmd, 388 .post_internal_cmd = ata_bmdma_post_internal_cmd,
370 .data_xfer = ata_pio_data_xfer, 389 .data_xfer = ata_data_xfer,
371 .irq_handler = nv_nf2_interrupt, 390 .irq_handler = nv_nf2_interrupt,
372 .irq_clear = ata_bmdma_irq_clear, 391 .irq_clear = ata_bmdma_irq_clear,
392 .irq_on = ata_irq_on,
393 .irq_ack = ata_irq_ack,
373 .scr_read = nv_scr_read, 394 .scr_read = nv_scr_read,
374 .scr_write = nv_scr_write, 395 .scr_write = nv_scr_write,
375 .port_start = ata_port_start, 396 .port_start = ata_port_start,
376 .port_stop = ata_port_stop,
377 .host_stop = ata_pci_host_stop,
378}; 397};
379 398
380static const struct ata_port_operations nv_ck804_ops = { 399static const struct ata_port_operations nv_ck804_ops = {
@@ -394,13 +413,14 @@ static const struct ata_port_operations nv_ck804_ops = {
394 .thaw = nv_ck804_thaw, 413 .thaw = nv_ck804_thaw,
395 .error_handler = nv_error_handler, 414 .error_handler = nv_error_handler,
396 .post_internal_cmd = ata_bmdma_post_internal_cmd, 415 .post_internal_cmd = ata_bmdma_post_internal_cmd,
397 .data_xfer = ata_pio_data_xfer, 416 .data_xfer = ata_data_xfer,
398 .irq_handler = nv_ck804_interrupt, 417 .irq_handler = nv_ck804_interrupt,
399 .irq_clear = ata_bmdma_irq_clear, 418 .irq_clear = ata_bmdma_irq_clear,
419 .irq_on = ata_irq_on,
420 .irq_ack = ata_irq_ack,
400 .scr_read = nv_scr_read, 421 .scr_read = nv_scr_read,
401 .scr_write = nv_scr_write, 422 .scr_write = nv_scr_write,
402 .port_start = ata_port_start, 423 .port_start = ata_port_start,
403 .port_stop = ata_port_stop,
404 .host_stop = nv_ck804_host_stop, 424 .host_stop = nv_ck804_host_stop,
405}; 425};
406 426
@@ -422,13 +442,17 @@ static const struct ata_port_operations nv_adma_ops = {
422 .thaw = nv_ck804_thaw, 442 .thaw = nv_ck804_thaw,
423 .error_handler = nv_adma_error_handler, 443 .error_handler = nv_adma_error_handler,
424 .post_internal_cmd = nv_adma_bmdma_stop, 444 .post_internal_cmd = nv_adma_bmdma_stop,
425 .data_xfer = ata_mmio_data_xfer, 445 .data_xfer = ata_data_xfer,
426 .irq_handler = nv_adma_interrupt, 446 .irq_handler = nv_adma_interrupt,
427 .irq_clear = nv_adma_irq_clear, 447 .irq_clear = nv_adma_irq_clear,
448 .irq_on = ata_irq_on,
449 .irq_ack = ata_irq_ack,
428 .scr_read = nv_scr_read, 450 .scr_read = nv_scr_read,
429 .scr_write = nv_scr_write, 451 .scr_write = nv_scr_write,
430 .port_start = nv_adma_port_start, 452 .port_start = nv_adma_port_start,
431 .port_stop = nv_adma_port_stop, 453 .port_stop = nv_adma_port_stop,
454 .port_suspend = nv_adma_port_suspend,
455 .port_resume = nv_adma_port_resume,
432 .host_stop = nv_adma_host_stop, 456 .host_stop = nv_adma_host_stop,
433}; 457};
434 458
@@ -467,6 +491,7 @@ static struct ata_port_info nv_port_info[] = {
467 { 491 {
468 .sht = &nv_adma_sht, 492 .sht = &nv_adma_sht,
469 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 493 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
494 ATA_FLAG_HRST_TO_RESUME |
470 ATA_FLAG_MMIO | ATA_FLAG_NCQ, 495 ATA_FLAG_MMIO | ATA_FLAG_NCQ,
471 .pio_mask = NV_PIO_MASK, 496 .pio_mask = NV_PIO_MASK,
472 .mwdma_mask = NV_MWDMA_MASK, 497 .mwdma_mask = NV_MWDMA_MASK,
@@ -483,57 +508,72 @@ MODULE_VERSION(DRV_VERSION);
483 508
484static int adma_enabled = 1; 509static int adma_enabled = 1;
485 510
486static inline void __iomem *__nv_adma_ctl_block(void __iomem *mmio,
487 unsigned int port_no)
488{
489 mmio += NV_ADMA_PORT + port_no * NV_ADMA_PORT_SIZE;
490 return mmio;
491}
492
493static inline void __iomem *nv_adma_ctl_block(struct ata_port *ap)
494{
495 return __nv_adma_ctl_block(ap->host->mmio_base, ap->port_no);
496}
497
498static inline void __iomem *nv_adma_gen_block(struct ata_port *ap)
499{
500 return (ap->host->mmio_base + NV_ADMA_GEN);
501}
502
503static inline void __iomem *nv_adma_notifier_clear_block(struct ata_port *ap)
504{
505 return (nv_adma_gen_block(ap) + NV_ADMA_NOTIFIER_CLEAR + (4 * ap->port_no));
506}
507
508static void nv_adma_register_mode(struct ata_port *ap) 511static void nv_adma_register_mode(struct ata_port *ap)
509{ 512{
510 void __iomem *mmio = nv_adma_ctl_block(ap);
511 struct nv_adma_port_priv *pp = ap->private_data; 513 struct nv_adma_port_priv *pp = ap->private_data;
512 u16 tmp; 514 void __iomem *mmio = pp->ctl_block;
515 u16 tmp, status;
516 int count = 0;
513 517
514 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) 518 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE)
515 return; 519 return;
516 520
521 status = readw(mmio + NV_ADMA_STAT);
522 while(!(status & NV_ADMA_STAT_IDLE) && count < 20) {
523 ndelay(50);
524 status = readw(mmio + NV_ADMA_STAT);
525 count++;
526 }
527 if(count == 20)
528 ata_port_printk(ap, KERN_WARNING,
529 "timeout waiting for ADMA IDLE, stat=0x%hx\n",
530 status);
531
517 tmp = readw(mmio + NV_ADMA_CTL); 532 tmp = readw(mmio + NV_ADMA_CTL);
518 writew(tmp & ~NV_ADMA_CTL_GO, mmio + NV_ADMA_CTL); 533 writew(tmp & ~NV_ADMA_CTL_GO, mmio + NV_ADMA_CTL);
519 534
535 count = 0;
536 status = readw(mmio + NV_ADMA_STAT);
537 while(!(status & NV_ADMA_STAT_LEGACY) && count < 20) {
538 ndelay(50);
539 status = readw(mmio + NV_ADMA_STAT);
540 count++;
541 }
542 if(count == 20)
543 ata_port_printk(ap, KERN_WARNING,
544 "timeout waiting for ADMA LEGACY, stat=0x%hx\n",
545 status);
546
520 pp->flags |= NV_ADMA_PORT_REGISTER_MODE; 547 pp->flags |= NV_ADMA_PORT_REGISTER_MODE;
521} 548}
522 549
523static void nv_adma_mode(struct ata_port *ap) 550static void nv_adma_mode(struct ata_port *ap)
524{ 551{
525 void __iomem *mmio = nv_adma_ctl_block(ap);
526 struct nv_adma_port_priv *pp = ap->private_data; 552 struct nv_adma_port_priv *pp = ap->private_data;
527 u16 tmp; 553 void __iomem *mmio = pp->ctl_block;
554 u16 tmp, status;
555 int count = 0;
528 556
529 if (!(pp->flags & NV_ADMA_PORT_REGISTER_MODE)) 557 if (!(pp->flags & NV_ADMA_PORT_REGISTER_MODE))
530 return; 558 return;
531 559
532 WARN_ON(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE); 560 WARN_ON(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE);
533 561
534 tmp = readw(mmio + NV_ADMA_CTL); 562 tmp = readw(mmio + NV_ADMA_CTL);
535 writew(tmp | NV_ADMA_CTL_GO, mmio + NV_ADMA_CTL); 563 writew(tmp | NV_ADMA_CTL_GO, mmio + NV_ADMA_CTL);
536 564
565 status = readw(mmio + NV_ADMA_STAT);
566 while(((status & NV_ADMA_STAT_LEGACY) ||
567 !(status & NV_ADMA_STAT_IDLE)) && count < 20) {
568 ndelay(50);
569 status = readw(mmio + NV_ADMA_STAT);
570 count++;
571 }
572 if(count == 20)
573 ata_port_printk(ap, KERN_WARNING,
574 "timeout waiting for ADMA LEGACY clear and IDLE, stat=0x%hx\n",
575 status);
576
537 pp->flags &= ~NV_ADMA_PORT_REGISTER_MODE; 577 pp->flags &= ~NV_ADMA_PORT_REGISTER_MODE;
538} 578}
539 579
@@ -568,7 +608,7 @@ static int nv_adma_slave_config(struct scsi_device *sdev)
568 /* Subtract 1 since an extra entry may be needed for padding, see 608 /* Subtract 1 since an extra entry may be needed for padding, see
569 libata-scsi.c */ 609 libata-scsi.c */
570 sg_tablesize = LIBATA_MAX_PRD - 1; 610 sg_tablesize = LIBATA_MAX_PRD - 1;
571 611
572 /* Since the legacy DMA engine is in use, we need to disable ADMA 612 /* Since the legacy DMA engine is in use, we need to disable ADMA
573 on the port. */ 613 on the port. */
574 adma_enable = 0; 614 adma_enable = 0;
@@ -580,7 +620,7 @@ static int nv_adma_slave_config(struct scsi_device *sdev)
580 sg_tablesize = NV_ADMA_SGTBL_TOTAL_LEN; 620 sg_tablesize = NV_ADMA_SGTBL_TOTAL_LEN;
581 adma_enable = 1; 621 adma_enable = 1;
582 } 622 }
583 623
584 pci_read_config_dword(pdev, NV_MCP_SATA_CFG_20, &current_reg); 624 pci_read_config_dword(pdev, NV_MCP_SATA_CFG_20, &current_reg);
585 625
586 if(ap->port_no == 1) 626 if(ap->port_no == 1)
@@ -589,7 +629,7 @@ static int nv_adma_slave_config(struct scsi_device *sdev)
589 else 629 else
590 config_mask = NV_MCP_SATA_CFG_20_PORT0_EN | 630 config_mask = NV_MCP_SATA_CFG_20_PORT0_EN |
591 NV_MCP_SATA_CFG_20_PORT0_PWB_EN; 631 NV_MCP_SATA_CFG_20_PORT0_PWB_EN;
592 632
593 if(adma_enable) { 633 if(adma_enable) {
594 new_reg = current_reg | config_mask; 634 new_reg = current_reg | config_mask;
595 pp->flags &= ~NV_ADMA_ATAPI_SETUP_COMPLETE; 635 pp->flags &= ~NV_ADMA_ATAPI_SETUP_COMPLETE;
@@ -598,10 +638,10 @@ static int nv_adma_slave_config(struct scsi_device *sdev)
598 new_reg = current_reg & ~config_mask; 638 new_reg = current_reg & ~config_mask;
599 pp->flags |= NV_ADMA_ATAPI_SETUP_COMPLETE; 639 pp->flags |= NV_ADMA_ATAPI_SETUP_COMPLETE;
600 } 640 }
601 641
602 if(current_reg != new_reg) 642 if(current_reg != new_reg)
603 pci_write_config_dword(pdev, NV_MCP_SATA_CFG_20, new_reg); 643 pci_write_config_dword(pdev, NV_MCP_SATA_CFG_20, new_reg);
604 644
605 blk_queue_bounce_limit(sdev->request_queue, bounce_limit); 645 blk_queue_bounce_limit(sdev->request_queue, bounce_limit);
606 blk_queue_segment_boundary(sdev->request_queue, segment_boundary); 646 blk_queue_segment_boundary(sdev->request_queue, segment_boundary);
607 blk_queue_max_hw_segments(sdev->request_queue, sg_tablesize); 647 blk_queue_max_hw_segments(sdev->request_queue, sg_tablesize);
@@ -648,53 +688,62 @@ static unsigned int nv_adma_tf_to_cpb(struct ata_taskfile *tf, __le16 *cpb)
648 return idx; 688 return idx;
649} 689}
650 690
651static void nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err) 691static int nv_adma_check_cpb(struct ata_port *ap, int cpb_num, int force_err)
652{ 692{
653 struct nv_adma_port_priv *pp = ap->private_data; 693 struct nv_adma_port_priv *pp = ap->private_data;
654 int complete = 0, have_err = 0;
655 u8 flags = pp->cpb[cpb_num].resp_flags; 694 u8 flags = pp->cpb[cpb_num].resp_flags;
656 695
657 VPRINTK("CPB %d, flags=0x%x\n", cpb_num, flags); 696 VPRINTK("CPB %d, flags=0x%x\n", cpb_num, flags);
658 697
659 if (flags & NV_CPB_RESP_DONE) { 698 if (unlikely((force_err ||
660 VPRINTK("CPB flags done, flags=0x%x\n", flags); 699 flags & (NV_CPB_RESP_ATA_ERR |
661 complete = 1; 700 NV_CPB_RESP_CMD_ERR |
662 } 701 NV_CPB_RESP_CPB_ERR)))) {
663 if (flags & NV_CPB_RESP_ATA_ERR) { 702 struct ata_eh_info *ehi = &ap->eh_info;
664 ata_port_printk(ap, KERN_ERR, "CPB flags ATA err, flags=0x%x\n", flags); 703 int freeze = 0;
665 have_err = 1; 704
666 complete = 1; 705 ata_ehi_clear_desc(ehi);
667 } 706 ata_ehi_push_desc(ehi, "CPB resp_flags 0x%x", flags );
668 if (flags & NV_CPB_RESP_CMD_ERR) { 707 if (flags & NV_CPB_RESP_ATA_ERR) {
669 ata_port_printk(ap, KERN_ERR, "CPB flags CMD err, flags=0x%x\n", flags); 708 ata_ehi_push_desc(ehi, ": ATA error");
670 have_err = 1; 709 ehi->err_mask |= AC_ERR_DEV;
671 complete = 1; 710 } else if (flags & NV_CPB_RESP_CMD_ERR) {
672 } 711 ata_ehi_push_desc(ehi, ": CMD error");
673 if (flags & NV_CPB_RESP_CPB_ERR) { 712 ehi->err_mask |= AC_ERR_DEV;
674 ata_port_printk(ap, KERN_ERR, "CPB flags CPB err, flags=0x%x\n", flags); 713 } else if (flags & NV_CPB_RESP_CPB_ERR) {
675 have_err = 1; 714 ata_ehi_push_desc(ehi, ": CPB error");
676 complete = 1; 715 ehi->err_mask |= AC_ERR_SYSTEM;
716 freeze = 1;
717 } else {
718 /* notifier error, but no error in CPB flags? */
719 ehi->err_mask |= AC_ERR_OTHER;
720 freeze = 1;
721 }
722 /* Kill all commands. EH will determine what actually failed. */
723 if (freeze)
724 ata_port_freeze(ap);
725 else
726 ata_port_abort(ap);
727 return 1;
677 } 728 }
678 if(complete || force_err) 729
679 { 730 if (flags & NV_CPB_RESP_DONE) {
680 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, cpb_num); 731 struct ata_queued_cmd *qc = ata_qc_from_tag(ap, cpb_num);
681 if(likely(qc)) { 732 VPRINTK("CPB flags done, flags=0x%x\n", flags);
682 u8 ata_status = 0; 733 if (likely(qc)) {
683 /* Only use the ATA port status for non-NCQ commands. 734 /* Grab the ATA port status for non-NCQ commands.
684 For NCQ commands the current status may have nothing to do with 735 For NCQ commands the current status may have nothing to do with
685 the command just completed. */ 736 the command just completed. */
686 if(qc->tf.protocol != ATA_PROT_NCQ) 737 if (qc->tf.protocol != ATA_PROT_NCQ) {
687 ata_status = readb(nv_adma_ctl_block(ap) + (ATA_REG_STATUS * 4)); 738 u8 ata_status = readb(pp->ctl_block + (ATA_REG_STATUS * 4));
688 739 qc->err_mask |= ac_err_mask(ata_status);
689 if(have_err || force_err) 740 }
690 ata_status |= ATA_ERR;
691
692 qc->err_mask |= ac_err_mask(ata_status);
693 DPRINTK("Completing qc from tag %d with err_mask %u\n",cpb_num, 741 DPRINTK("Completing qc from tag %d with err_mask %u\n",cpb_num,
694 qc->err_mask); 742 qc->err_mask);
695 ata_qc_complete(qc); 743 ata_qc_complete(qc);
696 } 744 }
697 } 745 }
746 return 0;
698} 747}
699 748
700static int nv_host_intr(struct ata_port *ap, u8 irq_stat) 749static int nv_host_intr(struct ata_port *ap, u8 irq_stat)
@@ -735,15 +784,14 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
735 784
736 if (ap && !(ap->flags & ATA_FLAG_DISABLED)) { 785 if (ap && !(ap->flags & ATA_FLAG_DISABLED)) {
737 struct nv_adma_port_priv *pp = ap->private_data; 786 struct nv_adma_port_priv *pp = ap->private_data;
738 void __iomem *mmio = nv_adma_ctl_block(ap); 787 void __iomem *mmio = pp->ctl_block;
739 u16 status; 788 u16 status;
740 u32 gen_ctl; 789 u32 gen_ctl;
741 int have_global_err = 0;
742 u32 notifier, notifier_error; 790 u32 notifier, notifier_error;
743 791
744 /* if in ATA register mode, use standard ata interrupt handler */ 792 /* if in ATA register mode, use standard ata interrupt handler */
745 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) { 793 if (pp->flags & NV_ADMA_PORT_REGISTER_MODE) {
746 u8 irq_stat = readb(host->mmio_base + NV_INT_STATUS_CK804) 794 u8 irq_stat = readb(host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804)
747 >> (NV_INT_PORT_SHIFT * i); 795 >> (NV_INT_PORT_SHIFT * i);
748 if(ata_tag_valid(ap->active_tag)) 796 if(ata_tag_valid(ap->active_tag))
749 /** NV_INT_DEV indication seems unreliable at times 797 /** NV_INT_DEV indication seems unreliable at times
@@ -758,7 +806,7 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
758 notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR); 806 notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR);
759 notifier_clears[i] = notifier | notifier_error; 807 notifier_clears[i] = notifier | notifier_error;
760 808
761 gen_ctl = readl(nv_adma_gen_block(ap) + NV_ADMA_GEN_CTL); 809 gen_ctl = readl(pp->gen_block + NV_ADMA_GEN_CTL);
762 810
763 if( !NV_ADMA_CHECK_INTR(gen_ctl, ap->port_no) && !notifier && 811 if( !NV_ADMA_CHECK_INTR(gen_ctl, ap->port_no) && !notifier &&
764 !notifier_error) 812 !notifier_error)
@@ -774,52 +822,60 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
774 readw(mmio + NV_ADMA_STAT); /* flush posted write */ 822 readw(mmio + NV_ADMA_STAT); /* flush posted write */
775 rmb(); 823 rmb();
776 824
777 /* freeze if hotplugged */ 825 handled++; /* irq handled if we got here */
778 if (unlikely(status & (NV_ADMA_STAT_HOTPLUG | NV_ADMA_STAT_HOTUNPLUG))) { 826
779 ata_port_printk(ap, KERN_NOTICE, "Hotplug event, freezing\n"); 827 /* freeze if hotplugged or controller error */
828 if (unlikely(status & (NV_ADMA_STAT_HOTPLUG |
829 NV_ADMA_STAT_HOTUNPLUG |
830 NV_ADMA_STAT_TIMEOUT))) {
831 struct ata_eh_info *ehi = &ap->eh_info;
832
833 ata_ehi_clear_desc(ehi);
834 ata_ehi_push_desc(ehi, "ADMA status 0x%08x", status );
835 if (status & NV_ADMA_STAT_TIMEOUT) {
836 ehi->err_mask |= AC_ERR_SYSTEM;
837 ata_ehi_push_desc(ehi, ": timeout");
838 } else if (status & NV_ADMA_STAT_HOTPLUG) {
839 ata_ehi_hotplugged(ehi);
840 ata_ehi_push_desc(ehi, ": hotplug");
841 } else if (status & NV_ADMA_STAT_HOTUNPLUG) {
842 ata_ehi_hotplugged(ehi);
843 ata_ehi_push_desc(ehi, ": hot unplug");
844 }
780 ata_port_freeze(ap); 845 ata_port_freeze(ap);
781 handled++;
782 continue; 846 continue;
783 } 847 }
784 848
785 if (status & NV_ADMA_STAT_TIMEOUT) { 849 if (status & (NV_ADMA_STAT_DONE |
786 ata_port_printk(ap, KERN_ERR, "timeout, stat=0x%x\n", status); 850 NV_ADMA_STAT_CPBERR)) {
787 have_global_err = 1;
788 }
789 if (status & NV_ADMA_STAT_CPBERR) {
790 ata_port_printk(ap, KERN_ERR, "CPB error, stat=0x%x\n", status);
791 have_global_err = 1;
792 }
793 if ((status & NV_ADMA_STAT_DONE) || have_global_err) {
794 /** Check CPBs for completed commands */ 851 /** Check CPBs for completed commands */
795 852
796 if(ata_tag_valid(ap->active_tag)) 853 if (ata_tag_valid(ap->active_tag)) {
797 /* Non-NCQ command */ 854 /* Non-NCQ command */
798 nv_adma_check_cpb(ap, ap->active_tag, have_global_err || 855 nv_adma_check_cpb(ap, ap->active_tag,
799 (notifier_error & (1 << ap->active_tag))); 856 notifier_error & (1 << ap->active_tag));
800 else { 857 } else {
801 int pos; 858 int pos, error = 0;
802 u32 active = ap->sactive; 859 u32 active = ap->sactive;
803 while( (pos = ffs(active)) ) { 860
861 while ((pos = ffs(active)) && !error) {
804 pos--; 862 pos--;
805 nv_adma_check_cpb(ap, pos, have_global_err || 863 error = nv_adma_check_cpb(ap, pos,
806 (notifier_error & (1 << pos)) ); 864 notifier_error & (1 << pos) );
807 active &= ~(1 << pos ); 865 active &= ~(1 << pos );
808 } 866 }
809 } 867 }
810 } 868 }
811
812 handled++; /* irq handled if we got here */
813 } 869 }
814 } 870 }
815 871
816 if(notifier_clears[0] || notifier_clears[1]) { 872 if(notifier_clears[0] || notifier_clears[1]) {
817 /* Note: Both notifier clear registers must be written 873 /* Note: Both notifier clear registers must be written
818 if either is set, even if one is zero, according to NVIDIA. */ 874 if either is set, even if one is zero, according to NVIDIA. */
819 writel(notifier_clears[0], 875 struct nv_adma_port_priv *pp = host->ports[0]->private_data;
820 nv_adma_notifier_clear_block(host->ports[0])); 876 writel(notifier_clears[0], pp->notifier_clear_block);
821 writel(notifier_clears[1], 877 pp = host->ports[1]->private_data;
822 nv_adma_notifier_clear_block(host->ports[1])); 878 writel(notifier_clears[1], pp->notifier_clear_block);
823 } 879 }
824 880
825 spin_unlock(&host->lock); 881 spin_unlock(&host->lock);
@@ -829,19 +885,20 @@ static irqreturn_t nv_adma_interrupt(int irq, void *dev_instance)
829 885
830static void nv_adma_irq_clear(struct ata_port *ap) 886static void nv_adma_irq_clear(struct ata_port *ap)
831{ 887{
832 void __iomem *mmio = nv_adma_ctl_block(ap); 888 struct nv_adma_port_priv *pp = ap->private_data;
889 void __iomem *mmio = pp->ctl_block;
833 u16 status = readw(mmio + NV_ADMA_STAT); 890 u16 status = readw(mmio + NV_ADMA_STAT);
834 u32 notifier = readl(mmio + NV_ADMA_NOTIFIER); 891 u32 notifier = readl(mmio + NV_ADMA_NOTIFIER);
835 u32 notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR); 892 u32 notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR);
836 unsigned long dma_stat_addr = ap->ioaddr.bmdma_addr + ATA_DMA_STATUS; 893 void __iomem *dma_stat_addr = ap->ioaddr.bmdma_addr + ATA_DMA_STATUS;
837 894
838 /* clear ADMA status */ 895 /* clear ADMA status */
839 writew(status, mmio + NV_ADMA_STAT); 896 writew(status, mmio + NV_ADMA_STAT);
840 writel(notifier | notifier_error, 897 writel(notifier | notifier_error,
841 nv_adma_notifier_clear_block(ap)); 898 pp->notifier_clear_block);
842 899
843 /** clear legacy status */ 900 /** clear legacy status */
844 outb(inb(dma_stat_addr), dma_stat_addr); 901 iowrite8(ioread8(dma_stat_addr), dma_stat_addr);
845} 902}
846 903
847static void nv_adma_bmdma_setup(struct ata_queued_cmd *qc) 904static void nv_adma_bmdma_setup(struct ata_queued_cmd *qc)
@@ -857,15 +914,15 @@ static void nv_adma_bmdma_setup(struct ata_queued_cmd *qc)
857 } 914 }
858 915
859 /* load PRD table addr. */ 916 /* load PRD table addr. */
860 outl(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS); 917 iowrite32(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);
861 918
862 /* specify data direction, triple-check start bit is clear */ 919 /* specify data direction, triple-check start bit is clear */
863 dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 920 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
864 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START); 921 dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);
865 if (!rw) 922 if (!rw)
866 dmactl |= ATA_DMA_WR; 923 dmactl |= ATA_DMA_WR;
867 924
868 outb(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 925 iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
869 926
870 /* issue r/w command */ 927 /* issue r/w command */
871 ata_exec_command(ap, &qc->tf); 928 ata_exec_command(ap, &qc->tf);
@@ -883,9 +940,9 @@ static void nv_adma_bmdma_start(struct ata_queued_cmd *qc)
883 } 940 }
884 941
885 /* start host DMA transaction */ 942 /* start host DMA transaction */
886 dmactl = inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 943 dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
887 outb(dmactl | ATA_DMA_START, 944 iowrite8(dmactl | ATA_DMA_START,
888 ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 945 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
889} 946}
890 947
891static void nv_adma_bmdma_stop(struct ata_queued_cmd *qc) 948static void nv_adma_bmdma_stop(struct ata_queued_cmd *qc)
@@ -897,8 +954,8 @@ static void nv_adma_bmdma_stop(struct ata_queued_cmd *qc)
897 return; 954 return;
898 955
899 /* clear start/stop bit */ 956 /* clear start/stop bit */
900 outb(inb(ap->ioaddr.bmdma_addr + ATA_DMA_CMD) & ~ATA_DMA_START, 957 iowrite8(ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD) & ~ATA_DMA_START,
901 ap->ioaddr.bmdma_addr + ATA_DMA_CMD); 958 ap->ioaddr.bmdma_addr + ATA_DMA_CMD);
902 959
903 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */ 960 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
904 ata_altstatus(ap); /* dummy read */ 961 ata_altstatus(ap); /* dummy read */
@@ -910,7 +967,7 @@ static u8 nv_adma_bmdma_status(struct ata_port *ap)
910 967
911 WARN_ON(!(pp->flags & NV_ADMA_PORT_REGISTER_MODE)); 968 WARN_ON(!(pp->flags & NV_ADMA_PORT_REGISTER_MODE));
912 969
913 return inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS); 970 return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
914} 971}
915 972
916static int nv_adma_port_start(struct ata_port *ap) 973static int nv_adma_port_start(struct ata_port *ap)
@@ -920,7 +977,7 @@ static int nv_adma_port_start(struct ata_port *ap)
920 int rc; 977 int rc;
921 void *mem; 978 void *mem;
922 dma_addr_t mem_dma; 979 dma_addr_t mem_dma;
923 void __iomem *mmio = nv_adma_ctl_block(ap); 980 void __iomem *mmio;
924 u16 tmp; 981 u16 tmp;
925 982
926 VPRINTK("ENTER\n"); 983 VPRINTK("ENTER\n");
@@ -929,19 +986,21 @@ static int nv_adma_port_start(struct ata_port *ap)
929 if (rc) 986 if (rc)
930 return rc; 987 return rc;
931 988
932 pp = kzalloc(sizeof(*pp), GFP_KERNEL); 989 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
933 if (!pp) { 990 if (!pp)
934 rc = -ENOMEM; 991 return -ENOMEM;
935 goto err_out; 992
936 } 993 mmio = ap->host->iomap[NV_MMIO_BAR] + NV_ADMA_PORT +
937 994 ap->port_no * NV_ADMA_PORT_SIZE;
938 mem = dma_alloc_coherent(dev, NV_ADMA_PORT_PRIV_DMA_SZ, 995 pp->ctl_block = mmio;
939 &mem_dma, GFP_KERNEL); 996 pp->gen_block = ap->host->iomap[NV_MMIO_BAR] + NV_ADMA_GEN;
940 997 pp->notifier_clear_block = pp->gen_block +
941 if (!mem) { 998 NV_ADMA_NOTIFIER_CLEAR + (4 * ap->port_no);
942 rc = -ENOMEM; 999
943 goto err_out_kfree; 1000 mem = dmam_alloc_coherent(dev, NV_ADMA_PORT_PRIV_DMA_SZ,
944 } 1001 &mem_dma, GFP_KERNEL);
1002 if (!mem)
1003 return -ENOMEM;
945 memset(mem, 0, NV_ADMA_PORT_PRIV_DMA_SZ); 1004 memset(mem, 0, NV_ADMA_PORT_PRIV_DMA_SZ);
946 1005
947 /* 1006 /*
@@ -975,9 +1034,9 @@ static int nv_adma_port_start(struct ata_port *ap)
975 /* clear CPB fetch count */ 1034 /* clear CPB fetch count */
976 writew(0, mmio + NV_ADMA_CPB_COUNT); 1035 writew(0, mmio + NV_ADMA_CPB_COUNT);
977 1036
978 /* clear GO for register mode */ 1037 /* clear GO for register mode, enable interrupt */
979 tmp = readw(mmio + NV_ADMA_CTL); 1038 tmp = readw(mmio + NV_ADMA_CTL);
980 writew(tmp & ~NV_ADMA_CTL_GO, mmio + NV_ADMA_CTL); 1039 writew( (tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN, mmio + NV_ADMA_CTL);
981 1040
982 tmp = readw(mmio + NV_ADMA_CTL); 1041 tmp = readw(mmio + NV_ADMA_CTL);
983 writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL); 1042 writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
@@ -987,53 +1046,89 @@ static int nv_adma_port_start(struct ata_port *ap)
987 readl( mmio + NV_ADMA_CTL ); /* flush posted write */ 1046 readl( mmio + NV_ADMA_CTL ); /* flush posted write */
988 1047
989 return 0; 1048 return 0;
990
991err_out_kfree:
992 kfree(pp);
993err_out:
994 ata_port_stop(ap);
995 return rc;
996} 1049}
997 1050
998static void nv_adma_port_stop(struct ata_port *ap) 1051static void nv_adma_port_stop(struct ata_port *ap)
999{ 1052{
1000 struct device *dev = ap->host->dev;
1001 struct nv_adma_port_priv *pp = ap->private_data; 1053 struct nv_adma_port_priv *pp = ap->private_data;
1002 void __iomem *mmio = nv_adma_ctl_block(ap); 1054 void __iomem *mmio = pp->ctl_block;
1003 1055
1004 VPRINTK("ENTER\n"); 1056 VPRINTK("ENTER\n");
1057 writew(0, mmio + NV_ADMA_CTL);
1058}
1059
1060static int nv_adma_port_suspend(struct ata_port *ap, pm_message_t mesg)
1061{
1062 struct nv_adma_port_priv *pp = ap->private_data;
1063 void __iomem *mmio = pp->ctl_block;
1005 1064
1065 /* Go to register mode - clears GO */
1066 nv_adma_register_mode(ap);
1067
1068 /* clear CPB fetch count */
1069 writew(0, mmio + NV_ADMA_CPB_COUNT);
1070
1071 /* disable interrupt, shut down port */
1006 writew(0, mmio + NV_ADMA_CTL); 1072 writew(0, mmio + NV_ADMA_CTL);
1007 1073
1008 ap->private_data = NULL; 1074 return 0;
1009 dma_free_coherent(dev, NV_ADMA_PORT_PRIV_DMA_SZ, pp->cpb, pp->cpb_dma);
1010 kfree(pp);
1011 ata_port_stop(ap);
1012} 1075}
1013 1076
1077static int nv_adma_port_resume(struct ata_port *ap)
1078{
1079 struct nv_adma_port_priv *pp = ap->private_data;
1080 void __iomem *mmio = pp->ctl_block;
1081 u16 tmp;
1082
1083 /* set CPB block location */
1084 writel(pp->cpb_dma & 0xFFFFFFFF, mmio + NV_ADMA_CPB_BASE_LOW);
1085 writel((pp->cpb_dma >> 16 ) >> 16, mmio + NV_ADMA_CPB_BASE_HIGH);
1086
1087 /* clear any outstanding interrupt conditions */
1088 writew(0xffff, mmio + NV_ADMA_STAT);
1089
1090 /* initialize port variables */
1091 pp->flags |= NV_ADMA_PORT_REGISTER_MODE;
1092
1093 /* clear CPB fetch count */
1094 writew(0, mmio + NV_ADMA_CPB_COUNT);
1095
1096 /* clear GO for register mode, enable interrupt */
1097 tmp = readw(mmio + NV_ADMA_CTL);
1098 writew((tmp & ~NV_ADMA_CTL_GO) | NV_ADMA_CTL_AIEN, mmio + NV_ADMA_CTL);
1099
1100 tmp = readw(mmio + NV_ADMA_CTL);
1101 writew(tmp | NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
1102 readl( mmio + NV_ADMA_CTL ); /* flush posted write */
1103 udelay(1);
1104 writew(tmp & ~NV_ADMA_CTL_CHANNEL_RESET, mmio + NV_ADMA_CTL);
1105 readl( mmio + NV_ADMA_CTL ); /* flush posted write */
1106
1107 return 0;
1108}
1014 1109
1015static void nv_adma_setup_port(struct ata_probe_ent *probe_ent, unsigned int port) 1110static void nv_adma_setup_port(struct ata_probe_ent *probe_ent, unsigned int port)
1016{ 1111{
1017 void __iomem *mmio = probe_ent->mmio_base; 1112 void __iomem *mmio = probe_ent->iomap[NV_MMIO_BAR];
1018 struct ata_ioports *ioport = &probe_ent->port[port]; 1113 struct ata_ioports *ioport = &probe_ent->port[port];
1019 1114
1020 VPRINTK("ENTER\n"); 1115 VPRINTK("ENTER\n");
1021 1116
1022 mmio += NV_ADMA_PORT + port * NV_ADMA_PORT_SIZE; 1117 mmio += NV_ADMA_PORT + port * NV_ADMA_PORT_SIZE;
1023 1118
1024 ioport->cmd_addr = (unsigned long) mmio; 1119 ioport->cmd_addr = mmio;
1025 ioport->data_addr = (unsigned long) mmio + (ATA_REG_DATA * 4); 1120 ioport->data_addr = mmio + (ATA_REG_DATA * 4);
1026 ioport->error_addr = 1121 ioport->error_addr =
1027 ioport->feature_addr = (unsigned long) mmio + (ATA_REG_ERR * 4); 1122 ioport->feature_addr = mmio + (ATA_REG_ERR * 4);
1028 ioport->nsect_addr = (unsigned long) mmio + (ATA_REG_NSECT * 4); 1123 ioport->nsect_addr = mmio + (ATA_REG_NSECT * 4);
1029 ioport->lbal_addr = (unsigned long) mmio + (ATA_REG_LBAL * 4); 1124 ioport->lbal_addr = mmio + (ATA_REG_LBAL * 4);
1030 ioport->lbam_addr = (unsigned long) mmio + (ATA_REG_LBAM * 4); 1125 ioport->lbam_addr = mmio + (ATA_REG_LBAM * 4);
1031 ioport->lbah_addr = (unsigned long) mmio + (ATA_REG_LBAH * 4); 1126 ioport->lbah_addr = mmio + (ATA_REG_LBAH * 4);
1032 ioport->device_addr = (unsigned long) mmio + (ATA_REG_DEVICE * 4); 1127 ioport->device_addr = mmio + (ATA_REG_DEVICE * 4);
1033 ioport->status_addr = 1128 ioport->status_addr =
1034 ioport->command_addr = (unsigned long) mmio + (ATA_REG_STATUS * 4); 1129 ioport->command_addr = mmio + (ATA_REG_STATUS * 4);
1035 ioport->altstatus_addr = 1130 ioport->altstatus_addr =
1036 ioport->ctl_addr = (unsigned long) mmio + 0x20; 1131 ioport->ctl_addr = mmio + 0x20;
1037} 1132}
1038 1133
1039static int nv_adma_host_init(struct ata_probe_ent *probe_ent) 1134static int nv_adma_host_init(struct ata_probe_ent *probe_ent)
@@ -1056,15 +1151,6 @@ static int nv_adma_host_init(struct ata_probe_ent *probe_ent)
1056 for (i = 0; i < probe_ent->n_ports; i++) 1151 for (i = 0; i < probe_ent->n_ports; i++)
1057 nv_adma_setup_port(probe_ent, i); 1152 nv_adma_setup_port(probe_ent, i);
1058 1153
1059 for (i = 0; i < probe_ent->n_ports; i++) {
1060 void __iomem *mmio = __nv_adma_ctl_block(probe_ent->mmio_base, i);
1061 u16 tmp;
1062
1063 /* enable interrupt, clear reset if not already clear */
1064 tmp = readw(mmio + NV_ADMA_CTL);
1065 writew(tmp | NV_ADMA_CTL_AIEN, mmio + NV_ADMA_CTL);
1066 }
1067
1068 return 0; 1154 return 0;
1069} 1155}
1070 1156
@@ -1110,18 +1196,31 @@ static void nv_adma_fill_sg(struct ata_queued_cmd *qc, struct nv_adma_cpb *cpb)
1110 cpb->next_aprd = cpu_to_le64(((u64)(pp->aprd_dma + NV_ADMA_SGTBL_SZ * qc->tag))); 1196 cpb->next_aprd = cpu_to_le64(((u64)(pp->aprd_dma + NV_ADMA_SGTBL_SZ * qc->tag)));
1111} 1197}
1112 1198
1199static int nv_adma_use_reg_mode(struct ata_queued_cmd *qc)
1200{
1201 struct nv_adma_port_priv *pp = qc->ap->private_data;
1202
1203 /* ADMA engine can only be used for non-ATAPI DMA commands,
1204 or interrupt-driven no-data commands. */
1205 if((pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE) ||
1206 (qc->tf.flags & ATA_TFLAG_POLLING))
1207 return 1;
1208
1209 if((qc->flags & ATA_QCFLAG_DMAMAP) ||
1210 (qc->tf.protocol == ATA_PROT_NODATA))
1211 return 0;
1212
1213 return 1;
1214}
1215
1113static void nv_adma_qc_prep(struct ata_queued_cmd *qc) 1216static void nv_adma_qc_prep(struct ata_queued_cmd *qc)
1114{ 1217{
1115 struct nv_adma_port_priv *pp = qc->ap->private_data; 1218 struct nv_adma_port_priv *pp = qc->ap->private_data;
1116 struct nv_adma_cpb *cpb = &pp->cpb[qc->tag]; 1219 struct nv_adma_cpb *cpb = &pp->cpb[qc->tag];
1117 u8 ctl_flags = NV_CPB_CTL_CPB_VALID | 1220 u8 ctl_flags = NV_CPB_CTL_CPB_VALID |
1118 NV_CPB_CTL_APRD_VALID |
1119 NV_CPB_CTL_IEN; 1221 NV_CPB_CTL_IEN;
1120 1222
1121 VPRINTK("qc->flags = 0x%lx\n", qc->flags); 1223 if (nv_adma_use_reg_mode(qc)) {
1122
1123 if (!(qc->flags & ATA_QCFLAG_DMAMAP) ||
1124 (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE)) {
1125 nv_adma_register_mode(qc->ap); 1224 nv_adma_register_mode(qc->ap);
1126 ata_qc_prep(qc); 1225 ata_qc_prep(qc);
1127 return; 1226 return;
@@ -1137,9 +1236,15 @@ static void nv_adma_qc_prep(struct ata_queued_cmd *qc)
1137 if (qc->tf.protocol == ATA_PROT_NCQ) 1236 if (qc->tf.protocol == ATA_PROT_NCQ)
1138 ctl_flags |= NV_CPB_CTL_QUEUE | NV_CPB_CTL_FPDMA; 1237 ctl_flags |= NV_CPB_CTL_QUEUE | NV_CPB_CTL_FPDMA;
1139 1238
1239 VPRINTK("qc->flags = 0x%lx\n", qc->flags);
1240
1140 nv_adma_tf_to_cpb(&qc->tf, cpb->tf); 1241 nv_adma_tf_to_cpb(&qc->tf, cpb->tf);
1141 1242
1142 nv_adma_fill_sg(qc, cpb); 1243 if(qc->flags & ATA_QCFLAG_DMAMAP) {
1244 nv_adma_fill_sg(qc, cpb);
1245 ctl_flags |= NV_CPB_CTL_APRD_VALID;
1246 } else
1247 memset(&cpb->aprd[0], 0, sizeof(struct nv_adma_prd) * 5);
1143 1248
1144 /* Be paranoid and don't let the device see NV_CPB_CTL_CPB_VALID until we are 1249 /* Be paranoid and don't let the device see NV_CPB_CTL_CPB_VALID until we are
1145 finished filling in all of the contents */ 1250 finished filling in all of the contents */
@@ -1150,14 +1255,13 @@ static void nv_adma_qc_prep(struct ata_queued_cmd *qc)
1150static unsigned int nv_adma_qc_issue(struct ata_queued_cmd *qc) 1255static unsigned int nv_adma_qc_issue(struct ata_queued_cmd *qc)
1151{ 1256{
1152 struct nv_adma_port_priv *pp = qc->ap->private_data; 1257 struct nv_adma_port_priv *pp = qc->ap->private_data;
1153 void __iomem *mmio = nv_adma_ctl_block(qc->ap); 1258 void __iomem *mmio = pp->ctl_block;
1154 1259
1155 VPRINTK("ENTER\n"); 1260 VPRINTK("ENTER\n");
1156 1261
1157 if (!(qc->flags & ATA_QCFLAG_DMAMAP) || 1262 if (nv_adma_use_reg_mode(qc)) {
1158 (pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE)) {
1159 /* use ATA register mode */ 1263 /* use ATA register mode */
1160 VPRINTK("no dmamap or ATAPI, using ATA register mode: 0x%lx\n", qc->flags); 1264 VPRINTK("using ATA register mode: 0x%lx\n", qc->flags);
1161 nv_adma_register_mode(qc->ap); 1265 nv_adma_register_mode(qc->ap);
1162 return ata_qc_issue_prot(qc); 1266 return ata_qc_issue_prot(qc);
1163 } else 1267 } else
@@ -1229,7 +1333,7 @@ static irqreturn_t nv_nf2_interrupt(int irq, void *dev_instance)
1229 irqreturn_t ret; 1333 irqreturn_t ret;
1230 1334
1231 spin_lock(&host->lock); 1335 spin_lock(&host->lock);
1232 irq_stat = inb(host->ports[0]->ioaddr.scr_addr + NV_INT_STATUS); 1336 irq_stat = ioread8(host->ports[0]->ioaddr.scr_addr + NV_INT_STATUS);
1233 ret = nv_do_interrupt(host, irq_stat); 1337 ret = nv_do_interrupt(host, irq_stat);
1234 spin_unlock(&host->lock); 1338 spin_unlock(&host->lock);
1235 1339
@@ -1243,7 +1347,7 @@ static irqreturn_t nv_ck804_interrupt(int irq, void *dev_instance)
1243 irqreturn_t ret; 1347 irqreturn_t ret;
1244 1348
1245 spin_lock(&host->lock); 1349 spin_lock(&host->lock);
1246 irq_stat = readb(host->mmio_base + NV_INT_STATUS_CK804); 1350 irq_stat = readb(host->iomap[NV_MMIO_BAR] + NV_INT_STATUS_CK804);
1247 ret = nv_do_interrupt(host, irq_stat); 1351 ret = nv_do_interrupt(host, irq_stat);
1248 spin_unlock(&host->lock); 1352 spin_unlock(&host->lock);
1249 1353
@@ -1255,7 +1359,7 @@ static u32 nv_scr_read (struct ata_port *ap, unsigned int sc_reg)
1255 if (sc_reg > SCR_CONTROL) 1359 if (sc_reg > SCR_CONTROL)
1256 return 0xffffffffU; 1360 return 0xffffffffU;
1257 1361
1258 return ioread32((void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4)); 1362 return ioread32(ap->ioaddr.scr_addr + (sc_reg * 4));
1259} 1363}
1260 1364
1261static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 1365static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
@@ -1263,36 +1367,36 @@ static void nv_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
1263 if (sc_reg > SCR_CONTROL) 1367 if (sc_reg > SCR_CONTROL)
1264 return; 1368 return;
1265 1369
1266 iowrite32(val, (void __iomem *)ap->ioaddr.scr_addr + (sc_reg * 4)); 1370 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4));
1267} 1371}
1268 1372
1269static void nv_nf2_freeze(struct ata_port *ap) 1373static void nv_nf2_freeze(struct ata_port *ap)
1270{ 1374{
1271 unsigned long scr_addr = ap->host->ports[0]->ioaddr.scr_addr; 1375 void __iomem *scr_addr = ap->host->ports[0]->ioaddr.scr_addr;
1272 int shift = ap->port_no * NV_INT_PORT_SHIFT; 1376 int shift = ap->port_no * NV_INT_PORT_SHIFT;
1273 u8 mask; 1377 u8 mask;
1274 1378
1275 mask = inb(scr_addr + NV_INT_ENABLE); 1379 mask = ioread8(scr_addr + NV_INT_ENABLE);
1276 mask &= ~(NV_INT_ALL << shift); 1380 mask &= ~(NV_INT_ALL << shift);
1277 outb(mask, scr_addr + NV_INT_ENABLE); 1381 iowrite8(mask, scr_addr + NV_INT_ENABLE);
1278} 1382}
1279 1383
1280static void nv_nf2_thaw(struct ata_port *ap) 1384static void nv_nf2_thaw(struct ata_port *ap)
1281{ 1385{
1282 unsigned long scr_addr = ap->host->ports[0]->ioaddr.scr_addr; 1386 void __iomem *scr_addr = ap->host->ports[0]->ioaddr.scr_addr;
1283 int shift = ap->port_no * NV_INT_PORT_SHIFT; 1387 int shift = ap->port_no * NV_INT_PORT_SHIFT;
1284 u8 mask; 1388 u8 mask;
1285 1389
1286 outb(NV_INT_ALL << shift, scr_addr + NV_INT_STATUS); 1390 iowrite8(NV_INT_ALL << shift, scr_addr + NV_INT_STATUS);
1287 1391
1288 mask = inb(scr_addr + NV_INT_ENABLE); 1392 mask = ioread8(scr_addr + NV_INT_ENABLE);
1289 mask |= (NV_INT_MASK << shift); 1393 mask |= (NV_INT_MASK << shift);
1290 outb(mask, scr_addr + NV_INT_ENABLE); 1394 iowrite8(mask, scr_addr + NV_INT_ENABLE);
1291} 1395}
1292 1396
1293static void nv_ck804_freeze(struct ata_port *ap) 1397static void nv_ck804_freeze(struct ata_port *ap)
1294{ 1398{
1295 void __iomem *mmio_base = ap->host->mmio_base; 1399 void __iomem *mmio_base = ap->host->iomap[NV_MMIO_BAR];
1296 int shift = ap->port_no * NV_INT_PORT_SHIFT; 1400 int shift = ap->port_no * NV_INT_PORT_SHIFT;
1297 u8 mask; 1401 u8 mask;
1298 1402
@@ -1303,7 +1407,7 @@ static void nv_ck804_freeze(struct ata_port *ap)
1303 1407
1304static void nv_ck804_thaw(struct ata_port *ap) 1408static void nv_ck804_thaw(struct ata_port *ap)
1305{ 1409{
1306 void __iomem *mmio_base = ap->host->mmio_base; 1410 void __iomem *mmio_base = ap->host->iomap[NV_MMIO_BAR];
1307 int shift = ap->port_no * NV_INT_PORT_SHIFT; 1411 int shift = ap->port_no * NV_INT_PORT_SHIFT;
1308 u8 mask; 1412 u8 mask;
1309 1413
@@ -1335,32 +1439,13 @@ static void nv_adma_error_handler(struct ata_port *ap)
1335{ 1439{
1336 struct nv_adma_port_priv *pp = ap->private_data; 1440 struct nv_adma_port_priv *pp = ap->private_data;
1337 if(!(pp->flags & NV_ADMA_PORT_REGISTER_MODE)) { 1441 if(!(pp->flags & NV_ADMA_PORT_REGISTER_MODE)) {
1338 void __iomem *mmio = nv_adma_ctl_block(ap); 1442 void __iomem *mmio = pp->ctl_block;
1339 int i; 1443 int i;
1340 u16 tmp; 1444 u16 tmp;
1341 1445
1342 u32 notifier = readl(mmio + NV_ADMA_NOTIFIER);
1343 u32 notifier_error = readl(mmio + NV_ADMA_NOTIFIER_ERROR);
1344 u32 gen_ctl = readl(nv_adma_gen_block(ap) + NV_ADMA_GEN_CTL);
1345 u32 status = readw(mmio + NV_ADMA_STAT);
1346
1347 ata_port_printk(ap, KERN_ERR, "EH in ADMA mode, notifier 0x%X "
1348 "notifier_error 0x%X gen_ctl 0x%X status 0x%X\n",
1349 notifier, notifier_error, gen_ctl, status);
1350
1351 for( i=0;i<NV_ADMA_MAX_CPBS;i++) {
1352 struct nv_adma_cpb *cpb = &pp->cpb[i];
1353 if( cpb->ctl_flags || cpb->resp_flags )
1354 ata_port_printk(ap, KERN_ERR,
1355 "CPB %d: ctl_flags 0x%x, resp_flags 0x%x\n",
1356 i, cpb->ctl_flags, cpb->resp_flags);
1357 }
1358
1359 /* Push us back into port register mode for error handling. */ 1446 /* Push us back into port register mode for error handling. */
1360 nv_adma_register_mode(ap); 1447 nv_adma_register_mode(ap);
1361 1448
1362 ata_port_printk(ap, KERN_ERR, "Resetting port\n");
1363
1364 /* Mark all of the CPBs as invalid to prevent them from being executed */ 1449 /* Mark all of the CPBs as invalid to prevent them from being executed */
1365 for( i=0;i<NV_ADMA_MAX_CPBS;i++) 1450 for( i=0;i<NV_ADMA_MAX_CPBS;i++)
1366 pp->cpb[i].ctl_flags &= ~NV_CPB_CTL_CPB_VALID; 1451 pp->cpb[i].ctl_flags &= ~NV_CPB_CTL_CPB_VALID;
@@ -1386,10 +1471,10 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1386 static int printed_version = 0; 1471 static int printed_version = 0;
1387 struct ata_port_info *ppi[2]; 1472 struct ata_port_info *ppi[2];
1388 struct ata_probe_ent *probe_ent; 1473 struct ata_probe_ent *probe_ent;
1389 int pci_dev_busy = 0; 1474 struct nv_host_priv *hpriv;
1390 int rc; 1475 int rc;
1391 u32 bar; 1476 u32 bar;
1392 unsigned long base; 1477 void __iomem *base;
1393 unsigned long type = ent->driver_data; 1478 unsigned long type = ent->driver_data;
1394 int mask_set = 0; 1479 int mask_set = 0;
1395 1480
@@ -1400,17 +1485,17 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1400 if (pci_resource_start(pdev, bar) == 0) 1485 if (pci_resource_start(pdev, bar) == 0)
1401 return -ENODEV; 1486 return -ENODEV;
1402 1487
1403 if ( !printed_version++) 1488 if (!printed_version++)
1404 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1489 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1405 1490
1406 rc = pci_enable_device(pdev); 1491 rc = pcim_enable_device(pdev);
1407 if (rc) 1492 if (rc)
1408 goto err_out; 1493 return rc;
1409 1494
1410 rc = pci_request_regions(pdev, DRV_NAME); 1495 rc = pci_request_regions(pdev, DRV_NAME);
1411 if (rc) { 1496 if (rc) {
1412 pci_dev_busy = 1; 1497 pcim_pin_device(pdev);
1413 goto err_out_disable; 1498 return rc;
1414 } 1499 }
1415 1500
1416 if(type >= CK804 && adma_enabled) { 1501 if(type >= CK804 && adma_enabled) {
@@ -1424,27 +1509,31 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1424 if(!mask_set) { 1509 if(!mask_set) {
1425 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 1510 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
1426 if (rc) 1511 if (rc)
1427 goto err_out_regions; 1512 return rc;
1428 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 1513 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
1429 if (rc) 1514 if (rc)
1430 goto err_out_regions; 1515 return rc;
1431 } 1516 }
1432 1517
1433 rc = -ENOMEM; 1518 rc = -ENOMEM;
1434 1519
1520 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
1521 if (!hpriv)
1522 return -ENOMEM;
1523
1435 ppi[0] = ppi[1] = &nv_port_info[type]; 1524 ppi[0] = ppi[1] = &nv_port_info[type];
1436 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 1525 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
1437 if (!probe_ent) 1526 if (!probe_ent)
1438 goto err_out_regions; 1527 return -ENOMEM;
1439 1528
1440 probe_ent->mmio_base = pci_iomap(pdev, 5, 0); 1529 if (!pcim_iomap(pdev, NV_MMIO_BAR, 0))
1441 if (!probe_ent->mmio_base) { 1530 return -EIO;
1442 rc = -EIO; 1531 probe_ent->iomap = pcim_iomap_table(pdev);
1443 goto err_out_free_ent;
1444 }
1445 1532
1446 base = (unsigned long)probe_ent->mmio_base; 1533 probe_ent->private_data = hpriv;
1534 hpriv->type = type;
1447 1535
1536 base = probe_ent->iomap[NV_MMIO_BAR];
1448 probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET; 1537 probe_ent->port[0].scr_addr = base + NV_PORT0_SCR_REG_OFFSET;
1449 probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET; 1538 probe_ent->port[1].scr_addr = base + NV_PORT1_SCR_REG_OFFSET;
1450 1539
@@ -1462,28 +1551,72 @@ static int nv_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1462 if (type == ADMA) { 1551 if (type == ADMA) {
1463 rc = nv_adma_host_init(probe_ent); 1552 rc = nv_adma_host_init(probe_ent);
1464 if (rc) 1553 if (rc)
1465 goto err_out_iounmap; 1554 return rc;
1466 } 1555 }
1467 1556
1468 rc = ata_device_add(probe_ent); 1557 rc = ata_device_add(probe_ent);
1469 if (rc != NV_PORTS) 1558 if (rc != NV_PORTS)
1470 goto err_out_iounmap; 1559 return -ENODEV;
1471
1472 kfree(probe_ent);
1473 1560
1561 devm_kfree(&pdev->dev, probe_ent);
1474 return 0; 1562 return 0;
1563}
1475 1564
1476err_out_iounmap: 1565static void nv_remove_one (struct pci_dev *pdev)
1477 pci_iounmap(pdev, probe_ent->mmio_base); 1566{
1478err_out_free_ent: 1567 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1479 kfree(probe_ent); 1568 struct nv_host_priv *hpriv = host->private_data;
1480err_out_regions: 1569
1481 pci_release_regions(pdev); 1570 ata_pci_remove_one(pdev);
1482err_out_disable: 1571 kfree(hpriv);
1483 if (!pci_dev_busy) 1572}
1484 pci_disable_device(pdev); 1573
1485err_out: 1574static int nv_pci_device_resume(struct pci_dev *pdev)
1486 return rc; 1575{
1576 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1577 struct nv_host_priv *hpriv = host->private_data;
1578 int rc;
1579
1580 rc = ata_pci_device_do_resume(pdev);
1581 if(rc)
1582 return rc;
1583
1584 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) {
1585 if(hpriv->type >= CK804) {
1586 u8 regval;
1587
1588 pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
1589 regval |= NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
1590 pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
1591 }
1592 if(hpriv->type == ADMA) {
1593 u32 tmp32;
1594 struct nv_adma_port_priv *pp;
1595 /* enable/disable ADMA on the ports appropriately */
1596 pci_read_config_dword(pdev, NV_MCP_SATA_CFG_20, &tmp32);
1597
1598 pp = host->ports[0]->private_data;
1599 if(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE)
1600 tmp32 &= ~(NV_MCP_SATA_CFG_20_PORT0_EN |
1601 NV_MCP_SATA_CFG_20_PORT0_PWB_EN);
1602 else
1603 tmp32 |= (NV_MCP_SATA_CFG_20_PORT0_EN |
1604 NV_MCP_SATA_CFG_20_PORT0_PWB_EN);
1605 pp = host->ports[1]->private_data;
1606 if(pp->flags & NV_ADMA_ATAPI_SETUP_COMPLETE)
1607 tmp32 &= ~(NV_MCP_SATA_CFG_20_PORT1_EN |
1608 NV_MCP_SATA_CFG_20_PORT1_PWB_EN);
1609 else
1610 tmp32 |= (NV_MCP_SATA_CFG_20_PORT1_EN |
1611 NV_MCP_SATA_CFG_20_PORT1_PWB_EN);
1612
1613 pci_write_config_dword(pdev, NV_MCP_SATA_CFG_20, tmp32);
1614 }
1615 }
1616
1617 ata_host_resume(host);
1618
1619 return 0;
1487} 1620}
1488 1621
1489static void nv_ck804_host_stop(struct ata_host *host) 1622static void nv_ck804_host_stop(struct ata_host *host)
@@ -1495,25 +1628,13 @@ static void nv_ck804_host_stop(struct ata_host *host)
1495 pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval); 1628 pci_read_config_byte(pdev, NV_MCP_SATA_CFG_20, &regval);
1496 regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN; 1629 regval &= ~NV_MCP_SATA_CFG_20_SATA_SPACE_EN;
1497 pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval); 1630 pci_write_config_byte(pdev, NV_MCP_SATA_CFG_20, regval);
1498
1499 ata_pci_host_stop(host);
1500} 1631}
1501 1632
1502static void nv_adma_host_stop(struct ata_host *host) 1633static void nv_adma_host_stop(struct ata_host *host)
1503{ 1634{
1504 struct pci_dev *pdev = to_pci_dev(host->dev); 1635 struct pci_dev *pdev = to_pci_dev(host->dev);
1505 int i;
1506 u32 tmp32; 1636 u32 tmp32;
1507 1637
1508 for (i = 0; i < host->n_ports; i++) {
1509 void __iomem *mmio = __nv_adma_ctl_block(host->mmio_base, i);
1510 u16 tmp;
1511
1512 /* disable interrupt */
1513 tmp = readw(mmio + NV_ADMA_CTL);
1514 writew(tmp & ~NV_ADMA_CTL_AIEN, mmio + NV_ADMA_CTL);
1515 }
1516
1517 /* disable ADMA on the ports */ 1638 /* disable ADMA on the ports */
1518 pci_read_config_dword(pdev, NV_MCP_SATA_CFG_20, &tmp32); 1639 pci_read_config_dword(pdev, NV_MCP_SATA_CFG_20, &tmp32);
1519 tmp32 &= ~(NV_MCP_SATA_CFG_20_PORT0_EN | 1640 tmp32 &= ~(NV_MCP_SATA_CFG_20_PORT0_EN |
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index f055874a6ec..3be4cc338d7 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -39,10 +39,10 @@
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/sched.h> 40#include <linux/sched.h>
41#include <linux/device.h> 41#include <linux/device.h>
42#include <scsi/scsi.h>
42#include <scsi/scsi_host.h> 43#include <scsi/scsi_host.h>
43#include <scsi/scsi_cmnd.h> 44#include <scsi/scsi_cmnd.h>
44#include <linux/libata.h> 45#include <linux/libata.h>
45#include <asm/io.h>
46#include "sata_promise.h" 46#include "sata_promise.h"
47 47
48#define DRV_NAME "sata_promise" 48#define DRV_NAME "sata_promise"
@@ -50,6 +50,17 @@
50 50
51 51
52enum { 52enum {
53 PDC_MMIO_BAR = 3,
54
55 /* register offsets */
56 PDC_FEATURE = 0x04, /* Feature/Error reg (per port) */
57 PDC_SECTOR_COUNT = 0x08, /* Sector count reg (per port) */
58 PDC_SECTOR_NUMBER = 0x0C, /* Sector number reg (per port) */
59 PDC_CYLINDER_LOW = 0x10, /* Cylinder low reg (per port) */
60 PDC_CYLINDER_HIGH = 0x14, /* Cylinder high reg (per port) */
61 PDC_DEVICE = 0x18, /* Device/Head reg (per port) */
62 PDC_COMMAND = 0x1C, /* Command/status reg (per port) */
63 PDC_ALTSTATUS = 0x38, /* Alternate-status/device-control reg (per port) */
53 PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */ 64 PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
54 PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */ 65 PDC_INT_SEQMASK = 0x40, /* Mask of asserted SEQ INTs */
55 PDC_FLASH_CTL = 0x44, /* Flash control register */ 66 PDC_FLASH_CTL = 0x44, /* Flash control register */
@@ -71,13 +82,23 @@ enum {
71 82
72 PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */ 83 PDC_HAS_PATA = (1 << 1), /* PDC20375/20575 has PATA */
73 84
85 /* Sequence counter control registers bit definitions */
86 PDC_SEQCNTRL_INT_MASK = (1 << 5), /* Sequence Interrupt Mask */
87
88 /* Feature register values */
89 PDC_FEATURE_ATAPI_PIO = 0x00, /* ATAPI data xfer by PIO */
90 PDC_FEATURE_ATAPI_DMA = 0x01, /* ATAPI data xfer by DMA */
91
92 /* Device/Head register values */
93 PDC_DEVICE_SATA = 0xE0, /* Device/Head value for SATA devices */
94
74 /* PDC_CTLSTAT bit definitions */ 95 /* PDC_CTLSTAT bit definitions */
75 PDC_DMA_ENABLE = (1 << 7), 96 PDC_DMA_ENABLE = (1 << 7),
76 PDC_IRQ_DISABLE = (1 << 10), 97 PDC_IRQ_DISABLE = (1 << 10),
77 PDC_RESET = (1 << 11), /* HDMA reset */ 98 PDC_RESET = (1 << 11), /* HDMA reset */
78 99
79 PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY | 100 PDC_COMMON_FLAGS = ATA_FLAG_NO_LEGACY |
80 ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI | 101 ATA_FLAG_MMIO |
81 ATA_FLAG_PIO_POLLING, 102 ATA_FLAG_PIO_POLLING,
82 103
83 /* hp->flags bits */ 104 /* hp->flags bits */
@@ -92,6 +113,7 @@ struct pdc_port_priv {
92 113
93struct pdc_host_priv { 114struct pdc_host_priv {
94 unsigned long flags; 115 unsigned long flags;
116 unsigned long port_flags[ATA_MAX_PORTS];
95}; 117};
96 118
97static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg); 119static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg);
@@ -100,14 +122,14 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
100static irqreturn_t pdc_interrupt (int irq, void *dev_instance); 122static irqreturn_t pdc_interrupt (int irq, void *dev_instance);
101static void pdc_eng_timeout(struct ata_port *ap); 123static void pdc_eng_timeout(struct ata_port *ap);
102static int pdc_port_start(struct ata_port *ap); 124static int pdc_port_start(struct ata_port *ap);
103static void pdc_port_stop(struct ata_port *ap);
104static void pdc_pata_phy_reset(struct ata_port *ap); 125static void pdc_pata_phy_reset(struct ata_port *ap);
105static void pdc_qc_prep(struct ata_queued_cmd *qc); 126static void pdc_qc_prep(struct ata_queued_cmd *qc);
106static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 127static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
107static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 128static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
129static int pdc_check_atapi_dma(struct ata_queued_cmd *qc);
130static int pdc_old_check_atapi_dma(struct ata_queued_cmd *qc);
108static void pdc_irq_clear(struct ata_port *ap); 131static void pdc_irq_clear(struct ata_port *ap);
109static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc); 132static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc);
110static void pdc_host_stop(struct ata_host *host);
111static void pdc_freeze(struct ata_port *ap); 133static void pdc_freeze(struct ata_port *ap);
112static void pdc_thaw(struct ata_port *ap); 134static void pdc_thaw(struct ata_port *ap);
113static void pdc_error_handler(struct ata_port *ap); 135static void pdc_error_handler(struct ata_port *ap);
@@ -139,6 +161,34 @@ static const struct ata_port_operations pdc_sata_ops = {
139 .check_status = ata_check_status, 161 .check_status = ata_check_status,
140 .exec_command = pdc_exec_command_mmio, 162 .exec_command = pdc_exec_command_mmio,
141 .dev_select = ata_std_dev_select, 163 .dev_select = ata_std_dev_select,
164 .check_atapi_dma = pdc_check_atapi_dma,
165
166 .qc_prep = pdc_qc_prep,
167 .qc_issue = pdc_qc_issue_prot,
168 .freeze = pdc_freeze,
169 .thaw = pdc_thaw,
170 .error_handler = pdc_error_handler,
171 .post_internal_cmd = pdc_post_internal_cmd,
172 .data_xfer = ata_data_xfer,
173 .irq_handler = pdc_interrupt,
174 .irq_clear = pdc_irq_clear,
175 .irq_on = ata_irq_on,
176 .irq_ack = ata_irq_ack,
177
178 .scr_read = pdc_sata_scr_read,
179 .scr_write = pdc_sata_scr_write,
180 .port_start = pdc_port_start,
181};
182
183/* First-generation chips need a more restrictive ->check_atapi_dma op */
184static const struct ata_port_operations pdc_old_sata_ops = {
185 .port_disable = ata_port_disable,
186 .tf_load = pdc_tf_load_mmio,
187 .tf_read = ata_tf_read,
188 .check_status = ata_check_status,
189 .exec_command = pdc_exec_command_mmio,
190 .dev_select = ata_std_dev_select,
191 .check_atapi_dma = pdc_old_check_atapi_dma,
142 192
143 .qc_prep = pdc_qc_prep, 193 .qc_prep = pdc_qc_prep,
144 .qc_issue = pdc_qc_issue_prot, 194 .qc_issue = pdc_qc_issue_prot,
@@ -146,15 +196,15 @@ static const struct ata_port_operations pdc_sata_ops = {
146 .thaw = pdc_thaw, 196 .thaw = pdc_thaw,
147 .error_handler = pdc_error_handler, 197 .error_handler = pdc_error_handler,
148 .post_internal_cmd = pdc_post_internal_cmd, 198 .post_internal_cmd = pdc_post_internal_cmd,
149 .data_xfer = ata_mmio_data_xfer, 199 .data_xfer = ata_data_xfer,
150 .irq_handler = pdc_interrupt, 200 .irq_handler = pdc_interrupt,
151 .irq_clear = pdc_irq_clear, 201 .irq_clear = pdc_irq_clear,
202 .irq_on = ata_irq_on,
203 .irq_ack = ata_irq_ack,
152 204
153 .scr_read = pdc_sata_scr_read, 205 .scr_read = pdc_sata_scr_read,
154 .scr_write = pdc_sata_scr_write, 206 .scr_write = pdc_sata_scr_write,
155 .port_start = pdc_port_start, 207 .port_start = pdc_port_start,
156 .port_stop = pdc_port_stop,
157 .host_stop = pdc_host_stop,
158}; 208};
159 209
160static const struct ata_port_operations pdc_pata_ops = { 210static const struct ata_port_operations pdc_pata_ops = {
@@ -164,30 +214,31 @@ static const struct ata_port_operations pdc_pata_ops = {
164 .check_status = ata_check_status, 214 .check_status = ata_check_status,
165 .exec_command = pdc_exec_command_mmio, 215 .exec_command = pdc_exec_command_mmio,
166 .dev_select = ata_std_dev_select, 216 .dev_select = ata_std_dev_select,
217 .check_atapi_dma = pdc_check_atapi_dma,
167 218
168 .phy_reset = pdc_pata_phy_reset, 219 .phy_reset = pdc_pata_phy_reset,
169 220
170 .qc_prep = pdc_qc_prep, 221 .qc_prep = pdc_qc_prep,
171 .qc_issue = pdc_qc_issue_prot, 222 .qc_issue = pdc_qc_issue_prot,
172 .data_xfer = ata_mmio_data_xfer, 223 .data_xfer = ata_data_xfer,
173 .eng_timeout = pdc_eng_timeout, 224 .eng_timeout = pdc_eng_timeout,
174 .irq_handler = pdc_interrupt, 225 .irq_handler = pdc_interrupt,
175 .irq_clear = pdc_irq_clear, 226 .irq_clear = pdc_irq_clear,
227 .irq_on = ata_irq_on,
228 .irq_ack = ata_irq_ack,
176 229
177 .port_start = pdc_port_start, 230 .port_start = pdc_port_start,
178 .port_stop = pdc_port_stop,
179 .host_stop = pdc_host_stop,
180}; 231};
181 232
182static const struct ata_port_info pdc_port_info[] = { 233static const struct ata_port_info pdc_port_info[] = {
183 /* board_2037x */ 234 /* board_2037x */
184 { 235 {
185 .sht = &pdc_ata_sht, 236 .sht = &pdc_ata_sht,
186 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, 237 .flags = PDC_COMMON_FLAGS,
187 .pio_mask = 0x1f, /* pio0-4 */ 238 .pio_mask = 0x1f, /* pio0-4 */
188 .mwdma_mask = 0x07, /* mwdma0-2 */ 239 .mwdma_mask = 0x07, /* mwdma0-2 */
189 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 240 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
190 .port_ops = &pdc_sata_ops, 241 .port_ops = &pdc_old_sata_ops,
191 }, 242 },
192 243
193 /* board_20319 */ 244 /* board_20319 */
@@ -197,7 +248,7 @@ static const struct ata_port_info pdc_port_info[] = {
197 .pio_mask = 0x1f, /* pio0-4 */ 248 .pio_mask = 0x1f, /* pio0-4 */
198 .mwdma_mask = 0x07, /* mwdma0-2 */ 249 .mwdma_mask = 0x07, /* mwdma0-2 */
199 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 250 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
200 .port_ops = &pdc_sata_ops, 251 .port_ops = &pdc_old_sata_ops,
201 }, 252 },
202 253
203 /* board_20619 */ 254 /* board_20619 */
@@ -213,7 +264,7 @@ static const struct ata_port_info pdc_port_info[] = {
213 /* board_2057x */ 264 /* board_2057x */
214 { 265 {
215 .sht = &pdc_ata_sht, 266 .sht = &pdc_ata_sht,
216 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA, 267 .flags = PDC_COMMON_FLAGS,
217 .pio_mask = 0x1f, /* pio0-4 */ 268 .pio_mask = 0x1f, /* pio0-4 */
218 .mwdma_mask = 0x07, /* mwdma0-2 */ 269 .mwdma_mask = 0x07, /* mwdma0-2 */
219 .udma_mask = 0x7f, /* udma0-6 ; FIXME */ 270 .udma_mask = 0x7f, /* udma0-6 ; FIXME */
@@ -271,21 +322,22 @@ static int pdc_port_start(struct ata_port *ap)
271 struct pdc_port_priv *pp; 322 struct pdc_port_priv *pp;
272 int rc; 323 int rc;
273 324
325 /* fix up port flags and cable type for SATA+PATA chips */
326 ap->flags |= hp->port_flags[ap->port_no];
327 if (ap->flags & ATA_FLAG_SATA)
328 ap->cbl = ATA_CBL_SATA;
329
274 rc = ata_port_start(ap); 330 rc = ata_port_start(ap);
275 if (rc) 331 if (rc)
276 return rc; 332 return rc;
277 333
278 pp = kzalloc(sizeof(*pp), GFP_KERNEL); 334 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
279 if (!pp) { 335 if (!pp)
280 rc = -ENOMEM; 336 return -ENOMEM;
281 goto err_out;
282 }
283 337
284 pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL); 338 pp->pkt = dmam_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
285 if (!pp->pkt) { 339 if (!pp->pkt)
286 rc = -ENOMEM; 340 return -ENOMEM;
287 goto err_out_kfree;
288 }
289 341
290 ap->private_data = pp; 342 ap->private_data = pp;
291 343
@@ -300,40 +352,11 @@ static int pdc_port_start(struct ata_port *ap)
300 } 352 }
301 353
302 return 0; 354 return 0;
303
304err_out_kfree:
305 kfree(pp);
306err_out:
307 ata_port_stop(ap);
308 return rc;
309}
310
311
312static void pdc_port_stop(struct ata_port *ap)
313{
314 struct device *dev = ap->host->dev;
315 struct pdc_port_priv *pp = ap->private_data;
316
317 ap->private_data = NULL;
318 dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
319 kfree(pp);
320 ata_port_stop(ap);
321} 355}
322 356
323
324static void pdc_host_stop(struct ata_host *host)
325{
326 struct pdc_host_priv *hp = host->private_data;
327
328 ata_pci_host_stop(host);
329
330 kfree(hp);
331}
332
333
334static void pdc_reset_port(struct ata_port *ap) 357static void pdc_reset_port(struct ata_port *ap)
335{ 358{
336 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_CTLSTAT; 359 void __iomem *mmio = ap->ioaddr.cmd_addr + PDC_CTLSTAT;
337 unsigned int i; 360 unsigned int i;
338 u32 tmp; 361 u32 tmp;
339 362
@@ -377,18 +400,102 @@ static void pdc_pata_phy_reset(struct ata_port *ap)
377 400
378static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg) 401static u32 pdc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
379{ 402{
380 if (sc_reg > SCR_CONTROL) 403 if (sc_reg > SCR_CONTROL || ap->cbl != ATA_CBL_SATA)
381 return 0xffffffffU; 404 return 0xffffffffU;
382 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 405 return readl(ap->ioaddr.scr_addr + (sc_reg * 4));
383} 406}
384 407
385 408
386static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg, 409static void pdc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
387 u32 val) 410 u32 val)
388{ 411{
389 if (sc_reg > SCR_CONTROL) 412 if (sc_reg > SCR_CONTROL || ap->cbl != ATA_CBL_SATA)
390 return; 413 return;
391 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 414 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
415}
416
417static void pdc_atapi_pkt(struct ata_queued_cmd *qc)
418{
419 struct ata_port *ap = qc->ap;
420 dma_addr_t sg_table = ap->prd_dma;
421 unsigned int cdb_len = qc->dev->cdb_len;
422 u8 *cdb = qc->cdb;
423 struct pdc_port_priv *pp = ap->private_data;
424 u8 *buf = pp->pkt;
425 u32 *buf32 = (u32 *) buf;
426 unsigned int dev_sel, feature, nbytes;
427
428 /* set control bits (byte 0), zero delay seq id (byte 3),
429 * and seq id (byte 2)
430 */
431 switch (qc->tf.protocol) {
432 case ATA_PROT_ATAPI_DMA:
433 if (!(qc->tf.flags & ATA_TFLAG_WRITE))
434 buf32[0] = cpu_to_le32(PDC_PKT_READ);
435 else
436 buf32[0] = 0;
437 break;
438 case ATA_PROT_ATAPI_NODATA:
439 buf32[0] = cpu_to_le32(PDC_PKT_NODATA);
440 break;
441 default:
442 BUG();
443 break;
444 }
445 buf32[1] = cpu_to_le32(sg_table); /* S/G table addr */
446 buf32[2] = 0; /* no next-packet */
447
448 /* select drive */
449 if (sata_scr_valid(ap)) {
450 dev_sel = PDC_DEVICE_SATA;
451 } else {
452 dev_sel = ATA_DEVICE_OBS;
453 if (qc->dev->devno != 0)
454 dev_sel |= ATA_DEV1;
455 }
456 buf[12] = (1 << 5) | ATA_REG_DEVICE;
457 buf[13] = dev_sel;
458 buf[14] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_CLEAR_BSY;
459 buf[15] = dev_sel; /* once more, waiting for BSY to clear */
460
461 buf[16] = (1 << 5) | ATA_REG_NSECT;
462 buf[17] = 0x00;
463 buf[18] = (1 << 5) | ATA_REG_LBAL;
464 buf[19] = 0x00;
465
466 /* set feature and byte counter registers */
467 if (qc->tf.protocol != ATA_PROT_ATAPI_DMA) {
468 feature = PDC_FEATURE_ATAPI_PIO;
469 /* set byte counter register to real transfer byte count */
470 nbytes = qc->nbytes;
471 if (nbytes > 0xffff)
472 nbytes = 0xffff;
473 } else {
474 feature = PDC_FEATURE_ATAPI_DMA;
475 /* set byte counter register to 0 */
476 nbytes = 0;
477 }
478 buf[20] = (1 << 5) | ATA_REG_FEATURE;
479 buf[21] = feature;
480 buf[22] = (1 << 5) | ATA_REG_BYTEL;
481 buf[23] = nbytes & 0xFF;
482 buf[24] = (1 << 5) | ATA_REG_BYTEH;
483 buf[25] = (nbytes >> 8) & 0xFF;
484
485 /* send ATAPI packet command 0xA0 */
486 buf[26] = (1 << 5) | ATA_REG_CMD;
487 buf[27] = ATA_CMD_PACKET;
488
489 /* select drive and check DRQ */
490 buf[28] = (1 << 5) | ATA_REG_DEVICE | PDC_PKT_WAIT_DRDY;
491 buf[29] = dev_sel;
492
493 /* we can represent cdb lengths 2/4/6/8/10/12/14/16 */
494 BUG_ON(cdb_len & ~0x1E);
495
496 /* append the CDB as the final part */
497 buf[30] = (((cdb_len >> 1) & 7) << 5) | ATA_REG_DATA | PDC_LAST_REG;
498 memcpy(buf+31, cdb, cdb_len);
392} 499}
393 500
394static void pdc_qc_prep(struct ata_queued_cmd *qc) 501static void pdc_qc_prep(struct ata_queued_cmd *qc)
@@ -415,6 +522,17 @@ static void pdc_qc_prep(struct ata_queued_cmd *qc)
415 pdc_pkt_footer(&qc->tf, pp->pkt, i); 522 pdc_pkt_footer(&qc->tf, pp->pkt, i);
416 break; 523 break;
417 524
525 case ATA_PROT_ATAPI:
526 ata_qc_prep(qc);
527 break;
528
529 case ATA_PROT_ATAPI_DMA:
530 ata_qc_prep(qc);
531 /*FALLTHROUGH*/
532 case ATA_PROT_ATAPI_NODATA:
533 pdc_atapi_pkt(qc);
534 break;
535
418 default: 536 default:
419 break; 537 break;
420 } 538 }
@@ -517,7 +635,7 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap,
517{ 635{
518 unsigned int handled = 0; 636 unsigned int handled = 0;
519 u32 tmp; 637 u32 tmp;
520 void __iomem *mmio = (void __iomem *) ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL; 638 void __iomem *mmio = ap->ioaddr.cmd_addr + PDC_GLOBAL_CTL;
521 639
522 tmp = readl(mmio); 640 tmp = readl(mmio);
523 if (tmp & PDC_ERR_MASK) { 641 if (tmp & PDC_ERR_MASK) {
@@ -528,6 +646,8 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap,
528 switch (qc->tf.protocol) { 646 switch (qc->tf.protocol) {
529 case ATA_PROT_DMA: 647 case ATA_PROT_DMA:
530 case ATA_PROT_NODATA: 648 case ATA_PROT_NODATA:
649 case ATA_PROT_ATAPI_DMA:
650 case ATA_PROT_ATAPI_NODATA:
531 qc->err_mask |= ac_err_mask(ata_wait_idle(ap)); 651 qc->err_mask |= ac_err_mask(ata_wait_idle(ap));
532 ata_qc_complete(qc); 652 ata_qc_complete(qc);
533 handled = 1; 653 handled = 1;
@@ -544,7 +664,7 @@ static inline unsigned int pdc_host_intr( struct ata_port *ap,
544static void pdc_irq_clear(struct ata_port *ap) 664static void pdc_irq_clear(struct ata_port *ap)
545{ 665{
546 struct ata_host *host = ap->host; 666 struct ata_host *host = ap->host;
547 void __iomem *mmio = host->mmio_base; 667 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
548 668
549 readl(mmio + PDC_INT_SEQMASK); 669 readl(mmio + PDC_INT_SEQMASK);
550} 670}
@@ -560,12 +680,12 @@ static irqreturn_t pdc_interrupt (int irq, void *dev_instance)
560 680
561 VPRINTK("ENTER\n"); 681 VPRINTK("ENTER\n");
562 682
563 if (!host || !host->mmio_base) { 683 if (!host || !host->iomap[PDC_MMIO_BAR]) {
564 VPRINTK("QUICK EXIT\n"); 684 VPRINTK("QUICK EXIT\n");
565 return IRQ_NONE; 685 return IRQ_NONE;
566 } 686 }
567 687
568 mmio_base = host->mmio_base; 688 mmio_base = host->iomap[PDC_MMIO_BAR];
569 689
570 /* reading should also clear interrupts */ 690 /* reading should also clear interrupts */
571 mask = readl(mmio_base + PDC_INT_SEQMASK); 691 mask = readl(mmio_base + PDC_INT_SEQMASK);
@@ -610,32 +730,34 @@ static inline void pdc_packet_start(struct ata_queued_cmd *qc)
610{ 730{
611 struct ata_port *ap = qc->ap; 731 struct ata_port *ap = qc->ap;
612 struct pdc_port_priv *pp = ap->private_data; 732 struct pdc_port_priv *pp = ap->private_data;
733 void __iomem *mmio = ap->host->iomap[PDC_MMIO_BAR];
613 unsigned int port_no = ap->port_no; 734 unsigned int port_no = ap->port_no;
614 u8 seq = (u8) (port_no + 1); 735 u8 seq = (u8) (port_no + 1);
615 736
616 VPRINTK("ENTER, ap %p\n", ap); 737 VPRINTK("ENTER, ap %p\n", ap);
617 738
618 writel(0x00000001, ap->host->mmio_base + (seq * 4)); 739 writel(0x00000001, mmio + (seq * 4));
619 readl(ap->host->mmio_base + (seq * 4)); /* flush */ 740 readl(mmio + (seq * 4)); /* flush */
620 741
621 pp->pkt[2] = seq; 742 pp->pkt[2] = seq;
622 wmb(); /* flush PRD, pkt writes */ 743 wmb(); /* flush PRD, pkt writes */
623 writel(pp->pkt_dma, (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 744 writel(pp->pkt_dma, ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
624 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */ 745 readl(ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); /* flush */
625} 746}
626 747
627static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc) 748static unsigned int pdc_qc_issue_prot(struct ata_queued_cmd *qc)
628{ 749{
629 switch (qc->tf.protocol) { 750 switch (qc->tf.protocol) {
751 case ATA_PROT_ATAPI_NODATA:
752 if (qc->dev->flags & ATA_DFLAG_CDB_INTR)
753 break;
754 /*FALLTHROUGH*/
755 case ATA_PROT_ATAPI_DMA:
630 case ATA_PROT_DMA: 756 case ATA_PROT_DMA:
631 case ATA_PROT_NODATA: 757 case ATA_PROT_NODATA:
632 pdc_packet_start(qc); 758 pdc_packet_start(qc);
633 return 0; 759 return 0;
634 760
635 case ATA_PROT_ATAPI_DMA:
636 BUG();
637 break;
638
639 default: 761 default:
640 break; 762 break;
641 } 763 }
@@ -658,8 +780,44 @@ static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile
658 ata_exec_command(ap, tf); 780 ata_exec_command(ap, tf);
659} 781}
660 782
783static int pdc_check_atapi_dma(struct ata_queued_cmd *qc)
784{
785 u8 *scsicmd = qc->scsicmd->cmnd;
786 int pio = 1; /* atapi dma off by default */
787
788 /* Whitelist commands that may use DMA. */
789 switch (scsicmd[0]) {
790 case WRITE_12:
791 case WRITE_10:
792 case WRITE_6:
793 case READ_12:
794 case READ_10:
795 case READ_6:
796 case 0xad: /* READ_DVD_STRUCTURE */
797 case 0xbe: /* READ_CD */
798 pio = 0;
799 }
800 /* -45150 (FFFF4FA2) to -1 (FFFFFFFF) shall use PIO mode */
801 if (scsicmd[0] == WRITE_10) {
802 unsigned int lba;
803 lba = (scsicmd[2] << 24) | (scsicmd[3] << 16) | (scsicmd[4] << 8) | scsicmd[5];
804 if (lba >= 0xFFFF4FA2)
805 pio = 1;
806 }
807 return pio;
808}
661 809
662static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base) 810static int pdc_old_check_atapi_dma(struct ata_queued_cmd *qc)
811{
812 struct ata_port *ap = qc->ap;
813
814 /* First generation chips cannot use ATAPI DMA on SATA ports */
815 if (sata_scr_valid(ap))
816 return 1;
817 return pdc_check_atapi_dma(qc);
818}
819
820static void pdc_ata_setup_port(struct ata_ioports *port, void __iomem *base)
663{ 821{
664 port->cmd_addr = base; 822 port->cmd_addr = base;
665 port->data_addr = base; 823 port->data_addr = base;
@@ -679,7 +837,7 @@ static void pdc_ata_setup_port(struct ata_ioports *port, unsigned long base)
679 837
680static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 838static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
681{ 839{
682 void __iomem *mmio = pe->mmio_base; 840 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR];
683 struct pdc_host_priv *hp = pe->private_data; 841 struct pdc_host_priv *hp = pe->private_data;
684 int hotplug_offset; 842 int hotplug_offset;
685 u32 tmp; 843 u32 tmp;
@@ -733,55 +891,43 @@ static void pdc_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
733static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 891static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
734{ 892{
735 static int printed_version; 893 static int printed_version;
736 struct ata_probe_ent *probe_ent = NULL; 894 struct ata_probe_ent *probe_ent;
737 struct pdc_host_priv *hp; 895 struct pdc_host_priv *hp;
738 unsigned long base; 896 void __iomem *base;
739 void __iomem *mmio_base;
740 unsigned int board_idx = (unsigned int) ent->driver_data; 897 unsigned int board_idx = (unsigned int) ent->driver_data;
741 int pci_dev_busy = 0;
742 int rc; 898 int rc;
899 u8 tmp;
743 900
744 if (!printed_version++) 901 if (!printed_version++)
745 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 902 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
746 903
747 rc = pci_enable_device(pdev); 904 rc = pcim_enable_device(pdev);
748 if (rc) 905 if (rc)
749 return rc; 906 return rc;
750 907
751 rc = pci_request_regions(pdev, DRV_NAME); 908 rc = pcim_iomap_regions(pdev, 1 << PDC_MMIO_BAR, DRV_NAME);
752 if (rc) { 909 if (rc == -EBUSY)
753 pci_dev_busy = 1; 910 pcim_pin_device(pdev);
754 goto err_out; 911 if (rc)
755 } 912 return rc;
756 913
757 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 914 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
758 if (rc) 915 if (rc)
759 goto err_out_regions; 916 return rc;
760 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 917 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
761 if (rc) 918 if (rc)
762 goto err_out_regions; 919 return rc;
763 920
764 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); 921 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
765 if (probe_ent == NULL) { 922 if (probe_ent == NULL)
766 rc = -ENOMEM; 923 return -ENOMEM;
767 goto err_out_regions;
768 }
769 924
770 probe_ent->dev = pci_dev_to_dev(pdev); 925 probe_ent->dev = pci_dev_to_dev(pdev);
771 INIT_LIST_HEAD(&probe_ent->node); 926 INIT_LIST_HEAD(&probe_ent->node);
772 927
773 mmio_base = pci_iomap(pdev, 3, 0); 928 hp = devm_kzalloc(&pdev->dev, sizeof(*hp), GFP_KERNEL);
774 if (mmio_base == NULL) { 929 if (hp == NULL)
775 rc = -ENOMEM; 930 return -ENOMEM;
776 goto err_out_free_ent;
777 }
778 base = (unsigned long) mmio_base;
779
780 hp = kzalloc(sizeof(*hp), GFP_KERNEL);
781 if (hp == NULL) {
782 rc = -ENOMEM;
783 goto err_out_free_ent;
784 }
785 931
786 probe_ent->private_data = hp; 932 probe_ent->private_data = hp;
787 933
@@ -794,7 +940,9 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
794 940
795 probe_ent->irq = pdev->irq; 941 probe_ent->irq = pdev->irq;
796 probe_ent->irq_flags = IRQF_SHARED; 942 probe_ent->irq_flags = IRQF_SHARED;
797 probe_ent->mmio_base = mmio_base; 943 probe_ent->iomap = pcim_iomap_table(pdev);
944
945 base = probe_ent->iomap[PDC_MMIO_BAR];
798 946
799 pdc_ata_setup_port(&probe_ent->port[0], base + 0x200); 947 pdc_ata_setup_port(&probe_ent->port[0], base + 0x200);
800 pdc_ata_setup_port(&probe_ent->port[1], base + 0x280); 948 pdc_ata_setup_port(&probe_ent->port[1], base + 0x280);
@@ -820,7 +968,17 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
820 hp->flags |= PDC_FLAG_GEN_II; 968 hp->flags |= PDC_FLAG_GEN_II;
821 /* Fall through */ 969 /* Fall through */
822 case board_2037x: 970 case board_2037x:
823 probe_ent->n_ports = 2; 971 /* TX2plus boards also have a PATA port */
972 tmp = readb(base + PDC_FLASH_CTL+1);
973 if (!(tmp & 0x80)) {
974 probe_ent->n_ports = 3;
975 pdc_ata_setup_port(&probe_ent->port[2], base + 0x300);
976 hp->port_flags[2] = ATA_FLAG_SLAVE_POSS;
977 printk(KERN_INFO DRV_NAME " PATA port found\n");
978 } else
979 probe_ent->n_ports = 2;
980 hp->port_flags[0] = ATA_FLAG_SATA;
981 hp->port_flags[1] = ATA_FLAG_SATA;
824 break; 982 break;
825 case board_20619: 983 case board_20619:
826 probe_ent->n_ports = 4; 984 probe_ent->n_ports = 4;
@@ -841,22 +999,11 @@ static int pdc_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
841 /* initialize adapter */ 999 /* initialize adapter */
842 pdc_host_init(board_idx, probe_ent); 1000 pdc_host_init(board_idx, probe_ent);
843 1001
844 /* FIXME: Need any other frees than hp? */
845 if (!ata_device_add(probe_ent)) 1002 if (!ata_device_add(probe_ent))
846 kfree(hp); 1003 return -ENODEV;
847
848 kfree(probe_ent);
849 1004
1005 devm_kfree(&pdev->dev, probe_ent);
850 return 0; 1006 return 0;
851
852err_out_free_ent:
853 kfree(probe_ent);
854err_out_regions:
855 pci_release_regions(pdev);
856err_out:
857 if (!pci_dev_busy)
858 pci_disable_device(pdev);
859 return rc;
860} 1007}
861 1008
862 1009
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
index 710909df4ea..bfa35ede655 100644
--- a/drivers/ata/sata_qstor.c
+++ b/drivers/ata/sata_qstor.c
@@ -37,13 +37,14 @@
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/device.h> 38#include <linux/device.h>
39#include <scsi/scsi_host.h> 39#include <scsi/scsi_host.h>
40#include <asm/io.h>
41#include <linux/libata.h> 40#include <linux/libata.h>
42 41
43#define DRV_NAME "sata_qstor" 42#define DRV_NAME "sata_qstor"
44#define DRV_VERSION "0.06" 43#define DRV_VERSION "0.06"
45 44
46enum { 45enum {
46 QS_MMIO_BAR = 4,
47
47 QS_PORTS = 4, 48 QS_PORTS = 4,
48 QS_MAX_PRD = LIBATA_MAX_PRD, 49 QS_MAX_PRD = LIBATA_MAX_PRD,
49 QS_CPB_ORDER = 6, 50 QS_CPB_ORDER = 6,
@@ -117,7 +118,6 @@ static int qs_ata_init_one (struct pci_dev *pdev, const struct pci_device_id *en
117static irqreturn_t qs_intr (int irq, void *dev_instance); 118static irqreturn_t qs_intr (int irq, void *dev_instance);
118static int qs_port_start(struct ata_port *ap); 119static int qs_port_start(struct ata_port *ap);
119static void qs_host_stop(struct ata_host *host); 120static void qs_host_stop(struct ata_host *host);
120static void qs_port_stop(struct ata_port *ap);
121static void qs_phy_reset(struct ata_port *ap); 121static void qs_phy_reset(struct ata_port *ap);
122static void qs_qc_prep(struct ata_queued_cmd *qc); 122static void qs_qc_prep(struct ata_queued_cmd *qc);
123static unsigned int qs_qc_issue(struct ata_queued_cmd *qc); 123static unsigned int qs_qc_issue(struct ata_queued_cmd *qc);
@@ -157,14 +157,15 @@ static const struct ata_port_operations qs_ata_ops = {
157 .phy_reset = qs_phy_reset, 157 .phy_reset = qs_phy_reset,
158 .qc_prep = qs_qc_prep, 158 .qc_prep = qs_qc_prep,
159 .qc_issue = qs_qc_issue, 159 .qc_issue = qs_qc_issue,
160 .data_xfer = ata_mmio_data_xfer, 160 .data_xfer = ata_data_xfer,
161 .eng_timeout = qs_eng_timeout, 161 .eng_timeout = qs_eng_timeout,
162 .irq_handler = qs_intr, 162 .irq_handler = qs_intr,
163 .irq_clear = qs_irq_clear, 163 .irq_clear = qs_irq_clear,
164 .irq_on = ata_irq_on,
165 .irq_ack = ata_irq_ack,
164 .scr_read = qs_scr_read, 166 .scr_read = qs_scr_read,
165 .scr_write = qs_scr_write, 167 .scr_write = qs_scr_write,
166 .port_start = qs_port_start, 168 .port_start = qs_port_start,
167 .port_stop = qs_port_stop,
168 .host_stop = qs_host_stop, 169 .host_stop = qs_host_stop,
169 .bmdma_stop = qs_bmdma_stop, 170 .bmdma_stop = qs_bmdma_stop,
170 .bmdma_status = qs_bmdma_status, 171 .bmdma_status = qs_bmdma_status,
@@ -197,6 +198,11 @@ static struct pci_driver qs_ata_pci_driver = {
197 .remove = ata_pci_remove_one, 198 .remove = ata_pci_remove_one,
198}; 199};
199 200
201static void __iomem *qs_mmio_base(struct ata_host *host)
202{
203 return host->iomap[QS_MMIO_BAR];
204}
205
200static int qs_check_atapi_dma(struct ata_queued_cmd *qc) 206static int qs_check_atapi_dma(struct ata_queued_cmd *qc)
201{ 207{
202 return 1; /* ATAPI DMA not supported */ 208 return 1; /* ATAPI DMA not supported */
@@ -219,7 +225,7 @@ static void qs_irq_clear(struct ata_port *ap)
219 225
220static inline void qs_enter_reg_mode(struct ata_port *ap) 226static inline void qs_enter_reg_mode(struct ata_port *ap)
221{ 227{
222 u8 __iomem *chan = ap->host->mmio_base + (ap->port_no * 0x4000); 228 u8 __iomem *chan = qs_mmio_base(ap->host) + (ap->port_no * 0x4000);
223 229
224 writeb(QS_CTR0_REG, chan + QS_CCT_CTR0); 230 writeb(QS_CTR0_REG, chan + QS_CCT_CTR0);
225 readb(chan + QS_CCT_CTR0); /* flush */ 231 readb(chan + QS_CCT_CTR0); /* flush */
@@ -227,7 +233,7 @@ static inline void qs_enter_reg_mode(struct ata_port *ap)
227 233
228static inline void qs_reset_channel_logic(struct ata_port *ap) 234static inline void qs_reset_channel_logic(struct ata_port *ap)
229{ 235{
230 u8 __iomem *chan = ap->host->mmio_base + (ap->port_no * 0x4000); 236 u8 __iomem *chan = qs_mmio_base(ap->host) + (ap->port_no * 0x4000);
231 237
232 writeb(QS_CTR1_RCHN, chan + QS_CCT_CTR1); 238 writeb(QS_CTR1_RCHN, chan + QS_CCT_CTR1);
233 readb(chan + QS_CCT_CTR0); /* flush */ 239 readb(chan + QS_CCT_CTR0); /* flush */
@@ -257,14 +263,14 @@ static u32 qs_scr_read (struct ata_port *ap, unsigned int sc_reg)
257{ 263{
258 if (sc_reg > SCR_CONTROL) 264 if (sc_reg > SCR_CONTROL)
259 return ~0U; 265 return ~0U;
260 return readl((void __iomem *)(ap->ioaddr.scr_addr + (sc_reg * 8))); 266 return readl(ap->ioaddr.scr_addr + (sc_reg * 8));
261} 267}
262 268
263static void qs_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 269static void qs_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
264{ 270{
265 if (sc_reg > SCR_CONTROL) 271 if (sc_reg > SCR_CONTROL)
266 return; 272 return;
267 writel(val, (void __iomem *)(ap->ioaddr.scr_addr + (sc_reg * 8))); 273 writel(val, ap->ioaddr.scr_addr + (sc_reg * 8));
268} 274}
269 275
270static unsigned int qs_fill_sg(struct ata_queued_cmd *qc) 276static unsigned int qs_fill_sg(struct ata_queued_cmd *qc)
@@ -325,7 +331,7 @@ static void qs_qc_prep(struct ata_queued_cmd *qc)
325 /* host control block (HCB) */ 331 /* host control block (HCB) */
326 buf[ 0] = QS_HCB_HDR; 332 buf[ 0] = QS_HCB_HDR;
327 buf[ 1] = hflags; 333 buf[ 1] = hflags;
328 *(__le32 *)(&buf[ 4]) = cpu_to_le32(qc->nsect * ATA_SECT_SIZE); 334 *(__le32 *)(&buf[ 4]) = cpu_to_le32(qc->nbytes);
329 *(__le32 *)(&buf[ 8]) = cpu_to_le32(nelem); 335 *(__le32 *)(&buf[ 8]) = cpu_to_le32(nelem);
330 addr = ((u64)pp->pkt_dma) + QS_CPB_BYTES; 336 addr = ((u64)pp->pkt_dma) + QS_CPB_BYTES;
331 *(__le64 *)(&buf[16]) = cpu_to_le64(addr); 337 *(__le64 *)(&buf[16]) = cpu_to_le64(addr);
@@ -341,7 +347,7 @@ static void qs_qc_prep(struct ata_queued_cmd *qc)
341static inline void qs_packet_start(struct ata_queued_cmd *qc) 347static inline void qs_packet_start(struct ata_queued_cmd *qc)
342{ 348{
343 struct ata_port *ap = qc->ap; 349 struct ata_port *ap = qc->ap;
344 u8 __iomem *chan = ap->host->mmio_base + (ap->port_no * 0x4000); 350 u8 __iomem *chan = qs_mmio_base(ap->host) + (ap->port_no * 0x4000);
345 351
346 VPRINTK("ENTER, ap %p\n", ap); 352 VPRINTK("ENTER, ap %p\n", ap);
347 353
@@ -378,7 +384,7 @@ static inline unsigned int qs_intr_pkt(struct ata_host *host)
378{ 384{
379 unsigned int handled = 0; 385 unsigned int handled = 0;
380 u8 sFFE; 386 u8 sFFE;
381 u8 __iomem *mmio_base = host->mmio_base; 387 u8 __iomem *mmio_base = qs_mmio_base(host);
382 388
383 do { 389 do {
384 u32 sff0 = readl(mmio_base + QS_HST_SFF); 390 u32 sff0 = readl(mmio_base + QS_HST_SFF);
@@ -470,7 +476,7 @@ static irqreturn_t qs_intr(int irq, void *dev_instance)
470 return IRQ_RETVAL(handled); 476 return IRQ_RETVAL(handled);
471} 477}
472 478
473static void qs_ata_setup_port(struct ata_ioports *port, unsigned long base) 479static void qs_ata_setup_port(struct ata_ioports *port, void __iomem *base)
474{ 480{
475 port->cmd_addr = 481 port->cmd_addr =
476 port->data_addr = base + 0x400; 482 port->data_addr = base + 0x400;
@@ -492,7 +498,7 @@ static int qs_port_start(struct ata_port *ap)
492{ 498{
493 struct device *dev = ap->host->dev; 499 struct device *dev = ap->host->dev;
494 struct qs_port_priv *pp; 500 struct qs_port_priv *pp;
495 void __iomem *mmio_base = ap->host->mmio_base; 501 void __iomem *mmio_base = qs_mmio_base(ap->host);
496 void __iomem *chan = mmio_base + (ap->port_no * 0x4000); 502 void __iomem *chan = mmio_base + (ap->port_no * 0x4000);
497 u64 addr; 503 u64 addr;
498 int rc; 504 int rc;
@@ -501,17 +507,13 @@ static int qs_port_start(struct ata_port *ap)
501 if (rc) 507 if (rc)
502 return rc; 508 return rc;
503 qs_enter_reg_mode(ap); 509 qs_enter_reg_mode(ap);
504 pp = kzalloc(sizeof(*pp), GFP_KERNEL); 510 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
505 if (!pp) { 511 if (!pp)
506 rc = -ENOMEM; 512 return -ENOMEM;
507 goto err_out; 513 pp->pkt = dmam_alloc_coherent(dev, QS_PKT_BYTES, &pp->pkt_dma,
508 } 514 GFP_KERNEL);
509 pp->pkt = dma_alloc_coherent(dev, QS_PKT_BYTES, &pp->pkt_dma, 515 if (!pp->pkt)
510 GFP_KERNEL); 516 return -ENOMEM;
511 if (!pp->pkt) {
512 rc = -ENOMEM;
513 goto err_out_kfree;
514 }
515 memset(pp->pkt, 0, QS_PKT_BYTES); 517 memset(pp->pkt, 0, QS_PKT_BYTES);
516 ap->private_data = pp; 518 ap->private_data = pp;
517 519
@@ -519,43 +521,19 @@ static int qs_port_start(struct ata_port *ap)
519 writel((u32) addr, chan + QS_CCF_CPBA); 521 writel((u32) addr, chan + QS_CCF_CPBA);
520 writel((u32)(addr >> 32), chan + QS_CCF_CPBA + 4); 522 writel((u32)(addr >> 32), chan + QS_CCF_CPBA + 4);
521 return 0; 523 return 0;
522
523err_out_kfree:
524 kfree(pp);
525err_out:
526 ata_port_stop(ap);
527 return rc;
528}
529
530static void qs_port_stop(struct ata_port *ap)
531{
532 struct device *dev = ap->host->dev;
533 struct qs_port_priv *pp = ap->private_data;
534
535 if (pp != NULL) {
536 ap->private_data = NULL;
537 if (pp->pkt != NULL)
538 dma_free_coherent(dev, QS_PKT_BYTES, pp->pkt,
539 pp->pkt_dma);
540 kfree(pp);
541 }
542 ata_port_stop(ap);
543} 524}
544 525
545static void qs_host_stop(struct ata_host *host) 526static void qs_host_stop(struct ata_host *host)
546{ 527{
547 void __iomem *mmio_base = host->mmio_base; 528 void __iomem *mmio_base = qs_mmio_base(host);
548 struct pci_dev *pdev = to_pci_dev(host->dev);
549 529
550 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */ 530 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */
551 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */ 531 writeb(QS_CNFG3_GSRST, mmio_base + QS_HCF_CNFG3); /* global reset */
552
553 pci_iounmap(pdev, mmio_base);
554} 532}
555 533
556static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe) 534static void qs_host_init(unsigned int chip_id, struct ata_probe_ent *pe)
557{ 535{
558 void __iomem *mmio_base = pe->mmio_base; 536 void __iomem *mmio_base = pe->iomap[QS_MMIO_BAR];
559 unsigned int port_no; 537 unsigned int port_no;
560 538
561 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */ 539 writeb(0, mmio_base + QS_HCT_CTRL); /* disable host interrupts */
@@ -630,44 +608,34 @@ static int qs_ata_init_one(struct pci_dev *pdev,
630 const struct pci_device_id *ent) 608 const struct pci_device_id *ent)
631{ 609{
632 static int printed_version; 610 static int printed_version;
633 struct ata_probe_ent *probe_ent = NULL; 611 struct ata_probe_ent *probe_ent;
634 void __iomem *mmio_base; 612 void __iomem * const *iomap;
635 unsigned int board_idx = (unsigned int) ent->driver_data; 613 unsigned int board_idx = (unsigned int) ent->driver_data;
636 int rc, port_no; 614 int rc, port_no;
637 615
638 if (!printed_version++) 616 if (!printed_version++)
639 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 617 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
640 618
641 rc = pci_enable_device(pdev); 619 rc = pcim_enable_device(pdev);
642 if (rc) 620 if (rc)
643 return rc; 621 return rc;
644 622
645 rc = pci_request_regions(pdev, DRV_NAME); 623 if ((pci_resource_flags(pdev, QS_MMIO_BAR) & IORESOURCE_MEM) == 0)
646 if (rc) 624 return -ENODEV;
647 goto err_out;
648
649 if ((pci_resource_flags(pdev, 4) & IORESOURCE_MEM) == 0) {
650 rc = -ENODEV;
651 goto err_out_regions;
652 }
653 625
654 mmio_base = pci_iomap(pdev, 4, 0); 626 rc = pcim_iomap_regions(pdev, 1 << QS_MMIO_BAR, DRV_NAME);
655 if (mmio_base == NULL) { 627 if (rc)
656 rc = -ENOMEM; 628 return rc;
657 goto err_out_regions; 629 iomap = pcim_iomap_table(pdev);
658 }
659 630
660 rc = qs_set_dma_masks(pdev, mmio_base); 631 rc = qs_set_dma_masks(pdev, iomap[QS_MMIO_BAR]);
661 if (rc) 632 if (rc)
662 goto err_out_iounmap; 633 return rc;
663 634
664 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 635 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
665 if (probe_ent == NULL) { 636 if (probe_ent == NULL)
666 rc = -ENOMEM; 637 return -ENOMEM;
667 goto err_out_iounmap;
668 }
669 638
670 memset(probe_ent, 0, sizeof(*probe_ent));
671 probe_ent->dev = pci_dev_to_dev(pdev); 639 probe_ent->dev = pci_dev_to_dev(pdev);
672 INIT_LIST_HEAD(&probe_ent->node); 640 INIT_LIST_HEAD(&probe_ent->node);
673 641
@@ -680,12 +648,12 @@ static int qs_ata_init_one(struct pci_dev *pdev,
680 648
681 probe_ent->irq = pdev->irq; 649 probe_ent->irq = pdev->irq;
682 probe_ent->irq_flags = IRQF_SHARED; 650 probe_ent->irq_flags = IRQF_SHARED;
683 probe_ent->mmio_base = mmio_base; 651 probe_ent->iomap = iomap;
684 probe_ent->n_ports = QS_PORTS; 652 probe_ent->n_ports = QS_PORTS;
685 653
686 for (port_no = 0; port_no < probe_ent->n_ports; ++port_no) { 654 for (port_no = 0; port_no < probe_ent->n_ports; ++port_no) {
687 unsigned long chan = (unsigned long)mmio_base + 655 void __iomem *chan =
688 (port_no * 0x4000); 656 probe_ent->iomap[QS_MMIO_BAR] + (port_no * 0x4000);
689 qs_ata_setup_port(&probe_ent->port[port_no], chan); 657 qs_ata_setup_port(&probe_ent->port[port_no], chan);
690 } 658 }
691 659
@@ -694,19 +662,11 @@ static int qs_ata_init_one(struct pci_dev *pdev,
694 /* initialize adapter */ 662 /* initialize adapter */
695 qs_host_init(board_idx, probe_ent); 663 qs_host_init(board_idx, probe_ent);
696 664
697 rc = ata_device_add(probe_ent); 665 if (ata_device_add(probe_ent) != QS_PORTS)
698 kfree(probe_ent); 666 return -EIO;
699 if (rc != QS_PORTS)
700 goto err_out_iounmap;
701 return 0;
702 667
703err_out_iounmap: 668 devm_kfree(&pdev->dev, probe_ent);
704 pci_iounmap(pdev, mmio_base); 669 return 0;
705err_out_regions:
706 pci_release_regions(pdev);
707err_out:
708 pci_disable_device(pdev);
709 return rc;
710} 670}
711 671
712static int __init qs_ata_init(void) 672static int __init qs_ata_init(void)
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index 7808d0369d9..dca3d3749f0 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -49,6 +49,8 @@
49#define DRV_VERSION "2.0" 49#define DRV_VERSION "2.0"
50 50
51enum { 51enum {
52 SIL_MMIO_BAR = 5,
53
52 /* 54 /*
53 * host flags 55 * host flags
54 */ 56 */
@@ -200,18 +202,18 @@ static const struct ata_port_operations sil_ops = {
200 .bmdma_status = ata_bmdma_status, 202 .bmdma_status = ata_bmdma_status,
201 .qc_prep = ata_qc_prep, 203 .qc_prep = ata_qc_prep,
202 .qc_issue = ata_qc_issue_prot, 204 .qc_issue = ata_qc_issue_prot,
203 .data_xfer = ata_mmio_data_xfer, 205 .data_xfer = ata_data_xfer,
204 .freeze = sil_freeze, 206 .freeze = sil_freeze,
205 .thaw = sil_thaw, 207 .thaw = sil_thaw,
206 .error_handler = ata_bmdma_error_handler, 208 .error_handler = ata_bmdma_error_handler,
207 .post_internal_cmd = ata_bmdma_post_internal_cmd, 209 .post_internal_cmd = ata_bmdma_post_internal_cmd,
208 .irq_handler = sil_interrupt, 210 .irq_handler = sil_interrupt,
209 .irq_clear = ata_bmdma_irq_clear, 211 .irq_clear = ata_bmdma_irq_clear,
212 .irq_on = ata_irq_on,
213 .irq_ack = ata_irq_ack,
210 .scr_read = sil_scr_read, 214 .scr_read = sil_scr_read,
211 .scr_write = sil_scr_write, 215 .scr_write = sil_scr_write,
212 .port_start = ata_port_start, 216 .port_start = ata_port_start,
213 .port_stop = ata_port_stop,
214 .host_stop = ata_pci_host_stop,
215}; 217};
216 218
217static const struct ata_port_info sil_port_info[] = { 219static const struct ata_port_info sil_port_info[] = {
@@ -297,7 +299,8 @@ static void sil_post_set_mode (struct ata_port *ap)
297{ 299{
298 struct ata_host *host = ap->host; 300 struct ata_host *host = ap->host;
299 struct ata_device *dev; 301 struct ata_device *dev;
300 void __iomem *addr = host->mmio_base + sil_port[ap->port_no].xfer_mode; 302 void __iomem *mmio_base = host->iomap[SIL_MMIO_BAR];
303 void __iomem *addr = mmio_base + sil_port[ap->port_no].xfer_mode;
301 u32 tmp, dev_mode[2]; 304 u32 tmp, dev_mode[2];
302 unsigned int i; 305 unsigned int i;
303 306
@@ -320,9 +323,9 @@ static void sil_post_set_mode (struct ata_port *ap)
320 readl(addr); /* flush */ 323 readl(addr); /* flush */
321} 324}
322 325
323static inline unsigned long sil_scr_addr(struct ata_port *ap, unsigned int sc_reg) 326static inline void __iomem *sil_scr_addr(struct ata_port *ap, unsigned int sc_reg)
324{ 327{
325 unsigned long offset = ap->ioaddr.scr_addr; 328 void __iomem *offset = ap->ioaddr.scr_addr;
326 329
327 switch (sc_reg) { 330 switch (sc_reg) {
328 case SCR_STATUS: 331 case SCR_STATUS:
@@ -341,7 +344,7 @@ static inline unsigned long sil_scr_addr(struct ata_port *ap, unsigned int sc_re
341 344
342static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg) 345static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg)
343{ 346{
344 void __iomem *mmio = (void __iomem *) sil_scr_addr(ap, sc_reg); 347 void __iomem *mmio = sil_scr_addr(ap, sc_reg);
345 if (mmio) 348 if (mmio)
346 return readl(mmio); 349 return readl(mmio);
347 return 0xffffffffU; 350 return 0xffffffffU;
@@ -349,7 +352,7 @@ static u32 sil_scr_read (struct ata_port *ap, unsigned int sc_reg)
349 352
350static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 353static void sil_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
351{ 354{
352 void __iomem *mmio = (void __iomem *) sil_scr_addr(ap, sc_reg); 355 void __iomem *mmio = sil_scr_addr(ap, sc_reg);
353 if (mmio) 356 if (mmio)
354 writel(val, mmio); 357 writel(val, mmio);
355} 358}
@@ -444,7 +447,7 @@ static void sil_host_intr(struct ata_port *ap, u32 bmdma2)
444static irqreturn_t sil_interrupt(int irq, void *dev_instance) 447static irqreturn_t sil_interrupt(int irq, void *dev_instance)
445{ 448{
446 struct ata_host *host = dev_instance; 449 struct ata_host *host = dev_instance;
447 void __iomem *mmio_base = host->mmio_base; 450 void __iomem *mmio_base = host->iomap[SIL_MMIO_BAR];
448 int handled = 0; 451 int handled = 0;
449 int i; 452 int i;
450 453
@@ -476,7 +479,7 @@ static irqreturn_t sil_interrupt(int irq, void *dev_instance)
476 479
477static void sil_freeze(struct ata_port *ap) 480static void sil_freeze(struct ata_port *ap)
478{ 481{
479 void __iomem *mmio_base = ap->host->mmio_base; 482 void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR];
480 u32 tmp; 483 u32 tmp;
481 484
482 /* global IRQ mask doesn't block SATA IRQ, turn off explicitly */ 485 /* global IRQ mask doesn't block SATA IRQ, turn off explicitly */
@@ -491,7 +494,7 @@ static void sil_freeze(struct ata_port *ap)
491 494
492static void sil_thaw(struct ata_port *ap) 495static void sil_thaw(struct ata_port *ap)
493{ 496{
494 void __iomem *mmio_base = ap->host->mmio_base; 497 void __iomem *mmio_base = ap->host->iomap[SIL_MMIO_BAR];
495 u32 tmp; 498 u32 tmp;
496 499
497 /* clear IRQ */ 500 /* clear IRQ */
@@ -541,9 +544,9 @@ static void sil_dev_config(struct ata_port *ap, struct ata_device *dev)
541{ 544{
542 int print_info = ap->eh_context.i.flags & ATA_EHI_PRINTINFO; 545 int print_info = ap->eh_context.i.flags & ATA_EHI_PRINTINFO;
543 unsigned int n, quirks = 0; 546 unsigned int n, quirks = 0;
544 unsigned char model_num[41]; 547 unsigned char model_num[ATA_ID_PROD_LEN + 1];
545 548
546 ata_id_c_string(dev->id, model_num, ATA_ID_PROD_OFS, sizeof(model_num)); 549 ata_id_c_string(dev->id, model_num, ATA_ID_PROD, sizeof(model_num));
547 550
548 for (n = 0; sil_blacklist[n].product; n++) 551 for (n = 0; sil_blacklist[n].product; n++)
549 if (!strcmp(sil_blacklist[n].product, model_num)) { 552 if (!strcmp(sil_blacklist[n].product, model_num)) {
@@ -621,38 +624,35 @@ static void sil_init_controller(struct pci_dev *pdev,
621static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 624static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
622{ 625{
623 static int printed_version; 626 static int printed_version;
624 struct ata_probe_ent *probe_ent = NULL; 627 struct device *dev = &pdev->dev;
625 unsigned long base; 628 struct ata_probe_ent *probe_ent;
626 void __iomem *mmio_base; 629 void __iomem *mmio_base;
627 int rc; 630 int rc;
628 unsigned int i; 631 unsigned int i;
629 int pci_dev_busy = 0;
630 632
631 if (!printed_version++) 633 if (!printed_version++)
632 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 634 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
633 635
634 rc = pci_enable_device(pdev); 636 rc = pcim_enable_device(pdev);
635 if (rc) 637 if (rc)
636 return rc; 638 return rc;
637 639
638 rc = pci_request_regions(pdev, DRV_NAME); 640 rc = pcim_iomap_regions(pdev, 1 << SIL_MMIO_BAR, DRV_NAME);
639 if (rc) { 641 if (rc == -EBUSY)
640 pci_dev_busy = 1; 642 pcim_pin_device(pdev);
641 goto err_out; 643 if (rc)
642 } 644 return rc;
643 645
644 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 646 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
645 if (rc) 647 if (rc)
646 goto err_out_regions; 648 return rc;
647 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 649 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
648 if (rc) 650 if (rc)
649 goto err_out_regions; 651 return rc;
650 652
651 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL); 653 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
652 if (probe_ent == NULL) { 654 if (probe_ent == NULL)
653 rc = -ENOMEM; 655 return -ENOMEM;
654 goto err_out_regions;
655 }
656 656
657 INIT_LIST_HEAD(&probe_ent->node); 657 INIT_LIST_HEAD(&probe_ent->node);
658 probe_ent->dev = pci_dev_to_dev(pdev); 658 probe_ent->dev = pci_dev_to_dev(pdev);
@@ -666,22 +666,16 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
666 probe_ent->irq_flags = IRQF_SHARED; 666 probe_ent->irq_flags = IRQF_SHARED;
667 probe_ent->port_flags = sil_port_info[ent->driver_data].flags; 667 probe_ent->port_flags = sil_port_info[ent->driver_data].flags;
668 668
669 mmio_base = pci_iomap(pdev, 5, 0); 669 probe_ent->iomap = pcim_iomap_table(pdev);
670 if (mmio_base == NULL) {
671 rc = -ENOMEM;
672 goto err_out_free_ent;
673 }
674
675 probe_ent->mmio_base = mmio_base;
676 670
677 base = (unsigned long) mmio_base; 671 mmio_base = probe_ent->iomap[SIL_MMIO_BAR];
678 672
679 for (i = 0; i < probe_ent->n_ports; i++) { 673 for (i = 0; i < probe_ent->n_ports; i++) {
680 probe_ent->port[i].cmd_addr = base + sil_port[i].tf; 674 probe_ent->port[i].cmd_addr = mmio_base + sil_port[i].tf;
681 probe_ent->port[i].altstatus_addr = 675 probe_ent->port[i].altstatus_addr =
682 probe_ent->port[i].ctl_addr = base + sil_port[i].ctl; 676 probe_ent->port[i].ctl_addr = mmio_base + sil_port[i].ctl;
683 probe_ent->port[i].bmdma_addr = base + sil_port[i].bmdma; 677 probe_ent->port[i].bmdma_addr = mmio_base + sil_port[i].bmdma;
684 probe_ent->port[i].scr_addr = base + sil_port[i].scr; 678 probe_ent->port[i].scr_addr = mmio_base + sil_port[i].scr;
685 ata_std_ports(&probe_ent->port[i]); 679 ata_std_ports(&probe_ent->port[i]);
686 } 680 }
687 681
@@ -690,30 +684,25 @@ static int sil_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
690 684
691 pci_set_master(pdev); 685 pci_set_master(pdev);
692 686
693 /* FIXME: check ata_device_add return value */ 687 if (!ata_device_add(probe_ent))
694 ata_device_add(probe_ent); 688 return -ENODEV;
695 kfree(probe_ent);
696 689
690 devm_kfree(dev, probe_ent);
697 return 0; 691 return 0;
698
699err_out_free_ent:
700 kfree(probe_ent);
701err_out_regions:
702 pci_release_regions(pdev);
703err_out:
704 if (!pci_dev_busy)
705 pci_disable_device(pdev);
706 return rc;
707} 692}
708 693
709#ifdef CONFIG_PM 694#ifdef CONFIG_PM
710static int sil_pci_device_resume(struct pci_dev *pdev) 695static int sil_pci_device_resume(struct pci_dev *pdev)
711{ 696{
712 struct ata_host *host = dev_get_drvdata(&pdev->dev); 697 struct ata_host *host = dev_get_drvdata(&pdev->dev);
698 int rc;
699
700 rc = ata_pci_device_do_resume(pdev);
701 if (rc)
702 return rc;
713 703
714 ata_pci_device_do_resume(pdev);
715 sil_init_controller(pdev, host->n_ports, host->ports[0]->flags, 704 sil_init_controller(pdev, host->n_ports, host->ports[0]->flags,
716 host->mmio_base); 705 host->iomap[SIL_MMIO_BAR]);
717 ata_host_resume(host); 706 ata_host_resume(host);
718 707
719 return 0; 708 return 0;
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index 5aa288d2fb8..e65e8d55da3 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -28,7 +28,6 @@
28#include <scsi/scsi_host.h> 28#include <scsi/scsi_host.h>
29#include <scsi/scsi_cmnd.h> 29#include <scsi/scsi_cmnd.h>
30#include <linux/libata.h> 30#include <linux/libata.h>
31#include <asm/io.h>
32 31
33#define DRV_NAME "sata_sil24" 32#define DRV_NAME "sata_sil24"
34#define DRV_VERSION "0.3" 33#define DRV_VERSION "0.3"
@@ -61,6 +60,9 @@ struct sil24_port_multiplier {
61}; 60};
62 61
63enum { 62enum {
63 SIL24_HOST_BAR = 0,
64 SIL24_PORT_BAR = 2,
65
64 /* 66 /*
65 * Global controller registers (128 bytes @ BAR0) 67 * Global controller registers (128 bytes @ BAR0)
66 */ 68 */
@@ -321,12 +323,6 @@ struct sil24_port_priv {
321 struct ata_taskfile tf; /* Cached taskfile registers */ 323 struct ata_taskfile tf; /* Cached taskfile registers */
322}; 324};
323 325
324/* ap->host->private_data */
325struct sil24_host_priv {
326 void __iomem *host_base; /* global controller control (128 bytes @BAR0) */
327 void __iomem *port_base; /* port registers (4 * 8192 bytes @BAR2) */
328};
329
330static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev); 326static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev);
331static u8 sil24_check_status(struct ata_port *ap); 327static u8 sil24_check_status(struct ata_port *ap);
332static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg); 328static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg);
@@ -341,8 +337,6 @@ static void sil24_thaw(struct ata_port *ap);
341static void sil24_error_handler(struct ata_port *ap); 337static void sil24_error_handler(struct ata_port *ap);
342static void sil24_post_internal_cmd(struct ata_queued_cmd *qc); 338static void sil24_post_internal_cmd(struct ata_queued_cmd *qc);
343static int sil24_port_start(struct ata_port *ap); 339static int sil24_port_start(struct ata_port *ap);
344static void sil24_port_stop(struct ata_port *ap);
345static void sil24_host_stop(struct ata_host *host);
346static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent); 340static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent);
347#ifdef CONFIG_PM 341#ifdef CONFIG_PM
348static int sil24_pci_device_resume(struct pci_dev *pdev); 342static int sil24_pci_device_resume(struct pci_dev *pdev);
@@ -362,7 +356,7 @@ static struct pci_driver sil24_pci_driver = {
362 .name = DRV_NAME, 356 .name = DRV_NAME,
363 .id_table = sil24_pci_tbl, 357 .id_table = sil24_pci_tbl,
364 .probe = sil24_init_one, 358 .probe = sil24_init_one,
365 .remove = ata_pci_remove_one, /* safe? */ 359 .remove = ata_pci_remove_one,
366#ifdef CONFIG_PM 360#ifdef CONFIG_PM
367 .suspend = ata_pci_device_suspend, 361 .suspend = ata_pci_device_suspend,
368 .resume = sil24_pci_device_resume, 362 .resume = sil24_pci_device_resume,
@@ -406,6 +400,8 @@ static const struct ata_port_operations sil24_ops = {
406 400
407 .irq_handler = sil24_interrupt, 401 .irq_handler = sil24_interrupt,
408 .irq_clear = sil24_irq_clear, 402 .irq_clear = sil24_irq_clear,
403 .irq_on = ata_dummy_irq_on,
404 .irq_ack = ata_dummy_irq_ack,
409 405
410 .scr_read = sil24_scr_read, 406 .scr_read = sil24_scr_read,
411 .scr_write = sil24_scr_write, 407 .scr_write = sil24_scr_write,
@@ -416,8 +412,6 @@ static const struct ata_port_operations sil24_ops = {
416 .post_internal_cmd = sil24_post_internal_cmd, 412 .post_internal_cmd = sil24_post_internal_cmd,
417 413
418 .port_start = sil24_port_start, 414 .port_start = sil24_port_start,
419 .port_stop = sil24_port_stop,
420 .host_stop = sil24_host_stop,
421}; 415};
422 416
423/* 417/*
@@ -467,7 +461,7 @@ static int sil24_tag(int tag)
467 461
468static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev) 462static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev)
469{ 463{
470 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 464 void __iomem *port = ap->ioaddr.cmd_addr;
471 465
472 if (dev->cdb_len == 16) 466 if (dev->cdb_len == 16)
473 writel(PORT_CS_CDB16, port + PORT_CTRL_STAT); 467 writel(PORT_CS_CDB16, port + PORT_CTRL_STAT);
@@ -478,7 +472,7 @@ static void sil24_dev_config(struct ata_port *ap, struct ata_device *dev)
478static inline void sil24_update_tf(struct ata_port *ap) 472static inline void sil24_update_tf(struct ata_port *ap)
479{ 473{
480 struct sil24_port_priv *pp = ap->private_data; 474 struct sil24_port_priv *pp = ap->private_data;
481 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 475 void __iomem *port = ap->ioaddr.cmd_addr;
482 struct sil24_prb __iomem *prb = port; 476 struct sil24_prb __iomem *prb = port;
483 u8 fis[6 * 4]; 477 u8 fis[6 * 4];
484 478
@@ -501,7 +495,7 @@ static int sil24_scr_map[] = {
501 495
502static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg) 496static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg)
503{ 497{
504 void __iomem *scr_addr = (void __iomem *)ap->ioaddr.scr_addr; 498 void __iomem *scr_addr = ap->ioaddr.scr_addr;
505 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { 499 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
506 void __iomem *addr; 500 void __iomem *addr;
507 addr = scr_addr + sil24_scr_map[sc_reg] * 4; 501 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
@@ -512,7 +506,7 @@ static u32 sil24_scr_read(struct ata_port *ap, unsigned sc_reg)
512 506
513static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val) 507static void sil24_scr_write(struct ata_port *ap, unsigned sc_reg, u32 val)
514{ 508{
515 void __iomem *scr_addr = (void __iomem *)ap->ioaddr.scr_addr; 509 void __iomem *scr_addr = ap->ioaddr.scr_addr;
516 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) { 510 if (sc_reg < ARRAY_SIZE(sil24_scr_map)) {
517 void __iomem *addr; 511 void __iomem *addr;
518 addr = scr_addr + sil24_scr_map[sc_reg] * 4; 512 addr = scr_addr + sil24_scr_map[sc_reg] * 4;
@@ -528,7 +522,7 @@ static void sil24_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
528 522
529static int sil24_init_port(struct ata_port *ap) 523static int sil24_init_port(struct ata_port *ap)
530{ 524{
531 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 525 void __iomem *port = ap->ioaddr.cmd_addr;
532 u32 tmp; 526 u32 tmp;
533 527
534 writel(PORT_CS_INIT, port + PORT_CTRL_STAT); 528 writel(PORT_CS_INIT, port + PORT_CTRL_STAT);
@@ -544,7 +538,7 @@ static int sil24_init_port(struct ata_port *ap)
544 538
545static int sil24_softreset(struct ata_port *ap, unsigned int *class) 539static int sil24_softreset(struct ata_port *ap, unsigned int *class)
546{ 540{
547 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 541 void __iomem *port = ap->ioaddr.cmd_addr;
548 struct sil24_port_priv *pp = ap->private_data; 542 struct sil24_port_priv *pp = ap->private_data;
549 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb; 543 struct sil24_prb *prb = &pp->cmd_block[0].ata.prb;
550 dma_addr_t paddr = pp->cmd_block_dma; 544 dma_addr_t paddr = pp->cmd_block_dma;
@@ -604,7 +598,7 @@ static int sil24_softreset(struct ata_port *ap, unsigned int *class)
604 598
605static int sil24_hardreset(struct ata_port *ap, unsigned int *class) 599static int sil24_hardreset(struct ata_port *ap, unsigned int *class)
606{ 600{
607 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 601 void __iomem *port = ap->ioaddr.cmd_addr;
608 const char *reason; 602 const char *reason;
609 int tout_msec, rc; 603 int tout_msec, rc;
610 u32 tmp; 604 u32 tmp;
@@ -721,7 +715,7 @@ static unsigned int sil24_qc_issue(struct ata_queued_cmd *qc)
721{ 715{
722 struct ata_port *ap = qc->ap; 716 struct ata_port *ap = qc->ap;
723 struct sil24_port_priv *pp = ap->private_data; 717 struct sil24_port_priv *pp = ap->private_data;
724 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 718 void __iomem *port = ap->ioaddr.cmd_addr;
725 unsigned int tag = sil24_tag(qc->tag); 719 unsigned int tag = sil24_tag(qc->tag);
726 dma_addr_t paddr; 720 dma_addr_t paddr;
727 void __iomem *activate; 721 void __iomem *activate;
@@ -742,7 +736,7 @@ static void sil24_irq_clear(struct ata_port *ap)
742 736
743static void sil24_freeze(struct ata_port *ap) 737static void sil24_freeze(struct ata_port *ap)
744{ 738{
745 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 739 void __iomem *port = ap->ioaddr.cmd_addr;
746 740
747 /* Port-wide IRQ mask in HOST_CTRL doesn't really work, clear 741 /* Port-wide IRQ mask in HOST_CTRL doesn't really work, clear
748 * PORT_IRQ_ENABLE instead. 742 * PORT_IRQ_ENABLE instead.
@@ -752,7 +746,7 @@ static void sil24_freeze(struct ata_port *ap)
752 746
753static void sil24_thaw(struct ata_port *ap) 747static void sil24_thaw(struct ata_port *ap)
754{ 748{
755 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 749 void __iomem *port = ap->ioaddr.cmd_addr;
756 u32 tmp; 750 u32 tmp;
757 751
758 /* clear IRQ */ 752 /* clear IRQ */
@@ -765,7 +759,7 @@ static void sil24_thaw(struct ata_port *ap)
765 759
766static void sil24_error_intr(struct ata_port *ap) 760static void sil24_error_intr(struct ata_port *ap)
767{ 761{
768 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 762 void __iomem *port = ap->ioaddr.cmd_addr;
769 struct ata_eh_info *ehi = &ap->eh_info; 763 struct ata_eh_info *ehi = &ap->eh_info;
770 int freeze = 0; 764 int freeze = 0;
771 u32 irq_stat; 765 u32 irq_stat;
@@ -843,7 +837,7 @@ static void sil24_finish_qc(struct ata_queued_cmd *qc)
843 837
844static inline void sil24_host_intr(struct ata_port *ap) 838static inline void sil24_host_intr(struct ata_port *ap)
845{ 839{
846 void __iomem *port = (void __iomem *)ap->ioaddr.cmd_addr; 840 void __iomem *port = ap->ioaddr.cmd_addr;
847 u32 slot_stat, qc_active; 841 u32 slot_stat, qc_active;
848 int rc; 842 int rc;
849 843
@@ -878,12 +872,12 @@ static inline void sil24_host_intr(struct ata_port *ap)
878static irqreturn_t sil24_interrupt(int irq, void *dev_instance) 872static irqreturn_t sil24_interrupt(int irq, void *dev_instance)
879{ 873{
880 struct ata_host *host = dev_instance; 874 struct ata_host *host = dev_instance;
881 struct sil24_host_priv *hpriv = host->private_data; 875 void __iomem *host_base = host->iomap[SIL24_HOST_BAR];
882 unsigned handled = 0; 876 unsigned handled = 0;
883 u32 status; 877 u32 status;
884 int i; 878 int i;
885 879
886 status = readl(hpriv->host_base + HOST_IRQ_STAT); 880 status = readl(host_base + HOST_IRQ_STAT);
887 881
888 if (status == 0xffffffff) { 882 if (status == 0xffffffff) {
889 printk(KERN_ERR DRV_NAME ": IRQ status == 0xffffffff, " 883 printk(KERN_ERR DRV_NAME ": IRQ status == 0xffffffff, "
@@ -938,13 +932,6 @@ static void sil24_post_internal_cmd(struct ata_queued_cmd *qc)
938 sil24_init_port(ap); 932 sil24_init_port(ap);
939} 933}
940 934
941static inline void sil24_cblk_free(struct sil24_port_priv *pp, struct device *dev)
942{
943 const size_t cb_size = sizeof(*pp->cmd_block) * SIL24_MAX_CMDS;
944
945 dma_free_coherent(dev, cb_size, pp->cmd_block, pp->cmd_block_dma);
946}
947
948static int sil24_port_start(struct ata_port *ap) 935static int sil24_port_start(struct ata_port *ap)
949{ 936{
950 struct device *dev = ap->host->dev; 937 struct device *dev = ap->host->dev;
@@ -952,22 +939,22 @@ static int sil24_port_start(struct ata_port *ap)
952 union sil24_cmd_block *cb; 939 union sil24_cmd_block *cb;
953 size_t cb_size = sizeof(*cb) * SIL24_MAX_CMDS; 940 size_t cb_size = sizeof(*cb) * SIL24_MAX_CMDS;
954 dma_addr_t cb_dma; 941 dma_addr_t cb_dma;
955 int rc = -ENOMEM; 942 int rc;
956 943
957 pp = kzalloc(sizeof(*pp), GFP_KERNEL); 944 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
958 if (!pp) 945 if (!pp)
959 goto err_out; 946 return -ENOMEM;
960 947
961 pp->tf.command = ATA_DRDY; 948 pp->tf.command = ATA_DRDY;
962 949
963 cb = dma_alloc_coherent(dev, cb_size, &cb_dma, GFP_KERNEL); 950 cb = dmam_alloc_coherent(dev, cb_size, &cb_dma, GFP_KERNEL);
964 if (!cb) 951 if (!cb)
965 goto err_out_pp; 952 return -ENOMEM;
966 memset(cb, 0, cb_size); 953 memset(cb, 0, cb_size);
967 954
968 rc = ata_pad_alloc(ap, dev); 955 rc = ata_pad_alloc(ap, dev);
969 if (rc) 956 if (rc)
970 goto err_out_pad; 957 return rc;
971 958
972 pp->cmd_block = cb; 959 pp->cmd_block = cb;
973 pp->cmd_block_dma = cb_dma; 960 pp->cmd_block_dma = cb_dma;
@@ -975,33 +962,6 @@ static int sil24_port_start(struct ata_port *ap)
975 ap->private_data = pp; 962 ap->private_data = pp;
976 963
977 return 0; 964 return 0;
978
979err_out_pad:
980 sil24_cblk_free(pp, dev);
981err_out_pp:
982 kfree(pp);
983err_out:
984 return rc;
985}
986
987static void sil24_port_stop(struct ata_port *ap)
988{
989 struct device *dev = ap->host->dev;
990 struct sil24_port_priv *pp = ap->private_data;
991
992 sil24_cblk_free(pp, dev);
993 ata_pad_free(ap, dev);
994 kfree(pp);
995}
996
997static void sil24_host_stop(struct ata_host *host)
998{
999 struct sil24_host_priv *hpriv = host->private_data;
1000 struct pci_dev *pdev = to_pci_dev(host->dev);
1001
1002 pci_iounmap(pdev, hpriv->host_base);
1003 pci_iounmap(pdev, hpriv->port_base);
1004 kfree(hpriv);
1005} 965}
1006 966
1007static void sil24_init_controller(struct pci_dev *pdev, int n_ports, 967static void sil24_init_controller(struct pci_dev *pdev, int n_ports,
@@ -1066,43 +1026,32 @@ static void sil24_init_controller(struct pci_dev *pdev, int n_ports,
1066static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 1026static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1067{ 1027{
1068 static int printed_version = 0; 1028 static int printed_version = 0;
1029 struct device *dev = &pdev->dev;
1069 unsigned int board_id = (unsigned int)ent->driver_data; 1030 unsigned int board_id = (unsigned int)ent->driver_data;
1070 struct ata_port_info *pinfo = &sil24_port_info[board_id]; 1031 struct ata_port_info *pinfo = &sil24_port_info[board_id];
1071 struct ata_probe_ent *probe_ent = NULL; 1032 struct ata_probe_ent *probe_ent;
1072 struct sil24_host_priv *hpriv = NULL; 1033 void __iomem *host_base;
1073 void __iomem *host_base = NULL; 1034 void __iomem *port_base;
1074 void __iomem *port_base = NULL;
1075 int i, rc; 1035 int i, rc;
1076 u32 tmp; 1036 u32 tmp;
1077 1037
1078 if (!printed_version++) 1038 if (!printed_version++)
1079 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1039 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1080 1040
1081 rc = pci_enable_device(pdev); 1041 rc = pcim_enable_device(pdev);
1082 if (rc) 1042 if (rc)
1083 return rc; 1043 return rc;
1084 1044
1085 rc = pci_request_regions(pdev, DRV_NAME); 1045 rc = pcim_iomap_regions(pdev,
1046 (1 << SIL24_HOST_BAR) | (1 << SIL24_PORT_BAR),
1047 DRV_NAME);
1086 if (rc) 1048 if (rc)
1087 goto out_disable; 1049 return rc;
1088
1089 rc = -ENOMEM;
1090 /* map mmio registers */
1091 host_base = pci_iomap(pdev, 0, 0);
1092 if (!host_base)
1093 goto out_free;
1094 port_base = pci_iomap(pdev, 2, 0);
1095 if (!port_base)
1096 goto out_free;
1097
1098 /* allocate & init probe_ent and hpriv */
1099 probe_ent = kzalloc(sizeof(*probe_ent), GFP_KERNEL);
1100 if (!probe_ent)
1101 goto out_free;
1102 1050
1103 hpriv = kzalloc(sizeof(*hpriv), GFP_KERNEL); 1051 /* allocate & init probe_ent */
1104 if (!hpriv) 1052 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
1105 goto out_free; 1053 if (!probe_ent)
1054 return -ENOMEM;
1106 1055
1107 probe_ent->dev = pci_dev_to_dev(pdev); 1056 probe_ent->dev = pci_dev_to_dev(pdev);
1108 INIT_LIST_HEAD(&probe_ent->node); 1057 INIT_LIST_HEAD(&probe_ent->node);
@@ -1117,10 +1066,10 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1117 1066
1118 probe_ent->irq = pdev->irq; 1067 probe_ent->irq = pdev->irq;
1119 probe_ent->irq_flags = IRQF_SHARED; 1068 probe_ent->irq_flags = IRQF_SHARED;
1120 probe_ent->private_data = hpriv; 1069 probe_ent->iomap = pcim_iomap_table(pdev);
1121 1070
1122 hpriv->host_base = host_base; 1071 host_base = probe_ent->iomap[SIL24_HOST_BAR];
1123 hpriv->port_base = port_base; 1072 port_base = probe_ent->iomap[SIL24_PORT_BAR];
1124 1073
1125 /* 1074 /*
1126 * Configure the device 1075 * Configure the device
@@ -1132,7 +1081,7 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1132 if (rc) { 1081 if (rc) {
1133 dev_printk(KERN_ERR, &pdev->dev, 1082 dev_printk(KERN_ERR, &pdev->dev,
1134 "64-bit DMA enable failed\n"); 1083 "64-bit DMA enable failed\n");
1135 goto out_free; 1084 return rc;
1136 } 1085 }
1137 } 1086 }
1138 } else { 1087 } else {
@@ -1140,13 +1089,13 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1140 if (rc) { 1089 if (rc) {
1141 dev_printk(KERN_ERR, &pdev->dev, 1090 dev_printk(KERN_ERR, &pdev->dev,
1142 "32-bit DMA enable failed\n"); 1091 "32-bit DMA enable failed\n");
1143 goto out_free; 1092 return rc;
1144 } 1093 }
1145 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 1094 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
1146 if (rc) { 1095 if (rc) {
1147 dev_printk(KERN_ERR, &pdev->dev, 1096 dev_printk(KERN_ERR, &pdev->dev,
1148 "32-bit consistent DMA enable failed\n"); 1097 "32-bit consistent DMA enable failed\n");
1149 goto out_free; 1098 return rc;
1150 } 1099 }
1151 } 1100 }
1152 1101
@@ -1162,11 +1111,10 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1162 } 1111 }
1163 1112
1164 for (i = 0; i < probe_ent->n_ports; i++) { 1113 for (i = 0; i < probe_ent->n_ports; i++) {
1165 unsigned long portu = 1114 void __iomem *port = port_base + i * PORT_REGS_SIZE;
1166 (unsigned long)port_base + i * PORT_REGS_SIZE;
1167 1115
1168 probe_ent->port[i].cmd_addr = portu; 1116 probe_ent->port[i].cmd_addr = port;
1169 probe_ent->port[i].scr_addr = portu + PORT_SCONTROL; 1117 probe_ent->port[i].scr_addr = port + PORT_SCONTROL;
1170 1118
1171 ata_std_ports(&probe_ent->port[i]); 1119 ata_std_ports(&probe_ent->port[i]);
1172 } 1120 }
@@ -1176,38 +1124,30 @@ static int sil24_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1176 1124
1177 pci_set_master(pdev); 1125 pci_set_master(pdev);
1178 1126
1179 /* FIXME: check ata_device_add return value */ 1127 if (!ata_device_add(probe_ent))
1180 ata_device_add(probe_ent); 1128 return -ENODEV;
1181 1129
1182 kfree(probe_ent); 1130 devm_kfree(dev, probe_ent);
1183 return 0; 1131 return 0;
1184
1185 out_free:
1186 if (host_base)
1187 pci_iounmap(pdev, host_base);
1188 if (port_base)
1189 pci_iounmap(pdev, port_base);
1190 kfree(probe_ent);
1191 kfree(hpriv);
1192 pci_release_regions(pdev);
1193 out_disable:
1194 pci_disable_device(pdev);
1195 return rc;
1196} 1132}
1197 1133
1198#ifdef CONFIG_PM 1134#ifdef CONFIG_PM
1199static int sil24_pci_device_resume(struct pci_dev *pdev) 1135static int sil24_pci_device_resume(struct pci_dev *pdev)
1200{ 1136{
1201 struct ata_host *host = dev_get_drvdata(&pdev->dev); 1137 struct ata_host *host = dev_get_drvdata(&pdev->dev);
1202 struct sil24_host_priv *hpriv = host->private_data; 1138 void __iomem *host_base = host->iomap[SIL24_HOST_BAR];
1139 void __iomem *port_base = host->iomap[SIL24_PORT_BAR];
1140 int rc;
1203 1141
1204 ata_pci_device_do_resume(pdev); 1142 rc = ata_pci_device_do_resume(pdev);
1143 if (rc)
1144 return rc;
1205 1145
1206 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND) 1146 if (pdev->dev.power.power_state.event == PM_EVENT_SUSPEND)
1207 writel(HOST_CTRL_GLOBAL_RST, hpriv->host_base + HOST_CTRL); 1147 writel(HOST_CTRL_GLOBAL_RST, host_base + HOST_CTRL);
1208 1148
1209 sil24_init_controller(pdev, host->n_ports, host->ports[0]->flags, 1149 sil24_init_controller(pdev, host->n_ports, host->ports[0]->flags,
1210 hpriv->host_base, hpriv->port_base); 1150 host_base, port_base);
1211 1151
1212 ata_host_resume(host); 1152 ata_host_resume(host);
1213 1153
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index 9c25a1e9173..49c9e2bd706 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -40,9 +40,11 @@
40#include <linux/device.h> 40#include <linux/device.h>
41#include <scsi/scsi_host.h> 41#include <scsi/scsi_host.h>
42#include <linux/libata.h> 42#include <linux/libata.h>
43#include "libata.h"
43 44
45#undef DRV_NAME /* already defined in libata.h, for libata-core */
44#define DRV_NAME "sata_sis" 46#define DRV_NAME "sata_sis"
45#define DRV_VERSION "0.6" 47#define DRV_VERSION "0.7"
46 48
47enum { 49enum {
48 sis_180 = 0, 50 sis_180 = 0,
@@ -67,9 +69,12 @@ static u32 sis_scr_read (struct ata_port *ap, unsigned int sc_reg);
67static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 69static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
68 70
69static const struct pci_device_id sis_pci_tbl[] = { 71static const struct pci_device_id sis_pci_tbl[] = {
70 { PCI_VDEVICE(SI, 0x180), sis_180 }, 72 { PCI_VDEVICE(SI, 0x0180), sis_180 }, /* SiS 964/180 */
71 { PCI_VDEVICE(SI, 0x181), sis_180 }, 73 { PCI_VDEVICE(SI, 0x0181), sis_180 }, /* SiS 964/180 */
72 { PCI_VDEVICE(SI, 0x182), sis_180 }, 74 { PCI_VDEVICE(SI, 0x0182), sis_180 }, /* SiS 965/965L */
75 { PCI_VDEVICE(SI, 0x0183), sis_180 }, /* SiS 965/965L */
76 { PCI_VDEVICE(SI, 0x1182), sis_180 }, /* SiS 966/966L */
77 { PCI_VDEVICE(SI, 0x1183), sis_180 }, /* SiS 966/966L */
73 78
74 { } /* terminate list */ 79 { } /* terminate list */
75}; 80};
@@ -112,18 +117,18 @@ static const struct ata_port_operations sis_ops = {
112 .bmdma_status = ata_bmdma_status, 117 .bmdma_status = ata_bmdma_status,
113 .qc_prep = ata_qc_prep, 118 .qc_prep = ata_qc_prep,
114 .qc_issue = ata_qc_issue_prot, 119 .qc_issue = ata_qc_issue_prot,
115 .data_xfer = ata_pio_data_xfer, 120 .data_xfer = ata_data_xfer,
116 .freeze = ata_bmdma_freeze, 121 .freeze = ata_bmdma_freeze,
117 .thaw = ata_bmdma_thaw, 122 .thaw = ata_bmdma_thaw,
118 .error_handler = ata_bmdma_error_handler, 123 .error_handler = ata_bmdma_error_handler,
119 .post_internal_cmd = ata_bmdma_post_internal_cmd, 124 .post_internal_cmd = ata_bmdma_post_internal_cmd,
120 .irq_handler = ata_interrupt, 125 .irq_handler = ata_interrupt,
121 .irq_clear = ata_bmdma_irq_clear, 126 .irq_clear = ata_bmdma_irq_clear,
127 .irq_on = ata_irq_on,
128 .irq_ack = ata_irq_ack,
122 .scr_read = sis_scr_read, 129 .scr_read = sis_scr_read,
123 .scr_write = sis_scr_write, 130 .scr_write = sis_scr_write,
124 .port_start = ata_port_start, 131 .port_start = ata_port_start,
125 .port_stop = ata_port_stop,
126 .host_stop = ata_host_stop,
127}; 132};
128 133
129static struct ata_port_info sis_port_info = { 134static struct ata_port_info sis_port_info = {
@@ -135,31 +140,42 @@ static struct ata_port_info sis_port_info = {
135 .port_ops = &sis_ops, 140 .port_ops = &sis_ops,
136}; 141};
137 142
138
139MODULE_AUTHOR("Uwe Koziolek"); 143MODULE_AUTHOR("Uwe Koziolek");
140MODULE_DESCRIPTION("low-level driver for Silicon Integratad Systems SATA controller"); 144MODULE_DESCRIPTION("low-level driver for Silicon Integratad Systems SATA controller");
141MODULE_LICENSE("GPL"); 145MODULE_LICENSE("GPL");
142MODULE_DEVICE_TABLE(pci, sis_pci_tbl); 146MODULE_DEVICE_TABLE(pci, sis_pci_tbl);
143MODULE_VERSION(DRV_VERSION); 147MODULE_VERSION(DRV_VERSION);
144 148
145static unsigned int get_scr_cfg_addr(unsigned int port_no, unsigned int sc_reg, int device) 149static unsigned int get_scr_cfg_addr(struct ata_port *ap, unsigned int sc_reg)
146{ 150{
151 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
147 unsigned int addr = SIS_SCR_BASE + (4 * sc_reg); 152 unsigned int addr = SIS_SCR_BASE + (4 * sc_reg);
153 u8 pmr;
148 154
149 if (port_no) { 155 if (ap->port_no) {
150 if (device == 0x182) 156 switch (pdev->device) {
151 addr += SIS182_SATA1_OFS; 157 case 0x0180:
152 else 158 case 0x0181:
153 addr += SIS180_SATA1_OFS; 159 pci_read_config_byte(pdev, SIS_PMR, &pmr);
160 if ((pmr & SIS_PMR_COMBINED) == 0)
161 addr += SIS180_SATA1_OFS;
162 break;
163
164 case 0x0182:
165 case 0x0183:
166 case 0x1182:
167 case 0x1183:
168 addr += SIS182_SATA1_OFS;
169 break;
170 }
154 } 171 }
155
156 return addr; 172 return addr;
157} 173}
158 174
159static u32 sis_scr_cfg_read (struct ata_port *ap, unsigned int sc_reg) 175static u32 sis_scr_cfg_read (struct ata_port *ap, unsigned int sc_reg)
160{ 176{
161 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 177 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
162 unsigned int cfg_addr = get_scr_cfg_addr(ap->port_no, sc_reg, pdev->device); 178 unsigned int cfg_addr = get_scr_cfg_addr(ap, sc_reg);
163 u32 val, val2 = 0; 179 u32 val, val2 = 0;
164 u8 pmr; 180 u8 pmr;
165 181
@@ -170,26 +186,28 @@ static u32 sis_scr_cfg_read (struct ata_port *ap, unsigned int sc_reg)
170 186
171 pci_read_config_dword(pdev, cfg_addr, &val); 187 pci_read_config_dword(pdev, cfg_addr, &val);
172 188
173 if ((pdev->device == 0x182) || (pmr & SIS_PMR_COMBINED)) 189 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || (pdev->device == 0x1182) ||
190 (pdev->device == 0x1183) || (pmr & SIS_PMR_COMBINED))
174 pci_read_config_dword(pdev, cfg_addr+0x10, &val2); 191 pci_read_config_dword(pdev, cfg_addr+0x10, &val2);
175 192
176 return (val|val2) & 0xfffffffb; /* avoid problems with powerdowned ports */ 193 return (val|val2) & 0xfffffffb; /* avoid problems with powerdowned ports */
177} 194}
178 195
179static void sis_scr_cfg_write (struct ata_port *ap, unsigned int scr, u32 val) 196static void sis_scr_cfg_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
180{ 197{
181 struct pci_dev *pdev = to_pci_dev(ap->host->dev); 198 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
182 unsigned int cfg_addr = get_scr_cfg_addr(ap->port_no, scr, pdev->device); 199 unsigned int cfg_addr = get_scr_cfg_addr(ap, sc_reg);
183 u8 pmr; 200 u8 pmr;
184 201
185 if (scr == SCR_ERROR) /* doesn't exist in PCI cfg space */ 202 if (sc_reg == SCR_ERROR) /* doesn't exist in PCI cfg space */
186 return; 203 return;
187 204
188 pci_read_config_byte(pdev, SIS_PMR, &pmr); 205 pci_read_config_byte(pdev, SIS_PMR, &pmr);
189 206
190 pci_write_config_dword(pdev, cfg_addr, val); 207 pci_write_config_dword(pdev, cfg_addr, val);
191 208
192 if ((pdev->device == 0x182) || (pmr & SIS_PMR_COMBINED)) 209 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || (pdev->device == 0x1182) ||
210 (pdev->device == 0x1183) || (pmr & SIS_PMR_COMBINED))
193 pci_write_config_dword(pdev, cfg_addr+0x10, val); 211 pci_write_config_dword(pdev, cfg_addr+0x10, val);
194} 212}
195 213
@@ -207,10 +225,11 @@ static u32 sis_scr_read (struct ata_port *ap, unsigned int sc_reg)
207 225
208 pci_read_config_byte(pdev, SIS_PMR, &pmr); 226 pci_read_config_byte(pdev, SIS_PMR, &pmr);
209 227
210 val = inl(ap->ioaddr.scr_addr + (sc_reg * 4)); 228 val = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4));
211 229
212 if ((pdev->device == 0x182) || (pmr & SIS_PMR_COMBINED)) 230 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || (pdev->device == 0x1182) ||
213 val2 = inl(ap->ioaddr.scr_addr + (sc_reg * 4) + 0x10); 231 (pdev->device == 0x1183) || (pmr & SIS_PMR_COMBINED))
232 val2 = ioread32(ap->ioaddr.scr_addr + (sc_reg * 4) + 0x10);
214 233
215 return (val | val2) & 0xfffffffb; 234 return (val | val2) & 0xfffffffb;
216} 235}
@@ -228,9 +247,10 @@ static void sis_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
228 if (ap->flags & SIS_FLAG_CFGSCR) 247 if (ap->flags & SIS_FLAG_CFGSCR)
229 sis_scr_cfg_write(ap, sc_reg, val); 248 sis_scr_cfg_write(ap, sc_reg, val);
230 else { 249 else {
231 outl(val, ap->ioaddr.scr_addr + (sc_reg * 4)); 250 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4));
232 if ((pdev->device == 0x182) || (pmr & SIS_PMR_COMBINED)) 251 if ((pdev->device == 0x0182) || (pdev->device == 0x0183) || (pdev->device == 0x1182) ||
233 outl(val, ap->ioaddr.scr_addr + (sc_reg * 4)+0x10); 252 (pdev->device == 0x1183) || (pmr & SIS_PMR_COMBINED))
253 iowrite32(val, ap->ioaddr.scr_addr + (sc_reg * 4)+0x10);
234 } 254 }
235} 255}
236 256
@@ -241,29 +261,28 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
241 int rc; 261 int rc;
242 u32 genctl, val; 262 u32 genctl, val;
243 struct ata_port_info pi = sis_port_info, *ppi[2] = { &pi, &pi }; 263 struct ata_port_info pi = sis_port_info, *ppi[2] = { &pi, &pi };
244 int pci_dev_busy = 0;
245 u8 pmr; 264 u8 pmr;
246 u8 port2_start; 265 u8 port2_start = 0x20;
247 266
248 if (!printed_version++) 267 if (!printed_version++)
249 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 268 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
250 269
251 rc = pci_enable_device(pdev); 270 rc = pcim_enable_device(pdev);
252 if (rc) 271 if (rc)
253 return rc; 272 return rc;
254 273
255 rc = pci_request_regions(pdev, DRV_NAME); 274 rc = pci_request_regions(pdev, DRV_NAME);
256 if (rc) { 275 if (rc) {
257 pci_dev_busy = 1; 276 pcim_pin_device(pdev);
258 goto err_out; 277 return rc;
259 } 278 }
260 279
261 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 280 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
262 if (rc) 281 if (rc)
263 goto err_out_regions; 282 return rc;
264 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 283 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
265 if (rc) 284 if (rc)
266 goto err_out_regions; 285 return rc;
267 286
268 /* check and see if the SCRs are in IO space or PCI cfg space */ 287 /* check and see if the SCRs are in IO space or PCI cfg space */
269 pci_read_config_dword(pdev, SIS_GENCTL, &genctl); 288 pci_read_config_dword(pdev, SIS_GENCTL, &genctl);
@@ -282,60 +301,79 @@ static int sis_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
282 } 301 }
283 302
284 pci_read_config_byte(pdev, SIS_PMR, &pmr); 303 pci_read_config_byte(pdev, SIS_PMR, &pmr);
285 if (ent->device != 0x182) { 304 switch (ent->device) {
305 case 0x0180:
306 case 0x0181:
307
308 /* The PATA-handling is provided by pata_sis */
309 switch (pmr & 0x30) {
310 case 0x10:
311 ppi[1] = &sis_info133;
312 break;
313
314 case 0x30:
315 ppi[0] = &sis_info133;
316 break;
317 }
286 if ((pmr & SIS_PMR_COMBINED) == 0) { 318 if ((pmr & SIS_PMR_COMBINED) == 0) {
287 dev_printk(KERN_INFO, &pdev->dev, 319 dev_printk(KERN_INFO, &pdev->dev,
288 "Detected SiS 180/181/964 chipset in SATA mode\n"); 320 "Detected SiS 180/181/964 chipset in SATA mode\n");
289 port2_start = 64; 321 port2_start = 64;
290 } 322 } else {
291 else {
292 dev_printk(KERN_INFO, &pdev->dev, 323 dev_printk(KERN_INFO, &pdev->dev,
293 "Detected SiS 180/181 chipset in combined mode\n"); 324 "Detected SiS 180/181 chipset in combined mode\n");
294 port2_start=0; 325 port2_start=0;
295 pi.flags |= ATA_FLAG_SLAVE_POSS; 326 pi.flags |= ATA_FLAG_SLAVE_POSS;
296 } 327 }
297 } 328 break;
298 else { 329
330 case 0x0182:
331 case 0x0183:
299 pci_read_config_dword ( pdev, 0x6C, &val); 332 pci_read_config_dword ( pdev, 0x6C, &val);
300 if (val & (1L << 31)) { 333 if (val & (1L << 31)) {
301 dev_printk(KERN_INFO, &pdev->dev, "Detected SiS 182/965 chipset\n"); 334 dev_printk(KERN_INFO, &pdev->dev, "Detected SiS 182/965 chipset\n");
302 pi.flags |= ATA_FLAG_SLAVE_POSS; 335 pi.flags |= ATA_FLAG_SLAVE_POSS;
303 } 336 } else {
304 else
305 dev_printk(KERN_INFO, &pdev->dev, "Detected SiS 182/965L chipset\n"); 337 dev_printk(KERN_INFO, &pdev->dev, "Detected SiS 182/965L chipset\n");
306 port2_start = 0x20; 338 }
339 break;
340
341 case 0x1182:
342 case 0x1183:
343 pci_read_config_dword(pdev, 0x64, &val);
344 if (val & 0x10000000) {
345 dev_printk(KERN_INFO, &pdev->dev, "Detected SiS 1182/1183/966L SATA controller\n");
346 } else {
347 dev_printk(KERN_INFO, &pdev->dev, "Detected SiS 1182/1183/966 SATA controller\n");
348 pi.flags |= ATA_FLAG_SLAVE_POSS;
349 }
350 break;
307 } 351 }
308 352
309 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 353 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
310 if (!probe_ent) { 354 if (!probe_ent)
311 rc = -ENOMEM; 355 return -ENOMEM;
312 goto err_out_regions;
313 }
314 356
315 if (!(probe_ent->port_flags & SIS_FLAG_CFGSCR)) { 357 if (!(probe_ent->port_flags & SIS_FLAG_CFGSCR)) {
316 probe_ent->port[0].scr_addr = 358 void *mmio;
317 pci_resource_start(pdev, SIS_SCR_PCI_BAR); 359
318 probe_ent->port[1].scr_addr = 360 mmio = pcim_iomap(pdev, SIS_SCR_PCI_BAR, 0);
319 pci_resource_start(pdev, SIS_SCR_PCI_BAR) + port2_start; 361 if (!mmio)
362 return -ENOMEM;
363
364 probe_ent->port[0].scr_addr = mmio;
365 probe_ent->port[1].scr_addr = mmio + port2_start;
320 } 366 }
321 367
322 pci_set_master(pdev); 368 pci_set_master(pdev);
323 pci_intx(pdev, 1); 369 pci_intx(pdev, 1);
324 370
325 /* FIXME: check ata_device_add return value */ 371 if (!ata_device_add(probe_ent))
326 ata_device_add(probe_ent); 372 return -EIO;
327 kfree(probe_ent);
328 373
374 devm_kfree(&pdev->dev, probe_ent);
329 return 0; 375 return 0;
330 376
331err_out_regions:
332 pci_release_regions(pdev);
333
334err_out:
335 if (!pci_dev_busy)
336 pci_disable_device(pdev);
337 return rc;
338
339} 377}
340 378
341static int __init sis_init(void) 379static int __init sis_init(void)
@@ -350,4 +388,3 @@ static void __exit sis_exit(void)
350 388
351module_init(sis_init); 389module_init(sis_init);
352module_exit(sis_exit); 390module_exit(sis_exit);
353
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index 5f4e82ade6c..4e428999420 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -135,31 +135,31 @@ static void k2_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
135 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR; 135 unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
136 136
137 if (tf->ctl != ap->last_ctl) { 137 if (tf->ctl != ap->last_ctl) {
138 writeb(tf->ctl, (void __iomem *) ioaddr->ctl_addr); 138 writeb(tf->ctl, ioaddr->ctl_addr);
139 ap->last_ctl = tf->ctl; 139 ap->last_ctl = tf->ctl;
140 ata_wait_idle(ap); 140 ata_wait_idle(ap);
141 } 141 }
142 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { 142 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
143 writew(tf->feature | (((u16)tf->hob_feature) << 8), 143 writew(tf->feature | (((u16)tf->hob_feature) << 8),
144 (void __iomem *) ioaddr->feature_addr); 144 ioaddr->feature_addr);
145 writew(tf->nsect | (((u16)tf->hob_nsect) << 8), 145 writew(tf->nsect | (((u16)tf->hob_nsect) << 8),
146 (void __iomem *) ioaddr->nsect_addr); 146 ioaddr->nsect_addr);
147 writew(tf->lbal | (((u16)tf->hob_lbal) << 8), 147 writew(tf->lbal | (((u16)tf->hob_lbal) << 8),
148 (void __iomem *) ioaddr->lbal_addr); 148 ioaddr->lbal_addr);
149 writew(tf->lbam | (((u16)tf->hob_lbam) << 8), 149 writew(tf->lbam | (((u16)tf->hob_lbam) << 8),
150 (void __iomem *) ioaddr->lbam_addr); 150 ioaddr->lbam_addr);
151 writew(tf->lbah | (((u16)tf->hob_lbah) << 8), 151 writew(tf->lbah | (((u16)tf->hob_lbah) << 8),
152 (void __iomem *) ioaddr->lbah_addr); 152 ioaddr->lbah_addr);
153 } else if (is_addr) { 153 } else if (is_addr) {
154 writew(tf->feature, (void __iomem *) ioaddr->feature_addr); 154 writew(tf->feature, ioaddr->feature_addr);
155 writew(tf->nsect, (void __iomem *) ioaddr->nsect_addr); 155 writew(tf->nsect, ioaddr->nsect_addr);
156 writew(tf->lbal, (void __iomem *) ioaddr->lbal_addr); 156 writew(tf->lbal, ioaddr->lbal_addr);
157 writew(tf->lbam, (void __iomem *) ioaddr->lbam_addr); 157 writew(tf->lbam, ioaddr->lbam_addr);
158 writew(tf->lbah, (void __iomem *) ioaddr->lbah_addr); 158 writew(tf->lbah, ioaddr->lbah_addr);
159 } 159 }
160 160
161 if (tf->flags & ATA_TFLAG_DEVICE) 161 if (tf->flags & ATA_TFLAG_DEVICE)
162 writeb(tf->device, (void __iomem *) ioaddr->device_addr); 162 writeb(tf->device, ioaddr->device_addr);
163 163
164 ata_wait_idle(ap); 164 ata_wait_idle(ap);
165} 165}
@@ -171,12 +171,12 @@ static void k2_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
171 u16 nsect, lbal, lbam, lbah, feature; 171 u16 nsect, lbal, lbam, lbah, feature;
172 172
173 tf->command = k2_stat_check_status(ap); 173 tf->command = k2_stat_check_status(ap);
174 tf->device = readw((void __iomem *)ioaddr->device_addr); 174 tf->device = readw(ioaddr->device_addr);
175 feature = readw((void __iomem *)ioaddr->error_addr); 175 feature = readw(ioaddr->error_addr);
176 nsect = readw((void __iomem *)ioaddr->nsect_addr); 176 nsect = readw(ioaddr->nsect_addr);
177 lbal = readw((void __iomem *)ioaddr->lbal_addr); 177 lbal = readw(ioaddr->lbal_addr);
178 lbam = readw((void __iomem *)ioaddr->lbam_addr); 178 lbam = readw(ioaddr->lbam_addr);
179 lbah = readw((void __iomem *)ioaddr->lbah_addr); 179 lbah = readw(ioaddr->lbah_addr);
180 180
181 tf->feature = feature; 181 tf->feature = feature;
182 tf->nsect = nsect; 182 tf->nsect = nsect;
@@ -349,21 +349,21 @@ static const struct ata_port_operations k2_sata_ops = {
349 .bmdma_status = ata_bmdma_status, 349 .bmdma_status = ata_bmdma_status,
350 .qc_prep = ata_qc_prep, 350 .qc_prep = ata_qc_prep,
351 .qc_issue = ata_qc_issue_prot, 351 .qc_issue = ata_qc_issue_prot,
352 .data_xfer = ata_mmio_data_xfer, 352 .data_xfer = ata_data_xfer,
353 .freeze = ata_bmdma_freeze, 353 .freeze = ata_bmdma_freeze,
354 .thaw = ata_bmdma_thaw, 354 .thaw = ata_bmdma_thaw,
355 .error_handler = ata_bmdma_error_handler, 355 .error_handler = ata_bmdma_error_handler,
356 .post_internal_cmd = ata_bmdma_post_internal_cmd, 356 .post_internal_cmd = ata_bmdma_post_internal_cmd,
357 .irq_handler = ata_interrupt, 357 .irq_handler = ata_interrupt,
358 .irq_clear = ata_bmdma_irq_clear, 358 .irq_clear = ata_bmdma_irq_clear,
359 .irq_on = ata_irq_on,
360 .irq_ack = ata_irq_ack,
359 .scr_read = k2_sata_scr_read, 361 .scr_read = k2_sata_scr_read,
360 .scr_write = k2_sata_scr_write, 362 .scr_write = k2_sata_scr_write,
361 .port_start = ata_port_start, 363 .port_start = ata_port_start,
362 .port_stop = ata_port_stop,
363 .host_stop = ata_pci_host_stop,
364}; 364};
365 365
366static void k2_sata_setup_port(struct ata_ioports *port, unsigned long base) 366static void k2_sata_setup_port(struct ata_ioports *port, void __iomem *base)
367{ 367{
368 port->cmd_addr = base + K2_SATA_TF_CMD_OFFSET; 368 port->cmd_addr = base + K2_SATA_TF_CMD_OFFSET;
369 port->data_addr = base + K2_SATA_TF_DATA_OFFSET; 369 port->data_addr = base + K2_SATA_TF_DATA_OFFSET;
@@ -386,12 +386,11 @@ static void k2_sata_setup_port(struct ata_ioports *port, unsigned long base)
386static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 386static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
387{ 387{
388 static int printed_version; 388 static int printed_version;
389 struct ata_probe_ent *probe_ent = NULL; 389 struct device *dev = &pdev->dev;
390 unsigned long base; 390 struct ata_probe_ent *probe_ent;
391 void __iomem *mmio_base; 391 void __iomem *mmio_base;
392 const struct k2_board_info *board_info = 392 const struct k2_board_info *board_info =
393 &k2_board_info[ent->driver_data]; 393 &k2_board_info[ent->driver_data];
394 int pci_dev_busy = 0;
395 int rc; 394 int rc;
396 int i; 395 int i;
397 396
@@ -402,7 +401,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
402 * If this driver happens to only be useful on Apple's K2, then 401 * If this driver happens to only be useful on Apple's K2, then
403 * we should check that here as it has a normal Serverworks ID 402 * we should check that here as it has a normal Serverworks ID
404 */ 403 */
405 rc = pci_enable_device(pdev); 404 rc = pcim_enable_device(pdev);
406 if (rc) 405 if (rc)
407 return rc; 406 return rc;
408 /* 407 /*
@@ -412,48 +411,27 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
412 if (pci_resource_len(pdev, 5) == 0) 411 if (pci_resource_len(pdev, 5) == 0)
413 return -ENODEV; 412 return -ENODEV;
414 413
415 /* Request PCI regions */ 414 /* Request and iomap PCI regions */
416 rc = pci_request_regions(pdev, DRV_NAME); 415 rc = pcim_iomap_regions(pdev, 1 << 5, DRV_NAME);
417 if (rc) { 416 if (rc == -EBUSY)
418 pci_dev_busy = 1; 417 pcim_pin_device(pdev);
419 goto err_out; 418 if (rc)
420 } 419 return rc;
421 420
422 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 421 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
423 if (rc) 422 if (rc)
424 goto err_out_regions; 423 return rc;
425 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 424 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
426 if (rc) 425 if (rc)
427 goto err_out_regions; 426 return rc;
428 427
429 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 428 probe_ent = devm_kzalloc(dev, sizeof(*probe_ent), GFP_KERNEL);
430 if (probe_ent == NULL) { 429 if (probe_ent == NULL)
431 rc = -ENOMEM; 430 return -ENOMEM;
432 goto err_out_regions;
433 }
434 431
435 memset(probe_ent, 0, sizeof(*probe_ent));
436 probe_ent->dev = pci_dev_to_dev(pdev); 432 probe_ent->dev = pci_dev_to_dev(pdev);
437 INIT_LIST_HEAD(&probe_ent->node); 433 INIT_LIST_HEAD(&probe_ent->node);
438 434
439 mmio_base = pci_iomap(pdev, 5, 0);
440 if (mmio_base == NULL) {
441 rc = -ENOMEM;
442 goto err_out_free_ent;
443 }
444 base = (unsigned long) mmio_base;
445
446 /* Clear a magic bit in SCR1 according to Darwin, those help
447 * some funky seagate drives (though so far, those were already
448 * set by the firmware on the machines I had access to)
449 */
450 writel(readl(mmio_base + K2_SATA_SICR1_OFFSET) & ~0x00040000,
451 mmio_base + K2_SATA_SICR1_OFFSET);
452
453 /* Clear SATA error & interrupts we don't use */
454 writel(0xffffffff, mmio_base + K2_SATA_SCR_ERROR_OFFSET);
455 writel(0x0, mmio_base + K2_SATA_SIM_OFFSET);
456
457 probe_ent->sht = &k2_sata_sht; 435 probe_ent->sht = &k2_sata_sht;
458 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 436 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
459 ATA_FLAG_MMIO | board_info->port_flags; 437 ATA_FLAG_MMIO | board_info->port_flags;
@@ -461,7 +439,7 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
461 probe_ent->n_ports = 4; 439 probe_ent->n_ports = 4;
462 probe_ent->irq = pdev->irq; 440 probe_ent->irq = pdev->irq;
463 probe_ent->irq_flags = IRQF_SHARED; 441 probe_ent->irq_flags = IRQF_SHARED;
464 probe_ent->mmio_base = mmio_base; 442 probe_ent->iomap = pcim_iomap_table(pdev);
465 443
466 /* We don't care much about the PIO/UDMA masks, but the core won't like us 444 /* We don't care much about the PIO/UDMA masks, but the core won't like us
467 * if we don't fill these 445 * if we don't fill these
@@ -470,28 +448,33 @@ static int k2_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *e
470 probe_ent->mwdma_mask = 0x7; 448 probe_ent->mwdma_mask = 0x7;
471 probe_ent->udma_mask = 0x7f; 449 probe_ent->udma_mask = 0x7f;
472 450
451 mmio_base = probe_ent->iomap[5];
452
473 /* different controllers have different number of ports - currently 4 or 8 */ 453 /* different controllers have different number of ports - currently 4 or 8 */
474 /* All ports are on the same function. Multi-function device is no 454 /* All ports are on the same function. Multi-function device is no
475 * longer available. This should not be seen in any system. */ 455 * longer available. This should not be seen in any system. */
476 for (i = 0; i < board_info->n_ports; i++) 456 for (i = 0; i < board_info->n_ports; i++)
477 k2_sata_setup_port(&probe_ent->port[i], base + i * K2_SATA_PORT_OFFSET); 457 k2_sata_setup_port(&probe_ent->port[i],
458 mmio_base + i * K2_SATA_PORT_OFFSET);
459
460 /* Clear a magic bit in SCR1 according to Darwin, those help
461 * some funky seagate drives (though so far, those were already
462 * set by the firmware on the machines I had access to)
463 */
464 writel(readl(mmio_base + K2_SATA_SICR1_OFFSET) & ~0x00040000,
465 mmio_base + K2_SATA_SICR1_OFFSET);
466
467 /* Clear SATA error & interrupts we don't use */
468 writel(0xffffffff, mmio_base + K2_SATA_SCR_ERROR_OFFSET);
469 writel(0x0, mmio_base + K2_SATA_SIM_OFFSET);
478 470
479 pci_set_master(pdev); 471 pci_set_master(pdev);
480 472
481 /* FIXME: check ata_device_add return value */ 473 if (!ata_device_add(probe_ent))
482 ata_device_add(probe_ent); 474 return -ENODEV;
483 kfree(probe_ent);
484 475
476 devm_kfree(dev, probe_ent);
485 return 0; 477 return 0;
486
487err_out_free_ent:
488 kfree(probe_ent);
489err_out_regions:
490 pci_release_regions(pdev);
491err_out:
492 if (!pci_dev_busy)
493 pci_disable_device(pdev);
494 return rc;
495} 478}
496 479
497/* 0x240 is device ID for Apple K2 device 480/* 0x240 is device ID for Apple K2 device
diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
index ae7992de4b0..06e87a37738 100644
--- a/drivers/ata/sata_sx4.c
+++ b/drivers/ata/sata_sx4.c
@@ -42,7 +42,6 @@
42#include <scsi/scsi_host.h> 42#include <scsi/scsi_host.h>
43#include <scsi/scsi_cmnd.h> 43#include <scsi/scsi_cmnd.h>
44#include <linux/libata.h> 44#include <linux/libata.h>
45#include <asm/io.h>
46#include "sata_promise.h" 45#include "sata_promise.h"
47 46
48#define DRV_NAME "sata_sx4" 47#define DRV_NAME "sata_sx4"
@@ -50,6 +49,9 @@
50 49
51 50
52enum { 51enum {
52 PDC_MMIO_BAR = 3,
53 PDC_DIMM_BAR = 4,
54
53 PDC_PRD_TBL = 0x44, /* Direct command DMA table addr */ 55 PDC_PRD_TBL = 0x44, /* Direct command DMA table addr */
54 56
55 PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */ 57 PDC_PKT_SUBMIT = 0x40, /* Command packet pointer addr */
@@ -138,8 +140,6 @@ struct pdc_port_priv {
138}; 140};
139 141
140struct pdc_host_priv { 142struct pdc_host_priv {
141 void __iomem *dimm_mmio;
142
143 unsigned int doing_hdma; 143 unsigned int doing_hdma;
144 unsigned int hdma_prod; 144 unsigned int hdma_prod;
145 unsigned int hdma_cons; 145 unsigned int hdma_cons;
@@ -156,11 +156,9 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance);
156static void pdc_eng_timeout(struct ata_port *ap); 156static void pdc_eng_timeout(struct ata_port *ap);
157static void pdc_20621_phy_reset (struct ata_port *ap); 157static void pdc_20621_phy_reset (struct ata_port *ap);
158static int pdc_port_start(struct ata_port *ap); 158static int pdc_port_start(struct ata_port *ap);
159static void pdc_port_stop(struct ata_port *ap);
160static void pdc20621_qc_prep(struct ata_queued_cmd *qc); 159static void pdc20621_qc_prep(struct ata_queued_cmd *qc);
161static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 160static void pdc_tf_load_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
162static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf); 161static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile *tf);
163static void pdc20621_host_stop(struct ata_host *host);
164static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe); 162static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe);
165static int pdc20621_detect_dimm(struct ata_probe_ent *pe); 163static int pdc20621_detect_dimm(struct ata_probe_ent *pe);
166static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe, 164static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe,
@@ -205,13 +203,13 @@ static const struct ata_port_operations pdc_20621_ops = {
205 .phy_reset = pdc_20621_phy_reset, 203 .phy_reset = pdc_20621_phy_reset,
206 .qc_prep = pdc20621_qc_prep, 204 .qc_prep = pdc20621_qc_prep,
207 .qc_issue = pdc20621_qc_issue_prot, 205 .qc_issue = pdc20621_qc_issue_prot,
208 .data_xfer = ata_mmio_data_xfer, 206 .data_xfer = ata_data_xfer,
209 .eng_timeout = pdc_eng_timeout, 207 .eng_timeout = pdc_eng_timeout,
210 .irq_handler = pdc20621_interrupt, 208 .irq_handler = pdc20621_interrupt,
211 .irq_clear = pdc20621_irq_clear, 209 .irq_clear = pdc20621_irq_clear,
210 .irq_on = ata_irq_on,
211 .irq_ack = ata_irq_ack,
212 .port_start = pdc_port_start, 212 .port_start = pdc_port_start,
213 .port_stop = pdc_port_stop,
214 .host_stop = pdc20621_host_stop,
215}; 213};
216 214
217static const struct ata_port_info pdc_port_info[] = { 215static const struct ata_port_info pdc_port_info[] = {
@@ -243,18 +241,6 @@ static struct pci_driver pdc_sata_pci_driver = {
243}; 241};
244 242
245 243
246static void pdc20621_host_stop(struct ata_host *host)
247{
248 struct pci_dev *pdev = to_pci_dev(host->dev);
249 struct pdc_host_priv *hpriv = host->private_data;
250 void __iomem *dimm_mmio = hpriv->dimm_mmio;
251
252 pci_iounmap(pdev, dimm_mmio);
253 kfree(hpriv);
254
255 pci_iounmap(pdev, host->mmio_base);
256}
257
258static int pdc_port_start(struct ata_port *ap) 244static int pdc_port_start(struct ata_port *ap)
259{ 245{
260 struct device *dev = ap->host->dev; 246 struct device *dev = ap->host->dev;
@@ -265,43 +251,19 @@ static int pdc_port_start(struct ata_port *ap)
265 if (rc) 251 if (rc)
266 return rc; 252 return rc;
267 253
268 pp = kmalloc(sizeof(*pp), GFP_KERNEL); 254 pp = devm_kzalloc(dev, sizeof(*pp), GFP_KERNEL);
269 if (!pp) { 255 if (!pp)
270 rc = -ENOMEM; 256 return -ENOMEM;
271 goto err_out;
272 }
273 memset(pp, 0, sizeof(*pp));
274 257
275 pp->pkt = dma_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL); 258 pp->pkt = dmam_alloc_coherent(dev, 128, &pp->pkt_dma, GFP_KERNEL);
276 if (!pp->pkt) { 259 if (!pp->pkt)
277 rc = -ENOMEM; 260 return -ENOMEM;
278 goto err_out_kfree;
279 }
280 261
281 ap->private_data = pp; 262 ap->private_data = pp;
282 263
283 return 0; 264 return 0;
284
285err_out_kfree:
286 kfree(pp);
287err_out:
288 ata_port_stop(ap);
289 return rc;
290}
291
292
293static void pdc_port_stop(struct ata_port *ap)
294{
295 struct device *dev = ap->host->dev;
296 struct pdc_port_priv *pp = ap->private_data;
297
298 ap->private_data = NULL;
299 dma_free_coherent(dev, 128, pp->pkt, pp->pkt_dma);
300 kfree(pp);
301 ata_port_stop(ap);
302} 265}
303 266
304
305static void pdc_20621_phy_reset (struct ata_port *ap) 267static void pdc_20621_phy_reset (struct ata_port *ap)
306{ 268{
307 VPRINTK("ENTER\n"); 269 VPRINTK("ENTER\n");
@@ -452,9 +414,8 @@ static void pdc20621_dma_prep(struct ata_queued_cmd *qc)
452 struct scatterlist *sg; 414 struct scatterlist *sg;
453 struct ata_port *ap = qc->ap; 415 struct ata_port *ap = qc->ap;
454 struct pdc_port_priv *pp = ap->private_data; 416 struct pdc_port_priv *pp = ap->private_data;
455 void __iomem *mmio = ap->host->mmio_base; 417 void __iomem *mmio = ap->host->iomap[PDC_MMIO_BAR];
456 struct pdc_host_priv *hpriv = ap->host->private_data; 418 void __iomem *dimm_mmio = ap->host->iomap[PDC_DIMM_BAR];
457 void __iomem *dimm_mmio = hpriv->dimm_mmio;
458 unsigned int portno = ap->port_no; 419 unsigned int portno = ap->port_no;
459 unsigned int i, idx, total_len = 0, sgt_len; 420 unsigned int i, idx, total_len = 0, sgt_len;
460 u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ]; 421 u32 *buf = (u32 *) &pp->dimm_buf[PDC_DIMM_HEADER_SZ];
@@ -513,9 +474,8 @@ static void pdc20621_nodata_prep(struct ata_queued_cmd *qc)
513{ 474{
514 struct ata_port *ap = qc->ap; 475 struct ata_port *ap = qc->ap;
515 struct pdc_port_priv *pp = ap->private_data; 476 struct pdc_port_priv *pp = ap->private_data;
516 void __iomem *mmio = ap->host->mmio_base; 477 void __iomem *mmio = ap->host->iomap[PDC_MMIO_BAR];
517 struct pdc_host_priv *hpriv = ap->host->private_data; 478 void __iomem *dimm_mmio = ap->host->iomap[PDC_DIMM_BAR];
518 void __iomem *dimm_mmio = hpriv->dimm_mmio;
519 unsigned int portno = ap->port_no; 479 unsigned int portno = ap->port_no;
520 unsigned int i; 480 unsigned int i;
521 481
@@ -565,7 +525,7 @@ static void __pdc20621_push_hdma(struct ata_queued_cmd *qc,
565{ 525{
566 struct ata_port *ap = qc->ap; 526 struct ata_port *ap = qc->ap;
567 struct ata_host *host = ap->host; 527 struct ata_host *host = ap->host;
568 void __iomem *mmio = host->mmio_base; 528 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
569 529
570 /* hard-code chip #0 */ 530 /* hard-code chip #0 */
571 mmio += PDC_CHIP0_OFS; 531 mmio += PDC_CHIP0_OFS;
@@ -619,8 +579,7 @@ static void pdc20621_dump_hdma(struct ata_queued_cmd *qc)
619{ 579{
620 struct ata_port *ap = qc->ap; 580 struct ata_port *ap = qc->ap;
621 unsigned int port_no = ap->port_no; 581 unsigned int port_no = ap->port_no;
622 struct pdc_host_priv *hpriv = ap->host->private_data; 582 void __iomem *dimm_mmio = ap->host->iomap[PDC_DIMM_BAR];
623 void *dimm_mmio = hpriv->dimm_mmio;
624 583
625 dimm_mmio += (port_no * PDC_DIMM_WINDOW_STEP); 584 dimm_mmio += (port_no * PDC_DIMM_WINDOW_STEP);
626 dimm_mmio += PDC_DIMM_HOST_PKT; 585 dimm_mmio += PDC_DIMM_HOST_PKT;
@@ -639,7 +598,7 @@ static void pdc20621_packet_start(struct ata_queued_cmd *qc)
639 struct ata_port *ap = qc->ap; 598 struct ata_port *ap = qc->ap;
640 struct ata_host *host = ap->host; 599 struct ata_host *host = ap->host;
641 unsigned int port_no = ap->port_no; 600 unsigned int port_no = ap->port_no;
642 void __iomem *mmio = host->mmio_base; 601 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
643 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE); 602 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
644 u8 seq = (u8) (port_no + 1); 603 u8 seq = (u8) (port_no + 1);
645 unsigned int port_ofs; 604 unsigned int port_ofs;
@@ -668,8 +627,8 @@ static void pdc20621_packet_start(struct ata_queued_cmd *qc)
668 readl(mmio + PDC_20621_SEQCTL + (seq * 4)); /* flush */ 627 readl(mmio + PDC_20621_SEQCTL + (seq * 4)); /* flush */
669 628
670 writel(port_ofs + PDC_DIMM_ATA_PKT, 629 writel(port_ofs + PDC_DIMM_ATA_PKT,
671 (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 630 ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
672 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 631 readl(ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
673 VPRINTK("submitted ofs 0x%x (%u), seq %u\n", 632 VPRINTK("submitted ofs 0x%x (%u), seq %u\n",
674 port_ofs + PDC_DIMM_ATA_PKT, 633 port_ofs + PDC_DIMM_ATA_PKT,
675 port_ofs + PDC_DIMM_ATA_PKT, 634 port_ofs + PDC_DIMM_ATA_PKT,
@@ -747,8 +706,8 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
747 writel(0x00000001, mmio + PDC_20621_SEQCTL + (seq * 4)); 706 writel(0x00000001, mmio + PDC_20621_SEQCTL + (seq * 4));
748 readl(mmio + PDC_20621_SEQCTL + (seq * 4)); 707 readl(mmio + PDC_20621_SEQCTL + (seq * 4));
749 writel(port_ofs + PDC_DIMM_ATA_PKT, 708 writel(port_ofs + PDC_DIMM_ATA_PKT,
750 (void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 709 ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
751 readl((void __iomem *) ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT); 710 readl(ap->ioaddr.cmd_addr + PDC_PKT_SUBMIT);
752 } 711 }
753 712
754 /* step two - execute ATA command */ 713 /* step two - execute ATA command */
@@ -781,7 +740,7 @@ static inline unsigned int pdc20621_host_intr( struct ata_port *ap,
781static void pdc20621_irq_clear(struct ata_port *ap) 740static void pdc20621_irq_clear(struct ata_port *ap)
782{ 741{
783 struct ata_host *host = ap->host; 742 struct ata_host *host = ap->host;
784 void __iomem *mmio = host->mmio_base; 743 void __iomem *mmio = host->iomap[PDC_MMIO_BAR];
785 744
786 mmio += PDC_CHIP0_OFS; 745 mmio += PDC_CHIP0_OFS;
787 746
@@ -799,12 +758,12 @@ static irqreturn_t pdc20621_interrupt (int irq, void *dev_instance)
799 758
800 VPRINTK("ENTER\n"); 759 VPRINTK("ENTER\n");
801 760
802 if (!host || !host->mmio_base) { 761 if (!host || !host->iomap[PDC_MMIO_BAR]) {
803 VPRINTK("QUICK EXIT\n"); 762 VPRINTK("QUICK EXIT\n");
804 return IRQ_NONE; 763 return IRQ_NONE;
805 } 764 }
806 765
807 mmio_base = host->mmio_base; 766 mmio_base = host->iomap[PDC_MMIO_BAR];
808 767
809 /* reading should also clear interrupts */ 768 /* reading should also clear interrupts */
810 mmio_base += PDC_CHIP0_OFS; 769 mmio_base += PDC_CHIP0_OFS;
@@ -905,7 +864,7 @@ static void pdc_exec_command_mmio(struct ata_port *ap, const struct ata_taskfile
905} 864}
906 865
907 866
908static void pdc_sata_setup_port(struct ata_ioports *port, unsigned long base) 867static void pdc_sata_setup_port(struct ata_ioports *port, void __iomem *base)
909{ 868{
910 port->cmd_addr = base; 869 port->cmd_addr = base;
911 port->data_addr = base; 870 port->data_addr = base;
@@ -931,9 +890,8 @@ static void pdc20621_get_from_dimm(struct ata_probe_ent *pe, void *psource,
931 u16 idx; 890 u16 idx;
932 u8 page_mask; 891 u8 page_mask;
933 long dist; 892 long dist;
934 void __iomem *mmio = pe->mmio_base; 893 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR];
935 struct pdc_host_priv *hpriv = pe->private_data; 894 void __iomem *dimm_mmio = pe->iomap[PDC_DIMM_BAR];
936 void __iomem *dimm_mmio = hpriv->dimm_mmio;
937 895
938 /* hard-code chip #0 */ 896 /* hard-code chip #0 */
939 mmio += PDC_CHIP0_OFS; 897 mmio += PDC_CHIP0_OFS;
@@ -987,9 +945,8 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource,
987 u16 idx; 945 u16 idx;
988 u8 page_mask; 946 u8 page_mask;
989 long dist; 947 long dist;
990 void __iomem *mmio = pe->mmio_base; 948 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR];
991 struct pdc_host_priv *hpriv = pe->private_data; 949 void __iomem *dimm_mmio = pe->iomap[PDC_DIMM_BAR];
992 void __iomem *dimm_mmio = hpriv->dimm_mmio;
993 950
994 /* hard-code chip #0 */ 951 /* hard-code chip #0 */
995 mmio += PDC_CHIP0_OFS; 952 mmio += PDC_CHIP0_OFS;
@@ -1034,7 +991,7 @@ static void pdc20621_put_to_dimm(struct ata_probe_ent *pe, void *psource,
1034static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe, u32 device, 991static unsigned int pdc20621_i2c_read(struct ata_probe_ent *pe, u32 device,
1035 u32 subaddr, u32 *pdata) 992 u32 subaddr, u32 *pdata)
1036{ 993{
1037 void __iomem *mmio = pe->mmio_base; 994 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR];
1038 u32 i2creg = 0; 995 u32 i2creg = 0;
1039 u32 status; 996 u32 status;
1040 u32 count =0; 997 u32 count =0;
@@ -1093,7 +1050,7 @@ static int pdc20621_prog_dimm0(struct ata_probe_ent *pe)
1093 u32 data = 0; 1050 u32 data = 0;
1094 int size, i; 1051 int size, i;
1095 u8 bdimmsize; 1052 u8 bdimmsize;
1096 void __iomem *mmio = pe->mmio_base; 1053 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR];
1097 static const struct { 1054 static const struct {
1098 unsigned int reg; 1055 unsigned int reg;
1099 unsigned int ofs; 1056 unsigned int ofs;
@@ -1155,8 +1112,8 @@ static int pdc20621_prog_dimm0(struct ata_probe_ent *pe)
1155static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent *pe) 1112static unsigned int pdc20621_prog_dimm_global(struct ata_probe_ent *pe)
1156{ 1113{
1157 u32 data, spd0; 1114 u32 data, spd0;
1158 int error, i; 1115 int error, i;
1159 void __iomem *mmio = pe->mmio_base; 1116 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR];
1160 1117
1161 /* hard-code chip #0 */ 1118 /* hard-code chip #0 */
1162 mmio += PDC_CHIP0_OFS; 1119 mmio += PDC_CHIP0_OFS;
@@ -1210,7 +1167,7 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe)
1210 u32 ticks=0; 1167 u32 ticks=0;
1211 u32 clock=0; 1168 u32 clock=0;
1212 u32 fparam=0; 1169 u32 fparam=0;
1213 void __iomem *mmio = pe->mmio_base; 1170 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR];
1214 1171
1215 /* hard-code chip #0 */ 1172 /* hard-code chip #0 */
1216 mmio += PDC_CHIP0_OFS; 1173 mmio += PDC_CHIP0_OFS;
@@ -1334,7 +1291,7 @@ static unsigned int pdc20621_dimm_init(struct ata_probe_ent *pe)
1334static void pdc_20621_init(struct ata_probe_ent *pe) 1291static void pdc_20621_init(struct ata_probe_ent *pe)
1335{ 1292{
1336 u32 tmp; 1293 u32 tmp;
1337 void __iomem *mmio = pe->mmio_base; 1294 void __iomem *mmio = pe->iomap[PDC_MMIO_BAR];
1338 1295
1339 /* hard-code chip #0 */ 1296 /* hard-code chip #0 */
1340 mmio += PDC_CHIP0_OFS; 1297 mmio += PDC_CHIP0_OFS;
@@ -1365,67 +1322,43 @@ static void pdc_20621_init(struct ata_probe_ent *pe)
1365static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 1322static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
1366{ 1323{
1367 static int printed_version; 1324 static int printed_version;
1368 struct ata_probe_ent *probe_ent = NULL; 1325 struct ata_probe_ent *probe_ent;
1369 unsigned long base; 1326 void __iomem *base;
1370 void __iomem *mmio_base; 1327 struct pdc_host_priv *hpriv;
1371 void __iomem *dimm_mmio = NULL;
1372 struct pdc_host_priv *hpriv = NULL;
1373 unsigned int board_idx = (unsigned int) ent->driver_data; 1328 unsigned int board_idx = (unsigned int) ent->driver_data;
1374 int pci_dev_busy = 0;
1375 int rc; 1329 int rc;
1376 1330
1377 if (!printed_version++) 1331 if (!printed_version++)
1378 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 1332 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
1379 1333
1380 rc = pci_enable_device(pdev); 1334 rc = pcim_enable_device(pdev);
1381 if (rc) 1335 if (rc)
1382 return rc; 1336 return rc;
1383 1337
1384 rc = pci_request_regions(pdev, DRV_NAME); 1338 rc = pcim_iomap_regions(pdev, (1 << PDC_MMIO_BAR) | (1 << PDC_DIMM_BAR),
1385 if (rc) { 1339 DRV_NAME);
1386 pci_dev_busy = 1; 1340 if (rc == -EBUSY)
1387 goto err_out; 1341 pcim_pin_device(pdev);
1388 } 1342 if (rc)
1343 return rc;
1389 1344
1390 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 1345 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
1391 if (rc) 1346 if (rc)
1392 goto err_out_regions; 1347 return rc;
1393 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 1348 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
1394 if (rc) 1349 if (rc)
1395 goto err_out_regions; 1350 return rc;
1396 1351
1397 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 1352 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
1398 if (probe_ent == NULL) { 1353 if (probe_ent == NULL)
1399 rc = -ENOMEM; 1354 return -ENOMEM;
1400 goto err_out_regions;
1401 }
1402 1355
1403 memset(probe_ent, 0, sizeof(*probe_ent));
1404 probe_ent->dev = pci_dev_to_dev(pdev); 1356 probe_ent->dev = pci_dev_to_dev(pdev);
1405 INIT_LIST_HEAD(&probe_ent->node); 1357 INIT_LIST_HEAD(&probe_ent->node);
1406 1358
1407 mmio_base = pci_iomap(pdev, 3, 0); 1359 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
1408 if (mmio_base == NULL) { 1360 if (!hpriv)
1409 rc = -ENOMEM; 1361 return -ENOMEM;
1410 goto err_out_free_ent;
1411 }
1412 base = (unsigned long) mmio_base;
1413
1414 hpriv = kmalloc(sizeof(*hpriv), GFP_KERNEL);
1415 if (!hpriv) {
1416 rc = -ENOMEM;
1417 goto err_out_iounmap;
1418 }
1419 memset(hpriv, 0, sizeof(*hpriv));
1420
1421 dimm_mmio = pci_iomap(pdev, 4, 0);
1422 if (!dimm_mmio) {
1423 kfree(hpriv);
1424 rc = -ENOMEM;
1425 goto err_out_iounmap;
1426 }
1427
1428 hpriv->dimm_mmio = dimm_mmio;
1429 1362
1430 probe_ent->sht = pdc_port_info[board_idx].sht; 1363 probe_ent->sht = pdc_port_info[board_idx].sht;
1431 probe_ent->port_flags = pdc_port_info[board_idx].flags; 1364 probe_ent->port_flags = pdc_port_info[board_idx].flags;
@@ -1436,10 +1369,10 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1436 1369
1437 probe_ent->irq = pdev->irq; 1370 probe_ent->irq = pdev->irq;
1438 probe_ent->irq_flags = IRQF_SHARED; 1371 probe_ent->irq_flags = IRQF_SHARED;
1439 probe_ent->mmio_base = mmio_base; 1372 probe_ent->iomap = pcim_iomap_table(pdev);
1440 1373
1441 probe_ent->private_data = hpriv; 1374 probe_ent->private_data = hpriv;
1442 base += PDC_CHIP0_OFS; 1375 base = probe_ent->iomap[PDC_MMIO_BAR] + PDC_CHIP0_OFS;
1443 1376
1444 probe_ent->n_ports = 4; 1377 probe_ent->n_ports = 4;
1445 pdc_sata_setup_port(&probe_ent->port[0], base + 0x200); 1378 pdc_sata_setup_port(&probe_ent->port[0], base + 0x200);
@@ -1451,31 +1384,15 @@ static int pdc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *
1451 1384
1452 /* initialize adapter */ 1385 /* initialize adapter */
1453 /* initialize local dimm */ 1386 /* initialize local dimm */
1454 if (pdc20621_dimm_init(probe_ent)) { 1387 if (pdc20621_dimm_init(probe_ent))
1455 rc = -ENOMEM; 1388 return -ENOMEM;
1456 goto err_out_iounmap_dimm;
1457 }
1458 pdc_20621_init(probe_ent); 1389 pdc_20621_init(probe_ent);
1459 1390
1460 /* FIXME: check ata_device_add return value */ 1391 if (!ata_device_add(probe_ent))
1461 ata_device_add(probe_ent); 1392 return -ENODEV;
1462 kfree(probe_ent);
1463 1393
1394 devm_kfree(&pdev->dev, probe_ent);
1464 return 0; 1395 return 0;
1465
1466err_out_iounmap_dimm: /* only get to this label if 20621 */
1467 kfree(hpriv);
1468 pci_iounmap(pdev, dimm_mmio);
1469err_out_iounmap:
1470 pci_iounmap(pdev, mmio_base);
1471err_out_free_ent:
1472 kfree(probe_ent);
1473err_out_regions:
1474 pci_release_regions(pdev);
1475err_out:
1476 if (!pci_dev_busy)
1477 pci_disable_device(pdev);
1478 return rc;
1479} 1396}
1480 1397
1481 1398
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index a43aec62d50..80131eec68f 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -108,7 +108,7 @@ static const struct ata_port_operations uli_ops = {
108 .bmdma_status = ata_bmdma_status, 108 .bmdma_status = ata_bmdma_status,
109 .qc_prep = ata_qc_prep, 109 .qc_prep = ata_qc_prep,
110 .qc_issue = ata_qc_issue_prot, 110 .qc_issue = ata_qc_issue_prot,
111 .data_xfer = ata_pio_data_xfer, 111 .data_xfer = ata_data_xfer,
112 112
113 .freeze = ata_bmdma_freeze, 113 .freeze = ata_bmdma_freeze,
114 .thaw = ata_bmdma_thaw, 114 .thaw = ata_bmdma_thaw,
@@ -117,13 +117,13 @@ static const struct ata_port_operations uli_ops = {
117 117
118 .irq_handler = ata_interrupt, 118 .irq_handler = ata_interrupt,
119 .irq_clear = ata_bmdma_irq_clear, 119 .irq_clear = ata_bmdma_irq_clear,
120 .irq_on = ata_irq_on,
121 .irq_ack = ata_irq_ack,
120 122
121 .scr_read = uli_scr_read, 123 .scr_read = uli_scr_read,
122 .scr_write = uli_scr_write, 124 .scr_write = uli_scr_write,
123 125
124 .port_start = ata_port_start, 126 .port_start = ata_port_start,
125 .port_stop = ata_port_stop,
126 .host_stop = ata_host_stop,
127}; 127};
128 128
129static struct ata_port_info uli_port_info = { 129static struct ata_port_info uli_port_info = {
@@ -189,62 +189,60 @@ static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
189 struct ata_port_info *ppi[2]; 189 struct ata_port_info *ppi[2];
190 int rc; 190 int rc;
191 unsigned int board_idx = (unsigned int) ent->driver_data; 191 unsigned int board_idx = (unsigned int) ent->driver_data;
192 int pci_dev_busy = 0;
193 struct uli_priv *hpriv; 192 struct uli_priv *hpriv;
193 void __iomem * const *iomap;
194 194
195 if (!printed_version++) 195 if (!printed_version++)
196 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n"); 196 dev_printk(KERN_INFO, &pdev->dev, "version " DRV_VERSION "\n");
197 197
198 rc = pci_enable_device(pdev); 198 rc = pcim_enable_device(pdev);
199 if (rc) 199 if (rc)
200 return rc; 200 return rc;
201 201
202 rc = pci_request_regions(pdev, DRV_NAME); 202 rc = pci_request_regions(pdev, DRV_NAME);
203 if (rc) { 203 if (rc) {
204 pci_dev_busy = 1; 204 pcim_pin_device(pdev);
205 goto err_out; 205 return rc;
206 } 206 }
207 207
208 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 208 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
209 if (rc) 209 if (rc)
210 goto err_out_regions; 210 return rc;
211 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 211 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
212 if (rc) 212 if (rc)
213 goto err_out_regions; 213 return rc;
214 214
215 ppi[0] = ppi[1] = &uli_port_info; 215 ppi[0] = ppi[1] = &uli_port_info;
216 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 216 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
217 if (!probe_ent) { 217 if (!probe_ent)
218 rc = -ENOMEM; 218 return -ENOMEM;
219 goto err_out_regions;
220 }
221 219
222 hpriv = kzalloc(sizeof(*hpriv), GFP_KERNEL); 220 hpriv = devm_kzalloc(&pdev->dev, sizeof(*hpriv), GFP_KERNEL);
223 if (!hpriv) { 221 if (!hpriv)
224 rc = -ENOMEM; 222 return -ENOMEM;
225 goto err_out_probe_ent;
226 }
227 223
228 probe_ent->private_data = hpriv; 224 probe_ent->private_data = hpriv;
229 225
226 iomap = pcim_iomap_table(pdev);
227
230 switch (board_idx) { 228 switch (board_idx) {
231 case uli_5287: 229 case uli_5287:
232 hpriv->scr_cfg_addr[0] = ULI5287_BASE; 230 hpriv->scr_cfg_addr[0] = ULI5287_BASE;
233 hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS; 231 hpriv->scr_cfg_addr[1] = ULI5287_BASE + ULI5287_OFFS;
234 probe_ent->n_ports = 4; 232 probe_ent->n_ports = 4;
235 233
236 probe_ent->port[2].cmd_addr = pci_resource_start(pdev, 0) + 8; 234 probe_ent->port[2].cmd_addr = iomap[0] + 8;
237 probe_ent->port[2].altstatus_addr = 235 probe_ent->port[2].altstatus_addr =
238 probe_ent->port[2].ctl_addr = 236 probe_ent->port[2].ctl_addr = (void __iomem *)
239 (pci_resource_start(pdev, 1) | ATA_PCI_CTL_OFS) + 4; 237 ((unsigned long)iomap[1] | ATA_PCI_CTL_OFS) + 4;
240 probe_ent->port[2].bmdma_addr = pci_resource_start(pdev, 4) + 16; 238 probe_ent->port[2].bmdma_addr = iomap[4] + 16;
241 hpriv->scr_cfg_addr[2] = ULI5287_BASE + ULI5287_OFFS*4; 239 hpriv->scr_cfg_addr[2] = ULI5287_BASE + ULI5287_OFFS*4;
242 240
243 probe_ent->port[3].cmd_addr = pci_resource_start(pdev, 2) + 8; 241 probe_ent->port[3].cmd_addr = iomap[2] + 8;
244 probe_ent->port[3].altstatus_addr = 242 probe_ent->port[3].altstatus_addr =
245 probe_ent->port[3].ctl_addr = 243 probe_ent->port[3].ctl_addr = (void __iomem *)
246 (pci_resource_start(pdev, 3) | ATA_PCI_CTL_OFS) + 4; 244 ((unsigned long)iomap[3] | ATA_PCI_CTL_OFS) + 4;
247 probe_ent->port[3].bmdma_addr = pci_resource_start(pdev, 4) + 24; 245 probe_ent->port[3].bmdma_addr = iomap[4] + 24;
248 hpriv->scr_cfg_addr[3] = ULI5287_BASE + ULI5287_OFFS*5; 246 hpriv->scr_cfg_addr[3] = ULI5287_BASE + ULI5287_OFFS*5;
249 247
250 ata_std_ports(&probe_ent->port[2]); 248 ata_std_ports(&probe_ent->port[2]);
@@ -269,21 +267,11 @@ static int uli_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
269 pci_set_master(pdev); 267 pci_set_master(pdev);
270 pci_intx(pdev, 1); 268 pci_intx(pdev, 1);
271 269
272 /* FIXME: check ata_device_add return value */ 270 if (!ata_device_add(probe_ent))
273 ata_device_add(probe_ent); 271 return -ENODEV;
274 kfree(probe_ent);
275 272
273 devm_kfree(&pdev->dev, probe_ent);
276 return 0; 274 return 0;
277
278err_out_probe_ent:
279 kfree(probe_ent);
280err_out_regions:
281 pci_release_regions(pdev);
282err_out:
283 if (!pci_dev_busy)
284 pci_disable_device(pdev);
285 return rc;
286
287} 275}
288 276
289static int __init uli_init(void) 277static int __init uli_init(void)
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index d3d5c0d5703..baca6d79bb0 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -44,7 +44,6 @@
44#include <linux/device.h> 44#include <linux/device.h>
45#include <scsi/scsi_host.h> 45#include <scsi/scsi_host.h>
46#include <linux/libata.h> 46#include <linux/libata.h>
47#include <asm/io.h>
48 47
49#define DRV_NAME "sata_via" 48#define DRV_NAME "sata_via"
50#define DRV_VERSION "2.0" 49#define DRV_VERSION "2.0"
@@ -59,11 +58,14 @@ enum {
59 SATA_INT_GATE = 0x41, /* SATA interrupt gating */ 58 SATA_INT_GATE = 0x41, /* SATA interrupt gating */
60 SATA_NATIVE_MODE = 0x42, /* Native mode enable */ 59 SATA_NATIVE_MODE = 0x42, /* Native mode enable */
61 SATA_PATA_SHARING = 0x49, /* PATA/SATA sharing func ctrl */ 60 SATA_PATA_SHARING = 0x49, /* PATA/SATA sharing func ctrl */
62 61 PATA_UDMA_TIMING = 0xB3, /* PATA timing for DMA/ cable detect */
62 PATA_PIO_TIMING = 0xAB, /* PATA timing register */
63
63 PORT0 = (1 << 1), 64 PORT0 = (1 << 1),
64 PORT1 = (1 << 0), 65 PORT1 = (1 << 0),
65 ALL_PORTS = PORT0 | PORT1, 66 ALL_PORTS = PORT0 | PORT1,
66 N_PORTS = 2, 67 PATA_PORT = 2, /* PATA is port 2 */
68 N_PORTS = 3,
67 69
68 NATIVE_MODE_ALL = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4), 70 NATIVE_MODE_ALL = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4),
69 71
@@ -76,6 +78,11 @@ static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg);
76static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val); 78static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val);
77static void svia_noop_freeze(struct ata_port *ap); 79static void svia_noop_freeze(struct ata_port *ap);
78static void vt6420_error_handler(struct ata_port *ap); 80static void vt6420_error_handler(struct ata_port *ap);
81static void vt6421_sata_error_handler(struct ata_port *ap);
82static void vt6421_pata_error_handler(struct ata_port *ap);
83static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev);
84static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev);
85static int vt6421_port_start(struct ata_port *ap);
79 86
80static const struct pci_device_id svia_pci_tbl[] = { 87static const struct pci_device_id svia_pci_tbl[] = {
81 { PCI_VDEVICE(VIA, 0x5337), vt6420 }, 88 { PCI_VDEVICE(VIA, 0x5337), vt6420 },
@@ -127,7 +134,7 @@ static const struct ata_port_operations vt6420_sata_ops = {
127 134
128 .qc_prep = ata_qc_prep, 135 .qc_prep = ata_qc_prep,
129 .qc_issue = ata_qc_issue_prot, 136 .qc_issue = ata_qc_issue_prot,
130 .data_xfer = ata_pio_data_xfer, 137 .data_xfer = ata_data_xfer,
131 138
132 .freeze = svia_noop_freeze, 139 .freeze = svia_noop_freeze,
133 .thaw = ata_bmdma_thaw, 140 .thaw = ata_bmdma_thaw,
@@ -136,15 +143,49 @@ static const struct ata_port_operations vt6420_sata_ops = {
136 143
137 .irq_handler = ata_interrupt, 144 .irq_handler = ata_interrupt,
138 .irq_clear = ata_bmdma_irq_clear, 145 .irq_clear = ata_bmdma_irq_clear,
146 .irq_on = ata_irq_on,
147 .irq_ack = ata_irq_ack,
139 148
140 .port_start = ata_port_start, 149 .port_start = ata_port_start,
141 .port_stop = ata_port_stop,
142 .host_stop = ata_host_stop,
143}; 150};
144 151
145static const struct ata_port_operations vt6421_sata_ops = { 152static const struct ata_port_operations vt6421_pata_ops = {
146 .port_disable = ata_port_disable, 153 .port_disable = ata_port_disable,
154
155 .set_piomode = vt6421_set_pio_mode,
156 .set_dmamode = vt6421_set_dma_mode,
157
158 .tf_load = ata_tf_load,
159 .tf_read = ata_tf_read,
160 .check_status = ata_check_status,
161 .exec_command = ata_exec_command,
162 .dev_select = ata_std_dev_select,
163
164 .bmdma_setup = ata_bmdma_setup,
165 .bmdma_start = ata_bmdma_start,
166 .bmdma_stop = ata_bmdma_stop,
167 .bmdma_status = ata_bmdma_status,
168
169 .qc_prep = ata_qc_prep,
170 .qc_issue = ata_qc_issue_prot,
171 .data_xfer = ata_data_xfer,
172
173 .freeze = ata_bmdma_freeze,
174 .thaw = ata_bmdma_thaw,
175 .error_handler = vt6421_pata_error_handler,
176 .post_internal_cmd = ata_bmdma_post_internal_cmd,
147 177
178 .irq_handler = ata_interrupt,
179 .irq_clear = ata_bmdma_irq_clear,
180 .irq_on = ata_irq_on,
181 .irq_ack = ata_irq_ack,
182
183 .port_start = vt6421_port_start,
184};
185
186static const struct ata_port_operations vt6421_sata_ops = {
187 .port_disable = ata_port_disable,
188
148 .tf_load = ata_tf_load, 189 .tf_load = ata_tf_load,
149 .tf_read = ata_tf_read, 190 .tf_read = ata_tf_read,
150 .check_status = ata_check_status, 191 .check_status = ata_check_status,
@@ -158,22 +199,22 @@ static const struct ata_port_operations vt6421_sata_ops = {
158 199
159 .qc_prep = ata_qc_prep, 200 .qc_prep = ata_qc_prep,
160 .qc_issue = ata_qc_issue_prot, 201 .qc_issue = ata_qc_issue_prot,
161 .data_xfer = ata_pio_data_xfer, 202 .data_xfer = ata_data_xfer,
162 203
163 .freeze = ata_bmdma_freeze, 204 .freeze = ata_bmdma_freeze,
164 .thaw = ata_bmdma_thaw, 205 .thaw = ata_bmdma_thaw,
165 .error_handler = ata_bmdma_error_handler, 206 .error_handler = vt6421_sata_error_handler,
166 .post_internal_cmd = ata_bmdma_post_internal_cmd, 207 .post_internal_cmd = ata_bmdma_post_internal_cmd,
167 208
168 .irq_handler = ata_interrupt, 209 .irq_handler = ata_interrupt,
169 .irq_clear = ata_bmdma_irq_clear, 210 .irq_clear = ata_bmdma_irq_clear,
211 .irq_on = ata_irq_on,
212 .irq_ack = ata_irq_ack,
170 213
171 .scr_read = svia_scr_read, 214 .scr_read = svia_scr_read,
172 .scr_write = svia_scr_write, 215 .scr_write = svia_scr_write,
173 216
174 .port_start = ata_port_start, 217 .port_start = vt6421_port_start,
175 .port_stop = ata_port_stop,
176 .host_stop = ata_host_stop,
177}; 218};
178 219
179static struct ata_port_info vt6420_port_info = { 220static struct ata_port_info vt6420_port_info = {
@@ -195,14 +236,14 @@ static u32 svia_scr_read (struct ata_port *ap, unsigned int sc_reg)
195{ 236{
196 if (sc_reg > SCR_CONTROL) 237 if (sc_reg > SCR_CONTROL)
197 return 0xffffffffU; 238 return 0xffffffffU;
198 return inl(ap->ioaddr.scr_addr + (4 * sc_reg)); 239 return ioread32(ap->ioaddr.scr_addr + (4 * sc_reg));
199} 240}
200 241
201static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val) 242static void svia_scr_write (struct ata_port *ap, unsigned int sc_reg, u32 val)
202{ 243{
203 if (sc_reg > SCR_CONTROL) 244 if (sc_reg > SCR_CONTROL)
204 return; 245 return;
205 outl(val, ap->ioaddr.scr_addr + (4 * sc_reg)); 246 iowrite32(val, ap->ioaddr.scr_addr + (4 * sc_reg));
206} 247}
207 248
208static void svia_noop_freeze(struct ata_port *ap) 249static void svia_noop_freeze(struct ata_port *ap)
@@ -289,6 +330,61 @@ static void vt6420_error_handler(struct ata_port *ap)
289 NULL, ata_std_postreset); 330 NULL, ata_std_postreset);
290} 331}
291 332
333static int vt6421_pata_prereset(struct ata_port *ap)
334{
335 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
336 u8 tmp;
337
338 pci_read_config_byte(pdev, PATA_UDMA_TIMING, &tmp);
339 if (tmp & 0x10)
340 ap->cbl = ATA_CBL_PATA40;
341 else
342 ap->cbl = ATA_CBL_PATA80;
343 return 0;
344}
345
346static void vt6421_pata_error_handler(struct ata_port *ap)
347{
348 return ata_bmdma_drive_eh(ap, vt6421_pata_prereset, ata_std_softreset,
349 NULL, ata_std_postreset);
350}
351
352static int vt6421_sata_prereset(struct ata_port *ap)
353{
354 ap->cbl = ATA_CBL_SATA;
355 return 0;
356}
357
358static void vt6421_sata_error_handler(struct ata_port *ap)
359{
360 return ata_bmdma_drive_eh(ap, vt6421_sata_prereset, ata_std_softreset,
361 NULL, ata_std_postreset);
362}
363
364static void vt6421_set_pio_mode(struct ata_port *ap, struct ata_device *adev)
365{
366 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
367 static const u8 pio_bits[] = { 0xA8, 0x65, 0x65, 0x31, 0x20 };
368 pci_write_config_byte(pdev, PATA_PIO_TIMING, pio_bits[adev->pio_mode - XFER_PIO_0]);
369}
370
371static void vt6421_set_dma_mode(struct ata_port *ap, struct ata_device *adev)
372{
373 struct pci_dev *pdev = to_pci_dev(ap->host->dev);
374 static const u8 udma_bits[] = { 0xEE, 0xE8, 0xE6, 0xE4, 0xE2, 0xE1, 0xE0, 0xE0 };
375 pci_write_config_byte(pdev, PATA_UDMA_TIMING, udma_bits[adev->pio_mode - XFER_UDMA_0]);
376}
377
378static int vt6421_port_start(struct ata_port *ap)
379{
380 if (ap->port_no == PATA_PORT) {
381 ap->ops = &vt6421_pata_ops;
382 ap->mwdma_mask = 0;
383 ap->flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY | ATA_FLAG_SRST;
384 }
385 return ata_port_start(ap);
386}
387
292static const unsigned int svia_bar_sizes[] = { 388static const unsigned int svia_bar_sizes[] = {
293 8, 4, 8, 4, 16, 256 389 8, 4, 8, 4, 16, 256
294}; 390};
@@ -297,31 +393,28 @@ static const unsigned int vt6421_bar_sizes[] = {
297 16, 16, 16, 16, 32, 128 393 16, 16, 16, 16, 32, 128
298}; 394};
299 395
300static unsigned long svia_scr_addr(unsigned long addr, unsigned int port) 396static void __iomem * svia_scr_addr(void __iomem *addr, unsigned int port)
301{ 397{
302 return addr + (port * 128); 398 return addr + (port * 128);
303} 399}
304 400
305static unsigned long vt6421_scr_addr(unsigned long addr, unsigned int port) 401static void __iomem * vt6421_scr_addr(void __iomem *addr, unsigned int port)
306{ 402{
307 return addr + (port * 64); 403 return addr + (port * 64);
308} 404}
309 405
310static void vt6421_init_addrs(struct ata_probe_ent *probe_ent, 406static void vt6421_init_addrs(struct ata_probe_ent *probe_ent,
311 struct pci_dev *pdev, 407 void __iomem * const *iomap, unsigned int port)
312 unsigned int port)
313{ 408{
314 unsigned long reg_addr = pci_resource_start(pdev, port); 409 void __iomem *reg_addr = iomap[port];
315 unsigned long bmdma_addr = pci_resource_start(pdev, 4) + (port * 8); 410 void __iomem *bmdma_addr = iomap[4] + (port * 8);
316 unsigned long scr_addr;
317 411
318 probe_ent->port[port].cmd_addr = reg_addr; 412 probe_ent->port[port].cmd_addr = reg_addr;
319 probe_ent->port[port].altstatus_addr = 413 probe_ent->port[port].altstatus_addr =
320 probe_ent->port[port].ctl_addr = (reg_addr + 8) | ATA_PCI_CTL_OFS; 414 probe_ent->port[port].ctl_addr = (void __iomem *)
415 ((unsigned long)(reg_addr + 8) | ATA_PCI_CTL_OFS);
321 probe_ent->port[port].bmdma_addr = bmdma_addr; 416 probe_ent->port[port].bmdma_addr = bmdma_addr;
322 417 probe_ent->port[port].scr_addr = vt6421_scr_addr(iomap[5], port);
323 scr_addr = vt6421_scr_addr(pci_resource_start(pdev, 5), port);
324 probe_ent->port[port].scr_addr = scr_addr;
325 418
326 ata_std_ports(&probe_ent->port[port]); 419 ata_std_ports(&probe_ent->port[port]);
327} 420}
@@ -330,16 +423,16 @@ static struct ata_probe_ent *vt6420_init_probe_ent(struct pci_dev *pdev)
330{ 423{
331 struct ata_probe_ent *probe_ent; 424 struct ata_probe_ent *probe_ent;
332 struct ata_port_info *ppi[2]; 425 struct ata_port_info *ppi[2];
333 426 void __iomem * const *iomap;
427
334 ppi[0] = ppi[1] = &vt6420_port_info; 428 ppi[0] = ppi[1] = &vt6420_port_info;
335 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY); 429 probe_ent = ata_pci_init_native_mode(pdev, ppi, ATA_PORT_PRIMARY | ATA_PORT_SECONDARY);
336 if (!probe_ent) 430 if (!probe_ent)
337 return NULL; 431 return NULL;
338 432
339 probe_ent->port[0].scr_addr = 433 iomap = pcim_iomap_table(pdev);
340 svia_scr_addr(pci_resource_start(pdev, 5), 0); 434 probe_ent->port[0].scr_addr = svia_scr_addr(iomap[5], 0);
341 probe_ent->port[1].scr_addr = 435 probe_ent->port[1].scr_addr = svia_scr_addr(iomap[5], 1);
342 svia_scr_addr(pci_resource_start(pdev, 5), 1);
343 436
344 return probe_ent; 437 return probe_ent;
345} 438}
@@ -349,7 +442,7 @@ static struct ata_probe_ent *vt6421_init_probe_ent(struct pci_dev *pdev)
349 struct ata_probe_ent *probe_ent; 442 struct ata_probe_ent *probe_ent;
350 unsigned int i; 443 unsigned int i;
351 444
352 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 445 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
353 if (!probe_ent) 446 if (!probe_ent)
354 return NULL; 447 return NULL;
355 448
@@ -368,7 +461,7 @@ static struct ata_probe_ent *vt6421_init_probe_ent(struct pci_dev *pdev)
368 probe_ent->udma_mask = 0x7f; 461 probe_ent->udma_mask = 0x7f;
369 462
370 for (i = 0; i < N_PORTS; i++) 463 for (i = 0; i < N_PORTS; i++)
371 vt6421_init_addrs(probe_ent, pdev, i); 464 vt6421_init_addrs(probe_ent, pcim_iomap_table(pdev), i);
372 465
373 return probe_ent; 466 return probe_ent;
374} 467}
@@ -420,20 +513,19 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
420 struct ata_probe_ent *probe_ent; 513 struct ata_probe_ent *probe_ent;
421 int board_id = (int) ent->driver_data; 514 int board_id = (int) ent->driver_data;
422 const int *bar_sizes; 515 const int *bar_sizes;
423 int pci_dev_busy = 0;
424 u8 tmp8; 516 u8 tmp8;
425 517
426 if (!printed_version++) 518 if (!printed_version++)
427 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 519 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
428 520
429 rc = pci_enable_device(pdev); 521 rc = pcim_enable_device(pdev);
430 if (rc) 522 if (rc)
431 return rc; 523 return rc;
432 524
433 rc = pci_request_regions(pdev, DRV_NAME); 525 rc = pcim_iomap_regions(pdev, 0x1f, DRV_NAME);
434 if (rc) { 526 if (rc) {
435 pci_dev_busy = 1; 527 pcim_pin_device(pdev);
436 goto err_out; 528 return rc;
437 } 529 }
438 530
439 if (board_id == vt6420) { 531 if (board_id == vt6420) {
@@ -442,8 +534,7 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
442 dev_printk(KERN_ERR, &pdev->dev, 534 dev_printk(KERN_ERR, &pdev->dev,
443 "SATA master/slave not supported (0x%x)\n", 535 "SATA master/slave not supported (0x%x)\n",
444 (int) tmp8); 536 (int) tmp8);
445 rc = -EIO; 537 return -EIO;
446 goto err_out_regions;
447 } 538 }
448 539
449 bar_sizes = &svia_bar_sizes[0]; 540 bar_sizes = &svia_bar_sizes[0];
@@ -459,16 +550,15 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
459 i, 550 i,
460 (unsigned long long)pci_resource_start(pdev, i), 551 (unsigned long long)pci_resource_start(pdev, i),
461 (unsigned long long)pci_resource_len(pdev, i)); 552 (unsigned long long)pci_resource_len(pdev, i));
462 rc = -ENODEV; 553 return -ENODEV;
463 goto err_out_regions;
464 } 554 }
465 555
466 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK); 556 rc = pci_set_dma_mask(pdev, ATA_DMA_MASK);
467 if (rc) 557 if (rc)
468 goto err_out_regions; 558 return rc;
469 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK); 559 rc = pci_set_consistent_dma_mask(pdev, ATA_DMA_MASK);
470 if (rc) 560 if (rc)
471 goto err_out_regions; 561 return rc;
472 562
473 if (board_id == vt6420) 563 if (board_id == vt6420)
474 probe_ent = vt6420_init_probe_ent(pdev); 564 probe_ent = vt6420_init_probe_ent(pdev);
@@ -477,26 +567,18 @@ static int svia_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
477 567
478 if (!probe_ent) { 568 if (!probe_ent) {
479 dev_printk(KERN_ERR, &pdev->dev, "out of memory\n"); 569 dev_printk(KERN_ERR, &pdev->dev, "out of memory\n");
480 rc = -ENOMEM; 570 return -ENOMEM;
481 goto err_out_regions;
482 } 571 }
483 572
484 svia_configure(pdev); 573 svia_configure(pdev);
485 574
486 pci_set_master(pdev); 575 pci_set_master(pdev);
487 576
488 /* FIXME: check ata_device_add return value */ 577 if (!ata_device_add(probe_ent))
489 ata_device_add(probe_ent); 578 return -ENODEV;
490 kfree(probe_ent);
491 579
580 devm_kfree(&pdev->dev, probe_ent);
492 return 0; 581 return 0;
493
494err_out_regions:
495 pci_release_regions(pdev);
496err_out:
497 if (!pci_dev_busy)
498 pci_disable_device(pdev);
499 return rc;
500} 582}
501 583
502static int __init svia_init(void) 584static int __init svia_init(void)
@@ -511,4 +593,3 @@ static void __exit svia_exit(void)
511 593
512module_init(svia_init); 594module_init(svia_init);
513module_exit(svia_exit); 595module_exit(svia_exit);
514
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index 0fa1b89f76d..3d9daf23111 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -50,6 +50,8 @@
50#define DRV_VERSION "2.0" 50#define DRV_VERSION "2.0"
51 51
52enum { 52enum {
53 VSC_MMIO_BAR = 0,
54
53 /* Interrupt register offsets (from chip base address) */ 55 /* Interrupt register offsets (from chip base address) */
54 VSC_SATA_INT_STAT_OFFSET = 0x00, 56 VSC_SATA_INT_STAT_OFFSET = 0x00,
55 VSC_SATA_INT_MASK_OFFSET = 0x04, 57 VSC_SATA_INT_MASK_OFFSET = 0x04,
@@ -96,7 +98,6 @@ enum {
96 VSC_SATA_INT_PHY_CHANGE), 98 VSC_SATA_INT_PHY_CHANGE),
97}; 99};
98 100
99
100#define is_vsc_sata_int_err(port_idx, int_status) \ 101#define is_vsc_sata_int_err(port_idx, int_status) \
101 (int_status & (VSC_SATA_INT_ERROR << (8 * port_idx))) 102 (int_status & (VSC_SATA_INT_ERROR << (8 * port_idx)))
102 103
@@ -105,7 +106,7 @@ static u32 vsc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
105{ 106{
106 if (sc_reg > SCR_CONTROL) 107 if (sc_reg > SCR_CONTROL)
107 return 0xffffffffU; 108 return 0xffffffffU;
108 return readl((void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 109 return readl(ap->ioaddr.scr_addr + (sc_reg * 4));
109} 110}
110 111
111 112
@@ -114,7 +115,7 @@ static void vsc_sata_scr_write (struct ata_port *ap, unsigned int sc_reg,
114{ 115{
115 if (sc_reg > SCR_CONTROL) 116 if (sc_reg > SCR_CONTROL)
116 return; 117 return;
117 writel(val, (void __iomem *) ap->ioaddr.scr_addr + (sc_reg * 4)); 118 writel(val, ap->ioaddr.scr_addr + (sc_reg * 4));
118} 119}
119 120
120 121
@@ -123,7 +124,7 @@ static void vsc_intr_mask_update(struct ata_port *ap, u8 ctl)
123 void __iomem *mask_addr; 124 void __iomem *mask_addr;
124 u8 mask; 125 u8 mask;
125 126
126 mask_addr = ap->host->mmio_base + 127 mask_addr = ap->host->iomap[VSC_MMIO_BAR] +
127 VSC_SATA_INT_MASK_OFFSET + ap->port_no; 128 VSC_SATA_INT_MASK_OFFSET + ap->port_no;
128 mask = readb(mask_addr); 129 mask = readb(mask_addr);
129 if (ctl & ATA_NIEN) 130 if (ctl & ATA_NIEN)
@@ -150,25 +151,25 @@ static void vsc_sata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf)
150 } 151 }
151 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) { 152 if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
152 writew(tf->feature | (((u16)tf->hob_feature) << 8), 153 writew(tf->feature | (((u16)tf->hob_feature) << 8),
153 (void __iomem *) ioaddr->feature_addr); 154 ioaddr->feature_addr);
154 writew(tf->nsect | (((u16)tf->hob_nsect) << 8), 155 writew(tf->nsect | (((u16)tf->hob_nsect) << 8),
155 (void __iomem *) ioaddr->nsect_addr); 156 ioaddr->nsect_addr);
156 writew(tf->lbal | (((u16)tf->hob_lbal) << 8), 157 writew(tf->lbal | (((u16)tf->hob_lbal) << 8),
157 (void __iomem *) ioaddr->lbal_addr); 158 ioaddr->lbal_addr);
158 writew(tf->lbam | (((u16)tf->hob_lbam) << 8), 159 writew(tf->lbam | (((u16)tf->hob_lbam) << 8),
159 (void __iomem *) ioaddr->lbam_addr); 160 ioaddr->lbam_addr);
160 writew(tf->lbah | (((u16)tf->hob_lbah) << 8), 161 writew(tf->lbah | (((u16)tf->hob_lbah) << 8),
161 (void __iomem *) ioaddr->lbah_addr); 162 ioaddr->lbah_addr);
162 } else if (is_addr) { 163 } else if (is_addr) {
163 writew(tf->feature, (void __iomem *) ioaddr->feature_addr); 164 writew(tf->feature, ioaddr->feature_addr);
164 writew(tf->nsect, (void __iomem *) ioaddr->nsect_addr); 165 writew(tf->nsect, ioaddr->nsect_addr);
165 writew(tf->lbal, (void __iomem *) ioaddr->lbal_addr); 166 writew(tf->lbal, ioaddr->lbal_addr);
166 writew(tf->lbam, (void __iomem *) ioaddr->lbam_addr); 167 writew(tf->lbam, ioaddr->lbam_addr);
167 writew(tf->lbah, (void __iomem *) ioaddr->lbah_addr); 168 writew(tf->lbah, ioaddr->lbah_addr);
168 } 169 }
169 170
170 if (tf->flags & ATA_TFLAG_DEVICE) 171 if (tf->flags & ATA_TFLAG_DEVICE)
171 writeb(tf->device, (void __iomem *) ioaddr->device_addr); 172 writeb(tf->device, ioaddr->device_addr);
172 173
173 ata_wait_idle(ap); 174 ata_wait_idle(ap);
174} 175}
@@ -180,12 +181,12 @@ static void vsc_sata_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
180 u16 nsect, lbal, lbam, lbah, feature; 181 u16 nsect, lbal, lbam, lbah, feature;
181 182
182 tf->command = ata_check_status(ap); 183 tf->command = ata_check_status(ap);
183 tf->device = readw((void __iomem *) ioaddr->device_addr); 184 tf->device = readw(ioaddr->device_addr);
184 feature = readw((void __iomem *) ioaddr->error_addr); 185 feature = readw(ioaddr->error_addr);
185 nsect = readw((void __iomem *) ioaddr->nsect_addr); 186 nsect = readw(ioaddr->nsect_addr);
186 lbal = readw((void __iomem *) ioaddr->lbal_addr); 187 lbal = readw(ioaddr->lbal_addr);
187 lbam = readw((void __iomem *) ioaddr->lbam_addr); 188 lbam = readw(ioaddr->lbam_addr);
188 lbah = readw((void __iomem *) ioaddr->lbah_addr); 189 lbah = readw(ioaddr->lbah_addr);
189 190
190 tf->feature = feature; 191 tf->feature = feature;
191 tf->nsect = nsect; 192 tf->nsect = nsect;
@@ -217,7 +218,8 @@ static irqreturn_t vsc_sata_interrupt (int irq, void *dev_instance)
217 218
218 spin_lock(&host->lock); 219 spin_lock(&host->lock);
219 220
220 int_status = readl(host->mmio_base + VSC_SATA_INT_STAT_OFFSET); 221 int_status = readl(host->iomap[VSC_MMIO_BAR] +
222 VSC_SATA_INT_STAT_OFFSET);
221 223
222 for (i = 0; i < host->n_ports; i++) { 224 for (i = 0; i < host->n_ports; i++) {
223 if (int_status & ((u32) 0xFF << (8 * i))) { 225 if (int_status & ((u32) 0xFF << (8 * i))) {
@@ -301,21 +303,22 @@ static const struct ata_port_operations vsc_sata_ops = {
301 .bmdma_status = ata_bmdma_status, 303 .bmdma_status = ata_bmdma_status,
302 .qc_prep = ata_qc_prep, 304 .qc_prep = ata_qc_prep,
303 .qc_issue = ata_qc_issue_prot, 305 .qc_issue = ata_qc_issue_prot,
304 .data_xfer = ata_mmio_data_xfer, 306 .data_xfer = ata_data_xfer,
305 .freeze = ata_bmdma_freeze, 307 .freeze = ata_bmdma_freeze,
306 .thaw = ata_bmdma_thaw, 308 .thaw = ata_bmdma_thaw,
307 .error_handler = ata_bmdma_error_handler, 309 .error_handler = ata_bmdma_error_handler,
308 .post_internal_cmd = ata_bmdma_post_internal_cmd, 310 .post_internal_cmd = ata_bmdma_post_internal_cmd,
309 .irq_handler = vsc_sata_interrupt, 311 .irq_handler = vsc_sata_interrupt,
310 .irq_clear = ata_bmdma_irq_clear, 312 .irq_clear = ata_bmdma_irq_clear,
313 .irq_on = ata_irq_on,
314 .irq_ack = ata_irq_ack,
311 .scr_read = vsc_sata_scr_read, 315 .scr_read = vsc_sata_scr_read,
312 .scr_write = vsc_sata_scr_write, 316 .scr_write = vsc_sata_scr_write,
313 .port_start = ata_port_start, 317 .port_start = ata_port_start,
314 .port_stop = ata_port_stop,
315 .host_stop = ata_pci_host_stop,
316}; 318};
317 319
318static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned long base) 320static void __devinit vsc_sata_setup_port(struct ata_ioports *port,
321 void __iomem *base)
319{ 322{
320 port->cmd_addr = base + VSC_SATA_TF_CMD_OFFSET; 323 port->cmd_addr = base + VSC_SATA_TF_CMD_OFFSET;
321 port->data_addr = base + VSC_SATA_TF_DATA_OFFSET; 324 port->data_addr = base + VSC_SATA_TF_DATA_OFFSET;
@@ -332,80 +335,70 @@ static void __devinit vsc_sata_setup_port(struct ata_ioports *port, unsigned lon
332 port->ctl_addr = base + VSC_SATA_TF_CTL_OFFSET; 335 port->ctl_addr = base + VSC_SATA_TF_CTL_OFFSET;
333 port->bmdma_addr = base + VSC_SATA_DMA_CMD_OFFSET; 336 port->bmdma_addr = base + VSC_SATA_DMA_CMD_OFFSET;
334 port->scr_addr = base + VSC_SATA_SCR_STATUS_OFFSET; 337 port->scr_addr = base + VSC_SATA_SCR_STATUS_OFFSET;
335 writel(0, (void __iomem *) base + VSC_SATA_UP_DESCRIPTOR_OFFSET); 338 writel(0, base + VSC_SATA_UP_DESCRIPTOR_OFFSET);
336 writel(0, (void __iomem *) base + VSC_SATA_UP_DATA_BUFFER_OFFSET); 339 writel(0, base + VSC_SATA_UP_DATA_BUFFER_OFFSET);
337} 340}
338 341
339 342
340static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent) 343static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
341{ 344{
342 static int printed_version; 345 static int printed_version;
343 struct ata_probe_ent *probe_ent = NULL; 346 struct ata_probe_ent *probe_ent;
344 unsigned long base;
345 int pci_dev_busy = 0;
346 void __iomem *mmio_base; 347 void __iomem *mmio_base;
347 int rc; 348 int rc;
348 349
349 if (!printed_version++) 350 if (!printed_version++)
350 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n"); 351 dev_printk(KERN_DEBUG, &pdev->dev, "version " DRV_VERSION "\n");
351 352
352 rc = pci_enable_device(pdev); 353 rc = pcim_enable_device(pdev);
353 if (rc) 354 if (rc)
354 return rc; 355 return rc;
355 356
356 /* 357 /*
357 * Check if we have needed resource mapped. 358 * Check if we have needed resource mapped.
358 */ 359 */
359 if (pci_resource_len(pdev, 0) == 0) { 360 if (pci_resource_len(pdev, 0) == 0)
360 rc = -ENODEV; 361 return -ENODEV;
361 goto err_out;
362 }
363 362
364 rc = pci_request_regions(pdev, DRV_NAME); 363 rc = pcim_iomap_regions(pdev, 1 << VSC_MMIO_BAR, DRV_NAME);
365 if (rc) { 364 if (rc == -EBUSY)
366 pci_dev_busy = 1; 365 pcim_pin_device(pdev);
367 goto err_out; 366 if (rc)
368 } 367 return rc;
369 368
370 /* 369 /*
371 * Use 32 bit DMA mask, because 64 bit address support is poor. 370 * Use 32 bit DMA mask, because 64 bit address support is poor.
372 */ 371 */
373 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK); 372 rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
374 if (rc) 373 if (rc)
375 goto err_out_regions; 374 return rc;
376 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); 375 rc = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
377 if (rc) 376 if (rc)
378 goto err_out_regions; 377 return rc;
379 378
380 probe_ent = kmalloc(sizeof(*probe_ent), GFP_KERNEL); 379 probe_ent = devm_kzalloc(&pdev->dev, sizeof(*probe_ent), GFP_KERNEL);
381 if (probe_ent == NULL) { 380 if (probe_ent == NULL)
382 rc = -ENOMEM; 381 return -ENOMEM;
383 goto err_out_regions;
384 }
385 memset(probe_ent, 0, sizeof(*probe_ent));
386 probe_ent->dev = pci_dev_to_dev(pdev); 382 probe_ent->dev = pci_dev_to_dev(pdev);
387 INIT_LIST_HEAD(&probe_ent->node); 383 INIT_LIST_HEAD(&probe_ent->node);
388 384
389 mmio_base = pci_iomap(pdev, 0, 0);
390 if (mmio_base == NULL) {
391 rc = -ENOMEM;
392 goto err_out_free_ent;
393 }
394 base = (unsigned long) mmio_base;
395
396 /* 385 /*
397 * Due to a bug in the chip, the default cache line size can't be used 386 * Due to a bug in the chip, the default cache line size can't be used
398 */ 387 */
399 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x80); 388 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x80);
400 389
390 if (pci_enable_msi(pdev) == 0)
391 pci_intx(pdev, 0);
392 else
393 probe_ent->irq_flags = IRQF_SHARED;
394
401 probe_ent->sht = &vsc_sata_sht; 395 probe_ent->sht = &vsc_sata_sht;
402 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 396 probe_ent->port_flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
403 ATA_FLAG_MMIO; 397 ATA_FLAG_MMIO;
404 probe_ent->port_ops = &vsc_sata_ops; 398 probe_ent->port_ops = &vsc_sata_ops;
405 probe_ent->n_ports = 4; 399 probe_ent->n_ports = 4;
406 probe_ent->irq = pdev->irq; 400 probe_ent->irq = pdev->irq;
407 probe_ent->irq_flags = IRQF_SHARED; 401 probe_ent->iomap = pcim_iomap_table(pdev);
408 probe_ent->mmio_base = mmio_base;
409 402
410 /* We don't care much about the PIO/UDMA masks, but the core won't like us 403 /* We don't care much about the PIO/UDMA masks, but the core won't like us
411 * if we don't fill these 404 * if we don't fill these
@@ -414,11 +407,13 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d
414 probe_ent->mwdma_mask = 0x07; 407 probe_ent->mwdma_mask = 0x07;
415 probe_ent->udma_mask = 0x7f; 408 probe_ent->udma_mask = 0x7f;
416 409
410 mmio_base = probe_ent->iomap[VSC_MMIO_BAR];
411
417 /* We have 4 ports per PCI function */ 412 /* We have 4 ports per PCI function */
418 vsc_sata_setup_port(&probe_ent->port[0], base + 1 * VSC_SATA_PORT_OFFSET); 413 vsc_sata_setup_port(&probe_ent->port[0], mmio_base + 1 * VSC_SATA_PORT_OFFSET);
419 vsc_sata_setup_port(&probe_ent->port[1], base + 2 * VSC_SATA_PORT_OFFSET); 414 vsc_sata_setup_port(&probe_ent->port[1], mmio_base + 2 * VSC_SATA_PORT_OFFSET);
420 vsc_sata_setup_port(&probe_ent->port[2], base + 3 * VSC_SATA_PORT_OFFSET); 415 vsc_sata_setup_port(&probe_ent->port[2], mmio_base + 3 * VSC_SATA_PORT_OFFSET);
421 vsc_sata_setup_port(&probe_ent->port[3], base + 4 * VSC_SATA_PORT_OFFSET); 416 vsc_sata_setup_port(&probe_ent->port[3], mmio_base + 4 * VSC_SATA_PORT_OFFSET);
422 417
423 pci_set_master(pdev); 418 pci_set_master(pdev);
424 419
@@ -430,20 +425,11 @@ static int __devinit vsc_sata_init_one (struct pci_dev *pdev, const struct pci_d
430 */ 425 */
431 pci_write_config_dword(pdev, 0x98, 0); 426 pci_write_config_dword(pdev, 0x98, 0);
432 427
433 /* FIXME: check ata_device_add return value */ 428 if (!ata_device_add(probe_ent))
434 ata_device_add(probe_ent); 429 return -ENODEV;
435 kfree(probe_ent);
436 430
431 devm_kfree(&pdev->dev, probe_ent);
437 return 0; 432 return 0;
438
439err_out_free_ent:
440 kfree(probe_ent);
441err_out_regions:
442 pci_release_regions(pdev);
443err_out:
444 if (!pci_dev_busy)
445 pci_disable_device(pdev);
446 return rc;
447} 433}
448 434
449static const struct pci_device_id vsc_sata_pci_tbl[] = { 435static const struct pci_device_id vsc_sata_pci_tbl[] = {
diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
index 5aab7bd473a..8fccf018f16 100644
--- a/drivers/atm/eni.c
+++ b/drivers/atm/eni.c
@@ -912,7 +912,6 @@ static int start_rx(struct atm_dev *dev)
912 free_page((unsigned long) eni_dev->free_list); 912 free_page((unsigned long) eni_dev->free_list);
913 return -ENOMEM; 913 return -ENOMEM;
914 } 914 }
915 memset(eni_dev->rx_map,0,PAGE_SIZE);
916 eni_dev->rx_mult = DEFAULT_RX_MULT; 915 eni_dev->rx_mult = DEFAULT_RX_MULT;
917 eni_dev->fast = eni_dev->last_fast = NULL; 916 eni_dev->fast = eni_dev->last_fast = NULL;
918 eni_dev->slow = eni_dev->last_slow = NULL; 917 eni_dev->slow = eni_dev->last_slow = NULL;
diff --git a/drivers/auxdisplay/Kconfig b/drivers/auxdisplay/Kconfig
new file mode 100644
index 00000000000..0300e7f54cc
--- /dev/null
+++ b/drivers/auxdisplay/Kconfig
@@ -0,0 +1,109 @@
1#
2# For a description of the syntax of this configuration file,
3# see Documentation/kbuild/kconfig-language.txt.
4#
5# Auxiliary display drivers configuration.
6#
7
8menu "Auxiliary Display support"
9
10config KS0108
11 tristate "KS0108 LCD Controller"
12 depends on PARPORT_PC
13 default n
14 ---help---
15 If you have a LCD controlled by one or more KS0108
16 controllers, say Y. You will need also another more specific
17 driver for your LCD.
18
19 Depends on Parallel Port support. If you say Y at
20 parport, you will be able to compile this as a module (M)
21 and built-in as well (Y).
22
23 To compile this as a module, choose M here:
24 the module will be called ks0108.
25
26 If unsure, say N.
27
28config KS0108_PORT
29 hex "Parallel port where the LCD is connected"
30 depends on KS0108
31 default 0x378
32 ---help---
33 The address of the parallel port where the LCD is connected.
34
35 The first standard parallel port address is 0x378.
36 The second standard parallel port address is 0x278.
37 The third standard parallel port address is 0x3BC.
38
39 You can specify a different address if you need.
40
41 If you don't know what I'm talking about, load the parport module,
42 and execute "dmesg" or "cat /proc/ioports". You can see there how
43 many parallel ports are present and which address each one has.
44
45 Usually you only need to use 0x378.
46
47 If you compile this as a module, you can still override this
48 using the module parameters.
49
50config KS0108_DELAY
51 int "Delay between each control writing (microseconds)"
52 depends on KS0108
53 default "2"
54 ---help---
55 Amount of time the ks0108 should wait between each control write
56 to the parallel port.
57
58 If your driver seems to miss random writings, increment this.
59
60 If you don't know what I'm talking about, ignore it.
61
62 If you compile this as a module, you can still override this
63 value using the module parameters.
64
65config CFAG12864B
66 tristate "CFAG12864B LCD"
67 depends on X86
68 depends on FB
69 depends on KS0108
70 default n
71 ---help---
72 If you have a Crystalfontz 128x64 2-color LCD, cfag12864b Series,
73 say Y. You also need the ks0108 LCD Controller driver.
74
75 For help about how to wire your LCD to the parallel port,
76 check Documentation/auxdisplay/cfag12864b
77
78 Depends on the x86 arch and the framebuffer support.
79
80 The LCD framebuffer driver can be attached to a console.
81 It will work fine. However, you can't attach it to the fbdev driver
82 of the xorg server.
83
84 To compile this as a module, choose M here:
85 the modules will be called cfag12864b and cfag12864bfb.
86
87 If unsure, say N.
88
89config CFAG12864B_RATE
90 int "Refresh rate (hertz)"
91 depends on CFAG12864B
92 default "20"
93 ---help---
94 Refresh rate of the LCD.
95
96 As the LCD is not memory mapped, the driver has to make the work by
97 software. This means you should be careful setting this value higher.
98 If your CPUs are really slow or you feel the system is slowed down,
99 decrease the value.
100
101 Be careful modifying this value to a very high value:
102 You can freeze the computer, or the LCD maybe can't draw as fast as you
103 are requesting.
104
105 If you don't know what I'm talking about, ignore it.
106
107 If you compile this as a module, you can still override this
108 value using the module parameters.
109endmenu
diff --git a/drivers/auxdisplay/Makefile b/drivers/auxdisplay/Makefile
new file mode 100644
index 00000000000..8a8936a468b
--- /dev/null
+++ b/drivers/auxdisplay/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for the kernel auxiliary displays device drivers.
3#
4
5obj-$(CONFIG_KS0108) += ks0108.o
6obj-$(CONFIG_CFAG12864B) += cfag12864b.o cfag12864bfb.o
diff --git a/drivers/auxdisplay/cfag12864b.c b/drivers/auxdisplay/cfag12864b.c
new file mode 100644
index 00000000000..889583dfc1a
--- /dev/null
+++ b/drivers/auxdisplay/cfag12864b.c
@@ -0,0 +1,383 @@
1/*
2 * Filename: cfag12864b.c
3 * Version: 0.1.0
4 * Description: cfag12864b LCD driver
5 * License: GPLv2
6 * Depends: ks0108
7 *
8 * Author: Copyright (C) Miguel Ojeda Sandonis <maxextreme@gmail.com>
9 * Date: 2006-10-31
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 version 2 as
13 * published by the Free Software Foundation.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/fs.h>
30#include <linux/cdev.h>
31#include <linux/delay.h>
32#include <linux/device.h>
33#include <linux/jiffies.h>
34#include <linux/mutex.h>
35#include <linux/uaccess.h>
36#include <linux/vmalloc.h>
37#include <linux/workqueue.h>
38#include <linux/ks0108.h>
39#include <linux/cfag12864b.h>
40
41
42#define CFAG12864B_NAME "cfag12864b"
43
44/*
45 * Module Parameters
46 */
47
48static unsigned int cfag12864b_rate = CONFIG_CFAG12864B_RATE;
49module_param(cfag12864b_rate, uint, S_IRUGO);
50MODULE_PARM_DESC(cfag12864b_rate,
51 "Refresh rate (hertzs)");
52
53unsigned int cfag12864b_getrate(void)
54{
55 return cfag12864b_rate;
56}
57
58/*
59 * cfag12864b Commands
60 *
61 * E = Enable signal
62 * Everytime E switch from low to high,
63 * cfag12864b/ks0108 reads the command/data.
64 *
65 * CS1 = First ks0108controller.
66 * If high, the first ks0108 controller receives commands/data.
67 *
68 * CS2 = Second ks0108 controller
69 * If high, the second ks0108 controller receives commands/data.
70 *
71 * DI = Data/Instruction
72 * If low, cfag12864b will expect commands.
73 * If high, cfag12864b will expect data.
74 *
75 */
76
77#define bit(n) (((unsigned char)1)<<(n))
78
79#define CFAG12864B_BIT_E (0)
80#define CFAG12864B_BIT_CS1 (2)
81#define CFAG12864B_BIT_CS2 (1)
82#define CFAG12864B_BIT_DI (3)
83
84static unsigned char cfag12864b_state;
85
86static void cfag12864b_set(void)
87{
88 ks0108_writecontrol(cfag12864b_state);
89}
90
91static void cfag12864b_setbit(unsigned char state, unsigned char n)
92{
93 if (state)
94 cfag12864b_state |= bit(n);
95 else
96 cfag12864b_state &= ~bit(n);
97}
98
99static void cfag12864b_e(unsigned char state)
100{
101 cfag12864b_setbit(state, CFAG12864B_BIT_E);
102 cfag12864b_set();
103}
104
105static void cfag12864b_cs1(unsigned char state)
106{
107 cfag12864b_setbit(state, CFAG12864B_BIT_CS1);
108}
109
110static void cfag12864b_cs2(unsigned char state)
111{
112 cfag12864b_setbit(state, CFAG12864B_BIT_CS2);
113}
114
115static void cfag12864b_di(unsigned char state)
116{
117 cfag12864b_setbit(state, CFAG12864B_BIT_DI);
118}
119
120static void cfag12864b_setcontrollers(unsigned char first,
121 unsigned char second)
122{
123 if (first)
124 cfag12864b_cs1(0);
125 else
126 cfag12864b_cs1(1);
127
128 if (second)
129 cfag12864b_cs2(0);
130 else
131 cfag12864b_cs2(1);
132}
133
134static void cfag12864b_controller(unsigned char which)
135{
136 if (which == 0)
137 cfag12864b_setcontrollers(1, 0);
138 else if (which == 1)
139 cfag12864b_setcontrollers(0, 1);
140}
141
142static void cfag12864b_displaystate(unsigned char state)
143{
144 cfag12864b_di(0);
145 cfag12864b_e(1);
146 ks0108_displaystate(state);
147 cfag12864b_e(0);
148}
149
150static void cfag12864b_address(unsigned char address)
151{
152 cfag12864b_di(0);
153 cfag12864b_e(1);
154 ks0108_address(address);
155 cfag12864b_e(0);
156}
157
158static void cfag12864b_page(unsigned char page)
159{
160 cfag12864b_di(0);
161 cfag12864b_e(1);
162 ks0108_page(page);
163 cfag12864b_e(0);
164}
165
166static void cfag12864b_startline(unsigned char startline)
167{
168 cfag12864b_di(0);
169 cfag12864b_e(1);
170 ks0108_startline(startline);
171 cfag12864b_e(0);
172}
173
174static void cfag12864b_writebyte(unsigned char byte)
175{
176 cfag12864b_di(1);
177 cfag12864b_e(1);
178 ks0108_writedata(byte);
179 cfag12864b_e(0);
180}
181
182static void cfag12864b_nop(void)
183{
184 cfag12864b_startline(0);
185}
186
187/*
188 * cfag12864b Internal Commands
189 */
190
191static void cfag12864b_on(void)
192{
193 cfag12864b_setcontrollers(1, 1);
194 cfag12864b_displaystate(1);
195}
196
197static void cfag12864b_off(void)
198{
199 cfag12864b_setcontrollers(1, 1);
200 cfag12864b_displaystate(0);
201}
202
203static void cfag12864b_clear(void)
204{
205 unsigned char i, j;
206
207 cfag12864b_setcontrollers(1, 1);
208 for (i = 0; i < CFAG12864B_PAGES; i++) {
209 cfag12864b_page(i);
210 cfag12864b_address(0);
211 for (j = 0; j < CFAG12864B_ADDRESSES; j++)
212 cfag12864b_writebyte(0);
213 }
214}
215
216/*
217 * Update work
218 */
219
220unsigned char *cfag12864b_buffer;
221static unsigned char *cfag12864b_cache;
222static DEFINE_MUTEX(cfag12864b_mutex);
223static unsigned char cfag12864b_updating;
224static void cfag12864b_update(struct work_struct *delayed_work);
225static struct workqueue_struct *cfag12864b_workqueue;
226static DECLARE_DELAYED_WORK(cfag12864b_work, cfag12864b_update);
227
228static void cfag12864b_queue(void)
229{
230 queue_delayed_work(cfag12864b_workqueue, &cfag12864b_work,
231 HZ / cfag12864b_rate);
232}
233
234unsigned char cfag12864b_enable(void)
235{
236 unsigned char ret;
237
238 mutex_lock(&cfag12864b_mutex);
239
240 if (!cfag12864b_updating) {
241 cfag12864b_updating = 1;
242 cfag12864b_queue();
243 ret = 0;
244 } else
245 ret = 1;
246
247 mutex_unlock(&cfag12864b_mutex);
248
249 return ret;
250}
251
252void cfag12864b_disable(void)
253{
254 mutex_lock(&cfag12864b_mutex);
255
256 if (cfag12864b_updating) {
257 cfag12864b_updating = 0;
258 cancel_delayed_work(&cfag12864b_work);
259 flush_workqueue(cfag12864b_workqueue);
260 }
261
262 mutex_unlock(&cfag12864b_mutex);
263}
264
265unsigned char cfag12864b_isenabled(void)
266{
267 return cfag12864b_updating;
268}
269
270static void cfag12864b_update(struct work_struct *work)
271{
272 unsigned char c;
273 unsigned short i, j, k, b;
274
275 if (memcmp(cfag12864b_cache, cfag12864b_buffer, CFAG12864B_SIZE)) {
276 for (i = 0; i < CFAG12864B_CONTROLLERS; i++) {
277 cfag12864b_controller(i);
278 cfag12864b_nop();
279 for (j = 0; j < CFAG12864B_PAGES; j++) {
280 cfag12864b_page(j);
281 cfag12864b_nop();
282 cfag12864b_address(0);
283 cfag12864b_nop();
284 for (k = 0; k < CFAG12864B_ADDRESSES; k++) {
285 for (c = 0, b = 0; b < 8; b++)
286 if (cfag12864b_buffer
287 [i * CFAG12864B_ADDRESSES / 8
288 + k / 8 + (j * 8 + b) *
289 CFAG12864B_WIDTH / 8]
290 & bit(k % 8))
291 c |= bit(b);
292 cfag12864b_writebyte(c);
293 }
294 }
295 }
296
297 memcpy(cfag12864b_cache, cfag12864b_buffer, CFAG12864B_SIZE);
298 }
299
300 if (cfag12864b_updating)
301 cfag12864b_queue();
302}
303
304/*
305 * cfag12864b Exported Symbols
306 */
307
308EXPORT_SYMBOL_GPL(cfag12864b_buffer);
309EXPORT_SYMBOL_GPL(cfag12864b_getrate);
310EXPORT_SYMBOL_GPL(cfag12864b_enable);
311EXPORT_SYMBOL_GPL(cfag12864b_disable);
312EXPORT_SYMBOL_GPL(cfag12864b_isenabled);
313
314/*
315 * Module Init & Exit
316 */
317
318static int __init cfag12864b_init(void)
319{
320 int ret = -EINVAL;
321
322 if (PAGE_SIZE < CFAG12864B_SIZE) {
323 printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
324 "page size (%i) < cfag12864b size (%i)\n",
325 (unsigned int)PAGE_SIZE, CFAG12864B_SIZE);
326 ret = -ENOMEM;
327 goto none;
328 }
329
330 cfag12864b_buffer = (unsigned char *) __get_free_page(GFP_KERNEL);
331 if (cfag12864b_buffer == NULL) {
332 printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
333 "can't get a free page\n");
334 ret = -ENOMEM;
335 goto none;
336 }
337
338 cfag12864b_cache = kmalloc(sizeof(unsigned char) *
339 CFAG12864B_SIZE, GFP_KERNEL);
340 if (cfag12864b_buffer == NULL) {
341 printk(KERN_ERR CFAG12864B_NAME ": ERROR: "
342 "can't alloc cache buffer (%i bytes)\n",
343 CFAG12864B_SIZE);
344 ret = -ENOMEM;
345 goto bufferalloced;
346 }
347
348 cfag12864b_workqueue = create_singlethread_workqueue(CFAG12864B_NAME);
349 if (cfag12864b_workqueue == NULL)
350 goto cachealloced;
351
352 memset(cfag12864b_buffer, 0, CFAG12864B_SIZE);
353
354 cfag12864b_clear();
355 cfag12864b_on();
356
357 return 0;
358
359cachealloced:
360 kfree(cfag12864b_cache);
361
362bufferalloced:
363 free_page((unsigned long) cfag12864b_buffer);
364
365none:
366 return ret;
367}
368
369static void __exit cfag12864b_exit(void)
370{
371 cfag12864b_disable();
372 cfag12864b_off();
373 destroy_workqueue(cfag12864b_workqueue);
374 kfree(cfag12864b_cache);
375 free_page((unsigned long) cfag12864b_buffer);
376}
377
378module_init(cfag12864b_init);
379module_exit(cfag12864b_exit);
380
381MODULE_LICENSE("GPL v2");
382MODULE_AUTHOR("Miguel Ojeda Sandonis <maxextreme@gmail.com>");
383MODULE_DESCRIPTION("cfag12864b LCD driver");
diff --git a/drivers/auxdisplay/cfag12864bfb.c b/drivers/auxdisplay/cfag12864bfb.c
new file mode 100644
index 00000000000..94765e78315
--- /dev/null
+++ b/drivers/auxdisplay/cfag12864bfb.c
@@ -0,0 +1,180 @@
1/*
2 * Filename: cfag12864bfb.c
3 * Version: 0.1.0
4 * Description: cfag12864b LCD framebuffer driver
5 * License: GPLv2
6 * Depends: cfag12864b
7 *
8 * Author: Copyright (C) Miguel Ojeda Sandonis <maxextreme@gmail.com>
9 * Date: 2006-10-31
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 version 2 as
13 * published by the Free Software Foundation.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/delay.h>
30#include <linux/errno.h>
31#include <linux/fb.h>
32#include <linux/mm.h>
33#include <linux/platform_device.h>
34#include <linux/slab.h>
35#include <linux/string.h>
36#include <linux/uaccess.h>
37#include <linux/cfag12864b.h>
38
39#define CFAG12864BFB_NAME "cfag12864bfb"
40
41static struct fb_fix_screeninfo cfag12864bfb_fix __initdata = {
42 .id = "cfag12864b",
43 .type = FB_TYPE_PACKED_PIXELS,
44 .visual = FB_VISUAL_MONO10,
45 .xpanstep = 0,
46 .ypanstep = 0,
47 .ywrapstep = 0,
48 .line_length = CFAG12864B_WIDTH / 8,
49 .accel = FB_ACCEL_NONE,
50};
51
52static struct fb_var_screeninfo cfag12864bfb_var __initdata = {
53 .xres = CFAG12864B_WIDTH,
54 .yres = CFAG12864B_HEIGHT,
55 .xres_virtual = CFAG12864B_WIDTH,
56 .yres_virtual = CFAG12864B_HEIGHT,
57 .bits_per_pixel = 1,
58 .red = { 0, 1, 0 },
59 .green = { 0, 1, 0 },
60 .blue = { 0, 1, 0 },
61 .left_margin = 0,
62 .right_margin = 0,
63 .upper_margin = 0,
64 .lower_margin = 0,
65 .vmode = FB_VMODE_NONINTERLACED,
66};
67
68static int cfag12864bfb_mmap(struct fb_info *info, struct vm_area_struct *vma)
69{
70 return vm_insert_page(vma, vma->vm_start,
71 virt_to_page(cfag12864b_buffer));
72}
73
74static struct fb_ops cfag12864bfb_ops = {
75 .owner = THIS_MODULE,
76 .fb_fillrect = cfb_fillrect,
77 .fb_copyarea = cfb_copyarea,
78 .fb_imageblit = cfb_imageblit,
79 .fb_mmap = cfag12864bfb_mmap,
80};
81
82static int __init cfag12864bfb_probe(struct platform_device *device)
83{
84 int ret = -EINVAL;
85 struct fb_info *info = framebuffer_alloc(0, &device->dev);
86
87 if (!info)
88 goto none;
89
90 info->screen_base = (char __iomem *) cfag12864b_buffer;
91 info->screen_size = CFAG12864B_SIZE;
92 info->fbops = &cfag12864bfb_ops;
93 info->fix = cfag12864bfb_fix;
94 info->var = cfag12864bfb_var;
95 info->pseudo_palette = NULL;
96 info->par = NULL;
97 info->flags = FBINFO_FLAG_DEFAULT;
98
99 if (register_framebuffer(info) < 0)
100 goto fballoced;
101
102 platform_set_drvdata(device, info);
103
104 printk(KERN_INFO "fb%d: %s frame buffer device\n", info->node,
105 info->fix.id);
106
107 return 0;
108
109fballoced:
110 framebuffer_release(info);
111
112none:
113 return ret;
114}
115
116static int cfag12864bfb_remove(struct platform_device *device)
117{
118 struct fb_info *info = platform_get_drvdata(device);
119
120 if (info) {
121 unregister_framebuffer(info);
122 framebuffer_release(info);
123 }
124
125 return 0;
126}
127
128static struct platform_driver cfag12864bfb_driver = {
129 .probe = cfag12864bfb_probe,
130 .remove = cfag12864bfb_remove,
131 .driver = {
132 .name = CFAG12864BFB_NAME,
133 },
134};
135
136static struct platform_device *cfag12864bfb_device;
137
138static int __init cfag12864bfb_init(void)
139{
140 int ret;
141
142 if (cfag12864b_enable()) {
143 printk(KERN_ERR CFAG12864BFB_NAME ": ERROR: "
144 "can't enable cfag12864b refreshing (being used)\n");
145 return -ENODEV;
146 }
147
148 ret = platform_driver_register(&cfag12864bfb_driver);
149
150 if (!ret) {
151 cfag12864bfb_device =
152 platform_device_alloc(CFAG12864BFB_NAME, 0);
153
154 if (cfag12864bfb_device)
155 ret = platform_device_add(cfag12864bfb_device);
156 else
157 ret = -ENOMEM;
158
159 if (ret) {
160 platform_device_put(cfag12864bfb_device);
161 platform_driver_unregister(&cfag12864bfb_driver);
162 }
163 }
164
165 return ret;
166}
167
168static void __exit cfag12864bfb_exit(void)
169{
170 platform_device_unregister(cfag12864bfb_device);
171 platform_driver_unregister(&cfag12864bfb_driver);
172 cfag12864b_disable();
173}
174
175module_init(cfag12864bfb_init);
176module_exit(cfag12864bfb_exit);
177
178MODULE_LICENSE("GPL v2");
179MODULE_AUTHOR("Miguel Ojeda Sandonis <maxextreme@gmail.com>");
180MODULE_DESCRIPTION("cfag12864b LCD framebuffer driver");
diff --git a/drivers/auxdisplay/ks0108.c b/drivers/auxdisplay/ks0108.c
new file mode 100644
index 00000000000..a637575b910
--- /dev/null
+++ b/drivers/auxdisplay/ks0108.c
@@ -0,0 +1,166 @@
1/*
2 * Filename: ks0108.c
3 * Version: 0.1.0
4 * Description: ks0108 LCD Controller driver
5 * License: GPLv2
6 * Depends: parport
7 *
8 * Author: Copyright (C) Miguel Ojeda Sandonis <maxextreme@gmail.com>
9 * Date: 2006-10-31
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 version 2 as
13 * published by the Free Software Foundation.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/delay.h>
30#include <linux/fs.h>
31#include <linux/io.h>
32#include <linux/parport.h>
33#include <linux/uaccess.h>
34#include <linux/ks0108.h>
35
36#define KS0108_NAME "ks0108"
37
38/*
39 * Module Parameters
40 */
41
42static unsigned int ks0108_port = CONFIG_KS0108_PORT;
43module_param(ks0108_port, uint, S_IRUGO);
44MODULE_PARM_DESC(ks0108_port, "Parallel port where the LCD is connected");
45
46static unsigned int ks0108_delay = CONFIG_KS0108_DELAY;
47module_param(ks0108_delay, uint, S_IRUGO);
48MODULE_PARM_DESC(ks0108_delay, "Delay between each control writing (microseconds)");
49
50/*
51 * Device
52 */
53
54static struct parport *ks0108_parport;
55static struct pardevice *ks0108_pardevice;
56
57/*
58 * ks0108 Exported Commands (don't lock)
59 *
60 * You _should_ lock in the top driver: This functions _should not_
61 * get race conditions in any way. Locking for each byte here would be
62 * so slow and useless.
63 *
64 * There are not bit definitions because they are not flags,
65 * just arbitrary combinations defined by the documentation for each
66 * function in the ks0108 LCD controller. If you want to know what means
67 * a specific combination, look at the function's name.
68 *
69 * The ks0108_writecontrol bits need to be reverted ^(0,1,3) because
70 * the parallel port also revert them using a "not" logic gate.
71 */
72
73#define bit(n) (((unsigned char)1)<<(n))
74
75void ks0108_writedata(unsigned char byte)
76{
77 parport_write_data(ks0108_parport, byte);
78}
79
80void ks0108_writecontrol(unsigned char byte)
81{
82 udelay(ks0108_delay);
83 parport_write_control(ks0108_parport, byte ^ (bit(0) | bit(1) | bit(3)));
84}
85
86void ks0108_displaystate(unsigned char state)
87{
88 ks0108_writedata((state ? bit(0) : 0) | bit(1) | bit(2) | bit(3) | bit(4) | bit(5));
89}
90
91void ks0108_startline(unsigned char startline)
92{
93 ks0108_writedata(min(startline,(unsigned char)63) | bit(6) | bit(7));
94}
95
96void ks0108_address(unsigned char address)
97{
98 ks0108_writedata(min(address,(unsigned char)63) | bit(6));
99}
100
101void ks0108_page(unsigned char page)
102{
103 ks0108_writedata(min(page,(unsigned char)7) | bit(3) | bit(4) | bit(5) | bit(7));
104}
105
106EXPORT_SYMBOL_GPL(ks0108_writedata);
107EXPORT_SYMBOL_GPL(ks0108_writecontrol);
108EXPORT_SYMBOL_GPL(ks0108_displaystate);
109EXPORT_SYMBOL_GPL(ks0108_startline);
110EXPORT_SYMBOL_GPL(ks0108_address);
111EXPORT_SYMBOL_GPL(ks0108_page);
112
113/*
114 * Module Init & Exit
115 */
116
117static int __init ks0108_init(void)
118{
119 int result;
120 int ret = -EINVAL;
121
122 ks0108_parport = parport_find_base(ks0108_port);
123 if (ks0108_parport == NULL) {
124 printk(KERN_ERR KS0108_NAME ": ERROR: "
125 "parport didn't find %i port\n", ks0108_port);
126 goto none;
127 }
128
129 ks0108_pardevice = parport_register_device(ks0108_parport, KS0108_NAME,
130 NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
131 if (ks0108_pardevice == NULL) {
132 printk(KERN_ERR KS0108_NAME ": ERROR: "
133 "parport didn't register new device\n");
134 goto none;
135 }
136
137 result = parport_claim(ks0108_pardevice);
138 if (result != 0) {
139 printk(KERN_ERR KS0108_NAME ": ERROR: "
140 "can't claim %i parport, maybe in use\n", ks0108_port);
141 ret = result;
142 goto registered;
143 }
144
145 return 0;
146
147registered:
148 parport_unregister_device(ks0108_pardevice);
149
150none:
151 return ret;
152}
153
154static void __exit ks0108_exit(void)
155{
156 parport_release(ks0108_pardevice);
157 parport_unregister_device(ks0108_pardevice);
158}
159
160module_init(ks0108_init);
161module_exit(ks0108_exit);
162
163MODULE_LICENSE("GPL v2");
164MODULE_AUTHOR("Miguel Ojeda Sandonis <maxextreme@gmail.com>");
165MODULE_DESCRIPTION("ks0108 LCD Controller driver");
166
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 1429f3a2629..5d6312e3349 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -37,6 +37,18 @@ config DEBUG_DRIVER
37 37
38 If you are unsure about this, say N here. 38 If you are unsure about this, say N here.
39 39
40config DEBUG_DEVRES
41 bool "Managed device resources verbose debug messages"
42 depends on DEBUG_KERNEL
43 help
44 This option enables kernel parameter devres.log. If set to
45 non-zero, devres debug messages are printed. Select this if
46 you are having a problem with devres or want to debug
47 resource management for a managed device. devres.log can be
48 switched on and off from sysfs node.
49
50 If you are unsure about this, Say N here.
51
40config SYS_HYPERVISOR 52config SYS_HYPERVISOR
41 bool 53 bool
42 default n 54 default n
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 7bbb9eeda23..e9eb7382ac3 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -3,6 +3,7 @@
3obj-y := core.o sys.o bus.o dd.o \ 3obj-y := core.o sys.o bus.o dd.o \
4 driver.o class.o platform.o \ 4 driver.o class.o platform.o \
5 cpu.o firmware.o init.o map.o dmapool.o \ 5 cpu.o firmware.o init.o map.o dmapool.o \
6 dma-mapping.o devres.o \
6 attribute_container.o transport_class.o 7 attribute_container.o transport_class.o
7obj-y += power/ 8obj-y += power/
8obj-$(CONFIG_ISA) += isa.o 9obj-$(CONFIG_ISA) += isa.o
diff --git a/drivers/base/base.h b/drivers/base/base.h
index d26644a5953..de7e1442ce6 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -44,3 +44,4 @@ struct class_device_attribute *to_class_dev_attr(struct attribute *_attr)
44 44
45extern char *make_class_name(const char *name, struct kobject *kobj); 45extern char *make_class_name(const char *name, struct kobject *kobj);
46 46
47extern void devres_release_all(struct device *dev);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index e13614241c9..a8ac34ba610 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -428,6 +428,8 @@ void device_initialize(struct device *dev)
428 INIT_LIST_HEAD(&dev->dma_pools); 428 INIT_LIST_HEAD(&dev->dma_pools);
429 INIT_LIST_HEAD(&dev->node); 429 INIT_LIST_HEAD(&dev->node);
430 init_MUTEX(&dev->sem); 430 init_MUTEX(&dev->sem);
431 spin_lock_init(&dev->devres_lock);
432 INIT_LIST_HEAD(&dev->devres_head);
431 device_init_wakeup(dev, 0); 433 device_init_wakeup(dev, 0);
432 set_dev_node(dev, -1); 434 set_dev_node(dev, -1);
433} 435}
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index b5bf243d9cd..6a48824e43f 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -112,6 +112,7 @@ static int really_probe(void *void_data)
112 atomic_inc(&probe_count); 112 atomic_inc(&probe_count);
113 pr_debug("%s: Probing driver %s with device %s\n", 113 pr_debug("%s: Probing driver %s with device %s\n",
114 drv->bus->name, drv->name, dev->bus_id); 114 drv->bus->name, drv->name, dev->bus_id);
115 WARN_ON(!list_empty(&dev->devres_head));
115 116
116 dev->driver = drv; 117 dev->driver = drv;
117 if (driver_sysfs_add(dev)) { 118 if (driver_sysfs_add(dev)) {
@@ -137,6 +138,7 @@ static int really_probe(void *void_data)
137 goto done; 138 goto done;
138 139
139probe_failed: 140probe_failed:
141 devres_release_all(dev);
140 driver_sysfs_remove(dev); 142 driver_sysfs_remove(dev);
141 dev->driver = NULL; 143 dev->driver = NULL;
142 144
@@ -327,6 +329,7 @@ static void __device_release_driver(struct device * dev)
327 dev->bus->remove(dev); 329 dev->bus->remove(dev);
328 else if (drv->remove) 330 else if (drv->remove)
329 drv->remove(dev); 331 drv->remove(dev);
332 devres_release_all(dev);
330 dev->driver = NULL; 333 dev->driver = NULL;
331 put_driver(drv); 334 put_driver(drv);
332 } 335 }
diff --git a/drivers/base/devres.c b/drivers/base/devres.c
new file mode 100644
index 00000000000..e177c9533b6
--- /dev/null
+++ b/drivers/base/devres.c
@@ -0,0 +1,644 @@
1/*
2 * drivers/base/devres.c - device resource management
3 *
4 * Copyright (c) 2006 SUSE Linux Products GmbH
5 * Copyright (c) 2006 Tejun Heo <teheo@suse.de>
6 *
7 * This file is released under the GPLv2.
8 */
9
10#include <linux/device.h>
11#include <linux/module.h>
12
13struct devres_node {
14 struct list_head entry;
15 dr_release_t release;
16#ifdef CONFIG_DEBUG_DEVRES
17 const char *name;
18 size_t size;
19#endif
20};
21
22struct devres {
23 struct devres_node node;
24 /* -- 3 pointers */
25 unsigned long long data[]; /* guarantee ull alignment */
26};
27
28struct devres_group {
29 struct devres_node node[2];
30 void *id;
31 int color;
32 /* -- 8 pointers */
33};
34
35#ifdef CONFIG_DEBUG_DEVRES
36static int log_devres = 0;
37module_param_named(log, log_devres, int, S_IRUGO | S_IWUSR);
38
39static void set_node_dbginfo(struct devres_node *node, const char *name,
40 size_t size)
41{
42 node->name = name;
43 node->size = size;
44}
45
46static void devres_log(struct device *dev, struct devres_node *node,
47 const char *op)
48{
49 if (unlikely(log_devres))
50 dev_printk(KERN_ERR, dev, "DEVRES %3s %p %s (%lu bytes)\n",
51 op, node, node->name, (unsigned long)node->size);
52}
53#else /* CONFIG_DEBUG_DEVRES */
54#define set_node_dbginfo(node, n, s) do {} while (0)
55#define devres_log(dev, node, op) do {} while (0)
56#endif /* CONFIG_DEBUG_DEVRES */
57
58/*
59 * Release functions for devres group. These callbacks are used only
60 * for identification.
61 */
62static void group_open_release(struct device *dev, void *res)
63{
64 /* noop */
65}
66
67static void group_close_release(struct device *dev, void *res)
68{
69 /* noop */
70}
71
72static struct devres_group * node_to_group(struct devres_node *node)
73{
74 if (node->release == &group_open_release)
75 return container_of(node, struct devres_group, node[0]);
76 if (node->release == &group_close_release)
77 return container_of(node, struct devres_group, node[1]);
78 return NULL;
79}
80
81static __always_inline struct devres * alloc_dr(dr_release_t release,
82 size_t size, gfp_t gfp)
83{
84 size_t tot_size = sizeof(struct devres) + size;
85 struct devres *dr;
86
87 dr = kmalloc_track_caller(tot_size, gfp);
88 if (unlikely(!dr))
89 return NULL;
90
91 memset(dr, 0, tot_size);
92 INIT_LIST_HEAD(&dr->node.entry);
93 dr->node.release = release;
94 return dr;
95}
96
97static void add_dr(struct device *dev, struct devres_node *node)
98{
99 devres_log(dev, node, "ADD");
100 BUG_ON(!list_empty(&node->entry));
101 list_add_tail(&node->entry, &dev->devres_head);
102}
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
118void * __devres_alloc(dr_release_t release, size_t size, gfp_t gfp,
119 const char *name)
120{
121 struct devres *dr;
122
123 dr = alloc_dr(release, size, gfp);
124 if (unlikely(!dr))
125 return NULL;
126 set_node_dbginfo(&dr->node, name, size);
127 return dr->data;
128}
129EXPORT_SYMBOL_GPL(__devres_alloc);
130#else
131void * devres_alloc(dr_release_t release, size_t size, gfp_t gfp)
132{
133 struct devres *dr;
134
135 dr = alloc_dr(release, size, gfp);
136 if (unlikely(!dr))
137 return NULL;
138 return dr->data;
139}
140EXPORT_SYMBOL_GPL(devres_alloc);
141#endif
142
143/**
144 * devres_free - Free device resource data
145 * @res: Pointer to devres data to free
146 *
147 * Free devres created with devres_alloc().
148 */
149void devres_free(void *res)
150{
151 if (res) {
152 struct devres *dr = container_of(res, struct devres, data);
153
154 BUG_ON(!list_empty(&dr->node.entry));
155 kfree(dr);
156 }
157}
158EXPORT_SYMBOL_GPL(devres_free);
159
160/**
161 * devres_add - Register device resource
162 * @dev: Device to add resource to
163 * @res: Resource to register
164 *
165 * Register devres @res to @dev. @res should have been allocated
166 * using devres_alloc(). On driver detach, the associated release
167 * function will be invoked and devres will be freed automatically.
168 */
169void devres_add(struct device *dev, void *res)
170{
171 struct devres *dr = container_of(res, struct devres, data);
172 unsigned long flags;
173
174 spin_lock_irqsave(&dev->devres_lock, flags);
175 add_dr(dev, &dr->node);
176 spin_unlock_irqrestore(&dev->devres_lock, flags);
177}
178EXPORT_SYMBOL_GPL(devres_add);
179
180static struct devres *find_dr(struct device *dev, dr_release_t release,
181 dr_match_t match, void *match_data)
182{
183 struct devres_node *node;
184
185 list_for_each_entry_reverse(node, &dev->devres_head, entry) {
186 struct devres *dr = container_of(node, struct devres, node);
187
188 if (node->release != release)
189 continue;
190 if (match && !match(dev, dr->data, match_data))
191 continue;
192 return dr;
193 }
194
195 return NULL;
196}
197
198/**
199 * devres_find - Find device resource
200 * @dev: Device to lookup resource from
201 * @release: Look for resources associated with this release function
202 * @match: Match function (optional)
203 * @match_data: Data for the match function
204 *
205 * Find the latest devres of @dev which is associated with @release
206 * and for which @match returns 1. If @match is NULL, it's considered
207 * to match all.
208 *
209 * RETURNS:
210 * Pointer to found devres, NULL if not found.
211 */
212void * devres_find(struct device *dev, dr_release_t release,
213 dr_match_t match, void *match_data)
214{
215 struct devres *dr;
216 unsigned long flags;
217
218 spin_lock_irqsave(&dev->devres_lock, flags);
219 dr = find_dr(dev, release, match, match_data);
220 spin_unlock_irqrestore(&dev->devres_lock, flags);
221
222 if (dr)
223 return dr->data;
224 return NULL;
225}
226EXPORT_SYMBOL_GPL(devres_find);
227
228/**
229 * devres_get - Find devres, if non-existent, add one atomically
230 * @dev: Device to lookup or add devres for
231 * @new_res: Pointer to new initialized devres to add if not found
232 * @match: Match function (optional)
233 * @match_data: Data for the match function
234 *
235 * Find the latest devres of @dev which has the same release function
236 * as @new_res and for which @match return 1. If found, @new_res is
237 * freed; otherwise, @new_res is added atomically.
238 *
239 * RETURNS:
240 * Pointer to found or added devres.
241 */
242void * devres_get(struct device *dev, void *new_res,
243 dr_match_t match, void *match_data)
244{
245 struct devres *new_dr = container_of(new_res, struct devres, data);
246 struct devres *dr;
247 unsigned long flags;
248
249 spin_lock_irqsave(&dev->devres_lock, flags);
250 dr = find_dr(dev, new_dr->node.release, match, match_data);
251 if (!dr) {
252 add_dr(dev, &new_dr->node);
253 dr = new_dr;
254 new_dr = NULL;
255 }
256 spin_unlock_irqrestore(&dev->devres_lock, flags);
257 devres_free(new_dr);
258
259 return dr->data;
260}
261EXPORT_SYMBOL_GPL(devres_get);
262
263/**
264 * devres_remove - Find a device resource and remove it
265 * @dev: Device to find resource from
266 * @release: Look for resources associated with this release function
267 * @match: Match function (optional)
268 * @match_data: Data for the match function
269 *
270 * Find the latest devres of @dev associated with @release and for
271 * which @match returns 1. If @match is NULL, it's considered to
272 * match all. If found, the resource is removed atomically and
273 * returned.
274 *
275 * RETURNS:
276 * Pointer to removed devres on success, NULL if not found.
277 */
278void * devres_remove(struct device *dev, dr_release_t release,
279 dr_match_t match, void *match_data)
280{
281 struct devres *dr;
282 unsigned long flags;
283
284 spin_lock_irqsave(&dev->devres_lock, flags);
285 dr = find_dr(dev, release, match, match_data);
286 if (dr) {
287 list_del_init(&dr->node.entry);
288 devres_log(dev, &dr->node, "REM");
289 }
290 spin_unlock_irqrestore(&dev->devres_lock, flags);
291
292 if (dr)
293 return dr->data;
294 return NULL;
295}
296EXPORT_SYMBOL_GPL(devres_remove);
297
298/**
299 * devres_destroy - Find a device resource and destroy it
300 * @dev: Device to find resource from
301 * @release: Look for resources associated with this release function
302 * @match: Match function (optional)
303 * @match_data: Data for the match function
304 *
305 * Find the latest devres of @dev associated with @release and for
306 * which @match returns 1. If @match is NULL, it's considered to
307 * match all. If found, the resource is removed atomically and freed.
308 *
309 * RETURNS:
310 * 0 if devres is found and freed, -ENOENT if not found.
311 */
312int devres_destroy(struct device *dev, dr_release_t release,
313 dr_match_t match, void *match_data)
314{
315 void *res;
316
317 res = devres_remove(dev, release, match, match_data);
318 if (unlikely(!res))
319 return -ENOENT;
320
321 devres_free(res);
322 return 0;
323}
324EXPORT_SYMBOL_GPL(devres_destroy);
325
326static int remove_nodes(struct device *dev,
327 struct list_head *first, struct list_head *end,
328 struct list_head *todo)
329{
330 int cnt = 0, nr_groups = 0;
331 struct list_head *cur;
332
333 /* First pass - move normal devres entries to @todo and clear
334 * devres_group colors.
335 */
336 cur = first;
337 while (cur != end) {
338 struct devres_node *node;
339 struct devres_group *grp;
340
341 node = list_entry(cur, struct devres_node, entry);
342 cur = cur->next;
343
344 grp = node_to_group(node);
345 if (grp) {
346 /* clear color of group markers in the first pass */
347 grp->color = 0;
348 nr_groups++;
349 } else {
350 /* regular devres entry */
351 if (&node->entry == first)
352 first = first->next;
353 list_move_tail(&node->entry, todo);
354 cnt++;
355 }
356 }
357
358 if (!nr_groups)
359 return cnt;
360
361 /* Second pass - Scan groups and color them. A group gets
362 * color value of two iff the group is wholly contained in
363 * [cur, end). That is, for a closed group, both opening and
364 * closing markers should be in the range, while just the
365 * opening marker is enough for an open group.
366 */
367 cur = first;
368 while (cur != end) {
369 struct devres_node *node;
370 struct devres_group *grp;
371
372 node = list_entry(cur, struct devres_node, entry);
373 cur = cur->next;
374
375 grp = node_to_group(node);
376 BUG_ON(!grp || list_empty(&grp->node[0].entry));
377
378 grp->color++;
379 if (list_empty(&grp->node[1].entry))
380 grp->color++;
381
382 BUG_ON(grp->color <= 0 || grp->color > 2);
383 if (grp->color == 2) {
384 /* No need to update cur or end. The removed
385 * nodes are always before both.
386 */
387 list_move_tail(&grp->node[0].entry, todo);
388 list_del_init(&grp->node[1].entry);
389 }
390 }
391
392 return cnt;
393}
394
395static int release_nodes(struct device *dev, struct list_head *first,
396 struct list_head *end, unsigned long flags)
397{
398 LIST_HEAD(todo);
399 int cnt;
400 struct devres *dr, *tmp;
401
402 cnt = remove_nodes(dev, first, end, &todo);
403
404 spin_unlock_irqrestore(&dev->devres_lock, flags);
405
406 /* Release. Note that both devres and devres_group are
407 * handled as devres in the following loop. This is safe.
408 */
409 list_for_each_entry_safe_reverse(dr, tmp, &todo, node.entry) {
410 devres_log(dev, &dr->node, "REL");
411 dr->node.release(dev, dr->data);
412 kfree(dr);
413 }
414
415 return cnt;
416}
417
418/**
419 * devres_release_all - Release all resources
420 * @dev: Device to release resources for
421 *
422 * Release all resources associated with @dev. This function is
423 * called on driver detach.
424 */
425int devres_release_all(struct device *dev)
426{
427 unsigned long flags;
428
429 spin_lock_irqsave(&dev->devres_lock, flags);
430 return release_nodes(dev, dev->devres_head.next, &dev->devres_head,
431 flags);
432}
433
434/**
435 * devres_open_group - Open a new devres group
436 * @dev: Device to open devres group for
437 * @id: Separator ID
438 * @gfp: Allocation flags
439 *
440 * Open a new devres group for @dev with @id. For @id, using a
441 * pointer to an object which won't be used for another group is
442 * recommended. If @id is NULL, address-wise unique ID is created.
443 *
444 * RETURNS:
445 * ID of the new group, NULL on failure.
446 */
447void * devres_open_group(struct device *dev, void *id, gfp_t gfp)
448{
449 struct devres_group *grp;
450 unsigned long flags;
451
452 grp = kmalloc(sizeof(*grp), gfp);
453 if (unlikely(!grp))
454 return NULL;
455
456 grp->node[0].release = &group_open_release;
457 grp->node[1].release = &group_close_release;
458 INIT_LIST_HEAD(&grp->node[0].entry);
459 INIT_LIST_HEAD(&grp->node[1].entry);
460 set_node_dbginfo(&grp->node[0], "grp<", 0);
461 set_node_dbginfo(&grp->node[1], "grp>", 0);
462 grp->id = grp;
463 if (id)
464 grp->id = id;
465
466 spin_lock_irqsave(&dev->devres_lock, flags);
467 add_dr(dev, &grp->node[0]);
468 spin_unlock_irqrestore(&dev->devres_lock, flags);
469 return grp->id;
470}
471EXPORT_SYMBOL_GPL(devres_open_group);
472
473/* Find devres group with ID @id. If @id is NULL, look for the latest. */
474static struct devres_group * find_group(struct device *dev, void *id)
475{
476 struct devres_node *node;
477
478 list_for_each_entry_reverse(node, &dev->devres_head, entry) {
479 struct devres_group *grp;
480
481 if (node->release != &group_open_release)
482 continue;
483
484 grp = container_of(node, struct devres_group, node[0]);
485
486 if (id) {
487 if (grp->id == id)
488 return grp;
489 } else if (list_empty(&grp->node[1].entry))
490 return grp;
491 }
492
493 return NULL;
494}
495
496/**
497 * devres_close_group - Close a devres group
498 * @dev: Device to close devres group for
499 * @id: ID of target group, can be NULL
500 *
501 * Close the group identified by @id. If @id is NULL, the latest open
502 * group is selected.
503 */
504void devres_close_group(struct device *dev, void *id)
505{
506 struct devres_group *grp;
507 unsigned long flags;
508
509 spin_lock_irqsave(&dev->devres_lock, flags);
510
511 grp = find_group(dev, id);
512 if (grp)
513 add_dr(dev, &grp->node[1]);
514 else
515 WARN_ON(1);
516
517 spin_unlock_irqrestore(&dev->devres_lock, flags);
518}
519EXPORT_SYMBOL_GPL(devres_close_group);
520
521/**
522 * devres_remove_group - Remove a devres group
523 * @dev: Device to remove group for
524 * @id: ID of target group, can be NULL
525 *
526 * Remove the group identified by @id. If @id is NULL, the latest
527 * open group is selected. Note that removing a group doesn't affect
528 * any other resources.
529 */
530void devres_remove_group(struct device *dev, void *id)
531{
532 struct devres_group *grp;
533 unsigned long flags;
534
535 spin_lock_irqsave(&dev->devres_lock, flags);
536
537 grp = find_group(dev, id);
538 if (grp) {
539 list_del_init(&grp->node[0].entry);
540 list_del_init(&grp->node[1].entry);
541 devres_log(dev, &grp->node[0], "REM");
542 } else
543 WARN_ON(1);
544
545 spin_unlock_irqrestore(&dev->devres_lock, flags);
546
547 kfree(grp);
548}
549EXPORT_SYMBOL_GPL(devres_remove_group);
550
551/**
552 * devres_release_group - Release resources in a devres group
553 * @dev: Device to release group for
554 * @id: ID of target group, can be NULL
555 *
556 * Release all resources in the group identified by @id. If @id is
557 * NULL, the latest open group is selected. The selected group and
558 * groups properly nested inside the selected group are removed.
559 *
560 * RETURNS:
561 * The number of released non-group resources.
562 */
563int devres_release_group(struct device *dev, void *id)
564{
565 struct devres_group *grp;
566 unsigned long flags;
567 int cnt = 0;
568
569 spin_lock_irqsave(&dev->devres_lock, flags);
570
571 grp = find_group(dev, id);
572 if (grp) {
573 struct list_head *first = &grp->node[0].entry;
574 struct list_head *end = &dev->devres_head;
575
576 if (!list_empty(&grp->node[1].entry))
577 end = grp->node[1].entry.next;
578
579 cnt = release_nodes(dev, first, end, flags);
580 } else {
581 WARN_ON(1);
582 spin_unlock_irqrestore(&dev->devres_lock, flags);
583 }
584
585 return cnt;
586}
587EXPORT_SYMBOL_GPL(devres_release_group);
588
589/*
590 * Managed kzalloc/kfree
591 */
592static void devm_kzalloc_release(struct device *dev, void *res)
593{
594 /* noop */
595}
596
597static int devm_kzalloc_match(struct device *dev, void *res, void *data)
598{
599 return res == data;
600}
601
602/**
603 * devm_kzalloc - Managed kzalloc
604 * @dev: Device to allocate memory for
605 * @size: Allocation size
606 * @gfp: Allocation gfp flags
607 *
608 * Managed kzalloc. Memory allocated with this function is
609 * automatically freed on driver detach. Like all other devres
610 * resources, guaranteed alignment is unsigned long long.
611 *
612 * RETURNS:
613 * Pointer to allocated memory on success, NULL on failure.
614 */
615void * devm_kzalloc(struct device *dev, size_t size, gfp_t gfp)
616{
617 struct devres *dr;
618
619 /* use raw alloc_dr for kmalloc caller tracing */
620 dr = alloc_dr(devm_kzalloc_release, size, gfp);
621 if (unlikely(!dr))
622 return NULL;
623
624 set_node_dbginfo(&dr->node, "devm_kzalloc_release", size);
625 devres_add(dev, dr->data);
626 return dr->data;
627}
628EXPORT_SYMBOL_GPL(devm_kzalloc);
629
630/**
631 * devm_kfree - Managed kfree
632 * @dev: Device this memory belongs to
633 * @p: Memory to free
634 *
635 * Free memory allocated with dev_kzalloc().
636 */
637void devm_kfree(struct device *dev, void *p)
638{
639 int rc;
640
641 rc = devres_destroy(dev, devm_kzalloc_release, devm_kzalloc_match, p);
642 WARN_ON(rc);
643}
644EXPORT_SYMBOL_GPL(devm_kfree);
diff --git a/drivers/base/dma-mapping.c b/drivers/base/dma-mapping.c
new file mode 100644
index 00000000000..ca9186f70a6
--- /dev/null
+++ b/drivers/base/dma-mapping.c
@@ -0,0 +1,218 @@
1/*
2 * drivers/base/dma-mapping.c - arch-independent dma-mapping routines
3 *
4 * Copyright (c) 2006 SUSE Linux Products GmbH
5 * Copyright (c) 2006 Tejun Heo <teheo@suse.de>
6 *
7 * This file is released under the GPLv2.
8 */
9
10#include <linux/dma-mapping.h>
11
12/*
13 * Managed DMA API
14 */
15struct dma_devres {
16 size_t size;
17 void *vaddr;
18 dma_addr_t dma_handle;
19};
20
21static void dmam_coherent_release(struct device *dev, void *res)
22{
23 struct dma_devres *this = res;
24
25 dma_free_coherent(dev, this->size, this->vaddr, this->dma_handle);
26}
27
28static void dmam_noncoherent_release(struct device *dev, void *res)
29{
30 struct dma_devres *this = res;
31
32 dma_free_noncoherent(dev, this->size, this->vaddr, this->dma_handle);
33}
34
35static int dmam_match(struct device *dev, void *res, void *match_data)
36{
37 struct dma_devres *this = res, *match = match_data;
38
39 if (this->vaddr == match->vaddr) {
40 WARN_ON(this->size != match->size ||
41 this->dma_handle != match->dma_handle);
42 return 1;
43 }
44 return 0;
45}
46
47/**
48 * dmam_alloc_coherent - Managed dma_alloc_coherent()
49 * @dev: Device to allocate coherent memory for
50 * @size: Size of allocation
51 * @dma_handle: Out argument for allocated DMA handle
52 * @gfp: Allocation flags
53 *
54 * Managed dma_alloc_coherent(). Memory allocated using this function
55 * will be automatically released on driver detach.
56 *
57 * RETURNS:
58 * Pointer to allocated memory on success, NULL on failure.
59 */
60void * dmam_alloc_coherent(struct device *dev, size_t size,
61 dma_addr_t *dma_handle, gfp_t gfp)
62{
63 struct dma_devres *dr;
64 void *vaddr;
65
66 dr = devres_alloc(dmam_coherent_release, sizeof(*dr), gfp);
67 if (!dr)
68 return NULL;
69
70 vaddr = dma_alloc_coherent(dev, size, dma_handle, gfp);
71 if (!vaddr) {
72 devres_free(dr);
73 return NULL;
74 }
75
76 dr->vaddr = vaddr;
77 dr->dma_handle = *dma_handle;
78 dr->size = size;
79
80 devres_add(dev, dr);
81
82 return vaddr;
83}
84EXPORT_SYMBOL(dmam_alloc_coherent);
85
86/**
87 * dmam_free_coherent - Managed dma_free_coherent()
88 * @dev: Device to free coherent memory for
89 * @size: Size of allocation
90 * @vaddr: Virtual address of the memory to free
91 * @dma_handle: DMA handle of the memory to free
92 *
93 * Managed dma_free_coherent().
94 */
95void dmam_free_coherent(struct device *dev, size_t size, void *vaddr,
96 dma_addr_t dma_handle)
97{
98 struct dma_devres match_data = { size, vaddr, dma_handle };
99
100 dma_free_coherent(dev, size, vaddr, dma_handle);
101 WARN_ON(devres_destroy(dev, dmam_coherent_release, dmam_match,
102 &match_data));
103}
104EXPORT_SYMBOL(dmam_free_coherent);
105
106/**
107 * dmam_alloc_non_coherent - Managed dma_alloc_non_coherent()
108 * @dev: Device to allocate non_coherent memory for
109 * @size: Size of allocation
110 * @dma_handle: Out argument for allocated DMA handle
111 * @gfp: Allocation flags
112 *
113 * Managed dma_alloc_non_coherent(). Memory allocated using this
114 * function will be automatically released on driver detach.
115 *
116 * RETURNS:
117 * Pointer to allocated memory on success, NULL on failure.
118 */
119void *dmam_alloc_noncoherent(struct device *dev, size_t size,
120 dma_addr_t *dma_handle, gfp_t gfp)
121{
122 struct dma_devres *dr;
123 void *vaddr;
124
125 dr = devres_alloc(dmam_noncoherent_release, sizeof(*dr), gfp);
126 if (!dr)
127 return NULL;
128
129 vaddr = dma_alloc_noncoherent(dev, size, dma_handle, gfp);
130 if (!vaddr) {
131 devres_free(dr);
132 return NULL;
133 }
134
135 dr->vaddr = vaddr;
136 dr->dma_handle = *dma_handle;
137 dr->size = size;
138
139 devres_add(dev, dr);
140
141 return vaddr;
142}
143EXPORT_SYMBOL(dmam_alloc_noncoherent);
144
145/**
146 * dmam_free_coherent - Managed dma_free_noncoherent()
147 * @dev: Device to free noncoherent memory for
148 * @size: Size of allocation
149 * @vaddr: Virtual address of the memory to free
150 * @dma_handle: DMA handle of the memory to free
151 *
152 * Managed dma_free_noncoherent().
153 */
154void dmam_free_noncoherent(struct device *dev, size_t size, void *vaddr,
155 dma_addr_t dma_handle)
156{
157 struct dma_devres match_data = { size, vaddr, dma_handle };
158
159 dma_free_noncoherent(dev, size, vaddr, dma_handle);
160 WARN_ON(!devres_destroy(dev, dmam_noncoherent_release, dmam_match,
161 &match_data));
162}
163EXPORT_SYMBOL(dmam_free_noncoherent);
164
165#ifdef ARCH_HAS_DMA_DECLARE_COHERENT_MEMORY
166
167static void dmam_coherent_decl_release(struct device *dev, void *res)
168{
169 dma_release_declared_memory(dev);
170}
171
172/**
173 * dmam_declare_coherent_memory - Managed dma_declare_coherent_memory()
174 * @dev: Device to declare coherent memory for
175 * @bus_addr: Bus address of coherent memory to be declared
176 * @device_addr: Device address of coherent memory to be declared
177 * @size: Size of coherent memory to be declared
178 * @flags: Flags
179 *
180 * Managed dma_declare_coherent_memory().
181 *
182 * RETURNS:
183 * 0 on success, -errno on failure.
184 */
185int dmam_declare_coherent_memory(struct device *dev, dma_addr_t bus_addr,
186 dma_addr_t device_addr, size_t size, int flags)
187{
188 void *res;
189 int rc;
190
191 res = devres_alloc(dmam_coherent_decl_release, 0, GFP_KERNEL);
192 if (!res)
193 return -ENOMEM;
194
195 rc = dma_declare_coherent_memory(dev, bus_addr, device_addr, size,
196 flags);
197 if (rc == 0)
198 devres_add(dev, res);
199 else
200 devres_free(res);
201
202 return rc;
203}
204EXPORT_SYMBOL(dmam_declare_coherent_memory);
205
206/**
207 * dmam_release_declared_memory - Managed dma_release_declared_memory().
208 * @dev: Device to release declared coherent memory for
209 *
210 * Managed dmam_release_declared_memory().
211 */
212void dmam_release_declared_memory(struct device *dev)
213{
214 WARN_ON(devres_destroy(dev, dmam_coherent_decl_release, NULL, NULL));
215}
216EXPORT_SYMBOL(dmam_release_declared_memory);
217
218#endif
diff --git a/drivers/base/dmapool.c b/drivers/base/dmapool.c
index f95d5027727..cd467c9f33b 100644
--- a/drivers/base/dmapool.c
+++ b/drivers/base/dmapool.c
@@ -415,8 +415,67 @@ dma_pool_free (struct dma_pool *pool, void *vaddr, dma_addr_t dma)
415 spin_unlock_irqrestore (&pool->lock, flags); 415 spin_unlock_irqrestore (&pool->lock, flags);
416} 416}
417 417
418/*
419 * Managed DMA pool
420 */
421static void dmam_pool_release(struct device *dev, void *res)
422{
423 struct dma_pool *pool = *(struct dma_pool **)res;
424
425 dma_pool_destroy(pool);
426}
427
428static int dmam_pool_match(struct device *dev, void *res, void *match_data)
429{
430 return *(struct dma_pool **)res == match_data;
431}
432
433/**
434 * dmam_pool_create - Managed dma_pool_create()
435 * @name: name of pool, for diagnostics
436 * @dev: device that will be doing the DMA
437 * @size: size of the blocks in this pool.
438 * @align: alignment requirement for blocks; must be a power of two
439 * @allocation: returned blocks won't cross this boundary (or zero)
440 *
441 * Managed dma_pool_create(). DMA pool created with this function is
442 * automatically destroyed on driver detach.
443 */
444struct dma_pool *dmam_pool_create(const char *name, struct device *dev,
445 size_t size, size_t align, size_t allocation)
446{
447 struct dma_pool **ptr, *pool;
448
449 ptr = devres_alloc(dmam_pool_release, sizeof(*ptr), GFP_KERNEL);
450 if (!ptr)
451 return NULL;
452
453 pool = *ptr = dma_pool_create(name, dev, size, align, allocation);
454 if (pool)
455 devres_add(dev, ptr);
456 else
457 devres_free(ptr);
458
459 return pool;
460}
461
462/**
463 * dmam_pool_destroy - Managed dma_pool_destroy()
464 * @pool: dma pool that will be destroyed
465 *
466 * Managed dma_pool_destroy().
467 */
468void dmam_pool_destroy(struct dma_pool *pool)
469{
470 struct device *dev = pool->dev;
471
472 dma_pool_destroy(pool);
473 WARN_ON(devres_destroy(dev, dmam_pool_release, dmam_pool_match, pool));
474}
418 475
419EXPORT_SYMBOL (dma_pool_create); 476EXPORT_SYMBOL (dma_pool_create);
420EXPORT_SYMBOL (dma_pool_destroy); 477EXPORT_SYMBOL (dma_pool_destroy);
421EXPORT_SYMBOL (dma_pool_alloc); 478EXPORT_SYMBOL (dma_pool_alloc);
422EXPORT_SYMBOL (dma_pool_free); 479EXPORT_SYMBOL (dma_pool_free);
480EXPORT_SYMBOL (dmam_pool_create);
481EXPORT_SYMBOL (dmam_pool_destroy);
diff --git a/drivers/base/node.c b/drivers/base/node.c
index 001e6f6b9c1..475e33f76e0 100644
--- a/drivers/base/node.c
+++ b/drivers/base/node.c
@@ -40,13 +40,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
40 int n; 40 int n;
41 int nid = dev->id; 41 int nid = dev->id;
42 struct sysinfo i; 42 struct sysinfo i;
43 unsigned long inactive;
44 unsigned long active;
45 unsigned long free;
46 43
47 si_meminfo_node(&i, nid); 44 si_meminfo_node(&i, nid);
48 __get_zone_counts(&active, &inactive, &free, NODE_DATA(nid));
49
50 45
51 n = sprintf(buf, "\n" 46 n = sprintf(buf, "\n"
52 "Node %d MemTotal: %8lu kB\n" 47 "Node %d MemTotal: %8lu kB\n"
@@ -74,8 +69,8 @@ static ssize_t node_read_meminfo(struct sys_device * dev, char * buf)
74 nid, K(i.totalram), 69 nid, K(i.totalram),
75 nid, K(i.freeram), 70 nid, K(i.freeram),
76 nid, K(i.totalram - i.freeram), 71 nid, K(i.totalram - i.freeram),
77 nid, K(active), 72 nid, node_page_state(nid, NR_ACTIVE),
78 nid, K(inactive), 73 nid, node_page_state(nid, NR_INACTIVE),
79#ifdef CONFIG_HIGHMEM 74#ifdef CONFIG_HIGHMEM
80 nid, K(i.totalhigh), 75 nid, K(i.totalhigh),
81 nid, K(i.freehigh), 76 nid, K(i.freehigh),
diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c
index 8d81a3a64c0..92bf868ca05 100644
--- a/drivers/block/DAC960.c
+++ b/drivers/block/DAC960.c
@@ -177,7 +177,7 @@ static void DAC960_AnnounceDriver(DAC960_Controller_T *Controller)
177 DAC960_Failure prints a standardized error message, and then returns false. 177 DAC960_Failure prints a standardized error message, and then returns false.
178*/ 178*/
179 179
180static boolean DAC960_Failure(DAC960_Controller_T *Controller, 180static bool DAC960_Failure(DAC960_Controller_T *Controller,
181 unsigned char *ErrorMessage) 181 unsigned char *ErrorMessage)
182{ 182{
183 DAC960_Error("While configuring DAC960 PCI RAID Controller at\n", 183 DAC960_Error("While configuring DAC960 PCI RAID Controller at\n",
@@ -206,7 +206,7 @@ static boolean DAC960_Failure(DAC960_Controller_T *Controller,
206 that are passed in. 206 that are passed in.
207 */ 207 */
208 208
209static boolean init_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf, 209static bool init_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf,
210 size_t len) 210 size_t len)
211{ 211{
212 void *cpu_addr; 212 void *cpu_addr;
@@ -250,7 +250,7 @@ static void free_dma_loaf(struct pci_dev *dev, struct dma_loaf *loaf_handle)
250 failure. 250 failure.
251*/ 251*/
252 252
253static boolean DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller) 253static bool DAC960_CreateAuxiliaryStructures(DAC960_Controller_T *Controller)
254{ 254{
255 int CommandAllocationLength, CommandAllocationGroupSize; 255 int CommandAllocationLength, CommandAllocationGroupSize;
256 int CommandsRemaining = 0, CommandIdentifier, CommandGroupByteCount; 256 int CommandsRemaining = 0, CommandIdentifier, CommandGroupByteCount;
@@ -790,7 +790,7 @@ static void DAC960_ExecuteCommand(DAC960_Command_T *Command)
790 on failure. 790 on failure.
791*/ 791*/
792 792
793static boolean DAC960_V1_ExecuteType3(DAC960_Controller_T *Controller, 793static bool DAC960_V1_ExecuteType3(DAC960_Controller_T *Controller,
794 DAC960_V1_CommandOpcode_T CommandOpcode, 794 DAC960_V1_CommandOpcode_T CommandOpcode,
795 dma_addr_t DataDMA) 795 dma_addr_t DataDMA)
796{ 796{
@@ -814,7 +814,7 @@ static boolean DAC960_V1_ExecuteType3(DAC960_Controller_T *Controller,
814 on failure. 814 on failure.
815*/ 815*/
816 816
817static boolean DAC960_V1_ExecuteType3B(DAC960_Controller_T *Controller, 817static bool DAC960_V1_ExecuteType3B(DAC960_Controller_T *Controller,
818 DAC960_V1_CommandOpcode_T CommandOpcode, 818 DAC960_V1_CommandOpcode_T CommandOpcode,
819 unsigned char CommandOpcode2, 819 unsigned char CommandOpcode2,
820 dma_addr_t DataDMA) 820 dma_addr_t DataDMA)
@@ -840,7 +840,7 @@ static boolean DAC960_V1_ExecuteType3B(DAC960_Controller_T *Controller,
840 on failure. 840 on failure.
841*/ 841*/
842 842
843static boolean DAC960_V1_ExecuteType3D(DAC960_Controller_T *Controller, 843static bool DAC960_V1_ExecuteType3D(DAC960_Controller_T *Controller,
844 DAC960_V1_CommandOpcode_T CommandOpcode, 844 DAC960_V1_CommandOpcode_T CommandOpcode,
845 unsigned char Channel, 845 unsigned char Channel,
846 unsigned char TargetID, 846 unsigned char TargetID,
@@ -870,7 +870,7 @@ static boolean DAC960_V1_ExecuteType3D(DAC960_Controller_T *Controller,
870 Return data in The controller's HealthStatusBuffer, which is dma-able memory 870 Return data in The controller's HealthStatusBuffer, which is dma-able memory
871*/ 871*/
872 872
873static boolean DAC960_V2_GeneralInfo(DAC960_Controller_T *Controller) 873static bool DAC960_V2_GeneralInfo(DAC960_Controller_T *Controller)
874{ 874{
875 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller); 875 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
876 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox; 876 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
@@ -908,7 +908,7 @@ static boolean DAC960_V2_GeneralInfo(DAC960_Controller_T *Controller)
908 memory buffer. 908 memory buffer.
909*/ 909*/
910 910
911static boolean DAC960_V2_NewControllerInfo(DAC960_Controller_T *Controller) 911static bool DAC960_V2_NewControllerInfo(DAC960_Controller_T *Controller)
912{ 912{
913 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller); 913 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
914 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox; 914 DAC960_V2_CommandMailbox_T *CommandMailbox = &Command->V2.CommandMailbox;
@@ -946,7 +946,7 @@ static boolean DAC960_V2_NewControllerInfo(DAC960_Controller_T *Controller)
946 Data is returned in the controller's V2.NewLogicalDeviceInformation 946 Data is returned in the controller's V2.NewLogicalDeviceInformation
947*/ 947*/
948 948
949static boolean DAC960_V2_NewLogicalDeviceInfo(DAC960_Controller_T *Controller, 949static bool DAC960_V2_NewLogicalDeviceInfo(DAC960_Controller_T *Controller,
950 unsigned short LogicalDeviceNumber) 950 unsigned short LogicalDeviceNumber)
951{ 951{
952 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller); 952 DAC960_Command_T *Command = DAC960_AllocateCommand(Controller);
@@ -997,7 +997,7 @@ static boolean DAC960_V2_NewLogicalDeviceInfo(DAC960_Controller_T *Controller,
997 997
998*/ 998*/
999 999
1000static boolean DAC960_V2_NewPhysicalDeviceInfo(DAC960_Controller_T *Controller, 1000static bool DAC960_V2_NewPhysicalDeviceInfo(DAC960_Controller_T *Controller,
1001 unsigned char Channel, 1001 unsigned char Channel,
1002 unsigned char TargetID, 1002 unsigned char TargetID,
1003 unsigned char LogicalUnit) 1003 unsigned char LogicalUnit)
@@ -1082,7 +1082,7 @@ static void DAC960_V2_ConstructNewUnitSerialNumber(
1082 memory buffer. 1082 memory buffer.
1083*/ 1083*/
1084 1084
1085static boolean DAC960_V2_NewInquiryUnitSerialNumber(DAC960_Controller_T *Controller, 1085static bool DAC960_V2_NewInquiryUnitSerialNumber(DAC960_Controller_T *Controller,
1086 int Channel, int TargetID, int LogicalUnit) 1086 int Channel, int TargetID, int LogicalUnit)
1087{ 1087{
1088 DAC960_Command_T *Command; 1088 DAC960_Command_T *Command;
@@ -1110,7 +1110,7 @@ static boolean DAC960_V2_NewInquiryUnitSerialNumber(DAC960_Controller_T *Control
1110 success and false on failure. 1110 success and false on failure.
1111*/ 1111*/
1112 1112
1113static boolean DAC960_V2_DeviceOperation(DAC960_Controller_T *Controller, 1113static bool DAC960_V2_DeviceOperation(DAC960_Controller_T *Controller,
1114 DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode, 1114 DAC960_V2_IOCTL_Opcode_T IOCTL_Opcode,
1115 DAC960_V2_OperationDevice_T 1115 DAC960_V2_OperationDevice_T
1116 OperationDevice) 1116 OperationDevice)
@@ -1142,7 +1142,7 @@ static boolean DAC960_V2_DeviceOperation(DAC960_Controller_T *Controller,
1142 other dma mapped memory. 1142 other dma mapped memory.
1143*/ 1143*/
1144 1144
1145static boolean DAC960_V1_EnableMemoryMailboxInterface(DAC960_Controller_T 1145static bool DAC960_V1_EnableMemoryMailboxInterface(DAC960_Controller_T
1146 *Controller) 1146 *Controller)
1147{ 1147{
1148 void __iomem *ControllerBaseAddress = Controller->BaseAddress; 1148 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
@@ -1348,7 +1348,7 @@ skip_mailboxes:
1348 the structures that are contained in that region. 1348 the structures that are contained in that region.
1349*/ 1349*/
1350 1350
1351static boolean DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T 1351static bool DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T
1352 *Controller) 1352 *Controller)
1353{ 1353{
1354 void __iomem *ControllerBaseAddress = Controller->BaseAddress; 1354 void __iomem *ControllerBaseAddress = Controller->BaseAddress;
@@ -1373,8 +1373,7 @@ static boolean DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T
1373 Controller->BounceBufferLimit = DAC690_V2_PciDmaMask; 1373 Controller->BounceBufferLimit = DAC690_V2_PciDmaMask;
1374 1374
1375 /* This is a temporary dma mapping, used only in the scope of this function */ 1375 /* This is a temporary dma mapping, used only in the scope of this function */
1376 CommandMailbox = 1376 CommandMailbox = pci_alloc_consistent(PCI_Device,
1377 (DAC960_V2_CommandMailbox_T *)pci_alloc_consistent( PCI_Device,
1378 sizeof(DAC960_V2_CommandMailbox_T), &CommandMailboxDMA); 1377 sizeof(DAC960_V2_CommandMailbox_T), &CommandMailboxDMA);
1379 if (CommandMailbox == NULL) 1378 if (CommandMailbox == NULL)
1380 return false; 1379 return false;
@@ -1526,7 +1525,7 @@ static boolean DAC960_V2_EnableMemoryMailboxInterface(DAC960_Controller_T
1526 from DAC960 V1 Firmware Controllers and initializes the Controller structure. 1525 from DAC960 V1 Firmware Controllers and initializes the Controller structure.
1527*/ 1526*/
1528 1527
1529static boolean DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T 1528static bool DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T
1530 *Controller) 1529 *Controller)
1531{ 1530{
1532 DAC960_V1_Enquiry2_T *Enquiry2; 1531 DAC960_V1_Enquiry2_T *Enquiry2;
@@ -1767,7 +1766,7 @@ static boolean DAC960_V1_ReadControllerConfiguration(DAC960_Controller_T
1767 from DAC960 V2 Firmware Controllers and initializes the Controller structure. 1766 from DAC960 V2 Firmware Controllers and initializes the Controller structure.
1768*/ 1767*/
1769 1768
1770static boolean DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T 1769static bool DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
1771 *Controller) 1770 *Controller)
1772{ 1771{
1773 DAC960_V2_ControllerInfo_T *ControllerInfo = 1772 DAC960_V2_ControllerInfo_T *ControllerInfo =
@@ -1879,8 +1878,8 @@ static boolean DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
1879 if (NewLogicalDeviceInfo->LogicalDeviceState != 1878 if (NewLogicalDeviceInfo->LogicalDeviceState !=
1880 DAC960_V2_LogicalDevice_Offline) 1879 DAC960_V2_LogicalDevice_Offline)
1881 Controller->LogicalDriveInitiallyAccessible[LogicalDeviceNumber] = true; 1880 Controller->LogicalDriveInitiallyAccessible[LogicalDeviceNumber] = true;
1882 LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *) 1881 LogicalDeviceInfo = kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T),
1883 kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC); 1882 GFP_ATOMIC);
1884 if (LogicalDeviceInfo == NULL) 1883 if (LogicalDeviceInfo == NULL)
1885 return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION"); 1884 return DAC960_Failure(Controller, "LOGICAL DEVICE ALLOCATION");
1886 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] = 1885 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
@@ -1898,7 +1897,7 @@ static boolean DAC960_V2_ReadControllerConfiguration(DAC960_Controller_T
1898 for Controller. 1897 for Controller.
1899*/ 1898*/
1900 1899
1901static boolean DAC960_ReportControllerConfiguration(DAC960_Controller_T 1900static bool DAC960_ReportControllerConfiguration(DAC960_Controller_T
1902 *Controller) 1901 *Controller)
1903{ 1902{
1904 DAC960_Info("Configuring Mylex %s PCI RAID Controller\n", 1903 DAC960_Info("Configuring Mylex %s PCI RAID Controller\n",
@@ -1947,7 +1946,7 @@ static boolean DAC960_ReportControllerConfiguration(DAC960_Controller_T
1947 Controller. 1946 Controller.
1948*/ 1947*/
1949 1948
1950static boolean DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T 1949static bool DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
1951 *Controller) 1950 *Controller)
1952{ 1951{
1953 struct dma_loaf local_dma; 1952 struct dma_loaf local_dma;
@@ -2095,7 +2094,7 @@ static boolean DAC960_V1_ReadDeviceConfiguration(DAC960_Controller_T
2095 device connected to Controller. 2094 device connected to Controller.
2096*/ 2095*/
2097 2096
2098static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T 2097static bool DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
2099 *Controller) 2098 *Controller)
2100{ 2099{
2101 unsigned char Channel = 0, TargetID = 0, LogicalUnit = 0; 2100 unsigned char Channel = 0, TargetID = 0, LogicalUnit = 0;
@@ -2113,8 +2112,8 @@ static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
2113 if (!DAC960_V2_NewPhysicalDeviceInfo(Controller, Channel, TargetID, LogicalUnit)) 2112 if (!DAC960_V2_NewPhysicalDeviceInfo(Controller, Channel, TargetID, LogicalUnit))
2114 break; 2113 break;
2115 2114
2116 PhysicalDeviceInfo = (DAC960_V2_PhysicalDeviceInfo_T *) 2115 PhysicalDeviceInfo = kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T),
2117 kmalloc(sizeof(DAC960_V2_PhysicalDeviceInfo_T), GFP_ATOMIC); 2116 GFP_ATOMIC);
2118 if (PhysicalDeviceInfo == NULL) 2117 if (PhysicalDeviceInfo == NULL)
2119 return DAC960_Failure(Controller, "PHYSICAL DEVICE ALLOCATION"); 2118 return DAC960_Failure(Controller, "PHYSICAL DEVICE ALLOCATION");
2120 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex] = 2119 Controller->V2.PhysicalDeviceInformation[PhysicalDeviceIndex] =
@@ -2122,8 +2121,8 @@ static boolean DAC960_V2_ReadDeviceConfiguration(DAC960_Controller_T
2122 memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo, 2121 memcpy(PhysicalDeviceInfo, NewPhysicalDeviceInfo,
2123 sizeof(DAC960_V2_PhysicalDeviceInfo_T)); 2122 sizeof(DAC960_V2_PhysicalDeviceInfo_T));
2124 2123
2125 InquiryUnitSerialNumber = (DAC960_SCSI_Inquiry_UnitSerialNumber_T *) 2124 InquiryUnitSerialNumber = kmalloc(
2126 kmalloc(sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC); 2125 sizeof(DAC960_SCSI_Inquiry_UnitSerialNumber_T), GFP_ATOMIC);
2127 if (InquiryUnitSerialNumber == NULL) { 2126 if (InquiryUnitSerialNumber == NULL) {
2128 kfree(PhysicalDeviceInfo); 2127 kfree(PhysicalDeviceInfo);
2129 return DAC960_Failure(Controller, "SERIAL NUMBER ALLOCATION"); 2128 return DAC960_Failure(Controller, "SERIAL NUMBER ALLOCATION");
@@ -2219,7 +2218,7 @@ static void DAC960_SanitizeInquiryData(DAC960_SCSI_Inquiry_T
2219 Information for DAC960 V1 Firmware Controllers. 2218 Information for DAC960 V1 Firmware Controllers.
2220*/ 2219*/
2221 2220
2222static boolean DAC960_V1_ReportDeviceConfiguration(DAC960_Controller_T 2221static bool DAC960_V1_ReportDeviceConfiguration(DAC960_Controller_T
2223 *Controller) 2222 *Controller)
2224{ 2223{
2225 int LogicalDriveNumber, Channel, TargetID; 2224 int LogicalDriveNumber, Channel, TargetID;
@@ -2316,7 +2315,7 @@ static boolean DAC960_V1_ReportDeviceConfiguration(DAC960_Controller_T
2316 Information for DAC960 V2 Firmware Controllers. 2315 Information for DAC960 V2 Firmware Controllers.
2317*/ 2316*/
2318 2317
2319static boolean DAC960_V2_ReportDeviceConfiguration(DAC960_Controller_T 2318static bool DAC960_V2_ReportDeviceConfiguration(DAC960_Controller_T
2320 *Controller) 2319 *Controller)
2321{ 2320{
2322 int PhysicalDeviceIndex, LogicalDriveNumber; 2321 int PhysicalDeviceIndex, LogicalDriveNumber;
@@ -2501,7 +2500,7 @@ static boolean DAC960_V2_ReportDeviceConfiguration(DAC960_Controller_T
2501 associated with Controller. 2500 associated with Controller.
2502*/ 2501*/
2503 2502
2504static boolean DAC960_RegisterBlockDevice(DAC960_Controller_T *Controller) 2503static bool DAC960_RegisterBlockDevice(DAC960_Controller_T *Controller)
2505{ 2504{
2506 int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber; 2505 int MajorNumber = DAC960_MAJOR + Controller->ControllerNumber;
2507 int n; 2506 int n;
@@ -2582,7 +2581,7 @@ static void DAC960_ComputeGenericDiskInfo(DAC960_Controller_T *Controller)
2582 It returns true for fatal errors and false otherwise. 2581 It returns true for fatal errors and false otherwise.
2583*/ 2582*/
2584 2583
2585static boolean DAC960_ReportErrorStatus(DAC960_Controller_T *Controller, 2584static bool DAC960_ReportErrorStatus(DAC960_Controller_T *Controller,
2586 unsigned char ErrorStatus, 2585 unsigned char ErrorStatus,
2587 unsigned char Parameter0, 2586 unsigned char Parameter0,
2588 unsigned char Parameter1) 2587 unsigned char Parameter1)
@@ -3048,7 +3047,7 @@ Failure:
3048 DAC960_InitializeController initializes Controller. 3047 DAC960_InitializeController initializes Controller.
3049*/ 3048*/
3050 3049
3051static boolean 3050static bool
3052DAC960_InitializeController(DAC960_Controller_T *Controller) 3051DAC960_InitializeController(DAC960_Controller_T *Controller)
3053{ 3052{
3054 if (DAC960_ReadControllerConfiguration(Controller) && 3053 if (DAC960_ReadControllerConfiguration(Controller) &&
@@ -3445,8 +3444,8 @@ static void DAC960_RequestFunction(struct request_queue *RequestQueue)
3445 individual Buffer. 3444 individual Buffer.
3446*/ 3445*/
3447 3446
3448static inline boolean DAC960_ProcessCompletedRequest(DAC960_Command_T *Command, 3447static inline bool DAC960_ProcessCompletedRequest(DAC960_Command_T *Command,
3449 boolean SuccessfulIO) 3448 bool SuccessfulIO)
3450{ 3449{
3451 struct request *Request = Command->Request; 3450 struct request *Request = Command->Request;
3452 int UpToDate; 3451 int UpToDate;
@@ -3572,7 +3571,7 @@ static void DAC960_V1_ProcessCompletedCommand(DAC960_Command_T *Command)
3572 else if (CommandType == DAC960_ReadRetryCommand || 3571 else if (CommandType == DAC960_ReadRetryCommand ||
3573 CommandType == DAC960_WriteRetryCommand) 3572 CommandType == DAC960_WriteRetryCommand)
3574 { 3573 {
3575 boolean normal_completion; 3574 bool normal_completion;
3576#ifdef FORCE_RETRY_FAILURE_DEBUG 3575#ifdef FORCE_RETRY_FAILURE_DEBUG
3577 static int retry_count = 1; 3576 static int retry_count = 1;
3578#endif 3577#endif
@@ -4659,7 +4658,7 @@ static void DAC960_V2_ProcessCompletedCommand(DAC960_Command_T *Command)
4659 else if (CommandType == DAC960_ReadRetryCommand || 4658 else if (CommandType == DAC960_ReadRetryCommand ||
4660 CommandType == DAC960_WriteRetryCommand) 4659 CommandType == DAC960_WriteRetryCommand)
4661 { 4660 {
4662 boolean normal_completion; 4661 bool normal_completion;
4663 4662
4664#ifdef FORCE_RETRY_FAILURE_DEBUG 4663#ifdef FORCE_RETRY_FAILURE_DEBUG
4665 static int retry_count = 1; 4664 static int retry_count = 1;
@@ -4949,8 +4948,8 @@ static void DAC960_V2_ProcessCompletedCommand(DAC960_Command_T *Command)
4949 PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit; 4948 PhysicalDevice.LogicalUnit = NewLogicalDeviceInfo->LogicalUnit;
4950 Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] = 4949 Controller->V2.LogicalDriveToVirtualDevice[LogicalDeviceNumber] =
4951 PhysicalDevice; 4950 PhysicalDevice;
4952 LogicalDeviceInfo = (DAC960_V2_LogicalDeviceInfo_T *) 4951 LogicalDeviceInfo = kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T),
4953 kmalloc(sizeof(DAC960_V2_LogicalDeviceInfo_T), GFP_ATOMIC); 4952 GFP_ATOMIC);
4954 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] = 4953 Controller->V2.LogicalDeviceInformation[LogicalDeviceNumber] =
4955 LogicalDeviceInfo; 4954 LogicalDeviceInfo;
4956 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) " 4955 DAC960_Critical("Logical Drive %d (/dev/rd/c%dd%d) "
@@ -5632,7 +5631,7 @@ static void DAC960_MonitoringTimerFunction(unsigned long TimerData)
5632 &Controller->V2.ControllerInformation; 5631 &Controller->V2.ControllerInformation;
5633 unsigned int StatusChangeCounter = 5632 unsigned int StatusChangeCounter =
5634 Controller->V2.HealthStatusBuffer->StatusChangeCounter; 5633 Controller->V2.HealthStatusBuffer->StatusChangeCounter;
5635 boolean ForceMonitoringCommand = false; 5634 bool ForceMonitoringCommand = false;
5636 if (time_after(jiffies, Controller->SecondaryMonitoringTime 5635 if (time_after(jiffies, Controller->SecondaryMonitoringTime
5637 + DAC960_SecondaryMonitoringInterval)) 5636 + DAC960_SecondaryMonitoringInterval))
5638 { 5637 {
@@ -5696,7 +5695,7 @@ static void DAC960_MonitoringTimerFunction(unsigned long TimerData)
5696 necessary. It returns true if there is enough room and false otherwise. 5695 necessary. It returns true if there is enough room and false otherwise.
5697*/ 5696*/
5698 5697
5699static boolean DAC960_CheckStatusBuffer(DAC960_Controller_T *Controller, 5698static bool DAC960_CheckStatusBuffer(DAC960_Controller_T *Controller,
5700 unsigned int ByteCount) 5699 unsigned int ByteCount)
5701{ 5700{
5702 unsigned char *NewStatusBuffer; 5701 unsigned char *NewStatusBuffer;
@@ -5709,14 +5708,14 @@ static boolean DAC960_CheckStatusBuffer(DAC960_Controller_T *Controller,
5709 unsigned int NewStatusBufferLength = DAC960_InitialStatusBufferSize; 5708 unsigned int NewStatusBufferLength = DAC960_InitialStatusBufferSize;
5710 while (NewStatusBufferLength < ByteCount) 5709 while (NewStatusBufferLength < ByteCount)
5711 NewStatusBufferLength *= 2; 5710 NewStatusBufferLength *= 2;
5712 Controller->CombinedStatusBuffer = 5711 Controller->CombinedStatusBuffer = kmalloc(NewStatusBufferLength,
5713 (unsigned char *) kmalloc(NewStatusBufferLength, GFP_ATOMIC); 5712 GFP_ATOMIC);
5714 if (Controller->CombinedStatusBuffer == NULL) return false; 5713 if (Controller->CombinedStatusBuffer == NULL) return false;
5715 Controller->CombinedStatusBufferLength = NewStatusBufferLength; 5714 Controller->CombinedStatusBufferLength = NewStatusBufferLength;
5716 return true; 5715 return true;
5717 } 5716 }
5718 NewStatusBuffer = (unsigned char *) 5717 NewStatusBuffer = kmalloc(2 * Controller->CombinedStatusBufferLength,
5719 kmalloc(2 * Controller->CombinedStatusBufferLength, GFP_ATOMIC); 5718 GFP_ATOMIC);
5720 if (NewStatusBuffer == NULL) 5719 if (NewStatusBuffer == NULL)
5721 { 5720 {
5722 DAC960_Warning("Unable to expand Combined Status Buffer - Truncating\n", 5721 DAC960_Warning("Unable to expand Combined Status Buffer - Truncating\n",
@@ -5744,7 +5743,7 @@ static void DAC960_Message(DAC960_MessageLevel_T MessageLevel,
5744 ...) 5743 ...)
5745{ 5744{
5746 static unsigned char Buffer[DAC960_LineBufferSize]; 5745 static unsigned char Buffer[DAC960_LineBufferSize];
5747 static boolean BeginningOfLine = true; 5746 static bool BeginningOfLine = true;
5748 va_list Arguments; 5747 va_list Arguments;
5749 int Length = 0; 5748 int Length = 0;
5750 va_start(Arguments, Controller); 5749 va_start(Arguments, Controller);
@@ -5837,7 +5836,7 @@ static void DAC960_Message(DAC960_MessageLevel_T MessageLevel,
5837 Channel and TargetID and returns true on success and false on failure. 5836 Channel and TargetID and returns true on success and false on failure.
5838*/ 5837*/
5839 5838
5840static boolean DAC960_ParsePhysicalDevice(DAC960_Controller_T *Controller, 5839static bool DAC960_ParsePhysicalDevice(DAC960_Controller_T *Controller,
5841 char *UserCommandString, 5840 char *UserCommandString,
5842 unsigned char *Channel, 5841 unsigned char *Channel,
5843 unsigned char *TargetID) 5842 unsigned char *TargetID)
@@ -5870,7 +5869,7 @@ static boolean DAC960_ParsePhysicalDevice(DAC960_Controller_T *Controller,
5870 returns true on success and false on failure. 5869 returns true on success and false on failure.
5871*/ 5870*/
5872 5871
5873static boolean DAC960_ParseLogicalDrive(DAC960_Controller_T *Controller, 5872static bool DAC960_ParseLogicalDrive(DAC960_Controller_T *Controller,
5874 char *UserCommandString, 5873 char *UserCommandString,
5875 unsigned char *LogicalDriveNumber) 5874 unsigned char *LogicalDriveNumber)
5876{ 5875{
@@ -5951,7 +5950,7 @@ static void DAC960_V1_SetDeviceState(DAC960_Controller_T *Controller,
5951 Controllers. 5950 Controllers.
5952*/ 5951*/
5953 5952
5954static boolean DAC960_V1_ExecuteUserCommand(DAC960_Controller_T *Controller, 5953static bool DAC960_V1_ExecuteUserCommand(DAC960_Controller_T *Controller,
5955 unsigned char *UserCommand) 5954 unsigned char *UserCommand)
5956{ 5955{
5957 DAC960_Command_T *Command; 5956 DAC960_Command_T *Command;
@@ -6166,7 +6165,7 @@ failure:
6166 on failure. 6165 on failure.
6167*/ 6166*/
6168 6167
6169static boolean DAC960_V2_TranslatePhysicalDevice(DAC960_Command_T *Command, 6168static bool DAC960_V2_TranslatePhysicalDevice(DAC960_Command_T *Command,
6170 unsigned char Channel, 6169 unsigned char Channel,
6171 unsigned char TargetID, 6170 unsigned char TargetID,
6172 unsigned short 6171 unsigned short
@@ -6213,7 +6212,7 @@ static boolean DAC960_V2_TranslatePhysicalDevice(DAC960_Command_T *Command,
6213 Controllers. 6212 Controllers.
6214*/ 6213*/
6215 6214
6216static boolean DAC960_V2_ExecuteUserCommand(DAC960_Controller_T *Controller, 6215static bool DAC960_V2_ExecuteUserCommand(DAC960_Controller_T *Controller,
6217 unsigned char *UserCommand) 6216 unsigned char *UserCommand)
6218{ 6217{
6219 DAC960_Command_T *Command; 6218 DAC960_Command_T *Command;
@@ -7025,7 +7024,7 @@ static int DAC960_gam_ioctl(struct inode *inode, struct file *file,
7025 return -EINVAL; 7024 return -EINVAL;
7026} 7025}
7027 7026
7028static struct file_operations DAC960_gam_fops = { 7027static const struct file_operations DAC960_gam_fops = {
7029 .owner = THIS_MODULE, 7028 .owner = THIS_MODULE,
7030 .ioctl = DAC960_gam_ioctl 7029 .ioctl = DAC960_gam_ioctl
7031}; 7030};
diff --git a/drivers/block/DAC960.h b/drivers/block/DAC960.h
index 6148073532b..f5e2436c39a 100644
--- a/drivers/block/DAC960.h
+++ b/drivers/block/DAC960.h
@@ -68,13 +68,6 @@
68#define DAC690_V2_PciDmaMask 0xffffffffffffffffULL 68#define DAC690_V2_PciDmaMask 0xffffffffffffffffULL
69 69
70/* 70/*
71 Define a Boolean data type.
72*/
73
74typedef bool boolean;
75
76
77/*
78 Define a 32/64 bit I/O Address data type. 71 Define a 32/64 bit I/O Address data type.
79*/ 72*/
80 73
@@ -139,25 +132,25 @@ typedef struct DAC960_SCSI_Inquiry
139 unsigned char PeripheralDeviceType:5; /* Byte 0 Bits 0-4 */ 132 unsigned char PeripheralDeviceType:5; /* Byte 0 Bits 0-4 */
140 unsigned char PeripheralQualifier:3; /* Byte 0 Bits 5-7 */ 133 unsigned char PeripheralQualifier:3; /* Byte 0 Bits 5-7 */
141 unsigned char DeviceTypeModifier:7; /* Byte 1 Bits 0-6 */ 134 unsigned char DeviceTypeModifier:7; /* Byte 1 Bits 0-6 */
142 boolean RMB:1; /* Byte 1 Bit 7 */ 135 bool RMB:1; /* Byte 1 Bit 7 */
143 unsigned char ANSI_ApprovedVersion:3; /* Byte 2 Bits 0-2 */ 136 unsigned char ANSI_ApprovedVersion:3; /* Byte 2 Bits 0-2 */
144 unsigned char ECMA_Version:3; /* Byte 2 Bits 3-5 */ 137 unsigned char ECMA_Version:3; /* Byte 2 Bits 3-5 */
145 unsigned char ISO_Version:2; /* Byte 2 Bits 6-7 */ 138 unsigned char ISO_Version:2; /* Byte 2 Bits 6-7 */
146 unsigned char ResponseDataFormat:4; /* Byte 3 Bits 0-3 */ 139 unsigned char ResponseDataFormat:4; /* Byte 3 Bits 0-3 */
147 unsigned char :2; /* Byte 3 Bits 4-5 */ 140 unsigned char :2; /* Byte 3 Bits 4-5 */
148 boolean TrmIOP:1; /* Byte 3 Bit 6 */ 141 bool TrmIOP:1; /* Byte 3 Bit 6 */
149 boolean AENC:1; /* Byte 3 Bit 7 */ 142 bool AENC:1; /* Byte 3 Bit 7 */
150 unsigned char AdditionalLength; /* Byte 4 */ 143 unsigned char AdditionalLength; /* Byte 4 */
151 unsigned char :8; /* Byte 5 */ 144 unsigned char :8; /* Byte 5 */
152 unsigned char :8; /* Byte 6 */ 145 unsigned char :8; /* Byte 6 */
153 boolean SftRe:1; /* Byte 7 Bit 0 */ 146 bool SftRe:1; /* Byte 7 Bit 0 */
154 boolean CmdQue:1; /* Byte 7 Bit 1 */ 147 bool CmdQue:1; /* Byte 7 Bit 1 */
155 boolean :1; /* Byte 7 Bit 2 */ 148 bool :1; /* Byte 7 Bit 2 */
156 boolean Linked:1; /* Byte 7 Bit 3 */ 149 bool Linked:1; /* Byte 7 Bit 3 */
157 boolean Sync:1; /* Byte 7 Bit 4 */ 150 bool Sync:1; /* Byte 7 Bit 4 */
158 boolean WBus16:1; /* Byte 7 Bit 5 */ 151 bool WBus16:1; /* Byte 7 Bit 5 */
159 boolean WBus32:1; /* Byte 7 Bit 6 */ 152 bool WBus32:1; /* Byte 7 Bit 6 */
160 boolean RelAdr:1; /* Byte 7 Bit 7 */ 153 bool RelAdr:1; /* Byte 7 Bit 7 */
161 unsigned char VendorIdentification[8]; /* Bytes 8-15 */ 154 unsigned char VendorIdentification[8]; /* Bytes 8-15 */
162 unsigned char ProductIdentification[16]; /* Bytes 16-31 */ 155 unsigned char ProductIdentification[16]; /* Bytes 16-31 */
163 unsigned char ProductRevisionLevel[4]; /* Bytes 32-35 */ 156 unsigned char ProductRevisionLevel[4]; /* Bytes 32-35 */
@@ -215,13 +208,13 @@ DAC960_SCSI_RequestSenseKey_T;
215typedef struct DAC960_SCSI_RequestSense 208typedef struct DAC960_SCSI_RequestSense
216{ 209{
217 unsigned char ErrorCode:7; /* Byte 0 Bits 0-6 */ 210 unsigned char ErrorCode:7; /* Byte 0 Bits 0-6 */
218 boolean Valid:1; /* Byte 0 Bit 7 */ 211 bool Valid:1; /* Byte 0 Bit 7 */
219 unsigned char SegmentNumber; /* Byte 1 */ 212 unsigned char SegmentNumber; /* Byte 1 */
220 DAC960_SCSI_RequestSenseKey_T SenseKey:4; /* Byte 2 Bits 0-3 */ 213 DAC960_SCSI_RequestSenseKey_T SenseKey:4; /* Byte 2 Bits 0-3 */
221 unsigned char :1; /* Byte 2 Bit 4 */ 214 unsigned char :1; /* Byte 2 Bit 4 */
222 boolean ILI:1; /* Byte 2 Bit 5 */ 215 bool ILI:1; /* Byte 2 Bit 5 */
223 boolean EOM:1; /* Byte 2 Bit 6 */ 216 bool EOM:1; /* Byte 2 Bit 6 */
224 boolean Filemark:1; /* Byte 2 Bit 7 */ 217 bool Filemark:1; /* Byte 2 Bit 7 */
225 unsigned char Information[4]; /* Bytes 3-6 */ 218 unsigned char Information[4]; /* Bytes 3-6 */
226 unsigned char AdditionalSenseLength; /* Byte 7 */ 219 unsigned char AdditionalSenseLength; /* Byte 7 */
227 unsigned char CommandSpecificInformation[4]; /* Bytes 8-11 */ 220 unsigned char CommandSpecificInformation[4]; /* Bytes 8-11 */
@@ -381,8 +374,8 @@ typedef struct DAC960_V1_Enquiry
381 unsigned int LogicalDriveSizes[32]; /* Bytes 4-131 */ 374 unsigned int LogicalDriveSizes[32]; /* Bytes 4-131 */
382 unsigned short FlashAge; /* Bytes 132-133 */ 375 unsigned short FlashAge; /* Bytes 132-133 */
383 struct { 376 struct {
384 boolean DeferredWriteError:1; /* Byte 134 Bit 0 */ 377 bool DeferredWriteError:1; /* Byte 134 Bit 0 */
385 boolean BatteryLow:1; /* Byte 134 Bit 1 */ 378 bool BatteryLow:1; /* Byte 134 Bit 1 */
386 unsigned char :6; /* Byte 134 Bits 2-7 */ 379 unsigned char :6; /* Byte 134 Bits 2-7 */
387 } StatusFlags; 380 } StatusFlags;
388 unsigned char :8; /* Byte 135 */ 381 unsigned char :8; /* Byte 135 */
@@ -410,7 +403,7 @@ typedef struct DAC960_V1_Enquiry
410 unsigned char RebuildCount; /* Byte 150 */ 403 unsigned char RebuildCount; /* Byte 150 */
411 struct { 404 struct {
412 unsigned char :3; /* Byte 151 Bits 0-2 */ 405 unsigned char :3; /* Byte 151 Bits 0-2 */
413 boolean BatteryBackupUnitPresent:1; /* Byte 151 Bit 3 */ 406 bool BatteryBackupUnitPresent:1; /* Byte 151 Bit 3 */
414 unsigned char :3; /* Byte 151 Bits 4-6 */ 407 unsigned char :3; /* Byte 151 Bits 4-6 */
415 unsigned char :1; /* Byte 151 Bit 7 */ 408 unsigned char :1; /* Byte 151 Bit 7 */
416 } MiscFlags; 409 } MiscFlags;
@@ -492,8 +485,8 @@ typedef struct DAC960_V1_Enquiry2
492 DAC960_V1_ErrorCorrection_ECC = 0x2, 485 DAC960_V1_ErrorCorrection_ECC = 0x2,
493 DAC960_V1_ErrorCorrection_Last = 0x7 486 DAC960_V1_ErrorCorrection_Last = 0x7
494 } __attribute__ ((packed)) ErrorCorrection:3; /* Byte 40 Bits 3-5 */ 487 } __attribute__ ((packed)) ErrorCorrection:3; /* Byte 40 Bits 3-5 */
495 boolean FastPageMode:1; /* Byte 40 Bit 6 */ 488 bool FastPageMode:1; /* Byte 40 Bit 6 */
496 boolean LowPowerMemory:1; /* Byte 40 Bit 7 */ 489 bool LowPowerMemory:1; /* Byte 40 Bit 7 */
497 unsigned char :8; /* Bytes 41 */ 490 unsigned char :8; /* Bytes 41 */
498 } MemoryType; 491 } MemoryType;
499 unsigned short ClockSpeed; /* Bytes 42-43 */ 492 unsigned short ClockSpeed; /* Bytes 42-43 */
@@ -538,7 +531,7 @@ typedef struct DAC960_V1_Enquiry2
538 DAC960_V1_Ultra = 0x1, 531 DAC960_V1_Ultra = 0x1,
539 DAC960_V1_Ultra2 = 0x2 532 DAC960_V1_Ultra2 = 0x2
540 } __attribute__ ((packed)) BusSpeed:2; /* Byte 106 Bits 2-3 */ 533 } __attribute__ ((packed)) BusSpeed:2; /* Byte 106 Bits 2-3 */
541 boolean Differential:1; /* Byte 106 Bit 4 */ 534 bool Differential:1; /* Byte 106 Bit 4 */
542 unsigned char :3; /* Byte 106 Bits 5-7 */ 535 unsigned char :3; /* Byte 106 Bits 5-7 */
543 } SCSICapability; 536 } SCSICapability;
544 unsigned char :8; /* Byte 107 */ 537 unsigned char :8; /* Byte 107 */
@@ -554,10 +547,10 @@ typedef struct DAC960_V1_Enquiry2
554 } __attribute__ ((packed)) FaultManagementType; /* Byte 114 */ 547 } __attribute__ ((packed)) FaultManagementType; /* Byte 114 */
555 unsigned char :8; /* Byte 115 */ 548 unsigned char :8; /* Byte 115 */
556 struct { 549 struct {
557 boolean Clustering:1; /* Byte 116 Bit 0 */ 550 bool Clustering:1; /* Byte 116 Bit 0 */
558 boolean MylexOnlineRAIDExpansion:1; /* Byte 116 Bit 1 */ 551 bool MylexOnlineRAIDExpansion:1; /* Byte 116 Bit 1 */
559 boolean ReadAhead:1; /* Byte 116 Bit 2 */ 552 bool ReadAhead:1; /* Byte 116 Bit 2 */
560 boolean BackgroundInitialization:1; /* Byte 116 Bit 3 */ 553 bool BackgroundInitialization:1; /* Byte 116 Bit 3 */
561 unsigned int :28; /* Bytes 116-119 */ 554 unsigned int :28; /* Bytes 116-119 */
562 } FirmwareFeatures; 555 } FirmwareFeatures;
563 unsigned int :32; /* Bytes 120-123 */ 556 unsigned int :32; /* Bytes 120-123 */
@@ -589,7 +582,7 @@ typedef struct DAC960_V1_LogicalDriveInformation
589 unsigned int LogicalDriveSize; /* Bytes 0-3 */ 582 unsigned int LogicalDriveSize; /* Bytes 0-3 */
590 DAC960_V1_LogicalDriveState_T LogicalDriveState; /* Byte 4 */ 583 DAC960_V1_LogicalDriveState_T LogicalDriveState; /* Byte 4 */
591 unsigned char RAIDLevel:7; /* Byte 5 Bits 0-6 */ 584 unsigned char RAIDLevel:7; /* Byte 5 Bits 0-6 */
592 boolean WriteBack:1; /* Byte 5 Bit 7 */ 585 bool WriteBack:1; /* Byte 5 Bit 7 */
593 unsigned short :16; /* Bytes 6-7 */ 586 unsigned short :16; /* Bytes 6-7 */
594} 587}
595DAC960_V1_LogicalDriveInformation_T; 588DAC960_V1_LogicalDriveInformation_T;
@@ -630,13 +623,13 @@ typedef struct DAC960_V1_EventLogEntry
630 unsigned char :2; /* Byte 3 Bits 6-7 */ 623 unsigned char :2; /* Byte 3 Bits 6-7 */
631 unsigned short SequenceNumber; /* Bytes 4-5 */ 624 unsigned short SequenceNumber; /* Bytes 4-5 */
632 unsigned char ErrorCode:7; /* Byte 6 Bits 0-6 */ 625 unsigned char ErrorCode:7; /* Byte 6 Bits 0-6 */
633 boolean Valid:1; /* Byte 6 Bit 7 */ 626 bool Valid:1; /* Byte 6 Bit 7 */
634 unsigned char SegmentNumber; /* Byte 7 */ 627 unsigned char SegmentNumber; /* Byte 7 */
635 DAC960_SCSI_RequestSenseKey_T SenseKey:4; /* Byte 8 Bits 0-3 */ 628 DAC960_SCSI_RequestSenseKey_T SenseKey:4; /* Byte 8 Bits 0-3 */
636 unsigned char :1; /* Byte 8 Bit 4 */ 629 unsigned char :1; /* Byte 8 Bit 4 */
637 boolean ILI:1; /* Byte 8 Bit 5 */ 630 bool ILI:1; /* Byte 8 Bit 5 */
638 boolean EOM:1; /* Byte 8 Bit 6 */ 631 bool EOM:1; /* Byte 8 Bit 6 */
639 boolean Filemark:1; /* Byte 8 Bit 7 */ 632 bool Filemark:1; /* Byte 8 Bit 7 */
640 unsigned char Information[4]; /* Bytes 9-12 */ 633 unsigned char Information[4]; /* Bytes 9-12 */
641 unsigned char AdditionalSenseLength; /* Byte 13 */ 634 unsigned char AdditionalSenseLength; /* Byte 13 */
642 unsigned char CommandSpecificInformation[4]; /* Bytes 14-17 */ 635 unsigned char CommandSpecificInformation[4]; /* Bytes 14-17 */
@@ -670,7 +663,7 @@ DAC960_V1_PhysicalDeviceState_T;
670 663
671typedef struct DAC960_V1_DeviceState 664typedef struct DAC960_V1_DeviceState
672{ 665{
673 boolean Present:1; /* Byte 0 Bit 0 */ 666 bool Present:1; /* Byte 0 Bit 0 */
674 unsigned char :7; /* Byte 0 Bits 1-7 */ 667 unsigned char :7; /* Byte 0 Bits 1-7 */
675 enum { 668 enum {
676 DAC960_V1_OtherType = 0x0, 669 DAC960_V1_OtherType = 0x0,
@@ -678,12 +671,12 @@ typedef struct DAC960_V1_DeviceState
678 DAC960_V1_SequentialType = 0x2, 671 DAC960_V1_SequentialType = 0x2,
679 DAC960_V1_CDROM_or_WORM_Type = 0x3 672 DAC960_V1_CDROM_or_WORM_Type = 0x3
680 } __attribute__ ((packed)) DeviceType:2; /* Byte 1 Bits 0-1 */ 673 } __attribute__ ((packed)) DeviceType:2; /* Byte 1 Bits 0-1 */
681 boolean :1; /* Byte 1 Bit 2 */ 674 bool :1; /* Byte 1 Bit 2 */
682 boolean Fast20:1; /* Byte 1 Bit 3 */ 675 bool Fast20:1; /* Byte 1 Bit 3 */
683 boolean Sync:1; /* Byte 1 Bit 4 */ 676 bool Sync:1; /* Byte 1 Bit 4 */
684 boolean Fast:1; /* Byte 1 Bit 5 */ 677 bool Fast:1; /* Byte 1 Bit 5 */
685 boolean Wide:1; /* Byte 1 Bit 6 */ 678 bool Wide:1; /* Byte 1 Bit 6 */
686 boolean TaggedQueuingSupported:1; /* Byte 1 Bit 7 */ 679 bool TaggedQueuingSupported:1; /* Byte 1 Bit 7 */
687 DAC960_V1_PhysicalDeviceState_T DeviceState; /* Byte 2 */ 680 DAC960_V1_PhysicalDeviceState_T DeviceState; /* Byte 2 */
688 unsigned char :8; /* Byte 3 */ 681 unsigned char :8; /* Byte 3 */
689 unsigned char SynchronousMultiplier; /* Byte 4 */ 682 unsigned char SynchronousMultiplier; /* Byte 4 */
@@ -765,15 +758,15 @@ DAC960_V1_ErrorTable_T;
765typedef struct DAC960_V1_Config2 758typedef struct DAC960_V1_Config2
766{ 759{
767 unsigned char :1; /* Byte 0 Bit 0 */ 760 unsigned char :1; /* Byte 0 Bit 0 */
768 boolean ActiveNegationEnabled:1; /* Byte 0 Bit 1 */ 761 bool ActiveNegationEnabled:1; /* Byte 0 Bit 1 */
769 unsigned char :5; /* Byte 0 Bits 2-6 */ 762 unsigned char :5; /* Byte 0 Bits 2-6 */
770 boolean NoRescanIfResetReceivedDuringScan:1; /* Byte 0 Bit 7 */ 763 bool NoRescanIfResetReceivedDuringScan:1; /* Byte 0 Bit 7 */
771 boolean StorageWorksSupportEnabled:1; /* Byte 1 Bit 0 */ 764 bool StorageWorksSupportEnabled:1; /* Byte 1 Bit 0 */
772 boolean HewlettPackardSupportEnabled:1; /* Byte 1 Bit 1 */ 765 bool HewlettPackardSupportEnabled:1; /* Byte 1 Bit 1 */
773 boolean NoDisconnectOnFirstCommand:1; /* Byte 1 Bit 2 */ 766 bool NoDisconnectOnFirstCommand:1; /* Byte 1 Bit 2 */
774 unsigned char :2; /* Byte 1 Bits 3-4 */ 767 unsigned char :2; /* Byte 1 Bits 3-4 */
775 boolean AEMI_ARM:1; /* Byte 1 Bit 5 */ 768 bool AEMI_ARM:1; /* Byte 1 Bit 5 */
776 boolean AEMI_OFM:1; /* Byte 1 Bit 6 */ 769 bool AEMI_OFM:1; /* Byte 1 Bit 6 */
777 unsigned char :1; /* Byte 1 Bit 7 */ 770 unsigned char :1; /* Byte 1 Bit 7 */
778 enum { 771 enum {
779 DAC960_V1_OEMID_Mylex = 0x00, 772 DAC960_V1_OEMID_Mylex = 0x00,
@@ -787,13 +780,13 @@ typedef struct DAC960_V1_Config2
787 unsigned char PhysicalSector; /* Byte 4 */ 780 unsigned char PhysicalSector; /* Byte 4 */
788 unsigned char LogicalSector; /* Byte 5 */ 781 unsigned char LogicalSector; /* Byte 5 */
789 unsigned char BlockFactor; /* Byte 6 */ 782 unsigned char BlockFactor; /* Byte 6 */
790 boolean ReadAheadEnabled:1; /* Byte 7 Bit 0 */ 783 bool ReadAheadEnabled:1; /* Byte 7 Bit 0 */
791 boolean LowBIOSDelay:1; /* Byte 7 Bit 1 */ 784 bool LowBIOSDelay:1; /* Byte 7 Bit 1 */
792 unsigned char :2; /* Byte 7 Bits 2-3 */ 785 unsigned char :2; /* Byte 7 Bits 2-3 */
793 boolean ReassignRestrictedToOneSector:1; /* Byte 7 Bit 4 */ 786 bool ReassignRestrictedToOneSector:1; /* Byte 7 Bit 4 */
794 unsigned char :1; /* Byte 7 Bit 5 */ 787 unsigned char :1; /* Byte 7 Bit 5 */
795 boolean ForceUnitAccessDuringWriteRecovery:1; /* Byte 7 Bit 6 */ 788 bool ForceUnitAccessDuringWriteRecovery:1; /* Byte 7 Bit 6 */
796 boolean EnableLeftSymmetricRAID5Algorithm:1; /* Byte 7 Bit 7 */ 789 bool EnableLeftSymmetricRAID5Algorithm:1; /* Byte 7 Bit 7 */
797 unsigned char DefaultRebuildRate; /* Byte 8 */ 790 unsigned char DefaultRebuildRate; /* Byte 8 */
798 unsigned char :8; /* Byte 9 */ 791 unsigned char :8; /* Byte 9 */
799 unsigned char BlocksPerCacheLine; /* Byte 10 */ 792 unsigned char BlocksPerCacheLine; /* Byte 10 */
@@ -805,10 +798,10 @@ typedef struct DAC960_V1_Config2
805 DAC960_V1_Sync_5MHz = 0x2, 798 DAC960_V1_Sync_5MHz = 0x2,
806 DAC960_V1_Sync_10or20MHz = 0x3 /* Byte 11 Bits 0-1 */ 799 DAC960_V1_Sync_10or20MHz = 0x3 /* Byte 11 Bits 0-1 */
807 } __attribute__ ((packed)) Speed:2; 800 } __attribute__ ((packed)) Speed:2;
808 boolean Force8Bit:1; /* Byte 11 Bit 2 */ 801 bool Force8Bit:1; /* Byte 11 Bit 2 */
809 boolean DisableFast20:1; /* Byte 11 Bit 3 */ 802 bool DisableFast20:1; /* Byte 11 Bit 3 */
810 unsigned char :3; /* Byte 11 Bits 4-6 */ 803 unsigned char :3; /* Byte 11 Bits 4-6 */
811 boolean EnableTaggedQueuing:1; /* Byte 11 Bit 7 */ 804 bool EnableTaggedQueuing:1; /* Byte 11 Bit 7 */
812 } __attribute__ ((packed)) ChannelParameters[6]; /* Bytes 12-17 */ 805 } __attribute__ ((packed)) ChannelParameters[6]; /* Bytes 12-17 */
813 unsigned char SCSIInitiatorID; /* Byte 18 */ 806 unsigned char SCSIInitiatorID; /* Byte 18 */
814 unsigned char :8; /* Byte 19 */ 807 unsigned char :8; /* Byte 19 */
@@ -819,8 +812,8 @@ typedef struct DAC960_V1_Config2
819 unsigned char SimultaneousDeviceSpinUpCount; /* Byte 21 */ 812 unsigned char SimultaneousDeviceSpinUpCount; /* Byte 21 */
820 unsigned char SecondsDelayBetweenSpinUps; /* Byte 22 */ 813 unsigned char SecondsDelayBetweenSpinUps; /* Byte 22 */
821 unsigned char Reserved1[29]; /* Bytes 23-51 */ 814 unsigned char Reserved1[29]; /* Bytes 23-51 */
822 boolean BIOSDisabled:1; /* Byte 52 Bit 0 */ 815 bool BIOSDisabled:1; /* Byte 52 Bit 0 */
823 boolean CDROMBootEnabled:1; /* Byte 52 Bit 1 */ 816 bool CDROMBootEnabled:1; /* Byte 52 Bit 1 */
824 unsigned char :3; /* Byte 52 Bits 2-4 */ 817 unsigned char :3; /* Byte 52 Bits 2-4 */
825 enum { 818 enum {
826 DAC960_V1_Geometry_128_32 = 0x0, 819 DAC960_V1_Geometry_128_32 = 0x0,
@@ -849,7 +842,7 @@ typedef struct DAC960_V1_DCDB
849 DAC960_V1_DCDB_DataTransferSystemToDevice = 2, 842 DAC960_V1_DCDB_DataTransferSystemToDevice = 2,
850 DAC960_V1_DCDB_IllegalDataTransfer = 3 843 DAC960_V1_DCDB_IllegalDataTransfer = 3
851 } __attribute__ ((packed)) Direction:2; /* Byte 1 Bits 0-1 */ 844 } __attribute__ ((packed)) Direction:2; /* Byte 1 Bits 0-1 */
852 boolean EarlyStatus:1; /* Byte 1 Bit 2 */ 845 bool EarlyStatus:1; /* Byte 1 Bit 2 */
853 unsigned char :1; /* Byte 1 Bit 3 */ 846 unsigned char :1; /* Byte 1 Bit 3 */
854 enum { 847 enum {
855 DAC960_V1_DCDB_Timeout_24_hours = 0, 848 DAC960_V1_DCDB_Timeout_24_hours = 0,
@@ -857,8 +850,8 @@ typedef struct DAC960_V1_DCDB
857 DAC960_V1_DCDB_Timeout_60_seconds = 2, 850 DAC960_V1_DCDB_Timeout_60_seconds = 2,
858 DAC960_V1_DCDB_Timeout_10_minutes = 3 851 DAC960_V1_DCDB_Timeout_10_minutes = 3
859 } __attribute__ ((packed)) Timeout:2; /* Byte 1 Bits 4-5 */ 852 } __attribute__ ((packed)) Timeout:2; /* Byte 1 Bits 4-5 */
860 boolean NoAutomaticRequestSense:1; /* Byte 1 Bit 6 */ 853 bool NoAutomaticRequestSense:1; /* Byte 1 Bit 6 */
861 boolean DisconnectPermitted:1; /* Byte 1 Bit 7 */ 854 bool DisconnectPermitted:1; /* Byte 1 Bit 7 */
862 unsigned short TransferLength; /* Bytes 2-3 */ 855 unsigned short TransferLength; /* Bytes 2-3 */
863 DAC960_BusAddress32_T BusAddress; /* Bytes 4-7 */ 856 DAC960_BusAddress32_T BusAddress; /* Bytes 4-7 */
864 unsigned char CDBLength:4; /* Byte 8 Bits 0-3 */ 857 unsigned char CDBLength:4; /* Byte 8 Bits 0-3 */
@@ -920,7 +913,7 @@ typedef union DAC960_V1_CommandMailbox
920 DAC960_V1_CommandIdentifier_T CommandIdentifier; /* Byte 1 */ 913 DAC960_V1_CommandIdentifier_T CommandIdentifier; /* Byte 1 */
921 unsigned char Dummy1[5]; /* Bytes 2-6 */ 914 unsigned char Dummy1[5]; /* Bytes 2-6 */
922 unsigned char LogicalDriveNumber:6; /* Byte 7 Bits 0-6 */ 915 unsigned char LogicalDriveNumber:6; /* Byte 7 Bits 0-6 */
923 boolean AutoRestore:1; /* Byte 7 Bit 7 */ 916 bool AutoRestore:1; /* Byte 7 Bit 7 */
924 unsigned char Dummy2[8]; /* Bytes 8-15 */ 917 unsigned char Dummy2[8]; /* Bytes 8-15 */
925 } __attribute__ ((packed)) Type3C; 918 } __attribute__ ((packed)) Type3C;
926 struct { 919 struct {
@@ -1070,9 +1063,9 @@ typedef struct DAC960_V2_MemoryType
1070 DAC960_V2_MemoryType_SDRAM = 0x04, 1063 DAC960_V2_MemoryType_SDRAM = 0x04,
1071 DAC960_V2_MemoryType_Last = 0x1F 1064 DAC960_V2_MemoryType_Last = 0x1F
1072 } __attribute__ ((packed)) MemoryType:5; /* Byte 0 Bits 0-4 */ 1065 } __attribute__ ((packed)) MemoryType:5; /* Byte 0 Bits 0-4 */
1073 boolean :1; /* Byte 0 Bit 5 */ 1066 bool :1; /* Byte 0 Bit 5 */
1074 boolean MemoryParity:1; /* Byte 0 Bit 6 */ 1067 bool MemoryParity:1; /* Byte 0 Bit 6 */
1075 boolean MemoryECC:1; /* Byte 0 Bit 7 */ 1068 bool MemoryECC:1; /* Byte 0 Bit 7 */
1076} 1069}
1077DAC960_V2_MemoryType_T; 1070DAC960_V2_MemoryType_T;
1078 1071
@@ -1187,13 +1180,13 @@ typedef struct DAC960_V2_ControllerInfo
1187 unsigned char OEM_Code; /* Byte 131 */ 1180 unsigned char OEM_Code; /* Byte 131 */
1188 unsigned char VendorName[16]; /* Bytes 132-147 */ 1181 unsigned char VendorName[16]; /* Bytes 132-147 */
1189 /* Other Physical/Controller/Operation Information */ 1182 /* Other Physical/Controller/Operation Information */
1190 boolean BBU_Present:1; /* Byte 148 Bit 0 */ 1183 bool BBU_Present:1; /* Byte 148 Bit 0 */
1191 boolean ActiveActiveClusteringMode:1; /* Byte 148 Bit 1 */ 1184 bool ActiveActiveClusteringMode:1; /* Byte 148 Bit 1 */
1192 unsigned char :6; /* Byte 148 Bits 2-7 */ 1185 unsigned char :6; /* Byte 148 Bits 2-7 */
1193 unsigned char :8; /* Byte 149 */ 1186 unsigned char :8; /* Byte 149 */
1194 unsigned short :16; /* Bytes 150-151 */ 1187 unsigned short :16; /* Bytes 150-151 */
1195 /* Physical Device Scan Information */ 1188 /* Physical Device Scan Information */
1196 boolean PhysicalScanActive:1; /* Byte 152 Bit 0 */ 1189 bool PhysicalScanActive:1; /* Byte 152 Bit 0 */
1197 unsigned char :7; /* Byte 152 Bits 1-7 */ 1190 unsigned char :7; /* Byte 152 Bits 1-7 */
1198 unsigned char PhysicalDeviceChannelNumber; /* Byte 153 */ 1191 unsigned char PhysicalDeviceChannelNumber; /* Byte 153 */
1199 unsigned char PhysicalDeviceTargetID; /* Byte 154 */ 1192 unsigned char PhysicalDeviceTargetID; /* Byte 154 */
@@ -1305,8 +1298,8 @@ typedef struct DAC960_V2_ControllerInfo
1305 unsigned int FreeIOP; /* Bytes 468-471 */ 1298 unsigned int FreeIOP; /* Bytes 468-471 */
1306 unsigned short MaximumCombLengthInBlocks; /* Bytes 472-473 */ 1299 unsigned short MaximumCombLengthInBlocks; /* Bytes 472-473 */
1307 unsigned short NumberOfConfigurationGroups; /* Bytes 474-475 */ 1300 unsigned short NumberOfConfigurationGroups; /* Bytes 474-475 */
1308 boolean InstallationAbortStatus:1; /* Byte 476 Bit 0 */ 1301 bool InstallationAbortStatus:1; /* Byte 476 Bit 0 */
1309 boolean MaintenanceModeStatus:1; /* Byte 476 Bit 1 */ 1302 bool MaintenanceModeStatus:1; /* Byte 476 Bit 1 */
1310 unsigned int :24; /* Bytes 476-479 */ 1303 unsigned int :24; /* Bytes 476-479 */
1311 unsigned char Reserved10[32]; /* Bytes 480-511 */ 1304 unsigned char Reserved10[32]; /* Bytes 480-511 */
1312 unsigned char Reserved11[512]; /* Bytes 512-1023 */ 1305 unsigned char Reserved11[512]; /* Bytes 512-1023 */
@@ -1357,33 +1350,33 @@ typedef struct DAC960_V2_LogicalDeviceInfo
1357 DAC960_V2_IntelligentWriteCacheEnabled = 0x3, 1350 DAC960_V2_IntelligentWriteCacheEnabled = 0x3,
1358 DAC960_V2_WriteCache_Last = 0x7 1351 DAC960_V2_WriteCache_Last = 0x7
1359 } __attribute__ ((packed)) WriteCache:3; /* Byte 8 Bits 3-5 */ 1352 } __attribute__ ((packed)) WriteCache:3; /* Byte 8 Bits 3-5 */
1360 boolean :1; /* Byte 8 Bit 6 */ 1353 bool :1; /* Byte 8 Bit 6 */
1361 boolean LogicalDeviceInitialized:1; /* Byte 8 Bit 7 */ 1354 bool LogicalDeviceInitialized:1; /* Byte 8 Bit 7 */
1362 } LogicalDeviceControl; /* Byte 8 */ 1355 } LogicalDeviceControl; /* Byte 8 */
1363 /* Logical Device Operations Status */ 1356 /* Logical Device Operations Status */
1364 boolean ConsistencyCheckInProgress:1; /* Byte 9 Bit 0 */ 1357 bool ConsistencyCheckInProgress:1; /* Byte 9 Bit 0 */
1365 boolean RebuildInProgress:1; /* Byte 9 Bit 1 */ 1358 bool RebuildInProgress:1; /* Byte 9 Bit 1 */
1366 boolean BackgroundInitializationInProgress:1; /* Byte 9 Bit 2 */ 1359 bool BackgroundInitializationInProgress:1; /* Byte 9 Bit 2 */
1367 boolean ForegroundInitializationInProgress:1; /* Byte 9 Bit 3 */ 1360 bool ForegroundInitializationInProgress:1; /* Byte 9 Bit 3 */
1368 boolean DataMigrationInProgress:1; /* Byte 9 Bit 4 */ 1361 bool DataMigrationInProgress:1; /* Byte 9 Bit 4 */
1369 boolean PatrolOperationInProgress:1; /* Byte 9 Bit 5 */ 1362 bool PatrolOperationInProgress:1; /* Byte 9 Bit 5 */
1370 unsigned char :2; /* Byte 9 Bits 6-7 */ 1363 unsigned char :2; /* Byte 9 Bits 6-7 */
1371 unsigned char RAID5WriteUpdate; /* Byte 10 */ 1364 unsigned char RAID5WriteUpdate; /* Byte 10 */
1372 unsigned char RAID5Algorithm; /* Byte 11 */ 1365 unsigned char RAID5Algorithm; /* Byte 11 */
1373 unsigned short LogicalDeviceNumber; /* Bytes 12-13 */ 1366 unsigned short LogicalDeviceNumber; /* Bytes 12-13 */
1374 /* BIOS Info */ 1367 /* BIOS Info */
1375 boolean BIOSDisabled:1; /* Byte 14 Bit 0 */ 1368 bool BIOSDisabled:1; /* Byte 14 Bit 0 */
1376 boolean CDROMBootEnabled:1; /* Byte 14 Bit 1 */ 1369 bool CDROMBootEnabled:1; /* Byte 14 Bit 1 */
1377 boolean DriveCoercionEnabled:1; /* Byte 14 Bit 2 */ 1370 bool DriveCoercionEnabled:1; /* Byte 14 Bit 2 */
1378 boolean WriteSameDisabled:1; /* Byte 14 Bit 3 */ 1371 bool WriteSameDisabled:1; /* Byte 14 Bit 3 */
1379 boolean HBA_ModeEnabled:1; /* Byte 14 Bit 4 */ 1372 bool HBA_ModeEnabled:1; /* Byte 14 Bit 4 */
1380 enum { 1373 enum {
1381 DAC960_V2_Geometry_128_32 = 0x0, 1374 DAC960_V2_Geometry_128_32 = 0x0,
1382 DAC960_V2_Geometry_255_63 = 0x1, 1375 DAC960_V2_Geometry_255_63 = 0x1,
1383 DAC960_V2_Geometry_Reserved1 = 0x2, 1376 DAC960_V2_Geometry_Reserved1 = 0x2,
1384 DAC960_V2_Geometry_Reserved2 = 0x3 1377 DAC960_V2_Geometry_Reserved2 = 0x3
1385 } __attribute__ ((packed)) DriveGeometry:2; /* Byte 14 Bits 5-6 */ 1378 } __attribute__ ((packed)) DriveGeometry:2; /* Byte 14 Bits 5-6 */
1386 boolean SuperReadAheadEnabled:1; /* Byte 14 Bit 7 */ 1379 bool SuperReadAheadEnabled:1; /* Byte 14 Bit 7 */
1387 unsigned char :8; /* Byte 15 */ 1380 unsigned char :8; /* Byte 15 */
1388 /* Error Counters */ 1381 /* Error Counters */
1389 unsigned short SoftErrors; /* Bytes 16-17 */ 1382 unsigned short SoftErrors; /* Bytes 16-17 */
@@ -1446,13 +1439,13 @@ typedef struct DAC960_V2_PhysicalDeviceInfo
1446 unsigned char TargetID; /* Byte 2 */ 1439 unsigned char TargetID; /* Byte 2 */
1447 unsigned char LogicalUnit; /* Byte 3 */ 1440 unsigned char LogicalUnit; /* Byte 3 */
1448 /* Configuration Status Bits */ 1441 /* Configuration Status Bits */
1449 boolean PhysicalDeviceFaultTolerant:1; /* Byte 4 Bit 0 */ 1442 bool PhysicalDeviceFaultTolerant:1; /* Byte 4 Bit 0 */
1450 boolean PhysicalDeviceConnected:1; /* Byte 4 Bit 1 */ 1443 bool PhysicalDeviceConnected:1; /* Byte 4 Bit 1 */
1451 boolean PhysicalDeviceLocalToController:1; /* Byte 4 Bit 2 */ 1444 bool PhysicalDeviceLocalToController:1; /* Byte 4 Bit 2 */
1452 unsigned char :5; /* Byte 4 Bits 3-7 */ 1445 unsigned char :5; /* Byte 4 Bits 3-7 */
1453 /* Multiple Host/Controller Status Bits */ 1446 /* Multiple Host/Controller Status Bits */
1454 boolean RemoteHostSystemDead:1; /* Byte 5 Bit 0 */ 1447 bool RemoteHostSystemDead:1; /* Byte 5 Bit 0 */
1455 boolean RemoteControllerDead:1; /* Byte 5 Bit 1 */ 1448 bool RemoteControllerDead:1; /* Byte 5 Bit 1 */
1456 unsigned char :6; /* Byte 5 Bits 2-7 */ 1449 unsigned char :6; /* Byte 5 Bits 2-7 */
1457 DAC960_V2_PhysicalDeviceState_T PhysicalDeviceState; /* Byte 6 */ 1450 DAC960_V2_PhysicalDeviceState_T PhysicalDeviceState; /* Byte 6 */
1458 unsigned char NegotiatedDataWidthBits; /* Byte 7 */ 1451 unsigned char NegotiatedDataWidthBits; /* Byte 7 */
@@ -1464,12 +1457,12 @@ typedef struct DAC960_V2_PhysicalDeviceInfo
1464 unsigned char NetworkAddress[16]; /* Bytes 16-31 */ 1457 unsigned char NetworkAddress[16]; /* Bytes 16-31 */
1465 unsigned short MaximumTags; /* Bytes 32-33 */ 1458 unsigned short MaximumTags; /* Bytes 32-33 */
1466 /* Physical Device Operations Status */ 1459 /* Physical Device Operations Status */
1467 boolean ConsistencyCheckInProgress:1; /* Byte 34 Bit 0 */ 1460 bool ConsistencyCheckInProgress:1; /* Byte 34 Bit 0 */
1468 boolean RebuildInProgress:1; /* Byte 34 Bit 1 */ 1461 bool RebuildInProgress:1; /* Byte 34 Bit 1 */
1469 boolean MakingDataConsistentInProgress:1; /* Byte 34 Bit 2 */ 1462 bool MakingDataConsistentInProgress:1; /* Byte 34 Bit 2 */
1470 boolean PhysicalDeviceInitializationInProgress:1; /* Byte 34 Bit 3 */ 1463 bool PhysicalDeviceInitializationInProgress:1; /* Byte 34 Bit 3 */
1471 boolean DataMigrationInProgress:1; /* Byte 34 Bit 4 */ 1464 bool DataMigrationInProgress:1; /* Byte 34 Bit 4 */
1472 boolean PatrolOperationInProgress:1; /* Byte 34 Bit 5 */ 1465 bool PatrolOperationInProgress:1; /* Byte 34 Bit 5 */
1473 unsigned char :2; /* Byte 34 Bits 6-7 */ 1466 unsigned char :2; /* Byte 34 Bits 6-7 */
1474 unsigned char LongOperationStatus; /* Byte 35 */ 1467 unsigned char LongOperationStatus; /* Byte 35 */
1475 unsigned char ParityErrors; /* Byte 36 */ 1468 unsigned char ParityErrors; /* Byte 36 */
@@ -1555,14 +1548,14 @@ DAC960_V2_Event_T;
1555 1548
1556typedef struct DAC960_V2_CommandControlBits 1549typedef struct DAC960_V2_CommandControlBits
1557{ 1550{
1558 boolean ForceUnitAccess:1; /* Byte 0 Bit 0 */ 1551 bool ForceUnitAccess:1; /* Byte 0 Bit 0 */
1559 boolean DisablePageOut:1; /* Byte 0 Bit 1 */ 1552 bool DisablePageOut:1; /* Byte 0 Bit 1 */
1560 boolean :1; /* Byte 0 Bit 2 */ 1553 bool :1; /* Byte 0 Bit 2 */
1561 boolean AdditionalScatterGatherListMemory:1; /* Byte 0 Bit 3 */ 1554 bool AdditionalScatterGatherListMemory:1; /* Byte 0 Bit 3 */
1562 boolean DataTransferControllerToHost:1; /* Byte 0 Bit 4 */ 1555 bool DataTransferControllerToHost:1; /* Byte 0 Bit 4 */
1563 boolean :1; /* Byte 0 Bit 5 */ 1556 bool :1; /* Byte 0 Bit 5 */
1564 boolean NoAutoRequestSense:1; /* Byte 0 Bit 6 */ 1557 bool NoAutoRequestSense:1; /* Byte 0 Bit 6 */
1565 boolean DisconnectProhibited:1; /* Byte 0 Bit 7 */ 1558 bool DisconnectProhibited:1; /* Byte 0 Bit 7 */
1566} 1559}
1567DAC960_V2_CommandControlBits_T; 1560DAC960_V2_CommandControlBits_T;
1568 1561
@@ -1825,8 +1818,8 @@ typedef union DAC960_V2_CommandMailbox
1825 DAC960_V2_CommandTimeout_T CommandTimeout; /* Byte 19 */ 1818 DAC960_V2_CommandTimeout_T CommandTimeout; /* Byte 19 */
1826 unsigned char RequestSenseSize; /* Byte 20 */ 1819 unsigned char RequestSenseSize; /* Byte 20 */
1827 unsigned char IOCTL_Opcode; /* Byte 21 */ 1820 unsigned char IOCTL_Opcode; /* Byte 21 */
1828 boolean RestoreConsistency:1; /* Byte 22 Bit 0 */ 1821 bool RestoreConsistency:1; /* Byte 22 Bit 0 */
1829 boolean InitializedAreaOnly:1; /* Byte 22 Bit 1 */ 1822 bool InitializedAreaOnly:1; /* Byte 22 Bit 1 */
1830 unsigned char :6; /* Byte 22 Bits 2-7 */ 1823 unsigned char :6; /* Byte 22 Bits 2-7 */
1831 unsigned char Reserved[9]; /* Bytes 23-31 */ 1824 unsigned char Reserved[9]; /* Bytes 23-31 */
1832 DAC960_V2_DataTransferMemoryAddress_T 1825 DAC960_V2_DataTransferMemoryAddress_T
@@ -2190,7 +2183,7 @@ typedef union DAC960_V1_StatusMailbox
2190 struct { 2183 struct {
2191 DAC960_V1_CommandIdentifier_T CommandIdentifier; /* Byte 0 */ 2184 DAC960_V1_CommandIdentifier_T CommandIdentifier; /* Byte 0 */
2192 unsigned char :7; /* Byte 1 Bits 0-6 */ 2185 unsigned char :7; /* Byte 1 Bits 0-6 */
2193 boolean Valid:1; /* Byte 1 Bit 7 */ 2186 bool Valid:1; /* Byte 1 Bit 7 */
2194 DAC960_V1_CommandStatus_T CommandStatus; /* Bytes 2-3 */ 2187 DAC960_V1_CommandStatus_T CommandStatus; /* Bytes 2-3 */
2195 } Fields; 2188 } Fields;
2196} 2189}
@@ -2322,12 +2315,12 @@ typedef struct DAC960_Controller
2322 unsigned long ShutdownMonitoringTimer; 2315 unsigned long ShutdownMonitoringTimer;
2323 unsigned long LastProgressReportTime; 2316 unsigned long LastProgressReportTime;
2324 unsigned long LastCurrentStatusTime; 2317 unsigned long LastCurrentStatusTime;
2325 boolean ControllerInitialized; 2318 bool ControllerInitialized;
2326 boolean MonitoringCommandDeferred; 2319 bool MonitoringCommandDeferred;
2327 boolean EphemeralProgressMessage; 2320 bool EphemeralProgressMessage;
2328 boolean DriveSpinUpMessageDisplayed; 2321 bool DriveSpinUpMessageDisplayed;
2329 boolean MonitoringAlertMode; 2322 bool MonitoringAlertMode;
2330 boolean SuppressEnclosureMessages; 2323 bool SuppressEnclosureMessages;
2331 struct timer_list MonitoringTimer; 2324 struct timer_list MonitoringTimer;
2332 struct gendisk *disks[DAC960_MaxLogicalDrives]; 2325 struct gendisk *disks[DAC960_MaxLogicalDrives];
2333 struct pci_pool *ScatterGatherPool; 2326 struct pci_pool *ScatterGatherPool;
@@ -2342,11 +2335,11 @@ typedef struct DAC960_Controller
2342 DAC960_Command_T InitialCommand; 2335 DAC960_Command_T InitialCommand;
2343 DAC960_Command_T *Commands[DAC960_MaxDriverQueueDepth]; 2336 DAC960_Command_T *Commands[DAC960_MaxDriverQueueDepth];
2344 struct proc_dir_entry *ControllerProcEntry; 2337 struct proc_dir_entry *ControllerProcEntry;
2345 boolean LogicalDriveInitiallyAccessible[DAC960_MaxLogicalDrives]; 2338 bool LogicalDriveInitiallyAccessible[DAC960_MaxLogicalDrives];
2346 void (*QueueCommand)(DAC960_Command_T *Command); 2339 void (*QueueCommand)(DAC960_Command_T *Command);
2347 boolean (*ReadControllerConfiguration)(struct DAC960_Controller *); 2340 bool (*ReadControllerConfiguration)(struct DAC960_Controller *);
2348 boolean (*ReadDeviceConfiguration)(struct DAC960_Controller *); 2341 bool (*ReadDeviceConfiguration)(struct DAC960_Controller *);
2349 boolean (*ReportDeviceConfiguration)(struct DAC960_Controller *); 2342 bool (*ReportDeviceConfiguration)(struct DAC960_Controller *);
2350 void (*QueueReadWriteCommand)(DAC960_Command_T *Command); 2343 void (*QueueReadWriteCommand)(DAC960_Command_T *Command);
2351 union { 2344 union {
2352 struct { 2345 struct {
@@ -2359,21 +2352,21 @@ typedef struct DAC960_Controller
2359 unsigned short OldEventLogSequenceNumber; 2352 unsigned short OldEventLogSequenceNumber;
2360 unsigned short DeviceStateChannel; 2353 unsigned short DeviceStateChannel;
2361 unsigned short DeviceStateTargetID; 2354 unsigned short DeviceStateTargetID;
2362 boolean DualModeMemoryMailboxInterface; 2355 bool DualModeMemoryMailboxInterface;
2363 boolean BackgroundInitializationStatusSupported; 2356 bool BackgroundInitializationStatusSupported;
2364 boolean SAFTE_EnclosureManagementEnabled; 2357 bool SAFTE_EnclosureManagementEnabled;
2365 boolean NeedLogicalDriveInformation; 2358 bool NeedLogicalDriveInformation;
2366 boolean NeedErrorTableInformation; 2359 bool NeedErrorTableInformation;
2367 boolean NeedDeviceStateInformation; 2360 bool NeedDeviceStateInformation;
2368 boolean NeedDeviceInquiryInformation; 2361 bool NeedDeviceInquiryInformation;
2369 boolean NeedDeviceSerialNumberInformation; 2362 bool NeedDeviceSerialNumberInformation;
2370 boolean NeedRebuildProgress; 2363 bool NeedRebuildProgress;
2371 boolean NeedConsistencyCheckProgress; 2364 bool NeedConsistencyCheckProgress;
2372 boolean NeedBackgroundInitializationStatus; 2365 bool NeedBackgroundInitializationStatus;
2373 boolean StartDeviceStateScan; 2366 bool StartDeviceStateScan;
2374 boolean RebuildProgressFirst; 2367 bool RebuildProgressFirst;
2375 boolean RebuildFlagPending; 2368 bool RebuildFlagPending;
2376 boolean RebuildStatusPending; 2369 bool RebuildStatusPending;
2377 2370
2378 dma_addr_t FirstCommandMailboxDMA; 2371 dma_addr_t FirstCommandMailboxDMA;
2379 DAC960_V1_CommandMailbox_T *FirstCommandMailbox; 2372 DAC960_V1_CommandMailbox_T *FirstCommandMailbox;
@@ -2432,17 +2425,17 @@ typedef struct DAC960_Controller
2432 dma_addr_t NewInquiryUnitSerialNumberDMA; 2425 dma_addr_t NewInquiryUnitSerialNumberDMA;
2433 2426
2434 int DeviceResetCount[DAC960_V1_MaxChannels][DAC960_V1_MaxTargets]; 2427 int DeviceResetCount[DAC960_V1_MaxChannels][DAC960_V1_MaxTargets];
2435 boolean DirectCommandActive[DAC960_V1_MaxChannels][DAC960_V1_MaxTargets]; 2428 bool DirectCommandActive[DAC960_V1_MaxChannels][DAC960_V1_MaxTargets];
2436 } V1; 2429 } V1;
2437 struct { 2430 struct {
2438 unsigned int StatusChangeCounter; 2431 unsigned int StatusChangeCounter;
2439 unsigned int NextEventSequenceNumber; 2432 unsigned int NextEventSequenceNumber;
2440 unsigned int PhysicalDeviceIndex; 2433 unsigned int PhysicalDeviceIndex;
2441 boolean NeedLogicalDeviceInformation; 2434 bool NeedLogicalDeviceInformation;
2442 boolean NeedPhysicalDeviceInformation; 2435 bool NeedPhysicalDeviceInformation;
2443 boolean NeedDeviceSerialNumberInformation; 2436 bool NeedDeviceSerialNumberInformation;
2444 boolean StartLogicalDeviceInformationScan; 2437 bool StartLogicalDeviceInformationScan;
2445 boolean StartPhysicalDeviceInformationScan; 2438 bool StartPhysicalDeviceInformationScan;
2446 struct pci_pool *RequestSensePool; 2439 struct pci_pool *RequestSensePool;
2447 2440
2448 dma_addr_t FirstCommandMailboxDMA; 2441 dma_addr_t FirstCommandMailboxDMA;
@@ -2487,7 +2480,7 @@ typedef struct DAC960_Controller
2487 2480
2488 DAC960_V2_PhysicalDevice_T 2481 DAC960_V2_PhysicalDevice_T
2489 LogicalDriveToVirtualDevice[DAC960_MaxLogicalDrives]; 2482 LogicalDriveToVirtualDevice[DAC960_MaxLogicalDrives];
2490 boolean LogicalDriveFoundDuringScan[DAC960_MaxLogicalDrives]; 2483 bool LogicalDriveFoundDuringScan[DAC960_MaxLogicalDrives];
2491 } V2; 2484 } V2;
2492 } FW; 2485 } FW;
2493 unsigned char ProgressBuffer[DAC960_ProgressBufferSize]; 2486 unsigned char ProgressBuffer[DAC960_ProgressBufferSize];
@@ -2572,17 +2565,17 @@ typedef union DAC960_GEM_InboundDoorBellRegister
2572 unsigned int All; 2565 unsigned int All;
2573 struct { 2566 struct {
2574 unsigned int :24; 2567 unsigned int :24;
2575 boolean HardwareMailboxNewCommand:1; 2568 bool HardwareMailboxNewCommand:1;
2576 boolean AcknowledgeHardwareMailboxStatus:1; 2569 bool AcknowledgeHardwareMailboxStatus:1;
2577 boolean GenerateInterrupt:1; 2570 bool GenerateInterrupt:1;
2578 boolean ControllerReset:1; 2571 bool ControllerReset:1;
2579 boolean MemoryMailboxNewCommand:1; 2572 bool MemoryMailboxNewCommand:1;
2580 unsigned int :3; 2573 unsigned int :3;
2581 } Write; 2574 } Write;
2582 struct { 2575 struct {
2583 unsigned int :24; 2576 unsigned int :24;
2584 boolean HardwareMailboxFull:1; 2577 bool HardwareMailboxFull:1;
2585 boolean InitializationInProgress:1; 2578 bool InitializationInProgress:1;
2586 unsigned int :6; 2579 unsigned int :6;
2587 } Read; 2580 } Read;
2588} 2581}
@@ -2596,14 +2589,14 @@ typedef union DAC960_GEM_OutboundDoorBellRegister
2596 unsigned int All; 2589 unsigned int All;
2597 struct { 2590 struct {
2598 unsigned int :24; 2591 unsigned int :24;
2599 boolean AcknowledgeHardwareMailboxInterrupt:1; 2592 bool AcknowledgeHardwareMailboxInterrupt:1;
2600 boolean AcknowledgeMemoryMailboxInterrupt:1; 2593 bool AcknowledgeMemoryMailboxInterrupt:1;
2601 unsigned int :6; 2594 unsigned int :6;
2602 } Write; 2595 } Write;
2603 struct { 2596 struct {
2604 unsigned int :24; 2597 unsigned int :24;
2605 boolean HardwareMailboxStatusAvailable:1; 2598 bool HardwareMailboxStatusAvailable:1;
2606 boolean MemoryMailboxStatusAvailable:1; 2599 bool MemoryMailboxStatusAvailable:1;
2607 unsigned int :6; 2600 unsigned int :6;
2608 } Read; 2601 } Read;
2609} 2602}
@@ -2635,7 +2628,7 @@ typedef union DAC960_GEM_ErrorStatusRegister
2635 struct { 2628 struct {
2636 unsigned int :24; 2629 unsigned int :24;
2637 unsigned int :5; 2630 unsigned int :5;
2638 boolean ErrorStatusPending:1; 2631 bool ErrorStatusPending:1;
2639 unsigned int :2; 2632 unsigned int :2;
2640 } Bits; 2633 } Bits;
2641} 2634}
@@ -2697,7 +2690,7 @@ void DAC960_GEM_MemoryMailboxNewCommand(void __iomem *ControllerBaseAddress)
2697} 2690}
2698 2691
2699static inline 2692static inline
2700boolean DAC960_GEM_HardwareMailboxFullP(void __iomem *ControllerBaseAddress) 2693bool DAC960_GEM_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
2701{ 2694{
2702 DAC960_GEM_InboundDoorBellRegister_T InboundDoorBellRegister; 2695 DAC960_GEM_InboundDoorBellRegister_T InboundDoorBellRegister;
2703 InboundDoorBellRegister.All = 2696 InboundDoorBellRegister.All =
@@ -2707,7 +2700,7 @@ boolean DAC960_GEM_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
2707} 2700}
2708 2701
2709static inline 2702static inline
2710boolean DAC960_GEM_InitializationInProgressP(void __iomem *ControllerBaseAddress) 2703bool DAC960_GEM_InitializationInProgressP(void __iomem *ControllerBaseAddress)
2711{ 2704{
2712 DAC960_GEM_InboundDoorBellRegister_T InboundDoorBellRegister; 2705 DAC960_GEM_InboundDoorBellRegister_T InboundDoorBellRegister;
2713 InboundDoorBellRegister.All = 2706 InboundDoorBellRegister.All =
@@ -2748,7 +2741,7 @@ void DAC960_GEM_AcknowledgeInterrupt(void __iomem *ControllerBaseAddress)
2748} 2741}
2749 2742
2750static inline 2743static inline
2751boolean DAC960_GEM_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 2744bool DAC960_GEM_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
2752{ 2745{
2753 DAC960_GEM_OutboundDoorBellRegister_T OutboundDoorBellRegister; 2746 DAC960_GEM_OutboundDoorBellRegister_T OutboundDoorBellRegister;
2754 OutboundDoorBellRegister.All = 2747 OutboundDoorBellRegister.All =
@@ -2758,7 +2751,7 @@ boolean DAC960_GEM_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseA
2758} 2751}
2759 2752
2760static inline 2753static inline
2761boolean DAC960_GEM_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 2754bool DAC960_GEM_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
2762{ 2755{
2763 DAC960_GEM_OutboundDoorBellRegister_T OutboundDoorBellRegister; 2756 DAC960_GEM_OutboundDoorBellRegister_T OutboundDoorBellRegister;
2764 OutboundDoorBellRegister.All = 2757 OutboundDoorBellRegister.All =
@@ -2790,7 +2783,7 @@ void DAC960_GEM_DisableInterrupts(void __iomem *ControllerBaseAddress)
2790} 2783}
2791 2784
2792static inline 2785static inline
2793boolean DAC960_GEM_InterruptsEnabledP(void __iomem *ControllerBaseAddress) 2786bool DAC960_GEM_InterruptsEnabledP(void __iomem *ControllerBaseAddress)
2794{ 2787{
2795 DAC960_GEM_InterruptMaskRegister_T InterruptMaskRegister; 2788 DAC960_GEM_InterruptMaskRegister_T InterruptMaskRegister;
2796 InterruptMaskRegister.All = 2789 InterruptMaskRegister.All =
@@ -2834,7 +2827,7 @@ DAC960_GEM_ReadCommandStatus(void __iomem *ControllerBaseAddress)
2834 return readw(ControllerBaseAddress + DAC960_GEM_CommandStatusOffset + 2); 2827 return readw(ControllerBaseAddress + DAC960_GEM_CommandStatusOffset + 2);
2835} 2828}
2836 2829
2837static inline boolean 2830static inline bool
2838DAC960_GEM_ReadErrorStatus(void __iomem *ControllerBaseAddress, 2831DAC960_GEM_ReadErrorStatus(void __iomem *ControllerBaseAddress,
2839 unsigned char *ErrorStatus, 2832 unsigned char *ErrorStatus,
2840 unsigned char *Parameter0, 2833 unsigned char *Parameter0,
@@ -2882,16 +2875,16 @@ typedef union DAC960_BA_InboundDoorBellRegister
2882{ 2875{
2883 unsigned char All; 2876 unsigned char All;
2884 struct { 2877 struct {
2885 boolean HardwareMailboxNewCommand:1; /* Bit 0 */ 2878 bool HardwareMailboxNewCommand:1; /* Bit 0 */
2886 boolean AcknowledgeHardwareMailboxStatus:1; /* Bit 1 */ 2879 bool AcknowledgeHardwareMailboxStatus:1; /* Bit 1 */
2887 boolean GenerateInterrupt:1; /* Bit 2 */ 2880 bool GenerateInterrupt:1; /* Bit 2 */
2888 boolean ControllerReset:1; /* Bit 3 */ 2881 bool ControllerReset:1; /* Bit 3 */
2889 boolean MemoryMailboxNewCommand:1; /* Bit 4 */ 2882 bool MemoryMailboxNewCommand:1; /* Bit 4 */
2890 unsigned char :3; /* Bits 5-7 */ 2883 unsigned char :3; /* Bits 5-7 */
2891 } Write; 2884 } Write;
2892 struct { 2885 struct {
2893 boolean HardwareMailboxEmpty:1; /* Bit 0 */ 2886 bool HardwareMailboxEmpty:1; /* Bit 0 */
2894 boolean InitializationNotInProgress:1; /* Bit 1 */ 2887 bool InitializationNotInProgress:1; /* Bit 1 */
2895 unsigned char :6; /* Bits 2-7 */ 2888 unsigned char :6; /* Bits 2-7 */
2896 } Read; 2889 } Read;
2897} 2890}
@@ -2906,13 +2899,13 @@ typedef union DAC960_BA_OutboundDoorBellRegister
2906{ 2899{
2907 unsigned char All; 2900 unsigned char All;
2908 struct { 2901 struct {
2909 boolean AcknowledgeHardwareMailboxInterrupt:1; /* Bit 0 */ 2902 bool AcknowledgeHardwareMailboxInterrupt:1; /* Bit 0 */
2910 boolean AcknowledgeMemoryMailboxInterrupt:1; /* Bit 1 */ 2903 bool AcknowledgeMemoryMailboxInterrupt:1; /* Bit 1 */
2911 unsigned char :6; /* Bits 2-7 */ 2904 unsigned char :6; /* Bits 2-7 */
2912 } Write; 2905 } Write;
2913 struct { 2906 struct {
2914 boolean HardwareMailboxStatusAvailable:1; /* Bit 0 */ 2907 bool HardwareMailboxStatusAvailable:1; /* Bit 0 */
2915 boolean MemoryMailboxStatusAvailable:1; /* Bit 1 */ 2908 bool MemoryMailboxStatusAvailable:1; /* Bit 1 */
2916 unsigned char :6; /* Bits 2-7 */ 2909 unsigned char :6; /* Bits 2-7 */
2917 } Read; 2910 } Read;
2918} 2911}
@@ -2928,8 +2921,8 @@ typedef union DAC960_BA_InterruptMaskRegister
2928 unsigned char All; 2921 unsigned char All;
2929 struct { 2922 struct {
2930 unsigned int :2; /* Bits 0-1 */ 2923 unsigned int :2; /* Bits 0-1 */
2931 boolean DisableInterrupts:1; /* Bit 2 */ 2924 bool DisableInterrupts:1; /* Bit 2 */
2932 boolean DisableInterruptsI2O:1; /* Bit 3 */ 2925 bool DisableInterruptsI2O:1; /* Bit 3 */
2933 unsigned int :4; /* Bits 4-7 */ 2926 unsigned int :4; /* Bits 4-7 */
2934 } Bits; 2927 } Bits;
2935} 2928}
@@ -2945,7 +2938,7 @@ typedef union DAC960_BA_ErrorStatusRegister
2945 unsigned char All; 2938 unsigned char All;
2946 struct { 2939 struct {
2947 unsigned int :2; /* Bits 0-1 */ 2940 unsigned int :2; /* Bits 0-1 */
2948 boolean ErrorStatusPending:1; /* Bit 2 */ 2941 bool ErrorStatusPending:1; /* Bit 2 */
2949 unsigned int :5; /* Bits 3-7 */ 2942 unsigned int :5; /* Bits 3-7 */
2950 } Bits; 2943 } Bits;
2951} 2944}
@@ -3008,7 +3001,7 @@ void DAC960_BA_MemoryMailboxNewCommand(void __iomem *ControllerBaseAddress)
3008} 3001}
3009 3002
3010static inline 3003static inline
3011boolean DAC960_BA_HardwareMailboxFullP(void __iomem *ControllerBaseAddress) 3004bool DAC960_BA_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
3012{ 3005{
3013 DAC960_BA_InboundDoorBellRegister_T InboundDoorBellRegister; 3006 DAC960_BA_InboundDoorBellRegister_T InboundDoorBellRegister;
3014 InboundDoorBellRegister.All = 3007 InboundDoorBellRegister.All =
@@ -3017,7 +3010,7 @@ boolean DAC960_BA_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
3017} 3010}
3018 3011
3019static inline 3012static inline
3020boolean DAC960_BA_InitializationInProgressP(void __iomem *ControllerBaseAddress) 3013bool DAC960_BA_InitializationInProgressP(void __iomem *ControllerBaseAddress)
3021{ 3014{
3022 DAC960_BA_InboundDoorBellRegister_T InboundDoorBellRegister; 3015 DAC960_BA_InboundDoorBellRegister_T InboundDoorBellRegister;
3023 InboundDoorBellRegister.All = 3016 InboundDoorBellRegister.All =
@@ -3057,7 +3050,7 @@ void DAC960_BA_AcknowledgeInterrupt(void __iomem *ControllerBaseAddress)
3057} 3050}
3058 3051
3059static inline 3052static inline
3060boolean DAC960_BA_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 3053bool DAC960_BA_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
3061{ 3054{
3062 DAC960_BA_OutboundDoorBellRegister_T OutboundDoorBellRegister; 3055 DAC960_BA_OutboundDoorBellRegister_T OutboundDoorBellRegister;
3063 OutboundDoorBellRegister.All = 3056 OutboundDoorBellRegister.All =
@@ -3066,7 +3059,7 @@ boolean DAC960_BA_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAd
3066} 3059}
3067 3060
3068static inline 3061static inline
3069boolean DAC960_BA_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 3062bool DAC960_BA_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
3070{ 3063{
3071 DAC960_BA_OutboundDoorBellRegister_T OutboundDoorBellRegister; 3064 DAC960_BA_OutboundDoorBellRegister_T OutboundDoorBellRegister;
3072 OutboundDoorBellRegister.All = 3065 OutboundDoorBellRegister.All =
@@ -3097,7 +3090,7 @@ void DAC960_BA_DisableInterrupts(void __iomem *ControllerBaseAddress)
3097} 3090}
3098 3091
3099static inline 3092static inline
3100boolean DAC960_BA_InterruptsEnabledP(void __iomem *ControllerBaseAddress) 3093bool DAC960_BA_InterruptsEnabledP(void __iomem *ControllerBaseAddress)
3101{ 3094{
3102 DAC960_BA_InterruptMaskRegister_T InterruptMaskRegister; 3095 DAC960_BA_InterruptMaskRegister_T InterruptMaskRegister;
3103 InterruptMaskRegister.All = 3096 InterruptMaskRegister.All =
@@ -3140,7 +3133,7 @@ DAC960_BA_ReadCommandStatus(void __iomem *ControllerBaseAddress)
3140 return readw(ControllerBaseAddress + DAC960_BA_CommandStatusOffset + 2); 3133 return readw(ControllerBaseAddress + DAC960_BA_CommandStatusOffset + 2);
3141} 3134}
3142 3135
3143static inline boolean 3136static inline bool
3144DAC960_BA_ReadErrorStatus(void __iomem *ControllerBaseAddress, 3137DAC960_BA_ReadErrorStatus(void __iomem *ControllerBaseAddress,
3145 unsigned char *ErrorStatus, 3138 unsigned char *ErrorStatus,
3146 unsigned char *Parameter0, 3139 unsigned char *Parameter0,
@@ -3188,16 +3181,16 @@ typedef union DAC960_LP_InboundDoorBellRegister
3188{ 3181{
3189 unsigned char All; 3182 unsigned char All;
3190 struct { 3183 struct {
3191 boolean HardwareMailboxNewCommand:1; /* Bit 0 */ 3184 bool HardwareMailboxNewCommand:1; /* Bit 0 */
3192 boolean AcknowledgeHardwareMailboxStatus:1; /* Bit 1 */ 3185 bool AcknowledgeHardwareMailboxStatus:1; /* Bit 1 */
3193 boolean GenerateInterrupt:1; /* Bit 2 */ 3186 bool GenerateInterrupt:1; /* Bit 2 */
3194 boolean ControllerReset:1; /* Bit 3 */ 3187 bool ControllerReset:1; /* Bit 3 */
3195 boolean MemoryMailboxNewCommand:1; /* Bit 4 */ 3188 bool MemoryMailboxNewCommand:1; /* Bit 4 */
3196 unsigned char :3; /* Bits 5-7 */ 3189 unsigned char :3; /* Bits 5-7 */
3197 } Write; 3190 } Write;
3198 struct { 3191 struct {
3199 boolean HardwareMailboxFull:1; /* Bit 0 */ 3192 bool HardwareMailboxFull:1; /* Bit 0 */
3200 boolean InitializationInProgress:1; /* Bit 1 */ 3193 bool InitializationInProgress:1; /* Bit 1 */
3201 unsigned char :6; /* Bits 2-7 */ 3194 unsigned char :6; /* Bits 2-7 */
3202 } Read; 3195 } Read;
3203} 3196}
@@ -3212,13 +3205,13 @@ typedef union DAC960_LP_OutboundDoorBellRegister
3212{ 3205{
3213 unsigned char All; 3206 unsigned char All;
3214 struct { 3207 struct {
3215 boolean AcknowledgeHardwareMailboxInterrupt:1; /* Bit 0 */ 3208 bool AcknowledgeHardwareMailboxInterrupt:1; /* Bit 0 */
3216 boolean AcknowledgeMemoryMailboxInterrupt:1; /* Bit 1 */ 3209 bool AcknowledgeMemoryMailboxInterrupt:1; /* Bit 1 */
3217 unsigned char :6; /* Bits 2-7 */ 3210 unsigned char :6; /* Bits 2-7 */
3218 } Write; 3211 } Write;
3219 struct { 3212 struct {
3220 boolean HardwareMailboxStatusAvailable:1; /* Bit 0 */ 3213 bool HardwareMailboxStatusAvailable:1; /* Bit 0 */
3221 boolean MemoryMailboxStatusAvailable:1; /* Bit 1 */ 3214 bool MemoryMailboxStatusAvailable:1; /* Bit 1 */
3222 unsigned char :6; /* Bits 2-7 */ 3215 unsigned char :6; /* Bits 2-7 */
3223 } Read; 3216 } Read;
3224} 3217}
@@ -3234,7 +3227,7 @@ typedef union DAC960_LP_InterruptMaskRegister
3234 unsigned char All; 3227 unsigned char All;
3235 struct { 3228 struct {
3236 unsigned int :2; /* Bits 0-1 */ 3229 unsigned int :2; /* Bits 0-1 */
3237 boolean DisableInterrupts:1; /* Bit 2 */ 3230 bool DisableInterrupts:1; /* Bit 2 */
3238 unsigned int :5; /* Bits 3-7 */ 3231 unsigned int :5; /* Bits 3-7 */
3239 } Bits; 3232 } Bits;
3240} 3233}
@@ -3250,7 +3243,7 @@ typedef union DAC960_LP_ErrorStatusRegister
3250 unsigned char All; 3243 unsigned char All;
3251 struct { 3244 struct {
3252 unsigned int :2; /* Bits 0-1 */ 3245 unsigned int :2; /* Bits 0-1 */
3253 boolean ErrorStatusPending:1; /* Bit 2 */ 3246 bool ErrorStatusPending:1; /* Bit 2 */
3254 unsigned int :5; /* Bits 3-7 */ 3247 unsigned int :5; /* Bits 3-7 */
3255 } Bits; 3248 } Bits;
3256} 3249}
@@ -3313,7 +3306,7 @@ void DAC960_LP_MemoryMailboxNewCommand(void __iomem *ControllerBaseAddress)
3313} 3306}
3314 3307
3315static inline 3308static inline
3316boolean DAC960_LP_HardwareMailboxFullP(void __iomem *ControllerBaseAddress) 3309bool DAC960_LP_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
3317{ 3310{
3318 DAC960_LP_InboundDoorBellRegister_T InboundDoorBellRegister; 3311 DAC960_LP_InboundDoorBellRegister_T InboundDoorBellRegister;
3319 InboundDoorBellRegister.All = 3312 InboundDoorBellRegister.All =
@@ -3322,7 +3315,7 @@ boolean DAC960_LP_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
3322} 3315}
3323 3316
3324static inline 3317static inline
3325boolean DAC960_LP_InitializationInProgressP(void __iomem *ControllerBaseAddress) 3318bool DAC960_LP_InitializationInProgressP(void __iomem *ControllerBaseAddress)
3326{ 3319{
3327 DAC960_LP_InboundDoorBellRegister_T InboundDoorBellRegister; 3320 DAC960_LP_InboundDoorBellRegister_T InboundDoorBellRegister;
3328 InboundDoorBellRegister.All = 3321 InboundDoorBellRegister.All =
@@ -3362,7 +3355,7 @@ void DAC960_LP_AcknowledgeInterrupt(void __iomem *ControllerBaseAddress)
3362} 3355}
3363 3356
3364static inline 3357static inline
3365boolean DAC960_LP_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 3358bool DAC960_LP_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
3366{ 3359{
3367 DAC960_LP_OutboundDoorBellRegister_T OutboundDoorBellRegister; 3360 DAC960_LP_OutboundDoorBellRegister_T OutboundDoorBellRegister;
3368 OutboundDoorBellRegister.All = 3361 OutboundDoorBellRegister.All =
@@ -3371,7 +3364,7 @@ boolean DAC960_LP_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAd
3371} 3364}
3372 3365
3373static inline 3366static inline
3374boolean DAC960_LP_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 3367bool DAC960_LP_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
3375{ 3368{
3376 DAC960_LP_OutboundDoorBellRegister_T OutboundDoorBellRegister; 3369 DAC960_LP_OutboundDoorBellRegister_T OutboundDoorBellRegister;
3377 OutboundDoorBellRegister.All = 3370 OutboundDoorBellRegister.All =
@@ -3400,7 +3393,7 @@ void DAC960_LP_DisableInterrupts(void __iomem *ControllerBaseAddress)
3400} 3393}
3401 3394
3402static inline 3395static inline
3403boolean DAC960_LP_InterruptsEnabledP(void __iomem *ControllerBaseAddress) 3396bool DAC960_LP_InterruptsEnabledP(void __iomem *ControllerBaseAddress)
3404{ 3397{
3405 DAC960_LP_InterruptMaskRegister_T InterruptMaskRegister; 3398 DAC960_LP_InterruptMaskRegister_T InterruptMaskRegister;
3406 InterruptMaskRegister.All = 3399 InterruptMaskRegister.All =
@@ -3442,7 +3435,7 @@ DAC960_LP_ReadCommandStatus(void __iomem *ControllerBaseAddress)
3442 return readw(ControllerBaseAddress + DAC960_LP_CommandStatusOffset + 2); 3435 return readw(ControllerBaseAddress + DAC960_LP_CommandStatusOffset + 2);
3443} 3436}
3444 3437
3445static inline boolean 3438static inline bool
3446DAC960_LP_ReadErrorStatus(void __iomem *ControllerBaseAddress, 3439DAC960_LP_ReadErrorStatus(void __iomem *ControllerBaseAddress,
3447 unsigned char *ErrorStatus, 3440 unsigned char *ErrorStatus,
3448 unsigned char *Parameter0, 3441 unsigned char *Parameter0,
@@ -3502,16 +3495,16 @@ typedef union DAC960_LA_InboundDoorBellRegister
3502{ 3495{
3503 unsigned char All; 3496 unsigned char All;
3504 struct { 3497 struct {
3505 boolean HardwareMailboxNewCommand:1; /* Bit 0 */ 3498 bool HardwareMailboxNewCommand:1; /* Bit 0 */
3506 boolean AcknowledgeHardwareMailboxStatus:1; /* Bit 1 */ 3499 bool AcknowledgeHardwareMailboxStatus:1; /* Bit 1 */
3507 boolean GenerateInterrupt:1; /* Bit 2 */ 3500 bool GenerateInterrupt:1; /* Bit 2 */
3508 boolean ControllerReset:1; /* Bit 3 */ 3501 bool ControllerReset:1; /* Bit 3 */
3509 boolean MemoryMailboxNewCommand:1; /* Bit 4 */ 3502 bool MemoryMailboxNewCommand:1; /* Bit 4 */
3510 unsigned char :3; /* Bits 5-7 */ 3503 unsigned char :3; /* Bits 5-7 */
3511 } Write; 3504 } Write;
3512 struct { 3505 struct {
3513 boolean HardwareMailboxEmpty:1; /* Bit 0 */ 3506 bool HardwareMailboxEmpty:1; /* Bit 0 */
3514 boolean InitializationNotInProgress:1; /* Bit 1 */ 3507 bool InitializationNotInProgress:1; /* Bit 1 */
3515 unsigned char :6; /* Bits 2-7 */ 3508 unsigned char :6; /* Bits 2-7 */
3516 } Read; 3509 } Read;
3517} 3510}
@@ -3526,13 +3519,13 @@ typedef union DAC960_LA_OutboundDoorBellRegister
3526{ 3519{
3527 unsigned char All; 3520 unsigned char All;
3528 struct { 3521 struct {
3529 boolean AcknowledgeHardwareMailboxInterrupt:1; /* Bit 0 */ 3522 bool AcknowledgeHardwareMailboxInterrupt:1; /* Bit 0 */
3530 boolean AcknowledgeMemoryMailboxInterrupt:1; /* Bit 1 */ 3523 bool AcknowledgeMemoryMailboxInterrupt:1; /* Bit 1 */
3531 unsigned char :6; /* Bits 2-7 */ 3524 unsigned char :6; /* Bits 2-7 */
3532 } Write; 3525 } Write;
3533 struct { 3526 struct {
3534 boolean HardwareMailboxStatusAvailable:1; /* Bit 0 */ 3527 bool HardwareMailboxStatusAvailable:1; /* Bit 0 */
3535 boolean MemoryMailboxStatusAvailable:1; /* Bit 1 */ 3528 bool MemoryMailboxStatusAvailable:1; /* Bit 1 */
3536 unsigned char :6; /* Bits 2-7 */ 3529 unsigned char :6; /* Bits 2-7 */
3537 } Read; 3530 } Read;
3538} 3531}
@@ -3548,7 +3541,7 @@ typedef union DAC960_LA_InterruptMaskRegister
3548 unsigned char All; 3541 unsigned char All;
3549 struct { 3542 struct {
3550 unsigned char :2; /* Bits 0-1 */ 3543 unsigned char :2; /* Bits 0-1 */
3551 boolean DisableInterrupts:1; /* Bit 2 */ 3544 bool DisableInterrupts:1; /* Bit 2 */
3552 unsigned char :5; /* Bits 3-7 */ 3545 unsigned char :5; /* Bits 3-7 */
3553 } Bits; 3546 } Bits;
3554} 3547}
@@ -3564,7 +3557,7 @@ typedef union DAC960_LA_ErrorStatusRegister
3564 unsigned char All; 3557 unsigned char All;
3565 struct { 3558 struct {
3566 unsigned int :2; /* Bits 0-1 */ 3559 unsigned int :2; /* Bits 0-1 */
3567 boolean ErrorStatusPending:1; /* Bit 2 */ 3560 bool ErrorStatusPending:1; /* Bit 2 */
3568 unsigned int :5; /* Bits 3-7 */ 3561 unsigned int :5; /* Bits 3-7 */
3569 } Bits; 3562 } Bits;
3570} 3563}
@@ -3627,7 +3620,7 @@ void DAC960_LA_MemoryMailboxNewCommand(void __iomem *ControllerBaseAddress)
3627} 3620}
3628 3621
3629static inline 3622static inline
3630boolean DAC960_LA_HardwareMailboxFullP(void __iomem *ControllerBaseAddress) 3623bool DAC960_LA_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
3631{ 3624{
3632 DAC960_LA_InboundDoorBellRegister_T InboundDoorBellRegister; 3625 DAC960_LA_InboundDoorBellRegister_T InboundDoorBellRegister;
3633 InboundDoorBellRegister.All = 3626 InboundDoorBellRegister.All =
@@ -3636,7 +3629,7 @@ boolean DAC960_LA_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
3636} 3629}
3637 3630
3638static inline 3631static inline
3639boolean DAC960_LA_InitializationInProgressP(void __iomem *ControllerBaseAddress) 3632bool DAC960_LA_InitializationInProgressP(void __iomem *ControllerBaseAddress)
3640{ 3633{
3641 DAC960_LA_InboundDoorBellRegister_T InboundDoorBellRegister; 3634 DAC960_LA_InboundDoorBellRegister_T InboundDoorBellRegister;
3642 InboundDoorBellRegister.All = 3635 InboundDoorBellRegister.All =
@@ -3676,7 +3669,7 @@ void DAC960_LA_AcknowledgeInterrupt(void __iomem *ControllerBaseAddress)
3676} 3669}
3677 3670
3678static inline 3671static inline
3679boolean DAC960_LA_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 3672bool DAC960_LA_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
3680{ 3673{
3681 DAC960_LA_OutboundDoorBellRegister_T OutboundDoorBellRegister; 3674 DAC960_LA_OutboundDoorBellRegister_T OutboundDoorBellRegister;
3682 OutboundDoorBellRegister.All = 3675 OutboundDoorBellRegister.All =
@@ -3685,7 +3678,7 @@ boolean DAC960_LA_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAd
3685} 3678}
3686 3679
3687static inline 3680static inline
3688boolean DAC960_LA_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 3681bool DAC960_LA_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
3689{ 3682{
3690 DAC960_LA_OutboundDoorBellRegister_T OutboundDoorBellRegister; 3683 DAC960_LA_OutboundDoorBellRegister_T OutboundDoorBellRegister;
3691 OutboundDoorBellRegister.All = 3684 OutboundDoorBellRegister.All =
@@ -3714,7 +3707,7 @@ void DAC960_LA_DisableInterrupts(void __iomem *ControllerBaseAddress)
3714} 3707}
3715 3708
3716static inline 3709static inline
3717boolean DAC960_LA_InterruptsEnabledP(void __iomem *ControllerBaseAddress) 3710bool DAC960_LA_InterruptsEnabledP(void __iomem *ControllerBaseAddress)
3718{ 3711{
3719 DAC960_LA_InterruptMaskRegister_T InterruptMaskRegister; 3712 DAC960_LA_InterruptMaskRegister_T InterruptMaskRegister;
3720 InterruptMaskRegister.All = 3713 InterruptMaskRegister.All =
@@ -3763,7 +3756,7 @@ DAC960_LA_ReadStatusRegister(void __iomem *ControllerBaseAddress)
3763 return readw(ControllerBaseAddress + DAC960_LA_StatusRegisterOffset); 3756 return readw(ControllerBaseAddress + DAC960_LA_StatusRegisterOffset);
3764} 3757}
3765 3758
3766static inline boolean 3759static inline bool
3767DAC960_LA_ReadErrorStatus(void __iomem *ControllerBaseAddress, 3760DAC960_LA_ReadErrorStatus(void __iomem *ControllerBaseAddress,
3768 unsigned char *ErrorStatus, 3761 unsigned char *ErrorStatus,
3769 unsigned char *Parameter0, 3762 unsigned char *Parameter0,
@@ -3822,16 +3815,16 @@ typedef union DAC960_PG_InboundDoorBellRegister
3822{ 3815{
3823 unsigned int All; 3816 unsigned int All;
3824 struct { 3817 struct {
3825 boolean HardwareMailboxNewCommand:1; /* Bit 0 */ 3818 bool HardwareMailboxNewCommand:1; /* Bit 0 */
3826 boolean AcknowledgeHardwareMailboxStatus:1; /* Bit 1 */ 3819 bool AcknowledgeHardwareMailboxStatus:1; /* Bit 1 */
3827 boolean GenerateInterrupt:1; /* Bit 2 */ 3820 bool GenerateInterrupt:1; /* Bit 2 */
3828 boolean ControllerReset:1; /* Bit 3 */ 3821 bool ControllerReset:1; /* Bit 3 */
3829 boolean MemoryMailboxNewCommand:1; /* Bit 4 */ 3822 bool MemoryMailboxNewCommand:1; /* Bit 4 */
3830 unsigned int :27; /* Bits 5-31 */ 3823 unsigned int :27; /* Bits 5-31 */
3831 } Write; 3824 } Write;
3832 struct { 3825 struct {
3833 boolean HardwareMailboxFull:1; /* Bit 0 */ 3826 bool HardwareMailboxFull:1; /* Bit 0 */
3834 boolean InitializationInProgress:1; /* Bit 1 */ 3827 bool InitializationInProgress:1; /* Bit 1 */
3835 unsigned int :30; /* Bits 2-31 */ 3828 unsigned int :30; /* Bits 2-31 */
3836 } Read; 3829 } Read;
3837} 3830}
@@ -3846,13 +3839,13 @@ typedef union DAC960_PG_OutboundDoorBellRegister
3846{ 3839{
3847 unsigned int All; 3840 unsigned int All;
3848 struct { 3841 struct {
3849 boolean AcknowledgeHardwareMailboxInterrupt:1; /* Bit 0 */ 3842 bool AcknowledgeHardwareMailboxInterrupt:1; /* Bit 0 */
3850 boolean AcknowledgeMemoryMailboxInterrupt:1; /* Bit 1 */ 3843 bool AcknowledgeMemoryMailboxInterrupt:1; /* Bit 1 */
3851 unsigned int :30; /* Bits 2-31 */ 3844 unsigned int :30; /* Bits 2-31 */
3852 } Write; 3845 } Write;
3853 struct { 3846 struct {
3854 boolean HardwareMailboxStatusAvailable:1; /* Bit 0 */ 3847 bool HardwareMailboxStatusAvailable:1; /* Bit 0 */
3855 boolean MemoryMailboxStatusAvailable:1; /* Bit 1 */ 3848 bool MemoryMailboxStatusAvailable:1; /* Bit 1 */
3856 unsigned int :30; /* Bits 2-31 */ 3849 unsigned int :30; /* Bits 2-31 */
3857 } Read; 3850 } Read;
3858} 3851}
@@ -3868,7 +3861,7 @@ typedef union DAC960_PG_InterruptMaskRegister
3868 unsigned int All; 3861 unsigned int All;
3869 struct { 3862 struct {
3870 unsigned int MessageUnitInterruptMask1:2; /* Bits 0-1 */ 3863 unsigned int MessageUnitInterruptMask1:2; /* Bits 0-1 */
3871 boolean DisableInterrupts:1; /* Bit 2 */ 3864 bool DisableInterrupts:1; /* Bit 2 */
3872 unsigned int MessageUnitInterruptMask2:5; /* Bits 3-7 */ 3865 unsigned int MessageUnitInterruptMask2:5; /* Bits 3-7 */
3873 unsigned int Reserved0:24; /* Bits 8-31 */ 3866 unsigned int Reserved0:24; /* Bits 8-31 */
3874 } Bits; 3867 } Bits;
@@ -3885,7 +3878,7 @@ typedef union DAC960_PG_ErrorStatusRegister
3885 unsigned char All; 3878 unsigned char All;
3886 struct { 3879 struct {
3887 unsigned int :2; /* Bits 0-1 */ 3880 unsigned int :2; /* Bits 0-1 */
3888 boolean ErrorStatusPending:1; /* Bit 2 */ 3881 bool ErrorStatusPending:1; /* Bit 2 */
3889 unsigned int :5; /* Bits 3-7 */ 3882 unsigned int :5; /* Bits 3-7 */
3890 } Bits; 3883 } Bits;
3891} 3884}
@@ -3948,7 +3941,7 @@ void DAC960_PG_MemoryMailboxNewCommand(void __iomem *ControllerBaseAddress)
3948} 3941}
3949 3942
3950static inline 3943static inline
3951boolean DAC960_PG_HardwareMailboxFullP(void __iomem *ControllerBaseAddress) 3944bool DAC960_PG_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
3952{ 3945{
3953 DAC960_PG_InboundDoorBellRegister_T InboundDoorBellRegister; 3946 DAC960_PG_InboundDoorBellRegister_T InboundDoorBellRegister;
3954 InboundDoorBellRegister.All = 3947 InboundDoorBellRegister.All =
@@ -3957,7 +3950,7 @@ boolean DAC960_PG_HardwareMailboxFullP(void __iomem *ControllerBaseAddress)
3957} 3950}
3958 3951
3959static inline 3952static inline
3960boolean DAC960_PG_InitializationInProgressP(void __iomem *ControllerBaseAddress) 3953bool DAC960_PG_InitializationInProgressP(void __iomem *ControllerBaseAddress)
3961{ 3954{
3962 DAC960_PG_InboundDoorBellRegister_T InboundDoorBellRegister; 3955 DAC960_PG_InboundDoorBellRegister_T InboundDoorBellRegister;
3963 InboundDoorBellRegister.All = 3956 InboundDoorBellRegister.All =
@@ -3997,7 +3990,7 @@ void DAC960_PG_AcknowledgeInterrupt(void __iomem *ControllerBaseAddress)
3997} 3990}
3998 3991
3999static inline 3992static inline
4000boolean DAC960_PG_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 3993bool DAC960_PG_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
4001{ 3994{
4002 DAC960_PG_OutboundDoorBellRegister_T OutboundDoorBellRegister; 3995 DAC960_PG_OutboundDoorBellRegister_T OutboundDoorBellRegister;
4003 OutboundDoorBellRegister.All = 3996 OutboundDoorBellRegister.All =
@@ -4006,7 +3999,7 @@ boolean DAC960_PG_HardwareMailboxStatusAvailableP(void __iomem *ControllerBaseAd
4006} 3999}
4007 4000
4008static inline 4001static inline
4009boolean DAC960_PG_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress) 4002bool DAC960_PG_MemoryMailboxStatusAvailableP(void __iomem *ControllerBaseAddress)
4010{ 4003{
4011 DAC960_PG_OutboundDoorBellRegister_T OutboundDoorBellRegister; 4004 DAC960_PG_OutboundDoorBellRegister_T OutboundDoorBellRegister;
4012 OutboundDoorBellRegister.All = 4005 OutboundDoorBellRegister.All =
@@ -4039,7 +4032,7 @@ void DAC960_PG_DisableInterrupts(void __iomem *ControllerBaseAddress)
4039} 4032}
4040 4033
4041static inline 4034static inline
4042boolean DAC960_PG_InterruptsEnabledP(void __iomem *ControllerBaseAddress) 4035bool DAC960_PG_InterruptsEnabledP(void __iomem *ControllerBaseAddress)
4043{ 4036{
4044 DAC960_PG_InterruptMaskRegister_T InterruptMaskRegister; 4037 DAC960_PG_InterruptMaskRegister_T InterruptMaskRegister;
4045 InterruptMaskRegister.All = 4038 InterruptMaskRegister.All =
@@ -4088,7 +4081,7 @@ DAC960_PG_ReadStatusRegister(void __iomem *ControllerBaseAddress)
4088 return readw(ControllerBaseAddress + DAC960_PG_StatusRegisterOffset); 4081 return readw(ControllerBaseAddress + DAC960_PG_StatusRegisterOffset);
4089} 4082}
4090 4083
4091static inline boolean 4084static inline bool
4092DAC960_PG_ReadErrorStatus(void __iomem *ControllerBaseAddress, 4085DAC960_PG_ReadErrorStatus(void __iomem *ControllerBaseAddress,
4093 unsigned char *ErrorStatus, 4086 unsigned char *ErrorStatus,
4094 unsigned char *Parameter0, 4087 unsigned char *Parameter0,
@@ -4147,15 +4140,15 @@ typedef union DAC960_PD_InboundDoorBellRegister
4147{ 4140{
4148 unsigned char All; 4141 unsigned char All;
4149 struct { 4142 struct {
4150 boolean NewCommand:1; /* Bit 0 */ 4143 bool NewCommand:1; /* Bit 0 */
4151 boolean AcknowledgeStatus:1; /* Bit 1 */ 4144 bool AcknowledgeStatus:1; /* Bit 1 */
4152 boolean GenerateInterrupt:1; /* Bit 2 */ 4145 bool GenerateInterrupt:1; /* Bit 2 */
4153 boolean ControllerReset:1; /* Bit 3 */ 4146 bool ControllerReset:1; /* Bit 3 */
4154 unsigned char :4; /* Bits 4-7 */ 4147 unsigned char :4; /* Bits 4-7 */
4155 } Write; 4148 } Write;
4156 struct { 4149 struct {
4157 boolean MailboxFull:1; /* Bit 0 */ 4150 bool MailboxFull:1; /* Bit 0 */
4158 boolean InitializationInProgress:1; /* Bit 1 */ 4151 bool InitializationInProgress:1; /* Bit 1 */
4159 unsigned char :6; /* Bits 2-7 */ 4152 unsigned char :6; /* Bits 2-7 */
4160 } Read; 4153 } Read;
4161} 4154}
@@ -4170,11 +4163,11 @@ typedef union DAC960_PD_OutboundDoorBellRegister
4170{ 4163{
4171 unsigned char All; 4164 unsigned char All;
4172 struct { 4165 struct {
4173 boolean AcknowledgeInterrupt:1; /* Bit 0 */ 4166 bool AcknowledgeInterrupt:1; /* Bit 0 */
4174 unsigned char :7; /* Bits 1-7 */ 4167 unsigned char :7; /* Bits 1-7 */
4175 } Write; 4168 } Write;
4176 struct { 4169 struct {
4177 boolean StatusAvailable:1; /* Bit 0 */ 4170 bool StatusAvailable:1; /* Bit 0 */
4178 unsigned char :7; /* Bits 1-7 */ 4171 unsigned char :7; /* Bits 1-7 */
4179 } Read; 4172 } Read;
4180} 4173}
@@ -4189,7 +4182,7 @@ typedef union DAC960_PD_InterruptEnableRegister
4189{ 4182{
4190 unsigned char All; 4183 unsigned char All;
4191 struct { 4184 struct {
4192 boolean EnableInterrupts:1; /* Bit 0 */ 4185 bool EnableInterrupts:1; /* Bit 0 */
4193 unsigned char :7; /* Bits 1-7 */ 4186 unsigned char :7; /* Bits 1-7 */
4194 } Bits; 4187 } Bits;
4195} 4188}
@@ -4205,7 +4198,7 @@ typedef union DAC960_PD_ErrorStatusRegister
4205 unsigned char All; 4198 unsigned char All;
4206 struct { 4199 struct {
4207 unsigned int :2; /* Bits 0-1 */ 4200 unsigned int :2; /* Bits 0-1 */
4208 boolean ErrorStatusPending:1; /* Bit 2 */ 4201 bool ErrorStatusPending:1; /* Bit 2 */
4209 unsigned int :5; /* Bits 3-7 */ 4202 unsigned int :5; /* Bits 3-7 */
4210 } Bits; 4203 } Bits;
4211} 4204}
@@ -4258,7 +4251,7 @@ void DAC960_PD_ControllerReset(void __iomem *ControllerBaseAddress)
4258} 4251}
4259 4252
4260static inline 4253static inline
4261boolean DAC960_PD_MailboxFullP(void __iomem *ControllerBaseAddress) 4254bool DAC960_PD_MailboxFullP(void __iomem *ControllerBaseAddress)
4262{ 4255{
4263 DAC960_PD_InboundDoorBellRegister_T InboundDoorBellRegister; 4256 DAC960_PD_InboundDoorBellRegister_T InboundDoorBellRegister;
4264 InboundDoorBellRegister.All = 4257 InboundDoorBellRegister.All =
@@ -4267,7 +4260,7 @@ boolean DAC960_PD_MailboxFullP(void __iomem *ControllerBaseAddress)
4267} 4260}
4268 4261
4269static inline 4262static inline
4270boolean DAC960_PD_InitializationInProgressP(void __iomem *ControllerBaseAddress) 4263bool DAC960_PD_InitializationInProgressP(void __iomem *ControllerBaseAddress)
4271{ 4264{
4272 DAC960_PD_InboundDoorBellRegister_T InboundDoorBellRegister; 4265 DAC960_PD_InboundDoorBellRegister_T InboundDoorBellRegister;
4273 InboundDoorBellRegister.All = 4266 InboundDoorBellRegister.All =
@@ -4286,7 +4279,7 @@ void DAC960_PD_AcknowledgeInterrupt(void __iomem *ControllerBaseAddress)
4286} 4279}
4287 4280
4288static inline 4281static inline
4289boolean DAC960_PD_StatusAvailableP(void __iomem *ControllerBaseAddress) 4282bool DAC960_PD_StatusAvailableP(void __iomem *ControllerBaseAddress)
4290{ 4283{
4291 DAC960_PD_OutboundDoorBellRegister_T OutboundDoorBellRegister; 4284 DAC960_PD_OutboundDoorBellRegister_T OutboundDoorBellRegister;
4292 OutboundDoorBellRegister.All = 4285 OutboundDoorBellRegister.All =
@@ -4315,7 +4308,7 @@ void DAC960_PD_DisableInterrupts(void __iomem *ControllerBaseAddress)
4315} 4308}
4316 4309
4317static inline 4310static inline
4318boolean DAC960_PD_InterruptsEnabledP(void __iomem *ControllerBaseAddress) 4311bool DAC960_PD_InterruptsEnabledP(void __iomem *ControllerBaseAddress)
4319{ 4312{
4320 DAC960_PD_InterruptEnableRegister_T InterruptEnableRegister; 4313 DAC960_PD_InterruptEnableRegister_T InterruptEnableRegister;
4321 InterruptEnableRegister.All = 4314 InterruptEnableRegister.All =
@@ -4350,7 +4343,7 @@ DAC960_PD_ReadStatusRegister(void __iomem *ControllerBaseAddress)
4350 return readw(ControllerBaseAddress + DAC960_PD_StatusRegisterOffset); 4343 return readw(ControllerBaseAddress + DAC960_PD_StatusRegisterOffset);
4351} 4344}
4352 4345
4353static inline boolean 4346static inline bool
4354DAC960_PD_ReadErrorStatus(void __iomem *ControllerBaseAddress, 4347DAC960_PD_ReadErrorStatus(void __iomem *ControllerBaseAddress,
4355 unsigned char *ErrorStatus, 4348 unsigned char *ErrorStatus,
4356 unsigned char *Parameter0, 4349 unsigned char *Parameter0,
diff --git a/drivers/block/Kconfig b/drivers/block/Kconfig
index 58c1debf86f..cacb1c816e3 100644
--- a/drivers/block/Kconfig
+++ b/drivers/block/Kconfig
@@ -417,8 +417,10 @@ config BLK_DEV_INITRD
417 etc. See <file:Documentation/initrd.txt> for details. 417 etc. See <file:Documentation/initrd.txt> for details.
418 418
419 If RAM disk support (BLK_DEV_RAM) is also included, this 419 If RAM disk support (BLK_DEV_RAM) is also included, this
420 also enables initial RAM disk (initrd) support. 420 also enables initial RAM disk (initrd) support and adds
421 15 Kbytes (more on some other architectures) to the kernel size.
421 422
423 If unsure say Y.
422 424
423config CDROM_PKTCDVD 425config CDROM_PKTCDVD
424 tristate "Packet writing on CD/DVD media" 426 tristate "Packet writing on CD/DVD media"
diff --git a/drivers/block/acsi_slm.c b/drivers/block/acsi_slm.c
index e04be94d195..e2e04329096 100644
--- a/drivers/block/acsi_slm.c
+++ b/drivers/block/acsi_slm.c
@@ -269,7 +269,7 @@ static int slm_get_pagesize( int device, int *w, int *h );
269 269
270static DEFINE_TIMER(slm_timer, slm_test_ready, 0, 0); 270static DEFINE_TIMER(slm_timer, slm_test_ready, 0, 0);
271 271
272static struct file_operations slm_fops = { 272static const struct file_operations slm_fops = {
273 .owner = THIS_MODULE, 273 .owner = THIS_MODULE,
274 .read = slm_read, 274 .read = slm_read,
275 .write = slm_write, 275 .write = slm_write,
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index e22b4c9520a..39e563ea087 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -233,7 +233,7 @@ loop:
233 } 233 }
234} 234}
235 235
236static struct file_operations aoe_fops = { 236static const struct file_operations aoe_fops = {
237 .write = aoechr_write, 237 .write = aoechr_write,
238 .read = aoechr_read, 238 .read = aoechr_read,
239 .open = aoechr_open, 239 .open = aoechr_open,
diff --git a/drivers/block/paride/Kconfig b/drivers/block/paride/Kconfig
index c0d2854dd09..28cf3082d44 100644
--- a/drivers/block/paride/Kconfig
+++ b/drivers/block/paride/Kconfig
@@ -2,14 +2,8 @@
2# PARIDE configuration 2# PARIDE configuration
3# 3#
4# PARIDE doesn't need PARPORT, but if PARPORT is configured as a module, 4# PARIDE doesn't need PARPORT, but if PARPORT is configured as a module,
5# PARIDE must also be a module. The bogus CONFIG_PARIDE_PARPORT option 5# PARIDE must also be a module.
6# controls the choices given to the user ...
7# PARIDE only supports PC style parports. Tough for USB or other parports... 6# PARIDE only supports PC style parports. Tough for USB or other parports...
8config PARIDE_PARPORT
9 tristate
10 depends on PARIDE!=n
11 default m if PARPORT_PC=m
12 default y if PARPORT_PC!=m
13 7
14comment "Parallel IDE high-level drivers" 8comment "Parallel IDE high-level drivers"
15 depends on PARIDE 9 depends on PARIDE
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index 9970aedbb5d..d89e7d32a3b 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -227,7 +227,7 @@ static struct class *pg_class;
227 227
228/* kernel glue structures */ 228/* kernel glue structures */
229 229
230static struct file_operations pg_fops = { 230static const struct file_operations pg_fops = {
231 .owner = THIS_MODULE, 231 .owner = THIS_MODULE,
232 .read = pg_read, 232 .read = pg_read,
233 .write = pg_write, 233 .write = pg_write,
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index c902b25e486..9f4e67ee1eb 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -232,7 +232,7 @@ static char pt_scratch[512]; /* scratch block buffer */
232 232
233/* kernel glue structures */ 233/* kernel glue structures */
234 234
235static struct file_operations pt_fops = { 235static const struct file_operations pt_fops = {
236 .owner = THIS_MODULE, 236 .owner = THIS_MODULE,
237 .read = pt_read, 237 .read = pt_read,
238 .write = pt_write, 238 .write = pt_write,
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 62462190e07..93fb6ed4ed5 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -190,15 +190,6 @@ static struct attribute *kobj_pkt_attrs_wqueue[] = {
190 NULL 190 NULL
191}; 191};
192 192
193/* declares a char buffer[64] _dbuf, copies data from
194 * _b with length _l into it and ensures that _dbuf ends
195 * with a \0 character.
196 */
197#define DECLARE_BUF_AS_STRING(_dbuf, _b, _l) \
198 char _dbuf[64]; int dlen = (_l) < 0 ? 0 : (_l); \
199 if (dlen >= sizeof(_dbuf)) dlen = sizeof(_dbuf)-1; \
200 memcpy(_dbuf, _b, dlen); _dbuf[dlen] = 0
201
202static ssize_t kobj_pkt_show(struct kobject *kobj, 193static ssize_t kobj_pkt_show(struct kobject *kobj,
203 struct attribute *attr, char *data) 194 struct attribute *attr, char *data)
204{ 195{
@@ -264,9 +255,8 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
264{ 255{
265 struct pktcdvd_device *pd = to_pktcdvdkobj(kobj)->pd; 256 struct pktcdvd_device *pd = to_pktcdvdkobj(kobj)->pd;
266 int val; 257 int val;
267 DECLARE_BUF_AS_STRING(dbuf, data, len); /* ensure sscanf scans a string */
268 258
269 if (strcmp(attr->name, "reset") == 0 && dlen > 0) { 259 if (strcmp(attr->name, "reset") == 0 && len > 0) {
270 pd->stats.pkt_started = 0; 260 pd->stats.pkt_started = 0;
271 pd->stats.pkt_ended = 0; 261 pd->stats.pkt_ended = 0;
272 pd->stats.secs_w = 0; 262 pd->stats.secs_w = 0;
@@ -274,7 +264,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
274 pd->stats.secs_r = 0; 264 pd->stats.secs_r = 0;
275 265
276 } else if (strcmp(attr->name, "congestion_off") == 0 266 } else if (strcmp(attr->name, "congestion_off") == 0
277 && sscanf(dbuf, "%d", &val) == 1) { 267 && sscanf(data, "%d", &val) == 1) {
278 spin_lock(&pd->lock); 268 spin_lock(&pd->lock);
279 pd->write_congestion_off = val; 269 pd->write_congestion_off = val;
280 init_write_congestion_marks(&pd->write_congestion_off, 270 init_write_congestion_marks(&pd->write_congestion_off,
@@ -282,7 +272,7 @@ static ssize_t kobj_pkt_store(struct kobject *kobj,
282 spin_unlock(&pd->lock); 272 spin_unlock(&pd->lock);
283 273
284 } else if (strcmp(attr->name, "congestion_on") == 0 274 } else if (strcmp(attr->name, "congestion_on") == 0
285 && sscanf(dbuf, "%d", &val) == 1) { 275 && sscanf(data, "%d", &val) == 1) {
286 spin_lock(&pd->lock); 276 spin_lock(&pd->lock);
287 pd->write_congestion_on = val; 277 pd->write_congestion_on = val;
288 init_write_congestion_marks(&pd->write_congestion_off, 278 init_write_congestion_marks(&pd->write_congestion_off,
@@ -369,8 +359,7 @@ static ssize_t class_pktcdvd_store_add(struct class *c, const char *buf,
369 size_t count) 359 size_t count)
370{ 360{
371 unsigned int major, minor; 361 unsigned int major, minor;
372 DECLARE_BUF_AS_STRING(dbuf, buf, count); 362 if (sscanf(buf, "%u:%u", &major, &minor) == 2) {
373 if (sscanf(dbuf, "%u:%u", &major, &minor) == 2) {
374 pkt_setup_dev(MKDEV(major, minor), NULL); 363 pkt_setup_dev(MKDEV(major, minor), NULL);
375 return count; 364 return count;
376 } 365 }
@@ -381,8 +370,7 @@ static ssize_t class_pktcdvd_store_remove(struct class *c, const char *buf,
381 size_t count) 370 size_t count)
382{ 371{
383 unsigned int major, minor; 372 unsigned int major, minor;
384 DECLARE_BUF_AS_STRING(dbuf, buf, count); 373 if (sscanf(buf, "%u:%u", &major, &minor) == 2) {
385 if (sscanf(dbuf, "%u:%u", &major, &minor) == 2) {
386 pkt_remove_dev(MKDEV(major, minor)); 374 pkt_remove_dev(MKDEV(major, minor));
387 return count; 375 return count;
388 } 376 }
@@ -447,7 +435,7 @@ static int pkt_debugfs_fops_open(struct inode *inode, struct file *file)
447 return single_open(file, pkt_debugfs_seq_show, inode->i_private); 435 return single_open(file, pkt_debugfs_seq_show, inode->i_private);
448} 436}
449 437
450static struct file_operations debug_fops = { 438static const struct file_operations debug_fops = {
451 .open = pkt_debugfs_fops_open, 439 .open = pkt_debugfs_fops_open,
452 .read = seq_read, 440 .read = seq_read,
453 .llseek = seq_lseek, 441 .llseek = seq_lseek,
@@ -1377,7 +1365,7 @@ try_next_bio:
1377 && pd->bio_queue_size <= pd->write_congestion_off); 1365 && pd->bio_queue_size <= pd->write_congestion_off);
1378 spin_unlock(&pd->lock); 1366 spin_unlock(&pd->lock);
1379 if (wakeup) 1367 if (wakeup)
1380 blk_clear_queue_congested(pd->disk->queue, WRITE); 1368 clear_bdi_congested(&pd->disk->queue->backing_dev_info, WRITE);
1381 1369
1382 pkt->sleep_time = max(PACKET_WAIT_TIME, 1); 1370 pkt->sleep_time = max(PACKET_WAIT_TIME, 1);
1383 pkt_set_state(pkt, PACKET_WAITING_STATE); 1371 pkt_set_state(pkt, PACKET_WAITING_STATE);
@@ -2598,7 +2586,7 @@ static int pkt_make_request(request_queue_t *q, struct bio *bio)
2598 spin_lock(&pd->lock); 2586 spin_lock(&pd->lock);
2599 if (pd->write_congestion_on > 0 2587 if (pd->write_congestion_on > 0
2600 && pd->bio_queue_size >= pd->write_congestion_on) { 2588 && pd->bio_queue_size >= pd->write_congestion_on) {
2601 blk_set_queue_congested(q, WRITE); 2589 set_bdi_congested(&q->backing_dev_info, WRITE);
2602 do { 2590 do {
2603 spin_unlock(&pd->lock); 2591 spin_unlock(&pd->lock);
2604 congestion_wait(WRITE, HZ); 2592 congestion_wait(WRITE, HZ);
@@ -2737,7 +2725,7 @@ static int pkt_seq_open(struct inode *inode, struct file *file)
2737 return single_open(file, pkt_seq_show, PDE(inode)->data); 2725 return single_open(file, pkt_seq_show, PDE(inode)->data);
2738} 2726}
2739 2727
2740static struct file_operations pkt_proc_fops = { 2728static const struct file_operations pkt_proc_fops = {
2741 .open = pkt_seq_open, 2729 .open = pkt_seq_open,
2742 .read = seq_read, 2730 .read = seq_read,
2743 .llseek = seq_lseek, 2731 .llseek = seq_lseek,
@@ -3064,7 +3052,7 @@ static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cm
3064} 3052}
3065 3053
3066 3054
3067static struct file_operations pkt_ctl_fops = { 3055static const struct file_operations pkt_ctl_fops = {
3068 .ioctl = pkt_ctl_ioctl, 3056 .ioctl = pkt_ctl_ioctl,
3069 .owner = THIS_MODULE, 3057 .owner = THIS_MODULE,
3070}; 3058};
diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index a278d98a915..b71a5ccc587 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -332,7 +332,7 @@ static int vhci_fasync(int fd, struct file *file, int on)
332 return 0; 332 return 0;
333} 333}
334 334
335static struct file_operations vhci_fops = { 335static const struct file_operations vhci_fops = {
336 .owner = THIS_MODULE, 336 .owner = THIS_MODULE,
337 .llseek = vhci_llseek, 337 .llseek = vhci_llseek,
338 .read = vhci_read, 338 .read = vhci_read,
diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c
index 93fbf84dcc4..dc13ebacedf 100644
--- a/drivers/cdrom/viocd.c
+++ b/drivers/cdrom/viocd.c
@@ -176,7 +176,7 @@ static int proc_viocd_open(struct inode *inode, struct file *file)
176 return single_open(file, proc_viocd_show, NULL); 176 return single_open(file, proc_viocd_show, NULL);
177} 177}
178 178
179static struct file_operations proc_viocd_operations = { 179static const struct file_operations proc_viocd_operations = {
180 .open = proc_viocd_open, 180 .open = proc_viocd_open,
181 .read = seq_read, 181 .read = seq_read,
182 .llseek = seq_lseek, 182 .llseek = seq_lseek,
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index d08bb4ee130..d0a6dc53213 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -191,7 +191,7 @@ config MOXA_INTELLIO
191 module will be called moxa. 191 module will be called moxa.
192 192
193config MOXA_SMARTIO 193config MOXA_SMARTIO
194 tristate "Moxa SmartIO support" 194 tristate "Moxa SmartIO support (OBSOLETE)"
195 depends on SERIAL_NONSTANDARD 195 depends on SERIAL_NONSTANDARD
196 help 196 help
197 Say Y here if you have a Moxa SmartIO multiport serial card. 197 Say Y here if you have a Moxa SmartIO multiport serial card.
@@ -202,7 +202,7 @@ config MOXA_SMARTIO
202 here. 202 here.
203 203
204config MOXA_SMARTIO_NEW 204config MOXA_SMARTIO_NEW
205 tristate "Moxa SmartIO support v. 2.0 (EXPERIMENTAL)" 205 tristate "Moxa SmartIO support v. 2.0"
206 depends on SERIAL_NONSTANDARD && (PCI || EISA || ISA) 206 depends on SERIAL_NONSTANDARD && (PCI || EISA || ISA)
207 help 207 help
208 Say Y here if you have a Moxa SmartIO multiport serial card and/or 208 Say Y here if you have a Moxa SmartIO multiport serial card and/or
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index feb4ac802a0..0e2b72f2b88 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -527,10 +527,8 @@ static void do_softint(unsigned long private_)
527 if (!tty) 527 if (!tty)
528 return; 528 return;
529 529
530 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) { 530 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
531 tty_wakeup(tty); 531 tty_wakeup(tty);
532 wake_up_interruptible(&tty->write_wait);
533 }
534} 532}
535 533
536/* 534/*
@@ -904,8 +902,7 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
904 if (!info->xmit.buf) 902 if (!info->xmit.buf)
905 return 0; 903 return 0;
906 904
907 local_save_flags(flags); 905 local_irq_save(flags);
908 local_irq_disable();
909 while (1) { 906 while (1) {
910 c = CIRC_SPACE_TO_END(info->xmit.head, 907 c = CIRC_SPACE_TO_END(info->xmit.head,
911 info->xmit.tail, 908 info->xmit.tail,
@@ -968,7 +965,6 @@ static void rs_flush_buffer(struct tty_struct *tty)
968 local_irq_save(flags); 965 local_irq_save(flags);
969 info->xmit.head = info->xmit.tail = 0; 966 info->xmit.head = info->xmit.tail = 0;
970 local_irq_restore(flags); 967 local_irq_restore(flags);
971 wake_up_interruptible(&tty->write_wait);
972 tty_wakeup(tty); 968 tty_wakeup(tty);
973} 969}
974 970
diff --git a/drivers/char/briq_panel.c b/drivers/char/briq_panel.c
index 9f8082f8dd2..7f60a18ef76 100644
--- a/drivers/char/briq_panel.c
+++ b/drivers/char/briq_panel.c
@@ -187,7 +187,7 @@ static ssize_t briq_panel_write(struct file *file, const char __user *buf, size_
187 return len; 187 return len;
188} 188}
189 189
190static struct file_operations briq_panel_fops = { 190static const struct file_operations briq_panel_fops = {
191 .owner = THIS_MODULE, 191 .owner = THIS_MODULE,
192 .read = briq_panel_read, 192 .read = briq_panel_read,
193 .write = briq_panel_write, 193 .write = briq_panel_write,
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index 3ffa0807754..54df35527bc 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -829,17 +829,18 @@ static unsigned short cy_pci_nboard;
829static unsigned short cy_isa_nboard; 829static unsigned short cy_isa_nboard;
830static unsigned short cy_nboard; 830static unsigned short cy_nboard;
831#ifdef CONFIG_PCI 831#ifdef CONFIG_PCI
832static unsigned short cy_pci_dev_id[] = { 832static struct pci_device_id cy_pci_dev_id[] __devinitdata = {
833 PCI_DEVICE_ID_CYCLOM_Y_Lo, /* PCI < 1Mb */ 833 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Lo) }, /* PCI < 1Mb */
834 PCI_DEVICE_ID_CYCLOM_Y_Hi, /* PCI > 1Mb */ 834 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Hi) }, /* PCI > 1Mb */
835 PCI_DEVICE_ID_CYCLOM_4Y_Lo, /* 4Y PCI < 1Mb */ 835 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_4Y_Lo) }, /* 4Y PCI < 1Mb */
836 PCI_DEVICE_ID_CYCLOM_4Y_Hi, /* 4Y PCI > 1Mb */ 836 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_4Y_Hi) }, /* 4Y PCI > 1Mb */
837 PCI_DEVICE_ID_CYCLOM_8Y_Lo, /* 8Y PCI < 1Mb */ 837 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_8Y_Lo) }, /* 8Y PCI < 1Mb */
838 PCI_DEVICE_ID_CYCLOM_8Y_Hi, /* 8Y PCI > 1Mb */ 838 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_8Y_Hi) }, /* 8Y PCI > 1Mb */
839 PCI_DEVICE_ID_CYCLOM_Z_Lo, /* Z PCI < 1Mb */ 839 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Z_Lo) }, /* Z PCI < 1Mb */
840 PCI_DEVICE_ID_CYCLOM_Z_Hi, /* Z PCI > 1Mb */ 840 { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Z_Hi) }, /* Z PCI > 1Mb */
841 0 /* end of table */ 841 { } /* end of table */
842}; 842};
843MODULE_DEVICE_TABLE(pci, cy_pci_dev_id);
843#endif 844#endif
844 845
845static void cy_start(struct tty_struct *); 846static void cy_start(struct tty_struct *);
@@ -4488,7 +4489,6 @@ static void cy_flush_buffer(struct tty_struct *tty)
4488 CY_UNLOCK(info, flags); 4489 CY_UNLOCK(info, flags);
4489 } 4490 }
4490 tty_wakeup(tty); 4491 tty_wakeup(tty);
4491 wake_up_interruptible(&tty->write_wait);
4492} /* cy_flush_buffer */ 4492} /* cy_flush_buffer */
4493 4493
4494/* 4494/*
@@ -4759,7 +4759,7 @@ static int __init cy_detect_pci(void)
4759 4759
4760 for (i = 0; i < NR_CARDS; i++) { 4760 for (i = 0; i < NR_CARDS; i++) {
4761 /* look for a Cyclades card by vendor and device id */ 4761 /* look for a Cyclades card by vendor and device id */
4762 while ((device_id = cy_pci_dev_id[dev_index]) != 0) { 4762 while ((device_id = cy_pci_dev_id[dev_index].device) != 0) {
4763 if ((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES, 4763 if ((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES,
4764 device_id, pdev)) == NULL) { 4764 device_id, pdev)) == NULL) {
4765 dev_index++; /* try next device id */ 4765 dev_index++; /* try next device id */
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c
index a70af0de445..f5b9b2480c1 100644
--- a/drivers/char/drm/drm_drv.c
+++ b/drivers/char/drm/drm_drv.c
@@ -371,7 +371,7 @@ void drm_exit(struct drm_driver *driver)
371EXPORT_SYMBOL(drm_exit); 371EXPORT_SYMBOL(drm_exit);
372 372
373/** File operations structure */ 373/** File operations structure */
374static struct file_operations drm_stub_fops = { 374static const struct file_operations drm_stub_fops = {
375 .owner = THIS_MODULE, 375 .owner = THIS_MODULE,
376 .open = drm_stub_open 376 .open = drm_stub_open
377}; 377};
diff --git a/drivers/char/drm/i810_dma.c b/drivers/char/drm/i810_dma.c
index 60cb4e45a75..603d17fd2d6 100644
--- a/drivers/char/drm/i810_dma.c
+++ b/drivers/char/drm/i810_dma.c
@@ -112,7 +112,7 @@ static int i810_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
112 return 0; 112 return 0;
113} 113}
114 114
115static struct file_operations i810_buffer_fops = { 115static const struct file_operations i810_buffer_fops = {
116 .open = drm_open, 116 .open = drm_open,
117 .release = drm_release, 117 .release = drm_release,
118 .ioctl = drm_ioctl, 118 .ioctl = drm_ioctl,
diff --git a/drivers/char/drm/i830_dma.c b/drivers/char/drm/i830_dma.c
index 95224455ec0..3314a9fea9e 100644
--- a/drivers/char/drm/i830_dma.c
+++ b/drivers/char/drm/i830_dma.c
@@ -114,7 +114,7 @@ static int i830_mmap_buffers(struct file *filp, struct vm_area_struct *vma)
114 return 0; 114 return 0;
115} 115}
116 116
117static struct file_operations i830_buffer_fops = { 117static const struct file_operations i830_buffer_fops = {
118 .open = drm_open, 118 .open = drm_open,
119 .release = drm_release, 119 .release = drm_release,
120 .ioctl = drm_ioctl, 120 .ioctl = drm_ioctl,
diff --git a/drivers/char/drm/via_dmablit.c b/drivers/char/drm/via_dmablit.c
index 2054d577371..2881a06b6f5 100644
--- a/drivers/char/drm/via_dmablit.c
+++ b/drivers/char/drm/via_dmablit.c
@@ -376,10 +376,8 @@ via_dmablit_handler(drm_device_t *dev, int engine, int from_irq)
376 blitq->cur = cur; 376 blitq->cur = cur;
377 blitq->num_outstanding--; 377 blitq->num_outstanding--;
378 blitq->end = jiffies + DRM_HZ; 378 blitq->end = jiffies + DRM_HZ;
379 if (!timer_pending(&blitq->poll_timer)) { 379 if (!timer_pending(&blitq->poll_timer))
380 blitq->poll_timer.expires = jiffies+1; 380 mod_timer(&blitq->poll_timer, jiffies + 1);
381 add_timer(&blitq->poll_timer);
382 }
383 } else { 381 } else {
384 if (timer_pending(&blitq->poll_timer)) { 382 if (timer_pending(&blitq->poll_timer)) {
385 del_timer(&blitq->poll_timer); 383 del_timer(&blitq->poll_timer);
@@ -478,8 +476,7 @@ via_dmablit_timer(unsigned long data)
478 via_dmablit_handler(dev, engine, 0); 476 via_dmablit_handler(dev, engine, 0);
479 477
480 if (!timer_pending(&blitq->poll_timer)) { 478 if (!timer_pending(&blitq->poll_timer)) {
481 blitq->poll_timer.expires = jiffies+1; 479 mod_timer(&blitq->poll_timer, jiffies + 1);
482 add_timer(&blitq->poll_timer);
483 480
484 /* 481 /*
485 * Rerun handler to delete timer if engines are off, and 482 * Rerun handler to delete timer if engines are off, and
@@ -574,9 +571,8 @@ via_init_dmablit(drm_device_t *dev)
574 } 571 }
575 DRM_INIT_WAITQUEUE(&blitq->busy_queue); 572 DRM_INIT_WAITQUEUE(&blitq->busy_queue);
576 INIT_WORK(&blitq->wq, via_dmablit_workqueue); 573 INIT_WORK(&blitq->wq, via_dmablit_workqueue);
577 init_timer(&blitq->poll_timer); 574 setup_timer(&blitq->poll_timer, via_dmablit_timer,
578 blitq->poll_timer.function = &via_dmablit_timer; 575 (unsigned long)blitq);
579 blitq->poll_timer.data = (unsigned long) blitq;
580 } 576 }
581} 577}
582 578
diff --git a/drivers/char/ds1302.c b/drivers/char/ds1302.c
index bcdb107aa96..fada6ddefba 100644
--- a/drivers/char/ds1302.c
+++ b/drivers/char/ds1302.c
@@ -120,7 +120,6 @@ get_rtc_time(struct rtc_time *rtc_tm)
120 unsigned long flags; 120 unsigned long flags;
121 121
122 local_irq_save(flags); 122 local_irq_save(flags);
123 local_irq_disable();
124 123
125 rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS); 124 rtc_tm->tm_sec = CMOS_READ(RTC_SECONDS);
126 rtc_tm->tm_min = CMOS_READ(RTC_MINUTES); 125 rtc_tm->tm_min = CMOS_READ(RTC_MINUTES);
@@ -219,7 +218,6 @@ rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
219 BIN_TO_BCD(yrs); 218 BIN_TO_BCD(yrs);
220 219
221 local_irq_save(flags); 220 local_irq_save(flags);
222 local_irq_disable();
223 CMOS_WRITE(yrs, RTC_YEAR); 221 CMOS_WRITE(yrs, RTC_YEAR);
224 CMOS_WRITE(mon, RTC_MONTH); 222 CMOS_WRITE(mon, RTC_MONTH);
225 CMOS_WRITE(day, RTC_DAY_OF_MONTH); 223 CMOS_WRITE(day, RTC_DAY_OF_MONTH);
diff --git a/drivers/char/dtlk.c b/drivers/char/dtlk.c
index d4005e94fe5..d8dbdb91623 100644
--- a/drivers/char/dtlk.c
+++ b/drivers/char/dtlk.c
@@ -72,6 +72,7 @@
72#define TRACE_RET ((void) 0) 72#define TRACE_RET ((void) 0)
73#endif /* TRACING */ 73#endif /* TRACING */
74 74
75static void dtlk_timer_tick(unsigned long data);
75 76
76static int dtlk_major; 77static int dtlk_major;
77static int dtlk_port_lpc; 78static int dtlk_port_lpc;
@@ -81,7 +82,7 @@ static int dtlk_has_indexing;
81static unsigned int dtlk_portlist[] = 82static unsigned int dtlk_portlist[] =
82{0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0}; 83{0x25e, 0x29e, 0x2de, 0x31e, 0x35e, 0x39e, 0};
83static wait_queue_head_t dtlk_process_list; 84static wait_queue_head_t dtlk_process_list;
84static struct timer_list dtlk_timer; 85static DEFINE_TIMER(dtlk_timer, dtlk_timer_tick, 0, 0);
85 86
86/* prototypes for file_operations struct */ 87/* prototypes for file_operations struct */
87static ssize_t dtlk_read(struct file *, char __user *, 88static ssize_t dtlk_read(struct file *, char __user *,
@@ -117,7 +118,6 @@ static char dtlk_write_tts(char);
117/* 118/*
118 static void dtlk_handle_error(char, char, unsigned int); 119 static void dtlk_handle_error(char, char, unsigned int);
119 */ 120 */
120static void dtlk_timer_tick(unsigned long data);
121 121
122static ssize_t dtlk_read(struct file *file, char __user *buf, 122static ssize_t dtlk_read(struct file *file, char __user *buf,
123 size_t count, loff_t * ppos) 123 size_t count, loff_t * ppos)
@@ -318,7 +318,7 @@ static int dtlk_release(struct inode *inode, struct file *file)
318 } 318 }
319 TRACE_RET; 319 TRACE_RET;
320 320
321 del_timer(&dtlk_timer); 321 del_timer_sync(&dtlk_timer);
322 322
323 return 0; 323 return 0;
324} 324}
@@ -336,8 +336,6 @@ static int __init dtlk_init(void)
336 if (dtlk_dev_probe() == 0) 336 if (dtlk_dev_probe() == 0)
337 printk(", MAJOR %d\n", dtlk_major); 337 printk(", MAJOR %d\n", dtlk_major);
338 338
339 init_timer(&dtlk_timer);
340 dtlk_timer.function = dtlk_timer_tick;
341 init_waitqueue_head(&dtlk_process_list); 339 init_waitqueue_head(&dtlk_process_list);
342 340
343 return 0; 341 return 0;
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index a0f822c9d74..88fc24fc439 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -844,7 +844,6 @@ static void pc_flush_buffer(struct tty_struct *tty)
844 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0); 844 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
845 memoff(ch); 845 memoff(ch);
846 spin_unlock_irqrestore(&epca_lock, flags); 846 spin_unlock_irqrestore(&epca_lock, flags);
847 wake_up_interruptible(&tty->write_wait);
848 tty_wakeup(tty); 847 tty_wakeup(tty);
849} /* End pc_flush_buffer */ 848} /* End pc_flush_buffer */
850 849
@@ -1795,7 +1794,6 @@ static void doevent(int crd)
1795 { /* Begin if LOWWAIT */ 1794 { /* Begin if LOWWAIT */
1796 ch->statusflags &= ~LOWWAIT; 1795 ch->statusflags &= ~LOWWAIT;
1797 tty_wakeup(tty); 1796 tty_wakeup(tty);
1798 wake_up_interruptible(&tty->write_wait);
1799 } /* End if LOWWAIT */ 1797 } /* End if LOWWAIT */
1800 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */ 1798 } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
1801 /* This event is generated by setup_empty_event */ 1799 /* This event is generated by setup_empty_event */
@@ -1803,7 +1801,6 @@ static void doevent(int crd)
1803 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */ 1801 if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
1804 ch->statusflags &= ~EMPTYWAIT; 1802 ch->statusflags &= ~EMPTYWAIT;
1805 tty_wakeup(tty); 1803 tty_wakeup(tty);
1806 wake_up_interruptible(&tty->write_wait);
1807 } /* End if EMPTYWAIT */ 1804 } /* End if EMPTYWAIT */
1808 } /* End EMPTYTX_IND */ 1805 } /* End EMPTYTX_IND */
1809 } /* End if valid tty */ 1806 } /* End if valid tty */
diff --git a/drivers/char/generic_nvram.c b/drivers/char/generic_nvram.c
index 43ff5981651..2398e864c28 100644
--- a/drivers/char/generic_nvram.c
+++ b/drivers/char/generic_nvram.c
@@ -117,7 +117,7 @@ static int nvram_ioctl(struct inode *inode, struct file *file,
117 return 0; 117 return 0;
118} 118}
119 119
120struct file_operations nvram_fops = { 120const struct file_operations nvram_fops = {
121 .owner = THIS_MODULE, 121 .owner = THIS_MODULE,
122 .llseek = nvram_llseek, 122 .llseek = nvram_llseek,
123 .read = read_nvram, 123 .read = read_nvram,
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index e769811e741..337bbcdcf13 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -382,7 +382,6 @@ void gs_flush_buffer(struct tty_struct *tty)
382 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 382 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
383 spin_unlock_irqrestore (&port->driver_lock, flags); 383 spin_unlock_irqrestore (&port->driver_lock, flags);
384 384
385 wake_up_interruptible(&tty->write_wait);
386 tty_wakeup(tty); 385 tty_wakeup(tty);
387 func_exit (); 386 func_exit ();
388} 387}
diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
index f22e78e3c70..cc1046e6ee0 100644
--- a/drivers/char/hw_random/intel-rng.c
+++ b/drivers/char/hw_random/intel-rng.c
@@ -96,49 +96,49 @@
96 */ 96 */
97static const struct pci_device_id pci_tbl[] = { 97static const struct pci_device_id pci_tbl[] = {
98/* AA 98/* AA
99 { 0x8086, 0x2418, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */ 99 { PCI_DEVICE(0x8086, 0x2418) }, */
100 { 0x8086, 0x2410, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AA */ 100 { PCI_DEVICE(0x8086, 0x2410) }, /* AA */
101/* AB 101/* AB
102 { 0x8086, 0x2428, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */ 102 { PCI_DEVICE(0x8086, 0x2428) }, */
103 { 0x8086, 0x2420, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* AB */ 103 { PCI_DEVICE(0x8086, 0x2420) }, /* AB */
104/* ?? 104/* ??
105 { 0x8086, 0x2430, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */ 105 { PCI_DEVICE(0x8086, 0x2430) }, */
106/* BAM, CAM, DBM, FBM, GxM 106/* BAM, CAM, DBM, FBM, GxM
107 { 0x8086, 0x2448, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */ 107 { PCI_DEVICE(0x8086, 0x2448) }, */
108 { 0x8086, 0x244c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BAM */ 108 { PCI_DEVICE(0x8086, 0x244c) }, /* BAM */
109 { 0x8086, 0x248c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CAM */ 109 { PCI_DEVICE(0x8086, 0x248c) }, /* CAM */
110 { 0x8086, 0x24cc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DBM */ 110 { PCI_DEVICE(0x8086, 0x24cc) }, /* DBM */
111 { 0x8086, 0x2641, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* FBM */ 111 { PCI_DEVICE(0x8086, 0x2641) }, /* FBM */
112 { 0x8086, 0x27b9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM */ 112 { PCI_DEVICE(0x8086, 0x27b9) }, /* GxM */
113 { 0x8086, 0x27bd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* GxM DH */ 113 { PCI_DEVICE(0x8086, 0x27bd) }, /* GxM DH */
114/* BA, CA, DB, Ex, 6300, Fx, 631x/632x, Gx 114/* BA, CA, DB, Ex, 6300, Fx, 631x/632x, Gx
115 { 0x8086, 0x244e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */ 115 { PCI_DEVICE(0x8086, 0x244e) }, */
116 { 0x8086, 0x2440, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* BA */ 116 { PCI_DEVICE(0x8086, 0x2440) }, /* BA */
117 { 0x8086, 0x2480, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* CA */ 117 { PCI_DEVICE(0x8086, 0x2480) }, /* CA */
118 { 0x8086, 0x24c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* DB */ 118 { PCI_DEVICE(0x8086, 0x24c0) }, /* DB */
119 { 0x8086, 0x24d0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ex */ 119 { PCI_DEVICE(0x8086, 0x24d0) }, /* Ex */
120 { 0x8086, 0x25a1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 6300 */ 120 { PCI_DEVICE(0x8086, 0x25a1) }, /* 6300 */
121 { 0x8086, 0x2640, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Fx */ 121 { PCI_DEVICE(0x8086, 0x2640) }, /* Fx */
122 { 0x8086, 0x2670, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 122 { PCI_DEVICE(0x8086, 0x2670) }, /* 631x/632x */
123 { 0x8086, 0x2671, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 123 { PCI_DEVICE(0x8086, 0x2671) }, /* 631x/632x */
124 { 0x8086, 0x2672, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 124 { PCI_DEVICE(0x8086, 0x2672) }, /* 631x/632x */
125 { 0x8086, 0x2673, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 125 { PCI_DEVICE(0x8086, 0x2673) }, /* 631x/632x */
126 { 0x8086, 0x2674, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 126 { PCI_DEVICE(0x8086, 0x2674) }, /* 631x/632x */
127 { 0x8086, 0x2675, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 127 { PCI_DEVICE(0x8086, 0x2675) }, /* 631x/632x */
128 { 0x8086, 0x2676, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 128 { PCI_DEVICE(0x8086, 0x2676) }, /* 631x/632x */
129 { 0x8086, 0x2677, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 129 { PCI_DEVICE(0x8086, 0x2677) }, /* 631x/632x */
130 { 0x8086, 0x2678, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 130 { PCI_DEVICE(0x8086, 0x2678) }, /* 631x/632x */
131 { 0x8086, 0x2679, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 131 { PCI_DEVICE(0x8086, 0x2679) }, /* 631x/632x */
132 { 0x8086, 0x267a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 132 { PCI_DEVICE(0x8086, 0x267a) }, /* 631x/632x */
133 { 0x8086, 0x267b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 133 { PCI_DEVICE(0x8086, 0x267b) }, /* 631x/632x */
134 { 0x8086, 0x267c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 134 { PCI_DEVICE(0x8086, 0x267c) }, /* 631x/632x */
135 { 0x8086, 0x267d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 135 { PCI_DEVICE(0x8086, 0x267d) }, /* 631x/632x */
136 { 0x8086, 0x267e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 136 { PCI_DEVICE(0x8086, 0x267e) }, /* 631x/632x */
137 { 0x8086, 0x267f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* 631x/632x */ 137 { PCI_DEVICE(0x8086, 0x267f) }, /* 631x/632x */
138 { 0x8086, 0x27b8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Gx */ 138 { PCI_DEVICE(0x8086, 0x27b8) }, /* Gx */
139/* E 139/* E
140 { 0x8086, 0x245e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, */ 140 { PCI_DEVICE(0x8086, 0x245e) }, */
141 { 0x8086, 0x2450, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* E */ 141 { PCI_DEVICE(0x8086, 0x2450) }, /* E */
142 { 0, }, /* terminate list */ 142 { 0, }, /* terminate list */
143}; 143};
144MODULE_DEVICE_TABLE(pci, pci_tbl); 144MODULE_DEVICE_TABLE(pci, pci_tbl);
diff --git a/drivers/char/ip2/i2lib.c b/drivers/char/ip2/i2lib.c
index 78045767ec3..f86fa0c55d3 100644
--- a/drivers/char/ip2/i2lib.c
+++ b/drivers/char/ip2/i2lib.c
@@ -80,7 +80,7 @@ static int i2RetryFlushOutput(i2ChanStrPtr);
80// Not a documented part of the library routines (careful...) but the Diagnostic 80// Not a documented part of the library routines (careful...) but the Diagnostic
81// i2diag.c finds them useful to help the throughput in certain limited 81// i2diag.c finds them useful to help the throughput in certain limited
82// single-threaded operations. 82// single-threaded operations.
83static void iiSendPendingMail(i2eBordStrPtr); 83static inline void iiSendPendingMail(i2eBordStrPtr);
84static void serviceOutgoingFifo(i2eBordStrPtr); 84static void serviceOutgoingFifo(i2eBordStrPtr);
85 85
86// Functions defined in ip2.c as part of interrupt handling 86// Functions defined in ip2.c as part of interrupt handling
@@ -150,6 +150,13 @@ i2Validate ( i2ChanStrPtr pCh )
150 == (CHANNEL_MAGIC | CHANNEL_SUPPORT)); 150 == (CHANNEL_MAGIC | CHANNEL_SUPPORT));
151} 151}
152 152
153static void iiSendPendingMail_t(unsigned long data)
154{
155 i2eBordStrPtr pB = (i2eBordStrPtr)data;
156
157 iiSendPendingMail(pB);
158}
159
153//****************************************************************************** 160//******************************************************************************
154// Function: iiSendPendingMail(pB) 161// Function: iiSendPendingMail(pB)
155// Parameters: Pointer to a board structure 162// Parameters: Pointer to a board structure
@@ -184,12 +191,9 @@ iiSendPendingMail(i2eBordStrPtr pB)
184 /\/\|=mhw=|\/\/ */ 191 /\/\|=mhw=|\/\/ */
185 192
186 if( ++pB->SendPendingRetry < 16 ) { 193 if( ++pB->SendPendingRetry < 16 ) {
187 194 setup_timer(&pB->SendPendingTimer,
188 init_timer( &(pB->SendPendingTimer) ); 195 iiSendPendingMail_t, (unsigned long)pB);
189 pB->SendPendingTimer.expires = jiffies + 1; 196 mod_timer(&pB->SendPendingTimer, jiffies + 1);
190 pB->SendPendingTimer.function = (void*)(unsigned long)iiSendPendingMail;
191 pB->SendPendingTimer.data = (unsigned long)pB;
192 add_timer( &(pB->SendPendingTimer) );
193 } else { 197 } else {
194 printk( KERN_ERR "IP2: iiSendPendingMail unable to queue outbound mail\n" ); 198 printk( KERN_ERR "IP2: iiSendPendingMail unable to queue outbound mail\n" );
195 } 199 }
@@ -1265,8 +1269,10 @@ i2RetryFlushOutput(i2ChanStrPtr pCh)
1265// soon as all the data is completely sent. 1269// soon as all the data is completely sent.
1266//****************************************************************************** 1270//******************************************************************************
1267static void 1271static void
1268i2DrainWakeup(i2ChanStrPtr pCh) 1272i2DrainWakeup(unsigned long d)
1269{ 1273{
1274 i2ChanStrPtr pCh = (i2ChanStrPtr)d;
1275
1270 ip2trace (CHANN, ITRC_DRAIN, 10, 1, pCh->BookmarkTimer.expires ); 1276 ip2trace (CHANN, ITRC_DRAIN, 10, 1, pCh->BookmarkTimer.expires );
1271 1277
1272 pCh->BookmarkTimer.expires = 0; 1278 pCh->BookmarkTimer.expires = 0;
@@ -1292,14 +1298,12 @@ i2DrainOutput(i2ChanStrPtr pCh, int timeout)
1292 } 1298 }
1293 if ((timeout > 0) && (pCh->BookmarkTimer.expires == 0 )) { 1299 if ((timeout > 0) && (pCh->BookmarkTimer.expires == 0 )) {
1294 // One per customer (channel) 1300 // One per customer (channel)
1295 init_timer( &(pCh->BookmarkTimer) ); 1301 setup_timer(&pCh->BookmarkTimer, i2DrainWakeup,
1296 pCh->BookmarkTimer.expires = jiffies + timeout; 1302 (unsigned long)pCh);
1297 pCh->BookmarkTimer.function = (void*)(unsigned long)i2DrainWakeup;
1298 pCh->BookmarkTimer.data = (unsigned long)pCh;
1299 1303
1300 ip2trace (CHANN, ITRC_DRAIN, 1, 1, pCh->BookmarkTimer.expires ); 1304 ip2trace (CHANN, ITRC_DRAIN, 1, 1, pCh->BookmarkTimer.expires );
1301 1305
1302 add_timer( &(pCh->BookmarkTimer) ); 1306 mod_timer(&pCh->BookmarkTimer, jiffies + timeout);
1303 } 1307 }
1304 1308
1305 i2QueueCommands( PTYPE_INLINE, pCh, -1, 1, CMD_BMARK_REQ ); 1309 i2QueueCommands( PTYPE_INLINE, pCh, -1, 1, CMD_BMARK_REQ );
@@ -1373,15 +1377,7 @@ ip2_owake( PTTY tp)
1373 ip2trace (CHANN, ITRC_SICMD, 10, 2, tp->flags, 1377 ip2trace (CHANN, ITRC_SICMD, 10, 2, tp->flags,
1374 (1 << TTY_DO_WRITE_WAKEUP) ); 1378 (1 << TTY_DO_WRITE_WAKEUP) );
1375 1379
1376 wake_up_interruptible ( &tp->write_wait ); 1380 tty_wakeup(tp);
1377 if ( ( tp->flags & (1 << TTY_DO_WRITE_WAKEUP) )
1378 && tp->ldisc.write_wakeup )
1379 {
1380 (tp->ldisc.write_wakeup) ( tp );
1381
1382 ip2trace (CHANN, ITRC_SICMD, 11, 0 );
1383
1384 }
1385} 1381}
1386 1382
1387static inline void 1383static inline void
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 7c70310a49b..83c7258d358 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -1271,8 +1271,8 @@ static void do_input(struct work_struct *work)
1271// code duplicated from n_tty (ldisc) 1271// code duplicated from n_tty (ldisc)
1272static inline void isig(int sig, struct tty_struct *tty, int flush) 1272static inline void isig(int sig, struct tty_struct *tty, int flush)
1273{ 1273{
1274 if (tty->pgrp > 0) 1274 if (tty->pgrp)
1275 kill_pg(tty->pgrp, sig, 1); 1275 kill_pgrp(tty->pgrp, sig, 1);
1276 if (flush || !L_NOFLSH(tty)) { 1276 if (flush || !L_NOFLSH(tty)) {
1277 if ( tty->ldisc.flush_buffer ) 1277 if ( tty->ldisc.flush_buffer )
1278 tty->ldisc.flush_buffer(tty); 1278 tty->ldisc.flush_buffer(tty);
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 53582b53da9..3aff5e99b67 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -406,13 +406,14 @@ static void clean_up_interface_data(ipmi_smi_t intf)
406 free_smi_msg_list(&intf->waiting_msgs); 406 free_smi_msg_list(&intf->waiting_msgs);
407 free_recv_msg_list(&intf->waiting_events); 407 free_recv_msg_list(&intf->waiting_events);
408 408
409 /* Wholesale remove all the entries from the list in the 409 /*
410 * interface and wait for RCU to know that none are in use. */ 410 * Wholesale remove all the entries from the list in the
411 * interface and wait for RCU to know that none are in use.
412 */
411 mutex_lock(&intf->cmd_rcvrs_mutex); 413 mutex_lock(&intf->cmd_rcvrs_mutex);
412 list_add_rcu(&list, &intf->cmd_rcvrs); 414 INIT_LIST_HEAD(&list);
413 list_del_rcu(&intf->cmd_rcvrs); 415 list_splice_init_rcu(&intf->cmd_rcvrs, &list, synchronize_rcu);
414 mutex_unlock(&intf->cmd_rcvrs_mutex); 416 mutex_unlock(&intf->cmd_rcvrs_mutex);
415 synchronize_rcu();
416 417
417 list_for_each_entry_safe(rcvr, rcvr2, &list, link) 418 list_for_each_entry_safe(rcvr, rcvr2, &list, link)
418 kfree(rcvr); 419 kfree(rcvr);
@@ -451,7 +452,7 @@ int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
451 mutex_lock(&ipmi_interfaces_mutex); 452 mutex_lock(&ipmi_interfaces_mutex);
452 453
453 /* Build a list of things to deliver. */ 454 /* Build a list of things to deliver. */
454 list_for_each_entry_rcu(intf, &ipmi_interfaces, link) { 455 list_for_each_entry(intf, &ipmi_interfaces, link) {
455 if (intf->intf_num == -1) 456 if (intf->intf_num == -1)
456 continue; 457 continue;
457 e = kmalloc(sizeof(*e), GFP_KERNEL); 458 e = kmalloc(sizeof(*e), GFP_KERNEL);
@@ -1886,7 +1887,6 @@ int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
1886 kfree(entry); 1887 kfree(entry);
1887 rv = -ENOMEM; 1888 rv = -ENOMEM;
1888 } else { 1889 } else {
1889 file->nlink = 1;
1890 file->data = data; 1890 file->data = data;
1891 file->read_proc = read_proc; 1891 file->read_proc = read_proc;
1892 file->write_proc = write_proc; 1892 file->write_proc = write_proc;
@@ -2760,9 +2760,15 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
2760 synchronize_rcu(); 2760 synchronize_rcu();
2761 kref_put(&intf->refcount, intf_free); 2761 kref_put(&intf->refcount, intf_free);
2762 } else { 2762 } else {
2763 /* After this point the interface is legal to use. */ 2763 /*
2764 * Keep memory order straight for RCU readers. Make
2765 * sure everything else is committed to memory before
2766 * setting intf_num to mark the interface valid.
2767 */
2768 smp_wmb();
2764 intf->intf_num = i; 2769 intf->intf_num = i;
2765 mutex_unlock(&ipmi_interfaces_mutex); 2770 mutex_unlock(&ipmi_interfaces_mutex);
2771 /* After this point the interface is legal to use. */
2766 call_smi_watchers(i, intf->si_dev); 2772 call_smi_watchers(i, intf->si_dev);
2767 mutex_unlock(&smi_watchers_mutex); 2773 mutex_unlock(&smi_watchers_mutex);
2768 } 2774 }
@@ -3923,6 +3929,14 @@ static void send_panic_events(char *str)
3923 /* Interface was not ready yet. */ 3929 /* Interface was not ready yet. */
3924 continue; 3930 continue;
3925 3931
3932 /*
3933 * intf_num is used as an marker to tell if the
3934 * interface is valid. Thus we need a read barrier to
3935 * make sure data fetched before checking intf_num
3936 * won't be used.
3937 */
3938 smp_rmb();
3939
3926 /* First job here is to figure out where to send the 3940 /* First job here is to figure out where to send the
3927 OEM events. There's no way in IPMI to send OEM 3941 OEM events. There's no way in IPMI to send OEM
3928 events using an event send command, so we have to 3942 events using an event send command, so we have to
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 01084abffdd..43ab9edc76f 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -183,7 +183,7 @@ static DEFINE_TIMER(tx, isicom_tx, 0, 0);
183/* baud index mappings from linux defns to isi */ 183/* baud index mappings from linux defns to isi */
184 184
185static signed char linuxb_to_isib[] = { 185static signed char linuxb_to_isib[] = {
186 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17, 18, 19 186 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17, 18, 19, 20, 21
187}; 187};
188 188
189struct isi_board { 189struct isi_board {
@@ -213,8 +213,6 @@ struct isi_port {
213 struct tty_struct * tty; 213 struct tty_struct * tty;
214 wait_queue_head_t close_wait; 214 wait_queue_head_t close_wait;
215 wait_queue_head_t open_wait; 215 wait_queue_head_t open_wait;
216 struct work_struct hangup_tq;
217 struct work_struct bh_tqueue;
218 unsigned char * xmit_buf; 216 unsigned char * xmit_buf;
219 int xmit_head; 217 int xmit_head;
220 int xmit_tail; 218 int xmit_tail;
@@ -510,7 +508,7 @@ static void isicom_tx(unsigned long _data)
510 if (port->xmit_cnt <= 0) 508 if (port->xmit_cnt <= 0)
511 port->status &= ~ISI_TXOK; 509 port->status &= ~ISI_TXOK;
512 if (port->xmit_cnt <= WAKEUP_CHARS) 510 if (port->xmit_cnt <= WAKEUP_CHARS)
513 schedule_work(&port->bh_tqueue); 511 tty_wakeup(tty);
514 unlock_card(&isi_card[card]); 512 unlock_card(&isi_card[card]);
515 } 513 }
516 514
@@ -524,21 +522,6 @@ sched_again:
524 mod_timer(&tx, jiffies + msecs_to_jiffies(10)); 522 mod_timer(&tx, jiffies + msecs_to_jiffies(10));
525} 523}
526 524
527/* Interrupt handlers */
528
529
530static void isicom_bottomhalf(struct work_struct *work)
531{
532 struct isi_port *port = container_of(work, struct isi_port, bh_tqueue);
533 struct tty_struct *tty = port->tty;
534
535 if (!tty)
536 return;
537
538 tty_wakeup(tty);
539 wake_up_interruptible(&tty->write_wait);
540}
541
542/* 525/*
543 * Main interrupt handler routine 526 * Main interrupt handler routine
544 */ 527 */
@@ -557,6 +540,11 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
557 return IRQ_NONE; 540 return IRQ_NONE;
558 541
559 base = card->base; 542 base = card->base;
543
544 /* did the card interrupt us? */
545 if (!(inw(base + 0x0e) & 0x02))
546 return IRQ_NONE;
547
560 spin_lock(&card->card_lock); 548 spin_lock(&card->card_lock);
561 549
562 /* 550 /*
@@ -581,6 +569,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
581 port = card->ports + channel; 569 port = card->ports + channel;
582 if (!(port->flags & ASYNC_INITIALIZED)) { 570 if (!(port->flags & ASYNC_INITIALIZED)) {
583 outw(0x0000, base+0x04); /* enable interrupts */ 571 outw(0x0000, base+0x04); /* enable interrupts */
572 spin_unlock(&card->card_lock);
584 return IRQ_HANDLED; 573 return IRQ_HANDLED;
585 } 574 }
586 575
@@ -609,7 +598,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
609 pr_dbg("interrupt: DCD->low.\n" 598 pr_dbg("interrupt: DCD->low.\n"
610 ); 599 );
611 port->status &= ~ISI_DCD; 600 port->status &= ~ISI_DCD;
612 schedule_work(&port->hangup_tq); 601 tty_hangup(tty);
613 } 602 }
614 } else if (header & ISI_DCD) { 603 } else if (header & ISI_DCD) {
615 /* Carrier has been detected */ 604 /* Carrier has been detected */
@@ -631,7 +620,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
631 /* start tx ing */ 620 /* start tx ing */
632 port->status |= (ISI_TXOK 621 port->status |= (ISI_TXOK
633 | ISI_CTS); 622 | ISI_CTS);
634 schedule_work(&port->bh_tqueue); 623 tty_wakeup(tty);
635 } 624 }
636 } else if (!(header & ISI_CTS)) { 625 } else if (!(header & ISI_CTS)) {
637 port->tty->hw_stopped = 1; 626 port->tty->hw_stopped = 1;
@@ -695,6 +684,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
695 tty_flip_buffer_push(tty); 684 tty_flip_buffer_push(tty);
696 } 685 }
697 outw(0x0000, base+0x04); /* enable interrupts */ 686 outw(0x0000, base+0x04); /* enable interrupts */
687 spin_unlock(&card->card_lock);
698 688
699 return IRQ_HANDLED; 689 return IRQ_HANDLED;
700} 690}
@@ -720,7 +710,8 @@ static void isicom_config_port(struct isi_port *port)
720 * respectively. 710 * respectively.
721 */ 711 */
722 712
723 if (baud < 1 || baud > 2) 713 /* 1,2,3,4 => 57.6, 115.2, 230, 460 kbps resp. */
714 if (baud < 1 || baud > 4)
724 port->tty->termios->c_cflag &= ~CBAUDEX; 715 port->tty->termios->c_cflag &= ~CBAUDEX;
725 else 716 else
726 baud += 15; 717 baud += 15;
@@ -736,6 +727,10 @@ static void isicom_config_port(struct isi_port *port)
736 baud++; /* 57.6 Kbps */ 727 baud++; /* 57.6 Kbps */
737 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 728 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
738 baud +=2; /* 115 Kbps */ 729 baud +=2; /* 115 Kbps */
730 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
731 baud += 3; /* 230 kbps*/
732 if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
733 baud += 4; /* 460 kbps*/
739 } 734 }
740 if (linuxb_to_isib[baud] == -1) { 735 if (linuxb_to_isib[baud] == -1) {
741 /* hang up */ 736 /* hang up */
@@ -1460,17 +1455,6 @@ static void isicom_start(struct tty_struct *tty)
1460 port->status |= ISI_TXOK; 1455 port->status |= ISI_TXOK;
1461} 1456}
1462 1457
1463/* hangup et all */
1464static void do_isicom_hangup(struct work_struct *work)
1465{
1466 struct isi_port *port = container_of(work, struct isi_port, hangup_tq);
1467 struct tty_struct *tty;
1468
1469 tty = port->tty;
1470 if (tty)
1471 tty_hangup(tty);
1472}
1473
1474static void isicom_hangup(struct tty_struct *tty) 1458static void isicom_hangup(struct tty_struct *tty)
1475{ 1459{
1476 struct isi_port *port = tty->driver_data; 1460 struct isi_port *port = tty->driver_data;
@@ -1503,7 +1487,6 @@ static void isicom_flush_buffer(struct tty_struct *tty)
1503 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 1487 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1504 spin_unlock_irqrestore(&card->card_lock, flags); 1488 spin_unlock_irqrestore(&card->card_lock, flags);
1505 1489
1506 wake_up_interruptible(&tty->write_wait);
1507 tty_wakeup(tty); 1490 tty_wakeup(tty);
1508} 1491}
1509 1492
@@ -1536,7 +1519,7 @@ static int __devinit reset_card(struct pci_dev *pdev,
1536{ 1519{
1537 struct isi_board *board = pci_get_drvdata(pdev); 1520 struct isi_board *board = pci_get_drvdata(pdev);
1538 unsigned long base = board->base; 1521 unsigned long base = board->base;
1539 unsigned int portcount = 0; 1522 unsigned int sig, portcount = 0;
1540 int retval = 0; 1523 int retval = 0;
1541 1524
1542 dev_dbg(&pdev->dev, "ISILoad:Resetting Card%d at 0x%lx\n", card + 1, 1525 dev_dbg(&pdev->dev, "ISILoad:Resetting Card%d at 0x%lx\n", card + 1,
@@ -1544,27 +1527,35 @@ static int __devinit reset_card(struct pci_dev *pdev,
1544 1527
1545 inw(base + 0x8); 1528 inw(base + 0x8);
1546 1529
1547 mdelay(10); 1530 msleep(10);
1548 1531
1549 outw(0, base + 0x8); /* Reset */ 1532 outw(0, base + 0x8); /* Reset */
1550 1533
1551 msleep(3000); 1534 msleep(1000);
1552 1535
1553 *signature = inw(base + 0x4) & 0xff; 1536 sig = inw(base + 0x4) & 0xff;
1537
1538 if (sig != 0xa5 && sig != 0xbb && sig != 0xcc && sig != 0xdd &&
1539 sig != 0xee) {
1540 dev_warn(&pdev->dev, "ISILoad:Card%u reset failure (Possible "
1541 "bad I/O Port Address 0x%lx).\n", card + 1, base);
1542 dev_dbg(&pdev->dev, "Sig=0x%x\n", sig);
1543 retval = -EIO;
1544 goto end;
1545 }
1546
1547 msleep(10);
1554 1548
1555 portcount = inw(base + 0x2); 1549 portcount = inw(base + 0x2);
1556 if (!(inw(base + 0xe) & 0x1) || ((portcount != 0) && 1550 if (!inw(base + 0xe) & 0x1 || (portcount != 0 && portcount != 4 &&
1557 (portcount != 4) && (portcount != 8))) { 1551 portcount != 8 && portcount != 16)) {
1558 dev_dbg(&pdev->dev, "base+0x2=0x%lx, base+0xe=0x%lx\n", 1552 dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure.",
1559 inw(base + 0x2), inw(base + 0xe)); 1553 card + 1);
1560 dev_err(&pdev->dev, "ISILoad:PCI Card%d reset failure "
1561 "(Possible bad I/O Port Address 0x%lx).\n",
1562 card + 1, base);
1563 retval = -EIO; 1554 retval = -EIO;
1564 goto end; 1555 goto end;
1565 } 1556 }
1566 1557
1567 switch (*signature) { 1558 switch (sig) {
1568 case 0xa5: 1559 case 0xa5:
1569 case 0xbb: 1560 case 0xbb:
1570 case 0xdd: 1561 case 0xdd:
@@ -1572,16 +1563,13 @@ static int __devinit reset_card(struct pci_dev *pdev,
1572 board->shift_count = 12; 1563 board->shift_count = 12;
1573 break; 1564 break;
1574 case 0xcc: 1565 case 0xcc:
1566 case 0xee:
1575 board->port_count = 16; 1567 board->port_count = 16;
1576 board->shift_count = 11; 1568 board->shift_count = 11;
1577 break; 1569 break;
1578 default:
1579 dev_warn(&pdev->dev, "ISILoad:Card%d reset failure (Possible "
1580 "bad I/O Port Address 0x%lx).\n", card + 1, base);
1581 dev_dbg(&pdev->dev, "Sig=0x%lx\n", signature);
1582 retval = -EIO;
1583 } 1570 }
1584 dev_info(&pdev->dev, "-Done\n"); 1571 dev_info(&pdev->dev, "-Done\n");
1572 *signature = sig;
1585 1573
1586end: 1574end:
1587 return retval; 1575 return retval;
@@ -1757,7 +1745,7 @@ end:
1757/* 1745/*
1758 * Insmod can set static symbols so keep these static 1746 * Insmod can set static symbols so keep these static
1759 */ 1747 */
1760static int card; 1748static unsigned int card_count;
1761 1749
1762static int __devinit isicom_probe(struct pci_dev *pdev, 1750static int __devinit isicom_probe(struct pci_dev *pdev,
1763 const struct pci_device_id *ent) 1751 const struct pci_device_id *ent)
@@ -1767,7 +1755,7 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
1767 u8 pciirq; 1755 u8 pciirq;
1768 struct isi_board *board = NULL; 1756 struct isi_board *board = NULL;
1769 1757
1770 if (card >= BOARD_COUNT) 1758 if (card_count >= BOARD_COUNT)
1771 goto err; 1759 goto err;
1772 1760
1773 ioaddr = pci_resource_start(pdev, 3); 1761 ioaddr = pci_resource_start(pdev, 3);
@@ -1785,7 +1773,7 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
1785 board->index = index; 1773 board->index = index;
1786 board->base = ioaddr; 1774 board->base = ioaddr;
1787 board->irq = pciirq; 1775 board->irq = pciirq;
1788 card++; 1776 card_count++;
1789 1777
1790 pci_set_drvdata(pdev, board); 1778 pci_set_drvdata(pdev, board);
1791 1779
@@ -1795,7 +1783,7 @@ static int __devinit isicom_probe(struct pci_dev *pdev,
1795 "will be disabled.\n", board->base, board->base + 15, 1783 "will be disabled.\n", board->base, board->base + 15,
1796 index + 1); 1784 index + 1);
1797 retval = -EBUSY; 1785 retval = -EBUSY;
1798 goto err; 1786 goto errdec;
1799 } 1787 }
1800 1788
1801 retval = request_irq(board->irq, isicom_interrupt, 1789 retval = request_irq(board->irq, isicom_interrupt,
@@ -1824,8 +1812,10 @@ errunri:
1824 free_irq(board->irq, board); 1812 free_irq(board->irq, board);
1825errunrr: 1813errunrr:
1826 pci_release_region(pdev, 3); 1814 pci_release_region(pdev, 3);
1827err: 1815errdec:
1828 board->base = 0; 1816 board->base = 0;
1817 card_count--;
1818err:
1829 return retval; 1819 return retval;
1830} 1820}
1831 1821
@@ -1839,6 +1829,8 @@ static void __devexit isicom_remove(struct pci_dev *pdev)
1839 1829
1840 free_irq(board->irq, board); 1830 free_irq(board->irq, board);
1841 pci_release_region(pdev, 3); 1831 pci_release_region(pdev, 3);
1832 board->base = 0;
1833 card_count--;
1842} 1834}
1843 1835
1844static int __init isicom_init(void) 1836static int __init isicom_init(void)
@@ -1846,8 +1838,6 @@ static int __init isicom_init(void)
1846 int retval, idx, channel; 1838 int retval, idx, channel;
1847 struct isi_port *port; 1839 struct isi_port *port;
1848 1840
1849 card = 0;
1850
1851 for(idx = 0; idx < BOARD_COUNT; idx++) { 1841 for(idx = 0; idx < BOARD_COUNT; idx++) {
1852 port = &isi_ports[idx * 16]; 1842 port = &isi_ports[idx * 16];
1853 isi_card[idx].ports = port; 1843 isi_card[idx].ports = port;
@@ -1858,8 +1848,6 @@ static int __init isicom_init(void)
1858 port->channel = channel; 1848 port->channel = channel;
1859 port->close_delay = 50 * HZ/100; 1849 port->close_delay = 50 * HZ/100;
1860 port->closing_wait = 3000 * HZ/100; 1850 port->closing_wait = 3000 * HZ/100;
1861 INIT_WORK(&port->hangup_tq, do_isicom_hangup);
1862 INIT_WORK(&port->bh_tqueue, isicom_bottomhalf);
1863 port->status = 0; 1851 port->status = 0;
1864 init_waitqueue_head(&port->open_wait); 1852 init_waitqueue_head(&port->open_wait);
1865 init_waitqueue_head(&port->close_wait); 1853 init_waitqueue_head(&port->close_wait);
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 68645d35187..7b279d1de4a 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -2424,7 +2424,6 @@ static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
2424 if (tty != NULL) { 2424 if (tty != NULL) {
2425 tty_wakeup(tty); 2425 tty_wakeup(tty);
2426 EBRDENABLE(brdp); 2426 EBRDENABLE(brdp);
2427 wake_up_interruptible(&tty->write_wait);
2428 } 2427 }
2429 } 2428 }
2430 2429
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 7a6c1c0b7a9..c654a3e0c69 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -595,15 +595,9 @@ static void fn_spawn_con(struct vc_data *vc)
595 595
596static void fn_SAK(struct vc_data *vc) 596static void fn_SAK(struct vc_data *vc)
597{ 597{
598 struct tty_struct *tty = vc->vc_tty; 598 struct work_struct *SAK_work = &vc_cons[fg_console].SAK_work;
599 599 PREPARE_WORK(SAK_work, vc_SAK);
600 /* 600 schedule_work(SAK_work);
601 * SAK should also work in all raw modes and reset
602 * them properly.
603 */
604 if (tty)
605 do_SAK(tty);
606 reset_vc(vc);
607} 601}
608 602
609static void fn_null(struct vc_data *vc) 603static void fn_null(struct vc_data *vc)
diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
index 0afb7ba999c..57f9115a456 100644
--- a/drivers/char/mbcs.c
+++ b/drivers/char/mbcs.c
@@ -46,7 +46,7 @@ LIST_HEAD(soft_list);
46/* 46/*
47 * file operations 47 * file operations
48 */ 48 */
49struct file_operations mbcs_ops = { 49const struct file_operations mbcs_ops = {
50 .open = mbcs_open, 50 .open = mbcs_open,
51 .llseek = mbcs_sram_llseek, 51 .llseek = mbcs_sram_llseek,
52 .read = mbcs_sram_read, 52 .read = mbcs_sram_read,
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index f391a24a1b4..7dbaee8d940 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -11,15 +11,6 @@
11 * 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
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */ 14 */
24 15
25/* 16/*
@@ -55,36 +46,20 @@
55#include <asm/io.h> 46#include <asm/io.h>
56#include <asm/uaccess.h> 47#include <asm/uaccess.h>
57 48
58#define MOXA_VERSION "5.1k" 49#define MOXA_VERSION "5.1k"
59 50
60#define MOXAMAJOR 172 51#define MOXAMAJOR 172
61#define MOXACUMAJOR 173 52#define MOXACUMAJOR 173
62 53
63#define put_to_user(arg1, arg2) put_user(arg1, (unsigned long *)arg2) 54#define MAX_BOARDS 4 /* Don't change this value */
64#define get_from_user(arg1, arg2) get_user(arg1, (unsigned int *)arg2)
65
66#define MAX_BOARDS 4 /* Don't change this value */
67#define MAX_PORTS_PER_BOARD 32 /* Don't change this value */ 55#define MAX_PORTS_PER_BOARD 32 /* Don't change this value */
68#define MAX_PORTS 128 /* Don't change this value */ 56#define MAX_PORTS (MAX_BOARDS * MAX_PORTS_PER_BOARD)
69 57
70/* 58/*
71 * Define the Moxa PCI vendor and device IDs. 59 * Define the Moxa PCI vendor and device IDs.
72 */ 60 */
73#define MOXA_BUS_TYPE_ISA 0 61#define MOXA_BUS_TYPE_ISA 0
74#define MOXA_BUS_TYPE_PCI 1 62#define MOXA_BUS_TYPE_PCI 1
75
76#ifndef PCI_VENDOR_ID_MOXA
77#define PCI_VENDOR_ID_MOXA 0x1393
78#endif
79#ifndef PCI_DEVICE_ID_CP204J
80#define PCI_DEVICE_ID_CP204J 0x2040
81#endif
82#ifndef PCI_DEVICE_ID_C218
83#define PCI_DEVICE_ID_C218 0x2180
84#endif
85#ifndef PCI_DEVICE_ID_C320
86#define PCI_DEVICE_ID_C320 0x3200
87#endif
88 63
89enum { 64enum {
90 MOXA_BOARD_C218_PCI = 1, 65 MOXA_BOARD_C218_PCI = 1,
@@ -105,47 +80,56 @@ static char *moxa_brdname[] =
105 80
106#ifdef CONFIG_PCI 81#ifdef CONFIG_PCI
107static struct pci_device_id moxa_pcibrds[] = { 82static struct pci_device_id moxa_pcibrds[] = {
108 { PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_C218, PCI_ANY_ID, PCI_ANY_ID, 83 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C218),
109 0, 0, MOXA_BOARD_C218_PCI }, 84 .driver_data = MOXA_BOARD_C218_PCI },
110 { PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_C320, PCI_ANY_ID, PCI_ANY_ID, 85 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_C320),
111 0, 0, MOXA_BOARD_C320_PCI }, 86 .driver_data = MOXA_BOARD_C320_PCI },
112 { PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_CP204J, PCI_ANY_ID, PCI_ANY_ID, 87 { PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP204J),
113 0, 0, MOXA_BOARD_CP204J }, 88 .driver_data = MOXA_BOARD_CP204J },
114 { 0 } 89 { 0 }
115}; 90};
116MODULE_DEVICE_TABLE(pci, moxa_pcibrds); 91MODULE_DEVICE_TABLE(pci, moxa_pcibrds);
117#endif /* CONFIG_PCI */ 92#endif /* CONFIG_PCI */
118 93
119typedef struct _moxa_isa_board_conf { 94struct moxa_isa_board_conf {
120 int boardType; 95 int boardType;
121 int numPorts; 96 int numPorts;
122 unsigned long baseAddr; 97 unsigned long baseAddr;
123} moxa_isa_board_conf; 98};
124 99
125static moxa_isa_board_conf moxa_isa_boards[] = 100static struct moxa_isa_board_conf moxa_isa_boards[] =
126{ 101{
127/* {MOXA_BOARD_C218_ISA,8,0xDC000}, */ 102/* {MOXA_BOARD_C218_ISA,8,0xDC000}, */
128}; 103};
129 104
130typedef struct _moxa_pci_devinfo { 105static struct moxa_board_conf {
131 ushort busNum;
132 ushort devNum;
133 struct pci_dev *pdev;
134} moxa_pci_devinfo;
135
136typedef struct _moxa_board_conf {
137 int boardType; 106 int boardType;
138 int numPorts; 107 int numPorts;
139 unsigned long baseAddr; 108 unsigned long baseAddr;
140 int busType; 109 int busType;
141 moxa_pci_devinfo pciInfo;
142} moxa_board_conf;
143 110
144static moxa_board_conf moxa_boards[MAX_BOARDS]; 111 int loadstat;
145static void __iomem *moxaBaseAddr[MAX_BOARDS]; 112
146static int loadstat[MAX_BOARDS]; 113 void __iomem *basemem;
114 void __iomem *intNdx;
115 void __iomem *intPend;
116 void __iomem *intTable;
117} moxa_boards[MAX_BOARDS];
118
119struct mxser_mstatus {
120 tcflag_t cflag;
121 int cts;
122 int dsr;
123 int ri;
124 int dcd;
125};
126
127struct moxaq_str {
128 int inq;
129 int outq;
130};
147 131
148struct moxa_str { 132struct moxa_port {
149 int type; 133 int type;
150 int port; 134 int port;
151 int close_delay; 135 int close_delay;
@@ -159,18 +143,18 @@ struct moxa_str {
159 int cflag; 143 int cflag;
160 wait_queue_head_t open_wait; 144 wait_queue_head_t open_wait;
161 wait_queue_head_t close_wait; 145 wait_queue_head_t close_wait;
162 struct work_struct tqueue;
163};
164 146
165struct mxser_mstatus { 147 struct timer_list emptyTimer;
166 tcflag_t cflag;
167 int cts;
168 int dsr;
169 int ri;
170 int dcd;
171};
172 148
173static struct mxser_mstatus GMStatus[MAX_PORTS]; 149 char chkPort;
150 char lineCtrl;
151 void __iomem *tableAddr;
152 long curBaud;
153 char DCDState;
154 char lowChkFlag;
155
156 ushort breakCnt;
157};
174 158
175/* statusflags */ 159/* statusflags */
176#define TXSTOPPED 0x1 160#define TXSTOPPED 0x1
@@ -178,25 +162,17 @@ static struct mxser_mstatus GMStatus[MAX_PORTS];
178#define EMPTYWAIT 0x4 162#define EMPTYWAIT 0x4
179#define THROTTLE 0x8 163#define THROTTLE 0x8
180 164
181/* event */
182#define MOXA_EVENT_HANGUP 1
183
184#define SERIAL_DO_RESTART 165#define SERIAL_DO_RESTART
185 166
186
187#define SERIAL_TYPE_NORMAL 1
188
189#define WAKEUP_CHARS 256 167#define WAKEUP_CHARS 256
190 168
191#define PORTNO(x) ((x)->index)
192
193static int verbose = 0; 169static int verbose = 0;
194static int ttymajor = MOXAMAJOR; 170static int ttymajor = MOXAMAJOR;
195/* Variables for insmod */ 171/* Variables for insmod */
196#ifdef MODULE 172#ifdef MODULE
197static int baseaddr[] = {0, 0, 0, 0}; 173static int baseaddr[4];
198static int type[] = {0, 0, 0, 0}; 174static int type[4];
199static int numports[] = {0, 0, 0, 0}; 175static int numports[4];
200#endif 176#endif
201 177
202MODULE_AUTHOR("William Chen"); 178MODULE_AUTHOR("William Chen");
@@ -210,19 +186,9 @@ module_param_array(numports, int, NULL, 0);
210module_param(ttymajor, int, 0); 186module_param(ttymajor, int, 0);
211module_param(verbose, bool, 0644); 187module_param(verbose, bool, 0644);
212 188
213static struct tty_driver *moxaDriver;
214static struct moxa_str moxaChannels[MAX_PORTS];
215static unsigned char *moxaXmitBuff;
216static int moxaTimer_on;
217static struct timer_list moxaTimer;
218static int moxaEmptyTimer_on[MAX_PORTS];
219static struct timer_list moxaEmptyTimer[MAX_PORTS];
220static struct semaphore moxaBuffSem;
221
222/* 189/*
223 * static functions: 190 * static functions:
224 */ 191 */
225static void do_moxa_softint(struct work_struct *);
226static int moxa_open(struct tty_struct *, struct file *); 192static int moxa_open(struct tty_struct *, struct file *);
227static void moxa_close(struct tty_struct *, struct file *); 193static void moxa_close(struct tty_struct *, struct file *);
228static int moxa_write(struct tty_struct *, const unsigned char *, int); 194static int moxa_write(struct tty_struct *, const unsigned char *, int);
@@ -244,11 +210,11 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
244static void moxa_poll(unsigned long); 210static void moxa_poll(unsigned long);
245static void set_tty_param(struct tty_struct *); 211static void set_tty_param(struct tty_struct *);
246static int block_till_ready(struct tty_struct *, struct file *, 212static int block_till_ready(struct tty_struct *, struct file *,
247 struct moxa_str *); 213 struct moxa_port *);
248static void setup_empty_event(struct tty_struct *); 214static void setup_empty_event(struct tty_struct *);
249static void check_xmit_empty(unsigned long); 215static void check_xmit_empty(unsigned long);
250static void shut_down(struct moxa_str *); 216static void shut_down(struct moxa_port *);
251static void receive_data(struct moxa_str *); 217static void receive_data(struct moxa_port *);
252/* 218/*
253 * moxa board interface functions: 219 * moxa board interface functions:
254 */ 220 */
@@ -278,8 +244,8 @@ static void MoxaPortTxDisable(int);
278static void MoxaPortTxEnable(int); 244static void MoxaPortTxEnable(int);
279static int MoxaPortResetBrkCnt(int); 245static int MoxaPortResetBrkCnt(int);
280static void MoxaPortSendBreak(int, int); 246static void MoxaPortSendBreak(int, int);
281static int moxa_get_serial_info(struct moxa_str *, struct serial_struct __user *); 247static int moxa_get_serial_info(struct moxa_port *, struct serial_struct __user *);
282static int moxa_set_serial_info(struct moxa_str *, struct serial_struct __user *); 248static int moxa_set_serial_info(struct moxa_port *, struct serial_struct __user *);
283static void MoxaSetFifo(int port, int enable); 249static void MoxaSetFifo(int port, int enable);
284 250
285static const struct tty_operations moxa_ops = { 251static const struct tty_operations moxa_ops = {
@@ -302,12 +268,41 @@ static const struct tty_operations moxa_ops = {
302 .tiocmset = moxa_tiocmset, 268 .tiocmset = moxa_tiocmset,
303}; 269};
304 270
271static struct tty_driver *moxaDriver;
272static struct moxa_port moxa_ports[MAX_PORTS];
273static DEFINE_TIMER(moxaTimer, moxa_poll, 0, 0);
305static DEFINE_SPINLOCK(moxa_lock); 274static DEFINE_SPINLOCK(moxa_lock);
306 275
307#ifdef CONFIG_PCI 276#ifdef CONFIG_PCI
308static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf * board) 277static int __devinit moxa_pci_probe(struct pci_dev *pdev,
278 const struct pci_device_id *ent)
309{ 279{
310 board->baseAddr = pci_resource_start (p, 2); 280 struct moxa_board_conf *board;
281 unsigned int i;
282 int board_type = ent->driver_data;
283 int retval;
284
285 retval = pci_enable_device(pdev);
286 if (retval)
287 goto err;
288
289 for (i = 0; i < MAX_BOARDS; i++)
290 if (moxa_boards[i].basemem == NULL)
291 break;
292
293 retval = -ENODEV;
294 if (i >= MAX_BOARDS) {
295 if (verbose)
296 printk("More than %d MOXA Intellio family boards "
297 "found. Board is ignored.\n", MAX_BOARDS);
298 goto err;
299 }
300
301 board = &moxa_boards[i];
302 board->basemem = pci_iomap(pdev, 2, 0x4000);
303 if (board->basemem == NULL)
304 goto err;
305
311 board->boardType = board_type; 306 board->boardType = board_type;
312 switch (board_type) { 307 switch (board_type) {
313 case MOXA_BOARD_C218_ISA: 308 case MOXA_BOARD_C218_ISA:
@@ -323,27 +318,40 @@ static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf
323 break; 318 break;
324 } 319 }
325 board->busType = MOXA_BUS_TYPE_PCI; 320 board->busType = MOXA_BUS_TYPE_PCI;
326 board->pciInfo.busNum = p->bus->number; 321
327 board->pciInfo.devNum = p->devfn >> 3; 322 pci_set_drvdata(pdev, board);
328 board->pciInfo.pdev = p;
329 /* don't lose the reference in the next pci_get_device iteration */
330 pci_dev_get(p);
331 323
332 return (0); 324 return (0);
325err:
326 return retval;
333} 327}
328
329static void __devexit moxa_pci_remove(struct pci_dev *pdev)
330{
331 struct moxa_board_conf *brd = pci_get_drvdata(pdev);
332
333 pci_iounmap(pdev, brd->basemem);
334 brd->basemem = NULL;
335}
336
337static struct pci_driver moxa_pci_driver = {
338 .name = "moxa",
339 .id_table = moxa_pcibrds,
340 .probe = moxa_pci_probe,
341 .remove = __devexit_p(moxa_pci_remove)
342};
334#endif /* CONFIG_PCI */ 343#endif /* CONFIG_PCI */
335 344
336static int __init moxa_init(void) 345static int __init moxa_init(void)
337{ 346{
338 int i, numBoards; 347 int i, numBoards, retval = 0;
339 struct moxa_str *ch; 348 struct moxa_port *ch;
340 349
341 printk(KERN_INFO "MOXA Intellio family driver version %s\n", MOXA_VERSION); 350 printk(KERN_INFO "MOXA Intellio family driver version %s\n", MOXA_VERSION);
342 moxaDriver = alloc_tty_driver(MAX_PORTS + 1); 351 moxaDriver = alloc_tty_driver(MAX_PORTS + 1);
343 if (!moxaDriver) 352 if (!moxaDriver)
344 return -ENOMEM; 353 return -ENOMEM;
345 354
346 init_MUTEX(&moxaBuffSem);
347 moxaDriver->owner = THIS_MODULE; 355 moxaDriver->owner = THIS_MODULE;
348 moxaDriver->name = "ttyMX"; 356 moxaDriver->name = "ttyMX";
349 moxaDriver->major = ttymajor; 357 moxaDriver->major = ttymajor;
@@ -351,40 +359,25 @@ static int __init moxa_init(void)
351 moxaDriver->type = TTY_DRIVER_TYPE_SERIAL; 359 moxaDriver->type = TTY_DRIVER_TYPE_SERIAL;
352 moxaDriver->subtype = SERIAL_TYPE_NORMAL; 360 moxaDriver->subtype = SERIAL_TYPE_NORMAL;
353 moxaDriver->init_termios = tty_std_termios; 361 moxaDriver->init_termios = tty_std_termios;
354 moxaDriver->init_termios.c_iflag = 0;
355 moxaDriver->init_termios.c_oflag = 0;
356 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 362 moxaDriver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
357 moxaDriver->init_termios.c_lflag = 0;
358 moxaDriver->init_termios.c_ispeed = 9600; 363 moxaDriver->init_termios.c_ispeed = 9600;
359 moxaDriver->init_termios.c_ospeed = 9600; 364 moxaDriver->init_termios.c_ospeed = 9600;
360 moxaDriver->flags = TTY_DRIVER_REAL_RAW; 365 moxaDriver->flags = TTY_DRIVER_REAL_RAW;
361 tty_set_operations(moxaDriver, &moxa_ops); 366 tty_set_operations(moxaDriver, &moxa_ops);
362 367
363 moxaXmitBuff = NULL; 368 for (i = 0, ch = moxa_ports; i < MAX_PORTS; i++, ch++) {
364
365 for (i = 0, ch = moxaChannels; i < MAX_PORTS; i++, ch++) {
366 ch->type = PORT_16550A; 369 ch->type = PORT_16550A;
367 ch->port = i; 370 ch->port = i;
368 INIT_WORK(&ch->tqueue, do_moxa_softint);
369 ch->tty = NULL;
370 ch->close_delay = 5 * HZ / 10; 371 ch->close_delay = 5 * HZ / 10;
371 ch->closing_wait = 30 * HZ; 372 ch->closing_wait = 30 * HZ;
372 ch->count = 0;
373 ch->blocked_open = 0;
374 ch->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL; 373 ch->cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
375 init_waitqueue_head(&ch->open_wait); 374 init_waitqueue_head(&ch->open_wait);
376 init_waitqueue_head(&ch->close_wait); 375 init_waitqueue_head(&ch->close_wait);
377 }
378 376
379 for (i = 0; i < MAX_BOARDS; i++) { 377 setup_timer(&ch->emptyTimer, check_xmit_empty,
380 moxa_boards[i].boardType = 0; 378 (unsigned long)ch);
381 moxa_boards[i].numPorts = 0;
382 moxa_boards[i].baseAddr = 0;
383 moxa_boards[i].busType = 0;
384 moxa_boards[i].pciInfo.busNum = 0;
385 moxa_boards[i].pciInfo.devNum = 0;
386 } 379 }
387 MoxaDriverInit(); 380
388 printk("Tty devices major number = %d\n", ttymajor); 381 printk("Tty devices major number = %d\n", ttymajor);
389 382
390 if (tty_register_driver(moxaDriver)) { 383 if (tty_register_driver(moxaDriver)) {
@@ -392,18 +385,8 @@ static int __init moxa_init(void)
392 put_tty_driver(moxaDriver); 385 put_tty_driver(moxaDriver);
393 return -1; 386 return -1;
394 } 387 }
395 for (i = 0; i < MAX_PORTS; i++) {
396 init_timer(&moxaEmptyTimer[i]);
397 moxaEmptyTimer[i].function = check_xmit_empty;
398 moxaEmptyTimer[i].data = (unsigned long) & moxaChannels[i];
399 moxaEmptyTimer_on[i] = 0;
400 }
401 388
402 init_timer(&moxaTimer); 389 mod_timer(&moxaTimer, jiffies + HZ / 50);
403 moxaTimer.function = moxa_poll;
404 moxaTimer.expires = jiffies + (HZ / 50);
405 moxaTimer_on = 1;
406 add_timer(&moxaTimer);
407 390
408 /* Find the boards defined in source code */ 391 /* Find the boards defined in source code */
409 numBoards = 0; 392 numBoards = 0;
@@ -451,35 +434,22 @@ static int __init moxa_init(void)
451 } 434 }
452 } 435 }
453#endif 436#endif
454 /* Find PCI boards here */ 437
455#ifdef CONFIG_PCI 438#ifdef CONFIG_PCI
456 { 439 retval = pci_register_driver(&moxa_pci_driver);
457 struct pci_dev *p = NULL; 440 if (retval) {
458 int n = ARRAY_SIZE(moxa_pcibrds) - 1; 441 printk(KERN_ERR "Can't register moxa pci driver!\n");
459 i = 0; 442 if (numBoards)
460 while (i < n) { 443 retval = 0;
461 while ((p = pci_get_device(moxa_pcibrds[i].vendor, moxa_pcibrds[i].device, p))!=NULL)
462 {
463 if (pci_enable_device(p))
464 continue;
465 if (numBoards >= MAX_BOARDS) {
466 if (verbose)
467 printk("More than %d MOXA Intellio family boards found. Board is ignored.", MAX_BOARDS);
468 } else {
469 moxa_get_PCI_conf(p, moxa_pcibrds[i].driver_data,
470 &moxa_boards[numBoards]);
471 numBoards++;
472 }
473 }
474 i++;
475 }
476 } 444 }
477#endif 445#endif
446
478 for (i = 0; i < numBoards; i++) { 447 for (i = 0; i < numBoards; i++) {
479 moxaBaseAddr[i] = ioremap((unsigned long) moxa_boards[i].baseAddr, 0x4000); 448 moxa_boards[i].basemem = ioremap(moxa_boards[i].baseAddr,
449 0x4000);
480 } 450 }
481 451
482 return (0); 452 return retval;
483} 453}
484 454
485static void __exit moxa_exit(void) 455static void __exit moxa_exit(void)
@@ -489,23 +459,22 @@ static void __exit moxa_exit(void)
489 if (verbose) 459 if (verbose)
490 printk("Unloading module moxa ...\n"); 460 printk("Unloading module moxa ...\n");
491 461
492 if (moxaTimer_on) 462 del_timer_sync(&moxaTimer);
493 del_timer(&moxaTimer);
494 463
495 for (i = 0; i < MAX_PORTS; i++) 464 for (i = 0; i < MAX_PORTS; i++)
496 if (moxaEmptyTimer_on[i]) 465 del_timer_sync(&moxa_ports[i].emptyTimer);
497 del_timer(&moxaEmptyTimer[i]);
498 466
499 if (tty_unregister_driver(moxaDriver)) 467 if (tty_unregister_driver(moxaDriver))
500 printk("Couldn't unregister MOXA Intellio family serial driver\n"); 468 printk("Couldn't unregister MOXA Intellio family serial driver\n");
501 put_tty_driver(moxaDriver); 469 put_tty_driver(moxaDriver);
502 470
503 for (i = 0; i < MAX_BOARDS; i++) { 471#ifdef CONFIG_PCI
504 if (moxaBaseAddr[i]) 472 pci_unregister_driver(&moxa_pci_driver);
505 iounmap(moxaBaseAddr[i]); 473#endif
506 if (moxa_boards[i].busType == MOXA_BUS_TYPE_PCI) 474
507 pci_dev_put(moxa_boards[i].pciInfo.pdev); 475 for (i = 0; i < MAX_BOARDS; i++)
508 } 476 if (moxa_boards[i].basemem)
477 iounmap(moxa_boards[i].basemem);
509 478
510 if (verbose) 479 if (verbose)
511 printk("Done\n"); 480 printk("Done\n");
@@ -514,28 +483,13 @@ static void __exit moxa_exit(void)
514module_init(moxa_init); 483module_init(moxa_init);
515module_exit(moxa_exit); 484module_exit(moxa_exit);
516 485
517static void do_moxa_softint(struct work_struct *work)
518{
519 struct moxa_str *ch = container_of(work, struct moxa_str, tqueue);
520 struct tty_struct *tty;
521
522 if (ch && (tty = ch->tty)) {
523 if (test_and_clear_bit(MOXA_EVENT_HANGUP, &ch->event)) {
524 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
525 wake_up_interruptible(&ch->open_wait);
526 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
527 }
528 }
529}
530
531static int moxa_open(struct tty_struct *tty, struct file *filp) 486static int moxa_open(struct tty_struct *tty, struct file *filp)
532{ 487{
533 struct moxa_str *ch; 488 struct moxa_port *ch;
534 int port; 489 int port;
535 int retval; 490 int retval;
536 unsigned long page;
537 491
538 port = PORTNO(tty); 492 port = tty->index;
539 if (port == MAX_PORTS) { 493 if (port == MAX_PORTS) {
540 return (0); 494 return (0);
541 } 495 }
@@ -543,23 +497,8 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
543 tty->driver_data = NULL; 497 tty->driver_data = NULL;
544 return (-ENODEV); 498 return (-ENODEV);
545 } 499 }
546 down(&moxaBuffSem);
547 if (!moxaXmitBuff) {
548 page = get_zeroed_page(GFP_KERNEL);
549 if (!page) {
550 up(&moxaBuffSem);
551 return (-ENOMEM);
552 }
553 /* This test is guarded by the BuffSem so no longer needed
554 delete me in 2.5 */
555 if (moxaXmitBuff)
556 free_page(page);
557 else
558 moxaXmitBuff = (unsigned char *) page;
559 }
560 up(&moxaBuffSem);
561 500
562 ch = &moxaChannels[port]; 501 ch = &moxa_ports[port];
563 ch->count++; 502 ch->count++;
564 tty->driver_data = ch; 503 tty->driver_data = ch;
565 ch->tty = tty; 504 ch->tty = tty;
@@ -585,10 +524,10 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
585 524
586static void moxa_close(struct tty_struct *tty, struct file *filp) 525static void moxa_close(struct tty_struct *tty, struct file *filp)
587{ 526{
588 struct moxa_str *ch; 527 struct moxa_port *ch;
589 int port; 528 int port;
590 529
591 port = PORTNO(tty); 530 port = tty->index;
592 if (port == MAX_PORTS) { 531 if (port == MAX_PORTS) {
593 return; 532 return;
594 } 533 }
@@ -605,7 +544,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
605 if (tty_hung_up_p(filp)) { 544 if (tty_hung_up_p(filp)) {
606 return; 545 return;
607 } 546 }
608 ch = (struct moxa_str *) tty->driver_data; 547 ch = (struct moxa_port *) tty->driver_data;
609 548
610 if ((tty->count == 1) && (ch->count != 1)) { 549 if ((tty->count == 1) && (ch->count != 1)) {
611 printk("moxa_close: bad serial port count; tty->count is 1, " 550 printk("moxa_close: bad serial port count; tty->count is 1, "
@@ -626,8 +565,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
626 if (ch->asyncflags & ASYNC_INITIALIZED) { 565 if (ch->asyncflags & ASYNC_INITIALIZED) {
627 setup_empty_event(tty); 566 setup_empty_event(tty);
628 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */ 567 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */
629 moxaEmptyTimer_on[ch->port] = 0; 568 del_timer_sync(&moxa_ports[ch->port].emptyTimer);
630 del_timer(&moxaEmptyTimer[ch->port]);
631 } 569 }
632 shut_down(ch); 570 shut_down(ch);
633 MoxaPortFlushData(port, 2); 571 MoxaPortFlushData(port, 2);
@@ -652,11 +590,11 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
652static int moxa_write(struct tty_struct *tty, 590static int moxa_write(struct tty_struct *tty,
653 const unsigned char *buf, int count) 591 const unsigned char *buf, int count)
654{ 592{
655 struct moxa_str *ch; 593 struct moxa_port *ch;
656 int len, port; 594 int len, port;
657 unsigned long flags; 595 unsigned long flags;
658 596
659 ch = (struct moxa_str *) tty->driver_data; 597 ch = (struct moxa_port *) tty->driver_data;
660 if (ch == NULL) 598 if (ch == NULL)
661 return (0); 599 return (0);
662 port = ch->port; 600 port = ch->port;
@@ -675,11 +613,11 @@ static int moxa_write(struct tty_struct *tty,
675 613
676static int moxa_write_room(struct tty_struct *tty) 614static int moxa_write_room(struct tty_struct *tty)
677{ 615{
678 struct moxa_str *ch; 616 struct moxa_port *ch;
679 617
680 if (tty->stopped) 618 if (tty->stopped)
681 return (0); 619 return (0);
682 ch = (struct moxa_str *) tty->driver_data; 620 ch = (struct moxa_port *) tty->driver_data;
683 if (ch == NULL) 621 if (ch == NULL)
684 return (0); 622 return (0);
685 return (MoxaPortTxFree(ch->port)); 623 return (MoxaPortTxFree(ch->port));
@@ -687,7 +625,7 @@ static int moxa_write_room(struct tty_struct *tty)
687 625
688static void moxa_flush_buffer(struct tty_struct *tty) 626static void moxa_flush_buffer(struct tty_struct *tty)
689{ 627{
690 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 628 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
691 629
692 if (ch == NULL) 630 if (ch == NULL)
693 return; 631 return;
@@ -698,7 +636,7 @@ static void moxa_flush_buffer(struct tty_struct *tty)
698static int moxa_chars_in_buffer(struct tty_struct *tty) 636static int moxa_chars_in_buffer(struct tty_struct *tty)
699{ 637{
700 int chars; 638 int chars;
701 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 639 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
702 640
703 /* 641 /*
704 * Sigh...I have to check if driver_data is NULL here, because 642 * Sigh...I have to check if driver_data is NULL here, because
@@ -730,17 +668,16 @@ static void moxa_flush_chars(struct tty_struct *tty)
730 668
731static void moxa_put_char(struct tty_struct *tty, unsigned char c) 669static void moxa_put_char(struct tty_struct *tty, unsigned char c)
732{ 670{
733 struct moxa_str *ch; 671 struct moxa_port *ch;
734 int port; 672 int port;
735 unsigned long flags; 673 unsigned long flags;
736 674
737 ch = (struct moxa_str *) tty->driver_data; 675 ch = (struct moxa_port *) tty->driver_data;
738 if (ch == NULL) 676 if (ch == NULL)
739 return; 677 return;
740 port = ch->port; 678 port = ch->port;
741 spin_lock_irqsave(&moxa_lock, flags); 679 spin_lock_irqsave(&moxa_lock, flags);
742 moxaXmitBuff[0] = c; 680 MoxaPortWriteData(port, &c, 1);
743 MoxaPortWriteData(port, moxaXmitBuff, 1);
744 spin_unlock_irqrestore(&moxa_lock, flags); 681 spin_unlock_irqrestore(&moxa_lock, flags);
745 /************************************************ 682 /************************************************
746 if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) ) 683 if ( !(ch->statusflags & LOWWAIT) && (MoxaPortTxFree(port) <= 100) )
@@ -750,11 +687,11 @@ static void moxa_put_char(struct tty_struct *tty, unsigned char c)
750 687
751static int moxa_tiocmget(struct tty_struct *tty, struct file *file) 688static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
752{ 689{
753 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 690 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
754 int port; 691 int port;
755 int flag = 0, dtr, rts; 692 int flag = 0, dtr, rts;
756 693
757 port = PORTNO(tty); 694 port = tty->index;
758 if ((port != MAX_PORTS) && (!ch)) 695 if ((port != MAX_PORTS) && (!ch))
759 return (-EINVAL); 696 return (-EINVAL);
760 697
@@ -776,11 +713,11 @@ static int moxa_tiocmget(struct tty_struct *tty, struct file *file)
776static int moxa_tiocmset(struct tty_struct *tty, struct file *file, 713static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
777 unsigned int set, unsigned int clear) 714 unsigned int set, unsigned int clear)
778{ 715{
779 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 716 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
780 int port; 717 int port;
781 int dtr, rts; 718 int dtr, rts;
782 719
783 port = PORTNO(tty); 720 port = tty->index;
784 if ((port != MAX_PORTS) && (!ch)) 721 if ((port != MAX_PORTS) && (!ch))
785 return (-EINVAL); 722 return (-EINVAL);
786 723
@@ -800,12 +737,12 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
800static int moxa_ioctl(struct tty_struct *tty, struct file *file, 737static int moxa_ioctl(struct tty_struct *tty, struct file *file,
801 unsigned int cmd, unsigned long arg) 738 unsigned int cmd, unsigned long arg)
802{ 739{
803 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 740 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
804 register int port; 741 register int port;
805 void __user *argp = (void __user *)arg; 742 void __user *argp = (void __user *)arg;
806 int retval; 743 int retval;
807 744
808 port = PORTNO(tty); 745 port = tty->index;
809 if ((port != MAX_PORTS) && (!ch)) 746 if ((port != MAX_PORTS) && (!ch))
810 return (-EINVAL); 747 return (-EINVAL);
811 748
@@ -853,14 +790,14 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file,
853 790
854static void moxa_throttle(struct tty_struct *tty) 791static void moxa_throttle(struct tty_struct *tty)
855{ 792{
856 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 793 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
857 794
858 ch->statusflags |= THROTTLE; 795 ch->statusflags |= THROTTLE;
859} 796}
860 797
861static void moxa_unthrottle(struct tty_struct *tty) 798static void moxa_unthrottle(struct tty_struct *tty)
862{ 799{
863 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 800 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
864 801
865 ch->statusflags &= ~THROTTLE; 802 ch->statusflags &= ~THROTTLE;
866} 803}
@@ -868,7 +805,7 @@ static void moxa_unthrottle(struct tty_struct *tty)
868static void moxa_set_termios(struct tty_struct *tty, 805static void moxa_set_termios(struct tty_struct *tty,
869 struct ktermios *old_termios) 806 struct ktermios *old_termios)
870{ 807{
871 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 808 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
872 809
873 if (ch == NULL) 810 if (ch == NULL)
874 return; 811 return;
@@ -880,7 +817,7 @@ static void moxa_set_termios(struct tty_struct *tty,
880 817
881static void moxa_stop(struct tty_struct *tty) 818static void moxa_stop(struct tty_struct *tty)
882{ 819{
883 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 820 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
884 821
885 if (ch == NULL) 822 if (ch == NULL)
886 return; 823 return;
@@ -891,7 +828,7 @@ static void moxa_stop(struct tty_struct *tty)
891 828
892static void moxa_start(struct tty_struct *tty) 829static void moxa_start(struct tty_struct *tty)
893{ 830{
894 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 831 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
895 832
896 if (ch == NULL) 833 if (ch == NULL)
897 return; 834 return;
@@ -905,7 +842,7 @@ static void moxa_start(struct tty_struct *tty)
905 842
906static void moxa_hangup(struct tty_struct *tty) 843static void moxa_hangup(struct tty_struct *tty)
907{ 844{
908 struct moxa_str *ch = (struct moxa_str *) tty->driver_data; 845 struct moxa_port *ch = (struct moxa_port *) tty->driver_data;
909 846
910 moxa_flush_buffer(tty); 847 moxa_flush_buffer(tty);
911 shut_down(ch); 848 shut_down(ch);
@@ -919,24 +856,20 @@ static void moxa_hangup(struct tty_struct *tty)
919static void moxa_poll(unsigned long ignored) 856static void moxa_poll(unsigned long ignored)
920{ 857{
921 register int card; 858 register int card;
922 struct moxa_str *ch; 859 struct moxa_port *ch;
923 struct tty_struct *tp; 860 struct tty_struct *tp;
924 int i, ports; 861 int i, ports;
925 862
926 moxaTimer_on = 0;
927 del_timer(&moxaTimer); 863 del_timer(&moxaTimer);
928 864
929 if (MoxaDriverPoll() < 0) { 865 if (MoxaDriverPoll() < 0) {
930 moxaTimer.function = moxa_poll; 866 mod_timer(&moxaTimer, jiffies + HZ / 50);
931 moxaTimer.expires = jiffies + (HZ / 50);
932 moxaTimer_on = 1;
933 add_timer(&moxaTimer);
934 return; 867 return;
935 } 868 }
936 for (card = 0; card < MAX_BOARDS; card++) { 869 for (card = 0; card < MAX_BOARDS; card++) {
937 if ((ports = MoxaPortsOfCard(card)) <= 0) 870 if ((ports = MoxaPortsOfCard(card)) <= 0)
938 continue; 871 continue;
939 ch = &moxaChannels[card * MAX_PORTS_PER_BOARD]; 872 ch = &moxa_ports[card * MAX_PORTS_PER_BOARD];
940 for (i = 0; i < ports; i++, ch++) { 873 for (i = 0; i < ports; i++, ch++) {
941 if ((ch->asyncflags & ASYNC_INITIALIZED) == 0) 874 if ((ch->asyncflags & ASYNC_INITIALIZED) == 0)
942 continue; 875 continue;
@@ -962,18 +895,16 @@ static void moxa_poll(unsigned long ignored)
962 if (MoxaPortDCDON(ch->port)) 895 if (MoxaPortDCDON(ch->port))
963 wake_up_interruptible(&ch->open_wait); 896 wake_up_interruptible(&ch->open_wait);
964 else { 897 else {
965 set_bit(MOXA_EVENT_HANGUP, &ch->event); 898 tty_hangup(tp);
966 schedule_work(&ch->tqueue); 899 wake_up_interruptible(&ch->open_wait);
900 ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
967 } 901 }
968 } 902 }
969 } 903 }
970 } 904 }
971 } 905 }
972 906
973 moxaTimer.function = moxa_poll; 907 mod_timer(&moxaTimer, jiffies + HZ / 50);
974 moxaTimer.expires = jiffies + (HZ / 50);
975 moxaTimer_on = 1;
976 add_timer(&moxaTimer);
977} 908}
978 909
979/******************************************************************************/ 910/******************************************************************************/
@@ -981,10 +912,10 @@ static void moxa_poll(unsigned long ignored)
981static void set_tty_param(struct tty_struct *tty) 912static void set_tty_param(struct tty_struct *tty)
982{ 913{
983 register struct ktermios *ts; 914 register struct ktermios *ts;
984 struct moxa_str *ch; 915 struct moxa_port *ch;
985 int rts, cts, txflow, rxflow, xany; 916 int rts, cts, txflow, rxflow, xany;
986 917
987 ch = (struct moxa_str *) tty->driver_data; 918 ch = (struct moxa_port *) tty->driver_data;
988 ts = tty->termios; 919 ts = tty->termios;
989 if (ts->c_cflag & CLOCAL) 920 if (ts->c_cflag & CLOCAL)
990 ch->asyncflags &= ~ASYNC_CHECK_CD; 921 ch->asyncflags &= ~ASYNC_CHECK_CD;
@@ -1004,7 +935,7 @@ static void set_tty_param(struct tty_struct *tty)
1004} 935}
1005 936
1006static int block_till_ready(struct tty_struct *tty, struct file *filp, 937static int block_till_ready(struct tty_struct *tty, struct file *filp,
1007 struct moxa_str *ch) 938 struct moxa_port *ch)
1008{ 939{
1009 DECLARE_WAITQUEUE(wait,current); 940 DECLARE_WAITQUEUE(wait,current);
1010 unsigned long flags; 941 unsigned long flags;
@@ -1095,40 +1026,33 @@ static int block_till_ready(struct tty_struct *tty, struct file *filp,
1095 1026
1096static void setup_empty_event(struct tty_struct *tty) 1027static void setup_empty_event(struct tty_struct *tty)
1097{ 1028{
1098 struct moxa_str *ch = tty->driver_data; 1029 struct moxa_port *ch = tty->driver_data;
1099 unsigned long flags; 1030 unsigned long flags;
1100 1031
1101 spin_lock_irqsave(&moxa_lock, flags); 1032 spin_lock_irqsave(&moxa_lock, flags);
1102 ch->statusflags |= EMPTYWAIT; 1033 ch->statusflags |= EMPTYWAIT;
1103 moxaEmptyTimer_on[ch->port] = 0; 1034 mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ);
1104 del_timer(&moxaEmptyTimer[ch->port]);
1105 moxaEmptyTimer[ch->port].expires = jiffies + HZ;
1106 moxaEmptyTimer_on[ch->port] = 1;
1107 add_timer(&moxaEmptyTimer[ch->port]);
1108 spin_unlock_irqrestore(&moxa_lock, flags); 1035 spin_unlock_irqrestore(&moxa_lock, flags);
1109} 1036}
1110 1037
1111static void check_xmit_empty(unsigned long data) 1038static void check_xmit_empty(unsigned long data)
1112{ 1039{
1113 struct moxa_str *ch; 1040 struct moxa_port *ch;
1114 1041
1115 ch = (struct moxa_str *) data; 1042 ch = (struct moxa_port *) data;
1116 moxaEmptyTimer_on[ch->port] = 0; 1043 del_timer_sync(&moxa_ports[ch->port].emptyTimer);
1117 del_timer(&moxaEmptyTimer[ch->port]);
1118 if (ch->tty && (ch->statusflags & EMPTYWAIT)) { 1044 if (ch->tty && (ch->statusflags & EMPTYWAIT)) {
1119 if (MoxaPortTxQueue(ch->port) == 0) { 1045 if (MoxaPortTxQueue(ch->port) == 0) {
1120 ch->statusflags &= ~EMPTYWAIT; 1046 ch->statusflags &= ~EMPTYWAIT;
1121 tty_wakeup(ch->tty); 1047 tty_wakeup(ch->tty);
1122 return; 1048 return;
1123 } 1049 }
1124 moxaEmptyTimer[ch->port].expires = jiffies + HZ; 1050 mod_timer(&moxa_ports[ch->port].emptyTimer, jiffies + HZ);
1125 moxaEmptyTimer_on[ch->port] = 1;
1126 add_timer(&moxaEmptyTimer[ch->port]);
1127 } else 1051 } else
1128 ch->statusflags &= ~EMPTYWAIT; 1052 ch->statusflags &= ~EMPTYWAIT;
1129} 1053}
1130 1054
1131static void shut_down(struct moxa_str *ch) 1055static void shut_down(struct moxa_port *ch)
1132{ 1056{
1133 struct tty_struct *tp; 1057 struct tty_struct *tp;
1134 1058
@@ -1148,7 +1072,7 @@ static void shut_down(struct moxa_str *ch)
1148 ch->asyncflags &= ~ASYNC_INITIALIZED; 1072 ch->asyncflags &= ~ASYNC_INITIALIZED;
1149} 1073}
1150 1074
1151static void receive_data(struct moxa_str *ch) 1075static void receive_data(struct moxa_port *ch)
1152{ 1076{
1153 struct tty_struct *tp; 1077 struct tty_struct *tp;
1154 struct ktermios *ts; 1078 struct ktermios *ts;
@@ -1465,35 +1389,21 @@ static void receive_data(struct moxa_str *ch)
1465/* 1389/*
1466 * Query 1390 * Query
1467 */ 1391 */
1468#define QueryPort MAX_PORTS
1469
1470
1471 1392
1472struct mon_str { 1393struct mon_str {
1473 int tick; 1394 int tick;
1474 int rxcnt[MAX_PORTS]; 1395 int rxcnt[MAX_PORTS];
1475 int txcnt[MAX_PORTS]; 1396 int txcnt[MAX_PORTS];
1476}; 1397};
1477typedef struct mon_str mon_st;
1478 1398
1479#define DCD_changed 0x01 1399#define DCD_changed 0x01
1480#define DCD_oldstate 0x80 1400#define DCD_oldstate 0x80
1481 1401
1482static unsigned char moxaBuff[10240]; 1402static unsigned char moxaBuff[10240];
1483static void __iomem *moxaIntNdx[MAX_BOARDS];
1484static void __iomem *moxaIntPend[MAX_BOARDS];
1485static void __iomem *moxaIntTable[MAX_BOARDS];
1486static char moxaChkPort[MAX_PORTS];
1487static char moxaLineCtrl[MAX_PORTS];
1488static void __iomem *moxaTableAddr[MAX_PORTS];
1489static long moxaCurBaud[MAX_PORTS];
1490static char moxaDCDState[MAX_PORTS];
1491static char moxaLowChkFlag[MAX_PORTS];
1492static int moxaLowWaterChk; 1403static int moxaLowWaterChk;
1493static int moxaCard; 1404static int moxaCard;
1494static mon_st moxaLog; 1405static struct mon_str moxaLog;
1495static int moxaFuncTout; 1406static int moxaFuncTout = HZ / 2;
1496static ushort moxaBreakCnt[MAX_PORTS];
1497 1407
1498static void moxadelay(int); 1408static void moxadelay(int);
1499static void moxafunc(void __iomem *, int, ushort); 1409static void moxafunc(void __iomem *, int, ushort);
@@ -1514,16 +1424,18 @@ static int moxaloadc320(int, void __iomem *, int, int *);
1514 *****************************************************************************/ 1424 *****************************************************************************/
1515void MoxaDriverInit(void) 1425void MoxaDriverInit(void)
1516{ 1426{
1517 int i; 1427 struct moxa_port *p;
1428 unsigned int i;
1518 1429
1519 moxaFuncTout = HZ / 2; /* 500 mini-seconds */ 1430 moxaFuncTout = HZ / 2; /* 500 mini-seconds */
1520 moxaCard = 0; 1431 moxaCard = 0;
1521 moxaLog.tick = 0; 1432 moxaLog.tick = 0;
1522 moxaLowWaterChk = 0; 1433 moxaLowWaterChk = 0;
1523 for (i = 0; i < MAX_PORTS; i++) { 1434 for (i = 0; i < MAX_PORTS; i++) {
1524 moxaChkPort[i] = 0; 1435 p = &moxa_ports[i];
1525 moxaLowChkFlag[i] = 0; 1436 p->chkPort = 0;
1526 moxaLineCtrl[i] = 0; 1437 p->lowChkFlag = 0;
1438 p->lineCtrl = 0;
1527 moxaLog.rxcnt[i] = 0; 1439 moxaLog.rxcnt[i] = 0;
1528 moxaLog.txcnt[i] = 0; 1440 moxaLog.txcnt[i] = 0;
1529 } 1441 }
@@ -1545,19 +1457,12 @@ void MoxaDriverInit(void)
1545#define MOXA_GET_CUMAJOR (MOXA + 64) 1457#define MOXA_GET_CUMAJOR (MOXA + 64)
1546#define MOXA_GETMSTATUS (MOXA + 65) 1458#define MOXA_GETMSTATUS (MOXA + 65)
1547 1459
1548
1549struct moxaq_str {
1550 int inq;
1551 int outq;
1552};
1553
1554struct dl_str { 1460struct dl_str {
1555 char __user *buf; 1461 char __user *buf;
1556 int len; 1462 int len;
1557 int cardno; 1463 int cardno;
1558}; 1464};
1559 1465
1560static struct moxaq_str temp_queue[MAX_PORTS];
1561static struct dl_str dltmp; 1466static struct dl_str dltmp;
1562 1467
1563void MoxaPortFlushData(int port, int mode) 1468void MoxaPortFlushData(int port, int mode)
@@ -1565,10 +1470,10 @@ void MoxaPortFlushData(int port, int mode)
1565 void __iomem *ofsAddr; 1470 void __iomem *ofsAddr;
1566 if ((mode < 0) || (mode > 2)) 1471 if ((mode < 0) || (mode > 2))
1567 return; 1472 return;
1568 ofsAddr = moxaTableAddr[port]; 1473 ofsAddr = moxa_ports[port].tableAddr;
1569 moxafunc(ofsAddr, FC_FlushQueue, mode); 1474 moxafunc(ofsAddr, FC_FlushQueue, mode);
1570 if (mode != 1) { 1475 if (mode != 1) {
1571 moxaLowChkFlag[port] = 0; 1476 moxa_ports[port].lowChkFlag = 0;
1572 low_water_check(ofsAddr); 1477 low_water_check(ofsAddr);
1573 } 1478 }
1574} 1479}
@@ -1580,7 +1485,7 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1580 int MoxaPortTxQueue(int), MoxaPortRxQueue(int); 1485 int MoxaPortTxQueue(int), MoxaPortRxQueue(int);
1581 void __user *argp = (void __user *)arg; 1486 void __user *argp = (void __user *)arg;
1582 1487
1583 if (port == QueryPort) { 1488 if (port == MAX_PORTS) {
1584 if ((cmd != MOXA_GET_CONF) && (cmd != MOXA_INIT_DRIVER) && 1489 if ((cmd != MOXA_GET_CONF) && (cmd != MOXA_INIT_DRIVER) &&
1585 (cmd != MOXA_LOAD_BIOS) && (cmd != MOXA_FIND_BOARD) && (cmd != MOXA_LOAD_C320B) && 1490 (cmd != MOXA_LOAD_BIOS) && (cmd != MOXA_FIND_BOARD) && (cmd != MOXA_LOAD_C320B) &&
1586 (cmd != MOXA_LOAD_CODE) && (cmd != MOXA_GETDATACOUNT) && 1491 (cmd != MOXA_LOAD_CODE) && (cmd != MOXA_GETDATACOUNT) &&
@@ -1590,7 +1495,8 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1590 } 1495 }
1591 switch (cmd) { 1496 switch (cmd) {
1592 case MOXA_GET_CONF: 1497 case MOXA_GET_CONF:
1593 if(copy_to_user(argp, &moxa_boards, MAX_BOARDS * sizeof(moxa_board_conf))) 1498 if(copy_to_user(argp, &moxa_boards, MAX_BOARDS *
1499 sizeof(struct moxa_board_conf)))
1594 return -EFAULT; 1500 return -EFAULT;
1595 return (0); 1501 return (0);
1596 case MOXA_INIT_DRIVER: 1502 case MOXA_INIT_DRIVER:
@@ -1599,23 +1505,27 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1599 return (0); 1505 return (0);
1600 case MOXA_GETDATACOUNT: 1506 case MOXA_GETDATACOUNT:
1601 moxaLog.tick = jiffies; 1507 moxaLog.tick = jiffies;
1602 if(copy_to_user(argp, &moxaLog, sizeof(mon_st))) 1508 if(copy_to_user(argp, &moxaLog, sizeof(struct mon_str)))
1603 return -EFAULT; 1509 return -EFAULT;
1604 return (0); 1510 return (0);
1605 case MOXA_FLUSH_QUEUE: 1511 case MOXA_FLUSH_QUEUE:
1606 MoxaPortFlushData(port, arg); 1512 MoxaPortFlushData(port, arg);
1607 return (0); 1513 return (0);
1608 case MOXA_GET_IOQUEUE: 1514 case MOXA_GET_IOQUEUE: {
1609 for (i = 0; i < MAX_PORTS; i++) { 1515 struct moxaq_str __user *argm = argp;
1610 if (moxaChkPort[i]) { 1516 struct moxaq_str tmp;
1611 temp_queue[i].inq = MoxaPortRxQueue(i); 1517
1612 temp_queue[i].outq = MoxaPortTxQueue(i); 1518 for (i = 0; i < MAX_PORTS; i++, argm++) {
1519 memset(&tmp, 0, sizeof(tmp));
1520 if (moxa_ports[i].chkPort) {
1521 tmp.inq = MoxaPortRxQueue(i);
1522 tmp.outq = MoxaPortTxQueue(i);
1613 } 1523 }
1524 if (copy_to_user(argm, &tmp, sizeof(tmp)))
1525 return -EFAULT;
1614 } 1526 }
1615 if(copy_to_user(argp, temp_queue, sizeof(struct moxaq_str) * MAX_PORTS))
1616 return -EFAULT;
1617 return (0); 1527 return (0);
1618 case MOXA_GET_OQUEUE: 1528 } case MOXA_GET_OQUEUE:
1619 i = MoxaPortTxQueue(port); 1529 i = MoxaPortTxQueue(port);
1620 return put_user(i, (unsigned long __user *)argp); 1530 return put_user(i, (unsigned long __user *)argp);
1621 case MOXA_GET_IQUEUE: 1531 case MOXA_GET_IQUEUE:
@@ -1630,33 +1540,36 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1630 if(copy_to_user(argp, &i, sizeof(int))) 1540 if(copy_to_user(argp, &i, sizeof(int)))
1631 return -EFAULT; 1541 return -EFAULT;
1632 return 0; 1542 return 0;
1633 case MOXA_GETMSTATUS: 1543 case MOXA_GETMSTATUS: {
1634 for (i = 0; i < MAX_PORTS; i++) { 1544 struct mxser_mstatus __user *argm = argp;
1635 GMStatus[i].ri = 0; 1545 struct mxser_mstatus tmp;
1636 GMStatus[i].dcd = 0; 1546 struct moxa_port *p;
1637 GMStatus[i].dsr = 0; 1547
1638 GMStatus[i].cts = 0; 1548 for (i = 0; i < MAX_PORTS; i++, argm++) {
1639 if (!moxaChkPort[i]) { 1549 p = &moxa_ports[i];
1640 continue; 1550 memset(&tmp, 0, sizeof(tmp));
1551 if (!p->chkPort) {
1552 goto copy;
1641 } else { 1553 } else {
1642 status = MoxaPortLineStatus(moxaChannels[i].port); 1554 status = MoxaPortLineStatus(p->port);
1643 if (status & 1) 1555 if (status & 1)
1644 GMStatus[i].cts = 1; 1556 tmp.cts = 1;
1645 if (status & 2) 1557 if (status & 2)
1646 GMStatus[i].dsr = 1; 1558 tmp.dsr = 1;
1647 if (status & 4) 1559 if (status & 4)
1648 GMStatus[i].dcd = 1; 1560 tmp.dcd = 1;
1649 } 1561 }
1650 1562
1651 if (!moxaChannels[i].tty || !moxaChannels[i].tty->termios) 1563 if (!p->tty || !p->tty->termios)
1652 GMStatus[i].cflag = moxaChannels[i].cflag; 1564 tmp.cflag = p->cflag;
1653 else 1565 else
1654 GMStatus[i].cflag = moxaChannels[i].tty->termios->c_cflag; 1566 tmp.cflag = p->tty->termios->c_cflag;
1567copy:
1568 if (copy_to_user(argm, &tmp, sizeof(tmp)))
1569 return -EFAULT;
1655 } 1570 }
1656 if(copy_to_user(argp, GMStatus, sizeof(struct mxser_mstatus) * MAX_PORTS))
1657 return -EFAULT;
1658 return 0; 1571 return 0;
1659 default: 1572 } default:
1660 return (-ENOIOCTLCMD); 1573 return (-ENOIOCTLCMD);
1661 case MOXA_LOAD_BIOS: 1574 case MOXA_LOAD_BIOS:
1662 case MOXA_FIND_BOARD: 1575 case MOXA_FIND_BOARD:
@@ -1694,6 +1607,7 @@ int MoxaDriverIoctl(unsigned int cmd, unsigned long arg, int port)
1694 1607
1695int MoxaDriverPoll(void) 1608int MoxaDriverPoll(void)
1696{ 1609{
1610 struct moxa_board_conf *brd;
1697 register ushort temp; 1611 register ushort temp;
1698 register int card; 1612 register int card;
1699 void __iomem *ofsAddr; 1613 void __iomem *ofsAddr;
@@ -1703,43 +1617,44 @@ int MoxaDriverPoll(void)
1703 if (moxaCard == 0) 1617 if (moxaCard == 0)
1704 return (-1); 1618 return (-1);
1705 for (card = 0; card < MAX_BOARDS; card++) { 1619 for (card = 0; card < MAX_BOARDS; card++) {
1706 if (loadstat[card] == 0) 1620 brd = &moxa_boards[card];
1621 if (brd->loadstat == 0)
1707 continue; 1622 continue;
1708 if ((ports = moxa_boards[card].numPorts) == 0) 1623 if ((ports = brd->numPorts) == 0)
1709 continue; 1624 continue;
1710 if (readb(moxaIntPend[card]) == 0xff) { 1625 if (readb(brd->intPend) == 0xff) {
1711 ip = moxaIntTable[card] + readb(moxaIntNdx[card]); 1626 ip = brd->intTable + readb(brd->intNdx);
1712 p = card * MAX_PORTS_PER_BOARD; 1627 p = card * MAX_PORTS_PER_BOARD;
1713 ports <<= 1; 1628 ports <<= 1;
1714 for (port = 0; port < ports; port += 2, p++) { 1629 for (port = 0; port < ports; port += 2, p++) {
1715 if ((temp = readw(ip + port)) != 0) { 1630 if ((temp = readw(ip + port)) != 0) {
1716 writew(0, ip + port); 1631 writew(0, ip + port);
1717 ofsAddr = moxaTableAddr[p]; 1632 ofsAddr = moxa_ports[p].tableAddr;
1718 if (temp & IntrTx) 1633 if (temp & IntrTx)
1719 writew(readw(ofsAddr + HostStat) & ~WakeupTx, ofsAddr + HostStat); 1634 writew(readw(ofsAddr + HostStat) & ~WakeupTx, ofsAddr + HostStat);
1720 if (temp & IntrBreak) { 1635 if (temp & IntrBreak) {
1721 moxaBreakCnt[p]++; 1636 moxa_ports[p].breakCnt++;
1722 } 1637 }
1723 if (temp & IntrLine) { 1638 if (temp & IntrLine) {
1724 if (readb(ofsAddr + FlagStat) & DCD_state) { 1639 if (readb(ofsAddr + FlagStat) & DCD_state) {
1725 if ((moxaDCDState[p] & DCD_oldstate) == 0) 1640 if ((moxa_ports[p].DCDState & DCD_oldstate) == 0)
1726 moxaDCDState[p] = (DCD_oldstate | 1641 moxa_ports[p].DCDState = (DCD_oldstate |
1727 DCD_changed); 1642 DCD_changed);
1728 } else { 1643 } else {
1729 if (moxaDCDState[p] & DCD_oldstate) 1644 if (moxa_ports[p].DCDState & DCD_oldstate)
1730 moxaDCDState[p] = DCD_changed; 1645 moxa_ports[p].DCDState = DCD_changed;
1731 } 1646 }
1732 } 1647 }
1733 } 1648 }
1734 } 1649 }
1735 writeb(0, moxaIntPend[card]); 1650 writeb(0, brd->intPend);
1736 } 1651 }
1737 if (moxaLowWaterChk) { 1652 if (moxaLowWaterChk) {
1738 p = card * MAX_PORTS_PER_BOARD; 1653 p = card * MAX_PORTS_PER_BOARD;
1739 for (port = 0; port < ports; port++, p++) { 1654 for (port = 0; port < ports; port++, p++) {
1740 if (moxaLowChkFlag[p]) { 1655 if (moxa_ports[p].lowChkFlag) {
1741 moxaLowChkFlag[p] = 0; 1656 moxa_ports[p].lowChkFlag = 0;
1742 ofsAddr = moxaTableAddr[p]; 1657 ofsAddr = moxa_ports[p].tableAddr;
1743 low_water_check(ofsAddr); 1658 low_water_check(ofsAddr);
1744 } 1659 }
1745 } 1660 }
@@ -1767,9 +1682,7 @@ int MoxaPortsOfCard(int cardno)
1767 * 2. MoxaPortEnable(int port); * 1682 * 2. MoxaPortEnable(int port); *
1768 * 3. MoxaPortDisable(int port); * 1683 * 3. MoxaPortDisable(int port); *
1769 * 4. MoxaPortGetMaxBaud(int port); * 1684 * 4. MoxaPortGetMaxBaud(int port); *
1770 * 5. MoxaPortGetCurBaud(int port); *
1771 * 6. MoxaPortSetBaud(int port, long baud); * 1685 * 6. MoxaPortSetBaud(int port, long baud); *
1772 * 7. MoxaPortSetMode(int port, int databit, int stopbit, int parity); *
1773 * 8. MoxaPortSetTermio(int port, unsigned char *termio); * 1686 * 8. MoxaPortSetTermio(int port, unsigned char *termio); *
1774 * 9. MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); * 1687 * 9. MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); *
1775 * 10. MoxaPortLineCtrl(int port, int dtrState, int rtsState); * 1688 * 10. MoxaPortLineCtrl(int port, int dtrState, int rtsState); *
@@ -1780,18 +1693,12 @@ int MoxaPortsOfCard(int cardno)
1780 * 15. MoxaPortFlushData(int port, int mode); * 1693 * 15. MoxaPortFlushData(int port, int mode); *
1781 * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); * 1694 * 16. MoxaPortWriteData(int port, unsigned char * buffer, int length); *
1782 * 17. MoxaPortReadData(int port, struct tty_struct *tty); * 1695 * 17. MoxaPortReadData(int port, struct tty_struct *tty); *
1783 * 18. MoxaPortTxBufSize(int port); *
1784 * 19. MoxaPortRxBufSize(int port); *
1785 * 20. MoxaPortTxQueue(int port); * 1696 * 20. MoxaPortTxQueue(int port); *
1786 * 21. MoxaPortTxFree(int port); * 1697 * 21. MoxaPortTxFree(int port); *
1787 * 22. MoxaPortRxQueue(int port); * 1698 * 22. MoxaPortRxQueue(int port); *
1788 * 23. MoxaPortRxFree(int port); *
1789 * 24. MoxaPortTxDisable(int port); * 1699 * 24. MoxaPortTxDisable(int port); *
1790 * 25. MoxaPortTxEnable(int port); * 1700 * 25. MoxaPortTxEnable(int port); *
1791 * 26. MoxaPortGetBrkCnt(int port); *
1792 * 27. MoxaPortResetBrkCnt(int port); * 1701 * 27. MoxaPortResetBrkCnt(int port); *
1793 * 28. MoxaPortSetXonXoff(int port, int xonValue, int xoffValue); *
1794 * 29. MoxaPortIsTxHold(int port); *
1795 * 30. MoxaPortSendBreak(int port, int ticks); * 1702 * 30. MoxaPortSendBreak(int port, int ticks); *
1796 *****************************************************************************/ 1703 *****************************************************************************/
1797/* 1704/*
@@ -1878,15 +1785,6 @@ int MoxaPortsOfCard(int cardno)
1878 * 38400/57600/115200 bps 1785 * 38400/57600/115200 bps
1879 * 1786 *
1880 * 1787 *
1881 * Function 9: Get the current baud rate of this port.
1882 * Syntax:
1883 * long MoxaPortGetCurBaud(int port);
1884 * int port : port number (0 - 127)
1885 *
1886 * return: 0 : this port is invalid
1887 * 50 - 115200 bps
1888 *
1889 *
1890 * Function 10: Setting baud rate of this port. 1788 * Function 10: Setting baud rate of this port.
1891 * Syntax: 1789 * Syntax:
1892 * long MoxaPortSetBaud(int port, long baud); 1790 * long MoxaPortSetBaud(int port, long baud);
@@ -1900,18 +1798,6 @@ int MoxaPortsOfCard(int cardno)
1900 * baud rate will be the maximun baud rate. 1798 * baud rate will be the maximun baud rate.
1901 * 1799 *
1902 * 1800 *
1903 * Function 11: Setting the data-bits/stop-bits/parity of this port
1904 * Syntax:
1905 * int MoxaPortSetMode(int port, int databits, int stopbits, int parity);
1906 * int port : port number (0 - 127)
1907 * int databits : data bits (8/7/6/5)
1908 * int stopbits : stop bits (2/1/0, 0 show 1.5 stop bits)
1909 int parity : parity (0:None,1:Odd,2:Even,3:Mark,4:Space)
1910 *
1911 * return: -1 : invalid parameter
1912 * 0 : setting O.K.
1913 *
1914 *
1915 * Function 12: Configure the port. 1801 * Function 12: Configure the port.
1916 * Syntax: 1802 * Syntax:
1917 * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud); 1803 * int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud);
@@ -2016,22 +1902,6 @@ int MoxaPortsOfCard(int cardno)
2016 * return: 0 - length : real read data length 1902 * return: 0 - length : real read data length
2017 * 1903 *
2018 * 1904 *
2019 * Function 22: Get the Tx buffer size of this port
2020 * Syntax:
2021 * int MoxaPortTxBufSize(int port);
2022 * int port : port number (0 - 127)
2023 *
2024 * return: .. : Tx buffer size
2025 *
2026 *
2027 * Function 23: Get the Rx buffer size of this port
2028 * Syntax:
2029 * int MoxaPortRxBufSize(int port);
2030 * int port : port number (0 - 127)
2031 *
2032 * return: .. : Rx buffer size
2033 *
2034 *
2035 * Function 24: Get the Tx buffer current queued data bytes 1905 * Function 24: Get the Tx buffer current queued data bytes
2036 * Syntax: 1906 * Syntax:
2037 * int MoxaPortTxQueue(int port); 1907 * int MoxaPortTxQueue(int port);
@@ -2056,14 +1926,6 @@ int MoxaPortsOfCard(int cardno)
2056 * return: .. : Rx buffer current queued data bytes 1926 * return: .. : Rx buffer current queued data bytes
2057 * 1927 *
2058 * 1928 *
2059 * Function 27: Get the Rx buffer current free space
2060 * Syntax:
2061 * int MoxaPortRxFree(int port);
2062 * int port : port number (0 - 127)
2063 *
2064 * return: .. : Rx buffer current free space
2065 *
2066 *
2067 * Function 28: Disable port data transmission. 1929 * Function 28: Disable port data transmission.
2068 * Syntax: 1930 * Syntax:
2069 * void MoxaPortTxDisable(int port); 1931 * void MoxaPortTxDisable(int port);
@@ -2076,14 +1938,6 @@ int MoxaPortsOfCard(int cardno)
2076 * int port : port number (0 - 127) 1938 * int port : port number (0 - 127)
2077 * 1939 *
2078 * 1940 *
2079 * Function 30: Get the received BREAK signal count.
2080 * Syntax:
2081 * int MoxaPortGetBrkCnt(int port);
2082 * int port : port number (0 - 127)
2083 *
2084 * return: 0 - .. : BREAK signal count
2085 *
2086 *
2087 * Function 31: Get the received BREAK signal count and reset it. 1941 * Function 31: Get the received BREAK signal count and reset it.
2088 * Syntax: 1942 * Syntax:
2089 * int MoxaPortResetBrkCnt(int port); 1943 * int MoxaPortResetBrkCnt(int port);
@@ -2092,25 +1946,6 @@ int MoxaPortsOfCard(int cardno)
2092 * return: 0 - .. : BREAK signal count 1946 * return: 0 - .. : BREAK signal count
2093 * 1947 *
2094 * 1948 *
2095 * Function 32: Set the S/W flow control new XON/XOFF value, default
2096 * XON is 0x11 & XOFF is 0x13.
2097 * Syntax:
2098 * void MoxaPortSetXonXoff(int port, int xonValue, int xoffValue);
2099 * int port : port number (0 - 127)
2100 * int xonValue : new XON value (0 - 255)
2101 * int xoffValue : new XOFF value (0 - 255)
2102 *
2103 *
2104 * Function 33: Check this port's transmission is hold by remote site
2105 * because the flow control.
2106 * Syntax:
2107 * int MoxaPortIsTxHold(int port);
2108 * int port : port number (0 - 127)
2109 *
2110 * return: 0 : normal
2111 * 1 : hold by remote site
2112 *
2113 *
2114 * Function 34: Send out a BREAK signal. 1949 * Function 34: Send out a BREAK signal.
2115 * Syntax: 1950 * Syntax:
2116 * void MoxaPortSendBreak(int port, int ms100); 1951 * void MoxaPortSendBreak(int port, int ms100);
@@ -2125,7 +1960,7 @@ int MoxaPortIsValid(int port)
2125 1960
2126 if (moxaCard == 0) 1961 if (moxaCard == 0)
2127 return (0); 1962 return (0);
2128 if (moxaChkPort[port] == 0) 1963 if (moxa_ports[port].chkPort == 0)
2129 return (0); 1964 return (0);
2130 return (1); 1965 return (1);
2131} 1966}
@@ -2136,9 +1971,9 @@ void MoxaPortEnable(int port)
2136 int MoxaPortLineStatus(int); 1971 int MoxaPortLineStatus(int);
2137 short lowwater = 512; 1972 short lowwater = 512;
2138 1973
2139 ofsAddr = moxaTableAddr[port]; 1974 ofsAddr = moxa_ports[port].tableAddr;
2140 writew(lowwater, ofsAddr + Low_water); 1975 writew(lowwater, ofsAddr + Low_water);
2141 moxaBreakCnt[port] = 0; 1976 moxa_ports[port].breakCnt = 0;
2142 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || 1977 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2143 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { 1978 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2144 moxafunc(ofsAddr, FC_SetBreakIrq, 0); 1979 moxafunc(ofsAddr, FC_SetBreakIrq, 0);
@@ -2155,7 +1990,7 @@ void MoxaPortEnable(int port)
2155 1990
2156void MoxaPortDisable(int port) 1991void MoxaPortDisable(int port)
2157{ 1992{
2158 void __iomem *ofsAddr = moxaTableAddr[port]; 1993 void __iomem *ofsAddr = moxa_ports[port].tableAddr;
2159 1994
2160 moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */ 1995 moxafunc(ofsAddr, FC_SetFlowCtl, 0); /* disable flow control */
2161 moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code); 1996 moxafunc(ofsAddr, FC_ClrLineIrq, Magic_code);
@@ -2181,7 +2016,7 @@ long MoxaPortSetBaud(int port, long baud)
2181 2016
2182 if ((baud < 50L) || ((max = MoxaPortGetMaxBaud(port)) == 0)) 2017 if ((baud < 50L) || ((max = MoxaPortGetMaxBaud(port)) == 0))
2183 return (0); 2018 return (0);
2184 ofsAddr = moxaTableAddr[port]; 2019 ofsAddr = moxa_ports[port].tableAddr;
2185 if (baud > max) 2020 if (baud > max)
2186 baud = max; 2021 baud = max;
2187 if (max == 38400L) 2022 if (max == 38400L)
@@ -2193,7 +2028,7 @@ long MoxaPortSetBaud(int port, long baud)
2193 val = clock / baud; 2028 val = clock / baud;
2194 moxafunc(ofsAddr, FC_SetBaud, val); 2029 moxafunc(ofsAddr, FC_SetBaud, val);
2195 baud = clock / val; 2030 baud = clock / val;
2196 moxaCurBaud[port] = baud; 2031 moxa_ports[port].curBaud = baud;
2197 return (baud); 2032 return (baud);
2198} 2033}
2199 2034
@@ -2203,9 +2038,9 @@ int MoxaPortSetTermio(int port, struct ktermios *termio, speed_t baud)
2203 tcflag_t cflag; 2038 tcflag_t cflag;
2204 tcflag_t mode = 0; 2039 tcflag_t mode = 0;
2205 2040
2206 if (moxaChkPort[port] == 0 || termio == 0) 2041 if (moxa_ports[port].chkPort == 0 || termio == 0)
2207 return (-1); 2042 return (-1);
2208 ofsAddr = moxaTableAddr[port]; 2043 ofsAddr = moxa_ports[port].tableAddr;
2209 cflag = termio->c_cflag; /* termio->c_cflag */ 2044 cflag = termio->c_cflag; /* termio->c_cflag */
2210 2045
2211 mode = termio->c_cflag & CSIZE; 2046 mode = termio->c_cflag & CSIZE;
@@ -2259,13 +2094,13 @@ int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState)
2259 if (!MoxaPortIsValid(port)) 2094 if (!MoxaPortIsValid(port))
2260 return (-1); 2095 return (-1);
2261 if (dtrState) { 2096 if (dtrState) {
2262 if (moxaLineCtrl[port] & DTR_ON) 2097 if (moxa_ports[port].lineCtrl & DTR_ON)
2263 *dtrState = 1; 2098 *dtrState = 1;
2264 else 2099 else
2265 *dtrState = 0; 2100 *dtrState = 0;
2266 } 2101 }
2267 if (rtsState) { 2102 if (rtsState) {
2268 if (moxaLineCtrl[port] & RTS_ON) 2103 if (moxa_ports[port].lineCtrl & RTS_ON)
2269 *rtsState = 1; 2104 *rtsState = 1;
2270 else 2105 else
2271 *rtsState = 0; 2106 *rtsState = 0;
@@ -2278,13 +2113,13 @@ void MoxaPortLineCtrl(int port, int dtr, int rts)
2278 void __iomem *ofsAddr; 2113 void __iomem *ofsAddr;
2279 int mode; 2114 int mode;
2280 2115
2281 ofsAddr = moxaTableAddr[port]; 2116 ofsAddr = moxa_ports[port].tableAddr;
2282 mode = 0; 2117 mode = 0;
2283 if (dtr) 2118 if (dtr)
2284 mode |= DTR_ON; 2119 mode |= DTR_ON;
2285 if (rts) 2120 if (rts)
2286 mode |= RTS_ON; 2121 mode |= RTS_ON;
2287 moxaLineCtrl[port] = mode; 2122 moxa_ports[port].lineCtrl = mode;
2288 moxafunc(ofsAddr, FC_LineControl, mode); 2123 moxafunc(ofsAddr, FC_LineControl, mode);
2289} 2124}
2290 2125
@@ -2293,7 +2128,7 @@ void MoxaPortFlowCtrl(int port, int rts, int cts, int txflow, int rxflow, int tx
2293 void __iomem *ofsAddr; 2128 void __iomem *ofsAddr;
2294 int mode; 2129 int mode;
2295 2130
2296 ofsAddr = moxaTableAddr[port]; 2131 ofsAddr = moxa_ports[port].tableAddr;
2297 mode = 0; 2132 mode = 0;
2298 if (rts) 2133 if (rts)
2299 mode |= RTS_FlowCtl; 2134 mode |= RTS_FlowCtl;
@@ -2313,7 +2148,7 @@ int MoxaPortLineStatus(int port)
2313 void __iomem *ofsAddr; 2148 void __iomem *ofsAddr;
2314 int val; 2149 int val;
2315 2150
2316 ofsAddr = moxaTableAddr[port]; 2151 ofsAddr = moxa_ports[port].tableAddr;
2317 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) || 2152 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
2318 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) { 2153 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
2319 moxafunc(ofsAddr, FC_LineStatus, 0); 2154 moxafunc(ofsAddr, FC_LineStatus, 0);
@@ -2324,11 +2159,11 @@ int MoxaPortLineStatus(int port)
2324 val &= 0x0B; 2159 val &= 0x0B;
2325 if (val & 8) { 2160 if (val & 8) {
2326 val |= 4; 2161 val |= 4;
2327 if ((moxaDCDState[port] & DCD_oldstate) == 0) 2162 if ((moxa_ports[port].DCDState & DCD_oldstate) == 0)
2328 moxaDCDState[port] = (DCD_oldstate | DCD_changed); 2163 moxa_ports[port].DCDState = (DCD_oldstate | DCD_changed);
2329 } else { 2164 } else {
2330 if (moxaDCDState[port] & DCD_oldstate) 2165 if (moxa_ports[port].DCDState & DCD_oldstate)
2331 moxaDCDState[port] = DCD_changed; 2166 moxa_ports[port].DCDState = DCD_changed;
2332 } 2167 }
2333 val &= 7; 2168 val &= 7;
2334 return (val); 2169 return (val);
@@ -2338,10 +2173,10 @@ int MoxaPortDCDChange(int port)
2338{ 2173{
2339 int n; 2174 int n;
2340 2175
2341 if (moxaChkPort[port] == 0) 2176 if (moxa_ports[port].chkPort == 0)
2342 return (0); 2177 return (0);
2343 n = moxaDCDState[port]; 2178 n = moxa_ports[port].DCDState;
2344 moxaDCDState[port] &= ~DCD_changed; 2179 moxa_ports[port].DCDState &= ~DCD_changed;
2345 n &= DCD_changed; 2180 n &= DCD_changed;
2346 return (n); 2181 return (n);
2347} 2182}
@@ -2350,32 +2185,15 @@ int MoxaPortDCDON(int port)
2350{ 2185{
2351 int n; 2186 int n;
2352 2187
2353 if (moxaChkPort[port] == 0) 2188 if (moxa_ports[port].chkPort == 0)
2354 return (0); 2189 return (0);
2355 if (moxaDCDState[port] & DCD_oldstate) 2190 if (moxa_ports[port].DCDState & DCD_oldstate)
2356 n = 1; 2191 n = 1;
2357 else 2192 else
2358 n = 0; 2193 n = 0;
2359 return (n); 2194 return (n);
2360} 2195}
2361 2196
2362
2363/*
2364 int MoxaDumpMem(int port, unsigned char * buffer, int len)
2365 {
2366 int i;
2367 unsigned long baseAddr,ofsAddr,ofs;
2368
2369 baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD];
2370 ofs = baseAddr + DynPage_addr + pageofs;
2371 if (len > 0x2000L)
2372 len = 0x2000L;
2373 for (i = 0; i < len; i++)
2374 buffer[i] = readb(ofs+i);
2375 }
2376 */
2377
2378
2379int MoxaPortWriteData(int port, unsigned char * buffer, int len) 2197int MoxaPortWriteData(int port, unsigned char * buffer, int len)
2380{ 2198{
2381 int c, total, i; 2199 int c, total, i;
@@ -2385,8 +2203,8 @@ int MoxaPortWriteData(int port, unsigned char * buffer, int len)
2385 ushort pageno, pageofs, bufhead; 2203 ushort pageno, pageofs, bufhead;
2386 void __iomem *baseAddr, *ofsAddr, *ofs; 2204 void __iomem *baseAddr, *ofsAddr, *ofs;
2387 2205
2388 ofsAddr = moxaTableAddr[port]; 2206 ofsAddr = moxa_ports[port].tableAddr;
2389 baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD]; 2207 baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem;
2390 tx_mask = readw(ofsAddr + TX_mask); 2208 tx_mask = readw(ofsAddr + TX_mask);
2391 spage = readw(ofsAddr + Page_txb); 2209 spage = readw(ofsAddr + Page_txb);
2392 epage = readw(ofsAddr + EndPage_txb); 2210 epage = readw(ofsAddr + EndPage_txb);
@@ -2448,8 +2266,8 @@ int MoxaPortReadData(int port, struct tty_struct *tty)
2448 ushort pageno, bufhead; 2266 ushort pageno, bufhead;
2449 void __iomem *baseAddr, *ofsAddr, *ofs; 2267 void __iomem *baseAddr, *ofsAddr, *ofs;
2450 2268
2451 ofsAddr = moxaTableAddr[port]; 2269 ofsAddr = moxa_ports[port].tableAddr;
2452 baseAddr = moxaBaseAddr[port / MAX_PORTS_PER_BOARD]; 2270 baseAddr = moxa_boards[port / MAX_PORTS_PER_BOARD].basemem;
2453 head = readw(ofsAddr + RXrptr); 2271 head = readw(ofsAddr + RXrptr);
2454 tail = readw(ofsAddr + RXwptr); 2272 tail = readw(ofsAddr + RXwptr);
2455 rx_mask = readw(ofsAddr + RX_mask); 2273 rx_mask = readw(ofsAddr + RX_mask);
@@ -2504,7 +2322,7 @@ int MoxaPortReadData(int port, struct tty_struct *tty)
2504 } 2322 }
2505 if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) { 2323 if ((readb(ofsAddr + FlagStat) & Xoff_state) && (remain < LowWater)) {
2506 moxaLowWaterChk = 1; 2324 moxaLowWaterChk = 1;
2507 moxaLowChkFlag[port] = 1; 2325 moxa_ports[port].lowChkFlag = 1;
2508 } 2326 }
2509 return (total); 2327 return (total);
2510} 2328}
@@ -2516,7 +2334,7 @@ int MoxaPortTxQueue(int port)
2516 ushort rptr, wptr, mask; 2334 ushort rptr, wptr, mask;
2517 int len; 2335 int len;
2518 2336
2519 ofsAddr = moxaTableAddr[port]; 2337 ofsAddr = moxa_ports[port].tableAddr;
2520 rptr = readw(ofsAddr + TXrptr); 2338 rptr = readw(ofsAddr + TXrptr);
2521 wptr = readw(ofsAddr + TXwptr); 2339 wptr = readw(ofsAddr + TXwptr);
2522 mask = readw(ofsAddr + TX_mask); 2340 mask = readw(ofsAddr + TX_mask);
@@ -2530,7 +2348,7 @@ int MoxaPortTxFree(int port)
2530 ushort rptr, wptr, mask; 2348 ushort rptr, wptr, mask;
2531 int len; 2349 int len;
2532 2350
2533 ofsAddr = moxaTableAddr[port]; 2351 ofsAddr = moxa_ports[port].tableAddr;
2534 rptr = readw(ofsAddr + TXrptr); 2352 rptr = readw(ofsAddr + TXrptr);
2535 wptr = readw(ofsAddr + TXwptr); 2353 wptr = readw(ofsAddr + TXwptr);
2536 mask = readw(ofsAddr + TX_mask); 2354 mask = readw(ofsAddr + TX_mask);
@@ -2544,7 +2362,7 @@ int MoxaPortRxQueue(int port)
2544 ushort rptr, wptr, mask; 2362 ushort rptr, wptr, mask;
2545 int len; 2363 int len;
2546 2364
2547 ofsAddr = moxaTableAddr[port]; 2365 ofsAddr = moxa_ports[port].tableAddr;
2548 rptr = readw(ofsAddr + RXrptr); 2366 rptr = readw(ofsAddr + RXrptr);
2549 wptr = readw(ofsAddr + RXwptr); 2367 wptr = readw(ofsAddr + RXwptr);
2550 mask = readw(ofsAddr + RX_mask); 2368 mask = readw(ofsAddr + RX_mask);
@@ -2557,7 +2375,7 @@ void MoxaPortTxDisable(int port)
2557{ 2375{
2558 void __iomem *ofsAddr; 2376 void __iomem *ofsAddr;
2559 2377
2560 ofsAddr = moxaTableAddr[port]; 2378 ofsAddr = moxa_ports[port].tableAddr;
2561 moxafunc(ofsAddr, FC_SetXoffState, Magic_code); 2379 moxafunc(ofsAddr, FC_SetXoffState, Magic_code);
2562} 2380}
2563 2381
@@ -2565,7 +2383,7 @@ void MoxaPortTxEnable(int port)
2565{ 2383{
2566 void __iomem *ofsAddr; 2384 void __iomem *ofsAddr;
2567 2385
2568 ofsAddr = moxaTableAddr[port]; 2386 ofsAddr = moxa_ports[port].tableAddr;
2569 moxafunc(ofsAddr, FC_SetXonState, Magic_code); 2387 moxafunc(ofsAddr, FC_SetXonState, Magic_code);
2570} 2388}
2571 2389
@@ -2573,8 +2391,8 @@ void MoxaPortTxEnable(int port)
2573int MoxaPortResetBrkCnt(int port) 2391int MoxaPortResetBrkCnt(int port)
2574{ 2392{
2575 ushort cnt; 2393 ushort cnt;
2576 cnt = moxaBreakCnt[port]; 2394 cnt = moxa_ports[port].breakCnt;
2577 moxaBreakCnt[port] = 0; 2395 moxa_ports[port].breakCnt = 0;
2578 return (cnt); 2396 return (cnt);
2579} 2397}
2580 2398
@@ -2583,7 +2401,7 @@ void MoxaPortSendBreak(int port, int ms100)
2583{ 2401{
2584 void __iomem *ofsAddr; 2402 void __iomem *ofsAddr;
2585 2403
2586 ofsAddr = moxaTableAddr[port]; 2404 ofsAddr = moxa_ports[port].tableAddr;
2587 if (ms100) { 2405 if (ms100) {
2588 moxafunc(ofsAddr, FC_SendBreak, Magic_code); 2406 moxafunc(ofsAddr, FC_SendBreak, Magic_code);
2589 moxadelay(ms100 * (HZ / 10)); 2407 moxadelay(ms100 * (HZ / 10));
@@ -2594,7 +2412,7 @@ void MoxaPortSendBreak(int port, int ms100)
2594 moxafunc(ofsAddr, FC_StopBreak, Magic_code); 2412 moxafunc(ofsAddr, FC_StopBreak, Magic_code);
2595} 2413}
2596 2414
2597static int moxa_get_serial_info(struct moxa_str *info, 2415static int moxa_get_serial_info(struct moxa_port *info,
2598 struct serial_struct __user *retinfo) 2416 struct serial_struct __user *retinfo)
2599{ 2417{
2600 struct serial_struct tmp; 2418 struct serial_struct tmp;
@@ -2616,7 +2434,7 @@ static int moxa_get_serial_info(struct moxa_str *info,
2616} 2434}
2617 2435
2618 2436
2619static int moxa_set_serial_info(struct moxa_str *info, 2437static int moxa_set_serial_info(struct moxa_port *info,
2620 struct serial_struct __user *new_info) 2438 struct serial_struct __user *new_info)
2621{ 2439{
2622 struct serial_struct new_serial; 2440 struct serial_struct new_serial;
@@ -2713,7 +2531,7 @@ static int moxaloadbios(int cardno, unsigned char __user *tmp, int len)
2713 2531
2714 if(copy_from_user(moxaBuff, tmp, len)) 2532 if(copy_from_user(moxaBuff, tmp, len))
2715 return -EFAULT; 2533 return -EFAULT;
2716 baseAddr = moxaBaseAddr[cardno]; 2534 baseAddr = moxa_boards[cardno].basemem;
2717 writeb(HW_reset, baseAddr + Control_reg); /* reset */ 2535 writeb(HW_reset, baseAddr + Control_reg); /* reset */
2718 moxadelay(1); /* delay 10 ms */ 2536 moxadelay(1); /* delay 10 ms */
2719 for (i = 0; i < 4096; i++) 2537 for (i = 0; i < 4096; i++)
@@ -2729,7 +2547,7 @@ static int moxafindcard(int cardno)
2729 void __iomem *baseAddr; 2547 void __iomem *baseAddr;
2730 ushort tmp; 2548 ushort tmp;
2731 2549
2732 baseAddr = moxaBaseAddr[cardno]; 2550 baseAddr = moxa_boards[cardno].basemem;
2733 switch (moxa_boards[cardno].boardType) { 2551 switch (moxa_boards[cardno].boardType) {
2734 case MOXA_BOARD_C218_ISA: 2552 case MOXA_BOARD_C218_ISA:
2735 case MOXA_BOARD_C218_PCI: 2553 case MOXA_BOARD_C218_PCI:
@@ -2762,7 +2580,7 @@ static int moxaload320b(int cardno, unsigned char __user *tmp, int len)
2762 return -EINVAL; 2580 return -EINVAL;
2763 if(copy_from_user(moxaBuff, tmp, len)) 2581 if(copy_from_user(moxaBuff, tmp, len))
2764 return -EFAULT; 2582 return -EFAULT;
2765 baseAddr = moxaBaseAddr[cardno]; 2583 baseAddr = moxa_boards[cardno].basemem;
2766 writew(len - 7168 - 2, baseAddr + C320bapi_len); 2584 writew(len - 7168 - 2, baseAddr + C320bapi_len);
2767 writeb(1, baseAddr + Control_reg); /* Select Page 1 */ 2585 writeb(1, baseAddr + Control_reg); /* Select Page 1 */
2768 for (i = 0; i < 7168; i++) 2586 for (i = 0; i < 7168; i++)
@@ -2780,7 +2598,7 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2780 2598
2781 if(copy_from_user(moxaBuff, tmp, len)) 2599 if(copy_from_user(moxaBuff, tmp, len))
2782 return -EFAULT; 2600 return -EFAULT;
2783 baseAddr = moxaBaseAddr[cardno]; 2601 baseAddr = moxa_boards[cardno].basemem;
2784 switch (moxa_boards[cardno].boardType) { 2602 switch (moxa_boards[cardno].boardType) {
2785 case MOXA_BOARD_C218_ISA: 2603 case MOXA_BOARD_C218_ISA:
2786 case MOXA_BOARD_C218_PCI: 2604 case MOXA_BOARD_C218_PCI:
@@ -2790,11 +2608,13 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2790 return (retval); 2608 return (retval);
2791 port = cardno * MAX_PORTS_PER_BOARD; 2609 port = cardno * MAX_PORTS_PER_BOARD;
2792 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) { 2610 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) {
2793 moxaChkPort[port] = 1; 2611 struct moxa_port *p = &moxa_ports[port];
2794 moxaCurBaud[port] = 9600L; 2612
2795 moxaDCDState[port] = 0; 2613 p->chkPort = 1;
2796 moxaTableAddr[port] = baseAddr + Extern_table + Extern_size * i; 2614 p->curBaud = 9600L;
2797 ofsAddr = moxaTableAddr[port]; 2615 p->DCDState = 0;
2616 p->tableAddr = baseAddr + Extern_table + Extern_size * i;
2617 ofsAddr = p->tableAddr;
2798 writew(C218rx_mask, ofsAddr + RX_mask); 2618 writew(C218rx_mask, ofsAddr + RX_mask);
2799 writew(C218tx_mask, ofsAddr + TX_mask); 2619 writew(C218tx_mask, ofsAddr + TX_mask);
2800 writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb); 2620 writew(C218rx_spage + i * C218buf_pageno, ofsAddr + Page_rxb);
@@ -2812,11 +2632,13 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2812 return (retval); 2632 return (retval);
2813 port = cardno * MAX_PORTS_PER_BOARD; 2633 port = cardno * MAX_PORTS_PER_BOARD;
2814 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) { 2634 for (i = 0; i < moxa_boards[cardno].numPorts; i++, port++) {
2815 moxaChkPort[port] = 1; 2635 struct moxa_port *p = &moxa_ports[port];
2816 moxaCurBaud[port] = 9600L; 2636
2817 moxaDCDState[port] = 0; 2637 p->chkPort = 1;
2818 moxaTableAddr[port] = baseAddr + Extern_table + Extern_size * i; 2638 p->curBaud = 9600L;
2819 ofsAddr = moxaTableAddr[port]; 2639 p->DCDState = 0;
2640 p->tableAddr = baseAddr + Extern_table + Extern_size * i;
2641 ofsAddr = p->tableAddr;
2820 if (moxa_boards[cardno].numPorts == 8) { 2642 if (moxa_boards[cardno].numPorts == 8) {
2821 writew(C320p8rx_mask, ofsAddr + RX_mask); 2643 writew(C320p8rx_mask, ofsAddr + RX_mask);
2822 writew(C320p8tx_mask, ofsAddr + TX_mask); 2644 writew(C320p8tx_mask, ofsAddr + TX_mask);
@@ -2852,7 +2674,7 @@ static int moxaloadcode(int cardno, unsigned char __user *tmp, int len)
2852 } 2674 }
2853 break; 2675 break;
2854 } 2676 }
2855 loadstat[cardno] = 1; 2677 moxa_boards[cardno].loadstat = 1;
2856 return (0); 2678 return (0);
2857} 2679}
2858 2680
@@ -2926,9 +2748,9 @@ static int moxaloadc218(int cardno, void __iomem *baseAddr, int len)
2926 return (-1); 2748 return (-1);
2927 } 2749 }
2928 moxaCard = 1; 2750 moxaCard = 1;
2929 moxaIntNdx[cardno] = baseAddr + IRQindex; 2751 moxa_boards[cardno].intNdx = baseAddr + IRQindex;
2930 moxaIntPend[cardno] = baseAddr + IRQpending; 2752 moxa_boards[cardno].intPend = baseAddr + IRQpending;
2931 moxaIntTable[cardno] = baseAddr + IRQtable; 2753 moxa_boards[cardno].intTable = baseAddr + IRQtable;
2932 return (0); 2754 return (0);
2933} 2755}
2934 2756
@@ -3021,25 +2843,15 @@ static int moxaloadc320(int cardno, void __iomem *baseAddr, int len, int *numPor
3021 if (readw(baseAddr + Magic_no) != Magic_code) 2843 if (readw(baseAddr + Magic_no) != Magic_code)
3022 return (-102); 2844 return (-102);
3023 moxaCard = 1; 2845 moxaCard = 1;
3024 moxaIntNdx[cardno] = baseAddr + IRQindex; 2846 moxa_boards[cardno].intNdx = baseAddr + IRQindex;
3025 moxaIntPend[cardno] = baseAddr + IRQpending; 2847 moxa_boards[cardno].intPend = baseAddr + IRQpending;
3026 moxaIntTable[cardno] = baseAddr + IRQtable; 2848 moxa_boards[cardno].intTable = baseAddr + IRQtable;
3027 return (0); 2849 return (0);
3028} 2850}
3029 2851
3030#if 0
3031long MoxaPortGetCurBaud(int port)
3032{
3033
3034 if (moxaChkPort[port] == 0)
3035 return (0);
3036 return (moxaCurBaud[port]);
3037}
3038#endif /* 0 */
3039
3040static void MoxaSetFifo(int port, int enable) 2852static void MoxaSetFifo(int port, int enable)
3041{ 2853{
3042 void __iomem *ofsAddr = moxaTableAddr[port]; 2854 void __iomem *ofsAddr = moxa_ports[port].tableAddr;
3043 2855
3044 if (!enable) { 2856 if (!enable) {
3045 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0); 2857 moxafunc(ofsAddr, FC_SetRxFIFOTrig, 0);
@@ -3049,132 +2861,3 @@ static void MoxaSetFifo(int port, int enable)
3049 moxafunc(ofsAddr, FC_SetTxFIFOCnt, 16); 2861 moxafunc(ofsAddr, FC_SetTxFIFOCnt, 16);
3050 } 2862 }
3051} 2863}
3052
3053#if 0
3054int MoxaPortSetMode(int port, int databits, int stopbits, int parity)
3055{
3056 void __iomem *ofsAddr;
3057 int val;
3058
3059 val = 0;
3060 switch (databits) {
3061 case 5:
3062 val |= 0;
3063 break;
3064 case 6:
3065 val |= 1;
3066 break;
3067 case 7:
3068 val |= 2;
3069 break;
3070 case 8:
3071 val |= 3;
3072 break;
3073 default:
3074 return (-1);
3075 }
3076 switch (stopbits) {
3077 case 0:
3078 val |= 0;
3079 break; /* stop bits 1.5 */
3080 case 1:
3081 val |= 0;
3082 break;
3083 case 2:
3084 val |= 4;
3085 break;
3086 default:
3087 return (-1);
3088 }
3089 switch (parity) {
3090 case 0:
3091 val |= 0x00;
3092 break; /* None */
3093 case 1:
3094 val |= 0x08;
3095 break; /* Odd */
3096 case 2:
3097 val |= 0x18;
3098 break; /* Even */
3099 case 3:
3100 val |= 0x28;
3101 break; /* Mark */
3102 case 4:
3103 val |= 0x38;
3104 break; /* Space */
3105 default:
3106 return (-1);
3107 }
3108 ofsAddr = moxaTableAddr[port];
3109 moxafunc(ofsAddr, FC_SetMode, val);
3110 return (0);
3111}
3112
3113int MoxaPortTxBufSize(int port)
3114{
3115 void __iomem *ofsAddr;
3116 int size;
3117
3118 ofsAddr = moxaTableAddr[port];
3119 size = readw(ofsAddr + TX_mask);
3120 return (size);
3121}
3122
3123int MoxaPortRxBufSize(int port)
3124{
3125 void __iomem *ofsAddr;
3126 int size;
3127
3128 ofsAddr = moxaTableAddr[port];
3129 size = readw(ofsAddr + RX_mask);
3130 return (size);
3131}
3132
3133int MoxaPortRxFree(int port)
3134{
3135 void __iomem *ofsAddr;
3136 ushort rptr, wptr, mask;
3137 int len;
3138
3139 ofsAddr = moxaTableAddr[port];
3140 rptr = readw(ofsAddr + RXrptr);
3141 wptr = readw(ofsAddr + RXwptr);
3142 mask = readw(ofsAddr + RX_mask);
3143 len = mask - ((wptr - rptr) & mask);
3144 return (len);
3145}
3146int MoxaPortGetBrkCnt(int port)
3147{
3148 return (moxaBreakCnt[port]);
3149}
3150
3151void MoxaPortSetXonXoff(int port, int xonValue, int xoffValue)
3152{
3153 void __iomem *ofsAddr;
3154
3155 ofsAddr = moxaTableAddr[port];
3156 writew(xonValue, ofsAddr + FuncArg);
3157 writew(xoffValue, ofsAddr + FuncArg1);
3158 writew(FC_SetXonXoff, ofsAddr + FuncCode);
3159 wait_finish(ofsAddr);
3160}
3161
3162int MoxaPortIsTxHold(int port)
3163{
3164 void __iomem *ofsAddr;
3165 int val;
3166
3167 ofsAddr = moxaTableAddr[port];
3168 if ((moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_ISA) ||
3169 (moxa_boards[port / MAX_PORTS_PER_BOARD].boardType == MOXA_BOARD_C320_PCI)) {
3170 moxafunc(ofsAddr, FC_GetCCSR, 0);
3171 val = readw(ofsAddr + FuncArg);
3172 if (val & 0x04)
3173 return (1);
3174 } else {
3175 if (readw(ofsAddr + FlagStat) & Tx_flowOff)
3176 return (1);
3177 }
3178 return (0);
3179}
3180#endif
diff --git a/drivers/char/mspec.c b/drivers/char/mspec.c
index 235e8922611..7ac30612068 100644
--- a/drivers/char/mspec.c
+++ b/drivers/char/mspec.c
@@ -291,7 +291,7 @@ uncached_mmap(struct file *file, struct vm_area_struct *vma)
291 return mspec_mmap(file, vma, MSPEC_UNCACHED); 291 return mspec_mmap(file, vma, MSPEC_UNCACHED);
292} 292}
293 293
294static struct file_operations fetchop_fops = { 294static const struct file_operations fetchop_fops = {
295 .owner = THIS_MODULE, 295 .owner = THIS_MODULE,
296 .mmap = fetchop_mmap 296 .mmap = fetchop_mmap
297}; 297};
@@ -302,7 +302,7 @@ static struct miscdevice fetchop_miscdev = {
302 .fops = &fetchop_fops 302 .fops = &fetchop_fops
303}; 303};
304 304
305static struct file_operations cached_fops = { 305static const struct file_operations cached_fops = {
306 .owner = THIS_MODULE, 306 .owner = THIS_MODULE,
307 .mmap = cached_mmap 307 .mmap = cached_mmap
308}; 308};
@@ -313,7 +313,7 @@ static struct miscdevice cached_miscdev = {
313 .fops = &cached_fops 313 .fops = &cached_fops
314}; 314};
315 315
316static struct file_operations uncached_fops = { 316static const struct file_operations uncached_fops = {
317 .owner = THIS_MODULE, 317 .owner = THIS_MODULE,
318 .mmap = uncached_mmap 318 .mmap = uncached_mmap
319}; 319};
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 83f604b1929..a61fb6da5d0 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -321,8 +321,6 @@ struct mxser_struct {
321 unsigned long event; 321 unsigned long event;
322 int count; /* # of fd on device */ 322 int count; /* # of fd on device */
323 int blocked_open; /* # of blocked opens */ 323 int blocked_open; /* # of blocked opens */
324 long session; /* Session of opening process */
325 long pgrp; /* pgrp of opening process */
326 unsigned char *xmit_buf; 324 unsigned char *xmit_buf;
327 int xmit_head; 325 int xmit_head;
328 int xmit_tail; 326 int xmit_tail;
@@ -1001,15 +999,12 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
1001 mxser_change_speed(info, NULL); 999 mxser_change_speed(info, NULL);
1002 } 1000 }
1003 1001
1004 info->session = process_session(current);
1005 info->pgrp = process_group(current);
1006
1007 /* 1002 /*
1008 status = mxser_get_msr(info->base, 0, info->port); 1003 status = mxser_get_msr(info->base, 0, info->port);
1009 mxser_check_modem_status(info, status); 1004 mxser_check_modem_status(info, status);
1010 */ 1005 */
1011 1006
1012/* unmark here for very high baud rate (ex. 921600 bps) used */ 1007 /* unmark here for very high baud rate (ex. 921600 bps) used */
1013 tty->low_latency = 1; 1008 tty->low_latency = 1;
1014 return 0; 1009 return 0;
1015} 1010}
@@ -1254,9 +1249,7 @@ static void mxser_flush_buffer(struct tty_struct *tty)
1254 spin_unlock_irqrestore(&info->slock, flags); 1249 spin_unlock_irqrestore(&info->slock, flags);
1255 /* above added by shinhay */ 1250 /* above added by shinhay */
1256 1251
1257 wake_up_interruptible(&tty->write_wait); 1252 tty_wakeup(tty);
1258 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && tty->ldisc.write_wakeup)
1259 (tty->ldisc.write_wakeup) (tty);
1260} 1253}
1261 1254
1262static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 1255static int mxser_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
diff --git a/drivers/char/mxser.h b/drivers/char/mxser.h
index 7e188a4d602..9fe28497eae 100644
--- a/drivers/char/mxser.h
+++ b/drivers/char/mxser.h
@@ -439,12 +439,4 @@
439 439
440#define READ_MOXA_MUST_GDL(baseio) inb((baseio)+MOXA_MUST_GDL_REGISTER) 440#define READ_MOXA_MUST_GDL(baseio) inb((baseio)+MOXA_MUST_GDL_REGISTER)
441 441
442
443#ifndef INIT_WORK
444#define INIT_WORK(_work, _func, _data){ \
445 _data->tqueue.routine = _func;\
446 _data->tqueue.data = _data;\
447 }
448#endif
449
450#endif 442#endif
diff --git a/drivers/char/mxser_new.c b/drivers/char/mxser_new.c
index 1bb030b3a51..9af07e4999d 100644
--- a/drivers/char/mxser_new.c
+++ b/drivers/char/mxser_new.c
@@ -49,22 +49,25 @@
49 49
50#include "mxser_new.h" 50#include "mxser_new.h"
51 51
52#define MXSER_VERSION "2.0" 52#define MXSER_VERSION "2.0.1" /* 1.9.15 */
53#define MXSERMAJOR 174 53#define MXSERMAJOR 174
54#define MXSERCUMAJOR 175 54#define MXSERCUMAJOR 175
55 55
56#define MXSER_EVENT_TXLOW 1
57
58#define MXSER_BOARDS 4 /* Max. boards */ 56#define MXSER_BOARDS 4 /* Max. boards */
59#define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */ 57#define MXSER_PORTS_PER_BOARD 8 /* Max. ports per board */
60#define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD) 58#define MXSER_PORTS (MXSER_BOARDS * MXSER_PORTS_PER_BOARD)
61#define MXSER_ISR_PASS_LIMIT 99999L 59#define MXSER_ISR_PASS_LIMIT 100
62 60
63#define MXSER_ERR_IOADDR -1 61#define MXSER_ERR_IOADDR -1
64#define MXSER_ERR_IRQ -2 62#define MXSER_ERR_IRQ -2
65#define MXSER_ERR_IRQ_CONFLIT -3 63#define MXSER_ERR_IRQ_CONFLIT -3
66#define MXSER_ERR_VECTOR -4 64#define MXSER_ERR_VECTOR -4
67 65
66/*CheckIsMoxaMust return value*/
67#define MOXA_OTHER_UART 0x00
68#define MOXA_MUST_MU150_HWID 0x01
69#define MOXA_MUST_MU860_HWID 0x02
70
68#define WAKEUP_CHARS 256 71#define WAKEUP_CHARS 256
69 72
70#define UART_MCR_AFE 0x20 73#define UART_MCR_AFE 0x20
@@ -176,6 +179,18 @@ static struct pci_device_id mxser_pcibrds[] = {
176}; 179};
177MODULE_DEVICE_TABLE(pci, mxser_pcibrds); 180MODULE_DEVICE_TABLE(pci, mxser_pcibrds);
178 181
182static int mxvar_baud_table[] = {
183 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400,
184 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
185};
186static unsigned int mxvar_baud_table1[] = {
187 0, B50, B75, B110, B134, B150, B200, B300, B600, B1200, B1800, B2400,
188 B4800, B9600, B19200, B38400, B57600, B115200, B230400, B460800, B921600
189};
190#define BAUD_TABLE_NO ARRAY_SIZE(mxvar_baud_table)
191
192#define B_SPEC B2000000
193
179static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 }; 194static int ioaddr[MXSER_BOARDS] = { 0, 0, 0, 0 };
180static int ttymajor = MXSERMAJOR; 195static int ttymajor = MXSERMAJOR;
181static int calloutmajor = MXSERCUMAJOR; 196static int calloutmajor = MXSERCUMAJOR;
@@ -237,8 +252,7 @@ struct mxser_port {
237 long realbaud; 252 long realbaud;
238 int type; /* UART type */ 253 int type; /* UART type */
239 int flags; /* defined in tty.h */ 254 int flags; /* defined in tty.h */
240 long session; /* Session of opening process */ 255 int speed;
241 long pgrp; /* pgrp of opening process */
242 256
243 int x_char; /* xon/xoff character */ 257 int x_char; /* xon/xoff character */
244 int IER; /* Interrupt Enable Register */ 258 int IER; /* Interrupt Enable Register */
@@ -267,14 +281,11 @@ struct mxser_port {
267 int xmit_cnt; 281 int xmit_cnt;
268 282
269 struct ktermios normal_termios; 283 struct ktermios normal_termios;
270 struct ktermios callout_termios;
271 284
272 struct mxser_mon mon_data; 285 struct mxser_mon mon_data;
273 286
274 spinlock_t slock; 287 spinlock_t slock;
275 struct work_struct tqueue;
276 wait_queue_head_t open_wait; 288 wait_queue_head_t open_wait;
277 wait_queue_head_t close_wait;
278 wait_queue_head_t delta_msr_wait; 289 wait_queue_head_t delta_msr_wait;
279}; 290};
280 291
@@ -313,10 +324,9 @@ static int mxvar_diagflag;
313static unsigned char mxser_msr[MXSER_PORTS + 1]; 324static unsigned char mxser_msr[MXSER_PORTS + 1];
314static struct mxser_mon_ext mon_data_ext; 325static struct mxser_mon_ext mon_data_ext;
315static int mxser_set_baud_method[MXSER_PORTS + 1]; 326static int mxser_set_baud_method[MXSER_PORTS + 1];
316static spinlock_t gm_lock;
317 327
318#ifdef CONFIG_PCI 328#ifdef CONFIG_PCI
319static int CheckIsMoxaMust(int io) 329static int __devinit CheckIsMoxaMust(int io)
320{ 330{
321 u8 oldmcr, hwid; 331 u8 oldmcr, hwid;
322 int i; 332 int i;
@@ -360,15 +370,6 @@ static void process_txrx_fifo(struct mxser_port *info)
360 } 370 }
361} 371}
362 372
363static void mxser_do_softint(struct work_struct *work)
364{
365 struct mxser_port *info = container_of(work, struct mxser_port, tqueue);
366 struct tty_struct *tty = info->tty;
367
368 if (test_and_clear_bit(MXSER_EVENT_TXLOW, &info->event))
369 tty_wakeup(tty);
370}
371
372static unsigned char mxser_get_msr(int baseaddr, int mode, int port) 373static unsigned char mxser_get_msr(int baseaddr, int mode, int port)
373{ 374{
374 unsigned char status = 0; 375 unsigned char status = 0;
@@ -456,10 +457,10 @@ static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp,
456 457
457static int mxser_set_baud(struct mxser_port *info, long newspd) 458static int mxser_set_baud(struct mxser_port *info, long newspd)
458{ 459{
460 unsigned int i;
459 int quot = 0; 461 int quot = 0;
460 unsigned char cval; 462 unsigned char cval;
461 int ret = 0; 463 int ret = 0;
462 unsigned long flags;
463 464
464 if (!info->tty || !info->tty->termios) 465 if (!info->tty || !info->tty->termios)
465 return ret; 466 return ret;
@@ -471,29 +472,34 @@ static int mxser_set_baud(struct mxser_port *info, long newspd)
471 return 0; 472 return 0;
472 473
473 info->realbaud = newspd; 474 info->realbaud = newspd;
474 if (newspd == 134) { 475 for (i = 0; i < BAUD_TABLE_NO; i++)
475 quot = (2 * info->baud_base / 269); 476 if (newspd == mxvar_baud_table[i])
476 } else if (newspd) { 477 break;
477 quot = info->baud_base / newspd; 478 if (i == BAUD_TABLE_NO) {
478 if (quot == 0) 479 quot = info->baud_base / info->speed;
479 quot = 1; 480 if (info->speed <= 0 || info->speed > info->max_baud)
481 quot = 0;
480 } else { 482 } else {
481 quot = 0; 483 if (newspd == 134) {
484 quot = (2 * info->baud_base / 269);
485 } else if (newspd) {
486 quot = info->baud_base / newspd;
487 if (quot == 0)
488 quot = 1;
489 } else {
490 quot = 0;
491 }
482 } 492 }
483 493
484 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base); 494 info->timeout = ((info->xmit_fifo_size * HZ * 10 * quot) / info->baud_base);
485 info->timeout += HZ / 50; /* Add .02 seconds of slop */ 495 info->timeout += HZ / 50; /* Add .02 seconds of slop */
486 496
487 if (quot) { 497 if (quot) {
488 spin_lock_irqsave(&info->slock, flags);
489 info->MCR |= UART_MCR_DTR; 498 info->MCR |= UART_MCR_DTR;
490 outb(info->MCR, info->ioaddr + UART_MCR); 499 outb(info->MCR, info->ioaddr + UART_MCR);
491 spin_unlock_irqrestore(&info->slock, flags);
492 } else { 500 } else {
493 spin_lock_irqsave(&info->slock, flags);
494 info->MCR &= ~UART_MCR_DTR; 501 info->MCR &= ~UART_MCR_DTR;
495 outb(info->MCR, info->ioaddr + UART_MCR); 502 outb(info->MCR, info->ioaddr + UART_MCR);
496 spin_unlock_irqrestore(&info->slock, flags);
497 return ret; 503 return ret;
498 } 504 }
499 505
@@ -505,6 +511,18 @@ static int mxser_set_baud(struct mxser_port *info, long newspd)
505 outb(quot >> 8, info->ioaddr + UART_DLM); /* MS of divisor */ 511 outb(quot >> 8, info->ioaddr + UART_DLM); /* MS of divisor */
506 outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */ 512 outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */
507 513
514 if (i == BAUD_TABLE_NO) {
515 quot = info->baud_base % info->speed;
516 quot *= 8;
517 if ((quot % info->speed) > (info->speed / 2)) {
518 quot /= info->speed;
519 quot++;
520 } else {
521 quot /= info->speed;
522 }
523 SET_MOXA_MUST_ENUM_VALUE(info->ioaddr, quot);
524 } else
525 SET_MOXA_MUST_ENUM_VALUE(info->ioaddr, 0);
508 526
509 return ret; 527 return ret;
510} 528}
@@ -520,7 +538,6 @@ static int mxser_change_speed(struct mxser_port *info,
520 int ret = 0; 538 int ret = 0;
521 unsigned char status; 539 unsigned char status;
522 long baud; 540 long baud;
523 unsigned long flags;
524 541
525 if (!info->tty || !info->tty->termios) 542 if (!info->tty || !info->tty->termios)
526 return ret; 543 return ret;
@@ -529,7 +546,10 @@ static int mxser_change_speed(struct mxser_port *info,
529 return ret; 546 return ret;
530 547
531 if (mxser_set_baud_method[info->tty->index] == 0) { 548 if (mxser_set_baud_method[info->tty->index] == 0) {
532 baud = tty_get_baud_rate(info->tty); 549 if ((cflag & CBAUD) == B_SPEC)
550 baud = info->speed;
551 else
552 baud = tty_get_baud_rate(info->tty);
533 mxser_set_baud(info, baud); 553 mxser_set_baud(info, baud);
534 } 554 }
535 555
@@ -612,8 +632,8 @@ static int mxser_change_speed(struct mxser_port *info,
612 outb(info->IER, info->ioaddr + 632 outb(info->IER, info->ioaddr +
613 UART_IER); 633 UART_IER);
614 } 634 }
615 set_bit(MXSER_EVENT_TXLOW, &info->event); 635 tty_wakeup(info->tty);
616 schedule_work(&info->tqueue); } 636 }
617 } else { 637 } else {
618 if (!(status & UART_MSR_CTS)) { 638 if (!(status & UART_MSR_CTS)) {
619 info->tty->hw_stopped = 1; 639 info->tty->hw_stopped = 1;
@@ -668,7 +688,6 @@ static int mxser_change_speed(struct mxser_port *info,
668 } 688 }
669 } 689 }
670 if (info->board->chip_flag) { 690 if (info->board->chip_flag) {
671 spin_lock_irqsave(&info->slock, flags);
672 SET_MOXA_MUST_XON1_VALUE(info->ioaddr, START_CHAR(info->tty)); 691 SET_MOXA_MUST_XON1_VALUE(info->ioaddr, START_CHAR(info->tty));
673 SET_MOXA_MUST_XOFF1_VALUE(info->ioaddr, STOP_CHAR(info->tty)); 692 SET_MOXA_MUST_XOFF1_VALUE(info->ioaddr, STOP_CHAR(info->tty));
674 if (I_IXON(info->tty)) { 693 if (I_IXON(info->tty)) {
@@ -681,7 +700,6 @@ static int mxser_change_speed(struct mxser_port *info,
681 } else { 700 } else {
682 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr); 701 DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(info->ioaddr);
683 } 702 }
684 spin_unlock_irqrestore(&info->slock, flags);
685 } 703 }
686 704
687 705
@@ -708,7 +726,6 @@ static void mxser_check_modem_status(struct mxser_port *port, int status)
708 if ((port->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) { 726 if ((port->flags & ASYNC_CHECK_CD) && (status & UART_MSR_DDCD)) {
709 if (status & UART_MSR_DCD) 727 if (status & UART_MSR_DCD)
710 wake_up_interruptible(&port->open_wait); 728 wake_up_interruptible(&port->open_wait);
711 schedule_work(&port->tqueue);
712 } 729 }
713 730
714 if (port->flags & ASYNC_CTS_FLOW) { 731 if (port->flags & ASYNC_CTS_FLOW) {
@@ -724,8 +741,7 @@ static void mxser_check_modem_status(struct mxser_port *port, int status)
724 outb(port->IER, port->ioaddr + 741 outb(port->IER, port->ioaddr +
725 UART_IER); 742 UART_IER);
726 } 743 }
727 set_bit(MXSER_EVENT_TXLOW, &port->event); 744 tty_wakeup(port->tty);
728 schedule_work(&port->tqueue);
729 } 745 }
730 } else { 746 } else {
731 if (!(status & UART_MSR_CTS)) { 747 if (!(status & UART_MSR_CTS)) {
@@ -836,10 +852,10 @@ static int mxser_startup(struct mxser_port *info)
836 /* 852 /*
837 * and set the speed of the serial port 853 * and set the speed of the serial port
838 */ 854 */
839 spin_unlock_irqrestore(&info->slock, flags);
840 mxser_change_speed(info, NULL); 855 mxser_change_speed(info, NULL);
841
842 info->flags |= ASYNC_INITIALIZED; 856 info->flags |= ASYNC_INITIALIZED;
857 spin_unlock_irqrestore(&info->slock, flags);
858
843 return 0; 859 return 0;
844} 860}
845 861
@@ -909,11 +925,9 @@ static void mxser_shutdown(struct mxser_port *info)
909static int mxser_open(struct tty_struct *tty, struct file *filp) 925static int mxser_open(struct tty_struct *tty, struct file *filp)
910{ 926{
911 struct mxser_port *info; 927 struct mxser_port *info;
928 unsigned long flags;
912 int retval, line; 929 int retval, line;
913 930
914 /* initialize driver_data in case something fails */
915 tty->driver_data = NULL;
916
917 line = tty->index; 931 line = tty->index;
918 if (line == MXSER_PORTS) 932 if (line == MXSER_PORTS)
919 return 0; 933 return 0;
@@ -928,7 +942,9 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
928 /* 942 /*
929 * Start up serial port 943 * Start up serial port
930 */ 944 */
945 spin_lock_irqsave(&info->slock, flags);
931 info->count++; 946 info->count++;
947 spin_unlock_irqrestore(&info->slock, flags);
932 retval = mxser_startup(info); 948 retval = mxser_startup(info);
933 if (retval) 949 if (retval)
934 return retval; 950 return retval;
@@ -937,17 +953,6 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
937 if (retval) 953 if (retval)
938 return retval; 954 return retval;
939 955
940 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
941 if (tty->driver->subtype == SERIAL_TYPE_NORMAL)
942 *tty->termios = info->normal_termios;
943 else
944 *tty->termios = info->callout_termios;
945 mxser_change_speed(info, NULL);
946 }
947
948 info->session = process_session(current);
949 info->pgrp = process_group(current);
950
951 /* unmark here for very high baud rate (ex. 921600 bps) used */ 956 /* unmark here for very high baud rate (ex. 921600 bps) used */
952 tty->low_latency = 1; 957 tty->low_latency = 1;
953 return 0; 958 return 0;
@@ -1054,8 +1059,6 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
1054 } 1059 }
1055 1060
1056 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING); 1061 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1057 wake_up_interruptible(&info->close_wait);
1058
1059} 1062}
1060 1063
1061static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count) 1064static int mxser_write(struct tty_struct *tty, const unsigned char *buf, int count)
@@ -1222,6 +1225,7 @@ static int mxser_set_serial_info(struct mxser_port *info,
1222 struct serial_struct __user *new_info) 1225 struct serial_struct __user *new_info)
1223{ 1226{
1224 struct serial_struct new_serial; 1227 struct serial_struct new_serial;
1228 unsigned long sl_flags;
1225 unsigned int flags; 1229 unsigned int flags;
1226 int retval = 0; 1230 int retval = 0;
1227 1231
@@ -1264,8 +1268,11 @@ static int mxser_set_serial_info(struct mxser_port *info,
1264 process_txrx_fifo(info); 1268 process_txrx_fifo(info);
1265 1269
1266 if (info->flags & ASYNC_INITIALIZED) { 1270 if (info->flags & ASYNC_INITIALIZED) {
1267 if (flags != (info->flags & ASYNC_SPD_MASK)) 1271 if (flags != (info->flags & ASYNC_SPD_MASK)) {
1272 spin_lock_irqsave(&info->slock, sl_flags);
1268 mxser_change_speed(info, NULL); 1273 mxser_change_speed(info, NULL);
1274 spin_unlock_irqrestore(&info->slock, sl_flags);
1275 }
1269 } else 1276 } else
1270 retval = mxser_startup(info); 1277 retval = mxser_startup(info);
1271 1278
@@ -1373,11 +1380,10 @@ static int mxser_tiocmset(struct tty_struct *tty, struct file *file,
1373 return 0; 1380 return 0;
1374} 1381}
1375 1382
1376static int mxser_program_mode(int port) 1383static int __init mxser_program_mode(int port)
1377{ 1384{
1378 int id, i, j, n; 1385 int id, i, j, n;
1379 1386
1380 spin_lock(&gm_lock);
1381 outb(0, port); 1387 outb(0, port);
1382 outb(0, port); 1388 outb(0, port);
1383 outb(0, port); 1389 outb(0, port);
@@ -1385,7 +1391,6 @@ static int mxser_program_mode(int port)
1385 (void)inb(port); 1391 (void)inb(port);
1386 outb(0, port); 1392 outb(0, port);
1387 (void)inb(port); 1393 (void)inb(port);
1388 spin_unlock(&gm_lock);
1389 1394
1390 id = inb(port + 1) & 0x1F; 1395 id = inb(port + 1) & 0x1F;
1391 if ((id != C168_ASIC_ID) && 1396 if ((id != C168_ASIC_ID) &&
@@ -1410,7 +1415,7 @@ static int mxser_program_mode(int port)
1410 return id; 1415 return id;
1411} 1416}
1412 1417
1413static void mxser_normal_mode(int port) 1418static void __init mxser_normal_mode(int port)
1414{ 1419{
1415 int i, n; 1420 int i, n;
1416 1421
@@ -1443,7 +1448,7 @@ static void mxser_normal_mode(int port)
1443#define EN0_PORT 0x010 /* Rcv missed frame error counter RD */ 1448#define EN0_PORT 0x010 /* Rcv missed frame error counter RD */
1444#define ENC_PAGE0 0x000 /* Select page 0 of chip registers */ 1449#define ENC_PAGE0 0x000 /* Select page 0 of chip registers */
1445#define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */ 1450#define ENC_PAGE3 0x0C0 /* Select page 3 of chip registers */
1446static int mxser_read_register(int port, unsigned short *regs) 1451static int __init mxser_read_register(int port, unsigned short *regs)
1447{ 1452{
1448 int i, k, value, id; 1453 int i, k, value, id;
1449 unsigned int j; 1454 unsigned int j;
@@ -1644,6 +1649,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1644 struct serial_icounter_struct __user *p_cuser; 1649 struct serial_icounter_struct __user *p_cuser;
1645 unsigned long templ; 1650 unsigned long templ;
1646 unsigned long flags; 1651 unsigned long flags;
1652 unsigned int i;
1647 void __user *argp = (void __user *)arg; 1653 void __user *argp = (void __user *)arg;
1648 int retval; 1654 int retval;
1649 1655
@@ -1682,6 +1688,36 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1682 return 0; 1688 return 0;
1683 } 1689 }
1684 1690
1691 if (cmd == MOXA_SET_SPECIAL_BAUD_RATE) {
1692 int speed;
1693
1694 if (get_user(speed, (int __user *)argp))
1695 return -EFAULT;
1696 if (speed <= 0 || speed > info->max_baud)
1697 return -EFAULT;
1698 if (!info->tty || !info->tty->termios || !info->ioaddr)
1699 return 0;
1700 info->tty->termios->c_cflag &= ~(CBAUD | CBAUDEX);
1701 for (i = 0; i < BAUD_TABLE_NO; i++)
1702 if (speed == mxvar_baud_table[i])
1703 break;
1704 if (i == BAUD_TABLE_NO) {
1705 info->tty->termios->c_cflag |= B_SPEC;
1706 } else if (speed != 0)
1707 info->tty->termios->c_cflag |= mxvar_baud_table1[i];
1708
1709 info->speed = speed;
1710 spin_lock_irqsave(&info->slock, flags);
1711 mxser_change_speed(info, NULL);
1712 spin_unlock_irqrestore(&info->slock, flags);
1713
1714 return 0;
1715 } else if (cmd == MOXA_GET_SPECIAL_BAUD_RATE) {
1716 if (copy_to_user(argp, &info->speed, sizeof(int)))
1717 return -EFAULT;
1718 return 0;
1719 }
1720
1685 if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && cmd != TIOCGICOUNT && 1721 if (cmd != TIOCGSERIAL && cmd != TIOCMIWAIT && cmd != TIOCGICOUNT &&
1686 test_bit(TTY_IO_ERROR, &tty->flags)) 1722 test_bit(TTY_IO_ERROR, &tty->flags))
1687 return -EIO; 1723 return -EIO;
@@ -1799,7 +1835,9 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1799 long baud; 1835 long baud;
1800 if (get_user(baud, (long __user *)argp)) 1836 if (get_user(baud, (long __user *)argp))
1801 return -EFAULT; 1837 return -EFAULT;
1838 spin_lock_irqsave(&info->slock, flags);
1802 mxser_set_baud(info, baud); 1839 mxser_set_baud(info, baud);
1840 spin_unlock_irqrestore(&info->slock, flags);
1803 return 0; 1841 return 0;
1804 } 1842 }
1805 case MOXA_ASPP_GETBAUD: 1843 case MOXA_ASPP_GETBAUD:
@@ -1976,7 +2014,9 @@ static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termi
1976 if ((tty->termios->c_cflag != old_termios->c_cflag) || 2014 if ((tty->termios->c_cflag != old_termios->c_cflag) ||
1977 (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) { 2015 (RELEVANT_IFLAG(tty->termios->c_iflag) != RELEVANT_IFLAG(old_termios->c_iflag))) {
1978 2016
2017 spin_lock_irqsave(&info->slock, flags);
1979 mxser_change_speed(info, old_termios); 2018 mxser_change_speed(info, old_termios);
2019 spin_unlock_irqrestore(&info->slock, flags);
1980 2020
1981 if ((old_termios->c_cflag & CRTSCTS) && 2021 if ((old_termios->c_cflag & CRTSCTS) &&
1982 !(tty->termios->c_cflag & CRTSCTS)) { 2022 !(tty->termios->c_cflag & CRTSCTS)) {
@@ -2066,7 +2106,7 @@ static void mxser_wait_until_sent(struct tty_struct *tty, int timeout)
2066/* 2106/*
2067 * This routine is called by tty_hangup() when a hangup is signaled. 2107 * This routine is called by tty_hangup() when a hangup is signaled.
2068 */ 2108 */
2069void mxser_hangup(struct tty_struct *tty) 2109static void mxser_hangup(struct tty_struct *tty)
2070{ 2110{
2071 struct mxser_port *info = tty->driver_data; 2111 struct mxser_port *info = tty->driver_data;
2072 2112
@@ -2105,9 +2145,6 @@ static void mxser_receive_chars(struct mxser_port *port, int *status)
2105 int cnt = 0; 2145 int cnt = 0;
2106 int recv_room; 2146 int recv_room;
2107 int max = 256; 2147 int max = 256;
2108 unsigned long flags;
2109
2110 spin_lock_irqsave(&port->slock, flags);
2111 2148
2112 recv_room = tty->receive_room; 2149 recv_room = tty->receive_room;
2113 if ((recv_room == 0) && (!port->ldisc_stop_rx)) 2150 if ((recv_room == 0) && (!port->ldisc_stop_rx))
@@ -2169,7 +2206,8 @@ intr_old:
2169 } else if (*status & UART_LSR_OE) { 2206 } else if (*status & UART_LSR_OE) {
2170 flag = TTY_OVERRUN; 2207 flag = TTY_OVERRUN;
2171 port->icount.overrun++; 2208 port->icount.overrun++;
2172 } 2209 } else
2210 flag = TTY_BREAK;
2173 } 2211 }
2174 tty_insert_flip_char(tty, ch, flag); 2212 tty_insert_flip_char(tty, ch, flag);
2175 cnt++; 2213 cnt++;
@@ -2191,7 +2229,6 @@ end_intr:
2191 mxvar_log.rxcnt[port->tty->index] += cnt; 2229 mxvar_log.rxcnt[port->tty->index] += cnt;
2192 port->mon_data.rxcnt += cnt; 2230 port->mon_data.rxcnt += cnt;
2193 port->mon_data.up_rxcnt += cnt; 2231 port->mon_data.up_rxcnt += cnt;
2194 spin_unlock_irqrestore(&port->slock, flags);
2195 2232
2196 tty_flip_buffer_push(tty); 2233 tty_flip_buffer_push(tty);
2197} 2234}
@@ -2199,9 +2236,6 @@ end_intr:
2199static void mxser_transmit_chars(struct mxser_port *port) 2236static void mxser_transmit_chars(struct mxser_port *port)
2200{ 2237{
2201 int count, cnt; 2238 int count, cnt;
2202 unsigned long flags;
2203
2204 spin_lock_irqsave(&port->slock, flags);
2205 2239
2206 if (port->x_char) { 2240 if (port->x_char) {
2207 outb(port->x_char, port->ioaddr + UART_TX); 2241 outb(port->x_char, port->ioaddr + UART_TX);
@@ -2210,11 +2244,11 @@ static void mxser_transmit_chars(struct mxser_port *port)
2210 port->mon_data.txcnt++; 2244 port->mon_data.txcnt++;
2211 port->mon_data.up_txcnt++; 2245 port->mon_data.up_txcnt++;
2212 port->icount.tx++; 2246 port->icount.tx++;
2213 goto unlock; 2247 return;
2214 } 2248 }
2215 2249
2216 if (port->xmit_buf == 0) 2250 if (port->xmit_buf == 0)
2217 goto unlock; 2251 return;
2218 2252
2219 if ((port->xmit_cnt <= 0) || port->tty->stopped || 2253 if ((port->xmit_cnt <= 0) || port->tty->stopped ||
2220 (port->tty->hw_stopped && 2254 (port->tty->hw_stopped &&
@@ -2222,7 +2256,7 @@ static void mxser_transmit_chars(struct mxser_port *port)
2222 (!port->board->chip_flag))) { 2256 (!port->board->chip_flag))) {
2223 port->IER &= ~UART_IER_THRI; 2257 port->IER &= ~UART_IER_THRI;
2224 outb(port->IER, port->ioaddr + UART_IER); 2258 outb(port->IER, port->ioaddr + UART_IER);
2225 goto unlock; 2259 return;
2226 } 2260 }
2227 2261
2228 cnt = port->xmit_cnt; 2262 cnt = port->xmit_cnt;
@@ -2240,16 +2274,13 @@ static void mxser_transmit_chars(struct mxser_port *port)
2240 port->mon_data.up_txcnt += (cnt - port->xmit_cnt); 2274 port->mon_data.up_txcnt += (cnt - port->xmit_cnt);
2241 port->icount.tx += (cnt - port->xmit_cnt); 2275 port->icount.tx += (cnt - port->xmit_cnt);
2242 2276
2243 if (port->xmit_cnt < WAKEUP_CHARS) { 2277 if (port->xmit_cnt < WAKEUP_CHARS)
2244 set_bit(MXSER_EVENT_TXLOW, &port->event); 2278 tty_wakeup(port->tty);
2245 schedule_work(&port->tqueue); 2279
2246 }
2247 if (port->xmit_cnt <= 0) { 2280 if (port->xmit_cnt <= 0) {
2248 port->IER &= ~UART_IER_THRI; 2281 port->IER &= ~UART_IER_THRI;
2249 outb(port->IER, port->ioaddr + UART_IER); 2282 outb(port->IER, port->ioaddr + UART_IER);
2250 } 2283 }
2251unlock:
2252 spin_unlock_irqrestore(&port->slock, flags);
2253} 2284}
2254 2285
2255/* 2286/*
@@ -2261,8 +2292,7 @@ static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2261 struct mxser_board *brd = NULL; 2292 struct mxser_board *brd = NULL;
2262 struct mxser_port *port; 2293 struct mxser_port *port;
2263 int max, irqbits, bits, msr; 2294 int max, irqbits, bits, msr;
2264 int pass_counter = 0; 2295 unsigned int int_cnt, pass_counter = 0;
2265 unsigned int int_cnt;
2266 int handled = IRQ_NONE; 2296 int handled = IRQ_NONE;
2267 2297
2268 for (i = 0; i < MXSER_BOARDS; i++) 2298 for (i = 0; i < MXSER_BOARDS; i++)
@@ -2276,7 +2306,7 @@ static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2276 if (brd == NULL) 2306 if (brd == NULL)
2277 goto irq_stop; 2307 goto irq_stop;
2278 max = brd->info->nports; 2308 max = brd->info->nports;
2279 while (1) { 2309 while (pass_counter++ < MXSER_ISR_PASS_LIMIT) {
2280 irqbits = inb(brd->vector) & brd->vector_mask; 2310 irqbits = inb(brd->vector) & brd->vector_mask;
2281 if (irqbits == brd->vector_mask) 2311 if (irqbits == brd->vector_mask)
2282 break; 2312 break;
@@ -2290,12 +2320,16 @@ static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2290 port = &brd->ports[i]; 2320 port = &brd->ports[i];
2291 2321
2292 int_cnt = 0; 2322 int_cnt = 0;
2323 spin_lock(&port->slock);
2293 do { 2324 do {
2294 iir = inb(port->ioaddr + UART_IIR); 2325 iir = inb(port->ioaddr + UART_IIR);
2295 if (iir & UART_IIR_NO_INT) 2326 if (iir & UART_IIR_NO_INT)
2296 break; 2327 break;
2297 iir &= MOXA_MUST_IIR_MASK; 2328 iir &= MOXA_MUST_IIR_MASK;
2298 if (!port->tty) { 2329 if (!port->tty ||
2330 (port->flags & ASYNC_CLOSING) ||
2331 !(port->flags &
2332 ASYNC_INITIALIZED)) {
2299 status = inb(port->ioaddr + UART_LSR); 2333 status = inb(port->ioaddr + UART_LSR);
2300 outb(0x27, port->ioaddr + UART_FCR); 2334 outb(0x27, port->ioaddr + UART_FCR);
2301 inb(port->ioaddr + UART_MSR); 2335 inb(port->ioaddr + UART_MSR);
@@ -2341,9 +2375,8 @@ static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2341 mxser_transmit_chars(port); 2375 mxser_transmit_chars(port);
2342 } 2376 }
2343 } while (int_cnt++ < MXSER_ISR_PASS_LIMIT); 2377 } while (int_cnt++ < MXSER_ISR_PASS_LIMIT);
2378 spin_unlock(&port->slock);
2344 } 2379 }
2345 if (pass_counter++ > MXSER_ISR_PASS_LIMIT)
2346 break; /* Prevent infinite loops */
2347 } 2380 }
2348 2381
2349irq_stop: 2382irq_stop:
@@ -2385,7 +2418,6 @@ static void mxser_release_res(struct mxser_board *brd, struct pci_dev *pdev,
2385#ifdef CONFIG_PCI 2418#ifdef CONFIG_PCI
2386 pci_release_region(pdev, 2); 2419 pci_release_region(pdev, 2);
2387 pci_release_region(pdev, 3); 2420 pci_release_region(pdev, 3);
2388 pci_dev_put(pdev);
2389#endif 2421#endif
2390 } else { 2422 } else {
2391 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports); 2423 release_region(brd->ports[0].ioaddr, 8 * brd->info->nports);
@@ -2420,11 +2452,10 @@ static int __devinit mxser_initbrd(struct mxser_board *brd,
2420 info->custom_divisor = info->baud_base * 16; 2452 info->custom_divisor = info->baud_base * 16;
2421 info->close_delay = 5 * HZ / 10; 2453 info->close_delay = 5 * HZ / 10;
2422 info->closing_wait = 30 * HZ; 2454 info->closing_wait = 30 * HZ;
2423 INIT_WORK(&info->tqueue, mxser_do_softint);
2424 info->normal_termios = mxvar_sdriver->init_termios; 2455 info->normal_termios = mxvar_sdriver->init_termios;
2425 init_waitqueue_head(&info->open_wait); 2456 init_waitqueue_head(&info->open_wait);
2426 init_waitqueue_head(&info->close_wait);
2427 init_waitqueue_head(&info->delta_msr_wait); 2457 init_waitqueue_head(&info->delta_msr_wait);
2458 info->speed = 9600;
2428 memset(&info->mon_data, 0, sizeof(struct mxser_mon)); 2459 memset(&info->mon_data, 0, sizeof(struct mxser_mon));
2429 info->err_shadow = 0; 2460 info->err_shadow = 0;
2430 spin_lock_init(&info->slock); 2461 spin_lock_init(&info->slock);
@@ -2433,22 +2464,17 @@ static int __devinit mxser_initbrd(struct mxser_board *brd,
2433 outb(inb(info->ioaddr + UART_IER) & 0xf0, 2464 outb(inb(info->ioaddr + UART_IER) & 0xf0,
2434 info->ioaddr + UART_IER); 2465 info->ioaddr + UART_IER);
2435 } 2466 }
2436 /*
2437 * Allocate the IRQ if necessary
2438 */
2439 2467
2440 retval = request_irq(brd->irq, mxser_interrupt, 2468 retval = request_irq(brd->irq, mxser_interrupt, IRQF_SHARED, "mxser",
2441 (brd->ports[0].flags & ASYNC_SHARE_IRQ) ? IRQF_SHARED : 2469 brd);
2442 IRQF_DISABLED, "mxser", brd);
2443 if (retval) { 2470 if (retval) {
2444 printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may " 2471 printk(KERN_ERR "Board %s: Request irq failed, IRQ (%d) may "
2445 "conflict with another device.\n", 2472 "conflict with another device.\n",
2446 brd->info->name, brd->irq); 2473 brd->info->name, brd->irq);
2447 /* We hold resources, we need to release them. */ 2474 /* We hold resources, we need to release them. */
2448 mxser_release_res(brd, pdev, 0); 2475 mxser_release_res(brd, pdev, 0);
2449 return retval;
2450 } 2476 }
2451 return 0; 2477 return retval;
2452} 2478}
2453 2479
2454static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd) 2480static int __init mxser_get_ISA_conf(int cap, struct mxser_board *brd)
@@ -2633,8 +2659,9 @@ static int __devinit mxser_probe(struct pci_dev *pdev,
2633 } 2659 }
2634 2660
2635 /* mxser_initbrd will hook ISR. */ 2661 /* mxser_initbrd will hook ISR. */
2636 if (mxser_initbrd(brd, pdev) < 0) 2662 retval = mxser_initbrd(brd, pdev);
2637 goto err_relvec; 2663 if (retval)
2664 goto err_null;
2638 2665
2639 for (i = 0; i < brd->info->nports; i++) 2666 for (i = 0; i < brd->info->nports; i++)
2640 tty_register_device(mxvar_sdriver, brd->idx + i, &pdev->dev); 2667 tty_register_device(mxvar_sdriver, brd->idx + i, &pdev->dev);
@@ -2642,10 +2669,9 @@ static int __devinit mxser_probe(struct pci_dev *pdev,
2642 pci_set_drvdata(pdev, brd); 2669 pci_set_drvdata(pdev, brd);
2643 2670
2644 return 0; 2671 return 0;
2645err_relvec:
2646 pci_release_region(pdev, 3);
2647err_relio: 2672err_relio:
2648 pci_release_region(pdev, 2); 2673 pci_release_region(pdev, 2);
2674err_null:
2649 brd->info = NULL; 2675 brd->info = NULL;
2650err: 2676err:
2651 return retval; 2677 return retval;
@@ -2663,6 +2689,7 @@ static void __devexit mxser_remove(struct pci_dev *pdev)
2663 tty_unregister_device(mxvar_sdriver, brd->idx + i); 2689 tty_unregister_device(mxvar_sdriver, brd->idx + i);
2664 2690
2665 mxser_release_res(brd, pdev, 1); 2691 mxser_release_res(brd, pdev, 1);
2692 brd->info = NULL;
2666} 2693}
2667 2694
2668static struct pci_driver mxser_driver = { 2695static struct pci_driver mxser_driver = {
@@ -2684,7 +2711,6 @@ static int __init mxser_module_init(void)
2684 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1); 2711 mxvar_sdriver = alloc_tty_driver(MXSER_PORTS + 1);
2685 if (!mxvar_sdriver) 2712 if (!mxvar_sdriver)
2686 return -ENOMEM; 2713 return -ENOMEM;
2687 spin_lock_init(&gm_lock);
2688 2714
2689 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n", 2715 printk(KERN_INFO "MOXA Smartio/Industio family driver version %s\n",
2690 MXSER_VERSION); 2716 MXSER_VERSION);
diff --git a/drivers/char/mxser_new.h b/drivers/char/mxser_new.h
index a08f0ecb09b..d42f7766c65 100644
--- a/drivers/char/mxser_new.h
+++ b/drivers/char/mxser_new.h
@@ -26,18 +26,8 @@
26#define RS422_MODE 2 26#define RS422_MODE 2
27#define RS485_4WIRE_MODE 3 27#define RS485_4WIRE_MODE 3
28#define OP_MODE_MASK 3 28#define OP_MODE_MASK 3
29// above add by Victor Yu. 01-05-2004
30
31#define TTY_THRESHOLD_THROTTLE 128
32
33#define LO_WATER (TTY_FLIPBUF_SIZE)
34#define HI_WATER (TTY_FLIPBUF_SIZE*2*3/4)
35
36// added by James. 03-11-2004.
37#define MOXA_SDS_GETICOUNTER (MOXA + 68)
38#define MOXA_SDS_RSTICOUNTER (MOXA + 69)
39// (above) added by James.
40 29
30#define MOXA_SDS_RSTICOUNTER (MOXA + 69)
41#define MOXA_ASPP_OQUEUE (MOXA + 70) 31#define MOXA_ASPP_OQUEUE (MOXA + 70)
42#define MOXA_ASPP_SETBAUD (MOXA + 71) 32#define MOXA_ASPP_SETBAUD (MOXA + 71)
43#define MOXA_ASPP_GETBAUD (MOXA + 72) 33#define MOXA_ASPP_GETBAUD (MOXA + 72)
@@ -45,7 +35,8 @@
45#define MOXA_ASPP_LSTATUS (MOXA + 74) 35#define MOXA_ASPP_LSTATUS (MOXA + 74)
46#define MOXA_ASPP_MON_EXT (MOXA + 75) 36#define MOXA_ASPP_MON_EXT (MOXA + 75)
47#define MOXA_SET_BAUD_METHOD (MOXA + 76) 37#define MOXA_SET_BAUD_METHOD (MOXA + 76)
48 38#define MOXA_SET_SPECIAL_BAUD_RATE (MOXA + 77)
39#define MOXA_GET_SPECIAL_BAUD_RATE (MOXA + 78)
49 40
50/* --------------------------------------------------- */ 41/* --------------------------------------------------- */
51 42
@@ -55,51 +46,46 @@
55#define NPPI_NOTIFY_SW_OVERRUN 0x08 46#define NPPI_NOTIFY_SW_OVERRUN 0x08
56#define NPPI_NOTIFY_BREAK 0x10 47#define NPPI_NOTIFY_BREAK 0x10
57 48
58#define NPPI_NOTIFY_CTSHOLD 0x01 // Tx hold by CTS low 49#define NPPI_NOTIFY_CTSHOLD 0x01 /* Tx hold by CTS low */
59#define NPPI_NOTIFY_DSRHOLD 0x02 // Tx hold by DSR low 50#define NPPI_NOTIFY_DSRHOLD 0x02 /* Tx hold by DSR low */
60#define NPPI_NOTIFY_XOFFHOLD 0x08 // Tx hold by Xoff received 51#define NPPI_NOTIFY_XOFFHOLD 0x08 /* Tx hold by Xoff received */
61#define NPPI_NOTIFY_XOFFXENT 0x10 // Xoff Sent 52#define NPPI_NOTIFY_XOFFXENT 0x10 /* Xoff Sent */
62 53
63//CheckIsMoxaMust return value 54/* follow just for Moxa Must chip define. */
64#define MOXA_OTHER_UART 0x00 55/* */
65#define MOXA_MUST_MU150_HWID 0x01 56/* when LCR register (offset 0x03) write following value, */
66#define MOXA_MUST_MU860_HWID 0x02 57/* the Must chip will enter enchance mode. And write value */
67 58/* on EFR (offset 0x02) bit 6,7 to change bank. */
68// follow just for Moxa Must chip define.
69//
70// when LCR register (offset 0x03) write following value,
71// the Must chip will enter enchance mode. And write value
72// on EFR (offset 0x02) bit 6,7 to change bank.
73#define MOXA_MUST_ENTER_ENCHANCE 0xBF 59#define MOXA_MUST_ENTER_ENCHANCE 0xBF
74 60
75// when enhance mode enable, access on general bank register 61/* when enhance mode enable, access on general bank register */
76#define MOXA_MUST_GDL_REGISTER 0x07 62#define MOXA_MUST_GDL_REGISTER 0x07
77#define MOXA_MUST_GDL_MASK 0x7F 63#define MOXA_MUST_GDL_MASK 0x7F
78#define MOXA_MUST_GDL_HAS_BAD_DATA 0x80 64#define MOXA_MUST_GDL_HAS_BAD_DATA 0x80
79 65
80#define MOXA_MUST_LSR_RERR 0x80 // error in receive FIFO 66#define MOXA_MUST_LSR_RERR 0x80 /* error in receive FIFO */
81// enchance register bank select and enchance mode setting register 67/* enchance register bank select and enchance mode setting register */
82// when LCR register equal to 0xBF 68/* when LCR register equal to 0xBF */
83#define MOXA_MUST_EFR_REGISTER 0x02 69#define MOXA_MUST_EFR_REGISTER 0x02
84// enchance mode enable 70/* enchance mode enable */
85#define MOXA_MUST_EFR_EFRB_ENABLE 0x10 71#define MOXA_MUST_EFR_EFRB_ENABLE 0x10
86// enchance reister bank set 0, 1, 2 72/* enchance reister bank set 0, 1, 2 */
87#define MOXA_MUST_EFR_BANK0 0x00 73#define MOXA_MUST_EFR_BANK0 0x00
88#define MOXA_MUST_EFR_BANK1 0x40 74#define MOXA_MUST_EFR_BANK1 0x40
89#define MOXA_MUST_EFR_BANK2 0x80 75#define MOXA_MUST_EFR_BANK2 0x80
90#define MOXA_MUST_EFR_BANK3 0xC0 76#define MOXA_MUST_EFR_BANK3 0xC0
91#define MOXA_MUST_EFR_BANK_MASK 0xC0 77#define MOXA_MUST_EFR_BANK_MASK 0xC0
92 78
93// set XON1 value register, when LCR=0xBF and change to bank0 79/* set XON1 value register, when LCR=0xBF and change to bank0 */
94#define MOXA_MUST_XON1_REGISTER 0x04 80#define MOXA_MUST_XON1_REGISTER 0x04
95 81
96// set XON2 value register, when LCR=0xBF and change to bank0 82/* set XON2 value register, when LCR=0xBF and change to bank0 */
97#define MOXA_MUST_XON2_REGISTER 0x05 83#define MOXA_MUST_XON2_REGISTER 0x05
98 84
99// set XOFF1 value register, when LCR=0xBF and change to bank0 85/* set XOFF1 value register, when LCR=0xBF and change to bank0 */
100#define MOXA_MUST_XOFF1_REGISTER 0x06 86#define MOXA_MUST_XOFF1_REGISTER 0x06
101 87
102// set XOFF2 value register, when LCR=0xBF and change to bank0 88/* set XOFF2 value register, when LCR=0xBF and change to bank0 */
103#define MOXA_MUST_XOFF2_REGISTER 0x07 89#define MOXA_MUST_XOFF2_REGISTER 0x07
104 90
105#define MOXA_MUST_RBRTL_REGISTER 0x04 91#define MOXA_MUST_RBRTL_REGISTER 0x04
@@ -111,32 +97,32 @@
111#define MOXA_MUST_ECR_REGISTER 0x06 97#define MOXA_MUST_ECR_REGISTER 0x06
112#define MOXA_MUST_CSR_REGISTER 0x07 98#define MOXA_MUST_CSR_REGISTER 0x07
113 99
114// good data mode enable 100/* good data mode enable */
115#define MOXA_MUST_FCR_GDA_MODE_ENABLE 0x20 101#define MOXA_MUST_FCR_GDA_MODE_ENABLE 0x20
116// only good data put into RxFIFO 102/* only good data put into RxFIFO */
117#define MOXA_MUST_FCR_GDA_ONLY_ENABLE 0x10 103#define MOXA_MUST_FCR_GDA_ONLY_ENABLE 0x10
118 104
119// enable CTS interrupt 105/* enable CTS interrupt */
120#define MOXA_MUST_IER_ECTSI 0x80 106#define MOXA_MUST_IER_ECTSI 0x80
121// enable RTS interrupt 107/* enable RTS interrupt */
122#define MOXA_MUST_IER_ERTSI 0x40 108#define MOXA_MUST_IER_ERTSI 0x40
123// enable Xon/Xoff interrupt 109/* enable Xon/Xoff interrupt */
124#define MOXA_MUST_IER_XINT 0x20 110#define MOXA_MUST_IER_XINT 0x20
125// enable GDA interrupt 111/* enable GDA interrupt */
126#define MOXA_MUST_IER_EGDAI 0x10 112#define MOXA_MUST_IER_EGDAI 0x10
127 113
128#define MOXA_MUST_RECV_ISR (UART_IER_RDI | MOXA_MUST_IER_EGDAI) 114#define MOXA_MUST_RECV_ISR (UART_IER_RDI | MOXA_MUST_IER_EGDAI)
129 115
130// GDA interrupt pending 116/* GDA interrupt pending */
131#define MOXA_MUST_IIR_GDA 0x1C 117#define MOXA_MUST_IIR_GDA 0x1C
132#define MOXA_MUST_IIR_RDA 0x04 118#define MOXA_MUST_IIR_RDA 0x04
133#define MOXA_MUST_IIR_RTO 0x0C 119#define MOXA_MUST_IIR_RTO 0x0C
134#define MOXA_MUST_IIR_LSR 0x06 120#define MOXA_MUST_IIR_LSR 0x06
135 121
136// recieved Xon/Xoff or specical interrupt pending 122/* recieved Xon/Xoff or specical interrupt pending */
137#define MOXA_MUST_IIR_XSC 0x10 123#define MOXA_MUST_IIR_XSC 0x10
138 124
139// RTS/CTS change state interrupt pending 125/* RTS/CTS change state interrupt pending */
140#define MOXA_MUST_IIR_RTSCTS 0x20 126#define MOXA_MUST_IIR_RTSCTS 0x20
141#define MOXA_MUST_IIR_MASK 0x3E 127#define MOXA_MUST_IIR_MASK 0x3E
142 128
@@ -144,307 +130,164 @@
144#define MOXA_MUST_MCR_XON_ANY 0x80 130#define MOXA_MUST_MCR_XON_ANY 0x80
145#define MOXA_MUST_MCR_TX_XON 0x08 131#define MOXA_MUST_MCR_TX_XON 0x08
146 132
147 133/* software flow control on chip mask value */
148// software flow control on chip mask value
149#define MOXA_MUST_EFR_SF_MASK 0x0F 134#define MOXA_MUST_EFR_SF_MASK 0x0F
150// send Xon1/Xoff1 135/* send Xon1/Xoff1 */
151#define MOXA_MUST_EFR_SF_TX1 0x08 136#define MOXA_MUST_EFR_SF_TX1 0x08
152// send Xon2/Xoff2 137/* send Xon2/Xoff2 */
153#define MOXA_MUST_EFR_SF_TX2 0x04 138#define MOXA_MUST_EFR_SF_TX2 0x04
154// send Xon1,Xon2/Xoff1,Xoff2 139/* send Xon1,Xon2/Xoff1,Xoff2 */
155#define MOXA_MUST_EFR_SF_TX12 0x0C 140#define MOXA_MUST_EFR_SF_TX12 0x0C
156// don't send Xon/Xoff 141/* don't send Xon/Xoff */
157#define MOXA_MUST_EFR_SF_TX_NO 0x00 142#define MOXA_MUST_EFR_SF_TX_NO 0x00
158// Tx software flow control mask 143/* Tx software flow control mask */
159#define MOXA_MUST_EFR_SF_TX_MASK 0x0C 144#define MOXA_MUST_EFR_SF_TX_MASK 0x0C
160// don't receive Xon/Xoff 145/* don't receive Xon/Xoff */
161#define MOXA_MUST_EFR_SF_RX_NO 0x00 146#define MOXA_MUST_EFR_SF_RX_NO 0x00
162// receive Xon1/Xoff1 147/* receive Xon1/Xoff1 */
163#define MOXA_MUST_EFR_SF_RX1 0x02 148#define MOXA_MUST_EFR_SF_RX1 0x02
164// receive Xon2/Xoff2 149/* receive Xon2/Xoff2 */
165#define MOXA_MUST_EFR_SF_RX2 0x01 150#define MOXA_MUST_EFR_SF_RX2 0x01
166// receive Xon1,Xon2/Xoff1,Xoff2 151/* receive Xon1,Xon2/Xoff1,Xoff2 */
167#define MOXA_MUST_EFR_SF_RX12 0x03 152#define MOXA_MUST_EFR_SF_RX12 0x03
168// Rx software flow control mask 153/* Rx software flow control mask */
169#define MOXA_MUST_EFR_SF_RX_MASK 0x03 154#define MOXA_MUST_EFR_SF_RX_MASK 0x03
170 155
171//#define MOXA_MUST_MIN_XOFFLIMIT 66 156#define ENABLE_MOXA_MUST_ENCHANCE_MODE(baseio) do { \
172//#define MOXA_MUST_MIN_XONLIMIT 20 157 u8 __oldlcr, __efr; \
173//#define ID1_RX_TRIG 120 158 __oldlcr = inb((baseio)+UART_LCR); \
174
175
176#define CHECK_MOXA_MUST_XOFFLIMIT(info) { \
177 if ( (info)->IsMoxaMustChipFlag && \
178 (info)->HandFlow.XoffLimit < MOXA_MUST_MIN_XOFFLIMIT ) { \
179 (info)->HandFlow.XoffLimit = MOXA_MUST_MIN_XOFFLIMIT; \
180 (info)->HandFlow.XonLimit = MOXA_MUST_MIN_XONLIMIT; \
181 } \
182}
183
184#define ENABLE_MOXA_MUST_ENCHANCE_MODE(baseio) { \
185 u8 __oldlcr, __efr; \
186 __oldlcr = inb((baseio)+UART_LCR); \
187 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 159 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
188 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 160 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
189 __efr |= MOXA_MUST_EFR_EFRB_ENABLE; \ 161 __efr |= MOXA_MUST_EFR_EFRB_ENABLE; \
190 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 162 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
191 outb(__oldlcr, (baseio)+UART_LCR); \ 163 outb(__oldlcr, (baseio)+UART_LCR); \
192} 164} while (0)
193 165
194#define DISABLE_MOXA_MUST_ENCHANCE_MODE(baseio) { \ 166#define DISABLE_MOXA_MUST_ENCHANCE_MODE(baseio) do { \
195 u8 __oldlcr, __efr; \ 167 u8 __oldlcr, __efr; \
196 __oldlcr = inb((baseio)+UART_LCR); \ 168 __oldlcr = inb((baseio)+UART_LCR); \
197 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 169 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
198 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 170 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
199 __efr &= ~MOXA_MUST_EFR_EFRB_ENABLE; \ 171 __efr &= ~MOXA_MUST_EFR_EFRB_ENABLE; \
200 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 172 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
201 outb(__oldlcr, (baseio)+UART_LCR); \ 173 outb(__oldlcr, (baseio)+UART_LCR); \
202} 174} while (0)
203 175
204#define SET_MOXA_MUST_XON1_VALUE(baseio, Value) { \ 176#define SET_MOXA_MUST_XON1_VALUE(baseio, Value) do { \
205 u8 __oldlcr, __efr; \ 177 u8 __oldlcr, __efr; \
206 __oldlcr = inb((baseio)+UART_LCR); \ 178 __oldlcr = inb((baseio)+UART_LCR); \
207 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 179 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
208 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 180 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
209 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \ 181 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
210 __efr |= MOXA_MUST_EFR_BANK0; \ 182 __efr |= MOXA_MUST_EFR_BANK0; \
211 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 183 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
212 outb((u8)(Value), (baseio)+MOXA_MUST_XON1_REGISTER); \ 184 outb((u8)(Value), (baseio)+MOXA_MUST_XON1_REGISTER); \
213 outb(__oldlcr, (baseio)+UART_LCR); \ 185 outb(__oldlcr, (baseio)+UART_LCR); \
214} 186} while (0)
215 187
216#define SET_MOXA_MUST_XON2_VALUE(baseio, Value) { \ 188#define SET_MOXA_MUST_XOFF1_VALUE(baseio, Value) do { \
217 u8 __oldlcr, __efr; \ 189 u8 __oldlcr, __efr; \
218 __oldlcr = inb((baseio)+UART_LCR); \ 190 __oldlcr = inb((baseio)+UART_LCR); \
219 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 191 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
220 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 192 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
221 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \ 193 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
222 __efr |= MOXA_MUST_EFR_BANK0; \ 194 __efr |= MOXA_MUST_EFR_BANK0; \
223 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 195 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
224 outb((u8)(Value), (baseio)+MOXA_MUST_XON2_REGISTER); \
225 outb(__oldlcr, (baseio)+UART_LCR); \
226}
227
228#define SET_MOXA_MUST_XOFF1_VALUE(baseio, Value) { \
229 u8 __oldlcr, __efr; \
230 __oldlcr = inb((baseio)+UART_LCR); \
231 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
232 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
233 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
234 __efr |= MOXA_MUST_EFR_BANK0; \
235 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
236 outb((u8)(Value), (baseio)+MOXA_MUST_XOFF1_REGISTER); \ 196 outb((u8)(Value), (baseio)+MOXA_MUST_XOFF1_REGISTER); \
237 outb(__oldlcr, (baseio)+UART_LCR); \ 197 outb(__oldlcr, (baseio)+UART_LCR); \
238} 198} while (0)
239 199
240#define SET_MOXA_MUST_XOFF2_VALUE(baseio, Value) { \ 200#define SET_MOXA_MUST_FIFO_VALUE(info) do { \
241 u8 __oldlcr, __efr; \ 201 u8 __oldlcr, __efr; \
242 __oldlcr = inb((baseio)+UART_LCR); \ 202 __oldlcr = inb((info)->ioaddr+UART_LCR); \
243 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 203 outb(MOXA_MUST_ENTER_ENCHANCE, (info)->ioaddr+UART_LCR);\
244 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
245 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
246 __efr |= MOXA_MUST_EFR_BANK0; \
247 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
248 outb((u8)(Value), (baseio)+MOXA_MUST_XOFF2_REGISTER); \
249 outb(__oldlcr, (baseio)+UART_LCR); \
250}
251
252#define SET_MOXA_MUST_RBRTL_VALUE(baseio, Value) { \
253 u8 __oldlcr, __efr; \
254 __oldlcr = inb((baseio)+UART_LCR); \
255 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
256 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
257 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
258 __efr |= MOXA_MUST_EFR_BANK1; \
259 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
260 outb((u8)(Value), (baseio)+MOXA_MUST_RBRTL_REGISTER); \
261 outb(__oldlcr, (baseio)+UART_LCR); \
262}
263
264#define SET_MOXA_MUST_RBRTH_VALUE(baseio, Value) { \
265 u8 __oldlcr, __efr; \
266 __oldlcr = inb((baseio)+UART_LCR); \
267 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
268 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
269 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
270 __efr |= MOXA_MUST_EFR_BANK1; \
271 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
272 outb((u8)(Value), (baseio)+MOXA_MUST_RBRTH_REGISTER); \
273 outb(__oldlcr, (baseio)+UART_LCR); \
274}
275
276#define SET_MOXA_MUST_RBRTI_VALUE(baseio, Value) { \
277 u8 __oldlcr, __efr; \
278 __oldlcr = inb((baseio)+UART_LCR); \
279 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
280 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
281 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
282 __efr |= MOXA_MUST_EFR_BANK1; \
283 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
284 outb((u8)(Value), (baseio)+MOXA_MUST_RBRTI_REGISTER); \
285 outb(__oldlcr, (baseio)+UART_LCR); \
286}
287
288#define SET_MOXA_MUST_THRTL_VALUE(baseio, Value) { \
289 u8 __oldlcr, __efr; \
290 __oldlcr = inb((baseio)+UART_LCR); \
291 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
292 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
293 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
294 __efr |= MOXA_MUST_EFR_BANK1; \
295 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
296 outb((u8)(Value), (baseio)+MOXA_MUST_THRTL_REGISTER); \
297 outb(__oldlcr, (baseio)+UART_LCR); \
298}
299
300//#define MOXA_MUST_RBRL_VALUE 4
301#define SET_MOXA_MUST_FIFO_VALUE(info) { \
302 u8 __oldlcr, __efr; \
303 __oldlcr = inb((info)->ioaddr+UART_LCR); \
304 outb(MOXA_MUST_ENTER_ENCHANCE, (info)->ioaddr+UART_LCR); \
305 __efr = inb((info)->ioaddr+MOXA_MUST_EFR_REGISTER); \ 204 __efr = inb((info)->ioaddr+MOXA_MUST_EFR_REGISTER); \
306 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \ 205 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
307 __efr |= MOXA_MUST_EFR_BANK1; \ 206 __efr |= MOXA_MUST_EFR_BANK1; \
308 outb(__efr, (info)->ioaddr+MOXA_MUST_EFR_REGISTER); \ 207 outb(__efr, (info)->ioaddr+MOXA_MUST_EFR_REGISTER); \
309 outb((u8)((info)->rx_high_water), (info)->ioaddr+MOXA_MUST_RBRTH_REGISTER); \ 208 outb((u8)((info)->rx_high_water), (info)->ioaddr+ \
310 outb((u8)((info)->rx_trigger), (info)->ioaddr+MOXA_MUST_RBRTI_REGISTER); \ 209 MOXA_MUST_RBRTH_REGISTER); \
311 outb((u8)((info)->rx_low_water), (info)->ioaddr+MOXA_MUST_RBRTL_REGISTER); \ 210 outb((u8)((info)->rx_trigger), (info)->ioaddr+ \
312 outb(__oldlcr, (info)->ioaddr+UART_LCR); \ 211 MOXA_MUST_RBRTI_REGISTER); \
313} 212 outb((u8)((info)->rx_low_water), (info)->ioaddr+ \
314 213 MOXA_MUST_RBRTL_REGISTER); \
315 214 outb(__oldlcr, (info)->ioaddr+UART_LCR); \
316 215} while (0)
317#define SET_MOXA_MUST_ENUM_VALUE(baseio, Value) { \ 216
318 u8 __oldlcr, __efr; \ 217#define SET_MOXA_MUST_ENUM_VALUE(baseio, Value) do { \
319 __oldlcr = inb((baseio)+UART_LCR); \ 218 u8 __oldlcr, __efr; \
219 __oldlcr = inb((baseio)+UART_LCR); \
320 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 220 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
321 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 221 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
322 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \ 222 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
323 __efr |= MOXA_MUST_EFR_BANK2; \ 223 __efr |= MOXA_MUST_EFR_BANK2; \
324 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 224 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
325 outb((u8)(Value), (baseio)+MOXA_MUST_ENUM_REGISTER); \ 225 outb((u8)(Value), (baseio)+MOXA_MUST_ENUM_REGISTER); \
326 outb(__oldlcr, (baseio)+UART_LCR); \ 226 outb(__oldlcr, (baseio)+UART_LCR); \
327} 227} while (0)
328 228
329#define GET_MOXA_MUST_HARDWARE_ID(baseio, pId) { \ 229#define GET_MOXA_MUST_HARDWARE_ID(baseio, pId) do { \
330 u8 __oldlcr, __efr; \ 230 u8 __oldlcr, __efr; \
331 __oldlcr = inb((baseio)+UART_LCR); \ 231 __oldlcr = inb((baseio)+UART_LCR); \
332 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
333 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
334 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
335 __efr |= MOXA_MUST_EFR_BANK2; \
336 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
337 *pId = inb((baseio)+MOXA_MUST_HWID_REGISTER); \
338 outb(__oldlcr, (baseio)+UART_LCR); \
339}
340
341#define SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(baseio) { \
342 u8 __oldlcr, __efr; \
343 __oldlcr = inb((baseio)+UART_LCR); \
344 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
345 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
346 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
347 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
348 outb(__oldlcr, (baseio)+UART_LCR); \
349}
350
351#define SET_MOXA_MUST_JUST_TX_SOFTWARE_FLOW_CONTROL(baseio) { \
352 u8 __oldlcr, __efr; \
353 __oldlcr = inb((baseio)+UART_LCR); \
354 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 232 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
355 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 233 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
356 __efr &= ~MOXA_MUST_EFR_SF_MASK; \ 234 __efr &= ~MOXA_MUST_EFR_BANK_MASK; \
357 __efr |= MOXA_MUST_EFR_SF_TX1; \ 235 __efr |= MOXA_MUST_EFR_BANK2; \
358 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 236 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
359 outb(__oldlcr, (baseio)+UART_LCR); \ 237 *pId = inb((baseio)+MOXA_MUST_HWID_REGISTER); \
360} 238 outb(__oldlcr, (baseio)+UART_LCR); \
361 239} while (0)
362#define ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) { \ 240
363 u8 __oldlcr, __efr; \ 241#define SET_MOXA_MUST_NO_SOFTWARE_FLOW_CONTROL(baseio) do { \
364 __oldlcr = inb((baseio)+UART_LCR); \ 242 u8 __oldlcr, __efr; \
243 __oldlcr = inb((baseio)+UART_LCR); \
365 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 244 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
366 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 245 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
367 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \ 246 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
368 __efr |= MOXA_MUST_EFR_SF_TX1; \ 247 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
369 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 248 outb(__oldlcr, (baseio)+UART_LCR); \
370 outb(__oldlcr, (baseio)+UART_LCR); \ 249} while (0)
371} 250
372 251#define ENABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) do { \
373#define DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) { \ 252 u8 __oldlcr, __efr; \
374 u8 __oldlcr, __efr; \ 253 __oldlcr = inb((baseio)+UART_LCR); \
375 __oldlcr = inb((baseio)+UART_LCR); \
376 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 254 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
377 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 255 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
378 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \ 256 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \
379 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 257 __efr |= MOXA_MUST_EFR_SF_TX1; \
380 outb(__oldlcr, (baseio)+UART_LCR); \ 258 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
381} 259 outb(__oldlcr, (baseio)+UART_LCR); \
382 260} while (0)
383#define SET_MOXA_MUST_JUST_RX_SOFTWARE_FLOW_CONTROL(baseio) { \ 261
384 u8 __oldlcr, __efr; \ 262#define DISABLE_MOXA_MUST_TX_SOFTWARE_FLOW_CONTROL(baseio) do { \
385 __oldlcr = inb((baseio)+UART_LCR); \ 263 u8 __oldlcr, __efr; \
264 __oldlcr = inb((baseio)+UART_LCR); \
386 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 265 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
387 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 266 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
388 __efr &= ~MOXA_MUST_EFR_SF_MASK; \ 267 __efr &= ~MOXA_MUST_EFR_SF_TX_MASK; \
389 __efr |= MOXA_MUST_EFR_SF_RX1; \ 268 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
390 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 269 outb(__oldlcr, (baseio)+UART_LCR); \
391 outb(__oldlcr, (baseio)+UART_LCR); \ 270} while (0)
392} 271
393 272#define ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) do { \
394#define ENABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) { \ 273 u8 __oldlcr, __efr; \
395 u8 __oldlcr, __efr; \ 274 __oldlcr = inb((baseio)+UART_LCR); \
396 __oldlcr = inb((baseio)+UART_LCR); \
397 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 275 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
398 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 276 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
399 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \ 277 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \
400 __efr |= MOXA_MUST_EFR_SF_RX1; \ 278 __efr |= MOXA_MUST_EFR_SF_RX1; \
401 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 279 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
402 outb(__oldlcr, (baseio)+UART_LCR); \ 280 outb(__oldlcr, (baseio)+UART_LCR); \
403} 281} while (0)
404 282
405#define DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) { \ 283#define DISABLE_MOXA_MUST_RX_SOFTWARE_FLOW_CONTROL(baseio) do { \
406 u8 __oldlcr, __efr; \ 284 u8 __oldlcr, __efr; \
407 __oldlcr = inb((baseio)+UART_LCR); \ 285 __oldlcr = inb((baseio)+UART_LCR); \
408 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \ 286 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
409 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \ 287 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
410 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \ 288 __efr &= ~MOXA_MUST_EFR_SF_RX_MASK; \
411 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \ 289 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
412 outb(__oldlcr, (baseio)+UART_LCR); \ 290 outb(__oldlcr, (baseio)+UART_LCR); \
413} 291} while (0)
414
415#define ENABLE_MOXA_MUST_TX_RX_SOFTWARE_FLOW_CONTROL(baseio) { \
416 u8 __oldlcr, __efr; \
417 __oldlcr = inb((baseio)+UART_LCR); \
418 outb(MOXA_MUST_ENTER_ENCHANCE, (baseio)+UART_LCR); \
419 __efr = inb((baseio)+MOXA_MUST_EFR_REGISTER); \
420 __efr &= ~MOXA_MUST_EFR_SF_MASK; \
421 __efr |= (MOXA_MUST_EFR_SF_RX1|MOXA_MUST_EFR_SF_TX1); \
422 outb(__efr, (baseio)+MOXA_MUST_EFR_REGISTER); \
423 outb(__oldlcr, (baseio)+UART_LCR); \
424}
425
426#define ENABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(baseio) { \
427 u8 __oldmcr; \
428 __oldmcr = inb((baseio)+UART_MCR); \
429 __oldmcr |= MOXA_MUST_MCR_XON_ANY; \
430 outb(__oldmcr, (baseio)+UART_MCR); \
431}
432
433#define DISABLE_MOXA_MUST_XON_ANY_FLOW_CONTROL(baseio) { \
434 u8 __oldmcr; \
435 __oldmcr = inb((baseio)+UART_MCR); \
436 __oldmcr &= ~MOXA_MUST_MCR_XON_ANY; \
437 outb(__oldmcr, (baseio)+UART_MCR); \
438}
439
440#define READ_MOXA_MUST_GDL(baseio) inb((baseio)+MOXA_MUST_GDL_REGISTER)
441
442
443#ifndef INIT_WORK
444#define INIT_WORK(_work, _func, _data){ \
445 _data->tqueue.routine = _func;\
446 _data->tqueue.data = _data;\
447 }
448#endif
449 292
450#endif 293#endif
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index dc6d4184145..65f2d3a96b8 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -60,62 +60,56 @@
60#include <linux/slab.h> 60#include <linux/slab.h>
61#include <linux/tty.h> 61#include <linux/tty.h>
62#include <linux/errno.h> 62#include <linux/errno.h>
63#include <linux/string.h> /* used in new tty drivers */ 63#include <linux/string.h> /* used in new tty drivers */
64#include <linux/signal.h> /* used in new tty drivers */ 64#include <linux/signal.h> /* used in new tty drivers */
65#include <linux/ioctl.h> 65#include <linux/ioctl.h>
66#include <linux/n_r3964.h> 66#include <linux/n_r3964.h>
67#include <linux/poll.h> 67#include <linux/poll.h>
68#include <linux/init.h> 68#include <linux/init.h>
69#include <asm/uaccess.h> 69#include <asm/uaccess.h>
70 70
71 71/*#define DEBUG_QUEUE*/
72//#define DEBUG_QUEUE
73 72
74/* Log successful handshake and protocol operations */ 73/* Log successful handshake and protocol operations */
75//#define DEBUG_PROTO_S 74/*#define DEBUG_PROTO_S*/
76 75
77/* Log handshake and protocol errors: */ 76/* Log handshake and protocol errors: */
78//#define DEBUG_PROTO_E 77/*#define DEBUG_PROTO_E*/
79 78
80/* Log Linediscipline operations (open, close, read, write...): */ 79/* Log Linediscipline operations (open, close, read, write...): */
81//#define DEBUG_LDISC 80/*#define DEBUG_LDISC*/
82 81
83/* Log module and memory operations (init, cleanup; kmalloc, kfree): */ 82/* Log module and memory operations (init, cleanup; kmalloc, kfree): */
84//#define DEBUG_MODUL 83/*#define DEBUG_MODUL*/
85 84
86/* Macro helpers for debug output: */ 85/* Macro helpers for debug output: */
87#define TRACE(format, args...) printk("r3964: " format "\n" , ## args); 86#define TRACE(format, args...) printk("r3964: " format "\n" , ## args)
88 87
89#ifdef DEBUG_MODUL 88#ifdef DEBUG_MODUL
90#define TRACE_M(format, args...) printk("r3964: " format "\n" , ## args); 89#define TRACE_M(format, args...) printk("r3964: " format "\n" , ## args)
91#else 90#else
92#define TRACE_M(fmt, arg...) /**/ 91#define TRACE_M(fmt, arg...) do {} while (0)
93#endif 92#endif
94
95#ifdef DEBUG_PROTO_S 93#ifdef DEBUG_PROTO_S
96#define TRACE_PS(format, args...) printk("r3964: " format "\n" , ## args); 94#define TRACE_PS(format, args...) printk("r3964: " format "\n" , ## args)
97#else 95#else
98#define TRACE_PS(fmt, arg...) /**/ 96#define TRACE_PS(fmt, arg...) do {} while (0)
99#endif 97#endif
100
101#ifdef DEBUG_PROTO_E 98#ifdef DEBUG_PROTO_E
102#define TRACE_PE(format, args...) printk("r3964: " format "\n" , ## args); 99#define TRACE_PE(format, args...) printk("r3964: " format "\n" , ## args)
103#else 100#else
104#define TRACE_PE(fmt, arg...) /**/ 101#define TRACE_PE(fmt, arg...) do {} while (0)
105#endif 102#endif
106
107#ifdef DEBUG_LDISC 103#ifdef DEBUG_LDISC
108#define TRACE_L(format, args...) printk("r3964: " format "\n" , ## args); 104#define TRACE_L(format, args...) printk("r3964: " format "\n" , ## args)
109#else 105#else
110#define TRACE_L(fmt, arg...) /**/ 106#define TRACE_L(fmt, arg...) do {} while (0)
111#endif 107#endif
112
113#ifdef DEBUG_QUEUE 108#ifdef DEBUG_QUEUE
114#define TRACE_Q(format, args...) printk("r3964: " format "\n" , ## args); 109#define TRACE_Q(format, args...) printk("r3964: " format "\n" , ## args)
115#else 110#else
116#define TRACE_Q(fmt, arg...) /**/ 111#define TRACE_Q(fmt, arg...) do {} while (0)
117#endif 112#endif
118
119static void add_tx_queue(struct r3964_info *, struct r3964_block_header *); 113static void add_tx_queue(struct r3964_info *, struct r3964_block_header *);
120static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code); 114static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code);
121static void put_char(struct r3964_info *pInfo, unsigned char ch); 115static void put_char(struct r3964_info *pInfo, unsigned char ch);
@@ -126,937 +120,830 @@ static void receive_char(struct r3964_info *pInfo, const unsigned char c);
126static void receive_error(struct r3964_info *pInfo, const char flag); 120static void receive_error(struct r3964_info *pInfo, const char flag);
127static void on_timeout(unsigned long priv); 121static void on_timeout(unsigned long priv);
128static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg); 122static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg);
129static int read_telegram(struct r3964_info *pInfo, struct pid *pid, unsigned char __user *buf); 123static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
124 unsigned char __user * buf);
130static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg, 125static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
131 int error_code, struct r3964_block_header *pBlock); 126 int error_code, struct r3964_block_header *pBlock);
132static struct r3964_message* remove_msg(struct r3964_info *pInfo, 127static struct r3964_message *remove_msg(struct r3964_info *pInfo,
133 struct r3964_client_info *pClient); 128 struct r3964_client_info *pClient);
134static void remove_client_block(struct r3964_info *pInfo, 129static void remove_client_block(struct r3964_info *pInfo,
135 struct r3964_client_info *pClient); 130 struct r3964_client_info *pClient);
136 131
137static int r3964_open(struct tty_struct *tty); 132static int r3964_open(struct tty_struct *tty);
138static void r3964_close(struct tty_struct *tty); 133static void r3964_close(struct tty_struct *tty);
139static ssize_t r3964_read(struct tty_struct *tty, struct file *file, 134static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
140 unsigned char __user *buf, size_t nr); 135 unsigned char __user * buf, size_t nr);
141static ssize_t r3964_write(struct tty_struct * tty, struct file * file, 136static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
142 const unsigned char * buf, size_t nr); 137 const unsigned char *buf, size_t nr);
143static int r3964_ioctl(struct tty_struct * tty, struct file * file, 138static int r3964_ioctl(struct tty_struct *tty, struct file *file,
144 unsigned int cmd, unsigned long arg); 139 unsigned int cmd, unsigned long arg);
145static void r3964_set_termios(struct tty_struct *tty, struct ktermios * old); 140static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old);
146static unsigned int r3964_poll(struct tty_struct * tty, struct file * file, 141static unsigned int r3964_poll(struct tty_struct *tty, struct file *file,
147 struct poll_table_struct *wait); 142 struct poll_table_struct *wait);
148static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp, 143static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
149 char *fp, int count); 144 char *fp, int count);
150 145
151static struct tty_ldisc tty_ldisc_N_R3964 = { 146static struct tty_ldisc tty_ldisc_N_R3964 = {
152 .owner = THIS_MODULE, 147 .owner = THIS_MODULE,
153 .magic = TTY_LDISC_MAGIC, 148 .magic = TTY_LDISC_MAGIC,
154 .name = "R3964", 149 .name = "R3964",
155 .open = r3964_open, 150 .open = r3964_open,
156 .close = r3964_close, 151 .close = r3964_close,
157 .read = r3964_read, 152 .read = r3964_read,
158 .write = r3964_write, 153 .write = r3964_write,
159 .ioctl = r3964_ioctl, 154 .ioctl = r3964_ioctl,
160 .set_termios = r3964_set_termios, 155 .set_termios = r3964_set_termios,
161 .poll = r3964_poll, 156 .poll = r3964_poll,
162 .receive_buf = r3964_receive_buf, 157 .receive_buf = r3964_receive_buf,
163}; 158};
164 159
165
166
167static void dump_block(const unsigned char *block, unsigned int length) 160static void dump_block(const unsigned char *block, unsigned int length)
168{ 161{
169 unsigned int i,j; 162 unsigned int i, j;
170 char linebuf[16*3+1]; 163 char linebuf[16 * 3 + 1];
171 164
172 for(i=0;i<length;i+=16) 165 for (i = 0; i < length; i += 16) {
173 { 166 for (j = 0; (j < 16) && (j + i < length); j++) {
174 for(j=0;(j<16) && (j+i<length);j++) 167 sprintf(linebuf + 3 * j, "%02x ", block[i + j]);
175 { 168 }
176 sprintf(linebuf+3*j,"%02x ",block[i+j]); 169 linebuf[3 * j] = '\0';
177 } 170 TRACE_PS("%s", linebuf);
178 linebuf[3*j]='\0'; 171 }
179 TRACE_PS("%s",linebuf);
180 }
181} 172}
182 173
183
184
185
186/************************************************************* 174/*************************************************************
187 * Driver initialisation 175 * Driver initialisation
188 *************************************************************/ 176 *************************************************************/
189 177
190
191/************************************************************* 178/*************************************************************
192 * Module support routines 179 * Module support routines
193 *************************************************************/ 180 *************************************************************/
194 181
195static void __exit r3964_exit(void) 182static void __exit r3964_exit(void)
196{ 183{
197 int status; 184 int status;
198 185
199 TRACE_M ("cleanup_module()"); 186 TRACE_M("cleanup_module()");
200 187
201 status=tty_unregister_ldisc(N_R3964); 188 status = tty_unregister_ldisc(N_R3964);
202 189
203 if(status!=0) 190 if (status != 0) {
204 { 191 printk(KERN_ERR "r3964: error unregistering linediscipline: "
205 printk(KERN_ERR "r3964: error unregistering linediscipline: %d\n", status); 192 "%d\n", status);
206 } 193 } else {
207 else 194 TRACE_L("linediscipline successfully unregistered");
208 { 195 }
209 TRACE_L("linediscipline successfully unregistered");
210 }
211
212} 196}
213 197
214static int __init r3964_init(void) 198static int __init r3964_init(void)
215{ 199{
216 int status; 200 int status;
217 201
218 printk ("r3964: Philips r3964 Driver $Revision: 1.10 $\n"); 202 printk("r3964: Philips r3964 Driver $Revision: 1.10 $\n");
219 203
220 /* 204 /*
221 * Register the tty line discipline 205 * Register the tty line discipline
222 */ 206 */
223 207
224 status = tty_register_ldisc (N_R3964, &tty_ldisc_N_R3964); 208 status = tty_register_ldisc(N_R3964, &tty_ldisc_N_R3964);
225 if (status == 0) 209 if (status == 0) {
226 { 210 TRACE_L("line discipline %d registered", N_R3964);
227 TRACE_L("line discipline %d registered", N_R3964); 211 TRACE_L("flags=%x num=%x", tty_ldisc_N_R3964.flags,
228 TRACE_L("flags=%x num=%x", tty_ldisc_N_R3964.flags, 212 tty_ldisc_N_R3964.num);
229 tty_ldisc_N_R3964.num); 213 TRACE_L("open=%p", tty_ldisc_N_R3964.open);
230 TRACE_L("open=%p", tty_ldisc_N_R3964.open); 214 TRACE_L("tty_ldisc_N_R3964 = %p", &tty_ldisc_N_R3964);
231 TRACE_L("tty_ldisc_N_R3964 = %p", &tty_ldisc_N_R3964); 215 } else {
232 } 216 printk(KERN_ERR "r3964: error registering line discipline: "
233 else 217 "%d\n", status);
234 { 218 }
235 printk (KERN_ERR "r3964: error registering line discipline: %d\n", status); 219 return status;
236 }
237 return status;
238} 220}
239 221
240module_init(r3964_init); 222module_init(r3964_init);
241module_exit(r3964_exit); 223module_exit(r3964_exit);
242 224
243
244/************************************************************* 225/*************************************************************
245 * Protocol implementation routines 226 * Protocol implementation routines
246 *************************************************************/ 227 *************************************************************/
247 228
248static void add_tx_queue(struct r3964_info *pInfo, struct r3964_block_header *pHeader) 229static void add_tx_queue(struct r3964_info *pInfo,
230 struct r3964_block_header *pHeader)
249{ 231{
250 unsigned long flags; 232 unsigned long flags;
251 233
252 spin_lock_irqsave(&pInfo->lock, flags); 234 spin_lock_irqsave(&pInfo->lock, flags);
253 235
254 pHeader->next = NULL; 236 pHeader->next = NULL;
255 237
256 if(pInfo->tx_last == NULL) 238 if (pInfo->tx_last == NULL) {
257 { 239 pInfo->tx_first = pInfo->tx_last = pHeader;
258 pInfo->tx_first = pInfo->tx_last = pHeader; 240 } else {
259 } 241 pInfo->tx_last->next = pHeader;
260 else 242 pInfo->tx_last = pHeader;
261 { 243 }
262 pInfo->tx_last->next = pHeader; 244
263 pInfo->tx_last = pHeader; 245 spin_unlock_irqrestore(&pInfo->lock, flags);
264 } 246
265 247 TRACE_Q("add_tx_queue %p, length %d, tx_first = %p",
266 spin_unlock_irqrestore(&pInfo->lock, flags); 248 pHeader, pHeader->length, pInfo->tx_first);
267
268 TRACE_Q("add_tx_queue %p, length %d, tx_first = %p",
269 pHeader, pHeader->length, pInfo->tx_first );
270} 249}
271 250
272static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code) 251static void remove_from_tx_queue(struct r3964_info *pInfo, int error_code)
273{ 252{
274 struct r3964_block_header *pHeader; 253 struct r3964_block_header *pHeader;
275 unsigned long flags; 254 unsigned long flags;
276#ifdef DEBUG_QUEUE 255#ifdef DEBUG_QUEUE
277 struct r3964_block_header *pDump; 256 struct r3964_block_header *pDump;
278#endif 257#endif
279
280 pHeader = pInfo->tx_first;
281 258
282 if(pHeader==NULL) 259 pHeader = pInfo->tx_first;
283 return; 260
261 if (pHeader == NULL)
262 return;
284 263
285#ifdef DEBUG_QUEUE 264#ifdef DEBUG_QUEUE
286 printk("r3964: remove_from_tx_queue: %p, length %u - ", 265 printk("r3964: remove_from_tx_queue: %p, length %u - ",
287 pHeader, pHeader->length ); 266 pHeader, pHeader->length);
288 for(pDump=pHeader;pDump;pDump=pDump->next) 267 for (pDump = pHeader; pDump; pDump = pDump->next)
289 printk("%p ", pDump); 268 printk("%p ", pDump);
290 printk("\n"); 269 printk("\n");
291#endif 270#endif
292 271
272 if (pHeader->owner) {
273 if (error_code) {
274 add_msg(pHeader->owner, R3964_MSG_ACK, 0,
275 error_code, NULL);
276 } else {
277 add_msg(pHeader->owner, R3964_MSG_ACK, pHeader->length,
278 error_code, NULL);
279 }
280 wake_up_interruptible(&pInfo->read_wait);
281 }
282
283 spin_lock_irqsave(&pInfo->lock, flags);
284
285 pInfo->tx_first = pHeader->next;
286 if (pInfo->tx_first == NULL) {
287 pInfo->tx_last = NULL;
288 }
289
290 spin_unlock_irqrestore(&pInfo->lock, flags);
291
292 kfree(pHeader);
293 TRACE_M("remove_from_tx_queue - kfree %p", pHeader);
293 294
294 if(pHeader->owner) 295 TRACE_Q("remove_from_tx_queue: tx_first = %p, tx_last = %p",
295 { 296 pInfo->tx_first, pInfo->tx_last);
296 if(error_code)
297 {
298 add_msg(pHeader->owner, R3964_MSG_ACK, 0,
299 error_code, NULL);
300 }
301 else
302 {
303 add_msg(pHeader->owner, R3964_MSG_ACK, pHeader->length,
304 error_code, NULL);
305 }
306 wake_up_interruptible (&pInfo->read_wait);
307 }
308
309 spin_lock_irqsave(&pInfo->lock, flags);
310
311 pInfo->tx_first = pHeader->next;
312 if(pInfo->tx_first==NULL)
313 {
314 pInfo->tx_last = NULL;
315 }
316
317 spin_unlock_irqrestore(&pInfo->lock, flags);
318
319 kfree(pHeader);
320 TRACE_M("remove_from_tx_queue - kfree %p",pHeader);
321
322 TRACE_Q("remove_from_tx_queue: tx_first = %p, tx_last = %p",
323 pInfo->tx_first, pInfo->tx_last );
324} 297}
325 298
326static void add_rx_queue(struct r3964_info *pInfo, struct r3964_block_header *pHeader) 299static void add_rx_queue(struct r3964_info *pInfo,
300 struct r3964_block_header *pHeader)
327{ 301{
328 unsigned long flags; 302 unsigned long flags;
329 303
330 spin_lock_irqsave(&pInfo->lock, flags); 304 spin_lock_irqsave(&pInfo->lock, flags);
331 305
332 pHeader->next = NULL; 306 pHeader->next = NULL;
333 307
334 if(pInfo->rx_last == NULL) 308 if (pInfo->rx_last == NULL) {
335 { 309 pInfo->rx_first = pInfo->rx_last = pHeader;
336 pInfo->rx_first = pInfo->rx_last = pHeader; 310 } else {
337 } 311 pInfo->rx_last->next = pHeader;
338 else 312 pInfo->rx_last = pHeader;
339 { 313 }
340 pInfo->rx_last->next = pHeader; 314 pInfo->blocks_in_rx_queue++;
341 pInfo->rx_last = pHeader; 315
342 } 316 spin_unlock_irqrestore(&pInfo->lock, flags);
343 pInfo->blocks_in_rx_queue++; 317
344 318 TRACE_Q("add_rx_queue: %p, length = %d, rx_first = %p, count = %d",
345 spin_unlock_irqrestore(&pInfo->lock, flags); 319 pHeader, pHeader->length,
346 320 pInfo->rx_first, pInfo->blocks_in_rx_queue);
347 TRACE_Q("add_rx_queue: %p, length = %d, rx_first = %p, count = %d",
348 pHeader, pHeader->length,
349 pInfo->rx_first, pInfo->blocks_in_rx_queue);
350} 321}
351 322
352static void remove_from_rx_queue(struct r3964_info *pInfo, 323static void remove_from_rx_queue(struct r3964_info *pInfo,
353 struct r3964_block_header *pHeader) 324 struct r3964_block_header *pHeader)
354{ 325{
355 unsigned long flags; 326 unsigned long flags;
356 struct r3964_block_header *pFind; 327 struct r3964_block_header *pFind;
357 328
358 if(pHeader==NULL) 329 if (pHeader == NULL)
359 return; 330 return;
360 331
361 TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d", 332 TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d",
362 pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue ); 333 pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue);
363 TRACE_Q("remove_from_rx_queue: %p, length %u", 334 TRACE_Q("remove_from_rx_queue: %p, length %u",
364 pHeader, pHeader->length ); 335 pHeader, pHeader->length);
365 336
366 spin_lock_irqsave(&pInfo->lock, flags); 337 spin_lock_irqsave(&pInfo->lock, flags);
367 338
368 if(pInfo->rx_first == pHeader) 339 if (pInfo->rx_first == pHeader) {
369 { 340 /* Remove the first block in the linked list: */
370 /* Remove the first block in the linked list: */ 341 pInfo->rx_first = pHeader->next;
371 pInfo->rx_first = pHeader->next; 342
372 343 if (pInfo->rx_first == NULL) {
373 if(pInfo->rx_first==NULL) 344 pInfo->rx_last = NULL;
374 { 345 }
375 pInfo->rx_last = NULL; 346 pInfo->blocks_in_rx_queue--;
376 } 347 } else {
377 pInfo->blocks_in_rx_queue--; 348 /* Find block to remove: */
378 } 349 for (pFind = pInfo->rx_first; pFind; pFind = pFind->next) {
379 else 350 if (pFind->next == pHeader) {
380 { 351 /* Got it. */
381 /* Find block to remove: */ 352 pFind->next = pHeader->next;
382 for(pFind=pInfo->rx_first; pFind; pFind=pFind->next) 353 pInfo->blocks_in_rx_queue--;
383 { 354 if (pFind->next == NULL) {
384 if(pFind->next == pHeader) 355 /* Oh, removed the last one! */
385 { 356 pInfo->rx_last = pFind;
386 /* Got it. */ 357 }
387 pFind->next = pHeader->next; 358 break;
388 pInfo->blocks_in_rx_queue--; 359 }
389 if(pFind->next==NULL) 360 }
390 { 361 }
391 /* Oh, removed the last one! */ 362
392 pInfo->rx_last = pFind; 363 spin_unlock_irqrestore(&pInfo->lock, flags);
393 } 364
394 break; 365 kfree(pHeader);
395 } 366 TRACE_M("remove_from_rx_queue - kfree %p", pHeader);
396 } 367
397 } 368 TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d",
398 369 pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue);
399 spin_unlock_irqrestore(&pInfo->lock, flags);
400
401 kfree(pHeader);
402 TRACE_M("remove_from_rx_queue - kfree %p",pHeader);
403
404 TRACE_Q("remove_from_rx_queue: rx_first = %p, rx_last = %p, count = %d",
405 pInfo->rx_first, pInfo->rx_last, pInfo->blocks_in_rx_queue );
406} 370}
407 371
408static void put_char(struct r3964_info *pInfo, unsigned char ch) 372static void put_char(struct r3964_info *pInfo, unsigned char ch)
409{ 373{
410 struct tty_struct *tty = pInfo->tty; 374 struct tty_struct *tty = pInfo->tty;
411 375
412 if(tty==NULL) 376 if (tty == NULL)
413 return; 377 return;
414 378
415 if(tty->driver->put_char) 379 if (tty->driver->put_char) {
416 { 380 tty->driver->put_char(tty, ch);
417 tty->driver->put_char(tty, ch); 381 }
418 } 382 pInfo->bcc ^= ch;
419 pInfo->bcc ^= ch;
420} 383}
421 384
422static void flush(struct r3964_info *pInfo) 385static void flush(struct r3964_info *pInfo)
423{ 386{
424 struct tty_struct *tty = pInfo->tty; 387 struct tty_struct *tty = pInfo->tty;
425 388
426 if(tty==NULL) 389 if (tty == NULL)
427 return; 390 return;
428 391
429 if(tty->driver->flush_chars) 392 if (tty->driver->flush_chars) {
430 { 393 tty->driver->flush_chars(tty);
431 tty->driver->flush_chars(tty); 394 }
432 }
433} 395}
434 396
435static void trigger_transmit(struct r3964_info *pInfo) 397static void trigger_transmit(struct r3964_info *pInfo)
436{ 398{
437 unsigned long flags; 399 unsigned long flags;
438
439 400
440 spin_lock_irqsave(&pInfo->lock, flags); 401 spin_lock_irqsave(&pInfo->lock, flags);
441 402
442 if((pInfo->state == R3964_IDLE) && (pInfo->tx_first!=NULL)) 403 if ((pInfo->state == R3964_IDLE) && (pInfo->tx_first != NULL)) {
443 { 404 pInfo->state = R3964_TX_REQUEST;
444 pInfo->state = R3964_TX_REQUEST; 405 pInfo->nRetry = 0;
445 pInfo->nRetry=0; 406 pInfo->flags &= ~R3964_ERROR;
446 pInfo->flags &= ~R3964_ERROR; 407 mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
447 mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
448 408
449 spin_unlock_irqrestore(&pInfo->lock, flags); 409 spin_unlock_irqrestore(&pInfo->lock, flags);
450 410
451 TRACE_PS("trigger_transmit - sent STX"); 411 TRACE_PS("trigger_transmit - sent STX");
452 412
453 put_char(pInfo, STX); 413 put_char(pInfo, STX);
454 flush(pInfo); 414 flush(pInfo);
455 415
456 pInfo->bcc = 0; 416 pInfo->bcc = 0;
457 } 417 } else {
458 else 418 spin_unlock_irqrestore(&pInfo->lock, flags);
459 { 419 }
460 spin_unlock_irqrestore(&pInfo->lock, flags);
461 }
462} 420}
463 421
464static void retry_transmit(struct r3964_info *pInfo) 422static void retry_transmit(struct r3964_info *pInfo)
465{ 423{
466 if(pInfo->nRetry<R3964_MAX_RETRIES) 424 if (pInfo->nRetry < R3964_MAX_RETRIES) {
467 { 425 TRACE_PE("transmission failed. Retry #%d", pInfo->nRetry);
468 TRACE_PE("transmission failed. Retry #%d", 426 pInfo->bcc = 0;
469 pInfo->nRetry); 427 put_char(pInfo, STX);
470 pInfo->bcc = 0; 428 flush(pInfo);
471 put_char(pInfo, STX); 429 pInfo->state = R3964_TX_REQUEST;
472 flush(pInfo); 430 pInfo->nRetry++;
473 pInfo->state = R3964_TX_REQUEST; 431 mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
474 pInfo->nRetry++; 432 } else {
475 mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ); 433 TRACE_PE("transmission failed after %d retries",
476 } 434 R3964_MAX_RETRIES);
477 else 435
478 { 436 remove_from_tx_queue(pInfo, R3964_TX_FAIL);
479 TRACE_PE("transmission failed after %d retries", 437
480 R3964_MAX_RETRIES); 438 put_char(pInfo, NAK);
481 439 flush(pInfo);
482 remove_from_tx_queue(pInfo, R3964_TX_FAIL); 440 pInfo->state = R3964_IDLE;
483 441
484 put_char(pInfo, NAK); 442 trigger_transmit(pInfo);
485 flush(pInfo); 443 }
486 pInfo->state = R3964_IDLE;
487
488 trigger_transmit(pInfo);
489 }
490} 444}
491 445
492
493static void transmit_block(struct r3964_info *pInfo) 446static void transmit_block(struct r3964_info *pInfo)
494{ 447{
495 struct tty_struct *tty = pInfo->tty; 448 struct tty_struct *tty = pInfo->tty;
496 struct r3964_block_header *pBlock = pInfo->tx_first; 449 struct r3964_block_header *pBlock = pInfo->tx_first;
497 int room=0; 450 int room = 0;
498 451
499 if((tty==NULL) || (pBlock==NULL)) 452 if ((tty == NULL) || (pBlock == NULL)) {
500 { 453 return;
501 return; 454 }
502 } 455
503 456 if (tty->driver->write_room)
504 if(tty->driver->write_room) 457 room = tty->driver->write_room(tty);
505 room=tty->driver->write_room(tty); 458
506 459 TRACE_PS("transmit_block %p, room %d, length %d",
507 TRACE_PS("transmit_block %p, room %d, length %d", 460 pBlock, room, pBlock->length);
508 pBlock, room, pBlock->length); 461
509 462 while (pInfo->tx_position < pBlock->length) {
510 while(pInfo->tx_position < pBlock->length) 463 if (room < 2)
511 { 464 break;
512 if(room<2) 465
513 break; 466 if (pBlock->data[pInfo->tx_position] == DLE) {
514 467 /* send additional DLE char: */
515 if(pBlock->data[pInfo->tx_position]==DLE) 468 put_char(pInfo, DLE);
516 { 469 }
517 /* send additional DLE char: */ 470 put_char(pInfo, pBlock->data[pInfo->tx_position++]);
518 put_char(pInfo, DLE); 471
519 } 472 room--;
520 put_char(pInfo, pBlock->data[pInfo->tx_position++]); 473 }
521 474
522 room--; 475 if ((pInfo->tx_position == pBlock->length) && (room >= 3)) {
523 } 476 put_char(pInfo, DLE);
524 477 put_char(pInfo, ETX);
525 if((pInfo->tx_position == pBlock->length) && (room>=3)) 478 if (pInfo->flags & R3964_BCC) {
526 { 479 put_char(pInfo, pInfo->bcc);
527 put_char(pInfo, DLE); 480 }
528 put_char(pInfo, ETX); 481 pInfo->state = R3964_WAIT_FOR_TX_ACK;
529 if(pInfo->flags & R3964_BCC) 482 mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
530 { 483 }
531 put_char(pInfo, pInfo->bcc); 484 flush(pInfo);
532 }
533 pInfo->state = R3964_WAIT_FOR_TX_ACK;
534 mod_timer(&pInfo->tmr, jiffies + R3964_TO_QVZ);
535 }
536 flush(pInfo);
537} 485}
538 486
539static void on_receive_block(struct r3964_info *pInfo) 487static void on_receive_block(struct r3964_info *pInfo)
540{ 488{
541 unsigned int length; 489 unsigned int length;
542 struct r3964_client_info *pClient; 490 struct r3964_client_info *pClient;
543 struct r3964_block_header *pBlock; 491 struct r3964_block_header *pBlock;
544 492
545 length=pInfo->rx_position; 493 length = pInfo->rx_position;
546 494
547 /* compare byte checksum characters: */ 495 /* compare byte checksum characters: */
548 if(pInfo->flags & R3964_BCC) 496 if (pInfo->flags & R3964_BCC) {
549 { 497 if (pInfo->bcc != pInfo->last_rx) {
550 if(pInfo->bcc!=pInfo->last_rx) 498 TRACE_PE("checksum error - got %x but expected %x",
551 { 499 pInfo->last_rx, pInfo->bcc);
552 TRACE_PE("checksum error - got %x but expected %x", 500 pInfo->flags |= R3964_CHECKSUM;
553 pInfo->last_rx, pInfo->bcc); 501 }
554 pInfo->flags |= R3964_CHECKSUM; 502 }
555 } 503
556 } 504 /* check for errors (parity, overrun,...): */
557 505 if (pInfo->flags & R3964_ERROR) {
558 /* check for errors (parity, overrun,...): */ 506 TRACE_PE("on_receive_block - transmission failed error %x",
559 if(pInfo->flags & R3964_ERROR) 507 pInfo->flags & R3964_ERROR);
560 { 508
561 TRACE_PE("on_receive_block - transmission failed error %x", 509 put_char(pInfo, NAK);
562 pInfo->flags & R3964_ERROR); 510 flush(pInfo);
563 511 if (pInfo->nRetry < R3964_MAX_RETRIES) {
564 put_char(pInfo, NAK); 512 pInfo->state = R3964_WAIT_FOR_RX_REPEAT;
565 flush(pInfo); 513 pInfo->nRetry++;
566 if(pInfo->nRetry<R3964_MAX_RETRIES) 514 mod_timer(&pInfo->tmr, jiffies + R3964_TO_RX_PANIC);
567 { 515 } else {
568 pInfo->state=R3964_WAIT_FOR_RX_REPEAT; 516 TRACE_PE("on_receive_block - failed after max retries");
569 pInfo->nRetry++; 517 pInfo->state = R3964_IDLE;
570 mod_timer(&pInfo->tmr, jiffies + R3964_TO_RX_PANIC); 518 }
571 } 519 return;
572 else 520 }
573 { 521
574 TRACE_PE("on_receive_block - failed after max retries"); 522 /* received block; submit DLE: */
575 pInfo->state=R3964_IDLE; 523 put_char(pInfo, DLE);
576 } 524 flush(pInfo);
577 return; 525 del_timer_sync(&pInfo->tmr);
578 } 526 TRACE_PS(" rx success: got %d chars", length);
579 527
580 528 /* prepare struct r3964_block_header: */
581 /* received block; submit DLE: */ 529 pBlock = kmalloc(length + sizeof(struct r3964_block_header),
582 put_char(pInfo, DLE); 530 GFP_KERNEL);
583 flush(pInfo); 531 TRACE_M("on_receive_block - kmalloc %p", pBlock);
584 del_timer_sync(&pInfo->tmr); 532
585 TRACE_PS(" rx success: got %d chars", length); 533 if (pBlock == NULL)
586 534 return;
587 /* prepare struct r3964_block_header: */ 535
588 pBlock = kmalloc(length+sizeof(struct r3964_block_header), GFP_KERNEL); 536 pBlock->length = length;
589 TRACE_M("on_receive_block - kmalloc %p",pBlock); 537 pBlock->data = ((unsigned char *)pBlock) +
590 538 sizeof(struct r3964_block_header);
591 if(pBlock==NULL) 539 pBlock->locks = 0;
592 return; 540 pBlock->next = NULL;
593 541 pBlock->owner = NULL;
594 pBlock->length = length; 542
595 pBlock->data = ((unsigned char*)pBlock)+sizeof(struct r3964_block_header); 543 memcpy(pBlock->data, pInfo->rx_buf, length);
596 pBlock->locks = 0; 544
597 pBlock->next = NULL; 545 /* queue block into rx_queue: */
598 pBlock->owner = NULL; 546 add_rx_queue(pInfo, pBlock);
599 547
600 memcpy(pBlock->data, pInfo->rx_buf, length); 548 /* notify attached client processes: */
601 549 for (pClient = pInfo->firstClient; pClient; pClient = pClient->next) {
602 /* queue block into rx_queue: */ 550 if (pClient->sig_flags & R3964_SIG_DATA) {
603 add_rx_queue(pInfo, pBlock); 551 add_msg(pClient, R3964_MSG_DATA, length, R3964_OK,
604 552 pBlock);
605 /* notify attached client processes: */ 553 }
606 for(pClient=pInfo->firstClient; pClient; pClient=pClient->next) 554 }
607 { 555 wake_up_interruptible(&pInfo->read_wait);
608 if(pClient->sig_flags & R3964_SIG_DATA)
609 {
610 add_msg(pClient, R3964_MSG_DATA, length, R3964_OK, pBlock);
611 }
612 }
613 wake_up_interruptible (&pInfo->read_wait);
614
615 pInfo->state = R3964_IDLE;
616
617 trigger_transmit(pInfo);
618}
619 556
557 pInfo->state = R3964_IDLE;
558
559 trigger_transmit(pInfo);
560}
620 561
621static void receive_char(struct r3964_info *pInfo, const unsigned char c) 562static void receive_char(struct r3964_info *pInfo, const unsigned char c)
622{ 563{
623 switch(pInfo->state) 564 switch (pInfo->state) {
624 { 565 case R3964_TX_REQUEST:
625 case R3964_TX_REQUEST: 566 if (c == DLE) {
626 if(c==DLE) 567 TRACE_PS("TX_REQUEST - got DLE");
627 { 568
628 TRACE_PS("TX_REQUEST - got DLE"); 569 pInfo->state = R3964_TRANSMITTING;
629 570 pInfo->tx_position = 0;
630 pInfo->state = R3964_TRANSMITTING; 571
631 pInfo->tx_position = 0; 572 transmit_block(pInfo);
632 573 } else if (c == STX) {
633 transmit_block(pInfo); 574 if (pInfo->nRetry == 0) {
634 } 575 TRACE_PE("TX_REQUEST - init conflict");
635 else if(c==STX) 576 if (pInfo->priority == R3964_SLAVE) {
636 { 577 goto start_receiving;
637 if(pInfo->nRetry==0) 578 }
638 { 579 } else {
639 TRACE_PE("TX_REQUEST - init conflict"); 580 TRACE_PE("TX_REQUEST - secondary init "
640 if(pInfo->priority == R3964_SLAVE) 581 "conflict!? Switching to SLAVE mode "
641 { 582 "for next rx.");
642 goto start_receiving; 583 goto start_receiving;
643 } 584 }
644 } 585 } else {
645 else 586 TRACE_PE("TX_REQUEST - char != DLE: %x", c);
646 { 587 retry_transmit(pInfo);
647 TRACE_PE("TX_REQUEST - secondary init conflict!?" 588 }
648 " Switching to SLAVE mode for next rx."); 589 break;
649 goto start_receiving; 590 case R3964_TRANSMITTING:
650 } 591 if (c == NAK) {
651 } 592 TRACE_PE("TRANSMITTING - got NAK");
652 else 593 retry_transmit(pInfo);
653 { 594 } else {
654 TRACE_PE("TX_REQUEST - char != DLE: %x", c); 595 TRACE_PE("TRANSMITTING - got invalid char");
655 retry_transmit(pInfo); 596
656 } 597 pInfo->state = R3964_WAIT_ZVZ_BEFORE_TX_RETRY;
657 break; 598 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
658 case R3964_TRANSMITTING: 599 }
659 if(c==NAK) 600 break;
660 { 601 case R3964_WAIT_FOR_TX_ACK:
661 TRACE_PE("TRANSMITTING - got NAK"); 602 if (c == DLE) {
662 retry_transmit(pInfo); 603 TRACE_PS("WAIT_FOR_TX_ACK - got DLE");
663 } 604 remove_from_tx_queue(pInfo, R3964_OK);
664 else 605
665 { 606 pInfo->state = R3964_IDLE;
666 TRACE_PE("TRANSMITTING - got invalid char"); 607 trigger_transmit(pInfo);
667 608 } else {
668 pInfo->state = R3964_WAIT_ZVZ_BEFORE_TX_RETRY; 609 retry_transmit(pInfo);
669 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ); 610 }
670 } 611 break;
671 break; 612 case R3964_WAIT_FOR_RX_REPEAT:
672 case R3964_WAIT_FOR_TX_ACK: 613 /* FALLTROUGH */
673 if(c==DLE) 614 case R3964_IDLE:
674 { 615 if (c == STX) {
675 TRACE_PS("WAIT_FOR_TX_ACK - got DLE"); 616 /* Prevent rx_queue from overflow: */
676 remove_from_tx_queue(pInfo, R3964_OK); 617 if (pInfo->blocks_in_rx_queue >=
677 618 R3964_MAX_BLOCKS_IN_RX_QUEUE) {
678 pInfo->state = R3964_IDLE; 619 TRACE_PE("IDLE - got STX but no space in "
679 trigger_transmit(pInfo); 620 "rx_queue!");
680 } 621 pInfo->state = R3964_WAIT_FOR_RX_BUF;
681 else 622 mod_timer(&pInfo->tmr,
682 { 623 jiffies + R3964_TO_NO_BUF);
683 retry_transmit(pInfo); 624 break;
684 } 625 }
685 break;
686 case R3964_WAIT_FOR_RX_REPEAT:
687 /* FALLTROUGH */
688 case R3964_IDLE:
689 if(c==STX)
690 {
691 /* Prevent rx_queue from overflow: */
692 if(pInfo->blocks_in_rx_queue >= R3964_MAX_BLOCKS_IN_RX_QUEUE)
693 {
694 TRACE_PE("IDLE - got STX but no space in rx_queue!");
695 pInfo->state=R3964_WAIT_FOR_RX_BUF;
696 mod_timer(&pInfo->tmr, jiffies + R3964_TO_NO_BUF);
697 break;
698 }
699start_receiving: 626start_receiving:
700 /* Ok, start receiving: */ 627 /* Ok, start receiving: */
701 TRACE_PS("IDLE - got STX"); 628 TRACE_PS("IDLE - got STX");
702 pInfo->rx_position = 0; 629 pInfo->rx_position = 0;
703 pInfo->last_rx = 0; 630 pInfo->last_rx = 0;
704 pInfo->flags &= ~R3964_ERROR; 631 pInfo->flags &= ~R3964_ERROR;
705 pInfo->state=R3964_RECEIVING; 632 pInfo->state = R3964_RECEIVING;
706 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ); 633 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
707 pInfo->nRetry = 0; 634 pInfo->nRetry = 0;
708 put_char(pInfo, DLE); 635 put_char(pInfo, DLE);
709 flush(pInfo); 636 flush(pInfo);
710 pInfo->bcc = 0; 637 pInfo->bcc = 0;
711 } 638 }
712 break; 639 break;
713 case R3964_RECEIVING: 640 case R3964_RECEIVING:
714 if(pInfo->rx_position < RX_BUF_SIZE) 641 if (pInfo->rx_position < RX_BUF_SIZE) {
715 { 642 pInfo->bcc ^= c;
716 pInfo->bcc ^= c; 643
717 644 if (c == DLE) {
718 if(c==DLE) 645 if (pInfo->last_rx == DLE) {
719 { 646 pInfo->last_rx = 0;
720 if(pInfo->last_rx==DLE) 647 goto char_to_buf;
721 { 648 }
722 pInfo->last_rx = 0; 649 pInfo->last_rx = DLE;
723 goto char_to_buf; 650 break;
724 } 651 } else if ((c == ETX) && (pInfo->last_rx == DLE)) {
725 pInfo->last_rx = DLE; 652 if (pInfo->flags & R3964_BCC) {
726 break; 653 pInfo->state = R3964_WAIT_FOR_BCC;
727 } 654 mod_timer(&pInfo->tmr,
728 else if((c==ETX) && (pInfo->last_rx==DLE)) 655 jiffies + R3964_TO_ZVZ);
729 { 656 } else {
730 if(pInfo->flags & R3964_BCC) 657 on_receive_block(pInfo);
731 { 658 }
732 pInfo->state = R3964_WAIT_FOR_BCC; 659 } else {
733 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ); 660 pInfo->last_rx = c;
734 }
735 else
736 {
737 on_receive_block(pInfo);
738 }
739 }
740 else
741 {
742 pInfo->last_rx = c;
743char_to_buf: 661char_to_buf:
744 pInfo->rx_buf[pInfo->rx_position++] = c; 662 pInfo->rx_buf[pInfo->rx_position++] = c;
745 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ); 663 mod_timer(&pInfo->tmr, jiffies + R3964_TO_ZVZ);
746 } 664 }
747 } 665 }
748 /* else: overflow-msg? BUF_SIZE>MTU; should not happen? */ 666 /* else: overflow-msg? BUF_SIZE>MTU; should not happen? */
749 break; 667 break;
750 case R3964_WAIT_FOR_BCC: 668 case R3964_WAIT_FOR_BCC:
751 pInfo->last_rx = c; 669 pInfo->last_rx = c;
752 on_receive_block(pInfo); 670 on_receive_block(pInfo);
753 break; 671 break;
754 } 672 }
755} 673}
756 674
757static void receive_error(struct r3964_info *pInfo, const char flag) 675static void receive_error(struct r3964_info *pInfo, const char flag)
758{ 676{
759 switch (flag) 677 switch (flag) {
760 { 678 case TTY_NORMAL:
761 case TTY_NORMAL: 679 break;
762 break; 680 case TTY_BREAK:
763 case TTY_BREAK: 681 TRACE_PE("received break");
764 TRACE_PE("received break") 682 pInfo->flags |= R3964_BREAK;
765 pInfo->flags |= R3964_BREAK; 683 break;
766 break; 684 case TTY_PARITY:
767 case TTY_PARITY: 685 TRACE_PE("parity error");
768 TRACE_PE("parity error") 686 pInfo->flags |= R3964_PARITY;
769 pInfo->flags |= R3964_PARITY; 687 break;
770 break; 688 case TTY_FRAME:
771 case TTY_FRAME: 689 TRACE_PE("frame error");
772 TRACE_PE("frame error") 690 pInfo->flags |= R3964_FRAME;
773 pInfo->flags |= R3964_FRAME; 691 break;
774 break; 692 case TTY_OVERRUN:
775 case TTY_OVERRUN: 693 TRACE_PE("frame overrun");
776 TRACE_PE("frame overrun") 694 pInfo->flags |= R3964_OVERRUN;
777 pInfo->flags |= R3964_OVERRUN; 695 break;
778 break; 696 default:
779 default: 697 TRACE_PE("receive_error - unknown flag %d", flag);
780 TRACE_PE("receive_error - unknown flag %d", flag); 698 pInfo->flags |= R3964_UNKNOWN;
781 pInfo->flags |= R3964_UNKNOWN; 699 break;
782 break; 700 }
783 }
784} 701}
785 702
786static void on_timeout(unsigned long priv) 703static void on_timeout(unsigned long priv)
787{ 704{
788 struct r3964_info *pInfo = (void *)priv; 705 struct r3964_info *pInfo = (void *)priv;
789 706
790 switch(pInfo->state) 707 switch (pInfo->state) {
791 { 708 case R3964_TX_REQUEST:
792 case R3964_TX_REQUEST: 709 TRACE_PE("TX_REQUEST - timeout");
793 TRACE_PE("TX_REQUEST - timeout"); 710 retry_transmit(pInfo);
794 retry_transmit(pInfo); 711 break;
795 break; 712 case R3964_WAIT_ZVZ_BEFORE_TX_RETRY:
796 case R3964_WAIT_ZVZ_BEFORE_TX_RETRY: 713 put_char(pInfo, NAK);
797 put_char(pInfo, NAK); 714 flush(pInfo);
798 flush(pInfo); 715 retry_transmit(pInfo);
799 retry_transmit(pInfo); 716 break;
800 break; 717 case R3964_WAIT_FOR_TX_ACK:
801 case R3964_WAIT_FOR_TX_ACK: 718 TRACE_PE("WAIT_FOR_TX_ACK - timeout");
802 TRACE_PE("WAIT_FOR_TX_ACK - timeout"); 719 retry_transmit(pInfo);
803 retry_transmit(pInfo); 720 break;
804 break; 721 case R3964_WAIT_FOR_RX_BUF:
805 case R3964_WAIT_FOR_RX_BUF: 722 TRACE_PE("WAIT_FOR_RX_BUF - timeout");
806 TRACE_PE("WAIT_FOR_RX_BUF - timeout"); 723 put_char(pInfo, NAK);
807 put_char(pInfo, NAK); 724 flush(pInfo);
808 flush(pInfo); 725 pInfo->state = R3964_IDLE;
809 pInfo->state=R3964_IDLE; 726 break;
810 break; 727 case R3964_RECEIVING:
811 case R3964_RECEIVING: 728 TRACE_PE("RECEIVING - timeout after %d chars",
812 TRACE_PE("RECEIVING - timeout after %d chars", 729 pInfo->rx_position);
813 pInfo->rx_position); 730 put_char(pInfo, NAK);
814 put_char(pInfo, NAK); 731 flush(pInfo);
815 flush(pInfo); 732 pInfo->state = R3964_IDLE;
816 pInfo->state=R3964_IDLE; 733 break;
817 break; 734 case R3964_WAIT_FOR_RX_REPEAT:
818 case R3964_WAIT_FOR_RX_REPEAT: 735 TRACE_PE("WAIT_FOR_RX_REPEAT - timeout");
819 TRACE_PE("WAIT_FOR_RX_REPEAT - timeout"); 736 pInfo->state = R3964_IDLE;
820 pInfo->state=R3964_IDLE; 737 break;
821 break; 738 case R3964_WAIT_FOR_BCC:
822 case R3964_WAIT_FOR_BCC: 739 TRACE_PE("WAIT_FOR_BCC - timeout");
823 TRACE_PE("WAIT_FOR_BCC - timeout"); 740 put_char(pInfo, NAK);
824 put_char(pInfo, NAK); 741 flush(pInfo);
825 flush(pInfo); 742 pInfo->state = R3964_IDLE;
826 pInfo->state=R3964_IDLE; 743 break;
827 break; 744 }
828 }
829} 745}
830 746
831static struct r3964_client_info *findClient( 747static struct r3964_client_info *findClient(struct r3964_info *pInfo,
832 struct r3964_info *pInfo, struct pid *pid) 748 struct pid *pid)
833{ 749{
834 struct r3964_client_info *pClient; 750 struct r3964_client_info *pClient;
835 751
836 for(pClient=pInfo->firstClient; pClient; pClient=pClient->next) 752 for (pClient = pInfo->firstClient; pClient; pClient = pClient->next) {
837 { 753 if (pClient->pid == pid) {
838 if(pClient->pid == pid) 754 return pClient;
839 { 755 }
840 return pClient; 756 }
841 } 757 return NULL;
842 }
843 return NULL;
844} 758}
845 759
846static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg) 760static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg)
847{ 761{
848 struct r3964_client_info *pClient; 762 struct r3964_client_info *pClient;
849 struct r3964_client_info **ppClient; 763 struct r3964_client_info **ppClient;
850 struct r3964_message *pMsg; 764 struct r3964_message *pMsg;
851 765
852 if((arg & R3964_SIG_ALL)==0) 766 if ((arg & R3964_SIG_ALL) == 0) {
853 { 767 /* Remove client from client list */
854 /* Remove client from client list */ 768 for (ppClient = &pInfo->firstClient; *ppClient;
855 for(ppClient=&pInfo->firstClient; *ppClient; ppClient=&(*ppClient)->next) 769 ppClient = &(*ppClient)->next) {
856 { 770 pClient = *ppClient;
857 pClient = *ppClient; 771
858 772 if (pClient->pid == pid) {
859 if(pClient->pid == pid) 773 TRACE_PS("removing client %d from client list",
860 { 774 pid_nr(pid));
861 TRACE_PS("removing client %d from client list", pid_nr(pid)); 775 *ppClient = pClient->next;
862 *ppClient = pClient->next; 776 while (pClient->msg_count) {
863 while(pClient->msg_count) 777 pMsg = remove_msg(pInfo, pClient);
864 { 778 if (pMsg) {
865 pMsg=remove_msg(pInfo, pClient); 779 kfree(pMsg);
866 if(pMsg) 780 TRACE_M("enable_signals - msg "
867 { 781 "kfree %p", pMsg);
868 kfree(pMsg); 782 }
869 TRACE_M("enable_signals - msg kfree %p",pMsg); 783 }
870 } 784 put_pid(pClient->pid);
871 } 785 kfree(pClient);
872 put_pid(pClient->pid); 786 TRACE_M("enable_signals - kfree %p", pClient);
873 kfree(pClient); 787 return 0;
874 TRACE_M("enable_signals - kfree %p",pClient); 788 }
875 return 0; 789 }
876 } 790 return -EINVAL;
877 } 791 } else {
878 return -EINVAL; 792 pClient = findClient(pInfo, pid);
879 } 793 if (pClient) {
880 else 794 /* update signal options */
881 { 795 pClient->sig_flags = arg;
882 pClient=findClient(pInfo, pid); 796 } else {
883 if(pClient) 797 /* add client to client list */
884 { 798 pClient = kmalloc(sizeof(struct r3964_client_info),
885 /* update signal options */ 799 GFP_KERNEL);
886 pClient->sig_flags=arg; 800 TRACE_M("enable_signals - kmalloc %p", pClient);
887 } 801 if (pClient == NULL)
888 else 802 return -ENOMEM;
889 { 803
890 /* add client to client list */ 804 TRACE_PS("add client %d to client list", pid_nr(pid));
891 pClient=kmalloc(sizeof(struct r3964_client_info), GFP_KERNEL); 805 spin_lock_init(&pClient->lock);
892 TRACE_M("enable_signals - kmalloc %p",pClient); 806 pClient->sig_flags = arg;
893 if(pClient==NULL) 807 pClient->pid = get_pid(pid);
894 return -ENOMEM; 808 pClient->next = pInfo->firstClient;
895 809 pClient->first_msg = NULL;
896 TRACE_PS("add client %d to client list", pid_nr(pid)); 810 pClient->last_msg = NULL;
897 spin_lock_init(&pClient->lock); 811 pClient->next_block_to_read = NULL;
898 pClient->sig_flags=arg; 812 pClient->msg_count = 0;
899 pClient->pid = get_pid(pid); 813 pInfo->firstClient = pClient;
900 pClient->next=pInfo->firstClient; 814 }
901 pClient->first_msg = NULL; 815 }
902 pClient->last_msg = NULL; 816
903 pClient->next_block_to_read = NULL; 817 return 0;
904 pClient->msg_count = 0;
905 pInfo->firstClient=pClient;
906 }
907 }
908
909 return 0;
910} 818}
911 819
912static int read_telegram(struct r3964_info *pInfo, struct pid *pid, unsigned char __user *buf) 820static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
821 unsigned char __user * buf)
913{ 822{
914 struct r3964_client_info *pClient; 823 struct r3964_client_info *pClient;
915 struct r3964_block_header *block; 824 struct r3964_block_header *block;
916 825
917 if(!buf) 826 if (!buf) {
918 { 827 return -EINVAL;
919 return -EINVAL; 828 }
920 } 829
921 830 pClient = findClient(pInfo, pid);
922 pClient=findClient(pInfo,pid); 831 if (pClient == NULL) {
923 if(pClient==NULL) 832 return -EINVAL;
924 { 833 }
925 return -EINVAL; 834
926 } 835 block = pClient->next_block_to_read;
927 836 if (!block) {
928 block=pClient->next_block_to_read; 837 return 0;
929 if(!block) 838 } else {
930 { 839 if (copy_to_user(buf, block->data, block->length))
931 return 0; 840 return -EFAULT;
932 } 841
933 else 842 remove_client_block(pInfo, pClient);
934 { 843 return block->length;
935 if (copy_to_user (buf, block->data, block->length)) 844 }
936 return -EFAULT; 845
937 846 return -EINVAL;
938 remove_client_block(pInfo, pClient);
939 return block->length;
940 }
941
942 return -EINVAL;
943} 847}
944 848
945static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg, 849static void add_msg(struct r3964_client_info *pClient, int msg_id, int arg,
946 int error_code, struct r3964_block_header *pBlock) 850 int error_code, struct r3964_block_header *pBlock)
947{ 851{
948 struct r3964_message *pMsg; 852 struct r3964_message *pMsg;
949 unsigned long flags; 853 unsigned long flags;
950 854
951 if(pClient->msg_count<R3964_MAX_MSG_COUNT-1) 855 if (pClient->msg_count < R3964_MAX_MSG_COUNT - 1) {
952 {
953queue_the_message: 856queue_the_message:
954 857
955 pMsg = kmalloc(sizeof(struct r3964_message), 858 pMsg = kmalloc(sizeof(struct r3964_message),
956 error_code?GFP_ATOMIC:GFP_KERNEL); 859 error_code ? GFP_ATOMIC : GFP_KERNEL);
957 TRACE_M("add_msg - kmalloc %p",pMsg); 860 TRACE_M("add_msg - kmalloc %p", pMsg);
958 if(pMsg==NULL) { 861 if (pMsg == NULL) {
959 return; 862 return;
960 } 863 }
961 864
962 spin_lock_irqsave(&pClient->lock, flags); 865 spin_lock_irqsave(&pClient->lock, flags);
963 866
964 pMsg->msg_id = msg_id; 867 pMsg->msg_id = msg_id;
965 pMsg->arg = arg; 868 pMsg->arg = arg;
966 pMsg->error_code = error_code; 869 pMsg->error_code = error_code;
967 pMsg->block = pBlock; 870 pMsg->block = pBlock;
968 pMsg->next = NULL; 871 pMsg->next = NULL;
969 872
970 if(pClient->last_msg==NULL) 873 if (pClient->last_msg == NULL) {
971 { 874 pClient->first_msg = pClient->last_msg = pMsg;
972 pClient->first_msg=pClient->last_msg=pMsg; 875 } else {
973 } 876 pClient->last_msg->next = pMsg;
974 else 877 pClient->last_msg = pMsg;
975 { 878 }
976 pClient->last_msg->next = pMsg; 879
977 pClient->last_msg=pMsg; 880 pClient->msg_count++;
978 } 881
979 882 if (pBlock != NULL) {
980 pClient->msg_count++; 883 pBlock->locks++;
981 884 }
982 if(pBlock!=NULL) 885 spin_unlock_irqrestore(&pClient->lock, flags);
983 { 886 } else {
984 pBlock->locks++; 887 if ((pClient->last_msg->msg_id == R3964_MSG_ACK)
985 } 888 && (pClient->last_msg->error_code == R3964_OVERFLOW)) {
986 spin_unlock_irqrestore(&pClient->lock, flags); 889 pClient->last_msg->arg++;
987 } 890 TRACE_PE("add_msg - inc prev OVERFLOW-msg");
988 else 891 } else {
989 { 892 msg_id = R3964_MSG_ACK;
990 if((pClient->last_msg->msg_id == R3964_MSG_ACK) 893 arg = 0;
991 && (pClient->last_msg->error_code==R3964_OVERFLOW)) 894 error_code = R3964_OVERFLOW;
992 { 895 pBlock = NULL;
993 pClient->last_msg->arg++; 896 TRACE_PE("add_msg - queue OVERFLOW-msg");
994 TRACE_PE("add_msg - inc prev OVERFLOW-msg"); 897 goto queue_the_message;
995 } 898 }
996 else 899 }
997 { 900 /* Send SIGIO signal to client process: */
998 msg_id = R3964_MSG_ACK; 901 if (pClient->sig_flags & R3964_USE_SIGIO) {
999 arg = 0; 902 kill_pid(pClient->pid, SIGIO, 1);
1000 error_code = R3964_OVERFLOW; 903 }
1001 pBlock = NULL;
1002 TRACE_PE("add_msg - queue OVERFLOW-msg");
1003 goto queue_the_message;
1004 }
1005 }
1006 /* Send SIGIO signal to client process: */
1007 if(pClient->sig_flags & R3964_USE_SIGIO)
1008 {
1009 kill_pid(pClient->pid, SIGIO, 1);
1010 }
1011} 904}
1012 905
1013static struct r3964_message *remove_msg(struct r3964_info *pInfo, 906static struct r3964_message *remove_msg(struct r3964_info *pInfo,
1014 struct r3964_client_info *pClient) 907 struct r3964_client_info *pClient)
1015{ 908{
1016 struct r3964_message *pMsg=NULL; 909 struct r3964_message *pMsg = NULL;
1017 unsigned long flags; 910 unsigned long flags;
1018 911
1019 if(pClient->first_msg) 912 if (pClient->first_msg) {
1020 { 913 spin_lock_irqsave(&pClient->lock, flags);
1021 spin_lock_irqsave(&pClient->lock, flags); 914
1022 915 pMsg = pClient->first_msg;
1023 pMsg = pClient->first_msg; 916 pClient->first_msg = pMsg->next;
1024 pClient->first_msg = pMsg->next; 917 if (pClient->first_msg == NULL) {
1025 if(pClient->first_msg==NULL) 918 pClient->last_msg = NULL;
1026 { 919 }
1027 pClient->last_msg = NULL; 920
1028 } 921 pClient->msg_count--;
1029 922 if (pMsg->block) {
1030 pClient->msg_count--; 923 remove_client_block(pInfo, pClient);
1031 if(pMsg->block) 924 pClient->next_block_to_read = pMsg->block;
1032 { 925 }
1033 remove_client_block(pInfo, pClient); 926 spin_unlock_irqrestore(&pClient->lock, flags);
1034 pClient->next_block_to_read = pMsg->block; 927 }
1035 } 928 return pMsg;
1036 spin_unlock_irqrestore(&pClient->lock, flags);
1037 }
1038 return pMsg;
1039} 929}
1040 930
1041static void remove_client_block(struct r3964_info *pInfo, 931static void remove_client_block(struct r3964_info *pInfo,
1042 struct r3964_client_info *pClient) 932 struct r3964_client_info *pClient)
1043{ 933{
1044 struct r3964_block_header *block; 934 struct r3964_block_header *block;
1045 935
1046 TRACE_PS("remove_client_block PID %d", pid_nr(pClient->pid)); 936 TRACE_PS("remove_client_block PID %d", pid_nr(pClient->pid));
1047
1048 block=pClient->next_block_to_read;
1049 if(block)
1050 {
1051 block->locks--;
1052 if(block->locks==0)
1053 {
1054 remove_from_rx_queue(pInfo, block);
1055 }
1056 }
1057 pClient->next_block_to_read = NULL;
1058}
1059 937
938 block = pClient->next_block_to_read;
939 if (block) {
940 block->locks--;
941 if (block->locks == 0) {
942 remove_from_rx_queue(pInfo, block);
943 }
944 }
945 pClient->next_block_to_read = NULL;
946}
1060 947
1061/************************************************************* 948/*************************************************************
1062 * Line discipline routines 949 * Line discipline routines
@@ -1064,342 +951,318 @@ static void remove_client_block(struct r3964_info *pInfo,
1064 951
1065static int r3964_open(struct tty_struct *tty) 952static int r3964_open(struct tty_struct *tty)
1066{ 953{
1067 struct r3964_info *pInfo; 954 struct r3964_info *pInfo;
1068 955
1069 TRACE_L("open"); 956 TRACE_L("open");
1070 TRACE_L("tty=%p, PID=%d, disc_data=%p", 957 TRACE_L("tty=%p, PID=%d, disc_data=%p",
1071 tty, current->pid, tty->disc_data); 958 tty, current->pid, tty->disc_data);
1072 959
1073 pInfo=kmalloc(sizeof(struct r3964_info), GFP_KERNEL); 960 pInfo = kmalloc(sizeof(struct r3964_info), GFP_KERNEL);
1074 TRACE_M("r3964_open - info kmalloc %p",pInfo); 961 TRACE_M("r3964_open - info kmalloc %p", pInfo);
1075 962
1076 if(!pInfo) 963 if (!pInfo) {
1077 { 964 printk(KERN_ERR "r3964: failed to alloc info structure\n");
1078 printk(KERN_ERR "r3964: failed to alloc info structure\n"); 965 return -ENOMEM;
1079 return -ENOMEM; 966 }
1080 } 967
1081 968 pInfo->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL);
1082 pInfo->rx_buf = kmalloc(RX_BUF_SIZE, GFP_KERNEL); 969 TRACE_M("r3964_open - rx_buf kmalloc %p", pInfo->rx_buf);
1083 TRACE_M("r3964_open - rx_buf kmalloc %p",pInfo->rx_buf); 970
1084 971 if (!pInfo->rx_buf) {
1085 if(!pInfo->rx_buf) 972 printk(KERN_ERR "r3964: failed to alloc receive buffer\n");
1086 { 973 kfree(pInfo);
1087 printk(KERN_ERR "r3964: failed to alloc receive buffer\n"); 974 TRACE_M("r3964_open - info kfree %p", pInfo);
1088 kfree(pInfo); 975 return -ENOMEM;
1089 TRACE_M("r3964_open - info kfree %p",pInfo); 976 }
1090 return -ENOMEM; 977
1091 } 978 pInfo->tx_buf = kmalloc(TX_BUF_SIZE, GFP_KERNEL);
1092 979 TRACE_M("r3964_open - tx_buf kmalloc %p", pInfo->tx_buf);
1093 pInfo->tx_buf = kmalloc(TX_BUF_SIZE, GFP_KERNEL); 980
1094 TRACE_M("r3964_open - tx_buf kmalloc %p",pInfo->tx_buf); 981 if (!pInfo->tx_buf) {
1095 982 printk(KERN_ERR "r3964: failed to alloc transmit buffer\n");
1096 if(!pInfo->tx_buf) 983 kfree(pInfo->rx_buf);
1097 { 984 TRACE_M("r3964_open - rx_buf kfree %p", pInfo->rx_buf);
1098 printk(KERN_ERR "r3964: failed to alloc transmit buffer\n"); 985 kfree(pInfo);
1099 kfree(pInfo->rx_buf); 986 TRACE_M("r3964_open - info kfree %p", pInfo);
1100 TRACE_M("r3964_open - rx_buf kfree %p",pInfo->rx_buf); 987 return -ENOMEM;
1101 kfree(pInfo); 988 }
1102 TRACE_M("r3964_open - info kfree %p",pInfo); 989
1103 return -ENOMEM; 990 spin_lock_init(&pInfo->lock);
1104 } 991 pInfo->tty = tty;
1105 992 init_waitqueue_head(&pInfo->read_wait);
1106 spin_lock_init(&pInfo->lock); 993 pInfo->priority = R3964_MASTER;
1107 pInfo->tty = tty; 994 pInfo->rx_first = pInfo->rx_last = NULL;
1108 init_waitqueue_head (&pInfo->read_wait); 995 pInfo->tx_first = pInfo->tx_last = NULL;
1109 pInfo->priority = R3964_MASTER; 996 pInfo->rx_position = 0;
1110 pInfo->rx_first = pInfo->rx_last = NULL; 997 pInfo->tx_position = 0;
1111 pInfo->tx_first = pInfo->tx_last = NULL; 998 pInfo->last_rx = 0;
1112 pInfo->rx_position = 0; 999 pInfo->blocks_in_rx_queue = 0;
1113 pInfo->tx_position = 0; 1000 pInfo->firstClient = NULL;
1114 pInfo->last_rx = 0; 1001 pInfo->state = R3964_IDLE;
1115 pInfo->blocks_in_rx_queue = 0; 1002 pInfo->flags = R3964_DEBUG;
1116 pInfo->firstClient=NULL; 1003 pInfo->nRetry = 0;
1117 pInfo->state=R3964_IDLE; 1004
1118 pInfo->flags = R3964_DEBUG; 1005 tty->disc_data = pInfo;
1119 pInfo->nRetry = 0; 1006 tty->receive_room = 65536;
1120 1007
1121 tty->disc_data = pInfo; 1008 setup_timer(&pInfo->tmr, on_timeout, (unsigned long)pInfo);
1122 tty->receive_room = 65536; 1009
1123 1010 return 0;
1124 init_timer(&pInfo->tmr);
1125 pInfo->tmr.data = (unsigned long)pInfo;
1126 pInfo->tmr.function = on_timeout;
1127
1128 return 0;
1129} 1011}
1130 1012
1131static void r3964_close(struct tty_struct *tty) 1013static void r3964_close(struct tty_struct *tty)
1132{ 1014{
1133 struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data; 1015 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
1134 struct r3964_client_info *pClient, *pNext; 1016 struct r3964_client_info *pClient, *pNext;
1135 struct r3964_message *pMsg; 1017 struct r3964_message *pMsg;
1136 struct r3964_block_header *pHeader, *pNextHeader; 1018 struct r3964_block_header *pHeader, *pNextHeader;
1137 unsigned long flags; 1019 unsigned long flags;
1138 1020
1139 TRACE_L("close"); 1021 TRACE_L("close");
1140 1022
1141 /* 1023 /*
1142 * Make sure that our task queue isn't activated. If it 1024 * Make sure that our task queue isn't activated. If it
1143 * is, take it out of the linked list. 1025 * is, take it out of the linked list.
1144 */ 1026 */
1145 del_timer_sync(&pInfo->tmr); 1027 del_timer_sync(&pInfo->tmr);
1146 1028
1147 /* Remove client-structs and message queues: */ 1029 /* Remove client-structs and message queues: */
1148 pClient=pInfo->firstClient; 1030 pClient = pInfo->firstClient;
1149 while(pClient) 1031 while (pClient) {
1150 { 1032 pNext = pClient->next;
1151 pNext=pClient->next; 1033 while (pClient->msg_count) {
1152 while(pClient->msg_count) 1034 pMsg = remove_msg(pInfo, pClient);
1153 { 1035 if (pMsg) {
1154 pMsg=remove_msg(pInfo, pClient); 1036 kfree(pMsg);
1155 if(pMsg) 1037 TRACE_M("r3964_close - msg kfree %p", pMsg);
1156 { 1038 }
1157 kfree(pMsg); 1039 }
1158 TRACE_M("r3964_close - msg kfree %p",pMsg); 1040 put_pid(pClient->pid);
1159 } 1041 kfree(pClient);
1160 } 1042 TRACE_M("r3964_close - client kfree %p", pClient);
1161 put_pid(pClient->pid); 1043 pClient = pNext;
1162 kfree(pClient); 1044 }
1163 TRACE_M("r3964_close - client kfree %p",pClient); 1045 /* Remove jobs from tx_queue: */
1164 pClient=pNext; 1046 spin_lock_irqsave(&pInfo->lock, flags);
1165 } 1047 pHeader = pInfo->tx_first;
1166 /* Remove jobs from tx_queue: */ 1048 pInfo->tx_first = pInfo->tx_last = NULL;
1167 spin_lock_irqsave(&pInfo->lock, flags);
1168 pHeader=pInfo->tx_first;
1169 pInfo->tx_first=pInfo->tx_last=NULL;
1170 spin_unlock_irqrestore(&pInfo->lock, flags); 1049 spin_unlock_irqrestore(&pInfo->lock, flags);
1171 1050
1172 while(pHeader) 1051 while (pHeader) {
1173 { 1052 pNextHeader = pHeader->next;
1174 pNextHeader=pHeader->next; 1053 kfree(pHeader);
1175 kfree(pHeader); 1054 pHeader = pNextHeader;
1176 pHeader=pNextHeader;
1177 } 1055 }
1178 1056
1179 /* Free buffers: */ 1057 /* Free buffers: */
1180 wake_up_interruptible(&pInfo->read_wait); 1058 wake_up_interruptible(&pInfo->read_wait);
1181 kfree(pInfo->rx_buf); 1059 kfree(pInfo->rx_buf);
1182 TRACE_M("r3964_close - rx_buf kfree %p",pInfo->rx_buf); 1060 TRACE_M("r3964_close - rx_buf kfree %p", pInfo->rx_buf);
1183 kfree(pInfo->tx_buf); 1061 kfree(pInfo->tx_buf);
1184 TRACE_M("r3964_close - tx_buf kfree %p",pInfo->tx_buf); 1062 TRACE_M("r3964_close - tx_buf kfree %p", pInfo->tx_buf);
1185 kfree(pInfo); 1063 kfree(pInfo);
1186 TRACE_M("r3964_close - info kfree %p",pInfo); 1064 TRACE_M("r3964_close - info kfree %p", pInfo);
1187} 1065}
1188 1066
1189static ssize_t r3964_read(struct tty_struct *tty, struct file *file, 1067static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
1190 unsigned char __user *buf, size_t nr) 1068 unsigned char __user * buf, size_t nr)
1191{ 1069{
1192 struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data; 1070 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
1193 struct r3964_client_info *pClient; 1071 struct r3964_client_info *pClient;
1194 struct r3964_message *pMsg; 1072 struct r3964_message *pMsg;
1195 struct r3964_client_message theMsg; 1073 struct r3964_client_message theMsg;
1196 DECLARE_WAITQUEUE (wait, current); 1074 DECLARE_WAITQUEUE(wait, current);
1197 1075
1198 int count; 1076 int count;
1199 1077
1200 TRACE_L("read()"); 1078 TRACE_L("read()");
1201 1079
1202 pClient=findClient(pInfo, task_pid(current)); 1080 pClient = findClient(pInfo, task_pid(current));
1203 if(pClient) 1081 if (pClient) {
1204 { 1082 pMsg = remove_msg(pInfo, pClient);
1205 pMsg = remove_msg(pInfo, pClient); 1083 if (pMsg == NULL) {
1206 if(pMsg==NULL) 1084 /* no messages available. */
1207 { 1085 if (file->f_flags & O_NONBLOCK) {
1208 /* no messages available. */ 1086 return -EAGAIN;
1209 if (file->f_flags & O_NONBLOCK) 1087 }
1210 { 1088 /* block until there is a message: */
1211 return -EAGAIN; 1089 add_wait_queue(&pInfo->read_wait, &wait);
1212 }
1213 /* block until there is a message: */
1214 add_wait_queue(&pInfo->read_wait, &wait);
1215repeat: 1090repeat:
1216 current->state = TASK_INTERRUPTIBLE; 1091 current->state = TASK_INTERRUPTIBLE;
1217 pMsg = remove_msg(pInfo, pClient); 1092 pMsg = remove_msg(pInfo, pClient);
1218 if (!pMsg && !signal_pending(current)) 1093 if (!pMsg && !signal_pending(current)) {
1219 { 1094 schedule();
1220 schedule(); 1095 goto repeat;
1221 goto repeat; 1096 }
1222 } 1097 current->state = TASK_RUNNING;
1223 current->state = TASK_RUNNING; 1098 remove_wait_queue(&pInfo->read_wait, &wait);
1224 remove_wait_queue(&pInfo->read_wait, &wait); 1099 }
1225 } 1100
1226 1101 /* If we still haven't got a message, we must have been signalled */
1227 /* If we still haven't got a message, we must have been signalled */ 1102
1228 1103 if (!pMsg)
1229 if (!pMsg) return -EINTR; 1104 return -EINTR;
1230 1105
1231 /* deliver msg to client process: */ 1106 /* deliver msg to client process: */
1232 theMsg.msg_id = pMsg->msg_id; 1107 theMsg.msg_id = pMsg->msg_id;
1233 theMsg.arg = pMsg->arg; 1108 theMsg.arg = pMsg->arg;
1234 theMsg.error_code = pMsg->error_code; 1109 theMsg.error_code = pMsg->error_code;
1235 count = sizeof(struct r3964_client_message); 1110 count = sizeof(struct r3964_client_message);
1236 1111
1237 kfree(pMsg); 1112 kfree(pMsg);
1238 TRACE_M("r3964_read - msg kfree %p",pMsg); 1113 TRACE_M("r3964_read - msg kfree %p", pMsg);
1239 1114
1240 if (copy_to_user(buf,&theMsg, count)) 1115 if (copy_to_user(buf, &theMsg, count))
1241 return -EFAULT; 1116 return -EFAULT;
1242 1117
1243 TRACE_PS("read - return %d", count); 1118 TRACE_PS("read - return %d", count);
1244 return count; 1119 return count;
1245 } 1120 }
1246 return -EPERM; 1121 return -EPERM;
1247} 1122}
1248 1123
1249static ssize_t r3964_write(struct tty_struct * tty, struct file * file, 1124static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
1250 const unsigned char *data, size_t count) 1125 const unsigned char *data, size_t count)
1251{ 1126{
1252 struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data; 1127 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
1253 struct r3964_block_header *pHeader; 1128 struct r3964_block_header *pHeader;
1254 struct r3964_client_info *pClient; 1129 struct r3964_client_info *pClient;
1255 unsigned char *new_data; 1130 unsigned char *new_data;
1256 1131
1257 TRACE_L("write request, %d characters", count); 1132 TRACE_L("write request, %d characters", count);
1258/* 1133/*
1259 * Verify the pointers 1134 * Verify the pointers
1260 */ 1135 */
1261 1136
1262 if(!pInfo) 1137 if (!pInfo)
1263 return -EIO; 1138 return -EIO;
1264 1139
1265/* 1140/*
1266 * Ensure that the caller does not wish to send too much. 1141 * Ensure that the caller does not wish to send too much.
1267 */ 1142 */
1268 if (count > R3964_MTU) 1143 if (count > R3964_MTU) {
1269 { 1144 if (pInfo->flags & R3964_DEBUG) {
1270 if (pInfo->flags & R3964_DEBUG) 1145 TRACE_L(KERN_WARNING "r3964_write: truncating user "
1271 { 1146 "packet from %u to mtu %d", count, R3964_MTU);
1272 TRACE_L (KERN_WARNING 1147 }
1273 "r3964_write: truncating user packet " 1148 count = R3964_MTU;
1274 "from %u to mtu %d", count, R3964_MTU); 1149 }
1275 }
1276 count = R3964_MTU;
1277 }
1278/* 1150/*
1279 * Allocate a buffer for the data and copy it from the buffer with header prepended 1151 * Allocate a buffer for the data and copy it from the buffer with header prepended
1280 */ 1152 */
1281 new_data = kmalloc (count+sizeof(struct r3964_block_header), GFP_KERNEL); 1153 new_data = kmalloc(count + sizeof(struct r3964_block_header),
1282 TRACE_M("r3964_write - kmalloc %p",new_data); 1154 GFP_KERNEL);
1283 if (new_data == NULL) { 1155 TRACE_M("r3964_write - kmalloc %p", new_data);
1284 if (pInfo->flags & R3964_DEBUG) 1156 if (new_data == NULL) {
1285 { 1157 if (pInfo->flags & R3964_DEBUG) {
1286 printk (KERN_ERR 1158 printk(KERN_ERR "r3964_write: no memory\n");
1287 "r3964_write: no memory\n"); 1159 }
1288 } 1160 return -ENOSPC;
1289 return -ENOSPC; 1161 }
1290 } 1162
1291 1163 pHeader = (struct r3964_block_header *)new_data;
1292 pHeader = (struct r3964_block_header *)new_data; 1164 pHeader->data = new_data + sizeof(struct r3964_block_header);
1293 pHeader->data = new_data + sizeof(struct r3964_block_header); 1165 pHeader->length = count;
1294 pHeader->length = count; 1166 pHeader->locks = 0;
1295 pHeader->locks = 0; 1167 pHeader->owner = NULL;
1296 pHeader->owner = NULL; 1168
1297 1169 pClient = findClient(pInfo, task_pid(current));
1298 pClient=findClient(pInfo, task_pid(current)); 1170 if (pClient) {
1299 if(pClient) 1171 pHeader->owner = pClient;
1300 { 1172 }
1301 pHeader->owner = pClient; 1173
1302 } 1174 memcpy(pHeader->data, data, count); /* We already verified this */
1303 1175
1304 memcpy(pHeader->data, data, count); /* We already verified this */ 1176 if (pInfo->flags & R3964_DEBUG) {
1305 1177 dump_block(pHeader->data, count);
1306 if(pInfo->flags & R3964_DEBUG) 1178 }
1307 {
1308 dump_block(pHeader->data, count);
1309 }
1310 1179
1311/* 1180/*
1312 * Add buffer to transmit-queue: 1181 * Add buffer to transmit-queue:
1313 */ 1182 */
1314 add_tx_queue(pInfo, pHeader); 1183 add_tx_queue(pInfo, pHeader);
1315 trigger_transmit(pInfo); 1184 trigger_transmit(pInfo);
1316 1185
1317 return 0; 1186 return 0;
1318} 1187}
1319 1188
1320static int r3964_ioctl(struct tty_struct * tty, struct file * file, 1189static int r3964_ioctl(struct tty_struct *tty, struct file *file,
1321 unsigned int cmd, unsigned long arg) 1190 unsigned int cmd, unsigned long arg)
1322{ 1191{
1323 struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data; 1192 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
1324 if(pInfo==NULL) 1193 if (pInfo == NULL)
1325 return -EINVAL; 1194 return -EINVAL;
1326 switch(cmd) 1195 switch (cmd) {
1327 { 1196 case R3964_ENABLE_SIGNALS:
1328 case R3964_ENABLE_SIGNALS: 1197 return enable_signals(pInfo, task_pid(current), arg);
1329 return enable_signals(pInfo, task_pid(current), arg); 1198 case R3964_SETPRIORITY:
1330 case R3964_SETPRIORITY: 1199 if (arg < R3964_MASTER || arg > R3964_SLAVE)
1331 if(arg<R3964_MASTER || arg>R3964_SLAVE) 1200 return -EINVAL;
1332 return -EINVAL; 1201 pInfo->priority = arg & 0xff;
1333 pInfo->priority = arg & 0xff; 1202 return 0;
1334 return 0; 1203 case R3964_USE_BCC:
1335 case R3964_USE_BCC: 1204 if (arg)
1336 if(arg) 1205 pInfo->flags |= R3964_BCC;
1337 pInfo->flags |= R3964_BCC; 1206 else
1338 else 1207 pInfo->flags &= ~R3964_BCC;
1339 pInfo->flags &= ~R3964_BCC; 1208 return 0;
1340 return 0; 1209 case R3964_READ_TELEGRAM:
1341 case R3964_READ_TELEGRAM: 1210 return read_telegram(pInfo, task_pid(current),
1342 return read_telegram(pInfo, task_pid(current), (unsigned char __user *)arg); 1211 (unsigned char __user *)arg);
1343 default: 1212 default:
1344 return -ENOIOCTLCMD; 1213 return -ENOIOCTLCMD;
1345 } 1214 }
1346} 1215}
1347 1216
1348static void r3964_set_termios(struct tty_struct *tty, struct ktermios * old) 1217static void r3964_set_termios(struct tty_struct *tty, struct ktermios *old)
1349{ 1218{
1350 TRACE_L("set_termios"); 1219 TRACE_L("set_termios");
1351} 1220}
1352 1221
1353/* Called without the kernel lock held - fine */ 1222/* Called without the kernel lock held - fine */
1354static unsigned int r3964_poll(struct tty_struct * tty, struct file * file, 1223static unsigned int r3964_poll(struct tty_struct *tty, struct file *file,
1355 struct poll_table_struct *wait) 1224 struct poll_table_struct *wait)
1356{ 1225{
1357 struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data; 1226 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
1358 struct r3964_client_info *pClient; 1227 struct r3964_client_info *pClient;
1359 struct r3964_message *pMsg=NULL; 1228 struct r3964_message *pMsg = NULL;
1360 unsigned long flags; 1229 unsigned long flags;
1361 int result = POLLOUT; 1230 int result = POLLOUT;
1362 1231
1363 TRACE_L("POLL"); 1232 TRACE_L("POLL");
1364 1233
1365 pClient=findClient(pInfo, task_pid(current)); 1234 pClient = findClient(pInfo, task_pid(current));
1366 if(pClient) 1235 if (pClient) {
1367 { 1236 poll_wait(file, &pInfo->read_wait, wait);
1368 poll_wait(file, &pInfo->read_wait, wait); 1237 spin_lock_irqsave(&pInfo->lock, flags);
1369 spin_lock_irqsave(&pInfo->lock, flags); 1238 pMsg = pClient->first_msg;
1370 pMsg=pClient->first_msg; 1239 spin_unlock_irqrestore(&pInfo->lock, flags);
1371 spin_unlock_irqrestore(&pInfo->lock, flags); 1240 if (pMsg)
1372 if(pMsg) 1241 result |= POLLIN | POLLRDNORM;
1373 result |= POLLIN | POLLRDNORM; 1242 } else {
1374 } 1243 result = -EINVAL;
1375 else 1244 }
1376 { 1245 return result;
1377 result = -EINVAL;
1378 }
1379 return result;
1380} 1246}
1381 1247
1382static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp, 1248static void r3964_receive_buf(struct tty_struct *tty, const unsigned char *cp,
1383 char *fp, int count) 1249 char *fp, int count)
1384{ 1250{
1385 struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data; 1251 struct r3964_info *pInfo = (struct r3964_info *)tty->disc_data;
1386 const unsigned char *p; 1252 const unsigned char *p;
1387 char *f, flags = 0; 1253 char *f, flags = 0;
1388 int i; 1254 int i;
1389 1255
1390 for (i=count, p = cp, f = fp; i; i--, p++) { 1256 for (i = count, p = cp, f = fp; i; i--, p++) {
1391 if (f) 1257 if (f)
1392 flags = *f++; 1258 flags = *f++;
1393 if(flags==TTY_NORMAL) 1259 if (flags == TTY_NORMAL) {
1394 { 1260 receive_char(pInfo, *p);
1395 receive_char(pInfo, *p); 1261 } else {
1396 } 1262 receive_error(pInfo, flags);
1397 else 1263 }
1398 { 1264
1399 receive_error(pInfo, flags); 1265 }
1400 }
1401
1402 }
1403} 1266}
1404 1267
1405MODULE_LICENSE("GPL"); 1268MODULE_LICENSE("GPL");
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index 2bdb0144a22..6ac3ca4c723 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -579,8 +579,8 @@ static void eraser(unsigned char c, struct tty_struct *tty)
579 579
580static inline void isig(int sig, struct tty_struct *tty, int flush) 580static inline void isig(int sig, struct tty_struct *tty, int flush)
581{ 581{
582 if (tty->pgrp > 0) 582 if (tty->pgrp)
583 kill_pg(tty->pgrp, sig, 1); 583 kill_pgrp(tty->pgrp, sig, 1);
584 if (flush || !L_NOFLSH(tty)) { 584 if (flush || !L_NOFLSH(tty)) {
585 n_tty_flush_buffer(tty); 585 n_tty_flush_buffer(tty);
586 if (tty->driver->flush_buffer) 586 if (tty->driver->flush_buffer)
@@ -1184,13 +1184,13 @@ static int job_control(struct tty_struct *tty, struct file *file)
1184 /* don't stop on /dev/console */ 1184 /* don't stop on /dev/console */
1185 if (file->f_op->write != redirected_tty_write && 1185 if (file->f_op->write != redirected_tty_write &&
1186 current->signal->tty == tty) { 1186 current->signal->tty == tty) {
1187 if (tty->pgrp <= 0) 1187 if (!tty->pgrp)
1188 printk("read_chan: tty->pgrp <= 0!\n"); 1188 printk("read_chan: no tty->pgrp!\n");
1189 else if (process_group(current) != tty->pgrp) { 1189 else if (task_pgrp(current) != tty->pgrp) {
1190 if (is_ignored(SIGTTIN) || 1190 if (is_ignored(SIGTTIN) ||
1191 is_orphaned_pgrp(process_group(current))) 1191 is_current_pgrp_orphaned())
1192 return -EIO; 1192 return -EIO;
1193 kill_pg(process_group(current), SIGTTIN, 1); 1193 kill_pgrp(task_pgrp(current), SIGTTIN, 1);
1194 return -ERESTARTSYS; 1194 return -ERESTARTSYS;
1195 } 1195 }
1196 } 1196 }
diff --git a/drivers/char/nwbutton.c b/drivers/char/nwbutton.c
index 2d264971d83..2604246501e 100644
--- a/drivers/char/nwbutton.c
+++ b/drivers/char/nwbutton.c
@@ -23,8 +23,11 @@
23#define __NWBUTTON_C /* Tell the header file who we are */ 23#define __NWBUTTON_C /* Tell the header file who we are */
24#include "nwbutton.h" 24#include "nwbutton.h"
25 25
26static void button_sequence_finished (unsigned long parameters);
27
26static int button_press_count; /* The count of button presses */ 28static int button_press_count; /* The count of button presses */
27static struct timer_list button_timer; /* Times for the end of a sequence */ 29/* Times for the end of a sequence */
30static DEFINE_TIMER(button_timer, button_sequence_finished, 0, 0);
28static DECLARE_WAIT_QUEUE_HEAD(button_wait_queue); /* Used for blocking read */ 31static DECLARE_WAIT_QUEUE_HEAD(button_wait_queue); /* Used for blocking read */
29static char button_output_buffer[32]; /* Stores data to write out of device */ 32static char button_output_buffer[32]; /* Stores data to write out of device */
30static int bcount; /* The number of bytes in the buffer */ 33static int bcount; /* The number of bytes in the buffer */
@@ -146,14 +149,8 @@ static void button_sequence_finished (unsigned long parameters)
146 149
147static irqreturn_t button_handler (int irq, void *dev_id) 150static irqreturn_t button_handler (int irq, void *dev_id)
148{ 151{
149 if (button_press_count) {
150 del_timer (&button_timer);
151 }
152 button_press_count++; 152 button_press_count++;
153 init_timer (&button_timer); 153 mod_timer(&button_timer, jiffies + bdelay);
154 button_timer.function = button_sequence_finished;
155 button_timer.expires = (jiffies + bdelay);
156 add_timer (&button_timer);
157 154
158 return IRQ_HANDLED; 155 return IRQ_HANDLED;
159} 156}
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index 211c93fda6f..e91b43a014b 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -946,8 +946,7 @@ release_io:
946 946
947return_with_timer: 947return_with_timer:
948 DEBUGP(7, dev, "<- monitor_card (returns with timer)\n"); 948 DEBUGP(7, dev, "<- monitor_card (returns with timer)\n");
949 dev->timer.expires = jiffies + dev->mdelay; 949 mod_timer(&dev->timer, jiffies + dev->mdelay);
950 add_timer(&dev->timer);
951 clear_bit(LOCK_MONITOR, &dev->flags); 950 clear_bit(LOCK_MONITOR, &dev->flags);
952} 951}
953 952
@@ -1406,12 +1405,9 @@ static void start_monitor(struct cm4000_dev *dev)
1406 DEBUGP(3, dev, "-> start_monitor\n"); 1405 DEBUGP(3, dev, "-> start_monitor\n");
1407 if (!dev->monitor_running) { 1406 if (!dev->monitor_running) {
1408 DEBUGP(5, dev, "create, init and add timer\n"); 1407 DEBUGP(5, dev, "create, init and add timer\n");
1409 init_timer(&dev->timer); 1408 setup_timer(&dev->timer, monitor_card, (unsigned long)dev);
1410 dev->monitor_running = 1; 1409 dev->monitor_running = 1;
1411 dev->timer.expires = jiffies; 1410 mod_timer(&dev->timer, jiffies);
1412 dev->timer.data = (unsigned long) dev;
1413 dev->timer.function = monitor_card;
1414 add_timer(&dev->timer);
1415 } else 1411 } else
1416 DEBUGP(5, dev, "monitor already running\n"); 1412 DEBUGP(5, dev, "monitor already running\n");
1417 DEBUGP(3, dev, "<- start_monitor\n"); 1413 DEBUGP(3, dev, "<- start_monitor\n");
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 9b1ff7e8f89..0e82968c2f3 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -632,8 +632,7 @@ static int reader_probe(struct pcmcia_device *link)
632 init_waitqueue_head(&dev->poll_wait); 632 init_waitqueue_head(&dev->poll_wait);
633 init_waitqueue_head(&dev->read_wait); 633 init_waitqueue_head(&dev->read_wait);
634 init_waitqueue_head(&dev->write_wait); 634 init_waitqueue_head(&dev->write_wait);
635 init_timer(&dev->poll_timer); 635 setup_timer(&dev->poll_timer, cm4040_do_poll, 0);
636 dev->poll_timer.function = &cm4040_do_poll;
637 636
638 ret = reader_config(link, i); 637 ret = reader_config(link, i);
639 if (ret) 638 if (ret)
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index f108c136800..8d025e9b5bc 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -887,10 +887,8 @@ static void bh_transmit(MGSLPC_INFO *info)
887 if (debug_level >= DEBUG_LEVEL_BH) 887 if (debug_level >= DEBUG_LEVEL_BH)
888 printk("bh_transmit() entry on %s\n", info->device_name); 888 printk("bh_transmit() entry on %s\n", info->device_name);
889 889
890 if (tty) { 890 if (tty)
891 tty_wakeup(tty); 891 tty_wakeup(tty);
892 wake_up_interruptible(&tty->write_wait);
893 }
894} 892}
895 893
896static void bh_status(MGSLPC_INFO *info) 894static void bh_status(MGSLPC_INFO *info)
@@ -1363,9 +1361,7 @@ static int startup(MGSLPC_INFO * info)
1363 1361
1364 memset(&info->icount, 0, sizeof(info->icount)); 1362 memset(&info->icount, 0, sizeof(info->icount));
1365 1363
1366 init_timer(&info->tx_timer); 1364 setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
1367 info->tx_timer.data = (unsigned long)info;
1368 info->tx_timer.function = tx_timeout;
1369 1365
1370 /* Allocate and claim adapter resources */ 1366 /* Allocate and claim adapter resources */
1371 retval = claim_resources(info); 1367 retval = claim_resources(info);
@@ -1410,7 +1406,7 @@ static void shutdown(MGSLPC_INFO * info)
1410 wake_up_interruptible(&info->status_event_wait_q); 1406 wake_up_interruptible(&info->status_event_wait_q);
1411 wake_up_interruptible(&info->event_wait_q); 1407 wake_up_interruptible(&info->event_wait_q);
1412 1408
1413 del_timer(&info->tx_timer); 1409 del_timer_sync(&info->tx_timer);
1414 1410
1415 if (info->tx_buf) { 1411 if (info->tx_buf) {
1416 free_page((unsigned long) info->tx_buf); 1412 free_page((unsigned long) info->tx_buf);
@@ -3551,8 +3547,8 @@ static void tx_start(MGSLPC_INFO *info)
3551 } else { 3547 } else {
3552 info->tx_active = 1; 3548 info->tx_active = 1;
3553 tx_ready(info); 3549 tx_ready(info);
3554 info->tx_timer.expires = jiffies + msecs_to_jiffies(5000); 3550 mod_timer(&info->tx_timer, jiffies +
3555 add_timer(&info->tx_timer); 3551 msecs_to_jiffies(5000));
3556 } 3552 }
3557 } 3553 }
3558 3554
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 13d0b1350a6..b9dc7aa1dfb 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1117,14 +1117,14 @@ random_ioctl(struct inode * inode, struct file * file,
1117 } 1117 }
1118} 1118}
1119 1119
1120struct file_operations random_fops = { 1120const struct file_operations random_fops = {
1121 .read = random_read, 1121 .read = random_read,
1122 .write = random_write, 1122 .write = random_write,
1123 .poll = random_poll, 1123 .poll = random_poll,
1124 .ioctl = random_ioctl, 1124 .ioctl = random_ioctl,
1125}; 1125};
1126 1126
1127struct file_operations urandom_fops = { 1127const struct file_operations urandom_fops = {
1128 .read = urandom_read, 1128 .read = urandom_read,
1129 .write = random_write, 1129 .write = random_write,
1130 .ioctl = random_ioctl, 1130 .ioctl = random_ioctl,
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 645e20a06ec..1f0d7c60c94 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -154,7 +154,7 @@ static int raw_ctl_ioctl(struct inode *inode, struct file *filp,
154 goto out; 154 goto out;
155 } 155 }
156 156
157 if (rq.raw_minor < 0 || rq.raw_minor >= MAX_RAW_MINORS) { 157 if (rq.raw_minor <= 0 || rq.raw_minor >= MAX_RAW_MINORS) {
158 err = -EINVAL; 158 err = -EINVAL;
159 goto out; 159 goto out;
160 } 160 }
diff --git a/drivers/char/rio/rio_linux.c b/drivers/char/rio/rio_linux.c
index e79b2ede851..85c16184526 100644
--- a/drivers/char/rio/rio_linux.c
+++ b/drivers/char/rio/rio_linux.c
@@ -418,8 +418,7 @@ static void rio_pollfunc(unsigned long data)
418 func_enter(); 418 func_enter();
419 419
420 rio_interrupt(0, &p->RIOHosts[data]); 420 rio_interrupt(0, &p->RIOHosts[data]);
421 p->RIOHosts[data].timer.expires = jiffies + rio_poll; 421 mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
422 add_timer(&p->RIOHosts[data].timer);
423 422
424 func_exit(); 423 func_exit();
425} 424}
@@ -1154,13 +1153,10 @@ static int __init rio_init(void)
1154 /* Init the timer "always" to make sure that it can safely be 1153 /* Init the timer "always" to make sure that it can safely be
1155 deleted when we unload... */ 1154 deleted when we unload... */
1156 1155
1157 init_timer(&hp->timer); 1156 setup_timer(&hp->timer, rio_pollfunc, i);
1158 if (!hp->Ivec) { 1157 if (!hp->Ivec) {
1159 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll); 1158 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
1160 hp->timer.data = i; 1159 mod_timer(&hp->timer, jiffies + rio_poll);
1161 hp->timer.function = rio_pollfunc;
1162 hp->timer.expires = jiffies + rio_poll;
1163 add_timer(&hp->timer);
1164 } 1160 }
1165 } 1161 }
1166 1162
@@ -1191,7 +1187,7 @@ static void __exit rio_exit(void)
1191 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec); 1187 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1192 } 1188 }
1193 /* It is safe/allowed to del_timer a non-active timer */ 1189 /* It is safe/allowed to del_timer a non-active timer */
1194 del_timer(&hp->timer); 1190 del_timer_sync(&hp->timer);
1195 if (hp->Caddr) 1191 if (hp->Caddr)
1196 iounmap(hp->Caddr); 1192 iounmap(hp->Caddr);
1197 if (hp->Type == RIO_PCI) 1193 if (hp->Type == RIO_PCI)
diff --git a/drivers/char/rio/riointr.c b/drivers/char/rio/riointr.c
index eeda40c5e18..ebc76342712 100644
--- a/drivers/char/rio/riointr.c
+++ b/drivers/char/rio/riointr.c
@@ -162,13 +162,8 @@ void RIOTxEnable(char *en)
162 162
163 rio_spin_unlock_irqrestore(&PortP->portSem, flags); 163 rio_spin_unlock_irqrestore(&PortP->portSem, flags);
164 164
165 if (PortP->gs.xmit_cnt <= (PortP->gs.wakeup_chars + 2 * PKT_MAX_DATA_LEN)) { 165 if (PortP->gs.xmit_cnt <= (PortP->gs.wakeup_chars + 2 * PKT_MAX_DATA_LEN))
166 rio_dprintk(RIO_DEBUG_INTR, "Waking up.... ldisc:%d (%d/%d)....", (int) (PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)), PortP->gs.wakeup_chars, PortP->gs.xmit_cnt); 166 tty_wakeup(PortP->gs.tty);
167 if ((PortP->gs.tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && PortP->gs.tty->ldisc.write_wakeup)
168 (PortP->gs.tty->ldisc.write_wakeup) (PortP->gs.tty);
169 rio_dprintk(RIO_DEBUG_INTR, "(%d/%d)\n", PortP->gs.wakeup_chars, PortP->gs.xmit_cnt);
170 wake_up_interruptible(&PortP->gs.tty->write_wait);
171 }
172 167
173} 168}
174 169
diff --git a/drivers/char/riscom8.c b/drivers/char/riscom8.c
index e2a94bfb2a4..70145254fb9 100644
--- a/drivers/char/riscom8.c
+++ b/drivers/char/riscom8.c
@@ -1229,7 +1229,6 @@ static void rc_flush_buffer(struct tty_struct *tty)
1229 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0; 1229 port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
1230 restore_flags(flags); 1230 restore_flags(flags);
1231 1231
1232 wake_up_interruptible(&tty->write_wait);
1233 tty_wakeup(tty); 1232 tty_wakeup(tty);
1234} 1233}
1235 1234
@@ -1570,10 +1569,8 @@ static void do_softint(struct work_struct *ugly_api)
1570 if(!(tty = port->tty)) 1569 if(!(tty = port->tty))
1571 return; 1570 return;
1572 1571
1573 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) { 1572 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event))
1574 tty_wakeup(tty); 1573 tty_wakeup(tty);
1575 wake_up_interruptible(&tty->write_wait);
1576 }
1577} 1574}
1578 1575
1579static const struct tty_operations riscom_ops = { 1576static const struct tty_operations riscom_ops = {
diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
index e94a62e30fc..76357c855ce 100644
--- a/drivers/char/rocket.c
+++ b/drivers/char/rocket.c
@@ -106,6 +106,8 @@
106 106
107/****** RocketPort Local Variables ******/ 107/****** RocketPort Local Variables ******/
108 108
109static void rp_do_poll(unsigned long dummy);
110
109static struct tty_driver *rocket_driver; 111static struct tty_driver *rocket_driver;
110 112
111static struct rocket_version driver_version = { 113static struct rocket_version driver_version = {
@@ -116,7 +118,7 @@ static struct r_port *rp_table[MAX_RP_PORTS]; /* The main repository of
116static unsigned int xmit_flags[NUM_BOARDS]; /* Bit significant, indicates port had data to transmit. */ 118static unsigned int xmit_flags[NUM_BOARDS]; /* Bit significant, indicates port had data to transmit. */
117 /* eg. Bit 0 indicates port 0 has xmit data, ... */ 119 /* eg. Bit 0 indicates port 0 has xmit data, ... */
118static atomic_t rp_num_ports_open; /* Number of serial ports open */ 120static atomic_t rp_num_ports_open; /* Number of serial ports open */
119static struct timer_list rocket_timer; 121static DEFINE_TIMER(rocket_timer, rp_do_poll, 0, 0);
120 122
121static unsigned long board1; /* ISA addresses, retrieved from rocketport.conf */ 123static unsigned long board1; /* ISA addresses, retrieved from rocketport.conf */
122static unsigned long board2; 124static unsigned long board2;
@@ -474,7 +476,6 @@ static void rp_do_transmit(struct r_port *info)
474 476
475 if (info->xmit_cnt < WAKEUP_CHARS) { 477 if (info->xmit_cnt < WAKEUP_CHARS) {
476 tty_wakeup(tty); 478 tty_wakeup(tty);
477 wake_up_interruptible(&tty->write_wait);
478#ifdef ROCKETPORT_HAVE_POLL_WAIT 479#ifdef ROCKETPORT_HAVE_POLL_WAIT
479 wake_up_interruptible(&tty->poll_wait); 480 wake_up_interruptible(&tty->poll_wait);
480#endif 481#endif
@@ -1772,7 +1773,6 @@ static int rp_write(struct tty_struct *tty,
1772end: 1773end:
1773 if (info->xmit_cnt < WAKEUP_CHARS) { 1774 if (info->xmit_cnt < WAKEUP_CHARS) {
1774 tty_wakeup(tty); 1775 tty_wakeup(tty);
1775 wake_up_interruptible(&tty->write_wait);
1776#ifdef ROCKETPORT_HAVE_POLL_WAIT 1776#ifdef ROCKETPORT_HAVE_POLL_WAIT
1777 wake_up_interruptible(&tty->poll_wait); 1777 wake_up_interruptible(&tty->poll_wait);
1778#endif 1778#endif
@@ -1841,7 +1841,6 @@ static void rp_flush_buffer(struct tty_struct *tty)
1841 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 1841 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1842 spin_unlock_irqrestore(&info->slock, flags); 1842 spin_unlock_irqrestore(&info->slock, flags);
1843 1843
1844 wake_up_interruptible(&tty->write_wait);
1845#ifdef ROCKETPORT_HAVE_POLL_WAIT 1844#ifdef ROCKETPORT_HAVE_POLL_WAIT
1846 wake_up_interruptible(&tty->poll_wait); 1845 wake_up_interruptible(&tty->poll_wait);
1847#endif 1846#endif
@@ -2371,12 +2370,6 @@ static int __init rp_init(void)
2371 return -ENOMEM; 2370 return -ENOMEM;
2372 2371
2373 /* 2372 /*
2374 * Set up the timer channel.
2375 */
2376 init_timer(&rocket_timer);
2377 rocket_timer.function = rp_do_poll;
2378
2379 /*
2380 * Initialize the array of pointers to our own internal state 2373 * Initialize the array of pointers to our own internal state
2381 * structures. 2374 * structures.
2382 */ 2375 */
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index 664f36c98e6..b6d3072dce5 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -135,7 +135,9 @@ static struct fasync_struct *rtc_async_queue;
135static DECLARE_WAIT_QUEUE_HEAD(rtc_wait); 135static DECLARE_WAIT_QUEUE_HEAD(rtc_wait);
136 136
137#ifdef RTC_IRQ 137#ifdef RTC_IRQ
138static struct timer_list rtc_irq_timer; 138static void rtc_dropped_irq(unsigned long data);
139
140static DEFINE_TIMER(rtc_irq_timer, rtc_dropped_irq, 0, 0);
139#endif 141#endif
140 142
141static ssize_t rtc_read(struct file *file, char __user *buf, 143static ssize_t rtc_read(struct file *file, char __user *buf,
@@ -150,8 +152,6 @@ static unsigned int rtc_poll(struct file *file, poll_table *wait);
150 152
151static void get_rtc_alm_time (struct rtc_time *alm_tm); 153static void get_rtc_alm_time (struct rtc_time *alm_tm);
152#ifdef RTC_IRQ 154#ifdef RTC_IRQ
153static void rtc_dropped_irq(unsigned long data);
154
155static void set_rtc_irq_bit_locked(unsigned char bit); 155static void set_rtc_irq_bit_locked(unsigned char bit);
156static void mask_rtc_irq_bit_locked(unsigned char bit); 156static void mask_rtc_irq_bit_locked(unsigned char bit);
157 157
@@ -454,8 +454,8 @@ static int rtc_do_ioctl(unsigned int cmd, unsigned long arg, int kernel)
454 454
455 spin_lock_irqsave (&rtc_lock, flags); 455 spin_lock_irqsave (&rtc_lock, flags);
456 if (!(rtc_status & RTC_TIMER_ON)) { 456 if (!(rtc_status & RTC_TIMER_ON)) {
457 rtc_irq_timer.expires = jiffies + HZ/rtc_freq + 2*HZ/100; 457 mod_timer(&rtc_irq_timer, jiffies + HZ/rtc_freq +
458 add_timer(&rtc_irq_timer); 458 2*HZ/100);
459 rtc_status |= RTC_TIMER_ON; 459 rtc_status |= RTC_TIMER_ON;
460 } 460 }
461 set_rtc_irq_bit_locked(RTC_PIE); 461 set_rtc_irq_bit_locked(RTC_PIE);
@@ -1084,8 +1084,6 @@ no_irq:
1084 if (rtc_has_irq == 0) 1084 if (rtc_has_irq == 0)
1085 goto no_irq2; 1085 goto no_irq2;
1086 1086
1087 init_timer(&rtc_irq_timer);
1088 rtc_irq_timer.function = rtc_dropped_irq;
1089 spin_lock_irq(&rtc_lock); 1087 spin_lock_irq(&rtc_lock);
1090 rtc_freq = 1024; 1088 rtc_freq = 1024;
1091 if (!hpet_set_periodic_freq(rtc_freq)) { 1089 if (!hpet_set_periodic_freq(rtc_freq)) {
diff --git a/drivers/char/scan_keyb.c b/drivers/char/scan_keyb.c
deleted file mode 100644
index 2b5bb4f5754..00000000000
--- a/drivers/char/scan_keyb.c
+++ /dev/null
@@ -1,149 +0,0 @@
1/*
2 * $Id: scan_keyb.c,v 1.2 2000/07/04 06:24:42 yaegashi Exp $
3 * Copyright (C) 2000 YAEGASHI Takeshi
4 * Generic scan keyboard driver
5 */
6
7#include <linux/spinlock.h>
8#include <linux/sched.h>
9#include <linux/interrupt.h>
10#include <linux/tty.h>
11#include <linux/mm.h>
12#include <linux/signal.h>
13#include <linux/init.h>
14#include <linux/kbd_ll.h>
15#include <linux/delay.h>
16#include <linux/random.h>
17#include <linux/poll.h>
18#include <linux/miscdevice.h>
19#include <linux/slab.h>
20#include <linux/kbd_kern.h>
21#include <linux/timer.h>
22
23#define SCANHZ (HZ/20)
24
25struct scan_keyboard {
26 struct scan_keyboard *next;
27 int (*scan)(unsigned char *buffer);
28 const unsigned char *table;
29 unsigned char *s0, *s1;
30 int length;
31};
32
33static int scan_jiffies=0;
34static struct scan_keyboard *keyboards=NULL;
35struct timer_list scan_timer;
36
37static void check_kbd(const unsigned char *table,
38 unsigned char *new, unsigned char *old, int length)
39{
40 int need_tasklet_schedule=0;
41 unsigned int xor, bit;
42
43 while(length-->0) {
44 if((xor=*new^*old)==0) {
45 table+=8;
46 }
47 else {
48 for(bit=0x01; bit<0x100; bit<<=1) {
49 if(xor&bit) {
50 handle_scancode(*table, !(*new&bit));
51 need_tasklet_schedule=1;
52#if 0
53 printk("0x%x %s\n", *table, (*new&bit)?"released":"pressed");
54#endif
55 }
56 table++;
57 }
58 }
59 new++; old++;
60 }
61
62 if(need_tasklet_schedule)
63 tasklet_schedule(&keyboard_tasklet);
64}
65
66
67static void scan_kbd(unsigned long dummy)
68{
69 struct scan_keyboard *kbd;
70
71 scan_jiffies++;
72
73 for(kbd=keyboards; kbd!=NULL; kbd=kbd->next) {
74 if(scan_jiffies&1) {
75 if(!kbd->scan(kbd->s0))
76 check_kbd(kbd->table,
77 kbd->s0, kbd->s1, kbd->length);
78 else
79 memcpy(kbd->s0, kbd->s1, kbd->length);
80 }
81 else {
82 if(!kbd->scan(kbd->s1))
83 check_kbd(kbd->table,
84 kbd->s1, kbd->s0, kbd->length);
85 else
86 memcpy(kbd->s1, kbd->s0, kbd->length);
87 }
88
89 }
90
91 init_timer(&scan_timer);
92 scan_timer.expires = jiffies + SCANHZ;
93 scan_timer.data = 0;
94 scan_timer.function = scan_kbd;
95 add_timer(&scan_timer);
96}
97
98
99int register_scan_keyboard(int (*scan)(unsigned char *buffer),
100 const unsigned char *table,
101 int length)
102{
103 struct scan_keyboard *kbd;
104
105 kbd = kmalloc(sizeof(struct scan_keyboard), GFP_KERNEL);
106 if (kbd == NULL)
107 goto error_out;
108
109 kbd->scan=scan;
110 kbd->table=table;
111 kbd->length=length;
112
113 kbd->s0 = kmalloc(length, GFP_KERNEL);
114 if (kbd->s0 == NULL)
115 goto error_free_kbd;
116
117 kbd->s1 = kmalloc(length, GFP_KERNEL);
118 if (kbd->s1 == NULL)
119 goto error_free_s0;
120
121 memset(kbd->s0, -1, kbd->length);
122 memset(kbd->s1, -1, kbd->length);
123
124 kbd->next=keyboards;
125 keyboards=kbd;
126
127 return 0;
128
129 error_free_s0:
130 kfree(kbd->s0);
131
132 error_free_kbd:
133 kfree(kbd);
134
135 error_out:
136 return -ENOMEM;
137}
138
139
140void __init scan_kbd_init(void)
141{
142 init_timer(&scan_timer);
143 scan_timer.expires = jiffies + SCANHZ;
144 scan_timer.data = 0;
145 scan_timer.function = scan_kbd;
146 add_timer(&scan_timer);
147
148 printk(KERN_INFO "Generic scan keyboard driver initialized\n");
149}
diff --git a/drivers/char/scan_keyb.h b/drivers/char/scan_keyb.h
deleted file mode 100644
index b4b611290a0..00000000000
--- a/drivers/char/scan_keyb.h
+++ /dev/null
@@ -1,15 +0,0 @@
1#ifndef __DRIVER_CHAR_SCAN_KEYB_H
2#define __DRIVER_CHAR_SCAN_KEYB_H
3/*
4 * $Id: scan_keyb.h,v 1.1 2000/06/10 21:45:30 yaegashi Exp $
5 * Copyright (C) 2000 YAEGASHI Takeshi
6 * Generic scan keyboard driver
7 */
8
9int register_scan_keyboard(int (*scan)(unsigned char *buffer),
10 const unsigned char *table,
11 int length);
12
13void __init scan_kbd_init(void);
14
15#endif
diff --git a/drivers/char/serial167.c b/drivers/char/serial167.c
index af50d32ae2c..5fd314adc1f 100644
--- a/drivers/char/serial167.c
+++ b/drivers/char/serial167.c
@@ -111,12 +111,13 @@ u_char initial_console_speed;
111 111
112/* This is the per-port data structure */ 112/* This is the per-port data structure */
113struct cyclades_port cy_port[] = { 113struct cyclades_port cy_port[] = {
114 /* CARD# */ 114 /* CARD# */
115 {-1 }, /* ttyS0 */ 115 {-1}, /* ttyS0 */
116 {-1 }, /* ttyS1 */ 116 {-1}, /* ttyS1 */
117 {-1 }, /* ttyS2 */ 117 {-1}, /* ttyS2 */
118 {-1 }, /* ttyS3 */ 118 {-1}, /* ttyS3 */
119}; 119};
120
120#define NR_PORTS ARRAY_SIZE(cy_port) 121#define NR_PORTS ARRAY_SIZE(cy_port)
121 122
122/* 123/*
@@ -128,42 +129,46 @@ struct cyclades_port cy_port[] = {
128 * HI VHI 129 * HI VHI
129 */ 130 */
130static int baud_table[] = { 131static int baud_table[] = {
131 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 132 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
132 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000, 133 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
133 0}; 134 0
135};
134 136
135#if 0 137#if 0
136static char baud_co[] = { /* 25 MHz clock option table */ 138static char baud_co[] = { /* 25 MHz clock option table */
137 /* value => 00 01 02 03 04 */ 139 /* value => 00 01 02 03 04 */
138 /* divide by 8 32 128 512 2048 */ 140 /* divide by 8 32 128 512 2048 */
139 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02, 141 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
140 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 142 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
143};
141 144
142static char baud_bpr[] = { /* 25 MHz baud rate period table */ 145static char baud_bpr[] = { /* 25 MHz baud rate period table */
143 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3, 146 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
144 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15}; 147 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
148};
145#endif 149#endif
146 150
147/* I think 166 brd clocks 2401 at 20MHz.... */ 151/* I think 166 brd clocks 2401 at 20MHz.... */
148 152
149/* These values are written directly to tcor, and >> 5 for writing to rcor */ 153/* These values are written directly to tcor, and >> 5 for writing to rcor */
150static u_char baud_co[] = { /* 20 MHz clock option table */ 154static u_char baud_co[] = { /* 20 MHz clock option table */
151 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40, 155 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x60, 0x60, 0x40,
152 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 156 0x40, 0x40, 0x20, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
157};
153 158
154/* These values written directly to tbpr/rbpr */ 159/* These values written directly to tbpr/rbpr */
155static u_char baud_bpr[] = { /* 20 MHz baud rate period table */ 160static u_char baud_bpr[] = { /* 20 MHz baud rate period table */
156 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81, 161 0x00, 0xc0, 0x80, 0x58, 0x6c, 0x40, 0xc0, 0x81, 0x40, 0x81,
157 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10}; 162 0x57, 0x40, 0x81, 0x40, 0x81, 0x40, 0x2b, 0x20, 0x15, 0x10
158 163};
159static u_char baud_cor4[] = { /* receive threshold */
160 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
161 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
162
163 164
165static u_char baud_cor4[] = { /* receive threshold */
166 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
167 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07
168};
164 169
165static void shutdown(struct cyclades_port *); 170static void shutdown(struct cyclades_port *);
166static int startup (struct cyclades_port *); 171static int startup(struct cyclades_port *);
167static void cy_throttle(struct tty_struct *); 172static void cy_throttle(struct tty_struct *);
168static void cy_unthrottle(struct tty_struct *); 173static void cy_unthrottle(struct tty_struct *);
169static void config_setup(struct cyclades_port *); 174static void config_setup(struct cyclades_port *);
@@ -174,16 +179,16 @@ static void show_status(int);
174 179
175#ifdef CONFIG_REMOTE_DEBUG 180#ifdef CONFIG_REMOTE_DEBUG
176static void debug_setup(void); 181static void debug_setup(void);
177void queueDebugChar (int c); 182void queueDebugChar(int c);
178int getDebugChar(void); 183int getDebugChar(void);
179 184
180#define DEBUG_PORT 1 185#define DEBUG_PORT 1
181#define DEBUG_LEN 256 186#define DEBUG_LEN 256
182 187
183typedef struct { 188typedef struct {
184 int in; 189 int in;
185 int out; 190 int out;
186 unsigned char buf[DEBUG_LEN]; 191 unsigned char buf[DEBUG_LEN];
187} debugq; 192} debugq;
188 193
189debugq debugiq; 194debugq debugiq;
@@ -196,7 +201,7 @@ debugq debugiq;
196 * delay, but this wild guess will do for now. 201 * delay, but this wild guess will do for now.
197 */ 202 */
198 203
199void my_udelay (long us) 204void my_udelay(long us)
200{ 205{
201 u_char x; 206 u_char x;
202 volatile u_char *p = &x; 207 volatile u_char *p = &x;
@@ -207,62 +212,73 @@ void my_udelay (long us)
207 x |= *p; 212 x |= *p;
208} 213}
209 214
210static inline int 215static inline int serial_paranoia_check(struct cyclades_port *info, char *name,
211serial_paranoia_check(struct cyclades_port *info, char *name, 216 const char *routine)
212 const char *routine)
213{ 217{
214#ifdef SERIAL_PARANOIA_CHECK 218#ifdef SERIAL_PARANOIA_CHECK
215 static const char *badmagic = 219 if (!info) {
216 "Warning: bad magic number for serial struct (%s) in %s\n"; 220 printk("Warning: null cyclades_port for (%s) in %s\n", name,
217 static const char *badinfo = 221 routine);
218 "Warning: null cyclades_port for (%s) in %s\n"; 222 return 1;
219 static const char *badrange = 223 }
220 "Warning: cyclades_port out of range for (%s) in %s\n"; 224
221 225 if ((long)info < (long)(&cy_port[0])
222 if (!info) { 226 || (long)(&cy_port[NR_PORTS]) < (long)info) {
223 printk(badinfo, name, routine); 227 printk("Warning: cyclades_port out of range for (%s) in %s\n",
224 return 1; 228 name, routine);
225 } 229 return 1;
226 230 }
227 if( (long)info < (long)(&cy_port[0]) 231
228 || (long)(&cy_port[NR_PORTS]) < (long)info ){ 232 if (info->magic != CYCLADES_MAGIC) {
229 printk(badrange, name, routine); 233 printk("Warning: bad magic number for serial struct (%s) in "
230 return 1; 234 "%s\n", name, routine);
231 } 235 return 1;
232 236 }
233 if (info->magic != CYCLADES_MAGIC) {
234 printk(badmagic, name, routine);
235 return 1;
236 }
237#endif 237#endif
238 return 0; 238 return 0;
239} /* serial_paranoia_check */ 239} /* serial_paranoia_check */
240 240
241#if 0 241#if 0
242/* The following diagnostic routines allow the driver to spew 242/* The following diagnostic routines allow the driver to spew
243 information on the screen, even (especially!) during interrupts. 243 information on the screen, even (especially!) during interrupts.
244 */ 244 */
245void 245void SP(char *data)
246SP(char *data){ 246{
247 unsigned long flags; 247 unsigned long flags;
248 local_irq_save(flags); 248 local_irq_save(flags);
249 console_print(data); 249 console_print(data);
250 local_irq_restore(flags); 250 local_irq_restore(flags);
251} 251}
252
252char scrn[2]; 253char scrn[2];
253void 254void CP(char data)
254CP(char data){ 255{
255 unsigned long flags; 256 unsigned long flags;
256 local_irq_save(flags); 257 local_irq_save(flags);
257 scrn[0] = data; 258 scrn[0] = data;
258 console_print(scrn); 259 console_print(scrn);
259 local_irq_restore(flags); 260 local_irq_restore(flags);
260}/* CP */ 261} /* CP */
261 262
262void CP1(int data) { (data<10)? CP(data+'0'): CP(data+'A'-10); }/* CP1 */ 263void CP1(int data)
263void CP2(int data) { CP1((data>>4) & 0x0f); CP1( data & 0x0f); }/* CP2 */ 264{
264void CP4(int data) { CP2((data>>8) & 0xff); CP2(data & 0xff); }/* CP4 */ 265 (data < 10) ? CP(data + '0') : CP(data + 'A' - 10);
265void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */ 266} /* CP1 */
267void CP2(int data)
268{
269 CP1((data >> 4) & 0x0f);
270 CP1(data & 0x0f);
271} /* CP2 */
272void CP4(int data)
273{
274 CP2((data >> 8) & 0xff);
275 CP2(data & 0xff);
276} /* CP4 */
277void CP8(long data)
278{
279 CP4((data >> 16) & 0xffff);
280 CP4(data & 0xffff);
281} /* CP8 */
266#endif 282#endif
267 283
268/* This routine waits up to 1000 micro-seconds for the previous 284/* This routine waits up to 1000 micro-seconds for the previous
@@ -270,87 +286,78 @@ void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }/* CP8 */
270 new command. An error is returned if the previous command 286 new command. An error is returned if the previous command
271 didn't finish within the time limit. 287 didn't finish within the time limit.
272 */ 288 */
273u_short 289u_short write_cy_cmd(volatile u_char * base_addr, u_char cmd)
274write_cy_cmd(volatile u_char *base_addr, u_char cmd)
275{ 290{
276 unsigned long flags; 291 unsigned long flags;
277 volatile int i; 292 volatile int i;
278 293
279 local_irq_save(flags); 294 local_irq_save(flags);
280 /* Check to see that the previous command has completed */ 295 /* Check to see that the previous command has completed */
281 for(i = 0 ; i < 100 ; i++){ 296 for (i = 0; i < 100; i++) {
282 if (base_addr[CyCCR] == 0){ 297 if (base_addr[CyCCR] == 0) {
283 break; 298 break;
284 } 299 }
285 my_udelay(10L); 300 my_udelay(10L);
286 } 301 }
287 /* if the CCR never cleared, the previous command 302 /* if the CCR never cleared, the previous command
288 didn't finish within the "reasonable time" */ 303 didn't finish within the "reasonable time" */
289 if ( i == 10 ) { 304 if (i == 10) {
290 local_irq_restore(flags); 305 local_irq_restore(flags);
291 return (-1); 306 return (-1);
292 } 307 }
293 308
294 /* Issue the new command */ 309 /* Issue the new command */
295 base_addr[CyCCR] = cmd; 310 base_addr[CyCCR] = cmd;
296 local_irq_restore(flags); 311 local_irq_restore(flags);
297 return(0); 312 return (0);
298} /* write_cy_cmd */ 313} /* write_cy_cmd */
299
300 314
301/* cy_start and cy_stop provide software output flow control as a 315/* cy_start and cy_stop provide software output flow control as a
302 function of XON/XOFF, software CTS, and other such stuff. */ 316 function of XON/XOFF, software CTS, and other such stuff. */
303 317
304static void 318static void cy_stop(struct tty_struct *tty)
305cy_stop(struct tty_struct *tty)
306{ 319{
307 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 320 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
308 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 321 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
309 int channel; 322 int channel;
310 unsigned long flags; 323 unsigned long flags;
311 324
312#ifdef SERIAL_DEBUG_OTHER 325#ifdef SERIAL_DEBUG_OTHER
313 printk("cy_stop %s\n", tty->name); /* */ 326 printk("cy_stop %s\n", tty->name); /* */
314#endif 327#endif
315 328
316 if (serial_paranoia_check(info, tty->name, "cy_stop")) 329 if (serial_paranoia_check(info, tty->name, "cy_stop"))
317 return; 330 return;
318
319 channel = info->line;
320 331
321 local_irq_save(flags); 332 channel = info->line;
322 base_addr[CyCAR] = (u_char)(channel); /* index channel */
323 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
324 local_irq_restore(flags);
325 333
326 return; 334 local_irq_save(flags);
327} /* cy_stop */ 335 base_addr[CyCAR] = (u_char) (channel); /* index channel */
336 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
337 local_irq_restore(flags);
338} /* cy_stop */
328 339
329static void 340static void cy_start(struct tty_struct *tty)
330cy_start(struct tty_struct *tty)
331{ 341{
332 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 342 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
333 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 343 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
334 int channel; 344 int channel;
335 unsigned long flags; 345 unsigned long flags;
336 346
337#ifdef SERIAL_DEBUG_OTHER 347#ifdef SERIAL_DEBUG_OTHER
338 printk("cy_start %s\n", tty->name); /* */ 348 printk("cy_start %s\n", tty->name); /* */
339#endif 349#endif
340 350
341 if (serial_paranoia_check(info, tty->name, "cy_start")) 351 if (serial_paranoia_check(info, tty->name, "cy_start"))
342 return; 352 return;
343
344 channel = info->line;
345 353
346 local_irq_save(flags); 354 channel = info->line;
347 base_addr[CyCAR] = (u_char)(channel);
348 base_addr[CyIER] |= CyTxMpty;
349 local_irq_restore(flags);
350
351 return;
352} /* cy_start */
353 355
356 local_irq_save(flags);
357 base_addr[CyCAR] = (u_char) (channel);
358 base_addr[CyIER] |= CyTxMpty;
359 local_irq_restore(flags);
360} /* cy_start */
354 361
355/* 362/*
356 * This routine is used by the interrupt handler to schedule 363 * This routine is used by the interrupt handler to schedule
@@ -358,332 +365,332 @@ cy_start(struct tty_struct *tty)
358 * (also known as the "bottom half"). This can be called any 365 * (also known as the "bottom half"). This can be called any
359 * number of times for any channel without harm. 366 * number of times for any channel without harm.
360 */ 367 */
361static inline void 368static inline void cy_sched_event(struct cyclades_port *info, int event)
362cy_sched_event(struct cyclades_port *info, int event)
363{ 369{
364 info->event |= 1 << event; /* remember what kind of event and who */ 370 info->event |= 1 << event; /* remember what kind of event and who */
365 schedule_work(&info->tqueue); 371 schedule_work(&info->tqueue);
366} /* cy_sched_event */ 372} /* cy_sched_event */
367
368 373
369/* The real interrupt service routines are called 374/* The real interrupt service routines are called
370 whenever the card wants its hand held--chars 375 whenever the card wants its hand held--chars
371 received, out buffer empty, modem change, etc. 376 received, out buffer empty, modem change, etc.
372 */ 377 */
373static irqreturn_t 378static irqreturn_t cd2401_rxerr_interrupt(int irq, void *dev_id)
374cd2401_rxerr_interrupt(int irq, void *dev_id)
375{ 379{
376 struct tty_struct *tty; 380 struct tty_struct *tty;
377 struct cyclades_port *info; 381 struct cyclades_port *info;
378 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 382 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
379 unsigned char err, rfoc; 383 unsigned char err, rfoc;
380 int channel; 384 int channel;
381 char data; 385 char data;
382 386
383 /* determine the channel and change to that context */ 387 /* determine the channel and change to that context */
384 channel = (u_short ) (base_addr[CyLICR] >> 2); 388 channel = (u_short) (base_addr[CyLICR] >> 2);
385 info = &cy_port[channel]; 389 info = &cy_port[channel];
386 info->last_active = jiffies; 390 info->last_active = jiffies;
387 391
388 if ((err = base_addr[CyRISR]) & CyTIMEOUT) { 392 if ((err = base_addr[CyRISR]) & CyTIMEOUT) {
389 /* This is a receive timeout interrupt, ignore it */ 393 /* This is a receive timeout interrupt, ignore it */
390 base_addr[CyREOIR] = CyNOTRANS; 394 base_addr[CyREOIR] = CyNOTRANS;
391 return IRQ_HANDLED; 395 return IRQ_HANDLED;
392 } 396 }
393
394 /* Read a byte of data if there is any - assume the error
395 * is associated with this character */
396 397
397 if ((rfoc = base_addr[CyRFOC]) != 0) 398 /* Read a byte of data if there is any - assume the error
398 data = base_addr[CyRDR]; 399 * is associated with this character */
399 else
400 data = 0;
401 400
402 /* if there is nowhere to put the data, discard it */ 401 if ((rfoc = base_addr[CyRFOC]) != 0)
403 if(info->tty == 0) { 402 data = base_addr[CyRDR];
403 else
404 data = 0;
405
406 /* if there is nowhere to put the data, discard it */
407 if (info->tty == 0) {
408 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
409 return IRQ_HANDLED;
410 } else { /* there is an open port for this data */
411 tty = info->tty;
412 if (err & info->ignore_status_mask) {
413 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
414 return IRQ_HANDLED;
415 }
416 if (tty_buffer_request_room(tty, 1) != 0) {
417 if (err & info->read_status_mask) {
418 if (err & CyBREAK) {
419 tty_insert_flip_char(tty, data,
420 TTY_BREAK);
421 if (info->flags & ASYNC_SAK) {
422 do_SAK(tty);
423 }
424 } else if (err & CyFRAME) {
425 tty_insert_flip_char(tty, data,
426 TTY_FRAME);
427 } else if (err & CyPARITY) {
428 tty_insert_flip_char(tty, data,
429 TTY_PARITY);
430 } else if (err & CyOVERRUN) {
431 tty_insert_flip_char(tty, 0,
432 TTY_OVERRUN);
433 /*
434 If the flip buffer itself is
435 overflowing, we still loose
436 the next incoming character.
437 */
438 if (tty_buffer_request_room(tty, 1) !=
439 0) {
440 tty_insert_flip_char(tty, data,
441 TTY_FRAME);
442 }
443 /* These two conditions may imply */
444 /* a normal read should be done. */
445 /* else if(data & CyTIMEOUT) */
446 /* else if(data & CySPECHAR) */
447 } else {
448 tty_insert_flip_char(tty, 0,
449 TTY_NORMAL);
450 }
451 } else {
452 tty_insert_flip_char(tty, data, TTY_NORMAL);
453 }
454 } else {
455 /* there was a software buffer overrun
456 and nothing could be done about it!!! */
457 }
458 }
459 tty_schedule_flip(tty);
460 /* end of service */
404 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS; 461 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
405 return IRQ_HANDLED; 462 return IRQ_HANDLED;
406 } 463} /* cy_rxerr_interrupt */
407 else { /* there is an open port for this data */ 464
408 tty = info->tty; 465static irqreturn_t cd2401_modem_interrupt(int irq, void *dev_id)
409 if(err & info->ignore_status_mask){
410 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
411 return IRQ_HANDLED;
412 }
413 if (tty_buffer_request_room(tty, 1) != 0){
414 if (err & info->read_status_mask){
415 if(err & CyBREAK){
416 tty_insert_flip_char(tty, data, TTY_BREAK);
417 if (info->flags & ASYNC_SAK){
418 do_SAK(tty);
419 }
420 }else if(err & CyFRAME){
421 tty_insert_flip_char(tty, data, TTY_FRAME);
422 }else if(err & CyPARITY){
423 tty_insert_flip_char(tty, data, TTY_PARITY);
424 }else if(err & CyOVERRUN){
425 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
426 /*
427 If the flip buffer itself is
428 overflowing, we still loose
429 the next incoming character.
430 */
431 if (tty_buffer_request_room(tty, 1) != 0){
432 tty_insert_flip_char(tty, data, TTY_FRAME);
433 }
434 /* These two conditions may imply */
435 /* a normal read should be done. */
436 /* else if(data & CyTIMEOUT) */
437 /* else if(data & CySPECHAR) */
438 }else{
439 tty_insert_flip_char(tty, 0, TTY_NORMAL);
440 }
441 }else{
442 tty_insert_flip_char(tty, data, TTY_NORMAL);
443 }
444 }else{
445 /* there was a software buffer overrun
446 and nothing could be done about it!!! */
447 }
448 }
449 tty_schedule_flip(tty);
450 /* end of service */
451 base_addr[CyREOIR] = rfoc ? 0 : CyNOTRANS;
452 return IRQ_HANDLED;
453} /* cy_rxerr_interrupt */
454
455static irqreturn_t
456cd2401_modem_interrupt(int irq, void *dev_id)
457{ 466{
458 struct cyclades_port *info; 467 struct cyclades_port *info;
459 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 468 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
460 int channel; 469 int channel;
461 int mdm_change; 470 int mdm_change;
462 int mdm_status; 471 int mdm_status;
463 472
464 473 /* determine the channel and change to that context */
465 /* determine the channel and change to that context */ 474 channel = (u_short) (base_addr[CyLICR] >> 2);
466 channel = (u_short ) (base_addr[CyLICR] >> 2); 475 info = &cy_port[channel];
467 info = &cy_port[channel]; 476 info->last_active = jiffies;
468 info->last_active = jiffies; 477
469 478 mdm_change = base_addr[CyMISR];
470 mdm_change = base_addr[CyMISR]; 479 mdm_status = base_addr[CyMSVR1];
471 mdm_status = base_addr[CyMSVR1]; 480
472 481 if (info->tty == 0) { /* nowhere to put the data, ignore it */
473 if(info->tty == 0){ /* nowhere to put the data, ignore it */ 482 ;
474 ; 483 } else {
475 }else{ 484 if ((mdm_change & CyDCD)
476 if((mdm_change & CyDCD) 485 && (info->flags & ASYNC_CHECK_CD)) {
477 && (info->flags & ASYNC_CHECK_CD)){ 486 if (mdm_status & CyDCD) {
478 if(mdm_status & CyDCD){
479/* CP('!'); */ 487/* CP('!'); */
480 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP); 488 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
481 } else { 489 } else {
482/* CP('@'); */ 490/* CP('@'); */
483 cy_sched_event(info, Cy_EVENT_HANGUP); 491 cy_sched_event(info, Cy_EVENT_HANGUP);
484 } 492 }
485 }
486 if((mdm_change & CyCTS)
487 && (info->flags & ASYNC_CTS_FLOW)){
488 if(info->tty->stopped){
489 if(mdm_status & CyCTS){
490 /* !!! cy_start isn't used because... */
491 info->tty->stopped = 0;
492 base_addr[CyIER] |= CyTxMpty;
493 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
494 } 493 }
495 }else{ 494 if ((mdm_change & CyCTS)
496 if(!(mdm_status & CyCTS)){ 495 && (info->flags & ASYNC_CTS_FLOW)) {
497 /* !!! cy_stop isn't used because... */ 496 if (info->tty->stopped) {
498 info->tty->stopped = 1; 497 if (mdm_status & CyCTS) {
499 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy); 498 /* !!! cy_start isn't used because... */
499 info->tty->stopped = 0;
500 base_addr[CyIER] |= CyTxMpty;
501 cy_sched_event(info,
502 Cy_EVENT_WRITE_WAKEUP);
503 }
504 } else {
505 if (!(mdm_status & CyCTS)) {
506 /* !!! cy_stop isn't used because... */
507 info->tty->stopped = 1;
508 base_addr[CyIER] &=
509 ~(CyTxMpty | CyTxRdy);
510 }
511 }
512 }
513 if (mdm_status & CyDSR) {
500 } 514 }
501 }
502 }
503 if(mdm_status & CyDSR){
504 } 515 }
505 } 516 base_addr[CyMEOIR] = 0;
506 base_addr[CyMEOIR] = 0; 517 return IRQ_HANDLED;
507 return IRQ_HANDLED; 518} /* cy_modem_interrupt */
508} /* cy_modem_interrupt */
509 519
510static irqreturn_t 520static irqreturn_t cd2401_tx_interrupt(int irq, void *dev_id)
511cd2401_tx_interrupt(int irq, void *dev_id)
512{ 521{
513 struct cyclades_port *info; 522 struct cyclades_port *info;
514 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 523 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
515 int channel; 524 int channel;
516 int char_count, saved_cnt; 525 int char_count, saved_cnt;
517 int outch; 526 int outch;
518 527
519 /* determine the channel and change to that context */ 528 /* determine the channel and change to that context */
520 channel = (u_short ) (base_addr[CyLICR] >> 2); 529 channel = (u_short) (base_addr[CyLICR] >> 2);
521 530
522#ifdef CONFIG_REMOTE_DEBUG 531#ifdef CONFIG_REMOTE_DEBUG
523 if (channel == DEBUG_PORT) { 532 if (channel == DEBUG_PORT) {
524 panic ("TxInt on debug port!!!"); 533 panic("TxInt on debug port!!!");
525 } 534 }
526#endif 535#endif
527 536
528 info = &cy_port[channel]; 537 info = &cy_port[channel];
529 538
530 /* validate the port number (as configured and open) */ 539 /* validate the port number (as configured and open) */
531 if( (channel < 0) || (NR_PORTS <= channel) ){ 540 if ((channel < 0) || (NR_PORTS <= channel)) {
532 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy); 541 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
533 base_addr[CyTEOIR] = CyNOTRANS; 542 base_addr[CyTEOIR] = CyNOTRANS;
534 return IRQ_HANDLED; 543 return IRQ_HANDLED;
535 } 544 }
536 info->last_active = jiffies; 545 info->last_active = jiffies;
537 if(info->tty == 0){ 546 if (info->tty == 0) {
538 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy); 547 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
539 if (info->xmit_cnt < WAKEUP_CHARS) { 548 if (info->xmit_cnt < WAKEUP_CHARS) {
540 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 549 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
541 } 550 }
542 base_addr[CyTEOIR] = CyNOTRANS; 551 base_addr[CyTEOIR] = CyNOTRANS;
543 return IRQ_HANDLED; 552 return IRQ_HANDLED;
544 } 553 }
545 554
546 /* load the on-chip space available for outbound data */ 555 /* load the on-chip space available for outbound data */
547 saved_cnt = char_count = base_addr[CyTFTC]; 556 saved_cnt = char_count = base_addr[CyTFTC];
548 557
549 if(info->x_char) { /* send special char */ 558 if (info->x_char) { /* send special char */
550 outch = info->x_char; 559 outch = info->x_char;
551 base_addr[CyTDR] = outch;
552 char_count--;
553 info->x_char = 0;
554 }
555
556 if (info->x_break){
557 /* The Cirrus chip requires the "Embedded Transmit
558 Commands" of start break, delay, and end break
559 sequences to be sent. The duration of the
560 break is given in TICs, which runs at HZ
561 (typically 100) and the PPR runs at 200 Hz,
562 so the delay is duration * 200/HZ, and thus a
563 break can run from 1/100 sec to about 5/4 sec.
564 Need to check these values - RGH 141095.
565 */
566 base_addr[CyTDR] = 0; /* start break */
567 base_addr[CyTDR] = 0x81;
568 base_addr[CyTDR] = 0; /* delay a bit */
569 base_addr[CyTDR] = 0x82;
570 base_addr[CyTDR] = info->x_break*200/HZ;
571 base_addr[CyTDR] = 0; /* terminate break */
572 base_addr[CyTDR] = 0x83;
573 char_count -= 7;
574 info->x_break = 0;
575 }
576
577 while (char_count > 0){
578 if (!info->xmit_cnt){
579 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
580 break;
581 }
582 if (info->xmit_buf == 0){
583 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
584 break;
585 }
586 if (info->tty->stopped || info->tty->hw_stopped){
587 base_addr[CyIER] &= ~(CyTxMpty|CyTxRdy);
588 break;
589 }
590 /* Because the Embedded Transmit Commands have been
591 enabled, we must check to see if the escape
592 character, NULL, is being sent. If it is, we
593 must ensure that there is room for it to be
594 doubled in the output stream. Therefore we
595 no longer advance the pointer when the character
596 is fetched, but rather wait until after the check
597 for a NULL output character. (This is necessary
598 because there may not be room for the two chars
599 needed to send a NULL.
600 */
601 outch = info->xmit_buf[info->xmit_tail];
602 if( outch ){
603 info->xmit_cnt--;
604 info->xmit_tail = (info->xmit_tail + 1)
605 & (PAGE_SIZE - 1);
606 base_addr[CyTDR] = outch;
607 char_count--;
608 }else{
609 if(char_count > 1){
610 info->xmit_cnt--;
611 info->xmit_tail = (info->xmit_tail + 1)
612 & (PAGE_SIZE - 1);
613 base_addr[CyTDR] = outch; 560 base_addr[CyTDR] = outch;
614 base_addr[CyTDR] = 0;
615 char_count--; 561 char_count--;
616 char_count--; 562 info->x_char = 0;
617 }else{
618 break;
619 }
620 } 563 }
621 }
622 564
623 if (info->xmit_cnt < WAKEUP_CHARS) { 565 if (info->x_break) {
624 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 566 /* The Cirrus chip requires the "Embedded Transmit
625 } 567 Commands" of start break, delay, and end break
626 base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS; 568 sequences to be sent. The duration of the
627 return IRQ_HANDLED; 569 break is given in TICs, which runs at HZ
628} /* cy_tx_interrupt */ 570 (typically 100) and the PPR runs at 200 Hz,
571 so the delay is duration * 200/HZ, and thus a
572 break can run from 1/100 sec to about 5/4 sec.
573 Need to check these values - RGH 141095.
574 */
575 base_addr[CyTDR] = 0; /* start break */
576 base_addr[CyTDR] = 0x81;
577 base_addr[CyTDR] = 0; /* delay a bit */
578 base_addr[CyTDR] = 0x82;
579 base_addr[CyTDR] = info->x_break * 200 / HZ;
580 base_addr[CyTDR] = 0; /* terminate break */
581 base_addr[CyTDR] = 0x83;
582 char_count -= 7;
583 info->x_break = 0;
584 }
585
586 while (char_count > 0) {
587 if (!info->xmit_cnt) {
588 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
589 break;
590 }
591 if (info->xmit_buf == 0) {
592 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
593 break;
594 }
595 if (info->tty->stopped || info->tty->hw_stopped) {
596 base_addr[CyIER] &= ~(CyTxMpty | CyTxRdy);
597 break;
598 }
599 /* Because the Embedded Transmit Commands have been
600 enabled, we must check to see if the escape
601 character, NULL, is being sent. If it is, we
602 must ensure that there is room for it to be
603 doubled in the output stream. Therefore we
604 no longer advance the pointer when the character
605 is fetched, but rather wait until after the check
606 for a NULL output character. (This is necessary
607 because there may not be room for the two chars
608 needed to send a NULL.
609 */
610 outch = info->xmit_buf[info->xmit_tail];
611 if (outch) {
612 info->xmit_cnt--;
613 info->xmit_tail = (info->xmit_tail + 1)
614 & (PAGE_SIZE - 1);
615 base_addr[CyTDR] = outch;
616 char_count--;
617 } else {
618 if (char_count > 1) {
619 info->xmit_cnt--;
620 info->xmit_tail = (info->xmit_tail + 1)
621 & (PAGE_SIZE - 1);
622 base_addr[CyTDR] = outch;
623 base_addr[CyTDR] = 0;
624 char_count--;
625 char_count--;
626 } else {
627 break;
628 }
629 }
630 }
631
632 if (info->xmit_cnt < WAKEUP_CHARS) {
633 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
634 }
635 base_addr[CyTEOIR] = (char_count != saved_cnt) ? 0 : CyNOTRANS;
636 return IRQ_HANDLED;
637} /* cy_tx_interrupt */
629 638
630static irqreturn_t 639static irqreturn_t cd2401_rx_interrupt(int irq, void *dev_id)
631cd2401_rx_interrupt(int irq, void *dev_id)
632{ 640{
633 struct tty_struct *tty; 641 struct tty_struct *tty;
634 struct cyclades_port *info; 642 struct cyclades_port *info;
635 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 643 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
636 int channel; 644 int channel;
637 char data; 645 char data;
638 int char_count; 646 int char_count;
639 int save_cnt; 647 int save_cnt;
640 int len; 648 int len;
641 649
642 /* determine the channel and change to that context */ 650 /* determine the channel and change to that context */
643 channel = (u_short ) (base_addr[CyLICR] >> 2); 651 channel = (u_short) (base_addr[CyLICR] >> 2);
644 info = &cy_port[channel]; 652 info = &cy_port[channel];
645 info->last_active = jiffies; 653 info->last_active = jiffies;
646 save_cnt = char_count = base_addr[CyRFOC]; 654 save_cnt = char_count = base_addr[CyRFOC];
647 655
648#ifdef CONFIG_REMOTE_DEBUG 656#ifdef CONFIG_REMOTE_DEBUG
649 if (channel == DEBUG_PORT) { 657 if (channel == DEBUG_PORT) {
650 while (char_count--) { 658 while (char_count--) {
651 data = base_addr[CyRDR]; 659 data = base_addr[CyRDR];
652 queueDebugChar(data); 660 queueDebugChar(data);
653 } 661 }
654 } 662 } else
655 else
656#endif 663#endif
657 /* if there is nowhere to put the data, discard it */ 664 /* if there is nowhere to put the data, discard it */
658 if(info->tty == 0){ 665 if (info->tty == 0) {
659 while(char_count--){ 666 while (char_count--) {
660 data = base_addr[CyRDR]; 667 data = base_addr[CyRDR];
661 } 668 }
662 }else{ /* there is an open port for this data */ 669 } else { /* there is an open port for this data */
663 tty = info->tty; 670 tty = info->tty;
664 /* load # characters available from the chip */ 671 /* load # characters available from the chip */
665 672
666#ifdef CYCLOM_ENABLE_MONITORING 673#ifdef CYCLOM_ENABLE_MONITORING
667 ++info->mon.int_count; 674 ++info->mon.int_count;
668 info->mon.char_count += char_count; 675 info->mon.char_count += char_count;
669 if (char_count > info->mon.char_max) 676 if (char_count > info->mon.char_max)
670 info->mon.char_max = char_count; 677 info->mon.char_max = char_count;
671 info->mon.char_last = char_count; 678 info->mon.char_last = char_count;
672#endif 679#endif
673 len = tty_buffer_request_room(tty, char_count); 680 len = tty_buffer_request_room(tty, char_count);
674 while(len--){ 681 while (len--) {
675 data = base_addr[CyRDR]; 682 data = base_addr[CyRDR];
676 tty_insert_flip_char(tty, data, TTY_NORMAL); 683 tty_insert_flip_char(tty, data, TTY_NORMAL);
677#ifdef CYCLOM_16Y_HACK 684#ifdef CYCLOM_16Y_HACK
678 udelay(10L); 685 udelay(10L);
679#endif 686#endif
680 } 687 }
681 tty_schedule_flip(tty); 688 tty_schedule_flip(tty);
682 } 689 }
683 /* end of service */ 690 /* end of service */
684 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS; 691 base_addr[CyREOIR] = save_cnt ? 0 : CyNOTRANS;
685 return IRQ_HANDLED; 692 return IRQ_HANDLED;
686} /* cy_rx_interrupt */ 693} /* cy_rx_interrupt */
687 694
688/* 695/*
689 * This routine is used to handle the "bottom half" processing for the 696 * This routine is used to handle the "bottom half" processing for the
@@ -705,192 +712,188 @@ cd2401_rx_interrupt(int irq, void *dev_id)
705 * structure) to the bottom half of the driver. Previous kernels 712 * structure) to the bottom half of the driver. Previous kernels
706 * had to poll every port to see if that port needed servicing. 713 * had to poll every port to see if that port needed servicing.
707 */ 714 */
708static void 715static void do_softint(struct work_struct *ugly_api)
709do_softint(struct work_struct *ugly_api)
710{ 716{
711 struct cyclades_port *info = container_of(ugly_api, struct cyclades_port, tqueue); 717 struct cyclades_port *info =
712 struct tty_struct *tty; 718 container_of(ugly_api, struct cyclades_port, tqueue);
713 719 struct tty_struct *tty;
714 tty = info->tty;
715 if (!tty)
716 return;
717 720
718 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) { 721 tty = info->tty;
719 tty_hangup(info->tty); 722 if (!tty)
720 wake_up_interruptible(&info->open_wait); 723 return;
721 info->flags &= ~ASYNC_NORMAL_ACTIVE;
722 }
723 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
724 wake_up_interruptible(&info->open_wait);
725 }
726 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
727 tty_wakeup(tty);
728 }
729} /* do_softint */
730 724
725 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
726 tty_hangup(info->tty);
727 wake_up_interruptible(&info->open_wait);
728 info->flags &= ~ASYNC_NORMAL_ACTIVE;
729 }
730 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
731 wake_up_interruptible(&info->open_wait);
732 }
733 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
734 tty_wakeup(tty);
735 }
736} /* do_softint */
731 737
732/* This is called whenever a port becomes active; 738/* This is called whenever a port becomes active;
733 interrupts are enabled and DTR & RTS are turned on. 739 interrupts are enabled and DTR & RTS are turned on.
734 */ 740 */
735static int 741static int startup(struct cyclades_port *info)
736startup(struct cyclades_port * info)
737{ 742{
738 unsigned long flags; 743 unsigned long flags;
739 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR; 744 volatile unsigned char *base_addr = (unsigned char *)BASE_ADDR;
740 int channel; 745 int channel;
741 746
742 if (info->flags & ASYNC_INITIALIZED){ 747 if (info->flags & ASYNC_INITIALIZED) {
743 return 0; 748 return 0;
744 } 749 }
745 750
746 if (!info->type){ 751 if (!info->type) {
747 if (info->tty){ 752 if (info->tty) {
748 set_bit(TTY_IO_ERROR, &info->tty->flags); 753 set_bit(TTY_IO_ERROR, &info->tty->flags);
754 }
755 return 0;
749 } 756 }
750 return 0; 757 if (!info->xmit_buf) {
751 } 758 info->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
752 if (!info->xmit_buf){ 759 if (!info->xmit_buf) {
753 info->xmit_buf = (unsigned char *) get_zeroed_page (GFP_KERNEL); 760 return -ENOMEM;
754 if (!info->xmit_buf){ 761 }
755 return -ENOMEM;
756 } 762 }
757 }
758 763
759 config_setup(info); 764 config_setup(info);
760 765
761 channel = info->line; 766 channel = info->line;
762 767
763#ifdef SERIAL_DEBUG_OPEN 768#ifdef SERIAL_DEBUG_OPEN
764 printk("startup channel %d\n", channel); 769 printk("startup channel %d\n", channel);
765#endif 770#endif
766 771
767 local_irq_save(flags); 772 local_irq_save(flags);
768 base_addr[CyCAR] = (u_char)channel; 773 base_addr[CyCAR] = (u_char) channel;
769 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR); 774 write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);
770 775
771 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */ 776 base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */
772 base_addr[CyMSVR1] = CyRTS; 777 base_addr[CyMSVR1] = CyRTS;
773/* CP('S');CP('1'); */ 778/* CP('S');CP('1'); */
774 base_addr[CyMSVR2] = CyDTR; 779 base_addr[CyMSVR2] = CyDTR;
775 780
776#ifdef SERIAL_DEBUG_DTR 781#ifdef SERIAL_DEBUG_DTR
777 printk("cyc: %d: raising DTR\n", __LINE__); 782 printk("cyc: %d: raising DTR\n", __LINE__);
778 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 783 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
784 base_addr[CyMSVR2]);
779#endif 785#endif
780 786
781 base_addr[CyIER] |= CyRxData; 787 base_addr[CyIER] |= CyRxData;
782 info->flags |= ASYNC_INITIALIZED; 788 info->flags |= ASYNC_INITIALIZED;
783 789
784 if (info->tty){ 790 if (info->tty) {
785 clear_bit(TTY_IO_ERROR, &info->tty->flags); 791 clear_bit(TTY_IO_ERROR, &info->tty->flags);
786 } 792 }
787 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 793 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
788 794
789 local_irq_restore(flags); 795 local_irq_restore(flags);
790 796
791#ifdef SERIAL_DEBUG_OPEN 797#ifdef SERIAL_DEBUG_OPEN
792 printk(" done\n"); 798 printk(" done\n");
793#endif 799#endif
794 return 0; 800 return 0;
795} /* startup */ 801} /* startup */
796 802
797void 803void start_xmit(struct cyclades_port *info)
798start_xmit( struct cyclades_port *info )
799{ 804{
800 unsigned long flags; 805 unsigned long flags;
801 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 806 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
802 int channel; 807 int channel;
803 808
804 channel = info->line; 809 channel = info->line;
805 local_irq_save(flags); 810 local_irq_save(flags);
806 base_addr[CyCAR] = channel; 811 base_addr[CyCAR] = channel;
807 base_addr[CyIER] |= CyTxMpty; 812 base_addr[CyIER] |= CyTxMpty;
808 local_irq_restore(flags); 813 local_irq_restore(flags);
809} /* start_xmit */ 814} /* start_xmit */
810 815
811/* 816/*
812 * This routine shuts down a serial port; interrupts are disabled, 817 * This routine shuts down a serial port; interrupts are disabled,
813 * and DTR is dropped if the hangup on close termio flag is on. 818 * and DTR is dropped if the hangup on close termio flag is on.
814 */ 819 */
815static void 820static void shutdown(struct cyclades_port *info)
816shutdown(struct cyclades_port * info)
817{ 821{
818 unsigned long flags; 822 unsigned long flags;
819 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 823 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
820 int channel; 824 int channel;
821 825
822 if (!(info->flags & ASYNC_INITIALIZED)){ 826 if (!(info->flags & ASYNC_INITIALIZED)) {
823/* CP('$'); */ 827/* CP('$'); */
824 return; 828 return;
825 } 829 }
826 830
827 channel = info->line; 831 channel = info->line;
828 832
829#ifdef SERIAL_DEBUG_OPEN 833#ifdef SERIAL_DEBUG_OPEN
830 printk("shutdown channel %d\n", channel); 834 printk("shutdown channel %d\n", channel);
831#endif 835#endif
832 836
833 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE 837 /* !!! REALLY MUST WAIT FOR LAST CHARACTER TO BE
834 SENT BEFORE DROPPING THE LINE !!! (Perhaps 838 SENT BEFORE DROPPING THE LINE !!! (Perhaps
835 set some flag that is read when XMTY happens.) 839 set some flag that is read when XMTY happens.)
836 Other choices are to delay some fixed interval 840 Other choices are to delay some fixed interval
837 or schedule some later processing. 841 or schedule some later processing.
838 */ 842 */
839 local_irq_save(flags); 843 local_irq_save(flags);
840 if (info->xmit_buf){ 844 if (info->xmit_buf) {
841 free_page((unsigned long) info->xmit_buf); 845 free_page((unsigned long)info->xmit_buf);
842 info->xmit_buf = NULL; 846 info->xmit_buf = NULL;
843 } 847 }
844 848
845 base_addr[CyCAR] = (u_char)channel; 849 base_addr[CyCAR] = (u_char) channel;
846 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { 850 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
847 base_addr[CyMSVR1] = 0; 851 base_addr[CyMSVR1] = 0;
848/* CP('C');CP('1'); */ 852/* CP('C');CP('1'); */
849 base_addr[CyMSVR2] = 0; 853 base_addr[CyMSVR2] = 0;
850#ifdef SERIAL_DEBUG_DTR 854#ifdef SERIAL_DEBUG_DTR
851 printk("cyc: %d: dropping DTR\n", __LINE__); 855 printk("cyc: %d: dropping DTR\n", __LINE__);
852 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 856 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
857 base_addr[CyMSVR2]);
853#endif 858#endif
854 } 859 }
855 write_cy_cmd(base_addr,CyDIS_RCVR); 860 write_cy_cmd(base_addr, CyDIS_RCVR);
856 /* it may be appropriate to clear _XMIT at 861 /* it may be appropriate to clear _XMIT at
857 some later date (after testing)!!! */ 862 some later date (after testing)!!! */
858 863
859 if (info->tty){ 864 if (info->tty) {
860 set_bit(TTY_IO_ERROR, &info->tty->flags); 865 set_bit(TTY_IO_ERROR, &info->tty->flags);
861 } 866 }
862 info->flags &= ~ASYNC_INITIALIZED; 867 info->flags &= ~ASYNC_INITIALIZED;
863 local_irq_restore(flags); 868 local_irq_restore(flags);
864 869
865#ifdef SERIAL_DEBUG_OPEN 870#ifdef SERIAL_DEBUG_OPEN
866 printk(" done\n"); 871 printk(" done\n");
867#endif 872#endif
868 return; 873} /* shutdown */
869} /* shutdown */
870 874
871/* 875/*
872 * This routine finds or computes the various line characteristics. 876 * This routine finds or computes the various line characteristics.
873 */ 877 */
874static void 878static void config_setup(struct cyclades_port *info)
875config_setup(struct cyclades_port * info)
876{ 879{
877 unsigned long flags; 880 unsigned long flags;
878 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 881 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
879 int channel; 882 int channel;
880 unsigned cflag; 883 unsigned cflag;
881 int i; 884 int i;
882 unsigned char ti, need_init_chan = 0; 885 unsigned char ti, need_init_chan = 0;
883 886
884 if (!info->tty || !info->tty->termios){ 887 if (!info->tty || !info->tty->termios) {
885 return; 888 return;
886 } 889 }
887 if (info->line == -1){ 890 if (info->line == -1) {
888 return; 891 return;
889 } 892 }
890 cflag = info->tty->termios->c_cflag; 893 cflag = info->tty->termios->c_cflag;
891 894
892 /* baud rate */ 895 /* baud rate */
893 i = cflag & CBAUD; 896 i = cflag & CBAUD;
894#ifdef CBAUDEX 897#ifdef CBAUDEX
895/* Starting with kernel 1.1.65, there is direct support for 898/* Starting with kernel 1.1.65, there is direct support for
896 higher baud rates. The following code supports those 899 higher baud rates. The following code supports those
@@ -900,120 +903,123 @@ config_setup(struct cyclades_port * info)
900 is still the possibility of supporting 75 kbit/sec with 903 is still the possibility of supporting 75 kbit/sec with
901 the Cyclades board.) 904 the Cyclades board.)
902 */ 905 */
903 if (i & CBAUDEX) { 906 if (i & CBAUDEX) {
904 if (i == B57600) 907 if (i == B57600)
905 i = 16; 908 i = 16;
906 else if(i == B115200) 909 else if (i == B115200)
907 i = 18; 910 i = 18;
908#ifdef B78600 911#ifdef B78600
909 else if(i == B78600) 912 else if (i == B78600)
910 i = 17; 913 i = 17;
911#endif 914#endif
912 else 915 else
913 info->tty->termios->c_cflag &= ~CBAUDEX; 916 info->tty->termios->c_cflag &= ~CBAUDEX;
914 } 917 }
915#endif 918#endif
916 if (i == 15) { 919 if (i == 15) {
917 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 920 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
918 i += 1; 921 i += 1;
919 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI) 922 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
920 i += 3; 923 i += 3;
921 } 924 }
922 /* Don't ever change the speed of the console port. It will 925 /* Don't ever change the speed of the console port. It will
923 * run at the speed specified in bootinfo, or at 19.2K */ 926 * run at the speed specified in bootinfo, or at 19.2K */
924 /* Actually, it should run at whatever speed 166Bug was using */ 927 /* Actually, it should run at whatever speed 166Bug was using */
925 /* Note info->timeout isn't used at present */ 928 /* Note info->timeout isn't used at present */
926 if (info != serial_console_info) { 929 if (info != serial_console_info) {
927 info->tbpr = baud_bpr[i]; /* Tx BPR */ 930 info->tbpr = baud_bpr[i]; /* Tx BPR */
928 info->tco = baud_co[i]; /* Tx CO */ 931 info->tco = baud_co[i]; /* Tx CO */
929 info->rbpr = baud_bpr[i]; /* Rx BPR */ 932 info->rbpr = baud_bpr[i]; /* Rx BPR */
930 info->rco = baud_co[i] >> 5; /* Rx CO */ 933 info->rco = baud_co[i] >> 5; /* Rx CO */
931 if (baud_table[i] == 134) { 934 if (baud_table[i] == 134) {
932 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2; 935 info->timeout =
933 /* get it right for 134.5 baud */ 936 (info->xmit_fifo_size * HZ * 30 / 269) + 2;
934 } else if (baud_table[i]) { 937 /* get it right for 134.5 baud */
935 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2; 938 } else if (baud_table[i]) {
936 /* this needs to be propagated into the card info */ 939 info->timeout =
940 (info->xmit_fifo_size * HZ * 15 / baud_table[i]) +
941 2;
942 /* this needs to be propagated into the card info */
943 } else {
944 info->timeout = 0;
945 }
946 }
947 /* By tradition (is it a standard?) a baud rate of zero
948 implies the line should be/has been closed. A bit
949 later in this routine such a test is performed. */
950
951 /* byte size and parity */
952 info->cor7 = 0;
953 info->cor6 = 0;
954 info->cor5 = 0;
955 info->cor4 = (info->default_threshold ? info->default_threshold : baud_cor4[i]); /* receive threshold */
956 /* Following two lines added 101295, RGH. */
957 /* It is obviously wrong to access CyCORx, and not info->corx here,
958 * try and remember to fix it later! */
959 channel = info->line;
960 base_addr[CyCAR] = (u_char) channel;
961 if (C_CLOCAL(info->tty)) {
962 if (base_addr[CyIER] & CyMdmCh)
963 base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */
964 /* ignore 1->0 modem transitions */
965 if (base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD))
966 base_addr[CyCOR4] &= ~(CyDSR | CyCTS | CyDCD);
967 /* ignore 0->1 modem transitions */
968 if (base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD))
969 base_addr[CyCOR5] &= ~(CyDSR | CyCTS | CyDCD);
937 } else { 970 } else {
938 info->timeout = 0; 971 if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh)
939 } 972 base_addr[CyIER] |= CyMdmCh; /* with modem intr */
940 } 973 /* act on 1->0 modem transitions */
941 /* By tradition (is it a standard?) a baud rate of zero 974 if ((base_addr[CyCOR4] & (CyDSR | CyCTS | CyDCD)) !=
942 implies the line should be/has been closed. A bit 975 (CyDSR | CyCTS | CyDCD))
943 later in this routine such a test is performed. */ 976 base_addr[CyCOR4] |= CyDSR | CyCTS | CyDCD;
944 977 /* act on 0->1 modem transitions */
945 /* byte size and parity */ 978 if ((base_addr[CyCOR5] & (CyDSR | CyCTS | CyDCD)) !=
946 info->cor7 = 0; 979 (CyDSR | CyCTS | CyDCD))
947 info->cor6 = 0; 980 base_addr[CyCOR5] |= CyDSR | CyCTS | CyDCD;
948 info->cor5 = 0; 981 }
949 info->cor4 = (info->default_threshold 982 info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
950 ? info->default_threshold 983 info->cor2 = CyETC;
951 : baud_cor4[i]); /* receive threshold */ 984 switch (cflag & CSIZE) {
952 /* Following two lines added 101295, RGH. */ 985 case CS5:
953 /* It is obviously wrong to access CyCORx, and not info->corx here, 986 info->cor1 = Cy_5_BITS;
954 * try and remember to fix it later! */ 987 break;
955 channel = info->line; 988 case CS6:
956 base_addr[CyCAR] = (u_char)channel; 989 info->cor1 = Cy_6_BITS;
957 if (C_CLOCAL(info->tty)) { 990 break;
958 if (base_addr[CyIER] & CyMdmCh) 991 case CS7:
959 base_addr[CyIER] &= ~CyMdmCh; /* without modem intr */ 992 info->cor1 = Cy_7_BITS;
960 /* ignore 1->0 modem transitions */ 993 break;
961 if (base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) 994 case CS8:
962 base_addr[CyCOR4] &= ~(CyDSR|CyCTS|CyDCD); 995 info->cor1 = Cy_8_BITS;
963 /* ignore 0->1 modem transitions */ 996 break;
964 if (base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) 997 }
965 base_addr[CyCOR5] &= ~(CyDSR|CyCTS|CyDCD); 998 if (cflag & PARENB) {
966 } else { 999 if (cflag & PARODD) {
967 if ((base_addr[CyIER] & CyMdmCh) != CyMdmCh) 1000 info->cor1 |= CyPARITY_O;
968 base_addr[CyIER] |= CyMdmCh; /* with modem intr */ 1001 } else {
969 /* act on 1->0 modem transitions */ 1002 info->cor1 |= CyPARITY_E;
970 if ((base_addr[CyCOR4] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD)) 1003 }
971 base_addr[CyCOR4] |= CyDSR|CyCTS|CyDCD; 1004 } else {
972 /* act on 0->1 modem transitions */ 1005 info->cor1 |= CyPARITY_NONE;
973 if ((base_addr[CyCOR5] & (CyDSR|CyCTS|CyDCD)) != (CyDSR|CyCTS|CyDCD)) 1006 }
974 base_addr[CyCOR5] |= CyDSR|CyCTS|CyDCD; 1007
975 } 1008 /* CTS flow control flag */
976 info->cor3 = (cflag & CSTOPB) ? Cy_2_STOP : Cy_1_STOP;
977 info->cor2 = CyETC;
978 switch(cflag & CSIZE){
979 case CS5:
980 info->cor1 = Cy_5_BITS;
981 break;
982 case CS6:
983 info->cor1 = Cy_6_BITS;
984 break;
985 case CS7:
986 info->cor1 = Cy_7_BITS;
987 break;
988 case CS8:
989 info->cor1 = Cy_8_BITS;
990 break;
991 }
992 if (cflag & PARENB){
993 if (cflag & PARODD){
994 info->cor1 |= CyPARITY_O;
995 }else{
996 info->cor1 |= CyPARITY_E;
997 }
998 }else{
999 info->cor1 |= CyPARITY_NONE;
1000 }
1001
1002 /* CTS flow control flag */
1003#if 0 1009#if 0
1004 /* Don't complcate matters for now! RGH 141095 */ 1010 /* Don't complcate matters for now! RGH 141095 */
1005 if (cflag & CRTSCTS){ 1011 if (cflag & CRTSCTS) {
1006 info->flags |= ASYNC_CTS_FLOW; 1012 info->flags |= ASYNC_CTS_FLOW;
1007 info->cor2 |= CyCtsAE; 1013 info->cor2 |= CyCtsAE;
1008 }else{ 1014 } else {
1009 info->flags &= ~ASYNC_CTS_FLOW; 1015 info->flags &= ~ASYNC_CTS_FLOW;
1010 info->cor2 &= ~CyCtsAE; 1016 info->cor2 &= ~CyCtsAE;
1011 } 1017 }
1012#endif 1018#endif
1013 if (cflag & CLOCAL) 1019 if (cflag & CLOCAL)
1014 info->flags &= ~ASYNC_CHECK_CD; 1020 info->flags &= ~ASYNC_CHECK_CD;
1015 else 1021 else
1016 info->flags |= ASYNC_CHECK_CD; 1022 info->flags |= ASYNC_CHECK_CD;
1017 1023
1018 /*********************************************** 1024 /***********************************************
1019 The hardware option, CyRtsAO, presents RTS when 1025 The hardware option, CyRtsAO, presents RTS when
@@ -1025,149 +1031,146 @@ config_setup(struct cyclades_port * info)
1025 cable. Contact Marcio Saito for details. 1031 cable. Contact Marcio Saito for details.
1026 ***********************************************/ 1032 ***********************************************/
1027 1033
1028 channel = info->line; 1034 channel = info->line;
1029 1035
1030 local_irq_save(flags); 1036 local_irq_save(flags);
1031 base_addr[CyCAR] = (u_char)channel; 1037 base_addr[CyCAR] = (u_char) channel;
1032 1038
1033 /* CyCMR set once only in mvme167_init_serial() */ 1039 /* CyCMR set once only in mvme167_init_serial() */
1034 if (base_addr[CyLICR] != channel << 2) 1040 if (base_addr[CyLICR] != channel << 2)
1035 base_addr[CyLICR] = channel << 2; 1041 base_addr[CyLICR] = channel << 2;
1036 if (base_addr[CyLIVR] != 0x5c) 1042 if (base_addr[CyLIVR] != 0x5c)
1037 base_addr[CyLIVR] = 0x5c; 1043 base_addr[CyLIVR] = 0x5c;
1038 1044
1039 /* tx and rx baud rate */ 1045 /* tx and rx baud rate */
1040 1046
1041 if (base_addr[CyCOR1] != info->cor1) 1047 if (base_addr[CyCOR1] != info->cor1)
1042 need_init_chan = 1; 1048 need_init_chan = 1;
1043 if (base_addr[CyTCOR] != info->tco) 1049 if (base_addr[CyTCOR] != info->tco)
1044 base_addr[CyTCOR] = info->tco; 1050 base_addr[CyTCOR] = info->tco;
1045 if (base_addr[CyTBPR] != info->tbpr) 1051 if (base_addr[CyTBPR] != info->tbpr)
1046 base_addr[CyTBPR] = info->tbpr; 1052 base_addr[CyTBPR] = info->tbpr;
1047 if (base_addr[CyRCOR] != info->rco) 1053 if (base_addr[CyRCOR] != info->rco)
1048 base_addr[CyRCOR] = info->rco; 1054 base_addr[CyRCOR] = info->rco;
1049 if (base_addr[CyRBPR] != info->rbpr) 1055 if (base_addr[CyRBPR] != info->rbpr)
1050 base_addr[CyRBPR] = info->rbpr; 1056 base_addr[CyRBPR] = info->rbpr;
1051 1057
1052 /* set line characteristics according configuration */ 1058 /* set line characteristics according configuration */
1053 1059
1054 if (base_addr[CySCHR1] != START_CHAR(info->tty)) 1060 if (base_addr[CySCHR1] != START_CHAR(info->tty))
1055 base_addr[CySCHR1] = START_CHAR(info->tty); 1061 base_addr[CySCHR1] = START_CHAR(info->tty);
1056 if (base_addr[CySCHR2] != STOP_CHAR(info->tty)) 1062 if (base_addr[CySCHR2] != STOP_CHAR(info->tty))
1057 base_addr[CySCHR2] = STOP_CHAR(info->tty); 1063 base_addr[CySCHR2] = STOP_CHAR(info->tty);
1058 if (base_addr[CySCRL] != START_CHAR(info->tty)) 1064 if (base_addr[CySCRL] != START_CHAR(info->tty))
1059 base_addr[CySCRL] = START_CHAR(info->tty); 1065 base_addr[CySCRL] = START_CHAR(info->tty);
1060 if (base_addr[CySCRH] != START_CHAR(info->tty)) 1066 if (base_addr[CySCRH] != START_CHAR(info->tty))
1061 base_addr[CySCRH] = START_CHAR(info->tty); 1067 base_addr[CySCRH] = START_CHAR(info->tty);
1062 if (base_addr[CyCOR1] != info->cor1) 1068 if (base_addr[CyCOR1] != info->cor1)
1063 base_addr[CyCOR1] = info->cor1; 1069 base_addr[CyCOR1] = info->cor1;
1064 if (base_addr[CyCOR2] != info->cor2) 1070 if (base_addr[CyCOR2] != info->cor2)
1065 base_addr[CyCOR2] = info->cor2; 1071 base_addr[CyCOR2] = info->cor2;
1066 if (base_addr[CyCOR3] != info->cor3) 1072 if (base_addr[CyCOR3] != info->cor3)
1067 base_addr[CyCOR3] = info->cor3; 1073 base_addr[CyCOR3] = info->cor3;
1068 if (base_addr[CyCOR4] != info->cor4) 1074 if (base_addr[CyCOR4] != info->cor4)
1069 base_addr[CyCOR4] = info->cor4; 1075 base_addr[CyCOR4] = info->cor4;
1070 if (base_addr[CyCOR5] != info->cor5) 1076 if (base_addr[CyCOR5] != info->cor5)
1071 base_addr[CyCOR5] = info->cor5; 1077 base_addr[CyCOR5] = info->cor5;
1072 if (base_addr[CyCOR6] != info->cor6) 1078 if (base_addr[CyCOR6] != info->cor6)
1073 base_addr[CyCOR6] = info->cor6; 1079 base_addr[CyCOR6] = info->cor6;
1074 if (base_addr[CyCOR7] != info->cor7) 1080 if (base_addr[CyCOR7] != info->cor7)
1075 base_addr[CyCOR7] = info->cor7; 1081 base_addr[CyCOR7] = info->cor7;
1076 1082
1077 if (need_init_chan) 1083 if (need_init_chan)
1078 write_cy_cmd(base_addr,CyINIT_CHAN); 1084 write_cy_cmd(base_addr, CyINIT_CHAN);
1079 1085
1080 base_addr[CyCAR] = (u_char)channel; /* !!! Is this needed? */ 1086 base_addr[CyCAR] = (u_char) channel; /* !!! Is this needed? */
1081 1087
1082 /* 2ms default rx timeout */ 1088 /* 2ms default rx timeout */
1083 ti = info->default_timeout ? info->default_timeout : 0x02; 1089 ti = info->default_timeout ? info->default_timeout : 0x02;
1084 if (base_addr[CyRTPRL] != ti) 1090 if (base_addr[CyRTPRL] != ti)
1085 base_addr[CyRTPRL] = ti; 1091 base_addr[CyRTPRL] = ti;
1086 if (base_addr[CyRTPRH] != 0) 1092 if (base_addr[CyRTPRH] != 0)
1087 base_addr[CyRTPRH] = 0; 1093 base_addr[CyRTPRH] = 0;
1088 1094
1089 /* Set up RTS here also ????? RGH 141095 */ 1095 /* Set up RTS here also ????? RGH 141095 */
1090 if(i == 0){ /* baud rate is zero, turn off line */ 1096 if (i == 0) { /* baud rate is zero, turn off line */
1091 if ((base_addr[CyMSVR2] & CyDTR) == CyDTR) 1097 if ((base_addr[CyMSVR2] & CyDTR) == CyDTR)
1092 base_addr[CyMSVR2] = 0; 1098 base_addr[CyMSVR2] = 0;
1093#ifdef SERIAL_DEBUG_DTR 1099#ifdef SERIAL_DEBUG_DTR
1094 printk("cyc: %d: dropping DTR\n", __LINE__); 1100 printk("cyc: %d: dropping DTR\n", __LINE__);
1095 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1101 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1102 base_addr[CyMSVR2]);
1096#endif 1103#endif
1097 }else{ 1104 } else {
1098 if ((base_addr[CyMSVR2] & CyDTR) != CyDTR) 1105 if ((base_addr[CyMSVR2] & CyDTR) != CyDTR)
1099 base_addr[CyMSVR2] = CyDTR; 1106 base_addr[CyMSVR2] = CyDTR;
1100#ifdef SERIAL_DEBUG_DTR 1107#ifdef SERIAL_DEBUG_DTR
1101 printk("cyc: %d: raising DTR\n", __LINE__); 1108 printk("cyc: %d: raising DTR\n", __LINE__);
1102 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1109 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1110 base_addr[CyMSVR2]);
1103#endif 1111#endif
1104 } 1112 }
1105 1113
1106 if (info->tty){ 1114 if (info->tty) {
1107 clear_bit(TTY_IO_ERROR, &info->tty->flags); 1115 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1108 } 1116 }
1109 1117
1110 local_irq_restore(flags); 1118 local_irq_restore(flags);
1111
1112} /* config_setup */
1113 1119
1120} /* config_setup */
1114 1121
1115static void 1122static void cy_put_char(struct tty_struct *tty, unsigned char ch)
1116cy_put_char(struct tty_struct *tty, unsigned char ch)
1117{ 1123{
1118 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1124 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1119 unsigned long flags; 1125 unsigned long flags;
1120 1126
1121#ifdef SERIAL_DEBUG_IO 1127#ifdef SERIAL_DEBUG_IO
1122 printk("cy_put_char %s(0x%02x)\n", tty->name, ch); 1128 printk("cy_put_char %s(0x%02x)\n", tty->name, ch);
1123#endif 1129#endif
1124 1130
1125 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 1131 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
1126 return; 1132 return;
1127 1133
1128 if (!info->xmit_buf) 1134 if (!info->xmit_buf)
1129 return; 1135 return;
1130 1136
1131 local_irq_save(flags); 1137 local_irq_save(flags);
1132 if (info->xmit_cnt >= PAGE_SIZE - 1) { 1138 if (info->xmit_cnt >= PAGE_SIZE - 1) {
1133 local_irq_restore(flags); 1139 local_irq_restore(flags);
1134 return; 1140 return;
1135 } 1141 }
1136 1142
1137 info->xmit_buf[info->xmit_head++] = ch; 1143 info->xmit_buf[info->xmit_head++] = ch;
1138 info->xmit_head &= PAGE_SIZE - 1; 1144 info->xmit_head &= PAGE_SIZE - 1;
1139 info->xmit_cnt++; 1145 info->xmit_cnt++;
1140 local_irq_restore(flags); 1146 local_irq_restore(flags);
1141} /* cy_put_char */ 1147} /* cy_put_char */
1142
1143 1148
1144static void 1149static void cy_flush_chars(struct tty_struct *tty)
1145cy_flush_chars(struct tty_struct *tty)
1146{ 1150{
1147 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1151 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1148 unsigned long flags; 1152 unsigned long flags;
1149 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1153 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1150 int channel; 1154 int channel;
1151 1155
1152#ifdef SERIAL_DEBUG_IO 1156#ifdef SERIAL_DEBUG_IO
1153 printk("cy_flush_chars %s\n", tty->name); /* */ 1157 printk("cy_flush_chars %s\n", tty->name); /* */
1154#endif 1158#endif
1155 1159
1156 if (serial_paranoia_check(info, tty->name, "cy_flush_chars")) 1160 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
1157 return; 1161 return;
1158 1162
1159 if (info->xmit_cnt <= 0 || tty->stopped 1163 if (info->xmit_cnt <= 0 || tty->stopped
1160 || tty->hw_stopped || !info->xmit_buf) 1164 || tty->hw_stopped || !info->xmit_buf)
1161 return; 1165 return;
1162 1166
1163 channel = info->line; 1167 channel = info->line;
1164 1168
1165 local_irq_save(flags); 1169 local_irq_save(flags);
1166 base_addr[CyCAR] = channel; 1170 base_addr[CyCAR] = channel;
1167 base_addr[CyIER] |= CyTxMpty; 1171 base_addr[CyIER] |= CyTxMpty;
1168 local_irq_restore(flags); 1172 local_irq_restore(flags);
1169} /* cy_flush_chars */ 1173} /* cy_flush_chars */
1170
1171 1174
1172/* This routine gets called when tty_write has put something into 1175/* This routine gets called when tty_write has put something into
1173 the write_queue. If the port is not already transmitting stuff, 1176 the write_queue. If the port is not already transmitting stuff,
@@ -1175,650 +1178,616 @@ cy_flush_chars(struct tty_struct *tty)
1175 routine will then ensure that the characters are sent. If the 1178 routine will then ensure that the characters are sent. If the
1176 port is already active, there is no need to kick it. 1179 port is already active, there is no need to kick it.
1177 */ 1180 */
1178static int 1181static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
1179cy_write(struct tty_struct * tty,
1180 const unsigned char *buf, int count)
1181{ 1182{
1182 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1183 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1183 unsigned long flags; 1184 unsigned long flags;
1184 int c, total = 0; 1185 int c, total = 0;
1185 1186
1186#ifdef SERIAL_DEBUG_IO 1187#ifdef SERIAL_DEBUG_IO
1187 printk("cy_write %s\n", tty->name); /* */ 1188 printk("cy_write %s\n", tty->name); /* */
1188#endif 1189#endif
1189 1190
1190 if (serial_paranoia_check(info, tty->name, "cy_write")){ 1191 if (serial_paranoia_check(info, tty->name, "cy_write")) {
1191 return 0; 1192 return 0;
1192 } 1193 }
1193
1194 if (!info->xmit_buf){
1195 return 0;
1196 }
1197
1198 while (1) {
1199 local_irq_save(flags);
1200 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1201 SERIAL_XMIT_SIZE - info->xmit_head));
1202 if (c <= 0) {
1203 local_irq_restore(flags);
1204 break;
1205 }
1206
1207 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1208 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1209 info->xmit_cnt += c;
1210 local_irq_restore(flags);
1211
1212 buf += c;
1213 count -= c;
1214 total += c;
1215 }
1216
1217 if (info->xmit_cnt
1218 && !tty->stopped
1219 && !tty->hw_stopped ) {
1220 start_xmit(info);
1221 }
1222 return total;
1223} /* cy_write */
1224 1194
1195 if (!info->xmit_buf) {
1196 return 0;
1197 }
1225 1198
1226static int 1199 while (1) {
1227cy_write_room(struct tty_struct *tty) 1200 local_irq_save(flags);
1201 c = min_t(int, count, min(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1202 SERIAL_XMIT_SIZE - info->xmit_head));
1203 if (c <= 0) {
1204 local_irq_restore(flags);
1205 break;
1206 }
1207
1208 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1209 info->xmit_head =
1210 (info->xmit_head + c) & (SERIAL_XMIT_SIZE - 1);
1211 info->xmit_cnt += c;
1212 local_irq_restore(flags);
1213
1214 buf += c;
1215 count -= c;
1216 total += c;
1217 }
1218
1219 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
1220 start_xmit(info);
1221 }
1222 return total;
1223} /* cy_write */
1224
1225static int cy_write_room(struct tty_struct *tty)
1228{ 1226{
1229 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1227 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1230 int ret; 1228 int ret;
1231 1229
1232#ifdef SERIAL_DEBUG_IO 1230#ifdef SERIAL_DEBUG_IO
1233 printk("cy_write_room %s\n", tty->name); /* */ 1231 printk("cy_write_room %s\n", tty->name); /* */
1234#endif 1232#endif
1235 1233
1236 if (serial_paranoia_check(info, tty->name, "cy_write_room")) 1234 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
1237 return 0; 1235 return 0;
1238 ret = PAGE_SIZE - info->xmit_cnt - 1; 1236 ret = PAGE_SIZE - info->xmit_cnt - 1;
1239 if (ret < 0) 1237 if (ret < 0)
1240 ret = 0; 1238 ret = 0;
1241 return ret; 1239 return ret;
1242} /* cy_write_room */ 1240} /* cy_write_room */
1243
1244 1241
1245static int 1242static int cy_chars_in_buffer(struct tty_struct *tty)
1246cy_chars_in_buffer(struct tty_struct *tty)
1247{ 1243{
1248 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1244 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1249 1245
1250#ifdef SERIAL_DEBUG_IO 1246#ifdef SERIAL_DEBUG_IO
1251 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */ 1247 printk("cy_chars_in_buffer %s %d\n", tty->name, info->xmit_cnt); /* */
1252#endif 1248#endif
1253 1249
1254 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer")) 1250 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
1255 return 0; 1251 return 0;
1256
1257 return info->xmit_cnt;
1258} /* cy_chars_in_buffer */
1259 1252
1253 return info->xmit_cnt;
1254} /* cy_chars_in_buffer */
1260 1255
1261static void 1256static void cy_flush_buffer(struct tty_struct *tty)
1262cy_flush_buffer(struct tty_struct *tty)
1263{ 1257{
1264 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1258 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1265 unsigned long flags; 1259 unsigned long flags;
1266 1260
1267#ifdef SERIAL_DEBUG_IO 1261#ifdef SERIAL_DEBUG_IO
1268 printk("cy_flush_buffer %s\n", tty->name); /* */ 1262 printk("cy_flush_buffer %s\n", tty->name); /* */
1269#endif 1263#endif
1270 1264
1271 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer")) 1265 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
1272 return; 1266 return;
1273 local_irq_save(flags); 1267 local_irq_save(flags);
1274 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 1268 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1275 local_irq_restore(flags); 1269 local_irq_restore(flags);
1276 tty_wakeup(tty); 1270 tty_wakeup(tty);
1277} /* cy_flush_buffer */ 1271} /* cy_flush_buffer */
1278
1279 1272
1280/* This routine is called by the upper-layer tty layer to signal 1273/* This routine is called by the upper-layer tty layer to signal
1281 that incoming characters should be throttled or that the 1274 that incoming characters should be throttled or that the
1282 throttle should be released. 1275 throttle should be released.
1283 */ 1276 */
1284static void 1277static void cy_throttle(struct tty_struct *tty)
1285cy_throttle(struct tty_struct * tty)
1286{ 1278{
1287 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1279 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1288 unsigned long flags; 1280 unsigned long flags;
1289 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1281 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1290 int channel; 1282 int channel;
1291 1283
1292#ifdef SERIAL_DEBUG_THROTTLE 1284#ifdef SERIAL_DEBUG_THROTTLE
1293 char buf[64]; 1285 char buf[64];
1294 1286
1295 printk("throttle %s: %d....\n", tty_name(tty, buf), 1287 printk("throttle %s: %d....\n", tty_name(tty, buf),
1296 tty->ldisc.chars_in_buffer(tty)); 1288 tty->ldisc.chars_in_buffer(tty));
1297 printk("cy_throttle %s\n", tty->name); 1289 printk("cy_throttle %s\n", tty->name);
1298#endif 1290#endif
1299 1291
1300 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){ 1292 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
1301 return; 1293 return;
1302 } 1294 }
1303 1295
1304 if (I_IXOFF(tty)) { 1296 if (I_IXOFF(tty)) {
1305 info->x_char = STOP_CHAR(tty); 1297 info->x_char = STOP_CHAR(tty);
1306 /* Should use the "Send Special Character" feature!!! */ 1298 /* Should use the "Send Special Character" feature!!! */
1307 } 1299 }
1308 1300
1309 channel = info->line; 1301 channel = info->line;
1310 1302
1311 local_irq_save(flags); 1303 local_irq_save(flags);
1312 base_addr[CyCAR] = (u_char)channel; 1304 base_addr[CyCAR] = (u_char) channel;
1313 base_addr[CyMSVR1] = 0; 1305 base_addr[CyMSVR1] = 0;
1314 local_irq_restore(flags); 1306 local_irq_restore(flags);
1315 1307} /* cy_throttle */
1316 return;
1317} /* cy_throttle */
1318
1319 1308
1320static void 1309static void cy_unthrottle(struct tty_struct *tty)
1321cy_unthrottle(struct tty_struct * tty)
1322{ 1310{
1323 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1311 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1324 unsigned long flags; 1312 unsigned long flags;
1325 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1313 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1326 int channel; 1314 int channel;
1327 1315
1328#ifdef SERIAL_DEBUG_THROTTLE 1316#ifdef SERIAL_DEBUG_THROTTLE
1329 char buf[64]; 1317 char buf[64];
1330 1318
1331 printk("throttle %s: %d....\n", tty_name(tty, buf), 1319 printk("throttle %s: %d....\n", tty_name(tty, buf),
1332 tty->ldisc.chars_in_buffer(tty)); 1320 tty->ldisc.chars_in_buffer(tty));
1333 printk("cy_unthrottle %s\n", tty->name); 1321 printk("cy_unthrottle %s\n", tty->name);
1334#endif 1322#endif
1335 1323
1336 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")){ 1324 if (serial_paranoia_check(info, tty->name, "cy_nthrottle")) {
1337 return; 1325 return;
1338 } 1326 }
1339 1327
1340 if (I_IXOFF(tty)) { 1328 if (I_IXOFF(tty)) {
1341 info->x_char = START_CHAR(tty); 1329 info->x_char = START_CHAR(tty);
1342 /* Should use the "Send Special Character" feature!!! */ 1330 /* Should use the "Send Special Character" feature!!! */
1343 } 1331 }
1344 1332
1345 channel = info->line; 1333 channel = info->line;
1346 1334
1347 local_irq_save(flags); 1335 local_irq_save(flags);
1348 base_addr[CyCAR] = (u_char)channel; 1336 base_addr[CyCAR] = (u_char) channel;
1349 base_addr[CyMSVR1] = CyRTS; 1337 base_addr[CyMSVR1] = CyRTS;
1350 local_irq_restore(flags); 1338 local_irq_restore(flags);
1351 1339} /* cy_unthrottle */
1352 return;
1353} /* cy_unthrottle */
1354 1340
1355static int 1341static int
1356get_serial_info(struct cyclades_port * info, 1342get_serial_info(struct cyclades_port *info,
1357 struct serial_struct __user * retinfo) 1343 struct serial_struct __user * retinfo)
1358{ 1344{
1359 struct serial_struct tmp; 1345 struct serial_struct tmp;
1360 1346
1361/* CP('g'); */ 1347/* CP('g'); */
1362 if (!retinfo) 1348 if (!retinfo)
1363 return -EFAULT; 1349 return -EFAULT;
1364 memset(&tmp, 0, sizeof(tmp)); 1350 memset(&tmp, 0, sizeof(tmp));
1365 tmp.type = info->type; 1351 tmp.type = info->type;
1366 tmp.line = info->line; 1352 tmp.line = info->line;
1367 tmp.port = info->line; 1353 tmp.port = info->line;
1368 tmp.irq = 0; 1354 tmp.irq = 0;
1369 tmp.flags = info->flags; 1355 tmp.flags = info->flags;
1370 tmp.baud_base = 0; /*!!!*/ 1356 tmp.baud_base = 0; /*!!! */
1371 tmp.close_delay = info->close_delay; 1357 tmp.close_delay = info->close_delay;
1372 tmp.custom_divisor = 0; /*!!!*/ 1358 tmp.custom_divisor = 0; /*!!! */
1373 tmp.hub6 = 0; /*!!!*/ 1359 tmp.hub6 = 0; /*!!! */
1374 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0; 1360 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
1375} /* get_serial_info */ 1361} /* get_serial_info */
1376 1362
1377static int 1363static int
1378set_serial_info(struct cyclades_port * info, 1364set_serial_info(struct cyclades_port *info,
1379 struct serial_struct __user * new_info) 1365 struct serial_struct __user * new_info)
1380{ 1366{
1381 struct serial_struct new_serial; 1367 struct serial_struct new_serial;
1382 struct cyclades_port old_info; 1368 struct cyclades_port old_info;
1383 1369
1384/* CP('s'); */ 1370/* CP('s'); */
1385 if (!new_info) 1371 if (!new_info)
1386 return -EFAULT; 1372 return -EFAULT;
1387 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 1373 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
1388 return -EFAULT; 1374 return -EFAULT;
1389 old_info = *info; 1375 old_info = *info;
1376
1377 if (!capable(CAP_SYS_ADMIN)) {
1378 if ((new_serial.close_delay != info->close_delay) ||
1379 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
1380 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
1381 return -EPERM;
1382 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1383 (new_serial.flags & ASYNC_USR_MASK));
1384 goto check_and_exit;
1385 }
1390 1386
1391 if (!capable(CAP_SYS_ADMIN)) { 1387 /*
1392 if ((new_serial.close_delay != info->close_delay) || 1388 * OK, past this point, all the error checking has been done.
1393 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) != 1389 * At this point, we start making changes.....
1394 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))) 1390 */
1395 return -EPERM;
1396 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1397 (new_serial.flags & ASYNC_USR_MASK));
1398 goto check_and_exit;
1399 }
1400 1391
1392 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1393 (new_serial.flags & ASYNC_FLAGS));
1394 info->close_delay = new_serial.close_delay;
1401 1395
1402 /* 1396check_and_exit:
1403 * OK, past this point, all the error checking has been done. 1397 if (info->flags & ASYNC_INITIALIZED) {
1404 * At this point, we start making changes..... 1398 config_setup(info);
1405 */ 1399 return 0;
1400 }
1401 return startup(info);
1402} /* set_serial_info */
1406 1403
1407 info->flags = ((info->flags & ~ASYNC_FLAGS) | 1404static int cy_tiocmget(struct tty_struct *tty, struct file *file)
1408 (new_serial.flags & ASYNC_FLAGS)); 1405{
1409 info->close_delay = new_serial.close_delay; 1406 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1407 int channel;
1408 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1409 unsigned long flags;
1410 unsigned char status;
1410 1411
1412 channel = info->line;
1411 1413
1412check_and_exit: 1414 local_irq_save(flags);
1413 if (info->flags & ASYNC_INITIALIZED){ 1415 base_addr[CyCAR] = (u_char) channel;
1414 config_setup(info); 1416 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1415 return 0; 1417 local_irq_restore(flags);
1416 }else{
1417 return startup(info);
1418 }
1419} /* set_serial_info */
1420 1418
1421static int 1419 return ((status & CyRTS) ? TIOCM_RTS : 0)
1422cy_tiocmget(struct tty_struct *tty, struct file *file) 1420 | ((status & CyDTR) ? TIOCM_DTR : 0)
1423{ 1421 | ((status & CyDCD) ? TIOCM_CAR : 0)
1424 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1422 | ((status & CyDSR) ? TIOCM_DSR : 0)
1425 int channel; 1423 | ((status & CyCTS) ? TIOCM_CTS : 0);
1426 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1424} /* cy_tiocmget */
1427 unsigned long flags;
1428 unsigned char status;
1429
1430 channel = info->line;
1431
1432 local_irq_save(flags);
1433 base_addr[CyCAR] = (u_char)channel;
1434 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1435 local_irq_restore(flags);
1436
1437 return ((status & CyRTS) ? TIOCM_RTS : 0)
1438 | ((status & CyDTR) ? TIOCM_DTR : 0)
1439 | ((status & CyDCD) ? TIOCM_CAR : 0)
1440 | ((status & CyDSR) ? TIOCM_DSR : 0)
1441 | ((status & CyCTS) ? TIOCM_CTS : 0);
1442} /* cy_tiocmget */
1443 1425
1444static int 1426static int
1445cy_tiocmset(struct tty_struct *tty, struct file *file, 1427cy_tiocmset(struct tty_struct *tty, struct file *file,
1446 unsigned int set, unsigned int clear) 1428 unsigned int set, unsigned int clear)
1447{ 1429{
1448 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1430 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1449 int channel; 1431 int channel;
1450 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1432 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1451 unsigned long flags; 1433 unsigned long flags;
1452 1434
1453 channel = info->line; 1435 channel = info->line;
1454 1436
1455 if (set & TIOCM_RTS){ 1437 if (set & TIOCM_RTS) {
1456 local_irq_save(flags); 1438 local_irq_save(flags);
1457 base_addr[CyCAR] = (u_char)channel; 1439 base_addr[CyCAR] = (u_char) channel;
1458 base_addr[CyMSVR1] = CyRTS; 1440 base_addr[CyMSVR1] = CyRTS;
1459 local_irq_restore(flags); 1441 local_irq_restore(flags);
1460 } 1442 }
1461 if (set & TIOCM_DTR){ 1443 if (set & TIOCM_DTR) {
1462 local_irq_save(flags); 1444 local_irq_save(flags);
1463 base_addr[CyCAR] = (u_char)channel; 1445 base_addr[CyCAR] = (u_char) channel;
1464/* CP('S');CP('2'); */ 1446/* CP('S');CP('2'); */
1465 base_addr[CyMSVR2] = CyDTR; 1447 base_addr[CyMSVR2] = CyDTR;
1466#ifdef SERIAL_DEBUG_DTR 1448#ifdef SERIAL_DEBUG_DTR
1467 printk("cyc: %d: raising DTR\n", __LINE__); 1449 printk("cyc: %d: raising DTR\n", __LINE__);
1468 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1450 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1451 base_addr[CyMSVR2]);
1469#endif 1452#endif
1470 local_irq_restore(flags); 1453 local_irq_restore(flags);
1471 } 1454 }
1472 1455
1473 if (clear & TIOCM_RTS){ 1456 if (clear & TIOCM_RTS) {
1474 local_irq_save(flags); 1457 local_irq_save(flags);
1475 base_addr[CyCAR] = (u_char)channel; 1458 base_addr[CyCAR] = (u_char) channel;
1476 base_addr[CyMSVR1] = 0; 1459 base_addr[CyMSVR1] = 0;
1477 local_irq_restore(flags); 1460 local_irq_restore(flags);
1478 } 1461 }
1479 if (clear & TIOCM_DTR){ 1462 if (clear & TIOCM_DTR) {
1480 local_irq_save(flags); 1463 local_irq_save(flags);
1481 base_addr[CyCAR] = (u_char)channel; 1464 base_addr[CyCAR] = (u_char) channel;
1482/* CP('C');CP('2'); */ 1465/* CP('C');CP('2'); */
1483 base_addr[CyMSVR2] = 0; 1466 base_addr[CyMSVR2] = 0;
1484#ifdef SERIAL_DEBUG_DTR 1467#ifdef SERIAL_DEBUG_DTR
1485 printk("cyc: %d: dropping DTR\n", __LINE__); 1468 printk("cyc: %d: dropping DTR\n", __LINE__);
1486 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1469 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1470 base_addr[CyMSVR2]);
1487#endif 1471#endif
1488 local_irq_restore(flags); 1472 local_irq_restore(flags);
1489 } 1473 }
1490 1474
1491 return 0; 1475 return 0;
1492} /* set_modem_info */ 1476} /* set_modem_info */
1493 1477
1494static void 1478static void send_break(struct cyclades_port *info, int duration)
1495send_break( struct cyclades_port * info, int duration) 1479{ /* Let the transmit ISR take care of this (since it
1496{ /* Let the transmit ISR take care of this (since it 1480 requires stuffing characters into the output stream).
1497 requires stuffing characters into the output stream). 1481 */
1498 */ 1482 info->x_break = duration;
1499 info->x_break = duration; 1483 if (!info->xmit_cnt) {
1500 if (!info->xmit_cnt ) { 1484 start_xmit(info);
1501 start_xmit(info); 1485 }
1502 } 1486} /* send_break */
1503} /* send_break */
1504 1487
1505static int 1488static int
1506get_mon_info(struct cyclades_port * info, struct cyclades_monitor __user * mon) 1489get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
1507{ 1490{
1508 1491
1509 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor))) 1492 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
1510 return -EFAULT; 1493 return -EFAULT;
1511 info->mon.int_count = 0; 1494 info->mon.int_count = 0;
1512 info->mon.char_count = 0; 1495 info->mon.char_count = 0;
1513 info->mon.char_max = 0; 1496 info->mon.char_max = 0;
1514 info->mon.char_last = 0; 1497 info->mon.char_last = 0;
1515 return 0; 1498 return 0;
1516} 1499}
1517 1500
1518static int 1501static int set_threshold(struct cyclades_port *info, unsigned long __user * arg)
1519set_threshold(struct cyclades_port * info, unsigned long __user *arg)
1520{ 1502{
1521 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1503 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1522 unsigned long value; 1504 unsigned long value;
1523 int channel; 1505 int channel;
1524 1506
1525 if (get_user(value, arg)) 1507 if (get_user(value, arg))
1526 return -EFAULT; 1508 return -EFAULT;
1527 1509
1528 channel = info->line; 1510 channel = info->line;
1529 info->cor4 &= ~CyREC_FIFO; 1511 info->cor4 &= ~CyREC_FIFO;
1530 info->cor4 |= value & CyREC_FIFO; 1512 info->cor4 |= value & CyREC_FIFO;
1531 base_addr[CyCOR4] = info->cor4; 1513 base_addr[CyCOR4] = info->cor4;
1532 return 0; 1514 return 0;
1533} 1515}
1534 1516
1535static int 1517static int
1536get_threshold(struct cyclades_port * info, unsigned long __user *value) 1518get_threshold(struct cyclades_port *info, unsigned long __user * value)
1537{ 1519{
1538 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1520 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1539 int channel; 1521 int channel;
1540 unsigned long tmp; 1522 unsigned long tmp;
1541 1523
1542 channel = info->line; 1524 channel = info->line;
1543 1525
1544 tmp = base_addr[CyCOR4] & CyREC_FIFO; 1526 tmp = base_addr[CyCOR4] & CyREC_FIFO;
1545 return put_user(tmp,value); 1527 return put_user(tmp, value);
1546} 1528}
1547 1529
1548static int 1530static int
1549set_default_threshold(struct cyclades_port * info, unsigned long __user *arg) 1531set_default_threshold(struct cyclades_port *info, unsigned long __user * arg)
1550{ 1532{
1551 unsigned long value; 1533 unsigned long value;
1552 1534
1553 if (get_user(value, arg)) 1535 if (get_user(value, arg))
1554 return -EFAULT; 1536 return -EFAULT;
1555 1537
1556 info->default_threshold = value & 0x0f; 1538 info->default_threshold = value & 0x0f;
1557 return 0; 1539 return 0;
1558} 1540}
1559 1541
1560static int 1542static int
1561get_default_threshold(struct cyclades_port * info, unsigned long __user *value) 1543get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
1562{ 1544{
1563 return put_user(info->default_threshold,value); 1545 return put_user(info->default_threshold, value);
1564} 1546}
1565 1547
1566static int 1548static int set_timeout(struct cyclades_port *info, unsigned long __user * arg)
1567set_timeout(struct cyclades_port * info, unsigned long __user *arg)
1568{ 1549{
1569 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1550 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1570 int channel; 1551 int channel;
1571 unsigned long value; 1552 unsigned long value;
1572 1553
1573 if (get_user(value, arg)) 1554 if (get_user(value, arg))
1574 return -EFAULT; 1555 return -EFAULT;
1575 1556
1576 channel = info->line; 1557 channel = info->line;
1577 1558
1578 base_addr[CyRTPRL] = value & 0xff; 1559 base_addr[CyRTPRL] = value & 0xff;
1579 base_addr[CyRTPRH] = (value >> 8) & 0xff; 1560 base_addr[CyRTPRH] = (value >> 8) & 0xff;
1580 return 0; 1561 return 0;
1581} 1562}
1582 1563
1583static int 1564static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
1584get_timeout(struct cyclades_port * info, unsigned long __user *value)
1585{ 1565{
1586 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 1566 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
1587 int channel; 1567 int channel;
1588 unsigned long tmp; 1568 unsigned long tmp;
1589 1569
1590 channel = info->line; 1570 channel = info->line;
1591 1571
1592 tmp = base_addr[CyRTPRL]; 1572 tmp = base_addr[CyRTPRL];
1593 return put_user(tmp,value); 1573 return put_user(tmp, value);
1594} 1574}
1595 1575
1596static int 1576static int set_default_timeout(struct cyclades_port *info, unsigned long value)
1597set_default_timeout(struct cyclades_port * info, unsigned long value)
1598{ 1577{
1599 info->default_timeout = value & 0xff; 1578 info->default_timeout = value & 0xff;
1600 return 0; 1579 return 0;
1601} 1580}
1602 1581
1603static int 1582static int
1604get_default_timeout(struct cyclades_port * info, unsigned long __user *value) 1583get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
1605{ 1584{
1606 return put_user(info->default_timeout,value); 1585 return put_user(info->default_timeout, value);
1607} 1586}
1608 1587
1609static int 1588static int
1610cy_ioctl(struct tty_struct *tty, struct file * file, 1589cy_ioctl(struct tty_struct *tty, struct file *file,
1611 unsigned int cmd, unsigned long arg) 1590 unsigned int cmd, unsigned long arg)
1612{ 1591{
1613 unsigned long val; 1592 unsigned long val;
1614 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1593 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1615 int ret_val = 0; 1594 int ret_val = 0;
1616 void __user *argp = (void __user *)arg; 1595 void __user *argp = (void __user *)arg;
1617 1596
1618#ifdef SERIAL_DEBUG_OTHER 1597#ifdef SERIAL_DEBUG_OTHER
1619 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */ 1598 printk("cy_ioctl %s, cmd = %x arg = %lx\n", tty->name, cmd, arg); /* */
1620#endif 1599#endif
1621 1600
1622 switch (cmd) { 1601 switch (cmd) {
1623 case CYGETMON: 1602 case CYGETMON:
1624 ret_val = get_mon_info(info, argp); 1603 ret_val = get_mon_info(info, argp);
1625 break; 1604 break;
1626 case CYGETTHRESH: 1605 case CYGETTHRESH:
1627 ret_val = get_threshold(info, argp); 1606 ret_val = get_threshold(info, argp);
1628 break; 1607 break;
1629 case CYSETTHRESH: 1608 case CYSETTHRESH:
1630 ret_val = set_threshold(info, argp); 1609 ret_val = set_threshold(info, argp);
1631 break; 1610 break;
1632 case CYGETDEFTHRESH: 1611 case CYGETDEFTHRESH:
1633 ret_val = get_default_threshold(info, argp); 1612 ret_val = get_default_threshold(info, argp);
1634 break; 1613 break;
1635 case CYSETDEFTHRESH: 1614 case CYSETDEFTHRESH:
1636 ret_val = set_default_threshold(info, argp); 1615 ret_val = set_default_threshold(info, argp);
1637 break; 1616 break;
1638 case CYGETTIMEOUT: 1617 case CYGETTIMEOUT:
1639 ret_val = get_timeout(info, argp); 1618 ret_val = get_timeout(info, argp);
1640 break; 1619 break;
1641 case CYSETTIMEOUT: 1620 case CYSETTIMEOUT:
1642 ret_val = set_timeout(info, argp); 1621 ret_val = set_timeout(info, argp);
1643 break; 1622 break;
1644 case CYGETDEFTIMEOUT: 1623 case CYGETDEFTIMEOUT:
1645 ret_val = get_default_timeout(info, argp); 1624 ret_val = get_default_timeout(info, argp);
1646 break; 1625 break;
1647 case CYSETDEFTIMEOUT: 1626 case CYSETDEFTIMEOUT:
1648 ret_val = set_default_timeout(info, (unsigned long)arg); 1627 ret_val = set_default_timeout(info, (unsigned long)arg);
1649 break; 1628 break;
1650 case TCSBRK: /* SVID version: non-zero arg --> no break */ 1629 case TCSBRK: /* SVID version: non-zero arg --> no break */
1651 ret_val = tty_check_change(tty); 1630 ret_val = tty_check_change(tty);
1652 if (ret_val) 1631 if (ret_val)
1653 break; 1632 break;
1654 tty_wait_until_sent(tty,0); 1633 tty_wait_until_sent(tty, 0);
1655 if (!arg) 1634 if (!arg)
1656 send_break(info, HZ/4); /* 1/4 second */ 1635 send_break(info, HZ / 4); /* 1/4 second */
1657 break; 1636 break;
1658 case TCSBRKP: /* support for POSIX tcsendbreak() */ 1637 case TCSBRKP: /* support for POSIX tcsendbreak() */
1659 ret_val = tty_check_change(tty); 1638 ret_val = tty_check_change(tty);
1660 if (ret_val) 1639 if (ret_val)
1640 break;
1641 tty_wait_until_sent(tty, 0);
1642 send_break(info, arg ? arg * (HZ / 10) : HZ / 4);
1661 break; 1643 break;
1662 tty_wait_until_sent(tty,0);
1663 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1664 break;
1665 1644
1666/* The following commands are incompletely implemented!!! */ 1645/* The following commands are incompletely implemented!!! */
1667 case TIOCGSOFTCAR: 1646 case TIOCGSOFTCAR:
1668 ret_val = put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *) argp); 1647 ret_val =
1669 break; 1648 put_user(C_CLOCAL(tty) ? 1 : 0,
1670 case TIOCSSOFTCAR: 1649 (unsigned long __user *)argp);
1671 ret_val = get_user(val, (unsigned long __user *) argp); 1650 break;
1672 if (ret_val) 1651 case TIOCSSOFTCAR:
1673 break; 1652 ret_val = get_user(val, (unsigned long __user *)argp);
1674 tty->termios->c_cflag = 1653 if (ret_val)
1675 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0)); 1654 break;
1676 break; 1655 tty->termios->c_cflag =
1677 case TIOCGSERIAL: 1656 ((tty->termios->c_cflag & ~CLOCAL) | (val ? CLOCAL : 0));
1678 ret_val = get_serial_info(info, argp); 1657 break;
1679 break; 1658 case TIOCGSERIAL:
1680 case TIOCSSERIAL: 1659 ret_val = get_serial_info(info, argp);
1681 ret_val = set_serial_info(info, argp); 1660 break;
1682 break; 1661 case TIOCSSERIAL:
1683 default: 1662 ret_val = set_serial_info(info, argp);
1684 ret_val = -ENOIOCTLCMD; 1663 break;
1685 } 1664 default:
1665 ret_val = -ENOIOCTLCMD;
1666 }
1686 1667
1687#ifdef SERIAL_DEBUG_OTHER 1668#ifdef SERIAL_DEBUG_OTHER
1688 printk("cy_ioctl done\n"); 1669 printk("cy_ioctl done\n");
1689#endif 1670#endif
1690 1671
1691 return ret_val; 1672 return ret_val;
1692} /* cy_ioctl */ 1673} /* cy_ioctl */
1693
1694 1674
1695 1675static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1696
1697static void
1698cy_set_termios(struct tty_struct *tty, struct ktermios * old_termios)
1699{ 1676{
1700 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 1677 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1701 1678
1702#ifdef SERIAL_DEBUG_OTHER 1679#ifdef SERIAL_DEBUG_OTHER
1703 printk("cy_set_termios %s\n", tty->name); 1680 printk("cy_set_termios %s\n", tty->name);
1704#endif 1681#endif
1705 1682
1706 if (tty->termios->c_cflag == old_termios->c_cflag) 1683 if (tty->termios->c_cflag == old_termios->c_cflag)
1707 return; 1684 return;
1708 config_setup(info); 1685 config_setup(info);
1709 1686
1710 if ((old_termios->c_cflag & CRTSCTS) && 1687 if ((old_termios->c_cflag & CRTSCTS) &&
1711 !(tty->termios->c_cflag & CRTSCTS)) { 1688 !(tty->termios->c_cflag & CRTSCTS)) {
1712 tty->stopped = 0; 1689 tty->stopped = 0;
1713 cy_start(tty); 1690 cy_start(tty);
1714 } 1691 }
1715#ifdef tytso_patch_94Nov25_1726 1692#ifdef tytso_patch_94Nov25_1726
1716 if (!(old_termios->c_cflag & CLOCAL) && 1693 if (!(old_termios->c_cflag & CLOCAL) &&
1717 (tty->termios->c_cflag & CLOCAL)) 1694 (tty->termios->c_cflag & CLOCAL))
1718 wake_up_interruptible(&info->open_wait); 1695 wake_up_interruptible(&info->open_wait);
1719#endif 1696#endif
1697} /* cy_set_termios */
1720 1698
1721 return; 1699static void cy_close(struct tty_struct *tty, struct file *filp)
1722} /* cy_set_termios */
1723
1724
1725static void
1726cy_close(struct tty_struct * tty, struct file * filp)
1727{ 1700{
1728 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1701 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1729 1702
1730/* CP('C'); */ 1703/* CP('C'); */
1731#ifdef SERIAL_DEBUG_OTHER 1704#ifdef SERIAL_DEBUG_OTHER
1732 printk("cy_close %s\n", tty->name); 1705 printk("cy_close %s\n", tty->name);
1733#endif 1706#endif
1734 1707
1735 if (!info 1708 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
1736 || serial_paranoia_check(info, tty->name, "cy_close")){ 1709 return;
1737 return; 1710 }
1738 }
1739#ifdef SERIAL_DEBUG_OPEN 1711#ifdef SERIAL_DEBUG_OPEN
1740 printk("cy_close %s, count = %d\n", tty->name, info->count); 1712 printk("cy_close %s, count = %d\n", tty->name, info->count);
1741#endif 1713#endif
1742 1714
1743 if ((tty->count == 1) && (info->count != 1)) { 1715 if ((tty->count == 1) && (info->count != 1)) {
1744 /* 1716 /*
1745 * Uh, oh. tty->count is 1, which means that the tty 1717 * Uh, oh. tty->count is 1, which means that the tty
1746 * structure will be freed. Info->count should always 1718 * structure will be freed. Info->count should always
1747 * be one in these conditions. If it's greater than 1719 * be one in these conditions. If it's greater than
1748 * one, we've got real problems, since it means the 1720 * one, we've got real problems, since it means the
1749 * serial port won't be shutdown. 1721 * serial port won't be shutdown.
1750 */ 1722 */
1751 printk("cy_close: bad serial port count; tty->count is 1, " 1723 printk("cy_close: bad serial port count; tty->count is 1, "
1752 "info->count is %d\n", info->count); 1724 "info->count is %d\n", info->count);
1753 info->count = 1; 1725 info->count = 1;
1754 } 1726 }
1755#ifdef SERIAL_DEBUG_COUNT 1727#ifdef SERIAL_DEBUG_COUNT
1756 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count - 1); 1728 printk("cyc: %d: decrementing count to %d\n", __LINE__,
1729 info->count - 1);
1757#endif 1730#endif
1758 if (--info->count < 0) { 1731 if (--info->count < 0) {
1759 printk("cy_close: bad serial port count for ttys%d: %d\n", 1732 printk("cy_close: bad serial port count for ttys%d: %d\n",
1760 info->line, info->count); 1733 info->line, info->count);
1761#ifdef SERIAL_DEBUG_COUNT 1734#ifdef SERIAL_DEBUG_COUNT
1762 printk("cyc: %d: setting count to 0\n", __LINE__); 1735 printk("cyc: %d: setting count to 0\n", __LINE__);
1763#endif 1736#endif
1764 info->count = 0; 1737 info->count = 0;
1765 }
1766 if (info->count)
1767 return;
1768 info->flags |= ASYNC_CLOSING;
1769 if (info->flags & ASYNC_INITIALIZED)
1770 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1771 shutdown(info);
1772 if (tty->driver->flush_buffer)
1773 tty->driver->flush_buffer(tty);
1774 tty_ldisc_flush(tty);
1775 info->event = 0;
1776 info->tty = NULL;
1777 if (info->blocked_open) {
1778 if (info->close_delay) {
1779 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1780 } 1738 }
1781 wake_up_interruptible(&info->open_wait); 1739 if (info->count)
1782 } 1740 return;
1783 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1741 info->flags |= ASYNC_CLOSING;
1784 wake_up_interruptible(&info->close_wait); 1742 if (info->flags & ASYNC_INITIALIZED)
1743 tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
1744 shutdown(info);
1745 if (tty->driver->flush_buffer)
1746 tty->driver->flush_buffer(tty);
1747 tty_ldisc_flush(tty);
1748 info->event = 0;
1749 info->tty = NULL;
1750 if (info->blocked_open) {
1751 if (info->close_delay) {
1752 msleep_interruptible(jiffies_to_msecs
1753 (info->close_delay));
1754 }
1755 wake_up_interruptible(&info->open_wait);
1756 }
1757 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
1758 wake_up_interruptible(&info->close_wait);
1785 1759
1786#ifdef SERIAL_DEBUG_OTHER 1760#ifdef SERIAL_DEBUG_OTHER
1787 printk("cy_close done\n"); 1761 printk("cy_close done\n");
1788#endif 1762#endif
1789 1763} /* cy_close */
1790 return;
1791} /* cy_close */
1792 1764
1793/* 1765/*
1794 * cy_hangup() --- called by tty_hangup() when a hangup is signaled. 1766 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
1795 */ 1767 */
1796void 1768void cy_hangup(struct tty_struct *tty)
1797cy_hangup(struct tty_struct *tty)
1798{ 1769{
1799 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 1770 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1800 1771
1801#ifdef SERIAL_DEBUG_OTHER 1772#ifdef SERIAL_DEBUG_OTHER
1802 printk("cy_hangup %s\n", tty->name); /* */ 1773 printk("cy_hangup %s\n", tty->name); /* */
1803#endif 1774#endif
1804 1775
1805 if (serial_paranoia_check(info, tty->name, "cy_hangup")) 1776 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
1806 return; 1777 return;
1807 1778
1808 shutdown(info); 1779 shutdown(info);
1809#if 0 1780#if 0
1810 info->event = 0; 1781 info->event = 0;
1811 info->count = 0; 1782 info->count = 0;
1812#ifdef SERIAL_DEBUG_COUNT 1783#ifdef SERIAL_DEBUG_COUNT
1813 printk("cyc: %d: setting count to 0\n", __LINE__); 1784 printk("cyc: %d: setting count to 0\n", __LINE__);
1814#endif 1785#endif
1815 info->tty = 0; 1786 info->tty = 0;
1816#endif 1787#endif
1817 info->flags &= ~ASYNC_NORMAL_ACTIVE; 1788 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1818 wake_up_interruptible(&info->open_wait); 1789 wake_up_interruptible(&info->open_wait);
1819} /* cy_hangup */ 1790} /* cy_hangup */
1820
1821
1822 1791
1823/* 1792/*
1824 * ------------------------------------------------------------ 1793 * ------------------------------------------------------------
@@ -1827,177 +1796,180 @@ cy_hangup(struct tty_struct *tty)
1827 */ 1796 */
1828 1797
1829static int 1798static int
1830block_til_ready(struct tty_struct *tty, struct file * filp, 1799block_til_ready(struct tty_struct *tty, struct file *filp,
1831 struct cyclades_port *info) 1800 struct cyclades_port *info)
1832{ 1801{
1833 DECLARE_WAITQUEUE(wait, current); 1802 DECLARE_WAITQUEUE(wait, current);
1834 unsigned long flags; 1803 unsigned long flags;
1835 int channel; 1804 int channel;
1836 int retval; 1805 int retval;
1837 volatile u_char *base_addr = (u_char *)BASE_ADDR; 1806 volatile u_char *base_addr = (u_char *) BASE_ADDR;
1838 1807
1839 /* 1808 /*
1840 * If the device is in the middle of being closed, then block 1809 * If the device is in the middle of being closed, then block
1841 * until it's done, and then try again. 1810 * until it's done, and then try again.
1842 */ 1811 */
1843 if (info->flags & ASYNC_CLOSING) { 1812 if (info->flags & ASYNC_CLOSING) {
1844 interruptible_sleep_on(&info->close_wait); 1813 interruptible_sleep_on(&info->close_wait);
1845 if (info->flags & ASYNC_HUP_NOTIFY){ 1814 if (info->flags & ASYNC_HUP_NOTIFY) {
1846 return -EAGAIN; 1815 return -EAGAIN;
1847 }else{ 1816 } else {
1848 return -ERESTARTSYS; 1817 return -ERESTARTSYS;
1849 } 1818 }
1850 } 1819 }
1851 1820
1852 /* 1821 /*
1853 * If non-blocking mode is set, then make the check up front 1822 * If non-blocking mode is set, then make the check up front
1854 * and then exit. 1823 * and then exit.
1855 */ 1824 */
1856 if (filp->f_flags & O_NONBLOCK) { 1825 if (filp->f_flags & O_NONBLOCK) {
1857 info->flags |= ASYNC_NORMAL_ACTIVE; 1826 info->flags |= ASYNC_NORMAL_ACTIVE;
1858 return 0; 1827 return 0;
1859 } 1828 }
1860 1829
1861 /* 1830 /*
1862 * Block waiting for the carrier detect and the line to become 1831 * Block waiting for the carrier detect and the line to become
1863 * free (i.e., not in use by the callout). While we are in 1832 * free (i.e., not in use by the callout). While we are in
1864 * this loop, info->count is dropped by one, so that 1833 * this loop, info->count is dropped by one, so that
1865 * cy_close() knows when to free things. We restore it upon 1834 * cy_close() knows when to free things. We restore it upon
1866 * exit, either normal or abnormal. 1835 * exit, either normal or abnormal.
1867 */ 1836 */
1868 retval = 0; 1837 retval = 0;
1869 add_wait_queue(&info->open_wait, &wait); 1838 add_wait_queue(&info->open_wait, &wait);
1870#ifdef SERIAL_DEBUG_OPEN 1839#ifdef SERIAL_DEBUG_OPEN
1871 printk("block_til_ready before block: %s, count = %d\n", 1840 printk("block_til_ready before block: %s, count = %d\n",
1872 tty->name, info->count);/**/ 1841 tty->name, info->count);
1842 /**/
1873#endif 1843#endif
1874 info->count--; 1844 info->count--;
1875#ifdef SERIAL_DEBUG_COUNT 1845#ifdef SERIAL_DEBUG_COUNT
1876 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count); 1846 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
1877#endif 1847#endif
1878 info->blocked_open++; 1848 info->blocked_open++;
1879 1849
1880 channel = info->line; 1850 channel = info->line;
1881 1851
1882 while (1) { 1852 while (1) {
1883 local_irq_save(flags); 1853 local_irq_save(flags);
1884 base_addr[CyCAR] = (u_char)channel; 1854 base_addr[CyCAR] = (u_char) channel;
1885 base_addr[CyMSVR1] = CyRTS; 1855 base_addr[CyMSVR1] = CyRTS;
1886/* CP('S');CP('4'); */ 1856/* CP('S');CP('4'); */
1887 base_addr[CyMSVR2] = CyDTR; 1857 base_addr[CyMSVR2] = CyDTR;
1888#ifdef SERIAL_DEBUG_DTR 1858#ifdef SERIAL_DEBUG_DTR
1889 printk("cyc: %d: raising DTR\n", __LINE__); 1859 printk("cyc: %d: raising DTR\n", __LINE__);
1890 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]); 1860 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1],
1891#endif 1861 base_addr[CyMSVR2]);
1892 local_irq_restore(flags); 1862#endif
1893 set_current_state(TASK_INTERRUPTIBLE); 1863 local_irq_restore(flags);
1894 if (tty_hung_up_p(filp) 1864 set_current_state(TASK_INTERRUPTIBLE);
1895 || !(info->flags & ASYNC_INITIALIZED) ){ 1865 if (tty_hung_up_p(filp)
1896 if (info->flags & ASYNC_HUP_NOTIFY) { 1866 || !(info->flags & ASYNC_INITIALIZED)) {
1897 retval = -EAGAIN; 1867 if (info->flags & ASYNC_HUP_NOTIFY) {
1898 }else{ 1868 retval = -EAGAIN;
1899 retval = -ERESTARTSYS; 1869 } else {
1900 } 1870 retval = -ERESTARTSYS;
1901 break; 1871 }
1902 } 1872 break;
1903 local_irq_save(flags); 1873 }
1904 base_addr[CyCAR] = (u_char)channel; 1874 local_irq_save(flags);
1875 base_addr[CyCAR] = (u_char) channel;
1905/* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */ 1876/* CP('L');CP1(1 && C_CLOCAL(tty)); CP1(1 && (base_addr[CyMSVR1] & CyDCD) ); */
1906 if (!(info->flags & ASYNC_CLOSING) 1877 if (!(info->flags & ASYNC_CLOSING)
1907 && (C_CLOCAL(tty) 1878 && (C_CLOCAL(tty)
1908 || (base_addr[CyMSVR1] & CyDCD))) { 1879 || (base_addr[CyMSVR1] & CyDCD))) {
1909 local_irq_restore(flags); 1880 local_irq_restore(flags);
1910 break; 1881 break;
1911 } 1882 }
1912 local_irq_restore(flags); 1883 local_irq_restore(flags);
1913 if (signal_pending(current)) { 1884 if (signal_pending(current)) {
1914 retval = -ERESTARTSYS; 1885 retval = -ERESTARTSYS;
1915 break; 1886 break;
1916 } 1887 }
1917#ifdef SERIAL_DEBUG_OPEN 1888#ifdef SERIAL_DEBUG_OPEN
1918 printk("block_til_ready blocking: %s, count = %d\n", 1889 printk("block_til_ready blocking: %s, count = %d\n",
1919 tty->name, info->count);/**/ 1890 tty->name, info->count);
1920#endif 1891 /**/
1921 schedule(); 1892#endif
1922 } 1893 schedule();
1923 current->state = TASK_RUNNING; 1894 }
1924 remove_wait_queue(&info->open_wait, &wait); 1895 current->state = TASK_RUNNING;
1925 if (!tty_hung_up_p(filp)){ 1896 remove_wait_queue(&info->open_wait, &wait);
1926 info->count++; 1897 if (!tty_hung_up_p(filp)) {
1898 info->count++;
1927#ifdef SERIAL_DEBUG_COUNT 1899#ifdef SERIAL_DEBUG_COUNT
1928 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count); 1900 printk("cyc: %d: incrementing count to %d\n", __LINE__,
1901 info->count);
1929#endif 1902#endif
1930 } 1903 }
1931 info->blocked_open--; 1904 info->blocked_open--;
1932#ifdef SERIAL_DEBUG_OPEN 1905#ifdef SERIAL_DEBUG_OPEN
1933 printk("block_til_ready after blocking: %s, count = %d\n", 1906 printk("block_til_ready after blocking: %s, count = %d\n",
1934 tty->name, info->count);/**/ 1907 tty->name, info->count);
1908 /**/
1935#endif 1909#endif
1936 if (retval) 1910 if (retval)
1937 return retval; 1911 return retval;
1938 info->flags |= ASYNC_NORMAL_ACTIVE; 1912 info->flags |= ASYNC_NORMAL_ACTIVE;
1939 return 0; 1913 return 0;
1940} /* block_til_ready */ 1914} /* block_til_ready */
1941 1915
1942/* 1916/*
1943 * This routine is called whenever a serial port is opened. It 1917 * This routine is called whenever a serial port is opened. It
1944 * performs the serial-specific initialization for the tty structure. 1918 * performs the serial-specific initialization for the tty structure.
1945 */ 1919 */
1946int 1920int cy_open(struct tty_struct *tty, struct file *filp)
1947cy_open(struct tty_struct *tty, struct file * filp)
1948{ 1921{
1949 struct cyclades_port *info; 1922 struct cyclades_port *info;
1950 int retval, line; 1923 int retval, line;
1951 1924
1952/* CP('O'); */ 1925/* CP('O'); */
1953 line = tty->index; 1926 line = tty->index;
1954 if ((line < 0) || (NR_PORTS <= line)){ 1927 if ((line < 0) || (NR_PORTS <= line)) {
1955 return -ENODEV; 1928 return -ENODEV;
1956 } 1929 }
1957 info = &cy_port[line]; 1930 info = &cy_port[line];
1958 if (info->line < 0){ 1931 if (info->line < 0) {
1959 return -ENODEV; 1932 return -ENODEV;
1960 } 1933 }
1961#ifdef SERIAL_DEBUG_OTHER 1934#ifdef SERIAL_DEBUG_OTHER
1962 printk("cy_open %s\n", tty->name); /* */ 1935 printk("cy_open %s\n", tty->name); /* */
1963#endif 1936#endif
1964 if (serial_paranoia_check(info, tty->name, "cy_open")){ 1937 if (serial_paranoia_check(info, tty->name, "cy_open")) {
1965 return -ENODEV; 1938 return -ENODEV;
1966 } 1939 }
1967#ifdef SERIAL_DEBUG_OPEN 1940#ifdef SERIAL_DEBUG_OPEN
1968 printk("cy_open %s, count = %d\n", tty->name, info->count);/**/ 1941 printk("cy_open %s, count = %d\n", tty->name, info->count);
1942 /**/
1969#endif 1943#endif
1970 info->count++; 1944 info->count++;
1971#ifdef SERIAL_DEBUG_COUNT 1945#ifdef SERIAL_DEBUG_COUNT
1972 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count); 1946 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
1973#endif 1947#endif
1974 tty->driver_data = info; 1948 tty->driver_data = info;
1975 info->tty = tty; 1949 info->tty = tty;
1976 1950
1977 /* 1951 /*
1978 * Start up serial port 1952 * Start up serial port
1979 */ 1953 */
1980 retval = startup(info); 1954 retval = startup(info);
1981 if (retval){ 1955 if (retval) {
1982 return retval; 1956 return retval;
1983 } 1957 }
1984 1958
1985 retval = block_til_ready(tty, filp, info); 1959 retval = block_til_ready(tty, filp, info);
1986 if (retval) { 1960 if (retval) {
1987#ifdef SERIAL_DEBUG_OPEN 1961#ifdef SERIAL_DEBUG_OPEN
1988 printk("cy_open returning after block_til_ready with %d\n", 1962 printk("cy_open returning after block_til_ready with %d\n",
1989 retval); 1963 retval);
1990#endif 1964#endif
1991 return retval; 1965 return retval;
1992 } 1966 }
1993
1994#ifdef SERIAL_DEBUG_OPEN 1967#ifdef SERIAL_DEBUG_OPEN
1995 printk("cy_open done\n");/**/ 1968 printk("cy_open done\n");
1969 /**/
1996#endif 1970#endif
1997 return 0; 1971 return 0;
1998} /* cy_open */ 1972} /* cy_open */
1999
2000
2001 1973
2002/* 1974/*
2003 * --------------------------------------------------------------------- 1975 * ---------------------------------------------------------------------
@@ -2012,11 +1984,10 @@ cy_open(struct tty_struct *tty, struct file * filp)
2012 * number, and identifies which options were configured into this 1984 * number, and identifies which options were configured into this
2013 * driver. 1985 * driver.
2014 */ 1986 */
2015static void 1987static void show_version(void)
2016show_version(void)
2017{ 1988{
2018 printk("MVME166/167 cd2401 driver\n"); 1989 printk("MVME166/167 cd2401 driver\n");
2019} /* show_version */ 1990} /* show_version */
2020 1991
2021/* initialize chips on card -- return number of valid 1992/* initialize chips on card -- return number of valid
2022 chips (which is number of ports/4) */ 1993 chips (which is number of ports/4) */
@@ -2030,10 +2001,9 @@ show_version(void)
2030 * ... I wonder what I should do if this fails ... 2001 * ... I wonder what I should do if this fails ...
2031 */ 2002 */
2032 2003
2033void 2004void mvme167_serial_console_setup(int cflag)
2034mvme167_serial_console_setup(int cflag)
2035{ 2005{
2036 volatile unsigned char* base_addr = (u_char *)BASE_ADDR; 2006 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2037 int ch; 2007 int ch;
2038 u_char spd; 2008 u_char spd;
2039 u_char rcor, rbpr, badspeed = 0; 2009 u_char rcor, rbpr, badspeed = 0;
@@ -2062,21 +2032,21 @@ mvme167_serial_console_setup(int cflag)
2062 2032
2063 /* OK, we have chosen a speed, now reset and reinitialise */ 2033 /* OK, we have chosen a speed, now reset and reinitialise */
2064 2034
2065 my_udelay(20000L); /* Allow time for any active o/p to complete */ 2035 my_udelay(20000L); /* Allow time for any active o/p to complete */
2066 if(base_addr[CyCCR] != 0x00){ 2036 if (base_addr[CyCCR] != 0x00) {
2067 local_irq_restore(flags); 2037 local_irq_restore(flags);
2068 /* printk(" chip is never idle (CCR != 0)\n"); */ 2038 /* printk(" chip is never idle (CCR != 0)\n"); */
2069 return; 2039 return;
2070 } 2040 }
2071 2041
2072 base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */ 2042 base_addr[CyCCR] = CyCHIP_RESET; /* Reset the chip */
2073 my_udelay(1000L); 2043 my_udelay(1000L);
2074 2044
2075 if(base_addr[CyGFRCR] == 0x00){ 2045 if (base_addr[CyGFRCR] == 0x00) {
2076 local_irq_restore(flags); 2046 local_irq_restore(flags);
2077 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */ 2047 /* printk(" chip is not responding (GFRCR stayed 0)\n"); */
2078 return; 2048 return;
2079 } 2049 }
2080 2050
2081 /* 2051 /*
2082 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms 2052 * System clock is 20Mhz, divided by 2048, so divide by 10 for a 1.0ms
@@ -2085,9 +2055,9 @@ mvme167_serial_console_setup(int cflag)
2085 2055
2086 base_addr[CyTPR] = 10; 2056 base_addr[CyTPR] = 10;
2087 2057
2088 base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */ 2058 base_addr[CyPILR1] = 0x01; /* Interrupt level for modem change */
2089 base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */ 2059 base_addr[CyPILR2] = 0x02; /* Interrupt level for tx ints */
2090 base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */ 2060 base_addr[CyPILR3] = 0x03; /* Interrupt level for rx ints */
2091 2061
2092 /* 2062 /*
2093 * Attempt to set up all channels to something reasonable, and 2063 * Attempt to set up all channels to something reasonable, and
@@ -2095,11 +2065,11 @@ mvme167_serial_console_setup(int cflag)
2095 * the ammount of fiddling we have to do in normal running. 2065 * the ammount of fiddling we have to do in normal running.
2096 */ 2066 */
2097 2067
2098 for (ch = 3; ch >= 0 ; ch--) { 2068 for (ch = 3; ch >= 0; ch--) {
2099 base_addr[CyCAR] = (u_char)ch; 2069 base_addr[CyCAR] = (u_char) ch;
2100 base_addr[CyIER] = 0; 2070 base_addr[CyIER] = 0;
2101 base_addr[CyCMR] = CyASYNC; 2071 base_addr[CyCMR] = CyASYNC;
2102 base_addr[CyLICR] = (u_char)ch << 2; 2072 base_addr[CyLICR] = (u_char) ch << 2;
2103 base_addr[CyLIVR] = 0x5c; 2073 base_addr[CyLIVR] = 0x5c;
2104 base_addr[CyTCOR] = baud_co[spd]; 2074 base_addr[CyTCOR] = baud_co[spd];
2105 base_addr[CyTBPR] = baud_bpr[spd]; 2075 base_addr[CyTBPR] = baud_bpr[spd];
@@ -2118,29 +2088,30 @@ mvme167_serial_console_setup(int cflag)
2118 base_addr[CyCOR7] = 0; 2088 base_addr[CyCOR7] = 0;
2119 base_addr[CyRTPRL] = 2; 2089 base_addr[CyRTPRL] = 2;
2120 base_addr[CyRTPRH] = 0; 2090 base_addr[CyRTPRH] = 0;
2121 base_addr[CyMSVR1] = 0; 2091 base_addr[CyMSVR1] = 0;
2122 base_addr[CyMSVR2] = 0; 2092 base_addr[CyMSVR2] = 0;
2123 write_cy_cmd(base_addr,CyINIT_CHAN|CyDIS_RCVR|CyDIS_XMTR); 2093 write_cy_cmd(base_addr, CyINIT_CHAN | CyDIS_RCVR | CyDIS_XMTR);
2124 } 2094 }
2125 2095
2126 /* 2096 /*
2127 * Now do specials for channel zero.... 2097 * Now do specials for channel zero....
2128 */ 2098 */
2129 2099
2130 base_addr[CyMSVR1] = CyRTS; 2100 base_addr[CyMSVR1] = CyRTS;
2131 base_addr[CyMSVR2] = CyDTR; 2101 base_addr[CyMSVR2] = CyDTR;
2132 base_addr[CyIER] = CyRxData; 2102 base_addr[CyIER] = CyRxData;
2133 write_cy_cmd(base_addr,CyENB_RCVR|CyENB_XMTR); 2103 write_cy_cmd(base_addr, CyENB_RCVR | CyENB_XMTR);
2134 2104
2135 local_irq_restore(flags); 2105 local_irq_restore(flags);
2136 2106
2137 my_udelay(20000L); /* Let it all settle down */ 2107 my_udelay(20000L); /* Let it all settle down */
2138 2108
2139 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]); 2109 printk("CD2401 initialised, chip is rev 0x%02x\n", base_addr[CyGFRCR]);
2140 if (badspeed) 2110 if (badspeed)
2141 printk(" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n", 2111 printk
2142 rcor >> 5, rbpr); 2112 (" WARNING: Failed to identify line speed, rcor=%02x,rbpr=%02x\n",
2143} /* serial_console_init */ 2113 rcor >> 5, rbpr);
2114} /* serial_console_init */
2144 2115
2145static const struct tty_operations cy_ops = { 2116static const struct tty_operations cy_ops = {
2146 .open = cy_open, 2117 .open = cy_open,
@@ -2161,6 +2132,7 @@ static const struct tty_operations cy_ops = {
2161 .tiocmget = cy_tiocmget, 2132 .tiocmget = cy_tiocmget,
2162 .tiocmset = cy_tiocmset, 2133 .tiocmset = cy_tiocmset,
2163}; 2134};
2135
2164/* The serial driver boot-time initialization code! 2136/* The serial driver boot-time initialization code!
2165 Hardware I/O ports are mapped to character special devices on a 2137 Hardware I/O ports are mapped to character special devices on a
2166 first found, first allocated manner. That is, this code searches 2138 first found, first allocated manner. That is, this code searches
@@ -2177,214 +2149,214 @@ static const struct tty_operations cy_ops = {
2177 If there are more cards with more ports than have been statically 2149 If there are more cards with more ports than have been statically
2178 allocated above, a warning is printed and the extra ports are ignored. 2150 allocated above, a warning is printed and the extra ports are ignored.
2179 */ 2151 */
2180static int __init 2152static int __init serial167_init(void)
2181serial167_init(void)
2182{ 2153{
2183 struct cyclades_port *info; 2154 struct cyclades_port *info;
2184 int ret = 0; 2155 int ret = 0;
2185 int good_ports = 0; 2156 int good_ports = 0;
2186 int port_num = 0; 2157 int port_num = 0;
2187 int index; 2158 int index;
2188 int DefSpeed; 2159 int DefSpeed;
2189#ifdef notyet 2160#ifdef notyet
2190 struct sigaction sa; 2161 struct sigaction sa;
2191#endif 2162#endif
2192 2163
2193 if (!(mvme16x_config &MVME16x_CONFIG_GOT_CD2401)) 2164 if (!(mvme16x_config & MVME16x_CONFIG_GOT_CD2401))
2194 return 0; 2165 return 0;
2195 2166
2196 cy_serial_driver = alloc_tty_driver(NR_PORTS); 2167 cy_serial_driver = alloc_tty_driver(NR_PORTS);
2197 if (!cy_serial_driver) 2168 if (!cy_serial_driver)
2198 return -ENOMEM; 2169 return -ENOMEM;
2199 2170
2200#if 0 2171#if 0
2201scrn[1] = '\0'; 2172 scrn[1] = '\0';
2202#endif 2173#endif
2203 2174
2204 show_version(); 2175 show_version();
2205 2176
2206 /* Has "console=0,9600n8" been used in bootinfo to change speed? */ 2177 /* Has "console=0,9600n8" been used in bootinfo to change speed? */
2207 if (serial_console_cflag) 2178 if (serial_console_cflag)
2208 DefSpeed = serial_console_cflag & 0017; 2179 DefSpeed = serial_console_cflag & 0017;
2209 else { 2180 else {
2210 DefSpeed = initial_console_speed; 2181 DefSpeed = initial_console_speed;
2211 serial_console_info = &cy_port[0]; 2182 serial_console_info = &cy_port[0];
2212 serial_console_cflag = DefSpeed | CS8; 2183 serial_console_cflag = DefSpeed | CS8;
2213#if 0 2184#if 0
2214 serial_console = 64; /*callout_driver.minor_start*/ 2185 serial_console = 64; /*callout_driver.minor_start */
2215#endif 2186#endif
2216 } 2187 }
2217
2218 /* Initialize the tty_driver structure */
2219
2220 cy_serial_driver->owner = THIS_MODULE;
2221 cy_serial_driver->name = "ttyS";
2222 cy_serial_driver->major = TTY_MAJOR;
2223 cy_serial_driver->minor_start = 64;
2224 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2225 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
2226 cy_serial_driver->init_termios = tty_std_termios;
2227 cy_serial_driver->init_termios.c_cflag =
2228 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2229 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
2230 tty_set_operations(cy_serial_driver, &cy_ops);
2231 2188
2232 ret = tty_register_driver(cy_serial_driver); 2189 /* Initialize the tty_driver structure */
2233 if (ret) {
2234 printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2235 put_tty_driver(cy_serial_driver);
2236 return ret;
2237 }
2238 2190
2239 port_num = 0; 2191 cy_serial_driver->owner = THIS_MODULE;
2240 info = cy_port; 2192 cy_serial_driver->name = "ttyS";
2241 for (index = 0; index < 1; index++) { 2193 cy_serial_driver->major = TTY_MAJOR;
2194 cy_serial_driver->minor_start = 64;
2195 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
2196 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
2197 cy_serial_driver->init_termios = tty_std_termios;
2198 cy_serial_driver->init_termios.c_cflag =
2199 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2200 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
2201 tty_set_operations(cy_serial_driver, &cy_ops);
2202
2203 ret = tty_register_driver(cy_serial_driver);
2204 if (ret) {
2205 printk(KERN_ERR "Couldn't register MVME166/7 serial driver\n");
2206 put_tty_driver(cy_serial_driver);
2207 return ret;
2208 }
2242 2209
2243 good_ports = 4; 2210 port_num = 0;
2211 info = cy_port;
2212 for (index = 0; index < 1; index++) {
2244 2213
2245 if(port_num < NR_PORTS){ 2214 good_ports = 4;
2246 while( good_ports-- && port_num < NR_PORTS){ 2215
2216 if (port_num < NR_PORTS) {
2217 while (good_ports-- && port_num < NR_PORTS) {
2247 /*** initialize port ***/ 2218 /*** initialize port ***/
2248 info->magic = CYCLADES_MAGIC; 2219 info->magic = CYCLADES_MAGIC;
2249 info->type = PORT_CIRRUS; 2220 info->type = PORT_CIRRUS;
2250 info->card = index; 2221 info->card = index;
2251 info->line = port_num; 2222 info->line = port_num;
2252 info->flags = STD_COM_FLAGS; 2223 info->flags = STD_COM_FLAGS;
2253 info->tty = NULL; 2224 info->tty = NULL;
2254 info->xmit_fifo_size = 12; 2225 info->xmit_fifo_size = 12;
2255 info->cor1 = CyPARITY_NONE|Cy_8_BITS; 2226 info->cor1 = CyPARITY_NONE | Cy_8_BITS;
2256 info->cor2 = CyETC; 2227 info->cor2 = CyETC;
2257 info->cor3 = Cy_1_STOP; 2228 info->cor3 = Cy_1_STOP;
2258 info->cor4 = 0x08; /* _very_ small receive threshold */ 2229 info->cor4 = 0x08; /* _very_ small receive threshold */
2259 info->cor5 = 0; 2230 info->cor5 = 0;
2260 info->cor6 = 0; 2231 info->cor6 = 0;
2261 info->cor7 = 0; 2232 info->cor7 = 0;
2262 info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */ 2233 info->tbpr = baud_bpr[DefSpeed]; /* Tx BPR */
2263 info->tco = baud_co[DefSpeed]; /* Tx CO */ 2234 info->tco = baud_co[DefSpeed]; /* Tx CO */
2264 info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */ 2235 info->rbpr = baud_bpr[DefSpeed]; /* Rx BPR */
2265 info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */ 2236 info->rco = baud_co[DefSpeed] >> 5; /* Rx CO */
2266 info->close_delay = 0; 2237 info->close_delay = 0;
2267 info->x_char = 0; 2238 info->x_char = 0;
2268 info->event = 0; 2239 info->event = 0;
2269 info->count = 0; 2240 info->count = 0;
2270#ifdef SERIAL_DEBUG_COUNT 2241#ifdef SERIAL_DEBUG_COUNT
2271 printk("cyc: %d: setting count to 0\n", __LINE__); 2242 printk("cyc: %d: setting count to 0\n",
2272#endif 2243 __LINE__);
2273 info->blocked_open = 0; 2244#endif
2274 info->default_threshold = 0; 2245 info->blocked_open = 0;
2275 info->default_timeout = 0; 2246 info->default_threshold = 0;
2276 INIT_WORK(&info->tqueue, do_softint); 2247 info->default_timeout = 0;
2277 init_waitqueue_head(&info->open_wait); 2248 INIT_WORK(&info->tqueue, do_softint);
2278 init_waitqueue_head(&info->close_wait); 2249 init_waitqueue_head(&info->open_wait);
2279 /* info->session */ 2250 init_waitqueue_head(&info->close_wait);
2280 /* info->pgrp */ 2251 /* info->session */
2252 /* info->pgrp */
2281/*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/ 2253/*** !!!!!!!! this may expose new bugs !!!!!!!!! *********/
2282 info->read_status_mask = CyTIMEOUT| CySPECHAR| CyBREAK 2254 info->read_status_mask =
2283 | CyPARITY| CyFRAME| CyOVERRUN; 2255 CyTIMEOUT | CySPECHAR | CyBREAK | CyPARITY |
2284 /* info->timeout */ 2256 CyFRAME | CyOVERRUN;
2285 2257 /* info->timeout */
2286 printk("ttyS%d ", info->line); 2258
2287 port_num++;info++; 2259 printk("ttyS%d ", info->line);
2288 if(!(port_num & 7)){ 2260 port_num++;
2289 printk("\n "); 2261 info++;
2262 if (!(port_num & 7)) {
2263 printk("\n ");
2264 }
2265 }
2290 } 2266 }
2291 } 2267 printk("\n");
2292 } 2268 }
2293 printk("\n"); 2269 while (port_num < NR_PORTS) {
2294 } 2270 info->line = -1;
2295 while( port_num < NR_PORTS){ 2271 port_num++;
2296 info->line = -1; 2272 info++;
2297 port_num++;info++; 2273 }
2298 }
2299#ifdef CONFIG_REMOTE_DEBUG 2274#ifdef CONFIG_REMOTE_DEBUG
2300 debug_setup(); 2275 debug_setup();
2301#endif 2276#endif
2302 ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0, 2277 ret = request_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt, 0,
2303 "cd2401_errors", cd2401_rxerr_interrupt); 2278 "cd2401_errors", cd2401_rxerr_interrupt);
2304 if (ret) { 2279 if (ret) {
2305 printk(KERN_ERR "Could't get cd2401_errors IRQ"); 2280 printk(KERN_ERR "Could't get cd2401_errors IRQ");
2306 goto cleanup_serial_driver; 2281 goto cleanup_serial_driver;
2307 } 2282 }
2308 2283
2309 ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0, 2284 ret = request_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt, 0,
2310 "cd2401_modem", cd2401_modem_interrupt); 2285 "cd2401_modem", cd2401_modem_interrupt);
2311 if (ret) { 2286 if (ret) {
2312 printk(KERN_ERR "Could't get cd2401_modem IRQ"); 2287 printk(KERN_ERR "Could't get cd2401_modem IRQ");
2313 goto cleanup_irq_cd2401_errors; 2288 goto cleanup_irq_cd2401_errors;
2314 } 2289 }
2315 2290
2316 ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0, 2291 ret = request_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt, 0,
2317 "cd2401_txints", cd2401_tx_interrupt); 2292 "cd2401_txints", cd2401_tx_interrupt);
2318 if (ret) { 2293 if (ret) {
2319 printk(KERN_ERR "Could't get cd2401_txints IRQ"); 2294 printk(KERN_ERR "Could't get cd2401_txints IRQ");
2320 goto cleanup_irq_cd2401_modem; 2295 goto cleanup_irq_cd2401_modem;
2321 } 2296 }
2322 2297
2323 ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0, 2298 ret = request_irq(MVME167_IRQ_SER_RX, cd2401_rx_interrupt, 0,
2324 "cd2401_rxints", cd2401_rx_interrupt); 2299 "cd2401_rxints", cd2401_rx_interrupt);
2325 if (ret) { 2300 if (ret) {
2326 printk(KERN_ERR "Could't get cd2401_rxints IRQ"); 2301 printk(KERN_ERR "Could't get cd2401_rxints IRQ");
2327 goto cleanup_irq_cd2401_txints; 2302 goto cleanup_irq_cd2401_txints;
2328 } 2303 }
2329 2304
2330 /* Now we have registered the interrupt handlers, allow the interrupts */ 2305 /* Now we have registered the interrupt handlers, allow the interrupts */
2331 2306
2332 pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */ 2307 pcc2chip[PccSCCMICR] = 0x15; /* Serial ints are level 5 */
2333 pcc2chip[PccSCCTICR] = 0x15; 2308 pcc2chip[PccSCCTICR] = 0x15;
2334 pcc2chip[PccSCCRICR] = 0x15; 2309 pcc2chip[PccSCCRICR] = 0x15;
2335 2310
2336 pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */ 2311 pcc2chip[PccIMLR] = 3; /* Allow PCC2 ints above 3!? */
2337 2312
2338 return 0; 2313 return 0;
2339cleanup_irq_cd2401_txints: 2314cleanup_irq_cd2401_txints:
2340 free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt); 2315 free_irq(MVME167_IRQ_SER_TX, cd2401_tx_interrupt);
2341cleanup_irq_cd2401_modem: 2316cleanup_irq_cd2401_modem:
2342 free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt); 2317 free_irq(MVME167_IRQ_SER_MODEM, cd2401_modem_interrupt);
2343cleanup_irq_cd2401_errors: 2318cleanup_irq_cd2401_errors:
2344 free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt); 2319 free_irq(MVME167_IRQ_SER_ERR, cd2401_rxerr_interrupt);
2345cleanup_serial_driver: 2320cleanup_serial_driver:
2346 if (tty_unregister_driver(cy_serial_driver)) 2321 if (tty_unregister_driver(cy_serial_driver))
2347 printk(KERN_ERR "Couldn't unregister MVME166/7 serial driver\n"); 2322 printk(KERN_ERR
2348 put_tty_driver(cy_serial_driver); 2323 "Couldn't unregister MVME166/7 serial driver\n");
2349 return ret; 2324 put_tty_driver(cy_serial_driver);
2350} /* serial167_init */ 2325 return ret;
2326} /* serial167_init */
2351 2327
2352module_init(serial167_init); 2328module_init(serial167_init);
2353 2329
2354
2355#ifdef CYCLOM_SHOW_STATUS 2330#ifdef CYCLOM_SHOW_STATUS
2356static void 2331static void show_status(int line_num)
2357show_status(int line_num)
2358{ 2332{
2359 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2333 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2360 int channel; 2334 int channel;
2361 struct cyclades_port * info; 2335 struct cyclades_port *info;
2362 unsigned long flags; 2336 unsigned long flags;
2363 2337
2364 info = &cy_port[line_num]; 2338 info = &cy_port[line_num];
2365 channel = info->line; 2339 channel = info->line;
2366 printk(" channel %d\n", channel);/**/ 2340 printk(" channel %d\n", channel);
2367 2341 /**/ printk(" cy_port\n");
2368 printk(" cy_port\n"); 2342 printk(" card line flags = %d %d %x\n",
2369 printk(" card line flags = %d %d %x\n", 2343 info->card, info->line, info->flags);
2370 info->card, info->line, info->flags); 2344 printk
2371 printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n", 2345 (" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2372 (long)info->tty, info->read_status_mask, 2346 (long)info->tty, info->read_status_mask, info->timeout,
2373 info->timeout, info->xmit_fifo_size); 2347 info->xmit_fifo_size);
2374 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n", 2348 printk(" cor1,cor2,cor3,cor4,cor5,cor6,cor7 = %x %x %x %x %x %x %x\n",
2375 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5, 2349 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5,
2376 info->cor6, info->cor7); 2350 info->cor6, info->cor7);
2377 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n", 2351 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n", info->tbpr, info->tco,
2378 info->tbpr, info->tco, info->rbpr, info->rco); 2352 info->rbpr, info->rco);
2379 printk(" close_delay event count = %d %d %d\n", 2353 printk(" close_delay event count = %d %d %d\n", info->close_delay,
2380 info->close_delay, info->event, info->count); 2354 info->event, info->count);
2381 printk(" x_char blocked_open = %x %x\n", 2355 printk(" x_char blocked_open = %x %x\n", info->x_char,
2382 info->x_char, info->blocked_open); 2356 info->blocked_open);
2383 printk(" open_wait = %lx %lx %lx\n", 2357 printk(" open_wait = %lx %lx %lx\n", (long)info->open_wait);
2384 (long)info->open_wait); 2358
2385 2359 local_irq_save(flags);
2386
2387 local_irq_save(flags);
2388 2360
2389/* Global Registers */ 2361/* Global Registers */
2390 2362
@@ -2398,7 +2370,7 @@ show_status(int line_num)
2398 printk(" CyMIR %x\n", base_addr[CyMIR]); 2370 printk(" CyMIR %x\n", base_addr[CyMIR]);
2399 printk(" CyTPR %x\n", base_addr[CyTPR]); 2371 printk(" CyTPR %x\n", base_addr[CyTPR]);
2400 2372
2401 base_addr[CyCAR] = (u_char)channel; 2373 base_addr[CyCAR] = (u_char) channel;
2402 2374
2403/* Virtual Registers */ 2375/* Virtual Registers */
2404 2376
@@ -2442,11 +2414,10 @@ show_status(int line_num)
2442 printk(" CyTBPR %x\n", base_addr[CyTBPR]); 2414 printk(" CyTBPR %x\n", base_addr[CyTBPR]);
2443 printk(" CyTCOR %x\n", base_addr[CyTCOR]); 2415 printk(" CyTCOR %x\n", base_addr[CyTCOR]);
2444 2416
2445 local_irq_restore(flags); 2417 local_irq_restore(flags);
2446} /* show_status */ 2418} /* show_status */
2447#endif 2419#endif
2448 2420
2449
2450#if 0 2421#if 0
2451/* Dummy routine in mvme16x/config.c for now */ 2422/* Dummy routine in mvme16x/config.c for now */
2452 2423
@@ -2459,61 +2430,67 @@ void console_setup(char *str, int *ints)
2459 int cflag = 0; 2430 int cflag = 0;
2460 2431
2461 /* Sanity check. */ 2432 /* Sanity check. */
2462 if (ints[0] > 3 || ints[1] > 3) return; 2433 if (ints[0] > 3 || ints[1] > 3)
2434 return;
2463 2435
2464 /* Get baud, bits and parity */ 2436 /* Get baud, bits and parity */
2465 baud = 2400; 2437 baud = 2400;
2466 bits = 8; 2438 bits = 8;
2467 parity = 'n'; 2439 parity = 'n';
2468 if (ints[2]) baud = ints[2]; 2440 if (ints[2])
2441 baud = ints[2];
2469 if ((s = strchr(str, ','))) { 2442 if ((s = strchr(str, ','))) {
2470 do { 2443 do {
2471 s++; 2444 s++;
2472 } while(*s >= '0' && *s <= '9'); 2445 } while (*s >= '0' && *s <= '9');
2473 if (*s) parity = *s++; 2446 if (*s)
2474 if (*s) bits = *s - '0'; 2447 parity = *s++;
2448 if (*s)
2449 bits = *s - '0';
2475 } 2450 }
2476 2451
2477 /* Now construct a cflag setting. */ 2452 /* Now construct a cflag setting. */
2478 switch(baud) { 2453 switch (baud) {
2479 case 1200: 2454 case 1200:
2480 cflag |= B1200; 2455 cflag |= B1200;
2481 break; 2456 break;
2482 case 9600: 2457 case 9600:
2483 cflag |= B9600; 2458 cflag |= B9600;
2484 break; 2459 break;
2485 case 19200: 2460 case 19200:
2486 cflag |= B19200; 2461 cflag |= B19200;
2487 break; 2462 break;
2488 case 38400: 2463 case 38400:
2489 cflag |= B38400; 2464 cflag |= B38400;
2490 break; 2465 break;
2491 case 2400: 2466 case 2400:
2492 default: 2467 default:
2493 cflag |= B2400; 2468 cflag |= B2400;
2494 break; 2469 break;
2495 } 2470 }
2496 switch(bits) { 2471 switch (bits) {
2497 case 7: 2472 case 7:
2498 cflag |= CS7; 2473 cflag |= CS7;
2499 break; 2474 break;
2500 default: 2475 default:
2501 case 8: 2476 case 8:
2502 cflag |= CS8; 2477 cflag |= CS8;
2503 break; 2478 break;
2504 } 2479 }
2505 switch(parity) { 2480 switch (parity) {
2506 case 'o': case 'O': 2481 case 'o':
2507 cflag |= PARODD; 2482 case 'O':
2508 break; 2483 cflag |= PARODD;
2509 case 'e': case 'E': 2484 break;
2510 cflag |= PARENB; 2485 case 'e':
2511 break; 2486 case 'E':
2487 cflag |= PARENB;
2488 break;
2512 } 2489 }
2513 2490
2514 serial_console_info = &cy_port[ints[1]]; 2491 serial_console_info = &cy_port[ints[1]];
2515 serial_console_cflag = cflag; 2492 serial_console_cflag = cflag;
2516 serial_console = ints[1] + 64; /*callout_driver.minor_start*/ 2493 serial_console = ints[1] + 64; /*callout_driver.minor_start */
2517} 2494}
2518#endif 2495#endif
2519 2496
@@ -2532,9 +2509,10 @@ void console_setup(char *str, int *ints)
2532 * The console must be locked when we get here. 2509 * The console must be locked when we get here.
2533 */ 2510 */
2534 2511
2535void serial167_console_write(struct console *co, const char *str, unsigned count) 2512void serial167_console_write(struct console *co, const char *str,
2513 unsigned count)
2536{ 2514{
2537 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2515 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2538 unsigned long flags; 2516 unsigned long flags;
2539 volatile u_char sink; 2517 volatile u_char sink;
2540 u_char ier; 2518 u_char ier;
@@ -2547,7 +2525,7 @@ void serial167_console_write(struct console *co, const char *str, unsigned count
2547 /* Ensure transmitter is enabled! */ 2525 /* Ensure transmitter is enabled! */
2548 2526
2549 port = 0; 2527 port = 0;
2550 base_addr[CyCAR] = (u_char)port; 2528 base_addr[CyCAR] = (u_char) port;
2551 while (base_addr[CyCCR]) 2529 while (base_addr[CyCCR])
2552 ; 2530 ;
2553 base_addr[CyCCR] = CyENB_XMTR; 2531 base_addr[CyCCR] = CyENB_XMTR;
@@ -2556,8 +2534,7 @@ void serial167_console_write(struct console *co, const char *str, unsigned count
2556 base_addr[CyIER] = CyTxMpty; 2534 base_addr[CyIER] = CyTxMpty;
2557 2535
2558 while (1) { 2536 while (1) {
2559 if (pcc2chip[PccSCCTICR] & 0x20) 2537 if (pcc2chip[PccSCCTICR] & 0x20) {
2560 {
2561 /* We have a Tx int. Acknowledge it */ 2538 /* We have a Tx int. Acknowledge it */
2562 sink = pcc2chip[PccTPIACKR]; 2539 sink = pcc2chip[PccTPIACKR];
2563 if ((base_addr[CyLICR] >> 2) == port) { 2540 if ((base_addr[CyLICR] >> 2) == port) {
@@ -2571,18 +2548,15 @@ void serial167_console_write(struct console *co, const char *str, unsigned count
2571 str++; 2548 str++;
2572 i++; 2549 i++;
2573 do_lf = 0; 2550 do_lf = 0;
2574 } 2551 } else if (*str == '\n') {
2575 else if (*str == '\n') {
2576 base_addr[CyTDR] = '\r'; 2552 base_addr[CyTDR] = '\r';
2577 do_lf = 1; 2553 do_lf = 1;
2578 } 2554 } else {
2579 else {
2580 base_addr[CyTDR] = *str++; 2555 base_addr[CyTDR] = *str++;
2581 i++; 2556 i++;
2582 } 2557 }
2583 base_addr[CyTEOIR] = 0; 2558 base_addr[CyTEOIR] = 0;
2584 } 2559 } else
2585 else
2586 base_addr[CyTEOIR] = CyNOTRANS; 2560 base_addr[CyTEOIR] = CyNOTRANS;
2587 } 2561 }
2588 } 2562 }
@@ -2592,45 +2566,44 @@ void serial167_console_write(struct console *co, const char *str, unsigned count
2592 local_irq_restore(flags); 2566 local_irq_restore(flags);
2593} 2567}
2594 2568
2595static struct tty_driver *serial167_console_device(struct console *c, int *index) 2569static struct tty_driver *serial167_console_device(struct console *c,
2570 int *index)
2596{ 2571{
2597 *index = c->index; 2572 *index = c->index;
2598 return cy_serial_driver; 2573 return cy_serial_driver;
2599} 2574}
2600 2575
2601
2602static int __init serial167_console_setup(struct console *co, char *options) 2576static int __init serial167_console_setup(struct console *co, char *options)
2603{ 2577{
2604 return 0; 2578 return 0;
2605} 2579}
2606 2580
2607
2608static struct console sercons = { 2581static struct console sercons = {
2609 .name = "ttyS", 2582 .name = "ttyS",
2610 .write = serial167_console_write, 2583 .write = serial167_console_write,
2611 .device = serial167_console_device, 2584 .device = serial167_console_device,
2612 .setup = serial167_console_setup, 2585 .setup = serial167_console_setup,
2613 .flags = CON_PRINTBUFFER, 2586 .flags = CON_PRINTBUFFER,
2614 .index = -1, 2587 .index = -1,
2615}; 2588};
2616 2589
2617
2618static int __init serial167_console_init(void) 2590static int __init serial167_console_init(void)
2619{ 2591{
2620 if (vme_brdtype == VME_TYPE_MVME166 || 2592 if (vme_brdtype == VME_TYPE_MVME166 ||
2621 vme_brdtype == VME_TYPE_MVME167 || 2593 vme_brdtype == VME_TYPE_MVME167 ||
2622 vme_brdtype == VME_TYPE_MVME177) { 2594 vme_brdtype == VME_TYPE_MVME177) {
2623 mvme167_serial_console_setup(0); 2595 mvme167_serial_console_setup(0);
2624 register_console(&sercons); 2596 register_console(&sercons);
2625 } 2597 }
2626 return 0; 2598 return 0;
2627} 2599}
2600
2628console_initcall(serial167_console_init); 2601console_initcall(serial167_console_init);
2629 2602
2630#ifdef CONFIG_REMOTE_DEBUG 2603#ifdef CONFIG_REMOTE_DEBUG
2631void putDebugChar (int c) 2604void putDebugChar(int c)
2632{ 2605{
2633 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2606 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2634 unsigned long flags; 2607 unsigned long flags;
2635 volatile u_char sink; 2608 volatile u_char sink;
2636 u_char ier; 2609 u_char ier;
@@ -2641,7 +2614,7 @@ void putDebugChar (int c)
2641 /* Ensure transmitter is enabled! */ 2614 /* Ensure transmitter is enabled! */
2642 2615
2643 port = DEBUG_PORT; 2616 port = DEBUG_PORT;
2644 base_addr[CyCAR] = (u_char)port; 2617 base_addr[CyCAR] = (u_char) port;
2645 while (base_addr[CyCCR]) 2618 while (base_addr[CyCCR])
2646 ; 2619 ;
2647 base_addr[CyCCR] = CyENB_XMTR; 2620 base_addr[CyCCR] = CyENB_XMTR;
@@ -2650,16 +2623,14 @@ void putDebugChar (int c)
2650 base_addr[CyIER] = CyTxMpty; 2623 base_addr[CyIER] = CyTxMpty;
2651 2624
2652 while (1) { 2625 while (1) {
2653 if (pcc2chip[PccSCCTICR] & 0x20) 2626 if (pcc2chip[PccSCCTICR] & 0x20) {
2654 {
2655 /* We have a Tx int. Acknowledge it */ 2627 /* We have a Tx int. Acknowledge it */
2656 sink = pcc2chip[PccTPIACKR]; 2628 sink = pcc2chip[PccTPIACKR];
2657 if ((base_addr[CyLICR] >> 2) == port) { 2629 if ((base_addr[CyLICR] >> 2) == port) {
2658 base_addr[CyTDR] = c; 2630 base_addr[CyTDR] = c;
2659 base_addr[CyTEOIR] = 0; 2631 base_addr[CyTEOIR] = 0;
2660 break; 2632 break;
2661 } 2633 } else
2662 else
2663 base_addr[CyTEOIR] = CyNOTRANS; 2634 base_addr[CyTEOIR] = CyNOTRANS;
2664 } 2635 }
2665 } 2636 }
@@ -2671,7 +2642,7 @@ void putDebugChar (int c)
2671 2642
2672int getDebugChar() 2643int getDebugChar()
2673{ 2644{
2674 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2645 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2675 unsigned long flags; 2646 unsigned long flags;
2676 volatile u_char sink; 2647 volatile u_char sink;
2677 u_char ier; 2648 u_char ier;
@@ -2693,7 +2664,7 @@ int getDebugChar()
2693 /* Ensure receiver is enabled! */ 2664 /* Ensure receiver is enabled! */
2694 2665
2695 port = DEBUG_PORT; 2666 port = DEBUG_PORT;
2696 base_addr[CyCAR] = (u_char)port; 2667 base_addr[CyCAR] = (u_char) port;
2697#if 0 2668#if 0
2698 while (base_addr[CyCCR]) 2669 while (base_addr[CyCCR])
2699 ; 2670 ;
@@ -2703,31 +2674,30 @@ int getDebugChar()
2703 base_addr[CyIER] = CyRxData; 2674 base_addr[CyIER] = CyRxData;
2704 2675
2705 while (1) { 2676 while (1) {
2706 if (pcc2chip[PccSCCRICR] & 0x20) 2677 if (pcc2chip[PccSCCRICR] & 0x20) {
2707 {
2708 /* We have a Rx int. Acknowledge it */ 2678 /* We have a Rx int. Acknowledge it */
2709 sink = pcc2chip[PccRPIACKR]; 2679 sink = pcc2chip[PccRPIACKR];
2710 if ((base_addr[CyLICR] >> 2) == port) { 2680 if ((base_addr[CyLICR] >> 2) == port) {
2711 int cnt = base_addr[CyRFOC]; 2681 int cnt = base_addr[CyRFOC];
2712 while (cnt-- > 0) 2682 while (cnt-- > 0) {
2713 {
2714 c = base_addr[CyRDR]; 2683 c = base_addr[CyRDR];
2715 if (c == 0) 2684 if (c == 0)
2716 printk ("!! debug char is null (cnt=%d) !!", cnt); 2685 printk
2686 ("!! debug char is null (cnt=%d) !!",
2687 cnt);
2717 else 2688 else
2718 queueDebugChar (c); 2689 queueDebugChar(c);
2719 } 2690 }
2720 base_addr[CyREOIR] = 0; 2691 base_addr[CyREOIR] = 0;
2721 i = debugiq.out; 2692 i = debugiq.out;
2722 if (i == debugiq.in) 2693 if (i == debugiq.in)
2723 panic ("Debug input queue empty!"); 2694 panic("Debug input queue empty!");
2724 c = debugiq.buf[i]; 2695 c = debugiq.buf[i];
2725 if (++i == DEBUG_LEN) 2696 if (++i == DEBUG_LEN)
2726 i = 0; 2697 i = 0;
2727 debugiq.out = i; 2698 debugiq.out = i;
2728 break; 2699 break;
2729 } 2700 } else
2730 else
2731 base_addr[CyREOIR] = CyNOTRANS; 2701 base_addr[CyREOIR] = CyNOTRANS;
2732 } 2702 }
2733 } 2703 }
@@ -2739,7 +2709,7 @@ int getDebugChar()
2739 return (c); 2709 return (c);
2740} 2710}
2741 2711
2742void queueDebugChar (int c) 2712void queueDebugChar(int c)
2743{ 2713{
2744 int i; 2714 int i;
2745 2715
@@ -2751,73 +2721,71 @@ void queueDebugChar (int c)
2751 debugiq.in = i; 2721 debugiq.in = i;
2752} 2722}
2753 2723
2754static void 2724static void debug_setup()
2755debug_setup()
2756{ 2725{
2757 unsigned long flags; 2726 unsigned long flags;
2758 volatile unsigned char *base_addr = (u_char *)BASE_ADDR; 2727 volatile unsigned char *base_addr = (u_char *) BASE_ADDR;
2759 int i, cflag; 2728 int i, cflag;
2760 2729
2761 cflag = B19200; 2730 cflag = B19200;
2762 2731
2763 local_irq_save(flags); 2732 local_irq_save(flags);
2764 2733
2765 for (i = 0; i < 4; i++) 2734 for (i = 0; i < 4; i++) {
2766 { 2735 base_addr[CyCAR] = i;
2767 base_addr[CyCAR] = i; 2736 base_addr[CyLICR] = i << 2;
2768 base_addr[CyLICR] = i << 2; 2737 }
2769 }
2770 2738
2771 debugiq.in = debugiq.out = 0; 2739 debugiq.in = debugiq.out = 0;
2772 2740
2773 base_addr[CyCAR] = DEBUG_PORT; 2741 base_addr[CyCAR] = DEBUG_PORT;
2774 2742
2775 /* baud rate */ 2743 /* baud rate */
2776 i = cflag & CBAUD; 2744 i = cflag & CBAUD;
2777 2745
2778 base_addr[CyIER] = 0; 2746 base_addr[CyIER] = 0;
2779 2747
2780 base_addr[CyCMR] = CyASYNC; 2748 base_addr[CyCMR] = CyASYNC;
2781 base_addr[CyLICR] = DEBUG_PORT << 2; 2749 base_addr[CyLICR] = DEBUG_PORT << 2;
2782 base_addr[CyLIVR] = 0x5c; 2750 base_addr[CyLIVR] = 0x5c;
2783 2751
2784 /* tx and rx baud rate */ 2752 /* tx and rx baud rate */
2785 2753
2786 base_addr[CyTCOR] = baud_co[i]; 2754 base_addr[CyTCOR] = baud_co[i];
2787 base_addr[CyTBPR] = baud_bpr[i]; 2755 base_addr[CyTBPR] = baud_bpr[i];
2788 base_addr[CyRCOR] = baud_co[i] >> 5; 2756 base_addr[CyRCOR] = baud_co[i] >> 5;
2789 base_addr[CyRBPR] = baud_bpr[i]; 2757 base_addr[CyRBPR] = baud_bpr[i];
2790 2758
2791 /* set line characteristics according configuration */ 2759 /* set line characteristics according configuration */
2792 2760
2793 base_addr[CySCHR1] = 0; 2761 base_addr[CySCHR1] = 0;
2794 base_addr[CySCHR2] = 0; 2762 base_addr[CySCHR2] = 0;
2795 base_addr[CySCRL] = 0; 2763 base_addr[CySCRL] = 0;
2796 base_addr[CySCRH] = 0; 2764 base_addr[CySCRH] = 0;
2797 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE; 2765 base_addr[CyCOR1] = Cy_8_BITS | CyPARITY_NONE;
2798 base_addr[CyCOR2] = 0; 2766 base_addr[CyCOR2] = 0;
2799 base_addr[CyCOR3] = Cy_1_STOP; 2767 base_addr[CyCOR3] = Cy_1_STOP;
2800 base_addr[CyCOR4] = baud_cor4[i]; 2768 base_addr[CyCOR4] = baud_cor4[i];
2801 base_addr[CyCOR5] = 0; 2769 base_addr[CyCOR5] = 0;
2802 base_addr[CyCOR6] = 0; 2770 base_addr[CyCOR6] = 0;
2803 base_addr[CyCOR7] = 0; 2771 base_addr[CyCOR7] = 0;
2804 2772
2805 write_cy_cmd(base_addr,CyINIT_CHAN); 2773 write_cy_cmd(base_addr, CyINIT_CHAN);
2806 write_cy_cmd(base_addr,CyENB_RCVR); 2774 write_cy_cmd(base_addr, CyENB_RCVR);
2807 2775
2808 base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */ 2776 base_addr[CyCAR] = DEBUG_PORT; /* !!! Is this needed? */
2809 2777
2810 base_addr[CyRTPRL] = 2; 2778 base_addr[CyRTPRL] = 2;
2811 base_addr[CyRTPRH] = 0; 2779 base_addr[CyRTPRH] = 0;
2812 2780
2813 base_addr[CyMSVR1] = CyRTS; 2781 base_addr[CyMSVR1] = CyRTS;
2814 base_addr[CyMSVR2] = CyDTR; 2782 base_addr[CyMSVR2] = CyDTR;
2815 2783
2816 base_addr[CyIER] = CyRxData; 2784 base_addr[CyIER] = CyRxData;
2817 2785
2818 local_irq_restore(flags); 2786 local_irq_restore(flags);
2819 2787
2820} /* debug_setup */ 2788} /* debug_setup */
2821 2789
2822#endif 2790#endif
2823 2791
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 20946f5127e..baf7234b6e6 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -459,10 +459,9 @@ void missed_irq (unsigned long data)
459 if (irq) { 459 if (irq) {
460 printk (KERN_INFO "Missed interrupt... Calling int from timer. \n"); 460 printk (KERN_INFO "Missed interrupt... Calling int from timer. \n");
461 sx_interrupt (((struct specialix_board *)data)->irq, 461 sx_interrupt (((struct specialix_board *)data)->irq,
462 (void*)data, NULL); 462 (void*)data);
463 } 463 }
464 missed_irq_timer.expires = jiffies + sx_poll; 464 mod_timer(&missed_irq_timer, jiffies + sx_poll);
465 add_timer (&missed_irq_timer);
466} 465}
467#endif 466#endif
468 467
@@ -597,11 +596,8 @@ static int sx_probe(struct specialix_board *bp)
597 dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) ); 596 dprintk (SX_DEBUG_INIT, " GFCR = 0x%02x\n", sx_in_off(bp, CD186x_GFRCR) );
598 597
599#ifdef SPECIALIX_TIMER 598#ifdef SPECIALIX_TIMER
600 init_timer (&missed_irq_timer); 599 setup_timer(&missed_irq_timer, missed_irq, (unsigned long)bp);
601 missed_irq_timer.function = missed_irq; 600 mod_timer(&missed_irq_timer, jiffies + sx_poll);
602 missed_irq_timer.data = (unsigned long) bp;
603 missed_irq_timer.expires = jiffies + sx_poll;
604 add_timer (&missed_irq_timer);
605#endif 601#endif
606 602
607 printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n", 603 printk(KERN_INFO"sx%d: specialix IO8+ board detected at 0x%03x, IRQ %d, CD%d Rev. %c.\n",
@@ -2350,10 +2346,8 @@ static void do_softint(struct work_struct *work)
2350 return; 2346 return;
2351 } 2347 }
2352 2348
2353 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event)) { 2349 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &port->event))
2354 tty_wakeup(tty); 2350 tty_wakeup(tty);
2355 //wake_up_interruptible(&tty->write_wait);
2356 }
2357 2351
2358 func_exit(); 2352 func_exit();
2359} 2353}
@@ -2561,7 +2555,7 @@ static void __exit specialix_exit_module(void)
2561 if (sx_board[i].flags & SX_BOARD_PRESENT) 2555 if (sx_board[i].flags & SX_BOARD_PRESENT)
2562 sx_release_io_range(&sx_board[i]); 2556 sx_release_io_range(&sx_board[i]);
2563#ifdef SPECIALIX_TIMER 2557#ifdef SPECIALIX_TIMER
2564 del_timer (&missed_irq_timer); 2558 del_timer_sync(&missed_irq_timer);
2565#endif 2559#endif
2566 2560
2567 func_exit(); 2561 func_exit();
diff --git a/drivers/char/synclink.c b/drivers/char/synclink.c
index 3fa625db9e4..ce4db6f5236 100644
--- a/drivers/char/synclink.c
+++ b/drivers/char/synclink.c
@@ -1148,10 +1148,8 @@ static void mgsl_bh_transmit(struct mgsl_struct *info)
1148 printk( "%s(%d):mgsl_bh_transmit() entry on %s\n", 1148 printk( "%s(%d):mgsl_bh_transmit() entry on %s\n",
1149 __FILE__,__LINE__,info->device_name); 1149 __FILE__,__LINE__,info->device_name);
1150 1150
1151 if (tty) { 1151 if (tty)
1152 tty_wakeup(tty); 1152 tty_wakeup(tty);
1153 wake_up_interruptible(&tty->write_wait);
1154 }
1155 1153
1156 /* if transmitter idle and loopmode_send_done_requested 1154 /* if transmitter idle and loopmode_send_done_requested
1157 * then start echoing RxD to TxD 1155 * then start echoing RxD to TxD
@@ -1800,9 +1798,7 @@ static int startup(struct mgsl_struct * info)
1800 1798
1801 memset(&info->icount, 0, sizeof(info->icount)); 1799 memset(&info->icount, 0, sizeof(info->icount));
1802 1800
1803 init_timer(&info->tx_timer); 1801 setup_timer(&info->tx_timer, mgsl_tx_timeout, (unsigned long)info);
1804 info->tx_timer.data = (unsigned long)info;
1805 info->tx_timer.function = mgsl_tx_timeout;
1806 1802
1807 /* Allocate and claim adapter resources */ 1803 /* Allocate and claim adapter resources */
1808 retval = mgsl_claim_resources(info); 1804 retval = mgsl_claim_resources(info);
@@ -1853,7 +1849,7 @@ static void shutdown(struct mgsl_struct * info)
1853 wake_up_interruptible(&info->status_event_wait_q); 1849 wake_up_interruptible(&info->status_event_wait_q);
1854 wake_up_interruptible(&info->event_wait_q); 1850 wake_up_interruptible(&info->event_wait_q);
1855 1851
1856 del_timer(&info->tx_timer); 1852 del_timer_sync(&info->tx_timer);
1857 1853
1858 if (info->xmit_buf) { 1854 if (info->xmit_buf) {
1859 free_page((unsigned long) info->xmit_buf); 1855 free_page((unsigned long) info->xmit_buf);
@@ -2340,7 +2336,6 @@ static void mgsl_flush_buffer(struct tty_struct *tty)
2340 del_timer(&info->tx_timer); 2336 del_timer(&info->tx_timer);
2341 spin_unlock_irqrestore(&info->irq_spinlock,flags); 2337 spin_unlock_irqrestore(&info->irq_spinlock,flags);
2342 2338
2343 wake_up_interruptible(&tty->write_wait);
2344 tty_wakeup(tty); 2339 tty_wakeup(tty);
2345} 2340}
2346 2341
@@ -5713,8 +5708,8 @@ static void usc_start_transmitter( struct mgsl_struct *info )
5713 5708
5714 usc_TCmd( info, TCmd_SendFrame ); 5709 usc_TCmd( info, TCmd_SendFrame );
5715 5710
5716 info->tx_timer.expires = jiffies + msecs_to_jiffies(5000); 5711 mod_timer(&info->tx_timer, jiffies +
5717 add_timer(&info->tx_timer); 5712 msecs_to_jiffies(5000));
5718 } 5713 }
5719 info->tx_active = 1; 5714 info->tx_active = 1;
5720 } 5715 }
diff --git a/drivers/char/synclink_gt.c b/drivers/char/synclink_gt.c
index 792c79c315e..0a367cd4121 100644
--- a/drivers/char/synclink_gt.c
+++ b/drivers/char/synclink_gt.c
@@ -1045,7 +1045,6 @@ static void flush_buffer(struct tty_struct *tty)
1045 info->tx_count = 0; 1045 info->tx_count = 0;
1046 spin_unlock_irqrestore(&info->lock,flags); 1046 spin_unlock_irqrestore(&info->lock,flags);
1047 1047
1048 wake_up_interruptible(&tty->write_wait);
1049 tty_wakeup(tty); 1048 tty_wakeup(tty);
1050} 1049}
1051 1050
@@ -1826,8 +1825,7 @@ static void rx_async(struct slgt_info *info)
1826 if (i < count) { 1825 if (i < count) {
1827 /* receive buffer not completed */ 1826 /* receive buffer not completed */
1828 info->rbuf_index += i; 1827 info->rbuf_index += i;
1829 info->rx_timer.expires = jiffies + 1; 1828 mod_timer(&info->rx_timer, jiffies + 1);
1830 add_timer(&info->rx_timer);
1831 break; 1829 break;
1832 } 1830 }
1833 1831
@@ -1933,10 +1931,8 @@ static void bh_transmit(struct slgt_info *info)
1933 struct tty_struct *tty = info->tty; 1931 struct tty_struct *tty = info->tty;
1934 1932
1935 DBGBH(("%s bh_transmit\n", info->device_name)); 1933 DBGBH(("%s bh_transmit\n", info->device_name));
1936 if (tty) { 1934 if (tty)
1937 tty_wakeup(tty); 1935 tty_wakeup(tty);
1938 wake_up_interruptible(&tty->write_wait);
1939 }
1940} 1936}
1941 1937
1942static void dsr_change(struct slgt_info *info) 1938static void dsr_change(struct slgt_info *info)
@@ -3343,13 +3339,8 @@ static struct slgt_info *alloc_dev(int adapter_num, int port_num, struct pci_dev
3343 info->adapter_num = adapter_num; 3339 info->adapter_num = adapter_num;
3344 info->port_num = port_num; 3340 info->port_num = port_num;
3345 3341
3346 init_timer(&info->tx_timer); 3342 setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
3347 info->tx_timer.data = (unsigned long)info; 3343 setup_timer(&info->rx_timer, rx_timeout, (unsigned long)info);
3348 info->tx_timer.function = tx_timeout;
3349
3350 init_timer(&info->rx_timer);
3351 info->rx_timer.data = (unsigned long)info;
3352 info->rx_timer.function = rx_timeout;
3353 3344
3354 /* Copy configuration info to device instance data */ 3345 /* Copy configuration info to device instance data */
3355 info->pdev = pdev; 3346 info->pdev = pdev;
@@ -3797,10 +3788,9 @@ static void tx_start(struct slgt_info *info)
3797 } 3788 }
3798 } 3789 }
3799 3790
3800 if (info->params.mode == MGSL_MODE_HDLC) { 3791 if (info->params.mode == MGSL_MODE_HDLC)
3801 info->tx_timer.expires = jiffies + msecs_to_jiffies(5000); 3792 mod_timer(&info->tx_timer, jiffies +
3802 add_timer(&info->tx_timer); 3793 msecs_to_jiffies(5000));
3803 }
3804 } else { 3794 } else {
3805 tdma_reset(info); 3795 tdma_reset(info);
3806 /* set 1st descriptor address */ 3796 /* set 1st descriptor address */
diff --git a/drivers/char/synclinkmp.c b/drivers/char/synclinkmp.c
index 8f4d67afe5b..ef93d055bdd 100644
--- a/drivers/char/synclinkmp.c
+++ b/drivers/char/synclinkmp.c
@@ -1258,7 +1258,6 @@ static void flush_buffer(struct tty_struct *tty)
1258 del_timer(&info->tx_timer); 1258 del_timer(&info->tx_timer);
1259 spin_unlock_irqrestore(&info->lock,flags); 1259 spin_unlock_irqrestore(&info->lock,flags);
1260 1260
1261 wake_up_interruptible(&tty->write_wait);
1262 tty_wakeup(tty); 1261 tty_wakeup(tty);
1263} 1262}
1264 1263
@@ -2127,10 +2126,8 @@ void bh_transmit(SLMP_INFO *info)
2127 printk( "%s(%d):%s bh_transmit() entry\n", 2126 printk( "%s(%d):%s bh_transmit() entry\n",
2128 __FILE__,__LINE__,info->device_name); 2127 __FILE__,__LINE__,info->device_name);
2129 2128
2130 if (tty) { 2129 if (tty)
2131 tty_wakeup(tty); 2130 tty_wakeup(tty);
2132 wake_up_interruptible(&tty->write_wait);
2133 }
2134} 2131}
2135 2132
2136void bh_status(SLMP_INFO *info) 2133void bh_status(SLMP_INFO *info)
@@ -2747,8 +2744,7 @@ static int startup(SLMP_INFO * info)
2747 2744
2748 change_params(info); 2745 change_params(info);
2749 2746
2750 info->status_timer.expires = jiffies + msecs_to_jiffies(10); 2747 mod_timer(&info->status_timer, jiffies + msecs_to_jiffies(10));
2751 add_timer(&info->status_timer);
2752 2748
2753 if (info->tty) 2749 if (info->tty)
2754 clear_bit(TTY_IO_ERROR, &info->tty->flags); 2750 clear_bit(TTY_IO_ERROR, &info->tty->flags);
@@ -3844,13 +3840,9 @@ static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
3844 info->bus_type = MGSL_BUS_TYPE_PCI; 3840 info->bus_type = MGSL_BUS_TYPE_PCI;
3845 info->irq_flags = IRQF_SHARED; 3841 info->irq_flags = IRQF_SHARED;
3846 3842
3847 init_timer(&info->tx_timer); 3843 setup_timer(&info->tx_timer, tx_timeout, (unsigned long)info);
3848 info->tx_timer.data = (unsigned long)info; 3844 setup_timer(&info->status_timer, status_timeout,
3849 info->tx_timer.function = tx_timeout; 3845 (unsigned long)info);
3850
3851 init_timer(&info->status_timer);
3852 info->status_timer.data = (unsigned long)info;
3853 info->status_timer.function = status_timeout;
3854 3846
3855 /* Store the PCI9050 misc control register value because a flaw 3847 /* Store the PCI9050 misc control register value because a flaw
3856 * in the PCI9050 prevents LCR registers from being read if 3848 * in the PCI9050 prevents LCR registers from being read if
@@ -4294,8 +4286,8 @@ void tx_start(SLMP_INFO *info)
4294 write_reg(info, TXDMA + DIR, 0x40); /* enable Tx DMA interrupts (EOM) */ 4286 write_reg(info, TXDMA + DIR, 0x40); /* enable Tx DMA interrupts (EOM) */
4295 write_reg(info, TXDMA + DSR, 0xf2); /* clear Tx DMA IRQs, enable Tx DMA */ 4287 write_reg(info, TXDMA + DSR, 0xf2); /* clear Tx DMA IRQs, enable Tx DMA */
4296 4288
4297 info->tx_timer.expires = jiffies + msecs_to_jiffies(5000); 4289 mod_timer(&info->tx_timer, jiffies +
4298 add_timer(&info->tx_timer); 4290 msecs_to_jiffies(5000));
4299 } 4291 }
4300 else { 4292 else {
4301 tx_load_fifo(info); 4293 tx_load_fifo(info);
@@ -5577,10 +5569,7 @@ void status_timeout(unsigned long context)
5577 if (status) 5569 if (status)
5578 isr_io_pin(info,status); 5570 isr_io_pin(info,status);
5579 5571
5580 info->status_timer.data = (unsigned long)info; 5572 mod_timer(&info->status_timer, jiffies + msecs_to_jiffies(10));
5581 info->status_timer.function = status_timeout;
5582 info->status_timer.expires = jiffies + msecs_to_jiffies(10);
5583 add_timer(&info->status_timer);
5584} 5573}
5585 5574
5586 5575
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index 7fd3cd5ddf2..3757610b783 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -88,9 +88,9 @@ static struct sysrq_key_op sysrq_loglevel_op = {
88#ifdef CONFIG_VT 88#ifdef CONFIG_VT
89static void sysrq_handle_SAK(int key, struct tty_struct *tty) 89static void sysrq_handle_SAK(int key, struct tty_struct *tty)
90{ 90{
91 if (tty) 91 struct work_struct *SAK_work = &vc_cons[fg_console].SAK_work;
92 do_SAK(tty); 92 PREPARE_WORK(SAK_work, vc_SAK);
93 reset_vc(vc_cons[fg_console].d); 93 schedule_work(SAK_work);
94} 94}
95static struct sysrq_key_op sysrq_SAK_op = { 95static struct sysrq_key_op sysrq_SAK_op = {
96 .handler = sysrq_handle_SAK, 96 .handler = sysrq_handle_SAK,
diff --git a/drivers/char/toshiba.c b/drivers/char/toshiba.c
index 07067c31c4e..c346ec5a3dc 100644
--- a/drivers/char/toshiba.c
+++ b/drivers/char/toshiba.c
@@ -68,6 +68,7 @@
68#include <linux/init.h> 68#include <linux/init.h>
69#include <linux/stat.h> 69#include <linux/stat.h>
70#include <linux/proc_fs.h> 70#include <linux/proc_fs.h>
71#include <linux/seq_file.h>
71 72
72#include <linux/toshiba.h> 73#include <linux/toshiba.h>
73 74
@@ -298,12 +299,10 @@ static int tosh_ioctl(struct inode *ip, struct file *fp, unsigned int cmd,
298 * Print the information for /proc/toshiba 299 * Print the information for /proc/toshiba
299 */ 300 */
300#ifdef CONFIG_PROC_FS 301#ifdef CONFIG_PROC_FS
301static int tosh_get_info(char *buffer, char **start, off_t fpos, int length) 302static int proc_toshiba_show(struct seq_file *m, void *v)
302{ 303{
303 char *temp;
304 int key; 304 int key;
305 305
306 temp = buffer;
307 key = tosh_fn_status(); 306 key = tosh_fn_status();
308 307
309 /* Arguments 308 /* Arguments
@@ -314,8 +313,7 @@ static int tosh_get_info(char *buffer, char **start, off_t fpos, int length)
314 4) BIOS date (in SCI date format) 313 4) BIOS date (in SCI date format)
315 5) Fn Key status 314 5) Fn Key status
316 */ 315 */
317 316 seq_printf(m, "1.1 0x%04x %d.%d %d.%d 0x%04x 0x%02x\n",
318 temp += sprintf(temp, "1.1 0x%04x %d.%d %d.%d 0x%04x 0x%02x\n",
319 tosh_id, 317 tosh_id,
320 (tosh_sci & 0xff00)>>8, 318 (tosh_sci & 0xff00)>>8,
321 tosh_sci & 0xff, 319 tosh_sci & 0xff,
@@ -323,9 +321,21 @@ static int tosh_get_info(char *buffer, char **start, off_t fpos, int length)
323 tosh_bios & 0xff, 321 tosh_bios & 0xff,
324 tosh_date, 322 tosh_date,
325 key); 323 key);
324 return 0;
325}
326 326
327 return temp-buffer; 327static int proc_toshiba_open(struct inode *inode, struct file *file)
328{
329 return single_open(file, proc_toshiba_show, NULL);
328} 330}
331
332static const struct file_operations proc_toshiba_fops = {
333 .owner = THIS_MODULE,
334 .open = proc_toshiba_open,
335 .read = seq_read,
336 .llseek = seq_lseek,
337 .release = single_release,
338};
329#endif 339#endif
330 340
331 341
@@ -508,10 +518,15 @@ static int __init toshiba_init(void)
508 return retval; 518 return retval;
509 519
510#ifdef CONFIG_PROC_FS 520#ifdef CONFIG_PROC_FS
511 /* register the proc entry */ 521 {
512 if (create_proc_info_entry("toshiba", 0, NULL, tosh_get_info) == NULL) { 522 struct proc_dir_entry *pde;
513 misc_deregister(&tosh_device); 523
514 return -ENOMEM; 524 pde = create_proc_entry("toshiba", 0, NULL);
525 if (!pde) {
526 misc_deregister(&tosh_device);
527 return -ENOMEM;
528 }
529 pde->proc_fops = &proc_toshiba_fops;
515 } 530 }
516#endif 531#endif
517 532
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 33e1f66e39c..2f572b97c16 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -1107,9 +1107,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1107 1107
1108 INIT_WORK(&chip->work, timeout_work); 1108 INIT_WORK(&chip->work, timeout_work);
1109 1109
1110 init_timer(&chip->user_read_timer); 1110 setup_timer(&chip->user_read_timer, user_reader_timeout,
1111 chip->user_read_timer.function = user_reader_timeout; 1111 (unsigned long)chip);
1112 chip->user_read_timer.data = (unsigned long) chip;
1113 1112
1114 memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific)); 1113 memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
1115 1114
diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
index 7fca5f470be..4eba32b23b2 100644
--- a/drivers/char/tpm/tpm_bios.c
+++ b/drivers/char/tpm/tpm_bios.c
@@ -441,7 +441,7 @@ static int tpm_ascii_bios_measurements_open(struct inode *inode,
441 return err; 441 return err;
442} 442}
443 443
444struct file_operations tpm_ascii_bios_measurements_ops = { 444const struct file_operations tpm_ascii_bios_measurements_ops = {
445 .open = tpm_ascii_bios_measurements_open, 445 .open = tpm_ascii_bios_measurements_open,
446 .read = seq_read, 446 .read = seq_read,
447 .llseek = seq_lseek, 447 .llseek = seq_lseek,
@@ -474,7 +474,7 @@ static int tpm_binary_bios_measurements_open(struct inode *inode,
474 return err; 474 return err;
475} 475}
476 476
477struct file_operations tpm_binary_bios_measurements_ops = { 477const struct file_operations tpm_binary_bios_measurements_ops = {
478 .open = tpm_binary_bios_measurements_open, 478 .open = tpm_binary_bios_measurements_open,
479 .read = seq_read, 479 .read = seq_read,
480 .llseek = seq_lseek, 480 .llseek = seq_lseek,
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 47a6eacb10b..65672c57470 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -154,7 +154,9 @@ static int tty_release(struct inode *, struct file *);
154int tty_ioctl(struct inode * inode, struct file * file, 154int tty_ioctl(struct inode * inode, struct file * file,
155 unsigned int cmd, unsigned long arg); 155 unsigned int cmd, unsigned long arg);
156static int tty_fasync(int fd, struct file * filp, int on); 156static int tty_fasync(int fd, struct file * filp, int on);
157static void release_mem(struct tty_struct *tty, int idx); 157static void release_tty(struct tty_struct *tty, int idx);
158static struct pid *__proc_set_tty(struct task_struct *tsk,
159 struct tty_struct *tty);
158 160
159/** 161/**
160 * alloc_tty_struct - allocate a tty object 162 * alloc_tty_struct - allocate a tty object
@@ -1109,17 +1111,17 @@ int tty_check_change(struct tty_struct * tty)
1109{ 1111{
1110 if (current->signal->tty != tty) 1112 if (current->signal->tty != tty)
1111 return 0; 1113 return 0;
1112 if (tty->pgrp <= 0) { 1114 if (!tty->pgrp) {
1113 printk(KERN_WARNING "tty_check_change: tty->pgrp <= 0!\n"); 1115 printk(KERN_WARNING "tty_check_change: tty->pgrp == NULL!\n");
1114 return 0; 1116 return 0;
1115 } 1117 }
1116 if (process_group(current) == tty->pgrp) 1118 if (task_pgrp(current) == tty->pgrp)
1117 return 0; 1119 return 0;
1118 if (is_ignored(SIGTTOU)) 1120 if (is_ignored(SIGTTOU))
1119 return 0; 1121 return 0;
1120 if (is_orphaned_pgrp(process_group(current))) 1122 if (is_current_pgrp_orphaned())
1121 return -EIO; 1123 return -EIO;
1122 (void) kill_pg(process_group(current), SIGTTOU, 1); 1124 (void) kill_pgrp(task_pgrp(current), SIGTTOU, 1);
1123 return -ERESTARTSYS; 1125 return -ERESTARTSYS;
1124} 1126}
1125 1127
@@ -1354,8 +1356,8 @@ static void do_tty_hangup(struct work_struct *work)
1354 tty_release is called */ 1356 tty_release is called */
1355 1357
1356 read_lock(&tasklist_lock); 1358 read_lock(&tasklist_lock);
1357 if (tty->session > 0) { 1359 if (tty->session) {
1358 do_each_task_pid(tty->session, PIDTYPE_SID, p) { 1360 do_each_pid_task(tty->session, PIDTYPE_SID, p) {
1359 spin_lock_irq(&p->sighand->siglock); 1361 spin_lock_irq(&p->sighand->siglock);
1360 if (p->signal->tty == tty) 1362 if (p->signal->tty == tty)
1361 p->signal->tty = NULL; 1363 p->signal->tty = NULL;
@@ -1365,16 +1367,17 @@ static void do_tty_hangup(struct work_struct *work)
1365 } 1367 }
1366 __group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p); 1368 __group_send_sig_info(SIGHUP, SEND_SIG_PRIV, p);
1367 __group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p); 1369 __group_send_sig_info(SIGCONT, SEND_SIG_PRIV, p);
1368 if (tty->pgrp > 0) 1370 put_pid(p->signal->tty_old_pgrp); /* A noop */
1369 p->signal->tty_old_pgrp = tty->pgrp; 1371 if (tty->pgrp)
1372 p->signal->tty_old_pgrp = get_pid(tty->pgrp);
1370 spin_unlock_irq(&p->sighand->siglock); 1373 spin_unlock_irq(&p->sighand->siglock);
1371 } while_each_task_pid(tty->session, PIDTYPE_SID, p); 1374 } while_each_pid_task(tty->session, PIDTYPE_SID, p);
1372 } 1375 }
1373 read_unlock(&tasklist_lock); 1376 read_unlock(&tasklist_lock);
1374 1377
1375 tty->flags = 0; 1378 tty->flags = 0;
1376 tty->session = 0; 1379 tty->session = NULL;
1377 tty->pgrp = -1; 1380 tty->pgrp = NULL;
1378 tty->ctrl_status = 0; 1381 tty->ctrl_status = 0;
1379 /* 1382 /*
1380 * If one of the devices matches a console pointer, we 1383 * If one of the devices matches a console pointer, we
@@ -1459,12 +1462,12 @@ int tty_hung_up_p(struct file * filp)
1459 1462
1460EXPORT_SYMBOL(tty_hung_up_p); 1463EXPORT_SYMBOL(tty_hung_up_p);
1461 1464
1462static void session_clear_tty(pid_t session) 1465static void session_clear_tty(struct pid *session)
1463{ 1466{
1464 struct task_struct *p; 1467 struct task_struct *p;
1465 do_each_task_pid(session, PIDTYPE_SID, p) { 1468 do_each_pid_task(session, PIDTYPE_SID, p) {
1466 proc_clear_tty(p); 1469 proc_clear_tty(p);
1467 } while_each_task_pid(session, PIDTYPE_SID, p); 1470 } while_each_pid_task(session, PIDTYPE_SID, p);
1468} 1471}
1469 1472
1470/** 1473/**
@@ -1494,46 +1497,54 @@ static void session_clear_tty(pid_t session)
1494void disassociate_ctty(int on_exit) 1497void disassociate_ctty(int on_exit)
1495{ 1498{
1496 struct tty_struct *tty; 1499 struct tty_struct *tty;
1497 int tty_pgrp = -1; 1500 struct pid *tty_pgrp = NULL;
1498 int session;
1499 1501
1500 lock_kernel(); 1502 lock_kernel();
1501 1503
1502 mutex_lock(&tty_mutex); 1504 mutex_lock(&tty_mutex);
1503 tty = get_current_tty(); 1505 tty = get_current_tty();
1504 if (tty) { 1506 if (tty) {
1505 tty_pgrp = tty->pgrp; 1507 tty_pgrp = get_pid(tty->pgrp);
1506 mutex_unlock(&tty_mutex); 1508 mutex_unlock(&tty_mutex);
1507 /* XXX: here we race, there is nothing protecting tty */ 1509 /* XXX: here we race, there is nothing protecting tty */
1508 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) 1510 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
1509 tty_vhangup(tty); 1511 tty_vhangup(tty);
1510 } else { 1512 } else if (on_exit) {
1511 pid_t old_pgrp = current->signal->tty_old_pgrp; 1513 struct pid *old_pgrp;
1514 spin_lock_irq(&current->sighand->siglock);
1515 old_pgrp = current->signal->tty_old_pgrp;
1516 current->signal->tty_old_pgrp = NULL;
1517 spin_unlock_irq(&current->sighand->siglock);
1512 if (old_pgrp) { 1518 if (old_pgrp) {
1513 kill_pg(old_pgrp, SIGHUP, on_exit); 1519 kill_pgrp(old_pgrp, SIGHUP, on_exit);
1514 kill_pg(old_pgrp, SIGCONT, on_exit); 1520 kill_pgrp(old_pgrp, SIGCONT, on_exit);
1521 put_pid(old_pgrp);
1515 } 1522 }
1516 mutex_unlock(&tty_mutex); 1523 mutex_unlock(&tty_mutex);
1517 unlock_kernel(); 1524 unlock_kernel();
1518 return; 1525 return;
1519 } 1526 }
1520 if (tty_pgrp > 0) { 1527 if (tty_pgrp) {
1521 kill_pg(tty_pgrp, SIGHUP, on_exit); 1528 kill_pgrp(tty_pgrp, SIGHUP, on_exit);
1522 if (!on_exit) 1529 if (!on_exit)
1523 kill_pg(tty_pgrp, SIGCONT, on_exit); 1530 kill_pgrp(tty_pgrp, SIGCONT, on_exit);
1531 put_pid(tty_pgrp);
1524 } 1532 }
1525 1533
1526 spin_lock_irq(&current->sighand->siglock); 1534 spin_lock_irq(&current->sighand->siglock);
1535 tty_pgrp = current->signal->tty_old_pgrp;
1527 current->signal->tty_old_pgrp = 0; 1536 current->signal->tty_old_pgrp = 0;
1528 session = process_session(current);
1529 spin_unlock_irq(&current->sighand->siglock); 1537 spin_unlock_irq(&current->sighand->siglock);
1538 put_pid(tty_pgrp);
1530 1539
1531 mutex_lock(&tty_mutex); 1540 mutex_lock(&tty_mutex);
1532 /* It is possible that do_tty_hangup has free'd this tty */ 1541 /* It is possible that do_tty_hangup has free'd this tty */
1533 tty = get_current_tty(); 1542 tty = get_current_tty();
1534 if (tty) { 1543 if (tty) {
1535 tty->session = 0; 1544 put_pid(tty->session);
1536 tty->pgrp = 0; 1545 put_pid(tty->pgrp);
1546 tty->session = NULL;
1547 tty->pgrp = NULL;
1537 } else { 1548 } else {
1538#ifdef TTY_DEBUG_HANGUP 1549#ifdef TTY_DEBUG_HANGUP
1539 printk(KERN_DEBUG "error attempted to write to tty [0x%p]" 1550 printk(KERN_DEBUG "error attempted to write to tty [0x%p]"
@@ -1544,7 +1555,7 @@ void disassociate_ctty(int on_exit)
1544 1555
1545 /* Now clear signal->tty under the lock */ 1556 /* Now clear signal->tty under the lock */
1546 read_lock(&tasklist_lock); 1557 read_lock(&tasklist_lock);
1547 session_clear_tty(session); 1558 session_clear_tty(task_session(current));
1548 read_unlock(&tasklist_lock); 1559 read_unlock(&tasklist_lock);
1549 unlock_kernel(); 1560 unlock_kernel();
1550} 1561}
@@ -1612,7 +1623,6 @@ void start_tty(struct tty_struct *tty)
1612 1623
1613 /* If we have a running line discipline it may need kicking */ 1624 /* If we have a running line discipline it may need kicking */
1614 tty_wakeup(tty); 1625 tty_wakeup(tty);
1615 wake_up_interruptible(&tty->write_wait);
1616} 1626}
1617 1627
1618EXPORT_SYMBOL(start_tty); 1628EXPORT_SYMBOL(start_tty);
@@ -2003,7 +2013,7 @@ static int init_dev(struct tty_driver *driver, int idx,
2003 2013
2004 /* 2014 /*
2005 * All structures have been allocated, so now we install them. 2015 * All structures have been allocated, so now we install them.
2006 * Failures after this point use release_mem to clean up, so 2016 * Failures after this point use release_tty to clean up, so
2007 * there's no need to null out the local pointers. 2017 * there's no need to null out the local pointers.
2008 */ 2018 */
2009 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) { 2019 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) {
@@ -2024,8 +2034,8 @@ static int init_dev(struct tty_driver *driver, int idx,
2024 2034
2025 /* 2035 /*
2026 * Structures all installed ... call the ldisc open routines. 2036 * Structures all installed ... call the ldisc open routines.
2027 * If we fail here just call release_mem to clean up. No need 2037 * If we fail here just call release_tty to clean up. No need
2028 * to decrement the use counts, as release_mem doesn't care. 2038 * to decrement the use counts, as release_tty doesn't care.
2029 */ 2039 */
2030 2040
2031 if (tty->ldisc.open) { 2041 if (tty->ldisc.open) {
@@ -2095,17 +2105,17 @@ fail_no_mem:
2095 retval = -ENOMEM; 2105 retval = -ENOMEM;
2096 goto end_init; 2106 goto end_init;
2097 2107
2098 /* call the tty release_mem routine to clean out this slot */ 2108 /* call the tty release_tty routine to clean out this slot */
2099release_mem_out: 2109release_mem_out:
2100 if (printk_ratelimit()) 2110 if (printk_ratelimit())
2101 printk(KERN_INFO "init_dev: ldisc open failed, " 2111 printk(KERN_INFO "init_dev: ldisc open failed, "
2102 "clearing slot %d\n", idx); 2112 "clearing slot %d\n", idx);
2103 release_mem(tty, idx); 2113 release_tty(tty, idx);
2104 goto end_init; 2114 goto end_init;
2105} 2115}
2106 2116
2107/** 2117/**
2108 * release_mem - release tty structure memory 2118 * release_one_tty - release tty structure memory
2109 * 2119 *
2110 * Releases memory associated with a tty structure, and clears out the 2120 * Releases memory associated with a tty structure, and clears out the
2111 * driver table slots. This function is called when a device is no longer 2121 * driver table slots. This function is called when a device is no longer
@@ -2117,37 +2127,14 @@ release_mem_out:
2117 * of ttys that the driver keeps. 2127 * of ttys that the driver keeps.
2118 * FIXME: should we require tty_mutex is held here ?? 2128 * FIXME: should we require tty_mutex is held here ??
2119 */ 2129 */
2120 2130static void release_one_tty(struct tty_struct *tty, int idx)
2121static void release_mem(struct tty_struct *tty, int idx)
2122{ 2131{
2123 struct tty_struct *o_tty;
2124 struct ktermios *tp;
2125 int devpts = tty->driver->flags & TTY_DRIVER_DEVPTS_MEM; 2132 int devpts = tty->driver->flags & TTY_DRIVER_DEVPTS_MEM;
2126 2133 struct ktermios *tp;
2127 if ((o_tty = tty->link) != NULL) {
2128 if (!devpts)
2129 o_tty->driver->ttys[idx] = NULL;
2130 if (o_tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) {
2131 tp = o_tty->termios;
2132 if (!devpts)
2133 o_tty->driver->termios[idx] = NULL;
2134 kfree(tp);
2135
2136 tp = o_tty->termios_locked;
2137 if (!devpts)
2138 o_tty->driver->termios_locked[idx] = NULL;
2139 kfree(tp);
2140 }
2141 o_tty->magic = 0;
2142 o_tty->driver->refcount--;
2143 file_list_lock();
2144 list_del_init(&o_tty->tty_files);
2145 file_list_unlock();
2146 free_tty_struct(o_tty);
2147 }
2148 2134
2149 if (!devpts) 2135 if (!devpts)
2150 tty->driver->ttys[idx] = NULL; 2136 tty->driver->ttys[idx] = NULL;
2137
2151 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) { 2138 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) {
2152 tp = tty->termios; 2139 tp = tty->termios;
2153 if (!devpts) 2140 if (!devpts)
@@ -2160,15 +2147,39 @@ static void release_mem(struct tty_struct *tty, int idx)
2160 kfree(tp); 2147 kfree(tp);
2161 } 2148 }
2162 2149
2150
2163 tty->magic = 0; 2151 tty->magic = 0;
2164 tty->driver->refcount--; 2152 tty->driver->refcount--;
2153
2165 file_list_lock(); 2154 file_list_lock();
2166 list_del_init(&tty->tty_files); 2155 list_del_init(&tty->tty_files);
2167 file_list_unlock(); 2156 file_list_unlock();
2168 module_put(tty->driver->owner); 2157
2169 free_tty_struct(tty); 2158 free_tty_struct(tty);
2170} 2159}
2171 2160
2161/**
2162 * release_tty - release tty structure memory
2163 *
2164 * Release both @tty and a possible linked partner (think pty pair),
2165 * and decrement the refcount of the backing module.
2166 *
2167 * Locking:
2168 * tty_mutex - sometimes only
2169 * takes the file list lock internally when working on the list
2170 * of ttys that the driver keeps.
2171 * FIXME: should we require tty_mutex is held here ??
2172 */
2173static void release_tty(struct tty_struct *tty, int idx)
2174{
2175 struct tty_driver *driver = tty->driver;
2176
2177 if (tty->link)
2178 release_one_tty(tty->link, idx);
2179 release_one_tty(tty, idx);
2180 module_put(driver->owner);
2181}
2182
2172/* 2183/*
2173 * Even releasing the tty structures is a tricky business.. We have 2184 * Even releasing the tty structures is a tricky business.. We have
2174 * to be very careful that the structures are all released at the 2185 * to be very careful that the structures are all released at the
@@ -2436,10 +2447,10 @@ static void release_dev(struct file * filp)
2436 tty_set_termios_ldisc(o_tty,N_TTY); 2447 tty_set_termios_ldisc(o_tty,N_TTY);
2437 } 2448 }
2438 /* 2449 /*
2439 * The release_mem function takes care of the details of clearing 2450 * The release_tty function takes care of the details of clearing
2440 * the slots and preserving the termios structure. 2451 * the slots and preserving the termios structure.
2441 */ 2452 */
2442 release_mem(tty, idx); 2453 release_tty(tty, idx);
2443 2454
2444#ifdef CONFIG_UNIX98_PTYS 2455#ifdef CONFIG_UNIX98_PTYS
2445 /* Make this pty number available for reallocation */ 2456 /* Make this pty number available for reallocation */
@@ -2481,6 +2492,7 @@ static int tty_open(struct inode * inode, struct file * filp)
2481 int index; 2492 int index;
2482 dev_t device = inode->i_rdev; 2493 dev_t device = inode->i_rdev;
2483 unsigned short saved_flags = filp->f_flags; 2494 unsigned short saved_flags = filp->f_flags;
2495 struct pid *old_pgrp;
2484 2496
2485 nonseekable_open(inode, filp); 2497 nonseekable_open(inode, filp);
2486 2498
@@ -2574,15 +2586,17 @@ got_driver:
2574 goto retry_open; 2586 goto retry_open;
2575 } 2587 }
2576 2588
2589 old_pgrp = NULL;
2577 mutex_lock(&tty_mutex); 2590 mutex_lock(&tty_mutex);
2578 spin_lock_irq(&current->sighand->siglock); 2591 spin_lock_irq(&current->sighand->siglock);
2579 if (!noctty && 2592 if (!noctty &&
2580 current->signal->leader && 2593 current->signal->leader &&
2581 !current->signal->tty && 2594 !current->signal->tty &&
2582 tty->session == 0) 2595 tty->session == NULL)
2583 __proc_set_tty(current, tty); 2596 old_pgrp = __proc_set_tty(current, tty);
2584 spin_unlock_irq(&current->sighand->siglock); 2597 spin_unlock_irq(&current->sighand->siglock);
2585 mutex_unlock(&tty_mutex); 2598 mutex_unlock(&tty_mutex);
2599 put_pid(old_pgrp);
2586 return 0; 2600 return 0;
2587} 2601}
2588 2602
@@ -2721,9 +2735,18 @@ static int tty_fasync(int fd, struct file * filp, int on)
2721 return retval; 2735 return retval;
2722 2736
2723 if (on) { 2737 if (on) {
2738 enum pid_type type;
2739 struct pid *pid;
2724 if (!waitqueue_active(&tty->read_wait)) 2740 if (!waitqueue_active(&tty->read_wait))
2725 tty->minimum_to_wake = 1; 2741 tty->minimum_to_wake = 1;
2726 retval = f_setown(filp, (-tty->pgrp) ? : current->pid, 0); 2742 if (tty->pgrp) {
2743 pid = tty->pgrp;
2744 type = PIDTYPE_PGID;
2745 } else {
2746 pid = task_pid(current);
2747 type = PIDTYPE_PID;
2748 }
2749 retval = __f_setown(filp, pid, type, 0);
2727 if (retval) 2750 if (retval)
2728 return retval; 2751 return retval;
2729 } else { 2752 } else {
@@ -2825,10 +2848,10 @@ static int tiocswinsz(struct tty_struct *tty, struct tty_struct *real_tty,
2825 } 2848 }
2826 } 2849 }
2827#endif 2850#endif
2828 if (tty->pgrp > 0) 2851 if (tty->pgrp)
2829 kill_pg(tty->pgrp, SIGWINCH, 1); 2852 kill_pgrp(tty->pgrp, SIGWINCH, 1);
2830 if ((real_tty->pgrp != tty->pgrp) && (real_tty->pgrp > 0)) 2853 if ((real_tty->pgrp != tty->pgrp) && real_tty->pgrp)
2831 kill_pg(real_tty->pgrp, SIGWINCH, 1); 2854 kill_pgrp(real_tty->pgrp, SIGWINCH, 1);
2832 tty->winsize = tmp_ws; 2855 tty->winsize = tmp_ws;
2833 real_tty->winsize = tmp_ws; 2856 real_tty->winsize = tmp_ws;
2834done: 2857done:
@@ -2913,8 +2936,7 @@ static int fionbio(struct file *file, int __user *p)
2913static int tiocsctty(struct tty_struct *tty, int arg) 2936static int tiocsctty(struct tty_struct *tty, int arg)
2914{ 2937{
2915 int ret = 0; 2938 int ret = 0;
2916 if (current->signal->leader && 2939 if (current->signal->leader && (task_session(current) == tty->session))
2917 (process_session(current) == tty->session))
2918 return ret; 2940 return ret;
2919 2941
2920 mutex_lock(&tty_mutex); 2942 mutex_lock(&tty_mutex);
@@ -2927,7 +2949,7 @@ static int tiocsctty(struct tty_struct *tty, int arg)
2927 goto unlock; 2949 goto unlock;
2928 } 2950 }
2929 2951
2930 if (tty->session > 0) { 2952 if (tty->session) {
2931 /* 2953 /*
2932 * This tty is already the controlling 2954 * This tty is already the controlling
2933 * tty for another session group! 2955 * tty for another session group!
@@ -2970,7 +2992,7 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2970 */ 2992 */
2971 if (tty == real_tty && current->signal->tty != real_tty) 2993 if (tty == real_tty && current->signal->tty != real_tty)
2972 return -ENOTTY; 2994 return -ENOTTY;
2973 return put_user(real_tty->pgrp, p); 2995 return put_user(pid_nr(real_tty->pgrp), p);
2974} 2996}
2975 2997
2976/** 2998/**
@@ -2987,7 +3009,8 @@ static int tiocgpgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2987 3009
2988static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p) 3010static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t __user *p)
2989{ 3011{
2990 pid_t pgrp; 3012 struct pid *pgrp;
3013 pid_t pgrp_nr;
2991 int retval = tty_check_change(real_tty); 3014 int retval = tty_check_change(real_tty);
2992 3015
2993 if (retval == -EIO) 3016 if (retval == -EIO)
@@ -2996,16 +3019,26 @@ static int tiocspgrp(struct tty_struct *tty, struct tty_struct *real_tty, pid_t
2996 return retval; 3019 return retval;
2997 if (!current->signal->tty || 3020 if (!current->signal->tty ||
2998 (current->signal->tty != real_tty) || 3021 (current->signal->tty != real_tty) ||
2999 (real_tty->session != process_session(current))) 3022 (real_tty->session != task_session(current)))
3000 return -ENOTTY; 3023 return -ENOTTY;
3001 if (get_user(pgrp, p)) 3024 if (get_user(pgrp_nr, p))
3002 return -EFAULT; 3025 return -EFAULT;
3003 if (pgrp < 0) 3026 if (pgrp_nr < 0)
3004 return -EINVAL; 3027 return -EINVAL;
3005 if (session_of_pgrp(pgrp) != process_session(current)) 3028 rcu_read_lock();
3006 return -EPERM; 3029 pgrp = find_pid(pgrp_nr);
3007 real_tty->pgrp = pgrp; 3030 retval = -ESRCH;
3008 return 0; 3031 if (!pgrp)
3032 goto out_unlock;
3033 retval = -EPERM;
3034 if (session_of_pgrp(pgrp) != task_session(current))
3035 goto out_unlock;
3036 retval = 0;
3037 put_pid(real_tty->pgrp);
3038 real_tty->pgrp = get_pid(pgrp);
3039out_unlock:
3040 rcu_read_unlock();
3041 return retval;
3009} 3042}
3010 3043
3011/** 3044/**
@@ -3028,9 +3061,9 @@ static int tiocgsid(struct tty_struct *tty, struct tty_struct *real_tty, pid_t _
3028 */ 3061 */
3029 if (tty == real_tty && current->signal->tty != real_tty) 3062 if (tty == real_tty && current->signal->tty != real_tty)
3030 return -ENOTTY; 3063 return -ENOTTY;
3031 if (real_tty->session <= 0) 3064 if (!real_tty->session)
3032 return -ENOTTY; 3065 return -ENOTTY;
3033 return put_user(real_tty->session, p); 3066 return put_user(pid_nr(real_tty->session), p);
3034} 3067}
3035 3068
3036/** 3069/**
@@ -3324,15 +3357,13 @@ int tty_ioctl(struct inode * inode, struct file * file,
3324 * Nasty bug: do_SAK is being called in interrupt context. This can 3357 * Nasty bug: do_SAK is being called in interrupt context. This can
3325 * deadlock. We punt it up to process context. AKPM - 16Mar2001 3358 * deadlock. We punt it up to process context. AKPM - 16Mar2001
3326 */ 3359 */
3327static void __do_SAK(struct work_struct *work) 3360void __do_SAK(struct tty_struct *tty)
3328{ 3361{
3329 struct tty_struct *tty =
3330 container_of(work, struct tty_struct, SAK_work);
3331#ifdef TTY_SOFT_SAK 3362#ifdef TTY_SOFT_SAK
3332 tty_hangup(tty); 3363 tty_hangup(tty);
3333#else 3364#else
3334 struct task_struct *g, *p; 3365 struct task_struct *g, *p;
3335 int session; 3366 struct pid *session;
3336 int i; 3367 int i;
3337 struct file *filp; 3368 struct file *filp;
3338 struct fdtable *fdt; 3369 struct fdtable *fdt;
@@ -3348,12 +3379,12 @@ static void __do_SAK(struct work_struct *work)
3348 3379
3349 read_lock(&tasklist_lock); 3380 read_lock(&tasklist_lock);
3350 /* Kill the entire session */ 3381 /* Kill the entire session */
3351 do_each_task_pid(session, PIDTYPE_SID, p) { 3382 do_each_pid_task(session, PIDTYPE_SID, p) {
3352 printk(KERN_NOTICE "SAK: killed process %d" 3383 printk(KERN_NOTICE "SAK: killed process %d"
3353 " (%s): process_session(p)==tty->session\n", 3384 " (%s): process_session(p)==tty->session\n",
3354 p->pid, p->comm); 3385 p->pid, p->comm);
3355 send_sig(SIGKILL, p, 1); 3386 send_sig(SIGKILL, p, 1);
3356 } while_each_task_pid(session, PIDTYPE_SID, p); 3387 } while_each_pid_task(session, PIDTYPE_SID, p);
3357 /* Now kill any processes that happen to have the 3388 /* Now kill any processes that happen to have the
3358 * tty open. 3389 * tty open.
3359 */ 3390 */
@@ -3394,6 +3425,13 @@ static void __do_SAK(struct work_struct *work)
3394#endif 3425#endif
3395} 3426}
3396 3427
3428static void do_SAK_work(struct work_struct *work)
3429{
3430 struct tty_struct *tty =
3431 container_of(work, struct tty_struct, SAK_work);
3432 __do_SAK(tty);
3433}
3434
3397/* 3435/*
3398 * The tq handling here is a little racy - tty->SAK_work may already be queued. 3436 * The tq handling here is a little racy - tty->SAK_work may already be queued.
3399 * Fortunately we don't need to worry, because if ->SAK_work is already queued, 3437 * Fortunately we don't need to worry, because if ->SAK_work is already queued,
@@ -3404,7 +3442,7 @@ void do_SAK(struct tty_struct *tty)
3404{ 3442{
3405 if (!tty) 3443 if (!tty)
3406 return; 3444 return;
3407 PREPARE_WORK(&tty->SAK_work, __do_SAK); 3445 PREPARE_WORK(&tty->SAK_work, do_SAK_work);
3408 schedule_work(&tty->SAK_work); 3446 schedule_work(&tty->SAK_work);
3409} 3447}
3410 3448
@@ -3515,7 +3553,8 @@ static void initialize_tty_struct(struct tty_struct *tty)
3515 memset(tty, 0, sizeof(struct tty_struct)); 3553 memset(tty, 0, sizeof(struct tty_struct));
3516 tty->magic = TTY_MAGIC; 3554 tty->magic = TTY_MAGIC;
3517 tty_ldisc_assign(tty, tty_ldisc_get(N_TTY)); 3555 tty_ldisc_assign(tty, tty_ldisc_get(N_TTY));
3518 tty->pgrp = -1; 3556 tty->session = NULL;
3557 tty->pgrp = NULL;
3519 tty->overrun_time = jiffies; 3558 tty->overrun_time = jiffies;
3520 tty->buf.head = tty->buf.tail = NULL; 3559 tty->buf.head = tty->buf.tail = NULL;
3521 tty_buffer_init(tty); 3560 tty_buffer_init(tty);
@@ -3786,21 +3825,28 @@ void proc_clear_tty(struct task_struct *p)
3786} 3825}
3787EXPORT_SYMBOL(proc_clear_tty); 3826EXPORT_SYMBOL(proc_clear_tty);
3788 3827
3789void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 3828static struct pid *__proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3790{ 3829{
3830 struct pid *old_pgrp;
3791 if (tty) { 3831 if (tty) {
3792 tty->session = process_session(tsk); 3832 tty->session = get_pid(task_session(tsk));
3793 tty->pgrp = process_group(tsk); 3833 tty->pgrp = get_pid(task_pgrp(tsk));
3794 } 3834 }
3835 old_pgrp = tsk->signal->tty_old_pgrp;
3795 tsk->signal->tty = tty; 3836 tsk->signal->tty = tty;
3796 tsk->signal->tty_old_pgrp = 0; 3837 tsk->signal->tty_old_pgrp = NULL;
3838 return old_pgrp;
3797} 3839}
3798 3840
3799void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty) 3841void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3800{ 3842{
3843 struct pid *old_pgrp;
3844
3801 spin_lock_irq(&tsk->sighand->siglock); 3845 spin_lock_irq(&tsk->sighand->siglock);
3802 __proc_set_tty(tsk, tty); 3846 old_pgrp = __proc_set_tty(tsk, tty);
3803 spin_unlock_irq(&tsk->sighand->siglock); 3847 spin_unlock_irq(&tsk->sighand->siglock);
3848
3849 put_pid(old_pgrp);
3804} 3850}
3805 3851
3806struct tty_struct *get_current_tty(void) 3852struct tty_struct *get_current_tty(void)
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index dee47f40c6a..fd471cb3338 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -225,7 +225,7 @@ EXPORT_SYMBOL(tty_termios_input_baud_rate);
225 225
226/** 226/**
227 * tty_termios_encode_baud_rate 227 * tty_termios_encode_baud_rate
228 * @termios: termios structure 228 * @termios: ktermios structure holding user requested state
229 * @ispeed: input speed 229 * @ispeed: input speed
230 * @ospeed: output speed 230 * @ospeed: output speed
231 * 231 *
@@ -233,7 +233,10 @@ EXPORT_SYMBOL(tty_termios_input_baud_rate);
233 * used as a library helper for drivers os that they can report back 233 * used as a library helper for drivers os that they can report back
234 * the actual speed selected when it differs from the speed requested 234 * the actual speed selected when it differs from the speed requested
235 * 235 *
236 * For now input and output speed must agree. 236 * For maximal back compatibility with legacy SYS5/POSIX *nix behaviour
237 * we need to carefully set the bits when the user does not get the
238 * desired speed. We allow small margins and preserve as much of possible
239 * of the input intent to keep compatiblity.
237 * 240 *
238 * Locking: Caller should hold termios lock. This is already held 241 * Locking: Caller should hold termios lock. This is already held
239 * when calling this function from the driver termios handler. 242 * when calling this function from the driver termios handler.
@@ -242,32 +245,44 @@ EXPORT_SYMBOL(tty_termios_input_baud_rate);
242void tty_termios_encode_baud_rate(struct ktermios *termios, speed_t ibaud, speed_t obaud) 245void tty_termios_encode_baud_rate(struct ktermios *termios, speed_t ibaud, speed_t obaud)
243{ 246{
244 int i = 0; 247 int i = 0;
245 int ifound = 0, ofound = 0; 248 int ifound = -1, ofound = -1;
249 int iclose = ibaud/50, oclose = obaud/50;
250 int ibinput = 0;
246 251
247 termios->c_ispeed = ibaud; 252 termios->c_ispeed = ibaud;
248 termios->c_ospeed = obaud; 253 termios->c_ospeed = obaud;
249 254
255 /* If the user asked for a precise weird speed give a precise weird
256 answer. If they asked for a Bfoo speed they many have problems
257 digesting non-exact replies so fuzz a bit */
258
259 if ((termios->c_cflag & CBAUD) == BOTHER)
260 oclose = 0;
261 if (((termios->c_cflag >> IBSHIFT) & CBAUD) == BOTHER)
262 iclose = 0;
263 if ((termios->c_cflag >> IBSHIFT) & CBAUD)
264 ibinput = 1; /* An input speed was specified */
265
250 termios->c_cflag &= ~CBAUD; 266 termios->c_cflag &= ~CBAUD;
251 /* Identical speed means no input encoding (ie B0 << IBSHIFT)*/
252 if (termios->c_ispeed == termios->c_ospeed)
253 ifound = 1;
254 267
255 do { 268 do {
256 if (obaud == baud_table[i]) { 269 if (obaud - oclose >= baud_table[i] && obaud + oclose <= baud_table[i]) {
257 termios->c_cflag |= baud_bits[i]; 270 termios->c_cflag |= baud_bits[i];
258 ofound = 1; 271 ofound = i;
259 /* So that if ibaud == obaud we don't set it */
260 continue;
261 } 272 }
262 if (ibaud == baud_table[i]) { 273 if (ibaud - iclose >= baud_table[i] && ibaud + iclose <= baud_table[i]) {
263 termios->c_cflag |= (baud_bits[i] << IBSHIFT); 274 /* For the case input == output don't set IBAUD bits if the user didn't do so */
264 ifound = 1; 275 if (ofound != i || ibinput)
276 termios->c_cflag |= (baud_bits[i] << IBSHIFT);
277 ifound = i;
265 } 278 }
266 } 279 }
267 while(++i < n_baud_table); 280 while(++i < n_baud_table);
268 if (!ofound) 281 if (ofound == -1)
269 termios->c_cflag |= BOTHER; 282 termios->c_cflag |= BOTHER;
270 if (!ifound) 283 /* Set exact input bits only if the input and output differ or the
284 user already did */
285 if (ifound == -1 && (ibaud != obaud || ibinput))
271 termios->c_cflag |= (BOTHER << IBSHIFT); 286 termios->c_cflag |= (BOTHER << IBSHIFT);
272} 287}
273 288
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 9438512b17f..13faf8d1748 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -872,7 +872,7 @@ free_op:
872 return ret; 872 return ret;
873} 873}
874 874
875struct file_operations viotap_fops = { 875const struct file_operations viotap_fops = {
876 owner: THIS_MODULE, 876 owner: THIS_MODULE,
877 read: viotap_read, 877 read: viotap_read,
878 write: viotap_write, 878 write: viotap_write,
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 06c32a3e3ca..94ce3e7fc9e 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -136,9 +136,6 @@ const struct consw *conswitchp;
136#define DEFAULT_BELL_PITCH 750 136#define DEFAULT_BELL_PITCH 750
137#define DEFAULT_BELL_DURATION (HZ/8) 137#define DEFAULT_BELL_DURATION (HZ/8)
138 138
139extern void vcs_make_sysfs(struct tty_struct *tty);
140extern void vcs_remove_sysfs(struct tty_struct *tty);
141
142struct vc vc_cons [MAX_NR_CONSOLES]; 139struct vc vc_cons [MAX_NR_CONSOLES];
143 140
144#ifndef VT_SINGLE_DRIVER 141#ifndef VT_SINGLE_DRIVER
@@ -213,7 +210,7 @@ static int scrollback_delta;
213 */ 210 */
214int (*console_blank_hook)(int); 211int (*console_blank_hook)(int);
215 212
216static struct timer_list console_timer; 213static DEFINE_TIMER(console_timer, blank_screen_t, 0, 0);
217static int blank_state; 214static int blank_state;
218static int blank_timer_expired; 215static int blank_timer_expired;
219enum { 216enum {
@@ -869,8 +866,8 @@ int vc_resize(struct vc_data *vc, unsigned int cols, unsigned int lines)
869 ws.ws_col = vc->vc_cols; 866 ws.ws_col = vc->vc_cols;
870 ws.ws_ypixel = vc->vc_scan_lines; 867 ws.ws_ypixel = vc->vc_scan_lines;
871 if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) && 868 if ((ws.ws_row != cws->ws_row || ws.ws_col != cws->ws_col) &&
872 vc->vc_tty->pgrp > 0) 869 vc->vc_tty->pgrp)
873 kill_pg(vc->vc_tty->pgrp, SIGWINCH, 1); 870 kill_pgrp(vc->vc_tty->pgrp, SIGWINCH, 1);
874 *cws = ws; 871 *cws = ws;
875 } 872 }
876 873
@@ -2628,8 +2625,6 @@ static int __init con_init(void)
2628 for (i = 0; i < MAX_NR_CONSOLES; i++) 2625 for (i = 0; i < MAX_NR_CONSOLES; i++)
2629 con_driver_map[i] = conswitchp; 2626 con_driver_map[i] = conswitchp;
2630 2627
2631 init_timer(&console_timer);
2632 console_timer.function = blank_screen_t;
2633 if (blankinterval) { 2628 if (blankinterval) {
2634 blank_state = blank_normal_wait; 2629 blank_state = blank_normal_wait;
2635 mod_timer(&console_timer, jiffies + blankinterval); 2630 mod_timer(&console_timer, jiffies + blankinterval);
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index dc8368ebb1a..3a5d301e783 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -672,7 +672,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
672 vc->vt_mode = tmp; 672 vc->vt_mode = tmp;
673 /* the frsig is ignored, so we set it to 0 */ 673 /* the frsig is ignored, so we set it to 0 */
674 vc->vt_mode.frsig = 0; 674 vc->vt_mode.frsig = 0;
675 put_pid(xchg(&vc->vt_pid, get_pid(task_pid(current)))); 675 put_pid(vc->vt_pid);
676 vc->vt_pid = get_pid(task_pid(current));
676 /* no switch is required -- saw@shade.msu.ru */ 677 /* no switch is required -- saw@shade.msu.ru */
677 vc->vt_newvt = -1; 678 vc->vt_newvt = -1;
678 release_console_sem(); 679 release_console_sem();
@@ -1063,12 +1064,35 @@ void reset_vc(struct vc_data *vc)
1063 vc->vt_mode.relsig = 0; 1064 vc->vt_mode.relsig = 0;
1064 vc->vt_mode.acqsig = 0; 1065 vc->vt_mode.acqsig = 0;
1065 vc->vt_mode.frsig = 0; 1066 vc->vt_mode.frsig = 0;
1066 put_pid(xchg(&vc->vt_pid, NULL)); 1067 put_pid(vc->vt_pid);
1068 vc->vt_pid = NULL;
1067 vc->vt_newvt = -1; 1069 vc->vt_newvt = -1;
1068 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */ 1070 if (!in_interrupt()) /* Via keyboard.c:SAK() - akpm */
1069 reset_palette(vc); 1071 reset_palette(vc);
1070} 1072}
1071 1073
1074void vc_SAK(struct work_struct *work)
1075{
1076 struct vc *vc_con =
1077 container_of(work, struct vc, SAK_work);
1078 struct vc_data *vc;
1079 struct tty_struct *tty;
1080
1081 acquire_console_sem();
1082 vc = vc_con->d;
1083 if (vc) {
1084 tty = vc->vc_tty;
1085 /*
1086 * SAK should also work in all raw modes and reset
1087 * them properly.
1088 */
1089 if (tty)
1090 __do_SAK(tty);
1091 reset_vc(vc);
1092 }
1093 release_console_sem();
1094}
1095
1072/* 1096/*
1073 * Performs the back end of a vt switch 1097 * Performs the back end of a vt switch
1074 */ 1098 */
diff --git a/drivers/char/watchdog/alim7101_wdt.c b/drivers/char/watchdog/alim7101_wdt.c
index bf25d0a55a9..e5b2c2ee292 100644
--- a/drivers/char/watchdog/alim7101_wdt.c
+++ b/drivers/char/watchdog/alim7101_wdt.c
@@ -417,10 +417,8 @@ module_init(alim7101_wdt_init);
417module_exit(alim7101_wdt_unload); 417module_exit(alim7101_wdt_unload);
418 418
419static struct pci_device_id alim7101_pci_tbl[] __devinitdata = { 419static struct pci_device_id alim7101_pci_tbl[] __devinitdata = {
420 { PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, 420 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533) },
421 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 421 { PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101) },
422 { PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101,
423 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
424 { } 422 { }
425}; 423};
426 424
diff --git a/drivers/char/watchdog/iTCO_wdt.c b/drivers/char/watchdog/iTCO_wdt.c
index 7eac922df86..fd8a44a08cd 100644
--- a/drivers/char/watchdog/iTCO_wdt.c
+++ b/drivers/char/watchdog/iTCO_wdt.c
@@ -539,7 +539,7 @@ static int iTCO_wdt_ioctl (struct inode *inode, struct file *file,
539 * Kernel Interfaces 539 * Kernel Interfaces
540 */ 540 */
541 541
542static struct file_operations iTCO_wdt_fops = { 542static const struct file_operations iTCO_wdt_fops = {
543 .owner = THIS_MODULE, 543 .owner = THIS_MODULE,
544 .llseek = no_llseek, 544 .llseek = no_llseek,
545 .write = iTCO_wdt_write, 545 .write = iTCO_wdt_write,
diff --git a/drivers/char/watchdog/omap_wdt.c b/drivers/char/watchdog/omap_wdt.c
index 6c6f97332db..84074a697dc 100644
--- a/drivers/char/watchdog/omap_wdt.c
+++ b/drivers/char/watchdog/omap_wdt.c
@@ -230,7 +230,7 @@ omap_wdt_ioctl(struct inode *inode, struct file *file,
230 } 230 }
231} 231}
232 232
233static struct file_operations omap_wdt_fops = { 233static const struct file_operations omap_wdt_fops = {
234 .owner = THIS_MODULE, 234 .owner = THIS_MODULE,
235 .write = omap_wdt_write, 235 .write = omap_wdt_write,
236 .ioctl = omap_wdt_ioctl, 236 .ioctl = omap_wdt_ioctl,
diff --git a/drivers/char/watchdog/pc87413_wdt.c b/drivers/char/watchdog/pc87413_wdt.c
index 1d447e32af4..a77a90717ad 100644
--- a/drivers/char/watchdog/pc87413_wdt.c
+++ b/drivers/char/watchdog/pc87413_wdt.c
@@ -526,7 +526,7 @@ static int pc87413_notify_sys(struct notifier_block *this,
526 526
527/* -- Module's structures ---------------------------------------*/ 527/* -- Module's structures ---------------------------------------*/
528 528
529static struct file_operations pc87413_fops = { 529static const struct file_operations pc87413_fops = {
530 .owner = THIS_MODULE, 530 .owner = THIS_MODULE,
531 .llseek = no_llseek, 531 .llseek = no_llseek,
532 .write = pc87413_write, 532 .write = pc87413_write,
diff --git a/drivers/char/watchdog/pnx4008_wdt.c b/drivers/char/watchdog/pnx4008_wdt.c
index 3a55fc6abcd..ff6f1ca1e5e 100644
--- a/drivers/char/watchdog/pnx4008_wdt.c
+++ b/drivers/char/watchdog/pnx4008_wdt.c
@@ -238,7 +238,7 @@ static int pnx4008_wdt_release(struct inode *inode, struct file *file)
238 return 0; 238 return 0;
239} 239}
240 240
241static struct file_operations pnx4008_wdt_fops = { 241static const struct file_operations pnx4008_wdt_fops = {
242 .owner = THIS_MODULE, 242 .owner = THIS_MODULE,
243 .llseek = no_llseek, 243 .llseek = no_llseek,
244 .write = pnx4008_wdt_write, 244 .write = pnx4008_wdt_write,
diff --git a/drivers/char/watchdog/rm9k_wdt.c b/drivers/char/watchdog/rm9k_wdt.c
index 7576a13e86b..b4678839d3b 100644
--- a/drivers/char/watchdog/rm9k_wdt.c
+++ b/drivers/char/watchdog/rm9k_wdt.c
@@ -95,7 +95,7 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be disabled once started");
95 95
96 96
97/* Kernel interfaces */ 97/* Kernel interfaces */
98static struct file_operations fops = { 98static const struct file_operations fops = {
99 .owner = THIS_MODULE, 99 .owner = THIS_MODULE,
100 .open = wdt_gpi_open, 100 .open = wdt_gpi_open,
101 .release = wdt_gpi_release, 101 .release = wdt_gpi_release,
diff --git a/drivers/char/watchdog/smsc37b787_wdt.c b/drivers/char/watchdog/smsc37b787_wdt.c
index 9f56913b484..a9681d580dd 100644
--- a/drivers/char/watchdog/smsc37b787_wdt.c
+++ b/drivers/char/watchdog/smsc37b787_wdt.c
@@ -510,7 +510,7 @@ static int wb_smsc_wdt_notify_sys(struct notifier_block *this, unsigned long cod
510 510
511/* -- Module's structures ---------------------------------------*/ 511/* -- Module's structures ---------------------------------------*/
512 512
513static struct file_operations wb_smsc_wdt_fops = 513static const struct file_operations wb_smsc_wdt_fops =
514{ 514{
515 .owner = THIS_MODULE, 515 .owner = THIS_MODULE,
516 .llseek = no_llseek, 516 .llseek = no_llseek,
diff --git a/drivers/char/watchdog/w83697hf_wdt.c b/drivers/char/watchdog/w83697hf_wdt.c
index 7768b55487c..c960ec110dd 100644
--- a/drivers/char/watchdog/w83697hf_wdt.c
+++ b/drivers/char/watchdog/w83697hf_wdt.c
@@ -323,7 +323,7 @@ wdt_notify_sys(struct notifier_block *this, unsigned long code,
323 * Kernel Interfaces 323 * Kernel Interfaces
324 */ 324 */
325 325
326static struct file_operations wdt_fops = { 326static const struct file_operations wdt_fops = {
327 .owner = THIS_MODULE, 327 .owner = THIS_MODULE,
328 .llseek = no_llseek, 328 .llseek = no_llseek,
329 .write = wdt_write, 329 .write = wdt_write,
diff --git a/drivers/edac/e752x_edac.c b/drivers/edac/e752x_edac.c
index c82bc0ed7f1..8bcc887692a 100644
--- a/drivers/edac/e752x_edac.c
+++ b/drivers/edac/e752x_edac.c
@@ -285,8 +285,9 @@ static void do_process_ce(struct mem_ctl_info *mci, u16 error_one,
285 if (!pvt->map_type) 285 if (!pvt->map_type)
286 row = 7 - row; 286 row = 7 - row;
287 287
288 edac_mc_handle_ce(mci, page, 0, sec1_syndrome, row, channel, 288 /* e752x mc reads 34:6 of the DRAM linear address */
289 "e752x CE"); 289 edac_mc_handle_ce(mci, page, offset_in_page(sec1_add << 4),
290 sec1_syndrome, row, channel, "e752x CE");
290} 291}
291 292
292static inline void process_ce(struct mem_ctl_info *mci, u16 error_one, 293static inline void process_ce(struct mem_ctl_info *mci, u16 error_one,
@@ -319,8 +320,10 @@ static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
319 ((block_page >> 1) & 3) : 320 ((block_page >> 1) & 3) :
320 edac_mc_find_csrow_by_page(mci, block_page); 321 edac_mc_find_csrow_by_page(mci, block_page);
321 322
322 edac_mc_handle_ue(mci, block_page, 0, row, 323 /* e752x mc reads 34:6 of the DRAM linear address */
323 "e752x UE from Read"); 324 edac_mc_handle_ue(mci, block_page,
325 offset_in_page(error_2b << 4),
326 row, "e752x UE from Read");
324 } 327 }
325 if (error_one & 0x0404) { 328 if (error_one & 0x0404) {
326 error_2b = scrb_add; 329 error_2b = scrb_add;
@@ -333,8 +336,10 @@ static void do_process_ue(struct mem_ctl_info *mci, u16 error_one,
333 ((block_page >> 1) & 3) : 336 ((block_page >> 1) & 3) :
334 edac_mc_find_csrow_by_page(mci, block_page); 337 edac_mc_find_csrow_by_page(mci, block_page);
335 338
336 edac_mc_handle_ue(mci, block_page, 0, row, 339 /* e752x mc reads 34:6 of the DRAM linear address */
337 "e752x UE from Scruber"); 340 edac_mc_handle_ue(mci, block_page,
341 offset_in_page(error_2b << 4),
342 row, "e752x UE from Scruber");
338 } 343 }
339} 344}
340 345
@@ -556,17 +561,17 @@ static void e752x_check_sysbus(struct e752x_error_info *info,
556 error32 = (stat32 >> 16) & 0x3ff; 561 error32 = (stat32 >> 16) & 0x3ff;
557 stat32 = stat32 & 0x3ff; 562 stat32 = stat32 & 0x3ff;
558 563
559 if(stat32 & 0x083) 564 if(stat32 & 0x087)
560 sysbus_error(1, stat32 & 0x083, error_found, handle_error); 565 sysbus_error(1, stat32 & 0x087, error_found, handle_error);
561 566
562 if(stat32 & 0x37c) 567 if(stat32 & 0x378)
563 sysbus_error(0, stat32 & 0x37c, error_found, handle_error); 568 sysbus_error(0, stat32 & 0x378, error_found, handle_error);
564 569
565 if(error32 & 0x083) 570 if(error32 & 0x087)
566 sysbus_error(1, error32 & 0x083, error_found, handle_error); 571 sysbus_error(1, error32 & 0x087, error_found, handle_error);
567 572
568 if(error32 & 0x37c) 573 if(error32 & 0x378)
569 sysbus_error(0, error32 & 0x37c, error_found, handle_error); 574 sysbus_error(0, error32 & 0x378, error_found, handle_error);
570} 575}
571 576
572static void e752x_check_membuf (struct e752x_error_info *info, 577static void e752x_check_membuf (struct e752x_error_info *info,
@@ -782,7 +787,12 @@ static void e752x_init_csrows(struct mem_ctl_info *mci, struct pci_dev *pdev,
782 u8 value; 787 u8 value;
783 u32 dra, drc, cumul_size; 788 u32 dra, drc, cumul_size;
784 789
785 pci_read_config_dword(pdev, E752X_DRA, &dra); 790 dra = 0;
791 for (index=0; index < 4; index++) {
792 u8 dra_reg;
793 pci_read_config_byte(pdev, E752X_DRA+index, &dra_reg);
794 dra |= dra_reg << (index * 8);
795 }
786 pci_read_config_dword(pdev, E752X_DRC, &drc); 796 pci_read_config_dword(pdev, E752X_DRC, &drc);
787 drc_chan = dual_channel_active(ddrcsr); 797 drc_chan = dual_channel_active(ddrcsr);
788 drc_drbg = drc_chan + 1; /* 128 in dual mode, 64 in single */ 798 drc_drbg = drc_chan + 1; /* 128 in dual mode, 64 in single */
diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
index 1b4fc922180..7b622300d0e 100644
--- a/drivers/edac/edac_mc.c
+++ b/drivers/edac/edac_mc.c
@@ -927,6 +927,57 @@ static ssize_t mci_reset_counters_store(struct mem_ctl_info *mci,
927 return count; 927 return count;
928} 928}
929 929
930/* memory scrubbing */
931static ssize_t mci_sdram_scrub_rate_store(struct mem_ctl_info *mci,
932 const char *data, size_t count)
933{
934 u32 bandwidth = -1;
935
936 if (mci->set_sdram_scrub_rate) {
937
938 memctrl_int_store(&bandwidth, data, count);
939
940 if (!(*mci->set_sdram_scrub_rate)(mci, &bandwidth)) {
941 edac_printk(KERN_DEBUG, EDAC_MC,
942 "Scrub rate set successfully, applied: %d\n",
943 bandwidth);
944 } else {
945 /* FIXME: error codes maybe? */
946 edac_printk(KERN_DEBUG, EDAC_MC,
947 "Scrub rate set FAILED, could not apply: %d\n",
948 bandwidth);
949 }
950 } else {
951 /* FIXME: produce "not implemented" ERROR for user-side. */
952 edac_printk(KERN_WARNING, EDAC_MC,
953 "Memory scrubbing 'set'control is not implemented!\n");
954 }
955 return count;
956}
957
958static ssize_t mci_sdram_scrub_rate_show(struct mem_ctl_info *mci, char *data)
959{
960 u32 bandwidth = -1;
961
962 if (mci->get_sdram_scrub_rate) {
963 if (!(*mci->get_sdram_scrub_rate)(mci, &bandwidth)) {
964 edac_printk(KERN_DEBUG, EDAC_MC,
965 "Scrub rate successfully, fetched: %d\n",
966 bandwidth);
967 } else {
968 /* FIXME: error codes maybe? */
969 edac_printk(KERN_DEBUG, EDAC_MC,
970 "Scrub rate fetch FAILED, got: %d\n",
971 bandwidth);
972 }
973 } else {
974 /* FIXME: produce "not implemented" ERROR for user-side. */
975 edac_printk(KERN_WARNING, EDAC_MC,
976 "Memory scrubbing 'get' control is not implemented!\n");
977 }
978 return sprintf(data, "%d\n", bandwidth);
979}
980
930/* default attribute files for the MCI object */ 981/* default attribute files for the MCI object */
931static ssize_t mci_ue_count_show(struct mem_ctl_info *mci, char *data) 982static ssize_t mci_ue_count_show(struct mem_ctl_info *mci, char *data)
932{ 983{
@@ -1033,6 +1084,9 @@ MCIDEV_ATTR(ce_noinfo_count,S_IRUGO,mci_ce_noinfo_show,NULL);
1033MCIDEV_ATTR(ue_count,S_IRUGO,mci_ue_count_show,NULL); 1084MCIDEV_ATTR(ue_count,S_IRUGO,mci_ue_count_show,NULL);
1034MCIDEV_ATTR(ce_count,S_IRUGO,mci_ce_count_show,NULL); 1085MCIDEV_ATTR(ce_count,S_IRUGO,mci_ce_count_show,NULL);
1035 1086
1087/* memory scrubber attribute file */
1088MCIDEV_ATTR(sdram_scrub_rate,S_IRUGO|S_IWUSR,mci_sdram_scrub_rate_show,mci_sdram_scrub_rate_store);
1089
1036static struct mcidev_attribute *mci_attr[] = { 1090static struct mcidev_attribute *mci_attr[] = {
1037 &mci_attr_reset_counters, 1091 &mci_attr_reset_counters,
1038 &mci_attr_mc_name, 1092 &mci_attr_mc_name,
@@ -1042,6 +1096,7 @@ static struct mcidev_attribute *mci_attr[] = {
1042 &mci_attr_ce_noinfo_count, 1096 &mci_attr_ce_noinfo_count,
1043 &mci_attr_ue_count, 1097 &mci_attr_ue_count,
1044 &mci_attr_ce_count, 1098 &mci_attr_ce_count,
1099 &mci_attr_sdram_scrub_rate,
1045 NULL 1100 NULL
1046}; 1101};
1047 1102
@@ -1442,11 +1497,11 @@ int edac_mc_add_mc(struct mem_ctl_info *mci, int mc_idx)
1442 /* set load time so that error rate can be tracked */ 1497 /* set load time so that error rate can be tracked */
1443 mci->start_time = jiffies; 1498 mci->start_time = jiffies;
1444 1499
1445 if (edac_create_sysfs_mci_device(mci)) { 1500 if (edac_create_sysfs_mci_device(mci)) {
1446 edac_mc_printk(mci, KERN_WARNING, 1501 edac_mc_printk(mci, KERN_WARNING,
1447 "failed to create sysfs device\n"); 1502 "failed to create sysfs device\n");
1448 goto fail1; 1503 goto fail1;
1449 } 1504 }
1450 1505
1451 /* Report action taken */ 1506 /* Report action taken */
1452 edac_mc_printk(mci, KERN_INFO, "Giving out device to %s %s: DEV %s\n", 1507 edac_mc_printk(mci, KERN_INFO, "Giving out device to %s %s: DEV %s\n",
@@ -1703,6 +1758,116 @@ void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, const char *msg)
1703EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info); 1758EXPORT_SYMBOL_GPL(edac_mc_handle_ue_no_info);
1704 1759
1705 1760
1761/*************************************************************
1762 * On Fully Buffered DIMM modules, this help function is
1763 * called to process UE events
1764 */
1765void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci,
1766 unsigned int csrow,
1767 unsigned int channela,
1768 unsigned int channelb,
1769 char *msg)
1770{
1771 int len = EDAC_MC_LABEL_LEN * 4;
1772 char labels[len + 1];
1773 char *pos = labels;
1774 int chars;
1775
1776 if (csrow >= mci->nr_csrows) {
1777 /* something is wrong */
1778 edac_mc_printk(mci, KERN_ERR,
1779 "INTERNAL ERROR: row out of range (%d >= %d)\n",
1780 csrow, mci->nr_csrows);
1781 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
1782 return;
1783 }
1784
1785 if (channela >= mci->csrows[csrow].nr_channels) {
1786 /* something is wrong */
1787 edac_mc_printk(mci, KERN_ERR,
1788 "INTERNAL ERROR: channel-a out of range "
1789 "(%d >= %d)\n",
1790 channela, mci->csrows[csrow].nr_channels);
1791 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
1792 return;
1793 }
1794
1795 if (channelb >= mci->csrows[csrow].nr_channels) {
1796 /* something is wrong */
1797 edac_mc_printk(mci, KERN_ERR,
1798 "INTERNAL ERROR: channel-b out of range "
1799 "(%d >= %d)\n",
1800 channelb, mci->csrows[csrow].nr_channels);
1801 edac_mc_handle_ue_no_info(mci, "INTERNAL ERROR");
1802 return;
1803 }
1804
1805 mci->ue_count++;
1806 mci->csrows[csrow].ue_count++;
1807
1808 /* Generate the DIMM labels from the specified channels */
1809 chars = snprintf(pos, len + 1, "%s",
1810 mci->csrows[csrow].channels[channela].label);
1811 len -= chars; pos += chars;
1812 chars = snprintf(pos, len + 1, "-%s",
1813 mci->csrows[csrow].channels[channelb].label);
1814
1815 if (log_ue)
1816 edac_mc_printk(mci, KERN_EMERG,
1817 "UE row %d, channel-a= %d channel-b= %d "
1818 "labels \"%s\": %s\n", csrow, channela, channelb,
1819 labels, msg);
1820
1821 if (panic_on_ue)
1822 panic("UE row %d, channel-a= %d channel-b= %d "
1823 "labels \"%s\": %s\n", csrow, channela,
1824 channelb, labels, msg);
1825}
1826EXPORT_SYMBOL(edac_mc_handle_fbd_ue);
1827
1828/*************************************************************
1829 * On Fully Buffered DIMM modules, this help function is
1830 * called to process CE events
1831 */
1832void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci,
1833 unsigned int csrow,
1834 unsigned int channel,
1835 char *msg)
1836{
1837
1838 /* Ensure boundary values */
1839 if (csrow >= mci->nr_csrows) {
1840 /* something is wrong */
1841 edac_mc_printk(mci, KERN_ERR,
1842 "INTERNAL ERROR: row out of range (%d >= %d)\n",
1843 csrow, mci->nr_csrows);
1844 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
1845 return;
1846 }
1847 if (channel >= mci->csrows[csrow].nr_channels) {
1848 /* something is wrong */
1849 edac_mc_printk(mci, KERN_ERR,
1850 "INTERNAL ERROR: channel out of range (%d >= %d)\n",
1851 channel, mci->csrows[csrow].nr_channels);
1852 edac_mc_handle_ce_no_info(mci, "INTERNAL ERROR");
1853 return;
1854 }
1855
1856 if (log_ce)
1857 /* FIXME - put in DIMM location */
1858 edac_mc_printk(mci, KERN_WARNING,
1859 "CE row %d, channel %d, label \"%s\": %s\n",
1860 csrow, channel,
1861 mci->csrows[csrow].channels[channel].label,
1862 msg);
1863
1864 mci->ce_count++;
1865 mci->csrows[csrow].ce_count++;
1866 mci->csrows[csrow].channels[channel].ce_count++;
1867}
1868EXPORT_SYMBOL(edac_mc_handle_fbd_ce);
1869
1870
1706/* 1871/*
1707 * Iterate over all MC instances and check for ECC, et al, errors 1872 * Iterate over all MC instances and check for ECC, et al, errors
1708 */ 1873 */
@@ -1806,7 +1971,7 @@ static void __exit edac_mc_exit(void)
1806 debugf0("%s()\n", __func__); 1971 debugf0("%s()\n", __func__);
1807 kthread_stop(edac_thread); 1972 kthread_stop(edac_thread);
1808 1973
1809 /* tear down the sysfs device */ 1974 /* tear down the sysfs device */
1810 edac_sysfs_memctrl_teardown(); 1975 edac_sysfs_memctrl_teardown();
1811 edac_sysfs_pci_teardown(); 1976 edac_sysfs_pci_teardown();
1812} 1977}
diff --git a/drivers/edac/edac_mc.h b/drivers/edac/edac_mc.h
index a1cfd4e3c97..713444cc410 100644
--- a/drivers/edac/edac_mc.h
+++ b/drivers/edac/edac_mc.h
@@ -123,7 +123,9 @@ enum mem_type {
123 MEM_RDR, /* Registered single data rate SDRAM */ 123 MEM_RDR, /* Registered single data rate SDRAM */
124 MEM_DDR, /* Double data rate SDRAM */ 124 MEM_DDR, /* Double data rate SDRAM */
125 MEM_RDDR, /* Registered Double data rate SDRAM */ 125 MEM_RDDR, /* Registered Double data rate SDRAM */
126 MEM_RMBS /* Rambus DRAM */ 126 MEM_RMBS, /* Rambus DRAM */
127 MEM_DDR2, /* DDR2 RAM */
128 MEM_FB_DDR2, /* fully buffered DDR2 */
127}; 129};
128 130
129#define MEM_FLAG_EMPTY BIT(MEM_EMPTY) 131#define MEM_FLAG_EMPTY BIT(MEM_EMPTY)
@@ -137,6 +139,8 @@ enum mem_type {
137#define MEM_FLAG_DDR BIT(MEM_DDR) 139#define MEM_FLAG_DDR BIT(MEM_DDR)
138#define MEM_FLAG_RDDR BIT(MEM_RDDR) 140#define MEM_FLAG_RDDR BIT(MEM_RDDR)
139#define MEM_FLAG_RMBS BIT(MEM_RMBS) 141#define MEM_FLAG_RMBS BIT(MEM_RMBS)
142#define MEM_FLAG_DDR2 BIT(MEM_DDR2)
143#define MEM_FLAG_FB_DDR2 BIT(MEM_FB_DDR2)
140 144
141/* chipset Error Detection and Correction capabilities and mode */ 145/* chipset Error Detection and Correction capabilities and mode */
142enum edac_type { 146enum edac_type {
@@ -315,8 +319,21 @@ struct mem_ctl_info {
315 unsigned long scrub_cap; /* chipset scrub capabilities */ 319 unsigned long scrub_cap; /* chipset scrub capabilities */
316 enum scrub_type scrub_mode; /* current scrub mode */ 320 enum scrub_type scrub_mode; /* current scrub mode */
317 321
322 /* Translates sdram memory scrub rate given in bytes/sec to the
323 internal representation and configures whatever else needs
324 to be configured.
325 */
326 int (*set_sdram_scrub_rate) (struct mem_ctl_info *mci, u32 *bw);
327
328 /* Get the current sdram memory scrub rate from the internal
329 representation and converts it to the closest matching
330 bandwith in bytes/sec.
331 */
332 int (*get_sdram_scrub_rate) (struct mem_ctl_info *mci, u32 *bw);
333
318 /* pointer to edac checking routine */ 334 /* pointer to edac checking routine */
319 void (*edac_check) (struct mem_ctl_info * mci); 335 void (*edac_check) (struct mem_ctl_info * mci);
336
320 /* 337 /*
321 * Remaps memory pages: controller pages to physical pages. 338 * Remaps memory pages: controller pages to physical pages.
322 * For most MC's, this will be NULL. 339 * For most MC's, this will be NULL.
@@ -441,6 +458,15 @@ extern void edac_mc_handle_ue(struct mem_ctl_info *mci,
441 int row, const char *msg); 458 int row, const char *msg);
442extern void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci, 459extern void edac_mc_handle_ue_no_info(struct mem_ctl_info *mci,
443 const char *msg); 460 const char *msg);
461extern void edac_mc_handle_fbd_ue(struct mem_ctl_info *mci,
462 unsigned int csrow,
463 unsigned int channel0,
464 unsigned int channel1,
465 char *msg);
466extern void edac_mc_handle_fbd_ce(struct mem_ctl_info *mci,
467 unsigned int csrow,
468 unsigned int channel,
469 char *msg);
444 470
445/* 471/*
446 * This kmalloc's and initializes all the structures. 472 * This kmalloc's and initializes all the structures.
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c
index 5c261e1f92b..d8806e4f182 100644
--- a/drivers/firmware/edd.c
+++ b/drivers/firmware/edd.c
@@ -233,6 +233,8 @@ edd_show_interface(struct edd_device *edev, char *buf)
233 233
234/** 234/**
235 * edd_show_raw_data() - copies raw data to buffer for userspace to parse 235 * edd_show_raw_data() - copies raw data to buffer for userspace to parse
236 * @edev: target edd_device
237 * @buf: output buffer
236 * 238 *
237 * Returns: number of bytes written, or -EINVAL on failure 239 * Returns: number of bytes written, or -EINVAL on failure
238 */ 240 */
@@ -634,8 +636,8 @@ static decl_subsys(edd,&ktype_edd,NULL);
634 636
635/** 637/**
636 * edd_dev_is_type() - is this EDD device a 'type' device? 638 * edd_dev_is_type() - is this EDD device a 'type' device?
637 * @edev 639 * @edev: target edd_device
638 * @type - a host bus or interface identifier string per the EDD spec 640 * @type: a host bus or interface identifier string per the EDD spec
639 * 641 *
640 * Returns 1 (TRUE) if it is a 'type' device, 0 otherwise. 642 * Returns 1 (TRUE) if it is a 'type' device, 0 otherwise.
641 */ 643 */
@@ -657,7 +659,7 @@ edd_dev_is_type(struct edd_device *edev, const char *type)
657 659
658/** 660/**
659 * edd_get_pci_dev() - finds pci_dev that matches edev 661 * edd_get_pci_dev() - finds pci_dev that matches edev
660 * @edev - edd_device 662 * @edev: edd_device
661 * 663 *
662 * Returns pci_dev if found, or NULL 664 * Returns pci_dev if found, or NULL
663 */ 665 */
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 4ee56def61f..214fbb1423c 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -308,7 +308,7 @@ static int dbg_tps_open(struct inode *inode, struct file *file)
308 return single_open(file, dbg_show, inode->i_private); 308 return single_open(file, dbg_show, inode->i_private);
309} 309}
310 310
311static struct file_operations debug_fops = { 311static const struct file_operations debug_fops = {
312 .open = dbg_tps_open, 312 .open = dbg_tps_open,
313 .read = seq_read, 313 .read = seq_read,
314 .llseek = seq_lseek, 314 .llseek = seq_lseek,
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index ac5bd2a7ca9..cb4fa9bef8c 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -392,7 +392,7 @@ static int i2cdev_release(struct inode *inode, struct file *file)
392 return 0; 392 return 0;
393} 393}
394 394
395static struct file_operations i2cdev_fops = { 395static const struct file_operations i2cdev_fops = {
396 .owner = THIS_MODULE, 396 .owner = THIS_MODULE,
397 .llseek = no_llseek, 397 .llseek = no_llseek,
398 .read = i2cdev_read, 398 .read = i2cdev_read,
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index aa049dab3d9..30a5780f418 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -413,7 +413,6 @@ void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void
413 while (p->name != NULL) { 413 while (p->name != NULL) {
414 ent = create_proc_entry(p->name, p->mode, dir); 414 ent = create_proc_entry(p->name, p->mode, dir);
415 if (!ent) return; 415 if (!ent) return;
416 ent->nlink = 1;
417 ent->data = data; 416 ent->data = data;
418 ent->read_proc = p->read_proc; 417 ent->read_proc = p->read_proc;
419 ent->write_proc = p->write_proc; 418 ent->write_proc = p->write_proc;
@@ -549,7 +548,7 @@ static int ide_drivers_open(struct inode *inode, struct file *file)
549 return single_open(file, &ide_drivers_show, NULL); 548 return single_open(file, &ide_drivers_show, NULL);
550} 549}
551 550
552static struct file_operations ide_drivers_operations = { 551static const struct file_operations ide_drivers_operations = {
553 .open = ide_drivers_open, 552 .open = ide_drivers_open,
554 .read = seq_read, 553 .read = seq_read,
555 .llseek = seq_lseek, 554 .llseek = seq_lseek,
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index b3bcd1d7315..c6eec0413a6 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -4779,7 +4779,7 @@ static ide_driver_t idetape_driver = {
4779/* 4779/*
4780 * Our character device supporting functions, passed to register_chrdev. 4780 * Our character device supporting functions, passed to register_chrdev.
4781 */ 4781 */
4782static struct file_operations idetape_fops = { 4782static const struct file_operations idetape_fops = {
4783 .owner = THIS_MODULE, 4783 .owner = THIS_MODULE,
4784 .read = idetape_chrdev_read, 4784 .read = idetape_chrdev_read,
4785 .write = idetape_chrdev_write, 4785 .write = idetape_chrdev_write,
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index 55d6ae664fd..dee9529aa8e 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -2147,7 +2147,7 @@ out:
2147} 2147}
2148 2148
2149static struct cdev dv1394_cdev; 2149static struct cdev dv1394_cdev;
2150static struct file_operations dv1394_fops= 2150static const struct file_operations dv1394_fops=
2151{ 2151{
2152 .owner = THIS_MODULE, 2152 .owner = THIS_MODULE,
2153 .poll = dv1394_poll, 2153 .poll = dv1394_poll,
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index a77a832828c..aa9ca8385ec 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -3013,7 +3013,7 @@ static struct hpsb_highlevel raw1394_highlevel = {
3013}; 3013};
3014 3014
3015static struct cdev raw1394_cdev; 3015static struct cdev raw1394_cdev;
3016static struct file_operations raw1394_fops = { 3016static const struct file_operations raw1394_fops = {
3017 .owner = THIS_MODULE, 3017 .owner = THIS_MODULE,
3018 .read = raw1394_read, 3018 .read = raw1394_read,
3019 .write = raw1394_write, 3019 .write = raw1394_write,
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index f4d1ec00af6..95ca26d7527 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -1277,7 +1277,7 @@ static long video1394_compat_ioctl(struct file *f, unsigned cmd, unsigned long a
1277#endif 1277#endif
1278 1278
1279static struct cdev video1394_cdev; 1279static struct cdev video1394_cdev;
1280static struct file_operations video1394_fops= 1280static const struct file_operations video1394_fops=
1281{ 1281{
1282 .owner = THIS_MODULE, 1282 .owner = THIS_MODULE,
1283 .unlocked_ioctl = video1394_ioctl, 1283 .unlocked_ioctl = video1394_ioctl,
diff --git a/drivers/infiniband/core/ucm.c b/drivers/infiniband/core/ucm.c
index f15220a0ee7..ee51d79a7ad 100644
--- a/drivers/infiniband/core/ucm.c
+++ b/drivers/infiniband/core/ucm.c
@@ -1221,7 +1221,7 @@ static void ib_ucm_release_class_dev(struct class_device *class_dev)
1221 kfree(dev); 1221 kfree(dev);
1222} 1222}
1223 1223
1224static struct file_operations ucm_fops = { 1224static const struct file_operations ucm_fops = {
1225 .owner = THIS_MODULE, 1225 .owner = THIS_MODULE,
1226 .open = ib_ucm_open, 1226 .open = ib_ucm_open,
1227 .release = ib_ucm_close, 1227 .release = ib_ucm_close,
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c
index e2e8d329b44..6b81b98961c 100644
--- a/drivers/infiniband/core/ucma.c
+++ b/drivers/infiniband/core/ucma.c
@@ -833,7 +833,7 @@ static int ucma_close(struct inode *inode, struct file *filp)
833 return 0; 833 return 0;
834} 834}
835 835
836static struct file_operations ucma_fops = { 836static const struct file_operations ucma_fops = {
837 .owner = THIS_MODULE, 837 .owner = THIS_MODULE,
838 .open = ucma_open, 838 .open = ucma_open,
839 .release = ucma_close, 839 .release = ucma_close,
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index 807fbd6b841..c069ebeba8e 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -771,7 +771,7 @@ static int ib_umad_close(struct inode *inode, struct file *filp)
771 return 0; 771 return 0;
772} 772}
773 773
774static struct file_operations umad_fops = { 774static const struct file_operations umad_fops = {
775 .owner = THIS_MODULE, 775 .owner = THIS_MODULE,
776 .read = ib_umad_read, 776 .read = ib_umad_read,
777 .write = ib_umad_write, 777 .write = ib_umad_write,
@@ -846,7 +846,7 @@ static int ib_umad_sm_close(struct inode *inode, struct file *filp)
846 return ret; 846 return ret;
847} 847}
848 848
849static struct file_operations umad_sm_fops = { 849static const struct file_operations umad_sm_fops = {
850 .owner = THIS_MODULE, 850 .owner = THIS_MODULE,
851 .open = ib_umad_sm_open, 851 .open = ib_umad_sm_open,
852 .release = ib_umad_sm_close 852 .release = ib_umad_sm_close
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index a617ca7b692..f8bc822a3cc 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -375,7 +375,7 @@ static int ib_uverbs_event_close(struct inode *inode, struct file *filp)
375 return 0; 375 return 0;
376} 376}
377 377
378static struct file_operations uverbs_event_fops = { 378static const struct file_operations uverbs_event_fops = {
379 .owner = THIS_MODULE, 379 .owner = THIS_MODULE,
380 .read = ib_uverbs_event_read, 380 .read = ib_uverbs_event_read,
381 .poll = ib_uverbs_event_poll, 381 .poll = ib_uverbs_event_poll,
@@ -679,14 +679,14 @@ static int ib_uverbs_close(struct inode *inode, struct file *filp)
679 return 0; 679 return 0;
680} 680}
681 681
682static struct file_operations uverbs_fops = { 682static const struct file_operations uverbs_fops = {
683 .owner = THIS_MODULE, 683 .owner = THIS_MODULE,
684 .write = ib_uverbs_write, 684 .write = ib_uverbs_write,
685 .open = ib_uverbs_open, 685 .open = ib_uverbs_open,
686 .release = ib_uverbs_close 686 .release = ib_uverbs_close
687}; 687};
688 688
689static struct file_operations uverbs_mmap_fops = { 689static const struct file_operations uverbs_mmap_fops = {
690 .owner = THIS_MODULE, 690 .owner = THIS_MODULE,
691 .write = ib_uverbs_write, 691 .write = ib_uverbs_write,
692 .mmap = ib_uverbs_mmap, 692 .mmap = ib_uverbs_mmap,
diff --git a/drivers/infiniband/hw/ehca/ehca_cq.c b/drivers/infiniband/hw/ehca/ehca_cq.c
index 9291a86ca05..6ebfa27e4e1 100644
--- a/drivers/infiniband/hw/ehca/ehca_cq.c
+++ b/drivers/infiniband/hw/ehca/ehca_cq.c
@@ -134,14 +134,13 @@ struct ib_cq *ehca_create_cq(struct ib_device *device, int cqe,
134 if (cqe >= 0xFFFFFFFF - 64 - additional_cqe) 134 if (cqe >= 0xFFFFFFFF - 64 - additional_cqe)
135 return ERR_PTR(-EINVAL); 135 return ERR_PTR(-EINVAL);
136 136
137 my_cq = kmem_cache_alloc(cq_cache, GFP_KERNEL); 137 my_cq = kmem_cache_zalloc(cq_cache, GFP_KERNEL);
138 if (!my_cq) { 138 if (!my_cq) {
139 ehca_err(device, "Out of memory for ehca_cq struct device=%p", 139 ehca_err(device, "Out of memory for ehca_cq struct device=%p",
140 device); 140 device);
141 return ERR_PTR(-ENOMEM); 141 return ERR_PTR(-ENOMEM);
142 } 142 }
143 143
144 memset(my_cq, 0, sizeof(struct ehca_cq));
145 memset(&param, 0, sizeof(struct ehca_alloc_cq_parms)); 144 memset(&param, 0, sizeof(struct ehca_alloc_cq_parms));
146 145
147 spin_lock_init(&my_cq->spinlock); 146 spin_lock_init(&my_cq->spinlock);
diff --git a/drivers/infiniband/hw/ehca/ehca_mrmw.c b/drivers/infiniband/hw/ehca/ehca_mrmw.c
index cfb362a1029..d22ab563633 100644
--- a/drivers/infiniband/hw/ehca/ehca_mrmw.c
+++ b/drivers/infiniband/hw/ehca/ehca_mrmw.c
@@ -53,9 +53,8 @@ static struct ehca_mr *ehca_mr_new(void)
53{ 53{
54 struct ehca_mr *me; 54 struct ehca_mr *me;
55 55
56 me = kmem_cache_alloc(mr_cache, GFP_KERNEL); 56 me = kmem_cache_zalloc(mr_cache, GFP_KERNEL);
57 if (me) { 57 if (me) {
58 memset(me, 0, sizeof(struct ehca_mr));
59 spin_lock_init(&me->mrlock); 58 spin_lock_init(&me->mrlock);
60 } else 59 } else
61 ehca_gen_err("alloc failed"); 60 ehca_gen_err("alloc failed");
@@ -72,9 +71,8 @@ static struct ehca_mw *ehca_mw_new(void)
72{ 71{
73 struct ehca_mw *me; 72 struct ehca_mw *me;
74 73
75 me = kmem_cache_alloc(mw_cache, GFP_KERNEL); 74 me = kmem_cache_zalloc(mw_cache, GFP_KERNEL);
76 if (me) { 75 if (me) {
77 memset(me, 0, sizeof(struct ehca_mw));
78 spin_lock_init(&me->mwlock); 76 spin_lock_init(&me->mwlock);
79 } else 77 } else
80 ehca_gen_err("alloc failed"); 78 ehca_gen_err("alloc failed");
diff --git a/drivers/infiniband/hw/ehca/ehca_pd.c b/drivers/infiniband/hw/ehca/ehca_pd.c
index d5345e5b3cd..79d0591a804 100644
--- a/drivers/infiniband/hw/ehca/ehca_pd.c
+++ b/drivers/infiniband/hw/ehca/ehca_pd.c
@@ -50,14 +50,13 @@ struct ib_pd *ehca_alloc_pd(struct ib_device *device,
50{ 50{
51 struct ehca_pd *pd; 51 struct ehca_pd *pd;
52 52
53 pd = kmem_cache_alloc(pd_cache, GFP_KERNEL); 53 pd = kmem_cache_zalloc(pd_cache, GFP_KERNEL);
54 if (!pd) { 54 if (!pd) {
55 ehca_err(device, "device=%p context=%p out of memory", 55 ehca_err(device, "device=%p context=%p out of memory",
56 device, context); 56 device, context);
57 return ERR_PTR(-ENOMEM); 57 return ERR_PTR(-ENOMEM);
58 } 58 }
59 59
60 memset(pd, 0, sizeof(struct ehca_pd));
61 pd->ownpid = current->tgid; 60 pd->ownpid = current->tgid;
62 61
63 /* 62 /*
diff --git a/drivers/infiniband/hw/ehca/ehca_qp.c b/drivers/infiniband/hw/ehca/ehca_qp.c
index 95efef921f1..df0516f2437 100644
--- a/drivers/infiniband/hw/ehca/ehca_qp.c
+++ b/drivers/infiniband/hw/ehca/ehca_qp.c
@@ -450,13 +450,12 @@ struct ib_qp *ehca_create_qp(struct ib_pd *pd,
450 if (pd->uobject && udata) 450 if (pd->uobject && udata)
451 context = pd->uobject->context; 451 context = pd->uobject->context;
452 452
453 my_qp = kmem_cache_alloc(qp_cache, GFP_KERNEL); 453 my_qp = kmem_cache_zalloc(qp_cache, GFP_KERNEL);
454 if (!my_qp) { 454 if (!my_qp) {
455 ehca_err(pd->device, "pd=%p not enough memory to alloc qp", pd); 455 ehca_err(pd->device, "pd=%p not enough memory to alloc qp", pd);
456 return ERR_PTR(-ENOMEM); 456 return ERR_PTR(-ENOMEM);
457 } 457 }
458 458
459 memset(my_qp, 0, sizeof(struct ehca_qp));
460 memset (&parms, 0, sizeof(struct ehca_alloc_qp_parms)); 459 memset (&parms, 0, sizeof(struct ehca_alloc_qp_parms));
461 spin_lock_init(&my_qp->spinlock_s); 460 spin_lock_init(&my_qp->spinlock_s);
462 spin_lock_init(&my_qp->spinlock_r); 461 spin_lock_init(&my_qp->spinlock_r);
diff --git a/drivers/infiniband/hw/ipath/ipath_diag.c b/drivers/infiniband/hw/ipath/ipath_diag.c
index 28c087b824c..0f13a2182cc 100644
--- a/drivers/infiniband/hw/ipath/ipath_diag.c
+++ b/drivers/infiniband/hw/ipath/ipath_diag.c
@@ -59,7 +59,7 @@ static ssize_t ipath_diag_read(struct file *fp, char __user *data,
59static ssize_t ipath_diag_write(struct file *fp, const char __user *data, 59static ssize_t ipath_diag_write(struct file *fp, const char __user *data,
60 size_t count, loff_t *off); 60 size_t count, loff_t *off);
61 61
62static struct file_operations diag_file_ops = { 62static const struct file_operations diag_file_ops = {
63 .owner = THIS_MODULE, 63 .owner = THIS_MODULE,
64 .write = ipath_diag_write, 64 .write = ipath_diag_write,
65 .read = ipath_diag_read, 65 .read = ipath_diag_read,
@@ -71,7 +71,7 @@ static ssize_t ipath_diagpkt_write(struct file *fp,
71 const char __user *data, 71 const char __user *data,
72 size_t count, loff_t *off); 72 size_t count, loff_t *off);
73 73
74static struct file_operations diagpkt_file_ops = { 74static const struct file_operations diagpkt_file_ops = {
75 .owner = THIS_MODULE, 75 .owner = THIS_MODULE,
76 .write = ipath_diagpkt_write, 76 .write = ipath_diagpkt_write,
77}; 77};
diff --git a/drivers/infiniband/hw/ipath/ipath_file_ops.c b/drivers/infiniband/hw/ipath/ipath_file_ops.c
index b932bcb67a5..5d64ff87529 100644
--- a/drivers/infiniband/hw/ipath/ipath_file_ops.c
+++ b/drivers/infiniband/hw/ipath/ipath_file_ops.c
@@ -54,7 +54,7 @@ static ssize_t ipath_write(struct file *, const char __user *, size_t,
54static unsigned int ipath_poll(struct file *, struct poll_table_struct *); 54static unsigned int ipath_poll(struct file *, struct poll_table_struct *);
55static int ipath_mmap(struct file *, struct vm_area_struct *); 55static int ipath_mmap(struct file *, struct vm_area_struct *);
56 56
57static struct file_operations ipath_file_ops = { 57static const struct file_operations ipath_file_ops = {
58 .owner = THIS_MODULE, 58 .owner = THIS_MODULE,
59 .write = ipath_write, 59 .write = ipath_write,
60 .open = ipath_open, 60 .open = ipath_open,
@@ -2153,7 +2153,7 @@ bail:
2153 2153
2154static struct class *ipath_class; 2154static struct class *ipath_class;
2155 2155
2156static int init_cdev(int minor, char *name, struct file_operations *fops, 2156static int init_cdev(int minor, char *name, const struct file_operations *fops,
2157 struct cdev **cdevp, struct class_device **class_devp) 2157 struct cdev **cdevp, struct class_device **class_devp)
2158{ 2158{
2159 const dev_t dev = MKDEV(IPATH_MAJOR, minor); 2159 const dev_t dev = MKDEV(IPATH_MAJOR, minor);
@@ -2210,7 +2210,7 @@ done:
2210 return ret; 2210 return ret;
2211} 2211}
2212 2212
2213int ipath_cdev_init(int minor, char *name, struct file_operations *fops, 2213int ipath_cdev_init(int minor, char *name, const struct file_operations *fops,
2214 struct cdev **cdevp, struct class_device **class_devp) 2214 struct cdev **cdevp, struct class_device **class_devp)
2215{ 2215{
2216 return init_cdev(minor, name, fops, cdevp, class_devp); 2216 return init_cdev(minor, name, fops, cdevp, class_devp);
diff --git a/drivers/infiniband/hw/ipath/ipath_fs.c b/drivers/infiniband/hw/ipath/ipath_fs.c
index 79a60f020a2..5b40a846ff9 100644
--- a/drivers/infiniband/hw/ipath/ipath_fs.c
+++ b/drivers/infiniband/hw/ipath/ipath_fs.c
@@ -47,7 +47,7 @@
47static struct super_block *ipath_super; 47static struct super_block *ipath_super;
48 48
49static int ipathfs_mknod(struct inode *dir, struct dentry *dentry, 49static int ipathfs_mknod(struct inode *dir, struct dentry *dentry,
50 int mode, struct file_operations *fops, 50 int mode, const struct file_operations *fops,
51 void *data) 51 void *data)
52{ 52{
53 int error; 53 int error;
@@ -81,7 +81,7 @@ bail:
81 81
82static int create_file(const char *name, mode_t mode, 82static int create_file(const char *name, mode_t mode,
83 struct dentry *parent, struct dentry **dentry, 83 struct dentry *parent, struct dentry **dentry,
84 struct file_operations *fops, void *data) 84 const struct file_operations *fops, void *data)
85{ 85{
86 int error; 86 int error;
87 87
@@ -105,7 +105,7 @@ static ssize_t atomic_stats_read(struct file *file, char __user *buf,
105 sizeof ipath_stats); 105 sizeof ipath_stats);
106} 106}
107 107
108static struct file_operations atomic_stats_ops = { 108static const struct file_operations atomic_stats_ops = {
109 .read = atomic_stats_read, 109 .read = atomic_stats_read,
110}; 110};
111 111
@@ -127,7 +127,7 @@ static ssize_t atomic_counters_read(struct file *file, char __user *buf,
127 sizeof counters); 127 sizeof counters);
128} 128}
129 129
130static struct file_operations atomic_counters_ops = { 130static const struct file_operations atomic_counters_ops = {
131 .read = atomic_counters_read, 131 .read = atomic_counters_read,
132}; 132};
133 133
@@ -166,7 +166,7 @@ static ssize_t atomic_node_info_read(struct file *file, char __user *buf,
166 sizeof nodeinfo); 166 sizeof nodeinfo);
167} 167}
168 168
169static struct file_operations atomic_node_info_ops = { 169static const struct file_operations atomic_node_info_ops = {
170 .read = atomic_node_info_read, 170 .read = atomic_node_info_read,
171}; 171};
172 172
@@ -291,7 +291,7 @@ static ssize_t atomic_port_info_read(struct file *file, char __user *buf,
291 sizeof portinfo); 291 sizeof portinfo);
292} 292}
293 293
294static struct file_operations atomic_port_info_ops = { 294static const struct file_operations atomic_port_info_ops = {
295 .read = atomic_port_info_read, 295 .read = atomic_port_info_read,
296}; 296};
297 297
@@ -394,7 +394,7 @@ bail:
394 return ret; 394 return ret;
395} 395}
396 396
397static struct file_operations flash_ops = { 397static const struct file_operations flash_ops = {
398 .read = flash_read, 398 .read = flash_read,
399 .write = flash_write, 399 .write = flash_write,
400}; 400};
diff --git a/drivers/infiniband/hw/ipath/ipath_kernel.h b/drivers/infiniband/hw/ipath/ipath_kernel.h
index 986b2125b8f..6d8d05fb599 100644
--- a/drivers/infiniband/hw/ipath/ipath_kernel.h
+++ b/drivers/infiniband/hw/ipath/ipath_kernel.h
@@ -593,7 +593,7 @@ void ipath_shutdown_device(struct ipath_devdata *);
593void ipath_disarm_senderrbufs(struct ipath_devdata *); 593void ipath_disarm_senderrbufs(struct ipath_devdata *);
594 594
595struct file_operations; 595struct file_operations;
596int ipath_cdev_init(int minor, char *name, struct file_operations *fops, 596int ipath_cdev_init(int minor, char *name, const struct file_operations *fops,
597 struct cdev **cdevp, struct class_device **class_devp); 597 struct cdev **cdevp, struct class_device **class_devp);
598void ipath_cdev_cleanup(struct cdev **cdevp, 598void ipath_cdev_cleanup(struct cdev **cdevp,
599 struct class_device **class_devp); 599 struct class_device **class_devp);
diff --git a/drivers/infiniband/ulp/ipoib/ipoib_fs.c b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
index f1cb83688b3..44c174182a8 100644
--- a/drivers/infiniband/ulp/ipoib/ipoib_fs.c
+++ b/drivers/infiniband/ulp/ipoib/ipoib_fs.c
@@ -146,7 +146,7 @@ static int ipoib_mcg_open(struct inode *inode, struct file *file)
146 return 0; 146 return 0;
147} 147}
148 148
149static struct file_operations ipoib_mcg_fops = { 149static const struct file_operations ipoib_mcg_fops = {
150 .owner = THIS_MODULE, 150 .owner = THIS_MODULE,
151 .open = ipoib_mcg_open, 151 .open = ipoib_mcg_open,
152 .read = seq_read, 152 .read = seq_read,
@@ -252,7 +252,7 @@ static int ipoib_path_open(struct inode *inode, struct file *file)
252 return 0; 252 return 0;
253} 253}
254 254
255static struct file_operations ipoib_path_fops = { 255static const struct file_operations ipoib_path_fops = {
256 .owner = THIS_MODULE, 256 .owner = THIS_MODULE,
257 .open = ipoib_path_open, 257 .open = ipoib_path_open,
258 .read = seq_read, 258 .read = seq_read,
diff --git a/drivers/input/gameport/ns558.c b/drivers/input/gameport/ns558.c
index f68dbe6f7f0..7b7a546323c 100644
--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -151,7 +151,6 @@ static int ns558_isa_probe(int io)
151 return -ENOMEM; 151 return -ENOMEM;
152 } 152 }
153 153
154 memset(ns558, 0, sizeof(struct ns558));
155 ns558->io = io; 154 ns558->io = io;
156 ns558->size = 1 << i; 155 ns558->size = 1 << i;
157 ns558->gameport = port; 156 ns558->gameport = port;
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 7cf2b4f603a..14d4c0493c3 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -482,7 +482,7 @@ static int input_proc_devices_open(struct inode *inode, struct file *file)
482 return seq_open(file, &input_devices_seq_ops); 482 return seq_open(file, &input_devices_seq_ops);
483} 483}
484 484
485static struct file_operations input_devices_fileops = { 485static const struct file_operations input_devices_fileops = {
486 .owner = THIS_MODULE, 486 .owner = THIS_MODULE,
487 .open = input_proc_devices_open, 487 .open = input_proc_devices_open,
488 .poll = input_proc_devices_poll, 488 .poll = input_proc_devices_poll,
@@ -533,7 +533,7 @@ static int input_proc_handlers_open(struct inode *inode, struct file *file)
533 return seq_open(file, &input_handlers_seq_ops); 533 return seq_open(file, &input_handlers_seq_ops);
534} 534}
535 535
536static struct file_operations input_handlers_fileops = { 536static const struct file_operations input_handlers_fileops = {
537 .owner = THIS_MODULE, 537 .owner = THIS_MODULE,
538 .open = input_proc_handlers_open, 538 .open = input_proc_handlers_open,
539 .read = seq_read, 539 .read = seq_read,
@@ -1142,7 +1142,7 @@ static int input_open_file(struct inode *inode, struct file *file)
1142 return err; 1142 return err;
1143} 1143}
1144 1144
1145static struct file_operations input_fops = { 1145static const struct file_operations input_fops = {
1146 .owner = THIS_MODULE, 1146 .owner = THIS_MODULE,
1147 .open = input_open_file, 1147 .open = input_open_file,
1148}; 1148};
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 049f2f544e7..1b81a72e19d 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -135,12 +135,12 @@ config KEYBOARD_STOWAWAY
135config KEYBOARD_CORGI 135config KEYBOARD_CORGI
136 tristate "Corgi keyboard" 136 tristate "Corgi keyboard"
137 depends on PXA_SHARPSL 137 depends on PXA_SHARPSL
138 default y 138 default y
139 help 139 help
140 Say Y here to enable the keyboard on the Sharp Zaurus SL-C7xx 140 Say Y here to enable the keyboard on the Sharp Zaurus SL-C7xx
141 series of PDAs. 141 series of PDAs.
142 142
143 To compile this driver as a module, choose M here: the 143 To compile this driver as a module, choose M here: the
144 module will be called corgikbd. 144 module will be called corgikbd.
145 145
146config KEYBOARD_SPITZ 146config KEYBOARD_SPITZ
@@ -214,4 +214,17 @@ config KEYBOARD_AAED2000
214 To compile this driver as a module, choose M here: the 214 To compile this driver as a module, choose M here: the
215 module will be called aaed2000_kbd. 215 module will be called aaed2000_kbd.
216 216
217config KEYBOARD_GPIO
218 tristate "Buttons on CPU GPIOs (PXA)"
219 depends on ARCH_PXA
220 help
221 This driver implements support for buttons connected
222 directly to GPIO pins of PXA CPUs.
223
224 Say Y here if your device has buttons connected
225 directly to GPIO pins of the CPU.
226
227 To compile this driver as a module, choose M here: the
228 module will be called gpio-keys.
229
217endif 230endif
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 56879790734..586a0fe53be 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o
16obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o 16obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o
17obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o 17obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
18obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o 18obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
19obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o 19obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o
20obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o 20obj-$(CONFIG_KEYBOARD_AAED2000) += aaed2000_kbd.o
21obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
21 22
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
new file mode 100644
index 00000000000..3a8f1b427a7
--- /dev/null
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -0,0 +1,147 @@
1/*
2 * Driver for keys on GPIO lines capable of generating interrupts.
3 *
4 * Copyright 2005 Phil Blundell
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#include <linux/module.h>
12#include <linux/version.h>
13
14#include <linux/init.h>
15#include <linux/fs.h>
16#include <linux/interrupt.h>
17#include <linux/irq.h>
18#include <linux/sched.h>
19#include <linux/pm.h>
20#include <linux/sysctl.h>
21#include <linux/proc_fs.h>
22#include <linux/delay.h>
23#include <linux/platform_device.h>
24#include <linux/input.h>
25#include <linux/irq.h>
26
27#include <asm/arch/pxa-regs.h>
28#include <asm/arch/hardware.h>
29
30#include <asm/hardware/gpio_keys.h>
31
32static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
33{
34 int i;
35 struct platform_device *pdev = dev_id;
36 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
37 struct input_dev *input = platform_get_drvdata(pdev);
38
39 for (i = 0; i < pdata->nbuttons; i++) {
40 int gpio = pdata->buttons[i].gpio;
41 if (irq == IRQ_GPIO(gpio)) {
42 int state = ((GPLR(gpio) & GPIO_bit(gpio)) ? 1 : 0) ^ (pdata->buttons[i].active_low);
43
44 input_report_key(input, pdata->buttons[i].keycode, state);
45 input_sync(input);
46 }
47 }
48
49 return IRQ_HANDLED;
50}
51
52static int __devinit gpio_keys_probe(struct platform_device *pdev)
53{
54 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
55 struct input_dev *input;
56 int i, error;
57
58 input = input_allocate_device();
59 if (!input)
60 return -ENOMEM;
61
62 platform_set_drvdata(pdev, input);
63
64 input->evbit[0] = BIT(EV_KEY);
65
66 input->name = pdev->name;
67 input->phys = "gpio-keys/input0";
68 input->cdev.dev = &pdev->dev;
69 input->private = pdata;
70
71 input->id.bustype = BUS_HOST;
72 input->id.vendor = 0x0001;
73 input->id.product = 0x0001;
74 input->id.version = 0x0100;
75
76 for (i = 0; i < pdata->nbuttons; i++) {
77 int code = pdata->buttons[i].keycode;
78 int irq = IRQ_GPIO(pdata->buttons[i].gpio);
79
80 set_irq_type(irq, IRQ_TYPE_EDGE_BOTH);
81 error = request_irq(irq, gpio_keys_isr, SA_SAMPLE_RANDOM,
82 pdata->buttons[i].desc ? pdata->buttons[i].desc : "gpio_keys",
83 pdev);
84 if (error) {
85 printk(KERN_ERR "gpio-keys: unable to claim irq %d; error %d\n", irq, ret);
86 goto fail;
87 }
88 set_bit(code, input->keybit);
89 }
90
91 error = input_register_device(input);
92 if (error) {
93 printk(KERN_ERR "Unable to register gpio-keys input device\n");
94 goto fail;
95 }
96
97 return 0;
98
99 fail:
100 for (i = i - 1; i >= 0; i--)
101 free_irq(IRQ_GPIO(pdata->buttons[i].gpio), pdev);
102
103 input_free_device(input);
104
105 return error;
106}
107
108static int __devexit gpio_keys_remove(struct platform_device *pdev)
109{
110 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data;
111 struct input_dev *input = platform_get_drvdata(pdev);
112 int i;
113
114 for (i = 0; i < pdata->nbuttons; i++) {
115 int irq = IRQ_GPIO(pdata->buttons[i].gpio);
116 free_irq(irq, pdev);
117 }
118
119 input_unregister_device(input);
120
121 return 0;
122}
123
124struct platform_driver gpio_keys_device_driver = {
125 .probe = gpio_keys_probe,
126 .remove = __devexit_p(gpio_keys_remove),
127 .driver = {
128 .name = "gpio-keys",
129 }
130};
131
132static int __init gpio_keys_init(void)
133{
134 return platform_driver_register(&gpio_keys_device_driver);
135}
136
137static void __exit gpio_keys_exit(void)
138{
139 platform_driver_unregister(&gpio_keys_device_driver);
140}
141
142module_init(gpio_keys_init);
143module_exit(gpio_keys_exit);
144
145MODULE_LICENSE("GPL");
146MODULE_AUTHOR("Phil Blundell <pb@handhelds.org>");
147MODULE_DESCRIPTION("Keyboard driver for CPU GPIOs");
diff --git a/drivers/input/keyboard/hilkbd.c b/drivers/input/keyboard/hilkbd.c
index 35461eab2fa..255a6ec75a4 100644
--- a/drivers/input/keyboard/hilkbd.c
+++ b/drivers/input/keyboard/hilkbd.c
@@ -6,10 +6,10 @@
6 * Copyright (C) 1999-2006 Helge Deller <deller@gmx.de> 6 * Copyright (C) 1999-2006 Helge Deller <deller@gmx.de>
7 * 7 *
8 * Very basic HP Human Interface Loop (HIL) driver. 8 * Very basic HP Human Interface Loop (HIL) driver.
9 * This driver handles the keyboard on HP300 (m68k) and on some 9 * This driver handles the keyboard on HP300 (m68k) and on some
10 * HP700 (parisc) series machines. 10 * HP700 (parisc) series machines.
11 * 11 *
12 * 12 *
13 * This file is subject to the terms and conditions of the GNU General Public 13 * This file is subject to the terms and conditions of the GNU General Public
14 * License version 2. See the file COPYING in the main directory of this 14 * License version 2. See the file COPYING in the main directory of this
15 * archive for more details. 15 * archive for more details.
@@ -64,9 +64,9 @@ MODULE_LICENSE("GPL v2");
64#endif 64#endif
65 65
66 66
67 67
68/* HIL helper functions */ 68/* HIL helper functions */
69 69
70#define hil_busy() (hil_readb(HILBASE + HIL_CMD) & HIL_BUSY) 70#define hil_busy() (hil_readb(HILBASE + HIL_CMD) & HIL_BUSY)
71#define hil_data_available() (hil_readb(HILBASE + HIL_CMD) & HIL_DATA_RDY) 71#define hil_data_available() (hil_readb(HILBASE + HIL_CMD) & HIL_DATA_RDY)
72#define hil_status() (hil_readb(HILBASE + HIL_CMD)) 72#define hil_status() (hil_readb(HILBASE + HIL_CMD))
@@ -75,7 +75,7 @@ MODULE_LICENSE("GPL v2");
75#define hil_write_data(x) do { hil_writeb((x), HILBASE + HIL_DATA); } while (0) 75#define hil_write_data(x) do { hil_writeb((x), HILBASE + HIL_DATA); } while (0)
76 76
77/* HIL constants */ 77/* HIL constants */
78 78
79#define HIL_BUSY 0x02 79#define HIL_BUSY 0x02
80#define HIL_DATA_RDY 0x01 80#define HIL_DATA_RDY 0x01
81 81
@@ -86,10 +86,10 @@ MODULE_LICENSE("GPL v2");
86#define HIL_INTON 0x5C /* Turn on interrupts. */ 86#define HIL_INTON 0x5C /* Turn on interrupts. */
87#define HIL_INTOFF 0x5D /* Turn off interrupts. */ 87#define HIL_INTOFF 0x5D /* Turn off interrupts. */
88 88
89#define HIL_READKBDSADR 0xF9 89#define HIL_READKBDSADR 0xF9
90#define HIL_WRITEKBDSADR 0xE9 90#define HIL_WRITEKBDSADR 0xE9
91 91
92static unsigned int hphilkeyb_keycode[HIL_KEYCODES_SET1_TBLSIZE] = 92static unsigned int hphilkeyb_keycode[HIL_KEYCODES_SET1_TBLSIZE] =
93 { HIL_KEYCODES_SET1 }; 93 { HIL_KEYCODES_SET1 };
94 94
95/* HIL structure */ 95/* HIL structure */
@@ -97,11 +97,11 @@ static struct {
97 struct input_dev *dev; 97 struct input_dev *dev;
98 98
99 unsigned int curdev; 99 unsigned int curdev;
100 100
101 unsigned char s; 101 unsigned char s;
102 unsigned char c; 102 unsigned char c;
103 int valid; 103 int valid;
104 104
105 unsigned char data[16]; 105 unsigned char data[16];
106 unsigned int ptr; 106 unsigned int ptr;
107 spinlock_t lock; 107 spinlock_t lock;
@@ -115,7 +115,7 @@ static void poll_finished(void)
115 int down; 115 int down;
116 int key; 116 int key;
117 unsigned char scode; 117 unsigned char scode;
118 118
119 switch (hil_dev.data[0]) { 119 switch (hil_dev.data[0]) {
120 case 0x40: 120 case 0x40:
121 down = (hil_dev.data[1] & 1) == 0; 121 down = (hil_dev.data[1] & 1) == 0;
@@ -127,6 +127,7 @@ static void poll_finished(void)
127 hil_dev.curdev = 0; 127 hil_dev.curdev = 0;
128} 128}
129 129
130
130static inline void handle_status(unsigned char s, unsigned char c) 131static inline void handle_status(unsigned char s, unsigned char c)
131{ 132{
132 if (c & 0x8) { 133 if (c & 0x8) {
@@ -143,6 +144,7 @@ static inline void handle_status(unsigned char s, unsigned char c)
143 } 144 }
144} 145}
145 146
147
146static inline void handle_data(unsigned char s, unsigned char c) 148static inline void handle_data(unsigned char s, unsigned char c)
147{ 149{
148 if (hil_dev.curdev) { 150 if (hil_dev.curdev) {
@@ -152,13 +154,11 @@ static inline void handle_data(unsigned char s, unsigned char c)
152} 154}
153 155
154 156
155/* 157/* handle HIL interrupts */
156 * Handle HIL interrupts.
157 */
158static irqreturn_t hil_interrupt(int irq, void *handle) 158static irqreturn_t hil_interrupt(int irq, void *handle)
159{ 159{
160 unsigned char s, c; 160 unsigned char s, c;
161 161
162 s = hil_status(); 162 s = hil_status();
163 c = hil_read_data(); 163 c = hil_read_data();
164 164
@@ -179,10 +179,8 @@ static irqreturn_t hil_interrupt(int irq, void *handle)
179 return IRQ_HANDLED; 179 return IRQ_HANDLED;
180} 180}
181 181
182/*
183 * Send a command to the HIL
184 */
185 182
183/* send a command to the HIL */
186static void hil_do(unsigned char cmd, unsigned char *data, unsigned int len) 184static void hil_do(unsigned char cmd, unsigned char *data, unsigned int len)
187{ 185{
188 unsigned long flags; 186 unsigned long flags;
@@ -200,16 +198,14 @@ static void hil_do(unsigned char cmd, unsigned char *data, unsigned int len)
200} 198}
201 199
202 200
203/* 201/* initialise HIL */
204 * Initialise HIL.
205 */
206
207static int __init 202static int __init
208hil_keyb_init(void) 203hil_keyb_init(void)
209{ 204{
210 unsigned char c; 205 unsigned char c;
211 unsigned int i, kbid; 206 unsigned int i, kbid;
212 wait_queue_head_t hil_wait; 207 wait_queue_head_t hil_wait;
208 int err;
213 209
214 if (hil_dev.dev) { 210 if (hil_dev.dev) {
215 return -ENODEV; /* already initialized */ 211 return -ENODEV; /* already initialized */
@@ -219,15 +215,25 @@ hil_keyb_init(void)
219 if (!hil_dev.dev) 215 if (!hil_dev.dev)
220 return -ENOMEM; 216 return -ENOMEM;
221 hil_dev.dev->private = &hil_dev; 217 hil_dev.dev->private = &hil_dev;
222 218
223#if defined(CONFIG_HP300) 219#if defined(CONFIG_HP300)
224 if (!hwreg_present((void *)(HILBASE + HIL_DATA))) 220 if (!hwreg_present((void *)(HILBASE + HIL_DATA))) {
225 return -ENODEV; 221 printk(KERN_ERR "HIL: hardware register was not found\n");
226 222 err = -ENODEV;
227 request_region(HILBASE+HIL_DATA, 2, "hil"); 223 goto err1;
224 }
225 if (!request_region(HILBASE + HIL_DATA, 2, "hil")) {
226 printk(KERN_ERR "HIL: IOPORT region already used\n");
227 err = -EIO;
228 goto err1;
229 }
228#endif 230#endif
229 231
230 request_irq(HIL_IRQ, hil_interrupt, 0, "hil", hil_dev.dev_id); 232 err = request_irq(HIL_IRQ, hil_interrupt, 0, "hil", hil_dev.dev_id);
233 if (err) {
234 printk(KERN_ERR "HIL: Can't get IRQ\n");
235 goto err2;
236 }
231 237
232 /* Turn on interrupts */ 238 /* Turn on interrupts */
233 hil_do(HIL_INTON, NULL, 0); 239 hil_do(HIL_INTON, NULL, 0);
@@ -239,47 +245,63 @@ hil_keyb_init(void)
239 init_waitqueue_head(&hil_wait); 245 init_waitqueue_head(&hil_wait);
240 wait_event_interruptible_timeout(hil_wait, hil_dev.valid, 3*HZ); 246 wait_event_interruptible_timeout(hil_wait, hil_dev.valid, 3*HZ);
241 if (!hil_dev.valid) { 247 if (!hil_dev.valid) {
242 printk(KERN_WARNING "HIL: timed out, assuming no keyboard present.\n"); 248 printk(KERN_WARNING "HIL: timed out, assuming no keyboard present\n");
243 } 249 }
244 250
245 c = hil_dev.c; 251 c = hil_dev.c;
246 hil_dev.valid = 0; 252 hil_dev.valid = 0;
247 if (c == 0) { 253 if (c == 0) {
248 kbid = -1; 254 kbid = -1;
249 printk(KERN_WARNING "HIL: no keyboard present.\n"); 255 printk(KERN_WARNING "HIL: no keyboard present\n");
250 } else { 256 } else {
251 kbid = ffz(~c); 257 kbid = ffz(~c);
252 /* printk(KERN_INFO "HIL: keyboard found at id %d\n", kbid); */ 258 printk(KERN_INFO "HIL: keyboard found at id %d\n", kbid);
253 } 259 }
254 260
255 /* set it to raw mode */ 261 /* set it to raw mode */
256 c = 0; 262 c = 0;
257 hil_do(HIL_WRITEKBDSADR, &c, 1); 263 hil_do(HIL_WRITEKBDSADR, &c, 1);
258 264
259 for (i = 0; i < HIL_KEYCODES_SET1_TBLSIZE; i++) 265 for (i = 0; i < HIL_KEYCODES_SET1_TBLSIZE; i++)
260 if (hphilkeyb_keycode[i] != KEY_RESERVED) 266 if (hphilkeyb_keycode[i] != KEY_RESERVED)
261 set_bit(hphilkeyb_keycode[i], hil_dev.dev->keybit); 267 set_bit(hphilkeyb_keycode[i], hil_dev.dev->keybit);
262 268
263 hil_dev.dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); 269 hil_dev.dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP);
264 hil_dev.dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL); 270 hil_dev.dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL);
265 hil_dev.dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE; 271 hil_dev.dev->keycodemax = HIL_KEYCODES_SET1_TBLSIZE;
266 hil_dev.dev->keycodesize = sizeof(hphilkeyb_keycode[0]); 272 hil_dev.dev->keycodesize= sizeof(hphilkeyb_keycode[0]);
267 hil_dev.dev->keycode = hphilkeyb_keycode; 273 hil_dev.dev->keycode = hphilkeyb_keycode;
268 hil_dev.dev->name = "HIL keyboard"; 274 hil_dev.dev->name = "HIL keyboard";
269 hil_dev.dev->phys = "hpkbd/input0"; 275 hil_dev.dev->phys = "hpkbd/input0";
270 276
271 hil_dev.dev->id.bustype = BUS_HIL; 277 hil_dev.dev->id.bustype = BUS_HIL;
272 hil_dev.dev->id.vendor = PCI_VENDOR_ID_HP; 278 hil_dev.dev->id.vendor = PCI_VENDOR_ID_HP;
273 hil_dev.dev->id.product = 0x0001; 279 hil_dev.dev->id.product = 0x0001;
274 hil_dev.dev->id.version = 0x0010; 280 hil_dev.dev->id.version = 0x0010;
275 281
276 input_register_device(hil_dev.dev); 282 err = input_register_device(hil_dev.dev);
283 if (err) {
284 printk(KERN_ERR "HIL: Can't register device\n");
285 goto err3;
286 }
277 printk(KERN_INFO "input: %s, ID %d at 0x%08lx (irq %d) found and attached\n", 287 printk(KERN_INFO "input: %s, ID %d at 0x%08lx (irq %d) found and attached\n",
278 hil_dev.dev->name, kbid, HILBASE, HIL_IRQ); 288 hil_dev.dev->name, kbid, HILBASE, HIL_IRQ);
279 289
280 return 0; 290 return 0;
291
292err3:
293 hil_do(HIL_INTOFF, NULL, 0);
294 disable_irq(HIL_IRQ);
295 free_irq(HIL_IRQ, hil_dev.dev_id);
296err2:
297 release_region(HILBASE + HIL_DATA, 2);
298err1:
299 input_free_device(hil_dev.dev);
300 hil_dev.dev = NULL;
301 return err;
281} 302}
282 303
304
283#if defined(CONFIG_PARISC) 305#if defined(CONFIG_PARISC)
284static int __init 306static int __init
285hil_init_chip(struct parisc_device *dev) 307hil_init_chip(struct parisc_device *dev)
@@ -292,7 +314,7 @@ hil_init_chip(struct parisc_device *dev)
292 hil_base = dev->hpa.start; 314 hil_base = dev->hpa.start;
293 hil_irq = dev->irq; 315 hil_irq = dev->irq;
294 hil_dev.dev_id = dev; 316 hil_dev.dev_id = dev;
295 317
296 printk(KERN_INFO "Found HIL bus at 0x%08lx, IRQ %d\n", hil_base, hil_irq); 318 printk(KERN_INFO "Found HIL bus at 0x%08lx, IRQ %d\n", hil_base, hil_irq);
297 319
298 return hil_keyb_init(); 320 return hil_keyb_init();
@@ -313,9 +335,6 @@ static struct parisc_driver hil_driver = {
313#endif /* CONFIG_PARISC */ 335#endif /* CONFIG_PARISC */
314 336
315 337
316
317
318
319static int __init hil_init(void) 338static int __init hil_init(void)
320{ 339{
321#if defined(CONFIG_PARISC) 340#if defined(CONFIG_PARISC)
@@ -349,4 +368,3 @@ static void __exit hil_exit(void)
349 368
350module_init(hil_init); 369module_init(hil_init);
351module_exit(hil_exit); 370module_exit(hil_exit);
352
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index ba0e88c64e1..41b42587f5e 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -50,6 +50,16 @@ config INPUT_WISTRON_BTNS
50 To compile this driver as a module, choose M here: the module will 50 To compile this driver as a module, choose M here: the module will
51 be called wistron_btns. 51 be called wistron_btns.
52 52
53config INPUT_ATLAS_BTNS
54 tristate "x86 Atlas button interface"
55 depends on X86 && ACPI
56 help
57 Say Y here for support of Atlas wallmount touchscreen buttons.
58 The events will show up as scancodes F1 through F9 via evdev.
59
60 To compile this driver as a module, choose M here: the module will
61 be called atlas_btns.
62
53config INPUT_IXP4XX_BEEPER 63config INPUT_IXP4XX_BEEPER
54 tristate "IXP4XX Beeper support" 64 tristate "IXP4XX Beeper support"
55 depends on ARCH_IXP4XX 65 depends on ARCH_IXP4XX
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 415c4917898..e0a8d58c9e9 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -9,5 +9,6 @@ obj-$(CONFIG_INPUT_PCSPKR) += pcspkr.o
9obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o 9obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o
10obj-$(CONFIG_INPUT_UINPUT) += uinput.o 10obj-$(CONFIG_INPUT_UINPUT) += uinput.o
11obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o 11obj-$(CONFIG_INPUT_WISTRON_BTNS) += wistron_btns.o
12obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o
12obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o 13obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
13obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o 14obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o
diff --git a/drivers/input/misc/atlas_btns.c b/drivers/input/misc/atlas_btns.c
new file mode 100644
index 00000000000..0acc3a12360
--- /dev/null
+++ b/drivers/input/misc/atlas_btns.c
@@ -0,0 +1,170 @@
1/*
2 * atlas_btns.c - Atlas Wallmount Touchscreen ACPI Extras
3 *
4 * Copyright (C) 2006 Jaya Kumar
5 * Based on Toshiba ACPI by John Belmonte and ASUS ACPI
6 * This work was sponsored by CIS(M) Sdn Bhd.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/init.h>
27#include <linux/input.h>
28#include <linux/types.h>
29#include <asm/uaccess.h>
30#include <acpi/acpi_drivers.h>
31
32#define ACPI_ATLAS_NAME "Atlas ACPI"
33#define ACPI_ATLAS_CLASS "Atlas"
34#define ACPI_ATLAS_BUTTON_HID "ASIM0000"
35
36static struct input_dev *input_dev;
37
38/* button handling code */
39static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
40 u32 function, void *handler_context, void **return_context)
41{
42 *return_context =
43 (function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
44
45 return AE_OK;
46}
47
48static acpi_status acpi_atlas_button_handler(u32 function,
49 acpi_physical_address address,
50 u32 bit_width, acpi_integer *value,
51 void *handler_context, void *region_context)
52{
53 acpi_status status;
54 int keycode;
55
56 if (function == ACPI_WRITE) {
57 keycode = KEY_F1 + (address & 0x0F);
58 input_report_key(input_dev, keycode, !(address & 0x10));
59 input_sync(input_dev);
60 status = 0;
61 } else {
62 printk(KERN_WARNING "atlas: shrugged on unexpected function"
63 ":function=%x,address=%lx,value=%x\n",
64 function, (unsigned long)address, (u32)*value);
65 status = -EINVAL;
66 }
67
68 return status;
69}
70
71static int atlas_acpi_button_add(struct acpi_device *device)
72{
73 acpi_status status;
74 int err;
75
76 input_dev = input_allocate_device();
77 if (!input_dev) {
78 printk(KERN_ERR "atlas: unable to allocate input device\n");
79 return -ENOMEM;
80 }
81
82 input_dev->name = "Atlas ACPI button driver";
83 input_dev->phys = "ASIM0000/atlas/input0";
84 input_dev->id.bustype = BUS_HOST;
85 input_dev->evbit[LONG(EV_KEY)] = BIT(EV_KEY);
86
87 set_bit(KEY_F1, input_dev->keybit);
88 set_bit(KEY_F2, input_dev->keybit);
89 set_bit(KEY_F3, input_dev->keybit);
90 set_bit(KEY_F4, input_dev->keybit);
91 set_bit(KEY_F5, input_dev->keybit);
92 set_bit(KEY_F6, input_dev->keybit);
93 set_bit(KEY_F7, input_dev->keybit);
94 set_bit(KEY_F8, input_dev->keybit);
95 set_bit(KEY_F9, input_dev->keybit);
96
97 err = input_register_device(input_dev);
98 if (err) {
99 printk(KERN_ERR "atlas: couldn't register input device\n");
100 input_free_device(input_dev);
101 return err;
102 }
103
104 /* hookup button handler */
105 status = acpi_install_address_space_handler(device->handle,
106 0x81, &acpi_atlas_button_handler,
107 &acpi_atlas_button_setup, device);
108 if (ACPI_FAILURE(status)) {
109 printk(KERN_ERR "Atlas: Error installing addr spc handler\n");
110 input_unregister_device(input_dev);
111 status = -EINVAL;
112 }
113
114 return status;
115}
116
117static int atlas_acpi_button_remove(struct acpi_device *device, int type)
118{
119 acpi_status status;
120
121 status = acpi_remove_address_space_handler(device->handle,
122 0x81, &acpi_atlas_button_handler);
123 if (ACPI_FAILURE(status)) {
124 printk(KERN_ERR "Atlas: Error removing addr spc handler\n");
125 status = -EINVAL;
126 }
127
128 input_unregister_device(input_dev);
129
130 return status;
131}
132
133static struct acpi_driver atlas_acpi_driver = {
134 .name = ACPI_ATLAS_NAME,
135 .class = ACPI_ATLAS_CLASS,
136 .ids = ACPI_ATLAS_BUTTON_HID,
137 .ops = {
138 .add = atlas_acpi_button_add,
139 .remove = atlas_acpi_button_remove,
140 },
141};
142
143static int __init atlas_acpi_init(void)
144{
145 int result;
146
147 if (acpi_disabled)
148 return -ENODEV;
149
150 result = acpi_bus_register_driver(&atlas_acpi_driver);
151 if (result < 0) {
152 printk(KERN_ERR "Atlas ACPI: Unable to register driver\n");
153 return -ENODEV;
154 }
155
156 return 0;
157}
158
159static void __exit atlas_acpi_exit(void)
160{
161 acpi_bus_unregister_driver(&atlas_acpi_driver);
162}
163
164module_init(atlas_acpi_init);
165module_exit(atlas_acpi_exit);
166
167MODULE_AUTHOR("Jaya Kumar");
168MODULE_LICENSE("GPL");
169MODULE_DESCRIPTION("Atlas button driver");
170
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c
index 31d5a13bfd6..ab76ea442fa 100644
--- a/drivers/input/misc/hp_sdc_rtc.c
+++ b/drivers/input/misc/hp_sdc_rtc.c
@@ -670,7 +670,7 @@ static int hp_sdc_rtc_ioctl(struct inode *inode, struct file *file,
670#endif 670#endif
671} 671}
672 672
673static struct file_operations hp_sdc_rtc_fops = { 673static const struct file_operations hp_sdc_rtc_fops = {
674 .owner = THIS_MODULE, 674 .owner = THIS_MODULE,
675 .llseek = no_llseek, 675 .llseek = no_llseek,
676 .read = hp_sdc_rtc_read, 676 .read = hp_sdc_rtc_read,
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index 9516439b7c7..42556232c52 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -627,7 +627,7 @@ static long uinput_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
627 return retval; 627 return retval;
628} 628}
629 629
630static struct file_operations uinput_fops = { 630static const struct file_operations uinput_fops = {
631 .owner = THIS_MODULE, 631 .owner = THIS_MODULE,
632 .open = uinput_open, 632 .open = uinput_open,
633 .release = uinput_release, 633 .release = uinput_release,
diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c
index 7b9d1c1da41..e1183aeb8ed 100644
--- a/drivers/input/misc/wistron_btns.c
+++ b/drivers/input/misc/wistron_btns.c
@@ -335,6 +335,17 @@ static struct key_entry keymap_aopen_1559as[] = {
335 { KE_END, 0 }, 335 { KE_END, 0 },
336}; 336};
337 337
338static struct key_entry keymap_fs_amilo_d88x0[] = {
339 { KE_KEY, 0x01, KEY_HELP },
340 { KE_KEY, 0x08, KEY_MUTE },
341 { KE_KEY, 0x31, KEY_MAIL },
342 { KE_KEY, 0x36, KEY_WWW },
343 { KE_KEY, 0x11, KEY_PROG1 },
344 { KE_KEY, 0x12, KEY_PROG2 },
345 { KE_KEY, 0x13, KEY_PROG3 },
346 { KE_END, 0 }
347};
348
338/* 349/*
339 * If your machine is not here (which is currently rather likely), please send 350 * If your machine is not here (which is currently rather likely), please send
340 * a list of buttons and their key codes (reported when loading this module 351 * a list of buttons and their key codes (reported when loading this module
@@ -413,6 +424,15 @@ static struct dmi_system_id dmi_ids[] __initdata = {
413 }, 424 },
414 .driver_data = keymap_wistron_ms2111 425 .driver_data = keymap_wistron_ms2111
415 }, 426 },
427 {
428 .callback = dmi_matched,
429 .ident = "Fujitsu Siemens Amilo D88x0",
430 .matches = {
431 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
432 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO D"),
433 },
434 .driver_data = keymap_fs_amilo_d88x0
435 },
416 { NULL, } 436 { NULL, }
417}; 437};
418 438
diff --git a/drivers/input/mouse/inport.c b/drivers/input/mouse/inport.c
index 13dd96785e3..701ebd5473c 100644
--- a/drivers/input/mouse/inport.c
+++ b/drivers/input/mouse/inport.c
@@ -61,7 +61,7 @@ MODULE_LICENSE("GPL");
61#define INPORT_REG_MODE 0x07 61#define INPORT_REG_MODE 0x07
62#define INPORT_RESET 0x80 62#define INPORT_RESET 0x80
63 63
64#ifdef CONFIG_INPUT_ATIXL 64#ifdef CONFIG_MOUSE_ATIXL
65#define INPORT_NAME "ATI XL Mouse" 65#define INPORT_NAME "ATI XL Mouse"
66#define INPORT_VENDOR 0x0002 66#define INPORT_VENDOR 0x0002
67#define INPORT_SPEED_30HZ 0x01 67#define INPORT_SPEED_30HZ 0x01
diff --git a/drivers/input/mouse/pc110pad.c b/drivers/input/mouse/pc110pad.c
index f155c1fea04..05d992e514f 100644
--- a/drivers/input/mouse/pc110pad.c
+++ b/drivers/input/mouse/pc110pad.c
@@ -113,7 +113,7 @@ static int __init pc110pad_init(void)
113 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL); 113 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
114 if (dev) { 114 if (dev) {
115 pci_dev_put(dev); 115 pci_dev_put(dev);
116 return -ENOENT; 116 return -ENODEV;
117 } 117 }
118 118
119 if (!request_region(pc110pad_io, 4, "pc110pad")) { 119 if (!request_region(pc110pad_io, 4, "pc110pad")) {
diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c
index debe9445488..c3fdfc1f342 100644
--- a/drivers/input/serio/i8042.c
+++ b/drivers/input/serio/i8042.c
@@ -371,7 +371,7 @@ static irqreturn_t i8042_interrupt(int irq, void *dev_id)
371 if (unlikely(i8042_suppress_kbd_ack)) 371 if (unlikely(i8042_suppress_kbd_ack))
372 if (port_no == I8042_KBD_PORT_NO && 372 if (port_no == I8042_KBD_PORT_NO &&
373 (data == 0xfa || data == 0xfe)) { 373 (data == 0xfa || data == 0xfe)) {
374 i8042_suppress_kbd_ack = 0; 374 i8042_suppress_kbd_ack--;
375 goto out; 375 goto out;
376 } 376 }
377 377
@@ -543,6 +543,7 @@ static int __devinit i8042_check_aux(void)
543{ 543{
544 int retval = -1; 544 int retval = -1;
545 int irq_registered = 0; 545 int irq_registered = 0;
546 int aux_loop_broken = 0;
546 unsigned long flags; 547 unsigned long flags;
547 unsigned char param; 548 unsigned char param;
548 549
@@ -572,6 +573,8 @@ static int __devinit i8042_check_aux(void)
572 if (i8042_command(&param, I8042_CMD_AUX_TEST) || 573 if (i8042_command(&param, I8042_CMD_AUX_TEST) ||
573 (param && param != 0xfa && param != 0xff)) 574 (param && param != 0xfa && param != 0xff))
574 return -1; 575 return -1;
576
577 aux_loop_broken = 1;
575 } 578 }
576 579
577/* 580/*
@@ -595,7 +598,7 @@ static int __devinit i8042_check_aux(void)
595 * used it for a PCI card or somethig else. 598 * used it for a PCI card or somethig else.
596 */ 599 */
597 600
598 if (i8042_noloop) { 601 if (i8042_noloop || aux_loop_broken) {
599/* 602/*
600 * Without LOOP command we can't test AUX IRQ delivery. Assume the port 603 * Without LOOP command we can't test AUX IRQ delivery. Assume the port
601 * is working and hope we are right. 604 * is working and hope we are right.
@@ -838,13 +841,14 @@ static long i8042_panic_blink(long count)
838 led ^= 0x01 | 0x04; 841 led ^= 0x01 | 0x04;
839 while (i8042_read_status() & I8042_STR_IBF) 842 while (i8042_read_status() & I8042_STR_IBF)
840 DELAY; 843 DELAY;
841 i8042_suppress_kbd_ack = 1; 844 dbg("%02x -> i8042 (panic blink)", 0xed);
845 i8042_suppress_kbd_ack = 2;
842 i8042_write_data(0xed); /* set leds */ 846 i8042_write_data(0xed); /* set leds */
843 DELAY; 847 DELAY;
844 while (i8042_read_status() & I8042_STR_IBF) 848 while (i8042_read_status() & I8042_STR_IBF)
845 DELAY; 849 DELAY;
846 DELAY; 850 DELAY;
847 i8042_suppress_kbd_ack = 1; 851 dbg("%02x -> i8042 (panic blink)", led);
848 i8042_write_data(led); 852 i8042_write_data(led);
849 DELAY; 853 DELAY;
850 last_blink = count; 854 last_blink = count;
diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
index 088ebc348ba..887357666c6 100644
--- a/drivers/input/serio/serio_raw.c
+++ b/drivers/input/serio/serio_raw.c
@@ -234,7 +234,7 @@ static unsigned int serio_raw_poll(struct file *file, poll_table *wait)
234 return 0; 234 return 0;
235} 235}
236 236
237static struct file_operations serio_raw_fops = { 237static const struct file_operations serio_raw_fops = {
238 .owner = THIS_MODULE, 238 .owner = THIS_MODULE,
239 .open = serio_raw_open, 239 .open = serio_raw_open,
240 .release = serio_raw_release, 240 .release = serio_raw_release,
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 6b46c9bf1d2..971618059a6 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -12,13 +12,18 @@ menuconfig INPUT_TOUCHSCREEN
12if INPUT_TOUCHSCREEN 12if INPUT_TOUCHSCREEN
13 13
14config TOUCHSCREEN_ADS7846 14config TOUCHSCREEN_ADS7846
15 tristate "ADS 7846 based touchscreens" 15 tristate "ADS 7846/7843 based touchscreens"
16 depends on SPI_MASTER 16 depends on SPI_MASTER
17 depends on HWMON = n || HWMON
17 help 18 help
18 Say Y here if you have a touchscreen interface using the 19 Say Y here if you have a touchscreen interface using the
19 ADS7846 controller, and your board-specific initialization 20 ADS7846 or ADS7843 controller, and your board-specific setup
20 code includes that in its table of SPI devices. 21 code includes that in its table of SPI devices.
21 22
23 If HWMON is selected, and the driver is told the reference voltage
24 on your board, you will also get hwmon interfaces for the voltage
25 (and on ads7846, temperature) sensors of this chip.
26
22 If unsure, say N (but it's safe to say "Y"). 27 If unsure, say N (but it's safe to say "Y").
23 28
24 To compile this driver as a module, choose M here: the 29 To compile this driver as a module, choose M here: the
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index c6164b6f476..cd251efda41 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -17,8 +17,9 @@
17 * it under the terms of the GNU General Public License version 2 as 17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation. 18 * published by the Free Software Foundation.
19 */ 19 */
20#include <linux/device.h> 20#include <linux/hwmon.h>
21#include <linux/init.h> 21#include <linux/init.h>
22#include <linux/err.h>
22#include <linux/delay.h> 23#include <linux/delay.h>
23#include <linux/input.h> 24#include <linux/input.h>
24#include <linux/interrupt.h> 25#include <linux/interrupt.h>
@@ -54,7 +55,8 @@
54 * files. 55 * files.
55 */ 56 */
56 57
57#define TS_POLL_PERIOD msecs_to_jiffies(10) 58#define TS_POLL_DELAY (1 * 1000000) /* ns delay before the first sample */
59#define TS_POLL_PERIOD (5 * 1000000) /* ns delay between samples */
58 60
59/* this driver doesn't aim at the peak continuous sample rate */ 61/* this driver doesn't aim at the peak continuous sample rate */
60#define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */) 62#define SAMPLE_BITS (8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */)
@@ -63,12 +65,12 @@ struct ts_event {
63 /* For portability, we can't read 12 bit values using SPI (which 65 /* For portability, we can't read 12 bit values using SPI (which
64 * would make the controller deliver them as native byteorder u16 66 * would make the controller deliver them as native byteorder u16
65 * with msbs zeroed). Instead, we read them as two 8-bit values, 67 * with msbs zeroed). Instead, we read them as two 8-bit values,
66 * which need byteswapping then range adjustment. 68 * *** WHICH NEED BYTESWAPPING *** and range adjustment.
67 */ 69 */
68 __be16 x; 70 u16 x;
69 __be16 y; 71 u16 y;
70 __be16 z1, z2; 72 u16 z1, z2;
71 int ignore; 73 int ignore;
72}; 74};
73 75
74struct ads7846 { 76struct ads7846 {
@@ -76,7 +78,12 @@ struct ads7846 {
76 char phys[32]; 78 char phys[32];
77 79
78 struct spi_device *spi; 80 struct spi_device *spi;
81
82#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
79 struct attribute_group *attr_group; 83 struct attribute_group *attr_group;
84 struct class_device *hwmon;
85#endif
86
80 u16 model; 87 u16 model;
81 u16 vref_delay_usecs; 88 u16 vref_delay_usecs;
82 u16 x_plate_ohms; 89 u16 x_plate_ohms;
@@ -99,13 +106,16 @@ struct ads7846 {
99 u16 debounce_rep; 106 u16 debounce_rep;
100 107
101 spinlock_t lock; 108 spinlock_t lock;
102 struct timer_list timer; /* P: lock */ 109 struct hrtimer timer;
103 unsigned pendown:1; /* P: lock */ 110 unsigned pendown:1; /* P: lock */
104 unsigned pending:1; /* P: lock */ 111 unsigned pending:1; /* P: lock */
105// FIXME remove "irq_disabled" 112// FIXME remove "irq_disabled"
106 unsigned irq_disabled:1; /* P: lock */ 113 unsigned irq_disabled:1; /* P: lock */
107 unsigned disabled:1; 114 unsigned disabled:1;
108 115
116 int (*filter)(void *data, int data_idx, int *val);
117 void *filter_data;
118 void (*filter_cleanup)(void *data);
109 int (*get_pendown_state)(void); 119 int (*get_pendown_state)(void);
110}; 120};
111 121
@@ -142,15 +152,16 @@ struct ads7846 {
142#define MAX_12BIT ((1<<12)-1) 152#define MAX_12BIT ((1<<12)-1)
143 153
144/* leave ADC powered up (disables penirq) between differential samples */ 154/* leave ADC powered up (disables penirq) between differential samples */
145#define READ_12BIT_DFR(x) (ADS_START | ADS_A2A1A0_d_ ## x \ 155#define READ_12BIT_DFR(x, adc, vref) (ADS_START | ADS_A2A1A0_d_ ## x \
146 | ADS_12_BIT | ADS_DFR) 156 | ADS_12_BIT | ADS_DFR | \
157 (adc ? ADS_PD10_ADC_ON : 0) | (vref ? ADS_PD10_REF_ON : 0))
147 158
148#define READ_Y (READ_12BIT_DFR(y) | ADS_PD10_ADC_ON) 159#define READ_Y(vref) (READ_12BIT_DFR(y, 1, vref))
149#define READ_Z1 (READ_12BIT_DFR(z1) | ADS_PD10_ADC_ON) 160#define READ_Z1(vref) (READ_12BIT_DFR(z1, 1, vref))
150#define READ_Z2 (READ_12BIT_DFR(z2) | ADS_PD10_ADC_ON) 161#define READ_Z2(vref) (READ_12BIT_DFR(z2, 1, vref))
151 162
152#define READ_X (READ_12BIT_DFR(x) | ADS_PD10_ADC_ON) 163#define READ_X(vref) (READ_12BIT_DFR(x, 1, vref))
153#define PWRDOWN (READ_12BIT_DFR(y) | ADS_PD10_PDOWN) /* LAST */ 164#define PWRDOWN (READ_12BIT_DFR(y, 0, 0)) /* LAST */
154 165
155/* single-ended samples need to first power up reference voltage; 166/* single-ended samples need to first power up reference voltage;
156 * we leave both ADC and VREF powered 167 * we leave both ADC and VREF powered
@@ -158,14 +169,19 @@ struct ads7846 {
158#define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \ 169#define READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \
159 | ADS_12_BIT | ADS_SER) 170 | ADS_12_BIT | ADS_SER)
160 171
161#define REF_ON (READ_12BIT_DFR(x) | ADS_PD10_ALL_ON) 172#define REF_ON (READ_12BIT_DFR(x, 1, 1))
162#define REF_OFF (READ_12BIT_DFR(y) | ADS_PD10_PDOWN) 173#define REF_OFF (READ_12BIT_DFR(y, 0, 0))
163 174
164/*--------------------------------------------------------------------------*/ 175/*--------------------------------------------------------------------------*/
165 176
166/* 177/*
167 * Non-touchscreen sensors only use single-ended conversions. 178 * Non-touchscreen sensors only use single-ended conversions.
179 * The range is GND..vREF. The ads7843 and ads7835 must use external vREF;
180 * ads7846 lets that pin be unconnected, to use internal vREF.
168 */ 181 */
182static unsigned vREF_mV;
183module_param(vREF_mV, uint, 0);
184MODULE_PARM_DESC(vREF_mV, "external vREF voltage, in milliVolts");
169 185
170struct ser_req { 186struct ser_req {
171 u8 ref_on; 187 u8 ref_on;
@@ -193,50 +209,55 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
193 struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL); 209 struct ser_req *req = kzalloc(sizeof *req, GFP_KERNEL);
194 int status; 210 int status;
195 int sample; 211 int sample;
196 int i; 212 int use_internal;
197 213
198 if (!req) 214 if (!req)
199 return -ENOMEM; 215 return -ENOMEM;
200 216
201 spi_message_init(&req->msg); 217 spi_message_init(&req->msg);
202 218
203 /* activate reference, so it has time to settle; */ 219 /* FIXME boards with ads7846 might use external vref instead ... */
204 req->ref_on = REF_ON; 220 use_internal = (ts->model == 7846);
205 req->xfer[0].tx_buf = &req->ref_on; 221
206 req->xfer[0].len = 1; 222 /* maybe turn on internal vREF, and let it settle */
207 req->xfer[1].rx_buf = &req->scratch; 223 if (use_internal) {
208 req->xfer[1].len = 2; 224 req->ref_on = REF_ON;
209 225 req->xfer[0].tx_buf = &req->ref_on;
210 /* 226 req->xfer[0].len = 1;
211 * for external VREF, 0 usec (and assume it's always on); 227 spi_message_add_tail(&req->xfer[0], &req->msg);
212 * for 1uF, use 800 usec; 228
213 * no cap, 100 usec. 229 req->xfer[1].rx_buf = &req->scratch;
214 */ 230 req->xfer[1].len = 2;
215 req->xfer[1].delay_usecs = ts->vref_delay_usecs; 231
232 /* for 1uF, settle for 800 usec; no cap, 100 usec. */
233 req->xfer[1].delay_usecs = ts->vref_delay_usecs;
234 spi_message_add_tail(&req->xfer[1], &req->msg);
235 }
216 236
217 /* take sample */ 237 /* take sample */
218 req->command = (u8) command; 238 req->command = (u8) command;
219 req->xfer[2].tx_buf = &req->command; 239 req->xfer[2].tx_buf = &req->command;
220 req->xfer[2].len = 1; 240 req->xfer[2].len = 1;
241 spi_message_add_tail(&req->xfer[2], &req->msg);
242
221 req->xfer[3].rx_buf = &req->sample; 243 req->xfer[3].rx_buf = &req->sample;
222 req->xfer[3].len = 2; 244 req->xfer[3].len = 2;
245 spi_message_add_tail(&req->xfer[3], &req->msg);
223 246
224 /* REVISIT: take a few more samples, and compare ... */ 247 /* REVISIT: take a few more samples, and compare ... */
225 248
226 /* turn off reference */ 249 /* maybe off internal vREF */
227 req->ref_off = REF_OFF; 250 if (use_internal) {
228 req->xfer[4].tx_buf = &req->ref_off; 251 req->ref_off = REF_OFF;
229 req->xfer[4].len = 1; 252 req->xfer[4].tx_buf = &req->ref_off;
230 req->xfer[5].rx_buf = &req->scratch; 253 req->xfer[4].len = 1;
231 req->xfer[5].len = 2; 254 spi_message_add_tail(&req->xfer[4], &req->msg);
232 255
233 CS_CHANGE(req->xfer[5]); 256 req->xfer[5].rx_buf = &req->scratch;
234 257 req->xfer[5].len = 2;
235 /* group all the transfers together, so we can't interfere with 258 CS_CHANGE(req->xfer[5]);
236 * reading touchscreen state; disable penirq while sampling 259 spi_message_add_tail(&req->xfer[5], &req->msg);
237 */ 260 }
238 for (i = 0; i < 6; i++)
239 spi_message_add_tail(&req->xfer[i], &req->msg);
240 261
241 ts->irq_disabled = 1; 262 ts->irq_disabled = 1;
242 disable_irq(spi->irq); 263 disable_irq(spi->irq);
@@ -256,25 +277,173 @@ static int ads7846_read12_ser(struct device *dev, unsigned command)
256 return status ? status : sample; 277 return status ? status : sample;
257} 278}
258 279
259#define SHOW(name) static ssize_t \ 280#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
281
282#define SHOW(name, var, adjust) static ssize_t \
260name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ 283name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \
261{ \ 284{ \
285 struct ads7846 *ts = dev_get_drvdata(dev); \
262 ssize_t v = ads7846_read12_ser(dev, \ 286 ssize_t v = ads7846_read12_ser(dev, \
263 READ_12BIT_SER(name) | ADS_PD10_ALL_ON); \ 287 READ_12BIT_SER(var) | ADS_PD10_ALL_ON); \
264 if (v < 0) \ 288 if (v < 0) \
265 return v; \ 289 return v; \
266 return sprintf(buf, "%u\n", (unsigned) v); \ 290 return sprintf(buf, "%u\n", adjust(ts, v)); \
267} \ 291} \
268static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL); 292static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL);
269 293
270SHOW(temp0) 294
271SHOW(temp1) 295/* Sysfs conventions report temperatures in millidegrees Celcius.
272SHOW(vaux) 296 * ADS7846 could use the low-accuracy two-sample scheme, but can't do the high
273SHOW(vbatt) 297 * accuracy scheme without calibration data. For now we won't try either;
298 * userspace sees raw sensor values, and must scale/calibrate appropriately.
299 */
300static inline unsigned null_adjust(struct ads7846 *ts, ssize_t v)
301{
302 return v;
303}
304
305SHOW(temp0, temp0, null_adjust) /* temp1_input */
306SHOW(temp1, temp1, null_adjust) /* temp2_input */
307
308
309/* sysfs conventions report voltages in millivolts. We can convert voltages
310 * if we know vREF. userspace may need to scale vAUX to match the board's
311 * external resistors; we assume that vBATT only uses the internal ones.
312 */
313static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v)
314{
315 unsigned retval = v;
316
317 /* external resistors may scale vAUX into 0..vREF */
318 retval *= vREF_mV;
319 retval = retval >> 12;
320 return retval;
321}
322
323static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v)
324{
325 unsigned retval = vaux_adjust(ts, v);
326
327 /* ads7846 has a resistor ladder to scale this signal down */
328 if (ts->model == 7846)
329 retval *= 4;
330 return retval;
331}
332
333SHOW(in0_input, vaux, vaux_adjust)
334SHOW(in1_input, vbatt, vbatt_adjust)
335
336
337static struct attribute *ads7846_attributes[] = {
338 &dev_attr_temp0.attr,
339 &dev_attr_temp1.attr,
340 &dev_attr_in0_input.attr,
341 &dev_attr_in1_input.attr,
342 NULL,
343};
344
345static struct attribute_group ads7846_attr_group = {
346 .attrs = ads7846_attributes,
347};
348
349static struct attribute *ads7843_attributes[] = {
350 &dev_attr_in0_input.attr,
351 &dev_attr_in1_input.attr,
352 NULL,
353};
354
355static struct attribute_group ads7843_attr_group = {
356 .attrs = ads7843_attributes,
357};
358
359static struct attribute *ads7845_attributes[] = {
360 &dev_attr_in0_input.attr,
361 NULL,
362};
363
364static struct attribute_group ads7845_attr_group = {
365 .attrs = ads7845_attributes,
366};
367
368static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts)
369{
370 struct class_device *hwmon;
371 int err;
372
373 /* hwmon sensors need a reference voltage */
374 switch (ts->model) {
375 case 7846:
376 if (!vREF_mV) {
377 dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n");
378 vREF_mV = 2500;
379 }
380 break;
381 case 7845:
382 case 7843:
383 if (!vREF_mV) {
384 dev_warn(&spi->dev,
385 "external vREF for ADS%d not specified\n",
386 ts->model);
387 return 0;
388 }
389 break;
390 }
391
392 /* different chips have different sensor groups */
393 switch (ts->model) {
394 case 7846:
395 ts->attr_group = &ads7846_attr_group;
396 break;
397 case 7845:
398 ts->attr_group = &ads7845_attr_group;
399 break;
400 case 7843:
401 ts->attr_group = &ads7843_attr_group;
402 break;
403 default:
404 dev_dbg(&spi->dev, "ADS%d not recognized\n", ts->model);
405 return 0;
406 }
407
408 err = sysfs_create_group(&spi->dev.kobj, ts->attr_group);
409 if (err)
410 return err;
411
412 hwmon = hwmon_device_register(&spi->dev);
413 if (IS_ERR(hwmon)) {
414 sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
415 return PTR_ERR(hwmon);
416 }
417
418 ts->hwmon = hwmon;
419 return 0;
420}
421
422static void ads784x_hwmon_unregister(struct spi_device *spi,
423 struct ads7846 *ts)
424{
425 if (ts->hwmon) {
426 sysfs_remove_group(&spi->dev.kobj, ts->attr_group);
427 hwmon_device_unregister(ts->hwmon);
428 }
429}
430
431#else
432static inline int ads784x_hwmon_register(struct spi_device *spi,
433 struct ads7846 *ts)
434{
435 return 0;
436}
437
438static inline void ads784x_hwmon_unregister(struct spi_device *spi,
439 struct ads7846 *ts)
440{
441}
442#endif
274 443
275static int is_pen_down(struct device *dev) 444static int is_pen_down(struct device *dev)
276{ 445{
277 struct ads7846 *ts = dev_get_drvdata(dev); 446 struct ads7846 *ts = dev_get_drvdata(dev);
278 447
279 return ts->pendown; 448 return ts->pendown;
280} 449}
@@ -318,46 +487,14 @@ static ssize_t ads7846_disable_store(struct device *dev,
318 487
319static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store); 488static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store);
320 489
321static struct attribute *ads7846_attributes[] = { 490static struct attribute *ads784x_attributes[] = {
322 &dev_attr_temp0.attr,
323 &dev_attr_temp1.attr,
324 &dev_attr_vbatt.attr,
325 &dev_attr_vaux.attr,
326 &dev_attr_pen_down.attr,
327 &dev_attr_disable.attr,
328 NULL,
329};
330
331static struct attribute_group ads7846_attr_group = {
332 .attrs = ads7846_attributes,
333};
334
335/*
336 * ads7843/7845 don't have temperature sensors, and
337 * use the other sensors a bit differently too
338 */
339
340static struct attribute *ads7843_attributes[] = {
341 &dev_attr_vbatt.attr,
342 &dev_attr_vaux.attr,
343 &dev_attr_pen_down.attr, 491 &dev_attr_pen_down.attr,
344 &dev_attr_disable.attr, 492 &dev_attr_disable.attr,
345 NULL, 493 NULL,
346}; 494};
347 495
348static struct attribute_group ads7843_attr_group = { 496static struct attribute_group ads784x_attr_group = {
349 .attrs = ads7843_attributes, 497 .attrs = ads784x_attributes,
350};
351
352static struct attribute *ads7845_attributes[] = {
353 &dev_attr_vaux.attr,
354 &dev_attr_pen_down.attr,
355 &dev_attr_disable.attr,
356 NULL,
357};
358
359static struct attribute_group ads7845_attr_group = {
360 .attrs = ads7845_attributes,
361}; 498};
362 499
363/*--------------------------------------------------------------------------*/ 500/*--------------------------------------------------------------------------*/
@@ -373,25 +510,22 @@ static struct attribute_group ads7845_attr_group = {
373static void ads7846_rx(void *ads) 510static void ads7846_rx(void *ads)
374{ 511{
375 struct ads7846 *ts = ads; 512 struct ads7846 *ts = ads;
376 struct input_dev *input_dev = ts->input;
377 unsigned Rt; 513 unsigned Rt;
378 unsigned sync = 0;
379 u16 x, y, z1, z2; 514 u16 x, y, z1, z2;
380 unsigned long flags;
381 515
382 /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding; 516 /* ads7846_rx_val() did in-place conversion (including byteswap) from
383 * built from two 8 bit values written msb-first. 517 * on-the-wire format as part of debouncing to get stable readings.
384 */ 518 */
385 x = (be16_to_cpu(ts->tc.x) >> 3) & 0x0fff; 519 x = ts->tc.x;
386 y = (be16_to_cpu(ts->tc.y) >> 3) & 0x0fff; 520 y = ts->tc.y;
387 z1 = (be16_to_cpu(ts->tc.z1) >> 3) & 0x0fff; 521 z1 = ts->tc.z1;
388 z2 = (be16_to_cpu(ts->tc.z2) >> 3) & 0x0fff; 522 z2 = ts->tc.z2;
389 523
390 /* range filtering */ 524 /* range filtering */
391 if (x == MAX_12BIT) 525 if (x == MAX_12BIT)
392 x = 0; 526 x = 0;
393 527
394 if (likely(x && z1 && !device_suspended(&ts->spi->dev))) { 528 if (likely(x && z1)) {
395 /* compute touch pressure resistance using equation #2 */ 529 /* compute touch pressure resistance using equation #2 */
396 Rt = z2; 530 Rt = z2;
397 Rt -= z1; 531 Rt -= z1;
@@ -403,100 +537,129 @@ static void ads7846_rx(void *ads)
403 Rt = 0; 537 Rt = 0;
404 538
405 /* Sample found inconsistent by debouncing or pressure is beyond 539 /* Sample found inconsistent by debouncing or pressure is beyond
406 * the maximum. Don't report it to user space, repeat at least 540 * the maximum. Don't report it to user space, repeat at least
407 * once more the measurement */ 541 * once more the measurement
542 */
408 if (ts->tc.ignore || Rt > ts->pressure_max) { 543 if (ts->tc.ignore || Rt > ts->pressure_max) {
409 mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD); 544#ifdef VERBOSE
545 pr_debug("%s: ignored %d pressure %d\n",
546 ts->spi->dev.bus_id, ts->tc.ignore, Rt);
547#endif
548 hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD),
549 HRTIMER_REL);
410 return; 550 return;
411 } 551 }
412 552
413 /* NOTE: "pendown" is inferred from pressure; we don't rely on 553 /* NOTE: We can't rely on the pressure to determine the pen down
414 * being able to check nPENIRQ status, or "friendly" trigger modes 554 * state, even this controller has a pressure sensor. The pressure
415 * (both-edges is much better than just-falling or low-level). 555 * value can fluctuate for quite a while after lifting the pen and
556 * in some cases may not even settle at the expected value.
416 * 557 *
417 * REVISIT: some boards may require reading nPENIRQ; it's 558 * The only safe way to check for the pen up condition is in the
418 * needed on 7843. and 7845 reads pressure differently... 559 * timer by reading the pen signal state (it's a GPIO _and_ IRQ).
419 *
420 * REVISIT: the touchscreen might not be connected; this code
421 * won't notice that, even if nPENIRQ never fires ...
422 */ 560 */
423 if (!ts->pendown && Rt != 0) {
424 input_report_key(input_dev, BTN_TOUCH, 1);
425 sync = 1;
426 } else if (ts->pendown && Rt == 0) {
427 input_report_key(input_dev, BTN_TOUCH, 0);
428 sync = 1;
429 }
430
431 if (Rt) { 561 if (Rt) {
432 input_report_abs(input_dev, ABS_X, x); 562 struct input_dev *input = ts->input;
433 input_report_abs(input_dev, ABS_Y, y);
434 sync = 1;
435 }
436
437 if (sync) {
438 input_report_abs(input_dev, ABS_PRESSURE, Rt);
439 input_sync(input_dev);
440 }
441 563
442#ifdef VERBOSE 564 if (!ts->pendown) {
443 if (Rt || ts->pendown) 565 input_report_key(input, BTN_TOUCH, 1);
444 pr_debug("%s: %d/%d/%d%s\n", ts->spi->dev.bus_id, 566 ts->pendown = 1;
445 x, y, Rt, Rt ? "" : " UP"); 567#ifdef VERBOSE
568 dev_dbg(&ts->spi->dev, "DOWN\n");
446#endif 569#endif
570 }
571 input_report_abs(input, ABS_X, x);
572 input_report_abs(input, ABS_Y, y);
573 input_report_abs(input, ABS_PRESSURE, Rt);
447 574
448 spin_lock_irqsave(&ts->lock, flags); 575 input_sync(input);
449 576#ifdef VERBOSE
450 ts->pendown = (Rt != 0); 577 dev_dbg(&ts->spi->dev, "%4d/%4d/%4d\n", x, y, Rt);
451 mod_timer(&ts->timer, jiffies + TS_POLL_PERIOD); 578#endif
579 }
452 580
453 spin_unlock_irqrestore(&ts->lock, flags); 581 hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD), HRTIMER_REL);
454} 582}
455 583
456static void ads7846_debounce(void *ads) 584static int ads7846_debounce(void *ads, int data_idx, int *val)
457{ 585{
458 struct ads7846 *ts = ads; 586 struct ads7846 *ts = ads;
459 struct spi_message *m;
460 struct spi_transfer *t;
461 int val;
462 int status;
463 587
464 m = &ts->msg[ts->msg_idx]; 588 if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) {
465 t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); 589 /* Start over collecting consistent readings. */
466 val = (be16_to_cpu(*(__be16 *)t->rx_buf) >> 3) & 0x0fff; 590 ts->read_rep = 0;
467 if (!ts->read_cnt || (abs(ts->last_read - val) > ts->debounce_tol)) {
468 /* Repeat it, if this was the first read or the read 591 /* Repeat it, if this was the first read or the read
469 * wasn't consistent enough. */ 592 * wasn't consistent enough. */
470 if (ts->read_cnt < ts->debounce_max) { 593 if (ts->read_cnt < ts->debounce_max) {
471 ts->last_read = val; 594 ts->last_read = *val;
472 ts->read_cnt++; 595 ts->read_cnt++;
596 return ADS7846_FILTER_REPEAT;
473 } else { 597 } else {
474 /* Maximum number of debouncing reached and still 598 /* Maximum number of debouncing reached and still
475 * not enough number of consistent readings. Abort 599 * not enough number of consistent readings. Abort
476 * the whole sample, repeat it in the next sampling 600 * the whole sample, repeat it in the next sampling
477 * period. 601 * period.
478 */ 602 */
479 ts->tc.ignore = 1;
480 ts->read_cnt = 0; 603 ts->read_cnt = 0;
481 /* Last message will contain ads7846_rx() as the 604 return ADS7846_FILTER_IGNORE;
482 * completion function.
483 */
484 m = ts->last_msg;
485 } 605 }
486 /* Start over collecting consistent readings. */
487 ts->read_rep = 0;
488 } else { 606 } else {
489 if (++ts->read_rep > ts->debounce_rep) { 607 if (++ts->read_rep > ts->debounce_rep) {
490 /* Got a good reading for this coordinate, 608 /* Got a good reading for this coordinate,
491 * go for the next one. */ 609 * go for the next one. */
492 ts->tc.ignore = 0;
493 ts->msg_idx++;
494 ts->read_cnt = 0; 610 ts->read_cnt = 0;
495 ts->read_rep = 0; 611 ts->read_rep = 0;
496 m++; 612 return ADS7846_FILTER_OK;
497 } else 613 } else {
498 /* Read more values that are consistent. */ 614 /* Read more values that are consistent. */
499 ts->read_cnt++; 615 ts->read_cnt++;
616 return ADS7846_FILTER_REPEAT;
617 }
618 }
619}
620
621static int ads7846_no_filter(void *ads, int data_idx, int *val)
622{
623 return ADS7846_FILTER_OK;
624}
625
626static void ads7846_rx_val(void *ads)
627{
628 struct ads7846 *ts = ads;
629 struct spi_message *m;
630 struct spi_transfer *t;
631 u16 *rx_val;
632 int val;
633 int action;
634 int status;
635
636 m = &ts->msg[ts->msg_idx];
637 t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list);
638 rx_val = t->rx_buf;
639
640 /* adjust: on-wire is a must-ignore bit, a BE12 value, then padding;
641 * built from two 8 bit values written msb-first.
642 */
643 val = be16_to_cpu(*rx_val) >> 3;
644
645 action = ts->filter(ts->filter_data, ts->msg_idx, &val);
646 switch (action) {
647 case ADS7846_FILTER_REPEAT:
648 break;
649 case ADS7846_FILTER_IGNORE:
650 ts->tc.ignore = 1;
651 /* Last message will contain ads7846_rx() as the
652 * completion function.
653 */
654 m = ts->last_msg;
655 break;
656 case ADS7846_FILTER_OK:
657 *rx_val = val;
658 ts->tc.ignore = 0;
659 m = &ts->msg[++ts->msg_idx];
660 break;
661 default:
662 BUG();
500 } 663 }
501 status = spi_async(ts->spi, m); 664 status = spi_async(ts->spi, m);
502 if (status) 665 if (status)
@@ -504,21 +667,34 @@ static void ads7846_debounce(void *ads)
504 status); 667 status);
505} 668}
506 669
507static void ads7846_timer(unsigned long handle) 670static int ads7846_timer(struct hrtimer *handle)
508{ 671{
509 struct ads7846 *ts = (void *)handle; 672 struct ads7846 *ts = container_of(handle, struct ads7846, timer);
510 int status = 0; 673 int status = 0;
511 674
512 spin_lock_irq(&ts->lock); 675 spin_lock_irq(&ts->lock);
513 676
514 if (unlikely(ts->msg_idx && !ts->pendown)) { 677 if (unlikely(!ts->get_pendown_state() ||
678 device_suspended(&ts->spi->dev))) {
679 if (ts->pendown) {
680 struct input_dev *input = ts->input;
681
682 input_report_key(input, BTN_TOUCH, 0);
683 input_report_abs(input, ABS_PRESSURE, 0);
684 input_sync(input);
685
686 ts->pendown = 0;
687#ifdef VERBOSE
688 dev_dbg(&ts->spi->dev, "UP\n");
689#endif
690 }
691
515 /* measurement cycle ended */ 692 /* measurement cycle ended */
516 if (!device_suspended(&ts->spi->dev)) { 693 if (!device_suspended(&ts->spi->dev)) {
517 ts->irq_disabled = 0; 694 ts->irq_disabled = 0;
518 enable_irq(ts->spi->irq); 695 enable_irq(ts->spi->irq);
519 } 696 }
520 ts->pending = 0; 697 ts->pending = 0;
521 ts->msg_idx = 0;
522 } else { 698 } else {
523 /* pen is still down, continue with the measurement */ 699 /* pen is still down, continue with the measurement */
524 ts->msg_idx = 0; 700 ts->msg_idx = 0;
@@ -528,6 +704,7 @@ static void ads7846_timer(unsigned long handle)
528 } 704 }
529 705
530 spin_unlock_irq(&ts->lock); 706 spin_unlock_irq(&ts->lock);
707 return HRTIMER_NORESTART;
531} 708}
532 709
533static irqreturn_t ads7846_irq(int irq, void *handle) 710static irqreturn_t ads7846_irq(int irq, void *handle)
@@ -546,7 +723,8 @@ static irqreturn_t ads7846_irq(int irq, void *handle)
546 ts->irq_disabled = 1; 723 ts->irq_disabled = 1;
547 disable_irq(ts->spi->irq); 724 disable_irq(ts->spi->irq);
548 ts->pending = 1; 725 ts->pending = 1;
549 mod_timer(&ts->timer, jiffies); 726 hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_DELAY),
727 HRTIMER_REL);
550 } 728 }
551 } 729 }
552 spin_unlock_irqrestore(&ts->lock, flags); 730 spin_unlock_irqrestore(&ts->lock, flags);
@@ -632,6 +810,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
632 struct ads7846_platform_data *pdata = spi->dev.platform_data; 810 struct ads7846_platform_data *pdata = spi->dev.platform_data;
633 struct spi_message *m; 811 struct spi_message *m;
634 struct spi_transfer *x; 812 struct spi_transfer *x;
813 int vref;
635 int err; 814 int err;
636 815
637 if (!spi->irq) { 816 if (!spi->irq) {
@@ -665,6 +844,10 @@ static int __devinit ads7846_probe(struct spi_device *spi)
665 * may not. So we stick to very-portable 8 bit words, both RX and TX. 844 * may not. So we stick to very-portable 8 bit words, both RX and TX.
666 */ 845 */
667 spi->bits_per_word = 8; 846 spi->bits_per_word = 8;
847 spi->mode = SPI_MODE_1;
848 err = spi_setup(spi);
849 if (err < 0)
850 return err;
668 851
669 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); 852 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL);
670 input_dev = input_allocate_device(); 853 input_dev = input_allocate_device();
@@ -679,8 +862,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
679 ts->spi = spi; 862 ts->spi = spi;
680 ts->input = input_dev; 863 ts->input = input_dev;
681 864
682 init_timer(&ts->timer); 865 hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_REL);
683 ts->timer.data = (unsigned long) ts;
684 ts->timer.function = ads7846_timer; 866 ts->timer.function = ads7846_timer;
685 867
686 spin_lock_init(&ts->lock); 868 spin_lock_init(&ts->lock);
@@ -689,14 +871,25 @@ static int __devinit ads7846_probe(struct spi_device *spi)
689 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100; 871 ts->vref_delay_usecs = pdata->vref_delay_usecs ? : 100;
690 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400; 872 ts->x_plate_ohms = pdata->x_plate_ohms ? : 400;
691 ts->pressure_max = pdata->pressure_max ? : ~0; 873 ts->pressure_max = pdata->pressure_max ? : ~0;
692 if (pdata->debounce_max) { 874
875 if (pdata->filter != NULL) {
876 if (pdata->filter_init != NULL) {
877 err = pdata->filter_init(pdata, &ts->filter_data);
878 if (err < 0)
879 goto err_free_mem;
880 }
881 ts->filter = pdata->filter;
882 ts->filter_cleanup = pdata->filter_cleanup;
883 } else if (pdata->debounce_max) {
693 ts->debounce_max = pdata->debounce_max; 884 ts->debounce_max = pdata->debounce_max;
885 if (ts->debounce_max < 2)
886 ts->debounce_max = 2;
694 ts->debounce_tol = pdata->debounce_tol; 887 ts->debounce_tol = pdata->debounce_tol;
695 ts->debounce_rep = pdata->debounce_rep; 888 ts->debounce_rep = pdata->debounce_rep;
696 if (ts->debounce_rep > ts->debounce_max + 1) 889 ts->filter = ads7846_debounce;
697 ts->debounce_rep = ts->debounce_max - 1; 890 ts->filter_data = ts;
698 } else 891 } else
699 ts->debounce_tol = ~0; 892 ts->filter = ads7846_no_filter;
700 ts->get_pendown_state = pdata->get_pendown_state; 893 ts->get_pendown_state = pdata->get_pendown_state;
701 894
702 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id); 895 snprintf(ts->phys, sizeof(ts->phys), "%s/input0", spi->dev.bus_id);
@@ -718,6 +911,8 @@ static int __devinit ads7846_probe(struct spi_device *spi)
718 input_set_abs_params(input_dev, ABS_PRESSURE, 911 input_set_abs_params(input_dev, ABS_PRESSURE,
719 pdata->pressure_min, pdata->pressure_max, 0, 0); 912 pdata->pressure_min, pdata->pressure_max, 0, 0);
720 913
914 vref = pdata->keep_vref_on;
915
721 /* set up the transfers to read touchscreen state; this assumes we 916 /* set up the transfers to read touchscreen state; this assumes we
722 * use formula #2 for pressure, not #3. 917 * use formula #2 for pressure, not #3.
723 */ 918 */
@@ -727,7 +922,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
727 spi_message_init(m); 922 spi_message_init(m);
728 923
729 /* y- still on; turn on only y+ (and ADC) */ 924 /* y- still on; turn on only y+ (and ADC) */
730 ts->read_y = READ_Y; 925 ts->read_y = READ_Y(vref);
731 x->tx_buf = &ts->read_y; 926 x->tx_buf = &ts->read_y;
732 x->len = 1; 927 x->len = 1;
733 spi_message_add_tail(x, m); 928 spi_message_add_tail(x, m);
@@ -737,7 +932,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
737 x->len = 2; 932 x->len = 2;
738 spi_message_add_tail(x, m); 933 spi_message_add_tail(x, m);
739 934
740 m->complete = ads7846_debounce; 935 m->complete = ads7846_rx_val;
741 m->context = ts; 936 m->context = ts;
742 937
743 m++; 938 m++;
@@ -745,7 +940,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
745 940
746 /* turn y- off, x+ on, then leave in lowpower */ 941 /* turn y- off, x+ on, then leave in lowpower */
747 x++; 942 x++;
748 ts->read_x = READ_X; 943 ts->read_x = READ_X(vref);
749 x->tx_buf = &ts->read_x; 944 x->tx_buf = &ts->read_x;
750 x->len = 1; 945 x->len = 1;
751 spi_message_add_tail(x, m); 946 spi_message_add_tail(x, m);
@@ -755,7 +950,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
755 x->len = 2; 950 x->len = 2;
756 spi_message_add_tail(x, m); 951 spi_message_add_tail(x, m);
757 952
758 m->complete = ads7846_debounce; 953 m->complete = ads7846_rx_val;
759 m->context = ts; 954 m->context = ts;
760 955
761 /* turn y+ off, x- on; we'll use formula #2 */ 956 /* turn y+ off, x- on; we'll use formula #2 */
@@ -764,7 +959,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
764 spi_message_init(m); 959 spi_message_init(m);
765 960
766 x++; 961 x++;
767 ts->read_z1 = READ_Z1; 962 ts->read_z1 = READ_Z1(vref);
768 x->tx_buf = &ts->read_z1; 963 x->tx_buf = &ts->read_z1;
769 x->len = 1; 964 x->len = 1;
770 spi_message_add_tail(x, m); 965 spi_message_add_tail(x, m);
@@ -774,14 +969,14 @@ static int __devinit ads7846_probe(struct spi_device *spi)
774 x->len = 2; 969 x->len = 2;
775 spi_message_add_tail(x, m); 970 spi_message_add_tail(x, m);
776 971
777 m->complete = ads7846_debounce; 972 m->complete = ads7846_rx_val;
778 m->context = ts; 973 m->context = ts;
779 974
780 m++; 975 m++;
781 spi_message_init(m); 976 spi_message_init(m);
782 977
783 x++; 978 x++;
784 ts->read_z2 = READ_Z2; 979 ts->read_z2 = READ_Z2(vref);
785 x->tx_buf = &ts->read_z2; 980 x->tx_buf = &ts->read_z2;
786 x->len = 1; 981 x->len = 1;
787 spi_message_add_tail(x, m); 982 spi_message_add_tail(x, m);
@@ -791,7 +986,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
791 x->len = 2; 986 x->len = 2;
792 spi_message_add_tail(x, m); 987 spi_message_add_tail(x, m);
793 988
794 m->complete = ads7846_debounce; 989 m->complete = ads7846_rx_val;
795 m->context = ts; 990 m->context = ts;
796 } 991 }
797 992
@@ -820,31 +1015,24 @@ static int __devinit ads7846_probe(struct spi_device *spi)
820 spi->dev.driver->name, ts)) { 1015 spi->dev.driver->name, ts)) {
821 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); 1016 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
822 err = -EBUSY; 1017 err = -EBUSY;
823 goto err_free_mem; 1018 goto err_cleanup_filter;
824 } 1019 }
825 1020
1021 err = ads784x_hwmon_register(spi, ts);
1022 if (err)
1023 goto err_free_irq;
1024
826 dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq); 1025 dev_info(&spi->dev, "touchscreen, irq %d\n", spi->irq);
827 1026
828 /* take a first sample, leaving nPENIRQ active; avoid 1027 /* take a first sample, leaving nPENIRQ active and vREF off; avoid
829 * the touchscreen, in case it's not connected. 1028 * the touchscreen, in case it's not connected.
830 */ 1029 */
831 (void) ads7846_read12_ser(&spi->dev, 1030 (void) ads7846_read12_ser(&spi->dev,
832 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON); 1031 READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON);
833 1032
834 switch (ts->model) { 1033 err = sysfs_create_group(&spi->dev.kobj, &ads784x_attr_group);
835 case 7846:
836 ts->attr_group = &ads7846_attr_group;
837 break;
838 case 7845:
839 ts->attr_group = &ads7845_attr_group;
840 break;
841 default:
842 ts->attr_group = &ads7843_attr_group;
843 break;
844 }
845 err = sysfs_create_group(&spi->dev.kobj, ts->attr_group);
846 if (err) 1034 if (err)
847 goto err_free_irq; 1035 goto err_remove_hwmon;
848 1036
849 err = input_register_device(input_dev); 1037 err = input_register_device(input_dev);
850 if (err) 1038 if (err)
@@ -853,9 +1041,14 @@ static int __devinit ads7846_probe(struct spi_device *spi)
853 return 0; 1041 return 0;
854 1042
855 err_remove_attr_group: 1043 err_remove_attr_group:
856 sysfs_remove_group(&spi->dev.kobj, ts->attr_group); 1044 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group);
1045 err_remove_hwmon:
1046 ads784x_hwmon_unregister(spi, ts);
857 err_free_irq: 1047 err_free_irq:
858 free_irq(spi->irq, ts); 1048 free_irq(spi->irq, ts);
1049 err_cleanup_filter:
1050 if (ts->filter_cleanup)
1051 ts->filter_cleanup(ts->filter_data);
859 err_free_mem: 1052 err_free_mem:
860 input_free_device(input_dev); 1053 input_free_device(input_dev);
861 kfree(ts); 1054 kfree(ts);
@@ -866,16 +1059,20 @@ static int __devexit ads7846_remove(struct spi_device *spi)
866{ 1059{
867 struct ads7846 *ts = dev_get_drvdata(&spi->dev); 1060 struct ads7846 *ts = dev_get_drvdata(&spi->dev);
868 1061
1062 ads784x_hwmon_unregister(spi, ts);
869 input_unregister_device(ts->input); 1063 input_unregister_device(ts->input);
870 1064
871 ads7846_suspend(spi, PMSG_SUSPEND); 1065 ads7846_suspend(spi, PMSG_SUSPEND);
872 1066
873 sysfs_remove_group(&spi->dev.kobj, ts->attr_group); 1067 sysfs_remove_group(&spi->dev.kobj, &ads784x_attr_group);
874 1068
875 free_irq(ts->spi->irq, ts); 1069 free_irq(ts->spi->irq, ts);
876 /* suspend left the IRQ disabled */ 1070 /* suspend left the IRQ disabled */
877 enable_irq(ts->spi->irq); 1071 enable_irq(ts->spi->irq);
878 1072
1073 if (ts->filter_cleanup)
1074 ts->filter_cleanup(ts->filter_data);
1075
879 kfree(ts); 1076 kfree(ts);
880 1077
881 dev_dbg(&spi->dev, "unregistered touchscreen\n"); 1078 dev_dbg(&spi->dev, "unregistered touchscreen\n");
diff --git a/drivers/input/tsdev.c b/drivers/input/tsdev.c
index a730c461227..0300dca8591 100644
--- a/drivers/input/tsdev.c
+++ b/drivers/input/tsdev.c
@@ -151,6 +151,10 @@ static int tsdev_open(struct inode *inode, struct file *file)
151 int i = iminor(inode) - TSDEV_MINOR_BASE; 151 int i = iminor(inode) - TSDEV_MINOR_BASE;
152 struct tsdev_list *list; 152 struct tsdev_list *list;
153 153
154 printk(KERN_WARNING "tsdev (compaq touchscreen emulation) is scheduled "
155 "for removal.\nSee Documentation/feature-removal-schedule.txt "
156 "for details.\n");
157
154 if (i >= TSDEV_MINORS || !tsdev_table[i & TSDEV_MINOR_MASK]) 158 if (i >= TSDEV_MINORS || !tsdev_table[i & TSDEV_MINOR_MASK])
155 return -ENODEV; 159 return -ENODEV;
156 160
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index d22c0224fde..db1260f73f1 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -118,6 +118,15 @@ struct capiminor {
118}; 118};
119#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ 119#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
120 120
121/* FIXME: The following lock is a sledgehammer-workaround to a
122 * locking issue with the capiminor (and maybe other) data structure(s).
123 * Access to this data is done in a racy way and crashes the machine with
124 * a FritzCard DSL driver; sooner or later. This is a workaround
125 * which trades scalability vs stability, so it doesn't crash the kernel anymore.
126 * The correct (and scalable) fix for the issue seems to require
127 * an API change to the drivers... . */
128static DEFINE_SPINLOCK(workaround_lock);
129
121struct capincci { 130struct capincci {
122 struct capincci *next; 131 struct capincci *next;
123 u32 ncci; 132 u32 ncci;
@@ -589,6 +598,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
589#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ 598#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
590 struct capincci *np; 599 struct capincci *np;
591 u32 ncci; 600 u32 ncci;
601 unsigned long flags;
592 602
593 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) { 603 if (CAPIMSG_CMD(skb->data) == CAPI_CONNECT_B3_CONF) {
594 u16 info = CAPIMSG_U16(skb->data, 12); // Info field 604 u16 info = CAPIMSG_U16(skb->data, 12); // Info field
@@ -603,9 +613,11 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
603 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data)); 613 capincci_alloc(cdev, CAPIMSG_NCCI(skb->data));
604 up(&cdev->ncci_list_sem); 614 up(&cdev->ncci_list_sem);
605 } 615 }
616 spin_lock_irqsave(&workaround_lock, flags);
606 if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) { 617 if (CAPIMSG_COMMAND(skb->data) != CAPI_DATA_B3) {
607 skb_queue_tail(&cdev->recvqueue, skb); 618 skb_queue_tail(&cdev->recvqueue, skb);
608 wake_up_interruptible(&cdev->recvwait); 619 wake_up_interruptible(&cdev->recvwait);
620 spin_unlock_irqrestore(&workaround_lock, flags);
609 return; 621 return;
610 } 622 }
611 ncci = CAPIMSG_CONTROL(skb->data); 623 ncci = CAPIMSG_CONTROL(skb->data);
@@ -615,6 +627,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
615 printk(KERN_ERR "BUG: capi_signal: ncci not found\n"); 627 printk(KERN_ERR "BUG: capi_signal: ncci not found\n");
616 skb_queue_tail(&cdev->recvqueue, skb); 628 skb_queue_tail(&cdev->recvqueue, skb);
617 wake_up_interruptible(&cdev->recvwait); 629 wake_up_interruptible(&cdev->recvwait);
630 spin_unlock_irqrestore(&workaround_lock, flags);
618 return; 631 return;
619 } 632 }
620#ifndef CONFIG_ISDN_CAPI_MIDDLEWARE 633#ifndef CONFIG_ISDN_CAPI_MIDDLEWARE
@@ -625,6 +638,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
625 if (!mp) { 638 if (!mp) {
626 skb_queue_tail(&cdev->recvqueue, skb); 639 skb_queue_tail(&cdev->recvqueue, skb);
627 wake_up_interruptible(&cdev->recvwait); 640 wake_up_interruptible(&cdev->recvwait);
641 spin_unlock_irqrestore(&workaround_lock, flags);
628 return; 642 return;
629 } 643 }
630 644
@@ -660,6 +674,7 @@ static void capi_recv_message(struct capi20_appl *ap, struct sk_buff *skb)
660 wake_up_interruptible(&cdev->recvwait); 674 wake_up_interruptible(&cdev->recvwait);
661 } 675 }
662#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ 676#endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */
677 spin_unlock_irqrestore(&workaround_lock, flags);
663} 678}
664 679
665/* -------- file_operations for capidev ----------------------------- */ 680/* -------- file_operations for capidev ----------------------------- */
@@ -988,7 +1003,7 @@ capi_release(struct inode *inode, struct file *file)
988 return 0; 1003 return 0;
989} 1004}
990 1005
991static struct file_operations capi_fops = 1006static const struct file_operations capi_fops =
992{ 1007{
993 .owner = THIS_MODULE, 1008 .owner = THIS_MODULE,
994 .llseek = no_llseek, 1009 .llseek = no_llseek,
@@ -1006,6 +1021,7 @@ static struct file_operations capi_fops =
1006static int capinc_tty_open(struct tty_struct * tty, struct file * file) 1021static int capinc_tty_open(struct tty_struct * tty, struct file * file)
1007{ 1022{
1008 struct capiminor *mp; 1023 struct capiminor *mp;
1024 unsigned long flags;
1009 1025
1010 if ((mp = capiminor_find(iminor(file->f_path.dentry->d_inode))) == 0) 1026 if ((mp = capiminor_find(iminor(file->f_path.dentry->d_inode))) == 0)
1011 return -ENXIO; 1027 return -ENXIO;
@@ -1014,6 +1030,7 @@ static int capinc_tty_open(struct tty_struct * tty, struct file * file)
1014 1030
1015 tty->driver_data = (void *)mp; 1031 tty->driver_data = (void *)mp;
1016 1032
1033 spin_lock_irqsave(&workaround_lock, flags);
1017 if (atomic_read(&mp->ttyopencount) == 0) 1034 if (atomic_read(&mp->ttyopencount) == 0)
1018 mp->tty = tty; 1035 mp->tty = tty;
1019 atomic_inc(&mp->ttyopencount); 1036 atomic_inc(&mp->ttyopencount);
@@ -1021,6 +1038,7 @@ static int capinc_tty_open(struct tty_struct * tty, struct file * file)
1021 printk(KERN_DEBUG "capinc_tty_open ocount=%d\n", atomic_read(&mp->ttyopencount)); 1038 printk(KERN_DEBUG "capinc_tty_open ocount=%d\n", atomic_read(&mp->ttyopencount));
1022#endif 1039#endif
1023 handle_minor_recv(mp); 1040 handle_minor_recv(mp);
1041 spin_unlock_irqrestore(&workaround_lock, flags);
1024 return 0; 1042 return 0;
1025} 1043}
1026 1044
@@ -1054,6 +1072,7 @@ static int capinc_tty_write(struct tty_struct * tty,
1054{ 1072{
1055 struct capiminor *mp = (struct capiminor *)tty->driver_data; 1073 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1056 struct sk_buff *skb; 1074 struct sk_buff *skb;
1075 unsigned long flags;
1057 1076
1058#ifdef _DEBUG_TTYFUNCS 1077#ifdef _DEBUG_TTYFUNCS
1059 printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count); 1078 printk(KERN_DEBUG "capinc_tty_write(count=%d)\n", count);
@@ -1066,6 +1085,7 @@ static int capinc_tty_write(struct tty_struct * tty,
1066 return 0; 1085 return 0;
1067 } 1086 }
1068 1087
1088 spin_lock_irqsave(&workaround_lock, flags);
1069 skb = mp->ttyskb; 1089 skb = mp->ttyskb;
1070 if (skb) { 1090 if (skb) {
1071 mp->ttyskb = NULL; 1091 mp->ttyskb = NULL;
@@ -1076,6 +1096,7 @@ static int capinc_tty_write(struct tty_struct * tty,
1076 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_ATOMIC); 1096 skb = alloc_skb(CAPI_DATA_B3_REQ_LEN+count, GFP_ATOMIC);
1077 if (!skb) { 1097 if (!skb) {
1078 printk(KERN_ERR "capinc_tty_write: alloc_skb failed\n"); 1098 printk(KERN_ERR "capinc_tty_write: alloc_skb failed\n");
1099 spin_unlock_irqrestore(&workaround_lock, flags);
1079 return -ENOMEM; 1100 return -ENOMEM;
1080 } 1101 }
1081 1102
@@ -1086,6 +1107,7 @@ static int capinc_tty_write(struct tty_struct * tty,
1086 mp->outbytes += skb->len; 1107 mp->outbytes += skb->len;
1087 (void)handle_minor_send(mp); 1108 (void)handle_minor_send(mp);
1088 (void)handle_minor_recv(mp); 1109 (void)handle_minor_recv(mp);
1110 spin_unlock_irqrestore(&workaround_lock, flags);
1089 return count; 1111 return count;
1090} 1112}
1091 1113
@@ -1093,6 +1115,7 @@ static void capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
1093{ 1115{
1094 struct capiminor *mp = (struct capiminor *)tty->driver_data; 1116 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1095 struct sk_buff *skb; 1117 struct sk_buff *skb;
1118 unsigned long flags;
1096 1119
1097#ifdef _DEBUG_TTYFUNCS 1120#ifdef _DEBUG_TTYFUNCS
1098 printk(KERN_DEBUG "capinc_put_char(%u)\n", ch); 1121 printk(KERN_DEBUG "capinc_put_char(%u)\n", ch);
@@ -1105,10 +1128,12 @@ static void capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
1105 return; 1128 return;
1106 } 1129 }
1107 1130
1131 spin_lock_irqsave(&workaround_lock, flags);
1108 skb = mp->ttyskb; 1132 skb = mp->ttyskb;
1109 if (skb) { 1133 if (skb) {
1110 if (skb_tailroom(skb) > 0) { 1134 if (skb_tailroom(skb) > 0) {
1111 *(skb_put(skb, 1)) = ch; 1135 *(skb_put(skb, 1)) = ch;
1136 spin_unlock_irqrestore(&workaround_lock, flags);
1112 return; 1137 return;
1113 } 1138 }
1114 mp->ttyskb = NULL; 1139 mp->ttyskb = NULL;
@@ -1124,12 +1149,14 @@ static void capinc_tty_put_char(struct tty_struct *tty, unsigned char ch)
1124 } else { 1149 } else {
1125 printk(KERN_ERR "capinc_put_char: char %u lost\n", ch); 1150 printk(KERN_ERR "capinc_put_char: char %u lost\n", ch);
1126 } 1151 }
1152 spin_unlock_irqrestore(&workaround_lock, flags);
1127} 1153}
1128 1154
1129static void capinc_tty_flush_chars(struct tty_struct *tty) 1155static void capinc_tty_flush_chars(struct tty_struct *tty)
1130{ 1156{
1131 struct capiminor *mp = (struct capiminor *)tty->driver_data; 1157 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1132 struct sk_buff *skb; 1158 struct sk_buff *skb;
1159 unsigned long flags;
1133 1160
1134#ifdef _DEBUG_TTYFUNCS 1161#ifdef _DEBUG_TTYFUNCS
1135 printk(KERN_DEBUG "capinc_tty_flush_chars\n"); 1162 printk(KERN_DEBUG "capinc_tty_flush_chars\n");
@@ -1142,6 +1169,7 @@ static void capinc_tty_flush_chars(struct tty_struct *tty)
1142 return; 1169 return;
1143 } 1170 }
1144 1171
1172 spin_lock_irqsave(&workaround_lock, flags);
1145 skb = mp->ttyskb; 1173 skb = mp->ttyskb;
1146 if (skb) { 1174 if (skb) {
1147 mp->ttyskb = NULL; 1175 mp->ttyskb = NULL;
@@ -1150,6 +1178,7 @@ static void capinc_tty_flush_chars(struct tty_struct *tty)
1150 (void)handle_minor_send(mp); 1178 (void)handle_minor_send(mp);
1151 } 1179 }
1152 (void)handle_minor_recv(mp); 1180 (void)handle_minor_recv(mp);
1181 spin_unlock_irqrestore(&workaround_lock, flags);
1153} 1182}
1154 1183
1155static int capinc_tty_write_room(struct tty_struct *tty) 1184static int capinc_tty_write_room(struct tty_struct *tty)
@@ -1220,12 +1249,15 @@ static void capinc_tty_throttle(struct tty_struct * tty)
1220static void capinc_tty_unthrottle(struct tty_struct * tty) 1249static void capinc_tty_unthrottle(struct tty_struct * tty)
1221{ 1250{
1222 struct capiminor *mp = (struct capiminor *)tty->driver_data; 1251 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1252 unsigned long flags;
1223#ifdef _DEBUG_TTYFUNCS 1253#ifdef _DEBUG_TTYFUNCS
1224 printk(KERN_DEBUG "capinc_tty_unthrottle\n"); 1254 printk(KERN_DEBUG "capinc_tty_unthrottle\n");
1225#endif 1255#endif
1226 if (mp) { 1256 if (mp) {
1257 spin_lock_irqsave(&workaround_lock, flags);
1227 mp->ttyinstop = 0; 1258 mp->ttyinstop = 0;
1228 handle_minor_recv(mp); 1259 handle_minor_recv(mp);
1260 spin_unlock_irqrestore(&workaround_lock, flags);
1229 } 1261 }
1230} 1262}
1231 1263
@@ -1243,12 +1275,15 @@ static void capinc_tty_stop(struct tty_struct *tty)
1243static void capinc_tty_start(struct tty_struct *tty) 1275static void capinc_tty_start(struct tty_struct *tty)
1244{ 1276{
1245 struct capiminor *mp = (struct capiminor *)tty->driver_data; 1277 struct capiminor *mp = (struct capiminor *)tty->driver_data;
1278 unsigned long flags;
1246#ifdef _DEBUG_TTYFUNCS 1279#ifdef _DEBUG_TTYFUNCS
1247 printk(KERN_DEBUG "capinc_tty_start\n"); 1280 printk(KERN_DEBUG "capinc_tty_start\n");
1248#endif 1281#endif
1249 if (mp) { 1282 if (mp) {
1283 spin_lock_irqsave(&workaround_lock, flags);
1250 mp->ttyoutstop = 0; 1284 mp->ttyoutstop = 0;
1251 (void)handle_minor_send(mp); 1285 (void)handle_minor_send(mp);
1286 spin_unlock_irqrestore(&workaround_lock, flags);
1252 } 1287 }
1253} 1288}
1254 1289
@@ -1456,7 +1491,7 @@ static struct procfsentries {
1456 1491
1457static void __init proc_init(void) 1492static void __init proc_init(void)
1458{ 1493{
1459 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]); 1494 int nelem = ARRAY_SIZE(procfsentries);
1460 int i; 1495 int i;
1461 1496
1462 for (i=0; i < nelem; i++) { 1497 for (i=0; i < nelem; i++) {
@@ -1468,7 +1503,7 @@ static void __init proc_init(void)
1468 1503
1469static void __exit proc_exit(void) 1504static void __exit proc_exit(void)
1470{ 1505{
1471 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]); 1506 int nelem = ARRAY_SIZE(procfsentries);
1472 int i; 1507 int i;
1473 1508
1474 for (i=nelem-1; i >= 0; i--) { 1509 for (i=nelem-1; i >= 0; i--) {
diff --git a/drivers/isdn/capi/capidrv.c b/drivers/isdn/capi/capidrv.c
index c4d438c17da..8cec9c3898e 100644
--- a/drivers/isdn/capi/capidrv.c
+++ b/drivers/isdn/capi/capidrv.c
@@ -2218,7 +2218,7 @@ static struct procfsentries {
2218 2218
2219static void __init proc_init(void) 2219static void __init proc_init(void)
2220{ 2220{
2221 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]); 2221 int nelem = ARRAY_SIZE(procfsentries);
2222 int i; 2222 int i;
2223 2223
2224 for (i=0; i < nelem; i++) { 2224 for (i=0; i < nelem; i++) {
@@ -2230,7 +2230,7 @@ static void __init proc_init(void)
2230 2230
2231static void __exit proc_exit(void) 2231static void __exit proc_exit(void)
2232{ 2232{
2233 int nelem = sizeof(procfsentries)/sizeof(procfsentries[0]); 2233 int nelem = ARRAY_SIZE(procfsentries);
2234 int i; 2234 int i;
2235 2235
2236 for (i=nelem-1; i >= 0; i--) { 2236 for (i=nelem-1; i >= 0; i--) {
diff --git a/drivers/isdn/capi/kcapi_proc.c b/drivers/isdn/capi/kcapi_proc.c
index ca9dc00a45c..31f4fd8b8b0 100644
--- a/drivers/isdn/capi/kcapi_proc.c
+++ b/drivers/isdn/capi/kcapi_proc.c
@@ -113,14 +113,14 @@ static int seq_contrstats_open(struct inode *inode, struct file *file)
113 return seq_open(file, &seq_contrstats_ops); 113 return seq_open(file, &seq_contrstats_ops);
114} 114}
115 115
116static struct file_operations proc_controller_ops = { 116static const struct file_operations proc_controller_ops = {
117 .open = seq_controller_open, 117 .open = seq_controller_open,
118 .read = seq_read, 118 .read = seq_read,
119 .llseek = seq_lseek, 119 .llseek = seq_lseek,
120 .release = seq_release, 120 .release = seq_release,
121}; 121};
122 122
123static struct file_operations proc_contrstats_ops = { 123static const struct file_operations proc_contrstats_ops = {
124 .open = seq_contrstats_open, 124 .open = seq_contrstats_open,
125 .read = seq_read, 125 .read = seq_read,
126 .llseek = seq_lseek, 126 .llseek = seq_lseek,
@@ -218,14 +218,14 @@ seq_applstats_open(struct inode *inode, struct file *file)
218 return seq_open(file, &seq_applstats_ops); 218 return seq_open(file, &seq_applstats_ops);
219} 219}
220 220
221static struct file_operations proc_applications_ops = { 221static const struct file_operations proc_applications_ops = {
222 .open = seq_applications_open, 222 .open = seq_applications_open,
223 .read = seq_read, 223 .read = seq_read,
224 .llseek = seq_lseek, 224 .llseek = seq_lseek,
225 .release = seq_release, 225 .release = seq_release,
226}; 226};
227 227
228static struct file_operations proc_applstats_ops = { 228static const struct file_operations proc_applstats_ops = {
229 .open = seq_applstats_open, 229 .open = seq_applstats_open,
230 .read = seq_read, 230 .read = seq_read,
231 .llseek = seq_lseek, 231 .llseek = seq_lseek,
@@ -302,7 +302,7 @@ seq_capi_driver_open(struct inode *inode, struct file *file)
302 return err; 302 return err;
303} 303}
304 304
305static struct file_operations proc_driver_ops = { 305static const struct file_operations proc_driver_ops = {
306 .open = seq_capi_driver_open, 306 .open = seq_capi_driver_open,
307 .read = seq_read, 307 .read = seq_read,
308 .llseek = seq_lseek, 308 .llseek = seq_lseek,
diff --git a/drivers/isdn/divert/divert_procfs.c b/drivers/isdn/divert/divert_procfs.c
index 06967da7c4a..53a18900335 100644
--- a/drivers/isdn/divert/divert_procfs.c
+++ b/drivers/isdn/divert/divert_procfs.c
@@ -256,7 +256,7 @@ isdn_divert_ioctl(struct inode *inode, struct file *file,
256 256
257 257
258#ifdef CONFIG_PROC_FS 258#ifdef CONFIG_PROC_FS
259static struct file_operations isdn_fops = 259static const struct file_operations isdn_fops =
260{ 260{
261 .owner = THIS_MODULE, 261 .owner = THIS_MODULE,
262 .llseek = no_llseek, 262 .llseek = no_llseek,
diff --git a/drivers/isdn/gigaset/Kconfig b/drivers/isdn/gigaset/Kconfig
index 708d47a6484..bcbb6502a77 100644
--- a/drivers/isdn/gigaset/Kconfig
+++ b/drivers/isdn/gigaset/Kconfig
@@ -7,7 +7,13 @@ config ISDN_DRV_GIGASET
7 select CRC_CCITT 7 select CRC_CCITT
8 select BITREVERSE 8 select BITREVERSE
9 help 9 help
10 Say m here if you have a Gigaset or Sinus isdn device. 10 This driver supports the Siemens Gigaset SX205/255 family of
11 ISDN DECT bases, including the predecessors Gigaset 3070/3075
12 and 4170/4175 and their T-Com versions Sinus 45isdn and Sinus
13 721X.
14 If you have one of these devices, say M here and for at least
15 one of the connection specific parts that follow.
16 This will build a module called "gigaset".
11 17
12if ISDN_DRV_GIGASET!=n 18if ISDN_DRV_GIGASET!=n
13 19
@@ -15,14 +21,25 @@ config GIGASET_BASE
15 tristate "Gigaset base station support" 21 tristate "Gigaset base station support"
16 depends on ISDN_DRV_GIGASET && USB 22 depends on ISDN_DRV_GIGASET && USB
17 help 23 help
18 Say m here if you need to communicate with the base 24 Say M here if you want to use the USB interface of the Gigaset
19 directly via USB. 25 base for connection to your system.
26 This will build a module called "bas_gigaset".
20 27
21config GIGASET_M105 28config GIGASET_M105
22 tristate "Gigaset M105 support" 29 tristate "Gigaset M105 support"
23 depends on ISDN_DRV_GIGASET && USB 30 depends on ISDN_DRV_GIGASET && USB
24 help 31 help
25 Say m here if you need the driver for the Gigaset M105 device. 32 Say M here if you want to connect to the Gigaset base via DECT
33 using a Gigaset M105 (Sinus 45 Data 2) USB DECT device.
34 This will build a module called "usb_gigaset".
35
36config GIGASET_M101
37 tristate "Gigaset M101 support"
38 depends on ISDN_DRV_GIGASET
39 help
40 Say M here if you want to connect to the Gigaset base via DECT
41 using a Gigaset M101 (Sinus 45 Data 1) RS232 DECT device.
42 This will build a module called "ser_gigaset".
26 43
27config GIGASET_DEBUG 44config GIGASET_DEBUG
28 bool "Gigaset debugging" 45 bool "Gigaset debugging"
diff --git a/drivers/isdn/gigaset/Makefile b/drivers/isdn/gigaset/Makefile
index 9b9acf1a21a..835b806a9de 100644
--- a/drivers/isdn/gigaset/Makefile
+++ b/drivers/isdn/gigaset/Makefile
@@ -1,6 +1,8 @@
1gigaset-y := common.o interface.o proc.o ev-layer.o i4l.o 1gigaset-y := common.o interface.o proc.o ev-layer.o i4l.o
2usb_gigaset-y := usb-gigaset.o asyncdata.o 2usb_gigaset-y := usb-gigaset.o asyncdata.o
3bas_gigaset-y := bas-gigaset.o isocdata.o 3bas_gigaset-y := bas-gigaset.o isocdata.o
4ser_gigaset-y := ser-gigaset.o asyncdata.o
4 5
5obj-$(CONFIG_GIGASET_M105) += usb_gigaset.o gigaset.o 6obj-$(CONFIG_GIGASET_M105) += usb_gigaset.o gigaset.o
6obj-$(CONFIG_GIGASET_BASE) += bas_gigaset.o gigaset.o 7obj-$(CONFIG_GIGASET_BASE) += bas_gigaset.o gigaset.o
8obj-$(CONFIG_GIGASET_M105) += ser_gigaset.o gigaset.o
diff --git a/drivers/isdn/gigaset/asyncdata.c b/drivers/isdn/gigaset/asyncdata.c
index 88e958f176d..ddf5e92be44 100644
--- a/drivers/isdn/gigaset/asyncdata.c
+++ b/drivers/isdn/gigaset/asyncdata.c
@@ -13,6 +13,11 @@
13 * ===================================================================== 13 * =====================================================================
14 */ 14 */
15 15
16/* not set by Kbuild when building both ser_gigaset and usb_gigaset */
17#ifndef KBUILD_MODNAME
18#define KBUILD_MODNAME "asy_gigaset"
19#endif
20
16#include "gigaset.h" 21#include "gigaset.h"
17#include <linux/crc-ccitt.h> 22#include <linux/crc-ccitt.h>
18#include <linux/bitrev.h> 23#include <linux/bitrev.h>
diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
index b5e7f9c7d74..63e51dd6deb 100644
--- a/drivers/isdn/gigaset/bas-gigaset.c
+++ b/drivers/isdn/gigaset/bas-gigaset.c
@@ -257,10 +257,10 @@ static inline void dump_urb(enum debuglevel level, const char *tag,
257 urb->transfer_flags); 257 urb->transfer_flags);
258 gig_dbg(level, 258 gig_dbg(level,
259 " transfer_buffer=0x%08lx[%d], actual_length=%d, " 259 " transfer_buffer=0x%08lx[%d], actual_length=%d, "
260 "bandwidth=%d, setup_packet=0x%08lx,", 260 "setup_packet=0x%08lx,",
261 (unsigned long) urb->transfer_buffer, 261 (unsigned long) urb->transfer_buffer,
262 urb->transfer_buffer_length, urb->actual_length, 262 urb->transfer_buffer_length, urb->actual_length,
263 urb->bandwidth, (unsigned long) urb->setup_packet); 263 (unsigned long) urb->setup_packet);
264 gig_dbg(level, 264 gig_dbg(level,
265 " start_frame=%d, number_of_packets=%d, interval=%d, " 265 " start_frame=%d, number_of_packets=%d, interval=%d, "
266 "error_count=%d,", 266 "error_count=%d,",
diff --git a/drivers/isdn/gigaset/common.c b/drivers/isdn/gigaset/common.c
index 4f75cce6fdf..b460a73a7c8 100644
--- a/drivers/isdn/gigaset/common.c
+++ b/drivers/isdn/gigaset/common.c
@@ -640,7 +640,6 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
640 return NULL; 640 return NULL;
641 } 641 }
642 mutex_init(&cs->mutex); 642 mutex_init(&cs->mutex);
643 mutex_lock(&cs->mutex);
644 643
645 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1); 644 gig_dbg(DEBUG_INIT, "allocating bcs[0..%d]", channels - 1);
646 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL); 645 cs->bcs = kmalloc(channels * sizeof(struct bc_state), GFP_KERNEL);
@@ -738,6 +737,7 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
738 737
739 ++cs->cs_init; 738 ++cs->cs_init;
740 739
740 /* set up character device */
741 gigaset_if_init(cs); 741 gigaset_if_init(cs);
742 742
743 /* set up device sysfs */ 743 /* set up device sysfs */
@@ -753,11 +753,9 @@ struct cardstate *gigaset_initcs(struct gigaset_driver *drv, int channels,
753 add_timer(&cs->timer); 753 add_timer(&cs->timer);
754 754
755 gig_dbg(DEBUG_INIT, "cs initialized"); 755 gig_dbg(DEBUG_INIT, "cs initialized");
756 mutex_unlock(&cs->mutex);
757 return cs; 756 return cs;
758 757
759error: 758error:
760 mutex_unlock(&cs->mutex);
761 gig_dbg(DEBUG_INIT, "failed"); 759 gig_dbg(DEBUG_INIT, "failed");
762 gigaset_freecs(cs); 760 gigaset_freecs(cs);
763 return NULL; 761 return NULL;
@@ -908,20 +906,7 @@ void gigaset_shutdown(struct cardstate *cs)
908 gig_dbg(DEBUG_CMD, "scheduling SHUTDOWN"); 906 gig_dbg(DEBUG_CMD, "scheduling SHUTDOWN");
909 gigaset_schedule_event(cs); 907 gigaset_schedule_event(cs);
910 908
911 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) { 909 wait_event(cs->waitqueue, !cs->waiting);
912 warn("%s: aborted", __func__);
913 //FIXME
914 }
915
916 if (atomic_read(&cs->mstate) != MS_LOCKED) {
917 //FIXME?
918 //gigaset_baud_rate(cs, B115200);
919 //gigaset_set_line_ctrl(cs, CS8);
920 //gigaset_set_modem_ctrl(cs, TIOCM_DTR|TIOCM_RTS, 0);
921 //cs->control_state = 0;
922 } else {
923 //FIXME use some saved values?
924 }
925 910
926 cleanup_cs(cs); 911 cleanup_cs(cs);
927 912
@@ -944,10 +929,7 @@ void gigaset_stop(struct cardstate *cs)
944 gig_dbg(DEBUG_CMD, "scheduling STOP"); 929 gig_dbg(DEBUG_CMD, "scheduling STOP");
945 gigaset_schedule_event(cs); 930 gigaset_schedule_event(cs);
946 931
947 if (wait_event_interruptible(cs->waitqueue, !cs->waiting)) { 932 wait_event(cs->waitqueue, !cs->waiting);
948 warn("%s: aborted", __func__);
949 //FIXME
950 }
951 933
952 cleanup_cs(cs); 934 cleanup_cs(cs);
953 935
diff --git a/drivers/isdn/gigaset/ev-layer.c b/drivers/isdn/gigaset/ev-layer.c
index 44f02dbd111..4661e2c722b 100644
--- a/drivers/isdn/gigaset/ev-layer.c
+++ b/drivers/isdn/gigaset/ev-layer.c
@@ -1015,7 +1015,7 @@ static void finish_shutdown(struct cardstate *cs)
1015 1015
1016 cs->cmd_result = -ENODEV; 1016 cs->cmd_result = -ENODEV;
1017 cs->waiting = 0; 1017 cs->waiting = 0;
1018 wake_up_interruptible(&cs->waitqueue); 1018 wake_up(&cs->waitqueue);
1019} 1019}
1020 1020
1021static void do_shutdown(struct cardstate *cs) 1021static void do_shutdown(struct cardstate *cs)
diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
index 458b6462f93..eb50f3dab5f 100644
--- a/drivers/isdn/gigaset/interface.c
+++ b/drivers/isdn/gigaset/interface.c
@@ -599,19 +599,9 @@ out:
599static void if_wake(unsigned long data) 599static void if_wake(unsigned long data)
600{ 600{
601 struct cardstate *cs = (struct cardstate *) data; 601 struct cardstate *cs = (struct cardstate *) data;
602 struct tty_struct *tty;
603
604 tty = cs->tty;
605 if (!tty)
606 return;
607
608 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
609 tty->ldisc.write_wakeup) {
610 gig_dbg(DEBUG_IF, "write wakeup call");
611 tty->ldisc.write_wakeup(tty);
612 }
613 602
614 wake_up_interruptible(&tty->write_wait); 603 if (cs->tty)
604 tty_wakeup(cs->tty);
615} 605}
616 606
617/*** interface to common ***/ 607/*** interface to common ***/
@@ -625,6 +615,8 @@ void gigaset_if_init(struct cardstate *cs)
625 return; 615 return;
626 616
627 tasklet_init(&cs->if_wake_tasklet, &if_wake, (unsigned long) cs); 617 tasklet_init(&cs->if_wake_tasklet, &if_wake, (unsigned long) cs);
618
619 mutex_lock(&cs->mutex);
628 cs->tty_dev = tty_register_device(drv->tty, cs->minor_index, NULL); 620 cs->tty_dev = tty_register_device(drv->tty, cs->minor_index, NULL);
629 621
630 if (!IS_ERR(cs->tty_dev)) 622 if (!IS_ERR(cs->tty_dev))
@@ -633,6 +625,7 @@ void gigaset_if_init(struct cardstate *cs)
633 warn("could not register device to the tty subsystem"); 625 warn("could not register device to the tty subsystem");
634 cs->tty_dev = NULL; 626 cs->tty_dev = NULL;
635 } 627 }
628 mutex_unlock(&cs->mutex);
636} 629}
637 630
638void gigaset_if_free(struct cardstate *cs) 631void gigaset_if_free(struct cardstate *cs)
diff --git a/drivers/isdn/gigaset/isocdata.c b/drivers/isdn/gigaset/isocdata.c
index df988eb0e36..8c0eb522dab 100644
--- a/drivers/isdn/gigaset/isocdata.c
+++ b/drivers/isdn/gigaset/isocdata.c
@@ -921,6 +921,8 @@ static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf)
921 /* end of line */ 921 /* end of line */
922 gig_dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)", 922 gig_dbg(DEBUG_TRANSCMD, "%s: End of Command (%d Bytes)",
923 __func__, cbytes); 923 __func__, cbytes);
924 if (cbytes >= MAX_RESP_SIZE - 1)
925 dev_warn(cs->dev, "response too large\n");
924 cs->cbytes = cbytes; 926 cs->cbytes = cbytes;
925 gigaset_handle_modem_response(cs); 927 gigaset_handle_modem_response(cs);
926 cbytes = 0; 928 cbytes = 0;
@@ -929,8 +931,6 @@ static void cmd_loop(unsigned char *src, int numbytes, struct inbuf_t *inbuf)
929 /* advance in line buffer, checking for overflow */ 931 /* advance in line buffer, checking for overflow */
930 if (cbytes < MAX_RESP_SIZE - 1) 932 if (cbytes < MAX_RESP_SIZE - 1)
931 cbytes++; 933 cbytes++;
932 else
933 dev_warn(cs->dev, "response too large\n");
934 } 934 }
935 } 935 }
936 936
diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
new file mode 100644
index 00000000000..c8b7db65e48
--- /dev/null
+++ b/drivers/isdn/gigaset/ser-gigaset.c
@@ -0,0 +1,837 @@
1/* This is the serial hardware link layer (HLL) for the Gigaset 307x isdn
2 * DECT base (aka Sinus 45 isdn) using the RS232 DECT data module M101,
3 * written as a line discipline.
4 *
5 * =====================================================================
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 * =====================================================================
11 */
12
13#include "gigaset.h"
14
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/platform_device.h>
18#include <linux/tty.h>
19#include <linux/poll.h>
20
21/* Version Information */
22#define DRIVER_AUTHOR "Tilman Schmidt"
23#define DRIVER_DESC "Serial Driver for Gigaset 307x using Siemens M101"
24
25#define GIGASET_MINORS 1
26#define GIGASET_MINOR 0
27#define GIGASET_MODULENAME "ser_gigaset"
28#define GIGASET_DEVNAME "ttyGS"
29
30/* length limit according to Siemens 3070usb-protokoll.doc ch. 2.1 */
31#define IF_WRITEBUF 264
32
33MODULE_AUTHOR(DRIVER_AUTHOR);
34MODULE_DESCRIPTION(DRIVER_DESC);
35MODULE_LICENSE("GPL");
36MODULE_ALIAS_LDISC(N_GIGASET_M101);
37
38static int startmode = SM_ISDN;
39module_param(startmode, int, S_IRUGO);
40MODULE_PARM_DESC(startmode, "initial operation mode");
41static int cidmode = 1;
42module_param(cidmode, int, S_IRUGO);
43MODULE_PARM_DESC(cidmode, "stay in CID mode when idle");
44
45static struct gigaset_driver *driver;
46
47struct ser_cardstate {
48 struct platform_device dev;
49 struct tty_struct *tty;
50 atomic_t refcnt;
51 struct mutex dead_mutex;
52};
53
54static struct platform_driver device_driver = {
55 .driver = {
56 .name = GIGASET_MODULENAME,
57 },
58};
59
60static void flush_send_queue(struct cardstate *);
61
62/* transmit data from current open skb
63 * result: number of bytes sent or error code < 0
64 */
65static int write_modem(struct cardstate *cs)
66{
67 struct tty_struct *tty = cs->hw.ser->tty;
68 struct bc_state *bcs = &cs->bcs[0]; /* only one channel */
69 struct sk_buff *skb = bcs->tx_skb;
70 int sent;
71
72 if (!tty || !tty->driver || !skb)
73 return -EFAULT;
74
75 if (!skb->len) {
76 dev_kfree_skb_any(skb);
77 bcs->tx_skb = NULL;
78 return -EINVAL;
79 }
80
81 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
82 sent = tty->driver->write(tty, skb->data, skb->len);
83 gig_dbg(DEBUG_OUTPUT, "write_modem: sent %d", sent);
84 if (sent < 0) {
85 /* error */
86 flush_send_queue(cs);
87 return sent;
88 }
89 skb_pull(skb, sent);
90 if (!skb->len) {
91 /* skb sent completely */
92 gigaset_skb_sent(bcs, skb);
93
94 gig_dbg(DEBUG_INTR, "kfree skb (Adr: %lx)!",
95 (unsigned long) skb);
96 dev_kfree_skb_any(skb);
97 bcs->tx_skb = NULL;
98 }
99 return sent;
100}
101
102/*
103 * transmit first queued command buffer
104 * result: number of bytes sent or error code < 0
105 */
106static int send_cb(struct cardstate *cs)
107{
108 struct tty_struct *tty = cs->hw.ser->tty;
109 struct cmdbuf_t *cb, *tcb;
110 unsigned long flags;
111 int sent = 0;
112
113 if (!tty || !tty->driver)
114 return -EFAULT;
115
116 cb = cs->cmdbuf;
117 if (!cb)
118 return 0; /* nothing to do */
119
120 if (cb->len) {
121 set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
122 sent = tty->driver->write(tty, cb->buf + cb->offset, cb->len);
123 if (sent < 0) {
124 /* error */
125 gig_dbg(DEBUG_OUTPUT, "send_cb: write error %d", sent);
126 flush_send_queue(cs);
127 return sent;
128 }
129 cb->offset += sent;
130 cb->len -= sent;
131 gig_dbg(DEBUG_OUTPUT, "send_cb: sent %d, left %u, queued %u",
132 sent, cb->len, cs->cmdbytes);
133 }
134
135 while (cb && !cb->len) {
136 spin_lock_irqsave(&cs->cmdlock, flags);
137 cs->cmdbytes -= cs->curlen;
138 tcb = cb;
139 cs->cmdbuf = cb = cb->next;
140 if (cb) {
141 cb->prev = NULL;
142 cs->curlen = cb->len;
143 } else {
144 cs->lastcmdbuf = NULL;
145 cs->curlen = 0;
146 }
147 spin_unlock_irqrestore(&cs->cmdlock, flags);
148
149 if (tcb->wake_tasklet)
150 tasklet_schedule(tcb->wake_tasklet);
151 kfree(tcb);
152 }
153 return sent;
154}
155
156/*
157 * send queue tasklet
158 * If there is already a skb opened, put data to the transfer buffer
159 * by calling "write_modem".
160 * Otherwise take a new skb out of the queue.
161 */
162static void gigaset_modem_fill(unsigned long data)
163{
164 struct cardstate *cs = (struct cardstate *) data;
165 struct bc_state *bcs;
166 int sent = 0;
167
168 if (!cs || !(bcs = cs->bcs)) {
169 gig_dbg(DEBUG_OUTPUT, "%s: no cardstate", __func__);
170 return;
171 }
172 if (!bcs->tx_skb) {
173 /* no skb is being sent; send command if any */
174 sent = send_cb(cs);
175 gig_dbg(DEBUG_OUTPUT, "%s: send_cb -> %d", __func__, sent);
176 if (sent)
177 /* something sent or error */
178 return;
179
180 /* no command to send; get skb */
181 if (!(bcs->tx_skb = skb_dequeue(&bcs->squeue)))
182 /* no skb either, nothing to do */
183 return;
184
185 gig_dbg(DEBUG_INTR, "Dequeued skb (Adr: %lx)",
186 (unsigned long) bcs->tx_skb);
187 }
188
189 /* send skb */
190 gig_dbg(DEBUG_OUTPUT, "%s: tx_skb", __func__);
191 if (write_modem(cs) < 0)
192 gig_dbg(DEBUG_OUTPUT, "%s: write_modem failed", __func__);
193}
194
195/*
196 * throw away all data queued for sending
197 */
198static void flush_send_queue(struct cardstate *cs)
199{
200 struct sk_buff *skb;
201 struct cmdbuf_t *cb;
202 unsigned long flags;
203
204 /* command queue */
205 spin_lock_irqsave(&cs->cmdlock, flags);
206 while ((cb = cs->cmdbuf) != NULL) {
207 cs->cmdbuf = cb->next;
208 if (cb->wake_tasklet)
209 tasklet_schedule(cb->wake_tasklet);
210 kfree(cb);
211 }
212 cs->cmdbuf = cs->lastcmdbuf = NULL;
213 cs->cmdbytes = cs->curlen = 0;
214 spin_unlock_irqrestore(&cs->cmdlock, flags);
215
216 /* data queue */
217 if (cs->bcs->tx_skb)
218 dev_kfree_skb_any(cs->bcs->tx_skb);
219 while ((skb = skb_dequeue(&cs->bcs->squeue)) != NULL)
220 dev_kfree_skb_any(skb);
221}
222
223
224/* Gigaset Driver Interface */
225/* ======================== */
226
227/*
228 * queue an AT command string for transmission to the Gigaset device
229 * parameters:
230 * cs controller state structure
231 * buf buffer containing the string to send
232 * len number of characters to send
233 * wake_tasklet tasklet to run when transmission is complete, or NULL
234 * return value:
235 * number of bytes queued, or error code < 0
236 */
237static int gigaset_write_cmd(struct cardstate *cs, const unsigned char *buf,
238 int len, struct tasklet_struct *wake_tasklet)
239{
240 struct cmdbuf_t *cb;
241 unsigned long flags;
242
243 gigaset_dbg_buffer(atomic_read(&cs->mstate) != MS_LOCKED ?
244 DEBUG_TRANSCMD : DEBUG_LOCKCMD,
245 "CMD Transmit", len, buf);
246
247 if (len <= 0)
248 return 0;
249
250 if (!(cb = kmalloc(sizeof(struct cmdbuf_t) + len, GFP_ATOMIC))) {
251 dev_err(cs->dev, "%s: out of memory!\n", __func__);
252 return -ENOMEM;
253 }
254
255 memcpy(cb->buf, buf, len);
256 cb->len = len;
257 cb->offset = 0;
258 cb->next = NULL;
259 cb->wake_tasklet = wake_tasklet;
260
261 spin_lock_irqsave(&cs->cmdlock, flags);
262 cb->prev = cs->lastcmdbuf;
263 if (cs->lastcmdbuf)
264 cs->lastcmdbuf->next = cb;
265 else {
266 cs->cmdbuf = cb;
267 cs->curlen = len;
268 }
269 cs->cmdbytes += len;
270 cs->lastcmdbuf = cb;
271 spin_unlock_irqrestore(&cs->cmdlock, flags);
272
273 spin_lock_irqsave(&cs->lock, flags);
274 if (cs->connected)
275 tasklet_schedule(&cs->write_tasklet);
276 spin_unlock_irqrestore(&cs->lock, flags);
277 return len;
278}
279
280/*
281 * tty_driver.write_room interface routine
282 * return number of characters the driver will accept to be written
283 * parameter:
284 * controller state structure
285 * return value:
286 * number of characters
287 */
288static int gigaset_write_room(struct cardstate *cs)
289{
290 unsigned bytes;
291
292 bytes = cs->cmdbytes;
293 return bytes < IF_WRITEBUF ? IF_WRITEBUF - bytes : 0;
294}
295
296/*
297 * tty_driver.chars_in_buffer interface routine
298 * return number of characters waiting to be sent
299 * parameter:
300 * controller state structure
301 * return value:
302 * number of characters
303 */
304static int gigaset_chars_in_buffer(struct cardstate *cs)
305{
306 return cs->cmdbytes;
307}
308
309/*
310 * implementation of ioctl(GIGASET_BRKCHARS)
311 * parameter:
312 * controller state structure
313 * return value:
314 * -EINVAL (unimplemented function)
315 */
316static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
317{
318 /* not implemented */
319 return -EINVAL;
320}
321
322/*
323 * Open B channel
324 * Called by "do_action" in ev-layer.c
325 */
326static int gigaset_init_bchannel(struct bc_state *bcs)
327{
328 /* nothing to do for M10x */
329 gigaset_bchannel_up(bcs);
330 return 0;
331}
332
333/*
334 * Close B channel
335 * Called by "do_action" in ev-layer.c
336 */
337static int gigaset_close_bchannel(struct bc_state *bcs)
338{
339 /* nothing to do for M10x */
340 gigaset_bchannel_down(bcs);
341 return 0;
342}
343
344/*
345 * Set up B channel structure
346 * This is called by "gigaset_initcs" in common.c
347 */
348static int gigaset_initbcshw(struct bc_state *bcs)
349{
350 /* unused */
351 bcs->hw.ser = NULL;
352 return 1;
353}
354
355/*
356 * Free B channel structure
357 * Called by "gigaset_freebcs" in common.c
358 */
359static int gigaset_freebcshw(struct bc_state *bcs)
360{
361 /* unused */
362 return 1;
363}
364
365/*
366 * Reinitialize B channel structure
367 * This is called by "bcs_reinit" in common.c
368 */
369static void gigaset_reinitbcshw(struct bc_state *bcs)
370{
371 /* nothing to do for M10x */
372}
373
374/*
375 * Free hardware specific device data
376 * This will be called by "gigaset_freecs" in common.c
377 */
378static void gigaset_freecshw(struct cardstate *cs)
379{
380 tasklet_kill(&cs->write_tasklet);
381 if (!cs->hw.ser)
382 return;
383 dev_set_drvdata(&cs->hw.ser->dev.dev, NULL);
384 platform_device_unregister(&cs->hw.ser->dev);
385 kfree(cs->hw.ser);
386 cs->hw.ser = NULL;
387}
388
389static void gigaset_device_release(struct device *dev)
390{
391 struct platform_device *pdev =
392 container_of(dev, struct platform_device, dev);
393
394 /* adapted from platform_device_release() in drivers/base/platform.c */
395 //FIXME is this actually necessary?
396 kfree(dev->platform_data);
397 kfree(pdev->resource);
398}
399
400/*
401 * Set up hardware specific device data
402 * This is called by "gigaset_initcs" in common.c
403 */
404static int gigaset_initcshw(struct cardstate *cs)
405{
406 int rc;
407
408 if (!(cs->hw.ser = kzalloc(sizeof(struct ser_cardstate), GFP_KERNEL))) {
409 err("%s: out of memory!", __func__);
410 return 0;
411 }
412
413 cs->hw.ser->dev.name = GIGASET_MODULENAME;
414 cs->hw.ser->dev.id = cs->minor_index;
415 cs->hw.ser->dev.dev.release = gigaset_device_release;
416 if ((rc = platform_device_register(&cs->hw.ser->dev)) != 0) {
417 err("error %d registering platform device", rc);
418 kfree(cs->hw.ser);
419 cs->hw.ser = NULL;
420 return 0;
421 }
422 dev_set_drvdata(&cs->hw.ser->dev.dev, cs);
423
424 tasklet_init(&cs->write_tasklet,
425 &gigaset_modem_fill, (unsigned long) cs);
426 return 1;
427}
428
429/*
430 * set modem control lines
431 * Parameters:
432 * card state structure
433 * modem control line state ([TIOCM_DTR]|[TIOCM_RTS])
434 * Called by "gigaset_start" and "gigaset_enterconfigmode" in common.c
435 * and by "if_lock" and "if_termios" in interface.c
436 */
437static int gigaset_set_modem_ctrl(struct cardstate *cs, unsigned old_state, unsigned new_state)
438{
439 struct tty_struct *tty = cs->hw.ser->tty;
440 unsigned int set, clear;
441
442 if (!tty || !tty->driver || !tty->driver->tiocmset)
443 return -EFAULT;
444 set = new_state & ~old_state;
445 clear = old_state & ~new_state;
446 if (!set && !clear)
447 return 0;
448 gig_dbg(DEBUG_IF, "tiocmset set %x clear %x", set, clear);
449 return tty->driver->tiocmset(tty, NULL, set, clear);
450}
451
452static int gigaset_baud_rate(struct cardstate *cs, unsigned cflag)
453{
454 return -EINVAL;
455}
456
457static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
458{
459 return -EINVAL;
460}
461
462static struct gigaset_ops ops = {
463 gigaset_write_cmd,
464 gigaset_write_room,
465 gigaset_chars_in_buffer,
466 gigaset_brkchars,
467 gigaset_init_bchannel,
468 gigaset_close_bchannel,
469 gigaset_initbcshw,
470 gigaset_freebcshw,
471 gigaset_reinitbcshw,
472 gigaset_initcshw,
473 gigaset_freecshw,
474 gigaset_set_modem_ctrl,
475 gigaset_baud_rate,
476 gigaset_set_line_ctrl,
477 gigaset_m10x_send_skb, /* asyncdata.c */
478 gigaset_m10x_input, /* asyncdata.c */
479};
480
481
482/* Line Discipline Interface */
483/* ========================= */
484
485/* helper functions for cardstate refcounting */
486static struct cardstate *cs_get(struct tty_struct *tty)
487{
488 struct cardstate *cs = tty->disc_data;
489
490 if (!cs || !cs->hw.ser) {
491 gig_dbg(DEBUG_ANY, "%s: no cardstate", __func__);
492 return NULL;
493 }
494 atomic_inc(&cs->hw.ser->refcnt);
495 return cs;
496}
497
498static void cs_put(struct cardstate *cs)
499{
500 if (atomic_dec_and_test(&cs->hw.ser->refcnt))
501 mutex_unlock(&cs->hw.ser->dead_mutex);
502}
503
504/*
505 * Called by the tty driver when the line discipline is pushed onto the tty.
506 * Called in process context.
507 */
508static int
509gigaset_tty_open(struct tty_struct *tty)
510{
511 struct cardstate *cs;
512
513 gig_dbg(DEBUG_INIT, "Starting HLL for Gigaset M101");
514
515 info(DRIVER_AUTHOR);
516 info(DRIVER_DESC);
517
518 if (!driver) {
519 err("%s: no driver structure", __func__);
520 return -ENODEV;
521 }
522
523 /* allocate memory for our device state and intialize it */
524 if (!(cs = gigaset_initcs(driver, 1, 1, 0, cidmode,
525 GIGASET_MODULENAME)))
526 goto error;
527
528 cs->dev = &cs->hw.ser->dev.dev;
529 cs->hw.ser->tty = tty;
530 mutex_init(&cs->hw.ser->dead_mutex);
531 atomic_set(&cs->hw.ser->refcnt, 1);
532
533 tty->disc_data = cs;
534
535 /* OK.. Initialization of the datastructures and the HW is done.. Now
536 * startup system and notify the LL that we are ready to run
537 */
538 if (startmode == SM_LOCKED)
539 atomic_set(&cs->mstate, MS_LOCKED);
540 if (!gigaset_start(cs)) {
541 tasklet_kill(&cs->write_tasklet);
542 goto error;
543 }
544
545 gig_dbg(DEBUG_INIT, "Startup of HLL done");
546 mutex_lock(&cs->hw.ser->dead_mutex);
547 return 0;
548
549error:
550 gig_dbg(DEBUG_INIT, "Startup of HLL failed");
551 tty->disc_data = NULL;
552 gigaset_freecs(cs);
553 return -ENODEV;
554}
555
556/*
557 * Called by the tty driver when the line discipline is removed.
558 * Called from process context.
559 */
560static void
561gigaset_tty_close(struct tty_struct *tty)
562{
563 struct cardstate *cs = tty->disc_data;
564
565 gig_dbg(DEBUG_INIT, "Stopping HLL for Gigaset M101");
566
567 if (!cs) {
568 gig_dbg(DEBUG_INIT, "%s: no cardstate", __func__);
569 return;
570 }
571
572 /* prevent other callers from entering ldisc methods */
573 tty->disc_data = NULL;
574
575 if (!cs->hw.ser)
576 err("%s: no hw cardstate", __func__);
577 else {
578 /* wait for running methods to finish */
579 if (!atomic_dec_and_test(&cs->hw.ser->refcnt))
580 mutex_lock(&cs->hw.ser->dead_mutex);
581 }
582
583 /* stop operations */
584 gigaset_stop(cs);
585 tasklet_kill(&cs->write_tasklet);
586 flush_send_queue(cs);
587 cs->dev = NULL;
588 gigaset_freecs(cs);
589
590 gig_dbg(DEBUG_INIT, "Shutdown of HLL done");
591}
592
593/*
594 * Called by the tty driver when the tty line is hung up.
595 * Wait for I/O to driver to complete and unregister ISDN device.
596 * This is already done by the close routine, so just call that.
597 * Called from process context.
598 */
599static int gigaset_tty_hangup(struct tty_struct *tty)
600{
601 gigaset_tty_close(tty);
602 return 0;
603}
604
605/*
606 * Read on the tty.
607 * Unused, received data goes only to the Gigaset driver.
608 */
609static ssize_t
610gigaset_tty_read(struct tty_struct *tty, struct file *file,
611 unsigned char __user *buf, size_t count)
612{
613 return -EAGAIN;
614}
615
616/*
617 * Write on the tty.
618 * Unused, transmit data comes only from the Gigaset driver.
619 */
620static ssize_t
621gigaset_tty_write(struct tty_struct *tty, struct file *file,
622 const unsigned char *buf, size_t count)
623{
624 return -EAGAIN;
625}
626
627/*
628 * Ioctl on the tty.
629 * Called in process context only.
630 * May be re-entered by multiple ioctl calling threads.
631 */
632static int
633gigaset_tty_ioctl(struct tty_struct *tty, struct file *file,
634 unsigned int cmd, unsigned long arg)
635{
636 struct cardstate *cs = cs_get(tty);
637 int rc, val;
638 int __user *p = (int __user *)arg;
639
640 if (!cs)
641 return -ENXIO;
642
643 switch (cmd) {
644 case TCGETS:
645 case TCGETA:
646 /* pass through to underlying serial device */
647 rc = n_tty_ioctl(tty, file, cmd, arg);
648 break;
649
650 case TCFLSH:
651 /* flush our buffers and the serial port's buffer */
652 switch (arg) {
653 case TCIFLUSH:
654 /* no own input buffer to flush */
655 break;
656 case TCIOFLUSH:
657 case TCOFLUSH:
658 flush_send_queue(cs);
659 break;
660 }
661 /* flush the serial port's buffer */
662 rc = n_tty_ioctl(tty, file, cmd, arg);
663 break;
664
665 case FIONREAD:
666 /* unused, always return zero */
667 val = 0;
668 rc = put_user(val, p);
669 break;
670
671 default:
672 rc = -ENOIOCTLCMD;
673 }
674
675 cs_put(cs);
676 return rc;
677}
678
679/*
680 * Poll on the tty.
681 * Unused, always return zero.
682 */
683static unsigned int
684gigaset_tty_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
685{
686 return 0;
687}
688
689/*
690 * Called by the tty driver when a block of data has been received.
691 * Will not be re-entered while running but other ldisc functions
692 * may be called in parallel.
693 * Can be called from hard interrupt level as well as soft interrupt
694 * level or mainline.
695 * Parameters:
696 * tty tty structure
697 * buf buffer containing received characters
698 * cflags buffer containing error flags for received characters (ignored)
699 * count number of received characters
700 */
701static void
702gigaset_tty_receive(struct tty_struct *tty, const unsigned char *buf,
703 char *cflags, int count)
704{
705 struct cardstate *cs = cs_get(tty);
706 unsigned tail, head, n;
707 struct inbuf_t *inbuf;
708
709 if (!cs)
710 return;
711 if (!(inbuf = cs->inbuf)) {
712 dev_err(cs->dev, "%s: no inbuf\n", __func__);
713 cs_put(cs);
714 return;
715 }
716
717 tail = atomic_read(&inbuf->tail);
718 head = atomic_read(&inbuf->head);
719 gig_dbg(DEBUG_INTR, "buffer state: %u -> %u, receive %u bytes",
720 head, tail, count);
721
722 if (head <= tail) {
723 /* possible buffer wraparound */
724 n = min_t(unsigned, count, RBUFSIZE - tail);
725 memcpy(inbuf->data + tail, buf, n);
726 tail = (tail + n) % RBUFSIZE;
727 buf += n;
728 count -= n;
729 }
730
731 if (count > 0) {
732 /* tail < head and some data left */
733 n = head - tail - 1;
734 if (count > n) {
735 dev_err(cs->dev,
736 "inbuf overflow, discarding %d bytes\n",
737 count - n);
738 count = n;
739 }
740 memcpy(inbuf->data + tail, buf, count);
741 tail += count;
742 }
743
744 gig_dbg(DEBUG_INTR, "setting tail to %u", tail);
745 atomic_set(&inbuf->tail, tail);
746
747 /* Everything was received .. Push data into handler */
748 gig_dbg(DEBUG_INTR, "%s-->BH", __func__);
749 gigaset_schedule_event(cs);
750 cs_put(cs);
751}
752
753/*
754 * Called by the tty driver when there's room for more data to send.
755 */
756static void
757gigaset_tty_wakeup(struct tty_struct *tty)
758{
759 struct cardstate *cs = cs_get(tty);
760
761 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
762 if (!cs)
763 return;
764 tasklet_schedule(&cs->write_tasklet);
765 cs_put(cs);
766}
767
768static struct tty_ldisc gigaset_ldisc = {
769 .owner = THIS_MODULE,
770 .magic = TTY_LDISC_MAGIC,
771 .name = "ser_gigaset",
772 .open = gigaset_tty_open,
773 .close = gigaset_tty_close,
774 .hangup = gigaset_tty_hangup,
775 .read = gigaset_tty_read,
776 .write = gigaset_tty_write,
777 .ioctl = gigaset_tty_ioctl,
778 .poll = gigaset_tty_poll,
779 .receive_buf = gigaset_tty_receive,
780 .write_wakeup = gigaset_tty_wakeup,
781};
782
783
784/* Initialization / Shutdown */
785/* ========================= */
786
787static int __init ser_gigaset_init(void)
788{
789 int rc;
790
791 gig_dbg(DEBUG_INIT, "%s", __func__);
792 if ((rc = platform_driver_register(&device_driver)) != 0) {
793 err("error %d registering platform driver", rc);
794 return rc;
795 }
796
797 /* allocate memory for our driver state and intialize it */
798 if (!(driver = gigaset_initdriver(GIGASET_MINOR, GIGASET_MINORS,
799 GIGASET_MODULENAME, GIGASET_DEVNAME,
800 &ops, THIS_MODULE)))
801 goto error;
802
803 if ((rc = tty_register_ldisc(N_GIGASET_M101, &gigaset_ldisc)) != 0) {
804 err("error %d registering line discipline", rc);
805 goto error;
806 }
807
808 return 0;
809
810error:
811 if (driver) {
812 gigaset_freedriver(driver);
813 driver = NULL;
814 }
815 platform_driver_unregister(&device_driver);
816 return rc;
817}
818
819static void __exit ser_gigaset_exit(void)
820{
821 int rc;
822
823 gig_dbg(DEBUG_INIT, "%s", __func__);
824
825 if (driver) {
826 gigaset_freedriver(driver);
827 driver = NULL;
828 }
829
830 if ((rc = tty_unregister_ldisc(N_GIGASET_M101)) != 0)
831 err("error %d unregistering line discipline", rc);
832
833 platform_driver_unregister(&device_driver);
834}
835
836module_init(ser_gigaset_init);
837module_exit(ser_gigaset_exit);
diff --git a/drivers/isdn/hardware/avm/b1dma.c b/drivers/isdn/hardware/avm/b1dma.c
index ddd47cdfdb1..1e2d38e3d68 100644
--- a/drivers/isdn/hardware/avm/b1dma.c
+++ b/drivers/isdn/hardware/avm/b1dma.c
@@ -29,7 +29,7 @@
29 29
30static char *revision = "$Revision: 1.1.2.3 $"; 30static char *revision = "$Revision: 1.1.2.3 $";
31 31
32#undef CONFIG_B1DMA_DEBUG 32#undef AVM_B1DMA_DEBUG
33 33
34/* ------------------------------------------------------------- */ 34/* ------------------------------------------------------------- */
35 35
@@ -391,16 +391,16 @@ static void b1dma_dispatch_tx(avmcard *card)
391 _put_slice(&p, skb->data, len); 391 _put_slice(&p, skb->data, len);
392 } 392 }
393 txlen = (u8 *)p - (u8 *)dma->sendbuf.dmabuf; 393 txlen = (u8 *)p - (u8 *)dma->sendbuf.dmabuf;
394#ifdef CONFIG_B1DMA_DEBUG 394#ifdef AVM_B1DMA_DEBUG
395 printk(KERN_DEBUG "tx: put msg len=%d\n", txlen); 395 printk(KERN_DEBUG "tx: put msg len=%d\n", txlen);
396#endif 396#endif
397 } else { 397 } else {
398 txlen = skb->len-2; 398 txlen = skb->len-2;
399#ifdef CONFIG_B1DMA_POLLDEBUG 399#ifdef AVM_B1DMA_POLLDEBUG
400 if (skb->data[2] == SEND_POLLACK) 400 if (skb->data[2] == SEND_POLLACK)
401 printk(KERN_INFO "%s: send ack\n", card->name); 401 printk(KERN_INFO "%s: send ack\n", card->name);
402#endif 402#endif
403#ifdef CONFIG_B1DMA_DEBUG 403#ifdef AVM_B1DMA_DEBUG
404 printk(KERN_DEBUG "tx: put 0x%x len=%d\n", 404 printk(KERN_DEBUG "tx: put 0x%x len=%d\n",
405 skb->data[2], txlen); 405 skb->data[2], txlen);
406#endif 406#endif
@@ -450,7 +450,7 @@ static void b1dma_handle_rx(avmcard *card)
450 u32 ApplId, MsgLen, DataB3Len, NCCI, WindowSize; 450 u32 ApplId, MsgLen, DataB3Len, NCCI, WindowSize;
451 u8 b1cmd = _get_byte(&p); 451 u8 b1cmd = _get_byte(&p);
452 452
453#ifdef CONFIG_B1DMA_DEBUG 453#ifdef AVM_B1DMA_DEBUG
454 printk(KERN_DEBUG "rx: 0x%x %lu\n", b1cmd, (unsigned long)dma->recvlen); 454 printk(KERN_DEBUG "rx: 0x%x %lu\n", b1cmd, (unsigned long)dma->recvlen);
455#endif 455#endif
456 456
@@ -515,7 +515,7 @@ static void b1dma_handle_rx(avmcard *card)
515 break; 515 break;
516 516
517 case RECEIVE_START: 517 case RECEIVE_START:
518#ifdef CONFIG_B1DMA_POLLDEBUG 518#ifdef AVM_B1DMA_POLLDEBUG
519 printk(KERN_INFO "%s: receive poll\n", card->name); 519 printk(KERN_INFO "%s: receive poll\n", card->name);
520#endif 520#endif
521 if (!suppress_pollack) 521 if (!suppress_pollack)
@@ -601,7 +601,7 @@ static void b1dma_handle_interrupt(avmcard *card)
601 rxlen = (dma->recvlen + 3) & ~3; 601 rxlen = (dma->recvlen + 3) & ~3;
602 b1dma_writel(card, dma->recvbuf.dmaaddr+4, AMCC_RXPTR); 602 b1dma_writel(card, dma->recvbuf.dmaaddr+4, AMCC_RXPTR);
603 b1dma_writel(card, rxlen, AMCC_RXLEN); 603 b1dma_writel(card, rxlen, AMCC_RXLEN);
604#ifdef CONFIG_B1DMA_DEBUG 604#ifdef AVM_B1DMA_DEBUG
605 } else { 605 } else {
606 printk(KERN_ERR "%s: rx not complete (%d).\n", 606 printk(KERN_ERR "%s: rx not complete (%d).\n",
607 card->name, rxlen); 607 card->name, rxlen);
diff --git a/drivers/isdn/hardware/avm/c4.c b/drivers/isdn/hardware/avm/c4.c
index 2a3eb38f0eb..6f5efa8d78c 100644
--- a/drivers/isdn/hardware/avm/c4.c
+++ b/drivers/isdn/hardware/avm/c4.c
@@ -28,8 +28,8 @@
28#include <linux/isdn/capilli.h> 28#include <linux/isdn/capilli.h>
29#include "avmcard.h" 29#include "avmcard.h"
30 30
31#undef CONFIG_C4_DEBUG 31#undef AVM_C4_DEBUG
32#undef CONFIG_C4_POLLDEBUG 32#undef AVM_C4_POLLDEBUG
33 33
34/* ------------------------------------------------------------- */ 34/* ------------------------------------------------------------- */
35 35
@@ -420,7 +420,7 @@ static void c4_dispatch_tx(avmcard *card)
420 420
421 skb = skb_dequeue(&dma->send_queue); 421 skb = skb_dequeue(&dma->send_queue);
422 if (!skb) { 422 if (!skb) {
423#ifdef CONFIG_C4_DEBUG 423#ifdef AVM_C4_DEBUG
424 printk(KERN_DEBUG "%s: tx underrun\n", card->name); 424 printk(KERN_DEBUG "%s: tx underrun\n", card->name);
425#endif 425#endif
426 return; 426 return;
@@ -444,16 +444,16 @@ static void c4_dispatch_tx(avmcard *card)
444 _put_slice(&p, skb->data, len); 444 _put_slice(&p, skb->data, len);
445 } 445 }
446 txlen = (u8 *)p - (u8 *)dma->sendbuf.dmabuf; 446 txlen = (u8 *)p - (u8 *)dma->sendbuf.dmabuf;
447#ifdef CONFIG_C4_DEBUG 447#ifdef AVM_C4_DEBUG
448 printk(KERN_DEBUG "%s: tx put msg len=%d\n", card->name, txlen); 448 printk(KERN_DEBUG "%s: tx put msg len=%d\n", card->name, txlen);
449#endif 449#endif
450 } else { 450 } else {
451 txlen = skb->len-2; 451 txlen = skb->len-2;
452#ifdef CONFIG_C4_POLLDEBUG 452#ifdef AVM_C4_POLLDEBUG
453 if (skb->data[2] == SEND_POLLACK) 453 if (skb->data[2] == SEND_POLLACK)
454 printk(KERN_INFO "%s: ack to c4\n", card->name); 454 printk(KERN_INFO "%s: ack to c4\n", card->name);
455#endif 455#endif
456#ifdef CONFIG_C4_DEBUG 456#ifdef AVM_C4_DEBUG
457 printk(KERN_DEBUG "%s: tx put 0x%x len=%d\n", 457 printk(KERN_DEBUG "%s: tx put 0x%x len=%d\n",
458 card->name, skb->data[2], txlen); 458 card->name, skb->data[2], txlen);
459#endif 459#endif
@@ -508,7 +508,7 @@ static void c4_handle_rx(avmcard *card)
508 u32 cidx; 508 u32 cidx;
509 509
510 510
511#ifdef CONFIG_C4_DEBUG 511#ifdef AVM_C4_DEBUG
512 printk(KERN_DEBUG "%s: rx 0x%x len=%lu\n", card->name, 512 printk(KERN_DEBUG "%s: rx 0x%x len=%lu\n", card->name,
513 b1cmd, (unsigned long)dma->recvlen); 513 b1cmd, (unsigned long)dma->recvlen);
514#endif 514#endif
@@ -586,7 +586,7 @@ static void c4_handle_rx(avmcard *card)
586 break; 586 break;
587 587
588 case RECEIVE_START: 588 case RECEIVE_START:
589#ifdef CONFIG_C4_POLLDEBUG 589#ifdef AVM_C4_POLLDEBUG
590 printk(KERN_INFO "%s: poll from c4\n", card->name); 590 printk(KERN_INFO "%s: poll from c4\n", card->name);
591#endif 591#endif
592 if (!suppress_pollack) 592 if (!suppress_pollack)
diff --git a/drivers/isdn/hardware/eicon/capifunc.c b/drivers/isdn/hardware/eicon/capifunc.c
index 0afd7633556..ff284aeb8fb 100644
--- a/drivers/isdn/hardware/eicon/capifunc.c
+++ b/drivers/isdn/hardware/eicon/capifunc.c
@@ -187,7 +187,7 @@ static diva_card *find_card_by_ctrl(word controller)
187 */ 187 */
188void *TransmitBufferSet(APPL * appl, dword ref) 188void *TransmitBufferSet(APPL * appl, dword ref)
189{ 189{
190 appl->xbuffer_used[ref] = TRUE; 190 appl->xbuffer_used[ref] = true;
191 DBG_PRV1(("%d:xbuf_used(%d)", appl->Id, ref + 1)) 191 DBG_PRV1(("%d:xbuf_used(%d)", appl->Id, ref + 1))
192 return (void *) ref; 192 return (void *) ref;
193} 193}
@@ -202,7 +202,7 @@ void *TransmitBufferGet(APPL * appl, void *p)
202 202
203void TransmitBufferFree(APPL * appl, void *p) 203void TransmitBufferFree(APPL * appl, void *p)
204{ 204{
205 appl->xbuffer_used[(dword) p] = FALSE; 205 appl->xbuffer_used[(dword) p] = false;
206 DBG_PRV1(("%d:xbuf_free(%d)", appl->Id, ((dword) p) + 1)) 206 DBG_PRV1(("%d:xbuf_free(%d)", appl->Id, ((dword) p) + 1))
207} 207}
208 208
diff --git a/drivers/isdn/hardware/eicon/debug.c b/drivers/isdn/hardware/eicon/debug.c
index d835e74ecf1..0db9cc661e2 100644
--- a/drivers/isdn/hardware/eicon/debug.c
+++ b/drivers/isdn/hardware/eicon/debug.c
@@ -287,7 +287,7 @@ void* diva_maint_finit (void) {
287 } 287 }
288 external_dbg_queue = 0; 288 external_dbg_queue = 0;
289 289
290 for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) { 290 for (i = 1; i < ARRAY_SIZE(clients); i++) {
291 if (clients[i].pmem) { 291 if (clients[i].pmem) {
292 diva_os_free (0, clients[i].pmem); 292 diva_os_free (0, clients[i].pmem);
293 } 293 }
@@ -391,7 +391,7 @@ static void DI_register (void *arg) {
391 391
392 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register"); 392 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register");
393 393
394 for (id = 1; id < (sizeof(clients)/sizeof(clients[0])); id++) { 394 for (id = 1; id < ARRAY_SIZE(clients); id++) {
395 if (clients[id].hDbg == hDbg) { 395 if (clients[id].hDbg == hDbg) {
396 /* 396 /*
397 driver already registered 397 driver already registered
@@ -494,7 +494,7 @@ static void DI_deregister (pDbgHandle hDbg) {
494 diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read"); 494 diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read");
495 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read"); 495 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read");
496 496
497 for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) { 497 for (i = 1; i < ARRAY_SIZE(clients); i++) {
498 if (clients[i].hDbg == hDbg) { 498 if (clients[i].hDbg == hDbg) {
499 diva_dbg_entry_head_t* pmsg; 499 diva_dbg_entry_head_t* pmsg;
500 char tmp[256]; 500 char tmp[256];
@@ -736,7 +736,7 @@ int diva_get_driver_info (dword id, byte* data, int data_length) {
736 int to_copy; 736 int to_copy;
737 737
738 if (!data || !id || (data_length < 17) || 738 if (!data || !id || (data_length < 17) ||
739 (id >= (sizeof(clients)/sizeof(clients[0])))) { 739 (id >= ARRAY_SIZE(clients))) {
740 return (-1); 740 return (-1);
741 } 741 }
742 742
@@ -786,7 +786,7 @@ int diva_get_driver_dbg_mask (dword id, byte* data) {
786 diva_os_spin_lock_magic_t old_irql; 786 diva_os_spin_lock_magic_t old_irql;
787 int ret = -1; 787 int ret = -1;
788 788
789 if (!data || !id || (id >= (sizeof(clients)/sizeof(clients[0])))) { 789 if (!data || !id || (id >= ARRAY_SIZE(clients))) {
790 return (-1); 790 return (-1);
791 } 791 }
792 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "driver info"); 792 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "driver info");
@@ -809,7 +809,7 @@ int diva_set_driver_dbg_mask (dword id, dword mask) {
809 int ret = -1; 809 int ret = -1;
810 810
811 811
812 if (!id || (id >= (sizeof(clients)/sizeof(clients[0])))) { 812 if (!id || (id >= ARRAY_SIZE(clients))) {
813 return (-1); 813 return (-1);
814 } 814 }
815 815
@@ -887,7 +887,7 @@ void diva_mnt_add_xdi_adapter (const DESCRIPTOR* d) {
887 diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "register"); 887 diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
888 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register"); 888 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register");
889 889
890 for (id = 1; id < (sizeof(clients)/sizeof(clients[0])); id++) { 890 for (id = 1; id < ARRAY_SIZE(clients); id++) {
891 if (clients[id].hDbg && (clients[id].request == d->request)) { 891 if (clients[id].hDbg && (clients[id].request == d->request)) {
892 diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register"); 892 diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register");
893 diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "register"); 893 diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
@@ -1037,7 +1037,7 @@ void diva_mnt_remove_xdi_adapter (const DESCRIPTOR* d) {
1037 diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read"); 1037 diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read");
1038 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read"); 1038 diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read");
1039 1039
1040 for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) { 1040 for (i = 1; i < ARRAY_SIZE(clients); i++) {
1041 if (clients[i].hDbg && (clients[i].request == d->request)) { 1041 if (clients[i].hDbg && (clients[i].request == d->request)) {
1042 diva_dbg_entry_head_t* pmsg; 1042 diva_dbg_entry_head_t* pmsg;
1043 char tmp[256]; 1043 char tmp[256];
@@ -1115,7 +1115,7 @@ void diva_mnt_remove_xdi_adapter (const DESCRIPTOR* d) {
1115void* SuperTraceOpenAdapter (int AdapterNumber) { 1115void* SuperTraceOpenAdapter (int AdapterNumber) {
1116 int i; 1116 int i;
1117 1117
1118 for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) { 1118 for (i = 1; i < ARRAY_SIZE(clients); i++) {
1119 if (clients[i].hDbg && clients[i].request && (clients[i].logical == AdapterNumber)) { 1119 if (clients[i].hDbg && clients[i].request && (clients[i].logical == AdapterNumber)) {
1120 return (&clients[i]); 1120 return (&clients[i]);
1121 } 1121 }
@@ -1508,7 +1508,7 @@ static void diva_maint_state_change_notify (void* user_context,
1508 int ch = TraceFilterChannel; 1508 int ch = TraceFilterChannel;
1509 int id = TraceFilterIdent; 1509 int id = TraceFilterIdent;
1510 1510
1511 if ((id >= 0) && (ch >= 0) && (id < sizeof(clients)/sizeof(clients[0])) && 1511 if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
1512 (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) { 1512 (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
1513 if (ch != (int)modem->ChannelNumber) { 1513 if (ch != (int)modem->ChannelNumber) {
1514 break; 1514 break;
@@ -1555,7 +1555,7 @@ static void diva_maint_state_change_notify (void* user_context,
1555 int ch = TraceFilterChannel; 1555 int ch = TraceFilterChannel;
1556 int id = TraceFilterIdent; 1556 int id = TraceFilterIdent;
1557 1557
1558 if ((id >= 0) && (ch >= 0) && (id < sizeof(clients)/sizeof(clients[0])) && 1558 if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
1559 (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) { 1559 (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
1560 if (ch != (int)fax->ChannelNumber) { 1560 if (ch != (int)fax->ChannelNumber) {
1561 break; 1561 break;
@@ -1803,7 +1803,7 @@ static void diva_maint_trace_notify (void* user_context,
1803 /* 1803 /*
1804 Selective trace 1804 Selective trace
1805 */ 1805 */
1806 if ((id >= 0) && (ch >= 0) && (id < sizeof(clients)/sizeof(clients[0])) && 1806 if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
1807 (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) { 1807 (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
1808 const char* p = NULL; 1808 const char* p = NULL;
1809 int ch_value = -1; 1809 int ch_value = -1;
@@ -1925,7 +1925,7 @@ int diva_mnt_shutdown_xdi_adapters (void) {
1925 byte * pmem; 1925 byte * pmem;
1926 1926
1927 1927
1928 for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) { 1928 for (i = 1; i < ARRAY_SIZE(clients); i++) {
1929 pmem = NULL; 1929 pmem = NULL;
1930 1930
1931 diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "unload"); 1931 diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "unload");
@@ -2006,7 +2006,7 @@ int diva_set_trace_filter (int filter_length, const char* filter) {
2006 2006
2007 on = (TraceFilter[0] == 0); 2007 on = (TraceFilter[0] == 0);
2008 2008
2009 for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) { 2009 for (i = 1; i < ARRAY_SIZE(clients); i++) {
2010 if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request) { 2010 if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request) {
2011 client_b_on = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_BCHANNEL) != 0); 2011 client_b_on = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_BCHANNEL) != 0);
2012 client_atap_on = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_AUDIO) != 0); 2012 client_atap_on = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_AUDIO) != 0);
@@ -2017,7 +2017,7 @@ int diva_set_trace_filter (int filter_length, const char* filter) {
2017 } 2017 }
2018 } 2018 }
2019 2019
2020 for (i = 1; i < (sizeof(clients)/sizeof(clients[0])); i++) { 2020 for (i = 1; i < ARRAY_SIZE(clients); i++) {
2021 if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request && clients[i].request_pending) { 2021 if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request && clients[i].request_pending) {
2022 diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "write_filter"); 2022 diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "write_filter");
2023 clients[i].request_pending = 0; 2023 clients[i].request_pending = 0;
diff --git a/drivers/isdn/hardware/eicon/di.c b/drivers/isdn/hardware/eicon/di.c
index e1df8d98c31..ce8df387890 100644
--- a/drivers/isdn/hardware/eicon/di.c
+++ b/drivers/isdn/hardware/eicon/di.c
@@ -173,16 +173,16 @@ void pr_out(ADAPTER * a)
173 xdi_xlog_request (XDI_A_NR(a), this->Id, this->ReqCh, this->MInd, 173 xdi_xlog_request (XDI_A_NR(a), this->Id, this->ReqCh, this->MInd,
174 a->IdTypeTable[this->No]); 174 a->IdTypeTable[this->No]);
175 a->ram_out(a, &ReqOut->Req, this->MInd); 175 a->ram_out(a, &ReqOut->Req, this->MInd);
176 more = TRUE; 176 more = true;
177 } 177 }
178 else { 178 else {
179 xdi_xlog_request (XDI_A_NR(a), this->Id, this->ReqCh, this->Req, 179 xdi_xlog_request (XDI_A_NR(a), this->Id, this->ReqCh, this->Req,
180 a->IdTypeTable[this->No]); 180 a->IdTypeTable[this->No]);
181 this->More |=XMOREF; 181 this->More |=XMOREF;
182 a->ram_out(a, &ReqOut->Req, this->Req); 182 a->ram_out(a, &ReqOut->Req, this->Req);
183 more = FALSE; 183 more = false;
184 if (a->FlowControlIdTable[this->ReqCh] == this->Id) 184 if (a->FlowControlIdTable[this->ReqCh] == this->Id)
185 a->FlowControlSkipTable[this->ReqCh] = TRUE; 185 a->FlowControlSkipTable[this->ReqCh] = true;
186 /* 186 /*
187 Note that remove request was sent to the card 187 Note that remove request was sent to the card
188 */ 188 */
@@ -311,7 +311,7 @@ byte pr_dpc(ADAPTER * a)
311 /* are marked RNR */ 311 /* are marked RNR */
312 if(RNRId && RNRId==a->ram_in(a, &IndIn->IndId)) { 312 if(RNRId && RNRId==a->ram_in(a, &IndIn->IndId)) {
313 a->ram_out(a, &IndIn->Ind, 0); 313 a->ram_out(a, &IndIn->Ind, 0);
314 a->ram_out(a, &IndIn->RNR, TRUE); 314 a->ram_out(a, &IndIn->RNR, true);
315 } 315 }
316 else { 316 else {
317 Ind = a->ram_in(a, &IndIn->Ind); 317 Ind = a->ram_in(a, &IndIn->Ind);
@@ -331,7 +331,7 @@ byte pr_dpc(ADAPTER * a)
331 dtrc(dprintf("RNR")); 331 dtrc(dprintf("RNR"));
332 a->ram_out(a, &IndIn->Ind, 0); 332 a->ram_out(a, &IndIn->Ind, 0);
333 RNRId = a->ram_in(a, &IndIn->IndId); 333 RNRId = a->ram_in(a, &IndIn->IndId);
334 a->ram_out(a, &IndIn->RNR, TRUE); 334 a->ram_out(a, &IndIn->RNR, true);
335 } 335 }
336 } 336 }
337 } 337 }
@@ -340,7 +340,7 @@ byte pr_dpc(ADAPTER * a)
340 } 340 }
341 a->ram_out(a, &PR_RAM->IndOutput, 0); 341 a->ram_out(a, &PR_RAM->IndOutput, 0);
342 } 342 }
343 return FALSE; 343 return false;
344} 344}
345byte scom_test_int(ADAPTER * a) 345byte scom_test_int(ADAPTER * a)
346{ 346{
@@ -399,7 +399,7 @@ byte isdn_rc(ADAPTER * a,
399 return (0); 399 return (0);
400 } 400 }
401 if (extended_info_type == DIVA_RC_TYPE_REMOVE_COMPLETE) 401 if (extended_info_type == DIVA_RC_TYPE_REMOVE_COMPLETE)
402 a->RcExtensionSupported = TRUE; 402 a->RcExtensionSupported = true;
403 } 403 }
404 a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_REMOVE_PENDING; 404 a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_REMOVE_PENDING;
405 a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_NO_RC_CANCELLING; 405 a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_NO_RC_CANCELLING;
@@ -428,7 +428,7 @@ byte isdn_rc(ADAPTER * a,
428 } 428 }
429 if (Rc==OK_FC) { 429 if (Rc==OK_FC) {
430 a->FlowControlIdTable[Ch] = Id; 430 a->FlowControlIdTable[Ch] = Id;
431 a->FlowControlSkipTable[Ch] = FALSE; 431 a->FlowControlSkipTable[Ch] = false;
432 this->Rc = Rc; 432 this->Rc = Rc;
433 this->More &= ~(XBUSY | XMOREC); 433 this->More &= ~(XBUSY | XMOREC);
434 this->complete=0xff; 434 this->complete=0xff;
diff --git a/drivers/isdn/hardware/eicon/divamnt.c b/drivers/isdn/hardware/eicon/divamnt.c
index 77155d9f399..6b2940ed077 100644
--- a/drivers/isdn/hardware/eicon/divamnt.c
+++ b/drivers/isdn/hardware/eicon/divamnt.c
@@ -164,7 +164,7 @@ static ssize_t divas_maint_read(struct file *file, char __user *buf,
164 return (maint_read_write(buf, (int) count)); 164 return (maint_read_write(buf, (int) count));
165} 165}
166 166
167static struct file_operations divas_maint_fops = { 167static const struct file_operations divas_maint_fops = {
168 .owner = THIS_MODULE, 168 .owner = THIS_MODULE,
169 .llseek = no_llseek, 169 .llseek = no_llseek,
170 .read = divas_maint_read, 170 .read = divas_maint_read,
diff --git a/drivers/isdn/hardware/eicon/divasi.c b/drivers/isdn/hardware/eicon/divasi.c
index fff0d89c806..556b19615bc 100644
--- a/drivers/isdn/hardware/eicon/divasi.c
+++ b/drivers/isdn/hardware/eicon/divasi.c
@@ -131,7 +131,7 @@ static void remove_um_idi_proc(void)
131 } 131 }
132} 132}
133 133
134static struct file_operations divas_idi_fops = { 134static const struct file_operations divas_idi_fops = {
135 .owner = THIS_MODULE, 135 .owner = THIS_MODULE,
136 .llseek = no_llseek, 136 .llseek = no_llseek,
137 .read = um_idi_read, 137 .read = um_idi_read,
diff --git a/drivers/isdn/hardware/eicon/divasmain.c b/drivers/isdn/hardware/eicon/divasmain.c
index 91fc92c01af..b365e44072c 100644
--- a/drivers/isdn/hardware/eicon/divasmain.c
+++ b/drivers/isdn/hardware/eicon/divasmain.c
@@ -663,7 +663,7 @@ static unsigned int divas_poll(struct file *file, poll_table * wait)
663 return (POLLIN | POLLRDNORM); 663 return (POLLIN | POLLRDNORM);
664} 664}
665 665
666static struct file_operations divas_fops = { 666static const struct file_operations divas_fops = {
667 .owner = THIS_MODULE, 667 .owner = THIS_MODULE,
668 .llseek = no_llseek, 668 .llseek = no_llseek,
669 .read = divas_read, 669 .read = divas_read,
diff --git a/drivers/isdn/hardware/eicon/divasproc.c b/drivers/isdn/hardware/eicon/divasproc.c
index 6a4373a4f1e..0632a260699 100644
--- a/drivers/isdn/hardware/eicon/divasproc.c
+++ b/drivers/isdn/hardware/eicon/divasproc.c
@@ -113,7 +113,7 @@ static int divas_close(struct inode *inode, struct file *file)
113 return (0); 113 return (0);
114} 114}
115 115
116static struct file_operations divas_fops = { 116static const struct file_operations divas_fops = {
117 .owner = THIS_MODULE, 117 .owner = THIS_MODULE,
118 .llseek = no_llseek, 118 .llseek = no_llseek,
119 .read = divas_read, 119 .read = divas_read,
diff --git a/drivers/isdn/hardware/eicon/message.c b/drivers/isdn/hardware/eicon/message.c
index f9b00f19afd..784232a144c 100644
--- a/drivers/isdn/hardware/eicon/message.c
+++ b/drivers/isdn/hardware/eicon/message.c
@@ -253,7 +253,7 @@ extern APPL * application;
253 253
254 254
255 255
256static byte remove_started = FALSE; 256static byte remove_started = false;
257static PLCI dummy_plci; 257static PLCI dummy_plci;
258 258
259 259
@@ -456,12 +456,12 @@ word api_put(APPL * appl, CAPI_MSG * msg)
456 456
457 return _QUEUE_FULL; 457 return _QUEUE_FULL;
458 } 458 }
459 c = FALSE; 459 c = false;
460 if ((((byte *) msg) < ((byte *)(plci->msg_in_queue))) 460 if ((((byte *) msg) < ((byte *)(plci->msg_in_queue)))
461 || (((byte *) msg) >= ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue))) 461 || (((byte *) msg) >= ((byte *)(plci->msg_in_queue)) + sizeof(plci->msg_in_queue)))
462 { 462 {
463 if (plci->msg_in_write_pos != plci->msg_in_read_pos) 463 if (plci->msg_in_write_pos != plci->msg_in_read_pos)
464 c = TRUE; 464 c = true;
465 } 465 }
466 if (msg->header.command == _DATA_B3_R) 466 if (msg->header.command == _DATA_B3_R)
467 { 467 {
@@ -506,13 +506,13 @@ word api_put(APPL * appl, CAPI_MSG * msg)
506 506
507 return _QUEUE_FULL; 507 return _QUEUE_FULL;
508 } 508 }
509 c = TRUE; 509 c = true;
510 } 510 }
511 } 511 }
512 else 512 else
513 { 513 {
514 if (plci->req_in || plci->internal_command) 514 if (plci->req_in || plci->internal_command)
515 c = TRUE; 515 c = true;
516 else 516 else
517 { 517 {
518 plci->command = msg->header.command; 518 plci->command = msg->header.command;
@@ -626,10 +626,10 @@ word api_parse(byte * msg, word length, byte * format, API_PARSE * parms)
626 break; 626 break;
627 } 627 }
628 628
629 if(p>length) return TRUE; 629 if(p>length) return true;
630 } 630 }
631 if(parms) parms[i].info = NULL; 631 if(parms) parms[i].info = NULL;
632 return FALSE; 632 return false;
633} 633}
634 634
635void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out) 635void api_save_msg(API_PARSE *in, byte *format, API_SAVE *out)
@@ -687,7 +687,7 @@ word api_remove_start(void)
687 word j; 687 word j;
688 688
689 if(!remove_started) { 689 if(!remove_started) {
690 remove_started = TRUE; 690 remove_started = true;
691 for(i=0;i<max_adapter;i++) { 691 for(i=0;i<max_adapter;i++) {
692 if(adapter[i].request) { 692 if(adapter[i].request) {
693 for(j=0;j<adapter[i].max_plci;j++) { 693 for(j=0;j<adapter[i].max_plci;j++) {
@@ -1080,7 +1080,7 @@ static void plci_remove(PLCI * plci)
1080 send_req(plci); 1080 send_req(plci);
1081 } 1081 }
1082 } 1082 }
1083 ncci_remove (plci, 0, FALSE); 1083 ncci_remove (plci, 0, false);
1084 plci_free_msg_in_queue (plci); 1084 plci_free_msg_in_queue (plci);
1085 1085
1086 plci->channels = 0; 1086 plci->channels = 0;
@@ -1226,7 +1226,7 @@ byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
1226 Id = ((word)1<<8)|a->Id; 1226 Id = ((word)1<<8)|a->Id;
1227 sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0); 1227 sendf(appl,_CONNECT_R|CONFIRM,Id,Number,"w",0);
1228 sendf(appl, _DISCONNECT_I, Id, 0, "w", _L1_ERROR); 1228 sendf(appl, _DISCONNECT_I, Id, 0, "w", _L1_ERROR);
1229 return FALSE; 1229 return false;
1230 } 1230 }
1231 Info = _OUT_OF_PLCI; 1231 Info = _OUT_OF_PLCI;
1232 if((i=get_plci(a))) 1232 if((i=get_plci(a)))
@@ -1330,7 +1330,7 @@ byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
1330 plci->command = _CONNECT_R; 1330 plci->command = _CONNECT_R;
1331 plci->number = Number; 1331 plci->number = Number;
1332 /* x.31 or D-ch free SAPI in LinkLayer? */ 1332 /* x.31 or D-ch free SAPI in LinkLayer? */
1333 if(ch==1 && LinkLayer!=3 && LinkLayer!=12) noCh = TRUE; 1333 if(ch==1 && LinkLayer!=3 && LinkLayer!=12) noCh = true;
1334 if((ch==0 || ch==2 || noCh || ch==3 || ch==4) && !Info) 1334 if((ch==0 || ch==2 || noCh || ch==3 || ch==4) && !Info)
1335 { 1335 {
1336 /* B-channel used for B3 connections (ch==0), or no B channel */ 1336 /* B-channel used for B3 connections (ch==0), or no B channel */
@@ -1381,7 +1381,7 @@ byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
1381 plci->command = 0; 1381 plci->command = 0;
1382 dbug(1,dprintf("Spoof")); 1382 dbug(1,dprintf("Spoof"));
1383 send_req(plci); 1383 send_req(plci);
1384 return FALSE; 1384 return false;
1385 } 1385 }
1386 if(ch==4)add_p(plci,CHI,p_chi); 1386 if(ch==4)add_p(plci,CHI,p_chi);
1387 add_s(plci,CPN,&parms[1]); 1387 add_s(plci,CPN,&parms[1]);
@@ -1395,11 +1395,11 @@ byte connect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
1395 plci->appl = appl; 1395 plci->appl = appl;
1396 sig_req(plci,LISTEN_REQ,0); 1396 sig_req(plci,LISTEN_REQ,0);
1397 send_req(plci); 1397 send_req(plci);
1398 return FALSE; 1398 return false;
1399 } 1399 }
1400 } 1400 }
1401 send_req(plci); 1401 send_req(plci);
1402 return FALSE; 1402 return false;
1403 } 1403 }
1404 plci->Id = 0; 1404 plci->Id = 0;
1405 } 1405 }
@@ -1571,7 +1571,7 @@ byte connect_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
1571byte connect_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg) 1571byte connect_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
1572{ 1572{
1573 dbug(1,dprintf("connect_a_res")); 1573 dbug(1,dprintf("connect_a_res"));
1574 return FALSE; 1574 return false;
1575} 1575}
1576 1576
1577byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg) 1577byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
@@ -1624,9 +1624,9 @@ byte disconnect_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
1624 } 1624 }
1625 } 1625 }
1626 1626
1627 if(!appl) return FALSE; 1627 if(!appl) return false;
1628 sendf(appl, _DISCONNECT_R|CONFIRM, Id, Number, "w",Info); 1628 sendf(appl, _DISCONNECT_R|CONFIRM, Id, Number, "w",Info);
1629 return FALSE; 1629 return false;
1630} 1630}
1631 1631
1632byte disconnect_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg) 1632byte disconnect_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
@@ -1702,7 +1702,7 @@ byte listen_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, A
1702 "w",Info); 1702 "w",Info);
1703 1703
1704 if (a) listen_check(a); 1704 if (a) listen_check(a);
1705 return FALSE; 1705 return false;
1706} 1706}
1707 1707
1708byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg) 1708byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
@@ -1739,7 +1739,7 @@ byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APP
1739 add_s(plci,KEY,&ai_parms[1]); 1739 add_s(plci,KEY,&ai_parms[1]);
1740 sig_req(plci,INFO_REQ,0); 1740 sig_req(plci,INFO_REQ,0);
1741 send_req(plci); 1741 send_req(plci);
1742 return FALSE; 1742 return false;
1743 } 1743 }
1744 1744
1745 if(plci->State && ai_parms[2].length) 1745 if(plci->State && ai_parms[2].length)
@@ -1769,7 +1769,7 @@ byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APP
1769 if((i=get_plci(a))) 1769 if((i=get_plci(a)))
1770 { 1770 {
1771 rc_plci = &a->plci[i-1]; 1771 rc_plci = &a->plci[i-1];
1772 appl->NullCREnable = TRUE; 1772 appl->NullCREnable = true;
1773 rc_plci->internal_command = C_NCR_FAC_REQ; 1773 rc_plci->internal_command = C_NCR_FAC_REQ;
1774 rc_plci->appl = appl; 1774 rc_plci->appl = appl;
1775 add_p(rc_plci,CAI,"\x01\x80"); 1775 add_p(rc_plci,CAI,"\x01\x80");
@@ -1788,7 +1788,7 @@ byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APP
1788 add_ai(rc_plci, &msg[1]); 1788 add_ai(rc_plci, &msg[1]);
1789 sig_req(rc_plci,NCR_FACILITY,0); 1789 sig_req(rc_plci,NCR_FACILITY,0);
1790 send_req(rc_plci); 1790 send_req(rc_plci);
1791 return FALSE; 1791 return false;
1792 /* for application controlled supplementary services */ 1792 /* for application controlled supplementary services */
1793 } 1793 }
1794 } 1794 }
@@ -1811,13 +1811,13 @@ byte info_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APP
1811 Number, 1811 Number,
1812 "w",Info); 1812 "w",Info);
1813 } 1813 }
1814 return FALSE; 1814 return false;
1815} 1815}
1816 1816
1817byte info_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg) 1817byte info_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
1818{ 1818{
1819 dbug(1,dprintf("info_res")); 1819 dbug(1,dprintf("info_res"));
1820 return FALSE; 1820 return false;
1821} 1821}
1822 1822
1823byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg) 1823byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
@@ -1828,7 +1828,7 @@ byte alert_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, AP
1828 dbug(1,dprintf("alert_req")); 1828 dbug(1,dprintf("alert_req"));
1829 1829
1830 Info = _WRONG_IDENTIFIER; 1830 Info = _WRONG_IDENTIFIER;
1831 ret = FALSE; 1831 ret = false;
1832 if(plci) { 1832 if(plci) {
1833 Info = _ALERT_IGNORED; 1833 Info = _ALERT_IGNORED;
1834 if(plci->State!=INC_CON_ALERT) { 1834 if(plci->State!=INC_CON_ALERT) {
@@ -1922,7 +1922,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
1922 rplci->appl = appl; 1922 rplci->appl = appl;
1923 sig_req(rplci,S_SUPPORTED,0); 1923 sig_req(rplci,S_SUPPORTED,0);
1924 send_req(rplci); 1924 send_req(rplci);
1925 return FALSE; 1925 return false;
1926 break; 1926 break;
1927 1927
1928 case S_LISTEN: 1928 case S_LISTEN:
@@ -1972,7 +1972,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
1972 add_s(plci,CAI,&ss_parms[1]); 1972 add_s(plci,CAI,&ss_parms[1]);
1973 sig_req(plci,CALL_HOLD,0); 1973 sig_req(plci,CALL_HOLD,0);
1974 send_req(plci); 1974 send_req(plci);
1975 return FALSE; 1975 return false;
1976 } 1976 }
1977 else Info = 0x3010; /* wrong state */ 1977 else Info = 0x3010; /* wrong state */
1978 break; 1978 break;
@@ -1997,13 +1997,13 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
1997 plci->internal_command = BLOCK_PLCI; 1997 plci->internal_command = BLOCK_PLCI;
1998 plci->command = 0; 1998 plci->command = 0;
1999 dbug(1,dprintf("Spoof")); 1999 dbug(1,dprintf("Spoof"));
2000 return FALSE; 2000 return false;
2001 } 2001 }
2002 else 2002 else
2003 { 2003 {
2004 sig_req(plci,CALL_RETRIEVE,0); 2004 sig_req(plci,CALL_RETRIEVE,0);
2005 send_req(plci); 2005 send_req(plci);
2006 return FALSE; 2006 return false;
2007 } 2007 }
2008 } 2008 }
2009 else Info = 0x3010; /* wrong state */ 2009 else Info = 0x3010; /* wrong state */
@@ -2123,7 +2123,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2123 add_p(plci,CAI,cai); 2123 add_p(plci,CAI,cai);
2124 sig_req(plci,S_SERVICE,0); 2124 sig_req(plci,S_SERVICE,0);
2125 send_req(plci); 2125 send_req(plci);
2126 return FALSE; 2126 return false;
2127 } 2127 }
2128 else Info = 0x3010; /* wrong state */ 2128 else Info = 0x3010; /* wrong state */
2129 break; 2129 break;
@@ -2265,7 +2265,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2265 add_p(rplci,CAI,cai); 2265 add_p(rplci,CAI,cai);
2266 sig_req(rplci,S_SERVICE,0); 2266 sig_req(rplci,S_SERVICE,0);
2267 send_req(rplci); 2267 send_req(rplci);
2268 return FALSE; 2268 return false;
2269 } 2269 }
2270 else 2270 else
2271 { 2271 {
@@ -2291,14 +2291,14 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2291 ss_parms[3].info[3] = (byte)GET_WORD(&(ss_parms[2].info[0])); 2291 ss_parms[3].info[3] = (byte)GET_WORD(&(ss_parms[2].info[0]));
2292 plci->command = 0; 2292 plci->command = 0;
2293 plci->internal_command = CD_REQ_PEND; 2293 plci->internal_command = CD_REQ_PEND;
2294 appl->CDEnable = TRUE; 2294 appl->CDEnable = true;
2295 cai[0] = 1; 2295 cai[0] = 1;
2296 cai[1] = CALL_DEFLECTION; 2296 cai[1] = CALL_DEFLECTION;
2297 add_p(plci,CAI,cai); 2297 add_p(plci,CAI,cai);
2298 add_p(plci,CPN,ss_parms[3].info); 2298 add_p(plci,CPN,ss_parms[3].info);
2299 sig_req(plci,S_SERVICE,0); 2299 sig_req(plci,S_SERVICE,0);
2300 send_req(plci); 2300 send_req(plci);
2301 return FALSE; 2301 return false;
2302 break; 2302 break;
2303 2303
2304 case S_CALL_FORWARDING_START: 2304 case S_CALL_FORWARDING_START:
@@ -2337,7 +2337,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2337 add_p(rplci,CPN,ss_parms[6].info); 2337 add_p(rplci,CPN,ss_parms[6].info);
2338 sig_req(rplci,S_SERVICE,0); 2338 sig_req(rplci,S_SERVICE,0);
2339 send_req(rplci); 2339 send_req(rplci);
2340 return FALSE; 2340 return false;
2341 break; 2341 break;
2342 2342
2343 case S_INTERROGATE_DIVERSION: 2343 case S_INTERROGATE_DIVERSION:
@@ -2456,7 +2456,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2456 2456
2457 sig_req(rplci,S_SERVICE,0); 2457 sig_req(rplci,S_SERVICE,0);
2458 send_req(rplci); 2458 send_req(rplci);
2459 return FALSE; 2459 return false;
2460 break; 2460 break;
2461 2461
2462 case S_MWI_ACTIVATE: 2462 case S_MWI_ACTIVATE:
@@ -2472,7 +2472,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2472 { 2472 {
2473 rplci = &a->plci[i-1]; 2473 rplci = &a->plci[i-1];
2474 rplci->appl = appl; 2474 rplci->appl = appl;
2475 rplci->cr_enquiry=TRUE; 2475 rplci->cr_enquiry=true;
2476 add_p(rplci,CAI,"\x01\x80"); 2476 add_p(rplci,CAI,"\x01\x80");
2477 add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30"); 2477 add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
2478 sig_req(rplci,ASSIGN,DSIG_ID); 2478 sig_req(rplci,ASSIGN,DSIG_ID);
@@ -2487,7 +2487,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2487 else 2487 else
2488 { 2488 {
2489 rplci = plci; 2489 rplci = plci;
2490 rplci->cr_enquiry=FALSE; 2490 rplci->cr_enquiry=false;
2491 } 2491 }
2492 2492
2493 rplci->command = 0; 2493 rplci->command = 0;
@@ -2509,7 +2509,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2509 add_p(rplci,UID,ss_parms[10].info); /* Time */ 2509 add_p(rplci,UID,ss_parms[10].info); /* Time */
2510 sig_req(rplci,S_SERVICE,0); 2510 sig_req(rplci,S_SERVICE,0);
2511 send_req(rplci); 2511 send_req(rplci);
2512 return FALSE; 2512 return false;
2513 2513
2514 case S_MWI_DEACTIVATE: 2514 case S_MWI_DEACTIVATE:
2515 if(api_parse(&parms->info[1],(word)parms->length,"wbwwss",ss_parms)) 2515 if(api_parse(&parms->info[1],(word)parms->length,"wbwwss",ss_parms))
@@ -2524,7 +2524,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2524 { 2524 {
2525 rplci = &a->plci[i-1]; 2525 rplci = &a->plci[i-1];
2526 rplci->appl = appl; 2526 rplci->appl = appl;
2527 rplci->cr_enquiry=TRUE; 2527 rplci->cr_enquiry=true;
2528 add_p(rplci,CAI,"\x01\x80"); 2528 add_p(rplci,CAI,"\x01\x80");
2529 add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30"); 2529 add_p(rplci,UID,"\x06\x43\x61\x70\x69\x32\x30");
2530 sig_req(rplci,ASSIGN,DSIG_ID); 2530 sig_req(rplci,ASSIGN,DSIG_ID);
@@ -2539,7 +2539,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2539 else 2539 else
2540 { 2540 {
2541 rplci = plci; 2541 rplci = plci;
2542 rplci->cr_enquiry=FALSE; 2542 rplci->cr_enquiry=false;
2543 } 2543 }
2544 2544
2545 rplci->command = 0; 2545 rplci->command = 0;
@@ -2556,7 +2556,7 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2556 add_p(rplci,OAD,ss_parms[5].info); /* Controlling User Number */ 2556 add_p(rplci,OAD,ss_parms[5].info); /* Controlling User Number */
2557 sig_req(rplci,S_SERVICE,0); 2557 sig_req(rplci,S_SERVICE,0);
2558 send_req(rplci); 2558 send_req(rplci);
2559 return FALSE; 2559 return false;
2560 2560
2561 default: 2561 default:
2562 Info = 0x300E; /* not supported */ 2562 Info = 0x300E; /* not supported */
@@ -2597,13 +2597,13 @@ byte facility_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
2597 Id, 2597 Id,
2598 Number, 2598 Number,
2599 "wws",Info,selector,SSparms); 2599 "wws",Info,selector,SSparms);
2600 return FALSE; 2600 return false;
2601} 2601}
2602 2602
2603byte facility_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg) 2603byte facility_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * msg)
2604{ 2604{
2605 dbug(1,dprintf("facility_res")); 2605 dbug(1,dprintf("facility_res"));
2606 return FALSE; 2606 return false;
2607} 2607}
2608 2608
2609byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 2609byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -2649,7 +2649,7 @@ byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2649 Id, 2649 Id,
2650 Number, 2650 Number,
2651 "w",Info); 2651 "w",Info);
2652 return FALSE; 2652 return false;
2653 } 2653 }
2654 plci->requested_options_conn = 0; 2654 plci->requested_options_conn = 0;
2655 2655
@@ -2684,7 +2684,7 @@ byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2684 || (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)) 2684 || (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS))
2685 { 2685 {
2686 len = (byte)(&(((T30_INFO *) 0)->universal_6)); 2686 len = (byte)(&(((T30_INFO *) 0)->universal_6));
2687 fax_info_change = FALSE; 2687 fax_info_change = false;
2688 if (ncpi->length >= 4) 2688 if (ncpi->length >= 4)
2689 { 2689 {
2690 w = GET_WORD(&ncpi->info[3]); 2690 w = GET_WORD(&ncpi->info[3]);
@@ -2693,7 +2693,7 @@ byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2693 ((T30_INFO *)(plci->fax_connect_info_buffer))->resolution = 2693 ((T30_INFO *)(plci->fax_connect_info_buffer))->resolution =
2694 (byte)((((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & ~T30_RESOLUTION_R8_0770_OR_200) | 2694 (byte)((((T30_INFO *)(plci->fax_connect_info_buffer))->resolution & ~T30_RESOLUTION_R8_0770_OR_200) |
2695 ((w & 0x0001) ? T30_RESOLUTION_R8_0770_OR_200 : 0)); 2695 ((w & 0x0001) ? T30_RESOLUTION_R8_0770_OR_200 : 0));
2696 fax_info_change = TRUE; 2696 fax_info_change = true;
2697 } 2697 }
2698 fax_control_bits &= ~(T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS); 2698 fax_control_bits &= ~(T30_CONTROL_BIT_REQUEST_POLLING | T30_CONTROL_BIT_MORE_DOCUMENTS);
2699 if (w & 0x0002) /* Fax-polling request */ 2699 if (w & 0x0002) /* Fax-polling request */
@@ -2709,7 +2709,7 @@ byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2709 if (((byte) w) != ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format) 2709 if (((byte) w) != ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format)
2710 { 2710 {
2711 ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format = (byte) w; 2711 ((T30_INFO *)(plci->fax_connect_info_buffer))->data_format = (byte) w;
2712 fax_info_change = TRUE; 2712 fax_info_change = true;
2713 } 2713 }
2714 2714
2715 if ((a->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD)) 2715 if ((a->man_profile.private_options & (1L << PRIVATE_FAX_SUB_SEP_PWD))
@@ -2781,13 +2781,13 @@ byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2781 { 2781 {
2782 len = (byte)(&(((T30_INFO *) 0)->universal_6)); 2782 len = (byte)(&(((T30_INFO *) 0)->universal_6));
2783 } 2783 }
2784 fax_info_change = TRUE; 2784 fax_info_change = true;
2785 2785
2786 } 2786 }
2787 if (fax_control_bits != GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low)) 2787 if (fax_control_bits != GET_WORD(&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low))
2788 { 2788 {
2789 PUT_WORD (&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low, fax_control_bits); 2789 PUT_WORD (&((T30_INFO *)plci->fax_connect_info_buffer)->control_bits_low, fax_control_bits);
2790 fax_info_change = TRUE; 2790 fax_info_change = true;
2791 } 2791 }
2792 } 2792 }
2793 if (Info == GOOD) 2793 if (Info == GOOD)
@@ -2798,12 +2798,12 @@ byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2798 if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS) 2798 if (fax_feature_bits & T30_FEATURE_BIT_MORE_DOCUMENTS)
2799 { 2799 {
2800 start_internal_command (Id, plci, fax_connect_info_command); 2800 start_internal_command (Id, plci, fax_connect_info_command);
2801 return FALSE; 2801 return false;
2802 } 2802 }
2803 else 2803 else
2804 { 2804 {
2805 start_internal_command (Id, plci, fax_adjust_b23_command); 2805 start_internal_command (Id, plci, fax_adjust_b23_command);
2806 return FALSE; 2806 return false;
2807 } 2807 }
2808 } 2808 }
2809 } 2809 }
@@ -2820,7 +2820,7 @@ byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2820 for (w = 0; w < ncpi->length; w++) 2820 for (w = 0; w < ncpi->length; w++)
2821 plci->internal_req_buffer[2+w] = ncpi->info[1+w]; 2821 plci->internal_req_buffer[2+w] = ncpi->info[1+w];
2822 start_internal_command (Id, plci, rtp_connect_b3_req_command); 2822 start_internal_command (Id, plci, rtp_connect_b3_req_command);
2823 return FALSE; 2823 return false;
2824 } 2824 }
2825 2825
2826 if(!Info) 2826 if(!Info)
@@ -2837,7 +2837,7 @@ byte connect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2837 Id, 2837 Id,
2838 Number, 2838 Number,
2839 "w",Info); 2839 "w",Info);
2840 return FALSE; 2840 return false;
2841} 2841}
2842 2842
2843byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 2843byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -2909,7 +2909,7 @@ byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2909 plci->fax_connect_info_length = len; 2909 plci->fax_connect_info_length = len;
2910 ((T30_INFO *)(plci->fax_connect_info_buffer))->code = 0; 2910 ((T30_INFO *)(plci->fax_connect_info_buffer))->code = 0;
2911 start_internal_command (Id, plci, fax_connect_ack_command); 2911 start_internal_command (Id, plci, fax_connect_ack_command);
2912 return FALSE; 2912 return false;
2913 } 2913 }
2914 } 2914 }
2915 2915
@@ -2932,7 +2932,7 @@ byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2932 for (w = 0; w < ncpi->length; w++) 2932 for (w = 0; w < ncpi->length; w++)
2933 plci->internal_req_buffer[2+w] = ncpi->info[1+w]; 2933 plci->internal_req_buffer[2+w] = ncpi->info[1+w];
2934 start_internal_command (Id, plci, rtp_connect_b3_res_command); 2934 start_internal_command (Id, plci, rtp_connect_b3_res_command);
2935 return FALSE; 2935 return false;
2936 } 2936 }
2937 2937
2938 else 2938 else
@@ -2945,14 +2945,14 @@ byte connect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plc
2945 sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s",""); 2945 sendf(appl,_CONNECT_B3_ACTIVE_I,Id,0,"s","");
2946 if (plci->adjust_b_restore) 2946 if (plci->adjust_b_restore)
2947 { 2947 {
2948 plci->adjust_b_restore = FALSE; 2948 plci->adjust_b_restore = false;
2949 start_internal_command (Id, plci, adjust_b_restore); 2949 start_internal_command (Id, plci, adjust_b_restore);
2950 } 2950 }
2951 } 2951 }
2952 return 1; 2952 return 1;
2953 } 2953 }
2954 } 2954 }
2955 return FALSE; 2955 return false;
2956} 2956}
2957 2957
2958byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 2958byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -2972,7 +2972,7 @@ byte connect_b3_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * p
2972 channel_xmit_xon (plci); 2972 channel_xmit_xon (plci);
2973 } 2973 }
2974 } 2974 }
2975 return FALSE; 2975 return false;
2976} 2976}
2977 2977
2978byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 2978byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -3004,7 +3004,7 @@ byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI *
3004 { 3004 {
3005 plci->send_disc = (byte)ncci; 3005 plci->send_disc = (byte)ncci;
3006 plci->command = 0; 3006 plci->command = 0;
3007 return FALSE; 3007 return false;
3008 } 3008 }
3009 else 3009 else
3010 { 3010 {
@@ -3028,7 +3028,7 @@ byte disconnect_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI *
3028 Id, 3028 Id,
3029 Number, 3029 Number,
3030 "w",Info); 3030 "w",Info);
3031 return FALSE; 3031 return false;
3032} 3032}
3033 3033
3034byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 3034byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -3084,7 +3084,7 @@ byte disconnect_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI *
3084 } 3084 }
3085 } 3085 }
3086 } 3086 }
3087 return FALSE; 3087 return false;
3088} 3088}
3089 3089
3090byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 3090byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -3140,7 +3140,7 @@ byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
3140 } 3140 }
3141 3141
3142 send_data(plci); 3142 send_data(plci);
3143 return FALSE; 3143 return false;
3144 } 3144 }
3145 } 3145 }
3146 if (appl) 3146 if (appl)
@@ -3161,7 +3161,7 @@ byte data_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
3161 Number, 3161 Number,
3162 "ww",GET_WORD(parms[2].info),Info); 3162 "ww",GET_WORD(parms[2].info),Info);
3163 } 3163 }
3164 return FALSE; 3164 return false;
3165} 3165}
3166 3166
3167byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 3167byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -3194,7 +3194,7 @@ byte data_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
3194 } 3194 }
3195 } 3195 }
3196 } 3196 }
3197 return FALSE; 3197 return false;
3198} 3198}
3199 3199
3200byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 3200byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -3235,7 +3235,7 @@ byte reset_b3_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
3235 Id, 3235 Id,
3236 Number, 3236 Number,
3237 "w",Info); 3237 "w",Info);
3238 return FALSE; 3238 return false;
3239} 3239}
3240 3240
3241byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 3241byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -3254,12 +3254,12 @@ byte reset_b3_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
3254 { 3254 {
3255 a->ncci_state[ncci] = CONNECTED; 3255 a->ncci_state[ncci] = CONNECTED;
3256 nl_req_ncci(plci,N_RESET_ACK,(byte)ncci); 3256 nl_req_ncci(plci,N_RESET_ACK,(byte)ncci);
3257 return TRUE; 3257 return true;
3258 } 3258 }
3259 break; 3259 break;
3260 } 3260 }
3261 } 3261 }
3262 return FALSE; 3262 return false;
3263} 3263}
3264 3264
3265byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 3265byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -3292,7 +3292,7 @@ byte connect_b3_t90_a_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI
3292 return 1; 3292 return 1;
3293 } 3293 }
3294 } 3294 }
3295 return FALSE; 3295 return false;
3296} 3296}
3297 3297
3298 3298
@@ -3378,7 +3378,7 @@ byte select_b_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
3378 plci->internal_command = BLOCK_PLCI; /* lock other commands */ 3378 plci->internal_command = BLOCK_PLCI; /* lock other commands */
3379 plci->command = 0; 3379 plci->command = 0;
3380 dbug(1,dprintf("continue if codec loaded")); 3380 dbug(1,dprintf("continue if codec loaded"));
3381 return FALSE; 3381 return false;
3382 } 3382 }
3383 } 3383 }
3384 } 3384 }
@@ -3407,12 +3407,12 @@ byte select_b_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci,
3407 else if (plci->call_dir & CALL_DIR_IN) 3407 else if (plci->call_dir & CALL_DIR_IN)
3408 plci->call_dir = CALL_DIR_IN | CALL_DIR_ANSWER; 3408 plci->call_dir = CALL_DIR_IN | CALL_DIR_ANSWER;
3409 start_internal_command (Id, plci, select_b_command); 3409 start_internal_command (Id, plci, select_b_command);
3410 return FALSE; 3410 return false;
3411 } 3411 }
3412 } 3412 }
3413 } 3413 }
3414 sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", Info); 3414 sendf(appl, _SELECT_B_REQ|CONFIRM, Id, Number, "w", Info);
3415 return FALSE; 3415 return false;
3416} 3416}
3417 3417
3418byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms) 3418byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * plci, APPL * appl, API_PARSE * parms)
@@ -3489,7 +3489,7 @@ byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * p
3489 } 3489 }
3490 3490
3491 plci->State = LOCAL_CONNECT; 3491 plci->State = LOCAL_CONNECT;
3492 plci->manufacturer = TRUE; 3492 plci->manufacturer = true;
3493 plci->command = _MANUFACTURER_R; 3493 plci->command = _MANUFACTURER_R;
3494 plci->m_command = command; 3494 plci->m_command = command;
3495 plci->number = Number; 3495 plci->number = Number;
@@ -3520,7 +3520,7 @@ byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * p
3520 plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */ 3520 plci->internal_command = BLOCK_PLCI; /* reject other req meanwhile */
3521 plci->command = 0; 3521 plci->command = 0;
3522 send_req(plci); 3522 send_req(plci);
3523 return FALSE; 3523 return false;
3524 } 3524 }
3525 if(dir==1) { 3525 if(dir==1) {
3526 sig_req(plci,CALL_REQ,0); 3526 sig_req(plci,CALL_REQ,0);
@@ -3573,7 +3573,7 @@ byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * p
3573 } 3573 }
3574 else if(req==LAW_REQ) 3574 else if(req==LAW_REQ)
3575 { 3575 {
3576 plci->cr_enquiry = TRUE; 3576 plci->cr_enquiry = true;
3577 } 3577 }
3578 add_ss(plci,FTY,&m_parms[1]); 3578 add_ss(plci,FTY,&m_parms[1]);
3579 sig_req(plci,req,0); 3579 sig_req(plci,req,0);
@@ -3739,7 +3739,7 @@ byte manufacturer_req(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * p
3739 Id, 3739 Id,
3740 Number, 3740 Number,
3741 "dww",_DI_MANU_ID,command,Info); 3741 "dww",_DI_MANU_ID,command,Info);
3742 return FALSE; 3742 return false;
3743} 3743}
3744 3744
3745 3745
@@ -3760,7 +3760,7 @@ byte manufacturer_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * p
3760 || (msg[1].length == 0) 3760 || (msg[1].length == 0)
3761 || (GET_DWORD(msg[0].info)!=_DI_MANU_ID)) 3761 || (GET_DWORD(msg[0].info)!=_DI_MANU_ID))
3762 { 3762 {
3763 return FALSE; 3763 return false;
3764 } 3764 }
3765 indication = GET_WORD(msg[1].info); 3765 indication = GET_WORD(msg[1].info);
3766 switch (indication) 3766 switch (indication)
@@ -3811,7 +3811,7 @@ byte manufacturer_res(dword Id, word Number, DIVA_CAPI_ADAPTER * a, PLCI * p
3811 break; 3811 break;
3812 3812
3813 } 3813 }
3814 return FALSE; 3814 return false;
3815} 3815}
3816 3816
3817/*------------------------------------------------------------------*/ 3817/*------------------------------------------------------------------*/
@@ -3908,14 +3908,14 @@ void callback(ENTITY * e)
3908 plci->nl_req = 0; 3908 plci->nl_req = 0;
3909 } 3909 }
3910 if (plci->nl_req) 3910 if (plci->nl_req)
3911 control_rc (plci, 0, rc, ch, 0, TRUE); 3911 control_rc (plci, 0, rc, ch, 0, true);
3912 else 3912 else
3913 { 3913 {
3914 if (req == N_XON) 3914 if (req == N_XON)
3915 { 3915 {
3916 channel_x_on (plci, ch); 3916 channel_x_on (plci, ch);
3917 if (plci->internal_command) 3917 if (plci->internal_command)
3918 control_rc (plci, req, rc, ch, 0, TRUE); 3918 control_rc (plci, req, rc, ch, 0, true);
3919 } 3919 }
3920 else 3920 else
3921 { 3921 {
@@ -3931,21 +3931,21 @@ void callback(ENTITY * e)
3931 } 3931 }
3932 } 3932 }
3933 channel_xmit_xon (plci); 3933 channel_xmit_xon (plci);
3934 control_rc (plci, 0, rc, ch, global_req, TRUE); 3934 control_rc (plci, 0, rc, ch, global_req, true);
3935 } 3935 }
3936 else if (plci->data_sent) 3936 else if (plci->data_sent)
3937 { 3937 {
3938 channel_xmit_xon (plci); 3938 channel_xmit_xon (plci);
3939 plci->data_sent = FALSE; 3939 plci->data_sent = false;
3940 plci->NL.XNum = 1; 3940 plci->NL.XNum = 1;
3941 data_rc (plci, ch); 3941 data_rc (plci, ch);
3942 if (plci->internal_command) 3942 if (plci->internal_command)
3943 control_rc (plci, req, rc, ch, 0, TRUE); 3943 control_rc (plci, req, rc, ch, 0, true);
3944 } 3944 }
3945 else 3945 else
3946 { 3946 {
3947 channel_xmit_xon (plci); 3947 channel_xmit_xon (plci);
3948 control_rc (plci, req, rc, ch, 0, TRUE); 3948 control_rc (plci, req, rc, ch, 0, true);
3949 } 3949 }
3950 } 3950 }
3951 } 3951 }
@@ -3974,12 +3974,12 @@ void callback(ENTITY * e)
3974 if (rc != ASSIGN_OK) 3974 if (rc != ASSIGN_OK)
3975 e->Id = 0; 3975 e->Id = 0;
3976 channel_xmit_xon (plci); 3976 channel_xmit_xon (plci);
3977 control_rc (plci, 0, rc, ch, global_req, FALSE); 3977 control_rc (plci, 0, rc, ch, global_req, false);
3978 } 3978 }
3979 else 3979 else
3980 { 3980 {
3981 channel_xmit_xon (plci); 3981 channel_xmit_xon (plci);
3982 control_rc (plci, req, rc, ch, 0, FALSE); 3982 control_rc (plci, req, rc, ch, 0, false);
3983 } 3983 }
3984 } 3984 }
3985 /* 3985 /*
@@ -4065,8 +4065,8 @@ capi_callback_suffix:
4065 4065
4066 if (plci->li_notify_update) 4066 if (plci->li_notify_update)
4067 { 4067 {
4068 plci->li_notify_update = FALSE; 4068 plci->li_notify_update = false;
4069 mixer_notify_update (plci, FALSE); 4069 mixer_notify_update (plci, false);
4070 } 4070 }
4071 4071
4072 } 4072 }
@@ -4428,7 +4428,7 @@ void control_rc(PLCI * plci, byte req, byte rc, byte ch, byte global_req, byte
4428 else 4428 else
4429 { 4429 {
4430 sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE); 4430 sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
4431 appl->NullCREnable = FALSE; 4431 appl->NullCREnable = false;
4432 plci_remove(plci); 4432 plci_remove(plci);
4433 } 4433 }
4434 } 4434 }
@@ -4441,7 +4441,7 @@ void control_rc(PLCI * plci, byte req, byte rc, byte ch, byte global_req, byte
4441 else 4441 else
4442 { 4442 {
4443 sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE); 4443 sendf(appl,_INFO_R|CONFIRM,Id&0xf,Number,"w",_WRONG_STATE);
4444 appl->NullCREnable = FALSE; 4444 appl->NullCREnable = false;
4445 } 4445 }
4446 plci_remove(plci); 4446 plci_remove(plci);
4447 } 4447 }
@@ -4862,7 +4862,7 @@ void sig_ind(PLCI * plci)
4862 byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00"; 4862 byte CF_Ind[] = "\x09\x02\x00\x06\x00\x00\x00\x00\x00\x00";
4863 byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; 4863 byte Interr_Err_Ind[] = "\x0a\x02\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
4864 byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\0x00\0x00\0x00\0x00"; 4864 byte CONF_Ind[] = "\x09\x16\x00\x06\x00\x00\0x00\0x00\0x00\0x00";
4865 byte force_mt_info = FALSE; 4865 byte force_mt_info = false;
4866 byte dir; 4866 byte dir;
4867 dword d; 4867 dword d;
4868 word w; 4868 word w;
@@ -4933,7 +4933,7 @@ void sig_ind(PLCI * plci)
4933 { 4933 {
4934 if(plci->cr_enquiry && plci->appl) 4934 if(plci->cr_enquiry && plci->appl)
4935 { 4935 {
4936 plci->cr_enquiry = FALSE; 4936 plci->cr_enquiry = false;
4937 /* d = MANU_ID */ 4937 /* d = MANU_ID */
4938 /* w = m_command */ 4938 /* w = m_command */
4939 /* b = total length */ 4939 /* b = total length */
@@ -5158,7 +5158,7 @@ void sig_ind(PLCI * plci)
5158 if(application[i].CDEnable) 5158 if(application[i].CDEnable)
5159 { 5159 {
5160 if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind); 5160 if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
5161 application[i].CDEnable = FALSE; 5161 application[i].CDEnable = false;
5162 } 5162 }
5163 } 5163 }
5164 break; 5164 break;
@@ -5375,7 +5375,7 @@ void sig_ind(PLCI * plci)
5375 if(application[i].CDEnable) 5375 if(application[i].CDEnable)
5376 { 5376 {
5377 if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind); 5377 if(application[i].Id) sendf(&application[i],_FACILITY_I,Id,0,"ws",3, SS_Ind);
5378 application[i].CDEnable = FALSE; 5378 application[i].CDEnable = false;
5379 } 5379 }
5380 } 5380 }
5381 break; 5381 break;
@@ -5730,7 +5730,7 @@ void sig_ind(PLCI * plci)
5730 plci, 5730 plci,
5731 Id, 5731 Id,
5732 parms, 5732 parms,
5733 SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, TRUE)); 5733 SendMultiIE(plci,Id,multi_pi_parms, PI, 0x210, true));
5734 } 5734 }
5735 } 5735 }
5736 clear_c_ind_mask_bit (plci, MAX_APPL); 5736 clear_c_ind_mask_bit (plci, MAX_APPL);
@@ -6117,38 +6117,38 @@ static void SendSetupInfo(APPL * appl, PLCI * plci, dword Id, byte * * par
6117 dbug(1,dprintf("CPN ")); 6117 dbug(1,dprintf("CPN "));
6118 Info_Number = 0x0070; 6118 Info_Number = 0x0070;
6119 Info_Mask = 0x80; 6119 Info_Mask = 0x80;
6120 Info_Sent_Flag = TRUE; 6120 Info_Sent_Flag = true;
6121 break; 6121 break;
6122 case 8: /* display */ 6122 case 8: /* display */
6123 dbug(1,dprintf("display(%d)",i)); 6123 dbug(1,dprintf("display(%d)",i));
6124 Info_Number = 0x0028; 6124 Info_Number = 0x0028;
6125 Info_Mask = 0x04; 6125 Info_Mask = 0x04;
6126 Info_Sent_Flag = TRUE; 6126 Info_Sent_Flag = true;
6127 break; 6127 break;
6128 case 16: /* Channel Id */ 6128 case 16: /* Channel Id */
6129 dbug(1,dprintf("CHI")); 6129 dbug(1,dprintf("CHI"));
6130 Info_Number = 0x0018; 6130 Info_Number = 0x0018;
6131 Info_Mask = 0x100; 6131 Info_Mask = 0x100;
6132 Info_Sent_Flag = TRUE; 6132 Info_Sent_Flag = true;
6133 mixer_set_bchannel_id (plci, Info_Element); 6133 mixer_set_bchannel_id (plci, Info_Element);
6134 break; 6134 break;
6135 case 19: /* Redirected Number */ 6135 case 19: /* Redirected Number */
6136 dbug(1,dprintf("RDN")); 6136 dbug(1,dprintf("RDN"));
6137 Info_Number = 0x0074; 6137 Info_Number = 0x0074;
6138 Info_Mask = 0x400; 6138 Info_Mask = 0x400;
6139 Info_Sent_Flag = TRUE; 6139 Info_Sent_Flag = true;
6140 break; 6140 break;
6141 case 20: /* Redirected Number extended */ 6141 case 20: /* Redirected Number extended */
6142 dbug(1,dprintf("RDX")); 6142 dbug(1,dprintf("RDX"));
6143 Info_Number = 0x0073; 6143 Info_Number = 0x0073;
6144 Info_Mask = 0x400; 6144 Info_Mask = 0x400;
6145 Info_Sent_Flag = TRUE; 6145 Info_Sent_Flag = true;
6146 break; 6146 break;
6147 case 22: /* Redirecing Number */ 6147 case 22: /* Redirecing Number */
6148 dbug(1,dprintf("RIN")); 6148 dbug(1,dprintf("RIN"));
6149 Info_Number = 0x0076; 6149 Info_Number = 0x0076;
6150 Info_Mask = 0x400; 6150 Info_Mask = 0x400;
6151 Info_Sent_Flag = TRUE; 6151 Info_Sent_Flag = true;
6152 break; 6152 break;
6153 default: 6153 default:
6154 Info_Number = 0; 6154 Info_Number = 0;
@@ -6312,7 +6312,7 @@ void SendInfo(PLCI * plci, dword Id, byte * * parms, byte iesent)
6312 && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask) 6312 && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
6313 { 6313 {
6314 dbug(1,dprintf("NCR_Ind")); 6314 dbug(1,dprintf("NCR_Ind"));
6315 iesent=TRUE; 6315 iesent=true;
6316 sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element); 6316 sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
6317 } 6317 }
6318 } 6318 }
@@ -6330,7 +6330,7 @@ void SendInfo(PLCI * plci, dword Id, byte * * parms, byte iesent)
6330 if(test_c_ind_mask_bit (plci, j)) 6330 if(test_c_ind_mask_bit (plci, j))
6331 { 6331 {
6332 dbug(1,dprintf("Ovl_Ind")); 6332 dbug(1,dprintf("Ovl_Ind"));
6333 iesent=TRUE; 6333 iesent=true;
6334 sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element); 6334 sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
6335 } 6335 }
6336 } 6336 }
@@ -6340,7 +6340,7 @@ void SendInfo(PLCI * plci, dword Id, byte * * parms, byte iesent)
6340 && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask) 6340 && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
6341 { 6341 {
6342 dbug(1,dprintf("Std_Ind")); 6342 dbug(1,dprintf("Std_Ind"));
6343 iesent=TRUE; 6343 iesent=true;
6344 sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element); 6344 sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
6345 } 6345 }
6346 } 6346 }
@@ -6391,7 +6391,7 @@ byte SendMultiIE(PLCI * plci, dword Id, byte * * parms, byte ie_type, dword
6391 && appl->Id 6391 && appl->Id
6392 && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask) 6392 && plci->adapter->Info_Mask[appl->Id-1] &Info_Mask)
6393 { 6393 {
6394 iesent = TRUE; 6394 iesent = true;
6395 dbug(1,dprintf("Mlt_NCR_Ind")); 6395 dbug(1,dprintf("Mlt_NCR_Ind"));
6396 sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element); 6396 sendf(&application[j],_INFO_I,Id&0x0f,0,"wS",Info_Number,Info_Element);
6397 } 6397 }
@@ -6403,7 +6403,7 @@ byte SendMultiIE(PLCI * plci, dword Id, byte * * parms, byte ie_type, dword
6403 { 6403 {
6404 if(test_c_ind_mask_bit (plci, j)) 6404 if(test_c_ind_mask_bit (plci, j))
6405 { 6405 {
6406 iesent = TRUE; 6406 iesent = true;
6407 dbug(1,dprintf("Mlt_Ovl_Ind")); 6407 dbug(1,dprintf("Mlt_Ovl_Ind"));
6408 sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element); 6408 sendf(&application[j],_INFO_I,Id,0,"wS",Info_Number,Info_Element);
6409 } 6409 }
@@ -6412,7 +6412,7 @@ byte SendMultiIE(PLCI * plci, dword Id, byte * * parms, byte ie_type, dword
6412 else if(Info_Number 6412 else if(Info_Number
6413 && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask) 6413 && plci->adapter->Info_Mask[plci->appl->Id-1] &Info_Mask)
6414 { 6414 {
6415 iesent = TRUE; 6415 iesent = true;
6416 dbug(1,dprintf("Mlt_Std_Ind")); 6416 dbug(1,dprintf("Mlt_Std_Ind"));
6417 sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element); 6417 sendf(plci->appl,_INFO_I,Id,0,"wS",Info_Number,Info_Element);
6418 } 6418 }
@@ -6812,7 +6812,7 @@ void nl_ind(PLCI * plci)
6812 } 6812 }
6813 if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK)) 6813 if (((plci->NL.Ind & 0x0f) == N_DISC) || ((plci->NL.Ind & 0x0f) == N_DISC_ACK))
6814 { 6814 {
6815 if (((T30_INFO *)plci->NL.RBuffer->P)->code < sizeof(fax_info) / sizeof(fax_info[0])) 6815 if (((T30_INFO *)plci->NL.RBuffer->P)->code < ARRAY_SIZE(fax_info))
6816 info = fax_info[((T30_INFO *)plci->NL.RBuffer->P)->code]; 6816 info = fax_info[((T30_INFO *)plci->NL.RBuffer->P)->code];
6817 else 6817 else
6818 info = _FAX_PROTOCOL_ERROR; 6818 info = _FAX_PROTOCOL_ERROR;
@@ -6887,7 +6887,7 @@ void nl_ind(PLCI * plci)
6887 (byte)(plci->ncpi_buffer[0] + 1), plci->ncpi_buffer); 6887 (byte)(plci->ncpi_buffer[0] + 1), plci->ncpi_buffer);
6888 plci->ncpi_state |= NCPI_NEGOTIATE_B3_SENT; 6888 plci->ncpi_state |= NCPI_NEGOTIATE_B3_SENT;
6889 if (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP) 6889 if (plci->nsf_control_bits & T30_NSF_CONTROL_BIT_NEGOTIATE_RESP)
6890 fax_send_edata_ack = FALSE; 6890 fax_send_edata_ack = false;
6891 } 6891 }
6892 6892
6893 if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS) 6893 if (a->manufacturer_features & MANUFACTURER_FEATURE_FAX_PAPER_FORMATS)
@@ -6928,7 +6928,7 @@ void nl_ind(PLCI * plci)
6928 sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",GOOD,plci->ncpi_buffer); 6928 sendf(plci->appl,_DISCONNECT_B3_I,Id,0,"wS",GOOD,plci->ncpi_buffer);
6929 a->ncci_state[ncci] = INC_DIS_PENDING; 6929 a->ncci_state[ncci] = INC_DIS_PENDING;
6930 plci->ncpi_state = 0; 6930 plci->ncpi_state = 0;
6931 fax_send_edata_ack = FALSE; 6931 fax_send_edata_ack = false;
6932 } 6932 }
6933 break; 6933 break;
6934 } 6934 }
@@ -7025,7 +7025,7 @@ void nl_ind(PLCI * plci)
7025 } 7025 }
7026 if (plci->adjust_b_restore) 7026 if (plci->adjust_b_restore)
7027 { 7027 {
7028 plci->adjust_b_restore = FALSE; 7028 plci->adjust_b_restore = false;
7029 start_internal_command (Id, plci, adjust_b_restore); 7029 start_internal_command (Id, plci, adjust_b_restore);
7030 } 7030 }
7031 break; 7031 break;
@@ -7041,7 +7041,7 @@ void nl_ind(PLCI * plci)
7041 next_internal_command (Id, plci); 7041 next_internal_command (Id, plci);
7042 } 7042 }
7043 ncci_state = a->ncci_state[ncci]; 7043 ncci_state = a->ncci_state[ncci];
7044 ncci_remove (plci, ncci, FALSE); 7044 ncci_remove (plci, ncci, false);
7045 7045
7046 /* with N_DISC or N_DISC_ACK the IDI frees the respective */ 7046 /* with N_DISC or N_DISC_ACK the IDI frees the respective */
7047 /* channel, so we cannot store the state in ncci_state! The */ 7047 /* channel, so we cannot store the state in ncci_state! The */
@@ -7288,18 +7288,18 @@ word get_plci(DIVA_CAPI_ADAPTER * a)
7288 plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE; 7288 plci->msg_in_read_pos = MSG_IN_QUEUE_SIZE;
7289 plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE; 7289 plci->msg_in_wrap_pos = MSG_IN_QUEUE_SIZE;
7290 7290
7291 plci->data_sent = FALSE; 7291 plci->data_sent = false;
7292 plci->send_disc = 0; 7292 plci->send_disc = 0;
7293 plci->sig_global_req = 0; 7293 plci->sig_global_req = 0;
7294 plci->sig_remove_id = 0; 7294 plci->sig_remove_id = 0;
7295 plci->nl_global_req = 0; 7295 plci->nl_global_req = 0;
7296 plci->nl_remove_id = 0; 7296 plci->nl_remove_id = 0;
7297 plci->adv_nl = 0; 7297 plci->adv_nl = 0;
7298 plci->manufacturer = FALSE; 7298 plci->manufacturer = false;
7299 plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE; 7299 plci->call_dir = CALL_DIR_OUT | CALL_DIR_ORIGINATE;
7300 plci->spoofed_msg = 0; 7300 plci->spoofed_msg = 0;
7301 plci->ptyState = 0; 7301 plci->ptyState = 0;
7302 plci->cr_enquiry = FALSE; 7302 plci->cr_enquiry = false;
7303 plci->hangup_flow_ctrl_timer = 0; 7303 plci->hangup_flow_ctrl_timer = 0;
7304 7304
7305 plci->ncci_ring_list = 0; 7305 plci->ncci_ring_list = 0;
@@ -7972,7 +7972,7 @@ word add_b23(PLCI * plci, API_PARSE * bp)
7972 7972
7973 if(!bp->length && plci->tel) 7973 if(!bp->length && plci->tel)
7974 { 7974 {
7975 plci->adv_nl = TRUE; 7975 plci->adv_nl = true;
7976 dbug(1,dprintf("Default adv.Nl")); 7976 dbug(1,dprintf("Default adv.Nl"));
7977 add_p(plci,LLI,lli); 7977 add_p(plci,LLI,lli);
7978 plci->B2_prot = 1 /*XPARENT*/; 7978 plci->B2_prot = 1 /*XPARENT*/;
@@ -8022,7 +8022,7 @@ word add_b23(PLCI * plci, API_PARSE * bp)
8022 { 8022 {
8023 if(GET_WORD(bp_parms[1].info)!=1 8023 if(GET_WORD(bp_parms[1].info)!=1
8024 || GET_WORD(bp_parms[2].info)!=0) return _B2_NOT_SUPPORTED; 8024 || GET_WORD(bp_parms[2].info)!=0) return _B2_NOT_SUPPORTED;
8025 plci->adv_nl = TRUE; 8025 plci->adv_nl = true;
8026 } 8026 }
8027 else if(plci->tel) return _B2_NOT_SUPPORTED; 8027 else if(plci->tel) return _B2_NOT_SUPPORTED;
8028 8028
@@ -8840,7 +8840,7 @@ void send_data(PLCI * plci)
8840 plci->NL.X = plci->NData; 8840 plci->NL.X = plci->NData;
8841 plci->NL.ReqCh = a->ncci_ch[ncci]; 8841 plci->NL.ReqCh = a->ncci_ch[ncci];
8842 dbug(1,dprintf("%x:DREQ(%x:%x)",a->Id,plci->NL.Id,plci->NL.Req)); 8842 dbug(1,dprintf("%x:DREQ(%x:%x)",a->Id,plci->NL.Id,plci->NL.Req));
8843 plci->data_sent = TRUE; 8843 plci->data_sent = true;
8844 plci->data_sent_ptr = data->P; 8844 plci->data_sent_ptr = data->P;
8845 a->request(&plci->NL); 8845 a->request(&plci->NL);
8846 } 8846 }
@@ -8995,10 +8995,10 @@ void IndParse(PLCI * plci, word * parms_id, byte ** parms, byte multiIEsize)
8995byte ie_compare(byte * ie1, byte * ie2) 8995byte ie_compare(byte * ie1, byte * ie2)
8996{ 8996{
8997 word i; 8997 word i;
8998 if(!ie1 || ! ie2) return FALSE; 8998 if(!ie1 || ! ie2) return false;
8999 if(!ie1[0]) return FALSE; 8999 if(!ie1[0]) return false;
9000 for(i=0;i<(word)(ie1[0]+1);i++) if(ie1[i]!=ie2[i]) return FALSE; 9000 for(i=0;i<(word)(ie1[0]+1);i++) if(ie1[i]!=ie2[i]) return false;
9001 return TRUE; 9001 return true;
9002} 9002}
9003 9003
9004word find_cip(DIVA_CAPI_ADAPTER * a, byte * bc, byte * hlc) 9004word find_cip(DIVA_CAPI_ADAPTER * a, byte * bc, byte * hlc)
@@ -9151,7 +9151,7 @@ word AdvCodecSupport(DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, byte ho
9151 plci->tel=ADV_VOICE; 9151 plci->tel=ADV_VOICE;
9152 } 9152 }
9153 a->AdvSignalAppl = appl; 9153 a->AdvSignalAppl = appl;
9154 a->AdvCodecFLAG = TRUE; 9154 a->AdvCodecFLAG = true;
9155 a->AdvCodecPLCI = splci; 9155 a->AdvCodecPLCI = splci;
9156 add_p(splci,CAI,"\x01\x15"); 9156 add_p(splci,CAI,"\x01\x15");
9157 add_p(splci,LLI,"\x01\x00"); 9157 add_p(splci,LLI,"\x01\x00");
@@ -9183,7 +9183,7 @@ word AdvCodecSupport(DIVA_CAPI_ADAPTER *a, PLCI *plci, APPL *appl, byte ho
9183 add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30"); 9183 add_p(splci,UID,"\x06\x43\x61\x70\x69\x32\x30");
9184 sig_req(splci,ASSIGN,0xC0); /* 0xc0 is the TEL_ID */ 9184 sig_req(splci,ASSIGN,0xC0); /* 0xc0 is the TEL_ID */
9185 send_req(splci); 9185 send_req(splci);
9186 a->scom_appl_disable = TRUE; 9186 a->scom_appl_disable = true;
9187 } 9187 }
9188 else{ 9188 else{
9189 return 0x2001; /* wrong state, no more plcis */ 9189 return 0x2001; /* wrong state, no more plcis */
@@ -9411,7 +9411,7 @@ word CapiRelease(word Id)
9411 } 9411 }
9412 if(a->AdvSignalAppl==this) 9412 if(a->AdvSignalAppl==this)
9413 { 9413 {
9414 this->NullCREnable = FALSE; 9414 this->NullCREnable = false;
9415 if (a->AdvCodecPLCI) 9415 if (a->AdvCodecPLCI)
9416 { 9416 {
9417 plci_remove(a->AdvCodecPLCI); 9417 plci_remove(a->AdvCodecPLCI);
@@ -9433,7 +9433,7 @@ word CapiRelease(word Id)
9433 9433
9434static word plci_remove_check(PLCI *plci) 9434static word plci_remove_check(PLCI *plci)
9435{ 9435{
9436 if(!plci) return TRUE; 9436 if(!plci) return true;
9437 if(!plci->NL.Id && c_ind_mask_empty (plci)) 9437 if(!plci->NL.Id && c_ind_mask_empty (plci))
9438 { 9438 {
9439 if(plci->Sig.Id == 0xff) 9439 if(plci->Sig.Id == 0xff)
@@ -9446,7 +9446,7 @@ static word plci_remove_check(PLCI *plci)
9446 { 9446 {
9447 CodecIdCheck(plci->adapter, plci); 9447 CodecIdCheck(plci->adapter, plci);
9448 clear_b1_config (plci); 9448 clear_b1_config (plci);
9449 ncci_remove (plci, 0, FALSE); 9449 ncci_remove (plci, 0, false);
9450 plci_free_msg_in_queue (plci); 9450 plci_free_msg_in_queue (plci);
9451 channel_flow_control_remove (plci); 9451 channel_flow_control_remove (plci);
9452 plci->Id = 0; 9452 plci->Id = 0;
@@ -9456,10 +9456,10 @@ static word plci_remove_check(PLCI *plci)
9456 plci->notifiedcall = 0; 9456 plci->notifiedcall = 0;
9457 } 9457 }
9458 listen_check(plci->adapter); 9458 listen_check(plci->adapter);
9459 return TRUE; 9459 return true;
9460 } 9460 }
9461 } 9461 }
9462 return FALSE; 9462 return false;
9463} 9463}
9464 9464
9465 9465
@@ -9564,7 +9564,7 @@ static struct
9564 9564
9565}; 9565};
9566 9566
9567#define DTMF_DIGIT_MAP_ENTRIES (sizeof(dtmf_digit_map) / sizeof(dtmf_digit_map[0])) 9567#define DTMF_DIGIT_MAP_ENTRIES ARRAY_SIZE(dtmf_digit_map)
9568 9568
9569 9569
9570static void dtmf_enable_receiver (PLCI *plci, byte enable_mask) 9570static void dtmf_enable_receiver (PLCI *plci, byte enable_mask)
@@ -9815,7 +9815,7 @@ static void dtmf_command (dword Id, PLCI *plci, byte Rc)
9815 } 9815 }
9816 plci->dtmf_rec_active &= ~mask; 9816 plci->dtmf_rec_active &= ~mask;
9817 plci->internal_command = DTMF_COMMAND_2; 9817 plci->internal_command = DTMF_COMMAND_2;
9818 dtmf_enable_receiver (plci, FALSE); 9818 dtmf_enable_receiver (plci, false);
9819 return; 9819 return;
9820 } 9820 }
9821 Rc = OK; 9821 Rc = OK;
@@ -10020,7 +10020,7 @@ static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
10020 } 10020 }
10021 } 10021 }
10022 start_internal_command (Id, plci, dtmf_command); 10022 start_internal_command (Id, plci, dtmf_command);
10023 return (FALSE); 10023 return (false);
10024 10024
10025 10025
10026 case DTMF_SEND_TONE: 10026 case DTMF_SEND_TONE:
@@ -10069,8 +10069,7 @@ static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
10069 PUT_WORD (&result[1], DTMF_INCORRECT_DIGIT); 10069 PUT_WORD (&result[1], DTMF_INCORRECT_DIGIT);
10070 break; 10070 break;
10071 } 10071 }
10072 if (plci->dtmf_send_requests >= 10072 if (plci->dtmf_send_requests >= ARRAY_SIZE(plci->dtmf_msg_number_queue))
10073 sizeof(plci->dtmf_msg_number_queue) / sizeof(plci->dtmf_msg_number_queue[0]))
10074 { 10073 {
10075 dbug (1, dprintf ("[%06lx] %s,%d: DTMF request overrun", 10074 dbug (1, dprintf ("[%06lx] %s,%d: DTMF request overrun",
10076 UnMapId (Id), (char *)(FILE_), __LINE__)); 10075 UnMapId (Id), (char *)(FILE_), __LINE__));
@@ -10079,7 +10078,7 @@ static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
10079 } 10078 }
10080 api_save_msg (dtmf_parms, "wwws", &plci->saved_msg); 10079 api_save_msg (dtmf_parms, "wwws", &plci->saved_msg);
10081 start_internal_command (Id, plci, dtmf_command); 10080 start_internal_command (Id, plci, dtmf_command);
10082 return (FALSE); 10081 return (false);
10083 10082
10084 default: 10083 default:
10085 dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x", 10084 dbug (1, dprintf ("[%06lx] %s,%d: DTMF unknown request %04x",
@@ -10090,7 +10089,7 @@ static byte dtmf_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
10090 } 10089 }
10091 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number, 10090 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
10092 "wws", Info, SELECTOR_DTMF, result); 10091 "wws", Info, SELECTOR_DTMF, result);
10093 return (FALSE); 10092 return (false);
10094} 10093}
10095 10094
10096 10095
@@ -10842,10 +10841,10 @@ static struct
10842 byte to_pc; 10841 byte to_pc;
10843} xconnect_write_prog[] = 10842} xconnect_write_prog[] =
10844{ 10843{
10845 { LI_COEF_CH_CH, FALSE, FALSE }, 10844 { LI_COEF_CH_CH, false, false },
10846 { LI_COEF_CH_PC, FALSE, TRUE }, 10845 { LI_COEF_CH_PC, false, true },
10847 { LI_COEF_PC_CH, TRUE, FALSE }, 10846 { LI_COEF_PC_CH, true, false },
10848 { LI_COEF_PC_PC, TRUE, TRUE } 10847 { LI_COEF_PC_PC, true, true }
10849}; 10848};
10850 10849
10851 10850
@@ -10916,7 +10915,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
10916 { 10915 {
10917 dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out", 10916 dbug (1, dprintf ("[%06x] %s,%d: Channel id wiped out",
10918 UnMapId (Id), (char *)(FILE_), __LINE__)); 10917 UnMapId (Id), (char *)(FILE_), __LINE__));
10919 return (TRUE); 10918 return (true);
10920 } 10919 }
10921 i = a->li_base + (plci->li_bchannel_id - 1); 10920 i = a->li_base + (plci->li_bchannel_id - 1);
10922 j = plci->li_write_channel; 10921 j = plci->li_write_channel;
@@ -10927,7 +10926,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
10927 { 10926 {
10928 dbug (1, dprintf ("[%06lx] %s,%d: LI write coefs failed %02x", 10927 dbug (1, dprintf ("[%06lx] %s,%d: LI write coefs failed %02x",
10929 UnMapId (Id), (char *)(FILE_), __LINE__, Rc)); 10928 UnMapId (Id), (char *)(FILE_), __LINE__, Rc));
10930 return (FALSE); 10929 return (false);
10931 } 10930 }
10932 } 10931 }
10933 if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT) 10932 if (li_config_table[i].adapter->manufacturer_features & MANUFACTURER_FEATURE_XCONNECT)
@@ -10969,7 +10968,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
10969 { 10968 {
10970 plci->internal_command = plci->li_write_command; 10969 plci->internal_command = plci->li_write_command;
10971 if (plci_nl_busy (plci)) 10970 if (plci_nl_busy (plci))
10972 return (TRUE); 10971 return (true);
10973 to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0; 10972 to_ch = (a->li_pri) ? plci->li_bchannel_id - 1 : 0;
10974 *(p++) = UDATA_REQUEST_XCONNECT_TO; 10973 *(p++) = UDATA_REQUEST_XCONNECT_TO;
10975 do 10974 do
@@ -11018,9 +11017,9 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
11018 li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4; 11017 li_config_table[i].coef_table[j] ^= xconnect_write_prog[n].mask << 4;
11019 } 11018 }
11020 n++; 11019 n++;
11021 } while ((n < sizeof(xconnect_write_prog) / sizeof(xconnect_write_prog[0])) 11020 } while ((n < ARRAY_SIZE(xconnect_write_prog))
11022 && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE)); 11021 && ((p - plci->internal_req_buffer) + 16 < INTERNAL_REQ_BUFFER_SIZE));
11023 if (n == sizeof(xconnect_write_prog) / sizeof(xconnect_write_prog[0])) 11022 if (n == ARRAY_SIZE(xconnect_write_prog))
11024 { 11023 {
11025 do 11024 do
11026 { 11025 {
@@ -11050,7 +11049,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
11050 { 11049 {
11051 plci->internal_command = plci->li_write_command; 11050 plci->internal_command = plci->li_write_command;
11052 if (plci_nl_busy (plci)) 11051 if (plci_nl_busy (plci))
11053 return (TRUE); 11052 return (true);
11054 if (a->li_pri) 11053 if (a->li_pri)
11055 { 11054 {
11056 *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC; 11055 *(p++) = UDATA_REQUEST_SET_MIXER_COEFS_PRI_SYNC;
@@ -11090,7 +11089,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
11090 ch_map[j+1] = (byte)(j+1); 11089 ch_map[j+1] = (byte)(j+1);
11091 } 11090 }
11092 } 11091 }
11093 for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++) 11092 for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
11094 { 11093 {
11095 i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch]; 11094 i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
11096 j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch]; 11095 j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
@@ -11127,7 +11126,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
11127 { 11126 {
11128 plci->internal_command = plci->li_write_command; 11127 plci->internal_command = plci->li_write_command;
11129 if (plci_nl_busy (plci)) 11128 if (plci_nl_busy (plci))
11130 return (TRUE); 11129 return (true);
11131 if (j < a->li_base) 11130 if (j < a->li_base)
11132 j = a->li_base; 11131 j = a->li_base;
11133 if (a->li_pri) 11132 if (a->li_pri)
@@ -11140,7 +11139,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
11140 w |= MIXER_FEATURE_ENABLE_RX_DATA; 11139 w |= MIXER_FEATURE_ENABLE_RX_DATA;
11141 *(p++) = (byte) w; 11140 *(p++) = (byte) w;
11142 *(p++) = (byte)(w >> 8); 11141 *(p++) = (byte)(w >> 8);
11143 for (n = 0; n < sizeof(mixer_write_prog_pri) / sizeof(mixer_write_prog_pri[0]); n++) 11142 for (n = 0; n < ARRAY_SIZE(mixer_write_prog_pri); n++)
11144 { 11143 {
11145 *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags); 11144 *(p++) = (byte)((plci->li_bchannel_id - 1) | mixer_write_prog_pri[n].line_flags);
11146 for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++) 11145 for (j = a->li_base; j < a->li_base + MIXER_CHANNELS_PRI; j++)
@@ -11196,7 +11195,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
11196 ch_map[j+1] = (byte)(j+1); 11195 ch_map[j+1] = (byte)(j+1);
11197 } 11196 }
11198 } 11197 }
11199 for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++) 11198 for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
11200 { 11199 {
11201 i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch]; 11200 i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
11202 j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch]; 11201 j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
@@ -11232,7 +11231,7 @@ static byte xconnect_write_coefs_process (dword Id, PLCI *plci, byte Rc)
11232 plci->NL.Req = plci->nl_req = (byte) N_UDATA; 11231 plci->NL.Req = plci->nl_req = (byte) N_UDATA;
11233 plci->adapter->request (&plci->NL); 11232 plci->adapter->request (&plci->NL);
11234 } 11233 }
11235 return (TRUE); 11234 return (true);
11236} 11235}
11237 11236
11238 11237
@@ -11251,7 +11250,7 @@ static void mixer_notify_update (PLCI *plci, byte others)
11251 if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED) 11250 if (a->profile.Global_Options & GL_LINE_INTERCONNECT_SUPPORTED)
11252 { 11251 {
11253 if (others) 11252 if (others)
11254 plci->li_notify_update = TRUE; 11253 plci->li_notify_update = true;
11255 i = 0; 11254 i = 0;
11256 do 11255 do
11257 { 11256 {
@@ -11277,7 +11276,7 @@ static void mixer_notify_update (PLCI *plci, byte others)
11277 && (notify_plci->State) 11276 && (notify_plci->State)
11278 && notify_plci->NL.Id && !notify_plci->nl_remove_id) 11277 && notify_plci->NL.Id && !notify_plci->nl_remove_id)
11279 { 11278 {
11280 notify_plci->li_notify_update = TRUE; 11279 notify_plci->li_notify_update = true;
11281 ((CAPI_MSG *) msg)->header.length = 18; 11280 ((CAPI_MSG *) msg)->header.length = 18;
11282 ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id; 11281 ((CAPI_MSG *) msg)->header.appl_id = notify_plci->appl->Id;
11283 ((CAPI_MSG *) msg)->header.command = _FACILITY_R; 11282 ((CAPI_MSG *) msg)->header.command = _FACILITY_R;
@@ -11299,12 +11298,12 @@ static void mixer_notify_update (PLCI *plci, byte others)
11299 (char *)(FILE_), __LINE__, 11298 (char *)(FILE_), __LINE__,
11300 (dword)((notify_plci->Id << 8) | UnMapController (notify_plci->adapter->Id)), w)); 11299 (dword)((notify_plci->Id << 8) | UnMapController (notify_plci->adapter->Id)), w));
11301 } 11300 }
11302 notify_plci->li_notify_update = FALSE; 11301 notify_plci->li_notify_update = false;
11303 } 11302 }
11304 } 11303 }
11305 } while (others && (notify_plci != NULL)); 11304 } while (others && (notify_plci != NULL));
11306 if (others) 11305 if (others)
11307 plci->li_notify_update = FALSE; 11306 plci->li_notify_update = false;
11308 } 11307 }
11309} 11308}
11310 11309
@@ -11318,7 +11317,7 @@ static void mixer_clear_config (PLCI *plci)
11318 (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)), 11317 (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
11319 (char *)(FILE_), __LINE__)); 11318 (char *)(FILE_), __LINE__));
11320 11319
11321 plci->li_notify_update = FALSE; 11320 plci->li_notify_update = false;
11322 plci->li_plci_b_write_pos = 0; 11321 plci->li_plci_b_write_pos = 0;
11323 plci->li_plci_b_read_pos = 0; 11322 plci->li_plci_b_read_pos = 0;
11324 plci->li_plci_b_req_pos = 0; 11323 plci->li_plci_b_req_pos = 0;
@@ -12159,7 +12158,7 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12159 plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]); 12158 plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
12160 if (plci_b == NULL) 12159 if (plci_b == NULL)
12161 break; 12160 break;
12162 li_update_connect (Id, a, plci, plci_b_id, TRUE, li_flags); 12161 li_update_connect (Id, a, plci, plci_b_id, true, li_flags);
12163 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG; 12162 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_LAST_FLAG;
12164 plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1; 12163 plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
12165 plci->li_plci_b_write_pos = plci_b_write_pos; 12164 plci->li_plci_b_write_pos = plci_b_write_pos;
@@ -12188,7 +12187,7 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12188 plci_b_write_pos = plci->li_plci_b_write_pos; 12187 plci_b_write_pos = plci->li_plci_b_write_pos;
12189 participant_parms_pos = 0; 12188 participant_parms_pos = 0;
12190 result_pos = 7; 12189 result_pos = 7;
12191 li2_update_connect (Id, a, plci, UnMapId (Id), TRUE, li_flags); 12190 li2_update_connect (Id, a, plci, UnMapId (Id), true, li_flags);
12192 while (participant_parms_pos < li_req_parms[1].length) 12191 while (participant_parms_pos < li_req_parms[1].length)
12193 { 12192 {
12194 result[result_pos] = 6; 12193 result[result_pos] = 6;
@@ -12224,7 +12223,7 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12224 plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]); 12223 plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
12225 if (plci_b != NULL) 12224 if (plci_b != NULL)
12226 { 12225 {
12227 li2_update_connect (Id, a, plci, plci_b_id, TRUE, li_flags); 12226 li2_update_connect (Id, a, plci, plci_b_id, true, li_flags);
12228 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | 12227 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id |
12229 ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A | 12228 ((li_flags & (LI2_FLAG_INTERCONNECT_A_B | LI2_FLAG_INTERCONNECT_B_A |
12230 LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG); 12229 LI2_FLAG_PCCONNECT_A_B | LI2_FLAG_PCCONNECT_B_A)) ? 0 : LI_PLCI_B_DISC_FLAG);
@@ -12249,13 +12248,13 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12249 } 12248 }
12250 mixer_calculate_coefs (a); 12249 mixer_calculate_coefs (a);
12251 plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel; 12250 plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
12252 mixer_notify_update (plci, TRUE); 12251 mixer_notify_update (plci, true);
12253 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number, 12252 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
12254 "wwS", Info, SELECTOR_LINE_INTERCONNECT, result); 12253 "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
12255 plci->command = 0; 12254 plci->command = 0;
12256 plci->li_cmd = GET_WORD (li_parms[0].info); 12255 plci->li_cmd = GET_WORD (li_parms[0].info);
12257 start_internal_command (Id, plci, mixer_command); 12256 start_internal_command (Id, plci, mixer_command);
12258 return (FALSE); 12257 return (false);
12259 12258
12260 case LI_REQ_DISCONNECT: 12259 case LI_REQ_DISCONNECT:
12261 if (li_parms[1].length == 4) 12260 if (li_parms[1].length == 4)
@@ -12283,7 +12282,7 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12283 plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]); 12282 plci_b = li_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[8]);
12284 if (plci_b == NULL) 12283 if (plci_b == NULL)
12285 break; 12284 break;
12286 li_update_connect (Id, a, plci, plci_b_id, FALSE, 0); 12285 li_update_connect (Id, a, plci, plci_b_id, false, 0);
12287 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG; 12286 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG | LI_PLCI_B_LAST_FLAG;
12288 plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1; 12287 plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
12289 plci->li_plci_b_write_pos = plci_b_write_pos; 12288 plci->li_plci_b_write_pos = plci_b_write_pos;
@@ -12345,7 +12344,7 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12345 plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]); 12344 plci_b = li2_check_plci_b (Id, plci, plci_b_id, plci_b_write_pos, &result[result_pos - 2]);
12346 if (plci_b != NULL) 12345 if (plci_b != NULL)
12347 { 12346 {
12348 li2_update_connect (Id, a, plci, plci_b_id, FALSE, 0); 12347 li2_update_connect (Id, a, plci, plci_b_id, false, 0);
12349 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG; 12348 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
12350 plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1; 12349 plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
12351 } 12350 }
@@ -12368,13 +12367,13 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12368 } 12367 }
12369 mixer_calculate_coefs (a); 12368 mixer_calculate_coefs (a);
12370 plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel; 12369 plci->li_channel_bits = li_config_table[a->li_base + (plci->li_bchannel_id - 1)].channel;
12371 mixer_notify_update (plci, TRUE); 12370 mixer_notify_update (plci, true);
12372 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number, 12371 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
12373 "wwS", Info, SELECTOR_LINE_INTERCONNECT, result); 12372 "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
12374 plci->command = 0; 12373 plci->command = 0;
12375 plci->li_cmd = GET_WORD (li_parms[0].info); 12374 plci->li_cmd = GET_WORD (li_parms[0].info);
12376 start_internal_command (Id, plci, mixer_command); 12375 start_internal_command (Id, plci, mixer_command);
12377 return (FALSE); 12376 return (false);
12378 12377
12379 case LI_REQ_SILENT_UPDATE: 12378 case LI_REQ_SILENT_UPDATE:
12380 if (!plci || !plci->State 12379 if (!plci || !plci->State
@@ -12384,7 +12383,7 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12384 { 12383 {
12385 dbug (1, dprintf ("[%06lx] %s,%d: Wrong state", 12384 dbug (1, dprintf ("[%06lx] %s,%d: Wrong state",
12386 UnMapId (Id), (char *)(FILE_), __LINE__)); 12385 UnMapId (Id), (char *)(FILE_), __LINE__));
12387 return (FALSE); 12386 return (false);
12388 } 12387 }
12389 plci_b_write_pos = plci->li_plci_b_write_pos; 12388 plci_b_write_pos = plci->li_plci_b_write_pos;
12390 if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos : 12389 if (((plci->li_plci_b_read_pos > plci_b_write_pos) ? plci->li_plci_b_read_pos :
@@ -12392,7 +12391,7 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12392 { 12391 {
12393 dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun", 12392 dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
12394 UnMapId (Id), (char *)(FILE_), __LINE__)); 12393 UnMapId (Id), (char *)(FILE_), __LINE__));
12395 return (FALSE); 12394 return (false);
12396 } 12395 }
12397 i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1; 12396 i = (plci_b_write_pos == 0) ? LI_PLCI_B_QUEUE_ENTRIES-1 : plci_b_write_pos - 1;
12398 if ((plci_b_write_pos == plci->li_plci_b_read_pos) 12397 if ((plci_b_write_pos == plci->li_plci_b_read_pos)
@@ -12408,7 +12407,7 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12408 plci->command = 0; 12407 plci->command = 0;
12409 plci->li_cmd = GET_WORD (li_parms[0].info); 12408 plci->li_cmd = GET_WORD (li_parms[0].info);
12410 start_internal_command (Id, plci, mixer_command); 12409 start_internal_command (Id, plci, mixer_command);
12411 return (FALSE); 12410 return (false);
12412 12411
12413 default: 12412 default:
12414 dbug (1, dprintf ("[%06lx] %s,%d: LI unknown request %04x", 12413 dbug (1, dprintf ("[%06lx] %s,%d: LI unknown request %04x",
@@ -12418,7 +12417,7 @@ static byte mixer_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI
12418 } 12417 }
12419 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number, 12418 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
12420 "wwS", Info, SELECTOR_LINE_INTERCONNECT, result); 12419 "wwS", Info, SELECTOR_LINE_INTERCONNECT, result);
12421 return (FALSE); 12420 return (false);
12422} 12421}
12423 12422
12424 12423
@@ -12523,7 +12522,7 @@ static void mixer_indication_xconnect_from (dword Id, PLCI *plci, byte *msg,
12523 if (!plci->internal_command) 12522 if (!plci->internal_command)
12524 next_internal_command (Id, plci); 12523 next_internal_command (Id, plci);
12525 } 12524 }
12526 mixer_notify_update (plci, TRUE); 12525 mixer_notify_update (plci, true);
12527} 12526}
12528 12527
12529 12528
@@ -12547,12 +12546,12 @@ static byte mixer_notify_source_removed (PLCI *plci, dword plci_b_id)
12547 dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun", 12546 dbug (1, dprintf ("[%06lx] %s,%d: LI request overrun",
12548 (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)), 12547 (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
12549 (char *)(FILE_), __LINE__)); 12548 (char *)(FILE_), __LINE__));
12550 return (FALSE); 12549 return (false);
12551 } 12550 }
12552 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG; 12551 plci->li_plci_b_queue[plci_b_write_pos] = plci_b_id | LI_PLCI_B_DISC_FLAG;
12553 plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1; 12552 plci_b_write_pos = (plci_b_write_pos == LI_PLCI_B_QUEUE_ENTRIES-1) ? 0 : plci_b_write_pos + 1;
12554 plci->li_plci_b_write_pos = plci_b_write_pos; 12553 plci->li_plci_b_write_pos = plci_b_write_pos;
12555 return (TRUE); 12554 return (true);
12556} 12555}
12557 12556
12558 12557
@@ -12596,7 +12595,7 @@ static void mixer_remove (PLCI *plci)
12596 } 12595 }
12597 mixer_clear_config (plci); 12596 mixer_clear_config (plci);
12598 mixer_calculate_coefs (a); 12597 mixer_calculate_coefs (a);
12599 mixer_notify_update (plci, TRUE); 12598 mixer_notify_update (plci, true);
12600 } 12599 }
12601 li_config_table[i].plci = NULL; 12600 li_config_table[i].plci = NULL;
12602 plci->li_bchannel_id = 0; 12601 plci->li_bchannel_id = 0;
@@ -12883,29 +12882,29 @@ static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *p
12883 case EC_ENABLE_OPERATION: 12882 case EC_ENABLE_OPERATION:
12884 plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS; 12883 plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
12885 start_internal_command (Id, plci, ec_command); 12884 start_internal_command (Id, plci, ec_command);
12886 return (FALSE); 12885 return (false);
12887 12886
12888 case EC_DISABLE_OPERATION: 12887 case EC_DISABLE_OPERATION:
12889 plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER | 12888 plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
12890 LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING | 12889 LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
12891 LEC_RESET_COEFFICIENTS; 12890 LEC_RESET_COEFFICIENTS;
12892 start_internal_command (Id, plci, ec_command); 12891 start_internal_command (Id, plci, ec_command);
12893 return (FALSE); 12892 return (false);
12894 12893
12895 case EC_FREEZE_COEFFICIENTS: 12894 case EC_FREEZE_COEFFICIENTS:
12896 plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS; 12895 plci->ec_idi_options |= LEC_FREEZE_COEFFICIENTS;
12897 start_internal_command (Id, plci, ec_command); 12896 start_internal_command (Id, plci, ec_command);
12898 return (FALSE); 12897 return (false);
12899 12898
12900 case EC_RESUME_COEFFICIENT_UPDATE: 12899 case EC_RESUME_COEFFICIENT_UPDATE:
12901 plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS; 12900 plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
12902 start_internal_command (Id, plci, ec_command); 12901 start_internal_command (Id, plci, ec_command);
12903 return (FALSE); 12902 return (false);
12904 12903
12905 case EC_RESET_COEFFICIENTS: 12904 case EC_RESET_COEFFICIENTS:
12906 plci->ec_idi_options |= LEC_RESET_COEFFICIENTS; 12905 plci->ec_idi_options |= LEC_RESET_COEFFICIENTS;
12907 start_internal_command (Id, plci, ec_command); 12906 start_internal_command (Id, plci, ec_command);
12908 return (FALSE); 12907 return (false);
12909 12908
12910 default: 12909 default:
12911 dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x", 12910 dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
@@ -12978,14 +12977,14 @@ static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *p
12978 case EC_ENABLE_OPERATION: 12977 case EC_ENABLE_OPERATION:
12979 plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS; 12978 plci->ec_idi_options &= ~LEC_FREEZE_COEFFICIENTS;
12980 start_internal_command (Id, plci, ec_command); 12979 start_internal_command (Id, plci, ec_command);
12981 return (FALSE); 12980 return (false);
12982 12981
12983 case EC_DISABLE_OPERATION: 12982 case EC_DISABLE_OPERATION:
12984 plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER | 12983 plci->ec_idi_options = LEC_ENABLE_ECHO_CANCELLER |
12985 LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING | 12984 LEC_MANUAL_DISABLE | LEC_ENABLE_NONLINEAR_PROCESSING |
12986 LEC_RESET_COEFFICIENTS; 12985 LEC_RESET_COEFFICIENTS;
12987 start_internal_command (Id, plci, ec_command); 12986 start_internal_command (Id, plci, ec_command);
12988 return (FALSE); 12987 return (false);
12989 12988
12990 default: 12989 default:
12991 dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x", 12990 dbug (1, dprintf ("[%06lx] %s,%d: EC unknown request %04x",
@@ -12999,7 +12998,7 @@ static byte ec_request (dword Id, word Number, DIVA_CAPI_ADAPTER *a, PLCI *p
12999 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number, 12998 sendf (appl, _FACILITY_R | CONFIRM, Id & 0xffffL, Number,
13000 "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ? 12999 "wws", Info, (appl->appl_flags & APPL_FLAG_PRIV_EC_SPEC) ?
13001 PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result); 13000 PRIV_SELECTOR_ECHO_CANCELLER : SELECTOR_ECHO_CANCELLER, result);
13002 return (FALSE); 13001 return (false);
13003} 13002}
13004 13003
13005 13004
@@ -13178,7 +13177,7 @@ static void adv_voice_write_coefs (PLCI *plci, word write_command)
13178 ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1)); 13177 ch_map[j] = (byte)(j + (plci->li_bchannel_id - 1));
13179 ch_map[j+1] = (byte)(j + (2 - plci->li_bchannel_id)); 13178 ch_map[j+1] = (byte)(j + (2 - plci->li_bchannel_id));
13180 } 13179 }
13181 for (n = 0; n < sizeof(mixer_write_prog_bri) / sizeof(mixer_write_prog_bri[0]); n++) 13180 for (n = 0; n < ARRAY_SIZE(mixer_write_prog_bri); n++)
13182 { 13181 {
13183 i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch]; 13182 i = a->li_base + ch_map[mixer_write_prog_bri[n].to_ch];
13184 j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch]; 13183 j = a->li_base + ch_map[mixer_write_prog_bri[n].from_ch];
@@ -13563,7 +13562,7 @@ static void adjust_b_clear (PLCI *plci)
13563 (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)), 13562 (dword)((plci->Id << 8) | UnMapController (plci->adapter->Id)),
13564 (char *)(FILE_), __LINE__)); 13563 (char *)(FILE_), __LINE__));
13565 13564
13566 plci->adjust_b_restore = FALSE; 13565 plci->adjust_b_restore = false;
13567} 13566}
13568 13567
13569 13568
@@ -13832,7 +13831,7 @@ static word adjust_b_process (dword Id, PLCI *plci, byte Rc)
13832 } 13831 }
13833 if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT) 13832 if (plci->adjust_b_mode & ADJUST_B_MODE_USER_CONNECT)
13834 { 13833 {
13835 plci->adjust_b_restore = TRUE; 13834 plci->adjust_b_restore = true;
13836 break; 13835 break;
13837 } 13836 }
13838 plci->adjust_b_state = ADJUST_B_CONNECT_1; 13837 plci->adjust_b_state = ADJUST_B_CONNECT_1;
@@ -14603,7 +14602,7 @@ static void channel_request_xon (PLCI * plci, byte ch) {
14603 14602
14604static void channel_xmit_extended_xon (PLCI * plci) { 14603static void channel_xmit_extended_xon (PLCI * plci) {
14605 DIVA_CAPI_ADAPTER * a; 14604 DIVA_CAPI_ADAPTER * a;
14606 int max_ch = sizeof(a->ch_flow_control)/sizeof(a->ch_flow_control[0]); 14605 int max_ch = ARRAY_SIZE(a->ch_flow_control);
14607 int i, one_requested = 0; 14606 int i, one_requested = 0;
14608 14607
14609 if ((!plci) || (!plci->Id) || ((a = plci->adapter) == 0)) { 14608 if ((!plci) || (!plci->Id) || ((a = plci->adapter) == 0)) {
@@ -14628,7 +14627,7 @@ static void channel_xmit_extended_xon (PLCI * plci) {
14628 Try to xmit next X_ON 14627 Try to xmit next X_ON
14629 */ 14628 */
14630static int find_channel_with_pending_x_on (DIVA_CAPI_ADAPTER * a, PLCI * plci) { 14629static int find_channel_with_pending_x_on (DIVA_CAPI_ADAPTER * a, PLCI * plci) {
14631 int max_ch = sizeof(a->ch_flow_control)/sizeof(a->ch_flow_control[0]); 14630 int max_ch = ARRAY_SIZE(a->ch_flow_control);
14632 int i; 14631 int i;
14633 14632
14634 if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) { 14633 if (!(plci->adapter->manufacturer_features & MANUFACTURER_FEATURE_XONOFF_FLOW_CONTROL)) {
@@ -14768,19 +14767,19 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
14768 { 14767 {
14769 if(application[i].Id && a->CIP_Mask[i] ) 14768 if(application[i].Id && a->CIP_Mask[i] )
14770 { 14769 {
14771 for(k=0,busy=FALSE; k<a->max_plci; k++) 14770 for(k=0,busy=false; k<a->max_plci; k++)
14772 { 14771 {
14773 if(a->plci[k].Id) 14772 if(a->plci[k].Id)
14774 { 14773 {
14775 auxplci = &a->plci[k]; 14774 auxplci = &a->plci[k];
14776 if(auxplci->appl == &application[i]) /* application has a busy PLCI */ 14775 if(auxplci->appl == &application[i]) /* application has a busy PLCI */
14777 { 14776 {
14778 busy = TRUE; 14777 busy = true;
14779 dbug(1,dprintf("Appl 0x%x is busy",i+1)); 14778 dbug(1,dprintf("Appl 0x%x is busy",i+1));
14780 } 14779 }
14781 else if(test_c_ind_mask_bit (auxplci, i)) /* application has an incoming call pending */ 14780 else if(test_c_ind_mask_bit (auxplci, i)) /* application has an incoming call pending */
14782 { 14781 {
14783 busy = TRUE; 14782 busy = true;
14784 dbug(1,dprintf("Appl 0x%x has inc. call pending",i+1)); 14783 dbug(1,dprintf("Appl 0x%x has inc. call pending",i+1));
14785 } 14784 }
14786 } 14785 }
@@ -14791,13 +14790,13 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
14791 if(j==MAX_CIP_TYPES) /* all groups are in use but group still not found */ 14790 if(j==MAX_CIP_TYPES) /* all groups are in use but group still not found */
14792 { /* the MAX_CIP_TYPES group enables all calls because of field overflow */ 14791 { /* the MAX_CIP_TYPES group enables all calls because of field overflow */
14793 appl_number_group_type[i] = MAX_CIP_TYPES; 14792 appl_number_group_type[i] = MAX_CIP_TYPES;
14794 group_found=TRUE; 14793 group_found=true;
14795 dbug(1,dprintf("Field overflow appl 0x%x",i+1)); 14794 dbug(1,dprintf("Field overflow appl 0x%x",i+1));
14796 } 14795 }
14797 else if( (info_mask_group[j]==a->CIP_Mask[i]) && (cip_mask_group[j]==a->Info_Mask[i]) ) 14796 else if( (info_mask_group[j]==a->CIP_Mask[i]) && (cip_mask_group[j]==a->Info_Mask[i]) )
14798 { /* is group already present ? */ 14797 { /* is group already present ? */
14799 appl_number_group_type[i] = j|0x80; /* store the group number for each application */ 14798 appl_number_group_type[i] = j|0x80; /* store the group number for each application */
14800 group_found=TRUE; 14799 group_found=true;
14801 dbug(1,dprintf("Group 0x%x found with appl 0x%x, CIP=0x%lx",appl_number_group_type[i],i+1,info_mask_group[j])); 14800 dbug(1,dprintf("Group 0x%x found with appl 0x%x, CIP=0x%lx",appl_number_group_type[i],i+1,info_mask_group[j]));
14802 } 14801 }
14803 else if(!info_mask_group[j]) 14802 else if(!info_mask_group[j])
@@ -14805,7 +14804,7 @@ static void group_optimization(DIVA_CAPI_ADAPTER * a, PLCI * plci)
14805 appl_number_group_type[i] = j|0x80; /* store the group number for each application */ 14804 appl_number_group_type[i] = j|0x80; /* store the group number for each application */
14806 info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */ 14805 info_mask_group[j] = a->CIP_Mask[i]; /* store the new CIP mask for the new group */
14807 cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */ 14806 cip_mask_group[j] = a->Info_Mask[i]; /* store the new Info_Mask for this new group */
14808 group_found=TRUE; 14807 group_found=true;
14809 dbug(1,dprintf("New Group 0x%x established with appl 0x%x, CIP=0x%lx",appl_number_group_type[i],i+1,info_mask_group[j])); 14808 dbug(1,dprintf("New Group 0x%x established with appl 0x%x, CIP=0x%lx",appl_number_group_type[i],i+1,info_mask_group[j]));
14810 } 14809 }
14811 } 14810 }
@@ -14860,7 +14859,7 @@ word CapiRegister(word id)
14860 } 14859 }
14861 } 14860 }
14862 14861
14863 if(appls_found) return TRUE; 14862 if(appls_found) return true;
14864 for(i=0; i<max_adapter; i++) /* scan all adapters... */ 14863 for(i=0; i<max_adapter; i++) /* scan all adapters... */
14865 { 14864 {
14866 a = &adapter[i]; 14865 a = &adapter[i];
@@ -14889,7 +14888,7 @@ word CapiRegister(word id)
14889 } 14888 }
14890 } 14889 }
14891 } 14890 }
14892 return FALSE; 14891 return false;
14893} 14892}
14894 14893
14895/*------------------------------------------------------------------*/ 14894/*------------------------------------------------------------------*/
diff --git a/drivers/isdn/hardware/eicon/os_pri.c b/drivers/isdn/hardware/eicon/os_pri.c
index a296a846f29..903356547b7 100644
--- a/drivers/isdn/hardware/eicon/os_pri.c
+++ b/drivers/isdn/hardware/eicon/os_pri.c
@@ -487,7 +487,7 @@ diva_pri_start_adapter(PISDN_ADAPTER IoAdapter,
487 } 487 }
488 DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot); 488 DIVA_OS_MEM_DETACH_ADDRESS(IoAdapter, boot);
489 489
490 IoAdapter->Initialized = TRUE; 490 IoAdapter->Initialized = true;
491 491
492 /* 492 /*
493 Check Interrupt 493 Check Interrupt
@@ -504,7 +504,7 @@ diva_pri_start_adapter(PISDN_ADAPTER IoAdapter,
504 if (!IoAdapter->IrqCount) { 504 if (!IoAdapter->IrqCount) {
505 DBG_ERR(("A: A(%d) interrupt test failed", 505 DBG_ERR(("A: A(%d) interrupt test failed",
506 IoAdapter->ANum)) 506 IoAdapter->ANum))
507 IoAdapter->Initialized = FALSE; 507 IoAdapter->Initialized = false;
508 IoAdapter->stop(IoAdapter); 508 IoAdapter->stop(IoAdapter);
509 return (-1); 509 return (-1);
510 } 510 }
diff --git a/drivers/isdn/hardware/eicon/platform.h b/drivers/isdn/hardware/eicon/platform.h
index 2444811e0b3..ff09f07f440 100644
--- a/drivers/isdn/hardware/eicon/platform.h
+++ b/drivers/isdn/hardware/eicon/platform.h
@@ -71,14 +71,6 @@
71#define qword u64 71#define qword u64
72#endif 72#endif
73 73
74#ifndef TRUE
75#define TRUE 1
76#endif
77
78#ifndef FALSE
79#define FALSE 0
80#endif
81
82#ifndef NULL 74#ifndef NULL
83#define NULL ((void *) 0) 75#define NULL ((void *) 0)
84#endif 76#endif
@@ -131,10 +123,6 @@
131#define DIVA_OS_MEM_DETACH_CONFIG(a, x) do { } while(0) 123#define DIVA_OS_MEM_DETACH_CONFIG(a, x) do { } while(0)
132#define DIVA_OS_MEM_DETACH_CONTROL(a, x) do { } while(0) 124#define DIVA_OS_MEM_DETACH_CONTROL(a, x) do { } while(0)
133 125
134#if !defined(DIM)
135#define DIM(array) (sizeof (array)/sizeof ((array)[0]))
136#endif
137
138#define DIVA_INVALID_FILE_HANDLE ((dword)(-1)) 126#define DIVA_INVALID_FILE_HANDLE ((dword)(-1))
139 127
140#define DIVAS_CONTAINING_RECORD(address, type, field) \ 128#define DIVAS_CONTAINING_RECORD(address, type, field) \
diff --git a/drivers/isdn/hisax/Kconfig b/drivers/isdn/hisax/Kconfig
index 34ab5f7dcab..12d91fb9f8c 100644
--- a/drivers/isdn/hisax/Kconfig
+++ b/drivers/isdn/hisax/Kconfig
@@ -340,8 +340,6 @@ config HISAX_HFC_SX
340 This enables HiSax support for the HFC-S+, HFC-SP and HFC-PCMCIA 340 This enables HiSax support for the HFC-S+, HFC-SP and HFC-PCMCIA
341 cards. This code is not finished yet. 341 cards. This code is not finished yet.
342 342
343# bool ' TESTEMULATOR (EXPERIMENTAL)' CONFIG_HISAX_TESTEMU
344
345config HISAX_ENTERNOW_PCI 343config HISAX_ENTERNOW_PCI
346 bool "Formula-n enter:now PCI card" 344 bool "Formula-n enter:now PCI card"
347 depends on HISAX_NETJET && PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV)) 345 depends on HISAX_NETJET && PCI && (BROKEN || !(SPARC || PPC || PARISC || M68K || (MIPS && !CPU_LITTLE_ENDIAN) || FRV))
diff --git a/drivers/isdn/hisax/Makefile b/drivers/isdn/hisax/Makefile
index 293e27789d5..c7a3794bdae 100644
--- a/drivers/isdn/hisax/Makefile
+++ b/drivers/isdn/hisax/Makefile
@@ -60,5 +60,4 @@ hisax-$(CONFIG_HISAX_SCT_QUADRO) += bkm_a8.o isac.o arcofi.o hscx.o
60hisax-$(CONFIG_HISAX_GAZEL) += gazel.o isac.o arcofi.o hscx.o 60hisax-$(CONFIG_HISAX_GAZEL) += gazel.o isac.o arcofi.o hscx.o
61hisax-$(CONFIG_HISAX_W6692) += w6692.o 61hisax-$(CONFIG_HISAX_W6692) += w6692.o
62hisax-$(CONFIG_HISAX_ENTERNOW_PCI) += enternow_pci.o amd7930_fn.o 62hisax-$(CONFIG_HISAX_ENTERNOW_PCI) += enternow_pci.o amd7930_fn.o
63#hisax-$(CONFIG_HISAX_TESTEMU) += testemu.o
64 63
diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
index 17ec0b70ba1..da4196f21e0 100644
--- a/drivers/isdn/hisax/config.c
+++ b/drivers/isdn/hisax/config.c
@@ -549,10 +549,6 @@ extern int setup_isurf(struct IsdnCard *card);
549extern int setup_saphir(struct IsdnCard *card); 549extern int setup_saphir(struct IsdnCard *card);
550#endif 550#endif
551 551
552#if CARD_TESTEMU
553extern int setup_testemu(struct IsdnCard *card);
554#endif
555
556#if CARD_BKM_A4T 552#if CARD_BKM_A4T
557extern int setup_bkm_a4t(struct IsdnCard *card); 553extern int setup_bkm_a4t(struct IsdnCard *card);
558#endif 554#endif
@@ -1061,11 +1057,6 @@ static int checkcard(int cardnr, char *id, int *busy_flag, struct module *lockow
1061 ret = setup_saphir(card); 1057 ret = setup_saphir(card);
1062 break; 1058 break;
1063#endif 1059#endif
1064#if CARD_TESTEMU
1065 case ISDN_CTYPE_TESTEMU:
1066 ret = setup_testemu(card);
1067 break;
1068#endif
1069#if CARD_BKM_A4T 1060#if CARD_BKM_A4T
1070 case ISDN_CTYPE_BKM_A4T: 1061 case ISDN_CTYPE_BKM_A4T:
1071 ret = setup_bkm_a4t(card); 1062 ret = setup_bkm_a4t(card);
@@ -1881,7 +1872,7 @@ static struct pci_device_id hisax_pci_tbl[] __devinitdata = {
1881 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_DJINN_ITOO, PCI_ANY_ID, PCI_ANY_ID}, 1872 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_DJINN_ITOO, PCI_ANY_ID, PCI_ANY_ID},
1882 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_OLITEC, PCI_ANY_ID, PCI_ANY_ID}, 1873 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_OLITEC, PCI_ANY_ID, PCI_ANY_ID},
1883#endif 1874#endif
1884#ifdef CONFIG_HISAX_QUADRO 1875#ifdef CONFIG_HISAX_SCT_QUADRO
1885 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_ANY_ID, PCI_ANY_ID}, 1876 {PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, PCI_ANY_ID, PCI_ANY_ID},
1886#endif 1877#endif
1887#ifdef CONFIG_HISAX_NICCY 1878#ifdef CONFIG_HISAX_NICCY
diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
index 0279fb323cb..ae377e81277 100644
--- a/drivers/isdn/hisax/elsa_ser.c
+++ b/drivers/isdn/hisax/elsa_ser.c
@@ -58,7 +58,7 @@ static inline unsigned int serial_in(struct IsdnCardState *cs, int offset)
58static inline unsigned int serial_inp(struct IsdnCardState *cs, int offset) 58static inline unsigned int serial_inp(struct IsdnCardState *cs, int offset)
59{ 59{
60#ifdef SERIAL_DEBUG_REG 60#ifdef SERIAL_DEBUG_REG
61#ifdef CONFIG_SERIAL_NOPAUSE_IO 61#ifdef ELSA_SERIAL_NOPAUSE_IO
62 u_int val = inb(cs->hw.elsa.base + 8 + offset); 62 u_int val = inb(cs->hw.elsa.base + 8 + offset);
63 debugl1(cs,"inp %s %02x",ModemIn[offset], val); 63 debugl1(cs,"inp %s %02x",ModemIn[offset], val);
64#else 64#else
@@ -67,7 +67,7 @@ static inline unsigned int serial_inp(struct IsdnCardState *cs, int offset)
67#endif 67#endif
68 return(val); 68 return(val);
69#else 69#else
70#ifdef CONFIG_SERIAL_NOPAUSE_IO 70#ifdef ELSA_SERIAL_NOPAUSE_IO
71 return inb(cs->hw.elsa.base + 8 + offset); 71 return inb(cs->hw.elsa.base + 8 + offset);
72#else 72#else
73 return inb_p(cs->hw.elsa.base + 8 + offset); 73 return inb_p(cs->hw.elsa.base + 8 + offset);
@@ -87,13 +87,13 @@ static inline void serial_outp(struct IsdnCardState *cs, int offset,
87 int value) 87 int value)
88{ 88{
89#ifdef SERIAL_DEBUG_REG 89#ifdef SERIAL_DEBUG_REG
90#ifdef CONFIG_SERIAL_NOPAUSE_IO 90#ifdef ELSA_SERIAL_NOPAUSE_IO
91 debugl1(cs,"outp %s %02x",ModemOut[offset], value); 91 debugl1(cs,"outp %s %02x",ModemOut[offset], value);
92#else 92#else
93 debugl1(cs,"outP %s %02x",ModemOut[offset], value); 93 debugl1(cs,"outP %s %02x",ModemOut[offset], value);
94#endif 94#endif
95#endif 95#endif
96#ifdef CONFIG_SERIAL_NOPAUSE_IO 96#ifdef ELSA_SERIAL_NOPAUSE_IO
97 outb(value, cs->hw.elsa.base + 8 + offset); 97 outb(value, cs->hw.elsa.base + 8 + offset);
98#else 98#else
99 outb_p(value, cs->hw.elsa.base + 8 + offset); 99 outb_p(value, cs->hw.elsa.base + 8 + offset);
diff --git a/drivers/isdn/hisax/hfc4s8s_l1.c b/drivers/isdn/hisax/hfc4s8s_l1.c
index a2fa4ecb8c8..ab98e135bcb 100644
--- a/drivers/isdn/hisax/hfc4s8s_l1.c
+++ b/drivers/isdn/hisax/hfc4s8s_l1.c
@@ -199,7 +199,7 @@ typedef struct _hfc4s8s_hw {
199/***************************/ 199/***************************/
200/* inline function defines */ 200/* inline function defines */
201/***************************/ 201/***************************/
202#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM /* inline functions mempry mapped */ 202#ifdef HISAX_HFC4S8S_PCIMEM /* inline functions memory mapped */
203 203
204/* memory write and dummy IO read to avoid PCI byte merge problems */ 204/* memory write and dummy IO read to avoid PCI byte merge problems */
205#define Write_hfc8(a,b,c) {(*((volatile u_char *)(a->membase+b)) = c); inb(a->iobase+4);} 205#define Write_hfc8(a,b,c) {(*((volatile u_char *)(a->membase+b)) = c); inb(a->iobase+4);}
@@ -305,7 +305,7 @@ wait_busy(hfc4s8s_hw * a)
305 305
306#define PCI_ENA_REGIO 0x01 306#define PCI_ENA_REGIO 0x01
307 307
308#endif /* CONFIG_HISAX_HFC4S8S_PCIMEM */ 308#endif /* HISAX_HFC4S8S_PCIMEM */
309 309
310/******************************************************/ 310/******************************************************/
311/* function to read critical counter registers that */ 311/* function to read critical counter registers that */
@@ -724,12 +724,12 @@ rx_d_frame(struct hfc4s8s_l1 *l1p, int ech)
724 } else { 724 } else {
725 /* read errornous D frame */ 725 /* read errornous D frame */
726 726
727#ifndef CONFIG_HISAX_HFC4S8S_PCIMEM 727#ifndef HISAX_HFC4S8S_PCIMEM
728 SetRegAddr(l1p->hw, A_FIFO_DATA0); 728 SetRegAddr(l1p->hw, A_FIFO_DATA0);
729#endif 729#endif
730 730
731 while (z1 >= 4) { 731 while (z1 >= 4) {
732#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 732#ifdef HISAX_HFC4S8S_PCIMEM
733 Read_hfc32(l1p->hw, A_FIFO_DATA0); 733 Read_hfc32(l1p->hw, A_FIFO_DATA0);
734#else 734#else
735 fRead_hfc32(l1p->hw); 735 fRead_hfc32(l1p->hw);
@@ -738,7 +738,7 @@ rx_d_frame(struct hfc4s8s_l1 *l1p, int ech)
738 } 738 }
739 739
740 while (z1--) 740 while (z1--)
741#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 741#ifdef HISAX_HFC4S8S_PCIMEM
742 Read_hfc8(l1p->hw, A_FIFO_DATA0); 742 Read_hfc8(l1p->hw, A_FIFO_DATA0);
743#else 743#else
744 fRead_hfc8(l1p->hw); 744 fRead_hfc8(l1p->hw);
@@ -752,12 +752,12 @@ rx_d_frame(struct hfc4s8s_l1 *l1p, int ech)
752 752
753 cp = skb->data; 753 cp = skb->data;
754 754
755#ifndef CONFIG_HISAX_HFC4S8S_PCIMEM 755#ifndef HISAX_HFC4S8S_PCIMEM
756 SetRegAddr(l1p->hw, A_FIFO_DATA0); 756 SetRegAddr(l1p->hw, A_FIFO_DATA0);
757#endif 757#endif
758 758
759 while (z1 >= 4) { 759 while (z1 >= 4) {
760#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 760#ifdef HISAX_HFC4S8S_PCIMEM
761 *((unsigned long *) cp) = 761 *((unsigned long *) cp) =
762 Read_hfc32(l1p->hw, A_FIFO_DATA0); 762 Read_hfc32(l1p->hw, A_FIFO_DATA0);
763#else 763#else
@@ -768,7 +768,7 @@ rx_d_frame(struct hfc4s8s_l1 *l1p, int ech)
768 } 768 }
769 769
770 while (z1--) 770 while (z1--)
771#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 771#ifdef HISAX_HFC4S8S_PCIMEM
772 *cp++ = Read_hfc8(l1p->hw, A_FIFO_DATA0); 772 *cp++ = Read_hfc8(l1p->hw, A_FIFO_DATA0);
773#else 773#else
774 *cp++ = fRead_hfc8(l1p->hw); 774 *cp++ = fRead_hfc8(l1p->hw);
@@ -858,12 +858,12 @@ rx_b_frame(struct hfc4s8s_btype *bch)
858 wait_busy(l1->hw); 858 wait_busy(l1->hw);
859 return; 859 return;
860 } 860 }
861#ifndef CONFIG_HISAX_HFC4S8S_PCIMEM 861#ifndef HISAX_HFC4S8S_PCIMEM
862 SetRegAddr(l1->hw, A_FIFO_DATA0); 862 SetRegAddr(l1->hw, A_FIFO_DATA0);
863#endif 863#endif
864 864
865 while (z1 >= 4) { 865 while (z1 >= 4) {
866#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 866#ifdef HISAX_HFC4S8S_PCIMEM
867 *((unsigned long *) bch->rx_ptr) = 867 *((unsigned long *) bch->rx_ptr) =
868 Read_hfc32(l1->hw, A_FIFO_DATA0); 868 Read_hfc32(l1->hw, A_FIFO_DATA0);
869#else 869#else
@@ -875,7 +875,7 @@ rx_b_frame(struct hfc4s8s_btype *bch)
875 } 875 }
876 876
877 while (z1--) 877 while (z1--)
878#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 878#ifdef HISAX_HFC4S8S_PCIMEM
879 *(bch->rx_ptr++) = Read_hfc8(l1->hw, A_FIFO_DATA0); 879 *(bch->rx_ptr++) = Read_hfc8(l1->hw, A_FIFO_DATA0);
880#else 880#else
881 *(bch->rx_ptr++) = fRead_hfc8(l1->hw); 881 *(bch->rx_ptr++) = fRead_hfc8(l1->hw);
@@ -939,12 +939,12 @@ tx_d_frame(struct hfc4s8s_l1 *l1p)
939 if ((skb = skb_dequeue(&l1p->d_tx_queue))) { 939 if ((skb = skb_dequeue(&l1p->d_tx_queue))) {
940 cp = skb->data; 940 cp = skb->data;
941 cnt = skb->len; 941 cnt = skb->len;
942#ifndef CONFIG_HISAX_HFC4S8S_PCIMEM 942#ifndef HISAX_HFC4S8S_PCIMEM
943 SetRegAddr(l1p->hw, A_FIFO_DATA0); 943 SetRegAddr(l1p->hw, A_FIFO_DATA0);
944#endif 944#endif
945 945
946 while (cnt >= 4) { 946 while (cnt >= 4) {
947#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 947#ifdef HISAX_HFC4S8S_PCIMEM
948 fWrite_hfc32(l1p->hw, A_FIFO_DATA0, 948 fWrite_hfc32(l1p->hw, A_FIFO_DATA0,
949 *(unsigned long *) cp); 949 *(unsigned long *) cp);
950#else 950#else
@@ -955,7 +955,7 @@ tx_d_frame(struct hfc4s8s_l1 *l1p)
955 cnt -= 4; 955 cnt -= 4;
956 } 956 }
957 957
958#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 958#ifdef HISAX_HFC4S8S_PCIMEM
959 while (cnt--) 959 while (cnt--)
960 fWrite_hfc8(l1p->hw, A_FIFO_DATA0, *cp++); 960 fWrite_hfc8(l1p->hw, A_FIFO_DATA0, *cp++);
961#else 961#else
@@ -1036,11 +1036,11 @@ tx_b_frame(struct hfc4s8s_btype *bch)
1036 cp = skb->data + bch->tx_cnt; 1036 cp = skb->data + bch->tx_cnt;
1037 bch->tx_cnt += cnt; 1037 bch->tx_cnt += cnt;
1038 1038
1039#ifndef CONFIG_HISAX_HFC4S8S_PCIMEM 1039#ifndef HISAX_HFC4S8S_PCIMEM
1040 SetRegAddr(l1->hw, A_FIFO_DATA0); 1040 SetRegAddr(l1->hw, A_FIFO_DATA0);
1041#endif 1041#endif
1042 while (cnt >= 4) { 1042 while (cnt >= 4) {
1043#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 1043#ifdef HISAX_HFC4S8S_PCIMEM
1044 fWrite_hfc32(l1->hw, A_FIFO_DATA0, 1044 fWrite_hfc32(l1->hw, A_FIFO_DATA0,
1045 *(unsigned long *) cp); 1045 *(unsigned long *) cp);
1046#else 1046#else
@@ -1051,7 +1051,7 @@ tx_b_frame(struct hfc4s8s_btype *bch)
1051 } 1051 }
1052 1052
1053 while (cnt--) 1053 while (cnt--)
1054#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 1054#ifdef HISAX_HFC4S8S_PCIMEM
1055 fWrite_hfc8(l1->hw, A_FIFO_DATA0, *cp++); 1055 fWrite_hfc8(l1->hw, A_FIFO_DATA0, *cp++);
1056#else 1056#else
1057 fWrite_hfc8(l1->hw, *cp++); 1057 fWrite_hfc8(l1->hw, *cp++);
@@ -1280,7 +1280,7 @@ hfc4s8s_interrupt(int intno, void *dev_id)
1280 if (!hw || !(hw->mr.r_irq_ctrl & M_GLOB_IRQ_EN)) 1280 if (!hw || !(hw->mr.r_irq_ctrl & M_GLOB_IRQ_EN))
1281 return IRQ_NONE; 1281 return IRQ_NONE;
1282 1282
1283#ifndef CONFIG_HISAX_HFC4S8S_PCIMEM 1283#ifndef HISAX_HFC4S8S_PCIMEM
1284 /* read current selected regsister */ 1284 /* read current selected regsister */
1285 old_ioreg = GetRegAddr(hw); 1285 old_ioreg = GetRegAddr(hw);
1286#endif 1286#endif
@@ -1291,7 +1291,7 @@ hfc4s8s_interrupt(int intno, void *dev_id)
1291 if (! 1291 if (!
1292 (b = (Read_hfc8(hw, R_STATUS) & (M_MISC_IRQSTA | M_FR_IRQSTA))) 1292 (b = (Read_hfc8(hw, R_STATUS) & (M_MISC_IRQSTA | M_FR_IRQSTA)))
1293&& !hw->mr.r_irq_statech) { 1293&& !hw->mr.r_irq_statech) {
1294#ifndef CONFIG_HISAX_HFC4S8S_PCIMEM 1294#ifndef HISAX_HFC4S8S_PCIMEM
1295 SetRegAddr(hw, old_ioreg); 1295 SetRegAddr(hw, old_ioreg);
1296#endif 1296#endif
1297 return IRQ_NONE; 1297 return IRQ_NONE;
@@ -1321,7 +1321,7 @@ hfc4s8s_interrupt(int intno, void *dev_id)
1321 /* queue the request to allow other cards to interrupt */ 1321 /* queue the request to allow other cards to interrupt */
1322 schedule_work(&hw->tqueue); 1322 schedule_work(&hw->tqueue);
1323 1323
1324#ifndef CONFIG_HISAX_HFC4S8S_PCIMEM 1324#ifndef HISAX_HFC4S8S_PCIMEM
1325 SetRegAddr(hw, old_ioreg); 1325 SetRegAddr(hw, old_ioreg);
1326#endif 1326#endif
1327 return IRQ_HANDLED; 1327 return IRQ_HANDLED;
@@ -1470,7 +1470,7 @@ static void
1470release_pci_ports(hfc4s8s_hw * hw) 1470release_pci_ports(hfc4s8s_hw * hw)
1471{ 1471{
1472 pci_write_config_word(hw->pdev, PCI_COMMAND, 0); 1472 pci_write_config_word(hw->pdev, PCI_COMMAND, 0);
1473#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 1473#ifdef HISAX_HFC4S8S_PCIMEM
1474 if (hw->membase) 1474 if (hw->membase)
1475 iounmap((void *) hw->membase); 1475 iounmap((void *) hw->membase);
1476#else 1476#else
@@ -1485,7 +1485,7 @@ release_pci_ports(hfc4s8s_hw * hw)
1485static void 1485static void
1486enable_pci_ports(hfc4s8s_hw * hw) 1486enable_pci_ports(hfc4s8s_hw * hw)
1487{ 1487{
1488#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 1488#ifdef HISAX_HFC4S8S_PCIMEM
1489 pci_write_config_word(hw->pdev, PCI_COMMAND, PCI_ENA_MEMIO); 1489 pci_write_config_word(hw->pdev, PCI_COMMAND, PCI_ENA_MEMIO);
1490#else 1490#else
1491 pci_write_config_word(hw->pdev, PCI_COMMAND, PCI_ENA_REGIO); 1491 pci_write_config_word(hw->pdev, PCI_COMMAND, PCI_ENA_REGIO);
@@ -1560,7 +1560,7 @@ setup_instance(hfc4s8s_hw * hw)
1560 hw->irq); 1560 hw->irq);
1561 goto out; 1561 goto out;
1562 } 1562 }
1563#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 1563#ifdef HISAX_HFC4S8S_PCIMEM
1564 printk(KERN_INFO 1564 printk(KERN_INFO
1565 "HFC-4S/8S: found PCI card at membase 0x%p, irq %d\n", 1565 "HFC-4S/8S: found PCI card at membase 0x%p, irq %d\n",
1566 hw->hw_membase, hw->irq); 1566 hw->hw_membase, hw->irq);
@@ -1613,7 +1613,7 @@ hfc4s8s_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1613 hw->irq = pdev->irq; 1613 hw->irq = pdev->irq;
1614 hw->iobase = pci_resource_start(pdev, 0); 1614 hw->iobase = pci_resource_start(pdev, 0);
1615 1615
1616#ifdef CONFIG_HISAX_HFC4S8S_PCIMEM 1616#ifdef HISAX_HFC4S8S_PCIMEM
1617 hw->hw_membase = (u_char *) pci_resource_start(pdev, 1); 1617 hw->hw_membase = (u_char *) pci_resource_start(pdev, 1);
1618 hw->membase = ioremap((ulong) hw->hw_membase, 256); 1618 hw->membase = ioremap((ulong) hw->hw_membase, 256);
1619#else 1619#else
diff --git a/drivers/isdn/hisax/hfc_usb.c b/drivers/isdn/hisax/hfc_usb.c
index 5a6989f23fc..42bbae2a646 100644
--- a/drivers/isdn/hisax/hfc_usb.c
+++ b/drivers/isdn/hisax/hfc_usb.c
@@ -183,7 +183,7 @@ typedef struct hfcusb_data {
183 int vend_idx; /* vendor found */ 183 int vend_idx; /* vendor found */
184 int b_mode[2]; /* B-channel mode */ 184 int b_mode[2]; /* B-channel mode */
185 int l1_activated; /* layer 1 activated */ 185 int l1_activated; /* layer 1 activated */
186 int disc_flag; /* TRUE if device was disonnected to avoid some USB actions */ 186 int disc_flag; /* 'true' if device was disonnected to avoid some USB actions */
187 int packet_size, iso_packet_size; 187 int packet_size, iso_packet_size;
188 188
189 /* control pipe background handling */ 189 /* control pipe background handling */
@@ -392,7 +392,7 @@ l1_timer_expire_t3(hfcusb_data * hfc)
392 DBG(ISDN_DBG, 392 DBG(ISDN_DBG,
393 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)"); 393 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
394#endif 394#endif
395 hfc->l1_activated = FALSE; 395 hfc->l1_activated = false;
396 handle_led(hfc, LED_S0_OFF); 396 handle_led(hfc, LED_S0_OFF);
397 /* deactivate : */ 397 /* deactivate : */
398 queue_control_request(hfc, HFCUSB_STATES, 0x10, 1); 398 queue_control_request(hfc, HFCUSB_STATES, 0x10, 1);
@@ -411,7 +411,7 @@ l1_timer_expire_t4(hfcusb_data * hfc)
411 DBG(ISDN_DBG, 411 DBG(ISDN_DBG,
412 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)"); 412 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
413#endif 413#endif
414 hfc->l1_activated = FALSE; 414 hfc->l1_activated = false;
415 handle_led(hfc, LED_S0_OFF); 415 handle_led(hfc, LED_S0_OFF);
416} 416}
417 417
@@ -452,7 +452,7 @@ state_handler(hfcusb_data * hfc, __u8 state)
452#ifdef CONFIG_HISAX_DEBUG 452#ifdef CONFIG_HISAX_DEBUG
453 DBG(ISDN_DBG, "HFC-S USB: PH_ACTIVATE | INDICATION sent"); 453 DBG(ISDN_DBG, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
454#endif 454#endif
455 hfc->l1_activated = TRUE; 455 hfc->l1_activated = true;
456 handle_led(hfc, LED_S0_ON); 456 handle_led(hfc, LED_S0_ON);
457 } else if (state <= 3 /* && activated */ ) { 457 } else if (state <= 3 /* && activated */ ) {
458 if (old_state == 7 || old_state == 8) { 458 if (old_state == 7 || old_state == 8) {
@@ -472,7 +472,7 @@ state_handler(hfcusb_data * hfc, __u8 state)
472 DBG(ISDN_DBG, 472 DBG(ISDN_DBG,
473 "HFC-S USB: PH_DEACTIVATE | INDICATION sent"); 473 "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
474#endif 474#endif
475 hfc->l1_activated = FALSE; 475 hfc->l1_activated = false;
476 handle_led(hfc, LED_S0_OFF); 476 handle_led(hfc, LED_S0_OFF);
477 } 477 }
478 } 478 }
@@ -622,7 +622,7 @@ tx_iso_complete(struct urb *urb)
622 if (fifo->active && !status) { 622 if (fifo->active && !status) {
623 transp_mode = 0; 623 transp_mode = 0;
624 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS) 624 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
625 transp_mode = TRUE; 625 transp_mode = true;
626 626
627 /* is FifoFull-threshold set for our channel? */ 627 /* is FifoFull-threshold set for our channel? */
628 threshbit = threshtable[fifon] & hfc->threshold_mask; 628 threshbit = threshtable[fifon] & hfc->threshold_mask;
@@ -640,7 +640,7 @@ tx_iso_complete(struct urb *urb)
640 tx_iso_complete, urb->context); 640 tx_iso_complete, urb->context);
641 memset(context_iso_urb->buffer, 0, 641 memset(context_iso_urb->buffer, 0,
642 sizeof(context_iso_urb->buffer)); 642 sizeof(context_iso_urb->buffer));
643 frame_complete = FALSE; 643 frame_complete = false;
644 /* Generate next Iso Packets */ 644 /* Generate next Iso Packets */
645 for (k = 0; k < num_isoc_packets; ++k) { 645 for (k = 0; k < num_isoc_packets; ++k) {
646 if (fifo->skbuff) { 646 if (fifo->skbuff) {
@@ -666,7 +666,7 @@ tx_iso_complete(struct urb *urb)
666 /* add 2 byte flags and 16bit CRC at end of ISDN frame */ 666 /* add 2 byte flags and 16bit CRC at end of ISDN frame */
667 fifo->bit_line += 32; 667 fifo->bit_line += 32;
668 } 668 }
669 frame_complete = TRUE; 669 frame_complete = true;
670 } 670 }
671 671
672 memcpy(context_iso_urb->buffer + 672 memcpy(context_iso_urb->buffer +
@@ -693,7 +693,7 @@ tx_iso_complete(struct urb *urb)
693 } 693 }
694 694
695 if (frame_complete) { 695 if (frame_complete) {
696 fifo->delete_flg = TRUE; 696 fifo->delete_flg = true;
697 fifo->hif->l1l2(fifo->hif, 697 fifo->hif->l1l2(fifo->hif,
698 PH_DATA | CONFIRM, 698 PH_DATA | CONFIRM,
699 (void *) (unsigned long) fifo->skbuff-> 699 (void *) (unsigned long) fifo->skbuff->
@@ -701,9 +701,9 @@ tx_iso_complete(struct urb *urb)
701 if (fifo->skbuff && fifo->delete_flg) { 701 if (fifo->skbuff && fifo->delete_flg) {
702 dev_kfree_skb_any(fifo->skbuff); 702 dev_kfree_skb_any(fifo->skbuff);
703 fifo->skbuff = NULL; 703 fifo->skbuff = NULL;
704 fifo->delete_flg = FALSE; 704 fifo->delete_flg = false;
705 } 705 }
706 frame_complete = FALSE; 706 frame_complete = false;
707 } 707 }
708 } 708 }
709 errcode = usb_submit_urb(urb, GFP_ATOMIC); 709 errcode = usb_submit_urb(urb, GFP_ATOMIC);
@@ -837,7 +837,7 @@ collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, int finish)
837 fifon = fifo->fifonum; 837 fifon = fifo->fifonum;
838 transp_mode = 0; 838 transp_mode = 0;
839 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS) 839 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
840 transp_mode = TRUE; 840 transp_mode = true;
841 841
842 if (!fifo->skbuff) { 842 if (!fifo->skbuff) {
843 fifo->skbuff = dev_alloc_skb(fifo->max_size + 3); 843 fifo->skbuff = dev_alloc_skb(fifo->max_size + 3);
@@ -1176,7 +1176,7 @@ hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
1176 if (fifo->skbuff && fifo->delete_flg) { 1176 if (fifo->skbuff && fifo->delete_flg) {
1177 dev_kfree_skb_any(fifo->skbuff); 1177 dev_kfree_skb_any(fifo->skbuff);
1178 fifo->skbuff = NULL; 1178 fifo->skbuff = NULL;
1179 fifo->delete_flg = FALSE; 1179 fifo->delete_flg = false;
1180 } 1180 }
1181 fifo->skbuff = arg; /* we have a new buffer */ 1181 fifo->skbuff = arg; /* we have a new buffer */
1182 break; 1182 break;
@@ -1262,8 +1262,8 @@ usb_init(hfcusb_data * hfc)
1262 hfc->b_mode[0] = L1_MODE_NULL; 1262 hfc->b_mode[0] = L1_MODE_NULL;
1263 hfc->b_mode[1] = L1_MODE_NULL; 1263 hfc->b_mode[1] = L1_MODE_NULL;
1264 1264
1265 hfc->l1_activated = FALSE; 1265 hfc->l1_activated = false;
1266 hfc->disc_flag = FALSE; 1266 hfc->disc_flag = false;
1267 hfc->led_state = 0; 1267 hfc->led_state = 0;
1268 hfc->led_new_data = 0; 1268 hfc->led_new_data = 0;
1269 hfc->old_led_state = 0; 1269 hfc->old_led_state = 0;
@@ -1404,7 +1404,7 @@ hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1404 1404
1405 /* check for config EOL element */ 1405 /* check for config EOL element */
1406 while (validconf[cfg_used][0]) { 1406 while (validconf[cfg_used][0]) {
1407 cfg_found = TRUE; 1407 cfg_found = true;
1408 vcf = validconf[cfg_used]; 1408 vcf = validconf[cfg_used];
1409 /* first endpoint descriptor */ 1409 /* first endpoint descriptor */
1410 ep = iface->endpoint; 1410 ep = iface->endpoint;
@@ -1426,7 +1426,7 @@ hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1426 idx++; 1426 idx++;
1427 attr = ep->desc.bmAttributes; 1427 attr = ep->desc.bmAttributes;
1428 if (cmptbl[idx] == EP_NUL) { 1428 if (cmptbl[idx] == EP_NUL) {
1429 cfg_found = FALSE; 1429 cfg_found = false;
1430 } 1430 }
1431 if (attr == USB_ENDPOINT_XFER_INT 1431 if (attr == USB_ENDPOINT_XFER_INT
1432 && cmptbl[idx] == EP_INT) 1432 && cmptbl[idx] == EP_INT)
@@ -1448,7 +1448,7 @@ hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1448 "HFC-S USB: Interrupt Endpoint interval < %d found - skipping config", 1448 "HFC-S USB: Interrupt Endpoint interval < %d found - skipping config",
1449 vcf[17]); 1449 vcf[17]);
1450#endif 1450#endif
1451 cfg_found = FALSE; 1451 cfg_found = false;
1452 } 1452 }
1453 ep++; 1453 ep++;
1454 } 1454 }
@@ -1456,7 +1456,7 @@ hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1456 /* all entries must be EP_NOP or EP_NUL for a valid config */ 1456 /* all entries must be EP_NOP or EP_NUL for a valid config */
1457 if (cmptbl[i] != EP_NOP 1457 if (cmptbl[i] != EP_NOP
1458 && cmptbl[i] != EP_NUL) 1458 && cmptbl[i] != EP_NUL)
1459 cfg_found = FALSE; 1459 cfg_found = false;
1460 } 1460 }
1461 if (cfg_found) { 1461 if (cfg_found) {
1462 if (cfg_used < small_match) { 1462 if (cfg_used < small_match) {
@@ -1656,7 +1656,7 @@ hfc_usb_disconnect(struct usb_interface
1656 hfcusb_data *context = usb_get_intfdata(intf); 1656 hfcusb_data *context = usb_get_intfdata(intf);
1657 int i; 1657 int i;
1658 printk(KERN_INFO "HFC-S USB: device disconnect\n"); 1658 printk(KERN_INFO "HFC-S USB: device disconnect\n");
1659 context->disc_flag = TRUE; 1659 context->disc_flag = true;
1660 usb_set_intfdata(intf, NULL); 1660 usb_set_intfdata(intf, NULL);
1661 if (!context) 1661 if (!context)
1662 return; 1662 return;
diff --git a/drivers/isdn/hisax/hfc_usb.h b/drivers/isdn/hisax/hfc_usb.h
index 6349367ed48..471f2354dfd 100644
--- a/drivers/isdn/hisax/hfc_usb.h
+++ b/drivers/isdn/hisax/hfc_usb.h
@@ -12,9 +12,6 @@
12 12
13#define VERBOSE_USB_DEBUG 13#define VERBOSE_USB_DEBUG
14 14
15#define TRUE 1
16#define FALSE 0
17
18 15
19/***********/ 16/***********/
20/* defines */ 17/* defines */
diff --git a/drivers/isdn/hisax/hisax.h b/drivers/isdn/hisax/hisax.h
index 3f1137e3467..3cd8d5ba239 100644
--- a/drivers/isdn/hisax/hisax.h
+++ b/drivers/isdn/hisax/hisax.h
@@ -795,19 +795,6 @@ struct w6692_hw {
795 struct timer_list timer; 795 struct timer_list timer;
796}; 796};
797 797
798#ifdef CONFIG_HISAX_TESTEMU
799struct te_hw {
800 unsigned char *sfifo;
801 unsigned char *sfifo_w;
802 unsigned char *sfifo_r;
803 unsigned char *sfifo_e;
804 int sfifo_cnt;
805 unsigned int stat;
806 wait_queue_head_t rwaitq;
807 wait_queue_head_t swaitq;
808};
809#endif
810
811struct arcofi_msg { 798struct arcofi_msg {
812 struct arcofi_msg *next; 799 struct arcofi_msg *next;
813 u_char receive; 800 u_char receive;
@@ -916,9 +903,6 @@ struct IsdnCardState {
916 struct ix1_hw niccy; 903 struct ix1_hw niccy;
917 struct isurf_hw isurf; 904 struct isurf_hw isurf;
918 struct saphir_hw saphir; 905 struct saphir_hw saphir;
919#ifdef CONFIG_HISAX_TESTEMU
920 struct te_hw te;
921#endif
922 struct bkm_hw ax; 906 struct bkm_hw ax;
923 struct gazel_hw gazel; 907 struct gazel_hw gazel;
924 struct w6692_hw w6692; 908 struct w6692_hw w6692;
@@ -1175,15 +1159,6 @@ struct IsdnCardState {
1175#define CARD_HSTSAPHIR 0 1159#define CARD_HSTSAPHIR 0
1176#endif 1160#endif
1177 1161
1178#ifdef CONFIG_HISAX_TESTEMU
1179#define CARD_TESTEMU 1
1180#define ISDN_CTYPE_TESTEMU 99
1181#undef ISDN_CTYPE_COUNT
1182#define ISDN_CTYPE_COUNT ISDN_CTYPE_TESTEMU
1183#else
1184#define CARD_TESTEMU 0
1185#endif
1186
1187#ifdef CONFIG_HISAX_BKM_A4T 1162#ifdef CONFIG_HISAX_BKM_A4T
1188#define CARD_BKM_A4T 1 1163#define CARD_BKM_A4T 1
1189#ifndef ISDN_CHIP_ISAC 1164#ifndef ISDN_CHIP_ISAC
diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
index 6f1a6583b17..9df9e3548cf 100644
--- a/drivers/isdn/hisax/isar.c
+++ b/drivers/isdn/hisax/isar.c
@@ -431,7 +431,6 @@ reterror:
431 return(ret); 431 return(ret);
432} 432}
433 433
434extern void BChannel_bh(struct BCState *);
435#define B_LL_NOCARRIER 8 434#define B_LL_NOCARRIER 8
436#define B_LL_CONNECT 9 435#define B_LL_CONNECT 9
437#define B_LL_OK 10 436#define B_LL_OK 10
diff --git a/drivers/isdn/hisax/isdnl1.h b/drivers/isdn/hisax/isdnl1.h
index 0e88cfabdf1..172ad4c8c96 100644
--- a/drivers/isdn/hisax/isdnl1.h
+++ b/drivers/isdn/hisax/isdnl1.h
@@ -21,12 +21,11 @@
21#define B_XMTBUFREADY 1 21#define B_XMTBUFREADY 1
22#define B_ACKPENDING 2 22#define B_ACKPENDING 2
23 23
24extern void debugl1(struct IsdnCardState *cs, char *fmt, ...); 24void debugl1(struct IsdnCardState *cs, char *fmt, ...);
25extern void DChannel_proc_xmt(struct IsdnCardState *cs); 25void DChannel_proc_xmt(struct IsdnCardState *cs);
26extern void DChannel_proc_rcv(struct IsdnCardState *cs); 26void DChannel_proc_rcv(struct IsdnCardState *cs);
27extern void l1_msg(struct IsdnCardState *cs, int pr, void *arg); 27void l1_msg(struct IsdnCardState *cs, int pr, void *arg);
28extern void l1_msg_b(struct PStack *st, int pr, void *arg); 28void l1_msg_b(struct PStack *st, int pr, void *arg);
29 29void Logl2Frame(struct IsdnCardState *cs, struct sk_buff *skb, char *buf,
30#ifdef L2FRAME_DEBUG 30 int dir);
31extern void Logl2Frame(struct IsdnCardState *cs, struct sk_buff *skb, char *buf, int dir); 31void BChannel_bh(struct work_struct *work);
32#endif
diff --git a/drivers/isdn/hisax/isdnl3.c b/drivers/isdn/hisax/isdnl3.c
index 281fa27d9f0..935f23356fa 100644
--- a/drivers/isdn/hisax/isdnl3.c
+++ b/drivers/isdn/hisax/isdnl3.c
@@ -231,18 +231,6 @@ no_l3_proto_spec(struct PStack *st, isdn_ctrl *ic)
231 return(-1); 231 return(-1);
232} 232}
233 233
234#ifdef CONFIG_HISAX_EURO
235extern void setstack_dss1(struct PStack *st);
236#endif
237
238#ifdef CONFIG_HISAX_NI1
239extern void setstack_ni1(struct PStack *st);
240#endif
241
242#ifdef CONFIG_HISAX_1TR6
243extern void setstack_1tr6(struct PStack *st);
244#endif
245
246struct l3_process 234struct l3_process
247*getl3proc(struct PStack *st, int cr) 235*getl3proc(struct PStack *st, int cr)
248{ 236{
diff --git a/drivers/isdn/hisax/isdnl3.h b/drivers/isdn/hisax/isdnl3.h
index 1dbe0297a50..749498fe6c4 100644
--- a/drivers/isdn/hisax/isdnl3.h
+++ b/drivers/isdn/hisax/isdnl3.h
@@ -25,13 +25,19 @@ struct stateentry {
25 25
26#define l3_debug(st, fmt, args...) HiSax_putstatus(st->l1.hardware, "l3 ", fmt, ## args) 26#define l3_debug(st, fmt, args...) HiSax_putstatus(st->l1.hardware, "l3 ", fmt, ## args)
27 27
28extern void newl3state(struct l3_process *pc, int state); 28struct PStack;
29extern void L3InitTimer(struct l3_process *pc, struct L3Timer *t); 29
30extern void L3DelTimer(struct L3Timer *t); 30void newl3state(struct l3_process *pc, int state);
31extern int L3AddTimer(struct L3Timer *t, int millisec, int event); 31void L3InitTimer(struct l3_process *pc, struct L3Timer *t);
32extern void StopAllL3Timer(struct l3_process *pc); 32void L3DelTimer(struct L3Timer *t);
33extern struct sk_buff *l3_alloc_skb(int len); 33int L3AddTimer(struct L3Timer *t, int millisec, int event);
34extern struct l3_process *new_l3_process(struct PStack *st, int cr); 34void StopAllL3Timer(struct l3_process *pc);
35extern void release_l3_process(struct l3_process *p); 35struct sk_buff *l3_alloc_skb(int len);
36extern struct l3_process *getl3proc(struct PStack *st, int cr); 36struct l3_process *new_l3_process(struct PStack *st, int cr);
37extern void l3_msg(struct PStack *st, int pr, void *arg); 37void release_l3_process(struct l3_process *p);
38struct l3_process *getl3proc(struct PStack *st, int cr);
39void l3_msg(struct PStack *st, int pr, void *arg);
40void setstack_dss1(struct PStack *st);
41void setstack_ni1(struct PStack *st);
42void setstack_1tr6(struct PStack *st);
43
diff --git a/drivers/isdn/hysdn/hysdn_procconf.c b/drivers/isdn/hysdn/hysdn_procconf.c
index 94a93508911..dc477e0aab0 100644
--- a/drivers/isdn/hysdn/hysdn_procconf.c
+++ b/drivers/isdn/hysdn/hysdn_procconf.c
@@ -367,7 +367,7 @@ hysdn_conf_close(struct inode *ino, struct file *filep)
367/******************************************************/ 367/******************************************************/
368/* table for conf filesystem functions defined above. */ 368/* table for conf filesystem functions defined above. */
369/******************************************************/ 369/******************************************************/
370static struct file_operations conf_fops = 370static const struct file_operations conf_fops =
371{ 371{
372 .llseek = no_llseek, 372 .llseek = no_llseek,
373 .read = hysdn_conf_read, 373 .read = hysdn_conf_read,
diff --git a/drivers/isdn/hysdn/hysdn_proclog.c b/drivers/isdn/hysdn/hysdn_proclog.c
index 375d956884d..f7e83a86f44 100644
--- a/drivers/isdn/hysdn/hysdn_proclog.c
+++ b/drivers/isdn/hysdn/hysdn_proclog.c
@@ -383,7 +383,7 @@ hysdn_log_poll(struct file *file, poll_table * wait)
383/**************************************************/ 383/**************************************************/
384/* table for log filesystem functions defined above. */ 384/* table for log filesystem functions defined above. */
385/**************************************************/ 385/**************************************************/
386static struct file_operations log_fops = 386static const struct file_operations log_fops =
387{ 387{
388 .llseek = no_llseek, 388 .llseek = no_llseek,
389 .read = hysdn_log_read, 389 .read = hysdn_log_read,
diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
index 6a2ef0a87ed..9c926e41b11 100644
--- a/drivers/isdn/i4l/isdn_common.c
+++ b/drivers/isdn/i4l/isdn_common.c
@@ -1822,7 +1822,7 @@ isdn_close(struct inode *ino, struct file *filep)
1822 return 0; 1822 return 0;
1823} 1823}
1824 1824
1825static struct file_operations isdn_fops = 1825static const struct file_operations isdn_fops =
1826{ 1826{
1827 .owner = THIS_MODULE, 1827 .owner = THIS_MODULE,
1828 .llseek = no_llseek, 1828 .llseek = no_llseek,
diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
index fc80afe555b..ea5f30d4a5a 100644
--- a/drivers/isdn/i4l/isdn_tty.c
+++ b/drivers/isdn/i4l/isdn_tty.c
@@ -1261,7 +1261,6 @@ isdn_tty_flush_buffer(struct tty_struct *tty)
1261 } 1261 }
1262 isdn_tty_cleanup_xmit(info); 1262 isdn_tty_cleanup_xmit(info);
1263 info->xmit_count = 0; 1263 info->xmit_count = 0;
1264 wake_up_interruptible(&tty->write_wait);
1265 tty_wakeup(tty); 1264 tty_wakeup(tty);
1266} 1265}
1267 1266
diff --git a/drivers/isdn/pcbit/drv.c b/drivers/isdn/pcbit/drv.c
index 11c1b0b6e39..386c5ce6484 100644
--- a/drivers/isdn/pcbit/drv.c
+++ b/drivers/isdn/pcbit/drv.c
@@ -774,10 +774,6 @@ static void pcbit_logstat(struct pcbit_dev *dev, char *str)
774 dev->dev_if->statcallb(&ictl); 774 dev->dev_if->statcallb(&ictl);
775} 775}
776 776
777extern char * isdn_state_table[];
778extern char * strisdnevent(unsigned short);
779
780
781void pcbit_state_change(struct pcbit_dev * dev, struct pcbit_chan * chan, 777void pcbit_state_change(struct pcbit_dev * dev, struct pcbit_chan * chan,
782 unsigned short i, unsigned short ev, unsigned short f) 778 unsigned short i, unsigned short ev, unsigned short f)
783{ 779{
diff --git a/drivers/isdn/pcbit/edss1.c b/drivers/isdn/pcbit/edss1.c
index 93ca7de5670..1ad8b07efd8 100644
--- a/drivers/isdn/pcbit/edss1.c
+++ b/drivers/isdn/pcbit/edss1.c
@@ -35,12 +35,6 @@
35#include "callbacks.h" 35#include "callbacks.h"
36 36
37 37
38extern void pcbit_state_change(struct pcbit_dev *, struct pcbit_chan *,
39 unsigned short i, unsigned short ev,
40 unsigned short f);
41
42extern struct pcbit_dev * dev_pcbit[MAX_PCBIT_CARDS];
43
44char * isdn_state_table[] = { 38char * isdn_state_table[] = {
45 "Closed", 39 "Closed",
46 "Call initiated", 40 "Call initiated",
diff --git a/drivers/isdn/pcbit/edss1.h b/drivers/isdn/pcbit/edss1.h
index 6bb587005b8..0b64f97015d 100644
--- a/drivers/isdn/pcbit/edss1.h
+++ b/drivers/isdn/pcbit/edss1.h
@@ -90,9 +90,12 @@ struct fsm_timer_entry {
90 unsigned long timeout; /* in seconds */ 90 unsigned long timeout; /* in seconds */
91}; 91};
92 92
93extern char * isdn_state_table[];
94
95void pcbit_fsm_event(struct pcbit_dev *, struct pcbit_chan *,
96 unsigned short event, struct callb_data *);
97char * strisdnevent(ushort ev);
93 98
94extern void pcbit_fsm_event(struct pcbit_dev *, struct pcbit_chan *,
95 unsigned short event, struct callb_data *);
96#endif 99#endif
97 100
98 101
diff --git a/drivers/isdn/pcbit/layer2.c b/drivers/isdn/pcbit/layer2.c
index eafcce5e656..58eee50c8e2 100644
--- a/drivers/isdn/pcbit/layer2.c
+++ b/drivers/isdn/pcbit/layer2.c
@@ -47,22 +47,6 @@
47#undef DEBUG_FRAG 47#undef DEBUG_FRAG
48 48
49 49
50
51/*
52 * task queue struct
53 */
54
55
56
57/*
58 * Layer 3 packet demultiplexer
59 * drv.c
60 */
61
62extern void pcbit_l3_receive(struct pcbit_dev *dev, ulong msg,
63 struct sk_buff *skb,
64 ushort hdr_len, ushort refnum);
65
66/* 50/*
67 * Prototypes 51 * Prototypes
68 */ 52 */
diff --git a/drivers/isdn/pcbit/module.c b/drivers/isdn/pcbit/module.c
index 282073a35d6..7b7b1777f09 100644
--- a/drivers/isdn/pcbit/module.c
+++ b/drivers/isdn/pcbit/module.c
@@ -32,9 +32,6 @@ module_param_array(irq, int, NULL, 0);
32static int num_boards; 32static int num_boards;
33struct pcbit_dev * dev_pcbit[MAX_PCBIT_CARDS]; 33struct pcbit_dev * dev_pcbit[MAX_PCBIT_CARDS];
34 34
35extern void pcbit_terminate(int board);
36extern int pcbit_init_dev(int board, int mem_base, int irq);
37
38static int __init pcbit_init(void) 35static int __init pcbit_init(void)
39{ 36{
40 int board; 37 int board;
diff --git a/drivers/isdn/pcbit/pcbit.h b/drivers/isdn/pcbit/pcbit.h
index 19c18e88ff1..d76fffc88b8 100644
--- a/drivers/isdn/pcbit/pcbit.h
+++ b/drivers/isdn/pcbit/pcbit.h
@@ -166,6 +166,12 @@ struct pcbit_ioctl {
166#define L2_RUNNING 5 166#define L2_RUNNING 5
167#define L2_ERROR 6 167#define L2_ERROR 6
168 168
169extern void pcbit_deliver(struct work_struct *work); 169void pcbit_deliver(struct work_struct *work);
170int pcbit_init_dev(int board, int mem_base, int irq);
171void pcbit_terminate(int board);
172void pcbit_l3_receive(struct pcbit_dev * dev, ulong msg, struct sk_buff * skb,
173 ushort hdr_len, ushort refnum);
174void pcbit_state_change(struct pcbit_dev * dev, struct pcbit_chan * chan,
175 unsigned short i, unsigned short ev, unsigned short f);
170 176
171#endif 177#endif
diff --git a/drivers/isdn/sc/card.h b/drivers/isdn/sc/card.h
index 8e44928cdf1..4fbfa825c3a 100644
--- a/drivers/isdn/sc/card.h
+++ b/drivers/isdn/sc/card.h
@@ -26,7 +26,9 @@
26#include <linux/timer.h> 26#include <linux/timer.h>
27#include <linux/time.h> 27#include <linux/time.h>
28#include <linux/isdnif.h> 28#include <linux/isdnif.h>
29#include <linux/irqreturn.h>
29#include "message.h" 30#include "message.h"
31#include "scioc.h"
30 32
31/* 33/*
32 * Amount of time to wait for a reset to complete 34 * Amount of time to wait for a reset to complete
@@ -98,4 +100,32 @@ typedef struct {
98 spinlock_t lock; /* local lock */ 100 spinlock_t lock; /* local lock */
99} board; 101} board;
100 102
103
104extern board *sc_adapter[];
105extern int cinst;
106
107void memcpy_toshmem(int card, void *dest, const void *src, size_t n);
108void memcpy_fromshmem(int card, void *dest, const void *src, size_t n);
109int get_card_from_id(int driver);
110int indicate_status(int card, int event, ulong Channel, char *Data);
111irqreturn_t interrupt_handler(int interrupt, void *cardptr);
112int sndpkt(int devId, int channel, struct sk_buff *data);
113void rcvpkt(int card, RspMessage *rcvmsg);
114int command(isdn_ctrl *cmd);
115int reset(int card);
116int startproc(int card);
117int send_and_receive(int card, unsigned int procid, unsigned char type,
118 unsigned char class, unsigned char code,
119 unsigned char link, unsigned char data_len,
120 unsigned char *data, RspMessage *mesgdata, int timeout);
121void flushreadfifo (int card);
122int sendmessage(int card, unsigned int procid, unsigned int type,
123 unsigned int class, unsigned int code, unsigned int link,
124 unsigned int data_len, unsigned int *data);
125int receivemessage(int card, RspMessage *rspmsg);
126int sc_ioctl(int card, scs_ioctl *data);
127int setup_buffers(int card, int c);
128void check_reset(unsigned long data);
129void check_phystat(unsigned long data);
130
101#endif /* CARD_H */ 131#endif /* CARD_H */
diff --git a/drivers/isdn/sc/command.c b/drivers/isdn/sc/command.c
index 04b8a58f03b..b7bb7cbcf50 100644
--- a/drivers/isdn/sc/command.c
+++ b/drivers/isdn/sc/command.c
@@ -31,19 +31,6 @@ static int setl2(int card, unsigned long arg);
31static int setl3(int card, unsigned long arg); 31static int setl3(int card, unsigned long arg);
32static int acceptb(int card, unsigned long channel); 32static int acceptb(int card, unsigned long channel);
33 33
34extern int cinst;
35extern board *sc_adapter[];
36
37extern int sc_ioctl(int, scs_ioctl *);
38extern int setup_buffers(int, int, unsigned int);
39extern int indicate_status(int, int,ulong,char*);
40extern void check_reset(unsigned long);
41extern int send_and_receive(int, unsigned int, unsigned char, unsigned char,
42 unsigned char, unsigned char, unsigned char, unsigned char *,
43 RspMessage *, int);
44extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
45 unsigned int, unsigned int, unsigned int, unsigned int *);
46
47#ifdef DEBUG 34#ifdef DEBUG
48/* 35/*
49 * Translate command codes to strings 36 * Translate command codes to strings
@@ -208,7 +195,7 @@ static int answer(int card, unsigned long channel)
208 return -ENODEV; 195 return -ENODEV;
209 } 196 }
210 197
211 if(setup_buffers(card, channel+1, BUFFER_SIZE)) { 198 if(setup_buffers(card, channel+1)) {
212 hangup(card, channel+1); 199 hangup(card, channel+1);
213 return -ENOBUFS; 200 return -ENOBUFS;
214 } 201 }
@@ -297,7 +284,7 @@ static int acceptb(int card, unsigned long channel)
297 return -ENODEV; 284 return -ENODEV;
298 } 285 }
299 286
300 if(setup_buffers(card, channel+1, BUFFER_SIZE)) 287 if(setup_buffers(card, channel+1))
301 { 288 {
302 hangup(card, channel+1); 289 hangup(card, channel+1);
303 return -ENOBUFS; 290 return -ENOBUFS;
diff --git a/drivers/isdn/sc/event.c b/drivers/isdn/sc/event.c
index 57367325ef0..498f4039ece 100644
--- a/drivers/isdn/sc/event.c
+++ b/drivers/isdn/sc/event.c
@@ -20,9 +20,6 @@
20#include "message.h" 20#include "message.h"
21#include "card.h" 21#include "card.h"
22 22
23extern int cinst;
24extern board *sc_adapter[];
25
26#ifdef DEBUG 23#ifdef DEBUG
27static char *events[] = { "ISDN_STAT_STAVAIL", 24static char *events[] = { "ISDN_STAT_STAVAIL",
28 "ISDN_STAT_ICALL", 25 "ISDN_STAT_ICALL",
diff --git a/drivers/isdn/sc/init.c b/drivers/isdn/sc/init.c
index 150759a5cdd..0bf76344a0d 100644
--- a/drivers/isdn/sc/init.c
+++ b/drivers/isdn/sc/init.c
@@ -35,12 +35,6 @@ module_param_array(irq, int, NULL, 0);
35module_param_array(ram, int, NULL, 0); 35module_param_array(ram, int, NULL, 0);
36module_param(do_reset, bool, 0); 36module_param(do_reset, bool, 0);
37 37
38extern irqreturn_t interrupt_handler(int, void *);
39extern int sndpkt(int, int, int, struct sk_buff *);
40extern int command(isdn_ctrl *);
41extern int indicate_status(int, int, ulong, char*);
42extern int reset(int);
43
44static int identify_board(unsigned long, unsigned int); 38static int identify_board(unsigned long, unsigned int);
45 39
46static int __init sc_init(void) 40static int __init sc_init(void)
diff --git a/drivers/isdn/sc/interrupt.c b/drivers/isdn/sc/interrupt.c
index cd17de18cb7..bef7963cdd0 100644
--- a/drivers/isdn/sc/interrupt.c
+++ b/drivers/isdn/sc/interrupt.c
@@ -21,16 +21,6 @@
21#include "card.h" 21#include "card.h"
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23 23
24extern int indicate_status(int, int, ulong, char *);
25extern void check_phystat(unsigned long);
26extern int receivemessage(int, RspMessage *);
27extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
28 unsigned int, unsigned int, unsigned int, unsigned int *);
29extern void rcvpkt(int, RspMessage *);
30
31extern int cinst;
32extern board *sc_adapter[];
33
34static int get_card_from_irq(int irq) 24static int get_card_from_irq(int irq)
35{ 25{
36 int i; 26 int i;
diff --git a/drivers/isdn/sc/ioctl.c b/drivers/isdn/sc/ioctl.c
index 57c4ab96d13..7817d224492 100644
--- a/drivers/isdn/sc/ioctl.c
+++ b/drivers/isdn/sc/ioctl.c
@@ -12,16 +12,6 @@
12#include "card.h" 12#include "card.h"
13#include "scioc.h" 13#include "scioc.h"
14 14
15extern int indicate_status(int, int, unsigned long, char *);
16extern int startproc(int);
17extern int reset(int);
18extern int send_and_receive(int, unsigned int, unsigned char,unsigned char,
19 unsigned char,unsigned char,
20 unsigned char, unsigned char *, RspMessage *, int);
21
22extern board *sc_adapter[];
23
24
25static int GetStatus(int card, boardInfo *); 15static int GetStatus(int card, boardInfo *);
26 16
27/* 17/*
diff --git a/drivers/isdn/sc/message.c b/drivers/isdn/sc/message.c
index 0a0fe6b8039..c5a307e3c49 100644
--- a/drivers/isdn/sc/message.c
+++ b/drivers/isdn/sc/message.c
@@ -22,16 +22,6 @@
22#include "message.h" 22#include "message.h"
23#include "card.h" 23#include "card.h"
24 24
25extern board *sc_adapter[];
26extern unsigned int cinst;
27
28/*
29 * Obligatory function prototypes
30 */
31extern int indicate_status(int,ulong,char*);
32extern int scm_command(isdn_ctrl *);
33
34
35/* 25/*
36 * receive a message from the board 26 * receive a message from the board
37 */ 27 */
diff --git a/drivers/isdn/sc/packet.c b/drivers/isdn/sc/packet.c
index 1e04676b016..92016a2608e 100644
--- a/drivers/isdn/sc/packet.c
+++ b/drivers/isdn/sc/packet.c
@@ -20,16 +20,6 @@
20#include "message.h" 20#include "message.h"
21#include "card.h" 21#include "card.h"
22 22
23extern board *sc_adapter[];
24extern unsigned int cinst;
25
26extern int get_card_from_id(int);
27extern int indicate_status(int, int,ulong, char*);
28extern void memcpy_toshmem(int, void *, const void *, size_t);
29extern void memcpy_fromshmem(int, void *, const void *, size_t);
30extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
31 unsigned int, unsigned int, unsigned int, unsigned int *);
32
33int sndpkt(int devId, int channel, struct sk_buff *data) 23int sndpkt(int devId, int channel, struct sk_buff *data)
34{ 24{
35 LLData ReqLnkWrite; 25 LLData ReqLnkWrite;
diff --git a/drivers/isdn/sc/scioc.h b/drivers/isdn/sc/scioc.h
index d08e650c7b6..dfb107a6de4 100644
--- a/drivers/isdn/sc/scioc.h
+++ b/drivers/isdn/sc/scioc.h
@@ -1,3 +1,6 @@
1#ifndef __ISDN_SC_SCIOC_H__
2#define __ISDN_SC_SCIOC_H__
3
1/* 4/*
2 * This software may be used and distributed according to the terms 5 * This software may be used and distributed according to the terms
3 * of the GNU General Public License, incorporated herein by reference. 6 * of the GNU General Public License, incorporated herein by reference.
@@ -103,3 +106,6 @@ typedef struct {
103 POTInfo potsinfo; 106 POTInfo potsinfo;
104 } info; 107 } info;
105} boardInfo; 108} boardInfo;
109
110#endif /* __ISDN_SC_SCIOC_H__ */
111
diff --git a/drivers/isdn/sc/shmem.c b/drivers/isdn/sc/shmem.c
index 6f58862992d..034d41a61ae 100644
--- a/drivers/isdn/sc/shmem.c
+++ b/drivers/isdn/sc/shmem.c
@@ -22,12 +22,6 @@
22#include "card.h" 22#include "card.h"
23 23
24/* 24/*
25 * Main adapter array
26 */
27extern board *sc_adapter[];
28extern int cinst;
29
30/*
31 * 25 *
32 */ 26 */
33void memcpy_toshmem(int card, void *dest, const void *src, size_t n) 27void memcpy_toshmem(int card, void *dest, const void *src, size_t n)
diff --git a/drivers/isdn/sc/timer.c b/drivers/isdn/sc/timer.c
index f43282be0ad..cc1b8861be2 100644
--- a/drivers/isdn/sc/timer.c
+++ b/drivers/isdn/sc/timer.c
@@ -20,14 +20,6 @@
20#include "message.h" 20#include "message.h"
21#include "card.h" 21#include "card.h"
22 22
23extern board *sc_adapter[];
24
25extern void flushreadfifo(int);
26extern int startproc(int);
27extern int indicate_status(int, int, unsigned long, char *);
28extern int sendmessage(int, unsigned int, unsigned int, unsigned int,
29 unsigned int, unsigned int, unsigned int, unsigned int *);
30
31 23
32/* 24/*
33 * Write the proper values into the I/O ports following a reset 25 * Write the proper values into the I/O ports following a reset
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index 2db1ca4c680..04574a9d443 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -304,6 +304,7 @@ struct kvm {
304 int memory_config_version; 304 int memory_config_version;
305 int busy; 305 int busy;
306 unsigned long rmap_overflow; 306 unsigned long rmap_overflow;
307 struct list_head vm_list;
307}; 308};
308 309
309struct kvm_stat { 310struct kvm_stat {
@@ -340,6 +341,7 @@ struct kvm_arch_ops {
340 341
341 struct kvm_vcpu *(*vcpu_load)(struct kvm_vcpu *vcpu); 342 struct kvm_vcpu *(*vcpu_load)(struct kvm_vcpu *vcpu);
342 void (*vcpu_put)(struct kvm_vcpu *vcpu); 343 void (*vcpu_put)(struct kvm_vcpu *vcpu);
344 void (*vcpu_decache)(struct kvm_vcpu *vcpu);
343 345
344 int (*set_guest_debug)(struct kvm_vcpu *vcpu, 346 int (*set_guest_debug)(struct kvm_vcpu *vcpu,
345 struct kvm_debug_guest *dbg); 347 struct kvm_debug_guest *dbg);
@@ -558,7 +560,7 @@ static inline void load_gs(u16 sel)
558#ifndef load_ldt 560#ifndef load_ldt
559static inline void load_ldt(u16 sel) 561static inline void load_ldt(u16 sel)
560{ 562{
561 asm ("lldt %0" : : "g"(sel)); 563 asm ("lldt %0" : : "rm"(sel));
562} 564}
563#endif 565#endif
564 566
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 099f0afd394..af866147ff2 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -34,6 +34,8 @@
34#include <linux/highmem.h> 34#include <linux/highmem.h>
35#include <linux/file.h> 35#include <linux/file.h>
36#include <asm/desc.h> 36#include <asm/desc.h>
37#include <linux/sysdev.h>
38#include <linux/cpu.h>
37 39
38#include "x86_emulate.h" 40#include "x86_emulate.h"
39#include "segment_descriptor.h" 41#include "segment_descriptor.h"
@@ -41,6 +43,9 @@
41MODULE_AUTHOR("Qumranet"); 43MODULE_AUTHOR("Qumranet");
42MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
43 45
46static DEFINE_SPINLOCK(kvm_lock);
47static LIST_HEAD(vm_list);
48
44struct kvm_arch_ops *kvm_arch_ops; 49struct kvm_arch_ops *kvm_arch_ops;
45struct kvm_stat kvm_stat; 50struct kvm_stat kvm_stat;
46EXPORT_SYMBOL_GPL(kvm_stat); 51EXPORT_SYMBOL_GPL(kvm_stat);
@@ -230,9 +235,13 @@ static int kvm_dev_open(struct inode *inode, struct file *filp)
230 struct kvm_vcpu *vcpu = &kvm->vcpus[i]; 235 struct kvm_vcpu *vcpu = &kvm->vcpus[i];
231 236
232 mutex_init(&vcpu->mutex); 237 mutex_init(&vcpu->mutex);
238 vcpu->cpu = -1;
233 vcpu->kvm = kvm; 239 vcpu->kvm = kvm;
234 vcpu->mmu.root_hpa = INVALID_PAGE; 240 vcpu->mmu.root_hpa = INVALID_PAGE;
235 INIT_LIST_HEAD(&vcpu->free_pages); 241 INIT_LIST_HEAD(&vcpu->free_pages);
242 spin_lock(&kvm_lock);
243 list_add(&kvm->vm_list, &vm_list);
244 spin_unlock(&kvm_lock);
236 } 245 }
237 filp->private_data = kvm; 246 filp->private_data = kvm;
238 return 0; 247 return 0;
@@ -272,7 +281,9 @@ static void kvm_free_physmem(struct kvm *kvm)
272 281
273static void kvm_free_vcpu(struct kvm_vcpu *vcpu) 282static void kvm_free_vcpu(struct kvm_vcpu *vcpu)
274{ 283{
275 vcpu_load(vcpu->kvm, vcpu_slot(vcpu)); 284 if (!vcpu_load(vcpu->kvm, vcpu_slot(vcpu)))
285 return;
286
276 kvm_mmu_destroy(vcpu); 287 kvm_mmu_destroy(vcpu);
277 vcpu_put(vcpu); 288 vcpu_put(vcpu);
278 kvm_arch_ops->vcpu_free(vcpu); 289 kvm_arch_ops->vcpu_free(vcpu);
@@ -290,6 +301,9 @@ static int kvm_dev_release(struct inode *inode, struct file *filp)
290{ 301{
291 struct kvm *kvm = filp->private_data; 302 struct kvm *kvm = filp->private_data;
292 303
304 spin_lock(&kvm_lock);
305 list_del(&kvm->vm_list);
306 spin_unlock(&kvm_lock);
293 kvm_free_vcpus(kvm); 307 kvm_free_vcpus(kvm);
294 kvm_free_physmem(kvm); 308 kvm_free_physmem(kvm);
295 kfree(kvm); 309 kfree(kvm);
@@ -544,7 +558,6 @@ static int kvm_dev_ioctl_create_vcpu(struct kvm *kvm, int n)
544 FX_IMAGE_ALIGN); 558 FX_IMAGE_ALIGN);
545 vcpu->guest_fx_image = vcpu->host_fx_image + FX_IMAGE_SIZE; 559 vcpu->guest_fx_image = vcpu->host_fx_image + FX_IMAGE_SIZE;
546 560
547 vcpu->cpu = -1; /* First load will set up TR */
548 r = kvm_arch_ops->vcpu_create(vcpu); 561 r = kvm_arch_ops->vcpu_create(vcpu);
549 if (r < 0) 562 if (r < 0)
550 goto out_free_vcpus; 563 goto out_free_vcpus;
@@ -1360,6 +1373,9 @@ static int kvm_dev_ioctl_run(struct kvm *kvm, struct kvm_run *kvm_run)
1360 if (!vcpu) 1373 if (!vcpu)
1361 return -ENOENT; 1374 return -ENOENT;
1362 1375
1376 /* re-sync apic's tpr */
1377 vcpu->cr8 = kvm_run->cr8;
1378
1363 if (kvm_run->emulated) { 1379 if (kvm_run->emulated) {
1364 kvm_arch_ops->skip_emulated_instruction(vcpu); 1380 kvm_arch_ops->skip_emulated_instruction(vcpu);
1365 kvm_run->emulated = 0; 1381 kvm_run->emulated = 0;
@@ -2025,6 +2041,64 @@ static struct notifier_block kvm_reboot_notifier = {
2025 .priority = 0, 2041 .priority = 0,
2026}; 2042};
2027 2043
2044/*
2045 * Make sure that a cpu that is being hot-unplugged does not have any vcpus
2046 * cached on it.
2047 */
2048static void decache_vcpus_on_cpu(int cpu)
2049{
2050 struct kvm *vm;
2051 struct kvm_vcpu *vcpu;
2052 int i;
2053
2054 spin_lock(&kvm_lock);
2055 list_for_each_entry(vm, &vm_list, vm_list)
2056 for (i = 0; i < KVM_MAX_VCPUS; ++i) {
2057 vcpu = &vm->vcpus[i];
2058 /*
2059 * If the vcpu is locked, then it is running on some
2060 * other cpu and therefore it is not cached on the
2061 * cpu in question.
2062 *
2063 * If it's not locked, check the last cpu it executed
2064 * on.
2065 */
2066 if (mutex_trylock(&vcpu->mutex)) {
2067 if (vcpu->cpu == cpu) {
2068 kvm_arch_ops->vcpu_decache(vcpu);
2069 vcpu->cpu = -1;
2070 }
2071 mutex_unlock(&vcpu->mutex);
2072 }
2073 }
2074 spin_unlock(&kvm_lock);
2075}
2076
2077static int kvm_cpu_hotplug(struct notifier_block *notifier, unsigned long val,
2078 void *v)
2079{
2080 int cpu = (long)v;
2081
2082 switch (val) {
2083 case CPU_DEAD:
2084 case CPU_UP_CANCELED:
2085 decache_vcpus_on_cpu(cpu);
2086 smp_call_function_single(cpu, kvm_arch_ops->hardware_disable,
2087 NULL, 0, 1);
2088 break;
2089 case CPU_UP_PREPARE:
2090 smp_call_function_single(cpu, kvm_arch_ops->hardware_enable,
2091 NULL, 0, 1);
2092 break;
2093 }
2094 return NOTIFY_OK;
2095}
2096
2097static struct notifier_block kvm_cpu_notifier = {
2098 .notifier_call = kvm_cpu_hotplug,
2099 .priority = 20, /* must be > scheduler priority */
2100};
2101
2028static __init void kvm_init_debug(void) 2102static __init void kvm_init_debug(void)
2029{ 2103{
2030 struct kvm_stats_debugfs_item *p; 2104 struct kvm_stats_debugfs_item *p;
@@ -2044,6 +2118,30 @@ static void kvm_exit_debug(void)
2044 debugfs_remove(debugfs_dir); 2118 debugfs_remove(debugfs_dir);
2045} 2119}
2046 2120
2121static int kvm_suspend(struct sys_device *dev, pm_message_t state)
2122{
2123 decache_vcpus_on_cpu(raw_smp_processor_id());
2124 on_each_cpu(kvm_arch_ops->hardware_disable, 0, 0, 1);
2125 return 0;
2126}
2127
2128static int kvm_resume(struct sys_device *dev)
2129{
2130 on_each_cpu(kvm_arch_ops->hardware_enable, 0, 0, 1);
2131 return 0;
2132}
2133
2134static struct sysdev_class kvm_sysdev_class = {
2135 set_kset_name("kvm"),
2136 .suspend = kvm_suspend,
2137 .resume = kvm_resume,
2138};
2139
2140static struct sys_device kvm_sysdev = {
2141 .id = 0,
2142 .cls = &kvm_sysdev_class,
2143};
2144
2047hpa_t bad_page_address; 2145hpa_t bad_page_address;
2048 2146
2049int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module) 2147int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
@@ -2071,8 +2169,19 @@ int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
2071 return r; 2169 return r;
2072 2170
2073 on_each_cpu(kvm_arch_ops->hardware_enable, NULL, 0, 1); 2171 on_each_cpu(kvm_arch_ops->hardware_enable, NULL, 0, 1);
2172 r = register_cpu_notifier(&kvm_cpu_notifier);
2173 if (r)
2174 goto out_free_1;
2074 register_reboot_notifier(&kvm_reboot_notifier); 2175 register_reboot_notifier(&kvm_reboot_notifier);
2075 2176
2177 r = sysdev_class_register(&kvm_sysdev_class);
2178 if (r)
2179 goto out_free_2;
2180
2181 r = sysdev_register(&kvm_sysdev);
2182 if (r)
2183 goto out_free_3;
2184
2076 kvm_chardev_ops.owner = module; 2185 kvm_chardev_ops.owner = module;
2077 2186
2078 r = misc_register(&kvm_dev); 2187 r = misc_register(&kvm_dev);
@@ -2084,7 +2193,13 @@ int kvm_init_arch(struct kvm_arch_ops *ops, struct module *module)
2084 return r; 2193 return r;
2085 2194
2086out_free: 2195out_free:
2196 sysdev_unregister(&kvm_sysdev);
2197out_free_3:
2198 sysdev_class_unregister(&kvm_sysdev_class);
2199out_free_2:
2087 unregister_reboot_notifier(&kvm_reboot_notifier); 2200 unregister_reboot_notifier(&kvm_reboot_notifier);
2201 unregister_cpu_notifier(&kvm_cpu_notifier);
2202out_free_1:
2088 on_each_cpu(kvm_arch_ops->hardware_disable, NULL, 0, 1); 2203 on_each_cpu(kvm_arch_ops->hardware_disable, NULL, 0, 1);
2089 kvm_arch_ops->hardware_unsetup(); 2204 kvm_arch_ops->hardware_unsetup();
2090 return r; 2205 return r;
@@ -2093,8 +2208,10 @@ out_free:
2093void kvm_exit_arch(void) 2208void kvm_exit_arch(void)
2094{ 2209{
2095 misc_deregister(&kvm_dev); 2210 misc_deregister(&kvm_dev);
2096 2211 sysdev_unregister(&kvm_sysdev);
2212 sysdev_class_unregister(&kvm_sysdev_class);
2097 unregister_reboot_notifier(&kvm_reboot_notifier); 2213 unregister_reboot_notifier(&kvm_reboot_notifier);
2214 unregister_cpu_notifier(&kvm_cpu_notifier);
2098 on_each_cpu(kvm_arch_ops->hardware_disable, NULL, 0, 1); 2215 on_each_cpu(kvm_arch_ops->hardware_disable, NULL, 0, 1);
2099 kvm_arch_ops->hardware_unsetup(); 2216 kvm_arch_ops->hardware_unsetup();
2100 kvm_arch_ops = NULL; 2217 kvm_arch_ops = NULL;
diff --git a/drivers/kvm/paging_tmpl.h b/drivers/kvm/paging_tmpl.h
index 149fa45fd9a..b6b90e9e130 100644
--- a/drivers/kvm/paging_tmpl.h
+++ b/drivers/kvm/paging_tmpl.h
@@ -443,31 +443,17 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr,
443static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr) 443static gpa_t FNAME(gva_to_gpa)(struct kvm_vcpu *vcpu, gva_t vaddr)
444{ 444{
445 struct guest_walker walker; 445 struct guest_walker walker;
446 pt_element_t guest_pte; 446 gpa_t gpa = UNMAPPED_GVA;
447 gpa_t gpa; 447 int r;
448
449 FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0);
450 guest_pte = *walker.ptep;
451 FNAME(release_walker)(&walker);
452
453 if (!is_present_pte(guest_pte))
454 return UNMAPPED_GVA;
455
456 if (walker.level == PT_DIRECTORY_LEVEL) {
457 ASSERT((guest_pte & PT_PAGE_SIZE_MASK));
458 ASSERT(PTTYPE == 64 || is_pse(vcpu));
459 448
460 gpa = (guest_pte & PT_DIR_BASE_ADDR_MASK) | (vaddr & 449 r = FNAME(walk_addr)(&walker, vcpu, vaddr, 0, 0, 0);
461 (PT_LEVEL_MASK(PT_PAGE_TABLE_LEVEL) | ~PAGE_MASK));
462 450
463 if (PTTYPE == 32 && is_cpuid_PSE36()) 451 if (r) {
464 gpa |= (guest_pte & PT32_DIR_PSE36_MASK) << 452 gpa = (gpa_t)walker.gfn << PAGE_SHIFT;
465 (32 - PT32_DIR_PSE36_SHIFT); 453 gpa |= vaddr & ~PAGE_MASK;
466 } else {
467 gpa = (guest_pte & PT_BASE_ADDR_MASK);
468 gpa |= (vaddr & ~PAGE_MASK);
469 } 454 }
470 455
456 FNAME(release_walker)(&walker);
471 return gpa; 457 return gpa;
472} 458}
473 459
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index 85f61dd1e93..83da4ea150a 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -528,7 +528,13 @@ static void init_vmcb(struct vmcb *vmcb)
528 save->cs.attrib = SVM_SELECTOR_READ_MASK | SVM_SELECTOR_P_MASK | 528 save->cs.attrib = SVM_SELECTOR_READ_MASK | SVM_SELECTOR_P_MASK |
529 SVM_SELECTOR_S_MASK | SVM_SELECTOR_CODE_MASK; 529 SVM_SELECTOR_S_MASK | SVM_SELECTOR_CODE_MASK;
530 save->cs.limit = 0xffff; 530 save->cs.limit = 0xffff;
531 save->cs.base = 0xffff0000; 531 /*
532 * cs.base should really be 0xffff0000, but vmx can't handle that, so
533 * be consistent with it.
534 *
535 * Replace when we have real mode working for vmx.
536 */
537 save->cs.base = 0xf0000;
532 538
533 save->gdtr.limit = 0xffff; 539 save->gdtr.limit = 0xffff;
534 save->idtr.limit = 0xffff; 540 save->idtr.limit = 0xffff;
@@ -603,6 +609,10 @@ static void svm_vcpu_put(struct kvm_vcpu *vcpu)
603 put_cpu(); 609 put_cpu();
604} 610}
605 611
612static void svm_vcpu_decache(struct kvm_vcpu *vcpu)
613{
614}
615
606static void svm_cache_regs(struct kvm_vcpu *vcpu) 616static void svm_cache_regs(struct kvm_vcpu *vcpu)
607{ 617{
608 vcpu->regs[VCPU_REGS_RAX] = vcpu->svm->vmcb->save.rax; 618 vcpu->regs[VCPU_REGS_RAX] = vcpu->svm->vmcb->save.rax;
@@ -723,7 +733,7 @@ static void svm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
723 } 733 }
724#endif 734#endif
725 vcpu->svm->cr0 = cr0; 735 vcpu->svm->cr0 = cr0;
726 vcpu->svm->vmcb->save.cr0 = cr0 | CR0_PG_MASK; 736 vcpu->svm->vmcb->save.cr0 = cr0 | CR0_PG_MASK | CR0_WP_MASK;
727 vcpu->cr0 = cr0; 737 vcpu->cr0 = cr0;
728} 738}
729 739
@@ -1671,6 +1681,7 @@ static struct kvm_arch_ops svm_arch_ops = {
1671 1681
1672 .vcpu_load = svm_vcpu_load, 1682 .vcpu_load = svm_vcpu_load,
1673 .vcpu_put = svm_vcpu_put, 1683 .vcpu_put = svm_vcpu_put,
1684 .vcpu_decache = svm_vcpu_decache,
1674 1685
1675 .set_guest_debug = svm_guest_debug, 1686 .set_guest_debug = svm_guest_debug,
1676 .get_msr = svm_get_msr, 1687 .get_msr = svm_get_msr,
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index 27e05a77e21..1e640b89917 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -125,6 +125,15 @@ static void __vcpu_clear(void *arg)
125 per_cpu(current_vmcs, cpu) = NULL; 125 per_cpu(current_vmcs, cpu) = NULL;
126} 126}
127 127
128static void vcpu_clear(struct kvm_vcpu *vcpu)
129{
130 if (vcpu->cpu != raw_smp_processor_id() && vcpu->cpu != -1)
131 smp_call_function_single(vcpu->cpu, __vcpu_clear, vcpu, 0, 1);
132 else
133 __vcpu_clear(vcpu);
134 vcpu->launched = 0;
135}
136
128static unsigned long vmcs_readl(unsigned long field) 137static unsigned long vmcs_readl(unsigned long field)
129{ 138{
130 unsigned long value; 139 unsigned long value;
@@ -202,10 +211,8 @@ static struct kvm_vcpu *vmx_vcpu_load(struct kvm_vcpu *vcpu)
202 211
203 cpu = get_cpu(); 212 cpu = get_cpu();
204 213
205 if (vcpu->cpu != cpu) { 214 if (vcpu->cpu != cpu)
206 smp_call_function(__vcpu_clear, vcpu, 0, 1); 215 vcpu_clear(vcpu);
207 vcpu->launched = 0;
208 }
209 216
210 if (per_cpu(current_vmcs, cpu) != vcpu->vmcs) { 217 if (per_cpu(current_vmcs, cpu) != vcpu->vmcs) {
211 u8 error; 218 u8 error;
@@ -243,6 +250,11 @@ static void vmx_vcpu_put(struct kvm_vcpu *vcpu)
243 put_cpu(); 250 put_cpu();
244} 251}
245 252
253static void vmx_vcpu_decache(struct kvm_vcpu *vcpu)
254{
255 vcpu_clear(vcpu);
256}
257
246static unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu) 258static unsigned long vmx_get_rflags(struct kvm_vcpu *vcpu)
247{ 259{
248 return vmcs_readl(GUEST_RFLAGS); 260 return vmcs_readl(GUEST_RFLAGS);
@@ -502,7 +514,7 @@ static __init int vmx_disabled_by_bios(void)
502 return (msr & 5) == 1; /* locked but not enabled */ 514 return (msr & 5) == 1; /* locked but not enabled */
503} 515}
504 516
505static __init void hardware_enable(void *garbage) 517static void hardware_enable(void *garbage)
506{ 518{
507 int cpu = raw_smp_processor_id(); 519 int cpu = raw_smp_processor_id();
508 u64 phys_addr = __pa(per_cpu(vmxarea, cpu)); 520 u64 phys_addr = __pa(per_cpu(vmxarea, cpu));
@@ -1375,6 +1387,11 @@ static int handle_external_interrupt(struct kvm_vcpu *vcpu,
1375 return 1; 1387 return 1;
1376} 1388}
1377 1389
1390static int handle_triple_fault(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1391{
1392 kvm_run->exit_reason = KVM_EXIT_SHUTDOWN;
1393 return 0;
1394}
1378 1395
1379static int get_io_count(struct kvm_vcpu *vcpu, u64 *count) 1396static int get_io_count(struct kvm_vcpu *vcpu, u64 *count)
1380{ 1397{
@@ -1635,6 +1652,7 @@ static int (*kvm_vmx_exit_handlers[])(struct kvm_vcpu *vcpu,
1635 struct kvm_run *kvm_run) = { 1652 struct kvm_run *kvm_run) = {
1636 [EXIT_REASON_EXCEPTION_NMI] = handle_exception, 1653 [EXIT_REASON_EXCEPTION_NMI] = handle_exception,
1637 [EXIT_REASON_EXTERNAL_INTERRUPT] = handle_external_interrupt, 1654 [EXIT_REASON_EXTERNAL_INTERRUPT] = handle_external_interrupt,
1655 [EXIT_REASON_TRIPLE_FAULT] = handle_triple_fault,
1638 [EXIT_REASON_IO_INSTRUCTION] = handle_io, 1656 [EXIT_REASON_IO_INSTRUCTION] = handle_io,
1639 [EXIT_REASON_CR_ACCESS] = handle_cr, 1657 [EXIT_REASON_CR_ACCESS] = handle_cr,
1640 [EXIT_REASON_DR_ACCESS] = handle_dr, 1658 [EXIT_REASON_DR_ACCESS] = handle_dr,
@@ -1786,10 +1804,10 @@ again:
1786 "kvm_vmx_return: " 1804 "kvm_vmx_return: "
1787 /* Save guest registers, load host registers, keep flags */ 1805 /* Save guest registers, load host registers, keep flags */
1788#ifdef CONFIG_X86_64 1806#ifdef CONFIG_X86_64
1789 "xchg %3, 0(%%rsp) \n\t" 1807 "xchg %3, (%%rsp) \n\t"
1790 "mov %%rax, %c[rax](%3) \n\t" 1808 "mov %%rax, %c[rax](%3) \n\t"
1791 "mov %%rbx, %c[rbx](%3) \n\t" 1809 "mov %%rbx, %c[rbx](%3) \n\t"
1792 "pushq 0(%%rsp); popq %c[rcx](%3) \n\t" 1810 "pushq (%%rsp); popq %c[rcx](%3) \n\t"
1793 "mov %%rdx, %c[rdx](%3) \n\t" 1811 "mov %%rdx, %c[rdx](%3) \n\t"
1794 "mov %%rsi, %c[rsi](%3) \n\t" 1812 "mov %%rsi, %c[rsi](%3) \n\t"
1795 "mov %%rdi, %c[rdi](%3) \n\t" 1813 "mov %%rdi, %c[rdi](%3) \n\t"
@@ -1804,24 +1822,24 @@ again:
1804 "mov %%r15, %c[r15](%3) \n\t" 1822 "mov %%r15, %c[r15](%3) \n\t"
1805 "mov %%cr2, %%rax \n\t" 1823 "mov %%cr2, %%rax \n\t"
1806 "mov %%rax, %c[cr2](%3) \n\t" 1824 "mov %%rax, %c[cr2](%3) \n\t"
1807 "mov 0(%%rsp), %3 \n\t" 1825 "mov (%%rsp), %3 \n\t"
1808 1826
1809 "pop %%rcx; pop %%r15; pop %%r14; pop %%r13; pop %%r12;" 1827 "pop %%rcx; pop %%r15; pop %%r14; pop %%r13; pop %%r12;"
1810 "pop %%r11; pop %%r10; pop %%r9; pop %%r8;" 1828 "pop %%r11; pop %%r10; pop %%r9; pop %%r8;"
1811 "pop %%rbp; pop %%rdi; pop %%rsi;" 1829 "pop %%rbp; pop %%rdi; pop %%rsi;"
1812 "pop %%rdx; pop %%rbx; pop %%rax \n\t" 1830 "pop %%rdx; pop %%rbx; pop %%rax \n\t"
1813#else 1831#else
1814 "xchg %3, 0(%%esp) \n\t" 1832 "xchg %3, (%%esp) \n\t"
1815 "mov %%eax, %c[rax](%3) \n\t" 1833 "mov %%eax, %c[rax](%3) \n\t"
1816 "mov %%ebx, %c[rbx](%3) \n\t" 1834 "mov %%ebx, %c[rbx](%3) \n\t"
1817 "pushl 0(%%esp); popl %c[rcx](%3) \n\t" 1835 "pushl (%%esp); popl %c[rcx](%3) \n\t"
1818 "mov %%edx, %c[rdx](%3) \n\t" 1836 "mov %%edx, %c[rdx](%3) \n\t"
1819 "mov %%esi, %c[rsi](%3) \n\t" 1837 "mov %%esi, %c[rsi](%3) \n\t"
1820 "mov %%edi, %c[rdi](%3) \n\t" 1838 "mov %%edi, %c[rdi](%3) \n\t"
1821 "mov %%ebp, %c[rbp](%3) \n\t" 1839 "mov %%ebp, %c[rbp](%3) \n\t"
1822 "mov %%cr2, %%eax \n\t" 1840 "mov %%cr2, %%eax \n\t"
1823 "mov %%eax, %c[cr2](%3) \n\t" 1841 "mov %%eax, %c[cr2](%3) \n\t"
1824 "mov 0(%%esp), %3 \n\t" 1842 "mov (%%esp), %3 \n\t"
1825 1843
1826 "pop %%ecx; popa \n\t" 1844 "pop %%ecx; popa \n\t"
1827#endif 1845#endif
@@ -1859,9 +1877,7 @@ again:
1859 fx_restore(vcpu->host_fx_image); 1877 fx_restore(vcpu->host_fx_image);
1860 vcpu->interrupt_window_open = (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0; 1878 vcpu->interrupt_window_open = (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) & 3) == 0;
1861 1879
1862#ifndef CONFIG_X86_64
1863 asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS)); 1880 asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
1864#endif
1865 1881
1866 /* 1882 /*
1867 * Profile KVM exit RIPs: 1883 * Profile KVM exit RIPs:
@@ -2012,6 +2028,7 @@ static struct kvm_arch_ops vmx_arch_ops = {
2012 2028
2013 .vcpu_load = vmx_vcpu_load, 2029 .vcpu_load = vmx_vcpu_load,
2014 .vcpu_put = vmx_vcpu_put, 2030 .vcpu_put = vmx_vcpu_put,
2031 .vcpu_decache = vmx_vcpu_decache,
2015 2032
2016 .set_guest_debug = set_guest_debug, 2033 .set_guest_debug = set_guest_debug,
2017 .get_msr = vmx_get_msr, 2034 .get_msr = vmx_get_msr,
diff --git a/drivers/kvm/vmx.h b/drivers/kvm/vmx.h
index 4c0ab151836..d0dc93df411 100644
--- a/drivers/kvm/vmx.h
+++ b/drivers/kvm/vmx.h
@@ -180,6 +180,7 @@ enum vmcs_field {
180 180
181#define EXIT_REASON_EXCEPTION_NMI 0 181#define EXIT_REASON_EXCEPTION_NMI 0
182#define EXIT_REASON_EXTERNAL_INTERRUPT 1 182#define EXIT_REASON_EXTERNAL_INTERRUPT 1
183#define EXIT_REASON_TRIPLE_FAULT 2
183 184
184#define EXIT_REASON_PENDING_INTERRUPT 7 185#define EXIT_REASON_PENDING_INTERRUPT 7
185 186
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index 7cec6de5e2b..f729eebf771 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -885,7 +885,7 @@ out:
885 return ret; 885 return ret;
886} 886}
887 887
888static struct file_operations adb_fops = { 888static const struct file_operations adb_fops = {
889 .owner = THIS_MODULE, 889 .owner = THIS_MODULE,
890 .llseek = no_llseek, 890 .llseek = no_llseek,
891 .read = adb_read, 891 .read = adb_read,
diff --git a/drivers/macintosh/ans-lcd.c b/drivers/macintosh/ans-lcd.c
index 2b8a6e821d4..cdd5a0f72e3 100644
--- a/drivers/macintosh/ans-lcd.c
+++ b/drivers/macintosh/ans-lcd.c
@@ -121,7 +121,7 @@ anslcd_open( struct inode * inode, struct file * file )
121 return 0; 121 return 0;
122} 122}
123 123
124struct file_operations anslcd_fops = { 124const struct file_operations anslcd_fops = {
125 .write = anslcd_write, 125 .write = anslcd_write,
126 .ioctl = anslcd_ioctl, 126 .ioctl = anslcd_ioctl,
127 .open = anslcd_open, 127 .open = anslcd_open,
diff --git a/drivers/macintosh/apm_emu.c b/drivers/macintosh/apm_emu.c
index 4300c628f8a..a6d50f4fabd 100644
--- a/drivers/macintosh/apm_emu.c
+++ b/drivers/macintosh/apm_emu.c
@@ -501,7 +501,7 @@ static int apm_emu_get_info(char *buf, char **start, off_t fpos, int length)
501 return p - buf; 501 return p - buf;
502} 502}
503 503
504static struct file_operations apm_bios_fops = { 504static const struct file_operations apm_bios_fops = {
505 .owner = THIS_MODULE, 505 .owner = THIS_MODULE,
506 .read = do_read, 506 .read = do_read,
507 .poll = do_poll, 507 .poll = do_poll,
diff --git a/drivers/macintosh/nvram.c b/drivers/macintosh/nvram.c
index 30791875fc9..b195d753d2e 100644
--- a/drivers/macintosh/nvram.c
+++ b/drivers/macintosh/nvram.c
@@ -100,7 +100,7 @@ static int nvram_ioctl(struct inode *inode, struct file *file,
100 return 0; 100 return 0;
101} 101}
102 102
103struct file_operations nvram_fops = { 103const struct file_operations nvram_fops = {
104 .owner = THIS_MODULE, 104 .owner = THIS_MODULE,
105 .llseek = nvram_llseek, 105 .llseek = nvram_llseek,
106 .read = read_nvram, 106 .read = read_nvram,
diff --git a/drivers/macintosh/smu.c b/drivers/macintosh/smu.c
index 6f30459b938..3096836d8bd 100644
--- a/drivers/macintosh/smu.c
+++ b/drivers/macintosh/smu.c
@@ -1277,7 +1277,7 @@ static int smu_release(struct inode *inode, struct file *file)
1277} 1277}
1278 1278
1279 1279
1280static struct file_operations smu_device_fops = { 1280static const struct file_operations smu_device_fops = {
1281 .llseek = no_llseek, 1281 .llseek = no_llseek,
1282 .read = smu_read, 1282 .read = smu_read,
1283 .write = smu_write, 1283 .write = smu_write,
diff --git a/drivers/macintosh/via-pmu.c b/drivers/macintosh/via-pmu.c
index 8ca75e52f63..96bea4b62c4 100644
--- a/drivers/macintosh/via-pmu.c
+++ b/drivers/macintosh/via-pmu.c
@@ -516,7 +516,6 @@ static int __init via_pmu_dev_init(void)
516 proc_get_irqstats, NULL); 516 proc_get_irqstats, NULL);
517 proc_pmu_options = create_proc_entry("options", 0600, proc_pmu_root); 517 proc_pmu_options = create_proc_entry("options", 0600, proc_pmu_root);
518 if (proc_pmu_options) { 518 if (proc_pmu_options) {
519 proc_pmu_options->nlink = 1;
520 proc_pmu_options->read_proc = proc_read_options; 519 proc_pmu_options->read_proc = proc_read_options;
521 proc_pmu_options->write_proc = proc_write_options; 520 proc_pmu_options->write_proc = proc_write_options;
522 } 521 }
@@ -2673,7 +2672,7 @@ pmu_ioctl(struct inode * inode, struct file *filp,
2673 return error; 2672 return error;
2674} 2673}
2675 2674
2676static struct file_operations pmu_device_fops = { 2675static const struct file_operations pmu_device_fops = {
2677 .read = pmu_read, 2676 .read = pmu_read,
2678 .write = pmu_write, 2677 .write = pmu_write,
2679 .poll = pmu_fpoll, 2678 .poll = pmu_fpoll,
diff --git a/drivers/macintosh/via-pmu68k.c b/drivers/macintosh/via-pmu68k.c
index 93e6ef9233f..4f5b6fa196c 100644
--- a/drivers/macintosh/via-pmu68k.c
+++ b/drivers/macintosh/via-pmu68k.c
@@ -1040,7 +1040,7 @@ static int pmu_ioctl(struct inode * inode, struct file *filp,
1040 return -EINVAL; 1040 return -EINVAL;
1041} 1041}
1042 1042
1043static struct file_operations pmu_device_fops = { 1043static const struct file_operations pmu_device_fops = {
1044 .read = pmu_read, 1044 .read = pmu_read,
1045 .write = pmu_write, 1045 .write = pmu_write,
1046 .ioctl = pmu_ioctl, 1046 .ioctl = pmu_ioctl,
diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
index 059704fbb75..5554adaa58f 100644
--- a/drivers/md/bitmap.c
+++ b/drivers/md/bitmap.c
@@ -666,7 +666,7 @@ static void bitmap_file_put(struct bitmap *bitmap)
666 666
667 if (file) { 667 if (file) {
668 struct inode *inode = file->f_path.dentry->d_inode; 668 struct inode *inode = file->f_path.dentry->d_inode;
669 invalidate_inode_pages(inode->i_mapping); 669 invalidate_mapping_pages(inode->i_mapping, 0, -1);
670 fput(file); 670 fput(file);
671 } 671 }
672} 672}
diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
index cd6a184536a..b441d82c338 100644
--- a/drivers/md/dm-ioctl.c
+++ b/drivers/md/dm-ioctl.c
@@ -1473,7 +1473,7 @@ static int ctl_ioctl(struct inode *inode, struct file *file,
1473 return r; 1473 return r;
1474} 1474}
1475 1475
1476static struct file_operations _ctl_fops = { 1476static const struct file_operations _ctl_fops = {
1477 .ioctl = ctl_ioctl, 1477 .ioctl = ctl_ioctl,
1478 .owner = THIS_MODULE, 1478 .owner = THIS_MODULE,
1479}; 1479};
diff --git a/drivers/md/md.c b/drivers/md/md.c
index e8807ea5377..e85fa75a791 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -4920,7 +4920,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
4920 return mask; 4920 return mask;
4921} 4921}
4922 4922
4923static struct file_operations md_seq_fops = { 4923static const struct file_operations md_seq_fops = {
4924 .owner = THIS_MODULE, 4924 .owner = THIS_MODULE,
4925 .open = md_seq_open, 4925 .open = md_seq_open,
4926 .read = seq_read, 4926 .read = seq_read,
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index d867a6a9e43..b8dcfa16526 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -416,7 +416,7 @@ static ssize_t fops_write(struct file *file, const char __user *data, size_t cou
416 } 416 }
417} 417}
418 418
419static struct file_operations video_fops = 419static const struct file_operations video_fops =
420{ 420{
421 .owner = THIS_MODULE, 421 .owner = THIS_MODULE,
422 .open = fops_open, 422 .open = fops_open,
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c
index db865a0667e..df8d0520d1d 100644
--- a/drivers/media/radio/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
@@ -144,7 +144,7 @@ struct dsbr100_device {
144 144
145 145
146/* File system interface */ 146/* File system interface */
147static struct file_operations usb_dsbr100_fops = { 147static const struct file_operations usb_dsbr100_fops = {
148 .owner = THIS_MODULE, 148 .owner = THIS_MODULE,
149 .open = usb_dsbr100_open, 149 .open = usb_dsbr100_open,
150 .release = usb_dsbr100_close, 150 .release = usb_dsbr100_close,
diff --git a/drivers/media/radio/miropcm20-radio.c b/drivers/media/radio/miropcm20-radio.c
index c4312fa0e2f..c7c9d1dc069 100644
--- a/drivers/media/radio/miropcm20-radio.c
+++ b/drivers/media/radio/miropcm20-radio.c
@@ -216,7 +216,7 @@ static struct pcm20_device pcm20_unit = {
216 .muted = 1, 216 .muted = 1,
217}; 217};
218 218
219static struct file_operations pcm20_fops = { 219static const struct file_operations pcm20_fops = {
220 .owner = THIS_MODULE, 220 .owner = THIS_MODULE,
221 .open = video_exclusive_open, 221 .open = video_exclusive_open,
222 .release = video_exclusive_release, 222 .release = video_exclusive_release,
diff --git a/drivers/media/radio/miropcm20-rds.c b/drivers/media/radio/miropcm20-rds.c
index c1b1db65e66..c93490ec96b 100644
--- a/drivers/media/radio/miropcm20-rds.c
+++ b/drivers/media/radio/miropcm20-rds.c
@@ -105,7 +105,7 @@ static ssize_t rds_f_read(struct file *file, char __user *buffer, size_t length,
105 } 105 }
106} 106}
107 107
108static struct file_operations rds_fops = { 108static const struct file_operations rds_fops = {
109 .owner = THIS_MODULE, 109 .owner = THIS_MODULE,
110 .read = rds_f_read, 110 .read = rds_f_read,
111 .open = rds_f_open, 111 .open = rds_f_open,
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index 3368a89bfad..b2e88ad2897 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -358,7 +358,7 @@ static int rt_ioctl(struct inode *inode, struct file *file,
358 358
359static struct rt_device rtrack_unit; 359static struct rt_device rtrack_unit;
360 360
361static struct file_operations rtrack_fops = { 361static const struct file_operations rtrack_fops = {
362 .owner = THIS_MODULE, 362 .owner = THIS_MODULE,
363 .open = video_exclusive_open, 363 .open = video_exclusive_open,
364 .release = video_exclusive_release, 364 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-aztech.c b/drivers/media/radio/radio-aztech.c
index 3ba5fa8cf7e..19d45cc940b 100644
--- a/drivers/media/radio/radio-aztech.c
+++ b/drivers/media/radio/radio-aztech.c
@@ -314,7 +314,7 @@ static int az_ioctl(struct inode *inode, struct file *file,
314 314
315static struct az_device aztech_unit; 315static struct az_device aztech_unit;
316 316
317static struct file_operations aztech_fops = { 317static const struct file_operations aztech_fops = {
318 .owner = THIS_MODULE, 318 .owner = THIS_MODULE,
319 .open = video_exclusive_open, 319 .open = video_exclusive_open,
320 .release = video_exclusive_release, 320 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index 69d4b7919c5..8fbf0d8bd27 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -507,7 +507,7 @@ cadet_poll(struct file *file, struct poll_table_struct *wait)
507} 507}
508 508
509 509
510static struct file_operations cadet_fops = { 510static const struct file_operations cadet_fops = {
511 .owner = THIS_MODULE, 511 .owner = THIS_MODULE,
512 .open = cadet_open, 512 .open = cadet_open,
513 .release = cadet_release, 513 .release = cadet_release,
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index eb14106f66f..05e5aa77025 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -346,7 +346,7 @@ MODULE_DEVICE_TABLE( pci, gemtek_pci_id );
346 346
347static int mx = 1; 347static int mx = 1;
348 348
349static struct file_operations gemtek_pci_fops = { 349static const struct file_operations gemtek_pci_fops = {
350 .owner = THIS_MODULE, 350 .owner = THIS_MODULE,
351 .open = video_exclusive_open, 351 .open = video_exclusive_open,
352 .release = video_exclusive_release, 352 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-gemtek.c b/drivers/media/radio/radio-gemtek.c
index 730fe16126c..36c4be6622c 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -296,7 +296,7 @@ static int gemtek_ioctl(struct inode *inode, struct file *file,
296 296
297static struct gemtek_device gemtek_unit; 297static struct gemtek_device gemtek_unit;
298 298
299static struct file_operations gemtek_fops = { 299static const struct file_operations gemtek_fops = {
300 .owner = THIS_MODULE, 300 .owner = THIS_MODULE,
301 .open = video_exclusive_open, 301 .open = video_exclusive_open,
302 .release = video_exclusive_release, 302 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index e8ce5f75cf1..9bba6eb1092 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -99,7 +99,7 @@ static struct pci_driver maestro_r_driver = {
99 .remove = __devexit_p(maestro_remove), 99 .remove = __devexit_p(maestro_remove),
100}; 100};
101 101
102static struct file_operations maestro_fops = { 102static const struct file_operations maestro_fops = {
103 .owner = THIS_MODULE, 103 .owner = THIS_MODULE,
104 .open = video_exclusive_open, 104 .open = video_exclusive_open,
105 .release = video_exclusive_release, 105 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index c2eeae7a10d..00a2f31d2af 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -91,7 +91,7 @@ module_param(radio_nr, int, 0);
91static int radio_ioctl(struct inode *inode, struct file *file, 91static int radio_ioctl(struct inode *inode, struct file *file,
92 unsigned int cmd, unsigned long arg); 92 unsigned int cmd, unsigned long arg);
93 93
94static struct file_operations maxiradio_fops = { 94static const struct file_operations maxiradio_fops = {
95 .owner = THIS_MODULE, 95 .owner = THIS_MODULE,
96 .open = video_exclusive_open, 96 .open = video_exclusive_open,
97 .release = video_exclusive_release, 97 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-rtrack2.c b/drivers/media/radio/radio-rtrack2.c
index b9e98483e58..f6683872251 100644
--- a/drivers/media/radio/radio-rtrack2.c
+++ b/drivers/media/radio/radio-rtrack2.c
@@ -262,7 +262,7 @@ static int rt_ioctl(struct inode *inode, struct file *file,
262 262
263static struct rt_device rtrack2_unit; 263static struct rt_device rtrack2_unit;
264 264
265static struct file_operations rtrack2_fops = { 265static const struct file_operations rtrack2_fops = {
266 .owner = THIS_MODULE, 266 .owner = THIS_MODULE,
267 .open = video_exclusive_open, 267 .open = video_exclusive_open,
268 .release = video_exclusive_release, 268 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index ecc854b4ba3..f4619e4dda4 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -265,7 +265,7 @@ static int fmi_ioctl(struct inode *inode, struct file *file,
265 265
266static struct fmi_device fmi_unit; 266static struct fmi_device fmi_unit;
267 267
268static struct file_operations fmi_fops = { 268static const struct file_operations fmi_fops = {
269 .owner = THIS_MODULE, 269 .owner = THIS_MODULE,
270 .open = video_exclusive_open, 270 .open = video_exclusive_open,
271 .release = video_exclusive_release, 271 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index 4444dce864a..b96fafe1f9d 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -410,7 +410,7 @@ static int fmr2_ioctl(struct inode *inode, struct file *file,
410 410
411static struct fmr2_device fmr2_unit; 411static struct fmr2_device fmr2_unit;
412 412
413static struct file_operations fmr2_fops = { 413static const struct file_operations fmr2_fops = {
414 .owner = THIS_MODULE, 414 .owner = THIS_MODULE,
415 .open = video_exclusive_open, 415 .open = video_exclusive_open,
416 .release = video_exclusive_release, 416 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-terratec.c b/drivers/media/radio/radio-terratec.c
index f539491a0d7..d59a27accb8 100644
--- a/drivers/media/radio/radio-terratec.c
+++ b/drivers/media/radio/radio-terratec.c
@@ -338,7 +338,7 @@ static int tt_ioctl(struct inode *inode, struct file *file,
338 338
339static struct tt_device terratec_unit; 339static struct tt_device terratec_unit;
340 340
341static struct file_operations terratec_fops = { 341static const struct file_operations terratec_fops = {
342 .owner = THIS_MODULE, 342 .owner = THIS_MODULE,
343 .open = video_exclusive_open, 343 .open = video_exclusive_open,
344 .release = video_exclusive_release, 344 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-trust.c b/drivers/media/radio/radio-trust.c
index bb03ad5a203..6d7f1e7116e 100644
--- a/drivers/media/radio/radio-trust.c
+++ b/drivers/media/radio/radio-trust.c
@@ -325,7 +325,7 @@ static int tr_ioctl(struct inode *inode, struct file *file,
325 return video_usercopy(inode, file, cmd, arg, tr_do_ioctl); 325 return video_usercopy(inode, file, cmd, arg, tr_do_ioctl);
326} 326}
327 327
328static struct file_operations trust_fops = { 328static const struct file_operations trust_fops = {
329 .owner = THIS_MODULE, 329 .owner = THIS_MODULE,
330 .open = video_exclusive_open, 330 .open = video_exclusive_open,
331 .release = video_exclusive_release, 331 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-typhoon.c b/drivers/media/radio/radio-typhoon.c
index 4a72b4d4e62..3031fef178c 100644
--- a/drivers/media/radio/radio-typhoon.c
+++ b/drivers/media/radio/radio-typhoon.c
@@ -318,7 +318,7 @@ static struct typhoon_device typhoon_unit =
318 .mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ, 318 .mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ,
319}; 319};
320 320
321static struct file_operations typhoon_fops = { 321static const struct file_operations typhoon_fops = {
322 .owner = THIS_MODULE, 322 .owner = THIS_MODULE,
323 .open = video_exclusive_open, 323 .open = video_exclusive_open,
324 .release = video_exclusive_release, 324 .release = video_exclusive_release,
diff --git a/drivers/media/radio/radio-zoltrix.c b/drivers/media/radio/radio-zoltrix.c
index 671fe1b1e5b..ec08491fb7c 100644
--- a/drivers/media/radio/radio-zoltrix.c
+++ b/drivers/media/radio/radio-zoltrix.c
@@ -373,7 +373,7 @@ static int zol_ioctl(struct inode *inode, struct file *file,
373 373
374static struct zol_device zoltrix_unit; 374static struct zol_device zoltrix_unit;
375 375
376static struct file_operations zoltrix_fops = 376static const struct file_operations zoltrix_fops =
377{ 377{
378 .owner = THIS_MODULE, 378 .owner = THIS_MODULE,
379 .open = video_exclusive_open, 379 .open = video_exclusive_open,
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index 4861799eb43..649f52f9ad2 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -742,7 +742,7 @@ void ar_release(struct video_device *vfd)
742 * Video4Linux Module functions 742 * Video4Linux Module functions
743 * 743 *
744 ****************************************************************************/ 744 ****************************************************************************/
745static struct file_operations ar_fops = { 745static const struct file_operations ar_fops = {
746 .owner = THIS_MODULE, 746 .owner = THIS_MODULE,
747 .open = video_exclusive_open, 747 .open = video_exclusive_open,
748 .release = video_exclusive_release, 748 .release = video_exclusive_release,
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index ab8f970760f..41fd09d7d11 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -3174,7 +3174,7 @@ bttv_mmap(struct file *file, struct vm_area_struct *vma)
3174 return videobuf_mmap_mapper(bttv_queue(fh),vma); 3174 return videobuf_mmap_mapper(bttv_queue(fh),vma);
3175} 3175}
3176 3176
3177static struct file_operations bttv_fops = 3177static const struct file_operations bttv_fops =
3178{ 3178{
3179 .owner = THIS_MODULE, 3179 .owner = THIS_MODULE,
3180 .open = bttv_open, 3180 .open = bttv_open,
@@ -3332,7 +3332,7 @@ static unsigned int radio_poll(struct file *file, poll_table *wait)
3332 return cmd.result; 3332 return cmd.result;
3333} 3333}
3334 3334
3335static struct file_operations radio_fops = 3335static const struct file_operations radio_fops =
3336{ 3336{
3337 .owner = THIS_MODULE, 3337 .owner = THIS_MODULE,
3338 .open = radio_open, 3338 .open = radio_open,
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index 7d0b6e59c6e..7d47cbe6ad2 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -871,7 +871,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
871 return len; 871 return len;
872} 872}
873 873
874static struct file_operations qcam_fops = { 874static const struct file_operations qcam_fops = {
875 .owner = THIS_MODULE, 875 .owner = THIS_MODULE,
876 .open = video_exclusive_open, 876 .open = video_exclusive_open,
877 .release = video_exclusive_release, 877 .release = video_exclusive_release,
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c
index a3989bd2f81..925ff17efbb 100644
--- a/drivers/media/video/c-qcam.c
+++ b/drivers/media/video/c-qcam.c
@@ -684,7 +684,7 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
684} 684}
685 685
686/* video device template */ 686/* video device template */
687static struct file_operations qcam_fops = { 687static const struct file_operations qcam_fops = {
688 .owner = THIS_MODULE, 688 .owner = THIS_MODULE,
689 .open = video_exclusive_open, 689 .open = video_exclusive_open,
690 .release = video_exclusive_release, 690 .release = video_exclusive_release,
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index 3083c8075d1..fb1410c6f86 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -1715,7 +1715,7 @@ static void cafe_v4l_dev_release(struct video_device *vd)
1715 * clone it for specific real devices. 1715 * clone it for specific real devices.
1716 */ 1716 */
1717 1717
1718static struct file_operations cafe_v4l_fops = { 1718static const struct file_operations cafe_v4l_fops = {
1719 .owner = THIS_MODULE, 1719 .owner = THIS_MODULE,
1720 .open = cafe_v4l_open, 1720 .open = cafe_v4l_open,
1721 .release = cafe_v4l_release, 1721 .release = cafe_v4l_release,
@@ -1969,7 +1969,7 @@ static ssize_t cafe_dfs_read_regs(struct file *file,
1969 s - cafe_debug_buf); 1969 s - cafe_debug_buf);
1970} 1970}
1971 1971
1972static struct file_operations cafe_dfs_reg_ops = { 1972static const struct file_operations cafe_dfs_reg_ops = {
1973 .owner = THIS_MODULE, 1973 .owner = THIS_MODULE,
1974 .read = cafe_dfs_read_regs, 1974 .read = cafe_dfs_read_regs,
1975 .open = cafe_dfs_open 1975 .open = cafe_dfs_open
@@ -1995,7 +1995,7 @@ static ssize_t cafe_dfs_read_cam(struct file *file,
1995 s - cafe_debug_buf); 1995 s - cafe_debug_buf);
1996} 1996}
1997 1997
1998static struct file_operations cafe_dfs_cam_ops = { 1998static const struct file_operations cafe_dfs_cam_ops = {
1999 .owner = THIS_MODULE, 1999 .owner = THIS_MODULE,
2000 .read = cafe_dfs_read_cam, 2000 .read = cafe_dfs_read_cam,
2001 .open = cafe_dfs_open 2001 .open = cafe_dfs_open
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 3b31a0dd2f0..7e8d5ef58b6 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -3791,7 +3791,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3791 return 0; 3791 return 0;
3792} 3792}
3793 3793
3794static struct file_operations cpia_fops = { 3794static const struct file_operations cpia_fops = {
3795 .owner = THIS_MODULE, 3795 .owner = THIS_MODULE,
3796 .open = cpia_open, 3796 .open = cpia_open,
3797 .release = cpia_close, 3797 .release = cpia_close,
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index d09f49950f2..1bda7ad9de1 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -1924,7 +1924,7 @@ static void reset_camera_struct_v4l(struct camera_data *cam)
1924/*** 1924/***
1925 * The v4l video device structure initialized for this device 1925 * The v4l video device structure initialized for this device
1926 ***/ 1926 ***/
1927static struct file_operations fops_template = { 1927static const struct file_operations fops_template = {
1928 .owner = THIS_MODULE, 1928 .owner = THIS_MODULE,
1929 .open = cpia2_open, 1929 .open = cpia2_open,
1930 .release = cpia2_close, 1930 .release = cpia2_close,
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 0cf0360588e..9a7a2996f20 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1051,7 +1051,7 @@ mpeg_mmap(struct file *file, struct vm_area_struct * vma)
1051 return videobuf_mmap_mapper(&fh->mpegq, vma); 1051 return videobuf_mmap_mapper(&fh->mpegq, vma);
1052} 1052}
1053 1053
1054static struct file_operations mpeg_fops = 1054static const struct file_operations mpeg_fops =
1055{ 1055{
1056 .owner = THIS_MODULE, 1056 .owner = THIS_MODULE,
1057 .open = mpeg_open, 1057 .open = mpeg_open,
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 8613378428f..c86a7e06235 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -1808,7 +1808,7 @@ static irqreturn_t cx8800_irq(int irq, void *dev_id)
1808/* ----------------------------------------------------------- */ 1808/* ----------------------------------------------------------- */
1809/* exported stuff */ 1809/* exported stuff */
1810 1810
1811static struct file_operations video_fops = 1811static const struct file_operations video_fops =
1812{ 1812{
1813 .owner = THIS_MODULE, 1813 .owner = THIS_MODULE,
1814 .open = video_open, 1814 .open = video_open,
@@ -1839,7 +1839,7 @@ static struct video_device cx8800_vbi_template =
1839 .minor = -1, 1839 .minor = -1,
1840}; 1840};
1841 1841
1842static struct file_operations radio_fops = 1842static const struct file_operations radio_fops =
1843{ 1843{
1844 .owner = THIS_MODULE, 1844 .owner = THIS_MODULE,
1845 .open = video_open, 1845 .open = video_open,
diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c
index 917021fc299..ff4b238090a 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -696,7 +696,7 @@ static int dabusb_ioctl (struct inode *inode, struct file *file, unsigned int cm
696 return ret; 696 return ret;
697} 697}
698 698
699static struct file_operations dabusb_fops = 699static const struct file_operations dabusb_fops =
700{ 700{
701 .owner = THIS_MODULE, 701 .owner = THIS_MODULE,
702 .llseek = no_llseek, 702 .llseek = no_llseek,
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 36e72c207a8..bec67609500 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -1480,7 +1480,7 @@ static int em28xx_v4l2_ioctl(struct inode *inode, struct file *filp,
1480 return ret; 1480 return ret;
1481} 1481}
1482 1482
1483static struct file_operations em28xx_v4l_fops = { 1483static const struct file_operations em28xx_v4l_fops = {
1484 .owner = THIS_MODULE, 1484 .owner = THIS_MODULE,
1485 .open = em28xx_v4l2_open, 1485 .open = em28xx_v4l2_open,
1486 .release = em28xx_v4l2_close, 1486 .release = em28xx_v4l2_close,
diff --git a/drivers/media/video/et61x251/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index 86e353b26b5..49792ae8c61 100644
--- a/drivers/media/video/et61x251/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -2454,7 +2454,7 @@ static int et61x251_ioctl(struct inode* inode, struct file* filp,
2454} 2454}
2455 2455
2456 2456
2457static struct file_operations et61x251_fops = { 2457static const struct file_operations et61x251_fops = {
2458 .owner = THIS_MODULE, 2458 .owner = THIS_MODULE,
2459 .open = et61x251_open, 2459 .open = et61x251_open,
2460 .release = et61x251_release, 2460 .release = et61x251_release,
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index 616a35da191..9528e10c282 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -1748,7 +1748,7 @@ static int meye_mmap(struct file *file, struct vm_area_struct *vma)
1748 return 0; 1748 return 0;
1749} 1749}
1750 1750
1751static struct file_operations meye_fops = { 1751static const struct file_operations meye_fops = {
1752 .owner = THIS_MODULE, 1752 .owner = THIS_MODULE,
1753 .open = meye_open, 1753 .open = meye_open,
1754 .release = meye_release, 1754 .release = meye_release,
diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index b4db2cbb5a8..e5edff1059a 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -4653,7 +4653,7 @@ ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
4653 return 0; 4653 return 0;
4654} 4654}
4655 4655
4656static struct file_operations ov511_fops = { 4656static const struct file_operations ov511_fops = {
4657 .owner = THIS_MODULE, 4657 .owner = THIS_MODULE,
4658 .open = ov51x_v4l1_open, 4658 .open = ov51x_v4l1_open,
4659 .release = ov51x_v4l1_close, 4659 .release = ov51x_v4l1_close,
diff --git a/drivers/media/video/pms.c b/drivers/media/video/pms.c
index 5d681fa8bcb..d38d3dc4a01 100644
--- a/drivers/media/video/pms.c
+++ b/drivers/media/video/pms.c
@@ -881,7 +881,7 @@ static ssize_t pms_read(struct file *file, char __user *buf,
881 return len; 881 return len;
882} 882}
883 883
884static struct file_operations pms_fops = { 884static const struct file_operations pms_fops = {
885 .owner = THIS_MODULE, 885 .owner = THIS_MODULE,
886 .open = video_exclusive_open, 886 .open = video_exclusive_open,
887 .release = video_exclusive_release, 887 .release = video_exclusive_release,
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index bb40e908597..6cf17080eb4 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -986,7 +986,7 @@ static unsigned int pvr2_v4l2_poll(struct file *file, poll_table *wait)
986} 986}
987 987
988 988
989static struct file_operations vdev_fops = { 989static const struct file_operations vdev_fops = {
990 .owner = THIS_MODULE, 990 .owner = THIS_MODULE,
991 .open = pvr2_v4l2_open, 991 .open = pvr2_v4l2_open,
992 .release = pvr2_v4l2_release, 992 .release = pvr2_v4l2_release,
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index a996aad7927..9825fd34810 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -152,7 +152,7 @@ static int pwc_video_ioctl(struct inode *inode, struct file *file,
152 unsigned int ioctlnr, unsigned long arg); 152 unsigned int ioctlnr, unsigned long arg);
153static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma); 153static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma);
154 154
155static struct file_operations pwc_fops = { 155static const struct file_operations pwc_fops = {
156 .owner = THIS_MODULE, 156 .owner = THIS_MODULE,
157 .open = pwc_video_open, 157 .open = pwc_video_open,
158 .release = pwc_video_close, 158 .release = pwc_video_close,
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index 77bb940a1a4..0b5d159895b 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -817,7 +817,7 @@ static void __exit cleanup_saa_5246a (void)
817module_init(init_saa_5246a); 817module_init(init_saa_5246a);
818module_exit(cleanup_saa_5246a); 818module_exit(cleanup_saa_5246a);
819 819
820static struct file_operations saa_fops = { 820static const struct file_operations saa_fops = {
821 .owner = THIS_MODULE, 821 .owner = THIS_MODULE,
822 .open = saa5246a_open, 822 .open = saa5246a_open,
823 .release = saa5246a_release, 823 .release = saa5246a_release,
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index bb3fb4387f6..3e84737878a 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -699,7 +699,7 @@ static void __exit cleanup_saa_5249 (void)
699module_init(init_saa_5249); 699module_init(init_saa_5249);
700module_exit(cleanup_saa_5249); 700module_exit(cleanup_saa_5249);
701 701
702static struct file_operations saa_fops = { 702static const struct file_operations saa_fops = {
703 .owner = THIS_MODULE, 703 .owner = THIS_MODULE,
704 .open = saa5249_open, 704 .open = saa5249_open,
705 .release = saa5249_release, 705 .release = saa5249_release,
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index daaae870a2c..f521603482c 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -319,7 +319,7 @@ static int ts_ioctl(struct inode *inode, struct file *file,
319 return video_usercopy(inode, file, cmd, arg, ts_do_ioctl); 319 return video_usercopy(inode, file, cmd, arg, ts_do_ioctl);
320} 320}
321 321
322static struct file_operations ts_fops = 322static const struct file_operations ts_fops =
323{ 323{
324 .owner = THIS_MODULE, 324 .owner = THIS_MODULE,
325 .open = ts_open, 325 .open = ts_open,
diff --git a/drivers/media/video/saa7134/saa7134-oss.c b/drivers/media/video/saa7134/saa7134-oss.c
index bfcb860d14c..72444f039e3 100644
--- a/drivers/media/video/saa7134/saa7134-oss.c
+++ b/drivers/media/video/saa7134/saa7134-oss.c
@@ -563,7 +563,7 @@ static unsigned int dsp_poll(struct file *file, struct poll_table_struct *wait)
563 return mask; 563 return mask;
564} 564}
565 565
566struct file_operations saa7134_dsp_fops = { 566const struct file_operations saa7134_dsp_fops = {
567 .owner = THIS_MODULE, 567 .owner = THIS_MODULE,
568 .open = dsp_open, 568 .open = dsp_open,
569 .release = dsp_release, 569 .release = dsp_release,
@@ -804,7 +804,7 @@ static int mixer_ioctl(struct inode *inode, struct file *file,
804 } 804 }
805} 805}
806 806
807struct file_operations saa7134_mixer_fops = { 807const struct file_operations saa7134_mixer_fops = {
808 .owner = THIS_MODULE, 808 .owner = THIS_MODULE,
809 .open = mixer_open, 809 .open = mixer_open,
810 .release = mixer_release, 810 .release = mixer_release,
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 830617ea81c..f2cb6305304 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -2336,7 +2336,7 @@ static int radio_ioctl(struct inode *inode, struct file *file,
2336 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl); 2336 return video_usercopy(inode, file, cmd, arg, radio_do_ioctl);
2337} 2337}
2338 2338
2339static struct file_operations video_fops = 2339static const struct file_operations video_fops =
2340{ 2340{
2341 .owner = THIS_MODULE, 2341 .owner = THIS_MODULE,
2342 .open = video_open, 2342 .open = video_open,
@@ -2349,7 +2349,7 @@ static struct file_operations video_fops =
2349 .llseek = no_llseek, 2349 .llseek = no_llseek,
2350}; 2350};
2351 2351
2352static struct file_operations radio_fops = 2352static const struct file_operations radio_fops =
2353{ 2353{
2354 .owner = THIS_MODULE, 2354 .owner = THIS_MODULE,
2355 .open = video_open, 2355 .open = video_open,
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index e88ad7b40c4..88cd1297df1 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -683,8 +683,8 @@ int saa_dsp_writel(struct saa7134_dev *dev, int reg, u32 value);
683/* ----------------------------------------------------------- */ 683/* ----------------------------------------------------------- */
684/* saa7134-oss.c */ 684/* saa7134-oss.c */
685 685
686extern struct file_operations saa7134_dsp_fops; 686extern const struct file_operations saa7134_dsp_fops;
687extern struct file_operations saa7134_mixer_fops; 687extern const struct file_operations saa7134_mixer_fops;
688 688
689int saa7134_oss_init1(struct saa7134_dev *dev); 689int saa7134_oss_init1(struct saa7134_dev *dev);
690int saa7134_oss_fini(struct saa7134_dev *dev); 690int saa7134_oss_fini(struct saa7134_dev *dev);
diff --git a/drivers/media/video/se401.c b/drivers/media/video/se401.c
index 7aeec574d7c..038448f5a97 100644
--- a/drivers/media/video/se401.c
+++ b/drivers/media/video/se401.c
@@ -1185,7 +1185,7 @@ static int se401_mmap(struct file *file, struct vm_area_struct *vma)
1185 return 0; 1185 return 0;
1186} 1186}
1187 1187
1188static struct file_operations se401_fops = { 1188static const struct file_operations se401_fops = {
1189 .owner = THIS_MODULE, 1189 .owner = THIS_MODULE,
1190 .open = se401_open, 1190 .open = se401_open,
1191 .release = se401_close, 1191 .release = se401_close,
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 18458d46c0f..04d4c8f28b8 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -2736,7 +2736,7 @@ static int sn9c102_ioctl(struct inode* inode, struct file* filp,
2736 2736
2737/*****************************************************************************/ 2737/*****************************************************************************/
2738 2738
2739static struct file_operations sn9c102_fops = { 2739static const struct file_operations sn9c102_fops = {
2740 .owner = THIS_MODULE, 2740 .owner = THIS_MODULE,
2741 .open = sn9c102_open, 2741 .open = sn9c102_open,
2742 .release = sn9c102_release, 2742 .release = sn9c102_release,
diff --git a/drivers/media/video/stradis.c b/drivers/media/video/stradis.c
index 525d81288d5..3e736be5de8 100644
--- a/drivers/media/video/stradis.c
+++ b/drivers/media/video/stradis.c
@@ -1901,7 +1901,7 @@ static int saa_release(struct inode *inode, struct file *file)
1901 return 0; 1901 return 0;
1902} 1902}
1903 1903
1904static struct file_operations saa_fops = { 1904static const struct file_operations saa_fops = {
1905 .owner = THIS_MODULE, 1905 .owner = THIS_MODULE,
1906 .open = saa_open, 1906 .open = saa_open,
1907 .release = saa_release, 1907 .release = saa_release,
diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
index a1ec3aca3f9..bf3aa8d2d57 100644
--- a/drivers/media/video/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -1380,7 +1380,7 @@ static ssize_t stv680_read (struct file *file, char __user *buf,
1380 return realcount; 1380 return realcount;
1381} /* stv680_read */ 1381} /* stv680_read */
1382 1382
1383static struct file_operations stv680_fops = { 1383static const struct file_operations stv680_fops = {
1384 .owner = THIS_MODULE, 1384 .owner = THIS_MODULE,
1385 .open = stv_open, 1385 .open = stv_open,
1386 .release = stv_close, 1386 .release = stv_close,
diff --git a/drivers/media/video/tvmixer.c b/drivers/media/video/tvmixer.c
index 1654576de10..e2747bd373f 100644
--- a/drivers/media/video/tvmixer.c
+++ b/drivers/media/video/tvmixer.c
@@ -228,7 +228,7 @@ static struct i2c_driver driver = {
228 .detach_client = tvmixer_clients, 228 .detach_client = tvmixer_clients,
229}; 229};
230 230
231static struct file_operations tvmixer_fops = { 231static const struct file_operations tvmixer_fops = {
232 .owner = THIS_MODULE, 232 .owner = THIS_MODULE,
233 .llseek = no_llseek, 233 .llseek = no_llseek,
234 .ioctl = tvmixer_ioctl, 234 .ioctl = tvmixer_ioctl,
diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
index b560c9d7c51..d34d8c8b737 100644
--- a/drivers/media/video/usbvideo/usbvideo.c
+++ b/drivers/media/video/usbvideo/usbvideo.c
@@ -945,7 +945,7 @@ static int usbvideo_find_struct(struct usbvideo *cams)
945 return rv; 945 return rv;
946} 946}
947 947
948static struct file_operations usbvideo_fops = { 948static const struct file_operations usbvideo_fops = {
949 .owner = THIS_MODULE, 949 .owner = THIS_MODULE,
950 .open = usbvideo_v4l_open, 950 .open = usbvideo_v4l_open,
951 .release =usbvideo_v4l_close, 951 .release =usbvideo_v4l_close,
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/media/video/usbvideo/vicam.c
index 08f9559a6bf..876fd276824 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -1234,7 +1234,7 @@ static inline void vicam_create_proc_entry(struct vicam_camera *cam) { }
1234static inline void vicam_destroy_proc_entry(void *ptr) { } 1234static inline void vicam_destroy_proc_entry(void *ptr) { }
1235#endif 1235#endif
1236 1236
1237static struct file_operations vicam_fops = { 1237static const struct file_operations vicam_fops = {
1238 .owner = THIS_MODULE, 1238 .owner = THIS_MODULE,
1239 .open = vicam_open, 1239 .open = vicam_open,
1240 .release = vicam_close, 1240 .release = vicam_close,
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index bdd6301d2a4..4eb7330b96f 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -1475,7 +1475,7 @@ static int usbvision_vbi_ioctl(struct inode *inode, struct file *file,
1475// 1475//
1476 1476
1477// Video template 1477// Video template
1478static struct file_operations usbvision_fops = { 1478static const struct file_operations usbvision_fops = {
1479 .owner = THIS_MODULE, 1479 .owner = THIS_MODULE,
1480 .open = usbvision_v4l2_open, 1480 .open = usbvision_v4l2_open,
1481 .release = usbvision_v4l2_close, 1481 .release = usbvision_v4l2_close,
@@ -1496,7 +1496,7 @@ static struct video_device usbvision_video_template = {
1496 1496
1497 1497
1498// Radio template 1498// Radio template
1499static struct file_operations usbvision_radio_fops = { 1499static const struct file_operations usbvision_radio_fops = {
1500 .owner = THIS_MODULE, 1500 .owner = THIS_MODULE,
1501 .open = usbvision_radio_open, 1501 .open = usbvision_radio_open,
1502 .release = usbvision_radio_close, 1502 .release = usbvision_radio_close,
@@ -1517,7 +1517,7 @@ static struct video_device usbvision_radio_template=
1517 1517
1518 1518
1519// vbi template 1519// vbi template
1520static struct file_operations usbvision_vbi_fops = { 1520static const struct file_operations usbvision_vbi_fops = {
1521 .owner = THIS_MODULE, 1521 .owner = THIS_MODULE,
1522 .open = usbvision_vbi_open, 1522 .open = usbvision_vbi_open,
1523 .release = usbvision_vbi_close, 1523 .release = usbvision_vbi_close,
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index 6a0e8ca7294..30c3822692f 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -1561,7 +1561,7 @@ out:
1561} 1561}
1562 1562
1563 1563
1564static struct file_operations video_fops; 1564static const struct file_operations video_fops;
1565 1565
1566/** 1566/**
1567 * video_register_device - register video4linux devices 1567 * video_register_device - register video4linux devices
@@ -1709,7 +1709,7 @@ void video_unregister_device(struct video_device *vfd)
1709/* 1709/*
1710 * Video fs operations 1710 * Video fs operations
1711 */ 1711 */
1712static struct file_operations video_fops= 1712static const struct file_operations video_fops=
1713{ 1713{
1714 .owner = THIS_MODULE, 1714 .owner = THIS_MODULE,
1715 .llseek = no_llseek, 1715 .llseek = no_llseek,
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index a373c142e74..0c658b74f2c 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -4390,7 +4390,7 @@ static int vino_ioctl(struct inode *inode, struct file *file,
4390// __initdata 4390// __initdata
4391static int vino_init_stage = 0; 4391static int vino_init_stage = 0;
4392 4392
4393static struct file_operations vino_fops = { 4393static const struct file_operations vino_fops = {
4394 .owner = THIS_MODULE, 4394 .owner = THIS_MODULE,
4395 .open = vino_open, 4395 .open = vino_open,
4396 .release = vino_close, 4396 .release = vino_close,
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index d4cf5566673..cfb6b1f0402 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -1292,7 +1292,7 @@ vivi_mmap(struct file *file, struct vm_area_struct * vma)
1292 return ret; 1292 return ret;
1293} 1293}
1294 1294
1295static struct file_operations vivi_fops = { 1295static const struct file_operations vivi_fops = {
1296 .owner = THIS_MODULE, 1296 .owner = THIS_MODULE,
1297 .open = vivi_open, 1297 .open = vivi_open,
1298 .release = vivi_release, 1298 .release = vivi_release,
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c
index 8d14f308f17..47366408637 100644
--- a/drivers/media/video/w9966.c
+++ b/drivers/media/video/w9966.c
@@ -183,7 +183,7 @@ static int w9966_v4l_ioctl(struct inode *inode, struct file *file,
183static ssize_t w9966_v4l_read(struct file *file, char __user *buf, 183static ssize_t w9966_v4l_read(struct file *file, char __user *buf,
184 size_t count, loff_t *ppos); 184 size_t count, loff_t *ppos);
185 185
186static struct file_operations w9966_fops = { 186static const struct file_operations w9966_fops = {
187 .owner = THIS_MODULE, 187 .owner = THIS_MODULE,
188 .open = video_exclusive_open, 188 .open = video_exclusive_open,
189 .release = video_exclusive_release, 189 .release = video_exclusive_release,
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index 9f403af7b04..6e64af293be 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -399,7 +399,7 @@ MODULE_PARM_DESC(specific_debug,
399 ****************************************************************************/ 399 ****************************************************************************/
400 400
401/* Video4linux interface */ 401/* Video4linux interface */
402static struct file_operations w9968cf_fops; 402static const struct file_operations w9968cf_fops;
403static int w9968cf_open(struct inode*, struct file*); 403static int w9968cf_open(struct inode*, struct file*);
404static int w9968cf_release(struct inode*, struct file*); 404static int w9968cf_release(struct inode*, struct file*);
405static int w9968cf_mmap(struct file*, struct vm_area_struct*); 405static int w9968cf_mmap(struct file*, struct vm_area_struct*);
@@ -3466,7 +3466,7 @@ ioctl_fail:
3466} 3466}
3467 3467
3468 3468
3469static struct file_operations w9968cf_fops = { 3469static const struct file_operations w9968cf_fops = {
3470 .owner = THIS_MODULE, 3470 .owner = THIS_MODULE,
3471 .open = w9968cf_open, 3471 .open = w9968cf_open,
3472 .release = w9968cf_release, 3472 .release = w9968cf_release,
diff --git a/drivers/media/video/zc0301/zc0301_core.c b/drivers/media/video/zc0301/zc0301_core.c
index 52d0f759ee0..8da7f15f629 100644
--- a/drivers/media/video/zc0301/zc0301_core.c
+++ b/drivers/media/video/zc0301/zc0301_core.c
@@ -1871,7 +1871,7 @@ static int zc0301_ioctl(struct inode* inode, struct file* filp,
1871} 1871}
1872 1872
1873 1873
1874static struct file_operations zc0301_fops = { 1874static const struct file_operations zc0301_fops = {
1875 .owner = THIS_MODULE, 1875 .owner = THIS_MODULE,
1876 .open = zc0301_open, 1876 .open = zc0301_open,
1877 .release = zc0301_release, 1877 .release = zc0301_release,
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index 862a984c215..07432373335 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -562,7 +562,6 @@ jpg_fbuffer_alloc (struct file *file)
562 jpg_fbuffer_free(file); 562 jpg_fbuffer_free(file);
563 return -ENOBUFS; 563 return -ENOBUFS;
564 } 564 }
565 memset((void *) mem, 0, PAGE_SIZE);
566 fh->jpg_buffers.buffer[i].frag_tab = (u32 *) mem; 565 fh->jpg_buffers.buffer[i].frag_tab = (u32 *) mem;
567 fh->jpg_buffers.buffer[i].frag_tab_bus = 566 fh->jpg_buffers.buffer[i].frag_tab_bus =
568 virt_to_bus((void *) mem); 567 virt_to_bus((void *) mem);
@@ -4680,7 +4679,7 @@ zoran_mmap (struct file *file,
4680 return 0; 4679 return 0;
4681} 4680}
4682 4681
4683static struct file_operations zoran_fops = { 4682static const struct file_operations zoran_fops = {
4684 .owner = THIS_MODULE, 4683 .owner = THIS_MODULE,
4685 .open = zoran_open, 4684 .open = zoran_open,
4686 .release = zoran_close, 4685 .release = zoran_close,
diff --git a/drivers/media/video/zoran_procfs.c b/drivers/media/video/zoran_procfs.c
index c374c76b375..446ae8d5c3d 100644
--- a/drivers/media/video/zoran_procfs.c
+++ b/drivers/media/video/zoran_procfs.c
@@ -186,7 +186,7 @@ static ssize_t zoran_write(struct file *file, const char __user *buffer,
186 return count; 186 return count;
187} 187}
188 188
189static struct file_operations zoran_operations = { 189static const struct file_operations zoran_operations = {
190 .open = zoran_open, 190 .open = zoran_open,
191 .read = seq_read, 191 .read = seq_read,
192 .write = zoran_write, 192 .write = zoran_write,
diff --git a/drivers/message/fusion/Kconfig b/drivers/message/fusion/Kconfig
index ea31d847051..71037f91c22 100644
--- a/drivers/message/fusion/Kconfig
+++ b/drivers/message/fusion/Kconfig
@@ -66,7 +66,7 @@ config FUSION_MAX_SGE
66 66
67config FUSION_CTL 67config FUSION_CTL
68 tristate "Fusion MPT misc device (ioctl) driver" 68 tristate "Fusion MPT misc device (ioctl) driver"
69 depends on FUSION_SPI || FUSION_FC 69 depends on FUSION_SPI || FUSION_FC || FUSION_SAS
70 ---help--- 70 ---help---
71 The Fusion MPT misc device driver provides specialized control 71 The Fusion MPT misc device driver provides specialized control
72 of MPT adapters via system ioctl calls. Use of ioctl calls to 72 of MPT adapters via system ioctl calls. Use of ioctl calls to
diff --git a/drivers/message/fusion/Makefile b/drivers/message/fusion/Makefile
index 341691390e8..6003b46c843 100644
--- a/drivers/message/fusion/Makefile
+++ b/drivers/message/fusion/Makefile
@@ -8,6 +8,9 @@
8#EXTRA_CFLAGS += -DMPT_DEBUG_INIT 8#EXTRA_CFLAGS += -DMPT_DEBUG_INIT
9#EXTRA_CFLAGS += -DMPT_DEBUG_EXIT 9#EXTRA_CFLAGS += -DMPT_DEBUG_EXIT
10#EXTRA_CFLAGS += -DMPT_DEBUG_FAIL 10#EXTRA_CFLAGS += -DMPT_DEBUG_FAIL
11#EXTRA_CFLAGS += -DMPT_DEBUG_DV
12#EXTRA_CFLAGS += -DMPT_DEBUG_TM
13#EXTRA_CFLAGS += -DMPT_DEBUG_REPLY
11 14
12# 15#
13# driver/module specifics... 16# driver/module specifics...
@@ -20,11 +23,7 @@
20#CFLAGS_mptbase.o += -DMPT_DEBUG_RESET 23#CFLAGS_mptbase.o += -DMPT_DEBUG_RESET
21# 24#
22# For mptscsih: 25# For mptscsih:
23#CFLAGS_mptscsih.o += -DMPT_DEBUG_DV
24#CFLAGS_mptscsih.o += -DMPT_DEBUG_NEGO
25#CFLAGS_mptscsih.o += -DMPT_DEBUG_TM
26#CFLAGS_mptscsih.o += -DMPT_DEBUG_SCSI 26#CFLAGS_mptscsih.o += -DMPT_DEBUG_SCSI
27#CFLAGS_mptscsih.o += -DMPT_DEBUG_REPLY
28# 27#
29# For mptctl: 28# For mptctl:
30#CFLAGS_mptctl.o += -DMPT_DEBUG_IOCTL 29#CFLAGS_mptctl.o += -DMPT_DEBUG_IOCTL
diff --git a/drivers/message/fusion/lsi/mpi.h b/drivers/message/fusion/lsi/mpi.h
index 81ad77622da..75223bf24ae 100644
--- a/drivers/message/fusion/lsi/mpi.h
+++ b/drivers/message/fusion/lsi/mpi.h
@@ -1,12 +1,12 @@
1/* 1/*
2 * Copyright (c) 2000-2005 LSI Logic Corporation. 2 * Copyright (c) 2000-2006 LSI Logic Corporation.
3 * 3 *
4 * 4 *
5 * Name: mpi.h 5 * Name: mpi.h
6 * Title: MPI Message independent structures and definitions 6 * Title: MPI Message independent structures and definitions
7 * Creation Date: July 27, 2000 7 * Creation Date: July 27, 2000
8 * 8 *
9 * mpi.h Version: 01.05.11 9 * mpi.h Version: 01.05.12
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -77,6 +77,7 @@
77 * 08-03-05 01.05.09 Bumped MPI_HEADER_VERSION_UNIT. 77 * 08-03-05 01.05.09 Bumped MPI_HEADER_VERSION_UNIT.
78 * 08-30-05 01.05.10 Added 2 new IOCStatus codes for Target. 78 * 08-30-05 01.05.10 Added 2 new IOCStatus codes for Target.
79 * 03-27-06 01.05.11 Bumped MPI_HEADER_VERSION_UNIT. 79 * 03-27-06 01.05.11 Bumped MPI_HEADER_VERSION_UNIT.
80 * 10-11-06 01.05.12 Bumped MPI_HEADER_VERSION_UNIT.
80 * -------------------------------------------------------------------------- 81 * --------------------------------------------------------------------------
81 */ 82 */
82 83
@@ -107,7 +108,7 @@
107/* Note: The major versions of 0xe0 through 0xff are reserved */ 108/* Note: The major versions of 0xe0 through 0xff are reserved */
108 109
109/* versioning for this MPI header set */ 110/* versioning for this MPI header set */
110#define MPI_HEADER_VERSION_UNIT (0x0D) 111#define MPI_HEADER_VERSION_UNIT (0x0E)
111#define MPI_HEADER_VERSION_DEV (0x00) 112#define MPI_HEADER_VERSION_DEV (0x00)
112#define MPI_HEADER_VERSION_UNIT_MASK (0xFF00) 113#define MPI_HEADER_VERSION_UNIT_MASK (0xFF00)
113#define MPI_HEADER_VERSION_UNIT_SHIFT (8) 114#define MPI_HEADER_VERSION_UNIT_SHIFT (8)
diff --git a/drivers/message/fusion/lsi/mpi_cnfg.h b/drivers/message/fusion/lsi/mpi_cnfg.h
index 47e13e360c1..0e4c8e77a81 100644
--- a/drivers/message/fusion/lsi/mpi_cnfg.h
+++ b/drivers/message/fusion/lsi/mpi_cnfg.h
@@ -1,12 +1,12 @@
1/* 1/*
2 * Copyright (c) 2000-2005 LSI Logic Corporation. 2 * Copyright (c) 2000-2006 LSI Logic Corporation.
3 * 3 *
4 * 4 *
5 * Name: mpi_cnfg.h 5 * Name: mpi_cnfg.h
6 * Title: MPI Config message, structures, and Pages 6 * Title: MPI Config message, structures, and Pages
7 * Creation Date: July 27, 2000 7 * Creation Date: July 27, 2000
8 * 8 *
9 * mpi_cnfg.h Version: 01.05.12 9 * mpi_cnfg.h Version: 01.05.13
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -276,6 +276,23 @@
276 * Added AdditionalControlFlags, MaxTargetPortConnectTime, 276 * Added AdditionalControlFlags, MaxTargetPortConnectTime,
277 * ReportDeviceMissingDelay, and IODeviceMissingDelay 277 * ReportDeviceMissingDelay, and IODeviceMissingDelay
278 * fields to SAS IO Unit Page 1. 278 * fields to SAS IO Unit Page 1.
279 * 10-11-06 01.05.13 Added NumForceWWID field and ForceWWID array to
280 * Manufacturing Page 5.
281 * Added Manufacturing pages 8 through 10.
282 * Added defines for supported metadata size bits in
283 * CapabilitiesFlags field of IOC Page 6.
284 * Added defines for metadata size bits in VolumeSettings
285 * field of RAID Volume Page 0.
286 * Added SATA Link Reset settings, Enable SATA Asynchronous
287 * Notification bit, and HideNonZeroAttachedPhyIdentifiers
288 * bit to AdditionalControlFlags field of SAS IO Unit
289 * Page 1.
290 * Added defines for Enclosure Devices Unmapped and
291 * Device Limit Exceeded bits in Status field of SAS IO
292 * Unit Page 2.
293 * Added more AccessStatus values for SAS Device Page 0.
294 * Added bit for SATA Asynchronous Notification Support in
295 * Flags field of SAS Device Page 0.
279 * -------------------------------------------------------------------------- 296 * --------------------------------------------------------------------------
280 */ 297 */
281 298
@@ -654,17 +671,24 @@ typedef struct _CONFIG_PAGE_MANUFACTURING_4
654#define MPI_MANPAGE4_IR_NO_MIX_SAS_SATA (0x01) 671#define MPI_MANPAGE4_IR_NO_MIX_SAS_SATA (0x01)
655 672
656 673
674#ifndef MPI_MANPAGE5_NUM_FORCEWWID
675#define MPI_MANPAGE5_NUM_FORCEWWID (1)
676#endif
677
657typedef struct _CONFIG_PAGE_MANUFACTURING_5 678typedef struct _CONFIG_PAGE_MANUFACTURING_5
658{ 679{
659 CONFIG_PAGE_HEADER Header; /* 00h */ 680 CONFIG_PAGE_HEADER Header; /* 00h */
660 U64 BaseWWID; /* 04h */ 681 U64 BaseWWID; /* 04h */
661 U8 Flags; /* 0Ch */ 682 U8 Flags; /* 0Ch */
662 U8 Reserved1; /* 0Dh */ 683 U8 NumForceWWID; /* 0Dh */
663 U16 Reserved2; /* 0Eh */ 684 U16 Reserved2; /* 0Eh */
685 U32 Reserved3; /* 10h */
686 U32 Reserved4; /* 14h */
687 U64 ForceWWID[MPI_MANPAGE5_NUM_FORCEWWID]; /* 18h */
664} CONFIG_PAGE_MANUFACTURING_5, MPI_POINTER PTR_CONFIG_PAGE_MANUFACTURING_5, 688} CONFIG_PAGE_MANUFACTURING_5, MPI_POINTER PTR_CONFIG_PAGE_MANUFACTURING_5,
665 ManufacturingPage5_t, MPI_POINTER pManufacturingPage5_t; 689 ManufacturingPage5_t, MPI_POINTER pManufacturingPage5_t;
666 690
667#define MPI_MANUFACTURING5_PAGEVERSION (0x01) 691#define MPI_MANUFACTURING5_PAGEVERSION (0x02)
668 692
669/* defines for the Flags field */ 693/* defines for the Flags field */
670#define MPI_MANPAGE5_TWO_WWID_PER_PHY (0x01) 694#define MPI_MANPAGE5_TWO_WWID_PER_PHY (0x01)
@@ -740,6 +764,36 @@ typedef struct _CONFIG_PAGE_MANUFACTURING_7
740#define MPI_MANPAGE7_FLAG_USE_SLOT_INFO (0x00000001) 764#define MPI_MANPAGE7_FLAG_USE_SLOT_INFO (0x00000001)
741 765
742 766
767typedef struct _CONFIG_PAGE_MANUFACTURING_8
768{
769 CONFIG_PAGE_HEADER Header; /* 00h */
770 U32 ProductSpecificInfo;/* 04h */
771} CONFIG_PAGE_MANUFACTURING_8, MPI_POINTER PTR_CONFIG_PAGE_MANUFACTURING_8,
772 ManufacturingPage8_t, MPI_POINTER pManufacturingPage8_t;
773
774#define MPI_MANUFACTURING8_PAGEVERSION (0x00)
775
776
777typedef struct _CONFIG_PAGE_MANUFACTURING_9
778{
779 CONFIG_PAGE_HEADER Header; /* 00h */
780 U32 ProductSpecificInfo;/* 04h */
781} CONFIG_PAGE_MANUFACTURING_9, MPI_POINTER PTR_CONFIG_PAGE_MANUFACTURING_9,
782 ManufacturingPage9_t, MPI_POINTER pManufacturingPage9_t;
783
784#define MPI_MANUFACTURING6_PAGEVERSION (0x00)
785
786
787typedef struct _CONFIG_PAGE_MANUFACTURING_10
788{
789 CONFIG_PAGE_HEADER Header; /* 00h */
790 U32 ProductSpecificInfo;/* 04h */
791} CONFIG_PAGE_MANUFACTURING_10, MPI_POINTER PTR_CONFIG_PAGE_MANUFACTURING_10,
792 ManufacturingPage10_t, MPI_POINTER pManufacturingPage10_t;
793
794#define MPI_MANUFACTURING10_PAGEVERSION (0x00)
795
796
743/**************************************************************************** 797/****************************************************************************
744* IO Unit Config Pages 798* IO Unit Config Pages
745****************************************************************************/ 799****************************************************************************/
@@ -1080,10 +1134,14 @@ typedef struct _CONFIG_PAGE_IOC_6
1080} CONFIG_PAGE_IOC_6, MPI_POINTER PTR_CONFIG_PAGE_IOC_6, 1134} CONFIG_PAGE_IOC_6, MPI_POINTER PTR_CONFIG_PAGE_IOC_6,
1081 IOCPage6_t, MPI_POINTER pIOCPage6_t; 1135 IOCPage6_t, MPI_POINTER pIOCPage6_t;
1082 1136
1083#define MPI_IOCPAGE6_PAGEVERSION (0x00) 1137#define MPI_IOCPAGE6_PAGEVERSION (0x01)
1084 1138
1085/* IOC Page 6 Capabilities Flags */ 1139/* IOC Page 6 Capabilities Flags */
1086 1140
1141#define MPI_IOCPAGE6_CAP_FLAGS_MASK_METADATA_SIZE (0x00000006)
1142#define MPI_IOCPAGE6_CAP_FLAGS_64MB_METADATA_SIZE (0x00000000)
1143#define MPI_IOCPAGE6_CAP_FLAGS_512MB_METADATA_SIZE (0x00000002)
1144
1087#define MPI_IOCPAGE6_CAP_FLAGS_GLOBAL_HOT_SPARE (0x00000001) 1145#define MPI_IOCPAGE6_CAP_FLAGS_GLOBAL_HOT_SPARE (0x00000001)
1088 1146
1089 1147
@@ -2160,6 +2218,11 @@ typedef struct _RAID_VOL0_SETTINGS
2160#define MPI_RAIDVOL0_SETTING_AUTO_CONFIGURE (0x0004) 2218#define MPI_RAIDVOL0_SETTING_AUTO_CONFIGURE (0x0004)
2161#define MPI_RAIDVOL0_SETTING_PRIORITY_RESYNC (0x0008) 2219#define MPI_RAIDVOL0_SETTING_PRIORITY_RESYNC (0x0008)
2162#define MPI_RAIDVOL0_SETTING_FAST_DATA_SCRUBBING_0102 (0x0020) /* obsolete */ 2220#define MPI_RAIDVOL0_SETTING_FAST_DATA_SCRUBBING_0102 (0x0020) /* obsolete */
2221
2222#define MPI_RAIDVOL0_SETTING_MASK_METADATA_SIZE (0x00C0)
2223#define MPI_RAIDVOL0_SETTING_64MB_METADATA_SIZE (0x0000)
2224#define MPI_RAIDVOL0_SETTING_512MB_METADATA_SIZE (0x0040)
2225
2163#define MPI_RAIDVOL0_SETTING_USE_PRODUCT_ID_SUFFIX (0x0010) 2226#define MPI_RAIDVOL0_SETTING_USE_PRODUCT_ID_SUFFIX (0x0010)
2164#define MPI_RAIDVOL0_SETTING_USE_DEFAULTS (0x8000) 2227#define MPI_RAIDVOL0_SETTING_USE_DEFAULTS (0x8000)
2165 2228
@@ -2203,7 +2266,7 @@ typedef struct _CONFIG_PAGE_RAID_VOL_0
2203} CONFIG_PAGE_RAID_VOL_0, MPI_POINTER PTR_CONFIG_PAGE_RAID_VOL_0, 2266} CONFIG_PAGE_RAID_VOL_0, MPI_POINTER PTR_CONFIG_PAGE_RAID_VOL_0,
2204 RaidVolumePage0_t, MPI_POINTER pRaidVolumePage0_t; 2267 RaidVolumePage0_t, MPI_POINTER pRaidVolumePage0_t;
2205 2268
2206#define MPI_RAIDVOLPAGE0_PAGEVERSION (0x06) 2269#define MPI_RAIDVOLPAGE0_PAGEVERSION (0x07)
2207 2270
2208/* values for RAID Volume Page 0 InactiveStatus field */ 2271/* values for RAID Volume Page 0 InactiveStatus field */
2209#define MPI_RAIDVOLPAGE0_UNKNOWN_INACTIVE (0x00) 2272#define MPI_RAIDVOLPAGE0_UNKNOWN_INACTIVE (0x00)
@@ -2518,7 +2581,7 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_1
2518} CONFIG_PAGE_SAS_IO_UNIT_1, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_1, 2581} CONFIG_PAGE_SAS_IO_UNIT_1, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_1,
2519 SasIOUnitPage1_t, MPI_POINTER pSasIOUnitPage1_t; 2582 SasIOUnitPage1_t, MPI_POINTER pSasIOUnitPage1_t;
2520 2583
2521#define MPI_SASIOUNITPAGE1_PAGEVERSION (0x06) 2584#define MPI_SASIOUNITPAGE1_PAGEVERSION (0x07)
2522 2585
2523/* values for SAS IO Unit Page 1 ControlFlags */ 2586/* values for SAS IO Unit Page 1 ControlFlags */
2524#define MPI_SAS_IOUNIT1_CONTROL_DEVICE_SELF_TEST (0x8000) 2587#define MPI_SAS_IOUNIT1_CONTROL_DEVICE_SELF_TEST (0x8000)
@@ -2544,7 +2607,13 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_1
2544#define MPI_SAS_IOUNIT1_CONTROL_CLEAR_AFFILIATION (0x0001) 2607#define MPI_SAS_IOUNIT1_CONTROL_CLEAR_AFFILIATION (0x0001)
2545 2608
2546/* values for SAS IO Unit Page 1 AdditionalControlFlags */ 2609/* values for SAS IO Unit Page 1 AdditionalControlFlags */
2547#define MPI_SAS_IOUNIT1_ACONTROL_ALLOW_TABLE_TO_TABLE (0x0001) 2610#define MPI_SAS_IOUNIT1_ACONTROL_SATA_ASYNCHROUNOUS_NOTIFICATION (0x0040)
2611#define MPI_SAS_IOUNIT1_ACONTROL_HIDE_NONZERO_ATTACHED_PHY_IDENT (0x0020)
2612#define MPI_SAS_IOUNIT1_ACONTROL_PORT_ENABLE_ONLY_SATA_LINK_RESET (0x0010)
2613#define MPI_SAS_IOUNIT1_ACONTROL_OTHER_AFFILIATION_SATA_LINK_RESET (0x0008)
2614#define MPI_SAS_IOUNIT1_ACONTROL_SELF_AFFILIATION_SATA_LINK_RESET (0x0004)
2615#define MPI_SAS_IOUNIT1_ACONTROL_NO_AFFILIATION_SATA_LINK_RESET (0x0002)
2616#define MPI_SAS_IOUNIT1_ACONTROL_ALLOW_TABLE_TO_TABLE (0x0001)
2548 2617
2549/* defines for SAS IO Unit Page 1 ReportDeviceMissingDelay */ 2618/* defines for SAS IO Unit Page 1 ReportDeviceMissingDelay */
2550#define MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK (0x7F) 2619#define MPI_SAS_IOUNIT1_REPORT_MISSING_TIMEOUT_MASK (0x7F)
@@ -2585,9 +2654,11 @@ typedef struct _CONFIG_PAGE_SAS_IO_UNIT_2
2585} CONFIG_PAGE_SAS_IO_UNIT_2, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_2, 2654} CONFIG_PAGE_SAS_IO_UNIT_2, MPI_POINTER PTR_CONFIG_PAGE_SAS_IO_UNIT_2,
2586 SasIOUnitPage2_t, MPI_POINTER pSasIOUnitPage2_t; 2655 SasIOUnitPage2_t, MPI_POINTER pSasIOUnitPage2_t;
2587 2656
2588#define MPI_SASIOUNITPAGE2_PAGEVERSION (0x05) 2657#define MPI_SASIOUNITPAGE2_PAGEVERSION (0x06)
2589 2658
2590/* values for SAS IO Unit Page 2 Status field */ 2659/* values for SAS IO Unit Page 2 Status field */
2660#define MPI_SAS_IOUNIT2_STATUS_DEVICE_LIMIT_EXCEEDED (0x08)
2661#define MPI_SAS_IOUNIT2_STATUS_ENCLOSURE_DEVICES_UNMAPPED (0x04)
2591#define MPI_SAS_IOUNIT2_STATUS_DISABLED_PERSISTENT_MAPPINGS (0x02) 2662#define MPI_SAS_IOUNIT2_STATUS_DISABLED_PERSISTENT_MAPPINGS (0x02)
2592#define MPI_SAS_IOUNIT2_STATUS_FULL_PERSISTENT_MAPPINGS (0x01) 2663#define MPI_SAS_IOUNIT2_STATUS_FULL_PERSISTENT_MAPPINGS (0x01)
2593 2664
@@ -2739,24 +2810,38 @@ typedef struct _CONFIG_PAGE_SAS_DEVICE_0
2739} CONFIG_PAGE_SAS_DEVICE_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_DEVICE_0, 2810} CONFIG_PAGE_SAS_DEVICE_0, MPI_POINTER PTR_CONFIG_PAGE_SAS_DEVICE_0,
2740 SasDevicePage0_t, MPI_POINTER pSasDevicePage0_t; 2811 SasDevicePage0_t, MPI_POINTER pSasDevicePage0_t;
2741 2812
2742#define MPI_SASDEVICE0_PAGEVERSION (0x04) 2813#define MPI_SASDEVICE0_PAGEVERSION (0x05)
2743 2814
2744/* values for SAS Device Page 0 AccessStatus field */ 2815/* values for SAS Device Page 0 AccessStatus field */
2745#define MPI_SAS_DEVICE0_ASTATUS_NO_ERRORS (0x00) 2816#define MPI_SAS_DEVICE0_ASTATUS_NO_ERRORS (0x00)
2746#define MPI_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED (0x01) 2817#define MPI_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED (0x01)
2747#define MPI_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED (0x02) 2818#define MPI_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED (0x02)
2819#define MPI_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT (0x03)
2820/* specific values for SATA Init failures */
2821#define MPI_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN (0x10)
2822#define MPI_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT (0x11)
2823#define MPI_SAS_DEVICE0_ASTATUS_SIF_DIAG (0x12)
2824#define MPI_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION (0x13)
2825#define MPI_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER (0x14)
2826#define MPI_SAS_DEVICE0_ASTATUS_SIF_PIO_SN (0x15)
2827#define MPI_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN (0x16)
2828#define MPI_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN (0x17)
2829#define MPI_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION (0x18)
2830#define MPI_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE (0x19)
2831#define MPI_SAS_DEVICE0_ASTATUS_SIF_MAX (0x1F)
2748 2832
2749/* values for SAS Device Page 0 Flags field */ 2833/* values for SAS Device Page 0 Flags field */
2750#define MPI_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE (0x0200) 2834#define MPI_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY (0x0400)
2751#define MPI_SAS_DEVICE0_FLAGS_UNSUPPORTED_DEVICE (0x0100) 2835#define MPI_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE (0x0200)
2752#define MPI_SAS_DEVICE0_FLAGS_SATA_48BIT_LBA_SUPPORTED (0x0080) 2836#define MPI_SAS_DEVICE0_FLAGS_UNSUPPORTED_DEVICE (0x0100)
2753#define MPI_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED (0x0040) 2837#define MPI_SAS_DEVICE0_FLAGS_SATA_48BIT_LBA_SUPPORTED (0x0080)
2754#define MPI_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED (0x0020) 2838#define MPI_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED (0x0040)
2755#define MPI_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED (0x0010) 2839#define MPI_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED (0x0020)
2756#define MPI_SAS_DEVICE0_FLAGS_PORT_SELECTOR_ATTACH (0x0008) 2840#define MPI_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED (0x0010)
2757#define MPI_SAS_DEVICE0_FLAGS_MAPPING_PERSISTENT (0x0004) 2841#define MPI_SAS_DEVICE0_FLAGS_PORT_SELECTOR_ATTACH (0x0008)
2758#define MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED (0x0002) 2842#define MPI_SAS_DEVICE0_FLAGS_MAPPING_PERSISTENT (0x0004)
2759#define MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT (0x0001) 2843#define MPI_SAS_DEVICE0_FLAGS_DEVICE_MAPPED (0x0002)
2844#define MPI_SAS_DEVICE0_FLAGS_DEVICE_PRESENT (0x0001)
2760 2845
2761/* see mpi_sas.h for values for SAS Device Page 0 DeviceInfo values */ 2846/* see mpi_sas.h for values for SAS Device Page 0 DeviceInfo values */
2762 2847
diff --git a/drivers/message/fusion/lsi/mpi_history.txt b/drivers/message/fusion/lsi/mpi_history.txt
index 582cfe7c2aa..d6b4c607453 100644
--- a/drivers/message/fusion/lsi/mpi_history.txt
+++ b/drivers/message/fusion/lsi/mpi_history.txt
@@ -3,28 +3,28 @@
3 MPI Header File Change History 3 MPI Header File Change History
4 ============================== 4 ==============================
5 5
6 Copyright (c) 2000-2005 LSI Logic Corporation. 6 Copyright (c) 2000-2006 LSI Logic Corporation.
7 7
8 --------------------------------------- 8 ---------------------------------------
9 Header Set Release Version: 01.05.13 9 Header Set Release Version: 01.05.14
10 Header Set Release Date: 03-27-06 10 Header Set Release Date: 10-11-06
11 --------------------------------------- 11 ---------------------------------------
12 12
13 Filename Current version Prior version 13 Filename Current version Prior version
14 ---------- --------------- ------------- 14 ---------- --------------- -------------
15 mpi.h 01.05.11 01.05.10 15 mpi.h 01.05.12 01.05.11
16 mpi_ioc.h 01.05.11 01.05.10 16 mpi_ioc.h 01.05.12 01.05.11
17 mpi_cnfg.h 01.05.12 01.05.11 17 mpi_cnfg.h 01.05.13 01.05.12
18 mpi_init.h 01.05.07 01.05.06 18 mpi_init.h 01.05.08 01.05.07
19 mpi_targ.h 01.05.06 01.05.05 19 mpi_targ.h 01.05.06 01.05.06
20 mpi_fc.h 01.05.01 01.05.01 20 mpi_fc.h 01.05.01 01.05.01
21 mpi_lan.h 01.05.01 01.05.01 21 mpi_lan.h 01.05.01 01.05.01
22 mpi_raid.h 01.05.02 01.05.02 22 mpi_raid.h 01.05.02 01.05.02
23 mpi_tool.h 01.05.03 01.05.03 23 mpi_tool.h 01.05.03 01.05.03
24 mpi_inb.h 01.05.01 01.05.01 24 mpi_inb.h 01.05.01 01.05.01
25 mpi_sas.h 01.05.03 01.05.02 25 mpi_sas.h 01.05.04 01.05.03
26 mpi_type.h 01.05.02 01.05.02 26 mpi_type.h 01.05.02 01.05.02
27 mpi_history.txt 01.05.13 01.05.12 27 mpi_history.txt 01.05.14 01.05.13
28 28
29 29
30 * Date Version Description 30 * Date Version Description
@@ -94,6 +94,7 @@ mpi.h
94 * 08-03-05 01.05.09 Bumped MPI_HEADER_VERSION_UNIT. 94 * 08-03-05 01.05.09 Bumped MPI_HEADER_VERSION_UNIT.
95 * 08-30-05 01.05.10 Added 2 new IOCStatus codes for Target. 95 * 08-30-05 01.05.10 Added 2 new IOCStatus codes for Target.
96 * 03-27-06 01.05.11 Bumped MPI_HEADER_VERSION_UNIT. 96 * 03-27-06 01.05.11 Bumped MPI_HEADER_VERSION_UNIT.
97 * 10-11-06 01.05.12 Bumped MPI_HEADER_VERSION_UNIT.
97 * -------------------------------------------------------------------------- 98 * --------------------------------------------------------------------------
98 99
99mpi_ioc.h 100mpi_ioc.h
@@ -182,6 +183,14 @@ mpi_ioc.h
182 * Added MPI_EVENT_SAS_INIT_TABLE_OVERFLOW and event 183 * Added MPI_EVENT_SAS_INIT_TABLE_OVERFLOW and event
183 * data structure. 184 * data structure.
184 * Added MPI_EXT_IMAGE_TYPE_INITIALIZATION. 185 * Added MPI_EXT_IMAGE_TYPE_INITIALIZATION.
186 * 10-11-06 01.05.12 Added MPI_IOCFACTS_EXCEPT_METADATA_UNSUPPORTED.
187 * Added MaxInitiators field to PortFacts reply.
188 * Added SAS Device Status Change ReasonCode for
189 * asynchronous notificaiton.
190 * Added MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE and event
191 * data structure.
192 * Added new ImageType values for FWDownload and FWUpload
193 * requests.
185 * -------------------------------------------------------------------------- 194 * --------------------------------------------------------------------------
186 195
187mpi_cnfg.h 196mpi_cnfg.h
@@ -447,6 +456,23 @@ mpi_cnfg.h
447 * Added AdditionalControlFlags, MaxTargetPortConnectTime, 456 * Added AdditionalControlFlags, MaxTargetPortConnectTime,
448 * ReportDeviceMissingDelay, and IODeviceMissingDelay 457 * ReportDeviceMissingDelay, and IODeviceMissingDelay
449 * fields to SAS IO Unit Page 1. 458 * fields to SAS IO Unit Page 1.
459 * 10-11-06 01.05.13 Added NumForceWWID field and ForceWWID array to
460 * Manufacturing Page 5.
461 * Added Manufacturing pages 8 through 10.
462 * Added defines for supported metadata size bits in
463 * CapabilitiesFlags field of IOC Page 6.
464 * Added defines for metadata size bits in VolumeSettings
465 * field of RAID Volume Page 0.
466 * Added SATA Link Reset settings, Enable SATA Asynchronous
467 * Notification bit, and HideNonZeroAttachedPhyIdentifiers
468 * bit to AdditionalControlFlags field of SAS IO Unit
469 * Page 1.
470 * Added defines for Enclosure Devices Unmapped and
471 * Device Limit Exceeded bits in Status field of SAS IO
472 * Unit Page 2.
473 * Added more AccessStatus values for SAS Device Page 0.
474 * Added bit for SATA Asynchronous Notification Support in
475 * Flags field of SAS Device Page 0.
450 * -------------------------------------------------------------------------- 476 * --------------------------------------------------------------------------
451 477
452mpi_init.h 478mpi_init.h
@@ -490,6 +516,7 @@ mpi_init.h
490 * 08-03-05 01.05.06 Fixed some MPI_SCSIIO32_MSGFLGS_ defines to make them 516 * 08-03-05 01.05.06 Fixed some MPI_SCSIIO32_MSGFLGS_ defines to make them
491 * unique in the first 32 characters. 517 * unique in the first 32 characters.
492 * 03-27-06 01.05.07 Added Task Management type of Clear ACA. 518 * 03-27-06 01.05.07 Added Task Management type of Clear ACA.
519 * 10-11-06 01.05.08 Shortened define for Task Management type of Clear ACA.
493 * -------------------------------------------------------------------------- 520 * --------------------------------------------------------------------------
494 521
495mpi_targ.h 522mpi_targ.h
@@ -638,6 +665,8 @@ mpi_sas.h
638 * and Remove Device operations to SAS IO Unit Control. 665 * and Remove Device operations to SAS IO Unit Control.
639 * Added DevHandle field to SAS IO Unit Control request and 666 * Added DevHandle field to SAS IO Unit Control request and
640 * reply. 667 * reply.
668 * 10-11-06 01.05.04 Fixed the name of a define for Operation field of SAS IO
669 * Unit Control request.
641 * -------------------------------------------------------------------------- 670 * --------------------------------------------------------------------------
642 671
643mpi_type.h 672mpi_type.h
@@ -653,20 +682,20 @@ mpi_type.h
653 682
654mpi_history.txt Parts list history 683mpi_history.txt Parts list history
655 684
656Filename 01.05.13 01.05.12 01.05.11 01.05.10 01.05.09 685Filename 01.05.13 01.05.13 01.05.12 01.05.11 01.05.10 01.05.09
657---------- -------- -------- -------- -------- -------- 686---------- -------- -------- -------- -------- -------- --------
658mpi.h 01.05.11 01.05.10 01.05.09 01.05.08 01.05.07 687mpi.h 01.05.12 01.05.11 01.05.10 01.05.09 01.05.08 01.05.07
659mpi_ioc.h 01.05.11 01.05.10 01.05.09 01.05.09 01.05.08 688mpi_ioc.h 01.05.12 01.05.11 01.05.10 01.05.09 01.05.09 01.05.08
660mpi_cnfg.h 01.05.12 01.05.11 01.05.10 01.05.09 01.05.08 689mpi_cnfg.h 01.05.13 01.05.12 01.05.11 01.05.10 01.05.09 01.05.08
661mpi_init.h 01.05.07 01.05.06 01.05.06 01.05.05 01.05.04 690mpi_init.h 01.05.08 01.05.07 01.05.06 01.05.06 01.05.05 01.05.04
662mpi_targ.h 01.05.06 01.05.05 01.05.05 01.05.05 01.05.04 691mpi_targ.h 01.05.06 01.05.06 01.05.05 01.05.05 01.05.05 01.05.04
663mpi_fc.h 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01 692mpi_fc.h 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01
664mpi_lan.h 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01 693mpi_lan.h 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01
665mpi_raid.h 01.05.02 01.05.02 01.05.02 01.05.02 01.05.02 694mpi_raid.h 01.05.02 01.05.02 01.05.02 01.05.02 01.05.02 01.05.02
666mpi_tool.h 01.05.03 01.05.03 01.05.03 01.05.03 01.05.03 695mpi_tool.h 01.05.03 01.05.03 01.05.03 01.05.03 01.05.03 01.05.03
667mpi_inb.h 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01 696mpi_inb.h 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01 01.05.01
668mpi_sas.h 01.05.03 01.05.02 01.05.01 01.05.01 01.05.01 697mpi_sas.h 01.05.04 01.05.03 01.05.02 01.05.01 01.05.01 01.05.01
669mpi_type.h 01.05.02 01.05.02 01.05.01 01.05.01 01.05.01 698mpi_type.h 01.05.02 01.05.02 01.05.02 01.05.01 01.05.01 01.05.01
670 699
671Filename 01.05.08 01.05.07 01.05.06 01.05.05 01.05.04 01.05.03 700Filename 01.05.08 01.05.07 01.05.06 01.05.05 01.05.04 01.05.03
672---------- -------- -------- -------- -------- -------- -------- 701---------- -------- -------- -------- -------- -------- --------
diff --git a/drivers/message/fusion/lsi/mpi_init.h b/drivers/message/fusion/lsi/mpi_init.h
index c1c678989a2..ec9dff2249a 100644
--- a/drivers/message/fusion/lsi/mpi_init.h
+++ b/drivers/message/fusion/lsi/mpi_init.h
@@ -1,12 +1,12 @@
1/* 1/*
2 * Copyright (c) 2000-2005 LSI Logic Corporation. 2 * Copyright (c) 2000-2006 LSI Logic Corporation.
3 * 3 *
4 * 4 *
5 * Name: mpi_init.h 5 * Name: mpi_init.h
6 * Title: MPI initiator mode messages and structures 6 * Title: MPI initiator mode messages and structures
7 * Creation Date: June 8, 2000 7 * Creation Date: June 8, 2000
8 * 8 *
9 * mpi_init.h Version: 01.05.07 9 * mpi_init.h Version: 01.05.08
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -53,6 +53,7 @@
53 * 08-03-05 01.05.06 Fixed some MPI_SCSIIO32_MSGFLGS_ defines to make them 53 * 08-03-05 01.05.06 Fixed some MPI_SCSIIO32_MSGFLGS_ defines to make them
54 * unique in the first 32 characters. 54 * unique in the first 32 characters.
55 * 03-27-06 01.05.07 Added Task Management type of Clear ACA. 55 * 03-27-06 01.05.07 Added Task Management type of Clear ACA.
56 * 10-11-06 01.05.08 Shortened define for Task Management type of Clear ACA.
56 * -------------------------------------------------------------------------- 57 * --------------------------------------------------------------------------
57 */ 58 */
58 59
@@ -428,7 +429,7 @@ typedef struct _MSG_SCSI_TASK_MGMT
428#define MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET (0x05) 429#define MPI_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET (0x05)
429#define MPI_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET (0x06) 430#define MPI_SCSITASKMGMT_TASKTYPE_CLEAR_TASK_SET (0x06)
430#define MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK (0x07) 431#define MPI_SCSITASKMGMT_TASKTYPE_QUERY_TASK (0x07)
431#define MPI_SCSITASKMGMT_TASKTYPE_CLEAR_ACA (0x08) 432#define MPI_SCSITASKMGMT_TASKTYPE_CLR_ACA (0x08)
432 433
433/* MsgFlags bits */ 434/* MsgFlags bits */
434#define MPI_SCSITASKMGMT_MSGFLAGS_TARGET_RESET_OPTION (0x00) 435#define MPI_SCSITASKMGMT_MSGFLAGS_TARGET_RESET_OPTION (0x00)
diff --git a/drivers/message/fusion/lsi/mpi_ioc.h b/drivers/message/fusion/lsi/mpi_ioc.h
index 18ba407fd39..6c33e335337 100644
--- a/drivers/message/fusion/lsi/mpi_ioc.h
+++ b/drivers/message/fusion/lsi/mpi_ioc.h
@@ -1,12 +1,12 @@
1/* 1/*
2 * Copyright (c) 2000-2005 LSI Logic Corporation. 2 * Copyright (c) 2000-2006 LSI Logic Corporation.
3 * 3 *
4 * 4 *
5 * Name: mpi_ioc.h 5 * Name: mpi_ioc.h
6 * Title: MPI IOC, Port, Event, FW Download, and FW Upload messages 6 * Title: MPI IOC, Port, Event, FW Download, and FW Upload messages
7 * Creation Date: August 11, 2000 7 * Creation Date: August 11, 2000
8 * 8 *
9 * mpi_ioc.h Version: 01.05.11 9 * mpi_ioc.h Version: 01.05.12
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -98,6 +98,14 @@
98 * Added MPI_EVENT_SAS_INIT_TABLE_OVERFLOW and event 98 * Added MPI_EVENT_SAS_INIT_TABLE_OVERFLOW and event
99 * data structure. 99 * data structure.
100 * Added MPI_EXT_IMAGE_TYPE_INITIALIZATION. 100 * Added MPI_EXT_IMAGE_TYPE_INITIALIZATION.
101 * 10-11-06 01.05.12 Added MPI_IOCFACTS_EXCEPT_METADATA_UNSUPPORTED.
102 * Added MaxInitiators field to PortFacts reply.
103 * Added SAS Device Status Change ReasonCode for
104 * asynchronous notificaiton.
105 * Added MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE and event
106 * data structure.
107 * Added new ImageType values for FWDownload and FWUpload
108 * requests.
101 * -------------------------------------------------------------------------- 109 * --------------------------------------------------------------------------
102 */ 110 */
103 111
@@ -264,6 +272,7 @@ typedef struct _MSG_IOC_FACTS_REPLY
264#define MPI_IOCFACTS_EXCEPT_RAID_CONFIG_INVALID (0x0002) 272#define MPI_IOCFACTS_EXCEPT_RAID_CONFIG_INVALID (0x0002)
265#define MPI_IOCFACTS_EXCEPT_FW_CHECKSUM_FAIL (0x0004) 273#define MPI_IOCFACTS_EXCEPT_FW_CHECKSUM_FAIL (0x0004)
266#define MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL (0x0008) 274#define MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL (0x0008)
275#define MPI_IOCFACTS_EXCEPT_METADATA_UNSUPPORTED (0x0010)
267 276
268#define MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT (0x01) 277#define MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT (0x01)
269#define MPI_IOCFACTS_FLAGS_REPLY_FIFO_HOST_SIGNAL (0x02) 278#define MPI_IOCFACTS_FLAGS_REPLY_FIFO_HOST_SIGNAL (0x02)
@@ -328,7 +337,8 @@ typedef struct _MSG_PORT_FACTS_REPLY
328 U16 MaxPostedCmdBuffers; /* 1Ch */ 337 U16 MaxPostedCmdBuffers; /* 1Ch */
329 U16 MaxPersistentIDs; /* 1Eh */ 338 U16 MaxPersistentIDs; /* 1Eh */
330 U16 MaxLanBuckets; /* 20h */ 339 U16 MaxLanBuckets; /* 20h */
331 U16 Reserved4; /* 22h */ 340 U8 MaxInitiators; /* 22h */
341 U8 Reserved4; /* 23h */
332 U32 Reserved5; /* 24h */ 342 U32 Reserved5; /* 24h */
333} MSG_PORT_FACTS_REPLY, MPI_POINTER PTR_MSG_PORT_FACTS_REPLY, 343} MSG_PORT_FACTS_REPLY, MPI_POINTER PTR_MSG_PORT_FACTS_REPLY,
334 PortFactsReply_t, MPI_POINTER pPortFactsReply_t; 344 PortFactsReply_t, MPI_POINTER pPortFactsReply_t;
@@ -487,6 +497,7 @@ typedef struct _MSG_EVENT_ACK_REPLY
487#define MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE (0x00000018) 497#define MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE (0x00000018)
488#define MPI_EVENT_SAS_INIT_TABLE_OVERFLOW (0x00000019) 498#define MPI_EVENT_SAS_INIT_TABLE_OVERFLOW (0x00000019)
489#define MPI_EVENT_SAS_SMP_ERROR (0x0000001A) 499#define MPI_EVENT_SAS_SMP_ERROR (0x0000001A)
500#define MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE (0x0000001B)
490#define MPI_EVENT_LOG_ENTRY_ADDED (0x00000021) 501#define MPI_EVENT_LOG_ENTRY_ADDED (0x00000021)
491 502
492/* AckRequired field values */ 503/* AckRequired field values */
@@ -593,6 +604,7 @@ typedef struct _EVENT_DATA_SAS_DEVICE_STATUS_CHANGE
593#define MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL (0x0A) 604#define MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL (0x0A)
594#define MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL (0x0B) 605#define MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL (0x0B)
595#define MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL (0x0C) 606#define MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL (0x0C)
607#define MPI_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION (0x0D)
596 608
597 609
598/* SCSI Event data for Queue Full event */ 610/* SCSI Event data for Queue Full event */
@@ -895,6 +907,54 @@ typedef struct _EVENT_DATA_SAS_INIT_TABLE_OVERFLOW
895 MpiEventDataSasInitTableOverflow_t, 907 MpiEventDataSasInitTableOverflow_t,
896 MPI_POINTER pMpiEventDataSasInitTableOverflow_t; 908 MPI_POINTER pMpiEventDataSasInitTableOverflow_t;
897 909
910/* SAS Expander Status Change Event data */
911
912typedef struct _EVENT_DATA_SAS_EXPANDER_STATUS_CHANGE
913{
914 U8 ReasonCode; /* 00h */
915 U8 Reserved1; /* 01h */
916 U16 Reserved2; /* 02h */
917 U8 PhysicalPort; /* 04h */
918 U8 Reserved3; /* 05h */
919 U16 EnclosureHandle; /* 06h */
920 U64 SASAddress; /* 08h */
921 U32 DiscoveryStatus; /* 10h */
922 U16 DevHandle; /* 14h */
923 U16 ParentDevHandle; /* 16h */
924 U16 ExpanderChangeCount; /* 18h */
925 U16 ExpanderRouteIndexes; /* 1Ah */
926 U8 NumPhys; /* 1Ch */
927 U8 SASLevel; /* 1Dh */
928 U8 Flags; /* 1Eh */
929 U8 Reserved4; /* 1Fh */
930} EVENT_DATA_SAS_EXPANDER_STATUS_CHANGE,
931 MPI_POINTER PTR_EVENT_DATA_SAS_EXPANDER_STATUS_CHANGE,
932 MpiEventDataSasExpanderStatusChange_t,
933 MPI_POINTER pMpiEventDataSasExpanderStatusChange_t;
934
935/* values for ReasonCode field of SAS Expander Status Change Event data */
936#define MPI_EVENT_SAS_EXP_RC_ADDED (0x00)
937#define MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING (0x01)
938
939/* values for DiscoveryStatus field of SAS Expander Status Change Event data */
940#define MPI_EVENT_SAS_EXP_DS_LOOP_DETECTED (0x00000001)
941#define MPI_EVENT_SAS_EXP_DS_UNADDRESSABLE_DEVICE (0x00000002)
942#define MPI_EVENT_SAS_EXP_DS_MULTIPLE_PORTS (0x00000004)
943#define MPI_EVENT_SAS_EXP_DS_EXPANDER_ERR (0x00000008)
944#define MPI_EVENT_SAS_EXP_DS_SMP_TIMEOUT (0x00000010)
945#define MPI_EVENT_SAS_EXP_DS_OUT_ROUTE_ENTRIES (0x00000020)
946#define MPI_EVENT_SAS_EXP_DS_INDEX_NOT_EXIST (0x00000040)
947#define MPI_EVENT_SAS_EXP_DS_SMP_FUNCTION_FAILED (0x00000080)
948#define MPI_EVENT_SAS_EXP_DS_SMP_CRC_ERROR (0x00000100)
949#define MPI_EVENT_SAS_EXP_DS_SUBTRACTIVE_LINK (0x00000200)
950#define MPI_EVENT_SAS_EXP_DS_TABLE_LINK (0x00000400)
951#define MPI_EVENT_SAS_EXP_DS_UNSUPPORTED_DEVICE (0x00000800)
952
953/* values for Flags field of SAS Expander Status Change Event data */
954#define MPI_EVENT_SAS_EXP_FLAGS_ROUTE_TABLE_CONFIG (0x02)
955#define MPI_EVENT_SAS_EXP_FLAGS_CONFIG_IN_PROGRESS (0x01)
956
957
898 958
899/***************************************************************************** 959/*****************************************************************************
900* 960*
@@ -926,6 +986,10 @@ typedef struct _MSG_FW_DOWNLOAD
926#define MPI_FW_DOWNLOAD_ITYPE_BIOS (0x02) 986#define MPI_FW_DOWNLOAD_ITYPE_BIOS (0x02)
927#define MPI_FW_DOWNLOAD_ITYPE_NVDATA (0x03) 987#define MPI_FW_DOWNLOAD_ITYPE_NVDATA (0x03)
928#define MPI_FW_DOWNLOAD_ITYPE_BOOTLOADER (0x04) 988#define MPI_FW_DOWNLOAD_ITYPE_BOOTLOADER (0x04)
989#define MPI_FW_DOWNLOAD_ITYPE_MANUFACTURING (0x06)
990#define MPI_FW_DOWNLOAD_ITYPE_CONFIG_1 (0x07)
991#define MPI_FW_DOWNLOAD_ITYPE_CONFIG_2 (0x08)
992#define MPI_FW_DOWNLOAD_ITYPE_MEGARAID (0x09)
929 993
930 994
931typedef struct _FWDownloadTCSGE 995typedef struct _FWDownloadTCSGE
@@ -980,6 +1044,11 @@ typedef struct _MSG_FW_UPLOAD
980#define MPI_FW_UPLOAD_ITYPE_NVDATA (0x03) 1044#define MPI_FW_UPLOAD_ITYPE_NVDATA (0x03)
981#define MPI_FW_UPLOAD_ITYPE_BOOTLOADER (0x04) 1045#define MPI_FW_UPLOAD_ITYPE_BOOTLOADER (0x04)
982#define MPI_FW_UPLOAD_ITYPE_FW_BACKUP (0x05) 1046#define MPI_FW_UPLOAD_ITYPE_FW_BACKUP (0x05)
1047#define MPI_FW_UPLOAD_ITYPE_MANUFACTURING (0x06)
1048#define MPI_FW_UPLOAD_ITYPE_CONFIG_1 (0x07)
1049#define MPI_FW_UPLOAD_ITYPE_CONFIG_2 (0x08)
1050#define MPI_FW_UPLOAD_ITYPE_MEGARAID (0x09)
1051#define MPI_FW_UPLOAD_ITYPE_COMPLETE (0x0A)
983 1052
984typedef struct _FWUploadTCSGE 1053typedef struct _FWUploadTCSGE
985{ 1054{
diff --git a/drivers/message/fusion/lsi/mpi_log_sas.h b/drivers/message/fusion/lsi/mpi_log_sas.h
index 871ebc08b70..635bbe04513 100644
--- a/drivers/message/fusion/lsi/mpi_log_sas.h
+++ b/drivers/message/fusion/lsi/mpi_log_sas.h
@@ -1,4 +1,3 @@
1
2/*************************************************************************** 1/***************************************************************************
3 * * 2 * *
4 * Copyright 2003 LSI Logic Corporation. All rights reserved. * 3 * Copyright 2003 LSI Logic Corporation. All rights reserved. *
@@ -14,7 +13,7 @@
14#define IOPI_IOCLOGINFO_H_INCLUDED 13#define IOPI_IOCLOGINFO_H_INCLUDED
15 14
16#define SAS_LOGINFO_NEXUS_LOSS 0x31170000 15#define SAS_LOGINFO_NEXUS_LOSS 0x31170000
17#define SAS_LOGINFO_MASK 0xFFFF0000 16#define SAS_LOGINFO_MASK 0xFFFF0000
18 17
19/****************************************************************************/ 18/****************************************************************************/
20/* IOC LOGINFO defines, 0x00000000 - 0x0FFFFFFF */ 19/* IOC LOGINFO defines, 0x00000000 - 0x0FFFFFFF */
@@ -43,129 +42,172 @@
43/****************************************************************************/ 42/****************************************************************************/
44/* IOP LOGINFO_CODE defines, valid if IOC_LOGINFO_ORIGINATOR = IOP */ 43/* IOP LOGINFO_CODE defines, valid if IOC_LOGINFO_ORIGINATOR = IOP */
45/****************************************************************************/ 44/****************************************************************************/
46#define IOP_LOGINFO_CODE_INVALID_SAS_ADDRESS (0x00010000) 45#define IOP_LOGINFO_CODE_INVALID_SAS_ADDRESS (0x00010000)
47#define IOP_LOGINFO_CODE_UNUSED2 (0x00020000) 46#define IOP_LOGINFO_CODE_UNUSED2 (0x00020000)
48#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE (0x00030000) 47#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE (0x00030000)
49#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_RT (0x00030100) /* Route Table Entry not found */ 48#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_RT (0x00030100) /* Route Table Entry not found */
50#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_PN (0x00030200) /* Invalid Page Number */ 49#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_PN (0x00030200) /* Invalid Page Number */
51#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_FORM (0x00030300) /* Invalid FORM */ 50#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_FORM (0x00030300) /* Invalid FORM */
52#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_PT (0x00030400) /* Invalid Page Type */ 51#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_PT (0x00030400) /* Invalid Page Type */
53#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_DNM (0x00030500) /* Device Not Mapped */ 52#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_DNM (0x00030500) /* Device Not Mapped */
54#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_PERSIST (0x00030600) /* Persistent Page not found */ 53#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_PERSIST (0x00030600) /* Persistent Page not found */
55#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_DEFAULT (0x00030700) /* Default Page not found */ 54#define IOP_LOGINFO_CODE_CONFIG_INVALID_PAGE_DEFAULT (0x00030700) /* Default Page not found */
56 55
57#define IOP_LOGINFO_CODE_DIAG_MSG_ERROR (0x00040000) /* Error handling diag msg - or'd with diag status */ 56#define IOP_LOGINFO_CODE_FWUPLOAD_NO_FLASH_AVAILABLE (0x0003E000) /* Tried to upload from flash, but there is none */
58 57#define IOP_LOGINFO_CODE_FWUPLOAD_UNKNOWN_IMAGE_TYPE (0x0003E001) /* ImageType field contents were invalid */
59#define IOP_LOGINFO_CODE_TASK_TERMINATED (0x00050000) 58#define IOP_LOGINFO_CODE_FWUPLOAD_WRONG_IMAGE_SIZE (0x0003E002) /* ImageSize field in TCSGE was bad/offset in MfgPg 4 was wrong */
60 59#define IOP_LOGINFO_CODE_FWUPLOAD_ENTIRE_FLASH_UPLOAD_FAILED (0x0003E003) /* Error occured while attempting to upload the entire flash */
61#define IOP_LOGINFO_CODE_ENCL_MGMT_READ_ACTION_ERR0R (0x00060001) /* Read Action not supported for SEP msg */ 60#define IOP_LOGINFO_CODE_FWUPLOAD_REGION_UPLOAD_FAILED (0x0003E004) /* Error occured while attempting to upload single flash region */
62#define IOP_LOGINFO_CODE_ENCL_MGMT_INVALID_BUS_ID_ERR0R (0x00060002) /* Invalid Bus/ID in SEP msg */ 61#define IOP_LOGINFO_CODE_FWUPLOAD_DMA_FAILURE (0x0003E005) /* Problem occured while DMAing FW to host memory */
63 62
64#define IOP_LOGINFO_CODE_TARGET_ASSIST_TERMINATED (0x00070001) 63#define IOP_LOGINFO_CODE_DIAG_MSG_ERROR (0x00040000) /* Error handling diag msg - or'd with diag status */
65#define IOP_LOGINFO_CODE_TARGET_STATUS_SEND_TERMINATED (0x00070002) 64
66#define IOP_LOGINFO_CODE_TARGET_MODE_ABORT_ALL_IO (0x00070003) 65#define IOP_LOGINFO_CODE_TASK_TERMINATED (0x00050000)
67#define IOP_LOGINFO_CODE_TARGET_MODE_ABORT_EXACT_IO (0x00070004) 66
68#define IOP_LOGINFO_CODE_TARGET_MODE_ABORT_EXACT_IO_REQ (0x00070005) 67#define IOP_LOGINFO_CODE_ENCL_MGMT_READ_ACTION_ERR0R (0x00060001) /* Read Action not supported for SEP msg */
68#define IOP_LOGINFO_CODE_ENCL_MGMT_INVALID_BUS_ID_ERR0R (0x00060002) /* Invalid Bus/ID in SEP msg */
69
70#define IOP_LOGINFO_CODE_TARGET_ASSIST_TERMINATED (0x00070001)
71#define IOP_LOGINFO_CODE_TARGET_STATUS_SEND_TERMINATED (0x00070002)
72#define IOP_LOGINFO_CODE_TARGET_MODE_ABORT_ALL_IO (0x00070003)
73#define IOP_LOGINFO_CODE_TARGET_MODE_ABORT_EXACT_IO (0x00070004)
74#define IOP_LOGINFO_CODE_TARGET_MODE_ABORT_EXACT_IO_REQ (0x00070005)
69 75
70/****************************************************************************/ 76/****************************************************************************/
71/* PL LOGINFO_CODE defines, valid if IOC_LOGINFO_ORIGINATOR = PL */ 77/* PL LOGINFO_CODE defines, valid if IOC_LOGINFO_ORIGINATOR = PL */
72/****************************************************************************/ 78/****************************************************************************/
73#define PL_LOGINFO_CODE_OPEN_FAILURE (0x00010000) 79#define PL_LOGINFO_CODE_OPEN_FAILURE (0x00010000) /* see SUB_CODE_OPEN_FAIL_ below */
74#define PL_LOG_INFO_CODE_OPEN_FAILURE_NO_DEST_TIME_OUT (0x00010001) 80
75#define PL_LOGINFO_CODE_OPEN_FAILURE_BAD_DESTINATION (0x00010011) 81#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_NO_DEST_TIME_OUT (0x00000001)
76#define PL_LOGINFO_CODE_OPEN_FAILURE_PROTOCOL_NOT_SUPPORTED (0x00010013) 82#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_PATHWAY_BLOCKED (0x00000002)
77#define PL_LOGINFO_CODE_OPEN_FAILURE_STP_RESOURCES_BSY (0x00010018) 83#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RES_CONTINUE0 (0x00000003)
78#define PL_LOGINFO_CODE_OPEN_FAILURE_WRONG_DESTINATION (0x00010019) 84#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RES_CONTINUE1 (0x00000004)
79#define PL_LOGINFO_CODE_OPEN_FAILURE_ORR_TIMEOUT (0X0001001A) 85#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RES_INITIALIZE0 (0x00000005)
80#define PL_LOGINFO_CODE_OPEN_FAILURE_PATHWAY_BLOCKED (0x0001001B) 86#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RES_INITIALIZE1 (0x00000006)
81#define PL_LOGINFO_CODE_OPEN_FAILURE_AWT_MAXED (0x0001001C) 87#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RES_STOP0 (0x00000007)
82#define PL_LOGINFO_CODE_INVALID_SGL (0x00020000) 88#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RES_STOP1 (0x00000008)
83#define PL_LOGINFO_CODE_WRONG_REL_OFF_OR_FRAME_LENGTH (0x00030000) 89#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RETRY (0x00000009)
84#define PL_LOGINFO_CODE_FRAME_XFER_ERROR (0x00040000) 90#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_BREAK (0x0000000A)
85#define PL_LOGINFO_CODE_TX_FM_CONNECTED_LOW (0x00050000) 91#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_UNUSED_0B (0x0000000B)
86#define PL_LOGINFO_CODE_SATA_NON_NCQ_RW_ERR_BIT_SET (0x00060000) 92#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_OPEN_TIMEOUT_EXP (0x0000000C)
87#define PL_LOGINFO_CODE_SATA_READ_LOG_RECEIVE_DATA_ERR (0x00070000) 93#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_UNUSED_0D (0x0000000D)
88#define PL_LOGINFO_CODE_SATA_NCQ_FAIL_ALL_CMDS_AFTR_ERR (0x00080000) 94#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_DVTBLE_ACCSS_FAIL (0x0000000E)
89#define PL_LOGINFO_CODE_SATA_ERR_IN_RCV_SET_DEV_BIT_FIS (0x00090000) 95#define PL_LOGINFO_SUB CODE_OPEN_FAIL_BAD_DEST (0x00000011)
90#define PL_LOGINFO_CODE_RX_FM_INVALID_MESSAGE (0x000A0000) 96#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RATE_NOT_SUPP (0x00000012)
91#define PL_LOGINFO_CODE_RX_CTX_MESSAGE_VALID_ERROR (0x000B0000) 97#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_PROT_NOT_SUPP (0x00000013)
92#define PL_LOGINFO_CODE_RX_FM_CURRENT_FRAME_ERROR (0x000C0000) 98#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RESERVED_ABANDON0 (0x00000014)
93#define PL_LOGINFO_CODE_SATA_LINK_DOWN (0x000D0000) 99#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RESERVED_ABANDON1 (0x00000015)
94#define PL_LOGINFO_CODE_DISCOVERY_SATA_INIT_W_IOS (0x000E0000) 100#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RESERVED_ABANDON2 (0x00000016)
95#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE (0x000F0000) 101#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_RESERVED_ABANDON3 (0x00000017)
96#define PL_LOGINFO_CODE_CONFIG_PL_NOT_INITIALIZED (0x000F0001) /* PL not yet initialized, can't do config page req. */ 102#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_STP_RESOURCES_BSY (0x00000018)
97#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_PT (0x000F0100) /* Invalid Page Type */ 103#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_WRONG_DESTINATION (0x00000019)
98#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_NUM_PHYS (0x000F0200) /* Invalid Number of Phys */ 104
99#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_NOT_IMP (0x000F0300) /* Case Not Handled */ 105#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_PATH_BLOCKED (0x0000001B) /* Retry Timeout */
100#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_NO_DEV (0x000F0400) /* No Device Found */ 106#define PL_LOGINFO_SUB_CODE_OPEN_FAIL_AWT_MAXED (0x0000001C) /* Retry Timeout */
101#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_FORM (0x000F0500) /* Invalid FORM */ 107
102#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_PHY (0x000F0600) /* Invalid Phy */ 108
103#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_NO_OWNER (0x000F0700) /* No Owner Found */ 109
104#define PL_LOGINFO_CODE_DSCVRY_SATA_INIT_TIMEOUT (0x00100000) 110#define PL_LOGINFO_CODE_INVALID_SGL (0x00020000)
105#define PL_LOGINFO_CODE_RESET (0x00110000) /* See Sub-Codes below */ 111#define PL_LOGINFO_CODE_WRONG_REL_OFF_OR_FRAME_LENGTH (0x00030000)
106#define PL_LOGINFO_CODE_ABORT (0x00120000) /* See Sub-Codes below */ 112#define PL_LOGINFO_CODE_FRAME_XFER_ERROR (0x00040000)
107#define PL_LOGINFO_CODE_IO_NOT_YET_EXECUTED (0x00130000) 113#define PL_LOGINFO_CODE_TX_FM_CONNECTED_LOW (0x00050000)
108#define PL_LOGINFO_CODE_IO_EXECUTED (0x00140000) 114#define PL_LOGINFO_CODE_SATA_NON_NCQ_RW_ERR_BIT_SET (0x00060000)
109#define PL_LOGINFO_CODE_PERS_RESV_OUT_NOT_AFFIL_OWNER (0x00150000) 115#define PL_LOGINFO_CODE_SATA_READ_LOG_RECEIVE_DATA_ERR (0x00070000)
110#define PL_LOGINFO_CODE_OPEN_TXDMA_ABORT (0x00160000) 116#define PL_LOGINFO_CODE_SATA_NCQ_FAIL_ALL_CMDS_AFTR_ERR (0x00080000)
111#define PL_LOGINFO_CODE_IO_DEVICE_MISSING_DELAY_RETRY (0x00170000) 117#define PL_LOGINFO_CODE_SATA_ERR_IN_RCV_SET_DEV_BIT_FIS (0x00090000)
112#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE (0x00000100) 118#define PL_LOGINFO_CODE_RX_FM_INVALID_MESSAGE (0x000A0000)
113#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_NO_DEST_TIMEOUT (0x00000101) 119#define PL_LOGINFO_CODE_RX_CTX_MESSAGE_VALID_ERROR (0x000B0000)
114#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_ORR_TIMEOUT (0x0000011A) /* Open Reject (Retry) Timeout */ 120#define PL_LOGINFO_CODE_RX_FM_CURRENT_FRAME_ERROR (0x000C0000)
115#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_PATHWAY_BLOCKED (0x0000011B) 121#define PL_LOGINFO_CODE_SATA_LINK_DOWN (0x000D0000)
116#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_AWT_MAXED (0x0000011C) /* Arbitration Wait Timer Maxed */ 122#define PL_LOGINFO_CODE_DISCOVERY_SATA_INIT_W_IOS (0x000E0000)
117 123#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE (0x000F0000)
118#define PL_LOGINFO_SUB_CODE_TARGET_BUS_RESET (0x00000120) 124#define PL_LOGINFO_CODE_CONFIG_PL_NOT_INITIALIZED (0x000F0001) /* PL not yet initialized, can't do config page req. */
119#define PL_LOGINFO_SUB_CODE_TRANSPORT_LAYER (0x00000130) /* Leave lower nibble (1-f) reserved. */ 125#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_PT (0x000F0100) /* Invalid Page Type */
120#define PL_LOGINFO_SUB_CODE_PORT_LAYER (0x00000140) /* Leave lower nibble (1-f) reserved. */ 126#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_NUM_PHYS (0x000F0200) /* Invalid Number of Phys */
121 127#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_NOT_IMP (0x000F0300) /* Case Not Handled */
122 128#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_NO_DEV (0x000F0400) /* No Device Found */
123#define PL_LOGINFO_SUB_CODE_INVALID_SGL (0x00000200) 129#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_FORM (0x000F0500) /* Invalid FORM */
124#define PL_LOGINFO_SUB_CODE_WRONG_REL_OFF_OR_FRAME_LENGTH (0x00000300) 130#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_PHY (0x000F0600) /* Invalid Phy */
125#define PL_LOGINFO_SUB_CODE_FRAME_XFER_ERROR (0x00000400) 131#define PL_LOGINFO_CODE_CONFIG_INVALID_PAGE_NO_OWNER (0x000F0700) /* No Owner Found */
126#define PL_LOGINFO_SUB_CODE_TX_FM_CONNECTED_LOW (0x00000500) 132#define PL_LOGINFO_CODE_DSCVRY_SATA_INIT_TIMEOUT (0x00100000)
127#define PL_LOGINFO_SUB_CODE_SATA_NON_NCQ_RW_ERR_BIT_SET (0x00000600) 133#define PL_LOGINFO_CODE_RESET (0x00110000) /* See Sub-Codes below (PL_LOGINFO_SUB_CODE) */
128#define PL_LOGINFO_SUB_CODE_SATA_READ_LOG_RECEIVE_DATA_ERR (0x00000700) 134#define PL_LOGINFO_CODE_ABORT (0x00120000) /* See Sub-Codes below (PL_LOGINFO_SUB_CODE)*/
129#define PL_LOGINFO_SUB_CODE_SATA_NCQ_FAIL_ALL_CMDS_AFTR_ERR (0x00000800) 135#define PL_LOGINFO_CODE_IO_NOT_YET_EXECUTED (0x00130000)
130#define PL_LOGINFO_SUB_CODE_SATA_ERR_IN_RCV_SET_DEV_BIT_FIS (0x00000900) 136#define PL_LOGINFO_CODE_IO_EXECUTED (0x00140000)
131#define PL_LOGINFO_SUB_CODE_RX_FM_INVALID_MESSAGE (0x00000A00) 137#define PL_LOGINFO_CODE_PERS_RESV_OUT_NOT_AFFIL_OWNER (0x00150000)
132#define PL_LOGINFO_SUB_CODE_RX_CTX_MESSAGE_VALID_ERROR (0x00000B00) 138#define PL_LOGINFO_CODE_OPEN_TXDMA_ABORT (0x00160000)
133#define PL_LOGINFO_SUB_CODE_RX_FM_CURRENT_FRAME_ERROR (0x00000C00) 139#define PL_LOGINFO_CODE_IO_DEVICE_MISSING_DELAY_RETRY (0x00170000)
134#define PL_LOGINFO_SUB_CODE_SATA_LINK_DOWN (0x00000D00) 140#define PL_LOGINFO_CODE_IO_CANCELLED_DUE_TO_R_ERR (0x00180000)
135#define PL_LOGINFO_SUB_CODE_DISCOVERY_SATA_INIT_W_IOS (0x00000E00) 141#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE (0x00000100)
136#define PL_LOGINFO_SUB_CODE_DISCOVERY_REMOTE_SEP_RESET (0x00000E01) 142#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_NO_DEST_TIMEOUT (0x00000101)
137#define PL_LOGINFO_SUB_CODE_SECOND_OPEN (0x00000F00) 143#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_SATA_NEG_RATE_2HI (0x00000102)
138#define PL_LOGINFO_SUB_CODE_DSCVRY_SATA_INIT_TIMEOUT (0x00001000) 144#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_RATE_NOT_SUPPORTED (0x00000103)
139 145#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_BREAK (0x00000104)
140 146#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_ZONE_VIOLATION (0x00000114)
141#define PL_LOGINFO_CODE_ENCL_MGMT_SMP_FRAME_FAILURE (0x00200000) /* Can't get SMP Frame */ 147#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_ABANDON0 (0x00000114) /* Open Reject (Zone Violation) - available on SAS-2 devices */
142#define PL_LOGINFO_CODE_ENCL_MGMT_SMP_READ_ERROR (0x00200010) /* Error occured on SMP Read */ 148#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_ABANDON1 (0x00000115)
143#define PL_LOGINFO_CODE_ENCL_MGMT_SMP_WRITE_ERROR (0x00200020) /* Error occured on SMP Write */ 149#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_ABANDON2 (0x00000116)
144#define PL_LOGINFO_CODE_ENCL_MGMT_NOT_SUPPORTED_ON_ENCL (0x00200040) /* Encl Mgmt services not available for this WWID */ 150#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_ABANDON3 (0x00000117)
145#define PL_LOGINFO_CODE_ENCL_MGMT_ADDR_MODE_NOT_SUPPORTED (0x00200050) /* Address Mode not suppored */ 151#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_ORR_TIMEOUT (0x0000011A) /* Open Reject (Retry) Timeout */
146#define PL_LOGINFO_CODE_ENCL_MGMT_BAD_SLOT_NUM (0x00200060) /* Invalid Slot Number in SEP Msg */ 152#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_PATH_BLOCKED (0x0000011B)
147#define PL_LOGINFO_CODE_ENCL_MGMT_SGPIO_NOT_PRESENT (0x00200070) /* SGPIO not present/enabled */ 153#define PL_LOGINFO_SUB_CODE_OPEN_FAILURE_AWT_MAXED (0x0000011C) /* Arbitration Wait Timer Maxed */
148#define PL_LOGINFO_CODE_ENCL_MGMT_GPIO_NOT_CONFIGURED (0x00200080) /* GPIO not configured */ 154
149#define PL_LOGINFO_CODE_ENCL_MGMT_GPIO_FRAME_ERROR (0x00200090) /* GPIO can't allocate a frame */ 155#define PL_LOGINFO_SUB_CODE_TARGET_BUS_RESET (0x00000120)
150#define PL_LOGINFO_CODE_ENCL_MGMT_GPIO_CONFIG_PAGE_ERROR (0x002000A0) /* GPIO failed config page request */ 156#define PL_LOGINFO_SUB_CODE_TRANSPORT_LAYER (0x00000130) /* Leave lower nibble (1-f) reserved. */
151#define PL_LOGINFO_CODE_ENCL_MGMT_SES_FRAME_ALLOC_ERROR (0x002000B0) /* Can't get frame for SES command */ 157#define PL_LOGINFO_SUB_CODE_PORT_LAYER (0x00000140) /* Leave lower nibble (1-f) reserved. */
152#define PL_LOGINFO_CODE_ENCL_MGMT_SES_IO_ERROR (0x002000C0) /* I/O execution error */ 158
153#define PL_LOGINFO_CODE_ENCL_MGMT_SES_RETRIES_EXHAUSTED (0x002000D0) /* SEP I/O retries exhausted */ 159
154#define PL_LOGINFO_CODE_ENCL_MGMT_SMP_FRAME_ALLOC_ERROR (0x002000E0) /* Can't get frame for SMP command */ 160#define PL_LOGINFO_SUB_CODE_INVALID_SGL (0x00000200)
155 161#define PL_LOGINFO_SUB_CODE_WRONG_REL_OFF_OR_FRAME_LENGTH (0x00000300)
156#define PL_LOGINFO_DA_SEP_NOT_PRESENT (0x00200100) /* SEP not present when msg received */ 162#define PL_LOGINFO_SUB_CODE_FRAME_XFER_ERROR (0x00000400) /* Bits 0-3 encode Transport Status Register (offset 0x08) */
157#define PL_LOGINFO_DA_SEP_SINGLE_THREAD_ERROR (0x00200101) /* Can only accept 1 msg at a time */ 163 /* Bit 0 is Status Bit 0: FrameXferErr */
158#define PL_LOGINFO_DA_SEP_ISTWI_INTR_IN_IDLE_STATE (0x00200102) /* ISTWI interrupt recvd. while IDLE */ 164 /* Bit 1 & 2 are Status Bits 16 and 17: FrameXmitErrStatus */
159#define PL_LOGINFO_DA_SEP_RECEIVED_NACK_FROM_SLAVE (0x00200103) /* SEP NACK'd, it is busy */ 165 /* Bit 3 is Status Bit 18 WriteDataLenghtGTDataLengthErr */
160#define PL_LOGINFO_DA_SEP_DID_NOT_RECEIVE_ACK (0x00200104) /* SEP didn't rcv. ACK (Last Rcvd Bit = 1) */ 166
161#define PL_LOGINFO_DA_SEP_BAD_STATUS_HDR_CHKSUM (0x00200105) /* SEP stopped or sent bad chksum in Hdr */ 167#define PL_LOGINFO_SUB_CODE_TX_FM_CONNECTED_LOW (0x00000500)
162#define PL_LOGINFO_DA_SEP_STOP_ON_DATA (0x00200106) /* SEP stopped while transfering data */ 168#define PL_LOGINFO_SUB_CODE_SATA_NON_NCQ_RW_ERR_BIT_SET (0x00000600)
163#define PL_LOGINFO_DA_SEP_STOP_ON_SENSE_DATA (0x00200107) /* SEP stopped while transfering sense data */ 169#define PL_LOGINFO_SUB_CODE_SATA_READ_LOG_RECEIVE_DATA_ERR (0x00000700)
164#define PL_LOGINFO_DA_SEP_UNSUPPORTED_SCSI_STATUS_1 (0x00200108) /* SEP returned unknown scsi status */ 170#define PL_LOGINFO_SUB_CODE_SATA_NCQ_FAIL_ALL_CMDS_AFTR_ERR (0x00000800)
165#define PL_LOGINFO_DA_SEP_UNSUPPORTED_SCSI_STATUS_2 (0x00200109) /* SEP returned unknown scsi status */ 171#define PL_LOGINFO_SUB_CODE_SATA_ERR_IN_RCV_SET_DEV_BIT_FIS (0x00000900)
166#define PL_LOGINFO_DA_SEP_CHKSUM_ERROR_AFTER_STOP (0x0020010A) /* SEP returned bad chksum after STOP */ 172#define PL_LOGINFO_SUB_CODE_RX_FM_INVALID_MESSAGE (0x00000A00)
167#define PL_LOGINFO_DA_SEP_CHKSUM_ERROR_AFTER_STOP_GETDATA (0x0020010B) /* SEP returned bad chksum after STOP while gettin data*/ 173#define PL_LOGINFO_SUB_CODE_RX_CTX_MESSAGE_VALID_ERROR (0x00000B00)
168#define PL_LOGINFO_DA_SEP_UNSUPPORTED_COMMAND (0x0020010C) /* SEP doesn't support CDB opcode */ 174#define PL_LOGINFO_SUB_CODE_RX_FM_CURRENT_FRAME_ERROR (0x00000C00)
175#define PL_LOGINFO_SUB_CODE_SATA_LINK_DOWN (0x00000D00)
176#define PL_LOGINFO_SUB_CODE_DISCOVERY_SATA_INIT_W_IOS (0x00000E00)
177#define PL_LOGINFO_SUB_CODE_DISCOVERY_REMOTE_SEP_RESET (0x00000E01)
178#define PL_LOGINFO_SUB_CODE_SECOND_OPEN (0x00000F00)
179#define PL_LOGINFO_SUB_CODE_DSCVRY_SATA_INIT_TIMEOUT (0x00001000)
180
181#define PL_LOGINFO_CODE_ENCL_MGMT_SMP_FRAME_FAILURE (0x00200000) /* Can't get SMP Frame */
182#define PL_LOGINFO_CODE_ENCL_MGMT_SMP_READ_ERROR (0x00200010) /* Error occured on SMP Read */
183#define PL_LOGINFO_CODE_ENCL_MGMT_SMP_WRITE_ERROR (0x00200020) /* Error occured on SMP Write */
184#define PL_LOGINFO_CODE_ENCL_MGMT_NOT_SUPPORTED_ON_ENCL (0x00200040) /* Encl Mgmt services not available for this WWID */
185#define PL_LOGINFO_CODE_ENCL_MGMT_ADDR_MODE_NOT_SUPPORTED (0x00200050) /* Address Mode not suppored */
186#define PL_LOGINFO_CODE_ENCL_MGMT_BAD_SLOT_NUM (0x00200060) /* Invalid Slot Number in SEP Msg */
187#define PL_LOGINFO_CODE_ENCL_MGMT_SGPIO_NOT_PRESENT (0x00200070) /* SGPIO not present/enabled */
188#define PL_LOGINFO_CODE_ENCL_MGMT_GPIO_NOT_CONFIGURED (0x00200080) /* GPIO not configured */
189#define PL_LOGINFO_CODE_ENCL_MGMT_GPIO_FRAME_ERROR (0x00200090) /* GPIO can't allocate a frame */
190#define PL_LOGINFO_CODE_ENCL_MGMT_GPIO_CONFIG_PAGE_ERROR (0x002000A0) /* GPIO failed config page request */
191#define PL_LOGINFO_CODE_ENCL_MGMT_SES_FRAME_ALLOC_ERROR (0x002000B0) /* Can't get frame for SES command */
192#define PL_LOGINFO_CODE_ENCL_MGMT_SES_IO_ERROR (0x002000C0) /* I/O execution error */
193#define PL_LOGINFO_CODE_ENCL_MGMT_SES_RETRIES_EXHAUSTED (0x002000D0) /* SEP I/O retries exhausted */
194#define PL_LOGINFO_CODE_ENCL_MGMT_SMP_FRAME_ALLOC_ERROR (0x002000E0) /* Can't get frame for SMP command */
195
196#define PL_LOGINFO_DA_SEP_NOT_PRESENT (0x00200100) /* SEP not present when msg received */
197#define PL_LOGINFO_DA_SEP_SINGLE_THREAD_ERROR (0x00200101) /* Can only accept 1 msg at a time */
198#define PL_LOGINFO_DA_SEP_ISTWI_INTR_IN_IDLE_STATE (0x00200102) /* ISTWI interrupt recvd. while IDLE */
199#define PL_LOGINFO_DA_SEP_RECEIVED_NACK_FROM_SLAVE (0x00200103) /* SEP NACK'd, it is busy */
200#define PL_LOGINFO_DA_SEP_DID_NOT_RECEIVE_ACK (0x00200104) /* SEP didn't rcv. ACK (Last Rcvd Bit = 1) */
201#define PL_LOGINFO_DA_SEP_BAD_STATUS_HDR_CHKSUM (0x00200105) /* SEP stopped or sent bad chksum in Hdr */
202#define PL_LOGINFO_DA_SEP_STOP_ON_DATA (0x00200106) /* SEP stopped while transfering data */
203#define PL_LOGINFO_DA_SEP_STOP_ON_SENSE_DATA (0x00200107) /* SEP stopped while transfering sense data */
204#define PL_LOGINFO_DA_SEP_UNSUPPORTED_SCSI_STATUS_1 (0x00200108) /* SEP returned unknown scsi status */
205#define PL_LOGINFO_DA_SEP_UNSUPPORTED_SCSI_STATUS_2 (0x00200109) /* SEP returned unknown scsi status */
206#define PL_LOGINFO_DA_SEP_CHKSUM_ERROR_AFTER_STOP (0x0020010A) /* SEP returned bad chksum after STOP */
207#define PL_LOGINFO_DA_SEP_CHKSUM_ERROR_AFTER_STOP_GETDATA (0x0020010B) /* SEP returned bad chksum after STOP while gettin data*/
208#define PL_LOGINFO_DA_SEP_UNSUPPORTED_COMMAND (0x0020010C) /* SEP doesn't support CDB opcode f/w location 1 */
209#define PL_LOGINFO_DA_SEP_UNSUPPORTED_COMMAND_2 (0x0020010D) /* SEP doesn't support CDB opcode f/w location 2 */
210#define PL_LOGINFO_DA_SEP_UNSUPPORTED_COMMAND_3 (0x0020010E) /* SEP doesn't support CDB opcode f/w location 3 */
169 211
170 212
171/****************************************************************************/ 213/****************************************************************************/
diff --git a/drivers/message/fusion/lsi/mpi_sas.h b/drivers/message/fusion/lsi/mpi_sas.h
index 50b8f0a8f45..8e990a0fa7a 100644
--- a/drivers/message/fusion/lsi/mpi_sas.h
+++ b/drivers/message/fusion/lsi/mpi_sas.h
@@ -1,12 +1,12 @@
1/* 1/*
2 * Copyright (c) 2004 LSI Logic Corporation. 2 * Copyright (c) 2004-2006 LSI Logic Corporation.
3 * 3 *
4 * 4 *
5 * Name: mpi_sas.h 5 * Name: mpi_sas.h
6 * Title: MPI Serial Attached SCSI structures and definitions 6 * Title: MPI Serial Attached SCSI structures and definitions
7 * Creation Date: August 19, 2004 7 * Creation Date: August 19, 2004
8 * 8 *
9 * mpi_sas.h Version: 01.05.03 9 * mpi_sas.h Version: 01.05.04
10 * 10 *
11 * Version History 11 * Version History
12 * --------------- 12 * ---------------
@@ -21,6 +21,8 @@
21 * and Remove Device operations to SAS IO Unit Control. 21 * and Remove Device operations to SAS IO Unit Control.
22 * Added DevHandle field to SAS IO Unit Control request and 22 * Added DevHandle field to SAS IO Unit Control request and
23 * reply. 23 * reply.
24 * 10-11-06 01.05.04 Fixed the name of a define for Operation field of SAS IO
25 * Unit Control request.
24 * -------------------------------------------------------------------------- 26 * --------------------------------------------------------------------------
25 */ 27 */
26 28
@@ -237,7 +239,8 @@ typedef struct _MSG_SAS_IOUNIT_CONTROL_REQUEST
237#define MPI_SAS_OP_SEND_PRIMITIVE (0x0A) 239#define MPI_SAS_OP_SEND_PRIMITIVE (0x0A)
238#define MPI_SAS_OP_FORCE_FULL_DISCOVERY (0x0B) 240#define MPI_SAS_OP_FORCE_FULL_DISCOVERY (0x0B)
239#define MPI_SAS_OP_TRANSMIT_PORT_SELECT_SIGNAL (0x0C) 241#define MPI_SAS_OP_TRANSMIT_PORT_SELECT_SIGNAL (0x0C)
240#define MPI_SAS_OP_TRANSMIT_REMOVE_DEVICE (0x0D) 242#define MPI_SAS_OP_TRANSMIT_REMOVE_DEVICE (0x0D) /* obsolete name */
243#define MPI_SAS_OP_REMOVE_DEVICE (0x0D)
241 244
242/* values for the PrimFlags field */ 245/* values for the PrimFlags field */
243#define MPI_SAS_PRIMFLAGS_SINGLE (0x08) 246#define MPI_SAS_PRIMFLAGS_SINGLE (0x08)
diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
index b3f28a03b6a..083acfd91d8 100644
--- a/drivers/message/fusion/mptbase.c
+++ b/drivers/message/fusion/mptbase.c
@@ -6,7 +6,7 @@
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2007 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsi.com)
10 * 10 *
11 */ 11 */
12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -82,6 +82,10 @@ static int mpt_msi_enable;
82module_param(mpt_msi_enable, int, 0); 82module_param(mpt_msi_enable, int, 0);
83MODULE_PARM_DESC(mpt_msi_enable, " MSI Support Enable (default=0)"); 83MODULE_PARM_DESC(mpt_msi_enable, " MSI Support Enable (default=0)");
84 84
85static int mpt_channel_mapping;
86module_param(mpt_channel_mapping, int, 0);
87MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");
88
85#ifdef MFCNT 89#ifdef MFCNT
86static int mfcounter = 0; 90static int mfcounter = 0;
87#define PRINT_MF_COUNT 20000 91#define PRINT_MF_COUNT 20000
@@ -173,11 +177,14 @@ static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
173 177
174//int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag); 178//int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
175static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers); 179static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
176static void mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf); 180#ifdef MPT_DEBUG_REPLY
181static void mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
182#endif
177static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info); 183static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
178static void mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info); 184static void mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info);
179static void mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info); 185static void mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info);
180static int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc); 186static int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
187static void mpt_inactive_raid_list_free(MPT_ADAPTER *ioc);
181 188
182/* module entry point */ 189/* module entry point */
183static int __init fusion_init (void); 190static int __init fusion_init (void);
@@ -319,13 +326,11 @@ mpt_reply(MPT_ADAPTER *ioc, u32 pa)
319 else if (ioc->bus_type == SAS) 326 else if (ioc->bus_type == SAS)
320 mpt_sas_log_info(ioc, log_info); 327 mpt_sas_log_info(ioc, log_info);
321 } 328 }
322 if (ioc_stat & MPI_IOCSTATUS_MASK) {
323 if (ioc->bus_type == SPI &&
324 cb_idx != mpt_stm_index &&
325 cb_idx != mpt_lan_index)
326 mpt_sp_ioc_info(ioc, (u32)ioc_stat, mf);
327 }
328 329
330#ifdef MPT_DEBUG_REPLY
331 if (ioc_stat & MPI_IOCSTATUS_MASK)
332 mpt_iocstatus_info(ioc, (u32)ioc_stat, mf);
333#endif
329 334
330 /* Check for (valid) IO callback! */ 335 /* Check for (valid) IO callback! */
331 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS || 336 if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
@@ -911,7 +916,7 @@ mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
911int 916int
912mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag) 917mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
913{ 918{
914 int r = 0; 919 int r = 0;
915 u8 *req_as_bytes; 920 u8 *req_as_bytes;
916 int ii; 921 int ii;
917 922
@@ -1811,6 +1816,13 @@ mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
1811 * and we try GetLanConfigPages again... 1816 * and we try GetLanConfigPages again...
1812 */ 1817 */
1813 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) { 1818 if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
1819
1820 /*
1821 * Initalize link list for inactive raid volumes.
1822 */
1823 init_MUTEX(&ioc->raid_data.inactive_list_mutex);
1824 INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
1825
1814 if (ioc->bus_type == SAS) { 1826 if (ioc->bus_type == SAS) {
1815 1827
1816 /* clear persistency table */ 1828 /* clear persistency table */
@@ -2017,6 +2029,8 @@ mpt_adapter_disable(MPT_ADAPTER *ioc)
2017 } 2029 }
2018 2030
2019 kfree(ioc->spi_data.nvram); 2031 kfree(ioc->spi_data.nvram);
2032 mpt_inactive_raid_list_free(ioc);
2033 kfree(ioc->raid_data.pIocPg2);
2020 kfree(ioc->raid_data.pIocPg3); 2034 kfree(ioc->raid_data.pIocPg3);
2021 ioc->spi_data.nvram = NULL; 2035 ioc->spi_data.nvram = NULL;
2022 ioc->raid_data.pIocPg3 = NULL; 2036 ioc->raid_data.pIocPg3 = NULL;
@@ -2413,6 +2427,9 @@ GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
2413 facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word); 2427 facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
2414 2428
2415 facts->ProductID = le16_to_cpu(facts->ProductID); 2429 facts->ProductID = le16_to_cpu(facts->ProductID);
2430 if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
2431 > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
2432 ioc->ir_firmware = 1;
2416 facts->CurrentHostMfaHighAddr = 2433 facts->CurrentHostMfaHighAddr =
2417 le32_to_cpu(facts->CurrentHostMfaHighAddr); 2434 le32_to_cpu(facts->CurrentHostMfaHighAddr);
2418 facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits); 2435 facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
@@ -2505,6 +2522,7 @@ GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2505 int ii; 2522 int ii;
2506 int req_sz; 2523 int req_sz;
2507 int reply_sz; 2524 int reply_sz;
2525 int max_id;
2508 2526
2509 /* IOC *must* NOT be in RESET state! */ 2527 /* IOC *must* NOT be in RESET state! */
2510 if (ioc->last_state == MPI_IOC_STATE_RESET) { 2528 if (ioc->last_state == MPI_IOC_STATE_RESET) {
@@ -2552,6 +2570,21 @@ GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2552 pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs); 2570 pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
2553 pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets); 2571 pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
2554 2572
2573 max_id = (ioc->bus_type == SAS) ? pfacts->PortSCSIID :
2574 pfacts->MaxDevices;
2575 ioc->devices_per_bus = (max_id > 255) ? 256 : max_id;
2576 ioc->number_of_buses = (ioc->devices_per_bus < 256) ? 1 : max_id/256;
2577
2578 /*
2579 * Place all the devices on channels
2580 *
2581 * (for debuging)
2582 */
2583 if (mpt_channel_mapping) {
2584 ioc->devices_per_bus = 1;
2585 ioc->number_of_buses = (max_id > 255) ? 255 : max_id;
2586 }
2587
2555 return 0; 2588 return 0;
2556} 2589}
2557 2590
@@ -2592,13 +2625,8 @@ SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
2592 ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n", 2625 ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
2593 ioc->name, ioc->upload_fw, ioc->facts.Flags)); 2626 ioc->name, ioc->upload_fw, ioc->facts.Flags));
2594 2627
2595 if(ioc->bus_type == SAS) 2628 ioc_init.MaxDevices = (U8)ioc->devices_per_bus;
2596 ioc_init.MaxDevices = ioc->facts.MaxDevices; 2629 ioc_init.MaxBuses = (U8)ioc->number_of_buses;
2597 else if(ioc->bus_type == FC)
2598 ioc_init.MaxDevices = MPT_MAX_FC_DEVICES;
2599 else
2600 ioc_init.MaxDevices = MPT_MAX_SCSI_DEVICES;
2601 ioc_init.MaxBuses = MPT_MAX_BUS;
2602 dinitprintk((MYIOC_s_INFO_FMT "facts.MsgVersion=%x\n", 2630 dinitprintk((MYIOC_s_INFO_FMT "facts.MsgVersion=%x\n",
2603 ioc->name, ioc->facts.MsgVersion)); 2631 ioc->name, ioc->facts.MsgVersion));
2604 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) { 2632 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
@@ -2720,9 +2748,7 @@ SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
2720 2748
2721 /* RAID FW may take a long time to enable 2749 /* RAID FW may take a long time to enable
2722 */ 2750 */
2723 if (((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK) 2751 if (ioc->ir_firmware || ioc->bus_type == SAS) {
2724 > MPI_FW_HEADER_PID_PROD_TARGET_SCSI) ||
2725 (ioc->bus_type == SAS)) {
2726 rc = mpt_handshake_req_reply_wait(ioc, req_sz, 2752 rc = mpt_handshake_req_reply_wait(ioc, req_sz,
2727 (u32*)&port_enable, reply_sz, (u16*)&reply_buf, 2753 (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
2728 300 /*seconds*/, sleepFlag); 2754 300 /*seconds*/, sleepFlag);
@@ -3193,6 +3219,9 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3193 u32 diag1val = 0; 3219 u32 diag1val = 0;
3194#endif 3220#endif
3195 3221
3222 /* Clear any existing interrupts */
3223 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3224
3196 if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) { 3225 if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
3197 drsprintk((MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset " 3226 drsprintk((MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
3198 "address=%p\n", ioc->name, __FUNCTION__, 3227 "address=%p\n", ioc->name, __FUNCTION__,
@@ -3212,7 +3241,7 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3212 " count=%d\n", 3241 " count=%d\n",
3213 ioc->name, doorbell, count)); 3242 ioc->name, doorbell, count));
3214 if (doorbell == MPI_IOC_STATE_READY) { 3243 if (doorbell == MPI_IOC_STATE_READY) {
3215 return 0; 3244 return 1;
3216 } 3245 }
3217 3246
3218 /* wait 1 sec */ 3247 /* wait 1 sec */
@@ -3224,9 +3253,6 @@ mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
3224 return -1; 3253 return -1;
3225 } 3254 }
3226 3255
3227 /* Clear any existing interrupts */
3228 CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
3229
3230 /* Use "Diagnostic reset" method! (only thing available!) */ 3256 /* Use "Diagnostic reset" method! (only thing available!) */
3231 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic); 3257 diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
3232 3258
@@ -3942,7 +3968,7 @@ WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3942 } 3968 }
3943 } else { 3969 } else {
3944 while (--cntdn) { 3970 while (--cntdn) {
3945 mdelay (1); 3971 udelay (1000);
3946 intstat = CHIPREG_READ32(&ioc->chip->IntStatus); 3972 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3947 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS)) 3973 if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
3948 break; 3974 break;
@@ -3994,7 +4020,7 @@ WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
3994 intstat = CHIPREG_READ32(&ioc->chip->IntStatus); 4020 intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
3995 if (intstat & MPI_HIS_DOORBELL_INTERRUPT) 4021 if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
3996 break; 4022 break;
3997 mdelay(1); 4023 udelay (1000);
3998 count++; 4024 count++;
3999 } 4025 }
4000 } 4026 }
@@ -4310,8 +4336,8 @@ mptbase_raid_process_event_data(MPT_ADAPTER *ioc,
4310 if ((reason >= MPI_EVENT_RAID_RC_PHYSDISK_CREATED && 4336 if ((reason >= MPI_EVENT_RAID_RC_PHYSDISK_CREATED &&
4311 reason <= MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED) || 4337 reason <= MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED) ||
4312 (reason == MPI_EVENT_RAID_RC_SMART_DATA)) { 4338 (reason == MPI_EVENT_RAID_RC_SMART_DATA)) {
4313 printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for PhysDisk %d\n", 4339 printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for PhysDisk %d id=%d\n",
4314 ioc->name, disk); 4340 ioc->name, disk, volume);
4315 } else { 4341 } else {
4316 printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for VolumeID %d\n", 4342 printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for VolumeID %d\n",
4317 ioc->name, volume); 4343 ioc->name, volume);
@@ -4712,7 +4738,187 @@ mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
4712 return 0; 4738 return 0;
4713} 4739}
4714 4740
4715/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 4741/**
4742 * mpt_inactive_raid_list_free
4743 *
4744 * This clears this link list.
4745 *
4746 * @ioc - pointer to per adapter structure
4747 *
4748 **/
4749static void
4750mpt_inactive_raid_list_free(MPT_ADAPTER *ioc)
4751{
4752 struct inactive_raid_component_info *component_info, *pNext;
4753
4754 if (list_empty(&ioc->raid_data.inactive_list))
4755 return;
4756
4757 down(&ioc->raid_data.inactive_list_mutex);
4758 list_for_each_entry_safe(component_info, pNext,
4759 &ioc->raid_data.inactive_list, list) {
4760 list_del(&component_info->list);
4761 kfree(component_info);
4762 }
4763 up(&ioc->raid_data.inactive_list_mutex);
4764}
4765
4766/**
4767 * mpt_inactive_raid_volumes
4768 *
4769 * This sets up link list of phy_disk_nums for devices belonging in an inactive volume
4770 *
4771 * @ioc - pointer to per adapter structure
4772 * @channel - volume channel
4773 * @id - volume target id
4774 *
4775 *
4776 **/
4777static void
4778mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
4779{
4780 CONFIGPARMS cfg;
4781 ConfigPageHeader_t hdr;
4782 dma_addr_t dma_handle;
4783 pRaidVolumePage0_t buffer = NULL;
4784 int i;
4785 RaidPhysDiskPage0_t phys_disk;
4786 struct inactive_raid_component_info *component_info;
4787 int handle_inactive_volumes;
4788
4789 memset(&cfg, 0 , sizeof(CONFIGPARMS));
4790 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
4791 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
4792 cfg.pageAddr = (channel << 8) + id;
4793 cfg.cfghdr.hdr = &hdr;
4794 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4795
4796 if (mpt_config(ioc, &cfg) != 0)
4797 goto out;
4798
4799 if (!hdr.PageLength)
4800 goto out;
4801
4802 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
4803 &dma_handle);
4804
4805 if (!buffer)
4806 goto out;
4807
4808 cfg.physAddr = dma_handle;
4809 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4810
4811 if (mpt_config(ioc, &cfg) != 0)
4812 goto out;
4813
4814 if (!buffer->NumPhysDisks)
4815 goto out;
4816
4817 handle_inactive_volumes =
4818 (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE ||
4819 (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED) == 0 ||
4820 buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_FAILED ||
4821 buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_MISSING) ? 1 : 0;
4822
4823 if (!handle_inactive_volumes)
4824 goto out;
4825
4826 down(&ioc->raid_data.inactive_list_mutex);
4827 for (i = 0; i < buffer->NumPhysDisks; i++) {
4828 if(mpt_raid_phys_disk_pg0(ioc,
4829 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
4830 continue;
4831
4832 if ((component_info = kmalloc(sizeof (*component_info),
4833 GFP_KERNEL)) == NULL)
4834 continue;
4835
4836 component_info->volumeID = id;
4837 component_info->volumeBus = channel;
4838 component_info->d.PhysDiskNum = phys_disk.PhysDiskNum;
4839 component_info->d.PhysDiskBus = phys_disk.PhysDiskBus;
4840 component_info->d.PhysDiskID = phys_disk.PhysDiskID;
4841 component_info->d.PhysDiskIOC = phys_disk.PhysDiskIOC;
4842
4843 list_add_tail(&component_info->list,
4844 &ioc->raid_data.inactive_list);
4845 }
4846 up(&ioc->raid_data.inactive_list_mutex);
4847
4848 out:
4849 if (buffer)
4850 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
4851 dma_handle);
4852}
4853
4854/**
4855 * mpt_raid_phys_disk_pg0 - returns phys disk page zero
4856 * @ioc: Pointer to a Adapter Structure
4857 * @phys_disk_num: io unit unique phys disk num generated by the ioc
4858 * @phys_disk: requested payload data returned
4859 *
4860 * Return:
4861 * 0 on success
4862 * -EFAULT if read of config page header fails or data pointer not NULL
4863 * -ENOMEM if pci_alloc failed
4864 **/
4865int
4866mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage0_t phys_disk)
4867{
4868 CONFIGPARMS cfg;
4869 ConfigPageHeader_t hdr;
4870 dma_addr_t dma_handle;
4871 pRaidPhysDiskPage0_t buffer = NULL;
4872 int rc;
4873
4874 memset(&cfg, 0 , sizeof(CONFIGPARMS));
4875 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
4876
4877 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
4878 cfg.cfghdr.hdr = &hdr;
4879 cfg.physAddr = -1;
4880 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
4881
4882 if (mpt_config(ioc, &cfg) != 0) {
4883 rc = -EFAULT;
4884 goto out;
4885 }
4886
4887 if (!hdr.PageLength) {
4888 rc = -EFAULT;
4889 goto out;
4890 }
4891
4892 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
4893 &dma_handle);
4894
4895 if (!buffer) {
4896 rc = -ENOMEM;
4897 goto out;
4898 }
4899
4900 cfg.physAddr = dma_handle;
4901 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4902 cfg.pageAddr = phys_disk_num;
4903
4904 if (mpt_config(ioc, &cfg) != 0) {
4905 rc = -EFAULT;
4906 goto out;
4907 }
4908
4909 rc = 0;
4910 memcpy(phys_disk, buffer, sizeof(*buffer));
4911 phys_disk->MaxLBA = le32_to_cpu(buffer->MaxLBA);
4912
4913 out:
4914
4915 if (buffer)
4916 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
4917 dma_handle);
4918
4919 return rc;
4920}
4921
4716/** 4922/**
4717 * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes 4923 * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
4718 * @ioc: Pointer to a Adapter Strucutre 4924 * @ioc: Pointer to a Adapter Strucutre
@@ -4722,21 +4928,27 @@ mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
4722 * 0 on success 4928 * 0 on success
4723 * -EFAULT if read of config page header fails or data pointer not NULL 4929 * -EFAULT if read of config page header fails or data pointer not NULL
4724 * -ENOMEM if pci_alloc failed 4930 * -ENOMEM if pci_alloc failed
4725 */ 4931 **/
4726int 4932int
4727mpt_findImVolumes(MPT_ADAPTER *ioc) 4933mpt_findImVolumes(MPT_ADAPTER *ioc)
4728{ 4934{
4729 IOCPage2_t *pIoc2; 4935 IOCPage2_t *pIoc2;
4730 u8 *mem; 4936 u8 *mem;
4731 ConfigPageIoc2RaidVol_t *pIocRv;
4732 dma_addr_t ioc2_dma; 4937 dma_addr_t ioc2_dma;
4733 CONFIGPARMS cfg; 4938 CONFIGPARMS cfg;
4734 ConfigPageHeader_t header; 4939 ConfigPageHeader_t header;
4735 int jj;
4736 int rc = 0; 4940 int rc = 0;
4737 int iocpage2sz; 4941 int iocpage2sz;
4738 u8 nVols, nPhys; 4942 int i;
4739 u8 vid, vbus, vioc; 4943
4944 if (!ioc->ir_firmware)
4945 return 0;
4946
4947 /* Free the old page
4948 */
4949 kfree(ioc->raid_data.pIocPg2);
4950 ioc->raid_data.pIocPg2 = NULL;
4951 mpt_inactive_raid_list_free(ioc);
4740 4952
4741 /* Read IOCP2 header then the page. 4953 /* Read IOCP2 header then the page.
4742 */ 4954 */
@@ -4764,55 +4976,23 @@ mpt_findImVolumes(MPT_ADAPTER *ioc)
4764 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 4976 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4765 cfg.physAddr = ioc2_dma; 4977 cfg.physAddr = ioc2_dma;
4766 if (mpt_config(ioc, &cfg) != 0) 4978 if (mpt_config(ioc, &cfg) != 0)
4767 goto done_and_free; 4979 goto out;
4980
4981 mem = kmalloc(iocpage2sz, GFP_KERNEL);
4982 if (!mem)
4983 goto out;
4768 4984
4769 if ( (mem = (u8 *)ioc->raid_data.pIocPg2) == NULL ) {
4770 mem = kmalloc(iocpage2sz, GFP_ATOMIC);
4771 if (mem) {
4772 ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
4773 } else {
4774 goto done_and_free;
4775 }
4776 }
4777 memcpy(mem, (u8 *)pIoc2, iocpage2sz); 4985 memcpy(mem, (u8 *)pIoc2, iocpage2sz);
4986 ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
4778 4987
4779 /* Identify RAID Volume Id's */ 4988 mpt_read_ioc_pg_3(ioc);
4780 nVols = pIoc2->NumActiveVolumes;
4781 if ( nVols == 0) {
4782 /* No RAID Volume.
4783 */
4784 goto done_and_free;
4785 } else {
4786 /* At least 1 RAID Volume
4787 */
4788 pIocRv = pIoc2->RaidVolume;
4789 ioc->raid_data.isRaid = 0;
4790 for (jj = 0; jj < nVols; jj++, pIocRv++) {
4791 vid = pIocRv->VolumeID;
4792 vbus = pIocRv->VolumeBus;
4793 vioc = pIocRv->VolumeIOC;
4794
4795 /* find the match
4796 */
4797 if (vbus == 0) {
4798 ioc->raid_data.isRaid |= (1 << vid);
4799 } else {
4800 /* Error! Always bus 0
4801 */
4802 }
4803 }
4804 }
4805 4989
4806 /* Identify Hidden Physical Disk Id's */ 4990 for (i = 0; i < pIoc2->NumActiveVolumes ; i++)
4807 nPhys = pIoc2->NumActivePhysDisks; 4991 mpt_inactive_raid_volumes(ioc,
4808 if (nPhys == 0) { 4992 pIoc2->RaidVolume[i].VolumeBus,
4809 /* No physical disks. 4993 pIoc2->RaidVolume[i].VolumeID);
4810 */
4811 } else {
4812 mpt_read_ioc_pg_3(ioc);
4813 }
4814 4994
4815done_and_free: 4995 out:
4816 pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma); 4996 pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
4817 4997
4818 return rc; 4998 return rc;
@@ -4865,7 +5045,7 @@ mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
4865 cfg.physAddr = ioc3_dma; 5045 cfg.physAddr = ioc3_dma;
4866 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT; 5046 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
4867 if (mpt_config(ioc, &cfg) == 0) { 5047 if (mpt_config(ioc, &cfg) == 0) {
4868 mem = kmalloc(iocpage3sz, GFP_ATOMIC); 5048 mem = kmalloc(iocpage3sz, GFP_KERNEL);
4869 if (mem) { 5049 if (mem) {
4870 memcpy(mem, (u8 *)pIoc3, iocpage3sz); 5050 memcpy(mem, (u8 *)pIoc3, iocpage3sz);
4871 ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem; 5051 ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem;
@@ -5679,8 +5859,6 @@ mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
5679 return rc; 5859 return rc;
5680} 5860}
5681 5861
5682# define EVENT_DESCR_STR_SZ 100
5683
5684/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 5862/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
5685static void 5863static void
5686EventDescriptionStr(u8 event, u32 evData0, char *evStr) 5864EventDescriptionStr(u8 event, u32 evData0, char *evStr)
@@ -5708,9 +5886,6 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
5708 break; 5886 break;
5709 case MPI_EVENT_RESCAN: 5887 case MPI_EVENT_RESCAN:
5710 ds = "Bus Rescan Event"; 5888 ds = "Bus Rescan Event";
5711 /* Ok, do we need to do anything here? As far as
5712 I can tell, this is when a new device gets added
5713 to the loop. */
5714 break; 5889 break;
5715 case MPI_EVENT_LINK_STATUS_CHANGE: 5890 case MPI_EVENT_LINK_STATUS_CHANGE:
5716 if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE) 5891 if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
@@ -5787,48 +5962,63 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
5787 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE: 5962 case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
5788 { 5963 {
5789 u8 id = (u8)(evData0); 5964 u8 id = (u8)(evData0);
5965 u8 channel = (u8)(evData0 >> 8);
5790 u8 ReasonCode = (u8)(evData0 >> 16); 5966 u8 ReasonCode = (u8)(evData0 >> 16);
5791 switch (ReasonCode) { 5967 switch (ReasonCode) {
5792 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED: 5968 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
5793 snprintf(evStr, EVENT_DESCR_STR_SZ, 5969 snprintf(evStr, EVENT_DESCR_STR_SZ,
5794 "SAS Device Status Change: Added: id=%d", id); 5970 "SAS Device Status Change: Added: "
5971 "id=%d channel=%d", id, channel);
5795 break; 5972 break;
5796 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING: 5973 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
5797 snprintf(evStr, EVENT_DESCR_STR_SZ, 5974 snprintf(evStr, EVENT_DESCR_STR_SZ,
5798 "SAS Device Status Change: Deleted: id=%d", id); 5975 "SAS Device Status Change: Deleted: "
5976 "id=%d channel=%d", id, channel);
5799 break; 5977 break;
5800 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA: 5978 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
5801 snprintf(evStr, EVENT_DESCR_STR_SZ, 5979 snprintf(evStr, EVENT_DESCR_STR_SZ,
5802 "SAS Device Status Change: SMART Data: id=%d", 5980 "SAS Device Status Change: SMART Data: "
5803 id); 5981 "id=%d channel=%d", id, channel);
5804 break; 5982 break;
5805 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED: 5983 case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
5806 snprintf(evStr, EVENT_DESCR_STR_SZ, 5984 snprintf(evStr, EVENT_DESCR_STR_SZ,
5807 "SAS Device Status Change: No Persistancy: id=%d", id); 5985 "SAS Device Status Change: No Persistancy: "
5986 "id=%d channel=%d", id, channel);
5987 break;
5988 case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
5989 snprintf(evStr, EVENT_DESCR_STR_SZ,
5990 "SAS Device Status Change: Unsupported Device "
5991 "Discovered : id=%d channel=%d", id, channel);
5808 break; 5992 break;
5809 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: 5993 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
5810 snprintf(evStr, EVENT_DESCR_STR_SZ, 5994 snprintf(evStr, EVENT_DESCR_STR_SZ,
5811 "SAS Device Status Change: Internal Device Reset : id=%d", id); 5995 "SAS Device Status Change: Internal Device "
5996 "Reset : id=%d channel=%d", id, channel);
5812 break; 5997 break;
5813 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL: 5998 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
5814 snprintf(evStr, EVENT_DESCR_STR_SZ, 5999 snprintf(evStr, EVENT_DESCR_STR_SZ,
5815 "SAS Device Status Change: Internal Task Abort : id=%d", id); 6000 "SAS Device Status Change: Internal Task "
6001 "Abort : id=%d channel=%d", id, channel);
5816 break; 6002 break;
5817 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL: 6003 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
5818 snprintf(evStr, EVENT_DESCR_STR_SZ, 6004 snprintf(evStr, EVENT_DESCR_STR_SZ,
5819 "SAS Device Status Change: Internal Abort Task Set : id=%d", id); 6005 "SAS Device Status Change: Internal Abort "
6006 "Task Set : id=%d channel=%d", id, channel);
5820 break; 6007 break;
5821 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL: 6008 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
5822 snprintf(evStr, EVENT_DESCR_STR_SZ, 6009 snprintf(evStr, EVENT_DESCR_STR_SZ,
5823 "SAS Device Status Change: Internal Clear Task Set : id=%d", id); 6010 "SAS Device Status Change: Internal Clear "
6011 "Task Set : id=%d channel=%d", id, channel);
5824 break; 6012 break;
5825 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL: 6013 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
5826 snprintf(evStr, EVENT_DESCR_STR_SZ, 6014 snprintf(evStr, EVENT_DESCR_STR_SZ,
5827 "SAS Device Status Change: Internal Query Task : id=%d", id); 6015 "SAS Device Status Change: Internal Query "
6016 "Task : id=%d channel=%d", id, channel);
5828 break; 6017 break;
5829 default: 6018 default:
5830 snprintf(evStr, EVENT_DESCR_STR_SZ, 6019 snprintf(evStr, EVENT_DESCR_STR_SZ,
5831 "SAS Device Status Change: Unknown: id=%d", id); 6020 "SAS Device Status Change: Unknown: "
6021 "id=%d channel=%d", id, channel);
5832 break; 6022 break;
5833 } 6023 }
5834 break; 6024 break;
@@ -5837,8 +6027,16 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
5837 ds = "Bus Timer Expired"; 6027 ds = "Bus Timer Expired";
5838 break; 6028 break;
5839 case MPI_EVENT_QUEUE_FULL: 6029 case MPI_EVENT_QUEUE_FULL:
5840 ds = "Queue Full"; 6030 {
6031 u16 curr_depth = (u16)(evData0 >> 16);
6032 u8 channel = (u8)(evData0 >> 8);
6033 u8 id = (u8)(evData0);
6034
6035 snprintf(evStr, EVENT_DESCR_STR_SZ,
6036 "Queue Full: channel=%d id=%d depth=%d",
6037 channel, id, curr_depth);
5841 break; 6038 break;
6039 }
5842 case MPI_EVENT_SAS_SES: 6040 case MPI_EVENT_SAS_SES:
5843 ds = "SAS SES Event"; 6041 ds = "SAS SES Event";
5844 break; 6042 break;
@@ -5942,6 +6140,76 @@ EventDescriptionStr(u8 event, u32 evData0, char *evStr)
5942 ds = "SAS Log Entry Added"; 6140 ds = "SAS Log Entry Added";
5943 break; 6141 break;
5944 6142
6143 case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
6144 {
6145 u8 phy_num = (u8)(evData0);
6146 u8 port_num = (u8)(evData0 >> 8);
6147 u8 port_width = (u8)(evData0 >> 16);
6148 u8 primative = (u8)(evData0 >> 24);
6149 snprintf(evStr, EVENT_DESCR_STR_SZ,
6150 "SAS Broadcase Primative: phy=%d port=%d "
6151 "width=%d primative=0x%02x",
6152 phy_num, port_num, port_width, primative);
6153 break;
6154 }
6155
6156 case MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
6157 {
6158 u8 reason = (u8)(evData0);
6159 u8 port_num = (u8)(evData0 >> 8);
6160 u16 handle = le16_to_cpu(evData0 >> 16);
6161
6162 snprintf(evStr, EVENT_DESCR_STR_SZ,
6163 "SAS Initiator Device Status Change: reason=0x%02x "
6164 "port=%d handle=0x%04x",
6165 reason, port_num, handle);
6166 break;
6167 }
6168
6169 case MPI_EVENT_SAS_INIT_TABLE_OVERFLOW:
6170 {
6171 u8 max_init = (u8)(evData0);
6172 u8 current_init = (u8)(evData0 >> 8);
6173
6174 snprintf(evStr, EVENT_DESCR_STR_SZ,
6175 "SAS Initiator Device Table Overflow: max initiators=%02d "
6176 "current initators=%02d",
6177 max_init, current_init);
6178 break;
6179 }
6180 case MPI_EVENT_SAS_SMP_ERROR:
6181 {
6182 u8 status = (u8)(evData0);
6183 u8 port_num = (u8)(evData0 >> 8);
6184 u8 result = (u8)(evData0 >> 16);
6185
6186 if (status == MPI_EVENT_SAS_SMP_FUNCTION_RESULT_VALID)
6187 snprintf(evStr, EVENT_DESCR_STR_SZ,
6188 "SAS SMP Error: port=%d result=0x%02x",
6189 port_num, result);
6190 else if (status == MPI_EVENT_SAS_SMP_CRC_ERROR)
6191 snprintf(evStr, EVENT_DESCR_STR_SZ,
6192 "SAS SMP Error: port=%d : CRC Error",
6193 port_num);
6194 else if (status == MPI_EVENT_SAS_SMP_TIMEOUT)
6195 snprintf(evStr, EVENT_DESCR_STR_SZ,
6196 "SAS SMP Error: port=%d : Timeout",
6197 port_num);
6198 else if (status == MPI_EVENT_SAS_SMP_NO_DESTINATION)
6199 snprintf(evStr, EVENT_DESCR_STR_SZ,
6200 "SAS SMP Error: port=%d : No Destination",
6201 port_num);
6202 else if (status == MPI_EVENT_SAS_SMP_BAD_DESTINATION)
6203 snprintf(evStr, EVENT_DESCR_STR_SZ,
6204 "SAS SMP Error: port=%d : Bad Destination",
6205 port_num);
6206 else
6207 snprintf(evStr, EVENT_DESCR_STR_SZ,
6208 "SAS SMP Error: port=%d : status=0x%02x",
6209 port_num, status);
6210 break;
6211 }
6212
5945 /* 6213 /*
5946 * MPT base "custom" events may be added here... 6214 * MPT base "custom" events may be added here...
5947 */ 6215 */
@@ -6205,10 +6473,11 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
6205 "Abort", /* 12h */ 6473 "Abort", /* 12h */
6206 "IO Not Yet Executed", /* 13h */ 6474 "IO Not Yet Executed", /* 13h */
6207 "IO Executed", /* 14h */ 6475 "IO Executed", /* 14h */
6208 "Persistent Reservation Out Not Affiliation Owner", /* 15h */ 6476 "Persistent Reservation Out Not Affiliation "
6477 "Owner", /* 15h */
6209 "Open Transmit DMA Abort", /* 16h */ 6478 "Open Transmit DMA Abort", /* 16h */
6210 "IO Device Missing Delay Retry", /* 17h */ 6479 "IO Device Missing Delay Retry", /* 17h */
6211 NULL, /* 18h */ 6480 "IO Cancelled Due to Recieve Error", /* 18h */
6212 NULL, /* 19h */ 6481 NULL, /* 19h */
6213 NULL, /* 1Ah */ 6482 NULL, /* 1Ah */
6214 NULL, /* 1Bh */ 6483 NULL, /* 1Bh */
@@ -6218,6 +6487,96 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
6218 NULL, /* 1Fh */ 6487 NULL, /* 1Fh */
6219 "Enclosure Management" /* 20h */ 6488 "Enclosure Management" /* 20h */
6220 }; 6489 };
6490 static char *ir_code_str[] = {
6491 "Raid Action Error", /* 00h */
6492 NULL, /* 00h */
6493 NULL, /* 01h */
6494 NULL, /* 02h */
6495 NULL, /* 03h */
6496 NULL, /* 04h */
6497 NULL, /* 05h */
6498 NULL, /* 06h */
6499 NULL /* 07h */
6500 };
6501 static char *raid_sub_code_str[] = {
6502 NULL, /* 00h */
6503 "Volume Creation Failed: Data Passed too "
6504 "Large", /* 01h */
6505 "Volume Creation Failed: Duplicate Volumes "
6506 "Attempted", /* 02h */
6507 "Volume Creation Failed: Max Number "
6508 "Supported Volumes Exceeded", /* 03h */
6509 "Volume Creation Failed: DMA Error", /* 04h */
6510 "Volume Creation Failed: Invalid Volume Type", /* 05h */
6511 "Volume Creation Failed: Error Reading "
6512 "MFG Page 4", /* 06h */
6513 "Volume Creation Failed: Creating Internal "
6514 "Structures", /* 07h */
6515 NULL, /* 08h */
6516 NULL, /* 09h */
6517 NULL, /* 0Ah */
6518 NULL, /* 0Bh */
6519 NULL, /* 0Ch */
6520 NULL, /* 0Dh */
6521 NULL, /* 0Eh */
6522 NULL, /* 0Fh */
6523 "Activation failed: Already Active Volume", /* 10h */
6524 "Activation failed: Unsupported Volume Type", /* 11h */
6525 "Activation failed: Too Many Active Volumes", /* 12h */
6526 "Activation failed: Volume ID in Use", /* 13h */
6527 "Activation failed: Reported Failure", /* 14h */
6528 "Activation failed: Importing a Volume", /* 15h */
6529 NULL, /* 16h */
6530 NULL, /* 17h */
6531 NULL, /* 18h */
6532 NULL, /* 19h */
6533 NULL, /* 1Ah */
6534 NULL, /* 1Bh */
6535 NULL, /* 1Ch */
6536 NULL, /* 1Dh */
6537 NULL, /* 1Eh */
6538 NULL, /* 1Fh */
6539 "Phys Disk failed: Too Many Phys Disks", /* 20h */
6540 "Phys Disk failed: Data Passed too Large", /* 21h */
6541 "Phys Disk failed: DMA Error", /* 22h */
6542 "Phys Disk failed: Invalid <channel:id>", /* 23h */
6543 "Phys Disk failed: Creating Phys Disk Config "
6544 "Page", /* 24h */
6545 NULL, /* 25h */
6546 NULL, /* 26h */
6547 NULL, /* 27h */
6548 NULL, /* 28h */
6549 NULL, /* 29h */
6550 NULL, /* 2Ah */
6551 NULL, /* 2Bh */
6552 NULL, /* 2Ch */
6553 NULL, /* 2Dh */
6554 NULL, /* 2Eh */
6555 NULL, /* 2Fh */
6556 "Compatibility Error: IR Disabled", /* 30h */
6557 "Compatibility Error: Inquiry Comand Failed", /* 31h */
6558 "Compatibility Error: Device not Direct Access "
6559 "Device ", /* 32h */
6560 "Compatibility Error: Removable Device Found", /* 33h */
6561 "Compatibility Error: Device SCSI Version not "
6562 "2 or Higher", /* 34h */
6563 "Compatibility Error: SATA Device, 48 BIT LBA "
6564 "not Supported", /* 35h */
6565 "Compatibility Error: Device doesn't have "
6566 "512 Byte Block Sizes", /* 36h */
6567 "Compatibility Error: Volume Type Check Failed", /* 37h */
6568 "Compatibility Error: Volume Type is "
6569 "Unsupported by FW", /* 38h */
6570 "Compatibility Error: Disk Drive too Small for "
6571 "use in Volume", /* 39h */
6572 "Compatibility Error: Phys Disk for Create "
6573 "Volume not Found", /* 3Ah */
6574 "Compatibility Error: Too Many or too Few "
6575 "Disks for Volume Type", /* 3Bh */
6576 "Compatibility Error: Disk stripe Sizes "
6577 "Must be 64KB", /* 3Ch */
6578 "Compatibility Error: IME Size Limited to < 2TB", /* 3Dh */
6579 };
6221 6580
6222/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6581/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6223/** 6582/**
@@ -6226,7 +6585,7 @@ mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
6226 * @log_info: U32 LogInfo reply word from the IOC 6585 * @log_info: U32 LogInfo reply word from the IOC
6227 * 6586 *
6228 * Refer to lsi/mpi_log_sas.h. 6587 * Refer to lsi/mpi_log_sas.h.
6229 */ 6588 **/
6230static void 6589static void
6231mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info) 6590mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info)
6232{ 6591{
@@ -6240,56 +6599,165 @@ union loginfo_type {
6240 }dw; 6599 }dw;
6241}; 6600};
6242 union loginfo_type sas_loginfo; 6601 union loginfo_type sas_loginfo;
6602 char *originator_desc = NULL;
6243 char *code_desc = NULL; 6603 char *code_desc = NULL;
6604 char *sub_code_desc = NULL;
6244 6605
6245 sas_loginfo.loginfo = log_info; 6606 sas_loginfo.loginfo = log_info;
6246 if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) && 6607 if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) &&
6247 (sas_loginfo.dw.originator < sizeof(originator_str)/sizeof(char*))) 6608 (sas_loginfo.dw.originator < sizeof(originator_str)/sizeof(char*)))
6248 return; 6609 return;
6249 if ((sas_loginfo.dw.originator == 0 /*IOP*/) && 6610
6250 (sas_loginfo.dw.code < sizeof(iop_code_str)/sizeof(char*))) { 6611 originator_desc = originator_str[sas_loginfo.dw.originator];
6251 code_desc = iop_code_str[sas_loginfo.dw.code]; 6612
6252 }else if ((sas_loginfo.dw.originator == 1 /*PL*/) && 6613 switch (sas_loginfo.dw.originator) {
6253 (sas_loginfo.dw.code < sizeof(pl_code_str)/sizeof(char*) )) { 6614
6254 code_desc = pl_code_str[sas_loginfo.dw.code]; 6615 case 0: /* IOP */
6616 if (sas_loginfo.dw.code <
6617 sizeof(iop_code_str)/sizeof(char*))
6618 code_desc = iop_code_str[sas_loginfo.dw.code];
6619 break;
6620 case 1: /* PL */
6621 if (sas_loginfo.dw.code <
6622 sizeof(pl_code_str)/sizeof(char*))
6623 code_desc = pl_code_str[sas_loginfo.dw.code];
6624 break;
6625 case 2: /* IR */
6626 if (sas_loginfo.dw.code >=
6627 sizeof(ir_code_str)/sizeof(char*))
6628 break;
6629 code_desc = ir_code_str[sas_loginfo.dw.code];
6630 if (sas_loginfo.dw.subcode >=
6631 sizeof(raid_sub_code_str)/sizeof(char*))
6632 break;
6633 if (sas_loginfo.dw.code == 0)
6634 sub_code_desc =
6635 raid_sub_code_str[sas_loginfo.dw.subcode];
6636 break;
6637 default:
6638 return;
6255 } 6639 }
6256 6640
6257 if (code_desc != NULL) 6641 if (sub_code_desc != NULL)
6642 printk(MYIOC_s_INFO_FMT
6643 "LogInfo(0x%08x): Originator={%s}, Code={%s},"
6644 " SubCode={%s}\n",
6645 ioc->name, log_info, originator_desc, code_desc,
6646 sub_code_desc);
6647 else if (code_desc != NULL)
6258 printk(MYIOC_s_INFO_FMT 6648 printk(MYIOC_s_INFO_FMT
6259 "LogInfo(0x%08x): Originator={%s}, Code={%s}," 6649 "LogInfo(0x%08x): Originator={%s}, Code={%s},"
6260 " SubCode(0x%04x)\n", 6650 " SubCode(0x%04x)\n",
6261 ioc->name, 6651 ioc->name, log_info, originator_desc, code_desc,
6262 log_info,
6263 originator_str[sas_loginfo.dw.originator],
6264 code_desc,
6265 sas_loginfo.dw.subcode); 6652 sas_loginfo.dw.subcode);
6266 else 6653 else
6267 printk(MYIOC_s_INFO_FMT 6654 printk(MYIOC_s_INFO_FMT
6268 "LogInfo(0x%08x): Originator={%s}, Code=(0x%02x)," 6655 "LogInfo(0x%08x): Originator={%s}, Code=(0x%02x),"
6269 " SubCode(0x%04x)\n", 6656 " SubCode(0x%04x)\n",
6270 ioc->name, 6657 ioc->name, log_info, originator_desc,
6271 log_info, 6658 sas_loginfo.dw.code, sas_loginfo.dw.subcode);
6272 originator_str[sas_loginfo.dw.originator],
6273 sas_loginfo.dw.code,
6274 sas_loginfo.dw.subcode);
6275} 6659}
6276 6660
6661#ifdef MPT_DEBUG_REPLY
6277/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6662/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6278/** 6663/**
6279 * mpt_sp_ioc_info - IOC information returned from SCSI Parallel IOC. 6664 * mpt_iocstatus_info_config - IOCSTATUS information for config pages
6665 * @ioc: Pointer to MPT_ADAPTER structure
6666 * ioc_status: U32 IOCStatus word from IOC
6667 * @mf: Pointer to MPT request frame
6668 *
6669 * Refer to lsi/mpi.h.
6670 **/
6671static void
6672mpt_iocstatus_info_config(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
6673{
6674 Config_t *pReq = (Config_t *)mf;
6675 char extend_desc[EVENT_DESCR_STR_SZ];
6676 char *desc = NULL;
6677 u32 form;
6678 u8 page_type;
6679
6680 if (pReq->Header.PageType == MPI_CONFIG_PAGETYPE_EXTENDED)
6681 page_type = pReq->ExtPageType;
6682 else
6683 page_type = pReq->Header.PageType;
6684
6685 /*
6686 * ignore invalid page messages for GET_NEXT_HANDLE
6687 */
6688 form = le32_to_cpu(pReq->PageAddress);
6689 if (ioc_status == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
6690 if (page_type == MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE ||
6691 page_type == MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER ||
6692 page_type == MPI_CONFIG_EXTPAGETYPE_ENCLOSURE) {
6693 if ((form >> MPI_SAS_DEVICE_PGAD_FORM_SHIFT) ==
6694 MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE)
6695 return;
6696 }
6697 if (page_type == MPI_CONFIG_PAGETYPE_FC_DEVICE)
6698 if ((form & MPI_FC_DEVICE_PGAD_FORM_MASK) ==
6699 MPI_FC_DEVICE_PGAD_FORM_NEXT_DID)
6700 return;
6701 }
6702
6703 snprintf(extend_desc, EVENT_DESCR_STR_SZ,
6704 "type=%02Xh, page=%02Xh, action=%02Xh, form=%08Xh",
6705 page_type, pReq->Header.PageNumber, pReq->Action, form);
6706
6707 switch (ioc_status) {
6708
6709 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
6710 desc = "Config Page Invalid Action";
6711 break;
6712
6713 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
6714 desc = "Config Page Invalid Type";
6715 break;
6716
6717 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
6718 desc = "Config Page Invalid Page";
6719 break;
6720
6721 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
6722 desc = "Config Page Invalid Data";
6723 break;
6724
6725 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
6726 desc = "Config Page No Defaults";
6727 break;
6728
6729 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
6730 desc = "Config Page Can't Commit";
6731 break;
6732 }
6733
6734 if (!desc)
6735 return;
6736
6737 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04X): %s: %s\n",
6738 ioc->name, ioc_status, desc, extend_desc);
6739}
6740
6741/**
6742 * mpt_iocstatus_info - IOCSTATUS information returned from IOC.
6280 * @ioc: Pointer to MPT_ADAPTER structure 6743 * @ioc: Pointer to MPT_ADAPTER structure
6281 * @ioc_status: U32 IOCStatus word from IOC 6744 * @ioc_status: U32 IOCStatus word from IOC
6282 * @mf: Pointer to MPT request frame 6745 * @mf: Pointer to MPT request frame
6283 * 6746 *
6284 * Refer to lsi/mpi.h. 6747 * Refer to lsi/mpi.h.
6285 */ 6748 **/
6286static void 6749static void
6287mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf) 6750mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
6288{ 6751{
6289 u32 status = ioc_status & MPI_IOCSTATUS_MASK; 6752 u32 status = ioc_status & MPI_IOCSTATUS_MASK;
6290 char *desc = NULL; 6753 char *desc = NULL;
6291 6754
6292 switch (status) { 6755 switch (status) {
6756
6757/****************************************************************************/
6758/* Common IOCStatus values for all replies */
6759/****************************************************************************/
6760
6293 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */ 6761 case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
6294 desc = "Invalid Function"; 6762 desc = "Invalid Function";
6295 break; 6763 break;
@@ -6322,84 +6790,180 @@ mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
6322 desc = "Invalid State"; 6790 desc = "Invalid State";
6323 break; 6791 break;
6324 6792
6793/****************************************************************************/
6794/* Config IOCStatus values */
6795/****************************************************************************/
6796
6325 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */ 6797 case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
6326 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */ 6798 case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
6327 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */ 6799 case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
6328 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */ 6800 case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
6329 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */ 6801 case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
6330 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */ 6802 case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
6331 /* No message for Config IOCStatus values */ 6803 mpt_iocstatus_info_config(ioc, status, mf);
6332 break; 6804 break;
6333 6805
6806/****************************************************************************/
6807/* SCSIIO Reply (SPI, FCP, SAS) initiator values */
6808/* */
6809/* Look at mptscsih_iocstatus_info_scsiio in mptscsih.c */
6810/* */
6811/****************************************************************************/
6812
6334 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */ 6813 case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
6335 /* No message for recovered error 6814 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
6336 desc = "SCSI Recovered Error"; 6815 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
6337 */ 6816 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
6817 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
6818 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
6819 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
6820 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
6821 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
6822 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
6823 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
6824 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
6825 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
6338 break; 6826 break;
6339 6827
6340 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */ 6828/****************************************************************************/
6341 desc = "SCSI Invalid Bus"; 6829/* SCSI Target values */
6830/****************************************************************************/
6831
6832 case MPI_IOCSTATUS_TARGET_PRIORITY_IO: /* 0x0060 */
6833 desc = "Target: Priority IO";
6342 break; 6834 break;
6343 6835
6344 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */ 6836 case MPI_IOCSTATUS_TARGET_INVALID_PORT: /* 0x0061 */
6345 desc = "SCSI Invalid TargetID"; 6837 desc = "Target: Invalid Port";
6346 break; 6838 break;
6347 6839
6348 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */ 6840 case MPI_IOCSTATUS_TARGET_INVALID_IO_INDEX: /* 0x0062 */
6349 { 6841 desc = "Target Invalid IO Index:";
6350 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
6351 U8 cdb = pScsiReq->CDB[0];
6352 if (cdb != 0x12) { /* Inquiry is issued for device scanning */
6353 desc = "SCSI Device Not There";
6354 }
6355 break; 6842 break;
6356 }
6357 6843
6358 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */ 6844 case MPI_IOCSTATUS_TARGET_ABORTED: /* 0x0063 */
6359 desc = "SCSI Data Overrun"; 6845 desc = "Target: Aborted";
6360 break; 6846 break;
6361 6847
6362 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */ 6848 case MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: /* 0x0064 */
6363 /* This error is checked in scsi_io_done(). Skip. 6849 desc = "Target: No Conn Retryable";
6364 desc = "SCSI Data Underrun";
6365 */
6366 break; 6850 break;
6367 6851
6368 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */ 6852 case MPI_IOCSTATUS_TARGET_NO_CONNECTION: /* 0x0065 */
6369 desc = "SCSI I/O Data Error"; 6853 desc = "Target: No Connection";
6370 break; 6854 break;
6371 6855
6372 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */ 6856 case MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: /* 0x006A */
6373 desc = "SCSI Protocol Error"; 6857 desc = "Target: Transfer Count Mismatch";
6374 break; 6858 break;
6375 6859
6376 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */ 6860 case MPI_IOCSTATUS_TARGET_STS_DATA_NOT_SENT: /* 0x006B */
6377 desc = "SCSI Task Terminated"; 6861 desc = "Target: STS Data not Sent";
6378 break; 6862 break;
6379 6863
6380 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */ 6864 case MPI_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: /* 0x006D */
6381 desc = "SCSI Residual Mismatch"; 6865 desc = "Target: Data Offset Error";
6382 break; 6866 break;
6383 6867
6384 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */ 6868 case MPI_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: /* 0x006E */
6385 desc = "SCSI Task Management Failed"; 6869 desc = "Target: Too Much Write Data";
6386 break; 6870 break;
6387 6871
6388 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */ 6872 case MPI_IOCSTATUS_TARGET_IU_TOO_SHORT: /* 0x006F */
6389 desc = "SCSI IOC Terminated"; 6873 desc = "Target: IU Too Short";
6390 break; 6874 break;
6391 6875
6392 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */ 6876 case MPI_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: /* 0x0070 */
6393 desc = "SCSI Ext Terminated"; 6877 desc = "Target: ACK NAK Timeout";
6878 break;
6879
6880 case MPI_IOCSTATUS_TARGET_NAK_RECEIVED: /* 0x0071 */
6881 desc = "Target: Nak Received";
6882 break;
6883
6884/****************************************************************************/
6885/* Fibre Channel Direct Access values */
6886/****************************************************************************/
6887
6888 case MPI_IOCSTATUS_FC_ABORTED: /* 0x0066 */
6889 desc = "FC: Aborted";
6890 break;
6891
6892 case MPI_IOCSTATUS_FC_RX_ID_INVALID: /* 0x0067 */
6893 desc = "FC: RX ID Invalid";
6894 break;
6895
6896 case MPI_IOCSTATUS_FC_DID_INVALID: /* 0x0068 */
6897 desc = "FC: DID Invalid";
6898 break;
6899
6900 case MPI_IOCSTATUS_FC_NODE_LOGGED_OUT: /* 0x0069 */
6901 desc = "FC: Node Logged Out";
6902 break;
6903
6904 case MPI_IOCSTATUS_FC_EXCHANGE_CANCELED: /* 0x006C */
6905 desc = "FC: Exchange Canceled";
6906 break;
6907
6908/****************************************************************************/
6909/* LAN values */
6910/****************************************************************************/
6911
6912 case MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND: /* 0x0080 */
6913 desc = "LAN: Device not Found";
6914 break;
6915
6916 case MPI_IOCSTATUS_LAN_DEVICE_FAILURE: /* 0x0081 */
6917 desc = "LAN: Device Failure";
6918 break;
6919
6920 case MPI_IOCSTATUS_LAN_TRANSMIT_ERROR: /* 0x0082 */
6921 desc = "LAN: Transmit Error";
6922 break;
6923
6924 case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED: /* 0x0083 */
6925 desc = "LAN: Transmit Aborted";
6926 break;
6927
6928 case MPI_IOCSTATUS_LAN_RECEIVE_ERROR: /* 0x0084 */
6929 desc = "LAN: Receive Error";
6930 break;
6931
6932 case MPI_IOCSTATUS_LAN_RECEIVE_ABORTED: /* 0x0085 */
6933 desc = "LAN: Receive Aborted";
6934 break;
6935
6936 case MPI_IOCSTATUS_LAN_PARTIAL_PACKET: /* 0x0086 */
6937 desc = "LAN: Partial Packet";
6938 break;
6939
6940 case MPI_IOCSTATUS_LAN_CANCELED: /* 0x0087 */
6941 desc = "LAN: Canceled";
6942 break;
6943
6944/****************************************************************************/
6945/* Serial Attached SCSI values */
6946/****************************************************************************/
6947
6948 case MPI_IOCSTATUS_SAS_SMP_REQUEST_FAILED: /* 0x0090 */
6949 desc = "SAS: SMP Request Failed";
6950 break;
6951
6952 case MPI_IOCSTATUS_SAS_SMP_DATA_OVERRUN: /* 0x0090 */
6953 desc = "SAS: SMP Data Overrun";
6394 break; 6954 break;
6395 6955
6396 default: 6956 default:
6397 desc = "Others"; 6957 desc = "Others";
6398 break; 6958 break;
6399 } 6959 }
6400 if (desc != NULL) 6960
6401 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc); 6961 if (!desc)
6962 return;
6963
6964 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04X): %s\n", ioc->name, status, desc);
6402} 6965}
6966#endif
6403 6967
6404/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 6968/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6405EXPORT_SYMBOL(mpt_attach); 6969EXPORT_SYMBOL(mpt_attach);
@@ -6434,6 +6998,7 @@ EXPORT_SYMBOL(mpt_findImVolumes);
6434EXPORT_SYMBOL(mpt_alloc_fw_memory); 6998EXPORT_SYMBOL(mpt_alloc_fw_memory);
6435EXPORT_SYMBOL(mpt_free_fw_memory); 6999EXPORT_SYMBOL(mpt_free_fw_memory);
6436EXPORT_SYMBOL(mptbase_sas_persist_operation); 7000EXPORT_SYMBOL(mptbase_sas_persist_operation);
7001EXPORT_SYMBOL(mpt_raid_phys_disk_pg0);
6437 7002
6438/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 7003/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
6439/** 7004/**
diff --git a/drivers/message/fusion/mptbase.h b/drivers/message/fusion/mptbase.h
index e316708f76b..e3a39272aad 100644
--- a/drivers/message/fusion/mptbase.h
+++ b/drivers/message/fusion/mptbase.h
@@ -6,7 +6,7 @@
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2007 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsi.com)
10 * 10 *
11 */ 11 */
12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -75,8 +75,8 @@
75#define COPYRIGHT "Copyright (c) 1999-2007 " MODULEAUTHOR 75#define COPYRIGHT "Copyright (c) 1999-2007 " MODULEAUTHOR
76#endif 76#endif
77 77
78#define MPT_LINUX_VERSION_COMMON "3.04.03" 78#define MPT_LINUX_VERSION_COMMON "3.04.04"
79#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.03" 79#define MPT_LINUX_PACKAGE_NAME "@(#)mptlinux-3.04.04"
80#define WHAT_MAGIC_STRING "@" "(" "#" ")" 80#define WHAT_MAGIC_STRING "@" "(" "#" ")"
81 81
82#define show_mptmod_ver(s,ver) \ 82#define show_mptmod_ver(s,ver) \
@@ -172,6 +172,9 @@
172#define MPT_SCSI_SG_DEPTH 40 172#define MPT_SCSI_SG_DEPTH 40
173#endif 173#endif
174 174
175/* debug print string length used for events and iocstatus */
176# define EVENT_DESCR_STR_SZ 100
177
175#ifdef __KERNEL__ /* { */ 178#ifdef __KERNEL__ /* { */
176/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 179/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
177 180
@@ -334,8 +337,8 @@ typedef struct _VirtTarget {
334 struct scsi_target *starget; 337 struct scsi_target *starget;
335 u8 tflags; 338 u8 tflags;
336 u8 ioc_id; 339 u8 ioc_id;
337 u8 target_id; 340 u8 id;
338 u8 bus_id; 341 u8 channel;
339 u8 minSyncFactor; /* 0xFF is async */ 342 u8 minSyncFactor; /* 0xFF is async */
340 u8 maxOffset; /* 0 if async */ 343 u8 maxOffset; /* 0 if async */
341 u8 maxWidth; /* 0 if narrow, 1 if wide */ 344 u8 maxWidth; /* 0 if narrow, 1 if wide */
@@ -344,13 +347,12 @@ typedef struct _VirtTarget {
344 u8 type; /* byte 0 of Inquiry data */ 347 u8 type; /* byte 0 of Inquiry data */
345 u8 deleted; /* target in process of being removed */ 348 u8 deleted; /* target in process of being removed */
346 u32 num_luns; 349 u32 num_luns;
347 u32 luns[8]; /* Max LUNs is 256 */
348} VirtTarget; 350} VirtTarget;
349 351
350typedef struct _VirtDevice { 352typedef struct _VirtDevice {
351 VirtTarget *vtarget; 353 VirtTarget *vtarget;
352 u8 configured_lun; 354 u8 configured_lun;
353 u32 lun; 355 int lun;
354} VirtDevice; 356} VirtDevice;
355 357
356/* 358/*
@@ -412,7 +414,7 @@ typedef struct _MPT_IOCTL {
412 u8 rsvd; 414 u8 rsvd;
413 u8 status; /* current command status */ 415 u8 status; /* current command status */
414 u8 reset; /* 1 if bus reset allowed */ 416 u8 reset; /* 1 if bus reset allowed */
415 u8 target; /* target for reset */ 417 u8 id; /* target for reset */
416 struct mutex ioctl_mutex; 418 struct mutex ioctl_mutex;
417} MPT_IOCTL; 419} MPT_IOCTL;
418 420
@@ -483,10 +485,24 @@ typedef struct _SasCfgData {
483 */ 485 */
484}SasCfgData; 486}SasCfgData;
485 487
488/*
489 * Inactive volume link list of raid component data
490 * @inactive_list
491 */
492struct inactive_raid_component_info {
493 struct list_head list;
494 u8 volumeID; /* volume target id */
495 u8 volumeBus; /* volume channel */
496 IOC_3_PHYS_DISK d; /* phys disk info */
497};
498
486typedef struct _RaidCfgData { 499typedef struct _RaidCfgData {
487 IOCPage2_t *pIocPg2; /* table of Raid Volumes */ 500 IOCPage2_t *pIocPg2; /* table of Raid Volumes */
488 IOCPage3_t *pIocPg3; /* table of physical disks */ 501 IOCPage3_t *pIocPg3; /* table of physical disks */
489 int isRaid; /* bit field, 1 if RAID */ 502 struct semaphore inactive_list_mutex;
503 struct list_head inactive_list; /* link list for physical
504 disk that belong in
505 inactive volumes */
490}RaidCfgData; 506}RaidCfgData;
491 507
492typedef struct _FcCfgData { 508typedef struct _FcCfgData {
@@ -528,6 +544,8 @@ typedef struct _MPT_ADAPTER
528 u32 mem_phys; /* == f4020000 (mmap) */ 544 u32 mem_phys; /* == f4020000 (mmap) */
529 u32 pio_mem_phys; /* Programmed IO (downloadboot) */ 545 u32 pio_mem_phys; /* Programmed IO (downloadboot) */
530 int mem_size; /* mmap memory size */ 546 int mem_size; /* mmap memory size */
547 int number_of_buses;
548 int devices_per_bus;
531 int alloc_total; 549 int alloc_total;
532 u32 last_state; 550 u32 last_state;
533 int active; 551 int active;
@@ -607,6 +625,8 @@ typedef struct _MPT_ADAPTER
607 u8 persist_reply_frame[MPT_DEFAULT_FRAME_SIZE]; /* persist reply */ 625 u8 persist_reply_frame[MPT_DEFAULT_FRAME_SIZE]; /* persist reply */
608 LANPage0_t lan_cnfg_page0; 626 LANPage0_t lan_cnfg_page0;
609 LANPage1_t lan_cnfg_page1; 627 LANPage1_t lan_cnfg_page1;
628
629 u8 ir_firmware; /* =1 if IR firmware detected */
610 /* 630 /*
611 * Description: errata_flag_1064 631 * Description: errata_flag_1064
612 * If a PCIX read occurs within 1 or 2 cycles after the chip receives 632 * If a PCIX read occurs within 1 or 2 cycles after the chip receives
@@ -790,12 +810,6 @@ typedef struct _mpt_sge {
790#define ddvprintk(x) 810#define ddvprintk(x)
791#endif 811#endif
792 812
793#ifdef MPT_DEBUG_NEGO
794#define dnegoprintk(x) printk x
795#else
796#define dnegoprintk(x)
797#endif
798
799#if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY) 813#if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY)
800#define ddvtprintk(x) printk x 814#define ddvtprintk(x) printk x
801#else 815#else
@@ -957,7 +971,6 @@ typedef struct _MPT_SCSI_HOST {
957 int port; 971 int port;
958 u32 pad0; 972 u32 pad0;
959 struct scsi_cmnd **ScsiLookup; 973 struct scsi_cmnd **ScsiLookup;
960 VirtTarget **Targets;
961 MPT_LOCAL_REPLY *pLocal; /* used for internal commands */ 974 MPT_LOCAL_REPLY *pLocal; /* used for internal commands */
962 struct timer_list timer; 975 struct timer_list timer;
963 /* Pool of memory for holding SCpnts before doing 976 /* Pool of memory for holding SCpnts before doing
@@ -981,6 +994,7 @@ typedef struct _MPT_SCSI_HOST {
981 int scandv_wait_done; 994 int scandv_wait_done;
982 long last_queue_full; 995 long last_queue_full;
983 u16 tm_iocstatus; 996 u16 tm_iocstatus;
997 struct list_head target_reset_list;
984} MPT_SCSI_HOST; 998} MPT_SCSI_HOST;
985 999
986/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1000/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -1046,6 +1060,7 @@ extern void mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size);
1046extern void mpt_free_fw_memory(MPT_ADAPTER *ioc); 1060extern void mpt_free_fw_memory(MPT_ADAPTER *ioc);
1047extern int mpt_findImVolumes(MPT_ADAPTER *ioc); 1061extern int mpt_findImVolumes(MPT_ADAPTER *ioc);
1048extern int mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode); 1062extern int mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
1063extern int mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num, pRaidPhysDiskPage0_t phys_disk);
1049 1064
1050/* 1065/*
1051 * Public data decl's... 1066 * Public data decl's...
diff --git a/drivers/message/fusion/mptctl.c b/drivers/message/fusion/mptctl.c
index 504632da434..9d0f30478e4 100644
--- a/drivers/message/fusion/mptctl.c
+++ b/drivers/message/fusion/mptctl.c
@@ -5,7 +5,7 @@
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * 6 *
7 * Copyright (c) 1999-2007 LSI Logic Corporation 7 * Copyright (c) 1999-2007 LSI Logic Corporation
8 * (mailto:mpt_linux_developer@lsil.com) 8 * (mailto:mpt_linux_developer@lsi.com)
9 * 9 *
10 */ 10 */
11/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 11/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -313,7 +313,7 @@ static void mptctl_timeout_expired (MPT_IOCTL *ioctl)
313 */ 313 */
314 dctlprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n", 314 dctlprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
315 ioctl->ioc->name)); 315 ioctl->ioc->name));
316 mpt_HardResetHandler(ioctl->ioc, NO_SLEEP); 316 mpt_HardResetHandler(ioctl->ioc, CAN_SLEEP);
317 } 317 }
318 return; 318 return;
319 319
@@ -361,7 +361,7 @@ static int mptctl_bus_reset(MPT_IOCTL *ioctl)
361 ioctl->ioc->name, mf)); 361 ioctl->ioc->name, mf));
362 362
363 pScsiTm = (SCSITaskMgmt_t *) mf; 363 pScsiTm = (SCSITaskMgmt_t *) mf;
364 pScsiTm->TargetID = ioctl->target; 364 pScsiTm->TargetID = ioctl->id;
365 pScsiTm->Bus = hd->port; /* 0 */ 365 pScsiTm->Bus = hd->port; /* 0 */
366 pScsiTm->ChainOffset = 0; 366 pScsiTm->ChainOffset = 0;
367 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; 367 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
@@ -1159,15 +1159,12 @@ mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1159 struct mpt_ioctl_iocinfo *karg; 1159 struct mpt_ioctl_iocinfo *karg;
1160 MPT_ADAPTER *ioc; 1160 MPT_ADAPTER *ioc;
1161 struct pci_dev *pdev; 1161 struct pci_dev *pdev;
1162 struct Scsi_Host *sh;
1163 MPT_SCSI_HOST *hd;
1164 int iocnum; 1162 int iocnum;
1165 int numDevices = 0;
1166 unsigned int max_id;
1167 int ii;
1168 unsigned int port; 1163 unsigned int port;
1169 int cim_rev; 1164 int cim_rev;
1170 u8 revision; 1165 u8 revision;
1166 struct scsi_device *sdev;
1167 VirtDevice *vdev;
1171 1168
1172 dctlprintk((": mptctl_getiocinfo called.\n")); 1169 dctlprintk((": mptctl_getiocinfo called.\n"));
1173 /* Add of PCI INFO results in unaligned access for 1170 /* Add of PCI INFO results in unaligned access for
@@ -1257,23 +1254,16 @@ mptctl_getiocinfo (unsigned long arg, unsigned int data_size)
1257 1254
1258 /* Get number of devices 1255 /* Get number of devices
1259 */ 1256 */
1260 if ((sh = ioc->sh) != NULL) { 1257 karg->numDevices = 0;
1261 /* sh->max_id = maximum target ID + 1 1258 if (ioc->sh) {
1262 */ 1259 shost_for_each_device(sdev, ioc->sh) {
1263 max_id = sh->max_id - 1; 1260 vdev = sdev->hostdata;
1264 hd = (MPT_SCSI_HOST *) sh->hostdata; 1261 if (vdev->vtarget->tflags &
1265 1262 MPT_TARGET_FLAGS_RAID_COMPONENT)
1266 /* Check all of the target structures and 1263 continue;
1267 * keep a counter. 1264 karg->numDevices++;
1268 */
1269 if (hd && hd->Targets) {
1270 for (ii = 0; ii <= max_id; ii++) {
1271 if (hd->Targets[ii])
1272 numDevices++;
1273 }
1274 } 1265 }
1275 } 1266 }
1276 karg->numDevices = numDevices;
1277 1267
1278 /* Set the BIOS and FW Version 1268 /* Set the BIOS and FW Version
1279 */ 1269 */
@@ -1319,21 +1309,16 @@ mptctl_gettargetinfo (unsigned long arg)
1319 struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg; 1309 struct mpt_ioctl_targetinfo __user *uarg = (void __user *) arg;
1320 struct mpt_ioctl_targetinfo karg; 1310 struct mpt_ioctl_targetinfo karg;
1321 MPT_ADAPTER *ioc; 1311 MPT_ADAPTER *ioc;
1322 struct Scsi_Host *sh; 1312 VirtDevice *vdev;
1323 MPT_SCSI_HOST *hd;
1324 VirtTarget *vdev;
1325 char *pmem; 1313 char *pmem;
1326 int *pdata; 1314 int *pdata;
1327 IOCPage2_t *pIoc2;
1328 IOCPage3_t *pIoc3;
1329 int iocnum; 1315 int iocnum;
1330 int numDevices = 0; 1316 int numDevices = 0;
1331 unsigned int max_id; 1317 int lun;
1332 int id, jj, indexed_lun, lun_index;
1333 u32 lun;
1334 int maxWordsLeft; 1318 int maxWordsLeft;
1335 int numBytes; 1319 int numBytes;
1336 u8 port, devType, bus_id; 1320 u8 port;
1321 struct scsi_device *sdev;
1337 1322
1338 dctlprintk(("mptctl_gettargetinfo called.\n")); 1323 dctlprintk(("mptctl_gettargetinfo called.\n"));
1339 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) { 1324 if (copy_from_user(&karg, uarg, sizeof(struct mpt_ioctl_targetinfo))) {
@@ -1389,74 +1374,22 @@ mptctl_gettargetinfo (unsigned long arg)
1389 1374
1390 /* Get number of devices 1375 /* Get number of devices
1391 */ 1376 */
1392 if ((sh = ioc->sh) != NULL) { 1377 if (ioc->sh){
1393 1378 shost_for_each_device(sdev, ioc->sh) {
1394 max_id = sh->max_id - 1; 1379 if (!maxWordsLeft)
1395 hd = (MPT_SCSI_HOST *) sh->hostdata; 1380 continue;
1396 1381 vdev = sdev->hostdata;
1397 /* Check all of the target structures. 1382 if (vdev->vtarget->tflags &
1398 * Save the Id and increment the counter, 1383 MPT_TARGET_FLAGS_RAID_COMPONENT)
1399 * if ptr non-null. 1384 continue;
1400 * sh->max_id = maximum target ID + 1 1385 lun = (vdev->vtarget->raidVolume) ? 0x80 : vdev->lun;
1401 */ 1386 *pdata = (((u8)lun << 16) + (vdev->vtarget->channel << 8) +
1402 if (hd && hd->Targets) { 1387 (vdev->vtarget->id ));
1403 mpt_findImVolumes(ioc); 1388 pdata++;
1404 pIoc2 = ioc->raid_data.pIocPg2; 1389 numDevices++;
1405 for ( id = 0; id <= max_id; ) { 1390 --maxWordsLeft;
1406 if ( pIoc2 && pIoc2->NumActiveVolumes ) {
1407 if ( id == pIoc2->RaidVolume[0].VolumeID ) {
1408 if (maxWordsLeft <= 0) {
1409 printk(KERN_ERR "mptctl_gettargetinfo - "
1410 "buffer is full but volume is available on ioc %d\n, numDevices=%d", iocnum, numDevices);
1411 goto data_space_full;
1412 }
1413 if ( ( pIoc2->RaidVolume[0].Flags & MPI_IOCPAGE2_FLAG_VOLUME_INACTIVE ) == 0 )
1414 devType = 0x80;
1415 else
1416 devType = 0xC0;
1417 bus_id = pIoc2->RaidVolume[0].VolumeBus;
1418 numDevices++;
1419 *pdata = ( (devType << 24) | (bus_id << 8) | id );
1420 dctlprintk((KERN_ERR "mptctl_gettargetinfo - "
1421 "volume ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum, *pdata, numDevices, pdata));
1422 pdata++;
1423 --maxWordsLeft;
1424 goto next_id;
1425 } else {
1426 pIoc3 = ioc->raid_data.pIocPg3;
1427 for ( jj = 0; jj < pIoc3->NumPhysDisks; jj++ ) {
1428 if ( pIoc3->PhysDisk[jj].PhysDiskID == id )
1429 goto next_id;
1430 }
1431 }
1432 }
1433 if ( (vdev = hd->Targets[id]) ) {
1434 for (jj = 0; jj <= MPT_LAST_LUN; jj++) {
1435 lun_index = (jj >> 5);
1436 indexed_lun = (jj % 32);
1437 lun = (1 << indexed_lun);
1438 if (vdev->luns[lun_index] & lun) {
1439 if (maxWordsLeft <= 0) {
1440 printk(KERN_ERR "mptctl_gettargetinfo - "
1441 "buffer is full but more targets are available on ioc %d numDevices=%d\n", iocnum, numDevices);
1442 goto data_space_full;
1443 }
1444 bus_id = vdev->bus_id;
1445 numDevices++;
1446 *pdata = ( (jj << 16) | (bus_id << 8) | id );
1447 dctlprintk((KERN_ERR "mptctl_gettargetinfo - "
1448 "target ioc=%d target=%x numDevices=%d pdata=%p\n", iocnum, *pdata, numDevices, pdata));
1449 pdata++;
1450 --maxWordsLeft;
1451 }
1452 }
1453 }
1454next_id:
1455 id++;
1456 }
1457 } 1391 }
1458 } 1392 }
1459data_space_full:
1460 karg.numDevices = numDevices; 1393 karg.numDevices = numDevices;
1461 1394
1462 /* Copy part of the data from kernel memory to user memory 1395 /* Copy part of the data from kernel memory to user memory
@@ -1821,6 +1754,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1821 int msgContext; 1754 int msgContext;
1822 u16 req_idx; 1755 u16 req_idx;
1823 ulong timeout; 1756 ulong timeout;
1757 struct scsi_device *sdev;
1824 1758
1825 dctlprintk(("mptctl_do_mpt_command called.\n")); 1759 dctlprintk(("mptctl_do_mpt_command called.\n"));
1826 bufIn.kptr = bufOut.kptr = NULL; 1760 bufIn.kptr = bufOut.kptr = NULL;
@@ -1902,14 +1836,13 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1902 case MPI_FUNCTION_SCSI_IO_REQUEST: 1836 case MPI_FUNCTION_SCSI_IO_REQUEST:
1903 if (ioc->sh) { 1837 if (ioc->sh) {
1904 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf; 1838 SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
1905 VirtTarget *pTarget = NULL;
1906 MPT_SCSI_HOST *hd = NULL;
1907 int qtag = MPI_SCSIIO_CONTROL_UNTAGGED; 1839 int qtag = MPI_SCSIIO_CONTROL_UNTAGGED;
1908 int scsidir = 0; 1840 int scsidir = 0;
1909 int target = (int) pScsiReq->TargetID;
1910 int dataSize; 1841 int dataSize;
1842 u32 id;
1911 1843
1912 if ((target < 0) || (target >= ioc->sh->max_id)) { 1844 id = (ioc->devices_per_bus == 0) ? 256 : ioc->devices_per_bus;
1845 if (pScsiReq->TargetID > id) {
1913 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - " 1846 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1914 "Target ID out of bounds. \n", 1847 "Target ID out of bounds. \n",
1915 __FILE__, __LINE__); 1848 __FILE__, __LINE__);
@@ -1917,6 +1850,14 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1917 goto done_free_mem; 1850 goto done_free_mem;
1918 } 1851 }
1919 1852
1853 if (pScsiReq->Bus >= ioc->number_of_buses) {
1854 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
1855 "Target Bus out of bounds. \n",
1856 __FILE__, __LINE__);
1857 rc = -ENODEV;
1858 goto done_free_mem;
1859 }
1860
1920 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH; 1861 pScsiReq->MsgFlags &= ~MPI_SCSIIO_MSGFLGS_SENSE_WIDTH;
1921 pScsiReq->MsgFlags |= mpt_msg_flags(); 1862 pScsiReq->MsgFlags |= mpt_msg_flags();
1922 1863
@@ -1936,13 +1877,15 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1936 cpu_to_le32(ioc->sense_buf_low_dma 1877 cpu_to_le32(ioc->sense_buf_low_dma
1937 + (req_idx * MPT_SENSE_BUFFER_ALLOC)); 1878 + (req_idx * MPT_SENSE_BUFFER_ALLOC));
1938 1879
1939 if ((hd = (MPT_SCSI_HOST *) ioc->sh->hostdata)) { 1880 shost_for_each_device(sdev, ioc->sh) {
1940 if (hd->Targets) 1881 struct scsi_target *starget = scsi_target(sdev);
1941 pTarget = hd->Targets[target]; 1882 VirtTarget *vtarget = starget->hostdata;
1942 }
1943 1883
1944 if (pTarget &&(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)) 1884 if ((pScsiReq->TargetID == vtarget->id) &&
1945 qtag = MPI_SCSIIO_CONTROL_SIMPLEQ; 1885 (pScsiReq->Bus == vtarget->channel) &&
1886 (vtarget->tflags & MPT_TARGET_FLAGS_Q_YES))
1887 qtag = MPI_SCSIIO_CONTROL_SIMPLEQ;
1888 }
1946 1889
1947 /* Have the IOCTL driver set the direction based 1890 /* Have the IOCTL driver set the direction based
1948 * on the dataOutSize (ordering issue with Sparc). 1891 * on the dataOutSize (ordering issue with Sparc).
@@ -1959,7 +1902,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
1959 pScsiReq->DataLength = cpu_to_le32(dataSize); 1902 pScsiReq->DataLength = cpu_to_le32(dataSize);
1960 1903
1961 ioc->ioctl->reset = MPTCTL_RESET_OK; 1904 ioc->ioctl->reset = MPTCTL_RESET_OK;
1962 ioc->ioctl->target = target; 1905 ioc->ioctl->id = pScsiReq->TargetID;
1963 1906
1964 } else { 1907 } else {
1965 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - " 1908 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
@@ -2038,7 +1981,7 @@ mptctl_do_mpt_command (struct mpt_ioctl_command karg, void __user *mfPtr)
2038 pScsiReq->DataLength = cpu_to_le32(dataSize); 1981 pScsiReq->DataLength = cpu_to_le32(dataSize);
2039 1982
2040 ioc->ioctl->reset = MPTCTL_RESET_OK; 1983 ioc->ioctl->reset = MPTCTL_RESET_OK;
2041 ioc->ioctl->target = pScsiReq->TargetID; 1984 ioc->ioctl->id = pScsiReq->TargetID;
2042 } else { 1985 } else {
2043 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - " 1986 printk(KERN_ERR "%s@%d::mptctl_do_mpt_command - "
2044 "SCSI driver is not loaded. \n", 1987 "SCSI driver is not loaded. \n",
@@ -2719,7 +2662,7 @@ mptctl_hp_targetinfo(unsigned long arg)
2719 2662
2720/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2663/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2721 2664
2722static struct file_operations mptctl_fops = { 2665static const struct file_operations mptctl_fops = {
2723 .owner = THIS_MODULE, 2666 .owner = THIS_MODULE,
2724 .llseek = no_llseek, 2667 .llseek = no_llseek,
2725 .release = mptctl_release, 2668 .release = mptctl_release,
diff --git a/drivers/message/fusion/mptctl.h b/drivers/message/fusion/mptctl.h
index e65a1cf5eb0..f7e72c5e47d 100644
--- a/drivers/message/fusion/mptctl.h
+++ b/drivers/message/fusion/mptctl.h
@@ -6,7 +6,7 @@
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2007 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsi.com)
10 * 10 *
11 */ 11 */
12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
diff --git a/drivers/message/fusion/mptfc.c b/drivers/message/fusion/mptfc.c
index c819c23b55b..b7d4c7265ec 100644
--- a/drivers/message/fusion/mptfc.c
+++ b/drivers/message/fusion/mptfc.c
@@ -4,7 +4,7 @@
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2007 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsi.com)
8 * 8 *
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -86,6 +86,12 @@ MODULE_PARM_DESC(mptfc_dev_loss_tmo, " Initial time the driver programs the "
86 " return following a device loss event." 86 " return following a device loss event."
87 " Default=60."); 87 " Default=60.");
88 88
89/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
90#define MPTFC_MAX_LUN (16895)
91static int max_lun = MPTFC_MAX_LUN;
92module_param(max_lun, int, 0);
93MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
94
89static int mptfcDoneCtx = -1; 95static int mptfcDoneCtx = -1;
90static int mptfcTaskCtx = -1; 96static int mptfcTaskCtx = -1;
91static int mptfcInternalCtx = -1; /* Used only for internal commands */ 97static int mptfcInternalCtx = -1; /* Used only for internal commands */
@@ -292,10 +298,9 @@ mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, int ioc_port,
292 U32 port_id = 0xffffff; 298 U32 port_id = 0xffffff;
293 int num_targ = 0; 299 int num_targ = 0;
294 int max_bus = ioc->facts.MaxBuses; 300 int max_bus = ioc->facts.MaxBuses;
295 int max_targ = ioc->facts.MaxDevices; 301 int max_targ;
296 302
297 if (max_bus == 0 || max_targ == 0) 303 max_targ = (ioc->facts.MaxDevices == 0) ? 256 : ioc->facts.MaxDevices;
298 goto out;
299 304
300 data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ; 305 data_sz = sizeof(FCDevicePage0_t) * max_bus * max_targ;
301 p_p0 = p0_array = kzalloc(data_sz, GFP_KERNEL); 306 p_p0 = p0_array = kzalloc(data_sz, GFP_KERNEL);
@@ -467,8 +472,8 @@ mptfc_register_dev(MPT_ADAPTER *ioc, int channel, FCDevicePage0_t *pg0)
467 if (ri->starget) { 472 if (ri->starget) {
468 vtarget = ri->starget->hostdata; 473 vtarget = ri->starget->hostdata;
469 if (vtarget) { 474 if (vtarget) {
470 vtarget->target_id = pg0->CurrentTargetID; 475 vtarget->id = pg0->CurrentTargetID;
471 vtarget->bus_id = pg0->CurrentBus; 476 vtarget->channel = pg0->CurrentBus;
472 } 477 }
473 } 478 }
474 *((struct mptfc_rport_info **)rport->dd_data) = ri; 479 *((struct mptfc_rport_info **)rport->dd_data) = ri;
@@ -540,8 +545,8 @@ mptfc_target_alloc(struct scsi_target *starget)
540 if (rport) { 545 if (rport) {
541 ri = *((struct mptfc_rport_info **)rport->dd_data); 546 ri = *((struct mptfc_rport_info **)rport->dd_data);
542 if (ri) { /* better be! */ 547 if (ri) { /* better be! */
543 vtarget->target_id = ri->pg0.CurrentTargetID; 548 vtarget->id = ri->pg0.CurrentTargetID;
544 vtarget->bus_id = ri->pg0.CurrentBus; 549 vtarget->channel = ri->pg0.CurrentBus;
545 ri->starget = starget; 550 ri->starget = starget;
546 rc = 0; 551 rc = 0;
547 } 552 }
@@ -592,7 +597,6 @@ mptfc_slave_alloc(struct scsi_device *sdev)
592 if (vtarget->num_luns == 0) { 597 if (vtarget->num_luns == 0) {
593 vtarget->ioc_id = hd->ioc->id; 598 vtarget->ioc_id = hd->ioc->id;
594 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES; 599 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
595 hd->Targets[sdev->id] = vtarget;
596 } 600 }
597 601
598 vdev->vtarget = vtarget; 602 vdev->vtarget = vtarget;
@@ -630,16 +634,17 @@ mptfc_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
630 struct mptfc_rport_info *ri; 634 struct mptfc_rport_info *ri;
631 struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device)); 635 struct fc_rport *rport = starget_to_rport(scsi_target(SCpnt->device));
632 int err; 636 int err;
637 VirtDevice *vdev = SCpnt->device->hostdata;
633 638
634 err = fc_remote_port_chkready(rport); 639 if (!vdev || !vdev->vtarget) {
635 if (unlikely(err)) { 640 SCpnt->result = DID_NO_CONNECT << 16;
636 SCpnt->result = err;
637 done(SCpnt); 641 done(SCpnt);
638 return 0; 642 return 0;
639 } 643 }
640 644
641 if (!SCpnt->device->hostdata) { /* vdev */ 645 err = fc_remote_port_chkready(rport);
642 SCpnt->result = DID_NO_CONNECT << 16; 646 if (unlikely(err)) {
647 SCpnt->result = err;
643 done(SCpnt); 648 done(SCpnt);
644 return 0; 649 return 0;
645 } 650 }
@@ -1143,7 +1148,7 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1143 printk(MYIOC_s_WARN_FMT 1148 printk(MYIOC_s_WARN_FMT
1144 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n", 1149 "Skipping ioc=%p because SCSI Initiator mode is NOT enabled!\n",
1145 ioc->name, ioc); 1150 ioc->name, ioc);
1146 return -ENODEV; 1151 return 0;
1147 } 1152 }
1148 1153
1149 sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST)); 1154 sh = scsi_host_alloc(&mptfc_driver_template, sizeof(MPT_SCSI_HOST));
@@ -1173,10 +1178,9 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1173 /* set 16 byte cdb's */ 1178 /* set 16 byte cdb's */
1174 sh->max_cmd_len = 16; 1179 sh->max_cmd_len = 16;
1175 1180
1176 sh->max_id = MPT_MAX_FC_DEVICES<256 ? MPT_MAX_FC_DEVICES : 255; 1181 sh->max_id = ioc->pfacts->MaxDevices;
1182 sh->max_lun = max_lun;
1177 1183
1178 sh->max_lun = MPT_LAST_LUN + 1;
1179 sh->max_channel = 0;
1180 sh->this_id = ioc->pfacts[0].PortSCSIID; 1184 sh->this_id = ioc->pfacts[0].PortSCSIID;
1181 1185
1182 /* Required entry. 1186 /* Required entry.
@@ -1230,19 +1234,6 @@ mptfc_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1230 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n", 1234 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
1231 ioc->name, hd->ScsiLookup)); 1235 ioc->name, hd->ScsiLookup));
1232 1236
1233 /* Allocate memory for the device structures.
1234 * A non-Null pointer at an offset
1235 * indicates a device exists.
1236 * max_id = 1 + maximum id (hosts.h)
1237 */
1238 hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC);
1239 if (!hd->Targets) {
1240 error = -ENOMEM;
1241 goto out_mptfc_probe;
1242 }
1243
1244 dprintk((KERN_INFO " vdev @ %p\n", hd->Targets));
1245
1246 /* Clear the TM flags 1237 /* Clear the TM flags
1247 */ 1238 */
1248 hd->tmPending = 0; 1239 hd->tmPending = 0;
diff --git a/drivers/message/fusion/mptlan.c b/drivers/message/fusion/mptlan.c
index 2936204d8ad..b691292ff59 100644
--- a/drivers/message/fusion/mptlan.c
+++ b/drivers/message/fusion/mptlan.c
@@ -5,6 +5,7 @@
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * 6 *
7 * Copyright (c) 2000-2007 LSI Logic Corporation 7 * Copyright (c) 2000-2007 LSI Logic Corporation
8 * (mailto:mpt_linux_developer@lsi.com)
8 * 9 *
9 */ 10 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 11/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
diff --git a/drivers/message/fusion/mptlan.h b/drivers/message/fusion/mptlan.h
index 70ab75e7c26..fe438bf119f 100644
--- a/drivers/message/fusion/mptlan.h
+++ b/drivers/message/fusion/mptlan.h
@@ -5,6 +5,7 @@
5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 5 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
6 * 6 *
7 * Copyright (c) 2000-2007 LSI Logic Corporation 7 * Copyright (c) 2000-2007 LSI Logic Corporation
8 * (mailto:mpt_linux_developer@lsi.com)
8 * 9 *
9 */ 10 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 11/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
index 09e9a9d9641..84b8b485e95 100644
--- a/drivers/message/fusion/mptsas.c
+++ b/drivers/message/fusion/mptsas.c
@@ -4,7 +4,7 @@
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2007 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsi.com)
8 * Copyright (c) 2005-2007 Dell 8 * Copyright (c) 2005-2007 Dell
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -83,17 +83,31 @@ MODULE_PARM_DESC(mpt_pt_clear,
83 " Clear persistency table: enable=1 " 83 " Clear persistency table: enable=1 "
84 "(default=MPTSCSIH_PT_CLEAR=0)"); 84 "(default=MPTSCSIH_PT_CLEAR=0)");
85 85
86/* scsi-mid layer global parmeter is max_report_luns, which is 511 */
87#define MPTSAS_MAX_LUN (16895)
88static int max_lun = MPTSAS_MAX_LUN;
89module_param(max_lun, int, 0);
90MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
91
86static int mptsasDoneCtx = -1; 92static int mptsasDoneCtx = -1;
87static int mptsasTaskCtx = -1; 93static int mptsasTaskCtx = -1;
88static int mptsasInternalCtx = -1; /* Used only for internal commands */ 94static int mptsasInternalCtx = -1; /* Used only for internal commands */
89static int mptsasMgmtCtx = -1; 95static int mptsasMgmtCtx = -1;
90 96
97static void mptsas_hotplug_work(struct work_struct *work);
98
99struct mptsas_target_reset_event {
100 struct list_head list;
101 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE sas_event_data;
102 u8 target_reset_issued;
103};
91 104
92enum mptsas_hotplug_action { 105enum mptsas_hotplug_action {
93 MPTSAS_ADD_DEVICE, 106 MPTSAS_ADD_DEVICE,
94 MPTSAS_DEL_DEVICE, 107 MPTSAS_DEL_DEVICE,
95 MPTSAS_ADD_RAID, 108 MPTSAS_ADD_RAID,
96 MPTSAS_DEL_RAID, 109 MPTSAS_DEL_RAID,
110 MPTSAS_ADD_INACTIVE_VOLUME,
97 MPTSAS_IGNORE_EVENT, 111 MPTSAS_IGNORE_EVENT,
98}; 112};
99 113
@@ -102,14 +116,15 @@ struct mptsas_hotplug_event {
102 MPT_ADAPTER *ioc; 116 MPT_ADAPTER *ioc;
103 enum mptsas_hotplug_action event_type; 117 enum mptsas_hotplug_action event_type;
104 u64 sas_address; 118 u64 sas_address;
105 u32 channel; 119 u8 channel;
106 u32 id; 120 u8 id;
107 u32 device_info; 121 u32 device_info;
108 u16 handle; 122 u16 handle;
109 u16 parent_handle; 123 u16 parent_handle;
110 u8 phy_id; 124 u8 phy_id;
111 u8 phys_disk_num; 125 u8 phys_disk_num_valid; /* hrc (hidden raid component) */
112 u8 phys_disk_num_valid; 126 u8 phys_disk_num; /* hrc - unique index*/
127 u8 hidden_raid_component; /* hrc - don't expose*/
113}; 128};
114 129
115struct mptsas_discovery_event { 130struct mptsas_discovery_event {
@@ -134,6 +149,7 @@ struct mptsas_devinfo {
134 u8 port_id; /* sas physical port this device 149 u8 port_id; /* sas physical port this device
135 is assoc'd with */ 150 is assoc'd with */
136 u8 id; /* logical target id of this device */ 151 u8 id; /* logical target id of this device */
152 u32 phys_disk_num; /* phys disk id, for csmi-ioctls */
137 u8 channel; /* logical bus number of this device */ 153 u8 channel; /* logical bus number of this device */
138 u64 sas_address; /* WWN of this device, 154 u64 sas_address; /* WWN of this device,
139 SATA is assigned by HBA,expander */ 155 SATA is assigned by HBA,expander */
@@ -153,6 +169,7 @@ struct mptsas_portinfo_details{
153}; 169};
154 170
155struct mptsas_phyinfo { 171struct mptsas_phyinfo {
172 u16 handle; /* unique id to address this */
156 u8 phy_id; /* phy index */ 173 u8 phy_id; /* phy index */
157 u8 port_id; /* firmware port identifier */ 174 u8 port_id; /* firmware port identifier */
158 u8 negotiated_link_rate; /* nego'd link rate for this phy */ 175 u8 negotiated_link_rate; /* nego'd link rate for this phy */
@@ -168,7 +185,6 @@ struct mptsas_phyinfo {
168 185
169struct mptsas_portinfo { 186struct mptsas_portinfo {
170 struct list_head list; 187 struct list_head list;
171 u16 handle; /* unique id to address this */
172 u16 num_phys; /* number of phys */ 188 u16 num_phys; /* number of phys */
173 struct mptsas_phyinfo *phy_info; 189 struct mptsas_phyinfo *phy_info;
174}; 190};
@@ -561,22 +577,273 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
561 mutex_unlock(&ioc->sas_topology_mutex); 577 mutex_unlock(&ioc->sas_topology_mutex);
562} 578}
563 579
580/**
581 * csmisas_find_vtarget
582 *
583 * @ioc
584 * @volume_id
585 * @volume_bus
586 *
587 **/
588static VirtTarget *
589mptsas_find_vtarget(MPT_ADAPTER *ioc, u8 channel, u8 id)
590{
591 struct scsi_device *sdev;
592 VirtDevice *vdev;
593 VirtTarget *vtarget = NULL;
594
595 shost_for_each_device(sdev, ioc->sh) {
596 if ((vdev = sdev->hostdata) == NULL)
597 continue;
598 if (vdev->vtarget->id == id &&
599 vdev->vtarget->channel == channel)
600 vtarget = vdev->vtarget;
601 }
602 return vtarget;
603}
604
605/**
606 * mptsas_target_reset
607 *
608 * Issues TARGET_RESET to end device using handshaking method
609 *
610 * @ioc
611 * @channel
612 * @id
613 *
614 * Returns (1) success
615 * (0) failure
616 *
617 **/
618static int
619mptsas_target_reset(MPT_ADAPTER *ioc, u8 channel, u8 id)
620{
621 MPT_FRAME_HDR *mf;
622 SCSITaskMgmt_t *pScsiTm;
623
624 if ((mf = mpt_get_msg_frame(ioc->TaskCtx, ioc)) == NULL) {
625 dfailprintk((MYIOC_s_WARN_FMT "%s, no msg frames @%d!!\n",
626 ioc->name,__FUNCTION__, __LINE__));
627 return 0;
628 }
629
630 /* Format the Request
631 */
632 pScsiTm = (SCSITaskMgmt_t *) mf;
633 memset (pScsiTm, 0, sizeof(SCSITaskMgmt_t));
634 pScsiTm->TargetID = id;
635 pScsiTm->Bus = channel;
636 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
637 pScsiTm->TaskType = MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
638 pScsiTm->MsgFlags = MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION;
639
640 DBG_DUMP_TM_REQUEST_FRAME(mf);
641
642 if (mpt_send_handshake_request(ioc->TaskCtx, ioc,
643 sizeof(SCSITaskMgmt_t), (u32 *)mf, NO_SLEEP)) {
644 mpt_free_msg_frame(ioc, mf);
645 dfailprintk((MYIOC_s_WARN_FMT "%s, tm handshake failed @%d!!\n",
646 ioc->name,__FUNCTION__, __LINE__));
647 return 0;
648 }
649
650 return 1;
651}
652
653/**
654 * mptsas_target_reset_queue
655 *
656 * Receive request for TARGET_RESET after recieving an firmware
657 * event NOT_RESPONDING_EVENT, then put command in link list
658 * and queue if task_queue already in use.
659 *
660 * @ioc
661 * @sas_event_data
662 *
663 **/
564static void 664static void
565mptsas_target_reset(MPT_ADAPTER *ioc, VirtTarget * vtarget) 665mptsas_target_reset_queue(MPT_ADAPTER *ioc,
666 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data)
566{ 667{
567 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata; 668 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
669 VirtTarget *vtarget = NULL;
670 struct mptsas_target_reset_event *target_reset_list;
671 u8 id, channel;
568 672
569 if (mptscsih_TMHandler(hd, 673 id = sas_event_data->TargetID;
570 MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 674 channel = sas_event_data->Bus;
571 vtarget->bus_id, vtarget->target_id, 0, 0, 5) < 0) { 675
572 hd->tmPending = 0; 676 if (!(vtarget = mptsas_find_vtarget(ioc, channel, id)))
573 hd->tmState = TM_STATE_NONE; 677 return;
574 printk(MYIOC_s_WARN_FMT 678
575 "Error processing TaskMgmt id=%d TARGET_RESET\n", 679 vtarget->deleted = 1; /* block IO */
576 ioc->name, vtarget->target_id); 680
681 target_reset_list = kzalloc(sizeof(*target_reset_list),
682 GFP_ATOMIC);
683 if (!target_reset_list) {
684 dfailprintk((MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
685 ioc->name,__FUNCTION__, __LINE__));
686 return;
687 }
688
689 memcpy(&target_reset_list->sas_event_data, sas_event_data,
690 sizeof(*sas_event_data));
691 list_add_tail(&target_reset_list->list, &hd->target_reset_list);
692
693 if (hd->resetPending)
694 return;
695
696 if (mptsas_target_reset(ioc, channel, id)) {
697 target_reset_list->target_reset_issued = 1;
698 hd->resetPending = 1;
577 } 699 }
578} 700}
579 701
702/**
703 * mptsas_dev_reset_complete
704 *
705 * Completion for TARGET_RESET after NOT_RESPONDING_EVENT,
706 * enable work queue to finish off removing device from upper layers.
707 * then send next TARGET_RESET in the queue.
708 *
709 * @ioc
710 *
711 **/
712static void
713mptsas_dev_reset_complete(MPT_ADAPTER *ioc)
714{
715 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
716 struct list_head *head = &hd->target_reset_list;
717 struct mptsas_target_reset_event *target_reset_list;
718 struct mptsas_hotplug_event *ev;
719 EVENT_DATA_SAS_DEVICE_STATUS_CHANGE *sas_event_data;
720 u8 id, channel;
721 __le64 sas_address;
722
723 if (list_empty(head))
724 return;
725
726 target_reset_list = list_entry(head->next, struct mptsas_target_reset_event, list);
727
728 sas_event_data = &target_reset_list->sas_event_data;
729 id = sas_event_data->TargetID;
730 channel = sas_event_data->Bus;
731 hd->resetPending = 0;
732
733 /*
734 * retry target reset
735 */
736 if (!target_reset_list->target_reset_issued) {
737 if (mptsas_target_reset(ioc, channel, id)) {
738 target_reset_list->target_reset_issued = 1;
739 hd->resetPending = 1;
740 }
741 return;
742 }
743
744 /*
745 * enable work queue to remove device from upper layers
746 */
747 list_del(&target_reset_list->list);
748
749 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
750 if (!ev) {
751 dfailprintk((MYIOC_s_WARN_FMT "%s, failed to allocate mem @%d..!!\n",
752 ioc->name,__FUNCTION__, __LINE__));
753 return;
754 }
755
756 INIT_WORK(&ev->work, mptsas_hotplug_work);
757 ev->ioc = ioc;
758 ev->handle = le16_to_cpu(sas_event_data->DevHandle);
759 ev->parent_handle =
760 le16_to_cpu(sas_event_data->ParentDevHandle);
761 ev->channel = channel;
762 ev->id =id;
763 ev->phy_id = sas_event_data->PhyNum;
764 memcpy(&sas_address, &sas_event_data->SASAddress,
765 sizeof(__le64));
766 ev->sas_address = le64_to_cpu(sas_address);
767 ev->device_info = le32_to_cpu(sas_event_data->DeviceInfo);
768 ev->event_type = MPTSAS_DEL_DEVICE;
769 schedule_work(&ev->work);
770 kfree(target_reset_list);
771
772 /*
773 * issue target reset to next device in the queue
774 */
775
776 head = &hd->target_reset_list;
777 if (list_empty(head))
778 return;
779
780 target_reset_list = list_entry(head->next, struct mptsas_target_reset_event,
781 list);
782
783 sas_event_data = &target_reset_list->sas_event_data;
784 id = sas_event_data->TargetID;
785 channel = sas_event_data->Bus;
786
787 if (mptsas_target_reset(ioc, channel, id)) {
788 target_reset_list->target_reset_issued = 1;
789 hd->resetPending = 1;
790 }
791}
792
793/**
794 * mptsas_taskmgmt_complete
795 *
796 * @ioc
797 * @mf
798 * @mr
799 *
800 **/
801static int
802mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
803{
804 mptsas_dev_reset_complete(ioc);
805 return mptscsih_taskmgmt_complete(ioc, mf, mr);
806}
807
808/**
809 * mptscsih_ioc_reset
810 *
811 * @ioc
812 * @reset_phase
813 *
814 **/
815static int
816mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
817{
818 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
819 struct mptsas_target_reset_event *target_reset_list, *n;
820 int rc;
821
822 rc = mptscsih_ioc_reset(ioc, reset_phase);
823
824 if (ioc->bus_type != SAS)
825 goto out;
826
827 if (reset_phase != MPT_IOC_POST_RESET)
828 goto out;
829
830 if (!hd || !hd->ioc)
831 goto out;
832
833 if (list_empty(&hd->target_reset_list))
834 goto out;
835
836 /* flush the target_reset_list */
837 list_for_each_entry_safe(target_reset_list, n,
838 &hd->target_reset_list, list) {
839 list_del(&target_reset_list->list);
840 kfree(target_reset_list);
841 }
842
843 out:
844 return rc;
845}
846
580static int 847static int
581mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure, 848mptsas_sas_enclosure_pg0(MPT_ADAPTER *ioc, struct mptsas_enclosure *enclosure,
582 u32 form, u32 form_specific) 849 u32 form, u32 form_specific)
@@ -661,8 +928,7 @@ mptsas_target_alloc(struct scsi_target *starget)
661 struct Scsi_Host *host = dev_to_shost(&starget->dev); 928 struct Scsi_Host *host = dev_to_shost(&starget->dev);
662 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata; 929 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
663 VirtTarget *vtarget; 930 VirtTarget *vtarget;
664 u32 target_id; 931 u8 id, channel;
665 u32 channel;
666 struct sas_rphy *rphy; 932 struct sas_rphy *rphy;
667 struct mptsas_portinfo *p; 933 struct mptsas_portinfo *p;
668 int i; 934 int i;
@@ -673,15 +939,19 @@ mptsas_target_alloc(struct scsi_target *starget)
673 939
674 vtarget->starget = starget; 940 vtarget->starget = starget;
675 vtarget->ioc_id = hd->ioc->id; 941 vtarget->ioc_id = hd->ioc->id;
676 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES|MPT_TARGET_FLAGS_VALID_INQUIRY; 942 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
677 943 id = starget->id;
678 target_id = starget->id;
679 channel = 0; 944 channel = 0;
680 945
681 hd->Targets[target_id] = vtarget; 946 /*
682 947 * RAID volumes placed beyond the last expected port.
683 if (starget->channel == MPTSAS_RAID_CHANNEL) 948 */
949 if (starget->channel == MPTSAS_RAID_CHANNEL) {
950 for (i=0; i < hd->ioc->raid_data.pIocPg2->NumActiveVolumes; i++)
951 if (id == hd->ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID)
952 channel = hd->ioc->raid_data.pIocPg2->RaidVolume[i].VolumeBus;
684 goto out; 953 goto out;
954 }
685 955
686 rphy = dev_to_rphy(starget->dev.parent); 956 rphy = dev_to_rphy(starget->dev.parent);
687 mutex_lock(&hd->ioc->sas_topology_mutex); 957 mutex_lock(&hd->ioc->sas_topology_mutex);
@@ -690,18 +960,19 @@ mptsas_target_alloc(struct scsi_target *starget)
690 if (p->phy_info[i].attached.sas_address != 960 if (p->phy_info[i].attached.sas_address !=
691 rphy->identify.sas_address) 961 rphy->identify.sas_address)
692 continue; 962 continue;
693 target_id = p->phy_info[i].attached.id; 963 id = p->phy_info[i].attached.id;
694 channel = p->phy_info[i].attached.channel; 964 channel = p->phy_info[i].attached.channel;
695 mptsas_set_starget(&p->phy_info[i], starget); 965 mptsas_set_starget(&p->phy_info[i], starget);
696 966
697 /* 967 /*
698 * Exposing hidden raid components 968 * Exposing hidden raid components
699 */ 969 */
700 if (mptscsih_is_phys_disk(hd->ioc, target_id)) { 970 if (mptscsih_is_phys_disk(hd->ioc, channel, id)) {
701 target_id = mptscsih_raid_id_to_num(hd, 971 id = mptscsih_raid_id_to_num(hd->ioc,
702 target_id); 972 channel, id);
703 vtarget->tflags |= 973 vtarget->tflags |=
704 MPT_TARGET_FLAGS_RAID_COMPONENT; 974 MPT_TARGET_FLAGS_RAID_COMPONENT;
975 p->phy_info[i].attached.phys_disk_num = id;
705 } 976 }
706 mutex_unlock(&hd->ioc->sas_topology_mutex); 977 mutex_unlock(&hd->ioc->sas_topology_mutex);
707 goto out; 978 goto out;
@@ -713,8 +984,8 @@ mptsas_target_alloc(struct scsi_target *starget)
713 return -ENXIO; 984 return -ENXIO;
714 985
715 out: 986 out:
716 vtarget->target_id = target_id; 987 vtarget->id = id;
717 vtarget->bus_id = channel; 988 vtarget->channel = channel;
718 starget->hostdata = vtarget; 989 starget->hostdata = vtarget;
719 return 0; 990 return 0;
720} 991}
@@ -786,7 +1057,8 @@ mptsas_slave_alloc(struct scsi_device *sdev)
786 * Exposing hidden raid components 1057 * Exposing hidden raid components
787 */ 1058 */
788 if (mptscsih_is_phys_disk(hd->ioc, 1059 if (mptscsih_is_phys_disk(hd->ioc,
789 p->phy_info[i].attached.id)) 1060 p->phy_info[i].attached.channel,
1061 p->phy_info[i].attached.id))
790 sdev->no_uld_attach = 1; 1062 sdev->no_uld_attach = 1;
791 mutex_unlock(&hd->ioc->sas_topology_mutex); 1063 mutex_unlock(&hd->ioc->sas_topology_mutex);
792 goto out; 1064 goto out;
@@ -808,13 +1080,14 @@ mptsas_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
808{ 1080{
809 VirtDevice *vdev = SCpnt->device->hostdata; 1081 VirtDevice *vdev = SCpnt->device->hostdata;
810 1082
811// scsi_print_command(SCpnt); 1083 if (!vdev || !vdev->vtarget || vdev->vtarget->deleted) {
812 if (vdev->vtarget->deleted) {
813 SCpnt->result = DID_NO_CONNECT << 16; 1084 SCpnt->result = DID_NO_CONNECT << 16;
814 done(SCpnt); 1085 done(SCpnt);
815 return 0; 1086 return 0;
816 } 1087 }
817 1088
1089// scsi_print_command(SCpnt);
1090
818 return mptscsih_qcmd(SCpnt,done); 1091 return mptscsih_qcmd(SCpnt,done);
819} 1092}
820 1093
@@ -1114,9 +1387,6 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
1114 goto out_free_consistent; 1387 goto out_free_consistent;
1115 } 1388 }
1116 1389
1117 if (port_info->num_phys)
1118 port_info->handle =
1119 le16_to_cpu(buffer->PhyData[0].ControllerDevHandle);
1120 for (i = 0; i < port_info->num_phys; i++) { 1390 for (i = 0; i < port_info->num_phys; i++) {
1121 mptsas_print_phy_data(&buffer->PhyData[i]); 1391 mptsas_print_phy_data(&buffer->PhyData[i]);
1122 port_info->phy_info[i].phy_id = i; 1392 port_info->phy_info[i].phy_id = i;
@@ -1125,6 +1395,8 @@ mptsas_sas_io_unit_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info)
1125 port_info->phy_info[i].negotiated_link_rate = 1395 port_info->phy_info[i].negotiated_link_rate =
1126 buffer->PhyData[i].NegotiatedLinkRate; 1396 buffer->PhyData[i].NegotiatedLinkRate;
1127 port_info->phy_info[i].portinfo = port_info; 1397 port_info->phy_info[i].portinfo = port_info;
1398 port_info->phy_info[i].handle =
1399 le16_to_cpu(buffer->PhyData[i].ControllerDevHandle);
1128 } 1400 }
1129 1401
1130 out_free_consistent: 1402 out_free_consistent:
@@ -1261,6 +1533,7 @@ mptsas_sas_device_pg0(MPT_ADAPTER *ioc, struct mptsas_devinfo *device_info,
1261 device_info->phy_id = buffer->PhyNum; 1533 device_info->phy_id = buffer->PhyNum;
1262 device_info->port_id = buffer->PhysicalPort; 1534 device_info->port_id = buffer->PhysicalPort;
1263 device_info->id = buffer->TargetID; 1535 device_info->id = buffer->TargetID;
1536 device_info->phys_disk_num = ~0;
1264 device_info->channel = buffer->Bus; 1537 device_info->channel = buffer->Bus;
1265 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64)); 1538 memcpy(&sas_address, &buffer->SASAddress, sizeof(__le64));
1266 device_info->sas_address = le64_to_cpu(sas_address); 1539 device_info->sas_address = le64_to_cpu(sas_address);
@@ -1325,7 +1598,6 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
1325 1598
1326 /* save config data */ 1599 /* save config data */
1327 port_info->num_phys = buffer->NumPhys; 1600 port_info->num_phys = buffer->NumPhys;
1328 port_info->handle = le16_to_cpu(buffer->DevHandle);
1329 port_info->phy_info = kcalloc(port_info->num_phys, 1601 port_info->phy_info = kcalloc(port_info->num_phys,
1330 sizeof(*port_info->phy_info),GFP_KERNEL); 1602 sizeof(*port_info->phy_info),GFP_KERNEL);
1331 if (!port_info->phy_info) { 1603 if (!port_info->phy_info) {
@@ -1333,8 +1605,11 @@ mptsas_sas_expander_pg0(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info,
1333 goto out_free_consistent; 1605 goto out_free_consistent;
1334 } 1606 }
1335 1607
1336 for (i = 0; i < port_info->num_phys; i++) 1608 for (i = 0; i < port_info->num_phys; i++) {
1337 port_info->phy_info[i].portinfo = port_info; 1609 port_info->phy_info[i].portinfo = port_info;
1610 port_info->phy_info[i].handle =
1611 le16_to_cpu(buffer->DevHandle);
1612 }
1338 1613
1339 out_free_consistent: 1614 out_free_consistent:
1340 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4, 1615 pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
@@ -1702,7 +1977,6 @@ static int
1702mptsas_probe_hba_phys(MPT_ADAPTER *ioc) 1977mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1703{ 1978{
1704 struct mptsas_portinfo *port_info, *hba; 1979 struct mptsas_portinfo *port_info, *hba;
1705 u32 handle = 0xFFFF;
1706 int error = -ENOMEM, i; 1980 int error = -ENOMEM, i;
1707 1981
1708 hba = kzalloc(sizeof(*port_info), GFP_KERNEL); 1982 hba = kzalloc(sizeof(*port_info), GFP_KERNEL);
@@ -1714,34 +1988,36 @@ mptsas_probe_hba_phys(MPT_ADAPTER *ioc)
1714 goto out_free_port_info; 1988 goto out_free_port_info;
1715 1989
1716 mutex_lock(&ioc->sas_topology_mutex); 1990 mutex_lock(&ioc->sas_topology_mutex);
1717 ioc->handle = hba->handle; 1991 ioc->handle = hba->phy_info[0].handle;
1718 port_info = mptsas_find_portinfo_by_handle(ioc, hba->handle); 1992 port_info = mptsas_find_portinfo_by_handle(ioc, ioc->handle);
1719 if (!port_info) { 1993 if (!port_info) {
1720 port_info = hba; 1994 port_info = hba;
1721 list_add_tail(&port_info->list, &ioc->sas_topology); 1995 list_add_tail(&port_info->list, &ioc->sas_topology);
1722 } else { 1996 } else {
1723 port_info->handle = hba->handle; 1997 for (i = 0; i < hba->num_phys; i++) {
1724 for (i = 0; i < hba->num_phys; i++)
1725 port_info->phy_info[i].negotiated_link_rate = 1998 port_info->phy_info[i].negotiated_link_rate =
1726 hba->phy_info[i].negotiated_link_rate; 1999 hba->phy_info[i].negotiated_link_rate;
2000 port_info->phy_info[i].handle =
2001 hba->phy_info[i].handle;
2002 port_info->phy_info[i].port_id =
2003 hba->phy_info[i].port_id;
2004 }
1727 kfree(hba->phy_info); 2005 kfree(hba->phy_info);
1728 kfree(hba); 2006 kfree(hba);
1729 hba = NULL; 2007 hba = NULL;
1730 } 2008 }
1731 mutex_unlock(&ioc->sas_topology_mutex); 2009 mutex_unlock(&ioc->sas_topology_mutex);
1732
1733 for (i = 0; i < port_info->num_phys; i++) { 2010 for (i = 0; i < port_info->num_phys; i++) {
1734 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i], 2011 mptsas_sas_phy_pg0(ioc, &port_info->phy_info[i],
1735 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER << 2012 (MPI_SAS_PHY_PGAD_FORM_PHY_NUMBER <<
1736 MPI_SAS_PHY_PGAD_FORM_SHIFT), i); 2013 MPI_SAS_PHY_PGAD_FORM_SHIFT), i);
1737 2014
1738 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify, 2015 mptsas_sas_device_pg0(ioc, &port_info->phy_info[i].identify,
1739 (MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE << 2016 (MPI_SAS_DEVICE_PGAD_FORM_HANDLE <<
1740 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), handle); 2017 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2018 port_info->phy_info[i].handle);
1741 port_info->phy_info[i].identify.phy_id = 2019 port_info->phy_info[i].identify.phy_id =
1742 port_info->phy_info[i].phy_id; 2020 port_info->phy_info[i].phy_id = i;
1743 handle = port_info->phy_info[i].identify.handle;
1744
1745 if (port_info->phy_info[i].attached.handle) 2021 if (port_info->phy_info[i].attached.handle)
1746 mptsas_sas_device_pg0(ioc, 2022 mptsas_sas_device_pg0(ioc,
1747 &port_info->phy_info[i].attached, 2023 &port_info->phy_info[i].attached,
@@ -1777,12 +2053,12 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1777 goto out; 2053 goto out;
1778 2054
1779 error = mptsas_sas_expander_pg0(ioc, ex, 2055 error = mptsas_sas_expander_pg0(ioc, ex,
1780 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE << 2056 (MPI_SAS_EXPAND_PGAD_FORM_GET_NEXT_HANDLE <<
1781 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle); 2057 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), *handle);
1782 if (error) 2058 if (error)
1783 goto out_free_port_info; 2059 goto out_free_port_info;
1784 2060
1785 *handle = ex->handle; 2061 *handle = ex->phy_info[0].handle;
1786 2062
1787 mutex_lock(&ioc->sas_topology_mutex); 2063 mutex_lock(&ioc->sas_topology_mutex);
1788 port_info = mptsas_find_portinfo_by_handle(ioc, *handle); 2064 port_info = mptsas_find_portinfo_by_handle(ioc, *handle);
@@ -1790,7 +2066,12 @@ mptsas_probe_expander_phys(MPT_ADAPTER *ioc, u32 *handle)
1790 port_info = ex; 2066 port_info = ex;
1791 list_add_tail(&port_info->list, &ioc->sas_topology); 2067 list_add_tail(&port_info->list, &ioc->sas_topology);
1792 } else { 2068 } else {
1793 port_info->handle = ex->handle; 2069 for (i = 0; i < ex->num_phys; i++) {
2070 port_info->phy_info[i].handle =
2071 ex->phy_info[i].handle;
2072 port_info->phy_info[i].port_id =
2073 ex->phy_info[i].port_id;
2074 }
1794 kfree(ex->phy_info); 2075 kfree(ex->phy_info);
1795 kfree(ex); 2076 kfree(ex);
1796 ex = NULL; 2077 ex = NULL;
@@ -1868,8 +2149,6 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1868 struct mptsas_portinfo buffer; 2149 struct mptsas_portinfo buffer;
1869 struct mptsas_portinfo *port_info, *n, *parent; 2150 struct mptsas_portinfo *port_info, *n, *parent;
1870 struct mptsas_phyinfo *phy_info; 2151 struct mptsas_phyinfo *phy_info;
1871 struct scsi_target * starget;
1872 VirtTarget * vtarget;
1873 struct sas_port * port; 2152 struct sas_port * port;
1874 int i; 2153 int i;
1875 u64 expander_sas_address; 2154 u64 expander_sas_address;
@@ -1884,26 +2163,8 @@ mptsas_delete_expander_phys(MPT_ADAPTER *ioc)
1884 2163
1885 if (mptsas_sas_expander_pg0(ioc, &buffer, 2164 if (mptsas_sas_expander_pg0(ioc, &buffer,
1886 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE << 2165 (MPI_SAS_EXPAND_PGAD_FORM_HANDLE <<
1887 MPI_SAS_EXPAND_PGAD_FORM_SHIFT), port_info->handle)) { 2166 MPI_SAS_EXPAND_PGAD_FORM_SHIFT),
1888 2167 port_info->phy_info[0].handle)) {
1889 /*
1890 * Issue target reset to all child end devices
1891 * then mark them deleted to prevent further
1892 * IO going to them.
1893 */
1894 phy_info = port_info->phy_info;
1895 for (i = 0; i < port_info->num_phys; i++, phy_info++) {
1896 starget = mptsas_get_starget(phy_info);
1897 if (!starget)
1898 continue;
1899 vtarget = starget->hostdata;
1900 if(vtarget->deleted)
1901 continue;
1902 vtarget->deleted = 1;
1903 mptsas_target_reset(ioc, vtarget);
1904 sas_port_delete(mptsas_get_port(phy_info));
1905 mptsas_port_delete(phy_info->port_details);
1906 }
1907 2168
1908 /* 2169 /*
1909 * Obtain the port_info instance to the parent port 2170 * Obtain the port_info instance to the parent port
@@ -1972,11 +2233,13 @@ mptsas_scan_sas_topology(MPT_ADAPTER *ioc)
1972 /* 2233 /*
1973 Reporting RAID volumes. 2234 Reporting RAID volumes.
1974 */ 2235 */
2236 if (!ioc->ir_firmware)
2237 goto out;
1975 if (!ioc->raid_data.pIocPg2) 2238 if (!ioc->raid_data.pIocPg2)
1976 goto out; 2239 goto out;
1977 if (!ioc->raid_data.pIocPg2->NumActiveVolumes) 2240 if (!ioc->raid_data.pIocPg2->NumActiveVolumes)
1978 goto out; 2241 goto out;
1979 for (i=0; i<ioc->raid_data.pIocPg2->NumActiveVolumes; i++) { 2242 for (i = 0; i < ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
1980 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL, 2243 scsi_add_device(ioc->sh, MPTSAS_RAID_CHANNEL,
1981 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0); 2244 ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID, 0);
1982 } 2245 }
@@ -2030,12 +2293,37 @@ mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
2030 mutex_lock(&ioc->sas_topology_mutex); 2293 mutex_lock(&ioc->sas_topology_mutex);
2031 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2294 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2032 for (i = 0; i < port_info->num_phys; i++) { 2295 for (i = 0; i < port_info->num_phys; i++) {
2296 if (!mptsas_is_end_device(
2297 &port_info->phy_info[i].attached))
2298 continue;
2033 if (port_info->phy_info[i].attached.sas_address 2299 if (port_info->phy_info[i].attached.sas_address
2034 != sas_address) 2300 != sas_address)
2035 continue; 2301 continue;
2302 phy_info = &port_info->phy_info[i];
2303 break;
2304 }
2305 }
2306 mutex_unlock(&ioc->sas_topology_mutex);
2307 return phy_info;
2308}
2309
2310static struct mptsas_phyinfo *
2311mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u8 channel, u8 id)
2312{
2313 struct mptsas_portinfo *port_info;
2314 struct mptsas_phyinfo *phy_info = NULL;
2315 int i;
2316
2317 mutex_lock(&ioc->sas_topology_mutex);
2318 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2319 for (i = 0; i < port_info->num_phys; i++) {
2036 if (!mptsas_is_end_device( 2320 if (!mptsas_is_end_device(
2037 &port_info->phy_info[i].attached)) 2321 &port_info->phy_info[i].attached))
2038 continue; 2322 continue;
2323 if (port_info->phy_info[i].attached.id != id)
2324 continue;
2325 if (port_info->phy_info[i].attached.channel != channel)
2326 continue;
2039 phy_info = &port_info->phy_info[i]; 2327 phy_info = &port_info->phy_info[i];
2040 break; 2328 break;
2041 } 2329 }
@@ -2045,7 +2333,7 @@ mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address)
2045} 2333}
2046 2334
2047static struct mptsas_phyinfo * 2335static struct mptsas_phyinfo *
2048mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id) 2336mptsas_find_phyinfo_by_phys_disk_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
2049{ 2337{
2050 struct mptsas_portinfo *port_info; 2338 struct mptsas_portinfo *port_info;
2051 struct mptsas_phyinfo *phy_info = NULL; 2339 struct mptsas_phyinfo *phy_info = NULL;
@@ -2054,11 +2342,15 @@ mptsas_find_phyinfo_by_target(MPT_ADAPTER *ioc, u32 id)
2054 mutex_lock(&ioc->sas_topology_mutex); 2342 mutex_lock(&ioc->sas_topology_mutex);
2055 list_for_each_entry(port_info, &ioc->sas_topology, list) { 2343 list_for_each_entry(port_info, &ioc->sas_topology, list) {
2056 for (i = 0; i < port_info->num_phys; i++) { 2344 for (i = 0; i < port_info->num_phys; i++) {
2057 if (port_info->phy_info[i].attached.id != id)
2058 continue;
2059 if (!mptsas_is_end_device( 2345 if (!mptsas_is_end_device(
2060 &port_info->phy_info[i].attached)) 2346 &port_info->phy_info[i].attached))
2061 continue; 2347 continue;
2348 if (port_info->phy_info[i].attached.phys_disk_num == ~0)
2349 continue;
2350 if (port_info->phy_info[i].attached.phys_disk_num != id)
2351 continue;
2352 if (port_info->phy_info[i].attached.channel != channel)
2353 continue;
2062 phy_info = &port_info->phy_info[i]; 2354 phy_info = &port_info->phy_info[i];
2063 break; 2355 break;
2064 } 2356 }
@@ -2094,6 +2386,76 @@ mptsas_reprobe_target(struct scsi_target *starget, int uld_attach)
2094 mptsas_reprobe_lun); 2386 mptsas_reprobe_lun);
2095} 2387}
2096 2388
2389static void
2390mptsas_adding_inactive_raid_components(MPT_ADAPTER *ioc, u8 channel, u8 id)
2391{
2392 CONFIGPARMS cfg;
2393 ConfigPageHeader_t hdr;
2394 dma_addr_t dma_handle;
2395 pRaidVolumePage0_t buffer = NULL;
2396 RaidPhysDiskPage0_t phys_disk;
2397 int i;
2398 struct mptsas_hotplug_event *ev;
2399
2400 memset(&cfg, 0 , sizeof(CONFIGPARMS));
2401 memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
2402 hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
2403 cfg.pageAddr = (channel << 8) + id;
2404 cfg.cfghdr.hdr = &hdr;
2405 cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
2406
2407 if (mpt_config(ioc, &cfg) != 0)
2408 goto out;
2409
2410 if (!hdr.PageLength)
2411 goto out;
2412
2413 buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
2414 &dma_handle);
2415
2416 if (!buffer)
2417 goto out;
2418
2419 cfg.physAddr = dma_handle;
2420 cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
2421
2422 if (mpt_config(ioc, &cfg) != 0)
2423 goto out;
2424
2425 if (!(buffer->VolumeStatus.Flags &
2426 MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE))
2427 goto out;
2428
2429 if (!buffer->NumPhysDisks)
2430 goto out;
2431
2432 for (i = 0; i < buffer->NumPhysDisks; i++) {
2433
2434 if (mpt_raid_phys_disk_pg0(ioc,
2435 buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
2436 continue;
2437
2438 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2439 if (!ev) {
2440 printk(KERN_WARNING "mptsas: lost hotplug event\n");
2441 goto out;
2442 }
2443
2444 INIT_WORK(&ev->work, mptsas_hotplug_work);
2445 ev->ioc = ioc;
2446 ev->id = phys_disk.PhysDiskID;
2447 ev->channel = phys_disk.PhysDiskBus;
2448 ev->phys_disk_num_valid = 1;
2449 ev->phys_disk_num = phys_disk.PhysDiskNum;
2450 ev->event_type = MPTSAS_ADD_DEVICE;
2451 schedule_work(&ev->work);
2452 }
2453
2454 out:
2455 if (buffer)
2456 pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
2457 dma_handle);
2458}
2097/* 2459/*
2098 * Work queue thread to handle SAS hotplug events 2460 * Work queue thread to handle SAS hotplug events
2099 */ 2461 */
@@ -2102,6 +2464,7 @@ mptsas_hotplug_work(struct work_struct *work)
2102{ 2464{
2103 struct mptsas_hotplug_event *ev = 2465 struct mptsas_hotplug_event *ev =
2104 container_of(work, struct mptsas_hotplug_event, work); 2466 container_of(work, struct mptsas_hotplug_event, work);
2467
2105 MPT_ADAPTER *ioc = ev->ioc; 2468 MPT_ADAPTER *ioc = ev->ioc;
2106 struct mptsas_phyinfo *phy_info; 2469 struct mptsas_phyinfo *phy_info;
2107 struct sas_rphy *rphy; 2470 struct sas_rphy *rphy;
@@ -2114,17 +2477,43 @@ mptsas_hotplug_work(struct work_struct *work)
2114 VirtTarget *vtarget; 2477 VirtTarget *vtarget;
2115 VirtDevice *vdevice; 2478 VirtDevice *vdevice;
2116 2479
2117
2118 mutex_lock(&ioc->sas_discovery_mutex); 2480 mutex_lock(&ioc->sas_discovery_mutex);
2119 switch (ev->event_type) { 2481 switch (ev->event_type) {
2120 case MPTSAS_DEL_DEVICE: 2482 case MPTSAS_DEL_DEVICE:
2121 2483
2122 phy_info = mptsas_find_phyinfo_by_target(ioc, ev->id); 2484 phy_info = NULL;
2485 if (ev->phys_disk_num_valid) {
2486 if (ev->hidden_raid_component){
2487 if (mptsas_sas_device_pg0(ioc, &sas_device,
2488 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
2489 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2490 (ev->channel << 8) + ev->id)) {
2491 dfailprintk((MYIOC_s_ERR_FMT
2492 "%s: exit at line=%d\n", ioc->name,
2493 __FUNCTION__, __LINE__));
2494 break;
2495 }
2496 phy_info = mptsas_find_phyinfo_by_sas_address(
2497 ioc, sas_device.sas_address);
2498 }else
2499 phy_info = mptsas_find_phyinfo_by_phys_disk_num(
2500 ioc, ev->channel, ev->phys_disk_num);
2501 }
2502
2503 if (!phy_info)
2504 phy_info = mptsas_find_phyinfo_by_target(ioc,
2505 ev->channel, ev->id);
2123 2506
2124 /* 2507 /*
2125 * Sanity checks, for non-existing phys and remote rphys. 2508 * Sanity checks, for non-existing phys and remote rphys.
2126 */ 2509 */
2127 if (!phy_info || !phy_info->port_details) { 2510 if (!phy_info){
2511 dfailprintk((MYIOC_s_ERR_FMT
2512 "%s: exit at line=%d\n", ioc->name,
2513 __FUNCTION__, __LINE__));
2514 break;
2515 }
2516 if (!phy_info->port_details) {
2128 dfailprintk((MYIOC_s_ERR_FMT 2517 dfailprintk((MYIOC_s_ERR_FMT
2129 "%s: exit at line=%d\n", ioc->name, 2518 "%s: exit at line=%d\n", ioc->name,
2130 __FUNCTION__, __LINE__)); 2519 __FUNCTION__, __LINE__));
@@ -2137,6 +2526,7 @@ mptsas_hotplug_work(struct work_struct *work)
2137 __FUNCTION__, __LINE__)); 2526 __FUNCTION__, __LINE__));
2138 break; 2527 break;
2139 } 2528 }
2529
2140 port = mptsas_get_port(phy_info); 2530 port = mptsas_get_port(phy_info);
2141 if (!port) { 2531 if (!port) {
2142 dfailprintk((MYIOC_s_ERR_FMT 2532 dfailprintk((MYIOC_s_ERR_FMT
@@ -2159,28 +2549,35 @@ mptsas_hotplug_work(struct work_struct *work)
2159 /* 2549 /*
2160 * Handling RAID components 2550 * Handling RAID components
2161 */ 2551 */
2162 if (ev->phys_disk_num_valid) { 2552 if (ev->phys_disk_num_valid &&
2163 vtarget->target_id = ev->phys_disk_num; 2553 ev->hidden_raid_component) {
2164 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT; 2554 printk(MYIOC_s_INFO_FMT
2555 "RAID Hidding: channel=%d, id=%d, "
2556 "physdsk %d \n", ioc->name, ev->channel,
2557 ev->id, ev->phys_disk_num);
2558 vtarget->id = ev->phys_disk_num;
2559 vtarget->tflags |=
2560 MPT_TARGET_FLAGS_RAID_COMPONENT;
2165 mptsas_reprobe_target(starget, 1); 2561 mptsas_reprobe_target(starget, 1);
2166 break; 2562 phy_info->attached.phys_disk_num =
2563 ev->phys_disk_num;
2564 break;
2167 } 2565 }
2168
2169 vtarget->deleted = 1;
2170 mptsas_target_reset(ioc, vtarget);
2171 } 2566 }
2172 2567
2173 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET) 2568 if (phy_info->attached.device_info &
2569 MPI_SAS_DEVICE_INFO_SSP_TARGET)
2174 ds = "ssp"; 2570 ds = "ssp";
2175 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_STP_TARGET) 2571 if (phy_info->attached.device_info &
2572 MPI_SAS_DEVICE_INFO_STP_TARGET)
2176 ds = "stp"; 2573 ds = "stp";
2177 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE) 2574 if (phy_info->attached.device_info &
2575 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2178 ds = "sata"; 2576 ds = "sata";
2179 2577
2180 printk(MYIOC_s_INFO_FMT 2578 printk(MYIOC_s_INFO_FMT
2181 "removing %s device, channel %d, id %d, phy %d\n", 2579 "removing %s device, channel %d, id %d, phy %d\n",
2182 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id); 2580 ioc->name, ds, ev->channel, ev->id, phy_info->phy_id);
2183
2184#ifdef MPT_DEBUG_SAS_WIDE 2581#ifdef MPT_DEBUG_SAS_WIDE
2185 dev_printk(KERN_DEBUG, &port->dev, 2582 dev_printk(KERN_DEBUG, &port->dev,
2186 "delete port (%d)\n", port->port_identifier); 2583 "delete port (%d)\n", port->port_identifier);
@@ -2198,14 +2595,14 @@ mptsas_hotplug_work(struct work_struct *work)
2198 */ 2595 */
2199 if (mptsas_sas_device_pg0(ioc, &sas_device, 2596 if (mptsas_sas_device_pg0(ioc, &sas_device,
2200 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID << 2597 (MPI_SAS_DEVICE_PGAD_FORM_BUS_TARGET_ID <<
2201 MPI_SAS_DEVICE_PGAD_FORM_SHIFT), ev->id)) { 2598 MPI_SAS_DEVICE_PGAD_FORM_SHIFT),
2599 (ev->channel << 8) + ev->id)) {
2202 dfailprintk((MYIOC_s_ERR_FMT 2600 dfailprintk((MYIOC_s_ERR_FMT
2203 "%s: exit at line=%d\n", ioc->name, 2601 "%s: exit at line=%d\n", ioc->name,
2204 __FUNCTION__, __LINE__)); 2602 __FUNCTION__, __LINE__));
2205 break; 2603 break;
2206 } 2604 }
2207 2605
2208 ssleep(2);
2209 __mptsas_discovery_work(ioc); 2606 __mptsas_discovery_work(ioc);
2210 2607
2211 phy_info = mptsas_find_phyinfo_by_sas_address(ioc, 2608 phy_info = mptsas_find_phyinfo_by_sas_address(ioc,
@@ -2219,7 +2616,8 @@ mptsas_hotplug_work(struct work_struct *work)
2219 } 2616 }
2220 2617
2221 starget = mptsas_get_starget(phy_info); 2618 starget = mptsas_get_starget(phy_info);
2222 if (starget) { 2619 if (starget && (!ev->hidden_raid_component)){
2620
2223 vtarget = starget->hostdata; 2621 vtarget = starget->hostdata;
2224 2622
2225 if (!vtarget) { 2623 if (!vtarget) {
@@ -2232,9 +2630,15 @@ mptsas_hotplug_work(struct work_struct *work)
2232 * Handling RAID components 2630 * Handling RAID components
2233 */ 2631 */
2234 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) { 2632 if (vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) {
2235 vtarget->tflags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT; 2633 printk(MYIOC_s_INFO_FMT
2236 vtarget->target_id = ev->id; 2634 "RAID Exposing: channel=%d, id=%d, "
2635 "physdsk %d \n", ioc->name, ev->channel,
2636 ev->id, ev->phys_disk_num);
2637 vtarget->tflags &=
2638 ~MPT_TARGET_FLAGS_RAID_COMPONENT;
2639 vtarget->id = ev->id;
2237 mptsas_reprobe_target(starget, 0); 2640 mptsas_reprobe_target(starget, 0);
2641 phy_info->attached.phys_disk_num = ~0;
2238 } 2642 }
2239 break; 2643 break;
2240 } 2644 }
@@ -2243,8 +2647,10 @@ mptsas_hotplug_work(struct work_struct *work)
2243 dfailprintk((MYIOC_s_ERR_FMT 2647 dfailprintk((MYIOC_s_ERR_FMT
2244 "%s: exit at line=%d\n", ioc->name, 2648 "%s: exit at line=%d\n", ioc->name,
2245 __FUNCTION__, __LINE__)); 2649 __FUNCTION__, __LINE__));
2650 if (ev->channel) printk("%d\n", __LINE__);
2246 break; 2651 break;
2247 } 2652 }
2653
2248 port = mptsas_get_port(phy_info); 2654 port = mptsas_get_port(phy_info);
2249 if (!port) { 2655 if (!port) {
2250 dfailprintk((MYIOC_s_ERR_FMT 2656 dfailprintk((MYIOC_s_ERR_FMT
@@ -2252,15 +2658,17 @@ mptsas_hotplug_work(struct work_struct *work)
2252 __FUNCTION__, __LINE__)); 2658 __FUNCTION__, __LINE__));
2253 break; 2659 break;
2254 } 2660 }
2255
2256 memcpy(&phy_info->attached, &sas_device, 2661 memcpy(&phy_info->attached, &sas_device,
2257 sizeof(struct mptsas_devinfo)); 2662 sizeof(struct mptsas_devinfo));
2258 2663
2259 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SSP_TARGET) 2664 if (phy_info->attached.device_info &
2665 MPI_SAS_DEVICE_INFO_SSP_TARGET)
2260 ds = "ssp"; 2666 ds = "ssp";
2261 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_STP_TARGET) 2667 if (phy_info->attached.device_info &
2668 MPI_SAS_DEVICE_INFO_STP_TARGET)
2262 ds = "stp"; 2669 ds = "stp";
2263 if (phy_info->attached.device_info & MPI_SAS_DEVICE_INFO_SATA_DEVICE) 2670 if (phy_info->attached.device_info &
2671 MPI_SAS_DEVICE_INFO_SATA_DEVICE)
2264 ds = "sata"; 2672 ds = "sata";
2265 2673
2266 printk(MYIOC_s_INFO_FMT 2674 printk(MYIOC_s_INFO_FMT
@@ -2301,19 +2709,21 @@ mptsas_hotplug_work(struct work_struct *work)
2301 break; 2709 break;
2302 case MPTSAS_DEL_RAID: 2710 case MPTSAS_DEL_RAID:
2303 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL, 2711 sdev = scsi_device_lookup(ioc->sh, MPTSAS_RAID_CHANNEL,
2304 ev->id, 0); 2712 ev->id, 0);
2305 if (!sdev) 2713 if (!sdev)
2306 break; 2714 break;
2307 printk(MYIOC_s_INFO_FMT 2715 printk(MYIOC_s_INFO_FMT
2308 "removing raid volume, channel %d, id %d\n", 2716 "removing raid volume, channel %d, id %d\n",
2309 ioc->name, MPTSAS_RAID_CHANNEL, ev->id); 2717 ioc->name, MPTSAS_RAID_CHANNEL, ev->id);
2310 vdevice = sdev->hostdata; 2718 vdevice = sdev->hostdata;
2311 vdevice->vtarget->deleted = 1;
2312 mptsas_target_reset(ioc, vdevice->vtarget);
2313 scsi_remove_device(sdev); 2719 scsi_remove_device(sdev);
2314 scsi_device_put(sdev); 2720 scsi_device_put(sdev);
2315 mpt_findImVolumes(ioc); 2721 mpt_findImVolumes(ioc);
2316 break; 2722 break;
2723 case MPTSAS_ADD_INACTIVE_VOLUME:
2724 mptsas_adding_inactive_raid_components(ioc,
2725 ev->channel, ev->id);
2726 break;
2317 case MPTSAS_IGNORE_EVENT: 2727 case MPTSAS_IGNORE_EVENT:
2318 default: 2728 default:
2319 break; 2729 break;
@@ -2321,7 +2731,6 @@ mptsas_hotplug_work(struct work_struct *work)
2321 2731
2322 mutex_unlock(&ioc->sas_discovery_mutex); 2732 mutex_unlock(&ioc->sas_discovery_mutex);
2323 kfree(ev); 2733 kfree(ev);
2324
2325} 2734}
2326 2735
2327static void 2736static void
@@ -2339,8 +2748,12 @@ mptsas_send_sas_event(MPT_ADAPTER *ioc,
2339 return; 2748 return;
2340 2749
2341 switch (sas_event_data->ReasonCode) { 2750 switch (sas_event_data->ReasonCode) {
2342 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
2343 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING: 2751 case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
2752
2753 mptsas_target_reset_queue(ioc, sas_event_data);
2754 break;
2755
2756 case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
2344 ev = kzalloc(sizeof(*ev), GFP_ATOMIC); 2757 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2345 if (!ev) { 2758 if (!ev) {
2346 printk(KERN_WARNING "mptsas: lost hotplug event\n"); 2759 printk(KERN_WARNING "mptsas: lost hotplug event\n");
@@ -2375,15 +2788,20 @@ mptsas_send_sas_event(MPT_ADAPTER *ioc,
2375 mptsas_persist_clear_table); 2788 mptsas_persist_clear_table);
2376 schedule_work(&ioc->sas_persist_task); 2789 schedule_work(&ioc->sas_persist_task);
2377 break; 2790 break;
2791 /*
2792 * TODO, handle other events
2793 */
2378 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA: 2794 case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
2379 /* TODO */ 2795 case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
2380 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET: 2796 case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
2381 /* TODO */ 2797 case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
2798 case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
2799 case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
2800 case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
2382 default: 2801 default:
2383 break; 2802 break;
2384 } 2803 }
2385} 2804}
2386
2387static void 2805static void
2388mptsas_send_raid_event(MPT_ADAPTER *ioc, 2806mptsas_send_raid_event(MPT_ADAPTER *ioc,
2389 EVENT_DATA_RAID *raid_event_data) 2807 EVENT_DATA_RAID *raid_event_data)
@@ -2404,31 +2822,36 @@ mptsas_send_raid_event(MPT_ADAPTER *ioc,
2404 INIT_WORK(&ev->work, mptsas_hotplug_work); 2822 INIT_WORK(&ev->work, mptsas_hotplug_work);
2405 ev->ioc = ioc; 2823 ev->ioc = ioc;
2406 ev->id = raid_event_data->VolumeID; 2824 ev->id = raid_event_data->VolumeID;
2825 ev->channel = raid_event_data->VolumeBus;
2407 ev->event_type = MPTSAS_IGNORE_EVENT; 2826 ev->event_type = MPTSAS_IGNORE_EVENT;
2408 2827
2409 switch (raid_event_data->ReasonCode) { 2828 switch (raid_event_data->ReasonCode) {
2410 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED: 2829 case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
2830 ev->phys_disk_num_valid = 1;
2831 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2411 ev->event_type = MPTSAS_ADD_DEVICE; 2832 ev->event_type = MPTSAS_ADD_DEVICE;
2412 break; 2833 break;
2413 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED: 2834 case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
2414 ioc->raid_data.isRaid = 1;
2415 ev->phys_disk_num_valid = 1; 2835 ev->phys_disk_num_valid = 1;
2416 ev->phys_disk_num = raid_event_data->PhysDiskNum; 2836 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2837 ev->hidden_raid_component = 1;
2417 ev->event_type = MPTSAS_DEL_DEVICE; 2838 ev->event_type = MPTSAS_DEL_DEVICE;
2418 break; 2839 break;
2419 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED: 2840 case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
2420 switch (state) { 2841 switch (state) {
2421 case MPI_PD_STATE_ONLINE: 2842 case MPI_PD_STATE_ONLINE:
2422 ioc->raid_data.isRaid = 1; 2843 case MPI_PD_STATE_NOT_COMPATIBLE:
2423 ev->phys_disk_num_valid = 1; 2844 ev->phys_disk_num_valid = 1;
2424 ev->phys_disk_num = raid_event_data->PhysDiskNum; 2845 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2846 ev->hidden_raid_component = 1;
2425 ev->event_type = MPTSAS_ADD_DEVICE; 2847 ev->event_type = MPTSAS_ADD_DEVICE;
2426 break; 2848 break;
2427 case MPI_PD_STATE_MISSING: 2849 case MPI_PD_STATE_MISSING:
2428 case MPI_PD_STATE_NOT_COMPATIBLE:
2429 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST: 2850 case MPI_PD_STATE_OFFLINE_AT_HOST_REQUEST:
2430 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST: 2851 case MPI_PD_STATE_FAILED_AT_HOST_REQUEST:
2431 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON: 2852 case MPI_PD_STATE_OFFLINE_FOR_ANOTHER_REASON:
2853 ev->phys_disk_num_valid = 1;
2854 ev->phys_disk_num = raid_event_data->PhysDiskNum;
2432 ev->event_type = MPTSAS_DEL_DEVICE; 2855 ev->event_type = MPTSAS_DEL_DEVICE;
2433 break; 2856 break;
2434 default: 2857 default:
@@ -2485,6 +2908,35 @@ mptsas_send_discovery_event(MPT_ADAPTER *ioc,
2485 schedule_work(&ev->work); 2908 schedule_work(&ev->work);
2486}; 2909};
2487 2910
2911/*
2912 * mptsas_send_ir2_event - handle exposing hidden disk when
2913 * an inactive raid volume is added
2914 *
2915 * @ioc: Pointer to MPT_ADAPTER structure
2916 * @ir2_data
2917 *
2918 */
2919static void
2920mptsas_send_ir2_event(MPT_ADAPTER *ioc, PTR_MPI_EVENT_DATA_IR2 ir2_data)
2921{
2922 struct mptsas_hotplug_event *ev;
2923
2924 if (ir2_data->ReasonCode !=
2925 MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED)
2926 return;
2927
2928 ev = kzalloc(sizeof(*ev), GFP_ATOMIC);
2929 if (!ev)
2930 return;
2931
2932 INIT_WORK(&ev->work, mptsas_hotplug_work);
2933 ev->ioc = ioc;
2934 ev->id = ir2_data->TargetID;
2935 ev->channel = ir2_data->Bus;
2936 ev->event_type = MPTSAS_ADD_INACTIVE_VOLUME;
2937
2938 schedule_work(&ev->work);
2939};
2488 2940
2489static int 2941static int
2490mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply) 2942mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
@@ -2524,6 +2976,10 @@ mptsas_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *reply)
2524 mptsas_send_discovery_event(ioc, 2976 mptsas_send_discovery_event(ioc,
2525 (EVENT_DATA_SAS_DISCOVERY *)reply->Data); 2977 (EVENT_DATA_SAS_DISCOVERY *)reply->Data);
2526 break; 2978 break;
2979 case MPI_EVENT_IR2:
2980 mptsas_send_ir2_event(ioc,
2981 (PTR_MPI_EVENT_DATA_IR2)reply->Data);
2982 break;
2527 default: 2983 default:
2528 rc = mptscsih_event_process(ioc, reply); 2984 rc = mptscsih_event_process(ioc, reply);
2529 break; 2985 break;
@@ -2611,12 +3067,11 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2611 /* set 16 byte cdb's */ 3067 /* set 16 byte cdb's */
2612 sh->max_cmd_len = 16; 3068 sh->max_cmd_len = 16;
2613 3069
2614 sh->max_id = ioc->pfacts->MaxDevices + 1; 3070 sh->max_id = ioc->pfacts[0].PortSCSIID;
3071 sh->max_lun = max_lun;
2615 3072
2616 sh->transportt = mptsas_transport_template; 3073 sh->transportt = mptsas_transport_template;
2617 3074
2618 sh->max_lun = MPT_LAST_LUN + 1;
2619 sh->max_channel = 0;
2620 sh->this_id = ioc->pfacts[0].PortSCSIID; 3075 sh->this_id = ioc->pfacts[0].PortSCSIID;
2621 3076
2622 /* Required entry. 3077 /* Required entry.
@@ -2659,8 +3114,6 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2659 sh->sg_tablesize = numSGE; 3114 sh->sg_tablesize = numSGE;
2660 } 3115 }
2661 3116
2662 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2663
2664 hd = (MPT_SCSI_HOST *) sh->hostdata; 3117 hd = (MPT_SCSI_HOST *) sh->hostdata;
2665 hd->ioc = ioc; 3118 hd->ioc = ioc;
2666 3119
@@ -2676,19 +3129,6 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2676 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n", 3129 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
2677 ioc->name, hd->ScsiLookup)); 3130 ioc->name, hd->ScsiLookup));
2678 3131
2679 /* Allocate memory for the device structures.
2680 * A non-Null pointer at an offset
2681 * indicates a device exists.
2682 * max_id = 1 + maximum id (hosts.h)
2683 */
2684 hd->Targets = kcalloc(sh->max_id, sizeof(void *), GFP_ATOMIC);
2685 if (!hd->Targets) {
2686 error = -ENOMEM;
2687 goto out_mptsas_probe;
2688 }
2689
2690 dprintk((KERN_INFO " vtarget @ %p\n", hd->Targets));
2691
2692 /* Clear the TM flags 3132 /* Clear the TM flags
2693 */ 3133 */
2694 hd->tmPending = 0; 3134 hd->tmPending = 0;
@@ -2713,15 +3153,17 @@ mptsas_probe(struct pci_dev *pdev, const struct pci_device_id *id)
2713 3153
2714 ioc->sas_data.ptClear = mpt_pt_clear; 3154 ioc->sas_data.ptClear = mpt_pt_clear;
2715 3155
3156 init_waitqueue_head(&hd->scandv_waitq);
3157 hd->scandv_wait_done = 0;
3158 hd->last_queue_full = 0;
3159 INIT_LIST_HEAD(&hd->target_reset_list);
3160 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
3161
2716 if (ioc->sas_data.ptClear==1) { 3162 if (ioc->sas_data.ptClear==1) {
2717 mptbase_sas_persist_operation( 3163 mptbase_sas_persist_operation(
2718 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT); 3164 ioc, MPI_SAS_OP_CLEAR_ALL_PERSISTENT);
2719 } 3165 }
2720 3166
2721 init_waitqueue_head(&hd->scandv_waitq);
2722 hd->scandv_wait_done = 0;
2723 hd->last_queue_full = 0;
2724
2725 error = scsi_add_host(sh, &ioc->pcidev->dev); 3167 error = scsi_add_host(sh, &ioc->pcidev->dev);
2726 if (error) { 3168 if (error) {
2727 dprintk((KERN_ERR MYNAM 3169 dprintk((KERN_ERR MYNAM
@@ -2745,7 +3187,7 @@ static void __devexit mptsas_remove(struct pci_dev *pdev)
2745 struct mptsas_portinfo *p, *n; 3187 struct mptsas_portinfo *p, *n;
2746 int i; 3188 int i;
2747 3189
2748 ioc->sas_discovery_ignore_events=1; 3190 ioc->sas_discovery_ignore_events = 1;
2749 sas_remove_host(ioc->sh); 3191 sas_remove_host(ioc->sh);
2750 3192
2751 mutex_lock(&ioc->sas_topology_mutex); 3193 mutex_lock(&ioc->sas_topology_mutex);
@@ -2800,7 +3242,7 @@ mptsas_init(void)
2800 return -ENODEV; 3242 return -ENODEV;
2801 3243
2802 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER); 3244 mptsasDoneCtx = mpt_register(mptscsih_io_done, MPTSAS_DRIVER);
2803 mptsasTaskCtx = mpt_register(mptscsih_taskmgmt_complete, MPTSAS_DRIVER); 3245 mptsasTaskCtx = mpt_register(mptsas_taskmgmt_complete, MPTSAS_DRIVER);
2804 mptsasInternalCtx = 3246 mptsasInternalCtx =
2805 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER); 3247 mpt_register(mptscsih_scandv_complete, MPTSAS_DRIVER);
2806 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER); 3248 mptsasMgmtCtx = mpt_register(mptsas_mgmt_done, MPTSAS_DRIVER);
@@ -2810,7 +3252,7 @@ mptsas_init(void)
2810 ": Registered for IOC event notifications\n")); 3252 ": Registered for IOC event notifications\n"));
2811 } 3253 }
2812 3254
2813 if (mpt_reset_register(mptsasDoneCtx, mptscsih_ioc_reset) == 0) { 3255 if (mpt_reset_register(mptsasDoneCtx, mptsas_ioc_reset) == 0) {
2814 dprintk((KERN_INFO MYNAM 3256 dprintk((KERN_INFO MYNAM
2815 ": Registered for IOC reset notifications\n")); 3257 ": Registered for IOC reset notifications\n"));
2816 } 3258 }
diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
index f0cca3ea93b..c417ae0b5fe 100644
--- a/drivers/message/fusion/mptscsih.c
+++ b/drivers/message/fusion/mptscsih.c
@@ -4,7 +4,7 @@
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2007 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsi.com)
8 * 8 *
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -79,43 +79,6 @@ MODULE_LICENSE("GPL");
79MODULE_VERSION(my_VERSION); 79MODULE_VERSION(my_VERSION);
80 80
81/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 81/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
82
83typedef struct _BIG_SENSE_BUF {
84 u8 data[MPT_SENSE_BUFFER_ALLOC];
85} BIG_SENSE_BUF;
86
87#define MPT_SCANDV_GOOD (0x00000000) /* must be 0 */
88#define MPT_SCANDV_DID_RESET (0x00000001)
89#define MPT_SCANDV_SENSE (0x00000002)
90#define MPT_SCANDV_SOME_ERROR (0x00000004)
91#define MPT_SCANDV_SELECTION_TIMEOUT (0x00000008)
92#define MPT_SCANDV_ISSUE_SENSE (0x00000010)
93#define MPT_SCANDV_FALLBACK (0x00000020)
94
95#define MPT_SCANDV_MAX_RETRIES (10)
96
97#define MPT_ICFLAG_BUF_CAP 0x01 /* ReadBuffer Read Capacity format */
98#define MPT_ICFLAG_ECHO 0x02 /* ReadBuffer Echo buffer format */
99#define MPT_ICFLAG_EBOS 0x04 /* ReadBuffer Echo buffer has EBOS */
100#define MPT_ICFLAG_PHYS_DISK 0x08 /* Any SCSI IO but do Phys Disk Format */
101#define MPT_ICFLAG_TAGGED_CMD 0x10 /* Do tagged IO */
102#define MPT_ICFLAG_DID_RESET 0x20 /* Bus Reset occurred with this command */
103#define MPT_ICFLAG_RESERVED 0x40 /* Reserved has been issued */
104
105typedef struct _internal_cmd {
106 char *data; /* data pointer */
107 dma_addr_t data_dma; /* data dma address */
108 int size; /* transfer size */
109 u8 cmd; /* SCSI Op Code */
110 u8 bus; /* bus number */
111 u8 id; /* SCSI ID (virtual) */
112 u8 lun;
113 u8 flags; /* Bit Field - See above */
114 u8 physDiskNum; /* Phys disk number, -1 else */
115 u8 rsvd2;
116 u8 rsvd;
117} INTERNAL_CMD;
118
119/* 82/*
120 * Other private/forward protos... 83 * Other private/forward protos...
121 */ 84 */
@@ -131,14 +94,11 @@ static int mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd);
131static int mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout ); 94static int mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout );
132static int SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc); 95static int SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc);
133 96
134static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout); 97static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout);
135 98
136int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset); 99int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
137int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply); 100int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
138 101
139static void mptscsih_initTarget(MPT_SCSI_HOST *hd, VirtTarget *vtarget, struct scsi_device *sdev);
140static void mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *vtarget, struct scsi_device *sdev);
141static int mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus);
142int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r); 102int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
143static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd); 103static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
144static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice); 104static void mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice);
@@ -517,16 +477,100 @@ mptscsih_issue_sep_command(MPT_ADAPTER *ioc, VirtTarget *vtarget,
517 477
518 SEPMsg = (SEPRequest_t *)mf; 478 SEPMsg = (SEPRequest_t *)mf;
519 SEPMsg->Function = MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; 479 SEPMsg->Function = MPI_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
520 SEPMsg->Bus = vtarget->bus_id; 480 SEPMsg->Bus = vtarget->channel;
521 SEPMsg->TargetID = vtarget->target_id; 481 SEPMsg->TargetID = vtarget->id;
522 SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS; 482 SEPMsg->Action = MPI_SEP_REQ_ACTION_WRITE_STATUS;
523 SEPMsg->SlotStatus = SlotStatus; 483 SEPMsg->SlotStatus = SlotStatus;
524 devtverboseprintk((MYIOC_s_WARN_FMT 484 devtverboseprintk((MYIOC_s_WARN_FMT
525 "Sending SEP cmd=%x id=%d bus=%d\n", 485 "Sending SEP cmd=%x channel=%d id=%d\n",
526 ioc->name, SlotStatus, SEPMsg->TargetID, SEPMsg->Bus)); 486 ioc->name, SlotStatus, SEPMsg->Bus, SEPMsg->TargetID));
527 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf); 487 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
528} 488}
529 489
490#ifdef MPT_DEBUG_REPLY
491/**
492 * mptscsih_iocstatus_info_scsiio - IOCSTATUS information for SCSIIO
493 * @ioc: Pointer to MPT_ADAPTER structure
494 * @ioc_status: U32 IOCStatus word from IOC
495 * @scsi_status: U8 sam status from target
496 * @scsi_state: U8 scsi state
497 * @sc: original scsi cmnd pointer
498 * @mf: Pointer to MPT request frame
499 *
500 * Refer to lsi/mpi.h.
501 **/
502static void
503mptscsih_iocstatus_info_scsiio(MPT_ADAPTER *ioc, u32 ioc_status,
504 u8 scsi_status, u8 scsi_state, struct scsi_cmnd *sc)
505{
506 char extend_desc[EVENT_DESCR_STR_SZ];
507 char *desc = NULL;
508
509 switch (ioc_status) {
510
511 case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
512 desc = "SCSI Invalid Bus";
513 break;
514
515 case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
516 desc = "SCSI Invalid TargetID";
517 break;
518
519 case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
520 /*
521 * Inquiry is issued for device scanning
522 */
523 if (sc->cmnd[0] != 0x12)
524 desc = "SCSI Device Not There";
525 break;
526
527 case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
528 desc = "SCSI Data Overrun";
529 break;
530
531 case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
532 desc = "SCSI I/O Data Error";
533 break;
534
535 case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
536 desc = "SCSI Protocol Error";
537 break;
538
539 case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
540 desc = "SCSI Task Terminated";
541 break;
542
543 case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
544 desc = "SCSI Residual Mismatch";
545 break;
546
547 case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
548 desc = "SCSI Task Management Failed";
549 break;
550
551 case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
552 desc = "SCSI IOC Terminated";
553 break;
554
555 case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
556 desc = "SCSI Ext Terminated";
557 break;
558 }
559
560 if (!desc)
561 return;
562
563 snprintf(extend_desc, EVENT_DESCR_STR_SZ,
564 "[%d:%d:%d:%d] cmd=%02Xh, sam_status=%02Xh state=%02Xh",
565 sc->device->host->host_no,
566 sc->device->channel, sc->device->id, sc->device->lun,
567 sc->cmnd[0], scsi_status, scsi_state);
568
569 printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04X): %s: %s\n",
570 ioc->name, ioc_status, desc, extend_desc);
571}
572#endif
573
530/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 574/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
531/* 575/*
532 * mptscsih_io_done - Main SCSI IO callback routine registered to 576 * mptscsih_io_done - Main SCSI IO callback routine registered to
@@ -613,12 +657,14 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
613 u32 xfer_cnt; 657 u32 xfer_cnt;
614 u16 status; 658 u16 status;
615 u8 scsi_state, scsi_status; 659 u8 scsi_state, scsi_status;
660 u32 log_info;
616 661
617 status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK; 662 status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
618 scsi_state = pScsiReply->SCSIState; 663 scsi_state = pScsiReply->SCSIState;
619 scsi_status = pScsiReply->SCSIStatus; 664 scsi_status = pScsiReply->SCSIStatus;
620 xfer_cnt = le32_to_cpu(pScsiReply->TransferCount); 665 xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
621 sc->resid = sc->request_bufflen - xfer_cnt; 666 sc->resid = sc->request_bufflen - xfer_cnt;
667 log_info = le32_to_cpu(pScsiReply->IOCLogInfo);
622 668
623 /* 669 /*
624 * if we get a data underrun indication, yet no data was 670 * if we get a data underrun indication, yet no data was
@@ -633,13 +679,6 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
633 status = MPI_IOCSTATUS_SUCCESS; 679 status = MPI_IOCSTATUS_SUCCESS;
634 } 680 }
635 681
636 dreplyprintk((KERN_NOTICE "Reply ha=%d id=%d lun=%d:\n"
637 "IOCStatus=%04xh SCSIState=%02xh SCSIStatus=%02xh\n"
638 "resid=%d bufflen=%d xfer_cnt=%d\n",
639 ioc->id, sc->device->id, sc->device->lun,
640 status, scsi_state, scsi_status, sc->resid,
641 sc->request_bufflen, xfer_cnt));
642
643 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) 682 if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)
644 mptscsih_copy_sense_data(sc, hd, mf, pScsiReply); 683 mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);
645 684
@@ -648,9 +687,10 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
648 */ 687 */
649 if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID && 688 if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID &&
650 pScsiReply->ResponseInfo) { 689 pScsiReply->ResponseInfo) {
651 printk(KERN_NOTICE "ha=%d id=%d lun=%d: " 690 printk(KERN_NOTICE "[%d:%d:%d:%d] "
652 "FCP_ResponseInfo=%08xh\n", 691 "FCP_ResponseInfo=%08xh\n",
653 ioc->id, sc->device->id, sc->device->lun, 692 sc->device->host->host_no, sc->device->channel,
693 sc->device->id, sc->device->lun,
654 le32_to_cpu(pScsiReply->ResponseInfo)); 694 le32_to_cpu(pScsiReply->ResponseInfo));
655 } 695 }
656 696
@@ -695,9 +735,8 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
695 if ( ioc->bus_type == SAS ) { 735 if ( ioc->bus_type == SAS ) {
696 u16 ioc_status = le16_to_cpu(pScsiReply->IOCStatus); 736 u16 ioc_status = le16_to_cpu(pScsiReply->IOCStatus);
697 if (ioc_status & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) { 737 if (ioc_status & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
698 u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo); 738 if ((log_info & SAS_LOGINFO_MASK)
699 log_info &=SAS_LOGINFO_MASK; 739 == SAS_LOGINFO_NEXUS_LOSS) {
700 if (log_info == SAS_LOGINFO_NEXUS_LOSS) {
701 sc->result = (DID_BUS_BUSY << 16); 740 sc->result = (DID_BUS_BUSY << 16);
702 break; 741 break;
703 } 742 }
@@ -735,7 +774,8 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
735 else /* Sufficient data transfer occurred */ 774 else /* Sufficient data transfer occurred */
736 sc->result = (DID_OK << 16) | scsi_status; 775 sc->result = (DID_OK << 16) | scsi_status;
737 dreplyprintk((KERN_NOTICE 776 dreplyprintk((KERN_NOTICE
738 "RESIDUAL_MISMATCH: result=%x on id=%d\n", sc->result, sc->device->id)); 777 "RESIDUAL_MISMATCH: result=%x on channel=%d id=%d\n",
778 sc->result, sc->device->channel, sc->device->id));
739 break; 779 break;
740 780
741 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */ 781 case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
@@ -848,7 +888,28 @@ mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
848 888
849 } /* switch(status) */ 889 } /* switch(status) */
850 890
851 dreplyprintk((KERN_NOTICE " sc->result is %08xh\n", sc->result)); 891#ifdef MPT_DEBUG_REPLY
892 if (sc->result) {
893
894 mptscsih_iocstatus_info_scsiio(ioc, status,
895 scsi_status, scsi_state, sc);
896
897 dreplyprintk(("%s: [%d:%d:%d:%d] cmd=0x%02x "
898 "result=0x%08x\n\tiocstatus=0x%04X "
899 "scsi_state=0x%02X scsi_status=0x%02X "
900 "loginfo=0x%08X\n", __FUNCTION__,
901 sc->device->host->host_no, sc->device->channel, sc->device->id,
902 sc->device->lun, sc->cmnd[0], sc->result, status,
903 scsi_state, scsi_status, log_info));
904
905 dreplyprintk(("%s: [%d:%d:%d:%d] resid=%d "
906 "bufflen=%d xfer_cnt=%d\n", __FUNCTION__,
907 sc->device->host->host_no, sc->device->channel, sc->device->id,
908 sc->device->lun, sc->resid, sc->request_bufflen,
909 xfer_cnt));
910 }
911#endif
912
852 } /* end of address reply case */ 913 } /* end of address reply case */
853 914
854 /* Unmap the DMA buffers, if any. */ 915 /* Unmap the DMA buffers, if any. */
@@ -955,9 +1016,10 @@ mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
955 int ii; 1016 int ii;
956 int max = hd->ioc->req_depth; 1017 int max = hd->ioc->req_depth;
957 struct scsi_cmnd *sc; 1018 struct scsi_cmnd *sc;
1019 struct scsi_lun lun;
958 1020
959 dsprintk((KERN_INFO MYNAM ": search_running target %d lun %d max %d\n", 1021 dsprintk((KERN_INFO MYNAM ": search_running channel %d id %d lun %d max %d\n",
960 vdevice->vtarget->target_id, vdevice->lun, max)); 1022 vdevice->vtarget->channel, vdevice->vtarget->id, vdevice->lun, max));
961 1023
962 for (ii=0; ii < max; ii++) { 1024 for (ii=0; ii < max; ii++) {
963 if ((sc = hd->ScsiLookup[ii]) != NULL) { 1025 if ((sc = hd->ScsiLookup[ii]) != NULL) {
@@ -965,10 +1027,14 @@ mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
965 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii); 1027 mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii);
966 if (mf == NULL) 1028 if (mf == NULL)
967 continue; 1029 continue;
968 dsprintk(( "search_running: found (sc=%p, mf = %p) target %d, lun %d \n", 1030 int_to_scsilun(vdevice->lun, &lun);
969 hd->ScsiLookup[ii], mf, mf->TargetID, mf->LUN[1])); 1031 if ((mf->Bus != vdevice->vtarget->channel) ||
970 if ((mf->TargetID != ((u8)vdevice->vtarget->target_id)) || (mf->LUN[1] != ((u8) vdevice->lun))) 1032 (mf->TargetID != vdevice->vtarget->id) ||
1033 memcmp(lun.scsi_lun, mf->LUN, 8))
971 continue; 1034 continue;
1035 dsprintk(( "search_running: found (sc=%p, mf = %p) "
1036 "channel %d id %d, lun %d \n", hd->ScsiLookup[ii],
1037 mf, mf->Bus, mf->TargetID, vdevice->lun));
972 1038
973 /* Cleanup 1039 /* Cleanup
974 */ 1040 */
@@ -1065,12 +1131,6 @@ mptscsih_remove(struct pci_dev *pdev)
1065 hd->ScsiLookup = NULL; 1131 hd->ScsiLookup = NULL;
1066 } 1132 }
1067 1133
1068 /*
1069 * Free pointer array.
1070 */
1071 kfree(hd->Targets);
1072 hd->Targets = NULL;
1073
1074 dprintk((MYIOC_s_INFO_FMT 1134 dprintk((MYIOC_s_INFO_FMT
1075 "Free'd ScsiLookup (%d) memory\n", 1135 "Free'd ScsiLookup (%d) memory\n",
1076 hd->ioc->name, sz1)); 1136 hd->ioc->name, sz1));
@@ -1317,14 +1377,6 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1317 return SCSI_MLQUEUE_HOST_BUSY; 1377 return SCSI_MLQUEUE_HOST_BUSY;
1318 } 1378 }
1319 1379
1320 if ((hd->ioc->bus_type == SPI) &&
1321 vdev->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT &&
1322 mptscsih_raid_id_to_num(hd, SCpnt->device->id) < 0) {
1323 SCpnt->result = DID_NO_CONNECT << 16;
1324 done(SCpnt);
1325 return 0;
1326 }
1327
1328 /* 1380 /*
1329 * Put together a MPT SCSI request... 1381 * Put together a MPT SCSI request...
1330 */ 1382 */
@@ -1368,8 +1420,8 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1368 1420
1369 /* Use the above information to set up the message frame 1421 /* Use the above information to set up the message frame
1370 */ 1422 */
1371 pScsiReq->TargetID = (u8) vdev->vtarget->target_id; 1423 pScsiReq->TargetID = (u8) vdev->vtarget->id;
1372 pScsiReq->Bus = vdev->vtarget->bus_id; 1424 pScsiReq->Bus = vdev->vtarget->channel;
1373 pScsiReq->ChainOffset = 0; 1425 pScsiReq->ChainOffset = 0;
1374 if (vdev->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT) 1426 if (vdev->vtarget->tflags & MPT_TARGET_FLAGS_RAID_COMPONENT)
1375 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; 1427 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
@@ -1379,14 +1431,7 @@ mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
1379 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE; 1431 pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
1380 pScsiReq->Reserved = 0; 1432 pScsiReq->Reserved = 0;
1381 pScsiReq->MsgFlags = mpt_msg_flags(); 1433 pScsiReq->MsgFlags = mpt_msg_flags();
1382 pScsiReq->LUN[0] = 0; 1434 int_to_scsilun(SCpnt->device->lun, (struct scsi_lun *)pScsiReq->LUN);
1383 pScsiReq->LUN[1] = lun;
1384 pScsiReq->LUN[2] = 0;
1385 pScsiReq->LUN[3] = 0;
1386 pScsiReq->LUN[4] = 0;
1387 pScsiReq->LUN[5] = 0;
1388 pScsiReq->LUN[6] = 0;
1389 pScsiReq->LUN[7] = 0;
1390 pScsiReq->Control = cpu_to_le32(scsictl); 1435 pScsiReq->Control = cpu_to_le32(scsictl);
1391 1436
1392 /* 1437 /*
@@ -1491,14 +1536,14 @@ mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
1491 */ 1536 */
1492 1537
1493/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1538/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1494/* 1539/**
1495 * mptscsih_TMHandler - Generic handler for SCSI Task Management. 1540 * mptscsih_TMHandler - Generic handler for SCSI Task Management.
1496 * Fall through to mpt_HardResetHandler if: not operational, too many 1541 * Fall through to mpt_HardResetHandler if: not operational, too many
1497 * failed TM requests or handshake failure. 1542 * failed TM requests or handshake failure.
1498 * 1543 *
1499 * @ioc: Pointer to MPT_ADAPTER structure 1544 * @ioc: Pointer to MPT_ADAPTER structure
1500 * @type: Task Management type 1545 * @type: Task Management type
1501 * @target: Logical Target ID for reset (if appropriate) 1546 * @id: Logical Target ID for reset (if appropriate)
1502 * @lun: Logical Unit for reset (if appropriate) 1547 * @lun: Logical Unit for reset (if appropriate)
1503 * @ctx2abort: Context for the task to be aborted (if appropriate) 1548 * @ctx2abort: Context for the task to be aborted (if appropriate)
1504 * 1549 *
@@ -1507,28 +1552,17 @@ mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
1507 * Remark: With old EH code, at most 1 SCSI TaskMgmt function per IOC 1552 * Remark: With old EH code, at most 1 SCSI TaskMgmt function per IOC
1508 * will be active. 1553 * will be active.
1509 * 1554 *
1510 * Returns 0 for SUCCESS or -1 if FAILED. 1555 * Returns 0 for SUCCESS, or FAILED.
1511 */ 1556 **/
1512int 1557int
1513mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout) 1558mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
1514{ 1559{
1515 MPT_ADAPTER *ioc; 1560 MPT_ADAPTER *ioc;
1516 int rc = -1; 1561 int rc = -1;
1517 int doTask = 1;
1518 u32 ioc_raw_state; 1562 u32 ioc_raw_state;
1519 unsigned long flags; 1563 unsigned long flags;
1520 1564
1521 /* If FW is being reloaded currently, return success to
1522 * the calling function.
1523 */
1524 if (hd == NULL)
1525 return 0;
1526
1527 ioc = hd->ioc; 1565 ioc = hd->ioc;
1528 if (ioc == NULL) {
1529 printk(KERN_ERR MYNAM " TMHandler" " NULL ioc!\n");
1530 return FAILED;
1531 }
1532 dtmprintk((MYIOC_s_INFO_FMT "TMHandler Entered!\n", ioc->name)); 1566 dtmprintk((MYIOC_s_INFO_FMT "TMHandler Entered!\n", ioc->name));
1533 1567
1534 // SJR - CHECKME - Can we avoid this here? 1568 // SJR - CHECKME - Can we avoid this here?
@@ -1541,8 +1575,10 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, in
1541 spin_unlock_irqrestore(&ioc->diagLock, flags); 1575 spin_unlock_irqrestore(&ioc->diagLock, flags);
1542 1576
1543 /* Wait a fixed amount of time for the TM pending flag to be cleared. 1577 /* Wait a fixed amount of time for the TM pending flag to be cleared.
1544 * If we time out and not bus reset, then we return a FAILED status to the caller. 1578 * If we time out and not bus reset, then we return a FAILED status
1545 * The call to mptscsih_tm_pending_wait() will set the pending flag if we are 1579 * to the caller.
1580 * The call to mptscsih_tm_pending_wait() will set the pending flag
1581 * if we are
1546 * successful. Otherwise, reload the FW. 1582 * successful. Otherwise, reload the FW.
1547 */ 1583 */
1548 if (mptscsih_tm_pending_wait(hd) == FAILED) { 1584 if (mptscsih_tm_pending_wait(hd) == FAILED) {
@@ -1552,18 +1588,16 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, in
1552 hd->ioc->name, hd->tmPending)); 1588 hd->ioc->name, hd->tmPending));
1553 return FAILED; 1589 return FAILED;
1554 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) { 1590 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) {
1555 dtmprintk((KERN_INFO MYNAM ": %s: TMHandler target reset: " 1591 dtmprintk((KERN_INFO MYNAM ": %s: TMHandler target "
1556 "Timed out waiting for last TM (%d) to complete! \n", 1592 "reset: Timed out waiting for last TM (%d) "
1557 hd->ioc->name, hd->tmPending)); 1593 "to complete! \n", hd->ioc->name,
1594 hd->tmPending));
1558 return FAILED; 1595 return FAILED;
1559 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) { 1596 } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
1560 dtmprintk((KERN_INFO MYNAM ": %s: TMHandler bus reset: " 1597 dtmprintk((KERN_INFO MYNAM ": %s: TMHandler bus reset: "
1561 "Timed out waiting for last TM (%d) to complete! \n", 1598 "Timed out waiting for last TM (%d) to complete! \n",
1562 hd->ioc->name, hd->tmPending)); 1599 hd->ioc->name, hd->tmPending));
1563 if (hd->tmPending & (1 << MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)) 1600 return FAILED;
1564 return FAILED;
1565
1566 doTask = 0;
1567 } 1601 }
1568 } else { 1602 } else {
1569 spin_lock_irqsave(&hd->ioc->FreeQlock, flags); 1603 spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
@@ -1571,47 +1605,40 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, in
1571 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags); 1605 spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
1572 } 1606 }
1573 1607
1574 /* Is operational?
1575 */
1576 ioc_raw_state = mpt_GetIocState(hd->ioc, 0); 1608 ioc_raw_state = mpt_GetIocState(hd->ioc, 0);
1577 1609
1578#ifdef MPT_DEBUG_RESET
1579 if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) { 1610 if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
1580 printk(MYIOC_s_WARN_FMT 1611 printk(MYIOC_s_WARN_FMT
1581 "TM Handler: IOC Not operational(0x%x)!\n", 1612 "TM Handler for type=%x: IOC Not operational (0x%x)!\n",
1582 hd->ioc->name, ioc_raw_state); 1613 ioc->name, type, ioc_raw_state);
1583 } 1614 printk(KERN_WARNING " Issuing HardReset!!\n");
1584#endif 1615 if (mpt_HardResetHandler(ioc, CAN_SLEEP) < 0)
1585 1616 printk((KERN_WARNING "TMHandler: HardReset "
1586 if (doTask && ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) 1617 "FAILED!!\n"));
1587 && !(ioc_raw_state & MPI_DOORBELL_ACTIVE)) { 1618 return FAILED;
1588
1589 /* Isse the Task Mgmt request.
1590 */
1591 if (hd->hard_resets < -1)
1592 hd->hard_resets++;
1593 rc = mptscsih_IssueTaskMgmt(hd, type, channel, target, lun, ctx2abort, timeout);
1594 if (rc) {
1595 printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n", hd->ioc->name);
1596 } else {
1597 dtmprintk((MYIOC_s_INFO_FMT "Issue of TaskMgmt Successful!\n", hd->ioc->name));
1598 }
1599 } 1619 }
1600 1620
1601 /* Only fall through to the HRH if this is a bus reset 1621 if (ioc_raw_state & MPI_DOORBELL_ACTIVE) {
1602 */ 1622 printk(MYIOC_s_WARN_FMT
1603 if ((type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) && (rc || 1623 "TM Handler for type=%x: ioc_state: "
1604 ioc->reload_fw || (ioc->alt_ioc && ioc->alt_ioc->reload_fw))) { 1624 "DOORBELL_ACTIVE (0x%x)!\n",
1605 dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n", 1625 ioc->name, type, ioc_raw_state);
1606 hd->ioc->name)); 1626 return FAILED;
1607 rc = mpt_HardResetHandler(hd->ioc, CAN_SLEEP);
1608 } 1627 }
1609 1628
1610 /* 1629 /* Isse the Task Mgmt request.
1611 * Check IOCStatus from TM reply message
1612 */ 1630 */
1613 if (hd->tm_iocstatus != MPI_IOCSTATUS_SUCCESS) 1631 if (hd->hard_resets < -1)
1614 rc = FAILED; 1632 hd->hard_resets++;
1633
1634 rc = mptscsih_IssueTaskMgmt(hd, type, channel, id, lun,
1635 ctx2abort, timeout);
1636 if (rc)
1637 printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n",
1638 hd->ioc->name);
1639 else
1640 dtmprintk((MYIOC_s_INFO_FMT "Issue of TaskMgmt Successful!\n",
1641 hd->ioc->name));
1615 1642
1616 dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc)); 1643 dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc));
1617 1644
@@ -1620,11 +1647,11 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, in
1620 1647
1621 1648
1622/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1649/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1623/* 1650/**
1624 * mptscsih_IssueTaskMgmt - Generic send Task Management function. 1651 * mptscsih_IssueTaskMgmt - Generic send Task Management function.
1625 * @hd: Pointer to MPT_SCSI_HOST structure 1652 * @hd: Pointer to MPT_SCSI_HOST structure
1626 * @type: Task Management type 1653 * @type: Task Management type
1627 * @target: Logical Target ID for reset (if appropriate) 1654 * @id: Logical Target ID for reset (if appropriate)
1628 * @lun: Logical Unit for reset (if appropriate) 1655 * @lun: Logical Unit for reset (if appropriate)
1629 * @ctx2abort: Context for the task to be aborted (if appropriate) 1656 * @ctx2abort: Context for the task to be aborted (if appropriate)
1630 * 1657 *
@@ -1633,11 +1660,11 @@ mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, in
1633 * 1660 *
1634 * Not all fields are meaningfull for all task types. 1661 * Not all fields are meaningfull for all task types.
1635 * 1662 *
1636 * Returns 0 for SUCCESS, -999 for "no msg frames", 1663 * Returns 0 for SUCCESS, or FAILED.
1637 * else other non-zero value returned. 1664 *
1638 */ 1665 **/
1639static int 1666static int
1640mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout) 1667mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout)
1641{ 1668{
1642 MPT_FRAME_HDR *mf; 1669 MPT_FRAME_HDR *mf;
1643 SCSITaskMgmt_t *pScsiTm; 1670 SCSITaskMgmt_t *pScsiTm;
@@ -1657,7 +1684,7 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun
1657 /* Format the Request 1684 /* Format the Request
1658 */ 1685 */
1659 pScsiTm = (SCSITaskMgmt_t *) mf; 1686 pScsiTm = (SCSITaskMgmt_t *) mf;
1660 pScsiTm->TargetID = target; 1687 pScsiTm->TargetID = id;
1661 pScsiTm->Bus = channel; 1688 pScsiTm->Bus = channel;
1662 pScsiTm->ChainOffset = 0; 1689 pScsiTm->ChainOffset = 0;
1663 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT; 1690 pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
@@ -1668,42 +1695,59 @@ mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun
1668 pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) 1695 pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
1669 ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0; 1696 ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
1670 1697
1671 for (ii= 0; ii < 8; ii++) { 1698 int_to_scsilun(lun, (struct scsi_lun *)pScsiTm->LUN);
1672 pScsiTm->LUN[ii] = 0;
1673 }
1674 pScsiTm->LUN[1] = lun;
1675 1699
1676 for (ii=0; ii < 7; ii++) 1700 for (ii=0; ii < 7; ii++)
1677 pScsiTm->Reserved2[ii] = 0; 1701 pScsiTm->Reserved2[ii] = 0;
1678 1702
1679 pScsiTm->TaskMsgContext = ctx2abort; 1703 pScsiTm->TaskMsgContext = ctx2abort;
1680 1704
1681 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt: ctx2abort (0x%08x) type=%d\n", 1705 dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt: ctx2abort (0x%08x) "
1682 hd->ioc->name, ctx2abort, type)); 1706 "type=%d\n", hd->ioc->name, ctx2abort, type));
1683 1707
1684 DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm); 1708 DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm);
1685 1709
1686 if ((retval = mpt_send_handshake_request(hd->ioc->TaskCtx, hd->ioc, 1710 if ((retval = mpt_send_handshake_request(hd->ioc->TaskCtx, hd->ioc,
1687 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, 1711 sizeof(SCSITaskMgmt_t), (u32*)pScsiTm, CAN_SLEEP)) != 0) {
1688 CAN_SLEEP)) != 0) { 1712 dfailprintk((MYIOC_s_ERR_FMT "send_handshake FAILED!"
1689 dfailprintk((MYIOC_s_ERR_FMT "_send_handshake FAILED!" 1713 " (hd %p, ioc %p, mf %p, rc=%d) \n", hd->ioc->name, hd,
1690 " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd, 1714 hd->ioc, mf, retval));
1691 hd->ioc, mf)); 1715 goto fail_out;
1692 mpt_free_msg_frame(hd->ioc, mf);
1693 return retval;
1694 } 1716 }
1695 1717
1696 if(mptscsih_tm_wait_for_completion(hd, timeout) == FAILED) { 1718 if(mptscsih_tm_wait_for_completion(hd, timeout) == FAILED) {
1697 dfailprintk((MYIOC_s_ERR_FMT "_wait_for_completion FAILED!" 1719 dfailprintk((MYIOC_s_ERR_FMT "task management request TIMED OUT!"
1698 " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd, 1720 " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
1699 hd->ioc, mf)); 1721 hd->ioc, mf));
1700 mpt_free_msg_frame(hd->ioc, mf);
1701 dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n", 1722 dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
1702 hd->ioc->name)); 1723 hd->ioc->name));
1703 retval = mpt_HardResetHandler(hd->ioc, CAN_SLEEP); 1724 retval = mpt_HardResetHandler(hd->ioc, CAN_SLEEP);
1725 dtmprintk((MYIOC_s_INFO_FMT "rc=%d \n",
1726 hd->ioc->name, retval));
1727 goto fail_out;
1704 } 1728 }
1705 1729
1730 /*
1731 * Handle success case, see if theres a non-zero ioc_status.
1732 */
1733 if (hd->tm_iocstatus == MPI_IOCSTATUS_SUCCESS ||
1734 hd->tm_iocstatus == MPI_IOCSTATUS_SCSI_TASK_TERMINATED ||
1735 hd->tm_iocstatus == MPI_IOCSTATUS_SCSI_IOC_TERMINATED)
1736 retval = 0;
1737 else
1738 retval = FAILED;
1739
1706 return retval; 1740 return retval;
1741
1742 fail_out:
1743
1744 /*
1745 * Free task managment mf, and corresponding tm flags
1746 */
1747 mpt_free_msg_frame(hd->ioc, mf);
1748 hd->tmPending = 0;
1749 hd->tmState = TM_STATE_NONE;
1750 return FAILED;
1707} 1751}
1708 1752
1709static int 1753static int
@@ -1728,7 +1772,7 @@ mptscsih_get_tm_timeout(MPT_ADAPTER *ioc)
1728 * (linux scsi_host_template.eh_abort_handler routine) 1772 * (linux scsi_host_template.eh_abort_handler routine)
1729 * 1773 *
1730 * Returns SUCCESS or FAILED. 1774 * Returns SUCCESS or FAILED.
1731 */ 1775 **/
1732int 1776int
1733mptscsih_abort(struct scsi_cmnd * SCpnt) 1777mptscsih_abort(struct scsi_cmnd * SCpnt)
1734{ 1778{
@@ -1764,9 +1808,8 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
1764 return SUCCESS; 1808 return SUCCESS;
1765 } 1809 }
1766 1810
1767 if (hd->resetPending) { 1811 if (hd->resetPending)
1768 return FAILED; 1812 return FAILED;
1769 }
1770 1813
1771 if (hd->timeouts < -1) 1814 if (hd->timeouts < -1)
1772 hd->timeouts++; 1815 hd->timeouts++;
@@ -1789,13 +1832,12 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
1789 1832
1790 vdev = SCpnt->device->hostdata; 1833 vdev = SCpnt->device->hostdata;
1791 retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK, 1834 retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
1792 vdev->vtarget->bus_id, vdev->vtarget->target_id, vdev->lun, 1835 vdev->vtarget->channel, vdev->vtarget->id, vdev->lun,
1793 ctx2abort, mptscsih_get_tm_timeout(hd->ioc)); 1836 ctx2abort, mptscsih_get_tm_timeout(hd->ioc));
1794 1837
1795 if (SCPNT_TO_LOOKUP_IDX(SCpnt) == scpnt_idx && 1838 if (SCPNT_TO_LOOKUP_IDX(SCpnt) == scpnt_idx &&
1796 SCpnt->serial_number == sn) { 1839 SCpnt->serial_number == sn)
1797 retval = FAILED; 1840 retval = FAILED;
1798 }
1799 1841
1800 printk (KERN_WARNING MYNAM ": %s: task abort: %s (sc=%p)\n", 1842 printk (KERN_WARNING MYNAM ": %s: task abort: %s (sc=%p)\n",
1801 hd->ioc->name, 1843 hd->ioc->name,
@@ -1803,12 +1845,8 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
1803 1845
1804 if (retval == 0) 1846 if (retval == 0)
1805 return SUCCESS; 1847 return SUCCESS;
1806 1848 else
1807 if(retval != FAILED ) { 1849 return FAILED;
1808 hd->tmPending = 0;
1809 hd->tmState = TM_STATE_NONE;
1810 }
1811 return FAILED;
1812} 1850}
1813 1851
1814/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1852/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -1819,7 +1857,7 @@ mptscsih_abort(struct scsi_cmnd * SCpnt)
1819 * (linux scsi_host_template.eh_dev_reset_handler routine) 1857 * (linux scsi_host_template.eh_dev_reset_handler routine)
1820 * 1858 *
1821 * Returns SUCCESS or FAILED. 1859 * Returns SUCCESS or FAILED.
1822 */ 1860 **/
1823int 1861int
1824mptscsih_dev_reset(struct scsi_cmnd * SCpnt) 1862mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
1825{ 1863{
@@ -1845,7 +1883,7 @@ mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
1845 1883
1846 vdev = SCpnt->device->hostdata; 1884 vdev = SCpnt->device->hostdata;
1847 retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 1885 retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
1848 vdev->vtarget->bus_id, vdev->vtarget->target_id, 1886 vdev->vtarget->channel, vdev->vtarget->id,
1849 0, 0, mptscsih_get_tm_timeout(hd->ioc)); 1887 0, 0, mptscsih_get_tm_timeout(hd->ioc));
1850 1888
1851 printk (KERN_WARNING MYNAM ": %s: target reset: %s (sc=%p)\n", 1889 printk (KERN_WARNING MYNAM ": %s: target reset: %s (sc=%p)\n",
@@ -1854,14 +1892,11 @@ mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
1854 1892
1855 if (retval == 0) 1893 if (retval == 0)
1856 return SUCCESS; 1894 return SUCCESS;
1857 1895 else
1858 if(retval != FAILED ) { 1896 return FAILED;
1859 hd->tmPending = 0;
1860 hd->tmState = TM_STATE_NONE;
1861 }
1862 return FAILED;
1863} 1897}
1864 1898
1899
1865/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1900/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
1866/** 1901/**
1867 * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant 1902 * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
@@ -1870,7 +1905,7 @@ mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
1870 * (linux scsi_host_template.eh_bus_reset_handler routine) 1905 * (linux scsi_host_template.eh_bus_reset_handler routine)
1871 * 1906 *
1872 * Returns SUCCESS or FAILED. 1907 * Returns SUCCESS or FAILED.
1873 */ 1908 **/
1874int 1909int
1875mptscsih_bus_reset(struct scsi_cmnd * SCpnt) 1910mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
1876{ 1911{
@@ -1896,7 +1931,7 @@ mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
1896 1931
1897 vdev = SCpnt->device->hostdata; 1932 vdev = SCpnt->device->hostdata;
1898 retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS, 1933 retval = mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
1899 vdev->vtarget->bus_id, 0, 0, 0, mptscsih_get_tm_timeout(hd->ioc)); 1934 vdev->vtarget->channel, 0, 0, 0, mptscsih_get_tm_timeout(hd->ioc));
1900 1935
1901 printk (KERN_WARNING MYNAM ": %s: bus reset: %s (sc=%p)\n", 1936 printk (KERN_WARNING MYNAM ": %s: bus reset: %s (sc=%p)\n",
1902 hd->ioc->name, 1937 hd->ioc->name,
@@ -1904,12 +1939,8 @@ mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
1904 1939
1905 if (retval == 0) 1940 if (retval == 0)
1906 return SUCCESS; 1941 return SUCCESS;
1907 1942 else
1908 if(retval != FAILED ) { 1943 return FAILED;
1909 hd->tmPending = 0;
1910 hd->tmState = TM_STATE_NONE;
1911 }
1912 return FAILED;
1913} 1944}
1914 1945
1915/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 1946/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -1992,7 +2023,6 @@ mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd)
1992/** 2023/**
1993 * mptscsih_tm_wait_for_completion - wait for completion of TM task 2024 * mptscsih_tm_wait_for_completion - wait for completion of TM task
1994 * @hd: Pointer to MPT host structure. 2025 * @hd: Pointer to MPT host structure.
1995 * @timeout: timeout in seconds
1996 * 2026 *
1997 * Returns {SUCCESS,FAILED}. 2027 * Returns {SUCCESS,FAILED}.
1998 */ 2028 */
@@ -2066,7 +2096,7 @@ mptscsih_taskmgmt_response_code(MPT_ADAPTER *ioc, u8 response_code)
2066 * load/init time via the mpt_register() API call. 2096 * load/init time via the mpt_register() API call.
2067 * 2097 *
2068 * Returns 1 indicating alloc'd request frame ptr should be freed. 2098 * Returns 1 indicating alloc'd request frame ptr should be freed.
2069 */ 2099 **/
2070int 2100int
2071mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) 2101mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
2072{ 2102{
@@ -2076,78 +2106,85 @@ mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *m
2076 unsigned long flags; 2106 unsigned long flags;
2077 u16 iocstatus; 2107 u16 iocstatus;
2078 u8 tmType; 2108 u8 tmType;
2109 u32 termination_count;
2079 2110
2080 dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt completed (mf=%p,mr=%p)\n", 2111 dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt completed (mf=%p,mr=%p)\n",
2081 ioc->name, mf, mr)); 2112 ioc->name, mf, mr));
2082 if (ioc->sh) { 2113 if (!ioc->sh) {
2083 /* Depending on the thread, a timer is activated for 2114 dtmprintk((MYIOC_s_WARN_FMT
2084 * the TM request. Delete this timer on completion of TM. 2115 "TaskMgmt Complete: NULL Scsi Host Ptr\n", ioc->name));
2085 * Decrement count of outstanding TM requests.
2086 */
2087 hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
2088 } else {
2089 dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt Complete: NULL Scsi Host Ptr\n",
2090 ioc->name));
2091 return 1; 2116 return 1;
2092 } 2117 }
2093 2118
2094 if (mr == NULL) { 2119 if (mr == NULL) {
2095 dtmprintk((MYIOC_s_WARN_FMT "ERROR! TaskMgmt Reply: NULL Request %p\n", 2120 dtmprintk((MYIOC_s_WARN_FMT
2096 ioc->name, mf)); 2121 "ERROR! TaskMgmt Reply: NULL Request %p\n", ioc->name, mf));
2097 return 1; 2122 return 1;
2098 } else { 2123 }
2099 pScsiTmReply = (SCSITaskMgmtReply_t*)mr;
2100 pScsiTmReq = (SCSITaskMgmt_t*)mf;
2101
2102 /* Figure out if this was ABORT_TASK, TARGET_RESET, or BUS_RESET! */
2103 tmType = pScsiTmReq->TaskType;
2104 2124
2105 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 && 2125 hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
2106 pScsiTmReply->ResponseCode) 2126 pScsiTmReply = (SCSITaskMgmtReply_t*)mr;
2107 mptscsih_taskmgmt_response_code(ioc, 2127 pScsiTmReq = (SCSITaskMgmt_t*)mf;
2108 pScsiTmReply->ResponseCode); 2128 tmType = pScsiTmReq->TaskType;
2129 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
2130 termination_count = le32_to_cpu(pScsiTmReply->TerminationCount);
2131
2132 if (ioc->facts.MsgVersion >= MPI_VERSION_01_05 &&
2133 pScsiTmReply->ResponseCode)
2134 mptscsih_taskmgmt_response_code(ioc,
2135 pScsiTmReply->ResponseCode);
2136 DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply);
2137
2138#if defined(MPT_DEBUG_REPLY) || defined(MPT_DEBUG_TM)
2139 printk("%s: ha=%d [%d:%d:0] task_type=0x%02X "
2140 "iocstatus=0x%04X\n\tloginfo=0x%08X response_code=0x%02X "
2141 "term_cmnds=%d\n", __FUNCTION__, ioc->id, pScsiTmReply->Bus,
2142 pScsiTmReply->TargetID, pScsiTmReq->TaskType,
2143 le16_to_cpu(pScsiTmReply->IOCStatus),
2144 le32_to_cpu(pScsiTmReply->IOCLogInfo),pScsiTmReply->ResponseCode,
2145 le32_to_cpu(pScsiTmReply->TerminationCount));
2146#endif
2147 if (!iocstatus) {
2148 dtmprintk((MYIOC_s_WARN_FMT " TaskMgmt SUCCESS\n", ioc->name));
2149 hd->abortSCpnt = NULL;
2150 goto out;
2151 }
2109 2152
2110 dtmprintk((MYIOC_s_WARN_FMT " TaskType = %d, TerminationCount=%d\n", 2153 /* Error? (anything non-zero?) */
2111 ioc->name, tmType, le32_to_cpu(pScsiTmReply->TerminationCount)));
2112 DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply);
2113 2154
2114 iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK; 2155 /* clear flags and continue.
2115 hd->tm_iocstatus = iocstatus; 2156 */
2116 dtmprintk((MYIOC_s_WARN_FMT " SCSI TaskMgmt (%d) IOCStatus=%04x IOCLogInfo=%08x\n", 2157 switch (tmType) {
2117 ioc->name, tmType, iocstatus, le32_to_cpu(pScsiTmReply->IOCLogInfo)));
2118 /* Error? (anything non-zero?) */
2119 if (iocstatus) {
2120 2158
2121 /* clear flags and continue. 2159 case MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
2122 */ 2160 if (termination_count == 1)
2123 if (tmType == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) 2161 iocstatus = MPI_IOCSTATUS_SCSI_TASK_TERMINATED;
2124 hd->abortSCpnt = NULL; 2162 hd->abortSCpnt = NULL;
2163 break;
2125 2164
2126 /* If an internal command is present 2165 case MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS:
2127 * or the TM failed - reload the FW.
2128 * FC FW may respond FAILED to an ABORT
2129 */
2130 if (tmType == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
2131 if ((hd->cmdPtr) ||
2132 (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED)) {
2133 if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0) {
2134 printk((KERN_WARNING
2135 " Firmware Reload FAILED!!\n"));
2136 }
2137 }
2138 }
2139 } else {
2140 dtmprintk((MYIOC_s_WARN_FMT " TaskMgmt SUCCESS\n", ioc->name));
2141 2166
2142 hd->abortSCpnt = NULL; 2167 /* If an internal command is present
2168 * or the TM failed - reload the FW.
2169 * FC FW may respond FAILED to an ABORT
2170 */
2171 if (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED ||
2172 hd->cmdPtr)
2173 if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
2174 printk((KERN_WARNING " Firmware Reload FAILED!!\n"));
2175 break;
2143 2176
2144 } 2177 case MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
2178 default:
2179 break;
2145 } 2180 }
2146 2181
2182 out:
2147 spin_lock_irqsave(&ioc->FreeQlock, flags); 2183 spin_lock_irqsave(&ioc->FreeQlock, flags);
2148 hd->tmPending = 0; 2184 hd->tmPending = 0;
2149 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2150 hd->tmState = TM_STATE_NONE; 2185 hd->tmState = TM_STATE_NONE;
2186 hd->tm_iocstatus = iocstatus;
2187 spin_unlock_irqrestore(&ioc->FreeQlock, flags);
2151 2188
2152 return 1; 2189 return 1;
2153} 2190}
@@ -2191,7 +2228,7 @@ mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
2191 2228
2192 dprintk((KERN_NOTICE 2229 dprintk((KERN_NOTICE
2193 ": bios_param: Id=%i Lun=%i Channel=%i CHS=%i/%i/%i\n", 2230 ": bios_param: Id=%i Lun=%i Channel=%i CHS=%i/%i/%i\n",
2194 sdev->id, sdev->lun,sdev->channel,(int)cylinders,heads,sectors)); 2231 sdev->id, sdev->lun, sdev->channel, (int)cylinders, heads, sectors));
2195 2232
2196 return 0; 2233 return 0;
2197} 2234}
@@ -2200,115 +2237,78 @@ mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
2200 * 2237 *
2201 */ 2238 */
2202int 2239int
2203mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id) 2240mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id)
2204{ 2241{
2242 struct inactive_raid_component_info *component_info;
2205 int i; 2243 int i;
2244 int rc = 0;
2206 2245
2207 if (!ioc->raid_data.isRaid || !ioc->raid_data.pIocPg3) 2246 if (!ioc->raid_data.pIocPg3)
2208 return 0; 2247 goto out;
2209 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) { 2248 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2210 if (id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) 2249 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2211 return 1; 2250 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2212 } 2251 rc = 1;
2213 return 0; 2252 goto out;
2214} 2253 }
2215EXPORT_SYMBOL(mptscsih_is_phys_disk);
2216
2217int
2218mptscsih_raid_id_to_num(MPT_SCSI_HOST *hd, uint physdiskid)
2219{
2220 int i;
2221
2222 if (!hd->ioc->raid_data.isRaid || !hd->ioc->raid_data.pIocPg3)
2223 return -ENXIO;
2224
2225 for (i = 0; i < hd->ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2226 if (physdiskid ==
2227 hd->ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID)
2228 return hd->ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
2229 } 2254 }
2230 2255
2231 return -ENXIO; 2256 /*
2232} 2257 * Check inactive list for matching phys disks
2233EXPORT_SYMBOL(mptscsih_raid_id_to_num); 2258 */
2259 if (list_empty(&ioc->raid_data.inactive_list))
2260 goto out;
2234 2261
2235/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2262 down(&ioc->raid_data.inactive_list_mutex);
2236/* 2263 list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
2237 * OS entry point to allow host driver to alloc memory 2264 list) {
2238 * for each scsi target. Called once per device the bus scan. 2265 if ((component_info->d.PhysDiskID == id) &&
2239 * Return non-zero if allocation fails. 2266 (component_info->d.PhysDiskBus == channel))
2240 */ 2267 rc = 1;
2241int 2268 }
2242mptscsih_target_alloc(struct scsi_target *starget) 2269 up(&ioc->raid_data.inactive_list_mutex);
2243{
2244 VirtTarget *vtarget;
2245 2270
2246 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL); 2271 out:
2247 if (!vtarget) 2272 return rc;
2248 return -ENOMEM;
2249 starget->hostdata = vtarget;
2250 vtarget->starget = starget;
2251 return 0;
2252} 2273}
2274EXPORT_SYMBOL(mptscsih_is_phys_disk);
2253 2275
2254/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2276u8
2255/* 2277mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id)
2256 * OS entry point to allow host driver to alloc memory
2257 * for each scsi device. Called once per device the bus scan.
2258 * Return non-zero if allocation fails.
2259 */
2260int
2261mptscsih_slave_alloc(struct scsi_device *sdev)
2262{ 2278{
2263 struct Scsi_Host *host = sdev->host; 2279 struct inactive_raid_component_info *component_info;
2264 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata; 2280 int i;
2265 VirtTarget *vtarget; 2281 int rc = -ENXIO;
2266 VirtDevice *vdev;
2267 struct scsi_target *starget;
2268 2282
2269 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL); 2283 if (!ioc->raid_data.pIocPg3)
2270 if (!vdev) { 2284 goto out;
2271 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n", 2285 for (i = 0; i < ioc->raid_data.pIocPg3->NumPhysDisks; i++) {
2272 hd->ioc->name, sizeof(VirtDevice)); 2286 if ((id == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskID) &&
2273 return -ENOMEM; 2287 (channel == ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskBus)) {
2288 rc = ioc->raid_data.pIocPg3->PhysDisk[i].PhysDiskNum;
2289 goto out;
2290 }
2274 } 2291 }
2275 2292
2276 vdev->lun = sdev->lun; 2293 /*
2277 sdev->hostdata = vdev; 2294 * Check inactive list for matching phys disks
2278 2295 */
2279 starget = scsi_target(sdev); 2296 if (list_empty(&ioc->raid_data.inactive_list))
2280 vtarget = starget->hostdata; 2297 goto out;
2281 2298
2282 vdev->vtarget = vtarget; 2299 down(&ioc->raid_data.inactive_list_mutex);
2283 2300 list_for_each_entry(component_info, &ioc->raid_data.inactive_list,
2284 if (vtarget->num_luns == 0) { 2301 list) {
2285 hd->Targets[sdev->id] = vtarget; 2302 if ((component_info->d.PhysDiskID == id) &&
2286 vtarget->ioc_id = hd->ioc->id; 2303 (component_info->d.PhysDiskBus == channel))
2287 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES; 2304 rc = component_info->d.PhysDiskNum;
2288 vtarget->target_id = sdev->id;
2289 vtarget->bus_id = sdev->channel;
2290 if (hd->ioc->bus_type == SPI && sdev->channel == 0 &&
2291 hd->ioc->raid_data.isRaid & (1 << sdev->id)) {
2292 vtarget->raidVolume = 1;
2293 ddvtprintk((KERN_INFO
2294 "RAID Volume @ id %d\n", sdev->id));
2295 }
2296 } 2305 }
2297 vtarget->num_luns++; 2306 up(&ioc->raid_data.inactive_list_mutex);
2298 return 0;
2299}
2300 2307
2301/* 2308 out:
2302 * OS entry point to allow for host driver to free allocated memory 2309 return rc;
2303 * Called if no device present or device being unloaded
2304 */
2305void
2306mptscsih_target_destroy(struct scsi_target *starget)
2307{
2308 if (starget->hostdata)
2309 kfree(starget->hostdata);
2310 starget->hostdata = NULL;
2311} 2310}
2311EXPORT_SYMBOL(mptscsih_raid_id_to_num);
2312 2312
2313/* 2313/*
2314 * OS entry point to allow for host driver to free allocated memory 2314 * OS entry point to allow for host driver to free allocated memory
@@ -2328,11 +2328,7 @@ mptscsih_slave_destroy(struct scsi_device *sdev)
2328 vdevice = sdev->hostdata; 2328 vdevice = sdev->hostdata;
2329 2329
2330 mptscsih_search_running_cmds(hd, vdevice); 2330 mptscsih_search_running_cmds(hd, vdevice);
2331 vtarget->luns[0] &= ~(1 << vdevice->lun);
2332 vtarget->num_luns--; 2331 vtarget->num_luns--;
2333 if (vtarget->num_luns == 0) {
2334 hd->Targets[sdev->id] = NULL;
2335 }
2336 mptscsih_synchronize_cache(hd, vdevice); 2332 mptscsih_synchronize_cache(hd, vdevice);
2337 kfree(vdevice); 2333 kfree(vdevice);
2338 sdev->hostdata = NULL; 2334 sdev->hostdata = NULL;
@@ -2394,15 +2390,14 @@ mptscsih_slave_configure(struct scsi_device *sdev)
2394 VirtDevice *vdevice; 2390 VirtDevice *vdevice;
2395 struct scsi_target *starget; 2391 struct scsi_target *starget;
2396 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sh->hostdata; 2392 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sh->hostdata;
2397 int indexed_lun, lun_index;
2398 2393
2399 starget = scsi_target(sdev); 2394 starget = scsi_target(sdev);
2400 vtarget = starget->hostdata; 2395 vtarget = starget->hostdata;
2401 vdevice = sdev->hostdata; 2396 vdevice = sdev->hostdata;
2402 2397
2403 dsprintk((MYIOC_s_INFO_FMT 2398 dsprintk((MYIOC_s_INFO_FMT
2404 "device @ %p, id=%d, LUN=%d, channel=%d\n", 2399 "device @ %p, channel=%d, id=%d, lun=%d\n",
2405 hd->ioc->name, sdev, sdev->id, sdev->lun, sdev->channel)); 2400 hd->ioc->name, sdev, sdev->channel, sdev->id, sdev->lun));
2406 if (hd->ioc->bus_type == SPI) 2401 if (hd->ioc->bus_type == SPI)
2407 dsprintk((MYIOC_s_INFO_FMT 2402 dsprintk((MYIOC_s_INFO_FMT
2408 "sdtr %d wdtr %d ppr %d inq length=%d\n", 2403 "sdtr %d wdtr %d ppr %d inq length=%d\n",
@@ -2415,11 +2410,7 @@ mptscsih_slave_configure(struct scsi_device *sdev)
2415 goto slave_configure_exit; 2410 goto slave_configure_exit;
2416 } 2411 }
2417 2412
2418 vdevice->configured_lun=1; 2413 vdevice->configured_lun = 1;
2419 lun_index = (vdevice->lun >> 5); /* 32 luns per lun_index */
2420 indexed_lun = (vdevice->lun % 32);
2421 vtarget->luns[lun_index] |= (1 << indexed_lun);
2422 mptscsih_initTarget(hd, vtarget, sdev);
2423 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH); 2414 mptscsih_change_queue_depth(sdev, MPT_SCSI_CMD_PER_DEV_HIGH);
2424 2415
2425 dsprintk((MYIOC_s_INFO_FMT 2416 dsprintk((MYIOC_s_INFO_FMT
@@ -2683,285 +2674,6 @@ mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
2683 2674
2684/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 2675/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2685/* 2676/*
2686 * mptscsih_initTarget - Target, LUN alloc/free functionality.
2687 * @hd: Pointer to MPT_SCSI_HOST structure
2688 * @vtarget: per target private data
2689 * @sdev: SCSI device
2690 *
2691 * NOTE: It's only SAFE to call this routine if data points to
2692 * sane & valid STANDARD INQUIRY data!
2693 *
2694 * Allocate and initialize memory for this target.
2695 * Save inquiry data.
2696 *
2697 */
2698static void
2699mptscsih_initTarget(MPT_SCSI_HOST *hd, VirtTarget *vtarget,
2700 struct scsi_device *sdev)
2701{
2702 dinitprintk((MYIOC_s_INFO_FMT "initTarget bus=%d id=%d lun=%d hd=%p\n",
2703 hd->ioc->name, vtarget->bus_id, vtarget->target_id,
2704 sdev->lun, hd));
2705
2706 /* Is LUN supported? If so, upper 2 bits will be 0
2707 * in first byte of inquiry data.
2708 */
2709 if (sdev->inq_periph_qual != 0)
2710 return;
2711
2712 if (vtarget == NULL)
2713 return;
2714
2715 vtarget->type = sdev->type;
2716
2717 if (hd->ioc->bus_type != SPI)
2718 return;
2719
2720 if ((sdev->type == TYPE_PROCESSOR) && (hd->ioc->spi_data.Saf_Te)) {
2721 /* Treat all Processors as SAF-TE if
2722 * command line option is set */
2723 vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
2724 mptscsih_writeIOCPage4(hd, vtarget->target_id, vtarget->bus_id);
2725 }else if ((sdev->type == TYPE_PROCESSOR) &&
2726 !(vtarget->tflags & MPT_TARGET_FLAGS_SAF_TE_ISSUED )) {
2727 if (sdev->inquiry_len > 49 ) {
2728 if (sdev->inquiry[44] == 'S' &&
2729 sdev->inquiry[45] == 'A' &&
2730 sdev->inquiry[46] == 'F' &&
2731 sdev->inquiry[47] == '-' &&
2732 sdev->inquiry[48] == 'T' &&
2733 sdev->inquiry[49] == 'E' ) {
2734 vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
2735 mptscsih_writeIOCPage4(hd, vtarget->target_id, vtarget->bus_id);
2736 }
2737 }
2738 }
2739 mptscsih_setTargetNegoParms(hd, vtarget, sdev);
2740}
2741
2742/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2743/*
2744 * Update the target negotiation parameters based on the
2745 * the Inquiry data, adapter capabilities, and NVRAM settings.
2746 *
2747 */
2748static void
2749mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target,
2750 struct scsi_device *sdev)
2751{
2752 SpiCfgData *pspi_data = &hd->ioc->spi_data;
2753 int id = (int) target->target_id;
2754 int nvram;
2755 u8 width = MPT_NARROW;
2756 u8 factor = MPT_ASYNC;
2757 u8 offset = 0;
2758 u8 nfactor;
2759 u8 noQas = 1;
2760
2761 target->negoFlags = pspi_data->noQas;
2762
2763 /* noQas == 0 => device supports QAS. */
2764
2765 if (sdev->scsi_level < SCSI_2) {
2766 width = 0;
2767 factor = MPT_ULTRA2;
2768 offset = pspi_data->maxSyncOffset;
2769 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
2770 } else {
2771 if (scsi_device_wide(sdev)) {
2772 width = 1;
2773 }
2774
2775 if (scsi_device_sync(sdev)) {
2776 factor = pspi_data->minSyncFactor;
2777 if (!scsi_device_dt(sdev))
2778 factor = MPT_ULTRA2;
2779 else {
2780 if (!scsi_device_ius(sdev) &&
2781 !scsi_device_qas(sdev))
2782 factor = MPT_ULTRA160;
2783 else {
2784 factor = MPT_ULTRA320;
2785 if (scsi_device_qas(sdev)) {
2786 ddvtprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", scsi_device_qas(sdev), id));
2787 noQas = 0;
2788 }
2789 if (sdev->type == TYPE_TAPE &&
2790 scsi_device_ius(sdev))
2791 target->negoFlags |= MPT_TAPE_NEGO_IDP;
2792 }
2793 }
2794 offset = pspi_data->maxSyncOffset;
2795
2796 /* If RAID, never disable QAS
2797 * else if non RAID, do not disable
2798 * QAS if bit 1 is set
2799 * bit 1 QAS support, non-raid only
2800 * bit 0 IU support
2801 */
2802 if (target->raidVolume == 1) {
2803 noQas = 0;
2804 }
2805 } else {
2806 factor = MPT_ASYNC;
2807 offset = 0;
2808 }
2809 }
2810
2811 if (!sdev->tagged_supported) {
2812 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
2813 }
2814
2815 /* Update tflags based on NVRAM settings. (SCSI only)
2816 */
2817 if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
2818 nvram = pspi_data->nvram[id];
2819 nfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
2820
2821 if (width)
2822 width = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
2823
2824 if (offset > 0) {
2825 /* Ensure factor is set to the
2826 * maximum of: adapter, nvram, inquiry
2827 */
2828 if (nfactor) {
2829 if (nfactor < pspi_data->minSyncFactor )
2830 nfactor = pspi_data->minSyncFactor;
2831
2832 factor = max(factor, nfactor);
2833 if (factor == MPT_ASYNC)
2834 offset = 0;
2835 } else {
2836 offset = 0;
2837 factor = MPT_ASYNC;
2838 }
2839 } else {
2840 factor = MPT_ASYNC;
2841 }
2842 }
2843
2844 /* Make sure data is consistent
2845 */
2846 if ((!width) && (factor < MPT_ULTRA2)) {
2847 factor = MPT_ULTRA2;
2848 }
2849
2850 /* Save the data to the target structure.
2851 */
2852 target->minSyncFactor = factor;
2853 target->maxOffset = offset;
2854 target->maxWidth = width;
2855
2856 target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO;
2857
2858 /* Disable unused features.
2859 */
2860 if (!width)
2861 target->negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
2862
2863 if (!offset)
2864 target->negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
2865
2866 if ( factor > MPT_ULTRA320 )
2867 noQas = 0;
2868
2869 if (noQas && (pspi_data->noQas == 0)) {
2870 pspi_data->noQas |= MPT_TARGET_NO_NEGO_QAS;
2871 target->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
2872
2873 /* Disable QAS in a mixed configuration case
2874 */
2875
2876 ddvtprintk((KERN_INFO "Disabling QAS due to noQas=%02x on id=%d!\n", noQas, id));
2877 }
2878}
2879
2880/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2881
2882/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2883/*
2884 * SCSI Config Page functionality ...
2885 */
2886
2887/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2888/* mptscsih_writeIOCPage4 - write IOC Page 4
2889 * @hd: Pointer to a SCSI Host Structure
2890 * @target_id: write IOC Page4 for this ID & Bus
2891 *
2892 * Return: -EAGAIN if unable to obtain a Message Frame
2893 * or 0 if success.
2894 *
2895 * Remark: We do not wait for a return, write pages sequentially.
2896 */
2897static int
2898mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus)
2899{
2900 MPT_ADAPTER *ioc = hd->ioc;
2901 Config_t *pReq;
2902 IOCPage4_t *IOCPage4Ptr;
2903 MPT_FRAME_HDR *mf;
2904 dma_addr_t dataDma;
2905 u16 req_idx;
2906 u32 frameOffset;
2907 u32 flagsLength;
2908 int ii;
2909
2910 /* Get a MF for this command.
2911 */
2912 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
2913 dfailprintk((MYIOC_s_WARN_FMT "writeIOCPage4 : no msg frames!\n",
2914 ioc->name));
2915 return -EAGAIN;
2916 }
2917
2918 /* Set the request and the data pointers.
2919 * Place data at end of MF.
2920 */
2921 pReq = (Config_t *)mf;
2922
2923 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
2924 frameOffset = ioc->req_sz - sizeof(IOCPage4_t);
2925
2926 /* Complete the request frame (same for all requests).
2927 */
2928 pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
2929 pReq->Reserved = 0;
2930 pReq->ChainOffset = 0;
2931 pReq->Function = MPI_FUNCTION_CONFIG;
2932 pReq->ExtPageLength = 0;
2933 pReq->ExtPageType = 0;
2934 pReq->MsgFlags = 0;
2935 for (ii=0; ii < 8; ii++) {
2936 pReq->Reserved2[ii] = 0;
2937 }
2938
2939 IOCPage4Ptr = ioc->spi_data.pIocPg4;
2940 dataDma = ioc->spi_data.IocPg4_dma;
2941 ii = IOCPage4Ptr->ActiveSEP++;
2942 IOCPage4Ptr->SEP[ii].SEPTargetID = target_id;
2943 IOCPage4Ptr->SEP[ii].SEPBus = bus;
2944 pReq->Header = IOCPage4Ptr->Header;
2945 pReq->PageAddress = cpu_to_le32(target_id | (bus << 8 ));
2946
2947 /* Add a SGE to the config request.
2948 */
2949 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE |
2950 (IOCPage4Ptr->Header.PageLength + ii) * 4;
2951
2952 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
2953
2954 dinitprintk((MYIOC_s_INFO_FMT
2955 "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n",
2956 ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, target_id, bus));
2957
2958 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
2959
2960 return 0;
2961}
2962
2963/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
2964/*
2965 * Bus Scan and Domain Validation functionality ... 2677 * Bus Scan and Domain Validation functionality ...
2966 */ 2678 */
2967 2679
@@ -3343,7 +3055,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
3343 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH; 3055 pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
3344 } else { 3056 } else {
3345 pScsiReq->TargetID = io->id; 3057 pScsiReq->TargetID = io->id;
3346 pScsiReq->Bus = io->bus; 3058 pScsiReq->Bus = io->channel;
3347 pScsiReq->ChainOffset = 0; 3059 pScsiReq->ChainOffset = 0;
3348 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST; 3060 pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
3349 } 3061 }
@@ -3356,9 +3068,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
3356 pScsiReq->MsgFlags = mpt_msg_flags(); 3068 pScsiReq->MsgFlags = mpt_msg_flags();
3357 /* MsgContext set in mpt_get_msg_fram call */ 3069 /* MsgContext set in mpt_get_msg_fram call */
3358 3070
3359 for (ii=0; ii < 8; ii++) 3071 int_to_scsilun(io->lun, (struct scsi_lun *)pScsiReq->LUN);
3360 pScsiReq->LUN[ii] = 0;
3361 pScsiReq->LUN[1] = io->lun;
3362 3072
3363 if (io->flags & MPT_ICFLAG_TAGGED_CMD) 3073 if (io->flags & MPT_ICFLAG_TAGGED_CMD)
3364 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ); 3074 pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
@@ -3379,7 +3089,7 @@ mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
3379 + (my_idx * MPT_SENSE_BUFFER_ALLOC)); 3089 + (my_idx * MPT_SENSE_BUFFER_ALLOC));
3380 3090
3381 ddvprintk((MYIOC_s_INFO_FMT "Sending Command 0x%x for (%d:%d:%d)\n", 3091 ddvprintk((MYIOC_s_INFO_FMT "Sending Command 0x%x for (%d:%d:%d)\n",
3382 hd->ioc->name, cmd, io->bus, io->id, io->lun)); 3092 hd->ioc->name, cmd, io->channel, io->id, io->lun));
3383 3093
3384 if (dir == MPI_SCSIIO_CONTROL_READ) { 3094 if (dir == MPI_SCSIIO_CONTROL_READ) {
3385 mpt_add_sge((char *) &pScsiReq->SGL, 3095 mpt_add_sge((char *) &pScsiReq->SGL,
@@ -3462,9 +3172,9 @@ mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, VirtDevice *vdevice)
3462 iocmd.data_dma = -1; 3172 iocmd.data_dma = -1;
3463 iocmd.size = 0; 3173 iocmd.size = 0;
3464 iocmd.rsvd = iocmd.rsvd2 = 0; 3174 iocmd.rsvd = iocmd.rsvd2 = 0;
3465 iocmd.bus = vdevice->vtarget->bus_id; 3175 iocmd.channel = vdevice->vtarget->channel;
3466 iocmd.id = vdevice->vtarget->target_id; 3176 iocmd.id = vdevice->vtarget->id;
3467 iocmd.lun = (u8)vdevice->lun; 3177 iocmd.lun = vdevice->lun;
3468 3178
3469 if ((vdevice->vtarget->type == TYPE_DISK) && 3179 if ((vdevice->vtarget->type == TYPE_DISK) &&
3470 (vdevice->configured_lun)) 3180 (vdevice->configured_lun))
@@ -3480,9 +3190,6 @@ EXPORT_SYMBOL(mptscsih_resume);
3480EXPORT_SYMBOL(mptscsih_proc_info); 3190EXPORT_SYMBOL(mptscsih_proc_info);
3481EXPORT_SYMBOL(mptscsih_info); 3191EXPORT_SYMBOL(mptscsih_info);
3482EXPORT_SYMBOL(mptscsih_qcmd); 3192EXPORT_SYMBOL(mptscsih_qcmd);
3483EXPORT_SYMBOL(mptscsih_target_alloc);
3484EXPORT_SYMBOL(mptscsih_slave_alloc);
3485EXPORT_SYMBOL(mptscsih_target_destroy);
3486EXPORT_SYMBOL(mptscsih_slave_destroy); 3193EXPORT_SYMBOL(mptscsih_slave_destroy);
3487EXPORT_SYMBOL(mptscsih_slave_configure); 3194EXPORT_SYMBOL(mptscsih_slave_configure);
3488EXPORT_SYMBOL(mptscsih_abort); 3195EXPORT_SYMBOL(mptscsih_abort);
diff --git a/drivers/message/fusion/mptscsih.h b/drivers/message/fusion/mptscsih.h
index 187c8af0890..843c01a6aa0 100644
--- a/drivers/message/fusion/mptscsih.h
+++ b/drivers/message/fusion/mptscsih.h
@@ -6,7 +6,7 @@
6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 6 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
7 * 7 *
8 * Copyright (c) 1999-2007 LSI Logic Corporation 8 * Copyright (c) 1999-2007 LSI Logic Corporation
9 * (mailto:mpt_linux_developer@lsil.com) 9 * (mailto:mpt_linux_developer@lsi.com)
10 * 10 *
11 */ 11 */
12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 12/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -53,6 +53,24 @@
53 * SCSI Public stuff... 53 * SCSI Public stuff...
54 */ 54 */
55 55
56#define MPT_SCANDV_GOOD (0x00000000) /* must be 0 */
57#define MPT_SCANDV_DID_RESET (0x00000001)
58#define MPT_SCANDV_SENSE (0x00000002)
59#define MPT_SCANDV_SOME_ERROR (0x00000004)
60#define MPT_SCANDV_SELECTION_TIMEOUT (0x00000008)
61#define MPT_SCANDV_ISSUE_SENSE (0x00000010)
62#define MPT_SCANDV_FALLBACK (0x00000020)
63
64#define MPT_SCANDV_MAX_RETRIES (10)
65
66#define MPT_ICFLAG_BUF_CAP 0x01 /* ReadBuffer Read Capacity format */
67#define MPT_ICFLAG_ECHO 0x02 /* ReadBuffer Echo buffer format */
68#define MPT_ICFLAG_EBOS 0x04 /* ReadBuffer Echo buffer has EBOS */
69#define MPT_ICFLAG_PHYS_DISK 0x08 /* Any SCSI IO but do Phys Disk Format */
70#define MPT_ICFLAG_TAGGED_CMD 0x10 /* Do tagged IO */
71#define MPT_ICFLAG_DID_RESET 0x20 /* Bus Reset occurred with this command */
72#define MPT_ICFLAG_RESERVED 0x40 /* Reserved has been issued */
73
56#define MPT_SCSI_CMD_PER_DEV_HIGH 64 74#define MPT_SCSI_CMD_PER_DEV_HIGH 64
57#define MPT_SCSI_CMD_PER_DEV_LOW 32 75#define MPT_SCSI_CMD_PER_DEV_LOW 32
58 76
@@ -69,9 +87,22 @@
69#define MPTSCSIH_SAF_TE 0 87#define MPTSCSIH_SAF_TE 0
70#define MPTSCSIH_PT_CLEAR 0 88#define MPTSCSIH_PT_CLEAR 0
71 89
72
73#endif 90#endif
74 91
92typedef struct _internal_cmd {
93 char *data; /* data pointer */
94 dma_addr_t data_dma; /* data dma address */
95 int size; /* transfer size */
96 u8 cmd; /* SCSI Op Code */
97 u8 channel; /* bus number */
98 u8 id; /* SCSI ID (virtual) */
99 int lun;
100 u8 flags; /* Bit Field - See above */
101 u8 physDiskNum; /* Phys disk number, -1 else */
102 u8 rsvd2;
103 u8 rsvd;
104} INTERNAL_CMD;
105
75extern void mptscsih_remove(struct pci_dev *); 106extern void mptscsih_remove(struct pci_dev *);
76extern void mptscsih_shutdown(struct pci_dev *); 107extern void mptscsih_shutdown(struct pci_dev *);
77#ifdef CONFIG_PM 108#ifdef CONFIG_PM
@@ -81,9 +112,6 @@ extern int mptscsih_resume(struct pci_dev *pdev);
81extern int mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int func); 112extern int mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset, int length, int func);
82extern const char * mptscsih_info(struct Scsi_Host *SChost); 113extern const char * mptscsih_info(struct Scsi_Host *SChost);
83extern int mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *)); 114extern int mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *));
84extern int mptscsih_target_alloc(struct scsi_target *starget);
85extern int mptscsih_slave_alloc(struct scsi_device *device);
86extern void mptscsih_target_destroy(struct scsi_target *starget);
87extern void mptscsih_slave_destroy(struct scsi_device *device); 115extern void mptscsih_slave_destroy(struct scsi_device *device);
88extern int mptscsih_slave_configure(struct scsi_device *device); 116extern int mptscsih_slave_configure(struct scsi_device *device);
89extern int mptscsih_abort(struct scsi_cmnd * SCpnt); 117extern int mptscsih_abort(struct scsi_cmnd * SCpnt);
@@ -98,6 +126,6 @@ extern int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pE
98extern int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset); 126extern int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
99extern int mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth); 127extern int mptscsih_change_queue_depth(struct scsi_device *sdev, int qdepth);
100extern void mptscsih_timer_expired(unsigned long data); 128extern void mptscsih_timer_expired(unsigned long data);
101extern int mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout); 129extern int mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 id, int lun, int ctx2abort, ulong timeout);
102extern int mptscsih_raid_id_to_num(MPT_SCSI_HOST *hd, uint physdiskid); 130extern u8 mptscsih_raid_id_to_num(MPT_ADAPTER *ioc, u8 channel, u8 id);
103extern int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id); 131extern int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, u8 channel, u8 id);
diff --git a/drivers/message/fusion/mptspi.c b/drivers/message/fusion/mptspi.c
index 203c661d2c7..c31a9e3c8a2 100644
--- a/drivers/message/fusion/mptspi.c
+++ b/drivers/message/fusion/mptspi.c
@@ -4,7 +4,7 @@
4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware. 4 * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
5 * 5 *
6 * Copyright (c) 1999-2007 LSI Logic Corporation 6 * Copyright (c) 1999-2007 LSI Logic Corporation
7 * (mailto:mpt_linux_developer@lsil.com) 7 * (mailto:mpt_linux_developer@lsi.com)
8 * 8 *
9 */ 9 */
10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/ 10/*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
@@ -65,6 +65,7 @@
65#include <scsi/scsi_tcq.h> 65#include <scsi/scsi_tcq.h>
66#include <scsi/scsi_transport.h> 66#include <scsi/scsi_transport.h>
67#include <scsi/scsi_transport_spi.h> 67#include <scsi/scsi_transport_spi.h>
68#include <scsi/scsi_dbg.h>
68 69
69#include "mptbase.h" 70#include "mptbase.h"
70#include "mptscsih.h" 71#include "mptscsih.h"
@@ -95,25 +96,339 @@ static int mptspiDoneCtx = -1;
95static int mptspiTaskCtx = -1; 96static int mptspiTaskCtx = -1;
96static int mptspiInternalCtx = -1; /* Used only for internal commands */ 97static int mptspiInternalCtx = -1; /* Used only for internal commands */
97 98
99/**
100 * mptspi_setTargetNegoParms - Update the target negotiation
101 * parameters based on the the Inquiry data, adapter capabilities,
102 * and NVRAM settings
103 *
104 * @hd: Pointer to a SCSI Host Structure
105 * @vtarget: per target private data
106 * @sdev: SCSI device
107 *
108 **/
109static void
110mptspi_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtTarget *target,
111 struct scsi_device *sdev)
112{
113 SpiCfgData *pspi_data = &hd->ioc->spi_data;
114 int id = (int) target->id;
115 int nvram;
116 u8 width = MPT_NARROW;
117 u8 factor = MPT_ASYNC;
118 u8 offset = 0;
119 u8 nfactor;
120 u8 noQas = 1;
121
122 target->negoFlags = pspi_data->noQas;
123
124 if (sdev->scsi_level < SCSI_2) {
125 width = 0;
126 factor = MPT_ULTRA2;
127 offset = pspi_data->maxSyncOffset;
128 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
129 } else {
130 if (scsi_device_wide(sdev))
131 width = 1;
132
133 if (scsi_device_sync(sdev)) {
134 factor = pspi_data->minSyncFactor;
135 if (!scsi_device_dt(sdev))
136 factor = MPT_ULTRA2;
137 else {
138 if (!scsi_device_ius(sdev) &&
139 !scsi_device_qas(sdev))
140 factor = MPT_ULTRA160;
141 else {
142 factor = MPT_ULTRA320;
143 if (scsi_device_qas(sdev)) {
144 ddvprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", scsi_device_qas(sdev), id));
145 noQas = 0;
146 }
147 if (sdev->type == TYPE_TAPE &&
148 scsi_device_ius(sdev))
149 target->negoFlags |= MPT_TAPE_NEGO_IDP;
150 }
151 }
152 offset = pspi_data->maxSyncOffset;
153
154 /* If RAID, never disable QAS
155 * else if non RAID, do not disable
156 * QAS if bit 1 is set
157 * bit 1 QAS support, non-raid only
158 * bit 0 IU support
159 */
160 if (target->raidVolume == 1)
161 noQas = 0;
162 } else {
163 factor = MPT_ASYNC;
164 offset = 0;
165 }
166 }
167
168 if (!sdev->tagged_supported)
169 target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
170
171 /* Update tflags based on NVRAM settings. (SCSI only)
172 */
173 if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
174 nvram = pspi_data->nvram[id];
175 nfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
176
177 if (width)
178 width = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
179
180 if (offset > 0) {
181 /* Ensure factor is set to the
182 * maximum of: adapter, nvram, inquiry
183 */
184 if (nfactor) {
185 if (nfactor < pspi_data->minSyncFactor )
186 nfactor = pspi_data->minSyncFactor;
187
188 factor = max(factor, nfactor);
189 if (factor == MPT_ASYNC)
190 offset = 0;
191 } else {
192 offset = 0;
193 factor = MPT_ASYNC;
194 }
195 } else {
196 factor = MPT_ASYNC;
197 }
198 }
199
200 /* Make sure data is consistent
201 */
202 if ((!width) && (factor < MPT_ULTRA2))
203 factor = MPT_ULTRA2;
204
205 /* Save the data to the target structure.
206 */
207 target->minSyncFactor = factor;
208 target->maxOffset = offset;
209 target->maxWidth = width;
210
211 target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO;
212
213 /* Disable unused features.
214 */
215 if (!width)
216 target->negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
217
218 if (!offset)
219 target->negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
220
221 if ( factor > MPT_ULTRA320 )
222 noQas = 0;
223
224 if (noQas && (pspi_data->noQas == 0)) {
225 pspi_data->noQas |= MPT_TARGET_NO_NEGO_QAS;
226 target->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
227
228 /* Disable QAS in a mixed configuration case
229 */
230
231 ddvprintk((KERN_INFO "Disabling QAS due to noQas=%02x on id=%d!\n", noQas, id));
232 }
233}
234
235/**
236 * mptspi_writeIOCPage4 - write IOC Page 4
237 * @hd: Pointer to a SCSI Host Structure
238 * @channel:
239 * @id: write IOC Page4 for this ID & Bus
240 *
241 * Return: -EAGAIN if unable to obtain a Message Frame
242 * or 0 if success.
243 *
244 * Remark: We do not wait for a return, write pages sequentially.
245 **/
246static int
247mptspi_writeIOCPage4(MPT_SCSI_HOST *hd, u8 channel , u8 id)
248{
249 MPT_ADAPTER *ioc = hd->ioc;
250 Config_t *pReq;
251 IOCPage4_t *IOCPage4Ptr;
252 MPT_FRAME_HDR *mf;
253 dma_addr_t dataDma;
254 u16 req_idx;
255 u32 frameOffset;
256 u32 flagsLength;
257 int ii;
258
259 /* Get a MF for this command.
260 */
261 if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
262 dfailprintk((MYIOC_s_WARN_FMT "writeIOCPage4 : no msg frames!\n",
263 ioc->name));
264 return -EAGAIN;
265 }
266
267 /* Set the request and the data pointers.
268 * Place data at end of MF.
269 */
270 pReq = (Config_t *)mf;
271
272 req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
273 frameOffset = ioc->req_sz - sizeof(IOCPage4_t);
274
275 /* Complete the request frame (same for all requests).
276 */
277 pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
278 pReq->Reserved = 0;
279 pReq->ChainOffset = 0;
280 pReq->Function = MPI_FUNCTION_CONFIG;
281 pReq->ExtPageLength = 0;
282 pReq->ExtPageType = 0;
283 pReq->MsgFlags = 0;
284 for (ii=0; ii < 8; ii++) {
285 pReq->Reserved2[ii] = 0;
286 }
287
288 IOCPage4Ptr = ioc->spi_data.pIocPg4;
289 dataDma = ioc->spi_data.IocPg4_dma;
290 ii = IOCPage4Ptr->ActiveSEP++;
291 IOCPage4Ptr->SEP[ii].SEPTargetID = id;
292 IOCPage4Ptr->SEP[ii].SEPBus = channel;
293 pReq->Header = IOCPage4Ptr->Header;
294 pReq->PageAddress = cpu_to_le32(id | (channel << 8 ));
295
296 /* Add a SGE to the config request.
297 */
298 flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE |
299 (IOCPage4Ptr->Header.PageLength + ii) * 4;
300
301 mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
302
303 ddvprintk((MYIOC_s_INFO_FMT
304 "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n",
305 ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, id, channel));
306
307 mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
308
309 return 0;
310}
311
312/**
313 * mptspi_initTarget - Target, LUN alloc/free functionality.
314 * @hd: Pointer to MPT_SCSI_HOST structure
315 * @vtarget: per target private data
316 * @sdev: SCSI device
317 *
318 * NOTE: It's only SAFE to call this routine if data points to
319 * sane & valid STANDARD INQUIRY data!
320 *
321 * Allocate and initialize memory for this target.
322 * Save inquiry data.
323 *
324 **/
325static void
326mptspi_initTarget(MPT_SCSI_HOST *hd, VirtTarget *vtarget,
327 struct scsi_device *sdev)
328{
329
330 /* Is LUN supported? If so, upper 2 bits will be 0
331 * in first byte of inquiry data.
332 */
333 if (sdev->inq_periph_qual != 0)
334 return;
335
336 if (vtarget == NULL)
337 return;
338
339 vtarget->type = sdev->type;
340
341 if ((sdev->type == TYPE_PROCESSOR) && (hd->ioc->spi_data.Saf_Te)) {
342 /* Treat all Processors as SAF-TE if
343 * command line option is set */
344 vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
345 mptspi_writeIOCPage4(hd, vtarget->channel, vtarget->id);
346 }else if ((sdev->type == TYPE_PROCESSOR) &&
347 !(vtarget->tflags & MPT_TARGET_FLAGS_SAF_TE_ISSUED )) {
348 if (sdev->inquiry_len > 49 ) {
349 if (sdev->inquiry[44] == 'S' &&
350 sdev->inquiry[45] == 'A' &&
351 sdev->inquiry[46] == 'F' &&
352 sdev->inquiry[47] == '-' &&
353 sdev->inquiry[48] == 'T' &&
354 sdev->inquiry[49] == 'E' ) {
355 vtarget->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
356 mptspi_writeIOCPage4(hd, vtarget->channel, vtarget->id);
357 }
358 }
359 }
360 mptspi_setTargetNegoParms(hd, vtarget, sdev);
361}
362
363/**
364 * mptspi_is_raid - Determines whether target is belonging to volume
365 * @hd: Pointer to a SCSI HOST structure
366 * @id: target device id
367 *
368 * Return:
369 * non-zero = true
370 * zero = false
371 *
372 */
373static int
374mptspi_is_raid(struct _MPT_SCSI_HOST *hd, u32 id)
375{
376 int i, rc = 0;
377
378 if (!hd->ioc->raid_data.pIocPg2)
379 goto out;
380
381 if (!hd->ioc->raid_data.pIocPg2->NumActiveVolumes)
382 goto out;
383 for (i=0; i < hd->ioc->raid_data.pIocPg2->NumActiveVolumes; i++) {
384 if (hd->ioc->raid_data.pIocPg2->RaidVolume[i].VolumeID == id) {
385 rc = 1;
386 goto out;
387 }
388 }
389
390 out:
391 return rc;
392}
393
98static int mptspi_target_alloc(struct scsi_target *starget) 394static int mptspi_target_alloc(struct scsi_target *starget)
99{ 395{
100 struct Scsi_Host *shost = dev_to_shost(&starget->dev); 396 struct Scsi_Host *shost = dev_to_shost(&starget->dev);
101 struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata; 397 struct _MPT_SCSI_HOST *hd = (struct _MPT_SCSI_HOST *)shost->hostdata;
102 int ret; 398 VirtTarget *vtarget;
103 399
104 if (hd == NULL) 400 if (hd == NULL)
105 return -ENODEV; 401 return -ENODEV;
106 402
107 ret = mptscsih_target_alloc(starget); 403 vtarget = kzalloc(sizeof(VirtTarget), GFP_KERNEL);
108 if (ret) 404 if (!vtarget)
109 return ret; 405 return -ENOMEM;
406
407 vtarget->ioc_id = hd->ioc->id;
408 vtarget->tflags = MPT_TARGET_FLAGS_Q_YES;
409 vtarget->id = (u8)starget->id;
410 vtarget->channel = (u8)starget->channel;
411 vtarget->starget = starget;
412 starget->hostdata = vtarget;
413
414 if (starget->channel == 1) {
415 if (mptscsih_is_phys_disk(hd->ioc, 0, starget->id) == 0)
416 return 0;
417 vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
418 /* The real channel for this device is zero */
419 vtarget->channel = 0;
420 /* The actual physdisknum (for RAID passthrough) */
421 vtarget->id = mptscsih_raid_id_to_num(hd->ioc, 0,
422 starget->id);
423 }
110 424
111 /* if we're a device on virtual channel 1 and we're not part 425 if (starget->channel == 0 &&
112 * of an array, just return here (otherwise the setup below 426 mptspi_is_raid(hd, starget->id)) {
113 * may actually affect a real physical device on channel 0 */ 427 vtarget->raidVolume = 1;
114 if (starget->channel == 1 && 428 ddvprintk((KERN_INFO
115 mptscsih_raid_id_to_num(hd, starget->id) < 0) 429 "RAID Volume @ channel=%d id=%d\n", starget->channel,
116 return 0; 430 starget->id));
431 }
117 432
118 if (hd->ioc->spi_data.nvram && 433 if (hd->ioc->spi_data.nvram &&
119 hd->ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) { 434 hd->ioc->spi_data.nvram[starget->id] != MPT_HOST_NVRAM_INVALID) {
@@ -132,6 +447,64 @@ static int mptspi_target_alloc(struct scsi_target *starget)
132 return 0; 447 return 0;
133} 448}
134 449
450void
451mptspi_target_destroy(struct scsi_target *starget)
452{
453 if (starget->hostdata)
454 kfree(starget->hostdata);
455 starget->hostdata = NULL;
456}
457
458/**
459 * mptspi_print_write_nego - negotiation parameters debug info that is being sent
460 * @hd: Pointer to a SCSI HOST structure
461 * @starget: SCSI target
462 * @ii: negotiation parameters
463 *
464 */
465static void
466mptspi_print_write_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
467{
468 ddvprintk((MYIOC_s_INFO_FMT "id=%d Requested = 0x%08x"
469 " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
470 hd->ioc->name, starget->id, ii,
471 ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
472 ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF),
473 ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "",
474 ii & MPI_SCSIDEVPAGE0_NP_DT ? "DT ": "",
475 ii & MPI_SCSIDEVPAGE0_NP_QAS ? "QAS ": "",
476 ii & MPI_SCSIDEVPAGE0_NP_HOLD_MCS ? "HOLDMCS ": "",
477 ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "",
478 ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "",
479 ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "",
480 ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": ""));
481}
482
483/**
484 * mptspi_print_read_nego - negotiation parameters debug info that is being read
485 * @hd: Pointer to a SCSI HOST structure
486 * @starget: SCSI target
487 * @ii: negotiation parameters
488 *
489 */
490static void
491mptspi_print_read_nego(struct _MPT_SCSI_HOST *hd, struct scsi_target *starget, u32 ii)
492{
493 ddvprintk((MYIOC_s_INFO_FMT "id=%d Read = 0x%08x"
494 " ( %s factor = 0x%02x @ offset = 0x%02x %s%s%s%s%s%s%s%s)\n",
495 hd->ioc->name, starget->id, ii,
496 ii & MPI_SCSIDEVPAGE0_NP_WIDE ? "Wide ": "",
497 ((ii >> 8) & 0xFF), ((ii >> 16) & 0xFF),
498 ii & MPI_SCSIDEVPAGE0_NP_IU ? "IU ": "",
499 ii & MPI_SCSIDEVPAGE0_NP_DT ? "DT ": "",
500 ii & MPI_SCSIDEVPAGE0_NP_QAS ? "QAS ": "",
501 ii & MPI_SCSIDEVPAGE0_NP_HOLD_MCS ? "HOLDMCS ": "",
502 ii & MPI_SCSIDEVPAGE0_NP_WR_FLOW ? "WRFLOW ": "",
503 ii & MPI_SCSIDEVPAGE0_NP_RD_STRM ? "RDSTRM ": "",
504 ii & MPI_SCSIDEVPAGE0_NP_RTI ? "RTI ": "",
505 ii & MPI_SCSIDEVPAGE0_NP_PCOMP_EN ? "PCOMP ": ""));
506}
507
135static int mptspi_read_spi_device_pg0(struct scsi_target *starget, 508static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
136 struct _CONFIG_PAGE_SCSI_DEVICE_0 *pass_pg0) 509 struct _CONFIG_PAGE_SCSI_DEVICE_0 *pass_pg0)
137{ 510{
@@ -147,7 +520,7 @@ static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
147 520
148 /* No SPI parameters for RAID devices */ 521 /* No SPI parameters for RAID devices */
149 if (starget->channel == 0 && 522 if (starget->channel == 0 &&
150 (hd->ioc->raid_data.isRaid & (1 << starget->id))) 523 mptspi_is_raid(hd, starget->id))
151 return -1; 524 return -1;
152 525
153 size = ioc->spi_data.sdp0length * 4; 526 size = ioc->spi_data.sdp0length * 4;
@@ -185,6 +558,8 @@ static int mptspi_read_spi_device_pg0(struct scsi_target *starget,
185 err = 0; 558 err = 0;
186 memcpy(pass_pg0, pg0, size); 559 memcpy(pass_pg0, pg0, size);
187 560
561 mptspi_print_read_nego(hd, starget, le32_to_cpu(pg0->NegotiatedParameters));
562
188 out_free: 563 out_free:
189 dma_free_coherent(&ioc->pcidev->dev, size, pg0, pg0_dma); 564 dma_free_coherent(&ioc->pcidev->dev, size, pg0, pg0_dma);
190 return err; 565 return err;
@@ -233,7 +608,7 @@ static void mptspi_read_parameters(struct scsi_target *starget)
233} 608}
234 609
235static int 610static int
236mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, int disk) 611mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, u8 channel, u8 id)
237{ 612{
238 MpiRaidActionRequest_t *pReq; 613 MpiRaidActionRequest_t *pReq;
239 MPT_FRAME_HDR *mf; 614 MPT_FRAME_HDR *mf;
@@ -253,8 +628,8 @@ mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, int disk)
253 pReq->Reserved1 = 0; 628 pReq->Reserved1 = 0;
254 pReq->ChainOffset = 0; 629 pReq->ChainOffset = 0;
255 pReq->Function = MPI_FUNCTION_RAID_ACTION; 630 pReq->Function = MPI_FUNCTION_RAID_ACTION;
256 pReq->VolumeID = disk; 631 pReq->VolumeID = id;
257 pReq->VolumeBus = 0; 632 pReq->VolumeBus = channel;
258 pReq->PhysDiskNum = 0; 633 pReq->PhysDiskNum = 0;
259 pReq->MsgFlags = 0; 634 pReq->MsgFlags = 0;
260 pReq->Reserved2 = 0; 635 pReq->Reserved2 = 0;
@@ -263,8 +638,8 @@ mptscsih_quiesce_raid(MPT_SCSI_HOST *hd, int quiesce, int disk)
263 mpt_add_sge((char *)&pReq->ActionDataSGE, 638 mpt_add_sge((char *)&pReq->ActionDataSGE,
264 MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1); 639 MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
265 640
266 ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action %x id %d\n", 641 ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action=%x channel=%d id=%d\n",
267 hd->ioc->name, action, io->id)); 642 hd->ioc->name, pReq->Action, channel, id));
268 643
269 hd->pLocal = NULL; 644 hd->pLocal = NULL;
270 hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */ 645 hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */
@@ -292,12 +667,12 @@ static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
292 667
293 /* no DV on RAID devices */ 668 /* no DV on RAID devices */
294 if (sdev->channel == 0 && 669 if (sdev->channel == 0 &&
295 (hd->ioc->raid_data.isRaid & (1 << sdev->id))) 670 mptspi_is_raid(hd, sdev->id))
296 return; 671 return;
297 672
298 /* If this is a piece of a RAID, then quiesce first */ 673 /* If this is a piece of a RAID, then quiesce first */
299 if (sdev->channel == 1 && 674 if (sdev->channel == 1 &&
300 mptscsih_quiesce_raid(hd, 1, vtarget->target_id) < 0) { 675 mptscsih_quiesce_raid(hd, 1, vtarget->channel, vtarget->id) < 0) {
301 starget_printk(KERN_ERR, scsi_target(sdev), 676 starget_printk(KERN_ERR, scsi_target(sdev),
302 "Integrated RAID quiesce failed\n"); 677 "Integrated RAID quiesce failed\n");
303 return; 678 return;
@@ -306,7 +681,7 @@ static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
306 spi_dv_device(sdev); 681 spi_dv_device(sdev);
307 682
308 if (sdev->channel == 1 && 683 if (sdev->channel == 1 &&
309 mptscsih_quiesce_raid(hd, 0, vtarget->target_id) < 0) 684 mptscsih_quiesce_raid(hd, 0, vtarget->channel, vtarget->id) < 0)
310 starget_printk(KERN_ERR, scsi_target(sdev), 685 starget_printk(KERN_ERR, scsi_target(sdev),
311 "Integrated RAID resume failed\n"); 686 "Integrated RAID resume failed\n");
312 687
@@ -317,54 +692,89 @@ static void mptspi_dv_device(struct _MPT_SCSI_HOST *hd,
317 692
318static int mptspi_slave_alloc(struct scsi_device *sdev) 693static int mptspi_slave_alloc(struct scsi_device *sdev)
319{ 694{
320 int ret;
321 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sdev->host->hostdata; 695 MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sdev->host->hostdata;
322 /* gcc doesn't see that all uses of this variable occur within 696 VirtTarget *vtarget;
323 * the if() statements, so stop it from whining */ 697 VirtDevice *vdev;
324 int physdisknum = 0; 698 struct scsi_target *starget;
325
326 if (sdev->channel == 1) {
327 physdisknum = mptscsih_raid_id_to_num(hd, sdev->id);
328 699
329 if (physdisknum < 0) 700 if (sdev->channel == 1 &&
330 return physdisknum; 701 mptscsih_is_phys_disk(hd->ioc, 0, sdev->id) == 0)
702 return -ENXIO;
703
704 vdev = kzalloc(sizeof(VirtDevice), GFP_KERNEL);
705 if (!vdev) {
706 printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
707 hd->ioc->name, sizeof(VirtDevice));
708 return -ENOMEM;
331 } 709 }
332 710
333 ret = mptscsih_slave_alloc(sdev); 711 vdev->lun = sdev->lun;
712 sdev->hostdata = vdev;
334 713
335 if (ret) 714 starget = scsi_target(sdev);
336 return ret; 715 vtarget = starget->hostdata;
716 vdev->vtarget = vtarget;
717 vtarget->num_luns++;
337 718
338 if (sdev->channel == 1) { 719 if (sdev->channel == 1)
339 VirtDevice *vdev = sdev->hostdata;
340 sdev->no_uld_attach = 1; 720 sdev->no_uld_attach = 1;
341 vdev->vtarget->tflags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
342 /* The real channel for this device is zero */
343 vdev->vtarget->bus_id = 0;
344 /* The actual physdisknum (for RAID passthrough) */
345 vdev->vtarget->target_id = physdisknum;
346 }
347 721
348 return 0; 722 return 0;
349} 723}
350 724
351static int mptspi_slave_configure(struct scsi_device *sdev) 725static int mptspi_slave_configure(struct scsi_device *sdev)
352{ 726{
353 int ret = mptscsih_slave_configure(sdev);
354 struct _MPT_SCSI_HOST *hd = 727 struct _MPT_SCSI_HOST *hd =
355 (struct _MPT_SCSI_HOST *)sdev->host->hostdata; 728 (struct _MPT_SCSI_HOST *)sdev->host->hostdata;
729 VirtTarget *vtarget = scsi_target(sdev)->hostdata;
730 int ret = mptscsih_slave_configure(sdev);
356 731
357 if (ret) 732 if (ret)
358 return ret; 733 return ret;
359 734
735 mptspi_initTarget(hd, vtarget, sdev);
736
737 ddvprintk((MYIOC_s_INFO_FMT "id=%d min_period=0x%02x"
738 " max_offset=0x%02x max_width=%d\n", hd->ioc->name,
739 sdev->id, spi_min_period(scsi_target(sdev)),
740 spi_max_offset(scsi_target(sdev)),
741 spi_max_width(scsi_target(sdev))));
742
360 if ((sdev->channel == 1 || 743 if ((sdev->channel == 1 ||
361 !(hd->ioc->raid_data.isRaid & (1 << sdev->id))) && 744 !(mptspi_is_raid(hd, sdev->id))) &&
362 !spi_initial_dv(sdev->sdev_target)) 745 !spi_initial_dv(sdev->sdev_target))
363 mptspi_dv_device(hd, sdev); 746 mptspi_dv_device(hd, sdev);
364 747
365 return 0; 748 return 0;
366} 749}
367 750
751static int
752mptspi_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
753{
754 struct _MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata;
755 VirtDevice *vdev = SCpnt->device->hostdata;
756
757 if (!vdev || !vdev->vtarget) {
758 SCpnt->result = DID_NO_CONNECT << 16;
759 done(SCpnt);
760 return 0;
761 }
762
763 if (SCpnt->device->channel == 1 &&
764 mptscsih_is_phys_disk(hd->ioc, 0, SCpnt->device->id) == 0) {
765 SCpnt->result = DID_NO_CONNECT << 16;
766 done(SCpnt);
767 return 0;
768 }
769
770#ifdef MPT_DEBUG_DV
771 if (spi_dv_pending(scsi_target(SCpnt->device)))
772 scsi_print_command(SCpnt);
773#endif
774
775 return mptscsih_qcmd(SCpnt,done);
776}
777
368static void mptspi_slave_destroy(struct scsi_device *sdev) 778static void mptspi_slave_destroy(struct scsi_device *sdev)
369{ 779{
370 struct scsi_target *starget = scsi_target(sdev); 780 struct scsi_target *starget = scsi_target(sdev);
@@ -392,11 +802,11 @@ static struct scsi_host_template mptspi_driver_template = {
392 .proc_info = mptscsih_proc_info, 802 .proc_info = mptscsih_proc_info,
393 .name = "MPT SPI Host", 803 .name = "MPT SPI Host",
394 .info = mptscsih_info, 804 .info = mptscsih_info,
395 .queuecommand = mptscsih_qcmd, 805 .queuecommand = mptspi_qcmd,
396 .target_alloc = mptspi_target_alloc, 806 .target_alloc = mptspi_target_alloc,
397 .slave_alloc = mptspi_slave_alloc, 807 .slave_alloc = mptspi_slave_alloc,
398 .slave_configure = mptspi_slave_configure, 808 .slave_configure = mptspi_slave_configure,
399 .target_destroy = mptscsih_target_destroy, 809 .target_destroy = mptspi_target_destroy,
400 .slave_destroy = mptspi_slave_destroy, 810 .slave_destroy = mptspi_slave_destroy,
401 .change_queue_depth = mptscsih_change_queue_depth, 811 .change_queue_depth = mptscsih_change_queue_depth,
402 .eh_abort_handler = mptscsih_abort, 812 .eh_abort_handler = mptscsih_abort,
@@ -427,7 +837,7 @@ static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
427 837
428 /* don't allow updating nego parameters on RAID devices */ 838 /* don't allow updating nego parameters on RAID devices */
429 if (starget->channel == 0 && 839 if (starget->channel == 0 &&
430 (hd->ioc->raid_data.isRaid & (1 << starget->id))) 840 mptspi_is_raid(hd, starget->id))
431 return -1; 841 return -1;
432 842
433 size = ioc->spi_data.sdp1length * 4; 843 size = ioc->spi_data.sdp1length * 4;
@@ -460,6 +870,8 @@ static int mptspi_write_spi_device_pg1(struct scsi_target *starget,
460 pg1->Header.PageNumber = hdr.PageNumber; 870 pg1->Header.PageNumber = hdr.PageNumber;
461 pg1->Header.PageType = hdr.PageType; 871 pg1->Header.PageType = hdr.PageType;
462 872
873 mptspi_print_write_nego(hd, starget, le32_to_cpu(pg1->RequestedParameters));
874
463 if (mpt_config(ioc, &cfg)) { 875 if (mpt_config(ioc, &cfg)) {
464 starget_printk(KERN_ERR, starget, "mpt_config failed\n"); 876 starget_printk(KERN_ERR, starget, "mpt_config failed\n");
465 goto out_free; 877 goto out_free;
@@ -672,9 +1084,9 @@ static void mpt_work_wrapper(struct work_struct *work)
672 if (sdev->channel != 1) 1084 if (sdev->channel != 1)
673 continue; 1085 continue;
674 1086
675 /* The target_id is the raid PhysDiskNum, even if 1087 /* The id is the raid PhysDiskNum, even if
676 * starget->id is the actual target address */ 1088 * starget->id is the actual target address */
677 if(vtarget->target_id != disk) 1089 if(vtarget->id != disk)
678 continue; 1090 continue;
679 1091
680 starget_printk(KERN_INFO, vtarget->starget, 1092 starget_printk(KERN_INFO, vtarget->starget,
@@ -727,7 +1139,7 @@ mptspi_deny_binding(struct scsi_target *starget)
727{ 1139{
728 struct _MPT_SCSI_HOST *hd = 1140 struct _MPT_SCSI_HOST *hd =
729 (struct _MPT_SCSI_HOST *)dev_to_shost(starget->dev.parent)->hostdata; 1141 (struct _MPT_SCSI_HOST *)dev_to_shost(starget->dev.parent)->hostdata;
730 return ((hd->ioc->raid_data.isRaid & (1 << starget->id)) && 1142 return ((mptspi_is_raid(hd, starget->id)) &&
731 starget->channel == 0) ? 1 : 0; 1143 starget->channel == 0) ? 1 : 0;
732} 1144}
733 1145
@@ -945,14 +1357,13 @@ mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
945 * max_lun = 1 + actual last lun, 1357 * max_lun = 1 + actual last lun,
946 * see hosts.h :o( 1358 * see hosts.h :o(
947 */ 1359 */
948 sh->max_id = MPT_MAX_SCSI_DEVICES; 1360 sh->max_id = ioc->devices_per_bus;
949 1361
950 sh->max_lun = MPT_LAST_LUN + 1; 1362 sh->max_lun = MPT_LAST_LUN + 1;
951 /* 1363 /*
952 * If RAID Firmware Detected, setup virtual channel 1364 * If RAID Firmware Detected, setup virtual channel
953 */ 1365 */
954 if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK) 1366 if (ioc->ir_firmware)
955 > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
956 sh->max_channel = 1; 1367 sh->max_channel = 1;
957 else 1368 else
958 sh->max_channel = 0; 1369 sh->max_channel = 0;
@@ -1009,20 +1420,6 @@ mptspi_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1009 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n", 1420 dprintk((MYIOC_s_INFO_FMT "ScsiLookup @ %p\n",
1010 ioc->name, hd->ScsiLookup)); 1421 ioc->name, hd->ScsiLookup));
1011 1422
1012 /* Allocate memory for the device structures.
1013 * A non-Null pointer at an offset
1014 * indicates a device exists.
1015 * max_id = 1 + maximum id (hosts.h)
1016 */
1017 hd->Targets = kcalloc(sh->max_id * (sh->max_channel + 1),
1018 sizeof(void *), GFP_ATOMIC);
1019 if (!hd->Targets) {
1020 error = -ENOMEM;
1021 goto out_mptspi_probe;
1022 }
1023
1024 dprintk((KERN_INFO " vdev @ %p\n", hd->Targets));
1025
1026 /* Clear the TM flags 1423 /* Clear the TM flags
1027 */ 1424 */
1028 hd->tmPending = 0; 1425 hd->tmPending = 0;
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index e33d446e749..8ba275a1277 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -1111,7 +1111,7 @@ static int cfg_release(struct inode *inode, struct file *file)
1111 return 0; 1111 return 0;
1112} 1112}
1113 1113
1114static struct file_operations config_fops = { 1114static const struct file_operations config_fops = {
1115 .owner = THIS_MODULE, 1115 .owner = THIS_MODULE,
1116 .llseek = no_llseek, 1116 .llseek = no_llseek,
1117 .ioctl = i2o_cfg_ioctl, 1117 .ioctl = i2o_cfg_ioctl,
diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
index a61cb17c5c1..06892ac2286 100644
--- a/drivers/message/i2o/i2o_proc.c
+++ b/drivers/message/i2o/i2o_proc.c
@@ -1703,133 +1703,133 @@ static int i2o_seq_open_dev_name(struct inode *inode, struct file *file)
1703 return single_open(file, i2o_seq_show_dev_name, PDE(inode)->data); 1703 return single_open(file, i2o_seq_show_dev_name, PDE(inode)->data);
1704}; 1704};
1705 1705
1706static struct file_operations i2o_seq_fops_lct = { 1706static const struct file_operations i2o_seq_fops_lct = {
1707 .open = i2o_seq_open_lct, 1707 .open = i2o_seq_open_lct,
1708 .read = seq_read, 1708 .read = seq_read,
1709 .llseek = seq_lseek, 1709 .llseek = seq_lseek,
1710 .release = single_release, 1710 .release = single_release,
1711}; 1711};
1712 1712
1713static struct file_operations i2o_seq_fops_hrt = { 1713static const struct file_operations i2o_seq_fops_hrt = {
1714 .open = i2o_seq_open_hrt, 1714 .open = i2o_seq_open_hrt,
1715 .read = seq_read, 1715 .read = seq_read,
1716 .llseek = seq_lseek, 1716 .llseek = seq_lseek,
1717 .release = single_release, 1717 .release = single_release,
1718}; 1718};
1719 1719
1720static struct file_operations i2o_seq_fops_status = { 1720static const struct file_operations i2o_seq_fops_status = {
1721 .open = i2o_seq_open_status, 1721 .open = i2o_seq_open_status,
1722 .read = seq_read, 1722 .read = seq_read,
1723 .llseek = seq_lseek, 1723 .llseek = seq_lseek,
1724 .release = single_release, 1724 .release = single_release,
1725}; 1725};
1726 1726
1727static struct file_operations i2o_seq_fops_hw = { 1727static const struct file_operations i2o_seq_fops_hw = {
1728 .open = i2o_seq_open_hw, 1728 .open = i2o_seq_open_hw,
1729 .read = seq_read, 1729 .read = seq_read,
1730 .llseek = seq_lseek, 1730 .llseek = seq_lseek,
1731 .release = single_release, 1731 .release = single_release,
1732}; 1732};
1733 1733
1734static struct file_operations i2o_seq_fops_ddm_table = { 1734static const struct file_operations i2o_seq_fops_ddm_table = {
1735 .open = i2o_seq_open_ddm_table, 1735 .open = i2o_seq_open_ddm_table,
1736 .read = seq_read, 1736 .read = seq_read,
1737 .llseek = seq_lseek, 1737 .llseek = seq_lseek,
1738 .release = single_release, 1738 .release = single_release,
1739}; 1739};
1740 1740
1741static struct file_operations i2o_seq_fops_driver_store = { 1741static const struct file_operations i2o_seq_fops_driver_store = {
1742 .open = i2o_seq_open_driver_store, 1742 .open = i2o_seq_open_driver_store,
1743 .read = seq_read, 1743 .read = seq_read,
1744 .llseek = seq_lseek, 1744 .llseek = seq_lseek,
1745 .release = single_release, 1745 .release = single_release,
1746}; 1746};
1747 1747
1748static struct file_operations i2o_seq_fops_drivers_stored = { 1748static const struct file_operations i2o_seq_fops_drivers_stored = {
1749 .open = i2o_seq_open_drivers_stored, 1749 .open = i2o_seq_open_drivers_stored,
1750 .read = seq_read, 1750 .read = seq_read,
1751 .llseek = seq_lseek, 1751 .llseek = seq_lseek,
1752 .release = single_release, 1752 .release = single_release,
1753}; 1753};
1754 1754
1755static struct file_operations i2o_seq_fops_groups = { 1755static const struct file_operations i2o_seq_fops_groups = {
1756 .open = i2o_seq_open_groups, 1756 .open = i2o_seq_open_groups,
1757 .read = seq_read, 1757 .read = seq_read,
1758 .llseek = seq_lseek, 1758 .llseek = seq_lseek,
1759 .release = single_release, 1759 .release = single_release,
1760}; 1760};
1761 1761
1762static struct file_operations i2o_seq_fops_phys_device = { 1762static const struct file_operations i2o_seq_fops_phys_device = {
1763 .open = i2o_seq_open_phys_device, 1763 .open = i2o_seq_open_phys_device,
1764 .read = seq_read, 1764 .read = seq_read,
1765 .llseek = seq_lseek, 1765 .llseek = seq_lseek,
1766 .release = single_release, 1766 .release = single_release,
1767}; 1767};
1768 1768
1769static struct file_operations i2o_seq_fops_claimed = { 1769static const struct file_operations i2o_seq_fops_claimed = {
1770 .open = i2o_seq_open_claimed, 1770 .open = i2o_seq_open_claimed,
1771 .read = seq_read, 1771 .read = seq_read,
1772 .llseek = seq_lseek, 1772 .llseek = seq_lseek,
1773 .release = single_release, 1773 .release = single_release,
1774}; 1774};
1775 1775
1776static struct file_operations i2o_seq_fops_users = { 1776static const struct file_operations i2o_seq_fops_users = {
1777 .open = i2o_seq_open_users, 1777 .open = i2o_seq_open_users,
1778 .read = seq_read, 1778 .read = seq_read,
1779 .llseek = seq_lseek, 1779 .llseek = seq_lseek,
1780 .release = single_release, 1780 .release = single_release,
1781}; 1781};
1782 1782
1783static struct file_operations i2o_seq_fops_priv_msgs = { 1783static const struct file_operations i2o_seq_fops_priv_msgs = {
1784 .open = i2o_seq_open_priv_msgs, 1784 .open = i2o_seq_open_priv_msgs,
1785 .read = seq_read, 1785 .read = seq_read,
1786 .llseek = seq_lseek, 1786 .llseek = seq_lseek,
1787 .release = single_release, 1787 .release = single_release,
1788}; 1788};
1789 1789
1790static struct file_operations i2o_seq_fops_authorized_users = { 1790static const struct file_operations i2o_seq_fops_authorized_users = {
1791 .open = i2o_seq_open_authorized_users, 1791 .open = i2o_seq_open_authorized_users,
1792 .read = seq_read, 1792 .read = seq_read,
1793 .llseek = seq_lseek, 1793 .llseek = seq_lseek,
1794 .release = single_release, 1794 .release = single_release,
1795}; 1795};
1796 1796
1797static struct file_operations i2o_seq_fops_dev_name = { 1797static const struct file_operations i2o_seq_fops_dev_name = {
1798 .open = i2o_seq_open_dev_name, 1798 .open = i2o_seq_open_dev_name,
1799 .read = seq_read, 1799 .read = seq_read,
1800 .llseek = seq_lseek, 1800 .llseek = seq_lseek,
1801 .release = single_release, 1801 .release = single_release,
1802}; 1802};
1803 1803
1804static struct file_operations i2o_seq_fops_dev_identity = { 1804static const struct file_operations i2o_seq_fops_dev_identity = {
1805 .open = i2o_seq_open_dev_identity, 1805 .open = i2o_seq_open_dev_identity,
1806 .read = seq_read, 1806 .read = seq_read,
1807 .llseek = seq_lseek, 1807 .llseek = seq_lseek,
1808 .release = single_release, 1808 .release = single_release,
1809}; 1809};
1810 1810
1811static struct file_operations i2o_seq_fops_ddm_identity = { 1811static const struct file_operations i2o_seq_fops_ddm_identity = {
1812 .open = i2o_seq_open_ddm_identity, 1812 .open = i2o_seq_open_ddm_identity,
1813 .read = seq_read, 1813 .read = seq_read,
1814 .llseek = seq_lseek, 1814 .llseek = seq_lseek,
1815 .release = single_release, 1815 .release = single_release,
1816}; 1816};
1817 1817
1818static struct file_operations i2o_seq_fops_uinfo = { 1818static const struct file_operations i2o_seq_fops_uinfo = {
1819 .open = i2o_seq_open_uinfo, 1819 .open = i2o_seq_open_uinfo,
1820 .read = seq_read, 1820 .read = seq_read,
1821 .llseek = seq_lseek, 1821 .llseek = seq_lseek,
1822 .release = single_release, 1822 .release = single_release,
1823}; 1823};
1824 1824
1825static struct file_operations i2o_seq_fops_sgl_limits = { 1825static const struct file_operations i2o_seq_fops_sgl_limits = {
1826 .open = i2o_seq_open_sgl_limits, 1826 .open = i2o_seq_open_sgl_limits,
1827 .read = seq_read, 1827 .read = seq_read,
1828 .llseek = seq_lseek, 1828 .llseek = seq_lseek,
1829 .release = single_release, 1829 .release = single_release,
1830}; 1830};
1831 1831
1832static struct file_operations i2o_seq_fops_sensors = { 1832static const struct file_operations i2o_seq_fops_sensors = {
1833 .open = i2o_seq_open_sensors, 1833 .open = i2o_seq_open_sensors,
1834 .read = seq_read, 1834 .read = seq_read,
1835 .llseek = seq_lseek, 1835 .llseek = seq_lseek,
diff --git a/drivers/misc/hdpuftrs/hdpu_cpustate.c b/drivers/misc/hdpuftrs/hdpu_cpustate.c
index 11a801be71c..ca86f113f36 100644
--- a/drivers/misc/hdpuftrs/hdpu_cpustate.c
+++ b/drivers/misc/hdpuftrs/hdpu_cpustate.c
@@ -169,7 +169,7 @@ static struct platform_driver hdpu_cpustate_driver = {
169/* 169/*
170 * The various file operations we support. 170 * The various file operations we support.
171 */ 171 */
172static struct file_operations cpustate_fops = { 172static const struct file_operations cpustate_fops = {
173 owner:THIS_MODULE, 173 owner:THIS_MODULE,
174 open:cpustate_open, 174 open:cpustate_open,
175 release:cpustate_release, 175 release:cpustate_release,
diff --git a/drivers/misc/hdpuftrs/hdpu_nexus.c b/drivers/misc/hdpuftrs/hdpu_nexus.c
index ea9d5f233c8..6a51e99a807 100644
--- a/drivers/misc/hdpuftrs/hdpu_nexus.c
+++ b/drivers/misc/hdpuftrs/hdpu_nexus.c
@@ -72,11 +72,9 @@ static int hdpu_nexus_probe(struct platform_device *pdev)
72 printk("Could not map slot id\n"); 72 printk("Could not map slot id\n");
73 hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root); 73 hdpu_slot_id = create_proc_entry("sky_slot_id", 0666, &proc_root);
74 hdpu_slot_id->read_proc = hdpu_slot_id_read; 74 hdpu_slot_id->read_proc = hdpu_slot_id_read;
75 hdpu_slot_id->nlink = 1;
76 75
77 hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root); 76 hdpu_chassis_id = create_proc_entry("sky_chassis_id", 0666, &proc_root);
78 hdpu_chassis_id->read_proc = hdpu_chassis_id_read; 77 hdpu_chassis_id->read_proc = hdpu_chassis_id_read;
79 hdpu_chassis_id->nlink = 1;
80 return 0; 78 return 0;
81} 79}
82 80
diff --git a/drivers/misc/ibmasm/ibmasmfs.c b/drivers/misc/ibmasm/ibmasmfs.c
index b99dc507de2..c436d3de8b8 100644
--- a/drivers/misc/ibmasm/ibmasmfs.c
+++ b/drivers/misc/ibmasm/ibmasmfs.c
@@ -156,7 +156,7 @@ static struct inode *ibmasmfs_make_inode(struct super_block *sb, int mode)
156static struct dentry *ibmasmfs_create_file (struct super_block *sb, 156static struct dentry *ibmasmfs_create_file (struct super_block *sb,
157 struct dentry *parent, 157 struct dentry *parent,
158 const char *name, 158 const char *name,
159 struct file_operations *fops, 159 const struct file_operations *fops,
160 void *data, 160 void *data,
161 int mode) 161 int mode)
162{ 162{
@@ -581,28 +581,28 @@ static ssize_t remote_settings_file_write(struct file *file, const char __user *
581 return count; 581 return count;
582} 582}
583 583
584static struct file_operations command_fops = { 584static const struct file_operations command_fops = {
585 .open = command_file_open, 585 .open = command_file_open,
586 .release = command_file_close, 586 .release = command_file_close,
587 .read = command_file_read, 587 .read = command_file_read,
588 .write = command_file_write, 588 .write = command_file_write,
589}; 589};
590 590
591static struct file_operations event_fops = { 591static const struct file_operations event_fops = {
592 .open = event_file_open, 592 .open = event_file_open,
593 .release = event_file_close, 593 .release = event_file_close,
594 .read = event_file_read, 594 .read = event_file_read,
595 .write = event_file_write, 595 .write = event_file_write,
596}; 596};
597 597
598static struct file_operations r_heartbeat_fops = { 598static const struct file_operations r_heartbeat_fops = {
599 .open = r_heartbeat_file_open, 599 .open = r_heartbeat_file_open,
600 .release = r_heartbeat_file_close, 600 .release = r_heartbeat_file_close,
601 .read = r_heartbeat_file_read, 601 .read = r_heartbeat_file_read,
602 .write = r_heartbeat_file_write, 602 .write = r_heartbeat_file_write,
603}; 603};
604 604
605static struct file_operations remote_settings_fops = { 605static const struct file_operations remote_settings_fops = {
606 .open = remote_settings_file_open, 606 .open = remote_settings_file_open,
607 .release = remote_settings_file_close, 607 .release = remote_settings_file_close,
608 .read = remote_settings_file_read, 608 .read = remote_settings_file_read,
diff --git a/drivers/misc/ioc4.c b/drivers/misc/ioc4.c
index b995a15b752..6a5a05d1f39 100644
--- a/drivers/misc/ioc4.c
+++ b/drivers/misc/ioc4.c
@@ -309,7 +309,7 @@ ioc4_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
309 ret = -ENODEV; 309 ret = -ENODEV;
310 goto out_pci; 310 goto out_pci;
311 } 311 }
312 if (!request_region(idd->idd_bar0, sizeof(struct ioc4_misc_regs), 312 if (!request_mem_region(idd->idd_bar0, sizeof(struct ioc4_misc_regs),
313 "ioc4_misc")) { 313 "ioc4_misc")) {
314 printk(KERN_WARNING 314 printk(KERN_WARNING
315 "%s: Unable to request IOC4 misc region " 315 "%s: Unable to request IOC4 misc region "
@@ -379,7 +379,7 @@ ioc4_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
379 return 0; 379 return 0;
380 380
381out_misc_region: 381out_misc_region:
382 release_region(idd->idd_bar0, sizeof(struct ioc4_misc_regs)); 382 release_mem_region(idd->idd_bar0, sizeof(struct ioc4_misc_regs));
383out_pci: 383out_pci:
384 kfree(idd); 384 kfree(idd);
385out_idd: 385out_idd:
@@ -418,7 +418,7 @@ ioc4_remove(struct pci_dev *pdev)
418 "Device removal may be incomplete.\n", 418 "Device removal may be incomplete.\n",
419 __FUNCTION__, pci_name(idd->idd_pdev)); 419 __FUNCTION__, pci_name(idd->idd_pdev));
420 } 420 }
421 release_region(idd->idd_bar0, sizeof(struct ioc4_misc_regs)); 421 release_mem_region(idd->idd_bar0, sizeof(struct ioc4_misc_regs));
422 422
423 /* Disable IOC4 and relinquish */ 423 /* Disable IOC4 and relinquish */
424 pci_disable_device(pdev); 424 pci_disable_device(pdev);
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 4bf1fea5e2c..7522f76b15e 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -22,9 +22,6 @@
22#include "sdhci.h" 22#include "sdhci.h"
23 23
24#define DRIVER_NAME "sdhci" 24#define DRIVER_NAME "sdhci"
25#define DRIVER_VERSION "0.12"
26
27#define BUGMAIL "<sdhci-devel@list.drzeus.cx>"
28 25
29#define DBG(f, x...) \ 26#define DBG(f, x...) \
30 pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x) 27 pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
@@ -154,8 +151,7 @@ static void sdhci_reset(struct sdhci_host *host, u8 mask)
154 /* hw clears the bit when it's done */ 151 /* hw clears the bit when it's done */
155 while (readb(host->ioaddr + SDHCI_SOFTWARE_RESET) & mask) { 152 while (readb(host->ioaddr + SDHCI_SOFTWARE_RESET) & mask) {
156 if (timeout == 0) { 153 if (timeout == 0) {
157 printk(KERN_ERR "%s: Reset 0x%x never completed. " 154 printk(KERN_ERR "%s: Reset 0x%x never completed.\n",
158 "Please report this to " BUGMAIL ".\n",
159 mmc_hostname(host->mmc), (int)mask); 155 mmc_hostname(host->mmc), (int)mask);
160 sdhci_dumpregs(host); 156 sdhci_dumpregs(host);
161 return; 157 return;
@@ -474,12 +470,11 @@ static void sdhci_finish_data(struct sdhci_host *host)
474 470
475 if ((data->error == MMC_ERR_NONE) && blocks) { 471 if ((data->error == MMC_ERR_NONE) && blocks) {
476 printk(KERN_ERR "%s: Controller signalled completion even " 472 printk(KERN_ERR "%s: Controller signalled completion even "
477 "though there were blocks left. Please report this " 473 "though there were blocks left.\n",
478 "to " BUGMAIL ".\n", mmc_hostname(host->mmc)); 474 mmc_hostname(host->mmc));
479 data->error = MMC_ERR_FAILED; 475 data->error = MMC_ERR_FAILED;
480 } else if (host->size != 0) { 476 } else if (host->size != 0) {
481 printk(KERN_ERR "%s: %d bytes were left untransferred. " 477 printk(KERN_ERR "%s: %d bytes were left untransferred.\n",
482 "Please report this to " BUGMAIL ".\n",
483 mmc_hostname(host->mmc), host->size); 478 mmc_hostname(host->mmc), host->size);
484 data->error = MMC_ERR_FAILED; 479 data->error = MMC_ERR_FAILED;
485 } 480 }
@@ -526,8 +521,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
526 while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) { 521 while (readl(host->ioaddr + SDHCI_PRESENT_STATE) & mask) {
527 if (timeout == 0) { 522 if (timeout == 0) {
528 printk(KERN_ERR "%s: Controller never released " 523 printk(KERN_ERR "%s: Controller never released "
529 "inhibit bit(s). Please report this to " 524 "inhibit bit(s).\n", mmc_hostname(host->mmc));
530 BUGMAIL ".\n", mmc_hostname(host->mmc));
531 sdhci_dumpregs(host); 525 sdhci_dumpregs(host);
532 cmd->error = MMC_ERR_FAILED; 526 cmd->error = MMC_ERR_FAILED;
533 tasklet_schedule(&host->finish_tasklet); 527 tasklet_schedule(&host->finish_tasklet);
@@ -548,8 +542,7 @@ static void sdhci_send_command(struct sdhci_host *host, struct mmc_command *cmd)
548 sdhci_set_transfer_mode(host, cmd->data); 542 sdhci_set_transfer_mode(host, cmd->data);
549 543
550 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) { 544 if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) {
551 printk(KERN_ERR "%s: Unsupported response type! " 545 printk(KERN_ERR "%s: Unsupported response type!\n",
552 "Please report this to " BUGMAIL ".\n",
553 mmc_hostname(host->mmc)); 546 mmc_hostname(host->mmc));
554 cmd->error = MMC_ERR_INVALID; 547 cmd->error = MMC_ERR_INVALID;
555 tasklet_schedule(&host->finish_tasklet); 548 tasklet_schedule(&host->finish_tasklet);
@@ -647,9 +640,8 @@ static void sdhci_set_clock(struct sdhci_host *host, unsigned int clock)
647 while (!((clk = readw(host->ioaddr + SDHCI_CLOCK_CONTROL)) 640 while (!((clk = readw(host->ioaddr + SDHCI_CLOCK_CONTROL))
648 & SDHCI_CLOCK_INT_STABLE)) { 641 & SDHCI_CLOCK_INT_STABLE)) {
649 if (timeout == 0) { 642 if (timeout == 0) {
650 printk(KERN_ERR "%s: Internal clock never stabilised. " 643 printk(KERN_ERR "%s: Internal clock never "
651 "Please report this to " BUGMAIL ".\n", 644 "stabilised.\n", mmc_hostname(host->mmc));
652 mmc_hostname(host->mmc));
653 sdhci_dumpregs(host); 645 sdhci_dumpregs(host);
654 return; 646 return;
655 } 647 }
@@ -899,9 +891,8 @@ static void sdhci_timeout_timer(unsigned long data)
899 spin_lock_irqsave(&host->lock, flags); 891 spin_lock_irqsave(&host->lock, flags);
900 892
901 if (host->mrq) { 893 if (host->mrq) {
902 printk(KERN_ERR "%s: Timeout waiting for hardware interrupt. " 894 printk(KERN_ERR "%s: Timeout waiting for hardware "
903 "Please report this to " BUGMAIL ".\n", 895 "interrupt.\n", mmc_hostname(host->mmc));
904 mmc_hostname(host->mmc));
905 sdhci_dumpregs(host); 896 sdhci_dumpregs(host);
906 897
907 if (host->data) { 898 if (host->data) {
@@ -935,8 +926,6 @@ static void sdhci_cmd_irq(struct sdhci_host *host, u32 intmask)
935 printk(KERN_ERR "%s: Got command interrupt even though no " 926 printk(KERN_ERR "%s: Got command interrupt even though no "
936 "command operation was in progress.\n", 927 "command operation was in progress.\n",
937 mmc_hostname(host->mmc)); 928 mmc_hostname(host->mmc));
938 printk(KERN_ERR "%s: Please report this to " BUGMAIL ".\n",
939 mmc_hostname(host->mmc));
940 sdhci_dumpregs(host); 929 sdhci_dumpregs(host);
941 return; 930 return;
942 } 931 }
@@ -972,8 +961,6 @@ static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
972 printk(KERN_ERR "%s: Got data interrupt even though no " 961 printk(KERN_ERR "%s: Got data interrupt even though no "
973 "data operation was in progress.\n", 962 "data operation was in progress.\n",
974 mmc_hostname(host->mmc)); 963 mmc_hostname(host->mmc));
975 printk(KERN_ERR "%s: Please report this to " BUGMAIL ".\n",
976 mmc_hostname(host->mmc));
977 sdhci_dumpregs(host); 964 sdhci_dumpregs(host);
978 965
979 return; 966 return;
@@ -1045,8 +1032,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id)
1045 intmask &= SDHCI_INT_BUS_POWER; 1032 intmask &= SDHCI_INT_BUS_POWER;
1046 1033
1047 if (intmask) { 1034 if (intmask) {
1048 printk(KERN_ERR "%s: Unexpected interrupt 0x%08x. Please " 1035 printk(KERN_ERR "%s: Unexpected interrupt 0x%08x.\n",
1049 "report this to " BUGMAIL ".\n",
1050 mmc_hostname(host->mmc), intmask); 1036 mmc_hostname(host->mmc), intmask);
1051 sdhci_dumpregs(host); 1037 sdhci_dumpregs(host);
1052 1038
@@ -1528,8 +1514,7 @@ static struct pci_driver sdhci_driver = {
1528static int __init sdhci_drv_init(void) 1514static int __init sdhci_drv_init(void)
1529{ 1515{
1530 printk(KERN_INFO DRIVER_NAME 1516 printk(KERN_INFO DRIVER_NAME
1531 ": Secure Digital Host Controller Interface driver, " 1517 ": Secure Digital Host Controller Interface driver\n");
1532 DRIVER_VERSION "\n");
1533 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); 1518 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
1534 1519
1535 return pci_register_driver(&sdhci_driver); 1520 return pci_register_driver(&sdhci_driver);
@@ -1551,7 +1536,6 @@ module_param(debug_quirks, uint, 0444);
1551 1536
1552MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); 1537MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
1553MODULE_DESCRIPTION("Secure Digital Host Controller Interface driver"); 1538MODULE_DESCRIPTION("Secure Digital Host Controller Interface driver");
1554MODULE_VERSION(DRIVER_VERSION);
1555MODULE_LICENSE("GPL"); 1539MODULE_LICENSE("GPL");
1556 1540
1557MODULE_PARM_DESC(debug_nodma, "Forcefully disable DMA transfers. (default 0)"); 1541MODULE_PARM_DESC(debug_nodma, "Forcefully disable DMA transfers. (default 0)");
diff --git a/drivers/mmc/tifm_sd.c b/drivers/mmc/tifm_sd.c
index e65f8a0a934..0581d09c58f 100644
--- a/drivers/mmc/tifm_sd.c
+++ b/drivers/mmc/tifm_sd.c
@@ -36,8 +36,8 @@ module_param(fixed_timeout, bool, 0644);
36#define TIFM_MMCSD_INAB 0x0080 /* abort / initialize command */ 36#define TIFM_MMCSD_INAB 0x0080 /* abort / initialize command */
37#define TIFM_MMCSD_READ 0x8000 37#define TIFM_MMCSD_READ 0x8000
38 38
39#define TIFM_MMCSD_DATAMASK 0x001d /* set bits: EOFB, BRS, CB, EOC */ 39#define TIFM_MMCSD_DATAMASK 0x401d /* set bits: CERR, EOFB, BRS, CB, EOC */
40#define TIFM_MMCSD_ERRMASK 0x41e0 /* set bits: CERR, CCRC, CTO, DCRC, DTO */ 40#define TIFM_MMCSD_ERRMASK 0x01e0 /* set bits: CCRC, CTO, DCRC, DTO */
41#define TIFM_MMCSD_EOC 0x0001 /* end of command phase */ 41#define TIFM_MMCSD_EOC 0x0001 /* end of command phase */
42#define TIFM_MMCSD_CB 0x0004 /* card enter busy state */ 42#define TIFM_MMCSD_CB 0x0004 /* card enter busy state */
43#define TIFM_MMCSD_BRS 0x0008 /* block received/sent */ 43#define TIFM_MMCSD_BRS 0x0008 /* block received/sent */
@@ -242,7 +242,7 @@ change_state:
242 case IDLE: 242 case IDLE:
243 return; 243 return;
244 case CMD: 244 case CMD:
245 if (host_status & TIFM_MMCSD_EOC) { 245 if (host_status & (TIFM_MMCSD_EOC | TIFM_MMCSD_CERR)) {
246 tifm_sd_fetch_resp(cmd, sock); 246 tifm_sd_fetch_resp(cmd, sock);
247 if (cmd->data) { 247 if (cmd->data) {
248 host->state = BRS; 248 host->state = BRS;
@@ -341,10 +341,7 @@ static void tifm_sd_signal_irq(struct tifm_dev *sock,
341 goto done; 341 goto done;
342 342
343 if (host_status & TIFM_MMCSD_ERRMASK) { 343 if (host_status & TIFM_MMCSD_ERRMASK) {
344 if (host_status & TIFM_MMCSD_CERR) 344 if (host_status & (TIFM_MMCSD_CTO | TIFM_MMCSD_DTO))
345 error_code = MMC_ERR_FAILED;
346 else if (host_status
347 & (TIFM_MMCSD_CTO | TIFM_MMCSD_DTO))
348 error_code = MMC_ERR_TIMEOUT; 345 error_code = MMC_ERR_TIMEOUT;
349 else if (host_status 346 else if (host_status
350 & (TIFM_MMCSD_CCRC | TIFM_MMCSD_DCRC)) 347 & (TIFM_MMCSD_CCRC | TIFM_MMCSD_DCRC))
diff --git a/drivers/mmc/wbsd.c b/drivers/mmc/wbsd.c
index a44d8777ab9..05ccfc43168 100644
--- a/drivers/mmc/wbsd.c
+++ b/drivers/mmc/wbsd.c
@@ -42,7 +42,6 @@
42#include "wbsd.h" 42#include "wbsd.h"
43 43
44#define DRIVER_NAME "wbsd" 44#define DRIVER_NAME "wbsd"
45#define DRIVER_VERSION "1.6"
46 45
47#define DBG(x...) \ 46#define DBG(x...) \
48 pr_debug(DRIVER_NAME ": " x) 47 pr_debug(DRIVER_NAME ": " x)
@@ -344,7 +343,6 @@ static inline void wbsd_dma_to_sg(struct wbsd_host *host, struct mmc_data *data)
344 memcpy(sgbuf, dmabuf, size); 343 memcpy(sgbuf, dmabuf, size);
345 else 344 else
346 memcpy(sgbuf, dmabuf, sg[i].length); 345 memcpy(sgbuf, dmabuf, sg[i].length);
347 kunmap_atomic(sgbuf, KM_BIO_SRC_IRQ);
348 dmabuf += sg[i].length; 346 dmabuf += sg[i].length;
349 347
350 if (size < sg[i].length) 348 if (size < sg[i].length)
@@ -2101,8 +2099,7 @@ static int __init wbsd_drv_init(void)
2101 int result; 2099 int result;
2102 2100
2103 printk(KERN_INFO DRIVER_NAME 2101 printk(KERN_INFO DRIVER_NAME
2104 ": Winbond W83L51xD SD/MMC card interface driver, " 2102 ": Winbond W83L51xD SD/MMC card interface driver\n");
2105 DRIVER_VERSION "\n");
2106 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n"); 2103 printk(KERN_INFO DRIVER_NAME ": Copyright(c) Pierre Ossman\n");
2107 2104
2108#ifdef CONFIG_PNP 2105#ifdef CONFIG_PNP
@@ -2166,7 +2163,6 @@ module_param(dma, int, 0444);
2166MODULE_LICENSE("GPL"); 2163MODULE_LICENSE("GPL");
2167MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>"); 2164MODULE_AUTHOR("Pierre Ossman <drzeus@drzeus.cx>");
2168MODULE_DESCRIPTION("Winbond W83L51xD SD/MMC card interface driver"); 2165MODULE_DESCRIPTION("Winbond W83L51xD SD/MMC card interface driver");
2169MODULE_VERSION(DRIVER_VERSION);
2170 2166
2171#ifdef CONFIG_PNP 2167#ifdef CONFIG_PNP
2172MODULE_PARM_DESC(nopnp, "Scan for device instead of relying on PNP. (default 0)"); 2168MODULE_PARM_DESC(nopnp, "Scan for device instead of relying on PNP. (default 0)");
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 6d917a4daa9..f9f2ce7806b 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -278,7 +278,8 @@ static void block2mtd_free_device(struct block2mtd_dev *dev)
278 kfree(dev->mtd.name); 278 kfree(dev->mtd.name);
279 279
280 if (dev->blkdev) { 280 if (dev->blkdev) {
281 invalidate_inode_pages(dev->blkdev->bd_inode->i_mapping); 281 invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping,
282 0, -1);
282 close_bdev_excl(dev->blkdev); 283 close_bdev_excl(dev->blkdev);
283 } 284 }
284 285
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 3013d0883b9..61a994ea8af 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -759,7 +759,7 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
759 return ret; 759 return ret;
760} /* memory_ioctl */ 760} /* memory_ioctl */
761 761
762static struct file_operations mtd_fops = { 762static const struct file_operations mtd_fops = {
763 .owner = THIS_MODULE, 763 .owner = THIS_MODULE,
764 .llseek = mtd_lseek, 764 .llseek = mtd_lseek,
765 .read = mtd_read, 765 .read = mtd_read,
diff --git a/drivers/net/arcnet/com20020.c b/drivers/net/arcnet/com20020.c
index aa9dd8f1126..4218075c8aa 100644
--- a/drivers/net/arcnet/com20020.c
+++ b/drivers/net/arcnet/com20020.c
@@ -338,7 +338,8 @@ static void com20020_set_mc_list(struct net_device *dev)
338} 338}
339 339
340#if defined(CONFIG_ARCNET_COM20020_PCI_MODULE) || \ 340#if defined(CONFIG_ARCNET_COM20020_PCI_MODULE) || \
341 defined(CONFIG_ARCNET_COM20020_ISA_MODULE) 341 defined(CONFIG_ARCNET_COM20020_ISA_MODULE) || \
342 defined(CONFIG_ARCNET_COM20020_CS_MODULE)
342EXPORT_SYMBOL(com20020_check); 343EXPORT_SYMBOL(com20020_check);
343EXPORT_SYMBOL(com20020_found); 344EXPORT_SYMBOL(com20020_found);
344#endif 345#endif
diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 8ce8fec615b..61a6fa465d7 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -3120,7 +3120,7 @@ static int bond_info_open(struct inode *inode, struct file *file)
3120 return res; 3120 return res;
3121} 3121}
3122 3122
3123static struct file_operations bond_info_fops = { 3123static const struct file_operations bond_info_fops = {
3124 .owner = THIS_MODULE, 3124 .owner = THIS_MODULE,
3125 .open = bond_info_open, 3125 .open = bond_info_open,
3126 .read = seq_read, 3126 .read = seq_read,
diff --git a/drivers/net/gianfar_sysfs.c b/drivers/net/gianfar_sysfs.c
index 9dd387fb3d7..6e2166a7601 100644
--- a/drivers/net/gianfar_sysfs.c
+++ b/drivers/net/gianfar_sysfs.c
@@ -39,13 +39,15 @@
39#include "gianfar.h" 39#include "gianfar.h"
40 40
41#define GFAR_ATTR(_name) \ 41#define GFAR_ATTR(_name) \
42static ssize_t gfar_show_##_name(struct class_device *cdev, char *buf); \ 42static ssize_t gfar_show_##_name(struct device *dev, \
43static ssize_t gfar_set_##_name(struct class_device *cdev, \ 43 struct device_attribute *attr, char *buf); \
44static ssize_t gfar_set_##_name(struct device *dev, \
45 struct device_attribute *attr, \
44 const char *buf, size_t count); \ 46 const char *buf, size_t count); \
45static CLASS_DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name) 47static DEVICE_ATTR(_name, 0644, gfar_show_##_name, gfar_set_##_name)
46 48
47#define GFAR_CREATE_FILE(_dev, _name) \ 49#define GFAR_CREATE_FILE(_dev, _name) \
48 class_device_create_file(&_dev->class_dev, &class_device_attr_##_name) 50 device_create_file(&_dev->dev, &dev_attr_##_name)
49 51
50GFAR_ATTR(bd_stash); 52GFAR_ATTR(bd_stash);
51GFAR_ATTR(rx_stash_size); 53GFAR_ATTR(rx_stash_size);
@@ -54,29 +56,28 @@ GFAR_ATTR(fifo_threshold);
54GFAR_ATTR(fifo_starve); 56GFAR_ATTR(fifo_starve);
55GFAR_ATTR(fifo_starve_off); 57GFAR_ATTR(fifo_starve_off);
56 58
57#define to_net_dev(cd) container_of(cd, struct net_device, class_dev) 59static ssize_t gfar_show_bd_stash(struct device *dev,
58 60 struct device_attribute *attr, char *buf)
59static ssize_t gfar_show_bd_stash(struct class_device *cdev, char *buf)
60{ 61{
61 struct net_device *dev = to_net_dev(cdev); 62 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
62 struct gfar_private *priv = netdev_priv(dev);
63 63
64 return sprintf(buf, "%s\n", priv->bd_stash_en? "on" : "off"); 64 return sprintf(buf, "%s\n", priv->bd_stash_en ? "on" : "off");
65} 65}
66 66
67static ssize_t gfar_set_bd_stash(struct class_device *cdev, 67static ssize_t gfar_set_bd_stash(struct device *dev,
68 const char *buf, size_t count) 68 struct device_attribute *attr,
69 const char *buf, size_t count)
69{ 70{
70 struct net_device *dev = to_net_dev(cdev); 71 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
71 struct gfar_private *priv = netdev_priv(dev);
72 int new_setting = 0; 72 int new_setting = 0;
73 u32 temp; 73 u32 temp;
74 unsigned long flags; 74 unsigned long flags;
75 75
76 /* Find out the new setting */ 76 /* Find out the new setting */
77 if (!strncmp("on", buf, count-1) || !strncmp("1", buf, count-1)) 77 if (!strncmp("on", buf, count - 1) || !strncmp("1", buf, count - 1))
78 new_setting = 1; 78 new_setting = 1;
79 else if (!strncmp("off", buf, count-1) || !strncmp("0", buf, count-1)) 79 else if (!strncmp("off", buf, count - 1)
80 || !strncmp("0", buf, count - 1))
80 new_setting = 0; 81 new_setting = 0;
81 else 82 else
82 return count; 83 return count;
@@ -100,19 +101,19 @@ static ssize_t gfar_set_bd_stash(struct class_device *cdev,
100 return count; 101 return count;
101} 102}
102 103
103static ssize_t gfar_show_rx_stash_size(struct class_device *cdev, char *buf) 104static ssize_t gfar_show_rx_stash_size(struct device *dev,
105 struct device_attribute *attr, char *buf)
104{ 106{
105 struct net_device *dev = to_net_dev(cdev); 107 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
106 struct gfar_private *priv = netdev_priv(dev);
107 108
108 return sprintf(buf, "%d\n", priv->rx_stash_size); 109 return sprintf(buf, "%d\n", priv->rx_stash_size);
109} 110}
110 111
111static ssize_t gfar_set_rx_stash_size(struct class_device *cdev, 112static ssize_t gfar_set_rx_stash_size(struct device *dev,
112 const char *buf, size_t count) 113 struct device_attribute *attr,
114 const char *buf, size_t count)
113{ 115{
114 struct net_device *dev = to_net_dev(cdev); 116 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
115 struct gfar_private *priv = netdev_priv(dev);
116 unsigned int length = simple_strtoul(buf, NULL, 0); 117 unsigned int length = simple_strtoul(buf, NULL, 0);
117 u32 temp; 118 u32 temp;
118 unsigned long flags; 119 unsigned long flags;
@@ -146,21 +147,21 @@ static ssize_t gfar_set_rx_stash_size(struct class_device *cdev,
146 return count; 147 return count;
147} 148}
148 149
149
150/* Stashing will only be enabled when rx_stash_size != 0 */ 150/* Stashing will only be enabled when rx_stash_size != 0 */
151static ssize_t gfar_show_rx_stash_index(struct class_device *cdev, char *buf) 151static ssize_t gfar_show_rx_stash_index(struct device *dev,
152 struct device_attribute *attr,
153 char *buf)
152{ 154{
153 struct net_device *dev = to_net_dev(cdev); 155 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
154 struct gfar_private *priv = netdev_priv(dev);
155 156
156 return sprintf(buf, "%d\n", priv->rx_stash_index); 157 return sprintf(buf, "%d\n", priv->rx_stash_index);
157} 158}
158 159
159static ssize_t gfar_set_rx_stash_index(struct class_device *cdev, 160static ssize_t gfar_set_rx_stash_index(struct device *dev,
160 const char *buf, size_t count) 161 struct device_attribute *attr,
162 const char *buf, size_t count)
161{ 163{
162 struct net_device *dev = to_net_dev(cdev); 164 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
163 struct gfar_private *priv = netdev_priv(dev);
164 unsigned short index = simple_strtoul(buf, NULL, 0); 165 unsigned short index = simple_strtoul(buf, NULL, 0);
165 u32 temp; 166 u32 temp;
166 unsigned long flags; 167 unsigned long flags;
@@ -184,19 +185,20 @@ static ssize_t gfar_set_rx_stash_index(struct class_device *cdev,
184 return count; 185 return count;
185} 186}
186 187
187static ssize_t gfar_show_fifo_threshold(struct class_device *cdev, char *buf) 188static ssize_t gfar_show_fifo_threshold(struct device *dev,
189 struct device_attribute *attr,
190 char *buf)
188{ 191{
189 struct net_device *dev = to_net_dev(cdev); 192 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
190 struct gfar_private *priv = netdev_priv(dev);
191 193
192 return sprintf(buf, "%d\n", priv->fifo_threshold); 194 return sprintf(buf, "%d\n", priv->fifo_threshold);
193} 195}
194 196
195static ssize_t gfar_set_fifo_threshold(struct class_device *cdev, 197static ssize_t gfar_set_fifo_threshold(struct device *dev,
196 const char *buf, size_t count) 198 struct device_attribute *attr,
199 const char *buf, size_t count)
197{ 200{
198 struct net_device *dev = to_net_dev(cdev); 201 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
199 struct gfar_private *priv = netdev_priv(dev);
200 unsigned int length = simple_strtoul(buf, NULL, 0); 202 unsigned int length = simple_strtoul(buf, NULL, 0);
201 u32 temp; 203 u32 temp;
202 unsigned long flags; 204 unsigned long flags;
@@ -218,20 +220,19 @@ static ssize_t gfar_set_fifo_threshold(struct class_device *cdev,
218 return count; 220 return count;
219} 221}
220 222
221static ssize_t gfar_show_fifo_starve(struct class_device *cdev, char *buf) 223static ssize_t gfar_show_fifo_starve(struct device *dev,
224 struct device_attribute *attr, char *buf)
222{ 225{
223 struct net_device *dev = to_net_dev(cdev); 226 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
224 struct gfar_private *priv = netdev_priv(dev);
225 227
226 return sprintf(buf, "%d\n", priv->fifo_starve); 228 return sprintf(buf, "%d\n", priv->fifo_starve);
227} 229}
228 230
229 231static ssize_t gfar_set_fifo_starve(struct device *dev,
230static ssize_t gfar_set_fifo_starve(struct class_device *cdev, 232 struct device_attribute *attr,
231 const char *buf, size_t count) 233 const char *buf, size_t count)
232{ 234{
233 struct net_device *dev = to_net_dev(cdev); 235 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
234 struct gfar_private *priv = netdev_priv(dev);
235 unsigned int num = simple_strtoul(buf, NULL, 0); 236 unsigned int num = simple_strtoul(buf, NULL, 0);
236 u32 temp; 237 u32 temp;
237 unsigned long flags; 238 unsigned long flags;
@@ -253,19 +254,20 @@ static ssize_t gfar_set_fifo_starve(struct class_device *cdev,
253 return count; 254 return count;
254} 255}
255 256
256static ssize_t gfar_show_fifo_starve_off(struct class_device *cdev, char *buf) 257static ssize_t gfar_show_fifo_starve_off(struct device *dev,
258 struct device_attribute *attr,
259 char *buf)
257{ 260{
258 struct net_device *dev = to_net_dev(cdev); 261 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
259 struct gfar_private *priv = netdev_priv(dev);
260 262
261 return sprintf(buf, "%d\n", priv->fifo_starve_off); 263 return sprintf(buf, "%d\n", priv->fifo_starve_off);
262} 264}
263 265
264static ssize_t gfar_set_fifo_starve_off(struct class_device *cdev, 266static ssize_t gfar_set_fifo_starve_off(struct device *dev,
265 const char *buf, size_t count) 267 struct device_attribute *attr,
268 const char *buf, size_t count)
266{ 269{
267 struct net_device *dev = to_net_dev(cdev); 270 struct gfar_private *priv = netdev_priv(to_net_dev(dev));
268 struct gfar_private *priv = netdev_priv(dev);
269 unsigned int num = simple_strtoul(buf, NULL, 0); 271 unsigned int num = simple_strtoul(buf, NULL, 0);
270 u32 temp; 272 u32 temp;
271 unsigned long flags; 273 unsigned long flags;
diff --git a/drivers/net/hamradio/bpqether.c b/drivers/net/hamradio/bpqether.c
index 5b788d84011..d2542697e29 100644
--- a/drivers/net/hamradio/bpqether.c
+++ b/drivers/net/hamradio/bpqether.c
@@ -459,7 +459,7 @@ static int bpq_info_open(struct inode *inode, struct file *file)
459 return seq_open(file, &bpq_seqops); 459 return seq_open(file, &bpq_seqops);
460} 460}
461 461
462static struct file_operations bpq_info_fops = { 462static const struct file_operations bpq_info_fops = {
463 .owner = THIS_MODULE, 463 .owner = THIS_MODULE,
464 .open = bpq_info_open, 464 .open = bpq_info_open,
465 .read = seq_read, 465 .read = seq_read,
diff --git a/drivers/net/hamradio/scc.c b/drivers/net/hamradio/scc.c
index 2ce047e9d26..6fdaad5a457 100644
--- a/drivers/net/hamradio/scc.c
+++ b/drivers/net/hamradio/scc.c
@@ -2083,7 +2083,7 @@ static int scc_net_seq_open(struct inode *inode, struct file *file)
2083 return seq_open(file, &scc_net_seq_ops); 2083 return seq_open(file, &scc_net_seq_ops);
2084} 2084}
2085 2085
2086static struct file_operations scc_net_seq_fops = { 2086static const struct file_operations scc_net_seq_fops = {
2087 .owner = THIS_MODULE, 2087 .owner = THIS_MODULE,
2088 .open = scc_net_seq_open, 2088 .open = scc_net_seq_open,
2089 .read = seq_read, 2089 .read = seq_read,
diff --git a/drivers/net/hamradio/yam.c b/drivers/net/hamradio/yam.c
index 6d74f08720d..08f27119a80 100644
--- a/drivers/net/hamradio/yam.c
+++ b/drivers/net/hamradio/yam.c
@@ -804,7 +804,7 @@ static int yam_info_open(struct inode *inode, struct file *file)
804 return seq_open(file, &yam_seqops); 804 return seq_open(file, &yam_seqops);
805} 805}
806 806
807static struct file_operations yam_info_fops = { 807static const struct file_operations yam_info_fops = {
808 .owner = THIS_MODULE, 808 .owner = THIS_MODULE,
809 .open = yam_info_open, 809 .open = yam_info_open,
810 .read = seq_read, 810 .read = seq_read,
diff --git a/drivers/net/ibmveth.c b/drivers/net/ibmveth.c
index 99343b5836b..458db0538a9 100644
--- a/drivers/net/ibmveth.c
+++ b/drivers/net/ibmveth.c
@@ -1156,7 +1156,7 @@ static int ibmveth_proc_open(struct inode *inode, struct file *file)
1156 return rc; 1156 return rc;
1157} 1157}
1158 1158
1159static struct file_operations ibmveth_proc_fops = { 1159static const struct file_operations ibmveth_proc_fops = {
1160 .owner = THIS_MODULE, 1160 .owner = THIS_MODULE,
1161 .open = ibmveth_proc_open, 1161 .open = ibmveth_proc_open,
1162 .read = seq_read, 1162 .read = seq_read,
diff --git a/drivers/net/irda/vlsi_ir.c b/drivers/net/irda/vlsi_ir.c
index e2b1af61845..3457e9d8b66 100644
--- a/drivers/net/irda/vlsi_ir.c
+++ b/drivers/net/irda/vlsi_ir.c
@@ -385,7 +385,7 @@ static int vlsi_seq_open(struct inode *inode, struct file *file)
385 return single_open(file, vlsi_seq_show, PDE(inode)->data); 385 return single_open(file, vlsi_seq_show, PDE(inode)->data);
386} 386}
387 387
388static struct file_operations vlsi_proc_fops = { 388static const struct file_operations vlsi_proc_fops = {
389 .owner = THIS_MODULE, 389 .owner = THIS_MODULE,
390 .open = vlsi_seq_open, 390 .open = vlsi_seq_open,
391 .read = seq_read, 391 .read = seq_read,
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index c6de566188e..11b575f8985 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -83,7 +83,7 @@ struct ppp_file {
83 int dead; /* unit/channel has been shut down */ 83 int dead; /* unit/channel has been shut down */
84}; 84};
85 85
86#define PF_TO_X(pf, X) ((X *)((char *)(pf) - offsetof(X, file))) 86#define PF_TO_X(pf, X) container_of(pf, X, file)
87 87
88#define PF_TO_PPP(pf) PF_TO_X(pf, struct ppp) 88#define PF_TO_PPP(pf) PF_TO_X(pf, struct ppp)
89#define PF_TO_CHANNEL(pf) PF_TO_X(pf, struct channel) 89#define PF_TO_CHANNEL(pf) PF_TO_X(pf, struct channel)
@@ -834,7 +834,7 @@ static int ppp_unattached_ioctl(struct ppp_file *pf, struct file *file,
834 return err; 834 return err;
835} 835}
836 836
837static struct file_operations ppp_device_fops = { 837static const struct file_operations ppp_device_fops = {
838 .owner = THIS_MODULE, 838 .owner = THIS_MODULE,
839 .read = ppp_read, 839 .read = ppp_read,
840 .write = ppp_write, 840 .write = ppp_write,
diff --git a/drivers/net/pppoe.c b/drivers/net/pppoe.c
index 315d5c3fc66..860bb0f60f6 100644
--- a/drivers/net/pppoe.c
+++ b/drivers/net/pppoe.c
@@ -1043,7 +1043,7 @@ static int pppoe_seq_open(struct inode *inode, struct file *file)
1043 return seq_open(file, &pppoe_seq_ops); 1043 return seq_open(file, &pppoe_seq_ops);
1044} 1044}
1045 1045
1046static struct file_operations pppoe_seq_fops = { 1046static const struct file_operations pppoe_seq_fops = {
1047 .owner = THIS_MODULE, 1047 .owner = THIS_MODULE,
1048 .open = pppoe_seq_open, 1048 .open = pppoe_seq_open,
1049 .read = seq_read, 1049 .read = seq_read,
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 151a2e10e4f..5643d1e84ed 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -744,7 +744,7 @@ static int tun_chr_close(struct inode *inode, struct file *file)
744 return 0; 744 return 0;
745} 745}
746 746
747static struct file_operations tun_fops = { 747static const struct file_operations tun_fops = {
748 .owner = THIS_MODULE, 748 .owner = THIS_MODULE,
749 .llseek = no_llseek, 749 .llseek = no_llseek,
750 .read = do_sync_read, 750 .read = do_sync_read,
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index 6c7dfb50143..e91b5a84a20 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -311,7 +311,7 @@ static int cosa_chardev_ioctl(struct inode *inode, struct file *file,
311static int cosa_fasync(struct inode *inode, struct file *file, int on); 311static int cosa_fasync(struct inode *inode, struct file *file, int on);
312#endif 312#endif
313 313
314static struct file_operations cosa_fops = { 314static const struct file_operations cosa_fops = {
315 .owner = THIS_MODULE, 315 .owner = THIS_MODULE,
316 .llseek = no_llseek, 316 .llseek = no_llseek,
317 .read = cosa_read, 317 .read = cosa_read,
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 44a22701da9..b08055abe83 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -4430,53 +4430,53 @@ static int proc_BSSList_open( struct inode *inode, struct file *file );
4430static int proc_config_open( struct inode *inode, struct file *file ); 4430static int proc_config_open( struct inode *inode, struct file *file );
4431static int proc_wepkey_open( struct inode *inode, struct file *file ); 4431static int proc_wepkey_open( struct inode *inode, struct file *file );
4432 4432
4433static struct file_operations proc_statsdelta_ops = { 4433static const struct file_operations proc_statsdelta_ops = {
4434 .read = proc_read, 4434 .read = proc_read,
4435 .open = proc_statsdelta_open, 4435 .open = proc_statsdelta_open,
4436 .release = proc_close 4436 .release = proc_close
4437}; 4437};
4438 4438
4439static struct file_operations proc_stats_ops = { 4439static const struct file_operations proc_stats_ops = {
4440 .read = proc_read, 4440 .read = proc_read,
4441 .open = proc_stats_open, 4441 .open = proc_stats_open,
4442 .release = proc_close 4442 .release = proc_close
4443}; 4443};
4444 4444
4445static struct file_operations proc_status_ops = { 4445static const struct file_operations proc_status_ops = {
4446 .read = proc_read, 4446 .read = proc_read,
4447 .open = proc_status_open, 4447 .open = proc_status_open,
4448 .release = proc_close 4448 .release = proc_close
4449}; 4449};
4450 4450
4451static struct file_operations proc_SSID_ops = { 4451static const struct file_operations proc_SSID_ops = {
4452 .read = proc_read, 4452 .read = proc_read,
4453 .write = proc_write, 4453 .write = proc_write,
4454 .open = proc_SSID_open, 4454 .open = proc_SSID_open,
4455 .release = proc_close 4455 .release = proc_close
4456}; 4456};
4457 4457
4458static struct file_operations proc_BSSList_ops = { 4458static const struct file_operations proc_BSSList_ops = {
4459 .read = proc_read, 4459 .read = proc_read,
4460 .write = proc_write, 4460 .write = proc_write,
4461 .open = proc_BSSList_open, 4461 .open = proc_BSSList_open,
4462 .release = proc_close 4462 .release = proc_close
4463}; 4463};
4464 4464
4465static struct file_operations proc_APList_ops = { 4465static const struct file_operations proc_APList_ops = {
4466 .read = proc_read, 4466 .read = proc_read,
4467 .write = proc_write, 4467 .write = proc_write,
4468 .open = proc_APList_open, 4468 .open = proc_APList_open,
4469 .release = proc_close 4469 .release = proc_close
4470}; 4470};
4471 4471
4472static struct file_operations proc_config_ops = { 4472static const struct file_operations proc_config_ops = {
4473 .read = proc_read, 4473 .read = proc_read,
4474 .write = proc_write, 4474 .write = proc_write,
4475 .open = proc_config_open, 4475 .open = proc_config_open,
4476 .release = proc_close 4476 .release = proc_close
4477}; 4477};
4478 4478
4479static struct file_operations proc_wepkey_ops = { 4479static const struct file_operations proc_wepkey_ops = {
4480 .read = proc_read, 4480 .read = proc_read,
4481 .write = proc_write, 4481 .write = proc_write,
4482 .open = proc_wepkey_open, 4482 .open = proc_wepkey_open,
diff --git a/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
index b9df06a06ea..35dbe455451 100644
--- a/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
+++ b/drivers/net/wireless/bcm43xx/bcm43xx_debugfs.c
@@ -355,37 +355,37 @@ out_up:
355#undef fappend 355#undef fappend
356 356
357 357
358static struct file_operations devinfo_fops = { 358static const struct file_operations devinfo_fops = {
359 .read = devinfo_read_file, 359 .read = devinfo_read_file,
360 .write = write_file_dummy, 360 .write = write_file_dummy,
361 .open = open_file_generic, 361 .open = open_file_generic,
362}; 362};
363 363
364static struct file_operations spromdump_fops = { 364static const struct file_operations spromdump_fops = {
365 .read = spromdump_read_file, 365 .read = spromdump_read_file,
366 .write = write_file_dummy, 366 .write = write_file_dummy,
367 .open = open_file_generic, 367 .open = open_file_generic,
368}; 368};
369 369
370static struct file_operations drvinfo_fops = { 370static const struct file_operations drvinfo_fops = {
371 .read = drvinfo_read_file, 371 .read = drvinfo_read_file,
372 .write = write_file_dummy, 372 .write = write_file_dummy,
373 .open = open_file_generic, 373 .open = open_file_generic,
374}; 374};
375 375
376static struct file_operations tsf_fops = { 376static const struct file_operations tsf_fops = {
377 .read = tsf_read_file, 377 .read = tsf_read_file,
378 .write = tsf_write_file, 378 .write = tsf_write_file,
379 .open = open_file_generic, 379 .open = open_file_generic,
380}; 380};
381 381
382static struct file_operations txstat_fops = { 382static const struct file_operations txstat_fops = {
383 .read = txstat_read_file, 383 .read = txstat_read_file,
384 .write = write_file_dummy, 384 .write = write_file_dummy,
385 .open = open_file_generic, 385 .open = open_file_generic,
386}; 386};
387 387
388static struct file_operations restart_fops = { 388static const struct file_operations restart_fops = {
389 .write = restart_write_file, 389 .write = restart_write_file,
390 .open = open_file_generic, 390 .open = open_file_generic,
391}; 391};
diff --git a/drivers/net/wireless/strip.c b/drivers/net/wireless/strip.c
index ce3a8bac66f..f5ce1c6063d 100644
--- a/drivers/net/wireless/strip.c
+++ b/drivers/net/wireless/strip.c
@@ -1160,7 +1160,7 @@ static int strip_seq_open(struct inode *inode, struct file *file)
1160 return seq_open(file, &strip_seq_ops); 1160 return seq_open(file, &strip_seq_ops);
1161} 1161}
1162 1162
1163static struct file_operations strip_seq_fops = { 1163static const struct file_operations strip_seq_fops = {
1164 .owner = THIS_MODULE, 1164 .owner = THIS_MODULE,
1165 .open = strip_seq_open, 1165 .open = strip_seq_open,
1166 .read = seq_read, 1166 .read = seq_read,
diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
index 04d641714d3..00e937e9240 100644
--- a/drivers/oprofile/event_buffer.c
+++ b/drivers/oprofile/event_buffer.c
@@ -181,7 +181,7 @@ out:
181 return retval; 181 return retval;
182} 182}
183 183
184struct file_operations event_buffer_fops = { 184const struct file_operations event_buffer_fops = {
185 .open = event_buffer_open, 185 .open = event_buffer_open,
186 .release = event_buffer_release, 186 .release = event_buffer_release,
187 .read = event_buffer_read, 187 .read = event_buffer_read,
diff --git a/drivers/oprofile/event_buffer.h b/drivers/oprofile/event_buffer.h
index 92416276e57..9b6a4ebd03e 100644
--- a/drivers/oprofile/event_buffer.h
+++ b/drivers/oprofile/event_buffer.h
@@ -41,7 +41,7 @@ void wake_up_buffer_waiter(void);
41/* add data to the event buffer */ 41/* add data to the event buffer */
42void add_event_entry(unsigned long data); 42void add_event_entry(unsigned long data);
43 43
44extern struct file_operations event_buffer_fops; 44extern const struct file_operations event_buffer_fops;
45 45
46/* mutex between sync_cpu_buffers() and the 46/* mutex between sync_cpu_buffers() and the
47 * file reading code. 47 * file reading code.
diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
index a72006c08f2..ef953ba5ab6 100644
--- a/drivers/oprofile/oprofile_files.c
+++ b/drivers/oprofile/oprofile_files.c
@@ -44,7 +44,7 @@ static ssize_t depth_write(struct file * file, char const __user * buf, size_t c
44} 44}
45 45
46 46
47static struct file_operations depth_fops = { 47static const struct file_operations depth_fops = {
48 .read = depth_read, 48 .read = depth_read,
49 .write = depth_write 49 .write = depth_write
50}; 50};
@@ -56,7 +56,7 @@ static ssize_t pointer_size_read(struct file * file, char __user * buf, size_t c
56} 56}
57 57
58 58
59static struct file_operations pointer_size_fops = { 59static const struct file_operations pointer_size_fops = {
60 .read = pointer_size_read, 60 .read = pointer_size_read,
61}; 61};
62 62
@@ -67,7 +67,7 @@ static ssize_t cpu_type_read(struct file * file, char __user * buf, size_t count
67} 67}
68 68
69 69
70static struct file_operations cpu_type_fops = { 70static const struct file_operations cpu_type_fops = {
71 .read = cpu_type_read, 71 .read = cpu_type_read,
72}; 72};
73 73
@@ -101,7 +101,7 @@ static ssize_t enable_write(struct file * file, char const __user * buf, size_t
101} 101}
102 102
103 103
104static struct file_operations enable_fops = { 104static const struct file_operations enable_fops = {
105 .read = enable_read, 105 .read = enable_read,
106 .write = enable_write, 106 .write = enable_write,
107}; 107};
@@ -114,7 +114,7 @@ static ssize_t dump_write(struct file * file, char const __user * buf, size_t co
114} 114}
115 115
116 116
117static struct file_operations dump_fops = { 117static const struct file_operations dump_fops = {
118 .write = dump_write, 118 .write = dump_write,
119}; 119};
120 120
diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
index 5756401fb15..6e67b42ca46 100644
--- a/drivers/oprofile/oprofilefs.c
+++ b/drivers/oprofile/oprofilefs.c
@@ -115,14 +115,14 @@ static int default_open(struct inode * inode, struct file * filp)
115} 115}
116 116
117 117
118static struct file_operations ulong_fops = { 118static const struct file_operations ulong_fops = {
119 .read = ulong_read_file, 119 .read = ulong_read_file,
120 .write = ulong_write_file, 120 .write = ulong_write_file,
121 .open = default_open, 121 .open = default_open,
122}; 122};
123 123
124 124
125static struct file_operations ulong_ro_fops = { 125static const struct file_operations ulong_ro_fops = {
126 .read = ulong_read_file, 126 .read = ulong_read_file,
127 .open = default_open, 127 .open = default_open,
128}; 128};
@@ -182,7 +182,7 @@ static ssize_t atomic_read_file(struct file * file, char __user * buf, size_t co
182} 182}
183 183
184 184
185static struct file_operations atomic_ro_fops = { 185static const struct file_operations atomic_ro_fops = {
186 .read = atomic_read_file, 186 .read = atomic_read_file,
187 .open = default_open, 187 .open = default_open,
188}; 188};
diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
index fe3f5f5365c..894fdb9d44c 100644
--- a/drivers/parisc/ccio-dma.c
+++ b/drivers/parisc/ccio-dma.c
@@ -1091,7 +1091,7 @@ static int ccio_proc_info_open(struct inode *inode, struct file *file)
1091 return single_open(file, &ccio_proc_info, NULL); 1091 return single_open(file, &ccio_proc_info, NULL);
1092} 1092}
1093 1093
1094static struct file_operations ccio_proc_info_fops = { 1094static const struct file_operations ccio_proc_info_fops = {
1095 .owner = THIS_MODULE, 1095 .owner = THIS_MODULE,
1096 .open = ccio_proc_info_open, 1096 .open = ccio_proc_info_open,
1097 .read = seq_read, 1097 .read = seq_read,
@@ -1127,7 +1127,7 @@ static int ccio_proc_bitmap_open(struct inode *inode, struct file *file)
1127 return single_open(file, &ccio_proc_bitmap_info, NULL); 1127 return single_open(file, &ccio_proc_bitmap_info, NULL);
1128} 1128}
1129 1129
1130static struct file_operations ccio_proc_bitmap_fops = { 1130static const struct file_operations ccio_proc_bitmap_fops = {
1131 .owner = THIS_MODULE, 1131 .owner = THIS_MODULE,
1132 .open = ccio_proc_bitmap_open, 1132 .open = ccio_proc_bitmap_open,
1133 .read = seq_read, 1133 .read = seq_read,
diff --git a/drivers/parisc/eisa_eeprom.c b/drivers/parisc/eisa_eeprom.c
index e13aafa70bf..86e9c84a965 100644
--- a/drivers/parisc/eisa_eeprom.c
+++ b/drivers/parisc/eisa_eeprom.c
@@ -97,7 +97,7 @@ static int eisa_eeprom_release(struct inode *inode, struct file *file)
97/* 97/*
98 * The various file operations we support. 98 * The various file operations we support.
99 */ 99 */
100static struct file_operations eisa_eeprom_fops = { 100static const struct file_operations eisa_eeprom_fops = {
101 .owner = THIS_MODULE, 101 .owner = THIS_MODULE,
102 .llseek = eisa_eeprom_llseek, 102 .llseek = eisa_eeprom_llseek,
103 .read = eisa_eeprom_read, 103 .read = eisa_eeprom_read,
diff --git a/drivers/parisc/led.c b/drivers/parisc/led.c
index 8dac2ba82bb..9a731c101d1 100644
--- a/drivers/parisc/led.c
+++ b/drivers/parisc/led.c
@@ -252,7 +252,6 @@ static int __init led_create_procfs(void)
252 proc_pdc_root->owner = THIS_MODULE; 252 proc_pdc_root->owner = THIS_MODULE;
253 ent = create_proc_entry("led", S_IFREG|S_IRUGO|S_IWUSR, proc_pdc_root); 253 ent = create_proc_entry("led", S_IFREG|S_IRUGO|S_IWUSR, proc_pdc_root);
254 if (!ent) return -1; 254 if (!ent) return -1;
255 ent->nlink = 1;
256 ent->data = (void *)LED_NOLCD; /* LED */ 255 ent->data = (void *)LED_NOLCD; /* LED */
257 ent->read_proc = led_proc_read; 256 ent->read_proc = led_proc_read;
258 ent->write_proc = led_proc_write; 257 ent->write_proc = led_proc_write;
@@ -262,7 +261,6 @@ static int __init led_create_procfs(void)
262 { 261 {
263 ent = create_proc_entry("lcd", S_IFREG|S_IRUGO|S_IWUSR, proc_pdc_root); 262 ent = create_proc_entry("lcd", S_IFREG|S_IRUGO|S_IWUSR, proc_pdc_root);
264 if (!ent) return -1; 263 if (!ent) return -1;
265 ent->nlink = 1;
266 ent->data = (void *)LED_HASLCD; /* LCD */ 264 ent->data = (void *)LED_HASLCD; /* LCD */
267 ent->read_proc = led_proc_read; 265 ent->read_proc = led_proc_read;
268 ent->write_proc = led_proc_write; 266 ent->write_proc = led_proc_write;
diff --git a/drivers/parisc/sba_iommu.c b/drivers/parisc/sba_iommu.c
index f1e7ccd5475..76a29dadd51 100644
--- a/drivers/parisc/sba_iommu.c
+++ b/drivers/parisc/sba_iommu.c
@@ -1799,7 +1799,7 @@ sba_proc_open(struct inode *i, struct file *f)
1799 return single_open(f, &sba_proc_info, NULL); 1799 return single_open(f, &sba_proc_info, NULL);
1800} 1800}
1801 1801
1802static struct file_operations sba_proc_fops = { 1802static const struct file_operations sba_proc_fops = {
1803 .owner = THIS_MODULE, 1803 .owner = THIS_MODULE,
1804 .open = sba_proc_open, 1804 .open = sba_proc_open,
1805 .read = seq_read, 1805 .read = seq_read,
@@ -1831,7 +1831,7 @@ sba_proc_bitmap_open(struct inode *i, struct file *f)
1831 return single_open(f, &sba_proc_bitmap_info, NULL); 1831 return single_open(f, &sba_proc_bitmap_info, NULL);
1832} 1832}
1833 1833
1834static struct file_operations sba_proc_bitmap_fops = { 1834static const struct file_operations sba_proc_bitmap_fops = {
1835 .owner = THIS_MODULE, 1835 .owner = THIS_MODULE,
1836 .open = sba_proc_bitmap_open, 1836 .open = sba_proc_bitmap_open,
1837 .read = seq_read, 1837 .read = seq_read,
diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig
index 3cfb0a3575e..5ea5bc70cb8 100644
--- a/drivers/pci/Kconfig
+++ b/drivers/pci/Kconfig
@@ -4,7 +4,7 @@
4config PCI_MSI 4config PCI_MSI
5 bool "Message Signaled Interrupts (MSI and MSI-X)" 5 bool "Message Signaled Interrupts (MSI and MSI-X)"
6 depends on PCI 6 depends on PCI
7 depends on (X86_LOCAL_APIC && X86_IO_APIC) || IA64 7 depends on (X86_LOCAL_APIC && X86_IO_APIC) || IA64 || SPARC64
8 help 8 help
9 This allows device drivers to enable MSI (Message Signaled 9 This allows device drivers to enable MSI (Message Signaled
10 Interrupts). Message Signaled Interrupts enable a device to 10 Interrupts). Message Signaled Interrupts enable a device to
diff --git a/drivers/pci/hotplug/cpqphp_sysfs.c b/drivers/pci/hotplug/cpqphp_sysfs.c
index 634f74d919d..a13abf55d78 100644
--- a/drivers/pci/hotplug/cpqphp_sysfs.c
+++ b/drivers/pci/hotplug/cpqphp_sysfs.c
@@ -202,7 +202,7 @@ static int release(struct inode *inode, struct file *file)
202 return 0; 202 return 0;
203} 203}
204 204
205static struct file_operations debug_ops = { 205static const struct file_operations debug_ops = {
206 .owner = THIS_MODULE, 206 .owner = THIS_MODULE,
207 .open = open, 207 .open = open,
208 .llseek = lseek, 208 .llseek = lseek,
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 84c757ba066..8b44cff2c17 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -744,6 +744,104 @@ int pci_enable_device(struct pci_dev *dev)
744 return pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1); 744 return pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
745} 745}
746 746
747/*
748 * Managed PCI resources. This manages device on/off, intx/msi/msix
749 * on/off and BAR regions. pci_dev itself records msi/msix status, so
750 * there's no need to track it separately. pci_devres is initialized
751 * when a device is enabled using managed PCI device enable interface.
752 */
753struct pci_devres {
754 unsigned int disable:1;
755 unsigned int orig_intx:1;
756 unsigned int restore_intx:1;
757 u32 region_mask;
758};
759
760static void pcim_release(struct device *gendev, void *res)
761{
762 struct pci_dev *dev = container_of(gendev, struct pci_dev, dev);
763 struct pci_devres *this = res;
764 int i;
765
766 if (dev->msi_enabled)
767 pci_disable_msi(dev);
768 if (dev->msix_enabled)
769 pci_disable_msix(dev);
770
771 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
772 if (this->region_mask & (1 << i))
773 pci_release_region(dev, i);
774
775 if (this->restore_intx)
776 pci_intx(dev, this->orig_intx);
777
778 if (this->disable)
779 pci_disable_device(dev);
780}
781
782static struct pci_devres * get_pci_dr(struct pci_dev *pdev)
783{
784 struct pci_devres *dr, *new_dr;
785
786 dr = devres_find(&pdev->dev, pcim_release, NULL, NULL);
787 if (dr)
788 return dr;
789
790 new_dr = devres_alloc(pcim_release, sizeof(*new_dr), GFP_KERNEL);
791 if (!new_dr)
792 return NULL;
793 return devres_get(&pdev->dev, new_dr, NULL, NULL);
794}
795
796static struct pci_devres * find_pci_dr(struct pci_dev *pdev)
797{
798 if (pci_is_managed(pdev))
799 return devres_find(&pdev->dev, pcim_release, NULL, NULL);
800 return NULL;
801}
802
803/**
804 * pcim_enable_device - Managed pci_enable_device()
805 * @pdev: PCI device to be initialized
806 *
807 * Managed pci_enable_device().
808 */
809int pcim_enable_device(struct pci_dev *pdev)
810{
811 struct pci_devres *dr;
812 int rc;
813
814 dr = get_pci_dr(pdev);
815 if (unlikely(!dr))
816 return -ENOMEM;
817 WARN_ON(!!dr->disable);
818
819 rc = pci_enable_device(pdev);
820 if (!rc) {
821 pdev->is_managed = 1;
822 dr->disable = 1;
823 }
824 return rc;
825}
826
827/**
828 * pcim_pin_device - Pin managed PCI device
829 * @pdev: PCI device to pin
830 *
831 * Pin managed PCI device @pdev. Pinned device won't be disabled on
832 * driver detach. @pdev must have been enabled with
833 * pcim_enable_device().
834 */
835void pcim_pin_device(struct pci_dev *pdev)
836{
837 struct pci_devres *dr;
838
839 dr = find_pci_dr(pdev);
840 WARN_ON(!dr || !dr->disable);
841 if (dr)
842 dr->disable = 0;
843}
844
747/** 845/**
748 * pcibios_disable_device - disable arch specific PCI resources for device dev 846 * pcibios_disable_device - disable arch specific PCI resources for device dev
749 * @dev: the PCI device to disable 847 * @dev: the PCI device to disable
@@ -767,8 +865,13 @@ void __attribute__ ((weak)) pcibios_disable_device (struct pci_dev *dev) {}
767void 865void
768pci_disable_device(struct pci_dev *dev) 866pci_disable_device(struct pci_dev *dev)
769{ 867{
868 struct pci_devres *dr;
770 u16 pci_command; 869 u16 pci_command;
771 870
871 dr = find_pci_dr(dev);
872 if (dr)
873 dr->disable = 0;
874
772 if (atomic_sub_return(1, &dev->enable_cnt) != 0) 875 if (atomic_sub_return(1, &dev->enable_cnt) != 0)
773 return; 876 return;
774 877
@@ -867,6 +970,8 @@ pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge)
867 */ 970 */
868void pci_release_region(struct pci_dev *pdev, int bar) 971void pci_release_region(struct pci_dev *pdev, int bar)
869{ 972{
973 struct pci_devres *dr;
974
870 if (pci_resource_len(pdev, bar) == 0) 975 if (pci_resource_len(pdev, bar) == 0)
871 return; 976 return;
872 if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) 977 if (pci_resource_flags(pdev, bar) & IORESOURCE_IO)
@@ -875,6 +980,10 @@ void pci_release_region(struct pci_dev *pdev, int bar)
875 else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM) 980 else if (pci_resource_flags(pdev, bar) & IORESOURCE_MEM)
876 release_mem_region(pci_resource_start(pdev, bar), 981 release_mem_region(pci_resource_start(pdev, bar),
877 pci_resource_len(pdev, bar)); 982 pci_resource_len(pdev, bar));
983
984 dr = find_pci_dr(pdev);
985 if (dr)
986 dr->region_mask &= ~(1 << bar);
878} 987}
879 988
880/** 989/**
@@ -893,6 +1002,8 @@ void pci_release_region(struct pci_dev *pdev, int bar)
893 */ 1002 */
894int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name) 1003int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
895{ 1004{
1005 struct pci_devres *dr;
1006
896 if (pci_resource_len(pdev, bar) == 0) 1007 if (pci_resource_len(pdev, bar) == 0)
897 return 0; 1008 return 0;
898 1009
@@ -906,7 +1017,11 @@ int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
906 pci_resource_len(pdev, bar), res_name)) 1017 pci_resource_len(pdev, bar), res_name))
907 goto err_out; 1018 goto err_out;
908 } 1019 }
909 1020
1021 dr = find_pci_dr(pdev);
1022 if (dr)
1023 dr->region_mask |= 1 << bar;
1024
910 return 0; 1025 return 0;
911 1026
912err_out: 1027err_out:
@@ -1144,7 +1259,15 @@ pci_intx(struct pci_dev *pdev, int enable)
1144 } 1259 }
1145 1260
1146 if (new != pci_command) { 1261 if (new != pci_command) {
1262 struct pci_devres *dr;
1263
1147 pci_write_config_word(pdev, PCI_COMMAND, new); 1264 pci_write_config_word(pdev, PCI_COMMAND, new);
1265
1266 dr = find_pci_dr(pdev);
1267 if (dr && !dr->restore_intx) {
1268 dr->restore_intx = 1;
1269 dr->orig_intx = !enable;
1270 }
1148 } 1271 }
1149} 1272}
1150 1273
@@ -1226,6 +1349,8 @@ device_initcall(pci_init);
1226EXPORT_SYMBOL_GPL(pci_restore_bars); 1349EXPORT_SYMBOL_GPL(pci_restore_bars);
1227EXPORT_SYMBOL(pci_enable_device_bars); 1350EXPORT_SYMBOL(pci_enable_device_bars);
1228EXPORT_SYMBOL(pci_enable_device); 1351EXPORT_SYMBOL(pci_enable_device);
1352EXPORT_SYMBOL(pcim_enable_device);
1353EXPORT_SYMBOL(pcim_pin_device);
1229EXPORT_SYMBOL(pci_disable_device); 1354EXPORT_SYMBOL(pci_disable_device);
1230EXPORT_SYMBOL(pci_find_capability); 1355EXPORT_SYMBOL(pci_find_capability);
1231EXPORT_SYMBOL(pci_bus_find_capability); 1356EXPORT_SYMBOL(pci_bus_find_capability);
diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
index 4a6760a3b31..ed87aa59f0b 100644
--- a/drivers/pci/proc.c
+++ b/drivers/pci/proc.c
@@ -287,7 +287,7 @@ static int proc_bus_pci_release(struct inode *inode, struct file *file)
287} 287}
288#endif /* HAVE_PCI_MMAP */ 288#endif /* HAVE_PCI_MMAP */
289 289
290static struct file_operations proc_bus_pci_operations = { 290static const struct file_operations proc_bus_pci_operations = {
291 .llseek = proc_bus_pci_lseek, 291 .llseek = proc_bus_pci_lseek,
292 .read = proc_bus_pci_read, 292 .read = proc_bus_pci_read,
293 .write = proc_bus_pci_write, 293 .write = proc_bus_pci_write,
@@ -456,7 +456,7 @@ static int proc_bus_pci_dev_open(struct inode *inode, struct file *file)
456{ 456{
457 return seq_open(file, &proc_bus_pci_devices_op); 457 return seq_open(file, &proc_bus_pci_devices_op);
458} 458}
459static struct file_operations proc_bus_pci_dev_operations = { 459static const struct file_operations proc_bus_pci_dev_operations = {
460 .open = proc_bus_pci_dev_open, 460 .open = proc_bus_pci_dev_open,
461 .read = seq_read, 461 .read = seq_read,
462 .llseek = seq_lseek, 462 .llseek = seq_lseek,
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 11217bda4b9..1e6eda25c0d 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -871,7 +871,7 @@ static void __devinit quirk_sb600_sata(struct pci_dev *pdev)
871 pci_write_config_byte(pdev, 0xa, 6); 871 pci_write_config_byte(pdev, 0xa, 6);
872 pci_write_config_byte(pdev, 0x40, tmp); 872 pci_write_config_byte(pdev, 0x40, tmp);
873 873
874 pdev->class = 0x010601; 874 pdev->class = PCI_CLASS_STORAGE_SATA_AHCI;
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);
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
index 88494149e91..27523c5f4da 100644
--- a/drivers/pcmcia/pcmcia_ioctl.c
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -765,7 +765,7 @@ free_out:
765 765
766/*====================================================================*/ 766/*====================================================================*/
767 767
768static struct file_operations ds_fops = { 768static const struct file_operations ds_fops = {
769 .owner = THIS_MODULE, 769 .owner = THIS_MODULE,
770 .open = ds_open, 770 .open = ds_open,
771 .release = ds_release, 771 .release = ds_release,
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h
index 6b8c4cfd02a..31a633f6554 100644
--- a/drivers/pnp/base.h
+++ b/drivers/pnp/base.h
@@ -1,4 +1,3 @@
1extern struct bus_type pnp_bus_type;
2extern spinlock_t pnp_lock; 1extern spinlock_t pnp_lock;
3void *pnp_alloc(long size); 2void *pnp_alloc(long size);
4int pnp_interface_attach_device(struct pnp_dev *dev); 3int pnp_interface_attach_device(struct pnp_dev *dev);
diff --git a/drivers/pnp/isapnp/proc.c b/drivers/pnp/isapnp/proc.c
index d21f3c1e72f..40b724ebe23 100644
--- a/drivers/pnp/isapnp/proc.c
+++ b/drivers/pnp/isapnp/proc.c
@@ -85,7 +85,7 @@ static ssize_t isapnp_proc_bus_read(struct file *file, char __user *buf, size_t
85 return nbytes; 85 return nbytes;
86} 86}
87 87
88static struct file_operations isapnp_proc_bus_file_operations = 88static const struct file_operations isapnp_proc_bus_file_operations =
89{ 89{
90 .llseek = isapnp_proc_bus_lseek, 90 .llseek = isapnp_proc_bus_lseek,
91 .read = isapnp_proc_bus_read, 91 .read = isapnp_proc_bus_read,
diff --git a/drivers/pnp/pnpbios/rsparser.c b/drivers/pnp/pnpbios/rsparser.c
index 95b79685a9d..3c2ab8394e3 100644
--- a/drivers/pnp/pnpbios/rsparser.c
+++ b/drivers/pnp/pnpbios/rsparser.c
@@ -530,7 +530,6 @@ pnpbios_parse_compatible_ids(unsigned char *p, unsigned char *end, struct pnp_de
530 dev_id = kzalloc(sizeof (struct pnp_id), GFP_KERNEL); 530 dev_id = kzalloc(sizeof (struct pnp_id), GFP_KERNEL);
531 if (!dev_id) 531 if (!dev_id)
532 return NULL; 532 return NULL;
533 memset(dev_id, 0, sizeof(struct pnp_id));
534 pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] << 24,id); 533 pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] << 24,id);
535 memcpy(&dev_id->id, id, 7); 534 memcpy(&dev_id->id, id, 7);
536 pnp_add_id(dev_id, dev); 535 pnp_add_id(dev_id, dev);
diff --git a/drivers/ps3/Makefile b/drivers/ps3/Makefile
index d547cf50ca9..96958c03cf6 100644
--- a/drivers/ps3/Makefile
+++ b/drivers/ps3/Makefile
@@ -1 +1,2 @@
1obj-$(CONFIG_PS3_VUART) += vuart.o 1obj-$(CONFIG_PS3_VUART) += vuart.o
2obj-$(CONFIG_PS3_PS3AV) += ps3av.o ps3av_cmd.o
diff --git a/drivers/ps3/ps3av.c b/drivers/ps3/ps3av.c
new file mode 100644
index 00000000000..1926b4d3e1f
--- /dev/null
+++ b/drivers/ps3/ps3av.c
@@ -0,0 +1,974 @@
1/*
2 * Copyright (C) 2006 Sony Computer Entertainment Inc.
3 * Copyright 2006, 2007 Sony Corporation
4 *
5 * AV backend support for PS3
6 *
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
9 * by the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <linux/module.h>
22#include <linux/delay.h>
23#include <linux/notifier.h>
24#include <linux/reboot.h>
25#include <linux/kernel.h>
26#include <linux/ioctl.h>
27#include <asm/lv1call.h>
28#include <asm/ps3av.h>
29#include <asm/ps3.h>
30
31#include "vuart.h"
32
33#define BUFSIZE 4096 /* vuart buf size */
34#define PS3AV_BUF_SIZE 512 /* max packet size */
35
36static int timeout = 5000; /* in msec ( 5 sec ) */
37module_param(timeout, int, 0644);
38
39static struct ps3av ps3av;
40
41static struct ps3_vuart_port_device ps3av_dev = {
42 .match_id = PS3_MATCH_ID_AV_SETTINGS
43};
44
45/* color space */
46#define YUV444 PS3AV_CMD_VIDEO_CS_YUV444_8
47#define RGB8 PS3AV_CMD_VIDEO_CS_RGB_8
48/* format */
49#define XRGB PS3AV_CMD_VIDEO_FMT_X8R8G8B8
50/* aspect */
51#define A_N PS3AV_CMD_AV_ASPECT_4_3
52#define A_W PS3AV_CMD_AV_ASPECT_16_9
53static const struct avset_video_mode {
54 u32 cs;
55 u32 fmt;
56 u32 vid;
57 u32 aspect;
58 u32 x;
59 u32 y;
60 u32 interlace;
61 u32 freq;
62} video_mode_table[] = {
63 { 0, }, /* auto */
64 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_480I, A_N, 720, 480, 1, 60},
65 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_480P, A_N, 720, 480, 0, 60},
66 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_720P_60HZ, A_N, 1280, 720, 0, 60},
67 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080I_60HZ, A_W, 1920, 1080, 1, 60},
68 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080P_60HZ, A_W, 1920, 1080, 0, 60},
69 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_576I, A_N, 720, 576, 1, 50},
70 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_576P, A_N, 720, 576, 0, 50},
71 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_720P_50HZ, A_N, 1280, 720, 0, 50},
72 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080I_50HZ, A_W, 1920, 1080, 1, 50},
73 {YUV444, XRGB, PS3AV_CMD_VIDEO_VID_1080P_50HZ, A_W, 1920, 1080, 0, 50},
74 { RGB8, XRGB, PS3AV_CMD_VIDEO_VID_WXGA, A_W, 1280, 768, 0, 60},
75 { RGB8, XRGB, PS3AV_CMD_VIDEO_VID_SXGA, A_N, 1280, 1024, 0, 60},
76 { RGB8, XRGB, PS3AV_CMD_VIDEO_VID_WUXGA, A_W, 1920, 1200, 0, 60},
77};
78
79/* supported CIDs */
80static u32 cmd_table[] = {
81 /* init */
82 PS3AV_CID_AV_INIT,
83 PS3AV_CID_AV_FIN,
84 PS3AV_CID_VIDEO_INIT,
85 PS3AV_CID_AUDIO_INIT,
86
87 /* set */
88 PS3AV_CID_AV_ENABLE_EVENT,
89 PS3AV_CID_AV_DISABLE_EVENT,
90
91 PS3AV_CID_AV_VIDEO_CS,
92 PS3AV_CID_AV_VIDEO_MUTE,
93 PS3AV_CID_AV_VIDEO_DISABLE_SIG,
94 PS3AV_CID_AV_AUDIO_PARAM,
95 PS3AV_CID_AV_AUDIO_MUTE,
96 PS3AV_CID_AV_HDMI_MODE,
97 PS3AV_CID_AV_TV_MUTE,
98
99 PS3AV_CID_VIDEO_MODE,
100 PS3AV_CID_VIDEO_FORMAT,
101 PS3AV_CID_VIDEO_PITCH,
102
103 PS3AV_CID_AUDIO_MODE,
104 PS3AV_CID_AUDIO_MUTE,
105 PS3AV_CID_AUDIO_ACTIVE,
106 PS3AV_CID_AUDIO_INACTIVE,
107 PS3AV_CID_AVB_PARAM,
108
109 /* get */
110 PS3AV_CID_AV_GET_HW_CONF,
111 PS3AV_CID_AV_GET_MONITOR_INFO,
112
113 /* event */
114 PS3AV_CID_EVENT_UNPLUGGED,
115 PS3AV_CID_EVENT_PLUGGED,
116 PS3AV_CID_EVENT_HDCP_DONE,
117 PS3AV_CID_EVENT_HDCP_FAIL,
118 PS3AV_CID_EVENT_HDCP_AUTH,
119 PS3AV_CID_EVENT_HDCP_ERROR,
120
121 0
122};
123
124#define PS3AV_EVENT_CMD_MASK 0x10000000
125#define PS3AV_EVENT_ID_MASK 0x0000ffff
126#define PS3AV_CID_MASK 0xffffffff
127#define PS3AV_REPLY_BIT 0x80000000
128
129#define ps3av_event_get_port_id(cid) ((cid >> 16) & 0xff)
130
131static u32 *ps3av_search_cmd_table(u32 cid, u32 mask)
132{
133 u32 *table;
134 int i;
135
136 table = cmd_table;
137 for (i = 0;; table++, i++) {
138 if ((*table & mask) == (cid & mask))
139 break;
140 if (*table == 0)
141 return NULL;
142 }
143 return table;
144}
145
146static int ps3av_parse_event_packet(const struct ps3av_reply_hdr *hdr)
147{
148 u32 *table;
149
150 if (hdr->cid & PS3AV_EVENT_CMD_MASK) {
151 table = ps3av_search_cmd_table(hdr->cid, PS3AV_EVENT_CMD_MASK);
152 if (table)
153 dev_dbg(&ps3av_dev.core,
154 "recv event packet cid:%08x port:0x%x size:%d\n",
155 hdr->cid, ps3av_event_get_port_id(hdr->cid),
156 hdr->size);
157 else
158 printk(KERN_ERR
159 "%s: failed event packet, cid:%08x size:%d\n",
160 __FUNCTION__, hdr->cid, hdr->size);
161 return 1; /* receive event packet */
162 }
163 return 0;
164}
165
166static int ps3av_send_cmd_pkt(const struct ps3av_send_hdr *send_buf,
167 struct ps3av_reply_hdr *recv_buf, int write_len,
168 int read_len)
169{
170 int res;
171 u32 cmd;
172 int event;
173
174 if (!ps3av.available)
175 return -ENODEV;
176
177 /* send pkt */
178 res = ps3av_vuart_write(ps3av.dev, send_buf, write_len);
179 if (res < 0) {
180 dev_dbg(&ps3av_dev.core,
181 "%s: ps3av_vuart_write() failed (result=%d)\n",
182 __FUNCTION__, res);
183 return res;
184 }
185
186 /* recv pkt */
187 cmd = send_buf->cid;
188 do {
189 /* read header */
190 res = ps3av_vuart_read(ps3av.dev, recv_buf, PS3AV_HDR_SIZE,
191 timeout);
192 if (res != PS3AV_HDR_SIZE) {
193 dev_dbg(&ps3av_dev.core,
194 "%s: ps3av_vuart_read() failed (result=%d)\n",
195 __FUNCTION__, res);
196 return res;
197 }
198
199 /* read body */
200 res = ps3av_vuart_read(ps3av.dev, &recv_buf->cid,
201 recv_buf->size, timeout);
202 if (res < 0) {
203 dev_dbg(&ps3av_dev.core,
204 "%s: ps3av_vuart_read() failed (result=%d)\n",
205 __FUNCTION__, res);
206 return res;
207 }
208 res += PS3AV_HDR_SIZE; /* total len */
209 event = ps3av_parse_event_packet(recv_buf);
210 /* ret > 0 event packet */
211 } while (event);
212
213 if ((cmd | PS3AV_REPLY_BIT) != recv_buf->cid) {
214 dev_dbg(&ps3av_dev.core, "%s: reply err (result=%x)\n",
215 __FUNCTION__, recv_buf->cid);
216 return -EINVAL;
217 }
218
219 return 0;
220}
221
222static int ps3av_process_reply_packet(struct ps3av_send_hdr *cmd_buf,
223 const struct ps3av_reply_hdr *recv_buf,
224 int user_buf_size)
225{
226 int return_len;
227
228 if (recv_buf->version != PS3AV_VERSION) {
229 dev_dbg(&ps3av_dev.core, "reply_packet invalid version:%x\n",
230 recv_buf->version);
231 return -EFAULT;
232 }
233 return_len = recv_buf->size + PS3AV_HDR_SIZE;
234 if (return_len > user_buf_size)
235 return_len = user_buf_size;
236 memcpy(cmd_buf, recv_buf, return_len);
237 return 0; /* success */
238}
239
240void ps3av_set_hdr(u32 cid, u16 size, struct ps3av_send_hdr *hdr)
241{
242 hdr->version = PS3AV_VERSION;
243 hdr->size = size - PS3AV_HDR_SIZE;
244 hdr->cid = cid;
245}
246
247int ps3av_do_pkt(u32 cid, u16 send_len, size_t usr_buf_size,
248 struct ps3av_send_hdr *buf)
249{
250 int res = 0;
251 union {
252 struct ps3av_reply_hdr reply_hdr;
253 u8 raw[PS3AV_BUF_SIZE];
254 } recv_buf;
255
256 u32 *table;
257
258 BUG_ON(!ps3av.available);
259
260 if (down_interruptible(&ps3av.sem))
261 return -ERESTARTSYS;
262
263 table = ps3av_search_cmd_table(cid, PS3AV_CID_MASK);
264 BUG_ON(!table);
265 BUG_ON(send_len < PS3AV_HDR_SIZE);
266 BUG_ON(usr_buf_size < send_len);
267 BUG_ON(usr_buf_size > PS3AV_BUF_SIZE);
268
269 /* create header */
270 ps3av_set_hdr(cid, send_len, buf);
271
272 /* send packet via vuart */
273 res = ps3av_send_cmd_pkt(buf, &recv_buf.reply_hdr, send_len,
274 usr_buf_size);
275 if (res < 0) {
276 printk(KERN_ERR
277 "%s: ps3av_send_cmd_pkt() failed (result=%d)\n",
278 __FUNCTION__, res);
279 goto err;
280 }
281
282 /* process reply packet */
283 res = ps3av_process_reply_packet(buf, &recv_buf.reply_hdr,
284 usr_buf_size);
285 if (res < 0) {
286 printk(KERN_ERR "%s: put_return_status() failed (result=%d)\n",
287 __FUNCTION__, res);
288 goto err;
289 }
290
291 up(&ps3av.sem);
292 return 0;
293
294 err:
295 up(&ps3av.sem);
296 printk(KERN_ERR "%s: failed cid:%x res:%d\n", __FUNCTION__, cid, res);
297 return res;
298}
299
300static int ps3av_set_av_video_mute(u32 mute)
301{
302 int i, num_of_av_port, res;
303
304 num_of_av_port = ps3av.av_hw_conf.num_of_hdmi +
305 ps3av.av_hw_conf.num_of_avmulti;
306 /* video mute on */
307 for (i = 0; i < num_of_av_port; i++) {
308 res = ps3av_cmd_av_video_mute(1, &ps3av.av_port[i], mute);
309 if (res < 0)
310 return -1;
311 }
312
313 return 0;
314}
315
316static int ps3av_set_video_disable_sig(void)
317{
318 int i, num_of_hdmi_port, num_of_av_port, res;
319
320 num_of_hdmi_port = ps3av.av_hw_conf.num_of_hdmi;
321 num_of_av_port = ps3av.av_hw_conf.num_of_hdmi +
322 ps3av.av_hw_conf.num_of_avmulti;
323
324 /* tv mute */
325 for (i = 0; i < num_of_hdmi_port; i++) {
326 res = ps3av_cmd_av_tv_mute(ps3av.av_port[i],
327 PS3AV_CMD_MUTE_ON);
328 if (res < 0)
329 return -1;
330 }
331 msleep(100);
332
333 /* video mute on */
334 for (i = 0; i < num_of_av_port; i++) {
335 res = ps3av_cmd_av_video_disable_sig(ps3av.av_port[i]);
336 if (res < 0)
337 return -1;
338 if (i < num_of_hdmi_port) {
339 res = ps3av_cmd_av_tv_mute(ps3av.av_port[i],
340 PS3AV_CMD_MUTE_OFF);
341 if (res < 0)
342 return -1;
343 }
344 }
345 msleep(300);
346
347 return 0;
348}
349
350static int ps3av_set_audio_mute(u32 mute)
351{
352 int i, num_of_av_port, num_of_opt_port, res;
353
354 num_of_av_port = ps3av.av_hw_conf.num_of_hdmi +
355 ps3av.av_hw_conf.num_of_avmulti;
356 num_of_opt_port = ps3av.av_hw_conf.num_of_spdif;
357
358 for (i = 0; i < num_of_av_port; i++) {
359 res = ps3av_cmd_av_audio_mute(1, &ps3av.av_port[i], mute);
360 if (res < 0)
361 return -1;
362 }
363 for (i = 0; i < num_of_opt_port; i++) {
364 res = ps3av_cmd_audio_mute(1, &ps3av.opt_port[i], mute);
365 if (res < 0)
366 return -1;
367 }
368
369 return 0;
370}
371
372int ps3av_set_audio_mode(u32 ch, u32 fs, u32 word_bits, u32 format, u32 source)
373{
374 struct ps3av_pkt_avb_param avb_param;
375 int i, num_of_audio, vid, res;
376 struct ps3av_pkt_audio_mode audio_mode;
377 u32 len = 0;
378
379 num_of_audio = ps3av.av_hw_conf.num_of_hdmi +
380 ps3av.av_hw_conf.num_of_avmulti +
381 ps3av.av_hw_conf.num_of_spdif;
382
383 avb_param.num_of_video_pkt = 0;
384 avb_param.num_of_audio_pkt = PS3AV_AVB_NUM_AUDIO; /* always 0 */
385 avb_param.num_of_av_video_pkt = 0;
386 avb_param.num_of_av_audio_pkt = ps3av.av_hw_conf.num_of_hdmi;
387
388 vid = video_mode_table[ps3av.ps3av_mode].vid;
389
390 /* audio mute */
391 ps3av_set_audio_mute(PS3AV_CMD_MUTE_ON);
392
393 /* audio inactive */
394 res = ps3av_cmd_audio_active(0, ps3av.audio_port);
395 if (res < 0)
396 dev_dbg(&ps3av_dev.core,
397 "ps3av_cmd_audio_active OFF failed\n");
398
399 /* audio_pkt */
400 for (i = 0; i < num_of_audio; i++) {
401 ps3av_cmd_set_audio_mode(&audio_mode, ps3av.av_port[i], ch, fs,
402 word_bits, format, source);
403 if (i < ps3av.av_hw_conf.num_of_hdmi) {
404 /* hdmi only */
405 len += ps3av_cmd_set_av_audio_param(&avb_param.buf[len],
406 ps3av.av_port[i],
407 &audio_mode, vid);
408 }
409 /* audio_mode pkt should be sent separately */
410 res = ps3av_cmd_audio_mode(&audio_mode);
411 if (res < 0)
412 dev_dbg(&ps3av_dev.core,
413 "ps3av_cmd_audio_mode failed, port:%x\n", i);
414 }
415
416 /* send command using avb pkt */
417 len += offsetof(struct ps3av_pkt_avb_param, buf);
418 res = ps3av_cmd_avb_param(&avb_param, len);
419 if (res < 0)
420 dev_dbg(&ps3av_dev.core, "ps3av_cmd_avb_param failed\n");
421
422 /* audio mute */
423 ps3av_set_audio_mute(PS3AV_CMD_MUTE_OFF);
424
425 /* audio active */
426 res = ps3av_cmd_audio_active(1, ps3av.audio_port);
427 if (res < 0)
428 dev_dbg(&ps3av_dev.core, "ps3av_cmd_audio_active ON failed\n");
429
430 return 0;
431}
432
433EXPORT_SYMBOL_GPL(ps3av_set_audio_mode);
434
435static int ps3av_set_videomode(void)
436{
437 /* av video mute */
438 ps3av_set_av_video_mute(PS3AV_CMD_MUTE_ON);
439
440 /* wake up ps3avd to do the actual video mode setting */
441 up(&ps3av.ping);
442
443 return 0;
444}
445
446static void ps3av_set_videomode_cont(u32 id, u32 old_id)
447{
448 struct ps3av_pkt_avb_param avb_param;
449 int i;
450 u32 len = 0, av_video_cs;
451 const struct avset_video_mode *video_mode;
452 int res;
453
454 video_mode = &video_mode_table[id & PS3AV_MODE_MASK];
455
456 avb_param.num_of_video_pkt = PS3AV_AVB_NUM_VIDEO; /* num of head */
457 avb_param.num_of_audio_pkt = 0;
458 avb_param.num_of_av_video_pkt = ps3av.av_hw_conf.num_of_hdmi +
459 ps3av.av_hw_conf.num_of_avmulti;
460 avb_param.num_of_av_audio_pkt = 0;
461
462 /* video signal off */
463 ps3av_set_video_disable_sig();
464
465 /* Retail PS3 product doesn't support this */
466 if (id & PS3AV_MODE_HDCP_OFF) {
467 res = ps3av_cmd_av_hdmi_mode(PS3AV_CMD_AV_HDMI_HDCP_OFF);
468 if (res == PS3AV_STATUS_UNSUPPORTED_HDMI_MODE)
469 dev_dbg(&ps3av_dev.core, "Not supported\n");
470 else if (res)
471 dev_dbg(&ps3av_dev.core,
472 "ps3av_cmd_av_hdmi_mode failed\n");
473 } else if (old_id & PS3AV_MODE_HDCP_OFF) {
474 res = ps3av_cmd_av_hdmi_mode(PS3AV_CMD_AV_HDMI_MODE_NORMAL);
475 if (res < 0 && res != PS3AV_STATUS_UNSUPPORTED_HDMI_MODE)
476 dev_dbg(&ps3av_dev.core,
477 "ps3av_cmd_av_hdmi_mode failed\n");
478 }
479
480 /* video_pkt */
481 for (i = 0; i < avb_param.num_of_video_pkt; i++)
482 len += ps3av_cmd_set_video_mode(&avb_param.buf[len],
483 ps3av.head[i], video_mode->vid,
484 video_mode->fmt, id);
485 /* av_video_pkt */
486 for (i = 0; i < avb_param.num_of_av_video_pkt; i++) {
487 if (id & PS3AV_MODE_DVI || id & PS3AV_MODE_RGB)
488 av_video_cs = RGB8;
489 else
490 av_video_cs = video_mode->cs;
491#ifndef PS3AV_HDMI_YUV
492 if (ps3av.av_port[i] == PS3AV_CMD_AVPORT_HDMI_0 ||
493 ps3av.av_port[i] == PS3AV_CMD_AVPORT_HDMI_1)
494 av_video_cs = RGB8; /* use RGB for HDMI */
495#endif
496 len += ps3av_cmd_set_av_video_cs(&avb_param.buf[len],
497 ps3av.av_port[i],
498 video_mode->vid, av_video_cs,
499 video_mode->aspect, id);
500 }
501 /* send command using avb pkt */
502 len += offsetof(struct ps3av_pkt_avb_param, buf);
503 res = ps3av_cmd_avb_param(&avb_param, len);
504 if (res == PS3AV_STATUS_NO_SYNC_HEAD)
505 printk(KERN_WARNING
506 "%s: Command failed. Please try your request again. \n",
507 __FUNCTION__);
508 else if (res)
509 dev_dbg(&ps3av_dev.core, "ps3av_cmd_avb_param failed\n");
510
511 msleep(1500);
512 /* av video mute */
513 ps3av_set_av_video_mute(PS3AV_CMD_MUTE_OFF);
514}
515
516static int ps3avd(void *p)
517{
518 struct ps3av *info = p;
519
520 daemonize("ps3avd");
521 while (1) {
522 down(&info->ping);
523 ps3av_set_videomode_cont(info->ps3av_mode,
524 info->ps3av_mode_old);
525 up(&info->pong);
526 }
527 return 0;
528}
529
530static int ps3av_vid2table_id(int vid)
531{
532 int i;
533
534 for (i = 1; i < ARRAY_SIZE(video_mode_table); i++)
535 if (video_mode_table[i].vid == vid)
536 return i;
537 return -1;
538}
539
540static int ps3av_resbit2vid(u32 res_50, u32 res_60)
541{
542 int vid = -1;
543
544 if (res_50 > res_60) { /* if res_50 == res_60, res_60 will be used */
545 if (res_50 & PS3AV_RESBIT_1920x1080P)
546 vid = PS3AV_CMD_VIDEO_VID_1080P_50HZ;
547 else if (res_50 & PS3AV_RESBIT_1920x1080I)
548 vid = PS3AV_CMD_VIDEO_VID_1080I_50HZ;
549 else if (res_50 & PS3AV_RESBIT_1280x720P)
550 vid = PS3AV_CMD_VIDEO_VID_720P_50HZ;
551 else if (res_50 & PS3AV_RESBIT_720x576P)
552 vid = PS3AV_CMD_VIDEO_VID_576P;
553 else
554 vid = -1;
555 } else {
556 if (res_60 & PS3AV_RESBIT_1920x1080P)
557 vid = PS3AV_CMD_VIDEO_VID_1080P_60HZ;
558 else if (res_60 & PS3AV_RESBIT_1920x1080I)
559 vid = PS3AV_CMD_VIDEO_VID_1080I_60HZ;
560 else if (res_60 & PS3AV_RESBIT_1280x720P)
561 vid = PS3AV_CMD_VIDEO_VID_720P_60HZ;
562 else if (res_60 & PS3AV_RESBIT_720x480P)
563 vid = PS3AV_CMD_VIDEO_VID_480P;
564 else
565 vid = -1;
566 }
567 return vid;
568}
569
570static int ps3av_hdmi_get_vid(struct ps3av_info_monitor *info)
571{
572 u32 res_50, res_60;
573 int vid = -1;
574
575 if (info->monitor_type != PS3AV_MONITOR_TYPE_HDMI)
576 return -1;
577
578 /* check native resolution */
579 res_50 = info->res_50.native & PS3AV_RES_MASK_50;
580 res_60 = info->res_60.native & PS3AV_RES_MASK_60;
581 if (res_50 || res_60) {
582 vid = ps3av_resbit2vid(res_50, res_60);
583 return vid;
584 }
585
586 /* check resolution */
587 res_50 = info->res_50.res_bits & PS3AV_RES_MASK_50;
588 res_60 = info->res_60.res_bits & PS3AV_RES_MASK_60;
589 if (res_50 || res_60) {
590 vid = ps3av_resbit2vid(res_50, res_60);
591 return vid;
592 }
593
594 if (ps3av.region & PS3AV_REGION_60)
595 vid = PS3AV_DEFAULT_HDMI_VID_REG_60;
596 else
597 vid = PS3AV_DEFAULT_HDMI_VID_REG_50;
598 return vid;
599}
600
601static int ps3av_auto_videomode(struct ps3av_pkt_av_get_hw_conf *av_hw_conf,
602 int boot)
603{
604 int i, res, vid = -1, dvi = 0, rgb = 0;
605 struct ps3av_pkt_av_get_monitor_info monitor_info;
606 struct ps3av_info_monitor *info;
607
608 /* get vid for hdmi */
609 for (i = 0; i < av_hw_conf->num_of_hdmi; i++) {
610 res = ps3av_cmd_video_get_monitor_info(&monitor_info,
611 PS3AV_CMD_AVPORT_HDMI_0 +
612 i);
613 if (res < 0)
614 return -1;
615
616 ps3av_cmd_av_monitor_info_dump(&monitor_info);
617 info = &monitor_info.info;
618 /* check DVI */
619 if (info->monitor_type == PS3AV_MONITOR_TYPE_DVI) {
620 dvi = PS3AV_MODE_DVI;
621 break;
622 }
623 /* check HDMI */
624 vid = ps3av_hdmi_get_vid(info);
625 if (vid != -1) {
626 /* got valid vid */
627 break;
628 }
629 }
630
631 if (dvi) {
632 /* DVI mode */
633 vid = PS3AV_DEFAULT_DVI_VID;
634 } else if (vid == -1) {
635 /* no HDMI interface or HDMI is off */
636 if (ps3av.region & PS3AV_REGION_60)
637 vid = PS3AV_DEFAULT_AVMULTI_VID_REG_60;
638 else
639 vid = PS3AV_DEFAULT_AVMULTI_VID_REG_50;
640 if (ps3av.region & PS3AV_REGION_RGB)
641 rgb = PS3AV_MODE_RGB;
642 } else if (boot) {
643 /* HDMI: using DEFAULT HDMI_VID while booting up */
644 info = &monitor_info.info;
645 if (ps3av.region & PS3AV_REGION_60) {
646 if (info->res_60.res_bits & PS3AV_RESBIT_720x480P)
647 vid = PS3AV_DEFAULT_HDMI_VID_REG_60;
648 else if (info->res_50.res_bits & PS3AV_RESBIT_720x576P)
649 vid = PS3AV_DEFAULT_HDMI_VID_REG_50;
650 else {
651 /* default */
652 vid = PS3AV_DEFAULT_HDMI_VID_REG_60;
653 }
654 } else {
655 if (info->res_50.res_bits & PS3AV_RESBIT_720x576P)
656 vid = PS3AV_DEFAULT_HDMI_VID_REG_50;
657 else if (info->res_60.res_bits & PS3AV_RESBIT_720x480P)
658 vid = PS3AV_DEFAULT_HDMI_VID_REG_60;
659 else {
660 /* default */
661 vid = PS3AV_DEFAULT_HDMI_VID_REG_50;
662 }
663 }
664 }
665
666 return (ps3av_vid2table_id(vid) | dvi | rgb);
667}
668
669static int ps3av_get_hw_conf(struct ps3av *ps3av)
670{
671 int i, j, k, res;
672
673 /* get av_hw_conf */
674 res = ps3av_cmd_av_get_hw_conf(&ps3av->av_hw_conf);
675 if (res < 0)
676 return -1;
677
678 ps3av_cmd_av_hw_conf_dump(&ps3av->av_hw_conf);
679
680 for (i = 0; i < PS3AV_HEAD_MAX; i++)
681 ps3av->head[i] = PS3AV_CMD_VIDEO_HEAD_A + i;
682 for (i = 0; i < PS3AV_OPT_PORT_MAX; i++)
683 ps3av->opt_port[i] = PS3AV_CMD_AVPORT_SPDIF_0 + i;
684 for (i = 0; i < ps3av->av_hw_conf.num_of_hdmi; i++)
685 ps3av->av_port[i] = PS3AV_CMD_AVPORT_HDMI_0 + i;
686 for (j = 0; j < ps3av->av_hw_conf.num_of_avmulti; j++)
687 ps3av->av_port[i + j] = PS3AV_CMD_AVPORT_AVMULTI_0 + j;
688 for (k = 0; k < ps3av->av_hw_conf.num_of_spdif; k++)
689 ps3av->av_port[i + j + k] = PS3AV_CMD_AVPORT_SPDIF_0 + k;
690
691 /* set all audio port */
692 ps3av->audio_port = PS3AV_CMD_AUDIO_PORT_HDMI_0
693 | PS3AV_CMD_AUDIO_PORT_HDMI_1
694 | PS3AV_CMD_AUDIO_PORT_AVMULTI_0
695 | PS3AV_CMD_AUDIO_PORT_SPDIF_0 | PS3AV_CMD_AUDIO_PORT_SPDIF_1;
696
697 return 0;
698}
699
700/* set mode using id */
701int ps3av_set_video_mode(u32 id, int boot)
702{
703 int size;
704 u32 option;
705
706 size = ARRAY_SIZE(video_mode_table);
707 if ((id & PS3AV_MODE_MASK) > size - 1 || id < 0) {
708 dev_dbg(&ps3av_dev.core, "%s: error id :%d\n", __FUNCTION__,
709 id);
710 return -EINVAL;
711 }
712
713 /* auto mode */
714 option = id & ~PS3AV_MODE_MASK;
715 if ((id & PS3AV_MODE_MASK) == 0) {
716 id = ps3av_auto_videomode(&ps3av.av_hw_conf, boot);
717 if (id < 1) {
718 printk(KERN_ERR "%s: invalid id :%d\n", __FUNCTION__,
719 id);
720 return -EINVAL;
721 }
722 id |= option;
723 }
724
725 /* set videomode */
726 down(&ps3av.pong);
727 ps3av.ps3av_mode_old = ps3av.ps3av_mode;
728 ps3av.ps3av_mode = id;
729 if (ps3av_set_videomode())
730 ps3av.ps3av_mode = ps3av.ps3av_mode_old;
731
732 return 0;
733}
734
735EXPORT_SYMBOL_GPL(ps3av_set_video_mode);
736
737int ps3av_set_mode(u32 id, int boot)
738{
739 int res;
740
741 res = ps3av_set_video_mode(id, boot);
742 if (res)
743 return res;
744
745 res = ps3av_set_audio_mode(PS3AV_CMD_AUDIO_NUM_OF_CH_2,
746 PS3AV_CMD_AUDIO_FS_48K,
747 PS3AV_CMD_AUDIO_WORD_BITS_16,
748 PS3AV_CMD_AUDIO_FORMAT_PCM,
749 PS3AV_CMD_AUDIO_SOURCE_SERIAL);
750 if (res)
751 return res;
752
753 return 0;
754}
755
756EXPORT_SYMBOL_GPL(ps3av_set_mode);
757
758int ps3av_get_mode(void)
759{
760 return ps3av.ps3av_mode;
761}
762
763EXPORT_SYMBOL_GPL(ps3av_get_mode);
764
765int ps3av_get_scanmode(int id)
766{
767 int size;
768
769 id = id & PS3AV_MODE_MASK;
770 size = ARRAY_SIZE(video_mode_table);
771 if (id > size - 1 || id < 0) {
772 printk(KERN_ERR "%s: invalid mode %d\n", __FUNCTION__, id);
773 return -EINVAL;
774 }
775 return video_mode_table[id].interlace;
776}
777
778EXPORT_SYMBOL_GPL(ps3av_get_scanmode);
779
780int ps3av_get_refresh_rate(int id)
781{
782 int size;
783
784 id = id & PS3AV_MODE_MASK;
785 size = ARRAY_SIZE(video_mode_table);
786 if (id > size - 1 || id < 0) {
787 printk(KERN_ERR "%s: invalid mode %d\n", __FUNCTION__, id);
788 return -EINVAL;
789 }
790 return video_mode_table[id].freq;
791}
792
793EXPORT_SYMBOL_GPL(ps3av_get_refresh_rate);
794
795/* get resolution by video_mode */
796int ps3av_video_mode2res(u32 id, u32 *xres, u32 *yres)
797{
798 int size;
799
800 id = id & PS3AV_MODE_MASK;
801 size = ARRAY_SIZE(video_mode_table);
802 if (id > size - 1 || id < 0) {
803 printk(KERN_ERR "%s: invalid mode %d\n", __FUNCTION__, id);
804 return -EINVAL;
805 }
806 *xres = video_mode_table[id].x;
807 *yres = video_mode_table[id].y;
808 return 0;
809}
810
811EXPORT_SYMBOL_GPL(ps3av_video_mode2res);
812
813/* mute */
814int ps3av_video_mute(int mute)
815{
816 return ps3av_set_av_video_mute(mute ? PS3AV_CMD_MUTE_ON
817 : PS3AV_CMD_MUTE_OFF);
818}
819
820EXPORT_SYMBOL_GPL(ps3av_video_mute);
821
822int ps3av_audio_mute(int mute)
823{
824 return ps3av_set_audio_mute(mute ? PS3AV_CMD_MUTE_ON
825 : PS3AV_CMD_MUTE_OFF);
826}
827
828EXPORT_SYMBOL_GPL(ps3av_audio_mute);
829
830int ps3av_dev_open(void)
831{
832 int status = 0;
833
834 mutex_lock(&ps3av.mutex);
835 if (!ps3av.open_count++) {
836 status = lv1_gpu_open(0);
837 if (status) {
838 printk(KERN_ERR "%s: lv1_gpu_open failed %d\n",
839 __FUNCTION__, status);
840 ps3av.open_count--;
841 }
842 }
843 mutex_unlock(&ps3av.mutex);
844
845 return status;
846}
847
848EXPORT_SYMBOL_GPL(ps3av_dev_open);
849
850int ps3av_dev_close(void)
851{
852 int status = 0;
853
854 mutex_lock(&ps3av.mutex);
855 if (ps3av.open_count <= 0) {
856 printk(KERN_ERR "%s: GPU already closed\n", __FUNCTION__);
857 status = -1;
858 } else if (!--ps3av.open_count) {
859 status = lv1_gpu_close();
860 if (status)
861 printk(KERN_WARNING "%s: lv1_gpu_close failed %d\n",
862 __FUNCTION__, status);
863 }
864 mutex_unlock(&ps3av.mutex);
865
866 return status;
867}
868
869EXPORT_SYMBOL_GPL(ps3av_dev_close);
870
871static int ps3av_probe(struct ps3_vuart_port_device *dev)
872{
873 int res;
874 u32 id;
875
876 dev_dbg(&ps3av_dev.core, "init ...\n");
877 dev_dbg(&ps3av_dev.core, " timeout=%d\n", timeout);
878
879 memset(&ps3av, 0, sizeof(ps3av));
880
881 init_MUTEX(&ps3av.sem);
882 init_MUTEX_LOCKED(&ps3av.ping);
883 init_MUTEX(&ps3av.pong);
884 mutex_init(&ps3av.mutex);
885 ps3av.ps3av_mode = 0;
886 ps3av.dev = dev;
887 kernel_thread(ps3avd, &ps3av, CLONE_KERNEL);
888
889 ps3av.available = 1;
890 switch (ps3_os_area_get_av_multi_out()) {
891 case PS3_PARAM_AV_MULTI_OUT_NTSC:
892 ps3av.region = PS3AV_REGION_60;
893 break;
894 case PS3_PARAM_AV_MULTI_OUT_PAL_YCBCR:
895 case PS3_PARAM_AV_MULTI_OUT_SECAM:
896 ps3av.region = PS3AV_REGION_50;
897 break;
898 case PS3_PARAM_AV_MULTI_OUT_PAL_RGB:
899 ps3av.region = PS3AV_REGION_50 | PS3AV_REGION_RGB;
900 break;
901 default:
902 ps3av.region = PS3AV_REGION_60;
903 break;
904 }
905
906 /* init avsetting modules */
907 res = ps3av_cmd_init();
908 if (res < 0)
909 printk(KERN_ERR "%s: ps3av_cmd_init failed %d\n", __FUNCTION__,
910 res);
911
912 ps3av_get_hw_conf(&ps3av);
913 id = ps3av_auto_videomode(&ps3av.av_hw_conf, 1);
914 mutex_lock(&ps3av.mutex);
915 ps3av.ps3av_mode = id;
916 mutex_unlock(&ps3av.mutex);
917
918 dev_dbg(&ps3av_dev.core, "init...done\n");
919
920 return 0;
921}
922
923static int ps3av_remove(struct ps3_vuart_port_device *dev)
924{
925 if (ps3av.available) {
926 ps3av_cmd_fin();
927 ps3av.available = 0;
928 }
929
930 return 0;
931}
932
933static void ps3av_shutdown(struct ps3_vuart_port_device *dev)
934{
935 ps3av_remove(dev);
936}
937
938static struct ps3_vuart_port_driver ps3av_driver = {
939 .match_id = PS3_MATCH_ID_AV_SETTINGS,
940 .core = {
941 .name = "ps3_av",
942 },
943 .probe = ps3av_probe,
944 .remove = ps3av_remove,
945 .shutdown = ps3av_shutdown,
946};
947
948static int ps3av_module_init(void)
949{
950 int error = ps3_vuart_port_driver_register(&ps3av_driver);
951 if (error) {
952 printk(KERN_ERR
953 "%s: ps3_vuart_port_driver_register failed %d\n",
954 __FUNCTION__, error);
955 return error;
956 }
957
958 error = ps3_vuart_port_device_register(&ps3av_dev);
959 if (error)
960 printk(KERN_ERR
961 "%s: ps3_vuart_port_device_register failed %d\n",
962 __FUNCTION__, error);
963
964 return error;
965}
966
967static void __exit ps3av_module_exit(void)
968{
969 device_unregister(&ps3av_dev.core);
970 ps3_vuart_port_driver_unregister(&ps3av_driver);
971}
972
973subsys_initcall(ps3av_module_init);
974module_exit(ps3av_module_exit);
diff --git a/drivers/ps3/ps3av_cmd.c b/drivers/ps3/ps3av_cmd.c
new file mode 100644
index 00000000000..21c97c80aa2
--- /dev/null
+++ b/drivers/ps3/ps3av_cmd.c
@@ -0,0 +1,1020 @@
1/*
2 * Copyright (C) 2006 Sony Computer Entertainment Inc.
3 * Copyright 2006, 2007 Sony Corporation
4 *
5 * AV backend support for PS3
6 *
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
9 * by the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21#include <linux/module.h>
22#include <linux/kernel.h>
23#include <linux/delay.h>
24#include <asm/ps3av.h>
25#include <asm/ps3fb.h>
26#include <asm/ps3.h>
27
28#include "vuart.h"
29
30static const struct video_fmt {
31 u32 format;
32 u32 order;
33} ps3av_video_fmt_table[] = {
34 { PS3AV_CMD_VIDEO_FORMAT_ARGB_8BIT, PS3AV_CMD_VIDEO_ORDER_RGB },
35 { PS3AV_CMD_VIDEO_FORMAT_ARGB_8BIT, PS3AV_CMD_VIDEO_ORDER_BGR },
36};
37
38static const struct {
39 int cs;
40 u32 av;
41 u32 bl;
42} ps3av_cs_video2av_table[] = {
43 {
44 .cs = PS3AV_CMD_VIDEO_CS_RGB_8,
45 .av = PS3AV_CMD_AV_CS_RGB_8,
46 .bl = PS3AV_CMD_AV_CS_8
47 }, {
48 .cs = PS3AV_CMD_VIDEO_CS_RGB_10,
49 .av = PS3AV_CMD_AV_CS_RGB_8,
50 .bl = PS3AV_CMD_AV_CS_8
51 }, {
52 .cs = PS3AV_CMD_VIDEO_CS_RGB_12,
53 .av = PS3AV_CMD_AV_CS_RGB_8,
54 .bl = PS3AV_CMD_AV_CS_8
55 }, {
56 .cs = PS3AV_CMD_VIDEO_CS_YUV444_8,
57 .av = PS3AV_CMD_AV_CS_YUV444_8,
58 .bl = PS3AV_CMD_AV_CS_8
59 }, {
60 .cs = PS3AV_CMD_VIDEO_CS_YUV444_10,
61 .av = PS3AV_CMD_AV_CS_YUV444_8,
62 .bl = PS3AV_CMD_AV_CS_10
63 }, {
64 .cs = PS3AV_CMD_VIDEO_CS_YUV444_12,
65 .av = PS3AV_CMD_AV_CS_YUV444_8,
66 .bl = PS3AV_CMD_AV_CS_10
67 }, {
68 .cs = PS3AV_CMD_VIDEO_CS_YUV422_8,
69 .av = PS3AV_CMD_AV_CS_YUV422_8,
70 .bl = PS3AV_CMD_AV_CS_10
71 }, {
72 .cs = PS3AV_CMD_VIDEO_CS_YUV422_10,
73 .av = PS3AV_CMD_AV_CS_YUV422_8,
74 .bl = PS3AV_CMD_AV_CS_10
75 }, {
76 .cs = PS3AV_CMD_VIDEO_CS_YUV422_12,
77 .av = PS3AV_CMD_AV_CS_YUV422_8,
78 .bl = PS3AV_CMD_AV_CS_12
79 }, {
80 .cs = PS3AV_CMD_VIDEO_CS_XVYCC_8,
81 .av = PS3AV_CMD_AV_CS_XVYCC_8,
82 .bl = PS3AV_CMD_AV_CS_12
83 }, {
84 .cs = PS3AV_CMD_VIDEO_CS_XVYCC_10,
85 .av = PS3AV_CMD_AV_CS_XVYCC_8,
86 .bl = PS3AV_CMD_AV_CS_12
87 }, {
88 .cs = PS3AV_CMD_VIDEO_CS_XVYCC_12,
89 .av = PS3AV_CMD_AV_CS_XVYCC_8,
90 .bl = PS3AV_CMD_AV_CS_12
91 }
92};
93
94static u32 ps3av_cs_video2av(int cs)
95{
96 unsigned int i;
97
98 for (i = 0; i < ARRAY_SIZE(ps3av_cs_video2av_table); i++)
99 if (ps3av_cs_video2av_table[i].cs == cs)
100 return ps3av_cs_video2av_table[i].av;
101
102 return PS3AV_CMD_AV_CS_RGB_8;
103}
104
105static u32 ps3av_cs_video2av_bitlen(int cs)
106{
107 unsigned int i;
108
109 for (i = 0; i < ARRAY_SIZE(ps3av_cs_video2av_table); i++)
110 if (ps3av_cs_video2av_table[i].cs == cs)
111 return ps3av_cs_video2av_table[i].bl;
112
113 return PS3AV_CMD_AV_CS_8;
114}
115
116static const struct {
117 int vid;
118 u32 av;
119} ps3av_vid_video2av_table[] = {
120 { PS3AV_CMD_VIDEO_VID_480I, PS3AV_CMD_AV_VID_480I },
121 { PS3AV_CMD_VIDEO_VID_480P, PS3AV_CMD_AV_VID_480P },
122 { PS3AV_CMD_VIDEO_VID_576I, PS3AV_CMD_AV_VID_576I },
123 { PS3AV_CMD_VIDEO_VID_576P, PS3AV_CMD_AV_VID_576P },
124 { PS3AV_CMD_VIDEO_VID_1080I_60HZ, PS3AV_CMD_AV_VID_1080I_60HZ },
125 { PS3AV_CMD_VIDEO_VID_720P_60HZ, PS3AV_CMD_AV_VID_720P_60HZ },
126 { PS3AV_CMD_VIDEO_VID_1080P_60HZ, PS3AV_CMD_AV_VID_1080P_60HZ },
127 { PS3AV_CMD_VIDEO_VID_1080I_50HZ, PS3AV_CMD_AV_VID_1080I_50HZ },
128 { PS3AV_CMD_VIDEO_VID_720P_50HZ, PS3AV_CMD_AV_VID_720P_50HZ },
129 { PS3AV_CMD_VIDEO_VID_1080P_50HZ, PS3AV_CMD_AV_VID_1080P_50HZ },
130 { PS3AV_CMD_VIDEO_VID_WXGA, PS3AV_CMD_AV_VID_WXGA },
131 { PS3AV_CMD_VIDEO_VID_SXGA, PS3AV_CMD_AV_VID_SXGA },
132 { PS3AV_CMD_VIDEO_VID_WUXGA, PS3AV_CMD_AV_VID_WUXGA }
133};
134
135static u32 ps3av_vid_video2av(int vid)
136{
137 unsigned int i;
138
139 for (i = 0; i < ARRAY_SIZE(ps3av_vid_video2av_table); i++)
140 if (ps3av_vid_video2av_table[i].vid == vid)
141 return ps3av_vid_video2av_table[i].av;
142
143 return PS3AV_CMD_AV_VID_480P;
144}
145
146int ps3av_cmd_init(void)
147{
148 int res;
149 struct ps3av_pkt_av_init av_init;
150 struct ps3av_pkt_video_init video_init;
151 struct ps3av_pkt_audio_init audio_init;
152
153 /* video init */
154 memset(&video_init, 0, sizeof(video_init));
155
156 res = ps3av_do_pkt(PS3AV_CID_VIDEO_INIT, sizeof(video_init.send_hdr),
157 sizeof(video_init), &video_init.send_hdr);
158 if (res < 0)
159 return res;
160
161 res = get_status(&video_init);
162 if (res) {
163 printk(KERN_ERR "PS3AV_CID_VIDEO_INIT: failed %x\n", res);
164 return res;
165 }
166
167 /* audio init */
168 memset(&audio_init, 0, sizeof(audio_init));
169
170 res = ps3av_do_pkt(PS3AV_CID_AUDIO_INIT, sizeof(audio_init.send_hdr),
171 sizeof(audio_init), &audio_init.send_hdr);
172 if (res < 0)
173 return res;
174
175 res = get_status(&audio_init);
176 if (res) {
177 printk(KERN_ERR "PS3AV_CID_AUDIO_INIT: failed %x\n", res);
178 return res;
179 }
180
181 /* av init */
182 memset(&av_init, 0, sizeof(av_init));
183 av_init.event_bit = 0;
184
185 res = ps3av_do_pkt(PS3AV_CID_AV_INIT, sizeof(av_init), sizeof(av_init),
186 &av_init.send_hdr);
187 if (res < 0)
188 return res;
189
190 res = get_status(&av_init);
191 if (res)
192 printk(KERN_ERR "PS3AV_CID_AV_INIT: failed %x\n", res);
193
194 return res;
195}
196
197int ps3av_cmd_fin(void)
198{
199 int res;
200 struct ps3av_pkt_av_fin av_fin;
201
202 memset(&av_fin, 0, sizeof(av_fin));
203
204 res = ps3av_do_pkt(PS3AV_CID_AV_FIN, sizeof(av_fin.send_hdr),
205 sizeof(av_fin), &av_fin.send_hdr);
206 if (res < 0)
207 return res;
208
209 res = get_status(&av_fin);
210 if (res)
211 printk(KERN_ERR "PS3AV_CID_AV_FIN: failed %x\n", res);
212
213 return res;
214}
215
216int ps3av_cmd_av_video_mute(int num_of_port, u32 *port, u32 mute)
217{
218 int i, send_len, res;
219 struct ps3av_pkt_av_video_mute av_video_mute;
220
221 if (num_of_port > PS3AV_MUTE_PORT_MAX)
222 return -EINVAL;
223
224 memset(&av_video_mute, 0, sizeof(av_video_mute));
225 for (i = 0; i < num_of_port; i++) {
226 av_video_mute.mute[i].avport = port[i];
227 av_video_mute.mute[i].mute = mute;
228 }
229
230 send_len = sizeof(av_video_mute.send_hdr) +
231 sizeof(struct ps3av_av_mute) * num_of_port;
232 res = ps3av_do_pkt(PS3AV_CID_AV_VIDEO_MUTE, send_len,
233 sizeof(av_video_mute), &av_video_mute.send_hdr);
234 if (res < 0)
235 return res;
236
237 res = get_status(&av_video_mute);
238 if (res)
239 printk(KERN_ERR "PS3AV_CID_AV_VIDEO_MUTE: failed %x\n", res);
240
241 return res;
242}
243
244int ps3av_cmd_av_video_disable_sig(u32 port)
245{
246 int res;
247 struct ps3av_pkt_av_video_disable_sig av_video_sig;
248
249 memset(&av_video_sig, 0, sizeof(av_video_sig));
250 av_video_sig.avport = port;
251
252 res = ps3av_do_pkt(PS3AV_CID_AV_VIDEO_DISABLE_SIG,
253 sizeof(av_video_sig), sizeof(av_video_sig),
254 &av_video_sig.send_hdr);
255 if (res < 0)
256 return res;
257
258 res = get_status(&av_video_sig);
259 if (res)
260 printk(KERN_ERR
261 "PS3AV_CID_AV_VIDEO_DISABLE_SIG: failed %x port:%x\n",
262 res, port);
263
264 return res;
265}
266
267int ps3av_cmd_av_tv_mute(u32 avport, u32 mute)
268{
269 int res;
270 struct ps3av_pkt_av_tv_mute tv_mute;
271
272 memset(&tv_mute, 0, sizeof(tv_mute));
273 tv_mute.avport = avport;
274 tv_mute.mute = mute;
275
276 res = ps3av_do_pkt(PS3AV_CID_AV_TV_MUTE, sizeof(tv_mute),
277 sizeof(tv_mute), &tv_mute.send_hdr);
278 if (res < 0)
279 return res;
280
281 res = get_status(&tv_mute);
282 if (res)
283 printk(KERN_ERR "PS3AV_CID_AV_TV_MUTE: failed %x port:%x\n",
284 res, avport);
285
286 return res;
287}
288
289int ps3av_cmd_enable_event(void)
290{
291 int res;
292 struct ps3av_pkt_av_event av_event;
293
294 memset(&av_event, 0, sizeof(av_event));
295 av_event.event_bit = PS3AV_CMD_EVENT_BIT_UNPLUGGED |
296 PS3AV_CMD_EVENT_BIT_PLUGGED | PS3AV_CMD_EVENT_BIT_HDCP_DONE;
297
298 res = ps3av_do_pkt(PS3AV_CID_AV_ENABLE_EVENT, sizeof(av_event),
299 sizeof(av_event), &av_event.send_hdr);
300 if (res < 0)
301 return res;
302
303 res = get_status(&av_event);
304 if (res)
305 printk(KERN_ERR "PS3AV_CID_AV_ENABLE_EVENT: failed %x\n", res);
306
307 return res;
308}
309
310int ps3av_cmd_av_hdmi_mode(u8 mode)
311{
312 int res;
313 struct ps3av_pkt_av_hdmi_mode hdmi_mode;
314
315 memset(&hdmi_mode, 0, sizeof(hdmi_mode));
316 hdmi_mode.mode = mode;
317
318 res = ps3av_do_pkt(PS3AV_CID_AV_HDMI_MODE, sizeof(hdmi_mode),
319 sizeof(hdmi_mode), &hdmi_mode.send_hdr);
320 if (res < 0)
321 return res;
322
323 res = get_status(&hdmi_mode);
324 if (res && res != PS3AV_STATUS_UNSUPPORTED_HDMI_MODE)
325 printk(KERN_ERR "PS3AV_CID_AV_HDMI_MODE: failed %x\n", res);
326
327 return res;
328}
329
330u32 ps3av_cmd_set_av_video_cs(void *p, u32 avport, int video_vid, int cs_out,
331 int aspect, u32 id)
332{
333 struct ps3av_pkt_av_video_cs *av_video_cs;
334
335 av_video_cs = (struct ps3av_pkt_av_video_cs *)p;
336 if (video_vid == -1)
337 video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ;
338 if (cs_out == -1)
339 cs_out = PS3AV_CMD_VIDEO_CS_YUV444_8;
340 if (aspect == -1)
341 aspect = 0;
342
343 memset(av_video_cs, 0, sizeof(*av_video_cs));
344 ps3av_set_hdr(PS3AV_CID_AV_VIDEO_CS, sizeof(*av_video_cs),
345 &av_video_cs->send_hdr);
346 av_video_cs->avport = avport;
347 /* should be same as video_mode.resolution */
348 av_video_cs->av_vid = ps3av_vid_video2av(video_vid);
349 av_video_cs->av_cs_out = ps3av_cs_video2av(cs_out);
350 /* should be same as video_mode.video_cs_out */
351 av_video_cs->av_cs_in = ps3av_cs_video2av(PS3AV_CMD_VIDEO_CS_RGB_8);
352 av_video_cs->bitlen_out = ps3av_cs_video2av_bitlen(cs_out);
353 av_video_cs->aspect = aspect;
354 if (id & PS3AV_MODE_DITHER) {
355 av_video_cs->dither = PS3AV_CMD_AV_DITHER_ON
356 | PS3AV_CMD_AV_DITHER_8BIT;
357 } else {
358 /* default off */
359 av_video_cs->dither = PS3AV_CMD_AV_DITHER_OFF;
360 }
361
362 return sizeof(*av_video_cs);
363}
364
365u32 ps3av_cmd_set_video_mode(void *p, u32 head, int video_vid, int video_fmt,
366 u32 id)
367{
368 struct ps3av_pkt_video_mode *video_mode;
369 u32 x, y;
370
371 video_mode = (struct ps3av_pkt_video_mode *)p;
372 if (video_vid == -1)
373 video_vid = PS3AV_CMD_VIDEO_VID_720P_60HZ;
374 if (video_fmt == -1)
375 video_fmt = PS3AV_CMD_VIDEO_FMT_X8R8G8B8;
376
377 if (ps3av_video_mode2res(id, &x, &y))
378 return 0;
379
380 /* video mode */
381 memset(video_mode, 0, sizeof(*video_mode));
382 ps3av_set_hdr(PS3AV_CID_VIDEO_MODE, sizeof(*video_mode),
383 &video_mode->send_hdr);
384 video_mode->video_head = head;
385 if (video_vid == PS3AV_CMD_VIDEO_VID_480I
386 && head == PS3AV_CMD_VIDEO_HEAD_B)
387 video_mode->video_vid = PS3AV_CMD_VIDEO_VID_480I_A;
388 else
389 video_mode->video_vid = video_vid;
390 video_mode->width = (u16) x;
391 video_mode->height = (u16) y;
392 video_mode->pitch = video_mode->width * 4; /* line_length */
393 video_mode->video_out_format = PS3AV_CMD_VIDEO_OUT_FORMAT_RGB_12BIT;
394 video_mode->video_format = ps3av_video_fmt_table[video_fmt].format;
395 video_mode->video_order = ps3av_video_fmt_table[video_fmt].order;
396
397 pr_debug("%s: video_mode:vid:%x width:%d height:%d pitch:%d out_format:%d format:%x order:%x\n",
398 __FUNCTION__, video_vid, video_mode->width, video_mode->height,
399 video_mode->pitch, video_mode->video_out_format,
400 video_mode->video_format, video_mode->video_order);
401 return sizeof(*video_mode);
402}
403
404int ps3av_cmd_video_format_black(u32 head, u32 video_fmt, u32 mute)
405{
406 int res;
407 struct ps3av_pkt_video_format video_format;
408
409 memset(&video_format, 0, sizeof(video_format));
410 video_format.video_head = head;
411 if (mute != PS3AV_CMD_MUTE_OFF)
412 video_format.video_format = PS3AV_CMD_VIDEO_FORMAT_BLACK;
413 else
414 video_format.video_format =
415 ps3av_video_fmt_table[video_fmt].format;
416 video_format.video_order = ps3av_video_fmt_table[video_fmt].order;
417
418 res = ps3av_do_pkt(PS3AV_CID_VIDEO_FORMAT, sizeof(video_format),
419 sizeof(video_format), &video_format.send_hdr);
420 if (res < 0)
421 return res;
422
423 res = get_status(&video_format);
424 if (res)
425 printk(KERN_ERR "PS3AV_CID_VIDEO_FORMAT: failed %x\n", res);
426
427 return res;
428}
429
430
431int ps3av_cmd_av_audio_mute(int num_of_port, u32 *port, u32 mute)
432{
433 int i, res;
434 struct ps3av_pkt_av_audio_mute av_audio_mute;
435
436 if (num_of_port > PS3AV_MUTE_PORT_MAX)
437 return -EINVAL;
438
439 /* audio mute */
440 memset(&av_audio_mute, 0, sizeof(av_audio_mute));
441 for (i = 0; i < num_of_port; i++) {
442 av_audio_mute.mute[i].avport = port[i];
443 av_audio_mute.mute[i].mute = mute;
444 }
445
446 res = ps3av_do_pkt(PS3AV_CID_AV_AUDIO_MUTE,
447 sizeof(av_audio_mute.send_hdr) +
448 sizeof(struct ps3av_av_mute) * num_of_port,
449 sizeof(av_audio_mute), &av_audio_mute.send_hdr);
450 if (res < 0)
451 return res;
452
453 res = get_status(&av_audio_mute);
454 if (res)
455 printk(KERN_ERR "PS3AV_CID_AV_AUDIO_MUTE: failed %x\n", res);
456
457 return res;
458}
459
460static const struct {
461 u32 fs;
462 u8 mclk;
463} ps3av_cnv_mclk_table[] = {
464 { PS3AV_CMD_AUDIO_FS_44K, PS3AV_CMD_AV_MCLK_512 },
465 { PS3AV_CMD_AUDIO_FS_48K, PS3AV_CMD_AV_MCLK_512 },
466 { PS3AV_CMD_AUDIO_FS_88K, PS3AV_CMD_AV_MCLK_256 },
467 { PS3AV_CMD_AUDIO_FS_96K, PS3AV_CMD_AV_MCLK_256 },
468 { PS3AV_CMD_AUDIO_FS_176K, PS3AV_CMD_AV_MCLK_128 },
469 { PS3AV_CMD_AUDIO_FS_192K, PS3AV_CMD_AV_MCLK_128 }
470};
471
472static u8 ps3av_cnv_mclk(u32 fs)
473{
474 unsigned int i;
475
476 for (i = 0; i < ARRAY_SIZE(ps3av_cnv_mclk_table); i++)
477 if (ps3av_cnv_mclk_table[i].fs == fs)
478 return ps3av_cnv_mclk_table[i].mclk;
479
480 printk(KERN_ERR "%s failed, fs:%x\n", __FUNCTION__, fs);
481 return 0;
482}
483
484#define BASE PS3AV_CMD_AUDIO_FS_44K
485
486static const u32 ps3av_ns_table[][5] = {
487 /* D1, D2, D3, D4, D5 */
488 [PS3AV_CMD_AUDIO_FS_44K-BASE] { 6272, 6272, 17836, 17836, 8918 },
489 [PS3AV_CMD_AUDIO_FS_48K-BASE] { 6144, 6144, 11648, 11648, 5824 },
490 [PS3AV_CMD_AUDIO_FS_88K-BASE] { 12544, 12544, 35672, 35672, 17836 },
491 [PS3AV_CMD_AUDIO_FS_96K-BASE] { 12288, 12288, 23296, 23296, 11648 },
492 [PS3AV_CMD_AUDIO_FS_176K-BASE] { 25088, 25088, 71344, 71344, 35672 },
493 [PS3AV_CMD_AUDIO_FS_192K-BASE] { 24576, 24576, 46592, 46592, 23296 }
494};
495
496static void ps3av_cnv_ns(u8 *ns, u32 fs, u32 video_vid)
497{
498 u32 av_vid, ns_val;
499 u8 *p = ns;
500 int d;
501
502 d = ns_val = 0;
503 av_vid = ps3av_vid_video2av(video_vid);
504 switch (av_vid) {
505 case PS3AV_CMD_AV_VID_480I:
506 case PS3AV_CMD_AV_VID_576I:
507 d = 0;
508 break;
509 case PS3AV_CMD_AV_VID_480P:
510 case PS3AV_CMD_AV_VID_576P:
511 d = 1;
512 break;
513 case PS3AV_CMD_AV_VID_1080I_60HZ:
514 case PS3AV_CMD_AV_VID_1080I_50HZ:
515 d = 2;
516 break;
517 case PS3AV_CMD_AV_VID_720P_60HZ:
518 case PS3AV_CMD_AV_VID_720P_50HZ:
519 d = 3;
520 break;
521 case PS3AV_CMD_AV_VID_1080P_60HZ:
522 case PS3AV_CMD_AV_VID_1080P_50HZ:
523 case PS3AV_CMD_AV_VID_WXGA:
524 case PS3AV_CMD_AV_VID_SXGA:
525 case PS3AV_CMD_AV_VID_WUXGA:
526 d = 4;
527 break;
528 default:
529 printk(KERN_ERR "%s failed, vid:%x\n", __FUNCTION__,
530 video_vid);
531 break;
532 }
533
534 if (fs < PS3AV_CMD_AUDIO_FS_44K || fs > PS3AV_CMD_AUDIO_FS_192K)
535 printk(KERN_ERR "%s failed, fs:%x\n", __FUNCTION__, fs);
536 else
537 ns_val = ps3av_ns_table[PS3AV_CMD_AUDIO_FS_44K-BASE][d];
538
539 *p++ = ns_val & 0x000000FF;
540 *p++ = (ns_val & 0x0000FF00) >> 8;
541 *p = (ns_val & 0x00FF0000) >> 16;
542}
543
544#undef BASE
545
546static u8 ps3av_cnv_enable(u32 source, u8 *enable)
547{
548 u8 *p, ret = 0;
549
550 if (source == PS3AV_CMD_AUDIO_SOURCE_SPDIF) {
551 ret = 0x03;
552 } else if (source == PS3AV_CMD_AUDIO_SOURCE_SERIAL) {
553 p = enable;
554 ret = ((p[0] << 4) + (p[1] << 5) + (p[2] << 6) + (p[3] << 7)) |
555 0x01;
556 } else
557 printk(KERN_ERR "%s failed, source:%x\n", __FUNCTION__,
558 source);
559 return ret;
560}
561
562static u8 ps3av_cnv_fifomap(u8 *map)
563{
564 u8 *p, ret = 0;
565
566 p = map;
567 ret = p[0] + (p[1] << 2) + (p[2] << 4) + (p[3] << 6);
568 return ret;
569}
570
571static u8 ps3av_cnv_inputlen(u32 word_bits)
572{
573 u8 ret = 0;
574
575 switch (word_bits) {
576 case PS3AV_CMD_AUDIO_WORD_BITS_16:
577 ret = PS3AV_CMD_AV_INPUTLEN_16;
578 break;
579 case PS3AV_CMD_AUDIO_WORD_BITS_20:
580 ret = PS3AV_CMD_AV_INPUTLEN_20;
581 break;
582 case PS3AV_CMD_AUDIO_WORD_BITS_24:
583 ret = PS3AV_CMD_AV_INPUTLEN_24;
584 break;
585 default:
586 printk(KERN_ERR "%s failed, word_bits:%x\n", __FUNCTION__,
587 word_bits);
588 break;
589 }
590 return ret;
591}
592
593static u8 ps3av_cnv_layout(u32 num_of_ch)
594{
595 if (num_of_ch > PS3AV_CMD_AUDIO_NUM_OF_CH_8) {
596 printk(KERN_ERR "%s failed, num_of_ch:%x\n", __FUNCTION__,
597 num_of_ch);
598 return 0;
599 }
600
601 return num_of_ch == PS3AV_CMD_AUDIO_NUM_OF_CH_2 ? 0x0 : 0x1;
602}
603
604static void ps3av_cnv_info(struct ps3av_audio_info_frame *info,
605 const struct ps3av_pkt_audio_mode *mode)
606{
607 info->pb1.cc = mode->audio_num_of_ch + 1; /* CH2:0x01 --- CH8:0x07 */
608 info->pb1.ct = 0;
609 info->pb2.sf = 0;
610 info->pb2.ss = 0;
611
612 info->pb3 = 0; /* check mode->audio_format ?? */
613 info->pb4 = mode->audio_layout;
614 info->pb5.dm = mode->audio_downmix;
615 info->pb5.lsv = mode->audio_downmix_level;
616}
617
618static void ps3av_cnv_chstat(u8 *chstat, u8 *cs_info)
619{
620 memcpy(chstat, cs_info, 5);
621}
622
623u32 ps3av_cmd_set_av_audio_param(void *p, u32 port,
624 const struct ps3av_pkt_audio_mode *audio_mode,
625 u32 video_vid)
626{
627 struct ps3av_pkt_av_audio_param *param;
628
629 param = (struct ps3av_pkt_av_audio_param *)p;
630
631 memset(param, 0, sizeof(*param));
632 ps3av_set_hdr(PS3AV_CID_AV_AUDIO_PARAM, sizeof(*param),
633 &param->send_hdr);
634
635 param->avport = port;
636 param->mclk = ps3av_cnv_mclk(audio_mode->audio_fs) | 0x80;
637 ps3av_cnv_ns(param->ns, audio_mode->audio_fs, video_vid);
638 param->enable = ps3av_cnv_enable(audio_mode->audio_source,
639 audio_mode->audio_enable);
640 param->swaplr = 0x09;
641 param->fifomap = ps3av_cnv_fifomap(audio_mode->audio_map);
642 param->inputctrl = 0x49;
643 param->inputlen = ps3av_cnv_inputlen(audio_mode->audio_word_bits);
644 param->layout = ps3av_cnv_layout(audio_mode->audio_num_of_ch);
645 ps3av_cnv_info(&param->info, audio_mode);
646 ps3av_cnv_chstat(param->chstat, audio_mode->audio_cs_info);
647
648 return sizeof(*param);
649}
650
651/* default cs val */
652static const u8 ps3av_mode_cs_info[] = {
653 0x00, 0x09, 0x00, 0x02, 0x01, 0x00, 0x00, 0x00
654};
655
656#define CS_44 0x00
657#define CS_48 0x02
658#define CS_88 0x08
659#define CS_96 0x0a
660#define CS_176 0x0c
661#define CS_192 0x0e
662#define CS_MASK 0x0f
663#define CS_BIT 0x40
664
665void ps3av_cmd_set_audio_mode(struct ps3av_pkt_audio_mode *audio, u32 avport,
666 u32 ch, u32 fs, u32 word_bits, u32 format,
667 u32 source)
668{
669 int spdif_through, spdif_bitstream;
670 int i;
671
672 if (!(ch | fs | format | word_bits | source)) {
673 ch = PS3AV_CMD_AUDIO_NUM_OF_CH_2;
674 fs = PS3AV_CMD_AUDIO_FS_48K;
675 word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
676 format = PS3AV_CMD_AUDIO_FORMAT_PCM;
677 source = PS3AV_CMD_AUDIO_SOURCE_SERIAL;
678 }
679 spdif_through = spdif_bitstream = 0; /* XXX not supported */
680
681 /* audio mode */
682 memset(audio, 0, sizeof(*audio));
683 ps3av_set_hdr(PS3AV_CID_AUDIO_MODE, sizeof(*audio), &audio->send_hdr);
684
685 audio->avport = (u8) avport;
686 audio->mask = 0x0FFF; /* XXX set all */
687 audio->audio_num_of_ch = ch;
688 audio->audio_fs = fs;
689 audio->audio_word_bits = word_bits;
690 audio->audio_format = format;
691 audio->audio_source = source;
692
693 switch (ch) {
694 case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
695 audio->audio_enable[3] = 1;
696 /* fall through */
697 case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
698 audio->audio_enable[2] = 1;
699 audio->audio_enable[1] = 1;
700 /* fall through */
701 case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
702 default:
703 audio->audio_enable[0] = 1;
704 }
705
706 /* audio swap L/R */
707 for (i = 0; i < 4; i++)
708 audio->audio_swap[i] = PS3AV_CMD_AUDIO_SWAP_0; /* no swap */
709
710 /* audio serial input mapping */
711 audio->audio_map[0] = PS3AV_CMD_AUDIO_MAP_OUTPUT_0;
712 audio->audio_map[1] = PS3AV_CMD_AUDIO_MAP_OUTPUT_1;
713 audio->audio_map[2] = PS3AV_CMD_AUDIO_MAP_OUTPUT_2;
714 audio->audio_map[3] = PS3AV_CMD_AUDIO_MAP_OUTPUT_3;
715
716 /* audio speaker layout */
717 if (avport == PS3AV_CMD_AVPORT_HDMI_0 ||
718 avport == PS3AV_CMD_AVPORT_HDMI_1) {
719 switch (ch) {
720 case PS3AV_CMD_AUDIO_NUM_OF_CH_8:
721 audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_8CH;
722 break;
723 case PS3AV_CMD_AUDIO_NUM_OF_CH_6:
724 audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_6CH;
725 break;
726 case PS3AV_CMD_AUDIO_NUM_OF_CH_2:
727 default:
728 audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
729 break;
730 }
731 } else {
732 audio->audio_layout = PS3AV_CMD_AUDIO_LAYOUT_2CH;
733 }
734
735 /* audio downmix permission */
736 audio->audio_downmix = PS3AV_CMD_AUDIO_DOWNMIX_PERMITTED;
737 /* audio downmix level shift (0:0dB to 15:15dB) */
738 audio->audio_downmix_level = 0; /* 0dB */
739
740 /* set ch status */
741 for (i = 0; i < 8; i++)
742 audio->audio_cs_info[i] = ps3av_mode_cs_info[i];
743
744 switch (fs) {
745 case PS3AV_CMD_AUDIO_FS_44K:
746 audio->audio_cs_info[3] &= ~CS_MASK;
747 audio->audio_cs_info[3] |= CS_44;
748 break;
749 case PS3AV_CMD_AUDIO_FS_88K:
750 audio->audio_cs_info[3] &= ~CS_MASK;
751 audio->audio_cs_info[3] |= CS_88;
752 break;
753 case PS3AV_CMD_AUDIO_FS_96K:
754 audio->audio_cs_info[3] &= ~CS_MASK;
755 audio->audio_cs_info[3] |= CS_96;
756 break;
757 case PS3AV_CMD_AUDIO_FS_176K:
758 audio->audio_cs_info[3] &= ~CS_MASK;
759 audio->audio_cs_info[3] |= CS_176;
760 break;
761 case PS3AV_CMD_AUDIO_FS_192K:
762 audio->audio_cs_info[3] &= ~CS_MASK;
763 audio->audio_cs_info[3] |= CS_192;
764 break;
765 default:
766 break;
767 }
768
769 /* pass through setting */
770 if (spdif_through &&
771 (avport == PS3AV_CMD_AVPORT_SPDIF_0 ||
772 avport == PS3AV_CMD_AVPORT_SPDIF_1)) {
773 audio->audio_word_bits = PS3AV_CMD_AUDIO_WORD_BITS_16;
774 audio->audio_source = PS3AV_CMD_AUDIO_SOURCE_SPDIF;
775 if (spdif_bitstream) {
776 audio->audio_format = PS3AV_CMD_AUDIO_FORMAT_BITSTREAM;
777 audio->audio_cs_info[0] |= CS_BIT;
778 }
779 }
780}
781
782int ps3av_cmd_audio_mode(struct ps3av_pkt_audio_mode *audio_mode)
783{
784 int res;
785
786 res = ps3av_do_pkt(PS3AV_CID_AUDIO_MODE, sizeof(*audio_mode),
787 sizeof(*audio_mode), &audio_mode->send_hdr);
788 if (res < 0)
789 return res;
790
791 res = get_status(audio_mode);
792 if (res)
793 printk(KERN_ERR "PS3AV_CID_AUDIO_MODE: failed %x\n", res);
794
795 return res;
796}
797
798int ps3av_cmd_audio_mute(int num_of_port, u32 *port, u32 mute)
799{
800 int i, res;
801 struct ps3av_pkt_audio_mute audio_mute;
802
803 if (num_of_port > PS3AV_OPT_PORT_MAX)
804 return -EINVAL;
805
806 /* audio mute */
807 memset(&audio_mute, 0, sizeof(audio_mute));
808 for (i = 0; i < num_of_port; i++) {
809 audio_mute.mute[i].avport = port[i];
810 audio_mute.mute[i].mute = mute;
811 }
812
813 res = ps3av_do_pkt(PS3AV_CID_AUDIO_MUTE,
814 sizeof(audio_mute.send_hdr) +
815 sizeof(struct ps3av_audio_mute) * num_of_port,
816 sizeof(audio_mute), &audio_mute.send_hdr);
817 if (res < 0)
818 return res;
819
820 res = get_status(&audio_mute);
821 if (res)
822 printk(KERN_ERR "PS3AV_CID_AUDIO_MUTE: failed %x\n", res);
823
824 return res;
825}
826
827int ps3av_cmd_audio_active(int active, u32 port)
828{
829 int res;
830 struct ps3av_pkt_audio_active audio_active;
831 u32 cid;
832
833 /* audio active */
834 memset(&audio_active, 0, sizeof(audio_active));
835 audio_active.audio_port = port;
836 cid = active ? PS3AV_CID_AUDIO_ACTIVE : PS3AV_CID_AUDIO_INACTIVE;
837
838 res = ps3av_do_pkt(cid, sizeof(audio_active), sizeof(audio_active),
839 &audio_active.send_hdr);
840 if (res < 0)
841 return res;
842
843 res = get_status(&audio_active);
844 if (res)
845 printk(KERN_ERR "PS3AV_CID_AUDIO_ACTIVE:%x failed %x\n", cid,
846 res);
847
848 return res;
849}
850
851int ps3av_cmd_avb_param(struct ps3av_pkt_avb_param *avb, u32 send_len)
852{
853 int res;
854
855 ps3fb_flip_ctl(0); /* flip off */
856
857 /* avb packet */
858 res = ps3av_do_pkt(PS3AV_CID_AVB_PARAM, send_len, sizeof(*avb),
859 &avb->send_hdr);
860 if (res < 0)
861 goto out;
862
863 res = get_status(avb);
864 if (res)
865 pr_debug("%s: PS3AV_CID_AVB_PARAM: failed %x\n", __FUNCTION__,
866 res);
867
868 out:
869 ps3fb_flip_ctl(1); /* flip on */
870 return res;
871}
872
873int ps3av_cmd_av_get_hw_conf(struct ps3av_pkt_av_get_hw_conf *hw_conf)
874{
875 int res;
876
877 memset(hw_conf, 0, sizeof(*hw_conf));
878
879 res = ps3av_do_pkt(PS3AV_CID_AV_GET_HW_CONF, sizeof(hw_conf->send_hdr),
880 sizeof(*hw_conf), &hw_conf->send_hdr);
881 if (res < 0)
882 return res;
883
884 res = get_status(hw_conf);
885 if (res)
886 printk(KERN_ERR "PS3AV_CID_AV_GET_HW_CONF: failed %x\n", res);
887
888 return res;
889}
890
891int ps3av_cmd_video_get_monitor_info(struct ps3av_pkt_av_get_monitor_info *info,
892 u32 avport)
893{
894 int res;
895
896 memset(info, 0, sizeof(*info));
897 info->avport = avport;
898
899 res = ps3av_do_pkt(PS3AV_CID_AV_GET_MONITOR_INFO,
900 sizeof(info->send_hdr) + sizeof(info->avport) +
901 sizeof(info->reserved),
902 sizeof(*info), &info->send_hdr);
903 if (res < 0)
904 return res;
905
906 res = get_status(info);
907 if (res)
908 printk(KERN_ERR "PS3AV_CID_AV_GET_MONITOR_INFO: failed %x\n",
909 res);
910
911 return res;
912}
913
914#ifdef PS3AV_DEBUG
915void ps3av_cmd_av_hw_conf_dump(const struct ps3av_pkt_av_get_hw_conf *hw_conf)
916{
917 printk("av_h_conf:num of hdmi:%d\n", hw_conf->num_of_hdmi);
918 printk("av_h_conf:num of avmulti:%d\n", hw_conf->num_of_avmulti);
919 printk("av_h_conf:num of spdif:%d\n", hw_conf->num_of_spdif);
920}
921
922void ps3av_cmd_av_monitor_info_dump(const struct ps3av_pkt_av_get_monitor_info *monitor_info)
923{
924 const struct ps3av_info_monitor *info = &monitor_info->info;
925 const struct ps3av_info_audio *audio = info->audio;
926 int i;
927
928 printk("Monitor Info: size%d\n", monitor_info->send_hdr.size);
929
930 printk("avport:%02x\n", info->avport);
931 printk("monitor_id:");
932 for (i = 0; i < 10; i++)
933 printk("%02x ", info->monitor_id[i]);
934 printk("\nmonitor_type:%02x\n", info->monitor_type);
935 printk("monitor_name:");
936 for (i = 0; i < 16; i++)
937 printk("%c", info->monitor_name[i]);
938
939 /* resolution */
940 printk("\nresolution_60: bits:%08x native:%08x\n",
941 info->res_60.res_bits, info->res_60.native);
942 printk("resolution_50: bits:%08x native:%08x\n",
943 info->res_50.res_bits, info->res_50.native);
944 printk("resolution_other: bits:%08x native:%08x\n",
945 info->res_other.res_bits, info->res_other.native);
946 printk("resolution_vesa: bits:%08x native:%08x\n",
947 info->res_vesa.res_bits, info->res_vesa.native);
948
949 /* color space */
950 printk("color space rgb:%02x\n", info->cs.rgb);
951 printk("color space yuv444:%02x\n", info->cs.yuv444);
952 printk("color space yuv422:%02x\n", info->cs.yuv422);
953
954 /* color info */
955 printk("color info red:X %04x Y %04x\n",
956 info->color.red_x, info->color.red_y);
957 printk("color info green:X %04x Y %04x\n",
958 info->color.green_x, info->color.green_y);
959 printk("color info blue:X %04x Y %04x\n",
960 info->color.blue_x, info->color.blue_y);
961 printk("color info white:X %04x Y %04x\n",
962 info->color.white_x, info->color.white_y);
963 printk("color info gamma: %08x\n", info->color.gamma);
964
965 /* other info */
966 printk("supported_AI:%02x\n", info->supported_ai);
967 printk("speaker_info:%02x\n", info->speaker_info);
968 printk("num of audio:%02x\n", info->num_of_audio_block);
969
970 /* audio block */
971 for (i = 0; i < info->num_of_audio_block; i++) {
972 printk("audio[%d] type:%02x max_ch:%02x fs:%02x sbit:%02x\n",
973 i, audio->type, audio->max_num_of_ch, audio->fs,
974 audio->sbit);
975 audio++;
976 }
977}
978#endif /* PS3AV_DEBUG */
979
980#define PS3AV_AV_LAYOUT_0 (PS3AV_CMD_AV_LAYOUT_32 \
981 | PS3AV_CMD_AV_LAYOUT_44 \
982 | PS3AV_CMD_AV_LAYOUT_48)
983
984#define PS3AV_AV_LAYOUT_1 (PS3AV_AV_LAYOUT_0 \
985 | PS3AV_CMD_AV_LAYOUT_88 \
986 | PS3AV_CMD_AV_LAYOUT_96 \
987 | PS3AV_CMD_AV_LAYOUT_176 \
988 | PS3AV_CMD_AV_LAYOUT_192)
989
990/************************* vuart ***************************/
991
992#define POLLING_INTERVAL 25 /* in msec */
993
994int ps3av_vuart_write(struct ps3_vuart_port_device *dev, const void *buf,
995 unsigned long size)
996{
997 int error = ps3_vuart_write(dev, buf, size);
998 return error ? error : size;
999}
1000
1001int ps3av_vuart_read(struct ps3_vuart_port_device *dev, void *buf,
1002 unsigned long size, int timeout)
1003{
1004 int error;
1005 int loopcnt = 0;
1006
1007 timeout = (timeout + POLLING_INTERVAL - 1) / POLLING_INTERVAL;
1008 while (loopcnt++ <= timeout) {
1009 error = ps3_vuart_read(dev, buf, size);
1010 if (!error)
1011 return size;
1012 if (error != -EAGAIN) {
1013 printk(KERN_ERR "%s: ps3_vuart_read failed %d\n",
1014 __FUNCTION__, error);
1015 return error;
1016 }
1017 msleep(POLLING_INTERVAL);
1018 }
1019 return -EWOULDBLOCK;
1020}
diff --git a/drivers/ps3/vuart.c b/drivers/ps3/vuart.c
index a72da8f651f..ef8fd4c3087 100644
--- a/drivers/ps3/vuart.c
+++ b/drivers/ps3/vuart.c
@@ -867,6 +867,22 @@ static int ps3_vuart_remove(struct device *_dev)
867 return 0; 867 return 0;
868} 868}
869 869
870static void ps3_vuart_shutdown(struct device *_dev)
871{
872 struct ps3_vuart_port_device *dev = to_ps3_vuart_port_device(_dev);
873 struct ps3_vuart_port_driver *drv =
874 to_ps3_vuart_port_driver(_dev->driver);
875
876 dev_dbg(&dev->core, "%s:%d: %s\n", __func__, __LINE__,
877 dev->core.bus_id);
878
879 if (drv->shutdown)
880 drv->shutdown(dev);
881 else
882 dev_dbg(&dev->core, "%s:%d: %s no shutdown method\n", __func__,
883 __LINE__, dev->core.bus_id);
884}
885
870/** 886/**
871 * ps3_vuart - The vuart instance. 887 * ps3_vuart - The vuart instance.
872 * 888 *
@@ -878,6 +894,7 @@ struct bus_type ps3_vuart = {
878 .match = ps3_vuart_match, 894 .match = ps3_vuart_match,
879 .probe = ps3_vuart_probe, 895 .probe = ps3_vuart_probe,
880 .remove = ps3_vuart_remove, 896 .remove = ps3_vuart_remove,
897 .shutdown = ps3_vuart_shutdown,
881}; 898};
882 899
883int __init ps3_vuart_init(void) 900int __init ps3_vuart_init(void)
diff --git a/drivers/ps3/vuart.h b/drivers/ps3/vuart.h
index 11c421cf7a0..2cbf728a3a0 100644
--- a/drivers/ps3/vuart.h
+++ b/drivers/ps3/vuart.h
@@ -30,6 +30,7 @@ struct ps3_vuart_port_driver {
30 struct device_driver core; 30 struct device_driver core;
31 int (*probe)(struct ps3_vuart_port_device *); 31 int (*probe)(struct ps3_vuart_port_device *);
32 int (*remove)(struct ps3_vuart_port_device *); 32 int (*remove)(struct ps3_vuart_port_device *);
33 void (*shutdown)(struct ps3_vuart_port_device *);
33 int (*tx_event)(struct ps3_vuart_port_device *dev); 34 int (*tx_event)(struct ps3_vuart_port_device *dev);
34 int (*rx_event)(struct ps3_vuart_port_device *dev); 35 int (*rx_event)(struct ps3_vuart_port_device *dev);
35 int (*disconnect_event)(struct ps3_vuart_port_device *dev); 36 int (*disconnect_event)(struct ps3_vuart_port_device *dev);
diff --git a/drivers/rapidio/rio-scan.c b/drivers/rapidio/rio-scan.c
index 7bf7b2c8824..f935c1f71a5 100644
--- a/drivers/rapidio/rio-scan.c
+++ b/drivers/rapidio/rio-scan.c
@@ -326,14 +326,17 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
326 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR, 326 rio_mport_read_config_32(port, destid, hopcount, RIO_DST_OPS_CAR,
327 &rdev->dst_ops); 327 &rdev->dst_ops);
328 328
329 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops) 329 if (rio_device_has_destid(port, rdev->src_ops, rdev->dst_ops)) {
330 && do_enum) { 330 if (do_enum) {
331 rio_set_device_id(port, destid, hopcount, next_destid); 331 rio_set_device_id(port, destid, hopcount, next_destid);
332 rdev->destid = next_destid++; 332 rdev->destid = next_destid++;
333 if (next_destid == port->host_deviceid) 333 if (next_destid == port->host_deviceid)
334 next_destid++; 334 next_destid++;
335 } else
336 rdev->destid = rio_get_device_id(port, destid, hopcount);
335 } else 337 } else
336 rdev->destid = rio_get_device_id(port, destid, hopcount); 338 /* Switch device has an associated destID */
339 rdev->destid = RIO_INVALID_DESTID;
337 340
338 /* If a PE has both switch and other functions, show it as a switch */ 341 /* If a PE has both switch and other functions, show it as a switch */
339 if (rio_is_switch(rdev)) { 342 if (rio_is_switch(rdev)) {
@@ -347,7 +350,7 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
347 } 350 }
348 rswitch->switchid = next_switchid; 351 rswitch->switchid = next_switchid;
349 rswitch->hopcount = hopcount; 352 rswitch->hopcount = hopcount;
350 rswitch->destid = 0xffff; 353 rswitch->destid = destid;
351 /* Initialize switch route table */ 354 /* Initialize switch route table */
352 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES; rdid++) 355 for (rdid = 0; rdid < RIO_MAX_ROUTE_ENTRIES; rdid++)
353 rswitch->route_table[rdid] = RIO_INVALID_ROUTE; 356 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
@@ -422,7 +425,7 @@ rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
422/** 425/**
423 * rio_route_add_entry- Add a route entry to a switch routing table 426 * rio_route_add_entry- Add a route entry to a switch routing table
424 * @mport: Master port to send transaction 427 * @mport: Master port to send transaction
425 * @rdev: Switch device 428 * @rswitch: Switch device
426 * @table: Routing table ID 429 * @table: Routing table ID
427 * @route_destid: Destination ID to be routed 430 * @route_destid: Destination ID to be routed
428 * @route_port: Port number to be routed 431 * @route_port: Port number to be routed
@@ -434,18 +437,18 @@ rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
434 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL 437 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
435 * on failure. 438 * on failure.
436 */ 439 */
437static int rio_route_add_entry(struct rio_mport *mport, struct rio_dev *rdev, 440static int rio_route_add_entry(struct rio_mport *mport, struct rio_switch *rswitch,
438 u16 table, u16 route_destid, u8 route_port) 441 u16 table, u16 route_destid, u8 route_port)
439{ 442{
440 return rdev->rswitch->add_entry(mport, rdev->rswitch->destid, 443 return rswitch->add_entry(mport, rswitch->destid,
441 rdev->rswitch->hopcount, table, 444 rswitch->hopcount, table,
442 route_destid, route_port); 445 route_destid, route_port);
443} 446}
444 447
445/** 448/**
446 * rio_route_get_entry- Read a route entry in a switch routing table 449 * rio_route_get_entry- Read a route entry in a switch routing table
447 * @mport: Master port to send transaction 450 * @mport: Master port to send transaction
448 * @rdev: Switch device 451 * @rswitch: Switch device
449 * @table: Routing table ID 452 * @table: Routing table ID
450 * @route_destid: Destination ID to be routed 453 * @route_destid: Destination ID to be routed
451 * @route_port: Pointer to read port number into 454 * @route_port: Pointer to read port number into
@@ -458,11 +461,11 @@ static int rio_route_add_entry(struct rio_mport *mport, struct rio_dev *rdev,
458 * on failure. 461 * on failure.
459 */ 462 */
460static int 463static int
461rio_route_get_entry(struct rio_mport *mport, struct rio_dev *rdev, u16 table, 464rio_route_get_entry(struct rio_mport *mport, struct rio_switch *rswitch, u16 table,
462 u16 route_destid, u8 * route_port) 465 u16 route_destid, u8 * route_port)
463{ 466{
464 return rdev->rswitch->get_entry(mport, rdev->rswitch->destid, 467 return rswitch->get_entry(mport, rswitch->destid,
465 rdev->rswitch->hopcount, table, 468 rswitch->hopcount, table,
466 route_destid, route_port); 469 route_destid, route_port);
467} 470}
468 471
@@ -552,6 +555,8 @@ static int rio_enum_peer(struct rio_net *net, struct rio_mport *port,
552 int port_num; 555 int port_num;
553 int num_ports; 556 int num_ports;
554 int cur_destid; 557 int cur_destid;
558 int sw_destid;
559 int sw_inport;
555 struct rio_dev *rdev; 560 struct rio_dev *rdev;
556 u16 destid; 561 u16 destid;
557 int tmp; 562 int tmp;
@@ -594,15 +599,17 @@ static int rio_enum_peer(struct rio_net *net, struct rio_mport *port,
594 599
595 if (rio_is_switch(rdev)) { 600 if (rio_is_switch(rdev)) {
596 next_switchid++; 601 next_switchid++;
602 sw_inport = rio_get_swpinfo_inport(port, RIO_ANY_DESTID, hopcount);
603 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
604 port->host_deviceid, sw_inport);
605 rdev->rswitch->route_table[port->host_deviceid] = sw_inport;
597 606
598 for (destid = 0; destid < next_destid; destid++) { 607 for (destid = 0; destid < next_destid; destid++) {
599 rio_route_add_entry(port, rdev, RIO_GLOBAL_TABLE, 608 if (destid == port->host_deviceid)
600 destid, rio_get_swpinfo_inport(port, 609 continue;
601 RIO_ANY_DESTID, 610 rio_route_add_entry(port, rdev->rswitch, RIO_GLOBAL_TABLE,
602 hopcount)); 611 destid, sw_inport);
603 rdev->rswitch->route_table[destid] = 612 rdev->rswitch->route_table[destid] = sw_inport;
604 rio_get_swpinfo_inport(port, RIO_ANY_DESTID,
605 hopcount);
606 } 613 }
607 614
608 num_ports = 615 num_ports =
@@ -610,9 +617,9 @@ static int rio_enum_peer(struct rio_net *net, struct rio_mport *port,
610 pr_debug( 617 pr_debug(
611 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n", 618 "RIO: found %s (vid %4.4x did %4.4x) with %d ports\n",
612 rio_name(rdev), rdev->vid, rdev->did, num_ports); 619 rio_name(rdev), rdev->vid, rdev->did, num_ports);
620 sw_destid = next_destid;
613 for (port_num = 0; port_num < num_ports; port_num++) { 621 for (port_num = 0; port_num < num_ports; port_num++) {
614 if (rio_get_swpinfo_inport 622 if (sw_inport == port_num)
615 (port, RIO_ANY_DESTID, hopcount) == port_num)
616 continue; 623 continue;
617 624
618 cur_destid = next_destid; 625 cur_destid = next_destid;
@@ -622,7 +629,7 @@ static int rio_enum_peer(struct rio_net *net, struct rio_mport *port,
622 pr_debug( 629 pr_debug(
623 "RIO: scanning device on port %d\n", 630 "RIO: scanning device on port %d\n",
624 port_num); 631 port_num);
625 rio_route_add_entry(port, rdev, 632 rio_route_add_entry(port, rdev->rswitch,
626 RIO_GLOBAL_TABLE, 633 RIO_GLOBAL_TABLE,
627 RIO_ANY_DESTID, port_num); 634 RIO_ANY_DESTID, port_num);
628 635
@@ -633,7 +640,9 @@ static int rio_enum_peer(struct rio_net *net, struct rio_mport *port,
633 if (next_destid > cur_destid) { 640 if (next_destid > cur_destid) {
634 for (destid = cur_destid; 641 for (destid = cur_destid;
635 destid < next_destid; destid++) { 642 destid < next_destid; destid++) {
636 rio_route_add_entry(port, rdev, 643 if (destid == port->host_deviceid)
644 continue;
645 rio_route_add_entry(port, rdev->rswitch,
637 RIO_GLOBAL_TABLE, 646 RIO_GLOBAL_TABLE,
638 destid, 647 destid,
639 port_num); 648 port_num);
@@ -641,10 +650,18 @@ static int rio_enum_peer(struct rio_net *net, struct rio_mport *port,
641 route_table[destid] = 650 route_table[destid] =
642 port_num; 651 port_num;
643 } 652 }
644 rdev->rswitch->destid = cur_destid;
645 } 653 }
646 } 654 }
647 } 655 }
656
657 /* Check for empty switch */
658 if (next_destid == sw_destid) {
659 next_destid++;
660 if (next_destid == port->host_deviceid)
661 next_destid++;
662 }
663
664 rdev->rswitch->destid = sw_destid;
648 } else 665 } else
649 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n", 666 pr_debug("RIO: found %s (vid %4.4x did %4.4x)\n",
650 rio_name(rdev), rdev->vid, rdev->did); 667 rio_name(rdev), rdev->vid, rdev->did);
@@ -721,7 +738,7 @@ rio_disc_peer(struct rio_net *net, struct rio_mport *port, u16 destid,
721 port_num); 738 port_num);
722 for (ndestid = 0; ndestid < RIO_ANY_DESTID; 739 for (ndestid = 0; ndestid < RIO_ANY_DESTID;
723 ndestid++) { 740 ndestid++) {
724 rio_route_get_entry(port, rdev, 741 rio_route_get_entry(port, rdev->rswitch,
725 RIO_GLOBAL_TABLE, 742 RIO_GLOBAL_TABLE,
726 ndestid, 743 ndestid,
727 &route_port); 744 &route_port);
@@ -798,6 +815,44 @@ static struct rio_net __devinit *rio_alloc_net(struct rio_mport *port)
798} 815}
799 816
800/** 817/**
818 * rio_update_route_tables- Updates route tables in switches
819 * @port: Master port associated with the RIO network
820 *
821 * For each enumerated device, ensure that each switch in a system
822 * has correct routing entries. Add routes for devices that where
823 * unknown dirung the first enumeration pass through the switch.
824 */
825static void rio_update_route_tables(struct rio_mport *port)
826{
827 struct rio_dev *rdev;
828 struct rio_switch *rswitch;
829 u8 sport;
830 u16 destid;
831
832 list_for_each_entry(rdev, &rio_devices, global_list) {
833
834 destid = (rio_is_switch(rdev))?rdev->rswitch->destid:rdev->destid;
835
836 list_for_each_entry(rswitch, &rio_switches, node) {
837
838 if (rio_is_switch(rdev) && (rdev->rswitch == rswitch))
839 continue;
840
841 if (RIO_INVALID_ROUTE == rswitch->route_table[destid]) {
842
843 sport = rio_get_swpinfo_inport(port,
844 rswitch->destid, rswitch->hopcount);
845
846 if (rswitch->add_entry) {
847 rio_route_add_entry(port, rswitch, RIO_GLOBAL_TABLE, destid, sport);
848 rswitch->route_table[destid] = sport;
849 }
850 }
851 }
852 }
853}
854
855/**
801 * rio_enum_mport- Start enumeration through a master port 856 * rio_enum_mport- Start enumeration through a master port
802 * @mport: Master port to send transactions 857 * @mport: Master port to send transactions
803 * 858 *
@@ -838,6 +893,7 @@ int rio_enum_mport(struct rio_mport *mport)
838 rc = -EBUSY; 893 rc = -EBUSY;
839 goto out; 894 goto out;
840 } 895 }
896 rio_update_route_tables(mport);
841 rio_clear_locks(mport); 897 rio_clear_locks(mport);
842 } else { 898 } else {
843 printk(KERN_INFO "RIO: master port %d link inactive\n", 899 printk(KERN_INFO "RIO: master port %d link inactive\n",
@@ -865,8 +921,8 @@ static void rio_build_route_tables(void)
865 if (rio_is_switch(rdev)) 921 if (rio_is_switch(rdev))
866 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES; i++) { 922 for (i = 0; i < RIO_MAX_ROUTE_ENTRIES; i++) {
867 if (rio_route_get_entry 923 if (rio_route_get_entry
868 (rdev->net->hport, rdev, RIO_GLOBAL_TABLE, i, 924 (rdev->net->hport, rdev->rswitch, RIO_GLOBAL_TABLE,
869 &sport) < 0) 925 i, &sport) < 0)
870 continue; 926 continue;
871 rdev->rswitch->route_table[i] = sport; 927 rdev->rswitch->route_table[i] = sport;
872 } 928 }
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index 09660e2ab05..4bbca500d3d 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1,4 +1,4 @@
1\# 1#
2# RTC class/drivers configuration 2# RTC class/drivers configuration
3# 3#
4 4
@@ -95,6 +95,29 @@ config RTC_INTF_DEV_UIE_EMUL
95comment "RTC drivers" 95comment "RTC drivers"
96 depends on RTC_CLASS 96 depends on RTC_CLASS
97 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_PC || 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
98config RTC_DRV_X1205 121config RTC_DRV_X1205
99 tristate "Xicor/Intersil X1205" 122 tristate "Xicor/Intersil X1205"
100 depends on RTC_CLASS && I2C 123 depends on RTC_CLASS && I2C
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index e6beedacc96..92bfe1b3a5f 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
15obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o 15obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
16obj-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o 16obj-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o
17 17
18obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
18obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o 19obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
19obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 20obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
20obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o 21obj-$(CONFIG_RTC_DRV_TEST) += rtc-test.o
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
new file mode 100644
index 00000000000..85bf795abdc
--- /dev/null
+++ b/drivers/rtc/rtc-cmos.c
@@ -0,0 +1,725 @@
1/*
2 * RTC class driver for "CMOS RTC": PCs, ACPI, etc
3 *
4 * Copyright (C) 1996 Paul Gortmaker (drivers/char/rtc.c)
5 * Copyright (C) 2006 David Brownell (convert to new framework)
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
13/*
14 * The original "cmos clock" chip was an MC146818 chip, now obsolete.
15 * That defined the register interface now provided by all PCs, some
16 * non-PC systems, and incorporated into ACPI. Modern PC chipsets
17 * integrate an MC146818 clone in their southbridge, and boards use
18 * that instead of discrete clones like the DS12887 or M48T86. There
19 * are also clones that connect using the LPC bus.
20 *
21 * That register API is also used directly by various other drivers
22 * (notably for integrated NVRAM), infrastructure (x86 has code to
23 * bypass the RTC framework, directly reading the RTC during boot
24 * and updating minutes/seconds for systems using NTP synch) and
25 * utilities (like userspace 'hwclock', if no /dev node exists).
26 *
27 * So **ALL** calls to CMOS_READ and CMOS_WRITE must be done with
28 * interrupts disabled, holding the global rtc_lock, to exclude those
29 * other drivers and utilities on correctly configured systems.
30 */
31#include <linux/kernel.h>
32#include <linux/module.h>
33#include <linux/init.h>
34#include <linux/interrupt.h>
35#include <linux/spinlock.h>
36#include <linux/platform_device.h>
37#include <linux/mod_devicetable.h>
38
39/* this is for "generic access to PC-style RTC" using CMOS_READ/CMOS_WRITE */
40#include <asm-generic/rtc.h>
41
42
43struct cmos_rtc {
44 struct rtc_device *rtc;
45 struct device *dev;
46 int irq;
47 struct resource *iomem;
48
49 u8 suspend_ctrl;
50
51 /* newer hardware extends the original register set */
52 u8 day_alrm;
53 u8 mon_alrm;
54 u8 century;
55};
56
57/* both platform and pnp busses use negative numbers for invalid irqs */
58#define is_valid_irq(n) ((n) >= 0)
59
60static const char driver_name[] = "rtc_cmos";
61
62/*----------------------------------------------------------------*/
63
64static int cmos_read_time(struct device *dev, struct rtc_time *t)
65{
66 /* REVISIT: if the clock has a "century" register, use
67 * that instead of the heuristic in get_rtc_time().
68 * That'll make Y3K compatility (year > 2070) easy!
69 */
70 get_rtc_time(t);
71 return 0;
72}
73
74static int cmos_set_time(struct device *dev, struct rtc_time *t)
75{
76 /* REVISIT: set the "century" register if available
77 *
78 * NOTE: this ignores the issue whereby updating the seconds
79 * takes effect exactly 500ms after we write the register.
80 * (Also queueing and other delays before we get this far.)
81 */
82 return set_rtc_time(t);
83}
84
85static int cmos_read_alarm(struct device *dev, struct rtc_wkalrm *t)
86{
87 struct cmos_rtc *cmos = dev_get_drvdata(dev);
88 unsigned char rtc_control;
89
90 if (!is_valid_irq(cmos->irq))
91 return -EIO;
92
93 /* Basic alarms only support hour, minute, and seconds fields.
94 * Some also support day and month, for alarms up to a year in
95 * the future.
96 */
97 t->time.tm_mday = -1;
98 t->time.tm_mon = -1;
99
100 spin_lock_irq(&rtc_lock);
101 t->time.tm_sec = CMOS_READ(RTC_SECONDS_ALARM);
102 t->time.tm_min = CMOS_READ(RTC_MINUTES_ALARM);
103 t->time.tm_hour = CMOS_READ(RTC_HOURS_ALARM);
104
105 if (cmos->day_alrm) {
106 t->time.tm_mday = CMOS_READ(cmos->day_alrm);
107 if (!t->time.tm_mday)
108 t->time.tm_mday = -1;
109
110 if (cmos->mon_alrm) {
111 t->time.tm_mon = CMOS_READ(cmos->mon_alrm);
112 if (!t->time.tm_mon)
113 t->time.tm_mon = -1;
114 }
115 }
116
117 rtc_control = CMOS_READ(RTC_CONTROL);
118 spin_unlock_irq(&rtc_lock);
119
120 /* REVISIT this assumes PC style usage: always BCD */
121
122 if (((unsigned)t->time.tm_sec) < 0x60)
123 t->time.tm_sec = BCD2BIN(t->time.tm_sec);
124 else
125 t->time.tm_sec = -1;
126 if (((unsigned)t->time.tm_min) < 0x60)
127 t->time.tm_min = BCD2BIN(t->time.tm_min);
128 else
129 t->time.tm_min = -1;
130 if (((unsigned)t->time.tm_hour) < 0x24)
131 t->time.tm_hour = BCD2BIN(t->time.tm_hour);
132 else
133 t->time.tm_hour = -1;
134
135 if (cmos->day_alrm) {
136 if (((unsigned)t->time.tm_mday) <= 0x31)
137 t->time.tm_mday = BCD2BIN(t->time.tm_mday);
138 else
139 t->time.tm_mday = -1;
140 if (cmos->mon_alrm) {
141 if (((unsigned)t->time.tm_mon) <= 0x12)
142 t->time.tm_mon = BCD2BIN(t->time.tm_mon) - 1;
143 else
144 t->time.tm_mon = -1;
145 }
146 }
147 t->time.tm_year = -1;
148
149 t->enabled = !!(rtc_control & RTC_AIE);
150 t->pending = 0;
151
152 return 0;
153}
154
155static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
156{
157 struct cmos_rtc *cmos = dev_get_drvdata(dev);
158 unsigned char mon, mday, hrs, min, sec;
159 unsigned char rtc_control, rtc_intr;
160
161 if (!is_valid_irq(cmos->irq))
162 return -EIO;
163
164 /* REVISIT this assumes PC style usage: always BCD */
165
166 /* Writing 0xff means "don't care" or "match all". */
167
168 mon = t->time.tm_mon;
169 mon = (mon < 12) ? BIN2BCD(mon) : 0xff;
170 mon++;
171
172 mday = t->time.tm_mday;
173 mday = (mday >= 1 && mday <= 31) ? BIN2BCD(mday) : 0xff;
174
175 hrs = t->time.tm_hour;
176 hrs = (hrs < 24) ? BIN2BCD(hrs) : 0xff;
177
178 min = t->time.tm_min;
179 min = (min < 60) ? BIN2BCD(min) : 0xff;
180
181 sec = t->time.tm_sec;
182 sec = (sec < 60) ? BIN2BCD(sec) : 0xff;
183
184 spin_lock_irq(&rtc_lock);
185
186 /* next rtc irq must not be from previous alarm setting */
187 rtc_control = CMOS_READ(RTC_CONTROL);
188 rtc_control &= ~RTC_AIE;
189 CMOS_WRITE(rtc_control, RTC_CONTROL);
190 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
191 if (rtc_intr)
192 rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr);
193
194 /* update alarm */
195 CMOS_WRITE(hrs, RTC_HOURS_ALARM);
196 CMOS_WRITE(min, RTC_MINUTES_ALARM);
197 CMOS_WRITE(sec, RTC_SECONDS_ALARM);
198
199 /* the system may support an "enhanced" alarm */
200 if (cmos->day_alrm) {
201 CMOS_WRITE(mday, cmos->day_alrm);
202 if (cmos->mon_alrm)
203 CMOS_WRITE(mon, cmos->mon_alrm);
204 }
205
206 if (t->enabled) {
207 rtc_control |= RTC_AIE;
208 CMOS_WRITE(rtc_control, RTC_CONTROL);
209 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
210 if (rtc_intr)
211 rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr);
212 }
213
214 spin_unlock_irq(&rtc_lock);
215
216 return 0;
217}
218
219static int cmos_set_freq(struct device *dev, int freq)
220{
221 struct cmos_rtc *cmos = dev_get_drvdata(dev);
222 int f;
223 unsigned long flags;
224
225 if (!is_valid_irq(cmos->irq))
226 return -ENXIO;
227
228 /* 0 = no irqs; 1 = 2^15 Hz ... 15 = 2^0 Hz */
229 f = ffs(freq);
230 if (f != 0) {
231 if (f-- > 16 || freq != (1 << f))
232 return -EINVAL;
233 f = 16 - f;
234 }
235
236 spin_lock_irqsave(&rtc_lock, flags);
237 CMOS_WRITE(RTC_REF_CLCK_32KHZ | f, RTC_FREQ_SELECT);
238 spin_unlock_irqrestore(&rtc_lock, flags);
239
240 return 0;
241}
242
243#if defined(CONFIG_RTC_INTF_DEV) || defined(CONFIG_RTC_INTF_DEV_MODULE)
244
245static int
246cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
247{
248 struct cmos_rtc *cmos = dev_get_drvdata(dev);
249 unsigned char rtc_control, rtc_intr;
250 unsigned long flags;
251
252 switch (cmd) {
253 case RTC_AIE_OFF:
254 case RTC_AIE_ON:
255 case RTC_UIE_OFF:
256 case RTC_UIE_ON:
257 case RTC_PIE_OFF:
258 case RTC_PIE_ON:
259 if (!is_valid_irq(cmos->irq))
260 return -EINVAL;
261 break;
262 default:
263 return -ENOIOCTLCMD;
264 }
265
266 spin_lock_irqsave(&rtc_lock, flags);
267 rtc_control = CMOS_READ(RTC_CONTROL);
268 switch (cmd) {
269 case RTC_AIE_OFF: /* alarm off */
270 rtc_control &= ~RTC_AIE;
271 break;
272 case RTC_AIE_ON: /* alarm on */
273 rtc_control |= RTC_AIE;
274 break;
275 case RTC_UIE_OFF: /* update off */
276 rtc_control &= ~RTC_UIE;
277 break;
278 case RTC_UIE_ON: /* update on */
279 rtc_control |= RTC_UIE;
280 break;
281 case RTC_PIE_OFF: /* periodic off */
282 rtc_control &= ~RTC_PIE;
283 break;
284 case RTC_PIE_ON: /* periodic on */
285 rtc_control |= RTC_PIE;
286 break;
287 }
288 CMOS_WRITE(rtc_control, RTC_CONTROL);
289 rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
290 if (rtc_intr)
291 rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr);
292 spin_unlock_irqrestore(&rtc_lock, flags);
293 return 0;
294}
295
296#else
297#define cmos_rtc_ioctl NULL
298#endif
299
300#if defined(CONFIG_RTC_INTF_PROC) || defined(CONFIG_RTC_INTF_PROC_MODULE)
301
302static int cmos_procfs(struct device *dev, struct seq_file *seq)
303{
304 struct cmos_rtc *cmos = dev_get_drvdata(dev);
305 unsigned char rtc_control, valid;
306
307 spin_lock_irq(&rtc_lock);
308 rtc_control = CMOS_READ(RTC_CONTROL);
309 valid = CMOS_READ(RTC_VALID);
310 spin_unlock_irq(&rtc_lock);
311
312 /* NOTE: at least ICH6 reports battery status using a different
313 * (non-RTC) bit; and SQWE is ignored on many current systems.
314 */
315 return seq_printf(seq,
316 "periodic_IRQ\t: %s\n"
317 "update_IRQ\t: %s\n"
318 // "square_wave\t: %s\n"
319 // "BCD\t\t: %s\n"
320 "DST_enable\t: %s\n"
321 "periodic_freq\t: %d\n"
322 "batt_status\t: %s\n",
323 (rtc_control & RTC_PIE) ? "yes" : "no",
324 (rtc_control & RTC_UIE) ? "yes" : "no",
325 // (rtc_control & RTC_SQWE) ? "yes" : "no",
326 // (rtc_control & RTC_DM_BINARY) ? "no" : "yes",
327 (rtc_control & RTC_DST_EN) ? "yes" : "no",
328 cmos->rtc->irq_freq,
329 (valid & RTC_VRT) ? "okay" : "dead");
330}
331
332#else
333#define cmos_procfs NULL
334#endif
335
336static const struct rtc_class_ops cmos_rtc_ops = {
337 .ioctl = cmos_rtc_ioctl,
338 .read_time = cmos_read_time,
339 .set_time = cmos_set_time,
340 .read_alarm = cmos_read_alarm,
341 .set_alarm = cmos_set_alarm,
342 .proc = cmos_procfs,
343 .irq_set_freq = cmos_set_freq,
344};
345
346/*----------------------------------------------------------------*/
347
348static struct cmos_rtc cmos_rtc;
349
350static irqreturn_t cmos_interrupt(int irq, void *p)
351{
352 u8 irqstat;
353
354 spin_lock(&rtc_lock);
355 irqstat = CMOS_READ(RTC_INTR_FLAGS);
356 spin_unlock(&rtc_lock);
357
358 if (irqstat) {
359 /* NOTE: irqstat may have e.g. RTC_PF set
360 * even when RTC_PIE is clear...
361 */
362 rtc_update_irq(p, 1, irqstat);
363 return IRQ_HANDLED;
364 } else
365 return IRQ_NONE;
366}
367
368#ifdef CONFIG_PNPACPI
369#define is_pnpacpi() 1
370#define INITSECTION
371
372#else
373#define is_pnpacpi() 0
374#define INITSECTION __init
375#endif
376
377static int INITSECTION
378cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
379{
380 struct cmos_rtc_board_info *info = dev->platform_data;
381 int retval = 0;
382 unsigned char rtc_control;
383
384 /* there can be only one ... */
385 if (cmos_rtc.dev)
386 return -EBUSY;
387
388 if (!ports)
389 return -ENODEV;
390
391 cmos_rtc.irq = rtc_irq;
392 cmos_rtc.iomem = ports;
393
394 /* For ACPI systems the info comes from the FADT. On others,
395 * board specific setup provides it as appropriate.
396 */
397 if (info) {
398 cmos_rtc.day_alrm = info->rtc_day_alarm;
399 cmos_rtc.mon_alrm = info->rtc_mon_alarm;
400 cmos_rtc.century = info->rtc_century;
401 }
402
403 cmos_rtc.rtc = rtc_device_register(driver_name, dev,
404 &cmos_rtc_ops, THIS_MODULE);
405 if (IS_ERR(cmos_rtc.rtc))
406 return PTR_ERR(cmos_rtc.rtc);
407
408 cmos_rtc.dev = dev;
409 dev_set_drvdata(dev, &cmos_rtc);
410
411 /* platform and pnp busses handle resources incompatibly.
412 *
413 * REVISIT for non-x86 systems we may need to handle io memory
414 * resources: ioremap them, and request_mem_region().
415 */
416 if (is_pnpacpi()) {
417 retval = request_resource(&ioport_resource, ports);
418 if (retval < 0) {
419 dev_dbg(dev, "i/o registers already in use\n");
420 goto cleanup0;
421 }
422 }
423 rename_region(ports, cmos_rtc.rtc->class_dev.class_id);
424
425 spin_lock_irq(&rtc_lock);
426
427 /* force periodic irq to CMOS reset default of 1024Hz;
428 *
429 * REVISIT it's been reported that at least one x86_64 ALI mobo
430 * doesn't use 32KHz here ... for portability we might need to
431 * do something about other clock frequencies.
432 */
433 CMOS_WRITE(RTC_REF_CLCK_32KHZ | 0x06, RTC_FREQ_SELECT);
434 cmos_rtc.rtc->irq_freq = 1024;
435
436 /* disable irqs.
437 *
438 * NOTE after changing RTC_xIE bits we always read INTR_FLAGS;
439 * allegedly some older rtcs need that to handle irqs properly
440 */
441 rtc_control = CMOS_READ(RTC_CONTROL);
442 rtc_control &= ~(RTC_PIE | RTC_AIE | RTC_UIE);
443 CMOS_WRITE(rtc_control, RTC_CONTROL);
444 CMOS_READ(RTC_INTR_FLAGS);
445
446 spin_unlock_irq(&rtc_lock);
447
448 /* FIXME teach the alarm code how to handle binary mode;
449 * <asm-generic/rtc.h> doesn't know 12-hour mode either.
450 */
451 if (!(rtc_control & RTC_24H) || (rtc_control & (RTC_DM_BINARY))) {
452 dev_dbg(dev, "only 24-hr BCD mode supported\n");
453 retval = -ENXIO;
454 goto cleanup1;
455 }
456
457 if (is_valid_irq(rtc_irq))
458 retval = request_irq(rtc_irq, cmos_interrupt, IRQF_DISABLED,
459 cmos_rtc.rtc->class_dev.class_id,
460 &cmos_rtc.rtc->class_dev);
461 if (retval < 0) {
462 dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
463 goto cleanup1;
464 }
465
466 /* REVISIT optionally make 50 or 114 bytes NVRAM available,
467 * like rtc-ds1553, rtc-ds1742 ... this will often include
468 * registers for century, and day/month alarm.
469 */
470
471 pr_info("%s: alarms up to one %s%s\n",
472 cmos_rtc.rtc->class_dev.class_id,
473 is_valid_irq(rtc_irq)
474 ? (cmos_rtc.mon_alrm
475 ? "year"
476 : (cmos_rtc.day_alrm
477 ? "month" : "day"))
478 : "no",
479 cmos_rtc.century ? ", y3k" : ""
480 );
481
482 return 0;
483
484cleanup1:
485 rename_region(ports, NULL);
486cleanup0:
487 rtc_device_unregister(cmos_rtc.rtc);
488 return retval;
489}
490
491static void cmos_do_shutdown(void)
492{
493 unsigned char rtc_control;
494
495 spin_lock_irq(&rtc_lock);
496 rtc_control = CMOS_READ(RTC_CONTROL);
497 rtc_control &= ~(RTC_PIE|RTC_AIE|RTC_UIE);
498 CMOS_WRITE(rtc_control, RTC_CONTROL);
499 CMOS_READ(RTC_INTR_FLAGS);
500 spin_unlock_irq(&rtc_lock);
501}
502
503static void __exit cmos_do_remove(struct device *dev)
504{
505 struct cmos_rtc *cmos = dev_get_drvdata(dev);
506
507 cmos_do_shutdown();
508
509 if (is_pnpacpi())
510 release_resource(cmos->iomem);
511 rename_region(cmos->iomem, NULL);
512
513 if (is_valid_irq(cmos->irq))
514 free_irq(cmos->irq, &cmos_rtc.rtc->class_dev);
515
516 rtc_device_unregister(cmos_rtc.rtc);
517
518 cmos_rtc.dev = NULL;
519 dev_set_drvdata(dev, NULL);
520}
521
522#ifdef CONFIG_PM
523
524static int cmos_suspend(struct device *dev, pm_message_t mesg)
525{
526 struct cmos_rtc *cmos = dev_get_drvdata(dev);
527 int do_wake = device_may_wakeup(dev);
528 unsigned char tmp, irqstat;
529
530 /* only the alarm might be a wakeup event source */
531 spin_lock_irq(&rtc_lock);
532 cmos->suspend_ctrl = tmp = CMOS_READ(RTC_CONTROL);
533 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) {
534 if (do_wake)
535 tmp &= ~(RTC_PIE|RTC_UIE);
536 else
537 tmp &= ~(RTC_PIE|RTC_AIE|RTC_UIE);
538 CMOS_WRITE(tmp, RTC_CONTROL);
539 irqstat = CMOS_READ(RTC_INTR_FLAGS);
540 } else
541 irqstat = 0;
542 spin_unlock_irq(&rtc_lock);
543
544 if (irqstat)
545 rtc_update_irq(&cmos->rtc->class_dev, 1, irqstat);
546
547 /* ACPI HOOK: enable ACPI_EVENT_RTC when (tmp & RTC_AIE)
548 * ... it'd be best if we could do that under rtc_lock.
549 */
550
551 pr_debug("%s: suspend%s, ctrl %02x\n",
552 cmos_rtc.rtc->class_dev.class_id,
553 (tmp & RTC_AIE) ? ", alarm may wake" : "",
554 tmp);
555
556 return 0;
557}
558
559static int cmos_resume(struct device *dev)
560{
561 struct cmos_rtc *cmos = dev_get_drvdata(dev);
562 unsigned char tmp = cmos->suspend_ctrl;
563
564 /* REVISIT: a mechanism to resync the system clock (jiffies)
565 * on resume should be portable between platforms ...
566 */
567
568 /* re-enable any irqs previously active */
569 if (tmp & (RTC_PIE|RTC_AIE|RTC_UIE)) {
570
571 /* ACPI HOOK: disable ACPI_EVENT_RTC when (tmp & RTC_AIE) */
572
573 spin_lock_irq(&rtc_lock);
574 CMOS_WRITE(tmp, RTC_CONTROL);
575 tmp = CMOS_READ(RTC_INTR_FLAGS);
576 spin_unlock_irq(&rtc_lock);
577 if (tmp)
578 rtc_update_irq(&cmos->rtc->class_dev, 1, tmp);
579 }
580
581 pr_debug("%s: resume, ctrl %02x\n",
582 cmos_rtc.rtc->class_dev.class_id,
583 cmos->suspend_ctrl);
584
585
586 return 0;
587}
588
589#else
590#define cmos_suspend NULL
591#define cmos_resume NULL
592#endif
593
594/*----------------------------------------------------------------*/
595
596/* The "CMOS" RTC normally lives on the platform_bus. On ACPI systems,
597 * the device node may alternatively be created as a PNP device.
598 */
599
600#ifdef CONFIG_PNPACPI
601
602#include <linux/pnp.h>
603
604static int __devinit
605cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
606{
607 /* REVISIT paranoia argues for a shutdown notifier, since PNP
608 * drivers can't provide shutdown() methods to disable IRQs.
609 * Or better yet, fix PNP to allow those methods...
610 */
611 return cmos_do_probe(&pnp->dev,
612 &pnp->res.port_resource[0],
613 pnp->res.irq_resource[0].start);
614}
615
616static void __exit cmos_pnp_remove(struct pnp_dev *pnp)
617{
618 cmos_do_remove(&pnp->dev);
619}
620
621#ifdef CONFIG_PM
622
623static int cmos_pnp_suspend(struct pnp_dev *pnp, pm_message_t mesg)
624{
625 return cmos_suspend(&pnp->dev, mesg);
626}
627
628static int cmos_pnp_resume(struct pnp_dev *pnp)
629{
630 return cmos_resume(&pnp->dev);
631}
632
633#else
634#define cmos_pnp_suspend NULL
635#define cmos_pnp_resume NULL
636#endif
637
638
639static const struct pnp_device_id rtc_ids[] = {
640 { .id = "PNP0b00", },
641 { .id = "PNP0b01", },
642 { .id = "PNP0b02", },
643 { },
644};
645MODULE_DEVICE_TABLE(pnp, rtc_ids);
646
647static struct pnp_driver cmos_pnp_driver = {
648 .name = (char *) driver_name,
649 .id_table = rtc_ids,
650 .probe = cmos_pnp_probe,
651 .remove = __exit_p(cmos_pnp_remove),
652
653 /* flag ensures resume() gets called, and stops syslog spam */
654 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
655 .suspend = cmos_pnp_suspend,
656 .resume = cmos_pnp_resume,
657};
658
659static int __init cmos_init(void)
660{
661 return pnp_register_driver(&cmos_pnp_driver);
662}
663module_init(cmos_init);
664
665static void __exit cmos_exit(void)
666{
667 pnp_unregister_driver(&cmos_pnp_driver);
668}
669module_exit(cmos_exit);
670
671#else /* no PNPACPI */
672
673/*----------------------------------------------------------------*/
674
675/* Platform setup should have set up an RTC device, when PNPACPI is
676 * unavailable ... this is the normal case, common even on PCs.
677 */
678
679static int __init cmos_platform_probe(struct platform_device *pdev)
680{
681 return cmos_do_probe(&pdev->dev,
682 platform_get_resource(pdev, IORESOURCE_IO, 0),
683 platform_get_irq(pdev, 0));
684}
685
686static int __exit cmos_platform_remove(struct platform_device *pdev)
687{
688 cmos_do_remove(&pdev->dev);
689 return 0;
690}
691
692static void cmos_platform_shutdown(struct platform_device *pdev)
693{
694 cmos_do_shutdown();
695}
696
697static struct platform_driver cmos_platform_driver = {
698 .remove = __exit_p(cmos_platform_remove),
699 .shutdown = cmos_platform_shutdown,
700 .driver = {
701 .name = (char *) driver_name,
702 .suspend = cmos_suspend,
703 .resume = cmos_resume,
704 }
705};
706
707static int __init cmos_init(void)
708{
709 return platform_driver_probe(&cmos_platform_driver,
710 cmos_platform_probe);
711}
712module_init(cmos_init);
713
714static void __exit cmos_exit(void)
715{
716 platform_driver_unregister(&cmos_platform_driver);
717}
718module_exit(cmos_exit);
719
720
721#endif /* !PNPACPI */
722
723MODULE_AUTHOR("David Brownell");
724MODULE_DESCRIPTION("Driver for PC-style 'CMOS' RTCs");
725MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 82f2ac87ccd..137330b8636 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -384,7 +384,7 @@ static int rtc_dev_fasync(int fd, struct file *file, int on)
384 return fasync_helper(fd, file, on, &rtc->async_queue); 384 return fasync_helper(fd, file, on, &rtc->async_queue);
385} 385}
386 386
387static struct file_operations rtc_dev_fops = { 387static const struct file_operations rtc_dev_fops = {
388 .owner = THIS_MODULE, 388 .owner = THIS_MODULE,
389 .llseek = no_llseek, 389 .llseek = no_llseek,
390 .read = rtc_dev_read, 390 .read = rtc_dev_read,
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 001eb1123a6..e27176c0e18 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -297,7 +297,7 @@ static struct bin_attribute ds1553_nvram_attr = {
297 .write = ds1553_nvram_write, 297 .write = ds1553_nvram_write,
298}; 298};
299 299
300static int __init ds1553_rtc_probe(struct platform_device *pdev) 300static int __devinit ds1553_rtc_probe(struct platform_device *pdev)
301{ 301{
302 struct rtc_device *rtc; 302 struct rtc_device *rtc;
303 struct resource *res; 303 struct resource *res;
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 17633bfa848..d68288b389d 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -165,7 +165,7 @@ static struct bin_attribute ds1742_nvram_attr = {
165 .write = ds1742_nvram_write, 165 .write = ds1742_nvram_write,
166}; 166};
167 167
168static int __init ds1742_rtc_probe(struct platform_device *pdev) 168static int __devinit ds1742_rtc_probe(struct platform_device *pdev)
169{ 169{
170 struct rtc_device *rtc; 170 struct rtc_device *rtc;
171 struct resource *res; 171 struct resource *res;
diff --git a/drivers/rtc/rtc-proc.c b/drivers/rtc/rtc-proc.c
index c272afd6217..1bd624fc685 100644
--- a/drivers/rtc/rtc-proc.c
+++ b/drivers/rtc/rtc-proc.c
@@ -96,7 +96,7 @@ static int rtc_proc_release(struct inode *inode, struct file *file)
96 return res; 96 return res;
97} 97}
98 98
99static struct file_operations rtc_proc_fops = { 99static const struct file_operations rtc_proc_fops = {
100 .open = rtc_proc_open, 100 .open = rtc_proc_open,
101 .read = seq_read, 101 .read = seq_read,
102 .llseek = seq_lseek, 102 .llseek = seq_lseek,
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index 2ddd0cf0714..899ab8c514f 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -78,6 +78,92 @@ static struct attribute_group rtc_attr_group = {
78 .attrs = rtc_attrs, 78 .attrs = rtc_attrs,
79}; 79};
80 80
81
82static ssize_t
83rtc_sysfs_show_wakealarm(struct class_device *dev, char *buf)
84{
85 ssize_t retval;
86 unsigned long alarm;
87 struct rtc_wkalrm alm;
88
89 /* Don't show disabled alarms; but the RTC could leave the
90 * alarm enabled after it's already triggered. Alarms are
91 * conceptually one-shot, even though some common hardware
92 * (PCs) doesn't actually work that way.
93 *
94 * REVISIT maybe we should require RTC implementations to
95 * disable the RTC alarm after it triggers, for uniformity.
96 */
97 retval = rtc_read_alarm(dev, &alm);
98 if (retval == 0 && alm.enabled) {
99 rtc_tm_to_time(&alm.time, &alarm);
100 retval = sprintf(buf, "%lu\n", alarm);
101 }
102
103 return retval;
104}
105
106static ssize_t
107rtc_sysfs_set_wakealarm(struct class_device *dev, const char *buf, size_t n)
108{
109 ssize_t retval;
110 unsigned long now, alarm;
111 struct rtc_wkalrm alm;
112
113 /* Only request alarms that trigger in the future. Disable them
114 * by writing another time, e.g. 0 meaning Jan 1 1970 UTC.
115 */
116 retval = rtc_read_time(dev, &alm.time);
117 if (retval < 0)
118 return retval;
119 rtc_tm_to_time(&alm.time, &now);
120
121 alarm = simple_strtoul(buf, NULL, 0);
122 if (alarm > now) {
123 /* Avoid accidentally clobbering active alarms; we can't
124 * entirely prevent that here, without even the minimal
125 * locking from the /dev/rtcN api.
126 */
127 retval = rtc_read_alarm(dev, &alm);
128 if (retval < 0)
129 return retval;
130 if (alm.enabled)
131 return -EBUSY;
132
133 alm.enabled = 1;
134 } else {
135 alm.enabled = 0;
136
137 /* Provide a valid future alarm time. Linux isn't EFI,
138 * this time won't be ignored when disabling the alarm.
139 */
140 alarm = now + 300;
141 }
142 rtc_time_to_tm(alarm, &alm.time);
143
144 retval = rtc_set_alarm(dev, &alm);
145 return (retval < 0) ? retval : n;
146}
147static const CLASS_DEVICE_ATTR(wakealarm, S_IRUGO | S_IWUSR,
148 rtc_sysfs_show_wakealarm, rtc_sysfs_set_wakealarm);
149
150
151/* The reason to trigger an alarm with no process watching it (via sysfs)
152 * is its side effect: waking from a system state like suspend-to-RAM or
153 * suspend-to-disk. So: no attribute unless that side effect is possible.
154 * (Userspace may disable that mechanism later.)
155 */
156static inline int rtc_does_wakealarm(struct class_device *class_dev)
157{
158 struct rtc_device *rtc;
159
160 if (!device_can_wakeup(class_dev->dev))
161 return 0;
162 rtc = to_rtc_device(class_dev);
163 return rtc->ops->set_alarm != NULL;
164}
165
166
81static int rtc_sysfs_add_device(struct class_device *class_dev, 167static int rtc_sysfs_add_device(struct class_device *class_dev,
82 struct class_interface *class_intf) 168 struct class_interface *class_intf)
83{ 169{
@@ -87,8 +173,18 @@ static int rtc_sysfs_add_device(struct class_device *class_dev,
87 173
88 err = sysfs_create_group(&class_dev->kobj, &rtc_attr_group); 174 err = sysfs_create_group(&class_dev->kobj, &rtc_attr_group);
89 if (err) 175 if (err)
90 dev_err(class_dev->dev, 176 dev_err(class_dev->dev, "failed to create %s\n",
91 "failed to create sysfs attributes\n"); 177 "sysfs attributes");
178 else if (rtc_does_wakealarm(class_dev)) {
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 }
92 188
93 return err; 189 return err;
94} 190}
@@ -96,6 +192,9 @@ static int rtc_sysfs_add_device(struct class_device *class_dev,
96static void rtc_sysfs_remove_device(struct class_device *class_dev, 192static void rtc_sysfs_remove_device(struct class_device *class_dev,
97 struct class_interface *class_intf) 193 struct class_interface *class_intf)
98{ 194{
195 if (rtc_does_wakealarm(class_dev))
196 class_device_remove_file(class_dev,
197 &class_device_attr_wakealarm);
99 sysfs_remove_group(&class_dev->kobj, &rtc_attr_group); 198 sysfs_remove_group(&class_dev->kobj, &rtc_attr_group);
100} 199}
101 200
diff --git a/drivers/s390/block/dasd_eer.c b/drivers/s390/block/dasd_eer.c
index 6cedc914077..4b8a95fba1e 100644
--- a/drivers/s390/block/dasd_eer.c
+++ b/drivers/s390/block/dasd_eer.c
@@ -650,7 +650,7 @@ static unsigned int dasd_eer_poll(struct file *filp, poll_table *ptable)
650 return mask; 650 return mask;
651} 651}
652 652
653static struct file_operations dasd_eer_fops = { 653static const struct file_operations dasd_eer_fops = {
654 .open = &dasd_eer_open, 654 .open = &dasd_eer_open,
655 .release = &dasd_eer_close, 655 .release = &dasd_eer_close,
656 .read = &dasd_eer_read, 656 .read = &dasd_eer_read,
diff --git a/drivers/s390/block/dasd_proc.c b/drivers/s390/block/dasd_proc.c
index 8b7e11815d7..8b3b0f4a157 100644
--- a/drivers/s390/block/dasd_proc.c
+++ b/drivers/s390/block/dasd_proc.c
@@ -147,7 +147,7 @@ static int dasd_devices_open(struct inode *inode, struct file *file)
147 return seq_open(file, &dasd_devices_seq_ops); 147 return seq_open(file, &dasd_devices_seq_ops);
148} 148}
149 149
150static struct file_operations dasd_devices_file_ops = { 150static const struct file_operations dasd_devices_file_ops = {
151 .open = dasd_devices_open, 151 .open = dasd_devices_open,
152 .read = seq_read, 152 .read = seq_read,
153 .llseek = seq_lseek, 153 .llseek = seq_lseek,
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index e1a746269c4..ef36f2132aa 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -493,7 +493,7 @@ fs3270_close(struct inode *inode, struct file *filp)
493 return 0; 493 return 0;
494} 494}
495 495
496static struct file_operations fs3270_fops = { 496static const struct file_operations fs3270_fops = {
497 .owner = THIS_MODULE, /* owner */ 497 .owner = THIS_MODULE, /* owner */
498 .read = fs3270_read, /* read */ 498 .read = fs3270_read, /* read */
499 .write = fs3270_write, /* write */ 499 .write = fs3270_write, /* write */
diff --git a/drivers/s390/char/monreader.c b/drivers/s390/char/monreader.c
index 3a1a958fb5f..8df7b1323c0 100644
--- a/drivers/s390/char/monreader.c
+++ b/drivers/s390/char/monreader.c
@@ -547,7 +547,7 @@ static unsigned int mon_poll(struct file *filp, struct poll_table_struct *p)
547 return 0; 547 return 0;
548} 548}
549 549
550static struct file_operations mon_fops = { 550static const struct file_operations mon_fops = {
551 .owner = THIS_MODULE, 551 .owner = THIS_MODULE,
552 .open = &mon_open, 552 .open = &mon_open,
553 .release = &mon_close, 553 .release = &mon_close,
diff --git a/drivers/s390/char/monwriter.c b/drivers/s390/char/monwriter.c
index 9e451acc649..268598ef3ef 100644
--- a/drivers/s390/char/monwriter.c
+++ b/drivers/s390/char/monwriter.c
@@ -255,7 +255,7 @@ out_error:
255 return rc; 255 return rc;
256} 256}
257 257
258static struct file_operations monwrite_fops = { 258static const struct file_operations monwrite_fops = {
259 .owner = THIS_MODULE, 259 .owner = THIS_MODULE,
260 .open = &monwrite_open, 260 .open = &monwrite_open,
261 .release = &monwrite_close, 261 .release = &monwrite_close,
diff --git a/drivers/s390/char/tape_char.c b/drivers/s390/char/tape_char.c
index 9faea04e11e..b830a8cbef7 100644
--- a/drivers/s390/char/tape_char.c
+++ b/drivers/s390/char/tape_char.c
@@ -39,7 +39,7 @@ static int tapechar_ioctl(struct inode *, struct file *, unsigned int,
39static long tapechar_compat_ioctl(struct file *, unsigned int, 39static long tapechar_compat_ioctl(struct file *, unsigned int,
40 unsigned long); 40 unsigned long);
41 41
42static struct file_operations tape_fops = 42static const struct file_operations tape_fops =
43{ 43{
44 .owner = THIS_MODULE, 44 .owner = THIS_MODULE,
45 .read = tapechar_read, 45 .read = tapechar_read,
diff --git a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
index 56b87618b10..2e0d29730b6 100644
--- a/drivers/s390/char/tape_class.c
+++ b/drivers/s390/char/tape_class.c
@@ -36,7 +36,7 @@ static struct class *tape_class;
36struct tape_class_device *register_tape_dev( 36struct tape_class_device *register_tape_dev(
37 struct device * device, 37 struct device * device,
38 dev_t dev, 38 dev_t dev,
39 struct file_operations *fops, 39 const struct file_operations *fops,
40 char * device_name, 40 char * device_name,
41 char * mode_name) 41 char * mode_name)
42{ 42{
diff --git a/drivers/s390/char/tape_class.h b/drivers/s390/char/tape_class.h
index 3d0ca054cde..a8bd9b47fad 100644
--- a/drivers/s390/char/tape_class.h
+++ b/drivers/s390/char/tape_class.h
@@ -52,7 +52,7 @@ struct tape_class_device {
52struct tape_class_device *register_tape_dev( 52struct tape_class_device *register_tape_dev(
53 struct device * device, 53 struct device * device,
54 dev_t dev, 54 dev_t dev,
55 struct file_operations *fops, 55 const struct file_operations *fops,
56 char * device_name, 56 char * device_name,
57 char * node_name 57 char * node_name
58); 58);
diff --git a/drivers/s390/char/tape_proc.c b/drivers/s390/char/tape_proc.c
index 655d375ab22..cea49f001f8 100644
--- a/drivers/s390/char/tape_proc.c
+++ b/drivers/s390/char/tape_proc.c
@@ -109,7 +109,7 @@ static int tape_proc_open(struct inode *inode, struct file *file)
109 return seq_open(file, &tape_proc_seq); 109 return seq_open(file, &tape_proc_seq);
110} 110}
111 111
112static struct file_operations tape_proc_ops = 112static const struct file_operations tape_proc_ops =
113{ 113{
114 .open = tape_proc_open, 114 .open = tape_proc_open,
115 .read = seq_read, 115 .read = seq_read,
diff --git a/drivers/s390/char/vmcp.c b/drivers/s390/char/vmcp.c
index a420cd09904..fce3dac5cb3 100644
--- a/drivers/s390/char/vmcp.c
+++ b/drivers/s390/char/vmcp.c
@@ -173,7 +173,7 @@ static long vmcp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
173 } 173 }
174} 174}
175 175
176static struct file_operations vmcp_fops = { 176static const struct file_operations vmcp_fops = {
177 .owner = THIS_MODULE, 177 .owner = THIS_MODULE,
178 .open = &vmcp_open, 178 .open = &vmcp_open,
179 .release = &vmcp_release, 179 .release = &vmcp_release,
diff --git a/drivers/s390/char/vmlogrdr.c b/drivers/s390/char/vmlogrdr.c
index 8432a76b961..b87d3b01993 100644
--- a/drivers/s390/char/vmlogrdr.c
+++ b/drivers/s390/char/vmlogrdr.c
@@ -88,7 +88,7 @@ static int vmlogrdr_release(struct inode *, struct file *);
88static ssize_t vmlogrdr_read (struct file *filp, char __user *data, 88static ssize_t vmlogrdr_read (struct file *filp, char __user *data,
89 size_t count, loff_t * ppos); 89 size_t count, loff_t * ppos);
90 90
91static struct file_operations vmlogrdr_fops = { 91static const struct file_operations vmlogrdr_fops = {
92 .owner = THIS_MODULE, 92 .owner = THIS_MODULE,
93 .open = vmlogrdr_open, 93 .open = vmlogrdr_open,
94 .release = vmlogrdr_release, 94 .release = vmlogrdr_release,
diff --git a/drivers/s390/char/vmwatchdog.c b/drivers/s390/char/vmwatchdog.c
index 4b868f72fe8..680b9b58b80 100644
--- a/drivers/s390/char/vmwatchdog.c
+++ b/drivers/s390/char/vmwatchdog.c
@@ -228,7 +228,7 @@ static ssize_t vmwdt_write(struct file *f, const char __user *buf,
228 return count; 228 return count;
229} 229}
230 230
231static struct file_operations vmwdt_fops = { 231static const struct file_operations vmwdt_fops = {
232 .open = &vmwdt_open, 232 .open = &vmwdt_open,
233 .release = &vmwdt_close, 233 .release = &vmwdt_close,
234 .ioctl = &vmwdt_ioctl, 234 .ioctl = &vmwdt_ioctl,
diff --git a/drivers/s390/cio/blacklist.c b/drivers/s390/cio/blacklist.c
index aa65df4dfce..ec0404874fa 100644
--- a/drivers/s390/cio/blacklist.c
+++ b/drivers/s390/cio/blacklist.c
@@ -364,7 +364,7 @@ cio_ignore_proc_open(struct inode *inode, struct file *file)
364 return seq_open(file, &cio_ignore_proc_seq_ops); 364 return seq_open(file, &cio_ignore_proc_seq_ops);
365} 365}
366 366
367static struct file_operations cio_ignore_proc_fops = { 367static const struct file_operations cio_ignore_proc_fops = {
368 .open = cio_ignore_proc_open, 368 .open = cio_ignore_proc_open,
369 .read = seq_read, 369 .read = seq_read,
370 .llseek = seq_lseek, 370 .llseek = seq_lseek,
diff --git a/drivers/s390/cio/device_id.c b/drivers/s390/cio/device_id.c
index f17275917fe..997f4687453 100644
--- a/drivers/s390/cio/device_id.c
+++ b/drivers/s390/cio/device_id.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/kernel.h>
14 15
15#include <asm/ccwdev.h> 16#include <asm/ccwdev.h>
16#include <asm/delay.h> 17#include <asm/delay.h>
@@ -138,7 +139,7 @@ VM_virtual_device_info (__u16 devno, struct senseid *ps)
138 ps->cu_model = 0x60; 139 ps->cu_model = 0x60;
139 return; 140 return;
140 } 141 }
141 for (i = 0; i < sizeof(vm_devices) / sizeof(vm_devices[0]); i++) 142 for (i = 0; i < ARRAY_SIZE(vm_devices); i++)
142 if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla && 143 if (diag_data.vrdcvcla == vm_devices[i].vrdcvcla &&
143 diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) { 144 diag_data.vrdcvtyp == vm_devices[i].vrdcvtyp) {
144 ps->cu_type = vm_devices[i].cu_type; 145 ps->cu_type = vm_devices[i].cu_type;
diff --git a/drivers/s390/cio/device_ops.c b/drivers/s390/cio/device_ops.c
index d7b25b8f71d..7c7775aae38 100644
--- a/drivers/s390/cio/device_ops.c
+++ b/drivers/s390/cio/device_ops.c
@@ -23,8 +23,7 @@
23#include "chsc.h" 23#include "chsc.h"
24#include "device.h" 24#include "device.h"
25 25
26int 26int ccw_device_set_options_mask(struct ccw_device *cdev, unsigned long flags)
27ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
28{ 27{
29 /* 28 /*
30 * The flag usage is mutal exclusive ... 29 * The flag usage is mutal exclusive ...
@@ -39,6 +38,33 @@ ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
39 return 0; 38 return 0;
40} 39}
41 40
41int ccw_device_set_options(struct ccw_device *cdev, unsigned long flags)
42{
43 /*
44 * The flag usage is mutal exclusive ...
45 */
46 if (((flags & CCWDEV_EARLY_NOTIFICATION) &&
47 (flags & CCWDEV_REPORT_ALL)) ||
48 ((flags & CCWDEV_EARLY_NOTIFICATION) &&
49 cdev->private->options.repall) ||
50 ((flags & CCWDEV_REPORT_ALL) &&
51 cdev->private->options.fast))
52 return -EINVAL;
53 cdev->private->options.fast |= (flags & CCWDEV_EARLY_NOTIFICATION) != 0;
54 cdev->private->options.repall |= (flags & CCWDEV_REPORT_ALL) != 0;
55 cdev->private->options.pgroup |= (flags & CCWDEV_DO_PATHGROUP) != 0;
56 cdev->private->options.force |= (flags & CCWDEV_ALLOW_FORCE) != 0;
57 return 0;
58}
59
60void ccw_device_clear_options(struct ccw_device *cdev, unsigned long flags)
61{
62 cdev->private->options.fast &= (flags & CCWDEV_EARLY_NOTIFICATION) == 0;
63 cdev->private->options.repall &= (flags & CCWDEV_REPORT_ALL) == 0;
64 cdev->private->options.pgroup &= (flags & CCWDEV_DO_PATHGROUP) == 0;
65 cdev->private->options.force &= (flags & CCWDEV_ALLOW_FORCE) == 0;
66}
67
42int 68int
43ccw_device_clear(struct ccw_device *cdev, unsigned long intparm) 69ccw_device_clear(struct ccw_device *cdev, unsigned long intparm)
44{ 70{
@@ -601,7 +627,9 @@ _ccw_device_get_device_number(struct ccw_device *cdev)
601 627
602 628
603MODULE_LICENSE("GPL"); 629MODULE_LICENSE("GPL");
630EXPORT_SYMBOL(ccw_device_set_options_mask);
604EXPORT_SYMBOL(ccw_device_set_options); 631EXPORT_SYMBOL(ccw_device_set_options);
632EXPORT_SYMBOL(ccw_device_clear_options);
605EXPORT_SYMBOL(ccw_device_clear); 633EXPORT_SYMBOL(ccw_device_clear);
606EXPORT_SYMBOL(ccw_device_halt); 634EXPORT_SYMBOL(ccw_device_halt);
607EXPORT_SYMBOL(ccw_device_resume); 635EXPORT_SYMBOL(ccw_device_resume);
diff --git a/drivers/s390/cio/qdio.c b/drivers/s390/cio/qdio.c
index d726cd5777d..5b1e3ff26c0 100644
--- a/drivers/s390/cio/qdio.c
+++ b/drivers/s390/cio/qdio.c
@@ -3194,7 +3194,7 @@ qdio_establish(struct qdio_initialize *init_data)
3194 3194
3195 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags); 3195 spin_lock_irqsave(get_ccwdev_lock(cdev),saveflags);
3196 3196
3197 ccw_device_set_options(cdev, 0); 3197 ccw_device_set_options_mask(cdev, 0);
3198 result=ccw_device_start_timeout(cdev,&irq_ptr->ccw, 3198 result=ccw_device_start_timeout(cdev,&irq_ptr->ccw,
3199 QDIO_DOING_ESTABLISH,0, 0, 3199 QDIO_DOING_ESTABLISH,0, 0,
3200 QDIO_ESTABLISH_TIMEOUT); 3200 QDIO_ESTABLISH_TIMEOUT);
diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c
index b9e59bc9435..99761391f34 100644
--- a/drivers/s390/crypto/zcrypt_api.c
+++ b/drivers/s390/crypto/zcrypt_api.c
@@ -807,7 +807,7 @@ static long zcrypt_compat_ioctl(struct file *filp, unsigned int cmd,
807/** 807/**
808 * Misc device file operations. 808 * Misc device file operations.
809 */ 809 */
810static struct file_operations zcrypt_fops = { 810static const struct file_operations zcrypt_fops = {
811 .owner = THIS_MODULE, 811 .owner = THIS_MODULE,
812 .read = zcrypt_read, 812 .read = zcrypt_read,
813 .write = zcrypt_write, 813 .write = zcrypt_write,
@@ -1063,7 +1063,6 @@ int __init zcrypt_api_init(void)
1063 rc = -ENOMEM; 1063 rc = -ENOMEM;
1064 goto out_misc; 1064 goto out_misc;
1065 } 1065 }
1066 zcrypt_entry->nlink = 1;
1067 zcrypt_entry->data = NULL; 1066 zcrypt_entry->data = NULL;
1068 zcrypt_entry->read_proc = zcrypt_status_read; 1067 zcrypt_entry->read_proc = zcrypt_status_read;
1069 zcrypt_entry->write_proc = zcrypt_status_write; 1068 zcrypt_entry->write_proc = zcrypt_status_write;
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index b97dd15bdb9..ecca1046714 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -1511,8 +1511,7 @@ lcs_txbuffer_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
1511 LCS_DBF_TEXT(5, trace, "txbuffcb"); 1511 LCS_DBF_TEXT(5, trace, "txbuffcb");
1512 /* Put buffer back to pool. */ 1512 /* Put buffer back to pool. */
1513 lcs_release_buffer(channel, buffer); 1513 lcs_release_buffer(channel, buffer);
1514 card = (struct lcs_card *) 1514 card = container_of(channel, struct lcs_card, write);
1515 ((char *) channel - offsetof(struct lcs_card, write));
1516 if (netif_queue_stopped(card->dev) && netif_carrier_ok(card->dev)) 1515 if (netif_queue_stopped(card->dev) && netif_carrier_ok(card->dev))
1517 netif_wake_queue(card->dev); 1516 netif_wake_queue(card->dev);
1518 spin_lock(&card->lock); 1517 spin_lock(&card->lock);
@@ -1810,8 +1809,7 @@ lcs_get_frames_cb(struct lcs_channel *channel, struct lcs_buffer *buffer)
1810 LCS_DBF_TEXT(4, trace, "-eiogpkt"); 1809 LCS_DBF_TEXT(4, trace, "-eiogpkt");
1811 return; 1810 return;
1812 } 1811 }
1813 card = (struct lcs_card *) 1812 card = container_of(channel, struct lcs_card, read);
1814 ((char *) channel - offsetof(struct lcs_card, read));
1815 offset = 0; 1813 offset = 0;
1816 while (lcs_hdr->offset != 0) { 1814 while (lcs_hdr->offset != 0) {
1817 if (lcs_hdr->offset <= 0 || 1815 if (lcs_hdr->offset <= 0 ||
diff --git a/drivers/s390/net/qeth_proc.c b/drivers/s390/net/qeth_proc.c
index faa768e5925..81f805cc5ee 100644
--- a/drivers/s390/net/qeth_proc.c
+++ b/drivers/s390/net/qeth_proc.c
@@ -161,7 +161,7 @@ qeth_procfile_open(struct inode *inode, struct file *file)
161 return seq_open(file, &qeth_procfile_seq_ops); 161 return seq_open(file, &qeth_procfile_seq_ops);
162} 162}
163 163
164static struct file_operations qeth_procfile_fops = { 164static const struct file_operations qeth_procfile_fops = {
165 .owner = THIS_MODULE, 165 .owner = THIS_MODULE,
166 .open = qeth_procfile_open, 166 .open = qeth_procfile_open,
167 .read = seq_read, 167 .read = seq_read,
@@ -273,7 +273,7 @@ qeth_perf_procfile_open(struct inode *inode, struct file *file)
273 return seq_open(file, &qeth_perf_procfile_seq_ops); 273 return seq_open(file, &qeth_perf_procfile_seq_ops);
274} 274}
275 275
276static struct file_operations qeth_perf_procfile_fops = { 276static const struct file_operations qeth_perf_procfile_fops = {
277 .owner = THIS_MODULE, 277 .owner = THIS_MODULE,
278 .open = qeth_perf_procfile_open, 278 .open = qeth_perf_procfile_open,
279 .read = seq_read, 279 .read = seq_read,
diff --git a/drivers/s390/scsi/zfcp_aux.c b/drivers/s390/scsi/zfcp_aux.c
index 39a88526679..1f9554e0801 100644
--- a/drivers/s390/scsi/zfcp_aux.c
+++ b/drivers/s390/scsi/zfcp_aux.c
@@ -60,7 +60,7 @@ static long zfcp_cfdc_dev_ioctl(struct file *, unsigned int, unsigned long);
60 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data) 60 _IOWR(ZFCP_CFDC_IOC_MAGIC, 0, struct zfcp_cfdc_sense_data)
61 61
62 62
63static struct file_operations zfcp_cfdc_fops = { 63static const struct file_operations zfcp_cfdc_fops = {
64 .unlocked_ioctl = zfcp_cfdc_dev_ioctl, 64 .unlocked_ioctl = zfcp_cfdc_dev_ioctl,
65#ifdef CONFIG_COMPAT 65#ifdef CONFIG_COMPAT
66 .compat_ioctl = zfcp_cfdc_dev_ioctl 66 .compat_ioctl = zfcp_cfdc_dev_ioctl
diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c
index 88642dec080..421da1e7c0e 100644
--- a/drivers/s390/scsi/zfcp_erp.c
+++ b/drivers/s390/scsi/zfcp_erp.c
@@ -838,32 +838,28 @@ zfcp_erp_action_exists(struct zfcp_erp_action *erp_action)
838 * and does appropriate preparations (dismiss fsf request, ...) 838 * and does appropriate preparations (dismiss fsf request, ...)
839 * 839 *
840 * locks: called under erp_lock (disabled interrupts) 840 * locks: called under erp_lock (disabled interrupts)
841 *
842 * returns: 0
843 */ 841 */
844static int 842static void
845zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action) 843zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
846{ 844{
847 int retval = 0;
848 struct zfcp_fsf_req *fsf_req = NULL;
849 struct zfcp_adapter *adapter = erp_action->adapter; 845 struct zfcp_adapter *adapter = erp_action->adapter;
850 846
851 if (erp_action->fsf_req) { 847 if (erp_action->fsf_req) {
852 /* take lock to ensure that request is not deleted meanwhile */ 848 /* take lock to ensure that request is not deleted meanwhile */
853 spin_lock(&adapter->req_list_lock); 849 spin_lock(&adapter->req_list_lock);
854 if ((!zfcp_reqlist_ismember(adapter, 850 if (zfcp_reqlist_ismember(adapter,
855 erp_action->fsf_req->req_id)) && 851 erp_action->fsf_req->req_id)) {
856 (fsf_req->erp_action == erp_action)) {
857 /* fsf_req still exists */ 852 /* fsf_req still exists */
858 debug_text_event(adapter->erp_dbf, 3, "a_ca_req"); 853 debug_text_event(adapter->erp_dbf, 3, "a_ca_req");
859 debug_event(adapter->erp_dbf, 3, &fsf_req, 854 debug_event(adapter->erp_dbf, 3, &erp_action->fsf_req,
860 sizeof (unsigned long)); 855 sizeof (unsigned long));
861 /* dismiss fsf_req of timed out/dismissed erp_action */ 856 /* dismiss fsf_req of timed out/dismissed erp_action */
862 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED | 857 if (erp_action->status & (ZFCP_STATUS_ERP_DISMISSED |
863 ZFCP_STATUS_ERP_TIMEDOUT)) { 858 ZFCP_STATUS_ERP_TIMEDOUT)) {
864 debug_text_event(adapter->erp_dbf, 3, 859 debug_text_event(adapter->erp_dbf, 3,
865 "a_ca_disreq"); 860 "a_ca_disreq");
866 fsf_req->status |= ZFCP_STATUS_FSFREQ_DISMISSED; 861 erp_action->fsf_req->status |=
862 ZFCP_STATUS_FSFREQ_DISMISSED;
867 } 863 }
868 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) { 864 if (erp_action->status & ZFCP_STATUS_ERP_TIMEDOUT) {
869 ZFCP_LOG_NORMAL("error: erp step timed out " 865 ZFCP_LOG_NORMAL("error: erp step timed out "
@@ -876,11 +872,11 @@ zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
876 * then keep it running asynchronously and don't mess 872 * then keep it running asynchronously and don't mess
877 * with the association of erp_action and fsf_req. 873 * with the association of erp_action and fsf_req.
878 */ 874 */
879 if (fsf_req->status & (ZFCP_STATUS_FSFREQ_COMPLETED | 875 if (erp_action->fsf_req->status &
876 (ZFCP_STATUS_FSFREQ_COMPLETED |
880 ZFCP_STATUS_FSFREQ_DISMISSED)) { 877 ZFCP_STATUS_FSFREQ_DISMISSED)) {
881 /* forget about association between fsf_req 878 /* forget about association between fsf_req
882 and erp_action */ 879 and erp_action */
883 fsf_req->erp_action = NULL;
884 erp_action->fsf_req = NULL; 880 erp_action->fsf_req = NULL;
885 } 881 }
886 } else { 882 } else {
@@ -894,8 +890,6 @@ zfcp_erp_strategy_check_fsfreq(struct zfcp_erp_action *erp_action)
894 spin_unlock(&adapter->req_list_lock); 890 spin_unlock(&adapter->req_list_lock);
895 } else 891 } else
896 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq"); 892 debug_text_event(adapter->erp_dbf, 3, "a_ca_noreq");
897
898 return retval;
899} 893}
900 894
901/** 895/**
diff --git a/drivers/s390/scsi/zfcp_ext.h b/drivers/s390/scsi/zfcp_ext.h
index cda0cc095ad..01386ac688a 100644
--- a/drivers/s390/scsi/zfcp_ext.h
+++ b/drivers/s390/scsi/zfcp_ext.h
@@ -89,7 +89,7 @@ extern int zfcp_fsf_control_file(struct zfcp_adapter *, struct zfcp_fsf_req **,
89 u32, u32, struct zfcp_sg_list *); 89 u32, u32, struct zfcp_sg_list *);
90extern void zfcp_fsf_start_timer(struct zfcp_fsf_req *, unsigned long); 90extern void zfcp_fsf_start_timer(struct zfcp_fsf_req *, unsigned long);
91extern void zfcp_erp_start_timer(struct zfcp_fsf_req *); 91extern void zfcp_erp_start_timer(struct zfcp_fsf_req *);
92extern int zfcp_fsf_req_dismiss_all(struct zfcp_adapter *); 92extern void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *);
93extern int zfcp_fsf_status_read(struct zfcp_adapter *, int); 93extern int zfcp_fsf_status_read(struct zfcp_adapter *, int);
94extern int zfcp_fsf_req_create(struct zfcp_adapter *, u32, int, mempool_t *, 94extern int zfcp_fsf_req_create(struct zfcp_adapter *, u32, int, mempool_t *,
95 unsigned long *, struct zfcp_fsf_req **); 95 unsigned long *, struct zfcp_fsf_req **);
diff --git a/drivers/s390/scsi/zfcp_fsf.c b/drivers/s390/scsi/zfcp_fsf.c
index 4b3ae3f22e7..ef16f7ca4bb 100644
--- a/drivers/s390/scsi/zfcp_fsf.c
+++ b/drivers/s390/scsi/zfcp_fsf.c
@@ -176,28 +176,25 @@ static void zfcp_fsf_req_dismiss(struct zfcp_adapter *adapter,
176/** 176/**
177 * zfcp_fsf_req_dismiss_all - dismiss all remaining fsf requests 177 * zfcp_fsf_req_dismiss_all - dismiss all remaining fsf requests
178 */ 178 */
179int zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter) 179void zfcp_fsf_req_dismiss_all(struct zfcp_adapter *adapter)
180{ 180{
181 struct zfcp_fsf_req *request, *tmp; 181 struct zfcp_fsf_req *request, *tmp;
182 unsigned long flags; 182 unsigned long flags;
183 LIST_HEAD(remove_queue);
183 unsigned int i, counter; 184 unsigned int i, counter;
184 185
185 spin_lock_irqsave(&adapter->req_list_lock, flags); 186 spin_lock_irqsave(&adapter->req_list_lock, flags);
186 atomic_set(&adapter->reqs_active, 0); 187 atomic_set(&adapter->reqs_active, 0);
187 for (i=0; i<REQUEST_LIST_SIZE; i++) { 188 for (i=0; i<REQUEST_LIST_SIZE; i++)
188 if (list_empty(&adapter->req_list[i])) 189 list_splice_init(&adapter->req_list[i], &remove_queue);
189 continue; 190
190
191 counter = 0;
192 list_for_each_entry_safe(request, tmp,
193 &adapter->req_list[i], list) {
194 zfcp_fsf_req_dismiss(adapter, request, counter);
195 counter++;
196 }
197 }
198 spin_unlock_irqrestore(&adapter->req_list_lock, flags); 191 spin_unlock_irqrestore(&adapter->req_list_lock, flags);
199 192
200 return 0; 193 counter = 0;
194 list_for_each_entry_safe(request, tmp, &remove_queue, list) {
195 zfcp_fsf_req_dismiss(adapter, request, counter);
196 counter++;
197 }
201} 198}
202 199
203/* 200/*
diff --git a/drivers/sbus/char/bpp.c b/drivers/sbus/char/bpp.c
index ac7d1258efe..a39ee80c971 100644
--- a/drivers/sbus/char/bpp.c
+++ b/drivers/sbus/char/bpp.c
@@ -846,7 +846,7 @@ static int bpp_ioctl(struct inode *inode, struct file *f, unsigned int cmd,
846 return errno; 846 return errno;
847} 847}
848 848
849static struct file_operations bpp_fops = { 849static const struct file_operations bpp_fops = {
850 .owner = THIS_MODULE, 850 .owner = THIS_MODULE,
851 .read = bpp_read, 851 .read = bpp_read,
852 .write = bpp_write, 852 .write = bpp_write,
diff --git a/drivers/sbus/char/cpwatchdog.c b/drivers/sbus/char/cpwatchdog.c
index ad1c7db96cb..0cfd1e4c032 100644
--- a/drivers/sbus/char/cpwatchdog.c
+++ b/drivers/sbus/char/cpwatchdog.c
@@ -459,7 +459,7 @@ static irqreturn_t wd_interrupt(int irq, void *dev_id)
459 return IRQ_HANDLED; 459 return IRQ_HANDLED;
460} 460}
461 461
462static struct file_operations wd_fops = { 462static const struct file_operations wd_fops = {
463 .owner = THIS_MODULE, 463 .owner = THIS_MODULE,
464 .ioctl = wd_ioctl, 464 .ioctl = wd_ioctl,
465 .compat_ioctl = wd_compat_ioctl, 465 .compat_ioctl = wd_compat_ioctl,
diff --git a/drivers/sbus/char/display7seg.c b/drivers/sbus/char/display7seg.c
index a4909e0c7f8..2d14a29effe 100644
--- a/drivers/sbus/char/display7seg.c
+++ b/drivers/sbus/char/display7seg.c
@@ -166,7 +166,7 @@ static long d7s_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
166 return error; 166 return error;
167} 167}
168 168
169static struct file_operations d7s_fops = { 169static const struct file_operations d7s_fops = {
170 .owner = THIS_MODULE, 170 .owner = THIS_MODULE,
171 .unlocked_ioctl = d7s_ioctl, 171 .unlocked_ioctl = d7s_ioctl,
172 .compat_ioctl = d7s_ioctl, 172 .compat_ioctl = d7s_ioctl,
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index fff4660cdf9..2cea4f5d208 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -705,7 +705,7 @@ envctrl_release(struct inode *inode, struct file *file)
705 return 0; 705 return 0;
706} 706}
707 707
708static struct file_operations envctrl_fops = { 708static const struct file_operations envctrl_fops = {
709 .owner = THIS_MODULE, 709 .owner = THIS_MODULE,
710 .read = envctrl_read, 710 .read = envctrl_read,
711 .unlocked_ioctl = envctrl_ioctl, 711 .unlocked_ioctl = envctrl_ioctl,
diff --git a/drivers/sbus/char/flash.c b/drivers/sbus/char/flash.c
index fa2418f7ad3..6e99507aeb1 100644
--- a/drivers/sbus/char/flash.c
+++ b/drivers/sbus/char/flash.c
@@ -142,7 +142,7 @@ flash_release(struct inode *inode, struct file *file)
142 return 0; 142 return 0;
143} 143}
144 144
145static struct file_operations flash_fops = { 145static const struct file_operations flash_fops = {
146 /* no write to the Flash, use mmap 146 /* no write to the Flash, use mmap
147 * and play flash dependent tricks. 147 * and play flash dependent tricks.
148 */ 148 */
diff --git a/drivers/sbus/char/jsflash.c b/drivers/sbus/char/jsflash.c
index 14631ac11bc..512857a2316 100644
--- a/drivers/sbus/char/jsflash.c
+++ b/drivers/sbus/char/jsflash.c
@@ -431,7 +431,7 @@ static int jsf_release(struct inode *inode, struct file *file)
431 return 0; 431 return 0;
432} 432}
433 433
434static struct file_operations jsf_fops = { 434static const struct file_operations jsf_fops = {
435 .owner = THIS_MODULE, 435 .owner = THIS_MODULE,
436 .llseek = jsf_lseek, 436 .llseek = jsf_lseek,
437 .read = jsf_read, 437 .read = jsf_read,
diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c
index 4e2a0e2dcc2..e8776230782 100644
--- a/drivers/sbus/char/openprom.c
+++ b/drivers/sbus/char/openprom.c
@@ -704,7 +704,7 @@ static int openprom_release(struct inode * inode, struct file * file)
704 return 0; 704 return 0;
705} 705}
706 706
707static struct file_operations openprom_fops = { 707static const struct file_operations openprom_fops = {
708 .owner = THIS_MODULE, 708 .owner = THIS_MODULE,
709 .llseek = no_llseek, 709 .llseek = no_llseek,
710 .ioctl = openprom_ioctl, 710 .ioctl = openprom_ioctl,
diff --git a/drivers/sbus/char/riowatchdog.c b/drivers/sbus/char/riowatchdog.c
index 2a9cc820442..a2fc6b8c133 100644
--- a/drivers/sbus/char/riowatchdog.c
+++ b/drivers/sbus/char/riowatchdog.c
@@ -193,7 +193,7 @@ static ssize_t riowd_write(struct file *file, const char __user *buf, size_t cou
193 return 0; 193 return 0;
194} 194}
195 195
196static struct file_operations riowd_fops = { 196static const struct file_operations riowd_fops = {
197 .owner = THIS_MODULE, 197 .owner = THIS_MODULE,
198 .ioctl = riowd_ioctl, 198 .ioctl = riowd_ioctl,
199 .open = riowd_open, 199 .open = riowd_open,
diff --git a/drivers/sbus/char/rtc.c b/drivers/sbus/char/rtc.c
index 9b988baf0b5..94d18582911 100644
--- a/drivers/sbus/char/rtc.c
+++ b/drivers/sbus/char/rtc.c
@@ -233,7 +233,7 @@ static int rtc_release(struct inode *inode, struct file *file)
233 return 0; 233 return 0;
234} 234}
235 235
236static struct file_operations rtc_fops = { 236static const struct file_operations rtc_fops = {
237 .owner = THIS_MODULE, 237 .owner = THIS_MODULE,
238 .llseek = no_llseek, 238 .llseek = no_llseek,
239 .ioctl = rtc_ioctl, 239 .ioctl = rtc_ioctl,
diff --git a/drivers/sbus/char/uctrl.c b/drivers/sbus/char/uctrl.c
index b30372f17f1..4d1a505e9e7 100644
--- a/drivers/sbus/char/uctrl.c
+++ b/drivers/sbus/char/uctrl.c
@@ -224,7 +224,7 @@ static irqreturn_t uctrl_interrupt(int irq, void *dev_id)
224 return IRQ_HANDLED; 224 return IRQ_HANDLED;
225} 225}
226 226
227static struct file_operations uctrl_fops = { 227static const struct file_operations uctrl_fops = {
228 .owner = THIS_MODULE, 228 .owner = THIS_MODULE,
229 .llseek = no_llseek, 229 .llseek = no_llseek,
230 .ioctl = uctrl_ioctl, 230 .ioctl = uctrl_ioctl,
diff --git a/drivers/sbus/char/vfc_dev.c b/drivers/sbus/char/vfc_dev.c
index 386e7de0b7e..37a04a0cecf 100644
--- a/drivers/sbus/char/vfc_dev.c
+++ b/drivers/sbus/char/vfc_dev.c
@@ -44,7 +44,7 @@
44#include "vfc.h" 44#include "vfc.h"
45#include <asm/vfc_ioctls.h> 45#include <asm/vfc_ioctls.h>
46 46
47static struct file_operations vfc_fops; 47static const struct file_operations vfc_fops;
48struct vfc_dev **vfc_dev_lst; 48struct vfc_dev **vfc_dev_lst;
49static char vfcstr[]="vfc"; 49static char vfcstr[]="vfc";
50static unsigned char saa9051_init_array[VFC_SAA9051_NR] = { 50static unsigned char saa9051_init_array[VFC_SAA9051_NR] = {
@@ -633,7 +633,7 @@ static int vfc_mmap(struct file *file, struct vm_area_struct *vma)
633} 633}
634 634
635 635
636static struct file_operations vfc_fops = { 636static const struct file_operations vfc_fops = {
637 .owner = THIS_MODULE, 637 .owner = THIS_MODULE,
638 .llseek = no_llseek, 638 .llseek = no_llseek,
639 .ioctl = vfc_ioctl, 639 .ioctl = vfc_ioctl,
diff --git a/drivers/sbus/sbus.c b/drivers/sbus/sbus.c
index 98fcbb3d556..6349dd617f8 100644
--- a/drivers/sbus/sbus.c
+++ b/drivers/sbus/sbus.c
@@ -7,6 +7,7 @@
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include <linux/init.h> 8#include <linux/init.h>
9#include <linux/pci.h> 9#include <linux/pci.h>
10#include <linux/device.h>
10 11
11#include <asm/system.h> 12#include <asm/system.h>
12#include <asm/sbus.h> 13#include <asm/sbus.h>
@@ -17,13 +18,25 @@
17#include <asm/bpp.h> 18#include <asm/bpp.h>
18#include <asm/irq.h> 19#include <asm/irq.h>
19 20
21static ssize_t
22show_sbusobppath_attr(struct device * dev, struct device_attribute * attr, char * buf)
23{
24 struct sbus_dev *sbus;
25
26 sbus = to_sbus_device(dev);
27
28 return snprintf (buf, PAGE_SIZE, "%s\n", sbus->ofdev.node->full_name);
29}
30
31static DEVICE_ATTR(obppath, S_IRUSR | S_IRGRP | S_IROTH, show_sbusobppath_attr, NULL);
32
20struct sbus_bus *sbus_root; 33struct sbus_bus *sbus_root;
21 34
22static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev) 35static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sdev)
23{ 36{
24 unsigned long base; 37 unsigned long base;
25 void *pval; 38 void *pval;
26 int len; 39 int len, err;
27 40
28 sdev->prom_node = dp->node; 41 sdev->prom_node = dp->node;
29 strcpy(sdev->prom_name, dp->name); 42 strcpy(sdev->prom_name, dp->name);
@@ -66,6 +79,9 @@ static void __init fill_sbus_device(struct device_node *dp, struct sbus_dev *sde
66 if (of_device_register(&sdev->ofdev) != 0) 79 if (of_device_register(&sdev->ofdev) != 0)
67 printk(KERN_DEBUG "sbus: device registration error for %s!\n", 80 printk(KERN_DEBUG "sbus: device registration error for %s!\n",
68 dp->path_component_name); 81 dp->path_component_name);
82
83 /* WE HAVE BEEN INVADED BY ALIENS! */
84 err = sysfs_create_file(&sdev->ofdev.dev.kobj, &dev_attr_obppath.attr);
69} 85}
70 86
71static void __init sbus_bus_ranges_init(struct device_node *dp, struct sbus_bus *sbus) 87static void __init sbus_bus_ranges_init(struct device_node *dp, struct sbus_bus *sbus)
diff --git a/drivers/scsi/3w-9xxx.c b/drivers/scsi/3w-9xxx.c
index b091a0fc4eb..eb766c3af1c 100644
--- a/drivers/scsi/3w-9xxx.c
+++ b/drivers/scsi/3w-9xxx.c
@@ -197,7 +197,7 @@ static struct class_device_attribute *twa_host_attrs[] = {
197}; 197};
198 198
199/* File operations struct for character device */ 199/* File operations struct for character device */
200static struct file_operations twa_fops = { 200static const struct file_operations twa_fops = {
201 .owner = THIS_MODULE, 201 .owner = THIS_MODULE,
202 .ioctl = twa_chrdev_ioctl, 202 .ioctl = twa_chrdev_ioctl,
203 .open = twa_chrdev_open, 203 .open = twa_chrdev_open,
diff --git a/drivers/scsi/3w-xxxx.c b/drivers/scsi/3w-xxxx.c
index e1b44d6c0c3..bf5d63e1bee 100644
--- a/drivers/scsi/3w-xxxx.c
+++ b/drivers/scsi/3w-xxxx.c
@@ -1040,7 +1040,7 @@ static int tw_chrdev_open(struct inode *inode, struct file *file)
1040} /* End tw_chrdev_open() */ 1040} /* End tw_chrdev_open() */
1041 1041
1042/* File operations struct for character device */ 1042/* File operations struct for character device */
1043static struct file_operations tw_fops = { 1043static const struct file_operations tw_fops = {
1044 .owner = THIS_MODULE, 1044 .owner = THIS_MODULE,
1045 .ioctl = tw_chrdev_ioctl, 1045 .ioctl = tw_chrdev_ioctl,
1046 .open = tw_chrdev_open, 1046 .open = tw_chrdev_open,
diff --git a/drivers/scsi/53c700.c b/drivers/scsi/53c700.c
index 68103e508db..88e061d13d0 100644
--- a/drivers/scsi/53c700.c
+++ b/drivers/scsi/53c700.c
@@ -667,12 +667,30 @@ NCR_700_chip_setup(struct Scsi_Host *host)
667 __u8 min_xferp = (hostdata->chip710 ? NCR_710_MIN_XFERP : NCR_700_MIN_XFERP); 667 __u8 min_xferp = (hostdata->chip710 ? NCR_710_MIN_XFERP : NCR_700_MIN_XFERP);
668 668
669 if(hostdata->chip710) { 669 if(hostdata->chip710) {
670 __u8 burst_disable = hostdata->burst_disable 670 __u8 burst_disable = 0;
671 ? BURST_DISABLE : 0; 671 __u8 burst_length = 0;
672
673 switch (hostdata->burst_length) {
674 case 1:
675 burst_length = BURST_LENGTH_1;
676 break;
677 case 2:
678 burst_length = BURST_LENGTH_2;
679 break;
680 case 4:
681 burst_length = BURST_LENGTH_4;
682 break;
683 case 8:
684 burst_length = BURST_LENGTH_8;
685 break;
686 default:
687 burst_disable = BURST_DISABLE;
688 break;
689 }
672 dcntl_extra = COMPAT_700_MODE; 690 dcntl_extra = COMPAT_700_MODE;
673 691
674 NCR_700_writeb(dcntl_extra, host, DCNTL_REG); 692 NCR_700_writeb(dcntl_extra, host, DCNTL_REG);
675 NCR_700_writeb(BURST_LENGTH_8 | hostdata->dmode_extra, 693 NCR_700_writeb(burst_length | hostdata->dmode_extra,
676 host, DMODE_710_REG); 694 host, DMODE_710_REG);
677 NCR_700_writeb(burst_disable | (hostdata->differential ? 695 NCR_700_writeb(burst_disable | (hostdata->differential ?
678 DIFF : 0), host, CTEST7_REG); 696 DIFF : 0), host, CTEST7_REG);
diff --git a/drivers/scsi/53c700.h b/drivers/scsi/53c700.h
index f38822db421..841e1bb27d5 100644
--- a/drivers/scsi/53c700.h
+++ b/drivers/scsi/53c700.h
@@ -203,7 +203,7 @@ struct NCR_700_Host_Parameters {
203 __u32 force_le_on_be:1; 203 __u32 force_le_on_be:1;
204#endif 204#endif
205 __u32 chip710:1; /* set if really a 710 not 700 */ 205 __u32 chip710:1; /* set if really a 710 not 700 */
206 __u32 burst_disable:1; /* set to 1 to disable 710 bursting */ 206 __u32 burst_length:4; /* set to 0 to disable 710 bursting */
207 207
208 /* NOTHING BELOW HERE NEEDS ALTERING */ 208 /* NOTHING BELOW HERE NEEDS ALTERING */
209 __u32 fast:1; /* if we can alter the SCSI bus clock 209 __u32 fast:1; /* if we can alter the SCSI bus clock
diff --git a/drivers/scsi/53c7xx.c b/drivers/scsi/53c7xx.c
index 640536ef77d..93b41f45638 100644
--- a/drivers/scsi/53c7xx.c
+++ b/drivers/scsi/53c7xx.c
@@ -3099,7 +3099,6 @@ allocate_cmd (Scsi_Cmnd *cmd) {
3099 real = get_zeroed_page(GFP_ATOMIC); 3099 real = get_zeroed_page(GFP_ATOMIC);
3100 if (real == 0) 3100 if (real == 0)
3101 return NULL; 3101 return NULL;
3102 memset((void *)real, 0, 4096);
3103 cache_push(virt_to_phys((void *)real), 4096); 3102 cache_push(virt_to_phys((void *)real), 4096);
3104 cache_clear(virt_to_phys((void *)real), 4096); 3103 cache_clear(virt_to_phys((void *)real), 4096);
3105 kernel_set_cachemode((void *)real, 4096, IOMAP_NOCACHE_SER); 3104 kernel_set_cachemode((void *)real, 4096, IOMAP_NOCACHE_SER);
@@ -4400,7 +4399,7 @@ abort_connected (struct Scsi_Host *host) {
4400 * account the current synchronous offset) 4399 * account the current synchronous offset)
4401 */ 4400 */
4402 4401
4403 sstat = (NCR53c8x0_read8 (SSTAT2_REG); 4402 sstat = NCR53c8x0_read8 (SSTAT2_REG);
4404 offset = OFFSET (sstat & SSTAT2_FF_MASK) >> SSTAT2_FF_SHIFT; 4403 offset = OFFSET (sstat & SSTAT2_FF_MASK) >> SSTAT2_FF_SHIFT;
4405 phase = sstat & SSTAT2_PHASE_MASK; 4404 phase = sstat & SSTAT2_PHASE_MASK;
4406 4405
@@ -5423,7 +5422,7 @@ insn_to_offset (Scsi_Cmnd *cmd, u32 *insn) {
5423 --buffers, offset += segment->length, ++segment) 5422 --buffers, offset += segment->length, ++segment)
5424#if 0 5423#if 0
5425 printk("scsi%d: comparing 0x%p to 0x%p\n", 5424 printk("scsi%d: comparing 0x%p to 0x%p\n",
5426 cmd->device->host->host_no, saved, page_address(segment->page+segment->offset); 5425 cmd->device->host->host_no, saved, page_address(segment->page+segment->offset));
5427#else 5426#else
5428 ; 5427 ;
5429#endif 5428#endif
diff --git a/drivers/scsi/BusLogic.c b/drivers/scsi/BusLogic.c
index 3075204915c..e874b894487 100644
--- a/drivers/scsi/BusLogic.c
+++ b/drivers/scsi/BusLogic.c
@@ -192,7 +192,7 @@ static void BusLogic_InitializeCCBs(struct BusLogic_HostAdapter *HostAdapter, vo
192 BusLogic_CreateInitialCCBs allocates the initial CCBs for Host Adapter. 192 BusLogic_CreateInitialCCBs allocates the initial CCBs for Host Adapter.
193*/ 193*/
194 194
195static boolean __init BusLogic_CreateInitialCCBs(struct BusLogic_HostAdapter *HostAdapter) 195static bool __init BusLogic_CreateInitialCCBs(struct BusLogic_HostAdapter *HostAdapter)
196{ 196{
197 int BlockSize = BusLogic_CCB_AllocationGroupSize * sizeof(struct BusLogic_CCB); 197 int BlockSize = BusLogic_CCB_AllocationGroupSize * sizeof(struct BusLogic_CCB);
198 void *BlockPointer; 198 void *BlockPointer;
@@ -238,7 +238,7 @@ static void BusLogic_DestroyCCBs(struct BusLogic_HostAdapter *HostAdapter)
238 multiple host adapters share the same IRQ Channel. 238 multiple host adapters share the same IRQ Channel.
239*/ 239*/
240 240
241static void BusLogic_CreateAdditionalCCBs(struct BusLogic_HostAdapter *HostAdapter, int AdditionalCCBs, boolean SuccessMessageP) 241static void BusLogic_CreateAdditionalCCBs(struct BusLogic_HostAdapter *HostAdapter, int AdditionalCCBs, bool SuccessMessageP)
242{ 242{
243 int BlockSize = BusLogic_CCB_AllocationGroupSize * sizeof(struct BusLogic_CCB); 243 int BlockSize = BusLogic_CCB_AllocationGroupSize * sizeof(struct BusLogic_CCB);
244 int PreviouslyAllocated = HostAdapter->AllocatedCCBs; 244 int PreviouslyAllocated = HostAdapter->AllocatedCCBs;
@@ -362,10 +362,8 @@ static int BusLogic_Command(struct BusLogic_HostAdapter *HostAdapter, enum BusLo
362 interrupt could occur if the IRQ Channel was previously enabled by another 362 interrupt could occur if the IRQ Channel was previously enabled by another
363 BusLogic Host Adapter or another driver sharing the same IRQ Channel. 363 BusLogic Host Adapter or another driver sharing the same IRQ Channel.
364 */ 364 */
365 if (!HostAdapter->IRQ_ChannelAcquired) { 365 if (!HostAdapter->IRQ_ChannelAcquired)
366 local_irq_save(ProcessorFlags); 366 local_irq_save(ProcessorFlags);
367 local_irq_disable();
368 }
369 /* 367 /*
370 Wait for the Host Adapter Ready bit to be set and the Command/Parameter 368 Wait for the Host Adapter Ready bit to be set and the Command/Parameter
371 Register Busy bit to be reset in the Status Register. 369 Register Busy bit to be reset in the Status Register.
@@ -639,9 +637,9 @@ static int __init BusLogic_InitializeMultiMasterProbeInfo(struct BusLogic_HostAd
639 struct BusLogic_ProbeInfo *PrimaryProbeInfo = &BusLogic_ProbeInfoList[BusLogic_ProbeInfoCount]; 637 struct BusLogic_ProbeInfo *PrimaryProbeInfo = &BusLogic_ProbeInfoList[BusLogic_ProbeInfoCount];
640 int NonPrimaryPCIMultiMasterIndex = BusLogic_ProbeInfoCount + 1; 638 int NonPrimaryPCIMultiMasterIndex = BusLogic_ProbeInfoCount + 1;
641 int NonPrimaryPCIMultiMasterCount = 0, PCIMultiMasterCount = 0; 639 int NonPrimaryPCIMultiMasterCount = 0, PCIMultiMasterCount = 0;
642 boolean ForceBusDeviceScanningOrder = false; 640 bool ForceBusDeviceScanningOrder = false;
643 boolean ForceBusDeviceScanningOrderChecked = false; 641 bool ForceBusDeviceScanningOrderChecked = false;
644 boolean StandardAddressSeen[6]; 642 bool StandardAddressSeen[6];
645 struct pci_dev *PCI_Device = NULL; 643 struct pci_dev *PCI_Device = NULL;
646 int i; 644 int i;
647 if (BusLogic_ProbeInfoCount >= BusLogic_MaxHostAdapters) 645 if (BusLogic_ProbeInfoCount >= BusLogic_MaxHostAdapters)
@@ -1011,7 +1009,7 @@ static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
1011 BusLogic_Failure prints a standardized error message, and then returns false. 1009 BusLogic_Failure prints a standardized error message, and then returns false.
1012*/ 1010*/
1013 1011
1014static boolean BusLogic_Failure(struct BusLogic_HostAdapter *HostAdapter, char *ErrorMessage) 1012static bool BusLogic_Failure(struct BusLogic_HostAdapter *HostAdapter, char *ErrorMessage)
1015{ 1013{
1016 BusLogic_AnnounceDriver(HostAdapter); 1014 BusLogic_AnnounceDriver(HostAdapter);
1017 if (HostAdapter->HostAdapterBusType == BusLogic_PCI_Bus) { 1015 if (HostAdapter->HostAdapterBusType == BusLogic_PCI_Bus) {
@@ -1030,7 +1028,7 @@ static boolean BusLogic_Failure(struct BusLogic_HostAdapter *HostAdapter, char *
1030 BusLogic_ProbeHostAdapter probes for a BusLogic Host Adapter. 1028 BusLogic_ProbeHostAdapter probes for a BusLogic Host Adapter.
1031*/ 1029*/
1032 1030
1033static boolean __init BusLogic_ProbeHostAdapter(struct BusLogic_HostAdapter *HostAdapter) 1031static bool __init BusLogic_ProbeHostAdapter(struct BusLogic_HostAdapter *HostAdapter)
1034{ 1032{
1035 union BusLogic_StatusRegister StatusRegister; 1033 union BusLogic_StatusRegister StatusRegister;
1036 union BusLogic_InterruptRegister InterruptRegister; 1034 union BusLogic_InterruptRegister InterruptRegister;
@@ -1101,8 +1099,8 @@ static boolean __init BusLogic_ProbeHostAdapter(struct BusLogic_HostAdapter *Hos
1101 SCSI Bus Reset. 1099 SCSI Bus Reset.
1102*/ 1100*/
1103 1101
1104static boolean BusLogic_HardwareResetHostAdapter(struct BusLogic_HostAdapter 1102static bool BusLogic_HardwareResetHostAdapter(struct BusLogic_HostAdapter
1105 *HostAdapter, boolean HardReset) 1103 *HostAdapter, bool HardReset)
1106{ 1104{
1107 union BusLogic_StatusRegister StatusRegister; 1105 union BusLogic_StatusRegister StatusRegister;
1108 int TimeoutCounter; 1106 int TimeoutCounter;
@@ -1205,11 +1203,11 @@ static boolean BusLogic_HardwareResetHostAdapter(struct BusLogic_HostAdapter
1205 Host Adapter. 1203 Host Adapter.
1206*/ 1204*/
1207 1205
1208static boolean __init BusLogic_CheckHostAdapter(struct BusLogic_HostAdapter *HostAdapter) 1206static bool __init BusLogic_CheckHostAdapter(struct BusLogic_HostAdapter *HostAdapter)
1209{ 1207{
1210 struct BusLogic_ExtendedSetupInformation ExtendedSetupInformation; 1208 struct BusLogic_ExtendedSetupInformation ExtendedSetupInformation;
1211 unsigned char RequestedReplyLength; 1209 unsigned char RequestedReplyLength;
1212 boolean Result = true; 1210 bool Result = true;
1213 /* 1211 /*
1214 FlashPoint Host Adapters do not require this protection. 1212 FlashPoint Host Adapters do not require this protection.
1215 */ 1213 */
@@ -1239,7 +1237,7 @@ static boolean __init BusLogic_CheckHostAdapter(struct BusLogic_HostAdapter *Hos
1239 from Host Adapter and initializes the Host Adapter structure. 1237 from Host Adapter and initializes the Host Adapter structure.
1240*/ 1238*/
1241 1239
1242static boolean __init BusLogic_ReadHostAdapterConfiguration(struct BusLogic_HostAdapter 1240static bool __init BusLogic_ReadHostAdapterConfiguration(struct BusLogic_HostAdapter
1243 *HostAdapter) 1241 *HostAdapter)
1244{ 1242{
1245 struct BusLogic_BoardID BoardID; 1243 struct BusLogic_BoardID BoardID;
@@ -1686,14 +1684,14 @@ static boolean __init BusLogic_ReadHostAdapterConfiguration(struct BusLogic_Host
1686 Host Adapter. 1684 Host Adapter.
1687*/ 1685*/
1688 1686
1689static boolean __init BusLogic_ReportHostAdapterConfiguration(struct BusLogic_HostAdapter 1687static bool __init BusLogic_ReportHostAdapterConfiguration(struct BusLogic_HostAdapter
1690 *HostAdapter) 1688 *HostAdapter)
1691{ 1689{
1692 unsigned short AllTargetsMask = (1 << HostAdapter->MaxTargetDevices) - 1; 1690 unsigned short AllTargetsMask = (1 << HostAdapter->MaxTargetDevices) - 1;
1693 unsigned short SynchronousPermitted, FastPermitted; 1691 unsigned short SynchronousPermitted, FastPermitted;
1694 unsigned short UltraPermitted, WidePermitted; 1692 unsigned short UltraPermitted, WidePermitted;
1695 unsigned short DisconnectPermitted, TaggedQueuingPermitted; 1693 unsigned short DisconnectPermitted, TaggedQueuingPermitted;
1696 boolean CommonSynchronousNegotiation, CommonTaggedQueueDepth; 1694 bool CommonSynchronousNegotiation, CommonTaggedQueueDepth;
1697 char SynchronousString[BusLogic_MaxTargetDevices + 1]; 1695 char SynchronousString[BusLogic_MaxTargetDevices + 1];
1698 char WideString[BusLogic_MaxTargetDevices + 1]; 1696 char WideString[BusLogic_MaxTargetDevices + 1];
1699 char DisconnectString[BusLogic_MaxTargetDevices + 1]; 1697 char DisconnectString[BusLogic_MaxTargetDevices + 1];
@@ -1835,7 +1833,7 @@ static boolean __init BusLogic_ReportHostAdapterConfiguration(struct BusLogic_Ho
1835 Host Adapter. 1833 Host Adapter.
1836*/ 1834*/
1837 1835
1838static boolean __init BusLogic_AcquireResources(struct BusLogic_HostAdapter *HostAdapter) 1836static bool __init BusLogic_AcquireResources(struct BusLogic_HostAdapter *HostAdapter)
1839{ 1837{
1840 if (HostAdapter->IRQ_Channel == 0) { 1838 if (HostAdapter->IRQ_Channel == 0) {
1841 BusLogic_Error("NO LEGAL INTERRUPT CHANNEL ASSIGNED - DETACHING\n", HostAdapter); 1839 BusLogic_Error("NO LEGAL INTERRUPT CHANNEL ASSIGNED - DETACHING\n", HostAdapter);
@@ -1903,7 +1901,7 @@ static void BusLogic_ReleaseResources(struct BusLogic_HostAdapter *HostAdapter)
1903 of the Host Adapter from its initial power on or hard reset state. 1901 of the Host Adapter from its initial power on or hard reset state.
1904*/ 1902*/
1905 1903
1906static boolean BusLogic_InitializeHostAdapter(struct BusLogic_HostAdapter 1904static bool BusLogic_InitializeHostAdapter(struct BusLogic_HostAdapter
1907 *HostAdapter) 1905 *HostAdapter)
1908{ 1906{
1909 struct BusLogic_ExtendedMailboxRequest ExtendedMailboxRequest; 1907 struct BusLogic_ExtendedMailboxRequest ExtendedMailboxRequest;
@@ -2002,7 +2000,7 @@ static boolean BusLogic_InitializeHostAdapter(struct BusLogic_HostAdapter
2002 through Host Adapter. 2000 through Host Adapter.
2003*/ 2001*/
2004 2002
2005static boolean __init BusLogic_TargetDeviceInquiry(struct BusLogic_HostAdapter 2003static bool __init BusLogic_TargetDeviceInquiry(struct BusLogic_HostAdapter
2006 *HostAdapter) 2004 *HostAdapter)
2007{ 2005{
2008 u16 InstalledDevices; 2006 u16 InstalledDevices;
@@ -2739,7 +2737,7 @@ static irqreturn_t BusLogic_InterruptHandler(int IRQ_Channel, void *DeviceIdenti
2739 already have been acquired by the caller. 2737 already have been acquired by the caller.
2740*/ 2738*/
2741 2739
2742static boolean BusLogic_WriteOutgoingMailbox(struct BusLogic_HostAdapter 2740static bool BusLogic_WriteOutgoingMailbox(struct BusLogic_HostAdapter
2743 *HostAdapter, enum BusLogic_ActionCode ActionCode, struct BusLogic_CCB *CCB) 2741 *HostAdapter, enum BusLogic_ActionCode ActionCode, struct BusLogic_CCB *CCB)
2744{ 2742{
2745 struct BusLogic_OutgoingMailbox *NextOutgoingMailbox; 2743 struct BusLogic_OutgoingMailbox *NextOutgoingMailbox;
@@ -3058,7 +3056,7 @@ static int BusLogic_AbortCommand(struct scsi_cmnd *Command)
3058 currently executing SCSI Commands as having been Reset. 3056 currently executing SCSI Commands as having been Reset.
3059*/ 3057*/
3060 3058
3061static int BusLogic_ResetHostAdapter(struct BusLogic_HostAdapter *HostAdapter, boolean HardReset) 3059static int BusLogic_ResetHostAdapter(struct BusLogic_HostAdapter *HostAdapter, bool HardReset)
3062{ 3060{
3063 struct BusLogic_CCB *CCB; 3061 struct BusLogic_CCB *CCB;
3064 int TargetID; 3062 int TargetID;
@@ -3309,7 +3307,7 @@ Target Requested Completed Requested Completed Requested Completed\n\
3309static void BusLogic_Message(enum BusLogic_MessageLevel MessageLevel, char *Format, struct BusLogic_HostAdapter *HostAdapter, ...) 3307static void BusLogic_Message(enum BusLogic_MessageLevel MessageLevel, char *Format, struct BusLogic_HostAdapter *HostAdapter, ...)
3310{ 3308{
3311 static char Buffer[BusLogic_LineBufferSize]; 3309 static char Buffer[BusLogic_LineBufferSize];
3312 static boolean BeginningOfLine = true; 3310 static bool BeginningOfLine = true;
3313 va_list Arguments; 3311 va_list Arguments;
3314 int Length = 0; 3312 int Length = 0;
3315 va_start(Arguments, HostAdapter); 3313 va_start(Arguments, HostAdapter);
@@ -3347,7 +3345,7 @@ static void BusLogic_Message(enum BusLogic_MessageLevel MessageLevel, char *Form
3347 and updates the pointer if the keyword is recognized and false otherwise. 3345 and updates the pointer if the keyword is recognized and false otherwise.
3348*/ 3346*/
3349 3347
3350static boolean __init BusLogic_ParseKeyword(char **StringPointer, char *Keyword) 3348static bool __init BusLogic_ParseKeyword(char **StringPointer, char *Keyword)
3351{ 3349{
3352 char *Pointer = *StringPointer; 3350 char *Pointer = *StringPointer;
3353 while (*Keyword != '\0') { 3351 while (*Keyword != '\0') {
diff --git a/drivers/scsi/BusLogic.h b/drivers/scsi/BusLogic.h
index cca6d45eee4..bfbfb5c3a8f 100644
--- a/drivers/scsi/BusLogic.h
+++ b/drivers/scsi/BusLogic.h
@@ -234,12 +234,6 @@ enum BusLogic_BIOS_DiskGeometryTranslation {
234 234
235 235
236/* 236/*
237 Define a Boolean data type.
238*/
239
240typedef bool boolean;
241
242/*
243 Define a 10^18 Statistics Byte Counter data type. 237 Define a 10^18 Statistics Byte Counter data type.
244*/ 238*/
245 239
@@ -269,19 +263,19 @@ struct BusLogic_ProbeInfo {
269*/ 263*/
270 264
271struct BusLogic_ProbeOptions { 265struct BusLogic_ProbeOptions {
272 boolean NoProbe:1; /* Bit 0 */ 266 bool NoProbe:1; /* Bit 0 */
273 boolean NoProbeISA:1; /* Bit 1 */ 267 bool NoProbeISA:1; /* Bit 1 */
274 boolean NoProbePCI:1; /* Bit 2 */ 268 bool NoProbePCI:1; /* Bit 2 */
275 boolean NoSortPCI:1; /* Bit 3 */ 269 bool NoSortPCI:1; /* Bit 3 */
276 boolean MultiMasterFirst:1; /* Bit 4 */ 270 bool MultiMasterFirst:1;/* Bit 4 */
277 boolean FlashPointFirst:1; /* Bit 5 */ 271 bool FlashPointFirst:1; /* Bit 5 */
278 boolean LimitedProbeISA:1; /* Bit 6 */ 272 bool LimitedProbeISA:1; /* Bit 6 */
279 boolean Probe330:1; /* Bit 7 */ 273 bool Probe330:1; /* Bit 7 */
280 boolean Probe334:1; /* Bit 8 */ 274 bool Probe334:1; /* Bit 8 */
281 boolean Probe230:1; /* Bit 9 */ 275 bool Probe230:1; /* Bit 9 */
282 boolean Probe234:1; /* Bit 10 */ 276 bool Probe234:1; /* Bit 10 */
283 boolean Probe130:1; /* Bit 11 */ 277 bool Probe130:1; /* Bit 11 */
284 boolean Probe134:1; /* Bit 12 */ 278 bool Probe134:1; /* Bit 12 */
285}; 279};
286 280
287/* 281/*
@@ -289,10 +283,10 @@ struct BusLogic_ProbeOptions {
289*/ 283*/
290 284
291struct BusLogic_GlobalOptions { 285struct BusLogic_GlobalOptions {
292 boolean TraceProbe:1; /* Bit 0 */ 286 bool TraceProbe:1; /* Bit 0 */
293 boolean TraceHardwareReset:1; /* Bit 1 */ 287 bool TraceHardwareReset:1; /* Bit 1 */
294 boolean TraceConfiguration:1; /* Bit 2 */ 288 bool TraceConfiguration:1; /* Bit 2 */
295 boolean TraceErrors:1; /* Bit 3 */ 289 bool TraceErrors:1; /* Bit 3 */
296}; 290};
297 291
298/* 292/*
@@ -300,7 +294,7 @@ struct BusLogic_GlobalOptions {
300*/ 294*/
301 295
302struct BusLogic_LocalOptions { 296struct BusLogic_LocalOptions {
303 boolean InhibitTargetInquiry:1; /* Bit 0 */ 297 bool InhibitTargetInquiry:1; /* Bit 0 */
304}; 298};
305 299
306/* 300/*
@@ -322,10 +316,10 @@ union BusLogic_ControlRegister {
322 unsigned char All; 316 unsigned char All;
323 struct { 317 struct {
324 unsigned char:4; /* Bits 0-3 */ 318 unsigned char:4; /* Bits 0-3 */
325 boolean SCSIBusReset:1; /* Bit 4 */ 319 bool SCSIBusReset:1; /* Bit 4 */
326 boolean InterruptReset:1; /* Bit 5 */ 320 bool InterruptReset:1; /* Bit 5 */
327 boolean SoftReset:1; /* Bit 6 */ 321 bool SoftReset:1; /* Bit 6 */
328 boolean HardReset:1; /* Bit 7 */ 322 bool HardReset:1; /* Bit 7 */
329 } cr; 323 } cr;
330}; 324};
331 325
@@ -336,14 +330,14 @@ union BusLogic_ControlRegister {
336union BusLogic_StatusRegister { 330union BusLogic_StatusRegister {
337 unsigned char All; 331 unsigned char All;
338 struct { 332 struct {
339 boolean CommandInvalid:1; /* Bit 0 */ 333 bool CommandInvalid:1; /* Bit 0 */
340 boolean Reserved:1; /* Bit 1 */ 334 bool Reserved:1; /* Bit 1 */
341 boolean DataInRegisterReady:1; /* Bit 2 */ 335 bool DataInRegisterReady:1; /* Bit 2 */
342 boolean CommandParameterRegisterBusy:1; /* Bit 3 */ 336 bool CommandParameterRegisterBusy:1; /* Bit 3 */
343 boolean HostAdapterReady:1; /* Bit 4 */ 337 bool HostAdapterReady:1; /* Bit 4 */
344 boolean InitializationRequired:1; /* Bit 5 */ 338 bool InitializationRequired:1; /* Bit 5 */
345 boolean DiagnosticFailure:1; /* Bit 6 */ 339 bool DiagnosticFailure:1; /* Bit 6 */
346 boolean DiagnosticActive:1; /* Bit 7 */ 340 bool DiagnosticActive:1; /* Bit 7 */
347 } sr; 341 } sr;
348}; 342};
349 343
@@ -354,12 +348,12 @@ union BusLogic_StatusRegister {
354union BusLogic_InterruptRegister { 348union BusLogic_InterruptRegister {
355 unsigned char All; 349 unsigned char All;
356 struct { 350 struct {
357 boolean IncomingMailboxLoaded:1; /* Bit 0 */ 351 bool IncomingMailboxLoaded:1; /* Bit 0 */
358 boolean OutgoingMailboxAvailable:1; /* Bit 1 */ 352 bool OutgoingMailboxAvailable:1;/* Bit 1 */
359 boolean CommandComplete:1; /* Bit 2 */ 353 bool CommandComplete:1; /* Bit 2 */
360 boolean ExternalBusReset:1; /* Bit 3 */ 354 bool ExternalBusReset:1; /* Bit 3 */
361 unsigned char Reserved:3; /* Bits 4-6 */ 355 unsigned char Reserved:3; /* Bits 4-6 */
362 boolean InterruptValid:1; /* Bit 7 */ 356 bool InterruptValid:1; /* Bit 7 */
363 } ir; 357 } ir;
364}; 358};
365 359
@@ -373,7 +367,7 @@ union BusLogic_GeometryRegister {
373 enum BusLogic_BIOS_DiskGeometryTranslation Drive0Geometry:2; /* Bits 0-1 */ 367 enum BusLogic_BIOS_DiskGeometryTranslation Drive0Geometry:2; /* Bits 0-1 */
374 enum BusLogic_BIOS_DiskGeometryTranslation Drive1Geometry:2; /* Bits 2-3 */ 368 enum BusLogic_BIOS_DiskGeometryTranslation Drive1Geometry:2; /* Bits 2-3 */
375 unsigned char:3; /* Bits 4-6 */ 369 unsigned char:3; /* Bits 4-6 */
376 boolean ExtendedTranslationEnabled:1; /* Bit 7 */ 370 bool ExtendedTranslationEnabled:1; /* Bit 7 */
377 } gr; 371 } gr;
378}; 372};
379 373
@@ -445,16 +439,16 @@ struct BusLogic_BoardID {
445 439
446struct BusLogic_Configuration { 440struct BusLogic_Configuration {
447 unsigned char:5; /* Byte 0 Bits 0-4 */ 441 unsigned char:5; /* Byte 0 Bits 0-4 */
448 boolean DMA_Channel5:1; /* Byte 0 Bit 5 */ 442 bool DMA_Channel5:1; /* Byte 0 Bit 5 */
449 boolean DMA_Channel6:1; /* Byte 0 Bit 6 */ 443 bool DMA_Channel6:1; /* Byte 0 Bit 6 */
450 boolean DMA_Channel7:1; /* Byte 0 Bit 7 */ 444 bool DMA_Channel7:1; /* Byte 0 Bit 7 */
451 boolean IRQ_Channel9:1; /* Byte 1 Bit 0 */ 445 bool IRQ_Channel9:1; /* Byte 1 Bit 0 */
452 boolean IRQ_Channel10:1; /* Byte 1 Bit 1 */ 446 bool IRQ_Channel10:1; /* Byte 1 Bit 1 */
453 boolean IRQ_Channel11:1; /* Byte 1 Bit 2 */ 447 bool IRQ_Channel11:1; /* Byte 1 Bit 2 */
454 boolean IRQ_Channel12:1; /* Byte 1 Bit 3 */ 448 bool IRQ_Channel12:1; /* Byte 1 Bit 3 */
455 unsigned char:1; /* Byte 1 Bit 4 */ 449 unsigned char:1; /* Byte 1 Bit 4 */
456 boolean IRQ_Channel14:1; /* Byte 1 Bit 5 */ 450 bool IRQ_Channel14:1; /* Byte 1 Bit 5 */
457 boolean IRQ_Channel15:1; /* Byte 1 Bit 6 */ 451 bool IRQ_Channel15:1; /* Byte 1 Bit 6 */
458 unsigned char:1; /* Byte 1 Bit 7 */ 452 unsigned char:1; /* Byte 1 Bit 7 */
459 unsigned char HostAdapterID:4; /* Byte 2 Bits 0-3 */ 453 unsigned char HostAdapterID:4; /* Byte 2 Bits 0-3 */
460 unsigned char:4; /* Byte 2 Bits 4-7 */ 454 unsigned char:4; /* Byte 2 Bits 4-7 */
@@ -467,12 +461,12 @@ struct BusLogic_Configuration {
467struct BusLogic_SynchronousValue { 461struct BusLogic_SynchronousValue {
468 unsigned char Offset:4; /* Bits 0-3 */ 462 unsigned char Offset:4; /* Bits 0-3 */
469 unsigned char TransferPeriod:3; /* Bits 4-6 */ 463 unsigned char TransferPeriod:3; /* Bits 4-6 */
470 boolean Synchronous:1; /* Bit 7 */ 464 bool Synchronous:1; /* Bit 7 */
471}; 465};
472 466
473struct BusLogic_SetupInformation { 467struct BusLogic_SetupInformation {
474 boolean SynchronousInitiationEnabled:1; /* Byte 0 Bit 0 */ 468 bool SynchronousInitiationEnabled:1; /* Byte 0 Bit 0 */
475 boolean ParityCheckingEnabled:1; /* Byte 0 Bit 1 */ 469 bool ParityCheckingEnabled:1; /* Byte 0 Bit 1 */
476 unsigned char:6; /* Byte 0 Bits 2-7 */ 470 unsigned char:6; /* Byte 0 Bits 2-7 */
477 unsigned char BusTransferRate; /* Byte 1 */ 471 unsigned char BusTransferRate; /* Byte 1 */
478 unsigned char PreemptTimeOnBus; /* Byte 2 */ 472 unsigned char PreemptTimeOnBus; /* Byte 2 */
@@ -523,13 +517,13 @@ enum BusLogic_ISACompatibleIOPort {
523struct BusLogic_PCIHostAdapterInformation { 517struct BusLogic_PCIHostAdapterInformation {
524 enum BusLogic_ISACompatibleIOPort ISACompatibleIOPort; /* Byte 0 */ 518 enum BusLogic_ISACompatibleIOPort ISACompatibleIOPort; /* Byte 0 */
525 unsigned char PCIAssignedIRQChannel; /* Byte 1 */ 519 unsigned char PCIAssignedIRQChannel; /* Byte 1 */
526 boolean LowByteTerminated:1; /* Byte 2 Bit 0 */ 520 bool LowByteTerminated:1; /* Byte 2 Bit 0 */
527 boolean HighByteTerminated:1; /* Byte 2 Bit 1 */ 521 bool HighByteTerminated:1; /* Byte 2 Bit 1 */
528 unsigned char:2; /* Byte 2 Bits 2-3 */ 522 unsigned char:2; /* Byte 2 Bits 2-3 */
529 boolean JP1:1; /* Byte 2 Bit 4 */ 523 bool JP1:1; /* Byte 2 Bit 4 */
530 boolean JP2:1; /* Byte 2 Bit 5 */ 524 bool JP2:1; /* Byte 2 Bit 5 */
531 boolean JP3:1; /* Byte 2 Bit 6 */ 525 bool JP3:1; /* Byte 2 Bit 6 */
532 boolean GenericInfoValid:1; /* Byte 2 Bit 7 */ 526 bool GenericInfoValid:1;/* Byte 2 Bit 7 */
533 unsigned char:8; /* Byte 3 */ 527 unsigned char:8; /* Byte 3 */
534}; 528};
535 529
@@ -545,17 +539,17 @@ struct BusLogic_ExtendedSetupInformation {
545 u32 BaseMailboxAddress; /* Bytes 5-8 */ 539 u32 BaseMailboxAddress; /* Bytes 5-8 */
546 struct { 540 struct {
547 unsigned char:2; /* Byte 9 Bits 0-1 */ 541 unsigned char:2; /* Byte 9 Bits 0-1 */
548 boolean FastOnEISA:1; /* Byte 9 Bit 2 */ 542 bool FastOnEISA:1; /* Byte 9 Bit 2 */
549 unsigned char:3; /* Byte 9 Bits 3-5 */ 543 unsigned char:3; /* Byte 9 Bits 3-5 */
550 boolean LevelSensitiveInterrupt:1; /* Byte 9 Bit 6 */ 544 bool LevelSensitiveInterrupt:1; /* Byte 9 Bit 6 */
551 unsigned char:1; /* Byte 9 Bit 7 */ 545 unsigned char:1; /* Byte 9 Bit 7 */
552 } Misc; 546 } Misc;
553 unsigned char FirmwareRevision[3]; /* Bytes 10-12 */ 547 unsigned char FirmwareRevision[3]; /* Bytes 10-12 */
554 boolean HostWideSCSI:1; /* Byte 13 Bit 0 */ 548 bool HostWideSCSI:1; /* Byte 13 Bit 0 */
555 boolean HostDifferentialSCSI:1; /* Byte 13 Bit 1 */ 549 bool HostDifferentialSCSI:1; /* Byte 13 Bit 1 */
556 boolean HostSupportsSCAM:1; /* Byte 13 Bit 2 */ 550 bool HostSupportsSCAM:1; /* Byte 13 Bit 2 */
557 boolean HostUltraSCSI:1; /* Byte 13 Bit 3 */ 551 bool HostUltraSCSI:1; /* Byte 13 Bit 3 */
558 boolean HostSmartTermination:1; /* Byte 13 Bit 4 */ 552 bool HostSmartTermination:1; /* Byte 13 Bit 4 */
559 unsigned char:3; /* Byte 13 Bits 5-7 */ 553 unsigned char:3; /* Byte 13 Bits 5-7 */
560} PACKED; 554} PACKED;
561 555
@@ -590,35 +584,35 @@ struct BusLogic_AutoSCSIData {
590 unsigned char InformationByteCount; /* Byte 2 */ 584 unsigned char InformationByteCount; /* Byte 2 */
591 unsigned char HostAdapterType[6]; /* Bytes 3-8 */ 585 unsigned char HostAdapterType[6]; /* Bytes 3-8 */
592 unsigned char:8; /* Byte 9 */ 586 unsigned char:8; /* Byte 9 */
593 boolean FloppyEnabled:1; /* Byte 10 Bit 0 */ 587 bool FloppyEnabled:1; /* Byte 10 Bit 0 */
594 boolean FloppySecondary:1; /* Byte 10 Bit 1 */ 588 bool FloppySecondary:1; /* Byte 10 Bit 1 */
595 boolean LevelSensitiveInterrupt:1; /* Byte 10 Bit 2 */ 589 bool LevelSensitiveInterrupt:1; /* Byte 10 Bit 2 */
596 unsigned char:2; /* Byte 10 Bits 3-4 */ 590 unsigned char:2; /* Byte 10 Bits 3-4 */
597 unsigned char SystemRAMAreaForBIOS:3; /* Byte 10 Bits 5-7 */ 591 unsigned char SystemRAMAreaForBIOS:3; /* Byte 10 Bits 5-7 */
598 unsigned char DMA_Channel:7; /* Byte 11 Bits 0-6 */ 592 unsigned char DMA_Channel:7; /* Byte 11 Bits 0-6 */
599 boolean DMA_AutoConfiguration:1; /* Byte 11 Bit 7 */ 593 bool DMA_AutoConfiguration:1; /* Byte 11 Bit 7 */
600 unsigned char IRQ_Channel:7; /* Byte 12 Bits 0-6 */ 594 unsigned char IRQ_Channel:7; /* Byte 12 Bits 0-6 */
601 boolean IRQ_AutoConfiguration:1; /* Byte 12 Bit 7 */ 595 bool IRQ_AutoConfiguration:1; /* Byte 12 Bit 7 */
602 unsigned char DMA_TransferRate; /* Byte 13 */ 596 unsigned char DMA_TransferRate; /* Byte 13 */
603 unsigned char SCSI_ID; /* Byte 14 */ 597 unsigned char SCSI_ID; /* Byte 14 */
604 boolean LowByteTerminated:1; /* Byte 15 Bit 0 */ 598 bool LowByteTerminated:1; /* Byte 15 Bit 0 */
605 boolean ParityCheckingEnabled:1; /* Byte 15 Bit 1 */ 599 bool ParityCheckingEnabled:1; /* Byte 15 Bit 1 */
606 boolean HighByteTerminated:1; /* Byte 15 Bit 2 */ 600 bool HighByteTerminated:1; /* Byte 15 Bit 2 */
607 boolean NoisyCablingEnvironment:1; /* Byte 15 Bit 3 */ 601 bool NoisyCablingEnvironment:1; /* Byte 15 Bit 3 */
608 boolean FastSynchronousNegotiation:1; /* Byte 15 Bit 4 */ 602 bool FastSynchronousNegotiation:1; /* Byte 15 Bit 4 */
609 boolean BusResetEnabled:1; /* Byte 15 Bit 5 */ 603 bool BusResetEnabled:1; /* Byte 15 Bit 5 */
610 boolean:1; /* Byte 15 Bit 6 */ 604 bool:1; /* Byte 15 Bit 6 */
611 boolean ActiveNegationEnabled:1; /* Byte 15 Bit 7 */ 605 bool ActiveNegationEnabled:1; /* Byte 15 Bit 7 */
612 unsigned char BusOnDelay; /* Byte 16 */ 606 unsigned char BusOnDelay; /* Byte 16 */
613 unsigned char BusOffDelay; /* Byte 17 */ 607 unsigned char BusOffDelay; /* Byte 17 */
614 boolean HostAdapterBIOSEnabled:1; /* Byte 18 Bit 0 */ 608 bool HostAdapterBIOSEnabled:1; /* Byte 18 Bit 0 */
615 boolean BIOSRedirectionOfINT19Enabled:1; /* Byte 18 Bit 1 */ 609 bool BIOSRedirectionOfINT19Enabled:1; /* Byte 18 Bit 1 */
616 boolean ExtendedTranslationEnabled:1; /* Byte 18 Bit 2 */ 610 bool ExtendedTranslationEnabled:1; /* Byte 18 Bit 2 */
617 boolean MapRemovableAsFixedEnabled:1; /* Byte 18 Bit 3 */ 611 bool MapRemovableAsFixedEnabled:1; /* Byte 18 Bit 3 */
618 boolean:1; /* Byte 18 Bit 4 */ 612 bool:1; /* Byte 18 Bit 4 */
619 boolean BIOSSupportsMoreThan2DrivesEnabled:1; /* Byte 18 Bit 5 */ 613 bool BIOSSupportsMoreThan2DrivesEnabled:1; /* Byte 18 Bit 5 */
620 boolean BIOSInterruptModeEnabled:1; /* Byte 18 Bit 6 */ 614 bool BIOSInterruptModeEnabled:1; /* Byte 18 Bit 6 */
621 boolean FlopticalSupportEnabled:1; /* Byte 19 Bit 7 */ 615 bool FlopticalSupportEnabled:1; /* Byte 19 Bit 7 */
622 unsigned short DeviceEnabled; /* Bytes 19-20 */ 616 unsigned short DeviceEnabled; /* Bytes 19-20 */
623 unsigned short WidePermitted; /* Bytes 21-22 */ 617 unsigned short WidePermitted; /* Bytes 21-22 */
624 unsigned short FastPermitted; /* Bytes 23-24 */ 618 unsigned short FastPermitted; /* Bytes 23-24 */
@@ -628,22 +622,22 @@ struct BusLogic_AutoSCSIData {
628 unsigned short IgnoreInBIOSScan; /* Bytes 31-32 */ 622 unsigned short IgnoreInBIOSScan; /* Bytes 31-32 */
629 unsigned char PCIInterruptPin:2; /* Byte 33 Bits 0-1 */ 623 unsigned char PCIInterruptPin:2; /* Byte 33 Bits 0-1 */
630 unsigned char HostAdapterIOPortAddress:2; /* Byte 33 Bits 2-3 */ 624 unsigned char HostAdapterIOPortAddress:2; /* Byte 33 Bits 2-3 */
631 boolean StrictRoundRobinModeEnabled:1; /* Byte 33 Bit 4 */ 625 bool StrictRoundRobinModeEnabled:1; /* Byte 33 Bit 4 */
632 boolean VESABusSpeedGreaterThan33MHz:1; /* Byte 33 Bit 5 */ 626 bool VESABusSpeedGreaterThan33MHz:1; /* Byte 33 Bit 5 */
633 boolean VESABurstWriteEnabled:1; /* Byte 33 Bit 6 */ 627 bool VESABurstWriteEnabled:1; /* Byte 33 Bit 6 */
634 boolean VESABurstReadEnabled:1; /* Byte 33 Bit 7 */ 628 bool VESABurstReadEnabled:1; /* Byte 33 Bit 7 */
635 unsigned short UltraPermitted; /* Bytes 34-35 */ 629 unsigned short UltraPermitted; /* Bytes 34-35 */
636 unsigned int:32; /* Bytes 36-39 */ 630 unsigned int:32; /* Bytes 36-39 */
637 unsigned char:8; /* Byte 40 */ 631 unsigned char:8; /* Byte 40 */
638 unsigned char AutoSCSIMaximumLUN; /* Byte 41 */ 632 unsigned char AutoSCSIMaximumLUN; /* Byte 41 */
639 boolean:1; /* Byte 42 Bit 0 */ 633 bool:1; /* Byte 42 Bit 0 */
640 boolean SCAM_Dominant:1; /* Byte 42 Bit 1 */ 634 bool SCAM_Dominant:1; /* Byte 42 Bit 1 */
641 boolean SCAM_Enabled:1; /* Byte 42 Bit 2 */ 635 bool SCAM_Enabled:1; /* Byte 42 Bit 2 */
642 boolean SCAM_Level2:1; /* Byte 42 Bit 3 */ 636 bool SCAM_Level2:1; /* Byte 42 Bit 3 */
643 unsigned char:4; /* Byte 42 Bits 4-7 */ 637 unsigned char:4; /* Byte 42 Bits 4-7 */
644 boolean INT13ExtensionEnabled:1; /* Byte 43 Bit 0 */ 638 bool INT13ExtensionEnabled:1; /* Byte 43 Bit 0 */
645 boolean:1; /* Byte 43 Bit 1 */ 639 bool:1; /* Byte 43 Bit 1 */
646 boolean CDROMBootEnabled:1; /* Byte 43 Bit 2 */ 640 bool CDROMBootEnabled:1; /* Byte 43 Bit 2 */
647 unsigned char:5; /* Byte 43 Bits 3-7 */ 641 unsigned char:5; /* Byte 43 Bits 3-7 */
648 unsigned char BootTargetID:4; /* Byte 44 Bits 0-3 */ 642 unsigned char BootTargetID:4; /* Byte 44 Bits 0-3 */
649 unsigned char BootChannel:4; /* Byte 44 Bits 4-7 */ 643 unsigned char BootChannel:4; /* Byte 44 Bits 4-7 */
@@ -852,7 +846,7 @@ struct BusLogic_CCB {
852 enum BusLogic_CCB_Opcode Opcode; /* Byte 0 */ 846 enum BusLogic_CCB_Opcode Opcode; /* Byte 0 */
853 unsigned char:3; /* Byte 1 Bits 0-2 */ 847 unsigned char:3; /* Byte 1 Bits 0-2 */
854 enum BusLogic_DataDirection DataDirection:2; /* Byte 1 Bits 3-4 */ 848 enum BusLogic_DataDirection DataDirection:2; /* Byte 1 Bits 3-4 */
855 boolean TagEnable:1; /* Byte 1 Bit 5 */ 849 bool TagEnable:1; /* Byte 1 Bit 5 */
856 enum BusLogic_QueueTag QueueTag:2; /* Byte 1 Bits 6-7 */ 850 enum BusLogic_QueueTag QueueTag:2; /* Byte 1 Bits 6-7 */
857 unsigned char CDB_Length; /* Byte 2 */ 851 unsigned char CDB_Length; /* Byte 2 */
858 unsigned char SenseDataLength; /* Byte 3 */ 852 unsigned char SenseDataLength; /* Byte 3 */
@@ -864,7 +858,7 @@ struct BusLogic_CCB {
864 enum BusLogic_TargetDeviceStatus TargetDeviceStatus; /* Byte 15 */ 858 enum BusLogic_TargetDeviceStatus TargetDeviceStatus; /* Byte 15 */
865 unsigned char TargetID; /* Byte 16 */ 859 unsigned char TargetID; /* Byte 16 */
866 unsigned char LogicalUnit:5; /* Byte 17 Bits 0-4 */ 860 unsigned char LogicalUnit:5; /* Byte 17 Bits 0-4 */
867 boolean LegacyTagEnable:1; /* Byte 17 Bit 5 */ 861 bool LegacyTagEnable:1; /* Byte 17 Bit 5 */
868 enum BusLogic_QueueTag LegacyQueueTag:2; /* Byte 17 Bits 6-7 */ 862 enum BusLogic_QueueTag LegacyQueueTag:2; /* Byte 17 Bits 6-7 */
869 SCSI_CDB_T CDB; /* Bytes 18-29 */ 863 SCSI_CDB_T CDB; /* Bytes 18-29 */
870 unsigned char:8; /* Byte 30 */ 864 unsigned char:8; /* Byte 30 */
@@ -939,13 +933,13 @@ struct BusLogic_DriverOptions {
939*/ 933*/
940 934
941struct BusLogic_TargetFlags { 935struct BusLogic_TargetFlags {
942 boolean TargetExists:1; 936 bool TargetExists:1;
943 boolean TaggedQueuingSupported:1; 937 bool TaggedQueuingSupported:1;
944 boolean WideTransfersSupported:1; 938 bool WideTransfersSupported:1;
945 boolean TaggedQueuingActive:1; 939 bool TaggedQueuingActive:1;
946 boolean WideTransfersActive:1; 940 bool WideTransfersActive:1;
947 boolean CommandSuccessfulFlag:1; 941 bool CommandSuccessfulFlag:1;
948 boolean TargetInfoReported:1; 942 bool TargetInfoReported:1;
949}; 943};
950 944
951/* 945/*
@@ -992,7 +986,7 @@ typedef unsigned int FlashPoint_CardHandle_T;
992 986
993struct FlashPoint_Info { 987struct FlashPoint_Info {
994 u32 BaseAddress; /* Bytes 0-3 */ 988 u32 BaseAddress; /* Bytes 0-3 */
995 boolean Present; /* Byte 4 */ 989 bool Present; /* Byte 4 */
996 unsigned char IRQ_Channel; /* Byte 5 */ 990 unsigned char IRQ_Channel; /* Byte 5 */
997 unsigned char SCSI_ID; /* Byte 6 */ 991 unsigned char SCSI_ID; /* Byte 6 */
998 unsigned char SCSI_LUN; /* Byte 7 */ 992 unsigned char SCSI_LUN; /* Byte 7 */
@@ -1002,15 +996,15 @@ struct FlashPoint_Info {
1002 unsigned short UltraPermitted; /* Bytes 14-15 */ 996 unsigned short UltraPermitted; /* Bytes 14-15 */
1003 unsigned short DisconnectPermitted; /* Bytes 16-17 */ 997 unsigned short DisconnectPermitted; /* Bytes 16-17 */
1004 unsigned short WidePermitted; /* Bytes 18-19 */ 998 unsigned short WidePermitted; /* Bytes 18-19 */
1005 boolean ParityCheckingEnabled:1; /* Byte 20 Bit 0 */ 999 bool ParityCheckingEnabled:1; /* Byte 20 Bit 0 */
1006 boolean HostWideSCSI:1; /* Byte 20 Bit 1 */ 1000 bool HostWideSCSI:1; /* Byte 20 Bit 1 */
1007 boolean HostSoftReset:1; /* Byte 20 Bit 2 */ 1001 bool HostSoftReset:1; /* Byte 20 Bit 2 */
1008 boolean ExtendedTranslationEnabled:1; /* Byte 20 Bit 3 */ 1002 bool ExtendedTranslationEnabled:1; /* Byte 20 Bit 3 */
1009 boolean LowByteTerminated:1; /* Byte 20 Bit 4 */ 1003 bool LowByteTerminated:1; /* Byte 20 Bit 4 */
1010 boolean HighByteTerminated:1; /* Byte 20 Bit 5 */ 1004 bool HighByteTerminated:1; /* Byte 20 Bit 5 */
1011 boolean ReportDataUnderrun:1; /* Byte 20 Bit 6 */ 1005 bool ReportDataUnderrun:1; /* Byte 20 Bit 6 */
1012 boolean SCAM_Enabled:1; /* Byte 20 Bit 7 */ 1006 bool SCAM_Enabled:1; /* Byte 20 Bit 7 */
1013 boolean SCAM_Level2:1; /* Byte 21 Bit 0 */ 1007 bool SCAM_Level2:1; /* Byte 21 Bit 0 */
1014 unsigned char:7; /* Byte 21 Bits 1-7 */ 1008 unsigned char:7; /* Byte 21 Bits 1-7 */
1015 unsigned char Family; /* Byte 22 */ 1009 unsigned char Family; /* Byte 22 */
1016 unsigned char BusType; /* Byte 23 */ 1010 unsigned char BusType; /* Byte 23 */
@@ -1044,29 +1038,29 @@ struct BusLogic_HostAdapter {
1044 unsigned char IRQ_Channel; 1038 unsigned char IRQ_Channel;
1045 unsigned char DMA_Channel; 1039 unsigned char DMA_Channel;
1046 unsigned char SCSI_ID; 1040 unsigned char SCSI_ID;
1047 boolean IRQ_ChannelAcquired:1; 1041 bool IRQ_ChannelAcquired:1;
1048 boolean DMA_ChannelAcquired:1; 1042 bool DMA_ChannelAcquired:1;
1049 boolean ExtendedTranslationEnabled:1; 1043 bool ExtendedTranslationEnabled:1;
1050 boolean ParityCheckingEnabled:1; 1044 bool ParityCheckingEnabled:1;
1051 boolean BusResetEnabled:1; 1045 bool BusResetEnabled:1;
1052 boolean LevelSensitiveInterrupt:1; 1046 bool LevelSensitiveInterrupt:1;
1053 boolean HostWideSCSI:1; 1047 bool HostWideSCSI:1;
1054 boolean HostDifferentialSCSI:1; 1048 bool HostDifferentialSCSI:1;
1055 boolean HostSupportsSCAM:1; 1049 bool HostSupportsSCAM:1;
1056 boolean HostUltraSCSI:1; 1050 bool HostUltraSCSI:1;
1057 boolean ExtendedLUNSupport:1; 1051 bool ExtendedLUNSupport:1;
1058 boolean TerminationInfoValid:1; 1052 bool TerminationInfoValid:1;
1059 boolean LowByteTerminated:1; 1053 bool LowByteTerminated:1;
1060 boolean HighByteTerminated:1; 1054 bool HighByteTerminated:1;
1061 boolean BounceBuffersRequired:1; 1055 bool BounceBuffersRequired:1;
1062 boolean StrictRoundRobinModeSupport:1; 1056 bool StrictRoundRobinModeSupport:1;
1063 boolean SCAM_Enabled:1; 1057 bool SCAM_Enabled:1;
1064 boolean SCAM_Level2:1; 1058 bool SCAM_Level2:1;
1065 boolean HostAdapterInitialized:1; 1059 bool HostAdapterInitialized:1;
1066 boolean HostAdapterExternalReset:1; 1060 bool HostAdapterExternalReset:1;
1067 boolean HostAdapterInternalError:1; 1061 bool HostAdapterInternalError:1;
1068 boolean ProcessCompletedCCBsActive; 1062 bool ProcessCompletedCCBsActive;
1069 volatile boolean HostAdapterCommandCompleted; 1063 volatile bool HostAdapterCommandCompleted;
1070 unsigned short HostAdapterScatterGatherLimit; 1064 unsigned short HostAdapterScatterGatherLimit;
1071 unsigned short DriverScatterGatherLimit; 1065 unsigned short DriverScatterGatherLimit;
1072 unsigned short MaxTargetDevices; 1066 unsigned short MaxTargetDevices;
@@ -1141,25 +1135,25 @@ struct SCSI_Inquiry {
1141 unsigned char PeripheralDeviceType:5; /* Byte 0 Bits 0-4 */ 1135 unsigned char PeripheralDeviceType:5; /* Byte 0 Bits 0-4 */
1142 unsigned char PeripheralQualifier:3; /* Byte 0 Bits 5-7 */ 1136 unsigned char PeripheralQualifier:3; /* Byte 0 Bits 5-7 */
1143 unsigned char DeviceTypeModifier:7; /* Byte 1 Bits 0-6 */ 1137 unsigned char DeviceTypeModifier:7; /* Byte 1 Bits 0-6 */
1144 boolean RMB:1; /* Byte 1 Bit 7 */ 1138 bool RMB:1; /* Byte 1 Bit 7 */
1145 unsigned char ANSI_ApprovedVersion:3; /* Byte 2 Bits 0-2 */ 1139 unsigned char ANSI_ApprovedVersion:3; /* Byte 2 Bits 0-2 */
1146 unsigned char ECMA_Version:3; /* Byte 2 Bits 3-5 */ 1140 unsigned char ECMA_Version:3; /* Byte 2 Bits 3-5 */
1147 unsigned char ISO_Version:2; /* Byte 2 Bits 6-7 */ 1141 unsigned char ISO_Version:2; /* Byte 2 Bits 6-7 */
1148 unsigned char ResponseDataFormat:4; /* Byte 3 Bits 0-3 */ 1142 unsigned char ResponseDataFormat:4; /* Byte 3 Bits 0-3 */
1149 unsigned char:2; /* Byte 3 Bits 4-5 */ 1143 unsigned char:2; /* Byte 3 Bits 4-5 */
1150 boolean TrmIOP:1; /* Byte 3 Bit 6 */ 1144 bool TrmIOP:1; /* Byte 3 Bit 6 */
1151 boolean AENC:1; /* Byte 3 Bit 7 */ 1145 bool AENC:1; /* Byte 3 Bit 7 */
1152 unsigned char AdditionalLength; /* Byte 4 */ 1146 unsigned char AdditionalLength; /* Byte 4 */
1153 unsigned char:8; /* Byte 5 */ 1147 unsigned char:8; /* Byte 5 */
1154 unsigned char:8; /* Byte 6 */ 1148 unsigned char:8; /* Byte 6 */
1155 boolean SftRe:1; /* Byte 7 Bit 0 */ 1149 bool SftRe:1; /* Byte 7 Bit 0 */
1156 boolean CmdQue:1; /* Byte 7 Bit 1 */ 1150 bool CmdQue:1; /* Byte 7 Bit 1 */
1157 boolean:1; /* Byte 7 Bit 2 */ 1151 bool:1; /* Byte 7 Bit 2 */
1158 boolean Linked:1; /* Byte 7 Bit 3 */ 1152 bool Linked:1; /* Byte 7 Bit 3 */
1159 boolean Sync:1; /* Byte 7 Bit 4 */ 1153 bool Sync:1; /* Byte 7 Bit 4 */
1160 boolean WBus16:1; /* Byte 7 Bit 5 */ 1154 bool WBus16:1; /* Byte 7 Bit 5 */
1161 boolean WBus32:1; /* Byte 7 Bit 6 */ 1155 bool WBus32:1; /* Byte 7 Bit 6 */
1162 boolean RelAdr:1; /* Byte 7 Bit 7 */ 1156 bool RelAdr:1; /* Byte 7 Bit 7 */
1163 unsigned char VendorIdentification[8]; /* Bytes 8-15 */ 1157 unsigned char VendorIdentification[8]; /* Bytes 8-15 */
1164 unsigned char ProductIdentification[16]; /* Bytes 16-31 */ 1158 unsigned char ProductIdentification[16]; /* Bytes 16-31 */
1165 unsigned char ProductRevisionLevel[4]; /* Bytes 32-35 */ 1159 unsigned char ProductRevisionLevel[4]; /* Bytes 32-35 */
@@ -1348,7 +1342,7 @@ static int BusLogic_ProcDirectoryInfo(struct Scsi_Host *, char *, char **, off_t
1348static int BusLogic_SlaveConfigure(struct scsi_device *); 1342static int BusLogic_SlaveConfigure(struct scsi_device *);
1349static void BusLogic_QueueCompletedCCB(struct BusLogic_CCB *); 1343static void BusLogic_QueueCompletedCCB(struct BusLogic_CCB *);
1350static irqreturn_t BusLogic_InterruptHandler(int, void *); 1344static irqreturn_t BusLogic_InterruptHandler(int, void *);
1351static int BusLogic_ResetHostAdapter(struct BusLogic_HostAdapter *, boolean HardReset); 1345static int BusLogic_ResetHostAdapter(struct BusLogic_HostAdapter *, bool HardReset);
1352static void BusLogic_Message(enum BusLogic_MessageLevel, char *, struct BusLogic_HostAdapter *, ...); 1346static void BusLogic_Message(enum BusLogic_MessageLevel, char *, struct BusLogic_HostAdapter *, ...);
1353static int __init BusLogic_Setup(char *); 1347static int __init BusLogic_Setup(char *);
1354 1348
diff --git a/drivers/scsi/FlashPoint.c b/drivers/scsi/FlashPoint.c
index 7c006804958..a7f916c0c9c 100644
--- a/drivers/scsi/FlashPoint.c
+++ b/drivers/scsi/FlashPoint.c
@@ -7609,7 +7609,7 @@ FlashPoint__AbortCCB(FlashPoint_CardHandle_T CardHandle,
7609 FlashPoint_AbortCCB(CardHandle, (struct sccb *)CCB); 7609 FlashPoint_AbortCCB(CardHandle, (struct sccb *)CCB);
7610} 7610}
7611 7611
7612static inline boolean 7612static inline bool
7613FlashPoint__InterruptPending(FlashPoint_CardHandle_T CardHandle) 7613FlashPoint__InterruptPending(FlashPoint_CardHandle_T CardHandle)
7614{ 7614{
7615 return FlashPoint_InterruptPending(CardHandle); 7615 return FlashPoint_InterruptPending(CardHandle);
@@ -7640,7 +7640,7 @@ extern FlashPoint_CardHandle_T
7640FlashPoint_HardwareResetHostAdapter(struct FlashPoint_Info *); 7640FlashPoint_HardwareResetHostAdapter(struct FlashPoint_Info *);
7641extern void FlashPoint_StartCCB(FlashPoint_CardHandle_T, struct BusLogic_CCB *); 7641extern void FlashPoint_StartCCB(FlashPoint_CardHandle_T, struct BusLogic_CCB *);
7642extern int FlashPoint_AbortCCB(FlashPoint_CardHandle_T, struct BusLogic_CCB *); 7642extern int FlashPoint_AbortCCB(FlashPoint_CardHandle_T, struct BusLogic_CCB *);
7643extern boolean FlashPoint_InterruptPending(FlashPoint_CardHandle_T); 7643extern bool FlashPoint_InterruptPending(FlashPoint_CardHandle_T);
7644extern int FlashPoint_HandleInterrupt(FlashPoint_CardHandle_T); 7644extern int FlashPoint_HandleInterrupt(FlashPoint_CardHandle_T);
7645extern void FlashPoint_ReleaseHostAdapter(FlashPoint_CardHandle_T); 7645extern void FlashPoint_ReleaseHostAdapter(FlashPoint_CardHandle_T);
7646 7646
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index 7869c34a4a3..5bf3f07870b 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -973,6 +973,15 @@ config SCSI_LASI700
973 many PA-RISC workstations & servers. If you do not know whether you 973 many PA-RISC workstations & servers. If you do not know whether you
974 have a Lasi chip, it is safe to say "Y" here. 974 have a Lasi chip, it is safe to say "Y" here.
975 975
976config SCSI_SNI_53C710
977 tristate "SNI RM SCSI support for 53c710"
978 depends on SNI_RM && SCSI
979 select SCSI_SPI_ATTRS
980 select 53C700_LE_ON_BE
981 help
982 This is a driver for the onboard SCSI controller found in older
983 SNI RM workstations & servers.
984
976config 53C700_LE_ON_BE 985config 53C700_LE_ON_BE
977 bool 986 bool
978 depends on SCSI_LASI700 987 depends on SCSI_LASI700
diff --git a/drivers/scsi/Makefile b/drivers/scsi/Makefile
index bd7c9888f7f..79ecf4ebe6e 100644
--- a/drivers/scsi/Makefile
+++ b/drivers/scsi/Makefile
@@ -124,6 +124,7 @@ obj-$(CONFIG_JAZZ_ESP) += NCR53C9x.o jazz_esp.o
124obj-$(CONFIG_SUN3X_ESP) += NCR53C9x.o sun3x_esp.o 124obj-$(CONFIG_SUN3X_ESP) += NCR53C9x.o sun3x_esp.o
125obj-$(CONFIG_SCSI_FCAL) += fcal.o 125obj-$(CONFIG_SCSI_FCAL) += fcal.o
126obj-$(CONFIG_SCSI_LASI700) += 53c700.o lasi700.o 126obj-$(CONFIG_SCSI_LASI700) += 53c700.o lasi700.o
127obj-$(CONFIG_SCSI_SNI_53C710) += 53c700.o sni_53c710.o
127obj-$(CONFIG_SCSI_NSP32) += nsp32.o 128obj-$(CONFIG_SCSI_NSP32) += nsp32.o
128obj-$(CONFIG_SCSI_IPR) += ipr.o 129obj-$(CONFIG_SCSI_IPR) += ipr.o
129obj-$(CONFIG_SCSI_SRP) += libsrp.o 130obj-$(CONFIG_SCSI_SRP) += libsrp.o
diff --git a/drivers/scsi/NCR_D700.c b/drivers/scsi/NCR_D700.c
index 9859cd17fc5..f12864abed2 100644
--- a/drivers/scsi/NCR_D700.c
+++ b/drivers/scsi/NCR_D700.c
@@ -200,6 +200,7 @@ NCR_D700_probe_one(struct NCR_D700_private *p, int siop, int irq,
200 hostdata->base = ioport_map(region, 64); 200 hostdata->base = ioport_map(region, 64);
201 hostdata->differential = (((1<<siop) & differential) != 0); 201 hostdata->differential = (((1<<siop) & differential) != 0);
202 hostdata->clock = NCR_D700_CLOCK_MHZ; 202 hostdata->clock = NCR_D700_CLOCK_MHZ;
203 hostdata->burst_length = 8;
203 204
204 /* and register the siop */ 205 /* and register the siop */
205 host = NCR_700_detect(&NCR_D700_driver_template, hostdata, p->dev); 206 host = NCR_700_detect(&NCR_D700_driver_template, hostdata, p->dev);
diff --git a/drivers/scsi/aacraid/Makefile b/drivers/scsi/aacraid/Makefile
index 28d133a3094..f1cca4ee541 100644
--- a/drivers/scsi/aacraid/Makefile
+++ b/drivers/scsi/aacraid/Makefile
@@ -3,6 +3,6 @@
3obj-$(CONFIG_SCSI_AACRAID) := aacraid.o 3obj-$(CONFIG_SCSI_AACRAID) := aacraid.o
4 4
5aacraid-objs := linit.o aachba.o commctrl.o comminit.o commsup.o \ 5aacraid-objs := linit.o aachba.o commctrl.o comminit.o commsup.o \
6 dpcsup.o rx.o sa.o rkt.o 6 dpcsup.o rx.o sa.o rkt.o nark.o
7 7
8EXTRA_CFLAGS := -Idrivers/scsi 8EXTRA_CFLAGS := -Idrivers/scsi
diff --git a/drivers/scsi/aacraid/aachba.c b/drivers/scsi/aacraid/aachba.c
index 426cd6f49f5..ddb33b06e0e 100644
--- a/drivers/scsi/aacraid/aachba.c
+++ b/drivers/scsi/aacraid/aachba.c
@@ -170,9 +170,9 @@ int acbsize = -1;
170module_param(acbsize, int, S_IRUGO|S_IWUSR); 170module_param(acbsize, int, S_IRUGO|S_IWUSR);
171MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware."); 171MODULE_PARM_DESC(acbsize, "Request a specific adapter control block (FIB) size. Valid values are 512, 2048, 4096 and 8192. Default is to use suggestion from Firmware.");
172 172
173int expose_physicals = 0; 173int expose_physicals = -1;
174module_param(expose_physicals, int, S_IRUGO|S_IWUSR); 174module_param(expose_physicals, int, S_IRUGO|S_IWUSR);
175MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. 0=off, 1=on"); 175MODULE_PARM_DESC(expose_physicals, "Expose physical components of the arrays. -1=protect 0=off, 1=on");
176/** 176/**
177 * aac_get_config_status - check the adapter configuration 177 * aac_get_config_status - check the adapter configuration
178 * @common: adapter to query 178 * @common: adapter to query
@@ -706,6 +706,309 @@ static void set_sense(u8 *sense_buf, u8 sense_key, u8 sense_code,
706 } 706 }
707} 707}
708 708
709static int aac_bounds_32(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
710{
711 if (lba & 0xffffffff00000000LL) {
712 int cid = scmd_id(cmd);
713 dprintk((KERN_DEBUG "aacraid: Illegal lba\n"));
714 cmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
715 SAM_STAT_CHECK_CONDITION;
716 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
717 HARDWARE_ERROR,
718 SENCODE_INTERNAL_TARGET_FAILURE,
719 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
720 0, 0);
721 memcpy(cmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
722 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(cmd->sense_buffer))
723 ? sizeof(cmd->sense_buffer)
724 : sizeof(dev->fsa_dev[cid].sense_data));
725 cmd->scsi_done(cmd);
726 return 1;
727 }
728 return 0;
729}
730
731static int aac_bounds_64(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba)
732{
733 return 0;
734}
735
736static void io_callback(void *context, struct fib * fibptr);
737
738static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
739{
740 u16 fibsize;
741 struct aac_raw_io *readcmd;
742 aac_fib_init(fib);
743 readcmd = (struct aac_raw_io *) fib_data(fib);
744 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
745 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
746 readcmd->count = cpu_to_le32(count<<9);
747 readcmd->cid = cpu_to_le16(scmd_id(cmd));
748 readcmd->flags = cpu_to_le16(1);
749 readcmd->bpTotal = 0;
750 readcmd->bpComplete = 0;
751
752 aac_build_sgraw(cmd, &readcmd->sg);
753 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
754 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
755 /*
756 * Now send the Fib to the adapter
757 */
758 return aac_fib_send(ContainerRawIo,
759 fib,
760 fibsize,
761 FsaNormal,
762 0, 1,
763 (fib_callback) io_callback,
764 (void *) cmd);
765}
766
767static int aac_read_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
768{
769 u16 fibsize;
770 struct aac_read64 *readcmd;
771 aac_fib_init(fib);
772 readcmd = (struct aac_read64 *) fib_data(fib);
773 readcmd->command = cpu_to_le32(VM_CtHostRead64);
774 readcmd->cid = cpu_to_le16(scmd_id(cmd));
775 readcmd->sector_count = cpu_to_le16(count);
776 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
777 readcmd->pad = 0;
778 readcmd->flags = 0;
779
780 aac_build_sg64(cmd, &readcmd->sg);
781 fibsize = sizeof(struct aac_read64) +
782 ((le32_to_cpu(readcmd->sg.count) - 1) *
783 sizeof (struct sgentry64));
784 BUG_ON (fibsize > (fib->dev->max_fib_size -
785 sizeof(struct aac_fibhdr)));
786 /*
787 * Now send the Fib to the adapter
788 */
789 return aac_fib_send(ContainerCommand64,
790 fib,
791 fibsize,
792 FsaNormal,
793 0, 1,
794 (fib_callback) io_callback,
795 (void *) cmd);
796}
797
798static int aac_read_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
799{
800 u16 fibsize;
801 struct aac_read *readcmd;
802 aac_fib_init(fib);
803 readcmd = (struct aac_read *) fib_data(fib);
804 readcmd->command = cpu_to_le32(VM_CtBlockRead);
805 readcmd->cid = cpu_to_le16(scmd_id(cmd));
806 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
807 readcmd->count = cpu_to_le32(count * 512);
808
809 aac_build_sg(cmd, &readcmd->sg);
810 fibsize = sizeof(struct aac_read) +
811 ((le32_to_cpu(readcmd->sg.count) - 1) *
812 sizeof (struct sgentry));
813 BUG_ON (fibsize > (fib->dev->max_fib_size -
814 sizeof(struct aac_fibhdr)));
815 /*
816 * Now send the Fib to the adapter
817 */
818 return aac_fib_send(ContainerCommand,
819 fib,
820 fibsize,
821 FsaNormal,
822 0, 1,
823 (fib_callback) io_callback,
824 (void *) cmd);
825}
826
827static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
828{
829 u16 fibsize;
830 struct aac_raw_io *writecmd;
831 aac_fib_init(fib);
832 writecmd = (struct aac_raw_io *) fib_data(fib);
833 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
834 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
835 writecmd->count = cpu_to_le32(count<<9);
836 writecmd->cid = cpu_to_le16(scmd_id(cmd));
837 writecmd->flags = 0;
838 writecmd->bpTotal = 0;
839 writecmd->bpComplete = 0;
840
841 aac_build_sgraw(cmd, &writecmd->sg);
842 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
843 BUG_ON(fibsize > (fib->dev->max_fib_size - sizeof(struct aac_fibhdr)));
844 /*
845 * Now send the Fib to the adapter
846 */
847 return aac_fib_send(ContainerRawIo,
848 fib,
849 fibsize,
850 FsaNormal,
851 0, 1,
852 (fib_callback) io_callback,
853 (void *) cmd);
854}
855
856static int aac_write_block64(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
857{
858 u16 fibsize;
859 struct aac_write64 *writecmd;
860 aac_fib_init(fib);
861 writecmd = (struct aac_write64 *) fib_data(fib);
862 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
863 writecmd->cid = cpu_to_le16(scmd_id(cmd));
864 writecmd->sector_count = cpu_to_le16(count);
865 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
866 writecmd->pad = 0;
867 writecmd->flags = 0;
868
869 aac_build_sg64(cmd, &writecmd->sg);
870 fibsize = sizeof(struct aac_write64) +
871 ((le32_to_cpu(writecmd->sg.count) - 1) *
872 sizeof (struct sgentry64));
873 BUG_ON (fibsize > (fib->dev->max_fib_size -
874 sizeof(struct aac_fibhdr)));
875 /*
876 * Now send the Fib to the adapter
877 */
878 return aac_fib_send(ContainerCommand64,
879 fib,
880 fibsize,
881 FsaNormal,
882 0, 1,
883 (fib_callback) io_callback,
884 (void *) cmd);
885}
886
887static int aac_write_block(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count)
888{
889 u16 fibsize;
890 struct aac_write *writecmd;
891 aac_fib_init(fib);
892 writecmd = (struct aac_write *) fib_data(fib);
893 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
894 writecmd->cid = cpu_to_le16(scmd_id(cmd));
895 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
896 writecmd->count = cpu_to_le32(count * 512);
897 writecmd->sg.count = cpu_to_le32(1);
898 /* ->stable is not used - it did mean which type of write */
899
900 aac_build_sg(cmd, &writecmd->sg);
901 fibsize = sizeof(struct aac_write) +
902 ((le32_to_cpu(writecmd->sg.count) - 1) *
903 sizeof (struct sgentry));
904 BUG_ON (fibsize > (fib->dev->max_fib_size -
905 sizeof(struct aac_fibhdr)));
906 /*
907 * Now send the Fib to the adapter
908 */
909 return aac_fib_send(ContainerCommand,
910 fib,
911 fibsize,
912 FsaNormal,
913 0, 1,
914 (fib_callback) io_callback,
915 (void *) cmd);
916}
917
918static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd)
919{
920 struct aac_srb * srbcmd;
921 u32 flag;
922 u32 timeout;
923
924 aac_fib_init(fib);
925 switch(cmd->sc_data_direction){
926 case DMA_TO_DEVICE:
927 flag = SRB_DataOut;
928 break;
929 case DMA_BIDIRECTIONAL:
930 flag = SRB_DataIn | SRB_DataOut;
931 break;
932 case DMA_FROM_DEVICE:
933 flag = SRB_DataIn;
934 break;
935 case DMA_NONE:
936 default: /* shuts up some versions of gcc */
937 flag = SRB_NoDataXfer;
938 break;
939 }
940
941 srbcmd = (struct aac_srb*) fib_data(fib);
942 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
943 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(cmd)));
944 srbcmd->id = cpu_to_le32(scmd_id(cmd));
945 srbcmd->lun = cpu_to_le32(cmd->device->lun);
946 srbcmd->flags = cpu_to_le32(flag);
947 timeout = cmd->timeout_per_command/HZ;
948 if (timeout == 0)
949 timeout = 1;
950 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
951 srbcmd->retry_limit = 0; /* Obsolete parameter */
952 srbcmd->cdb_size = cpu_to_le32(cmd->cmd_len);
953 return srbcmd;
954}
955
956static void aac_srb_callback(void *context, struct fib * fibptr);
957
958static int aac_scsi_64(struct fib * fib, struct scsi_cmnd * cmd)
959{
960 u16 fibsize;
961 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
962
963 aac_build_sg64(cmd, (struct sgmap64*) &srbcmd->sg);
964 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
965
966 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
967 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
968 /*
969 * Build Scatter/Gather list
970 */
971 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
972 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
973 sizeof (struct sgentry64));
974 BUG_ON (fibsize > (fib->dev->max_fib_size -
975 sizeof(struct aac_fibhdr)));
976
977 /*
978 * Now send the Fib to the adapter
979 */
980 return aac_fib_send(ScsiPortCommand64, fib,
981 fibsize, FsaNormal, 0, 1,
982 (fib_callback) aac_srb_callback,
983 (void *) cmd);
984}
985
986static int aac_scsi_32(struct fib * fib, struct scsi_cmnd * cmd)
987{
988 u16 fibsize;
989 struct aac_srb * srbcmd = aac_scsi_common(fib, cmd);
990
991 aac_build_sg(cmd, (struct sgmap*)&srbcmd->sg);
992 srbcmd->count = cpu_to_le32(cmd->request_bufflen);
993
994 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
995 memcpy(srbcmd->cdb, cmd->cmnd, cmd->cmd_len);
996 /*
997 * Build Scatter/Gather list
998 */
999 fibsize = sizeof (struct aac_srb) +
1000 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
1001 sizeof (struct sgentry));
1002 BUG_ON (fibsize > (fib->dev->max_fib_size -
1003 sizeof(struct aac_fibhdr)));
1004
1005 /*
1006 * Now send the Fib to the adapter
1007 */
1008 return aac_fib_send(ScsiPortCommand, fib, fibsize, FsaNormal, 0, 1,
1009 (fib_callback) aac_srb_callback, (void *) cmd);
1010}
1011
709int aac_get_adapter_info(struct aac_dev* dev) 1012int aac_get_adapter_info(struct aac_dev* dev)
710{ 1013{
711 struct fib* fibptr; 1014 struct fib* fibptr;
@@ -874,14 +1177,27 @@ int aac_get_adapter_info(struct aac_dev* dev)
874 } 1177 }
875 } 1178 }
876 /* 1179 /*
877 * 57 scatter gather elements 1180 * Deal with configuring for the individualized limits of each packet
1181 * interface.
878 */ 1182 */
879 if (!(dev->raw_io_interface)) { 1183 dev->a_ops.adapter_scsi = (dev->dac_support)
1184 ? aac_scsi_64
1185 : aac_scsi_32;
1186 if (dev->raw_io_interface) {
1187 dev->a_ops.adapter_bounds = (dev->raw_io_64)
1188 ? aac_bounds_64
1189 : aac_bounds_32;
1190 dev->a_ops.adapter_read = aac_read_raw_io;
1191 dev->a_ops.adapter_write = aac_write_raw_io;
1192 } else {
1193 dev->a_ops.adapter_bounds = aac_bounds_32;
880 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size - 1194 dev->scsi_host_ptr->sg_tablesize = (dev->max_fib_size -
881 sizeof(struct aac_fibhdr) - 1195 sizeof(struct aac_fibhdr) -
882 sizeof(struct aac_write) + sizeof(struct sgentry)) / 1196 sizeof(struct aac_write) + sizeof(struct sgentry)) /
883 sizeof(struct sgentry); 1197 sizeof(struct sgentry);
884 if (dev->dac_support) { 1198 if (dev->dac_support) {
1199 dev->a_ops.adapter_read = aac_read_block64;
1200 dev->a_ops.adapter_write = aac_write_block64;
885 /* 1201 /*
886 * 38 scatter gather elements 1202 * 38 scatter gather elements
887 */ 1203 */
@@ -891,6 +1207,9 @@ int aac_get_adapter_info(struct aac_dev* dev)
891 sizeof(struct aac_write64) + 1207 sizeof(struct aac_write64) +
892 sizeof(struct sgentry64)) / 1208 sizeof(struct sgentry64)) /
893 sizeof(struct sgentry64); 1209 sizeof(struct sgentry64);
1210 } else {
1211 dev->a_ops.adapter_read = aac_read_block;
1212 dev->a_ops.adapter_write = aac_write_block;
894 } 1213 }
895 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT; 1214 dev->scsi_host_ptr->max_sectors = AAC_MAX_32BIT_SGBCOUNT;
896 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) { 1215 if(!(dev->adapter_info.options & AAC_OPT_NEW_COMM)) {
@@ -1004,8 +1323,6 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
1004 u64 lba; 1323 u64 lba;
1005 u32 count; 1324 u32 count;
1006 int status; 1325 int status;
1007
1008 u16 fibsize;
1009 struct aac_dev *dev; 1326 struct aac_dev *dev;
1010 struct fib * cmd_fibcontext; 1327 struct fib * cmd_fibcontext;
1011 1328
@@ -1059,23 +1376,8 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
1059 } 1376 }
1060 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n", 1377 dprintk((KERN_DEBUG "aac_read[cpu %d]: lba = %llu, t = %ld.\n",
1061 smp_processor_id(), (unsigned long long)lba, jiffies)); 1378 smp_processor_id(), (unsigned long long)lba, jiffies));
1062 if ((!(dev->raw_io_interface) || !(dev->raw_io_64)) && 1379 if (aac_adapter_bounds(dev,scsicmd,lba))
1063 (lba & 0xffffffff00000000LL)) {
1064 dprintk((KERN_DEBUG "aac_read: Illegal lba\n"));
1065 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 |
1066 SAM_STAT_CHECK_CONDITION;
1067 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1068 HARDWARE_ERROR,
1069 SENCODE_INTERNAL_TARGET_FAILURE,
1070 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1071 0, 0);
1072 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1073 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1074 ? sizeof(scsicmd->sense_buffer)
1075 : sizeof(dev->fsa_dev[cid].sense_data));
1076 scsicmd->scsi_done(scsicmd);
1077 return 0; 1380 return 0;
1078 }
1079 /* 1381 /*
1080 * Alocate and initialize a Fib 1382 * Alocate and initialize a Fib
1081 */ 1383 */
@@ -1083,85 +1385,7 @@ static int aac_read(struct scsi_cmnd * scsicmd, int cid)
1083 return -1; 1385 return -1;
1084 } 1386 }
1085 1387
1086 aac_fib_init(cmd_fibcontext); 1388 status = aac_adapter_read(cmd_fibcontext, scsicmd, lba, count);
1087
1088 if (dev->raw_io_interface) {
1089 struct aac_raw_io *readcmd;
1090 readcmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1091 readcmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1092 readcmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1093 readcmd->count = cpu_to_le32(count<<9);
1094 readcmd->cid = cpu_to_le16(cid);
1095 readcmd->flags = cpu_to_le16(1);
1096 readcmd->bpTotal = 0;
1097 readcmd->bpComplete = 0;
1098
1099 aac_build_sgraw(scsicmd, &readcmd->sg);
1100 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(readcmd->sg.count) - 1) * sizeof (struct sgentryraw));
1101 BUG_ON(fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)));
1102 /*
1103 * Now send the Fib to the adapter
1104 */
1105 status = aac_fib_send(ContainerRawIo,
1106 cmd_fibcontext,
1107 fibsize,
1108 FsaNormal,
1109 0, 1,
1110 (fib_callback) io_callback,
1111 (void *) scsicmd);
1112 } else if (dev->dac_support == 1) {
1113 struct aac_read64 *readcmd;
1114 readcmd = (struct aac_read64 *) fib_data(cmd_fibcontext);
1115 readcmd->command = cpu_to_le32(VM_CtHostRead64);
1116 readcmd->cid = cpu_to_le16(cid);
1117 readcmd->sector_count = cpu_to_le16(count);
1118 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1119 readcmd->pad = 0;
1120 readcmd->flags = 0;
1121
1122 aac_build_sg64(scsicmd, &readcmd->sg);
1123 fibsize = sizeof(struct aac_read64) +
1124 ((le32_to_cpu(readcmd->sg.count) - 1) *
1125 sizeof (struct sgentry64));
1126 BUG_ON (fibsize > (dev->max_fib_size -
1127 sizeof(struct aac_fibhdr)));
1128 /*
1129 * Now send the Fib to the adapter
1130 */
1131 status = aac_fib_send(ContainerCommand64,
1132 cmd_fibcontext,
1133 fibsize,
1134 FsaNormal,
1135 0, 1,
1136 (fib_callback) io_callback,
1137 (void *) scsicmd);
1138 } else {
1139 struct aac_read *readcmd;
1140 readcmd = (struct aac_read *) fib_data(cmd_fibcontext);
1141 readcmd->command = cpu_to_le32(VM_CtBlockRead);
1142 readcmd->cid = cpu_to_le32(cid);
1143 readcmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1144 readcmd->count = cpu_to_le32(count * 512);
1145
1146 aac_build_sg(scsicmd, &readcmd->sg);
1147 fibsize = sizeof(struct aac_read) +
1148 ((le32_to_cpu(readcmd->sg.count) - 1) *
1149 sizeof (struct sgentry));
1150 BUG_ON (fibsize > (dev->max_fib_size -
1151 sizeof(struct aac_fibhdr)));
1152 /*
1153 * Now send the Fib to the adapter
1154 */
1155 status = aac_fib_send(ContainerCommand,
1156 cmd_fibcontext,
1157 fibsize,
1158 FsaNormal,
1159 0, 1,
1160 (fib_callback) io_callback,
1161 (void *) scsicmd);
1162 }
1163
1164
1165 1389
1166 /* 1390 /*
1167 * Check that the command queued to the controller 1391 * Check that the command queued to the controller
@@ -1187,7 +1411,6 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1187 u64 lba; 1411 u64 lba;
1188 u32 count; 1412 u32 count;
1189 int status; 1413 int status;
1190 u16 fibsize;
1191 struct aac_dev *dev; 1414 struct aac_dev *dev;
1192 struct fib * cmd_fibcontext; 1415 struct fib * cmd_fibcontext;
1193 1416
@@ -1227,22 +1450,8 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1227 } 1450 }
1228 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n", 1451 dprintk((KERN_DEBUG "aac_write[cpu %d]: lba = %llu, t = %ld.\n",
1229 smp_processor_id(), (unsigned long long)lba, jiffies)); 1452 smp_processor_id(), (unsigned long long)lba, jiffies));
1230 if ((!(dev->raw_io_interface) || !(dev->raw_io_64)) 1453 if (aac_adapter_bounds(dev,scsicmd,lba))
1231 && (lba & 0xffffffff00000000LL)) {
1232 dprintk((KERN_DEBUG "aac_write: Illegal lba\n"));
1233 scsicmd->result = DID_OK << 16 | COMMAND_COMPLETE << 8 | SAM_STAT_CHECK_CONDITION;
1234 set_sense((u8 *) &dev->fsa_dev[cid].sense_data,
1235 HARDWARE_ERROR,
1236 SENCODE_INTERNAL_TARGET_FAILURE,
1237 ASENCODE_INTERNAL_TARGET_FAILURE, 0, 0,
1238 0, 0);
1239 memcpy(scsicmd->sense_buffer, &dev->fsa_dev[cid].sense_data,
1240 (sizeof(dev->fsa_dev[cid].sense_data) > sizeof(scsicmd->sense_buffer))
1241 ? sizeof(scsicmd->sense_buffer)
1242 : sizeof(dev->fsa_dev[cid].sense_data));
1243 scsicmd->scsi_done(scsicmd);
1244 return 0; 1454 return 0;
1245 }
1246 /* 1455 /*
1247 * Allocate and initialize a Fib then setup a BlockWrite command 1456 * Allocate and initialize a Fib then setup a BlockWrite command
1248 */ 1457 */
@@ -1251,85 +1460,8 @@ static int aac_write(struct scsi_cmnd * scsicmd, int cid)
1251 scsicmd->scsi_done(scsicmd); 1460 scsicmd->scsi_done(scsicmd);
1252 return 0; 1461 return 0;
1253 } 1462 }
1254 aac_fib_init(cmd_fibcontext);
1255 1463
1256 if (dev->raw_io_interface) { 1464 status = aac_adapter_write(cmd_fibcontext, scsicmd, lba, count);
1257 struct aac_raw_io *writecmd;
1258 writecmd = (struct aac_raw_io *) fib_data(cmd_fibcontext);
1259 writecmd->block[0] = cpu_to_le32((u32)(lba&0xffffffff));
1260 writecmd->block[1] = cpu_to_le32((u32)((lba&0xffffffff00000000LL)>>32));
1261 writecmd->count = cpu_to_le32(count<<9);
1262 writecmd->cid = cpu_to_le16(cid);
1263 writecmd->flags = 0;
1264 writecmd->bpTotal = 0;
1265 writecmd->bpComplete = 0;
1266
1267 aac_build_sgraw(scsicmd, &writecmd->sg);
1268 fibsize = sizeof(struct aac_raw_io) + ((le32_to_cpu(writecmd->sg.count) - 1) * sizeof (struct sgentryraw));
1269 BUG_ON(fibsize > (dev->max_fib_size - sizeof(struct aac_fibhdr)));
1270 /*
1271 * Now send the Fib to the adapter
1272 */
1273 status = aac_fib_send(ContainerRawIo,
1274 cmd_fibcontext,
1275 fibsize,
1276 FsaNormal,
1277 0, 1,
1278 (fib_callback) io_callback,
1279 (void *) scsicmd);
1280 } else if (dev->dac_support == 1) {
1281 struct aac_write64 *writecmd;
1282 writecmd = (struct aac_write64 *) fib_data(cmd_fibcontext);
1283 writecmd->command = cpu_to_le32(VM_CtHostWrite64);
1284 writecmd->cid = cpu_to_le16(cid);
1285 writecmd->sector_count = cpu_to_le16(count);
1286 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1287 writecmd->pad = 0;
1288 writecmd->flags = 0;
1289
1290 aac_build_sg64(scsicmd, &writecmd->sg);
1291 fibsize = sizeof(struct aac_write64) +
1292 ((le32_to_cpu(writecmd->sg.count) - 1) *
1293 sizeof (struct sgentry64));
1294 BUG_ON (fibsize > (dev->max_fib_size -
1295 sizeof(struct aac_fibhdr)));
1296 /*
1297 * Now send the Fib to the adapter
1298 */
1299 status = aac_fib_send(ContainerCommand64,
1300 cmd_fibcontext,
1301 fibsize,
1302 FsaNormal,
1303 0, 1,
1304 (fib_callback) io_callback,
1305 (void *) scsicmd);
1306 } else {
1307 struct aac_write *writecmd;
1308 writecmd = (struct aac_write *) fib_data(cmd_fibcontext);
1309 writecmd->command = cpu_to_le32(VM_CtBlockWrite);
1310 writecmd->cid = cpu_to_le32(cid);
1311 writecmd->block = cpu_to_le32((u32)(lba&0xffffffff));
1312 writecmd->count = cpu_to_le32(count * 512);
1313 writecmd->sg.count = cpu_to_le32(1);
1314 /* ->stable is not used - it did mean which type of write */
1315
1316 aac_build_sg(scsicmd, &writecmd->sg);
1317 fibsize = sizeof(struct aac_write) +
1318 ((le32_to_cpu(writecmd->sg.count) - 1) *
1319 sizeof (struct sgentry));
1320 BUG_ON (fibsize > (dev->max_fib_size -
1321 sizeof(struct aac_fibhdr)));
1322 /*
1323 * Now send the Fib to the adapter
1324 */
1325 status = aac_fib_send(ContainerCommand,
1326 cmd_fibcontext,
1327 fibsize,
1328 FsaNormal,
1329 0, 1,
1330 (fib_callback) io_callback,
1331 (void *) scsicmd);
1332 }
1333 1465
1334 /* 1466 /*
1335 * Check that the command queued to the controller 1467 * Check that the command queued to the controller
@@ -2099,10 +2231,6 @@ static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2099 struct fib* cmd_fibcontext; 2231 struct fib* cmd_fibcontext;
2100 struct aac_dev* dev; 2232 struct aac_dev* dev;
2101 int status; 2233 int status;
2102 struct aac_srb *srbcmd;
2103 u16 fibsize;
2104 u32 flag;
2105 u32 timeout;
2106 2234
2107 dev = (struct aac_dev *)scsicmd->device->host->hostdata; 2235 dev = (struct aac_dev *)scsicmd->device->host->hostdata;
2108 if (scmd_id(scsicmd) >= dev->maximum_num_physicals || 2236 if (scmd_id(scsicmd) >= dev->maximum_num_physicals ||
@@ -2112,88 +2240,14 @@ static int aac_send_srb_fib(struct scsi_cmnd* scsicmd)
2112 return 0; 2240 return 0;
2113 } 2241 }
2114 2242
2115 switch(scsicmd->sc_data_direction){
2116 case DMA_TO_DEVICE:
2117 flag = SRB_DataOut;
2118 break;
2119 case DMA_BIDIRECTIONAL:
2120 flag = SRB_DataIn | SRB_DataOut;
2121 break;
2122 case DMA_FROM_DEVICE:
2123 flag = SRB_DataIn;
2124 break;
2125 case DMA_NONE:
2126 default: /* shuts up some versions of gcc */
2127 flag = SRB_NoDataXfer;
2128 break;
2129 }
2130
2131
2132 /* 2243 /*
2133 * Allocate and initialize a Fib then setup a BlockWrite command 2244 * Allocate and initialize a Fib then setup a BlockWrite command
2134 */ 2245 */
2135 if (!(cmd_fibcontext = aac_fib_alloc(dev))) { 2246 if (!(cmd_fibcontext = aac_fib_alloc(dev))) {
2136 return -1; 2247 return -1;
2137 } 2248 }
2138 aac_fib_init(cmd_fibcontext); 2249 status = aac_adapter_scsi(cmd_fibcontext, scsicmd);
2139
2140 srbcmd = (struct aac_srb*) fib_data(cmd_fibcontext);
2141 srbcmd->function = cpu_to_le32(SRBF_ExecuteScsi);
2142 srbcmd->channel = cpu_to_le32(aac_logical_to_phys(scmd_channel(scsicmd)));
2143 srbcmd->id = cpu_to_le32(scmd_id(scsicmd));
2144 srbcmd->lun = cpu_to_le32(scsicmd->device->lun);
2145 srbcmd->flags = cpu_to_le32(flag);
2146 timeout = scsicmd->timeout_per_command/HZ;
2147 if(timeout == 0){
2148 timeout = 1;
2149 }
2150 srbcmd->timeout = cpu_to_le32(timeout); // timeout in seconds
2151 srbcmd->retry_limit = 0; /* Obsolete parameter */
2152 srbcmd->cdb_size = cpu_to_le32(scsicmd->cmd_len);
2153
2154 if( dev->dac_support == 1 ) {
2155 aac_build_sg64(scsicmd, (struct sgmap64*) &srbcmd->sg);
2156 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2157
2158 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2159 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2160 /*
2161 * Build Scatter/Gather list
2162 */
2163 fibsize = sizeof (struct aac_srb) - sizeof (struct sgentry) +
2164 ((le32_to_cpu(srbcmd->sg.count) & 0xff) *
2165 sizeof (struct sgentry64));
2166 BUG_ON (fibsize > (dev->max_fib_size -
2167 sizeof(struct aac_fibhdr)));
2168 2250
2169 /*
2170 * Now send the Fib to the adapter
2171 */
2172 status = aac_fib_send(ScsiPortCommand64, cmd_fibcontext,
2173 fibsize, FsaNormal, 0, 1,
2174 (fib_callback) aac_srb_callback,
2175 (void *) scsicmd);
2176 } else {
2177 aac_build_sg(scsicmd, (struct sgmap*)&srbcmd->sg);
2178 srbcmd->count = cpu_to_le32(scsicmd->request_bufflen);
2179
2180 memset(srbcmd->cdb, 0, sizeof(srbcmd->cdb));
2181 memcpy(srbcmd->cdb, scsicmd->cmnd, scsicmd->cmd_len);
2182 /*
2183 * Build Scatter/Gather list
2184 */
2185 fibsize = sizeof (struct aac_srb) +
2186 (((le32_to_cpu(srbcmd->sg.count) & 0xff) - 1) *
2187 sizeof (struct sgentry));
2188 BUG_ON (fibsize > (dev->max_fib_size -
2189 sizeof(struct aac_fibhdr)));
2190
2191 /*
2192 * Now send the Fib to the adapter
2193 */
2194 status = aac_fib_send(ScsiPortCommand, cmd_fibcontext, fibsize, FsaNormal, 0, 1,
2195 (fib_callback) aac_srb_callback, (void *) scsicmd);
2196 }
2197 /* 2251 /*
2198 * Check that the command queued to the controller 2252 * Check that the command queued to the controller
2199 */ 2253 */
diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
index 4f8b4c53d43..39ecd0d22eb 100644
--- a/drivers/scsi/aacraid/aacraid.h
+++ b/drivers/scsi/aacraid/aacraid.h
@@ -5,6 +5,7 @@
5#define _nblank(x) #x 5#define _nblank(x) #x
6#define nblank(x) _nblank(x)[0] 6#define nblank(x) _nblank(x)[0]
7 7
8#include <linux/interrupt.h>
8 9
9/*------------------------------------------------------------------------------ 10/*------------------------------------------------------------------------------
10 * D E F I N E S 11 * D E F I N E S
@@ -485,16 +486,28 @@ enum aac_log_level {
485 486
486struct aac_dev; 487struct aac_dev;
487struct fib; 488struct fib;
489struct scsi_cmnd;
488 490
489struct adapter_ops 491struct adapter_ops
490{ 492{
493 /* Low level operations */
491 void (*adapter_interrupt)(struct aac_dev *dev); 494 void (*adapter_interrupt)(struct aac_dev *dev);
492 void (*adapter_notify)(struct aac_dev *dev, u32 event); 495 void (*adapter_notify)(struct aac_dev *dev, u32 event);
493 void (*adapter_disable_int)(struct aac_dev *dev); 496 void (*adapter_disable_int)(struct aac_dev *dev);
497 void (*adapter_enable_int)(struct aac_dev *dev);
494 int (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4); 498 int (*adapter_sync_cmd)(struct aac_dev *dev, u32 command, u32 p1, u32 p2, u32 p3, u32 p4, u32 p5, u32 p6, u32 *status, u32 *r1, u32 *r2, u32 *r3, u32 *r4);
495 int (*adapter_check_health)(struct aac_dev *dev); 499 int (*adapter_check_health)(struct aac_dev *dev);
496 int (*adapter_send)(struct fib * fib); 500 /* Transport operations */
497 int (*adapter_ioremap)(struct aac_dev * dev, u32 size); 501 int (*adapter_ioremap)(struct aac_dev * dev, u32 size);
502 irqreturn_t (*adapter_intr)(int irq, void *dev_id);
503 /* Packet operations */
504 int (*adapter_deliver)(struct fib * fib);
505 int (*adapter_bounds)(struct aac_dev * dev, struct scsi_cmnd * cmd, u64 lba);
506 int (*adapter_read)(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count);
507 int (*adapter_write)(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u32 count);
508 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
509 /* Administrative operations */
510 int (*adapter_comm)(struct aac_dev * dev, int comm);
498}; 511};
499 512
500/* 513/*
@@ -1018,7 +1031,9 @@ struct aac_dev
1018 u8 nondasd_support; 1031 u8 nondasd_support;
1019 u8 dac_support; 1032 u8 dac_support;
1020 u8 raid_scsi_mode; 1033 u8 raid_scsi_mode;
1021 u8 new_comm_interface; 1034 u8 comm_interface;
1035# define AAC_COMM_PRODUCER 0
1036# define AAC_COMM_MESSAGE 1
1022 /* macro side-effects BEWARE */ 1037 /* macro side-effects BEWARE */
1023# define raw_io_interface \ 1038# define raw_io_interface \
1024 init->InitStructRevision==cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4) 1039 init->InitStructRevision==cpu_to_le32(ADAPTER_INIT_STRUCT_REVISION_4)
@@ -1036,18 +1051,36 @@ struct aac_dev
1036#define aac_adapter_disable_int(dev) \ 1051#define aac_adapter_disable_int(dev) \
1037 (dev)->a_ops.adapter_disable_int(dev) 1052 (dev)->a_ops.adapter_disable_int(dev)
1038 1053
1054#define aac_adapter_enable_int(dev) \
1055 (dev)->a_ops.adapter_enable_int(dev)
1056
1039#define aac_adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4) \ 1057#define aac_adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4) \
1040 (dev)->a_ops.adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4) 1058 (dev)->a_ops.adapter_sync_cmd(dev, command, p1, p2, p3, p4, p5, p6, status, r1, r2, r3, r4)
1041 1059
1042#define aac_adapter_check_health(dev) \ 1060#define aac_adapter_check_health(dev) \
1043 (dev)->a_ops.adapter_check_health(dev) 1061 (dev)->a_ops.adapter_check_health(dev)
1044 1062
1045#define aac_adapter_send(fib) \
1046 ((fib)->dev)->a_ops.adapter_send(fib)
1047
1048#define aac_adapter_ioremap(dev, size) \ 1063#define aac_adapter_ioremap(dev, size) \
1049 (dev)->a_ops.adapter_ioremap(dev, size) 1064 (dev)->a_ops.adapter_ioremap(dev, size)
1050 1065
1066#define aac_adapter_deliver(fib) \
1067 ((fib)->dev)->a_ops.adapter_deliver(fib)
1068
1069#define aac_adapter_bounds(dev,cmd,lba) \
1070 dev->a_ops.adapter_bounds(dev,cmd,lba)
1071
1072#define aac_adapter_read(fib,cmd,lba,count) \
1073 ((fib)->dev)->a_ops.adapter_read(fib,cmd,lba,count)
1074
1075#define aac_adapter_write(fib,cmd,lba,count) \
1076 ((fib)->dev)->a_ops.adapter_write(fib,cmd,lba,count)
1077
1078#define aac_adapter_scsi(fib,cmd) \
1079 ((fib)->dev)->a_ops.adapter_scsi(fib,cmd)
1080
1081#define aac_adapter_comm(dev,comm) \
1082 (dev)->a_ops.adapter_comm(dev, comm)
1083
1051#define FIB_CONTEXT_FLAG_TIMED_OUT (0x00000001) 1084#define FIB_CONTEXT_FLAG_TIMED_OUT (0x00000001)
1052 1085
1053/* 1086/*
@@ -1767,7 +1800,6 @@ static inline u32 cap_to_cyls(sector_t capacity, u32 divisor)
1767 return (u32)capacity; 1800 return (u32)capacity;
1768} 1801}
1769 1802
1770struct scsi_cmnd;
1771/* SCp.phase values */ 1803/* SCp.phase values */
1772#define AAC_OWNER_MIDLEVEL 0x101 1804#define AAC_OWNER_MIDLEVEL 0x101
1773#define AAC_OWNER_LOWLEVEL 0x102 1805#define AAC_OWNER_LOWLEVEL 0x102
@@ -1794,7 +1826,9 @@ int aac_dev_ioctl(struct aac_dev *dev, int cmd, void __user *arg);
1794int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg); 1826int aac_do_ioctl(struct aac_dev * dev, int cmd, void __user *arg);
1795int aac_rx_init(struct aac_dev *dev); 1827int aac_rx_init(struct aac_dev *dev);
1796int aac_rkt_init(struct aac_dev *dev); 1828int aac_rkt_init(struct aac_dev *dev);
1829int aac_nark_init(struct aac_dev *dev);
1797int aac_sa_init(struct aac_dev *dev); 1830int aac_sa_init(struct aac_dev *dev);
1831int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hw_fib, int wait, struct fib * fibptr, unsigned long *nonotify);
1798unsigned int aac_response_normal(struct aac_queue * q); 1832unsigned int aac_response_normal(struct aac_queue * q);
1799unsigned int aac_command_normal(struct aac_queue * q); 1833unsigned int aac_command_normal(struct aac_queue * q);
1800unsigned int aac_intr_normal(struct aac_dev * dev, u32 Index); 1834unsigned int aac_intr_normal(struct aac_dev * dev, u32 Index);
diff --git a/drivers/scsi/aacraid/comminit.c b/drivers/scsi/aacraid/comminit.c
index 6d305b2f854..df67ba68602 100644
--- a/drivers/scsi/aacraid/comminit.c
+++ b/drivers/scsi/aacraid/comminit.c
@@ -95,7 +95,7 @@ static int aac_alloc_comm(struct aac_dev *dev, void **commaddr, unsigned long co
95 init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES); 95 init->HostPhysMemPages = cpu_to_le32(AAC_MAX_HOSTPHYSMEMPAGES);
96 96
97 init->InitFlags = 0; 97 init->InitFlags = 0;
98 if (dev->new_comm_interface) { 98 if (dev->comm_interface == AAC_COMM_MESSAGE) {
99 init->InitFlags = cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED); 99 init->InitFlags = cpu_to_le32(INITFLAGS_NEW_COMM_SUPPORTED);
100 dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n")); 100 dprintk((KERN_WARNING"aacraid: New Comm Interface enabled\n"));
101 } 101 }
@@ -297,21 +297,23 @@ struct aac_dev *aac_init_adapter(struct aac_dev *dev)
297 - sizeof(struct aac_fibhdr) 297 - sizeof(struct aac_fibhdr)
298 - sizeof(struct aac_write) + sizeof(struct sgentry)) 298 - sizeof(struct aac_write) + sizeof(struct sgentry))
299 / sizeof(struct sgentry); 299 / sizeof(struct sgentry);
300 dev->new_comm_interface = 0; 300 dev->comm_interface = AAC_COMM_PRODUCER;
301 dev->raw_io_64 = 0; 301 dev->raw_io_64 = 0;
302 if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES, 302 if ((!aac_adapter_sync_cmd(dev, GET_ADAPTER_PROPERTIES,
303 0, 0, 0, 0, 0, 0, status+0, status+1, status+2, NULL, NULL)) && 303 0, 0, 0, 0, 0, 0, status+0, status+1, status+2, NULL, NULL)) &&
304 (status[0] == 0x00000001)) { 304 (status[0] == 0x00000001)) {
305 if (status[1] & AAC_OPT_NEW_COMM_64) 305 if (status[1] & AAC_OPT_NEW_COMM_64)
306 dev->raw_io_64 = 1; 306 dev->raw_io_64 = 1;
307 if (status[1] & AAC_OPT_NEW_COMM) 307 if (dev->a_ops.adapter_comm &&
308 dev->new_comm_interface = dev->a_ops.adapter_send != 0; 308 (status[1] & AAC_OPT_NEW_COMM))
309 if (dev->new_comm_interface && (status[2] > dev->base_size)) { 309 dev->comm_interface = AAC_COMM_MESSAGE;
310 if ((dev->comm_interface == AAC_COMM_MESSAGE) &&
311 (status[2] > dev->base_size)) {
310 aac_adapter_ioremap(dev, 0); 312 aac_adapter_ioremap(dev, 0);
311 dev->base_size = status[2]; 313 dev->base_size = status[2];
312 if (aac_adapter_ioremap(dev, status[2])) { 314 if (aac_adapter_ioremap(dev, status[2])) {
313 /* remap failed, go back ... */ 315 /* remap failed, go back ... */
314 dev->new_comm_interface = 0; 316 dev->comm_interface = AAC_COMM_PRODUCER;
315 if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) { 317 if (aac_adapter_ioremap(dev, AAC_MIN_FOOTPRINT_SIZE)) {
316 printk(KERN_WARNING 318 printk(KERN_WARNING
317 "aacraid: unable to map adapter.\n"); 319 "aacraid: unable to map adapter.\n");
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 4893a6d06a3..1b97f60652b 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -317,7 +317,7 @@ static int aac_get_entry (struct aac_dev * dev, u32 qid, struct aac_entry **entr
317 * success. 317 * success.
318 */ 318 */
319 319
320static int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hw_fib, int wait, struct fib * fibptr, unsigned long *nonotify) 320int aac_queue_get(struct aac_dev * dev, u32 * index, u32 qid, struct hw_fib * hw_fib, int wait, struct fib * fibptr, unsigned long *nonotify)
321{ 321{
322 struct aac_entry * entry = NULL; 322 struct aac_entry * entry = NULL;
323 int map = 0; 323 int map = 0;
@@ -387,7 +387,6 @@ int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size,
387{ 387{
388 struct aac_dev * dev = fibptr->dev; 388 struct aac_dev * dev = fibptr->dev;
389 struct hw_fib * hw_fib = fibptr->hw_fib; 389 struct hw_fib * hw_fib = fibptr->hw_fib;
390 struct aac_queue * q;
391 unsigned long flags = 0; 390 unsigned long flags = 0;
392 unsigned long qflags; 391 unsigned long qflags;
393 392
@@ -469,38 +468,10 @@ int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size,
469 468
470 if (!dev->queues) 469 if (!dev->queues)
471 return -EBUSY; 470 return -EBUSY;
472 q = &dev->queues->queue[AdapNormCmdQueue];
473 471
474 if(wait) 472 if(wait)
475 spin_lock_irqsave(&fibptr->event_lock, flags); 473 spin_lock_irqsave(&fibptr->event_lock, flags);
476 spin_lock_irqsave(q->lock, qflags); 474 aac_adapter_deliver(fibptr);
477 if (dev->new_comm_interface) {
478 unsigned long count = 10000000L; /* 50 seconds */
479 q->numpending++;
480 spin_unlock_irqrestore(q->lock, qflags);
481 while (aac_adapter_send(fibptr) != 0) {
482 if (--count == 0) {
483 if (wait)
484 spin_unlock_irqrestore(&fibptr->event_lock, flags);
485 spin_lock_irqsave(q->lock, qflags);
486 q->numpending--;
487 spin_unlock_irqrestore(q->lock, qflags);
488 return -ETIMEDOUT;
489 }
490 udelay(5);
491 }
492 } else {
493 u32 index;
494 unsigned long nointr = 0;
495 aac_queue_get( dev, &index, AdapNormCmdQueue, hw_fib, 1, fibptr, &nointr);
496
497 q->numpending++;
498 *(q->headers.producer) = cpu_to_le32(index + 1);
499 spin_unlock_irqrestore(q->lock, qflags);
500 dprintk((KERN_DEBUG "aac_fib_send: inserting a queue entry at index %d.\n",index));
501 if (!(nointr & aac_config.irq_mod))
502 aac_adapter_notify(dev, AdapNormCmdQueue);
503 }
504 475
505 /* 476 /*
506 * If the caller wanted us to wait for response wait now. 477 * If the caller wanted us to wait for response wait now.
@@ -520,6 +491,7 @@ int aac_fib_send(u16 command, struct fib *fibptr, unsigned long size,
520 while (down_trylock(&fibptr->event_wait)) { 491 while (down_trylock(&fibptr->event_wait)) {
521 int blink; 492 int blink;
522 if (--count == 0) { 493 if (--count == 0) {
494 struct aac_queue * q = &dev->queues->queue[AdapNormCmdQueue];
523 spin_lock_irqsave(q->lock, qflags); 495 spin_lock_irqsave(q->lock, qflags);
524 q->numpending--; 496 q->numpending--;
525 spin_unlock_irqrestore(q->lock, qflags); 497 spin_unlock_irqrestore(q->lock, qflags);
@@ -659,7 +631,7 @@ int aac_fib_adapter_complete(struct fib *fibptr, unsigned short size)
659 unsigned long qflags; 631 unsigned long qflags;
660 632
661 if (hw_fib->header.XferState == 0) { 633 if (hw_fib->header.XferState == 0) {
662 if (dev->new_comm_interface) 634 if (dev->comm_interface == AAC_COMM_MESSAGE)
663 kfree (hw_fib); 635 kfree (hw_fib);
664 return 0; 636 return 0;
665 } 637 }
@@ -667,7 +639,7 @@ int aac_fib_adapter_complete(struct fib *fibptr, unsigned short size)
667 * If we plan to do anything check the structure type first. 639 * If we plan to do anything check the structure type first.
668 */ 640 */
669 if ( hw_fib->header.StructType != FIB_MAGIC ) { 641 if ( hw_fib->header.StructType != FIB_MAGIC ) {
670 if (dev->new_comm_interface) 642 if (dev->comm_interface == AAC_COMM_MESSAGE)
671 kfree (hw_fib); 643 kfree (hw_fib);
672 return -EINVAL; 644 return -EINVAL;
673 } 645 }
@@ -679,7 +651,7 @@ int aac_fib_adapter_complete(struct fib *fibptr, unsigned short size)
679 * send the completed cdb to the adapter. 651 * send the completed cdb to the adapter.
680 */ 652 */
681 if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) { 653 if (hw_fib->header.XferState & cpu_to_le32(SentFromAdapter)) {
682 if (dev->new_comm_interface) { 654 if (dev->comm_interface == AAC_COMM_MESSAGE) {
683 kfree (hw_fib); 655 kfree (hw_fib);
684 } else { 656 } else {
685 u32 index; 657 u32 index;
diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
index d2cf875af59..0f948c2fb60 100644
--- a/drivers/scsi/aacraid/linit.c
+++ b/drivers/scsi/aacraid/linit.c
@@ -157,6 +157,7 @@ static struct pci_device_id aac_pci_tbl[] = {
157 { 0x9005, 0x0285, 0x17aa, PCI_ANY_ID, 0, 0, 58 }, /* Legend Catchall */ 157 { 0x9005, 0x0285, 0x17aa, PCI_ANY_ID, 0, 0, 58 }, /* Legend Catchall */
158 { 0x9005, 0x0285, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 59 }, /* Adaptec Catch All */ 158 { 0x9005, 0x0285, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 59 }, /* Adaptec Catch All */
159 { 0x9005, 0x0286, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 60 }, /* Adaptec Rocket Catch All */ 159 { 0x9005, 0x0286, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 60 }, /* Adaptec Rocket Catch All */
160 { 0x9005, 0x0288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 61 }, /* Adaptec NEMER/ARK Catch All */
160 { 0,} 161 { 0,}
161}; 162};
162MODULE_DEVICE_TABLE(pci, aac_pci_tbl); 163MODULE_DEVICE_TABLE(pci, aac_pci_tbl);
@@ -230,7 +231,8 @@ static struct aac_driver_ident aac_drivers[] = {
230 { aac_rx_init, "aacraid", "DELL ", "RAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Dell Catchall */ 231 { aac_rx_init, "aacraid", "DELL ", "RAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Dell Catchall */
231 { aac_rx_init, "aacraid", "Legend ", "RAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Legend Catchall */ 232 { aac_rx_init, "aacraid", "Legend ", "RAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Legend Catchall */
232 { aac_rx_init, "aacraid", "ADAPTEC ", "RAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Adaptec Catch All */ 233 { aac_rx_init, "aacraid", "ADAPTEC ", "RAID ", 2, AAC_QUIRK_31BIT | AAC_QUIRK_34SG }, /* Adaptec Catch All */
233 { aac_rkt_init, "aacraid", "ADAPTEC ", "RAID ", 2 } /* Adaptec Rocket Catch All */ 234 { aac_rkt_init, "aacraid", "ADAPTEC ", "RAID ", 2 }, /* Adaptec Rocket Catch All */
235 { aac_nark_init, "aacraid", "ADAPTEC ", "RAID ", 2 } /* Adaptec NEMER/ARK Catch All */
234}; 236};
235 237
236/** 238/**
@@ -396,11 +398,15 @@ static int aac_slave_configure(struct scsi_device *sdev)
396 sdev->skip_ms_page_3f = 1; 398 sdev->skip_ms_page_3f = 1;
397 } 399 }
398 if ((sdev->type == TYPE_DISK) && 400 if ((sdev->type == TYPE_DISK) &&
399 !expose_physicals &&
400 (sdev_channel(sdev) != CONTAINER_CHANNEL)) { 401 (sdev_channel(sdev) != CONTAINER_CHANNEL)) {
401 struct aac_dev *aac = (struct aac_dev *)sdev->host->hostdata; 402 if (expose_physicals == 0)
402 if (!aac->raid_scsi_mode || (sdev_channel(sdev) != 2)) 403 return -ENXIO;
403 sdev->no_uld_attach = 1; 404 if (expose_physicals < 0) {
405 struct aac_dev *aac =
406 (struct aac_dev *)sdev->host->hostdata;
407 if (!aac->raid_scsi_mode || (sdev_channel(sdev) != 2))
408 sdev->no_uld_attach = 1;
409 }
404 } 410 }
405 if (sdev->tagged_supported && (sdev->type == TYPE_DISK) && 411 if (sdev->tagged_supported && (sdev->type == TYPE_DISK) &&
406 (sdev_channel(sdev) == CONTAINER_CHANNEL)) { 412 (sdev_channel(sdev) == CONTAINER_CHANNEL)) {
@@ -768,7 +774,7 @@ static struct class_device_attribute *aac_attrs[] = {
768}; 774};
769 775
770 776
771static struct file_operations aac_cfg_fops = { 777static const struct file_operations aac_cfg_fops = {
772 .owner = THIS_MODULE, 778 .owner = THIS_MODULE,
773 .ioctl = aac_cfg_ioctl, 779 .ioctl = aac_cfg_ioctl,
774#ifdef CONFIG_COMPAT 780#ifdef CONFIG_COMPAT
@@ -804,7 +810,6 @@ static struct scsi_host_template aac_driver_template = {
804 .emulated = 1, 810 .emulated = 1,
805}; 811};
806 812
807
808static int __devinit aac_probe_one(struct pci_dev *pdev, 813static int __devinit aac_probe_one(struct pci_dev *pdev,
809 const struct pci_device_id *id) 814 const struct pci_device_id *id)
810{ 815{
diff --git a/drivers/scsi/aacraid/nark.c b/drivers/scsi/aacraid/nark.c
new file mode 100644
index 00000000000..c76b611b6af
--- /dev/null
+++ b/drivers/scsi/aacraid/nark.c
@@ -0,0 +1,87 @@
1/*
2 * Adaptec AAC series RAID controller driver
3 * (c) Copyright 2001 Red Hat Inc. <alan@redhat.com>
4 *
5 * based on the old aacraid driver that is..
6 * Adaptec aacraid device driver for Linux.
7 *
8 * Copyright (c) 2000 Adaptec, Inc. (aacraid@adaptec.com)
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * Module Name:
25 * nark.c
26 *
27 * Abstract: Hardware Device Interface for NEMER/ARK
28 *
29 */
30
31#include <linux/pci.h>
32#include <linux/blkdev.h>
33
34#include <scsi/scsi_host.h>
35
36#include "aacraid.h"
37
38/**
39 * aac_nark_ioremap
40 * @size: mapping resize request
41 *
42 */
43static int aac_nark_ioremap(struct aac_dev * dev, u32 size)
44{
45 if (!size) {
46 iounmap(dev->regs.rx);
47 dev->regs.rx = NULL;
48 iounmap(dev->base);
49 dev->base = NULL;
50 return 0;
51 }
52 dev->scsi_host_ptr->base = pci_resource_start(dev->pdev, 2);
53 dev->regs.rx = ioremap((u64)pci_resource_start(dev->pdev, 0) |
54 ((u64)pci_resource_start(dev->pdev, 1) << 32),
55 sizeof(struct rx_registers) - sizeof(struct rx_inbound));
56 dev->base = NULL;
57 if (dev->regs.rx == NULL)
58 return -1;
59 dev->base = ioremap(dev->scsi_host_ptr->base, size);
60 if (dev->base == NULL) {
61 iounmap(dev->regs.rx);
62 dev->regs.rx = NULL;
63 return -1;
64 }
65 dev->IndexRegs = &((struct rx_registers __iomem *)dev->base)->IndexRegs;
66 return 0;
67}
68
69/**
70 * aac_nark_init - initialize an NEMER/ARK Split Bar card
71 * @dev: device to configure
72 *
73 */
74
75int aac_nark_init(struct aac_dev * dev)
76{
77 extern int _aac_rx_init(struct aac_dev *dev);
78 extern int aac_rx_select_comm(struct aac_dev *dev, int comm);
79
80 /*
81 * Fill in the function dispatch table.
82 */
83 dev->a_ops.adapter_ioremap = aac_nark_ioremap;
84 dev->a_ops.adapter_comm = aac_rx_select_comm;
85
86 return _aac_rx_init(dev);
87}
diff --git a/drivers/scsi/aacraid/rkt.c b/drivers/scsi/aacraid/rkt.c
index 643f23b5ded..d953c3fe998 100644
--- a/drivers/scsi/aacraid/rkt.c
+++ b/drivers/scsi/aacraid/rkt.c
@@ -34,6 +34,40 @@
34 34
35#include "aacraid.h" 35#include "aacraid.h"
36 36
37#define AAC_NUM_IO_FIB_RKT (246 - AAC_NUM_MGT_FIB)
38
39/**
40 * aac_rkt_select_comm - Select communications method
41 * @dev: Adapter
42 * @comm: communications method
43 */
44
45static int aac_rkt_select_comm(struct aac_dev *dev, int comm)
46{
47 int retval;
48 extern int aac_rx_select_comm(struct aac_dev *dev, int comm);
49 retval = aac_rx_select_comm(dev, comm);
50 if (comm == AAC_COMM_MESSAGE) {
51 /*
52 * FIB Setup has already been done, but we can minimize the
53 * damage by at least ensuring the OS never issues more
54 * commands than we can handle. The Rocket adapters currently
55 * can only handle 246 commands and 8 AIFs at the same time,
56 * and in fact do notify us accordingly if we negotiate the
57 * FIB size. The problem that causes us to add this check is
58 * to ensure that we do not overdo it with the adapter when a
59 * hard coded FIB override is being utilized. This special
60 * case warrants this half baked, but convenient, check here.
61 */
62 if (dev->scsi_host_ptr->can_queue > AAC_NUM_IO_FIB_RKT) {
63 dev->init->MaxIoCommands =
64 cpu_to_le32(AAC_NUM_IO_FIB_RKT + AAC_NUM_MGT_FIB);
65 dev->scsi_host_ptr->can_queue = AAC_NUM_IO_FIB_RKT;
66 }
67 }
68 return retval;
69}
70
37/** 71/**
38 * aac_rkt_ioremap 72 * aac_rkt_ioremap
39 * @size: mapping resize request 73 * @size: mapping resize request
@@ -63,39 +97,13 @@ static int aac_rkt_ioremap(struct aac_dev * dev, u32 size)
63 97
64int aac_rkt_init(struct aac_dev *dev) 98int aac_rkt_init(struct aac_dev *dev)
65{ 99{
66 int retval;
67 extern int _aac_rx_init(struct aac_dev *dev); 100 extern int _aac_rx_init(struct aac_dev *dev);
68 extern void aac_rx_start_adapter(struct aac_dev *dev);
69 101
70 /* 102 /*
71 * Fill in the function dispatch table. 103 * Fill in the function dispatch table.
72 */ 104 */
73 dev->a_ops.adapter_ioremap = aac_rkt_ioremap; 105 dev->a_ops.adapter_ioremap = aac_rkt_ioremap;
106 dev->a_ops.adapter_comm = aac_rkt_select_comm;
74 107
75 retval = _aac_rx_init(dev); 108 return _aac_rx_init(dev);
76 if (retval)
77 return retval;
78 if (dev->new_comm_interface) {
79 /*
80 * FIB Setup has already been done, but we can minimize the
81 * damage by at least ensuring the OS never issues more
82 * commands than we can handle. The Rocket adapters currently
83 * can only handle 246 commands and 8 AIFs at the same time,
84 * and in fact do notify us accordingly if we negotiate the
85 * FIB size. The problem that causes us to add this check is
86 * to ensure that we do not overdo it with the adapter when a
87 * hard coded FIB override is being utilized. This special
88 * case warrants this half baked, but convenient, check here.
89 */
90 if (dev->scsi_host_ptr->can_queue > (246 - AAC_NUM_MGT_FIB)) {
91 dev->init->MaxIoCommands = cpu_to_le32(246);
92 dev->scsi_host_ptr->can_queue = 246 - AAC_NUM_MGT_FIB;
93 }
94 }
95 /*
96 * Tell the adapter that all is configured, and it can start
97 * accepting requests
98 */
99 aac_rx_start_adapter(dev);
100 return 0;
101} 109}
diff --git a/drivers/scsi/aacraid/rx.c b/drivers/scsi/aacraid/rx.c
index dcc8b0ea7a9..c632d9354a2 100644
--- a/drivers/scsi/aacraid/rx.c
+++ b/drivers/scsi/aacraid/rx.c
@@ -46,60 +46,60 @@
46 46
47#include "aacraid.h" 47#include "aacraid.h"
48 48
49static irqreturn_t aac_rx_intr(int irq, void *dev_id) 49static irqreturn_t aac_rx_intr_producer(int irq, void *dev_id)
50{ 50{
51 struct aac_dev *dev = dev_id; 51 struct aac_dev *dev = dev_id;
52 unsigned long bellbits;
53 u8 intstat = rx_readb(dev, MUnit.OISR);
52 54
53 dprintk((KERN_DEBUG "aac_rx_intr(%d,%p)\n", irq, dev_id)); 55 /*
54 if (dev->new_comm_interface) { 56 * Read mask and invert because drawbridge is reversed.
55 u32 Index = rx_readl(dev, MUnit.OutboundQueue); 57 * This allows us to only service interrupts that have
56 if (Index == 0xFFFFFFFFL) 58 * been enabled.
57 Index = rx_readl(dev, MUnit.OutboundQueue); 59 * Check to see if this is our interrupt. If it isn't just return
58 if (Index != 0xFFFFFFFFL) { 60 */
59 do { 61 if (intstat & ~(dev->OIMR)) {
60 if (aac_intr_normal(dev, Index)) { 62 bellbits = rx_readl(dev, OutboundDoorbellReg);
61 rx_writel(dev, MUnit.OutboundQueue, Index); 63 if (bellbits & DoorBellPrintfReady) {
62 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespReady); 64 aac_printf(dev, readl (&dev->IndexRegs->Mailbox[5]));
63 } 65 rx_writel(dev, MUnit.ODR,DoorBellPrintfReady);
64 Index = rx_readl(dev, MUnit.OutboundQueue); 66 rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
65 } while (Index != 0xFFFFFFFFL);
66 return IRQ_HANDLED;
67 } 67 }
68 } else { 68 else if (bellbits & DoorBellAdapterNormCmdReady) {
69 unsigned long bellbits; 69 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
70 u8 intstat; 70 aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
71 intstat = rx_readb(dev, MUnit.OISR); 71 }
72 /* 72 else if (bellbits & DoorBellAdapterNormRespReady) {
73 * Read mask and invert because drawbridge is reversed. 73 rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
74 * This allows us to only service interrupts that have 74 aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
75 * been enabled. 75 }
76 * Check to see if this is our interrupt. If it isn't just return 76 else if (bellbits & DoorBellAdapterNormCmdNotFull) {
77 */ 77 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
78 if (intstat & ~(dev->OIMR))
79 {
80 bellbits = rx_readl(dev, OutboundDoorbellReg);
81 if (bellbits & DoorBellPrintfReady) {
82 aac_printf(dev, readl (&dev->IndexRegs->Mailbox[5]));
83 rx_writel(dev, MUnit.ODR,DoorBellPrintfReady);
84 rx_writel(dev, InboundDoorbellReg,DoorBellPrintfDone);
85 }
86 else if (bellbits & DoorBellAdapterNormCmdReady) {
87 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdReady);
88 aac_command_normal(&dev->queues->queue[HostNormCmdQueue]);
89 }
90 else if (bellbits & DoorBellAdapterNormRespReady) {
91 rx_writel(dev, MUnit.ODR,DoorBellAdapterNormRespReady);
92 aac_response_normal(&dev->queues->queue[HostNormRespQueue]);
93 }
94 else if (bellbits & DoorBellAdapterNormCmdNotFull) {
95 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
96 }
97 else if (bellbits & DoorBellAdapterNormRespNotFull) {
98 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
99 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
100 }
101 return IRQ_HANDLED;
102 } 78 }
79 else if (bellbits & DoorBellAdapterNormRespNotFull) {
80 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormCmdNotFull);
81 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespNotFull);
82 }
83 return IRQ_HANDLED;
84 }
85 return IRQ_NONE;
86}
87
88static irqreturn_t aac_rx_intr_message(int irq, void *dev_id)
89{
90 struct aac_dev *dev = dev_id;
91 u32 Index = rx_readl(dev, MUnit.OutboundQueue);
92 if (Index == 0xFFFFFFFFL)
93 Index = rx_readl(dev, MUnit.OutboundQueue);
94 if (Index != 0xFFFFFFFFL) {
95 do {
96 if (aac_intr_normal(dev, Index)) {
97 rx_writel(dev, MUnit.OutboundQueue, Index);
98 rx_writel(dev, MUnit.ODR, DoorBellAdapterNormRespReady);
99 }
100 Index = rx_readl(dev, MUnit.OutboundQueue);
101 } while (Index != 0xFFFFFFFFL);
102 return IRQ_HANDLED;
103 } 103 }
104 return IRQ_NONE; 104 return IRQ_NONE;
105} 105}
@@ -115,6 +115,26 @@ static void aac_rx_disable_interrupt(struct aac_dev *dev)
115} 115}
116 116
117/** 117/**
118 * aac_rx_enable_interrupt_producer - Enable interrupts
119 * @dev: Adapter
120 */
121
122static void aac_rx_enable_interrupt_producer(struct aac_dev *dev)
123{
124 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
125}
126
127/**
128 * aac_rx_enable_interrupt_message - Enable interrupts
129 * @dev: Adapter
130 */
131
132static void aac_rx_enable_interrupt_message(struct aac_dev *dev)
133{
134 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
135}
136
137/**
118 * rx_sync_cmd - send a command and wait 138 * rx_sync_cmd - send a command and wait
119 * @dev: Adapter 139 * @dev: Adapter
120 * @command: Command to execute 140 * @command: Command to execute
@@ -189,10 +209,7 @@ static int rx_sync_cmd(struct aac_dev *dev, u32 command,
189 /* 209 /*
190 * Restore interrupt mask even though we timed out 210 * Restore interrupt mask even though we timed out
191 */ 211 */
192 if (dev->new_comm_interface) 212 aac_adapter_enable_int(dev);
193 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
194 else
195 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
196 return -ETIMEDOUT; 213 return -ETIMEDOUT;
197 } 214 }
198 /* 215 /*
@@ -215,10 +232,7 @@ static int rx_sync_cmd(struct aac_dev *dev, u32 command,
215 /* 232 /*
216 * Restore interrupt mask 233 * Restore interrupt mask
217 */ 234 */
218 if (dev->new_comm_interface) 235 aac_adapter_enable_int(dev);
219 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7);
220 else
221 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb);
222 return 0; 236 return 0;
223 237
224} 238}
@@ -360,35 +374,72 @@ static int aac_rx_check_health(struct aac_dev *dev)
360} 374}
361 375
362/** 376/**
363 * aac_rx_send 377 * aac_rx_deliver_producer
364 * @fib: fib to issue 378 * @fib: fib to issue
365 * 379 *
366 * Will send a fib, returning 0 if successful. 380 * Will send a fib, returning 0 if successful.
367 */ 381 */
368static int aac_rx_send(struct fib * fib) 382static int aac_rx_deliver_producer(struct fib * fib)
369{ 383{
370 u64 addr = fib->hw_fib_pa;
371 struct aac_dev *dev = fib->dev; 384 struct aac_dev *dev = fib->dev;
372 volatile void __iomem *device = dev->regs.rx; 385 struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
386 unsigned long qflags;
373 u32 Index; 387 u32 Index;
388 unsigned long nointr = 0;
374 389
375 dprintk((KERN_DEBUG "%p->aac_rx_send(%p->%llx)\n", dev, fib, addr)); 390 spin_lock_irqsave(q->lock, qflags);
376 Index = rx_readl(dev, MUnit.InboundQueue); 391 aac_queue_get( dev, &Index, AdapNormCmdQueue, fib->hw_fib, 1, fib, &nointr);
377 if (Index == 0xFFFFFFFFL) 392
393 q->numpending++;
394 *(q->headers.producer) = cpu_to_le32(Index + 1);
395 spin_unlock_irqrestore(q->lock, qflags);
396 if (!(nointr & aac_config.irq_mod))
397 aac_adapter_notify(dev, AdapNormCmdQueue);
398
399 return 0;
400}
401
402/**
403 * aac_rx_deliver_message
404 * @fib: fib to issue
405 *
406 * Will send a fib, returning 0 if successful.
407 */
408static int aac_rx_deliver_message(struct fib * fib)
409{
410 struct aac_dev *dev = fib->dev;
411 struct aac_queue *q = &dev->queues->queue[AdapNormCmdQueue];
412 unsigned long qflags;
413 u32 Index;
414 u64 addr;
415 volatile void __iomem *device;
416
417 unsigned long count = 10000000L; /* 50 seconds */
418 spin_lock_irqsave(q->lock, qflags);
419 q->numpending++;
420 spin_unlock_irqrestore(q->lock, qflags);
421 for(;;) {
378 Index = rx_readl(dev, MUnit.InboundQueue); 422 Index = rx_readl(dev, MUnit.InboundQueue);
379 dprintk((KERN_DEBUG "Index = 0x%x\n", Index)); 423 if (Index == 0xFFFFFFFFL)
380 if (Index == 0xFFFFFFFFL) 424 Index = rx_readl(dev, MUnit.InboundQueue);
381 return Index; 425 if (Index != 0xFFFFFFFFL)
426 break;
427 if (--count == 0) {
428 spin_lock_irqsave(q->lock, qflags);
429 q->numpending--;
430 spin_unlock_irqrestore(q->lock, qflags);
431 return -ETIMEDOUT;
432 }
433 udelay(5);
434 }
382 device = dev->base + Index; 435 device = dev->base + Index;
383 dprintk((KERN_DEBUG "entry = %x %x %u\n", (u32)(addr & 0xffffffff), 436 addr = fib->hw_fib_pa;
384 (u32)(addr >> 32), (u32)le16_to_cpu(fib->hw_fib->header.Size)));
385 writel((u32)(addr & 0xffffffff), device); 437 writel((u32)(addr & 0xffffffff), device);
386 device += sizeof(u32); 438 device += sizeof(u32);
387 writel((u32)(addr >> 32), device); 439 writel((u32)(addr >> 32), device);
388 device += sizeof(u32); 440 device += sizeof(u32);
389 writel(le16_to_cpu(fib->hw_fib->header.Size), device); 441 writel(le16_to_cpu(fib->hw_fib->header.Size), device);
390 rx_writel(dev, MUnit.InboundQueue, Index); 442 rx_writel(dev, MUnit.InboundQueue, Index);
391 dprintk((KERN_DEBUG "aac_rx_send - return 0\n"));
392 return 0; 443 return 0;
393} 444}
394 445
@@ -430,6 +481,31 @@ static int aac_rx_restart_adapter(struct aac_dev *dev)
430} 481}
431 482
432/** 483/**
484 * aac_rx_select_comm - Select communications method
485 * @dev: Adapter
486 * @comm: communications method
487 */
488
489int aac_rx_select_comm(struct aac_dev *dev, int comm)
490{
491 switch (comm) {
492 case AAC_COMM_PRODUCER:
493 dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_producer;
494 dev->a_ops.adapter_intr = aac_rx_intr_producer;
495 dev->a_ops.adapter_deliver = aac_rx_deliver_producer;
496 break;
497 case AAC_COMM_MESSAGE:
498 dev->a_ops.adapter_enable_int = aac_rx_enable_interrupt_message;
499 dev->a_ops.adapter_intr = aac_rx_intr_message;
500 dev->a_ops.adapter_deliver = aac_rx_deliver_message;
501 break;
502 default:
503 return 1;
504 }
505 return 0;
506}
507
508/**
433 * aac_rx_init - initialize an i960 based AAC card 509 * aac_rx_init - initialize an i960 based AAC card
434 * @dev: device to configure 510 * @dev: device to configure
435 * 511 *
@@ -489,40 +565,42 @@ int _aac_rx_init(struct aac_dev *dev)
489 } 565 }
490 msleep(1); 566 msleep(1);
491 } 567 }
492 if (request_irq(dev->scsi_host_ptr->irq, aac_rx_intr, IRQF_SHARED|IRQF_DISABLED, "aacraid", (void *)dev)<0)
493 {
494 printk(KERN_ERR "%s%d: Interrupt unavailable.\n", name, instance);
495 goto error_iounmap;
496 }
497 /* 568 /*
498 * Fill in the function dispatch table. 569 * Fill in the common function dispatch table.
499 */ 570 */
500 dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter; 571 dev->a_ops.adapter_interrupt = aac_rx_interrupt_adapter;
501 dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt; 572 dev->a_ops.adapter_disable_int = aac_rx_disable_interrupt;
502 dev->a_ops.adapter_notify = aac_rx_notify_adapter; 573 dev->a_ops.adapter_notify = aac_rx_notify_adapter;
503 dev->a_ops.adapter_sync_cmd = rx_sync_cmd; 574 dev->a_ops.adapter_sync_cmd = rx_sync_cmd;
504 dev->a_ops.adapter_check_health = aac_rx_check_health; 575 dev->a_ops.adapter_check_health = aac_rx_check_health;
505 dev->a_ops.adapter_send = aac_rx_send;
506 576
507 /* 577 /*
508 * First clear out all interrupts. Then enable the one's that we 578 * First clear out all interrupts. Then enable the one's that we
509 * can handle. 579 * can handle.
510 */ 580 */
511 rx_writeb(dev, MUnit.OIMR, 0xff); 581 aac_adapter_comm(dev, AAC_COMM_PRODUCER);
582 aac_adapter_disable_int(dev);
512 rx_writel(dev, MUnit.ODR, 0xffffffff); 583 rx_writel(dev, MUnit.ODR, 0xffffffff);
513 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xfb); 584 aac_adapter_enable_int(dev);
514 585
515 if (aac_init_adapter(dev) == NULL) 586 if (aac_init_adapter(dev) == NULL)
516 goto error_irq; 587 goto error_iounmap;
517 if (dev->new_comm_interface) 588 aac_adapter_comm(dev, dev->comm_interface);
518 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xf7); 589 if (request_irq(dev->scsi_host_ptr->irq, dev->a_ops.adapter_intr,
590 IRQF_SHARED|IRQF_DISABLED, "aacraid", dev) < 0) {
591 printk(KERN_ERR "%s%d: Interrupt unavailable.\n",
592 name, instance);
593 goto error_iounmap;
594 }
595 aac_adapter_enable_int(dev);
596 /*
597 * Tell the adapter that all is configured, and it can
598 * start accepting requests
599 */
600 aac_rx_start_adapter(dev);
519 601
520 return 0; 602 return 0;
521 603
522error_irq:
523 rx_writeb(dev, MUnit.OIMR, dev->OIMR = 0xff);
524 free_irq(dev->scsi_host_ptr->irq, (void *)dev);
525
526error_iounmap: 604error_iounmap:
527 605
528 return -1; 606 return -1;
@@ -530,20 +608,11 @@ error_iounmap:
530 608
531int aac_rx_init(struct aac_dev *dev) 609int aac_rx_init(struct aac_dev *dev)
532{ 610{
533 int retval;
534
535 /* 611 /*
536 * Fill in the function dispatch table. 612 * Fill in the function dispatch table.
537 */ 613 */
538 dev->a_ops.adapter_ioremap = aac_rx_ioremap; 614 dev->a_ops.adapter_ioremap = aac_rx_ioremap;
615 dev->a_ops.adapter_comm = aac_rx_select_comm;
539 616
540 retval = _aac_rx_init(dev); 617 return _aac_rx_init(dev);
541 if (!retval) {
542 /*
543 * Tell the adapter that all is configured, and it can
544 * start accepting requests
545 */
546 aac_rx_start_adapter(dev);
547 }
548 return retval;
549} 618}
diff --git a/drivers/scsi/aacraid/sa.c b/drivers/scsi/aacraid/sa.c
index 511b0a938fb..8535db068c2 100644
--- a/drivers/scsi/aacraid/sa.c
+++ b/drivers/scsi/aacraid/sa.c
@@ -92,6 +92,17 @@ static void aac_sa_disable_interrupt (struct aac_dev *dev)
92} 92}
93 93
94/** 94/**
95 * aac_sa_enable_interrupt - enable interrupt
96 * @dev: Which adapter to enable.
97 */
98
99static void aac_sa_enable_interrupt (struct aac_dev *dev)
100{
101 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 |
102 DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
103}
104
105/**
95 * aac_sa_notify_adapter - handle adapter notification 106 * aac_sa_notify_adapter - handle adapter notification
96 * @dev: Adapter that notification is for 107 * @dev: Adapter that notification is for
97 * @event: Event to notidy 108 * @event: Event to notidy
@@ -347,32 +358,36 @@ int aac_sa_init(struct aac_dev *dev)
347 msleep(1); 358 msleep(1);
348 } 359 }
349 360
350 if (request_irq(dev->scsi_host_ptr->irq, aac_sa_intr, IRQF_SHARED|IRQF_DISABLED, "aacraid", (void *)dev ) < 0) {
351 printk(KERN_WARNING "%s%d: Interrupt unavailable.\n", name, instance);
352 goto error_iounmap;
353 }
354
355 /* 361 /*
356 * Fill in the function dispatch table. 362 * Fill in the function dispatch table.
357 */ 363 */
358 364
359 dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter; 365 dev->a_ops.adapter_interrupt = aac_sa_interrupt_adapter;
360 dev->a_ops.adapter_disable_int = aac_sa_disable_interrupt; 366 dev->a_ops.adapter_disable_int = aac_sa_disable_interrupt;
367 dev->a_ops.adapter_enable_int = aac_sa_enable_interrupt;
361 dev->a_ops.adapter_notify = aac_sa_notify_adapter; 368 dev->a_ops.adapter_notify = aac_sa_notify_adapter;
362 dev->a_ops.adapter_sync_cmd = sa_sync_cmd; 369 dev->a_ops.adapter_sync_cmd = sa_sync_cmd;
363 dev->a_ops.adapter_check_health = aac_sa_check_health; 370 dev->a_ops.adapter_check_health = aac_sa_check_health;
371 dev->a_ops.adapter_intr = aac_sa_intr;
364 dev->a_ops.adapter_ioremap = aac_sa_ioremap; 372 dev->a_ops.adapter_ioremap = aac_sa_ioremap;
365 373
366 /* 374 /*
367 * First clear out all interrupts. Then enable the one's that 375 * First clear out all interrupts. Then enable the one's that
368 * we can handle. 376 * we can handle.
369 */ 377 */
370 sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff); 378 aac_adapter_disable_int(dev);
371 sa_writew(dev, SaDbCSR.PRICLEARIRQMASK, (PrintfReady | DOORBELL_1 | 379 aac_adapter_enable_int(dev);
372 DOORBELL_2 | DOORBELL_3 | DOORBELL_4));
373 380
374 if(aac_init_adapter(dev) == NULL) 381 if(aac_init_adapter(dev) == NULL)
375 goto error_irq; 382 goto error_irq;
383 if (request_irq(dev->scsi_host_ptr->irq, dev->a_ops.adapter_intr,
384 IRQF_SHARED|IRQF_DISABLED,
385 "aacraid", (void *)dev ) < 0) {
386 printk(KERN_WARNING "%s%d: Interrupt unavailable.\n",
387 name, instance);
388 goto error_iounmap;
389 }
390 aac_adapter_enable_int(dev);
376 391
377 /* 392 /*
378 * Tell the adapter that all is configure, and it can start 393 * Tell the adapter that all is configure, and it can start
@@ -382,7 +397,7 @@ int aac_sa_init(struct aac_dev *dev)
382 return 0; 397 return 0;
383 398
384error_irq: 399error_irq:
385 sa_writew(dev, SaDbCSR.PRISETIRQMASK, 0xffff); 400 aac_sa_disable_interrupt(dev);
386 free_irq(dev->scsi_host_ptr->irq, (void *)dev); 401 free_irq(dev->scsi_host_ptr->irq, (void *)dev);
387 402
388error_iounmap: 403error_iounmap:
diff --git a/drivers/scsi/advansys.c b/drivers/scsi/advansys.c
index 306bec355e4..9b3303b6411 100644
--- a/drivers/scsi/advansys.c
+++ b/drivers/scsi/advansys.c
@@ -4403,7 +4403,7 @@ advansys_detect(struct scsi_host_template *tpnt)
4403 ASC_DBG1(1, 4403 ASC_DBG1(1,
4404 "advansys_detect: probing I/O port 0x%x...\n", 4404 "advansys_detect: probing I/O port 0x%x...\n",
4405 iop); 4405 iop);
4406 if (check_region(iop, ASC_IOADR_GAP) != 0) { 4406 if (!request_region(iop, ASC_IOADR_GAP, "advansys")){
4407 printk( 4407 printk(
4408"AdvanSys SCSI: specified I/O Port 0x%X is busy\n", iop); 4408"AdvanSys SCSI: specified I/O Port 0x%X is busy\n", iop);
4409 /* Don't try this I/O port twice. */ 4409 /* Don't try this I/O port twice. */
@@ -4413,6 +4413,7 @@ advansys_detect(struct scsi_host_template *tpnt)
4413 printk( 4413 printk(
4414"AdvanSys SCSI: specified I/O Port 0x%X has no adapter\n", iop); 4414"AdvanSys SCSI: specified I/O Port 0x%X has no adapter\n", iop);
4415 /* Don't try this I/O port twice. */ 4415 /* Don't try this I/O port twice. */
4416 release_region(iop, ASC_IOADR_GAP);
4416 asc_ioport[ioport] = 0; 4417 asc_ioport[ioport] = 0;
4417 goto ioport_try_again; 4418 goto ioport_try_again;
4418 } else { 4419 } else {
@@ -4431,6 +4432,7 @@ advansys_detect(struct scsi_host_template *tpnt)
4431 * 'ioport' past this board. 4432 * 'ioport' past this board.
4432 */ 4433 */
4433 ioport++; 4434 ioport++;
4435 release_region(iop, ASC_IOADR_GAP);
4434 goto ioport_try_again; 4436 goto ioport_try_again;
4435 } 4437 }
4436 } 4438 }
@@ -9740,13 +9742,14 @@ AscSearchIOPortAddr11(
9740 } 9742 }
9741 for (; i < ASC_IOADR_TABLE_MAX_IX; i++) { 9743 for (; i < ASC_IOADR_TABLE_MAX_IX; i++) {
9742 iop_base = _asc_def_iop_base[i]; 9744 iop_base = _asc_def_iop_base[i];
9743 if (check_region(iop_base, ASC_IOADR_GAP) != 0) { 9745 if (!request_region(iop_base, ASC_IOADR_GAP, "advansys")){
9744 ASC_DBG1(1, 9746 ASC_DBG1(1,
9745 "AscSearchIOPortAddr11: check_region() failed I/O port 0x%x\n", 9747 "AscSearchIOPortAddr11: check_region() failed I/O port 0x%x\n",
9746 iop_base); 9748 iop_base);
9747 continue; 9749 continue;
9748 } 9750 }
9749 ASC_DBG1(1, "AscSearchIOPortAddr11: probing I/O port 0x%x\n", iop_base); 9751 ASC_DBG1(1, "AscSearchIOPortAddr11: probing I/O port 0x%x\n", iop_base);
9752 release_region(iop_base, ASC_IOADR_GAP);
9750 if (AscFindSignature(iop_base)) { 9753 if (AscFindSignature(iop_base)) {
9751 return (iop_base); 9754 return (iop_base);
9752 } 9755 }
diff --git a/drivers/scsi/aic7xxx/aic79xx.h b/drivers/scsi/aic7xxx/aic79xx.h
index 170a4344cbb..27adbb294ac 100644
--- a/drivers/scsi/aic7xxx/aic79xx.h
+++ b/drivers/scsi/aic7xxx/aic79xx.h
@@ -1337,9 +1337,6 @@ int ahd_pci_test_register_access(struct ahd_softc *);
1337/************************** SCB and SCB queue management **********************/ 1337/************************** SCB and SCB queue management **********************/
1338void ahd_qinfifo_requeue_tail(struct ahd_softc *ahd, 1338void ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
1339 struct scb *scb); 1339 struct scb *scb);
1340int ahd_match_scb(struct ahd_softc *ahd, struct scb *scb,
1341 int target, char channel, int lun,
1342 u_int tag, role_t role);
1343 1340
1344/****************************** Initialization ********************************/ 1341/****************************** Initialization ********************************/
1345struct ahd_softc *ahd_alloc(void *platform_arg, char *name); 1342struct ahd_softc *ahd_alloc(void *platform_arg, char *name);
diff --git a/drivers/scsi/aic7xxx/aic79xx_core.c b/drivers/scsi/aic7xxx/aic79xx_core.c
index 07a86a30f67..9ddc6e4a74b 100644
--- a/drivers/scsi/aic7xxx/aic79xx_core.c
+++ b/drivers/scsi/aic7xxx/aic79xx_core.c
@@ -262,6 +262,9 @@ static void ahd_update_coalescing_values(struct ahd_softc *ahd,
262 u_int mincmds); 262 u_int mincmds);
263static int ahd_verify_vpd_cksum(struct vpd_config *vpd); 263static int ahd_verify_vpd_cksum(struct vpd_config *vpd);
264static int ahd_wait_seeprom(struct ahd_softc *ahd); 264static int ahd_wait_seeprom(struct ahd_softc *ahd);
265static int ahd_match_scb(struct ahd_softc *ahd, struct scb *scb,
266 int target, char channel, int lun,
267 u_int tag, role_t role);
265 268
266/******************************** Private Inlines *****************************/ 269/******************************** Private Inlines *****************************/
267 270
@@ -7256,7 +7259,7 @@ ahd_busy_tcl(struct ahd_softc *ahd, u_int tcl, u_int scbid)
7256} 7259}
7257 7260
7258/************************** SCB and SCB queue management **********************/ 7261/************************** SCB and SCB queue management **********************/
7259int 7262static int
7260ahd_match_scb(struct ahd_softc *ahd, struct scb *scb, int target, 7263ahd_match_scb(struct ahd_softc *ahd, struct scb *scb, int target,
7261 char channel, int lun, u_int tag, role_t role) 7264 char channel, int lun, u_int tag, role_t role)
7262{ 7265{
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.c b/drivers/scsi/aic7xxx/aic79xx_osm.c
index 9bfcca5ede0..c7fe478f481 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.c
@@ -1126,15 +1126,6 @@ ahd_linux_register_host(struct ahd_softc *ahd, struct scsi_host_template *templa
1126 return 0; 1126 return 0;
1127} 1127}
1128 1128
1129uint64_t
1130ahd_linux_get_memsize(void)
1131{
1132 struct sysinfo si;
1133
1134 si_meminfo(&si);
1135 return ((uint64_t)si.totalram << PAGE_SHIFT);
1136}
1137
1138/* 1129/*
1139 * Place the SCSI bus into a known state by either resetting it, 1130 * Place the SCSI bus into a known state by either resetting it,
1140 * or forcing transfer negotiations on the next command to any 1131 * or forcing transfer negotiations on the next command to any
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm.h b/drivers/scsi/aic7xxx/aic79xx_osm.h
index 3a67fc578d7..147c83c456a 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm.h
+++ b/drivers/scsi/aic7xxx/aic79xx_osm.h
@@ -496,8 +496,6 @@ ahd_insb(struct ahd_softc * ahd, long port, uint8_t *array, int count)
496int ahd_linux_register_host(struct ahd_softc *, 496int ahd_linux_register_host(struct ahd_softc *,
497 struct scsi_host_template *); 497 struct scsi_host_template *);
498 498
499uint64_t ahd_linux_get_memsize(void);
500
501/*************************** Pretty Printing **********************************/ 499/*************************** Pretty Printing **********************************/
502struct info_str { 500struct info_str {
503 char *buffer; 501 char *buffer;
diff --git a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
index 1a3ab6aa856..c62ce41f279 100644
--- a/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_osm_pci.c
@@ -132,6 +132,7 @@ ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
132 struct ahd_pci_identity *entry; 132 struct ahd_pci_identity *entry;
133 char *name; 133 char *name;
134 int error; 134 int error;
135 struct device *dev = &pdev->dev;
135 136
136 pci = pdev; 137 pci = pdev;
137 entry = ahd_find_pci_device(pci); 138 entry = ahd_find_pci_device(pci);
@@ -161,20 +162,18 @@ ahd_linux_pci_dev_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
161 pci_set_master(pdev); 162 pci_set_master(pdev);
162 163
163 if (sizeof(dma_addr_t) > 4) { 164 if (sizeof(dma_addr_t) > 4) {
164 uint64_t memsize; 165 const u64 required_mask = dma_get_required_mask(dev);
165 const uint64_t mask_39bit = 0x7FFFFFFFFFULL;
166 166
167 memsize = ahd_linux_get_memsize(); 167 if (required_mask > DMA_39BIT_MASK &&
168 168 dma_set_mask(dev, DMA_64BIT_MASK) == 0)
169 if (memsize >= 0x8000000000ULL
170 && pci_set_dma_mask(pdev, DMA_64BIT_MASK) == 0) {
171 ahd->flags |= AHD_64BIT_ADDRESSING; 169 ahd->flags |= AHD_64BIT_ADDRESSING;
172 } else if (memsize > 0x80000000 170 else if (required_mask > DMA_32BIT_MASK &&
173 && pci_set_dma_mask(pdev, mask_39bit) == 0) { 171 dma_set_mask(dev, DMA_39BIT_MASK) == 0)
174 ahd->flags |= AHD_39BIT_ADDRESSING; 172 ahd->flags |= AHD_39BIT_ADDRESSING;
175 } 173 else
174 dma_set_mask(dev, DMA_32BIT_MASK);
176 } else { 175 } else {
177 pci_set_dma_mask(pdev, DMA_32BIT_MASK); 176 dma_set_mask(dev, DMA_32BIT_MASK);
178 } 177 }
179 ahd->dev_softc = pci; 178 ahd->dev_softc = pci;
180 error = ahd_pci_config(ahd, entry); 179 error = ahd_pci_config(ahd, entry);
diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
index 2cf7bb3123f..8d72bbae96a 100644
--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
@@ -88,7 +88,7 @@ ahd_compose_id(u_int device, u_int vendor, u_int subdevice, u_int subvendor)
88 88
89#define SUBID_9005_LEGACYCONN_FUNC(id) ((id) & 0x20) 89#define SUBID_9005_LEGACYCONN_FUNC(id) ((id) & 0x20)
90 90
91#define SUBID_9005_SEEPTYPE(id) ((id) & 0x0C0) >> 6) 91#define SUBID_9005_SEEPTYPE(id) (((id) & 0x0C0) >> 6)
92#define SUBID_9005_SEEPTYPE_NONE 0x0 92#define SUBID_9005_SEEPTYPE_NONE 0x0
93#define SUBID_9005_SEEPTYPE_4K 0x1 93#define SUBID_9005_SEEPTYPE_4K 0x1
94 94
diff --git a/drivers/scsi/aic94xx/aic94xx_dev.c b/drivers/scsi/aic94xx/aic94xx_dev.c
index 6f8901b748f..c520e5b41fb 100644
--- a/drivers/scsi/aic94xx/aic94xx_dev.c
+++ b/drivers/scsi/aic94xx/aic94xx_dev.c
@@ -37,18 +37,14 @@
37 37
38static inline int asd_get_ddb(struct asd_ha_struct *asd_ha) 38static inline int asd_get_ddb(struct asd_ha_struct *asd_ha)
39{ 39{
40 unsigned long flags;
41 int ddb, i; 40 int ddb, i;
42 41
43 spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
44 ddb = FIND_FREE_DDB(asd_ha); 42 ddb = FIND_FREE_DDB(asd_ha);
45 if (ddb >= asd_ha->hw_prof.max_ddbs) { 43 if (ddb >= asd_ha->hw_prof.max_ddbs) {
46 ddb = -ENOMEM; 44 ddb = -ENOMEM;
47 spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
48 goto out; 45 goto out;
49 } 46 }
50 SET_DDB(ddb, asd_ha); 47 SET_DDB(ddb, asd_ha);
51 spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
52 48
53 for (i = 0; i < sizeof(struct asd_ddb_ssp_smp_target_port); i+= 4) 49 for (i = 0; i < sizeof(struct asd_ddb_ssp_smp_target_port); i+= 4)
54 asd_ddbsite_write_dword(asd_ha, ddb, i, 0); 50 asd_ddbsite_write_dword(asd_ha, ddb, i, 0);
@@ -77,14 +73,10 @@ out:
77 73
78static inline void asd_free_ddb(struct asd_ha_struct *asd_ha, int ddb) 74static inline void asd_free_ddb(struct asd_ha_struct *asd_ha, int ddb)
79{ 75{
80 unsigned long flags;
81
82 if (!ddb || ddb >= 0xFFFF) 76 if (!ddb || ddb >= 0xFFFF)
83 return; 77 return;
84 asd_ddbsite_write_byte(asd_ha, ddb, DDB_TYPE, DDB_TYPE_UNUSED); 78 asd_ddbsite_write_byte(asd_ha, ddb, DDB_TYPE, DDB_TYPE_UNUSED);
85 spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
86 CLEAR_DDB(ddb, asd_ha); 79 CLEAR_DDB(ddb, asd_ha);
87 spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
88} 80}
89 81
90static inline void asd_set_ddb_type(struct domain_device *dev) 82static inline void asd_set_ddb_type(struct domain_device *dev)
@@ -320,8 +312,11 @@ out:
320 312
321int asd_dev_found(struct domain_device *dev) 313int asd_dev_found(struct domain_device *dev)
322{ 314{
315 unsigned long flags;
323 int res = 0; 316 int res = 0;
317 struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
324 318
319 spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
325 switch (dev->dev_type) { 320 switch (dev->dev_type) {
326 case SATA_PM: 321 case SATA_PM:
327 res = asd_init_sata_pm_ddb(dev); 322 res = asd_init_sata_pm_ddb(dev);
@@ -335,14 +330,18 @@ int asd_dev_found(struct domain_device *dev)
335 else 330 else
336 res = asd_init_initiator_ddb(dev); 331 res = asd_init_initiator_ddb(dev);
337 } 332 }
333 spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
334
338 return res; 335 return res;
339} 336}
340 337
341void asd_dev_gone(struct domain_device *dev) 338void asd_dev_gone(struct domain_device *dev)
342{ 339{
343 int ddb, sister_ddb; 340 int ddb, sister_ddb;
341 unsigned long flags;
344 struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha; 342 struct asd_ha_struct *asd_ha = dev->port->ha->lldd_ha;
345 343
344 spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
346 ddb = (int) (unsigned long) dev->lldd_dev; 345 ddb = (int) (unsigned long) dev->lldd_dev;
347 sister_ddb = asd_ddbsite_read_word(asd_ha, ddb, SISTER_DDB); 346 sister_ddb = asd_ddbsite_read_word(asd_ha, ddb, SISTER_DDB);
348 347
@@ -350,4 +349,5 @@ void asd_dev_gone(struct domain_device *dev)
350 asd_free_ddb(asd_ha, sister_ddb); 349 asd_free_ddb(asd_ha, sister_ddb);
351 asd_free_ddb(asd_ha, ddb); 350 asd_free_ddb(asd_ha, ddb);
352 dev->lldd_dev = NULL; 351 dev->lldd_dev = NULL;
352 spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
353} 353}
diff --git a/drivers/scsi/aic94xx/aic94xx_dump.c b/drivers/scsi/aic94xx/aic94xx_dump.c
index e6ade5996d9..6bd8e3059d2 100644
--- a/drivers/scsi/aic94xx/aic94xx_dump.c
+++ b/drivers/scsi/aic94xx/aic94xx_dump.c
@@ -556,7 +556,7 @@ static void asd_dump_lseq_state(struct asd_ha_struct *asd_ha, int lseq)
556 PRINT_LMIP_word(asd_ha, lseq, Q_TGTXFR_TAIL); 556 PRINT_LMIP_word(asd_ha, lseq, Q_TGTXFR_TAIL);
557 PRINT_LMIP_byte(asd_ha, lseq, LINK_NUMBER); 557 PRINT_LMIP_byte(asd_ha, lseq, LINK_NUMBER);
558 PRINT_LMIP_byte(asd_ha, lseq, SCRATCH_FLAGS); 558 PRINT_LMIP_byte(asd_ha, lseq, SCRATCH_FLAGS);
559 PRINT_LMIP_qword(asd_ha, lseq, CONNECTION_STATE); 559 PRINT_LMIP_dword(asd_ha, lseq, CONNECTION_STATE);
560 PRINT_LMIP_word(asd_ha, lseq, CONCTL); 560 PRINT_LMIP_word(asd_ha, lseq, CONCTL);
561 PRINT_LMIP_byte(asd_ha, lseq, CONSTAT); 561 PRINT_LMIP_byte(asd_ha, lseq, CONSTAT);
562 PRINT_LMIP_byte(asd_ha, lseq, CONNECTION_MODES); 562 PRINT_LMIP_byte(asd_ha, lseq, CONNECTION_MODES);
diff --git a/drivers/scsi/aic94xx/aic94xx_hwi.c b/drivers/scsi/aic94xx/aic94xx_hwi.c
index da94e126ca8..0cd7eed9196 100644
--- a/drivers/scsi/aic94xx/aic94xx_hwi.c
+++ b/drivers/scsi/aic94xx/aic94xx_hwi.c
@@ -1052,10 +1052,9 @@ static inline struct asd_ascb *asd_ascb_alloc(struct asd_ha_struct *asd_ha,
1052 struct asd_ascb *ascb; 1052 struct asd_ascb *ascb;
1053 unsigned long flags; 1053 unsigned long flags;
1054 1054
1055 ascb = kmem_cache_alloc(asd_ascb_cache, gfp_flags); 1055 ascb = kmem_cache_zalloc(asd_ascb_cache, gfp_flags);
1056 1056
1057 if (ascb) { 1057 if (ascb) {
1058 memset(ascb, 0, sizeof(*ascb));
1059 ascb->dma_scb.size = sizeof(struct scb); 1058 ascb->dma_scb.size = sizeof(struct scb);
1060 ascb->dma_scb.vaddr = dma_pool_alloc(asd_ha->scb_pool, 1059 ascb->dma_scb.vaddr = dma_pool_alloc(asd_ha->scb_pool,
1061 gfp_flags, 1060 gfp_flags,
diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
index fbc82b00a41..bc7744e35ad 100644
--- a/drivers/scsi/aic94xx/aic94xx_init.c
+++ b/drivers/scsi/aic94xx/aic94xx_init.c
@@ -38,7 +38,7 @@
38#include "aic94xx_seq.h" 38#include "aic94xx_seq.h"
39 39
40/* The format is "version.release.patchlevel" */ 40/* The format is "version.release.patchlevel" */
41#define ASD_DRIVER_VERSION "1.0.2" 41#define ASD_DRIVER_VERSION "1.0.3"
42 42
43static int use_msi = 0; 43static int use_msi = 0;
44module_param_named(use_msi, use_msi, int, S_IRUGO); 44module_param_named(use_msi, use_msi, int, S_IRUGO);
@@ -57,6 +57,8 @@ MODULE_PARM_DESC(collector, "\n"
57char sas_addr_str[2*SAS_ADDR_SIZE + 1] = ""; 57char sas_addr_str[2*SAS_ADDR_SIZE + 1] = "";
58 58
59static struct scsi_transport_template *aic94xx_transport_template; 59static struct scsi_transport_template *aic94xx_transport_template;
60static int asd_scan_finished(struct Scsi_Host *, unsigned long);
61static void asd_scan_start(struct Scsi_Host *);
60 62
61static struct scsi_host_template aic94xx_sht = { 63static struct scsi_host_template aic94xx_sht = {
62 .module = THIS_MODULE, 64 .module = THIS_MODULE,
@@ -66,6 +68,8 @@ static struct scsi_host_template aic94xx_sht = {
66 .target_alloc = sas_target_alloc, 68 .target_alloc = sas_target_alloc,
67 .slave_configure = sas_slave_configure, 69 .slave_configure = sas_slave_configure,
68 .slave_destroy = sas_slave_destroy, 70 .slave_destroy = sas_slave_destroy,
71 .scan_finished = asd_scan_finished,
72 .scan_start = asd_scan_start,
69 .change_queue_depth = sas_change_queue_depth, 73 .change_queue_depth = sas_change_queue_depth,
70 .change_queue_type = sas_change_queue_type, 74 .change_queue_type = sas_change_queue_type,
71 .bios_param = sas_bios_param, 75 .bios_param = sas_bios_param,
@@ -75,6 +79,8 @@ static struct scsi_host_template aic94xx_sht = {
75 .sg_tablesize = SG_ALL, 79 .sg_tablesize = SG_ALL,
76 .max_sectors = SCSI_DEFAULT_MAX_SECTORS, 80 .max_sectors = SCSI_DEFAULT_MAX_SECTORS,
77 .use_clustering = ENABLE_CLUSTERING, 81 .use_clustering = ENABLE_CLUSTERING,
82 .eh_device_reset_handler = sas_eh_device_reset_handler,
83 .eh_bus_reset_handler = sas_eh_bus_reset_handler,
78}; 84};
79 85
80static int __devinit asd_map_memio(struct asd_ha_struct *asd_ha) 86static int __devinit asd_map_memio(struct asd_ha_struct *asd_ha)
@@ -234,7 +240,7 @@ static int __devinit asd_common_setup(struct asd_ha_struct *asd_ha)
234 } 240 }
235 /* Provide some sane default values. */ 241 /* Provide some sane default values. */
236 asd_ha->hw_prof.max_scbs = 512; 242 asd_ha->hw_prof.max_scbs = 512;
237 asd_ha->hw_prof.max_ddbs = 128; 243 asd_ha->hw_prof.max_ddbs = ASD_MAX_DDBS;
238 asd_ha->hw_prof.num_phys = ASD_MAX_PHYS; 244 asd_ha->hw_prof.num_phys = ASD_MAX_PHYS;
239 /* All phys are enabled, by default. */ 245 /* All phys are enabled, by default. */
240 asd_ha->hw_prof.enabled_phys = 0xFF; 246 asd_ha->hw_prof.enabled_phys = 0xFF;
@@ -526,6 +532,7 @@ static int asd_register_sas_ha(struct asd_ha_struct *asd_ha)
526 asd_ha->sas_ha.num_phys= ASD_MAX_PHYS; 532 asd_ha->sas_ha.num_phys= ASD_MAX_PHYS;
527 533
528 asd_ha->sas_ha.lldd_queue_size = asd_ha->seq.can_queue; 534 asd_ha->sas_ha.lldd_queue_size = asd_ha->seq.can_queue;
535 asd_ha->sas_ha.lldd_max_execute_num = lldd_max_execute_num;
529 536
530 return sas_register_ha(&asd_ha->sas_ha); 537 return sas_register_ha(&asd_ha->sas_ha);
531} 538}
@@ -671,21 +678,10 @@ static int __devinit asd_pci_probe(struct pci_dev *dev,
671 if (err) 678 if (err)
672 goto Err_reg_sas; 679 goto Err_reg_sas;
673 680
674 err = asd_enable_phys(asd_ha, asd_ha->hw_prof.enabled_phys); 681 scsi_scan_host(shost);
675 if (err) {
676 asd_printk("coudln't enable phys, err:%d\n", err);
677 goto Err_en_phys;
678 }
679 ASD_DPRINTK("enabled phys\n");
680 /* give the phy enabling interrupt event time to come in (1s
681 * is empirically about all it takes) */
682 ssleep(1);
683 /* Wait for discovery to finish */
684 scsi_flush_work(asd_ha->sas_ha.core.shost);
685 682
686 return 0; 683 return 0;
687Err_en_phys: 684
688 asd_unregister_sas_ha(asd_ha);
689Err_reg_sas: 685Err_reg_sas:
690 asd_remove_dev_attrs(asd_ha); 686 asd_remove_dev_attrs(asd_ha);
691Err_dev_attrs: 687Err_dev_attrs:
@@ -778,6 +774,28 @@ static void __devexit asd_pci_remove(struct pci_dev *dev)
778 return; 774 return;
779} 775}
780 776
777static void asd_scan_start(struct Scsi_Host *shost)
778{
779 struct asd_ha_struct *asd_ha;
780 int err;
781
782 asd_ha = SHOST_TO_SAS_HA(shost)->lldd_ha;
783 err = asd_enable_phys(asd_ha, asd_ha->hw_prof.enabled_phys);
784 if (err)
785 asd_printk("Couldn't enable phys, err:%d\n", err);
786}
787
788static int asd_scan_finished(struct Scsi_Host *shost, unsigned long time)
789{
790 /* give the phy enabling interrupt event time to come in (1s
791 * is empirically about all it takes) */
792 if (time < HZ)
793 return 0;
794 /* Wait for discovery to finish */
795 scsi_flush_work(shost);
796 return 1;
797}
798
781static ssize_t asd_version_show(struct device_driver *driver, char *buf) 799static ssize_t asd_version_show(struct device_driver *driver, char *buf)
782{ 800{
783 return snprintf(buf, PAGE_SIZE, "%s\n", ASD_DRIVER_VERSION); 801 return snprintf(buf, PAGE_SIZE, "%s\n", ASD_DRIVER_VERSION);
@@ -885,6 +903,7 @@ static void __exit aic94xx_exit(void)
885 asd_remove_driver_attrs(&aic94xx_pci_driver.driver); 903 asd_remove_driver_attrs(&aic94xx_pci_driver.driver);
886 pci_unregister_driver(&aic94xx_pci_driver); 904 pci_unregister_driver(&aic94xx_pci_driver);
887 sas_release_transport(aic94xx_transport_template); 905 sas_release_transport(aic94xx_transport_template);
906 asd_release_firmware();
888 asd_destroy_global_caches(); 907 asd_destroy_global_caches();
889 asd_printk("%s version %s unloaded\n", ASD_DRIVER_DESCRIPTION, 908 asd_printk("%s version %s unloaded\n", ASD_DRIVER_DESCRIPTION,
890 ASD_DRIVER_VERSION); 909 ASD_DRIVER_VERSION);
diff --git a/drivers/scsi/aic94xx/aic94xx_reg_def.h b/drivers/scsi/aic94xx/aic94xx_reg_def.h
index a11f4e6d8bd..a43e8cdf4ee 100644
--- a/drivers/scsi/aic94xx/aic94xx_reg_def.h
+++ b/drivers/scsi/aic94xx/aic94xx_reg_def.h
@@ -2226,9 +2226,10 @@
2226#define LmSEQ_SAS_RESET_MODE(LinkNum) (LmSCRATCH(LinkNum) + 0x0074) 2226#define LmSEQ_SAS_RESET_MODE(LinkNum) (LmSCRATCH(LinkNum) + 0x0074)
2227#define LmSEQ_LINK_RESET_RETRY_COUNT(LinkNum) (LmSCRATCH(LinkNum) + 0x0075) 2227#define LmSEQ_LINK_RESET_RETRY_COUNT(LinkNum) (LmSCRATCH(LinkNum) + 0x0075)
2228#define LmSEQ_NUM_LINK_RESET_RETRIES(LinkNum) (LmSCRATCH(LinkNum) + 0x0076) 2228#define LmSEQ_NUM_LINK_RESET_RETRIES(LinkNum) (LmSCRATCH(LinkNum) + 0x0076)
2229#define LmSEQ_OOB_INT_ENABLES(LinkNum) (LmSCRATCH(LinkNum) + 0x007A) 2229#define LmSEQ_OOB_INT_ENABLES(LinkNum) (LmSCRATCH(LinkNum) + 0x0078)
2230#define LmSEQ_NOTIFY_TIMER_DOWN_COUNT(LinkNum) (LmSCRATCH(LinkNum) + 0x007A)
2230#define LmSEQ_NOTIFY_TIMER_TIMEOUT(LinkNum) (LmSCRATCH(LinkNum) + 0x007C) 2231#define LmSEQ_NOTIFY_TIMER_TIMEOUT(LinkNum) (LmSCRATCH(LinkNum) + 0x007C)
2231#define LmSEQ_NOTIFY_TIMER_DOWN_COUNT(LinkNum) (LmSCRATCH(LinkNum) + 0x007E) 2232#define LmSEQ_NOTIFY_TIMER_INITIAL_COUNT(LinkNum) (LmSCRATCH(LinkNum) + 0x007E)
2232 2233
2233/* Mode dependent scratch page 1, mode 0 and mode 1 */ 2234/* Mode dependent scratch page 1, mode 0 and mode 1 */
2234#define LmSEQ_SG_LIST_PTR_ADDR0(LinkNum) (LmSCRATCH(LinkNum) + 0x0020) 2235#define LmSEQ_SG_LIST_PTR_ADDR0(LinkNum) (LmSCRATCH(LinkNum) + 0x0020)
diff --git a/drivers/scsi/aic94xx/aic94xx_sas.h b/drivers/scsi/aic94xx/aic94xx_sas.h
index 9050e93bfd5..fa7c5290257 100644
--- a/drivers/scsi/aic94xx/aic94xx_sas.h
+++ b/drivers/scsi/aic94xx/aic94xx_sas.h
@@ -34,6 +34,7 @@
34 * domain that this sequencer can maintain low-level connections for 34 * domain that this sequencer can maintain low-level connections for
35 * us. They are be 64 bytes. 35 * us. They are be 64 bytes.
36 */ 36 */
37#define ASD_MAX_DDBS 128
37 38
38struct asd_ddb_ssp_smp_target_port { 39struct asd_ddb_ssp_smp_target_port {
39 u8 conn_type; /* byte 0 */ 40 u8 conn_type; /* byte 0 */
diff --git a/drivers/scsi/aic94xx/aic94xx_scb.c b/drivers/scsi/aic94xx/aic94xx_scb.c
index 75ed6b0569d..8f43ff772f2 100644
--- a/drivers/scsi/aic94xx/aic94xx_scb.c
+++ b/drivers/scsi/aic94xx/aic94xx_scb.c
@@ -413,40 +413,6 @@ void asd_invalidate_edb(struct asd_ascb *ascb, int edb_id)
413 } 413 }
414} 414}
415 415
416/* hard reset a phy later */
417static void do_phy_reset_later(struct work_struct *work)
418{
419 struct sas_phy *sas_phy =
420 container_of(work, struct sas_phy, reset_work);
421 int error;
422
423 ASD_DPRINTK("%s: About to hard reset phy %d\n", __FUNCTION__,
424 sas_phy->identify.phy_identifier);
425 /* Reset device port */
426 error = sas_phy_reset(sas_phy, 1);
427 if (error)
428 ASD_DPRINTK("%s: Hard reset of phy %d failed (%d).\n",
429 __FUNCTION__, sas_phy->identify.phy_identifier, error);
430}
431
432static void phy_reset_later(struct sas_phy *sas_phy, struct Scsi_Host *shost)
433{
434 INIT_WORK(&sas_phy->reset_work, do_phy_reset_later);
435 queue_work(shost->work_q, &sas_phy->reset_work);
436}
437
438/* start up the ABORT TASK tmf... */
439static void task_kill_later(struct asd_ascb *ascb)
440{
441 struct asd_ha_struct *asd_ha = ascb->ha;
442 struct sas_ha_struct *sas_ha = &asd_ha->sas_ha;
443 struct Scsi_Host *shost = sas_ha->core.shost;
444 struct sas_task *task = ascb->uldd_task;
445
446 INIT_WORK(&task->abort_work, sas_task_abort);
447 queue_work(shost->work_q, &task->abort_work);
448}
449
450static void escb_tasklet_complete(struct asd_ascb *ascb, 416static void escb_tasklet_complete(struct asd_ascb *ascb,
451 struct done_list_struct *dl) 417 struct done_list_struct *dl)
452{ 418{
@@ -479,26 +445,55 @@ static void escb_tasklet_complete(struct asd_ascb *ascb,
479 case REQ_TASK_ABORT: { 445 case REQ_TASK_ABORT: {
480 struct asd_ascb *a, *b; 446 struct asd_ascb *a, *b;
481 u16 tc_abort; 447 u16 tc_abort;
448 struct domain_device *failed_dev = NULL;
449
450 ASD_DPRINTK("%s: REQ_TASK_ABORT, reason=0x%X\n",
451 __FUNCTION__, dl->status_block[3]);
482 452
453 /*
454 * Find the task that caused the abort and abort it first.
455 * The sequencer won't put anything on the done list until
456 * that happens.
457 */
483 tc_abort = *((u16*)(&dl->status_block[1])); 458 tc_abort = *((u16*)(&dl->status_block[1]));
484 tc_abort = le16_to_cpu(tc_abort); 459 tc_abort = le16_to_cpu(tc_abort);
485 460
486 ASD_DPRINTK("%s: REQ_TASK_ABORT, reason=0x%X\n", 461 list_for_each_entry_safe(a, b, &asd_ha->seq.pend_q, list) {
487 __FUNCTION__, dl->status_block[3]); 462 struct sas_task *task = ascb->uldd_task;
488 463
489 /* Find the pending task and abort it. */ 464 if (task && a->tc_index == tc_abort) {
490 list_for_each_entry_safe(a, b, &asd_ha->seq.pend_q, list) 465 failed_dev = task->dev;
491 if (a->tc_index == tc_abort) { 466 sas_task_abort(task);
492 task_kill_later(a);
493 break; 467 break;
494 } 468 }
469 }
470
471 if (!failed_dev) {
472 ASD_DPRINTK("%s: Can't find task (tc=%d) to abort!\n",
473 __FUNCTION__, tc_abort);
474 goto out;
475 }
476
477 /*
478 * Now abort everything else for that device (hba?) so
479 * that the EH will wake up and do something.
480 */
481 list_for_each_entry_safe(a, b, &asd_ha->seq.pend_q, list) {
482 struct sas_task *task = ascb->uldd_task;
483
484 if (task &&
485 task->dev == failed_dev &&
486 a->tc_index != tc_abort)
487 sas_task_abort(task);
488 }
489
495 goto out; 490 goto out;
496 } 491 }
497 case REQ_DEVICE_RESET: { 492 case REQ_DEVICE_RESET: {
498 struct Scsi_Host *shost = sas_ha->core.shost;
499 struct sas_phy *dev_phy;
500 struct asd_ascb *a; 493 struct asd_ascb *a;
501 u16 conn_handle; 494 u16 conn_handle;
495 unsigned long flags;
496 struct sas_task *last_dev_task = NULL;
502 497
503 conn_handle = *((u16*)(&dl->status_block[1])); 498 conn_handle = *((u16*)(&dl->status_block[1]));
504 conn_handle = le16_to_cpu(conn_handle); 499 conn_handle = le16_to_cpu(conn_handle);
@@ -506,32 +501,47 @@ static void escb_tasklet_complete(struct asd_ascb *ascb,
506 ASD_DPRINTK("%s: REQ_DEVICE_RESET, reason=0x%X\n", __FUNCTION__, 501 ASD_DPRINTK("%s: REQ_DEVICE_RESET, reason=0x%X\n", __FUNCTION__,
507 dl->status_block[3]); 502 dl->status_block[3]);
508 503
509 /* Kill all pending tasks and reset the device */ 504 /* Find the last pending task for the device... */
510 dev_phy = NULL;
511 list_for_each_entry(a, &asd_ha->seq.pend_q, list) { 505 list_for_each_entry(a, &asd_ha->seq.pend_q, list) {
512 struct sas_task *task;
513 struct domain_device *dev;
514 u16 x; 506 u16 x;
507 struct domain_device *dev;
508 struct sas_task *task = a->uldd_task;
515 509
516 task = a->uldd_task;
517 if (!task) 510 if (!task)
518 continue; 511 continue;
519 dev = task->dev; 512 dev = task->dev;
520 513
521 x = (unsigned long)dev->lldd_dev; 514 x = (unsigned long)dev->lldd_dev;
522 if (x == conn_handle) { 515 if (x == conn_handle)
523 dev_phy = dev->port->phy; 516 last_dev_task = task;
524 task_kill_later(a);
525 }
526 } 517 }
527 518
528 /* Reset device port */ 519 if (!last_dev_task) {
529 if (!dev_phy) { 520 ASD_DPRINTK("%s: Device reset for idle device %d?\n",
530 ASD_DPRINTK("%s: No pending commands; can't reset.\n", 521 __FUNCTION__, conn_handle);
531 __FUNCTION__);
532 goto out; 522 goto out;
533 } 523 }
534 phy_reset_later(dev_phy, shost); 524
525 /* ...and set the reset flag */
526 spin_lock_irqsave(&last_dev_task->task_state_lock, flags);
527 last_dev_task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
528 spin_unlock_irqrestore(&last_dev_task->task_state_lock, flags);
529
530 /* Kill all pending tasks for the device */
531 list_for_each_entry(a, &asd_ha->seq.pend_q, list) {
532 u16 x;
533 struct domain_device *dev;
534 struct sas_task *task = a->uldd_task;
535
536 if (!task)
537 continue;
538 dev = task->dev;
539
540 x = (unsigned long)dev->lldd_dev;
541 if (x == conn_handle)
542 sas_task_abort(task);
543 }
544
535 goto out; 545 goto out;
536 } 546 }
537 case SIGNAL_NCQ_ERROR: 547 case SIGNAL_NCQ_ERROR:
diff --git a/drivers/scsi/aic94xx/aic94xx_sds.c b/drivers/scsi/aic94xx/aic94xx_sds.c
index e5a0ec37e95..5b0932f6147 100644
--- a/drivers/scsi/aic94xx/aic94xx_sds.c
+++ b/drivers/scsi/aic94xx/aic94xx_sds.c
@@ -427,7 +427,7 @@ struct asd_manuf_sec {
427 427
428struct asd_manuf_phy_desc { 428struct asd_manuf_phy_desc {
429 u8 state; /* low 4 bits */ 429 u8 state; /* low 4 bits */
430#define MS_PHY_STATE_ENABLEABLE 0 430#define MS_PHY_STATE_ENABLED 0
431#define MS_PHY_STATE_REPORTED 1 431#define MS_PHY_STATE_REPORTED 1
432#define MS_PHY_STATE_HIDDEN 2 432#define MS_PHY_STATE_HIDDEN 2
433 u8 phy_id; 433 u8 phy_id;
@@ -756,11 +756,11 @@ static void *asd_find_ll_by_id(void * const start, const u8 id0, const u8 id1)
756 * 756 *
757 * HIDDEN phys do not count in the total count. REPORTED phys cannot 757 * HIDDEN phys do not count in the total count. REPORTED phys cannot
758 * be enabled but are reported and counted towards the total. 758 * be enabled but are reported and counted towards the total.
759 * ENEBLEABLE phys are enabled by default and count towards the total. 759 * ENABLED phys are enabled by default and count towards the total.
760 * The absolute total phy number is ASD_MAX_PHYS. hw_prof->num_phys 760 * The absolute total phy number is ASD_MAX_PHYS. hw_prof->num_phys
761 * merely specifies the number of phys the host adapter decided to 761 * merely specifies the number of phys the host adapter decided to
762 * report. E.g., it is possible for phys 0, 1 and 2 to be HIDDEN, 762 * report. E.g., it is possible for phys 0, 1 and 2 to be HIDDEN,
763 * phys 3, 4 and 5 to be REPORTED and phys 6 and 7 to be ENEBLEABLE. 763 * phys 3, 4 and 5 to be REPORTED and phys 6 and 7 to be ENABLED.
764 * In this case ASD_MAX_PHYS is 8, hw_prof->num_phys is 5, and only 2 764 * In this case ASD_MAX_PHYS is 8, hw_prof->num_phys is 5, and only 2
765 * are actually enabled (enabled by default, max number of phys 765 * are actually enabled (enabled by default, max number of phys
766 * enableable in this case). 766 * enableable in this case).
@@ -816,8 +816,8 @@ static int asd_ms_get_phy_params(struct asd_ha_struct *asd_ha,
816 asd_ha->hw_prof.enabled_phys &= ~(1 << i); 816 asd_ha->hw_prof.enabled_phys &= ~(1 << i);
817 rep_phys++; 817 rep_phys++;
818 continue; 818 continue;
819 case MS_PHY_STATE_ENABLEABLE: 819 case MS_PHY_STATE_ENABLED:
820 ASD_DPRINTK("ms: phy%d: ENEBLEABLE\n", i); 820 ASD_DPRINTK("ms: phy%d: ENABLED\n", i);
821 asd_ha->hw_prof.enabled_phys |= (1 << i); 821 asd_ha->hw_prof.enabled_phys |= (1 << i);
822 en_phys++; 822 en_phys++;
823 break; 823 break;
diff --git a/drivers/scsi/aic94xx/aic94xx_seq.c b/drivers/scsi/aic94xx/aic94xx_seq.c
index 845112539d0..eae7a247bec 100644
--- a/drivers/scsi/aic94xx/aic94xx_seq.c
+++ b/drivers/scsi/aic94xx/aic94xx_seq.c
@@ -810,6 +810,8 @@ static void asd_init_lseq_mdp(struct asd_ha_struct *asd_ha, int lseq)
810 /* No delay for the first NOTIFY to be sent to the attached target. */ 810 /* No delay for the first NOTIFY to be sent to the attached target. */
811 asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_DOWN_COUNT(lseq), 811 asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_DOWN_COUNT(lseq),
812 ASD_NOTIFY_DOWN_COUNT); 812 ASD_NOTIFY_DOWN_COUNT);
813 asd_write_reg_word(asd_ha, LmSEQ_NOTIFY_TIMER_INITIAL_COUNT(lseq),
814 ASD_NOTIFY_DOWN_COUNT);
813 815
814 /* LSEQ Mode dependent, mode 0 and 1, page 1 setup. */ 816 /* LSEQ Mode dependent, mode 0 and 1, page 1 setup. */
815 for (i = 0; i < 2; i++) { 817 for (i = 0; i < 2; i++) {
@@ -907,6 +909,16 @@ static void asd_init_scb_sites(struct asd_ha_struct *asd_ha)
907 for (i = 0; i < ASD_SCB_SIZE; i += 4) 909 for (i = 0; i < ASD_SCB_SIZE; i += 4)
908 asd_scbsite_write_dword(asd_ha, site_no, i, 0); 910 asd_scbsite_write_dword(asd_ha, site_no, i, 0);
909 911
912 /* Initialize SCB Site Opcode field to invalid. */
913 asd_scbsite_write_byte(asd_ha, site_no,
914 offsetof(struct scb_header, opcode),
915 0xFF);
916
917 /* Initialize SCB Site Flags field to mean a response
918 * frame has been received. This means inadvertent
919 * frames received to be dropped. */
920 asd_scbsite_write_byte(asd_ha, site_no, 0x49, 0x01);
921
910 /* Workaround needed by SEQ to fix a SATA issue is to exclude 922 /* Workaround needed by SEQ to fix a SATA issue is to exclude
911 * certain SCB sites from the free list. */ 923 * certain SCB sites from the free list. */
912 if (!SCB_SITE_VALID(site_no)) 924 if (!SCB_SITE_VALID(site_no))
@@ -922,16 +934,6 @@ static void asd_init_scb_sites(struct asd_ha_struct *asd_ha)
922 /* Q_NEXT field of the last SCB is invalidated. */ 934 /* Q_NEXT field of the last SCB is invalidated. */
923 asd_scbsite_write_word(asd_ha, site_no, 0, first_scb_site_no); 935 asd_scbsite_write_word(asd_ha, site_no, 0, first_scb_site_no);
924 936
925 /* Initialize SCB Site Opcode field to invalid. */
926 asd_scbsite_write_byte(asd_ha, site_no,
927 offsetof(struct scb_header, opcode),
928 0xFF);
929
930 /* Initialize SCB Site Flags field to mean a response
931 * frame has been received. This means inadvertent
932 * frames received to be dropped. */
933 asd_scbsite_write_byte(asd_ha, site_no, 0x49, 0x01);
934
935 first_scb_site_no = site_no; 937 first_scb_site_no = site_no;
936 max_scbs++; 938 max_scbs++;
937 } 939 }
@@ -1173,6 +1175,16 @@ static void asd_init_ddb_0(struct asd_ha_struct *asd_ha)
1173 set_bit(0, asd_ha->hw_prof.ddb_bitmap); 1175 set_bit(0, asd_ha->hw_prof.ddb_bitmap);
1174} 1176}
1175 1177
1178static void asd_seq_init_ddb_sites(struct asd_ha_struct *asd_ha)
1179{
1180 unsigned int i;
1181 unsigned int ddb_site;
1182
1183 for (ddb_site = 0 ; ddb_site < ASD_MAX_DDBS; ddb_site++)
1184 for (i = 0; i < sizeof(struct asd_ddb_ssp_smp_target_port); i+= 4)
1185 asd_ddbsite_write_dword(asd_ha, ddb_site, i, 0);
1186}
1187
1176/** 1188/**
1177 * asd_seq_setup_seqs -- setup and initialize central and link sequencers 1189 * asd_seq_setup_seqs -- setup and initialize central and link sequencers
1178 * @asd_ha: pointer to host adapter structure 1190 * @asd_ha: pointer to host adapter structure
@@ -1182,6 +1194,9 @@ static void asd_seq_setup_seqs(struct asd_ha_struct *asd_ha)
1182 int lseq; 1194 int lseq;
1183 u8 lseq_mask; 1195 u8 lseq_mask;
1184 1196
1197 /* Initialize DDB sites */
1198 asd_seq_init_ddb_sites(asd_ha);
1199
1185 /* Initialize SCB sites. Done first to compute some values which 1200 /* Initialize SCB sites. Done first to compute some values which
1186 * the rest of the init code depends on. */ 1201 * the rest of the init code depends on. */
1187 asd_init_scb_sites(asd_ha); 1202 asd_init_scb_sites(asd_ha);
@@ -1232,6 +1247,13 @@ static int asd_seq_start_lseq(struct asd_ha_struct *asd_ha, int lseq)
1232 return asd_seq_unpause_lseq(asd_ha, lseq); 1247 return asd_seq_unpause_lseq(asd_ha, lseq);
1233} 1248}
1234 1249
1250int asd_release_firmware(void)
1251{
1252 if (sequencer_fw)
1253 release_firmware(sequencer_fw);
1254 return 0;
1255}
1256
1235static int asd_request_firmware(struct asd_ha_struct *asd_ha) 1257static int asd_request_firmware(struct asd_ha_struct *asd_ha)
1236{ 1258{
1237 int err, i; 1259 int err, i;
@@ -1375,7 +1397,9 @@ void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
1375 u8 phy_is_up; 1397 u8 phy_is_up;
1376 u8 mask; 1398 u8 mask;
1377 int i, err; 1399 int i, err;
1400 unsigned long flags;
1378 1401
1402 spin_lock_irqsave(&asd_ha->hw_prof.ddb_lock, flags);
1379 for_each_phy(phy_mask, mask, i) 1403 for_each_phy(phy_mask, mask, i)
1380 asd_ddbsite_write_byte(asd_ha, 0, 1404 asd_ddbsite_write_byte(asd_ha, 0,
1381 offsetof(struct asd_ddb_seq_shared, 1405 offsetof(struct asd_ddb_seq_shared,
@@ -1395,6 +1419,7 @@ void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy)
1395 break; 1419 break;
1396 } 1420 }
1397 } 1421 }
1422 spin_unlock_irqrestore(&asd_ha->hw_prof.ddb_lock, flags);
1398 1423
1399 if (err) 1424 if (err)
1400 asd_printk("couldn't update DDB 0:error:%d\n", err); 1425 asd_printk("couldn't update DDB 0:error:%d\n", err);
diff --git a/drivers/scsi/aic94xx/aic94xx_seq.h b/drivers/scsi/aic94xx/aic94xx_seq.h
index 9e715e5496a..9437ff0ae3a 100644
--- a/drivers/scsi/aic94xx/aic94xx_seq.h
+++ b/drivers/scsi/aic94xx/aic94xx_seq.h
@@ -63,6 +63,7 @@ int asd_pause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask);
63int asd_unpause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask); 63int asd_unpause_lseq(struct asd_ha_struct *asd_ha, u8 lseq_mask);
64int asd_init_seqs(struct asd_ha_struct *asd_ha); 64int asd_init_seqs(struct asd_ha_struct *asd_ha);
65int asd_start_seqs(struct asd_ha_struct *asd_ha); 65int asd_start_seqs(struct asd_ha_struct *asd_ha);
66int asd_release_firmware(void);
66 67
67void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy); 68void asd_update_port_links(struct asd_ha_struct *asd_ha, struct asd_phy *phy);
68#endif 69#endif
diff --git a/drivers/scsi/aic94xx/aic94xx_task.c b/drivers/scsi/aic94xx/aic94xx_task.c
index d202ed5a670..e2ad5bed940 100644
--- a/drivers/scsi/aic94xx/aic94xx_task.c
+++ b/drivers/scsi/aic94xx/aic94xx_task.c
@@ -349,6 +349,7 @@ Again:
349 349
350 spin_lock_irqsave(&task->task_state_lock, flags); 350 spin_lock_irqsave(&task->task_state_lock, flags);
351 task->task_state_flags &= ~SAS_TASK_STATE_PENDING; 351 task->task_state_flags &= ~SAS_TASK_STATE_PENDING;
352 task->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
352 task->task_state_flags |= SAS_TASK_STATE_DONE; 353 task->task_state_flags |= SAS_TASK_STATE_DONE;
353 if (unlikely((task->task_state_flags & SAS_TASK_STATE_ABORTED))) { 354 if (unlikely((task->task_state_flags & SAS_TASK_STATE_ABORTED))) {
354 spin_unlock_irqrestore(&task->task_state_lock, flags); 355 spin_unlock_irqrestore(&task->task_state_lock, flags);
@@ -557,6 +558,7 @@ int asd_execute_task(struct sas_task *task, const int num,
557 struct sas_task *t = task; 558 struct sas_task *t = task;
558 struct asd_ascb *ascb = NULL, *a; 559 struct asd_ascb *ascb = NULL, *a;
559 struct asd_ha_struct *asd_ha = task->dev->port->ha->lldd_ha; 560 struct asd_ha_struct *asd_ha = task->dev->port->ha->lldd_ha;
561 unsigned long flags;
560 562
561 res = asd_can_queue(asd_ha, num); 563 res = asd_can_queue(asd_ha, num);
562 if (res) 564 if (res)
@@ -599,6 +601,10 @@ int asd_execute_task(struct sas_task *task, const int num,
599 } 601 }
600 if (res) 602 if (res)
601 goto out_err_unmap; 603 goto out_err_unmap;
604
605 spin_lock_irqsave(&t->task_state_lock, flags);
606 t->task_state_flags |= SAS_TASK_AT_INITIATOR;
607 spin_unlock_irqrestore(&t->task_state_lock, flags);
602 } 608 }
603 list_del_init(&alist); 609 list_del_init(&alist);
604 610
@@ -617,6 +623,9 @@ out_err_unmap:
617 if (a == b) 623 if (a == b)
618 break; 624 break;
619 t = a->uldd_task; 625 t = a->uldd_task;
626 spin_lock_irqsave(&t->task_state_lock, flags);
627 t->task_state_flags &= ~SAS_TASK_AT_INITIATOR;
628 spin_unlock_irqrestore(&t->task_state_lock, flags);
620 switch (t->task_proto) { 629 switch (t->task_proto) {
621 case SATA_PROTO: 630 case SATA_PROTO:
622 case SAS_PROTO_STP: 631 case SAS_PROTO_STP:
diff --git a/drivers/scsi/aic94xx/aic94xx_tmf.c b/drivers/scsi/aic94xx/aic94xx_tmf.c
index 61234384503..9a14a6d9727 100644
--- a/drivers/scsi/aic94xx/aic94xx_tmf.c
+++ b/drivers/scsi/aic94xx/aic94xx_tmf.c
@@ -566,9 +566,7 @@ static int asd_initiate_ssp_tmf(struct domain_device *dev, u8 *lun,
566 res = TMF_RESP_FUNC_ESUPP; 566 res = TMF_RESP_FUNC_ESUPP;
567 break; 567 break;
568 default: 568 default:
569 ASD_DPRINTK("%s: converting result 0x%x to TMF_RESP_FUNC_FAILED\n", 569 /* Allow TMF response codes to propagate upwards */
570 __FUNCTION__, res);
571 res = TMF_RESP_FUNC_FAILED;
572 break; 570 break;
573 } 571 }
574out_err: 572out_err:
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index f6caa430776..d02759f1346 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -129,7 +129,7 @@ static struct scsi_driver ch_template =
129 }, 129 },
130}; 130};
131 131
132static struct file_operations changer_fops = 132static const struct file_operations changer_fops =
133{ 133{
134 .owner = THIS_MODULE, 134 .owner = THIS_MODULE,
135 .open = ch_open, 135 .open = ch_open,
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 365db537a28..cd36e81b2d9 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -116,7 +116,7 @@ static int sys_tbl_len = 0;
116static adpt_hba* hba_chain = NULL; 116static adpt_hba* hba_chain = NULL;
117static int hba_count = 0; 117static int hba_count = 0;
118 118
119static struct file_operations adpt_fops = { 119static const struct file_operations adpt_fops = {
120 .ioctl = adpt_ioctl, 120 .ioctl = adpt_ioctl,
121 .open = adpt_open, 121 .open = adpt_open,
122 .release = adpt_close 122 .release = adpt_close
diff --git a/drivers/scsi/gdth.c b/drivers/scsi/gdth.c
index 4c698a71f66..a1992928e67 100644
--- a/drivers/scsi/gdth.c
+++ b/drivers/scsi/gdth.c
@@ -687,7 +687,7 @@ MODULE_AUTHOR("Achim Leubner");
687MODULE_LICENSE("GPL"); 687MODULE_LICENSE("GPL");
688 688
689/* ioctl interface */ 689/* ioctl interface */
690static struct file_operations gdth_fops = { 690static const struct file_operations gdth_fops = {
691 .ioctl = gdth_ioctl, 691 .ioctl = gdth_ioctl,
692 .open = gdth_open, 692 .open = gdth_open,
693 .release = gdth_close, 693 .release = gdth_close,
diff --git a/drivers/scsi/ipr.c b/drivers/scsi/ipr.c
index 821386c7b57..95045e33710 100644
--- a/drivers/scsi/ipr.c
+++ b/drivers/scsi/ipr.c
@@ -595,10 +595,8 @@ static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
595{ 595{
596 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX); 596 int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
597 597
598 if (pcix_cmd_reg == 0) { 598 if (pcix_cmd_reg == 0)
599 dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n"); 599 return 0;
600 return -EIO;
601 }
602 600
603 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD, 601 if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
604 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) { 602 &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
@@ -627,10 +625,6 @@ static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
627 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n"); 625 dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
628 return -EIO; 626 return -EIO;
629 } 627 }
630 } else {
631 dev_err(&ioa_cfg->pdev->dev,
632 "Failed to setup PCI-X command register\n");
633 return -EIO;
634 } 628 }
635 629
636 return 0; 630 return 0;
@@ -6314,7 +6308,6 @@ static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
6314 int rc; 6308 int rc;
6315 6309
6316 ENTER; 6310 ENTER;
6317 pci_unblock_user_cfg_access(ioa_cfg->pdev);
6318 rc = pci_restore_state(ioa_cfg->pdev); 6311 rc = pci_restore_state(ioa_cfg->pdev);
6319 6312
6320 if (rc != PCIBIOS_SUCCESSFUL) { 6313 if (rc != PCIBIOS_SUCCESSFUL) {
@@ -6355,6 +6348,24 @@ static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
6355} 6348}
6356 6349
6357/** 6350/**
6351 * ipr_reset_bist_done - BIST has completed on the adapter.
6352 * @ipr_cmd: ipr command struct
6353 *
6354 * Description: Unblock config space and resume the reset process.
6355 *
6356 * Return value:
6357 * IPR_RC_JOB_CONTINUE
6358 **/
6359static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
6360{
6361 ENTER;
6362 pci_unblock_user_cfg_access(ipr_cmd->ioa_cfg->pdev);
6363 ipr_cmd->job_step = ipr_reset_restore_cfg_space;
6364 LEAVE;
6365 return IPR_RC_JOB_CONTINUE;
6366}
6367
6368/**
6358 * ipr_reset_start_bist - Run BIST on the adapter. 6369 * ipr_reset_start_bist - Run BIST on the adapter.
6359 * @ipr_cmd: ipr command struct 6370 * @ipr_cmd: ipr command struct
6360 * 6371 *
@@ -6376,7 +6387,7 @@ static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
6376 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR); 6387 ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
6377 rc = IPR_RC_JOB_CONTINUE; 6388 rc = IPR_RC_JOB_CONTINUE;
6378 } else { 6389 } else {
6379 ipr_cmd->job_step = ipr_reset_restore_cfg_space; 6390 ipr_cmd->job_step = ipr_reset_bist_done;
6380 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT); 6391 ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
6381 rc = IPR_RC_JOB_RETURN; 6392 rc = IPR_RC_JOB_RETURN;
6382 } 6393 }
@@ -7166,9 +7177,6 @@ ipr_get_chip_cfg(const struct pci_device_id *dev_id)
7166{ 7177{
7167 int i; 7178 int i;
7168 7179
7169 if (dev_id->driver_data)
7170 return (const struct ipr_chip_cfg_t *)dev_id->driver_data;
7171
7172 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++) 7180 for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
7173 if (ipr_chip[i].vendor == dev_id->vendor && 7181 if (ipr_chip[i].vendor == dev_id->vendor &&
7174 ipr_chip[i].device == dev_id->device) 7182 ipr_chip[i].device == dev_id->device)
@@ -7517,62 +7525,43 @@ static void ipr_shutdown(struct pci_dev *pdev)
7517 7525
7518static struct pci_device_id ipr_pci_table[] __devinitdata = { 7526static struct pci_device_id ipr_pci_table[] __devinitdata = {
7519 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, 7527 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7520 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 7528 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
7521 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7522 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, 7529 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7523 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 7530 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
7524 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7525 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, 7531 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7526 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 7532 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
7527 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7528 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, 7533 { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
7529 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 7534 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
7530 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7531 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, 7535 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7532 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 7536 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
7533 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7534 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, 7537 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7535 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 7538 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
7536 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7537 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, 7539 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7538 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 7540 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
7539 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7540 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, 7541 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
7541 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 7542 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0, 0 },
7542 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7543 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, 7543 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7544 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 7544 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7545 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7546 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, 7545 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7547 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 7546 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0, 0 },
7548 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7549 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, 7547 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
7550 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 7548 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0, 0 },
7551 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7552 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, 7549 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7553 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 7550 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
7554 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7555 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, 7551 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7556 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 7552 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0, 0 },
7557 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7558 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, 7553 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
7559 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 7554 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0, 0 },
7560 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7561 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, 7555 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
7562 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 7556 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0, 0 },
7563 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
7564 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, 7557 { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
7565 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 7558 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
7566 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
7567 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, 7559 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7568 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 7560 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
7569 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
7570 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, 7561 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7571 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 7562 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0, 0 },
7572 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
7573 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, 7563 { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
7574 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 7564 PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0, 0 },
7575 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
7576 { } 7565 { }
7577}; 7566};
7578MODULE_DEVICE_TABLE(pci, ipr_pci_table); 7567MODULE_DEVICE_TABLE(pci, ipr_pci_table);
diff --git a/drivers/scsi/ipr.h b/drivers/scsi/ipr.h
index 9f62a1d4d51..88f285de97b 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.0" 40#define IPR_DRIVER_VERSION "2.3.1"
41#define IPR_DRIVER_DATE "(November 8, 2006)" 41#define IPR_DRIVER_DATE "(January 23, 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
diff --git a/drivers/scsi/lasi700.c b/drivers/scsi/lasi700.c
index f0871c3ac3d..2aae1b081fc 100644
--- a/drivers/scsi/lasi700.c
+++ b/drivers/scsi/lasi700.c
@@ -123,6 +123,7 @@ lasi700_probe(struct parisc_device *dev)
123 hostdata->force_le_on_be = 0; 123 hostdata->force_le_on_be = 0;
124 hostdata->chip710 = 1; 124 hostdata->chip710 = 1;
125 hostdata->dmode_extra = DMODE_FC2; 125 hostdata->dmode_extra = DMODE_FC2;
126 hostdata->burst_length = 8;
126 } 127 }
127 128
128 host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev); 129 host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev);
diff --git a/drivers/scsi/libsas/sas_discover.c b/drivers/scsi/libsas/sas_discover.c
index fb7df7b7581..a65598b1e53 100644
--- a/drivers/scsi/libsas/sas_discover.c
+++ b/drivers/scsi/libsas/sas_discover.c
@@ -548,7 +548,7 @@ int sas_discover_sata(struct domain_device *dev)
548 548
549 res = sas_notify_lldd_dev_found(dev); 549 res = sas_notify_lldd_dev_found(dev);
550 if (res) 550 if (res)
551 return res; 551 goto out_err2;
552 552
553 switch (dev->dev_type) { 553 switch (dev->dev_type) {
554 case SATA_DEV: 554 case SATA_DEV:
@@ -560,11 +560,23 @@ int sas_discover_sata(struct domain_device *dev)
560 default: 560 default:
561 break; 561 break;
562 } 562 }
563 if (res)
564 goto out_err;
563 565
564 sas_notify_lldd_dev_gone(dev); 566 sas_notify_lldd_dev_gone(dev);
565 if (!res) { 567 res = sas_notify_lldd_dev_found(dev);
566 sas_notify_lldd_dev_found(dev); 568 if (res)
567 } 569 goto out_err2;
570
571 res = sas_rphy_add(dev->rphy);
572 if (res)
573 goto out_err;
574
575 return res;
576
577out_err:
578 sas_notify_lldd_dev_gone(dev);
579out_err2:
568 return res; 580 return res;
569} 581}
570 582
@@ -580,21 +592,17 @@ int sas_discover_end_dev(struct domain_device *dev)
580 592
581 res = sas_notify_lldd_dev_found(dev); 593 res = sas_notify_lldd_dev_found(dev);
582 if (res) 594 if (res)
583 return res; 595 goto out_err2;
584 596
585 res = sas_rphy_add(dev->rphy); 597 res = sas_rphy_add(dev->rphy);
586 if (res) 598 if (res)
587 goto out_err; 599 goto out_err;
588 600
589 /* do this to get the end device port attributes which will have
590 * been scanned in sas_rphy_add */
591 sas_notify_lldd_dev_gone(dev);
592 sas_notify_lldd_dev_found(dev);
593
594 return 0; 601 return 0;
595 602
596out_err: 603out_err:
597 sas_notify_lldd_dev_gone(dev); 604 sas_notify_lldd_dev_gone(dev);
605out_err2:
598 return res; 606 return res;
599} 607}
600 608
@@ -649,6 +657,7 @@ void sas_unregister_domain_devices(struct asd_sas_port *port)
649 */ 657 */
650static void sas_discover_domain(struct work_struct *work) 658static void sas_discover_domain(struct work_struct *work)
651{ 659{
660 struct domain_device *dev;
652 int error = 0; 661 int error = 0;
653 struct sas_discovery_event *ev = 662 struct sas_discovery_event *ev =
654 container_of(work, struct sas_discovery_event, work); 663 container_of(work, struct sas_discovery_event, work);
@@ -658,35 +667,42 @@ static void sas_discover_domain(struct work_struct *work)
658 &port->disc.pending); 667 &port->disc.pending);
659 668
660 if (port->port_dev) 669 if (port->port_dev)
661 return ; 670 return;
662 else { 671
663 error = sas_get_port_device(port); 672 error = sas_get_port_device(port);
664 if (error) 673 if (error)
665 return; 674 return;
666 } 675 dev = port->port_dev;
667 676
668 SAS_DPRINTK("DOING DISCOVERY on port %d, pid:%d\n", port->id, 677 SAS_DPRINTK("DOING DISCOVERY on port %d, pid:%d\n", port->id,
669 current->pid); 678 current->pid);
670 679
671 switch (port->port_dev->dev_type) { 680 switch (dev->dev_type) {
672 case SAS_END_DEV: 681 case SAS_END_DEV:
673 error = sas_discover_end_dev(port->port_dev); 682 error = sas_discover_end_dev(dev);
674 break; 683 break;
675 case EDGE_DEV: 684 case EDGE_DEV:
676 case FANOUT_DEV: 685 case FANOUT_DEV:
677 error = sas_discover_root_expander(port->port_dev); 686 error = sas_discover_root_expander(dev);
678 break; 687 break;
679 case SATA_DEV: 688 case SATA_DEV:
680 case SATA_PM: 689 case SATA_PM:
681 error = sas_discover_sata(port->port_dev); 690 error = sas_discover_sata(dev);
682 break; 691 break;
683 default: 692 default:
684 SAS_DPRINTK("unhandled device %d\n", port->port_dev->dev_type); 693 SAS_DPRINTK("unhandled device %d\n", dev->dev_type);
685 break; 694 break;
686 } 695 }
687 696
688 if (error) { 697 if (error) {
689 kfree(port->port_dev); /* not kobject_register-ed yet */ 698 sas_rphy_free(dev->rphy);
699 dev->rphy = NULL;
700
701 spin_lock(&port->dev_list_lock);
702 list_del_init(&dev->dev_list_node);
703 spin_unlock(&port->dev_list_lock);
704
705 kfree(dev); /* not kobject_register-ed yet */
690 port->port_dev = NULL; 706 port->port_dev = NULL;
691 } 707 }
692 708
@@ -726,7 +742,7 @@ int sas_discover_event(struct asd_sas_port *port, enum discover_event ev)
726 BUG_ON(ev >= DISC_NUM_EVENTS); 742 BUG_ON(ev >= DISC_NUM_EVENTS);
727 743
728 sas_queue_event(ev, &disc->disc_event_lock, &disc->pending, 744 sas_queue_event(ev, &disc->disc_event_lock, &disc->pending,
729 &disc->disc_work[ev].work, port->ha->core.shost); 745 &disc->disc_work[ev].work, port->ha);
730 746
731 return 0; 747 return 0;
732} 748}
diff --git a/drivers/scsi/libsas/sas_event.c b/drivers/scsi/libsas/sas_event.c
index d83392ee682..9db30fb5caf 100644
--- a/drivers/scsi/libsas/sas_event.c
+++ b/drivers/scsi/libsas/sas_event.c
@@ -31,7 +31,7 @@ static void notify_ha_event(struct sas_ha_struct *sas_ha, enum ha_event event)
31 BUG_ON(event >= HA_NUM_EVENTS); 31 BUG_ON(event >= HA_NUM_EVENTS);
32 32
33 sas_queue_event(event, &sas_ha->event_lock, &sas_ha->pending, 33 sas_queue_event(event, &sas_ha->event_lock, &sas_ha->pending,
34 &sas_ha->ha_events[event].work, sas_ha->core.shost); 34 &sas_ha->ha_events[event].work, sas_ha);
35} 35}
36 36
37static void notify_port_event(struct asd_sas_phy *phy, enum port_event event) 37static void notify_port_event(struct asd_sas_phy *phy, enum port_event event)
@@ -41,7 +41,7 @@ static void notify_port_event(struct asd_sas_phy *phy, enum port_event event)
41 BUG_ON(event >= PORT_NUM_EVENTS); 41 BUG_ON(event >= PORT_NUM_EVENTS);
42 42
43 sas_queue_event(event, &ha->event_lock, &phy->port_events_pending, 43 sas_queue_event(event, &ha->event_lock, &phy->port_events_pending,
44 &phy->port_events[event].work, ha->core.shost); 44 &phy->port_events[event].work, ha);
45} 45}
46 46
47static void notify_phy_event(struct asd_sas_phy *phy, enum phy_event event) 47static void notify_phy_event(struct asd_sas_phy *phy, enum phy_event event)
@@ -51,7 +51,7 @@ static void notify_phy_event(struct asd_sas_phy *phy, enum phy_event event)
51 BUG_ON(event >= PHY_NUM_EVENTS); 51 BUG_ON(event >= PHY_NUM_EVENTS);
52 52
53 sas_queue_event(event, &ha->event_lock, &phy->phy_events_pending, 53 sas_queue_event(event, &ha->event_lock, &phy->phy_events_pending,
54 &phy->phy_events[event].work, ha->core.shost); 54 &phy->phy_events[event].work, ha);
55} 55}
56 56
57int sas_init_events(struct sas_ha_struct *sas_ha) 57int sas_init_events(struct sas_ha_struct *sas_ha)
diff --git a/drivers/scsi/libsas/sas_expander.c b/drivers/scsi/libsas/sas_expander.c
index d31e6fa466f..dc70c180e11 100644
--- a/drivers/scsi/libsas/sas_expander.c
+++ b/drivers/scsi/libsas/sas_expander.c
@@ -667,8 +667,9 @@ static struct domain_device *sas_ex_discover_end_dev(
667 return child; 667 return child;
668 668
669 out_list_del: 669 out_list_del:
670 sas_rphy_free(child->rphy);
671 child->rphy = NULL;
670 list_del(&child->dev_list_node); 672 list_del(&child->dev_list_node);
671 sas_rphy_free(rphy);
672 out_free: 673 out_free:
673 sas_port_delete(phy->port); 674 sas_port_delete(phy->port);
674 out_err: 675 out_err:
@@ -677,6 +678,29 @@ static struct domain_device *sas_ex_discover_end_dev(
677 return NULL; 678 return NULL;
678} 679}
679 680
681/* See if this phy is part of a wide port */
682static int sas_ex_join_wide_port(struct domain_device *parent, int phy_id)
683{
684 struct ex_phy *phy = &parent->ex_dev.ex_phy[phy_id];
685 int i;
686
687 for (i = 0; i < parent->ex_dev.num_phys; i++) {
688 struct ex_phy *ephy = &parent->ex_dev.ex_phy[i];
689
690 if (ephy == phy)
691 continue;
692
693 if (!memcmp(phy->attached_sas_addr, ephy->attached_sas_addr,
694 SAS_ADDR_SIZE) && ephy->port) {
695 sas_port_add_phy(ephy->port, phy->phy);
696 phy->phy_state = PHY_DEVICE_DISCOVERED;
697 return 0;
698 }
699 }
700
701 return -ENODEV;
702}
703
680static struct domain_device *sas_ex_discover_expander( 704static struct domain_device *sas_ex_discover_expander(
681 struct domain_device *parent, int phy_id) 705 struct domain_device *parent, int phy_id)
682{ 706{
@@ -809,6 +833,13 @@ static int sas_ex_discover_dev(struct domain_device *dev, int phy_id)
809 return res; 833 return res;
810 } 834 }
811 835
836 res = sas_ex_join_wide_port(dev, phy_id);
837 if (!res) {
838 SAS_DPRINTK("Attaching ex phy%d to wide port %016llx\n",
839 phy_id, SAS_ADDR(ex_phy->attached_sas_addr));
840 return res;
841 }
842
812 switch (ex_phy->attached_dev_type) { 843 switch (ex_phy->attached_dev_type) {
813 case SAS_END_DEV: 844 case SAS_END_DEV:
814 child = sas_ex_discover_end_dev(dev, phy_id); 845 child = sas_ex_discover_end_dev(dev, phy_id);
@@ -1431,14 +1462,23 @@ int sas_discover_root_expander(struct domain_device *dev)
1431 int res; 1462 int res;
1432 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy); 1463 struct sas_expander_device *ex = rphy_to_expander_device(dev->rphy);
1433 1464
1434 sas_rphy_add(dev->rphy); 1465 res = sas_rphy_add(dev->rphy);
1466 if (res)
1467 goto out_err;
1435 1468
1436 ex->level = dev->port->disc.max_level; /* 0 */ 1469 ex->level = dev->port->disc.max_level; /* 0 */
1437 res = sas_discover_expander(dev); 1470 res = sas_discover_expander(dev);
1438 if (!res) 1471 if (res)
1439 sas_ex_bfs_disc(dev->port); 1472 goto out_err2;
1473
1474 sas_ex_bfs_disc(dev->port);
1440 1475
1441 return res; 1476 return res;
1477
1478out_err2:
1479 sas_rphy_remove(dev->rphy);
1480out_err:
1481 return res;
1442} 1482}
1443 1483
1444/* ---------- Domain revalidation ---------- */ 1484/* ---------- Domain revalidation ---------- */
diff --git a/drivers/scsi/libsas/sas_init.c b/drivers/scsi/libsas/sas_init.c
index 2f0c07fc3f4..965698c8b7b 100644
--- a/drivers/scsi/libsas/sas_init.c
+++ b/drivers/scsi/libsas/sas_init.c
@@ -87,6 +87,9 @@ int sas_register_ha(struct sas_ha_struct *sas_ha)
87 else if (sas_ha->lldd_queue_size == -1) 87 else if (sas_ha->lldd_queue_size == -1)
88 sas_ha->lldd_queue_size = 128; /* Sanity */ 88 sas_ha->lldd_queue_size = 128; /* Sanity */
89 89
90 sas_ha->state = SAS_HA_REGISTERED;
91 spin_lock_init(&sas_ha->state_lock);
92
90 error = sas_register_phys(sas_ha); 93 error = sas_register_phys(sas_ha);
91 if (error) { 94 if (error) {
92 printk(KERN_NOTICE "couldn't register sas phys:%d\n", error); 95 printk(KERN_NOTICE "couldn't register sas phys:%d\n", error);
@@ -127,12 +130,22 @@ Undo_phys:
127 130
128int sas_unregister_ha(struct sas_ha_struct *sas_ha) 131int sas_unregister_ha(struct sas_ha_struct *sas_ha)
129{ 132{
133 unsigned long flags;
134
135 /* Set the state to unregistered to avoid further
136 * events to be queued */
137 spin_lock_irqsave(&sas_ha->state_lock, flags);
138 sas_ha->state = SAS_HA_UNREGISTERED;
139 spin_unlock_irqrestore(&sas_ha->state_lock, flags);
140 scsi_flush_work(sas_ha->core.shost);
141
142 sas_unregister_ports(sas_ha);
143
130 if (sas_ha->lldd_max_execute_num > 1) { 144 if (sas_ha->lldd_max_execute_num > 1) {
131 sas_shutdown_queue(sas_ha); 145 sas_shutdown_queue(sas_ha);
146 sas_ha->lldd_max_execute_num = 1;
132 } 147 }
133 148
134 sas_unregister_ports(sas_ha);
135
136 return 0; 149 return 0;
137} 150}
138 151
@@ -146,6 +159,36 @@ static int sas_get_linkerrors(struct sas_phy *phy)
146 return sas_smp_get_phy_events(phy); 159 return sas_smp_get_phy_events(phy);
147} 160}
148 161
162int sas_phy_enable(struct sas_phy *phy, int enable)
163{
164 int ret;
165 enum phy_func command;
166
167 if (enable)
168 command = PHY_FUNC_LINK_RESET;
169 else
170 command = PHY_FUNC_DISABLE;
171
172 if (scsi_is_sas_phy_local(phy)) {
173 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
174 struct sas_ha_struct *sas_ha = SHOST_TO_SAS_HA(shost);
175 struct asd_sas_phy *asd_phy = sas_ha->sas_phy[phy->number];
176 struct sas_internal *i =
177 to_sas_internal(sas_ha->core.shost->transportt);
178
179 if (!enable) {
180 sas_phy_disconnected(asd_phy);
181 sas_ha->notify_phy_event(asd_phy, PHYE_LOSS_OF_SIGNAL);
182 }
183 ret = i->dft->lldd_control_phy(asd_phy, command, NULL);
184 } else {
185 struct sas_rphy *rphy = dev_to_rphy(phy->dev.parent);
186 struct domain_device *ddev = sas_find_dev_by_rphy(rphy);
187 ret = sas_smp_phy_control(ddev, phy->number, command, NULL);
188 }
189 return ret;
190}
191
149int sas_phy_reset(struct sas_phy *phy, int hard_reset) 192int sas_phy_reset(struct sas_phy *phy, int hard_reset)
150{ 193{
151 int ret; 194 int ret;
@@ -172,8 +215,8 @@ int sas_phy_reset(struct sas_phy *phy, int hard_reset)
172 return ret; 215 return ret;
173} 216}
174 217
175static int sas_set_phy_speed(struct sas_phy *phy, 218int sas_set_phy_speed(struct sas_phy *phy,
176 struct sas_phy_linkrates *rates) 219 struct sas_phy_linkrates *rates)
177{ 220{
178 int ret; 221 int ret;
179 222
@@ -212,6 +255,7 @@ static int sas_set_phy_speed(struct sas_phy *phy,
212} 255}
213 256
214static struct sas_function_template sft = { 257static struct sas_function_template sft = {
258 .phy_enable = sas_phy_enable,
215 .phy_reset = sas_phy_reset, 259 .phy_reset = sas_phy_reset,
216 .set_phy_speed = sas_set_phy_speed, 260 .set_phy_speed = sas_set_phy_speed,
217 .get_linkerrors = sas_get_linkerrors, 261 .get_linkerrors = sas_get_linkerrors,
diff --git a/drivers/scsi/libsas/sas_internal.h b/drivers/scsi/libsas/sas_internal.h
index 137d7e496b6..a78638df201 100644
--- a/drivers/scsi/libsas/sas_internal.h
+++ b/drivers/scsi/libsas/sas_internal.h
@@ -80,7 +80,7 @@ void sas_hae_reset(struct work_struct *work);
80static inline void sas_queue_event(int event, spinlock_t *lock, 80static inline void sas_queue_event(int event, spinlock_t *lock,
81 unsigned long *pending, 81 unsigned long *pending,
82 struct work_struct *work, 82 struct work_struct *work,
83 struct Scsi_Host *shost) 83 struct sas_ha_struct *sas_ha)
84{ 84{
85 unsigned long flags; 85 unsigned long flags;
86 86
@@ -91,7 +91,12 @@ static inline void sas_queue_event(int event, spinlock_t *lock,
91 } 91 }
92 __set_bit(event, pending); 92 __set_bit(event, pending);
93 spin_unlock_irqrestore(lock, flags); 93 spin_unlock_irqrestore(lock, flags);
94 scsi_queue_work(shost, work); 94
95 spin_lock_irqsave(&sas_ha->state_lock, flags);
96 if (sas_ha->state != SAS_HA_UNREGISTERED) {
97 scsi_queue_work(sas_ha->core.shost, work);
98 }
99 spin_unlock_irqrestore(&sas_ha->state_lock, flags);
95} 100}
96 101
97static inline void sas_begin_event(int event, spinlock_t *lock, 102static inline void sas_begin_event(int event, spinlock_t *lock,
diff --git a/drivers/scsi/libsas/sas_port.c b/drivers/scsi/libsas/sas_port.c
index 971c37ceecb..e1e2d085c92 100644
--- a/drivers/scsi/libsas/sas_port.c
+++ b/drivers/scsi/libsas/sas_port.c
@@ -42,10 +42,11 @@ static void sas_form_port(struct asd_sas_phy *phy)
42 struct asd_sas_port *port = phy->port; 42 struct asd_sas_port *port = phy->port;
43 struct sas_internal *si = 43 struct sas_internal *si =
44 to_sas_internal(sas_ha->core.shost->transportt); 44 to_sas_internal(sas_ha->core.shost->transportt);
45 unsigned long flags;
45 46
46 if (port) { 47 if (port) {
47 if (memcmp(port->attached_sas_addr, phy->attached_sas_addr, 48 if (memcmp(port->attached_sas_addr, phy->attached_sas_addr,
48 SAS_ADDR_SIZE) == 0) 49 SAS_ADDR_SIZE) != 0)
49 sas_deform_port(phy); 50 sas_deform_port(phy);
50 else { 51 else {
51 SAS_DPRINTK("%s: phy%d belongs to port%d already(%d)!\n", 52 SAS_DPRINTK("%s: phy%d belongs to port%d already(%d)!\n",
@@ -56,7 +57,7 @@ static void sas_form_port(struct asd_sas_phy *phy)
56 } 57 }
57 58
58 /* find a port */ 59 /* find a port */
59 spin_lock(&sas_ha->phy_port_lock); 60 spin_lock_irqsave(&sas_ha->phy_port_lock, flags);
60 for (i = 0; i < sas_ha->num_phys; i++) { 61 for (i = 0; i < sas_ha->num_phys; i++) {
61 port = sas_ha->sas_port[i]; 62 port = sas_ha->sas_port[i];
62 spin_lock(&port->phy_list_lock); 63 spin_lock(&port->phy_list_lock);
@@ -78,7 +79,7 @@ static void sas_form_port(struct asd_sas_phy *phy)
78 if (i >= sas_ha->num_phys) { 79 if (i >= sas_ha->num_phys) {
79 printk(KERN_NOTICE "%s: couldn't find a free port, bug?\n", 80 printk(KERN_NOTICE "%s: couldn't find a free port, bug?\n",
80 __FUNCTION__); 81 __FUNCTION__);
81 spin_unlock(&sas_ha->phy_port_lock); 82 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
82 return; 83 return;
83 } 84 }
84 85
@@ -105,7 +106,7 @@ static void sas_form_port(struct asd_sas_phy *phy)
105 } else 106 } else
106 port->linkrate = max(port->linkrate, phy->linkrate); 107 port->linkrate = max(port->linkrate, phy->linkrate);
107 spin_unlock(&port->phy_list_lock); 108 spin_unlock(&port->phy_list_lock);
108 spin_unlock(&sas_ha->phy_port_lock); 109 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
109 110
110 if (!port->port) { 111 if (!port->port) {
111 port->port = sas_port_alloc(phy->phy->dev.parent, port->id); 112 port->port = sas_port_alloc(phy->phy->dev.parent, port->id);
@@ -137,6 +138,7 @@ void sas_deform_port(struct asd_sas_phy *phy)
137 struct asd_sas_port *port = phy->port; 138 struct asd_sas_port *port = phy->port;
138 struct sas_internal *si = 139 struct sas_internal *si =
139 to_sas_internal(sas_ha->core.shost->transportt); 140 to_sas_internal(sas_ha->core.shost->transportt);
141 unsigned long flags;
140 142
141 if (!port) 143 if (!port)
142 return; /* done by a phy event */ 144 return; /* done by a phy event */
@@ -155,7 +157,7 @@ void sas_deform_port(struct asd_sas_phy *phy)
155 if (si->dft->lldd_port_deformed) 157 if (si->dft->lldd_port_deformed)
156 si->dft->lldd_port_deformed(phy); 158 si->dft->lldd_port_deformed(phy);
157 159
158 spin_lock(&sas_ha->phy_port_lock); 160 spin_lock_irqsave(&sas_ha->phy_port_lock, flags);
159 spin_lock(&port->phy_list_lock); 161 spin_lock(&port->phy_list_lock);
160 162
161 list_del_init(&phy->port_phy_el); 163 list_del_init(&phy->port_phy_el);
@@ -174,7 +176,7 @@ void sas_deform_port(struct asd_sas_phy *phy)
174 port->phy_mask = 0; 176 port->phy_mask = 0;
175 } 177 }
176 spin_unlock(&port->phy_list_lock); 178 spin_unlock(&port->phy_list_lock);
177 spin_unlock(&sas_ha->phy_port_lock); 179 spin_unlock_irqrestore(&sas_ha->phy_port_lock, flags);
178 180
179 return; 181 return;
180} 182}
diff --git a/drivers/scsi/libsas/sas_scsi_host.c b/drivers/scsi/libsas/sas_scsi_host.c
index 22672d54aa2..897a5e2c55e 100644
--- a/drivers/scsi/libsas/sas_scsi_host.c
+++ b/drivers/scsi/libsas/sas_scsi_host.c
@@ -34,6 +34,7 @@
34#include <scsi/scsi_transport_sas.h> 34#include <scsi/scsi_transport_sas.h>
35#include "../scsi_sas_internal.h" 35#include "../scsi_sas_internal.h"
36#include "../scsi_transport_api.h" 36#include "../scsi_transport_api.h"
37#include "../scsi_priv.h"
37 38
38#include <linux/err.h> 39#include <linux/err.h>
39#include <linux/blkdev.h> 40#include <linux/blkdev.h>
@@ -130,7 +131,7 @@ static enum task_attribute sas_scsi_get_task_attr(struct scsi_cmnd *cmd)
130 if (cmd->request && blk_rq_tagged(cmd->request)) { 131 if (cmd->request && blk_rq_tagged(cmd->request)) {
131 if (cmd->device->ordered_tags && 132 if (cmd->device->ordered_tags &&
132 (cmd->request->cmd_flags & REQ_HARDBARRIER)) 133 (cmd->request->cmd_flags & REQ_HARDBARRIER))
133 ta = TASK_ATTR_HOQ; 134 ta = TASK_ATTR_ORDERED;
134 } 135 }
135 return ta; 136 return ta;
136} 137}
@@ -281,6 +282,7 @@ enum task_disposition {
281 TASK_IS_ABORTED, 282 TASK_IS_ABORTED,
282 TASK_IS_AT_LU, 283 TASK_IS_AT_LU,
283 TASK_IS_NOT_AT_LU, 284 TASK_IS_NOT_AT_LU,
285 TASK_ABORT_FAILED,
284}; 286};
285 287
286static enum task_disposition sas_scsi_find_task(struct sas_task *task) 288static enum task_disposition sas_scsi_find_task(struct sas_task *task)
@@ -310,15 +312,6 @@ static enum task_disposition sas_scsi_find_task(struct sas_task *task)
310 spin_unlock_irqrestore(&core->task_queue_lock, flags); 312 spin_unlock_irqrestore(&core->task_queue_lock, flags);
311 } 313 }
312 314
313 spin_lock_irqsave(&task->task_state_lock, flags);
314 if (task->task_state_flags & SAS_TASK_INITIATOR_ABORTED) {
315 spin_unlock_irqrestore(&task->task_state_lock, flags);
316 SAS_DPRINTK("%s: task 0x%p already aborted\n",
317 __FUNCTION__, task);
318 return TASK_IS_ABORTED;
319 }
320 spin_unlock_irqrestore(&task->task_state_lock, flags);
321
322 for (i = 0; i < 5; i++) { 315 for (i = 0; i < 5; i++) {
323 SAS_DPRINTK("%s: aborting task 0x%p\n", __FUNCTION__, task); 316 SAS_DPRINTK("%s: aborting task 0x%p\n", __FUNCTION__, task);
324 res = si->dft->lldd_abort_task(task); 317 res = si->dft->lldd_abort_task(task);
@@ -340,15 +333,21 @@ static enum task_disposition sas_scsi_find_task(struct sas_task *task)
340 SAS_DPRINTK("%s: querying task 0x%p\n", 333 SAS_DPRINTK("%s: querying task 0x%p\n",
341 __FUNCTION__, task); 334 __FUNCTION__, task);
342 res = si->dft->lldd_query_task(task); 335 res = si->dft->lldd_query_task(task);
343 if (res == TMF_RESP_FUNC_SUCC) { 336 switch (res) {
337 case TMF_RESP_FUNC_SUCC:
344 SAS_DPRINTK("%s: task 0x%p at LU\n", 338 SAS_DPRINTK("%s: task 0x%p at LU\n",
345 __FUNCTION__, task); 339 __FUNCTION__, task);
346 return TASK_IS_AT_LU; 340 return TASK_IS_AT_LU;
347 } else if (res == TMF_RESP_FUNC_COMPLETE) { 341 case TMF_RESP_FUNC_COMPLETE:
348 SAS_DPRINTK("%s: task 0x%p not at LU\n", 342 SAS_DPRINTK("%s: task 0x%p not at LU\n",
349 __FUNCTION__, task); 343 __FUNCTION__, task);
350 return TASK_IS_NOT_AT_LU; 344 return TASK_IS_NOT_AT_LU;
351 } 345 case TMF_RESP_FUNC_FAILED:
346 SAS_DPRINTK("%s: task 0x%p failed to abort\n",
347 __FUNCTION__, task);
348 return TASK_ABORT_FAILED;
349 }
350
352 } 351 }
353 } 352 }
354 return res; 353 return res;
@@ -398,35 +397,113 @@ static int sas_recover_I_T(struct domain_device *dev)
398 return res; 397 return res;
399} 398}
400 399
401void sas_scsi_recover_host(struct Scsi_Host *shost) 400/* Find the sas_phy that's attached to this device */
401struct sas_phy *find_local_sas_phy(struct domain_device *dev)
402{
403 struct domain_device *pdev = dev->parent;
404 struct ex_phy *exphy = NULL;
405 int i;
406
407 /* Directly attached device */
408 if (!pdev)
409 return dev->port->phy;
410
411 /* Otherwise look in the expander */
412 for (i = 0; i < pdev->ex_dev.num_phys; i++)
413 if (!memcmp(dev->sas_addr,
414 pdev->ex_dev.ex_phy[i].attached_sas_addr,
415 SAS_ADDR_SIZE)) {
416 exphy = &pdev->ex_dev.ex_phy[i];
417 break;
418 }
419
420 BUG_ON(!exphy);
421 return exphy->phy;
422}
423
424/* Attempt to send a LUN reset message to a device */
425int sas_eh_device_reset_handler(struct scsi_cmnd *cmd)
426{
427 struct domain_device *dev = cmd_to_domain_dev(cmd);
428 struct sas_internal *i =
429 to_sas_internal(dev->port->ha->core.shost->transportt);
430 struct scsi_lun lun;
431 int res;
432
433 int_to_scsilun(cmd->device->lun, &lun);
434
435 if (!i->dft->lldd_lu_reset)
436 return FAILED;
437
438 res = i->dft->lldd_lu_reset(dev, lun.scsi_lun);
439 if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE)
440 return SUCCESS;
441
442 return FAILED;
443}
444
445/* Attempt to send a phy (bus) reset */
446int sas_eh_bus_reset_handler(struct scsi_cmnd *cmd)
447{
448 struct domain_device *dev = cmd_to_domain_dev(cmd);
449 struct sas_phy *phy = find_local_sas_phy(dev);
450 int res;
451
452 res = sas_phy_reset(phy, 1);
453 if (res)
454 SAS_DPRINTK("Bus reset of %s failed 0x%x\n",
455 phy->dev.kobj.k_name,
456 res);
457 if (res == TMF_RESP_FUNC_SUCC || res == TMF_RESP_FUNC_COMPLETE)
458 return SUCCESS;
459
460 return FAILED;
461}
462
463/* Try to reset a device */
464static int try_to_reset_cmd_device(struct Scsi_Host *shost,
465 struct scsi_cmnd *cmd)
466{
467 int res;
468
469 if (!shost->hostt->eh_device_reset_handler)
470 goto try_bus_reset;
471
472 res = shost->hostt->eh_device_reset_handler(cmd);
473 if (res == SUCCESS)
474 return res;
475
476try_bus_reset:
477 if (shost->hostt->eh_bus_reset_handler)
478 return shost->hostt->eh_bus_reset_handler(cmd);
479
480 return FAILED;
481}
482
483static int sas_eh_handle_sas_errors(struct Scsi_Host *shost,
484 struct list_head *work_q,
485 struct list_head *done_q)
402{ 486{
403 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
404 unsigned long flags;
405 LIST_HEAD(error_q);
406 struct scsi_cmnd *cmd, *n; 487 struct scsi_cmnd *cmd, *n;
407 enum task_disposition res = TASK_IS_DONE; 488 enum task_disposition res = TASK_IS_DONE;
408 int tmf_resp; 489 int tmf_resp, need_reset;
409 struct sas_internal *i = to_sas_internal(shost->transportt); 490 struct sas_internal *i = to_sas_internal(shost->transportt);
491 unsigned long flags;
492 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
410 493
411 spin_lock_irqsave(shost->host_lock, flags);
412 list_splice_init(&shost->eh_cmd_q, &error_q);
413 spin_unlock_irqrestore(shost->host_lock, flags);
414
415 SAS_DPRINTK("Enter %s\n", __FUNCTION__);
416
417 /* All tasks on this list were marked SAS_TASK_STATE_ABORTED
418 * by sas_scsi_timed_out() callback.
419 */
420Again: 494Again:
421 SAS_DPRINTK("going over list...\n"); 495 list_for_each_entry_safe(cmd, n, work_q, eh_entry) {
422 list_for_each_entry_safe(cmd, n, &error_q, eh_entry) {
423 struct sas_task *task = TO_SAS_TASK(cmd); 496 struct sas_task *task = TO_SAS_TASK(cmd);
424 list_del_init(&cmd->eh_entry);
425 497
426 if (!task) { 498 if (!task)
427 SAS_DPRINTK("%s: taskless cmd?!\n", __FUNCTION__);
428 continue; 499 continue;
429 } 500
501 list_del_init(&cmd->eh_entry);
502
503 spin_lock_irqsave(&task->task_state_lock, flags);
504 need_reset = task->task_state_flags & SAS_TASK_NEED_DEV_RESET;
505 spin_unlock_irqrestore(&task->task_state_lock, flags);
506
430 SAS_DPRINTK("trying to find task 0x%p\n", task); 507 SAS_DPRINTK("trying to find task 0x%p\n", task);
431 res = sas_scsi_find_task(task); 508 res = sas_scsi_find_task(task);
432 509
@@ -437,11 +514,15 @@ Again:
437 SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__, 514 SAS_DPRINTK("%s: task 0x%p is done\n", __FUNCTION__,
438 task); 515 task);
439 task->task_done(task); 516 task->task_done(task);
517 if (need_reset)
518 try_to_reset_cmd_device(shost, cmd);
440 continue; 519 continue;
441 case TASK_IS_ABORTED: 520 case TASK_IS_ABORTED:
442 SAS_DPRINTK("%s: task 0x%p is aborted\n", 521 SAS_DPRINTK("%s: task 0x%p is aborted\n",
443 __FUNCTION__, task); 522 __FUNCTION__, task);
444 task->task_done(task); 523 task->task_done(task);
524 if (need_reset)
525 try_to_reset_cmd_device(shost, cmd);
445 continue; 526 continue;
446 case TASK_IS_AT_LU: 527 case TASK_IS_AT_LU:
447 SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task); 528 SAS_DPRINTK("task 0x%p is at LU: lu recover\n", task);
@@ -452,11 +533,14 @@ Again:
452 SAS_ADDR(task->dev), 533 SAS_ADDR(task->dev),
453 cmd->device->lun); 534 cmd->device->lun);
454 task->task_done(task); 535 task->task_done(task);
455 sas_scsi_clear_queue_lu(&error_q, cmd); 536 if (need_reset)
537 try_to_reset_cmd_device(shost, cmd);
538 sas_scsi_clear_queue_lu(work_q, cmd);
456 goto Again; 539 goto Again;
457 } 540 }
458 /* fallthrough */ 541 /* fallthrough */
459 case TASK_IS_NOT_AT_LU: 542 case TASK_IS_NOT_AT_LU:
543 case TASK_ABORT_FAILED:
460 SAS_DPRINTK("task 0x%p is not at LU: I_T recover\n", 544 SAS_DPRINTK("task 0x%p is not at LU: I_T recover\n",
461 task); 545 task);
462 tmf_resp = sas_recover_I_T(task->dev); 546 tmf_resp = sas_recover_I_T(task->dev);
@@ -464,7 +548,9 @@ Again:
464 SAS_DPRINTK("I_T %016llx recovered\n", 548 SAS_DPRINTK("I_T %016llx recovered\n",
465 SAS_ADDR(task->dev->sas_addr)); 549 SAS_ADDR(task->dev->sas_addr));
466 task->task_done(task); 550 task->task_done(task);
467 sas_scsi_clear_queue_I_T(&error_q, task->dev); 551 if (need_reset)
552 try_to_reset_cmd_device(shost, cmd);
553 sas_scsi_clear_queue_I_T(work_q, task->dev);
468 goto Again; 554 goto Again;
469 } 555 }
470 /* Hammer time :-) */ 556 /* Hammer time :-) */
@@ -477,7 +563,9 @@ Again:
477 SAS_DPRINTK("clear nexus port:%d " 563 SAS_DPRINTK("clear nexus port:%d "
478 "succeeded\n", port->id); 564 "succeeded\n", port->id);
479 task->task_done(task); 565 task->task_done(task);
480 sas_scsi_clear_queue_port(&error_q, 566 if (need_reset)
567 try_to_reset_cmd_device(shost, cmd);
568 sas_scsi_clear_queue_port(work_q,
481 port); 569 port);
482 goto Again; 570 goto Again;
483 } 571 }
@@ -489,6 +577,8 @@ Again:
489 SAS_DPRINTK("clear nexus ha " 577 SAS_DPRINTK("clear nexus ha "
490 "succeeded\n"); 578 "succeeded\n");
491 task->task_done(task); 579 task->task_done(task);
580 if (need_reset)
581 try_to_reset_cmd_device(shost, cmd);
492 goto out; 582 goto out;
493 } 583 }
494 } 584 }
@@ -502,20 +592,54 @@ Again:
502 cmd->device->lun); 592 cmd->device->lun);
503 593
504 task->task_done(task); 594 task->task_done(task);
595 if (need_reset)
596 try_to_reset_cmd_device(shost, cmd);
505 goto clear_q; 597 goto clear_q;
506 } 598 }
507 } 599 }
508out: 600out:
509 scsi_eh_flush_done_q(&ha->eh_done_q); 601 return list_empty(work_q);
510 SAS_DPRINTK("--- Exit %s\n", __FUNCTION__);
511 return;
512clear_q: 602clear_q:
513 SAS_DPRINTK("--- Exit %s -- clear_q\n", __FUNCTION__); 603 SAS_DPRINTK("--- Exit %s -- clear_q\n", __FUNCTION__);
514 list_for_each_entry_safe(cmd, n, &error_q, eh_entry) { 604 list_for_each_entry_safe(cmd, n, work_q, eh_entry) {
515 struct sas_task *task = TO_SAS_TASK(cmd); 605 struct sas_task *task = TO_SAS_TASK(cmd);
516 list_del_init(&cmd->eh_entry); 606 list_del_init(&cmd->eh_entry);
517 task->task_done(task); 607 task->task_done(task);
518 } 608 }
609 return list_empty(work_q);
610}
611
612void sas_scsi_recover_host(struct Scsi_Host *shost)
613{
614 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
615 unsigned long flags;
616 LIST_HEAD(eh_work_q);
617
618 spin_lock_irqsave(shost->host_lock, flags);
619 list_splice_init(&shost->eh_cmd_q, &eh_work_q);
620 spin_unlock_irqrestore(shost->host_lock, flags);
621
622 SAS_DPRINTK("Enter %s\n", __FUNCTION__);
623 /*
624 * Deal with commands that still have SAS tasks (i.e. they didn't
625 * complete via the normal sas_task completion mechanism)
626 */
627 if (sas_eh_handle_sas_errors(shost, &eh_work_q, &ha->eh_done_q))
628 goto out;
629
630 /*
631 * Now deal with SCSI commands that completed ok but have a an error
632 * code (and hopefully sense data) attached. This is roughly what
633 * scsi_unjam_host does, but we skip scsi_eh_abort_cmds because any
634 * command we see here has no sas_task and is thus unknown to the HA.
635 */
636 if (!scsi_eh_get_sense(&eh_work_q, &ha->eh_done_q))
637 scsi_eh_ready_devs(shost, &eh_work_q, &ha->eh_done_q);
638
639out:
640 scsi_eh_flush_done_q(&ha->eh_done_q);
641 SAS_DPRINTK("--- Exit %s\n", __FUNCTION__);
642 return;
519} 643}
520 644
521enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd) 645enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
@@ -524,24 +648,30 @@ enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
524 unsigned long flags; 648 unsigned long flags;
525 649
526 if (!task) { 650 if (!task) {
527 SAS_DPRINTK("command 0x%p, task 0x%p, gone: EH_HANDLED\n", 651 cmd->timeout_per_command /= 2;
528 cmd, task); 652 SAS_DPRINTK("command 0x%p, task 0x%p, gone: %s\n",
529 return EH_HANDLED; 653 cmd, task, (cmd->timeout_per_command ?
654 "EH_RESET_TIMER" : "EH_NOT_HANDLED"));
655 if (!cmd->timeout_per_command)
656 return EH_NOT_HANDLED;
657 return EH_RESET_TIMER;
530 } 658 }
531 659
532 spin_lock_irqsave(&task->task_state_lock, flags); 660 spin_lock_irqsave(&task->task_state_lock, flags);
533 if (task->task_state_flags & SAS_TASK_INITIATOR_ABORTED) { 661 BUG_ON(task->task_state_flags & SAS_TASK_STATE_ABORTED);
534 spin_unlock_irqrestore(&task->task_state_lock, flags);
535 SAS_DPRINTK("command 0x%p, task 0x%p, aborted by initiator: "
536 "EH_NOT_HANDLED\n", cmd, task);
537 return EH_NOT_HANDLED;
538 }
539 if (task->task_state_flags & SAS_TASK_STATE_DONE) { 662 if (task->task_state_flags & SAS_TASK_STATE_DONE) {
540 spin_unlock_irqrestore(&task->task_state_lock, flags); 663 spin_unlock_irqrestore(&task->task_state_lock, flags);
541 SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_HANDLED\n", 664 SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_HANDLED\n",
542 cmd, task); 665 cmd, task);
543 return EH_HANDLED; 666 return EH_HANDLED;
544 } 667 }
668 if (!(task->task_state_flags & SAS_TASK_AT_INITIATOR)) {
669 spin_unlock_irqrestore(&task->task_state_lock, flags);
670 SAS_DPRINTK("command 0x%p, task 0x%p, not at initiator: "
671 "EH_RESET_TIMER\n",
672 cmd, task);
673 return EH_RESET_TIMER;
674 }
545 task->task_state_flags |= SAS_TASK_STATE_ABORTED; 675 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
546 spin_unlock_irqrestore(&task->task_state_lock, flags); 676 spin_unlock_irqrestore(&task->task_state_lock, flags);
547 677
@@ -557,8 +687,9 @@ struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy)
557 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost); 687 struct sas_ha_struct *ha = SHOST_TO_SAS_HA(shost);
558 struct domain_device *found_dev = NULL; 688 struct domain_device *found_dev = NULL;
559 int i; 689 int i;
690 unsigned long flags;
560 691
561 spin_lock(&ha->phy_port_lock); 692 spin_lock_irqsave(&ha->phy_port_lock, flags);
562 for (i = 0; i < ha->num_phys; i++) { 693 for (i = 0; i < ha->num_phys; i++) {
563 struct asd_sas_port *port = ha->sas_port[i]; 694 struct asd_sas_port *port = ha->sas_port[i];
564 struct domain_device *dev; 695 struct domain_device *dev;
@@ -574,7 +705,7 @@ struct domain_device *sas_find_dev_by_rphy(struct sas_rphy *rphy)
574 spin_unlock(&port->dev_list_lock); 705 spin_unlock(&port->dev_list_lock);
575 } 706 }
576 found: 707 found:
577 spin_unlock(&ha->phy_port_lock); 708 spin_unlock_irqrestore(&ha->phy_port_lock, flags);
578 709
579 return found_dev; 710 return found_dev;
580} 711}
@@ -623,6 +754,8 @@ int sas_slave_configure(struct scsi_device *scsi_dev)
623 scsi_deactivate_tcq(scsi_dev, 1); 754 scsi_deactivate_tcq(scsi_dev, 1);
624 } 755 }
625 756
757 scsi_dev->allow_restart = 1;
758
626 return 0; 759 return 0;
627} 760}
628 761
@@ -799,46 +932,42 @@ void sas_shutdown_queue(struct sas_ha_struct *sas_ha)
799 spin_unlock_irqrestore(&core->task_queue_lock, flags); 932 spin_unlock_irqrestore(&core->task_queue_lock, flags);
800} 933}
801 934
802static int do_sas_task_abort(struct sas_task *task) 935/*
936 * Call the LLDD task abort routine directly. This function is intended for
937 * use by upper layers that need to tell the LLDD to abort a task.
938 */
939int __sas_task_abort(struct sas_task *task)
803{ 940{
804 struct scsi_cmnd *sc = task->uldd_task;
805 struct sas_internal *si = 941 struct sas_internal *si =
806 to_sas_internal(task->dev->port->ha->core.shost->transportt); 942 to_sas_internal(task->dev->port->ha->core.shost->transportt);
807 unsigned long flags; 943 unsigned long flags;
808 int res; 944 int res;
809 945
810 spin_lock_irqsave(&task->task_state_lock, flags); 946 spin_lock_irqsave(&task->task_state_lock, flags);
811 if (task->task_state_flags & SAS_TASK_STATE_ABORTED) { 947 if (task->task_state_flags & SAS_TASK_STATE_ABORTED ||
948 task->task_state_flags & SAS_TASK_STATE_DONE) {
812 spin_unlock_irqrestore(&task->task_state_lock, flags); 949 spin_unlock_irqrestore(&task->task_state_lock, flags);
813 SAS_DPRINTK("%s: Task %p already aborted.\n", __FUNCTION__, 950 SAS_DPRINTK("%s: Task %p already finished.\n", __FUNCTION__,
814 task); 951 task);
815 return 0; 952 return 0;
816 } 953 }
817 954 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
818 task->task_state_flags |= SAS_TASK_INITIATOR_ABORTED;
819 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
820 task->task_state_flags |= SAS_TASK_STATE_ABORTED;
821 spin_unlock_irqrestore(&task->task_state_lock, flags); 955 spin_unlock_irqrestore(&task->task_state_lock, flags);
822 956
823 if (!si->dft->lldd_abort_task) 957 if (!si->dft->lldd_abort_task)
824 return -ENODEV; 958 return -ENODEV;
825 959
826 res = si->dft->lldd_abort_task(task); 960 res = si->dft->lldd_abort_task(task);
961
962 spin_lock_irqsave(&task->task_state_lock, flags);
827 if ((task->task_state_flags & SAS_TASK_STATE_DONE) || 963 if ((task->task_state_flags & SAS_TASK_STATE_DONE) ||
828 (res == TMF_RESP_FUNC_COMPLETE)) 964 (res == TMF_RESP_FUNC_COMPLETE))
829 { 965 {
830 /* SMP commands don't have scsi_cmds(?) */ 966 spin_unlock_irqrestore(&task->task_state_lock, flags);
831 if (!sc) { 967 task->task_done(task);
832 task->task_done(task);
833 return 0;
834 }
835 scsi_req_abort_cmd(sc);
836 scsi_schedule_eh(sc->device->host);
837 return 0; 968 return 0;
838 } 969 }
839 970
840 spin_lock_irqsave(&task->task_state_lock, flags);
841 task->task_state_flags &= ~SAS_TASK_INITIATOR_ABORTED;
842 if (!(task->task_state_flags & SAS_TASK_STATE_DONE)) 971 if (!(task->task_state_flags & SAS_TASK_STATE_DONE))
843 task->task_state_flags &= ~SAS_TASK_STATE_ABORTED; 972 task->task_state_flags &= ~SAS_TASK_STATE_ABORTED;
844 spin_unlock_irqrestore(&task->task_state_lock, flags); 973 spin_unlock_irqrestore(&task->task_state_lock, flags);
@@ -846,17 +975,24 @@ static int do_sas_task_abort(struct sas_task *task)
846 return -EAGAIN; 975 return -EAGAIN;
847} 976}
848 977
849void sas_task_abort(struct work_struct *work) 978/*
979 * Tell an upper layer that it needs to initiate an abort for a given task.
980 * This should only ever be called by an LLDD.
981 */
982void sas_task_abort(struct sas_task *task)
850{ 983{
851 struct sas_task *task = 984 struct scsi_cmnd *sc = task->uldd_task;
852 container_of(work, struct sas_task, abort_work);
853 int i;
854 985
855 for (i = 0; i < 5; i++) 986 /* Escape for libsas internal commands */
856 if (!do_sas_task_abort(task)) 987 if (!sc) {
988 if (!del_timer(&task->timer))
857 return; 989 return;
990 task->timer.function(task->timer.data);
991 return;
992 }
858 993
859 SAS_DPRINTK("%s: Could not kill task!\n", __FUNCTION__); 994 scsi_req_abort_cmd(sc);
995 scsi_schedule_eh(sc->device->host);
860} 996}
861 997
862EXPORT_SYMBOL_GPL(sas_queuecommand); 998EXPORT_SYMBOL_GPL(sas_queuecommand);
@@ -866,5 +1002,9 @@ EXPORT_SYMBOL_GPL(sas_slave_destroy);
866EXPORT_SYMBOL_GPL(sas_change_queue_depth); 1002EXPORT_SYMBOL_GPL(sas_change_queue_depth);
867EXPORT_SYMBOL_GPL(sas_change_queue_type); 1003EXPORT_SYMBOL_GPL(sas_change_queue_type);
868EXPORT_SYMBOL_GPL(sas_bios_param); 1004EXPORT_SYMBOL_GPL(sas_bios_param);
1005EXPORT_SYMBOL_GPL(__sas_task_abort);
869EXPORT_SYMBOL_GPL(sas_task_abort); 1006EXPORT_SYMBOL_GPL(sas_task_abort);
870EXPORT_SYMBOL_GPL(sas_phy_reset); 1007EXPORT_SYMBOL_GPL(sas_phy_reset);
1008EXPORT_SYMBOL_GPL(sas_phy_enable);
1009EXPORT_SYMBOL_GPL(sas_eh_device_reset_handler);
1010EXPORT_SYMBOL_GPL(sas_eh_bus_reset_handler);
diff --git a/drivers/scsi/megaraid.c b/drivers/scsi/megaraid.c
index 77d9d3804cc..808a1b8c404 100644
--- a/drivers/scsi/megaraid.c
+++ b/drivers/scsi/megaraid.c
@@ -92,7 +92,7 @@ static struct mega_hbas mega_hbas[MAX_CONTROLLERS];
92/* 92/*
93 * The File Operations structure for the serial/ioctl interface of the driver 93 * The File Operations structure for the serial/ioctl interface of the driver
94 */ 94 */
95static struct file_operations megadev_fops = { 95static const struct file_operations megadev_fops = {
96 .owner = THIS_MODULE, 96 .owner = THIS_MODULE,
97 .ioctl = megadev_ioctl, 97 .ioctl = megadev_ioctl,
98 .open = megadev_open, 98 .open = megadev_open,
diff --git a/drivers/scsi/megaraid/mbox_defs.h b/drivers/scsi/megaraid/mbox_defs.h
index 3052869f51f..170399ef06f 100644
--- a/drivers/scsi/megaraid/mbox_defs.h
+++ b/drivers/scsi/megaraid/mbox_defs.h
@@ -748,7 +748,7 @@ typedef struct {
748 748
749 749
750/** 750/**
751 * private_bios_data - bios private data for boot devices 751 * struct private_bios_data - bios private data for boot devices
752 * @geometry : bits 0-3 - BIOS geometry, 0x0001 - 1GB, 0x0010 - 2GB, 752 * @geometry : bits 0-3 - BIOS geometry, 0x0001 - 1GB, 0x0010 - 2GB,
753 * 0x1000 - 8GB, Others values are invalid 753 * 0x1000 - 8GB, Others values are invalid
754 * @unused : bits 4-7 are unused 754 * @unused : bits 4-7 are unused
diff --git a/drivers/scsi/megaraid/mega_common.h b/drivers/scsi/megaraid/mega_common.h
index b50e27e6602..26e1e6c5565 100644
--- a/drivers/scsi/megaraid/mega_common.h
+++ b/drivers/scsi/megaraid/mega_common.h
@@ -46,17 +46,17 @@
46 46
47/** 47/**
48 * scb_t - scsi command control block 48 * scb_t - scsi command control block
49 * @param ccb : command control block for individual driver 49 * @ccb : command control block for individual driver
50 * @param list : list of control blocks 50 * @list : list of control blocks
51 * @param gp : general purpose field for LLDs 51 * @gp : general purpose field for LLDs
52 * @param sno : all SCBs have a serial number 52 * @sno : all SCBs have a serial number
53 * @param scp : associated scsi command 53 * @scp : associated scsi command
54 * @param state : current state of scb 54 * @state : current state of scb
55 * @param dma_dir : direction of data transfer 55 * @dma_dir : direction of data transfer
56 * @param dma_type : transfer with sg list, buffer, or no data transfer 56 * @dma_type : transfer with sg list, buffer, or no data transfer
57 * @param dev_channel : actual channel on the device 57 * @dev_channel : actual channel on the device
58 * @param dev_target : actual target on the device 58 * @dev_target : actual target on the device
59 * @param status : completion status 59 * @status : completion status
60 * 60 *
61 * This is our central data structure to issue commands the each driver. 61 * This is our central data structure to issue commands the each driver.
62 * Driver specific data structures are maintained in the ccb field. 62 * Driver specific data structures are maintained in the ccb field.
@@ -99,42 +99,42 @@ typedef struct {
99 99
100/** 100/**
101 * struct adapter_t - driver's initialization structure 101 * struct adapter_t - driver's initialization structure
102 * @param dpc_h : tasklet handle 102 * @aram dpc_h : tasklet handle
103 * @param pdev : pci configuration pointer for kernel 103 * @pdev : pci configuration pointer for kernel
104 * @param host : pointer to host structure of mid-layer 104 * @host : pointer to host structure of mid-layer
105 * @param lock : synchronization lock for mid-layer and driver 105 * @lock : synchronization lock for mid-layer and driver
106 * @param quiescent : driver is quiescent for now. 106 * @quiescent : driver is quiescent for now.
107 * @param outstanding_cmds : number of commands pending in the driver 107 * @outstanding_cmds : number of commands pending in the driver
108 * @param kscb_list : pointer to the bulk of SCBs pointers for IO 108 * @kscb_list : pointer to the bulk of SCBs pointers for IO
109 * @param kscb_pool : pool of free scbs for IO 109 * @kscb_pool : pool of free scbs for IO
110 * @param kscb_pool_lock : lock for pool of free scbs 110 * @kscb_pool_lock : lock for pool of free scbs
111 * @param pend_list : pending commands list 111 * @pend_list : pending commands list
112 * @param pend_list_lock : exlusion lock for pending commands list 112 * @pend_list_lock : exclusion lock for pending commands list
113 * @param completed_list : list of completed commands 113 * @completed_list : list of completed commands
114 * @param completed_list_lock : exclusion lock for list of completed commands 114 * @completed_list_lock : exclusion lock for list of completed commands
115 * @param sglen : max sg elements supported 115 * @sglen : max sg elements supported
116 * @param device_ids : to convert kernel device addr to our devices. 116 * @device_ids : to convert kernel device addr to our devices.
117 * @param raid_device : raid adapter specific pointer 117 * @raid_device : raid adapter specific pointer
118 * @param max_channel : maximum channel number supported - inclusive 118 * @max_channel : maximum channel number supported - inclusive
119 * @param max_target : max target supported - inclusive 119 * @max_target : max target supported - inclusive
120 * @param max_lun : max lun supported - inclusive 120 * @max_lun : max lun supported - inclusive
121 * @param unique_id : unique identifier for each adapter 121 * @unique_id : unique identifier for each adapter
122 * @param irq : IRQ for this adapter 122 * @irq : IRQ for this adapter
123 * @param ito : internal timeout value, (-1) means no timeout 123 * @ito : internal timeout value, (-1) means no timeout
124 * @param ibuf : buffer to issue internal commands 124 * @ibuf : buffer to issue internal commands
125 * @param ibuf_dma_h : dma handle for the above buffer 125 * @ibuf_dma_h : dma handle for the above buffer
126 * @param uscb_list : SCB pointers for user cmds, common mgmt module 126 * @uscb_list : SCB pointers for user cmds, common mgmt module
127 * @param uscb_pool : pool of SCBs for user commands 127 * @uscb_pool : pool of SCBs for user commands
128 * @param uscb_pool_lock : exclusion lock for these SCBs 128 * @uscb_pool_lock : exclusion lock for these SCBs
129 * @param max_cmds : max outstanding commands 129 * @max_cmds : max outstanding commands
130 * @param fw_version : firmware version 130 * @fw_version : firmware version
131 * @param bios_version : bios version 131 * @bios_version : bios version
132 * @param max_cdb_sz : biggest CDB size supported. 132 * @max_cdb_sz : biggest CDB size supported.
133 * @param ha : is high availability present - clustering 133 * @ha : is high availability present - clustering
134 * @param init_id : initiator ID, the default value should be 7 134 * @init_id : initiator ID, the default value should be 7
135 * @param max_sectors : max sectors per request 135 * @max_sectors : max sectors per request
136 * @param cmd_per_lun : max outstanding commands per LUN 136 * @cmd_per_lun : max outstanding commands per LUN
137 * @param being_detached : set when unloading, no more mgmt calls 137 * @being_detached : set when unloading, no more mgmt calls
138 * 138 *
139 * 139 *
140 * mraid_setup_device_map() can be called anytime after the device map is 140 * mraid_setup_device_map() can be called anytime after the device map is
@@ -211,23 +211,23 @@ typedef struct {
211#define SCP2ADAPTER(scp) (adapter_t *)SCSIHOST2ADAP(SCP2HOST(scp)) 211#define SCP2ADAPTER(scp) (adapter_t *)SCSIHOST2ADAP(SCP2HOST(scp))
212 212
213 213
214/**
215 * MRAID_GET_DEVICE_MAP - device ids
216 * @param adp - Adapter's soft state
217 * @param scp - mid-layer scsi command pointer
218 * @param p_chan - physical channel on the controller
219 * @param target - target id of the device or logical drive number
220 * @param islogical - set if the command is for the logical drive
221 *
222 * Macro to retrieve information about device class, logical or physical and
223 * the corresponding physical channel and target or logical drive number
224 **/
225#define MRAID_IS_LOGICAL(adp, scp) \ 214#define MRAID_IS_LOGICAL(adp, scp) \
226 (SCP2CHANNEL(scp) == (adp)->max_channel) ? 1 : 0 215 (SCP2CHANNEL(scp) == (adp)->max_channel) ? 1 : 0
227 216
228#define MRAID_IS_LOGICAL_SDEV(adp, sdev) \ 217#define MRAID_IS_LOGICAL_SDEV(adp, sdev) \
229 (sdev->channel == (adp)->max_channel) ? 1 : 0 218 (sdev->channel == (adp)->max_channel) ? 1 : 0
230 219
220/**
221 * MRAID_GET_DEVICE_MAP - device ids
222 * @adp : adapter's soft state
223 * @scp : mid-layer scsi command pointer
224 * @p_chan : physical channel on the controller
225 * @target : target id of the device or logical drive number
226 * @islogical : set if the command is for the logical drive
227 *
228 * Macro to retrieve information about device class, logical or physical and
229 * the corresponding physical channel and target or logical drive number
230 */
231#define MRAID_GET_DEVICE_MAP(adp, scp, p_chan, target, islogical) \ 231#define MRAID_GET_DEVICE_MAP(adp, scp, p_chan, target, islogical) \
232 /* \ 232 /* \
233 * Is the request coming for the virtual channel \ 233 * Is the request coming for the virtual channel \
@@ -271,10 +271,10 @@ typedef struct {
271#define ASSERT(expression) 271#define ASSERT(expression)
272#endif 272#endif
273 273
274/* 274/**
275 * struct mraid_pci_blk - structure holds DMA memory block info 275 * struct mraid_pci_blk - structure holds DMA memory block info
276 * @param vaddr : virtual address to a memory block 276 * @vaddr : virtual address to a memory block
277 * @param dma_addr : DMA handle to a memory block 277 * @dma_addr : DMA handle to a memory block
278 * 278 *
279 * This structure is filled up for the caller. It is the responsibilty of the 279 * This structure is filled up for the caller. It is the responsibilty of the
280 * caller to allocate this array big enough to store addresses for all 280 * caller to allocate this array big enough to store addresses for all
diff --git a/drivers/scsi/megaraid/megaraid_ioctl.h b/drivers/scsi/megaraid/megaraid_ioctl.h
index b8aa34202ec..706fa05a187 100644
--- a/drivers/scsi/megaraid/megaraid_ioctl.h
+++ b/drivers/scsi/megaraid/megaraid_ioctl.h
@@ -22,23 +22,23 @@
22 22
23#include "mbox_defs.h" 23#include "mbox_defs.h"
24 24
25/*
26 * console messages debug levels
27 */
28#define CL_ANN 0 /* print unconditionally, announcements */
29#define CL_DLEVEL1 1 /* debug level 1, informative */
30#define CL_DLEVEL2 2 /* debug level 2, verbose */
31#define CL_DLEVEL3 3 /* debug level 3, very verbose */
32
25/** 33/**
26 * con_log() - console log routine 34 * con_log() - console log routine
27 * @param level : indicates the severity of the message. 35 * @level : indicates the severity of the message.
28 * @fparam mt : format string 36 * @fmt : format string
29 * 37 *
30 * con_log displays the error messages on the console based on the current 38 * con_log displays the error messages on the console based on the current
31 * debug level. Also it attaches the appropriate kernel severity level with 39 * debug level. Also it attaches the appropriate kernel severity level with
32 * the message. 40 * the message.
33 *
34 *
35 * consolge messages debug levels
36 */ 41 */
37#define CL_ANN 0 /* print unconditionally, announcements */
38#define CL_DLEVEL1 1 /* debug level 1, informative */
39#define CL_DLEVEL2 2 /* debug level 2, verbose */
40#define CL_DLEVEL3 3 /* debug level 3, very verbose */
41
42#define con_log(level, fmt) if (LSI_DBGLVL >= level) printk fmt; 42#define con_log(level, fmt) if (LSI_DBGLVL >= level) printk fmt;
43 43
44/* 44/*
@@ -157,14 +157,14 @@ typedef struct uioc {
157/** 157/**
158 * struct mraid_hba_info - information about the controller 158 * struct mraid_hba_info - information about the controller
159 * 159 *
160 * @param pci_vendor_id : PCI vendor id 160 * @pci_vendor_id : PCI vendor id
161 * @param pci_device_id : PCI device id 161 * @pci_device_id : PCI device id
162 * @param subsystem_vendor_id : PCI subsystem vendor id 162 * @subsystem_vendor_id : PCI subsystem vendor id
163 * @param subsystem_device_id : PCI subsystem device id 163 * @subsystem_device_id : PCI subsystem device id
164 * @param baseport : base port of hba memory 164 * @baseport : base port of hba memory
165 * @param pci_bus : PCI bus 165 * @pci_bus : PCI bus
166 * @param pci_dev_fn : PCI device/function values 166 * @pci_dev_fn : PCI device/function values
167 * @param irq : interrupt vector for the device 167 * @irq : interrupt vector for the device
168 * 168 *
169 * Extended information of 256 bytes about the controller. Align on the single 169 * Extended information of 256 bytes about the controller. Align on the single
170 * byte boundary so that 32-bit applications can be run on 64-bit platform 170 * byte boundary so that 32-bit applications can be run on 64-bit platform
diff --git a/drivers/scsi/megaraid/megaraid_mbox.c b/drivers/scsi/megaraid/megaraid_mbox.c
index 7bac86dda88..04d0b6918c6 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.c
+++ b/drivers/scsi/megaraid/megaraid_mbox.c
@@ -10,13 +10,13 @@
10 * 2 of the License, or (at your option) any later version. 10 * 2 of the License, or (at your option) any later version.
11 * 11 *
12 * FILE : megaraid_mbox.c 12 * FILE : megaraid_mbox.c
13 * Version : v2.20.4.9 (Jul 16 2006) 13 * Version : v2.20.5.1 (Nov 16 2006)
14 * 14 *
15 * Authors: 15 * Authors:
16 * Atul Mukker <Atul.Mukker@lsil.com> 16 * Atul Mukker <Atul.Mukker@lsi.com>
17 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsil.com> 17 * Sreenivas Bagalkote <Sreenivas.Bagalkote@lsi.com>
18 * Manoj Jose <Manoj.Jose@lsil.com> 18 * Manoj Jose <Manoj.Jose@lsi.com>
19 * Seokmann Ju <Seokmann.Ju@lsil.com> 19 * Seokmann Ju
20 * 20 *
21 * List of supported controllers 21 * List of supported controllers
22 * 22 *
@@ -107,6 +107,7 @@ static int megaraid_mbox_support_random_del(adapter_t *);
107static int megaraid_mbox_get_max_sg(adapter_t *); 107static int megaraid_mbox_get_max_sg(adapter_t *);
108static void megaraid_mbox_enum_raid_scsi(adapter_t *); 108static void megaraid_mbox_enum_raid_scsi(adapter_t *);
109static void megaraid_mbox_flush_cache(adapter_t *); 109static void megaraid_mbox_flush_cache(adapter_t *);
110static int megaraid_mbox_fire_sync_cmd(adapter_t *);
110 111
111static void megaraid_mbox_display_scb(adapter_t *, scb_t *); 112static void megaraid_mbox_display_scb(adapter_t *, scb_t *);
112static void megaraid_mbox_setup_device_map(adapter_t *); 113static void megaraid_mbox_setup_device_map(adapter_t *);
@@ -137,7 +138,7 @@ static int wait_till_fw_empty(adapter_t *);
137 138
138 139
139 140
140MODULE_AUTHOR("sju@lsil.com"); 141MODULE_AUTHOR("megaraidlinux@lsi.com");
141MODULE_DESCRIPTION("LSI Logic MegaRAID Mailbox Driver"); 142MODULE_DESCRIPTION("LSI Logic MegaRAID Mailbox Driver");
142MODULE_LICENSE("GPL"); 143MODULE_LICENSE("GPL");
143MODULE_VERSION(MEGARAID_VERSION); 144MODULE_VERSION(MEGARAID_VERSION);
@@ -146,7 +147,7 @@ MODULE_VERSION(MEGARAID_VERSION);
146 * ### modules parameters for driver ### 147 * ### modules parameters for driver ###
147 */ 148 */
148 149
149/** 150/*
150 * Set to enable driver to expose unconfigured disk to kernel 151 * Set to enable driver to expose unconfigured disk to kernel
151 */ 152 */
152static int megaraid_expose_unconf_disks = 0; 153static int megaraid_expose_unconf_disks = 0;
@@ -154,7 +155,7 @@ module_param_named(unconf_disks, megaraid_expose_unconf_disks, int, 0);
154MODULE_PARM_DESC(unconf_disks, 155MODULE_PARM_DESC(unconf_disks,
155 "Set to expose unconfigured disks to kernel (default=0)"); 156 "Set to expose unconfigured disks to kernel (default=0)");
156 157
157/** 158/*
158 * driver wait time if the adapter's mailbox is busy 159 * driver wait time if the adapter's mailbox is busy
159 */ 160 */
160static unsigned int max_mbox_busy_wait = MBOX_BUSY_WAIT; 161static unsigned int max_mbox_busy_wait = MBOX_BUSY_WAIT;
@@ -162,7 +163,7 @@ module_param_named(busy_wait, max_mbox_busy_wait, int, 0);
162MODULE_PARM_DESC(busy_wait, 163MODULE_PARM_DESC(busy_wait,
163 "Max wait for mailbox in microseconds if busy (default=10)"); 164 "Max wait for mailbox in microseconds if busy (default=10)");
164 165
165/** 166/*
166 * number of sectors per IO command 167 * number of sectors per IO command
167 */ 168 */
168static unsigned int megaraid_max_sectors = MBOX_MAX_SECTORS; 169static unsigned int megaraid_max_sectors = MBOX_MAX_SECTORS;
@@ -170,7 +171,7 @@ module_param_named(max_sectors, megaraid_max_sectors, int, 0);
170MODULE_PARM_DESC(max_sectors, 171MODULE_PARM_DESC(max_sectors,
171 "Maximum number of sectors per IO command (default=128)"); 172 "Maximum number of sectors per IO command (default=128)");
172 173
173/** 174/*
174 * number of commands per logical unit 175 * number of commands per logical unit
175 */ 176 */
176static unsigned int megaraid_cmd_per_lun = MBOX_DEF_CMD_PER_LUN; 177static unsigned int megaraid_cmd_per_lun = MBOX_DEF_CMD_PER_LUN;
@@ -179,7 +180,7 @@ MODULE_PARM_DESC(cmd_per_lun,
179 "Maximum number of commands per logical unit (default=64)"); 180 "Maximum number of commands per logical unit (default=64)");
180 181
181 182
182/** 183/*
183 * Fast driver load option, skip scanning for physical devices during load. 184 * Fast driver load option, skip scanning for physical devices during load.
184 * This would result in non-disk devices being skipped during driver load 185 * This would result in non-disk devices being skipped during driver load
185 * time. These can be later added though, using /proc/scsi/scsi 186 * time. These can be later added though, using /proc/scsi/scsi
@@ -190,7 +191,7 @@ MODULE_PARM_DESC(fast_load,
190 "Faster loading of the driver, skips physical devices! (default=0)"); 191 "Faster loading of the driver, skips physical devices! (default=0)");
191 192
192 193
193/** 194/*
194 * mraid_debug level - threshold for amount of information to be displayed by 195 * mraid_debug level - threshold for amount of information to be displayed by
195 * the driver. This level can be changed through modules parameters, ioctl or 196 * the driver. This level can be changed through modules parameters, ioctl or
196 * sysfs/proc interface. By default, print the announcement messages only. 197 * sysfs/proc interface. By default, print the announcement messages only.
@@ -337,7 +338,7 @@ static struct device_attribute *megaraid_sdev_attrs[] = {
337 * 338 *
338 * Return value: 339 * Return value:
339 * actual depth set 340 * actual depth set
340 **/ 341 */
341static int megaraid_change_queue_depth(struct scsi_device *sdev, int qdepth) 342static int megaraid_change_queue_depth(struct scsi_device *sdev, int qdepth)
342{ 343{
343 if (qdepth > MBOX_MAX_SCSI_CMDS) 344 if (qdepth > MBOX_MAX_SCSI_CMDS)
@@ -369,8 +370,8 @@ static struct scsi_host_template megaraid_template_g = {
369 * megaraid_init - module load hook 370 * megaraid_init - module load hook
370 * 371 *
371 * We register ourselves as hotplug enabled module and let PCI subsystem 372 * We register ourselves as hotplug enabled module and let PCI subsystem
372 * discover our adaters 373 * discover our adapters.
373 **/ 374 */
374static int __init 375static int __init
375megaraid_init(void) 376megaraid_init(void)
376{ 377{
@@ -405,7 +406,7 @@ megaraid_init(void)
405/** 406/**
406 * megaraid_exit - driver unload entry point 407 * megaraid_exit - driver unload entry point
407 * 408 *
408 * We simply unwrap the megaraid_init routine here 409 * We simply unwrap the megaraid_init routine here.
409 */ 410 */
410static void __exit 411static void __exit
411megaraid_exit(void) 412megaraid_exit(void)
@@ -421,12 +422,12 @@ megaraid_exit(void)
421 422
422/** 423/**
423 * megaraid_probe_one - PCI hotplug entry point 424 * megaraid_probe_one - PCI hotplug entry point
424 * @param pdev : handle to this controller's PCI configuration space 425 * @pdev : handle to this controller's PCI configuration space
425 * @param id : pci device id of the class of controllers 426 * @id : pci device id of the class of controllers
426 * 427 *
427 * This routine should be called whenever a new adapter is detected by the 428 * This routine should be called whenever a new adapter is detected by the
428 * PCI hotplug susbsytem. 429 * PCI hotplug susbsytem.
429 **/ 430 */
430static int __devinit 431static int __devinit
431megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id) 432megaraid_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
432{ 433{
@@ -542,16 +543,15 @@ out_probe_one:
542 543
543 544
544/** 545/**
545 * megaraid_detach_one - release the framework resources and call LLD release 546 * megaraid_detach_one - release framework resources and call LLD release routine
546 * routine 547 * @pdev : handle for our PCI cofiguration space
547 * @param pdev : handle for our PCI cofiguration space
548 * 548 *
549 * This routine is called during driver unload. We free all the allocated 549 * This routine is called during driver unload. We free all the allocated
550 * resources and call the corresponding LLD so that it can also release all 550 * resources and call the corresponding LLD so that it can also release all
551 * its resources. 551 * its resources.
552 * 552 *
553 * This routine is also called from the PCI hotplug system 553 * This routine is also called from the PCI hotplug system.
554 **/ 554 */
555static void 555static void
556megaraid_detach_one(struct pci_dev *pdev) 556megaraid_detach_one(struct pci_dev *pdev)
557{ 557{
@@ -615,9 +615,9 @@ megaraid_detach_one(struct pci_dev *pdev)
615 615
616/** 616/**
617 * megaraid_mbox_shutdown - PCI shutdown for megaraid HBA 617 * megaraid_mbox_shutdown - PCI shutdown for megaraid HBA
618 * @param device : generice driver model device 618 * @pdev : generic driver model device
619 * 619 *
620 * Shutdown notification, perform flush cache 620 * Shutdown notification, perform flush cache.
621 */ 621 */
622static void 622static void
623megaraid_mbox_shutdown(struct pci_dev *pdev) 623megaraid_mbox_shutdown(struct pci_dev *pdev)
@@ -643,10 +643,10 @@ megaraid_mbox_shutdown(struct pci_dev *pdev)
643 643
644/** 644/**
645 * megaraid_io_attach - attach a device with the IO subsystem 645 * megaraid_io_attach - attach a device with the IO subsystem
646 * @param adapter : controller's soft state 646 * @adapter : controller's soft state
647 * 647 *
648 * Attach this device with the IO subsystem 648 * Attach this device with the IO subsystem.
649 **/ 649 */
650static int 650static int
651megaraid_io_attach(adapter_t *adapter) 651megaraid_io_attach(adapter_t *adapter)
652{ 652{
@@ -695,10 +695,10 @@ megaraid_io_attach(adapter_t *adapter)
695 695
696/** 696/**
697 * megaraid_io_detach - detach a device from the IO subsystem 697 * megaraid_io_detach - detach a device from the IO subsystem
698 * @param adapter : controller's soft state 698 * @adapter : controller's soft state
699 * 699 *
700 * Detach this device from the IO subsystem 700 * Detach this device from the IO subsystem.
701 **/ 701 */
702static void 702static void
703megaraid_io_detach(adapter_t *adapter) 703megaraid_io_detach(adapter_t *adapter)
704{ 704{
@@ -722,13 +722,13 @@ megaraid_io_detach(adapter_t *adapter)
722 722
723/** 723/**
724 * megaraid_init_mbox - initialize controller 724 * megaraid_init_mbox - initialize controller
725 * @param adapter - our soft state 725 * @adapter : our soft state
726 * 726 *
727 * . Allocate 16-byte aligned mailbox memory for firmware handshake 727 * - Allocate 16-byte aligned mailbox memory for firmware handshake
728 * . Allocate controller's memory resources 728 * - Allocate controller's memory resources
729 * . Find out all initialization data 729 * - Find out all initialization data
730 * . Allocate memory required for all the commands 730 * - Allocate memory required for all the commands
731 * . Use internal library of FW routines, build up complete soft state 731 * - Use internal library of FW routines, build up complete soft state
732 */ 732 */
733static int __devinit 733static int __devinit
734megaraid_init_mbox(adapter_t *adapter) 734megaraid_init_mbox(adapter_t *adapter)
@@ -779,33 +779,39 @@ megaraid_init_mbox(adapter_t *adapter)
779 goto out_release_regions; 779 goto out_release_regions;
780 } 780 }
781 781
782 // 782 /* initialize the mutual exclusion lock for the mailbox */
783 // Setup the rest of the soft state using the library of FW routines 783 spin_lock_init(&raid_dev->mailbox_lock);
784 //
785 784
786 // request IRQ and register the interrupt service routine 785 /* allocate memory required for commands */
786 if (megaraid_alloc_cmd_packets(adapter) != 0)
787 goto out_iounmap;
788
789 /*
790 * Issue SYNC cmd to flush the pending cmds in the adapter
791 * and initialize its internal state
792 */
793
794 if (megaraid_mbox_fire_sync_cmd(adapter))
795 con_log(CL_ANN, ("megaraid: sync cmd failed\n"));
796
797 /*
798 * Setup the rest of the soft state using the library of
799 * FW routines
800 */
801
802 /* request IRQ and register the interrupt service routine */
787 if (request_irq(adapter->irq, megaraid_isr, IRQF_SHARED, "megaraid", 803 if (request_irq(adapter->irq, megaraid_isr, IRQF_SHARED, "megaraid",
788 adapter)) { 804 adapter)) {
789 805
790 con_log(CL_ANN, (KERN_WARNING 806 con_log(CL_ANN, (KERN_WARNING
791 "megaraid: Couldn't register IRQ %d!\n", adapter->irq)); 807 "megaraid: Couldn't register IRQ %d!\n", adapter->irq));
808 goto out_alloc_cmds;
792 809
793 goto out_iounmap;
794 }
795
796
797 // initialize the mutual exclusion lock for the mailbox
798 spin_lock_init(&raid_dev->mailbox_lock);
799
800 // allocate memory required for commands
801 if (megaraid_alloc_cmd_packets(adapter) != 0) {
802 goto out_free_irq;
803 } 810 }
804 811
805 // Product info 812 // Product info
806 if (megaraid_mbox_product_info(adapter) != 0) { 813 if (megaraid_mbox_product_info(adapter) != 0)
807 goto out_alloc_cmds; 814 goto out_free_irq;
808 }
809 815
810 // Do we support extended CDBs 816 // Do we support extended CDBs
811 adapter->max_cdb_sz = 10; 817 adapter->max_cdb_sz = 10;
@@ -874,9 +880,8 @@ megaraid_init_mbox(adapter_t *adapter)
874 * Allocate resources required to issue FW calls, when sysfs is 880 * Allocate resources required to issue FW calls, when sysfs is
875 * accessed 881 * accessed
876 */ 882 */
877 if (megaraid_sysfs_alloc_resources(adapter) != 0) { 883 if (megaraid_sysfs_alloc_resources(adapter) != 0)
878 goto out_alloc_cmds; 884 goto out_free_irq;
879 }
880 885
881 // Set the DMA mask to 64-bit. All supported controllers as capable of 886 // Set the DMA mask to 64-bit. All supported controllers as capable of
882 // DMA in this range 887 // DMA in this range
@@ -920,10 +925,10 @@ megaraid_init_mbox(adapter_t *adapter)
920 925
921out_free_sysfs_res: 926out_free_sysfs_res:
922 megaraid_sysfs_free_resources(adapter); 927 megaraid_sysfs_free_resources(adapter);
923out_alloc_cmds:
924 megaraid_free_cmd_packets(adapter);
925out_free_irq: 928out_free_irq:
926 free_irq(adapter->irq, adapter); 929 free_irq(adapter->irq, adapter);
930out_alloc_cmds:
931 megaraid_free_cmd_packets(adapter);
927out_iounmap: 932out_iounmap:
928 iounmap(raid_dev->baseaddr); 933 iounmap(raid_dev->baseaddr);
929out_release_regions: 934out_release_regions:
@@ -937,7 +942,7 @@ out_free_raid_dev:
937 942
938/** 943/**
939 * megaraid_fini_mbox - undo controller initialization 944 * megaraid_fini_mbox - undo controller initialization
940 * @param adapter : our soft state 945 * @adapter : our soft state
941 */ 946 */
942static void 947static void
943megaraid_fini_mbox(adapter_t *adapter) 948megaraid_fini_mbox(adapter_t *adapter)
@@ -967,12 +972,12 @@ megaraid_fini_mbox(adapter_t *adapter)
967 972
968/** 973/**
969 * megaraid_alloc_cmd_packets - allocate shared mailbox 974 * megaraid_alloc_cmd_packets - allocate shared mailbox
970 * @param adapter : soft state of the raid controller 975 * @adapter : soft state of the raid controller
971 * 976 *
972 * Allocate and align the shared mailbox. This maibox is used to issue 977 * Allocate and align the shared mailbox. This maibox is used to issue
973 * all the commands. For IO based controllers, the mailbox is also regsitered 978 * all the commands. For IO based controllers, the mailbox is also regsitered
974 * with the FW. Allocate memory for all commands as well. 979 * with the FW. Allocate memory for all commands as well.
975 * This is our big allocator 980 * This is our big allocator.
976 */ 981 */
977static int 982static int
978megaraid_alloc_cmd_packets(adapter_t *adapter) 983megaraid_alloc_cmd_packets(adapter_t *adapter)
@@ -1132,9 +1137,9 @@ out_free_common_mbox:
1132 1137
1133/** 1138/**
1134 * megaraid_free_cmd_packets - free memory 1139 * megaraid_free_cmd_packets - free memory
1135 * @param adapter : soft state of the raid controller 1140 * @adapter : soft state of the raid controller
1136 * 1141 *
1137 * Release memory resources allocated for commands 1142 * Release memory resources allocated for commands.
1138 */ 1143 */
1139static void 1144static void
1140megaraid_free_cmd_packets(adapter_t *adapter) 1145megaraid_free_cmd_packets(adapter_t *adapter)
@@ -1156,10 +1161,10 @@ megaraid_free_cmd_packets(adapter_t *adapter)
1156 1161
1157/** 1162/**
1158 * megaraid_mbox_setup_dma_pools - setup dma pool for command packets 1163 * megaraid_mbox_setup_dma_pools - setup dma pool for command packets
1159 * @param adapter : HBA soft state 1164 * @adapter : HBA soft state
1160 * 1165 *
1161 * setup the dma pools for mailbox, passthru and extended passthru structures, 1166 * Setup the dma pools for mailbox, passthru and extended passthru structures,
1162 * and scatter-gather lists 1167 * and scatter-gather lists.
1163 */ 1168 */
1164static int 1169static int
1165megaraid_mbox_setup_dma_pools(adapter_t *adapter) 1170megaraid_mbox_setup_dma_pools(adapter_t *adapter)
@@ -1252,10 +1257,10 @@ fail_setup_dma_pool:
1252 1257
1253/** 1258/**
1254 * megaraid_mbox_teardown_dma_pools - teardown dma pools for command packets 1259 * megaraid_mbox_teardown_dma_pools - teardown dma pools for command packets
1255 * @param adapter : HBA soft state 1260 * @adapter : HBA soft state
1256 * 1261 *
1257 * teardown the dma pool for mailbox, passthru and extended passthru 1262 * Teardown the dma pool for mailbox, passthru and extended passthru
1258 * structures, and scatter-gather lists 1263 * structures, and scatter-gather lists.
1259 */ 1264 */
1260static void 1265static void
1261megaraid_mbox_teardown_dma_pools(adapter_t *adapter) 1266megaraid_mbox_teardown_dma_pools(adapter_t *adapter)
@@ -1300,10 +1305,11 @@ megaraid_mbox_teardown_dma_pools(adapter_t *adapter)
1300/** 1305/**
1301 * megaraid_alloc_scb - detach and return a scb from the free list 1306 * megaraid_alloc_scb - detach and return a scb from the free list
1302 * @adapter : controller's soft state 1307 * @adapter : controller's soft state
1308 * @scp : pointer to the scsi command to be executed
1303 * 1309 *
1304 * return the scb from the head of the free list. NULL if there are none 1310 * Return the scb from the head of the free list. %NULL if there are none
1305 * available 1311 * available.
1306 **/ 1312 */
1307static scb_t * 1313static scb_t *
1308megaraid_alloc_scb(adapter_t *adapter, struct scsi_cmnd *scp) 1314megaraid_alloc_scb(adapter_t *adapter, struct scsi_cmnd *scp)
1309{ 1315{
@@ -1337,11 +1343,11 @@ megaraid_alloc_scb(adapter_t *adapter, struct scsi_cmnd *scp)
1337 * @adapter : controller's soft state 1343 * @adapter : controller's soft state
1338 * @scb : scb to be freed 1344 * @scb : scb to be freed
1339 * 1345 *
1340 * return the scb back to the free list of scbs. The caller must 'flush' the 1346 * Return the scb back to the free list of scbs. The caller must 'flush' the
1341 * SCB before calling us. E.g., performing pci_unamp and/or pci_sync etc. 1347 * SCB before calling us. E.g., performing pci_unamp and/or pci_sync etc.
1342 * NOTE NOTE: Make sure the scb is not on any list before calling this 1348 * NOTE NOTE: Make sure the scb is not on any list before calling this
1343 * routine. 1349 * routine.
1344 **/ 1350 */
1345static inline void 1351static inline void
1346megaraid_dealloc_scb(adapter_t *adapter, scb_t *scb) 1352megaraid_dealloc_scb(adapter_t *adapter, scb_t *scb)
1347{ 1353{
@@ -1362,10 +1368,10 @@ megaraid_dealloc_scb(adapter_t *adapter, scb_t *scb)
1362 1368
1363/** 1369/**
1364 * megaraid_mbox_mksgl - make the scatter-gather list 1370 * megaraid_mbox_mksgl - make the scatter-gather list
1365 * @adapter - controller's soft state 1371 * @adapter : controller's soft state
1366 * @scb - scsi control block 1372 * @scb : scsi control block
1367 * 1373 *
1368 * prepare the scatter-gather list 1374 * Prepare the scatter-gather list.
1369 */ 1375 */
1370static int 1376static int
1371megaraid_mbox_mksgl(adapter_t *adapter, scb_t *scb) 1377megaraid_mbox_mksgl(adapter_t *adapter, scb_t *scb)
@@ -1435,10 +1441,10 @@ megaraid_mbox_mksgl(adapter_t *adapter, scb_t *scb)
1435 1441
1436/** 1442/**
1437 * mbox_post_cmd - issue a mailbox command 1443 * mbox_post_cmd - issue a mailbox command
1438 * @adapter - controller's soft state 1444 * @adapter : controller's soft state
1439 * @scb - command to be issued 1445 * @scb : command to be issued
1440 * 1446 *
1441 * post the command to the controller if mailbox is availble. 1447 * Post the command to the controller if mailbox is available.
1442 */ 1448 */
1443static int 1449static int
1444mbox_post_cmd(adapter_t *adapter, scb_t *scb) 1450mbox_post_cmd(adapter_t *adapter, scb_t *scb)
@@ -1518,7 +1524,7 @@ mbox_post_cmd(adapter_t *adapter, scb_t *scb)
1518 * Queue entry point for mailbox based controllers. 1524 * Queue entry point for mailbox based controllers.
1519 */ 1525 */
1520static int 1526static int
1521megaraid_queue_command(struct scsi_cmnd *scp, void (* done)(struct scsi_cmnd *)) 1527megaraid_queue_command(struct scsi_cmnd *scp, void (*done)(struct scsi_cmnd *))
1522{ 1528{
1523 adapter_t *adapter; 1529 adapter_t *adapter;
1524 scb_t *scb; 1530 scb_t *scb;
@@ -1548,15 +1554,15 @@ megaraid_queue_command(struct scsi_cmnd *scp, void (* done)(struct scsi_cmnd *))
1548} 1554}
1549 1555
1550/** 1556/**
1551 * megaraid_mbox_build_cmd - transform the mid-layer scsi command to megaraid 1557 * megaraid_mbox_build_cmd - transform the mid-layer scsi commands
1552 * firmware lingua 1558 * @adapter : controller's soft state
1553 * @adapter - controller's soft state 1559 * @scp : mid-layer scsi command pointer
1554 * @scp - mid-layer scsi command pointer 1560 * @busy : set if request could not be completed because of lack of
1555 * @busy - set if request could not be completed because of lack of
1556 * resources 1561 * resources
1557 * 1562 *
1558 * convert the command issued by mid-layer to format understood by megaraid 1563 * Transform the mid-layer scsi command to megaraid firmware lingua.
1559 * firmware. We also complete certain command without sending them to firmware 1564 * Convert the command issued by mid-layer to format understood by megaraid
1565 * firmware. We also complete certain commands without sending them to firmware.
1560 */ 1566 */
1561static scb_t * 1567static scb_t *
1562megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy) 1568megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy)
@@ -1937,9 +1943,9 @@ megaraid_mbox_build_cmd(adapter_t *adapter, struct scsi_cmnd *scp, int *busy)
1937/** 1943/**
1938 * megaraid_mbox_runpendq - execute commands queued in the pending queue 1944 * megaraid_mbox_runpendq - execute commands queued in the pending queue
1939 * @adapter : controller's soft state 1945 * @adapter : controller's soft state
1940 * @scb : SCB to be queued in the pending list 1946 * @scb_q : SCB to be queued in the pending list
1941 * 1947 *
1942 * scan the pending list for commands which are not yet issued and try to 1948 * Scan the pending list for commands which are not yet issued and try to
1943 * post to the controller. The SCB can be a null pointer, which would indicate 1949 * post to the controller. The SCB can be a null pointer, which would indicate
1944 * no SCB to be queue, just try to execute the ones in the pending list. 1950 * no SCB to be queue, just try to execute the ones in the pending list.
1945 * 1951 *
@@ -2012,11 +2018,11 @@ megaraid_mbox_runpendq(adapter_t *adapter, scb_t *scb_q)
2012 2018
2013/** 2019/**
2014 * megaraid_mbox_prepare_pthru - prepare a command for physical devices 2020 * megaraid_mbox_prepare_pthru - prepare a command for physical devices
2015 * @adapter - pointer to controller's soft state 2021 * @adapter : pointer to controller's soft state
2016 * @scb - scsi control block 2022 * @scb : scsi control block
2017 * @scp - scsi command from the mid-layer 2023 * @scp : scsi command from the mid-layer
2018 * 2024 *
2019 * prepare a command for the scsi physical devices 2025 * Prepare a command for the scsi physical devices.
2020 */ 2026 */
2021static void 2027static void
2022megaraid_mbox_prepare_pthru(adapter_t *adapter, scb_t *scb, 2028megaraid_mbox_prepare_pthru(adapter_t *adapter, scb_t *scb,
@@ -2060,12 +2066,12 @@ megaraid_mbox_prepare_pthru(adapter_t *adapter, scb_t *scb,
2060 2066
2061/** 2067/**
2062 * megaraid_mbox_prepare_epthru - prepare a command for physical devices 2068 * megaraid_mbox_prepare_epthru - prepare a command for physical devices
2063 * @adapter - pointer to controller's soft state 2069 * @adapter : pointer to controller's soft state
2064 * @scb - scsi control block 2070 * @scb : scsi control block
2065 * @scp - scsi command from the mid-layer 2071 * @scp : scsi command from the mid-layer
2066 * 2072 *
2067 * prepare a command for the scsi physical devices. This rountine prepares 2073 * Prepare a command for the scsi physical devices. This rountine prepares
2068 * commands for devices which can take extended CDBs (>10 bytes) 2074 * commands for devices which can take extended CDBs (>10 bytes).
2069 */ 2075 */
2070static void 2076static void
2071megaraid_mbox_prepare_epthru(adapter_t *adapter, scb_t *scb, 2077megaraid_mbox_prepare_epthru(adapter_t *adapter, scb_t *scb,
@@ -2109,9 +2115,9 @@ megaraid_mbox_prepare_epthru(adapter_t *adapter, scb_t *scb,
2109 2115
2110/** 2116/**
2111 * megaraid_ack_sequence - interrupt ack sequence for memory mapped HBAs 2117 * megaraid_ack_sequence - interrupt ack sequence for memory mapped HBAs
2112 * @adapter - controller's soft state 2118 * @adapter : controller's soft state
2113 * 2119 *
2114 * Interrupt ackrowledgement sequence for memory mapped HBAs. Find out the 2120 * Interrupt acknowledgement sequence for memory mapped HBAs. Find out the
2115 * completed command and put them on the completed list for later processing. 2121 * completed command and put them on the completed list for later processing.
2116 * 2122 *
2117 * Returns: 1 if the interrupt is valid, 0 otherwise 2123 * Returns: 1 if the interrupt is valid, 0 otherwise
@@ -2224,9 +2230,8 @@ megaraid_ack_sequence(adapter_t *adapter)
2224 2230
2225/** 2231/**
2226 * megaraid_isr - isr for memory based mailbox based controllers 2232 * megaraid_isr - isr for memory based mailbox based controllers
2227 * @irq - irq 2233 * @irq : irq
2228 * @devp - pointer to our soft state 2234 * @devp : pointer to our soft state
2229 * @regs - unused
2230 * 2235 *
2231 * Interrupt service routine for memory-mapped mailbox controllers. 2236 * Interrupt service routine for memory-mapped mailbox controllers.
2232 */ 2237 */
@@ -2671,7 +2676,7 @@ megaraid_abort_handler(struct scsi_cmnd *scp)
2671 * the FW is still live, in which case the outstanding commands counter mut go 2676 * the FW is still live, in which case the outstanding commands counter mut go
2672 * down to 0. If that happens, also issue the reservation reset command to 2677 * down to 0. If that happens, also issue the reservation reset command to
2673 * relinquish (possible) reservations on the logical drives connected to this 2678 * relinquish (possible) reservations on the logical drives connected to this
2674 * host 2679 * host.
2675 **/ 2680 **/
2676static int 2681static int
2677megaraid_reset_handler(struct scsi_cmnd *scp) 2682megaraid_reset_handler(struct scsi_cmnd *scp)
@@ -2823,11 +2828,11 @@ megaraid_reset_handler(struct scsi_cmnd *scp)
2823 2828
2824/** 2829/**
2825 * mbox_post_sync_cmd() - blocking command to the mailbox based controllers 2830 * mbox_post_sync_cmd() - blocking command to the mailbox based controllers
2826 * @adapter - controller's soft state 2831 * @adapter : controller's soft state
2827 * @raw_mbox - the mailbox 2832 * @raw_mbox : the mailbox
2828 * 2833 *
2829 * Issue a scb in synchronous and non-interrupt mode for mailbox based 2834 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2830 * controllers 2835 * controllers.
2831 */ 2836 */
2832static int 2837static int
2833mbox_post_sync_cmd(adapter_t *adapter, uint8_t raw_mbox[]) 2838mbox_post_sync_cmd(adapter_t *adapter, uint8_t raw_mbox[])
@@ -2955,12 +2960,12 @@ blocked_mailbox:
2955 2960
2956/** 2961/**
2957 * mbox_post_sync_cmd_fast - blocking command to the mailbox based controllers 2962 * mbox_post_sync_cmd_fast - blocking command to the mailbox based controllers
2958 * @adapter - controller's soft state 2963 * @adapter : controller's soft state
2959 * @raw_mbox - the mailbox 2964 * @raw_mbox : the mailbox
2960 * 2965 *
2961 * Issue a scb in synchronous and non-interrupt mode for mailbox based 2966 * Issue a scb in synchronous and non-interrupt mode for mailbox based
2962 * controllers. This is a faster version of the synchronous command and 2967 * controllers. This is a faster version of the synchronous command and
2963 * therefore can be called in interrupt-context as well 2968 * therefore can be called in interrupt-context as well.
2964 */ 2969 */
2965static int 2970static int
2966mbox_post_sync_cmd_fast(adapter_t *adapter, uint8_t raw_mbox[]) 2971mbox_post_sync_cmd_fast(adapter_t *adapter, uint8_t raw_mbox[])
@@ -3008,10 +3013,10 @@ mbox_post_sync_cmd_fast(adapter_t *adapter, uint8_t raw_mbox[])
3008 3013
3009/** 3014/**
3010 * megaraid_busywait_mbox() - Wait until the controller's mailbox is available 3015 * megaraid_busywait_mbox() - Wait until the controller's mailbox is available
3011 * @raid_dev - RAID device (HBA) soft state 3016 * @raid_dev : RAID device (HBA) soft state
3012 * 3017 *
3013 * wait until the controller's mailbox is available to accept more commands. 3018 * Wait until the controller's mailbox is available to accept more commands.
3014 * wait for at most 1 second 3019 * Wait for at most 1 second.
3015 */ 3020 */
3016static int 3021static int
3017megaraid_busywait_mbox(mraid_device_t *raid_dev) 3022megaraid_busywait_mbox(mraid_device_t *raid_dev)
@@ -3032,9 +3037,9 @@ megaraid_busywait_mbox(mraid_device_t *raid_dev)
3032 3037
3033/** 3038/**
3034 * megaraid_mbox_product_info - some static information about the controller 3039 * megaraid_mbox_product_info - some static information about the controller
3035 * @adapter - our soft state 3040 * @adapter : our soft state
3036 * 3041 *
3037 * issue commands to the controller to grab some parameters required by our 3042 * Issue commands to the controller to grab some parameters required by our
3038 * caller. 3043 * caller.
3039 */ 3044 */
3040static int 3045static int
@@ -3157,10 +3162,10 @@ megaraid_mbox_product_info(adapter_t *adapter)
3157 3162
3158/** 3163/**
3159 * megaraid_mbox_extended_cdb - check for support for extended CDBs 3164 * megaraid_mbox_extended_cdb - check for support for extended CDBs
3160 * @adapter - soft state for the controller 3165 * @adapter : soft state for the controller
3161 * 3166 *
3162 * this routine check whether the controller in question supports extended 3167 * This routine check whether the controller in question supports extended
3163 * ( > 10 bytes ) CDBs 3168 * ( > 10 bytes ) CDBs.
3164 */ 3169 */
3165static int 3170static int
3166megaraid_mbox_extended_cdb(adapter_t *adapter) 3171megaraid_mbox_extended_cdb(adapter_t *adapter)
@@ -3193,8 +3198,8 @@ megaraid_mbox_extended_cdb(adapter_t *adapter)
3193 3198
3194/** 3199/**
3195 * megaraid_mbox_support_ha - Do we support clustering 3200 * megaraid_mbox_support_ha - Do we support clustering
3196 * @adapter - soft state for the controller 3201 * @adapter : soft state for the controller
3197 * @init_id - ID of the initiator 3202 * @init_id : ID of the initiator
3198 * 3203 *
3199 * Determine if the firmware supports clustering and the ID of the initiator. 3204 * Determine if the firmware supports clustering and the ID of the initiator.
3200 */ 3205 */
@@ -3236,9 +3241,9 @@ megaraid_mbox_support_ha(adapter_t *adapter, uint16_t *init_id)
3236 3241
3237/** 3242/**
3238 * megaraid_mbox_support_random_del - Do we support random deletion 3243 * megaraid_mbox_support_random_del - Do we support random deletion
3239 * @adapter - soft state for the controller 3244 * @adapter : soft state for the controller
3240 * 3245 *
3241 * Determine if the firmware supports random deletion 3246 * Determine if the firmware supports random deletion.
3242 * Return: 1 is operation supported, 0 otherwise 3247 * Return: 1 is operation supported, 0 otherwise
3243 */ 3248 */
3244static int 3249static int
@@ -3271,10 +3276,10 @@ megaraid_mbox_support_random_del(adapter_t *adapter)
3271 3276
3272/** 3277/**
3273 * megaraid_mbox_get_max_sg - maximum sg elements supported by the firmware 3278 * megaraid_mbox_get_max_sg - maximum sg elements supported by the firmware
3274 * @adapter - soft state for the controller 3279 * @adapter : soft state for the controller
3275 * 3280 *
3276 * Find out the maximum number of scatter-gather elements supported by the 3281 * Find out the maximum number of scatter-gather elements supported by the
3277 * firmware 3282 * firmware.
3278 */ 3283 */
3279static int 3284static int
3280megaraid_mbox_get_max_sg(adapter_t *adapter) 3285megaraid_mbox_get_max_sg(adapter_t *adapter)
@@ -3311,10 +3316,10 @@ megaraid_mbox_get_max_sg(adapter_t *adapter)
3311 3316
3312/** 3317/**
3313 * megaraid_mbox_enum_raid_scsi - enumerate the RAID and SCSI channels 3318 * megaraid_mbox_enum_raid_scsi - enumerate the RAID and SCSI channels
3314 * @adapter - soft state for the controller 3319 * @adapter : soft state for the controller
3315 * 3320 *
3316 * Enumerate the RAID and SCSI channels for ROMB platoforms so that channels 3321 * Enumerate the RAID and SCSI channels for ROMB platforms so that channels
3317 * can be exported as regular SCSI channels 3322 * can be exported as regular SCSI channels.
3318 */ 3323 */
3319static void 3324static void
3320megaraid_mbox_enum_raid_scsi(adapter_t *adapter) 3325megaraid_mbox_enum_raid_scsi(adapter_t *adapter)
@@ -3348,9 +3353,9 @@ megaraid_mbox_enum_raid_scsi(adapter_t *adapter)
3348 3353
3349/** 3354/**
3350 * megaraid_mbox_flush_cache - flush adapter and disks cache 3355 * megaraid_mbox_flush_cache - flush adapter and disks cache
3351 * @param adapter : soft state for the controller 3356 * @adapter : soft state for the controller
3352 * 3357 *
3353 * Flush adapter cache followed by disks cache 3358 * Flush adapter cache followed by disks cache.
3354 */ 3359 */
3355static void 3360static void
3356megaraid_mbox_flush_cache(adapter_t *adapter) 3361megaraid_mbox_flush_cache(adapter_t *adapter)
@@ -3380,13 +3385,91 @@ megaraid_mbox_flush_cache(adapter_t *adapter)
3380 3385
3381 3386
3382/** 3387/**
3388 * megaraid_mbox_fire_sync_cmd - fire the sync cmd
3389 * @adapter : soft state for the controller
3390 *
3391 * Clears the pending cmds in FW and reinits its RAID structs.
3392 */
3393static int
3394megaraid_mbox_fire_sync_cmd(adapter_t *adapter)
3395{
3396 mbox_t *mbox;
3397 uint8_t raw_mbox[sizeof(mbox_t)];
3398 mraid_device_t *raid_dev = ADAP2RAIDDEV(adapter);
3399 mbox64_t *mbox64;
3400 int status = 0;
3401 int i;
3402 uint32_t dword;
3403
3404 mbox = (mbox_t *)raw_mbox;
3405
3406 memset((caddr_t)raw_mbox, 0, sizeof(mbox_t));
3407
3408 raw_mbox[0] = 0xFF;
3409
3410 mbox64 = raid_dev->mbox64;
3411 mbox = raid_dev->mbox;
3412
3413 /* Wait until mailbox is free */
3414 if (megaraid_busywait_mbox(raid_dev) != 0) {
3415 status = 1;
3416 goto blocked_mailbox;
3417 }
3418
3419 /* Copy mailbox data into host structure */
3420 memcpy((caddr_t)mbox, (caddr_t)raw_mbox, 16);
3421 mbox->cmdid = 0xFE;
3422 mbox->busy = 1;
3423 mbox->poll = 0;
3424 mbox->ack = 0;
3425 mbox->numstatus = 0;
3426 mbox->status = 0;
3427
3428 wmb();
3429 WRINDOOR(raid_dev, raid_dev->mbox_dma | 0x1);
3430
3431 /* Wait for maximum 1 min for status to post.
3432 * If the Firmware SUPPORTS the ABOVE COMMAND,
3433 * mbox->cmd will be set to 0
3434 * else
3435 * the firmware will reject the command with
3436 * mbox->numstatus set to 1
3437 */
3438
3439 i = 0;
3440 status = 0;
3441 while (!mbox->numstatus && mbox->cmd == 0xFF) {
3442 rmb();
3443 msleep(1);
3444 i++;
3445 if (i > 1000 * 60) {
3446 status = 1;
3447 break;
3448 }
3449 }
3450 if (mbox->numstatus == 1)
3451 status = 1; /*cmd not supported*/
3452
3453 /* Check for interrupt line */
3454 dword = RDOUTDOOR(raid_dev);
3455 WROUTDOOR(raid_dev, dword);
3456 WRINDOOR(raid_dev,2);
3457
3458 return status;
3459
3460blocked_mailbox:
3461 con_log(CL_ANN, (KERN_WARNING "megaraid: blocked mailbox\n"));
3462 return status;
3463}
3464
3465/**
3383 * megaraid_mbox_display_scb - display SCB information, mostly debug purposes 3466 * megaraid_mbox_display_scb - display SCB information, mostly debug purposes
3384 * @param adapter : controllers' soft state 3467 * @adapter : controller's soft state
3385 * @param scb : SCB to be displayed 3468 * @scb : SCB to be displayed
3386 * @param level : debug level for console print 3469 * @level : debug level for console print
3387 * 3470 *
3388 * Diplay information about the given SCB iff the current debug level is 3471 * Diplay information about the given SCB iff the current debug level is
3389 * verbose 3472 * verbose.
3390 */ 3473 */
3391static void 3474static void
3392megaraid_mbox_display_scb(adapter_t *adapter, scb_t *scb) 3475megaraid_mbox_display_scb(adapter_t *adapter, scb_t *scb)
@@ -3434,7 +3517,7 @@ megaraid_mbox_display_scb(adapter_t *adapter, scb_t *scb)
3434 * scsi addresses and megaraid scsi and logical drive addresses. We export 3517 * scsi addresses and megaraid scsi and logical drive addresses. We export
3435 * scsi devices on their actual addresses, whereas the logical drives are 3518 * scsi devices on their actual addresses, whereas the logical drives are
3436 * exported on a virtual scsi channel. 3519 * exported on a virtual scsi channel.
3437 **/ 3520 */
3438static void 3521static void
3439megaraid_mbox_setup_device_map(adapter_t *adapter) 3522megaraid_mbox_setup_device_map(adapter_t *adapter)
3440{ 3523{
@@ -3472,7 +3555,7 @@ megaraid_mbox_setup_device_map(adapter_t *adapter)
3472 3555
3473/** 3556/**
3474 * megaraid_cmm_register - register with the mangement module 3557 * megaraid_cmm_register - register with the mangement module
3475 * @param adapter : HBA soft state 3558 * @adapter : HBA soft state
3476 * 3559 *
3477 * Register with the management module, which allows applications to issue 3560 * Register with the management module, which allows applications to issue
3478 * ioctl calls to the drivers. This interface is used by the management module 3561 * ioctl calls to the drivers. This interface is used by the management module
@@ -3562,11 +3645,11 @@ megaraid_cmm_register(adapter_t *adapter)
3562 3645
3563/** 3646/**
3564 * megaraid_cmm_unregister - un-register with the mangement module 3647 * megaraid_cmm_unregister - un-register with the mangement module
3565 * @param adapter : HBA soft state 3648 * @adapter : HBA soft state
3566 * 3649 *
3567 * Un-register with the management module. 3650 * Un-register with the management module.
3568 * FIXME: mgmt module must return failure for unregister if it has pending 3651 * FIXME: mgmt module must return failure for unregister if it has pending
3569 * commands in LLD 3652 * commands in LLD.
3570 */ 3653 */
3571static int 3654static int
3572megaraid_cmm_unregister(adapter_t *adapter) 3655megaraid_cmm_unregister(adapter_t *adapter)
@@ -3579,9 +3662,9 @@ megaraid_cmm_unregister(adapter_t *adapter)
3579 3662
3580/** 3663/**
3581 * megaraid_mbox_mm_handler - interface for CMM to issue commands to LLD 3664 * megaraid_mbox_mm_handler - interface for CMM to issue commands to LLD
3582 * @param drvr_data : LLD specific data 3665 * @drvr_data : LLD specific data
3583 * @param kioc : CMM interface packet 3666 * @kioc : CMM interface packet
3584 * @param action : command action 3667 * @action : command action
3585 * 3668 *
3586 * This routine is invoked whenever the Common Mangement Module (CMM) has a 3669 * This routine is invoked whenever the Common Mangement Module (CMM) has a
3587 * command for us. The 'action' parameter specifies if this is a new command 3670 * command for us. The 'action' parameter specifies if this is a new command
@@ -3634,8 +3717,8 @@ megaraid_mbox_mm_handler(unsigned long drvr_data, uioc_t *kioc, uint32_t action)
3634 3717
3635/** 3718/**
3636 * megaraid_mbox_mm_command - issues commands routed through CMM 3719 * megaraid_mbox_mm_command - issues commands routed through CMM
3637 * @param adapter : HBA soft state 3720 * @adapter : HBA soft state
3638 * @param kioc : management command packet 3721 * @kioc : management command packet
3639 * 3722 *
3640 * Issues commands, which are routed through the management module. 3723 * Issues commands, which are routed through the management module.
3641 */ 3724 */
@@ -3804,8 +3887,8 @@ megaraid_mbox_mm_done(adapter_t *adapter, scb_t *scb)
3804 3887
3805/** 3888/**
3806 * gather_hbainfo - HBA characteristics for the applications 3889 * gather_hbainfo - HBA characteristics for the applications
3807 * @param adapter : HBA soft state 3890 * @adapter : HBA soft state
3808 * @param hinfo : pointer to the caller's host info strucuture 3891 * @hinfo : pointer to the caller's host info strucuture
3809 */ 3892 */
3810static int 3893static int
3811gather_hbainfo(adapter_t *adapter, mraid_hba_info_t *hinfo) 3894gather_hbainfo(adapter_t *adapter, mraid_hba_info_t *hinfo)
@@ -3839,16 +3922,15 @@ gather_hbainfo(adapter_t *adapter, mraid_hba_info_t *hinfo)
3839 3922
3840/** 3923/**
3841 * megaraid_sysfs_alloc_resources - allocate sysfs related resources 3924 * megaraid_sysfs_alloc_resources - allocate sysfs related resources
3925 * @adapter : controller's soft state
3842 * 3926 *
3843 * Allocate packets required to issue FW calls whenever the sysfs attributes 3927 * Allocate packets required to issue FW calls whenever the sysfs attributes
3844 * are read. These attributes would require up-to-date information from the 3928 * are read. These attributes would require up-to-date information from the
3845 * FW. Also set up resources for mutual exclusion to share these resources and 3929 * FW. Also set up resources for mutual exclusion to share these resources and
3846 * the wait queue. 3930 * the wait queue.
3847 * 3931 *
3848 * @param adapter : controller's soft state 3932 * Return 0 on success.
3849 * 3933 * Return -ERROR_CODE on failure.
3850 * @return 0 on success
3851 * @return -ERROR_CODE on failure
3852 */ 3934 */
3853static int 3935static int
3854megaraid_sysfs_alloc_resources(adapter_t *adapter) 3936megaraid_sysfs_alloc_resources(adapter_t *adapter)
@@ -3885,10 +3967,9 @@ megaraid_sysfs_alloc_resources(adapter_t *adapter)
3885 3967
3886/** 3968/**
3887 * megaraid_sysfs_free_resources - free sysfs related resources 3969 * megaraid_sysfs_free_resources - free sysfs related resources
3970 * @adapter : controller's soft state
3888 * 3971 *
3889 * Free packets allocated for sysfs FW commands 3972 * Free packets allocated for sysfs FW commands
3890 *
3891 * @param adapter : controller's soft state
3892 */ 3973 */
3893static void 3974static void
3894megaraid_sysfs_free_resources(adapter_t *adapter) 3975megaraid_sysfs_free_resources(adapter_t *adapter)
@@ -3907,10 +3988,9 @@ megaraid_sysfs_free_resources(adapter_t *adapter)
3907 3988
3908/** 3989/**
3909 * megaraid_sysfs_get_ldmap_done - callback for get ldmap 3990 * megaraid_sysfs_get_ldmap_done - callback for get ldmap
3991 * @uioc : completed packet
3910 * 3992 *
3911 * Callback routine called in the ISR/tasklet context for get ldmap call 3993 * Callback routine called in the ISR/tasklet context for get ldmap call
3912 *
3913 * @param uioc : completed packet
3914 */ 3994 */
3915static void 3995static void
3916megaraid_sysfs_get_ldmap_done(uioc_t *uioc) 3996megaraid_sysfs_get_ldmap_done(uioc_t *uioc)
@@ -3926,12 +4006,11 @@ megaraid_sysfs_get_ldmap_done(uioc_t *uioc)
3926 4006
3927/** 4007/**
3928 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap 4008 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap
4009 * @data : timed out packet
3929 * 4010 *
3930 * Timeout routine to recover and return to application, in case the adapter 4011 * Timeout routine to recover and return to application, in case the adapter
3931 * has stopped responding. A timeout of 60 seconds for this command seem like 4012 * has stopped responding. A timeout of 60 seconds for this command seems like
3932 * a good value 4013 * a good value.
3933 *
3934 * @param uioc : timed out packet
3935 */ 4014 */
3936static void 4015static void
3937megaraid_sysfs_get_ldmap_timeout(unsigned long data) 4016megaraid_sysfs_get_ldmap_timeout(unsigned long data)
@@ -3948,6 +4027,7 @@ megaraid_sysfs_get_ldmap_timeout(unsigned long data)
3948 4027
3949/** 4028/**
3950 * megaraid_sysfs_get_ldmap - get update logical drive map 4029 * megaraid_sysfs_get_ldmap - get update logical drive map
4030 * @adapter : controller's soft state
3951 * 4031 *
3952 * This routine will be called whenever user reads the logical drive 4032 * This routine will be called whenever user reads the logical drive
3953 * attributes, go get the current logical drive mapping table from the 4033 * attributes, go get the current logical drive mapping table from the
@@ -3959,10 +4039,8 @@ megaraid_sysfs_get_ldmap_timeout(unsigned long data)
3959 * standalone libary. For now, this should suffice since there is no other 4039 * standalone libary. For now, this should suffice since there is no other
3960 * user of this interface. 4040 * user of this interface.
3961 * 4041 *
3962 * @param adapter : controller's soft state 4042 * Return 0 on success.
3963 * 4043 * Return -1 on failure.
3964 * @return 0 on success
3965 * @return -1 on failure
3966 */ 4044 */
3967static int 4045static int
3968megaraid_sysfs_get_ldmap(adapter_t *adapter) 4046megaraid_sysfs_get_ldmap(adapter_t *adapter)
@@ -4064,13 +4142,12 @@ megaraid_sysfs_get_ldmap(adapter_t *adapter)
4064 4142
4065/** 4143/**
4066 * megaraid_sysfs_show_app_hndl - display application handle for this adapter 4144 * megaraid_sysfs_show_app_hndl - display application handle for this adapter
4145 * @cdev : class device object representation for the host
4146 * @buf : buffer to send data to
4067 * 4147 *
4068 * Display the handle used by the applications while executing management 4148 * Display the handle used by the applications while executing management
4069 * tasks on the adapter. We invoke a management module API to get the adapter 4149 * tasks on the adapter. We invoke a management module API to get the adapter
4070 * handle, since we do not interface with applications directly. 4150 * handle, since we do not interface with applications directly.
4071 *
4072 * @param cdev : class device object representation for the host
4073 * @param buf : buffer to send data to
4074 */ 4151 */
4075static ssize_t 4152static ssize_t
4076megaraid_sysfs_show_app_hndl(struct class_device *cdev, char *buf) 4153megaraid_sysfs_show_app_hndl(struct class_device *cdev, char *buf)
@@ -4087,16 +4164,18 @@ megaraid_sysfs_show_app_hndl(struct class_device *cdev, char *buf)
4087 4164
4088/** 4165/**
4089 * megaraid_sysfs_show_ldnum - display the logical drive number for this device 4166 * megaraid_sysfs_show_ldnum - display the logical drive number for this device
4167 * @dev : device object representation for the scsi device
4168 * @attr : device attribute to show
4169 * @buf : buffer to send data to
4090 * 4170 *
4091 * Display the logical drive number for the device in question, if it a valid 4171 * Display the logical drive number for the device in question, if it a valid
4092 * logical drive. For physical devices, "-1" is returned 4172 * logical drive. For physical devices, "-1" is returned.
4093 * The logical drive number is displayed in following format 4173 *
4174 * The logical drive number is displayed in following format:
4094 * 4175 *
4095 * <SCSI ID> <LD NUM> <LD STICKY ID> <APP ADAPTER HANDLE> 4176 * <SCSI ID> <LD NUM> <LD STICKY ID> <APP ADAPTER HANDLE>
4096 * <int> <int> <int> <int>
4097 * 4177 *
4098 * @param dev : device object representation for the scsi device 4178 * <int> <int> <int> <int>
4099 * @param buf : buffer to send data to
4100 */ 4179 */
4101static ssize_t 4180static ssize_t
4102megaraid_sysfs_show_ldnum(struct device *dev, struct device_attribute *attr, char *buf) 4181megaraid_sysfs_show_ldnum(struct device *dev, struct device_attribute *attr, char *buf)
diff --git a/drivers/scsi/megaraid/megaraid_mbox.h b/drivers/scsi/megaraid/megaraid_mbox.h
index 2b5a3285f79..9de803cebd4 100644
--- a/drivers/scsi/megaraid/megaraid_mbox.h
+++ b/drivers/scsi/megaraid/megaraid_mbox.h
@@ -21,8 +21,8 @@
21#include "megaraid_ioctl.h" 21#include "megaraid_ioctl.h"
22 22
23 23
24#define MEGARAID_VERSION "2.20.4.9" 24#define MEGARAID_VERSION "2.20.5.1"
25#define MEGARAID_EXT_VERSION "(Release Date: Sun Jul 16 12:27:22 EST 2006)" 25#define MEGARAID_EXT_VERSION "(Release Date: Thu Nov 16 15:32:35 EST 2006)"
26 26
27 27
28/* 28/*
@@ -146,27 +146,27 @@ typedef struct {
146 146
147/** 147/**
148 * mraid_device_t - adapter soft state structure for mailbox controllers 148 * mraid_device_t - adapter soft state structure for mailbox controllers
149 * @param una_mbox64 : 64-bit mbox - unaligned 149 * @una_mbox64 : 64-bit mbox - unaligned
150 * @param una_mbox64_dma : mbox dma addr - unaligned 150 * @una_mbox64_dma : mbox dma addr - unaligned
151 * @param mbox : 32-bit mbox - aligned 151 * @mbox : 32-bit mbox - aligned
152 * @param mbox64 : 64-bit mbox - aligned 152 * @mbox64 : 64-bit mbox - aligned
153 * @param mbox_dma : mbox dma addr - aligned 153 * @mbox_dma : mbox dma addr - aligned
154 * @param mailbox_lock : exclusion lock for the mailbox 154 * @mailbox_lock : exclusion lock for the mailbox
155 * @param baseport : base port of hba memory 155 * @baseport : base port of hba memory
156 * @param baseaddr : mapped addr of hba memory 156 * @baseaddr : mapped addr of hba memory
157 * @param mbox_pool : pool of mailboxes 157 * @mbox_pool : pool of mailboxes
158 * @param mbox_pool_handle : handle for the mailbox pool memory 158 * @mbox_pool_handle : handle for the mailbox pool memory
159 * @param epthru_pool : a pool for extended passthru commands 159 * @epthru_pool : a pool for extended passthru commands
160 * @param epthru_pool_handle : handle to the pool above 160 * @epthru_pool_handle : handle to the pool above
161 * @param sg_pool : pool of scatter-gather lists for this driver 161 * @sg_pool : pool of scatter-gather lists for this driver
162 * @param sg_pool_handle : handle to the pool above 162 * @sg_pool_handle : handle to the pool above
163 * @param ccb_list : list of our command control blocks 163 * @ccb_list : list of our command control blocks
164 * @param uccb_list : list of cmd control blocks for mgmt module 164 * @uccb_list : list of cmd control blocks for mgmt module
165 * @param umbox64 : array of mailbox for user commands (cmm) 165 * @umbox64 : array of mailbox for user commands (cmm)
166 * @param pdrv_state : array for state of each physical drive. 166 * @pdrv_state : array for state of each physical drive.
167 * @param last_disp : flag used to show device scanning 167 * @last_disp : flag used to show device scanning
168 * @param hw_error : set if FW not responding 168 * @hw_error : set if FW not responding
169 * @param fast_load : If set, skip physical device scanning 169 * @fast_load : If set, skip physical device scanning
170 * @channel_class : channel class, RAID or SCSI 170 * @channel_class : channel class, RAID or SCSI
171 * @sysfs_sem : semaphore to serialize access to sysfs res. 171 * @sysfs_sem : semaphore to serialize access to sysfs res.
172 * @sysfs_uioc : management packet to issue FW calls from sysfs 172 * @sysfs_uioc : management packet to issue FW calls from sysfs
diff --git a/drivers/scsi/megaraid/megaraid_mm.c b/drivers/scsi/megaraid/megaraid_mm.c
index d85b9a8f1b8..f33a678f089 100644
--- a/drivers/scsi/megaraid/megaraid_mm.c
+++ b/drivers/scsi/megaraid/megaraid_mm.c
@@ -67,7 +67,7 @@ static struct list_head adapters_list_g;
67 67
68static wait_queue_head_t wait_q; 68static wait_queue_head_t wait_q;
69 69
70static struct file_operations lsi_fops = { 70static const struct file_operations lsi_fops = {
71 .open = mraid_mm_open, 71 .open = mraid_mm_open,
72 .ioctl = mraid_mm_ioctl, 72 .ioctl = mraid_mm_ioctl,
73#ifdef CONFIG_COMPAT 73#ifdef CONFIG_COMPAT
@@ -78,10 +78,10 @@ static struct file_operations lsi_fops = {
78 78
79/** 79/**
80 * mraid_mm_open - open routine for char node interface 80 * mraid_mm_open - open routine for char node interface
81 * @inod : unused 81 * @inode : unused
82 * @filep : unused 82 * @filep : unused
83 * 83 *
84 * allow ioctl operations by apps only if they superuser privilege 84 * Allow ioctl operations by apps only if they have superuser privilege.
85 */ 85 */
86static int 86static int
87mraid_mm_open(struct inode *inode, struct file *filep) 87mraid_mm_open(struct inode *inode, struct file *filep)
@@ -214,7 +214,9 @@ mraid_mm_ioctl(struct inode *inode, struct file *filep, unsigned int cmd,
214/** 214/**
215 * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet 215 * mraid_mm_get_adapter - Returns corresponding adapters for the mimd packet
216 * @umimd : User space mimd_t ioctl packet 216 * @umimd : User space mimd_t ioctl packet
217 * @adapter : pointer to the adapter (OUT) 217 * @rval : returned success/error status
218 *
219 * The function return value is a pointer to the located @adapter.
218 */ 220 */
219static mraid_mmadp_t * 221static mraid_mmadp_t *
220mraid_mm_get_adapter(mimd_t __user *umimd, int *rval) 222mraid_mm_get_adapter(mimd_t __user *umimd, int *rval)
@@ -252,11 +254,11 @@ mraid_mm_get_adapter(mimd_t __user *umimd, int *rval)
252 return adapter; 254 return adapter;
253} 255}
254 256
255/* 257/**
256 * handle_drvrcmd - This routine checks if the opcode is a driver 258 * handle_drvrcmd - Checks if the opcode is a driver cmd and if it is, handles it.
257 * cmd and if it is, handles it.
258 * @arg : packet sent by the user app 259 * @arg : packet sent by the user app
259 * @old_ioctl : mimd if 1; uioc otherwise 260 * @old_ioctl : mimd if 1; uioc otherwise
261 * @rval : pointer for command's returned value (not function status)
260 */ 262 */
261static int 263static int
262handle_drvrcmd(void __user *arg, uint8_t old_ioctl, int *rval) 264handle_drvrcmd(void __user *arg, uint8_t old_ioctl, int *rval)
@@ -322,8 +324,8 @@ old_packet:
322 324
323/** 325/**
324 * mimd_to_kioc - Converter from old to new ioctl format 326 * mimd_to_kioc - Converter from old to new ioctl format
325 *
326 * @umimd : user space old MIMD IOCTL 327 * @umimd : user space old MIMD IOCTL
328 * @adp : adapter softstate
327 * @kioc : kernel space new format IOCTL 329 * @kioc : kernel space new format IOCTL
328 * 330 *
329 * Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The 331 * Routine to convert MIMD interface IOCTL to new interface IOCTL packet. The
@@ -474,7 +476,6 @@ mimd_to_kioc(mimd_t __user *umimd, mraid_mmadp_t *adp, uioc_t *kioc)
474 476
475/** 477/**
476 * mraid_mm_attch_buf - Attach a free dma buffer for required size 478 * mraid_mm_attch_buf - Attach a free dma buffer for required size
477 *
478 * @adp : Adapter softstate 479 * @adp : Adapter softstate
479 * @kioc : kioc that the buffer needs to be attached to 480 * @kioc : kioc that the buffer needs to be attached to
480 * @xferlen : required length for buffer 481 * @xferlen : required length for buffer
@@ -607,7 +608,6 @@ mraid_mm_alloc_kioc(mraid_mmadp_t *adp)
607 608
608/** 609/**
609 * mraid_mm_dealloc_kioc - Return kioc to free pool 610 * mraid_mm_dealloc_kioc - Return kioc to free pool
610 *
611 * @adp : Adapter softstate 611 * @adp : Adapter softstate
612 * @kioc : uioc_t node to be returned to free pool 612 * @kioc : uioc_t node to be returned to free pool
613 */ 613 */
@@ -652,7 +652,6 @@ mraid_mm_dealloc_kioc(mraid_mmadp_t *adp, uioc_t *kioc)
652 652
653/** 653/**
654 * lld_ioctl - Routine to issue ioctl to low level drvr 654 * lld_ioctl - Routine to issue ioctl to low level drvr
655 *
656 * @adp : The adapter handle 655 * @adp : The adapter handle
657 * @kioc : The ioctl packet with kernel addresses 656 * @kioc : The ioctl packet with kernel addresses
658 */ 657 */
@@ -705,7 +704,6 @@ lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc)
705 704
706/** 705/**
707 * ioctl_done - callback from the low level driver 706 * ioctl_done - callback from the low level driver
708 *
709 * @kioc : completed ioctl packet 707 * @kioc : completed ioctl packet
710 */ 708 */
711static void 709static void
@@ -756,9 +754,8 @@ ioctl_done(uioc_t *kioc)
756} 754}
757 755
758 756
759/* 757/**
760 * lld_timedout : callback from the expired timer 758 * lld_timedout - callback from the expired timer
761 *
762 * @ptr : ioctl packet that timed out 759 * @ptr : ioctl packet that timed out
763 */ 760 */
764static void 761static void
@@ -776,8 +773,7 @@ lld_timedout(unsigned long ptr)
776 773
777 774
778/** 775/**
779 * kioc_to_mimd : Converter from new back to old format 776 * kioc_to_mimd - Converter from new back to old format
780 *
781 * @kioc : Kernel space IOCTL packet (successfully issued) 777 * @kioc : Kernel space IOCTL packet (successfully issued)
782 * @mimd : User space MIMD packet 778 * @mimd : User space MIMD packet
783 */ 779 */
@@ -855,7 +851,6 @@ kioc_to_mimd(uioc_t *kioc, mimd_t __user *mimd)
855 851
856/** 852/**
857 * hinfo_to_cinfo - Convert new format hba info into old format 853 * hinfo_to_cinfo - Convert new format hba info into old format
858 *
859 * @hinfo : New format, more comprehensive adapter info 854 * @hinfo : New format, more comprehensive adapter info
860 * @cinfo : Old format adapter info to support mimd_t apps 855 * @cinfo : Old format adapter info to support mimd_t apps
861 */ 856 */
@@ -878,10 +873,9 @@ hinfo_to_cinfo(mraid_hba_info_t *hinfo, mcontroller_t *cinfo)
878} 873}
879 874
880 875
881/* 876/**
882 * mraid_mm_register_adp - Registration routine for low level drvrs 877 * mraid_mm_register_adp - Registration routine for low level drivers
883 * 878 * @lld_adp : Adapter objejct
884 * @adp : Adapter objejct
885 */ 879 */
886int 880int
887mraid_mm_register_adp(mraid_mmadp_t *lld_adp) 881mraid_mm_register_adp(mraid_mmadp_t *lld_adp)
@@ -1007,15 +1001,14 @@ memalloc_error:
1007 1001
1008/** 1002/**
1009 * mraid_mm_adapter_app_handle - return the application handle for this adapter 1003 * mraid_mm_adapter_app_handle - return the application handle for this adapter
1004 * @unique_id : adapter unique identifier
1010 * 1005 *
1011 * For the given driver data, locate the adadpter in our global list and 1006 * For the given driver data, locate the adapter in our global list and
1012 * return the corresponding handle, which is also used by applications to 1007 * return the corresponding handle, which is also used by applications to
1013 * uniquely identify an adapter. 1008 * uniquely identify an adapter.
1014 * 1009 *
1015 * @param unique_id : adapter unique identifier 1010 * Return adapter handle if found in the list.
1016 * 1011 * Return 0 if adapter could not be located, should never happen though.
1017 * @return adapter handle if found in the list
1018 * @return 0 if adapter could not be located, should never happen though
1019 */ 1012 */
1020uint32_t 1013uint32_t
1021mraid_mm_adapter_app_handle(uint32_t unique_id) 1014mraid_mm_adapter_app_handle(uint32_t unique_id)
@@ -1040,7 +1033,6 @@ mraid_mm_adapter_app_handle(uint32_t unique_id)
1040 1033
1041/** 1034/**
1042 * mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter 1035 * mraid_mm_setup_dma_pools - Set up dma buffer pools per adapter
1043 *
1044 * @adp : Adapter softstate 1036 * @adp : Adapter softstate
1045 * 1037 *
1046 * We maintain a pool of dma buffers per each adapter. Each pool has one 1038 * We maintain a pool of dma buffers per each adapter. Each pool has one
@@ -1093,11 +1085,11 @@ dma_pool_setup_error:
1093} 1085}
1094 1086
1095 1087
1096/* 1088/**
1097 * mraid_mm_unregister_adp - Unregister routine for low level drivers 1089 * mraid_mm_unregister_adp - Unregister routine for low level drivers
1098 * Assume no outstanding ioctls to llds.
1099 *
1100 * @unique_id : UID of the adpater 1090 * @unique_id : UID of the adpater
1091 *
1092 * Assumes no outstanding ioctls to llds.
1101 */ 1093 */
1102int 1094int
1103mraid_mm_unregister_adp(uint32_t unique_id) 1095mraid_mm_unregister_adp(uint32_t unique_id)
@@ -1131,7 +1123,6 @@ mraid_mm_unregister_adp(uint32_t unique_id)
1131 1123
1132/** 1124/**
1133 * mraid_mm_free_adp_resources - Free adapter softstate 1125 * mraid_mm_free_adp_resources - Free adapter softstate
1134 *
1135 * @adp : Adapter softstate 1126 * @adp : Adapter softstate
1136 */ 1127 */
1137static void 1128static void
@@ -1162,7 +1153,6 @@ mraid_mm_free_adp_resources(mraid_mmadp_t *adp)
1162 1153
1163/** 1154/**
1164 * mraid_mm_teardown_dma_pools - Free all per adapter dma buffers 1155 * mraid_mm_teardown_dma_pools - Free all per adapter dma buffers
1165 *
1166 * @adp : Adapter softstate 1156 * @adp : Adapter softstate
1167 */ 1157 */
1168static void 1158static void
@@ -1190,7 +1180,7 @@ mraid_mm_teardown_dma_pools(mraid_mmadp_t *adp)
1190} 1180}
1191 1181
1192/** 1182/**
1193 * mraid_mm_init : Module entry point 1183 * mraid_mm_init - Module entry point
1194 */ 1184 */
1195static int __init 1185static int __init
1196mraid_mm_init(void) 1186mraid_mm_init(void)
@@ -1214,10 +1204,13 @@ mraid_mm_init(void)
1214} 1204}
1215 1205
1216 1206
1207#ifdef CONFIG_COMPAT
1217/** 1208/**
1218 * mraid_mm_compat_ioctl : 32bit to 64bit ioctl conversion routine 1209 * mraid_mm_compat_ioctl - 32bit to 64bit ioctl conversion routine
1210 * @filep : file operations pointer (ignored)
1211 * @cmd : ioctl command
1212 * @arg : user ioctl packet
1219 */ 1213 */
1220#ifdef CONFIG_COMPAT
1221static long 1214static long
1222mraid_mm_compat_ioctl(struct file *filep, unsigned int cmd, 1215mraid_mm_compat_ioctl(struct file *filep, unsigned int cmd,
1223 unsigned long arg) 1216 unsigned long arg)
@@ -1231,7 +1224,7 @@ mraid_mm_compat_ioctl(struct file *filep, unsigned int cmd,
1231#endif 1224#endif
1232 1225
1233/** 1226/**
1234 * mraid_mm_exit : Module exit point 1227 * mraid_mm_exit - Module exit point
1235 */ 1228 */
1236static void __exit 1229static void __exit
1237mraid_mm_exit(void) 1230mraid_mm_exit(void)
diff --git a/drivers/scsi/megaraid/megaraid_sas.c b/drivers/scsi/megaraid/megaraid_sas.c
index b5bdd0d7a8b..15e24fcc84f 100644
--- a/drivers/scsi/megaraid/megaraid_sas.c
+++ b/drivers/scsi/megaraid/megaraid_sas.c
@@ -2913,7 +2913,7 @@ megasas_mgmt_compat_ioctl(struct file *file, unsigned int cmd,
2913/* 2913/*
2914 * File operations structure for management interface 2914 * File operations structure for management interface
2915 */ 2915 */
2916static struct file_operations megasas_mgmt_fops = { 2916static const struct file_operations megasas_mgmt_fops = {
2917 .owner = THIS_MODULE, 2917 .owner = THIS_MODULE,
2918 .open = megasas_mgmt_open, 2918 .open = megasas_mgmt_open,
2919 .release = megasas_mgmt_release, 2919 .release = megasas_mgmt_release,
diff --git a/drivers/scsi/megaraid/megaraid_sas.h b/drivers/scsi/megaraid/megaraid_sas.h
index 55eddcf8eb1..cacb3ad9252 100644
--- a/drivers/scsi/megaraid/megaraid_sas.h
+++ b/drivers/scsi/megaraid/megaraid_sas.h
@@ -15,7 +15,7 @@
15#ifndef LSI_MEGARAID_SAS_H 15#ifndef LSI_MEGARAID_SAS_H
16#define LSI_MEGARAID_SAS_H 16#define LSI_MEGARAID_SAS_H
17 17
18/** 18/*
19 * MegaRAID SAS Driver meta data 19 * MegaRAID SAS Driver meta data
20 */ 20 */
21#define MEGASAS_VERSION "00.00.03.05" 21#define MEGASAS_VERSION "00.00.03.05"
@@ -40,7 +40,7 @@
40 * "message frames" 40 * "message frames"
41 */ 41 */
42 42
43/** 43/*
44 * FW posts its state in upper 4 bits of outbound_msg_0 register 44 * FW posts its state in upper 4 bits of outbound_msg_0 register
45 */ 45 */
46#define MFI_STATE_MASK 0xF0000000 46#define MFI_STATE_MASK 0xF0000000
@@ -58,7 +58,7 @@
58 58
59#define MEGAMFI_FRAME_SIZE 64 59#define MEGAMFI_FRAME_SIZE 64
60 60
61/** 61/*
62 * During FW init, clear pending cmds & reset state using inbound_msg_0 62 * During FW init, clear pending cmds & reset state using inbound_msg_0
63 * 63 *
64 * ABORT : Abort all pending cmds 64 * ABORT : Abort all pending cmds
@@ -78,7 +78,7 @@
78 MFI_INIT_MFIMODE| \ 78 MFI_INIT_MFIMODE| \
79 MFI_INIT_ABORT 79 MFI_INIT_ABORT
80 80
81/** 81/*
82 * MFI frame flags 82 * MFI frame flags
83 */ 83 */
84#define MFI_FRAME_POST_IN_REPLY_QUEUE 0x0000 84#define MFI_FRAME_POST_IN_REPLY_QUEUE 0x0000
@@ -92,12 +92,12 @@
92#define MFI_FRAME_DIR_READ 0x0010 92#define MFI_FRAME_DIR_READ 0x0010
93#define MFI_FRAME_DIR_BOTH 0x0018 93#define MFI_FRAME_DIR_BOTH 0x0018
94 94
95/** 95/*
96 * Definition for cmd_status 96 * Definition for cmd_status
97 */ 97 */
98#define MFI_CMD_STATUS_POLL_MODE 0xFF 98#define MFI_CMD_STATUS_POLL_MODE 0xFF
99 99
100/** 100/*
101 * MFI command opcodes 101 * MFI command opcodes
102 */ 102 */
103#define MFI_CMD_INIT 0x00 103#define MFI_CMD_INIT 0x00
@@ -128,7 +128,7 @@
128#define MR_DCMD_CLUSTER_RESET_ALL 0x08010100 128#define MR_DCMD_CLUSTER_RESET_ALL 0x08010100
129#define MR_DCMD_CLUSTER_RESET_LD 0x08010200 129#define MR_DCMD_CLUSTER_RESET_LD 0x08010200
130 130
131/** 131/*
132 * MFI command completion codes 132 * MFI command completion codes
133 */ 133 */
134enum MFI_STAT { 134enum MFI_STAT {
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index bd6bbf61adb..9668b73872c 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -5522,7 +5522,7 @@ __setup("osst=", osst_setup);
5522 5522
5523#endif 5523#endif
5524 5524
5525static struct file_operations osst_fops = { 5525static const struct file_operations osst_fops = {
5526 .owner = THIS_MODULE, 5526 .owner = THIS_MODULE,
5527 .read = osst_read, 5527 .read = osst_read,
5528 .write = osst_write, 5528 .write = osst_write,
diff --git a/drivers/scsi/pcmcia/nsp_cs.h b/drivers/scsi/pcmcia/nsp_cs.h
index 625ca97da52..9102cbdf135 100644
--- a/drivers/scsi/pcmcia/nsp_cs.h
+++ b/drivers/scsi/pcmcia/nsp_cs.h
@@ -290,7 +290,6 @@ typedef struct _nsp_hw_data {
290#endif 290#endif
291} nsp_hw_data; 291} nsp_hw_data;
292 292
293
294/**************************************************************************** 293/****************************************************************************
295 * 294 *
296 */ 295 */
@@ -302,22 +301,13 @@ static int nsp_cs_config (struct pcmcia_device *link);
302 301
303/* Linux SCSI subsystem specific functions */ 302/* Linux SCSI subsystem specific functions */
304static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht); 303static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht);
305#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
306static int nsp_detect_old (struct scsi_host_template *sht);
307static int nsp_release_old(struct Scsi_Host *shpnt);
308#endif
309static const char *nsp_info (struct Scsi_Host *shpnt); 304static const char *nsp_info (struct Scsi_Host *shpnt);
310static int nsp_proc_info ( 305static int nsp_proc_info (
311#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,73))
312 struct Scsi_Host *host, 306 struct Scsi_Host *host,
313#endif
314 char *buffer, 307 char *buffer,
315 char **start, 308 char **start,
316 off_t offset, 309 off_t offset,
317 int length, 310 int length,
318#if !(LINUX_VERSION_CODE > KERNEL_VERSION(2,5,73))
319 int hostno,
320#endif
321 int inout); 311 int inout);
322static int nsp_queuecommand(struct scsi_cmnd *SCpnt, 312static int nsp_queuecommand(struct scsi_cmnd *SCpnt,
323 void (* done)(struct scsi_cmnd *SCpnt)); 313 void (* done)(struct scsi_cmnd *SCpnt));
@@ -356,7 +346,6 @@ static struct Scsi_Host *nsp_detect(struct scsi_host_template *sht);
356static int __init nsp_cs_init(void); 346static int __init nsp_cs_init(void);
357static void __exit nsp_cs_exit(void); 347static void __exit nsp_cs_exit(void);
358 348
359
360/* Debug */ 349/* Debug */
361#ifdef NSP_DEBUG 350#ifdef NSP_DEBUG
362static void show_command (struct scsi_cmnd *SCpnt); 351static void show_command (struct scsi_cmnd *SCpnt);
@@ -401,7 +390,6 @@ enum _burst_mode {
401 BURST_MEM32 = 2, 390 BURST_MEM32 = 2,
402}; 391};
403 392
404
405/************************************************************************** 393/**************************************************************************
406 * SCSI messaage 394 * SCSI messaage
407 */ 395 */
@@ -413,62 +401,8 @@ enum _burst_mode {
413 401
414#define MSG_EXT_SDTR 0x01 402#define MSG_EXT_SDTR 0x01
415 403
416
417/**************************************************************************
418 * Compatibility functions
419 */
420
421/* for Kernel 2.4 */
422#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
423# define scsi_register_host(template) scsi_register_module(MODULE_SCSI_HA, template)
424# define scsi_unregister_host(template) scsi_unregister_module(MODULE_SCSI_HA, template)
425# define scsi_host_put(host) scsi_unregister(host)
426
427typedef void irqreturn_t;
428# define IRQ_NONE /* */
429# define IRQ_HANDLED /* */
430# define IRQ_RETVAL(x) /* */
431
432/* This is ad-hoc version of scsi_host_get_next() */
433static inline struct Scsi_Host *scsi_host_get_next(struct Scsi_Host *host)
434{
435 if (host == NULL) {
436 return scsi_hostlist;
437 } else {
438 return host->next;
439 }
440}
441
442/* This is ad-hoc version of scsi_host_hn_get() */
443static inline struct Scsi_Host *scsi_host_hn_get(unsigned short hostno)
444{
445 struct Scsi_Host *host;
446
447 for (host = scsi_host_get_next(NULL); host != NULL;
448 host = scsi_host_get_next(host)) {
449 if (host->host_no == hostno) {
450 break;
451 }
452 }
453
454 return host;
455}
456
457static void cs_error(struct pcmcia_device *handle, int func, int ret)
458{
459 error_info_t err = { func, ret };
460 pcmcia_report_error(handle, &err);
461}
462
463/* scatter-gather table */
464# define BUFFER_ADDR (SCpnt->SCp.buffer->address)
465#endif
466
467/* for Kernel 2.6 */
468#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
469/* scatter-gather table */ 404/* scatter-gather table */
470# define BUFFER_ADDR ((char *)((unsigned int)(SCpnt->SCp.buffer->page) + SCpnt->SCp.buffer->offset)) 405# define BUFFER_ADDR ((char *)((unsigned int)(SCpnt->SCp.buffer->page) + SCpnt->SCp.buffer->offset))
471#endif
472 406
473#endif /*__nsp_cs__*/ 407#endif /*__nsp_cs__*/
474/* end */ 408/* end */
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
index 7b18a6c7b7e..8081b637d97 100644
--- a/drivers/scsi/qla2xxx/qla_attr.c
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -140,6 +140,8 @@ qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
140 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count); 140 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
141 spin_unlock_irqrestore(&ha->hardware_lock, flags); 141 spin_unlock_irqrestore(&ha->hardware_lock, flags);
142 142
143 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
144
143 return (count); 145 return (count);
144} 146}
145 147
@@ -653,6 +655,43 @@ qla2x00_beacon_store(struct class_device *cdev, const char *buf,
653 return count; 655 return count;
654} 656}
655 657
658static ssize_t
659qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
660{
661 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
662
663 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
664 ha->bios_revision[0]);
665}
666
667static ssize_t
668qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
669{
670 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
671
672 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
673 ha->efi_revision[0]);
674}
675
676static ssize_t
677qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
678{
679 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
680
681 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
682 ha->fcode_revision[0]);
683}
684
685static ssize_t
686qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
687{
688 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
689
690 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
691 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
692 ha->fw_revision[3]);
693}
694
656static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, 695static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
657 NULL); 696 NULL);
658static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL); 697static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
@@ -669,6 +708,14 @@ static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
669 qla2x00_zio_timer_store); 708 qla2x00_zio_timer_store);
670static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show, 709static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
671 qla2x00_beacon_store); 710 qla2x00_beacon_store);
711static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
712 qla2x00_optrom_bios_version_show, NULL);
713static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
714 qla2x00_optrom_efi_version_show, NULL);
715static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
716 qla2x00_optrom_fcode_version_show, NULL);
717static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
718 qla2x00_optrom_fw_version_show, NULL);
672 719
673struct class_device_attribute *qla2x00_host_attrs[] = { 720struct class_device_attribute *qla2x00_host_attrs[] = {
674 &class_device_attr_driver_version, 721 &class_device_attr_driver_version,
@@ -683,6 +730,10 @@ struct class_device_attribute *qla2x00_host_attrs[] = {
683 &class_device_attr_zio, 730 &class_device_attr_zio,
684 &class_device_attr_zio_timer, 731 &class_device_attr_zio_timer,
685 &class_device_attr_beacon, 732 &class_device_attr_beacon,
733 &class_device_attr_optrom_bios_version,
734 &class_device_attr_optrom_efi_version,
735 &class_device_attr_optrom_fcode_version,
736 &class_device_attr_optrom_fw_version,
686 NULL, 737 NULL,
687}; 738};
688 739
@@ -836,21 +887,24 @@ qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
836 link_stat_t stat_buf; 887 link_stat_t stat_buf;
837 struct fc_host_statistics *pfc_host_stat; 888 struct fc_host_statistics *pfc_host_stat;
838 889
890 rval = QLA_FUNCTION_FAILED;
839 pfc_host_stat = &ha->fc_host_stat; 891 pfc_host_stat = &ha->fc_host_stat;
840 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics)); 892 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
841 893
842 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) { 894 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
843 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf, 895 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
844 sizeof(stat_buf) / 4, mb_stat); 896 sizeof(stat_buf) / 4, mb_stat);
845 } else { 897 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
898 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
899 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
900 !ha->dpc_active) {
901 /* Must be in a 'READY' state for statistics retrieval. */
846 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf, 902 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
847 mb_stat); 903 mb_stat);
848 } 904 }
849 if (rval != 0) { 905
850 qla_printk(KERN_WARNING, ha, 906 if (rval != QLA_SUCCESS)
851 "Unable to retrieve host statistics (%d).\n", mb_stat[0]); 907 goto done;
852 return pfc_host_stat;
853 }
854 908
855 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt; 909 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
856 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt; 910 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
@@ -858,7 +912,7 @@ qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
858 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt; 912 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
859 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt; 913 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
860 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt; 914 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
861 915done:
862 return pfc_host_stat; 916 return pfc_host_stat;
863} 917}
864 918
diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
index 2c10130d9e0..05f4f2a378e 100644
--- a/drivers/scsi/qla2xxx/qla_def.h
+++ b/drivers/scsi/qla2xxx/qla_def.h
@@ -2045,6 +2045,29 @@ struct isp_operations {
2045 uint32_t, uint32_t); 2045 uint32_t, uint32_t);
2046 int (*write_optrom) (struct scsi_qla_host *, uint8_t *, uint32_t, 2046 int (*write_optrom) (struct scsi_qla_host *, uint8_t *, uint32_t,
2047 uint32_t); 2047 uint32_t);
2048
2049 int (*get_flash_version) (struct scsi_qla_host *, void *);
2050};
2051
2052/* MSI-X Support *************************************************************/
2053
2054#define QLA_MSIX_CHIP_REV_24XX 3
2055#define QLA_MSIX_FW_MODE(m) (((m) & (BIT_7|BIT_8|BIT_9)) >> 7)
2056#define QLA_MSIX_FW_MODE_1(m) (QLA_MSIX_FW_MODE(m) == 1)
2057
2058#define QLA_MSIX_DEFAULT 0x00
2059#define QLA_MSIX_RSP_Q 0x01
2060
2061#define QLA_MSIX_ENTRIES 2
2062#define QLA_MIDX_DEFAULT 0
2063#define QLA_MIDX_RSP_Q 1
2064
2065struct scsi_qla_host;
2066
2067struct qla_msix_entry {
2068 int have_irq;
2069 uint16_t msix_vector;
2070 uint16_t msix_entry;
2048}; 2071};
2049 2072
2050/* 2073/*
@@ -2077,6 +2100,7 @@ typedef struct scsi_qla_host {
2077 uint32_t enable_lip_full_login :1; 2100 uint32_t enable_lip_full_login :1;
2078 uint32_t enable_target_reset :1; 2101 uint32_t enable_target_reset :1;
2079 uint32_t enable_led_scheme :1; 2102 uint32_t enable_led_scheme :1;
2103 uint32_t inta_enabled :1;
2080 uint32_t msi_enabled :1; 2104 uint32_t msi_enabled :1;
2081 uint32_t msix_enabled :1; 2105 uint32_t msix_enabled :1;
2082 uint32_t disable_serdes :1; 2106 uint32_t disable_serdes :1;
@@ -2316,8 +2340,6 @@ typedef struct scsi_qla_host {
2316#define MBX_INTR_WAIT 2 2340#define MBX_INTR_WAIT 2
2317#define MBX_UPDATE_FLASH_ACTIVE 3 2341#define MBX_UPDATE_FLASH_ACTIVE 3
2318 2342
2319 spinlock_t mbx_reg_lock; /* Mbx Cmd Register Lock */
2320
2321 struct semaphore mbx_cmd_sem; /* Serialialize mbx access */ 2343 struct semaphore mbx_cmd_sem; /* Serialialize mbx access */
2322 struct semaphore mbx_intr_sem; /* Used for completion notification */ 2344 struct semaphore mbx_intr_sem; /* Used for completion notification */
2323 2345
@@ -2358,6 +2380,7 @@ typedef struct scsi_qla_host {
2358 2380
2359 uint8_t host_str[16]; 2381 uint8_t host_str[16];
2360 uint32_t pci_attr; 2382 uint32_t pci_attr;
2383 uint16_t chip_revision;
2361 2384
2362 uint16_t product_id[4]; 2385 uint16_t product_id[4];
2363 2386
@@ -2379,6 +2402,15 @@ typedef struct scsi_qla_host {
2379#define QLA_SREADING 1 2402#define QLA_SREADING 1
2380#define QLA_SWRITING 2 2403#define QLA_SWRITING 2
2381 2404
2405 /* PCI expansion ROM image information. */
2406#define ROM_CODE_TYPE_BIOS 0
2407#define ROM_CODE_TYPE_FCODE 1
2408#define ROM_CODE_TYPE_EFI 3
2409 uint8_t bios_revision[2];
2410 uint8_t efi_revision[2];
2411 uint8_t fcode_revision[16];
2412 uint32_t fw_revision[4];
2413
2382 /* Needed for BEACON */ 2414 /* Needed for BEACON */
2383 uint16_t beacon_blink_led; 2415 uint16_t beacon_blink_led;
2384 uint8_t beacon_color_state; 2416 uint8_t beacon_color_state;
@@ -2391,6 +2423,8 @@ typedef struct scsi_qla_host {
2391 uint16_t zio_mode; 2423 uint16_t zio_mode;
2392 uint16_t zio_timer; 2424 uint16_t zio_timer;
2393 struct fc_host_statistics fc_host_stat; 2425 struct fc_host_statistics fc_host_stat;
2426
2427 struct qla_msix_entry msix_entries[QLA_MSIX_ENTRIES];
2394} scsi_qla_host_t; 2428} scsi_qla_host_t;
2395 2429
2396 2430
diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
index e4dd12f4b80..74544ae4b0e 100644
--- a/drivers/scsi/qla2xxx/qla_gbl.h
+++ b/drivers/scsi/qla2xxx/qla_gbl.h
@@ -224,6 +224,9 @@ extern irqreturn_t qla24xx_intr_handler(int, void *);
224extern void qla2x00_process_response_queue(struct scsi_qla_host *); 224extern void qla2x00_process_response_queue(struct scsi_qla_host *);
225extern void qla24xx_process_response_queue(struct scsi_qla_host *); 225extern void qla24xx_process_response_queue(struct scsi_qla_host *);
226 226
227extern int qla2x00_request_irqs(scsi_qla_host_t *);
228extern void qla2x00_free_irqs(scsi_qla_host_t *);
229
227/* 230/*
228 * Global Function Prototypes in qla_sup.c source file. 231 * Global Function Prototypes in qla_sup.c source file.
229 */ 232 */
@@ -259,6 +262,9 @@ extern uint8_t *qla24xx_read_optrom_data(struct scsi_qla_host *, uint8_t *,
259extern int qla24xx_write_optrom_data(struct scsi_qla_host *, uint8_t *, 262extern int qla24xx_write_optrom_data(struct scsi_qla_host *, uint8_t *,
260 uint32_t, uint32_t); 263 uint32_t, uint32_t);
261 264
265extern int qla2x00_get_flash_version(scsi_qla_host_t *, void *);
266extern int qla24xx_get_flash_version(scsi_qla_host_t *, void *);
267
262/* 268/*
263 * Global Function Prototypes in qla_dbg.c source file. 269 * Global Function Prototypes in qla_dbg.c source file.
264 */ 270 */
diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
index b3dac26ddba..98c01cd5e1a 100644
--- a/drivers/scsi/qla2xxx/qla_init.c
+++ b/drivers/scsi/qla2xxx/qla_init.c
@@ -65,7 +65,7 @@ qla2x00_initialize_adapter(scsi_qla_host_t *ha)
65 ha->flags.reset_active = 0; 65 ha->flags.reset_active = 0;
66 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); 66 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
67 atomic_set(&ha->loop_state, LOOP_DOWN); 67 atomic_set(&ha->loop_state, LOOP_DOWN);
68 ha->device_flags = 0; 68 ha->device_flags = DFLG_NO_CABLE;
69 ha->dpc_flags = 0; 69 ha->dpc_flags = 0;
70 ha->flags.management_server_logged_in = 0; 70 ha->flags.management_server_logged_in = 0;
71 ha->marker_needed = 0; 71 ha->marker_needed = 0;
@@ -77,16 +77,23 @@ qla2x00_initialize_adapter(scsi_qla_host_t *ha)
77 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n"); 77 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
78 rval = ha->isp_ops.pci_config(ha); 78 rval = ha->isp_ops.pci_config(ha);
79 if (rval) { 79 if (rval) {
80 DEBUG2(printk("scsi(%ld): Unable to configure PCI space=n", 80 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
81 ha->host_no)); 81 ha->host_no));
82 return (rval); 82 return (rval);
83 } 83 }
84 84
85 ha->isp_ops.reset_chip(ha); 85 ha->isp_ops.reset_chip(ha);
86 86
87 ha->isp_ops.get_flash_version(ha, ha->request_ring);
88
87 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n"); 89 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
88 90
89 ha->isp_ops.nvram_config(ha); 91 rval = ha->isp_ops.nvram_config(ha);
92 if (rval) {
93 DEBUG2(printk("scsi(%ld): Unable to verify NVRAM data.\n",
94 ha->host_no));
95 return rval;
96 }
90 97
91 if (ha->flags.disable_serdes) { 98 if (ha->flags.disable_serdes) {
92 /* Mask HBA via NVRAM settings? */ 99 /* Mask HBA via NVRAM settings? */
@@ -293,6 +300,8 @@ qla24xx_pci_config(scsi_qla_host_t *ha)
293 d &= ~PCI_ROM_ADDRESS_ENABLE; 300 d &= ~PCI_ROM_ADDRESS_ENABLE;
294 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d); 301 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
295 302
303 pci_read_config_word(ha->pdev, PCI_REVISION_ID, &ha->chip_revision);
304
296 /* Get PCI bus information. */ 305 /* Get PCI bus information. */
297 spin_lock_irqsave(&ha->hardware_lock, flags); 306 spin_lock_irqsave(&ha->hardware_lock, flags);
298 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status); 307 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
@@ -1351,6 +1360,39 @@ qla2x00_configure_hba(scsi_qla_host_t *ha)
1351 return(rval); 1360 return(rval);
1352} 1361}
1353 1362
1363static inline void
1364qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1365{
1366 char *st, *en;
1367 uint16_t index;
1368
1369 if (memcmp(model, BINZERO, len) != 0) {
1370 strncpy(ha->model_number, model, len);
1371 st = en = ha->model_number;
1372 en += len - 1;
1373 while (en > st) {
1374 if (*en != 0x20 && *en != 0x00)
1375 break;
1376 *en-- = '\0';
1377 }
1378
1379 index = (ha->pdev->subsystem_device & 0xff);
1380 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1381 index < QLA_MODEL_NAMES)
1382 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1383 } else {
1384 index = (ha->pdev->subsystem_device & 0xff);
1385 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1386 index < QLA_MODEL_NAMES) {
1387 strcpy(ha->model_number,
1388 qla2x00_model_name[index * 2]);
1389 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1390 } else {
1391 strcpy(ha->model_number, def);
1392 }
1393 }
1394}
1395
1354/* 1396/*
1355* NVRAM configuration for ISP 2xxx 1397* NVRAM configuration for ISP 2xxx
1356* 1398*
@@ -1367,7 +1409,6 @@ qla2x00_configure_hba(scsi_qla_host_t *ha)
1367int 1409int
1368qla2x00_nvram_config(scsi_qla_host_t *ha) 1410qla2x00_nvram_config(scsi_qla_host_t *ha)
1369{ 1411{
1370 int rval;
1371 uint8_t chksum = 0; 1412 uint8_t chksum = 0;
1372 uint16_t cnt; 1413 uint16_t cnt;
1373 uint8_t *dptr1, *dptr2; 1414 uint8_t *dptr1, *dptr2;
@@ -1376,8 +1417,6 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
1376 uint8_t *ptr = (uint8_t *)ha->request_ring; 1417 uint8_t *ptr = (uint8_t *)ha->request_ring;
1377 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; 1418 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1378 1419
1379 rval = QLA_SUCCESS;
1380
1381 /* Determine NVRAM starting address. */ 1420 /* Determine NVRAM starting address. */
1382 ha->nvram_size = sizeof(nvram_t); 1421 ha->nvram_size = sizeof(nvram_t);
1383 ha->nvram_base = 0; 1422 ha->nvram_base = 0;
@@ -1401,55 +1440,7 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
1401 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " 1440 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1402 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], 1441 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1403 nv->nvram_version); 1442 nv->nvram_version);
1404 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " 1443 return QLA_FUNCTION_FAILED;
1405 "invalid -- WWPN) defaults.\n");
1406
1407 /*
1408 * Set default initialization control block.
1409 */
1410 memset(nv, 0, ha->nvram_size);
1411 nv->parameter_block_version = ICB_VERSION;
1412
1413 if (IS_QLA23XX(ha)) {
1414 nv->firmware_options[0] = BIT_2 | BIT_1;
1415 nv->firmware_options[1] = BIT_7 | BIT_5;
1416 nv->add_firmware_options[0] = BIT_5;
1417 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1418 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1419 nv->special_options[1] = BIT_7;
1420 } else if (IS_QLA2200(ha)) {
1421 nv->firmware_options[0] = BIT_2 | BIT_1;
1422 nv->firmware_options[1] = BIT_7 | BIT_5;
1423 nv->add_firmware_options[0] = BIT_5;
1424 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1425 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1426 } else if (IS_QLA2100(ha)) {
1427 nv->firmware_options[0] = BIT_3 | BIT_1;
1428 nv->firmware_options[1] = BIT_5;
1429 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1430 }
1431
1432 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1433 nv->execution_throttle = __constant_cpu_to_le16(16);
1434 nv->retry_count = 8;
1435 nv->retry_delay = 1;
1436
1437 nv->port_name[0] = 33;
1438 nv->port_name[3] = 224;
1439 nv->port_name[4] = 139;
1440
1441 nv->login_timeout = 4;
1442
1443 /*
1444 * Set default host adapter parameters
1445 */
1446 nv->host_p[1] = BIT_2;
1447 nv->reset_delay = 5;
1448 nv->port_down_retry_count = 8;
1449 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1450 nv->link_down_timeout = 60;
1451
1452 rval = 1;
1453 } 1444 }
1454 1445
1455#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) 1446#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
@@ -1489,33 +1480,8 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
1489 strcpy(ha->model_number, "QLA2300"); 1480 strcpy(ha->model_number, "QLA2300");
1490 } 1481 }
1491 } else { 1482 } else {
1492 if (rval == 0 && 1483 qla2x00_set_model_info(ha, nv->model_number,
1493 memcmp(nv->model_number, BINZERO, 1484 sizeof(nv->model_number), "QLA23xx");
1494 sizeof(nv->model_number)) != 0) {
1495 char *st, *en;
1496
1497 strncpy(ha->model_number, nv->model_number,
1498 sizeof(nv->model_number));
1499 st = en = ha->model_number;
1500 en += sizeof(nv->model_number) - 1;
1501 while (en > st) {
1502 if (*en != 0x20 && *en != 0x00)
1503 break;
1504 *en-- = '\0';
1505 }
1506 } else {
1507 uint16_t index;
1508
1509 index = (ha->pdev->subsystem_device & 0xff);
1510 if (index < QLA_MODEL_NAMES) {
1511 strcpy(ha->model_number,
1512 qla2x00_model_name[index * 2]);
1513 ha->model_desc =
1514 qla2x00_model_name[index * 2 + 1];
1515 } else {
1516 strcpy(ha->model_number, "QLA23xx");
1517 }
1518 }
1519 } 1485 }
1520 } else if (IS_QLA2200(ha)) { 1486 } else if (IS_QLA2200(ha)) {
1521 nv->firmware_options[0] |= BIT_2; 1487 nv->firmware_options[0] |= BIT_2;
@@ -1687,11 +1653,7 @@ qla2x00_nvram_config(scsi_qla_host_t *ha)
1687 } 1653 }
1688 } 1654 }
1689 1655
1690 if (rval) { 1656 return QLA_SUCCESS;
1691 DEBUG2_3(printk(KERN_WARNING
1692 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1693 }
1694 return (rval);
1695} 1657}
1696 1658
1697static void 1659static void
@@ -3107,7 +3069,11 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
3107 } 3069 }
3108 spin_unlock_irqrestore(&ha->hardware_lock, flags); 3070 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3109 3071
3110 ha->isp_ops.nvram_config(ha); 3072 ha->isp_ops.get_flash_version(ha, ha->request_ring);
3073
3074 rval = ha->isp_ops.nvram_config(ha);
3075 if (rval)
3076 goto isp_abort_retry;
3111 3077
3112 if (!qla2x00_restart_isp(ha)) { 3078 if (!qla2x00_restart_isp(ha)) {
3113 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags); 3079 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
@@ -3137,6 +3103,7 @@ qla2x00_abort_isp(scsi_qla_host_t *ha)
3137 } 3103 }
3138 } 3104 }
3139 } else { /* failed the ISP abort */ 3105 } else { /* failed the ISP abort */
3106isp_abort_retry:
3140 ha->flags.online = 1; 3107 ha->flags.online = 1;
3141 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) { 3108 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3142 if (ha->isp_abort_cnt == 0) { 3109 if (ha->isp_abort_cnt == 0) {
@@ -3326,7 +3293,6 @@ qla24xx_reset_adapter(scsi_qla_host_t *ha)
3326int 3293int
3327qla24xx_nvram_config(scsi_qla_host_t *ha) 3294qla24xx_nvram_config(scsi_qla_host_t *ha)
3328{ 3295{
3329 int rval;
3330 struct init_cb_24xx *icb; 3296 struct init_cb_24xx *icb;
3331 struct nvram_24xx *nv; 3297 struct nvram_24xx *nv;
3332 uint32_t *dptr; 3298 uint32_t *dptr;
@@ -3334,7 +3300,6 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3334 uint32_t chksum; 3300 uint32_t chksum;
3335 uint16_t cnt; 3301 uint16_t cnt;
3336 3302
3337 rval = QLA_SUCCESS;
3338 icb = (struct init_cb_24xx *)ha->init_cb; 3303 icb = (struct init_cb_24xx *)ha->init_cb;
3339 nv = (struct nvram_24xx *)ha->request_ring; 3304 nv = (struct nvram_24xx *)ha->request_ring;
3340 3305
@@ -3367,51 +3332,7 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3367 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " 3332 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3368 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], 3333 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3369 le16_to_cpu(nv->nvram_version)); 3334 le16_to_cpu(nv->nvram_version));
3370 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " 3335 return QLA_FUNCTION_FAILED;
3371 "invalid -- WWPN) defaults.\n");
3372
3373 /*
3374 * Set default initialization control block.
3375 */
3376 memset(nv, 0, ha->nvram_size);
3377 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3378 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3379 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3380 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3381 nv->exchange_count = __constant_cpu_to_le16(0);
3382 nv->hard_address = __constant_cpu_to_le16(124);
3383 nv->port_name[0] = 0x21;
3384 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3385 nv->port_name[2] = 0x00;
3386 nv->port_name[3] = 0xe0;
3387 nv->port_name[4] = 0x8b;
3388 nv->port_name[5] = 0x1c;
3389 nv->port_name[6] = 0x55;
3390 nv->port_name[7] = 0x86;
3391 nv->node_name[0] = 0x20;
3392 nv->node_name[1] = 0x00;
3393 nv->node_name[2] = 0x00;
3394 nv->node_name[3] = 0xe0;
3395 nv->node_name[4] = 0x8b;
3396 nv->node_name[5] = 0x1c;
3397 nv->node_name[6] = 0x55;
3398 nv->node_name[7] = 0x86;
3399 nv->login_retry_count = __constant_cpu_to_le16(8);
3400 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3401 nv->login_timeout = __constant_cpu_to_le16(0);
3402 nv->firmware_options_1 =
3403 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3404 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3405 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3406 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3407 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3408 nv->efi_parameters = __constant_cpu_to_le32(0);
3409 nv->reset_delay = 5;
3410 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3411 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3412 nv->link_down_timeout = __constant_cpu_to_le16(30);
3413
3414 rval = 1;
3415 } 3336 }
3416 3337
3417 /* Reset Initialization control block */ 3338 /* Reset Initialization control block */
@@ -3438,25 +3359,8 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3438 /* 3359 /*
3439 * Setup driver NVRAM options. 3360 * Setup driver NVRAM options.
3440 */ 3361 */
3441 if (memcmp(nv->model_name, BINZERO, sizeof(nv->model_name)) != 0) { 3362 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3442 char *st, *en; 3363 "QLA2462");
3443 uint16_t index;
3444
3445 strncpy(ha->model_number, nv->model_name,
3446 sizeof(nv->model_name));
3447 st = en = ha->model_number;
3448 en += sizeof(nv->model_name) - 1;
3449 while (en > st) {
3450 if (*en != 0x20 && *en != 0x00)
3451 break;
3452 *en-- = '\0';
3453 }
3454
3455 index = (ha->pdev->subsystem_device & 0xff);
3456 if (index < QLA_MODEL_NAMES)
3457 ha->model_desc = qla2x00_model_name[index * 2 + 1];
3458 } else
3459 strcpy(ha->model_number, "QLA2462");
3460 3364
3461 /* Use alternate WWN? */ 3365 /* Use alternate WWN? */
3462 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { 3366 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
@@ -3575,11 +3479,7 @@ qla24xx_nvram_config(scsi_qla_host_t *ha)
3575 ha->flags.process_response_queue = 1; 3479 ha->flags.process_response_queue = 1;
3576 } 3480 }
3577 3481
3578 if (rval) { 3482 return QLA_SUCCESS;
3579 DEBUG2_3(printk(KERN_WARNING
3580 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3581 }
3582 return (rval);
3583} 3483}
3584 3484
3585static int 3485static int
diff --git a/drivers/scsi/qla2xxx/qla_isr.c b/drivers/scsi/qla2xxx/qla_isr.c
index 39fd17b05be..d4885616cd3 100644
--- a/drivers/scsi/qla2xxx/qla_isr.c
+++ b/drivers/scsi/qla2xxx/qla_isr.c
@@ -86,12 +86,8 @@ qla2100_intr_handler(int irq, void *dev_id)
86 86
87 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && 87 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
88 (status & MBX_INTERRUPT) && ha->flags.mbox_int) { 88 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
89 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
90
91 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); 89 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
92 up(&ha->mbx_intr_sem); 90 up(&ha->mbx_intr_sem);
93
94 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
95 } 91 }
96 92
97 return (IRQ_HANDLED); 93 return (IRQ_HANDLED);
@@ -199,12 +195,8 @@ qla2300_intr_handler(int irq, void *dev_id)
199 195
200 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && 196 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
201 (status & MBX_INTERRUPT) && ha->flags.mbox_int) { 197 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
202 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
203
204 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); 198 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
205 up(&ha->mbx_intr_sem); 199 up(&ha->mbx_intr_sem);
206
207 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
208 } 200 }
209 201
210 return (IRQ_HANDLED); 202 return (IRQ_HANDLED);
@@ -654,10 +646,8 @@ qla2x00_ramp_up_queue_depth(scsi_qla_host_t *ha, srb_t *sp)
654 fcport->last_queue_full + ql2xqfullrampup * HZ)) 646 fcport->last_queue_full + ql2xqfullrampup * HZ))
655 return; 647 return;
656 648
657 spin_unlock_irq(&ha->hardware_lock);
658 starget_for_each_device(sdev->sdev_target, fcport, 649 starget_for_each_device(sdev->sdev_target, fcport,
659 qla2x00_adjust_sdev_qdepth_up); 650 qla2x00_adjust_sdev_qdepth_up);
660 spin_lock_irq(&ha->hardware_lock);
661} 651}
662 652
663/** 653/**
@@ -927,10 +917,8 @@ qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
927 917
928 /* Adjust queue depth for all luns on the port. */ 918 /* Adjust queue depth for all luns on the port. */
929 fcport->last_queue_full = jiffies; 919 fcport->last_queue_full = jiffies;
930 spin_unlock_irq(&ha->hardware_lock);
931 starget_for_each_device(cp->device->sdev_target, 920 starget_for_each_device(cp->device->sdev_target,
932 fcport, qla2x00_adjust_sdev_qdepth_down); 921 fcport, qla2x00_adjust_sdev_qdepth_down);
933 spin_lock_irq(&ha->hardware_lock);
934 break; 922 break;
935 } 923 }
936 if (lscsi_status != SS_CHECK_CONDITION) 924 if (lscsi_status != SS_CHECK_CONDITION)
@@ -995,6 +983,22 @@ qla2x00_status_entry(scsi_qla_host_t *ha, void *pkt)
995 if (lscsi_status != 0) { 983 if (lscsi_status != 0) {
996 cp->result = DID_OK << 16 | lscsi_status; 984 cp->result = DID_OK << 16 | lscsi_status;
997 985
986 if (lscsi_status == SAM_STAT_TASK_SET_FULL) {
987 DEBUG2(printk(KERN_INFO
988 "scsi(%ld): QUEUE FULL status detected "
989 "0x%x-0x%x.\n", ha->host_no, comp_status,
990 scsi_status));
991
992 /*
993 * Adjust queue depth for all luns on the
994 * port.
995 */
996 fcport->last_queue_full = jiffies;
997 starget_for_each_device(
998 cp->device->sdev_target, fcport,
999 qla2x00_adjust_sdev_qdepth_down);
1000 break;
1001 }
998 if (lscsi_status != SS_CHECK_CONDITION) 1002 if (lscsi_status != SS_CHECK_CONDITION)
999 break; 1003 break;
1000 1004
@@ -1482,12 +1486,8 @@ qla24xx_intr_handler(int irq, void *dev_id)
1482 1486
1483 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) && 1487 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1484 (status & MBX_INTERRUPT) && ha->flags.mbox_int) { 1488 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1485 spin_lock_irqsave(&ha->mbx_reg_lock, flags);
1486
1487 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags); 1489 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1488 up(&ha->mbx_intr_sem); 1490 up(&ha->mbx_intr_sem);
1489
1490 spin_unlock_irqrestore(&ha->mbx_reg_lock, flags);
1491 } 1491 }
1492 1492
1493 return IRQ_HANDLED; 1493 return IRQ_HANDLED;
@@ -1536,3 +1536,216 @@ qla24xx_ms_entry(scsi_qla_host_t *ha, struct ct_entry_24xx *pkt)
1536 qla2x00_sp_compl(ha, sp); 1536 qla2x00_sp_compl(ha, sp);
1537} 1537}
1538 1538
1539static irqreturn_t
1540qla24xx_msix_rsp_q(int irq, void *dev_id)
1541{
1542 scsi_qla_host_t *ha;
1543 struct device_reg_24xx __iomem *reg;
1544 unsigned long flags;
1545
1546 ha = dev_id;
1547 reg = &ha->iobase->isp24;
1548
1549 spin_lock_irqsave(&ha->hardware_lock, flags);
1550
1551 qla24xx_process_response_queue(ha);
1552
1553 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1554 RD_REG_DWORD_RELAXED(&reg->hccr);
1555
1556 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1557
1558 return IRQ_HANDLED;
1559}
1560
1561static irqreturn_t
1562qla24xx_msix_default(int irq, void *dev_id)
1563{
1564 scsi_qla_host_t *ha;
1565 struct device_reg_24xx __iomem *reg;
1566 int status;
1567 unsigned long flags;
1568 unsigned long iter;
1569 uint32_t stat;
1570 uint32_t hccr;
1571 uint16_t mb[4];
1572
1573 ha = dev_id;
1574 reg = &ha->iobase->isp24;
1575 status = 0;
1576
1577 spin_lock_irqsave(&ha->hardware_lock, flags);
1578 for (iter = 50; iter--; ) {
1579 stat = RD_REG_DWORD(&reg->host_status);
1580 if (stat & HSRX_RISC_PAUSED) {
1581 hccr = RD_REG_DWORD(&reg->hccr);
1582
1583 qla_printk(KERN_INFO, ha, "RISC paused -- HCCR=%x, "
1584 "Dumping firmware!\n", hccr);
1585 ha->isp_ops.fw_dump(ha, 1);
1586 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1587 break;
1588 } else if ((stat & HSRX_RISC_INT) == 0)
1589 break;
1590
1591 switch (stat & 0xff) {
1592 case 0x1:
1593 case 0x2:
1594 case 0x10:
1595 case 0x11:
1596 qla24xx_mbx_completion(ha, MSW(stat));
1597 status |= MBX_INTERRUPT;
1598
1599 break;
1600 case 0x12:
1601 mb[0] = MSW(stat);
1602 mb[1] = RD_REG_WORD(&reg->mailbox1);
1603 mb[2] = RD_REG_WORD(&reg->mailbox2);
1604 mb[3] = RD_REG_WORD(&reg->mailbox3);
1605 qla2x00_async_event(ha, mb);
1606 break;
1607 case 0x13:
1608 qla24xx_process_response_queue(ha);
1609 break;
1610 default:
1611 DEBUG2(printk("scsi(%ld): Unrecognized interrupt type "
1612 "(%d).\n",
1613 ha->host_no, stat & 0xff));
1614 break;
1615 }
1616 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_INT);
1617 RD_REG_DWORD_RELAXED(&reg->hccr);
1618 }
1619 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1620
1621 if (test_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags) &&
1622 (status & MBX_INTERRUPT) && ha->flags.mbox_int) {
1623 set_bit(MBX_INTERRUPT, &ha->mbx_cmd_flags);
1624 up(&ha->mbx_intr_sem);
1625 }
1626
1627 return IRQ_HANDLED;
1628}
1629
1630/* Interrupt handling helpers. */
1631
1632struct qla_init_msix_entry {
1633 uint16_t entry;
1634 uint16_t index;
1635 const char *name;
1636 irqreturn_t (*handler)(int, void *);
1637};
1638
1639static struct qla_init_msix_entry imsix_entries[QLA_MSIX_ENTRIES] = {
1640 { QLA_MSIX_DEFAULT, QLA_MIDX_DEFAULT,
1641 "qla2xxx (default)", qla24xx_msix_default },
1642
1643 { QLA_MSIX_RSP_Q, QLA_MIDX_RSP_Q,
1644 "qla2xxx (rsp_q)", qla24xx_msix_rsp_q },
1645};
1646
1647static void
1648qla24xx_disable_msix(scsi_qla_host_t *ha)
1649{
1650 int i;
1651 struct qla_msix_entry *qentry;
1652
1653 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1654 qentry = &ha->msix_entries[imsix_entries[i].index];
1655 if (qentry->have_irq)
1656 free_irq(qentry->msix_vector, ha);
1657 }
1658 pci_disable_msix(ha->pdev);
1659}
1660
1661static int
1662qla24xx_enable_msix(scsi_qla_host_t *ha)
1663{
1664 int i, ret;
1665 struct msix_entry entries[QLA_MSIX_ENTRIES];
1666 struct qla_msix_entry *qentry;
1667
1668 for (i = 0; i < QLA_MSIX_ENTRIES; i++)
1669 entries[i].entry = imsix_entries[i].entry;
1670
1671 ret = pci_enable_msix(ha->pdev, entries, ARRAY_SIZE(entries));
1672 if (ret) {
1673 qla_printk(KERN_WARNING, ha,
1674 "MSI-X: Failed to enable support -- %d/%d\n",
1675 QLA_MSIX_ENTRIES, ret);
1676 goto msix_out;
1677 }
1678 ha->flags.msix_enabled = 1;
1679
1680 for (i = 0; i < QLA_MSIX_ENTRIES; i++) {
1681 qentry = &ha->msix_entries[imsix_entries[i].index];
1682 qentry->msix_vector = entries[i].vector;
1683 qentry->msix_entry = entries[i].entry;
1684 qentry->have_irq = 0;
1685 ret = request_irq(qentry->msix_vector,
1686 imsix_entries[i].handler, 0, imsix_entries[i].name, ha);
1687 if (ret) {
1688 qla_printk(KERN_WARNING, ha,
1689 "MSI-X: Unable to register handler -- %x/%d.\n",
1690 imsix_entries[i].index, ret);
1691 qla24xx_disable_msix(ha);
1692 goto msix_out;
1693 }
1694 qentry->have_irq = 1;
1695 }
1696
1697msix_out:
1698 return ret;
1699}
1700
1701int
1702qla2x00_request_irqs(scsi_qla_host_t *ha)
1703{
1704 int ret;
1705
1706 /* If possible, enable MSI-X. */
1707 if (!IS_QLA2432(ha))
1708 goto skip_msix;
1709
1710 if (ha->chip_revision < QLA_MSIX_CHIP_REV_24XX ||
1711 !QLA_MSIX_FW_MODE_1(ha->fw_attributes)) {
1712 DEBUG2(qla_printk(KERN_WARNING, ha,
1713 "MSI-X: Unsupported ISP2432 (0x%X, 0x%X).\n",
1714 ha->chip_revision, ha->fw_attributes));
1715
1716 goto skip_msix;
1717 }
1718
1719 ret = qla24xx_enable_msix(ha);
1720 if (!ret) {
1721 DEBUG2(qla_printk(KERN_INFO, ha,
1722 "MSI-X: Enabled (0x%X, 0x%X).\n", ha->chip_revision,
1723 ha->fw_attributes));
1724 return ret;
1725 }
1726 qla_printk(KERN_WARNING, ha,
1727 "MSI-X: Falling back-to INTa mode -- %d.\n", ret);
1728skip_msix:
1729 ret = request_irq(ha->pdev->irq, ha->isp_ops.intr_handler,
1730 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha);
1731 if (!ret) {
1732 ha->flags.inta_enabled = 1;
1733 ha->host->irq = ha->pdev->irq;
1734 } else {
1735 qla_printk(KERN_WARNING, ha,
1736 "Failed to reserve interrupt %d already in use.\n",
1737 ha->pdev->irq);
1738 }
1739
1740 return ret;
1741}
1742
1743void
1744qla2x00_free_irqs(scsi_qla_host_t *ha)
1745{
1746
1747 if (ha->flags.msix_enabled)
1748 qla24xx_disable_msix(ha);
1749 else if (ha->flags.inta_enabled)
1750 free_irq(ha->host->irq, ha);
1751}
diff --git a/drivers/scsi/qla2xxx/qla_mbx.c b/drivers/scsi/qla2xxx/qla_mbx.c
index 077e5789bee..83376f6ac3d 100644
--- a/drivers/scsi/qla2xxx/qla_mbx.c
+++ b/drivers/scsi/qla2xxx/qla_mbx.c
@@ -55,7 +55,6 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
55 uint16_t __iomem *optr; 55 uint16_t __iomem *optr;
56 uint32_t cnt; 56 uint32_t cnt;
57 uint32_t mboxes; 57 uint32_t mboxes;
58 unsigned long mbx_flags = 0;
59 unsigned long wait_time; 58 unsigned long wait_time;
60 59
61 rval = QLA_SUCCESS; 60 rval = QLA_SUCCESS;
@@ -81,10 +80,6 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
81 /* Save mailbox command for debug */ 80 /* Save mailbox command for debug */
82 ha->mcp = mcp; 81 ha->mcp = mcp;
83 82
84 /* Try to get mailbox register access */
85 if (!abort_active)
86 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
87
88 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n", 83 DEBUG11(printk("scsi(%ld): prepare to issue mbox cmd=0x%x.\n",
89 ha->host_no, mcp->mb[0])); 84 ha->host_no, mcp->mb[0]));
90 85
@@ -161,9 +156,6 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
161 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT); 156 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
162 spin_unlock_irqrestore(&ha->hardware_lock, flags); 157 spin_unlock_irqrestore(&ha->hardware_lock, flags);
163 158
164 if (!abort_active)
165 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
166
167 /* Wait for either the timer to expire 159 /* Wait for either the timer to expire
168 * or the mbox completion interrupt 160 * or the mbox completion interrupt
169 */ 161 */
@@ -184,8 +176,6 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
184 else 176 else
185 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT); 177 WRT_REG_WORD(&reg->isp.hccr, HCCR_SET_HOST_INT);
186 spin_unlock_irqrestore(&ha->hardware_lock, flags); 178 spin_unlock_irqrestore(&ha->hardware_lock, flags);
187 if (!abort_active)
188 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
189 179
190 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */ 180 wait_time = jiffies + mcp->tov * HZ; /* wait at most tov secs */
191 while (!ha->flags.mbox_int) { 181 while (!ha->flags.mbox_int) {
@@ -201,9 +191,6 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
201 } /* while */ 191 } /* while */
202 } 192 }
203 193
204 if (!abort_active)
205 spin_lock_irqsave(&ha->mbx_reg_lock, mbx_flags);
206
207 /* Check whether we timed out */ 194 /* Check whether we timed out */
208 if (ha->flags.mbox_int) { 195 if (ha->flags.mbox_int) {
209 uint16_t *iptr2; 196 uint16_t *iptr2;
@@ -256,9 +243,6 @@ qla2x00_mailbox_command(scsi_qla_host_t *ha, mbx_cmd_t *mcp)
256 rval = QLA_FUNCTION_TIMEOUT; 243 rval = QLA_FUNCTION_TIMEOUT;
257 } 244 }
258 245
259 if (!abort_active)
260 spin_unlock_irqrestore(&ha->mbx_reg_lock, mbx_flags);
261
262 ha->flags.mbox_busy = 0; 246 ha->flags.mbox_busy = 0;
263 247
264 /* Clean up */ 248 /* Clean up */
@@ -1713,7 +1697,7 @@ qla24xx_fabric_logout(scsi_qla_host_t *ha, uint16_t loop_id, uint8_t domain,
1713 lg->entry_count = 1; 1697 lg->entry_count = 1;
1714 lg->nport_handle = cpu_to_le16(loop_id); 1698 lg->nport_handle = cpu_to_le16(loop_id);
1715 lg->control_flags = 1699 lg->control_flags =
1716 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_EXPL_LOGO); 1700 __constant_cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO);
1717 lg->port_id[0] = al_pa; 1701 lg->port_id[0] = al_pa;
1718 lg->port_id[1] = area; 1702 lg->port_id[1] = area;
1719 lg->port_id[2] = domain; 1703 lg->port_id[2] = domain;
diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
index d6445ae841b..68f5d24b938 100644
--- a/drivers/scsi/qla2xxx/qla_os.c
+++ b/drivers/scsi/qla2xxx/qla_os.c
@@ -1485,6 +1485,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1485 ha->isp_ops.fw_dump = qla2100_fw_dump; 1485 ha->isp_ops.fw_dump = qla2100_fw_dump;
1486 ha->isp_ops.read_optrom = qla2x00_read_optrom_data; 1486 ha->isp_ops.read_optrom = qla2x00_read_optrom_data;
1487 ha->isp_ops.write_optrom = qla2x00_write_optrom_data; 1487 ha->isp_ops.write_optrom = qla2x00_write_optrom_data;
1488 ha->isp_ops.get_flash_version = qla2x00_get_flash_version;
1488 if (IS_QLA2100(ha)) { 1489 if (IS_QLA2100(ha)) {
1489 host->max_id = MAX_TARGETS_2100; 1490 host->max_id = MAX_TARGETS_2100;
1490 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100; 1491 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
@@ -1550,6 +1551,7 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1550 ha->isp_ops.beacon_on = qla24xx_beacon_on; 1551 ha->isp_ops.beacon_on = qla24xx_beacon_on;
1551 ha->isp_ops.beacon_off = qla24xx_beacon_off; 1552 ha->isp_ops.beacon_off = qla24xx_beacon_off;
1552 ha->isp_ops.beacon_blink = qla24xx_beacon_blink; 1553 ha->isp_ops.beacon_blink = qla24xx_beacon_blink;
1554 ha->isp_ops.get_flash_version = qla24xx_get_flash_version;
1553 ha->gid_list_info_size = 8; 1555 ha->gid_list_info_size = 8;
1554 ha->optrom_size = OPTROM_SIZE_24XX; 1556 ha->optrom_size = OPTROM_SIZE_24XX;
1555 } 1557 }
@@ -1564,14 +1566,6 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1564 INIT_LIST_HEAD(&ha->list); 1566 INIT_LIST_HEAD(&ha->list);
1565 INIT_LIST_HEAD(&ha->fcports); 1567 INIT_LIST_HEAD(&ha->fcports);
1566 1568
1567 /*
1568 * These locks are used to prevent more than one CPU
1569 * from modifying the queue at the same time. The
1570 * higher level "host_lock" will reduce most
1571 * contention for these locks.
1572 */
1573 spin_lock_init(&ha->mbx_reg_lock);
1574
1575 qla2x00_config_dma_addressing(ha); 1569 qla2x00_config_dma_addressing(ha);
1576 if (qla2x00_mem_alloc(ha)) { 1570 if (qla2x00_mem_alloc(ha)) {
1577 qla_printk(KERN_WARNING, ha, 1571 qla_printk(KERN_WARNING, ha,
@@ -1615,15 +1609,9 @@ qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
1615 host->max_lun = MAX_LUNS; 1609 host->max_lun = MAX_LUNS;
1616 host->transportt = qla2xxx_transport_template; 1610 host->transportt = qla2xxx_transport_template;
1617 1611
1618 ret = request_irq(pdev->irq, ha->isp_ops.intr_handler, 1612 ret = qla2x00_request_irqs(ha);
1619 IRQF_DISABLED|IRQF_SHARED, QLA2XXX_DRIVER_NAME, ha); 1613 if (ret)
1620 if (ret) {
1621 qla_printk(KERN_WARNING, ha,
1622 "Failed to reserve interrupt %d already in use.\n",
1623 pdev->irq);
1624 goto probe_failed; 1614 goto probe_failed;
1625 }
1626 host->irq = pdev->irq;
1627 1615
1628 /* Initialized the timer */ 1616 /* Initialized the timer */
1629 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL); 1617 qla2x00_start_timer(ha, qla2x00_timer, WATCH_INTERVAL);
@@ -1753,9 +1741,7 @@ qla2x00_free_device(scsi_qla_host_t *ha)
1753 1741
1754 qla2x00_mem_free(ha); 1742 qla2x00_mem_free(ha);
1755 1743
1756 /* Detach interrupts */ 1744 qla2x00_free_irqs(ha);
1757 if (ha->host->irq)
1758 free_irq(ha->host->irq, ha);
1759 1745
1760 /* release io space registers */ 1746 /* release io space registers */
1761 if (ha->iobase) 1747 if (ha->iobase)
diff --git a/drivers/scsi/qla2xxx/qla_sup.c b/drivers/scsi/qla2xxx/qla_sup.c
index 15390ad8745..ff1dd4175a7 100644
--- a/drivers/scsi/qla2xxx/qla_sup.c
+++ b/drivers/scsi/qla2xxx/qla_sup.c
@@ -611,7 +611,6 @@ qla24xx_write_flash_data(scsi_qla_host_t *ha, uint32_t *dwptr, uint32_t faddr,
611 flash_conf_to_access_addr(0x0339), 611 flash_conf_to_access_addr(0x0339),
612 (fdata & 0xff00) | ((fdata << 16) & 612 (fdata & 0xff00) | ((fdata << 16) &
613 0xff0000) | ((fdata >> 16) & 0xff)); 613 0xff0000) | ((fdata >> 16) & 0xff));
614 fdata = (faddr & sec_mask) << 2;
615 ret = qla24xx_write_flash_dword(ha, conf_addr, 614 ret = qla24xx_write_flash_dword(ha, conf_addr,
616 (fdata & 0xff00) |((fdata << 16) & 615 (fdata & 0xff00) |((fdata << 16) &
617 0xff0000) | ((fdata >> 16) & 0xff)); 616 0xff0000) | ((fdata >> 16) & 0xff));
@@ -1383,6 +1382,29 @@ qla2x00_get_flash_manufacturer(scsi_qla_host_t *ha, uint8_t *man_id,
1383 qla2x00_write_flash_byte(ha, 0x5555, 0xf0); 1382 qla2x00_write_flash_byte(ha, 0x5555, 0xf0);
1384} 1383}
1385 1384
1385static void
1386qla2x00_read_flash_data(scsi_qla_host_t *ha, uint8_t *tmp_buf, uint32_t saddr,
1387 uint32_t length)
1388{
1389 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1390 uint32_t midpoint, ilength;
1391 uint8_t data;
1392
1393 midpoint = length / 2;
1394
1395 WRT_REG_WORD(&reg->nvram, 0);
1396 RD_REG_WORD(&reg->nvram);
1397 for (ilength = 0; ilength < length; saddr++, ilength++, tmp_buf++) {
1398 if (ilength == midpoint) {
1399 WRT_REG_WORD(&reg->nvram, NVR_SELECT);
1400 RD_REG_WORD(&reg->nvram);
1401 }
1402 data = qla2x00_read_flash_byte(ha, saddr);
1403 if (saddr % 100)
1404 udelay(10);
1405 *tmp_buf = data;
1406 }
1407}
1386 1408
1387static inline void 1409static inline void
1388qla2x00_suspend_hba(struct scsi_qla_host *ha) 1410qla2x00_suspend_hba(struct scsi_qla_host *ha)
@@ -1722,3 +1744,327 @@ qla24xx_write_optrom_data(struct scsi_qla_host *ha, uint8_t *buf,
1722 1744
1723 return rval; 1745 return rval;
1724} 1746}
1747
1748/**
1749 * qla2x00_get_fcode_version() - Determine an FCODE image's version.
1750 * @ha: HA context
1751 * @pcids: Pointer to the FCODE PCI data structure
1752 *
1753 * The process of retrieving the FCODE version information is at best
1754 * described as interesting.
1755 *
1756 * Within the first 100h bytes of the image an ASCII string is present
1757 * which contains several pieces of information including the FCODE
1758 * version. Unfortunately it seems the only reliable way to retrieve
1759 * the version is by scanning for another sentinel within the string,
1760 * the FCODE build date:
1761 *
1762 * ... 2.00.02 10/17/02 ...
1763 *
1764 * Returns QLA_SUCCESS on successful retrieval of version.
1765 */
1766static void
1767qla2x00_get_fcode_version(scsi_qla_host_t *ha, uint32_t pcids)
1768{
1769 int ret = QLA_FUNCTION_FAILED;
1770 uint32_t istart, iend, iter, vend;
1771 uint8_t do_next, rbyte, *vbyte;
1772
1773 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
1774
1775 /* Skip the PCI data structure. */
1776 istart = pcids +
1777 ((qla2x00_read_flash_byte(ha, pcids + 0x0B) << 8) |
1778 qla2x00_read_flash_byte(ha, pcids + 0x0A));
1779 iend = istart + 0x100;
1780 do {
1781 /* Scan for the sentinel date string...eeewww. */
1782 do_next = 0;
1783 iter = istart;
1784 while ((iter < iend) && !do_next) {
1785 iter++;
1786 if (qla2x00_read_flash_byte(ha, iter) == '/') {
1787 if (qla2x00_read_flash_byte(ha, iter + 2) ==
1788 '/')
1789 do_next++;
1790 else if (qla2x00_read_flash_byte(ha,
1791 iter + 3) == '/')
1792 do_next++;
1793 }
1794 }
1795 if (!do_next)
1796 break;
1797
1798 /* Backtrack to previous ' ' (space). */
1799 do_next = 0;
1800 while ((iter > istart) && !do_next) {
1801 iter--;
1802 if (qla2x00_read_flash_byte(ha, iter) == ' ')
1803 do_next++;
1804 }
1805 if (!do_next)
1806 break;
1807
1808 /*
1809 * Mark end of version tag, and find previous ' ' (space) or
1810 * string length (recent FCODE images -- major hack ahead!!!).
1811 */
1812 vend = iter - 1;
1813 do_next = 0;
1814 while ((iter > istart) && !do_next) {
1815 iter--;
1816 rbyte = qla2x00_read_flash_byte(ha, iter);
1817 if (rbyte == ' ' || rbyte == 0xd || rbyte == 0x10)
1818 do_next++;
1819 }
1820 if (!do_next)
1821 break;
1822
1823 /* Mark beginning of version tag, and copy data. */
1824 iter++;
1825 if ((vend - iter) &&
1826 ((vend - iter) < sizeof(ha->fcode_revision))) {
1827 vbyte = ha->fcode_revision;
1828 while (iter <= vend) {
1829 *vbyte++ = qla2x00_read_flash_byte(ha, iter);
1830 iter++;
1831 }
1832 ret = QLA_SUCCESS;
1833 }
1834 } while (0);
1835
1836 if (ret != QLA_SUCCESS)
1837 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
1838}
1839
1840int
1841qla2x00_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
1842{
1843 int ret = QLA_SUCCESS;
1844 uint8_t code_type, last_image;
1845 uint32_t pcihdr, pcids;
1846 uint8_t *dbyte;
1847 uint16_t *dcode;
1848
1849 if (!ha->pio_address || !mbuf)
1850 return QLA_FUNCTION_FAILED;
1851
1852 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
1853 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
1854 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
1855 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
1856
1857 qla2x00_flash_enable(ha);
1858
1859 /* Begin with first PCI expansion ROM header. */
1860 pcihdr = 0;
1861 last_image = 1;
1862 do {
1863 /* Verify PCI expansion ROM header. */
1864 if (qla2x00_read_flash_byte(ha, pcihdr) != 0x55 ||
1865 qla2x00_read_flash_byte(ha, pcihdr + 0x01) != 0xaa) {
1866 /* No signature */
1867 DEBUG2(printk("scsi(%ld): No matching ROM "
1868 "signature.\n", ha->host_no));
1869 ret = QLA_FUNCTION_FAILED;
1870 break;
1871 }
1872
1873 /* Locate PCI data structure. */
1874 pcids = pcihdr +
1875 ((qla2x00_read_flash_byte(ha, pcihdr + 0x19) << 8) |
1876 qla2x00_read_flash_byte(ha, pcihdr + 0x18));
1877
1878 /* Validate signature of PCI data structure. */
1879 if (qla2x00_read_flash_byte(ha, pcids) != 'P' ||
1880 qla2x00_read_flash_byte(ha, pcids + 0x1) != 'C' ||
1881 qla2x00_read_flash_byte(ha, pcids + 0x2) != 'I' ||
1882 qla2x00_read_flash_byte(ha, pcids + 0x3) != 'R') {
1883 /* Incorrect header. */
1884 DEBUG2(printk("%s(): PCI data struct not found "
1885 "pcir_adr=%x.\n", __func__, pcids));
1886 ret = QLA_FUNCTION_FAILED;
1887 break;
1888 }
1889
1890 /* Read version */
1891 code_type = qla2x00_read_flash_byte(ha, pcids + 0x14);
1892 switch (code_type) {
1893 case ROM_CODE_TYPE_BIOS:
1894 /* Intel x86, PC-AT compatible. */
1895 ha->bios_revision[0] =
1896 qla2x00_read_flash_byte(ha, pcids + 0x12);
1897 ha->bios_revision[1] =
1898 qla2x00_read_flash_byte(ha, pcids + 0x13);
1899 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
1900 ha->bios_revision[1], ha->bios_revision[0]));
1901 break;
1902 case ROM_CODE_TYPE_FCODE:
1903 /* Open Firmware standard for PCI (FCode). */
1904 /* Eeeewww... */
1905 qla2x00_get_fcode_version(ha, pcids);
1906 break;
1907 case ROM_CODE_TYPE_EFI:
1908 /* Extensible Firmware Interface (EFI). */
1909 ha->efi_revision[0] =
1910 qla2x00_read_flash_byte(ha, pcids + 0x12);
1911 ha->efi_revision[1] =
1912 qla2x00_read_flash_byte(ha, pcids + 0x13);
1913 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
1914 ha->efi_revision[1], ha->efi_revision[0]));
1915 break;
1916 default:
1917 DEBUG2(printk("%s(): Unrecognized code type %x at "
1918 "pcids %x.\n", __func__, code_type, pcids));
1919 break;
1920 }
1921
1922 last_image = qla2x00_read_flash_byte(ha, pcids + 0x15) & BIT_7;
1923
1924 /* Locate next PCI expansion ROM. */
1925 pcihdr += ((qla2x00_read_flash_byte(ha, pcids + 0x11) << 8) |
1926 qla2x00_read_flash_byte(ha, pcids + 0x10)) * 512;
1927 } while (!last_image);
1928
1929 if (IS_QLA2322(ha)) {
1930 /* Read firmware image information. */
1931 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
1932 dbyte = mbuf;
1933 memset(dbyte, 0, 8);
1934 dcode = (uint16_t *)dbyte;
1935
1936 qla2x00_read_flash_data(ha, dbyte, FA_RISC_CODE_ADDR * 4 + 10,
1937 8);
1938 DEBUG3(printk("%s(%ld): dumping fw ver from flash:\n",
1939 __func__, ha->host_no));
1940 DEBUG3(qla2x00_dump_buffer((uint8_t *)dbyte, 8));
1941
1942 if ((dcode[0] == 0xffff && dcode[1] == 0xffff &&
1943 dcode[2] == 0xffff && dcode[3] == 0xffff) ||
1944 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
1945 dcode[3] == 0)) {
1946 DEBUG2(printk("%s(): Unrecognized fw revision at "
1947 "%x.\n", __func__, FA_RISC_CODE_ADDR * 4));
1948 } else {
1949 /* values are in big endian */
1950 ha->fw_revision[0] = dbyte[0] << 16 | dbyte[1];
1951 ha->fw_revision[1] = dbyte[2] << 16 | dbyte[3];
1952 ha->fw_revision[2] = dbyte[4] << 16 | dbyte[5];
1953 }
1954 }
1955
1956 qla2x00_flash_disable(ha);
1957
1958 return ret;
1959}
1960
1961int
1962qla24xx_get_flash_version(scsi_qla_host_t *ha, void *mbuf)
1963{
1964 int ret = QLA_SUCCESS;
1965 uint32_t pcihdr, pcids;
1966 uint32_t *dcode;
1967 uint8_t *bcode;
1968 uint8_t code_type, last_image;
1969 int i;
1970
1971 if (!mbuf)
1972 return QLA_FUNCTION_FAILED;
1973
1974 memset(ha->bios_revision, 0, sizeof(ha->bios_revision));
1975 memset(ha->efi_revision, 0, sizeof(ha->efi_revision));
1976 memset(ha->fcode_revision, 0, sizeof(ha->fcode_revision));
1977 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
1978
1979 dcode = mbuf;
1980
1981 /* Begin with first PCI expansion ROM header. */
1982 pcihdr = 0;
1983 last_image = 1;
1984 do {
1985 /* Verify PCI expansion ROM header. */
1986 qla24xx_read_flash_data(ha, dcode, pcihdr >> 2, 0x20);
1987 bcode = mbuf + (pcihdr % 4);
1988 if (bcode[0x0] != 0x55 || bcode[0x1] != 0xaa) {
1989 /* No signature */
1990 DEBUG2(printk("scsi(%ld): No matching ROM "
1991 "signature.\n", ha->host_no));
1992 ret = QLA_FUNCTION_FAILED;
1993 break;
1994 }
1995
1996 /* Locate PCI data structure. */
1997 pcids = pcihdr + ((bcode[0x19] << 8) | bcode[0x18]);
1998
1999 qla24xx_read_flash_data(ha, dcode, pcids >> 2, 0x20);
2000 bcode = mbuf + (pcihdr % 4);
2001
2002 /* Validate signature of PCI data structure. */
2003 if (bcode[0x0] != 'P' || bcode[0x1] != 'C' ||
2004 bcode[0x2] != 'I' || bcode[0x3] != 'R') {
2005 /* Incorrect header. */
2006 DEBUG2(printk("%s(): PCI data struct not found "
2007 "pcir_adr=%x.\n", __func__, pcids));
2008 ret = QLA_FUNCTION_FAILED;
2009 break;
2010 }
2011
2012 /* Read version */
2013 code_type = bcode[0x14];
2014 switch (code_type) {
2015 case ROM_CODE_TYPE_BIOS:
2016 /* Intel x86, PC-AT compatible. */
2017 ha->bios_revision[0] = bcode[0x12];
2018 ha->bios_revision[1] = bcode[0x13];
2019 DEBUG3(printk("%s(): read BIOS %d.%d.\n", __func__,
2020 ha->bios_revision[1], ha->bios_revision[0]));
2021 break;
2022 case ROM_CODE_TYPE_FCODE:
2023 /* Open Firmware standard for PCI (FCode). */
2024 ha->fcode_revision[0] = bcode[0x12];
2025 ha->fcode_revision[1] = bcode[0x13];
2026 DEBUG3(printk("%s(): read FCODE %d.%d.\n", __func__,
2027 ha->fcode_revision[1], ha->fcode_revision[0]));
2028 break;
2029 case ROM_CODE_TYPE_EFI:
2030 /* Extensible Firmware Interface (EFI). */
2031 ha->efi_revision[0] = bcode[0x12];
2032 ha->efi_revision[1] = bcode[0x13];
2033 DEBUG3(printk("%s(): read EFI %d.%d.\n", __func__,
2034 ha->efi_revision[1], ha->efi_revision[0]));
2035 break;
2036 default:
2037 DEBUG2(printk("%s(): Unrecognized code type %x at "
2038 "pcids %x.\n", __func__, code_type, pcids));
2039 break;
2040 }
2041
2042 last_image = bcode[0x15] & BIT_7;
2043
2044 /* Locate next PCI expansion ROM. */
2045 pcihdr += ((bcode[0x11] << 8) | bcode[0x10]) * 512;
2046 } while (!last_image);
2047
2048 /* Read firmware image information. */
2049 memset(ha->fw_revision, 0, sizeof(ha->fw_revision));
2050 dcode = mbuf;
2051
2052 qla24xx_read_flash_data(ha, dcode, FA_RISC_CODE_ADDR + 4, 4);
2053 for (i = 0; i < 4; i++)
2054 dcode[i] = be32_to_cpu(dcode[i]);
2055
2056 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
2057 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
2058 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
2059 dcode[3] == 0)) {
2060 DEBUG2(printk("%s(): Unrecognized fw version at %x.\n",
2061 __func__, FA_RISC_CODE_ADDR));
2062 } else {
2063 ha->fw_revision[0] = dcode[0];
2064 ha->fw_revision[1] = dcode[1];
2065 ha->fw_revision[2] = dcode[2];
2066 ha->fw_revision[3] = dcode[3];
2067 }
2068
2069 return ret;
2070}
diff --git a/drivers/scsi/qla2xxx/qla_version.h b/drivers/scsi/qla2xxx/qla_version.h
index 459e0d6bd2b..61347aee55c 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-k4" 10#define QLA2XXX_VERSION "8.01.07-k5"
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/scsi.c b/drivers/scsi/scsi.c
index 24cffd98ee6..f33e2eb9f1b 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -673,27 +673,6 @@ void __scsi_done(struct scsi_cmnd *cmd)
673} 673}
674 674
675/* 675/*
676 * Function: scsi_retry_command
677 *
678 * Purpose: Send a command back to the low level to be retried.
679 *
680 * Notes: This command is always executed in the context of the
681 * bottom half handler, or the error handler thread. Low
682 * level drivers should not become re-entrant as a result of
683 * this.
684 */
685int scsi_retry_command(struct scsi_cmnd *cmd)
686{
687 /*
688 * Zero the sense information from the last time we tried
689 * this command.
690 */
691 memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
692
693 return scsi_queue_insert(cmd, SCSI_MLQUEUE_EH_RETRY);
694}
695
696/*
697 * Function: scsi_finish_command 676 * Function: scsi_finish_command
698 * 677 *
699 * Purpose: Pass command off to upper layer for finishing of I/O 678 * Purpose: Pass command off to upper layer for finishing of I/O
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 30ee3d72c02..5adbbeedec3 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -51,10 +51,10 @@
51#include "scsi_logging.h" 51#include "scsi_logging.h"
52#include "scsi_debug.h" 52#include "scsi_debug.h"
53 53
54#define SCSI_DEBUG_VERSION "1.80" 54#define SCSI_DEBUG_VERSION "1.81"
55static const char * scsi_debug_version_date = "20061018"; 55static const char * scsi_debug_version_date = "20070104";
56 56
57/* Additional Sense Code (ASC) used */ 57/* Additional Sense Code (ASC) */
58#define NO_ADDITIONAL_SENSE 0x0 58#define NO_ADDITIONAL_SENSE 0x0
59#define LOGICAL_UNIT_NOT_READY 0x4 59#define LOGICAL_UNIT_NOT_READY 0x4
60#define UNRECOVERED_READ_ERR 0x11 60#define UNRECOVERED_READ_ERR 0x11
@@ -65,9 +65,13 @@ static const char * scsi_debug_version_date = "20061018";
65#define INVALID_FIELD_IN_PARAM_LIST 0x26 65#define INVALID_FIELD_IN_PARAM_LIST 0x26
66#define POWERON_RESET 0x29 66#define POWERON_RESET 0x29
67#define SAVING_PARAMS_UNSUP 0x39 67#define SAVING_PARAMS_UNSUP 0x39
68#define TRANSPORT_PROBLEM 0x4b
68#define THRESHOLD_EXCEEDED 0x5d 69#define THRESHOLD_EXCEEDED 0x5d
69#define LOW_POWER_COND_ON 0x5e 70#define LOW_POWER_COND_ON 0x5e
70 71
72/* Additional Sense Code Qualifier (ASCQ) */
73#define ACK_NAK_TO 0x3
74
71#define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */ 75#define SDEBUG_TAGGED_QUEUING 0 /* 0 | MSG_SIMPLE_TAG | MSG_ORDERED_TAG */
72 76
73/* Default values for driver parameters */ 77/* Default values for driver parameters */
@@ -95,15 +99,20 @@ static const char * scsi_debug_version_date = "20061018";
95#define SCSI_DEBUG_OPT_MEDIUM_ERR 2 99#define SCSI_DEBUG_OPT_MEDIUM_ERR 2
96#define SCSI_DEBUG_OPT_TIMEOUT 4 100#define SCSI_DEBUG_OPT_TIMEOUT 4
97#define SCSI_DEBUG_OPT_RECOVERED_ERR 8 101#define SCSI_DEBUG_OPT_RECOVERED_ERR 8
102#define SCSI_DEBUG_OPT_TRANSPORT_ERR 16
98/* When "every_nth" > 0 then modulo "every_nth" commands: 103/* When "every_nth" > 0 then modulo "every_nth" commands:
99 * - a no response is simulated if SCSI_DEBUG_OPT_TIMEOUT is set 104 * - a no response is simulated if SCSI_DEBUG_OPT_TIMEOUT is set
100 * - a RECOVERED_ERROR is simulated on successful read and write 105 * - a RECOVERED_ERROR is simulated on successful read and write
101 * commands if SCSI_DEBUG_OPT_RECOVERED_ERR is set. 106 * commands if SCSI_DEBUG_OPT_RECOVERED_ERR is set.
107 * - a TRANSPORT_ERROR is simulated on successful read and write
108 * commands if SCSI_DEBUG_OPT_TRANSPORT_ERR is set.
102 * 109 *
103 * When "every_nth" < 0 then after "- every_nth" commands: 110 * When "every_nth" < 0 then after "- every_nth" commands:
104 * - a no response is simulated if SCSI_DEBUG_OPT_TIMEOUT is set 111 * - a no response is simulated if SCSI_DEBUG_OPT_TIMEOUT is set
105 * - a RECOVERED_ERROR is simulated on successful read and write 112 * - a RECOVERED_ERROR is simulated on successful read and write
106 * commands if SCSI_DEBUG_OPT_RECOVERED_ERR is set. 113 * commands if SCSI_DEBUG_OPT_RECOVERED_ERR is set.
114 * - a TRANSPORT_ERROR is simulated on successful read and write
115 * commands if SCSI_DEBUG_OPT_TRANSPORT_ERR is set.
107 * This will continue until some other action occurs (e.g. the user 116 * This will continue until some other action occurs (e.g. the user
108 * writing a new value (other than -1 or 1) to every_nth via sysfs). 117 * writing a new value (other than -1 or 1) to every_nth via sysfs).
109 */ 118 */
@@ -315,6 +324,7 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
315 int target = SCpnt->device->id; 324 int target = SCpnt->device->id;
316 struct sdebug_dev_info * devip = NULL; 325 struct sdebug_dev_info * devip = NULL;
317 int inj_recovered = 0; 326 int inj_recovered = 0;
327 int inj_transport = 0;
318 int delay_override = 0; 328 int delay_override = 0;
319 329
320 if (done == NULL) 330 if (done == NULL)
@@ -352,6 +362,8 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
352 return 0; /* ignore command causing timeout */ 362 return 0; /* ignore command causing timeout */
353 else if (SCSI_DEBUG_OPT_RECOVERED_ERR & scsi_debug_opts) 363 else if (SCSI_DEBUG_OPT_RECOVERED_ERR & scsi_debug_opts)
354 inj_recovered = 1; /* to reads and writes below */ 364 inj_recovered = 1; /* to reads and writes below */
365 else if (SCSI_DEBUG_OPT_TRANSPORT_ERR & scsi_debug_opts)
366 inj_transport = 1; /* to reads and writes below */
355 } 367 }
356 368
357 if (devip->wlun) { 369 if (devip->wlun) {
@@ -468,7 +480,11 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
468 mk_sense_buffer(devip, RECOVERED_ERROR, 480 mk_sense_buffer(devip, RECOVERED_ERROR,
469 THRESHOLD_EXCEEDED, 0); 481 THRESHOLD_EXCEEDED, 0);
470 errsts = check_condition_result; 482 errsts = check_condition_result;
471 } 483 } else if (inj_transport && (0 == errsts)) {
484 mk_sense_buffer(devip, ABORTED_COMMAND,
485 TRANSPORT_PROBLEM, ACK_NAK_TO);
486 errsts = check_condition_result;
487 }
472 break; 488 break;
473 case REPORT_LUNS: /* mandatory, ignore unit attention */ 489 case REPORT_LUNS: /* mandatory, ignore unit attention */
474 delay_override = 1; 490 delay_override = 1;
@@ -531,6 +547,9 @@ int scsi_debug_queuecommand(struct scsi_cmnd * SCpnt, done_funct_t done)
531 delay_override = 1; 547 delay_override = 1;
532 errsts = check_readiness(SCpnt, 0, devip); 548 errsts = check_readiness(SCpnt, 0, devip);
533 break; 549 break;
550 case WRITE_BUFFER:
551 errsts = check_readiness(SCpnt, 1, devip);
552 break;
534 default: 553 default:
535 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts) 554 if (SCSI_DEBUG_OPT_NOISE & scsi_debug_opts)
536 printk(KERN_INFO "scsi_debug: Opcode: 0x%x not " 555 printk(KERN_INFO "scsi_debug: Opcode: 0x%x not "
@@ -954,7 +973,9 @@ static int resp_inquiry(struct scsi_cmnd * scp, int target,
954 int alloc_len, n, ret; 973 int alloc_len, n, ret;
955 974
956 alloc_len = (cmd[3] << 8) + cmd[4]; 975 alloc_len = (cmd[3] << 8) + cmd[4];
957 arr = kzalloc(SDEBUG_MAX_INQ_ARR_SZ, GFP_KERNEL); 976 arr = kzalloc(SDEBUG_MAX_INQ_ARR_SZ, GFP_ATOMIC);
977 if (! arr)
978 return DID_REQUEUE << 16;
958 if (devip->wlun) 979 if (devip->wlun)
959 pq_pdt = 0x1e; /* present, wlun */ 980 pq_pdt = 0x1e; /* present, wlun */
960 else if (scsi_debug_no_lun_0 && (0 == devip->lun)) 981 else if (scsi_debug_no_lun_0 && (0 == devip->lun))
@@ -1217,7 +1238,9 @@ static int resp_report_tgtpgs(struct scsi_cmnd * scp,
1217 alen = ((cmd[6] << 24) + (cmd[7] << 16) + (cmd[8] << 8) 1238 alen = ((cmd[6] << 24) + (cmd[7] << 16) + (cmd[8] << 8)
1218 + cmd[9]); 1239 + cmd[9]);
1219 1240
1220 arr = kzalloc(SDEBUG_MAX_TGTPGS_ARR_SZ, GFP_KERNEL); 1241 arr = kzalloc(SDEBUG_MAX_TGTPGS_ARR_SZ, GFP_ATOMIC);
1242 if (! arr)
1243 return DID_REQUEUE << 16;
1221 /* 1244 /*
1222 * EVPD page 0x88 states we have two ports, one 1245 * EVPD page 0x88 states we have two ports, one
1223 * real and a fake port with no device connected. 1246 * real and a fake port with no device connected.
@@ -1996,6 +2019,8 @@ static int scsi_debug_slave_configure(struct scsi_device * sdp)
1996 if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN) 2019 if (sdp->host->max_cmd_len != SCSI_DEBUG_MAX_CMD_LEN)
1997 sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN; 2020 sdp->host->max_cmd_len = SCSI_DEBUG_MAX_CMD_LEN;
1998 devip = devInfoReg(sdp); 2021 devip = devInfoReg(sdp);
2022 if (NULL == devip)
2023 return 1; /* no resources, will be marked offline */
1999 sdp->hostdata = devip; 2024 sdp->hostdata = devip;
2000 if (sdp->host->cmd_per_lun) 2025 if (sdp->host->cmd_per_lun)
2001 scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING, 2026 scsi_adjust_queue_depth(sdp, SDEBUG_TAGGED_QUEUING,
@@ -2044,7 +2069,7 @@ static struct sdebug_dev_info * devInfoReg(struct scsi_device * sdev)
2044 } 2069 }
2045 } 2070 }
2046 if (NULL == open_devip) { /* try and make a new one */ 2071 if (NULL == open_devip) { /* try and make a new one */
2047 open_devip = kzalloc(sizeof(*open_devip),GFP_KERNEL); 2072 open_devip = kzalloc(sizeof(*open_devip),GFP_ATOMIC);
2048 if (NULL == open_devip) { 2073 if (NULL == open_devip) {
2049 printk(KERN_ERR "%s: out of memory at line %d\n", 2074 printk(KERN_ERR "%s: out of memory at line %d\n",
2050 __FUNCTION__, __LINE__); 2075 __FUNCTION__, __LINE__);
@@ -2388,7 +2413,7 @@ MODULE_PARM_DESC(max_luns, "number of LUNs per target to simulate(def=1)");
2388MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)"); 2413MODULE_PARM_DESC(no_lun_0, "no LU number 0 (def=0 -> have lun 0)");
2389MODULE_PARM_DESC(num_parts, "number of partitions(def=0)"); 2414MODULE_PARM_DESC(num_parts, "number of partitions(def=0)");
2390MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)"); 2415MODULE_PARM_DESC(num_tgts, "number of targets per host to simulate(def=1)");
2391MODULE_PARM_DESC(opts, "1->noise, 2->medium_error, 4->... (def=0)"); 2416MODULE_PARM_DESC(opts, "1->noise, 2->medium_err, 4->timeout, 8->recovered_err... (def=0)");
2392MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])"); 2417MODULE_PARM_DESC(ptype, "SCSI peripheral type(def=0[disk])");
2393MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])"); 2418MODULE_PARM_DESC(scsi_level, "SCSI level to simulate(def=5[SPC-3])");
2394MODULE_PARM_DESC(virtual_gb, "virtual gigabyte size (def=0 -> use dev_size_mb)"); 2419MODULE_PARM_DESC(virtual_gb, "virtual gigabyte size (def=0 -> use dev_size_mb)");
@@ -2943,7 +2968,6 @@ static int sdebug_add_adapter(void)
2943 struct list_head *lh, *lh_sf; 2968 struct list_head *lh, *lh_sf;
2944 2969
2945 sdbg_host = kzalloc(sizeof(*sdbg_host),GFP_KERNEL); 2970 sdbg_host = kzalloc(sizeof(*sdbg_host),GFP_KERNEL);
2946
2947 if (NULL == sdbg_host) { 2971 if (NULL == sdbg_host) {
2948 printk(KERN_ERR "%s: out of memory at line %d\n", 2972 printk(KERN_ERR "%s: out of memory at line %d\n",
2949 __FUNCTION__, __LINE__); 2973 __FUNCTION__, __LINE__);
diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 2ecb6ff4244..b8edcf5b545 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -359,6 +359,11 @@ static int scsi_check_sense(struct scsi_cmnd *scmd)
359 return SUCCESS; 359 return SUCCESS;
360 360
361 case MEDIUM_ERROR: 361 case MEDIUM_ERROR:
362 if (sshdr.asc == 0x11 || /* UNRECOVERED READ ERR */
363 sshdr.asc == 0x13 || /* AMNF DATA FIELD */
364 sshdr.asc == 0x14) { /* RECORD NOT FOUND */
365 return SUCCESS;
366 }
362 return NEEDS_RETRY; 367 return NEEDS_RETRY;
363 368
364 case HARDWARE_ERROR: 369 case HARDWARE_ERROR:
@@ -453,6 +458,128 @@ static void scsi_eh_done(struct scsi_cmnd *scmd)
453} 458}
454 459
455/** 460/**
461 * scsi_try_host_reset - ask host adapter to reset itself
462 * @scmd: SCSI cmd to send hsot reset.
463 **/
464static int scsi_try_host_reset(struct scsi_cmnd *scmd)
465{
466 unsigned long flags;
467 int rtn;
468
469 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n",
470 __FUNCTION__));
471
472 if (!scmd->device->host->hostt->eh_host_reset_handler)
473 return FAILED;
474
475 rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd);
476
477 if (rtn == SUCCESS) {
478 if (!scmd->device->host->hostt->skip_settle_delay)
479 ssleep(HOST_RESET_SETTLE_TIME);
480 spin_lock_irqsave(scmd->device->host->host_lock, flags);
481 scsi_report_bus_reset(scmd->device->host,
482 scmd_channel(scmd));
483 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
484 }
485
486 return rtn;
487}
488
489/**
490 * scsi_try_bus_reset - ask host to perform a bus reset
491 * @scmd: SCSI cmd to send bus reset.
492 **/
493static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
494{
495 unsigned long flags;
496 int rtn;
497
498 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n",
499 __FUNCTION__));
500
501 if (!scmd->device->host->hostt->eh_bus_reset_handler)
502 return FAILED;
503
504 rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd);
505
506 if (rtn == SUCCESS) {
507 if (!scmd->device->host->hostt->skip_settle_delay)
508 ssleep(BUS_RESET_SETTLE_TIME);
509 spin_lock_irqsave(scmd->device->host->host_lock, flags);
510 scsi_report_bus_reset(scmd->device->host,
511 scmd_channel(scmd));
512 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
513 }
514
515 return rtn;
516}
517
518/**
519 * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
520 * @scmd: SCSI cmd used to send BDR
521 *
522 * Notes:
523 * There is no timeout for this operation. if this operation is
524 * unreliable for a given host, then the host itself needs to put a
525 * timer on it, and set the host back to a consistent state prior to
526 * returning.
527 **/
528static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
529{
530 int rtn;
531
532 if (!scmd->device->host->hostt->eh_device_reset_handler)
533 return FAILED;
534
535 rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd);
536 if (rtn == SUCCESS) {
537 scmd->device->was_reset = 1;
538 scmd->device->expecting_cc_ua = 1;
539 }
540
541 return rtn;
542}
543
544static int __scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
545{
546 if (!scmd->device->host->hostt->eh_abort_handler)
547 return FAILED;
548
549 return scmd->device->host->hostt->eh_abort_handler(scmd);
550}
551
552/**
553 * scsi_try_to_abort_cmd - Ask host to abort a running command.
554 * @scmd: SCSI cmd to abort from Lower Level.
555 *
556 * Notes:
557 * This function will not return until the user's completion function
558 * has been called. there is no timeout on this operation. if the
559 * author of the low-level driver wishes this operation to be timed,
560 * they can provide this facility themselves. helper functions in
561 * scsi_error.c can be supplied to make this easier to do.
562 **/
563static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
564{
565 /*
566 * scsi_done was called just after the command timed out and before
567 * we had a chance to process it. (db)
568 */
569 if (scmd->serial_number == 0)
570 return SUCCESS;
571 return __scsi_try_to_abort_cmd(scmd);
572}
573
574static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
575{
576 if (__scsi_try_to_abort_cmd(scmd) != SUCCESS)
577 if (scsi_try_bus_device_reset(scmd) != SUCCESS)
578 if (scsi_try_bus_reset(scmd) != SUCCESS)
579 scsi_try_host_reset(scmd);
580}
581
582/**
456 * scsi_send_eh_cmnd - submit a scsi command as part of error recory 583 * scsi_send_eh_cmnd - submit a scsi command as part of error recory
457 * @scmd: SCSI command structure to hijack 584 * @scmd: SCSI command structure to hijack
458 * @cmnd: CDB to send 585 * @cmnd: CDB to send
@@ -579,13 +706,7 @@ static int scsi_send_eh_cmnd(struct scsi_cmnd *scmd, unsigned char *cmnd,
579 break; 706 break;
580 } 707 }
581 } else { 708 } else {
582 /* 709 scsi_abort_eh_cmnd(scmd);
583 * FIXME(eric) - we are not tracking whether we could
584 * abort a timed out command or not. not sure how
585 * we should treat them differently anyways.
586 */
587 if (shost->hostt->eh_abort_handler)
588 shost->hostt->eh_abort_handler(scmd);
589 rtn = FAILED; 710 rtn = FAILED;
590 } 711 }
591 712
@@ -672,8 +793,8 @@ EXPORT_SYMBOL(scsi_eh_finish_cmd);
672 * XXX: Long term this code should go away, but that needs an audit of 793 * XXX: Long term this code should go away, but that needs an audit of
673 * all LLDDs first. 794 * all LLDDs first.
674 **/ 795 **/
675static int scsi_eh_get_sense(struct list_head *work_q, 796int scsi_eh_get_sense(struct list_head *work_q,
676 struct list_head *done_q) 797 struct list_head *done_q)
677{ 798{
678 struct scsi_cmnd *scmd, *next; 799 struct scsi_cmnd *scmd, *next;
679 int rtn; 800 int rtn;
@@ -715,31 +836,7 @@ static int scsi_eh_get_sense(struct list_head *work_q,
715 836
716 return list_empty(work_q); 837 return list_empty(work_q);
717} 838}
718 839EXPORT_SYMBOL_GPL(scsi_eh_get_sense);
719/**
720 * scsi_try_to_abort_cmd - Ask host to abort a running command.
721 * @scmd: SCSI cmd to abort from Lower Level.
722 *
723 * Notes:
724 * This function will not return until the user's completion function
725 * has been called. there is no timeout on this operation. if the
726 * author of the low-level driver wishes this operation to be timed,
727 * they can provide this facility themselves. helper functions in
728 * scsi_error.c can be supplied to make this easier to do.
729 **/
730static int scsi_try_to_abort_cmd(struct scsi_cmnd *scmd)
731{
732 if (!scmd->device->host->hostt->eh_abort_handler)
733 return FAILED;
734
735 /*
736 * scsi_done was called just after the command timed out and before
737 * we had a chance to process it. (db)
738 */
739 if (scmd->serial_number == 0)
740 return SUCCESS;
741 return scmd->device->host->hostt->eh_abort_handler(scmd);
742}
743 840
744/** 841/**
745 * scsi_eh_tur - Send TUR to device. 842 * scsi_eh_tur - Send TUR to device.
@@ -815,32 +912,6 @@ static int scsi_eh_abort_cmds(struct list_head *work_q,
815} 912}
816 913
817/** 914/**
818 * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
819 * @scmd: SCSI cmd used to send BDR
820 *
821 * Notes:
822 * There is no timeout for this operation. if this operation is
823 * unreliable for a given host, then the host itself needs to put a
824 * timer on it, and set the host back to a consistent state prior to
825 * returning.
826 **/
827static int scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
828{
829 int rtn;
830
831 if (!scmd->device->host->hostt->eh_device_reset_handler)
832 return FAILED;
833
834 rtn = scmd->device->host->hostt->eh_device_reset_handler(scmd);
835 if (rtn == SUCCESS) {
836 scmd->device->was_reset = 1;
837 scmd->device->expecting_cc_ua = 1;
838 }
839
840 return rtn;
841}
842
843/**
844 * scsi_eh_try_stu - Send START_UNIT to device. 915 * scsi_eh_try_stu - Send START_UNIT to device.
845 * @scmd: Scsi cmd to send START_UNIT 916 * @scmd: Scsi cmd to send START_UNIT
846 * 917 *
@@ -971,64 +1042,6 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
971} 1042}
972 1043
973/** 1044/**
974 * scsi_try_bus_reset - ask host to perform a bus reset
975 * @scmd: SCSI cmd to send bus reset.
976 **/
977static int scsi_try_bus_reset(struct scsi_cmnd *scmd)
978{
979 unsigned long flags;
980 int rtn;
981
982 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Bus RST\n",
983 __FUNCTION__));
984
985 if (!scmd->device->host->hostt->eh_bus_reset_handler)
986 return FAILED;
987
988 rtn = scmd->device->host->hostt->eh_bus_reset_handler(scmd);
989
990 if (rtn == SUCCESS) {
991 if (!scmd->device->host->hostt->skip_settle_delay)
992 ssleep(BUS_RESET_SETTLE_TIME);
993 spin_lock_irqsave(scmd->device->host->host_lock, flags);
994 scsi_report_bus_reset(scmd->device->host,
995 scmd_channel(scmd));
996 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
997 }
998
999 return rtn;
1000}
1001
1002/**
1003 * scsi_try_host_reset - ask host adapter to reset itself
1004 * @scmd: SCSI cmd to send hsot reset.
1005 **/
1006static int scsi_try_host_reset(struct scsi_cmnd *scmd)
1007{
1008 unsigned long flags;
1009 int rtn;
1010
1011 SCSI_LOG_ERROR_RECOVERY(3, printk("%s: Snd Host RST\n",
1012 __FUNCTION__));
1013
1014 if (!scmd->device->host->hostt->eh_host_reset_handler)
1015 return FAILED;
1016
1017 rtn = scmd->device->host->hostt->eh_host_reset_handler(scmd);
1018
1019 if (rtn == SUCCESS) {
1020 if (!scmd->device->host->hostt->skip_settle_delay)
1021 ssleep(HOST_RESET_SETTLE_TIME);
1022 spin_lock_irqsave(scmd->device->host->host_lock, flags);
1023 scsi_report_bus_reset(scmd->device->host,
1024 scmd_channel(scmd));
1025 spin_unlock_irqrestore(scmd->device->host->host_lock, flags);
1026 }
1027
1028 return rtn;
1029}
1030
1031/**
1032 * scsi_eh_bus_reset - send a bus reset 1045 * scsi_eh_bus_reset - send a bus reset
1033 * @shost: scsi host being recovered. 1046 * @shost: scsi host being recovered.
1034 * @eh_done_q: list_head for processed commands. 1047 * @eh_done_q: list_head for processed commands.
@@ -1411,9 +1424,9 @@ static void scsi_restart_operations(struct Scsi_Host *shost)
1411 * @eh_done_q: list_head for processed commands. 1424 * @eh_done_q: list_head for processed commands.
1412 * 1425 *
1413 **/ 1426 **/
1414static void scsi_eh_ready_devs(struct Scsi_Host *shost, 1427void scsi_eh_ready_devs(struct Scsi_Host *shost,
1415 struct list_head *work_q, 1428 struct list_head *work_q,
1416 struct list_head *done_q) 1429 struct list_head *done_q)
1417{ 1430{
1418 if (!scsi_eh_stu(shost, work_q, done_q)) 1431 if (!scsi_eh_stu(shost, work_q, done_q))
1419 if (!scsi_eh_bus_device_reset(shost, work_q, done_q)) 1432 if (!scsi_eh_bus_device_reset(shost, work_q, done_q))
@@ -1421,6 +1434,7 @@ static void scsi_eh_ready_devs(struct Scsi_Host *shost,
1421 if (!scsi_eh_host_reset(work_q, done_q)) 1434 if (!scsi_eh_host_reset(work_q, done_q))
1422 scsi_eh_offline_sdevs(work_q, done_q); 1435 scsi_eh_offline_sdevs(work_q, done_q);
1423} 1436}
1437EXPORT_SYMBOL_GPL(scsi_eh_ready_devs);
1424 1438
1425/** 1439/**
1426 * scsi_eh_flush_done_q - finish processed commands or retry them. 1440 * scsi_eh_flush_done_q - finish processed commands or retry them.
diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index f02f48a882a..9f7482d0b59 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -388,10 +388,9 @@ int scsi_execute_async(struct scsi_device *sdev, const unsigned char *cmd,
388 int err = 0; 388 int err = 0;
389 int write = (data_direction == DMA_TO_DEVICE); 389 int write = (data_direction == DMA_TO_DEVICE);
390 390
391 sioc = kmem_cache_alloc(scsi_io_context_cache, gfp); 391 sioc = kmem_cache_zalloc(scsi_io_context_cache, gfp);
392 if (!sioc) 392 if (!sioc)
393 return DRIVER_ERROR << 24; 393 return DRIVER_ERROR << 24;
394 memset(sioc, 0, sizeof(*sioc));
395 394
396 req = blk_get_request(sdev->request_queue, write, gfp); 395 req = blk_get_request(sdev->request_queue, write, gfp);
397 if (!req) 396 if (!req)
@@ -1400,7 +1399,7 @@ static void scsi_softirq_done(struct request *rq)
1400 scsi_finish_command(cmd); 1399 scsi_finish_command(cmd);
1401 break; 1400 break;
1402 case NEEDS_RETRY: 1401 case NEEDS_RETRY:
1403 scsi_retry_command(cmd); 1402 scsi_queue_insert(cmd, SCSI_MLQUEUE_EH_RETRY);
1404 break; 1403 break;
1405 case ADD_TO_MLQUEUE: 1404 case ADD_TO_MLQUEUE:
1406 scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY); 1405 scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
@@ -2250,6 +2249,8 @@ void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
2250 size_t sg_len = 0, len_complete = 0; 2249 size_t sg_len = 0, len_complete = 0;
2251 struct page *page; 2250 struct page *page;
2252 2251
2252 WARN_ON(!irqs_disabled());
2253
2253 for (i = 0; i < sg_count; i++) { 2254 for (i = 0; i < sg_count; i++) {
2254 len_complete = sg_len; /* Complete sg-entries */ 2255 len_complete = sg_len; /* Complete sg-entries */
2255 sg_len += sg[i].length; 2256 sg_len += sg[i].length;
diff --git a/drivers/scsi/scsi_priv.h b/drivers/scsi/scsi_priv.h
index f458c2f686d..ee8efe849bf 100644
--- a/drivers/scsi/scsi_priv.h
+++ b/drivers/scsi/scsi_priv.h
@@ -28,7 +28,6 @@ extern int scsi_dispatch_cmd(struct scsi_cmnd *cmd);
28extern int scsi_setup_command_freelist(struct Scsi_Host *shost); 28extern int scsi_setup_command_freelist(struct Scsi_Host *shost);
29extern void scsi_destroy_command_freelist(struct Scsi_Host *shost); 29extern void scsi_destroy_command_freelist(struct Scsi_Host *shost);
30extern void __scsi_done(struct scsi_cmnd *cmd); 30extern void __scsi_done(struct scsi_cmnd *cmd);
31extern int scsi_retry_command(struct scsi_cmnd *cmd);
32#ifdef CONFIG_SCSI_LOGGING 31#ifdef CONFIG_SCSI_LOGGING
33void scsi_log_send(struct scsi_cmnd *cmd); 32void scsi_log_send(struct scsi_cmnd *cmd);
34void scsi_log_completion(struct scsi_cmnd *cmd, int disposition); 33void scsi_log_completion(struct scsi_cmnd *cmd, int disposition);
@@ -58,6 +57,11 @@ extern int scsi_error_handler(void *host);
58extern int scsi_decide_disposition(struct scsi_cmnd *cmd); 57extern int scsi_decide_disposition(struct scsi_cmnd *cmd);
59extern void scsi_eh_wakeup(struct Scsi_Host *shost); 58extern void scsi_eh_wakeup(struct Scsi_Host *shost);
60extern int scsi_eh_scmd_add(struct scsi_cmnd *, int); 59extern int scsi_eh_scmd_add(struct scsi_cmnd *, int);
60void scsi_eh_ready_devs(struct Scsi_Host *shost,
61 struct list_head *work_q,
62 struct list_head *done_q);
63int scsi_eh_get_sense(struct list_head *work_q,
64 struct list_head *done_q);
61 65
62/* scsi_lib.c */ 66/* scsi_lib.c */
63extern int scsi_maybe_unblock_host(struct scsi_device *sdev); 67extern int scsi_maybe_unblock_host(struct scsi_device *sdev);
diff --git a/drivers/scsi/scsi_proc.c b/drivers/scsi/scsi_proc.c
index 524a5f7a519..69d6e9b198c 100644
--- a/drivers/scsi/scsi_proc.c
+++ b/drivers/scsi/scsi_proc.c
@@ -308,7 +308,7 @@ static int proc_scsi_open(struct inode *inode, struct file *file)
308 return single_open(file, proc_scsi_show, NULL); 308 return single_open(file, proc_scsi_show, NULL);
309} 309}
310 310
311static struct file_operations proc_scsi_operations = { 311static const struct file_operations proc_scsi_operations = {
312 .open = proc_scsi_open, 312 .open = proc_scsi_open,
313 .read = seq_read, 313 .read = seq_read,
314 .write = proc_scsi_write, 314 .write = proc_scsi_write,
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 96b7cbd746a..a43b9ec3aef 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1029,7 +1029,7 @@ static int scsi_probe_and_add_lun(struct scsi_target *starget,
1029 1029
1030 sdev_printk(KERN_INFO, sdev, 1030 sdev_printk(KERN_INFO, sdev,
1031 "scsi scan: consider passing scsi_mod." 1031 "scsi scan: consider passing scsi_mod."
1032 "dev_flags=%s:%s:0x240 or 0x800240\n", 1032 "dev_flags=%s:%s:0x240 or 0x1000240\n",
1033 scsi_inq_str(vend, result, 8, 16), 1033 scsi_inq_str(vend, result, 8, 16),
1034 scsi_inq_str(mod, result, 16, 32)); 1034 scsi_inq_str(mod, result, 16, 32));
1035 }); 1035 });
diff --git a/drivers/scsi/scsi_tgt_if.c b/drivers/scsi/scsi_tgt_if.c
index 37bbfbdb870..f2344ab8def 100644
--- a/drivers/scsi/scsi_tgt_if.c
+++ b/drivers/scsi/scsi_tgt_if.c
@@ -280,7 +280,7 @@ static int tgt_open(struct inode *inode, struct file *file)
280 return 0; 280 return 0;
281} 281}
282 282
283static struct file_operations tgt_fops = { 283static const struct file_operations tgt_fops = {
284 .owner = THIS_MODULE, 284 .owner = THIS_MODULE,
285 .open = tgt_open, 285 .open = tgt_open,
286 .poll = tgt_poll, 286 .poll = tgt_poll,
diff --git a/drivers/scsi/scsi_transport_sas.c b/drivers/scsi/scsi_transport_sas.c
index 5c0b75bbfa1..6d39150e205 100644
--- a/drivers/scsi/scsi_transport_sas.c
+++ b/drivers/scsi/scsi_transport_sas.c
@@ -336,6 +336,51 @@ show_sas_device_type(struct class_device *cdev, char *buf)
336} 336}
337static CLASS_DEVICE_ATTR(device_type, S_IRUGO, show_sas_device_type, NULL); 337static CLASS_DEVICE_ATTR(device_type, S_IRUGO, show_sas_device_type, NULL);
338 338
339static ssize_t do_sas_phy_enable(struct class_device *cdev,
340 size_t count, int enable)
341{
342 struct sas_phy *phy = transport_class_to_phy(cdev);
343 struct Scsi_Host *shost = dev_to_shost(phy->dev.parent);
344 struct sas_internal *i = to_sas_internal(shost->transportt);
345 int error;
346
347 error = i->f->phy_enable(phy, enable);
348 if (error)
349 return error;
350 phy->enabled = enable;
351 return count;
352};
353
354static ssize_t store_sas_phy_enable(struct class_device *cdev,
355 const char *buf, size_t count)
356{
357 if (count < 1)
358 return -EINVAL;
359
360 switch (buf[0]) {
361 case '0':
362 do_sas_phy_enable(cdev, count, 0);
363 break;
364 case '1':
365 do_sas_phy_enable(cdev, count, 1);
366 break;
367 default:
368 return -EINVAL;
369 }
370
371 return count;
372}
373
374static ssize_t show_sas_phy_enable(struct class_device *cdev, char *buf)
375{
376 struct sas_phy *phy = transport_class_to_phy(cdev);
377
378 return snprintf(buf, 20, "%d", phy->enabled);
379}
380
381static CLASS_DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, show_sas_phy_enable,
382 store_sas_phy_enable);
383
339static ssize_t do_sas_phy_reset(struct class_device *cdev, 384static ssize_t do_sas_phy_reset(struct class_device *cdev,
340 size_t count, int hard_reset) 385 size_t count, int hard_reset)
341{ 386{
@@ -435,6 +480,7 @@ struct sas_phy *sas_phy_alloc(struct device *parent, int number)
435 return NULL; 480 return NULL;
436 481
437 phy->number = number; 482 phy->number = number;
483 phy->enabled = 1;
438 484
439 device_initialize(&phy->dev); 485 device_initialize(&phy->dev);
440 phy->dev.parent = get_device(parent); 486 phy->dev.parent = get_device(parent);
@@ -579,8 +625,19 @@ static void sas_port_release(struct device *dev)
579static void sas_port_create_link(struct sas_port *port, 625static void sas_port_create_link(struct sas_port *port,
580 struct sas_phy *phy) 626 struct sas_phy *phy)
581{ 627{
582 sysfs_create_link(&port->dev.kobj, &phy->dev.kobj, phy->dev.bus_id); 628 int res;
583 sysfs_create_link(&phy->dev.kobj, &port->dev.kobj, "port"); 629
630 res = sysfs_create_link(&port->dev.kobj, &phy->dev.kobj,
631 phy->dev.bus_id);
632 if (res)
633 goto err;
634 res = sysfs_create_link(&phy->dev.kobj, &port->dev.kobj, "port");
635 if (res)
636 goto err;
637 return;
638err:
639 printk(KERN_ERR "%s: Cannot create port links, err=%d\n",
640 __FUNCTION__, res);
584} 641}
585 642
586static void sas_port_delete_link(struct sas_port *port, 643static void sas_port_delete_link(struct sas_port *port,
@@ -818,13 +875,20 @@ EXPORT_SYMBOL(sas_port_delete_phy);
818 875
819void sas_port_mark_backlink(struct sas_port *port) 876void sas_port_mark_backlink(struct sas_port *port)
820{ 877{
878 int res;
821 struct device *parent = port->dev.parent->parent->parent; 879 struct device *parent = port->dev.parent->parent->parent;
822 880
823 if (port->is_backlink) 881 if (port->is_backlink)
824 return; 882 return;
825 port->is_backlink = 1; 883 port->is_backlink = 1;
826 sysfs_create_link(&port->dev.kobj, &parent->kobj, 884 res = sysfs_create_link(&port->dev.kobj, &parent->kobj,
827 parent->bus_id); 885 parent->bus_id);
886 if (res)
887 goto err;
888 return;
889err:
890 printk(KERN_ERR "%s: Cannot create port backlink, err=%d\n",
891 __FUNCTION__, res);
828 892
829} 893}
830EXPORT_SYMBOL(sas_port_mark_backlink); 894EXPORT_SYMBOL(sas_port_mark_backlink);
@@ -1237,7 +1301,7 @@ int sas_rphy_add(struct sas_rphy *rphy)
1237 if (identify->device_type == SAS_END_DEVICE && 1301 if (identify->device_type == SAS_END_DEVICE &&
1238 rphy->scsi_target_id != -1) { 1302 rphy->scsi_target_id != -1) {
1239 scsi_scan_target(&rphy->dev, 0, 1303 scsi_scan_target(&rphy->dev, 0,
1240 rphy->scsi_target_id, ~0, 0); 1304 rphy->scsi_target_id, SCAN_WILD_CARD, 0);
1241 } 1305 }
1242 1306
1243 return 0; 1307 return 0;
@@ -1253,7 +1317,7 @@ EXPORT_SYMBOL(sas_rphy_add);
1253 * Note: 1317 * Note:
1254 * This function must only be called on a remote 1318 * This function must only be called on a remote
1255 * PHY that has not sucessfully been added using 1319 * PHY that has not sucessfully been added using
1256 * sas_rphy_add(). 1320 * sas_rphy_add() (or has been sas_rphy_remove()'d)
1257 */ 1321 */
1258void sas_rphy_free(struct sas_rphy *rphy) 1322void sas_rphy_free(struct sas_rphy *rphy)
1259{ 1323{
@@ -1272,18 +1336,30 @@ void sas_rphy_free(struct sas_rphy *rphy)
1272EXPORT_SYMBOL(sas_rphy_free); 1336EXPORT_SYMBOL(sas_rphy_free);
1273 1337
1274/** 1338/**
1275 * sas_rphy_delete -- remove SAS remote PHY 1339 * sas_rphy_delete -- remove and free SAS remote PHY
1276 * @rphy: SAS remote PHY to remove 1340 * @rphy: SAS remote PHY to remove and free
1277 * 1341 *
1278 * Removes the specified SAS remote PHY. 1342 * Removes the specified SAS remote PHY and frees it.
1279 */ 1343 */
1280void 1344void
1281sas_rphy_delete(struct sas_rphy *rphy) 1345sas_rphy_delete(struct sas_rphy *rphy)
1282{ 1346{
1347 sas_rphy_remove(rphy);
1348 sas_rphy_free(rphy);
1349}
1350EXPORT_SYMBOL(sas_rphy_delete);
1351
1352/**
1353 * sas_rphy_remove -- remove SAS remote PHY
1354 * @rphy: SAS remote phy to remove
1355 *
1356 * Removes the specified SAS remote PHY.
1357 */
1358void
1359sas_rphy_remove(struct sas_rphy *rphy)
1360{
1283 struct device *dev = &rphy->dev; 1361 struct device *dev = &rphy->dev;
1284 struct sas_port *parent = dev_to_sas_port(dev->parent); 1362 struct sas_port *parent = dev_to_sas_port(dev->parent);
1285 struct Scsi_Host *shost = dev_to_shost(parent->dev.parent);
1286 struct sas_host_attrs *sas_host = to_sas_host_attrs(shost);
1287 1363
1288 switch (rphy->identify.device_type) { 1364 switch (rphy->identify.device_type) {
1289 case SAS_END_DEVICE: 1365 case SAS_END_DEVICE:
@@ -1299,17 +1375,10 @@ sas_rphy_delete(struct sas_rphy *rphy)
1299 1375
1300 transport_remove_device(dev); 1376 transport_remove_device(dev);
1301 device_del(dev); 1377 device_del(dev);
1302 transport_destroy_device(dev);
1303
1304 mutex_lock(&sas_host->lock);
1305 list_del(&rphy->list);
1306 mutex_unlock(&sas_host->lock);
1307 1378
1308 parent->rphy = NULL; 1379 parent->rphy = NULL;
1309
1310 put_device(dev);
1311} 1380}
1312EXPORT_SYMBOL(sas_rphy_delete); 1381EXPORT_SYMBOL(sas_rphy_remove);
1313 1382
1314/** 1383/**
1315 * scsi_is_sas_rphy -- check if a struct device represents a SAS remote PHY 1384 * scsi_is_sas_rphy -- check if a struct device represents a SAS remote PHY
@@ -1389,6 +1458,10 @@ static int sas_user_scan(struct Scsi_Host *shost, uint channel,
1389 SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \ 1458 SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \
1390 !i->f->set_phy_speed, S_IRUGO) 1459 !i->f->set_phy_speed, S_IRUGO)
1391 1460
1461#define SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(field, func) \
1462 SETUP_TEMPLATE_RW(phy_attrs, field, S_IRUGO | S_IWUSR, 1, \
1463 !i->f->func, S_IRUGO)
1464
1392#define SETUP_PORT_ATTRIBUTE(field) \ 1465#define SETUP_PORT_ATTRIBUTE(field) \
1393 SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1) 1466 SETUP_TEMPLATE(port_attrs, field, S_IRUGO, 1)
1394 1467
@@ -1396,10 +1469,10 @@ static int sas_user_scan(struct Scsi_Host *shost, uint channel,
1396 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func) 1469 SETUP_TEMPLATE(phy_attrs, field, S_IRUGO, i->f->func)
1397 1470
1398#define SETUP_PHY_ATTRIBUTE_WRONLY(field) \ 1471#define SETUP_PHY_ATTRIBUTE_WRONLY(field) \
1399 SETUP_TEMPLATE(phy_attrs, field, S_IWUGO, 1) 1472 SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, 1)
1400 1473
1401#define SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(field, func) \ 1474#define SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(field, func) \
1402 SETUP_TEMPLATE(phy_attrs, field, S_IWUGO, i->f->func) 1475 SETUP_TEMPLATE(phy_attrs, field, S_IWUSR, i->f->func)
1403 1476
1404#define SETUP_END_DEV_ATTRIBUTE(field) \ 1477#define SETUP_END_DEV_ATTRIBUTE(field) \
1405 SETUP_TEMPLATE(end_dev_attrs, field, S_IRUGO, 1) 1478 SETUP_TEMPLATE(end_dev_attrs, field, S_IRUGO, 1)
@@ -1479,6 +1552,7 @@ sas_attach_transport(struct sas_function_template *ft)
1479 SETUP_PHY_ATTRIBUTE(phy_reset_problem_count); 1552 SETUP_PHY_ATTRIBUTE(phy_reset_problem_count);
1480 SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(link_reset, phy_reset); 1553 SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(link_reset, phy_reset);
1481 SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(hard_reset, phy_reset); 1554 SETUP_OPTIONAL_PHY_ATTRIBUTE_WRONLY(hard_reset, phy_reset);
1555 SETUP_OPTIONAL_PHY_ATTRIBUTE_RW(enable, phy_enable);
1482 i->phy_attrs[count] = NULL; 1556 i->phy_attrs[count] = NULL;
1483 1557
1484 count = 0; 1558 count = 0;
@@ -1587,7 +1661,7 @@ static void __exit sas_transport_exit(void)
1587} 1661}
1588 1662
1589MODULE_AUTHOR("Christoph Hellwig"); 1663MODULE_AUTHOR("Christoph Hellwig");
1590MODULE_DESCRIPTION("SAS Transphy Attributes"); 1664MODULE_DESCRIPTION("SAS Transport Attributes");
1591MODULE_LICENSE("GPL"); 1665MODULE_LICENSE("GPL");
1592 1666
1593module_init(sas_transport_init); 1667module_init(sas_transport_init);
diff --git a/drivers/scsi/scsi_transport_spi.c b/drivers/scsi/scsi_transport_spi.c
index 014d7fea1ff..6f56f875063 100644
--- a/drivers/scsi/scsi_transport_spi.c
+++ b/drivers/scsi/scsi_transport_spi.c
@@ -46,7 +46,6 @@
46 * two cc/ua clears */ 46 * two cc/ua clears */
47 47
48/* Private data accessors (keep these out of the header file) */ 48/* Private data accessors (keep these out of the header file) */
49#define spi_dv_pending(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_pending)
50#define spi_dv_in_progress(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_in_progress) 49#define spi_dv_in_progress(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_in_progress)
51#define spi_dv_mutex(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_mutex) 50#define spi_dv_mutex(x) (((struct spi_transport_attrs *)&(x)->starget_data)->dv_mutex)
52 51
diff --git a/drivers/scsi/sim710.c b/drivers/scsi/sim710.c
index 551baccec52..018c65f73ac 100644
--- a/drivers/scsi/sim710.c
+++ b/drivers/scsi/sim710.c
@@ -123,6 +123,7 @@ sim710_probe_common(struct device *dev, unsigned long base_addr,
123 hostdata->differential = differential; 123 hostdata->differential = differential;
124 hostdata->clock = clock; 124 hostdata->clock = clock;
125 hostdata->chip710 = 1; 125 hostdata->chip710 = 1;
126 hostdata->burst_length = 8;
126 127
127 /* and register the chip */ 128 /* and register the chip */
128 if((host = NCR_700_detect(&sim710_driver_template, hostdata, dev)) 129 if((host = NCR_700_detect(&sim710_driver_template, hostdata, dev))
diff --git a/drivers/scsi/sni_53c710.c b/drivers/scsi/sni_53c710.c
new file mode 100644
index 00000000000..6bc50511584
--- /dev/null
+++ b/drivers/scsi/sni_53c710.c
@@ -0,0 +1,159 @@
1/* -*- mode: c; c-basic-offset: 8 -*- */
2
3/* SNI RM driver
4 *
5 * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
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
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 */
24
25/*
26 * Based on lasi700.c
27 */
28
29#include <linux/kernel.h>
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/types.h>
33#include <linux/stat.h>
34#include <linux/mm.h>
35#include <linux/blkdev.h>
36#include <linux/sched.h>
37#include <linux/ioport.h>
38#include <linux/dma-mapping.h>
39#include <linux/platform_device.h>
40
41#include <asm/page.h>
42#include <asm/pgtable.h>
43#include <asm/irq.h>
44#include <asm/delay.h>
45
46#include <scsi/scsi_host.h>
47#include <scsi/scsi_device.h>
48#include <scsi/scsi_transport.h>
49#include <scsi/scsi_transport_spi.h>
50
51#include "53c700.h"
52
53MODULE_AUTHOR("Thomas Bogendörfer");
54MODULE_DESCRIPTION("SNI RM 53c710 SCSI Driver");
55MODULE_LICENSE("GPL");
56
57#define SNIRM710_CLOCK 32
58
59static struct scsi_host_template snirm710_template = {
60 .name = "SNI RM SCSI 53c710",
61 .proc_name = "snirm_53c710",
62 .this_id = 7,
63 .module = THIS_MODULE,
64};
65
66static int __init snirm710_probe(struct platform_device *dev)
67{
68 unsigned long base;
69 struct NCR_700_Host_Parameters *hostdata;
70 struct Scsi_Host *host;
71 struct resource *res;
72
73 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
74 if (!res)
75 return -ENODEV;
76
77 base = res->start;
78 hostdata = kzalloc(sizeof(*hostdata), GFP_KERNEL);
79 if (!hostdata) {
80 printk(KERN_ERR "%s: Failed to allocate host data\n",
81 dev->dev.bus_id);
82 return -ENOMEM;
83 }
84
85 hostdata->dev = &dev->dev;
86 dma_set_mask(&dev->dev, DMA_32BIT_MASK);
87 hostdata->base = ioremap_nocache(CPHYSADDR(base), 0x100);
88 hostdata->differential = 0;
89
90 hostdata->clock = SNIRM710_CLOCK;
91 hostdata->force_le_on_be = 1;
92 hostdata->chip710 = 1;
93 hostdata->burst_length = 4;
94
95 host = NCR_700_detect(&snirm710_template, hostdata, &dev->dev);
96 if (!host)
97 goto out_kfree;
98 host->this_id = 7;
99 host->base = base;
100 host->irq = platform_get_irq(dev, 0);
101 if(request_irq(host->irq, NCR_700_intr, SA_SHIRQ, "snirm710", host)) {
102 printk(KERN_ERR "snirm710: request_irq failed!\n");
103 goto out_put_host;
104 }
105
106 dev_set_drvdata(&dev->dev, host);
107 scsi_scan_host(host);
108
109 return 0;
110
111 out_put_host:
112 scsi_host_put(host);
113 out_kfree:
114 iounmap(hostdata->base);
115 kfree(hostdata);
116 return -ENODEV;
117}
118
119static int __exit snirm710_driver_remove(struct platform_device *dev)
120{
121 struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
122 struct NCR_700_Host_Parameters *hostdata =
123 (struct NCR_700_Host_Parameters *)host->hostdata[0];
124
125 scsi_remove_host(host);
126 NCR_700_release(host);
127 free_irq(host->irq, host);
128 iounmap(hostdata->base);
129 kfree(hostdata);
130
131 return 0;
132}
133
134static struct platform_driver snirm710_driver = {
135 .probe = snirm710_probe,
136 .remove = __devexit_p(snirm710_driver_remove),
137 .driver = {
138 .name = "snirm_53c710",
139 },
140};
141
142static int __init snirm710_init(void)
143{
144 int err;
145
146 if ((err = platform_driver_register(&snirm710_driver))) {
147 printk(KERN_ERR "Driver registration failed\n");
148 return err;
149 }
150 return 0;
151}
152
153static void __exit snirm710_exit(void)
154{
155 platform_driver_unregister(&snirm710_driver);
156}
157
158module_init(snirm710_init);
159module_exit(snirm710_exit);
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 488ec7948a5..3d2e02381e9 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -9,7 +9,7 @@
9 Steve Hirsch, Andreas Koppenh"ofer, Michael Leodolter, Eyal Lebedinsky, 9 Steve Hirsch, Andreas Koppenh"ofer, Michael Leodolter, Eyal Lebedinsky,
10 Michael Schaefer, J"org Weule, and Eric Youngdale. 10 Michael Schaefer, J"org Weule, and Eric Youngdale.
11 11
12 Copyright 1992 - 2006 Kai Makisara 12 Copyright 1992 - 2007 Kai Makisara
13 email Kai.Makisara@kolumbus.fi 13 email Kai.Makisara@kolumbus.fi
14 14
15 Some small formal changes - aeb, 950809 15 Some small formal changes - aeb, 950809
@@ -17,7 +17,7 @@
17 Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support 17 Last modified: 18-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Devfs support
18 */ 18 */
19 19
20static const char *verstr = "20061107"; 20static const char *verstr = "20070203";
21 21
22#include <linux/module.h> 22#include <linux/module.h>
23 23
@@ -1168,6 +1168,7 @@ static int st_open(struct inode *inode, struct file *filp)
1168 STps = &(STp->ps[i]); 1168 STps = &(STp->ps[i]);
1169 STps->rw = ST_IDLE; 1169 STps->rw = ST_IDLE;
1170 } 1170 }
1171 STp->try_dio_now = STp->try_dio;
1171 STp->recover_count = 0; 1172 STp->recover_count = 0;
1172 DEB( STp->nbr_waits = STp->nbr_finished = 0; 1173 DEB( STp->nbr_waits = STp->nbr_finished = 0;
1173 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = STp->nbr_combinable = 0; ) 1174 STp->nbr_requests = STp->nbr_dio = STp->nbr_pages = STp->nbr_combinable = 0; )
@@ -1400,9 +1401,9 @@ static int setup_buffering(struct scsi_tape *STp, const char __user *buf,
1400 struct st_buffer *STbp = STp->buffer; 1401 struct st_buffer *STbp = STp->buffer;
1401 1402
1402 if (is_read) 1403 if (is_read)
1403 i = STp->try_dio && try_rdio; 1404 i = STp->try_dio_now && try_rdio;
1404 else 1405 else
1405 i = STp->try_dio && try_wdio; 1406 i = STp->try_dio_now && try_wdio;
1406 1407
1407 if (i && ((unsigned long)buf & queue_dma_alignment( 1408 if (i && ((unsigned long)buf & queue_dma_alignment(
1408 STp->device->request_queue)) == 0) { 1409 STp->device->request_queue)) == 0) {
@@ -1599,7 +1600,7 @@ st_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
1599 STm->do_async_writes && STps->eof < ST_EOM_OK; 1600 STm->do_async_writes && STps->eof < ST_EOM_OK;
1600 1601
1601 if (STp->block_size != 0 && STm->do_buffer_writes && 1602 if (STp->block_size != 0 && STm->do_buffer_writes &&
1602 !(STp->try_dio && try_wdio) && STps->eof < ST_EOM_OK && 1603 !(STp->try_dio_now && try_wdio) && STps->eof < ST_EOM_OK &&
1603 STbp->buffer_bytes < STbp->buffer_size) { 1604 STbp->buffer_bytes < STbp->buffer_size) {
1604 STp->dirty = 1; 1605 STp->dirty = 1;
1605 /* Don't write a buffer that is not full enough. */ 1606 /* Don't write a buffer that is not full enough. */
@@ -1769,7 +1770,7 @@ static long read_tape(struct scsi_tape *STp, long count,
1769 if (STp->block_size == 0) 1770 if (STp->block_size == 0)
1770 blks = bytes = count; 1771 blks = bytes = count;
1771 else { 1772 else {
1772 if (!(STp->try_dio && try_rdio) && STm->do_read_ahead) { 1773 if (!(STp->try_dio_now && try_rdio) && STm->do_read_ahead) {
1773 blks = (STp->buffer)->buffer_blocks; 1774 blks = (STp->buffer)->buffer_blocks;
1774 bytes = blks * STp->block_size; 1775 bytes = blks * STp->block_size;
1775 } else { 1776 } else {
@@ -1948,10 +1949,12 @@ st_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos)
1948 goto out; 1949 goto out;
1949 1950
1950 STm = &(STp->modes[STp->current_mode]); 1951 STm = &(STp->modes[STp->current_mode]);
1951 if (!(STm->do_read_ahead) && STp->block_size != 0 && 1952 if (STp->block_size != 0 && (count % STp->block_size) != 0) {
1952 (count % STp->block_size) != 0) { 1953 if (!STm->do_read_ahead) {
1953 retval = (-EINVAL); /* Read must be integral number of blocks */ 1954 retval = (-EINVAL); /* Read must be integral number of blocks */
1954 goto out; 1955 goto out;
1956 }
1957 STp->try_dio_now = 0; /* Direct i/o can't handle split blocks */
1955 } 1958 }
1956 1959
1957 STps = &(STp->ps[STp->partition]); 1960 STps = &(STp->ps[STp->partition]);
@@ -3861,7 +3864,7 @@ __setup("st=", st_setup);
3861 3864
3862#endif 3865#endif
3863 3866
3864static struct file_operations st_fops = 3867static const struct file_operations st_fops =
3865{ 3868{
3866 .owner = THIS_MODULE, 3869 .owner = THIS_MODULE,
3867 .read = st_read, 3870 .read = st_read,
diff --git a/drivers/scsi/st.h b/drivers/scsi/st.h
index 05a5cae126e..50f3deb1f9e 100644
--- a/drivers/scsi/st.h
+++ b/drivers/scsi/st.h
@@ -117,7 +117,8 @@ struct scsi_tape {
117 unsigned char cln_sense_value; 117 unsigned char cln_sense_value;
118 unsigned char cln_sense_mask; 118 unsigned char cln_sense_mask;
119 unsigned char use_pf; /* Set Page Format bit in all mode selects? */ 119 unsigned char use_pf; /* Set Page Format bit in all mode selects? */
120 unsigned char try_dio; /* try direct i/o? */ 120 unsigned char try_dio; /* try direct i/o in general? */
121 unsigned char try_dio_now; /* try direct i/o before next close? */
121 unsigned char c_algo; /* compression algorithm */ 122 unsigned char c_algo; /* compression algorithm */
122 unsigned char pos_unknown; /* after reset position unknown */ 123 unsigned char pos_unknown; /* after reset position unknown */
123 int tape_type; 124 int tape_type;
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 5261f0af8b1..2964ca9df5a 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -920,12 +920,16 @@ static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
920#ifdef __i386__ 920#ifdef __i386__
921 outb(0xff, 0x080); 921 outb(0xff, 0x080);
922#endif 922#endif
923 scratch2 = serial_inp(up, UART_IER); 923 /*
924 * Mask out IER[7:4] bits for test as some UARTs (e.g. TL
925 * 16C754B) allow only to modify them if an EFR bit is set.
926 */
927 scratch2 = serial_inp(up, UART_IER) & 0x0f;
924 serial_outp(up, UART_IER, 0x0F); 928 serial_outp(up, UART_IER, 0x0F);
925#ifdef __i386__ 929#ifdef __i386__
926 outb(0, 0x080); 930 outb(0, 0x080);
927#endif 931#endif
928 scratch3 = serial_inp(up, UART_IER); 932 scratch3 = serial_inp(up, UART_IER) & 0x0f;
929 serial_outp(up, UART_IER, scratch); 933 serial_outp(up, UART_IER, scratch);
930 if (scratch2 != 0 || scratch3 != 0x0F) { 934 if (scratch2 != 0 || scratch3 != 0x0F) {
931 /* 935 /*
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index 52e2e64c664..a2dac378bda 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -679,6 +679,13 @@ static struct pci_serial_quirk pci_serial_quirks[] = {
679 */ 679 */
680 { 680 {
681 .vendor = PCI_VENDOR_ID_PLX, 681 .vendor = PCI_VENDOR_ID_PLX,
682 .device = PCI_DEVICE_ID_PLX_9030,
683 .subvendor = PCI_SUBVENDOR_ID_PERLE,
684 .subdevice = PCI_ANY_ID,
685 .setup = pci_default_setup,
686 },
687 {
688 .vendor = PCI_VENDOR_ID_PLX,
682 .device = PCI_DEVICE_ID_PLX_9050, 689 .device = PCI_DEVICE_ID_PLX_9050,
683 .subvendor = PCI_SUBVENDOR_ID_EXSYS, 690 .subvendor = PCI_SUBVENDOR_ID_EXSYS,
684 .subdevice = PCI_SUBDEVICE_ID_EXSYS_4055, 691 .subdevice = PCI_SUBDEVICE_ID_EXSYS_4055,
@@ -936,6 +943,7 @@ enum pci_board_num_t {
936 943
937 pbn_b2_1_115200, 944 pbn_b2_1_115200,
938 pbn_b2_2_115200, 945 pbn_b2_2_115200,
946 pbn_b2_4_115200,
939 pbn_b2_8_115200, 947 pbn_b2_8_115200,
940 948
941 pbn_b2_1_460800, 949 pbn_b2_1_460800,
@@ -1249,6 +1257,12 @@ static struct pciserial_board pci_boards[] __devinitdata = {
1249 .base_baud = 115200, 1257 .base_baud = 115200,
1250 .uart_offset = 8, 1258 .uart_offset = 8,
1251 }, 1259 },
1260 [pbn_b2_4_115200] = {
1261 .flags = FL_BASE2,
1262 .num_ports = 4,
1263 .base_baud = 115200,
1264 .uart_offset = 8,
1265 },
1252 [pbn_b2_8_115200] = { 1266 [pbn_b2_8_115200] = {
1253 .flags = FL_BASE2, 1267 .flags = FL_BASE2,
1254 .num_ports = 8, 1268 .num_ports = 8,
@@ -1990,6 +2004,10 @@ static struct pci_device_id serial_pci_tbl[] = {
1990 { PCI_VENDOR_ID_PANACOM, PCI_DEVICE_ID_PANACOM_DUALMODEM, 2004 { PCI_VENDOR_ID_PANACOM, PCI_DEVICE_ID_PANACOM_DUALMODEM,
1991 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2005 PCI_ANY_ID, PCI_ANY_ID, 0, 0,
1992 pbn_panacom2 }, 2006 pbn_panacom2 },
2007 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
2008 PCI_VENDOR_ID_ESDGMBH,
2009 PCI_DEVICE_ID_ESDGMBH_CPCIASIO4, 0, 0,
2010 pbn_b2_4_115200 },
1993 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, 2011 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
1994 PCI_SUBVENDOR_ID_CHASE_PCIFAST, 2012 PCI_SUBVENDOR_ID_CHASE_PCIFAST,
1995 PCI_SUBDEVICE_ID_CHASE_PCIFAST4, 0, 0, 2013 PCI_SUBDEVICE_ID_CHASE_PCIFAST4, 0, 0,
@@ -2379,6 +2397,15 @@ static struct pci_device_id serial_pci_tbl[] = {
2379 pbn_b2_2_115200 }, 2397 pbn_b2_2_115200 },
2380 2398
2381 /* 2399 /*
2400 * Perle PCI-RAS cards
2401 */
2402 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
2403 PCI_SUBVENDOR_ID_PERLE, PCI_SUBDEVICE_ID_PCI_RAS4,
2404 0, 0, pbn_b2_4_921600 },
2405 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9030,
2406 PCI_SUBVENDOR_ID_PERLE, PCI_SUBDEVICE_ID_PCI_RAS8,
2407 0, 0, pbn_b2_8_921600 },
2408 /*
2382 * These entries match devices with class COMMUNICATION_SERIAL, 2409 * These entries match devices with class COMMUNICATION_SERIAL,
2383 * COMMUNICATION_MODEM or COMMUNICATION_MULTISERIAL 2410 * COMMUNICATION_MODEM or COMMUNICATION_MULTISERIAL
2384 */ 2411 */
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 2978c09860e..5cc6b91f840 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -916,6 +916,11 @@ config SERIAL_TXX9
916config HAS_TXX9_SERIAL 916config HAS_TXX9_SERIAL
917 bool 917 bool
918 918
919config SERIAL_TXX9_NR_UARTS
920 int "Maximum number of TMPTX39XX/49XX SIO ports"
921 depends on SERIAL_TXX9
922 default "6"
923
919config SERIAL_TXX9_CONSOLE 924config SERIAL_TXX9_CONSOLE
920 bool "TMPTX39XX/49XX SIO Console support" 925 bool "TMPTX39XX/49XX SIO Console support"
921 depends on SERIAL_TXX9=y 926 depends on SERIAL_TXX9=y
diff --git a/drivers/serial/atmel_serial.c b/drivers/serial/atmel_serial.c
index 881f886b91c..df45a7ac773 100644
--- a/drivers/serial/atmel_serial.c
+++ b/drivers/serial/atmel_serial.c
@@ -73,35 +73,35 @@
73 73
74#define ATMEL_ISR_PASS_LIMIT 256 74#define ATMEL_ISR_PASS_LIMIT 256
75 75
76#define UART_PUT_CR(port,v) writel(v, (port)->membase + ATMEL_US_CR) 76#define UART_PUT_CR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_CR)
77#define UART_GET_MR(port) readl((port)->membase + ATMEL_US_MR) 77#define UART_GET_MR(port) __raw_readl((port)->membase + ATMEL_US_MR)
78#define UART_PUT_MR(port,v) writel(v, (port)->membase + ATMEL_US_MR) 78#define UART_PUT_MR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_MR)
79#define UART_PUT_IER(port,v) writel(v, (port)->membase + ATMEL_US_IER) 79#define UART_PUT_IER(port,v) __raw_writel(v, (port)->membase + ATMEL_US_IER)
80#define UART_PUT_IDR(port,v) writel(v, (port)->membase + ATMEL_US_IDR) 80#define UART_PUT_IDR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_IDR)
81#define UART_GET_IMR(port) readl((port)->membase + ATMEL_US_IMR) 81#define UART_GET_IMR(port) __raw_readl((port)->membase + ATMEL_US_IMR)
82#define UART_GET_CSR(port) readl((port)->membase + ATMEL_US_CSR) 82#define UART_GET_CSR(port) __raw_readl((port)->membase + ATMEL_US_CSR)
83#define UART_GET_CHAR(port) readl((port)->membase + ATMEL_US_RHR) 83#define UART_GET_CHAR(port) __raw_readl((port)->membase + ATMEL_US_RHR)
84#define UART_PUT_CHAR(port,v) writel(v, (port)->membase + ATMEL_US_THR) 84#define UART_PUT_CHAR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_THR)
85#define UART_GET_BRGR(port) readl((port)->membase + ATMEL_US_BRGR) 85#define UART_GET_BRGR(port) __raw_readl((port)->membase + ATMEL_US_BRGR)
86#define UART_PUT_BRGR(port,v) writel(v, (port)->membase + ATMEL_US_BRGR) 86#define UART_PUT_BRGR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_BRGR)
87#define UART_PUT_RTOR(port,v) writel(v, (port)->membase + ATMEL_US_RTOR) 87#define UART_PUT_RTOR(port,v) __raw_writel(v, (port)->membase + ATMEL_US_RTOR)
88 88
89// #define UART_GET_CR(port) readl((port)->membase + ATMEL_US_CR) // is write-only 89// #define UART_GET_CR(port) __raw_readl((port)->membase + ATMEL_US_CR) // is write-only
90 90
91 /* PDC registers */ 91 /* PDC registers */
92#define UART_PUT_PTCR(port,v) writel(v, (port)->membase + ATMEL_PDC_PTCR) 92#define UART_PUT_PTCR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_PTCR)
93#define UART_GET_PTSR(port) readl((port)->membase + ATMEL_PDC_PTSR) 93#define UART_GET_PTSR(port) __raw_readl((port)->membase + ATMEL_PDC_PTSR)
94 94
95#define UART_PUT_RPR(port,v) writel(v, (port)->membase + ATMEL_PDC_RPR) 95#define UART_PUT_RPR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_RPR)
96#define UART_GET_RPR(port) readl((port)->membase + ATMEL_PDC_RPR) 96#define UART_GET_RPR(port) __raw_readl((port)->membase + ATMEL_PDC_RPR)
97#define UART_PUT_RCR(port,v) writel(v, (port)->membase + ATMEL_PDC_RCR) 97#define UART_PUT_RCR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_RCR)
98#define UART_PUT_RNPR(port,v) writel(v, (port)->membase + ATMEL_PDC_RNPR) 98#define UART_PUT_RNPR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_RNPR)
99#define UART_PUT_RNCR(port,v) writel(v, (port)->membase + ATMEL_PDC_RNCR) 99#define UART_PUT_RNCR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_RNCR)
100 100
101#define UART_PUT_TPR(port,v) writel(v, (port)->membase + ATMEL_PDC_TPR) 101#define UART_PUT_TPR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_TPR)
102#define UART_PUT_TCR(port,v) writel(v, (port)->membase + ATMEL_PDC_TCR) 102#define UART_PUT_TCR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_TCR)
103//#define UART_PUT_TNPR(port,v) writel(v, (port)->membase + ATMEL_PDC_TNPR) 103//#define UART_PUT_TNPR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_TNPR)
104//#define UART_PUT_TNCR(port,v) writel(v, (port)->membase + ATMEL_PDC_TNCR) 104//#define UART_PUT_TNCR(port,v) __raw_writel(v, (port)->membase + ATMEL_PDC_TNCR)
105 105
106static int (*atmel_open_hook)(struct uart_port *); 106static int (*atmel_open_hook)(struct uart_port *);
107static void (*atmel_close_hook)(struct uart_port *); 107static void (*atmel_close_hook)(struct uart_port *);
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index 42b050c46ab..312bef6bd58 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -3173,12 +3173,8 @@ do_softint(void *private_)
3173 if (!tty) 3173 if (!tty)
3174 return; 3174 return;
3175 3175
3176 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) { 3176 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
3177 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && 3177 tty_wakeup(tty);
3178 tty->ldisc.write_wakeup)
3179 (tty->ldisc.write_wakeup)(tty);
3180 wake_up_interruptible(&tty->write_wait);
3181 }
3182} 3178}
3183 3179
3184static int 3180static int
@@ -3798,11 +3794,7 @@ rs_flush_buffer(struct tty_struct *tty)
3798 info->xmit.head = info->xmit.tail = 0; 3794 info->xmit.head = info->xmit.tail = 0;
3799 restore_flags(flags); 3795 restore_flags(flags);
3800 3796
3801 wake_up_interruptible(&tty->write_wait); 3797 tty_wakeup(tty);
3802
3803 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
3804 tty->ldisc.write_wakeup)
3805 (tty->ldisc.write_wakeup)(tty);
3806} 3798}
3807 3799
3808/* 3800/*
diff --git a/drivers/serial/ioc4_serial.c b/drivers/serial/ioc4_serial.c
index c862f67c985..f540212e740 100644
--- a/drivers/serial/ioc4_serial.c
+++ b/drivers/serial/ioc4_serial.c
@@ -2685,7 +2685,7 @@ static int ioc4_serial_remove_one(struct ioc4_driver_data *idd)
2685 free_irq(control->ic_irq, soft); 2685 free_irq(control->ic_irq, soft);
2686 if (soft->is_ioc4_serial_addr) { 2686 if (soft->is_ioc4_serial_addr) {
2687 iounmap(soft->is_ioc4_serial_addr); 2687 iounmap(soft->is_ioc4_serial_addr);
2688 release_region((unsigned long) 2688 release_mem_region((unsigned long)
2689 soft->is_ioc4_serial_addr, 2689 soft->is_ioc4_serial_addr,
2690 sizeof(struct ioc4_serial)); 2690 sizeof(struct ioc4_serial));
2691 } 2691 }
@@ -2790,7 +2790,7 @@ ioc4_serial_attach_one(struct ioc4_driver_data *idd)
2790 /* request serial registers */ 2790 /* request serial registers */
2791 tmp_addr1 = idd->idd_bar0 + IOC4_SERIAL_OFFSET; 2791 tmp_addr1 = idd->idd_bar0 + IOC4_SERIAL_OFFSET;
2792 2792
2793 if (!request_region(tmp_addr1, sizeof(struct ioc4_serial), 2793 if (!request_mem_region(tmp_addr1, sizeof(struct ioc4_serial),
2794 "sioc4_uart")) { 2794 "sioc4_uart")) {
2795 printk(KERN_WARNING 2795 printk(KERN_WARNING
2796 "ioc4 (%p): unable to get request region for " 2796 "ioc4 (%p): unable to get request region for "
@@ -2889,7 +2889,7 @@ out3:
2889out2: 2889out2:
2890 if (serial) 2890 if (serial)
2891 iounmap(serial); 2891 iounmap(serial);
2892 release_region(tmp_addr1, sizeof(struct ioc4_serial)); 2892 release_mem_region(tmp_addr1, sizeof(struct ioc4_serial));
2893out1: 2893out1:
2894 2894
2895 return ret; 2895 return ret;
diff --git a/drivers/serial/serial_txx9.c b/drivers/serial/serial_txx9.c
index 7186a82c475..f4440d32931 100644
--- a/drivers/serial/serial_txx9.c
+++ b/drivers/serial/serial_txx9.c
@@ -37,6 +37,7 @@
37 * 1.06 Do not insert a char caused previous overrun. 37 * 1.06 Do not insert a char caused previous overrun.
38 * Fix some spin_locks. 38 * Fix some spin_locks.
39 * Do not call uart_add_one_port for absent ports. 39 * Do not call uart_add_one_port for absent ports.
40 * 1.07 Use CONFIG_SERIAL_TXX9_NR_UARTS. Cleanup.
40 */ 41 */
41 42
42#if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ) 43#if defined(CONFIG_SERIAL_TXX9_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
@@ -58,9 +59,8 @@
58#include <linux/mutex.h> 59#include <linux/mutex.h>
59 60
60#include <asm/io.h> 61#include <asm/io.h>
61#include <asm/irq.h>
62 62
63static char *serial_version = "1.06"; 63static char *serial_version = "1.07";
64static char *serial_name = "TX39/49 Serial driver"; 64static char *serial_name = "TX39/49 Serial driver";
65 65
66#define PASS_LIMIT 256 66#define PASS_LIMIT 256
@@ -88,12 +88,7 @@ static char *serial_name = "TX39/49 Serial driver";
88/* 88/*
89 * Number of serial ports 89 * Number of serial ports
90 */ 90 */
91#ifdef ENABLE_SERIAL_TXX9_PCI 91#define UART_NR CONFIG_SERIAL_TXX9_NR_UARTS
92#define NR_PCI_BOARDS 4
93#define UART_NR (4 + NR_PCI_BOARDS)
94#else
95#define UART_NR 4
96#endif
97 92
98#define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8) 93#define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
99 94
@@ -987,6 +982,7 @@ int __init early_serial_txx9_setup(struct uart_port *port)
987} 982}
988 983
989#ifdef ENABLE_SERIAL_TXX9_PCI 984#ifdef ENABLE_SERIAL_TXX9_PCI
985#ifdef CONFIG_PM
990/** 986/**
991 * serial_txx9_suspend_port - suspend one serial port 987 * serial_txx9_suspend_port - suspend one serial port
992 * @line: serial line number 988 * @line: serial line number
@@ -1008,6 +1004,7 @@ static void serial_txx9_resume_port(int line)
1008{ 1004{
1009 uart_resume_port(&serial_txx9_reg, &serial_txx9_ports[line].port); 1005 uart_resume_port(&serial_txx9_reg, &serial_txx9_ports[line].port);
1010} 1006}
1007#endif
1011 1008
1012static DEFINE_MUTEX(serial_txx9_mutex); 1009static DEFINE_MUTEX(serial_txx9_mutex);
1013 1010
@@ -1118,6 +1115,7 @@ static void __devexit pciserial_txx9_remove_one(struct pci_dev *dev)
1118 } 1115 }
1119} 1116}
1120 1117
1118#ifdef CONFIG_PM
1121static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state) 1119static int pciserial_txx9_suspend_one(struct pci_dev *dev, pm_message_t state)
1122{ 1120{
1123 int line = (int)(long)pci_get_drvdata(dev); 1121 int line = (int)(long)pci_get_drvdata(dev);
@@ -1142,11 +1140,10 @@ static int pciserial_txx9_resume_one(struct pci_dev *dev)
1142 } 1140 }
1143 return 0; 1141 return 0;
1144} 1142}
1143#endif
1145 1144
1146static struct pci_device_id serial_txx9_pci_tbl[] = { 1145static const struct pci_device_id serial_txx9_pci_tbl[] = {
1147 { PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_TC86C001_MISC, 1146 { PCI_DEVICE(PCI_VENDOR_ID_TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_TC86C001_MISC) },
1148 PCI_ANY_ID, PCI_ANY_ID,
1149 0, 0, 0 },
1150 { 0, } 1147 { 0, }
1151}; 1148};
1152 1149
@@ -1154,8 +1151,10 @@ static struct pci_driver serial_txx9_pci_driver = {
1154 .name = "serial_txx9", 1151 .name = "serial_txx9",
1155 .probe = pciserial_txx9_init_one, 1152 .probe = pciserial_txx9_init_one,
1156 .remove = __devexit_p(pciserial_txx9_remove_one), 1153 .remove = __devexit_p(pciserial_txx9_remove_one),
1154#ifdef CONFIG_PM
1157 .suspend = pciserial_txx9_suspend_one, 1155 .suspend = pciserial_txx9_suspend_one,
1158 .resume = pciserial_txx9_resume_one, 1156 .resume = pciserial_txx9_resume_one,
1157#endif
1159 .id_table = serial_txx9_pci_tbl, 1158 .id_table = serial_txx9_pci_tbl,
1160}; 1159};
1161 1160
diff --git a/drivers/sn/ioc3.c b/drivers/sn/ioc3.c
index cd6b65333b7..2dd6eed50aa 100644
--- a/drivers/sn/ioc3.c
+++ b/drivers/sn/ioc3.c
@@ -654,7 +654,7 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
654 ret = -ENODEV; 654 ret = -ENODEV;
655 goto out_pci; 655 goto out_pci;
656 } 656 }
657 if (!request_region(idd->pma, IOC3_PCI_SIZE, "ioc3")) { 657 if (!request_mem_region(idd->pma, IOC3_PCI_SIZE, "ioc3")) {
658 printk(KERN_WARNING 658 printk(KERN_WARNING
659 "%s: Unable to request IOC3 region " 659 "%s: Unable to request IOC3 region "
660 "for pci_dev %s.\n", 660 "for pci_dev %s.\n",
@@ -744,7 +744,7 @@ static int ioc3_probe(struct pci_dev *pdev, const struct pci_device_id *pci_id)
744 return 0; 744 return 0;
745 745
746out_misc_region: 746out_misc_region:
747 release_region(idd->pma, IOC3_PCI_SIZE); 747 release_mem_region(idd->pma, IOC3_PCI_SIZE);
748out_pci: 748out_pci:
749 kfree(idd); 749 kfree(idd);
750out_idd: 750out_idd:
@@ -785,7 +785,7 @@ static void ioc3_remove(struct pci_dev *pdev)
785 if(idd->dual_irq) 785 if(idd->dual_irq)
786 free_irq(idd->irq_eth, (void *)idd); 786 free_irq(idd->irq_eth, (void *)idd);
787 iounmap(idd->vma); 787 iounmap(idd->vma);
788 release_region(idd->pma, IOC3_PCI_SIZE); 788 release_mem_region(idd->pma, IOC3_PCI_SIZE);
789 789
790 /* Disable IOC3 and relinquish */ 790 /* Disable IOC3 and relinquish */
791 pci_disable_device(pdev); 791 pci_disable_device(pdev);
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
index d895a1adb42..9052f4c3493 100644
--- a/drivers/spi/Kconfig
+++ b/drivers/spi/Kconfig
@@ -75,6 +75,13 @@ config SPI_BUTTERFLY
75 inexpensive battery powered microcontroller evaluation board. 75 inexpensive battery powered microcontroller evaluation board.
76 This same cable can be used to flash new firmware. 76 This same cable can be used to flash new firmware.
77 77
78config SPI_IMX
79 tristate "Freescale iMX SPI controller"
80 depends on SPI_MASTER && ARCH_IMX && EXPERIMENTAL
81 help
82 This enables using the Freescale iMX SPI controller in master
83 mode.
84
78config SPI_MPC83xx 85config SPI_MPC83xx
79 tristate "Freescale MPC83xx SPI controller" 86 tristate "Freescale MPC83xx SPI controller"
80 depends on SPI_MASTER && PPC_83xx && EXPERIMENTAL 87 depends on SPI_MASTER && PPC_83xx && EXPERIMENTAL
@@ -87,6 +94,14 @@ config SPI_MPC83xx
87 family of PowerPC processors. The MPC83xx uses a simple set of shift 94 family of PowerPC processors. The MPC83xx uses a simple set of shift
88 registers for data (opposed to the CPM based descriptor model). 95 registers for data (opposed to the CPM based descriptor model).
89 96
97config SPI_OMAP_UWIRE
98 tristate "OMAP1 MicroWire"
99 depends on SPI_MASTER && ARCH_OMAP1
100 select SPI_BITBANG
101 help
102 This hooks up to the MicroWire controller on OMAP1 chips.
103
104
90config SPI_PXA2XX 105config SPI_PXA2XX
91 tristate "PXA2xx SSP SPI master" 106 tristate "PXA2xx SSP SPI master"
92 depends on SPI_MASTER && ARCH_PXA && EXPERIMENTAL 107 depends on SPI_MASTER && ARCH_PXA && EXPERIMENTAL
@@ -95,6 +110,12 @@ config SPI_PXA2XX
95 The driver can be configured to use any SSP port and additional 110 The driver can be configured to use any SSP port and additional
96 documentation can be found a Documentation/spi/pxa2xx. 111 documentation can be found a Documentation/spi/pxa2xx.
97 112
113config SPI_S3C24XX
114 tristate "Samsung S3C24XX series SPI"
115 depends on SPI_MASTER && ARCH_S3C2410 && EXPERIMENTAL
116 help
117 SPI driver for Samsung S3C24XX series ARM SoCs
118
98config SPI_S3C24XX_GPIO 119config SPI_S3C24XX_GPIO
99 tristate "Samsung S3C24XX series SPI by GPIO" 120 tristate "Samsung S3C24XX series SPI by GPIO"
100 depends on SPI_MASTER && ARCH_S3C2410 && SPI_BITBANG && EXPERIMENTAL 121 depends on SPI_MASTER && ARCH_S3C2410 && SPI_BITBANG && EXPERIMENTAL
@@ -107,13 +128,6 @@ config SPI_S3C24XX_GPIO
107# Add new SPI master controllers in alphabetical order above this line 128# Add new SPI master controllers in alphabetical order above this line
108# 129#
109 130
110
111config SPI_S3C24XX
112 tristate "Samsung S3C24XX series SPI"
113 depends on SPI_MASTER && ARCH_S3C2410 && EXPERIMENTAL
114 help
115 SPI driver for Samsung S3C24XX series ARM SoCs
116
117# 131#
118# There are lots of SPI device types, with sensors and memory 132# There are lots of SPI device types, with sensors and memory
119# being probably the most widely used ones. 133# being probably the most widely used ones.
@@ -121,6 +135,16 @@ config SPI_S3C24XX
121comment "SPI Protocol Masters" 135comment "SPI Protocol Masters"
122 depends on SPI_MASTER 136 depends on SPI_MASTER
123 137
138config SPI_AT25
139 tristate "SPI EEPROMs from most vendors"
140 depends on SPI_MASTER && SYSFS
141 help
142 Enable this driver to get read/write support to most SPI EEPROMs,
143 after you configure the board init code to know about each eeprom
144 on your target board.
145
146 This driver can also be built as a module. If so, the module
147 will be called at25.
124 148
125# 149#
126# Add new SPI protocol masters in alphabetical order above this line 150# Add new SPI protocol masters in alphabetical order above this line
diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile
index 8f4cb67997b..bf271fe4e53 100644
--- a/drivers/spi/Makefile
+++ b/drivers/spi/Makefile
@@ -13,13 +13,16 @@ obj-$(CONFIG_SPI_MASTER) += spi.o
13# SPI master controller drivers (bus) 13# SPI master controller drivers (bus)
14obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o 14obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
15obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o 15obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
16obj-$(CONFIG_SPI_IMX) += spi_imx.o
16obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o 17obj-$(CONFIG_SPI_PXA2XX) += pxa2xx_spi.o
18obj-$(CONFIG_SPI_OMAP_UWIRE) += omap_uwire.o
17obj-$(CONFIG_SPI_MPC83xx) += spi_mpc83xx.o 19obj-$(CONFIG_SPI_MPC83xx) += spi_mpc83xx.o
18obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o 20obj-$(CONFIG_SPI_S3C24XX_GPIO) += spi_s3c24xx_gpio.o
19obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o 21obj-$(CONFIG_SPI_S3C24XX) += spi_s3c24xx.o
20# ... add above this line ... 22# ... add above this line ...
21 23
22# SPI protocol drivers (device/link on bus) 24# SPI protocol drivers (device/link on bus)
25obj-$(CONFIG_SPI_AT25) += at25.o
23# ... add above this line ... 26# ... add above this line ...
24 27
25# SPI slave controller drivers (upstream link) 28# SPI slave controller drivers (upstream link)
diff --git a/drivers/spi/at25.c b/drivers/spi/at25.c
new file mode 100644
index 00000000000..48e4f48e779
--- /dev/null
+++ b/drivers/spi/at25.c
@@ -0,0 +1,381 @@
1/*
2 * at25.c -- support most SPI EEPROMs, such as Atmel AT25 models
3 *
4 * Copyright (C) 2006 David Brownell
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
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/slab.h>
16#include <linux/delay.h>
17#include <linux/device.h>
18#include <linux/sched.h>
19
20#include <linux/spi/spi.h>
21#include <linux/spi/eeprom.h>
22
23
24struct at25_data {
25 struct spi_device *spi;
26 struct mutex lock;
27 struct spi_eeprom chip;
28 struct bin_attribute bin;
29 unsigned addrlen;
30};
31
32#define AT25_WREN 0x06 /* latch the write enable */
33#define AT25_WRDI 0x04 /* reset the write enable */
34#define AT25_RDSR 0x05 /* read status register */
35#define AT25_WRSR 0x01 /* write status register */
36#define AT25_READ 0x03 /* read byte(s) */
37#define AT25_WRITE 0x02 /* write byte(s)/sector */
38
39#define AT25_SR_nRDY 0x01 /* nRDY = write-in-progress */
40#define AT25_SR_WEN 0x02 /* write enable (latched) */
41#define AT25_SR_BP0 0x04 /* BP for software writeprotect */
42#define AT25_SR_BP1 0x08
43#define AT25_SR_WPEN 0x80 /* writeprotect enable */
44
45
46#define EE_MAXADDRLEN 3 /* 24 bit addresses, up to 2 MBytes */
47
48/* Specs often allow 5 msec for a page write, sometimes 20 msec;
49 * it's important to recover from write timeouts.
50 */
51#define EE_TIMEOUT 25
52
53/*-------------------------------------------------------------------------*/
54
55#define io_limit PAGE_SIZE /* bytes */
56
57static ssize_t
58at25_ee_read(
59 struct at25_data *at25,
60 char *buf,
61 unsigned offset,
62 size_t count
63)
64{
65 u8 command[EE_MAXADDRLEN + 1];
66 u8 *cp;
67 ssize_t status;
68 struct spi_transfer t[2];
69 struct spi_message m;
70
71 cp = command;
72 *cp++ = AT25_READ;
73
74 /* 8/16/24-bit address is written MSB first */
75 switch (at25->addrlen) {
76 default: /* case 3 */
77 *cp++ = offset >> 16;
78 case 2:
79 *cp++ = offset >> 8;
80 case 1:
81 case 0: /* can't happen: for better codegen */
82 *cp++ = offset >> 0;
83 }
84
85 spi_message_init(&m);
86 memset(t, 0, sizeof t);
87
88 t[0].tx_buf = command;
89 t[0].len = at25->addrlen + 1;
90 spi_message_add_tail(&t[0], &m);
91
92 t[1].rx_buf = buf;
93 t[1].len = count;
94 spi_message_add_tail(&t[1], &m);
95
96 mutex_lock(&at25->lock);
97
98 /* Read it all at once.
99 *
100 * REVISIT that's potentially a problem with large chips, if
101 * other devices on the bus need to be accessed regularly or
102 * this chip is clocked very slowly
103 */
104 status = spi_sync(at25->spi, &m);
105 dev_dbg(&at25->spi->dev,
106 "read %Zd bytes at %d --> %d\n",
107 count, offset, (int) status);
108
109 mutex_unlock(&at25->lock);
110 return status ? status : count;
111}
112
113static ssize_t
114at25_bin_read(struct kobject *kobj, char *buf, loff_t off, size_t count)
115{
116 struct device *dev;
117 struct at25_data *at25;
118
119 dev = container_of(kobj, struct device, kobj);
120 at25 = dev_get_drvdata(dev);
121
122 if (unlikely(off >= at25->bin.size))
123 return 0;
124 if ((off + count) > at25->bin.size)
125 count = at25->bin.size - off;
126 if (unlikely(!count))
127 return count;
128
129 return at25_ee_read(at25, buf, off, count);
130}
131
132
133static ssize_t
134at25_ee_write(struct at25_data *at25, char *buf, loff_t off, size_t count)
135{
136 ssize_t status = 0;
137 unsigned written = 0;
138 unsigned buf_size;
139 u8 *bounce;
140
141 /* Temp buffer starts with command and address */
142 buf_size = at25->chip.page_size;
143 if (buf_size > io_limit)
144 buf_size = io_limit;
145 bounce = kmalloc(buf_size + at25->addrlen + 1, GFP_KERNEL);
146 if (!bounce)
147 return -ENOMEM;
148
149 /* For write, rollover is within the page ... so we write at
150 * most one page, then manually roll over to the next page.
151 */
152 bounce[0] = AT25_WRITE;
153 mutex_lock(&at25->lock);
154 do {
155 unsigned long timeout, retries;
156 unsigned segment;
157 unsigned offset = (unsigned) off;
158 u8 *cp = bounce + 1;
159
160 *cp = AT25_WREN;
161 status = spi_write(at25->spi, cp, 1);
162 if (status < 0) {
163 dev_dbg(&at25->spi->dev, "WREN --> %d\n",
164 (int) status);
165 break;
166 }
167
168 /* 8/16/24-bit address is written MSB first */
169 switch (at25->addrlen) {
170 default: /* case 3 */
171 *cp++ = offset >> 16;
172 case 2:
173 *cp++ = offset >> 8;
174 case 1:
175 case 0: /* can't happen: for better codegen */
176 *cp++ = offset >> 0;
177 }
178
179 /* Write as much of a page as we can */
180 segment = buf_size - (offset % buf_size);
181 if (segment > count)
182 segment = count;
183 memcpy(cp, buf, segment);
184 status = spi_write(at25->spi, bounce,
185 segment + at25->addrlen + 1);
186 dev_dbg(&at25->spi->dev,
187 "write %u bytes at %u --> %d\n",
188 segment, offset, (int) status);
189 if (status < 0)
190 break;
191
192 /* REVISIT this should detect (or prevent) failed writes
193 * to readonly sections of the EEPROM...
194 */
195
196 /* Wait for non-busy status */
197 timeout = jiffies + msecs_to_jiffies(EE_TIMEOUT);
198 retries = 0;
199 do {
200 int sr;
201
202 sr = spi_w8r8(at25->spi, AT25_RDSR);
203 if (sr < 0 || (sr & AT25_SR_nRDY)) {
204 dev_dbg(&at25->spi->dev,
205 "rdsr --> %d (%02x)\n", sr, sr);
206 /* at HZ=100, this is sloooow */
207 msleep(1);
208 continue;
209 }
210 if (!(sr & AT25_SR_nRDY))
211 break;
212 } while (retries++ < 3 || time_before_eq(jiffies, timeout));
213
214 if (time_after(jiffies, timeout)) {
215 dev_err(&at25->spi->dev,
216 "write %d bytes offset %d, "
217 "timeout after %u msecs\n",
218 segment, offset,
219 jiffies_to_msecs(jiffies -
220 (timeout - EE_TIMEOUT)));
221 status = -ETIMEDOUT;
222 break;
223 }
224
225 off += segment;
226 buf += segment;
227 count -= segment;
228 written += segment;
229
230 } while (count > 0);
231
232 mutex_unlock(&at25->lock);
233
234 kfree(bounce);
235 return written ? written : status;
236}
237
238static ssize_t
239at25_bin_write(struct kobject *kobj, char *buf, loff_t off, size_t count)
240{
241 struct device *dev;
242 struct at25_data *at25;
243
244 dev = container_of(kobj, struct device, kobj);
245 at25 = dev_get_drvdata(dev);
246
247 if (unlikely(off >= at25->bin.size))
248 return -EFBIG;
249 if ((off + count) > at25->bin.size)
250 count = at25->bin.size - off;
251 if (unlikely(!count))
252 return count;
253
254 return at25_ee_write(at25, buf, off, count);
255}
256
257/*-------------------------------------------------------------------------*/
258
259static int at25_probe(struct spi_device *spi)
260{
261 struct at25_data *at25 = NULL;
262 const struct spi_eeprom *chip;
263 int err;
264 int sr;
265 int addrlen;
266
267 /* Chip description */
268 chip = spi->dev.platform_data;
269 if (!chip) {
270 dev_dbg(&spi->dev, "no chip description\n");
271 err = -ENODEV;
272 goto fail;
273 }
274
275 /* For now we only support 8/16/24 bit addressing */
276 if (chip->flags & EE_ADDR1)
277 addrlen = 1;
278 else if (chip->flags & EE_ADDR2)
279 addrlen = 2;
280 else if (chip->flags & EE_ADDR3)
281 addrlen = 3;
282 else {
283 dev_dbg(&spi->dev, "unsupported address type\n");
284 err = -EINVAL;
285 goto fail;
286 }
287
288 /* Ping the chip ... the status register is pretty portable,
289 * unlike probing manufacturer IDs. We do expect that system
290 * firmware didn't write it in the past few milliseconds!
291 */
292 sr = spi_w8r8(spi, AT25_RDSR);
293 if (sr < 0 || sr & AT25_SR_nRDY) {
294 dev_dbg(&at25->spi->dev, "rdsr --> %d (%02x)\n", sr, sr);
295 err = -ENXIO;
296 goto fail;
297 }
298
299 if (!(at25 = kzalloc(sizeof *at25, GFP_KERNEL))) {
300 err = -ENOMEM;
301 goto fail;
302 }
303
304 mutex_init(&at25->lock);
305 at25->chip = *chip;
306 at25->spi = spi_dev_get(spi);
307 dev_set_drvdata(&spi->dev, at25);
308 at25->addrlen = addrlen;
309
310 /* Export the EEPROM bytes through sysfs, since that's convenient.
311 * Default to root-only access to the data; EEPROMs often hold data
312 * that's sensitive for read and/or write, like ethernet addresses,
313 * security codes, board-specific manufacturing calibrations, etc.
314 */
315 at25->bin.attr.name = "eeprom";
316 at25->bin.attr.mode = S_IRUSR;
317 at25->bin.attr.owner = THIS_MODULE;
318 at25->bin.read = at25_bin_read;
319
320 at25->bin.size = at25->chip.byte_len;
321 if (!(chip->flags & EE_READONLY)) {
322 at25->bin.write = at25_bin_write;
323 at25->bin.attr.mode |= S_IWUSR;
324 }
325
326 err = sysfs_create_bin_file(&spi->dev.kobj, &at25->bin);
327 if (err)
328 goto fail;
329
330 dev_info(&spi->dev, "%Zd %s %s eeprom%s, pagesize %u\n",
331 (at25->bin.size < 1024)
332 ? at25->bin.size
333 : (at25->bin.size / 1024),
334 (at25->bin.size < 1024) ? "Byte" : "KByte",
335 at25->chip.name,
336 (chip->flags & EE_READONLY) ? " (readonly)" : "",
337 at25->chip.page_size);
338 return 0;
339fail:
340 dev_dbg(&spi->dev, "probe err %d\n", err);
341 kfree(at25);
342 return err;
343}
344
345static int __devexit at25_remove(struct spi_device *spi)
346{
347 struct at25_data *at25;
348
349 at25 = dev_get_drvdata(&spi->dev);
350 sysfs_remove_bin_file(&spi->dev.kobj, &at25->bin);
351 kfree(at25);
352 return 0;
353}
354
355/*-------------------------------------------------------------------------*/
356
357static struct spi_driver at25_driver = {
358 .driver = {
359 .name = "at25",
360 .owner = THIS_MODULE,
361 },
362 .probe = at25_probe,
363 .remove = __devexit_p(at25_remove),
364};
365
366static int __init at25_init(void)
367{
368 return spi_register_driver(&at25_driver);
369}
370module_init(at25_init);
371
372static void __exit at25_exit(void)
373{
374 spi_unregister_driver(&at25_driver);
375}
376module_exit(at25_exit);
377
378MODULE_DESCRIPTION("Driver for most SPI EEPROMs");
379MODULE_AUTHOR("David Brownell");
380MODULE_LICENSE("GPL");
381
diff --git a/drivers/spi/omap_uwire.c b/drivers/spi/omap_uwire.c
new file mode 100644
index 00000000000..366af4959a0
--- /dev/null
+++ b/drivers/spi/omap_uwire.c
@@ -0,0 +1,572 @@
1/*
2 * omap_uwire.c -- MicroWire interface driver for OMAP
3 *
4 * Copyright 2003 MontaVista Software Inc. <source@mvista.com>
5 *
6 * Ported to 2.6 OMAP uwire interface.
7 * Copyright (C) 2004 Texas Instruments.
8 *
9 * Generalization patches by Juha Yrjola <juha.yrjola@nokia.com>
10 *
11 * Copyright (C) 2005 David Brownell (ported to 2.6 SPI interface)
12 * Copyright (C) 2006 Nokia
13 *
14 * Many updates by Imre Deak <imre.deak@nokia.com>
15 *
16 * This program is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2 of the License, or (at your
19 * option) any later version.
20 *
21 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
28 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * You should have received a copy of the GNU General Public License along
33 * with this program; if not, write to the Free Software Foundation, Inc.,
34 * 675 Mass Ave, Cambridge, MA 02139, USA.
35 */
36#include <linux/kernel.h>
37#include <linux/init.h>
38#include <linux/delay.h>
39#include <linux/platform_device.h>
40#include <linux/workqueue.h>
41#include <linux/interrupt.h>
42#include <linux/err.h>
43#include <linux/clk.h>
44
45#include <linux/spi/spi.h>
46#include <linux/spi/spi_bitbang.h>
47
48#include <asm/system.h>
49#include <asm/irq.h>
50#include <asm/hardware.h>
51#include <asm/io.h>
52#include <asm/mach-types.h>
53
54#include <asm/arch/mux.h>
55#include <asm/arch/omap730.h> /* OMAP730_IO_CONF registers */
56
57
58/* FIXME address is now a platform device resource,
59 * and irqs should show there too...
60 */
61#define UWIRE_BASE_PHYS 0xFFFB3000
62#define UWIRE_BASE ((void *__iomem)IO_ADDRESS(UWIRE_BASE_PHYS))
63
64/* uWire Registers: */
65#define UWIRE_IO_SIZE 0x20
66#define UWIRE_TDR 0x00
67#define UWIRE_RDR 0x00
68#define UWIRE_CSR 0x01
69#define UWIRE_SR1 0x02
70#define UWIRE_SR2 0x03
71#define UWIRE_SR3 0x04
72#define UWIRE_SR4 0x05
73#define UWIRE_SR5 0x06
74
75/* CSR bits */
76#define RDRB (1 << 15)
77#define CSRB (1 << 14)
78#define START (1 << 13)
79#define CS_CMD (1 << 12)
80
81/* SR1 or SR2 bits */
82#define UWIRE_READ_FALLING_EDGE 0x0001
83#define UWIRE_READ_RISING_EDGE 0x0000
84#define UWIRE_WRITE_FALLING_EDGE 0x0000
85#define UWIRE_WRITE_RISING_EDGE 0x0002
86#define UWIRE_CS_ACTIVE_LOW 0x0000
87#define UWIRE_CS_ACTIVE_HIGH 0x0004
88#define UWIRE_FREQ_DIV_2 0x0000
89#define UWIRE_FREQ_DIV_4 0x0008
90#define UWIRE_FREQ_DIV_8 0x0010
91#define UWIRE_CHK_READY 0x0020
92#define UWIRE_CLK_INVERTED 0x0040
93
94
95struct uwire_spi {
96 struct spi_bitbang bitbang;
97 struct clk *ck;
98};
99
100struct uwire_state {
101 unsigned bits_per_word;
102 unsigned div1_idx;
103};
104
105/* REVISIT compile time constant for idx_shift? */
106static unsigned int uwire_idx_shift;
107
108static inline void uwire_write_reg(int idx, u16 val)
109{
110 __raw_writew(val, UWIRE_BASE + (idx << uwire_idx_shift));
111}
112
113static inline u16 uwire_read_reg(int idx)
114{
115 return __raw_readw(UWIRE_BASE + (idx << uwire_idx_shift));
116}
117
118static inline void omap_uwire_configure_mode(u8 cs, unsigned long flags)
119{
120 u16 w, val = 0;
121 int shift, reg;
122
123 if (flags & UWIRE_CLK_INVERTED)
124 val ^= 0x03;
125 val = flags & 0x3f;
126 if (cs & 1)
127 shift = 6;
128 else
129 shift = 0;
130 if (cs <= 1)
131 reg = UWIRE_SR1;
132 else
133 reg = UWIRE_SR2;
134
135 w = uwire_read_reg(reg);
136 w &= ~(0x3f << shift);
137 w |= val << shift;
138 uwire_write_reg(reg, w);
139}
140
141static int wait_uwire_csr_flag(u16 mask, u16 val, int might_not_catch)
142{
143 u16 w;
144 int c = 0;
145 unsigned long max_jiffies = jiffies + HZ;
146
147 for (;;) {
148 w = uwire_read_reg(UWIRE_CSR);
149 if ((w & mask) == val)
150 break;
151 if (time_after(jiffies, max_jiffies)) {
152 printk(KERN_ERR "%s: timeout. reg=%#06x "
153 "mask=%#06x val=%#06x\n",
154 __FUNCTION__, w, mask, val);
155 return -1;
156 }
157 c++;
158 if (might_not_catch && c > 64)
159 break;
160 }
161 return 0;
162}
163
164static void uwire_set_clk1_div(int div1_idx)
165{
166 u16 w;
167
168 w = uwire_read_reg(UWIRE_SR3);
169 w &= ~(0x03 << 1);
170 w |= div1_idx << 1;
171 uwire_write_reg(UWIRE_SR3, w);
172}
173
174static void uwire_chipselect(struct spi_device *spi, int value)
175{
176 struct uwire_state *ust = spi->controller_state;
177 u16 w;
178 int old_cs;
179
180
181 BUG_ON(wait_uwire_csr_flag(CSRB, 0, 0));
182
183 w = uwire_read_reg(UWIRE_CSR);
184 old_cs = (w >> 10) & 0x03;
185 if (value == BITBANG_CS_INACTIVE || old_cs != spi->chip_select) {
186 /* Deselect this CS, or the previous CS */
187 w &= ~CS_CMD;
188 uwire_write_reg(UWIRE_CSR, w);
189 }
190 /* activate specfied chipselect */
191 if (value == BITBANG_CS_ACTIVE) {
192 uwire_set_clk1_div(ust->div1_idx);
193 /* invert clock? */
194 if (spi->mode & SPI_CPOL)
195 uwire_write_reg(UWIRE_SR4, 1);
196 else
197 uwire_write_reg(UWIRE_SR4, 0);
198
199 w = spi->chip_select << 10;
200 w |= CS_CMD;
201 uwire_write_reg(UWIRE_CSR, w);
202 }
203}
204
205static int uwire_txrx(struct spi_device *spi, struct spi_transfer *t)
206{
207 struct uwire_state *ust = spi->controller_state;
208 unsigned len = t->len;
209 unsigned bits = ust->bits_per_word;
210 unsigned bytes;
211 u16 val, w;
212 int status = 0;;
213
214 if (!t->tx_buf && !t->rx_buf)
215 return 0;
216
217 /* Microwire doesn't read and write concurrently */
218 if (t->tx_buf && t->rx_buf)
219 return -EPERM;
220
221 w = spi->chip_select << 10;
222 w |= CS_CMD;
223
224 if (t->tx_buf) {
225 const u8 *buf = t->tx_buf;
226
227 /* NOTE: DMA could be used for TX transfers */
228
229 /* write one or two bytes at a time */
230 while (len >= 1) {
231 /* tx bit 15 is first sent; we byteswap multibyte words
232 * (msb-first) on the way out from memory.
233 */
234 val = *buf++;
235 if (bits > 8) {
236 bytes = 2;
237 val |= *buf++ << 8;
238 } else
239 bytes = 1;
240 val <<= 16 - bits;
241
242#ifdef VERBOSE
243 pr_debug("%s: write-%d =%04x\n",
244 spi->dev.bus_id, bits, val);
245#endif
246 if (wait_uwire_csr_flag(CSRB, 0, 0))
247 goto eio;
248
249 uwire_write_reg(UWIRE_TDR, val);
250
251 /* start write */
252 val = START | w | (bits << 5);
253
254 uwire_write_reg(UWIRE_CSR, val);
255 len -= bytes;
256
257 /* Wait till write actually starts.
258 * This is needed with MPU clock 60+ MHz.
259 * REVISIT: we may not have time to catch it...
260 */
261 if (wait_uwire_csr_flag(CSRB, CSRB, 1))
262 goto eio;
263
264 status += bytes;
265 }
266
267 /* REVISIT: save this for later to get more i/o overlap */
268 if (wait_uwire_csr_flag(CSRB, 0, 0))
269 goto eio;
270
271 } else if (t->rx_buf) {
272 u8 *buf = t->rx_buf;
273
274 /* read one or two bytes at a time */
275 while (len) {
276 if (bits > 8) {
277 bytes = 2;
278 } else
279 bytes = 1;
280
281 /* start read */
282 val = START | w | (bits << 0);
283 uwire_write_reg(UWIRE_CSR, val);
284 len -= bytes;
285
286 /* Wait till read actually starts */
287 (void) wait_uwire_csr_flag(CSRB, CSRB, 1);
288
289 if (wait_uwire_csr_flag(RDRB | CSRB,
290 RDRB, 0))
291 goto eio;
292
293 /* rx bit 0 is last received; multibyte words will
294 * be properly byteswapped on the way to memory.
295 */
296 val = uwire_read_reg(UWIRE_RDR);
297 val &= (1 << bits) - 1;
298 *buf++ = (u8) val;
299 if (bytes == 2)
300 *buf++ = val >> 8;
301 status += bytes;
302#ifdef VERBOSE
303 pr_debug("%s: read-%d =%04x\n",
304 spi->dev.bus_id, bits, val);
305#endif
306
307 }
308 }
309 return status;
310eio:
311 return -EIO;
312}
313
314static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
315{
316 struct uwire_state *ust = spi->controller_state;
317 struct uwire_spi *uwire;
318 unsigned flags = 0;
319 unsigned bits;
320 unsigned hz;
321 unsigned long rate;
322 int div1_idx;
323 int div1;
324 int div2;
325 int status;
326
327 uwire = spi_master_get_devdata(spi->master);
328
329 if (spi->chip_select > 3) {
330 pr_debug("%s: cs%d?\n", spi->dev.bus_id, spi->chip_select);
331 status = -ENODEV;
332 goto done;
333 }
334
335 bits = spi->bits_per_word;
336 if (t != NULL && t->bits_per_word)
337 bits = t->bits_per_word;
338 if (!bits)
339 bits = 8;
340
341 if (bits > 16) {
342 pr_debug("%s: wordsize %d?\n", spi->dev.bus_id, bits);
343 status = -ENODEV;
344 goto done;
345 }
346 ust->bits_per_word = bits;
347
348 /* mode 0..3, clock inverted separately;
349 * standard nCS signaling;
350 * don't treat DI=high as "not ready"
351 */
352 if (spi->mode & SPI_CS_HIGH)
353 flags |= UWIRE_CS_ACTIVE_HIGH;
354
355 if (spi->mode & SPI_CPOL)
356 flags |= UWIRE_CLK_INVERTED;
357
358 switch (spi->mode & (SPI_CPOL | SPI_CPHA)) {
359 case SPI_MODE_0:
360 case SPI_MODE_3:
361 flags |= UWIRE_WRITE_RISING_EDGE | UWIRE_READ_FALLING_EDGE;
362 break;
363 case SPI_MODE_1:
364 case SPI_MODE_2:
365 flags |= UWIRE_WRITE_FALLING_EDGE | UWIRE_READ_RISING_EDGE;
366 break;
367 }
368
369 /* assume it's already enabled */
370 rate = clk_get_rate(uwire->ck);
371
372 hz = spi->max_speed_hz;
373 if (t != NULL && t->speed_hz)
374 hz = t->speed_hz;
375
376 if (!hz) {
377 pr_debug("%s: zero speed?\n", spi->dev.bus_id);
378 status = -EINVAL;
379 goto done;
380 }
381
382 /* F_INT = mpu_xor_clk / DIV1 */
383 for (div1_idx = 0; div1_idx < 4; div1_idx++) {
384 switch (div1_idx) {
385 case 0:
386 div1 = 2;
387 break;
388 case 1:
389 div1 = 4;
390 break;
391 case 2:
392 div1 = 7;
393 break;
394 default:
395 case 3:
396 div1 = 10;
397 break;
398 }
399 div2 = (rate / div1 + hz - 1) / hz;
400 if (div2 <= 8)
401 break;
402 }
403 if (div1_idx == 4) {
404 pr_debug("%s: lowest clock %ld, need %d\n",
405 spi->dev.bus_id, rate / 10 / 8, hz);
406 status = -EDOM;
407 goto done;
408 }
409
410 /* we have to cache this and reset in uwire_chipselect as this is a
411 * global parameter and another uwire device can change it under
412 * us */
413 ust->div1_idx = div1_idx;
414 uwire_set_clk1_div(div1_idx);
415
416 rate /= div1;
417
418 switch (div2) {
419 case 0:
420 case 1:
421 case 2:
422 flags |= UWIRE_FREQ_DIV_2;
423 rate /= 2;
424 break;
425 case 3:
426 case 4:
427 flags |= UWIRE_FREQ_DIV_4;
428 rate /= 4;
429 break;
430 case 5:
431 case 6:
432 case 7:
433 case 8:
434 flags |= UWIRE_FREQ_DIV_8;
435 rate /= 8;
436 break;
437 }
438 omap_uwire_configure_mode(spi->chip_select, flags);
439 pr_debug("%s: uwire flags %02x, armxor %lu KHz, SCK %lu KHz\n",
440 __FUNCTION__, flags,
441 clk_get_rate(uwire->ck) / 1000,
442 rate / 1000);
443 status = 0;
444done:
445 return status;
446}
447
448static int uwire_setup(struct spi_device *spi)
449{
450 struct uwire_state *ust = spi->controller_state;
451
452 if (ust == NULL) {
453 ust = kzalloc(sizeof(*ust), GFP_KERNEL);
454 if (ust == NULL)
455 return -ENOMEM;
456 spi->controller_state = ust;
457 }
458
459 return uwire_setup_transfer(spi, NULL);
460}
461
462static void uwire_cleanup(const struct spi_device *spi)
463{
464 kfree(spi->controller_state);
465}
466
467static void uwire_off(struct uwire_spi *uwire)
468{
469 uwire_write_reg(UWIRE_SR3, 0);
470 clk_disable(uwire->ck);
471 clk_put(uwire->ck);
472 spi_master_put(uwire->bitbang.master);
473}
474
475static int uwire_probe(struct platform_device *pdev)
476{
477 struct spi_master *master;
478 struct uwire_spi *uwire;
479 int status;
480
481 master = spi_alloc_master(&pdev->dev, sizeof *uwire);
482 if (!master)
483 return -ENODEV;
484
485 uwire = spi_master_get_devdata(master);
486 dev_set_drvdata(&pdev->dev, uwire);
487
488 uwire->ck = clk_get(&pdev->dev, "armxor_ck");
489 if (!uwire->ck || IS_ERR(uwire->ck)) {
490 dev_dbg(&pdev->dev, "no mpu_xor_clk ?\n");
491 spi_master_put(master);
492 return -ENODEV;
493 }
494 clk_enable(uwire->ck);
495
496 if (cpu_is_omap730())
497 uwire_idx_shift = 1;
498 else
499 uwire_idx_shift = 2;
500
501 uwire_write_reg(UWIRE_SR3, 1);
502
503 master->bus_num = 2; /* "official" */
504 master->num_chipselect = 4;
505 master->setup = uwire_setup;
506 master->cleanup = uwire_cleanup;
507
508 uwire->bitbang.master = master;
509 uwire->bitbang.chipselect = uwire_chipselect;
510 uwire->bitbang.setup_transfer = uwire_setup_transfer;
511 uwire->bitbang.txrx_bufs = uwire_txrx;
512
513 status = spi_bitbang_start(&uwire->bitbang);
514 if (status < 0)
515 uwire_off(uwire);
516 return status;
517}
518
519static int uwire_remove(struct platform_device *pdev)
520{
521 struct uwire_spi *uwire = dev_get_drvdata(&pdev->dev);
522 int status;
523
524 // FIXME remove all child devices, somewhere ...
525
526 status = spi_bitbang_stop(&uwire->bitbang);
527 uwire_off(uwire);
528 return status;
529}
530
531static struct platform_driver uwire_driver = {
532 .driver = {
533 .name = "omap_uwire",
534 .bus = &platform_bus_type,
535 .owner = THIS_MODULE,
536 },
537 .probe = uwire_probe,
538 .remove = uwire_remove,
539 // suspend ... unuse ck
540 // resume ... use ck
541};
542
543static int __init omap_uwire_init(void)
544{
545 /* FIXME move these into the relevant board init code. also, include
546 * H3 support; it uses tsc2101 like H2 (on a different chipselect).
547 */
548
549 if (machine_is_omap_h2()) {
550 /* defaults: W21 SDO, U18 SDI, V19 SCL */
551 omap_cfg_reg(N14_1610_UWIRE_CS0);
552 omap_cfg_reg(N15_1610_UWIRE_CS1);
553 }
554 if (machine_is_omap_perseus2()) {
555 /* configure pins: MPU_UW_nSCS1, MPU_UW_SDO, MPU_UW_SCLK */
556 int val = omap_readl(OMAP730_IO_CONF_9) & ~0x00EEE000;
557 omap_writel(val | 0x00AAA000, OMAP730_IO_CONF_9);
558 }
559
560 return platform_driver_register(&uwire_driver);
561}
562
563static void __exit omap_uwire_exit(void)
564{
565 platform_driver_unregister(&uwire_driver);
566}
567
568subsys_initcall(omap_uwire_init);
569module_exit(omap_uwire_exit);
570
571MODULE_LICENSE("GPL");
572
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index 8b41f9cc256..9f2c887ffa0 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -1214,9 +1214,9 @@ static int setup(struct spi_device *spi)
1214 return 0; 1214 return 0;
1215} 1215}
1216 1216
1217static void cleanup(const struct spi_device *spi) 1217static void cleanup(struct spi_device *spi)
1218{ 1218{
1219 struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi); 1219 struct chip_data *chip = spi_get_ctldata(spi);
1220 1220
1221 kfree(chip); 1221 kfree(chip);
1222} 1222}
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 6307428d2c9..2328128728b 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -32,7 +32,7 @@
32 */ 32 */
33static void spidev_release(struct device *dev) 33static void spidev_release(struct device *dev)
34{ 34{
35 const struct spi_device *spi = to_spi_device(dev); 35 struct spi_device *spi = to_spi_device(dev);
36 36
37 /* spi masters may cleanup for released devices */ 37 /* spi masters may cleanup for released devices */
38 if (spi->master->cleanup) 38 if (spi->master->cleanup)
diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c
index 57289b61d0b..24a330d8239 100644
--- a/drivers/spi/spi_bitbang.c
+++ b/drivers/spi/spi_bitbang.c
@@ -210,7 +210,7 @@ int spi_bitbang_setup(struct spi_device *spi)
210 if (!cs->txrx_word) 210 if (!cs->txrx_word)
211 return -EINVAL; 211 return -EINVAL;
212 212
213 retval = spi_bitbang_setup_transfer(spi, NULL); 213 retval = bitbang->setup_transfer(spi, NULL);
214 if (retval < 0) 214 if (retval < 0)
215 return retval; 215 return retval;
216 216
@@ -238,7 +238,7 @@ EXPORT_SYMBOL_GPL(spi_bitbang_setup);
238/** 238/**
239 * spi_bitbang_cleanup - default cleanup for per-word I/O loops 239 * spi_bitbang_cleanup - default cleanup for per-word I/O loops
240 */ 240 */
241void spi_bitbang_cleanup(const struct spi_device *spi) 241void spi_bitbang_cleanup(struct spi_device *spi)
242{ 242{
243 kfree(spi->controller_state); 243 kfree(spi->controller_state);
244} 244}
@@ -442,9 +442,10 @@ EXPORT_SYMBOL_GPL(spi_bitbang_transfer);
442 * hardware that basically exposes a shift register) or per-spi_transfer 442 * hardware that basically exposes a shift register) or per-spi_transfer
443 * (which takes better advantage of hardware like fifos or DMA engines). 443 * (which takes better advantage of hardware like fifos or DMA engines).
444 * 444 *
445 * Drivers using per-word I/O loops should use (or call) spi_bitbang_setup and 445 * Drivers using per-word I/O loops should use (or call) spi_bitbang_setup,
446 * spi_bitbang_cleanup to handle those spi master methods. Those methods are 446 * spi_bitbang_cleanup and spi_bitbang_setup_transfer to handle those spi
447 * the defaults if the bitbang->txrx_bufs routine isn't initialized. 447 * master methods. Those methods are the defaults if the bitbang->txrx_bufs
448 * routine isn't initialized.
448 * 449 *
449 * This routine registers the spi_master, which will process requests in a 450 * This routine registers the spi_master, which will process requests in a
450 * dedicated task, keeping IRQs unblocked most of the time. To stop 451 * dedicated task, keeping IRQs unblocked most of the time. To stop
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
new file mode 100644
index 00000000000..6ccf8a12a21
--- /dev/null
+++ b/drivers/spi/spi_imx.c
@@ -0,0 +1,1769 @@
1/*
2 * drivers/spi/spi_imx.c
3 *
4 * Copyright (C) 2006 SWAPP
5 * Andrea Paterniani <a.paterniani@swapp-eng.it>
6 *
7 * Initial version inspired by:
8 * linux-2.6.17-rc3-mm1/drivers/spi/pxa2xx_spi.c
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/init.h>
22#include <linux/module.h>
23#include <linux/device.h>
24#include <linux/ioport.h>
25#include <linux/errno.h>
26#include <linux/interrupt.h>
27#include <linux/platform_device.h>
28#include <linux/dma-mapping.h>
29#include <linux/spi/spi.h>
30#include <linux/workqueue.h>
31#include <linux/delay.h>
32
33#include <asm/io.h>
34#include <asm/irq.h>
35#include <asm/hardware.h>
36#include <asm/delay.h>
37
38#include <asm/arch/hardware.h>
39#include <asm/arch/imx-dma.h>
40#include <asm/arch/spi_imx.h>
41
42/*-------------------------------------------------------------------------*/
43/* SPI Registers offsets from peripheral base address */
44#define SPI_RXDATA (0x00)
45#define SPI_TXDATA (0x04)
46#define SPI_CONTROL (0x08)
47#define SPI_INT_STATUS (0x0C)
48#define SPI_TEST (0x10)
49#define SPI_PERIOD (0x14)
50#define SPI_DMA (0x18)
51#define SPI_RESET (0x1C)
52
53/* SPI Control Register Bit Fields & Masks */
54#define SPI_CONTROL_BITCOUNT_MASK (0xF) /* Bit Count Mask */
55#define SPI_CONTROL_BITCOUNT(n) (((n) - 1) & SPI_CONTROL_BITCOUNT_MASK)
56#define SPI_CONTROL_POL (0x1 << 4) /* Clock Polarity Mask */
57#define SPI_CONTROL_POL_ACT_HIGH (0x0 << 4) /* Active high pol. (0=idle) */
58#define SPI_CONTROL_POL_ACT_LOW (0x1 << 4) /* Active low pol. (1=idle) */
59#define SPI_CONTROL_PHA (0x1 << 5) /* Clock Phase Mask */
60#define SPI_CONTROL_PHA_0 (0x0 << 5) /* Clock Phase 0 */
61#define SPI_CONTROL_PHA_1 (0x1 << 5) /* Clock Phase 1 */
62#define SPI_CONTROL_SSCTL (0x1 << 6) /* /SS Waveform Select Mask */
63#define SPI_CONTROL_SSCTL_0 (0x0 << 6) /* Master: /SS stays low between SPI burst
64 Slave: RXFIFO advanced by BIT_COUNT */
65#define SPI_CONTROL_SSCTL_1 (0x1 << 6) /* Master: /SS insert pulse between SPI burst
66 Slave: RXFIFO advanced by /SS rising edge */
67#define SPI_CONTROL_SSPOL (0x1 << 7) /* /SS Polarity Select Mask */
68#define SPI_CONTROL_SSPOL_ACT_LOW (0x0 << 7) /* /SS Active low */
69#define SPI_CONTROL_SSPOL_ACT_HIGH (0x1 << 7) /* /SS Active high */
70#define SPI_CONTROL_XCH (0x1 << 8) /* Exchange */
71#define SPI_CONTROL_SPIEN (0x1 << 9) /* SPI Module Enable */
72#define SPI_CONTROL_MODE (0x1 << 10) /* SPI Mode Select Mask */
73#define SPI_CONTROL_MODE_SLAVE (0x0 << 10) /* SPI Mode Slave */
74#define SPI_CONTROL_MODE_MASTER (0x1 << 10) /* SPI Mode Master */
75#define SPI_CONTROL_DRCTL (0x3 << 11) /* /SPI_RDY Control Mask */
76#define SPI_CONTROL_DRCTL_0 (0x0 << 11) /* Ignore /SPI_RDY */
77#define SPI_CONTROL_DRCTL_1 (0x1 << 11) /* /SPI_RDY falling edge triggers input */
78#define SPI_CONTROL_DRCTL_2 (0x2 << 11) /* /SPI_RDY active low level triggers input */
79#define SPI_CONTROL_DATARATE (0x7 << 13) /* Data Rate Mask */
80#define SPI_PERCLK2_DIV_MIN (0) /* PERCLK2:4 */
81#define SPI_PERCLK2_DIV_MAX (7) /* PERCLK2:512 */
82#define SPI_CONTROL_DATARATE_MIN (SPI_PERCLK2_DIV_MAX << 13)
83#define SPI_CONTROL_DATARATE_MAX (SPI_PERCLK2_DIV_MIN << 13)
84#define SPI_CONTROL_DATARATE_BAD (SPI_CONTROL_DATARATE_MIN + 1)
85
86/* SPI Interrupt/Status Register Bit Fields & Masks */
87#define SPI_STATUS_TE (0x1 << 0) /* TXFIFO Empty Status */
88#define SPI_STATUS_TH (0x1 << 1) /* TXFIFO Half Status */
89#define SPI_STATUS_TF (0x1 << 2) /* TXFIFO Full Status */
90#define SPI_STATUS_RR (0x1 << 3) /* RXFIFO Data Ready Status */
91#define SPI_STATUS_RH (0x1 << 4) /* RXFIFO Half Status */
92#define SPI_STATUS_RF (0x1 << 5) /* RXFIFO Full Status */
93#define SPI_STATUS_RO (0x1 << 6) /* RXFIFO Overflow */
94#define SPI_STATUS_BO (0x1 << 7) /* Bit Count Overflow */
95#define SPI_STATUS (0xFF) /* SPI Status Mask */
96#define SPI_INTEN_TE (0x1 << 8) /* TXFIFO Empty Interrupt Enable */
97#define SPI_INTEN_TH (0x1 << 9) /* TXFIFO Half Interrupt Enable */
98#define SPI_INTEN_TF (0x1 << 10) /* TXFIFO Full Interrupt Enable */
99#define SPI_INTEN_RE (0x1 << 11) /* RXFIFO Data Ready Interrupt Enable */
100#define SPI_INTEN_RH (0x1 << 12) /* RXFIFO Half Interrupt Enable */
101#define SPI_INTEN_RF (0x1 << 13) /* RXFIFO Full Interrupt Enable */
102#define SPI_INTEN_RO (0x1 << 14) /* RXFIFO Overflow Interrupt Enable */
103#define SPI_INTEN_BO (0x1 << 15) /* Bit Count Overflow Interrupt Enable */
104#define SPI_INTEN (0xFF << 8) /* SPI Interrupt Enable Mask */
105
106/* SPI Test Register Bit Fields & Masks */
107#define SPI_TEST_TXCNT (0xF << 0) /* TXFIFO Counter */
108#define SPI_TEST_RXCNT_LSB (4) /* RXFIFO Counter LSB */
109#define SPI_TEST_RXCNT (0xF << 4) /* RXFIFO Counter */
110#define SPI_TEST_SSTATUS (0xF << 8) /* State Machine Status */
111#define SPI_TEST_LBC (0x1 << 14) /* Loop Back Control */
112
113/* SPI Period Register Bit Fields & Masks */
114#define SPI_PERIOD_WAIT (0x7FFF << 0) /* Wait Between Transactions */
115#define SPI_PERIOD_MAX_WAIT (0x7FFF) /* Max Wait Between
116 Transactions */
117#define SPI_PERIOD_CSRC (0x1 << 15) /* Period Clock Source Mask */
118#define SPI_PERIOD_CSRC_BCLK (0x0 << 15) /* Period Clock Source is
119 Bit Clock */
120#define SPI_PERIOD_CSRC_32768 (0x1 << 15) /* Period Clock Source is
121 32.768 KHz Clock */
122
123/* SPI DMA Register Bit Fields & Masks */
124#define SPI_DMA_RHDMA (0xF << 4) /* RXFIFO Half Status */
125#define SPI_DMA_RFDMA (0x1 << 5) /* RXFIFO Full Status */
126#define SPI_DMA_TEDMA (0x1 << 6) /* TXFIFO Empty Status */
127#define SPI_DMA_THDMA (0x1 << 7) /* TXFIFO Half Status */
128#define SPI_DMA_RHDEN (0x1 << 12) /* RXFIFO Half DMA Request Enable */
129#define SPI_DMA_RFDEN (0x1 << 13) /* RXFIFO Full DMA Request Enable */
130#define SPI_DMA_TEDEN (0x1 << 14) /* TXFIFO Empty DMA Request Enable */
131#define SPI_DMA_THDEN (0x1 << 15) /* TXFIFO Half DMA Request Enable */
132
133/* SPI Soft Reset Register Bit Fields & Masks */
134#define SPI_RESET_START (0x1) /* Start */
135
136/* Default SPI configuration values */
137#define SPI_DEFAULT_CONTROL \
138( \
139 SPI_CONTROL_BITCOUNT(16) | \
140 SPI_CONTROL_POL_ACT_HIGH | \
141 SPI_CONTROL_PHA_0 | \
142 SPI_CONTROL_SPIEN | \
143 SPI_CONTROL_SSCTL_1 | \
144 SPI_CONTROL_MODE_MASTER | \
145 SPI_CONTROL_DRCTL_0 | \
146 SPI_CONTROL_DATARATE_MIN \
147)
148#define SPI_DEFAULT_ENABLE_LOOPBACK (0)
149#define SPI_DEFAULT_ENABLE_DMA (0)
150#define SPI_DEFAULT_PERIOD_WAIT (8)
151/*-------------------------------------------------------------------------*/
152
153
154/*-------------------------------------------------------------------------*/
155/* TX/RX SPI FIFO size */
156#define SPI_FIFO_DEPTH (8)
157#define SPI_FIFO_BYTE_WIDTH (2)
158#define SPI_FIFO_OVERFLOW_MARGIN (2)
159
160/* DMA burst lenght for half full/empty request trigger */
161#define SPI_DMA_BLR (SPI_FIFO_DEPTH * SPI_FIFO_BYTE_WIDTH / 2)
162
163/* Dummy char output to achieve reads.
164 Choosing something different from all zeroes may help pattern recogition
165 for oscilloscope analysis, but may break some drivers. */
166#define SPI_DUMMY_u8 0
167#define SPI_DUMMY_u16 ((SPI_DUMMY_u8 << 8) | SPI_DUMMY_u8)
168#define SPI_DUMMY_u32 ((SPI_DUMMY_u16 << 16) | SPI_DUMMY_u16)
169
170/**
171 * Macro to change a u32 field:
172 * @r : register to edit
173 * @m : bit mask
174 * @v : new value for the field correctly bit-alligned
175*/
176#define u32_EDIT(r, m, v) r = (r & ~(m)) | (v)
177
178/* Message state */
179#define START_STATE ((void*)0)
180#define RUNNING_STATE ((void*)1)
181#define DONE_STATE ((void*)2)
182#define ERROR_STATE ((void*)-1)
183
184/* Queue state */
185#define QUEUE_RUNNING (0)
186#define QUEUE_STOPPED (1)
187
188#define IS_DMA_ALIGNED(x) (((u32)(x) & 0x03) == 0)
189/*-------------------------------------------------------------------------*/
190
191
192/*-------------------------------------------------------------------------*/
193/* Driver data structs */
194
195/* Context */
196struct driver_data {
197 /* Driver model hookup */
198 struct platform_device *pdev;
199
200 /* SPI framework hookup */
201 struct spi_master *master;
202
203 /* IMX hookup */
204 struct spi_imx_master *master_info;
205
206 /* Memory resources and SPI regs virtual address */
207 struct resource *ioarea;
208 void __iomem *regs;
209
210 /* SPI RX_DATA physical address */
211 dma_addr_t rd_data_phys;
212
213 /* Driver message queue */
214 struct workqueue_struct *workqueue;
215 struct work_struct work;
216 spinlock_t lock;
217 struct list_head queue;
218 int busy;
219 int run;
220
221 /* Message Transfer pump */
222 struct tasklet_struct pump_transfers;
223
224 /* Current message, transfer and state */
225 struct spi_message *cur_msg;
226 struct spi_transfer *cur_transfer;
227 struct chip_data *cur_chip;
228
229 /* Rd / Wr buffers pointers */
230 size_t len;
231 void *tx;
232 void *tx_end;
233 void *rx;
234 void *rx_end;
235
236 u8 rd_only;
237 u8 n_bytes;
238 int cs_change;
239
240 /* Function pointers */
241 irqreturn_t (*transfer_handler)(struct driver_data *drv_data);
242 void (*cs_control)(u32 command);
243
244 /* DMA setup */
245 int rx_channel;
246 int tx_channel;
247 dma_addr_t rx_dma;
248 dma_addr_t tx_dma;
249 int rx_dma_needs_unmap;
250 int tx_dma_needs_unmap;
251 size_t tx_map_len;
252 u32 dummy_dma_buf ____cacheline_aligned;
253};
254
255/* Runtime state */
256struct chip_data {
257 u32 control;
258 u32 period;
259 u32 test;
260
261 u8 enable_dma:1;
262 u8 bits_per_word;
263 u8 n_bytes;
264 u32 max_speed_hz;
265
266 void (*cs_control)(u32 command);
267};
268/*-------------------------------------------------------------------------*/
269
270
271static void pump_messages(struct work_struct *work);
272
273static int flush(struct driver_data *drv_data)
274{
275 unsigned long limit = loops_per_jiffy << 1;
276 void __iomem *regs = drv_data->regs;
277 volatile u32 d;
278
279 dev_dbg(&drv_data->pdev->dev, "flush\n");
280 do {
281 while (readl(regs + SPI_INT_STATUS) & SPI_STATUS_RR)
282 d = readl(regs + SPI_RXDATA);
283 } while ((readl(regs + SPI_CONTROL) & SPI_CONTROL_XCH) && limit--);
284
285 return limit;
286}
287
288static void restore_state(struct driver_data *drv_data)
289{
290 void __iomem *regs = drv_data->regs;
291 struct chip_data *chip = drv_data->cur_chip;
292
293 /* Load chip registers */
294 dev_dbg(&drv_data->pdev->dev,
295 "restore_state\n"
296 " test = 0x%08X\n"
297 " control = 0x%08X\n",
298 chip->test,
299 chip->control);
300 writel(chip->test, regs + SPI_TEST);
301 writel(chip->period, regs + SPI_PERIOD);
302 writel(0, regs + SPI_INT_STATUS);
303 writel(chip->control, regs + SPI_CONTROL);
304}
305
306static void null_cs_control(u32 command)
307{
308}
309
310static inline u32 data_to_write(struct driver_data *drv_data)
311{
312 return ((u32)(drv_data->tx_end - drv_data->tx)) / drv_data->n_bytes;
313}
314
315static inline u32 data_to_read(struct driver_data *drv_data)
316{
317 return ((u32)(drv_data->rx_end - drv_data->rx)) / drv_data->n_bytes;
318}
319
320static int write(struct driver_data *drv_data)
321{
322 void __iomem *regs = drv_data->regs;
323 void *tx = drv_data->tx;
324 void *tx_end = drv_data->tx_end;
325 u8 n_bytes = drv_data->n_bytes;
326 u32 remaining_writes;
327 u32 fifo_avail_space;
328 u32 n;
329 u16 d;
330
331 /* Compute how many fifo writes to do */
332 remaining_writes = (u32)(tx_end - tx) / n_bytes;
333 fifo_avail_space = SPI_FIFO_DEPTH -
334 (readl(regs + SPI_TEST) & SPI_TEST_TXCNT);
335 if (drv_data->rx && (fifo_avail_space > SPI_FIFO_OVERFLOW_MARGIN))
336 /* Fix misunderstood receive overflow */
337 fifo_avail_space -= SPI_FIFO_OVERFLOW_MARGIN;
338 n = min(remaining_writes, fifo_avail_space);
339
340 dev_dbg(&drv_data->pdev->dev,
341 "write type %s\n"
342 " remaining writes = %d\n"
343 " fifo avail space = %d\n"
344 " fifo writes = %d\n",
345 (n_bytes == 1) ? "u8" : "u16",
346 remaining_writes,
347 fifo_avail_space,
348 n);
349
350 if (n > 0) {
351 /* Fill SPI TXFIFO */
352 if (drv_data->rd_only) {
353 tx += n * n_bytes;
354 while (n--)
355 writel(SPI_DUMMY_u16, regs + SPI_TXDATA);
356 } else {
357 if (n_bytes == 1) {
358 while (n--) {
359 d = *(u8*)tx;
360 writel(d, regs + SPI_TXDATA);
361 tx += 1;
362 }
363 } else {
364 while (n--) {
365 d = *(u16*)tx;
366 writel(d, regs + SPI_TXDATA);
367 tx += 2;
368 }
369 }
370 }
371
372 /* Trigger transfer */
373 writel(readl(regs + SPI_CONTROL) | SPI_CONTROL_XCH,
374 regs + SPI_CONTROL);
375
376 /* Update tx pointer */
377 drv_data->tx = tx;
378 }
379
380 return (tx >= tx_end);
381}
382
383static int read(struct driver_data *drv_data)
384{
385 void __iomem *regs = drv_data->regs;
386 void *rx = drv_data->rx;
387 void *rx_end = drv_data->rx_end;
388 u8 n_bytes = drv_data->n_bytes;
389 u32 remaining_reads;
390 u32 fifo_rxcnt;
391 u32 n;
392 u16 d;
393
394 /* Compute how many fifo reads to do */
395 remaining_reads = (u32)(rx_end - rx) / n_bytes;
396 fifo_rxcnt = (readl(regs + SPI_TEST) & SPI_TEST_RXCNT) >>
397 SPI_TEST_RXCNT_LSB;
398 n = min(remaining_reads, fifo_rxcnt);
399
400 dev_dbg(&drv_data->pdev->dev,
401 "read type %s\n"
402 " remaining reads = %d\n"
403 " fifo rx count = %d\n"
404 " fifo reads = %d\n",
405 (n_bytes == 1) ? "u8" : "u16",
406 remaining_reads,
407 fifo_rxcnt,
408 n);
409
410 if (n > 0) {
411 /* Read SPI RXFIFO */
412 if (n_bytes == 1) {
413 while (n--) {
414 d = readl(regs + SPI_RXDATA);
415 *((u8*)rx) = d;
416 rx += 1;
417 }
418 } else {
419 while (n--) {
420 d = readl(regs + SPI_RXDATA);
421 *((u16*)rx) = d;
422 rx += 2;
423 }
424 }
425
426 /* Update rx pointer */
427 drv_data->rx = rx;
428 }
429
430 return (rx >= rx_end);
431}
432
433static void *next_transfer(struct driver_data *drv_data)
434{
435 struct spi_message *msg = drv_data->cur_msg;
436 struct spi_transfer *trans = drv_data->cur_transfer;
437
438 /* Move to next transfer */
439 if (trans->transfer_list.next != &msg->transfers) {
440 drv_data->cur_transfer =
441 list_entry(trans->transfer_list.next,
442 struct spi_transfer,
443 transfer_list);
444 return RUNNING_STATE;
445 }
446
447 return DONE_STATE;
448}
449
450static int map_dma_buffers(struct driver_data *drv_data)
451{
452 struct spi_message *msg;
453 struct device *dev;
454 void *buf;
455
456 drv_data->rx_dma_needs_unmap = 0;
457 drv_data->tx_dma_needs_unmap = 0;
458
459 if (!drv_data->master_info->enable_dma ||
460 !drv_data->cur_chip->enable_dma)
461 return -1;
462
463 msg = drv_data->cur_msg;
464 dev = &msg->spi->dev;
465 if (msg->is_dma_mapped) {
466 if (drv_data->tx_dma)
467 /* The caller provided at least dma and cpu virtual
468 address for write; pump_transfers() will consider the
469 transfer as write only if cpu rx virtual address is
470 NULL */
471 return 0;
472
473 if (drv_data->rx_dma) {
474 /* The caller provided dma and cpu virtual address to
475 performe read only transfer -->
476 use drv_data->dummy_dma_buf for dummy writes to
477 achive reads */
478 buf = &drv_data->dummy_dma_buf;
479 drv_data->tx_map_len = sizeof(drv_data->dummy_dma_buf);
480 drv_data->tx_dma = dma_map_single(dev,
481 buf,
482 drv_data->tx_map_len,
483 DMA_TO_DEVICE);
484 if (dma_mapping_error(drv_data->tx_dma))
485 return -1;
486
487 drv_data->tx_dma_needs_unmap = 1;
488
489 /* Flags transfer as rd_only for pump_transfers() DMA
490 regs programming (should be redundant) */
491 drv_data->tx = NULL;
492
493 return 0;
494 }
495 }
496
497 if (!IS_DMA_ALIGNED(drv_data->rx) || !IS_DMA_ALIGNED(drv_data->tx))
498 return -1;
499
500 /* NULL rx means write-only transfer and no map needed
501 since rx DMA will not be used */
502 if (drv_data->rx) {
503 buf = drv_data->rx;
504 drv_data->rx_dma = dma_map_single(
505 dev,
506 buf,
507 drv_data->len,
508 DMA_FROM_DEVICE);
509 if (dma_mapping_error(drv_data->rx_dma))
510 return -1;
511 drv_data->rx_dma_needs_unmap = 1;
512 }
513
514 if (drv_data->tx == NULL) {
515 /* Read only message --> use drv_data->dummy_dma_buf for dummy
516 writes to achive reads */
517 buf = &drv_data->dummy_dma_buf;
518 drv_data->tx_map_len = sizeof(drv_data->dummy_dma_buf);
519 } else {
520 buf = drv_data->tx;
521 drv_data->tx_map_len = drv_data->len;
522 }
523 drv_data->tx_dma = dma_map_single(dev,
524 buf,
525 drv_data->tx_map_len,
526 DMA_TO_DEVICE);
527 if (dma_mapping_error(drv_data->tx_dma)) {
528 if (drv_data->rx_dma) {
529 dma_unmap_single(dev,
530 drv_data->rx_dma,
531 drv_data->len,
532 DMA_FROM_DEVICE);
533 drv_data->rx_dma_needs_unmap = 0;
534 }
535 return -1;
536 }
537 drv_data->tx_dma_needs_unmap = 1;
538
539 return 0;
540}
541
542static void unmap_dma_buffers(struct driver_data *drv_data)
543{
544 struct spi_message *msg = drv_data->cur_msg;
545 struct device *dev = &msg->spi->dev;
546
547 if (drv_data->rx_dma_needs_unmap) {
548 dma_unmap_single(dev,
549 drv_data->rx_dma,
550 drv_data->len,
551 DMA_FROM_DEVICE);
552 drv_data->rx_dma_needs_unmap = 0;
553 }
554 if (drv_data->tx_dma_needs_unmap) {
555 dma_unmap_single(dev,
556 drv_data->tx_dma,
557 drv_data->tx_map_len,
558 DMA_TO_DEVICE);
559 drv_data->tx_dma_needs_unmap = 0;
560 }
561}
562
563/* Caller already set message->status (dma is already blocked) */
564static void giveback(struct spi_message *message, struct driver_data *drv_data)
565{
566 void __iomem *regs = drv_data->regs;
567
568 /* Bring SPI to sleep; restore_state() and pump_transfer()
569 will do new setup */
570 writel(0, regs + SPI_INT_STATUS);
571 writel(0, regs + SPI_DMA);
572
573 drv_data->cs_control(SPI_CS_DEASSERT);
574
575 message->state = NULL;
576 if (message->complete)
577 message->complete(message->context);
578
579 drv_data->cur_msg = NULL;
580 drv_data->cur_transfer = NULL;
581 drv_data->cur_chip = NULL;
582 queue_work(drv_data->workqueue, &drv_data->work);
583}
584
585static void dma_err_handler(int channel, void *data, int errcode)
586{
587 struct driver_data *drv_data = data;
588 struct spi_message *msg = drv_data->cur_msg;
589
590 dev_dbg(&drv_data->pdev->dev, "dma_err_handler\n");
591
592 /* Disable both rx and tx dma channels */
593 imx_dma_disable(drv_data->rx_channel);
594 imx_dma_disable(drv_data->tx_channel);
595
596 if (flush(drv_data) == 0)
597 dev_err(&drv_data->pdev->dev,
598 "dma_err_handler - flush failed\n");
599
600 unmap_dma_buffers(drv_data);
601
602 msg->state = ERROR_STATE;
603 tasklet_schedule(&drv_data->pump_transfers);
604}
605
606static void dma_tx_handler(int channel, void *data)
607{
608 struct driver_data *drv_data = data;
609
610 dev_dbg(&drv_data->pdev->dev, "dma_tx_handler\n");
611
612 imx_dma_disable(channel);
613
614 /* Now waits for TX FIFO empty */
615 writel(readl(drv_data->regs + SPI_INT_STATUS) | SPI_INTEN_TE,
616 drv_data->regs + SPI_INT_STATUS);
617}
618
619static irqreturn_t dma_transfer(struct driver_data *drv_data)
620{
621 u32 status;
622 struct spi_message *msg = drv_data->cur_msg;
623 void __iomem *regs = drv_data->regs;
624 unsigned long limit;
625
626 status = readl(regs + SPI_INT_STATUS);
627
628 if ((status & SPI_INTEN_RO) && (status & SPI_STATUS_RO)) {
629 writel(status & ~SPI_INTEN, regs + SPI_INT_STATUS);
630
631 imx_dma_disable(drv_data->rx_channel);
632 unmap_dma_buffers(drv_data);
633
634 if (flush(drv_data) == 0)
635 dev_err(&drv_data->pdev->dev,
636 "dma_transfer - flush failed\n");
637
638 dev_warn(&drv_data->pdev->dev,
639 "dma_transfer - fifo overun\n");
640
641 msg->state = ERROR_STATE;
642 tasklet_schedule(&drv_data->pump_transfers);
643
644 return IRQ_HANDLED;
645 }
646
647 if (status & SPI_STATUS_TE) {
648 writel(status & ~SPI_INTEN_TE, regs + SPI_INT_STATUS);
649
650 if (drv_data->rx) {
651 /* Wait end of transfer before read trailing data */
652 limit = loops_per_jiffy << 1;
653 while ((readl(regs + SPI_CONTROL) & SPI_CONTROL_XCH) &&
654 limit--);
655
656 if (limit == 0)
657 dev_err(&drv_data->pdev->dev,
658 "dma_transfer - end of tx failed\n");
659 else
660 dev_dbg(&drv_data->pdev->dev,
661 "dma_transfer - end of tx\n");
662
663 imx_dma_disable(drv_data->rx_channel);
664 unmap_dma_buffers(drv_data);
665
666 /* Calculate number of trailing data and read them */
667 dev_dbg(&drv_data->pdev->dev,
668 "dma_transfer - test = 0x%08X\n",
669 readl(regs + SPI_TEST));
670 drv_data->rx = drv_data->rx_end -
671 ((readl(regs + SPI_TEST) &
672 SPI_TEST_RXCNT) >>
673 SPI_TEST_RXCNT_LSB)*drv_data->n_bytes;
674 read(drv_data);
675 } else {
676 /* Write only transfer */
677 unmap_dma_buffers(drv_data);
678
679 if (flush(drv_data) == 0)
680 dev_err(&drv_data->pdev->dev,
681 "dma_transfer - flush failed\n");
682 }
683
684 /* End of transfer, update total byte transfered */
685 msg->actual_length += drv_data->len;
686
687 /* Release chip select if requested, transfer delays are
688 handled in pump_transfers() */
689 if (drv_data->cs_change)
690 drv_data->cs_control(SPI_CS_DEASSERT);
691
692 /* Move to next transfer */
693 msg->state = next_transfer(drv_data);
694
695 /* Schedule transfer tasklet */
696 tasklet_schedule(&drv_data->pump_transfers);
697
698 return IRQ_HANDLED;
699 }
700
701 /* Opps problem detected */
702 return IRQ_NONE;
703}
704
705static irqreturn_t interrupt_wronly_transfer(struct driver_data *drv_data)
706{
707 struct spi_message *msg = drv_data->cur_msg;
708 void __iomem *regs = drv_data->regs;
709 u32 status;
710 irqreturn_t handled = IRQ_NONE;
711
712 status = readl(regs + SPI_INT_STATUS);
713
714 while (status & SPI_STATUS_TH) {
715 dev_dbg(&drv_data->pdev->dev,
716 "interrupt_wronly_transfer - status = 0x%08X\n", status);
717
718 /* Pump data */
719 if (write(drv_data)) {
720 writel(readl(regs + SPI_INT_STATUS) & ~SPI_INTEN,
721 regs + SPI_INT_STATUS);
722
723 dev_dbg(&drv_data->pdev->dev,
724 "interrupt_wronly_transfer - end of tx\n");
725
726 if (flush(drv_data) == 0)
727 dev_err(&drv_data->pdev->dev,
728 "interrupt_wronly_transfer - "
729 "flush failed\n");
730
731 /* End of transfer, update total byte transfered */
732 msg->actual_length += drv_data->len;
733
734 /* Release chip select if requested, transfer delays are
735 handled in pump_transfers */
736 if (drv_data->cs_change)
737 drv_data->cs_control(SPI_CS_DEASSERT);
738
739 /* Move to next transfer */
740 msg->state = next_transfer(drv_data);
741
742 /* Schedule transfer tasklet */
743 tasklet_schedule(&drv_data->pump_transfers);
744
745 return IRQ_HANDLED;
746 }
747
748 status = readl(regs + SPI_INT_STATUS);
749
750 /* We did something */
751 handled = IRQ_HANDLED;
752 }
753
754 return handled;
755}
756
757static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
758{
759 struct spi_message *msg = drv_data->cur_msg;
760 void __iomem *regs = drv_data->regs;
761 u32 status;
762 irqreturn_t handled = IRQ_NONE;
763 unsigned long limit;
764
765 status = readl(regs + SPI_INT_STATUS);
766
767 while (status & (SPI_STATUS_TH | SPI_STATUS_RO)) {
768 dev_dbg(&drv_data->pdev->dev,
769 "interrupt_transfer - status = 0x%08X\n", status);
770
771 if (status & SPI_STATUS_RO) {
772 writel(readl(regs + SPI_INT_STATUS) & ~SPI_INTEN,
773 regs + SPI_INT_STATUS);
774
775 dev_warn(&drv_data->pdev->dev,
776 "interrupt_transfer - fifo overun\n"
777 " data not yet written = %d\n"
778 " data not yet read = %d\n",
779 data_to_write(drv_data),
780 data_to_read(drv_data));
781
782 if (flush(drv_data) == 0)
783 dev_err(&drv_data->pdev->dev,
784 "interrupt_transfer - flush failed\n");
785
786 msg->state = ERROR_STATE;
787 tasklet_schedule(&drv_data->pump_transfers);
788
789 return IRQ_HANDLED;
790 }
791
792 /* Pump data */
793 read(drv_data);
794 if (write(drv_data)) {
795 writel(readl(regs + SPI_INT_STATUS) & ~SPI_INTEN,
796 regs + SPI_INT_STATUS);
797
798 dev_dbg(&drv_data->pdev->dev,
799 "interrupt_transfer - end of tx\n");
800
801 /* Read trailing bytes */
802 limit = loops_per_jiffy << 1;
803 while ((read(drv_data) == 0) && limit--);
804
805 if (limit == 0)
806 dev_err(&drv_data->pdev->dev,
807 "interrupt_transfer - "
808 "trailing byte read failed\n");
809 else
810 dev_dbg(&drv_data->pdev->dev,
811 "interrupt_transfer - end of rx\n");
812
813 /* End of transfer, update total byte transfered */
814 msg->actual_length += drv_data->len;
815
816 /* Release chip select if requested, transfer delays are
817 handled in pump_transfers */
818 if (drv_data->cs_change)
819 drv_data->cs_control(SPI_CS_DEASSERT);
820
821 /* Move to next transfer */
822 msg->state = next_transfer(drv_data);
823
824 /* Schedule transfer tasklet */
825 tasklet_schedule(&drv_data->pump_transfers);
826
827 return IRQ_HANDLED;
828 }
829
830 status = readl(regs + SPI_INT_STATUS);
831
832 /* We did something */
833 handled = IRQ_HANDLED;
834 }
835
836 return handled;
837}
838
839static irqreturn_t spi_int(int irq, void *dev_id)
840{
841 struct driver_data *drv_data = (struct driver_data *)dev_id;
842
843 if (!drv_data->cur_msg) {
844 dev_err(&drv_data->pdev->dev,
845 "spi_int - bad message state\n");
846 /* Never fail */
847 return IRQ_HANDLED;
848 }
849
850 return drv_data->transfer_handler(drv_data);
851}
852
853static inline u32 spi_speed_hz(u32 data_rate)
854{
855 return imx_get_perclk2() / (4 << ((data_rate) >> 13));
856}
857
858static u32 spi_data_rate(u32 speed_hz)
859{
860 u32 div;
861 u32 quantized_hz = imx_get_perclk2() >> 2;
862
863 for (div = SPI_PERCLK2_DIV_MIN;
864 div <= SPI_PERCLK2_DIV_MAX;
865 div++, quantized_hz >>= 1) {
866 if (quantized_hz <= speed_hz)
867 /* Max available speed LEQ required speed */
868 return div << 13;
869 }
870 return SPI_CONTROL_DATARATE_BAD;
871}
872
873static void pump_transfers(unsigned long data)
874{
875 struct driver_data *drv_data = (struct driver_data *)data;
876 struct spi_message *message;
877 struct spi_transfer *transfer, *previous;
878 struct chip_data *chip;
879 void __iomem *regs;
880 u32 tmp, control;
881
882 dev_dbg(&drv_data->pdev->dev, "pump_transfer\n");
883
884 message = drv_data->cur_msg;
885
886 /* Handle for abort */
887 if (message->state == ERROR_STATE) {
888 message->status = -EIO;
889 giveback(message, drv_data);
890 return;
891 }
892
893 /* Handle end of message */
894 if (message->state == DONE_STATE) {
895 message->status = 0;
896 giveback(message, drv_data);
897 return;
898 }
899
900 chip = drv_data->cur_chip;
901
902 /* Delay if requested at end of transfer*/
903 transfer = drv_data->cur_transfer;
904 if (message->state == RUNNING_STATE) {
905 previous = list_entry(transfer->transfer_list.prev,
906 struct spi_transfer,
907 transfer_list);
908 if (previous->delay_usecs)
909 udelay(previous->delay_usecs);
910 } else {
911 /* START_STATE */
912 message->state = RUNNING_STATE;
913 drv_data->cs_control = chip->cs_control;
914 }
915
916 transfer = drv_data->cur_transfer;
917 drv_data->tx = (void *)transfer->tx_buf;
918 drv_data->tx_end = drv_data->tx + transfer->len;
919 drv_data->rx = transfer->rx_buf;
920 drv_data->rx_end = drv_data->rx + transfer->len;
921 drv_data->rx_dma = transfer->rx_dma;
922 drv_data->tx_dma = transfer->tx_dma;
923 drv_data->len = transfer->len;
924 drv_data->cs_change = transfer->cs_change;
925 drv_data->rd_only = (drv_data->tx == NULL);
926
927 regs = drv_data->regs;
928 control = readl(regs + SPI_CONTROL);
929
930 /* Bits per word setup */
931 tmp = transfer->bits_per_word;
932 if (tmp == 0) {
933 /* Use device setup */
934 tmp = chip->bits_per_word;
935 drv_data->n_bytes = chip->n_bytes;
936 } else
937 /* Use per-transfer setup */
938 drv_data->n_bytes = (tmp <= 8) ? 1 : 2;
939 u32_EDIT(control, SPI_CONTROL_BITCOUNT_MASK, tmp - 1);
940
941 /* Speed setup (surely valid because already checked) */
942 tmp = transfer->speed_hz;
943 if (tmp == 0)
944 tmp = chip->max_speed_hz;
945 tmp = spi_data_rate(tmp);
946 u32_EDIT(control, SPI_CONTROL_DATARATE, tmp);
947
948 writel(control, regs + SPI_CONTROL);
949
950 /* Assert device chip-select */
951 drv_data->cs_control(SPI_CS_ASSERT);
952
953 /* DMA cannot read/write SPI FIFOs other than 16 bits at a time; hence
954 if bits_per_word is less or equal 8 PIO transfers are performed.
955 Moreover DMA is convinient for transfer length bigger than FIFOs
956 byte size. */
957 if ((drv_data->n_bytes == 2) &&
958 (drv_data->len > SPI_FIFO_DEPTH*SPI_FIFO_BYTE_WIDTH) &&
959 (map_dma_buffers(drv_data) == 0)) {
960 dev_dbg(&drv_data->pdev->dev,
961 "pump dma transfer\n"
962 " tx = %p\n"
963 " tx_dma = %08X\n"
964 " rx = %p\n"
965 " rx_dma = %08X\n"
966 " len = %d\n",
967 drv_data->tx,
968 (unsigned int)drv_data->tx_dma,
969 drv_data->rx,
970 (unsigned int)drv_data->rx_dma,
971 drv_data->len);
972
973 /* Ensure we have the correct interrupt handler */
974 drv_data->transfer_handler = dma_transfer;
975
976 /* Trigger transfer */
977 writel(readl(regs + SPI_CONTROL) | SPI_CONTROL_XCH,
978 regs + SPI_CONTROL);
979
980 /* Setup tx DMA */
981 if (drv_data->tx)
982 /* Linear source address */
983 CCR(drv_data->tx_channel) =
984 CCR_DMOD_FIFO |
985 CCR_SMOD_LINEAR |
986 CCR_SSIZ_32 | CCR_DSIZ_16 |
987 CCR_REN;
988 else
989 /* Read only transfer -> fixed source address for
990 dummy write to achive read */
991 CCR(drv_data->tx_channel) =
992 CCR_DMOD_FIFO |
993 CCR_SMOD_FIFO |
994 CCR_SSIZ_32 | CCR_DSIZ_16 |
995 CCR_REN;
996
997 imx_dma_setup_single(
998 drv_data->tx_channel,
999 drv_data->tx_dma,
1000 drv_data->len,
1001 drv_data->rd_data_phys + 4,
1002 DMA_MODE_WRITE);
1003
1004 if (drv_data->rx) {
1005 /* Setup rx DMA for linear destination address */
1006 CCR(drv_data->rx_channel) =
1007 CCR_DMOD_LINEAR |
1008 CCR_SMOD_FIFO |
1009 CCR_DSIZ_32 | CCR_SSIZ_16 |
1010 CCR_REN;
1011 imx_dma_setup_single(
1012 drv_data->rx_channel,
1013 drv_data->rx_dma,
1014 drv_data->len,
1015 drv_data->rd_data_phys,
1016 DMA_MODE_READ);
1017 imx_dma_enable(drv_data->rx_channel);
1018
1019 /* Enable SPI interrupt */
1020 writel(SPI_INTEN_RO, regs + SPI_INT_STATUS);
1021
1022 /* Set SPI to request DMA service on both
1023 Rx and Tx half fifo watermark */
1024 writel(SPI_DMA_RHDEN | SPI_DMA_THDEN, regs + SPI_DMA);
1025 } else
1026 /* Write only access -> set SPI to request DMA
1027 service on Tx half fifo watermark */
1028 writel(SPI_DMA_THDEN, regs + SPI_DMA);
1029
1030 imx_dma_enable(drv_data->tx_channel);
1031 } else {
1032 dev_dbg(&drv_data->pdev->dev,
1033 "pump pio transfer\n"
1034 " tx = %p\n"
1035 " rx = %p\n"
1036 " len = %d\n",
1037 drv_data->tx,
1038 drv_data->rx,
1039 drv_data->len);
1040
1041 /* Ensure we have the correct interrupt handler */
1042 if (drv_data->rx)
1043 drv_data->transfer_handler = interrupt_transfer;
1044 else
1045 drv_data->transfer_handler = interrupt_wronly_transfer;
1046
1047 /* Enable SPI interrupt */
1048 if (drv_data->rx)
1049 writel(SPI_INTEN_TH | SPI_INTEN_RO,
1050 regs + SPI_INT_STATUS);
1051 else
1052 writel(SPI_INTEN_TH, regs + SPI_INT_STATUS);
1053 }
1054}
1055
1056static void pump_messages(struct work_struct *work)
1057{
1058 struct driver_data *drv_data =
1059 container_of(work, struct driver_data, work);
1060 unsigned long flags;
1061
1062 /* Lock queue and check for queue work */
1063 spin_lock_irqsave(&drv_data->lock, flags);
1064 if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) {
1065 drv_data->busy = 0;
1066 spin_unlock_irqrestore(&drv_data->lock, flags);
1067 return;
1068 }
1069
1070 /* Make sure we are not already running a message */
1071 if (drv_data->cur_msg) {
1072 spin_unlock_irqrestore(&drv_data->lock, flags);
1073 return;
1074 }
1075
1076 /* Extract head of queue */
1077 drv_data->cur_msg = list_entry(drv_data->queue.next,
1078 struct spi_message, queue);
1079 list_del_init(&drv_data->cur_msg->queue);
1080 drv_data->busy = 1;
1081 spin_unlock_irqrestore(&drv_data->lock, flags);
1082
1083 /* Initial message state */
1084 drv_data->cur_msg->state = START_STATE;
1085 drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
1086 struct spi_transfer,
1087 transfer_list);
1088
1089 /* Setup the SPI using the per chip configuration */
1090 drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
1091 restore_state(drv_data);
1092
1093 /* Mark as busy and launch transfers */
1094 tasklet_schedule(&drv_data->pump_transfers);
1095}
1096
1097static int transfer(struct spi_device *spi, struct spi_message *msg)
1098{
1099 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1100 u32 min_speed_hz, max_speed_hz, tmp;
1101 struct spi_transfer *trans;
1102 unsigned long flags;
1103
1104 msg->actual_length = 0;
1105
1106 /* Per transfer setup check */
1107 min_speed_hz = spi_speed_hz(SPI_CONTROL_DATARATE_MIN);
1108 max_speed_hz = spi->max_speed_hz;
1109 list_for_each_entry(trans, &msg->transfers, transfer_list) {
1110 tmp = trans->bits_per_word;
1111 if (tmp > 16) {
1112 dev_err(&drv_data->pdev->dev,
1113 "message rejected : "
1114 "invalid transfer bits_per_word (%d bits)\n",
1115 tmp);
1116 goto msg_rejected;
1117 }
1118 tmp = trans->speed_hz;
1119 if (tmp) {
1120 if (tmp < min_speed_hz) {
1121 dev_err(&drv_data->pdev->dev,
1122 "message rejected : "
1123 "device min speed (%d Hz) exceeds "
1124 "required transfer speed (%d Hz)\n",
1125 min_speed_hz,
1126 tmp);
1127 goto msg_rejected;
1128 } else if (tmp > max_speed_hz) {
1129 dev_err(&drv_data->pdev->dev,
1130 "message rejected : "
1131 "transfer speed (%d Hz) exceeds "
1132 "device max speed (%d Hz)\n",
1133 tmp,
1134 max_speed_hz);
1135 goto msg_rejected;
1136 }
1137 }
1138 }
1139
1140 /* Message accepted */
1141 msg->status = -EINPROGRESS;
1142 msg->state = START_STATE;
1143
1144 spin_lock_irqsave(&drv_data->lock, flags);
1145 if (drv_data->run == QUEUE_STOPPED) {
1146 spin_unlock_irqrestore(&drv_data->lock, flags);
1147 return -ESHUTDOWN;
1148 }
1149
1150 list_add_tail(&msg->queue, &drv_data->queue);
1151 if (drv_data->run == QUEUE_RUNNING && !drv_data->busy)
1152 queue_work(drv_data->workqueue, &drv_data->work);
1153
1154 spin_unlock_irqrestore(&drv_data->lock, flags);
1155 return 0;
1156
1157msg_rejected:
1158 /* Message rejected and not queued */
1159 msg->status = -EINVAL;
1160 msg->state = ERROR_STATE;
1161 if (msg->complete)
1162 msg->complete(msg->context);
1163 return -EINVAL;
1164}
1165
1166/* On first setup bad values must free chip_data memory since will cause
1167 spi_new_device to fail. Bad value setup from protocol driver are simply not
1168 applied and notified to the calling driver. */
1169static int setup(struct spi_device *spi)
1170{
1171 struct spi_imx_chip *chip_info;
1172 struct chip_data *chip;
1173 int first_setup = 0;
1174 u32 tmp;
1175 int status = 0;
1176
1177 /* Get controller data */
1178 chip_info = spi->controller_data;
1179
1180 /* Get controller_state */
1181 chip = spi_get_ctldata(spi);
1182 if (chip == NULL) {
1183 first_setup = 1;
1184
1185 chip = kzalloc(sizeof(struct chip_data), GFP_KERNEL);
1186 if (!chip) {
1187 dev_err(&spi->dev,
1188 "setup - cannot allocate controller state");
1189 return -ENOMEM;
1190 }
1191 chip->control = SPI_DEFAULT_CONTROL;
1192
1193 if (chip_info == NULL) {
1194 /* spi_board_info.controller_data not is supplied */
1195 chip_info = kzalloc(sizeof(struct spi_imx_chip),
1196 GFP_KERNEL);
1197 if (!chip_info) {
1198 dev_err(&spi->dev,
1199 "setup - "
1200 "cannot allocate controller data");
1201 status = -ENOMEM;
1202 goto err_first_setup;
1203 }
1204 /* Set controller data default value */
1205 chip_info->enable_loopback =
1206 SPI_DEFAULT_ENABLE_LOOPBACK;
1207 chip_info->enable_dma = SPI_DEFAULT_ENABLE_DMA;
1208 chip_info->ins_ss_pulse = 1;
1209 chip_info->bclk_wait = SPI_DEFAULT_PERIOD_WAIT;
1210 chip_info->cs_control = null_cs_control;
1211 }
1212 }
1213
1214 /* Now set controller state based on controller data */
1215
1216 if (first_setup) {
1217 /* SPI loopback */
1218 if (chip_info->enable_loopback)
1219 chip->test = SPI_TEST_LBC;
1220 else
1221 chip->test = 0;
1222
1223 /* SPI dma driven */
1224 chip->enable_dma = chip_info->enable_dma;
1225
1226 /* SPI /SS pulse between spi burst */
1227 if (chip_info->ins_ss_pulse)
1228 u32_EDIT(chip->control,
1229 SPI_CONTROL_SSCTL, SPI_CONTROL_SSCTL_1);
1230 else
1231 u32_EDIT(chip->control,
1232 SPI_CONTROL_SSCTL, SPI_CONTROL_SSCTL_0);
1233
1234 /* SPI bclk waits between each bits_per_word spi burst */
1235 if (chip_info->bclk_wait > SPI_PERIOD_MAX_WAIT) {
1236 dev_err(&spi->dev,
1237 "setup - "
1238 "bclk_wait exceeds max allowed (%d)\n",
1239 SPI_PERIOD_MAX_WAIT);
1240 goto err_first_setup;
1241 }
1242 chip->period = SPI_PERIOD_CSRC_BCLK |
1243 (chip_info->bclk_wait & SPI_PERIOD_WAIT);
1244 }
1245
1246 /* SPI mode */
1247 tmp = spi->mode;
1248 if (tmp & SPI_LSB_FIRST) {
1249 status = -EINVAL;
1250 if (first_setup) {
1251 dev_err(&spi->dev,
1252 "setup - "
1253 "HW doesn't support LSB first transfer\n");
1254 goto err_first_setup;
1255 } else {
1256 dev_err(&spi->dev,
1257 "setup - "
1258 "HW doesn't support LSB first transfer, "
1259 "default to MSB first\n");
1260 spi->mode &= ~SPI_LSB_FIRST;
1261 }
1262 }
1263 if (tmp & SPI_CS_HIGH) {
1264 u32_EDIT(chip->control,
1265 SPI_CONTROL_SSPOL, SPI_CONTROL_SSPOL_ACT_HIGH);
1266 }
1267 switch (tmp & SPI_MODE_3) {
1268 case SPI_MODE_0:
1269 tmp = 0;
1270 break;
1271 case SPI_MODE_1:
1272 tmp = SPI_CONTROL_PHA_1;
1273 break;
1274 case SPI_MODE_2:
1275 tmp = SPI_CONTROL_POL_ACT_LOW;
1276 break;
1277 default:
1278 /* SPI_MODE_3 */
1279 tmp = SPI_CONTROL_PHA_1 | SPI_CONTROL_POL_ACT_LOW;
1280 break;
1281 }
1282 u32_EDIT(chip->control, SPI_CONTROL_POL | SPI_CONTROL_PHA, tmp);
1283
1284 /* SPI word width */
1285 tmp = spi->bits_per_word;
1286 if (tmp == 0) {
1287 tmp = 8;
1288 spi->bits_per_word = 8;
1289 } else if (tmp > 16) {
1290 status = -EINVAL;
1291 dev_err(&spi->dev,
1292 "setup - "
1293 "invalid bits_per_word (%d)\n",
1294 tmp);
1295 if (first_setup)
1296 goto err_first_setup;
1297 else {
1298 /* Undo setup using chip as backup copy */
1299 tmp = chip->bits_per_word;
1300 spi->bits_per_word = tmp;
1301 }
1302 }
1303 chip->bits_per_word = tmp;
1304 u32_EDIT(chip->control, SPI_CONTROL_BITCOUNT_MASK, tmp - 1);
1305 chip->n_bytes = (tmp <= 8) ? 1 : 2;
1306
1307 /* SPI datarate */
1308 tmp = spi_data_rate(spi->max_speed_hz);
1309 if (tmp == SPI_CONTROL_DATARATE_BAD) {
1310 status = -EINVAL;
1311 dev_err(&spi->dev,
1312 "setup - "
1313 "HW min speed (%d Hz) exceeds required "
1314 "max speed (%d Hz)\n",
1315 spi_speed_hz(SPI_CONTROL_DATARATE_MIN),
1316 spi->max_speed_hz);
1317 if (first_setup)
1318 goto err_first_setup;
1319 else
1320 /* Undo setup using chip as backup copy */
1321 spi->max_speed_hz = chip->max_speed_hz;
1322 } else {
1323 u32_EDIT(chip->control, SPI_CONTROL_DATARATE, tmp);
1324 /* Actual rounded max_speed_hz */
1325 tmp = spi_speed_hz(tmp);
1326 spi->max_speed_hz = tmp;
1327 chip->max_speed_hz = tmp;
1328 }
1329
1330 /* SPI chip-select management */
1331 if (chip_info->cs_control)
1332 chip->cs_control = chip_info->cs_control;
1333 else
1334 chip->cs_control = null_cs_control;
1335
1336 /* Save controller_state */
1337 spi_set_ctldata(spi, chip);
1338
1339 /* Summary */
1340 dev_dbg(&spi->dev,
1341 "setup succeded\n"
1342 " loopback enable = %s\n"
1343 " dma enable = %s\n"
1344 " insert /ss pulse = %s\n"
1345 " period wait = %d\n"
1346 " mode = %d\n"
1347 " bits per word = %d\n"
1348 " min speed = %d Hz\n"
1349 " rounded max speed = %d Hz\n",
1350 chip->test & SPI_TEST_LBC ? "Yes" : "No",
1351 chip->enable_dma ? "Yes" : "No",
1352 chip->control & SPI_CONTROL_SSCTL ? "Yes" : "No",
1353 chip->period & SPI_PERIOD_WAIT,
1354 spi->mode,
1355 spi->bits_per_word,
1356 spi_speed_hz(SPI_CONTROL_DATARATE_MIN),
1357 spi->max_speed_hz);
1358
1359err_first_setup:
1360 kfree(chip);
1361 return status;
1362}
1363
1364static void cleanup(const struct spi_device *spi)
1365{
1366 struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi);
1367 kfree(chip);
1368}
1369
1370static int init_queue(struct driver_data *drv_data)
1371{
1372 INIT_LIST_HEAD(&drv_data->queue);
1373 spin_lock_init(&drv_data->lock);
1374
1375 drv_data->run = QUEUE_STOPPED;
1376 drv_data->busy = 0;
1377
1378 tasklet_init(&drv_data->pump_transfers,
1379 pump_transfers, (unsigned long)drv_data);
1380
1381 INIT_WORK(&drv_data->work, pump_messages);
1382 drv_data->workqueue = create_singlethread_workqueue(
1383 drv_data->master->cdev.dev->bus_id);
1384 if (drv_data->workqueue == NULL)
1385 return -EBUSY;
1386
1387 return 0;
1388}
1389
1390static int start_queue(struct driver_data *drv_data)
1391{
1392 unsigned long flags;
1393
1394 spin_lock_irqsave(&drv_data->lock, flags);
1395
1396 if (drv_data->run == QUEUE_RUNNING || drv_data->busy) {
1397 spin_unlock_irqrestore(&drv_data->lock, flags);
1398 return -EBUSY;
1399 }
1400
1401 drv_data->run = QUEUE_RUNNING;
1402 drv_data->cur_msg = NULL;
1403 drv_data->cur_transfer = NULL;
1404 drv_data->cur_chip = NULL;
1405 spin_unlock_irqrestore(&drv_data->lock, flags);
1406
1407 queue_work(drv_data->workqueue, &drv_data->work);
1408
1409 return 0;
1410}
1411
1412static int stop_queue(struct driver_data *drv_data)
1413{
1414 unsigned long flags;
1415 unsigned limit = 500;
1416 int status = 0;
1417
1418 spin_lock_irqsave(&drv_data->lock, flags);
1419
1420 /* This is a bit lame, but is optimized for the common execution path.
1421 * A wait_queue on the drv_data->busy could be used, but then the common
1422 * execution path (pump_messages) would be required to call wake_up or
1423 * friends on every SPI message. Do this instead */
1424 drv_data->run = QUEUE_STOPPED;
1425 while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) {
1426 spin_unlock_irqrestore(&drv_data->lock, flags);
1427 msleep(10);
1428 spin_lock_irqsave(&drv_data->lock, flags);
1429 }
1430
1431 if (!list_empty(&drv_data->queue) || drv_data->busy)
1432 status = -EBUSY;
1433
1434 spin_unlock_irqrestore(&drv_data->lock, flags);
1435
1436 return status;
1437}
1438
1439static int destroy_queue(struct driver_data *drv_data)
1440{
1441 int status;
1442
1443 status = stop_queue(drv_data);
1444 if (status != 0)
1445 return status;
1446
1447 if (drv_data->workqueue)
1448 destroy_workqueue(drv_data->workqueue);
1449
1450 return 0;
1451}
1452
1453static int spi_imx_probe(struct platform_device *pdev)
1454{
1455 struct device *dev = &pdev->dev;
1456 struct spi_imx_master *platform_info;
1457 struct spi_master *master;
1458 struct driver_data *drv_data = NULL;
1459 struct resource *res;
1460 int irq, status = 0;
1461
1462 platform_info = dev->platform_data;
1463 if (platform_info == NULL) {
1464 dev_err(&pdev->dev, "probe - no platform data supplied\n");
1465 status = -ENODEV;
1466 goto err_no_pdata;
1467 }
1468
1469 /* Allocate master with space for drv_data */
1470 master = spi_alloc_master(dev, sizeof(struct driver_data));
1471 if (!master) {
1472 dev_err(&pdev->dev, "probe - cannot alloc spi_master\n");
1473 status = -ENOMEM;
1474 goto err_no_mem;
1475 }
1476 drv_data = spi_master_get_devdata(master);
1477 drv_data->master = master;
1478 drv_data->master_info = platform_info;
1479 drv_data->pdev = pdev;
1480
1481 master->bus_num = pdev->id;
1482 master->num_chipselect = platform_info->num_chipselect;
1483 master->cleanup = cleanup;
1484 master->setup = setup;
1485 master->transfer = transfer;
1486
1487 drv_data->dummy_dma_buf = SPI_DUMMY_u32;
1488
1489 /* Find and map resources */
1490 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1491 if (!res) {
1492 dev_err(&pdev->dev, "probe - MEM resources not defined\n");
1493 status = -ENODEV;
1494 goto err_no_iores;
1495 }
1496 drv_data->ioarea = request_mem_region(res->start,
1497 res->end - res->start + 1,
1498 pdev->name);
1499 if (drv_data->ioarea == NULL) {
1500 dev_err(&pdev->dev, "probe - cannot reserve region\n");
1501 status = -ENXIO;
1502 goto err_no_iores;
1503 }
1504 drv_data->regs = ioremap(res->start, res->end - res->start + 1);
1505 if (drv_data->regs == NULL) {
1506 dev_err(&pdev->dev, "probe - cannot map IO\n");
1507 status = -ENXIO;
1508 goto err_no_iomap;
1509 }
1510 drv_data->rd_data_phys = (dma_addr_t)res->start;
1511
1512 /* Attach to IRQ */
1513 irq = platform_get_irq(pdev, 0);
1514 if (irq < 0) {
1515 dev_err(&pdev->dev, "probe - IRQ resource not defined\n");
1516 status = -ENODEV;
1517 goto err_no_irqres;
1518 }
1519 status = request_irq(irq, spi_int, IRQF_DISABLED, dev->bus_id, drv_data);
1520 if (status < 0) {
1521 dev_err(&pdev->dev, "probe - cannot get IRQ (%d)\n", status);
1522 goto err_no_irqres;
1523 }
1524
1525 /* Setup DMA if requested */
1526 drv_data->tx_channel = -1;
1527 drv_data->rx_channel = -1;
1528 if (platform_info->enable_dma) {
1529 /* Get rx DMA channel */
1530 status = imx_dma_request_by_prio(&drv_data->rx_channel,
1531 "spi_imx_rx", DMA_PRIO_HIGH);
1532 if (status < 0) {
1533 dev_err(dev,
1534 "probe - problem (%d) requesting rx channel\n",
1535 status);
1536 goto err_no_rxdma;
1537 } else
1538 imx_dma_setup_handlers(drv_data->rx_channel, NULL,
1539 dma_err_handler, drv_data);
1540
1541 /* Get tx DMA channel */
1542 status = imx_dma_request_by_prio(&drv_data->tx_channel,
1543 "spi_imx_tx", DMA_PRIO_MEDIUM);
1544 if (status < 0) {
1545 dev_err(dev,
1546 "probe - problem (%d) requesting tx channel\n",
1547 status);
1548 imx_dma_free(drv_data->rx_channel);
1549 goto err_no_txdma;
1550 } else
1551 imx_dma_setup_handlers(drv_data->tx_channel,
1552 dma_tx_handler, dma_err_handler,
1553 drv_data);
1554
1555 /* Set request source and burst length for allocated channels */
1556 switch (drv_data->pdev->id) {
1557 case 1:
1558 /* Using SPI1 */
1559 RSSR(drv_data->rx_channel) = DMA_REQ_SPI1_R;
1560 RSSR(drv_data->tx_channel) = DMA_REQ_SPI1_T;
1561 break;
1562 case 2:
1563 /* Using SPI2 */
1564 RSSR(drv_data->rx_channel) = DMA_REQ_SPI2_R;
1565 RSSR(drv_data->tx_channel) = DMA_REQ_SPI2_T;
1566 break;
1567 default:
1568 dev_err(dev, "probe - bad SPI Id\n");
1569 imx_dma_free(drv_data->rx_channel);
1570 imx_dma_free(drv_data->tx_channel);
1571 status = -ENODEV;
1572 goto err_no_devid;
1573 }
1574 BLR(drv_data->rx_channel) = SPI_DMA_BLR;
1575 BLR(drv_data->tx_channel) = SPI_DMA_BLR;
1576 }
1577
1578 /* Load default SPI configuration */
1579 writel(SPI_RESET_START, drv_data->regs + SPI_RESET);
1580 writel(0, drv_data->regs + SPI_RESET);
1581 writel(SPI_DEFAULT_CONTROL, drv_data->regs + SPI_CONTROL);
1582
1583 /* Initial and start queue */
1584 status = init_queue(drv_data);
1585 if (status != 0) {
1586 dev_err(&pdev->dev, "probe - problem initializing queue\n");
1587 goto err_init_queue;
1588 }
1589 status = start_queue(drv_data);
1590 if (status != 0) {
1591 dev_err(&pdev->dev, "probe - problem starting queue\n");
1592 goto err_start_queue;
1593 }
1594
1595 /* Register with the SPI framework */
1596 platform_set_drvdata(pdev, drv_data);
1597 status = spi_register_master(master);
1598 if (status != 0) {
1599 dev_err(&pdev->dev, "probe - problem registering spi master\n");
1600 goto err_spi_register;
1601 }
1602
1603 dev_dbg(dev, "probe succeded\n");
1604 return 0;
1605
1606err_init_queue:
1607err_start_queue:
1608err_spi_register:
1609 destroy_queue(drv_data);
1610
1611err_no_rxdma:
1612err_no_txdma:
1613err_no_devid:
1614 free_irq(irq, drv_data);
1615
1616err_no_irqres:
1617 iounmap(drv_data->regs);
1618
1619err_no_iomap:
1620 release_resource(drv_data->ioarea);
1621 kfree(drv_data->ioarea);
1622
1623err_no_iores:
1624 spi_master_put(master);
1625
1626err_no_pdata:
1627err_no_mem:
1628 return status;
1629}
1630
1631static int __devexit spi_imx_remove(struct platform_device *pdev)
1632{
1633 struct driver_data *drv_data = platform_get_drvdata(pdev);
1634 int irq;
1635 int status = 0;
1636
1637 if (!drv_data)
1638 return 0;
1639
1640 tasklet_kill(&drv_data->pump_transfers);
1641
1642 /* Remove the queue */
1643 status = destroy_queue(drv_data);
1644 if (status != 0) {
1645 dev_err(&pdev->dev, "queue remove failed (%d)\n", status);
1646 return status;
1647 }
1648
1649 /* Reset SPI */
1650 writel(SPI_RESET_START, drv_data->regs + SPI_RESET);
1651 writel(0, drv_data->regs + SPI_RESET);
1652
1653 /* Release DMA */
1654 if (drv_data->master_info->enable_dma) {
1655 RSSR(drv_data->rx_channel) = 0;
1656 RSSR(drv_data->tx_channel) = 0;
1657 imx_dma_free(drv_data->tx_channel);
1658 imx_dma_free(drv_data->rx_channel);
1659 }
1660
1661 /* Release IRQ */
1662 irq = platform_get_irq(pdev, 0);
1663 if (irq >= 0)
1664 free_irq(irq, drv_data);
1665
1666 /* Release map resources */
1667 iounmap(drv_data->regs);
1668 release_resource(drv_data->ioarea);
1669 kfree(drv_data->ioarea);
1670
1671 /* Disconnect from the SPI framework */
1672 spi_unregister_master(drv_data->master);
1673 spi_master_put(drv_data->master);
1674
1675 /* Prevent double remove */
1676 platform_set_drvdata(pdev, NULL);
1677
1678 dev_dbg(&pdev->dev, "remove succeded\n");
1679
1680 return 0;
1681}
1682
1683static void spi_imx_shutdown(struct platform_device *pdev)
1684{
1685 struct driver_data *drv_data = platform_get_drvdata(pdev);
1686
1687 /* Reset SPI */
1688 writel(SPI_RESET_START, drv_data->regs + SPI_RESET);
1689 writel(0, drv_data->regs + SPI_RESET);
1690
1691 dev_dbg(&pdev->dev, "shutdown succeded\n");
1692}
1693
1694#ifdef CONFIG_PM
1695static int suspend_devices(struct device *dev, void *pm_message)
1696{
1697 pm_message_t *state = pm_message;
1698
1699 if (dev->power.power_state.event != state->event) {
1700 dev_warn(dev, "pm state does not match request\n");
1701 return -1;
1702 }
1703
1704 return 0;
1705}
1706
1707static int spi_imx_suspend(struct platform_device *pdev, pm_message_t state)
1708{
1709 struct driver_data *drv_data = platform_get_drvdata(pdev);
1710 int status = 0;
1711
1712 status = stop_queue(drv_data);
1713 if (status != 0) {
1714 dev_warn(&pdev->dev, "suspend cannot stop queue\n");
1715 return status;
1716 }
1717
1718 dev_dbg(&pdev->dev, "suspended\n");
1719
1720 return 0;
1721}
1722
1723static int spi_imx_resume(struct platform_device *pdev)
1724{
1725 struct driver_data *drv_data = platform_get_drvdata(pdev);
1726 int status = 0;
1727
1728 /* Start the queue running */
1729 status = start_queue(drv_data);
1730 if (status != 0)
1731 dev_err(&pdev->dev, "problem starting queue (%d)\n", status);
1732 else
1733 dev_dbg(&pdev->dev, "resumed\n");
1734
1735 return status;
1736}
1737#else
1738#define spi_imx_suspend NULL
1739#define spi_imx_resume NULL
1740#endif /* CONFIG_PM */
1741
1742static struct platform_driver driver = {
1743 .driver = {
1744 .name = "imx-spi",
1745 .bus = &platform_bus_type,
1746 .owner = THIS_MODULE,
1747 },
1748 .probe = spi_imx_probe,
1749 .remove = __devexit_p(spi_imx_remove),
1750 .shutdown = spi_imx_shutdown,
1751 .suspend = spi_imx_suspend,
1752 .resume = spi_imx_resume,
1753};
1754
1755static int __init spi_imx_init(void)
1756{
1757 return platform_driver_register(&driver);
1758}
1759module_init(spi_imx_init);
1760
1761static void __exit spi_imx_exit(void)
1762{
1763 platform_driver_unregister(&driver);
1764}
1765module_exit(spi_imx_exit);
1766
1767MODULE_AUTHOR("Andrea Paterniani, <a.paterniani@swapp-eng.it>");
1768MODULE_DESCRIPTION("iMX SPI Contoller Driver");
1769MODULE_LICENSE("GPL");
diff --git a/drivers/tc/zs.c b/drivers/tc/zs.c
index fc319727366..3d72aa5cfc7 100644
--- a/drivers/tc/zs.c
+++ b/drivers/tc/zs.c
@@ -626,10 +626,8 @@ static void do_softint(unsigned long private_)
626 if (!tty) 626 if (!tty)
627 return; 627 return;
628 628
629 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event)) { 629 if (test_and_clear_bit(RS_EVENT_WRITE_WAKEUP, &info->event))
630 tty_wakeup(tty); 630 tty_wakeup(tty);
631 wake_up_interruptible(&tty->write_wait);
632 }
633} 631}
634 632
635static int zs_startup(struct dec_serial * info) 633static int zs_startup(struct dec_serial * info)
diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
index df4cc1fb5f6..71cb64e41a1 100644
--- a/drivers/telephony/ixj.c
+++ b/drivers/telephony/ixj.c
@@ -648,9 +648,9 @@ static inline BYTE SLIC_GetState(IXJ *j)
648 return j->pld_slicr.bits.state; 648 return j->pld_slicr.bits.state;
649} 649}
650 650
651static BOOL SLIC_SetState(BYTE byState, IXJ *j) 651static bool SLIC_SetState(BYTE byState, IXJ *j)
652{ 652{
653 BOOL fRetVal = FALSE; 653 bool fRetVal = false;
654 654
655 if (j->cardtype == QTI_PHONECARD) { 655 if (j->cardtype == QTI_PHONECARD) {
656 if (j->flags.pcmciasct) { 656 if (j->flags.pcmciasct) {
@@ -659,14 +659,14 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
659 case PLD_SLIC_STATE_OC: 659 case PLD_SLIC_STATE_OC:
660 j->pslic.bits.powerdown = 1; 660 j->pslic.bits.powerdown = 1;
661 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0; 661 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
662 fRetVal = TRUE; 662 fRetVal = true;
663 break; 663 break;
664 case PLD_SLIC_STATE_RINGING: 664 case PLD_SLIC_STATE_RINGING:
665 if (j->readers || j->writers) { 665 if (j->readers || j->writers) {
666 j->pslic.bits.powerdown = 0; 666 j->pslic.bits.powerdown = 0;
667 j->pslic.bits.ring0 = 1; 667 j->pslic.bits.ring0 = 1;
668 j->pslic.bits.ring1 = 0; 668 j->pslic.bits.ring1 = 0;
669 fRetVal = TRUE; 669 fRetVal = true;
670 } 670 }
671 break; 671 break;
672 case PLD_SLIC_STATE_OHT: /* On-hook transmit */ 672 case PLD_SLIC_STATE_OHT: /* On-hook transmit */
@@ -679,14 +679,14 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
679 j->pslic.bits.powerdown = 1; 679 j->pslic.bits.powerdown = 1;
680 } 680 }
681 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0; 681 j->pslic.bits.ring0 = j->pslic.bits.ring1 = 0;
682 fRetVal = TRUE; 682 fRetVal = true;
683 break; 683 break;
684 case PLD_SLIC_STATE_APR: /* Active polarity reversal */ 684 case PLD_SLIC_STATE_APR: /* Active polarity reversal */
685 685
686 case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */ 686 case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */
687 687
688 default: 688 default:
689 fRetVal = FALSE; 689 fRetVal = false;
690 break; 690 break;
691 } 691 }
692 j->psccr.bits.dev = 3; 692 j->psccr.bits.dev = 3;
@@ -703,7 +703,7 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
703 j->pld_slicw.bits.c3 = 0; 703 j->pld_slicw.bits.c3 = 0;
704 j->pld_slicw.bits.b2en = 0; 704 j->pld_slicw.bits.b2en = 0;
705 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01); 705 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
706 fRetVal = TRUE; 706 fRetVal = true;
707 break; 707 break;
708 case PLD_SLIC_STATE_RINGING: 708 case PLD_SLIC_STATE_RINGING:
709 j->pld_slicw.bits.c1 = 1; 709 j->pld_slicw.bits.c1 = 1;
@@ -711,7 +711,7 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
711 j->pld_slicw.bits.c3 = 0; 711 j->pld_slicw.bits.c3 = 0;
712 j->pld_slicw.bits.b2en = 1; 712 j->pld_slicw.bits.b2en = 1;
713 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01); 713 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
714 fRetVal = TRUE; 714 fRetVal = true;
715 break; 715 break;
716 case PLD_SLIC_STATE_ACTIVE: 716 case PLD_SLIC_STATE_ACTIVE:
717 j->pld_slicw.bits.c1 = 0; 717 j->pld_slicw.bits.c1 = 0;
@@ -719,7 +719,7 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
719 j->pld_slicw.bits.c3 = 0; 719 j->pld_slicw.bits.c3 = 0;
720 j->pld_slicw.bits.b2en = 0; 720 j->pld_slicw.bits.b2en = 0;
721 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01); 721 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
722 fRetVal = TRUE; 722 fRetVal = true;
723 break; 723 break;
724 case PLD_SLIC_STATE_OHT: /* On-hook transmit */ 724 case PLD_SLIC_STATE_OHT: /* On-hook transmit */
725 725
@@ -728,7 +728,7 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
728 j->pld_slicw.bits.c3 = 0; 728 j->pld_slicw.bits.c3 = 0;
729 j->pld_slicw.bits.b2en = 0; 729 j->pld_slicw.bits.b2en = 0;
730 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01); 730 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
731 fRetVal = TRUE; 731 fRetVal = true;
732 break; 732 break;
733 case PLD_SLIC_STATE_TIPOPEN: 733 case PLD_SLIC_STATE_TIPOPEN:
734 j->pld_slicw.bits.c1 = 0; 734 j->pld_slicw.bits.c1 = 0;
@@ -736,7 +736,7 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
736 j->pld_slicw.bits.c3 = 1; 736 j->pld_slicw.bits.c3 = 1;
737 j->pld_slicw.bits.b2en = 0; 737 j->pld_slicw.bits.b2en = 0;
738 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01); 738 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
739 fRetVal = TRUE; 739 fRetVal = true;
740 break; 740 break;
741 case PLD_SLIC_STATE_STANDBY: 741 case PLD_SLIC_STATE_STANDBY:
742 j->pld_slicw.bits.c1 = 1; 742 j->pld_slicw.bits.c1 = 1;
@@ -744,7 +744,7 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
744 j->pld_slicw.bits.c3 = 1; 744 j->pld_slicw.bits.c3 = 1;
745 j->pld_slicw.bits.b2en = 1; 745 j->pld_slicw.bits.b2en = 1;
746 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01); 746 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
747 fRetVal = TRUE; 747 fRetVal = true;
748 break; 748 break;
749 case PLD_SLIC_STATE_APR: /* Active polarity reversal */ 749 case PLD_SLIC_STATE_APR: /* Active polarity reversal */
750 750
@@ -753,7 +753,7 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
753 j->pld_slicw.bits.c3 = 1; 753 j->pld_slicw.bits.c3 = 1;
754 j->pld_slicw.bits.b2en = 0; 754 j->pld_slicw.bits.b2en = 0;
755 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01); 755 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
756 fRetVal = TRUE; 756 fRetVal = true;
757 break; 757 break;
758 case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */ 758 case PLD_SLIC_STATE_OHTPR: /* OHT polarity reversal */
759 759
@@ -762,10 +762,10 @@ static BOOL SLIC_SetState(BYTE byState, IXJ *j)
762 j->pld_slicw.bits.c3 = 1; 762 j->pld_slicw.bits.c3 = 1;
763 j->pld_slicw.bits.b2en = 0; 763 j->pld_slicw.bits.b2en = 0;
764 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01); 764 outb_p(j->pld_slicw.byte, j->XILINXbase + 0x01);
765 fRetVal = TRUE; 765 fRetVal = true;
766 break; 766 break;
767 default: 767 default:
768 fRetVal = FALSE; 768 fRetVal = false;
769 break; 769 break;
770 } 770 }
771 } 771 }
@@ -4969,7 +4969,8 @@ static int ixj_daa_cid_read(IXJ *j)
4969{ 4969{
4970 int i; 4970 int i;
4971 BYTES bytes; 4971 BYTES bytes;
4972 char CID[ALISDAA_CALLERID_SIZE], mContinue; 4972 char CID[ALISDAA_CALLERID_SIZE];
4973 bool mContinue;
4973 char *pIn, *pOut; 4974 char *pIn, *pOut;
4974 4975
4975 if (!SCI_Prepare(j)) 4976 if (!SCI_Prepare(j))
@@ -5013,7 +5014,7 @@ static int ixj_daa_cid_read(IXJ *j)
5013 5014
5014 pIn = CID; 5015 pIn = CID;
5015 pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID; 5016 pOut = j->m_DAAShadowRegs.CAO_REGS.CAO.CallerID;
5016 mContinue = 1; 5017 mContinue = true;
5017 while (mContinue) { 5018 while (mContinue) {
5018 if ((pIn[1] & 0x03) == 0x01) { 5019 if ((pIn[1] & 0x03) == 0x01) {
5019 pOut[0] = pIn[0]; 5020 pOut[0] = pIn[0];
@@ -5027,7 +5028,7 @@ static int ixj_daa_cid_read(IXJ *j)
5027 if ((pIn[4] & 0xc0) == 0x40) { 5028 if ((pIn[4] & 0xc0) == 0x40) {
5028 pOut[3] = ((pIn[4] & 0x3f) << 2) | ((pIn[3] & 0xc0) >> 6); 5029 pOut[3] = ((pIn[4] & 0x3f) << 2) | ((pIn[3] & 0xc0) >> 6);
5029 } else { 5030 } else {
5030 mContinue = FALSE; 5031 mContinue = false;
5031 } 5032 }
5032 pIn += 5, pOut += 4; 5033 pIn += 5, pOut += 4;
5033 } 5034 }
@@ -6662,7 +6663,7 @@ static int ixj_fasync(int fd, struct file *file_p, int mode)
6662 return fasync_helper(fd, file_p, mode, &j->async_queue); 6663 return fasync_helper(fd, file_p, mode, &j->async_queue);
6663} 6664}
6664 6665
6665static struct file_operations ixj_fops = 6666static const struct file_operations ixj_fops =
6666{ 6667{
6667 .owner = THIS_MODULE, 6668 .owner = THIS_MODULE,
6668 .read = ixj_enhanced_read, 6669 .read = ixj_enhanced_read,
@@ -7498,7 +7499,7 @@ static BYTE PCIEE_ReadBit(WORD wEEPROMAddress, BYTE lastLCC)
7498 return ((inb(wEEPROMAddress) >> 3) & 1); 7499 return ((inb(wEEPROMAddress) >> 3) & 1);
7499} 7500}
7500 7501
7501static BOOL PCIEE_ReadWord(WORD wAddress, WORD wLoc, WORD * pwResult) 7502static bool PCIEE_ReadWord(WORD wAddress, WORD wLoc, WORD * pwResult)
7502{ 7503{
7503 BYTE lastLCC; 7504 BYTE lastLCC;
7504 WORD wEEPROMAddress = wAddress + 3; 7505 WORD wEEPROMAddress = wAddress + 3;
diff --git a/drivers/telephony/ixj.h b/drivers/telephony/ixj.h
index 8d69bcdc29c..4c32a43b791 100644
--- a/drivers/telephony/ixj.h
+++ b/drivers/telephony/ixj.h
@@ -48,15 +48,11 @@
48typedef __u16 WORD; 48typedef __u16 WORD;
49typedef __u32 DWORD; 49typedef __u32 DWORD;
50typedef __u8 BYTE; 50typedef __u8 BYTE;
51typedef __u8 BOOL;
52 51
53#ifndef IXJMAX 52#ifndef IXJMAX
54#define IXJMAX 16 53#define IXJMAX 16
55#endif 54#endif
56 55
57#define TRUE 1
58#define FALSE 0
59
60/****************************************************************************** 56/******************************************************************************
61* 57*
62* This structure when unioned with the structures below makes simple byte 58* This structure when unioned with the structures below makes simple byte
diff --git a/drivers/telephony/phonedev.c b/drivers/telephony/phonedev.c
index e41f49afd0f..4d8c2a5b329 100644
--- a/drivers/telephony/phonedev.c
+++ b/drivers/telephony/phonedev.c
@@ -127,7 +127,7 @@ void phone_unregister_device(struct phone_device *pfd)
127} 127}
128 128
129 129
130static struct file_operations phone_fops = 130static const struct file_operations phone_fops =
131{ 131{
132 .owner = THIS_MODULE, 132 .owner = THIS_MODULE,
133 .open = phone_open, 133 .open = phone_open,
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index f04a29a4664..c6b6479fa4d 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -1953,7 +1953,7 @@ static void invalidate_sub(struct lun *curlun)
1953 struct inode *inode = filp->f_path.dentry->d_inode; 1953 struct inode *inode = filp->f_path.dentry->d_inode;
1954 unsigned long rc; 1954 unsigned long rc;
1955 1955
1956 rc = invalidate_inode_pages(inode->i_mapping); 1956 rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
1957 VLDBG(curlun, "invalidate_inode_pages -> %ld\n", rc); 1957 VLDBG(curlun, "invalidate_inode_pages -> %ld\n", rc);
1958} 1958}
1959 1959
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 408c3380d60..6ec8cf1a3cc 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -1419,7 +1419,6 @@ int __devinit rndis_init (void)
1419 return -EIO; 1419 return -EIO;
1420 } 1420 }
1421 1421
1422 rndis_connect_state [i]->nlink = 1;
1423 rndis_connect_state [i]->write_proc = rndis_proc_write; 1422 rndis_connect_state [i]->write_proc = rndis_proc_write;
1424 rndis_connect_state [i]->read_proc = rndis_proc_read; 1423 rndis_connect_state [i]->read_proc = rndis_proc_read;
1425 rndis_connect_state [i]->data = (void *) 1424 rndis_connect_state [i]->data = (void *)
diff --git a/drivers/usb/host/hc_crisv10.c b/drivers/usb/host/hc_crisv10.c
index 282d82efc0b..f0ffb8907f2 100644
--- a/drivers/usb/host/hc_crisv10.c
+++ b/drivers/usb/host/hc_crisv10.c
@@ -2163,9 +2163,8 @@ static void etrax_usb_add_to_bulk_sb_list(struct urb *urb, int epid)
2163 2163
2164 maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)); 2164 maxlen = usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe));
2165 2165
2166 sb_desc = (USB_SB_Desc_t*)kmem_cache_alloc(usb_desc_cache, SLAB_FLAG); 2166 sb_desc = kmem_cache_zalloc(usb_desc_cache, SLAB_FLAG);
2167 assert(sb_desc != NULL); 2167 assert(sb_desc != NULL);
2168 memset(sb_desc, 0, sizeof(USB_SB_Desc_t));
2169 2168
2170 2169
2171 if (usb_pipeout(urb->pipe)) { 2170 if (usb_pipeout(urb->pipe)) {
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 2cbb239e63f..68e66b33e72 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -624,12 +624,10 @@ static inline struct urb_priv *uhci_alloc_urb_priv(struct uhci_hcd *uhci,
624{ 624{
625 struct urb_priv *urbp; 625 struct urb_priv *urbp;
626 626
627 urbp = kmem_cache_alloc(uhci_up_cachep, GFP_ATOMIC); 627 urbp = kmem_cache_zalloc(uhci_up_cachep, GFP_ATOMIC);
628 if (!urbp) 628 if (!urbp)
629 return NULL; 629 return NULL;
630 630
631 memset((void *)urbp, 0, sizeof(*urbp));
632
633 urbp->urb = urb; 631 urbp->urb = urb;
634 urb->hcpriv = urbp; 632 urb->hcpriv = urbp;
635 633
diff --git a/drivers/usb/input/hid-ff.c b/drivers/usb/input/hid-ff.c
index 5d145058a5c..bc7f8e6f8c9 100644
--- a/drivers/usb/input/hid-ff.c
+++ b/drivers/usb/input/hid-ff.c
@@ -57,6 +57,7 @@ static struct hid_ff_initializer inits[] = {
57 { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */ 57 { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */
58 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */ 58 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */
59 { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */ 59 { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */
60 { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */
60#endif 61#endif
61#ifdef CONFIG_PANTHERLORD_FF 62#ifdef CONFIG_PANTHERLORD_FF
62 { 0x810, 0x0001, hid_plff_init }, 63 { 0x810, 0x0001, hid_plff_init },
diff --git a/drivers/usb/input/hid-lgff.c b/drivers/usb/input/hid-lgff.c
index 4f4fc3be192..4df0968f852 100644
--- a/drivers/usb/input/hid-lgff.c
+++ b/drivers/usb/input/hid-lgff.c
@@ -52,6 +52,7 @@ static const struct dev_type devices[] = {
52 { 0x046d, 0xc211, ff_rumble }, 52 { 0x046d, 0xc211, ff_rumble },
53 { 0x046d, 0xc219, ff_rumble }, 53 { 0x046d, 0xc219, ff_rumble },
54 { 0x046d, 0xc283, ff_joystick }, 54 { 0x046d, 0xc283, ff_joystick },
55 { 0x046d, 0xca03, ff_joystick },
55 { 0x0000, 0x0000, ff_joystick } 56 { 0x0000, 0x0000, ff_joystick }
56}; 57};
57 58
diff --git a/drivers/usb/misc/adutux.c b/drivers/usb/misc/adutux.c
index af2934e016a..75bfab95ab3 100644
--- a/drivers/usb/misc/adutux.c
+++ b/drivers/usb/misc/adutux.c
@@ -644,7 +644,7 @@ exit:
644} 644}
645 645
646/* file operations needed when we register this driver */ 646/* file operations needed when we register this driver */
647static struct file_operations adu_fops = { 647static const struct file_operations adu_fops = {
648 .owner = THIS_MODULE, 648 .owner = THIS_MODULE,
649 .read = adu_read, 649 .read = adu_read,
650 .write = adu_write, 650 .write = adu_write,
diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
index a7932a72d29..32f0e3a5b02 100644
--- a/drivers/usb/misc/appledisplay.c
+++ b/drivers/usb/misc/appledisplay.c
@@ -281,8 +281,8 @@ static int appledisplay_probe(struct usb_interface *iface,
281 /* Register backlight device */ 281 /* Register backlight device */
282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d", 282 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
283 atomic_inc_return(&count_displays) - 1); 283 atomic_inc_return(&count_displays) - 1);
284 pdata->bd = backlight_device_register(bl_name, NULL, NULL, 284 pdata->bd = backlight_device_register(bl_name, NULL,
285 &appledisplay_bl_data); 285 pdata, &appledisplay_bl_data);
286 if (IS_ERR(pdata->bd)) { 286 if (IS_ERR(pdata->bd)) {
287 err("appledisplay: Backlight registration failed"); 287 err("appledisplay: Backlight registration failed");
288 goto error; 288 goto error;
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 41c0161abdb..0c1d66ddb81 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -1209,7 +1209,7 @@ error_1:
1209 return retval; 1209 return retval;
1210} 1210}
1211 1211
1212static struct file_operations ftdi_elan_fops = { 1212static const struct file_operations ftdi_elan_fops = {
1213 .owner = THIS_MODULE, 1213 .owner = THIS_MODULE,
1214 .llseek = no_llseek, 1214 .llseek = no_llseek,
1215 .ioctl = ftdi_elan_ioctl, 1215 .ioctl = ftdi_elan_ioctl,
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 0b0fb51bad3..d78692c01cf 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -616,15 +616,7 @@ static void digi_wakeup_write_lock(struct work_struct *work)
616 616
617static void digi_wakeup_write( struct usb_serial_port *port ) 617static void digi_wakeup_write( struct usb_serial_port *port )
618{ 618{
619 619 tty_wakeup(port->tty);
620 struct tty_struct *tty = port->tty;
621
622
623 /* wake up port processes */
624 wake_up_interruptible( &port->write_wait );
625
626 /* wake up line discipline */
627 tty_wakeup(tty);
628} 620}
629 621
630 622
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index da514cb785b..dd0b66a6ed5 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -182,13 +182,8 @@ static void keyspan_pda_wakeup_write(struct work_struct *work)
182 struct keyspan_pda_private *priv = 182 struct keyspan_pda_private *priv =
183 container_of(work, struct keyspan_pda_private, wakeup_work); 183 container_of(work, struct keyspan_pda_private, wakeup_work);
184 struct usb_serial_port *port = priv->port; 184 struct usb_serial_port *port = priv->port;
185 struct tty_struct *tty = port->tty;
186 185
187 /* wake up port processes */ 186 tty_wakeup(port->tty);
188 wake_up_interruptible( &port->write_wait );
189
190 /* wake up line discipline */
191 tty_wakeup(tty);
192} 187}
193 188
194static void keyspan_pda_request_unthrottle(struct work_struct *work) 189static void keyspan_pda_request_unthrottle(struct work_struct *work)
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 6109c6704a7..2d588fb8257 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -269,18 +269,8 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
269 269
270 tty = mos7720_port->port->tty; 270 tty = mos7720_port->port->tty;
271 271
272 if (tty && mos7720_port->open) { 272 if (tty && mos7720_port->open)
273 /* let the tty driver wakeup if it has a special * 273 tty_wakeup(tty);
274 * write_wakeup function */
275 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
276 tty->ldisc.write_wakeup)
277 (tty->ldisc.write_wakeup)(tty);
278
279 /* tell the tty driver that something has changed */
280 wake_up_interruptible(&tty->write_wait);
281 }
282
283 /* schedule_work(&mos7720_port->port->work); */
284} 274}
285 275
286/* 276/*
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index b2264a87617..c6cca859af4 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -755,18 +755,8 @@ static void mos7840_bulk_out_data_callback(struct urb *urb)
755 755
756 tty = mos7840_port->port->tty; 756 tty = mos7840_port->port->tty;
757 757
758 if (tty && mos7840_port->open) { 758 if (tty && mos7840_port->open)
759 /* let the tty driver wakeup if it has a special * 759 tty_wakeup(tty);
760 * write_wakeup function */
761
762 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP))
763 && tty->ldisc.write_wakeup) {
764 (tty->ldisc.write_wakeup) (tty);
765 }
766
767 /* tell the tty driver that something has changed */
768 wake_up_interruptible(&tty->write_wait);
769 }
770 760
771} 761}
772 762
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index 45fe65d8d7a..8874cf2fd27 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -85,6 +85,14 @@ config FB_CFB_IMAGEBLIT
85 blitting. This is used by drivers that don't provide their own 85 blitting. This is used by drivers that don't provide their own
86 (accelerated) version. 86 (accelerated) version.
87 87
88config FB_SVGALIB
89 tristate
90 depends on FB
91 default n
92 ---help---
93 Common utility functions useful to fbdev drivers of VGA-based
94 cards.
95
88config FB_MACMODES 96config FB_MACMODES
89 tristate 97 tristate
90 depends on FB 98 depends on FB
@@ -346,42 +354,6 @@ config FB_AMIGA_AGA
346 and CD32. If you intend to run Linux on any of these systems, say Y; 354 and CD32. If you intend to run Linux on any of these systems, say Y;
347 otherwise say N. 355 otherwise say N.
348 356
349config FB_CYBER
350 tristate "Amiga CyberVision 64 support"
351 depends on FB && ZORRO && BROKEN
352 select FB_CFB_FILLRECT
353 select FB_CFB_COPYAREA
354 select FB_CFB_IMAGEBLIT
355 help
356 This enables support for the Cybervision 64 graphics card from
357 Phase5. Please note that its use is not all that intuitive (i.e. if
358 you have any questions, be sure to ask!). Say N unless you have a
359 Cybervision 64 or plan to get one before you next recompile the
360 kernel. Please note that this driver DOES NOT support the
361 Cybervision 64/3D card, as they use incompatible video chips.
362
363config FB_VIRGE
364 bool "Amiga CyberVision 64/3D support "
365 depends on (FB = y) && ZORRO && BROKEN
366 select FB_CFB_FILLRECT
367 select FB_CFB_COPYAREA
368 select FB_CFB_IMAGEBLIT
369 help
370 This enables support for the Cybervision 64/3D graphics card from
371 Phase5. Please note that its use is not all that intuitive (i.e. if
372 you have any questions, be sure to ask!). Say N unless you have a
373 Cybervision 64/3D or plan to get one before you next recompile the
374 kernel. Please note that this driver DOES NOT support the older
375 Cybervision 64 card, as they use incompatible video chips.
376
377config FB_RETINAZ3
378 tristate "Amiga Retina Z3 support"
379 depends on (FB = y) && ZORRO && BROKEN
380 help
381 This enables support for the Retina Z3 graphics card. Say N unless
382 you have a Retina Z3 or plan to get one before you next recompile
383 the kernel.
384
385config FB_FM2 357config FB_FM2
386 bool "Amiga FrameMaster II/Rainbow II support" 358 bool "Amiga FrameMaster II/Rainbow II support"
387 depends on (FB = y) && ZORRO 359 depends on (FB = y) && ZORRO
@@ -617,10 +589,6 @@ config FB_GBE_MEM
617 This is the amount of memory reserved for the framebuffer, 589 This is the amount of memory reserved for the framebuffer,
618 which can be any value between 1MB and 8MB. 590 which can be any value between 1MB and 8MB.
619 591
620config FB_SUN3
621 bool "Sun3 framebuffer support"
622 depends on (FB = y) && (SUN3 || SUN3X) && BROKEN
623
624config FB_SBUS 592config FB_SBUS
625 bool "SBUS and UPA framebuffers" 593 bool "SBUS and UPA framebuffers"
626 depends on (FB = y) && SPARC 594 depends on (FB = y) && SPARC
@@ -629,7 +597,7 @@ config FB_SBUS
629 597
630config FB_BW2 598config FB_BW2
631 bool "BWtwo support" 599 bool "BWtwo support"
632 depends on (FB = y) && (SPARC && FB_SBUS || (SUN3 || SUN3X) && FB_SUN3) 600 depends on (FB = y) && (SPARC && FB_SBUS)
633 select FB_CFB_FILLRECT 601 select FB_CFB_FILLRECT
634 select FB_CFB_COPYAREA 602 select FB_CFB_COPYAREA
635 select FB_CFB_IMAGEBLIT 603 select FB_CFB_IMAGEBLIT
@@ -638,7 +606,7 @@ config FB_BW2
638 606
639config FB_CG3 607config FB_CG3
640 bool "CGthree support" 608 bool "CGthree support"
641 depends on (FB = y) && (SPARC && FB_SBUS || (SUN3 || SUN3X) && FB_SUN3) 609 depends on (FB = y) && (SPARC && FB_SBUS)
642 select FB_CFB_FILLRECT 610 select FB_CFB_FILLRECT
643 select FB_CFB_COPYAREA 611 select FB_CFB_COPYAREA
644 select FB_CFB_IMAGEBLIT 612 select FB_CFB_IMAGEBLIT
@@ -647,7 +615,7 @@ config FB_CG3
647 615
648config FB_CG6 616config FB_CG6
649 bool "CGsix (GX,TurboGX) support" 617 bool "CGsix (GX,TurboGX) support"
650 depends on (FB = y) && (SPARC && FB_SBUS || (SUN3 || SUN3X) && FB_SUN3) 618 depends on (FB = y) && (SPARC && FB_SBUS)
651 select FB_CFB_COPYAREA 619 select FB_CFB_COPYAREA
652 select FB_CFB_IMAGEBLIT 620 select FB_CFB_IMAGEBLIT
653 help 621 help
@@ -1141,11 +1109,16 @@ config FB_ATY_BACKLIGHT
1141 help 1109 help
1142 Say Y here if you want to control the backlight of your display. 1110 Say Y here if you want to control the backlight of your display.
1143 1111
1144config FB_S3TRIO 1112config FB_S3
1145 bool "S3 Trio display support" 1113 tristate "S3 Trio/Virge support"
1146 depends on (FB = y) && PPC && BROKEN 1114 depends on FB && PCI
1147 help 1115 select FB_CFB_FILLRECT
1148 If you have a S3 Trio say Y. Say N for S3 Virge. 1116 select FB_CFB_COPYAREA
1117 select FB_CFB_IMAGEBLIT
1118 select FB_TILEBLITTING
1119 select FB_SVGALIB
1120 ---help---
1121 Driver for graphics boards with S3 Trio / S3 Virge chip.
1149 1122
1150config FB_SAVAGE 1123config FB_SAVAGE
1151 tristate "S3 Savage support" 1124 tristate "S3 Savage support"
@@ -1625,6 +1598,26 @@ config FB_IBM_GXT4500
1625 Say Y here to enable support for the IBM GXT4500P display 1598 Say Y here to enable support for the IBM GXT4500P display
1626 adaptor, found on some IBM System P (pSeries) machines. 1599 adaptor, found on some IBM System P (pSeries) machines.
1627 1600
1601config FB_PS3
1602 bool "PS3 GPU framebuffer driver"
1603 depends on FB && PPC_PS3
1604 select PS3_PS3AV
1605 select FB_CFB_FILLRECT
1606 select FB_CFB_COPYAREA
1607 select FB_CFB_IMAGEBLIT
1608 ---help---
1609 Include support for the virtual frame buffer in the PS3 platform.
1610
1611config FB_PS3_DEFAULT_SIZE_M
1612 int "PS3 default frame buffer size (in MiB)"
1613 depends on FB_PS3
1614 default 18
1615 ---help---
1616 This is the default size (in MiB) of the virtual frame buffer in
1617 the PS3.
1618 The default value can be overridden on the kernel command line
1619 using the "ps3fb" option (e.g. "ps3fb=9M");
1620
1628config FB_VIRTUAL 1621config FB_VIRTUAL
1629 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)" 1622 tristate "Virtual Frame Buffer support (ONLY FOR TESTING!)"
1630 depends on FB 1623 depends on FB
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index 309a26dd164..6801edff36d 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -17,15 +17,14 @@ obj-$(CONFIG_SYSFS) += backlight/
17obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o 17obj-$(CONFIG_FB_CFB_FILLRECT) += cfbfillrect.o
18obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o 18obj-$(CONFIG_FB_CFB_COPYAREA) += cfbcopyarea.o
19obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o 19obj-$(CONFIG_FB_CFB_IMAGEBLIT) += cfbimgblt.o
20obj-$(CONFIG_FB_SVGALIB) += svgalib.o
20obj-$(CONFIG_FB_MACMODES) += macmodes.o 21obj-$(CONFIG_FB_MACMODES) += macmodes.o
21obj-$(CONFIG_FB_DDC) += fb_ddc.o 22obj-$(CONFIG_FB_DDC) += fb_ddc.o
22 23
23# Hardware specific drivers go first 24# Hardware specific drivers go first
24obj-$(CONFIG_FB_RETINAZ3) += retz3fb.o
25obj-$(CONFIG_FB_AMIGA) += amifb.o c2p.o 25obj-$(CONFIG_FB_AMIGA) += amifb.o c2p.o
26obj-$(CONFIG_FB_ARC) += arcfb.o 26obj-$(CONFIG_FB_ARC) += arcfb.o
27obj-$(CONFIG_FB_CLPS711X) += clps711xfb.o 27obj-$(CONFIG_FB_CLPS711X) += clps711xfb.o
28obj-$(CONFIG_FB_CYBER) += cyberfb.o
29obj-$(CONFIG_FB_CYBER2000) += cyber2000fb.o 28obj-$(CONFIG_FB_CYBER2000) += cyber2000fb.o
30obj-$(CONFIG_FB_PM2) += pm2fb.o 29obj-$(CONFIG_FB_PM2) += pm2fb.o
31obj-$(CONFIG_FB_PM3) += pm3fb.o 30obj-$(CONFIG_FB_PM3) += pm3fb.o
@@ -43,17 +42,16 @@ obj-$(CONFIG_FB_GEODE) += geode/
43obj-$(CONFIG_FB_MBX) += mbx/ 42obj-$(CONFIG_FB_MBX) += mbx/
44obj-$(CONFIG_FB_I810) += vgastate.o 43obj-$(CONFIG_FB_I810) += vgastate.o
45obj-$(CONFIG_FB_NEOMAGIC) += neofb.o vgastate.o 44obj-$(CONFIG_FB_NEOMAGIC) += neofb.o vgastate.o
46obj-$(CONFIG_FB_VIRGE) += virgefb.o
47obj-$(CONFIG_FB_3DFX) += tdfxfb.o 45obj-$(CONFIG_FB_3DFX) += tdfxfb.o
48obj-$(CONFIG_FB_CONTROL) += controlfb.o 46obj-$(CONFIG_FB_CONTROL) += controlfb.o
49obj-$(CONFIG_FB_PLATINUM) += platinumfb.o 47obj-$(CONFIG_FB_PLATINUM) += platinumfb.o
50obj-$(CONFIG_FB_VALKYRIE) += valkyriefb.o 48obj-$(CONFIG_FB_VALKYRIE) += valkyriefb.o
51obj-$(CONFIG_FB_CT65550) += chipsfb.o 49obj-$(CONFIG_FB_CT65550) += chipsfb.o
52obj-$(CONFIG_FB_IMSTT) += imsttfb.o 50obj-$(CONFIG_FB_IMSTT) += imsttfb.o
53obj-$(CONFIG_FB_S3TRIO) += S3triofb.o
54obj-$(CONFIG_FB_FM2) += fm2fb.o 51obj-$(CONFIG_FB_FM2) += fm2fb.o
55obj-$(CONFIG_FB_CYBLA) += cyblafb.o 52obj-$(CONFIG_FB_CYBLA) += cyblafb.o
56obj-$(CONFIG_FB_TRIDENT) += tridentfb.o 53obj-$(CONFIG_FB_TRIDENT) += tridentfb.o
54obj-$(CONFIG_FB_S3) += s3fb.o vgastate.o
57obj-$(CONFIG_FB_STI) += stifb.o 55obj-$(CONFIG_FB_STI) += stifb.o
58obj-$(CONFIG_FB_FFB) += ffb.o sbuslib.o 56obj-$(CONFIG_FB_FFB) += ffb.o sbuslib.o
59obj-$(CONFIG_FB_CG6) += cg6.o sbuslib.o 57obj-$(CONFIG_FB_CG6) += cg6.o sbuslib.o
@@ -75,7 +73,6 @@ obj-$(CONFIG_FB_TGA) += tgafb.o
75obj-$(CONFIG_FB_HP300) += hpfb.o 73obj-$(CONFIG_FB_HP300) += hpfb.o
76obj-$(CONFIG_FB_G364) += g364fb.o 74obj-$(CONFIG_FB_G364) += g364fb.o
77obj-$(CONFIG_FB_SA1100) += sa1100fb.o 75obj-$(CONFIG_FB_SA1100) += sa1100fb.o
78obj-$(CONFIG_FB_SUN3) += sun3fb.o
79obj-$(CONFIG_FB_HIT) += hitfb.o 76obj-$(CONFIG_FB_HIT) += hitfb.o
80obj-$(CONFIG_FB_EPSON1355) += epson1355fb.o 77obj-$(CONFIG_FB_EPSON1355) += epson1355fb.o
81obj-$(CONFIG_FB_PVR2) += pvr2fb.o 78obj-$(CONFIG_FB_PVR2) += pvr2fb.o
@@ -100,6 +97,7 @@ obj-$(CONFIG_FB_S3C2410) += s3c2410fb.o
100obj-$(CONFIG_FB_PNX4008_DUM) += pnx4008/ 97obj-$(CONFIG_FB_PNX4008_DUM) += pnx4008/
101obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/ 98obj-$(CONFIG_FB_PNX4008_DUM_RGB) += pnx4008/
102obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o 99obj-$(CONFIG_FB_IBM_GXT4500) += gxt4500.o
100obj-$(CONFIG_FB_PS3) += ps3fb.o
103 101
104# Platform or fallback drivers go here 102# Platform or fallback drivers go here
105obj-$(CONFIG_FB_VESA) += vesafb.o 103obj-$(CONFIG_FB_VESA) += vesafb.o
diff --git a/drivers/video/S3triofb.c b/drivers/video/S3triofb.c
deleted file mode 100644
index b3717c8f1bc..00000000000
--- a/drivers/video/S3triofb.c
+++ /dev/null
@@ -1,790 +0,0 @@
1/*
2 * linux/drivers/video/S3Triofb.c -- Open Firmware based frame buffer device
3 *
4 * Copyright (C) 1997 Peter De Schrijver
5 *
6 * This driver is partly based on the PowerMac console driver:
7 *
8 * Copyright (C) 1996 Paul Mackerras
9 *
10 * and on the Open Firmware based frame buffer device:
11 *
12 * Copyright (C) 1997 Geert Uytterhoeven
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 for
16 * more details.
17 */
18
19/*
20 Bugs : + OF dependencies should be removed.
21 + This driver should be merged with the CyberVision driver. The
22 CyberVision is a Zorro III implementation of the S3Trio64 chip.
23
24*/
25
26#include <linux/kernel.h>
27#include <linux/module.h>
28#include <linux/errno.h>
29#include <linux/string.h>
30#include <linux/mm.h>
31#include <linux/slab.h>
32#include <linux/vmalloc.h>
33#include <linux/delay.h>
34#include <linux/interrupt.h>
35#include <linux/fb.h>
36#include <linux/init.h>
37#include <linux/selection.h>
38#include <asm/io.h>
39#include <asm/prom.h>
40#include <asm/pci-bridge.h>
41#include <linux/pci.h>
42
43#include <video/fbcon.h>
44#include <video/fbcon-cfb8.h>
45#include <video/s3blit.h>
46
47
48#define mem_in8(addr) in_8((void *)(addr))
49#define mem_in16(addr) in_le16((void *)(addr))
50#define mem_in32(addr) in_le32((void *)(addr))
51
52#define mem_out8(val, addr) out_8((void *)(addr), val)
53#define mem_out16(val, addr) out_le16((void *)(addr), val)
54#define mem_out32(val, addr) out_le32((void *)(addr), val)
55
56#define IO_OUT16VAL(v, r) (((v) << 8) | (r))
57
58static struct display disp;
59static struct fb_info fb_info;
60static struct { u_char red, green, blue, pad; } palette[256];
61static char s3trio_name[16] = "S3Trio ";
62static char *s3trio_base;
63
64static struct fb_fix_screeninfo fb_fix;
65static struct fb_var_screeninfo fb_var = { 0, };
66
67
68 /*
69 * Interface used by the world
70 */
71
72static void __init s3triofb_of_init(struct device_node *dp);
73static int s3trio_get_fix(struct fb_fix_screeninfo *fix, int con,
74 struct fb_info *info);
75static int s3trio_get_var(struct fb_var_screeninfo *var, int con,
76 struct fb_info *info);
77static int s3trio_set_var(struct fb_var_screeninfo *var, int con,
78 struct fb_info *info);
79static int s3trio_get_cmap(struct fb_cmap *cmap, int kspc, int con,
80 struct fb_info *info);
81static int s3trio_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
82 u_int transp, struct fb_info *info);
83static int s3trio_pan_display(struct fb_var_screeninfo *var, int con,
84 struct fb_info *info);
85static void s3triofb_blank(int blank, struct fb_info *info);
86
87 /*
88 * Interface to the low level console driver
89 */
90
91int s3triofb_init(void);
92static int s3triofbcon_switch(int con, struct fb_info *info);
93static int s3triofbcon_updatevar(int con, struct fb_info *info);
94
95 /*
96 * Text console acceleration
97 */
98
99#ifdef FBCON_HAS_CFB8
100static struct display_switch fbcon_trio8;
101#endif
102
103 /*
104 * Accelerated Functions used by the low level console driver
105 */
106
107static void Trio_WaitQueue(u_short fifo);
108static void Trio_WaitBlit(void);
109static void Trio_BitBLT(u_short curx, u_short cury, u_short destx,
110 u_short desty, u_short width, u_short height,
111 u_short mode);
112static void Trio_RectFill(u_short x, u_short y, u_short width, u_short height,
113 u_short mode, u_short color);
114static void Trio_MoveCursor(u_short x, u_short y);
115
116
117 /*
118 * Internal routines
119 */
120
121static int s3trio_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
122 u_int *transp, struct fb_info *info);
123
124static struct fb_ops s3trio_ops = {
125 .owner = THIS_MODULE,
126 .fb_get_fix = s3trio_get_fix,
127 .fb_get_var = s3trio_get_var,
128 .fb_set_var = s3trio_set_var,
129 .fb_get_cmap = s3trio_get_cmap,
130 .fb_set_cmap = gen_set_cmap,
131 .fb_setcolreg = s3trio_setcolreg,
132 .fb_pan_display =s3trio_pan_display,
133 .fb_blank = s3triofb_blank,
134};
135
136 /*
137 * Get the Fixed Part of the Display
138 */
139
140static int s3trio_get_fix(struct fb_fix_screeninfo *fix, int con,
141 struct fb_info *info)
142{
143 memcpy(fix, &fb_fix, sizeof(fb_fix));
144 return 0;
145}
146
147
148 /*
149 * Get the User Defined Part of the Display
150 */
151
152static int s3trio_get_var(struct fb_var_screeninfo *var, int con,
153 struct fb_info *info)
154{
155 memcpy(var, &fb_var, sizeof(fb_var));
156 return 0;
157}
158
159
160 /*
161 * Set the User Defined Part of the Display
162 */
163
164static int s3trio_set_var(struct fb_var_screeninfo *var, int con,
165 struct fb_info *info)
166{
167 if (var->xres > fb_var.xres || var->yres > fb_var.yres ||
168 var->bits_per_pixel > fb_var.bits_per_pixel )
169 /* || var->nonstd || var->vmode != FB_VMODE_NONINTERLACED) */
170 return -EINVAL;
171 if (var->xres_virtual > fb_var.xres_virtual) {
172 outw(IO_OUT16VAL((var->xres_virtual /8) & 0xff, 0x13), 0x3d4);
173 outw(IO_OUT16VAL(((var->xres_virtual /8 ) & 0x300) >> 3, 0x51), 0x3d4);
174 fb_var.xres_virtual = var->xres_virtual;
175 fb_fix.line_length = var->xres_virtual;
176 }
177 fb_var.yres_virtual = var->yres_virtual;
178 memcpy(var, &fb_var, sizeof(fb_var));
179 return 0;
180}
181
182
183 /*
184 * Pan or Wrap the Display
185 *
186 * This call looks only at xoffset, yoffset and the FB_VMODE_YWRAP flag
187 */
188
189static int s3trio_pan_display(struct fb_var_screeninfo *var, int con,
190 struct fb_info *info)
191{
192 unsigned int base;
193
194 if (var->xoffset > (var->xres_virtual - var->xres))
195 return -EINVAL;
196 if (var->yoffset > (var->yres_virtual - var->yres))
197 return -EINVAL;
198
199 fb_var.xoffset = var->xoffset;
200 fb_var.yoffset = var->yoffset;
201
202 base = var->yoffset * fb_fix.line_length + var->xoffset;
203
204 outw(IO_OUT16VAL((base >> 8) & 0xff, 0x0c),0x03D4);
205 outw(IO_OUT16VAL(base & 0xff, 0x0d),0x03D4);
206 outw(IO_OUT16VAL((base >> 16) & 0xf, 0x69),0x03D4);
207 return 0;
208}
209
210
211 /*
212 * Get the Colormap
213 */
214
215static int s3trio_get_cmap(struct fb_cmap *cmap, int kspc, int con,
216 struct fb_info *info)
217{
218 if (con == info->currcon) /* current console? */
219 return fb_get_cmap(cmap, kspc, s3trio_getcolreg, info);
220 else if (fb_display[con].cmap.len) /* non default colormap? */
221 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
222 else
223 fb_copy_cmap(fb_default_cmap(1 << fb_display[con].var.bits_per_pixel),
224 cmap, kspc ? 0 : 2);
225 return 0;
226}
227
228int __init s3triofb_init(void)
229{
230 struct device_node *dp;
231
232 dp = find_devices("S3Trio");
233 if (dp != 0)
234 s3triofb_of_init(dp);
235 return 0;
236}
237
238void __init s3trio_resetaccel(void){
239
240
241#define EC01_ENH_ENB 0x0005
242#define EC01_LAW_ENB 0x0010
243#define EC01_MMIO_ENB 0x0020
244
245#define EC00_RESET 0x8000
246#define EC00_ENABLE 0x4000
247#define MF_MULT_MISC 0xE000
248#define SRC_FOREGROUND 0x0020
249#define SRC_BACKGROUND 0x0000
250#define MIX_SRC 0x0007
251#define MF_T_CLIP 0x1000
252#define MF_L_CLIP 0x2000
253#define MF_B_CLIP 0x3000
254#define MF_R_CLIP 0x4000
255#define MF_PIX_CONTROL 0xA000
256#define MFA_SRC_FOREGR_MIX 0x0000
257#define MF_PIX_CONTROL 0xA000
258
259 outw(EC00_RESET, 0x42e8);
260 inw( 0x42e8);
261 outw(EC00_ENABLE, 0x42e8);
262 inw( 0x42e8);
263 outw(EC01_ENH_ENB | EC01_LAW_ENB,
264 0x4ae8);
265 outw(MF_MULT_MISC, 0xbee8); /* 16 bit I/O registers */
266
267 /* Now set some basic accelerator registers */
268 Trio_WaitQueue(0x0400);
269 outw(SRC_FOREGROUND | MIX_SRC, 0xbae8);
270 outw(SRC_BACKGROUND | MIX_SRC, 0xb6e8);/* direct color*/
271 outw(MF_T_CLIP | 0, 0xbee8 ); /* clip virtual area */
272 outw(MF_L_CLIP | 0, 0xbee8 );
273 outw(MF_R_CLIP | (640 - 1), 0xbee8);
274 outw(MF_B_CLIP | (480 - 1), 0xbee8);
275 Trio_WaitQueue(0x0400);
276 outw(0xffff, 0xaae8); /* Enable all planes */
277 outw(0xffff, 0xaae8); /* Enable all planes */
278 outw( MF_PIX_CONTROL | MFA_SRC_FOREGR_MIX, 0xbee8);
279}
280
281int __init s3trio_init(struct device_node *dp){
282
283 u_char bus, dev;
284 unsigned int t32;
285 unsigned short cmd;
286
287 pci_device_loc(dp,&bus,&dev);
288 pcibios_read_config_dword(bus, dev, PCI_VENDOR_ID, &t32);
289 if(t32 == (PCI_DEVICE_ID_S3_TRIO << 16) + PCI_VENDOR_ID_S3) {
290 pcibios_read_config_dword(bus, dev, PCI_BASE_ADDRESS_0, &t32);
291 pcibios_read_config_dword(bus, dev, PCI_BASE_ADDRESS_1, &t32);
292 pcibios_read_config_word(bus, dev, PCI_COMMAND,&cmd);
293
294 pcibios_write_config_word(bus, dev, PCI_COMMAND, PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
295
296 pcibios_write_config_dword(bus, dev, PCI_BASE_ADDRESS_0,0xffffffff);
297 pcibios_read_config_dword(bus, dev, PCI_BASE_ADDRESS_0, &t32);
298
299/* This is a gross hack as OF only maps enough memory for the framebuffer and
300 we want to use MMIO too. We should find out which chunk of address space
301 we can use here */
302 pcibios_write_config_dword(bus,dev,PCI_BASE_ADDRESS_0,0xc6000000);
303
304 /* unlock s3 */
305
306 outb(0x01, 0x3C3);
307
308 outb(inb(0x03CC) | 1, 0x3c2);
309
310 outw(IO_OUT16VAL(0x48, 0x38),0x03D4);
311 outw(IO_OUT16VAL(0xA0, 0x39),0x03D4);
312 outb(0x33,0x3d4);
313 outw(IO_OUT16VAL((inb(0x3d5) & ~(0x2 | 0x10 | 0x40)) |
314 0x20, 0x33), 0x3d4);
315
316 outw(IO_OUT16VAL(0x6, 0x8), 0x3c4);
317
318 /* switch to MMIO only mode */
319
320 outb(0x58, 0x3d4);
321 outw(IO_OUT16VAL(inb(0x3d5) | 3 | 0x10, 0x58), 0x3d4);
322 outw(IO_OUT16VAL(8, 0x53), 0x3d4);
323
324 /* switch off I/O accesses */
325
326#if 0
327 pcibios_write_config_word(bus, dev, PCI_COMMAND,
328 PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
329#endif
330 return 1;
331 }
332
333 return 0;
334}
335
336
337 /*
338 * Initialisation
339 * We heavily rely on OF for the moment. This needs fixing.
340 */
341
342static void __init s3triofb_of_init(struct device_node *dp)
343{
344 int i, *pp, len;
345 unsigned long address, size;
346 u_long *CursorBase;
347
348 strncat(s3trio_name, dp->name, sizeof(s3trio_name));
349 s3trio_name[sizeof(s3trio_name)-1] = '\0';
350 strcpy(fb_fix.id, s3trio_name);
351
352 if((pp = get_property(dp, "vendor-id", &len)) != NULL
353 && *pp!=PCI_VENDOR_ID_S3) {
354 printk("%s: can't find S3 Trio board\n", dp->full_name);
355 return;
356 }
357
358 if((pp = get_property(dp, "device-id", &len)) != NULL
359 && *pp!=PCI_DEVICE_ID_S3_TRIO) {
360 printk("%s: can't find S3 Trio board\n", dp->full_name);
361 return;
362 }
363
364 if ((pp = get_property(dp, "depth", &len)) != NULL
365 && len == sizeof(int) && *pp != 8) {
366 printk("%s: can't use depth = %d\n", dp->full_name, *pp);
367 return;
368 }
369 if ((pp = get_property(dp, "width", &len)) != NULL
370 && len == sizeof(int))
371 fb_var.xres = fb_var.xres_virtual = *pp;
372 if ((pp = get_property(dp, "height", &len)) != NULL
373 && len == sizeof(int))
374 fb_var.yres = fb_var.yres_virtual = *pp;
375 if ((pp = get_property(dp, "linebytes", &len)) != NULL
376 && len == sizeof(int))
377 fb_fix.line_length = *pp;
378 else
379 fb_fix.line_length = fb_var.xres_virtual;
380 fb_fix.smem_len = fb_fix.line_length*fb_var.yres;
381
382 address = 0xc6000000;
383 size = 64*1024*1024;
384 if (!request_mem_region(address, size, "S3triofb"))
385 return;
386
387 s3trio_init(dp);
388 s3trio_base = ioremap(address, size);
389 fb_fix.smem_start = address;
390 fb_fix.type = FB_TYPE_PACKED_PIXELS;
391 fb_fix.type_aux = 0;
392 fb_fix.accel = FB_ACCEL_S3_TRIO64;
393 fb_fix.mmio_start = address+0x1000000;
394 fb_fix.mmio_len = 0x1000000;
395
396 fb_fix.xpanstep = 1;
397 fb_fix.ypanstep = 1;
398
399 s3trio_resetaccel();
400
401 mem_out8(0x30, s3trio_base+0x1008000 + 0x03D4);
402 mem_out8(0x2d, s3trio_base+0x1008000 + 0x03D4);
403 mem_out8(0x2e, s3trio_base+0x1008000 + 0x03D4);
404
405 mem_out8(0x50, s3trio_base+0x1008000 + 0x03D4);
406
407 /* disable HW cursor */
408
409 mem_out8(0x39, s3trio_base+0x1008000 + 0x03D4);
410 mem_out8(0xa0, s3trio_base+0x1008000 + 0x03D5);
411
412 mem_out8(0x45, s3trio_base+0x1008000 + 0x03D4);
413 mem_out8(0, s3trio_base+0x1008000 + 0x03D5);
414
415 mem_out8(0x4e, s3trio_base+0x1008000 + 0x03D4);
416 mem_out8(0, s3trio_base+0x1008000 + 0x03D5);
417
418 mem_out8(0x4f, s3trio_base+0x1008000 + 0x03D4);
419 mem_out8(0, s3trio_base+0x1008000 + 0x03D5);
420
421 /* init HW cursor */
422
423 CursorBase = (u_long *)(s3trio_base + 2*1024*1024 - 0x400);
424 for (i = 0; i < 8; i++) {
425 *(CursorBase +(i*4)) = 0xffffff00;
426 *(CursorBase+1+(i*4)) = 0xffff0000;
427 *(CursorBase+2+(i*4)) = 0xffff0000;
428 *(CursorBase+3+(i*4)) = 0xffff0000;
429 }
430 for (i = 8; i < 64; i++) {
431 *(CursorBase +(i*4)) = 0xffff0000;
432 *(CursorBase+1+(i*4)) = 0xffff0000;
433 *(CursorBase+2+(i*4)) = 0xffff0000;
434 *(CursorBase+3+(i*4)) = 0xffff0000;
435 }
436
437
438 mem_out8(0x4c, s3trio_base+0x1008000 + 0x03D4);
439 mem_out8(((2*1024 - 1)&0xf00)>>8, s3trio_base+0x1008000 + 0x03D5);
440
441 mem_out8(0x4d, s3trio_base+0x1008000 + 0x03D4);
442 mem_out8((2*1024 - 1) & 0xff, s3trio_base+0x1008000 + 0x03D5);
443
444 mem_out8(0x45, s3trio_base+0x1008000 + 0x03D4);
445 mem_in8(s3trio_base+0x1008000 + 0x03D4);
446
447 mem_out8(0x4a, s3trio_base+0x1008000 + 0x03D4);
448 mem_out8(0x80, s3trio_base+0x1008000 + 0x03D5);
449 mem_out8(0x80, s3trio_base+0x1008000 + 0x03D5);
450 mem_out8(0x80, s3trio_base+0x1008000 + 0x03D5);
451
452 mem_out8(0x4b, s3trio_base+0x1008000 + 0x03D4);
453 mem_out8(0x00, s3trio_base+0x1008000 + 0x03D5);
454 mem_out8(0x00, s3trio_base+0x1008000 + 0x03D5);
455 mem_out8(0x00, s3trio_base+0x1008000 + 0x03D5);
456
457 mem_out8(0x45, s3trio_base+0x1008000 + 0x03D4);
458 mem_out8(0, s3trio_base+0x1008000 + 0x03D5);
459
460 /* setup default color table */
461
462 for(i = 0; i < 16; i++) {
463 int j = color_table[i];
464 palette[i].red=default_red[j];
465 palette[i].green=default_grn[j];
466 palette[i].blue=default_blu[j];
467 }
468
469 s3trio_setcolreg(255, 56, 100, 160, 0, NULL /* not used */);
470 s3trio_setcolreg(254, 0, 0, 0, 0, NULL /* not used */);
471 memset((char *)s3trio_base, 0, 640*480);
472
473#if 0
474 Trio_RectFill(0, 0, 90, 90, 7, 1);
475#endif
476
477 fb_fix.visual = FB_VISUAL_PSEUDOCOLOR ;
478 fb_var.xoffset = fb_var.yoffset = 0;
479 fb_var.bits_per_pixel = 8;
480 fb_var.grayscale = 0;
481 fb_var.red.offset = fb_var.green.offset = fb_var.blue.offset = 0;
482 fb_var.red.length = fb_var.green.length = fb_var.blue.length = 8;
483 fb_var.red.msb_right = fb_var.green.msb_right = fb_var.blue.msb_right = 0;
484 fb_var.transp.offset = fb_var.transp.length = fb_var.transp.msb_right = 0;
485 fb_var.nonstd = 0;
486 fb_var.activate = 0;
487 fb_var.height = fb_var.width = -1;
488 fb_var.accel_flags = FB_ACCELF_TEXT;
489#warning FIXME: always obey fb_var.accel_flags
490 fb_var.pixclock = 1;
491 fb_var.left_margin = fb_var.right_margin = 0;
492 fb_var.upper_margin = fb_var.lower_margin = 0;
493 fb_var.hsync_len = fb_var.vsync_len = 0;
494 fb_var.sync = 0;
495 fb_var.vmode = FB_VMODE_NONINTERLACED;
496
497 disp.var = fb_var;
498 disp.cmap.start = 0;
499 disp.cmap.len = 0;
500 disp.cmap.red = disp.cmap.green = disp.cmap.blue = disp.cmap.transp = NULL;
501 disp.visual = fb_fix.visual;
502 disp.type = fb_fix.type;
503 disp.type_aux = fb_fix.type_aux;
504 disp.ypanstep = 0;
505 disp.ywrapstep = 0;
506 disp.line_length = fb_fix.line_length;
507 disp.can_soft_blank = 1;
508 disp.inverse = 0;
509#ifdef FBCON_HAS_CFB8
510 if (fb_var.accel_flags & FB_ACCELF_TEXT)
511 disp.dispsw = &fbcon_trio8;
512 else
513 disp.dispsw = &fbcon_cfb8;
514#else
515 disp.dispsw = &fbcon_dummy;
516#endif
517 disp.scrollmode = fb_var.accel_flags & FB_ACCELF_TEXT ? 0 : SCROLL_YREDRAW;
518
519 strcpy(fb_info.modename, "Trio64 ");
520 strncat(fb_info.modename, dp->full_name, sizeof(fb_info.modename));
521 fb_info.currcon = -1;
522 fb_info.fbops = &s3trio_ops;
523 fb_info.screen_base = s3trio_base;
524#if 0
525 fb_info.fbvar_num = 1;
526 fb_info.fbvar = &fb_var;
527#endif
528 fb_info.disp = &disp;
529 fb_info.fontname[0] = '\0';
530 fb_info.changevar = NULL;
531 fb_info.switch_con = &s3triofbcon_switch;
532 fb_info.updatevar = &s3triofbcon_updatevar;
533#if 0
534 fb_info.setcmap = &s3triofbcon_setcmap;
535#endif
536
537 fb_info.flags = FBINFO_FLAG_DEFAULT;
538 if (register_framebuffer(&fb_info) < 0) {
539 iounmap(fb_info.screen_base);
540 fb_info.screen_base = NULL;
541 return;
542 }
543
544 printk("fb%d: S3 Trio frame buffer device on %s\n",
545 fb_info.node, dp->full_name);
546}
547
548
549static int s3triofbcon_switch(int con, struct fb_info *info)
550{
551 /* Do we have to save the colormap? */
552 if (fb_display[info->currcon].cmap.len)
553 fb_get_cmap(&fb_display[info->currcon].cmap, 1, s3trio_getcolreg, info);
554
555 info->currcon = con;
556 /* Install new colormap */
557 do_install_cmap(con,info);
558 return 0;
559}
560
561 /*
562 * Update the `var' structure (called by fbcon.c)
563 */
564
565static int s3triofbcon_updatevar(int con, struct fb_info *info)
566{
567 /* Nothing */
568 return 0;
569}
570
571 /*
572 * Blank the display.
573 */
574
575static int s3triofb_blank(int blank, struct fb_info *info)
576{
577 unsigned char x;
578
579 mem_out8(0x1, s3trio_base+0x1008000 + 0x03c4);
580 x = mem_in8(s3trio_base+0x1008000 + 0x03c5);
581 mem_out8((x & (~0x20)) | (blank << 5), s3trio_base+0x1008000 + 0x03c5);
582 return 0;
583}
584
585 /*
586 * Read a single color register and split it into
587 * colors/transparent. Return != 0 for invalid regno.
588 */
589
590static int s3trio_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
591 u_int *transp, struct fb_info *info)
592{
593 if (regno > 255)
594 return 1;
595 *red = (palette[regno].red << 8) | palette[regno].red;
596 *green = (palette[regno].green << 8) | palette[regno].green;
597 *blue = (palette[regno].blue << 8) | palette[regno].blue;
598 *transp = 0;
599 return 0;
600}
601
602
603 /*
604 * Set a single color register. Return != 0 for invalid regno.
605 */
606
607static int s3trio_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
608 u_int transp, struct fb_info *info)
609{
610 if (regno > 255)
611 return 1;
612
613 red >>= 8;
614 green >>= 8;
615 blue >>= 8;
616 palette[regno].red = red;
617 palette[regno].green = green;
618 palette[regno].blue = blue;
619
620 mem_out8(regno,s3trio_base+0x1008000 + 0x3c8);
621 mem_out8((red & 0xff) >> 2,s3trio_base+0x1008000 + 0x3c9);
622 mem_out8((green & 0xff) >> 2,s3trio_base+0x1008000 + 0x3c9);
623 mem_out8((blue & 0xff) >> 2,s3trio_base+0x1008000 + 0x3c9);
624
625 return 0;
626}
627
628static void Trio_WaitQueue(u_short fifo) {
629
630 u_short status;
631
632 do
633 {
634 status = mem_in16(s3trio_base + 0x1000000 + 0x9AE8);
635 } while (!(status & fifo));
636
637}
638
639static void Trio_WaitBlit(void) {
640
641 u_short status;
642
643 do
644 {
645 status = mem_in16(s3trio_base + 0x1000000 + 0x9AE8);
646 } while (status & 0x200);
647
648}
649
650static void Trio_BitBLT(u_short curx, u_short cury, u_short destx,
651 u_short desty, u_short width, u_short height,
652 u_short mode) {
653
654 u_short blitcmd = 0xc011;
655
656 /* Set drawing direction */
657 /* -Y, X maj, -X (default) */
658
659 if (curx > destx)
660 blitcmd |= 0x0020; /* Drawing direction +X */
661 else {
662 curx += (width - 1);
663 destx += (width - 1);
664 }
665
666 if (cury > desty)
667 blitcmd |= 0x0080; /* Drawing direction +Y */
668 else {
669 cury += (height - 1);
670 desty += (height - 1);
671 }
672
673 Trio_WaitQueue(0x0400);
674
675 outw(0xa000, 0xBEE8);
676 outw(0x60 | mode, 0xBAE8);
677
678 outw(curx, 0x86E8);
679 outw(cury, 0x82E8);
680
681 outw(destx, 0x8EE8);
682 outw(desty, 0x8AE8);
683
684 outw(height - 1, 0xBEE8);
685 outw(width - 1, 0x96E8);
686
687 outw(blitcmd, 0x9AE8);
688
689}
690
691static void Trio_RectFill(u_short x, u_short y, u_short width, u_short height,
692 u_short mode, u_short color) {
693
694 u_short blitcmd = 0x40b1;
695
696 Trio_WaitQueue(0x0400);
697
698 outw(0xa000, 0xBEE8);
699 outw((0x20 | mode), 0xBAE8);
700 outw(0xe000, 0xBEE8);
701 outw(color, 0xA6E8);
702 outw(x, 0x86E8);
703 outw(y, 0x82E8);
704 outw((height - 1), 0xBEE8);
705 outw((width - 1), 0x96E8);
706 outw(blitcmd, 0x9AE8);
707
708}
709
710
711static void Trio_MoveCursor(u_short x, u_short y) {
712
713 mem_out8(0x39, s3trio_base + 0x1008000 + 0x3d4);
714 mem_out8(0xa0, s3trio_base + 0x1008000 + 0x3d5);
715
716 mem_out8(0x46, s3trio_base + 0x1008000 + 0x3d4);
717 mem_out8((x & 0x0700) >> 8, s3trio_base + 0x1008000 + 0x3d5);
718 mem_out8(0x47, s3trio_base + 0x1008000 + 0x3d4);
719 mem_out8(x & 0x00ff, s3trio_base + 0x1008000 + 0x3d5);
720
721 mem_out8(0x48, s3trio_base + 0x1008000 + 0x3d4);
722 mem_out8((y & 0x0700) >> 8, s3trio_base + 0x1008000 + 0x3d5);
723 mem_out8(0x49, s3trio_base + 0x1008000 + 0x3d4);
724 mem_out8(y & 0x00ff, s3trio_base + 0x1008000 + 0x3d5);
725
726}
727
728
729 /*
730 * Text console acceleration
731 */
732
733#ifdef FBCON_HAS_CFB8
734static void fbcon_trio8_bmove(struct display *p, int sy, int sx, int dy,
735 int dx, int height, int width)
736{
737 sx *= 8; dx *= 8; width *= 8;
738 Trio_BitBLT((u_short)sx, (u_short)(sy*fontheight(p)), (u_short)dx,
739 (u_short)(dy*fontheight(p)), (u_short)width,
740 (u_short)(height*fontheight(p)), (u_short)S3_NEW);
741}
742
743static void fbcon_trio8_clear(struct vc_data *conp, struct display *p, int sy,
744 int sx, int height, int width)
745{
746 unsigned char bg;
747
748 sx *= 8; width *= 8;
749 bg = attr_bgcol_ec(p,conp);
750 Trio_RectFill((u_short)sx,
751 (u_short)(sy*fontheight(p)),
752 (u_short)width,
753 (u_short)(height*fontheight(p)),
754 (u_short)S3_NEW,
755 (u_short)bg);
756}
757
758static void fbcon_trio8_putc(struct vc_data *conp, struct display *p, int c,
759 int yy, int xx)
760{
761 Trio_WaitBlit();
762 fbcon_cfb8_putc(conp, p, c, yy, xx);
763}
764
765static void fbcon_trio8_putcs(struct vc_data *conp, struct display *p,
766 const unsigned short *s, int count, int yy, int xx)
767{
768 Trio_WaitBlit();
769 fbcon_cfb8_putcs(conp, p, s, count, yy, xx);
770}
771
772static void fbcon_trio8_revc(struct display *p, int xx, int yy)
773{
774 Trio_WaitBlit();
775 fbcon_cfb8_revc(p, xx, yy);
776}
777
778static struct display_switch fbcon_trio8 = {
779 .setup = fbcon_cfb8_setup,
780 .bmove = fbcon_trio8_bmove,
781 .clear = fbcon_trio8_clear,
782 .putc = fbcon_trio8_putc,
783 .putcs = fbcon_trio8_putcs,
784 .revc = fbcon_trio8_revc,
785 .clear_margins = fbcon_cfb8_clear_margins,
786 .fontwidthmask = FONTWIDTH(8)
787};
788#endif
789
790MODULE_LICENSE("GPL");
diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
index f2ebdd88008..301612cef35 100644
--- a/drivers/video/aty/atyfb_base.c
+++ b/drivers/video/aty/atyfb_base.c
@@ -2566,7 +2566,7 @@ static int __devinit aty_init(struct fb_info *info)
2566 info->fix.smem_len == 0x80000 ? 'K' : 'M', ramname, xtal, par->pll_limits.pll_max, 2566 info->fix.smem_len == 0x80000 ? 'K' : 'M', ramname, xtal, par->pll_limits.pll_max,
2567 par->pll_limits.mclk, par->pll_limits.xclk); 2567 par->pll_limits.mclk, par->pll_limits.xclk);
2568 2568
2569#if defined(DEBUG) && defined(CONFIG_ATY_CT) 2569#if defined(DEBUG) && defined(CONFIG_FB_ATY_CT)
2570 if (M64_HAS(INTEGRATED)) { 2570 if (M64_HAS(INTEGRATED)) {
2571 int i; 2571 int i;
2572 printk("debug atyfb: BUS_CNTL DAC_CNTL MEM_CNTL EXT_MEM_CNTL CRTC_GEN_CNTL " 2572 printk("debug atyfb: BUS_CNTL DAC_CNTL MEM_CNTL EXT_MEM_CNTL CRTC_GEN_CNTL "
@@ -2957,8 +2957,6 @@ extern void (*prom_palette) (int);
2957static int __devinit atyfb_setup_sparc(struct pci_dev *pdev, 2957static int __devinit atyfb_setup_sparc(struct pci_dev *pdev,
2958 struct fb_info *info, unsigned long addr) 2958 struct fb_info *info, unsigned long addr)
2959{ 2959{
2960 extern int con_is_present(void);
2961
2962 struct atyfb_par *par = info->par; 2960 struct atyfb_par *par = info->par;
2963 struct pcidev_cookie *pcp; 2961 struct pcidev_cookie *pcp;
2964 char prop[128]; 2962 char prop[128];
diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c
index ef5c16f7f5a..80a81eccad3 100644
--- a/drivers/video/au1100fb.c
+++ b/drivers/video/au1100fb.c
@@ -468,11 +468,10 @@ int au1100fb_drv_probe(struct device *dev)
468 return -EINVAL; 468 return -EINVAL;
469 469
470 /* Allocate new device private */ 470 /* Allocate new device private */
471 if (!(fbdev = kmalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) { 471 if (!(fbdev = kzalloc(sizeof(struct au1100fb_device), GFP_KERNEL))) {
472 print_err("fail to allocate device private record"); 472 print_err("fail to allocate device private record");
473 return -ENOMEM; 473 return -ENOMEM;
474 } 474 }
475 memset((void*)fbdev, 0, sizeof(struct au1100fb_device));
476 475
477 fbdev->panel = &known_lcd_panels[drv_info.panel_idx]; 476 fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
478 477
@@ -549,10 +548,9 @@ int au1100fb_drv_probe(struct device *dev)
549 fbdev->info.fbops = &au1100fb_ops; 548 fbdev->info.fbops = &au1100fb_ops;
550 fbdev->info.fix = au1100fb_fix; 549 fbdev->info.fix = au1100fb_fix;
551 550
552 if (!(fbdev->info.pseudo_palette = kmalloc(sizeof(u32) * 16, GFP_KERNEL))) { 551 if (!(fbdev->info.pseudo_palette = kzalloc(sizeof(u32) * 16, GFP_KERNEL))) {
553 return -ENOMEM; 552 return -ENOMEM;
554 } 553 }
555 memset(fbdev->info.pseudo_palette, 0, sizeof(u32) * 16);
556 554
557 if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) { 555 if (fb_alloc_cmap(&fbdev->info.cmap, AU1100_LCD_NBR_PALETTE_ENTRIES, 0) < 0) {
558 print_err("Fail to allocate colormap (%d entries)", 556 print_err("Fail to allocate colormap (%d entries)",
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 31f476a6479..ce5ac268074 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -2071,7 +2071,7 @@ static int fbcon_resize(struct vc_data *vc, unsigned int width,
2071 y_diff = info->var.yres - var.yres; 2071 y_diff = info->var.yres - var.yres;
2072 if (x_diff < 0 || x_diff > virt_fw || 2072 if (x_diff < 0 || x_diff > virt_fw ||
2073 y_diff < 0 || y_diff > virt_fh) { 2073 y_diff < 0 || y_diff > virt_fh) {
2074 struct fb_videomode *mode; 2074 const struct fb_videomode *mode;
2075 2075
2076 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres); 2076 DPRINTK("attempting resize %ix%i\n", var.xres, var.yres);
2077 mode = fb_find_best_mode(&var, &info->modelist); 2077 mode = fb_find_best_mode(&var, &info->modelist);
@@ -2975,7 +2975,7 @@ static void fbcon_new_modelist(struct fb_info *info)
2975 int i; 2975 int i;
2976 struct vc_data *vc; 2976 struct vc_data *vc;
2977 struct fb_var_screeninfo var; 2977 struct fb_var_screeninfo var;
2978 struct fb_videomode *mode; 2978 const struct fb_videomode *mode;
2979 2979
2980 for (i = first_fb_vc; i <= last_fb_vc; i++) { 2980 for (i = first_fb_vc; i <= last_fb_vc; i++) {
2981 if (registered_fb[con2fb_map[i]] != info) 2981 if (registered_fb[con2fb_map[i]] != info)
diff --git a/drivers/video/console/fbcon.h b/drivers/video/console/fbcon.h
index b9386d168c0..71f24e00fcd 100644
--- a/drivers/video/console/fbcon.h
+++ b/drivers/video/console/fbcon.h
@@ -48,7 +48,7 @@ struct display {
48 struct fb_bitfield green; 48 struct fb_bitfield green;
49 struct fb_bitfield blue; 49 struct fb_bitfield blue;
50 struct fb_bitfield transp; 50 struct fb_bitfield transp;
51 struct fb_videomode *mode; 51 const struct fb_videomode *mode;
52}; 52};
53 53
54struct fbcon_ops { 54struct fbcon_ops {
diff --git a/drivers/video/controlfb.c b/drivers/video/controlfb.c
index 04c6d928189..fd60dba294d 100644
--- a/drivers/video/controlfb.c
+++ b/drivers/video/controlfb.c
@@ -696,11 +696,10 @@ static int __init control_of_init(struct device_node *dp)
696 printk(KERN_ERR "can't get 2 addresses for control\n"); 696 printk(KERN_ERR "can't get 2 addresses for control\n");
697 return -ENXIO; 697 return -ENXIO;
698 } 698 }
699 p = kmalloc(sizeof(*p), GFP_KERNEL); 699 p = kzalloc(sizeof(*p), GFP_KERNEL);
700 if (p == 0) 700 if (p == 0)
701 return -ENXIO; 701 return -ENXIO;
702 control_fb = p; /* save it for cleanups */ 702 control_fb = p; /* save it for cleanups */
703 memset(p, 0, sizeof(*p));
704 703
705 /* Map in frame buffer and registers */ 704 /* Map in frame buffer and registers */
706 p->fb_orig_base = fb_res.start; 705 p->fb_orig_base = fb_res.start;
diff --git a/drivers/video/cyber2000fb.c b/drivers/video/cyber2000fb.c
index aae6d9c26e8..7a6eeda5ae9 100644
--- a/drivers/video/cyber2000fb.c
+++ b/drivers/video/cyber2000fb.c
@@ -1539,16 +1539,21 @@ static int cyberpro_pci_enable_mmio(struct cfb_info *cfb)
1539 /* 1539 /*
1540 * Allow the CyberPro to accept PCI burst accesses 1540 * Allow the CyberPro to accept PCI burst accesses
1541 */ 1541 */
1542 val = cyber2000_grphr(EXT_BUS_CTL, cfb); 1542 if (cfb->id == ID_CYBERPRO_2010) {
1543 if (!(val & EXT_BUS_CTL_PCIBURST_WRITE)) { 1543 printk(KERN_INFO "%s: NOT enabling PCI bursts\n", cfb->fb.fix.id);
1544 printk(KERN_INFO "%s: enabling PCI bursts\n", cfb->fb.fix.id); 1544 } else {
1545 val = cyber2000_grphr(EXT_BUS_CTL, cfb);
1546 if (!(val & EXT_BUS_CTL_PCIBURST_WRITE)) {
1547 printk(KERN_INFO "%s: enabling PCI bursts\n",
1548 cfb->fb.fix.id);
1545 1549
1546 val |= EXT_BUS_CTL_PCIBURST_WRITE; 1550 val |= EXT_BUS_CTL_PCIBURST_WRITE;
1547 1551
1548 if (cfb->id == ID_CYBERPRO_5000) 1552 if (cfb->id == ID_CYBERPRO_5000)
1549 val |= EXT_BUS_CTL_PCIBURST_READ; 1553 val |= EXT_BUS_CTL_PCIBURST_READ;
1550 1554
1551 cyber2000_grphw(EXT_BUS_CTL, val, cfb); 1555 cyber2000_grphw(EXT_BUS_CTL, val, cfb);
1556 }
1552 } 1557 }
1553 1558
1554 return 0; 1559 return 0;
diff --git a/drivers/video/cyberfb.c b/drivers/video/cyberfb.c
deleted file mode 100644
index 0b8d5b12115..00000000000
--- a/drivers/video/cyberfb.c
+++ /dev/null
@@ -1,2295 +0,0 @@
1/*
2* linux/drivers/video/cyberfb.c -- CyberVision64 frame buffer device
3* $Id: cyberfb.c,v 1.6 1998/09/11 04:54:58 abair Exp $
4*
5* Copyright (C) 1998 Alan Bair
6*
7* This file is based on two CyberVision64 frame buffer device drivers
8*
9* The second CyberVision64 frame buffer device (cvision.c cvision_core.c):
10*
11* Copyright (c) 1997 Antonio Santos
12*
13* Released as a patch to 2.1.35, but never included in the source tree.
14* This is based on work from the NetBSD CyberVision64 frame buffer driver
15* and support files (grf_cv.c, grf_cvreg.h, ite_cv.c):
16* Permission to use the source of this driver was obtained from the
17* author Michael Teske by Alan Bair.
18*
19* Copyright (c) 1995 Michael Teske
20*
21* The first CyberVision64 frame buffer device (cyberfb.c):
22*
23* Copyright (C) 1996 Martin Apel
24* Geert Uytterhoeven
25*
26* Which is based on the Amiga frame buffer device (amifb.c):
27*
28* Copyright (C) 1995 Geert Uytterhoeven
29*
30*
31* History:
32* - 22 Dec 95: Original version by Martin Apel
33* - 05 Jan 96: Geert: integration into the current source tree
34* - 01 Aug 98: Alan: Merge in code from cvision.c and cvision_core.c
35* $Log: cyberfb.c,v $
36* Revision 1.6 1998/09/11 04:54:58 abair
37* Update for 2.1.120 change in include file location.
38* Clean up for public release.
39*
40* Revision 1.5 1998/09/03 04:27:13 abair
41* Move cv64_load_video_mode to cyber_set_video so a new video mode is install
42* with each change of the 'var' data.
43*
44* Revision 1.4 1998/09/01 00:31:17 abair
45* Put in a set of default 8,16,24 bpp modes and map cyber8,16 to them.
46* Update operations with 'par' to handle a more complete set of parameter
47* values for encode/decode process.
48*
49* Revision 1.3 1998/08/31 21:31:33 abair
50* Swap 800x490 for 640x480 video mode and more cleanup.
51* Abandon idea to resurrect "custom" mode setting via kernel opts,
52* instead work on making use of fbset program to do this.
53*
54* Revision 1.2 1998/08/31 06:17:08 abair
55* Make updates for changes in cyberfb.c released in 2.1.119
56* and do some cleanup of the code.
57*
58* Revision 1.1 1998/08/29 18:38:31 abair
59* Initial revision
60*
61* Revision 1.3 1998/08/17 06:21:53 abair
62* Remove more redundant code after merging in cvision_core.c
63* Set blanking by colormap to pale red to detect this vs trying to
64* use video blanking. More formating to Linux code style.
65*
66* Revision 1.2 1998/08/15 17:51:37 abair
67* Added cvision_core.c code from 2.1.35 patches.
68* Changed to compile correctly and switch to using initialization
69* code. Added debugging and dropping of duplicate code.
70*
71*
72*
73* This file is subject to the terms and conditions of the GNU General Public
74* License. See the file COPYING in the main directory of this archive
75* for more details.
76*/
77
78
79#include <linux/module.h>
80#include <linux/kernel.h>
81#include <linux/errno.h>
82#include <linux/string.h>
83#include <linux/mm.h>
84#include <linux/slab.h>
85#include <linux/delay.h>
86#include <linux/zorro.h>
87#include <linux/fb.h>
88#include <linux/init.h>
89#include <asm/uaccess.h>
90#include <asm/system.h>
91#include <asm/irq.h>
92#include <asm/pgtable.h>
93#include <asm/amigahw.h>
94#include <asm/io.h>
95
96#include "cyberfb.h"
97#include <video/fbcon.h>
98#include <video/fbcon-cfb8.h>
99#include <video/fbcon-cfb16.h>
100
101/*#define CYBERFBDEBUG*/
102#ifdef CYBERFBDEBUG
103#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
104static void cv64_dump(void);
105#else
106#define DPRINTK(fmt, args...)
107#endif
108
109#define wb_64(regs,reg,dat) (*(((volatile unsigned char *)regs) + reg) = dat)
110#define rb_64(regs, reg) (*(((volatile unsigned char *)regs) + reg))
111
112struct cyberfb_par {
113 struct fb_var_screeninfo var;
114 __u32 type;
115 __u32 type_aux;
116 __u32 visual;
117 __u32 line_length;
118};
119
120static struct cyberfb_par current_par;
121
122static int current_par_valid = 0;
123
124static struct display disp;
125static struct fb_info fb_info;
126
127
128/*
129 * Frame Buffer Name
130 */
131
132static char cyberfb_name[16] = "Cybervision";
133
134
135/*
136 * CyberVision Graphics Board
137 */
138
139static unsigned char Cyber_colour_table [256][3];
140static unsigned long CyberSize;
141static volatile unsigned char *CyberBase;
142static volatile unsigned char *CyberMem;
143static volatile unsigned char *CyberRegs;
144static unsigned long CyberMem_phys;
145static unsigned long CyberRegs_phys;
146
147/*
148 * Predefined Video Modes
149 */
150
151static struct {
152 const char *name;
153 struct fb_var_screeninfo var;
154} cyberfb_predefined[] __initdata = {
155 { "640x480-8", { /* Default 8 BPP mode (cyber8) */
156 640, 480, 640, 480, 0, 0, 8, 0,
157 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
158 0, 0, -1, -1, FB_ACCELF_TEXT, 39722, 40, 24, 32, 11, 96, 2,
159 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
160 FB_VMODE_NONINTERLACED
161 }},
162 { "640x480-16", { /* Default 16 BPP mode (cyber16) */
163 640, 480, 640, 480, 0, 0, 16, 0,
164 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
165 0, 0, -1, -1, FB_ACCELF_TEXT, 39722, 40, 24, 32, 11, 96, 2,
166 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
167 FB_VMODE_NONINTERLACED
168 }},
169 { "640x480-24", { /* Default 24 BPP mode */
170 640, 480, 640, 480, 0, 0, 24, 0,
171 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0},
172 0, 0, -1, -1, FB_ACCELF_TEXT, 39722, 40, 24, 32, 11, 96, 2,
173 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
174 FB_VMODE_NONINTERLACED
175 }},
176 { "800x490-8", { /* Cybervision 8 bpp */
177 /* NO Acceleration */
178 800, 490, 800, 490, 0, 0, 8, 0,
179 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
180 0, 0, -1, -1, FB_ACCEL_NONE, 33333, 80, 24, 23, 1, 56, 8,
181 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
182 FB_VMODE_NONINTERLACED
183 }},
184/* I can't test these with my monitor, but I suspect they will
185 * be OK, since Antonio Santos indicated he had tested them in
186 * his system.
187 */
188 { "800x600-8", { /* Cybervision 8 bpp */
189 800, 600, 800, 600, 0, 0, 8, 0,
190 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
191 0, 0, -1, -1, FB_ACCELF_TEXT, 27778, 64, 24, 22, 1, 72, 2,
192 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
193 FB_VMODE_NONINTERLACED
194 }},
195 { "1024x768-8", { /* Cybervision 8 bpp */
196 1024, 768, 1024, 768, 0, 0, 8, 0,
197 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
198 0, 0, -1, -1, FB_ACCELF_TEXT, 16667, 224, 72, 60, 12, 168, 4,
199 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
200 FB_VMODE_NONINTERLACED
201 }},
202 { "1152x886-8", { /* Cybervision 8 bpp */
203 1152, 886, 1152, 886, 0, 0, 8, 0,
204 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
205 0, 0, -1, -1, FB_ACCELF_TEXT, 15873, 184, 40, 24, 1, 56, 16,
206 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
207 FB_VMODE_NONINTERLACED
208 }},
209 { "1280x1024-8", { /* Cybervision 8 bpp */
210 1280, 1024, 1280, 1024, 0, 0, 8, 0,
211 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
212 0, 0, -1, -1, FB_ACCELF_TEXT, 16667, 256, 48, 50, 12, 72, 4,
213 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT,
214 FB_VMODE_INTERLACED
215 }}
216};
217
218#define NUM_TOTAL_MODES ARRAY_SIZE(cyberfb_predefined)
219
220static int Cyberfb_inverse = 0;
221
222/*
223 * Some default modes
224 */
225
226#define CYBER8_DEFMODE (0)
227#define CYBER16_DEFMODE (1)
228
229static struct fb_var_screeninfo cyberfb_default;
230static int cyberfb_usermode __initdata = 0;
231
232/*
233 * Interface used by the world
234 */
235
236int cyberfb_setup(char *options);
237
238static int cyberfb_get_fix(struct fb_fix_screeninfo *fix, int con,
239 struct fb_info *info);
240static int cyberfb_get_var(struct fb_var_screeninfo *var, int con,
241 struct fb_info *info);
242static int cyberfb_set_var(struct fb_var_screeninfo *var, int con,
243 struct fb_info *info);
244static int cyberfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
245 struct fb_info *info);
246static int cyberfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
247 u_int transp, struct fb_info *info);
248static int cyberfb_blank(int blank, struct fb_info *info);
249
250/*
251 * Interface to the low level console driver
252 */
253
254int cyberfb_init(void);
255static int Cyberfb_switch(int con, struct fb_info *info);
256static int Cyberfb_updatevar(int con, struct fb_info *info);
257
258/*
259 * Text console acceleration
260 */
261
262#ifdef FBCON_HAS_CFB8
263static struct display_switch fbcon_cyber8;
264#endif
265
266/*
267 * Accelerated Functions used by the low level console driver
268 */
269
270static void Cyber_WaitQueue(u_short fifo);
271static void Cyber_WaitBlit(void);
272static void Cyber_BitBLT(u_short curx, u_short cury, u_short destx,
273 u_short desty, u_short width, u_short height,
274 u_short mode);
275static void Cyber_RectFill(u_short x, u_short y, u_short width, u_short height,
276 u_short mode, u_short color);
277#if 0
278static void Cyber_MoveCursor(u_short x, u_short y);
279#endif
280
281/*
282 * Hardware Specific Routines
283 */
284
285static int Cyber_init(void);
286static int Cyber_encode_fix(struct fb_fix_screeninfo *fix,
287 struct cyberfb_par *par);
288static int Cyber_decode_var(struct fb_var_screeninfo *var,
289 struct cyberfb_par *par);
290static int Cyber_encode_var(struct fb_var_screeninfo *var,
291 struct cyberfb_par *par);
292static int Cyber_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
293 u_int *transp, struct fb_info *info);
294
295/*
296 * Internal routines
297 */
298
299static void cyberfb_get_par(struct cyberfb_par *par);
300static void cyberfb_set_par(struct cyberfb_par *par);
301static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive);
302static void cyberfb_set_disp(int con, struct fb_info *info);
303static int get_video_mode(const char *name);
304
305/* For cvision_core.c */
306static unsigned short cv64_compute_clock(unsigned long);
307static int cv_has_4mb (volatile unsigned char *);
308static void cv64_board_init (void);
309static void cv64_load_video_mode (struct fb_var_screeninfo *);
310
311
312/* -------------------- Hardware specific routines ------------------------- */
313
314
315/*
316 * Initialization
317 *
318 * Set the default video mode for this chipset. If a video mode was
319 * specified on the command line, it will override the default mode.
320 */
321
322static int Cyber_init(void)
323{
324 volatile unsigned char *regs = CyberRegs;
325 volatile unsigned long *CursorBase;
326 int i;
327 DPRINTK("ENTER\n");
328
329/* Init local cmap as greyscale levels */
330 for (i = 0; i < 256; i++) {
331 Cyber_colour_table [i][0] = i;
332 Cyber_colour_table [i][1] = i;
333 Cyber_colour_table [i][2] = i;
334 }
335
336/* Initialize the board and determine fbmem size */
337 cv64_board_init();
338#ifdef CYBERFBDEBUG
339 DPRINTK("Register state after initing board\n");
340 cv64_dump();
341#endif
342/* Clear framebuffer memory */
343 DPRINTK("Clear framebuffer memory\n");
344 memset ((char *)CyberMem, 0, CyberSize);
345
346/* Disable hardware cursor */
347 DPRINTK("Disable HW cursor\n");
348 wb_64(regs, S3_CRTC_ADR, S3_REG_LOCK2);
349 wb_64(regs, S3_CRTC_DATA, 0xa0);
350 wb_64(regs, S3_CRTC_ADR, S3_HGC_MODE);
351 wb_64(regs, S3_CRTC_DATA, 0x00);
352 wb_64(regs, S3_CRTC_ADR, S3_HWGC_DX);
353 wb_64(regs, S3_CRTC_DATA, 0x00);
354 wb_64(regs, S3_CRTC_ADR, S3_HWGC_DY);
355 wb_64(regs, S3_CRTC_DATA, 0x00);
356
357/* Initialize hardware cursor */
358 DPRINTK("Init HW cursor\n");
359 CursorBase = (u_long *)((char *)(CyberMem) + CyberSize - 0x400);
360 for (i=0; i < 8; i++)
361 {
362 *(CursorBase +(i*4)) = 0xffffff00;
363 *(CursorBase+1+(i*4)) = 0xffff0000;
364 *(CursorBase+2+(i*4)) = 0xffff0000;
365 *(CursorBase+3+(i*4)) = 0xffff0000;
366 }
367 for (i=8; i < 64; i++)
368 {
369 *(CursorBase +(i*4)) = 0xffff0000;
370 *(CursorBase+1+(i*4)) = 0xffff0000;
371 *(CursorBase+2+(i*4)) = 0xffff0000;
372 *(CursorBase+3+(i*4)) = 0xffff0000;
373 }
374
375 cyberfb_setcolreg (255, 56<<8, 100<<8, 160<<8, 0, NULL /* unused */);
376 cyberfb_setcolreg (254, 0, 0, 0, 0, NULL /* unused */);
377
378 DPRINTK("EXIT\n");
379 return 0;
380}
381
382
383/*
384 * This function should fill in the `fix' structure based on the
385 * values in the `par' structure.
386 */
387
388static int Cyber_encode_fix(struct fb_fix_screeninfo *fix,
389 struct cyberfb_par *par)
390{
391 DPRINTK("ENTER\n");
392 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
393 strcpy(fix->id, cyberfb_name);
394 fix->smem_start = CyberMem_phys;
395 fix->smem_len = CyberSize;
396 fix->mmio_start = CyberRegs_phys;
397 fix->mmio_len = 0x10000;
398
399 fix->type = FB_TYPE_PACKED_PIXELS;
400 fix->type_aux = 0;
401 if (par->var.bits_per_pixel == 15 || par->var.bits_per_pixel == 16 ||
402 par->var.bits_per_pixel == 24 || par->var.bits_per_pixel == 32) {
403 fix->visual = FB_VISUAL_DIRECTCOLOR;
404 } else {
405 fix->visual = FB_VISUAL_PSEUDOCOLOR;
406 }
407
408 fix->xpanstep = 0;
409 fix->ypanstep = 0;
410 fix->ywrapstep = 0;
411 fix->line_length = 0;
412 fix->accel = FB_ACCEL_S3_TRIO64;
413
414 DPRINTK("EXIT\n");
415 return(0);
416}
417
418
419/*
420* Fill the `par' structure based on the values in `var'.
421* TODO: Verify and adjust values, return -EINVAL if bad.
422*/
423
424static int Cyber_decode_var(struct fb_var_screeninfo *var,
425 struct cyberfb_par *par)
426{
427 DPRINTK("ENTER\n");
428 par->var.xres = var->xres;
429 par->var.yres = var->yres;
430 par->var.xres_virtual = var->xres_virtual;
431 par->var.yres_virtual = var->yres_virtual;
432 par->var.xoffset = var->xoffset;
433 par->var.yoffset = var->yoffset;
434 par->var.bits_per_pixel = var->bits_per_pixel;
435 par->var.grayscale = var->grayscale;
436 par->var.red = var->red;
437 par->var.green = var->green;
438 par->var.blue = var->blue;
439 par->var.transp = var->transp;
440 par->var.nonstd = var->nonstd;
441 par->var.activate = var->activate;
442 par->var.height = var->height;
443 par->var.width = var->width;
444 if (var->accel_flags & FB_ACCELF_TEXT) {
445 par->var.accel_flags = FB_ACCELF_TEXT;
446 } else {
447 par->var.accel_flags = 0;
448 }
449 par->var.pixclock = var->pixclock;
450 par->var.left_margin = var->left_margin;
451 par->var.right_margin = var->right_margin;
452 par->var.upper_margin = var->upper_margin;
453 par->var.lower_margin = var->lower_margin;
454 par->var.hsync_len = var->hsync_len;
455 par->var.vsync_len = var->vsync_len;
456 par->var.sync = var->sync;
457 par->var.vmode = var->vmode;
458 DPRINTK("EXIT\n");
459 return(0);
460}
461
462/*
463* Fill the `var' structure based on the values in `par' and maybe
464* other values read out of the hardware.
465*/
466
467static int Cyber_encode_var(struct fb_var_screeninfo *var,
468 struct cyberfb_par *par)
469{
470 DPRINTK("ENTER\n");
471 var->xres = par->var.xres;
472 var->yres = par->var.yres;
473 var->xres_virtual = par->var.xres_virtual;
474 var->yres_virtual = par->var.yres_virtual;
475 var->xoffset = par->var.xoffset;
476 var->yoffset = par->var.yoffset;
477
478 var->bits_per_pixel = par->var.bits_per_pixel;
479 var->grayscale = par->var.grayscale;
480
481 var->red = par->var.red;
482 var->green = par->var.green;
483 var->blue = par->var.blue;
484 var->transp = par->var.transp;
485
486 var->nonstd = par->var.nonstd;
487 var->activate = par->var.activate;
488
489 var->height = par->var.height;
490 var->width = par->var.width;
491
492 var->accel_flags = par->var.accel_flags;
493
494 var->pixclock = par->var.pixclock;
495 var->left_margin = par->var.left_margin;
496 var->right_margin = par->var.right_margin;
497 var->upper_margin = par->var.upper_margin;
498 var->lower_margin = par->var.lower_margin;
499 var->hsync_len = par->var.hsync_len;
500 var->vsync_len = par->var.vsync_len;
501 var->sync = par->var.sync;
502 var->vmode = par->var.vmode;
503
504 DPRINTK("EXIT\n");
505 return(0);
506}
507
508
509/*
510 * Set a single color register. Return != 0 for invalid regno.
511 */
512
513static int cyberfb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
514 u_int transp, struct fb_info *info)
515{
516 volatile unsigned char *regs = CyberRegs;
517
518 /*DPRINTK("ENTER\n");*/
519 if (regno > 255) {
520 DPRINTK("EXIT - Register # > 255\n");
521 return (1);
522 }
523
524 wb_64(regs, 0x3c8, (unsigned char) regno);
525
526 red >>= 10;
527 green >>= 10;
528 blue >>= 10;
529
530 Cyber_colour_table [regno][0] = red;
531 Cyber_colour_table [regno][1] = green;
532 Cyber_colour_table [regno][2] = blue;
533
534 wb_64(regs, 0x3c9, red);
535 wb_64(regs, 0x3c9, green);
536 wb_64(regs, 0x3c9, blue);
537
538 /*DPRINTK("EXIT\n");*/
539 return (0);
540}
541
542
543/*
544* Read a single color register and split it into
545* colors/transparent. Return != 0 for invalid regno.
546*/
547
548static int Cyber_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
549 u_int *transp, struct fb_info *info)
550{
551 int t;
552
553 /*DPRINTK("ENTER\n");*/
554 if (regno > 255) {
555 DPRINTK("EXIT - Register # > 255\n");
556 return (1);
557 }
558 /* ARB This shifting & oring seems VERY strange */
559 t = Cyber_colour_table [regno][0];
560 *red = (t<<10) | (t<<4) | (t>>2);
561 t = Cyber_colour_table [regno][1];
562 *green = (t<<10) | (t<<4) | (t>>2);
563 t = Cyber_colour_table [regno][2];
564 *blue = (t<<10) | (t<<4) | (t>>2);
565 *transp = 0;
566 /*DPRINTK("EXIT\n");*/
567 return (0);
568}
569
570
571/*
572* (Un)Blank the screen
573* blank: 1 = zero fb cmap
574* 0 = restore fb cmap from local cmap
575*/
576static int cyberfb_blank(int blank, struct fb_info *info)
577{
578 volatile unsigned char *regs = CyberRegs;
579 int i;
580
581 DPRINTK("ENTER\n");
582#if 0
583/* Blank by turning gfx off */
584 gfx_on_off (1, regs);
585#else
586 if (blank) {
587 for (i = 0; i < 256; i++) {
588 wb_64(regs, 0x3c8, (unsigned char) i);
589 /* ARB Pale red to detect this blanking method */
590 wb_64(regs, 0x3c9, 48);
591 wb_64(regs, 0x3c9, 0);
592 wb_64(regs, 0x3c9, 0);
593 }
594 } else {
595 for (i = 0; i < 256; i++) {
596 wb_64(regs, 0x3c8, (unsigned char) i);
597 wb_64(regs, 0x3c9, Cyber_colour_table[i][0]);
598 wb_64(regs, 0x3c9, Cyber_colour_table[i][1]);
599 wb_64(regs, 0x3c9, Cyber_colour_table[i][2]);
600 }
601 }
602#endif
603 DPRINTK("EXIT\n");
604 return 0;
605}
606
607
608/**************************************************************
609 * We are waiting for "fifo" FIFO-slots empty
610 */
611static void Cyber_WaitQueue (u_short fifo)
612{
613 unsigned short status;
614
615 DPRINTK("ENTER\n");
616 do {
617 status = *((u_short volatile *)(CyberRegs + S3_GP_STAT));
618 } while (status & fifo);
619 DPRINTK("EXIT\n");
620}
621
622/**************************************************************
623 * We are waiting for Hardware (Graphics Engine) not busy
624 */
625static void Cyber_WaitBlit (void)
626{
627 unsigned short status;
628
629 DPRINTK("ENTER\n");
630 do {
631 status = *((u_short volatile *)(CyberRegs + S3_GP_STAT));
632 } while (status & S3_HDW_BUSY);
633 DPRINTK("EXIT\n");
634}
635
636/**************************************************************
637 * BitBLT - Through the Plane
638 */
639static void Cyber_BitBLT (u_short curx, u_short cury, u_short destx,
640 u_short desty, u_short width, u_short height,
641 u_short mode)
642{
643 volatile unsigned char *regs = CyberRegs;
644 u_short blitcmd = S3_BITBLT;
645
646 DPRINTK("ENTER\n");
647 /* Set drawing direction */
648 /* -Y, X maj, -X (default) */
649 if (curx > destx) {
650 blitcmd |= 0x0020; /* Drawing direction +X */
651 } else {
652 curx += (width - 1);
653 destx += (width - 1);
654 }
655
656 if (cury > desty) {
657 blitcmd |= 0x0080; /* Drawing direction +Y */
658 } else {
659 cury += (height - 1);
660 desty += (height - 1);
661 }
662
663 Cyber_WaitQueue (0x8000);
664
665 *((u_short volatile *)(regs + S3_PIXEL_CNTL)) = 0xa000;
666 *((u_short volatile *)(regs + S3_FRGD_MIX)) = (0x0060 | mode);
667
668 *((u_short volatile *)(regs + S3_CUR_X)) = curx;
669 *((u_short volatile *)(regs + S3_CUR_Y)) = cury;
670
671 *((u_short volatile *)(regs + S3_DESTX_DIASTP)) = destx;
672 *((u_short volatile *)(regs + S3_DESTY_AXSTP)) = desty;
673
674 *((u_short volatile *)(regs + S3_MIN_AXIS_PCNT)) = height - 1;
675 *((u_short volatile *)(regs + S3_MAJ_AXIS_PCNT)) = width - 1;
676
677 *((u_short volatile *)(regs + S3_CMD)) = blitcmd;
678 DPRINTK("EXIT\n");
679}
680
681/**************************************************************
682 * Rectangle Fill Solid
683 */
684static void Cyber_RectFill (u_short x, u_short y, u_short width,
685 u_short height, u_short mode, u_short color)
686{
687 volatile unsigned char *regs = CyberRegs;
688 u_short blitcmd = S3_FILLEDRECT;
689
690 DPRINTK("ENTER\n");
691 Cyber_WaitQueue (0x8000);
692
693 *((u_short volatile *)(regs + S3_PIXEL_CNTL)) = 0xa000;
694 *((u_short volatile *)(regs + S3_FRGD_MIX)) = (0x0020 | mode);
695
696 *((u_short volatile *)(regs + S3_MULT_MISC)) = 0xe000;
697 *((u_short volatile *)(regs + S3_FRGD_COLOR)) = color;
698
699 *((u_short volatile *)(regs + S3_CUR_X)) = x;
700 *((u_short volatile *)(regs + S3_CUR_Y)) = y;
701
702 *((u_short volatile *)(regs + S3_MIN_AXIS_PCNT)) = height - 1;
703 *((u_short volatile *)(regs + S3_MAJ_AXIS_PCNT)) = width - 1;
704
705 *((u_short volatile *)(regs + S3_CMD)) = blitcmd;
706 DPRINTK("EXIT\n");
707}
708
709
710#if 0
711/**************************************************************
712 * Move cursor to x, y
713 */
714static void Cyber_MoveCursor (u_short x, u_short y)
715{
716 volatile unsigned char *regs = CyberRegs;
717 DPRINTK("ENTER\n");
718 *(regs + S3_CRTC_ADR) = 0x39;
719 *(regs + S3_CRTC_DATA) = 0xa0;
720
721 *(regs + S3_CRTC_ADR) = S3_HWGC_ORGX_H;
722 *(regs + S3_CRTC_DATA) = (char)((x & 0x0700) >> 8);
723 *(regs + S3_CRTC_ADR) = S3_HWGC_ORGX_L;
724 *(regs + S3_CRTC_DATA) = (char)(x & 0x00ff);
725
726 *(regs + S3_CRTC_ADR) = S3_HWGC_ORGY_H;
727 *(regs + S3_CRTC_DATA) = (char)((y & 0x0700) >> 8);
728 *(regs + S3_CRTC_ADR) = S3_HWGC_ORGY_L;
729 *(regs + S3_CRTC_DATA) = (char)(y & 0x00ff);
730 DPRINTK("EXIT\n");
731}
732#endif
733
734
735/* -------------------- Generic routines ---------------------------------- */
736
737
738/*
739 * Fill the hardware's `par' structure.
740 */
741
742static void cyberfb_get_par(struct cyberfb_par *par)
743{
744 DPRINTK("ENTER\n");
745 if (current_par_valid) {
746 *par = current_par;
747 } else {
748 Cyber_decode_var(&cyberfb_default, par);
749 }
750 DPRINTK("EXIT\n");
751}
752
753
754static void cyberfb_set_par(struct cyberfb_par *par)
755{
756 DPRINTK("ENTER\n");
757 current_par = *par;
758 current_par_valid = 1;
759 DPRINTK("EXIT\n");
760}
761
762
763static void cyber_set_video(struct fb_var_screeninfo *var)
764{
765
766 /* Load the video mode defined by the 'var' data */
767 cv64_load_video_mode (var);
768#ifdef CYBERFBDEBUG
769 DPRINTK("Register state after loading video mode\n");
770 cv64_dump();
771#endif
772}
773
774
775static int do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
776{
777 int err, activate;
778 struct cyberfb_par par;
779
780 DPRINTK("ENTER\n");
781 if ((err = Cyber_decode_var(var, &par))) {
782 DPRINTK("EXIT - decode_var failed\n");
783 return(err);
784 }
785 activate = var->activate;
786 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW && isactive)
787 cyberfb_set_par(&par);
788 Cyber_encode_var(var, &par);
789 var->activate = activate;
790
791 cyber_set_video(var);
792 DPRINTK("EXIT\n");
793 return 0;
794}
795
796/*
797 * Get the Fixed Part of the Display
798 */
799
800static int cyberfb_get_fix(struct fb_fix_screeninfo *fix, int con,
801 struct fb_info *info)
802{
803 struct cyberfb_par par;
804 int error = 0;
805
806 DPRINTK("ENTER\n");
807 if (con == -1) {
808 cyberfb_get_par(&par);
809 } else {
810 error = Cyber_decode_var(&fb_display[con].var, &par);
811 }
812 DPRINTK("EXIT\n");
813 return(error ? error : Cyber_encode_fix(fix, &par));
814}
815
816
817/*
818 * Get the User Defined Part of the Display
819 */
820
821static int cyberfb_get_var(struct fb_var_screeninfo *var, int con,
822 struct fb_info *info)
823{
824 struct cyberfb_par par;
825 int error = 0;
826
827 DPRINTK("ENTER\n");
828 if (con == -1) {
829 cyberfb_get_par(&par);
830 error = Cyber_encode_var(var, &par);
831 disp.var = *var; /* ++Andre: don't know if this is the right place */
832 } else {
833 *var = fb_display[con].var;
834 }
835
836 DPRINTK("EXIT\n");
837 return(error);
838}
839
840
841static void cyberfb_set_disp(int con, struct fb_info *info)
842{
843 struct fb_fix_screeninfo fix;
844 struct display *display;
845
846 DPRINTK("ENTER\n");
847 if (con >= 0)
848 display = &fb_display[con];
849 else
850 display = &disp; /* used during initialization */
851
852 cyberfb_get_fix(&fix, con, info);
853 if (con == -1)
854 con = 0;
855 display->visual = fix.visual;
856 display->type = fix.type;
857 display->type_aux = fix.type_aux;
858 display->ypanstep = fix.ypanstep;
859 display->ywrapstep = fix.ywrapstep;
860 display->can_soft_blank = 1;
861 display->inverse = Cyberfb_inverse;
862 switch (display->var.bits_per_pixel) {
863#ifdef FBCON_HAS_CFB8
864 case 8:
865 if (display->var.accel_flags & FB_ACCELF_TEXT) {
866 display->dispsw = &fbcon_cyber8;
867#warning FIXME: We should reinit the graphics engine here
868 } else
869 display->dispsw = &fbcon_cfb8;
870 break;
871#endif
872#ifdef FBCON_HAS_CFB16
873 case 16:
874 display->dispsw = &fbcon_cfb16;
875 break;
876#endif
877 default:
878 display->dispsw = NULL;
879 break;
880 }
881 DPRINTK("EXIT\n");
882}
883
884
885/*
886 * Set the User Defined Part of the Display
887 */
888
889static int cyberfb_set_var(struct fb_var_screeninfo *var, int con,
890 struct fb_info *info)
891{
892 int err, oldxres, oldyres, oldvxres, oldvyres, oldbpp, oldaccel;
893
894 DPRINTK("ENTER\n");
895 if ((err = do_fb_set_var(var, con == info->currcon))) {
896 DPRINTK("EXIT - do_fb_set_var failed\n");
897 return(err);
898 }
899 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
900 oldxres = fb_display[con].var.xres;
901 oldyres = fb_display[con].var.yres;
902 oldvxres = fb_display[con].var.xres_virtual;
903 oldvyres = fb_display[con].var.yres_virtual;
904 oldbpp = fb_display[con].var.bits_per_pixel;
905 oldaccel = fb_display[con].var.accel_flags;
906 fb_display[con].var = *var;
907 if (oldxres != var->xres || oldyres != var->yres ||
908 oldvxres != var->xres_virtual ||
909 oldvyres != var->yres_virtual ||
910 oldbpp != var->bits_per_pixel ||
911 oldaccel != var->accel_flags) {
912 cyberfb_set_disp(con, info);
913 (*fb_info.changevar)(con);
914 fb_alloc_cmap(&fb_display[con].cmap, 0, 0);
915 do_install_cmap(con, info);
916 }
917 }
918 var->activate = 0;
919 DPRINTK("EXIT\n");
920 return(0);
921}
922
923
924/*
925 * Get the Colormap
926 */
927
928static int cyberfb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
929 struct fb_info *info)
930{
931 DPRINTK("ENTER\n");
932 if (con == info->currcon) { /* current console? */
933 DPRINTK("EXIT - console is current console\n");
934 return(fb_get_cmap(cmap, kspc, Cyber_getcolreg, info));
935 } else if (fb_display[con].cmap.len) { /* non default colormap? */
936 DPRINTK("Use console cmap\n");
937 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
938 } else {
939 DPRINTK("Use default cmap\n");
940 fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
941 cmap, kspc ? 0 : 2);
942 }
943 DPRINTK("EXIT\n");
944 return(0);
945}
946
947static struct fb_ops cyberfb_ops = {
948 .owner = THIS_MODULE,
949 .fb_get_fix = cyberfb_get_fix,
950 .fb_get_var = cyberfb_get_var,
951 .fb_set_var = cyberfb_set_var,
952 .fb_get_cmap = cyberfb_get_cmap,
953 .fb_set_cmap = gen_set_cmap,
954 .fb_setcolreg = cyberfb_setcolreg,
955 .fb_blank = cyberfb_blank,
956};
957
958int __init cyberfb_setup(char *options)
959{
960 char *this_opt;
961 DPRINTK("ENTER\n");
962
963 fb_info.fontname[0] = '\0';
964
965 if (!options || !*options) {
966 DPRINTK("EXIT - no options\n");
967 return 0;
968 }
969
970 while ((this_opt = strsep(&options, ",")) != NULL) {
971 if (!*this_opt)
972 continue;
973 if (!strcmp(this_opt, "inverse")) {
974 Cyberfb_inverse = 1;
975 fb_invert_cmaps();
976 } else if (!strncmp(this_opt, "font:", 5)) {
977 strcpy(fb_info.fontname, this_opt+5);
978 } else if (!strcmp (this_opt, "cyber8")) {
979 cyberfb_default = cyberfb_predefined[CYBER8_DEFMODE].var;
980 cyberfb_usermode = 1;
981 } else if (!strcmp (this_opt, "cyber16")) {
982 cyberfb_default = cyberfb_predefined[CYBER16_DEFMODE].var;
983 cyberfb_usermode = 1;
984 } else get_video_mode(this_opt);
985 }
986
987 DPRINTK("default mode: xres=%d, yres=%d, bpp=%d\n",
988 cyberfb_default.xres,
989 cyberfb_default.yres,
990 cyberfb_default.bits_per_pixel);
991 DPRINTK("EXIT\n");
992 return 0;
993}
994
995/*
996 * Initialization
997 */
998
999int __init cyberfb_init(void)
1000{
1001 unsigned long board_addr, board_size;
1002 struct cyberfb_par par;
1003 struct zorro_dev *z = NULL;
1004 DPRINTK("ENTER\n");
1005
1006 while ((z = zorro_find_device(ZORRO_PROD_PHASE5_CYBERVISION64, z))) {
1007 board_addr = z->resource.start;
1008 board_size = z->resource.end-z->resource.start+1;
1009 CyberMem_phys = board_addr + 0x01400000;
1010 CyberRegs_phys = CyberMem_phys + 0x00c00000;
1011 if (!request_mem_region(CyberRegs_phys, 0x10000, "S3 Trio64"))
1012 continue;
1013 if (!request_mem_region(CyberMem_phys, 0x400000, "RAM")) {
1014 release_mem_region(CyberRegs_phys, 0x10000);
1015 continue;
1016 }
1017 DPRINTK("board_addr=%08lx\n", board_addr);
1018 DPRINTK("board_size=%08lx\n", board_size);
1019
1020 CyberBase = ioremap(board_addr, board_size);
1021 CyberRegs = CyberBase + 0x02000000;
1022 CyberMem = CyberBase + 0x01400000;
1023 DPRINTK("CyberBase=%08lx CyberRegs=%08lx CyberMem=%08lx\n",
1024 CyberBase, (long unsigned int)CyberRegs, CyberMem);
1025
1026#ifdef CYBERFBDEBUG
1027 DPRINTK("Register state just after mapping memory\n");
1028 cv64_dump();
1029#endif
1030
1031 strcpy(fb_info.modename, cyberfb_name);
1032 fb_info.changevar = NULL;
1033 fb_info.fbops = &cyberfb_ops;
1034 fb_info.screen_base = (unsigned char *)CyberMem;
1035 fb_info.disp = &disp;
1036 fb_info.currcon = -1;
1037 fb_info.switch_con = &Cyberfb_switch;
1038 fb_info.updatevar = &Cyberfb_updatevar;
1039
1040 Cyber_init();
1041 /* ++Andre: set cyberfb default mode */
1042 if (!cyberfb_usermode) {
1043 cyberfb_default = cyberfb_predefined[CYBER8_DEFMODE].var;
1044 DPRINTK("Use default cyber8 mode\n");
1045 }
1046 Cyber_decode_var(&cyberfb_default, &par);
1047 Cyber_encode_var(&cyberfb_default, &par);
1048
1049 do_fb_set_var(&cyberfb_default, 1);
1050 cyberfb_get_var(&fb_display[0].var, -1, &fb_info);
1051 cyberfb_set_disp(-1, &fb_info);
1052 do_install_cmap(0, &fb_info);
1053
1054 if (register_framebuffer(&fb_info) < 0) {
1055 DPRINTK("EXIT - register_framebuffer failed\n");
1056 if (CyberBase)
1057 iounmap(CyberBase);
1058 release_mem_region(CyberMem_phys, 0x400000);
1059 release_mem_region(CyberRegs_phys, 0x10000);
1060 return -EINVAL;
1061 }
1062
1063 printk("fb%d: %s frame buffer device, using %ldK of video memory\n",
1064 fb_info.node, fb_info.modename, CyberSize>>10);
1065
1066 /* TODO: This driver cannot be unloaded yet */
1067 DPRINTK("EXIT\n");
1068 return 0;
1069 }
1070 return -ENXIO;
1071}
1072
1073
1074static int Cyberfb_switch(int con, struct fb_info *info)
1075{
1076 DPRINTK("ENTER\n");
1077 /* Do we have to save the colormap? */
1078 if (fb_display[info->currcon].cmap.len) {
1079 fb_get_cmap(&fb_display[info->currcon].cmap, 1, Cyber_getcolreg,
1080 info);
1081 }
1082
1083 do_fb_set_var(&fb_display[con].var, 1);
1084 info->currcon = con;
1085 /* Install new colormap */
1086 do_install_cmap(con, info);
1087 DPRINTK("EXIT\n");
1088 return(0);
1089}
1090
1091
1092/*
1093 * Update the `var' structure (called by fbcon.c)
1094 *
1095 * This call looks only at yoffset and the FB_VMODE_YWRAP flag in `var'.
1096 * Since it's called by a kernel driver, no range checking is done.
1097 */
1098
1099static int Cyberfb_updatevar(int con, struct fb_info *info)
1100{
1101 DPRINTK("Enter - Exit\n");
1102 return(0);
1103}
1104
1105
1106/*
1107 * Get a Video Mode
1108 */
1109
1110static int __init get_video_mode(const char *name)
1111{
1112 int i;
1113
1114 DPRINTK("ENTER\n");
1115 for (i = 0; i < NUM_TOTAL_MODES; i++) {
1116 if (!strcmp(name, cyberfb_predefined[i].name)) {
1117 cyberfb_default = cyberfb_predefined[i].var;
1118 cyberfb_usermode = 1;
1119 DPRINTK("EXIT - Matched predefined mode\n");
1120 return(i);
1121 }
1122 }
1123 return(0);
1124}
1125
1126
1127/*
1128 * Text console acceleration
1129 */
1130
1131#ifdef FBCON_HAS_CFB8
1132static void fbcon_cyber8_bmove(struct display *p, int sy, int sx, int dy,
1133 int dx, int height, int width)
1134{
1135 DPRINTK("ENTER\n");
1136 sx *= 8; dx *= 8; width *= 8;
1137 Cyber_BitBLT((u_short)sx, (u_short)(sy*fontheight(p)), (u_short)dx,
1138 (u_short)(dy*fontheight(p)), (u_short)width,
1139 (u_short)(height*fontheight(p)), (u_short)S3_NEW);
1140 DPRINTK("EXIT\n");
1141}
1142
1143static void fbcon_cyber8_clear(struct vc_data *conp, struct display *p, int sy,
1144 int sx, int height, int width)
1145{
1146 unsigned char bg;
1147
1148 DPRINTK("ENTER\n");
1149 sx *= 8; width *= 8;
1150 bg = attr_bgcol_ec(p,conp);
1151 Cyber_RectFill((u_short)sx,
1152 (u_short)(sy*fontheight(p)),
1153 (u_short)width,
1154 (u_short)(height*fontheight(p)),
1155 (u_short)S3_NEW,
1156 (u_short)bg);
1157 DPRINTK("EXIT\n");
1158}
1159
1160static void fbcon_cyber8_putc(struct vc_data *conp, struct display *p, int c,
1161 int yy, int xx)
1162{
1163 DPRINTK("ENTER\n");
1164 Cyber_WaitBlit();
1165 fbcon_cfb8_putc(conp, p, c, yy, xx);
1166 DPRINTK("EXIT\n");
1167}
1168
1169static void fbcon_cyber8_putcs(struct vc_data *conp, struct display *p,
1170 const unsigned short *s, int count,
1171 int yy, int xx)
1172{
1173 DPRINTK("ENTER\n");
1174 Cyber_WaitBlit();
1175 fbcon_cfb8_putcs(conp, p, s, count, yy, xx);
1176 DPRINTK("EXIT\n");
1177}
1178
1179static void fbcon_cyber8_revc(struct display *p, int xx, int yy)
1180{
1181 DPRINTK("ENTER\n");
1182 Cyber_WaitBlit();
1183 fbcon_cfb8_revc(p, xx, yy);
1184 DPRINTK("EXIT\n");
1185}
1186
1187static struct display_switch fbcon_cyber8 = {
1188 .setup = fbcon_cfb8_setup,
1189 .bmove = fbcon_cyber8_bmove,
1190 .clear = fbcon_cyber8_clear,
1191 .putc = fbcon_cyber8_putc,
1192 .putcs = fbcon_cyber8_putcs,
1193 .revc = fbcon_cyber8_revc,
1194 .clear_margins =fbcon_cfb8_clear_margins,
1195 .fontwidthmask =FONTWIDTH(8)
1196};
1197#endif
1198
1199
1200#ifdef MODULE
1201MODULE_LICENSE("GPL");
1202
1203int init_module(void)
1204{
1205 return cyberfb_init();
1206}
1207#endif /* MODULE */
1208
1209/*
1210 *
1211 * Low level initialization routines for the CyberVision64 graphics card
1212 *
1213 * Most of the following code is from cvision_core.c
1214 *
1215 */
1216
1217#define MAXPIXELCLOCK 135000000 /* safety */
1218
1219#ifdef CV_AGGRESSIVE_TIMING
1220long cv64_memclk = 55000000;
1221#else
1222long cv64_memclk = 50000000;
1223#endif
1224
1225/*********************/
1226
1227static unsigned char clocks[]={
1228 0x13, 0x61, 0x6b, 0x6d, 0x51, 0x69, 0x54, 0x69,
1229 0x4f, 0x68, 0x6b, 0x6b, 0x18, 0x61, 0x7b, 0x6c,
1230 0x51, 0x67, 0x24, 0x62, 0x56, 0x67, 0x77, 0x6a,
1231 0x1d, 0x61, 0x53, 0x66, 0x6b, 0x68, 0x79, 0x69,
1232 0x7c, 0x69, 0x7f, 0x69, 0x22, 0x61, 0x54, 0x65,
1233 0x56, 0x65, 0x58, 0x65, 0x67, 0x66, 0x41, 0x63,
1234 0x27, 0x61, 0x13, 0x41, 0x37, 0x62, 0x6b, 0x4d,
1235 0x23, 0x43, 0x51, 0x49, 0x79, 0x66, 0x54, 0x49,
1236 0x7d, 0x66, 0x34, 0x56, 0x4f, 0x63, 0x1f, 0x42,
1237 0x6b, 0x4b, 0x7e, 0x4d, 0x18, 0x41, 0x2a, 0x43,
1238 0x7b, 0x4c, 0x74, 0x4b, 0x51, 0x47, 0x65, 0x49,
1239 0x24, 0x42, 0x68, 0x49, 0x56, 0x47, 0x75, 0x4a,
1240 0x77, 0x4a, 0x31, 0x43, 0x1d, 0x41, 0x71, 0x49,
1241 0x53, 0x46, 0x29, 0x42, 0x6b, 0x48, 0x1f, 0x41,
1242 0x79, 0x49, 0x6f, 0x48, 0x7c, 0x49, 0x38, 0x43,
1243 0x7f, 0x49, 0x5d, 0x46, 0x22, 0x41, 0x53, 0x45,
1244 0x54, 0x45, 0x55, 0x45, 0x56, 0x45, 0x57, 0x45,
1245 0x58, 0x45, 0x25, 0x41, 0x67, 0x46, 0x5b, 0x45,
1246 0x41, 0x43, 0x78, 0x47, 0x27, 0x41, 0x51, 0x44,
1247 0x13, 0x21, 0x7d, 0x47, 0x37, 0x42, 0x71, 0x46,
1248 0x6b, 0x2d, 0x14, 0x21, 0x23, 0x23, 0x7d, 0x2f,
1249 0x51, 0x29, 0x61, 0x2b, 0x79, 0x46, 0x1d, 0x22,
1250 0x54, 0x29, 0x45, 0x27, 0x7d, 0x46, 0x7f, 0x46,
1251 0x4f, 0x43, 0x2f, 0x41, 0x1f, 0x22, 0x6a, 0x2b,
1252 0x6b, 0x2b, 0x5b, 0x29, 0x7e, 0x2d, 0x65, 0x44,
1253 0x18, 0x21, 0x5e, 0x29, 0x2a, 0x23, 0x45, 0x26,
1254 0x7b, 0x2c, 0x19, 0x21, 0x74, 0x2b, 0x75, 0x2b,
1255 0x51, 0x27, 0x3f, 0x25, 0x65, 0x29, 0x40, 0x25,
1256 0x24, 0x22, 0x41, 0x25, 0x68, 0x29, 0x42, 0x25,
1257 0x56, 0x27, 0x7e, 0x2b, 0x75, 0x2a, 0x1c, 0x21,
1258 0x77, 0x2a, 0x4f, 0x26, 0x31, 0x23, 0x6f, 0x29,
1259 0x1d, 0x21, 0x32, 0x23, 0x71, 0x29, 0x72, 0x29,
1260 0x53, 0x26, 0x69, 0x28, 0x29, 0x22, 0x75, 0x29,
1261 0x6b, 0x28, 0x1f, 0x21, 0x1f, 0x21, 0x6d, 0x28,
1262 0x79, 0x29, 0x2b, 0x22, 0x6f, 0x28, 0x59, 0x26,
1263 0x7c, 0x29, 0x7d, 0x29, 0x38, 0x23, 0x21, 0x21,
1264 0x7f, 0x29, 0x39, 0x23, 0x5d, 0x26, 0x75, 0x28,
1265 0x22, 0x21, 0x77, 0x28, 0x53, 0x25, 0x6c, 0x27,
1266 0x54, 0x25, 0x61, 0x26, 0x55, 0x25, 0x30, 0x22,
1267 0x56, 0x25, 0x63, 0x26, 0x57, 0x25, 0x71, 0x27,
1268 0x58, 0x25, 0x7f, 0x28, 0x25, 0x21, 0x74, 0x27,
1269 0x67, 0x26, 0x40, 0x23, 0x5b, 0x25, 0x26, 0x21,
1270 0x41, 0x23, 0x34, 0x22, 0x78, 0x27, 0x6b, 0x26,
1271 0x27, 0x21, 0x35, 0x22, 0x51, 0x24, 0x7b, 0x27,
1272 0x13, 0x1, 0x13, 0x1, 0x7d, 0x27, 0x4c, 0x9,
1273 0x37, 0x22, 0x5b, 0xb, 0x71, 0x26, 0x5c, 0xb,
1274 0x6b, 0xd, 0x47, 0x23, 0x14, 0x1, 0x4f, 0x9,
1275 0x23, 0x3, 0x75, 0x26, 0x7d, 0xf, 0x1c, 0x2,
1276 0x51, 0x9, 0x59, 0x24, 0x61, 0xb, 0x69, 0x25,
1277 0x79, 0x26, 0x34, 0x5, 0x1d, 0x2, 0x6b, 0x25,
1278 0x54, 0x9, 0x35, 0x5, 0x45, 0x7, 0x6d, 0x25,
1279 0x7d, 0x26, 0x16, 0x1, 0x7f, 0x26, 0x77, 0xd,
1280 0x4f, 0x23, 0x78, 0xd, 0x2f, 0x21, 0x27, 0x3,
1281 0x1f, 0x2, 0x59, 0x9, 0x6a, 0xb, 0x73, 0x25,
1282 0x6b, 0xb, 0x63, 0x24, 0x5b, 0x9, 0x20, 0x2,
1283 0x7e, 0xd, 0x4b, 0x7, 0x65, 0x24, 0x43, 0x22,
1284 0x18, 0x1, 0x6f, 0xb, 0x5e, 0x9, 0x70, 0xb,
1285 0x2a, 0x3, 0x33, 0x4, 0x45, 0x6, 0x60, 0x9,
1286 0x7b, 0xc, 0x19, 0x1, 0x19, 0x1, 0x7d, 0xc,
1287 0x74, 0xb, 0x50, 0x7, 0x75, 0xb, 0x63, 0x9,
1288 0x51, 0x7, 0x23, 0x2, 0x3f, 0x5, 0x1a, 0x1,
1289 0x65, 0x9, 0x2d, 0x3, 0x40, 0x5, 0x0, 0x0,
1290};
1291
1292/* Console colors */
1293unsigned char cvconscolors[16][3] = { /* background, foreground, hilite */
1294 /* R G B */
1295 {0x30, 0x30, 0x30},
1296 {0x00, 0x00, 0x00},
1297 {0x80, 0x00, 0x00},
1298 {0x00, 0x80, 0x00},
1299 {0x00, 0x00, 0x80},
1300 {0x80, 0x80, 0x00},
1301 {0x00, 0x80, 0x80},
1302 {0x80, 0x00, 0x80},
1303 {0xff, 0xff, 0xff},
1304 {0x40, 0x40, 0x40},
1305 {0xff, 0x00, 0x00},
1306 {0x00, 0xff, 0x00},
1307 {0x00, 0x00, 0xff},
1308 {0xff, 0xff, 0x00},
1309 {0x00, 0xff, 0xff},
1310 {0x00, 0x00, 0xff}
1311};
1312
1313/* -------------------- Hardware specific routines ------------------------- */
1314
1315/* Read Attribute Controller Register=idx */
1316inline unsigned char RAttr (volatile unsigned char *regs, short idx)
1317{
1318 wb_64 (regs, ACT_ADDRESS_W, idx);
1319 mb();
1320 udelay(100);
1321 return (rb_64(regs, ACT_ADDRESS_R));
1322}
1323
1324/* Read Sequencer Register=idx */
1325inline unsigned char RSeq (volatile unsigned char *regs, short idx)
1326{
1327 wb_64 (regs, SEQ_ADDRESS, idx);
1328 mb();
1329 return (rb_64(regs, SEQ_ADDRESS_R));
1330}
1331
1332/* Read CRT Controller Register=idx */
1333inline unsigned char RCrt (volatile unsigned char *regs, short idx)
1334{
1335 wb_64 (regs, CRT_ADDRESS, idx);
1336 mb();
1337 return (rb_64(regs, CRT_ADDRESS_R));
1338}
1339
1340/* Read Graphics Controller Register=idx */
1341inline unsigned char RGfx (volatile unsigned char *regs, short idx)
1342{
1343 wb_64 (regs, GCT_ADDRESS, idx);
1344 mb();
1345 return (rb_64(regs, GCT_ADDRESS_R));
1346}
1347
1348/*
1349 * Special wakeup/passthrough registers on graphics boards
1350 */
1351
1352inline void cv64_write_port (unsigned short bits,
1353 volatile unsigned char *base)
1354{
1355 volatile unsigned char *addr;
1356 static unsigned char cvportbits = 0; /* Mirror port bits here */
1357 DPRINTK("ENTER\n");
1358
1359 addr = base + 0x40001;
1360 if (bits & 0x8000) {
1361 cvportbits |= bits & 0xff; /* Set bits */
1362 DPRINTK("Set bits: %04x\n", bits);
1363 } else {
1364 bits = bits & 0xff;
1365 bits = (~bits) & 0xff;
1366 cvportbits &= bits; /* Clear bits */
1367 DPRINTK("Clear bits: %04x\n", bits);
1368 }
1369
1370 *addr = cvportbits;
1371 DPRINTK("EXIT\n");
1372}
1373
1374/*
1375 * Monitor switch on CyberVision board
1376 *
1377 * toggle:
1378 * 0 = CyberVision Signal
1379 * 1 = Amiga Signal
1380 * board = board addr
1381 *
1382 */
1383inline void cvscreen (int toggle, volatile unsigned char *board)
1384{
1385 DPRINTK("ENTER\n");
1386 if (toggle == 1) {
1387 DPRINTK("Show Amiga video\n");
1388 cv64_write_port (0x10, board);
1389 } else {
1390 DPRINTK("Show CyberVision video\n");
1391 cv64_write_port (0x8010, board);
1392 }
1393 DPRINTK("EXIT\n");
1394}
1395
1396/* Control screen display */
1397/* toggle: 0 = on, 1 = off */
1398/* board = registerbase */
1399inline void gfx_on_off(int toggle, volatile unsigned char *regs)
1400{
1401 int r;
1402 DPRINTK("ENTER\n");
1403
1404 toggle &= 0x1;
1405 toggle = toggle << 5;
1406 DPRINTK("Turn display %s\n", (toggle ? "off" : "on"));
1407
1408 r = (int) RSeq(regs, SEQ_ID_CLOCKING_MODE);
1409 r &= 0xdf; /* Set bit 5 to 0 */
1410
1411 WSeq (regs, SEQ_ID_CLOCKING_MODE, r | toggle);
1412 DPRINTK("EXIT\n");
1413}
1414
1415/*
1416 * Computes M, N, and R values from
1417 * given input frequency. It uses a table of
1418 * precomputed values, to keep CPU time low.
1419 *
1420 * The return value consist of:
1421 * lower byte: Bits 4-0: N Divider Value
1422 * Bits 5-6: R Value for e.g. SR10 or SR12
1423 * higher byte: Bits 0-6: M divider value for e.g. SR11 or SR13
1424 */
1425static unsigned short cv64_compute_clock(unsigned long freq)
1426{
1427 static unsigned char *mnr, *save; /* M, N + R vals */
1428 unsigned long work_freq, r;
1429 unsigned short erg;
1430 long diff, d2;
1431
1432 DPRINTK("ENTER\n");
1433 if (freq < 12500000 || freq > MAXPIXELCLOCK) {
1434 printk("CV64 driver: Illegal clock frequency %ld, using 25MHz\n",
1435 freq);
1436 freq = 25000000;
1437 }
1438 DPRINTK("Freq = %ld\n", freq);
1439 mnr = clocks; /* there the vals are stored */
1440 d2 = 0x7fffffff;
1441
1442 while (*mnr) { /* mnr vals are 0-terminated */
1443 work_freq = (0x37EE * (mnr[0] + 2)) / ((mnr[1] & 0x1F) + 2);
1444
1445 r = (mnr[1] >> 5) & 0x03;
1446 if (r != 0) {
1447 work_freq = work_freq >> r; /* r is the freq divider */
1448 }
1449
1450 work_freq *= 0x3E8; /* 2nd part of OSC */
1451
1452 diff = abs(freq - work_freq);
1453
1454 if (d2 >= diff) {
1455 d2 = diff;
1456 /* In save are the vals for minimal diff */
1457 save = mnr;
1458 }
1459 mnr += 2;
1460 }
1461 erg = *((unsigned short *)save);
1462
1463 DPRINTK("EXIT\n");
1464 return (erg);
1465}
1466
1467static int cv_has_4mb (volatile unsigned char *fb)
1468{
1469 volatile unsigned long *tr, *tw;
1470 DPRINTK("ENTER\n");
1471
1472 /* write patterns in memory and test if they can be read */
1473 tw = (volatile unsigned long *) fb;
1474 tr = (volatile unsigned long *) (fb + 0x02000000);
1475
1476 *tw = 0x87654321;
1477
1478 if (*tr != 0x87654321) {
1479 DPRINTK("EXIT - <4MB\n");
1480 return (0);
1481 }
1482
1483 /* upper memory region */
1484 tw = (volatile unsigned long *) (fb + 0x00200000);
1485 tr = (volatile unsigned long *) (fb + 0x02200000);
1486
1487 *tw = 0x87654321;
1488
1489 if (*tr != 0x87654321) {
1490 DPRINTK("EXIT - <4MB\n");
1491 return (0);
1492 }
1493
1494 *tw = 0xAAAAAAAA;
1495
1496 if (*tr != 0xAAAAAAAA) {
1497 DPRINTK("EXIT - <4MB\n");
1498 return (0);
1499 }
1500
1501 *tw = 0x55555555;
1502
1503 if (*tr != 0x55555555) {
1504 DPRINTK("EXIT - <4MB\n");
1505 return (0);
1506 }
1507
1508 DPRINTK("EXIT\n");
1509 return (1);
1510}
1511
1512static void cv64_board_init (void)
1513{
1514 volatile unsigned char *regs = CyberRegs;
1515 int i;
1516 unsigned int clockpar;
1517 unsigned char test;
1518
1519 DPRINTK("ENTER\n");
1520
1521 /*
1522 * Special CyberVision 64 board operations
1523 */
1524 /* Reset board */
1525 for (i = 0; i < 6; i++) {
1526 cv64_write_port (0xff, CyberBase);
1527 }
1528 /* Return to operational mode */
1529 cv64_write_port (0x8004, CyberBase);
1530
1531 /*
1532 * Generic (?) S3 chip wakeup
1533 */
1534 /* Disable I/O & memory decoders, video in setup mode */
1535 wb_64 (regs, SREG_VIDEO_SUBS_ENABLE, 0x10);
1536 /* Video responds to cmds, addrs & data */
1537 wb_64 (regs, SREG_OPTION_SELECT, 0x1);
1538 /* Enable I/O & memory decoders, video in operational mode */
1539 wb_64 (regs, SREG_VIDEO_SUBS_ENABLE, 0x8);
1540 /* VGA color emulation, enable cpu access to display mem */
1541 wb_64 (regs, GREG_MISC_OUTPUT_W, 0x03);
1542 /* Unlock S3 VGA regs */
1543 WCrt (regs, CRT_ID_REGISTER_LOCK_1, 0x48);
1544 /* Unlock system control & extension registers */
1545 WCrt (regs, CRT_ID_REGISTER_LOCK_2, 0xA5);
1546/* GRF - Enable interrupts */
1547 /* Enable enhanced regs access, Ready cntl 0 wait states */
1548 test = RCrt (regs, CRT_ID_SYSTEM_CONFIG);
1549 test = test | 0x01; /* enable enhanced register access */
1550 test = test & 0xEF; /* clear bit 4, 0 wait state */
1551 WCrt (regs, CRT_ID_SYSTEM_CONFIG, test);
1552 /*
1553 * bit 0=1: Enable enhaced mode functions
1554 * bit 2=0: Enhanced mode 8+ bits/pixel
1555 * bit 4=1: Enable linear addressing
1556 * bit 5=1: Enable MMIO
1557 */
1558 wb_64 (regs, ECR_ADV_FUNC_CNTL, 0x31);
1559 /*
1560 * bit 0=1: Color emulation
1561 * bit 1=1: Enable CPU access to display memory
1562 * bit 5=1: Select high 64K memory page
1563 */
1564/* GRF - 0xE3 */
1565 wb_64 (regs, GREG_MISC_OUTPUT_W, 0x23);
1566
1567 /* Cpu base addr */
1568 WCrt (regs, CRT_ID_EXT_SYS_CNTL_4, 0x0);
1569
1570 /* Reset. This does nothing on Trio, but standard VGA practice */
1571 /* WSeq (CyberRegs, SEQ_ID_RESET, 0x03); */
1572 /* Character clocks 8 dots wide */
1573 WSeq (regs, SEQ_ID_CLOCKING_MODE, 0x01);
1574 /* Enable cpu write to all color planes */
1575 WSeq (regs, SEQ_ID_MAP_MASK, 0x0F);
1576 /* Font table in 1st 8k of plane 2, font A=B disables swtich */
1577 WSeq (regs, SEQ_ID_CHAR_MAP_SELECT, 0x0);
1578 /* Allow mem access to 256kb */
1579 WSeq (regs, SEQ_ID_MEMORY_MODE, 0x2);
1580 /* Unlock S3 extensions to VGA Sequencer regs */
1581 WSeq (regs, SEQ_ID_UNLOCK_EXT, 0x6);
1582
1583 /* Enable 4MB fast page mode */
1584 test = RSeq (regs, SEQ_ID_BUS_REQ_CNTL);
1585 test = test | 1 << 6;
1586 WSeq (regs, SEQ_ID_BUS_REQ_CNTL, test);
1587
1588 /* Faster LUT write: 1 DCLK LUT write cycle, RAMDAC clk doubled */
1589 WSeq (regs, SEQ_ID_RAMDAC_CNTL, 0xC0);
1590
1591 /* Clear immediate clock load bit */
1592 test = RSeq (regs, SEQ_ID_CLKSYN_CNTL_2);
1593 test = test & 0xDF;
1594 /* If > 55MHz, enable 2 cycle memory write */
1595 if (cv64_memclk >= 55000000) {
1596 test |= 0x80;
1597 }
1598 WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, test);
1599
1600 /* Set MCLK value */
1601 clockpar = cv64_compute_clock (cv64_memclk);
1602 test = (clockpar & 0xFF00) >> 8;
1603 WSeq (regs, SEQ_ID_MCLK_HI, test);
1604 test = clockpar & 0xFF;
1605 WSeq (regs, SEQ_ID_MCLK_LO, test);
1606
1607 /* Chip rev specific: Not in my Trio manual!!! */
1608 if (RCrt (regs, CRT_ID_REVISION) == 0x10)
1609 WSeq (regs, SEQ_ID_MORE_MAGIC, test);
1610
1611 /* We now load an 25 MHz, 31kHz, 640x480 standard VGA Mode. */
1612
1613 /* Set DCLK value */
1614 WSeq (regs, SEQ_ID_DCLK_HI, 0x13);
1615 WSeq (regs, SEQ_ID_DCLK_LO, 0x41);
1616
1617 /* Load DCLK (and MCLK?) immediately */
1618 test = RSeq (regs, SEQ_ID_CLKSYN_CNTL_2);
1619 test = test | 0x22;
1620 WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, test);
1621
1622 /* Enable loading of DCLK */
1623 test = rb_64(regs, GREG_MISC_OUTPUT_R);
1624 test = test | 0x0C;
1625 wb_64 (regs, GREG_MISC_OUTPUT_W, test);
1626
1627 /* Turn off immediate xCLK load */
1628 WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, 0x2);
1629
1630 /* Horizontal character clock counts */
1631 /* 8 LSB of 9 bits = total line - 5 */
1632 WCrt (regs, CRT_ID_HOR_TOTAL, 0x5F);
1633 /* Active display line */
1634 WCrt (regs, CRT_ID_HOR_DISP_ENA_END, 0x4F);
1635 /* Blank assertion start */
1636 WCrt (regs, CRT_ID_START_HOR_BLANK, 0x50);
1637 /* Blank assertion end */
1638 WCrt (regs, CRT_ID_END_HOR_BLANK, 0x82);
1639 /* HSYNC assertion start */
1640 WCrt (regs, CRT_ID_START_HOR_RETR, 0x54);
1641 /* HSYNC assertion end */
1642 WCrt (regs, CRT_ID_END_HOR_RETR, 0x80);
1643 WCrt (regs, CRT_ID_VER_TOTAL, 0xBF);
1644 WCrt (regs, CRT_ID_OVERFLOW, 0x1F);
1645 WCrt (regs, CRT_ID_PRESET_ROW_SCAN, 0x0);
1646 WCrt (regs, CRT_ID_MAX_SCAN_LINE, 0x40);
1647 WCrt (regs, CRT_ID_CURSOR_START, 0x00);
1648 WCrt (regs, CRT_ID_CURSOR_END, 0x00);
1649 WCrt (regs, CRT_ID_START_ADDR_HIGH, 0x00);
1650 WCrt (regs, CRT_ID_START_ADDR_LOW, 0x00);
1651 WCrt (regs, CRT_ID_CURSOR_LOC_HIGH, 0x00);
1652 WCrt (regs, CRT_ID_CURSOR_LOC_LOW, 0x00);
1653 WCrt (regs, CRT_ID_START_VER_RETR, 0x9C);
1654 WCrt (regs, CRT_ID_END_VER_RETR, 0x0E);
1655 WCrt (regs, CRT_ID_VER_DISP_ENA_END, 0x8F);
1656 WCrt (regs, CRT_ID_SCREEN_OFFSET, 0x50);
1657 WCrt (regs, CRT_ID_UNDERLINE_LOC, 0x00);
1658 WCrt (regs, CRT_ID_START_VER_BLANK, 0x96);
1659 WCrt (regs, CRT_ID_END_VER_BLANK, 0xB9);
1660 WCrt (regs, CRT_ID_MODE_CONTROL, 0xE3);
1661 WCrt (regs, CRT_ID_LINE_COMPARE, 0xFF);
1662 WCrt (regs, CRT_ID_BACKWAD_COMP_3, 0x10); /* FIFO enabled */
1663 WCrt (regs, CRT_ID_MISC_1, 0x35);
1664 WCrt (regs, CRT_ID_DISPLAY_FIFO, 0x5A);
1665 WCrt (regs, CRT_ID_EXT_MEM_CNTL_2, 0x70);
1666 WCrt (regs, CRT_ID_LAW_POS_LO, 0x40);
1667 WCrt (regs, CRT_ID_EXT_MEM_CNTL_3, 0xFF);
1668
1669 WGfx (regs, GCT_ID_SET_RESET, 0x0);
1670 WGfx (regs, GCT_ID_ENABLE_SET_RESET, 0x0);
1671 WGfx (regs, GCT_ID_COLOR_COMPARE, 0x0);
1672 WGfx (regs, GCT_ID_DATA_ROTATE, 0x0);
1673 WGfx (regs, GCT_ID_READ_MAP_SELECT, 0x0);
1674 WGfx (regs, GCT_ID_GRAPHICS_MODE, 0x40);
1675 WGfx (regs, GCT_ID_MISC, 0x01);
1676 WGfx (regs, GCT_ID_COLOR_XCARE, 0x0F);
1677 WGfx (regs, GCT_ID_BITMASK, 0xFF);
1678
1679 /* Colors for text mode */
1680 for (i = 0; i < 0xf; i++)
1681 WAttr (regs, i, i);
1682
1683 WAttr (regs, ACT_ID_ATTR_MODE_CNTL, 0x41);
1684 WAttr (regs, ACT_ID_OVERSCAN_COLOR, 0x01);
1685 WAttr (regs, ACT_ID_COLOR_PLANE_ENA, 0x0F);
1686 WAttr (regs, ACT_ID_HOR_PEL_PANNING, 0x0);
1687 WAttr (regs, ACT_ID_COLOR_SELECT, 0x0);
1688
1689 wb_64 (regs, VDAC_MASK, 0xFF);
1690
1691 *((unsigned long *) (regs + ECR_FRGD_COLOR)) = 0xFF;
1692 *((unsigned long *) (regs + ECR_BKGD_COLOR)) = 0;
1693
1694 /* Colors initially set to grayscale */
1695
1696 wb_64 (regs, VDAC_ADDRESS_W, 0);
1697 for (i = 255; i >= 0; i--) {
1698 wb_64(regs, VDAC_DATA, i);
1699 wb_64(regs, VDAC_DATA, i);
1700 wb_64(regs, VDAC_DATA, i);
1701 }
1702
1703 /* GFx hardware cursor off */
1704 WCrt (regs, CRT_ID_HWGC_MODE, 0x00);
1705
1706 /* Set first to 4MB, so test will work */
1707 WCrt (regs, CRT_ID_LAW_CNTL, 0x13);
1708 /* Find "correct" size of fbmem of Z3 board */
1709 if (cv_has_4mb (CyberMem)) {
1710 CyberSize = 1024 * 1024 * 4;
1711 WCrt (regs, CRT_ID_LAW_CNTL, 0x13);
1712 DPRINTK("4MB board\n");
1713 } else {
1714 CyberSize = 1024 * 1024 * 2;
1715 WCrt (regs, CRT_ID_LAW_CNTL, 0x12);
1716 DPRINTK("2MB board\n");
1717 }
1718
1719 /* Initialize graphics engine */
1720 Cyber_WaitBlit();
1721 vgaw16 (regs, ECR_FRGD_MIX, 0x27);
1722 vgaw16 (regs, ECR_BKGD_MIX, 0x07);
1723 vgaw16 (regs, ECR_READ_REG_DATA, 0x1000);
1724 udelay(200);
1725 vgaw16 (regs, ECR_READ_REG_DATA, 0x2000);
1726 Cyber_WaitBlit();
1727 vgaw16 (regs, ECR_READ_REG_DATA, 0x3FFF);
1728 Cyber_WaitBlit();
1729 udelay(200);
1730 vgaw16 (regs, ECR_READ_REG_DATA, 0x4FFF);
1731 Cyber_WaitBlit();
1732 vgaw16 (regs, ECR_BITPLANE_WRITE_MASK, ~0);
1733 Cyber_WaitBlit();
1734 vgaw16 (regs, ECR_READ_REG_DATA, 0xE000);
1735 vgaw16 (regs, ECR_CURRENT_Y_POS2, 0x00);
1736 vgaw16 (regs, ECR_CURRENT_X_POS2, 0x00);
1737 vgaw16 (regs, ECR_READ_REG_DATA, 0xA000);
1738 vgaw16 (regs, ECR_DEST_Y__AX_STEP, 0x00);
1739 vgaw16 (regs, ECR_DEST_Y2__AX_STEP2, 0x00);
1740 vgaw16 (regs, ECR_DEST_X__DIA_STEP, 0x00);
1741 vgaw16 (regs, ECR_DEST_X2__DIA_STEP2, 0x00);
1742 vgaw16 (regs, ECR_SHORT_STROKE, 0x00);
1743 vgaw16 (regs, ECR_DRAW_CMD, 0x01);
1744
1745 Cyber_WaitBlit();
1746
1747 vgaw16 (regs, ECR_READ_REG_DATA, 0x4FFF);
1748 vgaw16 (regs, ECR_BKGD_COLOR, 0x01);
1749 vgaw16 (regs, ECR_FRGD_COLOR, 0x00);
1750
1751
1752 /* Enable video display (set bit 5) */
1753/* ARB - Would also seem to write to AR13.
1754 * May want to use parts of WAttr to set JUST bit 5
1755 */
1756 WAttr (regs, 0x33, 0);
1757
1758/* GRF - function code ended here */
1759
1760 /* Turn gfx on again */
1761 gfx_on_off (0, regs);
1762
1763 /* Pass-through */
1764 cvscreen (0, CyberBase);
1765
1766 DPRINTK("EXIT\n");
1767}
1768
1769static void cv64_load_video_mode (struct fb_var_screeninfo *video_mode)
1770{
1771 volatile unsigned char *regs = CyberRegs;
1772 int fx, fy;
1773 unsigned short mnr;
1774 unsigned short HT, HDE, HBS, HBE, HSS, HSE, VDE, VBS, VBE, VSS, VSE, VT;
1775 char LACE, DBLSCAN, TEXT, CONSOLE;
1776 int cr50, sr15, sr18, clock_mode, test;
1777 int m, n;
1778 int tfillm, temptym;
1779 int hmul;
1780
1781 /* ---------------- */
1782 int xres, hfront, hsync, hback;
1783 int yres, vfront, vsync, vback;
1784 int bpp;
1785#if 0
1786 float freq_f;
1787#endif
1788 long freq;
1789 /* ---------------- */
1790
1791 DPRINTK("ENTER\n");
1792 TEXT = 0; /* if depth == 4 */
1793 CONSOLE = 0; /* mode num == 255 (console) */
1794 fx = fy = 8; /* force 8x8 font */
1795
1796/* GRF - Disable interrupts */
1797
1798 gfx_on_off (1, regs);
1799
1800 switch (video_mode->bits_per_pixel) {
1801 case 15:
1802 case 16:
1803 hmul = 2;
1804 break;
1805
1806 default:
1807 hmul = 1;
1808 break;
1809 }
1810
1811 bpp = video_mode->bits_per_pixel;
1812 xres = video_mode->xres;
1813 hfront = video_mode->right_margin;
1814 hsync = video_mode->hsync_len;
1815 hback = video_mode->left_margin;
1816
1817 LACE = 0;
1818 DBLSCAN = 0;
1819
1820 if (video_mode->vmode & FB_VMODE_DOUBLE) {
1821 yres = video_mode->yres * 2;
1822 vfront = video_mode->lower_margin * 2;
1823 vsync = video_mode->vsync_len * 2;
1824 vback = video_mode->upper_margin * 2;
1825 DBLSCAN = 1;
1826 } else if (video_mode->vmode & FB_VMODE_INTERLACED) {
1827 yres = (video_mode->yres + 1) / 2;
1828 vfront = (video_mode->lower_margin + 1) / 2;
1829 vsync = (video_mode->vsync_len + 1) / 2;
1830 vback = (video_mode->upper_margin + 1) / 2;
1831 LACE = 1;
1832 } else {
1833 yres = video_mode->yres;
1834 vfront = video_mode->lower_margin;
1835 vsync = video_mode->vsync_len;
1836 vback = video_mode->upper_margin;
1837 }
1838
1839 /* ARB Dropping custom setup method from cvision.c */
1840#if 0
1841 if (cvision_custom_mode) {
1842 HBS = hbs / 8 * hmul;
1843 HBE = hbe / 8 * hmul;
1844 HSS = hss / 8 * hmul;
1845 HSE = hse / 8 * hmul;
1846 HT = ht / 8 * hmul - 5;
1847
1848 VBS = vbs - 1;
1849 VSS = vss;
1850 VSE = vse;
1851 VBE = vbe;
1852 VT = vt - 2;
1853 } else {
1854#else
1855 {
1856#endif
1857 HBS = hmul * (xres / 8);
1858 HBE = hmul * ((xres/8) + (hfront/8) + (hsync/8) + (hback/8) - 2);
1859 HSS = hmul * ((xres/8) + (hfront/8) + 2);
1860 HSE = hmul * ((xres/8) + (hfront/8) + (hsync/8) + 1);
1861 HT = hmul * ((xres/8) + (hfront/8) + (hsync/8) + (hback/8));
1862
1863 VBS = yres;
1864 VBE = yres + vfront + vsync + vback - 2;
1865 VSS = yres + vfront - 1;
1866 VSE = yres + vfront + vsync - 1;
1867 VT = yres + vfront + vsync + vback - 2;
1868 }
1869
1870 wb_64 (regs, ECR_ADV_FUNC_CNTL, (TEXT ? 0x00 : 0x31));
1871
1872 if (TEXT)
1873 HDE = ((video_mode->xres + fx - 1) / fx) - 1;
1874 else
1875 HDE = (video_mode->xres + 3) * hmul / 8 - 1;
1876
1877 VDE = video_mode->yres - 1;
1878
1879 WCrt (regs, CRT_ID_HWGC_MODE, 0x00);
1880 WCrt (regs, CRT_ID_EXT_DAC_CNTL, 0x00);
1881
1882 WSeq (regs, SEQ_ID_MEMORY_MODE,
1883 (TEXT || (video_mode->bits_per_pixel == 1)) ? 0x06 : 0x0e);
1884 WGfx (regs, GCT_ID_READ_MAP_SELECT, 0x00);
1885 WSeq (regs, SEQ_ID_MAP_MASK,
1886 (video_mode->bits_per_pixel == 1) ? 0x01 : 0xFF);
1887 WSeq (regs, SEQ_ID_CHAR_MAP_SELECT, 0x00);
1888
1889 /* cv64_compute_clock accepts arguments in Hz */
1890 /* pixclock is in ps ... convert to Hz */
1891
1892#if 0
1893 freq_f = (1.0 / (float) video_mode->pixclock) * 1000000000;
1894 freq = ((long) freq_f) * 1000;
1895#else
1896/* freq = (long) ((long long)1000000000000 / (long long) video_mode->pixclock);
1897 */
1898 freq = (1000000000 / video_mode->pixclock) * 1000;
1899#endif
1900
1901 mnr = cv64_compute_clock (freq);
1902 WSeq (regs, SEQ_ID_DCLK_HI, ((mnr & 0xFF00) >> 8));
1903 WSeq (regs, SEQ_ID_DCLK_LO, (mnr & 0xFF));
1904
1905 /* Load display parameters into board */
1906 WCrt (regs, CRT_ID_EXT_HOR_OVF,
1907 ((HT & 0x100) ? 0x01 : 0x00) |
1908 ((HDE & 0x100) ? 0x02 : 0x00) |
1909 ((HBS & 0x100) ? 0x04 : 0x00) |
1910 /* ((HBE & 0x40) ? 0x08 : 0x00) | */
1911 ((HSS & 0x100) ? 0x10 : 0x00) |
1912 /* ((HSE & 0x20) ? 0x20 : 0x00) | */
1913 (((HT-5) & 0x100) ? 0x40 : 0x00)
1914 );
1915
1916 WCrt (regs, CRT_ID_EXT_VER_OVF,
1917 0x40 |
1918 ((VT & 0x400) ? 0x01 : 0x00) |
1919 ((VDE & 0x400) ? 0x02 : 0x00) |
1920 ((VBS & 0x400) ? 0x04 : 0x00) |
1921 ((VSS & 0x400) ? 0x10 : 0x00)
1922 );
1923
1924 WCrt (regs, CRT_ID_HOR_TOTAL, HT);
1925 WCrt (regs, CRT_ID_DISPLAY_FIFO, HT - 5);
1926 WCrt (regs, CRT_ID_HOR_DISP_ENA_END, ((HDE >= HBS) ? (HBS - 1) : HDE));
1927 WCrt (regs, CRT_ID_START_HOR_BLANK, HBS);
1928 WCrt (regs, CRT_ID_END_HOR_BLANK, ((HBE & 0x1F) | 0x80));
1929 WCrt (regs, CRT_ID_START_HOR_RETR, HSS);
1930 WCrt (regs, CRT_ID_END_HOR_RETR,
1931 (HSE & 0x1F) |
1932 ((HBE & 0x20) ? 0x80 : 0x00)
1933 );
1934 WCrt (regs, CRT_ID_VER_TOTAL, VT);
1935 WCrt (regs, CRT_ID_OVERFLOW,
1936 0x10 |
1937 ((VT & 0x100) ? 0x01 : 0x00) |
1938 ((VDE & 0x100) ? 0x02 : 0x00) |
1939 ((VSS & 0x100) ? 0x04 : 0x00) |
1940 ((VBS & 0x100) ? 0x08 : 0x00) |
1941 ((VT & 0x200) ? 0x20 : 0x00) |
1942 ((VDE & 0x200) ? 0x40 : 0x00) |
1943 ((VSS & 0x200) ? 0x80 : 0x00)
1944 );
1945 WCrt (regs, CRT_ID_MAX_SCAN_LINE,
1946 0x40 |
1947 (DBLSCAN ? 0x80 : 0x00) |
1948 ((VBS & 0x200) ? 0x20 : 0x00) |
1949 (TEXT ? ((fy - 1) & 0x1F) : 0x00)
1950 );
1951
1952 WCrt (regs, CRT_ID_MODE_CONTROL, 0xE3);
1953
1954 /* Text cursor */
1955
1956 if (TEXT) {
1957#if 1
1958 WCrt (regs, CRT_ID_CURSOR_START, (fy & 0x1f) - 2);
1959 WCrt (regs, CRT_ID_CURSOR_END, (fy & 0x1F) - 1);
1960#else
1961 WCrt (regs, CRT_ID_CURSOR_START, 0x00);
1962 WCrt (regs, CRT_ID_CURSOR_END, fy & 0x1F);
1963#endif
1964 WCrt (regs, CRT_ID_UNDERLINE_LOC, (fy - 1) & 0x1F);
1965 WCrt (regs, CRT_ID_CURSOR_LOC_HIGH, 0x00);
1966 WCrt (regs, CRT_ID_CURSOR_LOC_LOW, 0x00);
1967 }
1968
1969 WCrt (regs, CRT_ID_START_ADDR_HIGH, 0x00);
1970 WCrt (regs, CRT_ID_START_ADDR_LOW, 0x00);
1971 WCrt (regs, CRT_ID_START_VER_RETR, VSS);
1972 WCrt (regs, CRT_ID_END_VER_RETR, (VSE & 0x0F));
1973 WCrt (regs, CRT_ID_VER_DISP_ENA_END, VDE);
1974 WCrt (regs, CRT_ID_START_VER_BLANK, VBS);
1975 WCrt (regs, CRT_ID_END_VER_BLANK, VBE);
1976 WCrt (regs, CRT_ID_LINE_COMPARE, 0xFF);
1977 WCrt (regs, CRT_ID_LACE_RETR_START, HT / 2);
1978 WCrt (regs, CRT_ID_LACE_CONTROL, (LACE ? 0x20 : 0x00));
1979 WGfx (regs, GCT_ID_GRAPHICS_MODE,
1980 ((TEXT || (video_mode->bits_per_pixel == 1)) ? 0x00 : 0x40));
1981 WGfx (regs, GCT_ID_MISC, (TEXT ? 0x04 : 0x01));
1982 WSeq (regs, SEQ_ID_MEMORY_MODE,
1983 ((TEXT || (video_mode->bits_per_pixel == 1)) ? 0x06 : 0x02));
1984
1985 wb_64 (regs, VDAC_MASK, 0xFF);
1986
1987 /* Blank border */
1988 test = RCrt (regs, CRT_ID_BACKWAD_COMP_2);
1989 WCrt (regs, CRT_ID_BACKWAD_COMP_2, (test | 0x20));
1990
1991 sr15 = RSeq (regs, SEQ_ID_CLKSYN_CNTL_2);
1992 sr15 &= 0xEF;
1993 sr18 = RSeq (regs, SEQ_ID_RAMDAC_CNTL);
1994 sr18 &= 0x7F;
1995 clock_mode = 0x00;
1996 cr50 = 0x00;
1997
1998 test = RCrt (regs, CRT_ID_EXT_MISC_CNTL_2);
1999 test &= 0xD;
2000
2001 /* Clear roxxler byte-swapping... */
2002 cv64_write_port (0x0040, CyberBase);
2003 cv64_write_port (0x0020, CyberBase);
2004
2005 switch (video_mode->bits_per_pixel) {
2006 case 1:
2007 case 4: /* text */
2008 HDE = video_mode->xres / 16;
2009 break;
2010
2011 case 8:
2012 if (freq > 80000000) {
2013 clock_mode = 0x10 | 0x02;
2014 sr15 |= 0x10;
2015 sr18 |= 0x80;
2016 }
2017 HDE = video_mode->xres / 8;
2018 cr50 |= 0x00;
2019 break;
2020
2021 case 15:
2022 cv64_write_port (0x8020, CyberBase);
2023 clock_mode = 0x30;
2024 HDE = video_mode->xres / 4;
2025 cr50 |= 0x10;
2026 break;
2027
2028 case 16:
2029 cv64_write_port (0x8020, CyberBase);
2030 clock_mode = 0x50;
2031 HDE = video_mode->xres / 4;
2032 cr50 |= 0x10;
2033 break;
2034
2035 case 24:
2036 case 32:
2037 cv64_write_port (0x8040, CyberBase);
2038 clock_mode = 0xD0;
2039 HDE = video_mode->xres / 2;
2040 cr50 |= 0x30;
2041 break;
2042 }
2043
2044 WCrt (regs, CRT_ID_EXT_MISC_CNTL_2, clock_mode | test);
2045 WSeq (regs, SEQ_ID_CLKSYN_CNTL_2, sr15);
2046 WSeq (regs, SEQ_ID_RAMDAC_CNTL, sr18);
2047 WCrt (regs, CRT_ID_SCREEN_OFFSET, HDE);
2048
2049 WCrt (regs, CRT_ID_MISC_1, (TEXT ? 0x05 : 0x35));
2050
2051 test = RCrt (regs, CRT_ID_EXT_SYS_CNTL_2);
2052 test &= ~0x30;
2053 test |= (HDE >> 4) & 0x30;
2054 WCrt (regs, CRT_ID_EXT_SYS_CNTL_2, test);
2055
2056 /* Set up graphics engine */
2057 switch (video_mode->xres) {
2058 case 1024:
2059 cr50 |= 0x00;
2060 break;
2061
2062 case 640:
2063 cr50 |= 0x40;
2064 break;
2065
2066 case 800:
2067 cr50 |= 0x80;
2068 break;
2069
2070 case 1280:
2071 cr50 |= 0xC0;
2072 break;
2073
2074 case 1152:
2075 cr50 |= 0x01;
2076 break;
2077
2078 case 1600:
2079 cr50 |= 0x81;
2080 break;
2081
2082 default: /* XXX */
2083 break;
2084 }
2085
2086 WCrt (regs, CRT_ID_EXT_SYS_CNTL_1, cr50);
2087
2088 udelay(100);
2089 WAttr (regs, ACT_ID_ATTR_MODE_CNTL, (TEXT ? 0x08 : 0x41));
2090 udelay(100);
2091 WAttr (regs, ACT_ID_COLOR_PLANE_ENA,
2092 (video_mode->bits_per_pixel == 1) ? 0x01 : 0x0F);
2093 udelay(100);
2094
2095 tfillm = (96 * (cv64_memclk / 1000)) / 240000;
2096
2097 switch (video_mode->bits_per_pixel) {
2098 case 32:
2099 case 24:
2100 temptym = (24 * (cv64_memclk / 1000)) / (freq / 1000);
2101 break;
2102 case 15:
2103 case 16:
2104 temptym = (48 * (cv64_memclk / 1000)) / (freq / 1000);
2105 break;
2106 case 4:
2107 temptym = (192 * (cv64_memclk / 1000)) / (freq / 1000);
2108 break;
2109 default:
2110 temptym = (96 * (cv64_memclk / 1000)) / (freq / 1000);
2111 break;
2112 }
2113
2114 m = (temptym - tfillm - 9) / 2;
2115 if (m < 0)
2116 m = 0;
2117 m = (m & 0x1F) << 3;
2118 if (m < 0x18)
2119 m = 0x18;
2120 n = 0xFF;
2121
2122 WCrt (regs, CRT_ID_EXT_MEM_CNTL_2, m);
2123 WCrt (regs, CRT_ID_EXT_MEM_CNTL_3, n);
2124 udelay(10);
2125
2126 /* Text initialization */
2127
2128 if (TEXT) {
2129 /* Do text initialization here ! */
2130 }
2131
2132 if (CONSOLE) {
2133 int i;
2134 wb_64 (regs, VDAC_ADDRESS_W, 0);
2135 for (i = 0; i < 4; i++) {
2136 wb_64 (regs, VDAC_DATA, cvconscolors [i][0]);
2137 wb_64 (regs, VDAC_DATA, cvconscolors [i][1]);
2138 wb_64 (regs, VDAC_DATA, cvconscolors [i][2]);
2139 }
2140 }
2141
2142 WAttr (regs, 0x33, 0);
2143
2144 /* Turn gfx on again */
2145 gfx_on_off (0, (volatile unsigned char *) regs);
2146
2147 /* Pass-through */
2148 cvscreen (0, CyberBase);
2149
2150DPRINTK("EXIT\n");
2151}
2152
2153void cvision_bitblt (u_short sx, u_short sy, u_short dx, u_short dy,
2154 u_short w, u_short h)
2155{
2156 volatile unsigned char *regs = CyberRegs;
2157 unsigned short drawdir = 0;
2158
2159 DPRINTK("ENTER\n");
2160 if (sx > dx) {
2161 drawdir |= 1 << 5;
2162 } else {
2163 sx += w - 1;
2164 dx += w - 1;
2165 }
2166
2167 if (sy > dy) {
2168 drawdir |= 1 << 7;
2169 } else {
2170 sy += h - 1;
2171 dy += h - 1;
2172 }
2173
2174 Cyber_WaitBlit();
2175 vgaw16 (regs, ECR_READ_REG_DATA, 0xA000);
2176 vgaw16 (regs, ECR_BKGD_MIX, 0x7);
2177 vgaw16 (regs, ECR_FRGD_MIX, 0x67);
2178 vgaw16 (regs, ECR_BKGD_COLOR, 0x0);
2179 vgaw16 (regs, ECR_FRGD_COLOR, 0x1);
2180 vgaw16 (regs, ECR_BITPLANE_READ_MASK, 0x1);
2181 vgaw16 (regs, ECR_BITPLANE_WRITE_MASK, 0xFFF);
2182 vgaw16 (regs, ECR_CURRENT_Y_POS, sy);
2183 vgaw16 (regs, ECR_CURRENT_X_POS, sx);
2184 vgaw16 (regs, ECR_DEST_Y__AX_STEP, dy);
2185 vgaw16 (regs, ECR_DEST_X__DIA_STEP, dx);
2186 vgaw16 (regs, ECR_READ_REG_DATA, h - 1);
2187 vgaw16 (regs, ECR_MAJ_AXIS_PIX_CNT, w - 1);
2188 vgaw16 (regs, ECR_DRAW_CMD, 0xC051 | drawdir);
2189 DPRINTK("EXIT\n");
2190}
2191
2192void cvision_clear (u_short dx, u_short dy, u_short w, u_short h, u_short bg)
2193{
2194 volatile unsigned char *regs = CyberRegs;
2195 DPRINTK("ENTER\n");
2196 Cyber_WaitBlit();
2197 vgaw16 (regs, ECR_FRGD_MIX, 0x0027);
2198 vgaw16 (regs, ECR_FRGD_COLOR, bg);
2199 vgaw16 (regs, ECR_READ_REG_DATA, 0xA000);
2200 vgaw16 (regs, ECR_CURRENT_Y_POS, dy);
2201 vgaw16 (regs, ECR_CURRENT_X_POS, dx);
2202 vgaw16 (regs, ECR_READ_REG_DATA, h - 1);
2203 vgaw16 (regs, ECR_MAJ_AXIS_PIX_CNT, w - 1);
2204 vgaw16 (regs, ECR_DRAW_CMD, 0x40B1);
2205 DPRINTK("EXIT\n");
2206}
2207
2208#ifdef CYBERFBDEBUG
2209/*
2210 * Dump internal settings of CyberVision board
2211 */
2212static void cv64_dump (void)
2213{
2214 volatile unsigned char *regs = CyberRegs;
2215 DPRINTK("ENTER\n");
2216 /* Dump the VGA setup values */
2217 *(regs + S3_CRTC_ADR) = 0x00;
2218 DPRINTK("CR00 = %x\n", *(regs + S3_CRTC_DATA));
2219 *(regs + S3_CRTC_ADR) = 0x01;
2220 DPRINTK("CR01 = %x\n", *(regs + S3_CRTC_DATA));
2221 *(regs + S3_CRTC_ADR) = 0x02;
2222 DPRINTK("CR02 = %x\n", *(regs + S3_CRTC_DATA));
2223 *(regs + S3_CRTC_ADR) = 0x03;
2224 DPRINTK("CR03 = %x\n", *(regs + S3_CRTC_DATA));
2225 *(regs + S3_CRTC_ADR) = 0x04;
2226 DPRINTK("CR04 = %x\n", *(regs + S3_CRTC_DATA));
2227 *(regs + S3_CRTC_ADR) = 0x05;
2228 DPRINTK("CR05 = %x\n", *(regs + S3_CRTC_DATA));
2229 *(regs + S3_CRTC_ADR) = 0x06;
2230 DPRINTK("CR06 = %x\n", *(regs + S3_CRTC_DATA));
2231 *(regs + S3_CRTC_ADR) = 0x07;
2232 DPRINTK("CR07 = %x\n", *(regs + S3_CRTC_DATA));
2233 *(regs + S3_CRTC_ADR) = 0x08;
2234 DPRINTK("CR08 = %x\n", *(regs + S3_CRTC_DATA));
2235 *(regs + S3_CRTC_ADR) = 0x09;
2236 DPRINTK("CR09 = %x\n", *(regs + S3_CRTC_DATA));
2237 *(regs + S3_CRTC_ADR) = 0x10;
2238 DPRINTK("CR10 = %x\n", *(regs + S3_CRTC_DATA));
2239 *(regs + S3_CRTC_ADR) = 0x11;
2240 DPRINTK("CR11 = %x\n", *(regs + S3_CRTC_DATA));
2241 *(regs + S3_CRTC_ADR) = 0x12;
2242 DPRINTK("CR12 = %x\n", *(regs + S3_CRTC_DATA));
2243 *(regs + S3_CRTC_ADR) = 0x13;
2244 DPRINTK("CR13 = %x\n", *(regs + S3_CRTC_DATA));
2245 *(regs + S3_CRTC_ADR) = 0x15;
2246 DPRINTK("CR15 = %x\n", *(regs + S3_CRTC_DATA));
2247 *(regs + S3_CRTC_ADR) = 0x16;
2248 DPRINTK("CR16 = %x\n", *(regs + S3_CRTC_DATA));
2249 *(regs + S3_CRTC_ADR) = 0x36;
2250 DPRINTK("CR36 = %x\n", *(regs + S3_CRTC_DATA));
2251 *(regs + S3_CRTC_ADR) = 0x37;
2252 DPRINTK("CR37 = %x\n", *(regs + S3_CRTC_DATA));
2253 *(regs + S3_CRTC_ADR) = 0x42;
2254 DPRINTK("CR42 = %x\n", *(regs + S3_CRTC_DATA));
2255 *(regs + S3_CRTC_ADR) = 0x43;
2256 DPRINTK("CR43 = %x\n", *(regs + S3_CRTC_DATA));
2257 *(regs + S3_CRTC_ADR) = 0x50;
2258 DPRINTK("CR50 = %x\n", *(regs + S3_CRTC_DATA));
2259 *(regs + S3_CRTC_ADR) = 0x51;
2260 DPRINTK("CR51 = %x\n", *(regs + S3_CRTC_DATA));
2261 *(regs + S3_CRTC_ADR) = 0x53;
2262 DPRINTK("CR53 = %x\n", *(regs + S3_CRTC_DATA));
2263 *(regs + S3_CRTC_ADR) = 0x58;
2264 DPRINTK("CR58 = %x\n", *(regs + S3_CRTC_DATA));
2265 *(regs + S3_CRTC_ADR) = 0x59;
2266 DPRINTK("CR59 = %x\n", *(regs + S3_CRTC_DATA));
2267 *(regs + S3_CRTC_ADR) = 0x5A;
2268 DPRINTK("CR5A = %x\n", *(regs + S3_CRTC_DATA));
2269 *(regs + S3_CRTC_ADR) = 0x5D;
2270 DPRINTK("CR5D = %x\n", *(regs + S3_CRTC_DATA));
2271 *(regs + S3_CRTC_ADR) = 0x5E;
2272 DPRINTK("CR5E = %x\n", *(regs + S3_CRTC_DATA));
2273 DPRINTK("MISC = %x\n", *(regs + GREG_MISC_OUTPUT_R));
2274 *(regs + SEQ_ADDRESS) = 0x01;
2275 DPRINTK("SR01 = %x\n", *(regs + SEQ_ADDRESS_R));
2276 *(regs + SEQ_ADDRESS) = 0x02;
2277 DPRINTK("SR02 = %x\n", *(regs + SEQ_ADDRESS_R));
2278 *(regs + SEQ_ADDRESS) = 0x03;
2279 DPRINTK("SR03 = %x\n", *(regs + SEQ_ADDRESS_R));
2280 *(regs + SEQ_ADDRESS) = 0x09;
2281 DPRINTK("SR09 = %x\n", *(regs + SEQ_ADDRESS_R));
2282 *(regs + SEQ_ADDRESS) = 0x10;
2283 DPRINTK("SR10 = %x\n", *(regs + SEQ_ADDRESS_R));
2284 *(regs + SEQ_ADDRESS) = 0x11;
2285 DPRINTK("SR11 = %x\n", *(regs + SEQ_ADDRESS_R));
2286 *(regs + SEQ_ADDRESS) = 0x12;
2287 DPRINTK("SR12 = %x\n", *(regs + SEQ_ADDRESS_R));
2288 *(regs + SEQ_ADDRESS) = 0x13;
2289 DPRINTK("SR13 = %x\n", *(regs + SEQ_ADDRESS_R));
2290 *(regs + SEQ_ADDRESS) = 0x15;
2291 DPRINTK("SR15 = %x\n", *(regs + SEQ_ADDRESS_R));
2292
2293 return;
2294}
2295#endif
diff --git a/drivers/video/cyberfb.h b/drivers/video/cyberfb.h
deleted file mode 100644
index 8435c430ad2..00000000000
--- a/drivers/video/cyberfb.h
+++ /dev/null
@@ -1,415 +0,0 @@
1/*
2 * linux/arch/m68k/console/cvision.h -- CyberVision64 definitions for the
3 * text console driver.
4 *
5 * Copyright (c) 1998 Alan Bair
6 *
7 * This file is based on the initial port to Linux of grf_cvreg.h:
8 *
9 * Copyright (c) 1997 Antonio Santos
10 *
11 * The original work is from the NetBSD CyberVision 64 framebuffer driver
12 * and support files (grf_cv.c, grf_cvreg.h, ite_cv.c):
13 * Permission to use the source of this driver was obtained from the
14 * author Michael Teske by Alan Bair.
15 *
16 * Copyright (c) 1995 Michael Teske
17 *
18 * History:
19 *
20 *
21 *
22 * This file is subject to the terms and conditions of the GNU General Public
23 * License. See the file COPYING in the main directory of this archive
24 * for more details.
25 */
26
27/* s3 commands */
28#define S3_BITBLT 0xc011
29#define S3_TWOPOINTLINE 0x2811
30#define S3_FILLEDRECT 0x40b1
31
32#define S3_FIFO_EMPTY 0x0400
33#define S3_HDW_BUSY 0x0200
34
35/* Enhanced register mapping (MMIO mode) */
36
37#define S3_READ_SEL 0xbee8 /* offset f */
38#define S3_MULT_MISC 0xbee8 /* offset e */
39#define S3_ERR_TERM 0x92e8
40#define S3_FRGD_COLOR 0xa6e8
41#define S3_BKGD_COLOR 0xa2e8
42#define S3_PIXEL_CNTL 0xbee8 /* offset a */
43#define S3_FRGD_MIX 0xbae8
44#define S3_BKGD_MIX 0xb6e8
45#define S3_CUR_Y 0x82e8
46#define S3_CUR_X 0x86e8
47#define S3_DESTY_AXSTP 0x8ae8
48#define S3_DESTX_DIASTP 0x8ee8
49#define S3_MIN_AXIS_PCNT 0xbee8 /* offset 0 */
50#define S3_MAJ_AXIS_PCNT 0x96e8
51#define S3_CMD 0x9ae8
52#define S3_GP_STAT 0x9ae8
53#define S3_ADVFUNC_CNTL 0x4ae8
54#define S3_WRT_MASK 0xaae8
55#define S3_RD_MASK 0xaee8
56
57/* Enhanced register mapping (Packed MMIO mode, write only) */
58#define S3_ALT_CURXY 0x8100
59#define S3_ALT_CURXY2 0x8104
60#define S3_ALT_STEP 0x8108
61#define S3_ALT_STEP2 0x810c
62#define S3_ALT_ERR 0x8110
63#define S3_ALT_CMD 0x8118
64#define S3_ALT_MIX 0x8134
65#define S3_ALT_PCNT 0x8148
66#define S3_ALT_PAT 0x8168
67
68/* Drawing modes */
69#define S3_NOTCUR 0x0000
70#define S3_LOGICALZERO 0x0001
71#define S3_LOGICALONE 0x0002
72#define S3_LEAVEASIS 0x0003
73#define S3_NOTNEW 0x0004
74#define S3_CURXORNEW 0x0005
75#define S3_NOT_CURXORNEW 0x0006
76#define S3_NEW 0x0007
77#define S3_NOTCURORNOTNEW 0x0008
78#define S3_CURORNOTNEW 0x0009
79#define S3_NOTCURORNEW 0x000a
80#define S3_CURORNEW 0x000b
81#define S3_CURANDNEW 0x000c
82#define S3_NOTCURANDNEW 0x000d
83#define S3_CURANDNOTNEW 0x000e
84#define S3_NOTCURANDNOTNEW 0x000f
85
86#define S3_CRTC_ADR 0x03d4
87#define S3_CRTC_DATA 0x03d5
88
89#define S3_REG_LOCK2 0x39
90#define S3_HGC_MODE 0x45
91
92#define S3_HWGC_ORGX_H 0x46
93#define S3_HWGC_ORGX_L 0x47
94#define S3_HWGC_ORGY_H 0x48
95#define S3_HWGC_ORGY_L 0x49
96#define S3_HWGC_DX 0x4e
97#define S3_HWGC_DY 0x4f
98
99#define S3_LAW_CTL 0x58
100
101/**************************************************/
102
103/* support for a BitBlt operation. The op-codes are identical
104 to X11 GCs */
105#define GRFBBOPclear 0x0 /* 0 */
106#define GRFBBOPand 0x1 /* src AND dst */
107#define GRFBBOPandReverse 0x2 /* src AND NOT dst */
108#define GRFBBOPcopy 0x3 /* src */
109#define GRFBBOPandInverted 0x4 /* NOT src AND dst */
110#define GRFBBOPnoop 0x5 /* dst */
111#define GRFBBOPxor 0x6 /* src XOR dst */
112#define GRFBBOPor 0x7 /* src OR dst */
113#define GRFBBOPnor 0x8 /* NOT src AND NOT dst */
114#define GRFBBOPequiv 0x9 /* NOT src XOR dst */
115#define GRFBBOPinvert 0xa /* NOT dst */
116#define GRFBBOPorReverse 0xb /* src OR NOT dst */
117#define GRFBBOPcopyInverted 0xc /* NOT src */
118#define GRFBBOPorInverted 0xd /* NOT src OR dst */
119#define GRFBBOPnand 0xe /* NOT src OR NOT dst */
120#define GRFBBOPset 0xf /* 1 */
121
122
123/* Write 16 Bit VGA register */
124#define vgaw16(ba, reg, val) \
125*((unsigned short *) (((volatile unsigned char *)ba)+reg)) = val
126
127/*
128 * Defines for the used register addresses (mw)
129 *
130 * NOTE: There are some registers that have different addresses when
131 * in mono or color mode. We only support color mode, and thus
132 * some addresses won't work in mono-mode!
133 *
134 * General and VGA-registers taken from retina driver. Fixed a few
135 * bugs in it. (SR and GR read address is Port + 1, NOT Port)
136 *
137 */
138
139/* General Registers: */
140#define GREG_MISC_OUTPUT_R 0x03CC
141#define GREG_MISC_OUTPUT_W 0x03C2
142#define GREG_FEATURE_CONTROL_R 0x03CA
143#define GREG_FEATURE_CONTROL_W 0x03DA
144#define GREG_INPUT_STATUS0_R 0x03C2
145#define GREG_INPUT_STATUS1_R 0x03DA
146
147/* Setup Registers: */
148#define SREG_OPTION_SELECT 0x0102
149#define SREG_VIDEO_SUBS_ENABLE 0x46E8
150
151/* Attribute Controller: */
152#define ACT_ADDRESS 0x03C0
153#define ACT_ADDRESS_R 0x03C1
154#define ACT_ADDRESS_W 0x03C0
155#define ACT_ADDRESS_RESET 0x03DA
156#define ACT_ID_PALETTE0 0x00
157#define ACT_ID_PALETTE1 0x01
158#define ACT_ID_PALETTE2 0x02
159#define ACT_ID_PALETTE3 0x03
160#define ACT_ID_PALETTE4 0x04
161#define ACT_ID_PALETTE5 0x05
162#define ACT_ID_PALETTE6 0x06
163#define ACT_ID_PALETTE7 0x07
164#define ACT_ID_PALETTE8 0x08
165#define ACT_ID_PALETTE9 0x09
166#define ACT_ID_PALETTE10 0x0A
167#define ACT_ID_PALETTE11 0x0B
168#define ACT_ID_PALETTE12 0x0C
169#define ACT_ID_PALETTE13 0x0D
170#define ACT_ID_PALETTE14 0x0E
171#define ACT_ID_PALETTE15 0x0F
172#define ACT_ID_ATTR_MODE_CNTL 0x10
173#define ACT_ID_OVERSCAN_COLOR 0x11
174#define ACT_ID_COLOR_PLANE_ENA 0x12
175#define ACT_ID_HOR_PEL_PANNING 0x13
176#define ACT_ID_COLOR_SELECT 0x14
177
178/* Graphics Controller: */
179#define GCT_ADDRESS 0x03CE
180#define GCT_ADDRESS_R 0x03CF
181#define GCT_ADDRESS_W 0x03CF
182#define GCT_ID_SET_RESET 0x00
183#define GCT_ID_ENABLE_SET_RESET 0x01
184#define GCT_ID_COLOR_COMPARE 0x02
185#define GCT_ID_DATA_ROTATE 0x03
186#define GCT_ID_READ_MAP_SELECT 0x04
187#define GCT_ID_GRAPHICS_MODE 0x05
188#define GCT_ID_MISC 0x06
189#define GCT_ID_COLOR_XCARE 0x07
190#define GCT_ID_BITMASK 0x08
191
192/* Sequencer: */
193#define SEQ_ADDRESS 0x03C4
194#define SEQ_ADDRESS_R 0x03C5
195#define SEQ_ADDRESS_W 0x03C5
196#define SEQ_ID_RESET 0x00
197#define SEQ_ID_CLOCKING_MODE 0x01
198#define SEQ_ID_MAP_MASK 0x02
199#define SEQ_ID_CHAR_MAP_SELECT 0x03
200#define SEQ_ID_MEMORY_MODE 0x04
201#define SEQ_ID_UNKNOWN1 0x05
202#define SEQ_ID_UNKNOWN2 0x06
203#define SEQ_ID_UNKNOWN3 0x07
204/* S3 extensions */
205#define SEQ_ID_UNLOCK_EXT 0x08
206#define SEQ_ID_EXT_SEQ_REG9 0x09
207#define SEQ_ID_BUS_REQ_CNTL 0x0A
208#define SEQ_ID_EXT_MISC_SEQ 0x0B
209#define SEQ_ID_UNKNOWN4 0x0C
210#define SEQ_ID_EXT_SEQ 0x0D
211#define SEQ_ID_UNKNOWN5 0x0E
212#define SEQ_ID_UNKNOWN6 0x0F
213#define SEQ_ID_MCLK_LO 0x10
214#define SEQ_ID_MCLK_HI 0x11
215#define SEQ_ID_DCLK_LO 0x12
216#define SEQ_ID_DCLK_HI 0x13
217#define SEQ_ID_CLKSYN_CNTL_1 0x14
218#define SEQ_ID_CLKSYN_CNTL_2 0x15
219#define SEQ_ID_CLKSYN_TEST_HI 0x16 /* reserved for S3 testing of the */
220#define SEQ_ID_CLKSYN_TEST_LO 0x17 /* internal clock synthesizer */
221#define SEQ_ID_RAMDAC_CNTL 0x18
222#define SEQ_ID_MORE_MAGIC 0x1A
223
224/* CRT Controller: */
225#define CRT_ADDRESS 0x03D4
226#define CRT_ADDRESS_R 0x03D5
227#define CRT_ADDRESS_W 0x03D5
228#define CRT_ID_HOR_TOTAL 0x00
229#define CRT_ID_HOR_DISP_ENA_END 0x01
230#define CRT_ID_START_HOR_BLANK 0x02
231#define CRT_ID_END_HOR_BLANK 0x03
232#define CRT_ID_START_HOR_RETR 0x04
233#define CRT_ID_END_HOR_RETR 0x05
234#define CRT_ID_VER_TOTAL 0x06
235#define CRT_ID_OVERFLOW 0x07
236#define CRT_ID_PRESET_ROW_SCAN 0x08
237#define CRT_ID_MAX_SCAN_LINE 0x09
238#define CRT_ID_CURSOR_START 0x0A
239#define CRT_ID_CURSOR_END 0x0B
240#define CRT_ID_START_ADDR_HIGH 0x0C
241#define CRT_ID_START_ADDR_LOW 0x0D
242#define CRT_ID_CURSOR_LOC_HIGH 0x0E
243#define CRT_ID_CURSOR_LOC_LOW 0x0F
244#define CRT_ID_START_VER_RETR 0x10
245#define CRT_ID_END_VER_RETR 0x11
246#define CRT_ID_VER_DISP_ENA_END 0x12
247#define CRT_ID_SCREEN_OFFSET 0x13
248#define CRT_ID_UNDERLINE_LOC 0x14
249#define CRT_ID_START_VER_BLANK 0x15
250#define CRT_ID_END_VER_BLANK 0x16
251#define CRT_ID_MODE_CONTROL 0x17
252#define CRT_ID_LINE_COMPARE 0x18
253#define CRT_ID_GD_LATCH_RBACK 0x22
254#define CRT_ID_ACT_TOGGLE_RBACK 0x24
255#define CRT_ID_ACT_INDEX_RBACK 0x26
256/* S3 extensions: S3 VGA Registers */
257#define CRT_ID_DEVICE_HIGH 0x2D
258#define CRT_ID_DEVICE_LOW 0x2E
259#define CRT_ID_REVISION 0x2F
260#define CRT_ID_CHIP_ID_REV 0x30
261#define CRT_ID_MEMORY_CONF 0x31
262#define CRT_ID_BACKWAD_COMP_1 0x32
263#define CRT_ID_BACKWAD_COMP_2 0x33
264#define CRT_ID_BACKWAD_COMP_3 0x34
265#define CRT_ID_REGISTER_LOCK 0x35
266#define CRT_ID_CONFIG_1 0x36
267#define CRT_ID_CONFIG_2 0x37
268#define CRT_ID_REGISTER_LOCK_1 0x38
269#define CRT_ID_REGISTER_LOCK_2 0x39
270#define CRT_ID_MISC_1 0x3A
271#define CRT_ID_DISPLAY_FIFO 0x3B
272#define CRT_ID_LACE_RETR_START 0x3C
273/* S3 extensions: System Control Registers */
274#define CRT_ID_SYSTEM_CONFIG 0x40
275#define CRT_ID_BIOS_FLAG 0x41
276#define CRT_ID_LACE_CONTROL 0x42
277#define CRT_ID_EXT_MODE 0x43
278#define CRT_ID_HWGC_MODE 0x45 /* HWGC = Hardware Graphics Cursor */
279#define CRT_ID_HWGC_ORIGIN_X_HI 0x46
280#define CRT_ID_HWGC_ORIGIN_X_LO 0x47
281#define CRT_ID_HWGC_ORIGIN_Y_HI 0x48
282#define CRT_ID_HWGC_ORIGIN_Y_LO 0x49
283#define CRT_ID_HWGC_FG_STACK 0x4A
284#define CRT_ID_HWGC_BG_STACK 0x4B
285#define CRT_ID_HWGC_START_AD_HI 0x4C
286#define CRT_ID_HWGC_START_AD_LO 0x4D
287#define CRT_ID_HWGC_DSTART_X 0x4E
288#define CRT_ID_HWGC_DSTART_Y 0x4F
289/* S3 extensions: System Extension Registers */
290#define CRT_ID_EXT_SYS_CNTL_1 0x50
291#define CRT_ID_EXT_SYS_CNTL_2 0x51
292#define CRT_ID_EXT_BIOS_FLAG_1 0x52
293#define CRT_ID_EXT_MEM_CNTL_1 0x53
294#define CRT_ID_EXT_MEM_CNTL_2 0x54
295#define CRT_ID_EXT_DAC_CNTL 0x55
296#define CRT_ID_EX_SYNC_1 0x56
297#define CRT_ID_EX_SYNC_2 0x57
298#define CRT_ID_LAW_CNTL 0x58 /* LAW = Linear Address Window */
299#define CRT_ID_LAW_POS_HI 0x59
300#define CRT_ID_LAW_POS_LO 0x5A
301#define CRT_ID_GOUT_PORT 0x5C
302#define CRT_ID_EXT_HOR_OVF 0x5D
303#define CRT_ID_EXT_VER_OVF 0x5E
304#define CRT_ID_EXT_MEM_CNTL_3 0x60
305#define CRT_ID_EX_SYNC_3 0x63
306#define CRT_ID_EXT_MISC_CNTL 0x65
307#define CRT_ID_EXT_MISC_CNTL_1 0x66
308#define CRT_ID_EXT_MISC_CNTL_2 0x67
309#define CRT_ID_CONFIG_3 0x68
310#define CRT_ID_EXT_SYS_CNTL_3 0x69
311#define CRT_ID_EXT_SYS_CNTL_4 0x6A
312#define CRT_ID_EXT_BIOS_FLAG_3 0x6B
313#define CRT_ID_EXT_BIOS_FLAG_4 0x6C
314
315/* Enhanced Commands Registers: */
316#define ECR_SUBSYSTEM_STAT 0x42E8
317#define ECR_SUBSYSTEM_CNTL 0x42E8
318#define ECR_ADV_FUNC_CNTL 0x4AE8
319#define ECR_CURRENT_Y_POS 0x82E8
320#define ECR_CURRENT_Y_POS2 0x82EA /* Trio64 only */
321#define ECR_CURRENT_X_POS 0x86E8
322#define ECR_CURRENT_X_POS2 0x86EA /* Trio64 only */
323#define ECR_DEST_Y__AX_STEP 0x8AE8
324#define ECR_DEST_Y2__AX_STEP2 0x8AEA /* Trio64 only */
325#define ECR_DEST_X__DIA_STEP 0x8EE8
326#define ECR_DEST_X2__DIA_STEP2 0x8EEA /* Trio64 only */
327#define ECR_ERR_TERM 0x92E8
328#define ECR_ERR_TERM2 0x92EA /* Trio64 only */
329#define ECR_MAJ_AXIS_PIX_CNT 0x96E8
330#define ECR_MAJ_AXIS_PIX_CNT2 0x96EA /* Trio64 only */
331#define ECR_GP_STAT 0x9AE8 /* GP = Graphics Processor */
332#define ECR_DRAW_CMD 0x9AE8
333#define ECR_DRAW_CMD2 0x9AEA /* Trio64 only */
334#define ECR_SHORT_STROKE 0x9EE8
335#define ECR_BKGD_COLOR 0xA2E8 /* BKGD = Background */
336#define ECR_FRGD_COLOR 0xA6E8 /* FRGD = Foreground */
337#define ECR_BITPLANE_WRITE_MASK 0xAAE8
338#define ECR_BITPLANE_READ_MASK 0xAEE8
339#define ECR_COLOR_COMPARE 0xB2E8
340#define ECR_BKGD_MIX 0xB6E8
341#define ECR_FRGD_MIX 0xBAE8
342#define ECR_READ_REG_DATA 0xBEE8
343#define ECR_ID_MIN_AXIS_PIX_CNT 0x00
344#define ECR_ID_SCISSORS_TOP 0x01
345#define ECR_ID_SCISSORS_LEFT 0x02
346#define ECR_ID_SCISSORS_BUTTOM 0x03
347#define ECR_ID_SCISSORS_RIGHT 0x04
348#define ECR_ID_PIX_CNTL 0x0A
349#define ECR_ID_MULT_CNTL_MISC_2 0x0D
350#define ECR_ID_MULT_CNTL_MISC 0x0E
351#define ECR_ID_READ_SEL 0x0F
352#define ECR_PIX_TRANS 0xE2E8
353#define ECR_PIX_TRANS_EXT 0xE2EA
354#define ECR_PATTERN_Y 0xEAE8 /* Trio64 only */
355#define ECR_PATTERN_X 0xEAEA /* Trio64 only */
356
357
358/* Pass-through */
359#define PASS_ADDRESS 0x40001
360#define PASS_ADDRESS_W 0x40001
361
362/* Video DAC */
363#define VDAC_ADDRESS 0x03c8
364#define VDAC_ADDRESS_W 0x03c8
365#define VDAC_ADDRESS_R 0x03c7
366#define VDAC_STATE 0x03c7
367#define VDAC_DATA 0x03c9
368#define VDAC_MASK 0x03c6
369
370
371#define WGfx(ba, idx, val) \
372do { wb_64(ba, GCT_ADDRESS, idx); wb_64(ba, GCT_ADDRESS_W , val); } while (0)
373
374#define WSeq(ba, idx, val) \
375do { wb_64(ba, SEQ_ADDRESS, idx); wb_64(ba, SEQ_ADDRESS_W , val); } while (0)
376
377#define WCrt(ba, idx, val) \
378do { wb_64(ba, CRT_ADDRESS, idx); wb_64(ba, CRT_ADDRESS_W , val); } while (0)
379
380#define WAttr(ba, idx, val) \
381do { \
382 unsigned char tmp;\
383 tmp = rb_64(ba, ACT_ADDRESS_RESET);\
384 wb_64(ba, ACT_ADDRESS_W, idx);\
385 wb_64(ba, ACT_ADDRESS_W, val);\
386} while (0)
387
388#define SetTextPlane(ba, m) \
389do { \
390 WGfx(ba, GCT_ID_READ_MAP_SELECT, m & 3 );\
391 WSeq(ba, SEQ_ID_MAP_MASK, (1 << (m & 3)));\
392} while (0)
393
394 /* --------------------------------- */
395 /* prototypes */
396 /* --------------------------------- */
397
398inline unsigned char RAttr(volatile unsigned char * board, short idx);
399inline unsigned char RSeq(volatile unsigned char * board, short idx);
400inline unsigned char RCrt(volatile unsigned char * board, short idx);
401inline unsigned char RGfx(volatile unsigned char * board, short idx);
402inline void cv64_write_port(unsigned short bits,
403 volatile unsigned char *board);
404inline void cvscreen(int toggle, volatile unsigned char *board);
405inline void gfx_on_off(int toggle, volatile unsigned char *board);
406#if 0
407unsigned short cv64_compute_clock(unsigned long freq);
408int cv_has_4mb(volatile unsigned char * fb);
409void cv64_board_init(void);
410void cv64_load_video_mode(struct fb_var_screeninfo *video_mode);
411#endif
412
413void cvision_bitblt(u_short sx, u_short sy, u_short dx, u_short dy, u_short w,
414 u_short h);
415void cvision_clear(u_short dx, u_short dy, u_short w, u_short h, u_short bg);
diff --git a/drivers/video/fbsysfs.c b/drivers/video/fbsysfs.c
index 323bdf6fc7d..818fb09105f 100644
--- a/drivers/video/fbsysfs.c
+++ b/drivers/video/fbsysfs.c
@@ -175,7 +175,7 @@ static ssize_t store_modes(struct device *device,
175 175
176 acquire_console_sem(); 176 acquire_console_sem();
177 list_splice(&fb_info->modelist, &old_list); 177 list_splice(&fb_info->modelist, &old_list);
178 fb_videomode_to_modelist((struct fb_videomode *)buf, i, 178 fb_videomode_to_modelist((const struct fb_videomode *)buf, i,
179 &fb_info->modelist); 179 &fb_info->modelist);
180 if (fb_new_modelist(fb_info)) { 180 if (fb_new_modelist(fb_info)) {
181 fb_destroy_modelist(&fb_info->modelist); 181 fb_destroy_modelist(&fb_info->modelist);
diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
index bcf9cea54d8..bb20a228976 100644
--- a/drivers/video/geode/gx1fb_core.c
+++ b/drivers/video/geode/gx1fb_core.c
@@ -401,6 +401,30 @@ static void gx1fb_remove(struct pci_dev *pdev)
401 framebuffer_release(info); 401 framebuffer_release(info);
402} 402}
403 403
404#ifndef MODULE
405static void __init gx1fb_setup(char *options)
406{
407 char *this_opt;
408
409 if (!options || !*options)
410 return;
411
412 while ((this_opt = strsep(&options, ","))) {
413 if (!*this_opt)
414 continue;
415
416 if (!strncmp(this_opt, "mode:", 5))
417 strlcpy(mode_option, this_opt + 5, sizeof(mode_option));
418 else if (!strncmp(this_opt, "crt:", 4))
419 crt_option = !!simple_strtoul(this_opt + 4, NULL, 0);
420 else if (!strncmp(this_opt, "panel:", 6))
421 strlcpy(panel_option, this_opt + 6, sizeof(panel_option));
422 else
423 strlcpy(mode_option, this_opt, sizeof(mode_option));
424 }
425}
426#endif
427
404static struct pci_device_id gx1fb_id_table[] = { 428static struct pci_device_id gx1fb_id_table[] = {
405 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_VIDEO, 429 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_VIDEO,
406 PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16, 430 PCI_ANY_ID, PCI_ANY_ID, PCI_BASE_CLASS_DISPLAY << 16,
@@ -420,8 +444,11 @@ static struct pci_driver gx1fb_driver = {
420static int __init gx1fb_init(void) 444static int __init gx1fb_init(void)
421{ 445{
422#ifndef MODULE 446#ifndef MODULE
423 if (fb_get_options("gx1fb", NULL)) 447 char *option = NULL;
448
449 if (fb_get_options("gx1fb", &option))
424 return -ENODEV; 450 return -ENODEV;
451 gx1fb_setup(option);
425#endif 452#endif
426 return pci_register_driver(&gx1fb_driver); 453 return pci_register_driver(&gx1fb_driver);
427} 454}
diff --git a/drivers/video/i810/i810.h b/drivers/video/i810/i810.h
index 579195c2bea..aa65ffce915 100644
--- a/drivers/video/i810/i810.h
+++ b/drivers/video/i810/i810.h
@@ -264,7 +264,8 @@ struct i810fb_par {
264 struct heap_data cursor_heap; 264 struct heap_data cursor_heap;
265 struct vgastate state; 265 struct vgastate state;
266 struct i810fb_i2c_chan chan[3]; 266 struct i810fb_i2c_chan chan[3];
267 atomic_t use_count; 267 struct mutex open_lock;
268 unsigned int use_count;
268 u32 pseudo_palette[17]; 269 u32 pseudo_palette[17];
269 unsigned long mmio_start_phys; 270 unsigned long mmio_start_phys;
270 u8 __iomem *mmio_start_virtual; 271 u8 __iomem *mmio_start_virtual;
diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
index b55a12d95eb..ab1b8fe34d6 100644
--- a/drivers/video/i810/i810_main.c
+++ b/drivers/video/i810/i810_main.c
@@ -1049,7 +1049,7 @@ static int i810_check_params(struct fb_var_screeninfo *var,
1049 mode_valid = 1; 1049 mode_valid = 1;
1050 1050
1051 if (!mode_valid && info->monspecs.modedb_len) { 1051 if (!mode_valid && info->monspecs.modedb_len) {
1052 struct fb_videomode *mode; 1052 const struct fb_videomode *mode;
1053 1053
1054 mode = fb_find_best_mode(var, &info->modelist); 1054 mode = fb_find_best_mode(var, &info->modelist);
1055 if (mode) { 1055 if (mode) {
@@ -1235,9 +1235,9 @@ static int i810fb_getcolreg(u8 regno, u8 *red, u8 *green, u8 *blue,
1235static int i810fb_open(struct fb_info *info, int user) 1235static int i810fb_open(struct fb_info *info, int user)
1236{ 1236{
1237 struct i810fb_par *par = info->par; 1237 struct i810fb_par *par = info->par;
1238 u32 count = atomic_read(&par->use_count); 1238
1239 1239 mutex_lock(&par->open_lock);
1240 if (count == 0) { 1240 if (par->use_count == 0) {
1241 memset(&par->state, 0, sizeof(struct vgastate)); 1241 memset(&par->state, 0, sizeof(struct vgastate));
1242 par->state.flags = VGA_SAVE_CMAP; 1242 par->state.flags = VGA_SAVE_CMAP;
1243 par->state.vgabase = par->mmio_start_virtual; 1243 par->state.vgabase = par->mmio_start_virtual;
@@ -1246,7 +1246,8 @@ static int i810fb_open(struct fb_info *info, int user)
1246 i810_save_vga_state(par); 1246 i810_save_vga_state(par);
1247 } 1247 }
1248 1248
1249 atomic_inc(&par->use_count); 1249 par->use_count++;
1250 mutex_unlock(&par->open_lock);
1250 1251
1251 return 0; 1252 return 0;
1252} 1253}
@@ -1254,18 +1255,20 @@ static int i810fb_open(struct fb_info *info, int user)
1254static int i810fb_release(struct fb_info *info, int user) 1255static int i810fb_release(struct fb_info *info, int user)
1255{ 1256{
1256 struct i810fb_par *par = info->par; 1257 struct i810fb_par *par = info->par;
1257 u32 count; 1258
1258 1259 mutex_lock(&par->open_lock);
1259 count = atomic_read(&par->use_count); 1260 if (par->use_count == 0) {
1260 if (count == 0) 1261 mutex_unlock(&par->open_lock);
1261 return -EINVAL; 1262 return -EINVAL;
1263 }
1262 1264
1263 if (count == 1) { 1265 if (par->use_count == 1) {
1264 i810_restore_vga_state(par); 1266 i810_restore_vga_state(par);
1265 restore_vga(&par->state); 1267 restore_vga(&par->state);
1266 } 1268 }
1267 1269
1268 atomic_dec(&par->use_count); 1270 par->use_count--;
1271 mutex_unlock(&par->open_lock);
1269 1272
1270 return 0; 1273 return 0;
1271} 1274}
@@ -1752,6 +1755,8 @@ static void __devinit i810_init_monspecs(struct fb_info *info)
1752static void __devinit i810_init_defaults(struct i810fb_par *par, 1755static void __devinit i810_init_defaults(struct i810fb_par *par,
1753 struct fb_info *info) 1756 struct fb_info *info)
1754{ 1757{
1758 mutex_init(&par->open_lock);
1759
1755 if (voffset) 1760 if (voffset)
1756 v_offset_default = voffset; 1761 v_offset_default = voffset;
1757 else if (par->aperture.size > 32 * 1024 * 1024) 1762 else if (par->aperture.size > 32 * 1024 * 1024)
@@ -1919,7 +1924,7 @@ static void __devinit i810fb_find_init_mode(struct fb_info *info)
1919 fb_videomode_to_modelist(specs->modedb, specs->modedb_len, 1924 fb_videomode_to_modelist(specs->modedb, specs->modedb_len,
1920 &info->modelist); 1925 &info->modelist);
1921 if (specs->modedb != NULL) { 1926 if (specs->modedb != NULL) {
1922 struct fb_videomode *m; 1927 const struct fb_videomode *m;
1923 1928
1924 if (xres && yres) { 1929 if (xres && yres) {
1925 if ((m = fb_find_best_mode(&var, &info->modelist))) { 1930 if ((m = fb_find_best_mode(&var, &info->modelist))) {
@@ -2016,11 +2021,10 @@ static int __devinit i810fb_init_pci (struct pci_dev *dev,
2016 par = info->par; 2021 par = info->par;
2017 par->dev = dev; 2022 par->dev = dev;
2018 2023
2019 if (!(info->pixmap.addr = kmalloc(8*1024, GFP_KERNEL))) { 2024 if (!(info->pixmap.addr = kzalloc(8*1024, GFP_KERNEL))) {
2020 i810fb_release_resource(info, par); 2025 i810fb_release_resource(info, par);
2021 return -ENOMEM; 2026 return -ENOMEM;
2022 } 2027 }
2023 memset(info->pixmap.addr, 0, 8*1024);
2024 info->pixmap.size = 8*1024; 2028 info->pixmap.size = 8*1024;
2025 info->pixmap.buf_align = 8; 2029 info->pixmap.buf_align = 8;
2026 info->pixmap.access_align = 32; 2030 info->pixmap.access_align = 32;
diff --git a/drivers/video/igafb.c b/drivers/video/igafb.c
index 655ae0fa99c..90592fb5915 100644
--- a/drivers/video/igafb.c
+++ b/drivers/video/igafb.c
@@ -370,7 +370,6 @@ static int __init iga_init(struct fb_info *info, struct iga_par *par)
370 370
371int __init igafb_init(void) 371int __init igafb_init(void)
372{ 372{
373 extern int con_is_present(void);
374 struct fb_info *info; 373 struct fb_info *info;
375 struct pci_dev *pdev; 374 struct pci_dev *pdev;
376 struct iga_par *par; 375 struct iga_par *par;
@@ -402,12 +401,11 @@ int __init igafb_init(void)
402 401
403 size = sizeof(struct fb_info) + sizeof(struct iga_par) + sizeof(u32)*16; 402 size = sizeof(struct fb_info) + sizeof(struct iga_par) + sizeof(u32)*16;
404 403
405 info = kmalloc(size, GFP_ATOMIC); 404 info = kzalloc(size, GFP_ATOMIC);
406 if (!info) { 405 if (!info) {
407 printk("igafb_init: can't alloc fb_info\n"); 406 printk("igafb_init: can't alloc fb_info\n");
408 return -ENOMEM; 407 return -ENOMEM;
409 } 408 }
410 memset(info, 0, size);
411 409
412 par = (struct iga_par *) (info + 1); 410 par = (struct iga_par *) (info + 1);
413 411
@@ -466,7 +464,7 @@ int __init igafb_init(void)
466 * one additional region with size == 0. 464 * one additional region with size == 0.
467 */ 465 */
468 466
469 par->mmap_map = kmalloc(4 * sizeof(*par->mmap_map), GFP_ATOMIC); 467 par->mmap_map = kzalloc(4 * sizeof(*par->mmap_map), GFP_ATOMIC);
470 if (!par->mmap_map) { 468 if (!par->mmap_map) {
471 printk("igafb_init: can't alloc mmap_map\n"); 469 printk("igafb_init: can't alloc mmap_map\n");
472 iounmap((void *)par->io_base); 470 iounmap((void *)par->io_base);
@@ -475,8 +473,6 @@ int __init igafb_init(void)
475 return -ENOMEM; 473 return -ENOMEM;
476 } 474 }
477 475
478 memset(par->mmap_map, 0, 4 * sizeof(*par->mmap_map));
479
480 /* 476 /*
481 * Set default vmode and cmode from PROM properties. 477 * Set default vmode and cmode from PROM properties.
482 */ 478 */
diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c
index 664fc5cf962..b75eda84858 100644
--- a/drivers/video/intelfb/intelfbdrv.c
+++ b/drivers/video/intelfb/intelfbdrv.c
@@ -540,12 +540,11 @@ intelfb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
540 dinfo->pdev = pdev; 540 dinfo->pdev = pdev;
541 541
542 /* Reserve pixmap space. */ 542 /* Reserve pixmap space. */
543 info->pixmap.addr = kmalloc(64 * 1024, GFP_KERNEL); 543 info->pixmap.addr = kzalloc(64 * 1024, GFP_KERNEL);
544 if (info->pixmap.addr == NULL) { 544 if (info->pixmap.addr == NULL) {
545 ERR_MSG("Cannot reserve pixmap memory.\n"); 545 ERR_MSG("Cannot reserve pixmap memory.\n");
546 goto err_out_pixmap; 546 goto err_out_pixmap;
547 } 547 }
548 memset(info->pixmap.addr, 0, 64 * 1024);
549 548
550 /* set early this option because it could be changed by tv encoder 549 /* set early this option because it could be changed by tv encoder
551 driver */ 550 driver */
diff --git a/drivers/video/matrox/i2c-matroxfb.c b/drivers/video/matrox/i2c-matroxfb.c
index fe28848e7b5..f64c4a0984c 100644
--- a/drivers/video/matrox/i2c-matroxfb.c
+++ b/drivers/video/matrox/i2c-matroxfb.c
@@ -146,7 +146,7 @@ static void* i2c_matroxfb_probe(struct matrox_fb_info* minfo) {
146 unsigned long flags; 146 unsigned long flags;
147 struct matroxfb_dh_maven_info* m2info; 147 struct matroxfb_dh_maven_info* m2info;
148 148
149 m2info = kmalloc(sizeof(*m2info), GFP_KERNEL); 149 m2info = kzalloc(sizeof(*m2info), GFP_KERNEL);
150 if (!m2info) 150 if (!m2info)
151 return NULL; 151 return NULL;
152 152
@@ -155,8 +155,6 @@ static void* i2c_matroxfb_probe(struct matrox_fb_info* minfo) {
155 matroxfb_DAC_out(PMINFO DAC_XGENIOCTRL, 0x00); 155 matroxfb_DAC_out(PMINFO DAC_XGENIOCTRL, 0x00);
156 matroxfb_DAC_unlock_irqrestore(flags); 156 matroxfb_DAC_unlock_irqrestore(flags);
157 157
158 memset(m2info, 0, sizeof(*m2info));
159
160 switch (ACCESS_FBINFO(chip)) { 158 switch (ACCESS_FBINFO(chip)) {
161 case MGA_2064: 159 case MGA_2064:
162 case MGA_2164: 160 case MGA_2164:
diff --git a/drivers/video/matrox/matroxfb_crtc2.c b/drivers/video/matrox/matroxfb_crtc2.c
index 2c9801090fa..03ae55b168f 100644
--- a/drivers/video/matrox/matroxfb_crtc2.c
+++ b/drivers/video/matrox/matroxfb_crtc2.c
@@ -694,12 +694,11 @@ static void* matroxfb_crtc2_probe(struct matrox_fb_info* minfo) {
694 /* hardware is CRTC2 incapable... */ 694 /* hardware is CRTC2 incapable... */
695 if (!ACCESS_FBINFO(devflags.crtc2)) 695 if (!ACCESS_FBINFO(devflags.crtc2))
696 return NULL; 696 return NULL;
697 m2info = kmalloc(sizeof(*m2info), GFP_KERNEL); 697 m2info = kzalloc(sizeof(*m2info), GFP_KERNEL);
698 if (!m2info) { 698 if (!m2info) {
699 printk(KERN_ERR "matroxfb_crtc2: Not enough memory for CRTC2 control structs\n"); 699 printk(KERN_ERR "matroxfb_crtc2: Not enough memory for CRTC2 control structs\n");
700 return NULL; 700 return NULL;
701 } 701 }
702 memset(m2info, 0, sizeof(*m2info));
703 m2info->primary_dev = MINFO; 702 m2info->primary_dev = MINFO;
704 if (matroxfb_dh_registerfb(m2info)) { 703 if (matroxfb_dh_registerfb(m2info)) {
705 kfree(m2info); 704 kfree(m2info);
diff --git a/drivers/video/mbx/mbxdebugfs.c b/drivers/video/mbx/mbxdebugfs.c
index 472a3ca3d92..15b8b3c4330 100644
--- a/drivers/video/mbx/mbxdebugfs.c
+++ b/drivers/video/mbx/mbxdebugfs.c
@@ -170,37 +170,37 @@ static ssize_t misc_read_file(struct file *file, char __user *userbuf,
170} 170}
171 171
172 172
173static struct file_operations sysconf_fops = { 173static const struct file_operations sysconf_fops = {
174 .read = sysconf_read_file, 174 .read = sysconf_read_file,
175 .write = write_file_dummy, 175 .write = write_file_dummy,
176 .open = open_file_generic, 176 .open = open_file_generic,
177}; 177};
178 178
179static struct file_operations clock_fops = { 179static const struct file_operations clock_fops = {
180 .read = clock_read_file, 180 .read = clock_read_file,
181 .write = write_file_dummy, 181 .write = write_file_dummy,
182 .open = open_file_generic, 182 .open = open_file_generic,
183}; 183};
184 184
185static struct file_operations display_fops = { 185static const struct file_operations display_fops = {
186 .read = display_read_file, 186 .read = display_read_file,
187 .write = write_file_dummy, 187 .write = write_file_dummy,
188 .open = open_file_generic, 188 .open = open_file_generic,
189}; 189};
190 190
191static struct file_operations gsctl_fops = { 191static const struct file_operations gsctl_fops = {
192 .read = gsctl_read_file, 192 .read = gsctl_read_file,
193 .write = write_file_dummy, 193 .write = write_file_dummy,
194 .open = open_file_generic, 194 .open = open_file_generic,
195}; 195};
196 196
197static struct file_operations sdram_fops = { 197static const struct file_operations sdram_fops = {
198 .read = sdram_read_file, 198 .read = sdram_read_file,
199 .write = write_file_dummy, 199 .write = write_file_dummy,
200 .open = open_file_generic, 200 .open = open_file_generic,
201}; 201};
202 202
203static struct file_operations misc_fops = { 203static const struct file_operations misc_fops = {
204 .read = misc_read_file, 204 .read = misc_read_file,
205 .write = write_file_dummy, 205 .write = write_file_dummy,
206 .open = open_file_generic, 206 .open = open_file_generic,
diff --git a/drivers/video/modedb.c b/drivers/video/modedb.c
index 5df41f6f2b8..5162eab9553 100644
--- a/drivers/video/modedb.c
+++ b/drivers/video/modedb.c
@@ -610,10 +610,8 @@ done:
610 diff = refresh; 610 diff = refresh;
611 best = -1; 611 best = -1;
612 for (i = 0; i < dbsize; i++) { 612 for (i = 0; i < dbsize; i++) {
613 if ((name_matches(db[i], name, namelen) && 613 if (name_matches(db[i], name, namelen) ||
614 !fb_try_mode(var, info, &db[i], bpp))) 614 (res_specified && res_matches(db[i], xres, yres))) {
615 return 1;
616 if (res_specified && res_matches(db[i], xres, yres)) {
617 if(!fb_try_mode(var, info, &db[i], bpp)) { 615 if(!fb_try_mode(var, info, &db[i], bpp)) {
618 if(!refresh_specified || db[i].refresh == refresh) 616 if(!refresh_specified || db[i].refresh == refresh)
619 return 1; 617 return 1;
@@ -670,7 +668,7 @@ done:
670 * @var: pointer to struct fb_var_screeninfo 668 * @var: pointer to struct fb_var_screeninfo
671 */ 669 */
672void fb_var_to_videomode(struct fb_videomode *mode, 670void fb_var_to_videomode(struct fb_videomode *mode,
673 struct fb_var_screeninfo *var) 671 const struct fb_var_screeninfo *var)
674{ 672{
675 u32 pixclock, hfreq, htotal, vtotal; 673 u32 pixclock, hfreq, htotal, vtotal;
676 674
@@ -714,17 +712,21 @@ void fb_var_to_videomode(struct fb_videomode *mode,
714 * @mode: pointer to struct fb_videomode 712 * @mode: pointer to struct fb_videomode
715 */ 713 */
716void fb_videomode_to_var(struct fb_var_screeninfo *var, 714void fb_videomode_to_var(struct fb_var_screeninfo *var,
717 struct fb_videomode *mode) 715 const struct fb_videomode *mode)
718{ 716{
719 var->xres = mode->xres; 717 var->xres = mode->xres;
720 var->yres = mode->yres; 718 var->yres = mode->yres;
719 var->xres_virtual = mode->xres;
720 var->yres_virtual = mode->yres;
721 var->xoffset = 0;
722 var->yoffset = 0;
721 var->pixclock = mode->pixclock; 723 var->pixclock = mode->pixclock;
722 var->left_margin = mode->left_margin; 724 var->left_margin = mode->left_margin;
723 var->hsync_len = mode->hsync_len;
724 var->vsync_len = mode->vsync_len;
725 var->right_margin = mode->right_margin; 725 var->right_margin = mode->right_margin;
726 var->upper_margin = mode->upper_margin; 726 var->upper_margin = mode->upper_margin;
727 var->lower_margin = mode->lower_margin; 727 var->lower_margin = mode->lower_margin;
728 var->hsync_len = mode->hsync_len;
729 var->vsync_len = mode->vsync_len;
728 var->sync = mode->sync; 730 var->sync = mode->sync;
729 var->vmode = mode->vmode & FB_VMODE_MASK; 731 var->vmode = mode->vmode & FB_VMODE_MASK;
730} 732}
@@ -737,8 +739,8 @@ void fb_videomode_to_var(struct fb_var_screeninfo *var,
737 * RETURNS: 739 * RETURNS:
738 * 1 if equal, 0 if not 740 * 1 if equal, 0 if not
739 */ 741 */
740int fb_mode_is_equal(struct fb_videomode *mode1, 742int fb_mode_is_equal(const struct fb_videomode *mode1,
741 struct fb_videomode *mode2) 743 const struct fb_videomode *mode2)
742{ 744{
743 return (mode1->xres == mode2->xres && 745 return (mode1->xres == mode2->xres &&
744 mode1->yres == mode2->yres && 746 mode1->yres == mode2->yres &&
@@ -770,8 +772,8 @@ int fb_mode_is_equal(struct fb_videomode *mode1,
770 * var->xres and var->yres. If more than 1 videomode is found, will return 772 * var->xres and var->yres. If more than 1 videomode is found, will return
771 * the videomode with the highest refresh rate 773 * the videomode with the highest refresh rate
772 */ 774 */
773struct fb_videomode *fb_find_best_mode(struct fb_var_screeninfo *var, 775const struct fb_videomode *fb_find_best_mode(const struct fb_var_screeninfo *var,
774 struct list_head *head) 776 struct list_head *head)
775{ 777{
776 struct list_head *pos; 778 struct list_head *pos;
777 struct fb_modelist *modelist; 779 struct fb_modelist *modelist;
@@ -808,8 +810,8 @@ struct fb_videomode *fb_find_best_mode(struct fb_var_screeninfo *var,
808 * If more than 1 videomode is found, will return the videomode with 810 * If more than 1 videomode is found, will return the videomode with
809 * the closest refresh rate. 811 * the closest refresh rate.
810 */ 812 */
811struct fb_videomode *fb_find_nearest_mode(struct fb_videomode *mode, 813const struct fb_videomode *fb_find_nearest_mode(const struct fb_videomode *mode,
812 struct list_head *head) 814 struct list_head *head)
813{ 815{
814 struct list_head *pos; 816 struct list_head *pos;
815 struct fb_modelist *modelist; 817 struct fb_modelist *modelist;
@@ -847,8 +849,8 @@ struct fb_videomode *fb_find_nearest_mode(struct fb_videomode *mode,
847 * RETURNS: 849 * RETURNS:
848 * struct fb_videomode, NULL if none found 850 * struct fb_videomode, NULL if none found
849 */ 851 */
850struct fb_videomode *fb_match_mode(struct fb_var_screeninfo *var, 852const struct fb_videomode *fb_match_mode(const struct fb_var_screeninfo *var,
851 struct list_head *head) 853 struct list_head *head)
852{ 854{
853 struct list_head *pos; 855 struct list_head *pos;
854 struct fb_modelist *modelist; 856 struct fb_modelist *modelist;
@@ -872,7 +874,7 @@ struct fb_videomode *fb_match_mode(struct fb_var_screeninfo *var,
872 * NOTES: 874 * NOTES:
873 * Will only add unmatched mode entries 875 * Will only add unmatched mode entries
874 */ 876 */
875int fb_add_videomode(struct fb_videomode *mode, struct list_head *head) 877int fb_add_videomode(const struct fb_videomode *mode, struct list_head *head)
876{ 878{
877 struct list_head *pos; 879 struct list_head *pos;
878 struct fb_modelist *modelist; 880 struct fb_modelist *modelist;
@@ -907,7 +909,8 @@ int fb_add_videomode(struct fb_videomode *mode, struct list_head *head)
907 * NOTES: 909 * NOTES:
908 * Will remove all matching mode entries 910 * Will remove all matching mode entries
909 */ 911 */
910void fb_delete_videomode(struct fb_videomode *mode, struct list_head *head) 912void fb_delete_videomode(const struct fb_videomode *mode,
913 struct list_head *head)
911{ 914{
912 struct list_head *pos, *n; 915 struct list_head *pos, *n;
913 struct fb_modelist *modelist; 916 struct fb_modelist *modelist;
@@ -943,7 +946,7 @@ void fb_destroy_modelist(struct list_head *head)
943 * @num: number of entries in array 946 * @num: number of entries in array
944 * @head: struct list_head of modelist 947 * @head: struct list_head of modelist
945 */ 948 */
946void fb_videomode_to_modelist(struct fb_videomode *modedb, int num, 949void fb_videomode_to_modelist(const struct fb_videomode *modedb, int num,
947 struct list_head *head) 950 struct list_head *head)
948{ 951{
949 int i; 952 int i;
@@ -956,12 +959,12 @@ void fb_videomode_to_modelist(struct fb_videomode *modedb, int num,
956 } 959 }
957} 960}
958 961
959struct fb_videomode *fb_find_best_display(struct fb_monspecs *specs, 962const struct fb_videomode *fb_find_best_display(const struct fb_monspecs *specs,
960 struct list_head *head) 963 struct list_head *head)
961{ 964{
962 struct list_head *pos; 965 struct list_head *pos;
963 struct fb_modelist *modelist; 966 struct fb_modelist *modelist;
964 struct fb_videomode *m, *m1 = NULL, *md = NULL, *best = NULL; 967 const struct fb_videomode *m, *m1 = NULL, *md = NULL, *best = NULL;
965 int first = 0; 968 int first = 0;
966 969
967 if (!head->prev || !head->next || list_empty(head)) 970 if (!head->prev || !head->next || list_empty(head))
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index deaf820cb38..395ccedde9a 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -66,7 +66,6 @@
66#include <linux/init.h> 66#include <linux/init.h>
67#ifdef CONFIG_TOSHIBA 67#ifdef CONFIG_TOSHIBA
68#include <linux/toshiba.h> 68#include <linux/toshiba.h>
69extern int tosh_smm(SMMRegisters *regs);
70#endif 69#endif
71 70
72#include <asm/io.h> 71#include <asm/io.h>
@@ -557,14 +556,16 @@ static int
557neofb_open(struct fb_info *info, int user) 556neofb_open(struct fb_info *info, int user)
558{ 557{
559 struct neofb_par *par = info->par; 558 struct neofb_par *par = info->par;
560 int cnt = atomic_read(&par->ref_count);
561 559
562 if (!cnt) { 560 mutex_lock(&par->open_lock);
561 if (!par->ref_count) {
563 memset(&par->state, 0, sizeof(struct vgastate)); 562 memset(&par->state, 0, sizeof(struct vgastate));
564 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS; 563 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
565 save_vga(&par->state); 564 save_vga(&par->state);
566 } 565 }
567 atomic_inc(&par->ref_count); 566 par->ref_count++;
567 mutex_unlock(&par->open_lock);
568
568 return 0; 569 return 0;
569} 570}
570 571
@@ -572,14 +573,18 @@ static int
572neofb_release(struct fb_info *info, int user) 573neofb_release(struct fb_info *info, int user)
573{ 574{
574 struct neofb_par *par = info->par; 575 struct neofb_par *par = info->par;
575 int cnt = atomic_read(&par->ref_count);
576 576
577 if (!cnt) 577 mutex_lock(&par->open_lock);
578 if (!par->ref_count) {
579 mutex_unlock(&par->open_lock);
578 return -EINVAL; 580 return -EINVAL;
579 if (cnt == 1) { 581 }
582 if (par->ref_count == 1) {
580 restore_vga(&par->state); 583 restore_vga(&par->state);
581 } 584 }
582 atomic_dec(&par->ref_count); 585 par->ref_count--;
586 mutex_unlock(&par->open_lock);
587
583 return 0; 588 return 0;
584} 589}
585 590
@@ -2048,6 +2053,7 @@ static struct fb_info *__devinit neo_alloc_fb_info(struct pci_dev *dev, const st
2048 2053
2049 info->fix.accel = id->driver_data; 2054 info->fix.accel = id->driver_data;
2050 2055
2056 mutex_init(&par->open_lock);
2051 par->pci_burst = !nopciburst; 2057 par->pci_burst = !nopciburst;
2052 par->lcd_stretch = !nostretch; 2058 par->lcd_stretch = !nostretch;
2053 par->libretto = libretto; 2059 par->libretto = libretto;
diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
index 538e947610e..8e5b484db64 100644
--- a/drivers/video/nvidia/nvidia.c
+++ b/drivers/video/nvidia/nvidia.c
@@ -829,7 +829,7 @@ static int nvidiafb_check_var(struct fb_var_screeninfo *var,
829 } 829 }
830 830
831 if (!mode_valid) { 831 if (!mode_valid) {
832 struct fb_videomode *mode; 832 const struct fb_videomode *mode;
833 833
834 mode = fb_find_best_mode(var, &info->modelist); 834 mode = fb_find_best_mode(var, &info->modelist);
835 if (mode) { 835 if (mode) {
@@ -1046,10 +1046,10 @@ static int __devinit nvidia_set_fbinfo(struct fb_info *info)
1046 } 1046 }
1047 1047
1048 if (specs->modedb != NULL) { 1048 if (specs->modedb != NULL) {
1049 struct fb_videomode *modedb; 1049 const struct fb_videomode *mode;
1050 1050
1051 modedb = fb_find_best_display(specs, &info->modelist); 1051 mode = fb_find_best_display(specs, &info->modelist);
1052 fb_videomode_to_var(&nvidiafb_default_var, modedb); 1052 fb_videomode_to_var(&nvidiafb_default_var, mode);
1053 nvidiafb_default_var.bits_per_pixel = bpp; 1053 nvidiafb_default_var.bits_per_pixel = bpp;
1054 } else if (par->fpWidth && par->fpHeight) { 1054 } else if (par->fpWidth && par->fpHeight) {
1055 char buf[16]; 1055 char buf[16];
@@ -1205,13 +1205,11 @@ static int __devinit nvidiafb_probe(struct pci_dev *pd,
1205 par = info->par; 1205 par = info->par;
1206 par->pci_dev = pd; 1206 par->pci_dev = pd;
1207 1207
1208 info->pixmap.addr = kmalloc(8 * 1024, GFP_KERNEL); 1208 info->pixmap.addr = kzalloc(8 * 1024, GFP_KERNEL);
1209 1209
1210 if (info->pixmap.addr == NULL) 1210 if (info->pixmap.addr == NULL)
1211 goto err_out_kfree; 1211 goto err_out_kfree;
1212 1212
1213 memset(info->pixmap.addr, 0, 8 * 1024);
1214
1215 if (pci_enable_device(pd)) { 1213 if (pci_enable_device(pd)) {
1216 printk(KERN_ERR PFX "cannot enable PCI device\n"); 1214 printk(KERN_ERR PFX "cannot enable PCI device\n");
1217 goto err_out_enable; 1215 goto err_out_enable;
@@ -1347,7 +1345,7 @@ err_out:
1347 return -ENODEV; 1345 return -ENODEV;
1348} 1346}
1349 1347
1350static void __exit nvidiafb_remove(struct pci_dev *pd) 1348static void __devexit nvidiafb_remove(struct pci_dev *pd)
1351{ 1349{
1352 struct fb_info *info = pci_get_drvdata(pd); 1350 struct fb_info *info = pci_get_drvdata(pd);
1353 struct nvidia_par *par = info->par; 1351 struct nvidia_par *par = info->par;
@@ -1433,7 +1431,7 @@ static struct pci_driver nvidiafb_driver = {
1433 .probe = nvidiafb_probe, 1431 .probe = nvidiafb_probe,
1434 .suspend = nvidiafb_suspend, 1432 .suspend = nvidiafb_suspend,
1435 .resume = nvidiafb_resume, 1433 .resume = nvidiafb_resume,
1436 .remove = __exit_p(nvidiafb_remove), 1434 .remove = __devexit_p(nvidiafb_remove),
1437}; 1435};
1438 1436
1439/* ------------------------------------------------------------------------- * 1437/* ------------------------------------------------------------------------- *
diff --git a/drivers/video/pm3fb.c b/drivers/video/pm3fb.c
index 1d81ef47efd..bd787e80177 100644
--- a/drivers/video/pm3fb.c
+++ b/drivers/video/pm3fb.c
@@ -3299,14 +3299,12 @@ static void pm3fb_detect(void)
3299 fb_info[i].dev = NULL; 3299 fb_info[i].dev = NULL;
3300 } 3300 }
3301 3301
3302 dev = 3302 dev = pci_get_device(PCI_VENDOR_ID_3DLABS,
3303 pci_find_device(PCI_VENDOR_ID_3DLABS,
3304 PCI_DEVICE_ID_3DLABS_PERMEDIA3, dev); 3303 PCI_DEVICE_ID_3DLABS_PERMEDIA3, dev);
3305 3304
3306 for (i = 0; ((i < PM3_MAX_BOARD) && dev); i++) { 3305 for (i = 0; ((i < PM3_MAX_BOARD) && dev); i++) {
3307 dev_array[i] = dev; 3306 dev_array[i] = dev;
3308 dev = 3307 dev = pci_get_device(PCI_VENDOR_ID_3DLABS,
3309 pci_find_device(PCI_VENDOR_ID_3DLABS,
3310 PCI_DEVICE_ID_3DLABS_PERMEDIA3, dev); 3308 PCI_DEVICE_ID_3DLABS_PERMEDIA3, dev);
3311 } 3309 }
3312 3310
@@ -3353,7 +3351,7 @@ static void pm3fb_detect(void)
3353 /* now, initialize... or not */ 3351 /* now, initialize... or not */
3354 for (i = 0; i < PM3_MAX_BOARD; i++) { 3352 for (i = 0; i < PM3_MAX_BOARD; i++) {
3355 l_fb_info = &(fb_info[i]); 3353 l_fb_info = &(fb_info[i]);
3356 if ((l_fb_info->dev) && (!disable[i])) { /* PCI device was found and not disabled by user */ 3354 if (l_fb_info->dev && !disable[i]) { /* PCI device was found and not disabled by user */
3357 DPRINTK(2, 3355 DPRINTK(2,
3358 "found @%lx Vendor %lx Device %lx ; base @ : %lx - %lx - %lx - %lx - %lx - %lx, irq %ld\n", 3356 "found @%lx Vendor %lx Device %lx ; base @ : %lx - %lx - %lx - %lx - %lx - %lx, irq %ld\n",
3359 (unsigned long) l_fb_info->dev, 3357 (unsigned long) l_fb_info->dev,
@@ -3608,7 +3606,7 @@ int init_module(void)
3608 3606
3609 pm3fb_init(); 3607 pm3fb_init();
3610 3608
3611 return (0); 3609 return 0;
3612} 3610}
3613 3611
3614void cleanup_module(void) 3612void cleanup_module(void)
@@ -3619,23 +3617,18 @@ void cleanup_module(void)
3619 struct pm3fb_info *l_fb_info; 3617 struct pm3fb_info *l_fb_info;
3620 for (i = 0; i < PM3_MAX_BOARD; i++) { 3618 for (i = 0; i < PM3_MAX_BOARD; i++) {
3621 l_fb_info = &(fb_info[i]); 3619 l_fb_info = &(fb_info[i]);
3622 if ((l_fb_info->dev != NULL) 3620 pci_dev_put(l_fb_info->dev);
3623 && (!(disable[l_fb_info->board_num]))) { 3621 if (l_fb_info->dev != NULL && !(disable[l_fb_info->board_num])) {
3624 if (l_fb_info->vIOBase != 3622 if (l_fb_info->vIOBase != (unsigned char *) -1) {
3625 (unsigned char *) -1) {
3626 pm3fb_unmapIO(l_fb_info); 3623 pm3fb_unmapIO(l_fb_info);
3627 release_mem_region(l_fb_info->p_fb, 3624 release_mem_region(l_fb_info->p_fb,
3628 l_fb_info-> 3625 l_fb_info->fb_size);
3629 fb_size); 3626 release_mem_region(l_fb_info->pIOBase,
3630 release_mem_region(l_fb_info-> 3627 PM3_REGS_SIZE);
3631 pIOBase,
3632 PM3_REGS_SIZE);
3633 } 3628 }
3634 unregister_framebuffer(&l_fb_info->gen. 3629 unregister_framebuffer(&l_fb_info->gen.info);
3635 info);
3636 } 3630 }
3637 } 3631 }
3638 } 3632 }
3639 return;
3640} 3633}
3641#endif /* MODULE */ 3634#endif /* MODULE */
diff --git a/drivers/video/ps3fb.c b/drivers/video/ps3fb.c
new file mode 100644
index 00000000000..81e43cda7d8
--- /dev/null
+++ b/drivers/video/ps3fb.c
@@ -0,0 +1,1229 @@
1/*
2 * linux/drivers/video/ps3fb.c -- PS3 GPU frame buffer device
3 *
4 * Copyright (C) 2006 Sony Computer Entertainment Inc.
5 * Copyright 2006, 2007 Sony Corporation
6 *
7 * This file is based on :
8 *
9 * linux/drivers/video/vfb.c -- Virtual frame buffer device
10 *
11 * Copyright (C) 2002 James Simmons
12 *
13 * Copyright (C) 1997 Geert Uytterhoeven
14 *
15 * 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
17 * more details.
18 */
19
20#include <linux/module.h>
21#include <linux/kernel.h>
22#include <linux/errno.h>
23#include <linux/string.h>
24#include <linux/mm.h>
25#include <linux/tty.h>
26#include <linux/slab.h>
27#include <linux/vmalloc.h>
28#include <linux/delay.h>
29#include <linux/interrupt.h>
30#include <linux/platform_device.h>
31#include <linux/console.h>
32#include <linux/ioctl.h>
33#include <linux/notifier.h>
34#include <linux/reboot.h>
35
36#include <asm/uaccess.h>
37#include <linux/fb.h>
38#include <linux/init.h>
39#include <asm/time.h>
40
41#include <asm/abs_addr.h>
42#include <asm/lv1call.h>
43#include <asm/ps3av.h>
44#include <asm/ps3fb.h>
45#include <asm/ps3.h>
46
47#ifdef PS3FB_DEBUG
48#define DPRINTK(fmt, args...) printk("%s: " fmt, __FUNCTION__ , ##args)
49#else
50#define DPRINTK(fmt, args...)
51#endif
52
53#define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC 0x101
54#define L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP 0x102
55#define L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP 0x600
56#define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT 0x601
57#define L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT_SYNC 0x602
58
59#define L1GPU_FB_BLIT_WAIT_FOR_COMPLETION (1ULL << 32)
60
61#define L1GPU_DISPLAY_SYNC_HSYNC 1
62#define L1GPU_DISPLAY_SYNC_VSYNC 2
63
64#define DDR_SIZE (0) /* used no ddr */
65#define GPU_OFFSET (64 * 1024)
66#define GPU_IOIF (0x0d000000UL)
67
68#define PS3FB_FULL_MODE_BIT 0x80
69
70#define GPU_INTR_STATUS_VSYNC_0 0 /* vsync on head A */
71#define GPU_INTR_STATUS_VSYNC_1 1 /* vsync on head B */
72#define GPU_INTR_STATUS_FLIP_0 3 /* flip head A */
73#define GPU_INTR_STATUS_FLIP_1 4 /* flip head B */
74#define GPU_INTR_STATUS_QUEUE_0 5 /* queue head A */
75#define GPU_INTR_STATUS_QUEUE_1 6 /* queue head B */
76
77#define GPU_DRIVER_INFO_VERSION 0x211
78
79/* gpu internals */
80struct display_head {
81 u64 be_time_stamp;
82 u32 status;
83 u32 offset;
84 u32 res1;
85 u32 res2;
86 u32 field;
87 u32 reserved1;
88
89 u64 res3;
90 u32 raster;
91
92 u64 vblank_count;
93 u32 field_vsync;
94 u32 reserved2;
95};
96
97struct gpu_irq {
98 u32 irq_outlet;
99 u32 status;
100 u32 mask;
101 u32 video_cause;
102 u32 graph_cause;
103 u32 user_cause;
104
105 u32 res1;
106 u64 res2;
107
108 u32 reserved[4];
109};
110
111struct gpu_driver_info {
112 u32 version_driver;
113 u32 version_gpu;
114 u32 memory_size;
115 u32 hardware_channel;
116
117 u32 nvcore_frequency;
118 u32 memory_frequency;
119
120 u32 reserved[1063];
121 struct display_head display_head[8];
122 struct gpu_irq irq;
123};
124
125struct ps3fb_priv {
126 unsigned int irq_no;
127 void *dev;
128
129 u64 context_handle, memory_handle;
130 void *xdr_ea;
131 struct gpu_driver_info *dinfo;
132 struct semaphore sem;
133 u32 res_index;
134
135 u64 vblank_count; /* frame count */
136 wait_queue_head_t wait_vsync;
137
138 u32 num_frames; /* num of frame buffers */
139 atomic_t ext_flip; /* on/off flip with vsync */
140 atomic_t f_count; /* fb_open count */
141 int is_blanked;
142};
143static struct ps3fb_priv ps3fb;
144
145struct ps3fb_res_table {
146 u32 xres;
147 u32 yres;
148 u32 xoff;
149 u32 yoff;
150 u32 type;
151};
152#define PS3FB_RES_FULL 1
153static const struct ps3fb_res_table ps3fb_res[] = {
154 /* res_x,y margin_x,y full */
155 { 720, 480, 72, 48 , 0},
156 { 720, 576, 72, 58 , 0},
157 { 1280, 720, 78, 38 , 0},
158 { 1920, 1080, 116, 58 , 0},
159 /* full mode */
160 { 720, 480, 0, 0 , PS3FB_RES_FULL},
161 { 720, 576, 0, 0 , PS3FB_RES_FULL},
162 { 1280, 720, 0, 0 , PS3FB_RES_FULL},
163 { 1920, 1080, 0, 0 , PS3FB_RES_FULL},
164 /* vesa: normally full mode */
165 { 1280, 768, 0, 0 , 0},
166 { 1280, 1024, 0, 0 , 0},
167 { 1920, 1200, 0, 0 , 0},
168 { 0, 0, 0, 0 , 0} };
169
170/* default resolution */
171#define GPU_RES_INDEX 0 /* 720 x 480 */
172
173static const struct fb_videomode ps3fb_modedb[] = {
174 /* 60 Hz broadcast modes (modes "1" to "5") */
175 {
176 /* 480i */
177 "480i", 60, 576, 384, 74074, 130, 89, 78, 57, 63, 6,
178 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
179 }, {
180 /* 480p */
181 "480p", 60, 576, 384, 37037, 130, 89, 78, 57, 63, 6,
182 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
183 }, {
184 /* 720p */
185 "720p", 60, 1124, 644, 13481, 298, 148, 57, 44, 80, 5,
186 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
187 }, {
188 /* 1080i */
189 "1080i", 60, 1688, 964, 13481, 264, 160, 94, 62, 88, 5,
190 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
191 }, {
192 /* 1080p */
193 "1080p", 60, 1688, 964, 6741, 264, 160, 94, 62, 88, 5,
194 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
195 },
196
197 /* 50 Hz broadcast modes (modes "6" to "10") */
198 {
199 /* 576i */
200 "576i", 50, 576, 460, 74074, 142, 83, 97, 63, 63, 5,
201 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
202 }, {
203 /* 576p */
204 "576p", 50, 576, 460, 37037, 142, 83, 97, 63, 63, 5,
205 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
206 }, {
207 /* 720p */
208 "720p", 50, 1124, 644, 13468, 298, 478, 57, 44, 80, 5,
209 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
210 }, {
211 /* 1080 */
212 "1080i", 50, 1688, 964, 13468, 264, 600, 94, 62, 88, 5,
213 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
214 }, {
215 /* 1080p */
216 "1080p", 50, 1688, 964, 6734, 264, 600, 94, 62, 88, 5,
217 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
218 },
219
220 /* VESA modes (modes "11" to "13") */
221 {
222 /* WXGA */
223 "wxga", 60, 1280, 768, 12924, 160, 24, 29, 3, 136, 6,
224 0, FB_VMODE_NONINTERLACED,
225 FB_MODE_IS_VESA
226 }, {
227 /* SXGA */
228 "sxga", 60, 1280, 1024, 9259, 248, 48, 38, 1, 112, 3,
229 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED,
230 FB_MODE_IS_VESA
231 }, {
232 /* WUXGA */
233 "wuxga", 60, 1920, 1200, 6494, 80, 48, 26, 3, 32, 6,
234 FB_SYNC_HOR_HIGH_ACT, FB_VMODE_NONINTERLACED,
235 FB_MODE_IS_VESA
236 },
237
238 /* 60 Hz broadcast modes (full resolution versions of modes "1" to "5") */
239 {
240 /* 480if */
241 "480if", 60, 720, 480, 74074, 58, 17, 30, 9, 63, 6,
242 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
243 }, {
244 /* 480pf */
245 "480pf", 60, 720, 480, 37037, 58, 17, 30, 9, 63, 6,
246 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
247 }, {
248 /* 720pf */
249 "720pf", 60, 1280, 720, 13481, 220, 70, 19, 6, 80, 5,
250 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
251 }, {
252 /* 1080if */
253 "1080if", 60, 1920, 1080, 13481, 148, 44, 36, 4, 88, 5,
254 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
255 }, {
256 /* 1080pf */
257 "1080pf", 60, 1920, 1080, 6741, 148, 44, 36, 4, 88, 5,
258 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
259 },
260
261 /* 50 Hz broadcast modes (full resolution versions of modes "6" to "10") */
262 {
263 /* 576if */
264 "576if", 50, 720, 576, 74074, 70, 11, 39, 5, 63, 5,
265 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
266 }, {
267 /* 576pf */
268 "576pf", 50, 720, 576, 37037, 70, 11, 39, 5, 63, 5,
269 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
270 }, {
271 /* 720pf */
272 "720pf", 50, 1280, 720, 13468, 220, 400, 19, 6, 80, 5,
273 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
274 }, {
275 /* 1080if */
276 "1080f", 50, 1920, 1080, 13468, 148, 484, 36, 4, 88, 5,
277 FB_SYNC_BROADCAST, FB_VMODE_INTERLACED
278 }, {
279 /* 1080pf */
280 "1080pf", 50, 1920, 1080, 6734, 148, 484, 36, 4, 88, 5,
281 FB_SYNC_BROADCAST, FB_VMODE_NONINTERLACED
282 }
283};
284
285
286#define HEAD_A
287#define HEAD_B
288
289#define X_OFF(i) (ps3fb_res[i].xoff) /* left/right margin (pixel) */
290#define Y_OFF(i) (ps3fb_res[i].yoff) /* top/bottom margin (pixel) */
291#define WIDTH(i) (ps3fb_res[i].xres) /* width of FB */
292#define HEIGHT(i) (ps3fb_res[i].yres) /* height of FB */
293#define BPP 4 /* number of bytes per pixel */
294#define VP_OFF(i) (WIDTH(i) * Y_OFF(i) * BPP + X_OFF(i) * BPP)
295#define FB_OFF(i) (GPU_OFFSET - VP_OFF(i) % GPU_OFFSET)
296
297static int ps3fb_mode = 0;
298module_param(ps3fb_mode, bool, 0);
299
300static char *mode_option __initdata = NULL;
301
302
303static int ps3fb_get_res_table(u32 xres, u32 yres)
304{
305 int full_mode;
306 unsigned int i;
307 u32 x, y, f;
308
309 full_mode = (ps3fb_mode & PS3FB_FULL_MODE_BIT) ? PS3FB_RES_FULL : 0;
310 for (i = 0;; i++) {
311 x = ps3fb_res[i].xres;
312 y = ps3fb_res[i].yres;
313 f = ps3fb_res[i].type;
314
315 if (!x) {
316 DPRINTK("ERROR: ps3fb_get_res_table()\n");
317 return -1;
318 }
319
320 if (full_mode == PS3FB_RES_FULL && f != PS3FB_RES_FULL)
321 continue;
322
323 if (x == xres && (yres == 0 || y == yres))
324 break;
325
326 x = x - 2 * ps3fb_res[i].xoff;
327 y = y - 2 * ps3fb_res[i].yoff;
328 if (x == xres && (yres == 0 || y == yres))
329 break;
330 }
331 return i;
332}
333
334static unsigned int ps3fb_find_mode(const struct fb_var_screeninfo *var,
335 u32 *line_length)
336{
337 unsigned int i, mode;
338
339 for (i = 0; i < ARRAY_SIZE(ps3fb_modedb); i++)
340 if (var->xres == ps3fb_modedb[i].xres &&
341 var->yres == ps3fb_modedb[i].yres &&
342 var->pixclock == ps3fb_modedb[i].pixclock &&
343 var->hsync_len == ps3fb_modedb[i].hsync_len &&
344 var->vsync_len == ps3fb_modedb[i].vsync_len &&
345 var->left_margin == ps3fb_modedb[i].left_margin &&
346 var->right_margin == ps3fb_modedb[i].right_margin &&
347 var->upper_margin == ps3fb_modedb[i].upper_margin &&
348 var->lower_margin == ps3fb_modedb[i].lower_margin &&
349 var->sync == ps3fb_modedb[i].sync &&
350 (var->vmode & FB_VMODE_MASK) == ps3fb_modedb[i].vmode) {
351 /* Cropped broadcast modes use the full line_length */
352 *line_length =
353 ps3fb_modedb[i < 10 ? i + 13 : i].xres * 4;
354 /* Full broadcast modes have the full mode bit set */
355 mode = i > 12 ? (i - 12) | PS3FB_FULL_MODE_BIT : i + 1;
356
357 DPRINTK("ps3fb_find_mode: mode %u\n", mode);
358 return mode;
359 }
360
361 DPRINTK("ps3fb_find_mode: mode not found\n");
362 return 0;
363
364}
365
366static const struct fb_videomode *ps3fb_default_mode(void)
367{
368 u32 mode = ps3fb_mode & PS3AV_MODE_MASK;
369 u32 flags;
370
371 if (mode < 1 || mode > 13)
372 return NULL;
373
374 flags = ps3fb_mode & ~PS3AV_MODE_MASK;
375
376 if (mode <= 10 && flags & PS3FB_FULL_MODE_BIT) {
377 /* Full broadcast mode */
378 return &ps3fb_modedb[mode + 12];
379 }
380
381 return &ps3fb_modedb[mode - 1];
382}
383
384static int ps3fb_sync(u32 frame)
385{
386 int i, status;
387 u32 xres, yres;
388 u64 fb_ioif, offset;
389
390 i = ps3fb.res_index;
391 xres = ps3fb_res[i].xres;
392 yres = ps3fb_res[i].yres;
393
394 if (frame > ps3fb.num_frames - 1) {
395 printk(KERN_WARNING "%s: invalid frame number (%u)\n",
396 __FUNCTION__, frame);
397 return -EINVAL;
398 }
399 offset = xres * yres * BPP * frame;
400
401 fb_ioif = GPU_IOIF + FB_OFF(i) + offset;
402 status = lv1_gpu_context_attribute(ps3fb.context_handle,
403 L1GPU_CONTEXT_ATTRIBUTE_FB_BLIT,
404 offset, fb_ioif,
405 L1GPU_FB_BLIT_WAIT_FOR_COMPLETION |
406 (xres << 16) | yres,
407 xres * BPP); /* line_length */
408 if (status)
409 printk(KERN_ERR "%s: lv1_gpu_context_attribute FB_BLIT failed: %d\n",
410 __FUNCTION__, status);
411#ifdef HEAD_A
412 status = lv1_gpu_context_attribute(ps3fb.context_handle,
413 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
414 0, offset, 0, 0);
415 if (status)
416 printk(KERN_ERR "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
417 __FUNCTION__, status);
418#endif
419#ifdef HEAD_B
420 status = lv1_gpu_context_attribute(ps3fb.context_handle,
421 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_FLIP,
422 1, offset, 0, 0);
423 if (status)
424 printk(KERN_ERR "%s: lv1_gpu_context_attribute FLIP failed: %d\n",
425 __FUNCTION__, status);
426#endif
427 return 0;
428}
429
430
431static int ps3fb_open(struct fb_info *info, int user)
432{
433 atomic_inc(&ps3fb.f_count);
434 return 0;
435}
436
437static int ps3fb_release(struct fb_info *info, int user)
438{
439 if (atomic_dec_and_test(&ps3fb.f_count)) {
440 if (atomic_read(&ps3fb.ext_flip)) {
441 atomic_set(&ps3fb.ext_flip, 0);
442 ps3fb_sync(0); /* single buffer */
443 }
444 }
445 return 0;
446}
447
448 /*
449 * Setting the video mode has been split into two parts.
450 * First part, xxxfb_check_var, must not write anything
451 * to hardware, it should only verify and adjust var.
452 * This means it doesn't alter par but it does use hardware
453 * data from it to check this var.
454 */
455
456static int ps3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
457{
458 u32 line_length;
459 int mode;
460 int i;
461
462 DPRINTK("var->xres:%u info->var.xres:%u\n", var->xres, info->var.xres);
463 DPRINTK("var->yres:%u info->var.yres:%u\n", var->yres, info->var.yres);
464
465 /* FIXME For now we do exact matches only */
466 mode = ps3fb_find_mode(var, &line_length);
467 if (!mode)
468 return -EINVAL;
469
470 /*
471 * FB_VMODE_CONUPDATE and FB_VMODE_SMOOTH_XPAN are equal!
472 * as FB_VMODE_SMOOTH_XPAN is only used internally
473 */
474
475 if (var->vmode & FB_VMODE_CONUPDATE) {
476 var->vmode |= FB_VMODE_YWRAP;
477 var->xoffset = info->var.xoffset;
478 var->yoffset = info->var.yoffset;
479 }
480
481 /* Virtual screen and panning are not supported */
482 if (var->xres_virtual > var->xres || var->yres_virtual > var->yres ||
483 var->xoffset || var->yoffset) {
484 DPRINTK("Virtual screen and panning are not supported\n");
485 return -EINVAL;
486 }
487
488 var->xres_virtual = var->xres;
489 var->yres_virtual = var->yres;
490
491 /* We support ARGB8888 only */
492 if (var->bits_per_pixel > 32 || var->grayscale ||
493 var->red.offset > 16 || var->green.offset > 8 ||
494 var->blue.offset > 0 || var->transp.offset > 24 ||
495 var->red.length > 8 || var->green.length > 8 ||
496 var->blue.length > 8 || var->transp.length > 8 ||
497 var->red.msb_right || var->green.msb_right ||
498 var->blue.msb_right || var->transp.msb_right || var->nonstd) {
499 DPRINTK("We support ARGB8888 only\n");
500 return -EINVAL;
501 }
502
503 var->bits_per_pixel = 32;
504 var->red.offset = 16;
505 var->green.offset = 8;
506 var->blue.offset = 0;
507 var->transp.offset = 24;
508 var->red.length = 8;
509 var->green.length = 8;
510 var->blue.length = 8;
511 var->transp.length = 8;
512 var->red.msb_right = 0;
513 var->green.msb_right = 0;
514 var->blue.msb_right = 0;
515 var->transp.msb_right = 0;
516
517 /* Rotation is not supported */
518 if (var->rotate) {
519 DPRINTK("Rotation is not supported\n");
520 return -EINVAL;
521 }
522
523 /* Memory limit */
524 i = ps3fb_get_res_table(var->xres, var->yres);
525 if (ps3fb_res[i].xres*ps3fb_res[i].yres*BPP > ps3fb_videomemory.size) {
526 DPRINTK("Not enough memory\n");
527 return -ENOMEM;
528 }
529
530 var->height = -1;
531 var->width = -1;
532
533 return 0;
534}
535
536 /*
537 * This routine actually sets the video mode.
538 */
539
540static int ps3fb_set_par(struct fb_info *info)
541{
542 unsigned int mode;
543 int i;
544 unsigned long offset;
545 static int first = 1;
546
547 DPRINTK("xres:%d xv:%d yres:%d yv:%d clock:%d\n",
548 info->var.xres, info->var.xres_virtual,
549 info->var.yres, info->var.yres_virtual, info->var.pixclock);
550 i = ps3fb_get_res_table(info->var.xres, info->var.yres);
551 ps3fb.res_index = i;
552
553 mode = ps3fb_find_mode(&info->var, &info->fix.line_length);
554 if (!mode)
555 return -EINVAL;
556
557 offset = FB_OFF(i) + VP_OFF(i);
558 info->fix.smem_len = ps3fb_videomemory.size - offset;
559 info->screen_base = (char __iomem *)ps3fb.xdr_ea + offset;
560 memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
561
562 ps3fb.num_frames = ps3fb_videomemory.size/
563 (ps3fb_res[i].xres*ps3fb_res[i].yres*BPP);
564
565 /* Keep the special bits we cannot set using fb_var_screeninfo */
566 ps3fb_mode = (ps3fb_mode & ~PS3AV_MODE_MASK) | mode;
567
568 if (ps3av_set_video_mode(ps3fb_mode, first))
569 return -EINVAL;
570
571 first = 0;
572 return 0;
573}
574
575 /*
576 * Set a single color register. The values supplied are already
577 * rounded down to the hardware's capabilities (according to the
578 * entries in the var structure). Return != 0 for invalid regno.
579 */
580
581static int ps3fb_setcolreg(unsigned int regno, unsigned int red,
582 unsigned int green, unsigned int blue,
583 unsigned int transp, struct fb_info *info)
584{
585 if (regno >= 16)
586 return 1;
587
588 red >>= 8;
589 green >>= 8;
590 blue >>= 8;
591 transp >>= 8;
592
593 ((u32 *)info->pseudo_palette)[regno] = transp << 24 | red << 16 |
594 green << 8 | blue;
595 return 0;
596}
597
598 /*
599 * As we have a virtual frame buffer, we need our own mmap function
600 */
601
602static int ps3fb_mmap(struct fb_info *info, struct vm_area_struct *vma)
603{
604 unsigned long size, offset;
605 int i;
606
607 i = ps3fb_get_res_table(info->var.xres, info->var.yres);
608 if (i == -1)
609 return -EINVAL;
610
611 size = vma->vm_end - vma->vm_start;
612 offset = vma->vm_pgoff << PAGE_SHIFT;
613 if (offset + size > info->fix.smem_len)
614 return -EINVAL;
615
616 offset += info->fix.smem_start + FB_OFF(i) + VP_OFF(i);
617 if (remap_pfn_range(vma, vma->vm_start, offset >> PAGE_SHIFT,
618 size, vma->vm_page_prot))
619 return -EAGAIN;
620
621 printk(KERN_DEBUG "ps3fb: mmap framebuffer P(%lx)->V(%lx)\n", offset,
622 vma->vm_start);
623 return 0;
624}
625
626 /*
627 * Blank the display
628 */
629
630static int ps3fb_blank(int blank, struct fb_info *info)
631{
632 int retval;
633
634 DPRINTK("%s: blank:%d\n", __FUNCTION__, blank);
635 switch (blank) {
636 case FB_BLANK_POWERDOWN:
637 case FB_BLANK_HSYNC_SUSPEND:
638 case FB_BLANK_VSYNC_SUSPEND:
639 case FB_BLANK_NORMAL:
640 retval = ps3av_video_mute(1); /* mute on */
641 if (!retval)
642 ps3fb.is_blanked = 1;
643 break;
644
645 default: /* unblank */
646 retval = ps3av_video_mute(0); /* mute off */
647 if (!retval)
648 ps3fb.is_blanked = 0;
649 break;
650 }
651 return retval;
652}
653
654static int ps3fb_get_vblank(struct fb_vblank *vblank)
655{
656 memset(vblank, 0, sizeof(&vblank));
657 vblank->flags = FB_VBLANK_HAVE_VSYNC;
658 return 0;
659}
660
661int ps3fb_wait_for_vsync(u32 crtc)
662{
663 int ret;
664 u64 count;
665
666 count = ps3fb.vblank_count;
667 ret = wait_event_interruptible_timeout(ps3fb.wait_vsync,
668 count != ps3fb.vblank_count,
669 HZ / 10);
670 if (!ret)
671 return -ETIMEDOUT;
672
673 return 0;
674}
675
676EXPORT_SYMBOL_GPL(ps3fb_wait_for_vsync);
677
678void ps3fb_flip_ctl(int on)
679{
680 if (on) {
681 if (atomic_read(&ps3fb.ext_flip) > 0) {
682 atomic_dec(&ps3fb.ext_flip);
683 }
684 } else {
685 atomic_inc(&ps3fb.ext_flip);
686 }
687}
688
689EXPORT_SYMBOL_GPL(ps3fb_flip_ctl);
690
691 /*
692 * ioctl
693 */
694
695static int ps3fb_ioctl(struct fb_info *info, unsigned int cmd,
696 unsigned long arg)
697{
698 void __user *argp = (void __user *)arg;
699 u32 val, old_mode;
700 int retval = -EFAULT;
701
702 switch (cmd) {
703 case FBIOGET_VBLANK:
704 {
705 struct fb_vblank vblank;
706 DPRINTK("FBIOGET_VBLANK:\n");
707 retval = ps3fb_get_vblank(&vblank);
708 if (retval)
709 break;
710
711 if (copy_to_user(argp, &vblank, sizeof(vblank)))
712 retval = -EFAULT;
713 break;
714 }
715
716 case FBIO_WAITFORVSYNC:
717 {
718 u32 crt;
719 DPRINTK("FBIO_WAITFORVSYNC:\n");
720 if (get_user(crt, (u32 __user *) arg))
721 break;
722
723 retval = ps3fb_wait_for_vsync(crt);
724 break;
725 }
726
727 case PS3FB_IOCTL_SETMODE:
728 {
729 const struct fb_videomode *mode;
730 struct fb_var_screeninfo var;
731
732 if (copy_from_user(&val, argp, sizeof(val)))
733 break;
734
735 DPRINTK("PS3FB_IOCTL_SETMODE:%x\n", val);
736 retval = -EINVAL;
737 old_mode = ps3fb_mode;
738 ps3fb_mode = val;
739 mode = ps3fb_default_mode();
740 if (mode) {
741 var = info->var;
742 fb_videomode_to_var(&var, mode);
743 acquire_console_sem();
744 info->flags |= FBINFO_MISC_USEREVENT;
745 /* Force, in case only special bits changed */
746 var.activate |= FB_ACTIVATE_FORCE;
747 retval = fb_set_var(info, &var);
748 info->flags &= ~FBINFO_MISC_USEREVENT;
749 release_console_sem();
750 }
751 if (retval)
752 ps3fb_mode = old_mode;
753 break;
754 }
755
756 case PS3FB_IOCTL_GETMODE:
757 val = ps3av_get_mode();
758 DPRINTK("PS3FB_IOCTL_GETMODE:%x\n", val);
759 if (!copy_to_user(argp, &val, sizeof(val)))
760 retval = 0;
761 break;
762
763 case PS3FB_IOCTL_SCREENINFO:
764 {
765 struct ps3fb_ioctl_res res;
766 int i = ps3fb.res_index;
767 DPRINTK("PS3FB_IOCTL_SCREENINFO:\n");
768 res.xres = ps3fb_res[i].xres;
769 res.yres = ps3fb_res[i].yres;
770 res.xoff = ps3fb_res[i].xoff;
771 res.yoff = ps3fb_res[i].yoff;
772 res.num_frames = ps3fb.num_frames;
773 if (!copy_to_user(argp, &res, sizeof(res)))
774 retval = 0;
775 break;
776 }
777
778 case PS3FB_IOCTL_ON:
779 DPRINTK("PS3FB_IOCTL_ON:\n");
780 atomic_inc(&ps3fb.ext_flip);
781 retval = 0;
782 break;
783
784 case PS3FB_IOCTL_OFF:
785 DPRINTK("PS3FB_IOCTL_OFF:\n");
786 if (atomic_read(&ps3fb.ext_flip) > 0)
787 atomic_dec(&ps3fb.ext_flip);
788 retval = 0;
789 break;
790
791 case PS3FB_IOCTL_FSEL:
792 if (copy_from_user(&val, argp, sizeof(val)))
793 break;
794
795 DPRINTK("PS3FB_IOCTL_FSEL:%d\n", val);
796 retval = ps3fb_sync(val);
797 break;
798
799 default:
800 retval = -ENOIOCTLCMD;
801 break;
802 }
803 return retval;
804}
805
806static int ps3fbd(void *arg)
807{
808 daemonize("ps3fbd");
809 for (;;) {
810 down(&ps3fb.sem);
811 if (atomic_read(&ps3fb.ext_flip) == 0)
812 ps3fb_sync(0); /* single buffer */
813 }
814 return 0;
815}
816
817static irqreturn_t ps3fb_vsync_interrupt(int irq, void *ptr)
818{
819 u64 v1;
820 int status;
821 struct display_head *head = &ps3fb.dinfo->display_head[1];
822
823 status = lv1_gpu_context_intr(ps3fb.context_handle, &v1);
824 if (status) {
825 printk(KERN_ERR "%s: lv1_gpu_context_intr failed: %d\n",
826 __FUNCTION__, status);
827 return IRQ_NONE;
828 }
829
830 if (v1 & (1 << GPU_INTR_STATUS_VSYNC_1)) {
831 /* VSYNC */
832 ps3fb.vblank_count = head->vblank_count;
833 if (!ps3fb.is_blanked)
834 up(&ps3fb.sem);
835 wake_up_interruptible(&ps3fb.wait_vsync);
836 }
837
838 return IRQ_HANDLED;
839}
840
841#ifndef MODULE
842static int __init ps3fb_setup(char *options)
843{
844 char *this_opt;
845 int mode = 0;
846
847 if (!options || !*options)
848 return 0; /* no options */
849
850 while ((this_opt = strsep(&options, ",")) != NULL) {
851 if (!*this_opt)
852 continue;
853 if (!strncmp(this_opt, "mode:", 5))
854 mode = simple_strtoul(this_opt + 5, NULL, 0);
855 else
856 mode_option = this_opt;
857 }
858 return mode;
859}
860#endif /* MODULE */
861
862 /*
863 * Initialisation
864 */
865
866static void ps3fb_platform_release(struct device *device)
867{
868 /* This is called when the reference count goes to zero. */
869}
870
871static int ps3fb_vsync_settings(struct gpu_driver_info *dinfo, void *dev)
872{
873 int error;
874
875 DPRINTK("version_driver:%x\n", dinfo->version_driver);
876 DPRINTK("irq outlet:%x\n", dinfo->irq.irq_outlet);
877 DPRINTK("version_gpu:%x memory_size:%x ch:%x core_freq:%d mem_freq:%d\n",
878 dinfo->version_gpu, dinfo->memory_size, dinfo->hardware_channel,
879 dinfo->nvcore_frequency/1000000, dinfo->memory_frequency/1000000);
880
881 if (dinfo->version_driver != GPU_DRIVER_INFO_VERSION) {
882 printk(KERN_ERR "%s: version_driver err:%x\n", __FUNCTION__,
883 dinfo->version_driver);
884 return -EINVAL;
885 }
886
887 ps3fb.dev = dev;
888 error = ps3_alloc_irq(PS3_BINDING_CPU_ANY, dinfo->irq.irq_outlet,
889 &ps3fb.irq_no);
890 if (error) {
891 printk(KERN_ERR "%s: ps3_alloc_irq failed %d\n", __FUNCTION__,
892 error);
893 return error;
894 }
895
896 error = request_irq(ps3fb.irq_no, ps3fb_vsync_interrupt, IRQF_DISABLED,
897 "ps3fb vsync", ps3fb.dev);
898 if (error) {
899 printk(KERN_ERR "%s: request_irq failed %d\n", __FUNCTION__,
900 error);
901 ps3_free_irq(ps3fb.irq_no);
902 return error;
903 }
904
905 dinfo->irq.mask = (1 << GPU_INTR_STATUS_VSYNC_1) |
906 (1 << GPU_INTR_STATUS_FLIP_1);
907 return 0;
908}
909
910static int ps3fb_xdr_settings(u64 xdr_lpar)
911{
912 int status;
913
914 status = lv1_gpu_context_iomap(ps3fb.context_handle, GPU_IOIF,
915 xdr_lpar, ps3fb_videomemory.size, 0);
916 if (status) {
917 printk(KERN_ERR "%s: lv1_gpu_context_iomap failed: %d\n",
918 __FUNCTION__, status);
919 return -ENXIO;
920 }
921 DPRINTK("video:%p xdr_ea:%p ioif:%lx lpar:%lx phys:%lx size:%lx\n",
922 ps3fb_videomemory.address, ps3fb.xdr_ea, GPU_IOIF, xdr_lpar,
923 virt_to_abs(ps3fb.xdr_ea), ps3fb_videomemory.size);
924
925 status = lv1_gpu_context_attribute(ps3fb.context_handle,
926 L1GPU_CONTEXT_ATTRIBUTE_FB_SETUP,
927 xdr_lpar, ps3fb_videomemory.size,
928 GPU_IOIF, 0);
929 if (status) {
930 printk(KERN_ERR "%s: lv1_gpu_context_attribute FB_SETUP failed: %d\n",
931 __FUNCTION__, status);
932 return -ENXIO;
933 }
934 return 0;
935}
936
937static struct fb_ops ps3fb_ops = {
938 .fb_open = ps3fb_open,
939 .fb_release = ps3fb_release,
940 .fb_check_var = ps3fb_check_var,
941 .fb_set_par = ps3fb_set_par,
942 .fb_setcolreg = ps3fb_setcolreg,
943 .fb_fillrect = cfb_fillrect,
944 .fb_copyarea = cfb_copyarea,
945 .fb_imageblit = cfb_imageblit,
946 .fb_mmap = ps3fb_mmap,
947 .fb_blank = ps3fb_blank,
948 .fb_ioctl = ps3fb_ioctl,
949 .fb_compat_ioctl = ps3fb_ioctl
950};
951
952static struct fb_fix_screeninfo ps3fb_fix __initdata = {
953 .id = "PS3 FB",
954 .type = FB_TYPE_PACKED_PIXELS,
955 .visual = FB_VISUAL_TRUECOLOR,
956 .accel = FB_ACCEL_NONE,
957};
958
959static int __init ps3fb_probe(struct platform_device *dev)
960{
961 struct fb_info *info;
962 int retval = -ENOMEM;
963 u64 ddr_lpar = 0;
964 u64 lpar_dma_control = 0;
965 u64 lpar_driver_info = 0;
966 u64 lpar_reports = 0;
967 u64 lpar_reports_size = 0;
968 u64 xdr_lpar;
969 int status;
970 unsigned long offset;
971
972 /* get gpu context handle */
973 status = lv1_gpu_memory_allocate(DDR_SIZE, 0, 0, 0, 0,
974 &ps3fb.memory_handle, &ddr_lpar);
975 if (status) {
976 printk(KERN_ERR "%s: lv1_gpu_memory_allocate failed: %d\n",
977 __FUNCTION__, status);
978 goto err;
979 }
980 DPRINTK("ddr:lpar:0x%lx\n", ddr_lpar);
981
982 status = lv1_gpu_context_allocate(ps3fb.memory_handle, 0,
983 &ps3fb.context_handle,
984 &lpar_dma_control, &lpar_driver_info,
985 &lpar_reports, &lpar_reports_size);
986 if (status) {
987 printk(KERN_ERR "%s: lv1_gpu_context_attribute failed: %d\n",
988 __FUNCTION__, status);
989 goto err_gpu_memory_free;
990 }
991
992 /* vsync interrupt */
993 ps3fb.dinfo = ioremap(lpar_driver_info, 128 * 1024);
994 if (!ps3fb.dinfo) {
995 printk(KERN_ERR "%s: ioremap failed\n", __FUNCTION__);
996 goto err_gpu_context_free;
997 }
998
999 retval = ps3fb_vsync_settings(ps3fb.dinfo, dev);
1000 if (retval)
1001 goto err_iounmap_dinfo;
1002
1003 /* xdr frame buffer */
1004 ps3fb.xdr_ea = ps3fb_videomemory.address;
1005 xdr_lpar = ps3_mm_phys_to_lpar(__pa(ps3fb.xdr_ea));
1006 retval = ps3fb_xdr_settings(xdr_lpar);
1007 if (retval)
1008 goto err_free_irq;
1009
1010 /*
1011 * ps3fb must clear memory to prevent kernel info
1012 * leakage into userspace
1013 */
1014 memset(ps3fb.xdr_ea, 0, ps3fb_videomemory.size);
1015 info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
1016 if (!info)
1017 goto err_free_irq;
1018
1019 offset = FB_OFF(ps3fb.res_index) + VP_OFF(ps3fb.res_index);
1020 info->screen_base = (char __iomem *)ps3fb.xdr_ea + offset;
1021 info->fbops = &ps3fb_ops;
1022
1023 info->fix = ps3fb_fix;
1024 info->fix.smem_start = virt_to_abs(ps3fb.xdr_ea);
1025 info->fix.smem_len = ps3fb_videomemory.size - offset;
1026 info->pseudo_palette = info->par;
1027 info->par = NULL;
1028 info->flags = FBINFO_FLAG_DEFAULT;
1029
1030 retval = fb_alloc_cmap(&info->cmap, 256, 0);
1031 if (retval < 0)
1032 goto err_framebuffer_release;
1033
1034 if (!fb_find_mode(&info->var, info, mode_option, ps3fb_modedb,
1035 ARRAY_SIZE(ps3fb_modedb), ps3fb_default_mode(), 32)) {
1036 retval = -EINVAL;
1037 goto err_fb_dealloc;
1038 }
1039
1040 fb_videomode_to_modelist(ps3fb_modedb, ARRAY_SIZE(ps3fb_modedb),
1041 &info->modelist);
1042
1043 retval = register_framebuffer(info);
1044 if (retval < 0)
1045 goto err_fb_dealloc;
1046
1047 platform_set_drvdata(dev, info);
1048
1049 printk(KERN_INFO
1050 "fb%d: PS3 frame buffer device, using %ld KiB of video memory\n",
1051 info->node, ps3fb_videomemory.size >> 10);
1052
1053 kernel_thread(ps3fbd, info, CLONE_KERNEL);
1054 return 0;
1055
1056err_fb_dealloc:
1057 fb_dealloc_cmap(&info->cmap);
1058err_framebuffer_release:
1059 framebuffer_release(info);
1060err_free_irq:
1061 free_irq(ps3fb.irq_no, ps3fb.dev);
1062 ps3_free_irq(ps3fb.irq_no);
1063err_iounmap_dinfo:
1064 iounmap((u8 __iomem *)ps3fb.dinfo);
1065err_gpu_context_free:
1066 lv1_gpu_context_free(ps3fb.context_handle);
1067err_gpu_memory_free:
1068 lv1_gpu_memory_free(ps3fb.memory_handle);
1069err:
1070 return retval;
1071}
1072
1073static void ps3fb_shutdown(struct platform_device *dev)
1074{
1075 ps3fb_flip_ctl(0); /* flip off */
1076 ps3fb.dinfo->irq.mask = 0;
1077 free_irq(ps3fb.irq_no, ps3fb.dev);
1078 ps3_free_irq(ps3fb.irq_no);
1079 iounmap((u8 __iomem *)ps3fb.dinfo);
1080}
1081
1082void ps3fb_cleanup(void)
1083{
1084 int status;
1085
1086 if (ps3fb.irq_no) {
1087 free_irq(ps3fb.irq_no, ps3fb.dev);
1088 ps3_free_irq(ps3fb.irq_no);
1089 }
1090 iounmap((u8 __iomem *)ps3fb.dinfo);
1091
1092 status = lv1_gpu_context_free(ps3fb.context_handle);
1093 if (status)
1094 DPRINTK("lv1_gpu_context_free failed: %d\n", status);
1095
1096 status = lv1_gpu_memory_free(ps3fb.memory_handle);
1097 if (status)
1098 DPRINTK("lv1_gpu_memory_free failed: %d\n", status);
1099
1100 ps3av_dev_close();
1101}
1102
1103EXPORT_SYMBOL_GPL(ps3fb_cleanup);
1104
1105static int ps3fb_remove(struct platform_device *dev)
1106{
1107 struct fb_info *info = platform_get_drvdata(dev);
1108
1109 if (info) {
1110 unregister_framebuffer(info);
1111 fb_dealloc_cmap(&info->cmap);
1112 framebuffer_release(info);
1113 }
1114 ps3fb_cleanup();
1115 return 0;
1116}
1117
1118static struct platform_driver ps3fb_driver = {
1119 .probe = ps3fb_probe,
1120 .remove = ps3fb_remove,
1121 .shutdown = ps3fb_shutdown,
1122 .driver = { .name = "ps3fb" }
1123};
1124
1125static struct platform_device ps3fb_device = {
1126 .name = "ps3fb",
1127 .id = 0,
1128 .dev = { .release = ps3fb_platform_release }
1129};
1130
1131int ps3fb_set_sync(void)
1132{
1133 int status;
1134
1135#ifdef HEAD_A
1136 status = lv1_gpu_context_attribute(0x0,
1137 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1138 0, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1139 if (status) {
1140 printk(KERN_ERR "%s: lv1_gpu_context_attribute DISPLAY_SYNC failed: %d\n",
1141 __FUNCTION__, status);
1142 return -1;
1143 }
1144#endif
1145#ifdef HEAD_B
1146 status = lv1_gpu_context_attribute(0x0,
1147 L1GPU_CONTEXT_ATTRIBUTE_DISPLAY_SYNC,
1148 1, L1GPU_DISPLAY_SYNC_VSYNC, 0, 0);
1149
1150 if (status) {
1151 printk(KERN_ERR "%s: lv1_gpu_context_attribute DISPLAY_MODE failed: %d\n",
1152 __FUNCTION__, status);
1153 return -1;
1154 }
1155#endif
1156 return 0;
1157}
1158
1159EXPORT_SYMBOL_GPL(ps3fb_set_sync);
1160
1161static int __init ps3fb_init(void)
1162{
1163 int error;
1164#ifndef MODULE
1165 int mode;
1166 char *option = NULL;
1167
1168 if (fb_get_options("ps3fb", &option))
1169 goto err;
1170#endif
1171
1172 if (!ps3fb_videomemory.address)
1173 goto err;
1174
1175 error = ps3av_dev_open();
1176 if (error) {
1177 printk(KERN_ERR "%s: ps3av_dev_open failed\n", __FUNCTION__);
1178 goto err;
1179 }
1180
1181 ps3fb_mode = ps3av_get_mode();
1182 DPRINTK("ps3av_mode:%d\n", ps3fb_mode);
1183#ifndef MODULE
1184 mode = ps3fb_setup(option); /* check boot option */
1185 if (mode)
1186 ps3fb_mode = mode;
1187#endif
1188 if (ps3fb_mode > 0) {
1189 u32 xres, yres;
1190 ps3av_video_mode2res(ps3fb_mode, &xres, &yres);
1191 ps3fb.res_index = ps3fb_get_res_table(xres, yres);
1192 DPRINTK("res_index:%d\n", ps3fb.res_index);
1193 } else
1194 ps3fb.res_index = GPU_RES_INDEX;
1195
1196 atomic_set(&ps3fb.f_count, -1); /* fbcon opens ps3fb */
1197 atomic_set(&ps3fb.ext_flip, 0); /* for flip with vsync */
1198 init_MUTEX(&ps3fb.sem);
1199 init_waitqueue_head(&ps3fb.wait_vsync);
1200 ps3fb.num_frames = 1;
1201
1202 error = platform_driver_register(&ps3fb_driver);
1203 if (!error) {
1204 error = platform_device_register(&ps3fb_device);
1205 if (error)
1206 platform_driver_unregister(&ps3fb_driver);
1207 }
1208
1209 ps3fb_set_sync();
1210
1211 return error;
1212
1213err:
1214 return -ENXIO;
1215}
1216
1217module_init(ps3fb_init);
1218
1219#ifdef MODULE
1220static void __exit ps3fb_exit(void)
1221{
1222 platform_device_unregister(&ps3fb_device);
1223 platform_driver_unregister(&ps3fb_driver);
1224}
1225
1226module_exit(ps3fb_exit);
1227
1228MODULE_LICENSE("GPL");
1229#endif /* MODULE */
diff --git a/drivers/video/retz3fb.c b/drivers/video/retz3fb.c
deleted file mode 100644
index bc7ffc84e18..00000000000
--- a/drivers/video/retz3fb.c
+++ /dev/null
@@ -1,1588 +0,0 @@
1/*
2 * Linux/drivers/video/retz3fb.c -- RetinaZ3 frame buffer device
3 *
4 * Copyright (C) 1997 Jes Sorensen
5 *
6 * This file is based on the CyberVision64 frame buffer device and
7 * the generic Cirrus Logic driver.
8 *
9 * cyberfb.c: Copyright (C) 1996 Martin Apel,
10 * Geert Uytterhoeven
11 * clgen.c: Copyright (C) 1996 Frank Neumann
12 *
13 * History:
14 * - 22 Jan 97: Initial work
15 * - 14 Feb 97: Screen initialization works somewhat, still only
16 * 8-bit packed pixel is supported.
17 *
18 * This file is subject to the terms and conditions of the GNU General Public
19 * License. See the file COPYING in the main directory of this archive
20 * for more details.
21 */
22
23#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/errno.h>
26#include <linux/string.h>
27#include <linux/mm.h>
28#include <linux/slab.h>
29#include <linux/delay.h>
30#include <linux/fb.h>
31#include <linux/zorro.h>
32#include <linux/init.h>
33
34#include <asm/uaccess.h>
35#include <asm/system.h>
36#include <asm/irq.h>
37#include <asm/pgtable.h>
38#include <asm/io.h>
39
40#include <video/fbcon.h>
41#include <video/fbcon-cfb8.h>
42#include <video/fbcon-cfb16.h>
43
44#include "retz3fb.h"
45
46/* #define DEBUG if(1) */
47#define DEBUG if(0)
48
49/*
50 * Reserve space for one pattern line.
51 *
52 * For the time being we only support 4MB boards!
53 */
54
55#define PAT_MEM_SIZE 16*3
56#define PAT_MEM_OFF (4*1024*1024 - PAT_MEM_SIZE)
57
58struct retz3fb_par {
59 int xres;
60 int yres;
61 int xres_vir;
62 int yres_vir;
63 int xoffset;
64 int yoffset;
65 int bpp;
66
67 struct fb_bitfield red;
68 struct fb_bitfield green;
69 struct fb_bitfield blue;
70 struct fb_bitfield transp;
71
72 int pixclock;
73 int left_margin; /* time from sync to picture */
74 int right_margin; /* time from picture to sync */
75 int upper_margin; /* time from sync to picture */
76 int lower_margin;
77 int hsync_len; /* length of horizontal sync */
78 int vsync_len; /* length of vertical sync */
79 int vmode;
80
81 int accel;
82};
83
84struct display_data {
85 long h_total; /* Horizontal Total */
86 long h_sstart; /* Horizontal Sync Start */
87 long h_sstop; /* Horizontal Sync Stop */
88 long h_bstart; /* Horizontal Blank Start */
89 long h_bstop; /* Horizontal Blank Stop */
90 long h_dispend; /* Horizontal Display End */
91 long v_total; /* Vertical Total */
92 long v_sstart; /* Vertical Sync Start */
93 long v_sstop; /* Vertical Sync Stop */
94 long v_bstart; /* Vertical Blank Start */
95 long v_bstop; /* Vertical Blank Stop */
96 long v_dispend; /* Horizontal Display End */
97};
98
99struct retz3_fb_info {
100 struct fb_info info;
101 unsigned char *base;
102 unsigned char *fbmem;
103 unsigned long fbsize;
104 volatile unsigned char *regs;
105 unsigned long physfbmem;
106 unsigned long physregs;
107 int current_par_valid; /* set to 0 by memset */
108 int blitbusy;
109 struct display disp;
110 struct retz3fb_par current_par;
111 unsigned char color_table [256][3];
112};
113
114
115static char fontname[40] __initdata = { 0 };
116
117#define retz3info(info) ((struct retz3_fb_info *)(info))
118#define fbinfo(info) ((struct fb_info *)(info))
119
120
121/*
122 * Frame Buffer Name
123 */
124
125static char retz3fb_name[16] = "RetinaZ3";
126
127
128/*
129 * A small info on how to convert XFree86 timing values into fb
130 * timings - by Frank Neumann:
131 *
132An XFree86 mode line consists of the following fields:
133 "800x600" 50 800 856 976 1040 600 637 643 666
134 < name > DCF HR SH1 SH2 HFL VR SV1 SV2 VFL
135
136The fields in the fb_var_screeninfo structure are:
137 unsigned long pixclock; * pixel clock in ps (pico seconds) *
138 unsigned long left_margin; * time from sync to picture *
139 unsigned long right_margin; * time from picture to sync *
140 unsigned long upper_margin; * time from sync to picture *
141 unsigned long lower_margin;
142 unsigned long hsync_len; * length of horizontal sync *
143 unsigned long vsync_len; * length of vertical sync *
144
1451) Pixelclock:
146 xfree: in MHz
147 fb: In Picoseconds (ps)
148
149 pixclock = 1000000 / DCF
150
1512) horizontal timings:
152 left_margin = HFL - SH2
153 right_margin = SH1 - HR
154 hsync_len = SH2 - SH1
155
1563) vertical timings:
157 upper_margin = VFL - SV2
158 lower_margin = SV1 - VR
159 vsync_len = SV2 - SV1
160
161Good examples for VESA timings can be found in the XFree86 source tree,
162under "programs/Xserver/hw/xfree86/doc/modeDB.txt".
163*/
164
165/*
166 * Predefined Video Modes
167 */
168
169static struct {
170 const char *name;
171 struct fb_var_screeninfo var;
172} retz3fb_predefined[] __initdata = {
173 /*
174 * NB: it is very important to adjust the pixel-clock to the color-depth.
175 */
176
177 {
178 "640x480", { /* 640x480, 8 bpp */
179 640, 480, 640, 480, 0, 0, 8, 0,
180 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
181 0, 0, -1, -1, FB_ACCEL_NONE, 39722, 48, 16, 33, 10, 96, 2,
182 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED
183 }
184 },
185 /*
186 ModeLine "800x600" 36 800 824 896 1024 600 601 603 625
187 < name > DCF HR SH1 SH2 HFL VR SV1 SV2 VFL
188 */
189 {
190 "800x600", { /* 800x600, 8 bpp */
191 800, 600, 800, 600, 0, 0, 8, 0,
192 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
193 0, 0, -1, -1, FB_ACCELF_TEXT, 27778, 64, 24, 22, 1, 120, 2,
194 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
195 }
196 },
197 {
198 "800x600-60", { /* 800x600, 8 bpp */
199 800, 600, 800, 600, 0, 0, 8, 0,
200 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
201 0, 0, -1, -1, FB_ACCELF_TEXT, 25000, 88, 40, 23, 1, 128, 4,
202 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
203 }
204 },
205 {
206 "800x600-70", { /* 800x600, 8 bpp */
207 800, 600, 800, 600, 0, 0, 8, 0,
208 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
209 0, 0, -1, -1, FB_ACCELF_TEXT, 22272, 40, 24, 15, 9, 144, 12,
210 FB_SYNC_COMP_HIGH_ACT, FB_VMODE_NONINTERLACED
211 }
212 },
213 /*
214 ModeLine "1024x768i" 45 1024 1064 1224 1264 768 777 785 817 interlace
215 < name > DCF HR SH1 SH2 HFL VR SV1 SV2 VFL
216 */
217 {
218 "1024x768i", { /* 1024x768, 8 bpp, interlaced */
219 1024, 768, 1024, 768, 0, 0, 8, 0,
220 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
221 0, 0, -1, -1, FB_ACCELF_TEXT, 22222, 40, 40, 32, 9, 160, 8,
222 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_INTERLACED
223 }
224 },
225 {
226 "1024x768", {
227 1024, 768, 1024, 768, 0, 0, 8, 0,
228 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
229 0, 0, -1, -1, FB_ACCEL_NONE, 12500, 92, 112, 31, 2, 204, 4,
230 FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
231 }
232 },
233 {
234 "640x480-16", { /* 640x480, 16 bpp */
235 640, 480, 640, 480, 0, 0, 16, 0,
236 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
237 0, 0, -1, -1, 0, 38461/2, 28, 32, 12, 10, 96, 2,
238 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED
239 }
240 },
241 {
242 "640x480-24", { /* 640x480, 24 bpp */
243 640, 480, 640, 480, 0, 0, 24, 0,
244 {8, 8, 8}, {8, 8, 8}, {8, 8, 8}, {0, 0, 0},
245 0, 0, -1, -1, 0, 38461/3, 28, 32, 12, 10, 96, 2,
246 FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,FB_VMODE_NONINTERLACED
247 }
248 },
249};
250
251
252#define NUM_TOTAL_MODES ARRAY_SIZE(retz3fb_predefined)
253
254static struct fb_var_screeninfo retz3fb_default;
255
256static int z3fb_inverse = 0;
257static int z3fb_mode __initdata = 0;
258
259
260/*
261 * Interface used by the world
262 */
263
264int retz3fb_setup(char *options);
265
266static int retz3fb_get_fix(struct fb_fix_screeninfo *fix, int con,
267 struct fb_info *info);
268static int retz3fb_get_var(struct fb_var_screeninfo *var, int con,
269 struct fb_info *info);
270static int retz3fb_set_var(struct fb_var_screeninfo *var, int con,
271 struct fb_info *info);
272static int retz3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
273 struct fb_info *info);
274static int retz3fb_setcolreg(unsigned int regno, unsigned int red,
275 unsigned int green, unsigned int blue,
276 unsigned int transp, struct fb_info *info);
277static int retz3fb_blank(int blank, struct fb_info *info);
278
279
280/*
281 * Interface to the low level console driver
282 */
283
284int retz3fb_init(void);
285static int z3fb_switch(int con, struct fb_info *info);
286static int z3fb_updatevar(int con, struct fb_info *info);
287
288
289/*
290 * Text console acceleration
291 */
292
293#ifdef FBCON_HAS_CFB8
294static struct display_switch fbcon_retz3_8;
295#endif
296
297
298/*
299 * Accelerated Functions used by the low level console driver
300 */
301
302static void retz3_bitblt(struct display *p,
303 unsigned short curx, unsigned short cury, unsigned
304 short destx, unsigned short desty, unsigned short
305 width, unsigned short height, unsigned short cmd,
306 unsigned short mask);
307
308/*
309 * Hardware Specific Routines
310 */
311
312static int retz3_encode_fix(struct fb_info *info,
313 struct fb_fix_screeninfo *fix,
314 struct retz3fb_par *par);
315static int retz3_decode_var(struct fb_var_screeninfo *var,
316 struct retz3fb_par *par);
317static int retz3_encode_var(struct fb_var_screeninfo *var,
318 struct retz3fb_par *par);
319static int retz3_getcolreg(unsigned int regno, unsigned int *red,
320 unsigned int *green, unsigned int *blue,
321 unsigned int *transp, struct fb_info *info);
322
323/*
324 * Internal routines
325 */
326
327static void retz3fb_get_par(struct fb_info *info, struct retz3fb_par *par);
328static void retz3fb_set_par(struct fb_info *info, struct retz3fb_par *par);
329static int do_fb_set_var(struct fb_info *info,
330 struct fb_var_screeninfo *var, int isactive);
331static void retz3fb_set_disp(int con, struct fb_info *info);
332static int get_video_mode(const char *name);
333
334
335/* -------------------- Hardware specific routines ------------------------- */
336
337static unsigned short find_fq(unsigned int freq)
338{
339 unsigned long f;
340 long tmp;
341 long prev = 0x7fffffff;
342 long n2, n1 = 3;
343 unsigned long m;
344 unsigned short res = 0;
345
346 if (freq <= 31250000)
347 n2 = 3;
348 else if (freq <= 62500000)
349 n2 = 2;
350 else if (freq <= 125000000)
351 n2 = 1;
352 else if (freq <= 250000000)
353 n2 = 0;
354 else
355 return 0;
356
357
358 do {
359 f = freq >> (10 - n2);
360
361 m = (f * n1) / (14318180/1024);
362
363 if (m > 129)
364 break;
365
366 tmp = (((m * 14318180) >> n2) / n1) - freq;
367 if (tmp < 0)
368 tmp = -tmp;
369
370 if (tmp < prev) {
371 prev = tmp;
372 res = (((n2 << 5) | (n1-2)) << 8) | (m-2);
373 }
374
375 } while ( (++n1) <= 21);
376
377 return res;
378}
379
380
381static int retz3_set_video(struct fb_info *info,
382 struct fb_var_screeninfo *var,
383 struct retz3fb_par *par)
384{
385 volatile unsigned char *regs = retz3info(info)->regs;
386 unsigned int freq;
387
388 int xres, hfront, hsync, hback;
389 int yres, vfront, vsync, vback;
390 unsigned char tmp;
391 unsigned short best_freq;
392 struct display_data data;
393
394 short clocksel = 0; /* Apparantly this is always zero */
395
396 int bpp = var->bits_per_pixel;
397
398 /*
399 * XXX
400 */
401 if (bpp == 24)
402 return 0;
403
404 if ((bpp != 8) && (bpp != 16) && (bpp != 24))
405 return -EFAULT;
406
407 par->xoffset = 0;
408 par->yoffset = 0;
409
410 xres = var->xres * bpp / 4;
411 hfront = var->right_margin * bpp / 4;
412 hsync = var->hsync_len * bpp / 4;
413 hback = var->left_margin * bpp / 4;
414
415 if (var->vmode & FB_VMODE_DOUBLE)
416 {
417 yres = var->yres * 2;
418 vfront = var->lower_margin * 2;
419 vsync = var->vsync_len * 2;
420 vback = var->upper_margin * 2;
421 }
422 else if (var->vmode & FB_VMODE_INTERLACED)
423 {
424 yres = (var->yres + 1) / 2;
425 vfront = (var->lower_margin + 1) / 2;
426 vsync = (var->vsync_len + 1) / 2;
427 vback = (var->upper_margin + 1) / 2;
428 }
429 else
430 {
431 yres = var->yres; /* -1 ? */
432 vfront = var->lower_margin;
433 vsync = var->vsync_len;
434 vback = var->upper_margin;
435 }
436
437 data.h_total = (hback / 8) + (xres / 8)
438 + (hfront / 8) + (hsync / 8) - 1 /* + 1 */;
439 data.h_dispend = ((xres + bpp - 1)/ 8) - 1;
440 data.h_bstart = xres / 8 - 1 /* + 1 */;
441
442 data.h_bstop = data.h_total+1 + 2 + 1;
443 data.h_sstart = (xres / 8) + (hfront / 8) + 1;
444 data.h_sstop = (xres / 8) + (hfront / 8) + (hsync / 8) + 1;
445
446 data.v_total = yres + vfront + vsync + vback - 1;
447
448 data.v_dispend = yres - 1;
449 data.v_bstart = yres - 1;
450
451 data.v_bstop = data.v_total;
452 data.v_sstart = yres + vfront - 1 - 2;
453 data.v_sstop = yres + vfront + vsync - 1;
454
455#if 0 /* testing */
456
457 printk("HBS: %i\n", data.h_bstart);
458 printk("HSS: %i\n", data.h_sstart);
459 printk("HSE: %i\n", data.h_sstop);
460 printk("HBE: %i\n", data.h_bstop);
461 printk("HT: %i\n", data.h_total);
462
463 printk("hsync: %i\n", hsync);
464 printk("hfront: %i\n", hfront);
465 printk("hback: %i\n", hback);
466
467 printk("VBS: %i\n", data.v_bstart);
468 printk("VSS: %i\n", data.v_sstart);
469 printk("VSE: %i\n", data.v_sstop);
470 printk("VBE: %i\n", data.v_bstop);
471 printk("VT: %i\n", data.v_total);
472
473 printk("vsync: %i\n", vsync);
474 printk("vfront: %i\n", vfront);
475 printk("vback: %i\n", vback);
476#endif
477
478 if (data.v_total >= 1024)
479 printk(KERN_ERR "MAYDAY: v_total >= 1024; bailing out!\n");
480
481 reg_w(regs, GREG_MISC_OUTPUT_W, 0xe3 | ((clocksel & 3) * 0x04));
482 reg_w(regs, GREG_FEATURE_CONTROL_W, 0x00);
483
484 seq_w(regs, SEQ_RESET, 0x00);
485 seq_w(regs, SEQ_RESET, 0x03); /* reset sequencer logic */
486
487 /*
488 * CLOCKING_MODE bits:
489 * 2: This one is only set for certain text-modes, wonder if
490 * it may be for EGA-lines? (it was referred to as CLKDIV2)
491 * (The CL drivers sets it to 0x21 with the comment:
492 * FullBandwidth (video off) and 8/9 dot clock)
493 */
494 seq_w(regs, SEQ_CLOCKING_MODE, 0x01 | 0x00 /* 0x08 */);
495
496 seq_w(regs, SEQ_MAP_MASK, 0x0f); /* enable writing to plane 0-3 */
497 seq_w(regs, SEQ_CHAR_MAP_SELECT, 0x00); /* doesn't matter in gfx-mode */
498 seq_w(regs, SEQ_MEMORY_MODE, 0x06); /* CL driver says 0x0e for 256 col mode*/
499 seq_w(regs, SEQ_RESET, 0x01);
500 seq_w(regs, SEQ_RESET, 0x03);
501
502 seq_w(regs, SEQ_EXTENDED_ENABLE, 0x05);
503
504 seq_w(regs, SEQ_CURSOR_CONTROL, 0x00); /* disable cursor */
505 seq_w(regs, SEQ_PRIM_HOST_OFF_HI, 0x00);
506 seq_w(regs, SEQ_PRIM_HOST_OFF_HI, 0x00);
507 seq_w(regs, SEQ_LINEAR_0, 0x4a);
508 seq_w(regs, SEQ_LINEAR_1, 0x00);
509
510 seq_w(regs, SEQ_SEC_HOST_OFF_HI, 0x00);
511 seq_w(regs, SEQ_SEC_HOST_OFF_LO, 0x00);
512 seq_w(regs, SEQ_EXTENDED_MEM_ENA, 0x3 | 0x4 | 0x10 | 0x40);
513
514 /*
515 * The lower 4 bits (0-3) are used to set the font-width for
516 * text-mode - DON'T try to set this for gfx-mode.
517 */
518 seq_w(regs, SEQ_EXT_CLOCK_MODE, 0x10);
519 seq_w(regs, SEQ_EXT_VIDEO_ADDR, 0x03);
520
521 /*
522 * Extended Pixel Control:
523 * bit 0: text-mode=0, gfx-mode=1 (Graphics Byte ?)
524 * bit 1: (Packed/Nibble Pixel Format ?)
525 * bit 4-5: depth, 0=1-8bpp, 1=9-16bpp, 2=17-24bpp
526 */
527 seq_w(regs, SEQ_EXT_PIXEL_CNTL, 0x01 | (((bpp / 8) - 1) << 4));
528
529 seq_w(regs, SEQ_BUS_WIDTH_FEEDB, 0x04);
530 seq_w(regs, SEQ_COLOR_EXP_WFG, 0x01);
531 seq_w(regs, SEQ_COLOR_EXP_WBG, 0x00);
532 seq_w(regs, SEQ_EXT_RW_CONTROL, 0x00);
533 seq_w(regs, SEQ_MISC_FEATURE_SEL, (0x51 | (clocksel & 8)));
534 seq_w(regs, SEQ_COLOR_KEY_CNTL, 0x40);
535 seq_w(regs, SEQ_COLOR_KEY_MATCH0, 0x00);
536 seq_w(regs, SEQ_COLOR_KEY_MATCH1, 0x00);
537 seq_w(regs, SEQ_COLOR_KEY_MATCH2, 0x00);
538 seq_w(regs, SEQ_CRC_CONTROL, 0x00);
539 seq_w(regs, SEQ_PERF_SELECT, 0x10);
540 seq_w(regs, SEQ_ACM_APERTURE_1, 0x00);
541 seq_w(regs, SEQ_ACM_APERTURE_2, 0x30);
542 seq_w(regs, SEQ_ACM_APERTURE_3, 0x00);
543 seq_w(regs, SEQ_MEMORY_MAP_CNTL, 0x03);
544
545
546 /* unlock register CRT0..CRT7 */
547 crt_w(regs, CRT_END_VER_RETR, (data.v_sstop & 0x0f) | 0x20);
548
549 /* Zuerst zu schreibende Werte nur per printk ausgeben */
550 DEBUG printk("CRT_HOR_TOTAL: %ld\n", data.h_total);
551 crt_w(regs, CRT_HOR_TOTAL, data.h_total & 0xff);
552
553 DEBUG printk("CRT_HOR_DISP_ENA_END: %ld\n", data.h_dispend);
554 crt_w(regs, CRT_HOR_DISP_ENA_END, (data.h_dispend) & 0xff);
555
556 DEBUG printk("CRT_START_HOR_BLANK: %ld\n", data.h_bstart);
557 crt_w(regs, CRT_START_HOR_BLANK, data.h_bstart & 0xff);
558
559 DEBUG printk("CRT_END_HOR_BLANK: 128+%ld\n", data.h_bstop % 32);
560 crt_w(regs, CRT_END_HOR_BLANK, 0x80 | (data.h_bstop & 0x1f));
561
562 DEBUG printk("CRT_START_HOR_RETR: %ld\n", data.h_sstart);
563 crt_w(regs, CRT_START_HOR_RETR, data.h_sstart & 0xff);
564
565 tmp = (data.h_sstop & 0x1f);
566 if (data.h_bstop & 0x20)
567 tmp |= 0x80;
568 DEBUG printk("CRT_END_HOR_RETR: %d\n", tmp);
569 crt_w(regs, CRT_END_HOR_RETR, tmp);
570
571 DEBUG printk("CRT_VER_TOTAL: %ld\n", data.v_total & 0xff);
572 crt_w(regs, CRT_VER_TOTAL, (data.v_total & 0xff));
573
574 tmp = 0x10; /* LineCompare bit #9 */
575 if (data.v_total & 256)
576 tmp |= 0x01;
577 if (data.v_dispend & 256)
578 tmp |= 0x02;
579 if (data.v_sstart & 256)
580 tmp |= 0x04;
581 if (data.v_bstart & 256)
582 tmp |= 0x08;
583 if (data.v_total & 512)
584 tmp |= 0x20;
585 if (data.v_dispend & 512)
586 tmp |= 0x40;
587 if (data.v_sstart & 512)
588 tmp |= 0x80;
589 DEBUG printk("CRT_OVERFLOW: %d\n", tmp);
590 crt_w(regs, CRT_OVERFLOW, tmp);
591
592 crt_w(regs, CRT_PRESET_ROW_SCAN, 0x00); /* not CL !!! */
593
594 tmp = 0x40; /* LineCompare bit #8 */
595 if (data.v_bstart & 512)
596 tmp |= 0x20;
597 if (var->vmode & FB_VMODE_DOUBLE)
598 tmp |= 0x80;
599 DEBUG printk("CRT_MAX_SCAN_LINE: %d\n", tmp);
600 crt_w(regs, CRT_MAX_SCAN_LINE, tmp);
601
602 crt_w(regs, CRT_CURSOR_START, 0x00);
603 crt_w(regs, CRT_CURSOR_END, 8 & 0x1f); /* font height */
604
605 crt_w(regs, CRT_START_ADDR_HIGH, 0x00);
606 crt_w(regs, CRT_START_ADDR_LOW, 0x00);
607
608 crt_w(regs, CRT_CURSOR_LOC_HIGH, 0x00);
609 crt_w(regs, CRT_CURSOR_LOC_LOW, 0x00);
610
611 DEBUG printk("CRT_START_VER_RETR: %ld\n", data.v_sstart & 0xff);
612 crt_w(regs, CRT_START_VER_RETR, (data.v_sstart & 0xff));
613
614#if 1
615 /* 5 refresh cycles per scanline */
616 DEBUG printk("CRT_END_VER_RETR: 64+32+%ld\n", data.v_sstop % 16);
617 crt_w(regs, CRT_END_VER_RETR, ((data.v_sstop & 0x0f) | 0x40 | 0x20));
618#else
619 DEBUG printk("CRT_END_VER_RETR: 128+32+%ld\n", data.v_sstop % 16);
620 crt_w(regs, CRT_END_VER_RETR, ((data.v_sstop & 0x0f) | 128 | 32));
621#endif
622 DEBUG printk("CRT_VER_DISP_ENA_END: %ld\n", data.v_dispend & 0xff);
623 crt_w(regs, CRT_VER_DISP_ENA_END, (data.v_dispend & 0xff));
624
625 DEBUG printk("CRT_START_VER_BLANK: %ld\n", data.v_bstart & 0xff);
626 crt_w(regs, CRT_START_VER_BLANK, (data.v_bstart & 0xff));
627
628 DEBUG printk("CRT_END_VER_BLANK: %ld\n", data.v_bstop & 0xff);
629 crt_w(regs, CRT_END_VER_BLANK, (data.v_bstop & 0xff));
630
631 DEBUG printk("CRT_MODE_CONTROL: 0xe3\n");
632 crt_w(regs, CRT_MODE_CONTROL, 0xe3);
633
634 DEBUG printk("CRT_LINE_COMPARE: 0xff\n");
635 crt_w(regs, CRT_LINE_COMPARE, 0xff);
636
637 tmp = (var->xres_virtual / 8) * (bpp / 8);
638 crt_w(regs, CRT_OFFSET, tmp);
639
640 crt_w(regs, CRT_UNDERLINE_LOC, 0x07); /* probably font-height - 1 */
641
642 tmp = 0x20; /* Enable extended end bits */
643 if (data.h_total & 0x100)
644 tmp |= 0x01;
645 if ((data.h_dispend) & 0x100)
646 tmp |= 0x02;
647 if (data.h_bstart & 0x100)
648 tmp |= 0x04;
649 if (data.h_sstart & 0x100)
650 tmp |= 0x08;
651 if (var->vmode & FB_VMODE_INTERLACED)
652 tmp |= 0x10;
653 DEBUG printk("CRT_EXT_HOR_TIMING1: %d\n", tmp);
654 crt_w(regs, CRT_EXT_HOR_TIMING1, tmp);
655
656 tmp = 0x00;
657 if (((var->xres_virtual / 8) * (bpp / 8)) & 0x100)
658 tmp |= 0x10;
659 crt_w(regs, CRT_EXT_START_ADDR, tmp);
660
661 tmp = 0x00;
662 if (data.h_total & 0x200)
663 tmp |= 0x01;
664 if ((data.h_dispend) & 0x200)
665 tmp |= 0x02;
666 if (data.h_bstart & 0x200)
667 tmp |= 0x04;
668 if (data.h_sstart & 0x200)
669 tmp |= 0x08;
670 tmp |= ((data.h_bstop & 0xc0) >> 2);
671 tmp |= ((data.h_sstop & 0x60) << 1);
672 crt_w(regs, CRT_EXT_HOR_TIMING2, tmp);
673 DEBUG printk("CRT_EXT_HOR_TIMING2: %d\n", tmp);
674
675 tmp = 0x10; /* Line compare bit 10 */
676 if (data.v_total & 0x400)
677 tmp |= 0x01;
678 if ((data.v_dispend) & 0x400)
679 tmp |= 0x02;
680 if (data.v_bstart & 0x400)
681 tmp |= 0x04;
682 if (data.v_sstart & 0x400)
683 tmp |= 0x08;
684 tmp |= ((data.v_bstop & 0x300) >> 3);
685 if (data.v_sstop & 0x10)
686 tmp |= 0x80;
687 crt_w(regs, CRT_EXT_VER_TIMING, tmp);
688 DEBUG printk("CRT_EXT_VER_TIMING: %d\n", tmp);
689
690 crt_w(regs, CRT_MONITOR_POWER, 0x00);
691
692 /*
693 * Convert from ps to Hz.
694 */
695 freq = 2000000000 / var->pixclock;
696 freq = freq * 500;
697
698 best_freq = find_fq(freq);
699 pll_w(regs, 0x02, best_freq);
700 best_freq = find_fq(61000000);
701 pll_w(regs, 0x0a, best_freq);
702 pll_w(regs, 0x0e, 0x22);
703
704 gfx_w(regs, GFX_SET_RESET, 0x00);
705 gfx_w(regs, GFX_ENABLE_SET_RESET, 0x00);
706 gfx_w(regs, GFX_COLOR_COMPARE, 0x00);
707 gfx_w(regs, GFX_DATA_ROTATE, 0x00);
708 gfx_w(regs, GFX_READ_MAP_SELECT, 0x00);
709 gfx_w(regs, GFX_GRAPHICS_MODE, 0x00);
710 gfx_w(regs, GFX_MISC, 0x05);
711 gfx_w(regs, GFX_COLOR_XCARE, 0x0f);
712 gfx_w(regs, GFX_BITMASK, 0xff);
713
714 reg_r(regs, ACT_ADDRESS_RESET);
715 attr_w(regs, ACT_PALETTE0 , 0x00);
716 attr_w(regs, ACT_PALETTE1 , 0x01);
717 attr_w(regs, ACT_PALETTE2 , 0x02);
718 attr_w(regs, ACT_PALETTE3 , 0x03);
719 attr_w(regs, ACT_PALETTE4 , 0x04);
720 attr_w(regs, ACT_PALETTE5 , 0x05);
721 attr_w(regs, ACT_PALETTE6 , 0x06);
722 attr_w(regs, ACT_PALETTE7 , 0x07);
723 attr_w(regs, ACT_PALETTE8 , 0x08);
724 attr_w(regs, ACT_PALETTE9 , 0x09);
725 attr_w(regs, ACT_PALETTE10, 0x0a);
726 attr_w(regs, ACT_PALETTE11, 0x0b);
727 attr_w(regs, ACT_PALETTE12, 0x0c);
728 attr_w(regs, ACT_PALETTE13, 0x0d);
729 attr_w(regs, ACT_PALETTE14, 0x0e);
730 attr_w(regs, ACT_PALETTE15, 0x0f);
731 reg_r(regs, ACT_ADDRESS_RESET);
732
733 attr_w(regs, ACT_ATTR_MODE_CNTL, 0x09); /* 0x01 for CL */
734
735 attr_w(regs, ACT_OVERSCAN_COLOR, 0x00);
736 attr_w(regs, ACT_COLOR_PLANE_ENA, 0x0f);
737 attr_w(regs, ACT_HOR_PEL_PANNING, 0x00);
738 attr_w(regs, ACT_COLOR_SELECT, 0x00);
739
740 reg_r(regs, ACT_ADDRESS_RESET);
741 reg_w(regs, ACT_DATA, 0x20);
742
743 reg_w(regs, VDAC_MASK, 0xff);
744
745 /*
746 * Extended palette addressing ???
747 */
748 switch (bpp){
749 case 8:
750 reg_w(regs, 0x83c6, 0x00);
751 break;
752 case 16:
753 reg_w(regs, 0x83c6, 0x60);
754 break;
755 case 24:
756 reg_w(regs, 0x83c6, 0xe0);
757 break;
758 default:
759 printk(KERN_INFO "Illegal color-depth: %i\n", bpp);
760 }
761
762 reg_w(regs, VDAC_ADDRESS, 0x00);
763
764 seq_w(regs, SEQ_MAP_MASK, 0x0f );
765
766 return 0;
767}
768
769
770/*
771 * This function should fill in the `fix' structure based on the
772 * values in the `par' structure.
773 */
774
775static int retz3_encode_fix(struct fb_info *info,
776 struct fb_fix_screeninfo *fix,
777 struct retz3fb_par *par)
778{
779 struct retz3_fb_info *zinfo = retz3info(info);
780
781 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
782 strcpy(fix->id, retz3fb_name);
783 fix->smem_start = zinfo->physfbmem;
784 fix->smem_len = zinfo->fbsize;
785 fix->mmio_start = zinfo->physregs;
786 fix->mmio_len = 0x00c00000;
787
788 fix->type = FB_TYPE_PACKED_PIXELS;
789 fix->type_aux = 0;
790 if (par->bpp == 8)
791 fix->visual = FB_VISUAL_PSEUDOCOLOR;
792 else
793 fix->visual = FB_VISUAL_TRUECOLOR;
794
795 fix->xpanstep = 0;
796 fix->ypanstep = 0;
797 fix->ywrapstep = 0;
798 fix->line_length = 0;
799
800 fix->accel = FB_ACCEL_NCR_77C32BLT;
801
802 return 0;
803}
804
805
806/*
807 * Get the video params out of `var'. If a value doesn't fit, round
808 * it up, if it's too big, return -EINVAL.
809 */
810
811static int retz3_decode_var(struct fb_var_screeninfo *var,
812 struct retz3fb_par *par)
813{
814 par->xres = var->xres;
815 par->yres = var->yres;
816 par->xres_vir = var->xres_virtual;
817 par->yres_vir = var->yres_virtual;
818 par->bpp = var->bits_per_pixel;
819 par->pixclock = var->pixclock;
820 par->vmode = var->vmode;
821
822 par->red = var->red;
823 par->green = var->green;
824 par->blue = var->blue;
825 par->transp = var->transp;
826
827 par->left_margin = var->left_margin;
828 par->right_margin = var->right_margin;
829 par->upper_margin = var->upper_margin;
830 par->lower_margin = var->lower_margin;
831 par->hsync_len = var->hsync_len;
832 par->vsync_len = var->vsync_len;
833
834 if (var->accel_flags & FB_ACCELF_TEXT)
835 par->accel = FB_ACCELF_TEXT;
836 else
837 par->accel = 0;
838
839 return 0;
840}
841
842
843/*
844 * Fill the `var' structure based on the values in `par' and maybe
845 * other values read out of the hardware.
846 */
847
848static int retz3_encode_var(struct fb_var_screeninfo *var,
849 struct retz3fb_par *par)
850{
851 memset(var, 0, sizeof(struct fb_var_screeninfo));
852 var->xres = par->xres;
853 var->yres = par->yres;
854 var->xres_virtual = par->xres_vir;
855 var->yres_virtual = par->yres_vir;
856 var->xoffset = 0;
857 var->yoffset = 0;
858
859 var->bits_per_pixel = par->bpp;
860 var->grayscale = 0;
861
862 var->red = par->red;
863 var->green = par->green;
864 var->blue = par->blue;
865 var->transp = par->transp;
866
867 var->nonstd = 0;
868 var->activate = 0;
869
870 var->height = -1;
871 var->width = -1;
872
873 var->accel_flags = (par->accel && par->bpp == 8) ? FB_ACCELF_TEXT : 0;
874
875 var->pixclock = par->pixclock;
876
877 var->sync = 0; /* ??? */
878 var->left_margin = par->left_margin;
879 var->right_margin = par->right_margin;
880 var->upper_margin = par->upper_margin;
881 var->lower_margin = par->lower_margin;
882 var->hsync_len = par->hsync_len;
883 var->vsync_len = par->vsync_len;
884
885 var->vmode = par->vmode;
886 return 0;
887}
888
889
890/*
891 * Set a single color register. Return != 0 for invalid regno.
892 */
893
894static int retz3fb_setcolreg(unsigned int regno, unsigned int red,
895 unsigned int green, unsigned int blue,
896 unsigned int transp, struct fb_info *info)
897{
898 struct retz3_fb_info *zinfo = retz3info(info);
899 volatile unsigned char *regs = zinfo->regs;
900
901 /* We'll get to this */
902
903 if (regno > 255)
904 return 1;
905
906 red >>= 10;
907 green >>= 10;
908 blue >>= 10;
909
910 zinfo->color_table[regno][0] = red;
911 zinfo->color_table[regno][1] = green;
912 zinfo->color_table[regno][2] = blue;
913
914 reg_w(regs, VDAC_ADDRESS_W, regno);
915 reg_w(regs, VDAC_DATA, red);
916 reg_w(regs, VDAC_DATA, green);
917 reg_w(regs, VDAC_DATA, blue);
918
919 return 0;
920}
921
922
923/*
924 * Read a single color register and split it into
925 * colors/transparent. Return != 0 for invalid regno.
926 */
927
928static int retz3_getcolreg(unsigned int regno, unsigned int *red,
929 unsigned int *green, unsigned int *blue,
930 unsigned int *transp, struct fb_info *info)
931{
932 struct retz3_fb_info *zinfo = retz3info(info);
933 int t;
934
935 if (regno > 255)
936 return 1;
937 t = zinfo->color_table[regno][0];
938 *red = (t<<10) | (t<<4) | (t>>2);
939 t = zinfo->color_table[regno][1];
940 *green = (t<<10) | (t<<4) | (t>>2);
941 t = zinfo->color_table[regno][2];
942 *blue = (t<<10) | (t<<4) | (t>>2);
943 *transp = 0;
944 return 0;
945}
946
947
948static inline void retz3_busy(struct display *p)
949{
950 struct retz3_fb_info *zinfo = retz3info(p->fb_info);
951 volatile unsigned char *acm = zinfo->base + ACM_OFFSET;
952 unsigned char blt_status;
953
954 if (zinfo->blitbusy) {
955 do{
956 blt_status = *((acm) + (ACM_START_STATUS + 2));
957 }while ((blt_status & 1) == 0);
958 zinfo->blitbusy = 0;
959 }
960}
961
962
963static void retz3_bitblt (struct display *p,
964 unsigned short srcx, unsigned short srcy,
965 unsigned short destx, unsigned short desty,
966 unsigned short width, unsigned short height,
967 unsigned short cmd, unsigned short mask)
968{
969 struct fb_var_screeninfo *var = &p->var;
970 struct retz3_fb_info *zinfo = retz3info(p->fb_info);
971 volatile unsigned long *acm = (unsigned long *)(zinfo->base + ACM_OFFSET);
972 unsigned long *pattern = (unsigned long *)(zinfo->fbmem + PAT_MEM_OFF);
973
974 unsigned short mod;
975 unsigned long tmp;
976 unsigned long pat, src, dst;
977
978 int i, xres_virtual = var->xres_virtual;
979 short bpp = (var->bits_per_pixel & 0xff);
980
981 if (bpp < 8)
982 bpp = 8;
983
984 tmp = mask | (mask << 16);
985
986 retz3_busy(p);
987
988 i = 0;
989 do{
990 *pattern++ = tmp;
991 }while(i++ < bpp/4);
992
993 tmp = cmd << 8;
994 *(acm + ACM_RASTEROP_ROTATION/4) = tmp;
995
996 mod = 0xc0c2;
997
998 pat = 8 * PAT_MEM_OFF;
999 dst = bpp * (destx + desty * xres_virtual);
1000
1001 /*
1002 * Source is not set for clear.
1003 */
1004 if ((cmd != Z3BLTclear) && (cmd != Z3BLTset)) {
1005 src = bpp * (srcx + srcy * xres_virtual);
1006
1007 if (destx > srcx) {
1008 mod &= ~0x8000;
1009 src += bpp * (width - 1);
1010 dst += bpp * (width - 1);
1011 pat += bpp * 2;
1012 }
1013 if (desty > srcy) {
1014 mod &= ~0x4000;
1015 src += bpp * (height - 1) * xres_virtual;
1016 dst += bpp * (height - 1) * xres_virtual;
1017 pat += bpp * 4;
1018 }
1019
1020 *(acm + ACM_SOURCE/4) = cpu_to_le32(src);
1021 }
1022
1023 *(acm + ACM_PATTERN/4) = cpu_to_le32(pat);
1024
1025 *(acm + ACM_DESTINATION/4) = cpu_to_le32(dst);
1026
1027 tmp = mod << 16;
1028 *(acm + ACM_CONTROL/4) = tmp;
1029
1030 tmp = width | (height << 16);
1031
1032 *(acm + ACM_BITMAP_DIMENSION/4) = cpu_to_le32(tmp);
1033
1034 *(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x00;
1035 *(((volatile unsigned char *)acm) + ACM_START_STATUS) = 0x01;
1036 zinfo->blitbusy = 1;
1037}
1038
1039#if 0
1040/*
1041 * Move cursor to x, y
1042 */
1043static void retz3_MoveCursor (unsigned short x, unsigned short y)
1044{
1045 /* Guess we gotta deal with the cursor at some point */
1046}
1047#endif
1048
1049
1050/*
1051 * Fill the hardware's `par' structure.
1052 */
1053
1054static void retz3fb_get_par(struct fb_info *info, struct retz3fb_par *par)
1055{
1056 struct retz3_fb_info *zinfo = retz3info(info);
1057
1058 if (zinfo->current_par_valid)
1059 *par = zinfo->current_par;
1060 else
1061 retz3_decode_var(&retz3fb_default, par);
1062}
1063
1064
1065static void retz3fb_set_par(struct fb_info *info, struct retz3fb_par *par)
1066{
1067 struct retz3_fb_info *zinfo = retz3info(info);
1068
1069 zinfo->current_par = *par;
1070 zinfo->current_par_valid = 1;
1071}
1072
1073
1074static int do_fb_set_var(struct fb_info *info,
1075 struct fb_var_screeninfo *var, int isactive)
1076{
1077 int err, activate;
1078 struct retz3fb_par par;
1079 struct retz3_fb_info *zinfo = retz3info(info);
1080
1081 if ((err = retz3_decode_var(var, &par)))
1082 return err;
1083 activate = var->activate;
1084
1085 /* XXX ... what to do about isactive ? */
1086
1087 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW && isactive)
1088 retz3fb_set_par(info, &par);
1089 retz3_encode_var(var, &par);
1090 var->activate = activate;
1091
1092 retz3_set_video(info, var, &zinfo->current_par);
1093
1094 return 0;
1095}
1096
1097/*
1098 * Get the Fixed Part of the Display
1099 */
1100
1101static int retz3fb_get_fix(struct fb_fix_screeninfo *fix, int con,
1102 struct fb_info *info)
1103{
1104 struct retz3fb_par par;
1105 int error = 0;
1106
1107 if (con == -1)
1108 retz3fb_get_par(info, &par);
1109 else
1110 error = retz3_decode_var(&fb_display[con].var, &par);
1111 return(error ? error : retz3_encode_fix(info, fix, &par));
1112}
1113
1114
1115/*
1116 * Get the User Defined Part of the Display
1117 */
1118
1119static int retz3fb_get_var(struct fb_var_screeninfo *var, int con,
1120 struct fb_info *info)
1121{
1122 struct retz3fb_par par;
1123 int error = 0;
1124
1125 if (con == -1) {
1126 retz3fb_get_par(info, &par);
1127 error = retz3_encode_var(var, &par);
1128 } else
1129 *var = fb_display[con].var;
1130 return error;
1131}
1132
1133
1134static void retz3fb_set_disp(int con, struct fb_info *info)
1135{
1136 struct fb_fix_screeninfo fix;
1137 struct display *display;
1138 struct retz3_fb_info *zinfo = retz3info(info);
1139
1140 if (con >= 0)
1141 display = &fb_display[con];
1142 else
1143 display = &zinfo->disp; /* used during initialization */
1144
1145 retz3fb_get_fix(&fix, con, info);
1146
1147 if (con == -1)
1148 con = 0;
1149
1150 display->visual = fix.visual;
1151 display->type = fix.type;
1152 display->type_aux = fix.type_aux;
1153 display->ypanstep = fix.ypanstep;
1154 display->ywrapstep = fix.ywrapstep;
1155 display->can_soft_blank = 1;
1156 display->inverse = z3fb_inverse;
1157
1158 /*
1159 * This seems to be about 20% faster.
1160 */
1161 display->scrollmode = SCROLL_YREDRAW;
1162
1163 switch (display->var.bits_per_pixel) {
1164#ifdef FBCON_HAS_CFB8
1165 case 8:
1166 if (display->var.accel_flags & FB_ACCELF_TEXT) {
1167 display->dispsw = &fbcon_retz3_8;
1168 retz3_set_video(info, &display->var, &zinfo->current_par);
1169 } else
1170 display->dispsw = &fbcon_cfb8;
1171 break;
1172#endif
1173#ifdef FBCON_HAS_CFB16
1174 case 16:
1175 display->dispsw = &fbcon_cfb16;
1176 break;
1177#endif
1178 default:
1179 display->dispsw = &fbcon_dummy;
1180 break;
1181 }
1182}
1183
1184
1185/*
1186 * Set the User Defined Part of the Display
1187 */
1188
1189static int retz3fb_set_var(struct fb_var_screeninfo *var, int con,
1190 struct fb_info *info)
1191{
1192 int err, oldxres, oldyres, oldvxres, oldvyres, oldbpp, oldaccel;
1193 struct display *display;
1194 struct retz3_fb_info *zinfo = retz3info(info);
1195
1196 if (con >= 0)
1197 display = &fb_display[con];
1198 else
1199 display = &zinfo->disp; /* used during initialization */
1200
1201 if ((err = do_fb_set_var(info, var, con == info->currcon)))
1202 return err;
1203 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
1204 oldxres = display->var.xres;
1205 oldyres = display->var.yres;
1206 oldvxres = display->var.xres_virtual;
1207 oldvyres = display->var.yres_virtual;
1208 oldbpp = display->var.bits_per_pixel;
1209 oldaccel = display->var.accel_flags;
1210 display->var = *var;
1211
1212 if (oldxres != var->xres || oldyres != var->yres ||
1213 oldvxres != var->xres_virtual ||
1214 oldvyres != var->yres_virtual ||
1215 oldbpp != var->bits_per_pixel ||
1216 oldaccel != var->accel_flags) {
1217
1218 struct fb_fix_screeninfo fix;
1219 retz3fb_get_fix(&fix, con, info);
1220
1221 display->visual = fix.visual;
1222 display->type = fix.type;
1223 display->type_aux = fix.type_aux;
1224 display->ypanstep = fix.ypanstep;
1225 display->ywrapstep = fix.ywrapstep;
1226 display->line_length = fix.line_length;
1227 display->can_soft_blank = 1;
1228 display->inverse = z3fb_inverse;
1229 switch (display->var.bits_per_pixel) {
1230#ifdef FBCON_HAS_CFB8
1231 case 8:
1232 if (var->accel_flags & FB_ACCELF_TEXT) {
1233 display->dispsw = &fbcon_retz3_8;
1234 } else
1235 display->dispsw = &fbcon_cfb8;
1236 break;
1237#endif
1238#ifdef FBCON_HAS_CFB16
1239 case 16:
1240 display->dispsw = &fbcon_cfb16;
1241 break;
1242#endif
1243 default:
1244 display->dispsw = &fbcon_dummy;
1245 break;
1246 }
1247 /*
1248 * We still need to find a way to tell the X
1249 * server that the video mem has been fiddled with
1250 * so it redraws the entire screen when switching
1251 * between X and a text console.
1252 */
1253 retz3_set_video(info, var, &zinfo->current_par);
1254
1255 if (info->changevar)
1256 (*info->changevar)(con);
1257 }
1258
1259 if (oldbpp != var->bits_per_pixel) {
1260 if ((err = fb_alloc_cmap(&display->cmap, 0, 0)))
1261 return err;
1262 do_install_cmap(con, info);
1263 }
1264 }
1265 return 0;
1266}
1267
1268
1269/*
1270 * Get the Colormap
1271 */
1272
1273static int retz3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
1274 struct fb_info *info)
1275{
1276 if (con == info->currcon) /* current console? */
1277 return(fb_get_cmap(cmap, kspc, retz3_getcolreg, info));
1278 else if (fb_display[con].cmap.len) /* non default colormap? */
1279 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
1280 else
1281 fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel),
1282 cmap, kspc ? 0 : 2);
1283 return 0;
1284}
1285
1286/*
1287 * Blank the display.
1288 */
1289
1290static int retz3fb_blank(int blank, struct fb_info *info)
1291{
1292 struct retz3_fb_info *zinfo = retz3info(info);
1293 volatile unsigned char *regs = retz3info(info)->regs;
1294 short i;
1295
1296 if (blank)
1297 for (i = 0; i < 256; i++){
1298 reg_w(regs, VDAC_ADDRESS_W, i);
1299 reg_w(regs, VDAC_DATA, 0);
1300 reg_w(regs, VDAC_DATA, 0);
1301 reg_w(regs, VDAC_DATA, 0);
1302 }
1303 else
1304 for (i = 0; i < 256; i++){
1305 reg_w(regs, VDAC_ADDRESS_W, i);
1306 reg_w(regs, VDAC_DATA, zinfo->color_table[i][0]);
1307 reg_w(regs, VDAC_DATA, zinfo->color_table[i][1]);
1308 reg_w(regs, VDAC_DATA, zinfo->color_table[i][2]);
1309 }
1310 return 0;
1311}
1312
1313static struct fb_ops retz3fb_ops = {
1314 .owner = THIS_MODULE,
1315 .fb_get_fix = retz3fb_get_fix,
1316 .fb_get_var = retz3fb_get_var,
1317 .fb_set_var = retz3fb_set_var,
1318 .fb_get_cmap = retz3fb_get_cmap,
1319 .fb_set_cmap = gen_set_cmap,
1320 .fb_setcolreg = retz3fb_setcolreg,
1321 .fb_blank = retz3fb_blank,
1322};
1323
1324int __init retz3fb_setup(char *options)
1325{
1326 char *this_opt;
1327
1328 if (!options || !*options)
1329 return 0;
1330
1331 while ((this_opt = strsep(&options, ",")) != NULL) {
1332 if (!*this_opt)
1333 continue;
1334 if (!strcmp(this_opt, "inverse")) {
1335 z3fb_inverse = 1;
1336 fb_invert_cmaps();
1337 } else if (!strncmp(this_opt, "font:", 5)) {
1338 strlcpy(fontname, this_opt+5, sizeof(fontname));
1339 } else
1340 z3fb_mode = get_video_mode(this_opt);
1341 }
1342 return 0;
1343}
1344
1345
1346/*
1347 * Initialization
1348 */
1349
1350int __init retz3fb_init(void)
1351{
1352 unsigned long board_addr, board_size;
1353 struct zorro_dev *z = NULL;
1354 volatile unsigned char *regs;
1355 struct retz3fb_par par;
1356 struct retz3_fb_info *zinfo;
1357 struct fb_info *fb_info;
1358 short i;
1359 int res = -ENXIO;
1360
1361 while ((z = zorro_find_device(ZORRO_PROD_MACROSYSTEMS_RETINA_Z3, z))) {
1362 board_addr = z->resource.start;
1363 board_size = z->resource.end-z->resource.start+1;
1364 if (!request_mem_region(board_addr, 0x0c00000,
1365 "ncr77c32blt")) {
1366 continue;
1367 if (!request_mem_region(board_addr+VIDEO_MEM_OFFSET,
1368 0x00400000, "RAM"))
1369 release_mem_region(board_addr, 0x00c00000);
1370 continue;
1371 }
1372 if (!(zinfo = kmalloc(sizeof(struct retz3_fb_info),
1373 GFP_KERNEL)))
1374 return -ENOMEM;
1375 memset(zinfo, 0, sizeof(struct retz3_fb_info));
1376
1377 zinfo->base = ioremap(board_addr, board_size);
1378 zinfo->regs = zinfo->base;
1379 zinfo->fbmem = zinfo->base + VIDEO_MEM_OFFSET;
1380 /* Get memory size - for now we asume it's a 4MB board */
1381 zinfo->fbsize = 0x00400000; /* 4 MB */
1382 zinfo->physregs = board_addr;
1383 zinfo->physfbmem = board_addr + VIDEO_MEM_OFFSET;
1384
1385 fb_info = fbinfo(zinfo);
1386
1387 for (i = 0; i < 256; i++){
1388 for (i = 0; i < 256; i++){
1389 zinfo->color_table[i][0] = i;
1390 zinfo->color_table[i][1] = i;
1391 zinfo->color_table[i][2] = i;
1392 }
1393 }
1394
1395 regs = zinfo->regs;
1396 /* Disable hardware cursor */
1397 seq_w(regs, SEQ_CURSOR_Y_INDEX, 0x00);
1398
1399 retz3fb_setcolreg (255, 56<<8, 100<<8, 160<<8, 0, fb_info);
1400 retz3fb_setcolreg (254, 0, 0, 0, 0, fb_info);
1401
1402 strcpy(fb_info->modename, retz3fb_name);
1403 fb_info->changevar = NULL;
1404 fb_info->fbops = &retz3fb_ops;
1405 fb_info->screen_base = zinfo->fbmem;
1406 fb_info->disp = &zinfo->disp;
1407 fb_info->currcon = -1;
1408 fb_info->switch_con = &z3fb_switch;
1409 fb_info->updatevar = &z3fb_updatevar;
1410 fb_info->flags = FBINFO_FLAG_DEFAULT;
1411 strlcpy(fb_info->fontname, fontname, sizeof(fb_info->fontname));
1412
1413 if (z3fb_mode == -1)
1414 retz3fb_default = retz3fb_predefined[0].var;
1415
1416 retz3_decode_var(&retz3fb_default, &par);
1417 retz3_encode_var(&retz3fb_default, &par);
1418
1419 do_fb_set_var(fb_info, &retz3fb_default, 0);
1420 retz3fb_get_var(&zinfo->disp.var, -1, fb_info);
1421
1422 retz3fb_set_disp(-1, fb_info);
1423
1424 do_install_cmap(0, fb_info);
1425
1426 if (register_framebuffer(fb_info) < 0) {
1427 iounmap(zinfo->base);
1428 return -EINVAL;
1429 }
1430
1431 printk(KERN_INFO "fb%d: %s frame buffer device, using %ldK of "
1432 "video memory\n", fb_info->node,
1433 fb_info->modename, zinfo->fbsize>>10);
1434
1435 /* FIXME: This driver cannot be unloaded yet */
1436 res = 0;
1437 }
1438 return res;
1439}
1440
1441
1442static int z3fb_switch(int con, struct fb_info *info)
1443{
1444 /* Do we have to save the colormap? */
1445 if (fb_display[info->currcon].cmap.len)
1446 fb_get_cmap(&fb_display[info->currcon].cmap, 1,
1447 retz3_getcolreg, info);
1448
1449 do_fb_set_var(info, &fb_display[con].var, 1);
1450 info->currcon = con;
1451 /* Install new colormap */
1452 do_install_cmap(con, info);
1453 return 0;
1454}
1455
1456
1457/*
1458 * Update the `var' structure (called by fbcon.c)
1459 *
1460 * This call looks only at yoffset and the FB_VMODE_YWRAP flag in `var'.
1461 * Since it's called by a kernel driver, no range checking is done.
1462 */
1463
1464static int z3fb_updatevar(int con, struct fb_info *info)
1465{
1466 return 0;
1467}
1468
1469/*
1470 * Get a Video Mode
1471 */
1472
1473static int __init get_video_mode(const char *name)
1474{
1475 short i;
1476
1477 for (i = 0; i < NUM_TOTAL_MODES; i++)
1478 if (!strcmp(name, retz3fb_predefined[i].name)){
1479 retz3fb_default = retz3fb_predefined[i].var;
1480 return i;
1481 }
1482 return -1;
1483}
1484
1485
1486#ifdef MODULE
1487MODULE_LICENSE("GPL");
1488
1489int init_module(void)
1490{
1491 return retz3fb_init();
1492}
1493#endif
1494
1495
1496/*
1497 * Text console acceleration
1498 */
1499
1500#ifdef FBCON_HAS_CFB8
1501static void retz3_8_bmove(struct display *p, int sy, int sx,
1502 int dy, int dx, int height, int width)
1503{
1504 int fontwidth = fontwidth(p);
1505
1506 sx *= fontwidth;
1507 dx *= fontwidth;
1508 width *= fontwidth;
1509
1510 retz3_bitblt(p,
1511 (unsigned short)sx,
1512 (unsigned short)(sy*fontheight(p)),
1513 (unsigned short)dx,
1514 (unsigned short)(dy*fontheight(p)),
1515 (unsigned short)width,
1516 (unsigned short)(height*fontheight(p)),
1517 Z3BLTcopy,
1518 0xffff);
1519}
1520
1521static void retz3_8_clear(struct vc_data *conp, struct display *p,
1522 int sy, int sx, int height, int width)
1523{
1524 unsigned short col;
1525 int fontwidth = fontwidth(p);
1526
1527 sx *= fontwidth;
1528 width *= fontwidth;
1529
1530 col = attr_bgcol_ec(p, conp);
1531 col &= 0xff;
1532 col |= (col << 8);
1533
1534 retz3_bitblt(p,
1535 (unsigned short)sx,
1536 (unsigned short)(sy*fontheight(p)),
1537 (unsigned short)sx,
1538 (unsigned short)(sy*fontheight(p)),
1539 (unsigned short)width,
1540 (unsigned short)(height*fontheight(p)),
1541 Z3BLTset,
1542 col);
1543}
1544
1545
1546static void retz3_putc(struct vc_data *conp, struct display *p, int c,
1547 int yy, int xx)
1548{
1549 retz3_busy(p);
1550 fbcon_cfb8_putc(conp, p, c, yy, xx);
1551}
1552
1553
1554static void retz3_putcs(struct vc_data *conp, struct display *p,
1555 const unsigned short *s, int count,
1556 int yy, int xx)
1557{
1558 retz3_busy(p);
1559 fbcon_cfb8_putcs(conp, p, s, count, yy, xx);
1560}
1561
1562
1563static void retz3_revc(struct display *p, int xx, int yy)
1564{
1565 retz3_busy(p);
1566 fbcon_cfb8_revc(p, xx, yy);
1567}
1568
1569
1570static void retz3_clear_margins(struct vc_data* conp, struct display* p,
1571 int bottom_only)
1572{
1573 retz3_busy(p);
1574 fbcon_cfb8_clear_margins(conp, p, bottom_only);
1575}
1576
1577
1578static struct display_switch fbcon_retz3_8 = {
1579 .setup = fbcon_cfb8_setup,
1580 .bmove = retz3_8_bmove,
1581 .clear = retz3_8_clear,
1582 .putc = retz3_putc,
1583 .putcs = retz3_putcs,
1584 .revc = retz3_revc,
1585 .clear_margins = retz3_clear_margins,
1586 .fontwidthmask = FONTWIDTH(8)
1587};
1588#endif
diff --git a/drivers/video/retz3fb.h b/drivers/video/retz3fb.h
deleted file mode 100644
index 5cc75106772..00000000000
--- a/drivers/video/retz3fb.h
+++ /dev/null
@@ -1,286 +0,0 @@
1/*
2 * linux/drivers/video/retz3fb.h -- Defines and macros for the RetinaZ3 frame
3 * buffer device
4 *
5 * Copyright (C) 1997 Jes Sorensen
6 *
7 * History:
8 * - 22 Jan 97: Initial work
9 *
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file COPYING in the main directory of this archive
13 * for more details.
14 */
15
16/*
17 * Macros to read and write to registers.
18 */
19#define reg_w(regs, reg,dat) (*(regs + reg) = dat)
20#define reg_r(regs, reg) (*(regs + reg))
21
22/*
23 * Macro to access the sequencer.
24 */
25#define seq_w(regs, sreg, sdat) \
26 do{ reg_w(regs, SEQ_IDX, sreg); reg_w(regs, SEQ_DATA, sdat); } while(0)
27
28/*
29 * Macro to access the CRT controller.
30 */
31#define crt_w(regs, creg, cdat) \
32 do{ reg_w(regs, CRT_IDX, creg); reg_w(regs, CRT_DATA, cdat); } while(0)
33
34/*
35 * Macro to access the graphics controller.
36 */
37#define gfx_w(regs, greg, gdat) \
38 do{ reg_w(regs, GFX_IDX, greg); reg_w(regs, GFX_DATA, gdat); } while(0)
39
40/*
41 * Macro to access the attribute controller.
42 */
43#define attr_w(regs, areg, adat) \
44 do{ reg_w(regs, ACT_IDX, areg); reg_w(regs, ACT_DATA, adat); } while(0)
45
46/*
47 * Macro to access the pll.
48 */
49#define pll_w(regs, preg, pdat) \
50 do{ reg_w(regs, PLL_IDX, preg); \
51 reg_w(regs, PLL_DATA, (pdat & 0xff)); \
52 reg_w(regs, PLL_DATA, (pdat >> 8));\
53 } while(0)
54
55/*
56 * Offsets
57 */
58#define VIDEO_MEM_OFFSET 0x00c00000
59#define ACM_OFFSET 0x00b00000
60
61/*
62 * Accelerator Control Menu
63 */
64#define ACM_PRIMARY_OFFSET 0x00
65#define ACM_SECONDARY_OFFSET 0x04
66#define ACM_MODE_CONTROL 0x08
67#define ACM_CURSOR_POSITION 0x0c
68#define ACM_START_STATUS 0x30
69#define ACM_CONTROL 0x34
70#define ACM_RASTEROP_ROTATION 0x38
71#define ACM_BITMAP_DIMENSION 0x3c
72#define ACM_DESTINATION 0x40
73#define ACM_SOURCE 0x44
74#define ACM_PATTERN 0x48
75#define ACM_FOREGROUND 0x4c
76#define ACM_BACKGROUND 0x50
77
78/*
79 * Video DAC addresses
80 */
81#define VDAC_ADDRESS 0x03c8
82#define VDAC_ADDRESS_W 0x03c8
83#define VDAC_ADDRESS_R 0x03c7
84#define VDAC_STATE 0x03c7
85#define VDAC_DATA 0x03c9
86#define VDAC_MASK 0x03c6
87
88/*
89 * Sequencer
90 */
91#define SEQ_IDX 0x03c4 /* Sequencer Index */
92#define SEQ_DATA 0x03c5
93#define SEQ_RESET 0x00
94#define SEQ_CLOCKING_MODE 0x01
95#define SEQ_MAP_MASK 0x02
96#define SEQ_CHAR_MAP_SELECT 0x03
97#define SEQ_MEMORY_MODE 0x04
98#define SEQ_EXTENDED_ENABLE 0x05 /* NCR extensions */
99#define SEQ_UNKNOWN1 0x06
100#define SEQ_UNKNOWN2 0x07
101#define SEQ_CHIP_ID 0x08
102#define SEQ_UNKNOWN3 0x09
103#define SEQ_CURSOR_COLOR1 0x0a
104#define SEQ_CURSOR_COLOR0 0x0b
105#define SEQ_CURSOR_CONTROL 0x0c
106#define SEQ_CURSOR_X_LOC_HI 0x0d
107#define SEQ_CURSOR_X_LOC_LO 0x0e
108#define SEQ_CURSOR_Y_LOC_HI 0x0f
109#define SEQ_CURSOR_Y_LOC_LO 0x10
110#define SEQ_CURSOR_X_INDEX 0x11
111#define SEQ_CURSOR_Y_INDEX 0x12
112#define SEQ_CURSOR_STORE_HI 0x13
113#define SEQ_CURSOR_STORE_LO 0x14
114#define SEQ_CURSOR_ST_OFF_HI 0x15
115#define SEQ_CURSOR_ST_OFF_LO 0x16
116#define SEQ_CURSOR_PIXELMASK 0x17
117#define SEQ_PRIM_HOST_OFF_HI 0x18
118#define SEQ_PRIM_HOST_OFF_LO 0x19
119#define SEQ_LINEAR_0 0x1a
120#define SEQ_LINEAR_1 0x1b
121#define SEQ_SEC_HOST_OFF_HI 0x1c
122#define SEQ_SEC_HOST_OFF_LO 0x1d
123#define SEQ_EXTENDED_MEM_ENA 0x1e
124#define SEQ_EXT_CLOCK_MODE 0x1f
125#define SEQ_EXT_VIDEO_ADDR 0x20
126#define SEQ_EXT_PIXEL_CNTL 0x21
127#define SEQ_BUS_WIDTH_FEEDB 0x22
128#define SEQ_PERF_SELECT 0x23
129#define SEQ_COLOR_EXP_WFG 0x24
130#define SEQ_COLOR_EXP_WBG 0x25
131#define SEQ_EXT_RW_CONTROL 0x26
132#define SEQ_MISC_FEATURE_SEL 0x27
133#define SEQ_COLOR_KEY_CNTL 0x28
134#define SEQ_COLOR_KEY_MATCH0 0x29
135#define SEQ_COLOR_KEY_MATCH1 0x2a
136#define SEQ_COLOR_KEY_MATCH2 0x2b
137#define SEQ_UNKNOWN6 0x2c
138#define SEQ_CRC_CONTROL 0x2d
139#define SEQ_CRC_DATA_LOW 0x2e
140#define SEQ_CRC_DATA_HIGH 0x2f
141#define SEQ_MEMORY_MAP_CNTL 0x30
142#define SEQ_ACM_APERTURE_1 0x31
143#define SEQ_ACM_APERTURE_2 0x32
144#define SEQ_ACM_APERTURE_3 0x33
145#define SEQ_BIOS_UTILITY_0 0x3e
146#define SEQ_BIOS_UTILITY_1 0x3f
147
148/*
149 * Graphics Controller
150 */
151#define GFX_IDX 0x03ce
152#define GFX_DATA 0x03cf
153#define GFX_SET_RESET 0x00
154#define GFX_ENABLE_SET_RESET 0x01
155#define GFX_COLOR_COMPARE 0x02
156#define GFX_DATA_ROTATE 0x03
157#define GFX_READ_MAP_SELECT 0x04
158#define GFX_GRAPHICS_MODE 0x05
159#define GFX_MISC 0x06
160#define GFX_COLOR_XCARE 0x07
161#define GFX_BITMASK 0x08
162
163/*
164 * CRT Controller
165 */
166#define CRT_IDX 0x03d4
167#define CRT_DATA 0x03d5
168#define CRT_HOR_TOTAL 0x00
169#define CRT_HOR_DISP_ENA_END 0x01
170#define CRT_START_HOR_BLANK 0x02
171#define CRT_END_HOR_BLANK 0x03
172#define CRT_START_HOR_RETR 0x04
173#define CRT_END_HOR_RETR 0x05
174#define CRT_VER_TOTAL 0x06
175#define CRT_OVERFLOW 0x07
176#define CRT_PRESET_ROW_SCAN 0x08
177#define CRT_MAX_SCAN_LINE 0x09
178#define CRT_CURSOR_START 0x0a
179#define CRT_CURSOR_END 0x0b
180#define CRT_START_ADDR_HIGH 0x0c
181#define CRT_START_ADDR_LOW 0x0d
182#define CRT_CURSOR_LOC_HIGH 0x0e
183#define CRT_CURSOR_LOC_LOW 0x0f
184#define CRT_START_VER_RETR 0x10
185#define CRT_END_VER_RETR 0x11
186#define CRT_VER_DISP_ENA_END 0x12
187#define CRT_OFFSET 0x13
188#define CRT_UNDERLINE_LOC 0x14
189#define CRT_START_VER_BLANK 0x15
190#define CRT_END_VER_BLANK 0x16
191#define CRT_MODE_CONTROL 0x17
192#define CRT_LINE_COMPARE 0x18
193#define CRT_UNKNOWN1 0x19
194#define CRT_UNKNOWN2 0x1a
195#define CRT_UNKNOWN3 0x1b
196#define CRT_UNKNOWN4 0x1c
197#define CRT_UNKNOWN5 0x1d
198#define CRT_UNKNOWN6 0x1e
199#define CRT_UNKNOWN7 0x1f
200#define CRT_UNKNOWN8 0x20
201#define CRT_UNKNOWN9 0x21
202#define CRT_UNKNOWN10 0x22
203#define CRT_UNKNOWN11 0x23
204#define CRT_UNKNOWN12 0x24
205#define CRT_UNKNOWN13 0x25
206#define CRT_UNKNOWN14 0x26
207#define CRT_UNKNOWN15 0x27
208#define CRT_UNKNOWN16 0x28
209#define CRT_UNKNOWN17 0x29
210#define CRT_UNKNOWN18 0x2a
211#define CRT_UNKNOWN19 0x2b
212#define CRT_UNKNOWN20 0x2c
213#define CRT_UNKNOWN21 0x2d
214#define CRT_UNKNOWN22 0x2e
215#define CRT_UNKNOWN23 0x2f
216#define CRT_EXT_HOR_TIMING1 0x30 /* NCR crt extensions */
217#define CRT_EXT_START_ADDR 0x31
218#define CRT_EXT_HOR_TIMING2 0x32
219#define CRT_EXT_VER_TIMING 0x33
220#define CRT_MONITOR_POWER 0x34
221
222/*
223 * General Registers
224 */
225#define GREG_STATUS0_R 0x03c2
226#define GREG_STATUS1_R 0x03da
227#define GREG_MISC_OUTPUT_R 0x03cc
228#define GREG_MISC_OUTPUT_W 0x03c2
229#define GREG_FEATURE_CONTROL_R 0x03ca
230#define GREG_FEATURE_CONTROL_W 0x03da
231#define GREG_POS 0x0102
232
233/*
234 * Attribute Controller
235 */
236#define ACT_IDX 0x03C0
237#define ACT_ADDRESS_R 0x03C0
238#define ACT_DATA 0x03C0
239#define ACT_ADDRESS_RESET 0x03DA
240#define ACT_PALETTE0 0x00
241#define ACT_PALETTE1 0x01
242#define ACT_PALETTE2 0x02
243#define ACT_PALETTE3 0x03
244#define ACT_PALETTE4 0x04
245#define ACT_PALETTE5 0x05
246#define ACT_PALETTE6 0x06
247#define ACT_PALETTE7 0x07
248#define ACT_PALETTE8 0x08
249#define ACT_PALETTE9 0x09
250#define ACT_PALETTE10 0x0A
251#define ACT_PALETTE11 0x0B
252#define ACT_PALETTE12 0x0C
253#define ACT_PALETTE13 0x0D
254#define ACT_PALETTE14 0x0E
255#define ACT_PALETTE15 0x0F
256#define ACT_ATTR_MODE_CNTL 0x10
257#define ACT_OVERSCAN_COLOR 0x11
258#define ACT_COLOR_PLANE_ENA 0x12
259#define ACT_HOR_PEL_PANNING 0x13
260#define ACT_COLOR_SELECT 0x14
261
262/*
263 * PLL
264 */
265#define PLL_IDX 0x83c8
266#define PLL_DATA 0x83c9
267
268/*
269 * Blitter operations
270 */
271#define Z3BLTclear 0x00 /* 0 */
272#define Z3BLTand 0x80 /* src AND dst */
273#define Z3BLTandReverse 0x40 /* src AND NOT dst */
274#define Z3BLTcopy 0xc0 /* src */
275#define Z3BLTandInverted 0x20 /* NOT src AND dst */
276#define Z3BLTnoop 0xa0 /* dst */
277#define Z3BLTxor 0x60 /* src XOR dst */
278#define Z3BLTor 0xe0 /* src OR dst */
279#define Z3BLTnor 0x10 /* NOT src AND NOT dst */
280#define Z3BLTequiv 0x90 /* NOT src XOR dst */
281#define Z3BLTinvert 0x50 /* NOT dst */
282#define Z3BLTorReverse 0xd0 /* src OR NOT dst */
283#define Z3BLTcopyInverted 0x30 /* NOT src */
284#define Z3BLTorInverted 0xb0 /* NOT src OR dst */
285#define Z3BLTnand 0x70 /* NOT src OR NOT dst */
286#define Z3BLTset 0xf0 /* 1 */
diff --git a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
index 1a13966b7d5..f2e9b742c92 100644
--- a/drivers/video/riva/fbdev.c
+++ b/drivers/video/riva/fbdev.c
@@ -894,7 +894,8 @@ out:
894 return rc; 894 return rc;
895} 895}
896 896
897static void riva_update_var(struct fb_var_screeninfo *var, struct fb_videomode *modedb) 897static void riva_update_var(struct fb_var_screeninfo *var,
898 const struct fb_videomode *modedb)
898{ 899{
899 NVTRACE_ENTER(); 900 NVTRACE_ENTER();
900 var->xres = var->xres_virtual = modedb->xres; 901 var->xres = var->xres_virtual = modedb->xres;
@@ -1101,10 +1102,10 @@ static int riva_get_cmap_len(const struct fb_var_screeninfo *var)
1101static int rivafb_open(struct fb_info *info, int user) 1102static int rivafb_open(struct fb_info *info, int user)
1102{ 1103{
1103 struct riva_par *par = info->par; 1104 struct riva_par *par = info->par;
1104 int cnt = atomic_read(&par->ref_count);
1105 1105
1106 NVTRACE_ENTER(); 1106 NVTRACE_ENTER();
1107 if (!cnt) { 1107 mutex_lock(&par->open_lock);
1108 if (!par->ref_count) {
1108#ifdef CONFIG_X86 1109#ifdef CONFIG_X86
1109 memset(&par->state, 0, sizeof(struct vgastate)); 1110 memset(&par->state, 0, sizeof(struct vgastate));
1110 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS; 1111 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
@@ -1119,7 +1120,8 @@ static int rivafb_open(struct fb_info *info, int user)
1119 1120
1120 riva_save_state(par, &par->initial_state); 1121 riva_save_state(par, &par->initial_state);
1121 } 1122 }
1122 atomic_inc(&par->ref_count); 1123 par->ref_count++;
1124 mutex_unlock(&par->open_lock);
1123 NVTRACE_LEAVE(); 1125 NVTRACE_LEAVE();
1124 return 0; 1126 return 0;
1125} 1127}
@@ -1127,12 +1129,14 @@ static int rivafb_open(struct fb_info *info, int user)
1127static int rivafb_release(struct fb_info *info, int user) 1129static int rivafb_release(struct fb_info *info, int user)
1128{ 1130{
1129 struct riva_par *par = info->par; 1131 struct riva_par *par = info->par;
1130 int cnt = atomic_read(&par->ref_count);
1131 1132
1132 NVTRACE_ENTER(); 1133 NVTRACE_ENTER();
1133 if (!cnt) 1134 mutex_lock(&par->open_lock);
1135 if (!par->ref_count) {
1136 mutex_unlock(&par->open_lock);
1134 return -EINVAL; 1137 return -EINVAL;
1135 if (cnt == 1) { 1138 }
1139 if (par->ref_count == 1) {
1136 par->riva.LockUnlock(&par->riva, 0); 1140 par->riva.LockUnlock(&par->riva, 0);
1137 par->riva.LoadStateExt(&par->riva, &par->initial_state.ext); 1141 par->riva.LoadStateExt(&par->riva, &par->initial_state.ext);
1138 riva_load_state(par, &par->initial_state); 1142 riva_load_state(par, &par->initial_state);
@@ -1141,14 +1145,15 @@ static int rivafb_release(struct fb_info *info, int user)
1141#endif 1145#endif
1142 par->riva.LockUnlock(&par->riva, 1); 1146 par->riva.LockUnlock(&par->riva, 1);
1143 } 1147 }
1144 atomic_dec(&par->ref_count); 1148 par->ref_count--;
1149 mutex_unlock(&par->open_lock);
1145 NVTRACE_LEAVE(); 1150 NVTRACE_LEAVE();
1146 return 0; 1151 return 0;
1147} 1152}
1148 1153
1149static int rivafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) 1154static int rivafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1150{ 1155{
1151 struct fb_videomode *mode; 1156 const struct fb_videomode *mode;
1152 struct riva_par *par = info->par; 1157 struct riva_par *par = info->par;
1153 int nom, den; /* translating from pixels->bytes */ 1158 int nom, den; /* translating from pixels->bytes */
1154 int mode_valid = 0; 1159 int mode_valid = 0;
@@ -1980,12 +1985,11 @@ static int __devinit rivafb_probe(struct pci_dev *pd,
1980 default_par = info->par; 1985 default_par = info->par;
1981 default_par->pdev = pd; 1986 default_par->pdev = pd;
1982 1987
1983 info->pixmap.addr = kmalloc(8 * 1024, GFP_KERNEL); 1988 info->pixmap.addr = kzalloc(8 * 1024, GFP_KERNEL);
1984 if (info->pixmap.addr == NULL) { 1989 if (info->pixmap.addr == NULL) {
1985 ret = -ENOMEM; 1990 ret = -ENOMEM;
1986 goto err_framebuffer_release; 1991 goto err_framebuffer_release;
1987 } 1992 }
1988 memset(info->pixmap.addr, 0, 8 * 1024);
1989 1993
1990 ret = pci_enable_device(pd); 1994 ret = pci_enable_device(pd);
1991 if (ret < 0) { 1995 if (ret < 0) {
@@ -1999,6 +2003,7 @@ static int __devinit rivafb_probe(struct pci_dev *pd,
1999 goto err_disable_device; 2003 goto err_disable_device;
2000 } 2004 }
2001 2005
2006 mutex_init(&default_par->open_lock);
2002 default_par->riva.Architecture = riva_get_arch(pd); 2007 default_par->riva.Architecture = riva_get_arch(pd);
2003 2008
2004 default_par->Chipset = (pd->vendor << 16) | pd->device; 2009 default_par->Chipset = (pd->vendor << 16) | pd->device;
diff --git a/drivers/video/riva/rivafb.h b/drivers/video/riva/rivafb.h
index 7fa13fc9c41..48ead6d72f2 100644
--- a/drivers/video/riva/rivafb.h
+++ b/drivers/video/riva/rivafb.h
@@ -53,7 +53,8 @@ struct riva_par {
53#ifdef CONFIG_X86 53#ifdef CONFIG_X86
54 struct vgastate state; 54 struct vgastate state;
55#endif 55#endif
56 atomic_t ref_count; 56 struct mutex open_lock;
57 unsigned int ref_count;
57 unsigned char *EDID; 58 unsigned char *EDID;
58 unsigned int Chipset; 59 unsigned int Chipset;
59 int forceCRTC; 60 int forceCRTC;
diff --git a/drivers/video/s3fb.c b/drivers/video/s3fb.c
new file mode 100644
index 00000000000..3162c37b144
--- /dev/null
+++ b/drivers/video/s3fb.c
@@ -0,0 +1,1180 @@
1/*
2 * linux/drivers/video/s3fb.c -- Frame buffer device driver for S3 Trio/Virge
3 *
4 * Copyright (c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>
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 * Code is based on David Boucher's viafb (http://davesdomain.org.uk/viafb/)
11 * which is based on the code of neofb.
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 s3fb_info {
35 int chip, rev, mclk_freq;
36 int mtrr_reg;
37 struct vgastate state;
38 struct mutex open_lock;
39 unsigned int ref_count;
40 u32 pseudo_palette[16];
41};
42
43
44/* ------------------------------------------------------------------------- */
45
46static const struct svga_fb_format s3fb_formats[] = {
47 { 0, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
48 FB_TYPE_TEXT, FB_AUX_TEXT_SVGA_STEP4, FB_VISUAL_PSEUDOCOLOR, 8, 16},
49 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
50 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 8, 16},
51 { 4, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 1,
52 FB_TYPE_INTERLEAVED_PLANES, 1, FB_VISUAL_PSEUDOCOLOR, 8, 16},
53 { 8, {0, 6, 0}, {0, 6, 0}, {0, 6, 0}, {0, 0, 0}, 0,
54 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_PSEUDOCOLOR, 4, 8},
55 {16, {10, 5, 0}, {5, 5, 0}, {0, 5, 0}, {0, 0, 0}, 0,
56 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
57 {16, {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0}, 0,
58 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 2, 4},
59 {24, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
60 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
61 {32, {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {0, 0, 0}, 0,
62 FB_TYPE_PACKED_PIXELS, 0, FB_VISUAL_TRUECOLOR, 1, 2},
63 SVGA_FORMAT_END
64};
65
66
67static const struct svga_pll s3_pll = {3, 129, 3, 33, 0, 3,
68 60000, 240000, 14318};
69
70static const int s3_memsizes[] = {4096, 0, 3072, 8192, 2048, 6144, 1024, 512};
71
72static const char * const s3_names[] = {"S3 Unknown", "S3 Trio32", "S3 Trio64", "S3 Trio64V+",
73 "S3 Trio64UV+", "S3 Trio64V2/DX", "S3 Trio64V2/GX",
74 "S3 Plato/PX", "S3 Aurora64VP", "S3 Virge",
75 "S3 Virge/VX", "S3 Virge/DX", "S3 Virge/GX",
76 "S3 Virge/GX2", "S3 Virge/GX2P", "S3 Virge/GX2P"};
77
78#define CHIP_UNKNOWN 0x00
79#define CHIP_732_TRIO32 0x01
80#define CHIP_764_TRIO64 0x02
81#define CHIP_765_TRIO64VP 0x03
82#define CHIP_767_TRIO64UVP 0x04
83#define CHIP_775_TRIO64V2_DX 0x05
84#define CHIP_785_TRIO64V2_GX 0x06
85#define CHIP_551_PLATO_PX 0x07
86#define CHIP_M65_AURORA64VP 0x08
87#define CHIP_325_VIRGE 0x09
88#define CHIP_988_VIRGE_VX 0x0A
89#define CHIP_375_VIRGE_DX 0x0B
90#define CHIP_385_VIRGE_GX 0x0C
91#define CHIP_356_VIRGE_GX2 0x0D
92#define CHIP_357_VIRGE_GX2P 0x0E
93#define CHIP_359_VIRGE_GX2P 0x0F
94
95#define CHIP_XXX_TRIO 0x80
96#define CHIP_XXX_TRIO64V2_DXGX 0x81
97#define CHIP_XXX_VIRGE_DXGX 0x82
98
99#define CHIP_UNDECIDED_FLAG 0x80
100#define CHIP_MASK 0xFF
101
102/* CRT timing register sets */
103
104static const struct vga_regset s3_h_total_regs[] = {{0x00, 0, 7}, {0x5D, 0, 0}, VGA_REGSET_END};
105static const struct vga_regset s3_h_display_regs[] = {{0x01, 0, 7}, {0x5D, 1, 1}, VGA_REGSET_END};
106static const struct vga_regset s3_h_blank_start_regs[] = {{0x02, 0, 7}, {0x5D, 2, 2}, VGA_REGSET_END};
107static const struct vga_regset s3_h_blank_end_regs[] = {{0x03, 0, 4}, {0x05, 7, 7}, VGA_REGSET_END};
108static const struct vga_regset s3_h_sync_start_regs[] = {{0x04, 0, 7}, {0x5D, 4, 4}, VGA_REGSET_END};
109static const struct vga_regset s3_h_sync_end_regs[] = {{0x05, 0, 4}, VGA_REGSET_END};
110
111static const struct vga_regset s3_v_total_regs[] = {{0x06, 0, 7}, {0x07, 0, 0}, {0x07, 5, 5}, {0x5E, 0, 0}, VGA_REGSET_END};
112static const struct vga_regset s3_v_display_regs[] = {{0x12, 0, 7}, {0x07, 1, 1}, {0x07, 6, 6}, {0x5E, 1, 1}, VGA_REGSET_END};
113static const struct vga_regset s3_v_blank_start_regs[] = {{0x15, 0, 7}, {0x07, 3, 3}, {0x09, 5, 5}, {0x5E, 2, 2}, VGA_REGSET_END};
114static const struct vga_regset s3_v_blank_end_regs[] = {{0x16, 0, 7}, VGA_REGSET_END};
115static const struct vga_regset s3_v_sync_start_regs[] = {{0x10, 0, 7}, {0x07, 2, 2}, {0x07, 7, 7}, {0x5E, 4, 4}, VGA_REGSET_END};
116static const struct vga_regset s3_v_sync_end_regs[] = {{0x11, 0, 3}, VGA_REGSET_END};
117
118static const struct vga_regset s3_line_compare_regs[] = {{0x18, 0, 7}, {0x07, 4, 4}, {0x09, 6, 6}, {0x5E, 6, 6}, VGA_REGSET_END};
119static const struct vga_regset s3_start_address_regs[] = {{0x0d, 0, 7}, {0x0c, 0, 7}, {0x31, 4, 5}, {0x51, 0, 1}, VGA_REGSET_END};
120static const struct vga_regset s3_offset_regs[] = {{0x13, 0, 7}, {0x51, 4, 5}, VGA_REGSET_END}; /* set 0x43 bit 2 to 0 */
121
122static const struct svga_timing_regs s3_timing_regs = {
123 s3_h_total_regs, s3_h_display_regs, s3_h_blank_start_regs,
124 s3_h_blank_end_regs, s3_h_sync_start_regs, s3_h_sync_end_regs,
125 s3_v_total_regs, s3_v_display_regs, s3_v_blank_start_regs,
126 s3_v_blank_end_regs, s3_v_sync_start_regs, s3_v_sync_end_regs,
127};
128
129
130/* ------------------------------------------------------------------------- */
131
132/* Module parameters */
133
134
135static char *mode = "640x480-8@60";
136
137#ifdef CONFIG_MTRR
138static int mtrr = 1;
139#endif
140
141static int fasttext = 1;
142
143
144MODULE_AUTHOR("(c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>");
145MODULE_LICENSE("GPL");
146MODULE_DESCRIPTION("fbdev driver for S3 Trio/Virge");
147
148module_param(mode, charp, 0444);
149MODULE_PARM_DESC(mode, "Default video mode ('640x480-8@60', etc)");
150
151#ifdef CONFIG_MTRR
152module_param(mtrr, int, 0444);
153MODULE_PARM_DESC(mtrr, "Enable write-combining with MTRR (1=enable, 0=disable, default=1)");
154#endif
155
156module_param(fasttext, int, 0644);
157MODULE_PARM_DESC(fasttext, "Enable S3 fast text mode (1=enable, 0=disable, default=1)");
158
159
160/* ------------------------------------------------------------------------- */
161
162/* Set font in S3 fast text mode */
163
164static void s3fb_settile_fast(struct fb_info *info, struct fb_tilemap *map)
165{
166 const u8 *font = map->data;
167 u8* fb = (u8 *) info->screen_base;
168 int i, c;
169
170 if ((map->width != 8) || (map->height != 16) ||
171 (map->depth != 1) || (map->length != 256)) {
172 printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n",
173 info->node, map->width, map->height, map->depth, map->length);
174 return;
175 }
176
177 fb += 2;
178 for (i = 0; i < map->height; i++) {
179 for (c = 0; c < map->length; c++) {
180 fb[c * 4] = font[c * map->height + i];
181 }
182 fb += 1024;
183 }
184}
185
186
187
188static struct fb_tile_ops s3fb_tile_ops = {
189 .fb_settile = svga_settile,
190 .fb_tilecopy = svga_tilecopy,
191 .fb_tilefill = svga_tilefill,
192 .fb_tileblit = svga_tileblit,
193 .fb_tilecursor = svga_tilecursor,
194};
195
196static struct fb_tile_ops s3fb_fast_tile_ops = {
197 .fb_settile = s3fb_settile_fast,
198 .fb_tilecopy = svga_tilecopy,
199 .fb_tilefill = svga_tilefill,
200 .fb_tileblit = svga_tileblit,
201 .fb_tilecursor = svga_tilecursor,
202};
203
204
205/* ------------------------------------------------------------------------- */
206
207/* image data is MSB-first, fb structure is MSB-first too */
208static inline u32 expand_color(u32 c)
209{
210 return ((c & 1) | ((c & 2) << 7) | ((c & 4) << 14) | ((c & 8) << 21)) * 0xFF;
211}
212
213/* s3fb_iplan_imageblit silently assumes that almost everything is 8-pixel aligned */
214static void s3fb_iplan_imageblit(struct fb_info *info, const struct fb_image *image)
215{
216 u32 fg = expand_color(image->fg_color);
217 u32 bg = expand_color(image->bg_color);
218 const u8 *src1, *src;
219 u8 __iomem *dst1;
220 u32 __iomem *dst;
221 u32 val;
222 int x, y;
223
224 src1 = image->data;
225 dst1 = info->screen_base + (image->dy * info->fix.line_length)
226 + ((image->dx / 8) * 4);
227
228 for (y = 0; y < image->height; y++) {
229 src = src1;
230 dst = (u32 __iomem *) dst1;
231 for (x = 0; x < image->width; x += 8) {
232 val = *(src++) * 0x01010101;
233 val = (val & fg) | (~val & bg);
234 fb_writel(val, dst++);
235 }
236 src1 += image->width / 8;
237 dst1 += info->fix.line_length;
238 }
239
240}
241
242/* s3fb_iplan_fillrect silently assumes that almost everything is 8-pixel aligned */
243static void s3fb_iplan_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
244{
245 u32 fg = expand_color(rect->color);
246 u8 __iomem *dst1;
247 u32 __iomem *dst;
248 int x, y;
249
250 dst1 = info->screen_base + (rect->dy * info->fix.line_length)
251 + ((rect->dx / 8) * 4);
252
253 for (y = 0; y < rect->height; y++) {
254 dst = (u32 __iomem *) dst1;
255 for (x = 0; x < rect->width; x += 8) {
256 fb_writel(fg, dst++);
257 }
258 dst1 += info->fix.line_length;
259 }
260}
261
262
263/* image data is MSB-first, fb structure is high-nibble-in-low-byte-first */
264static inline u32 expand_pixel(u32 c)
265{
266 return (((c & 1) << 24) | ((c & 2) << 27) | ((c & 4) << 14) | ((c & 8) << 17) |
267 ((c & 16) << 4) | ((c & 32) << 7) | ((c & 64) >> 6) | ((c & 128) >> 3)) * 0xF;
268}
269
270/* s3fb_cfb4_imageblit silently assumes that almost everything is 8-pixel aligned */
271static void s3fb_cfb4_imageblit(struct fb_info *info, const struct fb_image *image)
272{
273 u32 fg = image->fg_color * 0x11111111;
274 u32 bg = image->bg_color * 0x11111111;
275 const u8 *src1, *src;
276 u8 __iomem *dst1;
277 u32 __iomem *dst;
278 u32 val;
279 int x, y;
280
281 src1 = image->data;
282 dst1 = info->screen_base + (image->dy * info->fix.line_length)
283 + ((image->dx / 8) * 4);
284
285 for (y = 0; y < image->height; y++) {
286 src = src1;
287 dst = (u32 __iomem *) dst1;
288 for (x = 0; x < image->width; x += 8) {
289 val = expand_pixel(*(src++));
290 val = (val & fg) | (~val & bg);
291 fb_writel(val, dst++);
292 }
293 src1 += image->width / 8;
294 dst1 += info->fix.line_length;
295 }
296}
297
298static void s3fb_imageblit(struct fb_info *info, const struct fb_image *image)
299{
300 if ((info->var.bits_per_pixel == 4) && (image->depth == 1)
301 && ((image->width % 8) == 0) && ((image->dx % 8) == 0)) {
302 if (info->fix.type == FB_TYPE_INTERLEAVED_PLANES)
303 s3fb_iplan_imageblit(info, image);
304 else
305 s3fb_cfb4_imageblit(info, image);
306 } else
307 cfb_imageblit(info, image);
308}
309
310static void s3fb_fillrect(struct fb_info *info, const struct fb_fillrect *rect)
311{
312 if ((info->var.bits_per_pixel == 4)
313 && ((rect->width % 8) == 0) && ((rect->dx % 8) == 0)
314 && (info->fix.type == FB_TYPE_INTERLEAVED_PLANES))
315 s3fb_iplan_fillrect(info, rect);
316 else
317 cfb_fillrect(info, rect);
318}
319
320
321
322/* ------------------------------------------------------------------------- */
323
324
325static void s3_set_pixclock(struct fb_info *info, u32 pixclock)
326{
327 u16 m, n, r;
328 u8 regval;
329
330 svga_compute_pll(&s3_pll, 1000000000 / pixclock, &m, &n, &r, info->node);
331
332 /* Set VGA misc register */
333 regval = vga_r(NULL, VGA_MIS_R);
334 vga_w(NULL, VGA_MIS_W, regval | VGA_MIS_ENB_PLL_LOAD);
335
336 /* Set S3 clock registers */
337 vga_wseq(NULL, 0x12, ((n - 2) | (r << 5)));
338 vga_wseq(NULL, 0x13, m - 2);
339
340 udelay(1000);
341
342 /* Activate clock - write 0, 1, 0 to seq/15 bit 5 */
343 regval = vga_rseq (NULL, 0x15); /* | 0x80; */
344 vga_wseq(NULL, 0x15, regval & ~(1<<5));
345 vga_wseq(NULL, 0x15, regval | (1<<5));
346 vga_wseq(NULL, 0x15, regval & ~(1<<5));
347}
348
349
350/* Open framebuffer */
351
352static int s3fb_open(struct fb_info *info, int user)
353{
354 struct s3fb_info *par = info->par;
355
356 mutex_lock(&(par->open_lock));
357 if (par->ref_count == 0) {
358 memset(&(par->state), 0, sizeof(struct vgastate));
359 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS | VGA_SAVE_CMAP;
360 par->state.num_crtc = 0x70;
361 par->state.num_seq = 0x20;
362 save_vga(&(par->state));
363 }
364
365 par->ref_count++;
366 mutex_unlock(&(par->open_lock));
367
368 return 0;
369}
370
371/* Close framebuffer */
372
373static int s3fb_release(struct fb_info *info, int user)
374{
375 struct s3fb_info *par = info->par;
376
377 mutex_lock(&(par->open_lock));
378 if (par->ref_count == 0) {
379 mutex_unlock(&(par->open_lock));
380 return -EINVAL;
381 }
382
383 if (par->ref_count == 1)
384 restore_vga(&(par->state));
385
386 par->ref_count--;
387 mutex_unlock(&(par->open_lock));
388
389 return 0;
390}
391
392/* Validate passed in var */
393
394static int s3fb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
395{
396 struct s3fb_info *par = info->par;
397 int rv, mem, step;
398
399 /* Find appropriate format */
400 rv = svga_match_format (s3fb_formats, var, NULL);
401 if ((rv < 0) || ((par->chip == CHIP_988_VIRGE_VX) ? (rv == 7) : (rv == 6)))
402 { /* 24bpp on VIRGE VX, 32bpp on others */
403 printk(KERN_ERR "fb%d: unsupported mode requested\n", info->node);
404 return rv;
405 }
406
407 /* Do not allow to have real resoulution larger than virtual */
408 if (var->xres > var->xres_virtual)
409 var->xres_virtual = var->xres;
410
411 if (var->yres > var->yres_virtual)
412 var->yres_virtual = var->yres;
413
414 /* Round up xres_virtual to have proper alignment of lines */
415 step = s3fb_formats[rv].xresstep - 1;
416 var->xres_virtual = (var->xres_virtual+step) & ~step;
417
418 /* Check whether have enough memory */
419 mem = ((var->bits_per_pixel * var->xres_virtual) >> 3) * var->yres_virtual;
420 if (mem > info->screen_size)
421 {
422 printk(KERN_ERR "fb%d: not enough framebuffer memory (%d kB requested , %d kB available)\n",
423 info->node, mem >> 10, (unsigned int) (info->screen_size >> 10));
424 return -EINVAL;
425 }
426
427 rv = svga_check_timings (&s3_timing_regs, var, info->node);
428 if (rv < 0)
429 {
430 printk(KERN_ERR "fb%d: invalid timings requested\n", info->node);
431 return rv;
432 }
433
434 return 0;
435}
436
437/* Set video mode from par */
438
439static int s3fb_set_par(struct fb_info *info)
440{
441 struct s3fb_info *par = info->par;
442 u32 value, mode, hmul, offset_value, screen_size, multiplex;
443 u32 bpp = info->var.bits_per_pixel;
444
445 if (bpp != 0) {
446 info->fix.ypanstep = 1;
447 info->fix.line_length = (info->var.xres_virtual * bpp) / 8;
448
449 info->flags &= ~FBINFO_MISC_TILEBLITTING;
450 info->tileops = NULL;
451
452 offset_value = (info->var.xres_virtual * bpp) / 64;
453 screen_size = info->var.yres_virtual * info->fix.line_length;
454 } else {
455 info->fix.ypanstep = 16;
456 info->fix.line_length = 0;
457
458 info->flags |= FBINFO_MISC_TILEBLITTING;
459 info->tileops = fasttext ? &s3fb_fast_tile_ops : &s3fb_tile_ops;
460
461 offset_value = info->var.xres_virtual / 16;
462 screen_size = (info->var.xres_virtual * info->var.yres_virtual) / 64;
463 }
464
465 info->var.xoffset = 0;
466 info->var.yoffset = 0;
467 info->var.activate = FB_ACTIVATE_NOW;
468
469 /* Unlock registers */
470 vga_wcrt(NULL, 0x38, 0x48);
471 vga_wcrt(NULL, 0x39, 0xA5);
472 vga_wseq(NULL, 0x08, 0x06);
473 svga_wcrt_mask(0x11, 0x00, 0x80);
474
475 /* Blank screen and turn off sync */
476 svga_wseq_mask(0x01, 0x20, 0x20);
477 svga_wcrt_mask(0x17, 0x00, 0x80);
478
479 /* Set default values */
480 svga_set_default_gfx_regs();
481 svga_set_default_atc_regs();
482 svga_set_default_seq_regs();
483 svga_set_default_crt_regs();
484 svga_wcrt_multi(s3_line_compare_regs, 0xFFFFFFFF);
485 svga_wcrt_multi(s3_start_address_regs, 0);
486
487 /* S3 specific initialization */
488 svga_wcrt_mask(0x58, 0x10, 0x10); /* enable linear framebuffer */
489 svga_wcrt_mask(0x31, 0x08, 0x08); /* enable sequencer access to framebuffer above 256 kB */
490
491/* svga_wcrt_mask(0x33, 0x08, 0x08); */ /* DDR ? */
492/* svga_wcrt_mask(0x43, 0x01, 0x01); */ /* DDR ? */
493 svga_wcrt_mask(0x33, 0x00, 0x08); /* no DDR ? */
494 svga_wcrt_mask(0x43, 0x00, 0x01); /* no DDR ? */
495
496 svga_wcrt_mask(0x5D, 0x00, 0x28); // Clear strange HSlen bits
497
498/* svga_wcrt_mask(0x58, 0x03, 0x03); */
499
500/* svga_wcrt_mask(0x53, 0x12, 0x13); */ /* enable MMIO */
501/* svga_wcrt_mask(0x40, 0x08, 0x08); */ /* enable write buffer */
502
503
504 /* Set the offset register */
505 pr_debug("fb%d: offset register : %d\n", info->node, offset_value);
506 svga_wcrt_multi(s3_offset_regs, offset_value);
507
508 vga_wcrt(NULL, 0x54, 0x18); /* M parameter */
509 vga_wcrt(NULL, 0x60, 0xff); /* N parameter */
510 vga_wcrt(NULL, 0x61, 0xff); /* L parameter */
511 vga_wcrt(NULL, 0x62, 0xff); /* L parameter */
512
513 vga_wcrt(NULL, 0x3A, 0x35);
514 svga_wattr(0x33, 0x00);
515
516 if (info->var.vmode & FB_VMODE_DOUBLE)
517 svga_wcrt_mask(0x09, 0x80, 0x80);
518 else
519 svga_wcrt_mask(0x09, 0x00, 0x80);
520
521 if (info->var.vmode & FB_VMODE_INTERLACED)
522 svga_wcrt_mask(0x42, 0x20, 0x20);
523 else
524 svga_wcrt_mask(0x42, 0x00, 0x20);
525
526 /* Disable hardware graphics cursor */
527 svga_wcrt_mask(0x45, 0x00, 0x01);
528 /* Disable Streams engine */
529 svga_wcrt_mask(0x67, 0x00, 0x0C);
530
531 mode = svga_match_format(s3fb_formats, &(info->var), &(info->fix));
532
533 /* S3 virge DX hack */
534 if (par->chip == CHIP_375_VIRGE_DX) {
535 vga_wcrt(NULL, 0x86, 0x80);
536 vga_wcrt(NULL, 0x90, 0x00);
537 }
538
539 /* S3 virge VX hack */
540 if (par->chip == CHIP_988_VIRGE_VX) {
541 vga_wcrt(NULL, 0x50, 0x00);
542 vga_wcrt(NULL, 0x67, 0x50);
543
544 vga_wcrt(NULL, 0x63, (mode <= 2) ? 0x90 : 0x09);
545 vga_wcrt(NULL, 0x66, 0x90);
546 }
547
548 svga_wcrt_mask(0x31, 0x00, 0x40);
549 multiplex = 0;
550 hmul = 1;
551
552 /* Set mode-specific register values */
553 switch (mode) {
554 case 0:
555 pr_debug("fb%d: text mode\n", info->node);
556 svga_set_textmode_vga_regs();
557
558 /* Set additional registers like in 8-bit mode */
559 svga_wcrt_mask(0x50, 0x00, 0x30);
560 svga_wcrt_mask(0x67, 0x00, 0xF0);
561
562 /* Disable enhanced mode */
563 svga_wcrt_mask(0x3A, 0x00, 0x30);
564
565 if (fasttext) {
566 pr_debug("fb%d: high speed text mode set\n", info->node);
567 svga_wcrt_mask(0x31, 0x40, 0x40);
568 }
569 break;
570 case 1:
571 pr_debug("fb%d: 4 bit pseudocolor\n", info->node);
572 vga_wgfx(NULL, VGA_GFX_MODE, 0x40);
573
574 /* Set additional registers like in 8-bit mode */
575 svga_wcrt_mask(0x50, 0x00, 0x30);
576 svga_wcrt_mask(0x67, 0x00, 0xF0);
577
578 /* disable enhanced mode */
579 svga_wcrt_mask(0x3A, 0x00, 0x30);
580 break;
581 case 2:
582 pr_debug("fb%d: 4 bit pseudocolor, planar\n", info->node);
583
584 /* Set additional registers like in 8-bit mode */
585 svga_wcrt_mask(0x50, 0x00, 0x30);
586 svga_wcrt_mask(0x67, 0x00, 0xF0);
587
588 /* disable enhanced mode */
589 svga_wcrt_mask(0x3A, 0x00, 0x30);
590 break;
591 case 3:
592 pr_debug("fb%d: 8 bit pseudocolor\n", info->node);
593 if (info->var.pixclock > 20000) {
594 svga_wcrt_mask(0x50, 0x00, 0x30);
595 svga_wcrt_mask(0x67, 0x00, 0xF0);
596 } else {
597 svga_wcrt_mask(0x50, 0x00, 0x30);
598 svga_wcrt_mask(0x67, 0x10, 0xF0);
599 multiplex = 1;
600 }
601 break;
602 case 4:
603 pr_debug("fb%d: 5/5/5 truecolor\n", info->node);
604 if (par->chip == CHIP_988_VIRGE_VX) {
605 if (info->var.pixclock > 20000)
606 svga_wcrt_mask(0x67, 0x20, 0xF0);
607 else
608 svga_wcrt_mask(0x67, 0x30, 0xF0);
609 } else {
610 svga_wcrt_mask(0x50, 0x10, 0x30);
611 svga_wcrt_mask(0x67, 0x30, 0xF0);
612 hmul = 2;
613 }
614 break;
615 case 5:
616 pr_debug("fb%d: 5/6/5 truecolor\n", info->node);
617 if (par->chip == CHIP_988_VIRGE_VX) {
618 if (info->var.pixclock > 20000)
619 svga_wcrt_mask(0x67, 0x40, 0xF0);
620 else
621 svga_wcrt_mask(0x67, 0x50, 0xF0);
622 } else {
623 svga_wcrt_mask(0x50, 0x10, 0x30);
624 svga_wcrt_mask(0x67, 0x50, 0xF0);
625 hmul = 2;
626 }
627 break;
628 case 6:
629 /* VIRGE VX case */
630 pr_debug("fb%d: 8/8/8 truecolor\n", info->node);
631 svga_wcrt_mask(0x67, 0xD0, 0xF0);
632 break;
633 case 7:
634 pr_debug("fb%d: 8/8/8/8 truecolor\n", info->node);
635 svga_wcrt_mask(0x50, 0x30, 0x30);
636 svga_wcrt_mask(0x67, 0xD0, 0xF0);
637 break;
638 default:
639 printk(KERN_ERR "fb%d: unsupported mode - bug\n", info->node);
640 return -EINVAL;
641 }
642
643 if (par->chip != CHIP_988_VIRGE_VX) {
644 svga_wseq_mask(0x15, multiplex ? 0x10 : 0x00, 0x10);
645 svga_wseq_mask(0x18, multiplex ? 0x80 : 0x00, 0x80);
646 }
647
648 s3_set_pixclock(info, info->var.pixclock);
649 svga_set_timings(&s3_timing_regs, &(info->var), hmul, 1,
650 (info->var.vmode & FB_VMODE_DOUBLE) ? 2 : 1,
651 (info->var.vmode & FB_VMODE_INTERLACED) ? 2 : 1,
652 hmul, info->node);
653
654 /* Set interlaced mode start/end register */
655 value = info->var.xres + info->var.left_margin + info->var.right_margin + info->var.hsync_len;
656 value = ((value * hmul) / 8) - 5;
657 vga_wcrt(NULL, 0x3C, (value + 1) / 2);
658
659 memset((u8*)info->screen_base, 0x00, screen_size);
660 /* Device and screen back on */
661 svga_wcrt_mask(0x17, 0x80, 0x80);
662 svga_wseq_mask(0x01, 0x00, 0x20);
663
664 return 0;
665}
666
667/* Set a colour register */
668
669static int s3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
670 u_int transp, struct fb_info *fb)
671{
672 switch (fb->var.bits_per_pixel) {
673 case 0:
674 case 4:
675 if (regno >= 16)
676 return -EINVAL;
677
678 if ((fb->var.bits_per_pixel == 4) &&
679 (fb->var.nonstd == 0)) {
680 outb(0xF0, VGA_PEL_MSK);
681 outb(regno*16, VGA_PEL_IW);
682 } else {
683 outb(0x0F, VGA_PEL_MSK);
684 outb(regno, VGA_PEL_IW);
685 }
686 outb(red >> 10, VGA_PEL_D);
687 outb(green >> 10, VGA_PEL_D);
688 outb(blue >> 10, VGA_PEL_D);
689 break;
690 case 8:
691 if (regno >= 256)
692 return -EINVAL;
693
694 outb(0xFF, VGA_PEL_MSK);
695 outb(regno, VGA_PEL_IW);
696 outb(red >> 10, VGA_PEL_D);
697 outb(green >> 10, VGA_PEL_D);
698 outb(blue >> 10, VGA_PEL_D);
699 break;
700 case 16:
701 if (regno >= 16)
702 return -EINVAL;
703
704 if (fb->var.green.length == 5)
705 ((u32*)fb->pseudo_palette)[regno] = ((red & 0xF800) >> 1) |
706 ((green & 0xF800) >> 6) | ((blue & 0xF800) >> 11);
707 else if (fb->var.green.length == 6)
708 ((u32*)fb->pseudo_palette)[regno] = (red & 0xF800) |
709 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
710 else return -EINVAL;
711 break;
712 case 24:
713 case 32:
714 if (regno >= 16)
715 return -EINVAL;
716
717 ((u32*)fb->pseudo_palette)[regno] = ((transp & 0xFF00) << 16) | ((red & 0xFF00) << 8) |
718 (green & 0xFF00) | ((blue & 0xFF00) >> 8);
719 break;
720 default:
721 return -EINVAL;
722 }
723
724 return 0;
725}
726
727
728/* Set the display blanking state */
729
730static int s3fb_blank(int blank_mode, struct fb_info *info)
731{
732 switch (blank_mode) {
733 case FB_BLANK_UNBLANK:
734 pr_debug("fb%d: unblank\n", info->node);
735 svga_wcrt_mask(0x56, 0x00, 0x06);
736 svga_wseq_mask(0x01, 0x00, 0x20);
737 break;
738 case FB_BLANK_NORMAL:
739 pr_debug("fb%d: blank\n", info->node);
740 svga_wcrt_mask(0x56, 0x00, 0x06);
741 svga_wseq_mask(0x01, 0x20, 0x20);
742 break;
743 case FB_BLANK_HSYNC_SUSPEND:
744 pr_debug("fb%d: hsync\n", info->node);
745 svga_wcrt_mask(0x56, 0x02, 0x06);
746 svga_wseq_mask(0x01, 0x20, 0x20);
747 break;
748 case FB_BLANK_VSYNC_SUSPEND:
749 pr_debug("fb%d: vsync\n", info->node);
750 svga_wcrt_mask(0x56, 0x04, 0x06);
751 svga_wseq_mask(0x01, 0x20, 0x20);
752 break;
753 case FB_BLANK_POWERDOWN:
754 pr_debug("fb%d: sync down\n", info->node);
755 svga_wcrt_mask(0x56, 0x06, 0x06);
756 svga_wseq_mask(0x01, 0x20, 0x20);
757 break;
758 }
759
760 return 0;
761}
762
763
764/* Pan the display */
765
766static int s3fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info) {
767
768 unsigned int offset;
769
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 */
777 if (var->bits_per_pixel == 0) {
778 offset = (var->yoffset / 16) * (var->xres_virtual / 2) + (var->xoffset / 2);
779 offset = offset >> 2;
780 } else {
781 offset = (var->yoffset * info->fix.line_length) +
782 (var->xoffset * var->bits_per_pixel / 8);
783 offset = offset >> 2;
784 }
785
786 /* Set the offset */
787 svga_wcrt_multi(s3_start_address_regs, offset);
788
789 return 0;
790}
791
792/* ------------------------------------------------------------------------- */
793
794/* Frame buffer operations */
795
796static struct fb_ops s3fb_ops = {
797 .owner = THIS_MODULE,
798 .fb_open = s3fb_open,
799 .fb_release = s3fb_release,
800 .fb_check_var = s3fb_check_var,
801 .fb_set_par = s3fb_set_par,
802 .fb_setcolreg = s3fb_setcolreg,
803 .fb_blank = s3fb_blank,
804 .fb_pan_display = s3fb_pan_display,
805 .fb_fillrect = s3fb_fillrect,
806 .fb_copyarea = cfb_copyarea,
807 .fb_imageblit = s3fb_imageblit,
808};
809
810/* ------------------------------------------------------------------------- */
811
812static int __devinit s3_identification(int chip)
813{
814 if (chip == CHIP_XXX_TRIO) {
815 u8 cr30 = vga_rcrt(NULL, 0x30);
816 u8 cr2e = vga_rcrt(NULL, 0x2e);
817 u8 cr2f = vga_rcrt(NULL, 0x2f);
818
819 if ((cr30 == 0xE0) || (cr30 == 0xE1)) {
820 if (cr2e == 0x10)
821 return CHIP_732_TRIO32;
822 if (cr2e == 0x11) {
823 if (! (cr2f & 0x40))
824 return CHIP_764_TRIO64;
825 else
826 return CHIP_765_TRIO64VP;
827 }
828 }
829 }
830
831 if (chip == CHIP_XXX_TRIO64V2_DXGX) {
832 u8 cr6f = vga_rcrt(NULL, 0x6f);
833
834 if (! (cr6f & 0x01))
835 return CHIP_775_TRIO64V2_DX;
836 else
837 return CHIP_785_TRIO64V2_GX;
838 }
839
840 if (chip == CHIP_XXX_VIRGE_DXGX) {
841 u8 cr6f = vga_rcrt(NULL, 0x6f);
842
843 if (! (cr6f & 0x01))
844 return CHIP_375_VIRGE_DX;
845 else
846 return CHIP_385_VIRGE_GX;
847 }
848
849 return CHIP_UNKNOWN;
850}
851
852
853/* PCI probe */
854
855static int __devinit s3_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
856{
857 struct fb_info *info;
858 struct s3fb_info *par;
859 int rc;
860 u8 regval, cr38, cr39;
861
862 /* Ignore secondary VGA device because there is no VGA arbitration */
863 if (! svga_primary_device(dev)) {
864 dev_info(&(dev->dev), "ignoring secondary device\n");
865 return -ENODEV;
866 }
867
868 /* Allocate and fill driver data structure */
869 info = framebuffer_alloc(sizeof(struct s3fb_info), NULL);
870 if (!info) {
871 dev_err(&(dev->dev), "cannot allocate memory\n");
872 return -ENOMEM;
873 }
874
875 par = info->par;
876 mutex_init(&par->open_lock);
877
878 info->flags = FBINFO_PARTIAL_PAN_OK | FBINFO_HWACCEL_YPAN;
879 info->fbops = &s3fb_ops;
880
881 /* Prepare PCI device */
882 rc = pci_enable_device(dev);
883 if (rc < 0) {
884 dev_err(&(dev->dev), "cannot enable PCI device\n");
885 goto err_enable_device;
886 }
887
888 rc = pci_request_regions(dev, "s3fb");
889 if (rc < 0) {
890 dev_err(&(dev->dev), "cannot reserve framebuffer region\n");
891 goto err_request_regions;
892 }
893
894
895 info->fix.smem_start = pci_resource_start(dev, 0);
896 info->fix.smem_len = pci_resource_len(dev, 0);
897
898 /* Map physical IO memory address into kernel space */
899 info->screen_base = pci_iomap(dev, 0, 0);
900 if (! info->screen_base) {
901 rc = -ENOMEM;
902 dev_err(&(dev->dev), "iomap for framebuffer failed\n");
903 goto err_iomap;
904 }
905
906 /* Unlock regs */
907 cr38 = vga_rcrt(NULL, 0x38);
908 cr39 = vga_rcrt(NULL, 0x39);
909 vga_wseq(NULL, 0x08, 0x06);
910 vga_wcrt(NULL, 0x38, 0x48);
911 vga_wcrt(NULL, 0x39, 0xA5);
912
913 /* Find how many physical memory there is on card */
914 /* 0x36 register is accessible even if other registers are locked */
915 regval = vga_rcrt(NULL, 0x36);
916 info->screen_size = s3_memsizes[regval >> 5] << 10;
917 info->fix.smem_len = info->screen_size;
918
919 par->chip = id->driver_data & CHIP_MASK;
920 par->rev = vga_rcrt(NULL, 0x2f);
921 if (par->chip & CHIP_UNDECIDED_FLAG)
922 par->chip = s3_identification(par->chip);
923
924 /* Find MCLK frequency */
925 regval = vga_rseq(NULL, 0x10);
926 par->mclk_freq = ((vga_rseq(NULL, 0x11) + 2) * 14318) / ((regval & 0x1F) + 2);
927 par->mclk_freq = par->mclk_freq >> (regval >> 5);
928
929 /* Restore locks */
930 vga_wcrt(NULL, 0x38, cr38);
931 vga_wcrt(NULL, 0x39, cr39);
932
933 strcpy(info->fix.id, s3_names [par->chip]);
934 info->fix.mmio_start = 0;
935 info->fix.mmio_len = 0;
936 info->fix.type = FB_TYPE_PACKED_PIXELS;
937 info->fix.visual = FB_VISUAL_PSEUDOCOLOR;
938 info->fix.ypanstep = 0;
939 info->fix.accel = FB_ACCEL_NONE;
940 info->pseudo_palette = (void*) (par->pseudo_palette);
941
942 /* Prepare startup mode */
943 rc = fb_find_mode(&(info->var), info, mode, NULL, 0, NULL, 8);
944 if (! ((rc == 1) || (rc == 2))) {
945 rc = -EINVAL;
946 dev_err(&(dev->dev), "mode %s not found\n", mode);
947 goto err_find_mode;
948 }
949
950 rc = fb_alloc_cmap(&info->cmap, 256, 0);
951 if (rc < 0) {
952 dev_err(&(dev->dev), "cannot allocate colormap\n");
953 goto err_alloc_cmap;
954 }
955
956 rc = register_framebuffer(info);
957 if (rc < 0) {
958 dev_err(&(dev->dev), "cannot register framebuffer\n");
959 goto err_reg_fb;
960 }
961
962 printk(KERN_INFO "fb%d: %s on %s, %d MB RAM, %d MHz MCLK\n", info->node, info->fix.id,
963 pci_name(dev), info->fix.smem_len >> 20, (par->mclk_freq + 500) / 1000);
964
965 if (par->chip == CHIP_UNKNOWN)
966 printk(KERN_INFO "fb%d: unknown chip, CR2D=%x, CR2E=%x, CRT2F=%x, CRT30=%x\n",
967 info->node, vga_rcrt(NULL, 0x2d), vga_rcrt(NULL, 0x2e),
968 vga_rcrt(NULL, 0x2f), vga_rcrt(NULL, 0x30));
969
970 /* Record a reference to the driver data */
971 pci_set_drvdata(dev, info);
972
973#ifdef CONFIG_MTRR
974 if (mtrr) {
975 par->mtrr_reg = -1;
976 par->mtrr_reg = mtrr_add(info->fix.smem_start, info->fix.smem_len, MTRR_TYPE_WRCOMB, 1);
977 }
978#endif
979
980 return 0;
981
982 /* Error handling */
983err_reg_fb:
984 fb_dealloc_cmap(&info->cmap);
985err_alloc_cmap:
986err_find_mode:
987 pci_iounmap(dev, info->screen_base);
988err_iomap:
989 pci_release_regions(dev);
990err_request_regions:
991/* pci_disable_device(dev); */
992err_enable_device:
993 framebuffer_release(info);
994 return rc;
995}
996
997
998/* PCI remove */
999
1000static void __devexit s3_pci_remove(struct pci_dev *dev)
1001{
1002 struct fb_info *info = pci_get_drvdata(dev);
1003 struct s3fb_info *par = info->par;
1004
1005 if (info) {
1006
1007#ifdef CONFIG_MTRR
1008 if (par->mtrr_reg >= 0) {
1009 mtrr_del(par->mtrr_reg, 0, 0);
1010 par->mtrr_reg = -1;
1011 }
1012#endif
1013
1014 unregister_framebuffer(info);
1015 fb_dealloc_cmap(&info->cmap);
1016
1017 pci_iounmap(dev, info->screen_base);
1018 pci_release_regions(dev);
1019/* pci_disable_device(dev); */
1020
1021 pci_set_drvdata(dev, NULL);
1022 framebuffer_release(info);
1023 }
1024}
1025
1026/* PCI suspend */
1027
1028static int s3_pci_suspend(struct pci_dev* dev, pm_message_t state)
1029{
1030 struct fb_info *info = pci_get_drvdata(dev);
1031 struct s3fb_info *par = info->par;
1032
1033 dev_info(&(dev->dev), "suspend\n");
1034
1035 acquire_console_sem();
1036 mutex_lock(&(par->open_lock));
1037
1038 if ((state.event == PM_EVENT_FREEZE) || (par->ref_count == 0)) {
1039 mutex_unlock(&(par->open_lock));
1040 release_console_sem();
1041 return 0;
1042 }
1043
1044 fb_set_suspend(info, 1);
1045
1046 pci_save_state(dev);
1047 pci_disable_device(dev);
1048 pci_set_power_state(dev, pci_choose_state(dev, state));
1049
1050 mutex_unlock(&(par->open_lock));
1051 release_console_sem();
1052
1053 return 0;
1054}
1055
1056
1057/* PCI resume */
1058
1059static int s3_pci_resume(struct pci_dev* dev)
1060{
1061 struct fb_info *info = pci_get_drvdata(dev);
1062 struct s3fb_info *par = info->par;
1063
1064 dev_info(&(dev->dev), "resume\n");
1065
1066 acquire_console_sem();
1067 mutex_lock(&(par->open_lock));
1068
1069 if (par->ref_count == 0) {
1070 mutex_unlock(&(par->open_lock));
1071 release_console_sem();
1072 return 0;
1073 }
1074
1075 pci_set_power_state(dev, PCI_D0);
1076 pci_restore_state(dev);
1077 pci_enable_device(dev);
1078 pci_set_master(dev);
1079
1080 s3fb_set_par(info);
1081 fb_set_suspend(info, 0);
1082
1083 mutex_unlock(&(par->open_lock));
1084 release_console_sem();
1085
1086 return 0;
1087}
1088
1089
1090/* List of boards that we are trying to support */
1091
1092static struct pci_device_id s3_devices[] __devinitdata = {
1093 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8810), .driver_data = CHIP_XXX_TRIO},
1094 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8811), .driver_data = CHIP_XXX_TRIO},
1095 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8812), .driver_data = CHIP_M65_AURORA64VP},
1096 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8814), .driver_data = CHIP_767_TRIO64UVP},
1097 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8901), .driver_data = CHIP_XXX_TRIO64V2_DXGX},
1098 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8902), .driver_data = CHIP_551_PLATO_PX},
1099
1100 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x5631), .driver_data = CHIP_325_VIRGE},
1101 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x883D), .driver_data = CHIP_988_VIRGE_VX},
1102 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A01), .driver_data = CHIP_XXX_VIRGE_DXGX},
1103 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A10), .driver_data = CHIP_356_VIRGE_GX2},
1104 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A11), .driver_data = CHIP_357_VIRGE_GX2P},
1105 {PCI_DEVICE(PCI_VENDOR_ID_S3, 0x8A12), .driver_data = CHIP_359_VIRGE_GX2P},
1106
1107 {0, 0, 0, 0, 0, 0, 0}
1108};
1109
1110
1111MODULE_DEVICE_TABLE(pci, s3_devices);
1112
1113static struct pci_driver s3fb_pci_driver = {
1114 .name = "s3fb",
1115 .id_table = s3_devices,
1116 .probe = s3_pci_probe,
1117 .remove = __devexit_p(s3_pci_remove),
1118 .suspend = s3_pci_suspend,
1119 .resume = s3_pci_resume,
1120};
1121
1122/* Parse user speficied options */
1123
1124#ifndef MODULE
1125static int __init s3fb_setup(char *options)
1126{
1127 char *opt;
1128
1129 if (!options || !*options)
1130 return 0;
1131
1132 while ((opt = strsep(&options, ",")) != NULL) {
1133
1134 if (!*opt)
1135 continue;
1136#ifdef CONFIG_MTRR
1137 else if (!strcmp(opt, "mtrr:"))
1138 mtrr = simple_strtoul(opt + 5, NULL, 0);
1139#endif
1140 else if (!strcmp(opt, "fasttext:"))
1141 mtrr = simple_strtoul(opt + 9, NULL, 0);
1142 else
1143 mode = opt;
1144 }
1145
1146 return 0;
1147}
1148#endif
1149
1150/* Cleanup */
1151
1152static void __exit s3fb_cleanup(void)
1153{
1154 pr_debug("s3fb: cleaning up\n");
1155 pci_unregister_driver(&s3fb_pci_driver);
1156}
1157
1158/* Driver Initialisation */
1159
1160static int __init s3fb_init(void)
1161{
1162
1163#ifndef MODULE
1164 char *option = NULL;
1165
1166 if (fb_get_options("s3fb", &option))
1167 return -ENODEV;
1168 s3fb_setup(option);
1169#endif
1170
1171 pr_debug("s3fb: initializing\n");
1172 return pci_register_driver(&s3fb_pci_driver);
1173}
1174
1175/* ------------------------------------------------------------------------- */
1176
1177/* Modularization */
1178
1179module_init(s3fb_init);
1180module_exit(s3fb_cleanup);
diff --git a/drivers/video/sa1100fb.h b/drivers/video/sa1100fb.h
index 0b07f6ae336..48066ef3af0 100644
--- a/drivers/video/sa1100fb.h
+++ b/drivers/video/sa1100fb.h
@@ -110,9 +110,7 @@ struct sa1100fb_info {
110#endif 110#endif
111}; 111};
112 112
113#define __type_entry(ptr,type,member) ((type *)((char *)(ptr)-offsetof(type,member))) 113#define TO_INF(ptr,member) container_of(ptr,struct sa1100fb_info,member)
114
115#define TO_INF(ptr,member) __type_entry(ptr,struct sa1100fb_info,member)
116 114
117#define SA1100_PALETTE_MODE_VAL(bpp) (((bpp) & 0x018) << 9) 115#define SA1100_PALETTE_MODE_VAL(bpp) (((bpp) & 0x018) << 9)
118 116
diff --git a/drivers/video/savage/savagefb_driver.c b/drivers/video/savage/savagefb_driver.c
index 82b3deaae02..4afa30522fd 100644
--- a/drivers/video/savage/savagefb_driver.c
+++ b/drivers/video/savage/savagefb_driver.c
@@ -833,7 +833,8 @@ static void savage_set_default_par(struct savagefb_par *par,
833 vga_out8(0x3d5, cr66, par); 833 vga_out8(0x3d5, cr66, par);
834} 834}
835 835
836static void savage_update_var(struct fb_var_screeninfo *var, struct fb_videomode *modedb) 836static void savage_update_var(struct fb_var_screeninfo *var,
837 const struct fb_videomode *modedb)
837{ 838{
838 var->xres = var->xres_virtual = modedb->xres; 839 var->xres = var->xres_virtual = modedb->xres;
839 var->yres = modedb->yres; 840 var->yres = modedb->yres;
@@ -902,7 +903,7 @@ static int savagefb_check_var(struct fb_var_screeninfo *var,
902 } 903 }
903 904
904 if (!mode_valid) { 905 if (!mode_valid) {
905 struct fb_videomode *mode; 906 const struct fb_videomode *mode;
906 907
907 mode = fb_find_best_mode(var, &info->modelist); 908 mode = fb_find_best_mode(var, &info->modelist);
908 if (mode) { 909 if (mode) {
@@ -2206,11 +2207,10 @@ static int __devinit savagefb_probe(struct pci_dev* dev,
2206 info->monspecs.modedb, info->monspecs.modedb_len, 2207 info->monspecs.modedb, info->monspecs.modedb_len,
2207 NULL, 8); 2208 NULL, 8);
2208 } else if (info->monspecs.modedb != NULL) { 2209 } else if (info->monspecs.modedb != NULL) {
2209 struct fb_videomode *modedb; 2210 const struct fb_videomode *mode;
2210 2211
2211 modedb = fb_find_best_display(&info->monspecs, 2212 mode = fb_find_best_display(&info->monspecs, &info->modelist);
2212 &info->modelist); 2213 savage_update_var(&info->var, mode);
2213 savage_update_var(&info->var, modedb);
2214 } 2214 }
2215 2215
2216 /* maximize virtual vertical length */ 2216 /* maximize virtual vertical length */
diff --git a/drivers/video/sis/init.c b/drivers/video/sis/init.c
index 2ab3868efde..c311ad3c368 100644
--- a/drivers/video/sis/init.c
+++ b/drivers/video/sis/init.c
@@ -317,23 +317,23 @@ InitTo310Pointer(struct SiS_Private *SiS_Pr)
317} 317}
318#endif 318#endif
319 319
320BOOLEAN 320bool
321SiSInitPtr(struct SiS_Private *SiS_Pr) 321SiSInitPtr(struct SiS_Private *SiS_Pr)
322{ 322{
323 if(SiS_Pr->ChipType < SIS_315H) { 323 if(SiS_Pr->ChipType < SIS_315H) {
324#ifdef SIS300 324#ifdef SIS300
325 InitTo300Pointer(SiS_Pr); 325 InitTo300Pointer(SiS_Pr);
326#else 326#else
327 return FALSE; 327 return false;
328#endif 328#endif
329 } else { 329 } else {
330#ifdef SIS315H 330#ifdef SIS315H
331 InitTo310Pointer(SiS_Pr); 331 InitTo310Pointer(SiS_Pr);
332#else 332#else
333 return FALSE; 333 return false;
334#endif 334#endif
335 } 335 }
336 return TRUE; 336 return true;
337} 337}
338 338
339/*********************************************/ 339/*********************************************/
@@ -345,7 +345,7 @@ static
345#endif 345#endif
346unsigned short 346unsigned short
347SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, 347SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
348 int Depth, BOOLEAN FSTN, int LCDwidth, int LCDheight) 348 int Depth, bool FSTN, int LCDwidth, int LCDheight)
349{ 349{
350 unsigned short ModeIndex = 0; 350 unsigned short ModeIndex = 0;
351 351
@@ -483,7 +483,7 @@ SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
483 483
484unsigned short 484unsigned short
485SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, 485SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
486 int Depth, BOOLEAN FSTN, unsigned short CustomT, int LCDwidth, int LCDheight, 486 int Depth, bool FSTN, unsigned short CustomT, int LCDwidth, int LCDheight,
487 unsigned int VBFlags2) 487 unsigned int VBFlags2)
488{ 488{
489 unsigned short ModeIndex = 0; 489 unsigned short ModeIndex = 0;
@@ -873,7 +873,7 @@ SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDispl
873 break; 873 break;
874 } 874 }
875 875
876 return SiS_GetModeID(VGAEngine, 0, HDisplay, VDisplay, Depth, FALSE, 0, 0); 876 return SiS_GetModeID(VGAEngine, 0, HDisplay, VDisplay, Depth, false, 0, 0);
877} 877}
878 878
879 879
@@ -1020,12 +1020,12 @@ SiS_GetSysFlags(struct SiS_Private *SiS_Pr)
1020 1020
1021 /* 661 and newer: NEVER write non-zero to SR11[7:4] */ 1021 /* 661 and newer: NEVER write non-zero to SR11[7:4] */
1022 /* (SR11 is used for DDC and in enable/disablebridge) */ 1022 /* (SR11 is used for DDC and in enable/disablebridge) */
1023 SiS_Pr->SiS_SensibleSR11 = FALSE; 1023 SiS_Pr->SiS_SensibleSR11 = false;
1024 SiS_Pr->SiS_MyCR63 = 0x63; 1024 SiS_Pr->SiS_MyCR63 = 0x63;
1025 if(SiS_Pr->ChipType >= SIS_330) { 1025 if(SiS_Pr->ChipType >= SIS_330) {
1026 SiS_Pr->SiS_MyCR63 = 0x53; 1026 SiS_Pr->SiS_MyCR63 = 0x53;
1027 if(SiS_Pr->ChipType >= SIS_661) { 1027 if(SiS_Pr->ChipType >= SIS_661) {
1028 SiS_Pr->SiS_SensibleSR11 = TRUE; 1028 SiS_Pr->SiS_SensibleSR11 = true;
1029 } 1029 }
1030 } 1030 }
1031 1031
@@ -1253,7 +1253,7 @@ SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1253/* HELPER: Determine ROM usage */ 1253/* HELPER: Determine ROM usage */
1254/*********************************************/ 1254/*********************************************/
1255 1255
1256BOOLEAN 1256bool
1257SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr) 1257SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr)
1258{ 1258{
1259 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 1259 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
@@ -1261,16 +1261,16 @@ SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr)
1261 1261
1262 if(SiS_Pr->ChipType >= XGI_20) { 1262 if(SiS_Pr->ChipType >= XGI_20) {
1263 /* XGI ROMs don't qualify */ 1263 /* XGI ROMs don't qualify */
1264 return FALSE; 1264 return false;
1265 } else if(SiS_Pr->ChipType >= SIS_761) { 1265 } else if(SiS_Pr->ChipType >= SIS_761) {
1266 /* I very much assume 761, 340 and newer will use new layout */ 1266 /* I very much assume 761, 340 and newer will use new layout */
1267 return TRUE; 1267 return true;
1268 } else if(SiS_Pr->ChipType >= SIS_661) { 1268 } else if(SiS_Pr->ChipType >= SIS_661) {
1269 if((ROMAddr[0x1a] == 'N') && 1269 if((ROMAddr[0x1a] == 'N') &&
1270 (ROMAddr[0x1b] == 'e') && 1270 (ROMAddr[0x1b] == 'e') &&
1271 (ROMAddr[0x1c] == 'w') && 1271 (ROMAddr[0x1c] == 'w') &&
1272 (ROMAddr[0x1d] == 'V')) { 1272 (ROMAddr[0x1d] == 'V')) {
1273 return TRUE; 1273 return true;
1274 } 1274 }
1275 romversoffs = ROMAddr[0x16] | (ROMAddr[0x17] << 8); 1275 romversoffs = ROMAddr[0x16] | (ROMAddr[0x17] << 8);
1276 if(romversoffs) { 1276 if(romversoffs) {
@@ -1280,17 +1280,17 @@ SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr)
1280 } 1280 }
1281 } 1281 }
1282 if((romvmaj != 0) || (romvmin >= 92)) { 1282 if((romvmaj != 0) || (romvmin >= 92)) {
1283 return TRUE; 1283 return true;
1284 } 1284 }
1285 } else if(IS_SIS650740) { 1285 } else if(IS_SIS650740) {
1286 if((ROMAddr[0x1a] == 'N') && 1286 if((ROMAddr[0x1a] == 'N') &&
1287 (ROMAddr[0x1b] == 'e') && 1287 (ROMAddr[0x1b] == 'e') &&
1288 (ROMAddr[0x1c] == 'w') && 1288 (ROMAddr[0x1c] == 'w') &&
1289 (ROMAddr[0x1d] == 'V')) { 1289 (ROMAddr[0x1d] == 'V')) {
1290 return TRUE; 1290 return true;
1291 } 1291 }
1292 } 1292 }
1293 return FALSE; 1293 return false;
1294} 1294}
1295 1295
1296static void 1296static void
@@ -1299,8 +1299,8 @@ SiSDetermineROMUsage(struct SiS_Private *SiS_Pr)
1299 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 1299 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1300 unsigned short romptr = 0; 1300 unsigned short romptr = 0;
1301 1301
1302 SiS_Pr->SiS_UseROM = FALSE; 1302 SiS_Pr->SiS_UseROM = false;
1303 SiS_Pr->SiS_ROMNew = FALSE; 1303 SiS_Pr->SiS_ROMNew = false;
1304 SiS_Pr->SiS_PWDOffset = 0; 1304 SiS_Pr->SiS_PWDOffset = 0;
1305 1305
1306 if(SiS_Pr->ChipType >= XGI_20) return; 1306 if(SiS_Pr->ChipType >= XGI_20) return;
@@ -1312,15 +1312,15 @@ SiSDetermineROMUsage(struct SiS_Private *SiS_Pr)
1312 * of the BIOS image. 1312 * of the BIOS image.
1313 */ 1313 */
1314 if((ROMAddr[3] == 0xe9) && ((ROMAddr[5] << 8) | ROMAddr[4]) > 0x21a) 1314 if((ROMAddr[3] == 0xe9) && ((ROMAddr[5] << 8) | ROMAddr[4]) > 0x21a)
1315 SiS_Pr->SiS_UseROM = TRUE; 1315 SiS_Pr->SiS_UseROM = true;
1316 } else if(SiS_Pr->ChipType < SIS_315H) { 1316 } else if(SiS_Pr->ChipType < SIS_315H) {
1317 /* Sony's VAIO BIOS 1.09 follows the standard, so perhaps 1317 /* Sony's VAIO BIOS 1.09 follows the standard, so perhaps
1318 * the others do as well 1318 * the others do as well
1319 */ 1319 */
1320 SiS_Pr->SiS_UseROM = TRUE; 1320 SiS_Pr->SiS_UseROM = true;
1321 } else { 1321 } else {
1322 /* 315/330 series stick to the standard(s) */ 1322 /* 315/330 series stick to the standard(s) */
1323 SiS_Pr->SiS_UseROM = TRUE; 1323 SiS_Pr->SiS_UseROM = true;
1324 if((SiS_Pr->SiS_ROMNew = SiSDetermineROMLayout661(SiS_Pr))) { 1324 if((SiS_Pr->SiS_ROMNew = SiSDetermineROMLayout661(SiS_Pr))) {
1325 SiS_Pr->SiS_EMIOffset = 14; 1325 SiS_Pr->SiS_EMIOffset = 14;
1326 SiS_Pr->SiS_PWDOffset = 17; 1326 SiS_Pr->SiS_PWDOffset = 17;
@@ -1488,7 +1488,7 @@ SiS_GetVBType(struct SiS_Private *SiS_Pr)
1488/*********************************************/ 1488/*********************************************/
1489 1489
1490#ifdef SIS_LINUX_KERNEL 1490#ifdef SIS_LINUX_KERNEL
1491static BOOLEAN 1491static bool
1492SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1492SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1493 unsigned short ModeIdIndex) 1493 unsigned short ModeIdIndex)
1494{ 1494{
@@ -1496,10 +1496,10 @@ SiS_CheckMemorySize(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1496 unsigned short modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex); 1496 unsigned short modeflag = SiS_GetModeFlag(SiS_Pr, ModeNo, ModeIdIndex);
1497 unsigned short memorysize = ((modeflag & MemoryInfoFlag) >> MemorySizeShift) + 1; 1497 unsigned short memorysize = ((modeflag & MemoryInfoFlag) >> MemorySizeShift) + 1;
1498 1498
1499 if(!AdapterMemSize) return TRUE; 1499 if(!AdapterMemSize) return true;
1500 1500
1501 if(AdapterMemSize < memorysize) return FALSE; 1501 if(AdapterMemSize < memorysize) return false;
1502 return TRUE; 1502 return true;
1503} 1503}
1504#endif 1504#endif
1505 1505
@@ -1605,7 +1605,7 @@ SiS_ClearBuffer(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
1605/* HELPER: SearchModeID */ 1605/* HELPER: SearchModeID */
1606/*********************************************/ 1606/*********************************************/
1607 1607
1608BOOLEAN 1608bool
1609SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo, 1609SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
1610 unsigned short *ModeIdIndex) 1610 unsigned short *ModeIdIndex)
1611{ 1611{
@@ -1617,7 +1617,7 @@ SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
1617 1617
1618 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) { 1618 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
1619 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == (*ModeNo)) break; 1619 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == (*ModeNo)) break;
1620 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == 0xFF) return FALSE; 1620 if(SiS_Pr->SiS_SModeIDTable[(*ModeIdIndex)].St_ModeID == 0xFF) return false;
1621 } 1621 }
1622 1622
1623 if((*ModeNo) == 0x07) { 1623 if((*ModeNo) == 0x07) {
@@ -1635,11 +1635,11 @@ SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
1635 1635
1636 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) { 1636 for((*ModeIdIndex) = 0; ;(*ModeIdIndex)++) {
1637 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == (*ModeNo)) break; 1637 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == (*ModeNo)) break;
1638 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == 0xFF) return FALSE; 1638 if(SiS_Pr->SiS_EModeIDTable[(*ModeIdIndex)].Ext_ModeID == 0xFF) return false;
1639 } 1639 }
1640 1640
1641 } 1641 }
1642 return TRUE; 1642 return true;
1643} 1643}
1644 1644
1645/*********************************************/ 1645/*********************************************/
@@ -1696,13 +1696,13 @@ SiS_GetRefCRT1CRTC(struct SiS_Private *SiS_Pr, unsigned short Index, int UseWide
1696/* HELPER: LowModeTests */ 1696/* HELPER: LowModeTests */
1697/*********************************************/ 1697/*********************************************/
1698 1698
1699static BOOLEAN 1699static bool
1700SiS_DoLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo) 1700SiS_DoLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
1701{ 1701{
1702 unsigned short temp, temp1, temp2; 1702 unsigned short temp, temp1, temp2;
1703 1703
1704 if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12)) 1704 if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12))
1705 return TRUE; 1705 return true;
1706 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x11); 1706 temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x11);
1707 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80); 1707 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80);
1708 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00); 1708 temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x00);
@@ -1712,13 +1712,13 @@ SiS_DoLowModeTest(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
1712 SiS_SetReg(SiS_Pr->SiS_P3d4,0x11,temp); 1712 SiS_SetReg(SiS_Pr->SiS_P3d4,0x11,temp);
1713 if((SiS_Pr->ChipType >= SIS_315H) || 1713 if((SiS_Pr->ChipType >= SIS_315H) ||
1714 (SiS_Pr->ChipType == SIS_300)) { 1714 (SiS_Pr->ChipType == SIS_300)) {
1715 if(temp2 == 0x55) return FALSE; 1715 if(temp2 == 0x55) return false;
1716 else return TRUE; 1716 else return true;
1717 } else { 1717 } else {
1718 if(temp2 != 0x55) return TRUE; 1718 if(temp2 != 0x55) return true;
1719 else { 1719 else {
1720 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01); 1720 SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01);
1721 return FALSE; 1721 return false;
1722 } 1722 }
1723 } 1723 }
1724} 1724}
@@ -3237,14 +3237,14 @@ static void
3237SiS_SetPitch(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn) 3237SiS_SetPitch(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
3238{ 3238{
3239 SISPtr pSiS = SISPTR(pScrn); 3239 SISPtr pSiS = SISPTR(pScrn);
3240 BOOLEAN isslavemode = FALSE; 3240 bool isslavemode = false;
3241 3241
3242 if( (pSiS->VBFlags2 & VB2_VIDEOBRIDGE) && 3242 if( (pSiS->VBFlags2 & VB2_VIDEOBRIDGE) &&
3243 ( ((pSiS->VGAEngine == SIS_300_VGA) && 3243 ( ((pSiS->VGAEngine == SIS_300_VGA) &&
3244 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0xa0) == 0x20) || 3244 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0xa0) == 0x20) ||
3245 ((pSiS->VGAEngine == SIS_315_VGA) && 3245 ((pSiS->VGAEngine == SIS_315_VGA) &&
3246 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x50) == 0x10) ) ) { 3246 (SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x50) == 0x10) ) ) {
3247 isslavemode = TRUE; 3247 isslavemode = true;
3248 } 3248 }
3249 3249
3250 /* We need to set pitch for CRT1 if bridge is in slave mode, too */ 3250 /* We need to set pitch for CRT1 if bridge is in slave mode, too */
@@ -3264,10 +3264,10 @@ SiS_SetPitch(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn)
3264 3264
3265#ifdef SIS_XORG_XF86 3265#ifdef SIS_XORG_XF86
3266/* We need pScrn for setting the pitch correctly */ 3266/* We need pScrn for setting the pitch correctly */
3267BOOLEAN 3267bool
3268SiSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, unsigned short ModeNo, BOOLEAN dosetpitch) 3268SiSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, unsigned short ModeNo, bool dosetpitch)
3269#else 3269#else
3270BOOLEAN 3270bool
3271SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo) 3271SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3272#endif 3272#endif
3273{ 3273{
@@ -3277,8 +3277,8 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3277#ifdef SIS_LINUX_KERNEL 3277#ifdef SIS_LINUX_KERNEL
3278 unsigned short KeepLockReg; 3278 unsigned short KeepLockReg;
3279 3279
3280 SiS_Pr->UseCustomMode = FALSE; 3280 SiS_Pr->UseCustomMode = false;
3281 SiS_Pr->CRT1UsesCustomMode = FALSE; 3281 SiS_Pr->CRT1UsesCustomMode = false;
3282#endif 3282#endif
3283 3283
3284 SiS_Pr->SiS_flag_clearbuffer = 0; 3284 SiS_Pr->SiS_flag_clearbuffer = 0;
@@ -3317,7 +3317,7 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3317 SiS_UnLockCRT2(SiS_Pr); 3317 SiS_UnLockCRT2(SiS_Pr);
3318 3318
3319 if(!SiS_Pr->UseCustomMode) { 3319 if(!SiS_Pr->UseCustomMode) {
3320 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE; 3320 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
3321 } else { 3321 } else {
3322 ModeIdIndex = 0; 3322 ModeIdIndex = 0;
3323 } 3323 }
@@ -3347,18 +3347,18 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3347#ifdef SIS_LINUX_KERNEL 3347#ifdef SIS_LINUX_KERNEL
3348 /* Check memory size (kernel framebuffer driver only) */ 3348 /* Check memory size (kernel framebuffer driver only) */
3349 if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) { 3349 if(!SiS_CheckMemorySize(SiS_Pr, ModeNo, ModeIdIndex)) {
3350 return FALSE; 3350 return false;
3351 } 3351 }
3352#endif 3352#endif
3353 3353
3354 SiS_OpenCRTC(SiS_Pr); 3354 SiS_OpenCRTC(SiS_Pr);
3355 3355
3356 if(SiS_Pr->UseCustomMode) { 3356 if(SiS_Pr->UseCustomMode) {
3357 SiS_Pr->CRT1UsesCustomMode = TRUE; 3357 SiS_Pr->CRT1UsesCustomMode = true;
3358 SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock; 3358 SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock;
3359 SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag; 3359 SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag;
3360 } else { 3360 } else {
3361 SiS_Pr->CRT1UsesCustomMode = FALSE; 3361 SiS_Pr->CRT1UsesCustomMode = false;
3362 } 3362 }
3363 3363
3364 /* Set mode on CRT1 */ 3364 /* Set mode on CRT1 */
@@ -3445,7 +3445,7 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3445 if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00); 3445 if(KeepLockReg != 0xA1) SiS_SetReg(SiS_Pr->SiS_P3c4,0x05,0x00);
3446#endif 3446#endif
3447 3447
3448 return TRUE; 3448 return true;
3449} 3449}
3450 3450
3451/*********************************************/ 3451/*********************************************/
@@ -3454,14 +3454,14 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
3454/*********************************************/ 3454/*********************************************/
3455 3455
3456#ifdef SIS_XORG_XF86 3456#ifdef SIS_XORG_XF86
3457BOOLEAN 3457bool
3458SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, 3458SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3459 DisplayModePtr mode, BOOLEAN IsCustom) 3459 DisplayModePtr mode, bool IsCustom)
3460{ 3460{
3461 SISPtr pSiS = SISPTR(pScrn); 3461 SISPtr pSiS = SISPTR(pScrn);
3462 unsigned short ModeNo = 0; 3462 unsigned short ModeNo = 0;
3463 3463
3464 SiS_Pr->UseCustomMode = FALSE; 3464 SiS_Pr->UseCustomMode = false;
3465 3465
3466 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) { 3466 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3467 3467
@@ -3475,13 +3475,13 @@ SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3475 3475
3476 /* Don't need vbflags here; checks done earlier */ 3476 /* Don't need vbflags here; checks done earlier */
3477 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags); 3477 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags);
3478 if(!ModeNo) return FALSE; 3478 if(!ModeNo) return false;
3479 3479
3480 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting standard mode 0x%x\n", ModeNo); 3480 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, "Setting standard mode 0x%x\n", ModeNo);
3481 3481
3482 } 3482 }
3483 3483
3484 return(SiSSetMode(SiS_Pr, pScrn, ModeNo, TRUE)); 3484 return(SiSSetMode(SiS_Pr, pScrn, ModeNo, true));
3485} 3485}
3486 3486
3487/*********************************************/ 3487/*********************************************/
@@ -3489,9 +3489,9 @@ SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3489/* for Dual-Head modes */ 3489/* for Dual-Head modes */
3490/*********************************************/ 3490/*********************************************/
3491 3491
3492BOOLEAN 3492bool
3493SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, 3493SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3494 DisplayModePtr mode, BOOLEAN IsCustom) 3494 DisplayModePtr mode, bool IsCustom)
3495{ 3495{
3496 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress; 3496 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3497 SISPtr pSiS = SISPTR(pScrn); 3497 SISPtr pSiS = SISPTR(pScrn);
@@ -3502,7 +3502,7 @@ SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3502 unsigned short ModeNo = 0; 3502 unsigned short ModeNo = 0;
3503 unsigned char backupreg = 0; 3503 unsigned char backupreg = 0;
3504 3504
3505 SiS_Pr->UseCustomMode = FALSE; 3505 SiS_Pr->UseCustomMode = false;
3506 3506
3507 /* Remember: Custom modes for CRT2 are ONLY supported 3507 /* Remember: Custom modes for CRT2 are ONLY supported
3508 * -) on the 30x/B/C, and 3508 * -) on the 30x/B/C, and
@@ -3516,7 +3516,7 @@ SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3516 } else { 3516 } else {
3517 3517
3518 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags); 3518 ModeNo = SiS_GetModeNumber(pScrn, mode, pSiS->VBFlags);
3519 if(!ModeNo) return FALSE; 3519 if(!ModeNo) return false;
3520 3520
3521 } 3521 }
3522 3522
@@ -3550,10 +3550,10 @@ SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3550 if(pSiSEnt->CRT1ModeNo == -1) { 3550 if(pSiSEnt->CRT1ModeNo == -1) {
3551 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, 3551 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3552 "Setting CRT2 mode delayed until after setting CRT1 mode\n"); 3552 "Setting CRT2 mode delayed until after setting CRT1 mode\n");
3553 return TRUE; 3553 return true;
3554 } 3554 }
3555#endif 3555#endif
3556 pSiSEnt->CRT2ModeSet = TRUE; 3556 pSiSEnt->CRT2ModeSet = true;
3557 } 3557 }
3558#endif 3558#endif
3559 3559
@@ -3578,7 +3578,7 @@ SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3578 SiS_UnLockCRT2(SiS_Pr); 3578 SiS_UnLockCRT2(SiS_Pr);
3579 3579
3580 if(!SiS_Pr->UseCustomMode) { 3580 if(!SiS_Pr->UseCustomMode) {
3581 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE; 3581 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
3582 } else { 3582 } else {
3583 ModeIdIndex = 0; 3583 ModeIdIndex = 0;
3584 } 3584 }
@@ -3658,7 +3658,7 @@ SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3658 3658
3659 SiS_Handle760(SiS_Pr); 3659 SiS_Handle760(SiS_Pr);
3660 3660
3661 return TRUE; 3661 return true;
3662} 3662}
3663 3663
3664/*********************************************/ 3664/*********************************************/
@@ -3666,9 +3666,9 @@ SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3666/* for Dual-Head modes */ 3666/* for Dual-Head modes */
3667/*********************************************/ 3667/*********************************************/
3668 3668
3669BOOLEAN 3669bool
3670SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, 3670SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3671 DisplayModePtr mode, BOOLEAN IsCustom) 3671 DisplayModePtr mode, bool IsCustom)
3672{ 3672{
3673 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress; 3673 SISIOADDRESS BaseAddr = SiS_Pr->IOAddress;
3674 SISPtr pSiS = SISPTR(pScrn); 3674 SISPtr pSiS = SISPTR(pScrn);
@@ -3677,10 +3677,10 @@ SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3677#ifdef SISDUALHEAD 3677#ifdef SISDUALHEAD
3678 SISEntPtr pSiSEnt = pSiS->entityPrivate; 3678 SISEntPtr pSiSEnt = pSiS->entityPrivate;
3679 unsigned char backupcr30, backupcr31, backupcr38, backupcr35, backupp40d=0; 3679 unsigned char backupcr30, backupcr31, backupcr38, backupcr35, backupp40d=0;
3680 BOOLEAN backupcustom; 3680 bool backupcustom;
3681#endif 3681#endif
3682 3682
3683 SiS_Pr->UseCustomMode = FALSE; 3683 SiS_Pr->UseCustomMode = false;
3684 3684
3685 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) { 3685 if((IsCustom) && (SiS_CheckBuildCustomMode(pScrn, mode, pSiS->VBFlags))) {
3686 3686
@@ -3697,7 +3697,7 @@ SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3697 } else { 3697 } else {
3698 3698
3699 ModeNo = SiS_GetModeNumber(pScrn, mode, 0); /* don't give VBFlags */ 3699 ModeNo = SiS_GetModeNumber(pScrn, mode, 0); /* don't give VBFlags */
3700 if(!ModeNo) return FALSE; 3700 if(!ModeNo) return false;
3701 3701
3702 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3, 3702 xf86DrvMsgVerb(pScrn->scrnIndex, X_INFO, 3,
3703 "Setting standard mode 0x%x on CRT1\n", ModeNo); 3703 "Setting standard mode 0x%x on CRT1\n", ModeNo);
@@ -3721,7 +3721,7 @@ SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3721 SiS_UnLockCRT2(SiS_Pr); 3721 SiS_UnLockCRT2(SiS_Pr);
3722 3722
3723 if(!SiS_Pr->UseCustomMode) { 3723 if(!SiS_Pr->UseCustomMode) {
3724 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE; 3724 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
3725 } else { 3725 } else {
3726 ModeIdIndex = 0; 3726 ModeIdIndex = 0;
3727 } 3727 }
@@ -3771,11 +3771,11 @@ SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3771#endif 3771#endif
3772 3772
3773 if(SiS_Pr->UseCustomMode) { 3773 if(SiS_Pr->UseCustomMode) {
3774 SiS_Pr->CRT1UsesCustomMode = TRUE; 3774 SiS_Pr->CRT1UsesCustomMode = true;
3775 SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock; 3775 SiS_Pr->CSRClock_CRT1 = SiS_Pr->CSRClock;
3776 SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag; 3776 SiS_Pr->CModeFlag_CRT1 = SiS_Pr->CModeFlag;
3777 } else { 3777 } else {
3778 SiS_Pr->CRT1UsesCustomMode = FALSE; 3778 SiS_Pr->CRT1UsesCustomMode = false;
3779 } 3779 }
3780 3780
3781 /* Reset CRT2 if changing mode on CRT1 */ 3781 /* Reset CRT2 if changing mode on CRT1 */
@@ -3838,7 +3838,7 @@ SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
3838 /* Backup/Set ModeNo in BIOS scratch area */ 3838 /* Backup/Set ModeNo in BIOS scratch area */
3839 SiS_GetSetModeID(pScrn,ModeNo); 3839 SiS_GetSetModeID(pScrn,ModeNo);
3840 3840
3841 return TRUE; 3841 return true;
3842} 3842}
3843#endif /* Linux_XF86 */ 3843#endif /* Linux_XF86 */
3844 3844
@@ -4082,7 +4082,7 @@ SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
4082 DisplayModePtr current 4082 DisplayModePtr current
4083#endif 4083#endif
4084#ifdef SIS_LINUX_KERNEL 4084#ifdef SIS_LINUX_KERNEL
4085 struct fb_var_screeninfo *var, BOOLEAN writeres 4085 struct fb_var_screeninfo *var, bool writeres
4086#endif 4086#endif
4087) 4087)
4088{ 4088{
diff --git a/drivers/video/sis/init.h b/drivers/video/sis/init.h
index 59d12844b4d..f40a680df86 100644
--- a/drivers/video/sis/init.h
+++ b/drivers/video/sis/init.h
@@ -1521,13 +1521,13 @@ static const struct SiS_LVDSCRT1Data SiS_LVDSCRT1640x480_1_H[] =
1521 0x00}} 1521 0x00}}
1522}; 1522};
1523 1523
1524BOOLEAN SiSInitPtr(struct SiS_Private *SiS_Pr); 1524bool SiSInitPtr(struct SiS_Private *SiS_Pr);
1525#ifdef SIS_XORG_XF86 1525#ifdef SIS_XORG_XF86
1526unsigned short SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay, 1526unsigned short SiS_GetModeID(int VGAEngine, unsigned int VBFlags, int HDisplay, int VDisplay,
1527 int Depth, BOOLEAN FSTN, int LCDwith, int LCDheight); 1527 int Depth, bool FSTN, int LCDwith, int LCDheight);
1528#endif 1528#endif
1529unsigned short SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, 1529unsigned short SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay,
1530 int VDisplay, int Depth, BOOLEAN FSTN, 1530 int VDisplay, int Depth, bool FSTN,
1531 unsigned short CustomT, int LCDwith, int LCDheight, 1531 unsigned short CustomT, int LCDwith, int LCDheight,
1532 unsigned int VBFlags2); 1532 unsigned int VBFlags2);
1533unsigned short SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay, 1533unsigned short SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay,
@@ -1558,12 +1558,12 @@ void SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable);
1558void SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable); 1558void SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable);
1559unsigned short SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1559unsigned short SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1560 unsigned short ModeIdIndex); 1560 unsigned short ModeIdIndex);
1561BOOLEAN SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr); 1561bool SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr);
1562#ifndef SIS_LINUX_KERNEL 1562#ifndef SIS_LINUX_KERNEL
1563void SiS_GetVBType(struct SiS_Private *SiS_Pr); 1563void SiS_GetVBType(struct SiS_Private *SiS_Pr);
1564#endif 1564#endif
1565 1565
1566BOOLEAN SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo, 1566bool SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
1567 unsigned short *ModeIdIndex); 1567 unsigned short *ModeIdIndex);
1568unsigned short SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1568unsigned short SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1569 unsigned short ModeIdIndex); 1569 unsigned short ModeIdIndex);
@@ -1581,17 +1581,17 @@ unsigned short SiS_GetLatencyFactor630(struct SiS_Private *SiS_Pr, unsigned shor
1581#endif 1581#endif
1582void SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex); 1582void SiS_LoadDAC(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
1583#ifdef SIS_XORG_XF86 1583#ifdef SIS_XORG_XF86
1584BOOLEAN SiSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, unsigned short ModeNo, 1584bool SiSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, unsigned short ModeNo,
1585 BOOLEAN dosetpitch); 1585 bool dosetpitch);
1586BOOLEAN SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, 1586bool SiSBIOSSetMode(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
1587 DisplayModePtr mode, BOOLEAN IsCustom); 1587 DisplayModePtr mode, bool IsCustom);
1588BOOLEAN SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, 1588bool SiSBIOSSetModeCRT2(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
1589 DisplayModePtr mode, BOOLEAN IsCustom); 1589 DisplayModePtr mode, bool IsCustom);
1590BOOLEAN SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn, 1590bool SiSBIOSSetModeCRT1(struct SiS_Private *SiS_Pr, ScrnInfoPtr pScrn,
1591 DisplayModePtr mode, BOOLEAN IsCustom); 1591 DisplayModePtr mode, bool IsCustom);
1592#endif 1592#endif
1593#ifdef SIS_LINUX_KERNEL 1593#ifdef SIS_LINUX_KERNEL
1594BOOLEAN SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo); 1594bool SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
1595#endif 1595#endif
1596void SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth); 1596void SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth);
1597void SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1597void SiS_CalcLCDACRT1Timing(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
@@ -1602,7 +1602,7 @@ void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdat
1602#endif 1602#endif
1603#ifdef SIS_LINUX_KERNEL 1603#ifdef SIS_LINUX_KERNEL
1604void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres, 1604void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, int xres,
1605 int yres, struct fb_var_screeninfo *var, BOOLEAN writeres); 1605 int yres, struct fb_var_screeninfo *var, bool writeres);
1606#endif 1606#endif
1607 1607
1608/* From init301.c: */ 1608/* From init301.c: */
@@ -1615,7 +1615,7 @@ extern void SiS_SetTVMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1615 unsigned short ModeIdIndex); 1615 unsigned short ModeIdIndex);
1616extern void SiS_UnLockCRT2(struct SiS_Private *SiS_Pr); 1616extern void SiS_UnLockCRT2(struct SiS_Private *SiS_Pr);
1617extern void SiS_DisableBridge(struct SiS_Private *); 1617extern void SiS_DisableBridge(struct SiS_Private *);
1618extern BOOLEAN SiS_SetCRT2Group(struct SiS_Private *, unsigned short); 1618extern bool SiS_SetCRT2Group(struct SiS_Private *, unsigned short);
1619extern unsigned short SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1619extern unsigned short SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1620 unsigned short ModeIdIndex); 1620 unsigned short ModeIdIndex);
1621extern void SiS_WaitRetrace1(struct SiS_Private *SiS_Pr); 1621extern void SiS_WaitRetrace1(struct SiS_Private *SiS_Pr);
@@ -1624,8 +1624,8 @@ extern unsigned short SiS_GetResInfo(struct SiS_Private *SiS_Pr, unsigned short
1624extern unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempax); 1624extern unsigned short SiS_GetCH700x(struct SiS_Private *SiS_Pr, unsigned short tempax);
1625extern unsigned short SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 1625extern unsigned short SiS_GetVCLK2Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
1626 unsigned short ModeIdIndex, unsigned short RRTI); 1626 unsigned short ModeIdIndex, unsigned short RRTI);
1627extern BOOLEAN SiS_IsVAMode(struct SiS_Private *); 1627extern bool SiS_IsVAMode(struct SiS_Private *);
1628extern BOOLEAN SiS_IsDualEdge(struct SiS_Private *); 1628extern bool SiS_IsDualEdge(struct SiS_Private *);
1629 1629
1630#ifdef SIS_XORG_XF86 1630#ifdef SIS_XORG_XF86
1631/* From other modules: */ 1631/* From other modules: */
diff --git a/drivers/video/sis/init301.c b/drivers/video/sis/init301.c
index 47e1896cffe..da33d801c22 100644
--- a/drivers/video/sis/init301.c
+++ b/drivers/video/sis/init301.c
@@ -200,7 +200,7 @@ GetLCDStructPtr661_2(struct SiS_Private *SiS_Pr)
200/* Adjust Rate for CRT2 */ 200/* Adjust Rate for CRT2 */
201/*********************************************/ 201/*********************************************/
202 202
203static BOOLEAN 203static bool
204SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, 204SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
205 unsigned short RRTI, unsigned short *i) 205 unsigned short RRTI, unsigned short *i)
206{ 206{
@@ -269,7 +269,7 @@ SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
269 /* Look backwards in table for matching CRT2 mode */ 269 /* Look backwards in table for matching CRT2 mode */
270 for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) { 270 for(; SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID == modeid; (*i)--) {
271 infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag; 271 infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
272 if(infoflag & checkmask) return TRUE; 272 if(infoflag & checkmask) return true;
273 if((*i) == 0) break; 273 if((*i) == 0) break;
274 } 274 }
275 275
@@ -279,9 +279,9 @@ SiS_AdjustCRT2Rate(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
279 for((*i) = 0; ; (*i)++) { 279 for((*i) = 0; ; (*i)++) {
280 if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break; 280 if(SiS_Pr->SiS_RefIndex[RRTI + (*i)].ModeID != modeid) break;
281 infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag; 281 infoflag = SiS_Pr->SiS_RefIndex[RRTI + (*i)].Ext_InfoFlag;
282 if(infoflag & checkmask) return TRUE; 282 if(infoflag & checkmask) return true;
283 } 283 }
284 return FALSE; 284 return false;
285} 285}
286 286
287/*********************************************/ 287/*********************************************/
@@ -405,7 +405,7 @@ SiS_SaveCRT2Info(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
405/*********************************************/ 405/*********************************************/
406 406
407#ifdef SIS300 407#ifdef SIS300
408static BOOLEAN 408static bool
409SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr) 409SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
410{ 410{
411 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 411 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
@@ -415,13 +415,13 @@ SiS_CR36BIOSWord23b(struct SiS_Private *SiS_Pr)
415 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { 415 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
416 temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f); 416 temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
417 temp1 = SISGETROMW(0x23b); 417 temp1 = SISGETROMW(0x23b);
418 if(temp1 & temp) return TRUE; 418 if(temp1 & temp) return true;
419 } 419 }
420 } 420 }
421 return FALSE; 421 return false;
422} 422}
423 423
424static BOOLEAN 424static bool
425SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr) 425SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
426{ 426{
427 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 427 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
@@ -431,10 +431,10 @@ SiS_CR36BIOSWord23d(struct SiS_Private *SiS_Pr)
431 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { 431 if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
432 temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f); 432 temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) & 0x0f);
433 temp1 = SISGETROMW(0x23d); 433 temp1 = SISGETROMW(0x23d);
434 if(temp1 & temp) return TRUE; 434 if(temp1 & temp) return true;
435 } 435 }
436 } 436 }
437 return FALSE; 437 return false;
438} 438}
439#endif 439#endif
440 440
@@ -687,38 +687,38 @@ SiS_VBLongWait(struct SiS_Private *SiS_Pr)
687/*********************************************/ 687/*********************************************/
688 688
689#ifdef SIS300 689#ifdef SIS300
690static BOOLEAN 690static bool
691SiS_Is301B(struct SiS_Private *SiS_Pr) 691SiS_Is301B(struct SiS_Private *SiS_Pr)
692{ 692{
693 if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return TRUE; 693 if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return true;
694 return FALSE; 694 return false;
695} 695}
696#endif 696#endif
697 697
698static BOOLEAN 698static bool
699SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr) 699SiS_CRT2IsLCD(struct SiS_Private *SiS_Pr)
700{ 700{
701 if(SiS_Pr->ChipType == SIS_730) { 701 if(SiS_Pr->ChipType == SIS_730) {
702 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return TRUE; 702 if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x13) & 0x20) return true;
703 } 703 }
704 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return TRUE; 704 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x30) & 0x20) return true;
705 return FALSE; 705 return false;
706} 706}
707 707
708BOOLEAN 708bool
709SiS_IsDualEdge(struct SiS_Private *SiS_Pr) 709SiS_IsDualEdge(struct SiS_Private *SiS_Pr)
710{ 710{
711#ifdef SIS315H 711#ifdef SIS315H
712 if(SiS_Pr->ChipType >= SIS_315H) { 712 if(SiS_Pr->ChipType >= SIS_315H) {
713 if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) { 713 if((SiS_Pr->ChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
714 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return TRUE; 714 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableDualEdge) return true;
715 } 715 }
716 } 716 }
717#endif 717#endif
718 return FALSE; 718 return false;
719} 719}
720 720
721BOOLEAN 721bool
722SiS_IsVAMode(struct SiS_Private *SiS_Pr) 722SiS_IsVAMode(struct SiS_Private *SiS_Pr)
723{ 723{
724#ifdef SIS315H 724#ifdef SIS315H
@@ -726,70 +726,70 @@ SiS_IsVAMode(struct SiS_Private *SiS_Pr)
726 726
727 if(SiS_Pr->ChipType >= SIS_315H) { 727 if(SiS_Pr->ChipType >= SIS_315H) {
728 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 728 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
729 if((flag & EnableDualEdge) && (flag & SetToLCDA)) return TRUE; 729 if((flag & EnableDualEdge) && (flag & SetToLCDA)) return true;
730 } 730 }
731#endif 731#endif
732 return FALSE; 732 return false;
733} 733}
734 734
735#ifdef SIS315H 735#ifdef SIS315H
736static BOOLEAN 736static bool
737SiS_IsVAorLCD(struct SiS_Private *SiS_Pr) 737SiS_IsVAorLCD(struct SiS_Private *SiS_Pr)
738{ 738{
739 if(SiS_IsVAMode(SiS_Pr)) return TRUE; 739 if(SiS_IsVAMode(SiS_Pr)) return true;
740 if(SiS_CRT2IsLCD(SiS_Pr)) return TRUE; 740 if(SiS_CRT2IsLCD(SiS_Pr)) return true;
741 return FALSE; 741 return false;
742} 742}
743#endif 743#endif
744 744
745static BOOLEAN 745static bool
746SiS_IsDualLink(struct SiS_Private *SiS_Pr) 746SiS_IsDualLink(struct SiS_Private *SiS_Pr)
747{ 747{
748#ifdef SIS315H 748#ifdef SIS315H
749 if(SiS_Pr->ChipType >= SIS_315H) { 749 if(SiS_Pr->ChipType >= SIS_315H) {
750 if((SiS_CRT2IsLCD(SiS_Pr)) || 750 if((SiS_CRT2IsLCD(SiS_Pr)) ||
751 (SiS_IsVAMode(SiS_Pr))) { 751 (SiS_IsVAMode(SiS_Pr))) {
752 if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return TRUE; 752 if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return true;
753 } 753 }
754 } 754 }
755#endif 755#endif
756 return FALSE; 756 return false;
757} 757}
758 758
759#ifdef SIS315H 759#ifdef SIS315H
760static BOOLEAN 760static bool
761SiS_TVEnabled(struct SiS_Private *SiS_Pr) 761SiS_TVEnabled(struct SiS_Private *SiS_Pr)
762{ 762{
763 if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return TRUE; 763 if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return true;
764 if(SiS_Pr->SiS_VBType & VB_SISYPBPR) { 764 if(SiS_Pr->SiS_VBType & VB_SISYPBPR) {
765 if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return TRUE; 765 if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return true;
766 } 766 }
767 return FALSE; 767 return false;
768} 768}
769#endif 769#endif
770 770
771#ifdef SIS315H 771#ifdef SIS315H
772static BOOLEAN 772static bool
773SiS_LCDAEnabled(struct SiS_Private *SiS_Pr) 773SiS_LCDAEnabled(struct SiS_Private *SiS_Pr)
774{ 774{
775 if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return TRUE; 775 if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return true;
776 return FALSE; 776 return false;
777} 777}
778#endif 778#endif
779 779
780#ifdef SIS315H 780#ifdef SIS315H
781static BOOLEAN 781static bool
782SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr) 782SiS_WeHaveBacklightCtrl(struct SiS_Private *SiS_Pr)
783{ 783{
784 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) { 784 if((SiS_Pr->ChipType >= SIS_315H) && (SiS_Pr->ChipType < SIS_661)) {
785 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return TRUE; 785 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x79) & 0x10) return true;
786 } 786 }
787 return FALSE; 787 return false;
788} 788}
789#endif 789#endif
790 790
791#ifdef SIS315H 791#ifdef SIS315H
792static BOOLEAN 792static bool
793SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr) 793SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
794{ 794{
795 unsigned short flag; 795 unsigned short flag;
@@ -798,90 +798,90 @@ SiS_IsNotM650orLater(struct SiS_Private *SiS_Pr)
798 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0; 798 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
799 /* Check for revision != A0 only */ 799 /* Check for revision != A0 only */
800 if((flag == 0xe0) || (flag == 0xc0) || 800 if((flag == 0xe0) || (flag == 0xc0) ||
801 (flag == 0xb0) || (flag == 0x90)) return FALSE; 801 (flag == 0xb0) || (flag == 0x90)) return false;
802 } else if(SiS_Pr->ChipType >= SIS_661) return FALSE; 802 } else if(SiS_Pr->ChipType >= SIS_661) return false;
803 return TRUE; 803 return true;
804} 804}
805#endif 805#endif
806 806
807#ifdef SIS315H 807#ifdef SIS315H
808static BOOLEAN 808static bool
809SiS_IsYPbPr(struct SiS_Private *SiS_Pr) 809SiS_IsYPbPr(struct SiS_Private *SiS_Pr)
810{ 810{
811 if(SiS_Pr->ChipType >= SIS_315H) { 811 if(SiS_Pr->ChipType >= SIS_315H) {
812 /* YPrPb = 0x08 */ 812 /* YPrPb = 0x08 */
813 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return TRUE; 813 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHYPbPr) return true;
814 } 814 }
815 return FALSE; 815 return false;
816} 816}
817#endif 817#endif
818 818
819#ifdef SIS315H 819#ifdef SIS315H
820static BOOLEAN 820static bool
821SiS_IsChScart(struct SiS_Private *SiS_Pr) 821SiS_IsChScart(struct SiS_Private *SiS_Pr)
822{ 822{
823 if(SiS_Pr->ChipType >= SIS_315H) { 823 if(SiS_Pr->ChipType >= SIS_315H) {
824 /* Scart = 0x04 */ 824 /* Scart = 0x04 */
825 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return TRUE; 825 if(SiS_GetReg(SiS_Pr->SiS_P3d4,0x38) & EnableCHScart) return true;
826 } 826 }
827 return FALSE; 827 return false;
828} 828}
829#endif 829#endif
830 830
831#ifdef SIS315H 831#ifdef SIS315H
832static BOOLEAN 832static bool
833SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr) 833SiS_IsTVOrYPbPrOrScart(struct SiS_Private *SiS_Pr)
834{ 834{
835 unsigned short flag; 835 unsigned short flag;
836 836
837 if(SiS_Pr->ChipType >= SIS_315H) { 837 if(SiS_Pr->ChipType >= SIS_315H) {
838 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 838 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
839 if(flag & SetCRT2ToTV) return TRUE; 839 if(flag & SetCRT2ToTV) return true;
840 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 840 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
841 if(flag & EnableCHYPbPr) return TRUE; /* = YPrPb = 0x08 */ 841 if(flag & EnableCHYPbPr) return true; /* = YPrPb = 0x08 */
842 if(flag & EnableCHScart) return TRUE; /* = Scart = 0x04 - TW */ 842 if(flag & EnableCHScart) return true; /* = Scart = 0x04 - TW */
843 } else { 843 } else {
844 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 844 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
845 if(flag & SetCRT2ToTV) return TRUE; 845 if(flag & SetCRT2ToTV) return true;
846 } 846 }
847 return FALSE; 847 return false;
848} 848}
849#endif 849#endif
850 850
851#ifdef SIS315H 851#ifdef SIS315H
852static BOOLEAN 852static bool
853SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr) 853SiS_IsLCDOrLCDA(struct SiS_Private *SiS_Pr)
854{ 854{
855 unsigned short flag; 855 unsigned short flag;
856 856
857 if(SiS_Pr->ChipType >= SIS_315H) { 857 if(SiS_Pr->ChipType >= SIS_315H) {
858 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 858 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
859 if(flag & SetCRT2ToLCD) return TRUE; 859 if(flag & SetCRT2ToLCD) return true;
860 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38); 860 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
861 if(flag & SetToLCDA) return TRUE; 861 if(flag & SetToLCDA) return true;
862 } else { 862 } else {
863 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30); 863 flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
864 if(flag & SetCRT2ToLCD) return TRUE; 864 if(flag & SetCRT2ToLCD) return true;
865 } 865 }
866 return FALSE; 866 return false;
867} 867}
868#endif 868#endif
869 869
870static BOOLEAN 870static bool
871SiS_HaveBridge(struct SiS_Private *SiS_Pr) 871SiS_HaveBridge(struct SiS_Private *SiS_Pr)
872{ 872{
873 unsigned short flag; 873 unsigned short flag;
874 874
875 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { 875 if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
876 return TRUE; 876 return true;
877 } else if(SiS_Pr->SiS_VBType & VB_SISVB) { 877 } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
878 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00); 878 flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
879 if((flag == 1) || (flag == 2)) return TRUE; 879 if((flag == 1) || (flag == 2)) return true;
880 } 880 }
881 return FALSE; 881 return false;
882} 882}
883 883
884static BOOLEAN 884static bool
885SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr) 885SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr)
886{ 886{
887 unsigned short flag; 887 unsigned short flag;
@@ -890,23 +890,23 @@ SiS_BridgeIsEnabled(struct SiS_Private *SiS_Pr)
890 flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00); 890 flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
891 if(SiS_Pr->ChipType < SIS_315H) { 891 if(SiS_Pr->ChipType < SIS_315H) {
892 flag &= 0xa0; 892 flag &= 0xa0;
893 if((flag == 0x80) || (flag == 0x20)) return TRUE; 893 if((flag == 0x80) || (flag == 0x20)) return true;
894 } else { 894 } else {
895 flag &= 0x50; 895 flag &= 0x50;
896 if((flag == 0x40) || (flag == 0x10)) return TRUE; 896 if((flag == 0x40) || (flag == 0x10)) return true;
897 } 897 }
898 } 898 }
899 return FALSE; 899 return false;
900} 900}
901 901
902static BOOLEAN 902static bool
903SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr) 903SiS_BridgeInSlavemode(struct SiS_Private *SiS_Pr)
904{ 904{
905 unsigned short flag1; 905 unsigned short flag1;
906 906
907 flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31); 907 flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
908 if(flag1 & (SetInSlaveMode >> 8)) return TRUE; 908 if(flag1 & (SetInSlaveMode >> 8)) return true;
909 return FALSE; 909 return false;
910} 910}
911 911
912/*********************************************/ 912/*********************************************/
@@ -1461,11 +1461,11 @@ SiS_GetLCDInfoBIOS(struct SiS_Private *SiS_Pr)
1461 1461
1462 if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) { 1462 if((ROMAddr = GetLCDStructPtr661(SiS_Pr))) {
1463 if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) { 1463 if((temp = SISGETROMW(6)) != SiS_Pr->PanelHT) {
1464 SiS_Pr->SiS_NeedRomModeData = TRUE; 1464 SiS_Pr->SiS_NeedRomModeData = true;
1465 SiS_Pr->PanelHT = temp; 1465 SiS_Pr->PanelHT = temp;
1466 } 1466 }
1467 if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) { 1467 if((temp = SISGETROMW(8)) != SiS_Pr->PanelVT) {
1468 SiS_Pr->SiS_NeedRomModeData = TRUE; 1468 SiS_Pr->SiS_NeedRomModeData = true;
1469 SiS_Pr->PanelVT = temp; 1469 SiS_Pr->PanelVT = temp;
1470 } 1470 }
1471 SiS_Pr->PanelHRS = SISGETROMW(10); 1471 SiS_Pr->PanelHRS = SISGETROMW(10);
@@ -1516,7 +1516,7 @@ void
1516SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex) 1516SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex)
1517{ 1517{
1518 unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0; 1518 unsigned short temp,modeflag,resinfo=0,modexres=0,modeyres=0;
1519 BOOLEAN panelcanscale = FALSE; 1519 bool panelcanscale = false;
1520#ifdef SIS300 1520#ifdef SIS300
1521 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 1521 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
1522 static const unsigned char SiS300SeriesLCDRes[] = 1522 static const unsigned char SiS300SeriesLCDRes[] =
@@ -1534,10 +1534,10 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
1534 SiS_Pr->PanelHRE = 999; /* HSync end */ 1534 SiS_Pr->PanelHRE = 999; /* HSync end */
1535 SiS_Pr->PanelVRS = 999; /* VSync start */ 1535 SiS_Pr->PanelVRS = 999; /* VSync start */
1536 SiS_Pr->PanelVRE = 999; /* VSync end */ 1536 SiS_Pr->PanelVRE = 999; /* VSync end */
1537 SiS_Pr->SiS_NeedRomModeData = FALSE; 1537 SiS_Pr->SiS_NeedRomModeData = false;
1538 1538
1539 /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */ 1539 /* Alternative 1600x1200@60 timing for 1600x1200 LCDA */
1540 SiS_Pr->Alternate1600x1200 = FALSE; 1540 SiS_Pr->Alternate1600x1200 = false;
1541 1541
1542 if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return; 1542 if(!(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))) return;
1543 1543
@@ -1633,7 +1633,7 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
1633 SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 1633 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
1634 } 1634 }
1635 1635
1636 panelcanscale = (SiS_Pr->SiS_LCDInfo & DontExpandLCD) ? TRUE : FALSE; 1636 panelcanscale = (bool)(SiS_Pr->SiS_LCDInfo & DontExpandLCD);
1637 1637
1638 if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD; 1638 if(!SiS_Pr->UsePanelScaler) SiS_Pr->SiS_LCDInfo &= ~DontExpandLCD;
1639 else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 1639 else if(SiS_Pr->UsePanelScaler == 1) SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
@@ -1833,7 +1833,7 @@ SiS_GetLCDResInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned sh
1833 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32; 1833 SiS_Pr->PanelHRS = 48; SiS_Pr->PanelHRE = 32;
1834 SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4; 1834 SiS_Pr->PanelVRS = 2; SiS_Pr->PanelVRE = 4;
1835 SiS_Pr->PanelVCLKIdx315 = VCLK130_315; 1835 SiS_Pr->PanelVCLKIdx315 = VCLK130_315;
1836 SiS_Pr->Alternate1600x1200 = TRUE; 1836 SiS_Pr->Alternate1600x1200 = true;
1837 } 1837 }
1838 } else if(SiS_Pr->SiS_IF_DEF_LVDS) { 1838 } else if(SiS_Pr->SiS_IF_DEF_LVDS) {
1839 SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320; 1839 SiS_Pr->PanelHT = 2048; SiS_Pr->PanelVT = 1320;
@@ -3448,7 +3448,7 @@ SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3448 3448
3449 } else { 3449 } else {
3450 3450
3451 BOOLEAN gotit = FALSE; 3451 bool gotit = false;
3452 3452
3453 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) { 3453 if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (!(SiS_Pr->SiS_LCDInfo & LCDPass11))) {
3454 3454
@@ -3456,7 +3456,7 @@ SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3456 SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT; 3456 SiS_Pr->SiS_VGAVT = SiS_Pr->PanelVT;
3457 SiS_Pr->SiS_HT = SiS_Pr->PanelHT; 3457 SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
3458 SiS_Pr->SiS_VT = SiS_Pr->PanelVT; 3458 SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
3459 gotit = TRUE; 3459 gotit = true;
3460 3460
3461 } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) { 3461 } else if( (!(SiS_Pr->SiS_LCDInfo & DontExpandLCD)) && (romptr) && (ROMAddr) ) {
3462 3462
@@ -3474,7 +3474,7 @@ SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3474 if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax; 3474 if(ROMAddr[romptr+9] & 0x80) SiS_Pr->SiS_RVBHRS2 -= tempax;
3475 else SiS_Pr->SiS_RVBHRS2 += tempax; 3475 else SiS_Pr->SiS_RVBHRS2 += tempax;
3476 } 3476 }
3477 if(SiS_Pr->SiS_VGAHT) gotit = TRUE; 3477 if(SiS_Pr->SiS_VGAHT) gotit = true;
3478 else { 3478 else {
3479 SiS_Pr->SiS_LCDInfo |= DontExpandLCD; 3479 SiS_Pr->SiS_LCDInfo |= DontExpandLCD;
3480 SiS_Pr->SiS_LCDInfo &= ~LCDPass11; 3480 SiS_Pr->SiS_LCDInfo &= ~LCDPass11;
@@ -3485,7 +3485,7 @@ SiS_GetCRT2Data301(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
3485 SiS_Pr->SiS_HT = SiS_Pr->PanelHT; 3485 SiS_Pr->SiS_HT = SiS_Pr->PanelHT;
3486 SiS_Pr->SiS_VT = SiS_Pr->PanelVT; 3486 SiS_Pr->SiS_VT = SiS_Pr->PanelVT;
3487 SiS_Pr->SiS_RVBHRS2 = 0; 3487 SiS_Pr->SiS_RVBHRS2 = 0;
3488 gotit = TRUE; 3488 gotit = true;
3489 } 3489 }
3490#endif 3490#endif
3491 3491
@@ -3960,8 +3960,8 @@ SiS_DisableBridge(struct SiS_Private *SiS_Pr)
3960#ifdef SIS315H /* 315 series */ 3960#ifdef SIS315H /* 315 series */
3961 3961
3962 int didpwd = 0; 3962 int didpwd = 0;
3963 BOOLEAN custom1 = ((SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) || 3963 bool custom1 = (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
3964 (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) ? TRUE : FALSE; 3964 (SiS_Pr->SiS_CustomT == CUT_CLEVO1400);
3965 3965
3966 modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f; 3966 modenum = SiS_GetReg(SiS_Pr->SiS_P3d4,0x34) & 0x7f;
3967 3967
@@ -4313,7 +4313,7 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4313 unsigned short temp=0, tempah; 4313 unsigned short temp=0, tempah;
4314#ifdef SIS315H 4314#ifdef SIS315H
4315 unsigned short temp1, pushax=0; 4315 unsigned short temp1, pushax=0;
4316 BOOLEAN delaylong = FALSE; 4316 bool delaylong = false;
4317#endif 4317#endif
4318 4318
4319 if(SiS_Pr->SiS_VBType & VB_SISVB) { 4319 if(SiS_Pr->SiS_VBType & VB_SISVB) {
@@ -4448,7 +4448,7 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4448 4448
4449 if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) { 4449 if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) & 0x40)) {
4450 SiS_PanelDelayLoop(SiS_Pr, 3, 10); 4450 SiS_PanelDelayLoop(SiS_Pr, 3, 10);
4451 delaylong = TRUE; 4451 delaylong = true;
4452 } 4452 }
4453 4453
4454 } 4454 }
@@ -4530,7 +4530,7 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4530 SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2]; 4530 SiS_Pr->EMI_33 = ROMAddr[romptr + SiS_Pr->SiS_EMIOffset + 2];
4531 if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40; 4531 if(ROMAddr[romptr + 1] & 0x10) SiS_Pr->EMI_30 = 0x40;
4532 /* emidelay = SISGETROMW((romptr + 0x22)); */ 4532 /* emidelay = SISGETROMW((romptr + 0x22)); */
4533 SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = TRUE; 4533 SiS_Pr->HaveEMI = SiS_Pr->HaveEMILCD = SiS_Pr->OverruleEMI = true;
4534 } 4534 }
4535 } 4535 }
4536 4536
@@ -4644,7 +4644,7 @@ SiS_EnableBridge(struct SiS_Private *SiS_Pr)
4644 SiS_PanelDelayLoop(SiS_Pr, 3, 5); 4644 SiS_PanelDelayLoop(SiS_Pr, 3, 5);
4645 if(delaylong) { 4645 if(delaylong) {
4646 SiS_PanelDelayLoop(SiS_Pr, 3, 5); 4646 SiS_PanelDelayLoop(SiS_Pr, 3, 5);
4647 delaylong = FALSE; 4647 delaylong = false;
4648 } 4648 }
4649 SiS_WaitVBRetrace(SiS_Pr); 4649 SiS_WaitVBRetrace(SiS_Pr);
4650 SiS_WaitVBRetrace(SiS_Pr); 4650 SiS_WaitVBRetrace(SiS_Pr);
@@ -5454,7 +5454,7 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5454 unsigned short modeflag, resinfo = 0; 5454 unsigned short modeflag, resinfo = 0;
5455 unsigned short push2, tempax, tempbx, tempcx, temp; 5455 unsigned short push2, tempax, tempbx, tempcx, temp;
5456 unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0; 5456 unsigned int tempeax = 0, tempebx, tempecx, tempvcfact = 0;
5457 BOOLEAN islvds = FALSE, issis = FALSE, chkdclkfirst = FALSE; 5457 bool islvds = false, issis = false, chkdclkfirst = false;
5458#ifdef SIS300 5458#ifdef SIS300
5459 unsigned short crt2crtc = 0; 5459 unsigned short crt2crtc = 0;
5460#endif 5460#endif
@@ -5480,17 +5480,17 @@ SiS_SetGroup1_LVDS(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
5480 5480
5481 /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */ 5481 /* is lvds if really LVDS, or 301B-DH with external LVDS transmitter */
5482 if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) { 5482 if((SiS_Pr->SiS_IF_DEF_LVDS == 1) || (SiS_Pr->SiS_VBType & VB_NoLCD)) {
5483 islvds = TRUE; 5483 islvds = true;
5484 } 5484 }
5485 5485
5486 /* is really sis if sis bridge, but not 301B-DH */ 5486 /* is really sis if sis bridge, but not 301B-DH */
5487 if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) { 5487 if((SiS_Pr->SiS_VBType & VB_SISVB) && (!(SiS_Pr->SiS_VBType & VB_NoLCD))) {
5488 issis = TRUE; 5488 issis = true;
5489 } 5489 }
5490 5490
5491 if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) { 5491 if((SiS_Pr->ChipType >= SIS_315H) && (islvds) && (!(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA))) {
5492 if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) { 5492 if((!SiS_Pr->SiS_IF_DEF_FSTN) && (!SiS_Pr->SiS_IF_DEF_DSTN)) {
5493 chkdclkfirst = TRUE; 5493 chkdclkfirst = true;
5494 } 5494 }
5495 } 5495 }
5496 5496
@@ -6447,13 +6447,13 @@ SiS_SetGroup2_C_ELV(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned
6447 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp); 6447 SiS_SetRegANDOR(SiS_Pr->SiS_Part2Port,0x4e,0xeb,temp);
6448} 6448}
6449 6449
6450static BOOLEAN 6450static bool
6451SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex, 6451SiS_GetCRT2Part2Ptr(struct SiS_Private *SiS_Pr,unsigned short ModeNo,unsigned short ModeIdIndex,
6452 unsigned short RefreshRateTableIndex,unsigned short *CRT2Index, 6452 unsigned short RefreshRateTableIndex,unsigned short *CRT2Index,
6453 unsigned short *ResIndex) 6453 unsigned short *ResIndex)
6454{ 6454{
6455 6455
6456 if(SiS_Pr->ChipType < SIS_315H) return FALSE; 6456 if(SiS_Pr->ChipType < SIS_315H) return false;
6457 6457
6458 if(ModeNo <= 0x13) 6458 if(ModeNo <= 0x13)
6459 (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC; 6459 (*ResIndex) = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_CRT2CRTC;
@@ -6688,7 +6688,7 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6688 unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp; 6688 unsigned short i, j, tempax, tempbx, tempcx, tempch, tempcl, temp;
6689 unsigned short push2, modeflag, crt2crtc, bridgeoffset; 6689 unsigned short push2, modeflag, crt2crtc, bridgeoffset;
6690 unsigned int longtemp, PhaseIndex; 6690 unsigned int longtemp, PhaseIndex;
6691 BOOLEAN newtvphase; 6691 bool newtvphase;
6692 const unsigned char *TimingPoint; 6692 const unsigned char *TimingPoint;
6693#ifdef SIS315H 6693#ifdef SIS315H
6694 unsigned short resindex, CRT2Index; 6694 unsigned short resindex, CRT2Index;
@@ -6721,11 +6721,11 @@ SiS_SetGroup2(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
6721 PhaseIndex = 0x01; /* SiS_PALPhase */ 6721 PhaseIndex = 0x01; /* SiS_PALPhase */
6722 TimingPoint = SiS_Pr->SiS_PALTiming; 6722 TimingPoint = SiS_Pr->SiS_PALTiming;
6723 6723
6724 newtvphase = FALSE; 6724 newtvphase = false;
6725 if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) && 6725 if( (SiS_Pr->SiS_VBType & VB_SIS30xBLV) &&
6726 ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) || 6726 ( (!(SiS_Pr->SiS_VBInfo & SetInSlaveMode)) ||
6727 (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) { 6727 (SiS_Pr->SiS_TVMode & TVSetTVSimuMode) ) ) {
6728 newtvphase = TRUE; 6728 newtvphase = true;
6729 } 6729 }
6730 6730
6731 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) { 6731 if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
@@ -7754,13 +7754,13 @@ SiS_SetGroup5(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short
7754/* MODIFY CRT1 GROUP FOR SLAVE MODE */ 7754/* MODIFY CRT1 GROUP FOR SLAVE MODE */
7755/*********************************************/ 7755/*********************************************/
7756 7756
7757static BOOLEAN 7757static bool
7758SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex, 7758SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex,
7759 unsigned short RefreshRateTableIndex, unsigned short *ResIndex, 7759 unsigned short RefreshRateTableIndex, unsigned short *ResIndex,
7760 unsigned short *DisplayType) 7760 unsigned short *DisplayType)
7761 { 7761 {
7762 unsigned short modeflag = 0; 7762 unsigned short modeflag = 0;
7763 BOOLEAN checkhd = TRUE; 7763 bool checkhd = true;
7764 7764
7765 /* Pass 1:1 not supported here */ 7765 /* Pass 1:1 not supported here */
7766 7766
@@ -7792,7 +7792,7 @@ SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
7792 (*DisplayType = 0); 7792 (*DisplayType = 0);
7793 switch(SiS_Pr->SiS_LCDResInfo) { 7793 switch(SiS_Pr->SiS_LCDResInfo) {
7794 case Panel_320x240_1: (*DisplayType) = 50; 7794 case Panel_320x240_1: (*DisplayType) = 50;
7795 checkhd = FALSE; 7795 checkhd = false;
7796 break; 7796 break;
7797 case Panel_320x240_2: (*DisplayType) = 14; 7797 case Panel_320x240_2: (*DisplayType) = 14;
7798 break; 7798 break;
@@ -7802,7 +7802,7 @@ SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
7802 break; 7802 break;
7803 case Panel_1024x600: (*DisplayType) = 26; 7803 case Panel_1024x600: (*DisplayType) = 26;
7804 break; 7804 break;
7805 default: return TRUE; 7805 default: return true;
7806 } 7806 }
7807 7807
7808 if(checkhd) { 7808 if(checkhd) {
@@ -7815,7 +7815,7 @@ SiS_GetLVDSCRT1Ptr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned s
7815 7815
7816 } 7816 }
7817 7817
7818 return TRUE; 7818 return true;
7819} 7819}
7820 7820
7821static void 7821static void
@@ -8654,7 +8654,7 @@ SiS_ChrontelDoSomething1(struct SiS_Private *SiS_Pr)
8654/* MAIN: SET CRT2 REGISTER GROUP */ 8654/* MAIN: SET CRT2 REGISTER GROUP */
8655/*********************************************/ 8655/*********************************************/
8656 8656
8657BOOLEAN 8657bool
8658SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo) 8658SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8659{ 8659{
8660#ifdef SIS300 8660#ifdef SIS300
@@ -8690,7 +8690,7 @@ SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8690 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { 8690 if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) {
8691 SiS_LockCRT2(SiS_Pr); 8691 SiS_LockCRT2(SiS_Pr);
8692 SiS_DisplayOn(SiS_Pr); 8692 SiS_DisplayOn(SiS_Pr);
8693 return TRUE; 8693 return true;
8694 } 8694 }
8695 8695
8696 SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex); 8696 SiS_GetCRT2Data(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex);
@@ -8828,7 +8828,7 @@ SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
8828 SiS_LockCRT2(SiS_Pr); 8828 SiS_LockCRT2(SiS_Pr);
8829 } 8829 }
8830 8830
8831 return TRUE; 8831 return true;
8832} 8832}
8833 8833
8834 8834
@@ -8908,7 +8908,7 @@ SiS_SetTrumpBlockLoop(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
8908 return NULL; 8908 return NULL;
8909} 8909}
8910 8910
8911static BOOLEAN 8911static bool
8912SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr) 8912SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
8913{ 8913{
8914 SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */ 8914 SiS_Pr->SiS_DDC_DeviceAddr = 0xF0; /* DAB (Device Address Byte) */
@@ -8921,14 +8921,14 @@ SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
8921 8921
8922 while(*dataptr) { 8922 while(*dataptr) {
8923 dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr); 8923 dataptr = SiS_SetTrumpBlockLoop(SiS_Pr, dataptr);
8924 if(!dataptr) return FALSE; 8924 if(!dataptr) return false;
8925 } 8925 }
8926#ifdef SIS_XORG_XF86 8926#ifdef SIS_XORG_XF86
8927#ifdef TWDEBUG 8927#ifdef TWDEBUG
8928 xf86DrvMsg(0, X_INFO, "Trumpion block success\n"); 8928 xf86DrvMsg(0, X_INFO, "Trumpion block success\n");
8929#endif 8929#endif
8930#endif 8930#endif
8931 return TRUE; 8931 return true;
8932} 8932}
8933#endif 8933#endif
8934 8934
@@ -8939,7 +8939,7 @@ SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr)
8939 * 0x0a, possibly for working around the DDC problems 8939 * 0x0a, possibly for working around the DDC problems
8940 */ 8940 */
8941 8941
8942static BOOLEAN 8942static bool
8943SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor) 8943SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val, unsigned short myor)
8944{ 8944{
8945 unsigned short temp, i; 8945 unsigned short temp, i;
@@ -8958,9 +8958,9 @@ SiS_SetChReg(struct SiS_Private *SiS_Pr, unsigned short reg, unsigned char val,
8958 if(temp) continue; /* (ERROR: no ack) */ 8958 if(temp) continue; /* (ERROR: no ack) */
8959 if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */ 8959 if(SiS_SetStop(SiS_Pr)) continue; /* Set stop condition */
8960 SiS_Pr->SiS_ChrontelInit = 1; 8960 SiS_Pr->SiS_ChrontelInit = 1;
8961 return TRUE; 8961 return true;
8962 } 8962 }
8963 return FALSE; 8963 return false;
8964} 8964}
8965 8965
8966/* Write to Chrontel 700x */ 8966/* Write to Chrontel 700x */
@@ -9119,7 +9119,7 @@ static
9119#endif 9119#endif
9120unsigned short 9120unsigned short
9121SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine, 9121SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
9122 unsigned short adaptnum, unsigned short DDCdatatype, BOOLEAN checkcr32, 9122 unsigned short adaptnum, unsigned short DDCdatatype, bool checkcr32,
9123 unsigned int VBFlags2) 9123 unsigned int VBFlags2)
9124{ 9124{
9125 unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 }; 9125 unsigned char ddcdtype[] = { 0xa0, 0xa0, 0xa0, 0xa2, 0xa6 };
@@ -9287,7 +9287,7 @@ SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
9287{ 9287{
9288 unsigned char mask, value; 9288 unsigned char mask, value;
9289 unsigned short temp, ret=0; 9289 unsigned short temp, ret=0;
9290 BOOLEAN failed = FALSE; 9290 bool failed = false;
9291 9291
9292 SiS_SetSwitchDDC2(SiS_Pr); 9292 SiS_SetSwitchDDC2(SiS_Pr);
9293 if(SiS_PrepareDDC(SiS_Pr)) { 9293 if(SiS_PrepareDDC(SiS_Pr)) {
@@ -9308,7 +9308,7 @@ SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
9308 mask = 0xff; 9308 mask = 0xff;
9309 value = 0xff; 9309 value = 0xff;
9310 } else { 9310 } else {
9311 failed = TRUE; 9311 failed = true;
9312 ret = 0xFFFF; 9312 ret = 0xFFFF;
9313#ifdef SIS_XORG_XF86 9313#ifdef SIS_XORG_XF86
9314#ifdef TWDEBUG 9314#ifdef TWDEBUG
@@ -9317,7 +9317,7 @@ SiS_DoProbeDDC(struct SiS_Private *SiS_Pr)
9317#endif 9317#endif
9318 } 9318 }
9319 } 9319 }
9320 if(failed == FALSE) { 9320 if(!failed) {
9321 temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr); 9321 temp = (unsigned char)SiS_ReadDDC2Data(SiS_Pr);
9322 SiS_SendACK(SiS_Pr, 1); 9322 SiS_SendACK(SiS_Pr, 1);
9323 temp &= mask; 9323 temp &= mask;
@@ -9431,7 +9431,7 @@ SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, int VGAEngine,
9431 if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0)) 9431 if((!(VBFlags2 & VB2_VIDEOBRIDGE)) && (adaptnum > 0))
9432 return 0xFFFF; 9432 return 0xFFFF;
9433 9433
9434 if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, FALSE, VBFlags2) == 0xFFFF) 9434 if(SiS_InitDDCRegs(SiS_Pr, VBFlags, VGAEngine, adaptnum, DDCdatatype, false, VBFlags2) == 0xFFFF)
9435 return 0xFFFF; 9435 return 0xFFFF;
9436 9436
9437 sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f); 9437 sr1f = SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f);
@@ -9829,7 +9829,7 @@ SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
9829{ 9829{
9830 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase; 9830 unsigned char *ROMAddr = SiS_Pr->VirtualRomBase;
9831 unsigned short delay=0,index,myindex,temp,romptr=0; 9831 unsigned short delay=0,index,myindex,temp,romptr=0;
9832 BOOLEAN dochiptest = TRUE; 9832 bool dochiptest = true;
9833 9833
9834 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 9834 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
9835 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf); 9835 SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x20,0xbf);
@@ -9864,7 +9864,7 @@ SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
9864 9864
9865 } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */ 9865 } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD|SetCRT2ToLCDA)) { /* ---------- LCD/LCDA */
9866 9866
9867 BOOLEAN gotitfrompci = FALSE; 9867 bool gotitfrompci = false;
9868 9868
9869 /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */ 9869 /* Could we detect a PDC for LCD or did we get a user-defined? If yes, use it */
9870 9870
@@ -9916,22 +9916,22 @@ SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
9916 case CUT_COMPAQ1280: 9916 case CUT_COMPAQ1280:
9917 case CUT_COMPAQ12802: 9917 case CUT_COMPAQ12802:
9918 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) { 9918 if(SiS_Pr->SiS_LCDResInfo == Panel_1280x1024) {
9919 gotitfrompci = TRUE; 9919 gotitfrompci = true;
9920 dochiptest = FALSE; 9920 dochiptest = false;
9921 delay = 0x03; 9921 delay = 0x03;
9922 } 9922 }
9923 break; 9923 break;
9924 case CUT_CLEVO1400: 9924 case CUT_CLEVO1400:
9925 case CUT_CLEVO14002: 9925 case CUT_CLEVO14002:
9926 gotitfrompci = TRUE; 9926 gotitfrompci = true;
9927 dochiptest = FALSE; 9927 dochiptest = false;
9928 delay = 0x02; 9928 delay = 0x02;
9929 break; 9929 break;
9930 case CUT_CLEVO1024: 9930 case CUT_CLEVO1024:
9931 case CUT_CLEVO10242: 9931 case CUT_CLEVO10242:
9932 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) { 9932 if(SiS_Pr->SiS_LCDResInfo == Panel_1024x768) {
9933 gotitfrompci = TRUE; 9933 gotitfrompci = true;
9934 dochiptest = FALSE; 9934 dochiptest = false;
9935 delay = 0x33; 9935 delay = 0x33;
9936 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay); 9936 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x2D,delay);
9937 delay &= 0x0f; 9937 delay &= 0x0f;
@@ -10009,7 +10009,7 @@ SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
10009 10009
10010 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { 10010 if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) {
10011 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0)); 10011 SiS_SetRegANDOR(SiS_Pr->SiS_Part1Port,0x2D,0x0F,((delay << 4) & 0xf0));
10012 dochiptest = FALSE; 10012 dochiptest = false;
10013 } 10013 }
10014 10014
10015 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */ 10015 } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* ------------ TV */
@@ -10043,12 +10043,12 @@ SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
10043 case CUT_CLEVO1400: 10043 case CUT_CLEVO1400:
10044 case CUT_CLEVO14002: 10044 case CUT_CLEVO14002:
10045 delay = 0x02; 10045 delay = 0x02;
10046 dochiptest = FALSE; 10046 dochiptest = false;
10047 break; 10047 break;
10048 case CUT_CLEVO1024: 10048 case CUT_CLEVO1024:
10049 case CUT_CLEVO10242: 10049 case CUT_CLEVO10242:
10050 delay = 0x03; 10050 delay = 0x03;
10051 dochiptest = FALSE; 10051 dochiptest = false;
10052 break; 10052 break;
10053 default: 10053 default:
10054 delay = SiS310_TVDelayCompensation_651301LV[index]; 10054 delay = SiS310_TVDelayCompensation_651301LV[index];
@@ -10085,7 +10085,7 @@ SetDelayComp(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
10085 10085
10086 if(SiS_LCDAEnabled(SiS_Pr)) { 10086 if(SiS_LCDAEnabled(SiS_Pr)) {
10087 delay &= 0x0f; 10087 delay &= 0x0f;
10088 dochiptest = FALSE; 10088 dochiptest = false;
10089 } 10089 }
10090 10090
10091 } else return; 10091 } else return;
@@ -10728,7 +10728,7 @@ SiS_FinalizeLCD(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned shor
10728 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00); 10728 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1c,0x00);
10729 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b); 10729 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x1d,0x1b);
10730 } 10730 }
10731 if((SiS_Pr->Backup == TRUE) && (SiS_Pr->Backup_Mode == ModeNo)) { 10731 if(SiS_Pr->Backup && (SiS_Pr->Backup_Mode == ModeNo)) {
10732 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14); 10732 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x14,SiS_Pr->Backup_14);
10733 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15); 10733 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x15,SiS_Pr->Backup_15);
10734 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16); 10734 SiS_SetReg(SiS_Pr->SiS_Part1Port,0x16,SiS_Pr->Backup_16);
diff --git a/drivers/video/sis/init301.h b/drivers/video/sis/init301.h
index 4f3a28699d3..7708e1e1d99 100644
--- a/drivers/video/sis/init301.h
+++ b/drivers/video/sis/init301.h
@@ -363,8 +363,8 @@ void SiS_LockCRT2(struct SiS_Private *SiS_Pr);
363void SiS_EnableCRT2(struct SiS_Private *SiS_Pr); 363void SiS_EnableCRT2(struct SiS_Private *SiS_Pr);
364unsigned short SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex); 364unsigned short SiS_GetRatePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
365void SiS_WaitRetrace1(struct SiS_Private *SiS_Pr); 365void SiS_WaitRetrace1(struct SiS_Private *SiS_Pr);
366BOOLEAN SiS_IsDualEdge(struct SiS_Private *SiS_Pr); 366bool SiS_IsDualEdge(struct SiS_Private *SiS_Pr);
367BOOLEAN SiS_IsVAMode(struct SiS_Private *SiS_Pr); 367bool SiS_IsVAMode(struct SiS_Private *SiS_Pr);
368void SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 368void SiS_GetVBInfo(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
369 unsigned short ModeIdIndex, int checkcrt2mode); 369 unsigned short ModeIdIndex, int checkcrt2mode);
370void SiS_SetYPbPr(struct SiS_Private *SiS_Pr); 370void SiS_SetYPbPr(struct SiS_Private *SiS_Pr);
@@ -379,7 +379,7 @@ void SiS_DisableBridge(struct SiS_Private *SiS_Pr);
379#ifndef SIS_LINUX_KERNEL 379#ifndef SIS_LINUX_KERNEL
380void SiS_EnableBridge(struct SiS_Private *SiS_Pr); 380void SiS_EnableBridge(struct SiS_Private *SiS_Pr);
381#endif 381#endif
382BOOLEAN SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo); 382bool SiS_SetCRT2Group(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
383void SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr); 383void SiS_SiS30xBLOn(struct SiS_Private *SiS_Pr);
384void SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr); 384void SiS_SiS30xBLOff(struct SiS_Private *SiS_Pr);
385 385
@@ -403,7 +403,7 @@ void SiS_Chrontel701xBLOff(struct SiS_Private *SiS_Pr);
403#endif /* 315 */ 403#endif /* 315 */
404 404
405#ifdef SIS300 405#ifdef SIS300
406static BOOLEAN SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr); 406static bool SiS_SetTrumpionBlock(struct SiS_Private *SiS_Pr, unsigned char *dataptr);
407void SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo); 407void SiS_SetChrontelGPIO(struct SiS_Private *SiS_Pr, unsigned short myvbinfo);
408#endif 408#endif
409 409
@@ -416,14 +416,14 @@ unsigned short SiS_HandleDDC(struct SiS_Private *SiS_Pr, unsigned int VBFlags, i
416#ifdef SIS_XORG_XF86 416#ifdef SIS_XORG_XF86
417unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, 417unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags,
418 int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype, 418 int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype,
419 BOOLEAN checkcr32, unsigned int VBFlags2); 419 bool checkcr32, unsigned int VBFlags2);
420unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr); 420unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr);
421unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, 421unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype,
422 unsigned char *buffer); 422 unsigned char *buffer);
423#else 423#else
424static unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags, 424static unsigned short SiS_InitDDCRegs(struct SiS_Private *SiS_Pr, unsigned int VBFlags,
425 int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype, 425 int VGAEngine, unsigned short adaptnum, unsigned short DDCdatatype,
426 BOOLEAN checkcr32, unsigned int VBFlags2); 426 bool checkcr32, unsigned int VBFlags2);
427static unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr); 427static unsigned short SiS_ProbeDDC(struct SiS_Private *SiS_Pr);
428static unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype, 428static unsigned short SiS_ReadDDC(struct SiS_Private *SiS_Pr, unsigned short DDCdatatype,
429 unsigned char *buffer); 429 unsigned char *buffer);
@@ -469,7 +469,7 @@ extern void SiS_SetRegOR(SISIOADDRESS, unsigned short, unsigned short);
469extern void SiS_SetRegAND(SISIOADDRESS, unsigned short, unsigned short); 469extern void SiS_SetRegAND(SISIOADDRESS, unsigned short, unsigned short);
470extern void SiS_DisplayOff(struct SiS_Private *SiS_Pr); 470extern void SiS_DisplayOff(struct SiS_Private *SiS_Pr);
471extern void SiS_DisplayOn(struct SiS_Private *SiS_Pr); 471extern void SiS_DisplayOn(struct SiS_Private *SiS_Pr);
472extern BOOLEAN SiS_SearchModeID(struct SiS_Private *, unsigned short *, unsigned short *); 472extern bool SiS_SearchModeID(struct SiS_Private *, unsigned short *, unsigned short *);
473extern unsigned short SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo, 473extern unsigned short SiS_GetModeFlag(struct SiS_Private *SiS_Pr, unsigned short ModeNo,
474 unsigned short ModeIdIndex); 474 unsigned short ModeIdIndex);
475extern unsigned short SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex); 475extern unsigned short SiS_GetModePtr(struct SiS_Private *SiS_Pr, unsigned short ModeNo, unsigned short ModeIdIndex);
diff --git a/drivers/video/sis/initextlfb.c b/drivers/video/sis/initextlfb.c
index c3884a29f4c..47a33501549 100644
--- a/drivers/video/sis/initextlfb.c
+++ b/drivers/video/sis/initextlfb.c
@@ -38,14 +38,14 @@ int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr,
38 unsigned char modeno, unsigned char rateindex); 38 unsigned char modeno, unsigned char rateindex);
39int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno, 39int sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
40 unsigned char rateindex, struct fb_var_screeninfo *var); 40 unsigned char rateindex, struct fb_var_screeninfo *var);
41BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, 41bool sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno,
42 int *htotal, int *vtotal, unsigned char rateindex); 42 int *htotal, int *vtotal, unsigned char rateindex);
43 43
44extern BOOLEAN SiSInitPtr(struct SiS_Private *SiS_Pr); 44extern bool SiSInitPtr(struct SiS_Private *SiS_Pr);
45extern BOOLEAN SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo, 45extern bool SiS_SearchModeID(struct SiS_Private *SiS_Pr, unsigned short *ModeNo,
46 unsigned short *ModeIdIndex); 46 unsigned short *ModeIdIndex);
47extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata, 47extern void SiS_Generic_ConvertCRData(struct SiS_Private *SiS_Pr, unsigned char *crdata,
48 int xres, int yres, struct fb_var_screeninfo *var, BOOLEAN writeres); 48 int xres, int yres, struct fb_var_screeninfo *var, bool writeres);
49 49
50int 50int
51sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, unsigned char modeno, 51sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, unsigned char modeno,
@@ -131,7 +131,7 @@ sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
131 (unsigned char *)&SiS_Pr->SiS_CRT1Table[index].CR[0], 131 (unsigned char *)&SiS_Pr->SiS_CRT1Table[index].CR[0],
132 SiS_Pr->SiS_RefIndex[RRTI].XRes, 132 SiS_Pr->SiS_RefIndex[RRTI].XRes,
133 SiS_Pr->SiS_RefIndex[RRTI].YRes, 133 SiS_Pr->SiS_RefIndex[RRTI].YRes,
134 var, FALSE); 134 var, false);
135 135
136 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x8000) 136 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & 0x8000)
137 var->sync &= ~FB_SYNC_VERT_HIGH_ACT; 137 var->sync &= ~FB_SYNC_VERT_HIGH_ACT;
@@ -175,7 +175,7 @@ sisfb_mode_rate_to_ddata(struct SiS_Private *SiS_Pr, unsigned char modeno,
175 return 1; 175 return 1;
176} 176}
177 177
178BOOLEAN 178bool
179sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *htotal, 179sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *htotal,
180 int *vtotal, unsigned char rateindex) 180 int *vtotal, unsigned char rateindex)
181{ 181{
@@ -184,7 +184,7 @@ sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *ht
184 unsigned short RRTI = 0; 184 unsigned short RRTI = 0;
185 unsigned char sr_data, cr_data, cr_data2; 185 unsigned char sr_data, cr_data, cr_data2;
186 186
187 if(!SiSInitPtr(SiS_Pr)) return FALSE; 187 if(!SiSInitPtr(SiS_Pr)) return false;
188 188
189 if(rateindex > 0) rateindex--; 189 if(rateindex > 0) rateindex--;
190 190
@@ -195,7 +195,7 @@ sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *ht
195 } 195 }
196#endif 196#endif
197 197
198 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return FALSE; 198 if(!(SiS_SearchModeID(SiS_Pr, &ModeNo, &ModeIdIndex))) return false;
199 199
200 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex; 200 RRTI = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
201 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) { 201 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & HaveWideTiming) {
@@ -226,7 +226,7 @@ sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, int *ht
226 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & InterlaceMode) 226 if(SiS_Pr->SiS_RefIndex[RRTI].Ext_InfoFlag & InterlaceMode)
227 *vtotal *= 2; 227 *vtotal *= 2;
228 228
229 return TRUE; 229 return true;
230} 230}
231 231
232 232
diff --git a/drivers/video/sis/sis.h b/drivers/video/sis/sis.h
index a259446ca7f..7d5ee2145e2 100644
--- a/drivers/video/sis/sis.h
+++ b/drivers/video/sis/sis.h
@@ -526,7 +526,7 @@ struct sis_video_info {
526 u16 vmax; 526 u16 vmax;
527 u32 dclockmax; 527 u32 dclockmax;
528 u8 feature; 528 u8 feature;
529 BOOLEAN datavalid; 529 bool datavalid;
530 } sisfb_thismonitor; 530 } sisfb_thismonitor;
531 531
532 unsigned short chip_id; /* PCI ID of chip */ 532 unsigned short chip_id; /* PCI ID of chip */
diff --git a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
index baaf495a0a6..01197d74021 100644
--- a/drivers/video/sis/sis_main.c
+++ b/drivers/video/sis/sis_main.c
@@ -110,7 +110,7 @@ sisfb_setdefaultparms(void)
110/* ------------- Parameter parsing -------------- */ 110/* ------------- Parameter parsing -------------- */
111 111
112static void __devinit 112static void __devinit
113sisfb_search_vesamode(unsigned int vesamode, BOOLEAN quiet) 113sisfb_search_vesamode(unsigned int vesamode, bool quiet)
114{ 114{
115 int i = 0, j = 0; 115 int i = 0, j = 0;
116 116
@@ -150,7 +150,7 @@ sisfb_search_vesamode(unsigned int vesamode, BOOLEAN quiet)
150} 150}
151 151
152static void __devinit 152static void __devinit
153sisfb_search_mode(char *name, BOOLEAN quiet) 153sisfb_search_mode(char *name, bool quiet)
154{ 154{
155 unsigned int j = 0, xres = 0, yres = 0, depth = 0, rate = 0; 155 unsigned int j = 0, xres = 0, yres = 0, depth = 0, rate = 0;
156 int i = 0; 156 int i = 0;
@@ -251,7 +251,7 @@ sisfb_get_vga_mode_from_kernel(void)
251 "sisfb: Using vga mode %s pre-set by kernel as default\n", 251 "sisfb: Using vga mode %s pre-set by kernel as default\n",
252 mymode); 252 mymode);
253 253
254 sisfb_search_mode(mymode, TRUE); 254 sisfb_search_mode(mymode, true);
255 } 255 }
256#endif 256#endif
257 return; 257 return;
@@ -307,7 +307,7 @@ static void __init
307sisfb_search_specialtiming(const char *name) 307sisfb_search_specialtiming(const char *name)
308{ 308{
309 int i = 0; 309 int i = 0;
310 BOOLEAN found = FALSE; 310 bool found = false;
311 311
312 /* We don't know the hardware specs yet and there is no ivideo */ 312 /* We don't know the hardware specs yet and there is no ivideo */
313 313
@@ -322,7 +322,7 @@ sisfb_search_specialtiming(const char *name)
322 if(!strnicmp(name,mycustomttable[i].optionName, 322 if(!strnicmp(name,mycustomttable[i].optionName,
323 strlen(mycustomttable[i].optionName))) { 323 strlen(mycustomttable[i].optionName))) {
324 sisfb_specialtiming = mycustomttable[i].SpecialID; 324 sisfb_specialtiming = mycustomttable[i].SpecialID;
325 found = TRUE; 325 found = true;
326 printk(KERN_INFO "sisfb: Special timing for %s %s forced (\"%s\")\n", 326 printk(KERN_INFO "sisfb: Special timing for %s %s forced (\"%s\")\n",
327 mycustomttable[i].vendorName, 327 mycustomttable[i].vendorName,
328 mycustomttable[i].cardName, 328 mycustomttable[i].cardName,
@@ -353,7 +353,7 @@ sisfb_detect_custom_timing(struct sis_video_info *ivideo)
353{ 353{
354 unsigned char *biosver = NULL; 354 unsigned char *biosver = NULL;
355 unsigned char *biosdate = NULL; 355 unsigned char *biosdate = NULL;
356 BOOLEAN footprint; 356 bool footprint;
357 u32 chksum = 0; 357 u32 chksum = 0;
358 int i, j; 358 int i, j;
359 359
@@ -380,16 +380,16 @@ sisfb_detect_custom_timing(struct sis_video_info *ivideo)
380 (mycustomttable[i].bioschksum == chksum))) && 380 (mycustomttable[i].bioschksum == chksum))) &&
381 (mycustomttable[i].pcisubsysvendor == ivideo->subsysvendor) && 381 (mycustomttable[i].pcisubsysvendor == ivideo->subsysvendor) &&
382 (mycustomttable[i].pcisubsyscard == ivideo->subsysdevice) ) { 382 (mycustomttable[i].pcisubsyscard == ivideo->subsysdevice) ) {
383 footprint = TRUE; 383 footprint = true;
384 for(j = 0; j < 5; j++) { 384 for(j = 0; j < 5; j++) {
385 if(mycustomttable[i].biosFootprintAddr[j]) { 385 if(mycustomttable[i].biosFootprintAddr[j]) {
386 if(ivideo->SiS_Pr.UseROM) { 386 if(ivideo->SiS_Pr.UseROM) {
387 if(ivideo->SiS_Pr.VirtualRomBase[mycustomttable[i].biosFootprintAddr[j]] != 387 if(ivideo->SiS_Pr.VirtualRomBase[mycustomttable[i].biosFootprintAddr[j]] !=
388 mycustomttable[i].biosFootprintData[j]) { 388 mycustomttable[i].biosFootprintData[j]) {
389 footprint = FALSE; 389 footprint = false;
390 } 390 }
391 } else 391 } else
392 footprint = FALSE; 392 footprint = false;
393 } 393 }
394 } 394 }
395 if(footprint) { 395 if(footprint) {
@@ -406,7 +406,7 @@ sisfb_detect_custom_timing(struct sis_video_info *ivideo)
406 } while(mycustomttable[i].chipID); 406 } while(mycustomttable[i].chipID);
407} 407}
408 408
409static BOOLEAN __devinit 409static bool __devinit
410sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer) 410sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
411{ 411{
412 int i, j, xres, yres, refresh, index; 412 int i, j, xres, yres, refresh, index;
@@ -417,13 +417,13 @@ sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
417 buffer[4] != 0xff || buffer[5] != 0xff || 417 buffer[4] != 0xff || buffer[5] != 0xff ||
418 buffer[6] != 0xff || buffer[7] != 0x00) { 418 buffer[6] != 0xff || buffer[7] != 0x00) {
419 printk(KERN_DEBUG "sisfb: Bad EDID header\n"); 419 printk(KERN_DEBUG "sisfb: Bad EDID header\n");
420 return FALSE; 420 return false;
421 } 421 }
422 422
423 if(buffer[0x12] != 0x01) { 423 if(buffer[0x12] != 0x01) {
424 printk(KERN_INFO "sisfb: EDID version %d not supported\n", 424 printk(KERN_INFO "sisfb: EDID version %d not supported\n",
425 buffer[0x12]); 425 buffer[0x12]);
426 return FALSE; 426 return false;
427 } 427 }
428 428
429 monitor->feature = buffer[0x18]; 429 monitor->feature = buffer[0x18];
@@ -449,7 +449,7 @@ sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
449 monitor->vmin = buffer[j + 5]; 449 monitor->vmin = buffer[j + 5];
450 monitor->vmax = buffer[j + 6]; 450 monitor->vmax = buffer[j + 6];
451 monitor->dclockmax = buffer[j + 9] * 10 * 1000; 451 monitor->dclockmax = buffer[j + 9] * 10 * 1000;
452 monitor->datavalid = TRUE; 452 monitor->datavalid = true;
453 break; 453 break;
454 } 454 }
455 j += 18; 455 j += 18;
@@ -501,7 +501,7 @@ sisfb_interpret_edid(struct sisfb_monitor *monitor, u8 *buffer)
501 index += 2; 501 index += 2;
502 } 502 }
503 if((monitor->hmin <= monitor->hmax) && (monitor->vmin <= monitor->vmax)) { 503 if((monitor->hmin <= monitor->hmax) && (monitor->vmin <= monitor->vmax)) {
504 monitor->datavalid = TRUE; 504 monitor->datavalid = true;
505 } 505 }
506 } 506 }
507 507
@@ -514,7 +514,7 @@ sisfb_handle_ddc(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, i
514 unsigned short temp, i, realcrtno = crtno; 514 unsigned short temp, i, realcrtno = crtno;
515 unsigned char buffer[256]; 515 unsigned char buffer[256];
516 516
517 monitor->datavalid = FALSE; 517 monitor->datavalid = false;
518 518
519 if(crtno) { 519 if(crtno) {
520 if(ivideo->vbflags & CRT2_LCD) realcrtno = 1; 520 if(ivideo->vbflags & CRT2_LCD) realcrtno = 1;
@@ -563,7 +563,7 @@ sisfb_handle_ddc(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, i
563 563
564/* -------------- Mode validation --------------- */ 564/* -------------- Mode validation --------------- */
565 565
566static BOOLEAN 566static bool
567sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor, 567sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor,
568 int mode_idx, int rate_idx, int rate) 568 int mode_idx, int rate_idx, int rate)
569{ 569{
@@ -571,10 +571,10 @@ sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor,
571 unsigned int dclock, hsync; 571 unsigned int dclock, hsync;
572 572
573 if(!monitor->datavalid) 573 if(!monitor->datavalid)
574 return TRUE; 574 return true;
575 575
576 if(mode_idx < 0) 576 if(mode_idx < 0)
577 return FALSE; 577 return false;
578 578
579 /* Skip for 320x200, 320x240, 640x400 */ 579 /* Skip for 320x200, 320x240, 640x400 */
580 switch(sisbios_mode[mode_idx].mode_no[ivideo->mni]) { 580 switch(sisbios_mode[mode_idx].mode_no[ivideo->mni]) {
@@ -587,34 +587,34 @@ sisfb_verify_rate(struct sis_video_info *ivideo, struct sisfb_monitor *monitor,
587 case 0x2f: 587 case 0x2f:
588 case 0x5d: 588 case 0x5d:
589 case 0x5e: 589 case 0x5e:
590 return TRUE; 590 return true;
591#ifdef CONFIG_FB_SIS_315 591#ifdef CONFIG_FB_SIS_315
592 case 0x5a: 592 case 0x5a:
593 case 0x5b: 593 case 0x5b:
594 if(ivideo->sisvga_engine == SIS_315_VGA) return TRUE; 594 if(ivideo->sisvga_engine == SIS_315_VGA) return true;
595#endif 595#endif
596 } 596 }
597 597
598 if(rate < (monitor->vmin - 1)) 598 if(rate < (monitor->vmin - 1))
599 return FALSE; 599 return false;
600 if(rate > (monitor->vmax + 1)) 600 if(rate > (monitor->vmax + 1))
601 return FALSE; 601 return false;
602 602
603 if(sisfb_gettotalfrommode(&ivideo->SiS_Pr, 603 if(sisfb_gettotalfrommode(&ivideo->SiS_Pr,
604 sisbios_mode[mode_idx].mode_no[ivideo->mni], 604 sisbios_mode[mode_idx].mode_no[ivideo->mni],
605 &htotal, &vtotal, rate_idx)) { 605 &htotal, &vtotal, rate_idx)) {
606 dclock = (htotal * vtotal * rate) / 1000; 606 dclock = (htotal * vtotal * rate) / 1000;
607 if(dclock > (monitor->dclockmax + 1000)) 607 if(dclock > (monitor->dclockmax + 1000))
608 return FALSE; 608 return false;
609 hsync = dclock / htotal; 609 hsync = dclock / htotal;
610 if(hsync < (monitor->hmin - 1)) 610 if(hsync < (monitor->hmin - 1))
611 return FALSE; 611 return false;
612 if(hsync > (monitor->hmax + 1)) 612 if(hsync > (monitor->hmax + 1))
613 return FALSE; 613 return false;
614 } else { 614 } else {
615 return FALSE; 615 return false;
616 } 616 }
617 return TRUE; 617 return true;
618} 618}
619 619
620static int 620static int
@@ -732,49 +732,49 @@ sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, int
732 } 732 }
733} 733}
734 734
735static BOOLEAN 735static bool
736sisfb_bridgeisslave(struct sis_video_info *ivideo) 736sisfb_bridgeisslave(struct sis_video_info *ivideo)
737{ 737{
738 unsigned char P1_00; 738 unsigned char P1_00;
739 739
740 if(!(ivideo->vbflags2 & VB2_VIDEOBRIDGE)) 740 if(!(ivideo->vbflags2 & VB2_VIDEOBRIDGE))
741 return FALSE; 741 return false;
742 742
743 inSISIDXREG(SISPART1,0x00,P1_00); 743 inSISIDXREG(SISPART1,0x00,P1_00);
744 if( ((ivideo->sisvga_engine == SIS_300_VGA) && (P1_00 & 0xa0) == 0x20) || 744 if( ((ivideo->sisvga_engine == SIS_300_VGA) && (P1_00 & 0xa0) == 0x20) ||
745 ((ivideo->sisvga_engine == SIS_315_VGA) && (P1_00 & 0x50) == 0x10) ) { 745 ((ivideo->sisvga_engine == SIS_315_VGA) && (P1_00 & 0x50) == 0x10) ) {
746 return TRUE; 746 return true;
747 } else { 747 } else {
748 return FALSE; 748 return false;
749 } 749 }
750} 750}
751 751
752static BOOLEAN 752static bool
753sisfballowretracecrt1(struct sis_video_info *ivideo) 753sisfballowretracecrt1(struct sis_video_info *ivideo)
754{ 754{
755 u8 temp; 755 u8 temp;
756 756
757 inSISIDXREG(SISCR,0x17,temp); 757 inSISIDXREG(SISCR,0x17,temp);
758 if(!(temp & 0x80)) 758 if(!(temp & 0x80))
759 return FALSE; 759 return false;
760 760
761 inSISIDXREG(SISSR,0x1f,temp); 761 inSISIDXREG(SISSR,0x1f,temp);
762 if(temp & 0xc0) 762 if(temp & 0xc0)
763 return FALSE; 763 return false;
764 764
765 return TRUE; 765 return true;
766} 766}
767 767
768static BOOLEAN 768static bool
769sisfbcheckvretracecrt1(struct sis_video_info *ivideo) 769sisfbcheckvretracecrt1(struct sis_video_info *ivideo)
770{ 770{
771 if(!sisfballowretracecrt1(ivideo)) 771 if(!sisfballowretracecrt1(ivideo))
772 return FALSE; 772 return false;
773 773
774 if(inSISREG(SISINPSTAT) & 0x08) 774 if(inSISREG(SISINPSTAT) & 0x08)
775 return TRUE; 775 return true;
776 else 776 else
777 return FALSE; 777 return false;
778} 778}
779 779
780static void 780static void
@@ -791,7 +791,7 @@ sisfbwaitretracecrt1(struct sis_video_info *ivideo)
791 while((inSISREG(SISINPSTAT) & 0x08) && --watchdog); 791 while((inSISREG(SISINPSTAT) & 0x08) && --watchdog);
792} 792}
793 793
794static BOOLEAN 794static bool
795sisfbcheckvretracecrt2(struct sis_video_info *ivideo) 795sisfbcheckvretracecrt2(struct sis_video_info *ivideo)
796{ 796{
797 unsigned char temp, reg; 797 unsigned char temp, reg;
@@ -799,17 +799,17 @@ sisfbcheckvretracecrt2(struct sis_video_info *ivideo)
799 switch(ivideo->sisvga_engine) { 799 switch(ivideo->sisvga_engine) {
800 case SIS_300_VGA: reg = 0x25; break; 800 case SIS_300_VGA: reg = 0x25; break;
801 case SIS_315_VGA: reg = 0x30; break; 801 case SIS_315_VGA: reg = 0x30; break;
802 default: return FALSE; 802 default: return false;
803 } 803 }
804 804
805 inSISIDXREG(SISPART1, reg, temp); 805 inSISIDXREG(SISPART1, reg, temp);
806 if(temp & 0x02) 806 if(temp & 0x02)
807 return TRUE; 807 return true;
808 else 808 else
809 return FALSE; 809 return false;
810} 810}
811 811
812static BOOLEAN 812static bool
813sisfb_CheckVBRetrace(struct sis_video_info *ivideo) 813sisfb_CheckVBRetrace(struct sis_video_info *ivideo)
814{ 814{
815 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { 815 if(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
@@ -874,7 +874,7 @@ static int
874sisfb_myblank(struct sis_video_info *ivideo, int blank) 874sisfb_myblank(struct sis_video_info *ivideo, int blank)
875{ 875{
876 u8 sr01, sr11, sr1f, cr63=0, p2_0, p1_13; 876 u8 sr01, sr11, sr1f, cr63=0, p2_0, p1_13;
877 BOOLEAN backlight = TRUE; 877 bool backlight = true;
878 878
879 switch(blank) { 879 switch(blank) {
880 case FB_BLANK_UNBLANK: /* on */ 880 case FB_BLANK_UNBLANK: /* on */
@@ -884,7 +884,7 @@ sisfb_myblank(struct sis_video_info *ivideo, int blank)
884 cr63 = 0x00; 884 cr63 = 0x00;
885 p2_0 = 0x20; 885 p2_0 = 0x20;
886 p1_13 = 0x00; 886 p1_13 = 0x00;
887 backlight = TRUE; 887 backlight = true;
888 break; 888 break;
889 case FB_BLANK_NORMAL: /* blank */ 889 case FB_BLANK_NORMAL: /* blank */
890 sr01 = 0x20; 890 sr01 = 0x20;
@@ -893,7 +893,7 @@ sisfb_myblank(struct sis_video_info *ivideo, int blank)
893 cr63 = 0x00; 893 cr63 = 0x00;
894 p2_0 = 0x20; 894 p2_0 = 0x20;
895 p1_13 = 0x00; 895 p1_13 = 0x00;
896 backlight = TRUE; 896 backlight = true;
897 break; 897 break;
898 case FB_BLANK_VSYNC_SUSPEND: /* no vsync */ 898 case FB_BLANK_VSYNC_SUSPEND: /* no vsync */
899 sr01 = 0x20; 899 sr01 = 0x20;
@@ -902,7 +902,7 @@ sisfb_myblank(struct sis_video_info *ivideo, int blank)
902 cr63 = 0x40; 902 cr63 = 0x40;
903 p2_0 = 0x40; 903 p2_0 = 0x40;
904 p1_13 = 0x80; 904 p1_13 = 0x80;
905 backlight = FALSE; 905 backlight = false;
906 break; 906 break;
907 case FB_BLANK_HSYNC_SUSPEND: /* no hsync */ 907 case FB_BLANK_HSYNC_SUSPEND: /* no hsync */
908 sr01 = 0x20; 908 sr01 = 0x20;
@@ -911,7 +911,7 @@ sisfb_myblank(struct sis_video_info *ivideo, int blank)
911 cr63 = 0x40; 911 cr63 = 0x40;
912 p2_0 = 0x80; 912 p2_0 = 0x80;
913 p1_13 = 0x40; 913 p1_13 = 0x40;
914 backlight = FALSE; 914 backlight = false;
915 break; 915 break;
916 case FB_BLANK_POWERDOWN: /* off */ 916 case FB_BLANK_POWERDOWN: /* off */
917 sr01 = 0x20; 917 sr01 = 0x20;
@@ -920,7 +920,7 @@ sisfb_myblank(struct sis_video_info *ivideo, int blank)
920 cr63 = 0x40; 920 cr63 = 0x40;
921 p2_0 = 0xc0; 921 p2_0 = 0xc0;
922 p1_13 = 0xc0; 922 p1_13 = 0xc0;
923 backlight = FALSE; 923 backlight = false;
924 break; 924 break;
925 default: 925 default:
926 return 1; 926 return 1;
@@ -1109,11 +1109,11 @@ sisfb_calc_pitch(struct sis_video_info *ivideo, struct fb_var_screeninfo *var)
1109static void 1109static void
1110sisfb_set_pitch(struct sis_video_info *ivideo) 1110sisfb_set_pitch(struct sis_video_info *ivideo)
1111{ 1111{
1112 BOOLEAN isslavemode = FALSE; 1112 bool isslavemode = false;
1113 unsigned short HDisplay1 = ivideo->scrnpitchCRT1 >> 3; 1113 unsigned short HDisplay1 = ivideo->scrnpitchCRT1 >> 3;
1114 unsigned short HDisplay2 = ivideo->video_linelength >> 3; 1114 unsigned short HDisplay2 = ivideo->video_linelength >> 3;
1115 1115
1116 if(sisfb_bridgeisslave(ivideo)) isslavemode = TRUE; 1116 if(sisfb_bridgeisslave(ivideo)) isslavemode = true;
1117 1117
1118 /* We need to set pitch for CRT1 if bridge is in slave mode, too */ 1118 /* We need to set pitch for CRT1 if bridge is in slave mode, too */
1119 if((ivideo->currentvbflags & VB_DISPTYPE_DISP1) || (isslavemode)) { 1119 if((ivideo->currentvbflags & VB_DISPTYPE_DISP1) || (isslavemode)) {
@@ -1178,7 +1178,7 @@ sisfb_set_mode(struct sis_video_info *ivideo, int clrscrn)
1178 1178
1179 sisfb_pre_setmode(ivideo); 1179 sisfb_pre_setmode(ivideo);
1180 1180
1181 if(SiSSetMode(&ivideo->SiS_Pr, modeno) == 0) { 1181 if(!SiSSetMode(&ivideo->SiS_Pr, modeno)) {
1182 printk(KERN_ERR "sisfb: Setting mode[0x%x] failed\n", ivideo->mode_no); 1182 printk(KERN_ERR "sisfb: Setting mode[0x%x] failed\n", ivideo->mode_no);
1183 return -EINVAL; 1183 return -EINVAL;
1184 } 1184 }
@@ -1446,7 +1446,7 @@ sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1446 unsigned int drate = 0, hrate = 0, maxyres; 1446 unsigned int drate = 0, hrate = 0, maxyres;
1447 int found_mode = 0; 1447 int found_mode = 0;
1448 int refresh_rate, search_idx, tidx; 1448 int refresh_rate, search_idx, tidx;
1449 BOOLEAN recalc_clock = FALSE; 1449 bool recalc_clock = false;
1450 u32 pixclock; 1450 u32 pixclock;
1451 1451
1452 htotal = var->left_margin + var->xres + var->right_margin + var->hsync_len; 1452 htotal = var->left_margin + var->xres + var->right_margin + var->hsync_len;
@@ -1524,7 +1524,7 @@ sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1524 (var->bits_per_pixel == 8) ) { 1524 (var->bits_per_pixel == 8) ) {
1525 /* Slave modes on LVDS and 301B-DH */ 1525 /* Slave modes on LVDS and 301B-DH */
1526 refresh_rate = 60; 1526 refresh_rate = 60;
1527 recalc_clock = TRUE; 1527 recalc_clock = true;
1528 } else if( (ivideo->current_htotal == htotal) && 1528 } else if( (ivideo->current_htotal == htotal) &&
1529 (ivideo->current_vtotal == vtotal) && 1529 (ivideo->current_vtotal == vtotal) &&
1530 (ivideo->current_pixclock == pixclock) ) { 1530 (ivideo->current_pixclock == pixclock) ) {
@@ -1545,17 +1545,17 @@ sisfb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1545 } else { 1545 } else {
1546 refresh_rate = 60; 1546 refresh_rate = 60;
1547 } 1547 }
1548 recalc_clock = TRUE; 1548 recalc_clock = true;
1549 } else if((pixclock) && (htotal) && (vtotal)) { 1549 } else if((pixclock) && (htotal) && (vtotal)) {
1550 drate = 1000000000 / pixclock; 1550 drate = 1000000000 / pixclock;
1551 hrate = (drate * 1000) / htotal; 1551 hrate = (drate * 1000) / htotal;
1552 refresh_rate = (unsigned int) (hrate * 2 / vtotal); 1552 refresh_rate = (unsigned int) (hrate * 2 / vtotal);
1553 } else if(ivideo->current_refresh_rate) { 1553 } else if(ivideo->current_refresh_rate) {
1554 refresh_rate = ivideo->current_refresh_rate; 1554 refresh_rate = ivideo->current_refresh_rate;
1555 recalc_clock = TRUE; 1555 recalc_clock = true;
1556 } else { 1556 } else {
1557 refresh_rate = 60; 1557 refresh_rate = 60;
1558 recalc_clock = TRUE; 1558 recalc_clock = true;
1559 } 1559 }
1560 1560
1561 myrateindex = sisfb_search_refresh_rate(ivideo, refresh_rate, search_idx); 1561 myrateindex = sisfb_search_refresh_rate(ivideo, refresh_rate, search_idx);
@@ -2181,7 +2181,7 @@ sisfb_detect_VB_connect(struct sis_video_info *ivideo)
2181 2181
2182/* ------------------ Sensing routines ------------------ */ 2182/* ------------------ Sensing routines ------------------ */
2183 2183
2184static BOOLEAN __devinit 2184static bool __devinit
2185sisfb_test_DDC1(struct sis_video_info *ivideo) 2185sisfb_test_DDC1(struct sis_video_info *ivideo)
2186{ 2186{
2187 unsigned short old; 2187 unsigned short old;
@@ -2191,13 +2191,13 @@ sisfb_test_DDC1(struct sis_video_info *ivideo)
2191 do { 2191 do {
2192 if(old != SiS_ReadDDC1Bit(&ivideo->SiS_Pr)) break; 2192 if(old != SiS_ReadDDC1Bit(&ivideo->SiS_Pr)) break;
2193 } while(count--); 2193 } while(count--);
2194 return (count == -1) ? FALSE : TRUE; 2194 return (count != -1);
2195} 2195}
2196 2196
2197static void __devinit 2197static void __devinit
2198sisfb_sense_crt1(struct sis_video_info *ivideo) 2198sisfb_sense_crt1(struct sis_video_info *ivideo)
2199{ 2199{
2200 BOOLEAN mustwait = FALSE; 2200 bool mustwait = false;
2201 u8 sr1F, cr17; 2201 u8 sr1F, cr17;
2202#ifdef CONFIG_FB_SIS_315 2202#ifdef CONFIG_FB_SIS_315
2203 u8 cr63=0; 2203 u8 cr63=0;
@@ -2208,7 +2208,7 @@ sisfb_sense_crt1(struct sis_video_info *ivideo)
2208 inSISIDXREG(SISSR,0x1F,sr1F); 2208 inSISIDXREG(SISSR,0x1F,sr1F);
2209 orSISIDXREG(SISSR,0x1F,0x04); 2209 orSISIDXREG(SISSR,0x1F,0x04);
2210 andSISIDXREG(SISSR,0x1F,0x3F); 2210 andSISIDXREG(SISSR,0x1F,0x3F);
2211 if(sr1F & 0xc0) mustwait = TRUE; 2211 if(sr1F & 0xc0) mustwait = true;
2212 2212
2213#ifdef CONFIG_FB_SIS_315 2213#ifdef CONFIG_FB_SIS_315
2214 if(ivideo->sisvga_engine == SIS_315_VGA) { 2214 if(ivideo->sisvga_engine == SIS_315_VGA) {
@@ -2222,7 +2222,7 @@ sisfb_sense_crt1(struct sis_video_info *ivideo)
2222 cr17 &= 0x80; 2222 cr17 &= 0x80;
2223 if(!cr17) { 2223 if(!cr17) {
2224 orSISIDXREG(SISCR,0x17,0x80); 2224 orSISIDXREG(SISCR,0x17,0x80);
2225 mustwait = TRUE; 2225 mustwait = true;
2226 outSISIDXREG(SISSR, 0x00, 0x01); 2226 outSISIDXREG(SISSR, 0x00, 0x01);
2227 outSISIDXREG(SISSR, 0x00, 0x03); 2227 outSISIDXREG(SISSR, 0x00, 0x03);
2228 } 2228 }
@@ -2284,7 +2284,7 @@ SiS_SenseLCD(struct sis_video_info *ivideo)
2284 u8 reg, cr37 = 0, paneltype = 0; 2284 u8 reg, cr37 = 0, paneltype = 0;
2285 u16 xres, yres; 2285 u16 xres, yres;
2286 2286
2287 ivideo->SiS_Pr.PanelSelfDetected = FALSE; 2287 ivideo->SiS_Pr.PanelSelfDetected = false;
2288 2288
2289 /* LCD detection only for TMDS bridges */ 2289 /* LCD detection only for TMDS bridges */
2290 if(!(ivideo->vbflags2 & VB2_SISTMDSBRIDGE)) 2290 if(!(ivideo->vbflags2 & VB2_SISTMDSBRIDGE))
@@ -2361,7 +2361,7 @@ SiS_SenseLCD(struct sis_video_info *ivideo)
2361 setSISIDXREG(SISCR, 0x37, 0x0c, cr37); 2361 setSISIDXREG(SISCR, 0x37, 0x0c, cr37);
2362 orSISIDXREG(SISCR, 0x32, 0x08); 2362 orSISIDXREG(SISCR, 0x32, 0x08);
2363 2363
2364 ivideo->SiS_Pr.PanelSelfDetected = TRUE; 2364 ivideo->SiS_Pr.PanelSelfDetected = true;
2365} 2365}
2366 2366
2367static int __devinit 2367static int __devinit
@@ -3016,7 +3016,7 @@ sisfb_save_pdc_emi(struct sis_video_info *ivideo)
3016 int tmp; 3016 int tmp;
3017 inSISIDXREG(SISPART1,0x13,tmp); 3017 inSISIDXREG(SISPART1,0x13,tmp);
3018 if(tmp & 0x04) { 3018 if(tmp & 0x04) {
3019 ivideo->SiS_Pr.SiS_UseLCDA = TRUE; 3019 ivideo->SiS_Pr.SiS_UseLCDA = true;
3020 ivideo->detectedlcda = 0x03; 3020 ivideo->detectedlcda = 0x03;
3021 } 3021 }
3022 } 3022 }
@@ -3071,9 +3071,9 @@ sisfb_save_pdc_emi(struct sis_video_info *ivideo)
3071 inSISIDXREG(SISPART4,0x31,ivideo->SiS_Pr.EMI_31); 3071 inSISIDXREG(SISPART4,0x31,ivideo->SiS_Pr.EMI_31);
3072 inSISIDXREG(SISPART4,0x32,ivideo->SiS_Pr.EMI_32); 3072 inSISIDXREG(SISPART4,0x32,ivideo->SiS_Pr.EMI_32);
3073 inSISIDXREG(SISPART4,0x33,ivideo->SiS_Pr.EMI_33); 3073 inSISIDXREG(SISPART4,0x33,ivideo->SiS_Pr.EMI_33);
3074 ivideo->SiS_Pr.HaveEMI = TRUE; 3074 ivideo->SiS_Pr.HaveEMI = true;
3075 if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) { 3075 if((tmp & 0x20) || (ivideo->detectedlcda != 0xff)) {
3076 ivideo->SiS_Pr.HaveEMILCD = TRUE; 3076 ivideo->SiS_Pr.HaveEMILCD = true;
3077 } 3077 }
3078 } 3078 }
3079 } 3079 }
@@ -3558,8 +3558,8 @@ sisfb_pre_setmode(struct sis_video_info *ivideo)
3558 } 3558 }
3559#endif 3559#endif
3560 3560
3561 SiS_SetEnableDstn(&ivideo->SiS_Pr, FALSE); 3561 SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
3562 SiS_SetEnableFstn(&ivideo->SiS_Pr, FALSE); 3562 SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
3563 ivideo->curFSTN = ivideo->curDSTN = 0; 3563 ivideo->curFSTN = ivideo->curDSTN = 0;
3564 3564
3565 switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) { 3565 switch(ivideo->currentvbflags & VB_DISPTYPE_DISP2) {
@@ -3814,8 +3814,8 @@ sisfb_set_TVyposoffset(struct sis_video_info *ivideo, int val)
3814static void 3814static void
3815sisfb_post_setmode(struct sis_video_info *ivideo) 3815sisfb_post_setmode(struct sis_video_info *ivideo)
3816{ 3816{
3817 BOOLEAN crt1isoff = FALSE; 3817 bool crt1isoff = false;
3818 BOOLEAN doit = TRUE; 3818 bool doit = true;
3819#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315) 3819#if defined(CONFIG_FB_SIS_300) || defined(CONFIG_FB_SIS_315)
3820 u8 reg; 3820 u8 reg;
3821#endif 3821#endif
@@ -3834,17 +3834,17 @@ sisfb_post_setmode(struct sis_video_info *ivideo)
3834 3834
3835 /* We can't switch off CRT1 if bridge is in slave mode */ 3835 /* We can't switch off CRT1 if bridge is in slave mode */
3836 if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) { 3836 if(ivideo->vbflags2 & VB2_VIDEOBRIDGE) {
3837 if(sisfb_bridgeisslave(ivideo)) doit = FALSE; 3837 if(sisfb_bridgeisslave(ivideo)) doit = false;
3838 } else 3838 } else
3839 ivideo->sisfb_crt1off = 0; 3839 ivideo->sisfb_crt1off = 0;
3840 3840
3841#ifdef CONFIG_FB_SIS_300 3841#ifdef CONFIG_FB_SIS_300
3842 if(ivideo->sisvga_engine == SIS_300_VGA) { 3842 if(ivideo->sisvga_engine == SIS_300_VGA) {
3843 if((ivideo->sisfb_crt1off) && (doit)) { 3843 if((ivideo->sisfb_crt1off) && (doit)) {
3844 crt1isoff = TRUE; 3844 crt1isoff = true;
3845 reg = 0x00; 3845 reg = 0x00;
3846 } else { 3846 } else {
3847 crt1isoff = FALSE; 3847 crt1isoff = false;
3848 reg = 0x80; 3848 reg = 0x80;
3849 } 3849 }
3850 setSISIDXREG(SISCR, 0x17, 0x7f, reg); 3850 setSISIDXREG(SISCR, 0x17, 0x7f, reg);
@@ -3853,11 +3853,11 @@ sisfb_post_setmode(struct sis_video_info *ivideo)
3853#ifdef CONFIG_FB_SIS_315 3853#ifdef CONFIG_FB_SIS_315
3854 if(ivideo->sisvga_engine == SIS_315_VGA) { 3854 if(ivideo->sisvga_engine == SIS_315_VGA) {
3855 if((ivideo->sisfb_crt1off) && (doit)) { 3855 if((ivideo->sisfb_crt1off) && (doit)) {
3856 crt1isoff = TRUE; 3856 crt1isoff = true;
3857 reg = 0x40; 3857 reg = 0x40;
3858 reg1 = 0xc0; 3858 reg1 = 0xc0;
3859 } else { 3859 } else {
3860 crt1isoff = FALSE; 3860 crt1isoff = false;
3861 reg = 0x00; 3861 reg = 0x00;
3862 reg1 = 0x00; 3862 reg1 = 0x00;
3863 } 3863 }
@@ -4004,9 +4004,9 @@ sisfb_setup(char *options)
4004 } else if(!strnicmp(this_opt, "tvstandard:",11)) { 4004 } else if(!strnicmp(this_opt, "tvstandard:",11)) {
4005 sisfb_search_tvstd(this_opt + 11); 4005 sisfb_search_tvstd(this_opt + 11);
4006 } else if(!strnicmp(this_opt, "mode:", 5)) { 4006 } else if(!strnicmp(this_opt, "mode:", 5)) {
4007 sisfb_search_mode(this_opt + 5, FALSE); 4007 sisfb_search_mode(this_opt + 5, false);
4008 } else if(!strnicmp(this_opt, "vesa:", 5)) { 4008 } else if(!strnicmp(this_opt, "vesa:", 5)) {
4009 sisfb_search_vesamode(simple_strtoul(this_opt + 5, NULL, 0), FALSE); 4009 sisfb_search_vesamode(simple_strtoul(this_opt + 5, NULL, 0), false);
4010 } else if(!strnicmp(this_opt, "rate:", 5)) { 4010 } else if(!strnicmp(this_opt, "rate:", 5)) {
4011 sisfb_parm_rate = simple_strtoul(this_opt + 5, NULL, 0); 4011 sisfb_parm_rate = simple_strtoul(this_opt + 5, NULL, 0);
4012 } else if(!strnicmp(this_opt, "forcecrt1:", 10)) { 4012 } else if(!strnicmp(this_opt, "forcecrt1:", 10)) {
@@ -4062,7 +4062,7 @@ sisfb_setup(char *options)
4062 sisfb_lvdshl = temp; 4062 sisfb_lvdshl = temp;
4063 } 4063 }
4064 } else if(this_opt[0] >= '0' && this_opt[0] <= '9') { 4064 } else if(this_opt[0] >= '0' && this_opt[0] <= '9') {
4065 sisfb_search_mode(this_opt, TRUE); 4065 sisfb_search_mode(this_opt, true);
4066#if !defined(__i386__) && !defined(__x86_64__) 4066#if !defined(__i386__) && !defined(__x86_64__)
4067 } else if(!strnicmp(this_opt, "resetcard", 9)) { 4067 } else if(!strnicmp(this_opt, "resetcard", 9)) {
4068 sisfb_resetcard = 1; 4068 sisfb_resetcard = 1;
@@ -4564,9 +4564,9 @@ sisfb_post_sis300(struct pci_dev *pdev)
4564 sisfb_sense_crt1(ivideo); 4564 sisfb_sense_crt1(ivideo);
4565 4565
4566 /* Set default mode, don't clear screen */ 4566 /* Set default mode, don't clear screen */
4567 ivideo->SiS_Pr.SiS_UseOEM = FALSE; 4567 ivideo->SiS_Pr.SiS_UseOEM = false;
4568 SiS_SetEnableDstn(&ivideo->SiS_Pr, FALSE); 4568 SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
4569 SiS_SetEnableFstn(&ivideo->SiS_Pr, FALSE); 4569 SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
4570 ivideo->curFSTN = ivideo->curDSTN = 0; 4570 ivideo->curFSTN = ivideo->curDSTN = 0;
4571 ivideo->SiS_Pr.VideoMemorySize = 8 << 20; 4571 ivideo->SiS_Pr.VideoMemorySize = 8 << 20;
4572 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80); 4572 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
@@ -5680,9 +5680,9 @@ sisfb_post_xgi(struct pci_dev *pdev)
5680 } else { 5680 } else {
5681 5681
5682 /* Set default mode, don't clear screen */ 5682 /* Set default mode, don't clear screen */
5683 ivideo->SiS_Pr.SiS_UseOEM = FALSE; 5683 ivideo->SiS_Pr.SiS_UseOEM = false;
5684 SiS_SetEnableDstn(&ivideo->SiS_Pr, FALSE); 5684 SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
5685 SiS_SetEnableFstn(&ivideo->SiS_Pr, FALSE); 5685 SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
5686 ivideo->curFSTN = ivideo->curDSTN = 0; 5686 ivideo->curFSTN = ivideo->curDSTN = 0;
5687 ivideo->SiS_Pr.VideoMemorySize = 8 << 20; 5687 ivideo->SiS_Pr.VideoMemorySize = 8 << 20;
5688 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80); 5688 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
@@ -5723,9 +5723,9 @@ sisfb_post_xgi(struct pci_dev *pdev)
5723 } 5723 }
5724 5724
5725 /* Set default mode, don't clear screen */ 5725 /* Set default mode, don't clear screen */
5726 ivideo->SiS_Pr.SiS_UseOEM = FALSE; 5726 ivideo->SiS_Pr.SiS_UseOEM = false;
5727 SiS_SetEnableDstn(&ivideo->SiS_Pr, FALSE); 5727 SiS_SetEnableDstn(&ivideo->SiS_Pr, false);
5728 SiS_SetEnableFstn(&ivideo->SiS_Pr, FALSE); 5728 SiS_SetEnableFstn(&ivideo->SiS_Pr, false);
5729 ivideo->curFSTN = ivideo->curDSTN = 0; 5729 ivideo->curFSTN = ivideo->curDSTN = 0;
5730 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80); 5730 SiSSetMode(&ivideo->SiS_Pr, 0x2e | 0x80);
5731 5731
@@ -5819,7 +5819,7 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5819 ivideo->detectedpdca = 0xff; 5819 ivideo->detectedpdca = 0xff;
5820 ivideo->detectedlcda = 0xff; 5820 ivideo->detectedlcda = 0xff;
5821 5821
5822 ivideo->sisfb_thismonitor.datavalid = FALSE; 5822 ivideo->sisfb_thismonitor.datavalid = false;
5823 5823
5824 ivideo->current_base = 0; 5824 ivideo->current_base = 0;
5825 5825
@@ -5871,21 +5871,21 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5871 5871
5872 ivideo->SiS_Pr.SiS_Backup70xx = 0xff; 5872 ivideo->SiS_Pr.SiS_Backup70xx = 0xff;
5873 ivideo->SiS_Pr.SiS_CHOverScan = -1; 5873 ivideo->SiS_Pr.SiS_CHOverScan = -1;
5874 ivideo->SiS_Pr.SiS_ChSW = FALSE; 5874 ivideo->SiS_Pr.SiS_ChSW = false;
5875 ivideo->SiS_Pr.SiS_UseLCDA = FALSE; 5875 ivideo->SiS_Pr.SiS_UseLCDA = false;
5876 ivideo->SiS_Pr.HaveEMI = FALSE; 5876 ivideo->SiS_Pr.HaveEMI = false;
5877 ivideo->SiS_Pr.HaveEMILCD = FALSE; 5877 ivideo->SiS_Pr.HaveEMILCD = false;
5878 ivideo->SiS_Pr.OverruleEMI = FALSE; 5878 ivideo->SiS_Pr.OverruleEMI = false;
5879 ivideo->SiS_Pr.SiS_SensibleSR11 = FALSE; 5879 ivideo->SiS_Pr.SiS_SensibleSR11 = false;
5880 ivideo->SiS_Pr.SiS_MyCR63 = 0x63; 5880 ivideo->SiS_Pr.SiS_MyCR63 = 0x63;
5881 ivideo->SiS_Pr.PDC = -1; 5881 ivideo->SiS_Pr.PDC = -1;
5882 ivideo->SiS_Pr.PDCA = -1; 5882 ivideo->SiS_Pr.PDCA = -1;
5883 ivideo->SiS_Pr.DDCPortMixup = FALSE; 5883 ivideo->SiS_Pr.DDCPortMixup = false;
5884#ifdef CONFIG_FB_SIS_315 5884#ifdef CONFIG_FB_SIS_315
5885 if(ivideo->chip >= SIS_330) { 5885 if(ivideo->chip >= SIS_330) {
5886 ivideo->SiS_Pr.SiS_MyCR63 = 0x53; 5886 ivideo->SiS_Pr.SiS_MyCR63 = 0x53;
5887 if(ivideo->chip >= SIS_661) { 5887 if(ivideo->chip >= SIS_661) {
5888 ivideo->SiS_Pr.SiS_SensibleSR11 = TRUE; 5888 ivideo->SiS_Pr.SiS_SensibleSR11 = true;
5889 } 5889 }
5890 } 5890 }
5891#endif 5891#endif
@@ -5969,7 +5969,7 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5969 do { 5969 do {
5970 if(mychswtable[i].subsysVendor == ivideo->subsysvendor && 5970 if(mychswtable[i].subsysVendor == ivideo->subsysvendor &&
5971 mychswtable[i].subsysCard == ivideo->subsysdevice) { 5971 mychswtable[i].subsysCard == ivideo->subsysdevice) {
5972 ivideo->SiS_Pr.SiS_ChSW = TRUE; 5972 ivideo->SiS_Pr.SiS_ChSW = true;
5973 printk(KERN_DEBUG "sisfb: Identified [%s %s] " 5973 printk(KERN_DEBUG "sisfb: Identified [%s %s] "
5974 "requiring Chrontel/GPIO setup\n", 5974 "requiring Chrontel/GPIO setup\n",
5975 mychswtable[i].vendorName, 5975 mychswtable[i].vendorName,
@@ -6018,20 +6018,20 @@ sisfb_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
6018 /* Search and copy ROM image */ 6018 /* Search and copy ROM image */
6019 ivideo->bios_abase = NULL; 6019 ivideo->bios_abase = NULL;
6020 ivideo->SiS_Pr.VirtualRomBase = NULL; 6020 ivideo->SiS_Pr.VirtualRomBase = NULL;
6021 ivideo->SiS_Pr.UseROM = FALSE; 6021 ivideo->SiS_Pr.UseROM = false;
6022 ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = FALSE; 6022 ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = false;
6023 if(ivideo->sisfb_userom) { 6023 if(ivideo->sisfb_userom) {
6024 ivideo->SiS_Pr.VirtualRomBase = sisfb_find_rom(pdev); 6024 ivideo->SiS_Pr.VirtualRomBase = sisfb_find_rom(pdev);
6025 ivideo->bios_abase = ivideo->SiS_Pr.VirtualRomBase; 6025 ivideo->bios_abase = ivideo->SiS_Pr.VirtualRomBase;
6026 ivideo->SiS_Pr.UseROM = (ivideo->SiS_Pr.VirtualRomBase) ? TRUE : FALSE; 6026 ivideo->SiS_Pr.UseROM = (bool)(ivideo->SiS_Pr.VirtualRomBase);
6027 printk(KERN_INFO "sisfb: Video ROM %sfound\n", 6027 printk(KERN_INFO "sisfb: Video ROM %sfound\n",
6028 ivideo->SiS_Pr.UseROM ? "" : "not "); 6028 ivideo->SiS_Pr.UseROM ? "" : "not ");
6029 if((ivideo->SiS_Pr.UseROM) && (ivideo->chip >= XGI_20)) { 6029 if((ivideo->SiS_Pr.UseROM) && (ivideo->chip >= XGI_20)) {
6030 ivideo->SiS_Pr.UseROM = FALSE; 6030 ivideo->SiS_Pr.UseROM = false;
6031 ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = TRUE; 6031 ivideo->haveXGIROM = ivideo->SiS_Pr.SiS_XGIROM = true;
6032 if( (ivideo->revision_id == 2) && 6032 if( (ivideo->revision_id == 2) &&
6033 (!(ivideo->bios_abase[0x1d1] & 0x01)) ) { 6033 (!(ivideo->bios_abase[0x1d1] & 0x01)) ) {
6034 ivideo->SiS_Pr.DDCPortMixup = TRUE; 6034 ivideo->SiS_Pr.DDCPortMixup = true;
6035 } 6035 }
6036 } 6036 }
6037 } else { 6037 } else {
@@ -6677,9 +6677,9 @@ static int __init sisfb_init_module(void)
6677 sisfb_search_tvstd(tvstandard); 6677 sisfb_search_tvstd(tvstandard);
6678 6678
6679 if(mode) 6679 if(mode)
6680 sisfb_search_mode(mode, FALSE); 6680 sisfb_search_mode(mode, false);
6681 else if(vesa != -1) 6681 else if(vesa != -1)
6682 sisfb_search_vesamode(vesa, FALSE); 6682 sisfb_search_vesamode(vesa, false);
6683 6683
6684 sisfb_crt1off = (crt1off == 0) ? 1 : 0; 6684 sisfb_crt1off = (crt1off == 0) ? 1 : 0;
6685 6685
diff --git a/drivers/video/sis/sis_main.h b/drivers/video/sis/sis_main.h
index 88e4f1e4147..3e3b7fa05d6 100644
--- a/drivers/video/sis/sis_main.h
+++ b/drivers/video/sis/sis_main.h
@@ -411,54 +411,54 @@ static const struct _sis_vrate {
411 u16 xres; 411 u16 xres;
412 u16 yres; 412 u16 yres;
413 u16 refresh; 413 u16 refresh;
414 BOOLEAN SiS730valid32bpp; 414 bool SiS730valid32bpp;
415} sisfb_vrate[] = { 415} sisfb_vrate[] = {
416 {1, 320, 200, 70, TRUE}, 416 {1, 320, 200, 70, true},
417 {1, 320, 240, 60, TRUE}, 417 {1, 320, 240, 60, true},
418 {1, 400, 300, 60, TRUE}, 418 {1, 400, 300, 60, true},
419 {1, 512, 384, 60, TRUE}, 419 {1, 512, 384, 60, true},
420 {1, 640, 400, 72, TRUE}, 420 {1, 640, 400, 72, true},
421 {1, 640, 480, 60, TRUE}, {2, 640, 480, 72, TRUE}, {3, 640, 480, 75, TRUE}, 421 {1, 640, 480, 60, true}, {2, 640, 480, 72, true}, {3, 640, 480, 75, true},
422 {4, 640, 480, 85, TRUE}, {5, 640, 480, 100, TRUE}, {6, 640, 480, 120, TRUE}, 422 {4, 640, 480, 85, true}, {5, 640, 480, 100, true}, {6, 640, 480, 120, true},
423 {7, 640, 480, 160, TRUE}, {8, 640, 480, 200, TRUE}, 423 {7, 640, 480, 160, true}, {8, 640, 480, 200, true},
424 {1, 720, 480, 60, TRUE}, 424 {1, 720, 480, 60, true},
425 {1, 720, 576, 58, TRUE}, 425 {1, 720, 576, 58, true},
426 {1, 768, 576, 58, TRUE}, 426 {1, 768, 576, 58, true},
427 {1, 800, 480, 60, TRUE}, {2, 800, 480, 75, TRUE}, {3, 800, 480, 85, TRUE}, 427 {1, 800, 480, 60, true}, {2, 800, 480, 75, true}, {3, 800, 480, 85, true},
428 {1, 800, 600, 56, TRUE}, {2, 800, 600, 60, TRUE}, {3, 800, 600, 72, TRUE}, 428 {1, 800, 600, 56, true}, {2, 800, 600, 60, true}, {3, 800, 600, 72, true},
429 {4, 800, 600, 75, TRUE}, {5, 800, 600, 85, TRUE}, {6, 800, 600, 105, TRUE}, 429 {4, 800, 600, 75, true}, {5, 800, 600, 85, true}, {6, 800, 600, 105, true},
430 {7, 800, 600, 120, TRUE}, {8, 800, 600, 160, TRUE}, 430 {7, 800, 600, 120, true}, {8, 800, 600, 160, true},
431 {1, 848, 480, 39, TRUE}, {2, 848, 480, 60, TRUE}, 431 {1, 848, 480, 39, true}, {2, 848, 480, 60, true},
432 {1, 856, 480, 39, TRUE}, {2, 856, 480, 60, TRUE}, 432 {1, 856, 480, 39, true}, {2, 856, 480, 60, true},
433 {1, 960, 540, 60, TRUE}, 433 {1, 960, 540, 60, true},
434 {1, 960, 600, 60, TRUE}, 434 {1, 960, 600, 60, true},
435 {1, 1024, 576, 60, TRUE}, {2, 1024, 576, 75, TRUE}, {3, 1024, 576, 85, TRUE}, 435 {1, 1024, 576, 60, true}, {2, 1024, 576, 75, true}, {3, 1024, 576, 85, true},
436 {1, 1024, 600, 60, TRUE}, 436 {1, 1024, 600, 60, true},
437 {1, 1024, 768, 43, TRUE}, {2, 1024, 768, 60, TRUE}, {3, 1024, 768, 70, FALSE}, 437 {1, 1024, 768, 43, true}, {2, 1024, 768, 60, true}, {3, 1024, 768, 70, false},
438 {4, 1024, 768, 75, FALSE}, {5, 1024, 768, 85, TRUE}, {6, 1024, 768, 100, TRUE}, 438 {4, 1024, 768, 75, false}, {5, 1024, 768, 85, true}, {6, 1024, 768, 100, true},
439 {7, 1024, 768, 120, TRUE}, 439 {7, 1024, 768, 120, true},
440 {1, 1152, 768, 60, TRUE}, 440 {1, 1152, 768, 60, true},
441 {1, 1152, 864, 60, TRUE}, {2, 1152, 864, 75, TRUE}, {3, 1152, 864, 84, TRUE}, 441 {1, 1152, 864, 60, true}, {2, 1152, 864, 75, true}, {3, 1152, 864, 84, true},
442 {1, 1280, 720, 60, TRUE}, {2, 1280, 720, 75, TRUE}, {3, 1280, 720, 85, TRUE}, 442 {1, 1280, 720, 60, true}, {2, 1280, 720, 75, true}, {3, 1280, 720, 85, true},
443 {1, 1280, 768, 60, TRUE}, 443 {1, 1280, 768, 60, true},
444 {1, 1280, 800, 60, TRUE}, 444 {1, 1280, 800, 60, true},
445 {1, 1280, 854, 60, TRUE}, 445 {1, 1280, 854, 60, true},
446 {1, 1280, 960, 60, TRUE}, {2, 1280, 960, 85, TRUE}, 446 {1, 1280, 960, 60, true}, {2, 1280, 960, 85, true},
447 {1, 1280, 1024, 43, TRUE}, {2, 1280, 1024, 60, TRUE}, {3, 1280, 1024, 75, TRUE}, 447 {1, 1280, 1024, 43, true}, {2, 1280, 1024, 60, true}, {3, 1280, 1024, 75, true},
448 {4, 1280, 1024, 85, TRUE}, 448 {4, 1280, 1024, 85, true},
449 {1, 1360, 768, 60, TRUE}, 449 {1, 1360, 768, 60, true},
450 {1, 1360, 1024, 59, TRUE}, 450 {1, 1360, 1024, 59, true},
451 {1, 1400, 1050, 60, TRUE}, {2, 1400, 1050, 75, TRUE}, 451 {1, 1400, 1050, 60, true}, {2, 1400, 1050, 75, true},
452 {1, 1600, 1200, 60, TRUE}, {2, 1600, 1200, 65, TRUE}, {3, 1600, 1200, 70, TRUE}, 452 {1, 1600, 1200, 60, true}, {2, 1600, 1200, 65, true}, {3, 1600, 1200, 70, true},
453 {4, 1600, 1200, 75, TRUE}, {5, 1600, 1200, 85, TRUE}, {6, 1600, 1200, 100, TRUE}, 453 {4, 1600, 1200, 75, true}, {5, 1600, 1200, 85, true}, {6, 1600, 1200, 100, true},
454 {7, 1600, 1200, 120, TRUE}, 454 {7, 1600, 1200, 120, true},
455 {1, 1680, 1050, 60, TRUE}, 455 {1, 1680, 1050, 60, true},
456 {1, 1920, 1080, 30, TRUE}, 456 {1, 1920, 1080, 30, true},
457 {1, 1920, 1440, 60, TRUE}, {2, 1920, 1440, 65, TRUE}, {3, 1920, 1440, 70, TRUE}, 457 {1, 1920, 1440, 60, true}, {2, 1920, 1440, 65, true}, {3, 1920, 1440, 70, true},
458 {4, 1920, 1440, 75, TRUE}, {5, 1920, 1440, 85, TRUE}, {6, 1920, 1440, 100, TRUE}, 458 {4, 1920, 1440, 75, true}, {5, 1920, 1440, 85, true}, {6, 1920, 1440, 100, true},
459 {1, 2048, 1536, 60, TRUE}, {2, 2048, 1536, 65, TRUE}, {3, 2048, 1536, 70, TRUE}, 459 {1, 2048, 1536, 60, true}, {2, 2048, 1536, 65, true}, {3, 2048, 1536, 70, true},
460 {4, 2048, 1536, 75, TRUE}, {5, 2048, 1536, 85, TRUE}, 460 {4, 2048, 1536, 75, true}, {5, 2048, 1536, 85, true},
461 {0, 0, 0, 0, FALSE} 461 {0, 0, 0, 0, false}
462}; 462};
463 463
464static struct _sisfbddcsmodes { 464static struct _sisfbddcsmodes {
@@ -691,7 +691,7 @@ extern int sisfb_initaccel(struct sis_video_info *ivideo);
691extern void sisfb_syncaccel(struct sis_video_info *ivideo); 691extern void sisfb_syncaccel(struct sis_video_info *ivideo);
692 692
693/* Internal general routines */ 693/* Internal general routines */
694static void sisfb_search_mode(char *name, BOOLEAN quiet); 694static void sisfb_search_mode(char *name, bool quiet);
695static int sisfb_validate_mode(struct sis_video_info *ivideo, int modeindex, u32 vbflags); 695static int sisfb_validate_mode(struct sis_video_info *ivideo, int modeindex, u32 vbflags);
696static u8 sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate, 696static u8 sisfb_search_refresh_rate(struct sis_video_info *ivideo, unsigned int rate,
697 int index); 697 int index);
@@ -702,10 +702,10 @@ static int sisfb_do_set_var(struct fb_var_screeninfo *var, int isactive,
702 struct fb_info *info); 702 struct fb_info *info);
703static void sisfb_pre_setmode(struct sis_video_info *ivideo); 703static void sisfb_pre_setmode(struct sis_video_info *ivideo);
704static void sisfb_post_setmode(struct sis_video_info *ivideo); 704static void sisfb_post_setmode(struct sis_video_info *ivideo);
705static BOOLEAN sisfb_CheckVBRetrace(struct sis_video_info *ivideo); 705static bool sisfb_CheckVBRetrace(struct sis_video_info *ivideo);
706static BOOLEAN sisfbcheckvretracecrt2(struct sis_video_info *ivideo); 706static bool sisfbcheckvretracecrt2(struct sis_video_info *ivideo);
707static BOOLEAN sisfbcheckvretracecrt1(struct sis_video_info *ivideo); 707static bool sisfbcheckvretracecrt1(struct sis_video_info *ivideo);
708static BOOLEAN sisfb_bridgeisslave(struct sis_video_info *ivideo); 708static bool sisfb_bridgeisslave(struct sis_video_info *ivideo);
709static void sisfb_detect_VB_connect(struct sis_video_info *ivideo); 709static void sisfb_detect_VB_connect(struct sis_video_info *ivideo);
710static void sisfb_get_VB_type(struct sis_video_info *ivideo); 710static void sisfb_get_VB_type(struct sis_video_info *ivideo);
711static void sisfb_set_TVxposoffset(struct sis_video_info *ivideo, int val); 711static void sisfb_set_TVxposoffset(struct sis_video_info *ivideo, int val);
@@ -737,20 +737,20 @@ static void sisfb_free_node(struct SIS_HEAP *memheap, struct SIS_OH *poh);
737 737
738/* Routines from init.c/init301.c */ 738/* Routines from init.c/init301.c */
739extern unsigned short SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay, 739extern unsigned short SiS_GetModeID_LCD(int VGAEngine, unsigned int VBFlags, int HDisplay,
740 int VDisplay, int Depth, BOOLEAN FSTN, unsigned short CustomT, 740 int VDisplay, int Depth, bool FSTN, unsigned short CustomT,
741 int LCDwith, int LCDheight, unsigned int VBFlags2); 741 int LCDwith, int LCDheight, unsigned int VBFlags2);
742extern unsigned short SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay, 742extern unsigned short SiS_GetModeID_TV(int VGAEngine, unsigned int VBFlags, int HDisplay,
743 int VDisplay, int Depth, unsigned int VBFlags2); 743 int VDisplay, int Depth, unsigned int VBFlags2);
744extern unsigned short SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay, 744extern unsigned short SiS_GetModeID_VGA2(int VGAEngine, unsigned int VBFlags, int HDisplay,
745 int VDisplay, int Depth, unsigned int VBFlags2); 745 int VDisplay, int Depth, unsigned int VBFlags2);
746extern void SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr); 746extern void SiSRegInit(struct SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr);
747extern BOOLEAN SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo); 747extern bool SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo);
748extern void SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable); 748extern void SiS_SetEnableDstn(struct SiS_Private *SiS_Pr, int enable);
749extern void SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable); 749extern void SiS_SetEnableFstn(struct SiS_Private *SiS_Pr, int enable);
750 750
751extern BOOLEAN SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr); 751extern bool SiSDetermineROMLayout661(struct SiS_Private *SiS_Pr);
752 752
753extern BOOLEAN sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno, 753extern bool sisfb_gettotalfrommode(struct SiS_Private *SiS_Pr, unsigned char modeno,
754 int *htotal, int *vtotal, unsigned char rateindex); 754 int *htotal, int *vtotal, unsigned char rateindex);
755extern int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr, 755extern int sisfb_mode_rate_to_dclock(struct SiS_Private *SiS_Pr,
756 unsigned char modeno, unsigned char rateindex); 756 unsigned char modeno, unsigned char rateindex);
diff --git a/drivers/video/sis/vgatypes.h b/drivers/video/sis/vgatypes.h
index 05d08b7889a..b532fbd2b04 100644
--- a/drivers/video/sis/vgatypes.h
+++ b/drivers/video/sis/vgatypes.h
@@ -57,18 +57,6 @@
57#include <linux/version.h> 57#include <linux/version.h>
58#endif 58#endif
59 59
60#ifndef FALSE
61#define FALSE 0
62#endif
63
64#ifndef TRUE
65#define TRUE 1
66#endif
67
68#ifndef BOOLEAN
69typedef unsigned int BOOLEAN;
70#endif
71
72#define SISIOMEMTYPE 60#define SISIOMEMTYPE
73 61
74#ifdef SIS_LINUX_KERNEL 62#ifdef SIS_LINUX_KERNEL
diff --git a/drivers/video/sis/vstruct.h b/drivers/video/sis/vstruct.h
index 9ae32923c14..705c8536052 100644
--- a/drivers/video/sis/vstruct.h
+++ b/drivers/video/sis/vstruct.h
@@ -240,7 +240,7 @@ struct SiS_Private
240 void *ivideo; 240 void *ivideo;
241#endif 241#endif
242 unsigned char *VirtualRomBase; 242 unsigned char *VirtualRomBase;
243 BOOLEAN UseROM; 243 bool UseROM;
244#ifdef SIS_LINUX_KERNEL 244#ifdef SIS_LINUX_KERNEL
245 unsigned char SISIOMEMTYPE *VideoMemoryAddress; 245 unsigned char SISIOMEMTYPE *VideoMemoryAddress;
246 unsigned int VideoMemorySize; 246 unsigned int VideoMemorySize;
@@ -283,24 +283,24 @@ struct SiS_Private
283#ifdef SIS_XORG_XF86 283#ifdef SIS_XORG_XF86
284 unsigned short SiS_CP1, SiS_CP2, SiS_CP3, SiS_CP4; 284 unsigned short SiS_CP1, SiS_CP2, SiS_CP3, SiS_CP4;
285#endif 285#endif
286 BOOLEAN SiS_UseROM; 286 bool SiS_UseROM;
287 BOOLEAN SiS_ROMNew; 287 bool SiS_ROMNew;
288 BOOLEAN SiS_XGIROM; 288 bool SiS_XGIROM;
289 BOOLEAN SiS_NeedRomModeData; 289 bool SiS_NeedRomModeData;
290 BOOLEAN PanelSelfDetected; 290 bool PanelSelfDetected;
291 BOOLEAN DDCPortMixup; 291 bool DDCPortMixup;
292 int SiS_CHOverScan; 292 int SiS_CHOverScan;
293 BOOLEAN SiS_CHSOverScan; 293 bool SiS_CHSOverScan;
294 BOOLEAN SiS_ChSW; 294 bool SiS_ChSW;
295 BOOLEAN SiS_UseLCDA; 295 bool SiS_UseLCDA;
296 int SiS_UseOEM; 296 int SiS_UseOEM;
297 unsigned int SiS_CustomT; 297 unsigned int SiS_CustomT;
298 int SiS_UseWide, SiS_UseWideCRT2; 298 int SiS_UseWide, SiS_UseWideCRT2;
299 int SiS_TVBlue; 299 int SiS_TVBlue;
300 unsigned short SiS_Backup70xx; 300 unsigned short SiS_Backup70xx;
301 BOOLEAN HaveEMI; 301 bool HaveEMI;
302 BOOLEAN HaveEMILCD; 302 bool HaveEMILCD;
303 BOOLEAN OverruleEMI; 303 bool OverruleEMI;
304 unsigned char EMI_30,EMI_31,EMI_32,EMI_33; 304 unsigned char EMI_30,EMI_31,EMI_32,EMI_33;
305 unsigned short SiS_EMIOffset; 305 unsigned short SiS_EMIOffset;
306 unsigned short SiS_PWDOffset; 306 unsigned short SiS_PWDOffset;
@@ -352,7 +352,7 @@ struct SiS_Private
352 unsigned short SiS_DDC_ReadAddr; 352 unsigned short SiS_DDC_ReadAddr;
353 unsigned short SiS_DDC_SecAddr; 353 unsigned short SiS_DDC_SecAddr;
354 unsigned short SiS_ChrontelInit; 354 unsigned short SiS_ChrontelInit;
355 BOOLEAN SiS_SensibleSR11; 355 bool SiS_SensibleSR11;
356 unsigned short SiS661LCD2TableSize; 356 unsigned short SiS661LCD2TableSize;
357 357
358 unsigned short SiS_PanelMinLVDS; 358 unsigned short SiS_PanelMinLVDS;
@@ -494,10 +494,10 @@ struct SiS_Private
494 unsigned short PanelVRS, PanelVRE; 494 unsigned short PanelVRS, PanelVRE;
495 unsigned short PanelVCLKIdx300; 495 unsigned short PanelVCLKIdx300;
496 unsigned short PanelVCLKIdx315; 496 unsigned short PanelVCLKIdx315;
497 BOOLEAN Alternate1600x1200; 497 bool Alternate1600x1200;
498 498
499 BOOLEAN UseCustomMode; 499 bool UseCustomMode;
500 BOOLEAN CRT1UsesCustomMode; 500 bool CRT1UsesCustomMode;
501 unsigned short CHDisplay; 501 unsigned short CHDisplay;
502 unsigned short CHSyncStart; 502 unsigned short CHSyncStart;
503 unsigned short CHSyncEnd; 503 unsigned short CHSyncEnd;
@@ -523,7 +523,7 @@ struct SiS_Private
523 523
524 int LVDSHL; 524 int LVDSHL;
525 525
526 BOOLEAN Backup; 526 bool Backup;
527 unsigned char Backup_Mode; 527 unsigned char Backup_Mode;
528 unsigned char Backup_14; 528 unsigned char Backup_14;
529 unsigned char Backup_15; 529 unsigned char Backup_15;
@@ -542,12 +542,12 @@ struct SiS_Private
542 int CenterScreen; 542 int CenterScreen;
543 543
544 unsigned short CP_Vendor, CP_Product; 544 unsigned short CP_Vendor, CP_Product;
545 BOOLEAN CP_HaveCustomData; 545 bool CP_HaveCustomData;
546 int CP_PreferredX, CP_PreferredY, CP_PreferredIndex; 546 int CP_PreferredX, CP_PreferredY, CP_PreferredIndex;
547 int CP_MaxX, CP_MaxY, CP_MaxClock; 547 int CP_MaxX, CP_MaxY, CP_MaxClock;
548 unsigned char CP_PrefSR2B, CP_PrefSR2C; 548 unsigned char CP_PrefSR2B, CP_PrefSR2C;
549 unsigned short CP_PrefClock; 549 unsigned short CP_PrefClock;
550 BOOLEAN CP_Supports64048075; 550 bool CP_Supports64048075;
551 int CP_HDisplay[7], CP_VDisplay[7]; /* For Custom LCD panel dimensions */ 551 int CP_HDisplay[7], CP_VDisplay[7]; /* For Custom LCD panel dimensions */
552 int CP_HTotal[7], CP_VTotal[7]; 552 int CP_HTotal[7], CP_VTotal[7];
553 int CP_HSyncStart[7], CP_VSyncStart[7]; 553 int CP_HSyncStart[7], CP_VSyncStart[7];
@@ -555,8 +555,8 @@ struct SiS_Private
555 int CP_HBlankStart[7], CP_VBlankStart[7]; 555 int CP_HBlankStart[7], CP_VBlankStart[7];
556 int CP_HBlankEnd[7], CP_VBlankEnd[7]; 556 int CP_HBlankEnd[7], CP_VBlankEnd[7];
557 int CP_Clock[7]; 557 int CP_Clock[7];
558 BOOLEAN CP_DataValid[7]; 558 bool CP_DataValid[7];
559 BOOLEAN CP_HSync_P[7], CP_VSync_P[7], CP_SyncValid[7]; 559 bool CP_HSync_P[7], CP_VSync_P[7], CP_SyncValid[7];
560}; 560};
561 561
562#endif 562#endif
diff --git a/drivers/video/sun3fb.c b/drivers/video/sun3fb.c
deleted file mode 100644
index f80356dfa8e..00000000000
--- a/drivers/video/sun3fb.c
+++ /dev/null
@@ -1,702 +0,0 @@
1/*
2 * linux/drivers/video/sun3fb.c -- Frame buffer driver for Sun3
3 *
4 * (C) 1998 Thomas Bogendoerfer
5 *
6 * This driver is bases on sbusfb.c, which is
7 *
8 * Copyright (C) 1998 Jakub Jelinek
9 *
10 * This driver is partly based on the Open Firmware console driver
11 *
12 * Copyright (C) 1997 Geert Uytterhoeven
13 *
14 * and SPARC console subsystem
15 *
16 * Copyright (C) 1995 Peter Zaitcev (zaitcev@yahoo.com)
17 * Copyright (C) 1995-1997 David S. Miller (davem@caip.rutgers.edu)
18 * Copyright (C) 1995-1996 Miguel de Icaza (miguel@nuclecu.unam.mx)
19 * Copyright (C) 1996 Dave Redman (djhr@tadpole.co.uk)
20 * Copyright (C) 1996-1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
21 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
22 *
23 * This file is subject to the terms and conditions of the GNU General Public
24 * License. See the file COPYING in the main directory of this archive for
25 * more details.
26 */
27
28#include <linux/module.h>
29#include <linux/kernel.h>
30#include <linux/errno.h>
31#include <linux/string.h>
32#include <linux/mm.h>
33#include <linux/slab.h>
34#include <linux/vmalloc.h>
35#include <linux/delay.h>
36#include <linux/interrupt.h>
37#include <linux/fb.h>
38#include <linux/selection.h>
39#include <linux/init.h>
40#include <linux/console.h>
41#include <linux/kd.h>
42#include <linux/vt_kern.h>
43
44#include <asm/uaccess.h>
45#include <asm/pgtable.h> /* io_remap_page_range() */
46
47#ifdef CONFIG_SUN3
48#include <asm/oplib.h>
49#include <asm/machines.h>
50#include <asm/idprom.h>
51
52#define CGFOUR_OBMEM_ADDR 0x1f300000
53#define BWTWO_OBMEM_ADDR 0x1f000000
54#define BWTWO_OBMEM50_ADDR 0x00100000
55
56#endif
57#ifdef CONFIG_SUN3X
58#include <asm/sun3x.h>
59#endif
60#include <video/sbusfb.h>
61
62#define DEFAULT_CURSOR_BLINK_RATE (2*HZ/5)
63
64#define CURSOR_SHAPE 1
65#define CURSOR_BLINK 2
66
67#define mymemset(x,y) memset(x,0,y)
68
69 /*
70 * Interface used by the world
71 */
72
73int sun3fb_init(void);
74void sun3fb_setup(char *options);
75
76static char fontname[40] __initdata = { 0 };
77static int curblink __initdata = 1;
78
79static int sun3fb_get_fix(struct fb_fix_screeninfo *fix, int con,
80 struct fb_info *info);
81static int sun3fb_get_var(struct fb_var_screeninfo *var, int con,
82 struct fb_info *info);
83static int sun3fb_set_var(struct fb_var_screeninfo *var, int con,
84 struct fb_info *info);
85static int sun3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
86 struct fb_info *info);
87static int sun3fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
88 struct fb_info *info);
89static int sun3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
90 u_int transp, struct fb_info *info);
91static int sun3fb_blank(int blank, struct fb_info *info);
92static void sun3fb_cursor(struct display *p, int mode, int x, int y);
93static void sun3fb_clear_margin(struct display *p, int s);
94
95 /*
96 * Interface to the low level console driver
97 */
98
99static int sun3fbcon_switch(int con, struct fb_info *info);
100static int sun3fbcon_updatevar(int con, struct fb_info *info);
101
102 /*
103 * Internal routines
104 */
105
106static int sun3fb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
107 u_int *transp, struct fb_info *info);
108
109static struct fb_ops sun3fb_ops = {
110 .owner = THIS_MODULE,
111 .fb_get_fix = sun3fb_get_fix,
112 .fb_get_var = sun3fb_get_var,
113 .fb_set_var = sun3fb_set_var,
114 .fb_get_cmap = sun3fb_get_cmap,
115 .fb_set_cmap = sun3fb_set_cmap,
116 .fb_setcolreg = sun3fb_setcolreg,
117 .fb_blank = sun3fb_blank,
118};
119
120static void sun3fb_clear_margin(struct display *p, int s)
121{
122 struct fb_info_sbusfb *fb = sbusfbinfod(p);
123
124 return;
125
126 if (fb->switch_from_graph)
127 (*fb->switch_from_graph)(fb);
128 if (fb->fill) {
129 unsigned short rects [16];
130
131 rects [0] = 0;
132 rects [1] = 0;
133 rects [2] = fb->var.xres_virtual;
134 rects [3] = fb->y_margin;
135 rects [4] = 0;
136 rects [5] = fb->y_margin;
137 rects [6] = fb->x_margin;
138 rects [7] = fb->var.yres_virtual;
139 rects [8] = fb->var.xres_virtual - fb->x_margin;
140 rects [9] = fb->y_margin;
141 rects [10] = fb->var.xres_virtual;
142 rects [11] = fb->var.yres_virtual;
143 rects [12] = fb->x_margin;
144 rects [13] = fb->var.yres_virtual - fb->y_margin;
145 rects [14] = fb->var.xres_virtual - fb->x_margin;
146 rects [15] = fb->var.yres_virtual;
147 (*fb->fill)(fb, p, s, 4, rects);
148 } else {
149 unsigned char *fb_base = fb->info.screen_base, *q;
150 int skip_bytes = fb->y_margin * fb->var.xres_virtual;
151 int scr_size = fb->var.xres_virtual * fb->var.yres_virtual;
152 int h, he, incr, size;
153
154 he = fb->var.yres;
155 if (fb->var.bits_per_pixel == 1) {
156 fb_base -= (skip_bytes + fb->x_margin) / 8;
157 skip_bytes /= 8;
158 scr_size /= 8;
159 mymemset (fb_base, skip_bytes - fb->x_margin / 8);
160 mymemset (fb_base + scr_size - skip_bytes + fb->x_margin / 8, skip_bytes - fb->x_margin / 8);
161 incr = fb->var.xres_virtual / 8;
162 size = fb->x_margin / 8 * 2;
163 for (q = fb_base + skip_bytes - fb->x_margin / 8, h = 0;
164 h <= he; q += incr, h++)
165 mymemset (q, size);
166 } else {
167 fb_base -= (skip_bytes + fb->x_margin);
168 memset (fb_base, attr_bgcol(p,s), skip_bytes - fb->x_margin);
169 memset (fb_base + scr_size - skip_bytes + fb->x_margin, attr_bgcol(p,s), skip_bytes - fb->x_margin);
170 incr = fb->var.xres_virtual;
171 size = fb->x_margin * 2;
172 for (q = fb_base + skip_bytes - fb->x_margin, h = 0;
173 h <= he; q += incr, h++)
174 memset (q, attr_bgcol(p,s), size);
175 }
176 }
177}
178
179static void sun3fb_disp_setup(struct display *p)
180{
181 struct fb_info_sbusfb *fb = sbusfbinfod(p);
182
183 if (fb->setup)
184 fb->setup(p);
185 sun3fb_clear_margin(p, 0);
186}
187
188 /*
189 * Get the Fixed Part of the Display
190 */
191
192static int sun3fb_get_fix(struct fb_fix_screeninfo *fix, int con,
193 struct fb_info *info)
194{
195 struct fb_info_sbusfb *fb = sbusfbinfo(info);
196
197 memcpy(fix, &fb->fix, sizeof(struct fb_fix_screeninfo));
198 return 0;
199}
200
201 /*
202 * Get the User Defined Part of the Display
203 */
204
205static int sun3fb_get_var(struct fb_var_screeninfo *var, int con,
206 struct fb_info *info)
207{
208 struct fb_info_sbusfb *fb = sbusfbinfo(info);
209
210 memcpy(var, &fb->var, sizeof(struct fb_var_screeninfo));
211 return 0;
212}
213
214 /*
215 * Set the User Defined Part of the Display
216 */
217
218static int sun3fb_set_var(struct fb_var_screeninfo *var, int con,
219 struct fb_info *info)
220{
221 struct fb_info_sbusfb *fb = sbusfbinfo(info);
222
223 if (var->xres > fb->var.xres || var->yres > fb->var.yres ||
224 var->xres_virtual > fb->var.xres_virtual ||
225 var->yres_virtual > fb->var.yres_virtual ||
226 var->bits_per_pixel != fb->var.bits_per_pixel ||
227 var->nonstd ||
228 (var->vmode & FB_VMODE_MASK) != FB_VMODE_NONINTERLACED)
229 return -EINVAL;
230 memcpy(var, &fb->var, sizeof(struct fb_var_screeninfo));
231 return 0;
232}
233
234 /*
235 * Hardware cursor
236 */
237
238static unsigned char hw_cursor_cmap[2] = { 0, 0xff };
239
240static void
241sun3fb_cursor_timer_handler(unsigned long dev_addr)
242{
243 struct fb_info_sbusfb *fb = (struct fb_info_sbusfb *)dev_addr;
244
245 if (!fb->setcursor) return;
246
247 if (fb->cursor.mode & CURSOR_BLINK) {
248 fb->cursor.enable ^= 1;
249 fb->setcursor(fb);
250 }
251
252 fb->cursor.timer.expires = jiffies + fb->cursor.blink_rate;
253 add_timer(&fb->cursor.timer);
254}
255
256static void sun3fb_cursor(struct display *p, int mode, int x, int y)
257{
258 struct fb_info_sbusfb *fb = sbusfbinfod(p);
259
260 switch (mode) {
261 case CM_ERASE:
262 fb->cursor.mode &= ~CURSOR_BLINK;
263 fb->cursor.enable = 0;
264 (*fb->setcursor)(fb);
265 break;
266
267 case CM_MOVE:
268 case CM_DRAW:
269 if (fb->cursor.mode & CURSOR_SHAPE) {
270 fb->cursor.size.fbx = fontwidth(p);
271 fb->cursor.size.fby = fontheight(p);
272 fb->cursor.chot.fbx = 0;
273 fb->cursor.chot.fby = 0;
274 fb->cursor.enable = 1;
275 memset (fb->cursor.bits, 0, sizeof (fb->cursor.bits));
276 fb->cursor.bits[0][fontheight(p) - 2] = (0xffffffff << (32 - fontwidth(p)));
277 fb->cursor.bits[1][fontheight(p) - 2] = (0xffffffff << (32 - fontwidth(p)));
278 fb->cursor.bits[0][fontheight(p) - 1] = (0xffffffff << (32 - fontwidth(p)));
279 fb->cursor.bits[1][fontheight(p) - 1] = (0xffffffff << (32 - fontwidth(p)));
280 (*fb->setcursormap) (fb, hw_cursor_cmap, hw_cursor_cmap, hw_cursor_cmap);
281 (*fb->setcurshape) (fb);
282 }
283 fb->cursor.mode = CURSOR_BLINK;
284 if (fontwidthlog(p))
285 fb->cursor.cpos.fbx = (x << fontwidthlog(p)) + fb->x_margin;
286 else
287 fb->cursor.cpos.fbx = (x * fontwidth(p)) + fb->x_margin;
288 if (fontheightlog(p))
289 fb->cursor.cpos.fby = (y << fontheightlog(p)) + fb->y_margin;
290 else
291 fb->cursor.cpos.fby = (y * fontheight(p)) + fb->y_margin;
292 (*fb->setcursor)(fb);
293 break;
294 }
295}
296
297 /*
298 * Get the Colormap
299 */
300
301static int sun3fb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
302 struct fb_info *info)
303{
304 if (con == info->currcon) /* current console? */
305 return fb_get_cmap(cmap, kspc, sun3fb_getcolreg, info);
306 else if (fb_display[con].cmap.len) /* non default colormap? */
307 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
308 else
309 fb_copy_cmap(fb_default_cmap(1<<fb_display[con].var.bits_per_pixel), cmap, kspc ? 0 : 2);
310 return 0;
311}
312
313 /*
314 * Set the Colormap
315 */
316
317static int sun3fb_set_cmap(struct fb_cmap *cmap, int kspc, int con,
318 struct fb_info *info)
319{
320 int err;
321
322 if (!fb_display[con].cmap.len) { /* no colormap allocated? */
323 if ((err = fb_alloc_cmap(&fb_display[con].cmap, 1<<fb_display[con].var.bits_per_pixel, 0)))
324 return err;
325 }
326 if (con == info->currcon) { /* current console? */
327 err = fb_set_cmap(cmap, kspc, info);
328 if (!err) {
329 struct fb_info_sbusfb *fb = sbusfbinfo(info);
330
331 if (fb->loadcmap)
332 (*fb->loadcmap)(fb, &fb_display[con], cmap->start, cmap->len);
333 }
334 return err;
335 } else
336 fb_copy_cmap(cmap, &fb_display[con].cmap, kspc ? 0 : 1);
337 return 0;
338}
339
340 /*
341 * Setup: parse used options
342 */
343
344void __init sun3fb_setup(char *options)
345{
346 char *p;
347
348 for (p = options;;) {
349 if (!strncmp(p, "font=", 5)) {
350 int i;
351
352 for (i = 0; i < sizeof(fontname) - 1; i++)
353 if (p[i+5] == ' ' || !p[i+5])
354 break;
355 memcpy(fontname, p+5, i);
356 fontname[i] = 0;
357 } else if (!strncmp(p, "noblink", 7))
358 curblink = 0;
359 while (*p && *p != ' ' && *p != ',') p++;
360 if (*p != ',') break;
361 p++;
362 }
363
364 return;
365}
366
367static int sun3fbcon_switch(int con, struct fb_info *info)
368{
369 int x_margin, y_margin;
370 struct fb_info_sbusfb *fb = sbusfbinfo(info);
371 int lastconsole;
372
373 /* Do we have to save the colormap? */
374 if (fb_display[info->currcon].cmap.len)
375 fb_get_cmap(&fb_display[info->currcon].cmap, 1, sun3fb_getcolreg, info);
376
377 if (info->display_fg) {
378 lastconsole = info->display_fg->vc_num;
379 if (lastconsole != con &&
380 (fontwidth(&fb_display[lastconsole]) != fontwidth(&fb_display[con]) ||
381 fontheight(&fb_display[lastconsole]) != fontheight(&fb_display[con])))
382 fb->cursor.mode |= CURSOR_SHAPE;
383 }
384 x_margin = (fb_display[con].var.xres_virtual - fb_display[con].var.xres) / 2;
385 y_margin = (fb_display[con].var.yres_virtual - fb_display[con].var.yres) / 2;
386 if (fb->margins)
387 fb->margins(fb, &fb_display[con], x_margin, y_margin);
388 if (fb->graphmode || fb->x_margin != x_margin || fb->y_margin != y_margin) {
389 fb->x_margin = x_margin; fb->y_margin = y_margin;
390 sun3fb_clear_margin(&fb_display[con], 0);
391 }
392 info->currcon = con;
393 /* Install new colormap */
394 do_install_cmap(con, info);
395 return 0;
396}
397
398 /*
399 * Update the `var' structure (called by fbcon.c)
400 */
401
402static int sun3fbcon_updatevar(int con, struct fb_info *info)
403{
404 /* Nothing */
405 return 0;
406}
407
408 /*
409 * Blank the display.
410 */
411
412static int sun3fb_blank(int blank, struct fb_info *info)
413{
414 struct fb_info_sbusfb *fb = sbusfbinfo(info);
415
416 if (blank && fb->blank)
417 return fb->blank(fb);
418 else if (!blank && fb->unblank)
419 return fb->unblank(fb);
420 return 0;
421}
422
423 /*
424 * Read a single color register and split it into
425 * colors/transparent. Return != 0 for invalid regno.
426 */
427
428static int sun3fb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
429 u_int *transp, struct fb_info *info)
430{
431 struct fb_info_sbusfb *fb = sbusfbinfo(info);
432
433 if (!fb->color_map || regno > 255)
434 return 1;
435 *red = (fb->color_map CM(regno, 0)<<8) | fb->color_map CM(regno, 0);
436 *green = (fb->color_map CM(regno, 1)<<8) | fb->color_map CM(regno, 1);
437 *blue = (fb->color_map CM(regno, 2)<<8) | fb->color_map CM(regno, 2);
438 *transp = 0;
439 return 0;
440}
441
442
443 /*
444 * Set a single color register. The values supplied are already
445 * rounded down to the hardware's capabilities (according to the
446 * entries in the var structure). Return != 0 for invalid regno.
447 */
448
449static int sun3fb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
450 u_int transp, struct fb_info *info)
451{
452 struct fb_info_sbusfb *fb = sbusfbinfo(info);
453
454 if (!fb->color_map || regno > 255)
455 return 1;
456 red >>= 8;
457 green >>= 8;
458 blue >>= 8;
459 fb->color_map CM(regno, 0) = red;
460 fb->color_map CM(regno, 1) = green;
461 fb->color_map CM(regno, 2) = blue;
462 return 0;
463}
464
465static int sun3fb_set_font(struct display *p, int width, int height)
466{
467 int w = p->var.xres_virtual, h = p->var.yres_virtual;
468 int depth = p->var.bits_per_pixel;
469 struct fb_info_sbusfb *fb = sbusfbinfod(p);
470 int x_margin, y_margin;
471
472 if (depth > 8) depth = 8;
473 x_margin = (w % width) / 2;
474 y_margin = (h % height) / 2;
475
476 p->var.xres = w - 2*x_margin;
477 p->var.yres = h - 2*y_margin;
478
479 fb->cursor.mode |= CURSOR_SHAPE;
480
481 if (fb->margins)
482 fb->margins(fb, p, x_margin, y_margin);
483 if (fb->x_margin != x_margin || fb->y_margin != y_margin) {
484 fb->x_margin = x_margin; fb->y_margin = y_margin;
485 sun3fb_clear_margin(p, 0);
486 }
487
488 return 1;
489}
490
491void sun3fb_palette(int enter)
492{
493 int i;
494 struct display *p;
495
496 for (i = 0; i < MAX_NR_CONSOLES; i++) {
497 p = &fb_display[i];
498 if (p->dispsw && p->dispsw->setup == sun3fb_disp_setup &&
499 p->fb_info->display_fg &&
500 p->fb_info->display_fg->vc_num == i) {
501 struct fb_info_sbusfb *fb = sbusfbinfod(p);
502
503 if (fb->restore_palette) {
504 if (enter)
505 fb->restore_palette(fb);
506 else if (vc_cons[i].d->vc_mode != KD_GRAPHICS)
507 vc_cons[i].d->vc_sw->con_set_palette(vc_cons[i].d, color_table);
508 }
509 }
510 }
511}
512
513 /*
514 * Initialisation
515 */
516static int __init sun3fb_init_fb(int fbtype, unsigned long addr)
517{
518 static struct sbus_dev sdb;
519 struct fb_fix_screeninfo *fix;
520 struct fb_var_screeninfo *var;
521 struct display *disp;
522 struct fb_info_sbusfb *fb;
523 struct fbtype *type;
524 int linebytes, w, h, depth;
525 char *p = NULL;
526
527 fb = kmalloc(sizeof(struct fb_info_sbusfb), GFP_ATOMIC);
528 if (!fb)
529 return -ENOMEM;
530
531 memset(fb, 0, sizeof(struct fb_info_sbusfb));
532 fix = &fb->fix;
533 var = &fb->var;
534 disp = &fb->disp;
535 type = &fb->type;
536
537 sdb.reg_addrs[0].phys_addr = addr;
538 fb->sbdp = &sdb;
539
540 type->fb_type = fbtype;
541
542 type->fb_height = h = 900;
543 type->fb_width = w = 1152;
544sizechange:
545 type->fb_depth = depth = (fbtype == FBTYPE_SUN2BW) ? 1 : 8;
546 linebytes = w * depth / 8;
547 type->fb_size = PAGE_ALIGN((linebytes) * h);
548/*
549 fb->x_margin = (w & 7) / 2;
550 fb->y_margin = (h & 15) / 2;
551*/
552 fb->x_margin = fb->y_margin = 0;
553
554 var->xres_virtual = w;
555 var->yres_virtual = h;
556 var->xres = w - 2*fb->x_margin;
557 var->yres = h - 2*fb->y_margin;
558
559 var->bits_per_pixel = depth;
560 var->height = var->width = -1;
561 var->pixclock = 10000;
562 var->vmode = FB_VMODE_NONINTERLACED;
563 var->red.length = var->green.length = var->blue.length = 8;
564
565 fix->line_length = linebytes;
566 fix->smem_len = type->fb_size;
567 fix->type = FB_TYPE_PACKED_PIXELS;
568 fix->visual = FB_VISUAL_PSEUDOCOLOR;
569
570 fb->info.fbops = &sun3fb_ops;
571 fb->info.disp = disp;
572 fb->info.currcon = -1;
573 strcpy(fb->info.fontname, fontname);
574 fb->info.changevar = NULL;
575 fb->info.switch_con = &sun3fbcon_switch;
576 fb->info.updatevar = &sun3fbcon_updatevar;
577 fb->info.flags = FBINFO_FLAG_DEFAULT;
578
579 fb->cursor.hwsize.fbx = 32;
580 fb->cursor.hwsize.fby = 32;
581
582 if (depth > 1 && !fb->color_map) {
583 if((fb->color_map = kmalloc(256 * 3, GFP_ATOMIC))==NULL)
584 return -ENOMEM;
585 }
586
587 switch(fbtype) {
588#ifdef CONFIG_FB_CGSIX
589 case FBTYPE_SUNFAST_COLOR:
590 p = cgsixfb_init(fb); break;
591#endif
592#ifdef CONFIG_FB_BWTWO
593 case FBTYPE_SUN2BW:
594 p = bwtwofb_init(fb); break;
595#endif
596#ifdef CONFIG_FB_CGTHREE
597 case FBTYPE_SUN4COLOR:
598 case FBTYPE_SUN3COLOR:
599 type->fb_size = 0x100000;
600 p = cgthreefb_init(fb); break;
601#endif
602 }
603 fix->smem_start = (unsigned long)fb->info.screen_base; // FIXME
604
605 if (!p) {
606 kfree(fb);
607 return -ENODEV;
608 }
609
610 if (p == SBUSFBINIT_SIZECHANGE)
611 goto sizechange;
612
613 disp->dispsw = &fb->dispsw;
614 if (fb->setcursor) {
615 fb->dispsw.cursor = sun3fb_cursor;
616 if (curblink) {
617 fb->cursor.blink_rate = DEFAULT_CURSOR_BLINK_RATE;
618 init_timer(&fb->cursor.timer);
619 fb->cursor.timer.expires = jiffies + fb->cursor.blink_rate;
620 fb->cursor.timer.data = (unsigned long)fb;
621 fb->cursor.timer.function = sun3fb_cursor_timer_handler;
622 add_timer(&fb->cursor.timer);
623 }
624 }
625 fb->cursor.mode = CURSOR_SHAPE;
626 fb->dispsw.set_font = sun3fb_set_font;
627 fb->setup = fb->dispsw.setup;
628 fb->dispsw.setup = sun3fb_disp_setup;
629 fb->dispsw.clear_margins = NULL;
630
631 disp->var = *var;
632 disp->visual = fix->visual;
633 disp->type = fix->type;
634 disp->type_aux = fix->type_aux;
635 disp->line_length = fix->line_length;
636
637 if (fb->blank)
638 disp->can_soft_blank = 1;
639
640 sun3fb_set_var(var, -1, &fb->info);
641
642 if (register_framebuffer(&fb->info) < 0) {
643 kfree(fb);
644 return -EINVAL;
645 }
646 printk("fb%d: %s\n", fb->info.node, p);
647
648 return 0;
649}
650
651
652int __init sun3fb_init(void)
653{
654 extern int con_is_present(void);
655 unsigned long addr;
656 char p4id;
657
658 if (!con_is_present()) return -ENODEV;
659#ifdef CONFIG_SUN3
660 switch(*(romvec->pv_fbtype))
661 {
662 case FBTYPE_SUN2BW:
663 addr = 0xfe20000;
664 return sun3fb_init_fb(FBTYPE_SUN2BW, addr);
665 case FBTYPE_SUN3COLOR:
666 case FBTYPE_SUN4COLOR:
667 if(idprom->id_machtype != (SM_SUN3|SM_3_60)) {
668 printk("sun3fb: cgthree/four only supported on 3/60\n");
669 return -ENODEV;
670 }
671
672 addr = CGFOUR_OBMEM_ADDR;
673 return sun3fb_init_fb(*(romvec->pv_fbtype), addr);
674 default:
675 printk("sun3fb: unsupported framebuffer\n");
676 return -ENODEV;
677 }
678#else
679 addr = SUN3X_VIDEO_BASE;
680 p4id = *(char *)SUN3X_VIDEO_P4ID;
681
682 p4id = (p4id == 0x45) ? p4id : (p4id & 0xf0);
683 switch (p4id) {
684 case 0x00:
685 return sun3fb_init_fb(FBTYPE_SUN2BW, addr);
686#if 0 /* not yet */
687 case 0x40:
688 return sun3fb_init_fb(FBTYPE_SUN4COLOR, addr);
689 break;
690 case 0x45:
691 return sun3fb_init_fb(FBTYPE_SUN8COLOR, addr);
692 break;
693#endif
694 case 0x60:
695 return sun3fb_init_fb(FBTYPE_SUNFAST_COLOR, addr);
696 }
697#endif
698
699 return -ENODEV;
700}
701
702MODULE_LICENSE("GPL");
diff --git a/drivers/video/svgalib.c b/drivers/video/svgalib.c
new file mode 100644
index 00000000000..68b30d9eac5
--- /dev/null
+++ b/drivers/video/svgalib.c
@@ -0,0 +1,632 @@
1/*
2 * Common utility functions for VGA-based graphics cards.
3 *
4 * Copyright (c) 2006-2007 Ondrej Zajicek <santiago@crfreenet.org>
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 * Some parts are based on David Boucher's viafb (http://davesdomain.org.uk/viafb/)
11 */
12
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/string.h>
16#include <linux/fb.h>
17#include <linux/svga.h>
18#include <linux/slab.h>
19#include <asm/types.h>
20#include <asm/io.h>
21
22
23/* Write a CRT register value spread across multiple registers */
24void svga_wcrt_multi(const struct vga_regset *regset, u32 value) {
25
26 u8 regval, bitval, bitnum;
27
28 while (regset->regnum != VGA_REGSET_END_VAL) {
29 regval = vga_rcrt(NULL, regset->regnum);
30 bitnum = regset->lowbit;
31 while (bitnum <= regset->highbit) {
32 bitval = 1 << bitnum;
33 regval = regval & ~bitval;
34 if (value & 1) regval = regval | bitval;
35 bitnum ++;
36 value = value >> 1;
37 }
38 vga_wcrt(NULL, regset->regnum, regval);
39 regset ++;
40 }
41}
42
43/* Write a sequencer register value spread across multiple registers */
44void svga_wseq_multi(const struct vga_regset *regset, u32 value) {
45
46 u8 regval, bitval, bitnum;
47
48 while (regset->regnum != VGA_REGSET_END_VAL) {
49 regval = vga_rseq(NULL, regset->regnum);
50 bitnum = regset->lowbit;
51 while (bitnum <= regset->highbit) {
52 bitval = 1 << bitnum;
53 regval = regval & ~bitval;
54 if (value & 1) regval = regval | bitval;
55 bitnum ++;
56 value = value >> 1;
57 }
58 vga_wseq(NULL, regset->regnum, regval);
59 regset ++;
60 }
61}
62
63static unsigned int svga_regset_size(const struct vga_regset *regset)
64{
65 u8 count = 0;
66
67 while (regset->regnum != VGA_REGSET_END_VAL) {
68 count += regset->highbit - regset->lowbit + 1;
69 regset ++;
70 }
71 return 1 << count;
72}
73
74
75/* ------------------------------------------------------------------------- */
76
77
78/* Set graphics controller registers to sane values */
79void svga_set_default_gfx_regs(void)
80{
81 /* All standard GFX registers (GR00 - GR08) */
82 vga_wgfx(NULL, VGA_GFX_SR_VALUE, 0x00);
83 vga_wgfx(NULL, VGA_GFX_SR_ENABLE, 0x00);
84 vga_wgfx(NULL, VGA_GFX_COMPARE_VALUE, 0x00);
85 vga_wgfx(NULL, VGA_GFX_DATA_ROTATE, 0x00);
86 vga_wgfx(NULL, VGA_GFX_PLANE_READ, 0x00);
87 vga_wgfx(NULL, VGA_GFX_MODE, 0x00);
88/* vga_wgfx(NULL, VGA_GFX_MODE, 0x20); */
89/* vga_wgfx(NULL, VGA_GFX_MODE, 0x40); */
90 vga_wgfx(NULL, VGA_GFX_MISC, 0x05);
91/* vga_wgfx(NULL, VGA_GFX_MISC, 0x01); */
92 vga_wgfx(NULL, VGA_GFX_COMPARE_MASK, 0x0F);
93 vga_wgfx(NULL, VGA_GFX_BIT_MASK, 0xFF);
94}
95
96/* Set attribute controller registers to sane values */
97void svga_set_default_atc_regs(void)
98{
99 u8 count;
100
101 vga_r(NULL, 0x3DA);
102 vga_w(NULL, VGA_ATT_W, 0x00);
103
104 /* All standard ATC registers (AR00 - AR14) */
105 for (count = 0; count <= 0xF; count ++)
106 svga_wattr(count, count);
107
108 svga_wattr(VGA_ATC_MODE, 0x01);
109/* svga_wattr(VGA_ATC_MODE, 0x41); */
110 svga_wattr(VGA_ATC_OVERSCAN, 0x00);
111 svga_wattr(VGA_ATC_PLANE_ENABLE, 0x0F);
112 svga_wattr(VGA_ATC_PEL, 0x00);
113 svga_wattr(VGA_ATC_COLOR_PAGE, 0x00);
114
115 vga_r(NULL, 0x3DA);
116 vga_w(NULL, VGA_ATT_W, 0x20);
117}
118
119/* Set sequencer registers to sane values */
120void svga_set_default_seq_regs(void)
121{
122 /* Standard sequencer registers (SR01 - SR04), SR00 is not set */
123 vga_wseq(NULL, VGA_SEQ_CLOCK_MODE, VGA_SR01_CHAR_CLK_8DOTS);
124 vga_wseq(NULL, VGA_SEQ_PLANE_WRITE, VGA_SR02_ALL_PLANES);
125 vga_wseq(NULL, VGA_SEQ_CHARACTER_MAP, 0x00);
126/* vga_wseq(NULL, VGA_SEQ_MEMORY_MODE, VGA_SR04_EXT_MEM | VGA_SR04_SEQ_MODE | VGA_SR04_CHN_4M); */
127 vga_wseq(NULL, VGA_SEQ_MEMORY_MODE, VGA_SR04_EXT_MEM | VGA_SR04_SEQ_MODE);
128}
129
130/* Set CRTC registers to sane values */
131void svga_set_default_crt_regs(void)
132{
133 /* Standard CRT registers CR03 CR08 CR09 CR14 CR17 */
134 svga_wcrt_mask(0x03, 0x80, 0x80); /* Enable vertical retrace EVRA */
135 vga_wcrt(NULL, VGA_CRTC_PRESET_ROW, 0);
136 svga_wcrt_mask(VGA_CRTC_MAX_SCAN, 0, 0x1F);
137 vga_wcrt(NULL, VGA_CRTC_UNDERLINE, 0);
138 vga_wcrt(NULL, VGA_CRTC_MODE, 0xE3);
139}
140
141void svga_set_textmode_vga_regs(void)
142{
143 /* svga_wseq_mask(0x1, 0x00, 0x01); */ /* Switch 8/9 pixel per char */
144 vga_wseq(NULL, VGA_SEQ_MEMORY_MODE, VGA_SR04_EXT_MEM);
145 vga_wseq(NULL, VGA_SEQ_PLANE_WRITE, 0x03);
146
147 vga_wcrt(NULL, VGA_CRTC_MAX_SCAN, 0x0f); /* 0x4f */
148 vga_wcrt(NULL, VGA_CRTC_UNDERLINE, 0x1f);
149 svga_wcrt_mask(VGA_CRTC_MODE, 0x23, 0x7f);
150
151 vga_wcrt(NULL, VGA_CRTC_CURSOR_START, 0x0d);
152 vga_wcrt(NULL, VGA_CRTC_CURSOR_END, 0x0e);
153 vga_wcrt(NULL, VGA_CRTC_CURSOR_HI, 0x00);
154 vga_wcrt(NULL, VGA_CRTC_CURSOR_LO, 0x00);
155
156 vga_wgfx(NULL, VGA_GFX_MODE, 0x10); /* Odd/even memory mode */
157 vga_wgfx(NULL, VGA_GFX_MISC, 0x0E); /* Misc graphics register - text mode enable */
158 vga_wgfx(NULL, VGA_GFX_COMPARE_MASK, 0x00);
159
160 vga_r(NULL, 0x3DA);
161 vga_w(NULL, VGA_ATT_W, 0x00);
162
163 svga_wattr(0x10, 0x0C); /* Attribute Mode Control Register - text mode, blinking and line graphics */
164 svga_wattr(0x13, 0x08); /* Horizontal Pixel Panning Register */
165
166 vga_r(NULL, 0x3DA);
167 vga_w(NULL, VGA_ATT_W, 0x20);
168}
169
170#if 0
171void svga_dump_var(struct fb_var_screeninfo *var, int node)
172{
173 pr_debug("fb%d: var.vmode : 0x%X\n", node, var->vmode);
174 pr_debug("fb%d: var.xres : %d\n", node, var->xres);
175 pr_debug("fb%d: var.yres : %d\n", node, var->yres);
176 pr_debug("fb%d: var.bits_per_pixel: %d\n", node, var->bits_per_pixel);
177 pr_debug("fb%d: var.xres_virtual : %d\n", node, var->xres_virtual);
178 pr_debug("fb%d: var.yres_virtual : %d\n", node, var->yres_virtual);
179 pr_debug("fb%d: var.left_margin : %d\n", node, var->left_margin);
180 pr_debug("fb%d: var.right_margin : %d\n", node, var->right_margin);
181 pr_debug("fb%d: var.upper_margin : %d\n", node, var->upper_margin);
182 pr_debug("fb%d: var.lower_margin : %d\n", node, var->lower_margin);
183 pr_debug("fb%d: var.hsync_len : %d\n", node, var->hsync_len);
184 pr_debug("fb%d: var.vsync_len : %d\n", node, var->vsync_len);
185 pr_debug("fb%d: var.sync : 0x%X\n", node, var->sync);
186 pr_debug("fb%d: var.pixclock : %d\n\n", node, var->pixclock);
187}
188#endif /* 0 */
189
190
191/* ------------------------------------------------------------------------- */
192
193
194void svga_settile(struct fb_info *info, struct fb_tilemap *map)
195{
196 const u8 *font = map->data;
197 u8* fb = (u8 *) info->screen_base;
198 int i, c;
199
200 if ((map->width != 8) || (map->height != 16) ||
201 (map->depth != 1) || (map->length != 256)) {
202 printk(KERN_ERR "fb%d: unsupported font parameters: width %d, height %d, depth %d, length %d\n",
203 info->node, map->width, map->height, map->depth, map->length);
204 return;
205 }
206
207 fb += 2;
208 for (c = 0; c < map->length; c++) {
209 for (i = 0; i < map->height; i++) {
210 fb[i * 4] = font[i];
211 }
212 fb += 128;
213 font += map->height;
214 }
215}
216
217/* Copy area in text (tileblit) mode */
218void svga_tilecopy(struct fb_info *info, struct fb_tilearea *area)
219{
220 int dx, dy;
221 /* 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 rowstride = colstride * (info->var.xres_virtual / 8);
224 u16 *fb = (u16 *) info->screen_base;
225 u16 *src, *dst;
226
227 if ((area->sy > area->dy) ||
228 ((area->sy == area->dy) && (area->sx > area->dx))) {
229 src = fb + area->sx * colstride + area->sy * rowstride;
230 dst = fb + area->dx * colstride + area->dy * rowstride;
231 } else {
232 src = fb + (area->sx + area->width - 1) * colstride
233 + (area->sy + area->height - 1) * rowstride;
234 dst = fb + (area->dx + area->width - 1) * colstride
235 + (area->dy + area->height - 1) * rowstride;
236
237 colstride = -colstride;
238 rowstride = -rowstride;
239 }
240
241 for (dy = 0; dy < area->height; dy++) {
242 u16* src2 = src;
243 u16* dst2 = dst;
244 for (dx = 0; dx < area->width; dx++) {
245 *dst2 = *src2;
246 src2 += colstride;
247 dst2 += colstride;
248 }
249 src += rowstride;
250 dst += rowstride;
251 }
252}
253
254/* Fill area in text (tileblit) mode */
255void svga_tilefill(struct fb_info *info, struct fb_tilerect *rect)
256{
257 int dx, dy;
258 int colstride = 2 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK);
259 int rowstride = colstride * (info->var.xres_virtual / 8);
260 int attr = (0x0F & rect->bg) << 4 | (0x0F & rect->fg);
261 u8 *fb = (u8 *) info->screen_base;
262 fb += rect->sx * colstride + rect->sy * rowstride;
263
264 for (dy = 0; dy < rect->height; dy++) {
265 u8* fb2 = fb;
266 for (dx = 0; dx < rect->width; dx++) {
267 fb2[0] = rect->index;
268 fb2[1] = attr;
269 fb2 += colstride;
270 }
271 fb += rowstride;
272 }
273}
274
275/* Write text in text (tileblit) mode */
276void svga_tileblit(struct fb_info *info, struct fb_tileblit *blit)
277{
278 int dx, dy, i;
279 int colstride = 2 << (info->fix.type_aux & FB_AUX_TEXT_SVGA_MASK);
280 int rowstride = colstride * (info->var.xres_virtual / 8);
281 int attr = (0x0F & blit->bg) << 4 | (0x0F & blit->fg);
282 u8* fb = (u8 *) info->screen_base;
283 fb += blit->sx * colstride + blit->sy * rowstride;
284
285 i=0;
286 for (dy=0; dy < blit->height; dy ++) {
287 u8* fb2 = fb;
288 for (dx = 0; dx < blit->width; dx ++) {
289 fb2[0] = blit->indices[i];
290 fb2[1] = attr;
291 fb2 += colstride;
292 i ++;
293 if (i == blit->length) return;
294 }
295 fb += rowstride;
296 }
297
298}
299
300/* Set cursor in text (tileblit) mode */
301void svga_tilecursor(struct fb_info *info, struct fb_tilecursor *cursor)
302{
303 u8 cs = 0x0d;
304 u8 ce = 0x0e;
305 u16 pos = cursor->sx + (info->var.xoffset / 8)
306 + (cursor->sy + (info->var.yoffset / 16))
307 * (info->var.xres_virtual / 8);
308
309 if (! cursor -> mode)
310 return;
311
312 svga_wcrt_mask(0x0A, 0x20, 0x20); /* disable cursor */
313
314 if (cursor -> shape == FB_TILE_CURSOR_NONE)
315 return;
316
317 switch (cursor -> shape) {
318 case FB_TILE_CURSOR_UNDERLINE:
319 cs = 0x0d;
320 break;
321 case FB_TILE_CURSOR_LOWER_THIRD:
322 cs = 0x09;
323 break;
324 case FB_TILE_CURSOR_LOWER_HALF:
325 cs = 0x07;
326 break;
327 case FB_TILE_CURSOR_TWO_THIRDS:
328 cs = 0x05;
329 break;
330 case FB_TILE_CURSOR_BLOCK:
331 cs = 0x01;
332 break;
333 }
334
335 /* set cursor position */
336 vga_wcrt(NULL, 0x0E, pos >> 8);
337 vga_wcrt(NULL, 0x0F, pos & 0xFF);
338
339 vga_wcrt(NULL, 0x0B, ce); /* set cursor end */
340 vga_wcrt(NULL, 0x0A, cs); /* set cursor start and enable it */
341}
342
343
344/* ------------------------------------------------------------------------- */
345
346
347/*
348 * Compute PLL settings (M, N, R)
349 * F_VCO = (F_BASE * M) / N
350 * F_OUT = F_VCO / (2^R)
351 */
352
353static inline u32 abs_diff(u32 a, u32 b)
354{
355 return (a > b) ? (a - b) : (b - a);
356}
357
358int svga_compute_pll(const struct svga_pll *pll, u32 f_wanted, u16 *m, u16 *n, u16 *r, int node)
359{
360 u16 am, an, ar;
361 u32 f_vco, f_current, delta_current, delta_best;
362
363 pr_debug("fb%d: ideal frequency: %d kHz\n", node, (unsigned int) f_wanted);
364
365 ar = pll->r_max;
366 f_vco = f_wanted << ar;
367
368 /* overflow check */
369 if ((f_vco >> ar) != f_wanted)
370 return -EINVAL;
371
372 /* It is usually better to have greater VCO clock
373 because of better frequency stability.
374 So first try r_max, then r smaller. */
375 while ((ar > pll->r_min) && (f_vco > pll->f_vco_max)) {
376 ar--;
377 f_vco = f_vco >> 1;
378 }
379
380 /* VCO bounds check */
381 if ((f_vco < pll->f_vco_min) || (f_vco > pll->f_vco_max))
382 return -EINVAL;
383
384 delta_best = 0xFFFFFFFF;
385 *m = 0;
386 *n = 0;
387 *r = ar;
388
389 am = pll->m_min;
390 an = pll->n_min;
391
392 while ((am <= pll->m_max) && (an <= pll->n_max)) {
393 f_current = (pll->f_base * am) / an;
394 delta_current = abs_diff (f_current, f_vco);
395
396 if (delta_current < delta_best) {
397 delta_best = delta_current;
398 *m = am;
399 *n = an;
400 }
401
402 if (f_current <= f_vco) {
403 am ++;
404 } else {
405 an ++;
406 }
407 }
408
409 f_current = (pll->f_base * *m) / *n;
410 pr_debug("fb%d: found frequency: %d kHz (VCO %d kHz)\n", node, (int) (f_current >> ar), (int) f_current);
411 pr_debug("fb%d: m = %d n = %d r = %d\n", node, (unsigned int) *m, (unsigned int) *n, (unsigned int) *r);
412 return 0;
413}
414
415
416/* ------------------------------------------------------------------------- */
417
418
419/* Check CRT timing values */
420int svga_check_timings(const struct svga_timing_regs *tm, struct fb_var_screeninfo *var, int node)
421{
422 u32 value;
423
424 var->xres = (var->xres+7)&~7;
425 var->left_margin = (var->left_margin+7)&~7;
426 var->right_margin = (var->right_margin+7)&~7;
427 var->hsync_len = (var->hsync_len+7)&~7;
428
429 /* Check horizontal total */
430 value = var->xres + var->left_margin + var->right_margin + var->hsync_len;
431 if (((value / 8) - 5) >= svga_regset_size (tm->h_total_regs))
432 return -EINVAL;
433
434 /* Check horizontal display and blank start */
435 value = var->xres;
436 if (((value / 8) - 1) >= svga_regset_size (tm->h_display_regs))
437 return -EINVAL;
438 if (((value / 8) - 1) >= svga_regset_size (tm->h_blank_start_regs))
439 return -EINVAL;
440
441 /* Check horizontal sync start */
442 value = var->xres + var->right_margin;
443 if (((value / 8) - 1) >= svga_regset_size (tm->h_sync_start_regs))
444 return -EINVAL;
445
446 /* Check horizontal blank end (or length) */
447 value = var->left_margin + var->right_margin + var->hsync_len;
448 if ((value == 0) || ((value / 8) >= svga_regset_size (tm->h_blank_end_regs)))
449 return -EINVAL;
450
451 /* Check horizontal sync end (or length) */
452 value = var->hsync_len;
453 if ((value == 0) || ((value / 8) >= svga_regset_size (tm->h_sync_end_regs)))
454 return -EINVAL;
455
456 /* Check vertical total */
457 value = var->yres + var->upper_margin + var->lower_margin + var->vsync_len;
458 if ((value - 1) >= svga_regset_size(tm->v_total_regs))
459 return -EINVAL;
460
461 /* Check vertical display and blank start */
462 value = var->yres;
463 if ((value - 1) >= svga_regset_size(tm->v_display_regs))
464 return -EINVAL;
465 if ((value - 1) >= svga_regset_size(tm->v_blank_start_regs))
466 return -EINVAL;
467
468 /* Check vertical sync start */
469 value = var->yres + var->lower_margin;
470 if ((value - 1) >= svga_regset_size(tm->v_sync_start_regs))
471 return -EINVAL;
472
473 /* Check vertical blank end (or length) */
474 value = var->upper_margin + var->lower_margin + var->vsync_len;
475 if ((value == 0) || (value >= svga_regset_size (tm->v_blank_end_regs)))
476 return -EINVAL;
477
478 /* Check vertical sync end (or length) */
479 value = var->vsync_len;
480 if ((value == 0) || (value >= svga_regset_size (tm->v_sync_end_regs)))
481 return -EINVAL;
482
483 return 0;
484}
485
486/* Set CRT timing registers */
487void svga_set_timings(const struct svga_timing_regs *tm, struct fb_var_screeninfo *var,
488 u32 hmul, u32 hdiv, u32 vmul, u32 vdiv, u32 hborder, int node)
489{
490 u8 regval;
491 u32 value;
492
493 value = var->xres + var->left_margin + var->right_margin + var->hsync_len;
494 value = (value * hmul) / hdiv;
495 pr_debug("fb%d: horizontal total : %d\n", node, value);
496 svga_wcrt_multi(tm->h_total_regs, (value / 8) - 5);
497
498 value = var->xres;
499 value = (value * hmul) / hdiv;
500 pr_debug("fb%d: horizontal display : %d\n", node, value);
501 svga_wcrt_multi(tm->h_display_regs, (value / 8) - 1);
502
503 value = var->xres;
504 value = (value * hmul) / hdiv;
505 pr_debug("fb%d: horizontal blank start: %d\n", node, value);
506 svga_wcrt_multi(tm->h_blank_start_regs, (value / 8) - 1 + hborder);
507
508 value = var->xres + var->left_margin + var->right_margin + var->hsync_len;
509 value = (value * hmul) / hdiv;
510 pr_debug("fb%d: horizontal blank end : %d\n", node, value);
511 svga_wcrt_multi(tm->h_blank_end_regs, (value / 8) - 1 - hborder);
512
513 value = var->xres + var->right_margin;
514 value = (value * hmul) / hdiv;
515 pr_debug("fb%d: horizontal sync start : %d\n", node, value);
516 svga_wcrt_multi(tm->h_sync_start_regs, (value / 8));
517
518 value = var->xres + var->right_margin + var->hsync_len;
519 value = (value * hmul) / hdiv;
520 pr_debug("fb%d: horizontal sync end : %d\n", node, value);
521 svga_wcrt_multi(tm->h_sync_end_regs, (value / 8));
522
523 value = var->yres + var->upper_margin + var->lower_margin + var->vsync_len;
524 value = (value * vmul) / vdiv;
525 pr_debug("fb%d: vertical total : %d\n", node, value);
526 svga_wcrt_multi(tm->v_total_regs, value - 2);
527
528 value = var->yres;
529 value = (value * vmul) / vdiv;
530 pr_debug("fb%d: vertical display : %d\n", node, value);
531 svga_wcrt_multi(tm->v_display_regs, value - 1);
532
533 value = var->yres;
534 value = (value * vmul) / vdiv;
535 pr_debug("fb%d: vertical blank start : %d\n", node, value);
536 svga_wcrt_multi(tm->v_blank_start_regs, value);
537
538 value = var->yres + var->upper_margin + var->lower_margin + var->vsync_len;
539 value = (value * vmul) / vdiv;
540 pr_debug("fb%d: vertical blank end : %d\n", node, value);
541 svga_wcrt_multi(tm->v_blank_end_regs, value - 2);
542
543 value = var->yres + var->lower_margin;
544 value = (value * vmul) / vdiv;
545 pr_debug("fb%d: vertical sync start : %d\n", node, value);
546 svga_wcrt_multi(tm->v_sync_start_regs, value);
547
548 value = var->yres + var->lower_margin + var->vsync_len;
549 value = (value * vmul) / vdiv;
550 pr_debug("fb%d: vertical sync end : %d\n", node, value);
551 svga_wcrt_multi(tm->v_sync_end_regs, value);
552
553 /* Set horizontal and vertical sync pulse polarity in misc register */
554
555 regval = vga_r(NULL, VGA_MIS_R);
556 if (var->sync & FB_SYNC_HOR_HIGH_ACT) {
557 pr_debug("fb%d: positive horizontal sync\n", node);
558 regval = regval & ~0x80;
559 } else {
560 pr_debug("fb%d: negative horizontal sync\n", node);
561 regval = regval | 0x80;
562 }
563 if (var->sync & FB_SYNC_VERT_HIGH_ACT) {
564 pr_debug("fb%d: positive vertical sync\n", node);
565 regval = regval & ~0x40;
566 } else {
567 pr_debug("fb%d: negative vertical sync\n\n", node);
568 regval = regval | 0x40;
569 }
570 vga_w(NULL, VGA_MIS_W, regval);
571}
572
573
574/* ------------------------------------------------------------------------- */
575
576
577int svga_match_format(const struct svga_fb_format *frm, struct fb_var_screeninfo *var, struct fb_fix_screeninfo *fix)
578{
579 int i = 0;
580
581 while (frm->bits_per_pixel != SVGA_FORMAT_END_VAL)
582 {
583 if ((var->bits_per_pixel == frm->bits_per_pixel) &&
584 (var->red.length <= frm->red.length) &&
585 (var->green.length <= frm->green.length) &&
586 (var->blue.length <= frm->blue.length) &&
587 (var->transp.length <= frm->transp.length) &&
588 (var->nonstd == frm->nonstd)) {
589 var->bits_per_pixel = frm->bits_per_pixel;
590 var->red = frm->red;
591 var->green = frm->green;
592 var->blue = frm->blue;
593 var->transp = frm->transp;
594 var->nonstd = frm->nonstd;
595 if (fix != NULL) {
596 fix->type = frm->type;
597 fix->type_aux = frm->type_aux;
598 fix->visual = frm->visual;
599 fix->xpanstep = frm->xpanstep;
600 }
601 return i;
602 }
603 i++;
604 frm++;
605 }
606 return -EINVAL;
607}
608
609
610EXPORT_SYMBOL(svga_wcrt_multi);
611EXPORT_SYMBOL(svga_wseq_multi);
612
613EXPORT_SYMBOL(svga_set_default_gfx_regs);
614EXPORT_SYMBOL(svga_set_default_atc_regs);
615EXPORT_SYMBOL(svga_set_default_seq_regs);
616EXPORT_SYMBOL(svga_set_default_crt_regs);
617EXPORT_SYMBOL(svga_set_textmode_vga_regs);
618
619EXPORT_SYMBOL(svga_settile);
620EXPORT_SYMBOL(svga_tilecopy);
621EXPORT_SYMBOL(svga_tilefill);
622EXPORT_SYMBOL(svga_tileblit);
623EXPORT_SYMBOL(svga_tilecursor);
624
625EXPORT_SYMBOL(svga_compute_pll);
626EXPORT_SYMBOL(svga_check_timings);
627EXPORT_SYMBOL(svga_set_timings);
628EXPORT_SYMBOL(svga_match_format);
629
630MODULE_AUTHOR("Ondrej Zajicek <santiago@crfreenet.org>");
631MODULE_DESCRIPTION("Common utility functions for VGA-based graphics cards");
632MODULE_LICENSE("GPL");
diff --git a/drivers/video/tgafb.c b/drivers/video/tgafb.c
index 4b88fab83b7..b604859b4dd 100644
--- a/drivers/video/tgafb.c
+++ b/drivers/video/tgafb.c
@@ -43,8 +43,9 @@ static void tgafb_imageblit(struct fb_info *, const struct fb_image *);
43static void tgafb_fillrect(struct fb_info *, const struct fb_fillrect *); 43static void tgafb_fillrect(struct fb_info *, const struct fb_fillrect *);
44static void tgafb_copyarea(struct fb_info *, const struct fb_copyarea *); 44static void tgafb_copyarea(struct fb_info *, const struct fb_copyarea *);
45 45
46static int tgafb_pci_register(struct pci_dev *, const struct pci_device_id *); 46static int __devinit tgafb_pci_register(struct pci_dev *,
47static void tgafb_pci_unregister(struct pci_dev *); 47 const struct pci_device_id *);
48static void __devexit tgafb_pci_unregister(struct pci_dev *);
48 49
49static const char *mode_option = "640x480@60"; 50static const char *mode_option = "640x480@60";
50 51
@@ -70,9 +71,10 @@ static struct fb_ops tgafb_ops = {
70 */ 71 */
71 72
72static struct pci_device_id const tgafb_pci_table[] = { 73static struct pci_device_id const tgafb_pci_table[] = {
73 { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TGA, PCI_ANY_ID, PCI_ANY_ID, 74 { PCI_DEVICE(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_TGA) },
74 0, 0, 0 } 75 { }
75}; 76};
77MODULE_DEVICE_TABLE(pci, tgafb_pci_table);
76 78
77static struct pci_driver tgafb_driver = { 79static struct pci_driver tgafb_driver = {
78 .name = "tgafb", 80 .name = "tgafb",
@@ -99,6 +101,12 @@ tgafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
99 if (var->bits_per_pixel != 32) 101 if (var->bits_per_pixel != 32)
100 return -EINVAL; 102 return -EINVAL;
101 } 103 }
104 var->red.length = var->green.length = var->blue.length = 8;
105 if (var->bits_per_pixel == 32) {
106 var->red.offset = 16;
107 var->green.offset = 8;
108 var->blue.offset = 0;
109 }
102 110
103 if (var->xres_virtual != var->xres || var->yres_virtual != var->yres) 111 if (var->xres_virtual != var->xres || var->yres_virtual != var->yres)
104 return -EINVAL; 112 return -EINVAL;
@@ -137,10 +145,10 @@ tgafb_set_par(struct fb_info *info)
137 0x00000303 145 0x00000303
138 }; 146 };
139 static unsigned int const mode_presets[4] = { 147 static unsigned int const mode_presets[4] = {
140 0x00002000, 148 0x00000000,
141 0x00002300, 149 0x00000300,
142 0xffffffff, 150 0xffffffff,
143 0x00002300 151 0x00000300
144 }; 152 };
145 static unsigned int const base_addr_presets[4] = { 153 static unsigned int const base_addr_presets[4] = {
146 0x00000000, 154 0x00000000,
@@ -152,7 +160,7 @@ tgafb_set_par(struct fb_info *info)
152 struct tga_par *par = (struct tga_par *) info->par; 160 struct tga_par *par = (struct tga_par *) info->par;
153 u32 htimings, vtimings, pll_freq; 161 u32 htimings, vtimings, pll_freq;
154 u8 tga_type; 162 u8 tga_type;
155 int i, j; 163 int i;
156 164
157 /* Encode video timings. */ 165 /* Encode video timings. */
158 htimings = (((info->var.xres/4) & TGA_HORIZ_ACT_LSB) 166 htimings = (((info->var.xres/4) & TGA_HORIZ_ACT_LSB)
@@ -190,7 +198,9 @@ tgafb_set_par(struct fb_info *info)
190 while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */ 198 while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */
191 continue; 199 continue;
192 mb(); 200 mb();
193 TGA_WRITE_REG(par, deep_presets[tga_type], TGA_DEEP_REG); 201 TGA_WRITE_REG(par, deep_presets[tga_type] |
202 (par->sync_on_green ? 0x0 : 0x00010000),
203 TGA_DEEP_REG);
194 while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */ 204 while (TGA_READ_REG(par, TGA_CMD_STAT_REG) & 1) /* wait for not busy */
195 continue; 205 continue;
196 mb(); 206 mb();
@@ -227,8 +237,10 @@ tgafb_set_par(struct fb_info *info)
227 BT485_WRITE(par, 0x00, BT485_ADDR_PAL_WRITE); 237 BT485_WRITE(par, 0x00, BT485_ADDR_PAL_WRITE);
228 TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG); 238 TGA_WRITE_REG(par, BT485_DATA_PAL, TGA_RAMDAC_SETUP_REG);
229 239
240#ifdef CONFIG_HW_CONSOLE
230 for (i = 0; i < 16; i++) { 241 for (i = 0; i < 16; i++) {
231 j = color_table[i]; 242 int j = color_table[i];
243
232 TGA_WRITE_REG(par, default_red[j]|(BT485_DATA_PAL<<8), 244 TGA_WRITE_REG(par, default_red[j]|(BT485_DATA_PAL<<8),
233 TGA_RAMDAC_REG); 245 TGA_RAMDAC_REG);
234 TGA_WRITE_REG(par, default_grn[j]|(BT485_DATA_PAL<<8), 246 TGA_WRITE_REG(par, default_grn[j]|(BT485_DATA_PAL<<8),
@@ -236,24 +248,27 @@ tgafb_set_par(struct fb_info *info)
236 TGA_WRITE_REG(par, default_blu[j]|(BT485_DATA_PAL<<8), 248 TGA_WRITE_REG(par, default_blu[j]|(BT485_DATA_PAL<<8),
237 TGA_RAMDAC_REG); 249 TGA_RAMDAC_REG);
238 } 250 }
239 for (i = 0; i < 240*3; i += 4) { 251 for (i = 0; i < 240 * 3; i += 4) {
240 TGA_WRITE_REG(par, 0x55|(BT485_DATA_PAL<<8), 252#else
253 for (i = 0; i < 256 * 3; i += 4) {
254#endif
255 TGA_WRITE_REG(par, 0x55 | (BT485_DATA_PAL << 8),
241 TGA_RAMDAC_REG); 256 TGA_RAMDAC_REG);
242 TGA_WRITE_REG(par, 0x00|(BT485_DATA_PAL<<8), 257 TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
243 TGA_RAMDAC_REG); 258 TGA_RAMDAC_REG);
244 TGA_WRITE_REG(par, 0x00|(BT485_DATA_PAL<<8), 259 TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
245 TGA_RAMDAC_REG); 260 TGA_RAMDAC_REG);
246 TGA_WRITE_REG(par, 0x00|(BT485_DATA_PAL<<8), 261 TGA_WRITE_REG(par, 0x00 | (BT485_DATA_PAL << 8),
247 TGA_RAMDAC_REG); 262 TGA_RAMDAC_REG);
248 } 263 }
249 264
250 } else { /* 24-plane or 24plusZ */ 265 } else { /* 24-plane or 24plusZ */
251 266
252 /* Init BT463 registers. */ 267 /* Init BT463 RAMDAC registers. */
253 BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_0, 0x40); 268 BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_0, 0x40);
254 BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_1, 0x08); 269 BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_1, 0x08);
255 BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_2, 270 BT463_WRITE(par, BT463_REG_ACC, BT463_CMD_REG_2,
256 (par->sync_on_green ? 0x80 : 0x40)); 271 (par->sync_on_green ? 0xc0 : 0x40));
257 272
258 BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_0, 0xff); 273 BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_0, 0xff);
259 BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_1, 0xff); 274 BT463_WRITE(par, BT463_REG_ACC, BT463_READ_MASK_1, 0xff);
@@ -267,26 +282,24 @@ tgafb_set_par(struct fb_info *info)
267 282
268 /* Fill the palette. */ 283 /* Fill the palette. */
269 BT463_LOAD_ADDR(par, 0x0000); 284 BT463_LOAD_ADDR(par, 0x0000);
270 TGA_WRITE_REG(par, BT463_PALETTE<<2, TGA_RAMDAC_REG); 285 TGA_WRITE_REG(par, BT463_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
271 286
287#ifdef CONFIG_HW_CONSOLE
272 for (i = 0; i < 16; i++) { 288 for (i = 0; i < 16; i++) {
273 j = color_table[i]; 289 int j = color_table[i];
274 TGA_WRITE_REG(par, default_red[j]|(BT463_PALETTE<<10), 290
275 TGA_RAMDAC_REG); 291 TGA_WRITE_REG(par, default_red[j], TGA_RAMDAC_REG);
276 TGA_WRITE_REG(par, default_grn[j]|(BT463_PALETTE<<10), 292 TGA_WRITE_REG(par, default_grn[j], TGA_RAMDAC_REG);
277 TGA_RAMDAC_REG); 293 TGA_WRITE_REG(par, default_blu[j], TGA_RAMDAC_REG);
278 TGA_WRITE_REG(par, default_blu[j]|(BT463_PALETTE<<10),
279 TGA_RAMDAC_REG);
280 } 294 }
281 for (i = 0; i < 512*3; i += 4) { 295 for (i = 0; i < 512 * 3; i += 4) {
282 TGA_WRITE_REG(par, 0x55|(BT463_PALETTE<<10), 296#else
283 TGA_RAMDAC_REG); 297 for (i = 0; i < 528 * 3; i += 4) {
284 TGA_WRITE_REG(par, 0x00|(BT463_PALETTE<<10), 298#endif
285 TGA_RAMDAC_REG); 299 TGA_WRITE_REG(par, 0x55, TGA_RAMDAC_REG);
286 TGA_WRITE_REG(par, 0x00|(BT463_PALETTE<<10), 300 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
287 TGA_RAMDAC_REG); 301 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
288 TGA_WRITE_REG(par, 0x00|(BT463_PALETTE<<10), 302 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
289 TGA_RAMDAC_REG);
290 } 303 }
291 304
292 /* Fill window type table after start of vertical retrace. */ 305 /* Fill window type table after start of vertical retrace. */
@@ -299,15 +312,12 @@ tgafb_set_par(struct fb_info *info)
299 TGA_WRITE_REG(par, 0x01, TGA_INTR_STAT_REG); 312 TGA_WRITE_REG(par, 0x01, TGA_INTR_STAT_REG);
300 313
301 BT463_LOAD_ADDR(par, BT463_WINDOW_TYPE_BASE); 314 BT463_LOAD_ADDR(par, BT463_WINDOW_TYPE_BASE);
302 TGA_WRITE_REG(par, BT463_REG_ACC<<2, TGA_RAMDAC_SETUP_REG); 315 TGA_WRITE_REG(par, BT463_REG_ACC << 2, TGA_RAMDAC_SETUP_REG);
303 316
304 for (i = 0; i < 16; i++) { 317 for (i = 0; i < 16; i++) {
305 TGA_WRITE_REG(par, 0x00|(BT463_REG_ACC<<10), 318 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
306 TGA_RAMDAC_REG); 319 TGA_WRITE_REG(par, 0x01, TGA_RAMDAC_REG);
307 TGA_WRITE_REG(par, 0x01|(BT463_REG_ACC<<10), 320 TGA_WRITE_REG(par, 0x00, TGA_RAMDAC_REG);
308 TGA_RAMDAC_REG);
309 TGA_WRITE_REG(par, 0x80|(BT463_REG_ACC<<10),
310 TGA_RAMDAC_REG);
311 } 321 }
312 322
313 } 323 }
@@ -435,9 +445,16 @@ tgafb_setcolreg(unsigned regno, unsigned red, unsigned green, unsigned blue,
435 TGA_WRITE_REG(par, red|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG); 445 TGA_WRITE_REG(par, red|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
436 TGA_WRITE_REG(par, green|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG); 446 TGA_WRITE_REG(par, green|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
437 TGA_WRITE_REG(par, blue|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG); 447 TGA_WRITE_REG(par, blue|(BT485_DATA_PAL<<8),TGA_RAMDAC_REG);
438 } else if (regno < 16) { 448 } else {
439 u32 value = (red << 16) | (green << 8) | blue; 449 if (regno < 16) {
440 ((u32 *)info->pseudo_palette)[regno] = value; 450 u32 value = (regno << 16) | (regno << 8) | regno;
451 ((u32 *)info->pseudo_palette)[regno] = value;
452 }
453 BT463_LOAD_ADDR(par, regno);
454 TGA_WRITE_REG(par, BT463_PALETTE << 2, TGA_RAMDAC_SETUP_REG);
455 TGA_WRITE_REG(par, red, TGA_RAMDAC_REG);
456 TGA_WRITE_REG(par, green, TGA_RAMDAC_REG);
457 TGA_WRITE_REG(par, blue, TGA_RAMDAC_REG);
441 } 458 }
442 459
443 return 0; 460 return 0;
@@ -885,7 +902,7 @@ copyarea_line_8bpp(struct fb_info *info, u32 dy, u32 sy,
885 902
886 n64 = (height * width) / 64; 903 n64 = (height * width) / 64;
887 904
888 if (dy < sy) { 905 if (sy < dy) {
889 spos = (sy + height) * width; 906 spos = (sy + height) * width;
890 dpos = (dy + height) * width; 907 dpos = (dy + height) * width;
891 908
@@ -933,7 +950,7 @@ copyarea_line_32bpp(struct fb_info *info, u32 dy, u32 sy,
933 950
934 n16 = (height * width) / 16; 951 n16 = (height * width) / 16;
935 952
936 if (dy < sy) { 953 if (sy < dy) {
937 src = tga_fb + (sy + height) * width * 4; 954 src = tga_fb + (sy + height) * width * 4;
938 dst = tga_fb + (dy + height) * width * 4; 955 dst = tga_fb + (dy + height) * width * 4;
939 956
@@ -1317,7 +1334,7 @@ tgafb_init_fix(struct fb_info *info)
1317 info->fix.type_aux = 0; 1334 info->fix.type_aux = 0;
1318 info->fix.visual = (tga_type == TGA_TYPE_8PLANE 1335 info->fix.visual = (tga_type == TGA_TYPE_8PLANE
1319 ? FB_VISUAL_PSEUDOCOLOR 1336 ? FB_VISUAL_PSEUDOCOLOR
1320 : FB_VISUAL_TRUECOLOR); 1337 : FB_VISUAL_DIRECTCOLOR);
1321 1338
1322 info->fix.line_length = par->xres * (par->bits_per_pixel >> 3); 1339 info->fix.line_length = par->xres * (par->bits_per_pixel >> 3);
1323 info->fix.smem_start = (size_t) par->tga_fb_base; 1340 info->fix.smem_start = (size_t) par->tga_fb_base;
@@ -1342,14 +1359,10 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1342 TGA_24PLUSZ_FB_OFFSET 1359 TGA_24PLUSZ_FB_OFFSET
1343 }; 1360 };
1344 1361
1345 struct all_info {
1346 struct fb_info info;
1347 struct tga_par par;
1348 u32 pseudo_palette[16];
1349 } *all;
1350
1351 void __iomem *mem_base; 1362 void __iomem *mem_base;
1352 unsigned long bar0_start, bar0_len; 1363 unsigned long bar0_start, bar0_len;
1364 struct fb_info *info;
1365 struct tga_par *par;
1353 u8 tga_type; 1366 u8 tga_type;
1354 int ret; 1367 int ret;
1355 1368
@@ -1360,13 +1373,14 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1360 } 1373 }
1361 1374
1362 /* Allocate the fb and par structures. */ 1375 /* Allocate the fb and par structures. */
1363 all = kmalloc(sizeof(*all), GFP_KERNEL); 1376 info = framebuffer_alloc(sizeof(struct tga_par), &pdev->dev);
1364 if (!all) { 1377 if (!info) {
1365 printk(KERN_ERR "tgafb: Cannot allocate memory\n"); 1378 printk(KERN_ERR "tgafb: Cannot allocate memory\n");
1366 return -ENOMEM; 1379 return -ENOMEM;
1367 } 1380 }
1368 memset(all, 0, sizeof(*all)); 1381
1369 pci_set_drvdata(pdev, all); 1382 par = info->par;
1383 pci_set_drvdata(pdev, info);
1370 1384
1371 /* Request the mem regions. */ 1385 /* Request the mem regions. */
1372 bar0_start = pci_resource_start(pdev, 0); 1386 bar0_start = pci_resource_start(pdev, 0);
@@ -1386,25 +1400,23 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1386 1400
1387 /* Grab info about the card. */ 1401 /* Grab info about the card. */
1388 tga_type = (readl(mem_base) >> 12) & 0x0f; 1402 tga_type = (readl(mem_base) >> 12) & 0x0f;
1389 all->par.pdev = pdev; 1403 par->pdev = pdev;
1390 all->par.tga_mem_base = mem_base; 1404 par->tga_mem_base = mem_base;
1391 all->par.tga_fb_base = mem_base + fb_offset_presets[tga_type]; 1405 par->tga_fb_base = mem_base + fb_offset_presets[tga_type];
1392 all->par.tga_regs_base = mem_base + TGA_REGS_OFFSET; 1406 par->tga_regs_base = mem_base + TGA_REGS_OFFSET;
1393 all->par.tga_type = tga_type; 1407 par->tga_type = tga_type;
1394 pci_read_config_byte(pdev, PCI_REVISION_ID, &all->par.tga_chip_rev); 1408 pci_read_config_byte(pdev, PCI_REVISION_ID, &par->tga_chip_rev);
1395 1409
1396 /* Setup framebuffer. */ 1410 /* Setup framebuffer. */
1397 all->info.flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA | 1411 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA |
1398 FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT; 1412 FBINFO_HWACCEL_IMAGEBLIT | FBINFO_HWACCEL_FILLRECT;
1399 all->info.fbops = &tgafb_ops; 1413 info->fbops = &tgafb_ops;
1400 all->info.screen_base = all->par.tga_fb_base; 1414 info->screen_base = par->tga_fb_base;
1401 all->info.par = &all->par; 1415 info->pseudo_palette = (void *)(par + 1);
1402 all->info.pseudo_palette = all->pseudo_palette;
1403 1416
1404 /* This should give a reasonable default video mode. */ 1417 /* This should give a reasonable default video mode. */
1405 1418
1406 ret = fb_find_mode(&all->info.var, &all->info, mode_option, 1419 ret = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL,
1407 NULL, 0, NULL,
1408 tga_type == TGA_TYPE_8PLANE ? 8 : 32); 1420 tga_type == TGA_TYPE_8PLANE ? 8 : 32);
1409 if (ret == 0 || ret == 4) { 1421 if (ret == 0 || ret == 4) {
1410 printk(KERN_ERR "tgafb: Could not find valid video mode\n"); 1422 printk(KERN_ERR "tgafb: Could not find valid video mode\n");
@@ -1412,29 +1424,28 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1412 goto err1; 1424 goto err1;
1413 } 1425 }
1414 1426
1415 if (fb_alloc_cmap(&all->info.cmap, 256, 0)) { 1427 if (fb_alloc_cmap(&info->cmap, 256, 0)) {
1416 printk(KERN_ERR "tgafb: Could not allocate color map\n"); 1428 printk(KERN_ERR "tgafb: Could not allocate color map\n");
1417 ret = -ENOMEM; 1429 ret = -ENOMEM;
1418 goto err1; 1430 goto err1;
1419 } 1431 }
1420 1432
1421 tgafb_set_par(&all->info); 1433 tgafb_set_par(info);
1422 tgafb_init_fix(&all->info); 1434 tgafb_init_fix(info);
1423 1435
1424 all->info.device = &pdev->dev; 1436 if (register_framebuffer(info) < 0) {
1425 if (register_framebuffer(&all->info) < 0) {
1426 printk(KERN_ERR "tgafb: Could not register framebuffer\n"); 1437 printk(KERN_ERR "tgafb: Could not register framebuffer\n");
1427 ret = -EINVAL; 1438 ret = -EINVAL;
1428 goto err1; 1439 goto err1;
1429 } 1440 }
1430 1441
1431 printk(KERN_INFO "tgafb: DC21030 [TGA] detected, rev=0x%02x\n", 1442 printk(KERN_INFO "tgafb: DC21030 [TGA] detected, rev=0x%02x\n",
1432 all->par.tga_chip_rev); 1443 par->tga_chip_rev);
1433 printk(KERN_INFO "tgafb: at PCI bus %d, device %d, function %d\n", 1444 printk(KERN_INFO "tgafb: at PCI bus %d, device %d, function %d\n",
1434 pdev->bus->number, PCI_SLOT(pdev->devfn), 1445 pdev->bus->number, PCI_SLOT(pdev->devfn),
1435 PCI_FUNC(pdev->devfn)); 1446 PCI_FUNC(pdev->devfn));
1436 printk(KERN_INFO "fb%d: %s frame buffer device at 0x%lx\n", 1447 printk(KERN_INFO "fb%d: %s frame buffer device at 0x%lx\n",
1437 all->info.node, all->info.fix.id, bar0_start); 1448 info->node, info->fix.id, bar0_start);
1438 1449
1439 return 0; 1450 return 0;
1440 1451
@@ -1443,11 +1454,11 @@ tgafb_pci_register(struct pci_dev *pdev, const struct pci_device_id *ent)
1443 iounmap(mem_base); 1454 iounmap(mem_base);
1444 release_mem_region(bar0_start, bar0_len); 1455 release_mem_region(bar0_start, bar0_len);
1445 err0: 1456 err0:
1446 kfree(all); 1457 framebuffer_release(info);
1447 return ret; 1458 return ret;
1448} 1459}
1449 1460
1450static void __exit 1461static void __devexit
1451tgafb_pci_unregister(struct pci_dev *pdev) 1462tgafb_pci_unregister(struct pci_dev *pdev)
1452{ 1463{
1453 struct fb_info *info = pci_get_drvdata(pdev); 1464 struct fb_info *info = pci_get_drvdata(pdev);
@@ -1456,22 +1467,21 @@ tgafb_pci_unregister(struct pci_dev *pdev)
1456 if (!info) 1467 if (!info)
1457 return; 1468 return;
1458 unregister_framebuffer(info); 1469 unregister_framebuffer(info);
1470 fb_dealloc_cmap(&info->cmap);
1459 iounmap(par->tga_mem_base); 1471 iounmap(par->tga_mem_base);
1460 release_mem_region(pci_resource_start(pdev, 0), 1472 release_mem_region(pci_resource_start(pdev, 0),
1461 pci_resource_len(pdev, 0)); 1473 pci_resource_len(pdev, 0));
1462 kfree(info); 1474 framebuffer_release(info);
1463} 1475}
1464 1476
1465#ifdef MODULE 1477static void __devexit
1466static void __exit
1467tgafb_exit(void) 1478tgafb_exit(void)
1468{ 1479{
1469 pci_unregister_driver(&tgafb_driver); 1480 pci_unregister_driver(&tgafb_driver);
1470} 1481}
1471#endif /* MODULE */
1472 1482
1473#ifndef MODULE 1483#ifndef MODULE
1474int __init 1484static int __devinit
1475tgafb_setup(char *arg) 1485tgafb_setup(char *arg)
1476{ 1486{
1477 char *this_opt; 1487 char *this_opt;
@@ -1493,7 +1503,7 @@ tgafb_setup(char *arg)
1493} 1503}
1494#endif /* !MODULE */ 1504#endif /* !MODULE */
1495 1505
1496int __init 1506static int __devinit
1497tgafb_init(void) 1507tgafb_init(void)
1498{ 1508{
1499#ifndef MODULE 1509#ifndef MODULE
@@ -1511,10 +1521,7 @@ tgafb_init(void)
1511 */ 1521 */
1512 1522
1513module_init(tgafb_init); 1523module_init(tgafb_init);
1514
1515#ifdef MODULE
1516module_exit(tgafb_exit); 1524module_exit(tgafb_exit);
1517#endif
1518 1525
1519MODULE_DESCRIPTION("framebuffer driver for TGA chipset"); 1526MODULE_DESCRIPTION("framebuffer driver for TGA chipset");
1520MODULE_LICENSE("GPL"); 1527MODULE_LICENSE("GPL");
diff --git a/drivers/video/vga16fb.c b/drivers/video/vga16fb.c
index 6aff63d5b29..ec4c7dc54a6 100644
--- a/drivers/video/vga16fb.c
+++ b/drivers/video/vga16fb.c
@@ -70,7 +70,8 @@ struct vga16fb_par {
70 unsigned char ClockingMode; /* Seq-Controller:01h */ 70 unsigned char ClockingMode; /* Seq-Controller:01h */
71 } vga_state; 71 } vga_state;
72 struct vgastate state; 72 struct vgastate state;
73 atomic_t ref_count; 73 struct mutex open_lock;
74 unsigned int ref_count;
74 int palette_blanked, vesa_blanked, mode, isVGA; 75 int palette_blanked, vesa_blanked, mode, isVGA;
75 u8 misc, pel_msk, vss, clkdiv; 76 u8 misc, pel_msk, vss, clkdiv;
76 u8 crtc[VGA_CRT_C]; 77 u8 crtc[VGA_CRT_C];
@@ -300,28 +301,33 @@ static void vga16fb_clock_chip(struct vga16fb_par *par,
300static int vga16fb_open(struct fb_info *info, int user) 301static int vga16fb_open(struct fb_info *info, int user)
301{ 302{
302 struct vga16fb_par *par = info->par; 303 struct vga16fb_par *par = info->par;
303 int cnt = atomic_read(&par->ref_count);
304 304
305 if (!cnt) { 305 mutex_lock(&par->open_lock);
306 if (!par->ref_count) {
306 memset(&par->state, 0, sizeof(struct vgastate)); 307 memset(&par->state, 0, sizeof(struct vgastate));
307 par->state.flags = VGA_SAVE_FONTS | VGA_SAVE_MODE | 308 par->state.flags = VGA_SAVE_FONTS | VGA_SAVE_MODE |
308 VGA_SAVE_CMAP; 309 VGA_SAVE_CMAP;
309 save_vga(&par->state); 310 save_vga(&par->state);
310 } 311 }
311 atomic_inc(&par->ref_count); 312 par->ref_count++;
313 mutex_unlock(&par->open_lock);
314
312 return 0; 315 return 0;
313} 316}
314 317
315static int vga16fb_release(struct fb_info *info, int user) 318static int vga16fb_release(struct fb_info *info, int user)
316{ 319{
317 struct vga16fb_par *par = info->par; 320 struct vga16fb_par *par = info->par;
318 int cnt = atomic_read(&par->ref_count);
319 321
320 if (!cnt) 322 mutex_lock(&par->open_lock);
323 if (!par->ref_count) {
324 mutex_unlock(&par->open_lock);
321 return -EINVAL; 325 return -EINVAL;
322 if (cnt == 1) 326 }
327 if (par->ref_count == 1)
323 restore_vga(&par->state); 328 restore_vga(&par->state);
324 atomic_dec(&par->ref_count); 329 par->ref_count--;
330 mutex_unlock(&par->open_lock);
325 331
326 return 0; 332 return 0;
327} 333}
@@ -1357,6 +1363,7 @@ static int __init vga16fb_probe(struct platform_device *dev)
1357 printk(KERN_INFO "vga16fb: mapped to 0x%p\n", info->screen_base); 1363 printk(KERN_INFO "vga16fb: mapped to 0x%p\n", info->screen_base);
1358 par = info->par; 1364 par = info->par;
1359 1365
1366 mutex_init(&par->open_lock);
1360 par->isVGA = ORIG_VIDEO_ISVGA; 1367 par->isVGA = ORIG_VIDEO_ISVGA;
1361 par->palette_blanked = 0; 1368 par->palette_blanked = 0;
1362 par->vesa_blanked = 0; 1369 par->vesa_blanked = 0;
diff --git a/drivers/video/virgefb.c b/drivers/video/virgefb.c
deleted file mode 100644
index b9fb6fb3600..00000000000
--- a/drivers/video/virgefb.c
+++ /dev/null
@@ -1,2526 +0,0 @@
1/*
2 * linux/drivers/video/virgefb.c -- CyberVision64/3D frame buffer device
3 *
4 * Copyright (C) 1997 André Heynatz
5 *
6 *
7 * This file is based on the CyberVision frame buffer device (cyberfb.c):
8 *
9 * Copyright (C) 1996 Martin Apel
10 * Geert Uytterhoeven
11 *
12 * Zorro II additions :
13 *
14 * Copyright (C) 1998-2000 Christian T. Steigies
15 *
16 * Initialization additions :
17 *
18 * Copyright (C) 1998-2000 Ken Tyler
19 *
20 * Parts of the Initialization code are based on Cyberfb.c by Allan Bair,
21 * and on the NetBSD CyberVision64 frame buffer driver by Michael Teske who gave
22 * permission for its use.
23 *
24 * Many thanks to Frank Mariak for his assistance with ZORRO 2 access and other
25 * mysteries.
26 *
27 *
28 *
29 * This file is subject to the terms and conditions of the GNU General Public
30 * License. See the file COPYING in the main directory of this archive
31 * for more details.
32 */
33
34#undef VIRGEFBDEBUG
35#undef VIRGEFBDUMP
36
37#include <linux/module.h>
38#include <linux/kernel.h>
39#include <linux/errno.h>
40#include <linux/string.h>
41#include <linux/mm.h>
42#include <linux/slab.h>
43#include <linux/delay.h>
44#include <linux/zorro.h>
45#include <linux/fb.h>
46#include <linux/init.h>
47#include <asm/uaccess.h>
48#include <asm/system.h>
49#include <asm/amigahw.h>
50#include <asm/io.h>
51#include <asm/irq.h>
52#include <video/fbcon.h>
53#include <video/fbcon-cfb8.h>
54#include <video/fbcon-cfb16.h>
55#include <video/fbcon-cfb32.h>
56
57#include "virgefb.h"
58
59#ifdef VIRGEFBDEBUG
60#define DPRINTK(fmt, args...) printk(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args)
61#else
62#define DPRINTK(fmt, args...)
63#endif
64
65#ifdef VIRGEFBDUMP
66static void cv64_dump(void);
67#define DUMP cv64_dump()
68#else
69#define DUMP
70#endif
71
72/*
73 * Macros for register access and zorro control
74 */
75
76static inline void mb_inline(void) { mb(); } /* for use in comma expressions */
77
78/* Set zorro 2 map */
79
80#define SelectIO \
81 mb(); \
82 if (on_zorro2) { \
83 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x04)) = 0x01); \
84 mb(); \
85 }
86
87#define SelectMMIO \
88 mb(); \
89 if (on_zorro2) { \
90 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x04)) = 0x02); \
91 mb(); \
92 }
93
94#define SelectCFG \
95 mb(); \
96 if (on_zorro2) { \
97 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x04)) = 0x03); \
98 mb(); \
99 }
100
101/* Set pass through, 0 = amiga, !=0 = cv64/3d */
102
103#define SetVSwitch(x) \
104 mb(); \
105 (*(volatile u16 *)((u8 *)(vcode_switch_base)) = \
106 (u16)(x ? 0 : 1)); \
107 mb();
108
109/* Zorro2 endian 'aperture' */
110
111#define ENDIAN_BYTE 2
112#define ENDIAN_WORD 1
113#define ENDIAN_LONG 0
114
115#define Select_Zorro2_FrameBuffer(x) \
116 do { \
117 if (on_zorro2) { \
118 mb(); \
119 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x08)) = \
120 (x * 0x40)); \
121 mb(); \
122 } \
123 } while (0)
124
125/* SetPortVal - only used for interrupt enable (not yet implemented) */
126
127#if 0
128#define SetPortVal(x) \
129 mb(); \
130 (*(volatile u16 *)((u8 *)(vcode_switch_base + 0x0c)) = \
131 (u16)x); \
132 mb();
133#endif
134
135/* IO access */
136
137#define byte_access_io(x) (((x) & 0x3ffc) | (((x) & 3)^3) | (((x) & 3) <<14))
138#define byte_access_mmio(x) (((x) & 0xfffc) | (((x) & 3)^3))
139
140/* Write 8 bit VGA register - used once for chip wakeup */
141
142#define wb_vgaio(reg, dat) \
143 SelectIO; \
144 (*(volatile u8 *)(vgaio_regs + ((u32)byte_access_io(reg) & 0xffff)) = \
145 (dat & 0xff)); \
146 SelectMMIO;
147
148/* Read 8 bit VGA register - only used in dump (SelectIO not needed on read ?) */
149
150#ifdef VIRGEFBDUMP
151#define rb_vgaio(reg) \
152 ({ \
153 u8 __zzyzx; \
154 SelectIO; \
155 __zzyzx = (*(volatile u8 *)((vgaio_regs)+(u32)byte_access_io(reg))); \
156 SelectMMIO; \
157 __zzyzx; \
158 })
159#endif
160
161/* MMIO access */
162
163/* Read 8 bit MMIO register */
164
165#define rb_mmio(reg) \
166 (mb_inline(), \
167 (*(volatile u8 *)(mmio_regs + 0x8000 + (u32)byte_access_mmio(reg))))
168
169/* Write 8 bit MMIO register */
170
171#define wb_mmio(reg,dat) \
172 mb(); \
173 (*(volatile u8 *)(mmio_regs + 0x8000 + (byte_access_mmio((reg) & 0xffff))) = \
174 (dat & 0xff)); \
175 mb();
176
177/* Read 32 bit MMIO register */
178
179#define rl_mmio(reg) \
180 (mb_inline(), \
181 (*((volatile u32 *)((u8 *)((mmio_regs + (on_zorro2 ? 0x20000 : 0)) + (reg))))))
182
183/* Write 32 bit MMIO register */
184
185#define wl_mmio(reg,dat) \
186 mb(); \
187 ((*(volatile u32 *)((u8 *)((mmio_regs + (on_zorro2 ? 0x20000 : 0)) + (reg)))) = \
188 (u32)(dat)); \
189 mb();
190
191/* Write to virge graphics register */
192
193#define wgfx(reg, dat) do { wb_mmio(GCT_ADDRESS, (reg)); wb_mmio(GCT_ADDRESS_W, (dat)); } while (0)
194
195/* Write to virge sequencer register */
196
197#define wseq(reg, dat) do { wb_mmio(SEQ_ADDRESS, (reg)); wb_mmio(SEQ_ADDRESS_W, (dat)); } while (0)
198
199/* Write to virge CRT controller register */
200
201#define wcrt(reg, dat) do { wb_mmio(CRT_ADDRESS, (reg)); wb_mmio(CRT_ADDRESS_W, (dat)); } while (0)
202
203/* Write to virge attribute register */
204
205#define watr(reg, dat) \
206 do { \
207 volatile unsigned char watr_tmp; \
208 watr_tmp = rb_mmio(ACT_ADDRESS_RESET); \
209 wb_mmio(ACT_ADDRESS_W, (reg)); \
210 wb_mmio(ACT_ADDRESS_W, (dat)); \
211 udelay(10); \
212 } while (0)
213
214/* end of macros */
215
216struct virgefb_par {
217 struct fb_var_screeninfo var;
218 __u32 type;
219 __u32 type_aux;
220 __u32 visual;
221 __u32 line_length;
222};
223
224static struct virgefb_par current_par;
225
226static int current_par_valid = 0;
227
228static struct display disp;
229static struct fb_info fb_info;
230
231static union {
232#ifdef FBCON_HAS_CFB16
233 u16 cfb16[16];
234#endif
235#ifdef FBCON_HAS_CFB32
236 u32 cfb32[16];
237#endif
238} fbcon_cmap;
239
240/*
241 * Switch for Chipset Independency
242 */
243
244static struct fb_hwswitch {
245
246 /* Initialisation */
247
248 int (*init)(void);
249
250 /* Display Control */
251
252 int (*encode_fix)(struct fb_fix_screeninfo *fix, struct virgefb_par *par);
253 int (*decode_var)(struct fb_var_screeninfo *var, struct virgefb_par *par);
254 int (*encode_var)(struct fb_var_screeninfo *var, struct virgefb_par *par);
255 int (*getcolreg)(u_int regno, u_int *red, u_int *green, u_int *blue,
256 u_int *transp, struct fb_info *info);
257 void (*blank)(int blank);
258} *fbhw;
259
260static unsigned char blit_maybe_busy = 0;
261
262/*
263 * Frame Buffer Name
264 */
265
266static char virgefb_name[16] = "CyberVision/3D";
267
268/*
269 * CyberVision64/3d Graphics Board
270 */
271
272static unsigned char virgefb_colour_table [256][3];
273static unsigned long v_ram;
274static unsigned long v_ram_size;
275static volatile unsigned char *mmio_regs;
276static volatile unsigned char *vgaio_regs;
277
278static unsigned long v_ram_phys;
279static unsigned long mmio_regs_phys;
280static unsigned long vcode_switch_base;
281static unsigned char on_zorro2;
282
283/*
284 * Offsets from start of video ram to appropriate ZIII aperture
285 */
286
287#ifdef FBCON_HAS_CFB8
288#define CYBMEM_OFFSET_8 0x800000 /* BGRX */
289#endif
290#ifdef FBCON_HAS_CFB16
291#define CYBMEM_OFFSET_16 0x400000 /* GBXR */
292#endif
293#ifdef FBCON_HAS_CFB32
294#define CYBMEM_OFFSET_32 0x000000 /* XRGB */
295#endif
296
297/*
298 * MEMCLOCK was 32MHz, 64MHz works, 72MHz doesn't (on my board)
299 */
300
301#define MEMCLOCK 50000000
302
303/*
304 * Predefined Video Modes
305 */
306
307static struct {
308 const char *name;
309 struct fb_var_screeninfo var;
310} virgefb_predefined[] __initdata = {
311#ifdef FBCON_HAS_CFB8
312 {
313 "640x480-8", { /* Cybervision 8 bpp */
314 640, 480, 640, 480, 0, 0, 8, 0,
315 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
316 0, 0, -1, -1, FB_ACCELF_TEXT, 31250, 160, 136, 82, 61, 88, 2,
317 0, FB_VMODE_NONINTERLACED
318 }
319 }, {
320 "768x576-8", { /* Cybervision 8 bpp */
321 768, 576, 768, 576, 0, 0, 8, 0,
322 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
323 0, 0, -1, -1, FB_ACCELF_TEXT, 29411, 144, 112, 32, 15, 64, 2,
324 0, FB_VMODE_NONINTERLACED
325 }
326 }, {
327 "800x600-8", { /* Cybervision 8 bpp */
328 800, 600, 800, 600, 0, 0, 8, 0,
329 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
330 0, 0, -1, -1, FB_ACCELF_TEXT, 28571, 168, 104, 22, 1, 48, 2,
331 0, FB_VMODE_NONINTERLACED
332 }
333 }, {
334 #if 0
335 "1024x768-8", { /* Cybervision 8 bpp */
336 1024, 768, 1024, 768, 0, 0, 8, 0,
337 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
338 0, 0, -1, -1, FB_ACCELF_TEXT, 20833, 272, 168, 39, 2, 72, 1,
339 0, FB_VMODE_NONINTERLACED
340 }
341 #else
342 "1024x768-8", {
343 1024, 768, 1024, 768, 0, 0, 8, 0,
344 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
345 #if 0
346 0, 0, -1, -1, FB_ACCELF_TEXT, 12500, 184, 40, 40, 2, 96, 1,
347 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
348 }
349 #else
350 0, 0, -1, -1, FB_ACCELF_TEXT, 12699, 176, 16, 28, 1, 96, 3,
351 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
352 }
353 #endif
354 #endif
355 }, {
356 "1152x886-8", { /* Cybervision 8 bpp */
357 1152, 886, 1152, 886, 0, 0, 8, 0,
358 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
359 0, 0, -1, -1, FB_ACCELF_TEXT, 19230, 280, 168, 45, 1, 64, 10,
360 0, FB_VMODE_NONINTERLACED
361 }
362 }, {
363 "1280x1024-8", { /* Cybervision 8 bpp */
364 1280, 1024, 1280, 1024, 0, 0, 8, 0,
365 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
366 #if 0
367 0, 0, -1, -1, FB_ACCELF_TEXT, 17857, 232, 232, 71, 15, 176, 12,
368 }
369 #else
370 0, 0, -1, -1, FB_ACCELF_TEXT, 7414, 232, 64, 38, 1, 112, 3,
371 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
372 }
373 #endif
374 }, {
375 "1600x1200-8", { /* Cybervision 8 bpp */
376 1600, 1200, 1600, 1200, 0, 0, 8, 0,
377 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
378 #if 0
379 0, 0, -1, -1, FB_ACCELF_TEXT, 13698, 336, 224, 77, 15, 176, 12,
380 0, FB_VMODE_NONINTERLACED
381 }
382 #else
383 0, 0, -1, -1, FB_ACCELF_TEXT, 6411, 256, 32, 52, 10, 160, 8,
384 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
385 }
386 #endif
387 },
388#endif
389
390#ifdef FBCON_HAS_CFB16
391 {
392 "640x480-16", { /* Cybervision 16 bpp */
393 640, 480, 640, 480, 0, 0, 16, 0,
394 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
395 0, 0, -1, -1, FB_ACCELF_TEXT, 31250, 152, 144, 82, 61, 88, 2,
396 0, FB_VMODE_NONINTERLACED
397 }
398 }, {
399 "768x576-16", { /* Cybervision 16 bpp */
400 768, 576, 768, 576, 0, 0, 16, 0,
401 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
402 0, 0, -1, -1, FB_ACCELF_TEXT, 29411, 144, 112, 32, 15, 64, 2,
403 0, FB_VMODE_NONINTERLACED
404 }
405 }, {
406 "800x600-16", { /* Cybervision 16 bpp */
407 800, 600, 800, 600, 0, 0, 16, 0,
408 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
409 0, 0, -1, -1, FB_ACCELF_TEXT, 28571, 168, 104, 22, 1, 48, 2,
410 0, FB_VMODE_NONINTERLACED
411 }
412 }, {
413#if 0
414 "1024x768-16", { /* Cybervision 16 bpp */
415 1024, 768, 1024, 768, 0, 0, 16, 0,
416 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
417 0, 0, -1, -1, FB_ACCELF_TEXT, 20833, 272, 168, 39, 2, 72, 1,
418 0, FB_VMODE_NONINTERLACED
419 }
420#else
421 "1024x768-16", {
422 1024, 768, 1024, 768, 0, 0, 16, 0,
423 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
424 0, 0, -1, -1, FB_ACCELF_TEXT, 12500, 184, 40, 40, 2, 96, 1,
425 FB_SYNC_COMP_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
426 }
427#endif
428 }, {
429 "1152x886-16", { /* Cybervision 16 bpp */
430 1152, 886, 1152, 886, 0, 0, 16, 0,
431 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
432 0, 0, -1, -1, FB_ACCELF_TEXT, 19230, 280, 168, 45, 1, 64, 10,
433 0, FB_VMODE_NONINTERLACED
434 }
435 }, {
436 "1280x1024-16", { /* Cybervision 16 bpp */
437 1280, 1024, 1280, 1024, 0, 0, 16, 0,
438 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
439 0, 0, -1, -1, FB_ACCELF_TEXT, 17857, 232, 232, 71, 15, 176, 12,
440 0, FB_VMODE_NONINTERLACED
441 }
442 }, {
443 "1600x1200-16", { /* Cybervision 16 bpp */
444 1600, 1200, 1600, 1200, 0, 0, 16, 0,
445 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
446 0, 0, -1, -1, FB_ACCELF_TEXT, 13698, 336, 224, 77, 15, 176, 12,
447 0, FB_VMODE_NONINTERLACED
448 }
449 },
450#endif
451
452#ifdef FBCON_HAS_CFB32
453 {
454 "640x480-32", { /* Cybervision 32 bpp */
455 640, 480, 640, 480, 0, 0, 32, 0,
456 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
457 0, 0, -1, -1, FB_ACCELF_TEXT, 31250, 160, 136, 82, 61, 88, 2,
458 0, FB_VMODE_NONINTERLACED
459 }
460 }, {
461 "768x576-32", { /* Cybervision 32 bpp */
462 768, 576, 768, 576, 0, 0, 32, 0,
463 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
464 0, 0, -1, -1, FB_ACCELF_TEXT, 29411, 144, 112, 32, 15, 64, 2,
465 0, FB_VMODE_NONINTERLACED
466 }
467 }, {
468 "800x600-32", { /* Cybervision 32 bpp */
469 800, 600, 800, 600, 0, 0, 32, 0,
470 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
471 0, 0, -1, -1, FB_ACCELF_TEXT, 28571, 168, 104, 22, 1, 48, 2,
472 0, FB_VMODE_NONINTERLACED
473 }
474 }, {
475 "1024x768-32", { /* Cybervision 32 bpp */
476 1024, 768, 1024, 768, 0, 0, 32, 0,
477 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
478 0, 0, -1, -1, FB_ACCELF_TEXT, 20833, 272, 168, 39, 2, 72, 1,
479 0, FB_VMODE_NONINTERLACED
480 }
481 }, {
482 "1152x886-32", { /* Cybervision 32 bpp */
483 1152, 886, 1152, 886, 0, 0, 32, 0,
484 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
485 0, 0, -1, -1, FB_ACCELF_TEXT, 19230, 280, 168, 45, 1, 64, 10,
486 0, FB_VMODE_NONINTERLACED
487 }
488 }, {
489 "1280x1024-32", { /* Cybervision 32 bpp */
490 1280, 1024, 1280, 1024, 0, 0, 32, 0,
491 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
492 0, 0, -1, -1, FB_ACCELF_TEXT, 17857, 232, 232, 71, 15, 176, 12,
493 0, FB_VMODE_NONINTERLACED
494 }
495 }, {
496 "1600x1200-32", { /* Cybervision 32 bpp */
497 1600, 1200, 1600, 1200, 0, 0, 32, 0,
498 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
499 0, 0, -1, -1, FB_ACCELF_TEXT, 13698, 336, 224, 77, 15, 176, 12,
500 0, FB_VMODE_NONINTERLACED
501 }
502 },
503#endif
504
505/* interlaced modes */
506
507#ifdef FBCON_HAS_CFB8
508 {
509 "1024x768-8i", { /* Cybervision 8 bpp */
510 1024, 768, 1024, 768, 0, 0, 8, 0,
511 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
512 0, 0, -1, -1, FB_ACCELF_TEXT, 20833, 272, 168, 39, 2, 72, 1,
513 0, FB_VMODE_INTERLACED
514 }
515 }, {
516 "1280x1024-8i", { /* Cybervision 8 bpp */
517 1280, 1024, 1280, 1024, 0, 0, 8, 0,
518 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
519 0, 0, -1, -1, FB_ACCELF_TEXT, 17857, 232, 232, 71, 15, 176, 12,
520 0, FB_VMODE_INTERLACED
521 }
522 }, {
523 "1600x1200-8i", { /* Cybervision 8 bpp */
524 1600, 1200, 1600, 1200, 0, 0, 8, 0,
525 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
526 0, 0, -1, -1, FB_ACCELF_TEXT, 13698, 336, 224, 77, 15, 176, 12,
527 0, FB_VMODE_INTERLACED
528 }
529 },
530#endif
531
532#ifdef FBCON_HAS_CFB16
533 {
534 "1024x768-16i", { /* Cybervision 16 bpp */
535 1024, 768, 1024, 768, 0, 0, 16, 0,
536 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
537 0, 0, -1, -1, FB_ACCELF_TEXT, 20833, 272, 168, 39, 2, 72, 1,
538 0, FB_VMODE_INTERLACED
539 }
540 }, {
541 "1280x1024-16i", { /* Cybervision 16 bpp */
542 1280, 1024, 1280, 1024, 0, 0, 16, 0,
543 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
544 0, 0, -1, -1, FB_ACCELF_TEXT, 17857, 232, 232, 71, 15, 176, 12,
545 0, FB_VMODE_INTERLACED
546 }
547 }, {
548 "1600x1200-16i", { /* Cybervision 16 bpp */
549 1600, 1200, 1600, 1200, 0, 0, 16, 0,
550 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
551 0, 0, -1, -1, FB_ACCELF_TEXT, 13698, 336, 224, 77, 15, 176, 12,
552 0, FB_VMODE_INTERLACED
553 }
554 },
555#endif
556
557#ifdef FBCON_HAS_CFB32
558 {
559 "1024x768-32i", { /* Cybervision 32 bpp */
560 1024, 768, 1024, 768, 0, 0, 32, 0,
561 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
562 0, 0, -1, -1, FB_ACCELF_TEXT, 22222, 216, 144, 39, 2, 72, 1,
563 0, FB_VMODE_INTERLACED
564 }
565 }, {
566 "1280x1024-32i", { /* Cybervision 32 bpp */
567 1280, 1024, 1280, 1024, 0, 0, 32, 0,
568 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {23, 0, 0},
569 0, 0, -1, -1, FB_ACCELF_TEXT, 17857, 232, 232, 71, 15, 176, 12,
570 0, FB_VMODE_INTERLACED
571 }
572 }, {
573 "1600x1200-32i", { /* Cybervision 32 bpp */
574 1600, 1200, 1600, 1200, 0, 0, 32, 0,
575 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
576 0, 0, -1, -1, FB_ACCELF_TEXT, 13698, 336, 224, 77, 15, 176, 12,
577 0, FB_VMODE_INTERLACED
578 }
579 },
580#endif
581
582/* doublescan modes */
583
584#ifdef FBCON_HAS_CFB8
585 {
586 "320x240-8d", { /* Cybervision 8 bpp */
587 320, 240, 320, 240, 0, 0, 8, 0,
588 {0, 8, 0}, {0, 8, 0}, {0, 8, 0}, {0, 0, 0},
589 0, 0, -1, -1, FB_ACCELF_TEXT, 59259, 80, 80, 45, 26, 32, 1,
590 0, FB_VMODE_DOUBLE
591 }
592 },
593#endif
594
595#ifdef FBCON_HAS_CFB16
596 {
597 "320x240-16d", { /* Cybervision 16 bpp */
598 320, 240, 320, 240, 0, 0, 16, 0,
599 {11, 5, 0}, {5, 6, 0}, {0, 5, 0}, {0, 0, 0},
600 0, 0, -1, -1, FB_ACCELF_TEXT, 59259, 80, 80, 45, 26, 32, 1,
601 0, FB_VMODE_DOUBLE
602 }
603 },
604#endif
605
606#ifdef FBCON_HAS_CFB32
607 {
608 "320x240-32d", { /* Cybervision 32 bpp */
609 320, 240, 320, 240, 0, 0, 32, 0,
610 {16, 8, 0}, {8, 8, 0}, {0, 8, 0}, {24, 0, 0},
611 0, 0, -1, -1, FB_ACCELF_TEXT, 59259, 80, 80, 45, 26, 32, 1,
612 0, FB_VMODE_DOUBLE
613 }
614 },
615#endif
616};
617
618#define NUM_TOTAL_MODES ARRAY_SIZE(virgefb_predefined)
619
620/*
621 * Default to 800x600 for video=virge8:, virge16: or virge32:
622 */
623
624#ifdef FBCON_HAS_CFB8
625#define VIRGE8_DEFMODE (2)
626#endif
627
628#ifdef FBCON_HAS_CFB16
629#define VIRGE16_DEFMODE (9)
630#endif
631
632#ifdef FBCON_HAS_CFB32
633#define VIRGE32_DEFMODE (16)
634#endif
635
636static struct fb_var_screeninfo virgefb_default;
637static int virgefb_inverse = 0;
638
639/*
640 * Interface used by the world
641 */
642
643int virgefb_setup(char*);
644static int virgefb_get_fix(struct fb_fix_screeninfo *fix, int con,
645 struct fb_info *info);
646static int virgefb_get_var(struct fb_var_screeninfo *var, int con,
647 struct fb_info *info);
648static int virgefb_set_var(struct fb_var_screeninfo *var, int con,
649 struct fb_info *info);
650static int virgefb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
651 struct fb_info *info);
652static int virgefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
653 u_int transp, struct fb_info *info);
654static int virgefb_blank(int blank, struct fb_info *info);
655
656/*
657 * Interface to the low level console driver
658 */
659
660int virgefb_init(void);
661static int virgefb_switch(int con, struct fb_info *info);
662static int virgefb_updatevar(int con, struct fb_info *info);
663
664/*
665 * Text console acceleration
666 */
667
668#ifdef FBCON_HAS_CFB8
669static struct display_switch fbcon_virge8;
670#endif
671
672#ifdef FBCON_HAS_CFB16
673static struct display_switch fbcon_virge16;
674#endif
675
676#ifdef FBCON_HAS_CFB32
677static struct display_switch fbcon_virge32;
678#endif
679
680/*
681 * Hardware Specific Routines
682 */
683
684static int virge_init(void);
685static int virgefb_encode_fix(struct fb_fix_screeninfo *fix,
686 struct virgefb_par *par);
687static int virgefb_decode_var(struct fb_var_screeninfo *var,
688 struct virgefb_par *par);
689static int virgefb_encode_var(struct fb_var_screeninfo *var,
690 struct virgefb_par *par);
691static int virgefb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
692 u_int *transp, struct fb_info *info);
693static void virgefb_gfx_on_off(int blank);
694static inline void virgefb_wait_for_idle(void);
695static void virgefb_BitBLT(u_short curx, u_short cury, u_short destx, u_short desty,
696 u_short width, u_short height, u_short stride, u_short depth);
697static void virgefb_RectFill(u_short x, u_short y, u_short width, u_short height,
698 u_short color, u_short stride, u_short depth);
699
700/*
701 * Internal routines
702 */
703
704static void virgefb_get_par(struct virgefb_par *par);
705static void virgefb_set_par(struct virgefb_par *par);
706static int virgefb_do_fb_set_var(struct fb_var_screeninfo *var, int isactive);
707static void virgefb_set_disp(int con, struct fb_info *info);
708static int virgefb_get_video_mode(const char *name);
709static void virgefb_set_video(struct fb_var_screeninfo *var);
710
711/*
712 * Additions for Initialization
713 */
714
715static void virgefb_load_video_mode(struct fb_var_screeninfo *video_mode);
716static int cv3d_has_4mb(void);
717static unsigned short virgefb_compute_clock(unsigned long freq);
718static inline unsigned char rattr(short);
719static inline unsigned char rseq(short);
720static inline unsigned char rcrt(short);
721static inline unsigned char rgfx(short);
722static inline void gfx_on_off(int toggle);
723static void virgefb_pci_init(void);
724
725/* -------------------- Hardware specific routines ------------------------- */
726
727/*
728 * Functions for register access
729 */
730
731/* Read attribute controller register */
732
733static inline unsigned char rattr(short idx)
734{
735 volatile unsigned char rattr_tmp;
736
737 rattr_tmp = rb_mmio(ACT_ADDRESS_RESET);
738 wb_mmio(ACT_ADDRESS_W, idx);
739 return (rb_mmio(ACT_ADDRESS_R));
740}
741
742/* Read sequencer register */
743
744static inline unsigned char rseq(short idx)
745{
746 wb_mmio(SEQ_ADDRESS, idx);
747 return (rb_mmio(SEQ_ADDRESS_R));
748}
749
750/* Read CRT controller register */
751
752static inline unsigned char rcrt(short idx)
753{
754 wb_mmio(CRT_ADDRESS, idx);
755 return (rb_mmio(CRT_ADDRESS_R));
756}
757
758/* Read graphics controller register */
759
760static inline unsigned char rgfx(short idx)
761{
762 wb_mmio(GCT_ADDRESS, idx);
763 return (rb_mmio(GCT_ADDRESS_R));
764}
765
766
767/*
768 * Initialization
769 */
770
771/* PCI init */
772
773void virgefb_pci_init(void) {
774
775 DPRINTK("ENTER\n");
776
777 SelectCFG;
778
779 if (on_zorro2) {
780 *((short *)(vgaio_regs + 0x00000010)) = 0;
781 *((long *)(vgaio_regs + 0x00000004)) = 0x02000003;
782 } else {
783 *((short *)(vgaio_regs + 0x000e0010)) = 0;
784 *((long *)(vgaio_regs + 0x000e0004)) = 0x02000003;
785 }
786
787 /* SelectIO is in wb_vgaio macro */
788 wb_vgaio(SREG_VIDEO_SUBS_ENABLE, 0x01);
789 /* SelectMMIO is in wb_vgaio macro */
790
791 DPRINTK("EXIT\n");
792
793 return;
794}
795
796/*
797 * Initalize all mode independent regs, find mem size and clear mem
798*/
799
800static int virge_init(void)
801{
802 int i;
803 unsigned char tmp;
804
805 DPRINTK("ENTER\n");
806
807 virgefb_pci_init();
808
809 wb_mmio(GREG_MISC_OUTPUT_W, 0x07); /* colour, ram enable, clk sel */
810
811 wseq(SEQ_ID_UNLOCK_EXT, 0x06); /* unlock extensions */
812 tmp = rb_mmio(GREG_MISC_OUTPUT_R);
813 wcrt(CRT_ID_REGISTER_LOCK_1, 0x48); /* unlock CR2D to CR3F */
814
815 wcrt(CRT_ID_BACKWAD_COMP_1, 0x00); /* irq disable */
816
817 wcrt(CRT_ID_REGISTER_LOCK_2, 0xa5); /* unlock CR40 to CRFF and more */
818 wcrt(CRT_ID_REGISTER_LOCK,0x00); /* unlock h and v timing */
819 wcrt(CRT_ID_SYSTEM_CONFIG, 0x01); /* unlock enhanced programming registers */
820
821 wb_mmio(GREG_FEATURE_CONTROL_W, 0x00);
822
823 wcrt(CRT_ID_EXT_MISC_CNTL, 0x00); /* b2 = 0 to allow VDAC mmio access */
824#if 0
825 /* write strap options ... ? */
826 wcrt(CRT_ID_CONFIG_1, 0x08);
827 wcrt(CRT_ID_CONFIG_2, 0xff); /* 0x0x2 bit needs to be set ?? */
828 wcrt(CRT_ID_CONFIG_3, 0x0f);
829 wcrt(CRT_ID_CONFIG_4, 0x1a);
830#endif
831 wcrt(CRT_ID_EXT_MISC_CNTL_1, 0x82); /* PCI DE and software reset S3D engine */
832 /* EXT_MISC_CNTL_1, CR66 bit 0 should be the same as bit 0 MR_ADVANCED_FUNCTION_CONTROL - check */
833 wl_mmio(MR_ADVANCED_FUNCTION_CONTROL, 0x00000011); /* enhanced mode, linear addressing */
834
835/* crtc registers */
836
837 wcrt(CRT_ID_PRESET_ROW_SCAN, 0x00);
838
839 /* Disable h/w cursor */
840
841 wcrt(CRT_ID_CURSOR_START, 0x00);
842 wcrt(CRT_ID_CURSOR_END, 0x00);
843 wcrt(CRT_ID_START_ADDR_HIGH, 0x00);
844 wcrt(CRT_ID_START_ADDR_LOW, 0x00);
845 wcrt(CRT_ID_CURSOR_LOC_HIGH, 0x00);
846 wcrt(CRT_ID_CURSOR_LOC_LOW, 0x00);
847 wcrt(CRT_ID_EXT_MODE, 0x00);
848 wcrt(CRT_ID_HWGC_MODE, 0x00);
849 wcrt(CRT_ID_HWGC_ORIGIN_X_HI, 0x00);
850 wcrt(CRT_ID_HWGC_ORIGIN_X_LO, 0x00);
851 wcrt(CRT_ID_HWGC_ORIGIN_Y_HI, 0x00);
852 wcrt(CRT_ID_HWGC_ORIGIN_Y_LO, 0x00);
853 i = rcrt(CRT_ID_HWGC_MODE);
854 wcrt(CRT_ID_HWGC_FG_STACK, 0x00);
855 wcrt(CRT_ID_HWGC_FG_STACK, 0x00);
856 wcrt(CRT_ID_HWGC_FG_STACK, 0x00);
857 wcrt(CRT_ID_HWGC_BG_STACK, 0x00);
858 wcrt(CRT_ID_HWGC_BG_STACK, 0x00);
859 wcrt(CRT_ID_HWGC_BG_STACK, 0x00);
860 wcrt(CRT_ID_HWGC_START_AD_HI, 0x00);
861 wcrt(CRT_ID_HWGC_START_AD_LO, 0x00);
862 wcrt(CRT_ID_HWGC_DSTART_X, 0x00);
863 wcrt(CRT_ID_HWGC_DSTART_Y, 0x00);
864
865 wcrt(CRT_ID_UNDERLINE_LOC, 0x00);
866
867 wcrt(CRT_ID_MODE_CONTROL, 0xe3);
868 wcrt(CRT_ID_BACKWAD_COMP_2, 0x22); /* blank bdr bit 5 blanking only on 8 bit */
869
870 wcrt(CRT_ID_EX_SYNC_1, 0x00);
871
872 /* memory */
873
874 wcrt(CRT_ID_EXT_SYS_CNTL_3, 0x00);
875 wcrt(CRT_ID_MEMORY_CONF, 0x08); /* config enhanced map */
876 wcrt(CRT_ID_EXT_MEM_CNTL_1, 0x08); /* MMIO Select (0x0c works as well)*/
877 wcrt(CRT_ID_EXT_MEM_CNTL_2, 0x02); /* why 02 big endian 00 works ? */
878 wcrt(CRT_ID_EXT_MEM_CNTL_4, 0x9f); /* config big endian - 0x00 ? */
879 wcrt(CRT_ID_LAW_POS_HI, 0x00);
880 wcrt(CRT_ID_LAW_POS_LO, 0x00);
881 wcrt(CRT_ID_EXT_MISC_CNTL_1, 0x81);
882 wcrt(CRT_ID_MISC_1, 0x90); /* must follow CRT_ID_EXT_MISC_CNTL_1 */
883 wcrt(CRT_ID_LAW_CNTL, 0x13); /* force 4 Meg for test */
884 if (cv3d_has_4mb()) {
885 v_ram_size = 0x00400000;
886 wcrt(CRT_ID_LAW_CNTL, 0x13); /* 4 MB */
887 } else {
888 v_ram_size = 0x00200000;
889 wcrt(CRT_ID_LAW_CNTL, 0x12); /* 2 MB */
890 }
891
892 if (on_zorro2)
893 v_ram_size -= 0x60000; /* we need some space for the registers */
894
895 wcrt(CRT_ID_EXT_SYS_CNTL_4, 0x00);
896 wcrt(CRT_ID_EXT_DAC_CNTL, 0x00); /* 0x10 for X11 cursor mode */
897
898/* sequencer registers */
899
900 wseq(SEQ_ID_CLOCKING_MODE, 0x01); /* 8 dot clock */
901 wseq(SEQ_ID_MAP_MASK, 0xff);
902 wseq(SEQ_ID_CHAR_MAP_SELECT, 0x00);
903 wseq(SEQ_ID_MEMORY_MODE, 0x02);
904 wseq(SEQ_ID_RAMDAC_CNTL, 0x00);
905 wseq(SEQ_ID_SIGNAL_SELECT, 0x00);
906 wseq(SEQ_ID_EXT_SEQ_REG9, 0x00); /* MMIO and PIO reg access enabled */
907 wseq(SEQ_ID_EXT_MISC_SEQ, 0x00);
908 wseq(SEQ_ID_CLKSYN_CNTL_1, 0x00);
909 wseq(SEQ_ID_EXT_SEQ, 0x00);
910
911/* graphic registers */
912
913 wgfx(GCT_ID_SET_RESET, 0x00);
914 wgfx(GCT_ID_ENABLE_SET_RESET, 0x00);
915 wgfx(GCT_ID_COLOR_COMPARE, 0x00);
916 wgfx(GCT_ID_DATA_ROTATE, 0x00);
917 wgfx(GCT_ID_READ_MAP_SELECT, 0x00);
918 wgfx(GCT_ID_GRAPHICS_MODE, 0x40);
919 wgfx(GCT_ID_MISC, 0x01);
920 wgfx(GCT_ID_COLOR_XCARE, 0x0f);
921 wgfx(GCT_ID_BITMASK, 0xff);
922
923/* attribute registers */
924
925 for(i = 0; i <= 15; i++)
926 watr(ACT_ID_PALETTE0 + i, i);
927 watr(ACT_ID_ATTR_MODE_CNTL, 0x41);
928 watr(ACT_ID_OVERSCAN_COLOR, 0xff);
929 watr(ACT_ID_COLOR_PLANE_ENA, 0x0f);
930 watr(ACT_ID_HOR_PEL_PANNING, 0x00);
931 watr(ACT_ID_COLOR_SELECT, 0x00);
932
933 wb_mmio(VDAC_MASK, 0xff);
934
935/* init local cmap as greyscale levels */
936
937 for (i = 0; i < 256; i++) {
938 virgefb_colour_table [i][0] = i;
939 virgefb_colour_table [i][1] = i;
940 virgefb_colour_table [i][2] = i;
941 }
942
943/* clear framebuffer memory */
944
945 memset((char*)v_ram, 0x00, v_ram_size);
946
947 DPRINTK("EXIT\n");
948 return 0;
949}
950
951
952/*
953 * This function should fill in the `fix' structure based on the
954 * values in the `par' structure.
955 */
956
957static int virgefb_encode_fix(struct fb_fix_screeninfo *fix,
958 struct virgefb_par *par)
959{
960 DPRINTK("ENTER set video phys addr\n");
961
962 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
963 strcpy(fix->id, virgefb_name);
964 if (on_zorro2)
965 fix->smem_start = v_ram_phys;
966 switch (par->var.bits_per_pixel) {
967#ifdef FBCON_HAS_CFB8
968 case 8:
969 if (on_zorro2)
970 Select_Zorro2_FrameBuffer(ENDIAN_BYTE);
971 else
972 fix->smem_start = (v_ram_phys + CYBMEM_OFFSET_8);
973 break;
974#endif
975#ifdef FBCON_HAS_CFB16
976 case 16:
977 if (on_zorro2)
978 Select_Zorro2_FrameBuffer(ENDIAN_WORD);
979 else
980 fix->smem_start = (v_ram_phys + CYBMEM_OFFSET_16);
981 break;
982#endif
983#ifdef FBCON_HAS_CFB32
984 case 32:
985 if (on_zorro2)
986 Select_Zorro2_FrameBuffer(ENDIAN_LONG);
987 else
988 fix->smem_start = (v_ram_phys + CYBMEM_OFFSET_32);
989 break;
990#endif
991 }
992
993 fix->smem_len = v_ram_size;
994 fix->mmio_start = mmio_regs_phys;
995 fix->mmio_len = 0x10000; /* TODO: verify this for the CV64/3D */
996
997 fix->type = FB_TYPE_PACKED_PIXELS;
998 fix->type_aux = 0;
999 if (par->var.bits_per_pixel == 8)
1000 fix->visual = FB_VISUAL_PSEUDOCOLOR;
1001 else
1002 fix->visual = FB_VISUAL_TRUECOLOR;
1003
1004 fix->xpanstep = 0;
1005 fix->ypanstep = 0;
1006 fix->ywrapstep = 0;
1007 fix->line_length = par->var.xres_virtual*par->var.bits_per_pixel/8;
1008 fix->accel = FB_ACCEL_S3_VIRGE;
1009 DPRINTK("EXIT v_ram_phys = 0x%8.8lx\n", (unsigned long)fix->smem_start);
1010 return 0;
1011}
1012
1013
1014/*
1015 * Fill the `par' structure based on the values in `var'.
1016 * TODO: Verify and adjust values, return -EINVAL if bad.
1017 */
1018
1019static int virgefb_decode_var(struct fb_var_screeninfo *var,
1020 struct virgefb_par *par)
1021{
1022 DPRINTK("ENTER\n");
1023 par->var.xres = var->xres;
1024 par->var.yres = var->yres;
1025 par->var.xres_virtual = var->xres_virtual;
1026 par->var.yres_virtual = var->yres_virtual;
1027 /* roundup and validate */
1028 par->var.xres = (par->var.xres+7) & ~7;
1029 par->var.xres_virtual = (par->var.xres_virtual+7) & ~7;
1030 if (par->var.xres_virtual < par->var.xres)
1031 par->var.xres_virtual = par->var.xres;
1032 if (par->var.yres_virtual < par->var.yres)
1033 par->var.yres_virtual = par->var.yres;
1034 par->var.xoffset = var->xoffset;
1035 par->var.yoffset = var->yoffset;
1036 par->var.bits_per_pixel = var->bits_per_pixel;
1037 if (par->var.bits_per_pixel <= 8)
1038 par->var.bits_per_pixel = 8;
1039 else if (par->var.bits_per_pixel <= 16)
1040 par->var.bits_per_pixel = 16;
1041 else
1042 par->var.bits_per_pixel = 32;
1043#ifndef FBCON_HAS_CFB32
1044 if (par->var.bits_per_pixel == 32)
1045 par->var.bits_per_pixel = 16;
1046#endif
1047#ifndef FBCON_HAS_CFB16
1048 if (par->var.bits_per_pixel == 16)
1049 par->var.bits_per_pixel = 8;
1050#endif
1051 par->var.grayscale = var->grayscale;
1052 par->var.red = var->red;
1053 par->var.green = var->green;
1054 par->var.blue = var->blue;
1055 par->var.transp = var->transp;
1056 par->var.nonstd = var->nonstd;
1057 par->var.activate = var->activate;
1058 par->var.height = var->height;
1059 par->var.width = var->width;
1060 if (var->accel_flags & FB_ACCELF_TEXT) {
1061 par->var.accel_flags = FB_ACCELF_TEXT;
1062 } else {
1063 par->var.accel_flags = 0;
1064 }
1065 par->var.pixclock = var->pixclock;
1066 par->var.left_margin = var->left_margin;
1067 par->var.right_margin = var->right_margin;
1068 par->var.upper_margin = var->upper_margin;
1069 par->var.lower_margin = var->lower_margin;
1070 par->var.hsync_len = var->hsync_len;
1071 par->var.vsync_len = var->vsync_len;
1072 par->var.sync = var->sync;
1073 par->var.vmode = var->vmode;
1074 DPRINTK("EXIT\n");
1075 return 0;
1076}
1077
1078/*
1079 * Fill the `var' structure based on the values in `par' and maybe
1080 * other values read out of the hardware.
1081 */
1082
1083static int virgefb_encode_var(struct fb_var_screeninfo *var,
1084 struct virgefb_par *par)
1085{
1086 DPRINTK("ENTER\n");
1087 memset(var, 0, sizeof(struct fb_var_screeninfo)); /* need this ? */
1088 var->xres = par->var.xres;
1089 var->yres = par->var.yres;
1090 var->xres_virtual = par->var.xres_virtual;
1091 var->yres_virtual = par->var.yres_virtual;
1092 var->xoffset = par->var.xoffset;
1093 var->yoffset = par->var.yoffset;
1094 var->bits_per_pixel = par->var.bits_per_pixel;
1095 var->grayscale = par->var.grayscale;
1096 var->red = par->var.red;
1097 var->green = par->var.green;
1098 var->blue = par->var.blue;
1099 var->transp = par->var.transp;
1100 var->nonstd = par->var.nonstd;
1101 var->activate = par->var.activate;
1102 var->height = par->var.height;
1103 var->width = par->var.width;
1104 var->accel_flags = par->var.accel_flags;
1105 var->pixclock = par->var.pixclock;
1106 var->left_margin = par->var.left_margin;
1107 var->right_margin = par->var.right_margin;
1108 var->upper_margin = par->var.upper_margin;
1109 var->lower_margin = par->var.lower_margin;
1110 var->hsync_len = par->var.hsync_len;
1111 var->vsync_len = par->var.vsync_len;
1112 var->sync = par->var.sync;
1113 var->vmode = par->var.vmode;
1114 DPRINTK("EXIT\n");
1115 return 0;
1116}
1117
1118/*
1119 * Set a single color register. The values supplied are already
1120 * rounded down to the hardware's capabilities (according to the
1121 * entries in the var structure). Return != 0 for invalid regno.
1122 */
1123
1124static int virgefb_setcolreg(u_int regno, u_int red, u_int green, u_int blue,
1125 u_int transp, struct fb_info *info)
1126{
1127 DPRINTK("ENTER\n");
1128 if (((current_par.var.bits_per_pixel==8) && (regno>255)) ||
1129 ((current_par.var.bits_per_pixel!=8) && (regno>15))) {
1130 DPRINTK("EXIT\n");
1131 return 1;
1132 }
1133 if (((current_par.var.bits_per_pixel==8) && (regno<256)) ||
1134 ((current_par.var.bits_per_pixel!=8) && (regno<16))) {
1135 virgefb_colour_table [regno][0] = red >> 10;
1136 virgefb_colour_table [regno][1] = green >> 10;
1137 virgefb_colour_table [regno][2] = blue >> 10;
1138 }
1139
1140 switch (current_par.var.bits_per_pixel) {
1141#ifdef FBCON_HAS_CFB8
1142 case 8:
1143 wb_mmio(VDAC_ADDRESS_W, (unsigned char)regno);
1144 wb_mmio(VDAC_DATA, ((unsigned char)(red >> 10)));
1145 wb_mmio(VDAC_DATA, ((unsigned char)(green >> 10)));
1146 wb_mmio(VDAC_DATA, ((unsigned char)(blue >> 10)));
1147 break;
1148#endif
1149#ifdef FBCON_HAS_CFB16
1150 case 16:
1151 fbcon_cmap.cfb16[regno] =
1152 ((red & 0xf800) |
1153 ((green & 0xfc00) >> 5) |
1154 ((blue & 0xf800) >> 11));
1155 break;
1156#endif
1157#ifdef FBCON_HAS_CFB32
1158 case 32:
1159 fbcon_cmap.cfb32[regno] =
1160 /* transp = 0's or 1's ? */
1161 (((red & 0xff00) << 8) |
1162 ((green & 0xff00) >> 0) |
1163 ((blue & 0xff00) >> 8));
1164 break;
1165#endif
1166 }
1167 DPRINTK("EXIT\n");
1168 return 0;
1169}
1170
1171
1172/*
1173 * Read a single color register and split it into
1174 * colors/transparent. Return != 0 for invalid regno.
1175 */
1176
1177static int virgefb_getcolreg(u_int regno, u_int *red, u_int *green, u_int *blue,
1178 u_int *transp, struct fb_info *info)
1179{
1180 int t;
1181
1182 DPRINTK("ENTER\n");
1183 if (regno > 255) {
1184 DPRINTK("EXIT\n");
1185 return 1;
1186 }
1187 if (((current_par.var.bits_per_pixel==8) && (regno<256)) ||
1188 ((current_par.var.bits_per_pixel!=8) && (regno<16))) {
1189
1190 t = virgefb_colour_table [regno][0];
1191 *red = (t<<10) | (t<<4) | (t>>2);
1192 t = virgefb_colour_table [regno][1];
1193 *green = (t<<10) | (t<<4) | (t>>2);
1194 t = virgefb_colour_table [regno][2];
1195 *blue = (t<<10) | (t<<4) | (t>>2);
1196 }
1197 *transp = 0;
1198 DPRINTK("EXIT\n");
1199 return 0;
1200}
1201
1202
1203/*
1204 * (Un)Blank the screen
1205 */
1206
1207static void virgefb_gfx_on_off(int blank)
1208{
1209 DPRINTK("ENTER\n");
1210 gfx_on_off(blank);
1211 DPRINTK("EXIT\n");
1212}
1213
1214/*
1215 * CV3D low-level support
1216 */
1217
1218
1219static inline void wait_3d_fifo_slots(int n) /* WaitQueue */
1220{
1221 do {
1222 mb();
1223 } while (((rl_mmio(MR_SUBSYSTEM_STATUS_R) >> 8) & 0x1f) < (n + 2));
1224}
1225
1226static inline void virgefb_wait_for_idle(void) /* WaitIdle */
1227{
1228 while(!(rl_mmio(MR_SUBSYSTEM_STATUS_R) & 0x2000)) ;
1229 blit_maybe_busy = 0;
1230}
1231
1232 /*
1233 * BitBLT - Through the Plane
1234 */
1235
1236static void virgefb_BitBLT(u_short curx, u_short cury, u_short destx, u_short desty,
1237 u_short width, u_short height, u_short stride, u_short depth)
1238{
1239 unsigned int blitcmd = S3V_BITBLT | S3V_DRAW | S3V_BLT_COPY;
1240
1241 switch (depth) {
1242#ifdef FBCON_HAS_CFB8
1243 case 8 :
1244 blitcmd |= S3V_DST_8BPP;
1245 break;
1246#endif
1247#ifdef FBCON_HAS_CFB16
1248 case 16 :
1249 blitcmd |= S3V_DST_16BPP;
1250 break;
1251#endif
1252#ifdef FBCON_HAS_CFB32
1253 case 32 :
1254 /* 32 bit uses 2 by 16 bit values, see fbcon_virge32_bmove */
1255 blitcmd |= S3V_DST_16BPP;
1256 break;
1257#endif
1258 }
1259
1260 /* Set drawing direction */
1261 /* -Y, X maj, -X (default) */
1262 if (curx > destx) {
1263 blitcmd |= (1 << 25); /* Drawing direction +X */
1264 } else {
1265 curx += (width - 1);
1266 destx += (width - 1);
1267 }
1268
1269 if (cury > desty) {
1270 blitcmd |= (1 << 26); /* Drawing direction +Y */
1271 } else {
1272 cury += (height - 1);
1273 desty += (height - 1);
1274 }
1275
1276 wait_3d_fifo_slots(8); /* wait on fifo slots for 8 writes */
1277
1278 if (blit_maybe_busy)
1279 virgefb_wait_for_idle();
1280 blit_maybe_busy = 1;
1281
1282 wl_mmio(BLT_PATTERN_COLOR, 1); /* pattern fb color */
1283 wl_mmio(BLT_MONO_PATTERN_0, ~0);
1284 wl_mmio(BLT_MONO_PATTERN_1, ~0);
1285 wl_mmio(BLT_SIZE_X_Y, ((width << 16) | height));
1286 wl_mmio(BLT_SRC_X_Y, ((curx << 16) | cury));
1287 wl_mmio(BLT_DEST_X_Y, ((destx << 16) | desty));
1288 wl_mmio(BLT_SRC_DEST_STRIDE, (((stride << 16) | stride) /* & 0x0ff80ff8 */)); /* why is this needed now ? */
1289 wl_mmio(BLT_COMMAND_SET, blitcmd);
1290}
1291
1292/*
1293 * Rectangle Fill Solid
1294 */
1295
1296static void virgefb_RectFill(u_short x, u_short y, u_short width, u_short height,
1297 u_short color, u_short stride, u_short depth)
1298{
1299 unsigned int blitcmd = S3V_RECTFILL | S3V_DRAW |
1300 S3V_BLT_CLEAR | S3V_MONO_PAT | (1 << 26) | (1 << 25);
1301
1302 switch (depth) {
1303#ifdef FBCON_HAS_CFB8
1304 case 8 :
1305 blitcmd |= S3V_DST_8BPP;
1306 break;
1307#endif
1308#ifdef FBCON_HAS_CFB16
1309 case 16 :
1310 blitcmd |= S3V_DST_16BPP;
1311 break;
1312#endif
1313#ifdef FBCON_HAS_CFB32
1314 case 32 :
1315 /* 32 bit uses 2 times 16 bit values, see fbcon_virge32_clear */
1316 blitcmd |= S3V_DST_16BPP;
1317 break;
1318#endif
1319 }
1320
1321 wait_3d_fifo_slots(5); /* wait on fifo slots for 5 writes */
1322
1323 if (blit_maybe_busy)
1324 virgefb_wait_for_idle();
1325 blit_maybe_busy = 1;
1326
1327 wl_mmio(BLT_PATTERN_COLOR, (color & 0xff));
1328 wl_mmio(BLT_SIZE_X_Y, ((width << 16) | height));
1329 wl_mmio(BLT_DEST_X_Y, ((x << 16) | y));
1330 wl_mmio(BLT_SRC_DEST_STRIDE, (((stride << 16) | stride) /* & 0x0ff80ff8 */));
1331 wl_mmio(BLT_COMMAND_SET, blitcmd);
1332}
1333
1334/*
1335 * Move cursor to x, y
1336 */
1337
1338#if 0
1339static void virgefb_move_cursor(u_short x, u_short y)
1340{
1341 DPRINTK("Yuck .... MoveCursor on a 3D\n");
1342 return 0;
1343}
1344#endif
1345
1346/* -------------------- Interfaces to hardware functions -------------------- */
1347
1348static struct fb_hwswitch virgefb_hw_switch = {
1349 .init = virge_init,
1350 .encode_fix = virgefb_encode_fix,
1351 .decode_var = virgefb_decode_var,
1352 .encode_var = virgefb_encode_var,
1353 .getcolreg = virgefb_getcolreg,
1354 .blank = virgefb_gfx_on_off
1355};
1356
1357
1358/* -------------------- Generic routines ------------------------------------ */
1359
1360
1361/*
1362 * Fill the hardware's `par' structure.
1363 */
1364
1365static void virgefb_get_par(struct virgefb_par *par)
1366{
1367 DPRINTK("ENTER\n");
1368 if (current_par_valid) {
1369 *par = current_par;
1370 } else {
1371 fbhw->decode_var(&virgefb_default, par);
1372 }
1373 DPRINTK("EXIT\n");
1374}
1375
1376
1377static void virgefb_set_par(struct virgefb_par *par)
1378{
1379 DPRINTK("ENTER\n");
1380 current_par = *par;
1381 current_par_valid = 1;
1382 DPRINTK("EXIT\n");
1383}
1384
1385
1386static void virgefb_set_video(struct fb_var_screeninfo *var)
1387{
1388/* Set clipping rectangle to current screen size */
1389
1390 unsigned int clip;
1391
1392 DPRINTK("ENTER\n");
1393 wait_3d_fifo_slots(4);
1394 clip = ((0 << 16) | (var->xres - 1));
1395 wl_mmio(BLT_CLIP_LEFT_RIGHT, clip);
1396 clip = ((0 << 16) | (var->yres - 1));
1397 wl_mmio(BLT_CLIP_TOP_BOTTOM, clip);
1398 wl_mmio(BLT_SRC_BASE, 0); /* seems we need to clear these two */
1399 wl_mmio(BLT_DEST_BASE, 0);
1400
1401/* Load the video mode defined by the 'var' data */
1402
1403 virgefb_load_video_mode(var);
1404 DPRINTK("EXIT\n");
1405}
1406
1407/*
1408Merge these two functions, Geert's suggestion.
1409static int virgefb_set_var(struct fb_var_screeninfo *var, int con, struct fb_info *info);
1410static int virgefb_do_fb_set_var(struct fb_var_screeninfo *var, int isactive);
1411*/
1412
1413static int virgefb_do_fb_set_var(struct fb_var_screeninfo *var, int isactive)
1414{
1415 int err, activate;
1416 struct virgefb_par par;
1417
1418 DPRINTK("ENTER\n");
1419 if ((err = fbhw->decode_var(var, &par))) {
1420 DPRINTK("EXIT\n");
1421 return (err);
1422 }
1423
1424 activate = var->activate;
1425 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW && isactive)
1426 virgefb_set_par(&par);
1427 fbhw->encode_var(var, &par);
1428 var->activate = activate;
1429 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW && isactive)
1430 virgefb_set_video(var);
1431 DPRINTK("EXIT\n");
1432 return 0;
1433}
1434
1435
1436/*
1437 * Get the Fixed Part of the Display
1438 */
1439
1440static int virgefb_get_fix(struct fb_fix_screeninfo *fix, int con,
1441 struct fb_info *info)
1442{
1443 struct virgefb_par par;
1444 int error = 0;
1445
1446 DPRINTK("ENTER\n");
1447 if (con == -1)
1448 virgefb_get_par(&par);
1449 else
1450 error = fbhw->decode_var(&fb_display[con].var, &par);
1451
1452 if (!error)
1453 error = fbhw->encode_fix(fix, &par);
1454 DPRINTK("EXIT\n");
1455 return(error);
1456}
1457
1458
1459/*
1460 * Get the User Defined Part of the Display
1461 */
1462
1463static int virgefb_get_var(struct fb_var_screeninfo *var, int con,
1464 struct fb_info *info)
1465{
1466 struct virgefb_par par;
1467 int error = 0;
1468
1469 DPRINTK("ENTER\n");
1470 if (con == -1) {
1471 virgefb_get_par(&par);
1472 error = fbhw->encode_var(var, &par);
1473 disp.var = *var; /* ++Andre: don't know if this is the right place */
1474 } else {
1475 *var = fb_display[con].var;
1476 }
1477 DPRINTK("EXIT\n");
1478 return(error);
1479}
1480
1481static void virgefb_set_disp(int con, struct fb_info *info)
1482{
1483 struct fb_fix_screeninfo fix;
1484 struct display *display;
1485
1486 DPRINTK("ENTER\n");
1487 if (con >= 0)
1488 display = &fb_display[con];
1489 else
1490 display = &disp; /* used during initialization */
1491
1492 virgefb_get_fix(&fix, con, info);
1493 if (con == -1)
1494 con = 0;
1495 if(on_zorro2) {
1496 info->screen_base = (char*)v_ram;
1497 } else {
1498 switch (display->var.bits_per_pixel) {
1499#ifdef FBCON_HAS_CFB8
1500 case 8:
1501 info->screen_base = (char*)(v_ram + CYBMEM_OFFSET_8);
1502 break;
1503#endif
1504#ifdef FBCON_HAS_CFB16
1505 case 16:
1506 info->screen_base = (char*)(v_ram + CYBMEM_OFFSET_16);
1507 break;
1508#endif
1509#ifdef FBCON_HAS_CFB32
1510 case 32:
1511 info->screen_base = (char*)(v_ram + CYBMEM_OFFSET_32);
1512 break;
1513#endif
1514 }
1515 }
1516 display->visual = fix.visual;
1517 display->type = fix.type;
1518 display->type_aux = fix.type_aux;
1519 display->ypanstep = fix.ypanstep;
1520 display->ywrapstep = fix.ywrapstep;
1521 display->can_soft_blank = 1;
1522 display->inverse = virgefb_inverse;
1523 display->line_length = display->var.xres_virtual*
1524 display->var.bits_per_pixel/8;
1525
1526 switch (display->var.bits_per_pixel) {
1527#ifdef FBCON_HAS_CFB8
1528 case 8:
1529 if (display->var.accel_flags & FB_ACCELF_TEXT) {
1530 display->dispsw = &fbcon_virge8;
1531#warning FIXME: We should reinit the graphics engine here
1532 } else
1533 display->dispsw = &fbcon_cfb8;
1534 break;
1535#endif
1536#ifdef FBCON_HAS_CFB16
1537 case 16:
1538 if (display->var.accel_flags & FB_ACCELF_TEXT) {
1539 display->dispsw = &fbcon_virge16;
1540 } else
1541 display->dispsw = &fbcon_cfb16;
1542 display->dispsw_data = &fbcon_cmap.cfb16;
1543 break;
1544#endif
1545#ifdef FBCON_HAS_CFB32
1546 case 32:
1547 if (display->var.accel_flags & FB_ACCELF_TEXT) {
1548 display->dispsw = &fbcon_virge32;
1549 } else
1550 display->dispsw = &fbcon_cfb32;
1551 display->dispsw_data = &fbcon_cmap.cfb32;
1552 break;
1553#endif
1554 default:
1555 display->dispsw = &fbcon_dummy;
1556 break;
1557 }
1558 DPRINTK("EXIT v_ram virt = 0x%8.8lx\n",(unsigned long)display->screen_base);
1559}
1560
1561
1562/*
1563 * Set the User Defined Part of the Display
1564 */
1565
1566static int virgefb_set_var(struct fb_var_screeninfo *var, int con,
1567 struct fb_info *info)
1568{
1569 int err, oldxres, oldyres, oldvxres, oldvyres, oldbpp, oldaccel;
1570
1571 DPRINTK("ENTER\n");
1572
1573 if ((err = virgefb_do_fb_set_var(var, con == info->currcon))) {
1574 DPRINTK("EXIT\n");
1575 return(err);
1576 }
1577 if ((var->activate & FB_ACTIVATE_MASK) == FB_ACTIVATE_NOW) {
1578 oldxres = fb_display[con].var.xres;
1579 oldyres = fb_display[con].var.yres;
1580 oldvxres = fb_display[con].var.xres_virtual;
1581 oldvyres = fb_display[con].var.yres_virtual;
1582 oldbpp = fb_display[con].var.bits_per_pixel;
1583 oldaccel = fb_display[con].var.accel_flags;
1584 fb_display[con].var = *var;
1585 if (oldxres != var->xres || oldyres != var->yres ||
1586 oldvxres != var->xres_virtual ||
1587 oldvyres != var->yres_virtual ||
1588 oldbpp != var->bits_per_pixel ||
1589 oldaccel != var->accel_flags) {
1590 virgefb_set_disp(con, info);
1591 if (fb_info.changevar)
1592 (*fb_info.changevar)(con);
1593 fb_alloc_cmap(&fb_display[con].cmap, 0, 0);
1594 do_install_cmap(con, info);
1595 }
1596 }
1597 var->activate = 0;
1598 DPRINTK("EXIT\n");
1599 return 0;
1600}
1601
1602
1603/*
1604 * Get the Colormap
1605 */
1606
1607static int virgefb_get_cmap(struct fb_cmap *cmap, int kspc, int con,
1608 struct fb_info *info)
1609{
1610 DPRINTK("ENTER\n");
1611 if (con == info->currcon) { /* current console? */
1612 DPRINTK("EXIT - console is current console, fb_get_cmap\n");
1613 return(fb_get_cmap(cmap, kspc, fbhw->getcolreg, info));
1614 } else if (fb_display[con].cmap.len) { /* non default colormap? */
1615 DPRINTK("Use console cmap\n");
1616 fb_copy_cmap(&fb_display[con].cmap, cmap, kspc ? 0 : 2);
1617 } else {
1618 DPRINTK("Use default cmap\n");
1619 fb_copy_cmap(fb_default_cmap(fb_display[con].var.bits_per_pixel==8 ? 256 : 16),
1620 cmap, kspc ? 0 : 2);
1621 }
1622 DPRINTK("EXIT\n");
1623 return 0;
1624}
1625
1626static struct fb_ops virgefb_ops = {
1627 .owner = THIS_MODULE,
1628 .fb_get_fix = virgefb_get_fix,
1629 .fb_get_var = virgefb_get_var,
1630 .fb_set_var = virgefb_set_var,
1631 .fb_get_cmap = virgefb_get_cmap,
1632 .fb_set_cmap = gen_set_cmap,
1633 .fb_setcolreg = virgefb_setcolreg,
1634 .fb_blank = virgefb_blank,
1635};
1636
1637int __init virgefb_setup(char *options)
1638{
1639 char *this_opt;
1640 fb_info.fontname[0] = '\0';
1641
1642 DPRINTK("ENTER\n");
1643 if (!options || !*options) {
1644 DPRINTK("EXIT\n");
1645 return 0;
1646 }
1647
1648 while ((this_opt = strsep(&options, ",")) != NULL) {
1649 if (!*this_opt)
1650 continue;
1651 if (!strcmp(this_opt, "inverse")) {
1652 virgefb_inverse = 1;
1653 fb_invert_cmaps();
1654 } else if (!strncmp(this_opt, "font:", 5))
1655 strcpy(fb_info.fontname, this_opt+5);
1656#ifdef FBCON_HAS_CFB8
1657 else if (!strcmp (this_opt, "virge8")){
1658 virgefb_default = virgefb_predefined[VIRGE8_DEFMODE].var;
1659 }
1660#endif
1661#ifdef FBCON_HAS_CFB16
1662 else if (!strcmp (this_opt, "virge16")){
1663 virgefb_default = virgefb_predefined[VIRGE16_DEFMODE].var;
1664 }
1665#endif
1666#ifdef FBCON_HAS_CFB32
1667 else if (!strcmp (this_opt, "virge32")){
1668 virgefb_default = virgefb_predefined[VIRGE32_DEFMODE].var;
1669 }
1670#endif
1671 else
1672 virgefb_get_video_mode(this_opt);
1673 }
1674
1675 printk(KERN_INFO "mode : xres=%d, yres=%d, bpp=%d\n", virgefb_default.xres,
1676 virgefb_default.yres, virgefb_default.bits_per_pixel);
1677 DPRINTK("EXIT\n");
1678 return 0;
1679}
1680
1681
1682/*
1683 * Get a Video Mode
1684 */
1685
1686static int __init virgefb_get_video_mode(const char *name)
1687{
1688 int i;
1689
1690 DPRINTK("ENTER\n");
1691 for (i = 0; i < NUM_TOTAL_MODES; i++) {
1692 if (!strcmp(name, virgefb_predefined[i].name)) {
1693 virgefb_default = virgefb_predefined[i].var;
1694 DPRINTK("EXIT\n");
1695 return(i);
1696 }
1697 }
1698 /* ++Andre: set virgefb default mode */
1699
1700/* prefer 16 bit depth, 8 if no 16, if no 8 or 16 use 32 */
1701
1702#ifdef FBCON_HAS_CFB32
1703 virgefb_default = virgefb_predefined[VIRGE32_DEFMODE].var;
1704#endif
1705#ifdef FBCON_HAS_CFB8
1706 virgefb_default = virgefb_predefined[VIRGE8_DEFMODE].var;
1707#endif
1708#ifdef FBCON_HAS_CFB16
1709 virgefb_default = virgefb_predefined[VIRGE16_DEFMODE].var;
1710#endif
1711 DPRINTK("EXIT\n");
1712 return 0;
1713}
1714
1715/*
1716 * Initialization
1717 */
1718
1719int __init virgefb_init(void)
1720{
1721 struct virgefb_par par;
1722 unsigned long board_addr, board_size;
1723 struct zorro_dev *z = NULL;
1724
1725 DPRINTK("ENTER\n");
1726
1727 z = zorro_find_device(ZORRO_PROD_PHASE5_CYBERVISION64_3D, NULL);
1728 if (!z)
1729 return -ENODEV;
1730
1731 board_addr = z->resource.start;
1732 if (board_addr < 0x01000000) {
1733
1734 /* board running in Z2 space. This includes the video memory
1735 as well as the S3 register set */
1736
1737 on_zorro2 = 1;
1738 board_size = 0x00400000;
1739
1740 if (!request_mem_region(board_addr, board_size, "S3 ViRGE"))
1741 return -ENOMEM;
1742
1743 v_ram_phys = board_addr;
1744 v_ram = ZTWO_VADDR(v_ram_phys);
1745 mmio_regs_phys = (unsigned long)(board_addr + 0x003c0000);
1746 vgaio_regs = (unsigned char *) ZTWO_VADDR(board_addr + 0x003c0000);
1747 mmio_regs = (unsigned char *)ZTWO_VADDR(mmio_regs_phys);
1748 vcode_switch_base = (unsigned long) ZTWO_VADDR(board_addr + 0x003a0000);
1749 printk(KERN_INFO "CV3D detected running in Z2 mode.\n");
1750
1751 } else {
1752
1753 /* board running in Z3 space. Separate video memory (3 apertures)
1754 and S3 register set */
1755
1756 on_zorro2 = 0;
1757 board_size = 0x01000000;
1758
1759 if (!request_mem_region(board_addr, board_size, "S3 ViRGE"))
1760 return -ENOMEM;
1761
1762 v_ram_phys = board_addr + 0x04000000;
1763 v_ram = (unsigned long)ioremap(v_ram_phys, 0x01000000);
1764 mmio_regs_phys = board_addr + 0x05000000;
1765 vgaio_regs = (unsigned char *)ioremap(board_addr +0x0c000000, 0x00100000); /* includes PCI regs */
1766 mmio_regs = ioremap(mmio_regs_phys, 0x00010000);
1767 vcode_switch_base = (unsigned long)ioremap(board_addr + 0x08000000, 0x1000);
1768 printk(KERN_INFO "CV3D detected running in Z3 mode\n");
1769 }
1770
1771#if defined (VIRGEFBDEBUG)
1772 DPRINTK("board_addr : 0x%8.8lx\n",board_addr);
1773 DPRINTK("board_size : 0x%8.8lx\n",board_size);
1774 DPRINTK("mmio_regs_phy : 0x%8.8lx\n",mmio_regs_phys);
1775 DPRINTK("v_ram_phys : 0x%8.8lx\n",v_ram_phys);
1776 DPRINTK("vgaio_regs : 0x%8.8lx\n",(unsigned long)vgaio_regs);
1777 DPRINTK("mmio_regs : 0x%8.8lx\n",(unsigned long)mmio_regs);
1778 DPRINTK("v_ram : 0x%8.8lx\n",v_ram);
1779 DPRINTK("vcode sw base : 0x%8.8lx\n",vcode_switch_base);
1780#endif
1781 fbhw = &virgefb_hw_switch;
1782 strcpy(fb_info.modename, virgefb_name);
1783 fb_info.changevar = NULL;
1784 fb_info.fbops = &virgefb_ops;
1785 fb_info.disp = &disp;
1786 fb_info.currcon = -1;
1787 fb_info.switch_con = &virgefb_switch;
1788 fb_info.updatevar = &virgefb_updatevar;
1789 fb_info.flags = FBINFO_FLAG_DEFAULT;
1790 fbhw->init();
1791 fbhw->decode_var(&virgefb_default, &par);
1792 fbhw->encode_var(&virgefb_default, &par);
1793 virgefb_do_fb_set_var(&virgefb_default, 1);
1794 virgefb_get_var(&fb_display[0].var, -1, &fb_info);
1795 virgefb_set_disp(-1, &fb_info);
1796 do_install_cmap(0, &fb_info);
1797
1798 if (register_framebuffer(&fb_info) < 0) {
1799 #warning release resources
1800 printk(KERN_ERR "virgefb.c: register_framebuffer failed\n");
1801 DPRINTK("EXIT\n");
1802 goto out_unmap;
1803 }
1804
1805 printk(KERN_INFO "fb%d: %s frame buffer device, using %ldK of video memory\n",
1806 fb_info.node, fb_info.modename, v_ram_size>>10);
1807
1808 /* TODO: This driver cannot be unloaded yet */
1809
1810 DPRINTK("EXIT\n");
1811 return 0;
1812
1813out_unmap:
1814 if (board_addr >= 0x01000000) {
1815 if (v_ram)
1816 iounmap((void*)v_ram);
1817 if (vgaio_regs)
1818 iounmap(vgaio_regs);
1819 if (mmio_regs)
1820 iounmap(mmio_regs);
1821 if (vcode_switch_base)
1822 iounmap((void*)vcode_switch_base);
1823 v_ram = vcode_switch_base = 0;
1824 vgaio_regs = mmio_regs = NULL;
1825 }
1826 return -EINVAL;
1827}
1828
1829
1830static int virgefb_switch(int con, struct fb_info *info)
1831{
1832 DPRINTK("ENTER\n");
1833 /* Do we have to save the colormap? */
1834 if (fb_display[info->currcon].cmap.len)
1835 fb_get_cmap(&fb_display[info->currcon].cmap, 1,
1836 fbhw->getcolreg, info);
1837 virgefb_do_fb_set_var(&fb_display[con].var, 1);
1838 info->currcon = con;
1839 /* Install new colormap */
1840 do_install_cmap(con, info);
1841 DPRINTK("EXIT\n");
1842 return 0;
1843}
1844
1845
1846/*
1847 * Update the `var' structure (called by fbcon.c)
1848 *
1849 * This call looks only at yoffset and the FB_VMODE_YWRAP flag in `var'.
1850 * Since it's called by a kernel driver, no range checking is done.
1851 */
1852
1853static int virgefb_updatevar(int con, struct fb_info *info)
1854{
1855 DPRINTK("ENTER\n");
1856 return 0;
1857 DPRINTK("EXIT\n");
1858}
1859
1860/*
1861 * Blank the display.
1862 */
1863
1864static int virgefb_blank(int blank, struct fb_info *info)
1865{
1866 DPRINTK("ENTER\n");
1867 fbhw->blank(blank);
1868 DPRINTK("EXIT\n");
1869 return 0;
1870}
1871
1872
1873/*
1874 * Text console acceleration
1875 */
1876
1877#ifdef FBCON_HAS_CFB8
1878static void fbcon_virge8_bmove(struct display *p, int sy, int sx, int dy,
1879 int dx, int height, int width)
1880{
1881 sx *= 8; dx *= 8; width *= 8;
1882 virgefb_BitBLT((u_short)sx, (u_short)(sy*fontheight(p)), (u_short)dx,
1883 (u_short)(dy*fontheight(p)), (u_short)width,
1884 (u_short)(height*fontheight(p)), (u_short)p->next_line, 8);
1885}
1886
1887static void fbcon_virge8_clear(struct vc_data *conp, struct display *p, int sy,
1888 int sx, int height, int width)
1889{
1890 unsigned char bg;
1891
1892 sx *= 8; width *= 8;
1893 bg = attr_bgcol_ec(p,conp);
1894 virgefb_RectFill((u_short)sx, (u_short)(sy*fontheight(p)),
1895 (u_short)width, (u_short)(height*fontheight(p)),
1896 (u_short)bg, (u_short)p->next_line, 8);
1897}
1898
1899static void fbcon_virge8_putc(struct vc_data *conp, struct display *p, int c, int yy,
1900 int xx)
1901{
1902 if (blit_maybe_busy)
1903 virgefb_wait_for_idle();
1904 fbcon_cfb8_putc(conp, p, c, yy, xx);
1905}
1906
1907static void fbcon_virge8_putcs(struct vc_data *conp, struct display *p,
1908 const unsigned short *s, int count, int yy, int xx)
1909{
1910 if (blit_maybe_busy)
1911 virgefb_wait_for_idle();
1912 fbcon_cfb8_putcs(conp, p, s, count, yy, xx);
1913}
1914
1915static void fbcon_virge8_revc(struct display *p, int xx, int yy)
1916{
1917 if (blit_maybe_busy)
1918 virgefb_wait_for_idle();
1919 fbcon_cfb8_revc(p, xx, yy);
1920}
1921
1922static void fbcon_virge8_clear_margins(struct vc_data *conp, struct display *p,
1923 int bottom_only)
1924{
1925 if (blit_maybe_busy)
1926 virgefb_wait_for_idle();
1927 fbcon_cfb8_clear_margins(conp, p, bottom_only);
1928}
1929
1930static struct display_switch fbcon_virge8 = {
1931 .setup = fbcon_cfb8_setup,
1932 .bmove = fbcon_virge8_bmove,
1933 .clear = fbcon_virge8_clear,
1934 .putc = fbcon_virge8_putc,
1935 .putcs = fbcon_virge8_putcs,
1936 .revc = fbcon_virge8_revc,
1937 .clear_margins = fbcon_virge8_clear_margins,
1938 .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
1939};
1940#endif
1941
1942#ifdef FBCON_HAS_CFB16
1943static void fbcon_virge16_bmove(struct display *p, int sy, int sx, int dy,
1944 int dx, int height, int width)
1945{
1946 sx *= 8; dx *= 8; width *= 8;
1947 virgefb_BitBLT((u_short)sx, (u_short)(sy*fontheight(p)), (u_short)dx,
1948 (u_short)(dy*fontheight(p)), (u_short)width,
1949 (u_short)(height*fontheight(p)), (u_short)p->next_line, 16);
1950}
1951
1952static void fbcon_virge16_clear(struct vc_data *conp, struct display *p, int sy,
1953 int sx, int height, int width)
1954{
1955 unsigned char bg;
1956
1957 sx *= 8; width *= 8;
1958 bg = attr_bgcol_ec(p,conp);
1959 virgefb_RectFill((u_short)sx, (u_short)(sy*fontheight(p)),
1960 (u_short)width, (u_short)(height*fontheight(p)),
1961 (u_short)bg, (u_short)p->next_line, 16);
1962}
1963
1964static void fbcon_virge16_putc(struct vc_data *conp, struct display *p, int c, int yy,
1965 int xx)
1966{
1967 if (blit_maybe_busy)
1968 virgefb_wait_for_idle();
1969 fbcon_cfb16_putc(conp, p, c, yy, xx);
1970}
1971
1972static void fbcon_virge16_putcs(struct vc_data *conp, struct display *p,
1973 const unsigned short *s, int count, int yy, int xx)
1974{
1975 if (blit_maybe_busy)
1976 virgefb_wait_for_idle();
1977 fbcon_cfb16_putcs(conp, p, s, count, yy, xx);
1978}
1979
1980static void fbcon_virge16_revc(struct display *p, int xx, int yy)
1981{
1982 if (blit_maybe_busy)
1983 virgefb_wait_for_idle();
1984 fbcon_cfb16_revc(p, xx, yy);
1985}
1986
1987static void fbcon_virge16_clear_margins(struct vc_data *conp, struct display *p,
1988 int bottom_only)
1989{
1990 if (blit_maybe_busy)
1991 virgefb_wait_for_idle();
1992 fbcon_cfb16_clear_margins(conp, p, bottom_only);
1993}
1994
1995static struct display_switch fbcon_virge16 = {
1996 .setup = fbcon_cfb16_setup,
1997 .bmove = fbcon_virge16_bmove,
1998 .clear = fbcon_virge16_clear,
1999 .putc = fbcon_virge16_putc,
2000 .putcs = fbcon_virge16_putcs,
2001 .revc = fbcon_virge16_revc,
2002 .clear_margins = fbcon_virge16_clear_margins,
2003 .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
2004};
2005#endif
2006
2007#ifdef FBCON_HAS_CFB32
2008static void fbcon_virge32_bmove(struct display *p, int sy, int sx, int dy,
2009 int dx, int height, int width)
2010{
2011 sx *= 16; dx *= 16; width *= 16; /* doubled these values to do 32 bit blit */
2012 virgefb_BitBLT((u_short)sx, (u_short)(sy*fontheight(p)), (u_short)dx,
2013 (u_short)(dy*fontheight(p)), (u_short)width,
2014 (u_short)(height*fontheight(p)), (u_short)p->next_line, 16);
2015}
2016
2017static void fbcon_virge32_clear(struct vc_data *conp, struct display *p, int sy,
2018 int sx, int height, int width)
2019{
2020 unsigned char bg;
2021
2022 sx *= 16; width *= 16; /* doubled these values to do 32 bit blit */
2023 bg = attr_bgcol_ec(p,conp);
2024 virgefb_RectFill((u_short)sx, (u_short)(sy*fontheight(p)),
2025 (u_short)width, (u_short)(height*fontheight(p)),
2026 (u_short)bg, (u_short)p->next_line, 16);
2027}
2028
2029static void fbcon_virge32_putc(struct vc_data *conp, struct display *p, int c, int yy,
2030 int xx)
2031{
2032 if (blit_maybe_busy)
2033 virgefb_wait_for_idle();
2034 fbcon_cfb32_putc(conp, p, c, yy, xx);
2035}
2036
2037static void fbcon_virge32_putcs(struct vc_data *conp, struct display *p,
2038 const unsigned short *s, int count, int yy, int xx)
2039{
2040 if (blit_maybe_busy)
2041 virgefb_wait_for_idle();
2042 fbcon_cfb32_putcs(conp, p, s, count, yy, xx);
2043}
2044
2045static void fbcon_virge32_revc(struct display *p, int xx, int yy)
2046{
2047 if (blit_maybe_busy)
2048 virgefb_wait_for_idle();
2049 fbcon_cfb32_revc(p, xx, yy);
2050}
2051
2052static void fbcon_virge32_clear_margins(struct vc_data *conp, struct display *p,
2053 int bottom_only)
2054{
2055 if (blit_maybe_busy)
2056 virgefb_wait_for_idle();
2057 fbcon_cfb32_clear_margins(conp, p, bottom_only);
2058}
2059
2060static struct display_switch fbcon_virge32 = {
2061 .setup = fbcon_cfb32_setup,
2062 .bmove = fbcon_virge32_bmove,
2063 .clear = fbcon_virge32_clear,
2064 .putc = fbcon_virge32_putc,
2065 .putcs = fbcon_virge32_putcs,
2066 .revc = fbcon_virge32_revc,
2067 .clear_margins = fbcon_virge32_clear_margins,
2068 .fontwidthmask = FONTWIDTH(4)|FONTWIDTH(8)|FONTWIDTH(12)|FONTWIDTH(16)
2069};
2070#endif
2071
2072#ifdef MODULE
2073MODULE_LICENSE("GPL");
2074
2075int init_module(void)
2076{
2077 return virgefb_init();
2078}
2079#endif /* MODULE */
2080
2081static int cv3d_has_4mb(void)
2082{
2083 /* cyberfb version didn't work, neither does this (not reliably)
2084 forced to return 4MB */
2085#if 0
2086 volatile unsigned long *t0, *t2;
2087#endif
2088 DPRINTK("ENTER\n");
2089#if 0
2090 /* write patterns in memory and test if they can be read */
2091 t0 = (volatile unsigned long *)v_ram;
2092 t2 = (volatile unsigned long *)(v_ram + 0x00200000);
2093 *t0 = 0x87654321;
2094 *t2 = 0x12345678;
2095
2096 if (*t0 != 0x87654321) {
2097 /* read of first location failed */
2098 DPRINTK("EXIT - 0MB !\n");
2099 return 0;
2100 }
2101
2102 if (*t2 == 0x87654321) {
2103 /* should read 0x12345678 if 4MB */
2104 DPRINTK("EXIT - 2MB(a) \n");
2105 return 0;
2106 }
2107
2108 if (*t2 != 0x12345678) {
2109 /* upper 2MB read back match failed */
2110 DPRINTK("EXIT - 2MB(b)\n");
2111 return 0;
2112 }
2113
2114 /* may have 4MB */
2115
2116 *t2 = 0xAAAAAAAA;
2117
2118 if(*t2 != 0xAAAAAAAA) {
2119 /* upper 2MB read back match failed */
2120 DPRINTK("EXIT - 2MB(c)\n");
2121 return 0;
2122 }
2123
2124 *t2 = 0x55555555;
2125
2126 if(*t2 != 0x55555555) {
2127 /* upper 2MB read back match failed */
2128 DPRINTK("EXIT - 2MB(d)\n");
2129 return 0;
2130 }
2131
2132#endif
2133 DPRINTK("EXIT - 4MB\n");
2134 return 1;
2135}
2136
2137
2138/*
2139 * Computes M, N, and R pll params for freq arg.
2140 * Returns 16 bits - hi 0MMMMMM lo 0RRNNNNN
2141 */
2142
2143#define REFCLOCK 14318000
2144
2145static unsigned short virgefb_compute_clock(unsigned long freq)
2146{
2147
2148 unsigned char m, n, r, rpwr;
2149 unsigned long diff, ftry, save = ~0UL;
2150 unsigned short mnr;
2151
2152 DPRINTK("ENTER\n");
2153
2154 for (r = 0, rpwr = 1 ; r < 4 ; r++, rpwr *= 2) {
2155 if ((135000000 <= (rpwr * freq)) && ((rpwr * freq) <= 270000000)) {
2156 for (n = 1 ; n < 32 ; n++) {
2157 m = ((freq * (n + 2) * rpwr)/REFCLOCK) - 2;
2158 if (m == 0 || m >127)
2159 break;
2160 ftry = ((REFCLOCK / (n + 2)) * (m + 2)) / rpwr;
2161 if (ftry > freq)
2162 diff = ftry - freq;
2163 else
2164 diff = freq - ftry;
2165 if (diff < save) {
2166 save = diff;
2167 mnr = (m << 8) | (r<<5) | (n & 0x7f);
2168 }
2169 }
2170 }
2171 }
2172 if (save == ~0UL)
2173 printk("Can't compute clock PLL values for %ld Hz clock\n", freq);
2174 DPRINTK("EXIT\n");
2175 return(mnr);
2176}
2177
2178static void virgefb_load_video_mode(struct fb_var_screeninfo *video_mode)
2179{
2180 unsigned char lace, dblscan, tmp;
2181 unsigned short mnr;
2182 unsigned short HT, HDE, HBS, HBW, HSS, HSW;
2183 unsigned short VT, VDE, VBS, VBW, VSS, VSW;
2184 unsigned short SCO;
2185 int cr11;
2186 int cr67;
2187 int hmul;
2188 int xres, xres_virtual, hfront, hsync, hback;
2189 int yres, vfront, vsync, vback;
2190 int bpp;
2191 int i;
2192 long freq;
2193
2194 DPRINTK("ENTER : %dx%d-%d\n",video_mode->xres, video_mode->yres,
2195 video_mode->bits_per_pixel);
2196
2197 bpp = video_mode->bits_per_pixel;
2198 xres = video_mode->xres;
2199 xres_virtual = video_mode->xres_virtual;
2200 hfront = video_mode->right_margin;
2201 hsync = video_mode->hsync_len;
2202 hback = video_mode->left_margin;
2203
2204 lace = 0;
2205 dblscan = 0;
2206
2207 if (video_mode->vmode & FB_VMODE_DOUBLE) {
2208 yres = video_mode->yres * 2;
2209 vfront = video_mode->lower_margin * 2;
2210 vsync = video_mode->vsync_len * 2;
2211 vback = video_mode->upper_margin * 2;
2212 dblscan = 1;
2213 } else if (video_mode->vmode & FB_VMODE_INTERLACED) {
2214 yres = (video_mode->yres + 1) / 2;
2215 vfront = (video_mode->lower_margin + 1) / 2;
2216 vsync = (video_mode->vsync_len + 1) / 2;
2217 vback = (video_mode->upper_margin + 1) / 2;
2218 lace = 1;
2219 } else {
2220 yres = video_mode->yres;
2221 vfront = video_mode->lower_margin;
2222 vsync = video_mode->vsync_len;
2223 vback = video_mode->upper_margin;
2224 }
2225
2226 switch (bpp) {
2227 case 8:
2228 video_mode->red.offset = 0;
2229 video_mode->green.offset = 0;
2230 video_mode->blue.offset = 0;
2231 video_mode->transp.offset = 0;
2232 video_mode->red.length = 8;
2233 video_mode->green.length = 8;
2234 video_mode->blue.length = 8;
2235 video_mode->transp.length = 0;
2236 hmul = 1;
2237 cr67 = 0x00;
2238 SCO = xres_virtual / 8;
2239 break;
2240 case 16:
2241 video_mode->red.offset = 11;
2242 video_mode->green.offset = 5;
2243 video_mode->blue.offset = 0;
2244 video_mode->transp.offset = 0;
2245 video_mode->red.length = 5;
2246 video_mode->green.length = 6;
2247 video_mode->blue.length = 5;
2248 video_mode->transp.length = 0;
2249 hmul = 2;
2250 cr67 = 0x50;
2251 SCO = xres_virtual / 4;
2252 break;
2253 case 32:
2254 video_mode->red.offset = 16;
2255 video_mode->green.offset = 8;
2256 video_mode->blue.offset = 0;
2257 video_mode->transp.offset = 24;
2258 video_mode->red.length = 8;
2259 video_mode->green.length = 8;
2260 video_mode->blue.length = 8;
2261 video_mode->transp.length = 8;
2262 hmul = 1;
2263 cr67 = 0xd0;
2264 SCO = xres_virtual / 2;
2265 break;
2266 }
2267
2268 HT = (((xres + hfront + hsync + hback) / 8) * hmul) - 5;
2269 HDE = ((xres / 8) * hmul) - 1;
2270 HBS = (xres / 8) * hmul;
2271 HSS = ((xres + hfront) / 8) * hmul;
2272 HSW = (hsync / 8) * hmul;
2273 HBW = (((hfront + hsync + hback) / 8) * hmul) - 2;
2274
2275 VT = yres + vfront + vsync + vback - 2;
2276 VDE = yres - 1;
2277 VBS = yres - 1;
2278 VSS = yres + vfront;
2279 VSW = vsync;
2280 VBW = vfront + vsync + vback - 2;
2281
2282#ifdef VIRGEFBDEBUG
2283 DPRINTK("HDE : 0x%4.4x, %4.4d\n", HDE, HDE);
2284 DPRINTK("HBS : 0x%4.4x, %4.4d\n", HBS, HBS);
2285 DPRINTK("HSS : 0x%4.4x, %4.4d\n", HSS, HSS);
2286 DPRINTK("HSW : 0x%4.4x, %4.4d\n", HSW, HSW);
2287 DPRINTK("HBW : 0x%4.4x, %4.4d\n", HBW, HBW);
2288 DPRINTK("HSS + HSW : 0x%4.4x, %4.4d\n", HSS+HSW, HSS+HSW);
2289 DPRINTK("HBS + HBW : 0x%4.4x, %4.4d\n", HBS+HBW, HBS+HBW);
2290 DPRINTK("HT : 0x%4.4x, %4.4d\n", HT, HT);
2291 DPRINTK("VDE : 0x%4.4x, %4.4d\n", VDE, VDE);
2292 DPRINTK("VBS : 0x%4.4x, %4.4d\n", VBS, VBS);
2293 DPRINTK("VSS : 0x%4.4x, %4.4d\n", VSS, VSS);
2294 DPRINTK("VSW : 0x%4.4x, %4.4d\n", VSW, VSW);
2295 DPRINTK("VBW : 0x%4.4x, %4.4d\n", VBW, VBW);
2296 DPRINTK("VT : 0x%4.4x, %4.4d\n", VT, VT);
2297#endif
2298
2299/* turn gfx off, don't mess up the display */
2300
2301 gfx_on_off(1);
2302
2303/* H and V sync polarity */
2304
2305 tmp = rb_mmio(GREG_MISC_OUTPUT_R) & 0x2f; /* colour, ram enable, clk sr12/s13 sel */
2306 if (!(video_mode->sync & FB_SYNC_HOR_HIGH_ACT))
2307 tmp |= 0x40; /* neg H sync polarity */
2308 if (!(video_mode->sync & FB_SYNC_VERT_HIGH_ACT))
2309 tmp |= 0x80; /* neg V sync polarity */
2310 tmp |= 0x0c; /* clk from sr12/sr13 */
2311 wb_mmio(GREG_MISC_OUTPUT_W, tmp);
2312
2313/* clocks */
2314
2315 wseq(SEQ_ID_BUS_REQ_CNTL, 0xc0); /* 2 clk mem wr and /RAS1 */
2316 wseq(SEQ_ID_CLKSYN_CNTL_2, 0x80); /* b7 is 2 mem clk wr */
2317 mnr = virgefb_compute_clock(MEMCLOCK);
2318 DPRINTK("mem clock %d, m %d, n %d, r %d.\n", MEMCLOCK, ((mnr>>8)&0x7f), (mnr&0x1f), ((mnr >> 5)&0x03));
2319 wseq(SEQ_ID_MCLK_LO, (mnr & 0x7f));
2320 wseq(SEQ_ID_MCLK_HI, ((mnr & 0x7f00) >> 8));
2321 freq = (1000000000 / video_mode->pixclock) * 1000; /* pixclock is in ps ... convert to Hz */
2322 mnr = virgefb_compute_clock(freq);
2323 DPRINTK("dot clock %ld, m %d, n %d, r %d.\n", freq, ((mnr>>8)&0x7f), (mnr&0x1f), ((mnr>>5)&0x03));
2324 wseq(SEQ_ID_DCLK_LO, (mnr & 0x7f));
2325 wseq(SEQ_ID_DCLK_HI, ((mnr & 0x7f00) >> 8));
2326 wseq(SEQ_ID_CLKSYN_CNTL_2, 0xa0);
2327 wseq(SEQ_ID_CLKSYN_CNTL_2, 0x80);
2328 udelay(100);
2329
2330/* load display parameters into board */
2331
2332 /* not sure about sync and blanking extensions bits in cr5d and cr5 */
2333
2334 wcrt(CRT_ID_EXT_HOR_OVF, /* 0x5d */
2335 ((HT & 0x100) ? 0x01 : 0x00) |
2336 ((HDE & 0x100) ? 0x02 : 0x00) |
2337 ((HBS & 0x100) ? 0x04 : 0x00) |
2338 /* (((HBS + HBW) & 0x40) ? 0x08 : 0x00) | */
2339 ((HSS & 0x100) ? 0x10 : 0x00) |
2340 /* (((HSS + HSW) & 0x20) ? 0x20 : 0x00) | */
2341 ((HSW >= 0x20) ? 0x20 : 0x00) |
2342 (((HT-5) & 0x100) ? 0x40 : 0x00));
2343
2344 wcrt(CRT_ID_EXT_VER_OVF, /* 0x5e */
2345 ((VT & 0x400) ? 0x01 : 0x00) |
2346 ((VDE & 0x400) ? 0x02 : 0x00) |
2347 ((VBS & 0x400) ? 0x04 : 0x00) |
2348 ((VSS & 0x400) ? 0x10 : 0x00) |
2349 0x40); /* line compare */
2350
2351 wcrt(CRT_ID_START_VER_RETR, VSS);
2352 cr11 = rcrt(CRT_ID_END_VER_RETR) | 0x20; /* vert interrupt flag */
2353 wcrt(CRT_ID_END_VER_RETR, ((cr11 & 0x20) | ((VSS + VSW) & 0x0f))); /* keeps vert irq enable state, also has unlock bit cr0 to 7 */
2354 wcrt(CRT_ID_VER_DISP_ENA_END, VDE);
2355 wcrt(CRT_ID_START_VER_BLANK, VBS);
2356 wcrt(CRT_ID_END_VER_BLANK, VBS + VBW); /* might be +/- 1 out */
2357 wcrt(CRT_ID_HOR_TOTAL, HT);
2358 wcrt(CRT_ID_DISPLAY_FIFO, HT - 5);
2359 wcrt(CRT_ID_BACKWAD_COMP_3, 0x10); /* enable display fifo */
2360 wcrt(CRT_ID_HOR_DISP_ENA_END, HDE);
2361 wcrt(CRT_ID_START_HOR_BLANK , HBS);
2362 wcrt(CRT_ID_END_HOR_BLANK, (HBS + HBW) & 0x1f);
2363 wcrt(CRT_ID_START_HOR_RETR, HSS);
2364 wcrt(CRT_ID_END_HOR_RETR, /* cr5 */
2365 ((HSS + HSW) & 0x1f) |
2366 (((HBS + HBW) & 0x20) ? 0x80 : 0x00));
2367 wcrt(CRT_ID_VER_TOTAL, VT);
2368 wcrt(CRT_ID_OVERFLOW,
2369 ((VT & 0x100) ? 0x01 : 0x00) |
2370 ((VDE & 0x100) ? 0x02 : 0x00) |
2371 ((VSS & 0x100) ? 0x04 : 0x00) |
2372 ((VBS & 0x100) ? 0x08 : 0x00) |
2373 0x10 |
2374 ((VT & 0x200) ? 0x20 : 0x00) |
2375 ((VDE & 0x200) ? 0x40 : 0x00) |
2376 ((VSS & 0x200) ? 0x80 : 0x00));
2377 wcrt(CRT_ID_MAX_SCAN_LINE,
2378 (dblscan ? 0x80 : 0x00) |
2379 0x40 |
2380 ((VBS & 0x200) ? 0x20 : 0x00));
2381 wcrt(CRT_ID_LINE_COMPARE, 0xff);
2382 wcrt(CRT_ID_LACE_RETR_START, HT / 2); /* (HT-5)/2 ? */
2383 wcrt(CRT_ID_LACE_CONTROL, (lace ? 0x20 : 0x00));
2384
2385 wcrt(CRT_ID_SCREEN_OFFSET, SCO);
2386 wcrt(CRT_ID_EXT_SYS_CNTL_2, (SCO >> 4) & 0x30 );
2387
2388 /* wait for vert sync before cr67 update */
2389
2390 for (i=0; i < 10000; i++) {
2391 udelay(10);
2392 mb();
2393 if (rb_mmio(GREG_INPUT_STATUS1_R) & 0x08)
2394 break;
2395 }
2396
2397 wl_mmio(0x8200, 0x0000c000); /* fifo control (0x00110400 ?) */
2398 wcrt(CRT_ID_EXT_MISC_CNTL_2, cr67);
2399
2400/* enable video */
2401
2402 tmp = rb_mmio(ACT_ADDRESS_RESET);
2403 wb_mmio(ACT_ADDRESS_W, ((bpp == 8) ? 0x20 : 0x00)); /* set b5, ENB PLT in attr idx reg) */
2404 tmp = rb_mmio(ACT_ADDRESS_RESET);
2405
2406/* turn gfx on again */
2407
2408 gfx_on_off(0);
2409
2410/* pass-through */
2411
2412 SetVSwitch(1); /* cv3d */
2413
2414 DUMP;
2415 DPRINTK("EXIT\n");
2416}
2417
2418static inline void gfx_on_off(int toggle)
2419{
2420 unsigned char tmp;
2421
2422 DPRINTK("ENTER gfx %s\n", (toggle ? "off" : "on"));
2423
2424 toggle = (toggle & 0x01) << 5;
2425 tmp = rseq(SEQ_ID_CLOCKING_MODE) & (~(0x01 << 5));
2426 wseq(SEQ_ID_CLOCKING_MODE, tmp | toggle);
2427
2428 DPRINTK("EXIT\n");
2429}
2430
2431#if defined (VIRGEFBDUMP)
2432
2433/*
2434 * Dump board registers
2435 */
2436
2437static void cv64_dump(void)
2438{
2439 int i;
2440 u8 c, b;
2441 u16 w;
2442 u32 l;
2443
2444 /* crt, seq, gfx and atr regs */
2445
2446 SelectMMIO;
2447
2448 printk("\n");
2449 for (i = 0; i <= 0x6f; i++) {
2450 wb_mmio(CRT_ADDRESS, i);
2451 printk("crt idx : 0x%2.2x : 0x%2.2x\n", i, rb_mmio(CRT_ADDRESS_R));
2452 }
2453 for (i = 0; i <= 0x1c; i++) {
2454 wb_mmio(SEQ_ADDRESS, i);
2455 printk("seq idx : 0x%2.2x : 0x%2.2x\n", i, rb_mmio(SEQ_ADDRESS_R));
2456 }
2457 for (i = 0; i <= 8; i++) {
2458 wb_mmio(GCT_ADDRESS, i);
2459 printk("gfx idx : 0x%2.2x : 0x%2.2x\n", i, rb_mmio(GCT_ADDRESS_R));
2460 }
2461 for (i = 0; i <= 0x14; i++) {
2462 c = rb_mmio(ACT_ADDRESS_RESET);
2463 wb_mmio(ACT_ADDRESS_W, i);
2464 printk("atr idx : 0x%2.2x : 0x%2.2x\n", i, rb_mmio(ACT_ADDRESS_R));
2465 }
2466
2467 /* re-enable video access to palette */
2468
2469 c = rb_mmio(ACT_ADDRESS_RESET);
2470 udelay(10);
2471 wb_mmio(ACT_ADDRESS_W, 0x20);
2472 c = rb_mmio(ACT_ADDRESS_RESET);
2473 udelay(10);
2474
2475 /* general regs */
2476
2477 printk("0x3cc(w 0x3c2) : 0x%2.2x\n", rb_mmio(0x3cc)); /* GREG_MISC_OUTPUT READ */
2478 printk("0x3c2(-------) : 0x%2.2x\n", rb_mmio(0x3c2)); /* GREG_INPUT_STATUS 0 READ */
2479 printk("0x3c3(w 0x3c3) : 0x%2.2x\n", rb_vgaio(0x3c3)); /* GREG_VIDEO_SUBS_ENABLE */
2480 printk("0x3ca(w 0x3da) : 0x%2.2x\n", rb_vgaio(0x3ca)); /* GREG_FEATURE_CONTROL read */
2481 printk("0x3da(-------) : 0x%2.2x\n", rb_mmio(0x3da)); /* GREG_INPUT_STATUS 1 READ */
2482
2483 /* engine regs */
2484
2485 for (i = 0x8180; i <= 0x8200; i = i + 4)
2486 printk("0x%8.8x : 0x%8.8x\n", i, rl_mmio(i));
2487
2488 i = 0x8504;
2489 printk("0x%8.8x : 0x%8.8x\n", i, rl_mmio(i));
2490 i = 0x850c;
2491 printk("0x%8.8x : 0x%8.8x\n", i, rl_mmio(i));
2492 for (i = 0xa4d4; i <= 0xa50c; i = i + 4)
2493 printk("0x%8.8x : 0x%8.8x\n", i, rl_mmio(i));
2494
2495 /* PCI regs */
2496
2497 SelectCFG;
2498
2499 for (c = 0; c < 0x08; c = c + 2) {
2500 w = (*((u16 *)((u32)(vgaio_regs + c + (on_zorro2 ? 0 : 0x000e0000)) ^ 2)));
2501 printk("pci 0x%2.2x : 0x%4.4x\n", c, w);
2502 }
2503 c = 8;
2504 l = (*((u32 *)((u32)(vgaio_regs + c + (on_zorro2 ? 0 : 0x000e0000)))));
2505 printk("pci 0x%2.2x : 0x%8.8x\n", c, l);
2506 c = 0x0d;
2507 b = (*((u8 *)((u32)(vgaio_regs + c + (on_zorro2 ? 0 : 0x000e0000)) ^ 3)));
2508 printk("pci 0x%2.2x : 0x%2.2x\n", c, b);
2509 c = 0x10;
2510 l = (*((u32 *)((u32)(vgaio_regs + c + (on_zorro2 ? 0 : 0x000e0000)))));
2511 printk("pci 0x%2.2x : 0x%8.8x\n", c, l);
2512 c = 0x30;
2513 l = (*((u32 *)((u32)(vgaio_regs + c + (on_zorro2 ? 0 : 0x000e0000)))));
2514 printk("pci 0x%2.2x : 0x%8.8x\n", c, l);
2515 c = 0x3c;
2516 b = (*((u8 *)((u32)(vgaio_regs + c + (on_zorro2 ? 0 : 0x000e0000)) ^ 3)));
2517 printk("pci 0x%2.2x : 0x%2.2x\n", c, b);
2518 c = 0x3d;
2519 b = (*((u8 *)((u32)(vgaio_regs + c + (on_zorro2 ? 0 : 0x000e0000)) ^ 3)));
2520 printk("pci 0x%2.2x : 0x%2.2x\n", c, b);
2521 c = 0x3e;
2522 w = (*((u16 *)((u32)(vgaio_regs + c + (on_zorro2 ? 0 : 0x000e0000)) ^ 2)));
2523 printk("pci 0x%2.2x : 0x%4.4x\n", c, w);
2524 SelectMMIO;
2525}
2526#endif
diff --git a/drivers/video/virgefb.h b/drivers/video/virgefb.h
deleted file mode 100644
index 157d66deb24..00000000000
--- a/drivers/video/virgefb.h
+++ /dev/null
@@ -1,288 +0,0 @@
1/*
2 * linux/drivers/video/virgefb.h -- CyberVision64 definitions for the
3 * text console driver.
4 *
5 * Copyright (c) 1998 Alan Bair
6 *
7 * This file is based on the initial port to Linux of grf_cvreg.h:
8 *
9 * Copyright (c) 1997 Antonio Santos
10 *
11 * The original work is from the NetBSD CyberVision 64 framebuffer driver
12 * and support files (grf_cv.c, grf_cvreg.h, ite_cv.c):
13 * Permission to use the source of this driver was obtained from the
14 * author Michael Teske by Alan Bair.
15 *
16 * Copyright (c) 1995 Michael Teske
17 *
18 * History:
19 *
20 *
21 *
22 * This file is subject to the terms and conditions of the GNU General Public
23 * License. See the file COPYING in the main directory of this archive
24 * for more details.
25 */
26
27/* Enhanced register mapping (MMIO mode) */
28
29#define S3_CRTC_ADR 0x03d4
30#define S3_CRTC_DATA 0x03d5
31
32#define S3_REG_LOCK2 0x39
33#define S3_HGC_MODE 0x45
34
35#define S3_HWGC_ORGX_H 0x46
36#define S3_HWGC_ORGX_L 0x47
37#define S3_HWGC_ORGY_H 0x48
38#define S3_HWGC_ORGY_L 0x49
39#define S3_HWGC_DX 0x4e
40#define S3_HWGC_DY 0x4f
41
42#define S3_LAW_CTL 0x58
43
44/**************************************************/
45
46/*
47 * Defines for the used register addresses (mw)
48 *
49 * NOTE: There are some registers that have different addresses when
50 * in mono or color mode. We only support color mode, and thus
51 * some addresses won't work in mono-mode!
52 *
53 * General and VGA-registers taken from retina driver. Fixed a few
54 * bugs in it. (SR and GR read address is Port + 1, NOT Port)
55 *
56 */
57
58/* General Registers: */
59#define GREG_MISC_OUTPUT_R 0x03CC
60#define GREG_MISC_OUTPUT_W 0x03C2
61#define GREG_FEATURE_CONTROL_R 0x03CA
62#define GREG_FEATURE_CONTROL_W 0x03DA
63#define GREG_INPUT_STATUS0_R 0x03C2
64#define GREG_INPUT_STATUS1_R 0x03DA
65
66/* Setup Registers: */
67#define SREG_VIDEO_SUBS_ENABLE 0x03C3 /* virge */
68
69/* Attribute Controller: */
70#define ACT_ADDRESS 0x03C0
71#define ACT_ADDRESS_R 0x03C1
72#define ACT_ADDRESS_W 0x03C0
73#define ACT_ADDRESS_RESET 0x03DA
74#define ACT_ID_PALETTE0 0x00
75#define ACT_ID_PALETTE1 0x01
76#define ACT_ID_PALETTE2 0x02
77#define ACT_ID_PALETTE3 0x03
78#define ACT_ID_PALETTE4 0x04
79#define ACT_ID_PALETTE5 0x05
80#define ACT_ID_PALETTE6 0x06
81#define ACT_ID_PALETTE7 0x07
82#define ACT_ID_PALETTE8 0x08
83#define ACT_ID_PALETTE9 0x09
84#define ACT_ID_PALETTE10 0x0A
85#define ACT_ID_PALETTE11 0x0B
86#define ACT_ID_PALETTE12 0x0C
87#define ACT_ID_PALETTE13 0x0D
88#define ACT_ID_PALETTE14 0x0E
89#define ACT_ID_PALETTE15 0x0F
90#define ACT_ID_ATTR_MODE_CNTL 0x10
91#define ACT_ID_OVERSCAN_COLOR 0x11
92#define ACT_ID_COLOR_PLANE_ENA 0x12
93#define ACT_ID_HOR_PEL_PANNING 0x13
94#define ACT_ID_COLOR_SELECT 0x14 /* virge PX_PADD pixel padding register */
95
96/* Graphics Controller: */
97#define GCT_ADDRESS 0x03CE
98#define GCT_ADDRESS_R 0x03CF
99#define GCT_ADDRESS_W 0x03CF
100#define GCT_ID_SET_RESET 0x00
101#define GCT_ID_ENABLE_SET_RESET 0x01
102#define GCT_ID_COLOR_COMPARE 0x02
103#define GCT_ID_DATA_ROTATE 0x03
104#define GCT_ID_READ_MAP_SELECT 0x04
105#define GCT_ID_GRAPHICS_MODE 0x05
106#define GCT_ID_MISC 0x06
107#define GCT_ID_COLOR_XCARE 0x07
108#define GCT_ID_BITMASK 0x08
109
110/* Sequencer: */
111#define SEQ_ADDRESS 0x03C4
112#define SEQ_ADDRESS_R 0x03C5
113#define SEQ_ADDRESS_W 0x03C5
114#define SEQ_ID_RESET 0x00
115#define SEQ_ID_CLOCKING_MODE 0x01
116#define SEQ_ID_MAP_MASK 0x02
117#define SEQ_ID_CHAR_MAP_SELECT 0x03
118#define SEQ_ID_MEMORY_MODE 0x04
119#define SEQ_ID_UNKNOWN1 0x05
120#define SEQ_ID_UNKNOWN2 0x06
121#define SEQ_ID_UNKNOWN3 0x07
122/* S3 extensions */
123#define SEQ_ID_UNLOCK_EXT 0x08
124#define SEQ_ID_EXT_SEQ_REG9 0x09 /* b7 = 1 extended reg access by MMIO only */
125#define SEQ_ID_BUS_REQ_CNTL 0x0A
126#define SEQ_ID_EXT_MISC_SEQ 0x0B
127#define SEQ_ID_UNKNOWN4 0x0C
128#define SEQ_ID_EXT_SEQ 0x0D
129#define SEQ_ID_UNKNOWN5 0x0E
130#define SEQ_ID_UNKNOWN6 0x0F
131#define SEQ_ID_MCLK_LO 0x10
132#define SEQ_ID_MCLK_HI 0x11
133#define SEQ_ID_DCLK_LO 0x12
134#define SEQ_ID_DCLK_HI 0x13
135#define SEQ_ID_CLKSYN_CNTL_1 0x14
136#define SEQ_ID_CLKSYN_CNTL_2 0x15
137#define SEQ_ID_CLKSYN_TEST_HI 0x16 /* reserved for S3 testing of the */
138#define SEQ_ID_CLKSYN_TEST_LO 0x17 /* internal clock synthesizer */
139#define SEQ_ID_RAMDAC_CNTL 0x18
140#define SEQ_ID_MORE_MAGIC 0x1A
141#define SEQ_ID_SIGNAL_SELECT 0x1C /* new for virge */
142
143/* CRT Controller: */
144#define CRT_ADDRESS 0x03D4
145#define CRT_ADDRESS_R 0x03D5
146#define CRT_ADDRESS_W 0x03D5
147#define CRT_ID_HOR_TOTAL 0x00
148#define CRT_ID_HOR_DISP_ENA_END 0x01
149#define CRT_ID_START_HOR_BLANK 0x02
150#define CRT_ID_END_HOR_BLANK 0x03
151#define CRT_ID_START_HOR_RETR 0x04
152#define CRT_ID_END_HOR_RETR 0x05
153#define CRT_ID_VER_TOTAL 0x06
154#define CRT_ID_OVERFLOW 0x07
155#define CRT_ID_PRESET_ROW_SCAN 0x08
156#define CRT_ID_MAX_SCAN_LINE 0x09
157#define CRT_ID_CURSOR_START 0x0A
158#define CRT_ID_CURSOR_END 0x0B
159#define CRT_ID_START_ADDR_HIGH 0x0C
160#define CRT_ID_START_ADDR_LOW 0x0D
161#define CRT_ID_CURSOR_LOC_HIGH 0x0E
162#define CRT_ID_CURSOR_LOC_LOW 0x0F
163#define CRT_ID_START_VER_RETR 0x10
164#define CRT_ID_END_VER_RETR 0x11
165#define CRT_ID_VER_DISP_ENA_END 0x12
166#define CRT_ID_SCREEN_OFFSET 0x13
167#define CRT_ID_UNDERLINE_LOC 0x14
168#define CRT_ID_START_VER_BLANK 0x15
169#define CRT_ID_END_VER_BLANK 0x16
170#define CRT_ID_MODE_CONTROL 0x17
171#define CRT_ID_LINE_COMPARE 0x18
172#define CRT_ID_GD_LATCH_RBACK 0x22
173#define CRT_ID_ACT_TOGGLE_RBACK 0x24
174#define CRT_ID_ACT_INDEX_RBACK 0x26
175/* S3 extensions: S3 VGA Registers */
176#define CRT_ID_DEVICE_HIGH 0x2D
177#define CRT_ID_DEVICE_LOW 0x2E
178#define CRT_ID_REVISION 0x2F
179#define CRT_ID_CHIP_ID_REV 0x30
180#define CRT_ID_MEMORY_CONF 0x31
181#define CRT_ID_BACKWAD_COMP_1 0x32
182#define CRT_ID_BACKWAD_COMP_2 0x33
183#define CRT_ID_BACKWAD_COMP_3 0x34
184#define CRT_ID_REGISTER_LOCK 0x35
185#define CRT_ID_CONFIG_1 0x36
186#define CRT_ID_CONFIG_2 0x37
187#define CRT_ID_REGISTER_LOCK_1 0x38
188#define CRT_ID_REGISTER_LOCK_2 0x39
189#define CRT_ID_MISC_1 0x3A
190#define CRT_ID_DISPLAY_FIFO 0x3B
191#define CRT_ID_LACE_RETR_START 0x3C
192/* S3 extensions: System Control Registers */
193#define CRT_ID_SYSTEM_CONFIG 0x40
194#define CRT_ID_BIOS_FLAG 0x41
195#define CRT_ID_LACE_CONTROL 0x42
196#define CRT_ID_EXT_MODE 0x43
197#define CRT_ID_HWGC_MODE 0x45 /* HWGC = Hardware Graphics Cursor */
198#define CRT_ID_HWGC_ORIGIN_X_HI 0x46
199#define CRT_ID_HWGC_ORIGIN_X_LO 0x47
200#define CRT_ID_HWGC_ORIGIN_Y_HI 0x48
201#define CRT_ID_HWGC_ORIGIN_Y_LO 0x49
202#define CRT_ID_HWGC_FG_STACK 0x4A
203#define CRT_ID_HWGC_BG_STACK 0x4B
204#define CRT_ID_HWGC_START_AD_HI 0x4C
205#define CRT_ID_HWGC_START_AD_LO 0x4D
206#define CRT_ID_HWGC_DSTART_X 0x4E
207#define CRT_ID_HWGC_DSTART_Y 0x4F
208/* S3 extensions: System Extension Registers */
209#define CRT_ID_EXT_SYS_CNTL_1 0x50 /* NOT a virge register */
210#define CRT_ID_EXT_SYS_CNTL_2 0x51
211#define CRT_ID_EXT_BIOS_FLAG_1 0x52
212#define CRT_ID_EXT_MEM_CNTL_1 0x53
213#define CRT_ID_EXT_MEM_CNTL_2 0x54
214#define CRT_ID_EXT_DAC_CNTL 0x55
215#define CRT_ID_EX_SYNC_1 0x56
216#define CRT_ID_EX_SYNC_2 0x57
217#define CRT_ID_LAW_CNTL 0x58 /* LAW = Linear Address Window */
218#define CRT_ID_LAW_POS_HI 0x59
219#define CRT_ID_LAW_POS_LO 0x5A
220#define CRT_ID_GOUT_PORT 0x5C
221#define CRT_ID_EXT_HOR_OVF 0x5D
222#define CRT_ID_EXT_VER_OVF 0x5E
223#define CRT_ID_EXT_MEM_CNTL_3 0x60 /* NOT a virge register */
224#define CRT_ID_EXT_MEM_CNTL_4 0x61
225#define CRT_ID_EX_SYNC_3 0x63 /* NOT a virge register */
226#define CRT_ID_EXT_MISC_CNTL 0x65
227#define CRT_ID_EXT_MISC_CNTL_1 0x66
228#define CRT_ID_EXT_MISC_CNTL_2 0x67
229#define CRT_ID_CONFIG_3 0x68
230#define CRT_ID_EXT_SYS_CNTL_3 0x69
231#define CRT_ID_EXT_SYS_CNTL_4 0x6A
232#define CRT_ID_EXT_BIOS_FLAG_3 0x6B
233#define CRT_ID_EXT_BIOS_FLAG_4 0x6C
234/* S3 virge extensions: more System Extension Registers */
235#define CRT_ID_EXT_BIOS_FLAG_5 0x6D
236#define CRT_ID_EXT_DAC_TEST 0x6E
237#define CRT_ID_CONFIG_4 0x6F
238
239/* Video DAC */
240#define VDAC_ADDRESS 0x03c8
241#define VDAC_ADDRESS_W 0x03c8
242#define VDAC_ADDRESS_R 0x03c7
243#define VDAC_STATE 0x03c7
244#define VDAC_DATA 0x03c9
245#define VDAC_MASK 0x03c6
246
247/* Miscellaneous Registers */
248#define MR_SUBSYSTEM_STATUS_R 0x8504 /* new for virge */
249#define MR_SUBSYSTEM_CNTL_W 0x8504 /* new for virge */
250#define MR_ADVANCED_FUNCTION_CONTROL 0x850C /* new for virge */
251
252/* Blitter */
253#define BLT_COMMAND_SET 0xA500
254#define BLT_SIZE_X_Y 0xA504
255#define BLT_SRC_X_Y 0xA508
256#define BLT_DEST_X_Y 0xA50C
257
258#define BLT_SRC_BASE 0xa4d4
259#define BLT_DEST_BASE 0xa4d8
260#define BLT_CLIP_LEFT_RIGHT 0xa4dc
261#define BLT_CLIP_TOP_BOTTOM 0xa4e0
262#define BLT_SRC_DEST_STRIDE 0xa4e4
263#define BLT_MONO_PATTERN_0 0xa4e8
264#define BLT_MONO_PATTERN_1 0xa4ec
265#define BLT_PATTERN_COLOR 0xa4f4
266
267#define L2D_COMMAND_SET 0xA900
268#define L2D_CLIP_LEFT_RIGHT 0xA8DC
269#define L2D_CLIP_TOP_BOTTOM 0xA8E0
270
271#define P2D_COMMAND_SET 0xAD00
272#define P2D_CLIP_LEFT_RIGHT 0xACDC
273#define P2D_CLIP_TOP_BOTTOM 0xACE0
274
275#define CMD_NOP (0xf << 27) /* %1111 << 27, was 0x07 */
276#define S3V_BITBLT (0x0 << 27)
277#define S3V_RECTFILL (0x2 << 27)
278#define S3V_AUTOEXE 0x01
279#define S3V_HWCLIP 0x02
280#define S3V_DRAW 0x20
281#define S3V_DST_8BPP 0x00
282#define S3V_DST_16BPP 0x04
283#define S3V_DST_24BPP 0x08
284#define S3V_MONO_PAT 0x100
285
286#define S3V_BLT_COPY (0xcc<<17)
287#define S3V_BLT_CLEAR (0x00<<17)
288#define S3V_BLT_SET (0xff<<17)
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index b022fffd8c5..732db478004 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -141,7 +141,7 @@ static inline int w1_convert_temp(u8 rom[9], u8 fid)
141{ 141{
142 int i; 142 int i;
143 143
144 for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i) 144 for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i)
145 if (w1_therm_families[i].f->fid == fid) 145 if (w1_therm_families[i].f->fid == fid)
146 return w1_therm_families[i].convert(rom); 146 return w1_therm_families[i].convert(rom);
147 147
@@ -238,7 +238,7 @@ static int __init w1_therm_init(void)
238{ 238{
239 int err, i; 239 int err, i;
240 240
241 for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i) { 241 for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i) {
242 err = w1_register_family(w1_therm_families[i].f); 242 err = w1_register_family(w1_therm_families[i].f);
243 if (err) 243 if (err)
244 w1_therm_families[i].broken = 1; 244 w1_therm_families[i].broken = 1;
@@ -251,7 +251,7 @@ static void __exit w1_therm_fini(void)
251{ 251{
252 int i; 252 int i;
253 253
254 for (i=0; i<sizeof(w1_therm_families)/sizeof(w1_therm_families[0]); ++i) 254 for (i = 0; i < ARRAY_SIZE(w1_therm_families); ++i)
255 if (!w1_therm_families[i].broken) 255 if (!w1_therm_families[i].broken)
256 w1_unregister_family(w1_therm_families[i].f); 256 w1_unregister_family(w1_therm_families[i].f);
257} 257}
diff --git a/drivers/zorro/proc.c b/drivers/zorro/proc.c
index 60b05bc1564..b3ce8859a58 100644
--- a/drivers/zorro/proc.c
+++ b/drivers/zorro/proc.c
@@ -75,7 +75,7 @@ proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *
75 return nbytes; 75 return nbytes;
76} 76}
77 77
78static struct file_operations proc_bus_zorro_operations = { 78static const struct file_operations proc_bus_zorro_operations = {
79 .llseek = proc_bus_zorro_lseek, 79 .llseek = proc_bus_zorro_lseek,
80 .read = proc_bus_zorro_read, 80 .read = proc_bus_zorro_read,
81}; 81};